2 lines
8.3 KiB
JavaScript
2 lines
8.3 KiB
JavaScript
var m=(e)=>typeof e==="function",j=(e)=>e&&typeof e==="object",N=Array.isArray,E=typeof document<"u"?document:null,$=(e)=>e?._isRuntime?e.container:e instanceof Node?e:E.createTextNode(e==null?"":String(e)),p=null,_=null,x=!1,A=0,T=new Set,U=new WeakMap,L=Symbol("iter"),M=new WeakMap,v=(e)=>{if(!e||e._disposed)return;e._disposed=!0;let s=[e];while(s.length){let t=s.pop();if(t._cleanups)t._cleanups.forEach((r)=>r()),t._cleanups.clear();if(t._children)t._children.forEach((r)=>s.push(r)),t._children.clear();if(t._deps)t._deps.forEach((r)=>r.delete(t)),t._deps.clear()}},q=(e)=>{if(_)(_._mounts||=[]).push(e)},g=(e)=>{if(_)(_._cleanups||=new Set).add(e)},z=(e)=>{let s=p;p=null;try{return e()}finally{p=s}},C=(e,s=!1)=>{let t=()=>{if(t._disposed)return;if(t._deps)t._deps.forEach((i)=>i.delete(t));if(t._cleanups)t._cleanups.forEach((i)=>i()),t._cleanups.clear();let r=p,n=_;p=_=t;try{return t._result=e()}catch(i){console.error("[SigPro]",i)}finally{p=r,_=n}};if(t._deps=t._cleanups=t._children=null,t._disposed=!1,t._isComputed=s,t._depth=p?p._depth+1:0,t._mounts=[],t._parent=_,_)(_._children||=new Set).add(t);return t},D=()=>{if(x)return;x=!0;let e=Array.from(T).sort((s,t)=>s._depth-t._depth);T.clear();for(let s of e)if(!s._disposed)s();x=!1},F=(e)=>{A++;try{return e()}finally{if(A--,A===0&&T.size>0&&!x)D()}},w=(e,s=!1)=>{if(!s&&p&&!p._disposed)e.add(p),(p._deps||=new Set).add(e);else if(s&&e.size>0){let t=!1;for(let r of e){if(r===p||r._disposed)continue;if(r._isComputed){if(r._dirty=!0,r._subs)w(r._subs,!0)}else T.add(r),t=!0}if(t&&!x&&A===0)queueMicrotask(D)}},B=(e,s=null)=>{let t=new Set;if(m(e)){let r,n=()=>{if(n._dirty){let i=p;p=n;try{let c=e();if(!Object.is(r,c))r=c,w(t,!0)}finally{p=i}n._dirty=!1}return w(t),r};if(n._isComputed=!0,n._subs=t,n._dirty=!0,n._deps=null,n._disposed=!1,n.stop=()=>{},_)g(n.stop);return n}if(s)try{e=JSON.parse(localStorage.getItem(s))??e}catch(r){}return(...r)=>{if(r.length){let n=m(r[0])?r[0](e):r[0];if(!Object.is(e,n)){if(e=n,s)localStorage.setItem(s,JSON.stringify(e));w(t,!0)}}return w(t),e}},V=(e)=>{if(!j(e))return e;let s=U.get(e);if(s)return s;let t=new Map,r=(n)=>{let i=t.get(n);if(!i)t.set(n,i=new Set);return i};return s=new Proxy(e,{get(n,i,c){if(typeof i!=="symbol")w(r(i));return V(Reflect.get(n,i,c))},set(n,i,c,o){let l=!Reflect.has(n,i),a=Reflect.get(n,i,o),d=Reflect.set(n,i,c,o);if(d&&!Object.is(a,c)){if(w(r(i),!0),l)w(r(L),!0)}return d},deleteProperty(n,i){let c=Reflect.deleteProperty(n,i);if(c)w(r(i),!0),w(r(L),!0);return c},ownKeys(n){return w(r(L)),Reflect.ownKeys(n)}}),U.set(e,s),s},O=(e,s)=>{if(s===void 0){let r=C(e);return r(),()=>v(r)}let t=C(()=>{let r=Array.isArray(e)?e.map((n)=>n()):e();z(()=>s(r))});return t(),()=>v(t)},P=(e)=>{if(e._cleanups)e._cleanups.forEach((s)=>s()),e._cleanups.clear();if(e._ownerEffect)v(e._ownerEffect);if(e.childNodes)e.childNodes.forEach(P)},G=/^\s*(javascript|data|vbscript):/i,J=(e)=>e==="src"||e==="href"||e.startsWith("on"),I=(e,s)=>{if(s==null||s===!1)return null;if(J(e)){let t=String(s);if(G.test(t))return console.warn(`[SigPro] Bloqueado protocolo peligroso en ${e}`),"#"}return s},R=(e,s={},t=[])=>{if(s instanceof Node||N(s)||!j(s))t=s,s={};if(m(e)){let c={_mounts:[],_cleanups:new Set},o=C(()=>{let f=e(s,{children:t,emit:(h,...u)=>s[`on${h[0].toUpperCase()}${h.slice(1)}`]?.(...u)});return o._result=f,f});o();let l=o._result;if(l==null)return null;let a=l instanceof Node||N(l)&&l.every((f)=>f instanceof Node)?l:E.createTextNode(String(l)),d=(f)=>{if(j(f)&&!f._isRuntime)f._mounts=o._mounts||[],f._cleanups=o._cleanups||new Set,f._ownerEffect=o};return N(a)?a.forEach(d):d(a),a}let r=/^(svg|path|circle|rect|line|poly(line|gon)|g|defs|text(path)?|tspan|use|symbol|image|marker|ellipse)$/i.test(e),n=r?E.createElementNS("http://www.w3.org/2000/svg",e):E.createElement(e);n._cleanups=new Set;for(let c in s){if(!s.hasOwnProperty(c))continue;let o=s[c];if(c==="ref"){m(o)?o(n):o.current=n;continue}if(r&&c.startsWith("xlink:")){val==null?n.removeAttributeNS("http://www.w3.org/1999/xlink",c.slice(6)):n.setAttributeNS("http://www.w3.org/1999/xlink",c.slice(6),val);continue}if(c.startsWith("on")){let l=c.slice(2).toLowerCase();n.addEventListener(l,o);let a=()=>n.removeEventListener(l,o);n._cleanups.add(a),g(a)}else if(m(o)){let l=C(()=>{let a=I(c,o());if(c==="class")n.className=a||"";else if(a==null)n.removeAttribute(c);else if(c in n&&!r)n[c]=a;else n.setAttribute(c,a===!0?"":a)});if(l(),n._cleanups.add(()=>v(l)),g(()=>v(l)),/^(INPUT|TEXTAREA|SELECT)$/.test(n.tagName)&&(c==="value"||c==="checked")){let a=c==="checked"?"change":"input";n.addEventListener(a,(d)=>o(d.target[c]))}}else{let l=I(c,o);if(l!=null)if(c in n&&!r)n[c]=l;else n.setAttribute(c,l===!0?"":l)}}let i=(c)=>{if(N(c))return c.forEach(i);if(m(c)){let o=E.createTextNode("");n.appendChild(o);let l=[],a=C(()=>{let d=c(),f=(N(d)?d:[d]).map($);l.forEach((u)=>{if(u._isRuntime)u.destroy();else P(u);if(u.parentNode)u.remove()});let h=o;for(let u=f.length-1;u>=0;u--){let y=f[u];if(y.parentNode!==h.parentNode)h.parentNode?.insertBefore(y,h);if(y._mounts)y._mounts.forEach((k)=>k());h=y}l=f});a(),n._cleanups.add(()=>v(a)),g(()=>v(a))}else{let o=$(c);if(n.appendChild(o),o._mounts)o._mounts.forEach((l)=>l())}};return i(t),n},S=(e)=>{let s=new Set,t=[],r=_,n=p,i=E.createElement("div");i.style.display="contents",i.setAttribute("role","presentation"),_={_cleanups:s,_mounts:t},p=null;let c=(o)=>{if(!o)return;if(o._isRuntime)s.add(o.destroy),i.appendChild(o.container);else if(N(o))o.forEach(c);else i.appendChild(o instanceof Node?o:E.createTextNode(String(o==null?"":o)))};try{c(e({onCleanup:(o)=>s.add(o)}))}finally{_=r,p=n}return t.forEach((o)=>o()),{_isRuntime:!0,container:i,destroy:()=>{s.forEach((o)=>o()),P(i),i.remove()}}},K=(e,s,t=null)=>{let r=E.createTextNode(""),n=R("div",{style:"display:contents"},[r]),i=null;return O(()=>!!(m(e)?e():e),(c)=>{if(i)i.destroy(),i=null;let o=c?s:t;if(o)i=S(()=>m(o)?o():o),n.insertBefore(i.container,r)}),g(()=>i?.destroy()),n},Q=(e,s,t)=>{let r=E.createTextNode(""),n=R("div",{style:"display:contents"},[r]),i=new Map;return O(()=>(m(e)?e():e)||[],(c)=>{let o=new Map,l=[],a=c||[];for(let f=0;f<a.length;f++){let h=a[f],u=t?t(h,f):h?.id??f,y=i.get(u);if(!y)y=S(()=>s(h,f));else i.delete(u);o.set(u,y),l.push(y)}i.forEach((f)=>f.destroy());let d=r;for(let f=l.length-1;f>=0;f--){let u=l[f].container;if(u.nextSibling!==d)n.insertBefore(u,d);d=u}i=o}),n},b=(e)=>{let s=()=>window.location.hash.slice(1)||"/",t=B(s()),r=()=>t(s());window.addEventListener("hashchange",r),g(()=>window.removeEventListener("hashchange",r));let n=R("div",{class:"router-hook"}),i=null;return O([t],()=>{let c=t(),o=e.find((l)=>{let a=l.path.split("/").filter(Boolean),d=c.split("/").filter(Boolean);return a.length===d.length&&a.every((f,h)=>f[0]===":"||f===d[h])})||e.find((l)=>l.path==="*");if(o){i?.destroy();let l={};o.path.split("/").filter(Boolean).forEach((a,d)=>{if(a[0]===":")l[a.slice(1)]=c.split("/").filter(Boolean)[d]}),b.params(l),i=S(()=>m(o.component)?o.component(l):o.component),n.replaceChildren(i.container)}}),n};b.params=B({});b.to=(e)=>window.location.hash=e.replace(/^#?\/?/,"#/");b.back=()=>window.history.back();b.path=()=>window.location.hash.replace(/^#/,"")||"/";var H=(e,s,{enter:t,leave:r}={})=>{let n=R("div",{style:"display:contents"}),i=null,c=(o,l)=>{let a=!1,d=()=>!a&&(a=!0,l());if(!o)return d();"transitionend animationend".split(" ").map((f)=>o.addEventListener(f,d,{once:!0})),setTimeout(d,500)};return O(e,(o)=>{if(o&&!i){let l=(i=S(s)).container.firstChild;if(n.appendChild(i.container),t&&l)l.classList.add(t),l.clientTop,l.classList.add(t+"-active"),c(l,()=>l.classList.remove(t,t+"-active"))}else if(!o&&i){let l=i.container.firstChild,a=()=>(i?.destroy(),i=null);r&&l?(l.classList.add(r),c(l,a)):a()}}),g(()=>i?.destroy()),n},X=(e,s)=>{let t=typeof s==="string"?E.querySelector(s):s;if(!t)return;if(M.has(t))M.get(t).destroy();let r=S(m(e)?e:()=>e);return t.replaceChildren(r.container),M.set(t,r),r},W=Object.freeze({$:B,$$:V,Watch:O,Tag:R,Render:S,If:K,For:Q,Router:b,Mount:X,onMount:q,onUnmount:g,Anim:H,Batch:F});if(typeof window<"u")Object.assign(window,W),"div span p h1 h2 h3 h4 h5 h6 br hr section article aside nav main header footer ul ol li a em strong pre code form label input textarea select button img svg".split(" ").forEach((e)=>window[e[0].toUpperCase()+e.slice(1)]=(s,t)=>W.Tag(e,s,t));export{g as onUnmount,q as onMount,O as Watch,R as Tag,b as Router,S as Render,X as Mount,K as If,Q as For,F as Batch,H as Anim,V as $$,B as $};
|