mirror of
https://github.com/jaandrle/deka-dom-el
synced 2025-04-02 04:05:52 +02:00
4 lines
13 KiB
JavaScript
4 lines
13 KiB
JavaScript
var W=(...t)=>Object.prototype.hasOwnProperty.call(...t);function A(t){return typeof t>"u"}function rt(t){let e=typeof t;return e!=="object"?e:t===null?"null":Object.prototype.toString.call(t)}function _(t,e){return t instanceof e}function ot(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function S(t=null,e={}){return Object.create(t,e)}function b(...t){return Object.assign(...t)}function Z(t,e){if(!t||!_(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}function ct(t,e){let{observedAttributes:n=[]}=t.constructor;return n.reduce(function(r,o){return r[St(o)]=e(t,o),r},{})}function St(t){return t.replace(/-./g,e=>e[1].toUpperCase())}var p={setDeleteAttr:wt,ssr:"",D:globalThis.document,N:globalThis.Node,F:globalThis.DocumentFragment,H:globalThis.HTMLElement,S:globalThis.SVGElement,M:globalThis.MutationObserver,q:t=>t||Promise.resolve()};function wt(t,e,n){if(Reflect.set(t,e,n),!!A(n)){if(Reflect.deleteProperty(t,e),_(t,p.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var M="__dde_lifecyclesToEvents",C="dde:connected",R="dde:disconnected",j="dde:attributeChanged";var D=p.M?yt():new Proxy({},{get(){return()=>{}}});function yt(){let t=new Map,e=!1,n=u=>function(a){for(let f of a)if(f.type==="childList"){if(m(f.addedNodes,!0)){u();continue}g(f.removedNodes,!0)&&u()}},r=new p.M(n(s));return{observe(u){let a=new p.M(n(()=>{}));return a.observe(u,{childList:!0,subtree:!0}),()=>a.disconnect()},onConnected(u,a){i();let f=c(u);f.connected.has(a)||(f.connected.add(a),f.length_c+=1)},offConnected(u,a){if(!t.has(u))return;let f=t.get(u);f.connected.has(a)&&(f.connected.delete(a),f.length_c-=1,o(u,f))},onDisconnected(u,a){i();let f=c(u);f.disconnected.has(a)||(f.disconnected.add(a),f.length_d+=1)},offDisconnected(u,a){if(!t.has(u))return;let f=t.get(u);f.disconnected.delete(a),f.length_d-=1,o(u,f)}};function o(u,a){a.length_c||a.length_d||(t.delete(u),s())}function c(u){if(t.has(u))return t.get(u);let a={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(u,a),a}function i(){e||(e=!0,r.observe(p.D.body,{childList:!0,subtree:!0}))}function s(){!e||t.size||(e=!1,r.disconnect())}function d(){return new Promise(function(u){(requestIdleCallback||requestAnimationFrame)(u)})}async function h(u){t.size>30&&await d();let a=[];if(!_(u,p.N))return a;for(let f of t.keys())f===u||!_(f,p.N)||u.contains(f)&&a.push(f);return a}function m(u,a){let f=!1;for(let w of u){if(a&&h(w).then(m),!t.has(w))continue;let k=t.get(w);k.length_c&&(w.dispatchEvent(new Event(C)),k.connected=new WeakSet,k.length_c=0,k.length_d||t.delete(w),f=!0)}return f}function g(u,a){let f=!1;for(let w of u)a&&h(w).then(g),!(!t.has(w)||!t.get(w).length_d)&&((globalThis.queueMicrotask||setTimeout)(J(w)),f=!0);return f}function J(u){return()=>{u.isConnected||(u.dispatchEvent(new Event(R)),t.delete(u))}}}function Ht(t,e,n){return typeof e=="function"&&(n=e,e=null),e||(e={}),function(o,...c){n&&(c.unshift(o),o=typeof n=="function"?n():n);let i=c.length?new CustomEvent(t,b({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(i)}}function y(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}y.defer=t=>setTimeout.bind(null,t,0);var it=t=>b({},typeof t=="object"?t:null,{once:!0});y.connected=function(t,e){return e=it(e),function(r){return r.addEventListener(C,t,e),r[M]?r:r.isConnected?(r.dispatchEvent(new Event(C)),r):(Z(e.signal,()=>D.offConnected(r,t))&&D.onConnected(r,t),r)}};y.disconnected=function(t,e){return e=it(e),function(r){return r.addEventListener(R,t,e),r[M]||Z(e.signal,()=>D.offDisconnected(r,t))&&D.onDisconnected(r,t),r}};var O=[{get scope(){return p.D.body},host:t=>t?t(p.D.body):p.D.body,prevent:!0}],G=new WeakMap,x={get current(){return O[O.length-1]},get host(){return this.current.host},get signal(){let{host:t}=this;if(G.has(t))return G.get(t);let e=new AbortController;return G.set(t,e),t(y.disconnected(()=>e.abort())),e.signal},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...O]},push(t={}){return O.push(b({},this.current,{prevent:!1},t))},pushRoot(){return O.push(O[0])},pop(){if(O.length!==1)return O.pop()}};var P={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function V(t,e=!0){return e?b(P,t):(Object.setPrototypeOf(t,P),t)}function F(t){return ot(t,P)&&t!==P?t:P}function st(t,e,n,r){return t[(A(r)?"remove":"set")+e](n,r)}function ut(t,e,n,r,o=null){return t[(A(r)?"remove":"set")+e+"NS"](o,n,r)}function K(t,e,n){if(Reflect.set(t,e,n),!!A(n))return Reflect.deleteProperty(t,e)}function ft(t,e,n,r){return _(t,p.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function ce(t){return p.q(t)}function at(...t){return this.appendOriginal(...t),this}function At(t){return t.append===at||(t.appendOriginal=t.append,t.append=at),t}var U;function q(t,e,...n){let r=F(this),o=0,c,i,s=typeof e;switch((s==="string"||s==="number"||r.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1;let d=(...g)=>g.length?(o===1?n.unshift(...g):g.forEach(J=>J(i)),void 0):i;x.push({scope:t,host:d}),c=t(e||void 0);let h=_(c,p.F);if(c.nodeName==="#comment")break;let m=q.mark({type:"component",name:t.name,host:h?"this":"parentElement"});c.prepend(m),h&&(i=m);break}case t==="#text":c=I.call(this,p.D.createTextNode(""),e);break;case(t==="<>"||!t):c=I.call(this,p.D.createDocumentFragment(),e);break;case!!U:c=I.call(this,p.D.createElementNS(U,t),e);break;case!c:c=I.call(this,p.D.createElement(t),e)}return At(c),i||(i=c),n.forEach(d=>d(i)),o&&x.pop(),o=2,c}q.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=p.D.createComment(`<dde:mark ${t}${p.ssr}${n}>`);return e&&(r.end=p.D.createComment("</dde:mark>")),r};function se(t){let e=this;return function(...r){U=t;let o=q.call(e,...r);return U=void 0,o}}var $=new WeakMap,{setDeleteAttr:pt}=p;function I(t,...e){if(!e.length)return t;$.set(t,lt(t,this));for(let[n,r]of Object.entries(b({},...e)))dt.call(this,t,n,r);return $.delete(t),t}function dt(t,e,n){let{setRemoveAttr:r,s:o}=lt(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(s,d)=>dt.call(c,t,s,d));let[i]=e;if(i==="=")return r(e.slice(1),n);if(i===".")return K(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 pt(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return Q(o,e,t,n,K.bind(null,t[e]));case"ariaset":return Q(o,e,t,n,(s,d)=>r("aria-"+s,d));case"classList":return Ct.call(c,t,n)}return Ot(t,e)?pt(t,e,n):r(e,n)}function lt(t,e){if($.has(t))return $.get(t);let r=(_(t,p.S)?ut:st).bind(null,t,"Attribute"),o=F(e);return{setRemoveAttr:r,s:o}}function Ct(t,e){let n=F(this);return Q(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function Ot(t,e){if(!(e in t))return!1;let n=ht(t,e);return!A(n.set)}function ht(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||ht(t,e)}function Q(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([s,d]){s&&(s=new c(s),s.target=e,d=t.processReactiveAttribute(n,s,d,o),o(s,d))})}function me(t,e=t){let n="\xB9\u2070",r="\u2713",o=Object.fromEntries(Array.from(e.querySelectorAll("slot")).filter(c=>!c.name.endsWith(n)).map(c=>[c.name+=n,c]));if(t.append=new Proxy(t.append,{apply(c,i,s){if(s[0]===e)return c.apply(t,s);for(let d of s){let h=(d.slot||"")+n;try{ft(d,"remove","slot")}catch{}let m=o[h];if(!m)return;m.name.startsWith(r)||(m.childNodes.forEach(g=>g.remove()),m.name=r+h),m.append(d)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}function ge(t,e,n={}){let r=t.host||t;x.push({scope:r,host:(...i)=>i.length?i.forEach(s=>s(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[M];o||Rt(r);let c=e.call(r,n);return o||r.dispatchEvent(new Event(C)),t.nodeType===11&&typeof t.mode=="string"&&r.addEventListener(R,D.observe(t),{once:!0}),x.pop(),t.append(c)}function Rt(t){return X(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(C))}),X(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(R)))}),X(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(j,{detail:[o,c]})),e.apply(n,r)}),t.prototype[M]=!0,t}function X(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}var mt="__dde_memo_of",z=[];function T(t,e){if(!z.length)return e(t);let n=typeof t=="object"?JSON.stringify(t):t,[{cache:r,after:o}]=z;return o(n,W(r,n)?r[n]:e(t))}T.isScope=function(t){return!!t[mt]};T.scope=function(e,{signal:n,onlyLast:r}={}){let o=S();function c(...i){if(n&&n.aborted)return e.apply(this,i);let s=r?o:S();z.unshift({cache:o,after(h,m){return s[h]=m}});let d=e.apply(this,i);return z.shift(),o=s,d}return c[mt]=e,c.clear=()=>o=S(),n&&n.addEventListener("abort",c.clear),c};var l="__dde_signal",Y=(()=>{let t=new Map,e=!1;function n(){e=!1;let r=t;t=new Map;for(let[o,c]of r){let i=o[l];i&&i.listeners.forEach(s=>s(i.value,c))}}return function(r,o=!1){t.set(r,t.get(r)||o),!e&&(e=!0,queueMicrotask(n))}})();var et=S(null,{get:{value(){return vt(this)}},set:{value(...t){return _t(this,...t)}},toJSON:{value(){return vt(this)}},valueOf:{value(){return this[l]&&this[l].value}}}),Dt=S(et,{set:{value(){}}});function H(t){return t&&t[l]}var B=[],E=new WeakMap;function v(t,e){if(typeof t!="function")return gt(!1,t,e);if(H(t))return t;let n=gt(!0);function r(o,c){let[i,...s]=E.get(r);if(E.set(r,new Set([i])),B.push(r),_t(n,t(),c),B.pop(),!s.length)return;let d=E.get(r);for(let h of s)d.has(h)||N(h,r)}return E.set(n[l],r),E.set(r,new Set([n])),r(),n}v.action=function(t,e,...n){let r=t[l];if(!r)return;let{actions:o}=r;if(!o||!W(o,e))throw new Error(`Action "${e}" not defined. See ${l}.actions.`);if(o[e].apply(r,n),r.skip)return delete r.skip;Y(t,!0)};v.on=function t(e,n,r={}){let{signal:o}=r;if(!(o&&o.aborted)){if(Array.isArray(e))return e.forEach(c=>t(c,n,r));nt(e,n),o&&o.addEventListener("abort",()=>N(e,n))}};v.symbols={onclear:Symbol.for("Signal.onclear")};v.clear=function(...t){for(let n of t){let r=n[l];r&&(delete n.toJSON,r.onclear.forEach(o=>o.call(r)),e(n,r),delete n[l])}function e(n,r){r.listeners.forEach(o=>{if(r.listeners.delete(o),!E.has(o))return;let c=E.get(o);c.delete(n),!(c.size>1)&&(n.clear(...c),E.delete(o))})}};var L="__dde_reactive";v.el=function(t,e){e=T.isScope(e)?e:T.scope(e,{onlyLast:!0});let{current:n}=x,{scope:r}=n,o=q.mark({type:"reactive",component:r&&r.name||""},!0),c=o.end,i=p.D.createDocumentFragment();i.append(o,c);let s=d=>{if(!o.parentNode||!c.parentNode)return N(t,s);x.push(n);let h=e(d);x.pop(),Array.isArray(h)||(h=[h]);let m=document.createComment("");h.push(m),o.after(...h);let g;for(;(g=m.nextSibling)&&g!==c;)g.remove();m.remove(),o.isConnected&&Lt(n.host())};return nt(t,s),xt(t,s,o,e),s(t.get()),n.host(y.disconnected(()=>e.clear())),i};function Lt(t){!t||!t[L]||(requestIdleCallback||setTimeout)(function(){t[L]=t[L].filter(([e,n])=>n.isConnected?!0:(N(...e),!1))})}var Nt={_set(t){this.value=t}};function Mt(t){return function(e,n){let r=S(et,{set:{value(...c){return e.setAttribute(n,...c)}}}),o=Et(r,e.getAttribute(n),Nt);return t[n]=o,o}}var tt="__dde_attributes";v.observedAttributes=function(t){let e=t[tt]={},n=ct(t,Mt(e));return y(j,function({detail:o}){/*! This maps attributes to signals (`S.observedAttributes`).
|
|
Investigate `__dde_attributes` key of the element. */let[c,i]=o,s=this[tt][c];if(s)return v.action(s,"_set",i)})(t),y.disconnected(function(){/*! This removes all signals mapped to attributes (`S.observedAttributes`).
|
|
Investigate `__dde_attributes` key of the element. */v.clear(...Object.values(this[tt]))})(t),n};var bt={isSignal:H,processReactiveAttribute(t,e,n,r){if(!H(n))return n;let o=c=>{if(!t.isConnected)return N(n,o);r(e,c)};return nt(n,o),xt(n,o,t,e),n.get()}};function xt(t,e,...n){let{current:r}=x;r.host(function(o){if(o[L])return o[L].push([[t,e],...n]);o[L]=[],!r.prevent&&y.disconnected(()=>o[L].forEach(([[c,i]])=>N(c,i,c[l]&&c[l].host&&c[l].host()===o)))(o)})}var Tt=new FinalizationRegistry(function(t){v.clear({[l]:t})});function gt(t,e,n){let r=S(t?Dt:et),o=Et(r,e,n,t);return Tt.register(o,o[l]),o}var kt=b(S(),{stopPropagation(){this.skip=!0}});function Et(t,e,n,r=!1){let o=[];rt(n)!=="[object Object]"&&(n={});let{onclear:c}=v.symbols;n[c]&&(o.push(n[c]),delete n[c]);let{host:i}=x;return Reflect.defineProperty(t,l,{value:b(S(kt),{value:e,actions:n,onclear:o,host:i,listeners:new Set,readonly:r}),enumerable:!1,writable:!1,configurable:!0}),t}function Pt(){return B[B.length-1]}function vt(t){if(!t[l])return;let{value:e,listeners:n}=t[l],r=Pt();return r&&n.add(r),E.has(r)&&E.get(r).add(t),e}function _t(t,e,n){let r=t[l];if(!(!r||!n&&r.value===e))return r.value=e,Y(t,n),e}function nt(t,e){if(t[l])return t[l].listeners.add(e)}function N(t,e,n){let r=t[l];if(!r)return;let{listeners:o}=r,c=o.delete(e);if(!c||!n||o.size)return c;v.clear(t);let i=E.get(r);if(!i)return c;let s=E.get(i);if(!s)return c;for(let d of s)N(d,i,!0);return c}V(bt);export{v as S,I as assign,dt as assignAttribute,At as chainableAppend,Ct as classListDeclarative,q as createElement,se as createElementNS,ge as customElementRender,Rt as customElementWithDDE,Ht as dispatchEvent,q as el,se as elNS,H as isSignal,Rt as lifecyclesToEvents,T as memo,y as on,ce as queue,V as registerReactivity,x as scope,v as signal,me as simulateSlots};
|