@estjs/template 0.0.16-beta.4 → 0.0.16-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-IA4OZ7NW.esm.js +1 -0
- package/dist/{chunk-JT6RSDKI.dev.esm.js → chunk-OEKE4VTS.dev.esm.js} +8 -4
- package/dist/chunk-OEKE4VTS.dev.esm.js.map +1 -0
- package/dist/{internal-DSKAj-zW.d.cts → internal-DR5pJGCO.d.cts} +8 -1
- package/dist/{internal-DSKAj-zW.d.ts → internal-DR5pJGCO.d.ts} +8 -1
- package/dist/internal.cjs.js +1 -2
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.dev.cjs.js +5 -0
- package/dist/internal.dev.cjs.js.map +1 -1
- package/dist/internal.dev.esm.js +1 -1
- package/dist/internal.esm.js +1 -2
- package/dist/template.cjs.js +2 -3
- package/dist/template.d.cts +3 -3
- package/dist/template.d.ts +3 -3
- package/dist/template.dev.cjs.js +15 -3
- package/dist/template.dev.cjs.js.map +1 -1
- package/dist/template.dev.esm.js +17 -5
- package/dist/template.dev.esm.js.map +1 -1
- package/dist/template.esm.js +2 -3
- package/package.json +6 -6
- package/dist/chunk-JT6RSDKI.dev.esm.js.map +0 -1
- package/dist/chunk-WWGSC3TY.esm.js +0 -2
- package/dist/chunk-WWGSC3TY.esm.js.map +0 -1
- package/dist/internal.cjs.js.map +0 -1
- package/dist/internal.esm.js.map +0 -1
- package/dist/template.cjs.js.map +0 -1
- package/dist/template.esm.js.map +0 -1
package/dist/template.esm.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {c,e,g,a,d,f,b}from'./chunk-WWGSC3TY.esm.js';import {normalizeClassName,isObject,isSpecialBooleanAttr,isBooleanAttr,includeBooleanAttr,isSymbol,isString,isArray,camelCase,capitalize,isBrowser,warn,isPromise,isFunction,isOn,coerceArray}from'@estjs/shared';import {effect,shallowReactive,isSignal,isComputed,signal}from'@estjs/signals';var ue="_$spread$";var We="http://www.w3.org/2000/svg",_e="http://www.w3.org/2000/xlink",xe="http://www.w3.org/2000/xmlns/";var Ae=Symbol(""),ie=Symbol(""),Pe=Symbol(""),Xe=Symbol("");function G(t,e,n,o){if(e==="key"){o==null?t.removeAttribute(e):t.setAttribute(e,String(o));return}if(e===ue){let d=isObject(n)?n:null,p=isObject(o)?o:null;if(d)for(let h in d)h!==ue&&(!p||!(h in p))&&G(t,h,d[h],null);if(p)for(let h in p)h!==ue&&G(t,h,d==null?void 0:d[h],p[h]);return}let r=(t==null?void 0:t.namespaceURI)===We,s=r&&e.startsWith("xlink:"),i=r&&e.startsWith("xmlns:"),c=isSpecialBooleanAttr(e)||isBooleanAttr(e);if(n===o||e.length>2&&e.charCodeAt(0)===111&&e.charCodeAt(1)===110)return;let l=e.toLowerCase();if(l==="innerhtml"||l==="srcdoc")return;if(o==null){if(s)t.removeAttributeNS(_e,e.slice(6));else if(i){let d=e.slice(6);t.removeAttributeNS(xe,d);}else t.removeAttribute(e);return}if(c){includeBooleanAttr(o)?t.setAttribute(e,""):t.removeAttribute(e);return}let u=isSymbol(o)?String(o):o;if((l==="href"||l==="src"||l==="xlink:href"||l==="action"||l==="formaction"||l==="poster")&&isString(u)){let d=u.trim().toLowerCase();if(d.startsWith("javascript:")||d.startsWith("data:"))return}if(s){t.setAttributeNS(_e,e,String(u));return}if(i){t.setAttributeNS(xe,e,String(u));return}if(r)t.setAttribute(e,String(u));else if(e in t)try{t[e]=u;}catch(d){t.setAttribute(e,String(u));}else t.setAttribute(e,String(u));}function de(t,e,n,o=false){if(e===n)return;let r=fe(n);if(!r){t.removeAttribute("class");return}(isString(e)?e:fe(e))!==r&&(o?t.setAttribute("class",r):t.className=r);}var fe=normalizeClassName;var Ge=/\s*!important$/,Pt=["Webkit","Moz","ms"],ke={};function me(t,e,n){let o=t.style;if(n&&isString(n)){e!==n&&(o.cssText=n);return}if(!n){e&&t.removeAttribute("style");return}if(e&&!isString(e)){let r=e;for(let s in r)(!n||n[s]==null)&&J(o,s,"");}else if(e&&isString(e)){let r=/(?:^|;)\s*([a-z][a-z\d-]*)\s*:/gi,s;for(;(s=r.exec(e))!==null;){let i=s[1].trim();i&&n&&isObject(n)&&n[i]==null&&J(o,i,"");}}if(n&&!isString(n)){let r=n;for(let s in r){let i=r[s];(!e||isString(e)||e[s]!==i)&&i!=null&&J(o,s,i);}}}function J(t,e,n){if(isArray(n)){for(let r of n)J(t,e,r);return}if((n==null||n==="")&&(n=""),e.startsWith("--")){t.setProperty(e,n);return}let o=kt(t,e);isString(n)&&Ge.test(n)?t.setProperty(camelCase(o),n.replace(Ge,""),"important"):t[o]=n;}function kt(t,e){let n=ke[e];if(n)return n;let o=camelCase(e);if(o!=="filter"&&o in t)return ke[e]=o;o=capitalize(o);for(let r of Pt){let s=r+o;if(s in t)return ke[e]=s}return e}var Te=0;function Je(){return String(Te++)}function Lt(){Te=0;}var z=false;function le(){return z}var Q=new Map;function Dt(t){let e=t.querySelectorAll("[data-hk]");for(let n of e){let o=n.dataset.hk;o!=null&&!Q.has(o)&&Q.set(o,n);}}var ye=[],se=new Map;function Ft(){if(typeof document=="undefined")return;let t=document.createNodeIterator(document.body,NodeFilter.SHOW_COMMENT),e;for(;e=t.nextNode();){let n=e.data;if(n==="teleport-anchor")ye.push(e);else if(n==="teleport-start"){let o=e.parentElement;if(!o)continue;let r=se.get(o);r||(r=[],se.set(o,r)),r.push(e);}}}function Re(){var t;return (t=ye.shift())!=null?t:null}function Le(t){let e=se.get(t),n=e==null?void 0:e.shift();if(!n)return null;let o=[],r=n.nextSibling;for(;r;){if(r.nodeType===Node.COMMENT_NODE&&r.data==="teleport-end")return {start:n,end:r,nodes:o};o.push(r),r=r.nextSibling;}return null}function De(t){z=true,Te=0,Q.clear(),ye.length=0,se.clear(),Dt(t),Ft();}function Fe(){z=false,Q.clear(),ye.length=0,se.clear();}function Mt(t){if(!isBrowser())return ()=>{throw new Error("[essor] getRenderedElement called in non-browser environment")};let e=null;return ()=>{if(!z)return e||(e=pe(t)),e();let n=Je(),o=Q.get(n);return o?(Q.delete(n),o):(warn(`[essor] hydration mismatch: no SSR element for key "${n}"`),e||(e=pe(t)),e())}}function It(t,e,n,o){z||de(t,e,n,o);}function Ht(t,e,n,o){z||G(t,e,n,o);}function Ot(t,e,n){z||me(t,e,n);}function Me(t,e){return e&&e.parentNode===t?e:null}function Qe(t,e,n,o){let r=Me(t,o),s=e.length,i=n.length;if(s===0&&i===0)return n;if(s===0){for(let f=0;f<i;f++)F(t,n[f],r);return n}if(i===0){for(let f=0;f<s;f++)K(e[f]);return []}let c=0,l=s-1,u=i-1;for(;c<=l&&c<=u&&e[c]===n[c];)c++;for(;l>=c&&u>=c&&e[l]===n[u];)l--,u--;if(c>l){if(c<=u){let f=u+1,d=Me(t,f<i?n[f]:r);for(let p=c;p<=u;p++)F(t,n[p],d);}}else if(c>u)for(let f=c;f<=l;f++)K(e[f]);else Vt(t,e,n,c,l,u,r);return n}function Vt(t,e,n,o,r,s,i){let c=s-o+1,l=new Map;for(let m=o;m<=s;m++)l.set(n[m],m);let u=new Int32Array(c);u.fill(0);let f=0,d=false,p=0;for(let m=o;m<=r;m++){let g=e[m];if(f>=c){K(g);continue}let a=l.get(g);a===void 0?K(g):(u[a-o]=m+1,a>=p?p=a:d=true,f++);}let h=d?Ie(u):[],v=h.length-1;for(let m=c-1;m>=0;m--){let g=o+m,a=n[g],y=Me(t,g+1<n.length?n[g+1]:i);u[m]===0?F(t,a,y):d&&(v<0||m!==h[v]?F(t,a,y):v--);}}function Ie(t){let e=new Int32Array(t.length),n=[0],o=t.length,r,s,i,c,l;for(r=0;r<o;r++){let u=t[r];if(u!==0){if(s=n[n.length-1],t[s]<u){e[r]=s,n.push(r);continue}for(i=0,c=n.length-1;i<c;)l=i+c>>1,t[n[l]]<u?i=l+1:c=l;u<t[n[i]]&&(i>0&&(e[r]=n[i-1]),n[i]=r);}}for(i=n.length,c=n[i-1];i-- >0;)n[i]=c,c=e[c];return n}function K(t){if(t)if(M(t))t.destroy();else {let e=t;e.parentNode&&e.remove();}}function F(t,e,n){if(!t||!e)return;let o=M(n)?n.firstChild:n;if(M(e)){e.mount(t,o);return}o?t.insertBefore(e,o):t.appendChild(e);}function Z(t){if(t instanceof Node||M(t))return t;let e=typeof t;return t==null||e==="string"||e==="number"||e==="boolean"||e==="symbol"?document.createTextNode(t===false||t==null?"":String(t)):document.createTextNode(String(t))}function B(t,e$1,n){if(!t)return;let o=c(),r=[],s=true,i=l=>{if(l instanceof Node)return [l];if(M(l))return [l];let u=typeof l;return l==null||u==="string"||u==="number"||u==="boolean"?[Z(l)]:coerceArray(l).map(f=>isFunction(f)?f():f).flatMap(f=>f).map(Z)},c$1=effect(()=>{let l=()=>{let u=isFunction(e$1)?e$1():e$1,f=i(u);if(s&&le()&&f.every(d=>d instanceof Node&&d.parentNode===t)){r=f,s=false;return}r=Qe(t,r,f,n),s=false;};o&&!o.isDestroyed?e(o,l):l();});return g(()=>{c$1.stop();for(let l of r)K(l);r=[];}),r}function $t(t){return (t==null?void 0:t.firstChild)||null}function Ut(t,e=1){for(;t&&e>0;)t=t.nextSibling,e--;return t||null}function zt(t,e){if(!t||e<0)return null;let n=t.firstChild;for(;n&&e>0;)n=n.nextSibling,e--;return n||null}function ee(t,e,n,o){if(!(o!=null&&o.delegate))return t.addEventListener(e,n,o),()=>t.removeEventListener(e,n,o);let r=o.delegate,s=u=>{let f=u.target;(f.matches(r)||f.closest(r))&&n.call(t,u);},l=o,{delegate:i}=l,c=a(l,["delegate"]);return t.addEventListener(e,s,c),()=>{t.removeEventListener(e,s,c);}}function He(t,e,n){let o=t[e];o||(o=[],t[e]=o),o.push(n);}function tt(t,e,n){let o=t.length;if(o===0)return;let r;for(let s=0;s<o;s++)try{let i=t[s]();if(isPromise(i)){let c=i.catch(l=>{});(r||(r=[])).push(c);}}catch(i){}if(r)return Promise.all(r).then(()=>{})}function Oe(t){let e=c();if(e){if(e.isMounted){try{let n=t();isPromise(n)&&n.catch(o=>{});}catch(n){}return}He(e,"onMount",t);}}function Bt(t){let e=c();e&&He(e,"onUpdate",t);}function te(t){let e=c();e&&He(e,"onDestroy",t);}function nt(t){if(t.isDestroyed)return;if(!t.onMount||t.onMount.length===0){t.isMounted=true;return}let e$1=t.onMount,n=e(t,()=>tt(e$1,t.id));return e$1.length=0,t.isMounted=true,n}function ot(t){if(!(t.isDestroyed||!t.onUpdate||t.onUpdate.length===0))return e(t,()=>tt(t.onUpdate,t.id))}function it(t,e,n=false){let o=n?new Set:null;for(let r of Object.getOwnPropertyNames(e))o==null||o.add(r),Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r));if(o)for(let r of Object.getOwnPropertyNames(t))o.has(r)||delete t[r];}function Gt(t,e){let n=Object.getOwnPropertyDescriptor(t,e);return n.get?n.get.call(t):n.value}var st;st="normal";var ne=class{constructor(e,n={}){this.component=e;this.props=n;this[st]=true;this.scope=null;this.state=0;this.beforeNode=void 0;this.renderedNodes=[];this.firstChild=void 0;this.parentNode=void 0;this.rootEventCleanups=[];this.parentScope=c();let o={};it(o,n),this.reactiveProps=shallowReactive(o);}mount(e$1,n){var s;if(this.parentNode=e$1,this.beforeNode=n,this.state=1,this.renderedNodes.length>0){for(let i of this.renderedNodes)F(e$1,i,n);return this.state=2,this.renderedNodes}let o=d((s=this.parentScope)!=null?s:c());this.scope=o;let r=e(o,()=>{var c;let i=this.component(this.reactiveProps);return isFunction(i)&&(i=i(this.reactiveProps)),(isSignal(i)||isComputed(i))&&(i=i.value),(c=B(e$1,i,n))!=null?c:[]});return this.renderedNodes=r,this.firstChild=r[0],this.syncSpecialProps(this.props),this.state=2,nt(o),this.renderedNodes}update(e){this.props=e;let n=this.scope;!n||n.isDestroyed||(it(this.reactiveProps,e!=null?e:{},true),this.syncSpecialProps(e),ot(n));}forceUpdate(){if(!this.parentNode)return;let e=this.parentNode,n=this.beforeNode;this.destroy(),this.mount(e,n);}destroy(){let e=this.scope;if(!(!e||e.isDestroyed)){this.scope=null,this.releaseSpecialProps(),f(e);for(let n of this.renderedNodes)K(n);this.renderedNodes=[],this.firstChild=void 0,this.parentNode=void 0;}}syncSpecialProps(e){if(!e)return;let n=this.firstChild;if(n){this.releaseSpecialProps();for(let o of Object.getOwnPropertyNames(e)){let r=Gt(e,o);if(o==="ref"){this.rootRefCleanup=this.bindRootRef(r,n);continue}if(isOn(o)&&isFunction(r)){let s=o.slice(2).toLowerCase();this.rootEventCleanups.push(ee(n,s,r));}}}}releaseSpecialProps(){for(let e of this.rootEventCleanups)e();this.rootEventCleanups.length=0,this.rootRefCleanup&&(this.rootRefCleanup(),this.rootRefCleanup=void 0);}bindRootRef(e,n){if(isFunction(e))return e(n),()=>e(null);if(isSignal(e)){let o=e,r=o.value;return o.value=n,()=>{o.value===n&&(o.value=r);}}}};function M(t){return !!t&&!!t.normal}function he(t,e){return M(t)?t:new ne(t,e)}function pe(t){let e,n=()=>{let o=document.createElement("template");o.innerHTML=t;let r=o.content.firstChild;if(!r)throw new Error("Invalid template: empty content");return r};return ()=>(e||(e=n())).cloneNode(true)}function Yt(t,e$1){let n=isString(e$1)?document.querySelector(e$1):e$1;if(!n)return;n.innerHTML&&(n.innerHTML="");let r=d(),s;try{e(r,()=>{let i=he(t);M(i)&&(s=i,F(n,i));});}catch(i){throw f(r),i}return {root:s,unmount:()=>{f(r),s==null||s.destroy();}}}function Jt(t,e$1){let n=isString(e$1)?document.querySelector(e$1):e$1;if(!n)return;De(n);let o=d(),r;try{e(o,()=>{let s=he(t);M(s)&&(r=s,B(n,s));});}catch(s){throw f(o),s}finally{Fe();}return {root:r,unmount:()=>{f(o),r==null||r.destroy();}}}function je(t,e){let n=c();n&&(n.provides||(n.provides=new Map),n.provides.set(t,e));}function ce(t,e){let n=c();if(!n)return e;let o=n;for(;o;){if(o.provides&&o.provides.has(t))return o.provides.get(t);o=o.parent;}return e}function Ke(t,e){Object.defineProperty(t,"target",{configurable:true,value:e});}function at(t){let e=t.target,n=t.type,o=t.target,r=t.currentTarget,s=()=>{let c=e[`_$${n}`];if(c&&isFunction(c)&&!e.disabled){let l=e[`${n}Data`];if(l?c.call(e,l,t):c.call(e,t),t.cancelBubble)return false}return e.host&&!isString(e.host)&&!e.host._$host&&isFunction(e.contains)&&e.contains(t.target)&&Ke(t,e.host),true},i=()=>{for(;s()&&(e=e._$host||e.parentNode||e.host););};if(Object.defineProperty(t,"currentTarget",{configurable:true,get(){return e||document}}),t.composedPath){let c=t.composedPath();Ke(t,c[0]);for(let l=0;l<c.length-2&&(e=c[l],!!s());l++){if(e._$host){e=e._$host,i();break}if(e.parentNode===r)break}}else i();Ke(t,o);}var ge=Symbol("_$EVENTS");function Zt(t,e=window.document){let n=e,o=n[ge]||(n[ge]=new Set);for(let r of t)o.has(r)||(o.add(r),e.addEventListener(r,at));}function en(t=window.document){let e=t,n=e[ge];if(n){for(let o of n.keys())t.removeEventListener(o,at);delete e[ge];}}function oe(t,e,n,o){let r=ee(t,e,n,o);c()&&g(r);}function $e(t,e){let n=t,o=e==null?"":String(e);n.value!==o&&(n.value=o);}var rn={event:"change",forceChange:true,read:t=>t.checked,write(t,e){let n=t,o=!!e;n.checked!==o&&(n.checked=o);}},sn={event:"change",forceChange:true,read(t){let e=t;return e.checked?e.value:""},write(t,e){let n=t,o=String(e)===n.value;n.checked!==o&&(n.checked=o);}},ln={event:"change",forceChange:true,read:t=>t.files,write(){}},cn={event:"input",ime:true,read:t=>t.value,write:$e},an={event:"input",ime:true,read:t=>t.value,write:$e},un={event:"change",forceChange:true,read(t){let e=t;return e.multiple?Array.from(e.selectedOptions,n=>n.value):e.value},write(t,e){let n=t;if(n.multiple){let o=new Set((Array.isArray(e)?e:[]).map(String));for(let r of Array.from(n.options))r.selected=o.has(r.value);}else $e(t,e);}};function fn(t,e){switch(t.nodeName){case "INPUT":return e==="checked"?t.type==="radio"?sn:rn:e==="files"?ln:cn;case "SELECT":return un;case "TEXTAREA":return an;default:return {event:"input",read:n=>n[e],write(n,o){n[e]=o;}}}}function dn(t,e,n){if(!isString(t))return t;let o=t;if(e&&(o=o.trim()),n&&o!==""){let r=Number(o);if(!Number.isNaN(r))return r}return o}function mn(t){let e=t.getRootNode();return (e instanceof Document||e instanceof ShadowRoot)&&e.activeElement===t}function pn(t,e,n,o,r={}){if(!t)return;let{event:s,read:i,write:c$1,forceChange:l,ime:u}=fn(t,e),f=r.trim===true,d=r.number===true,p=r.lazy===true,h=(f||d)&&e!=="files",v=isFunction(n)?n:()=>n,m=h?S=>dn(S,f,d):S=>S,g$1=false,a=p||l?"change":s,y=()=>{if(g$1)return;let S=i(t);if(S===void 0)return;let A=m(S);Object.is(v(),A)||o(A);};oe(t,a,y),!p&&h&&a!=="change"&&oe(t,"change",()=>c$1(t,m(i(t)))),u&&!p&&(oe(t,"compositionstart",()=>{g$1=true;}),oe(t,"compositionend",()=>{g$1&&(g$1=false,y());}));let N=effect(()=>{let S=v();u&&!p&&mn(t)&&(g$1||Object.is(m(i(t)),S))||c$1(t,S);});c()&&g(()=>N.stop());}function yn(t,e){let n=new Set(e);return new Proxy(t,{get(o,r){if(!n.has(r))return Reflect.get(o,r)},ownKeys(o){return Reflect.ownKeys(o).filter(r=>!n.has(r))},getOwnPropertyDescriptor(o,r){if(!n.has(r))return Reflect.getOwnPropertyDescriptor(o,r)},has(o,r){return n.has(r)?false:Reflect.has(o,r)}})}function ut(t){return !t||t.children==null?null:t.children}ut[Ae]=true;function hn(t){return !!t&&!!t[Ae]}function Ee(t){let e=isFunction(t.target)?t.target():t.target;return e==null?null:isString(e)?document.querySelector(e):e}function ve(t){return isFunction(t.disabled)?!!t.disabled():!!t.disabled}function dt(t){if(le()){let f=vn(t);if(f)return f}let e$1=document.createComment("portal");e$1[ie]=true;let{children:n}=t;if(n==null)return e$1;let o=c(),r=null,s=(f,d$1)=>{r=d(o),e(r,()=>{B(f,()=>n,d$1);});},i=()=>{r&&(f(r),r=null);},c$1=(f,d)=>{if(i(),f){let p=e$1.parentNode;if(!p)return;s(p,e$1);return}d&&s(d);},l=false,u=effect(()=>{let f=ve(t),d=f?null:Ee(t);l&&c$1(f,d);});return Oe(()=>{l=!0;let f=ve(t),d=f?null:Ee(t);if(f||d){c$1(f,d);return}queueMicrotask(()=>{e$1.parentNode&&c$1(ve(t),Ee(t));});}),g(()=>{u.stop(),i();}),e$1}dt[ie]=true;function vn(t){if(ve(t))return null;let e=Re();if(!e)return null;let n=Ee(t);return !n||!Le(n)?null:(e[ie]=true,e)}function Nn(t){return !!t&&!!t[ie]}function Se(t){for(;t.firstChild;)t.removeChild(t.firstChild);}function mt(t){let e=t;for(;isFunction(e);)e=e();return isSignal(e)||isComputed(e)?mt(e.value):e}var ae=Symbol("SuspenseContext");function pt(t){var v;if(!isBrowser())return (v=t.fallback)!=null?v:"";let e=document.createElement("div");e.style.display="contents";let n=true,o=0,r=false,s=null,i=m=>{let g=mt(m);if(isArray(g)){let a=[];for(let y of g){let N=i(y);isArray(N)?a.push(...N):a.push(N);}return a}return Z(g)},c=m=>{let g=i(m),a=isArray(g)?g:[g];for(let y of a)y!=null&&F(e,y);},l=()=>{Se(e),t.fallback!=null&&c(t.fallback);},u=()=>{r||(r=true,l());},f=()=>{!r||!(s||t.children!=null&&!isPromise(t.children))||(r=false,Se(e),s?d(s):t.children!=null&&!isPromise(t.children)&&d(t.children));},d=m=>{if(r||(Se(e),m==null))return;let g=isArray(m)?m:[m];for(let a of g)a!=null&&c(a);r&&l();},p={register:m=>{o++,u(),m.then(()=>{n&&(o--,o===0&&f());}).catch(g=>{n&&(o--,o===0&&f());});},increment:()=>{o++,u();},decrement:()=>{o=Math.max(0,o-1),o===0&&f();}};je(ae,p);let h=t.children;return isPromise(h)?(h.then(m=>{s=m;}).catch(()=>{}),p.register(h)):h!=null?d(h):u(),te(()=>{n=false,o=0,s=null,Se(e),e.remove();}),e}pt[Pe]=true;function _n(t){return !!t&&!!t[Pe]}function xn(t,e){let n=signal(e==null?void 0:e.initialValue),o=signal(true),r=signal(null),s=signal("pending"),i=0,c=null,l=false,u=ce(ae,null),f=()=>b(null,null,function*(){let h=++i;o.value=true,s.value="pending",r.value=null,l=false,u&&u.increment();try{let v=t();c=v,v.catch(()=>{});let m=yield v;h===i&&(n.value=m,s.value="ready",o.value=!1);}catch(v){h===i&&(r.value=v instanceof Error?v:new Error(String(v)),s.value="errored",o.value=false);}finally{u&&u.decrement();}});f();let d=(()=>(!l&&o.value&&c&&u&&(l=true,u.register(c)),n.value));return d.loading=o,d.error=r,d.state=s,[d,{mutate:h=>{n.value=h,s.value="ready",o.value=false,r.value=null;},refetch:()=>b(null,null,function*(){yield f();})}]}function yt(t){return isFunction(t)?t:t.default}function ze(t,e,n){let o=new ne(e,n);return o.mount(t),o}function Pn(t,e={}){let{delay:n=200,timeout:o,ssr:r="blocking",onError:s}=e;if(typeof window=="undefined"){if(r==="client-only"){let g=()=>"";return g.__asyncLoader=t,g.__asyncResolved=()=>null,g}let p=null,h=null,v=()=>h||(h=t().then(g=>{p=yt(g);}).catch(()=>{}),h);v();let m=g=>p?p(g):"";return m.__asyncLoader=v,m.__asyncResolved=()=>p,m}let i=null,c=null,l="pending",u=null;function f(){return u||(u=t().then(p=>{i=yt(p),l="resolved";}).catch(p=>{c=p instanceof Error?p:new Error(String(p)),l="errored",u=null;}),u)}f();function d(p){var W;if(l==="resolved"&&i){let C=document.createElement("div");C.style.display="contents";let I=ze(C,i,p);return g(()=>I.destroy()),C}if(l==="errored"&&c){let C=document.createElement("div");if(C.style.display="contents",e.error){let I=true,R=null,$=(q,E)=>{I&&(R==null||R.destroy(),R=ze(C,q,E));},X=()=>{u=null,l="pending",c=null,e.loading&&$(e.loading),f().then(()=>{I&&(l==="resolved"&&i?$(i,p):l==="errored"&&c&&e.error&&$(e.error,{error:c,retry:X}));});};$(e.error,{error:c,retry:X}),te(()=>{I=false,R==null||R.destroy(),R=null;});}return C}let h=document.createElement("div");h.style.display="contents";let v=true,m=null,g$1=null,a=null,y=(C,I)=>{v&&(m==null||m.destroy(),m=ze(h,C,I));},N=C=>()=>{u=null,l="pending",c=null,e.loading&&y(e.loading),f().then(()=>{l==="resolved"&&i?y(i,C):l==="errored"&&c&&e.error&&y(e.error,{error:c,retry:N(C)});});};te(()=>{v=false,m==null||m.destroy(),m=null,g$1!=null&&clearTimeout(g$1),a!=null&&clearTimeout(a);});let S=(W=ce(ae))!=null?W:null,A=C=>y(C,p),T=C=>{e.error&&y(e.error,{error:C,retry:N(p)});},V=()=>{e.loading&&y(e.loading);},j=f().then(()=>{v&&(l==="resolved"&&i?A(i):l==="errored"&&c&&(T(c),s&&s(c,N(p))),g$1!=null&&clearTimeout(g$1),a!=null&&clearTimeout(a));});return S&&S.register(j),n>0?g$1=setTimeout(()=>{v&&l==="pending"&&V();},n):e.loading&&V(),o!=null&&(a=setTimeout(()=>{if(v&&l==="pending"){let C=new Error(`[defineAsyncComponent] Timeout after ${o}ms`);c=C,l="errored",T(C),s&&s(C,N(p));}},o)),h}return d.__asyncLoader=f,d.__asyncResolved=()=>i,d}function ht(t){let e$1=document.createDocumentFragment(),n=document.createComment("");e$1.appendChild(n);let o=[],r=[],s=t.key,i=t.children,c$1=()=>{var y,N;let a=t.each;return isSignal(a)?(y=a.value)!=null?y:[]:isFunction(a)?(N=a())!=null?N:[]:a!=null?a:[]},l=a=>s?s(a):a,u=a=>{if(Array.isArray(a)){let y=[];for(let N of a)y.push(...u(N));return y}return [Z(a)]},f$1=(a,y,N)=>{let S=u(a);for(let A of S)N?y.insertBefore(A,N):y.appendChild(A);return S},d$1=(a,y)=>{if(!t.fallback)return;r=f$1(t.fallback(),a,y);},p=()=>{for(let a of r)a.parentNode&&a.parentNode.removeChild(a);r=[];},h=(a,y,N,S)=>{let A=c(),T=d(A),V=[];return e(T,()=>{V=f$1(i(a,y),N,S);}),{key:l(a),item:a,nodes:V,scope:T}},v=a=>{f(a.scope);for(let y of a.nodes)y.parentNode&&y.parentNode.removeChild(y);},m=effect(()=>{let a=c$1(),y=n.parentNode;if(!y){if(a.length===0)d$1(e$1,n);else {o=new Array(a.length);let N=0;for(let S of a)o[N]=h(S,N,e$1,n),N++;}return}g$1(y,a);});function g$1(a,y){let N=o.length,S=y.length;if(S===0){for(let E=0;E<N;E++)v(o[E]);o=[],t.fallback&&r.length===0&&d$1(a,n);return}if(N===0||r.length>0){r.length>0&&p(),o=new Array(S);let E=document.createDocumentFragment();for(let x=0;x<S;x++)o[x]=h(y[x],x,E,null);a.insertBefore(E,n);return}let A=new Map;for(let E=0;E<N;E++){let x=o[E],H=A.get(x.key),U=[x,E];H?H.push(U):A.set(x.key,[U]);}let T=new Array(S),V=[],j=null,W=new Int32Array(S),C=false,I=0,R=new Array(S);for(let E=0;E<S;E++)R[E]=l(y[E]);for(let E=0;E<S;E++){let x=y[E],H=R[E],U=A.get(H);if(U&&U.length>0){let[re,L]=U.shift();Object.is(re.item,x)?(re.item=x,T[E]=re,W[E]=L+1,L<I?C=true:I=L):(j||(j=document.createDocumentFragment()),v(re),T[E]=h(x,E,j,null));}else j||(j=document.createDocumentFragment()),T[E]=h(x,E,j,null);}for(let E of A.values())for(let[x]of E)V.push(x);for(let E of V)v(E);let $=C?Ie(W):[],X=$.length-1,q=n;for(let E=S-1;E>=0;E--){let H=T[E].nodes;if(!(W[E]===0)&&C&&X>=0&&E===$[X]){X--;for(let L=H.length-1;L>=0;L--)q=H[L];continue}for(let L=H.length-1;L>=0;L--){let be=H[L];be.nextSibling!==q&&a.insertBefore(be,q),q=be;}}o=T;}return g(()=>{m.stop();for(let a of o)v(a);o=[],p(),n.parentNode&&n.parentNode.removeChild(n);}),e$1}ht[Xe]=true;
|
|
2
|
-
export{ne as Component,
|
|
3
|
-
//# sourceMappingURL=template.esm.js.map
|
|
1
|
+
import {c,f,h,a,e,g,b}from'./chunk-IA4OZ7NW.esm.js';import {normalizeClassName,isObject,isSpecialBooleanAttr,isBooleanAttr,includeBooleanAttr,isSymbol,isString,isArray,kebabCase,camelCase,capitalize,isBrowser,warn,isPromise,isFunction,isOn,coerceArray}from'@estjs/shared';import {effect,shallowReactive,isSignal,isComputed,signal}from'@estjs/signals';var ue="_$spread$";var Be="http://www.w3.org/2000/svg",_e="http://www.w3.org/2000/xlink",xe="http://www.w3.org/2000/xmlns/";var Ae=Symbol(""),ie=Symbol(""),Pe=Symbol(""),Xe=Symbol("");function G(t,e,n,o){if(e==="key"){o==null?t.removeAttribute(e):t.setAttribute(e,String(o));return}if(e===ue){let d=isObject(n)?n:null,p=isObject(o)?o:null;if(d)for(let h in d)h!==ue&&(!p||!(h in p))&&G(t,h,d[h],null);if(p)for(let h in p)h!==ue&&G(t,h,d==null?void 0:d[h],p[h]);return}let r=(t==null?void 0:t.namespaceURI)===Be,s=r&&e.startsWith("xlink:"),i=r&&e.startsWith("xmlns:"),c=isSpecialBooleanAttr(e)||isBooleanAttr(e);if(n===o||e.length>2&&e.charCodeAt(0)===111&&e.charCodeAt(1)===110)return;let l=e.toLowerCase();if(l==="innerhtml"||l==="srcdoc")return;if(o==null){if(s)t.removeAttributeNS(_e,e.slice(6));else if(i){let d=e.slice(6);t.removeAttributeNS(xe,d);}else t.removeAttribute(e);return}if(c){includeBooleanAttr(o)?t.setAttribute(e,""):t.removeAttribute(e);return}let u=isSymbol(o)?String(o):o;if((l==="href"||l==="src"||l==="xlink:href"||l==="action"||l==="formaction"||l==="poster")&&isString(u)){let d=u.trim().toLowerCase();if(d.startsWith("javascript:")||d.startsWith("data:"))return}if(s){t.setAttributeNS(_e,e,String(u));return}if(i){t.setAttributeNS(xe,e,String(u));return}if(r)t.setAttribute(e,String(u));else if(e in t)try{t[e]=u;}catch(d){t.setAttribute(e,String(u));}else t.setAttribute(e,String(u));}function de(t,e,n,o=false){if(e===n)return;let r=fe(n);if(!r){t.removeAttribute("class");return}(isString(e)?e:fe(e))!==r&&(o?t.setAttribute("class",r):t.className=r);}var fe=normalizeClassName;var Ge=/\s*!important$/,kt=["Webkit","Moz","ms"],ke={};function me(t,e,n){let o=t.style;if(n&&isString(n)){e!==n&&(o.cssText=n);return}if(!n){e&&t.removeAttribute("style");return}if(e&&!isString(e)){let r=e;for(let s in r)(!n||n[s]==null)&&J(o,s,"");}else if(e&&isString(e)){let r=/(?:^|;)\s*([a-z][a-z\d-]*)\s*:/gi,s;for(;(s=r.exec(e))!==null;){let i=s[1].trim();i&&n&&isObject(n)&&n[i]==null&&J(o,i,"");}}if(n&&!isString(n)){let r=n;for(let s in r){let i=r[s];(!e||isString(e)||e[s]!==i)&&i!=null&&J(o,s,i);}}}function J(t,e,n){if(isArray(n)){for(let s of n)J(t,e,s);return}(n==null||n==="")&&(n="");let o=isString(n)&&Ge.test(n)?"important":"";if(o&&(n=n.replace(Ge,"")),e.startsWith("--")){o?t.setProperty(e,n,o):t.setProperty(e,n);return}let r=Rt(t,e);o?t.setProperty(Tt(r),n,o):t[r]=n;}function Tt(t){let e=kebabCase(t);return t.startsWith("Webkit")||t.startsWith("Moz")||t.startsWith("ms")?`-${e}`:e}function Rt(t,e){let n=ke[e];if(n)return n;let o=camelCase(e);if(o!=="filter"&&o in t)return ke[e]=o;o=capitalize(o);for(let r of kt){let s=r+o;if(s in t)return ke[e]=s}return e}var Te=0;function Ye(){return String(Te++)}function Ft(){Te=0;}var z=false;function le(){return z}var Q=new Map;function Mt(t){let e=t.querySelectorAll("[data-hk]");for(let n of e){let o=n.dataset.hk;o!=null&&!Q.has(o)&&Q.set(o,n);}}var ye=[],se=new Map;function It(){if(typeof document=="undefined")return;let t=document.createNodeIterator(document.body,NodeFilter.SHOW_COMMENT),e;for(;e=t.nextNode();){let n=e.data;if(n==="teleport-anchor")ye.push(e);else if(n==="teleport-start"){let o=e.parentElement;if(!o)continue;let r=se.get(o);r||(r=[],se.set(o,r)),r.push(e);}}}function Re(){var t;return (t=ye.shift())!=null?t:null}function Le(t){let e=se.get(t),n=e==null?void 0:e.shift();if(!n)return null;let o=[],r=n.nextSibling;for(;r;){if(r.nodeType===Node.COMMENT_NODE&&r.data==="teleport-end")return {start:n,end:r,nodes:o};o.push(r),r=r.nextSibling;}return null}function De(t){z=true,Te=0,Q.clear(),ye.length=0,se.clear(),Mt(t),It();}function Fe(){z=false,Q.clear(),ye.length=0,se.clear();}function Ht(t){if(!isBrowser())return ()=>{throw new Error("[essor] getRenderedElement called in non-browser environment")};let e=null;return ()=>{if(!z)return e||(e=pe(t)),e();let n=Ye(),o=Q.get(n);return o?(Q.delete(n),o):(warn(`[essor] hydration mismatch: no SSR element for key "${n}"`),e||(e=pe(t)),e())}}function Ot(t,e,n,o){z||de(t,e,n,o);}function Vt(t,e,n,o){z||G(t,e,n,o);}function jt(t,e,n){z||me(t,e,n);}function Me(t,e){return e&&e.parentNode===t?e:null}function Je(t,e,n,o){let r=Me(t,o),s=e.length,i=n.length;if(s===0&&i===0)return n;if(s===0){for(let f=0;f<i;f++)F(t,n[f],r);return n}if(i===0){for(let f=0;f<s;f++)K(e[f]);return []}let c=0,l=s-1,u=i-1;for(;c<=l&&c<=u&&e[c]===n[c];)c++;for(;l>=c&&u>=c&&e[l]===n[u];)l--,u--;if(c>l){if(c<=u){let f=u+1,d=Me(t,f<i?n[f]:r);for(let p=c;p<=u;p++)F(t,n[p],d);}}else if(c>u)for(let f=c;f<=l;f++)K(e[f]);else Kt(t,e,n,c,l,u,r);return n}function Kt(t,e,n,o,r,s,i){let c=s-o+1,l=new Map;for(let m=o;m<=s;m++)l.set(n[m],m);let u=new Int32Array(c);u.fill(0);let f=0,d=false,p=0;for(let m=o;m<=r;m++){let g=e[m];if(f>=c){K(g);continue}let a=l.get(g);a===void 0?K(g):(u[a-o]=m+1,a>=p?p=a:d=true,f++);}let h=d?Ie(u):[],N=h.length-1;for(let m=c-1;m>=0;m--){let g=o+m,a=n[g],y=Me(t,g+1<n.length?n[g+1]:i);u[m]===0?F(t,a,y):d&&(N<0||m!==h[N]?F(t,a,y):N--);}}function Ie(t){let e=new Int32Array(t.length),n=[0],o=t.length,r,s,i,c,l;for(r=0;r<o;r++){let u=t[r];if(u!==0){if(s=n[n.length-1],t[s]<u){e[r]=s,n.push(r);continue}for(i=0,c=n.length-1;i<c;)l=i+c>>1,t[n[l]]<u?i=l+1:c=l;u<t[n[i]]&&(i>0&&(e[r]=n[i-1]),n[i]=r);}}for(i=n.length,c=n[i-1];i-- >0;)n[i]=c,c=e[c];return n}function K(t){if(t)if(M(t))t.destroy();else {let e=t;e.parentNode&&e.remove();}}function F(t,e,n){if(!t||!e)return;let o=M(n)?n.firstChild:n;if(M(e)){e.mount(t,o);return}o?t.insertBefore(e,o):t.appendChild(e);}function Z(t){if(t instanceof Node||M(t))return t;let e=typeof t;return t==null||e==="string"||e==="number"||e==="boolean"||e==="symbol"?document.createTextNode(t===false||t==null?"":String(t)):document.createTextNode(String(t))}function W(t,e,n){if(!t)return;let o=c(),r=[],s=true,i=l=>{if(l instanceof Node)return [l];if(M(l))return [l];let u=typeof l;return l==null||u==="string"||u==="number"||u==="boolean"?[Z(l)]:coerceArray(l).map(f=>isFunction(f)?f():f).flatMap(f=>f).map(Z)},c$1=effect(()=>{let l=()=>{let u=isFunction(e)?e():e,f=i(u);if(s&&le()&&f.every(d=>d instanceof Node&&d.parentNode===t)){r=f,s=false;return}r=Je(t,r,f,n),s=false;};o&&!o.isDestroyed?f(o,l):l();});return h(()=>{c$1.stop();for(let l of r)K(l);r=[];}),r}function zt(t){return (t==null?void 0:t.firstChild)||null}function Wt(t,e=1){for(;t&&e>0;)t=t.nextSibling,e--;return t||null}function Bt(t,e){if(!t||e<0)return null;let n=t.firstChild;for(;n&&e>0;)n=n.nextSibling,e--;return n||null}function ee(t,e,n,o){if(!(o!=null&&o.delegate))return t.addEventListener(e,n,o),()=>t.removeEventListener(e,n,o);let r=o.delegate,s=u=>{let f=u.target;(f.matches(r)||f.closest(r))&&n.call(t,u);},l=o,{delegate:i}=l,c=a(l,["delegate"]);return t.addEventListener(e,s,c),()=>{t.removeEventListener(e,s,c);}}function He(t,e,n){let o=t[e];o||(o=[],t[e]=o),o.push(n);}function et(t,e,n){let o=t.length;if(o===0)return;let r;for(let s=0;s<o;s++)try{let i=t[s]();if(isPromise(i)){let c=i.catch(l=>{});(r||(r=[])).push(c);}}catch(i){}if(r)return Promise.all(r).then(()=>{})}function Oe(t){let e=c();if(e){if(e.isMounted){try{let n=t();isPromise(n)&&n.catch(o=>{});}catch(n){}return}He(e,"onMount",t);}}function Xt(t){let e=c();e&&He(e,"onUpdate",t);}function te(t){let e=c();e&&He(e,"onDestroy",t);}function tt(t){if(t.isDestroyed)return;if(!t.onMount||t.onMount.length===0){t.isMounted=true;return}let e=t.onMount,n=f(t,()=>et(e,t.id));return e.length=0,t.isMounted=true,n}function nt(t){if(!(t.isDestroyed||!t.onUpdate||t.onUpdate.length===0))return f(t,()=>et(t.onUpdate,t.id))}function rt(t,e,n=false){let o=n?new Set:null;for(let r of Object.getOwnPropertyNames(e))o==null||o.add(r),Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r));if(o)for(let r of Object.getOwnPropertyNames(t))o.has(r)||delete t[r];}function Jt(t,e){let n=Object.getOwnPropertyDescriptor(t,e);return n.get?n.get.call(t):n.value}var it;it="normal";var ne=class{constructor(e,n={}){this.component=e;this.props=n;this[it]=true;this.scope=null;this.state=0;this.beforeNode=void 0;this.renderedNodes=[];this.firstChild=void 0;this.parentNode=void 0;this.rootEventCleanups=[];this.parentScope=c();let o={};rt(o,n),this.reactiveProps=shallowReactive(o);}mount(e$1,n){var s;if(this.parentNode=e$1,this.beforeNode=n,this.state=1,this.renderedNodes.length>0){for(let i of this.renderedNodes)F(e$1,i,n);return this.state=2,this.renderedNodes}let o=e((s=this.parentScope)!=null?s:c());this.scope=o;let r=f(o,()=>{var c;let i=this.component(this.reactiveProps);return isFunction(i)&&(i=i(this.reactiveProps)),(isSignal(i)||isComputed(i))&&(i=i.value),(c=W(e$1,i,n))!=null?c:[]});return this.renderedNodes=r,this.firstChild=r[0],this.syncSpecialProps(this.props),this.state=2,tt(o),this.renderedNodes}update(e){this.props=e;let n=this.scope;!n||n.isDestroyed||(rt(this.reactiveProps,e!=null?e:{},true),this.syncSpecialProps(e),nt(n));}forceUpdate(){if(!this.parentNode)return;let e=this.parentNode,n=this.beforeNode;this.destroy(),this.mount(e,n);}destroy(){let e=this.scope;if(!(!e||e.isDestroyed)){this.scope=null,this.releaseSpecialProps(),g(e);for(let n of this.renderedNodes)K(n);this.renderedNodes=[],this.firstChild=void 0,this.parentNode=void 0;}}syncSpecialProps(e){if(!e)return;let n=this.firstChild;if(n){this.releaseSpecialProps();for(let o of Object.getOwnPropertyNames(e)){let r=Jt(e,o);if(o==="ref"){this.rootRefCleanup=this.bindRootRef(r,n);continue}if(isOn(o)&&isFunction(r)){let s=o.slice(2).toLowerCase();this.rootEventCleanups.push(ee(n,s,r));}}}}releaseSpecialProps(){for(let e of this.rootEventCleanups)e();this.rootEventCleanups.length=0,this.rootRefCleanup&&(this.rootRefCleanup(),this.rootRefCleanup=void 0);}bindRootRef(e,n){if(isFunction(e))return e(n),()=>e(null);if(isSignal(e)){let o=e,r=o.value;return o.value=n,()=>{o.value===n&&(o.value=r);}}}};function M(t){return !!t&&!!t.normal}function he(t,e){return M(t)?t:new ne(t,e)}function pe(t){let e,n=()=>{let o=document.createElement("template");o.innerHTML=t;let r=o.content.firstChild;if(!r)throw new Error("Invalid template: empty content");return r};return ()=>(e||(e=n())).cloneNode(true)}function Qt(t,e$1){let n=isString(e$1)?document.querySelector(e$1):e$1;if(!n)return;n.innerHTML&&(n.innerHTML="");let r=e(),s;try{f(r,()=>{let i=he(t);M(i)&&(s=i,F(n,i));});}catch(i){throw g(r),i}return {root:s,unmount:()=>{g(r),s==null||s.destroy();}}}function Zt(t,e$1){let n=isString(e$1)?document.querySelector(e$1):e$1;if(!n)return;De(n);let o=e(),r;try{f(o,()=>{let s=he(t);M(s)&&(r=s,W(n,s));});}catch(s){throw g(o),s}finally{Fe();}return {root:r,unmount:()=>{g(o),r==null||r.destroy();}}}function je(t,e){let n=c();n&&(n.provides||(n.provides=new Map),n.provides.set(t,e));}function ce(t,e){let n=c();if(!n)return e;let o=n;for(;o;){if(o.provides&&o.provides.has(t))return o.provides.get(t);o=o.parent;}return e}function Ke(t,e){Object.defineProperty(t,"target",{configurable:true,value:e});}function ct(t){let e=t.target,n=t.type,o=t.target,r=t.currentTarget,s=()=>{let c=e[`_$${n}`];if(c&&isFunction(c)&&!e.disabled){let l=e[`${n}Data`];if(l?c.call(e,l,t):c.call(e,t),t.cancelBubble)return false}return e.host&&!isString(e.host)&&!e.host._$host&&isFunction(e.contains)&&e.contains(t.target)&&Ke(t,e.host),true},i=()=>{for(;s()&&(e=e._$host||e.parentNode||e.host););};if(Object.defineProperty(t,"currentTarget",{configurable:true,get(){return e||document}}),t.composedPath){let c=t.composedPath();Ke(t,c[0]);for(let l=0;l<c.length-2&&(e=c[l],!!s());l++){if(e._$host){e=e._$host,i();break}if(e.parentNode===r)break}}else i();Ke(t,o);}var ge=Symbol("_$EVENTS");function tn(t,e=window.document){let n=e,o=n[ge]||(n[ge]=new Set);for(let r of t)o.has(r)||(o.add(r),e.addEventListener(r,ct));}function nn(t=window.document){let e=t,n=e[ge];if(n){for(let o of n.keys())t.removeEventListener(o,ct);delete e[ge];}}function oe(t,e,n,o){let r=ee(t,e,n,o);c()&&h(r);}function $e(t,e){let n=t,o=e==null?"":String(e);n.value!==o&&(n.value=o);}var ln={event:"change",forceChange:true,read:t=>t.checked,write(t,e){let n=t,o=!!e;n.checked!==o&&(n.checked=o);}},cn={event:"change",forceChange:true,read(t){let e=t;return e.checked?e.value:""},write(t,e){let n=t,o=String(e)===n.value;n.checked!==o&&(n.checked=o);}},an={event:"change",forceChange:true,read:t=>t.files,write(){}},un={event:"input",ime:true,read:t=>t.value,write:$e},fn={event:"input",ime:true,read:t=>t.value,write:$e},dn={event:"change",forceChange:true,read(t){let e=t;return e.multiple?Array.from(e.selectedOptions,n=>n.value):e.value},write(t,e){let n=t;if(n.multiple){let o=new Set((Array.isArray(e)?e:[]).map(String));for(let r of Array.from(n.options))r.selected=o.has(r.value);}else $e(t,e);}};function mn(t,e){switch(t.nodeName){case "INPUT":return e==="checked"?t.type==="radio"?cn:ln:e==="files"?an:un;case "SELECT":return dn;case "TEXTAREA":return fn;default:return {event:"input",read:n=>n[e],write(n,o){n[e]=o;}}}}function pn(t,e,n){if(!isString(t))return t;let o=t;if(e&&(o=o.trim()),n&&o!==""){let r=Number(o);if(!Number.isNaN(r))return r}return o}function yn(t){let e=t.getRootNode();return (e instanceof Document||e instanceof ShadowRoot)&&e.activeElement===t}function hn(t,e,n,o,r={}){if(!t)return;let{event:s,read:i,write:c$1,forceChange:l,ime:u}=mn(t,e),f=r.trim===true,d=r.number===true,p=r.lazy===true,h$1=(f||d)&&e!=="files",N=isFunction(n)?n:()=>n,m=h$1?S=>pn(S,f,d):S=>S,g=false,a=p||l?"change":s,y=()=>{if(g)return;let S=i(t);if(S===void 0)return;let A=m(S);Object.is(N(),A)||o(A);};oe(t,a,y),!p&&h$1&&a!=="change"&&oe(t,"change",()=>c$1(t,m(i(t)))),u&&!p&&(oe(t,"compositionstart",()=>{g=true;}),oe(t,"compositionend",()=>{g&&(g=false,y());}));let v=effect(()=>{let S=N();u&&!p&&yn(t)&&(g||Object.is(m(i(t)),S))||c$1(t,S);});c()&&h(()=>v.stop());}function gn(t,e){let n=new Set(e);return new Proxy(t,{get(o,r){if(!n.has(r))return Reflect.get(o,r)},ownKeys(o){return Reflect.ownKeys(o).filter(r=>!n.has(r))},getOwnPropertyDescriptor(o,r){if(!n.has(r))return Reflect.getOwnPropertyDescriptor(o,r)},has(o,r){return n.has(r)?false:Reflect.has(o,r)}})}function at(t){return !t||t.children==null?null:t.children}at[Ae]=true;function En(t){return !!t&&!!t[Ae]}function Ee(t){let e=isFunction(t.target)?t.target():t.target;return e==null?null:isString(e)?document.querySelector(e):e}function Ne(t){return isFunction(t.disabled)?!!t.disabled():!!t.disabled}function ft(t){if(le()){let f=Sn(t);if(f)return f}let e$1=document.createComment("portal");e$1[ie]=true;let{children:n}=t;if(n==null)return e$1;let o=c(),r=null,s=(f$1,d)=>{r=e(o),f(r,()=>{W(f$1,()=>n,d);});},i=()=>{r&&(g(r),r=null);},c$1=(f,d)=>{if(i(),f){let p=e$1.parentNode;if(!p)return;s(p,e$1);return}d&&s(d);},l=false,u=effect(()=>{let f=Ne(t),d=f?null:Ee(t);l&&c$1(f,d);});return Oe(()=>{l=!0;let f=Ne(t),d=f?null:Ee(t);if(f||d){c$1(f,d);return}queueMicrotask(()=>{e$1.parentNode&&c$1(Ne(t),Ee(t));});}),h(()=>{u.stop(),i();}),e$1}ft[ie]=true;function Sn(t){if(Ne(t))return null;let e=Re();if(!e)return null;let n=Ee(t);return !n||!Le(n)?null:(e[ie]=true,e)}function bn(t){return !!t&&!!t[ie]}function Se(t){for(;t.firstChild;)t.removeChild(t.firstChild);}function dt(t){let e=t;for(;isFunction(e);)e=e();return isSignal(e)||isComputed(e)?dt(e.value):e}var ae=Symbol("SuspenseContext");function mt(t){var N;if(!isBrowser())return (N=t.fallback)!=null?N:"";let e=document.createElement("div");e.style.display="contents";let n=true,o=0,r=false,s=null,i=m=>{let g=dt(m);if(isArray(g)){let a=[];for(let y of g){let v=i(y);isArray(v)?a.push(...v):a.push(v);}return a}return Z(g)},c=m=>{let g=i(m),a=isArray(g)?g:[g];for(let y of a)y!=null&&F(e,y);},l=()=>{Se(e),t.fallback!=null&&c(t.fallback);},u=()=>{r||(r=true,l());},f=()=>{!r||!(s||t.children!=null&&!isPromise(t.children))||(r=false,Se(e),s?d(s):t.children!=null&&!isPromise(t.children)&&d(t.children));},d=m=>{if(r||(Se(e),m==null))return;let g=isArray(m)?m:[m];for(let a of g)a!=null&&c(a);r&&l();},p={register:m=>{o++,u(),m.then(()=>{n&&(o--,o===0&&f());}).catch(g=>{n&&(o--,o===0&&f());});},increment:()=>{o++,u();},decrement:()=>{o=Math.max(0,o-1),o===0&&f();}};je(ae,p);let h=t.children;return isPromise(h)?(h.then(m=>{s=m;}).catch(()=>{}),p.register(h)):h!=null?d(h):u(),te(()=>{n=false,o=0,s=null,Se(e),e.remove();}),e}mt[Pe]=true;function An(t){return !!t&&!!t[Pe]}function Pn(t,e){let n=signal(e==null?void 0:e.initialValue),o=signal(true),r=signal(null),s=signal("pending"),i=0,c=null,l=false,u=ce(ae,null),f=()=>b(null,null,function*(){let h=++i;o.value=true,s.value="pending",r.value=null,l=false,u&&u.increment();try{let N=t();c=N,N.catch(()=>{});let m=yield N;h===i&&(n.value=m,s.value="ready",o.value=!1);}catch(N){h===i&&(r.value=N instanceof Error?N:new Error(String(N)),s.value="errored",o.value=false);}finally{u&&u.decrement();}});f();let d=(()=>(!l&&o.value&&c&&u&&(l=true,u.register(c)),n.value));return d.loading=o,d.error=r,d.state=s,[d,{mutate:h=>{n.value=h,s.value="ready",o.value=false,r.value=null;},refetch:()=>b(null,null,function*(){yield f();})}]}function pt(t){return isFunction(t)?t:t.default}function ze(t,e,n){let o=new ne(e,n);return o.mount(t),o}function Tn(t,e={}){let{delay:n=200,timeout:o,ssr:r="blocking",onError:s}=e;if(typeof window=="undefined"){if(r==="client-only"){let g=()=>"";return g.__asyncLoader=t,g.__asyncResolved=()=>null,g}let p=null,h=null,N=()=>h||(h=t().then(g=>{p=pt(g);}).catch(()=>{}),h);N();let m=g=>p?p(g):"";return m.__asyncLoader=N,m.__asyncResolved=()=>p,m}let i=null,c=null,l="pending",u=null;function f(){return u||(u=t().then(p=>{i=pt(p),l="resolved";}).catch(p=>{c=p instanceof Error?p:new Error(String(p)),l="errored",u=null;}),u)}f();function d(p){var B;if(l==="resolved"&&i){let b=document.createElement("div");b.style.display="contents";let I=ze(b,i,p);return h(()=>I.destroy()),b}if(l==="errored"&&c){let b=document.createElement("div");if(b.style.display="contents",e.error){let I=true,R=null,$=(q,E)=>{I&&(R==null||R.destroy(),R=ze(b,q,E));},X=()=>{u=null,l="pending",c=null,e.loading&&$(e.loading),f().then(()=>{I&&(l==="resolved"&&i?$(i,p):l==="errored"&&c&&e.error&&$(e.error,{error:c,retry:X}));});};$(e.error,{error:c,retry:X}),te(()=>{I=false,R==null||R.destroy(),R=null;});}return b}let h$1=document.createElement("div");h$1.style.display="contents";let N=true,m=null,g=null,a=null,y=(b,I)=>{N&&(m==null||m.destroy(),m=ze(h$1,b,I));},v=b=>()=>{u=null,l="pending",c=null,e.loading&&y(e.loading),f().then(()=>{l==="resolved"&&i?y(i,b):l==="errored"&&c&&e.error&&y(e.error,{error:c,retry:v(b)});});};te(()=>{N=false,m==null||m.destroy(),m=null,g!=null&&clearTimeout(g),a!=null&&clearTimeout(a);});let S=(B=ce(ae))!=null?B:null,A=b=>y(b,p),T=b=>{e.error&&y(e.error,{error:b,retry:v(p)});},V=()=>{e.loading&&y(e.loading);},j=f().then(()=>{N&&(l==="resolved"&&i?A(i):l==="errored"&&c&&(T(c),s&&s(c,v(p))),g!=null&&clearTimeout(g),a!=null&&clearTimeout(a));});return S&&S.register(j),n>0?g=setTimeout(()=>{N&&l==="pending"&&V();},n):e.loading&&V(),o!=null&&(a=setTimeout(()=>{if(N&&l==="pending"){let b=new Error(`[defineAsyncComponent] Timeout after ${o}ms`);c=b,l="errored",T(b),s&&s(b,v(p));}},o)),h$1}return d.__asyncLoader=f,d.__asyncResolved=()=>i,d}function yt(t){let e$1=document.createDocumentFragment(),n=document.createComment("");e$1.appendChild(n);let o=[],r=[],s=t.key,i=t.children,c$1=()=>{var y,v;let a=t.each;return isSignal(a)?(y=a.value)!=null?y:[]:isFunction(a)?(v=a())!=null?v:[]:a!=null?a:[]},l=a=>s?s(a):a,u=a=>{if(Array.isArray(a)){let y=[];for(let v of a)y.push(...u(v));return y}return [Z(a)]},f$1=(a,y,v)=>{let S=u(a);for(let A of S)v?y.insertBefore(A,v):y.appendChild(A);return S},d=(a,y)=>{if(!t.fallback)return;r=f$1(t.fallback(),a,y);},p=()=>{for(let a of r)a.parentNode&&a.parentNode.removeChild(a);r=[];},h$1=(a,y,v,S)=>{let A=c(),T=e(A),V=[];return f(T,()=>{V=f$1(i(a,y),v,S);}),{key:l(a),item:a,nodes:V,scope:T}},N=a=>{g(a.scope);for(let y of a.nodes)y.parentNode&&y.parentNode.removeChild(y);},m=effect(()=>{let a=c$1(),y=n.parentNode;if(!y){if(a.length===0)d(e$1,n);else {o=new Array(a.length);let v=0;for(let S of a)o[v]=h$1(S,v,e$1,n),v++;}return}g$1(y,a);});function g$1(a,y){let v=o.length,S=y.length;if(S===0){for(let E=0;E<v;E++)N(o[E]);o=[],t.fallback&&r.length===0&&d(a,n);return}if(v===0||r.length>0){r.length>0&&p(),o=new Array(S);let E=document.createDocumentFragment();for(let x=0;x<S;x++)o[x]=h$1(y[x],x,E,null);a.insertBefore(E,n);return}let A=new Map;for(let E=0;E<v;E++){let x=o[E],H=A.get(x.key),U=[x,E];H?H.push(U):A.set(x.key,[U]);}let T=new Array(S),V=[],j=null,B=new Int32Array(S),b=false,I=0,R=new Array(S);for(let E=0;E<S;E++)R[E]=l(y[E]);for(let E=0;E<S;E++){let x=y[E],H=R[E],U=A.get(H);if(U&&U.length>0){let[re,L]=U.shift();Object.is(re.item,x)?(re.item=x,T[E]=re,B[E]=L+1,L<I?b=true:I=L):(j||(j=document.createDocumentFragment()),N(re),T[E]=h$1(x,E,j,null));}else j||(j=document.createDocumentFragment()),T[E]=h$1(x,E,j,null);}for(let E of A.values())for(let[x]of E)V.push(x);for(let E of V)N(E);let $=b?Ie(B):[],X=$.length-1,q=n;for(let E=S-1;E>=0;E--){let H=T[E].nodes;if(!(B[E]===0)&&b&&X>=0&&E===$[X]){X--;for(let L=H.length-1;L>=0;L--)q=H[L];continue}for(let L=H.length-1;L>=0;L--){let Ce=H[L];Ce.nextSibling!==q&&a.insertBefore(Ce,q),q=Ce;}}o=T;}return h(()=>{m.stop();for(let a of o)N(a);o=[],p(),n.parentNode&&n.parentNode.removeChild(n);}),e$1}yt[Xe]=true;
|
|
2
|
+
export{ne as Component,yt as For,at as Fragment,ft as Portal,mt as Suspense,ee as addEvent,oe as addEventListener,De as beginHydration,hn as bindElement,zt as child,nn as clearDelegatedEvents,Re as consumeTeleportAnchor,Le as consumeTeleportBlock,Qt as createApp,he as createComponent,Pn as createResource,Tn as defineAsyncComponent,tn as delegateEvents,Fe as endHydration,Ye as getHydrationKey,Ht as getRenderedElement,Zt as hydrate,ce as inject,W as insert,M as isComponent,En as isFragment,le as isHydrating,bn as isPortal,An as isSuspense,Wt as next,fe as normalizeClass,Bt as nthChild,gn as omitProps,te as onDestroy,Oe as onMount,Xt as onUpdate,G as patchAttr,Vt as patchAttrHydrate,de as patchClass,Ot as patchClassHydrate,me as patchStyle,jt as patchStyleHydrate,je as provide,Ft as resetHydrationKey,J as setStyle,pe as template};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estjs/template",
|
|
3
|
-
"version": "0.0.16-beta.
|
|
3
|
+
"version": "0.0.16-beta.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [],
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"types": "./dist/template.d.ts",
|
|
51
51
|
"require": "./dist/template.cjs.js",
|
|
52
|
-
"import": "./dist/template.
|
|
52
|
+
"import": "./dist/template.esm.js"
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"typesVersions": {
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
"jsdelivr": "dist/template.esm.js",
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"csstype": "^3.2.3",
|
|
67
|
-
"@estjs/
|
|
68
|
-
"@estjs/
|
|
67
|
+
"@estjs/signals": "0.0.16-beta.5",
|
|
68
|
+
"@estjs/shared": "0.0.16-beta.5"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@babel/core": "^7.24.0",
|
|
72
|
-
"babel-plugin-essor": "0.0.16-beta.
|
|
72
|
+
"babel-plugin-essor": "0.0.16-beta.5"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
|
-
"build": "tsup && cross-env NODE_ENV=production tsup --clean=false
|
|
75
|
+
"build": "tsup && cross-env NODE_ENV=production tsup --clean=false",
|
|
76
76
|
"dev": "tsup --watch"
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/scope.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,IAAI,WAAA,GAA4B,IAAA;AAGhC,IAAI,OAAA,GAAU,CAAA;AAOP,SAAS,cAAA,GAA+B;AAC7C,EAAA,OAAO,WAAA;AACT;AAoBO,SAAS,WAAA,CAAY,SAAuB,WAAA,EAAoB;AACrE,EAAA,MAAM,aAAA,GAAgB,MAAA,GAAS,MAAA,CAAO,WAAA,CAAY,GAAA,CAAI,MAAM,WAAA,EAAa,CAAA,GAAK,WAAA,CAAY,IAAI,CAAA;AAC9F,EAAA,MAAM,KAAA,GAAe;AAAA,IACnB,IAAI,EAAE,OAAA;AAAA,IACN,WAAA,EAAa,aAAA;AAAA,IACb,MAAA;AAAA,IACA,QAAA,EAAU,IAAA;AAAA;AAAA,IACV,QAAA,EAAU,IAAA;AAAA;AAAA,IACV,OAAA,EAAS,IAAA;AAAA;AAAA,IACT,OAAA,EAAS,IAAA;AAAA;AAAA,IACT,QAAA,EAAU,IAAA;AAAA;AAAA,IACV,SAAA,EAAW,IAAA;AAAA;AAAA,IACX,SAAA,EAAW,KAAA;AAAA,IACX,WAAA,EAAa;AAAA,GACf;AAGA,EAAA,IAAI,MAAA,EAAQ;AACV,IAAA,IAAI,CAAC,OAAO,QAAA,EAAU;AACpB,MAAA,MAAA,CAAO,QAAA,uBAAe,GAAA,EAAI;AAAA,IAC5B;AACA,IAAA,MAAA,CAAO,QAAA,CAAS,IAAI,KAAK,CAAA;AAAA,EAC3B;AAEA,EAAA,OAAO,KAAA;AACT;AAUO,SAAS,YAAA,CAAgB,OAAc,EAAA,EAAgB;A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U,EAAC;AAAA,EACnB;AAEA,EAAA,KAAA,CAAM,OAAA,CAAQ,KAAK,EAAE,CAAA;AACvB","file":"chunk-JT6RSDKI.dev.esm.js","sourcesContent":["import { error } from '@estjs/shared';\nimport { type EffectScope, effectScope, setCurrentScope } from '@estjs/signals';\nimport type { InjectionKey } from './provide';\n\n/**\n * Scope represents an execution context in the component tree.\n * It manages provides, cleanup functions, and lifecycle hooks.\n */\nexport interface Scope {\n /** Unique identifier for debugging */\n readonly id: number;\n\n /** Reactive effect scope tied to this template scope */\n readonly effectScope: EffectScope;\n\n /** Parent scope in the hierarchy */\n parent: Scope | null;\n\n /** Child scopes (lazy initialized) */\n children: Set<Scope> | null;\n\n /** Provided values (lazy initialized) */\n provides: Map<InjectionKey<unknown> | string | number | symbol, unknown> | null;\n\n /** Cleanup functions (lazy initialized) */\n cleanup: Array<() => void> | null;\n\n /** Mount lifecycle hooks (lazy initialized) */\n onMount: Array<() => void | Promise<void>> | null;\n\n /** Update lifecycle hooks (lazy initialized) */\n onUpdate: Array<() => void | Promise<void>> | null;\n\n /** Destroy lifecycle hooks (lazy initialized) */\n onDestroy: Array<() => void | Promise<void>> | null;\n\n /** Whether the scope has been mounted */\n isMounted: boolean;\n\n /** Whether the scope has been destroyed */\n isDestroyed: boolean;\n}\n\n/** Currently active scope */\nlet activeScope: Scope | null = null;\n\n/** Scope ID counter for unique identification */\nlet scopeId = 0;\n\n/**\n * Get the currently active scope.\n *\n * @returns The active scope or null if none is active.\n */\nexport function getActiveScope(): Scope | null {\n return activeScope;\n}\n\n/**\n * Set the active scope (internal use).\n *\n * @param scope - The scope to set as active.\n * @returns {void}\n */\nexport function setActiveScope(scope: Scope | null): void {\n activeScope = scope;\n setCurrentScope(scope?.effectScope);\n}\n\n/**\n * Create a new scope with optional parent.\n * If no parent is provided, uses the current active scope as parent.\n *\n * @param parent - Optional parent scope (defaults to active scope).\n * @returns A new scope instance.\n */\nexport function createScope(parent: Scope | null = activeScope): Scope {\n const reactiveScope = parent ? parent.effectScope.run(() => effectScope())! : effectScope(true);\n const scope: Scope = {\n id: ++scopeId,\n effectScope: reactiveScope,\n parent,\n children: null, // Lazy initialized\n provides: null, // Lazy initialized\n cleanup: null, // Lazy initialized\n onMount: null, // Lazy initialized\n onUpdate: null, // Lazy initialized\n onDestroy: null, // Lazy initialized\n isMounted: false,\n isDestroyed: false,\n };\n\n // Establish parent-child relationship\n if (parent) {\n if (!parent.children) {\n parent.children = new Set();\n }\n parent.children.add(scope);\n }\n\n return scope;\n}\n\n/**\n * Run a function within a scope, ensuring proper cleanup.\n * The previous active scope is restored even if the function throws.\n *\n * @param scope - The scope to run within.\n * @param fn - The function to execute.\n * @returns The return value of the function.\n */\nexport function runWithScope<T>(scope: Scope, fn: () => T): T {\n const prevScope = activeScope;\n activeScope = scope;\n\n try {\n return scope.effectScope.run(fn) as T;\n } finally {\n // Restore previous scope directly\n activeScope = prevScope;\n }\n}\n\n/**\n * Dispose a scope and all its children.\n * Children are disposed first (depth-first), then the scope itself.\n *\n * @param scope - The scope to dispose.\n * @returns {void}\n */\nexport function disposeScope(scope: Scope): void {\n // Idempotent: already destroyed\n if (!scope || scope.isDestroyed) {\n return;\n }\n\n // Mark destroyed immediately to block re-entrant disposeScope calls\n // (e.g. an onDestroy hook that accidentally disposes the same scope again).\n scope.isDestroyed = true;\n\n // Dispose children first (depth-first)\n // Iterate directly safely by unlinking parent reference to prevent mutation during iteration\n if (scope.children && scope.children.size > 0) {\n for (const child of scope.children) {\n if (child) {\n child.parent = null;\n disposeScope(child);\n }\n }\n scope.children.clear();\n }\n\n // Execute destroy lifecycle hooks and cleanup functions within the scope's\n // context so that inject/provide/getActiveScope work correctly in callbacks.\n //\n // NOTE: `scope.isDestroyed` is already `true` at this point — this is\n // intentional to prevent re-entrant `disposeScope()` calls from within\n // hooks. Callbacks that inspect `getActiveScope()?.isDestroyed` should\n // be aware of this.\n runWithScope(scope, () => {\n // Execute destroy lifecycle hooks\n if (scope.onDestroy) {\n for (let i = 0; i < scope.onDestroy.length; i++) {\n try {\n scope.onDestroy[i]();\n } catch (error_) {\n if (__DEV__) {\n error(`Scope(${scope.id}): Error in destroy hook:`, error_);\n }\n }\n }\n scope.onDestroy = null;\n }\n\n // Execute cleanup functions\n if (scope.cleanup) {\n for (let i = 0; i < scope.cleanup.length; i++) {\n try {\n scope.cleanup[i]();\n } catch (error_) {\n if (__DEV__) {\n error(`Scope(${scope.id}): Error in cleanup:`, error_);\n }\n }\n }\n scope.cleanup = null;\n }\n });\n\n scope.effectScope.stop();\n\n // Remove from parent's children\n if (scope.parent?.children) {\n scope.parent.children.delete(scope);\n }\n\n // Clear all internal collections to prevent memory leaks\n if (scope.provides) {\n scope.provides.clear();\n scope.provides = null;\n }\n scope.onMount = null;\n scope.onUpdate = null;\n scope.children = null;\n\n // Break parent reference to prevent memory leaks\n scope.parent = null;\n}\n\n/**\n * Register a cleanup function in the current scope.\n * The function will be called when the scope is disposed.\n *\n * @param fn - The cleanup function.\n */\nexport function onCleanup(fn: () => void): void {\n const scope = activeScope;\n\n if (!scope) {\n if (__DEV__) {\n error('onCleanup() must be called within a scope');\n }\n return;\n }\n\n // Lazy initialize cleanup array\n if (!scope.cleanup) {\n scope.cleanup = [];\n }\n\n scope.cleanup.push(fn);\n}\n"]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import'@estjs/shared';import {effectScope}from'@estjs/signals';var d=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable;var _=(e,r)=>{var n={};for(var o in e)S.call(e,o)&&r.indexOf(o)<0&&(n[o]=e[o]);if(e!=null&&d)for(var o of d(e))r.indexOf(o)<0&&y.call(e,o)&&(n[o]=e[o]);return n};var m=(e,r,n)=>new Promise((o,c)=>{var p=l=>{try{i(n.next(l));}catch(u){c(u);}},a=l=>{try{i(n.throw(l));}catch(u){c(u);}},i=l=>l.done?o(l.value):Promise.resolve(l.value).then(p,a);i((n=n.apply(e,r)).next());});var t=null,v=0;function w(){return t}function T(e=t){let r=e?e.effectScope.run(()=>effectScope()):effectScope(true),n={id:++v,effectScope:r,parent:e,children:null,provides:null,cleanup:null,onMount:null,onUpdate:null,onDestroy:null,isMounted:false,isDestroyed:false};return e&&(e.children||(e.children=new Set),e.children.add(n)),n}function h(e,r){let n=t;t=e;try{return e.effectScope.run(r)}finally{t=n;}}function s(e){var r;if(!(!e||e.isDestroyed)){if(e.isDestroyed=true,e.children&&e.children.size>0){for(let n of e.children)n&&(n.parent=null,s(n));e.children.clear();}h(e,()=>{if(e.onDestroy){for(let n=0;n<e.onDestroy.length;n++)try{e.onDestroy[n]();}catch(o){}e.onDestroy=null;}if(e.cleanup){for(let n=0;n<e.cleanup.length;n++)try{e.cleanup[n]();}catch(o){}e.cleanup=null;}}),e.effectScope.stop(),(r=e.parent)!=null&&r.children&&e.parent.children.delete(e),e.provides&&(e.provides.clear(),e.provides=null),e.onMount=null,e.onUpdate=null,e.children=null,e.parent=null;}}function k(e){let r=t;r&&(r.cleanup||(r.cleanup=[]),r.cleanup.push(e));}export{_ as a,m as b,w as c,T as d,h as e,s as f,k as g};//# sourceMappingURL=chunk-WWGSC3TY.esm.js.map
|
|
2
|
-
//# sourceMappingURL=chunk-WWGSC3TY.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/scope.ts"],"names":["activeScope","scopeId","getActiveScope","createScope","parent","reactiveScope","effectScope","scope","runWithScope","fn","prevScope","disposeScope","_a","child","i","error_","onCleanup"],"mappings":"+DAAA,IAAA,CAAA,CAAA,MAAA,CAAA,qBAAA,CAAA,IAAA,CAAA,CAAA,MAAA,CAAA,SAAA,CAAA,cAAA,CAAA,CAAA,CAAA,MAAA,CAAA,SAAA,CAAA,oBAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,IAAA,CAAA,CAAA,EAAA,CAAA,IAAA,IAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA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QAAA,CAAW,IAAA,CAGjBA,CAAAA,CAAM,MAAA,CAAS,KAAA,CACjB,CAQO,SAASS,CAAAA,CAAUP,CAAAA,CAAsB,CAC9C,IAAMF,CAAAA,CAAQP,CAAAA,CAETO,CAAAA,GAQAA,CAAAA,CAAM,OAAA,GACTA,CAAAA,CAAM,OAAA,CAAU,EAAC,CAAA,CAGnBA,CAAAA,CAAM,OAAA,CAAQ,IAAA,CAAKE,CAAE,CAAA,EACvB","file":"chunk-WWGSC3TY.esm.js","sourcesContent":["import { error } from '@estjs/shared';\nimport { type EffectScope, effectScope, setCurrentScope } from '@estjs/signals';\nimport type { InjectionKey } from './provide';\n\n/**\n * Scope represents an execution context in the component tree.\n * It manages provides, cleanup functions, and lifecycle hooks.\n */\nexport interface Scope {\n /** Unique identifier for debugging */\n readonly id: number;\n\n /** Reactive effect scope tied to this template scope */\n readonly effectScope: EffectScope;\n\n /** Parent scope in the hierarchy */\n parent: Scope | null;\n\n /** Child scopes (lazy initialized) */\n children: Set<Scope> | null;\n\n /** Provided values (lazy initialized) */\n provides: Map<InjectionKey<unknown> | string | number | symbol, unknown> | null;\n\n /** Cleanup functions (lazy initialized) */\n cleanup: Array<() => void> | null;\n\n /** Mount lifecycle hooks (lazy initialized) */\n onMount: Array<() => void | Promise<void>> | null;\n\n /** Update lifecycle hooks (lazy initialized) */\n onUpdate: Array<() => void | Promise<void>> | null;\n\n /** Destroy lifecycle hooks (lazy initialized) */\n onDestroy: Array<() => void | Promise<void>> | null;\n\n /** Whether the scope has been mounted */\n isMounted: boolean;\n\n /** Whether the scope has been destroyed */\n isDestroyed: boolean;\n}\n\n/** Currently active scope */\nlet activeScope: Scope | null = null;\n\n/** Scope ID counter for unique identification */\nlet scopeId = 0;\n\n/**\n * Get the currently active scope.\n *\n * @returns The active scope or null if none is active.\n */\nexport function getActiveScope(): Scope | null {\n return activeScope;\n}\n\n/**\n * Set the active scope (internal use).\n *\n * @param scope - The scope to set as active.\n * @returns {void}\n */\nexport function setActiveScope(scope: Scope | null): void {\n activeScope = scope;\n setCurrentScope(scope?.effectScope);\n}\n\n/**\n * Create a new scope with optional parent.\n * If no parent is provided, uses the current active scope as parent.\n *\n * @param parent - Optional parent scope (defaults to active scope).\n * @returns A new scope instance.\n */\nexport function createScope(parent: Scope | null = activeScope): Scope {\n const reactiveScope = parent ? parent.effectScope.run(() => effectScope())! : effectScope(true);\n const scope: Scope = {\n id: ++scopeId,\n effectScope: reactiveScope,\n parent,\n children: null, // Lazy initialized\n provides: null, // Lazy initialized\n cleanup: null, // Lazy initialized\n onMount: null, // Lazy initialized\n onUpdate: null, // Lazy initialized\n onDestroy: null, // Lazy initialized\n isMounted: false,\n isDestroyed: false,\n };\n\n // Establish parent-child relationship\n if (parent) {\n if (!parent.children) {\n parent.children = new Set();\n }\n parent.children.add(scope);\n }\n\n return scope;\n}\n\n/**\n * Run a function within a scope, ensuring proper cleanup.\n * The previous active scope is restored even if the function throws.\n *\n * @param scope - The scope to run within.\n * @param fn - The function to execute.\n * @returns The return value of the function.\n */\nexport function runWithScope<T>(scope: Scope, fn: () => T): T {\n const prevScope = activeScope;\n activeScope = scope;\n\n try {\n return scope.effectScope.run(fn) as T;\n } finally {\n // Restore previous scope directly\n activeScope = prevScope;\n }\n}\n\n/**\n * Dispose a scope and all its children.\n * Children are disposed first (depth-first), then the scope itself.\n *\n * @param scope - The scope to dispose.\n * @returns {void}\n */\nexport function disposeScope(scope: Scope): void {\n // Idempotent: already destroyed\n if (!scope || scope.isDestroyed) {\n return;\n }\n\n // Mark destroyed immediately to block re-entrant disposeScope calls\n // (e.g. an onDestroy hook that accidentally disposes the same scope again).\n scope.isDestroyed = true;\n\n // Dispose children first (depth-first)\n // Iterate directly safely by unlinking parent reference to prevent mutation during iteration\n if (scope.children && scope.children.size > 0) {\n for (const child of scope.children) {\n if (child) {\n child.parent = null;\n disposeScope(child);\n }\n }\n scope.children.clear();\n }\n\n // Execute destroy lifecycle hooks and cleanup functions within the scope's\n // context so that inject/provide/getActiveScope work correctly in callbacks.\n //\n // NOTE: `scope.isDestroyed` is already `true` at this point — this is\n // intentional to prevent re-entrant `disposeScope()` calls from within\n // hooks. Callbacks that inspect `getActiveScope()?.isDestroyed` should\n // be aware of this.\n runWithScope(scope, () => {\n // Execute destroy lifecycle hooks\n if (scope.onDestroy) {\n for (let i = 0; i < scope.onDestroy.length; i++) {\n try {\n scope.onDestroy[i]();\n } catch (error_) {\n if (__DEV__) {\n error(`Scope(${scope.id}): Error in destroy hook:`, error_);\n }\n }\n }\n scope.onDestroy = null;\n }\n\n // Execute cleanup functions\n if (scope.cleanup) {\n for (let i = 0; i < scope.cleanup.length; i++) {\n try {\n scope.cleanup[i]();\n } catch (error_) {\n if (__DEV__) {\n error(`Scope(${scope.id}): Error in cleanup:`, error_);\n }\n }\n }\n scope.cleanup = null;\n }\n });\n\n scope.effectScope.stop();\n\n // Remove from parent's children\n if (scope.parent?.children) {\n scope.parent.children.delete(scope);\n }\n\n // Clear all internal collections to prevent memory leaks\n if (scope.provides) {\n scope.provides.clear();\n scope.provides = null;\n }\n scope.onMount = null;\n scope.onUpdate = null;\n scope.children = null;\n\n // Break parent reference to prevent memory leaks\n scope.parent = null;\n}\n\n/**\n * Register a cleanup function in the current scope.\n * The function will be called when the scope is disposed.\n *\n * @param fn - The cleanup function.\n */\nexport function onCleanup(fn: () => void): void {\n const scope = activeScope;\n\n if (!scope) {\n if (__DEV__) {\n error('onCleanup() must be called within a scope');\n }\n return;\n }\n\n // Lazy initialize cleanup array\n if (!scope.cleanup) {\n scope.cleanup = [];\n }\n\n scope.cleanup.push(fn);\n}\n"]}
|
package/dist/internal.cjs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/scope.ts"],"names":["activeScope","scopeId","getActiveScope","createScope","parent","reactiveScope","effectScope","scope","runWithScope","fn","prevScope","disposeScope","_a","child","i","error_"],"mappings":"4EA4CA,IAAIA,CAAAA,CAA4B,IAAA,CAG5BC,CAAAA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","sourcesContent":["import { error } from '@estjs/shared';\nimport { type EffectScope, effectScope, setCurrentScope } from '@estjs/signals';\nimport type { InjectionKey } from './provide';\n\n/**\n * Scope represents an execution context in the component tree.\n * It manages provides, cleanup functions, and lifecycle hooks.\n */\nexport interface Scope {\n /** Unique identifier for debugging */\n readonly id: number;\n\n /** Reactive effect scope tied to this template scope */\n readonly effectScope: EffectScope;\n\n /** Parent scope in the hierarchy */\n parent: Scope | null;\n\n /** Child scopes (lazy initialized) */\n children: Set<Scope> | null;\n\n /** Provided values (lazy initialized) */\n provides: Map<InjectionKey<unknown> | string | number | symbol, unknown> | null;\n\n /** Cleanup functions (lazy initialized) */\n cleanup: Array<() => void> | null;\n\n /** Mount lifecycle hooks (lazy initialized) */\n onMount: Array<() => void | Promise<void>> | null;\n\n /** Update lifecycle hooks (lazy initialized) */\n onUpdate: Array<() => void | Promise<void>> | null;\n\n /** Destroy lifecycle hooks (lazy initialized) */\n onDestroy: Array<() => void | Promise<void>> | null;\n\n /** Whether the scope has been mounted */\n isMounted: boolean;\n\n /** Whether the scope has been destroyed */\n isDestroyed: boolean;\n}\n\n/** Currently active scope */\nlet activeScope: Scope | null = null;\n\n/** Scope ID counter for unique identification */\nlet scopeId = 0;\n\n/**\n * Get the currently active scope.\n *\n * @returns The active scope or null if none is active.\n */\nexport function getActiveScope(): Scope | null {\n return activeScope;\n}\n\n/**\n * Set the active scope (internal use).\n *\n * @param scope - The scope to set as active.\n * @returns {void}\n */\nexport function setActiveScope(scope: Scope | null): void {\n activeScope = scope;\n setCurrentScope(scope?.effectScope);\n}\n\n/**\n * Create a new scope with optional parent.\n * If no parent is provided, uses the current active scope as parent.\n *\n * @param parent - Optional parent scope (defaults to active scope).\n * @returns A new scope instance.\n */\nexport function createScope(parent: Scope | null = activeScope): Scope {\n const reactiveScope = parent ? parent.effectScope.run(() => effectScope())! : effectScope(true);\n const scope: Scope = {\n id: ++scopeId,\n effectScope: reactiveScope,\n parent,\n children: null, // Lazy initialized\n provides: null, // Lazy initialized\n cleanup: null, // Lazy initialized\n onMount: null, // Lazy initialized\n onUpdate: null, // Lazy initialized\n onDestroy: null, // Lazy initialized\n isMounted: false,\n isDestroyed: false,\n };\n\n // Establish parent-child relationship\n if (parent) {\n if (!parent.children) {\n parent.children = new Set();\n }\n parent.children.add(scope);\n }\n\n return scope;\n}\n\n/**\n * Run a function within a scope, ensuring proper cleanup.\n * The previous active scope is restored even if the function throws.\n *\n * @param scope - The scope to run within.\n * @param fn - The function to execute.\n * @returns The return value of the function.\n */\nexport function runWithScope<T>(scope: Scope, fn: () => T): T {\n const prevScope = activeScope;\n activeScope = scope;\n\n try {\n return scope.effectScope.run(fn) as T;\n } finally {\n // Restore previous scope directly\n activeScope = prevScope;\n }\n}\n\n/**\n * Dispose a scope and all its children.\n * Children are disposed first (depth-first), then the scope itself.\n *\n * @param scope - The scope to dispose.\n * @returns {void}\n */\nexport function disposeScope(scope: Scope): void {\n // Idempotent: already destroyed\n if (!scope || scope.isDestroyed) {\n return;\n }\n\n // Mark destroyed immediately to block re-entrant disposeScope calls\n // (e.g. an onDestroy hook that accidentally disposes the same scope again).\n scope.isDestroyed = true;\n\n // Dispose children first (depth-first)\n // Iterate directly safely by unlinking parent reference to prevent mutation during iteration\n if (scope.children && scope.children.size > 0) {\n for (const child of scope.children) {\n if (child) {\n child.parent = null;\n disposeScope(child);\n }\n }\n scope.children.clear();\n }\n\n // Execute destroy lifecycle hooks and cleanup functions within the scope's\n // context so that inject/provide/getActiveScope work correctly in callbacks.\n //\n // NOTE: `scope.isDestroyed` is already `true` at this point — this is\n // intentional to prevent re-entrant `disposeScope()` calls from within\n // hooks. Callbacks that inspect `getActiveScope()?.isDestroyed` should\n // be aware of this.\n runWithScope(scope, () => {\n // Execute destroy lifecycle hooks\n if (scope.onDestroy) {\n for (let i = 0; i < scope.onDestroy.length; i++) {\n try {\n scope.onDestroy[i]();\n } catch (error_) {\n if (__DEV__) {\n error(`Scope(${scope.id}): Error in destroy hook:`, error_);\n }\n }\n }\n scope.onDestroy = null;\n }\n\n // Execute cleanup functions\n if (scope.cleanup) {\n for (let i = 0; i < scope.cleanup.length; i++) {\n try {\n scope.cleanup[i]();\n } catch (error_) {\n if (__DEV__) {\n error(`Scope(${scope.id}): Error in cleanup:`, error_);\n }\n }\n }\n scope.cleanup = null;\n }\n });\n\n scope.effectScope.stop();\n\n // Remove from parent's children\n if (scope.parent?.children) {\n scope.parent.children.delete(scope);\n }\n\n // Clear all internal collections to prevent memory leaks\n if (scope.provides) {\n scope.provides.clear();\n scope.provides = null;\n }\n scope.onMount = null;\n scope.onUpdate = null;\n scope.children = null;\n\n // Break parent reference to prevent memory leaks\n scope.parent = null;\n}\n\n/**\n * Register a cleanup function in the current scope.\n * The function will be called when the scope is disposed.\n *\n * @param fn - The cleanup function.\n */\nexport function onCleanup(fn: () => void): void {\n const scope = activeScope;\n\n if (!scope) {\n if (__DEV__) {\n error('onCleanup() must be called within a scope');\n }\n return;\n }\n\n // Lazy initialize cleanup array\n if (!scope.cleanup) {\n scope.cleanup = [];\n }\n\n scope.cleanup.push(fn);\n}\n"]}
|
package/dist/internal.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"internal.esm.js"}
|