2 lines
6.7 KiB
JavaScript
2 lines
6.7 KiB
JavaScript
(()=>{var{defineProperty:M,getOwnPropertyNames:w,getOwnPropertyDescriptor:$}=Object,k=Object.prototype.hasOwnProperty;var N=new WeakMap,g=(X)=>{var J=N.get(X),W;if(J)return J;if(J=M({},"__esModule",{value:!0}),X&&typeof X==="object"||typeof X==="function")w(X).map((q)=>!k.call(J,q)&&M(J,q,{get:()=>X[q],enumerable:!(W=$(X,q))||W.enumerable}));return N.set(X,J),J};var v=(X,J)=>{for(var W in J)M(X,W,{get:J[W],enumerable:!0,configurable:!0,set:(q)=>J[W]=()=>q})};var m={};v(m,{$watch:()=>C,$router:()=>H,$mount:()=>E,$if:()=>T,$html:()=>I,$for:()=>b,$:()=>D});var R=null,A=null,P=new Set,F=!1,S=new WeakMap,y=()=>{if(F)return;F=!0;while(P.size>0){let X=Array.from(P).sort((J,W)=>(J.depth||0)-(W.depth||0));P.clear();for(let J of X)if(!J._deleted)J()}F=!1},O=(X)=>{if(R&&!R._deleted)X.add(R),R._deps.add(X)},x=(X)=>{for(let J of X){if(J===R||J._deleted)continue;if(J._isComputed){if(J.markDirty(),J._subs)x(J._subs)}else P.add(J)}if(!F)queueMicrotask(y)},V=(X)=>{if(X._cleanups)X._cleanups.forEach((J)=>J()),X._cleanups.clear();X.childNodes?.forEach(V)},_=(X)=>{let J=new Set,W=A,q=document.createElement("div");q.style.display="contents",A={cleanups:J};try{let Y=X({onCleanup:(j)=>J.add(j)}),z=(j)=>{if(!j)return;if(j._isRuntime)J.add(j.destroy),q.appendChild(j.container);else if(Array.isArray(j))j.forEach(z);else q.appendChild(j instanceof Node?j:document.createTextNode(String(j)))};z(Y)}finally{A=W}return{_isRuntime:!0,container:q,destroy:()=>{J.forEach((Y)=>Y()),V(q),q.remove()}}},D=(X,J=null)=>{if(typeof X==="function"){let Y=new Set,z,j=!0,Z=()=>{if(Z._deleted)return;Z._deps.forEach((G)=>G.delete(Z)),Z._deps.clear();let B=R;R=Z;try{let G=X();if(!Object.is(z,G)||j)z=G,j=!1,x(Y)}finally{R=B}};if(Z._deps=new Set,Z._isComputed=!0,Z._subs=Y,Z._deleted=!1,Z.markDirty=()=>j=!0,Z.stop=()=>{Z._deleted=!0,Z._deps.forEach((B)=>B.delete(Z)),Y.clear()},A)A.cleanups.add(Z.stop);return()=>{if(j)Z();return O(Y),z}}let W=X;if(J)try{let Y=localStorage.getItem(J);if(Y!==null)W=JSON.parse(Y)}catch(Y){console.warn("SigPro: LocalStorage locked",Y)}let q=new Set;return(...Y)=>{if(Y.length){let z=typeof Y[0]==="function"?Y[0](W):Y[0];if(!Object.is(W,z)){if(W=z,J)localStorage.setItem(J,JSON.stringify(W));x(q)}}return O(q),W}},C=(X,J)=>{let W=Array.isArray(X),q=W?J:X,Y=W?X:null;if(typeof q!=="function")return()=>{};let z=A,j=()=>{if(j._deleted)return;j._deps.forEach((G)=>G.delete(j)),j._deps.clear(),j._cleanups.forEach((G)=>G()),j._cleanups.clear();let Z=R,B=A;R=j,A={cleanups:j._cleanups},j.depth=Z?Z.depth+1:0;try{if(W)R=null,q(),R=j,Y.forEach((G)=>typeof G==="function"&&G());else q()}finally{R=Z,A=B}};if(j._deps=new Set,j._cleanups=new Set,j._deleted=!1,j.stop=()=>{if(j._deleted)return;if(j._deleted=!0,P.delete(j),j._deps.forEach((Z)=>Z.delete(j)),j._cleanups.forEach((Z)=>Z()),z)z.cleanups.delete(j.stop)},z)z.cleanups.add(j.stop);return j(),j.stop},I=(X,J={},W=[])=>{if(J instanceof Node||Array.isArray(J)||typeof J!=="object")W=J,J={};let q=document.createElement(X),Y=(j,Z)=>(j==="src"||j==="href")&&String(Z).toLowerCase().includes("javascript:")?"#":Z;q._cleanups=new Set;for(let[j,Z]of Object.entries(J)){if(j==="ref"){typeof Z==="function"?Z(q):Z.current=q;continue}let B=typeof Z==="function";if(["INPUT","TEXTAREA","SELECT"].includes(q.tagName)&&(j==="value"||j==="checked")&&B){q._cleanups.add(C(()=>{let L=Z();if(q[j]!==L)q[j]=L}));let K=j==="checked"?"change":"input",Q=(L)=>Z(L.target[j]);q.addEventListener(K,Q),q._cleanups.add(()=>q.removeEventListener(K,Q))}else if(j.startsWith("on")){let K=j.slice(2).toLowerCase().split(".")[0],Q=(L)=>Z(L);q.addEventListener(K,Q),q._cleanups.add(()=>q.removeEventListener(K,Q))}else if(B)q._cleanups.add(C(()=>{let K=Y(j,Z());if(j==="class")q.className=K||"";else K==null?q.removeAttribute(j):q.setAttribute(j,K)}));else q.setAttribute(j,Y(j,Z))}let z=(j)=>{if(Array.isArray(j))return j.forEach(z);if(typeof j==="function"){let Z=document.createTextNode("");q.appendChild(Z);let B=[];q._cleanups.add(C(()=>{let G=j(),U=(Array.isArray(G)?G:[G]).map((K)=>K?._isRuntime?K.container:K instanceof Node?K:document.createTextNode(K??""));B.forEach((K)=>{V(K),K.remove()}),U.forEach((K)=>Z.parentNode?.insertBefore(K,Z)),B=U}))}else q.appendChild(j instanceof Node?j:document.createTextNode(j??""))};return z(W),q},T=(X,J,W=null)=>{let q=document.createTextNode(""),Y=I("div",{style:"display:contents"},[q]),z=null,j=null;return C(()=>{let Z=!!(typeof X==="function"?X():X);if(Z!==j){if(j=Z,z)z.destroy();let B=Z?J:W;if(B)z=_(()=>typeof B==="function"?B():B),Y.insertBefore(z.container,q)}}),Y};T.not=(X,J,W)=>T(()=>!(typeof X==="function"?X():X),J,W);var b=(X,J,W=(q,Y)=>Y)=>{let q=document.createTextNode(""),Y=I("div",{style:"display:contents"},[q]),z=new Map;return C(()=>{let j=(typeof X==="function"?X():X)||[],Z=new Set;j.forEach((B,G)=>{let U=W(B,G);Z.add(U);let K=z.get(U);if(!K)K=_(()=>J(B,G)),z.set(U,K);Y.insertBefore(K.container,q)}),z.forEach((B,G)=>{if(!Z.has(G)){if(B.destroy(),B.container&&B.container.parentNode)B.container.remove();z.delete(G)}})}),Y},H=(X)=>{let J=D(window.location.hash.replace(/^#/,"")||"/");window.addEventListener("hashchange",()=>J(window.location.hash.replace(/^#/,"")||"/"));let W=I("div",{class:"router-outlet"}),q=null;return C([J],async()=>{let Y=J(),z=X.find((j)=>{let Z=j.path.split("/").filter(Boolean),B=Y.split("/").filter(Boolean);return Z.length===B.length&&Z.every((G,U)=>G.startsWith(":")||G===B[U])})||X.find((j)=>j.path==="*");if(z){let j=z.component;if(typeof j==="function"&&j.toString().includes("import"))j=(await j()).default||await j();let Z={};if(z.path.split("/").filter(Boolean).forEach((B,G)=>{if(B.startsWith(":"))Z[B.slice(1)]=Y.split("/").filter(Boolean)[G]}),q)q.destroy();if(H.params)H.params(Z);q=_(()=>{try{return typeof j==="function"?j(Z):j}catch(B){return I("div",{class:"p-4 text-error"},"Error loading view")}}),W.appendChild(q.container)}}),W};H.params=D({});H.to=(X)=>window.location.hash=X.replace(/^#?\/?/,"#/");H.back=()=>window.history.back();H.path=()=>window.location.hash.replace(/^#/,"")||"/";var E=(X,J)=>{let W=typeof J==="string"?document.querySelector(J):J;if(!W)return;if(S.has(W))S.get(W).destroy();let q=_(typeof X==="function"?X:()=>X);return W.replaceChildren(q.container),S.set(W,q),q},h={$:D,$watch:C,$html:I,$if:T,$for:b,$router:H,$mount:E};if(typeof window<"u")((J)=>{Object.keys(J).forEach((q)=>{window[q]=J[q]}),"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(/\s+/).forEach((q)=>{let Y=q.charAt(0).toUpperCase()+q.slice(1);if(!(Y in window))window[Y]=(z,j)=>I(q,z,j)}),window.SigPro=Object.freeze(J)})(h);})();
|