mirror of
https://github.com/jaandrle/deka-dom-el
synced 2024-11-22 07:49:38 +01:00
2 lines
6.8 KiB
JavaScript
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 g(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 L={setDeleteAttr:U};function U(t,e,n){if(Reflect.set(t,e,n),!!g(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,inherit_host:!1}],S={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,s,f;switch((Object(e)!==e||o.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{r=1;let{inherit_host:d,host:p}=S.current,l=d?p:c=>c?(r===1?n.unshift(c):c(f),void 0):f;S.push({scope:t,host:l,inherit_host:d}),s=t(e||void 0);let h=s instanceof DocumentFragment,i=E.mark({type:"component",name:t.name,host:h?"this":s.nodeName==="#comment"?"previousLater":"parentElement"});s.prepend(i),h&&(f=i);break}case t==="#text":s=w.call(this,document.createTextNode(""),e);break;case(t==="<>"||!t):s=w.call(this,document.createDocumentFragment(),e);break;case A:s=w.call(this,document.createElementNS(A,t),e);break;case!s:s=w.call(this,document.createElement(t),e)}return B(s),f||(f=s),n.forEach(d=>d(f)),r&&S.pop(),r=2,s}E.mark=function(t,e=!1){t=Object.entries(t).map(([r,s])=>r+`="${s}"`).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}=L,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),s=this;n=r.processReactiveAttribute(t,e,n,(d,p)=>P.call(s,t,d,p));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 R(r,n,D.bind(null,t[e]));case"ariaset":return R(r,n,(d,p)=>o("aria-"+d,p));case"classList":return q.call(s,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 R(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!g(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 R(t,e,n){if(!(typeof e!="object"||e===null))return Object.entries(e).forEach(function([r,s]){r&&(s=t.processReactiveAttribute(e,r,s,n),n(r,s))})}function M(t){return Array.isArray(t)?t.filter(Boolean).join(" "):t}function F(t,e,n,o){return t[(g(o)?"remove":"set")+e](n,M(o))}function k(t,e,n,o,r=null){return t[(g(o)?"remove":"set")+e+"NS"](r,n,M(o))}function D(t,e,n){if(Reflect.set(t,e,n),!!g(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 y(t,e,n){return function(r){return r.addEventListener(t,e,n),r}}var C=Z(),I=new WeakSet;y.connected=function(t,e){let n="connected";return typeof e!="object"&&(e={}),e.once=!0,function(r){let s="dde:"+n;return r.addEventListener(s,t,e),r.__dde_lifecycleToEvents?r:r.isConnected?(r.dispatchEvent(new Event(s)),r):(x(e.signal,()=>C.offConnected(r,t))&&C.onConnected(r,t),r)}};y.disconnected=function(t,e){let n="disconnected";return typeof e!="object"&&(e={}),e.once=!0,function(r){let s="dde:"+n;return r.addEventListener(s,t,e),r.__dde_lifecycleToEvents||x(e.signal,()=>C.offDisconnected(r,t))&&C.onDisconnected(r,t),r}};y.attributeChanged=function(t,e){let n="attributeChanged";return typeof e!="object"&&(e={}),function(r){let s="dde:"+n;if(r.addEventListener(s,t,e),r.__dde_lifecycleToEvents||I.has(r))return r;let f=new MutationObserver(function(p){for(let{attributeName:l,target:h}of p)h.dispatchEvent(new CustomEvent(s,{detail:[l,h.getAttribute(l)]}))});return x(e.signal,()=>f.disconnect())&&f.observe(r,{attributes:!0}),r}};function Z(){let t=new Map,e=!1,n=new MutationObserver(function(i){for(let c of i)if(c.type==="childList"){if(l(c.addedNodes,!0)){f();continue}h(c.removedNodes,!0)&&f()}});return{onConnected(i,c){s();let u=r(i);u.connected.has(c)||(u.connected.add(c),u.length_c+=1)},offConnected(i,c){if(!t.has(i))return;let u=t.get(i);u.connected.has(c)&&(u.connected.delete(c),u.length_c-=1,o(i,u))},onDisconnected(i,c){s();let u=r(i);u.disconnected.has(c)||(u.disconnected.add(c),u.length_d+=1)},offDisconnected(i,c){if(!t.has(i))return;let u=t.get(i);u.disconnected.has(c)&&(u.disconnected.delete(c),u.length_d-=1,o(i,u))}};function o(i,c){c.length_c||c.length_d||(t.delete(i),f())}function r(i){if(t.has(i))return t.get(i);let c={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(i,c),c}function s(){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(i){(requestIdleCallback||requestAnimationFrame)(i)})}async function p(i){t.size>30&&await d();let c=[];if(!(i instanceof Node))return c;for(let u of t.keys())u===i||!(u instanceof Node)||i.contains(u)&&c.push(u);return c}function l(i,c){let u=!1;for(let a of i){if(c&&p(a).then(l),!t.has(a))continue;let b=t.get(a);b.length_c&&(a.dispatchEvent(new Event("dde:connected")),b.connected=new WeakSet,b.length_c=0,b.length_d||t.delete(a),u=!0)}return u}function h(i,c){let u=!1;for(let a of i)c&&p(a).then(h),!(!t.has(a)||!t.get(a).length_d)&&(a.dispatchEvent(new Event("dde:disconnected")),t.delete(a),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,y as on,$ as registerReactivity,S as scope};
|