jq79 0.3.19 → 0.3.20

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.js CHANGED
@@ -1,10 +1,10 @@
1
- var ce=Object.defineProperty;var ae=(e,t,n)=>t in e?ce(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var b=(e,t,n)=>ae(e,typeof t!="symbol"?t+"":t,n);var L=(e,t)=>typeof e=="string"?document.querySelector(e):e.querySelector(t||""),D=(e,t)=>Array.from(typeof e=="string"?document.querySelectorAll(e):e.querySelectorAll(t||"")),M=(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 o of s)n.appendChild(o);else n.setAttribute(r,s);return n};var le=(e,t)=>t.split(".").reduce((n,r)=>n?.[r],e),j=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 o=t?`${t}.${r}`:r;s&&typeof s=="object"&&j(s)?z(s,o,n):n(o,s)})},de=(e,t)=>e===t||e.startsWith(`${t}.`)||t.startsWith(`${e}.`),x=[],X=e=>{x.push(new Set);try{return e()}finally{x.pop()}},_=e=>{let t=new Map,n=new Set,r=new Set,s=new WeakSet,o=(a,p,m=!1)=>{t.get(a)?.forEach(h=>h(p,a)),n.forEach(h=>h(a,p)),r.forEach(h=>{(m||Array.from(h.deps).some(g=>de(g,a)))&&h.run()})},i=(a,p)=>{if(s.has(a))return a;Object.entries(a).forEach(([h,g])=>{g&&typeof g=="object"&&j(g)&&(a[h]=i(g,p?`${p}.${h}`:h))});let m=new Proxy(a,{get(h,g,u){return typeof g=="string"&&x[x.length-1]?.add(p?`${p}.${g}`:g),Reflect.get(h,g,u)},set(h,g,u,y){if(y!==m&&!Object.prototype.hasOwnProperty.call(h,g))return Reflect.set(h,g,u,y);let S=p?`${p}.${g}`:g;u&&typeof u=="object"&&j(u)&&(u=i(u,S));let T=!Object.prototype.hasOwnProperty.call(h,g);return h[g]=u,o(S,u,T),!0}});return s.add(m),m},c=i(e,""),l=(a,p,{immediate:m=!1}={})=>(t.has(a)||t.set(a,new Set),t.get(a).add(p),m&&p(le(c,a),a),()=>t.get(a)?.delete(p)),d=(a,{immediate:p=!1}={})=>(n.add(a),p&&z(c,"",(m,h)=>a(m,h)),()=>n.delete(a)),f=a=>{let p={deps:new Set,run:()=>{let m=new Set;x.push(m);try{a()}finally{x.pop(),p.deps=m}}};return r.add(p),p.run(),()=>{r.delete(p)}};return Object.defineProperty(c,"$on",{value:l,enumerable:!1}),Object.defineProperty(c,"$onAny",{value:d,enumerable:!1}),Object.defineProperty(c,"$effect",{value:f,enumerable:!1}),c},C=e=>{let t=[];return{effect:n=>{t.push(e.$effect(n))},onDispose:n=>{t.push(n)},dispose:()=>{t.splice(0).forEach(n=>n())}}};var G=/(?:let|var|const)\s+([A-Za-z_$][\w$]*)/y,K=/\$:\s*/y,O=/import(?=\s*\()/y,V=/\$:\s*([A-Za-z_$][\w$]*)\s*=(?!=)/y,P=(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},k=(e,t)=>{let n=e.indexOf(`
2
- `,t);return n===-1?e.length:n},F=(e,t)=>{let n=e.indexOf("*/",t+2);return n===-1?e.length:n+2},fe=(e,t)=>{let n=0,r=t;for(;r<e.length;){let s=e[r];if(s==="'"||s==='"'||s==="`"){r=P(e,r);continue}if(s==="/"&&e[r+1]==="/"){r=k(e,r);continue}if(s==="/"&&e[r+1]==="*"){r=F(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},Y=e=>{let t=[],n="",r=0,s=0,o=!0;for(;r<e.length;){let i=e[r],c=e[r+1];if(i==="'"||i==='"'||i==="`"){let l=P(e,r);n+=e.slice(r,l),r=l,o=!1;continue}if(i==="/"&&(c==="/"||c==="*")){let l=c==="/"?k(e,r):F(e,r);n+=e.slice(r,l),r=l;continue}if(i==="i"&&(r===0||!/[\w$.]/.test(e[r-1]))&&(O.lastIndex=r,O.test(e))){n+="$__import",r+=6,o=!1;continue}if(s===0&&o){G.lastIndex=r;let l=G.exec(e);if(l){t.push(l[1]),n+=l[1],r+=l[0].length,o=!1;continue}K.lastIndex=r;let d=K.exec(e);if(d){V.lastIndex=r;let f=V.exec(e);f&&t.push(f[1]);let a=r+d[0].length,p=fe(e,a);n+=`$__effect(() => { ${e.slice(a,p)} });`,r=p;continue}}"([{".includes(i)?s++:")]}".includes(i)&&(s=Math.max(0,s-1)),i===`
4
- `||i===";"||i==="}"?o=!0:/\s/.test(i)||(o=!1),n+=i,r++}return{vars:t,code:n}},Z=/export\s+default(?![\w$])/y,J=/import\s*(?:([\w$\s,{}*]+?)\s*from\s*)?(["'])([^"'\n]+)\2/y,ue=e=>{let t=[],n=0,r=0;for(let s=0;s<=e.length;s++){let o=e[s];if(o==="{")n++;else if(o==="}")n--;else if(s===e.length||o===","&&n===0){let i=e.slice(r,s).trim();i&&t.push(i),r=s+1}}return t},pe=(e,t,n)=>{let r=`await $__import(${JSON.stringify(t)})`;if(e===void 0)return r;let s=ue(e),o=[],i=r;if(s.length>1){let c=`$__mod${n}`;o.push(`${c} = ${r}`),i=c}for(let c of s)c.startsWith("{")?o.push(`${c.replace(/\s+as\s+/g,": ")} = ${i}`):c.startsWith("*")?o.push(`${c.replace(/^\*\s*as\s+/,"")} = ${i}`):o.push(`${c} = $__default(${i})`);return`const ${o.join(", ")}`},Q=e=>{let t="",n=0,r=0,s=!0,o=!1,i=0;for(;n<e.length;){let c=e[n],l=e[n+1],d=n===0||!/[\w$.]/.test(e[n-1]);if(c==="'"||c==='"'||c==="`"){let f=P(e,n);t+=e.slice(n,f),n=f,s=!1;continue}if(c==="/"&&(l==="/"||l==="*")){let f=l==="/"?k(e,n):F(e,n);t+=e.slice(n,f),n=f;continue}if(c==="i"&&d){if(O.lastIndex=n,O.test(e)){t+="$__import",n+=6,s=!1;continue}if(r===0&&s){J.lastIndex=n;let f=J.exec(e);if(f){t+=pe(f[1],f[3],i++),n+=f[0].length,s=!1;continue}}}if(c==="e"&&d&&r===0&&s){Z.lastIndex=n;let f=Z.exec(e);if(f){o=!0,t+="$__exports.default =",n+=f[0].length,s=!1;continue}}"([{".includes(c)?r++:")]}".includes(c)&&(r=Math.max(0,r-1)),c===`
5
- `||c===";"||c==="}"?s=!0:/\s/.test(c)||(s=!1),t+=c,n++}return o?t:null};var re=e=>Object.fromEntries(Array.from(e.attributes).map(t=>[t.name,t.value])),se=e=>({tag:e.tagName.toLowerCase(),attrs:re(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?[se(t)]:[]})}),w=(e,t,n)=>{try{return new Function("$scope",...Object.keys(n??{}),`with ($scope) { return (${e}); }`)(t,...Object.values(n??{}))}catch{return}},he=(e,t)=>e.replace(/{{\s*(.+?)\s*}}/g,(n,r)=>w(r,t)??""),oe=new Set([":attrs",":if",":elseif",":else",":each",":key",":with"]),me=/^\s*(\w+)\s+in\s+(.+)$/,ge=(e,t,n,r)=>{let[s,...o]=t.slice(1).split("."),i=new Set(o);e.addEventListener(s,c=>{if(i.has("self")&&c.target!==e)return;i.has("prevent")&&c.preventDefault(),i.has("stop")&&c.stopPropagation();let l=w(n,r,{$event:c});typeof l=="function"&&l.call(e,c)},{once:i.has("once"),capture:i.has("capture")})},ee=e=>e.replace(/-(\w)/g,(t,n)=>n.toUpperCase()),te=(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},ne=(e,t,n,r)=>{let s=document.createComment(e),o=document.createDocumentFragment();o.appendChild(s);let i={};Object.entries(t.attrs).forEach(([f,a])=>{if(!(oe.has(f)||f.startsWith("@")))if(f.startsWith(":")){let p=ee(f.slice(1));i[p]=a||p}else i[ee(f)]=JSON.stringify(a)});let c=null,l=null,d=null;return r.effect(()=>{let f=w(e,n),a=f instanceof N?f:null;if(a===l||(d?.dispose(),d=null,c?.destroy(),c=null,l=a,!a))return;let p=new N({template:a.template,scripts:a.scripts,styles:a.styles,modules:a.modules}),m=X(()=>Object.fromEntries(Object.entries(i).map(([u,y])=>[u,w(y,n)]))),h=document.createDocumentFragment();p.render(m).mount(h),s.parentNode.insertBefore(h,s.nextSibling);let g=C(n);Object.entries(i).forEach(([u,y])=>{g.effect(()=>{p.data[u]=w(y,n)})}),d=g,c=p}),r.onDispose(()=>{d?.dispose(),c?.destroy()}),o},ye=(e,t)=>{let n=()=>{let r=w(e,t);return r!==null&&typeof r=="object"?r:null};return new Proxy(t,{has(r,s){let o=n();return o!==null&&Reflect.has(o,s)||Reflect.has(r,s)},get(r,s){let o=n();return o!==null&&Reflect.has(o,s)?o[s]:Reflect.get(r,s)},set(r,s,o){let i=n();return i!==null&&Reflect.has(i,s)?(i[s]=o,!0):Reflect.set(r,s,o)}})},I=(e,t,n)=>{let r=e.attrs[":with"],s=r!==void 0?ye(r,t):t,o=te(s,e.tag);if(o)return ne(o,e,s,n);let i=document.createElement(e.tag);if(i instanceof HTMLUnknownElement||e.tag.includes("-")){let l=!1;n.effect(()=>{if(l)return;let d=te(s,e.tag);d&&(l=!0,i.replaceWith(ne(d,e,s,n)))})}Object.entries(e.attrs).forEach(([l,d])=>{l.startsWith("@")?ge(i,l,d,s):oe.has(l)||i.setAttribute(l,d)});let c=e.attrs[":attrs"];if(c!==void 0){let l=[];n.effect(()=>{l.forEach(f=>i.removeAttribute(f));let d=w(c,s);l=d&&typeof d=="object"?Object.keys(d):[],l.forEach(f=>{let a=d[f];a!=null&&a!==!1&&i.setAttribute(f,String(a))})})}return i.appendChild(W(e.children,s,n)),i},Ee=(e,t,n)=>{let r=document.createComment("if"),s=document.createDocumentFragment();s.appendChild(r);let o=null,i=null,c=null;return n.effect(()=>{let l=e.find(d=>d.expr===void 0||w(d.expr,t))??null;l!==i&&(c?.dispose(),o&&o.parentNode?.removeChild(o),o=null,i=l,l&&(c=C(t),o=I(l.node,t,c),r.parentNode.insertBefore(o,r.nextSibling)))}),s},B=(e,t,n)=>{Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})},Se=(e,t,n)=>{let r=e.attrs[":each"].match(me);if(!r)return document.createComment(`invalid :each expression "${e.attrs[":each"]}"`);let[,s,o]=r,i=e.attrs[":key"],{[":each"]:c,[":key"]:l,...d}=e.attrs,f={...e,attrs:d},a=document.createComment("each"),p=document.createDocumentFragment();p.appendChild(a);let m=[];return n.effect(()=>{let h=w(o,t),g=Array.isArray(h)?h:[],u=new Map(m.map(E=>[E.key,E])),y=g.map((E,v)=>{let $=Object.create(t);B($,s,E),B($,"$index",v);let q=i!==void 0?w(i,$):v,R=u.get(q);if(R&&Object.is(R.item,E))return B(R.scope,"$index",v),R;R?.fx.dispose(),R?.node.parentNode?.removeChild(R.node);let H=C(t);return{key:q,item:E,scope:$,fx:H,node:I(f,$,H)}}),S=new Set(y.map(E=>E.key));m.forEach(E=>{S.has(E.key)||(E.fx.dispose(),E.node.parentNode?.removeChild(E.node))});let T=a;y.forEach(E=>{T.nextSibling!==E.node&&a.parentNode.insertBefore(E.node,T.nextSibling),T=E.node}),m=y}),p},W=(e,t,n)=>{let r=document.createDocumentFragment(),s=0;for(;s<e.length;){let o=e[s];if(typeof o=="string"){let i=document.createTextNode("");n.effect(()=>{i.textContent=he(o,t)}),r.appendChild(i),s++;continue}if(":each"in o.attrs){r.appendChild(Se(o,t,n)),s++;continue}if(":if"in o.attrs){let i=[{expr:o.attrs[":if"],node:o}];for(s++;s<e.length&&typeof e[s]!="string"&&":elseif"in e[s].attrs;){let c=e[s];i.push({expr:c.attrs[":elseif"],node:c}),s++}s<e.length&&typeof e[s]!="string"&&":else"in e[s].attrs&&(i.push({node:e[s]}),s++),r.appendChild(Ee(i,t,n));continue}r.appendChild(I(o,t,n)),s++}return r},ke=(e,t)=>W(e.template,t,C(t)),be=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),$e=/<([A-Za-z][\w-]*)((?:"[^"]*"|'[^']*'|[^>"'])*?)\/>/g,we=/(<script[\s\S]*?<\/script\s*>|<style[\s\S]*?<\/style\s*>)/gi,Te=e=>e.split(we).map((t,n)=>n%2===1?t:t.replace($e,(r,s,o)=>be.has(s.toLowerCase())?r:`<${s}${o}></${s}>`)).join(""),Re=e=>{let n=new DOMParser().parseFromString(`<template>${Te(e)}</template>`,"text/html").querySelector("template"),r=[],s=[],o=[];return Array.from(n.content.children).forEach(i=>{let c={attrs:re(i),content:i.textContent??""};i.tagName==="SCRIPT"?r.push(c):i.tagName==="STYLE"?s.push(c):o.push(se(i))}),{template:o,scripts:r,styles:s}},U=e=>/\.html?([?#]|$)/.test(e)?N.fetch(e):import(e),A=new Map,xe=e=>{let t=A.get(e);if(!t){let n=document.createElement("style");n.textContent=e,document.head.appendChild(n),t={el:n,count:0},A.set(e,t)}t.count++},Ce=e=>{let t=A.get(e);t&&--t.count<=0&&(t.el.remove(),A.delete(e))},ie={$:L,$$:D,$create:M,$reactive:_},Ne=(e,t,n,r={},s=U)=>{let o={...ie,...r},i=new Proxy(t,{has:(l,d)=>d!=="$__effect"&&d!=="$__import"&&(Reflect.has(l,d)||!(d in globalThis)&&!(d in o))});new Function("$scope","$__effect","$__import",...Object.keys(o),`return (async () => { with ($scope) { ${e} } })()`)(i,n,s,...Object.values(o)).catch(l=>console.error("jq79: error in :setup script",l))},ve=e=>e&&e.default!==void 0?e.default:e,Le=(e,t,n,r={},s=U)=>{let o={...ie,...r},i={},c=new Function("$__exports","$__default","$__import",...Object.keys(o),`return (async () => { "use strict";
6
- ${e}
7
- ;$__exports.done = true })()`)(i,ve,s,...Object.values(o)),l=a=>console.error("jq79: error in factory script",a),d=!1,f=()=>{if(d)return;d=!0;let a=i.default;if(typeof a!="function")return;let p=h=>{h&&typeof h=="object"&&Object.assign(t,h)},m=a({$data:t,$effect:n,...r});m instanceof Promise?m.then(p).catch(l):p(m)};c.then(f,l),i.done&&f()},N=class e{constructor(t,n={}){b(this,"template");b(this,"scripts");b(this,"styles");b(this,"modules");b(this,"data",null);b(this,"fx",null);b(this,"content",null);b(this,"startMarker",null);b(this,"endMarker",null);b(this,"styleEls",[]);b(this,"ownsSharedStyles",!1);b(this,"useShadow",!1);b(this,"mountRoot",null);b(this,"resolveMounted",null);b(this,"emitListeners",new Map);let r=typeof t=="string"?Re(t):t;this.template=r.template,this.scripts=r.scripts,this.styles=r.styles,this.modules=n.modules??(typeof t=="string"?void 0:t.modules)}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())}on(t,n){return this.emitListeners.has(t)||this.emitListeners.set(t,new Set),this.emitListeners.get(t).add(n),this}off(t,n){return this.emitListeners.get(t)?.delete(n),this}render(t={}){return this.renderWith(t,!1)}renderShadow(t={}){return this.renderWith(t,!0)}renderWith(t,n){this.destroy();let r=_({...t}),s=C(r);this.data=r,this.fx=s,this.useShadow=n,this.startMarker=document.createComment("jq79"),this.endMarker=document.createComment("/jq79");let o=this.startMarker,i=(u,y)=>{let S=new CustomEvent(u,{detail:y,bubbles:!0,composed:!0}),T=o.dispatchEvent(S);return o===this.startMarker&&this.emitListeners.get(u)?.forEach(E=>E(S,y)),T},c,l=new Promise(u=>{c=u});this.resolveMounted=c;let d=()=>l,f=this.endMarker,a=u=>{let y=[];for(let S=o.nextSibling;S&&S!==f;S=S.nextSibling)S instanceof Element&&(S.matches(u)&&y.push(S),y.push(...Array.from(S.querySelectorAll(u))));return y},p=u=>a(u)[0]??null,m=this.modules,h=u=>m&&u in m?Promise.resolve(m[u]):U(u);this.scripts.forEach(u=>{let y={$emit:i,$mounted:d,$self:p,$$self:a},S=Q(u.content);if(S!==null){let $=":mounted"in u.attrs?`await $mounted();
8
- ${S}`:S;Le($,r,s.effect,y,h);return}let{vars:T,code:E}=Y(u.content);T.forEach($=>{$ in r||(r[$]=void 0)});let v=":mounted"in u.attrs?`await $mounted();
9
- ${E}`:E;Ne(v,r,s.effect,y,h)});let g=document.createDocumentFragment();return g.append(this.startMarker,W(this.template,r,s),this.endMarker),this.content=g,n?this.styleEls=this.styles.map(u=>{let y=document.createElement("style");return y.textContent=u.content,y}):(this.styles.forEach(u=>xe(u.content)),this.ownsSharedStyles=!0),this}mount(t,n){let r=typeof t=="string"?L(t):t;if(!r)throw new Error(`mount target not found: ${t}`);return(!this.content||n!==void 0)&&this.renderWith(n??{},this.useShadow),this.attach(r)}mountShadow(t,n){let r=typeof t=="string"?L(t):t;if(!r)throw new Error(`mount target not found: ${t}`);return(!this.content||n!==void 0||!this.useShadow)&&this.renderWith(n??{},!0),this.attach(r)}attach(t){this.mountRoot&&this.detach();let n=this.useShadow&&t instanceof Element?t.shadowRoot??t.attachShadow({mode:"open"}):t;return this.useShadow&&this.styleEls.forEach(r=>n.appendChild(r)),n.appendChild(this.content),this.mountRoot=n,this.resolveMounted?.(),this}detach(){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.detach(),this.fx?.dispose(),this.fx=null,this.styleEls.forEach(t=>t.parentNode?.removeChild(t)),this.styleEls=[],this.ownsSharedStyles&&(this.styles.forEach(t=>Ce(t.content)),this.ownsSharedStyles=!1),this.content=null,this.startMarker=null,this.endMarker=null,this.data=null,this.resolveMounted=null,this}},Fe=e=>new N(e);export{L as $,D as $$,M as $create,_ as $reactive,N as Component79,Fe as parseComponent,ke as renderComponent};
1
+ var dt=Object.defineProperty;var ft=(t,e,n)=>e in t?dt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var b=(t,e,n)=>ft(t,typeof e!="symbol"?e+"":e,n);var L=(t,e)=>typeof t=="string"?document.querySelector(t):t.querySelector(e||""),M=(t,e)=>Array.from(typeof t=="string"?document.querySelectorAll(t):t.querySelectorAll(e||"")),D=(t,e={})=>{let n=document.createElement(t);for(let[r,s]of Object.entries(e))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},ut=new Set(["a","b","i","em","strong","p","br","ul","ol","li","blockquote","code","pre","span","div","h1","h2","h3","h4","h5","h6","img"]),z={a:new Set(["href","title"]),img:new Set(["src","alt"]),"*":new Set(["class"])},pt=new Set(["http:","https:","mailto:"]);function ht(t){try{let e=new URL(t,"https://example.com");return pt.has(e.protocol)}catch{return!1}}function G(t,e){for(let n of Array.from(t.childNodes))if(n.nodeType===Node.ELEMENT_NODE){let r=mt(n);r&&e.appendChild(r)}else n.nodeType===Node.TEXT_NODE&&e.appendChild(n.cloneNode())}function mt(t){let e=t.tagName.toLowerCase();if(!ut.has(e))return null;let n=document.createElement(e);for(let r of Array.from(t.attributes)){let s=r.name.toLowerCase(),i=z[e]?.has(s),o=z["*"]?.has(s);!i&&!o||(s==="href"||s==="src")&&!ht(r.value)||n.setAttribute(s,r.value)}return e==="a"&&(n.setAttribute("rel","noopener noreferrer"),n.hasAttribute("target")&&n.removeAttribute("target")),G(t,n),n}function K(t){let e=new DOMParser().parseFromString(t,"text/html"),n=document.createElement("div");return G(e.body,n),n.innerHTML}var gt=(t,e)=>e.split(".").reduce((n,r)=>n?.[r],t),j=t=>{if(Array.isArray(t))return!0;let e=Object.getPrototypeOf(t);return e===Object.prototype||e===null},V=(t,e,n)=>{Object.entries(t).forEach(([r,s])=>{let i=e?`${e}.${r}`:r;s&&typeof s=="object"&&j(s)?V(s,i,n):n(i,s)})},yt=(t,e)=>t===e||t.startsWith(`${e}.`)||e.startsWith(`${t}.`),C=[],Z=t=>{C.push(new Set);try{return t()}finally{C.pop()}},_=t=>{let e=new Map,n=new Set,r=new Set,s=new WeakSet,i=(a,d,m=!1)=>{e.get(a)?.forEach(p=>p(d,a)),n.forEach(p=>p(a,d)),r.forEach(p=>{(m||Array.from(p.deps).some(g=>yt(g,a)))&&p.run()})},o=(a,d)=>{if(s.has(a))return a;Object.entries(a).forEach(([p,g])=>{g&&typeof g=="object"&&j(g)&&(a[p]=o(g,d?`${d}.${p}`:p))});let m=new Proxy(a,{get(p,g,u){return typeof g=="string"&&C[C.length-1]?.add(d?`${d}.${g}`:g),Reflect.get(p,g,u)},set(p,g,u,y){if(y!==m&&!Object.prototype.hasOwnProperty.call(p,g))return Reflect.set(p,g,u,y);let S=d?`${d}.${g}`:g;u&&typeof u=="object"&&j(u)&&(u=o(u,S));let x=!Object.prototype.hasOwnProperty.call(p,g);return p[g]=u,i(S,u,x),!0}});return s.add(m),m},c=o(t,""),f=(a,d,{immediate:m=!1}={})=>(e.has(a)||e.set(a,new Set),e.get(a).add(d),m&&d(gt(c,a),a),()=>e.get(a)?.delete(d)),h=(a,{immediate:d=!1}={})=>(n.add(a),d&&V(c,"",(m,p)=>a(m,p)),()=>n.delete(a)),l=a=>{let d={deps:new Set,run:()=>{let m=new Set;C.push(m);try{a()}finally{C.pop(),d.deps=m}}};return r.add(d),d.run(),()=>{r.delete(d)}};return Object.defineProperty(c,"$on",{value:f,enumerable:!1}),Object.defineProperty(c,"$onAny",{value:h,enumerable:!1}),Object.defineProperty(c,"$effect",{value:l,enumerable:!1}),c},T=t=>{let e=[];return{effect:n=>{e.push(t.$effect(n))},onDispose:n=>{e.push(n)},dispose:()=>{e.splice(0).forEach(n=>n())}}};var X=/(?:let|var|const)\s+([A-Za-z_$][\w$]*)/y,J=/\$:\s*/y,O=/import(?=\s*\()/y,Y=/\$:\s*([A-Za-z_$][\w$]*)\s*=(?!=)/y,P=(t,e)=>{let n=t[e],r=e+1;for(;r<t.length;){if(t[r]==="\\"){r+=2;continue}if(t[r]===n)return r+1;r++}return t.length},k=(t,e)=>{let n=t.indexOf(`
2
+ `,e);return n===-1?t.length:n},F=(t,e)=>{let n=t.indexOf("*/",e+2);return n===-1?t.length:n+2},Et=(t,e)=>{let n=0,r=e;for(;r<t.length;){let s=t[r];if(s==="'"||s==='"'||s==="`"){r=P(t,r);continue}if(s==="/"&&t[r+1]==="/"){r=k(t,r);continue}if(s==="/"&&t[r+1]==="*"){r=F(t,r);continue}if("([{".includes(s))n++;else if(")]}".includes(s))n--;else if(n<=0&&(s===`
3
+ `||s===";"))return r;r++}return t.length},et=t=>{let e=[],n="",r=0,s=0,i=!0;for(;r<t.length;){let o=t[r],c=t[r+1];if(o==="'"||o==='"'||o==="`"){let f=P(t,r);n+=t.slice(r,f),r=f,i=!1;continue}if(o==="/"&&(c==="/"||c==="*")){let f=c==="/"?k(t,r):F(t,r);n+=t.slice(r,f),r=f;continue}if(o==="i"&&(r===0||!/[\w$.]/.test(t[r-1]))&&(O.lastIndex=r,O.test(t))){n+="$__import",r+=6,i=!1;continue}if(s===0&&i){X.lastIndex=r;let f=X.exec(t);if(f){e.push(f[1]),n+=f[1],r+=f[0].length,i=!1;continue}J.lastIndex=r;let h=J.exec(t);if(h){Y.lastIndex=r;let l=Y.exec(t);l&&e.push(l[1]);let a=r+h[0].length,d=Et(t,a);n+=`$__effect(() => { ${t.slice(a,d)} });`,r=d;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:e,code:n}},Q=/export\s+default(?![\w$])/y,tt=/import\s*(?:([\w$\s,{}*]+?)\s*from\s*)?(["'])([^"'\n]+)\2/y,St=t=>{let e=[],n=0,r=0;for(let s=0;s<=t.length;s++){let i=t[s];if(i==="{")n++;else if(i==="}")n--;else if(s===t.length||i===","&&n===0){let o=t.slice(r,s).trim();o&&e.push(o),r=s+1}}return e},bt=(t,e,n)=>{let r=`await $__import(${JSON.stringify(e)})`;if(t===void 0)return r;let s=St(t),i=[],o=r;if(s.length>1){let c=`$__mod${n}`;i.push(`${c} = ${r}`),o=c}for(let c of s)c.startsWith("{")?i.push(`${c.replace(/\s+as\s+/g,": ")} = ${o}`):c.startsWith("*")?i.push(`${c.replace(/^\*\s*as\s+/,"")} = ${o}`):i.push(`${c} = $__default(${o})`);return`const ${i.join(", ")}`},nt=t=>{let e="",n=0,r=0,s=!0,i=!1,o=0;for(;n<t.length;){let c=t[n],f=t[n+1],h=n===0||!/[\w$.]/.test(t[n-1]);if(c==="'"||c==='"'||c==="`"){let l=P(t,n);e+=t.slice(n,l),n=l,s=!1;continue}if(c==="/"&&(f==="/"||f==="*")){let l=f==="/"?k(t,n):F(t,n);e+=t.slice(n,l),n=l;continue}if(c==="i"&&h){if(O.lastIndex=n,O.test(t)){e+="$__import",n+=6,s=!1;continue}if(r===0&&s){tt.lastIndex=n;let l=tt.exec(t);if(l){e+=bt(l[1],l[3],o++),n+=l[0].length,s=!1;continue}}}if(c==="e"&&h&&r===0&&s){Q.lastIndex=n;let l=Q.exec(t);if(l){i=!0,e+="$__exports.default =",n+=l[0].length,s=!1;continue}}"([{".includes(c)?r++:")]}".includes(c)&&(r=Math.max(0,r-1)),c===`
5
+ `||c===";"||c==="}"?s=!0:/\s/.test(c)||(s=!1),e+=c,n++}return i?e:null};var it=t=>Object.fromEntries(Array.from(t.attributes).map(e=>[e.name,e.value])),ct=t=>({tag:t.tagName.toLowerCase(),attrs:it(t),children:Array.from(t.childNodes).flatMap(e=>{if(e.nodeType===Node.TEXT_NODE){let n=e.textContent?.trim()??"";return n?[n]:[]}return e.nodeType===Node.ELEMENT_NODE?[ct(e)]:[]})}),$=(t,e,n)=>{try{return new Function("$scope",...Object.keys(n??{}),`with ($scope) { return (${t}); }`)(e,...Object.values(n??{}))}catch{return}},$t=(t,e)=>t.replace(/{{\s*(.+?)\s*}}/g,(n,r)=>$(r,e)??""),at=new Set([":attrs",":if",":elseif",":else",":each",":key",":with",":text",":html"]),wt=/^\s*(\w+)\s+in\s+(.+)$/,xt=(t,e,n,r)=>{let[s,...i]=e.slice(1).split("."),o=new Set(i);t.addEventListener(s,c=>{if(o.has("self")&&c.target!==t)return;o.has("prevent")&&c.preventDefault(),o.has("stop")&&c.stopPropagation();let f=$(n,r,{$event:c});typeof f=="function"&&f.call(t,c)},{once:o.has("once"),capture:o.has("capture")})},rt=t=>t.replace(/-(\w)/g,(e,n)=>n.toUpperCase()),st=(t,e)=>{let n=e.replace(/-/g,"").toLowerCase();for(let r=t;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},ot=(t,e,n,r)=>{let s=document.createComment(t),i=document.createDocumentFragment();i.appendChild(s);let o={};Object.entries(e.attrs).forEach(([l,a])=>{if(!(at.has(l)||l.startsWith("@")))if(l.startsWith(":")){let d=rt(l.slice(1));o[d]=a||d}else o[rt(l)]=JSON.stringify(a)});let c=null,f=null,h=null;return r.effect(()=>{let l=$(t,n),a=l instanceof v?l:null;if(a===f||(h?.dispose(),h=null,c?.destroy(),c=null,f=a,!a))return;let d=new v({template:a.template,scripts:a.scripts,styles:a.styles,modules:a.modules}),m=Z(()=>Object.fromEntries(Object.entries(o).map(([u,y])=>[u,$(y,n)]))),p=document.createDocumentFragment();d.render(m).mount(p),s.parentNode.insertBefore(p,s.nextSibling);let g=T(n);Object.entries(o).forEach(([u,y])=>{g.effect(()=>{d.data[u]=$(y,n)})}),h=g,c=d}),r.onDispose(()=>{h?.dispose(),c?.destroy()}),i},Rt=(t,e)=>{let n=()=>{let r=$(t,e);return r!==null&&typeof r=="object"?r:null};return new Proxy(e,{has(r,s){let i=n();return i!==null&&Reflect.has(i,s)||Reflect.has(r,s)},get(r,s){let i=n();return i!==null&&Reflect.has(i,s)?i[s]:Reflect.get(r,s)},set(r,s,i){let o=n();return o!==null&&Reflect.has(o,s)?(o[s]=i,!0):Reflect.set(r,s,i)}})},I=(t,e,n)=>{let r=t.attrs[":with"],s=r!==void 0?Rt(r,e):e,i=st(s,t.tag);if(i)return ot(i,t,s,n);let o=document.createElement(t.tag);if(o instanceof HTMLUnknownElement||t.tag.includes("-")){let l=!1;n.effect(()=>{if(l)return;let a=st(s,t.tag);a&&(l=!0,o.replaceWith(ot(a,t,s,n)))})}Object.entries(t.attrs).forEach(([l,a])=>{l.startsWith("@")?xt(o,l,a,s):at.has(l)||o.setAttribute(l,a)});let c=t.attrs[":attrs"];if(c!==void 0){let l=[];n.effect(()=>{l.forEach(d=>o.removeAttribute(d));let a=$(c,s);l=a&&typeof a=="object"?Object.keys(a):[],l.forEach(d=>{let m=a[d];m!=null&&m!==!1&&o.setAttribute(d,String(m))})})}let f=t.attrs[":text"],h=t.attrs[":html"];return f!==void 0?n.effect(()=>{o.textContent=String($(f,s)??"")}):h!==void 0?n.effect(()=>{o.innerHTML=K(String($(h,s)??""))}):o.appendChild(W(t.children,s,n)),o},Ct=(t,e,n)=>{let r=document.createComment("if"),s=document.createDocumentFragment();s.appendChild(r);let i=null,o=null,c=null;return n.effect(()=>{let f=t.find(h=>h.expr===void 0||$(h.expr,e))??null;f!==o&&(c?.dispose(),i&&i.parentNode?.removeChild(i),i=null,o=f,f&&(c=T(e),i=I(f.node,e,c),r.parentNode.insertBefore(i,r.nextSibling)))}),s},B=(t,e,n)=>{Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0,configurable:!0})},Tt=(t,e,n)=>{let r=t.attrs[":each"].match(wt);if(!r)return document.createComment(`invalid :each expression "${t.attrs[":each"]}"`);let[,s,i]=r,o=t.attrs[":key"],{[":each"]:c,[":key"]:f,...h}=t.attrs,l={...t,attrs:h},a=document.createComment("each"),d=document.createDocumentFragment();d.appendChild(a);let m=[];return n.effect(()=>{let p=$(i,e),g=Array.isArray(p)?p:[],u=new Map(m.map(E=>[E.key,E])),y=g.map((E,N)=>{let w=Object.create(e);B(w,s,E),B(w,"$index",N);let H=o!==void 0?$(o,w):N,R=u.get(H);if(R&&Object.is(R.item,E))return B(R.scope,"$index",N),R;R?.fx.dispose(),R?.node.parentNode?.removeChild(R.node);let q=T(e);return{key:H,item:E,scope:w,fx:q,node:I(l,w,q)}}),S=new Set(y.map(E=>E.key));m.forEach(E=>{S.has(E.key)||(E.fx.dispose(),E.node.parentNode?.removeChild(E.node))});let x=a;y.forEach(E=>{x.nextSibling!==E.node&&a.parentNode.insertBefore(E.node,x.nextSibling),x=E.node}),m=y}),d},W=(t,e,n)=>{let r=document.createDocumentFragment(),s=0;for(;s<t.length;){let i=t[s];if(typeof i=="string"){let o=document.createTextNode("");n.effect(()=>{o.textContent=$t(i,e)}),r.appendChild(o),s++;continue}if(":each"in i.attrs){r.appendChild(Tt(i,e,n)),s++;continue}if(":if"in i.attrs){let o=[{expr:i.attrs[":if"],node:i}];for(s++;s<t.length&&typeof t[s]!="string"&&":elseif"in t[s].attrs;){let c=t[s];o.push({expr:c.attrs[":elseif"],node:c}),s++}s<t.length&&typeof t[s]!="string"&&":else"in t[s].attrs&&(o.push({node:t[s]}),s++),r.appendChild(Ct(o,e,n));continue}r.appendChild(I(i,e,n)),s++}return r},qt=(t,e)=>W(t.template,e,T(e)),vt=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Nt=/<([A-Za-z][\w-]*)((?:"[^"]*"|'[^']*'|[^>"'])*?)\/>/g,Lt=/(<script[\s\S]*?<\/script\s*>|<style[\s\S]*?<\/style\s*>)/gi,_t=t=>t.split(Lt).map((e,n)=>n%2===1?e:e.replace(Nt,(r,s,i)=>vt.has(s.toLowerCase())?r:`<${s}${i}></${s}>`)).join(""),Ot=t=>{let n=new DOMParser().parseFromString(`<template>${_t(t)}</template>`,"text/html").querySelector("template"),r=[],s=[],i=[];return Array.from(n.content.children).forEach(o=>{let c={attrs:it(o),content:o.textContent??""};o.tagName==="SCRIPT"?r.push(c):o.tagName==="STYLE"?s.push(c):i.push(ct(o))}),{template:i,scripts:r,styles:s}},U=t=>/\.html?([?#]|$)/.test(t)?v.fetch(t):import(t),A=new Map,At=t=>{let e=A.get(t);if(!e){let n=document.createElement("style");n.textContent=t,document.head.appendChild(n),e={el:n,count:0},A.set(t,e)}e.count++},Mt=t=>{let e=A.get(t);e&&--e.count<=0&&(e.el.remove(),A.delete(t))},lt={$:L,$$:M,$create:D,$reactive:_},Dt=(t,e,n,r={},s=U)=>{let i={...lt,...r},o=new Proxy(e,{has:(f,h)=>h!=="$__effect"&&h!=="$__import"&&(Reflect.has(f,h)||!(h in globalThis)&&!(h in i))});new Function("$scope","$__effect","$__import",...Object.keys(i),`return (async () => { with ($scope) { ${t} } })()`)(o,n,s,...Object.values(i)).catch(f=>console.error("jq79: error in :setup script",f))},jt=t=>t&&t.default!==void 0?t.default:t,Pt=(t,e,n,r={},s=U)=>{let i={...lt,...r},o={},c=new Function("$__exports","$__default","$__import",...Object.keys(i),`return (async () => { "use strict";
6
+ ${t}
7
+ ;$__exports.done = true })()`)(o,jt,s,...Object.values(i)),f=a=>console.error("jq79: error in factory script",a),h=!1,l=()=>{if(h)return;h=!0;let a=o.default;if(typeof a!="function")return;let d=p=>{p&&typeof p=="object"&&Object.assign(e,p)},m=a({$data:e,$effect:n,...r});m instanceof Promise?m.then(d).catch(f):d(m)};c.then(l,f),o.done&&l()},v=class t{constructor(e,n={}){b(this,"template");b(this,"scripts");b(this,"styles");b(this,"modules");b(this,"data",null);b(this,"fx",null);b(this,"content",null);b(this,"startMarker",null);b(this,"endMarker",null);b(this,"styleEls",[]);b(this,"ownsSharedStyles",!1);b(this,"useShadow",!1);b(this,"mountRoot",null);b(this,"resolveMounted",null);b(this,"emitListeners",new Map);let r=typeof e=="string"?Ot(e):e;this.template=r.template,this.scripts=r.scripts,this.styles=r.styles,this.modules=n.modules??(typeof e=="string"?void 0:e.modules)}static async fetch(e){let n=await fetch(e);if(!n.ok)throw new Error(`failed to fetch component from ${e}: ${n.status}`);return new t(await n.text())}on(e,n){return this.emitListeners.has(e)||this.emitListeners.set(e,new Set),this.emitListeners.get(e).add(n),this}off(e,n){return this.emitListeners.get(e)?.delete(n),this}render(e={}){return this.renderWith(e,!1)}renderShadow(e={}){return this.renderWith(e,!0)}renderWith(e,n){this.destroy();let r=_({...e}),s=T(r);this.data=r,this.fx=s,this.useShadow=n,this.startMarker=document.createComment("jq79"),this.endMarker=document.createComment("/jq79");let i=this.startMarker,o=(u,y)=>{let S=new CustomEvent(u,{detail:y,bubbles:!0,composed:!0}),x=i.dispatchEvent(S);return i===this.startMarker&&this.emitListeners.get(u)?.forEach(E=>E(S,y)),x},c,f=new Promise(u=>{c=u});this.resolveMounted=c;let h=()=>f,l=this.endMarker,a=u=>{let y=[];for(let S=i.nextSibling;S&&S!==l;S=S.nextSibling)S instanceof Element&&(S.matches(u)&&y.push(S),y.push(...Array.from(S.querySelectorAll(u))));return y},d=u=>a(u)[0]??null,m=this.modules,p=u=>m&&u in m?Promise.resolve(m[u]):U(u);this.scripts.forEach(u=>{let y={$emit:o,$mounted:h,$self:d,$$self:a},S=nt(u.content);if(S!==null){let w=":mounted"in u.attrs?`await $mounted();
8
+ ${S}`:S;Pt(w,r,s.effect,y,p);return}let{vars:x,code:E}=et(u.content);x.forEach(w=>{w in r||(r[w]=void 0)});let N=":mounted"in u.attrs?`await $mounted();
9
+ ${E}`:E;Dt(N,r,s.effect,y,p)});let g=document.createDocumentFragment();return g.append(this.startMarker,W(this.template,r,s),this.endMarker),this.content=g,n?this.styleEls=this.styles.map(u=>{let y=document.createElement("style");return y.textContent=u.content,y}):(this.styles.forEach(u=>At(u.content)),this.ownsSharedStyles=!0),this}mount(e,n){let r=typeof e=="string"?L(e):e;if(!r)throw new Error(`mount target not found: ${e}`);return(!this.content||n!==void 0)&&this.renderWith(n??{},this.useShadow),this.attach(r)}mountShadow(e,n){let r=typeof e=="string"?L(e):e;if(!r)throw new Error(`mount target not found: ${e}`);return(!this.content||n!==void 0||!this.useShadow)&&this.renderWith(n??{},!0),this.attach(r)}attach(e){this.mountRoot&&this.detach();let n=this.useShadow&&e instanceof Element?e.shadowRoot??e.attachShadow({mode:"open"}):e;return this.useShadow&&this.styleEls.forEach(r=>n.appendChild(r)),n.appendChild(this.content),this.mountRoot=n,this.resolveMounted?.(),this}detach(){if(!this.mountRoot||!this.content||!this.startMarker||!this.endMarker)return this;let e=this.startMarker;for(;e;){let n=e.nextSibling;if(this.content.appendChild(e),e===this.endMarker)break;e=n}return this.mountRoot=null,this}destroy(){return this.detach(),this.fx?.dispose(),this.fx=null,this.styleEls.forEach(e=>e.parentNode?.removeChild(e)),this.styleEls=[],this.ownsSharedStyles&&(this.styles.forEach(e=>Mt(e.content)),this.ownsSharedStyles=!1),this.content=null,this.startMarker=null,this.endMarker=null,this.data=null,this.resolveMounted=null,this}},zt=t=>new v(t);export{L as $,M as $$,D as $create,_ as $reactive,v as Component79,zt as parseComponent,qt as renderComponent};
10
10
  //# sourceMappingURL=jq79.js.map