diff --git a/dist/esm-with-signals.js b/dist/esm-with-signals.js index 2265062..75f5c8e 100644 --- a/dist/esm-with-signals.js +++ b/dist/esm-with-signals.js @@ -639,7 +639,7 @@ function wrapMethod(obj, method, apply) { } // src/memo.js -var memoMark = "__dde_memo_of"; +var memoMark = "__dde_memo"; var memo_scope = []; function memo(key, generator) { if (!memo_scope.length) return generator(key); @@ -648,7 +648,7 @@ function memo(key, generator) { return after(k, hasOwn(cache, k) ? cache[k] : generator(key)); } memo.isScope = function(obj) { - return Boolean(obj[memoMark]); + return obj[memoMark]; }; memo.scope = function memoScopeCreate(fun, { signal: signal2, onlyLast } = {}) { let cache = oCreate(); @@ -667,7 +667,7 @@ memo.scope = function memoScopeCreate(fun, { signal: signal2, onlyLast } = {}) { cache = cache_local; return out; } - memoScope[memoMark] = fun; + memoScope[memoMark] = true; memoScope.clear = () => cache = oCreate(); if (signal2) signal2.addEventListener("abort", memoScope.clear); return memoScope; @@ -787,7 +787,7 @@ signal.clear = function(...signals2) { }; var key_reactive = "__dde_reactive"; signal.el = function(s, map) { - map = memo.isScope(map) ? map : memo.scope(map, { onlyLast: true }); + const mapScoped = memo.isScope(map) ? map : memo.scope(map, { onlyLast: true }); const { current } = scope, { scope: sc } = current; const mark_start = createElement.mark({ type: "reactive", component: sc && sc.name || "" }, true); const mark_end = mark_start.end; @@ -797,7 +797,7 @@ signal.el = function(s, map) { if (!mark_start.parentNode || !mark_end.parentNode) return removeSignalListener(s, reRenderReactiveElement); scope.push(current); - let els = map(v); + let els = mapScoped(v); scope.pop(); if (!Array.isArray(els)) els = [els]; @@ -817,7 +817,7 @@ signal.el = function(s, map) { current.host(on.disconnected( () => ( /*! Clears cached elements for reactive element `S.el` */ - map.clear() + mapScoped.clear() ) )); return out; @@ -889,9 +889,8 @@ var signals_config = { function removeSignalsFromElements(s, listener, ...notes) { const { current } = scope; current.host(function(element) { - if (element[key_reactive]) - return element[key_reactive].push([[s, listener], ...notes]); - element[key_reactive] = []; + if (!element[key_reactive]) element[key_reactive] = []; + element[key_reactive].push([[s, listener], ...notes]); if (current.prevent) return; on.disconnected( () => ( diff --git a/dist/esm-with-signals.min.js b/dist/esm-with-signals.min.js index c042e29..adcf83e 100644 --- a/dist/esm-with-signals.min.js +++ b/dist/esm-with-signals.min.js @@ -1,3 +1,3 @@ -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(``);return e&&(r.end=p.D.createComment("")),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`). +var j=(...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 d={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,d.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var T="__dde_lifecyclesToEvents",C="dde:connected",D="dde:disconnected",F="dde:attributeChanged";var L=d.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(h(f.addedNodes,!0)){u();continue}g(f.removedNodes,!0)&&u()}},r=new d.M(n(s));return{observe(u){let a=new d.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(d.D.body,{childList:!0,subtree:!0}))}function s(){!e||t.size||(e=!1,r.disconnect())}function p(){return new Promise(function(u){(requestIdleCallback||requestAnimationFrame)(u)})}async function m(u){t.size>30&&await p();let a=[];if(!_(u,d.N))return a;for(let f of t.keys())f===u||!_(f,d.N)||u.contains(f)&&a.push(f);return a}function h(u,a){let f=!1;for(let w of u){if(a&&m(w).then(h),!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 g(u,a){let f=!1;for(let w of u)a&&m(w).then(g),!(!t.has(w)||!t.get(w).length_d)&&((globalThis.queueMicrotask||setTimeout)(R(w)),f=!0);return f}function R(u){return()=>{u.isConnected||(u.dispatchEvent(new Event(D)),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[T]?r:r.isConnected?(r.dispatchEvent(new Event(C)),r):(Z(e.signal,()=>L.offConnected(r,t))&&L.onConnected(r,t),r)}};y.disconnected=function(t,e){return e=it(e),function(r){return r.addEventListener(D,t,e),r[T]||Z(e.signal,()=>L.offDisconnected(r,t))&&L.onDisconnected(r,t),r}};var O=[{get scope(){return d.D.body},host:t=>t?t(d.D.body):d.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 q={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function V(t,e=!0){return e?b(q,t):(Object.setPrototypeOf(t,q),t)}function I(t){return ot(t,q)&&t!==q?t:q}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,d.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function ce(t){return d.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 $;function W(t,e,...n){let r=I(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 p=(...g)=>g.length?(o===1?n.unshift(...g):g.forEach(R=>R(i)),void 0):i;x.push({scope:t,host:p}),c=t(e||void 0);let m=_(c,d.F);if(c.nodeName==="#comment")break;let h=W.mark({type:"component",name:t.name,host:m?"this":"parentElement"});c.prepend(h),m&&(i=h);break}case t==="#text":c=U.call(this,d.D.createTextNode(""),e);break;case(t==="<>"||!t):c=U.call(this,d.D.createDocumentFragment(),e);break;case!!$:c=U.call(this,d.D.createElementNS($,t),e);break;case!c:c=U.call(this,d.D.createElement(t),e)}return At(c),i||(i=c),n.forEach(p=>p(i)),o&&x.pop(),o=2,c}W.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=d.D.createComment(``);return e&&(r.end=d.D.createComment("")),r};function se(t){let e=this;return function(...r){$=t;let o=W.call(e,...r);return $=void 0,o}}var z=new WeakMap,{setDeleteAttr:pt}=d;function U(t,...e){if(!e.length)return t;z.set(t,lt(t,this));for(let[n,r]of Object.entries(b({},...e)))dt.call(this,t,n,r);return z.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,p)=>dt.call(c,t,s,p));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,p)=>r("aria-"+s,p));case"classList":return Ct.call(c,t,n)}return Ot(t,e)?pt(t,e,n):r(e,n)}function lt(t,e){if(z.has(t))return z.get(t);let r=(_(t,d.S)?ut:st).bind(null,t,"Attribute"),o=I(e);return{setRemoveAttr:r,s:o}}function Ct(t,e){let n=I(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,p]){s&&(s=new c(s),s.target=e,p=t.processReactiveAttribute(n,s,p,o),o(s,p))})}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 p of s){let m=(p.slot||"")+n;try{ft(p,"remove","slot")}catch{}let h=o[m];if(!h)return;h.name.startsWith(r)||(h.childNodes.forEach(g=>g.remove()),h.name=r+m),h.append(p)}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[T];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(D,L.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(D)))}),X(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(F,{detail:[o,c]})),e.apply(n,r)}),t.prototype[T]=!0,t}function X(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}var mt="__dde_memo",H=[];function k(t,e){if(!H.length)return e(t);let n=typeof t=="object"?JSON.stringify(t):t,[{cache:r,after:o}]=H;return o(n,j(r,n)?r[n]:e(t))}k.isScope=function(t){return t[mt]};k.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();H.unshift({cache:o,after(m,h){return s[m]=h}});let p=e.apply(this,i);return H.shift(),o=s,p}return c[mt]=!0,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 J(t){return t&&t[l]}var B=[],E=new WeakMap;function v(t,e){if(typeof t!="function")return gt(!1,t,e);if(J(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 p=E.get(r);for(let m of s)p.has(m)||M(m,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||!j(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",()=>M(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 N="__dde_reactive";v.el=function(t,e){let n=k.isScope(e)?e:k.scope(e,{onlyLast:!0}),{current:r}=x,{scope:o}=r,c=W.mark({type:"reactive",component:o&&o.name||""},!0),i=c.end,s=d.D.createDocumentFragment();s.append(c,i);let p=m=>{if(!c.parentNode||!i.parentNode)return M(t,p);x.push(r);let h=n(m);x.pop(),Array.isArray(h)||(h=[h]);let g=document.createComment("");h.push(g),c.after(...h);let R;for(;(R=g.nextSibling)&&R!==i;)R.remove();g.remove(),c.isConnected&&Lt(r.host())};return nt(t,p),xt(t,p,c,e),p(t.get()),r.host(y.disconnected(()=>n.clear())),s};function Lt(t){!t||!t[N]||(requestIdleCallback||setTimeout)(function(){t[N]=t[N].filter(([e,n])=>n.isConnected?!0:(M(...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(F,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}; + Investigate `__dde_attributes` key of the element. */v.clear(...Object.values(this[tt]))})(t),n};var bt={isSignal:J,processReactiveAttribute(t,e,n,r){if(!J(n))return n;let o=c=>{if(!t.isConnected)return M(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){o[N]||(o[N]=[]),o[N].push([[t,e],...n]),!r.prevent&&y.disconnected(()=>o[N].forEach(([[c,i]])=>M(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 M(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 p of s)M(p,i,!0);return c}V(bt);export{v as S,U as assign,dt as assignAttribute,At as chainableAppend,Ct as classListDeclarative,W as createElement,se as createElementNS,ge as customElementRender,Rt as customElementWithDDE,Ht as dispatchEvent,W as el,se as elNS,J as isSignal,Rt as lifecyclesToEvents,k as memo,y as on,ce as queue,V as registerReactivity,x as scope,v as signal,me as simulateSlots}; diff --git a/dist/esm.js b/dist/esm.js index b11cce7..53df0cf 100644 --- a/dist/esm.js +++ b/dist/esm.js @@ -623,7 +623,7 @@ function wrapMethod(obj, method, apply) { } // src/memo.js -var memoMark = "__dde_memo_of"; +var memoMark = "__dde_memo"; var memo_scope = []; function memo(key, generator) { if (!memo_scope.length) return generator(key); @@ -632,7 +632,7 @@ function memo(key, generator) { return after(k, hasOwn(cache, k) ? cache[k] : generator(key)); } memo.isScope = function(obj) { - return Boolean(obj[memoMark]); + return obj[memoMark]; }; memo.scope = function memoScopeCreate(fun, { signal, onlyLast } = {}) { let cache = oCreate(); @@ -651,7 +651,7 @@ memo.scope = function memoScopeCreate(fun, { signal, onlyLast } = {}) { cache = cache_local; return out; } - memoScope[memoMark] = fun; + memoScope[memoMark] = true; memoScope.clear = () => cache = oCreate(); if (signal) signal.addEventListener("abort", memoScope.clear); return memoScope; diff --git a/dist/esm.min.js b/dist/esm.min.js index bd3f771..13eaba1 100644 --- a/dist/esm.min.js +++ b/dist/esm.min.js @@ -1 +1 @@ -var H=(...t)=>Object.prototype.hasOwnProperty.call(...t);function x(t){return typeof t>"u"}function h(t,e){return t instanceof e}function z(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function R(t=null,e={}){return Object.create(t,e)}function g(...t){return Object.assign(...t)}function W(t,e){if(!t||!h(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var f={setDeleteAttr:nt,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 nt(t,e,n){if(Reflect.set(t,e,n),!!x(n)){if(Reflect.deleteProperty(t,e),h(t,f.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var C="__dde_lifecyclesToEvents",E="dde:connected",w="dde:disconnected",B="dde:attributeChanged";var y=f.M?rt():new Proxy({},{get(){return()=>{}}});function rt(){let t=new Map,e=!1,n=s=>function(u){for(let i of u)if(i.type==="childList"){if(l(i.addedNodes,!0)){s();continue}v(i.removedNodes,!0)&&s()}},r=new f.M(n(a));return{observe(s){let u=new f.M(n(()=>{}));return u.observe(s,{childList:!0,subtree:!0}),()=>u.disconnect()},onConnected(s,u){p();let i=c(s);i.connected.has(u)||(i.connected.add(u),i.length_c+=1)},offConnected(s,u){if(!t.has(s))return;let i=t.get(s);i.connected.has(u)&&(i.connected.delete(u),i.length_c-=1,o(s,i))},onDisconnected(s,u){p();let i=c(s);i.disconnected.has(u)||(i.disconnected.add(u),i.length_d+=1)},offDisconnected(s,u){if(!t.has(s))return;let i=t.get(s);i.disconnected.delete(u),i.length_d-=1,o(s,i)}};function o(s,u){u.length_c||u.length_d||(t.delete(s),a())}function c(s){if(t.has(s))return t.get(s);let u={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(s,u),u}function p(){e||(e=!0,r.observe(f.D.body,{childList:!0,subtree:!0}))}function a(){!e||t.size||(e=!1,r.disconnect())}function d(){return new Promise(function(s){(requestIdleCallback||requestAnimationFrame)(s)})}async function m(s){t.size>30&&await d();let u=[];if(!h(s,f.N))return u;for(let i of t.keys())i===s||!h(i,f.N)||s.contains(i)&&u.push(i);return u}function l(s,u){let i=!1;for(let b of s){if(u&&m(b).then(l),!t.has(b))continue;let S=t.get(b);S.length_c&&(b.dispatchEvent(new Event(E)),S.connected=new WeakSet,S.length_c=0,S.length_d||t.delete(b),i=!0)}return i}function v(s,u){let i=!1;for(let b of s)u&&m(b).then(v),!(!t.has(b)||!t.get(b).length_d)&&((globalThis.queueMicrotask||setTimeout)(q(b)),i=!0);return i}function q(s){return()=>{s.isConnected||(s.dispatchEvent(new Event(w)),t.delete(s))}}}function vt(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 p=c.length?new CustomEvent(t,g({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(p)}}function D(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}D.defer=t=>setTimeout.bind(null,t,0);var Z=t=>g({},typeof t=="object"?t:null,{once:!0});D.connected=function(t,e){return e=Z(e),function(r){return r.addEventListener(E,t,e),r[C]?r:r.isConnected?(r.dispatchEvent(new Event(E)),r):(W(e.signal,()=>y.offConnected(r,t))&&y.onConnected(r,t),r)}};D.disconnected=function(t,e){return e=Z(e),function(r){return r.addEventListener(w,t,e),r[C]||W(e.signal,()=>y.offDisconnected(r,t))&&y.onDisconnected(r,t),r}};var _=[{get scope(){return f.D.body},host:t=>t?t(f.D.body):f.D.body,prevent:!0}],j=new WeakMap,A={get current(){return _[_.length-1]},get host(){return this.current.host},get signal(){let{host:t}=this;if(j.has(t))return j.get(t);let e=new AbortController;return j.set(t,e),t(D.disconnected(()=>e.abort())),e.signal},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[..._]},push(t={}){return _.push(g({},this.current,{prevent:!1},t))},pushRoot(){return _.push(_[0])},pop(){if(_.length!==1)return _.pop()}};var O={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function ot(t,e=!0){return e?g(O,t):(Object.setPrototypeOf(t,O),t)}function L(t){return z(t,O)&&t!==O?t:O}function G(t,e,n,r){return t[(x(r)?"remove":"set")+e](n,r)}function J(t,e,n,r,o=null){return t[(x(r)?"remove":"set")+e+"NS"](o,n,r)}function F(t,e,n){if(Reflect.set(t,e,n),!!x(n))return Reflect.deleteProperty(t,e)}function V(t,e,n,r){return h(t,f.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function Tt(t){return f.q(t)}function K(...t){return this.appendOriginal(...t),this}function ct(t){return t.append===K||(t.appendOriginal=t.append,t.append=K),t}var T;function U(t,e,...n){let r=L(this),o=0,c,p,a=typeof e;switch((a==="string"||a==="number"||r.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1;let d=(...v)=>v.length?(o===1?n.unshift(...v):v.forEach(q=>q(p)),void 0):p;A.push({scope:t,host:d}),c=t(e||void 0);let m=h(c,f.F);if(c.nodeName==="#comment")break;let l=U.mark({type:"component",name:t.name,host:m?"this":"parentElement"});c.prepend(l),m&&(p=l);break}case t==="#text":c=N.call(this,f.D.createTextNode(""),e);break;case(t==="<>"||!t):c=N.call(this,f.D.createDocumentFragment(),e);break;case!!T:c=N.call(this,f.D.createElementNS(T,t),e);break;case!c:c=N.call(this,f.D.createElement(t),e)}return ct(c),p||(p=c),n.forEach(d=>d(p)),o&&A.pop(),o=2,c}U.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=f.D.createComment(``);return e&&(r.end=f.D.createComment("")),r};function Mt(t){let e=this;return function(...r){T=t;let o=U.call(e,...r);return T=void 0,o}}var P=new WeakMap,{setDeleteAttr:Q}=f;function N(t,...e){if(!e.length)return t;P.set(t,Y(t,this));for(let[n,r]of Object.entries(g({},...e)))X.call(this,t,n,r);return P.delete(t),t}function X(t,e,n){let{setRemoveAttr:r,s:o}=Y(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(a,d)=>X.call(c,t,a,d));let[p]=e;if(p==="=")return r(e.slice(1),n);if(p===".")return F(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 Q(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return I(o,e,t,n,F.bind(null,t[e]));case"ariaset":return I(o,e,t,n,(a,d)=>r("aria-"+a,d));case"classList":return st.call(c,t,n)}return it(t,e)?Q(t,e,n):r(e,n)}function Y(t,e){if(P.has(t))return P.get(t);let r=(h(t,f.S)?J:G).bind(null,t,"Attribute"),o=L(e);return{setRemoveAttr:r,s:o}}function st(t,e){let n=L(this);return I(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function it(t,e){if(!(e in t))return!1;let n=tt(t,e);return!x(n.set)}function tt(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||tt(t,e)}function I(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([a,d]){a&&(a=new c(a),a.target=e,d=t.processReactiveAttribute(n,a,d,o),o(a,d))})}function kt(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,p,a){if(a[0]===e)return c.apply(t,a);for(let d of a){let m=(d.slot||"")+n;try{V(d,"remove","slot")}catch{}let l=o[m];if(!l)return;l.name.startsWith(r)||(l.childNodes.forEach(v=>v.remove()),l.name=r+m),l.append(d)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}function Ht(t,e,n={}){let r=t.host||t;A.push({scope:r,host:(...p)=>p.length?p.forEach(a=>a(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[C];o||ut(r);let c=e.call(r,n);return o||r.dispatchEvent(new Event(E)),t.nodeType===11&&typeof t.mode=="string"&&r.addEventListener(w,y.observe(t),{once:!0}),A.pop(),t.append(c)}function ut(t){return $(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(E))}),$(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(w)))}),$(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(B,{detail:[o,c]})),e.apply(n,r)}),t.prototype[C]=!0,t}function $(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}var et="__dde_memo_of",M=[];function k(t,e){if(!M.length)return e(t);let n=typeof t=="object"?JSON.stringify(t):t,[{cache:r,after:o}]=M;return o(n,H(r,n)?r[n]:e(t))}k.isScope=function(t){return!!t[et]};k.scope=function(e,{signal:n,onlyLast:r}={}){let o=R();function c(...p){if(n&&n.aborted)return e.apply(this,p);let a=r?o:R();M.unshift({cache:o,after(m,l){return a[m]=l}});let d=e.apply(this,p);return M.shift(),o=a,d}return c[et]=e,c.clear=()=>o=R(),n&&n.addEventListener("abort",c.clear),c};export{N as assign,X as assignAttribute,ct as chainableAppend,st as classListDeclarative,U as createElement,Mt as createElementNS,Ht as customElementRender,ut as customElementWithDDE,vt as dispatchEvent,U as el,Mt as elNS,ut as lifecyclesToEvents,k as memo,D as on,Tt as queue,ot as registerReactivity,A as scope,kt as simulateSlots}; +var H=(...t)=>Object.prototype.hasOwnProperty.call(...t);function x(t){return typeof t>"u"}function h(t,e){return t instanceof e}function z(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function R(t=null,e={}){return Object.create(t,e)}function g(...t){return Object.assign(...t)}function W(t,e){if(!t||!h(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var f={setDeleteAttr:nt,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 nt(t,e,n){if(Reflect.set(t,e,n),!!x(n)){if(Reflect.deleteProperty(t,e),h(t,f.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var C="__dde_lifecyclesToEvents",E="dde:connected",w="dde:disconnected",B="dde:attributeChanged";var y=f.M?rt():new Proxy({},{get(){return()=>{}}});function rt(){let t=new Map,e=!1,n=s=>function(u){for(let i of u)if(i.type==="childList"){if(l(i.addedNodes,!0)){s();continue}v(i.removedNodes,!0)&&s()}},r=new f.M(n(a));return{observe(s){let u=new f.M(n(()=>{}));return u.observe(s,{childList:!0,subtree:!0}),()=>u.disconnect()},onConnected(s,u){p();let i=c(s);i.connected.has(u)||(i.connected.add(u),i.length_c+=1)},offConnected(s,u){if(!t.has(s))return;let i=t.get(s);i.connected.has(u)&&(i.connected.delete(u),i.length_c-=1,o(s,i))},onDisconnected(s,u){p();let i=c(s);i.disconnected.has(u)||(i.disconnected.add(u),i.length_d+=1)},offDisconnected(s,u){if(!t.has(s))return;let i=t.get(s);i.disconnected.delete(u),i.length_d-=1,o(s,i)}};function o(s,u){u.length_c||u.length_d||(t.delete(s),a())}function c(s){if(t.has(s))return t.get(s);let u={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(s,u),u}function p(){e||(e=!0,r.observe(f.D.body,{childList:!0,subtree:!0}))}function a(){!e||t.size||(e=!1,r.disconnect())}function d(){return new Promise(function(s){(requestIdleCallback||requestAnimationFrame)(s)})}async function m(s){t.size>30&&await d();let u=[];if(!h(s,f.N))return u;for(let i of t.keys())i===s||!h(i,f.N)||s.contains(i)&&u.push(i);return u}function l(s,u){let i=!1;for(let b of s){if(u&&m(b).then(l),!t.has(b))continue;let S=t.get(b);S.length_c&&(b.dispatchEvent(new Event(E)),S.connected=new WeakSet,S.length_c=0,S.length_d||t.delete(b),i=!0)}return i}function v(s,u){let i=!1;for(let b of s)u&&m(b).then(v),!(!t.has(b)||!t.get(b).length_d)&&((globalThis.queueMicrotask||setTimeout)(q(b)),i=!0);return i}function q(s){return()=>{s.isConnected||(s.dispatchEvent(new Event(w)),t.delete(s))}}}function vt(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 p=c.length?new CustomEvent(t,g({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(p)}}function D(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}D.defer=t=>setTimeout.bind(null,t,0);var Z=t=>g({},typeof t=="object"?t:null,{once:!0});D.connected=function(t,e){return e=Z(e),function(r){return r.addEventListener(E,t,e),r[C]?r:r.isConnected?(r.dispatchEvent(new Event(E)),r):(W(e.signal,()=>y.offConnected(r,t))&&y.onConnected(r,t),r)}};D.disconnected=function(t,e){return e=Z(e),function(r){return r.addEventListener(w,t,e),r[C]||W(e.signal,()=>y.offDisconnected(r,t))&&y.onDisconnected(r,t),r}};var _=[{get scope(){return f.D.body},host:t=>t?t(f.D.body):f.D.body,prevent:!0}],j=new WeakMap,A={get current(){return _[_.length-1]},get host(){return this.current.host},get signal(){let{host:t}=this;if(j.has(t))return j.get(t);let e=new AbortController;return j.set(t,e),t(D.disconnected(()=>e.abort())),e.signal},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[..._]},push(t={}){return _.push(g({},this.current,{prevent:!1},t))},pushRoot(){return _.push(_[0])},pop(){if(_.length!==1)return _.pop()}};var O={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function ot(t,e=!0){return e?g(O,t):(Object.setPrototypeOf(t,O),t)}function L(t){return z(t,O)&&t!==O?t:O}function G(t,e,n,r){return t[(x(r)?"remove":"set")+e](n,r)}function J(t,e,n,r,o=null){return t[(x(r)?"remove":"set")+e+"NS"](o,n,r)}function F(t,e,n){if(Reflect.set(t,e,n),!!x(n))return Reflect.deleteProperty(t,e)}function V(t,e,n,r){return h(t,f.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function Tt(t){return f.q(t)}function K(...t){return this.appendOriginal(...t),this}function ct(t){return t.append===K||(t.appendOriginal=t.append,t.append=K),t}var T;function U(t,e,...n){let r=L(this),o=0,c,p,a=typeof e;switch((a==="string"||a==="number"||r.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1;let d=(...v)=>v.length?(o===1?n.unshift(...v):v.forEach(q=>q(p)),void 0):p;A.push({scope:t,host:d}),c=t(e||void 0);let m=h(c,f.F);if(c.nodeName==="#comment")break;let l=U.mark({type:"component",name:t.name,host:m?"this":"parentElement"});c.prepend(l),m&&(p=l);break}case t==="#text":c=N.call(this,f.D.createTextNode(""),e);break;case(t==="<>"||!t):c=N.call(this,f.D.createDocumentFragment(),e);break;case!!T:c=N.call(this,f.D.createElementNS(T,t),e);break;case!c:c=N.call(this,f.D.createElement(t),e)}return ct(c),p||(p=c),n.forEach(d=>d(p)),o&&A.pop(),o=2,c}U.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=f.D.createComment(``);return e&&(r.end=f.D.createComment("")),r};function Mt(t){let e=this;return function(...r){T=t;let o=U.call(e,...r);return T=void 0,o}}var P=new WeakMap,{setDeleteAttr:Q}=f;function N(t,...e){if(!e.length)return t;P.set(t,Y(t,this));for(let[n,r]of Object.entries(g({},...e)))X.call(this,t,n,r);return P.delete(t),t}function X(t,e,n){let{setRemoveAttr:r,s:o}=Y(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(a,d)=>X.call(c,t,a,d));let[p]=e;if(p==="=")return r(e.slice(1),n);if(p===".")return F(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 Q(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return I(o,e,t,n,F.bind(null,t[e]));case"ariaset":return I(o,e,t,n,(a,d)=>r("aria-"+a,d));case"classList":return st.call(c,t,n)}return it(t,e)?Q(t,e,n):r(e,n)}function Y(t,e){if(P.has(t))return P.get(t);let r=(h(t,f.S)?J:G).bind(null,t,"Attribute"),o=L(e);return{setRemoveAttr:r,s:o}}function st(t,e){let n=L(this);return I(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function it(t,e){if(!(e in t))return!1;let n=tt(t,e);return!x(n.set)}function tt(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||tt(t,e)}function I(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([a,d]){a&&(a=new c(a),a.target=e,d=t.processReactiveAttribute(n,a,d,o),o(a,d))})}function kt(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,p,a){if(a[0]===e)return c.apply(t,a);for(let d of a){let m=(d.slot||"")+n;try{V(d,"remove","slot")}catch{}let l=o[m];if(!l)return;l.name.startsWith(r)||(l.childNodes.forEach(v=>v.remove()),l.name=r+m),l.append(d)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}function Ht(t,e,n={}){let r=t.host||t;A.push({scope:r,host:(...p)=>p.length?p.forEach(a=>a(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[C];o||ut(r);let c=e.call(r,n);return o||r.dispatchEvent(new Event(E)),t.nodeType===11&&typeof t.mode=="string"&&r.addEventListener(w,y.observe(t),{once:!0}),A.pop(),t.append(c)}function ut(t){return $(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(E))}),$(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(w)))}),$(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(B,{detail:[o,c]})),e.apply(n,r)}),t.prototype[C]=!0,t}function $(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}var et="__dde_memo",M=[];function k(t,e){if(!M.length)return e(t);let n=typeof t=="object"?JSON.stringify(t):t,[{cache:r,after:o}]=M;return o(n,H(r,n)?r[n]:e(t))}k.isScope=function(t){return t[et]};k.scope=function(e,{signal:n,onlyLast:r}={}){let o=R();function c(...p){if(n&&n.aborted)return e.apply(this,p);let a=r?o:R();M.unshift({cache:o,after(m,l){return a[m]=l}});let d=e.apply(this,p);return M.shift(),o=a,d}return c[et]=!0,c.clear=()=>o=R(),n&&n.addEventListener("abort",c.clear),c};export{N as assign,X as assignAttribute,ct as chainableAppend,st as classListDeclarative,U as createElement,Mt as createElementNS,Ht as customElementRender,ut as customElementWithDDE,vt as dispatchEvent,U as el,Mt as elNS,ut as lifecyclesToEvents,k as memo,D as on,Tt as queue,ot as registerReactivity,A as scope,kt as simulateSlots}; diff --git a/dist/iife-with-signals.js b/dist/iife-with-signals.js index 14e212a..c530964 100644 --- a/dist/iife-with-signals.js +++ b/dist/iife-with-signals.js @@ -684,7 +684,7 @@ var DDE = (() => { } // src/memo.js - var memoMark = "__dde_memo_of"; + var memoMark = "__dde_memo"; var memo_scope = []; function memo(key, generator) { if (!memo_scope.length) return generator(key); @@ -693,7 +693,7 @@ var DDE = (() => { return after(k, hasOwn(cache, k) ? cache[k] : generator(key)); } memo.isScope = function(obj) { - return Boolean(obj[memoMark]); + return obj[memoMark]; }; memo.scope = function memoScopeCreate(fun, { signal: signal2, onlyLast } = {}) { let cache = oCreate(); @@ -712,7 +712,7 @@ var DDE = (() => { cache = cache_local; return out; } - memoScope[memoMark] = fun; + memoScope[memoMark] = true; memoScope.clear = () => cache = oCreate(); if (signal2) signal2.addEventListener("abort", memoScope.clear); return memoScope; @@ -832,7 +832,7 @@ var DDE = (() => { }; var key_reactive = "__dde_reactive"; signal.el = function(s, map) { - map = memo.isScope(map) ? map : memo.scope(map, { onlyLast: true }); + const mapScoped = memo.isScope(map) ? map : memo.scope(map, { onlyLast: true }); const { current } = scope, { scope: sc } = current; const mark_start = createElement.mark({ type: "reactive", component: sc && sc.name || "" }, true); const mark_end = mark_start.end; @@ -842,7 +842,7 @@ var DDE = (() => { if (!mark_start.parentNode || !mark_end.parentNode) return removeSignalListener(s, reRenderReactiveElement); scope.push(current); - let els = map(v); + let els = mapScoped(v); scope.pop(); if (!Array.isArray(els)) els = [els]; @@ -862,7 +862,7 @@ var DDE = (() => { current.host(on.disconnected( () => ( /*! Clears cached elements for reactive element `S.el` */ - map.clear() + mapScoped.clear() ) )); return out; @@ -934,9 +934,8 @@ var DDE = (() => { function removeSignalsFromElements(s, listener, ...notes) { const { current } = scope; current.host(function(element) { - if (element[key_reactive]) - return element[key_reactive].push([[s, listener], ...notes]); - element[key_reactive] = []; + if (!element[key_reactive]) element[key_reactive] = []; + element[key_reactive].push([[s, listener], ...notes]); if (current.prevent) return; on.disconnected( () => ( diff --git a/dist/iife-with-signals.min.js b/dist/iife-with-signals.min.js index 628f548..2214989 100644 --- a/dist/iife-with-signals.min.js +++ b/dist/iife-with-signals.min.js @@ -1,3 +1,3 @@ -var DDE=(()=>{var G=Object.defineProperty;var Ct=Object.getOwnPropertyDescriptor;var Ot=Object.getOwnPropertyNames;var Rt=Object.prototype.hasOwnProperty;var Dt=(t,e)=>{for(var n in e)G(t,n,{get:e[n],enumerable:!0})},Lt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ot(e))!Rt.call(t,o)&&o!==n&&G(t,o,{get:()=>e[o],enumerable:!(r=Ct(e,o))||r.enumerable});return t};var Nt=t=>Lt(G({},"__esModule",{value:!0}),t);var Gt={};Dt(Gt,{S:()=>g,assign:()=>W,assignAttribute:()=>Y,chainableAppend:()=>ht,classListDeclarative:()=>gt,createElement:()=>k,createElementNS:()=>Wt,customElementRender:()=>It,customElementWithDDE:()=>bt,dispatchEvent:()=>Pt,el:()=>k,elNS:()=>Wt,isSignal:()=>j,lifecyclesToEvents:()=>bt,memo:()=>L,on:()=>w,queue:()=>qt,registerReactivity:()=>U,scope:()=>b,signal:()=>g,simulateSlots:()=>Ft});var F=(...t)=>Object.prototype.hasOwnProperty.call(...t);function A(t){return typeof t>"u"}function ct(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 it(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function S(t=null,e={}){return Object.create(t,e)}function x(...t){return Object.assign(...t)}function V(t,e){if(!t||!_(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}function st(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 p={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),_(t,p.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var T="__dde_lifecyclesToEvents",C="dde:connected",R="dde:disconnected",I="dde:attributeChanged";var D=p.M?kt():new Proxy({},{get(){return()=>{}}});function kt(){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}v(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 y of u){if(a&&h(y).then(m),!t.has(y))continue;let P=t.get(y);P.length_c&&(y.dispatchEvent(new Event(C)),P.connected=new WeakSet,P.length_c=0,P.length_d||t.delete(y),f=!0)}return f}function v(u,a){let f=!1;for(let y of u)a&&h(y).then(v),!(!t.has(y)||!t.get(y).length_d)&&((globalThis.queueMicrotask||setTimeout)(Z(y)),f=!0);return f}function Z(u){return()=>{u.isConnected||(u.dispatchEvent(new Event(R)),t.delete(u))}}}function Pt(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,x({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(i)}}function w(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}w.defer=t=>setTimeout.bind(null,t,0);var ut=t=>x({},typeof t=="object"?t:null,{once:!0});w.connected=function(t,e){return e=ut(e),function(r){return r.addEventListener(C,t,e),r[T]?r:r.isConnected?(r.dispatchEvent(new Event(C)),r):(V(e.signal,()=>D.offConnected(r,t))&&D.onConnected(r,t),r)}};w.disconnected=function(t,e){return e=ut(e),function(r){return r.addEventListener(R,t,e),r[T]||V(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}],K=new WeakMap,b={get current(){return O[O.length-1]},get host(){return this.current.host},get signal(){let{host:t}=this;if(K.has(t))return K.get(t);let e=new AbortController;return K.set(t,e),t(w.disconnected(()=>e.abort())),e.signal},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...O]},push(t={}){return O.push(x({},this.current,{prevent:!1},t))},pushRoot(){return O.push(O[0])},pop(){if(O.length!==1)return O.pop()}};var q={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function U(t,e=!0){return e?x(q,t):(Object.setPrototypeOf(t,q),t)}function $(t){return it(t,q)&&t!==q?t:q}function ft(t,e,n,r){return t[(A(r)?"remove":"set")+e](n,r)}function at(t,e,n,r,o=null){return t[(A(r)?"remove":"set")+e+"NS"](o,n,r)}function Q(t,e,n){if(Reflect.set(t,e,n),!!A(n))return Reflect.deleteProperty(t,e)}function pt(t,e,n,r){return _(t,p.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function qt(t){return p.q(t)}function dt(...t){return this.appendOriginal(...t),this}function ht(t){return t.append===dt||(t.appendOriginal=t.append,t.append=dt),t}var z;function k(t,e,...n){let r=$(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=(...v)=>v.length?(o===1?n.unshift(...v):v.forEach(Z=>Z(i)),void 0):i;b.push({scope:t,host:d}),c=t(e||void 0);let h=_(c,p.F);if(c.nodeName==="#comment")break;let m=k.mark({type:"component",name:t.name,host:h?"this":"parentElement"});c.prepend(m),h&&(i=m);break}case t==="#text":c=W.call(this,p.D.createTextNode(""),e);break;case(t==="<>"||!t):c=W.call(this,p.D.createDocumentFragment(),e);break;case!!z:c=W.call(this,p.D.createElementNS(z,t),e);break;case!c:c=W.call(this,p.D.createElement(t),e)}return ht(c),i||(i=c),n.forEach(d=>d(i)),o&&b.pop(),o=2,c}k.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=p.D.createComment(``);return e&&(r.end=p.D.createComment("")),r};function Wt(t){let e=this;return function(...r){z=t;let o=k.call(e,...r);return z=void 0,o}}var H=new WeakMap,{setDeleteAttr:lt}=p;function W(t,...e){if(!e.length)return t;H.set(t,mt(t,this));for(let[n,r]of Object.entries(x({},...e)))Y.call(this,t,n,r);return H.delete(t),t}function Y(t,e,n){let{setRemoveAttr:r,s:o}=mt(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(s,d)=>Y.call(c,t,s,d));let[i]=e;if(i==="=")return r(e.slice(1),n);if(i===".")return Q(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 lt(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return X(o,e,t,n,Q.bind(null,t[e]));case"ariaset":return X(o,e,t,n,(s,d)=>r("aria-"+s,d));case"classList":return gt.call(c,t,n)}return jt(t,e)?lt(t,e,n):r(e,n)}function mt(t,e){if(H.has(t))return H.get(t);let r=(_(t,p.S)?at:ft).bind(null,t,"Attribute"),o=$(e);return{setRemoveAttr:r,s:o}}function gt(t,e){let n=$(this);return X(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function jt(t,e){if(!(e in t))return!1;let n=vt(t,e);return!A(n.set)}function vt(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||vt(t,e)}function X(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 Ft(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{pt(d,"remove","slot")}catch{}let m=o[h];if(!m)return;m.name.startsWith(r)||(m.childNodes.forEach(v=>v.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 It(t,e,n={}){let r=t.host||t;b.push({scope:r,host:(...i)=>i.length?i.forEach(s=>s(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[T];o||bt(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}),b.pop(),t.append(c)}function bt(t){return tt(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(C))}),tt(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(R)))}),tt(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(I,{detail:[o,c]})),e.apply(n,r)}),t.prototype[T]=!0,t}function tt(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}var xt="__dde_memo_of",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,F(r,n)?r[n]:e(t))}L.isScope=function(t){return!!t[xt]};L.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();B.unshift({cache:o,after(h,m){return s[h]=m}});let d=e.apply(this,i);return B.shift(),o=s,d}return c[xt]=e,c.clear=()=>o=S(),n&&n.addEventListener("abort",c.clear),c};var l="__dde_signal",et=(()=>{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 rt=S(null,{get:{value(){return _t(this)}},set:{value(...t){return At(this,...t)}},toJSON:{value(){return _t(this)}},valueOf:{value(){return this[l]&&this[l].value}}}),Ut=S(rt,{set:{value(){}}});function j(t){return t&&t[l]}var J=[],E=new WeakMap;function g(t,e){if(typeof t!="function")return Et(!1,t,e);if(j(t))return t;let n=Et(!0);function r(o,c){let[i,...s]=E.get(r);if(E.set(r,new Set([i])),J.push(r),At(n,t(),c),J.pop(),!s.length)return;let d=E.get(r);for(let h of s)d.has(h)||M(h,r)}return E.set(n[l],r),E.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||!F(o,e))throw new Error(`Action "${e}" not defined. See ${l}.actions.`);if(o[e].apply(r,n),r.skip)return delete r.skip;et(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));ot(e,n),o&&o.addEventListener("abort",()=>M(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),!E.has(o))return;let c=E.get(o);c.delete(n),!(c.size>1)&&(n.clear(...c),E.delete(o))})}};var N="__dde_reactive";g.el=function(t,e){e=L.isScope(e)?e:L.scope(e,{onlyLast:!0});let{current:n}=b,{scope:r}=n,o=k.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 M(t,s);b.push(n);let h=e(d);b.pop(),Array.isArray(h)||(h=[h]);let m=document.createComment("");h.push(m),o.after(...h);let v;for(;(v=m.nextSibling)&&v!==c;)v.remove();m.remove(),o.isConnected&&$t(n.host())};return ot(t,s),wt(t,s,o,e),s(t.get()),n.host(w.disconnected(()=>e.clear())),i};function $t(t){!t||!t[N]||(requestIdleCallback||setTimeout)(function(){t[N]=t[N].filter(([e,n])=>n.isConnected?!0:(M(...e),!1))})}var zt={_set(t){this.value=t}};function Ht(t){return function(e,n){let r=S(rt,{set:{value(...c){return e.setAttribute(n,...c)}}}),o=yt(r,e.getAttribute(n),zt);return t[n]=o,o}}var nt="__dde_attributes";g.observedAttributes=function(t){let e=t[nt]={},n=st(t,Ht(e));return w(I,function({detail:o}){/*! This maps attributes to signals (`S.observedAttributes`). +var DDE=(()=>{var G=Object.defineProperty;var Ct=Object.getOwnPropertyDescriptor;var Ot=Object.getOwnPropertyNames;var Rt=Object.prototype.hasOwnProperty;var Dt=(t,e)=>{for(var n in e)G(t,n,{get:e[n],enumerable:!0})},Lt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ot(e))!Rt.call(t,o)&&o!==n&&G(t,o,{get:()=>e[o],enumerable:!(r=Ct(e,o))||r.enumerable});return t};var Nt=t=>Lt(G({},"__esModule",{value:!0}),t);var Gt={};Dt(Gt,{S:()=>g,assign:()=>j,assignAttribute:()=>Y,chainableAppend:()=>ht,classListDeclarative:()=>gt,createElement:()=>P,createElementNS:()=>Wt,customElementRender:()=>It,customElementWithDDE:()=>bt,dispatchEvent:()=>Pt,el:()=>P,elNS:()=>Wt,isSignal:()=>F,lifecyclesToEvents:()=>bt,memo:()=>N,on:()=>w,queue:()=>qt,registerReactivity:()=>$,scope:()=>b,signal:()=>g,simulateSlots:()=>Ft});var I=(...t)=>Object.prototype.hasOwnProperty.call(...t);function A(t){return typeof t>"u"}function ct(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 it(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function S(t=null,e={}){return Object.create(t,e)}function x(...t){return Object.assign(...t)}function V(t,e){if(!t||!_(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}function st(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 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),_(t,d.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var k="__dde_lifecyclesToEvents",C="dde:connected",D="dde:disconnected",U="dde:attributeChanged";var L=d.M?kt():new Proxy({},{get(){return()=>{}}});function kt(){let t=new Map,e=!1,n=u=>function(a){for(let f of a)if(f.type==="childList"){if(h(f.addedNodes,!0)){u();continue}v(f.removedNodes,!0)&&u()}},r=new d.M(n(s));return{observe(u){let a=new d.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(d.D.body,{childList:!0,subtree:!0}))}function s(){!e||t.size||(e=!1,r.disconnect())}function p(){return new Promise(function(u){(requestIdleCallback||requestAnimationFrame)(u)})}async function m(u){t.size>30&&await p();let a=[];if(!_(u,d.N))return a;for(let f of t.keys())f===u||!_(f,d.N)||u.contains(f)&&a.push(f);return a}function h(u,a){let f=!1;for(let y of u){if(a&&m(y).then(h),!t.has(y))continue;let q=t.get(y);q.length_c&&(y.dispatchEvent(new Event(C)),q.connected=new WeakSet,q.length_c=0,q.length_d||t.delete(y),f=!0)}return f}function v(u,a){let f=!1;for(let y of u)a&&m(y).then(v),!(!t.has(y)||!t.get(y).length_d)&&((globalThis.queueMicrotask||setTimeout)(R(y)),f=!0);return f}function R(u){return()=>{u.isConnected||(u.dispatchEvent(new Event(D)),t.delete(u))}}}function Pt(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,x({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(i)}}function w(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}w.defer=t=>setTimeout.bind(null,t,0);var ut=t=>x({},typeof t=="object"?t:null,{once:!0});w.connected=function(t,e){return e=ut(e),function(r){return r.addEventListener(C,t,e),r[k]?r:r.isConnected?(r.dispatchEvent(new Event(C)),r):(V(e.signal,()=>L.offConnected(r,t))&&L.onConnected(r,t),r)}};w.disconnected=function(t,e){return e=ut(e),function(r){return r.addEventListener(D,t,e),r[k]||V(e.signal,()=>L.offDisconnected(r,t))&&L.onDisconnected(r,t),r}};var O=[{get scope(){return d.D.body},host:t=>t?t(d.D.body):d.D.body,prevent:!0}],K=new WeakMap,b={get current(){return O[O.length-1]},get host(){return this.current.host},get signal(){let{host:t}=this;if(K.has(t))return K.get(t);let e=new AbortController;return K.set(t,e),t(w.disconnected(()=>e.abort())),e.signal},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...O]},push(t={}){return O.push(x({},this.current,{prevent:!1},t))},pushRoot(){return O.push(O[0])},pop(){if(O.length!==1)return O.pop()}};var W={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function $(t,e=!0){return e?x(W,t):(Object.setPrototypeOf(t,W),t)}function z(t){return it(t,W)&&t!==W?t:W}function ft(t,e,n,r){return t[(A(r)?"remove":"set")+e](n,r)}function at(t,e,n,r,o=null){return t[(A(r)?"remove":"set")+e+"NS"](o,n,r)}function Q(t,e,n){if(Reflect.set(t,e,n),!!A(n))return Reflect.deleteProperty(t,e)}function pt(t,e,n,r){return _(t,d.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function qt(t){return d.q(t)}function dt(...t){return this.appendOriginal(...t),this}function ht(t){return t.append===dt||(t.appendOriginal=t.append,t.append=dt),t}var H;function P(t,e,...n){let r=z(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 p=(...v)=>v.length?(o===1?n.unshift(...v):v.forEach(R=>R(i)),void 0):i;b.push({scope:t,host:p}),c=t(e||void 0);let m=_(c,d.F);if(c.nodeName==="#comment")break;let h=P.mark({type:"component",name:t.name,host:m?"this":"parentElement"});c.prepend(h),m&&(i=h);break}case t==="#text":c=j.call(this,d.D.createTextNode(""),e);break;case(t==="<>"||!t):c=j.call(this,d.D.createDocumentFragment(),e);break;case!!H:c=j.call(this,d.D.createElementNS(H,t),e);break;case!c:c=j.call(this,d.D.createElement(t),e)}return ht(c),i||(i=c),n.forEach(p=>p(i)),o&&b.pop(),o=2,c}P.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=d.D.createComment(``);return e&&(r.end=d.D.createComment("")),r};function Wt(t){let e=this;return function(...r){H=t;let o=P.call(e,...r);return H=void 0,o}}var J=new WeakMap,{setDeleteAttr:lt}=d;function j(t,...e){if(!e.length)return t;J.set(t,mt(t,this));for(let[n,r]of Object.entries(x({},...e)))Y.call(this,t,n,r);return J.delete(t),t}function Y(t,e,n){let{setRemoveAttr:r,s:o}=mt(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(s,p)=>Y.call(c,t,s,p));let[i]=e;if(i==="=")return r(e.slice(1),n);if(i===".")return Q(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 lt(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return X(o,e,t,n,Q.bind(null,t[e]));case"ariaset":return X(o,e,t,n,(s,p)=>r("aria-"+s,p));case"classList":return gt.call(c,t,n)}return jt(t,e)?lt(t,e,n):r(e,n)}function mt(t,e){if(J.has(t))return J.get(t);let r=(_(t,d.S)?at:ft).bind(null,t,"Attribute"),o=z(e);return{setRemoveAttr:r,s:o}}function gt(t,e){let n=z(this);return X(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function jt(t,e){if(!(e in t))return!1;let n=vt(t,e);return!A(n.set)}function vt(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||vt(t,e)}function X(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([s,p]){s&&(s=new c(s),s.target=e,p=t.processReactiveAttribute(n,s,p,o),o(s,p))})}function Ft(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 p of s){let m=(p.slot||"")+n;try{pt(p,"remove","slot")}catch{}let h=o[m];if(!h)return;h.name.startsWith(r)||(h.childNodes.forEach(v=>v.remove()),h.name=r+m),h.append(p)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}function It(t,e,n={}){let r=t.host||t;b.push({scope:r,host:(...i)=>i.length?i.forEach(s=>s(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[k];o||bt(r);let c=e.call(r,n);return o||r.dispatchEvent(new Event(C)),t.nodeType===11&&typeof t.mode=="string"&&r.addEventListener(D,L.observe(t),{once:!0}),b.pop(),t.append(c)}function bt(t){return tt(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(C))}),tt(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(D)))}),tt(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[k]=!0,t}function tt(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}var xt="__dde_memo",B=[];function N(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))}N.isScope=function(t){return t[xt]};N.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();B.unshift({cache:o,after(m,h){return s[m]=h}});let p=e.apply(this,i);return B.shift(),o=s,p}return c[xt]=!0,c.clear=()=>o=S(),n&&n.addEventListener("abort",c.clear),c};var l="__dde_signal",et=(()=>{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 rt=S(null,{get:{value(){return _t(this)}},set:{value(...t){return At(this,...t)}},toJSON:{value(){return _t(this)}},valueOf:{value(){return this[l]&&this[l].value}}}),Ut=S(rt,{set:{value(){}}});function F(t){return t&&t[l]}var Z=[],E=new WeakMap;function g(t,e){if(typeof t!="function")return Et(!1,t,e);if(F(t))return t;let n=Et(!0);function r(o,c){let[i,...s]=E.get(r);if(E.set(r,new Set([i])),Z.push(r),At(n,t(),c),Z.pop(),!s.length)return;let p=E.get(r);for(let m of s)p.has(m)||T(m,r)}return E.set(n[l],r),E.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;et(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));ot(e,n),o&&o.addEventListener("abort",()=>T(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),!E.has(o))return;let c=E.get(o);c.delete(n),!(c.size>1)&&(n.clear(...c),E.delete(o))})}};var M="__dde_reactive";g.el=function(t,e){let n=N.isScope(e)?e:N.scope(e,{onlyLast:!0}),{current:r}=b,{scope:o}=r,c=P.mark({type:"reactive",component:o&&o.name||""},!0),i=c.end,s=d.D.createDocumentFragment();s.append(c,i);let p=m=>{if(!c.parentNode||!i.parentNode)return T(t,p);b.push(r);let h=n(m);b.pop(),Array.isArray(h)||(h=[h]);let v=document.createComment("");h.push(v),c.after(...h);let R;for(;(R=v.nextSibling)&&R!==i;)R.remove();v.remove(),c.isConnected&&$t(r.host())};return ot(t,p),wt(t,p,c,e),p(t.get()),r.host(w.disconnected(()=>n.clear())),s};function $t(t){!t||!t[M]||(requestIdleCallback||setTimeout)(function(){t[M]=t[M].filter(([e,n])=>n.isConnected?!0:(T(...e),!1))})}var zt={_set(t){this.value=t}};function Ht(t){return function(e,n){let r=S(rt,{set:{value(...c){return e.setAttribute(n,...c)}}}),o=yt(r,e.getAttribute(n),zt);return t[n]=o,o}}var nt="__dde_attributes";g.observedAttributes=function(t){let e=t[nt]={},n=st(t,Ht(e));return w(U,function({detail:o}){/*! This maps attributes to signals (`S.observedAttributes`). Investigate `__dde_attributes` key of the element. */let[c,i]=o,s=this[nt][c];if(s)return g.action(s,"_set",i)})(t),w.disconnected(function(){/*! This removes all signals mapped to attributes (`S.observedAttributes`). - Investigate `__dde_attributes` key of the element. */g.clear(...Object.values(this[nt]))})(t),n};var St={isSignal:j,processReactiveAttribute(t,e,n,r){if(!j(n))return n;let o=c=>{if(!t.isConnected)return M(n,o);r(e,c)};return ot(n,o),wt(n,o,t,e),n.get()}};function wt(t,e,...n){let{current:r}=b;r.host(function(o){if(o[N])return o[N].push([[t,e],...n]);o[N]=[],!r.prevent&&w.disconnected(()=>o[N].forEach(([[c,i]])=>M(c,i,c[l]&&c[l].host&&c[l].host()===o)))(o)})}var Bt=new FinalizationRegistry(function(t){g.clear({[l]:t})});function Et(t,e,n){let r=S(t?Ut:rt),o=yt(r,e,n,t);return Bt.register(o,o[l]),o}var Jt=x(S(),{stopPropagation(){this.skip=!0}});function yt(t,e,n,r=!1){let o=[];ct(n)!=="[object Object]"&&(n={});let{onclear:c}=g.symbols;n[c]&&(o.push(n[c]),delete n[c]);let{host:i}=b;return Reflect.defineProperty(t,l,{value:x(S(Jt),{value:e,actions:n,onclear:o,host:i,listeners:new Set,readonly:r}),enumerable:!1,writable:!1,configurable:!0}),t}function Zt(){return J[J.length-1]}function _t(t){if(!t[l])return;let{value:e,listeners:n}=t[l],r=Zt();return r&&n.add(r),E.has(r)&&E.get(r).add(t),e}function At(t,e,n){let r=t[l];if(!(!r||!n&&r.value===e))return r.value=e,et(t,n),e}function ot(t,e){if(t[l])return t[l].listeners.add(e)}function M(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 i=E.get(r);if(!i)return c;let s=E.get(i);if(!s)return c;for(let d of s)M(d,i,!0);return c}U(St);return Nt(Gt);})(); + Investigate `__dde_attributes` key of the element. */g.clear(...Object.values(this[nt]))})(t),n};var St={isSignal:F,processReactiveAttribute(t,e,n,r){if(!F(n))return n;let o=c=>{if(!t.isConnected)return T(n,o);r(e,c)};return ot(n,o),wt(n,o,t,e),n.get()}};function wt(t,e,...n){let{current:r}=b;r.host(function(o){o[M]||(o[M]=[]),o[M].push([[t,e],...n]),!r.prevent&&w.disconnected(()=>o[M].forEach(([[c,i]])=>T(c,i,c[l]&&c[l].host&&c[l].host()===o)))(o)})}var Jt=new FinalizationRegistry(function(t){g.clear({[l]:t})});function Et(t,e,n){let r=S(t?Ut:rt),o=yt(r,e,n,t);return Jt.register(o,o[l]),o}var Bt=x(S(),{stopPropagation(){this.skip=!0}});function yt(t,e,n,r=!1){let o=[];ct(n)!=="[object Object]"&&(n={});let{onclear:c}=g.symbols;n[c]&&(o.push(n[c]),delete n[c]);let{host:i}=b;return Reflect.defineProperty(t,l,{value:x(S(Bt),{value:e,actions:n,onclear:o,host:i,listeners:new Set,readonly:r}),enumerable:!1,writable:!1,configurable:!0}),t}function Zt(){return Z[Z.length-1]}function _t(t){if(!t[l])return;let{value:e,listeners:n}=t[l],r=Zt();return r&&n.add(r),E.has(r)&&E.get(r).add(t),e}function At(t,e,n){let r=t[l];if(!(!r||!n&&r.value===e))return r.value=e,et(t,n),e}function ot(t,e){if(t[l])return t[l].listeners.add(e)}function T(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 i=E.get(r);if(!i)return c;let s=E.get(i);if(!s)return c;for(let p of s)T(p,i,!0);return c}$(St);return Nt(Gt);})(); diff --git a/dist/iife.js b/dist/iife.js index 3ce917f..15fa790 100644 --- a/dist/iife.js +++ b/dist/iife.js @@ -665,7 +665,7 @@ var DDE = (() => { } // src/memo.js - var memoMark = "__dde_memo_of"; + var memoMark = "__dde_memo"; var memo_scope = []; function memo(key, generator) { if (!memo_scope.length) return generator(key); @@ -674,7 +674,7 @@ var DDE = (() => { return after(k, hasOwn(cache, k) ? cache[k] : generator(key)); } memo.isScope = function(obj) { - return Boolean(obj[memoMark]); + return obj[memoMark]; }; memo.scope = function memoScopeCreate(fun, { signal, onlyLast } = {}) { let cache = oCreate(); @@ -693,7 +693,7 @@ var DDE = (() => { cache = cache_local; return out; } - memoScope[memoMark] = fun; + memoScope[memoMark] = true; memoScope.clear = () => cache = oCreate(); if (signal) signal.addEventListener("abort", memoScope.clear); return memoScope; diff --git a/dist/iife.min.js b/dist/iife.min.js index 0b93ff0..12e6a97 100644 --- a/dist/iife.min.js +++ b/dist/iife.min.js @@ -1 +1 @@ -var DDE=(()=>{var F=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var ut=Object.getOwnPropertyNames;var ft=Object.prototype.hasOwnProperty;var at=(t,e)=>{for(var n in e)F(t,n,{get:e[n],enumerable:!0})},pt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ut(e))!ft.call(t,o)&&o!==n&&F(t,o,{get:()=>e[o],enumerable:!(r=it(e,o))||r.enumerable});return t};var dt=t=>pt(F({},"__esModule",{value:!0}),t);var _t={};at(_t,{assign:()=>R,assignAttribute:()=>H,chainableAppend:()=>et,classListDeclarative:()=>rt,createElement:()=>M,createElementNS:()=>vt,customElementRender:()=>Et,customElementWithDDE:()=>ct,dispatchEvent:()=>mt,el:()=>M,elNS:()=>vt,lifecyclesToEvents:()=>ct,memo:()=>W,on:()=>S,queue:()=>bt,registerReactivity:()=>V,scope:()=>C,simulateSlots:()=>xt});var B=(...t)=>Object.prototype.hasOwnProperty.call(...t);function x(t){return typeof t>"u"}function h(t,e){return t instanceof e}function Z(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function L(t=null,e={}){return Object.create(t,e)}function g(...t){return Object.assign(...t)}function I(t,e){if(!t||!h(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var f={setDeleteAttr:lt,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 lt(t,e,n){if(Reflect.set(t,e,n),!!x(n)){if(Reflect.deleteProperty(t,e),h(t,f.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var A="__dde_lifecyclesToEvents",E="dde:connected",w="dde:disconnected",G="dde:attributeChanged";var y=f.M?ht():new Proxy({},{get(){return()=>{}}});function ht(){let t=new Map,e=!1,n=s=>function(u){for(let i of u)if(i.type==="childList"){if(l(i.addedNodes,!0)){s();continue}v(i.removedNodes,!0)&&s()}},r=new f.M(n(a));return{observe(s){let u=new f.M(n(()=>{}));return u.observe(s,{childList:!0,subtree:!0}),()=>u.disconnect()},onConnected(s,u){p();let i=c(s);i.connected.has(u)||(i.connected.add(u),i.length_c+=1)},offConnected(s,u){if(!t.has(s))return;let i=t.get(s);i.connected.has(u)&&(i.connected.delete(u),i.length_c-=1,o(s,i))},onDisconnected(s,u){p();let i=c(s);i.disconnected.has(u)||(i.disconnected.add(u),i.length_d+=1)},offDisconnected(s,u){if(!t.has(s))return;let i=t.get(s);i.disconnected.delete(u),i.length_d-=1,o(s,i)}};function o(s,u){u.length_c||u.length_d||(t.delete(s),a())}function c(s){if(t.has(s))return t.get(s);let u={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(s,u),u}function p(){e||(e=!0,r.observe(f.D.body,{childList:!0,subtree:!0}))}function a(){!e||t.size||(e=!1,r.disconnect())}function d(){return new Promise(function(s){(requestIdleCallback||requestAnimationFrame)(s)})}async function m(s){t.size>30&&await d();let u=[];if(!h(s,f.N))return u;for(let i of t.keys())i===s||!h(i,f.N)||s.contains(i)&&u.push(i);return u}function l(s,u){let i=!1;for(let b of s){if(u&&m(b).then(l),!t.has(b))continue;let D=t.get(b);D.length_c&&(b.dispatchEvent(new Event(E)),D.connected=new WeakSet,D.length_c=0,D.length_d||t.delete(b),i=!0)}return i}function v(s,u){let i=!1;for(let b of s)u&&m(b).then(v),!(!t.has(b)||!t.get(b).length_d)&&((globalThis.queueMicrotask||setTimeout)(j(b)),i=!0);return i}function j(s){return()=>{s.isConnected||(s.dispatchEvent(new Event(w)),t.delete(s))}}}function mt(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 p=c.length?new CustomEvent(t,g({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(p)}}function S(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}S.defer=t=>setTimeout.bind(null,t,0);var J=t=>g({},typeof t=="object"?t:null,{once:!0});S.connected=function(t,e){return e=J(e),function(r){return r.addEventListener(E,t,e),r[A]?r:r.isConnected?(r.dispatchEvent(new Event(E)),r):(I(e.signal,()=>y.offConnected(r,t))&&y.onConnected(r,t),r)}};S.disconnected=function(t,e){return e=J(e),function(r){return r.addEventListener(w,t,e),r[A]||I(e.signal,()=>y.offDisconnected(r,t))&&y.onDisconnected(r,t),r}};var _=[{get scope(){return f.D.body},host:t=>t?t(f.D.body):f.D.body,prevent:!0}],U=new WeakMap,C={get current(){return _[_.length-1]},get host(){return this.current.host},get signal(){let{host:t}=this;if(U.has(t))return U.get(t);let e=new AbortController;return U.set(t,e),t(S.disconnected(()=>e.abort())),e.signal},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[..._]},push(t={}){return _.push(g({},this.current,{prevent:!1},t))},pushRoot(){return _.push(_[0])},pop(){if(_.length!==1)return _.pop()}};var O={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function V(t,e=!0){return e?g(O,t):(Object.setPrototypeOf(t,O),t)}function N(t){return Z(t,O)&&t!==O?t:O}function K(t,e,n,r){return t[(x(r)?"remove":"set")+e](n,r)}function Q(t,e,n,r,o=null){return t[(x(r)?"remove":"set")+e+"NS"](o,n,r)}function $(t,e,n){if(Reflect.set(t,e,n),!!x(n))return Reflect.deleteProperty(t,e)}function X(t,e,n,r){return h(t,f.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function bt(t){return f.q(t)}function Y(...t){return this.appendOriginal(...t),this}function et(t){return t.append===Y||(t.appendOriginal=t.append,t.append=Y),t}var T;function M(t,e,...n){let r=N(this),o=0,c,p,a=typeof e;switch((a==="string"||a==="number"||r.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1;let d=(...v)=>v.length?(o===1?n.unshift(...v):v.forEach(j=>j(p)),void 0):p;C.push({scope:t,host:d}),c=t(e||void 0);let m=h(c,f.F);if(c.nodeName==="#comment")break;let l=M.mark({type:"component",name:t.name,host:m?"this":"parentElement"});c.prepend(l),m&&(p=l);break}case t==="#text":c=R.call(this,f.D.createTextNode(""),e);break;case(t==="<>"||!t):c=R.call(this,f.D.createDocumentFragment(),e);break;case!!T:c=R.call(this,f.D.createElementNS(T,t),e);break;case!c:c=R.call(this,f.D.createElement(t),e)}return et(c),p||(p=c),n.forEach(d=>d(p)),o&&C.pop(),o=2,c}M.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=f.D.createComment(``);return e&&(r.end=f.D.createComment("")),r};function vt(t){let e=this;return function(...r){T=t;let o=M.call(e,...r);return T=void 0,o}}var P=new WeakMap,{setDeleteAttr:tt}=f;function R(t,...e){if(!e.length)return t;P.set(t,nt(t,this));for(let[n,r]of Object.entries(g({},...e)))H.call(this,t,n,r);return P.delete(t),t}function H(t,e,n){let{setRemoveAttr:r,s:o}=nt(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(a,d)=>H.call(c,t,a,d));let[p]=e;if(p==="=")return r(e.slice(1),n);if(p===".")return $(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 tt(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return k(o,e,t,n,$.bind(null,t[e]));case"ariaset":return k(o,e,t,n,(a,d)=>r("aria-"+a,d));case"classList":return rt.call(c,t,n)}return gt(t,e)?tt(t,e,n):r(e,n)}function nt(t,e){if(P.has(t))return P.get(t);let r=(h(t,f.S)?Q:K).bind(null,t,"Attribute"),o=N(e);return{setRemoveAttr:r,s:o}}function rt(t,e){let n=N(this);return k(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function gt(t,e){if(!(e in t))return!1;let n=ot(t,e);return!x(n.set)}function ot(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||ot(t,e)}function k(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([a,d]){a&&(a=new c(a),a.target=e,d=t.processReactiveAttribute(n,a,d,o),o(a,d))})}function xt(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,p,a){if(a[0]===e)return c.apply(t,a);for(let d of a){let m=(d.slot||"")+n;try{X(d,"remove","slot")}catch{}let l=o[m];if(!l)return;l.name.startsWith(r)||(l.childNodes.forEach(v=>v.remove()),l.name=r+m),l.append(d)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}function Et(t,e,n={}){let r=t.host||t;C.push({scope:r,host:(...p)=>p.length?p.forEach(a=>a(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[A];o||ct(r);let c=e.call(r,n);return o||r.dispatchEvent(new Event(E)),t.nodeType===11&&typeof t.mode=="string"&&r.addEventListener(w,y.observe(t),{once:!0}),C.pop(),t.append(c)}function ct(t){return z(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(E))}),z(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(w)))}),z(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(G,{detail:[o,c]})),e.apply(n,r)}),t.prototype[A]=!0,t}function z(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}var st="__dde_memo_of",q=[];function W(t,e){if(!q.length)return e(t);let n=typeof t=="object"?JSON.stringify(t):t,[{cache:r,after:o}]=q;return o(n,B(r,n)?r[n]:e(t))}W.isScope=function(t){return!!t[st]};W.scope=function(e,{signal:n,onlyLast:r}={}){let o=L();function c(...p){if(n&&n.aborted)return e.apply(this,p);let a=r?o:L();q.unshift({cache:o,after(m,l){return a[m]=l}});let d=e.apply(this,p);return q.shift(),o=a,d}return c[st]=e,c.clear=()=>o=L(),n&&n.addEventListener("abort",c.clear),c};return dt(_t);})(); +var DDE=(()=>{var F=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var ut=Object.getOwnPropertyNames;var ft=Object.prototype.hasOwnProperty;var at=(t,e)=>{for(var n in e)F(t,n,{get:e[n],enumerable:!0})},pt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ut(e))!ft.call(t,o)&&o!==n&&F(t,o,{get:()=>e[o],enumerable:!(r=it(e,o))||r.enumerable});return t};var dt=t=>pt(F({},"__esModule",{value:!0}),t);var _t={};at(_t,{assign:()=>R,assignAttribute:()=>H,chainableAppend:()=>et,classListDeclarative:()=>rt,createElement:()=>M,createElementNS:()=>vt,customElementRender:()=>Et,customElementWithDDE:()=>ct,dispatchEvent:()=>mt,el:()=>M,elNS:()=>vt,lifecyclesToEvents:()=>ct,memo:()=>W,on:()=>S,queue:()=>bt,registerReactivity:()=>V,scope:()=>C,simulateSlots:()=>xt});var B=(...t)=>Object.prototype.hasOwnProperty.call(...t);function x(t){return typeof t>"u"}function h(t,e){return t instanceof e}function Z(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function L(t=null,e={}){return Object.create(t,e)}function g(...t){return Object.assign(...t)}function I(t,e){if(!t||!h(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var f={setDeleteAttr:lt,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 lt(t,e,n){if(Reflect.set(t,e,n),!!x(n)){if(Reflect.deleteProperty(t,e),h(t,f.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var A="__dde_lifecyclesToEvents",E="dde:connected",w="dde:disconnected",G="dde:attributeChanged";var y=f.M?ht():new Proxy({},{get(){return()=>{}}});function ht(){let t=new Map,e=!1,n=s=>function(u){for(let i of u)if(i.type==="childList"){if(l(i.addedNodes,!0)){s();continue}v(i.removedNodes,!0)&&s()}},r=new f.M(n(a));return{observe(s){let u=new f.M(n(()=>{}));return u.observe(s,{childList:!0,subtree:!0}),()=>u.disconnect()},onConnected(s,u){p();let i=c(s);i.connected.has(u)||(i.connected.add(u),i.length_c+=1)},offConnected(s,u){if(!t.has(s))return;let i=t.get(s);i.connected.has(u)&&(i.connected.delete(u),i.length_c-=1,o(s,i))},onDisconnected(s,u){p();let i=c(s);i.disconnected.has(u)||(i.disconnected.add(u),i.length_d+=1)},offDisconnected(s,u){if(!t.has(s))return;let i=t.get(s);i.disconnected.delete(u),i.length_d-=1,o(s,i)}};function o(s,u){u.length_c||u.length_d||(t.delete(s),a())}function c(s){if(t.has(s))return t.get(s);let u={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(s,u),u}function p(){e||(e=!0,r.observe(f.D.body,{childList:!0,subtree:!0}))}function a(){!e||t.size||(e=!1,r.disconnect())}function d(){return new Promise(function(s){(requestIdleCallback||requestAnimationFrame)(s)})}async function m(s){t.size>30&&await d();let u=[];if(!h(s,f.N))return u;for(let i of t.keys())i===s||!h(i,f.N)||s.contains(i)&&u.push(i);return u}function l(s,u){let i=!1;for(let b of s){if(u&&m(b).then(l),!t.has(b))continue;let D=t.get(b);D.length_c&&(b.dispatchEvent(new Event(E)),D.connected=new WeakSet,D.length_c=0,D.length_d||t.delete(b),i=!0)}return i}function v(s,u){let i=!1;for(let b of s)u&&m(b).then(v),!(!t.has(b)||!t.get(b).length_d)&&((globalThis.queueMicrotask||setTimeout)(j(b)),i=!0);return i}function j(s){return()=>{s.isConnected||(s.dispatchEvent(new Event(w)),t.delete(s))}}}function mt(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 p=c.length?new CustomEvent(t,g({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(p)}}function S(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}S.defer=t=>setTimeout.bind(null,t,0);var J=t=>g({},typeof t=="object"?t:null,{once:!0});S.connected=function(t,e){return e=J(e),function(r){return r.addEventListener(E,t,e),r[A]?r:r.isConnected?(r.dispatchEvent(new Event(E)),r):(I(e.signal,()=>y.offConnected(r,t))&&y.onConnected(r,t),r)}};S.disconnected=function(t,e){return e=J(e),function(r){return r.addEventListener(w,t,e),r[A]||I(e.signal,()=>y.offDisconnected(r,t))&&y.onDisconnected(r,t),r}};var _=[{get scope(){return f.D.body},host:t=>t?t(f.D.body):f.D.body,prevent:!0}],U=new WeakMap,C={get current(){return _[_.length-1]},get host(){return this.current.host},get signal(){let{host:t}=this;if(U.has(t))return U.get(t);let e=new AbortController;return U.set(t,e),t(S.disconnected(()=>e.abort())),e.signal},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[..._]},push(t={}){return _.push(g({},this.current,{prevent:!1},t))},pushRoot(){return _.push(_[0])},pop(){if(_.length!==1)return _.pop()}};var O={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function V(t,e=!0){return e?g(O,t):(Object.setPrototypeOf(t,O),t)}function N(t){return Z(t,O)&&t!==O?t:O}function K(t,e,n,r){return t[(x(r)?"remove":"set")+e](n,r)}function Q(t,e,n,r,o=null){return t[(x(r)?"remove":"set")+e+"NS"](o,n,r)}function $(t,e,n){if(Reflect.set(t,e,n),!!x(n))return Reflect.deleteProperty(t,e)}function X(t,e,n,r){return h(t,f.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function bt(t){return f.q(t)}function Y(...t){return this.appendOriginal(...t),this}function et(t){return t.append===Y||(t.appendOriginal=t.append,t.append=Y),t}var T;function M(t,e,...n){let r=N(this),o=0,c,p,a=typeof e;switch((a==="string"||a==="number"||r.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1;let d=(...v)=>v.length?(o===1?n.unshift(...v):v.forEach(j=>j(p)),void 0):p;C.push({scope:t,host:d}),c=t(e||void 0);let m=h(c,f.F);if(c.nodeName==="#comment")break;let l=M.mark({type:"component",name:t.name,host:m?"this":"parentElement"});c.prepend(l),m&&(p=l);break}case t==="#text":c=R.call(this,f.D.createTextNode(""),e);break;case(t==="<>"||!t):c=R.call(this,f.D.createDocumentFragment(),e);break;case!!T:c=R.call(this,f.D.createElementNS(T,t),e);break;case!c:c=R.call(this,f.D.createElement(t),e)}return et(c),p||(p=c),n.forEach(d=>d(p)),o&&C.pop(),o=2,c}M.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=f.D.createComment(``);return e&&(r.end=f.D.createComment("")),r};function vt(t){let e=this;return function(...r){T=t;let o=M.call(e,...r);return T=void 0,o}}var P=new WeakMap,{setDeleteAttr:tt}=f;function R(t,...e){if(!e.length)return t;P.set(t,nt(t,this));for(let[n,r]of Object.entries(g({},...e)))H.call(this,t,n,r);return P.delete(t),t}function H(t,e,n){let{setRemoveAttr:r,s:o}=nt(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(a,d)=>H.call(c,t,a,d));let[p]=e;if(p==="=")return r(e.slice(1),n);if(p===".")return $(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 tt(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return k(o,e,t,n,$.bind(null,t[e]));case"ariaset":return k(o,e,t,n,(a,d)=>r("aria-"+a,d));case"classList":return rt.call(c,t,n)}return gt(t,e)?tt(t,e,n):r(e,n)}function nt(t,e){if(P.has(t))return P.get(t);let r=(h(t,f.S)?Q:K).bind(null,t,"Attribute"),o=N(e);return{setRemoveAttr:r,s:o}}function rt(t,e){let n=N(this);return k(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function gt(t,e){if(!(e in t))return!1;let n=ot(t,e);return!x(n.set)}function ot(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||ot(t,e)}function k(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([a,d]){a&&(a=new c(a),a.target=e,d=t.processReactiveAttribute(n,a,d,o),o(a,d))})}function xt(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,p,a){if(a[0]===e)return c.apply(t,a);for(let d of a){let m=(d.slot||"")+n;try{X(d,"remove","slot")}catch{}let l=o[m];if(!l)return;l.name.startsWith(r)||(l.childNodes.forEach(v=>v.remove()),l.name=r+m),l.append(d)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}function Et(t,e,n={}){let r=t.host||t;C.push({scope:r,host:(...p)=>p.length?p.forEach(a=>a(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[A];o||ct(r);let c=e.call(r,n);return o||r.dispatchEvent(new Event(E)),t.nodeType===11&&typeof t.mode=="string"&&r.addEventListener(w,y.observe(t),{once:!0}),C.pop(),t.append(c)}function ct(t){return z(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(E))}),z(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(w)))}),z(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(G,{detail:[o,c]})),e.apply(n,r)}),t.prototype[A]=!0,t}function z(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}var st="__dde_memo",q=[];function W(t,e){if(!q.length)return e(t);let n=typeof t=="object"?JSON.stringify(t):t,[{cache:r,after:o}]=q;return o(n,B(r,n)?r[n]:e(t))}W.isScope=function(t){return t[st]};W.scope=function(e,{signal:n,onlyLast:r}={}){let o=L();function c(...p){if(n&&n.aborted)return e.apply(this,p);let a=r?o:L();q.unshift({cache:o,after(m,l){return a[m]=l}});let d=e.apply(this,p);return q.shift(),o=a,d}return c[st]=!0,c.clear=()=>o=L(),n&&n.addEventListener("abort",c.clear),c};return dt(_t);})(); diff --git a/src/memo.js b/src/memo.js index ca4dbaf..4a2507c 100644 --- a/src/memo.js +++ b/src/memo.js @@ -1,5 +1,5 @@ import { hasOwn, oCreate } from "./helpers.js"; -const memoMark= "__dde_memo_of"; +const memoMark= "__dde_memo"; const memo_scope= []; /** * ```js @@ -20,7 +20,7 @@ export function memo(key, generator){ const [ { cache, after } ]= memo_scope; return after(k, hasOwn(cache, k) ? cache[k] : generator(key)); } -memo.isScope= function(obj){ return Boolean(obj[memoMark]); }; +memo.isScope= function(obj){ return obj[memoMark]; }; /** * @param {Function} fun * @param {Object} [options={}] @@ -43,7 +43,7 @@ memo.scope= function memoScopeCreate(fun, { signal, onlyLast }= {}){ cache= cache_local; return out; } - memoScope[memoMark]= fun; + memoScope[memoMark]= true; memoScope.clear= ()=> cache= oCreate(); if(signal) signal.addEventListener("abort", memoScope.clear); return memoScope; diff --git a/src/signals-lib/signals-lib.js b/src/signals-lib/signals-lib.js index b05e783..f02b949 100644 --- a/src/signals-lib/signals-lib.js +++ b/src/signals-lib/signals-lib.js @@ -169,11 +169,11 @@ import { memo } from "../memo.js"; * Creates a reactive DOM element that re-renders when signal changes * * @param {Object} s - Signal object to watch - * @param {Function} map - Function mapping signal value to DOM elements + * @param {Function} mapScoped - Function mapping signal value to DOM elements * @returns {DocumentFragment} Fragment containing reactive elements */ signal.el= function(s, map){ - map= memo.isScope(map) ? map : memo.scope(map, { onlyLast: true }); + const mapScoped= memo.isScope(map) ? map : memo.scope(map, { onlyLast: true }); const { current }= scope, { scope: sc }= current; const mark_start= el.mark({ type: "reactive", component: sc && sc.name || "" }, true); const mark_end= mark_start.end; @@ -183,7 +183,7 @@ signal.el= function(s, map){ if(!mark_start.parentNode || !mark_end.parentNode) // === `isConnected` or wasn’t yet rendered return removeSignalListener(s, reRenderReactiveElement); scope.push(current); - let els= map(v); + let els= mapScoped(v); scope.pop(); if(!Array.isArray(els)) els= [ els ]; @@ -202,7 +202,7 @@ signal.el= function(s, map){ reRenderReactiveElement(s.get()); current.host(on.disconnected(()=> /*! Clears cached elements for reactive element `S.el` */ - map.clear() + mapScoped.clear() )); return out; }; @@ -314,9 +314,8 @@ export const signals_config= { function removeSignalsFromElements(s, listener, ...notes){ const { current }= scope; current.host(function(element){ - if(element[key_reactive]) - return element[key_reactive].push([ [ s, listener ], ...notes ]); - element[key_reactive]= []; + if(!element[key_reactive]) element[key_reactive]= []; + element[key_reactive].push([ [ s, listener ], ...notes ]); if(current.prevent) return; // typically document.body, doenst need auto-remove as it should happen on page leave on.disconnected(()=> /*! Clears all Signals listeners added in the current scope/host (`S.el`, `assign`, …?).