1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-22 07:49:38 +01:00
deka-dom-el/dist/esm.js

2 lines
6.8 KiB
JavaScript

var m={isSignal(t){return!1},processReactiveAttribute(t,e,n,o){return n}};function $(t,e=!0){return e?Object.assign(m,t):(Object.setPrototypeOf(t,m),t)}function _(t){return m.isPrototypeOf(t)&&t!==m?t:m}function l(t){return typeof t>"u"}function x(t,e){if(!t||!(t instanceof AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var y={setDeleteAttr:U};function U(t,e,n){if(Reflect.set(t,e,n),!!l(n)){if(Reflect.deleteProperty(t,e),t instanceof HTMLElement&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var v=[{scope:document.body,host:t=>t?t(document.body):document.body,prevent:!0}],L={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))},pop(){return v.pop()}},A;function E(t,e,...n){let o=_(this),r=0,c,f;switch((Object(e)!==e||o.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{r=1,L.push({scope:t,host:h=>h?(r===1?n.unshift(h):h(f),void 0):f}),c=t(e||void 0);let d=c instanceof DocumentFragment,a=E.mark({type:"component",name:t.name,host:d?"this":c.nodeName==="#comment"?"previousLater":"parentElement"});c.prepend(a),d&&(f=a);break}case t==="#text":c=w.call(this,document.createTextNode(""),e);break;case(t==="<>"||!t):c=w.call(this,document.createDocumentFragment(),e);break;case A:c=w.call(this,document.createElementNS(A,t),e);break;case!c:c=w.call(this,document.createElement(t),e)}return B(c),f||(f=c),n.forEach(d=>d(f)),r&&L.pop(),r=2,c}E.mark=function(t,e=!1){t=Object.entries(t).map(([r,c])=>r+`="${c}"`).join(" ");let n=e?"":"/",o=document.createComment(`<dde:mark ${t}${n}>`);return e||(o.end=document.createComment("</dde:mark>")),o};E.later=function(){let t=E.mark({type:"later"});return t.append=t.prepend=function(...e){return t.after(...e),t},t};function Q(t){let e=this;return function(...o){A=t;let r=E.call(e,...o);return A=void 0,r}}var{setDeleteAttr:N}=y,O=new WeakMap;function w(t,...e){if(!e.length)return t;O.set(t,T(t,this));for(let[n,o]of Object.entries(Object.assign({},...e)))P.call(this,t,n,o);return O.delete(t),t}function P(t,e,n){let{setRemoveAttr:o,s:r}=T(t,this),c=this;n=r.processReactiveAttribute(t,e,n,(d,a)=>P.call(c,t,d,a));let[f]=e;if(f==="=")return o(e.slice(1),n);if(f===".")return D(t,e.slice(1),n);if(/(aria|data)([A-Z])/.test(e))return e=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),o(e,n);switch(e==="className"&&(e="class"),e){case"xlink:href":return o(e,n,"http://www.w3.org/1999/xlink");case"textContent":return N(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return S(r,n,D.bind(null,t[e]));case"ariaset":return S(r,n,(d,a)=>o("aria-"+d,a));case"classList":return q.call(c,t,n)}return z(t,e)?N(t,e,n):o(e,n)}function T(t,e){if(O.has(t))return O.get(t);let o=(t instanceof SVGElement?k:F).bind(null,t,"Attribute"),r=_(e);return{setRemoveAttr:o,s:r}}function q(t,e){let n=_(this);return S(n,e,(o,r)=>t.classList.toggle(o,r===-1?void 0:!!r)),t}function Y(t){return Array.from(t.children).forEach(e=>e.remove()),t}function z(t,e){if(!Reflect.has(t,e))return!1;let n=W(t,e);return!l(n.set)}function W(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||W(t,e)}function S(t,e,n){if(!(typeof e!="object"||e===null))return Object.entries(e).forEach(function([r,c]){r&&(c=t.processReactiveAttribute(e,r,c,n),n(r,c))})}function M(t){return Array.isArray(t)?t.filter(Boolean).join(" "):t}function F(t,e,n,o){return t[(l(o)?"remove":"set")+e](n,M(o))}function k(t,e,n,o,r=null){return t[(l(o)?"remove":"set")+e+"NS"](r,n,M(o))}function D(t,e,n){if(Reflect.set(t,e,n),!!l(n))return Reflect.deleteProperty(t,e)}function j(...t){return this.appendOrig(...t),this}function B(t){return t.append===j||(t.appendOrig=t.append,t.append=j),t}function nt(t,e,...n){let o=n.length?new CustomEvent(e,{detail:n[0]}):new Event(e);return t.dispatchEvent(o)}function R(t,e,n){return function(r){return r.addEventListener(t,e,n),r}}var C=Z(),I=new WeakSet;R.connected=function(t,e){let n="connected";return typeof e!="object"&&(e={}),e.once=!0,function(r){let c="dde:"+n;return r.addEventListener(c,t,e),r.__dde_lifecycleToEvents?r:r.isConnected?(r.dispatchEvent(new Event(c)),r):(x(e.signal,()=>C.offConnected(r,t))&&C.onConnected(r,t),r)}};R.disconnected=function(t,e){let n="disconnected";return typeof e!="object"&&(e={}),e.once=!0,function(r){let c="dde:"+n;return r.addEventListener(c,t,e),r.__dde_lifecycleToEvents||x(e.signal,()=>C.offDisconnected(r,t))&&C.onDisconnected(r,t),r}};R.attributeChanged=function(t,e){let n="attributeChanged";return typeof e!="object"&&(e={}),function(r){let c="dde:"+n;if(r.addEventListener(c,t,e),r.__dde_lifecycleToEvents||I.has(r))return r;let f=new MutationObserver(function(a){for(let{attributeName:h,target:g}of a)g.dispatchEvent(new CustomEvent(c,{detail:[h,g.getAttribute(h)]}))});return x(e.signal,()=>f.disconnect())&&f.observe(r,{attributes:!0}),r}};function Z(){let t=new Map,e=!1,n=new MutationObserver(function(s){for(let i of s)if(i.type==="childList"){if(h(i.addedNodes,!0)){f();continue}g(i.removedNodes,!0)&&f()}});return{onConnected(s,i){c();let u=r(s);u.connected.has(i)||(u.connected.add(i),u.length_c+=1)},offConnected(s,i){if(!t.has(s))return;let u=t.get(s);u.connected.has(i)&&(u.connected.delete(i),u.length_c-=1,o(s,u))},onDisconnected(s,i){c();let u=r(s);u.disconnected.has(i)||(u.disconnected.add(i),u.length_d+=1)},offDisconnected(s,i){if(!t.has(s))return;let u=t.get(s);u.disconnected.has(i)&&(u.disconnected.delete(i),u.length_d-=1,o(s,u))}};function o(s,i){i.length_c||i.length_d||(t.delete(s),f())}function r(s){if(t.has(s))return t.get(s);let i={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(s,i),i}function c(){e||(e=!0,n.observe(document.body,{childList:!0,subtree:!0}))}function f(){!e||t.size||(e=!1,n.disconnect())}function d(){return new Promise(function(s){(requestIdleCallback||requestAnimationFrame)(s)})}async function a(s){t.size>30&&await d();let i=[];if(!(s instanceof Node))return i;for(let u of t.keys())u===s||!(u instanceof Node)||s.contains(u)&&i.push(u);return i}function h(s,i){let u=!1;for(let p of s){if(i&&a(p).then(h),!t.has(p))continue;let b=t.get(p);b.length_c&&(p.dispatchEvent(new Event("dde:connected")),b.connected=new WeakSet,b.length_c=0,b.length_d||t.delete(p),u=!0)}return u}function g(s,i){let u=!1;for(let p of s)i&&a(p).then(g),!(!t.has(p)||!t.get(p).length_d)&&(p.dispatchEvent(new Event("dde:disconnected")),t.delete(p),u=!0);return u}}export{w as assign,P as assignAttribute,q as classListDeclarative,E as createElement,Q as createElementNS,nt as dispatchEvent,E as el,Q as elNS,Y as empty,R as on,$ as registerReactivity,L as scope};