1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-21 23:39:37 +01:00
deka-dom-el/dist/esm.js
2024-01-31 14:41:18 +01:00

2 lines
9.4 KiB
JavaScript

var A={isObservable(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function z(t,e=!0){return e?Object.assign(A,t):(Object.setPrototypeOf(t,A),t)}function _(t){return A.isPrototypeOf(t)&&t!==A?t:A}function E(t){return typeof t>"u"}function O(t,e){if(!t||!(t instanceof AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}function k(t,e){let{observedAttributes:n=[]}=t.constructor;return n.reduce(function(r,o){return Reflect.set(r,B(o),e(t,o)),r},{})}function B(t){return t.replace(/-./g,e=>e[1].toUpperCase())}var a={setDeleteAttr:I,ssr:"",D:globalThis.document,F:globalThis.DocumentFragment,H:globalThis.HTMLElement,S:globalThis.SVGElement,M:globalThis.MutationObserver};function I(t,e,n){if(Reflect.set(t,e,n),!!E(n)){if(Reflect.deleteProperty(t,e),t instanceof a.H&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var x="__dde_lifecycleToEvents";var v=[{get scope(){return a.D.body},host:t=>t?t(a.D.body):a.D.body,prevent:!0}],g={get current(){return v[v.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...v]},push(t={}){return v.push(Object.assign({},this.current,{prevent:!1},t))},pushRoot(){return v.push(v[0])},pop(){if(v.length!==1)return v.pop()}};function W(...t){return this.appendOriginal(...t),this}function Z(t){return t.append===W||(t.appendOriginal=t.append,t.append=W),t}var S;function T(t,e,...n){let r=_(this),o=0,c,s;switch((Object(e)!==e||r.isObservable(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1,g.push({scope:t,host:(...l)=>l.length?(o===1?n.unshift(...l):l.forEach(p=>p(s)),void 0):s}),c=t(e||void 0);let d=c instanceof a.F;if(c.nodeName==="#comment")break;let h=T.mark({type:"component",name:t.name,host:d?"this":"parentElement"});c.prepend(h),d&&(s=h);break}case t==="#text":c=C.call(this,a.D.createTextNode(""),e);break;case(t==="<>"||!t):c=C.call(this,a.D.createDocumentFragment(),e);break;case!!S:c=C.call(this,a.D.createElementNS(S,t),e);break;case!c:c=C.call(this,a.D.createElement(t),e)}return Z(c),s||(s=c),n.forEach(d=>d(s)),o&&g.pop(),o=2,c}function ft(t,e=t,n=void 0){let r=Symbol.for("default"),o=Array.from(e.querySelectorAll("slot")).reduce((s,d)=>Reflect.set(s,d.name||r,d)&&s,{}),c=Reflect.has(o,r);if(t.append=new Proxy(t.append,{apply(s,d,h){if(!h.length)return t;let l=a.D.createDocumentFragment();for(let p of h){if(!p||!p.slot){c&&l.appendChild(p);continue}let y=p.slot,R=o[y];J(p,"remove","slot"),R&&(G(R,p,n),Reflect.deleteProperty(o,y))}return c&&(o[r].replaceWith(l),Reflect.deleteProperty(o,r)),t.append=s,t}}),t!==e){let s=Array.from(t.childNodes);s.forEach(d=>d.remove()),t.append(...s)}return e}function G(t,e,n){n&&n(t,e);try{t.replaceWith(C(e,{className:[e.className,t.className],dataset:{...t.dataset}}))}catch{t.replaceWith(e)}}T.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=a.D.createComment(`<dde:mark ${t}${a.ssr}${n}>`);return e&&(r.end=a.D.createComment("</dde:mark>")),r};function at(t){let e=this;return function(...r){S=t;let o=T.call(e,...r);return S=void 0,o}}var L=new WeakMap,{setDeleteAttr:j}=a;function C(t,...e){if(!e.length)return t;L.set(t,$(t,this));for(let[n,r]of Object.entries(Object.assign({},...e)))F.call(this,t,n,r);return L.delete(t),t}function F(t,e,n){let{setRemoveAttr:r,s:o}=$(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(d,h)=>F.call(c,t,d,h));let[s]=e;if(s==="=")return r(e.slice(1),n);if(s===".")return q(t,e.slice(1),n);if(/(aria|data)([A-Z])/.test(e))return e=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),r(e,n);switch(e==="className"&&(e="class"),e){case"xlink:href":return r(e,n,"http://www.w3.org/1999/xlink");case"textContent":return j(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return N(o,n,q.bind(null,t[e]));case"ariaset":return N(o,n,(d,h)=>r("aria-"+d,h));case"classList":return V.call(c,t,n)}return K(t,e)?j(t,e,n):r(e,n)}function $(t,e){if(L.has(t))return L.get(t);let r=(t instanceof a.S?X:Q).bind(null,t,"Attribute"),o=_(e);return{setRemoveAttr:r,s:o}}function V(t,e){let n=_(this);return N(n,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function dt(t){return Array.from(t.children).forEach(e=>e.remove()),t}function J(t,e,n,r){return t instanceof a.H?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function K(t,e){if(!Reflect.has(t,e))return!1;let n=U(t,e);return!E(n.set)}function U(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||U(t,e)}function N(t,e,n){if(!(typeof e!="object"||e===null))return Object.entries(e).forEach(function([o,c]){o&&(c=t.processReactiveAttribute(e,o,c,n),n(o,c))})}function H(t){return Array.isArray(t)?t.filter(Boolean).join(" "):t}function Q(t,e,n,r){return t[(E(r)?"remove":"set")+e](n,H(r))}function X(t,e,n,r,o=null){return t[(E(r)?"remove":"set")+e+"NS"](o,n,H(r))}function q(t,e,n){if(Reflect.set(t,e,n),!!E(n))return Reflect.deleteProperty(t,e)}var m=a.M?Y():new Proxy({},{get(){return()=>{}}});function Y(){let t=new Map,e=!1,n=i=>function(f){for(let u of f)if(u.type==="childList"){if(p(u.addedNodes,!0)){i();continue}y(u.removedNodes,!0)&&i()}},r=new a.M(n(d));return{observe(i){let f=new a.M(n(()=>{}));return f.observe(i,{childList:!0,subtree:!0}),()=>f.disconnect()},onConnected(i,f){s();let u=c(i);u.connected.has(f)||(u.connected.add(f),u.length_c+=1)},offConnected(i,f){if(!t.has(i))return;let u=t.get(i);u.connected.has(f)&&(u.connected.delete(f),u.length_c-=1,o(i,u))},onDisconnected(i,f){s();let u=c(i);u.disconnected.has(f)||(u.disconnected.add(f),u.length_d+=1)},offDisconnected(i,f){if(!t.has(i))return;let u=t.get(i);u.disconnected.has(f)&&(u.disconnected.delete(f),u.length_d-=1,o(i,u))}};function o(i,f){f.length_c||f.length_d||(t.delete(i),d())}function c(i){if(t.has(i))return t.get(i);let f={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(i,f),f}function s(){e||(e=!0,r.observe(a.D.body,{childList:!0,subtree:!0}))}function d(){!e||t.size||(e=!1,r.disconnect())}function h(){return new Promise(function(i){(requestIdleCallback||requestAnimationFrame)(i)})}async function l(i){t.size>30&&await h();let f=[];if(!(i instanceof Node))return f;for(let u of t.keys())u===i||!(u instanceof Node)||i.contains(u)&&f.push(u);return f}function p(i,f){let u=!1;for(let b of i){if(f&&l(b).then(p),!t.has(b))continue;let w=t.get(b);w.length_c&&(b.dispatchEvent(new Event("dde:connected")),w.connected=new WeakSet,w.length_c=0,w.length_d||t.delete(b),u=!0)}return u}function y(i,f){let u=!1;for(let b of i)f&&l(b).then(y),!(!t.has(b)||!t.get(b).length_d)&&((queueMicrotask||setTimeout)(R(b)),u=!0);return u}function R(i){return()=>{i.isConnected||(i.dispatchEvent(new Event("dde:disconnected")),t.delete(i))}}}function xt(t,e,n,r=et){g.push({scope:t,host:(...s)=>s.length?s.forEach(d=>d(t)):t}),typeof r=="function"&&(r=r.call(t,t));let o=t[x];o||tt(t);let c=n.call(t,r);return o||t.dispatchEvent(new Event("dde:connected")),e.nodeType===11&&typeof e.mode=="string"&&t.addEventListener("dde:disconnected",m.observe(e),{once:!0}),g.pop(),e.append(c)}function tt(t){return M(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event("dde:connected"))}),M(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event("dde:disconnected")))}),M(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent("dde:attributeChanged",{detail:[o,c]})),e.apply(n,r)}),t.prototype[x]=!0,t}function M(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}function et(t){return k(t,(e,n)=>e.getAttribute(n))}function At(t,e,n){return e||(e={}),function(o,...c){n&&(c.unshift(o),o=typeof n=="function"?n():n);let s=c.length?new CustomEvent(t,Object.assign({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(s)}}function D(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}var nt=new WeakSet;D.connected=function(t,e){let{custom_element:n}=g.current,r="connected";return typeof e!="object"&&(e={}),e.once=!0,function(c){n&&(c=n);let s="dde:"+r;return c.addEventListener(s,t,e),c[x]?c:c.isConnected?(c.dispatchEvent(new Event(s)),c):(O(e.signal,()=>m.offConnected(c,t))&&m.onConnected(c,t),c)}};D.disconnected=function(t,e){let{custom_element:n}=g.current,r="disconnected";return typeof e!="object"&&(e={}),e.once=!0,function(c){n&&(c=n);let s="dde:"+r;return c.addEventListener(s,t,e),c[x]||O(e.signal,()=>m.offDisconnected(c,t))&&m.onDisconnected(c,t),c}};var P=new WeakMap;D.disconnectedAsAbort=function(t){if(P.has(t))return P.get(t);let e=new AbortController;return P.set(t,e),t(D.disconnected(()=>e.abort())),e};D.attributeChanged=function(t,e){let n="attributeChanged";return typeof e!="object"&&(e={}),function(o){let c="dde:"+n;if(o.addEventListener(c,t,e),o[x]||nt.has(o)||!a.M)return o;let s=new a.M(function(h){for(let{attributeName:l,target:p}of h)p.dispatchEvent(new CustomEvent(c,{detail:[l,p.getAttribute(l)]}))});return O(e.signal,()=>s.disconnect())&&s.observe(o,{attributes:!0}),o}};export{C as assign,F as assignAttribute,Z as chainableAppend,V as classListDeclarative,T as createElement,at as createElementNS,xt as customElementRender,tt as customElementWithDDE,At as dispatchEvent,T as el,at as elNS,J as elementAttribute,dt as empty,tt as lifecycleToEvents,et as observedAttributes,D as on,z as registerReactivity,g as scope,ft as simulateSlots};