2 lines
6.6 KiB
JavaScript
2 lines
6.6 KiB
JavaScript
var w=null,m=null,y=new Set,x=!1,O=new WeakMap,k=document,b=Array.isArray,P=Object.assign,W=(e)=>k.createElement(e),E=(e)=>k.createTextNode(String(e??"")),h=(e)=>typeof e==="function",A=(e)=>typeof e==="object"&&e!==null,L=(e,s)=>{let c=w;w=e;try{return s()}finally{w=c}},T=(e)=>{if(e._cleanups)e._cleanups.forEach((s)=>s()),e._cleanups.clear();e.childNodes?.forEach(T)},D=()=>{if(x)return;x=!0;while(y.size>0){let e=Array.from(y).sort((s,c)=>(s.depth||0)-(c.depth||0));y.clear();for(let s of e)if(!s._deleted)s()}x=!1},R=(e)=>{if(w&&!w._deleted)e.add(w),w._deps.add(e)},C=(e)=>{if(e.forEach((s)=>{if(s===w||s._deleted)return;if(s._isComputed){if(s.markDirty(),s._subs)C(s._subs)}else y.add(s)}),!x)queueMicrotask(D)},S=(e)=>{let s=new Set,c=m,i=W("div");i.style.display="contents",m={cleanups:s};let n=(t)=>{if(!t)return;if(t._isRuntime)s.add(t.destroy),i.appendChild(t.container);else if(b(t))t.forEach(n);else i.appendChild(t instanceof Node?t:E(t))};try{n(e({onCleanup:(t)=>s.add(t)}))}finally{m=c}return{_isRuntime:!0,container:i,destroy:()=>{s.forEach((t)=>t()),T(i),i.remove()}}},B=(e,s=null)=>{let c=new Set;if(h(e)){let n,t=!0,r=()=>{if(r._deleted)return;r._deps.forEach((a)=>a.delete(r)),r._deps.clear(),L(r,()=>{let a=e();if(!Object.is(n,a)||t)n=a,t=!1,C(c)})};if(P(r,{_deps:new Set,_isComputed:!0,_subs:c,_deleted:!1,markDirty:()=>t=!0,stop:()=>{r._deleted=!0,r._deps.forEach((a)=>a.delete(r)),c.clear()}}),m)m.cleanups.add(r.stop);return()=>{if(t)r();return R(c),n}}let i=e;if(s)try{let n=localStorage.getItem(s);if(n!==null)i=JSON.parse(n)}catch(n){console.warn("SigPro Storage Lock",n)}return(...n)=>{if(n.length){let t=h(n[0])?n[0](i):n[0];if(!Object.is(i,t)){if(i=t,s)localStorage.setItem(s,JSON.stringify(i));C(c)}}return R(c),i}},V=(e,s=new WeakMap)=>{if(!A(e))return e;if(s.has(e))return s.get(e);let c={},i=new Proxy(e,{get(n,t){if(w)R(c[t]??=new Set);let r=Reflect.get(n,t);return A(r)?V(r,s):r},set(n,t,r){if(Object.is(n[t],r))return!0;let a=Reflect.set(n,t,r);if(c[t])C(c[t]);return a}});return s.set(e,i),i},v=(e,s)=>{let c=b(e),i=c?s:e;if(!h(i))return()=>{};let n=m,t=()=>{if(t._deleted)return;t._deps.forEach((a)=>a.delete(t)),t._deps.clear(),t._cleanups.forEach((a)=>a()),t._cleanups.clear();let r=m;t.depth=w?w.depth+1:0,L(t,()=>{if(m={cleanups:t._cleanups},c)L(null,i),e.forEach((a)=>h(a)&&a());else i();m=r})};if(P(t,{_deps:new Set,_cleanups:new Set,_deleted:!1,stop:()=>{if(t._deleted)return;if(t._deleted=!0,y.delete(t),t._deps.forEach((r)=>r.delete(t)),t._cleanups.forEach((r)=>r()),n)n.cleanups.delete(t.stop)}}),n)n.cleanups.add(t.stop);return t(),t.stop},g=(e,s={},c=[])=>{if(s instanceof Node||b(s)||!A(s))c=s,s={};let n=/^(svg|path|circle|rect|line|polyline|polygon|g|defs|text|tspan|use)$/.test(e)?k.createElementNS("http://www.w3.org/2000/svg",e):W(e);n._cleanups=new Set,n.onUnmount=(o)=>n._cleanups.add(o);let t=["disabled","checked","required","readonly","selected","multiple","autofocus"],r=(o,l)=>{let d=(o==="src"||o==="href")&&String(l).toLowerCase().includes("javascript:")?"#":l;if(t.includes(o))n[o]=!!d,d?n.setAttribute(o,""):n.removeAttribute(o);else d==null?n.removeAttribute(o):n.setAttribute(o,d)};for(let[o,l]of Object.entries(s)){if(o==="ref"){h(l)?l(n):l.current=n;continue}let d=h(l);if(o.startsWith("on")){let p=o.slice(2).toLowerCase().split(".")[0];n.addEventListener(p,l),n._cleanups.add(()=>n.removeEventListener(p,l))}else if(d){if(n._cleanups.add(v(()=>{let p=l();o==="class"?n.className=p||"":r(o,p)})),["INPUT","TEXTAREA","SELECT"].includes(n.tagName)&&(o==="value"||o==="checked")){let p=o==="checked"?"change":"input",u=(f)=>l(f.target[o]);n.addEventListener(p,u),n._cleanups.add(()=>n.removeEventListener(p,u))}}else r(o,l)}let a=(o)=>{if(b(o))return o.forEach(a);if(h(o)){let l=E("");n.appendChild(l);let d=[];n._cleanups.add(v(()=>{let p=o(),u=(b(p)?p:[p]).map((f)=>f?._isRuntime?f.container:f instanceof Node?f:E(f));d.forEach((f)=>{T(f),f.remove()}),u.forEach((f)=>l.parentNode?.insertBefore(f,l)),d=u}))}else n.appendChild(o instanceof Node?o:E(o))};return a(c),n},U=(e,s,c=null,i=null)=>{let n=E(""),t=g("div",{style:"display:contents"},[n]),r=null,a=null;return v(()=>{let o=!!(h(e)?e():e);if(o===a)return;a=o;let l=()=>{if(r)r.destroy();r=null};if(r&&!o&&i?.out)i.out(r.container,l);else l();let d=o?s:c;if(d){if(r=S(()=>h(d)?d():d),t.insertBefore(r.container,n),o&&i?.in)i.in(r.container)}}),t},q=(e,s,c,i="div",n={style:"display:contents"})=>{let t=E(""),r=g(i,n,[t]),a=new Map;return v(()=>{let o=(h(e)?e():e)||[],l=new Map,d=[];for(let u=0;u<o.length;u++){let f=o[u],N=c?c(f,u):u,j=a.get(N)||S(()=>s(f,u));a.delete(N),l.set(N,j),d.push(N)}a.forEach((u)=>{u.destroy(),u.container.remove()});let p=t;for(let u=d.length-1;u>=0;u--){let f=l.get(d[u]);if(f.container.nextSibling!==p)r.insertBefore(f.container,p);p=f.container}a=l}),r},_=(e)=>{let s=B(window.location.hash.replace(/^#/,"")||"/");window.addEventListener("hashchange",()=>s(window.location.hash.replace(/^#/,"")||"/"));let c=g("div",{class:"router-outlet"}),i=null;return v([s],async()=>{let n=s(),t=e.find((r)=>{let a=r.path.split("/").filter(Boolean),o=n.split("/").filter(Boolean);return a.length===o.length&&a.every((l,d)=>l.startsWith(":")||l===o[d])})||e.find((r)=>r.path==="*");if(t){let r=t.component;if(h(r)&&r.toString().includes("import"))r=(await r()).default||await r();let a={};if(t.path.split("/").filter(Boolean).forEach((o,l)=>{if(o.startsWith(":"))a[o.slice(1)]=n.split("/").filter(Boolean)[l]}),i)i.destroy();if(_.params)_.params(a);i=S(()=>{try{return h(r)?r(a):r}catch(o){return g("div",{class:"p-4 text-error"},"Error loading view")}}),c.appendChild(i.container)}}),c};_.params=B({});_.to=(e)=>window.location.hash=e.replace(/^#?\/?/,"#/");_.back=()=>window.history.back();_.path=()=>window.location.hash.replace(/^#/,"")||"/";var I=(e,s)=>{let c=typeof s==="string"?k.querySelector(s):s;if(!c)return;if(O.has(c))O.get(c).destroy();let i=S(h(e)?e:()=>e);return c.replaceChildren(i.container),O.set(c,i),i},$=({children:e})=>e,M={$:B,$$:V,Render:S,Watch:v,Tag:g,If:U,For:q,Router:_,Mount:I,Fragment:$};if(typeof window<"u")P(window,M),"div span p h1 h2 h3 h4 h5 h6 br hr section article aside nav main header footer address ul ol li dl dt dd a em strong small i b u mark time sub sup pre code blockquote details summary dialog form label input textarea select button option fieldset legend table thead tbody tfoot tr th td caption img video audio canvas svg iframe picture source progress meter".split(" ").forEach((s)=>{let c=s[0].toUpperCase()+s.slice(1);if(!(c in window))window[c]=(i,n)=>g(s,i,n)}),window.SigPro=Object.freeze(M);export{v as Watch,g as Tag,_ as Router,S as Render,I as Mount,U as If,$ as Fragment,q as For,V as $$,B as $};
|