@estjs/template 0.0.14 → 0.0.15-beta.1

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.
@@ -1,7 +1,8 @@
1
- import {isString,isFunction,isArray,escape,hasChanged,startsWith,capitalize,isNil,isHTMLElement,coerceArray,isFalsy,kebabCase}from'@estjs/shared';import {isSignal,shallowReactive,useReactive,useEffect,shallowSignal,isComputed}from'@estjs/signal';/**
2
- * @estjs/template v0.0.14
1
+ import {isObject,isFunction,hasChanged,startsWith,isHTMLElement,isString,error,isNil,isArray,camelCase,capitalize,isSpecialBooleanAttr,isBooleanAttr,includeBooleanAttr,isSymbol,isUndefined,isPromise,coerceArray,isFalsy,isNumber,isPrimitive,kebabCase}from'@estjs/shared';export{escapeHTML}from'@estjs/shared';import {shallowReactive,isSignal,isComputed,signal,effect}from'@estjs/signals';/**
2
+ * @estjs/template v0.0.15-beta.1
3
3
  * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
4
4
  * @license MIT
5
5
  **/
6
- var w="on",A="update",g="children",H="",B="0",q="1";var _="ref",O=" __PLACEHOLDER__ ";var D=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 D,z=new Map;function W(n,t){z.set(n,{index:t});}function Q(n){var t;return (t=z.get(n))==null?void 0:t.index}var y=class y{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 y.context[t]}setContext(t,e){y.context[t]=e;}initRef(){y.ref=this;}removeRef(){y.ref=null;}clearHooks(){Object.values(this.hooks).forEach(t=>t.clear());}};y.ref=null,y.context={};var l=y;function $(n){return n instanceof M}var b=1,M=class extends l{constructor(e,o={},r){super();this.template=e;this.props=o;this.key=r;W(e,b),this.templates=this.processTemplate();}processTemplate(){if(isArray(this.template)){let e=this.template.join(O);return this.processHtmlString(e).split(O)}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="${b}"${a||""}>`):i&&i.replace(O,"").trim()?`<!--0-${b}-->${i}<!$>`:o)}mount(){this.initRef();let e=this.render();return this.removeRef(),e}render(){if(isFunction(this.template)){let e=this.template(this.props);return $(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===g||isFunction(r)?delete e[o]:isSignal(r)&&(e[o]=r.value);});}generateAttributes(e){return Object.entries(e).filter(([o,r])=>o!==g&&!isFunction(r)).map(([o,r])=>`${o}="${escape(String(r))}"`).join(" ")}renderChildren(e,o){e.forEach(([r])=>{b++;let i=this.renderChild(r);this.templates[o]+=i;});}renderChild(e){if(isSignal(e))return `<!--1-${b}-->${e.value}<!$>`;if(isFunction(e))return this.renderChild(e(this.props));if($(e)){let o=e.mount();return isFunction(o)?o(this.props):I(o)}else return `<!--1-${b}-->${e}<!$>`}};var Ee="area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr".split(",");function F(n){if(h(n)||n instanceof Node||$(n))return n;let t=isFalsy(n)?"":String(n);return document.createTextNode(t)}function T(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 k(n){h(n)?n.unmount():n.parentNode&&n.remove();}function J(n,t,e){T(n,t,e),k(e);}function te(n,t,e){t==="class"?ge(n,e):t==="style"?Te(n,e):ye(n,t,e);}function ge(n,t){typeof t=="string"?n.className=t:isArray(t)?n.className=t.join(" "):t&&typeof t=="object"&&(n.className=Object.entries(t).reduce((e,[o,r])=>e+(r?` ${o}`:""),"").trim());}function Te(n,t){typeof t=="string"?n.style.cssText=t:t&&typeof t=="object"&&Object.entries(t).forEach(([o,r])=>{n.style.setProperty(kebabCase(o),String(r));});}function ye(n,t,e){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 oe(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 ne(n){return Ee.includes(n)?`<${n}/>`:`<${n}></${n}>`}function I(n){return isSignal(n)?n.value:n}var S=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=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,!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(useReactive(this.proxyProps,[g])),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&&L.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,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))startsWith(r,w)&&((o=this.rootNode)!=null&&o.firstChild)?this.patchEventListener(r,i):r===_?this.patchRef(i):startsWith(r,A)?this.patchUpdateHandler(r,i):r!==g&&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]=I(o);}patchNormalProp(e,o){let r=this.getNodeTrack(e);r.cleanup=useEffect(()=>{this.proxyProps[e]=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 se(n,t,e,o){let r=new Map,i=Array.from(t.values());if(i.length&&e.length===0)return be(n,i,o),r;let s=[],c=ke(e),a=0;for(let[d,p]of e.entries()){let f=i[a],C=x(f,d);for(;f&&!c.has(C);)k(f),t.delete(C),f=i[++a],C=x(f,d);let Y=x(p,d),G=t.get(Y);if(G&&(p=Me(n,G,p)),f)if(f===G)a++;else {let U=document.createComment("");T(n,U,f),s.push([U,p]);}else T(n,p,o);r.set(Y,p);}return s.forEach(([d,p])=>{J(n,p,d);}),t.forEach((d,p)=>{d.isConnected&&!r.has(p)&&k(d);}),r}function be(n,t,e){if(n.childNodes.length===t.length+(e?1:0))n.innerHTML="",e&&T(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 Me(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):(J(n,e,t),e)}function ke(n){let t=new Map;for(let[e,o]of n.entries()){let r=x(o,e);t.set(r,o);}return t}function x(n,t){if(h(n)){let e=n.key;if(e!=null)return String(e)}return `_$${t}$`}var v=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=Q(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=>T(t,s,e)),this.nodes;isArray(this.template)&&(this.template=R(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),T(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=>k(t)),this.nodes=[],this.mounted=!1,this.key&&L.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===g&&s)this.patchChildren(t,e,s,r);else if(i===_)o[i].value=e;else if(startsWith(i,w))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=`${A}${capitalize(o)}`;if(r&&t[r]&&isFunction(t[r]))return this.bindValueKeys.push(r),t[r]}patchChildren(t,e,o,r){if(isArray(o))o.filter(Boolean).forEach((i,s)=>{var C;let[c,a]=isArray(i)?i:[i,null],d=isNil(a)?null:(C=this.treeMap.get(a))!=null?C:null,p=`${t}:${g}:${s}`,f=this.getNodeTrack(p,!0,r);this.patchChild(f,e,c,d);});else {let i=`${t}:${g}: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=shallowSignal(),a=useEffect(()=>{c.value=isSignal(r)||isComputed(r)?r.value:r,te(e,o,c.value);}),d;i&&isHTMLElement(e)&&(d=oe(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){isFunction(o)?t.cleanup=useEffect(()=>{let i=coerceArray(o()).map(F);u.isSSR?t.lastNodes=this.reconcileChildren(e,i,r):t.lastNodes=se(e,t.lastNodes,i,r);}):coerceArray(o).forEach((i,s)=>{let c=F(i),a=x(c,s);u.isSSR?t.lastNodes=this.reconcileChildren(e,[c],r):(t.lastNodes.set(a,c),T(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=x(s,c);s.nodeType===Node.TEXT_NODE?i.forEach(d=>{s.textContent===d.textContent&&t.replaceChild(s,d);}):T(t,s,o),r.set(a,s);}),r}};var L=new Map;function j(n,t,e={},o){if(o){let i=L.get(o);if(i)return i}typeof t=="string"&&(t=R(t));let r=new n(t,e,o);return o&&r instanceof S&&L.set(o,r),r}function K(n,t={},e){if(n===H)return le(n,t);if(isString(n)){let o=ne(n),r={[q]:t};return j(v,o,r,e)}return isFunction(n)?j(S,n,t,e):j(v,n,t,e)}function Ie(n){return n instanceof S}function h(n){return n instanceof S||n instanceof v}function R(n){let t=document.createElement("template");return t.innerHTML=n,t}function le(n,t){let e=t.children?{[B]:{children:Array.isArray(t.children)?t.children.filter(Boolean):[t.children]}}:t,o=n===H?R(H):n;return j(v,o,e)}function je(n){l.ref&&l.ref.addHook("mounted",n);}function Ke(n){l.ref&&l.ref.addHook("destroy",n);}function Xe(n,t){l.ref&&l.ref.setContext(n,t);}function Ge(n,t){var e;return (e=l.ref&&l.ref.getContext(n))!=null?e:t}function De(n,t){u.setSSG();let o=new M(n,t||{}).mount();return u.setClient(),o}function Fe(n,t){let e=typeof t=="string"?document.querySelector(t):t;if(!e)throw new Error(`Could not find container: ${t}`);u.setSSR(),K(n).mount(e),u.setClient();}function Je(n,t){return u.isSSG?new M(n,t):K(n,t)}export{le as Fragment,K as h,Fe as hydrate,Ge as inject,Ie as isComponent,h as isJsxElement,Ke as onDestroy,je as onMount,Xe as provide,De as renderToString,Je as ssg,R as template};//# sourceMappingURL=template.esm.js.map
6
+ var ct=Object.defineProperty;var Se=Object.getOwnPropertySymbols;var at=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable;var Ee=(e,t,n)=>t in e?ct(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,K=(e,t)=>{for(var n in t||(t={}))at.call(t,n)&&Ee(e,n,t[n]);if(Se)for(var n of Se(t))ut.call(t,n)&&Ee(e,n,t[n]);return e};var F=(e,t,n)=>new Promise((r,o)=>{var i=c=>{try{a(n.next(c));}catch(u){o(u);}},s=c=>{try{a(n.throw(c));}catch(u){o(u);}},a=c=>c.done?r(c.value):Promise.resolve(c.value).then(i,s);a((n=n.apply(e,t)).next());});var M=null,Ae=[],ft=0;function Ce(e=null){let t={id:++ft,parent:e,provides:new Map,cleanup:new Set,mount:new Set,update:new Set,destroy:new Set,isMount:false,isDestroy:false,children:new Set};return e&&e.children.add(t),t}function S(){return M}function $(e){M&&Ae.push(M),M=e;}function X(){M=Ae.pop()||null;}function Z(e){if(!e||e.isDestroy)return;Array.from(e.children).forEach(Z),dt(e);}function dt(e){if(!(!e||e.isDestroy)){e.parent&&(e.parent.children.delete(e),e.parent=null);try{e.cleanup.forEach(t=>t()),e.cleanup.clear(),e.mount.clear(),e.update.clear(),e.destroy.clear(),e.provides.clear(),e.children.clear();}catch(t){error("Error during context cleanup:",t);}e.isDestroy=true;}}var b={mount:"mount",destroy:"destroy",update:"update"};function ee(e,t){let n=S();if(!n){error(`Cannot register ${e} hook outside component context`);return}if(!b[e]){error(`Invalid lifecycle type: ${e}`);return}if(e===b.mount&&n.isMount){try{t();}catch(r){error(`Error in ${e} hook:`,r);}return}n[e].add(t);}function O(e){let t=S();if(!t){error(`Cannot trigger ${e} hook outside component context`);return}let n=t[e];n!=null&&n.size&&n.forEach(r=>{try{r();}catch(o){}});}function te(e){ee(b.mount,e);}function ne(e){ee(b.destroy,e);}function mt(e){ee(b.update,e);}var ve="http://www.w3.org/2000/svg",re="http://www.w3.org/2000/xlink",oe="http://www.w3.org/2000/xmlns/",ie=/^\d+-\d+$/;var be=1e3,Te=new WeakMap;function Le(e){let t=Te.get(e);if(!t){let n=e.name||"anonymous",r=_e(e.toString()).toString(36);t=`${n}_${r}`,Te.set(e,t);}return t}function _e(e){let t=0,n=e.length<100?e.length:100;for(let r=0;r<n;r++)t=Math.trunc((t<<5)-t+e.charCodeAt(r));return t<0?-t:t}var gt=0;function ce(e){if(!isFalsy(e)){if(isString(e))return e.length<=be?e:`${e.slice(0,be-10)}_${_e(e).toString(36)}`;if(isNumber(e))return String(e);if(isSymbol(e)){let t=Symbol.keyFor(e);if(t)return `_s.${t}`;let n=e.description;return n?`_s.${n}`:`${gt++}`}return String(e)}}var se=Symbol("essor.key");function z(e,t){if(p(e)||!e||e.nodeType===Node.DOCUMENT_NODE)return;let n=ce(t);isFalsy(n)?delete e[se]:e[se]=n;}function L(e){if(e)return p(e)?e.key:e[se]}function T(e){if(e)try{if(p(e))e.destroy();else {let t=e;t.parentElement&&t.remove();}}catch(t){error("Failed to remove node:",t);}}function y(e,t,n=null){if(!(!e||!t))try{let r=p(n)?n.firstChild:n;if(p(t)){t.mount(e,r);return}r?e.insertBefore(t,r):e.appendChild(t);}catch(r){error("Failed to insert node:",r);}}function j(e,t,n){if(!(!e||!t||!n||t===n))try{y(e,t,n),T(n);}catch(r){error("Failed to replace node:",r);}}function w(e){return e?p(e)?e.firstChild:e:null}function _(e,t){let n=L(e),r=L(t);if(n!==r)return false;let o=p(e),i=p(t);if(o&&i)return e.component===t.component;if(o!==i)return false;let s=e,a=t;return s.nodeType!==a.nodeType?false:s.nodeType===Node.ELEMENT_NODE?s.tagName===a.tagName:true}function k(e){if(isHTMLElement(e))return e;if(isPrimitive(e)){let t=isFalsy(e)?"":String(e);return document.createTextNode(t)}return e}function Pe(e){return e instanceof HTMLInputElement}function Re(e){return e instanceof HTMLSelectElement}function we(e){return e instanceof HTMLTextAreaElement}function ue(e){return e instanceof Text}function De(e,t){if(e===t)return true;if(!e||!t||Array.isArray(e)!==Array.isArray(t))return false;for(let n in e)if(e[n]!==t[n])return false;for(let n in t)if(!(n in e))return false;return true}function He(e,t){if(p(e)||p(t))return;let n=L(e);n&&!L(t)&&z(t,n);}function P(e,t,n){if(n===t)return t;let r=isHTMLElement(t);if(isHTMLElement(n)&&r){if(n.isEqualNode(t))return t;if(t.tagName===n.tagName){let a=t.attributes,c=n.attributes;for(let u=a.length-1;u>=0;u--){let f=a[u].name;n.hasAttribute(f)||t.removeAttribute(f);}for(let u=0,f=c.length;u<f;u++){let l=c[u];t.getAttribute(l.name)!==l.value&&t.setAttribute(l.name,l.value);}return He(t,n),t}}if(ue(t)&&ue(n))return t.textContent!==n.textContent&&(t.textContent=n.textContent),He(t,n),t;let i=p(t),s=p(n);return i&&s&&t.component===n.component?n.update(t):(j(e,n,t),n)}function Ke(e,t,n,r){let o=t.length,i=n.length;if(o===0&&i===0)return [];if(o===0){let s=document.createDocumentFragment();for(let a=0;a<i;a++)y(s,n[a]);return y(e,s,r),n}if(i===0){for(let s=0;s<o;s++)T(t[s]);return []}if(o===1&&i===1){let s=t[0],a=n[0];return _(s,a)?(P(e,s,a),n[0]=s):j(e,a,s),n}if(o===2&&i===2){let s=t[0],a=t[1],c=n[0],u=n[1];if(_(s,c)&&_(a,u))return P(e,s,c),P(e,a,u),n[0]=s,n[1]=a,n;if(_(s,u)&&_(a,c)){P(e,s,u),P(e,a,c);let f=w(a),l=w(s);return f&&l&&f.parentNode===e&&e.insertBefore(f,l),n[0]=a,n[1]=s,n}}return Et(e,t,n,r)}function Et(e,t,n,r){let o=0,i=0,s=t.length-1,a=n.length-1,c=t[0],u=t[s],f=n[0],l=n[a];for(;o<=s&&i<=a;)if(!c)c=t[++o];else if(!u)u=t[--s];else if(_(c,f))P(e,c,f),n[i]=c,c=t[++o],f=n[++i];else break;for(;o<=s&&i<=a;)if(!c)c=t[++o];else if(!u)u=t[--s];else if(_(u,l))P(e,u,l),n[a]=u,u=t[--s],l=n[--a];else break;if(o>s){if(i<=a){let g=a+1<n.length?w(n[a+1]):r;for(let h=i;h<=a;h++)y(e,n[h],g);}}else if(i>a)for(let g=o;g<=s;g++){let h=t[g];h&&T(h);}else At(e,t,n,o,s,i,a,r);return n}function At(e,t,n,r,o,i,s,a){let c=s-i+1,u=n.length,f;for(let x=i;x<=s;x++){let N=L(n[x]);N!==void 0&&(f||(f=Object.create(null)),f[N]=x);}let l=new Int32Array(c),g=false,h=0,C=0;for(let x=r;x<=o;x++){let N=t[x];if(!N)continue;if(C>=c){T(N);continue}let E,R=L(N);if(R!==void 0&&f&&R in f)E=f[R];else for(let v=i;v<=s;v++)if(l[v-i]===0&&R===void 0&&L(n[v])===void 0&&_(N,n[v])){E=v;break}E===void 0?T(N):(l[E-i]=x+1,E>=h?h=E:g=true,P(e,N,n[E]),n[E]=N,C++);}let H=g?Ct(l):[],Q=H.length-1;for(let x=c-1;x>=0;x--){let N=i+x,E=n[N],R=N+1<u?w(n[N+1]):a;if(l[x]===0)y(e,E,R);else if(g)if(Q<0||x!==H[Q]){let v=w(E);v&&v.parentNode===e&&y(e,v,R);}else Q--;}}function Ct(e){let t=e.length;if(t===0)return [];if(t===1)return e[0]!==0?[0]:[];let n=[],r=new Int32Array(t),o,i,s,a,c;for(o=0;o<t;o++){let u=e[o];if(u!==0){if(i=n[n.length-1],n.length===0||e[i]<u){r[o]=i,n.push(o);continue}for(s=0,a=n.length-1;s<a;)c=s+a>>1,e[n[c]]<u?s=c+1:a=c;u<e[n[s]]&&(s>0&&(r[o]=n[s-1]),n[s]=o);}}for(s=n.length,a=n[s-1];s-- >0;)n[s]=a,a=r[a];return n}function A(e,t,n,r){e.addEventListener(t,n,r);let o=S();o&&o.cleanup.add(()=>{e.removeEventListener(t,n,r);});}function kt(e,t,n,r){if(Pe(e))switch(e.type){case "checkbox":A(e,"change",()=>{r(!!e.checked);});break;case "radio":A(e,"change",()=>{r(e.checked?e.value:"");});break;case "file":A(e,"change",()=>{r(e.files);});break;case "number":case "range":A(e,"input",()=>{r(e.value||"");});break;case "date":case "datetime-local":case "month":case "time":case "week":A(e,"change",()=>{r(e.value||"");});break;default:A(e,"input",()=>{r(e.value);});break}else Re(e)?A(e,"change",()=>{if(e.multiple){let o=Array.from(e.options).filter(i=>i.selected).map(i=>i.value);r(o);}else r(e.value);}):we(e)&&A(e,"input",()=>{r(e.value);});}function Lt(e,t,n,r){if(!e)return;let o=S();if(!o)return;let i=[],s=effect(()=>{let a=isFunction(t)?t():t,c=coerceArray(a).map(k);i=Ke(e,i,c,n);});o.cleanup.add(()=>{s(),r!=null&&r.preserveOnCleanup||i.forEach(a=>T(a)),i.length=0;});}function le(e,t){let n=t.length,r=new Array(n),o=new Set(t),i=1,s=0,a=c=>{if(c.nodeType!==Node.DOCUMENT_FRAGMENT_NODE){if(o.has(i)&&(r[s++]=c,s===n))return true;i++;}let u=c.firstChild;for(;u;){if(a(u))return true;u=u.nextSibling;}return false};return a(e),r}var Oe;Oe="normal";var q=class{constructor(t,n){this.component=t;this.props=n;this.renderedNode=null;this.componentContext=null;this.parentNode=null;this.beforeNode=null;this.reactiveProps={};this._propSnapshots={};this.state=0;this.context=null;this.parentContext=null;this[Oe]=true;if(this.key=n!=null&&n.key?ce(n.key):Le(t),this.reactiveProps=shallowReactive(K({},this.props||{})),this.parentContext=S(),this.props)for(let r in this.props){let o=this.props[r];isObject(o)&&o!==null&&(this._propSnapshots[r]=Array.isArray(o)?[...o]:K({},o));}}get isConnected(){return this.state===2}get firstChild(){var t;return (t=this.renderedNode)!=null?t:null}mount(t,n){if(this.parentNode=t,this.beforeNode=n||null,this.state=1,this.renderedNode)return y(t,this.renderedNode,n),this.renderedNode;this.componentContext=Ce(this.parentContext),$(this.componentContext);let r=this.component(this.reactiveProps);return isFunction(r)&&(r=r(this.reactiveProps)),(isSignal(r)||isComputed(r))&&(r=r.value),this.renderedNode=r,y(t,this.renderedNode,n),this.applyProps(this.props||{}),this.state=2,this.componentContext&&(this.componentContext.isMount=true),O(b.mount),this.renderedNode}update(t){if(this.key!==t.key)return this.mount(t.parentNode,t.beforeNode),this;if(this.parentNode=t.parentNode,this.beforeNode=t.beforeNode,this.componentContext=t.componentContext,this.renderedNode=t.renderedNode,this.state=t.state,this.reactiveProps=t.reactiveProps,this._propSnapshots=t._propSnapshots,this.props)for(let n in this.props){if(n==="key")continue;let r=this.props[n],o=this.reactiveProps[n];if(isObject(r)&&r!==null){let i=this._propSnapshots[n];if(!i||!De(r,i)){let s=Array.isArray(r)?r.slice():Object.assign({},r);this.reactiveProps[n]=s,this._propSnapshots[n]=s;}}else hasChanged(r,o)&&(this.reactiveProps[n]=r,this._propSnapshots[n]&&delete this._propSnapshots[n]);}return !this.isConnected&&this.parentNode&&this.mount(this.parentNode,this.beforeNode),this.componentContext&&($(this.componentContext),this.applyProps(this.props||{}),O(b.update),X()),this}forceUpdate(){return F(this,null,function*(){if(this.state===5||!this.parentNode||!this.componentContext)return;let t=this.renderedNode,n;try{this.componentContext&&$(this.componentContext),n=this.component(this.reactiveProps),isFunction(n)&&(n=n(this.reactiveProps)),(isSignal(n)||isComputed(n))&&(n=n.value),t&&n&&t!==n&&this.parentNode&&(j(this.parentNode,n,t),this.renderedNode=n),yield O(b.update);}catch(r){throw error("Force update failed:",r),r}finally{this.componentContext&&X();}})}destroy(){if(this.state===4||this.state===5)return;this.state=4;let t=this.componentContext;t&&($(t),O(b.destroy),Z(t),this.componentContext=null,X());let n=this.renderedNode;n&&T(n),this.renderedNode=null,this.parentNode=null,this.beforeNode=null,this.reactiveProps={},this.props=void 0,this.state=5;}applyProps(t){if(t){for(let[n,r]of Object.entries(t))if(startsWith(n,"on")&&this.renderedNode){let o=n.slice(2).toLowerCase();isHTMLElement(this.renderedNode)&&A(this.renderedNode,o,r);}else n==="ref"&&isSignal(r)&&(r.value=this.renderedNode);this.props=t;}}};function p(e){return !!e&&!!e.normal}function G(e,t){return p(e)?e:new q(e,t)}function de(e){let t,n=()=>{let r=document.createElement("template");r.innerHTML=e;let o=r.content.firstChild;if(!o)throw new Error("Invalid template: empty content");return o};return ()=>(t||(t=n())).cloneNode(true)}function Ht(e,t){let n=isString(t)?document.querySelector(t):t;if(!n){error(`Target element not found: ${t}`);return}n.innerHTML&&(error(`Target element is not empty, it will be delete: ${t}`),n.innerHTML="");let o=G(e);return o.mount(n),o}function me(e,t){let n=S();if(!n){error("provide must be called within a template");return}n.provides.set(e,t);}function pe(e,t){let n=S();if(!n)return error("inject must be called within a template"),t;let r=n;for(;r;){let o=r.provides.get(e);if(!isNil(o))return o;r=r.parent;}return t}function Mt(e){let t=e.target,n=`${e.type}`,r=e.target,o=e.currentTarget,i=c=>Object.defineProperty(e,"target",{configurable:true,value:c}),s=()=>{let c=t[`_$${n}`];if(c&&isFunction(c)&&!t.disabled){let u=t[`${n}Data`];if(u?c.call(t,u,e):c.call(t,e),e.cancelBubble)return false}return t.host&&!isString(t.host)&&!t.host._$host&&isFunction(t.contains)&&t.contains(e.target)&&i(t.host),true},a=()=>{for(;s()&&(t=t._$host||t.parentNode||t.host););};if(Object.defineProperty(e,"currentTarget",{configurable:true,get(){return t||document}}),e.composedPath){let c=e.composedPath();i(c[0]);for(let u=0;u<c.length-2&&(t=c[u],!!s());u++){if(t._$host){t=t._$host,a();break}if(t.parentNode===o)break}}else a();i(r);}var Ye=Symbol("_$EVENTS");function $t(e,t=window.document){let n=t,r=n[Ye]||(n[Ye]=new Set);for(let o of e)r.has(o)||(r.add(o),t.addEventListener(o,Mt));}function jt(e,t,n,r=false){if(t===n)return;let o=B(n),i=B(t);o&&i===o||(o?r?e.setAttribute("class",o):e.className=o:e.removeAttribute("class"));}function B(e){if(e==null)return "";if(typeof e=="string")return e.trim();if(isArray(e))return e.map(B).filter(Boolean).join(" ");if(isObject(e)){let t=[];for(let n in e)e[n]&&t.push(n);return t.join(" ")}return String(e).trim()}var Xe=/\s*!important$/,Xt=["Webkit","Moz","ms"],ye={};function Wt(e,t,n){let r=e.style,o=isString(n);if(n&&o){t!==n&&(r.cssText=n);return}if(!n){t&&e.removeAttribute("style");return}if(t&&!isString(t))for(let i in t)(!n||n[i]==null)&&Y(r,i,"");else if(t&&isString(t)){let i=t.split(";");for(let s of i){let a=s.indexOf(":");if(a>0){let c=s.slice(0,a).trim();n&&isObject(n)&&n[c]==null&&Y(r,c,"");}}}if(n&&!isString(n))for(let i in n){let s=n[i];(!t||isString(t)||t[i]!==s)&&s!=null&&Y(r,i,s);}}function Y(e,t,n){if(isArray(n)){for(let o of n)Y(e,t,o);return}if((n==null||n==="")&&(n=""),t.startsWith("--")){e.setProperty(t,n);return}let r=qt(e,t);typeof n=="string"&&Xe.test(n)?e.setProperty(camelCase(r),n.replace(Xe,""),"important"):e[r]=n;}function qt(e,t){let n=ye[t];if(n)return n;let r=camelCase(t);if(r!=="filter"&&r in e)return ye[t]=r;r=capitalize(r);for(let o of Xt){let i=o+r;if(i in e)return ye[t]=i}return t}function en(e,t,n,r){if(t==="ref"){n.value=e;return}if(t==="key"){r==null?z(e,void 0):z(e,String(r));return}let o=(e==null?void 0:e.namespaceURI)===ve,i=o&&t.startsWith("xlink:"),s=o&&t.startsWith("xmlns:"),a=isSpecialBooleanAttr(t)||isBooleanAttr(t);if(n===r)return;let c=t.toLowerCase();if(/^on[a-z]+/.test(c)||c==="innerhtml")return;if(r==null){if(i)e.removeAttributeNS(re,t.slice(6));else if(s){let l=t.slice(6);e.removeAttributeNS(oe,l);}else e.removeAttribute(t);return}if(i){e.setAttributeNS(re,t,String(r));return}if(s){e.setAttributeNS(oe,t,String(r));return}if(a){includeBooleanAttr(r)?e.setAttribute(t,""):e.removeAttribute(t);return}let u=isSymbol(r)?String(r):r;if((c==="href"||c==="src"||c==="xlink:href")&&typeof u=="string"){let l=u.trim().toLowerCase();if(l.startsWith("javascript:")||l.startsWith("data:"))return}if(o)e.setAttribute(t,String(u));else if(t in e)try{e[t]=u;}catch(l){e.setAttribute(t,String(u));}else e.setAttribute(t,String(u));}function tn(e,t,n,r){if(!(r!=null&&r.delegate))return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r);let o=r.delegate,i=a=>{let c=a.target;(c.matches(o)||c.closest(o))&&n.call(e,a);},s=K({},r);return s.delegate=void 0,e.addEventListener(t,i,s),()=>{e.removeEventListener(t,i,s);}}function nn(e){if(typeof document=="undefined"){let r=e.children;return r?(Array.isArray(r)?r:[r]).map(i=>String(i||"")).join(""):""}let t=document.createDocumentFragment(),n=e.children;return n&&(Array.isArray(n)?n:[n]).forEach(o=>{if(o!=null){let i=k(o);i&&y(t,i);}}),t}nn.fragment=true;function eo(e){return !!e&&!!e.fragment}function on(e){if(typeof document=="undefined"){let n=e.children;return n?(isArray(n)?n:[n]).map(o=>String(o||"")).join(""):""}let t=document.createComment("portal");return t.portal=true,te(()=>{let n=isString(e.target)?document.querySelector(e.target):e.target;if(!n)return;let r=e.children;r&&(isArray(r)?r:[r]).forEach(i=>{if(i!=null){let s=k(i);s&&y(n,s);}});}),t}on.portal=true;function co(e){return !!e&&!!e.portal}var ge=Symbol("SuspenseContext");function an(e){if(isUndefined(document)){let l=e.fallback;return l?String(l||""):""}let t=document.createElement("div");t.style.display="contents";let n=true,r=0,o=false,i=null,s=()=>{if(!o){for(o=true;t.firstChild;)t.removeChild(t.firstChild);if(e.fallback!=null){let l=k(e.fallback);l&&y(t,l);}}},a=()=>{if(!(!o||!(i||e.children!=null&&!isPromise(e.children)))){for(o=false;t.firstChild;)t.removeChild(t.firstChild);i?c(i):e.children!=null&&!isPromise(e.children)&&c(e.children);}},c=l=>{for(;t.firstChild;)t.removeChild(t.firstChild);if(l==null)return;let g=S();if((isArray(l)?l:[l]).forEach(C=>{if(C!=null){p(C)&&(C.parentContext=g);let H=k(C);H&&y(t,H);}}),o){for(;t.firstChild;)t.removeChild(t.firstChild);if(e.fallback!=null){let C=k(e.fallback);C&&y(t,C);}}},u={register:l=>{r++,s(),l.then(()=>{n&&(r--,r===0&&a());}).catch(g=>{n&&(r--,r===0&&a());});},increment:()=>{r++,s();},decrement:()=>{r--,r===0&&a();}};me(ge,u);let f=e.children;return isPromise(f)?(f.then(l=>{i=l;}).catch(()=>{}),u.register(f)):f!=null?c(f):s(),ne(()=>{for(n=false;t.firstChild;)t.removeChild(t.firstChild);}),t}an.suspense=true;function xo(e){return !!e&&!!e.suspense}function vo(e,t){let n=signal(t==null?void 0:t.initialValue),r=signal(true),o=signal(null),i=signal("pending"),s=0,a=null,c=()=>F(null,null,function*(){let l=++s;r.value=true,i.value="pending",o.value=null;let g=e();a=g.then(()=>{});try{let h=yield g;l===s&&(n.value=h,i.value="ready",r.value=!1);}catch(h){l===s&&(o.value=h instanceof Error?h:new Error(String(h)),i.value="errored",r.value=false);}});c();let u=(()=>{if(r.value&&a){let l=pe(ge,null);l&&l.register(a);}return n.value});return u.loading=r,u.error=o,u.state=i,[u,{mutate:l=>{n.value=l,i.value="ready",r.value=false,o.value=null;},refetch:()=>F(null,null,function*(){yield c();})}]}var Be=0;function xe(){return `${Be++}`}function J(){Be=0;}function Ne(){}function D(e,t=false){return isNil(e)?"":isString(e)?e:isArray(e)?e.map(n=>D(n,t)).join(""):isFunction(e)?D(e(),t):String(e)}function Qe(e,t){let n=/^<([a-z]+)(\s*)([^>]*)>/i,r=/data-idx="(\d+)"/g,o=/<!--(.*?)-->/g;return e.replace(n,`<$1$2$3 data-hk="${t}">`).replaceAll(r,`data-idx="${t}-$1"`).replaceAll(o,`<!--${t}-$1-->`)}function mn(e,t){if(!isFunction(e))return error("Component must be a function"),"";J();let n=e(t);return D(n)}function pn(e,t,...n){let r="",o=0;for(let s of e)if(r+=s,o<n.length){let a=n[o++];a&&(r+=D(a));}return Qe(r,t)}function yn(e,t={}){if(!isFunction(e))return error("create ssg component: Component is not a function"),"";let n=e(t);return D(n)}function rt(e){if(isArray(e)){let t={};for(let n of e){let r=isString(n)?Cn(n):rt(n);if(r)for(let o in r)t[o]=r[o];}return t}if(isString(e)||isObject(e))return e}var Sn=/;(?![^(]*\))/g,En=/:([\s\S]+)/,An=/\/\*[\s\S]*?\*\//g;function Cn(e){let t={};return e.replaceAll(An,"").split(Sn).forEach(n=>{if(n){let r=n.split(En);r.length>1&&(t[r[0].trim()]=r[1].trim());}}),t}function vn(e){if(!e)return "";if(isString(e))return e;let t="";for(let n in e){let r=e[n];if(isString(r)||isNumber(r)){let o=n.startsWith("--")?n:kebabCase(n);t+=`${o}:${r};`;}}return t}function ot(e){let t="";if(isString(e))t=e;else if(isArray(e))for(let n of e){let r=ot(n);r&&(t+=`${r} `);}else if(isObject(e))for(let n in e)e[n]&&(t+=`${n} `);return t.trim()}function it(e,t,n){if(isSignal(t)||isComputed(t))return it(e,t.value);if(!t&&t!==0)return "";if(e==="style"){let r=rt(t);return r?isString(r)?` style="${r}"`:` style="${vn(r)}"`:""}if(e==="class"){let r=ot(t);return r?` class="${r}"`:""}return e.startsWith("on")?"":t===true?` ${e}`:` ${e}="${t}"`}function Tn(e){return ()=>{let t=xe();return document.querySelector(`[data-hk="${t}"]`)||de(e)()}}function kn(e,t){let n=e.dataset.hk;if(!n)return le(e,t);let r=[],o=e.querySelectorAll(`[data-idx^="${n}"]`);o.length>0&&r.push(...Array.from(o).filter(c=>{let u=c.dataset.idx;return u!==null&&ie.test(u)}).map(c=>{let u=c.dataset.idx||"",[f,l]=u.split("-");return {hk:f,idx:l,node:c}}));let i=[],s=c=>{if(c.nodeType===Node.COMMENT_NODE&&c.textContent&&ie.test(c.textContent)){let[f,l]=c.textContent.split("-");i.push({hk:f,idx:l,node:c});}let u=c.firstChild;for(;u;)s(u),u=u.nextSibling;};s(e),r.push(...i);let a=[e];return t.forEach(c=>{let u=r.find(f=>f.idx===String(c));u&&a.push(u.node);}),a}function Ln(e,t,n={}){J();try{let r=isString(t)?document.querySelector(t):t;if(!r){error("Hydration error: Root element not found");return}let o=G(e,n);return o.mount(r),Ne(),o}catch(r){error("Hydration error:",r);return}}
7
+ export{q as Component,nn as Fragment,on as Portal,an as Suspense,ge as SuspenseContext,tn as addEvent,A as addEventListener,kt as bindElement,Ht as createApp,G as createComponent,vo as createResource,yn as createSSGComponent,$t as delegateEvents,xe as getHydrationKey,Tn as getRenderedElement,Ln as hydrate,pe as inject,Lt as insert,p as isComponent,eo as isFragment,co as isPortal,xo as isSuspense,le as mapNodes,kn as mapSSRNodes,B as normalizeClass,ne as onDestroy,te as onMount,mt as onUpdate,en as patchAttr,jt as patchClass,Wt as patchStyle,me as provide,pn as render,mn as renderToString,it as setSSGAttr,Y as setStyle,de as template};//# sourceMappingURL=template.esm.js.map
7
8
  //# sourceMappingURL=template.esm.js.map