mirror of
https://github.com/jaandrle/deka-dom-el
synced 2025-04-02 20:15:53 +02:00
* 🔤 ⚡ T now uses DocumentFragment * 🔤 * 🔤 ⚡ * 🐛 lint * ⚡ cleanup * ⚡ 🔤 lib download * ⚡ 🔤 ui * ⚡ reorganize files * ⚡ on.host * 🐛 on.* types * ⚡ 🔤 cdn * 🔤 converter * 🐛 signal.set(value, force) * ⚡ 🔤 * 🔤 ⚡ converter - convert also comments * ⚡ bs/build * 🔤 ui p14 * 🔤 * 🔤 Examples * 🔤 * 🐛 now only el(..., string|number) * 🐛 fixes #38 * 🔤 * ⚡ on.host → on.defer * 🔤 * 📺
5 lines
14 KiB
JavaScript
5 lines
14 KiB
JavaScript
var DDE=(()=>{var V=Object.defineProperty;var Ot=Object.getOwnPropertyDescriptor;var Rt=Object.getOwnPropertyNames;var Dt=Object.prototype.hasOwnProperty;var Lt=(t,e)=>{for(var n in e)V(t,n,{get:e[n],enumerable:!0})},Nt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Rt(e))!Dt.call(t,o)&&o!==n&&V(t,o,{get:()=>e[o],enumerable:!(r=Ot(e,o))||r.enumerable});return t};var kt=t=>Nt(V({},"__esModule",{value:!0}),t);var Vt={};Lt(Vt,{S:()=>g,assign:()=>W,assignAttribute:()=>tt,chainableAppend:()=>mt,classListDeclarative:()=>vt,createElement:()=>T,createElementNS:()=>Wt,customElementRender:()=>Ut,customElementWithDDE:()=>xt,dispatchEvent:()=>qt,el:()=>T,elNS:()=>Wt,isSignal:()=>F,lifecyclesToEvents:()=>xt,memo:()=>L,on:()=>S,queue:()=>jt,registerReactivity:()=>$,scope:()=>v,signal:()=>g,simulateSlots:()=>It});var I=(...t)=>Object.prototype.hasOwnProperty.call(...t);function A(t){return typeof t>"u"}function st(t){let e=typeof t;return e!=="object"?e:t===null?"null":Object.prototype.toString.call(t)}function E(t,e){return t instanceof e}function it(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function _(t=null,e={}){return Object.create(t,e)}function b(...t){return Object.assign(...t)}function K(t,e){if(!t||!E(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}function ut(t,e){let{observedAttributes:n=[]}=t.constructor;return n.reduce(function(r,o){return r[Mt(o)]=e(t,o),r},{})}function Mt(t){return t.replace(/-./g,e=>e[1].toUpperCase())}var q=class extends Error{constructor(){super();let[e,...n]=this.stack.split(`
|
|
`),r=e.slice(e.indexOf("@"),e.indexOf(".js:")+4),o=r.includes("src/helpers.js")?"src/":r;this.stack=n.find(c=>!c.includes(o))||e}get compact(){let{stack:e}=this;return e.slice(0,e.indexOf("@")+1)+"\u2026"+e.slice(e.lastIndexOf("/"))}};var d={setDeleteAttr:Tt,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 Tt(t,e,n){if(Reflect.set(t,e,n),!!A(n)){if(Reflect.deleteProperty(t,e),E(t,d.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",U="dde:attributeChanged";var D=d.M?Pt():new Proxy({},{get(){return()=>{}}});function Pt(){let t=new Map,e=!1,n=u=>function(p){for(let f of p)if(f.type==="childList"){if(m(f.addedNodes,!0)){u();continue}y(f.removedNodes,!0)&&u()}},r=new d.M(n(i));return{observe(u){let p=new d.M(n(()=>{}));return p.observe(u,{childList:!0,subtree:!0}),()=>p.disconnect()},onConnected(u,p){s();let f=c(u);f.connected.has(p)||(f.connected.add(p),f.length_c+=1)},offConnected(u,p){if(!t.has(u))return;let f=t.get(u);f.connected.has(p)&&(f.connected.delete(p),f.length_c-=1,o(u,f))},onDisconnected(u,p){s();let f=c(u);f.disconnected.has(p)||(f.disconnected.add(p),f.length_d+=1)},offDisconnected(u,p){if(!t.has(u))return;let f=t.get(u);f.disconnected.delete(p),f.length_d-=1,o(u,f)}};function o(u,p){p.length_c||p.length_d||(t.delete(u),i())}function c(u){if(t.has(u))return t.get(u);let p={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(u,p),p}function s(){e||(e=!0,r.observe(d.D.body,{childList:!0,subtree:!0}))}function i(){!e||t.size||(e=!1,r.disconnect())}function a(){return new Promise(function(u){(requestIdleCallback||requestAnimationFrame)(u)})}async function h(u){t.size>30&&await a();let p=[];if(!E(u,d.N))return p;for(let f of t.keys())f===u||!E(f,d.N)||u.contains(f)&&p.push(f);return p}function m(u,p){let f=!1;for(let w of u){if(p&&h(w).then(m),!t.has(w))continue;let P=t.get(w);P.length_c&&(w.dispatchEvent(new Event(C)),P.connected=new WeakSet,P.length_c=0,P.length_d||t.delete(w),f=!0)}return f}function y(u,p){let f=!1;for(let w of u)p&&h(w).then(y),!(!t.has(w)||!t.get(w).length_d)&&((globalThis.queueMicrotask||setTimeout)(G(w)),f=!0);return f}function G(u){return()=>{u.isConnected||(u.dispatchEvent(new Event(R)),t.delete(u))}}}function qt(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 s=c.length?new CustomEvent(t,b({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(s)}}function S(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}S.defer=t=>setTimeout.bind(null,t,0);var ft=t=>b({},typeof t=="object"?t:null,{once:!0});S.connected=function(t,e){return e=ft(e),function(r){return r.addEventListener(C,t,e),r[M]?r:r.isConnected?(r.dispatchEvent(new Event(C)),r):(K(e.signal,()=>D.offConnected(r,t))&&D.onConnected(r,t),r)}};S.disconnected=function(t,e){return e=ft(e),function(r){return r.addEventListener(R,t,e),r[M]||K(e.signal,()=>D.offDisconnected(r,t))&&D.onDisconnected(r,t),r}};var O=[{get scope(){return d.D.body},host:t=>t?t(d.D.body):d.D.body,prevent:!0}],Q=new WeakMap,v={get current(){return O[O.length-1]},get host(){return this.current.host},get signal(){let{host:t}=this;if(Q.has(t))return Q.get(t);let e=new AbortController;return Q.set(t,e),t(S.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 j={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function $(t,e=!0){return e?b(j,t):(Object.setPrototypeOf(t,j),t)}function z(t){return it(t,j)&&t!==j?t:j}function at(t,e,n,r){return t[(A(r)?"remove":"set")+e](n,r)}function pt(t,e,n,r,o=null){return t[(A(r)?"remove":"set")+e+"NS"](o,n,r)}function X(t,e,n){if(Reflect.set(t,e,n),!!A(n))return Reflect.deleteProperty(t,e)}function dt(t,e,n,r){return E(t,d.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function jt(t){return d.q(t)}function lt(...t){return this.appendOriginal(...t),this}function mt(t){return t.append===lt||(t.appendOriginal=t.append,t.append=lt),t}var H;function T(t,e,...n){let r=z(this),o=0,c,s,i=typeof e;switch((i==="string"||i==="number"||r.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1;let a=(...y)=>y.length?(o===1?n.unshift(...y):y.forEach(G=>G(s)),void 0):s;v.push({scope:t,host:a}),c=t(e||void 0);let h=E(c,d.F);if(c.nodeName==="#comment")break;let m=T.mark({type:"component",name:t.name,host:h?"this":"parentElement"});c.prepend(m),h&&(s=m);break}case t==="#text":c=W.call(this,d.D.createTextNode(""),e);break;case(t==="<>"||!t):c=W.call(this,d.D.createDocumentFragment(),e);break;case!!H:c=W.call(this,d.D.createElementNS(H,t),e);break;case!c:c=W.call(this,d.D.createElement(t),e)}return mt(c),s||(s=c),n.forEach(a=>a(s)),o&&v.pop(),o=2,c}T.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=d.D.createComment(`<dde:mark ${t}${d.ssr}${n}>`);return e&&(r.end=d.D.createComment("</dde:mark>")),r};function Wt(t){let e=this;return function(...r){H=t;let o=T.call(e,...r);return H=void 0,o}}var J=new WeakMap,{setDeleteAttr:ht}=d;function W(t,...e){if(!e.length)return t;J.set(t,gt(t,this));for(let[n,r]of Object.entries(b({},...e)))tt.call(this,t,n,r);return J.delete(t),t}function tt(t,e,n){let{setRemoveAttr:r,s:o}=gt(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(i,a)=>tt.call(c,t,i,a));let[s]=e;if(s==="=")return r(e.slice(1),n);if(s===".")return X(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 ht(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return Y(o,e,t,n,X.bind(null,t[e]));case"ariaset":return Y(o,e,t,n,(i,a)=>r("aria-"+i,a));case"classList":return vt.call(c,t,n)}return Ft(t,e)?ht(t,e,n):r(e,n)}function gt(t,e){if(J.has(t))return J.get(t);let r=(E(t,d.S)?pt:at).bind(null,t,"Attribute"),o=z(e);return{setRemoveAttr:r,s:o}}function vt(t,e){let n=z(this);return Y(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function Ft(t,e){if(!(e in t))return!1;let n=bt(t,e);return!A(n.set)}function bt(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||bt(t,e)}function Y(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([i,a]){i&&(i=new c(i),i.target=e,a=t.processReactiveAttribute(n,i,a,o),o(i,a))})}function It(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,s,i){if(i[0]===e)return c.apply(t,i);for(let a of i){let h=(a.slot||"")+n;try{dt(a,"remove","slot")}catch{}let m=o[h];if(!m)return;m.name.startsWith(r)||(m.childNodes.forEach(y=>y.remove()),m.name=r+h),m.append(a)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}function Ut(t,e,n={}){let r=t.host||t;v.push({scope:r,host:(...s)=>s.length?s.forEach(i=>i(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[M];o||xt(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}),v.pop(),t.append(c)}function xt(t){return et(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(C))}),et(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(R)))}),et(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(U,{detail:[o,c]})),e.apply(n,r)}),t.prototype[M]=!0,t}function et(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}var Et="__dde_memo",B=[];function L(t,e){if(!B.length)return e(t);let n=typeof t=="object"?JSON.stringify(t):t,[{cache:r,after:o}]=B;return o(n,I(r,n)?r[n]:e(t))}L.isScope=function(t){return t[Et]};L.scope=function(e,{signal:n,onlyLast:r}={}){let o=_();function c(...s){if(n&&n.aborted)return e.apply(this,s);let i=r?o:_();B.unshift({cache:o,after(h,m){return i[h]=m}});let a=e.apply(this,s);return B.shift(),o=i,a}return c[Et]=!0,c.clear=()=>o=_(),n&&n.addEventListener("abort",c.clear),c};var l="__dde_signal",nt=(()=>{let t=new Map,e=!1;function n(){e=!1;let r=t;t=new Map;for(let[o,c]of r){let s=o[l];s&&s.listeners.forEach(i=>i(s.value,c))}}return function(r,o=!1){t.set(r,t.get(r)||o),!e&&(e=!0,queueMicrotask(n))}})();var ot=_(null,{get:{value(){return St(this)}},set:{value(...t){return Ct(this,...t)}},toJSON:{value(){return St(this)}},valueOf:{value(){return this[l]&&this[l].value}}}),$t=_(ot,{set:{value(){}}});function F(t){return t&&t[l]}var Z=[],x=new WeakMap;function g(t,e){if(typeof t!="function")return _t(!1,t,e);if(F(t))return t;let n=_t(!0);function r(o,c){let[s,...i]=x.get(r);if(x.set(r,new Set([s])),Z.push(r),Ct(n,t(),c),Z.pop(),!i.length)return;let a=x.get(r);for(let h of i)a.has(h)||k(h,r)}return x.set(n[l],r),x.set(r,new Set([n])),r(),n}g.action=function(t,e,...n){let r=t[l];if(!r)return;let{actions:o}=r;if(!o||!I(o,e))throw new Error(`Action "${e}" not defined. See ${l}.actions.`);if(o[e].apply(r,n),r.skip)return delete r.skip;nt(t,!0)};g.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));ct(e,n),o&&o.addEventListener("abort",()=>k(e,n))}};g.symbols={onclear:Symbol.for("Signal.onclear")};g.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),!x.has(o))return;let c=x.get(o);c.delete(n),!(c.size>1)&&(n.clear(...c),x.delete(o))})}};var N="__dde_reactive";g.el=function(t,e){e=L.isScope(e)?e:L.scope(e,{onlyLast:!0});let n=T.mark({type:"reactive",source:new q().compact},!0),r=n.end,o=d.D.createDocumentFragment();o.append(n,r);let{current:c}=v,s=i=>{if(!n.parentNode||!r.parentNode)return k(t,s);v.push(c);let a=e(i);v.pop(),Array.isArray(a)||(a=[a]);let h=document.createComment("");a.push(h),n.after(...a);let m;for(;(m=h.nextSibling)&&m!==r;)m.remove();h.remove(),n.isConnected&&zt(c.host())};return ct(t,s),yt(t,s,n,e),s(t.get()),c.host(S.disconnected(()=>e.clear())),o};function zt(t){!t||!t[N]||(requestIdleCallback||setTimeout)(function(){t[N]=t[N].filter(([e,n])=>n.isConnected?!0:(k(...e),!1))})}var Ht={_set(t){this.value=t}};function Jt(t){return function(e,n){let r=_(ot,{set:{value(...c){return e.setAttribute(n,...c)}}}),o=At(r,e.getAttribute(n),Ht);return t[n]=o,o}}var rt="__dde_attributes";g.observedAttributes=function(t){let e=t[rt]={},n=ut(t,Jt(e));return S(U,function({detail:o}){/*! This maps attributes to signals (`S.observedAttributes`).
|
|
Investigate `__dde_attributes` key of the element. */let[c,s]=o,i=this[rt][c];if(i)return g.action(i,"_set",s)})(t),S.disconnected(function(){/*! This removes all signals mapped to attributes (`S.observedAttributes`).
|
|
Investigate `__dde_attributes` key of the element. */g.clear(...Object.values(this[rt]))})(t),n};var wt={isSignal:F,processReactiveAttribute(t,e,n,r){if(!F(n))return n;let o=c=>{if(!t.isConnected)return k(n,o);r(e,c)};return ct(n,o),yt(n,o,t,e),n.get()}};function yt(t,e,...n){let{current:r}=v;r.host(function(o){if(o[N])return o[N].push([[t,e],...n]);o[N]=[],!r.prevent&&S.disconnected(()=>o[N].forEach(([[c,s]])=>k(c,s,c[l]&&c[l].host&&c[l].host()===o)))(o)})}var Bt=new FinalizationRegistry(function(t){g.clear({[l]:t})});function _t(t,e,n){let r=_(t?$t:ot),o=At(r,e,n,t);return Bt.register(o,o[l]),o}var Zt=b(_(),{stopPropagation(){this.skip=!0}});function At(t,e,n,r=!1){let o=[];st(n)!=="[object Object]"&&(n={});let{onclear:c}=g.symbols;n[c]&&(o.push(n[c]),delete n[c]);let{host:s}=v;return Reflect.defineProperty(t,l,{value:b(_(Zt),{value:e,actions:n,onclear:o,host:s,listeners:new Set,defined:new q().stack,readonly:r}),enumerable:!1,writable:!1,configurable:!0}),t}function Gt(){return Z[Z.length-1]}function St(t){if(!t[l])return;let{value:e,listeners:n}=t[l],r=Gt();return r&&n.add(r),x.has(r)&&x.get(r).add(t),e}function Ct(t,e,n){let r=t[l];if(!(!r||!n&&r.value===e))return r.value=e,nt(t,n),e}function ct(t,e){if(t[l])return t[l].listeners.add(e)}function k(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;g.clear(t);let s=x.get(r);if(!s)return c;let i=x.get(s);if(!i)return c;for(let a of i)k(a,s,!0);return c}$(wt);return kt(Vt);})();
|