diff --git a/dist/dde-with-signals.js b/dist/dde-with-signals.js index 6b84714..ad8d415 100644 --- a/dist/dde-with-signals.js +++ b/dist/dde-with-signals.js @@ -1,23 +1,23 @@ //deka-dom-el library is available via global namespace `dde` (()=> { -var y={isSignal(t){return!1},processReactiveAttribute(t,e,n,o){return n}};function M(t,e=!0){return e?Object.assign(y,t):(Object.setPrototypeOf(t,y),t)}function R(t){return y.isPrototypeOf(t)&&t!==y?t:y}function _(t){return typeof t>"u"}function F(t){let e=typeof t;return e!=="object"?e:t===null?"null":Object.prototype.toString.call(t)}function C(t,e){if(!t||!(t instanceof AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var U={setDeleteAttr:X};function X(t,e,n){if(Reflect.set(t,e,n),!!_(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 w=[{scope:document.body,host:t=>t?t(document.body):document.body,prevent:!0}],E={get current(){return w[w.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...w]},push(t={}){return w.push(Object.assign({},this.current,{prevent:!1},t))},pop(){return w.pop()}},L;function v(t,e,...n){let o=R(this),r=0,c,s;switch((Object(e)!==e||o.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{r=1,E.push({scope:t,host:l=>l?(r===1?n.unshift(l):l(s),void 0):s}),c=t(e||void 0);let a=c instanceof DocumentFragment,d=v.mark({type:"component",name:t.name,host:a?"this":c.nodeName==="#comment"?"previousLater":"parentElement"});c.prepend(d),a&&(s=d);break}case t==="#text":c=N.call(this,document.createTextNode(""),e);break;case(t==="<>"||!t):c=N.call(this,document.createDocumentFragment(),e);break;case L:c=N.call(this,document.createElementNS(L,t),e);break;case!c:c=N.call(this,document.createElement(t),e)}return rt(c),s||(s=c),n.forEach(a=>a(s)),r&&E.pop(),r=2,c}v.mark=function(t,e=!1){t=Object.entries(t).map(([r,c])=>r+`="${c}"`).join(" ");let n=e?"":"/",o=document.createComment(``);return e||(o.end=document.createComment("")),o};v.later=function(){let t=v.mark({type:"later"});return t.append=t.prepend=function(...e){return t.after(...e),t},t};function bt(t){let e=this;return function(...o){L=t;let r=v.call(e,...o);return L=void 0,r}}var{setDeleteAttr:q}=U,j=new WeakMap;function N(t,...e){if(!e.length)return t;j.set(t,J(t,this));for(let[n,o]of Object.entries(Object.assign({},...e)))I.call(this,t,n,o);return j.delete(t),t}function I(t,e,n){let{setRemoveAttr:o,s:r}=J(t,this),c=this;n=r.processReactiveAttribute(t,e,n,(a,d)=>I.call(c,t,a,d));let[s]=e;if(s==="=")return o(e.slice(1),n);if(s===".")return H(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 q(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return W(r,n,H.bind(null,t[e]));case"ariaset":return W(r,n,(a,d)=>o("aria-"+a,d));case"classList":return Y.call(c,t,n)}return tt(t,e)?q(t,e,n):o(e,n)}function J(t,e){if(j.has(t))return j.get(t);let o=(t instanceof SVGElement?nt:et).bind(null,t,"Attribute"),r=R(e);return{setRemoveAttr:o,s:r}}function Y(t,e){let n=R(this);return W(n,e,(o,r)=>t.classList.toggle(o,r===-1?void 0:!!r)),t}function _t(t){return Array.from(t.children).forEach(e=>e.remove()),t}function tt(t,e){if(!Reflect.has(t,e))return!1;let n=Z(t,e);return!_(n.set)}function Z(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||Z(t,e)}function W(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 G(t){return Array.isArray(t)?t.filter(Boolean).join(" "):t}function et(t,e,n,o){return t[(_(o)?"remove":"set")+e](n,G(o))}function nt(t,e,n,o,r=null){return t[(_(o)?"remove":"set")+e+"NS"](r,n,G(o))}function H(t,e,n){if(Reflect.set(t,e,n),!!_(n))return Reflect.deleteProperty(t,e)}function B(...t){return this.appendOrig(...t),this}function rt(t){return t.append===B||(t.appendOrig=t.append,t.append=B),t}function xt(t,e,...n){let o=n.length?new CustomEvent(e,{detail:n[0]}):new Event(e);return t.dispatchEvent(o)}function m(t,e,n){return function(r){return r.addEventListener(t,e,n),r}}var P=ct(),ot=new WeakSet;m.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):(C(e.signal,()=>P.offConnected(r,t))&&P.onConnected(r,t),r)}};m.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||C(e.signal,()=>P.offDisconnected(r,t))&&P.onDisconnected(r,t),r}};m.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||ot.has(r))return r;let s=new MutationObserver(function(d){for(let{attributeName:l,target:x}of d)x.dispatchEvent(new CustomEvent(c,{detail:[l,x.getAttribute(l)]}))});return C(e.signal,()=>s.disconnect())&&s.observe(r,{attributes:!0}),r}};function ct(){let t=new Map,e=!1,n=new MutationObserver(function(i){for(let u of i)if(u.type==="childList"){if(l(u.addedNodes,!0)){s();continue}x(u.removedNodes,!0)&&s()}});return{onConnected(i,u){c();let f=r(i);f.connected.has(u)||(f.connected.add(u),f.length_c+=1)},offConnected(i,u){if(!t.has(i))return;let f=t.get(i);f.connected.has(u)&&(f.connected.delete(u),f.length_c-=1,o(i,f))},onDisconnected(i,u){c();let f=r(i);f.disconnected.has(u)||(f.disconnected.add(u),f.length_d+=1)},offDisconnected(i,u){if(!t.has(i))return;let f=t.get(i);f.disconnected.has(u)&&(f.disconnected.delete(u),f.length_d-=1,o(i,f))}};function o(i,u){u.length_c||u.length_d||(t.delete(i),s())}function r(i){if(t.has(i))return t.get(i);let u={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(i,u),u}function c(){e||(e=!0,n.observe(document.body,{childList:!0,subtree:!0}))}function s(){!e||t.size||(e=!1,n.disconnect())}function a(){return new Promise(function(i){(requestIdleCallback||requestAnimationFrame)(i)})}async function d(i){t.size>30&&await a();let u=[];if(!(i instanceof Node))return u;for(let f of t.keys())f===i||!(f instanceof Node)||i.contains(f)&&u.push(f);return u}function l(i,u){let f=!1;for(let b of i){if(u&&d(b).then(l),!t.has(b))continue;let S=t.get(b);S.length_c&&(b.dispatchEvent(new Event("dde:connected")),S.connected=new WeakSet,S.length_c=0,S.length_d||t.delete(b),f=!0)}return f}function x(i,u){let f=!1;for(let b of i)u&&d(b).then(x),!(!t.has(b)||!t.get(b).length_d)&&(b.dispatchEvent(new Event("dde:disconnected")),t.delete(b),f=!0);return f}}var p=Symbol.for("Signal");function D(t){try{return Reflect.has(t,p)}catch{return!1}}var T=[],h=new WeakMap;function g(t,e){if(typeof t!="function")return V(t,e);if(D(t))return t;let n=V(),o=function(){let[r,...c]=h.get(o);if(h.set(o,new Set([r])),T.push(o),n(t()),T.pop(),!c.length)return;let s=h.get(o);for(let a of c)s.has(a)||O(a,o)};return h.set(n[p],o),h.set(o,new Set([n])),o(),n}g.action=function(t,e,...n){let o=t[p],{actions:r}=o;if(!r||!Reflect.has(r,e))throw new Error(`'${t}' has no action with name '${e}'!`);if(r[e].apply(o,n),o.skip)return Reflect.deleteProperty(o,"skip");o.listeners.forEach(c=>c(o.value))};g.on=function t(e,n,o={}){let{signal:r}=o;if(!(r&&r.aborted)){if(Array.isArray(e))return e.forEach(c=>t(c,n,o));z(e,n),r&&r.addEventListener("abort",()=>O(e,n))}};g.symbols={signal:p,onclear:Symbol.for("Signal.onclear")};var A="__dde_attributes";g.attribute=function(t,e=void 0){let n=g(e),o;return E.host(r=>{if(o=r,r instanceof HTMLElement?r.hasAttribute(t)&&n(r.getAttribute(t)):r.hasAttributeNS(null,t)&&n(r.getAttributeNS(null,t)),r[A]){r[A][t]=n;return}return r[A]={[t]:n},m.attributeChanged(function({detail:s}){/*! This maps attributes to signals (`S.attribute`). -* Investigate `__dde_attributes` key of the element.*/let[a,d]=s,l=r[A][a];if(l)return l(d)})(r),m.disconnected(function(){/*! This removes all signals mapped to attributes (`S.attribute`). -* Investigate `__dde_attributes` key of the element.*/g.clear(...Object.values(r[A])),o=null})(r),r}),new Proxy(n,{apply(r,c,s){if(!s.length)return r();if(!o)return;let a=s[0];return o instanceof HTMLElement?o.setAttribute(t,a):o.setAttributeNS(null,t,a)}})};g.clear=function(...t){for(let n of t){Reflect.deleteProperty(n,"toJSON");let o=n[p];o.onclear.forEach(r=>r.call(o)),e(n,o),Reflect.deleteProperty(n,p)}function e(n,o){o.listeners.forEach(r=>{if(o.listeners.delete(r),!h.has(r))return;let c=h.get(r);c.delete(n),!(c.size>1)&&(g.clear(...c),h.delete(r))})}};var k="__dde_reactive";g.el=function(t,e){let n=v.mark({type:"reactive"},!1),o=n.end,r=document.createDocumentFragment();r.append(n,o);let{current:c}=E,s=a=>{if(!n.parentNode||!o.parentNode)return O(t,s);E.push(c);let d=e(a);E.pop(),Array.isArray(d)||(d=[d]);let l=n;for(;(l=n.nextSibling)!==o;)l.remove();n.after(...d)};return z(t,s),Q(t,s,n,e),s(t()),r};var K={isSignal:D,processReactiveAttribute(t,e,n,o){if(!D(n))return n;let r=c=>o(e,c);return z(n,r),Q(n,r,t,e),n()}};function Q(t,e,...n){let{current:o}=E;o.prevent||o.host(function(r){r[k]||(r[k]=[],m.disconnected(()=>r[k].forEach(([[c,s]])=>O(c,s,c[p]?.host()===r)))(r)),r[k].push([[t,e],...n])})}function V(t,e){let n=(...o)=>o.length?at(n,...o):ft(n);return it(n,t,e)}var st=Object.assign(Object.create(null),{stopPropagation(){this.skip=!0}}),$=class extends Error{constructor(){super();let[e,...n]=this.stack.split(` -`),o=e.slice(e.indexOf("@"),e.indexOf(".js:")+4);this.stack=n.find(r=>!r.includes(o))}};function it(t,e,n){let o=[];F(n)!=="[object Object]"&&(n={});let{onclear:r}=g.symbols;n[r]&&(o.push(n[r]),Reflect.deleteProperty(n,r));let{host:c}=E;return Reflect.defineProperty(t,p,{value:{value:e,actions:n,onclear:o,host:c,listeners:new Set,defined:new $},enumerable:!1,writable:!1,configurable:!0}),t.toJSON=()=>t(),Object.setPrototypeOf(t[p],st),t}function ut(){return T[T.length-1]}function ft(t){if(!t[p])return;let{value:e,listeners:n}=t[p],o=ut();return o&&n.add(o),h.has(o)&&h.get(o).add(t),e}function at(t,e,n){if(!t[p])return;let o=t[p];if(!(!n&&o.value===e))return o.value=e,o.listeners.forEach(r=>r(e)),e}function z(t,e){if(t[p])return t[p].listeners.add(e)}function O(t,e,n){let o=t[p];if(!o)return;let r=o.listeners.delete(e);if(n&&!o.listeners.size){if(g.clear(t),!h.has(o))return r;let c=h.get(o);if(!h.has(c))return r;h.get(c).forEach(s=>O(s,c,!0))}return r}M(K); +var y={isSignal(t){return!1},processReactiveAttribute(t,e,n,o){return n}};function M(t,e=!0){return e?Object.assign(y,t):(Object.setPrototypeOf(t,y),t)}function R(t){return y.isPrototypeOf(t)&&t!==y?t:y}function v(t){return typeof t>"u"}function F(t){let e=typeof t;return e!=="object"?e:t===null?"null":Object.prototype.toString.call(t)}function C(t,e){if(!t||!(t instanceof AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var U={setDeleteAttr:X};function X(t,e,n){if(Reflect.set(t,e,n),!!v(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 w=[{scope:document.body,host:t=>t?t(document.body):document.body,prevent:!0,inherit_host:!1}],_={get current(){return w[w.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...w]},push(t={}){return w.push(Object.assign({},this.current,{prevent:!1},t))},pop(){return w.pop()}},L;function m(t,e,...n){let o=R(this),r=0,c,s;switch((Object(e)!==e||o.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{r=1;let{inherit_host:a,host:d}=_.current,h=a?d:i=>i?(r===1?n.unshift(i):i(s),void 0):s;_.push({scope:t,host:h,inherit_host:a}),c=t(e||void 0);let E=c instanceof DocumentFragment,u=m.mark({type:"component",name:t.name,host:E?"this":c.nodeName==="#comment"?"previousLater":"parentElement"});c.prepend(u),E&&(s=u);break}case t==="#text":c=N.call(this,document.createTextNode(""),e);break;case(t==="<>"||!t):c=N.call(this,document.createDocumentFragment(),e);break;case L:c=N.call(this,document.createElementNS(L,t),e);break;case!c:c=N.call(this,document.createElement(t),e)}return rt(c),s||(s=c),n.forEach(a=>a(s)),r&&_.pop(),r=2,c}m.mark=function(t,e=!1){t=Object.entries(t).map(([r,c])=>r+`="${c}"`).join(" ");let n=e?"":"/",o=document.createComment(``);return e||(o.end=document.createComment("")),o};m.later=function(){let t=m.mark({type:"later"});return t.append=t.prepend=function(...e){return t.after(...e),t},t};function bt(t){let e=this;return function(...o){L=t;let r=m.call(e,...o);return L=void 0,r}}var{setDeleteAttr:q}=U,P=new WeakMap;function N(t,...e){if(!e.length)return t;P.set(t,J(t,this));for(let[n,o]of Object.entries(Object.assign({},...e)))I.call(this,t,n,o);return P.delete(t),t}function I(t,e,n){let{setRemoveAttr:o,s:r}=J(t,this),c=this;n=r.processReactiveAttribute(t,e,n,(a,d)=>I.call(c,t,a,d));let[s]=e;if(s==="=")return o(e.slice(1),n);if(s===".")return H(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 q(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return W(r,n,H.bind(null,t[e]));case"ariaset":return W(r,n,(a,d)=>o("aria-"+a,d));case"classList":return Y.call(c,t,n)}return tt(t,e)?q(t,e,n):o(e,n)}function J(t,e){if(P.has(t))return P.get(t);let o=(t instanceof SVGElement?nt:et).bind(null,t,"Attribute"),r=R(e);return{setRemoveAttr:o,s:r}}function Y(t,e){let n=R(this);return W(n,e,(o,r)=>t.classList.toggle(o,r===-1?void 0:!!r)),t}function Et(t){return Array.from(t.children).forEach(e=>e.remove()),t}function tt(t,e){if(!Reflect.has(t,e))return!1;let n=Z(t,e);return!v(n.set)}function Z(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||Z(t,e)}function W(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 G(t){return Array.isArray(t)?t.filter(Boolean).join(" "):t}function et(t,e,n,o){return t[(v(o)?"remove":"set")+e](n,G(o))}function nt(t,e,n,o,r=null){return t[(v(o)?"remove":"set")+e+"NS"](r,n,G(o))}function H(t,e,n){if(Reflect.set(t,e,n),!!v(n))return Reflect.deleteProperty(t,e)}function B(...t){return this.appendOrig(...t),this}function rt(t){return t.append===B||(t.appendOrig=t.append,t.append=B),t}function xt(t,e,...n){let o=n.length?new CustomEvent(e,{detail:n[0]}):new Event(e);return t.dispatchEvent(o)}function x(t,e,n){return function(r){return r.addEventListener(t,e,n),r}}var j=ct(),ot=new WeakSet;x.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):(C(e.signal,()=>j.offConnected(r,t))&&j.onConnected(r,t),r)}};x.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||C(e.signal,()=>j.offDisconnected(r,t))&&j.onDisconnected(r,t),r}};x.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||ot.has(r))return r;let s=new MutationObserver(function(d){for(let{attributeName:h,target:E}of d)E.dispatchEvent(new CustomEvent(c,{detail:[h,E.getAttribute(h)]}))});return C(e.signal,()=>s.disconnect())&&s.observe(r,{attributes:!0}),r}};function ct(){let t=new Map,e=!1,n=new MutationObserver(function(u){for(let i of u)if(i.type==="childList"){if(h(i.addedNodes,!0)){s();continue}E(i.removedNodes,!0)&&s()}});return{onConnected(u,i){c();let f=r(u);f.connected.has(i)||(f.connected.add(i),f.length_c+=1)},offConnected(u,i){if(!t.has(u))return;let f=t.get(u);f.connected.has(i)&&(f.connected.delete(i),f.length_c-=1,o(u,f))},onDisconnected(u,i){c();let f=r(u);f.disconnected.has(i)||(f.disconnected.add(i),f.length_d+=1)},offDisconnected(u,i){if(!t.has(u))return;let f=t.get(u);f.disconnected.has(i)&&(f.disconnected.delete(i),f.length_d-=1,o(u,f))}};function o(u,i){i.length_c||i.length_d||(t.delete(u),s())}function r(u){if(t.has(u))return t.get(u);let i={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(u,i),i}function c(){e||(e=!0,n.observe(document.body,{childList:!0,subtree:!0}))}function s(){!e||t.size||(e=!1,n.disconnect())}function a(){return new Promise(function(u){(requestIdleCallback||requestAnimationFrame)(u)})}async function d(u){t.size>30&&await a();let i=[];if(!(u instanceof Node))return i;for(let f of t.keys())f===u||!(f instanceof Node)||u.contains(f)&&i.push(f);return i}function h(u,i){let f=!1;for(let b of u){if(i&&d(b).then(h),!t.has(b))continue;let S=t.get(b);S.length_c&&(b.dispatchEvent(new Event("dde:connected")),S.connected=new WeakSet,S.length_c=0,S.length_d||t.delete(b),f=!0)}return f}function E(u,i){let f=!1;for(let b of u)i&&d(b).then(E),!(!t.has(b)||!t.get(b).length_d)&&(b.dispatchEvent(new Event("dde:disconnected")),t.delete(b),f=!0);return f}}var p=Symbol.for("Signal");function D(t){try{return Reflect.has(t,p)}catch{return!1}}var T=[],l=new WeakMap;function g(t,e){if(typeof t!="function")return V(t,e);if(D(t))return t;let n=V(),o=function(){let[r,...c]=l.get(o);if(l.set(o,new Set([r])),T.push(o),n(t()),T.pop(),!c.length)return;let s=l.get(o);for(let a of c)s.has(a)||O(a,o)};return l.set(n[p],o),l.set(o,new Set([n])),o(),n}g.action=function(t,e,...n){let o=t[p],{actions:r}=o;if(!r||!Reflect.has(r,e))throw new Error(`'${t}' has no action with name '${e}'!`);if(r[e].apply(o,n),o.skip)return Reflect.deleteProperty(o,"skip");o.listeners.forEach(c=>c(o.value))};g.on=function t(e,n,o={}){let{signal:r}=o;if(!(r&&r.aborted)){if(Array.isArray(e))return e.forEach(c=>t(c,n,o));z(e,n),r&&r.addEventListener("abort",()=>O(e,n))}};g.symbols={signal:p,onclear:Symbol.for("Signal.onclear")};var A="__dde_attributes";g.attribute=function(t,e=void 0){let n=g(e),o;return _.host(r=>{if(o=r,r instanceof HTMLElement?r.hasAttribute(t)&&n(r.getAttribute(t)):r.hasAttributeNS(null,t)&&n(r.getAttributeNS(null,t)),r[A]){r[A][t]=n;return}return r[A]={[t]:n},x.attributeChanged(function({detail:s}){/*! This maps attributes to signals (`S.attribute`). +* Investigate `__dde_attributes` key of the element.*/let[a,d]=s,h=r[A][a];if(h)return h(d)})(r),x.disconnected(function(){/*! This removes all signals mapped to attributes (`S.attribute`). +* Investigate `__dde_attributes` key of the element.*/g.clear(...Object.values(r[A])),o=null})(r),r}),new Proxy(n,{apply(r,c,s){if(!s.length)return r();if(!o)return;let a=s[0];return o instanceof HTMLElement?o.setAttribute(t,a):o.setAttributeNS(null,t,a)}})};g.clear=function(...t){for(let n of t){Reflect.deleteProperty(n,"toJSON");let o=n[p];o.onclear.forEach(r=>r.call(o)),e(n,o),Reflect.deleteProperty(n,p)}function e(n,o){o.listeners.forEach(r=>{if(o.listeners.delete(r),!l.has(r))return;let c=l.get(r);c.delete(n),!(c.size>1)&&(g.clear(...c),l.delete(r))})}};var k="__dde_reactive";g.el=function(t,e){let n=m.mark({type:"reactive"},!1),o=n.end,r=document.createDocumentFragment();r.append(n,o);let{current:c}=_,s=a=>{if(!n.parentNode||!o.parentNode)return O(t,s);_.push(c);let d=e(a);_.pop(),Array.isArray(d)||(d=[d]);let h=n;for(;(h=n.nextSibling)!==o;)h.remove();n.after(...d)};return z(t,s),Q(t,s,n,e),s(t()),r};var K={isSignal:D,processReactiveAttribute(t,e,n,o){if(!D(n))return n;let r=c=>o(e,c);return z(n,r),Q(n,r,t,e),n()}};function Q(t,e,...n){let{current:o}=_;o.prevent||o.host(function(r){r[k]||(r[k]=[],x.disconnected(()=>r[k].forEach(([[c,s]])=>O(c,s,c[p]?.host()===r)))(r)),r[k].push([[t,e],...n])})}function V(t,e){let n=(...o)=>o.length?at(n,...o):ft(n);return it(n,t,e)}var st=Object.assign(Object.create(null),{stopPropagation(){this.skip=!0}}),$=class extends Error{constructor(){super();let[e,...n]=this.stack.split(` +`),o=e.slice(e.indexOf("@"),e.indexOf(".js:")+4);this.stack=n.find(r=>!r.includes(o))}};function it(t,e,n){let o=[];F(n)!=="[object Object]"&&(n={});let{onclear:r}=g.symbols;n[r]&&(o.push(n[r]),Reflect.deleteProperty(n,r));let{host:c}=_;return Reflect.defineProperty(t,p,{value:{value:e,actions:n,onclear:o,host:c,listeners:new Set,defined:new $},enumerable:!1,writable:!1,configurable:!0}),t.toJSON=()=>t(),Object.setPrototypeOf(t[p],st),t}function ut(){return T[T.length-1]}function ft(t){if(!t[p])return;let{value:e,listeners:n}=t[p],o=ut();return o&&n.add(o),l.has(o)&&l.get(o).add(t),e}function at(t,e,n){if(!t[p])return;let o=t[p];if(!(!n&&o.value===e))return o.value=e,o.listeners.forEach(r=>r(e)),e}function z(t,e){if(t[p])return t[p].listeners.add(e)}function O(t,e,n){let o=t[p];if(!o)return;let r=o.listeners.delete(e);if(n&&!o.listeners.size){if(g.clear(t),!l.has(o))return r;let c=l.get(o);if(!l.has(c))return r;l.get(c).forEach(s=>O(s,c,!0))}return r}M(K); globalThis.dde= {S: g, assign: N, assignAttribute: I, classListDeclarative: Y, -createElement: v, +createElement: m, createElementNS: bt, dispatchEvent: xt, -el: v, +el: m, elNS: bt, -empty: _t, +empty: Et, isSignal: D, -on: m, +on: x, registerReactivity: M, -scope: E +scope: _ }; })(); \ No newline at end of file diff --git a/dist/dde.js b/dist/dde.js index a114fce..a95571d 100644 --- a/dist/dde.js +++ b/dist/dde.js @@ -1,6 +1,6 @@ //deka-dom-el library is available via global namespace `dde` (()=> { -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(``);return e||(o.end=document.createComment("")),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}} +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(``);return e||(o.end=document.createComment("")),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}} globalThis.dde= {assign: w, assignAttribute: P, classListDeclarative: q, @@ -10,9 +10,9 @@ dispatchEvent: nt, el: E, elNS: Q, empty: Y, -on: R, +on: y, registerReactivity: $, -scope: L +scope: S }; })(); \ No newline at end of file diff --git a/dist/esm-with-signals.d.ts b/dist/esm-with-signals.d.ts index 250b8a3..d0ff587 100644 --- a/dist/esm-with-signals.d.ts +++ b/dist/esm-with-signals.d.ts @@ -121,7 +121,7 @@ interface On{ ) : EE; } export const on: On; -type Scope= { scope: Node | Function | Object, host: ddeElementModifier, prevent: boolean } +type Scope= { scope: Node | Function | Object, host: ddeElementModifier, prevent: boolean, inherit_host: boolean, } /** Current scope created last time the `el(Function)` was invoke. (Or {@link scope.push}) */ export const scope: { current: Scope, @@ -138,9 +138,9 @@ export const scope: { state: Scope[], /** Adds new child scope. All attributes are inherited by default. */ - push(scope: Partial): ReturnType["push"]> + push(scope: Partial): ReturnType["push"]>, /** Removes last/current child scope. */ - pop(): ReturnType["pop"]> + pop(): ReturnType["pop"]>, }; /* * TODO TypeScript HACK (better way?) diff --git a/dist/esm-with-signals.js b/dist/esm-with-signals.js index 9291246..03e9948 100644 --- a/dist/esm-with-signals.js +++ b/dist/esm-with-signals.js @@ -1,4 +1,4 @@ -var y={isSignal(t){return!1},processReactiveAttribute(t,e,n,o){return n}};function M(t,e=!0){return e?Object.assign(y,t):(Object.setPrototypeOf(t,y),t)}function R(t){return y.isPrototypeOf(t)&&t!==y?t:y}function _(t){return typeof t>"u"}function F(t){let e=typeof t;return e!=="object"?e:t===null?"null":Object.prototype.toString.call(t)}function C(t,e){if(!t||!(t instanceof AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var U={setDeleteAttr:X};function X(t,e,n){if(Reflect.set(t,e,n),!!_(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 w=[{scope:document.body,host:t=>t?t(document.body):document.body,prevent:!0}],E={get current(){return w[w.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...w]},push(t={}){return w.push(Object.assign({},this.current,{prevent:!1},t))},pop(){return w.pop()}},L;function v(t,e,...n){let o=R(this),r=0,c,s;switch((Object(e)!==e||o.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{r=1,E.push({scope:t,host:l=>l?(r===1?n.unshift(l):l(s),void 0):s}),c=t(e||void 0);let a=c instanceof DocumentFragment,d=v.mark({type:"component",name:t.name,host:a?"this":c.nodeName==="#comment"?"previousLater":"parentElement"});c.prepend(d),a&&(s=d);break}case t==="#text":c=N.call(this,document.createTextNode(""),e);break;case(t==="<>"||!t):c=N.call(this,document.createDocumentFragment(),e);break;case L:c=N.call(this,document.createElementNS(L,t),e);break;case!c:c=N.call(this,document.createElement(t),e)}return rt(c),s||(s=c),n.forEach(a=>a(s)),r&&E.pop(),r=2,c}v.mark=function(t,e=!1){t=Object.entries(t).map(([r,c])=>r+`="${c}"`).join(" ");let n=e?"":"/",o=document.createComment(``);return e||(o.end=document.createComment("")),o};v.later=function(){let t=v.mark({type:"later"});return t.append=t.prepend=function(...e){return t.after(...e),t},t};function bt(t){let e=this;return function(...o){L=t;let r=v.call(e,...o);return L=void 0,r}}var{setDeleteAttr:q}=U,j=new WeakMap;function N(t,...e){if(!e.length)return t;j.set(t,J(t,this));for(let[n,o]of Object.entries(Object.assign({},...e)))I.call(this,t,n,o);return j.delete(t),t}function I(t,e,n){let{setRemoveAttr:o,s:r}=J(t,this),c=this;n=r.processReactiveAttribute(t,e,n,(a,d)=>I.call(c,t,a,d));let[s]=e;if(s==="=")return o(e.slice(1),n);if(s===".")return H(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 q(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return W(r,n,H.bind(null,t[e]));case"ariaset":return W(r,n,(a,d)=>o("aria-"+a,d));case"classList":return Y.call(c,t,n)}return tt(t,e)?q(t,e,n):o(e,n)}function J(t,e){if(j.has(t))return j.get(t);let o=(t instanceof SVGElement?nt:et).bind(null,t,"Attribute"),r=R(e);return{setRemoveAttr:o,s:r}}function Y(t,e){let n=R(this);return W(n,e,(o,r)=>t.classList.toggle(o,r===-1?void 0:!!r)),t}function _t(t){return Array.from(t.children).forEach(e=>e.remove()),t}function tt(t,e){if(!Reflect.has(t,e))return!1;let n=Z(t,e);return!_(n.set)}function Z(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||Z(t,e)}function W(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 G(t){return Array.isArray(t)?t.filter(Boolean).join(" "):t}function et(t,e,n,o){return t[(_(o)?"remove":"set")+e](n,G(o))}function nt(t,e,n,o,r=null){return t[(_(o)?"remove":"set")+e+"NS"](r,n,G(o))}function H(t,e,n){if(Reflect.set(t,e,n),!!_(n))return Reflect.deleteProperty(t,e)}function B(...t){return this.appendOrig(...t),this}function rt(t){return t.append===B||(t.appendOrig=t.append,t.append=B),t}function xt(t,e,...n){let o=n.length?new CustomEvent(e,{detail:n[0]}):new Event(e);return t.dispatchEvent(o)}function m(t,e,n){return function(r){return r.addEventListener(t,e,n),r}}var P=ct(),ot=new WeakSet;m.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):(C(e.signal,()=>P.offConnected(r,t))&&P.onConnected(r,t),r)}};m.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||C(e.signal,()=>P.offDisconnected(r,t))&&P.onDisconnected(r,t),r}};m.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||ot.has(r))return r;let s=new MutationObserver(function(d){for(let{attributeName:l,target:x}of d)x.dispatchEvent(new CustomEvent(c,{detail:[l,x.getAttribute(l)]}))});return C(e.signal,()=>s.disconnect())&&s.observe(r,{attributes:!0}),r}};function ct(){let t=new Map,e=!1,n=new MutationObserver(function(i){for(let u of i)if(u.type==="childList"){if(l(u.addedNodes,!0)){s();continue}x(u.removedNodes,!0)&&s()}});return{onConnected(i,u){c();let f=r(i);f.connected.has(u)||(f.connected.add(u),f.length_c+=1)},offConnected(i,u){if(!t.has(i))return;let f=t.get(i);f.connected.has(u)&&(f.connected.delete(u),f.length_c-=1,o(i,f))},onDisconnected(i,u){c();let f=r(i);f.disconnected.has(u)||(f.disconnected.add(u),f.length_d+=1)},offDisconnected(i,u){if(!t.has(i))return;let f=t.get(i);f.disconnected.has(u)&&(f.disconnected.delete(u),f.length_d-=1,o(i,f))}};function o(i,u){u.length_c||u.length_d||(t.delete(i),s())}function r(i){if(t.has(i))return t.get(i);let u={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(i,u),u}function c(){e||(e=!0,n.observe(document.body,{childList:!0,subtree:!0}))}function s(){!e||t.size||(e=!1,n.disconnect())}function a(){return new Promise(function(i){(requestIdleCallback||requestAnimationFrame)(i)})}async function d(i){t.size>30&&await a();let u=[];if(!(i instanceof Node))return u;for(let f of t.keys())f===i||!(f instanceof Node)||i.contains(f)&&u.push(f);return u}function l(i,u){let f=!1;for(let b of i){if(u&&d(b).then(l),!t.has(b))continue;let S=t.get(b);S.length_c&&(b.dispatchEvent(new Event("dde:connected")),S.connected=new WeakSet,S.length_c=0,S.length_d||t.delete(b),f=!0)}return f}function x(i,u){let f=!1;for(let b of i)u&&d(b).then(x),!(!t.has(b)||!t.get(b).length_d)&&(b.dispatchEvent(new Event("dde:disconnected")),t.delete(b),f=!0);return f}}var p=Symbol.for("Signal");function D(t){try{return Reflect.has(t,p)}catch{return!1}}var T=[],h=new WeakMap;function g(t,e){if(typeof t!="function")return V(t,e);if(D(t))return t;let n=V(),o=function(){let[r,...c]=h.get(o);if(h.set(o,new Set([r])),T.push(o),n(t()),T.pop(),!c.length)return;let s=h.get(o);for(let a of c)s.has(a)||O(a,o)};return h.set(n[p],o),h.set(o,new Set([n])),o(),n}g.action=function(t,e,...n){let o=t[p],{actions:r}=o;if(!r||!Reflect.has(r,e))throw new Error(`'${t}' has no action with name '${e}'!`);if(r[e].apply(o,n),o.skip)return Reflect.deleteProperty(o,"skip");o.listeners.forEach(c=>c(o.value))};g.on=function t(e,n,o={}){let{signal:r}=o;if(!(r&&r.aborted)){if(Array.isArray(e))return e.forEach(c=>t(c,n,o));z(e,n),r&&r.addEventListener("abort",()=>O(e,n))}};g.symbols={signal:p,onclear:Symbol.for("Signal.onclear")};var A="__dde_attributes";g.attribute=function(t,e=void 0){let n=g(e),o;return E.host(r=>{if(o=r,r instanceof HTMLElement?r.hasAttribute(t)&&n(r.getAttribute(t)):r.hasAttributeNS(null,t)&&n(r.getAttributeNS(null,t)),r[A]){r[A][t]=n;return}return r[A]={[t]:n},m.attributeChanged(function({detail:s}){/*! This maps attributes to signals (`S.attribute`). -* Investigate `__dde_attributes` key of the element.*/let[a,d]=s,l=r[A][a];if(l)return l(d)})(r),m.disconnected(function(){/*! This removes all signals mapped to attributes (`S.attribute`). -* Investigate `__dde_attributes` key of the element.*/g.clear(...Object.values(r[A])),o=null})(r),r}),new Proxy(n,{apply(r,c,s){if(!s.length)return r();if(!o)return;let a=s[0];return o instanceof HTMLElement?o.setAttribute(t,a):o.setAttributeNS(null,t,a)}})};g.clear=function(...t){for(let n of t){Reflect.deleteProperty(n,"toJSON");let o=n[p];o.onclear.forEach(r=>r.call(o)),e(n,o),Reflect.deleteProperty(n,p)}function e(n,o){o.listeners.forEach(r=>{if(o.listeners.delete(r),!h.has(r))return;let c=h.get(r);c.delete(n),!(c.size>1)&&(g.clear(...c),h.delete(r))})}};var k="__dde_reactive";g.el=function(t,e){let n=v.mark({type:"reactive"},!1),o=n.end,r=document.createDocumentFragment();r.append(n,o);let{current:c}=E,s=a=>{if(!n.parentNode||!o.parentNode)return O(t,s);E.push(c);let d=e(a);E.pop(),Array.isArray(d)||(d=[d]);let l=n;for(;(l=n.nextSibling)!==o;)l.remove();n.after(...d)};return z(t,s),Q(t,s,n,e),s(t()),r};var K={isSignal:D,processReactiveAttribute(t,e,n,o){if(!D(n))return n;let r=c=>o(e,c);return z(n,r),Q(n,r,t,e),n()}};function Q(t,e,...n){let{current:o}=E;o.prevent||o.host(function(r){r[k]||(r[k]=[],m.disconnected(()=>r[k].forEach(([[c,s]])=>O(c,s,c[p]?.host()===r)))(r)),r[k].push([[t,e],...n])})}function V(t,e){let n=(...o)=>o.length?at(n,...o):ft(n);return it(n,t,e)}var st=Object.assign(Object.create(null),{stopPropagation(){this.skip=!0}}),$=class extends Error{constructor(){super();let[e,...n]=this.stack.split(` -`),o=e.slice(e.indexOf("@"),e.indexOf(".js:")+4);this.stack=n.find(r=>!r.includes(o))}};function it(t,e,n){let o=[];F(n)!=="[object Object]"&&(n={});let{onclear:r}=g.symbols;n[r]&&(o.push(n[r]),Reflect.deleteProperty(n,r));let{host:c}=E;return Reflect.defineProperty(t,p,{value:{value:e,actions:n,onclear:o,host:c,listeners:new Set,defined:new $},enumerable:!1,writable:!1,configurable:!0}),t.toJSON=()=>t(),Object.setPrototypeOf(t[p],st),t}function ut(){return T[T.length-1]}function ft(t){if(!t[p])return;let{value:e,listeners:n}=t[p],o=ut();return o&&n.add(o),h.has(o)&&h.get(o).add(t),e}function at(t,e,n){if(!t[p])return;let o=t[p];if(!(!n&&o.value===e))return o.value=e,o.listeners.forEach(r=>r(e)),e}function z(t,e){if(t[p])return t[p].listeners.add(e)}function O(t,e,n){let o=t[p];if(!o)return;let r=o.listeners.delete(e);if(n&&!o.listeners.size){if(g.clear(t),!h.has(o))return r;let c=h.get(o);if(!h.has(c))return r;h.get(c).forEach(s=>O(s,c,!0))}return r}M(K);export{g as S,N as assign,I as assignAttribute,Y as classListDeclarative,v as createElement,bt as createElementNS,xt as dispatchEvent,v as el,bt as elNS,_t as empty,D as isSignal,m as on,M as registerReactivity,E as scope}; +var y={isSignal(t){return!1},processReactiveAttribute(t,e,n,o){return n}};function M(t,e=!0){return e?Object.assign(y,t):(Object.setPrototypeOf(t,y),t)}function R(t){return y.isPrototypeOf(t)&&t!==y?t:y}function v(t){return typeof t>"u"}function F(t){let e=typeof t;return e!=="object"?e:t===null?"null":Object.prototype.toString.call(t)}function C(t,e){if(!t||!(t instanceof AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var U={setDeleteAttr:X};function X(t,e,n){if(Reflect.set(t,e,n),!!v(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 w=[{scope:document.body,host:t=>t?t(document.body):document.body,prevent:!0,inherit_host:!1}],_={get current(){return w[w.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...w]},push(t={}){return w.push(Object.assign({},this.current,{prevent:!1},t))},pop(){return w.pop()}},L;function m(t,e,...n){let o=R(this),r=0,c,s;switch((Object(e)!==e||o.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{r=1;let{inherit_host:a,host:d}=_.current,h=a?d:i=>i?(r===1?n.unshift(i):i(s),void 0):s;_.push({scope:t,host:h,inherit_host:a}),c=t(e||void 0);let E=c instanceof DocumentFragment,u=m.mark({type:"component",name:t.name,host:E?"this":c.nodeName==="#comment"?"previousLater":"parentElement"});c.prepend(u),E&&(s=u);break}case t==="#text":c=N.call(this,document.createTextNode(""),e);break;case(t==="<>"||!t):c=N.call(this,document.createDocumentFragment(),e);break;case L:c=N.call(this,document.createElementNS(L,t),e);break;case!c:c=N.call(this,document.createElement(t),e)}return rt(c),s||(s=c),n.forEach(a=>a(s)),r&&_.pop(),r=2,c}m.mark=function(t,e=!1){t=Object.entries(t).map(([r,c])=>r+`="${c}"`).join(" ");let n=e?"":"/",o=document.createComment(``);return e||(o.end=document.createComment("")),o};m.later=function(){let t=m.mark({type:"later"});return t.append=t.prepend=function(...e){return t.after(...e),t},t};function bt(t){let e=this;return function(...o){L=t;let r=m.call(e,...o);return L=void 0,r}}var{setDeleteAttr:q}=U,P=new WeakMap;function N(t,...e){if(!e.length)return t;P.set(t,J(t,this));for(let[n,o]of Object.entries(Object.assign({},...e)))I.call(this,t,n,o);return P.delete(t),t}function I(t,e,n){let{setRemoveAttr:o,s:r}=J(t,this),c=this;n=r.processReactiveAttribute(t,e,n,(a,d)=>I.call(c,t,a,d));let[s]=e;if(s==="=")return o(e.slice(1),n);if(s===".")return H(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 q(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return W(r,n,H.bind(null,t[e]));case"ariaset":return W(r,n,(a,d)=>o("aria-"+a,d));case"classList":return Y.call(c,t,n)}return tt(t,e)?q(t,e,n):o(e,n)}function J(t,e){if(P.has(t))return P.get(t);let o=(t instanceof SVGElement?nt:et).bind(null,t,"Attribute"),r=R(e);return{setRemoveAttr:o,s:r}}function Y(t,e){let n=R(this);return W(n,e,(o,r)=>t.classList.toggle(o,r===-1?void 0:!!r)),t}function Et(t){return Array.from(t.children).forEach(e=>e.remove()),t}function tt(t,e){if(!Reflect.has(t,e))return!1;let n=Z(t,e);return!v(n.set)}function Z(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||Z(t,e)}function W(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 G(t){return Array.isArray(t)?t.filter(Boolean).join(" "):t}function et(t,e,n,o){return t[(v(o)?"remove":"set")+e](n,G(o))}function nt(t,e,n,o,r=null){return t[(v(o)?"remove":"set")+e+"NS"](r,n,G(o))}function H(t,e,n){if(Reflect.set(t,e,n),!!v(n))return Reflect.deleteProperty(t,e)}function B(...t){return this.appendOrig(...t),this}function rt(t){return t.append===B||(t.appendOrig=t.append,t.append=B),t}function xt(t,e,...n){let o=n.length?new CustomEvent(e,{detail:n[0]}):new Event(e);return t.dispatchEvent(o)}function x(t,e,n){return function(r){return r.addEventListener(t,e,n),r}}var j=ct(),ot=new WeakSet;x.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):(C(e.signal,()=>j.offConnected(r,t))&&j.onConnected(r,t),r)}};x.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||C(e.signal,()=>j.offDisconnected(r,t))&&j.onDisconnected(r,t),r}};x.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||ot.has(r))return r;let s=new MutationObserver(function(d){for(let{attributeName:h,target:E}of d)E.dispatchEvent(new CustomEvent(c,{detail:[h,E.getAttribute(h)]}))});return C(e.signal,()=>s.disconnect())&&s.observe(r,{attributes:!0}),r}};function ct(){let t=new Map,e=!1,n=new MutationObserver(function(u){for(let i of u)if(i.type==="childList"){if(h(i.addedNodes,!0)){s();continue}E(i.removedNodes,!0)&&s()}});return{onConnected(u,i){c();let f=r(u);f.connected.has(i)||(f.connected.add(i),f.length_c+=1)},offConnected(u,i){if(!t.has(u))return;let f=t.get(u);f.connected.has(i)&&(f.connected.delete(i),f.length_c-=1,o(u,f))},onDisconnected(u,i){c();let f=r(u);f.disconnected.has(i)||(f.disconnected.add(i),f.length_d+=1)},offDisconnected(u,i){if(!t.has(u))return;let f=t.get(u);f.disconnected.has(i)&&(f.disconnected.delete(i),f.length_d-=1,o(u,f))}};function o(u,i){i.length_c||i.length_d||(t.delete(u),s())}function r(u){if(t.has(u))return t.get(u);let i={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(u,i),i}function c(){e||(e=!0,n.observe(document.body,{childList:!0,subtree:!0}))}function s(){!e||t.size||(e=!1,n.disconnect())}function a(){return new Promise(function(u){(requestIdleCallback||requestAnimationFrame)(u)})}async function d(u){t.size>30&&await a();let i=[];if(!(u instanceof Node))return i;for(let f of t.keys())f===u||!(f instanceof Node)||u.contains(f)&&i.push(f);return i}function h(u,i){let f=!1;for(let b of u){if(i&&d(b).then(h),!t.has(b))continue;let S=t.get(b);S.length_c&&(b.dispatchEvent(new Event("dde:connected")),S.connected=new WeakSet,S.length_c=0,S.length_d||t.delete(b),f=!0)}return f}function E(u,i){let f=!1;for(let b of u)i&&d(b).then(E),!(!t.has(b)||!t.get(b).length_d)&&(b.dispatchEvent(new Event("dde:disconnected")),t.delete(b),f=!0);return f}}var p=Symbol.for("Signal");function D(t){try{return Reflect.has(t,p)}catch{return!1}}var T=[],l=new WeakMap;function g(t,e){if(typeof t!="function")return V(t,e);if(D(t))return t;let n=V(),o=function(){let[r,...c]=l.get(o);if(l.set(o,new Set([r])),T.push(o),n(t()),T.pop(),!c.length)return;let s=l.get(o);for(let a of c)s.has(a)||O(a,o)};return l.set(n[p],o),l.set(o,new Set([n])),o(),n}g.action=function(t,e,...n){let o=t[p],{actions:r}=o;if(!r||!Reflect.has(r,e))throw new Error(`'${t}' has no action with name '${e}'!`);if(r[e].apply(o,n),o.skip)return Reflect.deleteProperty(o,"skip");o.listeners.forEach(c=>c(o.value))};g.on=function t(e,n,o={}){let{signal:r}=o;if(!(r&&r.aborted)){if(Array.isArray(e))return e.forEach(c=>t(c,n,o));z(e,n),r&&r.addEventListener("abort",()=>O(e,n))}};g.symbols={signal:p,onclear:Symbol.for("Signal.onclear")};var A="__dde_attributes";g.attribute=function(t,e=void 0){let n=g(e),o;return _.host(r=>{if(o=r,r instanceof HTMLElement?r.hasAttribute(t)&&n(r.getAttribute(t)):r.hasAttributeNS(null,t)&&n(r.getAttributeNS(null,t)),r[A]){r[A][t]=n;return}return r[A]={[t]:n},x.attributeChanged(function({detail:s}){/*! This maps attributes to signals (`S.attribute`). +* Investigate `__dde_attributes` key of the element.*/let[a,d]=s,h=r[A][a];if(h)return h(d)})(r),x.disconnected(function(){/*! This removes all signals mapped to attributes (`S.attribute`). +* Investigate `__dde_attributes` key of the element.*/g.clear(...Object.values(r[A])),o=null})(r),r}),new Proxy(n,{apply(r,c,s){if(!s.length)return r();if(!o)return;let a=s[0];return o instanceof HTMLElement?o.setAttribute(t,a):o.setAttributeNS(null,t,a)}})};g.clear=function(...t){for(let n of t){Reflect.deleteProperty(n,"toJSON");let o=n[p];o.onclear.forEach(r=>r.call(o)),e(n,o),Reflect.deleteProperty(n,p)}function e(n,o){o.listeners.forEach(r=>{if(o.listeners.delete(r),!l.has(r))return;let c=l.get(r);c.delete(n),!(c.size>1)&&(g.clear(...c),l.delete(r))})}};var k="__dde_reactive";g.el=function(t,e){let n=m.mark({type:"reactive"},!1),o=n.end,r=document.createDocumentFragment();r.append(n,o);let{current:c}=_,s=a=>{if(!n.parentNode||!o.parentNode)return O(t,s);_.push(c);let d=e(a);_.pop(),Array.isArray(d)||(d=[d]);let h=n;for(;(h=n.nextSibling)!==o;)h.remove();n.after(...d)};return z(t,s),Q(t,s,n,e),s(t()),r};var K={isSignal:D,processReactiveAttribute(t,e,n,o){if(!D(n))return n;let r=c=>o(e,c);return z(n,r),Q(n,r,t,e),n()}};function Q(t,e,...n){let{current:o}=_;o.prevent||o.host(function(r){r[k]||(r[k]=[],x.disconnected(()=>r[k].forEach(([[c,s]])=>O(c,s,c[p]?.host()===r)))(r)),r[k].push([[t,e],...n])})}function V(t,e){let n=(...o)=>o.length?at(n,...o):ft(n);return it(n,t,e)}var st=Object.assign(Object.create(null),{stopPropagation(){this.skip=!0}}),$=class extends Error{constructor(){super();let[e,...n]=this.stack.split(` +`),o=e.slice(e.indexOf("@"),e.indexOf(".js:")+4);this.stack=n.find(r=>!r.includes(o))}};function it(t,e,n){let o=[];F(n)!=="[object Object]"&&(n={});let{onclear:r}=g.symbols;n[r]&&(o.push(n[r]),Reflect.deleteProperty(n,r));let{host:c}=_;return Reflect.defineProperty(t,p,{value:{value:e,actions:n,onclear:o,host:c,listeners:new Set,defined:new $},enumerable:!1,writable:!1,configurable:!0}),t.toJSON=()=>t(),Object.setPrototypeOf(t[p],st),t}function ut(){return T[T.length-1]}function ft(t){if(!t[p])return;let{value:e,listeners:n}=t[p],o=ut();return o&&n.add(o),l.has(o)&&l.get(o).add(t),e}function at(t,e,n){if(!t[p])return;let o=t[p];if(!(!n&&o.value===e))return o.value=e,o.listeners.forEach(r=>r(e)),e}function z(t,e){if(t[p])return t[p].listeners.add(e)}function O(t,e,n){let o=t[p];if(!o)return;let r=o.listeners.delete(e);if(n&&!o.listeners.size){if(g.clear(t),!l.has(o))return r;let c=l.get(o);if(!l.has(c))return r;l.get(c).forEach(s=>O(s,c,!0))}return r}M(K);export{g as S,N as assign,I as assignAttribute,Y as classListDeclarative,m as createElement,bt as createElementNS,xt as dispatchEvent,m as el,bt as elNS,Et as empty,D as isSignal,x as on,M as registerReactivity,_ as scope}; diff --git a/dist/esm.d.ts b/dist/esm.d.ts index ec6d7ee..db4d037 100644 --- a/dist/esm.d.ts +++ b/dist/esm.d.ts @@ -121,7 +121,7 @@ interface On{ ) : EE; } export const on: On; -type Scope= { scope: Node | Function | Object, host: ddeElementModifier, prevent: boolean } +type Scope= { scope: Node | Function | Object, host: ddeElementModifier, prevent: boolean, inherit_host: boolean, } /** Current scope created last time the `el(Function)` was invoke. (Or {@link scope.push}) */ export const scope: { current: Scope, @@ -138,9 +138,9 @@ export const scope: { state: Scope[], /** Adds new child scope. All attributes are inherited by default. */ - push(scope: Partial): ReturnType["push"]> + push(scope: Partial): ReturnType["push"]>, /** Removes last/current child scope. */ - pop(): ReturnType["pop"]> + pop(): ReturnType["pop"]>, }; /* * TODO TypeScript HACK (better way?) diff --git a/dist/esm.js b/dist/esm.js index 34b4ad1..1dc5237 100644 --- a/dist/esm.js +++ b/dist/esm.js @@ -1 +1 @@ -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(``);return e||(o.end=document.createComment("")),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}; +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(``);return e||(o.end=document.createComment("")),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}; diff --git a/examples/components/webComponent.js b/examples/components/webComponent.js index d845970..8788bc5 100644 --- a/examples/components/webComponent.js +++ b/examples/components/webComponent.js @@ -48,7 +48,7 @@ lifecycleToEvents(CustomHTMLTestElement) customElements.define(CustomHTMLTestElement.tagName, CustomHTMLTestElement); function customElementRender(_this, render){ - scope.push({ scope: _this, host: (...a)=> a.length ? a[0](_this) : _this }); + scope.push({ scope: _this, host: (...a)=> a.length ? a[0](_this) : _this, inherit_host: true }); const out= render(_this); scope.pop(); return out; diff --git a/index.d.ts b/index.d.ts index 2e5e334..ea781b0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -127,7 +127,7 @@ interface On{ } export const on: On; -type Scope= { scope: Node | Function | Object, host: ddeElementModifier, prevent: boolean } +type Scope= { scope: Node | Function | Object, host: ddeElementModifier, prevent: boolean, inherit_host: boolean, } /** Current scope created last time the `el(Function)` was invoke. (Or {@link scope.push}) */ export const scope: { current: Scope, @@ -144,9 +144,9 @@ export const scope: { state: Scope[], /** Adds new child scope. All attributes are inherited by default. */ - push(scope: Partial): ReturnType["push"]> + push(scope: Partial): ReturnType["push"]>, /** Removes last/current child scope. */ - pop(): ReturnType["pop"]> + pop(): ReturnType["pop"]>, }; /* diff --git a/package.json b/package.json index d89ab5e..b6b5740 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "deka-dom-el", - "version": "0.6.1", + "version": "0.7.0", "description": "A low-code library that simplifies the creation of native DOM elements/components using small wrappers and tweaks.", "author": "Jan Andrle ", "license": "MIT", @@ -75,6 +75,11 @@ "path": "./examples/components/webComponent.js", "limit": "12.5 kB", "gzip": false + }, + { + "path": "./examples/components/webComponent.js", + "limit": "5 kB", + "gzip": true } ], "modifyEsbuildConfig": { diff --git a/src/dom.js b/src/dom.js index 6b27f71..984565f 100644 --- a/src/dom.js +++ b/src/dom.js @@ -4,7 +4,8 @@ import { signals } from "./signals-common.js"; const scopes= [ { scope: document.body, host: c=> c ? c(document.body) : document.body, - prevent: true + prevent: true, + inherit_host: false, } ]; export const scope= { get current(){ return scopes[scopes.length-1]; }, @@ -24,7 +25,7 @@ export const scope= { }; let namespace; export function createElement(tag, attributes, ...modifiers){ - /* jshint maxcomplexity: 15 */ + /* jshint maxcomplexity: 16 */ const s= signals(this); let scoped= 0; let el, el_host; @@ -34,7 +35,9 @@ export function createElement(tag, attributes, ...modifiers){ switch(true){ case typeof tag==="function": { scoped= 1; - scope.push({ scope: tag, host: c=> c ? (scoped===1 ? modifiers.unshift(c) : c(el_host), undefined) : el_host }); + const { inherit_host, host: hostParent }= scope.current; + const host= inherit_host ? hostParent : c=> c ? (scoped===1 ? modifiers.unshift(c) : c(el_host), undefined) : el_host; + scope.push({ scope: tag, host, inherit_host }); el= tag(attributes || undefined); const is_fragment= el instanceof DocumentFragment; const el_mark= createElement.mark({