jq79 0.1.3 → 0.1.4

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/jq79.cjs CHANGED
@@ -1,5 +1,5 @@
1
- var $=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var ee=(e,t,n)=>t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var te=(e,t)=>{for(var n in t)$(e,n,{get:t[n],enumerable:!0})},ne=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Y(t))!Q.call(e,s)&&s!==n&&$(e,s,{get:()=>t[s],enumerable:!(r=X(t,s))||r.enumerable});return e};var re=e=>ne($({},"__esModule",{value:!0}),e);var E=(e,t,n)=>ee(e,typeof t!="symbol"?t+"":t,n);var Oe={};te(Oe,{$:()=>U,$$:()=>se,Component79:()=>w,createReactiveDeepData:()=>V,parseComponent:()=>$e,renderComponent:()=>me});module.exports=re(Oe);var U=(e,t)=>typeof e=="string"?document.querySelector(e):e.querySelector(t||""),se=(e,t)=>Array.from(typeof e=="string"?document.querySelectorAll(e):e.querySelectorAll(t||"")),W=e=>Object.fromEntries(Array.from(e.attributes).map(t=>[t.name,t.value])),z=e=>({tag:e.tagName.toLowerCase(),attrs:W(e),children:Array.from(e.childNodes).flatMap(t=>{if(t.nodeType===Node.TEXT_NODE){let n=t.textContent?.trim()??"";return n?[n]:[]}return t.nodeType===Node.ELEMENT_NODE?[z(t)]:[]})}),S=(e,t,n)=>{try{return new Function("$scope",...Object.keys(n??{}),`with ($scope) { return (${e}); }`)(t,...Object.values(n??{}))}catch{return}},oe=(e,t)=>e.replace(/{{\s*(.+?)\s*}}/g,(n,r)=>S(r,t)??""),ie=(e,t)=>t.split(".").reduce((n,r)=>n?.[r],e),D=e=>{if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},H=(e,t,n)=>{Object.entries(e).forEach(([r,s])=>{let i=t?`${t}.${r}`:r;s&&typeof s=="object"&&D(s)?H(s,i,n):n(i,s)})},ce=(e,t)=>e===t||e.startsWith(`${t}.`)||t.startsWith(`${e}.`),R=[],ae=e=>{R.push(new Set);try{return e()}finally{R.pop()}},V=e=>{let t=new Map,n=new Set,r=new Set,s=new WeakSet,i=(a,l)=>{t.get(a)?.forEach(p=>p(l,a)),n.forEach(p=>p(a,l)),r.forEach(p=>{Array.from(p.deps).some(h=>ce(h,a))&&p.run()})},o=(a,l)=>{if(s.has(a))return a;Object.entries(a).forEach(([h,u])=>{u&&typeof u=="object"&&D(u)&&(a[h]=o(u,l?`${l}.${h}`:h))});let p=new Proxy(a,{get(h,u,g){return typeof u=="string"&&R[R.length-1]?.add(l?`${l}.${u}`:u),Reflect.get(h,u,g)},set(h,u,g,b){if(b!==p&&!Object.prototype.hasOwnProperty.call(h,u))return Reflect.set(h,u,g,b);let N=l?`${l}.${u}`:u;return g&&typeof g=="object"&&D(g)&&(g=o(g,N)),h[u]=g,i(N,g),!0}});return s.add(p),p},c=o(e,""),d=(a,l,{immediate:p=!1}={})=>(t.has(a)||t.set(a,new Set),t.get(a).add(l),p&&l(ie(c,a),a),()=>t.get(a)?.delete(l)),f=(a,{immediate:l=!1}={})=>(n.add(a),l&&H(c,"",(p,h)=>a(p,h)),()=>n.delete(a)),y=a=>{let l={deps:new Set,run:()=>{let p=new Set;R.push(p);try{a()}finally{R.pop(),l.deps=p}}};return r.add(l),l.run(),()=>{r.delete(l)}};return Object.defineProperty(c,"$on",{value:d,enumerable:!1}),Object.defineProperty(c,"$onAny",{value:f,enumerable:!1}),Object.defineProperty(c,"$effect",{value:y,enumerable:!1}),c},Z=new Set([":bind",":if",":elseif",":else",":each",":key"]),le=/^\s*(\w+)\s+in\s+(.+)$/,x=e=>{let t=[];return{effect:n=>{t.push(e.$effect(n))},onDispose:n=>{t.push(n)},dispose:()=>{t.splice(0).forEach(n=>n())}}},de=(e,t,n,r)=>{let[s,...i]=t.slice(1).split("."),o=new Set(i);e.addEventListener(s,c=>{if(o.has("self")&&c.target!==e)return;o.has("prevent")&&c.preventDefault(),o.has("stop")&&c.stopPropagation();let d=S(n,r,{$event:c});typeof d=="function"&&d.call(e,c)},{once:o.has("once"),capture:o.has("capture")})},P=e=>e.replace(/-(\w)/g,(t,n)=>n.toUpperCase()),pe=(e,t)=>{let n=t.replace(/-/g,"").toLowerCase();for(let r=e;r&&r!==Object.prototype;r=Object.getPrototypeOf(r))for(let s of Object.keys(r))if(/^[A-Z]/.test(s)&&s.replace(/-/g,"").toLowerCase()===n)return s;return null},fe=(e,t,n,r)=>{let s=document.createComment(e),i=document.createDocumentFragment();i.appendChild(s);let o={};Object.entries(t.attrs).forEach(([y,a])=>{if(!(Z.has(y)||y.startsWith("@")))if(y.startsWith(":")){let l=P(y.slice(1));o[l]=a||l}else o[P(y)]=JSON.stringify(a)});let c=null,d=null,f=null;return r.effect(()=>{let y=S(e,n),a=y instanceof w?y:null;if(a===d||(f?.dispose(),f=null,c?.destroy(),c=null,d=a,!a))return;let l=new w({template:a.template,scripts:a.scripts,styles:a.styles}),p=ae(()=>Object.fromEntries(Object.entries(o).map(([g,b])=>[g,S(b,n)]))),h=document.createDocumentFragment();l.render(p).mount(h),s.parentNode.insertBefore(h,s.nextSibling);let u=x(n);Object.entries(o).forEach(([g,b])=>{u.effect(()=>{l.data[g]=S(b,n)})}),f=u,c=l}),r.onDispose(()=>{f?.dispose(),c?.destroy()}),i},_=(e,t,n)=>{let r=pe(t,e.tag);if(r)return fe(r,e,t,n);let s=document.createElement(e.tag);Object.entries(e.attrs).forEach(([o,c])=>{o.startsWith("@")?de(s,o,c,t):Z.has(o)||s.setAttribute(o,c)});let i=e.attrs[":bind"];if(i!==void 0){let o=[];n.effect(()=>{o.forEach(d=>s.removeAttribute(d));let c=S(i,t);o=c&&typeof c=="object"?Object.keys(c):[],o.forEach(d=>{let f=c[d];f!=null&&f!==!1&&s.setAttribute(d,String(f))})})}return s.appendChild(j(e.children,t,n)),s},ue=(e,t,n)=>{let r=document.createComment("if"),s=document.createDocumentFragment();s.appendChild(r);let i=null,o=null,c=null;return n.effect(()=>{let d=e.find(f=>f.expr===void 0||S(f.expr,t))??null;d!==o&&(c?.dispose(),i&&i.parentNode?.removeChild(i),i=null,o=d,d&&(c=x(t),i=_(d.node,t,c),r.parentNode.insertBefore(i,r.nextSibling)))}),s},L=(e,t,n)=>{Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})},he=(e,t,n)=>{let r=e.attrs[":each"].match(le);if(!r)return document.createComment(`invalid :each expression "${e.attrs[":each"]}"`);let[,s,i]=r,o=e.attrs[":key"],{[":each"]:c,[":key"]:d,...f}=e.attrs,y={...e,attrs:f},a=document.createComment("each"),l=document.createDocumentFragment();l.appendChild(a);let p=[];return n.effect(()=>{let h=S(i,t),u=Array.isArray(h)?h:[],g=new Map(p.map(m=>[m.key,m])),b=u.map((m,A)=>{let T=Object.create(t);L(T,s,m),L(T,"$index",A);let k=o!==void 0?S(o,T):A,C=g.get(k);if(C&&Object.is(C.item,m))return L(C.scope,"$index",A),C;C?.fx.dispose(),C?.node.parentNode?.removeChild(C.node);let M=x(t);return{key:k,item:m,scope:T,fx:M,node:_(y,T,M)}}),N=new Set(b.map(m=>m.key));p.forEach(m=>{N.has(m.key)||(m.fx.dispose(),m.node.parentNode?.removeChild(m.node))});let v=a;b.forEach(m=>{v.nextSibling!==m.node&&a.parentNode.insertBefore(m.node,v.nextSibling),v=m.node}),p=b}),l},j=(e,t,n)=>{let r=document.createDocumentFragment(),s=0;for(;s<e.length;){let i=e[s];if(typeof i=="string"){let o=document.createTextNode("");n.effect(()=>{o.textContent=oe(i,t)}),r.appendChild(o),s++;continue}if(":each"in i.attrs){r.appendChild(he(i,t,n)),s++;continue}if(":if"in i.attrs){let o=[{expr:i.attrs[":if"],node:i}];for(s++;s<e.length&&typeof e[s]!="string"&&":elseif"in e[s].attrs;){let c=e[s];o.push({expr:c.attrs[":elseif"],node:c}),s++}s<e.length&&typeof e[s]!="string"&&":else"in e[s].attrs&&(o.push({node:e[s]}),s++),r.appendChild(ue(o,t,n));continue}r.appendChild(_(i,t,n)),s++}return r},me=(e,t)=>j(e.template,t,x(t)),ge=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),ye=/<([A-Za-z][\w-]*)((?:"[^"]*"|'[^']*'|[^>"'])*?)\/>/g,Ee=/(<script[\s\S]*?<\/script\s*>|<style[\s\S]*?<\/style\s*>)/gi,be=e=>e.split(Ee).map((t,n)=>n%2===1?t:t.replace(ye,(r,s,i)=>ge.has(s.toLowerCase())?r:`<${s}${i}></${s}>`)).join(""),Se=e=>{let n=new DOMParser().parseFromString(`<template>${be(e)}</template>`,"text/html").querySelector("template"),r=[],s=[],i=[];return Array.from(n.content.children).forEach(o=>{let c={attrs:W(o),content:o.textContent??""};o.tagName==="SCRIPT"?r.push(c):o.tagName==="STYLE"?s.push(c):i.push(z(o))}),{template:i,scripts:r,styles:s}},B=/(?:let|var|const)\s+([A-Za-z_$][\w$]*)/y,F=/\$:\s*/y,I=/import(?=\s*\()/y,q=/\$:\s*([A-Za-z_$][\w$]*)\s*=(?!=)/y,K=(e,t)=>{let n=e[t],r=t+1;for(;r<e.length;){if(e[r]==="\\"){r+=2;continue}if(e[r]===n)return r+1;r++}return e.length},G=(e,t)=>{let n=e.indexOf(`
2
- `,t);return n===-1?e.length:n},J=(e,t)=>{let n=e.indexOf("*/",t+2);return n===-1?e.length:n+2},Ce=(e,t)=>{let n=0,r=t;for(;r<e.length;){let s=e[r];if(s==="'"||s==='"'||s==="`"){r=K(e,r);continue}if(s==="/"&&e[r+1]==="/"){r=G(e,r);continue}if(s==="/"&&e[r+1]==="*"){r=J(e,r);continue}if("([{".includes(s))n++;else if(")]}".includes(s))n--;else if(n<=0&&(s===`
3
- `||s===";"))return r;r++}return e.length},we=e=>{let t=[],n="",r=0,s=0,i=!0;for(;r<e.length;){let o=e[r],c=e[r+1];if(o==="'"||o==='"'||o==="`"){let d=K(e,r);n+=e.slice(r,d),r=d,i=!1;continue}if(o==="/"&&(c==="/"||c==="*")){let d=c==="/"?G(e,r):J(e,r);n+=e.slice(r,d),r=d;continue}if(o==="i"&&(r===0||!/[\w$.]/.test(e[r-1]))&&(I.lastIndex=r,I.test(e))){n+="$__import",r+=6,i=!1;continue}if(s===0&&i){B.lastIndex=r;let d=B.exec(e);if(d){t.push(d[1]),n+=d[1],r+=d[0].length,i=!1;continue}F.lastIndex=r;let f=F.exec(e);if(f){q.lastIndex=r;let y=q.exec(e);y&&t.push(y[1]);let a=r+f[0].length,l=Ce(e,a);n+=`$__effect(() => { ${e.slice(a,l)} });`,r=l;continue}}"([{".includes(o)?s++:")]}".includes(o)&&(s=Math.max(0,s-1)),o===`
4
- `||o===";"||o==="}"?i=!0:/\s/.test(o)||(i=!1),n+=o,r++}return{vars:t,code:n}},Re=e=>/\.html?([?#]|$)/.test(e)?w.fetch(e):import(e),O=new Map,Te=e=>{let t=O.get(e);if(!t){let n=document.createElement("style");n.textContent=e,document.head.appendChild(n),t={el:n,count:0},O.set(e,t)}t.count++},xe=e=>{let t=O.get(e);t&&--t.count<=0&&(t.el.remove(),O.delete(e))},Ne=(e,t,n)=>{let r=new Proxy(t,{has:(i,o)=>o!=="$__effect"&&o!=="$__import"&&(Reflect.has(i,o)||!(o in globalThis))});new Function("$scope","$__effect","$__import",`return (async () => { with ($scope) { ${e} } })()`)(r,n,Re).catch(i=>console.error("jq79: error in :setup script",i))},w=class e{constructor(t){E(this,"template");E(this,"scripts");E(this,"styles");E(this,"data",null);E(this,"fx",null);E(this,"content",null);E(this,"startMarker",null);E(this,"endMarker",null);E(this,"styleEls",[]);E(this,"ownsSharedStyles",!1);E(this,"useShadow",!1);E(this,"mountRoot",null);let{template:n,scripts:r,styles:s}=typeof t=="string"?Se(t):t;this.template=n,this.scripts=r,this.styles=s}static async fetch(t){let n=await fetch(t);if(!n.ok)throw new Error(`failed to fetch component from ${t}: ${n.status}`);return new e(await n.text())}render(t={}){return this.renderWith(t,!1)}renderShadow(t={}){return this.renderWith(t,!0)}renderWith(t,n){this.destroy();let r=V({...t}),s=x(r);this.data=r,this.fx=s,this.useShadow=n,this.scripts.forEach(o=>{let{vars:c,code:d}=we(o.content);c.forEach(f=>{f in r||(r[f]=void 0)}),Ne(d,r,s.effect)}),this.startMarker=document.createComment("jq79"),this.endMarker=document.createComment("/jq79");let i=document.createDocumentFragment();return i.append(this.startMarker,j(this.template,r,s),this.endMarker),this.content=i,n?this.styleEls=this.styles.map(o=>{let c=document.createElement("style");return c.textContent=o.content,c}):(this.styles.forEach(o=>Te(o.content)),this.ownsSharedStyles=!0),this}mount(t){let n=typeof t=="string"?U(t):t;if(!n)throw new Error(`mount target not found: ${t}`);if(!this.content)throw new Error("render() must be called before mount()");this.mountRoot&&this.unmount();let r=this.useShadow&&n instanceof Element?n.shadowRoot??n.attachShadow({mode:"open"}):n;return this.useShadow&&this.styleEls.forEach(s=>r.appendChild(s)),r.appendChild(this.content),this.mountRoot=r,this}unmount(){if(!this.mountRoot||!this.content||!this.startMarker||!this.endMarker)return this;let t=this.startMarker;for(;t;){let n=t.nextSibling;if(this.content.appendChild(t),t===this.endMarker)break;t=n}return this.mountRoot=null,this}destroy(){return this.unmount(),this.fx?.dispose(),this.fx=null,this.styleEls.forEach(t=>t.parentNode?.removeChild(t)),this.styleEls=[],this.ownsSharedStyles&&(this.styles.forEach(t=>xe(t.content)),this.ownsSharedStyles=!1),this.content=null,this.startMarker=null,this.endMarker=null,this.data=null,this}},$e=e=>new w(e);0&&(module.exports={$,$$,Component79,createReactiveDeepData,parseComponent,renderComponent});
1
+ var $=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var ee=(e,t,n)=>t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var te=(e,t)=>{for(var n in t)$(e,n,{get:t[n],enumerable:!0})},ne=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Y(t))!Q.call(e,s)&&s!==n&&$(e,s,{get:()=>t[s],enumerable:!(r=X(t,s))||r.enumerable});return e};var re=e=>ne($({},"__esModule",{value:!0}),e);var E=(e,t,n)=>ee(e,typeof t!="symbol"?t+"":t,n);var Ae={};te(Ae,{$:()=>U,$$:()=>se,$create:()=>oe,Component79:()=>w,createReactiveDeepData:()=>V,parseComponent:()=>Oe,renderComponent:()=>ge});module.exports=re(Ae);var U=(e,t)=>typeof e=="string"?document.querySelector(e):e.querySelector(t||""),se=(e,t)=>Array.from(typeof e=="string"?document.querySelectorAll(e):e.querySelectorAll(t||"")),oe=(e,t={})=>{let n=document.createElement(e);for(let[r,s]of Object.entries(t))if(r==="className")n.className=Array.isArray(s)?s.join(" "):s;else if(r==="textContent")n.textContent=s;else if(r==="children")for(let i of s)n.appendChild(i);else n.setAttribute(r,s);return n},W=e=>Object.fromEntries(Array.from(e.attributes).map(t=>[t.name,t.value])),H=e=>({tag:e.tagName.toLowerCase(),attrs:W(e),children:Array.from(e.childNodes).flatMap(t=>{if(t.nodeType===Node.TEXT_NODE){let n=t.textContent?.trim()??"";return n?[n]:[]}return t.nodeType===Node.ELEMENT_NODE?[H(t)]:[]})}),S=(e,t,n)=>{try{return new Function("$scope",...Object.keys(n??{}),`with ($scope) { return (${e}); }`)(t,...Object.values(n??{}))}catch{return}},ie=(e,t)=>e.replace(/{{\s*(.+?)\s*}}/g,(n,r)=>S(r,t)??""),ce=(e,t)=>t.split(".").reduce((n,r)=>n?.[r],e),D=e=>{if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},z=(e,t,n)=>{Object.entries(e).forEach(([r,s])=>{let i=t?`${t}.${r}`:r;s&&typeof s=="object"&&D(s)?z(s,i,n):n(i,s)})},ae=(e,t)=>e===t||e.startsWith(`${t}.`)||t.startsWith(`${e}.`),R=[],le=e=>{R.push(new Set);try{return e()}finally{R.pop()}},V=e=>{let t=new Map,n=new Set,r=new Set,s=new WeakSet,i=(a,l)=>{t.get(a)?.forEach(p=>p(l,a)),n.forEach(p=>p(a,l)),r.forEach(p=>{Array.from(p.deps).some(m=>ae(m,a))&&p.run()})},o=(a,l)=>{if(s.has(a))return a;Object.entries(a).forEach(([m,u])=>{u&&typeof u=="object"&&D(u)&&(a[m]=o(u,l?`${l}.${m}`:m))});let p=new Proxy(a,{get(m,u,g){return typeof u=="string"&&R[R.length-1]?.add(l?`${l}.${u}`:u),Reflect.get(m,u,g)},set(m,u,g,b){if(b!==p&&!Object.prototype.hasOwnProperty.call(m,u))return Reflect.set(m,u,g,b);let N=l?`${l}.${u}`:u;return g&&typeof g=="object"&&D(g)&&(g=o(g,N)),m[u]=g,i(N,g),!0}});return s.add(p),p},c=o(e,""),d=(a,l,{immediate:p=!1}={})=>(t.has(a)||t.set(a,new Set),t.get(a).add(l),p&&l(ce(c,a),a),()=>t.get(a)?.delete(l)),f=(a,{immediate:l=!1}={})=>(n.add(a),l&&z(c,"",(p,m)=>a(p,m)),()=>n.delete(a)),y=a=>{let l={deps:new Set,run:()=>{let p=new Set;R.push(p);try{a()}finally{R.pop(),l.deps=p}}};return r.add(l),l.run(),()=>{r.delete(l)}};return Object.defineProperty(c,"$on",{value:d,enumerable:!1}),Object.defineProperty(c,"$onAny",{value:f,enumerable:!1}),Object.defineProperty(c,"$effect",{value:y,enumerable:!1}),c},Z=new Set([":bind",":if",":elseif",":else",":each",":key"]),de=/^\s*(\w+)\s+in\s+(.+)$/,T=e=>{let t=[];return{effect:n=>{t.push(e.$effect(n))},onDispose:n=>{t.push(n)},dispose:()=>{t.splice(0).forEach(n=>n())}}},pe=(e,t,n,r)=>{let[s,...i]=t.slice(1).split("."),o=new Set(i);e.addEventListener(s,c=>{if(o.has("self")&&c.target!==e)return;o.has("prevent")&&c.preventDefault(),o.has("stop")&&c.stopPropagation();let d=S(n,r,{$event:c});typeof d=="function"&&d.call(e,c)},{once:o.has("once"),capture:o.has("capture")})},P=e=>e.replace(/-(\w)/g,(t,n)=>n.toUpperCase()),fe=(e,t)=>{let n=t.replace(/-/g,"").toLowerCase();for(let r=e;r&&r!==Object.prototype;r=Object.getPrototypeOf(r))for(let s of Object.keys(r))if(/^[A-Z]/.test(s)&&s.replace(/-/g,"").toLowerCase()===n)return s;return null},ue=(e,t,n,r)=>{let s=document.createComment(e),i=document.createDocumentFragment();i.appendChild(s);let o={};Object.entries(t.attrs).forEach(([y,a])=>{if(!(Z.has(y)||y.startsWith("@")))if(y.startsWith(":")){let l=P(y.slice(1));o[l]=a||l}else o[P(y)]=JSON.stringify(a)});let c=null,d=null,f=null;return r.effect(()=>{let y=S(e,n),a=y instanceof w?y:null;if(a===d||(f?.dispose(),f=null,c?.destroy(),c=null,d=a,!a))return;let l=new w({template:a.template,scripts:a.scripts,styles:a.styles}),p=le(()=>Object.fromEntries(Object.entries(o).map(([g,b])=>[g,S(b,n)]))),m=document.createDocumentFragment();l.render(p).mount(m),s.parentNode.insertBefore(m,s.nextSibling);let u=T(n);Object.entries(o).forEach(([g,b])=>{u.effect(()=>{l.data[g]=S(b,n)})}),f=u,c=l}),r.onDispose(()=>{f?.dispose(),c?.destroy()}),i},_=(e,t,n)=>{let r=fe(t,e.tag);if(r)return ue(r,e,t,n);let s=document.createElement(e.tag);Object.entries(e.attrs).forEach(([o,c])=>{o.startsWith("@")?pe(s,o,c,t):Z.has(o)||s.setAttribute(o,c)});let i=e.attrs[":bind"];if(i!==void 0){let o=[];n.effect(()=>{o.forEach(d=>s.removeAttribute(d));let c=S(i,t);o=c&&typeof c=="object"?Object.keys(c):[],o.forEach(d=>{let f=c[d];f!=null&&f!==!1&&s.setAttribute(d,String(f))})})}return s.appendChild(j(e.children,t,n)),s},me=(e,t,n)=>{let r=document.createComment("if"),s=document.createDocumentFragment();s.appendChild(r);let i=null,o=null,c=null;return n.effect(()=>{let d=e.find(f=>f.expr===void 0||S(f.expr,t))??null;d!==o&&(c?.dispose(),i&&i.parentNode?.removeChild(i),i=null,o=d,d&&(c=T(t),i=_(d.node,t,c),r.parentNode.insertBefore(i,r.nextSibling)))}),s},L=(e,t,n)=>{Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})},he=(e,t,n)=>{let r=e.attrs[":each"].match(de);if(!r)return document.createComment(`invalid :each expression "${e.attrs[":each"]}"`);let[,s,i]=r,o=e.attrs[":key"],{[":each"]:c,[":key"]:d,...f}=e.attrs,y={...e,attrs:f},a=document.createComment("each"),l=document.createDocumentFragment();l.appendChild(a);let p=[];return n.effect(()=>{let m=S(i,t),u=Array.isArray(m)?m:[],g=new Map(p.map(h=>[h.key,h])),b=u.map((h,v)=>{let x=Object.create(t);L(x,s,h),L(x,"$index",v);let k=o!==void 0?S(o,x):v,C=g.get(k);if(C&&Object.is(C.item,h))return L(C.scope,"$index",v),C;C?.fx.dispose(),C?.node.parentNode?.removeChild(C.node);let M=T(t);return{key:k,item:h,scope:x,fx:M,node:_(y,x,M)}}),N=new Set(b.map(h=>h.key));p.forEach(h=>{N.has(h.key)||(h.fx.dispose(),h.node.parentNode?.removeChild(h.node))});let A=a;b.forEach(h=>{A.nextSibling!==h.node&&a.parentNode.insertBefore(h.node,A.nextSibling),A=h.node}),p=b}),l},j=(e,t,n)=>{let r=document.createDocumentFragment(),s=0;for(;s<e.length;){let i=e[s];if(typeof i=="string"){let o=document.createTextNode("");n.effect(()=>{o.textContent=ie(i,t)}),r.appendChild(o),s++;continue}if(":each"in i.attrs){r.appendChild(he(i,t,n)),s++;continue}if(":if"in i.attrs){let o=[{expr:i.attrs[":if"],node:i}];for(s++;s<e.length&&typeof e[s]!="string"&&":elseif"in e[s].attrs;){let c=e[s];o.push({expr:c.attrs[":elseif"],node:c}),s++}s<e.length&&typeof e[s]!="string"&&":else"in e[s].attrs&&(o.push({node:e[s]}),s++),r.appendChild(me(o,t,n));continue}r.appendChild(_(i,t,n)),s++}return r},ge=(e,t)=>j(e.template,t,T(t)),ye=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Ee=/<([A-Za-z][\w-]*)((?:"[^"]*"|'[^']*'|[^>"'])*?)\/>/g,be=/(<script[\s\S]*?<\/script\s*>|<style[\s\S]*?<\/style\s*>)/gi,Se=e=>e.split(be).map((t,n)=>n%2===1?t:t.replace(Ee,(r,s,i)=>ye.has(s.toLowerCase())?r:`<${s}${i}></${s}>`)).join(""),Ce=e=>{let n=new DOMParser().parseFromString(`<template>${Se(e)}</template>`,"text/html").querySelector("template"),r=[],s=[],i=[];return Array.from(n.content.children).forEach(o=>{let c={attrs:W(o),content:o.textContent??""};o.tagName==="SCRIPT"?r.push(c):o.tagName==="STYLE"?s.push(c):i.push(H(o))}),{template:i,scripts:r,styles:s}},B=/(?:let|var|const)\s+([A-Za-z_$][\w$]*)/y,F=/\$:\s*/y,I=/import(?=\s*\()/y,q=/\$:\s*([A-Za-z_$][\w$]*)\s*=(?!=)/y,K=(e,t)=>{let n=e[t],r=t+1;for(;r<e.length;){if(e[r]==="\\"){r+=2;continue}if(e[r]===n)return r+1;r++}return e.length},G=(e,t)=>{let n=e.indexOf(`
2
+ `,t);return n===-1?e.length:n},J=(e,t)=>{let n=e.indexOf("*/",t+2);return n===-1?e.length:n+2},we=(e,t)=>{let n=0,r=t;for(;r<e.length;){let s=e[r];if(s==="'"||s==='"'||s==="`"){r=K(e,r);continue}if(s==="/"&&e[r+1]==="/"){r=G(e,r);continue}if(s==="/"&&e[r+1]==="*"){r=J(e,r);continue}if("([{".includes(s))n++;else if(")]}".includes(s))n--;else if(n<=0&&(s===`
3
+ `||s===";"))return r;r++}return e.length},Re=e=>{let t=[],n="",r=0,s=0,i=!0;for(;r<e.length;){let o=e[r],c=e[r+1];if(o==="'"||o==='"'||o==="`"){let d=K(e,r);n+=e.slice(r,d),r=d,i=!1;continue}if(o==="/"&&(c==="/"||c==="*")){let d=c==="/"?G(e,r):J(e,r);n+=e.slice(r,d),r=d;continue}if(o==="i"&&(r===0||!/[\w$.]/.test(e[r-1]))&&(I.lastIndex=r,I.test(e))){n+="$__import",r+=6,i=!1;continue}if(s===0&&i){B.lastIndex=r;let d=B.exec(e);if(d){t.push(d[1]),n+=d[1],r+=d[0].length,i=!1;continue}F.lastIndex=r;let f=F.exec(e);if(f){q.lastIndex=r;let y=q.exec(e);y&&t.push(y[1]);let a=r+f[0].length,l=we(e,a);n+=`$__effect(() => { ${e.slice(a,l)} });`,r=l;continue}}"([{".includes(o)?s++:")]}".includes(o)&&(s=Math.max(0,s-1)),o===`
4
+ `||o===";"||o==="}"?i=!0:/\s/.test(o)||(i=!1),n+=o,r++}return{vars:t,code:n}},xe=e=>/\.html?([?#]|$)/.test(e)?w.fetch(e):import(e),O=new Map,Te=e=>{let t=O.get(e);if(!t){let n=document.createElement("style");n.textContent=e,document.head.appendChild(n),t={el:n,count:0},O.set(e,t)}t.count++},Ne=e=>{let t=O.get(e);t&&--t.count<=0&&(t.el.remove(),O.delete(e))},$e=(e,t,n)=>{let r=new Proxy(t,{has:(i,o)=>o!=="$__effect"&&o!=="$__import"&&(Reflect.has(i,o)||!(o in globalThis))});new Function("$scope","$__effect","$__import",`return (async () => { with ($scope) { ${e} } })()`)(r,n,xe).catch(i=>console.error("jq79: error in :setup script",i))},w=class e{constructor(t){E(this,"template");E(this,"scripts");E(this,"styles");E(this,"data",null);E(this,"fx",null);E(this,"content",null);E(this,"startMarker",null);E(this,"endMarker",null);E(this,"styleEls",[]);E(this,"ownsSharedStyles",!1);E(this,"useShadow",!1);E(this,"mountRoot",null);let{template:n,scripts:r,styles:s}=typeof t=="string"?Ce(t):t;this.template=n,this.scripts=r,this.styles=s}static async fetch(t){let n=await fetch(t);if(!n.ok)throw new Error(`failed to fetch component from ${t}: ${n.status}`);return new e(await n.text())}render(t={}){return this.renderWith(t,!1)}renderShadow(t={}){return this.renderWith(t,!0)}renderWith(t,n){this.destroy();let r=V({...t}),s=T(r);this.data=r,this.fx=s,this.useShadow=n,this.scripts.forEach(o=>{let{vars:c,code:d}=Re(o.content);c.forEach(f=>{f in r||(r[f]=void 0)}),$e(d,r,s.effect)}),this.startMarker=document.createComment("jq79"),this.endMarker=document.createComment("/jq79");let i=document.createDocumentFragment();return i.append(this.startMarker,j(this.template,r,s),this.endMarker),this.content=i,n?this.styleEls=this.styles.map(o=>{let c=document.createElement("style");return c.textContent=o.content,c}):(this.styles.forEach(o=>Te(o.content)),this.ownsSharedStyles=!0),this}mount(t){let n=typeof t=="string"?U(t):t;if(!n)throw new Error(`mount target not found: ${t}`);if(!this.content)throw new Error("render() must be called before mount()");this.mountRoot&&this.unmount();let r=this.useShadow&&n instanceof Element?n.shadowRoot??n.attachShadow({mode:"open"}):n;return this.useShadow&&this.styleEls.forEach(s=>r.appendChild(s)),r.appendChild(this.content),this.mountRoot=r,this}unmount(){if(!this.mountRoot||!this.content||!this.startMarker||!this.endMarker)return this;let t=this.startMarker;for(;t;){let n=t.nextSibling;if(this.content.appendChild(t),t===this.endMarker)break;t=n}return this.mountRoot=null,this}destroy(){return this.unmount(),this.fx?.dispose(),this.fx=null,this.styleEls.forEach(t=>t.parentNode?.removeChild(t)),this.styleEls=[],this.ownsSharedStyles&&(this.styles.forEach(t=>Ne(t.content)),this.ownsSharedStyles=!1),this.content=null,this.startMarker=null,this.endMarker=null,this.data=null,this}},Oe=e=>new w(e);0&&(module.exports={$,$$,$create,Component79,createReactiveDeepData,parseComponent,renderComponent});
5
5
  //# sourceMappingURL=jq79.cjs.map
package/dist/jq79.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/jq79.ts"],"sourcesContent":["\nexport const $ = (selectorOrEl: string | Element, selector?: string) => \n typeof selectorOrEl === \"string\"\n ? document.querySelector(selectorOrEl)\n : selectorOrEl.querySelector(selector || \"\")\n\nexport const $$ = (selectorOrEl: string | Element, selector?: string) => Array.from(\n typeof selectorOrEl === \"string\"\n ? document.querySelectorAll(selectorOrEl)\n : selectorOrEl.querySelectorAll(selector || \"\")\n)\n\ntype TemplateNode = {\n tag: string\n attrs: Record<string, string>\n children: (TemplateNode | string)[]\n}\n\ntype TagBlock = {\n attrs: Record<string, string>\n content: string\n}\n\nconst elementAttrs = (el: Element): Record<string, string> =>\n Object.fromEntries(Array.from(el.attributes).map(attr => [attr.name, attr.value]))\n\nconst elementToAST = (el: Element): TemplateNode => ({\n tag: el.tagName.toLowerCase(),\n attrs: elementAttrs(el),\n children: Array.from(el.childNodes).flatMap((node): (TemplateNode | string)[] => {\n if (node.nodeType === Node.TEXT_NODE) {\n const text = node.textContent?.trim() ?? \"\"\n return text ? [text] : []\n }\n if (node.nodeType === Node.ELEMENT_NODE) {\n return [elementToAST(node as Element)]\n }\n return []\n })\n})\n\n// evaluated with `with` (rather than passing scope keys as positional params)\n// so only the identifiers an expression actually references are read from\n// `scope` - which is what makes dependency tracking in createReactiveDeepData\n// precise instead of \"read everything up front\". `extras` are passed as\n// function parameters (outside the `with`), so scope keys still win but names\n// like $event resolve when the scope doesn't shadow them\nconst evalExpr = (expr: string, scope: Record<string, any>, extras?: Record<string, any>): any => {\n try {\n return new Function(\"$scope\", ...Object.keys(extras ?? {}), `with ($scope) { return (${expr}); }`)(\n scope,\n ...Object.values(extras ?? {})\n )\n } catch {\n return undefined\n }\n}\n\nconst interpolate = (template: string, scope: Record<string, any>): string =>\n template.replace(/{{\\s*(.+?)\\s*}}/g, (_, expr) => evalExpr(expr, scope) ?? \"\")\n\ntype ChangeListener = (value: any, dotKey: string) => void\ntype AnyChangeListener = (dotKey: string, value: any) => void\ntype ListenerOptions = { immediate?: boolean }\ntype Unsubscribe = () => void\n\ntype ReactiveDeepData<T> = T & {\n $on: (dotKey: string, listener: ChangeListener, options?: ListenerOptions) => Unsubscribe\n $onAny: (listener: AnyChangeListener, options?: ListenerOptions) => Unsubscribe\n // runs `run` immediately, recording every dotKey it reads off this store, then\n // re-runs it whenever a changed dotKey overlaps one of those - see pathsOverlap\n $effect: (run: () => void) => Unsubscribe\n}\n\nconst getByPath = (obj: Record<string, any>, dotKey: string): any =>\n dotKey.split(\".\").reduce((acc, key) => (acc == null ? undefined : acc[key]), obj)\n\n// only plain objects and arrays get deep-wrapped by the reactive store;\n// class instances (Component79, Date, DOM nodes, ...) pass through untouched\n// so their identity, prototypes and internals stay intact\nconst isPlainData = (value: object): boolean => {\n if (Array.isArray(value)) return true\n const proto = Object.getPrototypeOf(value)\n return proto === Object.prototype || proto === null\n}\n\nconst walkLeaves = (obj: Record<string, any>, path: string, visit: (dotKey: string, value: any) => void) => {\n Object.entries(obj).forEach(([key, value]) => {\n const dotKey = path ? `${path}.${key}` : key\n if (value && typeof value === \"object\" && isPlainData(value)) walkLeaves(value, dotKey, visit)\n else visit(dotKey, value)\n })\n}\n\n// true when `a` and `b` sit on the same ancestor/descendant line, e.g.\n// \"user\" & \"user.address.city\" (a change to either affects the other) - false\n// for siblings like \"user.name\" & \"user.age\"\nconst pathsOverlap = (a: string, b: string): boolean =>\n a === b || a.startsWith(`${b}.`) || b.startsWith(`${a}.`)\n\n// active $effect() runs, innermost last - a module-level stack (rather than\n// one per store) so nested effects across stores still nest correctly; reads\n// during makeReactive's `get` trap are attributed to whichever run is on top\nconst trackerStack: Set<string>[] = []\n\n// runs fn with dependency tracking suspended - reads inside it are attributed\n// to a throwaway set instead of the currently running effect\nconst untracked = <T>(fn: () => T): T => {\n trackerStack.push(new Set())\n try {\n return fn()\n } finally {\n trackerStack.pop()\n }\n}\n\ntype Effect = { deps: Set<string>; run: () => void }\n\nexport const createReactiveDeepData = <T extends Record<string, any>>(data: T): ReactiveDeepData<T> => {\n const exactListeners = new Map<string, Set<ChangeListener>>()\n const anyListeners = new Set<AnyChangeListener>()\n const effects = new Set<Effect>()\n // every proxy this store has ever handed out, so re-assigning an object\n // that's already reactive (e.g. `data.list = [data.list[1], data.list[0]]`)\n // doesn't wrap it a second time - which would hand out a *new* object\n // identity for the same logical item, breaking reference-equality checks\n // like :each's keyed diffing\n const reactiveProxies = new WeakSet<object>()\n\n const notify = (dotKey: string, value: any) => {\n exactListeners.get(dotKey)?.forEach(listener => listener(value, dotKey))\n anyListeners.forEach(listener => listener(dotKey, value))\n effects.forEach(effect => {\n if (Array.from(effect.deps).some(dep => pathsOverlap(dep, dotKey))) effect.run()\n })\n }\n\n const makeReactive = (obj: Record<string, any>, path: string): Record<string, any> => {\n if (reactiveProxies.has(obj)) return obj\n\n Object.entries(obj).forEach(([key, value]) => {\n if (value && typeof value === \"object\" && isPlainData(value)) {\n obj[key] = makeReactive(value, path ? `${path}.${key}` : key)\n }\n })\n\n const proxy = new Proxy(obj, {\n get(target, key, receiver) {\n if (typeof key === \"string\") {\n trackerStack[trackerStack.length - 1]?.add(path ? `${path}.${key}` : key)\n }\n return Reflect.get(target, key, receiver)\n },\n set(target, key: string, value, receiver) {\n // an assignment delegated up the prototype chain from a derived scope\n // (Object.create(store) child, or a wrapping proxy): if the key isn't\n // a real property of this store, honor the receiver so the new binding\n // lands on the derived scope - a scope-local variable, not a store\n // mutation, so no notify. If the key IS a store property, fall through\n // and mutate the store itself regardless of receiver, so assignments\n // like @click=\"count = count + 1\" work from any nested scope\n if (receiver !== proxy && !Object.prototype.hasOwnProperty.call(target, key)) {\n return Reflect.set(target, key, value, receiver)\n }\n\n const dotKey = path ? `${path}.${key}` : key\n if (value && typeof value === \"object\" && isPlainData(value)) {\n value = makeReactive(value, dotKey)\n }\n target[key] = value\n notify(dotKey, value)\n return true\n }\n })\n\n reactiveProxies.add(proxy)\n return proxy\n }\n\n const reactive = makeReactive(data, \"\") as ReactiveDeepData<T>\n\n const $on = (dotKey: string, listener: ChangeListener, { immediate = false }: ListenerOptions = {}): Unsubscribe => {\n if (!exactListeners.has(dotKey)) exactListeners.set(dotKey, new Set())\n exactListeners.get(dotKey)!.add(listener)\n if (immediate) listener(getByPath(reactive, dotKey), dotKey)\n return () => exactListeners.get(dotKey)?.delete(listener)\n }\n\n const $onAny = (listener: AnyChangeListener, { immediate = false }: ListenerOptions = {}): Unsubscribe => {\n anyListeners.add(listener)\n if (immediate) walkLeaves(reactive, \"\", (dotKey, value) => listener(dotKey, value))\n return () => anyListeners.delete(listener)\n }\n\n const $effect = (run: () => void): Unsubscribe => {\n const effect: Effect = {\n deps: new Set(),\n run: () => {\n const deps = new Set<string>()\n trackerStack.push(deps)\n try {\n run()\n } finally {\n trackerStack.pop()\n effect.deps = deps\n }\n },\n }\n effects.add(effect)\n effect.run()\n return () => { effects.delete(effect) }\n }\n\n Object.defineProperty(reactive, \"$on\", { value: $on, enumerable: false })\n Object.defineProperty(reactive, \"$onAny\", { value: $onAny, enumerable: false })\n Object.defineProperty(reactive, \"$effect\", { value: $effect, enumerable: false })\n\n return reactive\n}\n\nconst CONTROL_ATTRS = new Set([\":bind\", \":if\", \":elseif\", \":else\", \":each\", \":key\"])\nconst EACH_PATTERN = /^\\s*(\\w+)\\s+in\\s+(.+)$/\n\ntype ConditionalBranch = { expr?: string; node: TemplateNode }\n\n// groups the disposers of every $effect created for one rendered subtree\n// (an :if branch, an :each item, ...) so the whole subtree's bindings can be\n// torn down in one call when that subtree is replaced/removed. `scope.$effect`\n// resolves through the prototype chain up to the root store no matter how\n// many nested :each scopes sit in between (see renderEach's itemScope)\ntype EffectScope = {\n effect: (run: () => void) => void\n // registers an arbitrary cleanup (e.g. destroying a nested component) to\n // run when this subtree is torn down\n onDispose: (fn: Unsubscribe) => void\n dispose: () => void\n}\n\nconst createEffectScope = (scope: Record<string, any>): EffectScope => {\n const disposers: Unsubscribe[] = []\n return {\n effect: run => { disposers.push(scope.$effect(run)) },\n onDispose: fn => { disposers.push(fn) },\n dispose: () => { disposers.splice(0).forEach(dispose => dispose()) },\n }\n}\n\n// @event attributes: @click=\"onClick\", @submit.prevent=\"$event => onSubmit($event)\",\n// or an inline statement like @click=\"count = count + 1\". The expression is\n// evaluated (with `$event` in scope) on every event; if it yields a function,\n// that function is then invoked with the event - so both a handler reference\n// and an inline arrow/statement work. Modifiers after dots: .prevent .stop\n// .self (runtime guards) and .once .capture (addEventListener options)\nconst bindEvent = (el: Element, attr: string, expr: string, scope: Record<string, any>) => {\n const [name, ...modifiers] = attr.slice(1).split(\".\")\n const mods = new Set(modifiers)\n\n el.addEventListener(name, event => {\n if (mods.has(\"self\") && event.target !== el) return\n if (mods.has(\"prevent\")) event.preventDefault()\n if (mods.has(\"stop\")) event.stopPropagation()\n\n const handler = evalExpr(expr, scope, { $event: event })\n if (typeof handler === \"function\") handler.call(el, event)\n }, { once: mods.has(\"once\"), capture: mods.has(\"capture\") })\n}\n\nconst kebabToCamel = (name: string) => name.replace(/-(\\w)/g, (_, c: string) => c.toUpperCase())\n\n// finds the scope variable a template tag refers to. HTML parsing lowercases\n// tag names, so <NestedComponent> arrives as \"nestedcomponent\" and matching is\n// case-insensitive with dashes stripped (<nested-component> works too). Only\n// PascalCase scope keys participate, so ordinary variables named like real\n// elements (title, code, ...) never hijack them\nconst findComponentKey = (scope: Record<string, any>, tag: string): string | null => {\n const normalized = tag.replace(/-/g, \"\").toLowerCase()\n for (let obj: any = scope; obj && obj !== Object.prototype; obj = Object.getPrototypeOf(obj)) {\n for (const key of Object.keys(obj)) {\n if (/^[A-Z]/.test(key) && key.replace(/-/g, \"\").toLowerCase() === normalized) return key\n }\n }\n return null\n}\n\n// <MyComponent :user :title=\"'str'\"></MyComponent> - renders a child\n// component instance at this position. Props: `:name=\"expr\"` evaluates expr\n// in the parent scope (`:name` alone is shorthand for `:name=\"name\"`), plain\n// attributes pass through as literal strings, and kebab-case prop names\n// become camelCase. Props stay live: a parent effect re-evaluates each\n// expression and writes it into the child's store. The component variable is\n// reactive too - while it's undefined (e.g. an `await import(...)` still in\n// flight) nothing renders, and the child appears when it resolves\nconst renderNestedComponent = (key: string, node: TemplateNode, scope: Record<string, any>, fx: EffectScope): Node => {\n const anchor = document.createComment(key)\n const wrapper = document.createDocumentFragment()\n wrapper.appendChild(anchor)\n\n const props: Record<string, string> = {} // prop name -> expression in parent scope\n Object.entries(node.attrs).forEach(([attr, value]) => {\n if (CONTROL_ATTRS.has(attr) || attr.startsWith(\"@\")) return\n if (attr.startsWith(\":\")) {\n const name = kebabToCamel(attr.slice(1))\n props[name] = value || name\n } else {\n props[kebabToCamel(attr)] = JSON.stringify(value)\n }\n })\n\n let current: Component79 | null = null\n let currentDef: Component79 | null = null\n let childFx: EffectScope | null = null\n\n fx.effect(() => {\n const value = evalExpr(key, scope)\n const nextDef = value instanceof Component79 ? value : null\n if (nextDef === currentDef) return\n\n childFx?.dispose()\n childFx = null\n current?.destroy() // unmounts its marker range, removing the child's DOM\n current = null\n currentDef = nextDef\n if (!nextDef) return\n\n // a fresh instance per usage site: the definition's parsed parts are\n // shared, but store/effects/DOM are per instance\n const instance = new Component79({ template: nextDef.template, scripts: nextDef.scripts, styles: nextDef.styles })\n const seed = untracked(() =>\n Object.fromEntries(Object.entries(props).map(([name, expr]) => [name, evalExpr(expr, scope)]))\n )\n const holder = document.createDocumentFragment()\n instance.render(seed).mount(holder)\n anchor.parentNode!.insertBefore(holder, anchor.nextSibling)\n\n const syncFx = createEffectScope(scope)\n Object.entries(props).forEach(([name, expr]) => {\n syncFx.effect(() => { (instance.data as Record<string, any>)[name] = evalExpr(expr, scope) })\n })\n\n childFx = syncFx\n current = instance\n })\n\n fx.onDispose(() => {\n childFx?.dispose()\n current?.destroy()\n })\n\n return wrapper\n}\n\n// renders a single element node: static attrs, @event listeners, a reactive\n// :bind object, and its (reactive) children. :if/:elseif/:else/:each are\n// handled by renderNodes, which decides *whether*/*how many times* a node is\n// rendered before calling this. Tags matching a PascalCase scope variable\n// render as nested components instead\nconst renderNode = (node: TemplateNode, scope: Record<string, any>, fx: EffectScope): Node => {\n const componentKey = findComponentKey(scope, node.tag)\n if (componentKey) return renderNestedComponent(componentKey, node, scope, fx)\n\n const el = document.createElement(node.tag)\n\n Object.entries(node.attrs).forEach(([key, value]) => {\n if (key.startsWith(\"@\")) bindEvent(el, key, value, scope)\n else if (!CONTROL_ATTRS.has(key)) el.setAttribute(key, value)\n })\n\n const bindExpr = node.attrs[\":bind\"]\n if (bindExpr !== undefined) {\n let boundKeys: string[] = []\n\n fx.effect(() => {\n boundKeys.forEach(key => el.removeAttribute(key))\n const bound = evalExpr(bindExpr, scope)\n boundKeys = bound && typeof bound === \"object\" ? Object.keys(bound) : []\n boundKeys.forEach(key => {\n const value = bound[key]\n if (value != null && value !== false) el.setAttribute(key, String(value))\n })\n })\n }\n\n el.appendChild(renderNodes(node.children, scope, fx))\n\n return el\n}\n\n// a :if/:elseif*/:else? chain sharing one anchor comment so the active branch\n// can be swapped in place without disturbing sibling positions. Only depends\n// on whatever the branch expressions read (e.g. \"score\"), and skips\n// rebuilding entirely when the active branch hasn't actually changed\nconst renderConditional = (branches: ConditionalBranch[], scope: Record<string, any>, fx: EffectScope): Node => {\n const anchor = document.createComment(\"if\")\n const wrapper = document.createDocumentFragment()\n wrapper.appendChild(anchor)\n\n let current: Node | null = null\n let activeBranch: ConditionalBranch | null = null\n let branchFx: EffectScope | null = null\n\n fx.effect(() => {\n const next = branches.find(branch => branch.expr === undefined || evalExpr(branch.expr, scope)) ?? null\n if (next === activeBranch) return\n\n branchFx?.dispose()\n if (current) current.parentNode?.removeChild(current)\n current = null\n activeBranch = next\n if (!next) return\n\n branchFx = createEffectScope(scope)\n current = renderNode(next.node, scope, branchFx)\n anchor.parentNode!.insertBefore(current, anchor.nextSibling)\n })\n\n return wrapper\n}\n\n// defines a loop-local binding directly as `scope`'s own property. Plain\n// assignment (scope[key] = value) would only do this if the key isn't\n// already own on `scope` *or anywhere up its prototype chain* - if it isn't,\n// JS delegates the [[Set]] to whatever's up there, which for us is another\n// reactive proxy's `set` trap: it would wrap `value` as if it were a genuine\n// store mutation and fire a bogus notify() under a name (e.g. \"item\") shared\n// by every unrelated item in every :each on the page. defineProperty always\n// writes to `scope` itself, never delegating, so this can't happen\nconst defineScopeVar = (scope: Record<string, any>, key: string, value: any) => {\n Object.defineProperty(scope, key, { value, writable: true, enumerable: true, configurable: true })\n}\n\ntype EachEntry = { key: any; item: any; scope: Record<string, any>; node: Node; fx: EffectScope }\n\n// :each=\"item in items\", optionally keyed with :key=\"expr\". Only depends on\n// the list expression itself (e.g. \"items\"), and on each run diffs by key:\n// unchanged items (same key, same item reference) keep their DOM/effects,\n// changed/added ones are (re)rendered, removed ones are disposed. Without\n// :key, position is used as the key, so reordering rebuilds every item after\n// the first change - add :key for anything that gets reordered or filtered.\n// Each item gets its own scope via Object.create(scope), so `item`/`$index`\n// shadow same-named outer bindings without copying the parent scope's keys\nconst renderEach = (node: TemplateNode, scope: Record<string, any>, fx: EffectScope): Node => {\n const match = node.attrs[\":each\"].match(EACH_PATTERN)\n if (!match) return document.createComment(`invalid :each expression \"${node.attrs[\":each\"]}\"`)\n\n const [, itemName, listExpr] = match\n const keyExpr = node.attrs[\":key\"]\n const { [\":each\"]: _each, [\":key\"]: _key, ...itemAttrs } = node.attrs\n const itemNode: TemplateNode = { ...node, attrs: itemAttrs }\n\n const anchor = document.createComment(\"each\")\n const wrapper = document.createDocumentFragment()\n wrapper.appendChild(anchor)\n\n let entries: EachEntry[] = []\n\n fx.effect(() => {\n const list = evalExpr(listExpr, scope)\n const items = Array.isArray(list) ? list : []\n const previous = new Map(entries.map(entry => [entry.key, entry]))\n\n const nextEntries = items.map((item, index): EachEntry => {\n const itemScope = Object.create(scope)\n defineScopeVar(itemScope, itemName, item)\n defineScopeVar(itemScope, \"$index\", index)\n const key = keyExpr !== undefined ? evalExpr(keyExpr, itemScope) : index\n const existing = previous.get(key)\n\n if (existing && Object.is(existing.item, item)) {\n defineScopeVar(existing.scope, \"$index\", index)\n return existing\n }\n\n existing?.fx.dispose()\n existing?.node.parentNode?.removeChild(existing.node)\n\n const itemFx = createEffectScope(scope)\n return { key, item, scope: itemScope, fx: itemFx, node: renderNode(itemNode, itemScope, itemFx) }\n })\n\n const nextKeys = new Set(nextEntries.map(entry => entry.key))\n entries.forEach(entry => {\n if (!nextKeys.has(entry.key)) {\n entry.fx.dispose()\n entry.node.parentNode?.removeChild(entry.node)\n }\n })\n\n let prevNode: Node = anchor\n nextEntries.forEach(entry => {\n if (prevNode.nextSibling !== entry.node) anchor.parentNode!.insertBefore(entry.node, prevNode.nextSibling)\n prevNode = entry.node\n })\n\n entries = nextEntries\n })\n\n return wrapper\n}\n\n// renders a list of sibling template nodes (text + elements), grouping\n// consecutive :if/:elseif/:else nodes into a single conditional block\nconst renderNodes = (nodes: (TemplateNode | string)[], scope: Record<string, any>, fx: EffectScope): DocumentFragment => {\n const fragment = document.createDocumentFragment()\n let i = 0\n\n while (i < nodes.length) {\n const node = nodes[i]\n\n if (typeof node === \"string\") {\n const textNode = document.createTextNode(\"\")\n fx.effect(() => { textNode.textContent = interpolate(node, scope) })\n fragment.appendChild(textNode)\n i++\n continue\n }\n\n if (\":each\" in node.attrs) {\n fragment.appendChild(renderEach(node, scope, fx))\n i++\n continue\n }\n\n if (\":if\" in node.attrs) {\n const branches: ConditionalBranch[] = [{ expr: node.attrs[\":if\"], node }]\n i++\n while (i < nodes.length && typeof nodes[i] !== \"string\" && \":elseif\" in (nodes[i] as TemplateNode).attrs) {\n const elseifNode = nodes[i] as TemplateNode\n branches.push({ expr: elseifNode.attrs[\":elseif\"], node: elseifNode })\n i++\n }\n if (i < nodes.length && typeof nodes[i] !== \"string\" && \":else\" in (nodes[i] as TemplateNode).attrs) {\n branches.push({ node: nodes[i] as TemplateNode })\n i++\n }\n\n fragment.appendChild(renderConditional(branches, scope, fx))\n continue\n }\n\n fragment.appendChild(renderNode(node, scope, fx))\n i++\n }\n\n return fragment\n}\n\nexport const renderComponent = (component: Component79, data: ReactiveDeepData<Record<string, any>>): Node =>\n renderNodes(component.template, data, createEffectScope(data))\n\ntype ComponentParts = {\n template: TemplateNode[]\n scripts: TagBlock[]\n styles: TagBlock[]\n}\n\nconst VOID_ELEMENTS = new Set([\n \"area\", \"base\", \"br\", \"col\", \"embed\", \"hr\", \"img\", \"input\",\n \"link\", \"meta\", \"param\", \"source\", \"track\", \"wbr\",\n])\n\n// a self-closing tag with its attributes; quoted attribute values are matched\n// as whole chunks so a \"/>\" inside one doesn't end the tag early\nconst SELF_CLOSING_RE = /<([A-Za-z][\\w-]*)((?:\"[^\"]*\"|'[^']*'|[^>\"'])*?)\\/>/g\nconst RAW_BLOCK_RE = /(<script[\\s\\S]*?<\\/script\\s*>|<style[\\s\\S]*?<\\/style\\s*>)/gi\n\n// expands self-closing tags (<MyComponent />, <div />) into explicit\n// open+close pairs BEFORE DOM parsing. The HTML parser ignores the slash and\n// would treat them as unclosed, swallowing the following siblings. Void\n// elements keep their native behavior, and <script>/<style> contents are\n// passed through untouched so code inside them is never rewritten\nconst expandSelfClosingTags = (src: string): string =>\n src\n .split(RAW_BLOCK_RE)\n .map((chunk, i) =>\n i % 2 === 1 // odd chunks are the captured script/style blocks\n ? chunk\n : chunk.replace(SELF_CLOSING_RE, (match, tag: string, attrs: string) =>\n VOID_ELEMENTS.has(tag.toLowerCase()) ? match : `<${tag}${attrs}></${tag}>`\n )\n )\n .join(\"\")\n\n// converts a string of HTML into an AST representation of the component:\n// - template: the non-script/style top-level elements, as TemplateNodes\n// - scripts/styles: { attrs, content } blocks in source order\nconst parseComponentString = (component: string): ComponentParts => {\n // example\n // <script :setup=\"{ fname, lname }\">\n // const fullName = `${fname} ${lname}`\n // </script>\n //\n // <div :bind=\"{ fullName }\"></div>\n // <div class=\"full-name\">\n // {{ fullName }}\n // </div>\n //\n // <style>\n // .full-name {\n // color: red;\n // }\n // </style>\n\n // parsed as the content of a <template> so leading <script>/<style> tags\n // aren't reparented into <head> by the HTML parser\n const parsedDOM = new DOMParser().parseFromString(`<template>${expandSelfClosingTags(component)}</template>`, \"text/html\")\n const root = parsedDOM.querySelector(\"template\") as HTMLTemplateElement\n\n const scripts: TagBlock[] = []\n const styles: TagBlock[] = []\n const template: TemplateNode[] = []\n\n Array.from(root.content.children).forEach(el => {\n const block = { attrs: elementAttrs(el), content: el.textContent ?? \"\" }\n\n if (el.tagName === \"SCRIPT\") scripts.push(block)\n else if (el.tagName === \"STYLE\") styles.push(block)\n else template.push(elementToAST(el))\n })\n\n return { template, scripts, styles }\n}\n\n// ---------------------------------------------------------------------------\n// :setup script transform\n//\n// setup scripts are written like Svelte components:\n//\n// let firstName = null\n// $: fullName = `${firstName} ${lastName}`\n// fetchUser().then(user => { firstName = user.firstName })\n//\n// and are executed inside `with ($scope)` against the component's reactive\n// store, so plain assignments (even from async callbacks) go through the\n// proxy's set trap and re-render whatever depends on them. To make that work\n// the source is lightly rewritten - no full JS parser, just a scanner that is\n// string/comment-aware and only touches code at brace/paren depth 0:\n// - `let/var/const x = ...` at the top level loses its keyword, becoming a\n// scope assignment (the name is pre-declared on the store so the `with`\n// lookup resolves it)\n// - `$: x = expr` becomes `$__effect(() => { x = expr })`, re-running when a\n// dependency read inside expr changes ($__effect is deliberately NOT a\n// property of the scope, so `with` falls through to the function parameter)\n// ---------------------------------------------------------------------------\n\ntype SetupTransform = { vars: string[]; code: string }\n\nconst DECLARATION_RE = /(?:let|var|const)\\s+([A-Za-z_$][\\w$]*)/y\nconst REACTIVE_LABEL_RE = /\\$:\\s*/y\nconst IMPORT_CALL_RE = /import(?=\\s*\\()/y\nconst REACTIVE_ASSIGN_RE = /\\$:\\s*([A-Za-z_$][\\w$]*)\\s*=(?!=)/y\n\nconst skipString = (src: string, start: number): number => {\n const quote = src[start]\n let i = start + 1\n while (i < src.length) {\n if (src[i] === \"\\\\\") { i += 2; continue }\n if (src[i] === quote) return i + 1\n i++\n }\n return src.length\n}\n\nconst skipLineComment = (src: string, start: number): number => {\n const end = src.indexOf(\"\\n\", start)\n return end === -1 ? src.length : end\n}\n\nconst skipBlockComment = (src: string, start: number): number => {\n const end = src.indexOf(\"*/\", start + 2)\n return end === -1 ? src.length : end + 2\n}\n\n// end of a statement starting at `start`: the first newline or `;` that isn't\n// inside a string/comment or unbalanced brackets, so multi-line RHS like a\n// wrapped function call or template literal stays in one piece\nconst findStatementEnd = (src: string, start: number): number => {\n let depth = 0\n let i = start\n while (i < src.length) {\n const ch = src[i]\n if (ch === \"'\" || ch === '\"' || ch === \"`\") { i = skipString(src, i); continue }\n if (ch === \"/\" && src[i + 1] === \"/\") { i = skipLineComment(src, i); continue }\n if (ch === \"/\" && src[i + 1] === \"*\") { i = skipBlockComment(src, i); continue }\n if (\"([{\".includes(ch)) depth++\n else if (\")]}\".includes(ch)) depth--\n else if (depth <= 0 && (ch === \"\\n\" || ch === \";\")) return i\n i++\n }\n return src.length\n}\n\nconst transformSetupScript = (src: string): SetupTransform => {\n const vars: string[] = []\n let out = \"\"\n let i = 0\n let depth = 0\n let atStatementStart = true\n\n while (i < src.length) {\n const ch = src[i]\n const next = src[i + 1]\n\n if (ch === \"'\" || ch === '\"' || ch === \"`\") {\n const end = skipString(src, i)\n out += src.slice(i, end)\n i = end\n atStatementStart = false\n continue\n }\n if (ch === \"/\" && (next === \"/\" || next === \"*\")) {\n const end = next === \"/\" ? skipLineComment(src, i) : skipBlockComment(src, i)\n out += src.slice(i, end)\n i = end\n continue\n }\n\n // `import(...)` is a keyword form, so it can't be intercepted through the\n // scope - rewrite the identifier to the injected $__import (which loads\n // .html URLs as components via Component79.fetch and delegates the rest to\n // native import). The `(` is left for the scanner so depth stays balanced\n if (ch === \"i\" && (i === 0 || !/[\\w$.]/.test(src[i - 1]))) {\n IMPORT_CALL_RE.lastIndex = i\n if (IMPORT_CALL_RE.test(src)) {\n out += \"$__import\"\n i += \"import\".length\n atStatementStart = false\n continue\n }\n }\n\n if (depth === 0 && atStatementStart) {\n DECLARATION_RE.lastIndex = i\n const decl = DECLARATION_RE.exec(src)\n if (decl) {\n vars.push(decl[1])\n out += decl[1]\n i += decl[0].length\n atStatementStart = false\n continue\n }\n\n REACTIVE_LABEL_RE.lastIndex = i\n const label = REACTIVE_LABEL_RE.exec(src)\n if (label) {\n REACTIVE_ASSIGN_RE.lastIndex = i\n const assign = REACTIVE_ASSIGN_RE.exec(src)\n if (assign) vars.push(assign[1])\n const start = i + label[0].length\n const end = findStatementEnd(src, start)\n out += `$__effect(() => { ${src.slice(start, end)} });`\n i = end\n continue\n }\n }\n\n if (\"([{\".includes(ch)) depth++\n else if (\")]}\".includes(ch)) depth = Math.max(0, depth - 1)\n\n if (ch === \"\\n\" || ch === \";\" || ch === \"}\") atStatementStart = true\n else if (!/\\s/.test(ch)) atStatementStart = false\n\n out += ch\n i++\n }\n\n return { vars, code: out }\n}\n\n// loads .html URLs as components, delegating anything else to native import()\nconst importResource = (url: string): Promise<any> =>\n /\\.html?([?#]|$)/.test(url) ? Component79.fetch(url) : import(url)\n\n// document.head styles are shared by content and refcounted, so N instances\n// of the same component (e.g. one per :each item) inject a single <style> tag\n// that goes away when the last instance is destroyed\nconst styleRegistry = new Map<string, { el: HTMLStyleElement; count: number }>()\n\nconst acquireStyle = (content: string) => {\n let entry = styleRegistry.get(content)\n if (!entry) {\n const el = document.createElement(\"style\")\n el.textContent = content\n document.head.appendChild(el)\n entry = { el, count: 0 }\n styleRegistry.set(content, entry)\n }\n entry.count++\n}\n\nconst releaseStyle = (content: string) => {\n const entry = styleRegistry.get(content)\n if (entry && --entry.count <= 0) {\n entry.el.remove()\n styleRegistry.delete(content)\n }\n}\n\n// scripts run inside `with (scriptScope)`, where scriptScope's `has` trap\n// claims ownership of every name that is neither a real global nor one of the\n// injected helpers. This makes `with` route ALL other reads/writes through the\n// reactive store - even bare assignments to names never declared with\n// let/const, which would otherwise leak onto globalThis - while `console`,\n// `Promise`, `fetch`, etc. still resolve normally. get/set are deliberately\n// not trapped: they default-forward to `scope` (the reactive proxy),\n// preserving tracking and notify.\n// The body is wrapped in an async IIFE so top-level `await` works: everything\n// up to the first await runs synchronously (before the template renders), and\n// later assignments update the DOM reactively when they happen\nconst runSetupScript = (code: string, scope: Record<string, any>, effect: (run: () => void) => void) => {\n const scriptScope = new Proxy(scope, {\n has: (target, key) =>\n key !== \"$__effect\" && key !== \"$__import\" && (Reflect.has(target, key) || !(key in globalThis)),\n })\n const result: Promise<void> = new Function(\n \"$scope\", \"$__effect\", \"$__import\",\n `return (async () => { with ($scope) { ${code} } })()`\n )(scriptScope, effect, importResource)\n result.catch(error => console.error(\"jq79: error in :setup script\", error))\n}\n\n// a parsed single-file component. Typical lifecycle:\n//\n// const jq79 = new Component79(src) // or await Component79.fetch(url)\n// jq79.render({ user }) // build reactive DOM, run scripts, inject styles\n// .mount(\"#app\") // attach (renderShadow mounts into a shadow root)\n// ...\n// jq79.unmount() // detach, keeping state - mount() re-attaches\n// .destroy() // dispose effects and remove styles\nexport class Component79 {\n template: TemplateNode[]\n scripts: TagBlock[]\n styles: TagBlock[]\n\n data: ReactiveDeepData<Record<string, any>> | null = null\n\n private fx: EffectScope | null = null\n // holds the rendered nodes while unmounted; anchors keep this fragment as\n // their parentNode, so effects keep the (detached) DOM up to date and a\n // later mount() shows current state\n private content: DocumentFragment | null = null\n // markers bracketing the component's output so unmount() can collect nodes\n // that :if/:each inserted next to the anchors after mounting\n private startMarker: Comment | null = null\n private endMarker: Comment | null = null\n // shadow rendering keeps per-instance <style> elements; head rendering goes\n // through the shared refcounted styleRegistry instead\n private styleEls: HTMLStyleElement[] = []\n private ownsSharedStyles = false\n private useShadow = false\n private mountRoot: Element | ShadowRoot | DocumentFragment | null = null\n\n constructor(src: string | ComponentParts) {\n const { template, scripts, styles } = typeof src === \"string\" ? parseComponentString(src) : src\n this.template = template\n this.scripts = scripts\n this.styles = styles\n }\n\n static async fetch(url: string): Promise<Component79> {\n const response = await fetch(url)\n if (!response.ok) throw new Error(`failed to fetch component from ${url}: ${response.status}`)\n return new Component79(await response.text())\n }\n\n render(data: Record<string, any> = {}): this {\n return this.renderWith(data, false)\n }\n\n // like render(), but styles are injected into a shadow root attached to the\n // mount target instead of document.head, so they don't leak globally\n renderShadow(data: Record<string, any> = {}): this {\n return this.renderWith(data, true)\n }\n\n private renderWith(data: Record<string, any>, shadow: boolean): this {\n this.destroy()\n\n const store = createReactiveDeepData({ ...data })\n const fx = createEffectScope(store)\n this.data = store\n this.fx = fx\n this.useShadow = shadow\n\n // scripts run before the template renders so `$:` values are initialized\n this.scripts.forEach(script => {\n const { vars, code } = transformSetupScript(script.content)\n // pre-declare script vars on the store so `with` resolves assignments\n // to them (and reads of them) through the reactive proxy\n vars.forEach(name => { if (!(name in store)) (store as any)[name] = undefined })\n runSetupScript(code, store, fx.effect)\n })\n\n this.startMarker = document.createComment(\"jq79\")\n this.endMarker = document.createComment(\"/jq79\")\n const content = document.createDocumentFragment()\n content.append(this.startMarker, renderNodes(this.template, store, fx), this.endMarker)\n this.content = content\n\n if (shadow) {\n this.styleEls = this.styles.map(style => {\n const el = document.createElement(\"style\")\n el.textContent = style.content\n return el\n })\n } else {\n this.styles.forEach(style => acquireStyle(style.content))\n this.ownsSharedStyles = true\n }\n\n return this\n }\n\n mount(parent: Element | ShadowRoot | DocumentFragment | string): this {\n const target = typeof parent === \"string\" ? $(parent) : parent\n if (!target) throw new Error(`mount target not found: ${parent}`)\n if (!this.content) throw new Error(\"render() must be called before mount()\")\n if (this.mountRoot) this.unmount()\n\n const root = this.useShadow && target instanceof Element\n ? target.shadowRoot ?? target.attachShadow({ mode: \"open\" })\n : target\n if (this.useShadow) this.styleEls.forEach(el => root.appendChild(el))\n root.appendChild(this.content)\n this.mountRoot = root\n return this\n }\n\n unmount(): this {\n if (!this.mountRoot || !this.content || !this.startMarker || !this.endMarker) return this\n\n // move everything between the markers (inclusive) back into the holding\n // fragment - including nodes :if/:each inserted after mounting\n let node: Node | null = this.startMarker\n while (node) {\n const nextNode: Node | null = node.nextSibling\n this.content.appendChild(node)\n if (node === this.endMarker) break\n node = nextNode\n }\n\n this.mountRoot = null\n return this\n }\n\n destroy(): this {\n this.unmount()\n this.fx?.dispose()\n this.fx = null\n this.styleEls.forEach(el => el.parentNode?.removeChild(el))\n this.styleEls = []\n if (this.ownsSharedStyles) {\n this.styles.forEach(style => releaseStyle(style.content))\n this.ownsSharedStyles = false\n }\n this.content = null\n this.startMarker = null\n this.endMarker = null\n this.data = null\n return this\n }\n}\n\nexport const parseComponent = (component: string): Component79 => new Component79(component)\n\n"],"mappings":"0iBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,OAAAE,EAAA,OAAAC,GAAA,gBAAAC,EAAA,2BAAAC,EAAA,mBAAAC,GAAA,oBAAAC,KAAA,eAAAC,GAAAR,IACO,IAAMS,EAAI,CAACC,EAAgCC,IAChD,OAAOD,GAAiB,SACpB,SAAS,cAAcA,CAAY,EACnCA,EAAa,cAAcC,GAAY,EAAE,EAElCC,GAAK,CAACF,EAAgCC,IAAsB,MAAM,KAC7E,OAAOD,GAAiB,SACpB,SAAS,iBAAiBA,CAAY,EACtCA,EAAa,iBAAiBC,GAAY,EAAE,CAClD,EAaME,EAAgBC,GACpB,OAAO,YAAY,MAAM,KAAKA,EAAG,UAAU,EAAE,IAAIC,GAAQ,CAACA,EAAK,KAAMA,EAAK,KAAK,CAAC,CAAC,EAE7EC,EAAgBF,IAA+B,CACnD,IAAKA,EAAG,QAAQ,YAAY,EAC5B,MAAOD,EAAaC,CAAE,EACtB,SAAU,MAAM,KAAKA,EAAG,UAAU,EAAE,QAASG,GAAoC,CAC/E,GAAIA,EAAK,WAAa,KAAK,UAAW,CACpC,IAAMC,EAAOD,EAAK,aAAa,KAAK,GAAK,GACzC,OAAOC,EAAO,CAACA,CAAI,EAAI,CAAC,CAC1B,CACA,OAAID,EAAK,WAAa,KAAK,aAClB,CAACD,EAAaC,CAAe,CAAC,EAEhC,CAAC,CACV,CAAC,CACH,GAQME,EAAW,CAACC,EAAcC,EAA4BC,IAAsC,CAChG,GAAI,CACF,OAAO,IAAI,SAAS,SAAU,GAAG,OAAO,KAAKA,GAAU,CAAC,CAAC,EAAG,2BAA2BF,CAAI,MAAM,EAC/FC,EACA,GAAG,OAAO,OAAOC,GAAU,CAAC,CAAC,CAC/B,CACF,MAAQ,CACN,MACF,CACF,EAEMC,GAAc,CAACC,EAAkBH,IACrCG,EAAS,QAAQ,mBAAoB,CAACC,EAAGL,IAASD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yK,CACT,CAEA,YAAK,UAAY,KACV,IACT,CAEA,SAAgB,CACd,YAAK,QAAQ,EACb,KAAK,IAAI,QAAQ,EACjB,KAAK,GAAK,KACV,KAAK,SAAS,QAAQ5K,GAAMA,EAAG,YAAY,YAAYA,CAAE,CAAC,EAC1D,KAAK,SAAW,CAAC,EACb,KAAK,mBACP,KAAK,OAAO,QAAQ0K,GAASX,GAAaW,EAAM,OAAO,CAAC,EACxD,KAAK,iBAAmB,IAE1B,KAAK,QAAU,KACf,KAAK,YAAc,KACnB,KAAK,UAAY,KACjB,KAAK,KAAO,KACL,IACT,CACF,EAEaG,GAAkBpD,GAAmC,IAAI9C,EAAY8C,CAAS","names":["jq79_exports","__export","$","$$","Component79","createReactiveDeepData","parseComponent","renderComponent","__toCommonJS","$","selectorOrEl","selector","$$","elementAttrs","el","attr","elementToAST","node","text","evalExpr","expr","scope","extras","interpolate","template","_","getByPath","obj","dotKey","acc","key","isPlainData","value","proto","walkLeaves","path","visit","pathsOverlap","a","b","trackerStack","untracked","fn","createReactiveDeepData","data","exactListeners","anyListeners","effects","reactiveProxies","notify","listener","effect","dep","makeReactive","proxy","target","receiver","reactive","$on","immediate","$onAny","$effect","run","deps","CONTROL_ATTRS","EACH_PATTERN","createEffectScope","disposers","dispose","bindEvent","name","modifiers","mods","event","handler","kebabToCamel","c","findComponentKey","tag","normalized","renderNestedComponent","fx","anchor","wrapper","props","current","currentDef","childFx","nextDef","Component79","instance","seed","holder","syncFx","renderNode","componentKey","bindExpr","boundKeys","bound","renderNodes","renderConditional","branches","activeBranch","branchFx","next","branch","defineScopeVar","renderEach","match","itemName","listExpr","keyExpr","_each","_key","itemAttrs","itemNode","entries","list","items","previous","entry","nextEntries","item","index","itemScope","existing","itemFx","nextKeys","prevNode","nodes","fragment","i","textNode","elseifNode","renderComponent","component","VOID_ELEMENTS","SELF_CLOSING_RE","RAW_BLOCK_RE","expandSelfClosingTags","src","chunk","attrs","parseComponentString","root","scripts","styles","block","DECLARATION_RE","REACTIVE_LABEL_RE","IMPORT_CALL_RE","REACTIVE_ASSIGN_RE","skipString","start","quote","skipLineComment","end","skipBlockComment","findStatementEnd","depth","ch","transformSetupScript","vars","out","atStatementStart","decl","label","assign","importResource","url","styleRegistry","acquireStyle","content","releaseStyle","runSetupScript","code","scriptScope","error","_Component79","__publicField","response","shadow","store","script","style","parent","nextNode","parseComponent"]}
1
+ {"version":3,"sources":["../src/jq79.ts"],"sourcesContent":["\nexport const $ = (selectorOrEl: string | Element, selector?: string) => \n typeof selectorOrEl === \"string\"\n ? document.querySelector(selectorOrEl)\n : selectorOrEl.querySelector(selector || \"\")\n\nexport const $$ = (selectorOrEl: string | Element, selector?: string) => Array.from(\n typeof selectorOrEl === \"string\"\n ? document.querySelectorAll(selectorOrEl)\n : selectorOrEl.querySelectorAll(selector || \"\")\n)\n\n// $create(tag, attrs): attrs are set as attributes, except className, which\n// may be a string or an array of class names.\nexport const $create = (tag: string, attrs: Record<string, any> = {}): HTMLElement => {\n const el = document.createElement(tag);\n for (const [name, value] of Object.entries(attrs)) {\n if (name === 'className') {\n el.className = Array.isArray(value) ? value.join(' ') : value;\n } else if (name === 'textContent') {\n el.textContent = value;\n } else if (name === 'children') {\n for (const child of value) {\n el.appendChild(child);\n }\n } else {\n el.setAttribute(name, value);\n }\n }\n return el;\n};\n\ntype TemplateNode = {\n tag: string\n attrs: Record<string, string>\n children: (TemplateNode | string)[]\n}\n\ntype TagBlock = {\n attrs: Record<string, string>\n content: string\n}\n\nconst elementAttrs = (el: Element): Record<string, string> =>\n Object.fromEntries(Array.from(el.attributes).map(attr => [attr.name, attr.value]))\n\nconst elementToAST = (el: Element): TemplateNode => ({\n tag: el.tagName.toLowerCase(),\n attrs: elementAttrs(el),\n children: Array.from(el.childNodes).flatMap((node): (TemplateNode | string)[] => {\n if (node.nodeType === Node.TEXT_NODE) {\n const text = node.textContent?.trim() ?? \"\"\n return text ? [text] : []\n }\n if (node.nodeType === Node.ELEMENT_NODE) {\n return [elementToAST(node as Element)]\n }\n return []\n })\n})\n\n// evaluated with `with` (rather than passing scope keys as positional params)\n// so only the identifiers an expression actually references are read from\n// `scope` - which is what makes dependency tracking in createReactiveDeepData\n// precise instead of \"read everything up front\". `extras` are passed as\n// function parameters (outside the `with`), so scope keys still win but names\n// like $event resolve when the scope doesn't shadow them\nconst evalExpr = (expr: string, scope: Record<string, any>, extras?: Record<string, any>): any => {\n try {\n return new Function(\"$scope\", ...Object.keys(extras ?? {}), `with ($scope) { return (${expr}); }`)(\n scope,\n ...Object.values(extras ?? {})\n )\n } catch {\n return undefined\n }\n}\n\nconst interpolate = (template: string, scope: Record<string, any>): string =>\n template.replace(/{{\\s*(.+?)\\s*}}/g, (_, expr) => evalExpr(expr, scope) ?? \"\")\n\ntype ChangeListener = (value: any, dotKey: string) => void\ntype AnyChangeListener = (dotKey: string, value: any) => void\ntype ListenerOptions = { immediate?: boolean }\ntype Unsubscribe = () => void\n\ntype ReactiveDeepData<T> = T & {\n $on: (dotKey: string, listener: ChangeListener, options?: ListenerOptions) => Unsubscribe\n $onAny: (listener: AnyChangeListener, options?: ListenerOptions) => Unsubscribe\n // runs `run` immediately, recording every dotKey it reads off this store, then\n // re-runs it whenever a changed dotKey overlaps one of those - see pathsOverlap\n $effect: (run: () => void) => Unsubscribe\n}\n\nconst getByPath = (obj: Record<string, any>, dotKey: string): any =>\n dotKey.split(\".\").reduce((acc, key) => (acc == null ? undefined : acc[key]), obj)\n\n// only plain objects and arrays get deep-wrapped by the reactive store;\n// class instances (Component79, Date, DOM nodes, ...) pass through untouched\n// so their identity, prototypes and internals stay intact\nconst isPlainData = (value: object): boolean => {\n if (Array.isArray(value)) return true\n const proto = Object.getPrototypeOf(value)\n return proto === Object.prototype || proto === null\n}\n\nconst walkLeaves = (obj: Record<string, any>, path: string, visit: (dotKey: string, value: any) => void) => {\n Object.entries(obj).forEach(([key, value]) => {\n const dotKey = path ? `${path}.${key}` : key\n if (value && typeof value === \"object\" && isPlainData(value)) walkLeaves(value, dotKey, visit)\n else visit(dotKey, value)\n })\n}\n\n// true when `a` and `b` sit on the same ancestor/descendant line, e.g.\n// \"user\" & \"user.address.city\" (a change to either affects the other) - false\n// for siblings like \"user.name\" & \"user.age\"\nconst pathsOverlap = (a: string, b: string): boolean =>\n a === b || a.startsWith(`${b}.`) || b.startsWith(`${a}.`)\n\n// active $effect() runs, innermost last - a module-level stack (rather than\n// one per store) so nested effects across stores still nest correctly; reads\n// during makeReactive's `get` trap are attributed to whichever run is on top\nconst trackerStack: Set<string>[] = []\n\n// runs fn with dependency tracking suspended - reads inside it are attributed\n// to a throwaway set instead of the currently running effect\nconst untracked = <T>(fn: () => T): T => {\n trackerStack.push(new Set())\n try {\n return fn()\n } finally {\n trackerStack.pop()\n }\n}\n\ntype Effect = { deps: Set<string>; run: () => void }\n\nexport const createReactiveDeepData = <T extends Record<string, any>>(data: T): ReactiveDeepData<T> => {\n const exactListeners = new Map<string, Set<ChangeListener>>()\n const anyListeners = new Set<AnyChangeListener>()\n const effects = new Set<Effect>()\n // every proxy this store has ever handed out, so re-assigning an object\n // that's already reactive (e.g. `data.list = [data.list[1], data.list[0]]`)\n // doesn't wrap it a second time - which would hand out a *new* object\n // identity for the same logical item, breaking reference-equality checks\n // like :each's keyed diffing\n const reactiveProxies = new WeakSet<object>()\n\n const notify = (dotKey: string, value: any) => {\n exactListeners.get(dotKey)?.forEach(listener => listener(value, dotKey))\n anyListeners.forEach(listener => listener(dotKey, value))\n effects.forEach(effect => {\n if (Array.from(effect.deps).some(dep => pathsOverlap(dep, dotKey))) effect.run()\n })\n }\n\n const makeReactive = (obj: Record<string, any>, path: string): Record<string, any> => {\n if (reactiveProxies.has(obj)) return obj\n\n Object.entries(obj).forEach(([key, value]) => {\n if (value && typeof value === \"object\" && isPlainData(value)) {\n obj[key] = makeReactive(value, path ? `${path}.${key}` : key)\n }\n })\n\n const proxy = new Proxy(obj, {\n get(target, key, receiver) {\n if (typeof key === \"string\") {\n trackerStack[trackerStack.length - 1]?.add(path ? `${path}.${key}` : key)\n }\n return Reflect.get(target, key, receiver)\n },\n set(target, key: string, value, receiver) {\n // an assignment delegated up the prototype chain from a derived scope\n // (Object.create(store) child, or a wrapping proxy): if the key isn't\n // a real property of this store, honor the receiver so the new binding\n // lands on the derived scope - a scope-local variable, not a store\n // mutation, so no notify. If the key IS a store property, fall through\n // and mutate the store itself regardless of receiver, so assignments\n // like @click=\"count = count + 1\" work from any nested scope\n if (receiver !== proxy && !Object.prototype.hasOwnProperty.call(target, key)) {\n return Reflect.set(target, key, value, receiver)\n }\n\n const dotKey = path ? `${path}.${key}` : key\n if (value && typeof value === \"object\" && isPlainData(value)) {\n value = makeReactive(value, dotKey)\n }\n target[key] = value\n notify(dotKey, value)\n return true\n }\n })\n\n reactiveProxies.add(proxy)\n return proxy\n }\n\n const reactive = makeReactive(data, \"\") as ReactiveDeepData<T>\n\n const $on = (dotKey: string, listener: ChangeListener, { immediate = false }: ListenerOptions = {}): Unsubscribe => {\n if (!exactListeners.has(dotKey)) exactListeners.set(dotKey, new Set())\n exactListeners.get(dotKey)!.add(listener)\n if (immediate) listener(getByPath(reactive, dotKey), dotKey)\n return () => exactListeners.get(dotKey)?.delete(listener)\n }\n\n const $onAny = (listener: AnyChangeListener, { immediate = false }: ListenerOptions = {}): Unsubscribe => {\n anyListeners.add(listener)\n if (immediate) walkLeaves(reactive, \"\", (dotKey, value) => listener(dotKey, value))\n return () => anyListeners.delete(listener)\n }\n\n const $effect = (run: () => void): Unsubscribe => {\n const effect: Effect = {\n deps: new Set(),\n run: () => {\n const deps = new Set<string>()\n trackerStack.push(deps)\n try {\n run()\n } finally {\n trackerStack.pop()\n effect.deps = deps\n }\n },\n }\n effects.add(effect)\n effect.run()\n return () => { effects.delete(effect) }\n }\n\n Object.defineProperty(reactive, \"$on\", { value: $on, enumerable: false })\n Object.defineProperty(reactive, \"$onAny\", { value: $onAny, enumerable: false })\n Object.defineProperty(reactive, \"$effect\", { value: $effect, enumerable: false })\n\n return reactive\n}\n\nconst CONTROL_ATTRS = new Set([\":bind\", \":if\", \":elseif\", \":else\", \":each\", \":key\"])\nconst EACH_PATTERN = /^\\s*(\\w+)\\s+in\\s+(.+)$/\n\ntype ConditionalBranch = { expr?: string; node: TemplateNode }\n\n// groups the disposers of every $effect created for one rendered subtree\n// (an :if branch, an :each item, ...) so the whole subtree's bindings can be\n// torn down in one call when that subtree is replaced/removed. `scope.$effect`\n// resolves through the prototype chain up to the root store no matter how\n// many nested :each scopes sit in between (see renderEach's itemScope)\ntype EffectScope = {\n effect: (run: () => void) => void\n // registers an arbitrary cleanup (e.g. destroying a nested component) to\n // run when this subtree is torn down\n onDispose: (fn: Unsubscribe) => void\n dispose: () => void\n}\n\nconst createEffectScope = (scope: Record<string, any>): EffectScope => {\n const disposers: Unsubscribe[] = []\n return {\n effect: run => { disposers.push(scope.$effect(run)) },\n onDispose: fn => { disposers.push(fn) },\n dispose: () => { disposers.splice(0).forEach(dispose => dispose()) },\n }\n}\n\n// @event attributes: @click=\"onClick\", @submit.prevent=\"$event => onSubmit($event)\",\n// or an inline statement like @click=\"count = count + 1\". The expression is\n// evaluated (with `$event` in scope) on every event; if it yields a function,\n// that function is then invoked with the event - so both a handler reference\n// and an inline arrow/statement work. Modifiers after dots: .prevent .stop\n// .self (runtime guards) and .once .capture (addEventListener options)\nconst bindEvent = (el: Element, attr: string, expr: string, scope: Record<string, any>) => {\n const [name, ...modifiers] = attr.slice(1).split(\".\")\n const mods = new Set(modifiers)\n\n el.addEventListener(name, event => {\n if (mods.has(\"self\") && event.target !== el) return\n if (mods.has(\"prevent\")) event.preventDefault()\n if (mods.has(\"stop\")) event.stopPropagation()\n\n const handler = evalExpr(expr, scope, { $event: event })\n if (typeof handler === \"function\") handler.call(el, event)\n }, { once: mods.has(\"once\"), capture: mods.has(\"capture\") })\n}\n\nconst kebabToCamel = (name: string) => name.replace(/-(\\w)/g, (_, c: string) => c.toUpperCase())\n\n// finds the scope variable a template tag refers to. HTML parsing lowercases\n// tag names, so <NestedComponent> arrives as \"nestedcomponent\" and matching is\n// case-insensitive with dashes stripped (<nested-component> works too). Only\n// PascalCase scope keys participate, so ordinary variables named like real\n// elements (title, code, ...) never hijack them\nconst findComponentKey = (scope: Record<string, any>, tag: string): string | null => {\n const normalized = tag.replace(/-/g, \"\").toLowerCase()\n for (let obj: any = scope; obj && obj !== Object.prototype; obj = Object.getPrototypeOf(obj)) {\n for (const key of Object.keys(obj)) {\n if (/^[A-Z]/.test(key) && key.replace(/-/g, \"\").toLowerCase() === normalized) return key\n }\n }\n return null\n}\n\n// <MyComponent :user :title=\"'str'\"></MyComponent> - renders a child\n// component instance at this position. Props: `:name=\"expr\"` evaluates expr\n// in the parent scope (`:name` alone is shorthand for `:name=\"name\"`), plain\n// attributes pass through as literal strings, and kebab-case prop names\n// become camelCase. Props stay live: a parent effect re-evaluates each\n// expression and writes it into the child's store. The component variable is\n// reactive too - while it's undefined (e.g. an `await import(...)` still in\n// flight) nothing renders, and the child appears when it resolves\nconst renderNestedComponent = (key: string, node: TemplateNode, scope: Record<string, any>, fx: EffectScope): Node => {\n const anchor = document.createComment(key)\n const wrapper = document.createDocumentFragment()\n wrapper.appendChild(anchor)\n\n const props: Record<string, string> = {} // prop name -> expression in parent scope\n Object.entries(node.attrs).forEach(([attr, value]) => {\n if (CONTROL_ATTRS.has(attr) || attr.startsWith(\"@\")) return\n if (attr.startsWith(\":\")) {\n const name = kebabToCamel(attr.slice(1))\n props[name] = value || name\n } else {\n props[kebabToCamel(attr)] = JSON.stringify(value)\n }\n })\n\n let current: Component79 | null = null\n let currentDef: Component79 | null = null\n let childFx: EffectScope | null = null\n\n fx.effect(() => {\n const value = evalExpr(key, scope)\n const nextDef = value instanceof Component79 ? value : null\n if (nextDef === currentDef) return\n\n childFx?.dispose()\n childFx = null\n current?.destroy() // unmounts its marker range, removing the child's DOM\n current = null\n currentDef = nextDef\n if (!nextDef) return\n\n // a fresh instance per usage site: the definition's parsed parts are\n // shared, but store/effects/DOM are per instance\n const instance = new Component79({ template: nextDef.template, scripts: nextDef.scripts, styles: nextDef.styles })\n const seed = untracked(() =>\n Object.fromEntries(Object.entries(props).map(([name, expr]) => [name, evalExpr(expr, scope)]))\n )\n const holder = document.createDocumentFragment()\n instance.render(seed).mount(holder)\n anchor.parentNode!.insertBefore(holder, anchor.nextSibling)\n\n const syncFx = createEffectScope(scope)\n Object.entries(props).forEach(([name, expr]) => {\n syncFx.effect(() => { (instance.data as Record<string, any>)[name] = evalExpr(expr, scope) })\n })\n\n childFx = syncFx\n current = instance\n })\n\n fx.onDispose(() => {\n childFx?.dispose()\n current?.destroy()\n })\n\n return wrapper\n}\n\n// renders a single element node: static attrs, @event listeners, a reactive\n// :bind object, and its (reactive) children. :if/:elseif/:else/:each are\n// handled by renderNodes, which decides *whether*/*how many times* a node is\n// rendered before calling this. Tags matching a PascalCase scope variable\n// render as nested components instead\nconst renderNode = (node: TemplateNode, scope: Record<string, any>, fx: EffectScope): Node => {\n const componentKey = findComponentKey(scope, node.tag)\n if (componentKey) return renderNestedComponent(componentKey, node, scope, fx)\n\n const el = document.createElement(node.tag)\n\n Object.entries(node.attrs).forEach(([key, value]) => {\n if (key.startsWith(\"@\")) bindEvent(el, key, value, scope)\n else if (!CONTROL_ATTRS.has(key)) el.setAttribute(key, value)\n })\n\n const bindExpr = node.attrs[\":bind\"]\n if (bindExpr !== undefined) {\n let boundKeys: string[] = []\n\n fx.effect(() => {\n boundKeys.forEach(key => el.removeAttribute(key))\n const bound = evalExpr(bindExpr, scope)\n boundKeys = bound && typeof bound === \"object\" ? Object.keys(bound) : []\n boundKeys.forEach(key => {\n const value = bound[key]\n if (value != null && value !== false) el.setAttribute(key, String(value))\n })\n })\n }\n\n el.appendChild(renderNodes(node.children, scope, fx))\n\n return el\n}\n\n// a :if/:elseif*/:else? chain sharing one anchor comment so the active branch\n// can be swapped in place without disturbing sibling positions. Only depends\n// on whatever the branch expressions read (e.g. \"score\"), and skips\n// rebuilding entirely when the active branch hasn't actually changed\nconst renderConditional = (branches: ConditionalBranch[], scope: Record<string, any>, fx: EffectScope): Node => {\n const anchor = document.createComment(\"if\")\n const wrapper = document.createDocumentFragment()\n wrapper.appendChild(anchor)\n\n let current: Node | null = null\n let activeBranch: ConditionalBranch | null = null\n let branchFx: EffectScope | null = null\n\n fx.effect(() => {\n const next = branches.find(branch => branch.expr === undefined || evalExpr(branch.expr, scope)) ?? null\n if (next === activeBranch) return\n\n branchFx?.dispose()\n if (current) current.parentNode?.removeChild(current)\n current = null\n activeBranch = next\n if (!next) return\n\n branchFx = createEffectScope(scope)\n current = renderNode(next.node, scope, branchFx)\n anchor.parentNode!.insertBefore(current, anchor.nextSibling)\n })\n\n return wrapper\n}\n\n// defines a loop-local binding directly as `scope`'s own property. Plain\n// assignment (scope[key] = value) would only do this if the key isn't\n// already own on `scope` *or anywhere up its prototype chain* - if it isn't,\n// JS delegates the [[Set]] to whatever's up there, which for us is another\n// reactive proxy's `set` trap: it would wrap `value` as if it were a genuine\n// store mutation and fire a bogus notify() under a name (e.g. \"item\") shared\n// by every unrelated item in every :each on the page. defineProperty always\n// writes to `scope` itself, never delegating, so this can't happen\nconst defineScopeVar = (scope: Record<string, any>, key: string, value: any) => {\n Object.defineProperty(scope, key, { value, writable: true, enumerable: true, configurable: true })\n}\n\ntype EachEntry = { key: any; item: any; scope: Record<string, any>; node: Node; fx: EffectScope }\n\n// :each=\"item in items\", optionally keyed with :key=\"expr\". Only depends on\n// the list expression itself (e.g. \"items\"), and on each run diffs by key:\n// unchanged items (same key, same item reference) keep their DOM/effects,\n// changed/added ones are (re)rendered, removed ones are disposed. Without\n// :key, position is used as the key, so reordering rebuilds every item after\n// the first change - add :key for anything that gets reordered or filtered.\n// Each item gets its own scope via Object.create(scope), so `item`/`$index`\n// shadow same-named outer bindings without copying the parent scope's keys\nconst renderEach = (node: TemplateNode, scope: Record<string, any>, fx: EffectScope): Node => {\n const match = node.attrs[\":each\"].match(EACH_PATTERN)\n if (!match) return document.createComment(`invalid :each expression \"${node.attrs[\":each\"]}\"`)\n\n const [, itemName, listExpr] = match\n const keyExpr = node.attrs[\":key\"]\n const { [\":each\"]: _each, [\":key\"]: _key, ...itemAttrs } = node.attrs\n const itemNode: TemplateNode = { ...node, attrs: itemAttrs }\n\n const anchor = document.createComment(\"each\")\n const wrapper = document.createDocumentFragment()\n wrapper.appendChild(anchor)\n\n let entries: EachEntry[] = []\n\n fx.effect(() => {\n const list = evalExpr(listExpr, scope)\n const items = Array.isArray(list) ? list : []\n const previous = new Map(entries.map(entry => [entry.key, entry]))\n\n const nextEntries = items.map((item, index): EachEntry => {\n const itemScope = Object.create(scope)\n defineScopeVar(itemScope, itemName, item)\n defineScopeVar(itemScope, \"$index\", index)\n const key = keyExpr !== undefined ? evalExpr(keyExpr, itemScope) : index\n const existing = previous.get(key)\n\n if (existing && Object.is(existing.item, item)) {\n defineScopeVar(existing.scope, \"$index\", index)\n return existing\n }\n\n existing?.fx.dispose()\n existing?.node.parentNode?.removeChild(existing.node)\n\n const itemFx = createEffectScope(scope)\n return { key, item, scope: itemScope, fx: itemFx, node: renderNode(itemNode, itemScope, itemFx) }\n })\n\n const nextKeys = new Set(nextEntries.map(entry => entry.key))\n entries.forEach(entry => {\n if (!nextKeys.has(entry.key)) {\n entry.fx.dispose()\n entry.node.parentNode?.removeChild(entry.node)\n }\n })\n\n let prevNode: Node = anchor\n nextEntries.forEach(entry => {\n if (prevNode.nextSibling !== entry.node) anchor.parentNode!.insertBefore(entry.node, prevNode.nextSibling)\n prevNode = entry.node\n })\n\n entries = nextEntries\n })\n\n return wrapper\n}\n\n// renders a list of sibling template nodes (text + elements), grouping\n// consecutive :if/:elseif/:else nodes into a single conditional block\nconst renderNodes = (nodes: (TemplateNode | string)[], scope: Record<string, any>, fx: EffectScope): DocumentFragment => {\n const fragment = document.createDocumentFragment()\n let i = 0\n\n while (i < nodes.length) {\n const node = nodes[i]\n\n if (typeof node === \"string\") {\n const textNode = document.createTextNode(\"\")\n fx.effect(() => { textNode.textContent = interpolate(node, scope) })\n fragment.appendChild(textNode)\n i++\n continue\n }\n\n if (\":each\" in node.attrs) {\n fragment.appendChild(renderEach(node, scope, fx))\n i++\n continue\n }\n\n if (\":if\" in node.attrs) {\n const branches: ConditionalBranch[] = [{ expr: node.attrs[\":if\"], node }]\n i++\n while (i < nodes.length && typeof nodes[i] !== \"string\" && \":elseif\" in (nodes[i] as TemplateNode).attrs) {\n const elseifNode = nodes[i] as TemplateNode\n branches.push({ expr: elseifNode.attrs[\":elseif\"], node: elseifNode })\n i++\n }\n if (i < nodes.length && typeof nodes[i] !== \"string\" && \":else\" in (nodes[i] as TemplateNode).attrs) {\n branches.push({ node: nodes[i] as TemplateNode })\n i++\n }\n\n fragment.appendChild(renderConditional(branches, scope, fx))\n continue\n }\n\n fragment.appendChild(renderNode(node, scope, fx))\n i++\n }\n\n return fragment\n}\n\nexport const renderComponent = (component: Component79, data: ReactiveDeepData<Record<string, any>>): Node =>\n renderNodes(component.template, data, createEffectScope(data))\n\ntype ComponentParts = {\n template: TemplateNode[]\n scripts: TagBlock[]\n styles: TagBlock[]\n}\n\nconst VOID_ELEMENTS = new Set([\n \"area\", \"base\", \"br\", \"col\", \"embed\", \"hr\", \"img\", \"input\",\n \"link\", \"meta\", \"param\", \"source\", \"track\", \"wbr\",\n])\n\n// a self-closing tag with its attributes; quoted attribute values are matched\n// as whole chunks so a \"/>\" inside one doesn't end the tag early\nconst SELF_CLOSING_RE = /<([A-Za-z][\\w-]*)((?:\"[^\"]*\"|'[^']*'|[^>\"'])*?)\\/>/g\nconst RAW_BLOCK_RE = /(<script[\\s\\S]*?<\\/script\\s*>|<style[\\s\\S]*?<\\/style\\s*>)/gi\n\n// expands self-closing tags (<MyComponent />, <div />) into explicit\n// open+close pairs BEFORE DOM parsing. The HTML parser ignores the slash and\n// would treat them as unclosed, swallowing the following siblings. Void\n// elements keep their native behavior, and <script>/<style> contents are\n// passed through untouched so code inside them is never rewritten\nconst expandSelfClosingTags = (src: string): string =>\n src\n .split(RAW_BLOCK_RE)\n .map((chunk, i) =>\n i % 2 === 1 // odd chunks are the captured script/style blocks\n ? chunk\n : chunk.replace(SELF_CLOSING_RE, (match, tag: string, attrs: string) =>\n VOID_ELEMENTS.has(tag.toLowerCase()) ? match : `<${tag}${attrs}></${tag}>`\n )\n )\n .join(\"\")\n\n// converts a string of HTML into an AST representation of the component:\n// - template: the non-script/style top-level elements, as TemplateNodes\n// - scripts/styles: { attrs, content } blocks in source order\nconst parseComponentString = (component: string): ComponentParts => {\n // example\n // <script :setup=\"{ fname, lname }\">\n // const fullName = `${fname} ${lname}`\n // </script>\n //\n // <div :bind=\"{ fullName }\"></div>\n // <div class=\"full-name\">\n // {{ fullName }}\n // </div>\n //\n // <style>\n // .full-name {\n // color: red;\n // }\n // </style>\n\n // parsed as the content of a <template> so leading <script>/<style> tags\n // aren't reparented into <head> by the HTML parser\n const parsedDOM = new DOMParser().parseFromString(`<template>${expandSelfClosingTags(component)}</template>`, \"text/html\")\n const root = parsedDOM.querySelector(\"template\") as HTMLTemplateElement\n\n const scripts: TagBlock[] = []\n const styles: TagBlock[] = []\n const template: TemplateNode[] = []\n\n Array.from(root.content.children).forEach(el => {\n const block = { attrs: elementAttrs(el), content: el.textContent ?? \"\" }\n\n if (el.tagName === \"SCRIPT\") scripts.push(block)\n else if (el.tagName === \"STYLE\") styles.push(block)\n else template.push(elementToAST(el))\n })\n\n return { template, scripts, styles }\n}\n\n// ---------------------------------------------------------------------------\n// :setup script transform\n//\n// setup scripts are written like Svelte components:\n//\n// let firstName = null\n// $: fullName = `${firstName} ${lastName}`\n// fetchUser().then(user => { firstName = user.firstName })\n//\n// and are executed inside `with ($scope)` against the component's reactive\n// store, so plain assignments (even from async callbacks) go through the\n// proxy's set trap and re-render whatever depends on them. To make that work\n// the source is lightly rewritten - no full JS parser, just a scanner that is\n// string/comment-aware and only touches code at brace/paren depth 0:\n// - `let/var/const x = ...` at the top level loses its keyword, becoming a\n// scope assignment (the name is pre-declared on the store so the `with`\n// lookup resolves it)\n// - `$: x = expr` becomes `$__effect(() => { x = expr })`, re-running when a\n// dependency read inside expr changes ($__effect is deliberately NOT a\n// property of the scope, so `with` falls through to the function parameter)\n// ---------------------------------------------------------------------------\n\ntype SetupTransform = { vars: string[]; code: string }\n\nconst DECLARATION_RE = /(?:let|var|const)\\s+([A-Za-z_$][\\w$]*)/y\nconst REACTIVE_LABEL_RE = /\\$:\\s*/y\nconst IMPORT_CALL_RE = /import(?=\\s*\\()/y\nconst REACTIVE_ASSIGN_RE = /\\$:\\s*([A-Za-z_$][\\w$]*)\\s*=(?!=)/y\n\nconst skipString = (src: string, start: number): number => {\n const quote = src[start]\n let i = start + 1\n while (i < src.length) {\n if (src[i] === \"\\\\\") { i += 2; continue }\n if (src[i] === quote) return i + 1\n i++\n }\n return src.length\n}\n\nconst skipLineComment = (src: string, start: number): number => {\n const end = src.indexOf(\"\\n\", start)\n return end === -1 ? src.length : end\n}\n\nconst skipBlockComment = (src: string, start: number): number => {\n const end = src.indexOf(\"*/\", start + 2)\n return end === -1 ? src.length : end + 2\n}\n\n// end of a statement starting at `start`: the first newline or `;` that isn't\n// inside a string/comment or unbalanced brackets, so multi-line RHS like a\n// wrapped function call or template literal stays in one piece\nconst findStatementEnd = (src: string, start: number): number => {\n let depth = 0\n let i = start\n while (i < src.length) {\n const ch = src[i]\n if (ch === \"'\" || ch === '\"' || ch === \"`\") { i = skipString(src, i); continue }\n if (ch === \"/\" && src[i + 1] === \"/\") { i = skipLineComment(src, i); continue }\n if (ch === \"/\" && src[i + 1] === \"*\") { i = skipBlockComment(src, i); continue }\n if (\"([{\".includes(ch)) depth++\n else if (\")]}\".includes(ch)) depth--\n else if (depth <= 0 && (ch === \"\\n\" || ch === \";\")) return i\n i++\n }\n return src.length\n}\n\nconst transformSetupScript = (src: string): SetupTransform => {\n const vars: string[] = []\n let out = \"\"\n let i = 0\n let depth = 0\n let atStatementStart = true\n\n while (i < src.length) {\n const ch = src[i]\n const next = src[i + 1]\n\n if (ch === \"'\" || ch === '\"' || ch === \"`\") {\n const end = skipString(src, i)\n out += src.slice(i, end)\n i = end\n atStatementStart = false\n continue\n }\n if (ch === \"/\" && (next === \"/\" || next === \"*\")) {\n const end = next === \"/\" ? skipLineComment(src, i) : skipBlockComment(src, i)\n out += src.slice(i, end)\n i = end\n continue\n }\n\n // `import(...)` is a keyword form, so it can't be intercepted through the\n // scope - rewrite the identifier to the injected $__import (which loads\n // .html URLs as components via Component79.fetch and delegates the rest to\n // native import). The `(` is left for the scanner so depth stays balanced\n if (ch === \"i\" && (i === 0 || !/[\\w$.]/.test(src[i - 1]))) {\n IMPORT_CALL_RE.lastIndex = i\n if (IMPORT_CALL_RE.test(src)) {\n out += \"$__import\"\n i += \"import\".length\n atStatementStart = false\n continue\n }\n }\n\n if (depth === 0 && atStatementStart) {\n DECLARATION_RE.lastIndex = i\n const decl = DECLARATION_RE.exec(src)\n if (decl) {\n vars.push(decl[1])\n out += decl[1]\n i += decl[0].length\n atStatementStart = false\n continue\n }\n\n REACTIVE_LABEL_RE.lastIndex = i\n const label = REACTIVE_LABEL_RE.exec(src)\n if (label) {\n REACTIVE_ASSIGN_RE.lastIndex = i\n const assign = REACTIVE_ASSIGN_RE.exec(src)\n if (assign) vars.push(assign[1])\n const start = i + label[0].length\n const end = findStatementEnd(src, start)\n out += `$__effect(() => { ${src.slice(start, end)} });`\n i = end\n continue\n }\n }\n\n if (\"([{\".includes(ch)) depth++\n else if (\")]}\".includes(ch)) depth = Math.max(0, depth - 1)\n\n if (ch === \"\\n\" || ch === \";\" || ch === \"}\") atStatementStart = true\n else if (!/\\s/.test(ch)) atStatementStart = false\n\n out += ch\n i++\n }\n\n return { vars, code: out }\n}\n\n// loads .html URLs as components, delegating anything else to native import()\nconst importResource = (url: string): Promise<any> =>\n /\\.html?([?#]|$)/.test(url) ? Component79.fetch(url) : import(url)\n\n// document.head styles are shared by content and refcounted, so N instances\n// of the same component (e.g. one per :each item) inject a single <style> tag\n// that goes away when the last instance is destroyed\nconst styleRegistry = new Map<string, { el: HTMLStyleElement; count: number }>()\n\nconst acquireStyle = (content: string) => {\n let entry = styleRegistry.get(content)\n if (!entry) {\n const el = document.createElement(\"style\")\n el.textContent = content\n document.head.appendChild(el)\n entry = { el, count: 0 }\n styleRegistry.set(content, entry)\n }\n entry.count++\n}\n\nconst releaseStyle = (content: string) => {\n const entry = styleRegistry.get(content)\n if (entry && --entry.count <= 0) {\n entry.el.remove()\n styleRegistry.delete(content)\n }\n}\n\n// scripts run inside `with (scriptScope)`, where scriptScope's `has` trap\n// claims ownership of every name that is neither a real global nor one of the\n// injected helpers. This makes `with` route ALL other reads/writes through the\n// reactive store - even bare assignments to names never declared with\n// let/const, which would otherwise leak onto globalThis - while `console`,\n// `Promise`, `fetch`, etc. still resolve normally. get/set are deliberately\n// not trapped: they default-forward to `scope` (the reactive proxy),\n// preserving tracking and notify.\n// The body is wrapped in an async IIFE so top-level `await` works: everything\n// up to the first await runs synchronously (before the template renders), and\n// later assignments update the DOM reactively when they happen\nconst runSetupScript = (code: string, scope: Record<string, any>, effect: (run: () => void) => void) => {\n const scriptScope = new Proxy(scope, {\n has: (target, key) =>\n key !== \"$__effect\" && key !== \"$__import\" && (Reflect.has(target, key) || !(key in globalThis)),\n })\n const result: Promise<void> = new Function(\n \"$scope\", \"$__effect\", \"$__import\",\n `return (async () => { with ($scope) { ${code} } })()`\n )(scriptScope, effect, importResource)\n result.catch(error => console.error(\"jq79: error in :setup script\", error))\n}\n\n// a parsed single-file component. Typical lifecycle:\n//\n// const jq79 = new Component79(src) // or await Component79.fetch(url)\n// jq79.render({ user }) // build reactive DOM, run scripts, inject styles\n// .mount(\"#app\") // attach (renderShadow mounts into a shadow root)\n// ...\n// jq79.unmount() // detach, keeping state - mount() re-attaches\n// .destroy() // dispose effects and remove styles\nexport class Component79 {\n template: TemplateNode[]\n scripts: TagBlock[]\n styles: TagBlock[]\n\n data: ReactiveDeepData<Record<string, any>> | null = null\n\n private fx: EffectScope | null = null\n // holds the rendered nodes while unmounted; anchors keep this fragment as\n // their parentNode, so effects keep the (detached) DOM up to date and a\n // later mount() shows current state\n private content: DocumentFragment | null = null\n // markers bracketing the component's output so unmount() can collect nodes\n // that :if/:each inserted next to the anchors after mounting\n private startMarker: Comment | null = null\n private endMarker: Comment | null = null\n // shadow rendering keeps per-instance <style> elements; head rendering goes\n // through the shared refcounted styleRegistry instead\n private styleEls: HTMLStyleElement[] = []\n private ownsSharedStyles = false\n private useShadow = false\n private mountRoot: Element | ShadowRoot | DocumentFragment | null = null\n\n constructor(src: string | ComponentParts) {\n const { template, scripts, styles } = typeof src === \"string\" ? parseComponentString(src) : src\n this.template = template\n this.scripts = scripts\n this.styles = styles\n }\n\n static async fetch(url: string): Promise<Component79> {\n const response = await fetch(url)\n if (!response.ok) throw new Error(`failed to fetch component from ${url}: ${response.status}`)\n return new Component79(await response.text())\n }\n\n render(data: Record<string, any> = {}): this {\n return this.renderWith(data, false)\n }\n\n // like render(), but styles are injected into a shadow root attached to the\n // mount target instead of document.head, so they don't leak globally\n renderShadow(data: Record<string, any> = {}): this {\n return this.renderWith(data, true)\n }\n\n private renderWith(data: Record<string, any>, shadow: boolean): this {\n this.destroy()\n\n const store = createReactiveDeepData({ ...data })\n const fx = createEffectScope(store)\n this.data = store\n this.fx = fx\n this.useShadow = shadow\n\n // scripts run before the template renders so `$:` values are initialized\n this.scripts.forEach(script => {\n const { vars, code } = transformSetupScript(script.content)\n // pre-declare script vars on the store so `with` resolves assignments\n // to them (and reads of them) through the reactive proxy\n vars.forEach(name => { if (!(name in store)) (store as any)[name] = undefined })\n runSetupScript(code, store, fx.effect)\n })\n\n this.startMarker = document.createComment(\"jq79\")\n this.endMarker = document.createComment(\"/jq79\")\n const content = document.createDocumentFragment()\n content.append(this.startMarker, renderNodes(this.template, store, fx), this.endMarker)\n this.content = content\n\n if (shadow) {\n this.styleEls = this.styles.map(style => {\n const el = document.createElement(\"style\")\n el.textContent = style.content\n return el\n })\n } else {\n this.styles.forEach(style => acquireStyle(style.content))\n this.ownsSharedStyles = true\n }\n\n return this\n }\n\n mount(parent: Element | ShadowRoot | DocumentFragment | string): this {\n const target = typeof parent === \"string\" ? $(parent) : parent\n if (!target) throw new Error(`mount target not found: ${parent}`)\n if (!this.content) throw new Error(\"render() must be called before mount()\")\n if (this.mountRoot) this.unmount()\n\n const root = this.useShadow && target instanceof Element\n ? target.shadowRoot ?? target.attachShadow({ mode: \"open\" })\n : target\n if (this.useShadow) this.styleEls.forEach(el => root.appendChild(el))\n root.appendChild(this.content)\n this.mountRoot = root\n return this\n }\n\n unmount(): this {\n if (!this.mountRoot || !this.content || !this.startMarker || !this.endMarker) return this\n\n // move everything between the markers (inclusive) back into the holding\n // fragment - including nodes :if/:each inserted after mounting\n let node: Node | null = this.startMarker\n while (node) {\n const nextNode: Node | null = node.nextSibling\n this.content.appendChild(node)\n if (node === this.endMarker) break\n node = nextNode\n }\n\n this.mountRoot = null\n return this\n }\n\n destroy(): this {\n this.unmount()\n this.fx?.dispose()\n this.fx = null\n this.styleEls.forEach(el => el.parentNode?.removeChild(el))\n this.styleEls = []\n if (this.ownsSharedStyles) {\n this.styles.forEach(style => releaseStyle(style.content))\n this.ownsSharedStyles = false\n }\n this.content = null\n this.startMarker = null\n this.endMarker = null\n this.data = null\n return this\n }\n}\n\nexport const parseComponent = (component: string): Component79 => new Component79(component)\n\n"],"mappings":"0iBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,OAAAE,EAAA,OAAAC,GAAA,YAAAC,GAAA,gBAAAC,EAAA,2BAAAC,EAAA,mBAAAC,GAAA,oBAAAC,KAAA,eAAAC,GAAAT,IACO,IAAMU,EAAI,CAACC,EAAgCC,IAChD,OAAOD,GAAiB,SACpB,SAAS,cAAcA,CAAY,EACnCA,EAAa,cAAcC,GAAY,EAAE,EAElCC,GAAK,CAACF,EAAgCC,IAAsB,MAAM,KAC7E,OAAOD,GAAiB,SACpB,SAAS,iBAAiBA,CAAY,EACtCA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7BA,EAAOqK,CACT,CAEA,YAAK,UAAY,KACV,IACT,CAEA,SAAgB,CACd,YAAK,QAAQ,EACb,KAAK,IAAI,QAAQ,EACjB,KAAK,GAAK,KACV,KAAK,SAAS,QAAQ5K,GAAMA,EAAG,YAAY,YAAYA,CAAE,CAAC,EAC1D,KAAK,SAAW,CAAC,EACb,KAAK,mBACP,KAAK,OAAO,QAAQ0K,GAASX,GAAaW,EAAM,OAAO,CAAC,EACxD,KAAK,iBAAmB,IAE1B,KAAK,QAAU,KACf,KAAK,YAAc,KACnB,KAAK,UAAY,KACjB,KAAK,KAAO,KACL,IACT,CACF,EAEaG,GAAkBnD,GAAmC,IAAI9C,EAAY8C,CAAS","names":["jq79_exports","__export","$","$$","$create","Component79","createReactiveDeepData","parseComponent","renderComponent","__toCommonJS","$","selectorOrEl","selector","$$","$create","tag","attrs","el","name","value","child","elementAttrs","attr","elementToAST","node","text","evalExpr","expr","scope","extras","interpolate","template","_","getByPath","obj","dotKey","acc","key","isPlainData","proto","walkLeaves","path","visit","pathsOverlap","a","b","trackerStack","untracked","fn","createReactiveDeepData","data","exactListeners","anyListeners","effects","reactiveProxies","notify","listener","effect","dep","makeReactive","proxy","target","receiver","reactive","$on","immediate","$onAny","$effect","run","deps","CONTROL_ATTRS","EACH_PATTERN","createEffectScope","disposers","dispose","bindEvent","modifiers","mods","event","handler","kebabToCamel","c","findComponentKey","normalized","renderNestedComponent","fx","anchor","wrapper","props","current","currentDef","childFx","nextDef","Component79","instance","seed","holder","syncFx","renderNode","componentKey","bindExpr","boundKeys","bound","renderNodes","renderConditional","branches","activeBranch","branchFx","next","branch","defineScopeVar","renderEach","match","itemName","listExpr","keyExpr","_each","_key","itemAttrs","itemNode","entries","list","items","previous","entry","nextEntries","item","index","itemScope","existing","itemFx","nextKeys","prevNode","nodes","fragment","i","textNode","elseifNode","renderComponent","component","VOID_ELEMENTS","SELF_CLOSING_RE","RAW_BLOCK_RE","expandSelfClosingTags","src","chunk","parseComponentString","root","scripts","styles","block","DECLARATION_RE","REACTIVE_LABEL_RE","IMPORT_CALL_RE","REACTIVE_ASSIGN_RE","skipString","start","quote","skipLineComment","end","skipBlockComment","findStatementEnd","depth","ch","transformSetupScript","vars","out","atStatementStart","decl","label","assign","importResource","url","styleRegistry","acquireStyle","content","releaseStyle","runSetupScript","code","scriptScope","error","_Component79","__publicField","response","shadow","store","script","style","parent","nextNode","parseComponent"]}
package/dist/jq79.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export declare const $: (selectorOrEl: string | Element, selector?: string) => Element | null;
2
2
  export declare const $$: (selectorOrEl: string | Element, selector?: string) => Element[];
3
+ export declare const $create: (tag: string, attrs?: Record<string, any>) => HTMLElement;
3
4
  type TemplateNode = {
4
5
  tag: string;
5
6
  attrs: Record<string, string>;
@@ -1,5 +1,5 @@
1
- var jq79=(()=>{var $=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var ee=(e,t,n)=>t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var te=(e,t)=>{for(var n in t)$(e,n,{get:t[n],enumerable:!0})},ne=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Y(t))!Q.call(e,s)&&s!==n&&$(e,s,{get:()=>t[s],enumerable:!(r=X(t,s))||r.enumerable});return e};var re=e=>ne($({},"__esModule",{value:!0}),e);var E=(e,t,n)=>ee(e,typeof t!="symbol"?t+"":t,n);var Oe={};te(Oe,{$:()=>U,$$:()=>se,Component79:()=>w,createReactiveDeepData:()=>V,parseComponent:()=>$e,renderComponent:()=>me});var U=(e,t)=>typeof e=="string"?document.querySelector(e):e.querySelector(t||""),se=(e,t)=>Array.from(typeof e=="string"?document.querySelectorAll(e):e.querySelectorAll(t||"")),W=e=>Object.fromEntries(Array.from(e.attributes).map(t=>[t.name,t.value])),z=e=>({tag:e.tagName.toLowerCase(),attrs:W(e),children:Array.from(e.childNodes).flatMap(t=>{if(t.nodeType===Node.TEXT_NODE){let n=t.textContent?.trim()??"";return n?[n]:[]}return t.nodeType===Node.ELEMENT_NODE?[z(t)]:[]})}),S=(e,t,n)=>{try{return new Function("$scope",...Object.keys(n??{}),`with ($scope) { return (${e}); }`)(t,...Object.values(n??{}))}catch{return}},oe=(e,t)=>e.replace(/{{\s*(.+?)\s*}}/g,(n,r)=>S(r,t)??""),ie=(e,t)=>t.split(".").reduce((n,r)=>n?.[r],e),D=e=>{if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},H=(e,t,n)=>{Object.entries(e).forEach(([r,s])=>{let i=t?`${t}.${r}`:r;s&&typeof s=="object"&&D(s)?H(s,i,n):n(i,s)})},ce=(e,t)=>e===t||e.startsWith(`${t}.`)||t.startsWith(`${e}.`),R=[],ae=e=>{R.push(new Set);try{return e()}finally{R.pop()}},V=e=>{let t=new Map,n=new Set,r=new Set,s=new WeakSet,i=(a,l)=>{t.get(a)?.forEach(p=>p(l,a)),n.forEach(p=>p(a,l)),r.forEach(p=>{Array.from(p.deps).some(h=>ce(h,a))&&p.run()})},o=(a,l)=>{if(s.has(a))return a;Object.entries(a).forEach(([h,u])=>{u&&typeof u=="object"&&D(u)&&(a[h]=o(u,l?`${l}.${h}`:h))});let p=new Proxy(a,{get(h,u,g){return typeof u=="string"&&R[R.length-1]?.add(l?`${l}.${u}`:u),Reflect.get(h,u,g)},set(h,u,g,b){if(b!==p&&!Object.prototype.hasOwnProperty.call(h,u))return Reflect.set(h,u,g,b);let N=l?`${l}.${u}`:u;return g&&typeof g=="object"&&D(g)&&(g=o(g,N)),h[u]=g,i(N,g),!0}});return s.add(p),p},c=o(e,""),d=(a,l,{immediate:p=!1}={})=>(t.has(a)||t.set(a,new Set),t.get(a).add(l),p&&l(ie(c,a),a),()=>t.get(a)?.delete(l)),f=(a,{immediate:l=!1}={})=>(n.add(a),l&&H(c,"",(p,h)=>a(p,h)),()=>n.delete(a)),y=a=>{let l={deps:new Set,run:()=>{let p=new Set;R.push(p);try{a()}finally{R.pop(),l.deps=p}}};return r.add(l),l.run(),()=>{r.delete(l)}};return Object.defineProperty(c,"$on",{value:d,enumerable:!1}),Object.defineProperty(c,"$onAny",{value:f,enumerable:!1}),Object.defineProperty(c,"$effect",{value:y,enumerable:!1}),c},Z=new Set([":bind",":if",":elseif",":else",":each",":key"]),le=/^\s*(\w+)\s+in\s+(.+)$/,x=e=>{let t=[];return{effect:n=>{t.push(e.$effect(n))},onDispose:n=>{t.push(n)},dispose:()=>{t.splice(0).forEach(n=>n())}}},de=(e,t,n,r)=>{let[s,...i]=t.slice(1).split("."),o=new Set(i);e.addEventListener(s,c=>{if(o.has("self")&&c.target!==e)return;o.has("prevent")&&c.preventDefault(),o.has("stop")&&c.stopPropagation();let d=S(n,r,{$event:c});typeof d=="function"&&d.call(e,c)},{once:o.has("once"),capture:o.has("capture")})},P=e=>e.replace(/-(\w)/g,(t,n)=>n.toUpperCase()),pe=(e,t)=>{let n=t.replace(/-/g,"").toLowerCase();for(let r=e;r&&r!==Object.prototype;r=Object.getPrototypeOf(r))for(let s of Object.keys(r))if(/^[A-Z]/.test(s)&&s.replace(/-/g,"").toLowerCase()===n)return s;return null},fe=(e,t,n,r)=>{let s=document.createComment(e),i=document.createDocumentFragment();i.appendChild(s);let o={};Object.entries(t.attrs).forEach(([y,a])=>{if(!(Z.has(y)||y.startsWith("@")))if(y.startsWith(":")){let l=P(y.slice(1));o[l]=a||l}else o[P(y)]=JSON.stringify(a)});let c=null,d=null,f=null;return r.effect(()=>{let y=S(e,n),a=y instanceof w?y:null;if(a===d||(f?.dispose(),f=null,c?.destroy(),c=null,d=a,!a))return;let l=new w({template:a.template,scripts:a.scripts,styles:a.styles}),p=ae(()=>Object.fromEntries(Object.entries(o).map(([g,b])=>[g,S(b,n)]))),h=document.createDocumentFragment();l.render(p).mount(h),s.parentNode.insertBefore(h,s.nextSibling);let u=x(n);Object.entries(o).forEach(([g,b])=>{u.effect(()=>{l.data[g]=S(b,n)})}),f=u,c=l}),r.onDispose(()=>{f?.dispose(),c?.destroy()}),i},_=(e,t,n)=>{let r=pe(t,e.tag);if(r)return fe(r,e,t,n);let s=document.createElement(e.tag);Object.entries(e.attrs).forEach(([o,c])=>{o.startsWith("@")?de(s,o,c,t):Z.has(o)||s.setAttribute(o,c)});let i=e.attrs[":bind"];if(i!==void 0){let o=[];n.effect(()=>{o.forEach(d=>s.removeAttribute(d));let c=S(i,t);o=c&&typeof c=="object"?Object.keys(c):[],o.forEach(d=>{let f=c[d];f!=null&&f!==!1&&s.setAttribute(d,String(f))})})}return s.appendChild(j(e.children,t,n)),s},ue=(e,t,n)=>{let r=document.createComment("if"),s=document.createDocumentFragment();s.appendChild(r);let i=null,o=null,c=null;return n.effect(()=>{let d=e.find(f=>f.expr===void 0||S(f.expr,t))??null;d!==o&&(c?.dispose(),i&&i.parentNode?.removeChild(i),i=null,o=d,d&&(c=x(t),i=_(d.node,t,c),r.parentNode.insertBefore(i,r.nextSibling)))}),s},L=(e,t,n)=>{Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})},he=(e,t,n)=>{let r=e.attrs[":each"].match(le);if(!r)return document.createComment(`invalid :each expression "${e.attrs[":each"]}"`);let[,s,i]=r,o=e.attrs[":key"],{[":each"]:c,[":key"]:d,...f}=e.attrs,y={...e,attrs:f},a=document.createComment("each"),l=document.createDocumentFragment();l.appendChild(a);let p=[];return n.effect(()=>{let h=S(i,t),u=Array.isArray(h)?h:[],g=new Map(p.map(m=>[m.key,m])),b=u.map((m,A)=>{let T=Object.create(t);L(T,s,m),L(T,"$index",A);let k=o!==void 0?S(o,T):A,C=g.get(k);if(C&&Object.is(C.item,m))return L(C.scope,"$index",A),C;C?.fx.dispose(),C?.node.parentNode?.removeChild(C.node);let M=x(t);return{key:k,item:m,scope:T,fx:M,node:_(y,T,M)}}),N=new Set(b.map(m=>m.key));p.forEach(m=>{N.has(m.key)||(m.fx.dispose(),m.node.parentNode?.removeChild(m.node))});let v=a;b.forEach(m=>{v.nextSibling!==m.node&&a.parentNode.insertBefore(m.node,v.nextSibling),v=m.node}),p=b}),l},j=(e,t,n)=>{let r=document.createDocumentFragment(),s=0;for(;s<e.length;){let i=e[s];if(typeof i=="string"){let o=document.createTextNode("");n.effect(()=>{o.textContent=oe(i,t)}),r.appendChild(o),s++;continue}if(":each"in i.attrs){r.appendChild(he(i,t,n)),s++;continue}if(":if"in i.attrs){let o=[{expr:i.attrs[":if"],node:i}];for(s++;s<e.length&&typeof e[s]!="string"&&":elseif"in e[s].attrs;){let c=e[s];o.push({expr:c.attrs[":elseif"],node:c}),s++}s<e.length&&typeof e[s]!="string"&&":else"in e[s].attrs&&(o.push({node:e[s]}),s++),r.appendChild(ue(o,t,n));continue}r.appendChild(_(i,t,n)),s++}return r},me=(e,t)=>j(e.template,t,x(t)),ge=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),ye=/<([A-Za-z][\w-]*)((?:"[^"]*"|'[^']*'|[^>"'])*?)\/>/g,Ee=/(<script[\s\S]*?<\/script\s*>|<style[\s\S]*?<\/style\s*>)/gi,be=e=>e.split(Ee).map((t,n)=>n%2===1?t:t.replace(ye,(r,s,i)=>ge.has(s.toLowerCase())?r:`<${s}${i}></${s}>`)).join(""),Se=e=>{let n=new DOMParser().parseFromString(`<template>${be(e)}</template>`,"text/html").querySelector("template"),r=[],s=[],i=[];return Array.from(n.content.children).forEach(o=>{let c={attrs:W(o),content:o.textContent??""};o.tagName==="SCRIPT"?r.push(c):o.tagName==="STYLE"?s.push(c):i.push(z(o))}),{template:i,scripts:r,styles:s}},B=/(?:let|var|const)\s+([A-Za-z_$][\w$]*)/y,F=/\$:\s*/y,I=/import(?=\s*\()/y,q=/\$:\s*([A-Za-z_$][\w$]*)\s*=(?!=)/y,K=(e,t)=>{let n=e[t],r=t+1;for(;r<e.length;){if(e[r]==="\\"){r+=2;continue}if(e[r]===n)return r+1;r++}return e.length},G=(e,t)=>{let n=e.indexOf(`
2
- `,t);return n===-1?e.length:n},J=(e,t)=>{let n=e.indexOf("*/",t+2);return n===-1?e.length:n+2},Ce=(e,t)=>{let n=0,r=t;for(;r<e.length;){let s=e[r];if(s==="'"||s==='"'||s==="`"){r=K(e,r);continue}if(s==="/"&&e[r+1]==="/"){r=G(e,r);continue}if(s==="/"&&e[r+1]==="*"){r=J(e,r);continue}if("([{".includes(s))n++;else if(")]}".includes(s))n--;else if(n<=0&&(s===`
3
- `||s===";"))return r;r++}return e.length},we=e=>{let t=[],n="",r=0,s=0,i=!0;for(;r<e.length;){let o=e[r],c=e[r+1];if(o==="'"||o==='"'||o==="`"){let d=K(e,r);n+=e.slice(r,d),r=d,i=!1;continue}if(o==="/"&&(c==="/"||c==="*")){let d=c==="/"?G(e,r):J(e,r);n+=e.slice(r,d),r=d;continue}if(o==="i"&&(r===0||!/[\w$.]/.test(e[r-1]))&&(I.lastIndex=r,I.test(e))){n+="$__import",r+=6,i=!1;continue}if(s===0&&i){B.lastIndex=r;let d=B.exec(e);if(d){t.push(d[1]),n+=d[1],r+=d[0].length,i=!1;continue}F.lastIndex=r;let f=F.exec(e);if(f){q.lastIndex=r;let y=q.exec(e);y&&t.push(y[1]);let a=r+f[0].length,l=Ce(e,a);n+=`$__effect(() => { ${e.slice(a,l)} });`,r=l;continue}}"([{".includes(o)?s++:")]}".includes(o)&&(s=Math.max(0,s-1)),o===`
4
- `||o===";"||o==="}"?i=!0:/\s/.test(o)||(i=!1),n+=o,r++}return{vars:t,code:n}},Re=e=>/\.html?([?#]|$)/.test(e)?w.fetch(e):import(e),O=new Map,Te=e=>{let t=O.get(e);if(!t){let n=document.createElement("style");n.textContent=e,document.head.appendChild(n),t={el:n,count:0},O.set(e,t)}t.count++},xe=e=>{let t=O.get(e);t&&--t.count<=0&&(t.el.remove(),O.delete(e))},Ne=(e,t,n)=>{let r=new Proxy(t,{has:(i,o)=>o!=="$__effect"&&o!=="$__import"&&(Reflect.has(i,o)||!(o in globalThis))});new Function("$scope","$__effect","$__import",`return (async () => { with ($scope) { ${e} } })()`)(r,n,Re).catch(i=>console.error("jq79: error in :setup script",i))},w=class e{constructor(t){E(this,"template");E(this,"scripts");E(this,"styles");E(this,"data",null);E(this,"fx",null);E(this,"content",null);E(this,"startMarker",null);E(this,"endMarker",null);E(this,"styleEls",[]);E(this,"ownsSharedStyles",!1);E(this,"useShadow",!1);E(this,"mountRoot",null);let{template:n,scripts:r,styles:s}=typeof t=="string"?Se(t):t;this.template=n,this.scripts=r,this.styles=s}static async fetch(t){let n=await fetch(t);if(!n.ok)throw new Error(`failed to fetch component from ${t}: ${n.status}`);return new e(await n.text())}render(t={}){return this.renderWith(t,!1)}renderShadow(t={}){return this.renderWith(t,!0)}renderWith(t,n){this.destroy();let r=V({...t}),s=x(r);this.data=r,this.fx=s,this.useShadow=n,this.scripts.forEach(o=>{let{vars:c,code:d}=we(o.content);c.forEach(f=>{f in r||(r[f]=void 0)}),Ne(d,r,s.effect)}),this.startMarker=document.createComment("jq79"),this.endMarker=document.createComment("/jq79");let i=document.createDocumentFragment();return i.append(this.startMarker,j(this.template,r,s),this.endMarker),this.content=i,n?this.styleEls=this.styles.map(o=>{let c=document.createElement("style");return c.textContent=o.content,c}):(this.styles.forEach(o=>Te(o.content)),this.ownsSharedStyles=!0),this}mount(t){let n=typeof t=="string"?U(t):t;if(!n)throw new Error(`mount target not found: ${t}`);if(!this.content)throw new Error("render() must be called before mount()");this.mountRoot&&this.unmount();let r=this.useShadow&&n instanceof Element?n.shadowRoot??n.attachShadow({mode:"open"}):n;return this.useShadow&&this.styleEls.forEach(s=>r.appendChild(s)),r.appendChild(this.content),this.mountRoot=r,this}unmount(){if(!this.mountRoot||!this.content||!this.startMarker||!this.endMarker)return this;let t=this.startMarker;for(;t;){let n=t.nextSibling;if(this.content.appendChild(t),t===this.endMarker)break;t=n}return this.mountRoot=null,this}destroy(){return this.unmount(),this.fx?.dispose(),this.fx=null,this.styleEls.forEach(t=>t.parentNode?.removeChild(t)),this.styleEls=[],this.ownsSharedStyles&&(this.styles.forEach(t=>xe(t.content)),this.ownsSharedStyles=!1),this.content=null,this.startMarker=null,this.endMarker=null,this.data=null,this}},$e=e=>new w(e);return re(Oe);})();
1
+ var jq79=(()=>{var $=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var ee=(e,t,n)=>t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var te=(e,t)=>{for(var n in t)$(e,n,{get:t[n],enumerable:!0})},ne=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Y(t))!Q.call(e,s)&&s!==n&&$(e,s,{get:()=>t[s],enumerable:!(r=X(t,s))||r.enumerable});return e};var re=e=>ne($({},"__esModule",{value:!0}),e);var E=(e,t,n)=>ee(e,typeof t!="symbol"?t+"":t,n);var Ae={};te(Ae,{$:()=>U,$$:()=>se,$create:()=>oe,Component79:()=>w,createReactiveDeepData:()=>V,parseComponent:()=>Oe,renderComponent:()=>ge});var U=(e,t)=>typeof e=="string"?document.querySelector(e):e.querySelector(t||""),se=(e,t)=>Array.from(typeof e=="string"?document.querySelectorAll(e):e.querySelectorAll(t||"")),oe=(e,t={})=>{let n=document.createElement(e);for(let[r,s]of Object.entries(t))if(r==="className")n.className=Array.isArray(s)?s.join(" "):s;else if(r==="textContent")n.textContent=s;else if(r==="children")for(let i of s)n.appendChild(i);else n.setAttribute(r,s);return n},W=e=>Object.fromEntries(Array.from(e.attributes).map(t=>[t.name,t.value])),H=e=>({tag:e.tagName.toLowerCase(),attrs:W(e),children:Array.from(e.childNodes).flatMap(t=>{if(t.nodeType===Node.TEXT_NODE){let n=t.textContent?.trim()??"";return n?[n]:[]}return t.nodeType===Node.ELEMENT_NODE?[H(t)]:[]})}),S=(e,t,n)=>{try{return new Function("$scope",...Object.keys(n??{}),`with ($scope) { return (${e}); }`)(t,...Object.values(n??{}))}catch{return}},ie=(e,t)=>e.replace(/{{\s*(.+?)\s*}}/g,(n,r)=>S(r,t)??""),ce=(e,t)=>t.split(".").reduce((n,r)=>n?.[r],e),D=e=>{if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},z=(e,t,n)=>{Object.entries(e).forEach(([r,s])=>{let i=t?`${t}.${r}`:r;s&&typeof s=="object"&&D(s)?z(s,i,n):n(i,s)})},ae=(e,t)=>e===t||e.startsWith(`${t}.`)||t.startsWith(`${e}.`),R=[],le=e=>{R.push(new Set);try{return e()}finally{R.pop()}},V=e=>{let t=new Map,n=new Set,r=new Set,s=new WeakSet,i=(a,l)=>{t.get(a)?.forEach(p=>p(l,a)),n.forEach(p=>p(a,l)),r.forEach(p=>{Array.from(p.deps).some(m=>ae(m,a))&&p.run()})},o=(a,l)=>{if(s.has(a))return a;Object.entries(a).forEach(([m,u])=>{u&&typeof u=="object"&&D(u)&&(a[m]=o(u,l?`${l}.${m}`:m))});let p=new Proxy(a,{get(m,u,g){return typeof u=="string"&&R[R.length-1]?.add(l?`${l}.${u}`:u),Reflect.get(m,u,g)},set(m,u,g,b){if(b!==p&&!Object.prototype.hasOwnProperty.call(m,u))return Reflect.set(m,u,g,b);let N=l?`${l}.${u}`:u;return g&&typeof g=="object"&&D(g)&&(g=o(g,N)),m[u]=g,i(N,g),!0}});return s.add(p),p},c=o(e,""),d=(a,l,{immediate:p=!1}={})=>(t.has(a)||t.set(a,new Set),t.get(a).add(l),p&&l(ce(c,a),a),()=>t.get(a)?.delete(l)),f=(a,{immediate:l=!1}={})=>(n.add(a),l&&z(c,"",(p,m)=>a(p,m)),()=>n.delete(a)),y=a=>{let l={deps:new Set,run:()=>{let p=new Set;R.push(p);try{a()}finally{R.pop(),l.deps=p}}};return r.add(l),l.run(),()=>{r.delete(l)}};return Object.defineProperty(c,"$on",{value:d,enumerable:!1}),Object.defineProperty(c,"$onAny",{value:f,enumerable:!1}),Object.defineProperty(c,"$effect",{value:y,enumerable:!1}),c},Z=new Set([":bind",":if",":elseif",":else",":each",":key"]),de=/^\s*(\w+)\s+in\s+(.+)$/,T=e=>{let t=[];return{effect:n=>{t.push(e.$effect(n))},onDispose:n=>{t.push(n)},dispose:()=>{t.splice(0).forEach(n=>n())}}},pe=(e,t,n,r)=>{let[s,...i]=t.slice(1).split("."),o=new Set(i);e.addEventListener(s,c=>{if(o.has("self")&&c.target!==e)return;o.has("prevent")&&c.preventDefault(),o.has("stop")&&c.stopPropagation();let d=S(n,r,{$event:c});typeof d=="function"&&d.call(e,c)},{once:o.has("once"),capture:o.has("capture")})},P=e=>e.replace(/-(\w)/g,(t,n)=>n.toUpperCase()),fe=(e,t)=>{let n=t.replace(/-/g,"").toLowerCase();for(let r=e;r&&r!==Object.prototype;r=Object.getPrototypeOf(r))for(let s of Object.keys(r))if(/^[A-Z]/.test(s)&&s.replace(/-/g,"").toLowerCase()===n)return s;return null},ue=(e,t,n,r)=>{let s=document.createComment(e),i=document.createDocumentFragment();i.appendChild(s);let o={};Object.entries(t.attrs).forEach(([y,a])=>{if(!(Z.has(y)||y.startsWith("@")))if(y.startsWith(":")){let l=P(y.slice(1));o[l]=a||l}else o[P(y)]=JSON.stringify(a)});let c=null,d=null,f=null;return r.effect(()=>{let y=S(e,n),a=y instanceof w?y:null;if(a===d||(f?.dispose(),f=null,c?.destroy(),c=null,d=a,!a))return;let l=new w({template:a.template,scripts:a.scripts,styles:a.styles}),p=le(()=>Object.fromEntries(Object.entries(o).map(([g,b])=>[g,S(b,n)]))),m=document.createDocumentFragment();l.render(p).mount(m),s.parentNode.insertBefore(m,s.nextSibling);let u=T(n);Object.entries(o).forEach(([g,b])=>{u.effect(()=>{l.data[g]=S(b,n)})}),f=u,c=l}),r.onDispose(()=>{f?.dispose(),c?.destroy()}),i},_=(e,t,n)=>{let r=fe(t,e.tag);if(r)return ue(r,e,t,n);let s=document.createElement(e.tag);Object.entries(e.attrs).forEach(([o,c])=>{o.startsWith("@")?pe(s,o,c,t):Z.has(o)||s.setAttribute(o,c)});let i=e.attrs[":bind"];if(i!==void 0){let o=[];n.effect(()=>{o.forEach(d=>s.removeAttribute(d));let c=S(i,t);o=c&&typeof c=="object"?Object.keys(c):[],o.forEach(d=>{let f=c[d];f!=null&&f!==!1&&s.setAttribute(d,String(f))})})}return s.appendChild(j(e.children,t,n)),s},me=(e,t,n)=>{let r=document.createComment("if"),s=document.createDocumentFragment();s.appendChild(r);let i=null,o=null,c=null;return n.effect(()=>{let d=e.find(f=>f.expr===void 0||S(f.expr,t))??null;d!==o&&(c?.dispose(),i&&i.parentNode?.removeChild(i),i=null,o=d,d&&(c=T(t),i=_(d.node,t,c),r.parentNode.insertBefore(i,r.nextSibling)))}),s},L=(e,t,n)=>{Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})},he=(e,t,n)=>{let r=e.attrs[":each"].match(de);if(!r)return document.createComment(`invalid :each expression "${e.attrs[":each"]}"`);let[,s,i]=r,o=e.attrs[":key"],{[":each"]:c,[":key"]:d,...f}=e.attrs,y={...e,attrs:f},a=document.createComment("each"),l=document.createDocumentFragment();l.appendChild(a);let p=[];return n.effect(()=>{let m=S(i,t),u=Array.isArray(m)?m:[],g=new Map(p.map(h=>[h.key,h])),b=u.map((h,v)=>{let x=Object.create(t);L(x,s,h),L(x,"$index",v);let k=o!==void 0?S(o,x):v,C=g.get(k);if(C&&Object.is(C.item,h))return L(C.scope,"$index",v),C;C?.fx.dispose(),C?.node.parentNode?.removeChild(C.node);let M=T(t);return{key:k,item:h,scope:x,fx:M,node:_(y,x,M)}}),N=new Set(b.map(h=>h.key));p.forEach(h=>{N.has(h.key)||(h.fx.dispose(),h.node.parentNode?.removeChild(h.node))});let A=a;b.forEach(h=>{A.nextSibling!==h.node&&a.parentNode.insertBefore(h.node,A.nextSibling),A=h.node}),p=b}),l},j=(e,t,n)=>{let r=document.createDocumentFragment(),s=0;for(;s<e.length;){let i=e[s];if(typeof i=="string"){let o=document.createTextNode("");n.effect(()=>{o.textContent=ie(i,t)}),r.appendChild(o),s++;continue}if(":each"in i.attrs){r.appendChild(he(i,t,n)),s++;continue}if(":if"in i.attrs){let o=[{expr:i.attrs[":if"],node:i}];for(s++;s<e.length&&typeof e[s]!="string"&&":elseif"in e[s].attrs;){let c=e[s];o.push({expr:c.attrs[":elseif"],node:c}),s++}s<e.length&&typeof e[s]!="string"&&":else"in e[s].attrs&&(o.push({node:e[s]}),s++),r.appendChild(me(o,t,n));continue}r.appendChild(_(i,t,n)),s++}return r},ge=(e,t)=>j(e.template,t,T(t)),ye=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Ee=/<([A-Za-z][\w-]*)((?:"[^"]*"|'[^']*'|[^>"'])*?)\/>/g,be=/(<script[\s\S]*?<\/script\s*>|<style[\s\S]*?<\/style\s*>)/gi,Se=e=>e.split(be).map((t,n)=>n%2===1?t:t.replace(Ee,(r,s,i)=>ye.has(s.toLowerCase())?r:`<${s}${i}></${s}>`)).join(""),Ce=e=>{let n=new DOMParser().parseFromString(`<template>${Se(e)}</template>`,"text/html").querySelector("template"),r=[],s=[],i=[];return Array.from(n.content.children).forEach(o=>{let c={attrs:W(o),content:o.textContent??""};o.tagName==="SCRIPT"?r.push(c):o.tagName==="STYLE"?s.push(c):i.push(H(o))}),{template:i,scripts:r,styles:s}},B=/(?:let|var|const)\s+([A-Za-z_$][\w$]*)/y,F=/\$:\s*/y,I=/import(?=\s*\()/y,q=/\$:\s*([A-Za-z_$][\w$]*)\s*=(?!=)/y,K=(e,t)=>{let n=e[t],r=t+1;for(;r<e.length;){if(e[r]==="\\"){r+=2;continue}if(e[r]===n)return r+1;r++}return e.length},G=(e,t)=>{let n=e.indexOf(`
2
+ `,t);return n===-1?e.length:n},J=(e,t)=>{let n=e.indexOf("*/",t+2);return n===-1?e.length:n+2},we=(e,t)=>{let n=0,r=t;for(;r<e.length;){let s=e[r];if(s==="'"||s==='"'||s==="`"){r=K(e,r);continue}if(s==="/"&&e[r+1]==="/"){r=G(e,r);continue}if(s==="/"&&e[r+1]==="*"){r=J(e,r);continue}if("([{".includes(s))n++;else if(")]}".includes(s))n--;else if(n<=0&&(s===`
3
+ `||s===";"))return r;r++}return e.length},Re=e=>{let t=[],n="",r=0,s=0,i=!0;for(;r<e.length;){let o=e[r],c=e[r+1];if(o==="'"||o==='"'||o==="`"){let d=K(e,r);n+=e.slice(r,d),r=d,i=!1;continue}if(o==="/"&&(c==="/"||c==="*")){let d=c==="/"?G(e,r):J(e,r);n+=e.slice(r,d),r=d;continue}if(o==="i"&&(r===0||!/[\w$.]/.test(e[r-1]))&&(I.lastIndex=r,I.test(e))){n+="$__import",r+=6,i=!1;continue}if(s===0&&i){B.lastIndex=r;let d=B.exec(e);if(d){t.push(d[1]),n+=d[1],r+=d[0].length,i=!1;continue}F.lastIndex=r;let f=F.exec(e);if(f){q.lastIndex=r;let y=q.exec(e);y&&t.push(y[1]);let a=r+f[0].length,l=we(e,a);n+=`$__effect(() => { ${e.slice(a,l)} });`,r=l;continue}}"([{".includes(o)?s++:")]}".includes(o)&&(s=Math.max(0,s-1)),o===`
4
+ `||o===";"||o==="}"?i=!0:/\s/.test(o)||(i=!1),n+=o,r++}return{vars:t,code:n}},xe=e=>/\.html?([?#]|$)/.test(e)?w.fetch(e):import(e),O=new Map,Te=e=>{let t=O.get(e);if(!t){let n=document.createElement("style");n.textContent=e,document.head.appendChild(n),t={el:n,count:0},O.set(e,t)}t.count++},Ne=e=>{let t=O.get(e);t&&--t.count<=0&&(t.el.remove(),O.delete(e))},$e=(e,t,n)=>{let r=new Proxy(t,{has:(i,o)=>o!=="$__effect"&&o!=="$__import"&&(Reflect.has(i,o)||!(o in globalThis))});new Function("$scope","$__effect","$__import",`return (async () => { with ($scope) { ${e} } })()`)(r,n,xe).catch(i=>console.error("jq79: error in :setup script",i))},w=class e{constructor(t){E(this,"template");E(this,"scripts");E(this,"styles");E(this,"data",null);E(this,"fx",null);E(this,"content",null);E(this,"startMarker",null);E(this,"endMarker",null);E(this,"styleEls",[]);E(this,"ownsSharedStyles",!1);E(this,"useShadow",!1);E(this,"mountRoot",null);let{template:n,scripts:r,styles:s}=typeof t=="string"?Ce(t):t;this.template=n,this.scripts=r,this.styles=s}static async fetch(t){let n=await fetch(t);if(!n.ok)throw new Error(`failed to fetch component from ${t}: ${n.status}`);return new e(await n.text())}render(t={}){return this.renderWith(t,!1)}renderShadow(t={}){return this.renderWith(t,!0)}renderWith(t,n){this.destroy();let r=V({...t}),s=T(r);this.data=r,this.fx=s,this.useShadow=n,this.scripts.forEach(o=>{let{vars:c,code:d}=Re(o.content);c.forEach(f=>{f in r||(r[f]=void 0)}),$e(d,r,s.effect)}),this.startMarker=document.createComment("jq79"),this.endMarker=document.createComment("/jq79");let i=document.createDocumentFragment();return i.append(this.startMarker,j(this.template,r,s),this.endMarker),this.content=i,n?this.styleEls=this.styles.map(o=>{let c=document.createElement("style");return c.textContent=o.content,c}):(this.styles.forEach(o=>Te(o.content)),this.ownsSharedStyles=!0),this}mount(t){let n=typeof t=="string"?U(t):t;if(!n)throw new Error(`mount target not found: ${t}`);if(!this.content)throw new Error("render() must be called before mount()");this.mountRoot&&this.unmount();let r=this.useShadow&&n instanceof Element?n.shadowRoot??n.attachShadow({mode:"open"}):n;return this.useShadow&&this.styleEls.forEach(s=>r.appendChild(s)),r.appendChild(this.content),this.mountRoot=r,this}unmount(){if(!this.mountRoot||!this.content||!this.startMarker||!this.endMarker)return this;let t=this.startMarker;for(;t;){let n=t.nextSibling;if(this.content.appendChild(t),t===this.endMarker)break;t=n}return this.mountRoot=null,this}destroy(){return this.unmount(),this.fx?.dispose(),this.fx=null,this.styleEls.forEach(t=>t.parentNode?.removeChild(t)),this.styleEls=[],this.ownsSharedStyles&&(this.styles.forEach(t=>Ne(t.content)),this.ownsSharedStyles=!1),this.content=null,this.startMarker=null,this.endMarker=null,this.data=null,this}},Oe=e=>new w(e);return re(Ae);})();
5
5
  //# sourceMappingURL=jq79.global.js.map