@estjs/template 0.0.14 → 0.0.15-beta.10

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/README.md CHANGED
@@ -0,0 +1,14 @@
1
+ # @estjs/template
2
+
3
+ The template engine for **Essor**. It handles the normalization of JSX templates and provides the runtime support for Server-Side Rendering (SSR) and Static Site Generation (SSG).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @estjs/template
9
+ ```
10
+
11
+
12
+ ## License
13
+
14
+ MIT
@@ -1,7 +1,3 @@
1
- 'use strict';var shared=require('@estjs/shared'),signal=require('@estjs/signal');/**
2
- * @estjs/template v0.0.14
3
- * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
4
- * @license MIT
5
- **/
6
- var R="on",w="update",E="children",A="",U="0",B="1";var H="ref",_=" __PLACEHOLDER__ ";var G=class{constructor(){this.renderMode=0;}get isSSG(){return this.renderMode===1}get isSSR(){return this.renderMode===2}get isClient(){return this.renderMode===0}setSSR(){this.renderMode=2;}setSSG(){this.renderMode=1;}setClient(){this.renderMode=0;}},u=new G,q=new Map;function z(n,t){q.set(n,{index:t});}function W(n){var t;return (t=q.get(n))==null?void 0:t.index}var T=class T{constructor(){this.hooks={mounted:new Set,destroy:new Set};}addEventListener(){}removeEventListener(){}addHook(t,e){var o;(o=this.hooks[t])==null||o.add(e);}getContext(t){return T.context[t]}setContext(t,e){T.context[t]=e;}initRef(){T.ref=this;}removeRef(){T.ref=null;}clearHooks(){Object.values(this.hooks).forEach(t=>t.clear());}};T.ref=null,T.context={};var l=T;function O(n){return n instanceof b}var C=1,b=class extends l{constructor(e,o={},r){super();this.template=e;this.props=o;this.key=r;z(e,C),this.templates=this.processTemplate();}processTemplate(){if(shared.isArray(this.template)){let e=this.template.join(_);return this.processHtmlString(e).split(_)}return []}processHtmlString(e){return e.replaceAll(/(<[^>]+>)|([^<]+)/g,(o,r,i)=>r?r.includes("data-ci")?o:r.replace(/<\s*([\da-z]+)(\s[^>]*)?>/i,(s,c,a)=>`<${c} data-ci="${C}"${a||""}>`):i&&i.replace(_,"").trim()?`<!--0-${C}-->${i}<!$>`:o)}mount(){this.initRef();let e=this.render();return this.removeRef(),e}render(){if(shared.isFunction(this.template)){let e=this.template(this.props);return O(e)?e.mount():String(e)}return this.renderTemplate()}renderTemplate(){return Object.entries(this.props).forEach(([e,o])=>{let r=o.children;this.normalizeProps(o);let i=this.templates.findIndex(s=>s.includes(`data-hk="${e}"`));r&&this.renderChildren(r,i),this.templates[i]=this.templates[i].replace(`data-hk="${e}"`,`data-hk="${e}" ${this.generateAttributes(o)}`);}),this.templates.join("")}normalizeProps(e){Object.entries(e).forEach(([o,r])=>{o===E||shared.isFunction(r)?delete e[o]:signal.isSignal(r)&&(e[o]=r.value);});}generateAttributes(e){return Object.entries(e).filter(([o,r])=>o!==E&&!shared.isFunction(r)).map(([o,r])=>`${o}="${shared.escape(String(r))}"`).join(" ")}renderChildren(e,o){e.forEach(([r])=>{C++;let i=this.renderChild(r);this.templates[o]+=i;});}renderChild(e){if(signal.isSignal(e))return `<!--1-${C}-->${e.value}<!$>`;if(shared.isFunction(e))return this.renderChild(e(this.props));if(O(e)){let o=e.mount();return shared.isFunction(o)?o(this.props):$(o)}else return `<!--1-${C}-->${e}<!$>`}};var Ne="area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr".split(",");function D(n){if(h(n)||n instanceof Node||O(n))return n;let t=shared.isFalsy(n)?"":String(n);return document.createTextNode(t)}function g(n,t,e=null){let o=h(e)?e.firstChild:e,r=u.isSSR;h(t)?t.mount(n,o):o&&!r?o.before(t):r||n.append(t);}function M(n){h(n)?n.unmount():n.parentNode&&n.remove();}function F(n,t,e){g(n,t,e),M(e);}function ee(n,t,e){t==="class"?Ee(n,e):t==="style"?ge(n,e):Te(n,t,e);}function Ee(n,t){typeof t=="string"?n.className=t:shared.isArray(t)?n.className=t.join(" "):t&&typeof t=="object"&&(n.className=Object.entries(t).reduce((e,[o,r])=>e+(r?` ${o}`:""),"").trim());}function ge(n,t){typeof t=="string"?n.style.cssText=t:t&&typeof t=="object"&&Object.entries(t).forEach(([o,r])=>{n.style.setProperty(shared.kebabCase(o),String(r));});}function Te(n,t,e){shared.isFalsy(e)?n.removeAttribute(t):e===!0?n.setAttribute(t,""):n instanceof HTMLInputElement&&t==="value"?n.value=String(e):n.setAttribute(t,String(e));}function te(n,t){if(n instanceof HTMLInputElement)switch(n.type){case"checkbox":return m(n,"change",()=>{t(!!n.checked);});case"date":return m(n,"change",()=>{t(n.value?n.value:"");});case"file":return m(n,"change",()=>{n.files&&t(n.files);});case"number":return m(n,"input",()=>{let e=Number.parseFloat(n.value);t(Number.isNaN(e)?"":String(e));});case"radio":return m(n,"change",()=>{t(n.checked?n.value:"");});case"text":return m(n,"input",()=>{t(n.value);})}if(n instanceof HTMLSelectElement)return m(n,"change",()=>{t(n.value);});if(n instanceof HTMLTextAreaElement)return m(n,"input",()=>{t(n.value);})}function m(n,t,e){return n.addEventListener(t,e),()=>n.removeEventListener(t,e)}function oe(n){return Ne.includes(n)?`<${n}/>`:`<${n}></${n}>`}function $(n){return signal.isSignal(n)?n.value:n}var y=class extends l{constructor(e,o,r){super();this.template=e;this.props=o;this.key=r;this.emitter=new Set;this.rootNode=null;this.trackMap=new Map;this.nodes=[];this.parent=null;this.before=null;this.key||(this.key=o&&o.key),this.proxyProps||(this.proxyProps=signal.shallowReactive(o||{}));}get firstChild(){var e,o;return (o=(e=this.rootNode)==null?void 0:e.firstChild)!=null?o:null}get isConnected(){var e,o;return (o=(e=this.rootNode)==null?void 0:e.isConnected)!=null?o:!1}mount(e,o){var r,i,s,c;if(this.parent=e,!shared.isFunction(this.template))throw new Error("Template must be a function");return this.isConnected?(i=(r=this.rootNode)==null?void 0:r.mount(e,o))!=null?i:[]:(this.initRef(),this.rootNode=this.template(signal.useReactive(this.proxyProps,[E])),this.nodes=(c=(s=this.rootNode)==null?void 0:s.mount(e,o))!=null?c:[],this.callMountHooks(),this.patchProps(this.props),this.removeRef(),this.nodes)}unmount(){var e;this.callLifecycleHooks("destroy"),this.cleanup(),(e=this.rootNode)==null||e.unmount(),this.resetState(),this.key&&k.delete(this.key);}resetState(){this.rootNode=null,this.proxyProps={},this.nodes=[],this.parent=null;}callLifecycleHooks(e){this.hooks[e].forEach(o=>o());}callMountHooks(){this.hooks.mounted.forEach(e=>e());}callDestroyHooks(){this.hooks.destroy.forEach(e=>e());}clearEmitter(){for(let e of this.emitter)e();this.emitter.clear();}inheritNode(e){if(Object.assign(this.proxyProps,e.proxyProps),this.rootNode=e.rootNode,this.trackMap=e.trackMap,this.hooks=e.hooks,shared.hasChanged(e.props,this.props)){let o=this.props;this.props=e.props,this.patchProps(o);}}getNodeTrack(e){let o=this.trackMap.get(e);return o||(o={cleanup:()=>{}},this.trackMap.set(e,o)),o.cleanup(),o}patchProps(e){var o;if(e){for(let[r,i]of Object.entries(e))shared.startsWith(r,R)&&((o=this.rootNode)!=null&&o.firstChild)?this.patchEventListener(r,i):r===H?this.patchRef(i):shared.startsWith(r,w)?this.patchUpdateHandler(r,i):r!==E&&this.patchNormalProp(r,i);this.props=e;}}patchEventListener(e,o){let r=e.slice(2).toLowerCase(),i=m(this.rootNode.nodes[0],r,o);this.emitter.add(i);}patchRef(e){var o,r;e.value=(r=(o=this.rootNode)==null?void 0:o.firstChild)!=null?r:null;}patchUpdateHandler(e,o){this.proxyProps[e]=$(o);}patchNormalProp(e,o){let r=this.getNodeTrack(e);r.cleanup=signal.useEffect(()=>{this.proxyProps[e]=shared.isFunction(o)?o():o;});}cleanup(){this.trackMap.forEach(e=>{var o;return (o=e.cleanup)==null?void 0:o.call(e)}),this.trackMap.clear(),this.emitter.forEach(e=>e()),this.emitter.clear();}};function ie(n,t,e,o){let r=new Map,i=Array.from(t.values());if(i.length&&e.length===0)return Ce(n,i,o),r;let s=[],c=Me(e),a=0;for(let[d,p]of e.entries()){let f=i[a],v=S(f,d);for(;f&&!c.has(v);)M(f),t.delete(v),f=i[++a],v=S(f,d);let V=S(p,d),X=t.get(V);if(X&&(p=be(n,X,p)),f)if(f===X)a++;else {let Y=document.createComment("");g(n,Y,f),s.push([Y,p]);}else g(n,p,o);r.set(V,p);}return s.forEach(([d,p])=>{F(n,p,d);}),t.forEach((d,p)=>{d.isConnected&&!r.has(p)&&M(d);}),r}function Ce(n,t,e){if(n.childNodes.length===t.length+(e?1:0))n.innerHTML="",e&&g(n,e);else {let o=document.createRange(),r=t[0],i=h(r)?r.firstChild:r;o.setStartBefore(i),e?o.setEndBefore(e):o.setEndAfter(n),o.deleteContents();}t.forEach(o=>{h(o)&&o.unmount();});}function be(n,t,e){return t===e?t:h(t)&&h(e)&&t.template===e.template?(e.inheritNode(t),e):t instanceof Text&&e instanceof Text?(t.textContent!==e.textContent&&(t.textContent=e.textContent),t):(F(n,e,t),e)}function Me(n){let t=new Map;for(let[e,o]of n.entries()){let r=S(o,e);t.set(r,o);}return t}function S(n,t){if(h(n)){let e=n.key;if(e!=null)return String(e)}return `_$${t}$`}var x=class{constructor(t,e,o){this.template=t;this.props=e;this.key=o;this.treeMap=new Map;this.mounted=!1;this.nodes=[];this.trackMap=new Map;this.bindValueKeys=[];this.parent=null;u.isSSR&&(this.componentIndex=W(this.template));}get firstChild(){var t;return (t=this.nodes[0])!=null?t:null}get isConnected(){return this.mounted}addEventListener(){}removeEventListener(){}mount(t,e){var i;if(this.parent=t,this.isConnected)return this.nodes.forEach(s=>g(t,s,e)),this.nodes;shared.isArray(this.template)&&(this.template=P(this.template.join("")));let o=this.template.content.cloneNode(!0),r=o.firstChild;return (i=r==null?void 0:r.hasAttribute)!=null&&i.call(r,"_svg_")&&(r.remove(),r.childNodes.forEach(s=>{o.append(s);})),this.nodes=Array.from(o.childNodes),u.isSSR?this.mapSSGNodeTree(t):this.mapNodeTree(t,o),g(t,o,e),this.patchProps(this.props),this.mounted=!0,this.nodes}unmount(){this.trackMap.forEach(t=>{t.cleanup&&t.cleanup();}),this.trackMap.clear(),this.treeMap.clear(),this.nodes.forEach(t=>M(t)),this.nodes=[],this.mounted=!1,this.key&&k.delete(this.key);}inheritNode(t){this.mounted=t.mounted,this.nodes=t.nodes,this.trackMap=t.trackMap,this.treeMap=t.treeMap;let e=this.props;this.props=t.props,this.patchProps(e);}mapSSGNodeTree(t){this.treeMap.set(0,t),this.walkNodeTree(t,this.handleSSGNode.bind(this));}mapNodeTree(t,e){let o=1;this.treeMap.set(0,t);let r=[t],i=s=>{s.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&(this.treeMap.set(o++,s),r.push(s));};this.walkNodeTree(e,i);}walkNodeTree(t,e){t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&e(t);let o=t.firstChild;for(;o;)this.walkNodeTree(o,e),o=o.nextSibling;}handleSSGNode(t){var e;if(t.nodeType===Node.COMMENT_NODE){let[o,r]=((e=t.textContent)==null?void 0:e.split("-"))||[];if(0===+o&&+r===this.componentIndex){let i=t.nextSibling;this.treeMap.set(+r,i);}}else if(t.nodeType!==Node.TEXT_NODE){let{ci:o="-1",hk:r}=(t==null?void 0:t.dataset)||{};r&&+o===this.componentIndex&&this.treeMap.set(+r,t);}}patchProps(t){t&&(Object.entries(t).forEach(([e,o])=>{let r=Number(e),i=this.treeMap.get(r);i&&this.patchProp(e,i,o,r===0);}),this.props=t);}patchProp(t,e,o,r){o&&Object.entries(o).forEach(([i,s])=>{if(i===E&&s)this.patchChildren(t,e,s,r);else if(i===H)o[i].value=e;else if(shared.startsWith(i,R))this.patchEventListener(t,e,i,s);else {if(this.bindValueKeys.includes(i))return;let c=this.getBindUpdateValue(o,t,i);this.patchAttribute(t,e,i,s,c);}});}getBindUpdateValue(t,e,o){let r=`${w}${shared.capitalize(o)}`;if(r&&t[r]&&shared.isFunction(t[r]))return this.bindValueKeys.push(r),t[r]}patchChildren(t,e,o,r){if(shared.isArray(o))o.filter(Boolean).forEach((i,s)=>{var v;let[c,a]=shared.isArray(i)?i:[i,null],d=shared.isNil(a)?null:(v=this.treeMap.get(a))!=null?v:null,p=`${t}:${E}:${s}`,f=this.getNodeTrack(p,!0,r);this.patchChild(f,e,c,d);});else {let i=`${t}:${E}:0`,s=this.getNodeTrack(i,!0,r);this.patchChild(s,e,o,null);}}patchEventListener(t,e,o,r){let i=o.slice(2).toLowerCase(),s=this.getNodeTrack(`${t}:${o}`);s.cleanup=m(e,i,r);}patchAttribute(t,e,o,r,i){let s=this.getNodeTrack(`${t}:${o}`),c=signal.shallowSignal(),a=signal.useEffect(()=>{c.value=signal.isSignal(r)||signal.isComputed(r)?r.value:r,ee(e,o,c.value);}),d;i&&shared.isHTMLElement(e)&&(d=te(e,p=>{i(p);})),s.cleanup=()=>{a&&a(),d&&d();};}getNodeTrack(t,e,o){let r=this.trackMap.get(t);return r||(r={cleanup:()=>{}},e&&(r.lastNodes=new Map),o&&(r.isRoot=!0),this.trackMap.set(t,r)),r.cleanup&&r.cleanup(),r}patchChild(t,e,o,r){shared.isFunction(o)?t.cleanup=signal.useEffect(()=>{let i=shared.coerceArray(o()).map(D);u.isSSR?t.lastNodes=this.reconcileChildren(e,i,r):t.lastNodes=ie(e,t.lastNodes,i,r);}):shared.coerceArray(o).forEach((i,s)=>{let c=D(i),a=S(c,s);u.isSSR?t.lastNodes=this.reconcileChildren(e,[c],r):(t.lastNodes.set(a,c),g(e,c,r));});}reconcileChildren(t,e,o){let r=new Map,i=Array.from(t.childNodes).filter(s=>{var c,a;return s.nodeType===Node.TEXT_NODE&&((c=s.previousSibling)==null?void 0:c.nodeType)===Node.COMMENT_NODE&&((a=s.nextSibling)==null?void 0:a.nodeType)===Node.COMMENT_NODE});return e.forEach((s,c)=>{let a=S(s,c);s.nodeType===Node.TEXT_NODE?i.forEach(d=>{s.textContent===d.textContent&&t.replaceChild(s,d);}):g(t,s,o),r.set(a,s);}),r}};var k=new Map;function I(n,t,e={},o){if(o){let i=k.get(o);if(i)return i}typeof t=="string"&&(t=P(t));let r=new n(t,e,o);return o&&r instanceof y&&k.set(o,r),r}function j(n,t={},e){if(n===A)return de(n,t);if(shared.isString(n)){let o=oe(n),r={[B]:t};return I(x,o,r,e)}return shared.isFunction(n)?I(y,n,t,e):I(x,n,t,e)}function $e(n){return n instanceof y}function h(n){return n instanceof y||n instanceof x}function P(n){let t=document.createElement("template");return t.innerHTML=n,t}function de(n,t){let e=t.children?{[U]:{children:Array.isArray(t.children)?t.children.filter(Boolean):[t.children]}}:t,o=n===A?P(A):n;return I(x,o,e)}function Ie(n){l.ref&&l.ref.addHook("mounted",n);}function je(n){l.ref&&l.ref.addHook("destroy",n);}function Ke(n,t){l.ref&&l.ref.setContext(n,t);}function Xe(n,t){var e;return (e=l.ref&&l.ref.getContext(n))!=null?e:t}function Ge(n,t){u.setSSG();let o=new b(n,t||{}).mount();return u.setClient(),o}function De(n,t){let e=typeof t=="string"?document.querySelector(t):t;if(!e)throw new Error(`Could not find container: ${t}`);u.setSSR(),j(n).mount(e),u.setClient();}function Fe(n,t){return u.isSSG?new b(n,t):j(n,t)}exports.Fragment=de;exports.h=j;exports.hydrate=De;exports.inject=Xe;exports.isComponent=$e;exports.isJsxElement=h;exports.onDestroy=je;exports.onMount=Ie;exports.provide=Ke;exports.renderToString=Ge;exports.ssg=Fe;exports.template=P;//# sourceMappingURL=template.cjs.js.map
1
+ 'use strict';var shared=require('@estjs/shared'),signals=require('@estjs/signals');var Et=Object.defineProperty;var De=Object.getOwnPropertySymbols;var xt=Object.prototype.hasOwnProperty,_t=Object.prototype.propertyIsEnumerable;var we=(e,t,o)=>t in e?Et(e,t,{enumerable:true,configurable:true,writable:true,value:o}):e[t]=o,K=(e,t)=>{for(var o in t||(t={}))xt.call(t,o)&&we(e,o,t[o]);if(De)for(var o of De(t))_t.call(t,o)&&we(e,o,t[o]);return e};var Z=(e,t,o)=>new Promise((n,r)=>{var s=a=>{try{c(o.next(a));}catch(u){r(u);}},i=a=>{try{c(o.throw(a));}catch(u){r(u);}},c=a=>a.done?n(a.value):Promise.resolve(a.value).then(s,i);c((o=o.apply(e,t)).next());});var M=null,vt=0;function N(){return M}function Le(e){M=e;}function ee(e=M){let t={id:++vt,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(t)),t}function D(e,t){let o=M;M=e;try{return t()}finally{M=o;}}function j(e){var t,o,n,r,s;if(!(!e||e.isDestroyed)){if(e.children)for(;e.children.size>0;){let i=e.children.values().next().value;i&&j(i);}if(e.onDestroy){for(let i of e.onDestroy)try{i();}catch(c){}e.onDestroy.clear();}if(e.cleanup){for(let i of e.cleanup)try{i();}catch(c){}e.cleanup.clear();}(t=e.parent)!=null&&t.children&&e.parent.children.delete(e),(o=e.children)==null||o.clear(),(n=e.provides)==null||n.clear(),(r=e.onMount)==null||r.clear(),(s=e.onUpdate)==null||s.clear(),Le(e.parent),e.parent=null,e.isDestroyed=true;}}function I(e){let t=M;t&&(t.cleanup||(t.cleanup=new Set),t.cleanup.add(e));}var Me="_$spread$";var Re="http://www.w3.org/2000/svg",te="http://www.w3.org/2000/xlink",oe="http://www.w3.org/2000/xmlns/";var ne=Symbol(""),re=Symbol(""),z=Symbol(""),ie=Symbol("");var He=1e3,Ke=new WeakMap;function Fe(e){let t=Ke.get(e);if(!t){let o=e.name||"anonymous",n=Oe(e.toString()).toString(36);t=`${o}_${n}`,Ke.set(e,t);}return t}function Oe(e){let t=0,o=e.length<100?e.length:100;for(let n=0;n<o;n++)t=Math.trunc((t<<5)-t+e.charCodeAt(n));return t<0?-t:t}var Ct=0;function ce(e){if(!shared.isFalsy(e)){if(shared.isString(e))return e.length<=He?e:`${e.slice(0,He-10)}_${Oe(e).toString(36)}`;if(shared.isNumber(e))return String(e);if(shared.isSymbol(e)){let t=Symbol.keyFor(e);if(t)return `_s.${t}`;let o=e.description;return o?`_s.${o}`:`${Ct++}`}return String(e)}}var se=Symbol("essor.key");function V(e,t){if(p(e)||!e||e.nodeType===Node.DOCUMENT_NODE)return;let o=ce(t);shared.isFalsy(o)?delete e[se]:e[se]=o;}function k(e){if(e)return p(e)?e.key:e[se]}function T(e){if(shared.isHTMLElement(e))return e;if(shared.isPrimitive(e)){let t=shared.isFalsy(e)?"":String(e);return document.createTextNode(t)}return e}function P(e,t){let o=k(e),n=k(t);if(o!==n)return false;let r=p(e),s=p(t);if(r&&s)return e.component===t.component;if(r!==s)return false;if(shared.isPrimitive(e)||shared.isPrimitive(t))return e===t;let i=e,c=t;return i.nodeType!==c.nodeType?false:i.nodeType===Node.ELEMENT_NODE?i.tagName===c.tagName:true}function ue(e,t){if(e===t)return true;if(shared.isNull(e)||shared.isNull(t)||!shared.isObject(e)||!shared.isObject(t)||shared.isArray(e)!==shared.isArray(t))return false;let o=e,n=t;for(let r in o)if(o[r]!==n[r])return false;for(let r in n)if(!(r in o))return false;return true}function x(e){if(e)try{if(p(e))e.destroy();else {let t=e;t.parentElement&&t.remove();}}catch(t){shared.error("Failed to remove node:",t);}}function y(e,t,o){if(!(!e||!t))try{let n=p(o)?o.firstChild:o;if(p(t)){t.mount(e,n);return}n?e.insertBefore(t,n):e.appendChild(t);}catch(n){shared.error("Failed to insert node:",n);}}function Y(e,t,o){if(!(!e||!t||!o||t===o))try{let n=p(o)?o.beforeNode:o.nextSibling;x(o),y(e,t,n);}catch(n){shared.error("Failed to replace node:",n);}}function _(e){if(e){if(p(e))return e.firstChild;if(!shared.isPrimitive(e))return e}}function Ye(e,t){if(p(e)||p(t))return;let o=k(e);o&&!k(t)&&V(t,o);}function w(e,t,o){if(o===t)return t;let n=shared.isHTMLElement(t);if(shared.isHTMLElement(o)&&n){if(o.isEqualNode(t))return t;if(t.tagName===o.tagName){let c=t.attributes,a=o.attributes;for(let u=c.length-1;u>=0;u--){let l=c[u].name;o.hasAttribute(l)||t.removeAttribute(l);}for(let u=0,l=a.length;u<l;u++){let f=a[u];t.getAttribute(f.name)!==f.value&&t.setAttribute(f.name,f.value);}return Ye(t,o),t}}if(shared.isTextNode(t)&&shared.isTextNode(o))return t.textContent!==o.textContent&&(t.textContent=o.textContent),Ye(t,o),t;let s=p(t),i=p(o);return s&&i&&t.component===o.component?o.update(t):(Y(e,o,t),o)}function Ge(e,t,o,n){let r=t.length,s=o.length;if(r===0&&s===0)return [];if(r===0){for(let i=0;i<s;i++)y(e,o[i],n);return o}if(s===0){for(let i=0;i<r;i++)x(t[i]);return []}if(r===1&&s===1){let i=t[0],c=o[0];return P(i,c)?(w(e,i,c),o[0]=i):Y(e,c,i),o}if(r===2&&s===2){let i=t[0],c=t[1],a=o[0],u=o[1];if(P(i,a)&&P(c,u))return w(e,i,a),w(e,c,u),o[0]=i,o[1]=c,o;if(P(i,u)&&P(c,a)){w(e,i,u),w(e,c,a);let l=_(c),f=_(i);return l&&f&&l.parentNode===e&&e.insertBefore(l,f),o[0]=c,o[1]=i,o}}return wt(e,t,o,n)}function wt(e,t,o,n){let r=0,s=0,i=t.length-1,c=o.length-1,a=t[0],u=t[i],l=o[0],f=o[c];for(;r<=i&&s<=c;)if(!a)a=t[++r];else if(!u)u=t[--i];else if(P(a,l))w(e,a,l),o[s]=a,a=t[++r],l=o[++s];else break;for(;r<=i&&s<=c;)if(!a)a=t[++r];else if(!u)u=t[--i];else if(P(u,f))w(e,u,f),o[c]=u,u=t[--i],f=o[--c];else break;if(r>i){if(s<=c){let m=c+1<o.length?_(o[c+1]):n;for(let S=s;S<=c;S++)y(e,o[S],m);}}else if(s>c)for(let m=r;m<=i;m++){let S=t[m];S&&x(S);}else Lt(e,t,o,r,i,s,c,n);return o}function Lt(e,t,o,n,r,s,i,c){let a=i-s+1,u;for(let h=s;h<=i;h++){let E=k(o[h]);E!==void 0&&(u||(u=Object.create(null)),u[E]=h);}let l=new Int32Array(a),f=false,m=0,S=0;for(let h=n;h<=r;h++){let E=t[h];if(!E)continue;if(S>=a){x(E);continue}let g,C=k(E);if(C!==void 0&&u&&C in u)g=u[C];else for(let H=s;H<=i;H++)if(l[H-s]===0&&C===void 0&&k(o[H])===void 0&&P(E,o[H])){g=H;break}g===void 0?x(E):(l[g-s]=h+1,g>=m?m=g:f=true,w(e,E,o[g]),o[g]=E,S++);}let A=f?Mt(l):[],R=A.length-1,b=c;for(let h=a-1;h>=0;h--){let E=s+h,g=o[E];if(l[h]===0)y(e,g,b),b=_(g)||b;else if(f)if(R<0||h!==A[R]){let C=_(g);C&&C.parentNode===e&&y(e,C,b),b=C||b;}else b=_(g)||b,R--;else b=_(g)||b;}}function Mt(e){let t=e.length;if(t===0)return [];if(t===1)return e[0]!==0?[0]:[];let o=[],n=new Int32Array(t),r,s,i,c,a;for(r=0;r<t;r++){let u=e[r];if(u!==0){if(s=o[o.length-1],o.length===0||e[s]<u){n[r]=s,o.push(r);continue}for(i=0,c=o.length-1;i<c;)a=i+c>>1,e[o[a]]<u?i=a+1:c=a;u<e[o[i]]&&(i>0&&(n[r]=o[i-1]),o[i]=r);}}for(i=o.length,c=o[i-1];i-- >0;)o[i]=c,c=n[c];return o}function v(e,t,o,n){e.addEventListener(t,o,n),I(()=>{e.removeEventListener(t,o,n);});}function Ot(e,t,o,n){shared.isHtmlInputElement(e)?Vt(e,n):shared.isHtmlSelectElement(e)?$t(e,n):shared.isHtmlTextAreaElement(e)&&v(e,"input",()=>{n(e.value);});}function Vt(e,t){switch(e.type){case "checkbox":v(e,"change",()=>{t(!!e.checked);});break;case "radio":v(e,"change",()=>{t(e.checked?e.value:"");});break;case "file":v(e,"change",()=>{t(e.files);});break;case "number":case "range":v(e,"input",()=>{t(e.value||"");});break;case "date":case "datetime-local":case "month":case "time":case "week":v(e,"change",()=>{t(e.value||"");});break;default:v(e,"input",()=>{t(e.value);});break}}function $t(e,t){v(e,"change",()=>{if(e.multiple){let o=Array.from(e.options).filter(n=>n.selected).map(n=>n.value);t(o);}else t(e.value);});}function le(e,t,o){if(!e)return;let n=[],r=signals.effect(()=>{let s=shared.isFunction(t)?t():t,i=shared.coerceArray(s).map(c=>shared.isFunction(c)?c():c).flatMap(T);n=Ge(e,n,i,o);});return I(()=>{r(),n.forEach(s=>x(s)),n.length=0;}),n}function de(e,t){let o=t.length,n=new Array(o),r=new Set(t),s=1,i=0,c=a=>{if(a.nodeType!==Node.DOCUMENT_FRAGMENT_NODE){if(r.has(s)&&(n[i++]=a,i===o))return true;s++;}let u=a.firstChild;for(;u;){if(c(u))return true;u=u.nextSibling;}return false};return c(e),n}function Ut(e){let t=N();if(t){if(t.isMounted){try{e();}catch(o){}return}t.onMount||(t.onMount=new Set),t.onMount.add(e);}}function jt(e){let t=N();t&&(t.onUpdate||(t.onUpdate=new Set),t.onUpdate.add(e));}function zt(e){let t=N();t&&(t.onDestroy||(t.onDestroy=new Set),t.onDestroy.add(e));}function We(e){!e||e.isDestroyed||e.isMounted||(e.isMounted=true,e.onMount&&D(e,()=>{for(let t of e.onMount)try{t();}catch(o){}}));}function pe(e){if(!(!e||e.isDestroyed)&&e.onUpdate)for(let t of e.onUpdate)try{t();}catch(o){}}function me(e){Ut(e);}function ye(e){zt(e);}function Yt(e){jt(e);}var Qe;Qe=ne;var X=class{constructor(t,o={}){this.component=t;this.props=o;this.renderedNodes=[];this.scope=null;this.parentNode=void 0;this.beforeNode=void 0;this.reactiveProps={};this._propSnapshots={};this.state=0;this.parentScope=null;this[Qe]=true;this.key=o.key?ce(o.key):Fe(t),this.reactiveProps=signals.shallowReactive(K({},o)),this.parentScope=N();for(let n in o){let r=o[n];shared.isObject(r)&&(this._propSnapshots[n]=shared.isArray(r)?[...r]:K({},r));}}get isConnected(){return this.state===2}get firstChild(){for(let t of this.renderedNodes){let o=_(t);if(o)return o}}mount(t,o){var s;if(this.parentNode=t,this.beforeNode=o,this.state=1,this.renderedNodes.length>0){for(let i of this.renderedNodes)y(t,i,o);return this.state=2,this.renderedNodes}let n=(s=this.parentScope)!=null?s:N();this.scope=ee(n);let r=D(this.scope,()=>{var c;let i=this.component(this.reactiveProps);return shared.isFunction(i)&&(i=i(this.reactiveProps)),(signals.isSignal(i)||signals.isComputed(i))&&(i=i.value),(c=le(t,i,o))!=null?c:[]});return this.renderedNodes=r,D(this.scope,()=>{this.applyProps(this.props);}),this.state=2,this.scope&&We(this.scope),this.renderedNodes}update(t){return this.key!==t.key?(this.mount(t.parentNode,t.beforeNode),this):(this.parentNode=t.parentNode,this.beforeNode=t.beforeNode,this.scope=t.scope,this.parentScope=t.parentScope,this.renderedNodes=t.renderedNodes,this.state=t.state,this.reactiveProps=t.reactiveProps,this._propSnapshots=t._propSnapshots,this._updateReactiveProps(this.props),!this.isConnected&&this.parentNode?(this.mount(this.parentNode,this.beforeNode),this):(this.scope&&(D(this.scope,()=>{this.applyProps(this.props);}),pe(this.scope)),this))}_updateReactiveProps(t){for(let o in t){if(o==="key")continue;let n=t[o],r=this.reactiveProps[o];if(n===r&&!this._propSnapshots[o])continue;if(shared.isObject(n)){let i=this._propSnapshots[o];if(i&&ue(n,i))continue;let c=shared.isArray(n)?[...n]:K({},n);this.reactiveProps[o]=c,this._propSnapshots[o]=c;}else shared.hasChanged(n,r)&&(this.reactiveProps[o]=n,this._propSnapshots[o]&&delete this._propSnapshots[o]);}}unwrapRenderResult(t){return shared.isFunction(t)&&(t=t(this.reactiveProps)),(signals.isSignal(t)||signals.isComputed(t))&&(t=t.value),p(t)&&(t=t.mount(this.parentNode,this.beforeNode)),shared.isPromise(t)&&(t=t.then(o=>this.unwrapRenderResult(o))),t}forceUpdate(){if(this.state===5||!this.parentNode||!this.scope)return;let t=[...this.renderedNodes];try{D(this.scope,()=>{let o=this.component(this.reactiveProps);shared.isFunction(o)&&(o=o(this.reactiveProps)),(signals.isSignal(o)||signals.isComputed(o))&&(o=o.value);let n=shared.coerceArray(o),r=this._getAnchorNode();if(this.parentNode){for(let s of this.renderedNodes)x(s);for(let s of n)y(this.parentNode,s,r);this.renderedNodes=n;}}),this.scope&&pe(this.scope);}catch(o){throw this.renderedNodes=t,o}}_getAnchorNode(){if(this.beforeNode)return this.beforeNode;if(this.renderedNodes.length>0){let t=this.renderedNodes[this.renderedNodes.length-1],o=_(t);if(o)return o.nextSibling}}destroy(){if(this.state===4||this.state===5)return;this.state=4;let t=this.scope;t&&(j(t),this.scope=null);for(let o of this.renderedNodes)x(o);this.renderedNodes=[],this.parentNode=void 0,this.beforeNode=void 0,this.parentScope=null,this.reactiveProps={},this.props={},this.state=5;}applyProps(t){if(!t)return;let o=this.firstChild;for(let[n,r]of Object.entries(t))if(shared.startsWith(n,"on")){if(!o||!shared.isHTMLElement(o))return;let s=n.slice("on".length).toLowerCase();v(o,s,r);}else n==="ref"&&signals.isSignal(r)&&(r.value=o);this.props=t;}};function p(e){return !!e&&!!e[ne]}function $(e,t){return p(e)?e:new X(e,t)}function Ne(e){let t,o=()=>{let n=document.createElement("template");n.innerHTML=e;let r=n.content.firstChild;if(!r)throw new Error("Invalid template: empty content");return r};return ()=>(t||(t=o())).cloneNode(true)}function eo(e,t){let o=shared.isString(t)?document.querySelector(t):t;if(!o){shared.error(`Target element not found: ${t}`);return}o.innerHTML&&(shared.error(`Target element is not empty, it will be delete: ${t}`),o.innerHTML="");let r=p(e)?e:$(e);return r.mount(o),r}function Se(e,t){let o=N();o&&(o.provides||(o.provides=new Map),o.provides.set(e,t));}function Ee(e,t){let o=N();if(!o)return t;let n=o;for(;n;){if(n.provides){let r=n.provides.get(e);if(r)return r}n=n.parent;}return t}function xe(e,t){Object.defineProperty(e,"target",{configurable:true,value:t});}function nt(e,t,o){let n=e[`_$${o}`];if(n&&shared.isFunction(n)&&!e.disabled){let r=e[`${o}Data`];if(r?n.call(e,r,t):n.call(e,t),t.cancelBubble)return false}return e.host&&!shared.isString(e.host)&&!e.host._$host&&shared.isFunction(e.contains)&&e.contains(t.target)&&xe(t,e.host),true}function tt(e,t,o){let n=e;for(;nt(n,t,o)&&(n=n._$host||n.parentNode||n.host););return n}function oo(e){let t=e.target,o=`${e.type}`,n=e.target,r=e.currentTarget;if(Object.defineProperty(e,"currentTarget",{configurable:true,get(){return t||document}}),e.composedPath){let s=e.composedPath();xe(e,s[0]);for(let i=0;i<s.length-2&&(t=s[i],!!nt(t,e,o));i++){if(t._$host){t=t._$host,t=tt(t,e,o);break}if(t.parentNode===r)break}}else t=tt(t,e,o);xe(e,n);}var ot=Symbol("_$EVENTS");function no(e,t=window.document){let o=t,n=o[ot]||(o[ot]=new Set);for(let r of e)n.has(r)||(n.add(r),t.addEventListener(r,oo));}function ro(e,t){let o=new Set(t);return new Proxy(e,{get(n,r){if(!o.has(r))return Reflect.get(n,r)},ownKeys(n){return Reflect.ownKeys(n).filter(r=>!o.has(r))},getOwnPropertyDescriptor(n,r){if(!o.has(r))return Reflect.getOwnPropertyDescriptor(n,r)},has(n,r){return o.has(r)?false:Reflect.has(n,r)}})}var _e=false;function W(){_e=true;}function U(){_e=false;}function L(){return _e}var rt=0;function q(){return `${rt++}`}function B(){rt=0;}var st=/^\d+-\d+$/;function ct(e){return ()=>{if(!shared.isBrowser())return null;let t=q(),o=document.querySelector(`[data-hk="${t}"]`);return o||Ne(e)()}}function at(e,t){let o=e.dataset.hk;if(!o)return de(e,t);let n=[],r=e.querySelectorAll(`[data-idx^="${o}"]`);r.length>0&&n.push(...Array.from(r).filter(a=>{let u=a.dataset.idx;return u!==null&&st.test(u)}).map(a=>{let u=a.dataset.idx||"",[l,f]=u.split("-");return {hk:l,idx:f,node:a}}));let s=[],i=a=>{if(a.nodeType===Node.COMMENT_NODE&&a.textContent&&st.test(a.textContent)){let[l,f]=a.textContent.split("-");s.push({hk:l,idx:f,node:a});}let u=a.firstChild;for(;u;)i(u),u=u.nextSibling;};i(e),n.push(...s);let c=[e];return t.forEach(a=>{let u=n.find(l=>l.idx===String(a));u&&c.push(u.node);}),c}function ut(e,t){W(),B();try{let o=shared.isString(t)?document.querySelector(t):t;if(!o){shared.error("Hydration error: Root element not found");return}let n=$(e);return n.mount(o),U(),n}catch(o){shared.error("Hydration error:",o),U();return}}function ft(e,t,o,n=false){if(t===o||L())return;let r=J(o),s=J(t);r&&s===r||(r?n?e.setAttribute("class",r):e.className=r:e.removeAttribute("class"));}function J(e){return shared.normalizeClassName(e)}var lt=/\s*!important$/,lo=["Webkit","Moz","ms"],ve={};function pt(e,t,o){let n=e.style,r=shared.isString(o);if(!L()){if(o&&r){t!==o&&(n.cssText=o);return}if(!o){t&&e.removeAttribute("style");return}if(t&&!shared.isString(t))for(let s in t)(!o||o[s]==null)&&O(n,s,"");else if(t&&shared.isString(t)){let s=t.split(";");for(let i of s){let c=i.indexOf(":");if(c>0){let a=i.slice(0,c).trim();o&&shared.isObject(o)&&o[a]==null&&O(n,a,"");}}}if(o&&!shared.isString(o))for(let s in o){let i=o[s];(!t||shared.isString(t)||t[s]!==i)&&i!=null&&O(n,s,i);}}}function O(e,t,o){if(shared.isArray(o)){for(let r of o)O(e,t,r);return}if((o==null||o==="")&&(o=""),t.startsWith("--")){e.setProperty(t,o);return}let n=po(e,t);shared.isString(o)&&lt.test(o)?e.setProperty(shared.camelCase(n),o.replace(lt,""),"important"):e[n]=o;}function po(e,t){let o=ve[t];if(o)return o;let n=shared.camelCase(t);if(n!=="filter"&&n in e)return ve[t]=n;n=shared.capitalize(n);for(let r of lo){let s=r+n;if(s in e)return ve[t]=s}return t}function Ae(e,t,o,n){if(t==="key"){n==null?V(e,void 0):V(e,String(n));return}if(t===Me){Object.keys(n).forEach(f=>{Ae(e,f,o==null?void 0:o[f],n==null?void 0:n[f]);});return}if(L())return;let r=(e==null?void 0:e.namespaceURI)===Re,s=r&&t.startsWith("xlink:"),i=r&&t.startsWith("xmlns:"),c=shared.isSpecialBooleanAttr(t)||shared.isBooleanAttr(t);if(o===n)return;let a=t.toLowerCase();if(a.length>2&&a.charCodeAt(0)===111&&a.charCodeAt(1)===110||a==="innerhtml")return;if(n==null){if(s)e.removeAttributeNS(te,t.slice(6));else if(i){let f=t.slice(6);e.removeAttributeNS(oe,f);}else e.removeAttribute(t);return}if(s){e.setAttributeNS(te,t,String(n));return}if(i){e.setAttributeNS(oe,t,String(n));return}if(c){shared.includeBooleanAttr(n)?e.setAttribute(t,""):e.removeAttribute(t);return}let u=shared.isSymbol(n)?String(n):n;if((a==="href"||a==="src"||a==="xlink:href")&&shared.isString(u)){let f=u.trim().toLowerCase();if(f.startsWith("javascript:")||f.startsWith("data:"))return}if(r)e.setAttribute(t,String(u));else if(t in e)try{e[t]=u;}catch(f){e.setAttribute(t,String(u));}else e.setAttribute(t,String(u));}function mt(e,t,o,n){if(!(n!=null&&n.delegate))return e.addEventListener(t,o,n),()=>e.removeEventListener(t,o,n);let r=n.delegate,s=c=>{let a=c.target;(a.matches(r)||a.closest(r))&&o.call(e,c);},i=K({},n);return i.delegate=void 0,e.addEventListener(t,s,i),()=>{e.removeEventListener(t,s,i);}}function be(e){if(!(e!=null&&e.children))return shared.error("Fragment component requires children"),null;let{children:t}=e;return t}be[re]=true;function yt(e){return !!e&&!!e[re]}function Pe(e){let t=document.createComment("portal");t[z]=true;let o=e.children;if(o){let n=shared.isArray(o)?o:[o],r=[];me(()=>{let s=shared.isString(e.target)?document.querySelector(e.target):e.target;s&&(n.forEach(i=>{if(i!=null){let c=T(i);c&&(y(s,c),r.push(c));}}),I(()=>{r.forEach(i=>{!shared.isString(i)&&i.parentNode===s&&s.removeChild(i);});}));});}return t}Pe[z]=true;function gt(e){return !!e&&!!e[z]}var ke=Symbol("SuspenseContext");function Te(e){if(shared.isUndefined(document)){let f=e.fallback;return f?String(f||""):""}let t=document.createElement("div");t.style.display="contents";let o=true,n=0,r=false,s=null,i=()=>{if(!r){for(r=true;t.firstChild;)t.removeChild(t.firstChild);if(e.fallback!=null){let f=T(e.fallback);f&&y(t,f);}}},c=()=>{if(!(!r||!(s||e.children!=null&&!shared.isPromise(e.children)))){for(r=false;t.firstChild;)t.removeChild(t.firstChild);s?a(s):e.children!=null&&!shared.isPromise(e.children)&&a(e.children);}},a=f=>{for(;t.firstChild;)t.removeChild(t.firstChild);if(f==null)return;let m=N();if((shared.isArray(f)?f:[f]).forEach(A=>{if(A!=null){p(A)&&(A.parentContext=m);let R=T(A);R&&y(t,R);}}),r){for(;t.firstChild;)t.removeChild(t.firstChild);if(e.fallback!=null){let A=T(e.fallback);A&&y(t,A);}}},u={register:f=>{n++,i(),f.then(()=>{o&&(n--,n===0&&c());}).catch(m=>{o&&(n--,n===0&&c());});},increment:()=>{n++,i();},decrement:()=>{n--,n===0&&c();}};Se(ke,u);let l=e.children;return shared.isPromise(l)?(l.then(f=>{s=f;}).catch(()=>{}),u.register(l)):l!=null?a(l):i(),ye(()=>{for(o=false;t.firstChild;)t.removeChild(t.firstChild);}),t}Te[ie]=true;function Nt(e){return !!e&&!!e[ie]}function St(e,t){let o=signals.signal(t==null?void 0:t.initialValue),n=signals.signal(true),r=signals.signal(null),s=signals.signal("pending"),i=0,c=null,a=()=>Z(null,null,function*(){let f=++i;n.value=true,s.value="pending",r.value=null;try{let m=e();c=m.then(()=>{}).catch(()=>{});let S=yield m;f===i&&(o.value=S,s.value="ready",n.value=!1);}catch(m){f===i&&(r.value=m instanceof Error?m:new Error(String(m)),s.value="errored",n.value=false);}});a();let u=(()=>{if(n.value&&c){let f=Ee(ke,null);f&&f.register(c);}return o.value});return u.loading=n,u.error=r,u.state=s,[u,{mutate:f=>{o.value=f,s.value="ready",n.value=false,r.value=null;},refetch:()=>Z(null,null,function*(){yield a();})}]}
2
+ exports.Component=X;exports.Fragment=be;exports.Portal=Pe;exports.Suspense=Te;exports.addEvent=mt;exports.addEventListener=v;exports.bindElement=Ot;exports.createApp=eo;exports.createComponent=$;exports.createResource=St;exports.createScope=ee;exports.delegateEvents=no;exports.disposeScope=j;exports.endHydration=U;exports.getActiveScope=N;exports.getFirstDOMNode=_;exports.getHydrationKey=q;exports.getRenderedElement=ct;exports.hydrate=ut;exports.inject=Ee;exports.insert=le;exports.insertNode=y;exports.isComponent=p;exports.isFragment=yt;exports.isHydrating=L;exports.isPortal=gt;exports.isSameNode=P;exports.isSuspense=Nt;exports.mapNodes=de;exports.mapSSRNodes=at;exports.normalizeClass=J;exports.normalizeNode=T;exports.omitProps=ro;exports.onCleanup=I;exports.onDestroy=ye;exports.onMount=me;exports.onUpdate=Yt;exports.patchAttr=Ae;exports.patchClass=ft;exports.patchStyle=pt;exports.provide=Se;exports.removeNode=x;exports.replaceNode=Y;exports.resetHydrationKey=B;exports.runWithScope=D;exports.setActiveScope=Le;exports.setStyle=O;exports.shallowCompare=ue;exports.startHydration=W;exports.template=Ne;//# sourceMappingURL=template.cjs.js.map
7
3
  //# sourceMappingURL=template.cjs.js.map