From d0ffb69b95112b79f059fa7c1eaa484c14a4f744 Mon Sep 17 00:00:00 2001 From: natxocc Date: Tue, 31 Mar 2026 11:27:44 +0200 Subject: [PATCH] Comptible with ESM and UMD --- .gitignore | 1 - dist/sigpro.js | 414 ++++++++++++++++++++++++++++++++++++++++++++ dist/sigpro.min.js | 1 + package.json | 12 +- sigpro/index.min.js | 1 + 5 files changed, 426 insertions(+), 3 deletions(-) create mode 100644 dist/sigpro.js create mode 100644 dist/sigpro.min.js create mode 100644 sigpro/index.min.js diff --git a/.gitignore b/.gitignore index f72ad73..99bd3a2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ node_modules/ jspm_packages/ # Build and Distribution -dist/ lib-cov/ coverage/ *.lcov diff --git a/dist/sigpro.js b/dist/sigpro.js new file mode 100644 index 0000000..9f7856e --- /dev/null +++ b/dist/sigpro.js @@ -0,0 +1,414 @@ +(() => { + var __defProp = Object.defineProperty; + var __getOwnPropNames = Object.getOwnPropertyNames; + var __getOwnPropDesc = Object.getOwnPropertyDescriptor; + var __hasOwnProp = Object.prototype.hasOwnProperty; + var __moduleCache = /* @__PURE__ */ new WeakMap; + var __toCommonJS = (from) => { + var entry = __moduleCache.get(from), desc; + if (entry) + return entry; + entry = __defProp({}, "__esModule", { value: true }); + if (from && typeof from === "object" || typeof from === "function") + __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, { + get: () => from[key], + enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable + })); + __moduleCache.set(from, entry); + return entry; + }; + var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { + get: all[name], + enumerable: true, + configurable: true, + set: (newValue) => all[name] = () => newValue + }); + }; + + // index.js + var exports_sigpro = {}; + __export(exports_sigpro, { + $watch: () => $watch, + $router: () => $router, + $mount: () => $mount, + $if: () => $if, + $html: () => $html, + $for: () => $for, + $: () => $ + }); + + // sigpro/index.js + var activeEffect = null; + var currentOwner = null; + var effectQueue = new Set; + var isFlushing = false; + var MOUNTED_NODES = new WeakMap; + var flush = () => { + if (isFlushing) + return; + isFlushing = true; + while (effectQueue.size > 0) { + const sorted = Array.from(effectQueue).sort((a, b) => (a.depth || 0) - (b.depth || 0)); + effectQueue.clear(); + for (const eff of sorted) + if (!eff._deleted) + eff(); + } + isFlushing = false; + }; + var track = (subs) => { + if (activeEffect && !activeEffect._deleted) { + subs.add(activeEffect); + activeEffect._deps.add(subs); + } + }; + var trigger = (subs) => { + for (const eff of subs) { + if (eff === activeEffect || eff._deleted) + continue; + if (eff._isComputed) { + eff.markDirty(); + if (eff._subs) + trigger(eff._subs); + } else { + effectQueue.add(eff); + } + } + if (!isFlushing) + queueMicrotask(flush); + }; + var sweep = (node) => { + if (node._cleanups) { + node._cleanups.forEach((f) => f()); + node._cleanups.clear(); + } + node.childNodes?.forEach(sweep); + }; + var _view = (fn) => { + const cleanups = new Set; + const prev = currentOwner; + const container = document.createElement("div"); + container.style.display = "contents"; + currentOwner = { cleanups }; + try { + const res = fn({ onCleanup: (f) => cleanups.add(f) }); + const process = (n) => { + if (!n) + return; + if (n._isRuntime) { + cleanups.add(n.destroy); + container.appendChild(n.container); + } else if (Array.isArray(n)) + n.forEach(process); + else + container.appendChild(n instanceof Node ? n : document.createTextNode(String(n))); + }; + process(res); + } finally { + currentOwner = prev; + } + return { + _isRuntime: true, + container, + destroy: () => { + cleanups.forEach((f) => f()); + sweep(container); + container.remove(); + } + }; + }; + var $ = (initial, key = null) => { + if (typeof initial === "function") { + const subs2 = new Set; + let cached, dirty = true; + const effect = () => { + if (effect._deleted) + return; + effect._deps.forEach((s) => s.delete(effect)); + effect._deps.clear(); + const prev = activeEffect; + activeEffect = effect; + try { + const val = initial(); + if (!Object.is(cached, val) || dirty) { + cached = val; + dirty = false; + trigger(subs2); + } + } finally { + activeEffect = prev; + } + }; + effect._deps = new Set; + effect._isComputed = true; + effect._subs = subs2; + effect._deleted = false; + effect.markDirty = () => dirty = true; + effect.stop = () => { + effect._deleted = true; + effect._deps.forEach((s) => s.delete(effect)); + subs2.clear(); + }; + if (currentOwner) + currentOwner.cleanups.add(effect.stop); + return () => { + if (dirty) + effect(); + track(subs2); + return cached; + }; + } + let value = initial; + if (key) { + try { + const saved = localStorage.getItem(key); + if (saved !== null) + value = JSON.parse(saved); + } catch (e) { + console.warn("SigPro: LocalStorage locked", e); + } + } + const subs = new Set; + return (...args) => { + if (args.length) { + const next = typeof args[0] === "function" ? args[0](value) : args[0]; + if (!Object.is(value, next)) { + value = next; + if (key) + localStorage.setItem(key, JSON.stringify(value)); + trigger(subs); + } + } + track(subs); + return value; + }; + }; + var $watch = (target, fn) => { + const isExplicit = Array.isArray(target); + const callback = isExplicit ? fn : target; + const depsInput = isExplicit ? target : null; + if (typeof callback !== "function") + return () => {}; + const owner = currentOwner; + const runner = () => { + if (runner._deleted) + return; + runner._deps.forEach((s) => s.delete(runner)); + runner._deps.clear(); + runner._cleanups.forEach((c) => c()); + runner._cleanups.clear(); + const prevEffect = activeEffect; + const prevOwner = currentOwner; + activeEffect = runner; + currentOwner = { cleanups: runner._cleanups }; + runner.depth = prevEffect ? prevEffect.depth + 1 : 0; + try { + if (isExplicit) { + activeEffect = null; + callback(); + activeEffect = runner; + depsInput.forEach((d) => typeof d === "function" && d()); + } else { + callback(); + } + } finally { + activeEffect = prevEffect; + currentOwner = prevOwner; + } + }; + runner._deps = new Set; + runner._cleanups = new Set; + runner._deleted = false; + runner.stop = () => { + if (runner._deleted) + return; + runner._deleted = true; + effectQueue.delete(runner); + runner._deps.forEach((s) => s.delete(runner)); + runner._cleanups.forEach((c) => c()); + if (owner) + owner.cleanups.delete(runner.stop); + }; + if (owner) + owner.cleanups.add(runner.stop); + runner(); + return runner.stop; + }; + var $html = (tag, props = {}, content = []) => { + if (props instanceof Node || Array.isArray(props) || typeof props !== "object") { + content = props; + props = {}; + } + const el = document.createElement(tag), _sanitize = (key, val) => (key === "src" || key === "href") && String(val).toLowerCase().includes("javascript:") ? "#" : val; + el._cleanups = new Set; + for (let [key, val] of Object.entries(props)) { + if (key === "ref") { + typeof val === "function" ? val(el) : val.current = el; + continue; + } + const isSignal = typeof val === "function", isInput = ["INPUT", "TEXTAREA", "SELECT"].includes(el.tagName), isBindAttr = key === "value" || key === "checked"; + if (isInput && isBindAttr && isSignal) { + el._cleanups.add($watch(() => { + const currentVal = val(); + if (el[key] !== currentVal) + el[key] = currentVal; + })); + const eventName = key === "checked" ? "change" : "input", handler = (event) => val(event.target[key]); + el.addEventListener(eventName, handler); + el._cleanups.add(() => el.removeEventListener(eventName, handler)); + } else if (key.startsWith("on")) { + const eventName = key.slice(2).toLowerCase().split(".")[0], handler = (event) => val(event); + el.addEventListener(eventName, handler); + el._cleanups.add(() => el.removeEventListener(eventName, handler)); + } else if (isSignal) { + el._cleanups.add($watch(() => { + const currentVal = _sanitize(key, val()); + if (key === "class") + el.className = currentVal || ""; + else + currentVal == null ? el.removeAttribute(key) : el.setAttribute(key, currentVal); + })); + } else { + el.setAttribute(key, _sanitize(key, val)); + } + } + const append = (child) => { + if (Array.isArray(child)) + return child.forEach(append); + if (typeof child === "function") { + const marker = document.createTextNode(""); + el.appendChild(marker); + let nodes = []; + el._cleanups.add($watch(() => { + const result = child(), nextNodes = (Array.isArray(result) ? result : [result]).map((item) => item?._isRuntime ? item.container : item instanceof Node ? item : document.createTextNode(item ?? "")); + nodes.forEach((node) => { + sweep(node); + node.remove(); + }); + nextNodes.forEach((node) => marker.parentNode?.insertBefore(node, marker)); + nodes = nextNodes; + })); + } else + el.appendChild(child instanceof Node ? child : document.createTextNode(child ?? "")); + }; + append(content); + return el; + }; + var $if = (condition, thenVal, otherwiseVal = null) => { + const marker = document.createTextNode(""); + const container = $html("div", { style: "display:contents" }, [marker]); + let current = null, last = null; + $watch(() => { + const state = !!(typeof condition === "function" ? condition() : condition); + if (state !== last) { + last = state; + if (current) + current.destroy(); + const branch = state ? thenVal : otherwiseVal; + if (branch) { + current = _view(() => typeof branch === "function" ? branch() : branch); + container.insertBefore(current.container, marker); + } + } + }); + return container; + }; + $if.not = (condition, thenVal, otherwiseVal) => $if(() => !(typeof condition === "function" ? condition() : condition), thenVal, otherwiseVal); + var $for = (source, render, keyFn) => { + const marker = document.createTextNode(""); + const container = $html("div", { style: "display:contents" }, [marker]); + const cache = new Map; + $watch(() => { + const items = (typeof source === "function" ? source() : source) || []; + const newKeys = new Set; + items.forEach((item, index) => { + const key = keyFn(item, index); + newKeys.add(key); + let run = cache.get(key); + if (!run) { + run = _view(() => render(item, index)); + cache.set(key, run); + } + container.insertBefore(run.container, marker); + }); + cache.forEach((run, key) => { + if (!newKeys.has(key)) { + run.destroy(); + cache.delete(key); + } + }); + }); + return container; + }; + var $router = (routes) => { + const sPath = $(window.location.hash.replace(/^#/, "") || "/"); + window.addEventListener("hashchange", () => sPath(window.location.hash.replace(/^#/, "") || "/")); + const outlet = $html("div", { class: "router-outlet" }); + let current = null; + $watch([sPath], async () => { + const path = sPath(); + const route = routes.find((r) => { + const rp = r.path.split("/").filter(Boolean), pp = path.split("/").filter(Boolean); + return rp.length === pp.length && rp.every((p, i) => p.startsWith(":") || p === pp[i]); + }) || routes.find((r) => r.path === "*"); + if (route) { + let comp = route.component; + if (typeof comp === "function" && comp.toString().includes("import")) { + comp = (await comp()).default || await comp(); + } + const params = {}; + route.path.split("/").filter(Boolean).forEach((p, i) => { + if (p.startsWith(":")) + params[p.slice(1)] = path.split("/").filter(Boolean)[i]; + }); + if (current) + current.destroy(); + if ($router.params) + $router.params(params); + current = _view(() => { + try { + return typeof comp === "function" ? comp(params) : comp; + } catch (e) { + return $html("div", { class: "p-4 text-error" }, "Error loading view"); + } + }); + outlet.appendChild(current.container); + } + }); + return outlet; + }; + $router.params = $({}); + $router.to = (path) => window.location.hash = path.replace(/^#?\/?/, "#/"); + $router.back = () => window.history.back(); + $router.path = () => window.location.hash.replace(/^#/, "") || "/"; + var $mount = (component, target) => { + const el = typeof target === "string" ? document.querySelector(target) : target; + if (!el) + return; + if (MOUNTED_NODES.has(el)) + MOUNTED_NODES.get(el).destroy(); + const instance = _view(typeof component === "function" ? component : () => component); + el.replaceChildren(instance.container); + MOUNTED_NODES.set(el, instance); + return instance; + }; + var SigProCore = { $, $watch, $html, $if, $for, $router, $mount }; + if (typeof window !== "undefined") { + const install = (registry) => { + Object.keys(registry).forEach((key) => { + window[key] = registry[key]; + }); + const tags = `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+/); + tags.forEach((tagName) => { + const helperName = tagName.charAt(0).toUpperCase() + tagName.slice(1); + if (!(helperName in window)) { + window[helperName] = (props, content) => $html(tagName, props, content); + } + }); + window.SigPro = Object.freeze(registry); + }; + install(SigProCore); + } +})(); diff --git a/dist/sigpro.min.js b/dist/sigpro.min.js new file mode 100644 index 0000000..4cbac13 --- /dev/null +++ b/dist/sigpro.min.js @@ -0,0 +1 @@ +(()=>{var{defineProperty:D,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=D({},"__esModule",{value:!0}),X&&typeof X==="object"||typeof X==="function")w(X).map((q)=>!k.call(J,q)&&D(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)D(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,$:()=>x});var R=null,A=null,P=new Set,F=!1,M=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)},S=(X)=>{for(let J of X){if(J===R||J._deleted)continue;if(J._isComputed){if(J.markDirty(),J._subs)S(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()}}},x=(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,S(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));S(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)=>{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))B.destroy(),z.delete(G)})}),Y},H=(X)=>{let J=x(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=x({});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(M.has(W))M.get(W).destroy();let q=_(typeof X==="function"?X:()=>X);return W.replaceChildren(q.container),M.set(W,q),q},h={$:x,$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);})(); diff --git a/package.json b/package.json index 33a1fb4..24a6001 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,23 @@ { "name": "sigpro", - "version": "1.1.16", + "version": "1.1.17", "type": "module", "license": "MIT", "main": "./index.js", "module": "./index.js", + "unpkg": "./dist/sigpro.min.js", + "jsdelivr": "./dist/sigpro.min.js", "exports": { - ".": "./index.js", + ".": { + "import": "./index.js", + "script": "./dist/sigpro.js" + }, "./vite": "./vite/index.js", "./vite/*": "./vite/*.js" }, "files": [ "index.js", + "dist", "sigpro", "vite", "README.md", @@ -26,6 +32,8 @@ "url": "https://github.com/natxocc/sigpro/issues" }, "scripts": { + "build": "bun build ./index.js --bundle --outfile=./dist/sigpro.js --format=iife --global-name=SigPro && bun build ./index.js --bundle --outfile=./dist/sigpro.min.js --format=iife --global-name=SigPro --minify", + "prepublishOnly": "bun run build", "docs": "bun x serve docs" }, "keywords": [ diff --git a/sigpro/index.min.js b/sigpro/index.min.js new file mode 100644 index 0000000..a05a272 --- /dev/null +++ b/sigpro/index.min.js @@ -0,0 +1 @@ +let activeEffect=null,currentOwner=null;const effectQueue=new Set;let isFlushing=!1;const MOUNTED_NODES=new WeakMap,flush=()=>{if(!isFlushing){for(isFlushing=!0;effectQueue.size>0;){const e=Array.from(effectQueue).sort(((e,t)=>(e.depth||0)-(t.depth||0)));effectQueue.clear();for(const t of e)t._deleted||t()}isFlushing=!1}},track=e=>{activeEffect&&!activeEffect._deleted&&(e.add(activeEffect),activeEffect._deps.add(e))},trigger=e=>{for(const t of e)t===activeEffect||t._deleted||(t._isComputed?(t.markDirty(),t._subs&&trigger(t._subs)):effectQueue.add(t));isFlushing||queueMicrotask(flush)},sweep=e=>{e._cleanups&&(e._cleanups.forEach((e=>e())),e._cleanups.clear()),e.childNodes?.forEach(sweep)},_view=e=>{const t=new Set,n=currentOwner,r=document.createElement("div");r.style.display="contents",currentOwner={cleanups:t};try{const o=e({onCleanup:e=>t.add(e)}),c=e=>{e&&(e._isRuntime?(t.add(e.destroy),r.appendChild(e.container)):Array.isArray(e)?e.forEach(c):r.appendChild(e instanceof Node?e:document.createTextNode(String(e))))};c(o)}finally{currentOwner=n}return{_isRuntime:!0,container:r,destroy:()=>{t.forEach((e=>e())),sweep(r),r.remove()}}},$=(e,t=null)=>{if("function"==typeof e){const t=new Set;let n,r=!0;const o=()=>{if(o._deleted)return;o._deps.forEach((e=>e.delete(o))),o._deps.clear();const c=activeEffect;activeEffect=o;try{const o=e();Object.is(n,o)&&!r||(n=o,r=!1,trigger(t))}finally{activeEffect=c}};return o._deps=new Set,o._isComputed=!0,o._subs=t,o._deleted=!1,o.markDirty=()=>r=!0,o.stop=()=>{o._deleted=!0,o._deps.forEach((e=>e.delete(o))),t.clear()},currentOwner&¤tOwner.cleanups.add(o.stop),()=>(r&&o(),track(t),n)}let n=e;if(t)try{const e=localStorage.getItem(t);null!==e&&(n=JSON.parse(e))}catch(e){}const r=new Set;return(...e)=>{if(e.length){const o="function"==typeof e[0]?e[0](n):e[0];Object.is(n,o)||(n=o,t&&localStorage.setItem(t,JSON.stringify(n)),trigger(r))}return track(r),n}},$watch=(e,t)=>{const n=Array.isArray(e),r=n?t:e,o=n?e:null;if("function"!=typeof r)return()=>{};const c=currentOwner,a=()=>{if(a._deleted)return;a._deps.forEach((e=>e.delete(a))),a._deps.clear(),a._cleanups.forEach((e=>e())),a._cleanups.clear();const e=activeEffect,t=currentOwner;activeEffect=a,currentOwner={cleanups:a._cleanups},a.depth=e?e.depth+1:0;try{n?(activeEffect=null,r(),activeEffect=a,o.forEach((e=>"function"==typeof e&&e()))):r()}finally{activeEffect=e,currentOwner=t}};return a._deps=new Set,a._cleanups=new Set,a._deleted=!1,a.stop=()=>{a._deleted||(a._deleted=!0,effectQueue.delete(a),a._deps.forEach((e=>e.delete(a))),a._cleanups.forEach((e=>e())),c&&c.cleanups.delete(a.stop))},c&&c.cleanups.add(a.stop),a(),a.stop},$html=(e,t={},n=[])=>{(t instanceof Node||Array.isArray(t)||"object"!=typeof t)&&(n=t,t={});const r=document.createElement(e),o=(e,t)=>"src"!==e&&"href"!==e||!String(t).toLowerCase().includes("javascript:")?t:"#";r._cleanups=new Set;for(let[e,n]of Object.entries(t)){if("ref"===e){"function"==typeof n?n(r):n.current=r;continue}const t="function"==typeof n,c=["INPUT","TEXTAREA","SELECT"].includes(r.tagName),a="value"===e||"checked"===e;if(c&&a&&t){r._cleanups.add($watch((()=>{const t=n();r[e]!==t&&(r[e]=t)})));const t="checked"===e?"change":"input",o=t=>n(t.target[e]);r.addEventListener(t,o),r._cleanups.add((()=>r.removeEventListener(t,o)))}else if(e.startsWith("on")){const t=e.slice(2).toLowerCase().split(".")[0],o=e=>n(e);r.addEventListener(t,o),r._cleanups.add((()=>r.removeEventListener(t,o)))}else t?r._cleanups.add($watch((()=>{const t=o(e,n());"class"===e?r.className=t||"":null==t?r.removeAttribute(e):r.setAttribute(e,t)}))):r.setAttribute(e,o(e,n))}const c=e=>{if(Array.isArray(e))return e.forEach(c);if("function"==typeof e){const t=document.createTextNode("");r.appendChild(t);let n=[];r._cleanups.add($watch((()=>{const r=e(),o=(Array.isArray(r)?r:[r]).map((e=>e?._isRuntime?e.container:e instanceof Node?e:document.createTextNode(e??"")));n.forEach((e=>{sweep(e),e.remove()})),o.forEach((e=>t.parentNode?.insertBefore(e,t))),n=o})))}else r.appendChild(e instanceof Node?e:document.createTextNode(e??""))};return c(n),r},$if=(e,t,n=null)=>{const r=document.createTextNode(""),o=$html("div",{style:"display:contents"},[r]);let c=null,a=null;return $watch((()=>{const s=!!("function"==typeof e?e():e);if(s!==a){a=s,c&&c.destroy();const e=s?t:n;e&&(c=_view((()=>"function"==typeof e?e():e)),o.insertBefore(c.container,r))}})),o};$if.not=(e,t,n)=>$if((()=>!("function"==typeof e?e():e)),t,n);const $for=(e,t,n)=>{const r=document.createTextNode(""),o=$html("div",{style:"display:contents"},[r]),c=new Map;return $watch((()=>{const a=("function"==typeof e?e():e)||[],s=new Set;a.forEach(((e,a)=>{const i=n(e,a);s.add(i);let l=c.get(i);l||(l=_view((()=>t(e,a))),c.set(i,l)),o.insertBefore(l.container,r)})),c.forEach(((e,t)=>{s.has(t)||(e.destroy(),c.delete(t))}))})),o},$router=e=>{const t=$(window.location.hash.replace(/^#/,"")||"/");window.addEventListener("hashchange",(()=>t(window.location.hash.replace(/^#/,"")||"/")));const n=$html("div",{class:"router-outlet"});let r=null;return $watch([t],(async()=>{const o=t(),c=e.find((e=>{const t=e.path.split("/").filter(Boolean),n=o.split("/").filter(Boolean);return t.length===n.length&&t.every(((e,t)=>e.startsWith(":")||e===n[t]))}))||e.find((e=>"*"===e.path));if(c){let e=c.component;"function"==typeof e&&e.toString().includes("import")&&(e=(await e()).default||await e());const t={};c.path.split("/").filter(Boolean).forEach(((e,n)=>{e.startsWith(":")&&(t[e.slice(1)]=o.split("/").filter(Boolean)[n])})),r&&r.destroy(),$router.params&&$router.params(t),r=_view((()=>{try{return"function"==typeof e?e(t):e}catch(e){return $html("div",{class:"p-4 text-error"},"Error loading view")}})),n.appendChild(r.container)}})),n};$router.params=$({}),$router.to=e=>window.location.hash=e.replace(/^#?\/?/,"#/"),$router.back=()=>window.history.back(),$router.path=()=>window.location.hash.replace(/^#/,"")||"/";const $mount=(e,t)=>{const n="string"==typeof t?document.querySelector(t):t;if(!n)return;MOUNTED_NODES.has(n)&&MOUNTED_NODES.get(n).destroy();const r=_view("function"==typeof e?e:()=>e);return n.replaceChildren(r.container),MOUNTED_NODES.set(n,r),r},SigProCore={$:$,$watch:$watch,$html:$html,$if:$if,$for:$for,$router:$router,$mount:$mount};if("undefined"!=typeof window){(e=>{Object.keys(e).forEach((t=>{window[t]=e[t]}));"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((e=>{const t=e.charAt(0).toUpperCase()+e.slice(1);t in window||(window[t]=(t,n)=>$html(e,t,n))})),window.SigPro=Object.freeze(e)})(SigProCore)}export{$,$watch,$html,$if,$for,$router,$mount};export default SigProCore; \ No newline at end of file