sigment 1.1.6 → 1.1.7

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/index.js CHANGED
@@ -1,11 +1,11 @@
1
- var I=Object.defineProperty;var c=(e,t)=>I(e,"name",{value:t,configurable:!0});var h={cleanHtml:B,cleanhtml:!0,setMaxCacheSize:U,maxCacheSize:10,setRoute:_,route:null},g={funcname:[],dataMap:new Map},T=null,x={},$=new Map,v=new Map,J=null,A=null,F=new Map,w={innerHTMLElements:["div","p","span","h1","h2","h3","h4","h5","h6","a","ul","ol","li","table","tr","td","th","thead","tbody","tfoot","form","label","button","section","article","header","footer","nav","aside","main","figure","figcaption","blockquote","cite","code","pre","em","strong","i","b","u","s","small","mark","time","abbr","q","dl","dt","dd","fieldset","legend","textarea","output","progress","meter","fragment","details","summary","dialog","menu","slot","template"],valueElements:["input","textarea","select","button","option","progress","meter"],srcElements:["img","script","iframe","audio","video","source","track","embed","frame","input"],hrefElements:["a","link","area","base"],voidElements:["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr","frame"]};Object.values(w).flat().forEach(e=>{globalThis[e]=(...t)=>O(e,...t)});var G=new Set(w.valueElements),oe=new Set(w.srcElements),re=new Set(w.hrefElements),V=new Set(w.voidElements);function ie(e,t){x[e]||(x[e]=K(t))}c(ie,"createGlobalSignal");function se(e){return x[e]}c(se,"getGlobalSignal");function z(e,t){g.dataMap.has(e)&&g.dataMap.delete(e),g.dataMap.set(e,t)}c(z,"addEntry");function S(e){k(S.name);let t=g.dataMap.get(e);return t?t.value:null}c(S,"gve");function le(e,t,n){let o;if(t instanceof HTMLElement?o=t.outerHTML:typeof t=="object"?o=JSON.stringify(t):o=t.toString(),o.length>4096){console.error("Cookie size exceeds 4KB limit. Data not stored.");return}document.cookie=e+"="+o+"; max-age="+n+" ; path=/ ;",setTimeout(()=>{document.cookie="testCookie=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;"},n*1e3)}c(le,"setCookie");function ce(e){let n=`; ${document.cookie}`.split(`; ${e}=`);if(n.length===2){let o=n.pop().split(";").shift();try{let s=JSON.parse(o);return typeof s=="object"&&s!==null&&"nodeType"in s&&s.nodeType===1,s}catch{return o}}return null}c(ce,"getCookie");function ae(e,t){let n;t instanceof HTMLElement?n=t.outerHTML:typeof t=="object"?n=JSON.stringify(t):n=t.toString(),localStorage.setItem(e,n)}c(ae,"setStorage");function fe(e){let t=localStorage.getItem(e);if(t!==null)try{let n=JSON.parse(t);return typeof n=="object"&&n!==null&&"nodeType"in n&&n.nodeType===1,n}catch{return t}}c(fe,"getStorage");function M(e,t=void 0){k(M.name),g.createInstance=M.name;let n="";t===void 0?n=e():n=e(t)}c(M,"createInstance");function H(e,t){k(H.name),g.rpc=H.name;let n={};for(let[o,s]of Object.entries(t))e[o]?n[o]=e[o].apply(null,s):(console.error(`Function ${o} not found!`),n[o]=null);return n}c(H,"rpc");function D(e,t=!1,n){k(D.name),g.gvec=D.name;let o=Object.keys(e),s=o[0],l=o[1],r=o[2];var a=e[s];a=a.name;var m=e[l];let d=e[l];var p=S(l)===null;if(p||t===!1){var y=""+l;g.dataMap.delete(y),M(m,e[r])}m=S(l);var i=S(s);if(i===null)throw new Error(` source id '${s} is not found in source component `);if(m===null)throw new Error(` target id '${l} is not found in target component `);if(i.replaceWith(m),n!==void 0)for(let b in d){let E=b.toString();if(typeof n=="object"){for(var u in n)if(E===u){var f=n[u];typeof f=="object"?d[b].apply(null,f):d[b].apply(null,[])}}else if(n.indexOf(",">-1)){let j=n.split(",");for(let L=0;L<j.length;L++)E===j[L]&&d[b].apply(null,[])}else E===n&&d[b].apply(null,[])}}c(D,"gvec");async function ue(e,t={}){let{passRestriction:n=[]}=t,o=window.location.pathname.replace(/^\/|\/$/g,"").toLowerCase(),s=e.replace(/^\/|\/$/g,"").toLowerCase();if(!new RegExp("^"+s.replace(/:[^\/]+/g,"[^/]+")+"$").test(o))return!1;let r=Array.isArray(n)?n:[n];for(let a of r)try{let m=typeof a=="function"?a():a;if(m instanceof Promise){if(!await m)return!1}else if(!m)return!1}catch(m){return console.error("Route check failed:",m),!1}return!0}c(ue,"Route");function de(e){return e==null||e===""}c(de,"IsEmpty");function W(e){let t=e.startsWith("/")?e:"/"+e;window.history.pushState({},"",t)}c(W,"Navigate");function U(e){h.maxCacheSize=e}c(U,"setMaxCacheSize");function B(e){h.cleanhtml=e}c(B,"cleanHtml");function _(e){h.route=e}c(_,"setRoute");async function me(e,t){let n;t==="/"?n=t:n=t.replace(/\//g,"").toLowerCase();let o=Object.keys(e).find(s=>s.toLowerCase()===n.toLowerCase());if(!o){let s=Object.keys(e).join(", ");throw new Error(`Unknown component: "${t}".
2
- Available components: ${s}
1
+ var Z=Object.defineProperty;var c=(e,t)=>Z(e,"name",{value:t,configurable:!0});var b={cleanHtml:N,cleanhtml:!0,setMaxCacheSize:X,maxCacheSize:10,setRoute:ee,route:null},E={funcname:[],dataMap:new Map},O=null,k={},M=new Map,x=new Map,_=new Map,K=null,A=null,F=new Map,S=null,V=window.location.href.replace(/^https?:\/\//,"").replace(/\/$/,""),f={innerHTMLElements:["div","p","span","h1","h2","h3","h4","h5","h6","a","ul","ol","li","table","tr","td","th","thead","tbody","tfoot","form","label","button","section","article","header","footer","nav","aside","main","figure","figcaption","blockquote","cite","code","pre","em","strong","i","b","u","s","small","mark","time","abbr","q","dl","dt","dd","fieldset","legend","textarea","output","progress","meter","fragment","details","summary","dialog","menu","slot","template"],valueElements:["input","textarea","select","button","option","progress","meter"],srcElements:["img","script","iframe","audio","video","source","track","embed","frame","input"],hrefElements:["a","link","area","base"],voidElements:["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr","frame"]};Object.values(f).flat().forEach(e=>{globalThis[e]=(...t)=>T(e,...t)});var H=new Set(f.valueElements),J=new Set(f.srcElements),U=new Set(f.hrefElements),P=new Set(f.voidElements);function fe(e,t){k[e]||(k[e]=le(t))}c(fe,"createGlobalSignal");function ae(e){return k[e]}c(ae,"getGlobalSignal");function B(e,t){E.dataMap.has(e)&&E.dataMap.delete(e),E.dataMap.set(e,t)}c(B,"addEntry");function L(e){C(L.name);let t=E.dataMap.get(e);return t?t.value:null}c(L,"gve");function de(e,t,n){let l;if(t instanceof HTMLElement?l=t.outerHTML:typeof t=="object"?l=JSON.stringify(t):l=t.toString(),l.length>4096){console.error("Cookie size exceeds 4KB limit. Data not stored.");return}document.cookie=e+"="+l+"; max-age="+n+" ; path=/ ;",setTimeout(()=>{document.cookie="testCookie=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;"},n*1e3)}c(de,"setCookie");function pe(e){let n=`; ${document.cookie}`.split(`; ${e}=`);if(n.length===2){let l=n.pop().split(";").shift();try{let o=JSON.parse(l);return typeof o=="object"&&o!==null&&"nodeType"in o&&o.nodeType===1,o}catch{return l}}return null}c(pe,"getCookie");function he(e,t){let n;t instanceof HTMLElement?n=t.outerHTML:typeof t=="object"?n=JSON.stringify(t):n=t.toString(),localStorage.setItem(e,n)}c(he,"setStorage");function me(e){let t=localStorage.getItem(e);if(t!==null)try{let n=JSON.parse(t);return typeof n=="object"&&n!==null&&"nodeType"in n&&n.nodeType===1,n}catch{return t}}c(me,"getStorage");function R(e,t=void 0){C(R.name),E.createInstance=R.name;let n="";t===void 0?n=e():n=e(t)}c(R,"createInstance");function G(e,t){C(G.name),E.rpc=G.name;let n={};for(let[l,o]of Object.entries(t))e[l]?n[l]=e[l].apply(null,o):(console.error(`Function ${l} not found!`),n[l]=null);return n}c(G,"rpc");function W(e,t=!1,n){C(W.name),E.gvec=W.name;let l=Object.keys(e),o=l[0],s=l[1],r=l[2];var d=e[o];d=d.name;var a=e[s];let m=e[s];var p=L(s)===null;if(p||t===!1){var g=""+s;E.dataMap.delete(g),R(a,e[r])}a=L(s);var y=L(o);if(y===null)throw new Error(` source id '${o} is not found in source component `);if(a===null)throw new Error(` target id '${s} is not found in target component `);if(y.replaceWith(a),n!==void 0)for(let h in m){let w=h.toString();if(typeof n=="object"){for(var i in n)if(w===i){var u=n[i];typeof u=="object"?m[h].apply(null,u):m[h].apply(null,[])}}else if(n.indexOf(",">-1)){let D=n.split(",");for(let $=0;$<D.length;$++)w===D[$]&&m[h].apply(null,[])}else w===n&&m[h].apply(null,[])}}c(W,"gvec");async function ye(e,t={}){let{passRestriction:n=[]}=t,l=window.location.pathname.replace(/^\/|\/$/g,"").toLowerCase(),o=e.replace(/^\/|\/$/g,"").toLowerCase();if(!new RegExp("^"+o.replace(/:[^\/]+/g,"[^/]+")+"$").test(l))return!1;let r=Array.isArray(n)?n:[n];for(let d of r)try{let a=typeof d=="function"?d():d;if(a instanceof Promise){if(!await a)return!1}else if(!a)return!1}catch(a){return console.error("Route check failed:",a),!1}return!0}c(ye,"Route");function ge(e){return e==null||e===""}c(ge,"IsEmpty");function Q(e){let t=e.startsWith("/")?e:"/"+e;window.history.pushState({},"",t)}c(Q,"Navigate");function X(e){b.maxCacheSize=e}c(X,"setMaxCacheSize");function N(e){b.cleanhtml=e}c(N,"cleanHtml");function ee(e){b.route=e}c(ee,"setRoute");async function be(e,t){let n;t==="/"?n=t:n=t.replace(/\//g,"").toLowerCase();let l=Object.keys(e).find(o=>o.toLowerCase()===n.toLowerCase());if(!l){let o=Object.keys(e).join(", ");throw new Error(`Unknown component: "${t}".
2
+ Available components: ${o}
3
3
 
4
4
  To add this component:
5
5
 
6
6
  const loadAsyncComponents = {
7
7
  ...existingComponents,
8
8
  "${t}": () => import('./${t}.js')
9
- };`)}if(v.has(o))return v.get(o);try{let l=(await e[o]()).default;return v.set(o,l),l}catch(s){throw new Error(`Failed to load component "${o}": ${s.message}`)}}c(me,"loadFunc");async function pe(e,t,n,o){let s;typeof t=="boolean"||typeof t=="string"?(n=t,t=h.route):t===void 0&&(t=h.route,n=!1),W(e);let{componentKey:l,params:r}=q(t),a=Object.keys(t);if(typeof n=="string")l=n,s=!!o;else if(typeof n=="boolean"){if(a.length===1)l=a[0];else if(a.includes(e))l=e;else throw new Error(`Ambiguous component map: multiple components exist and no matching key for path '${e}' found. Provide component key explicitly.`);s=n}else{if(a.length===1)l=a[0];else if(a.includes(e))l=e;else throw new Error(`Ambiguous component map: multiple components exist and no matching key for path '${e}' found. Provide component key explicitly.`);s=!1}let m=await Y(t,l,r,null,!1),d=F.get(e);(!d||!s)&&(typeof m=="function"?(d=m(),F.set(e,d)):d=m),A&&A.isConnected?A.replaceWith(d):document.body.appendChild(d),A=d,J=e}c(pe,"NavigateTo");function he(e){if(e){let t=e.toLowerCase(),n=!1;for(let o of v.keys())o.toLowerCase()===t&&(v.delete(o),n=!0);return n}else return v.clear(),!0}c(he,"clearComponentCache");function q(e){var a,m;let n=window.location.pathname.split("/").filter(Boolean),o=n[0]||"home",s={},l=(m=(a=e[o])==null?void 0:a.urlParam)==null?void 0:m.split("/");return l&&l.length&&l.forEach((d,p)=>{d=d.replace(/[{}]/g,""),n[p+1]&&(s[d]=n[p+1])}),new URL(window.location.href).searchParams.forEach((d,p)=>{s[p]=d}),{componentName:o,params:s}}c(q,"parsePath");function C(e){return new DOMParser().parseFromString(e,"text/html").body.firstChild}c(C,"parseHTML");async function Y(e,t,n=null,o=null,s=!0){let l=e[t.toLowerCase()];if(l||(typeof e.fallback=="string"?l=e[e.fallback]:l=e.fallback),!l)return C("<h1>404 - Component not found</h1>");let{loader:r,guard:a,cacheExpiration:m=null,...d}=l;if(o===null&&typeof l.logic=="function"&&(o=l.logic),typeof a=="function"&&!await a(n))return C("<h1>403 - Forbidden</h1><p>You do not have access to this page.</p>");for(let p in d){let y=d[p];if(typeof y=="function")try{await y()}catch(i){console.error(i)}}try{let p=Date.now(),y=v.get(t);y&&m!==null&&p-y.cachedAt>m&&(v.delete(t),y=null);let i;if(y)i=y.component,v.set(t,{component:i,cachedAt:p});else{if(i=(await r()).default,v.size>=h.maxCacheSize){let E=v.keys().next().value;v.delete(E)}v.set(t,{component:i,cachedAt:p})}if(typeof i!="function")return C("<h1>Invalid component</h1>");if(!s)return i;let u;Array.isArray(n)?u=i(...n):typeof n=="object"&&n!==null?u=i(n):u=i();let f="/";try{f=window.location.pathname.slice(1)+window.location.hash,f=f.endsWith("/")&&f!=="/"?f.slice(0,-1):f,f===""&&(f="/")}catch{f=t}return F.set(f,u),A=u,u}catch(p){return console.error(p),C("<h1>Error loading component</h1>")}}c(Y,"loadRunFunc");function P(e=""){var s,l;k(P.name),g.buildRoadMap=P.name;var t="";let n=(s=new Error().stack)==null?void 0:s.toString();navigator.userAgent.toLowerCase().indexOf("firefox")>0?n=n.split("@"):n=n.split(`
10
- `);for(let r=0;r<n.length;r++){var o="";if(navigator.userAgent.indexOf("Firefox")>0){let a=n[r].lastIndexOf(`
11
- `);if(a===-1)continue;o=n[r].slice(a+1),o===""?(a=n[r].lastIndexOf("/")+1,a>-1&&(o=n[r].substr(a),o=o.substr(0,o.indexOf(".")))):o.indexOf("/")>-1&&(o=o.substr(0,o.indexOf("/")))}else o=(l=n[r])==null?void 0:l.trim().split(" ")[1];if(!g.funcname.includes(o)&&!(o===void 0||o==="")&&!(o.indexOf("http://")>-1||o.indexOf("https://")>-1)){if(g.gvec!==void 0&&o.indexOf(g.gvec)>-1)break;t.indexOf("|"+o)>-1||(t+="|"+o.replace(".","|"))}}return e+t}c(P,"buildRoadMap");function k(e){!g.funcname.includes(e)&&g.funcname.push(e)}c(k,"setFuncName");function K(e){let t=e,n=new Set;function o(){return T&&n.add(T),t}c(o,"get");function s(l,r=!1){(r||t!==l)&&(t=l,n.forEach(a=>a()))}return c(s,"set"),[o,s]}c(K,"createSignal");function R(e){function t(){T=t,e(),T=null}c(t,"wrapped"),t()}c(R,"createEffect");function Q(e){e=e.toLowerCase(),w.innerHTMLElements.includes(e)||(w.innerHTMLElements.push(e),globalThis[e]=(...t)=>O(e,...t))}c(Q,"createTypeElement");function X(e){e=e.toLowerCase(),w.innerHTMLElements.includes(e)||(w.innerHTMLElements.push(e),globalThis[e]=(...t)=>O(e,...t))}c(X,"createSigment");function ye(e){X(e)}c(ye,"addSigment");function ge(e,...t){if(Q(e),t.length!==0)return globalThis[e](...t)}c(ge,"createElement");function Z(e){let t=document.createTextNode("");return R(()=>{if(typeof x!="object"||x===null){t.textContent=e;return}let n=e.replace(/{{(.*?)}}/g,(o,s)=>{let l=s.trim();if(x.hasOwnProperty(l)){let r=x[l];if(r&&typeof r[0]=="function")return r[0]()??""}return""});t.textContent=n}),t}c(Z,"interpolateReactiveText");function be(e,t=5e3,n={}){let o=JSON.stringify([e,n,t]);if(!$.has(o)){let s=te(async()=>{let l=await fetch(e,n);if(!l.ok)throw new Error(`Fetch failed: ${l.status}`);return l.json()},t);$.set(o,s)}return $.get(o)()}c(be,"fetchCache");function N(e){if(Array.isArray(e))return e.map(N);if(e&&typeof e=="object"){let t={};return Object.keys(e).sort().forEach(n=>{t[n]=N(e[n])}),t}return e}c(N,"sortObjectDeep");function ee(e){if(e&&typeof e=="object"&&!Array.isArray(e)){let t={};return Object.keys(e).sort().forEach(n=>{t[n]=e[n]}),t}return e}c(ee,"sortObjectShallow");function te(e,t=5e3,n={}){let o=new Map,s=c((...l)=>{let{deepSort:r}=n,a;r===!0?a=l.map(i=>i&&typeof i=="object"?N(i):i):r===!1?a=l.map(i=>i&&typeof i=="object"?ee(i):i):a=l;let m=JSON.stringify(a),d=Date.now(),p=o.get(m);if(p&&d-p.timestamp<t)return p.value;let y=e(...l);return o.set(m,{value:y,timestamp:d}),y instanceof Promise&&y.catch(()=>o.delete(m)),y},"wrapped");return s.clear=()=>o.clear(),s}c(te,"memoizeFunc");function O(e,...t){let n={},o=[];k(O.name);var s="";s=P();var l=s.split("|");if(l.includes(g.rpc))return;t[0]&&typeof t[0]=="object"&&!Array.isArray(t[0])&&!(t[0]instanceof Node)?(n=t[0],o=t.slice(1)):o=t;let r=null,a=e.toLowerCase()==="fragment";a?r=document.createDocumentFragment():r=document.createElement(e);let m=V.has(e),d=G.has(e),p=e==="input"||e==="option",y=e==="option";if(!a)for(let i in n){let u=n[i];i.startsWith("on")&&typeof u=="function"?r.addEventListener(i.slice(2).toLowerCase(),u):typeof u=="function"&&i!=="children"?R(()=>{let f=u();f==null||f===!1?(r.removeAttribute(i),i==="value"&&d&&(r.value="",h.cleanhtml||r.removeAttribute("value")),i==="checked"&&p&&(r.checked=!1,h.cleanhtml||r.removeAttribute("checked")),i==="selected"&&y&&(r.selected=!1,h.cleanhtml||r.removeAttribute("selected")),i==="id"&&(r.iid="",h.cleanhtml||r.removeAttribute("id"))):i==="id"?(r.iid=f,h.cleanhtml?r.setAttribute("id",f):r.removeAttribute("id"),z(f,{name:f,caller:f+s,value:r})):i==="value"&&d?(r.value=f,h.cleanhtml?r.setAttribute("value",f):r.removeAttribute("value")):i==="checked"&&p?(r.checked=f,h.cleanhtml&&f?r.setAttribute("checked",""):r.removeAttribute("checked")):i==="selected"&&y?(r.selected=f,h.cleanhtml&&f?r.setAttribute("selected",""):r.removeAttribute("selected")):r.setAttribute(i,f)}):u!=null&&u!==!1&&(i==="id"?(r.iid=u,h.cleanhtml?r.setAttribute("id",u):r.removeAttribute("id"),z(u,{name:u,caller:u+s,value:r})):i==="value"&&d?(r.value=u,h.cleanhtml?r.setAttribute("value",u):r.removeAttribute("value")):i==="checked"&&p?(r.checked=u,h.cleanhtml?r.setAttribute("checked",""):r.removeAttribute("checked")):i==="selected"&&y?(r.selected=u,h.cleanhtml?r.setAttribute("selected",""):r.removeAttribute("selected")):r.setAttribute(i,u))}return m?o.length===1&&(typeof o[0]=="string"||typeof o[0]=="number")?d&&(r.value=o[0],h.cleanhtml?r.setAttribute("value",o[0]):r.removeAttribute("value")):o.length>0&&console.warn(`Void element <${e}> should not have children.`):o.flat().forEach(i=>{if(typeof i=="function"){let u=document.createTextNode("");r.appendChild(u),R(()=>{let f=i();if(f instanceof Node){let b=u.parentNode;if(!b)return;b.nodeType===Node.DOCUMENT_FRAGMENT_NODE?b.replaceChildren(f):b.replaceChild(f,u),u=f}else{let b=f==null?"":String(f);u.textContent!==b&&(u.textContent=b)}})}else if(typeof i=="string"&&i.includes("{{")&&!i.includes("function"))r.appendChild(Z(i));else if(typeof i=="string"||typeof i=="number"){if(i.includes("function get(")||i.includes("function (")||i.includes("[native code]"))throw new Error("Detected reactive getter function used inside a template string. Use a function instead like: div(() => `Your text is: ${someState()}`)");r.appendChild(document.createTextNode(i))}else(i instanceof DocumentFragment||i instanceof Node)&&r.appendChild(i)}),r}c(O,"h");export{de as IsEmpty,h as MyApp,W as Navigate,pe as NavigateTo,ue as Route,ye as addSigment,he as clearComponentCache,R as createEffect,ge as createElement,ie as createGlobalSignal,X as createSigment,K as createSignal,be as fetchCache,ce as getCookie,se as getGlobalSignal,fe as getStorage,S as getVirtualElementById,ie as globalSignal,S as gve,D as gvec,O as h,me as loadFunc,Y as loadRunFunc,te as memoizeFunc,q as parsePath,H as rpc,le as setCookie,ae as setStorage,K as signal,se as useGlobalSignal};
9
+ };`)}if(x.has(l))return x.get(l);try{let s=(await e[l]()).default;return x.set(l,s),s}catch(o){throw new Error(`Failed to load component "${l}": ${o.message}`)}}c(be,"loadFunc");async function Ee(e,t,n,l){debugger;let o=window.location.host+"/"+e;if(V===o)return;V=o;let s;typeof t=="boolean"||typeof t=="string"?(n=t,t=b.route):t===void 0&&(t=b.route,n=!1),Q(e);let{componentKey:r,params:d}=te(t),a=Object.keys(t);if(typeof n=="string")r=n,s=!!l;else if(typeof n=="boolean"){if(a.length===1)r=a[0];else if(a.includes(e))r=e;else throw new Error(`Ambiguous component map: multiple components exist and no matching key for path '${e}' found. Provide component key explicitly.`);s=n}else{if(a.length===1)r=a[0];else if(a.includes(e))r=e;else throw new Error(`Ambiguous component map: multiple components exist and no matching key for path '${e}' found. Provide component key explicitly.`);s=!1}let m=await ne(t,r,d,null,!1),p=F.get(e);if((!p||!s)&&(typeof m=="function"?(p=m(),F.set(e,p)):p=m),A&&A.isConnected){var g=A.contains(p);g||A.replaceWith(p)}else document.body.appendChild(p);A=p,K=e}c(Ee,"NavigateTo");function we(e=S,t){let n=typeof e=="string"?document.getElementById(e):e;n.contains(t)||n.replaceChildren(t)}c(we,"updateNodeIfNeeded");function xe(e,t){if(S=typeof e=="string"?document.getElementById(e):e,!S)throw new Error("Mount target not found: "+e);S.replaceChildren(t)}c(xe,"mount");function ke(e){if(e){let t=e.toLowerCase(),n=!1;for(let l of x.keys())l.toLowerCase()===t&&(x.delete(l),n=!0);return n}else return x.clear(),!0}c(ke,"clearComponentCache");function te(e){var d,a;let n=window.location.pathname.split("/").filter(Boolean),l=n[0]||"home",o={},s=(a=(d=e[l])==null?void 0:d.urlParam)==null?void 0:a.split("/");return s&&s.length&&s.forEach((m,p)=>{m=m.replace(/[{}]/g,""),n[p+1]&&(o[m]=n[p+1])}),new URL(window.location.href).searchParams.forEach((m,p)=>{o[p]=m}),{componentName:l,params:o}}c(te,"parsePath");function v(e){return new DOMParser().parseFromString(e,"text/html").body.firstChild}c(v,"parseHTML");async function ne(e,t,n=null,l=null,o=!0){let s=e[t.toLowerCase()];if(s||(typeof e.fallback=="string"?s=e[e.fallback]:s=e.fallback),!s)return v("<h1>404 - Component not found</h1>");let{loader:r,guard:d,cacheExpiration:a=null,...m}=s;if(l===null&&typeof s.logic=="function"&&(l=s.logic),typeof d=="function"&&!await d(n))return v("<h1>403 - Forbidden</h1><p>You do not have access to this page.</p>");for(let p in m){let g=m[p];if(typeof g=="function")try{await g()}catch(y){console.error(y)}}try{let p=Date.now(),g=x.get(t);g&&a!==null&&p-g.cachedAt>a&&(x.delete(t),g=null);let y;if(g)y=g.component,x.set(t,{component:y,cachedAt:p});else{if(y=(await r()).default,x.size>=b.maxCacheSize){let w=x.keys().next().value;x.delete(w)}x.set(t,{component:y,cachedAt:p})}if(typeof y!="function")return v("<h1>Invalid component</h1>");if(!o)return y;let i;Array.isArray(n)?i=y(...n):typeof n=="object"&&n!==null?i=y(n):i=y();let u="/";try{u=window.location.pathname.slice(1)+window.location.hash,u=u.endsWith("/")&&u!=="/"?u.slice(0,-1):u,u===""&&(u="/")}catch{u=t}return F.set(u,i),A=i,i}catch(p){return console.error(p),v("<h1>Error loading component</h1>")}}c(ne,"loadRunFunc");function z(e=""){var o,s;C(z.name),E.buildRoadMap=z.name;var t="";let n=(o=new Error().stack)==null?void 0:o.toString();navigator.userAgent.toLowerCase().indexOf("firefox")>0?n=n.split("@"):n=n.split(`
10
+ `);for(let r=0;r<n.length;r++){var l="";if(navigator.userAgent.indexOf("Firefox")>0){let d=n[r].lastIndexOf(`
11
+ `);if(d===-1)continue;l=n[r].slice(d+1),l===""?(d=n[r].lastIndexOf("/")+1,d>-1&&(l=n[r].substr(d),l=l.substr(0,l.indexOf(".")))):l.indexOf("/")>-1&&(l=l.substr(0,l.indexOf("/")))}else l=(s=n[r])==null?void 0:s.trim().split(" ")[1];if(!E.funcname.includes(l)&&!(l===void 0||l==="")&&!(l.indexOf("http://")>-1||l.indexOf("https://")>-1)){if(E.gvec!==void 0&&l.indexOf(E.gvec)>-1)break;t.indexOf("|"+l)>-1||(t+="|"+l.replace(".","|"))}}return e+t}c(z,"buildRoadMap");function C(e){!E.funcname.includes(e)&&E.funcname.push(e)}c(C,"setFuncName");function le(e){let t=e,n=new Set;function l(){return O&&n.add(O),t}c(l,"get");function o(s,r=!1){(r||t!==s)&&(t=s,n.forEach(d=>d()))}return c(o,"set"),[l,o]}c(le,"createSignal");function j(e){function t(){O=t,e(),O=null}c(t,"wrapped"),t()}c(j,"createEffect");function re(e){e=e.toLowerCase(),f.innerHTMLElements.includes(e)||(f.innerHTMLElements.push(e),globalThis[e]=(...t)=>T(e,...t))}c(re,"createTypeElement");function q(e){return e.replace(/-+/g,"-").replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}c(q,"dashToCamel");function Ae(e,t=null){Y(e,t)}c(Ae,"createSigment");function Ce(e,t=null){Y(e,t)}c(Ce,"addSigment");function ve(e,...t){if(re(e),t.length!==0)return globalThis[e](...t)}c(ve,"createElement");function ie(e){let t=document.createTextNode("");return j(()=>{if(typeof k!="object"||k===null){t.nodeValue=e;return}let n=e.replace(/{{(.*?)}}/g,(l,o)=>{let s=o.trim();if(k.hasOwnProperty(s)){let r=k[s];if(r&&typeof r[0]=="function")return r[0]()??""}return""});t.nodeValue=n}),t}c(ie,"interpolateReactiveText");function Se(e,t=5e3,n={}){let l=JSON.stringify([e,n,t]);if(!M.has(l)){let o=se(async()=>{let s=await fetch(e,n);if(!s.ok)throw new Error(`Fetch failed: ${s.status}`);return s.json()},t);M.set(l,o)}return M.get(l)()}c(Se,"fetchCache");function I(e){if(Array.isArray(e))return e.map(I);if(e&&typeof e=="object"){let t={};return Object.keys(e).sort().forEach(n=>{t[n]=I(e[n])}),t}return e}c(I,"sortObjectDeep");function oe(e){if(e&&typeof e=="object"&&!Array.isArray(e)){let t={};return Object.keys(e).sort().forEach(n=>{t[n]=e[n]}),t}return e}c(oe,"sortObjectShallow");function se(e,t=null,n={}){debugger;let l=new Map,o=c((...s)=>{let{deepSort:r}=n,d;r===!0?d=s.map(i=>i&&typeof i=="object"?I(i):i):r===!1?d=s.map(i=>i&&typeof i=="object"?oe(i):i):d=s;let a=JSON.stringify(d),m=Date.now();a.length===2&&(a=e.name);let g=l.get(a);if(g&&(t===null||m-g.timestamp<t))return g.value;let y=e(...s);return l.set(a,{value:y,timestamp:m}),y instanceof Promise&&y.catch(()=>l.delete(a)),y},"wrapped");return o.clear=()=>l.clear(),o}c(se,"memoizeFunc");function T(e,...t){let n={},l=[];C(T.name);var o="";o=z();var s=o.split("|");if(s.includes(E.rpc))return;t[0]&&typeof t[0]=="object"&&!Array.isArray(t[0])&&!(t[0]instanceof Node)?(n=t[0],l=t.slice(1)):l=t;let r=null,d=e.toLowerCase()==="fragment";if(d)r=document.createDocumentFragment();else{var a;let i=_.get(e);i&&(a=i.tagName,i.nativeTag!==null&&(a=i.nativeTag)),a!==void 0&&(e=a),r=document.createElement(e)}let m=P.has(e),p=H.has(q(e)),g=e==="input"||e==="option",y=e==="option";if(!d)for(let i in n){let u=n[i];i.startsWith("on")&&typeof u=="function"?r.addEventListener(i.slice(2).toLowerCase(),u):typeof u=="function"&&i!=="children"?j(()=>{let h=u();h==null||h===!1?(r.removeAttribute(i),i==="value"&&p&&(r.value="",b.cleanhtml||r.removeAttribute("value")),i==="checked"&&g&&(r.checked=!1,b.cleanhtml||r.removeAttribute("checked")),i==="selected"&&y&&(r.selected=!1,b.cleanhtml||r.removeAttribute("selected")),i==="id"&&(r.iid="",b.cleanhtml||r.removeAttribute("id"))):i==="id"?(r.iid=h,b.cleanhtml?r.setAttribute("id",h):r.removeAttribute("id"),B(h,{name:h,caller:h+o,value:r})):i==="value"&&p?(r.value=h,b.cleanhtml?r.setAttribute("value",h):r.removeAttribute("value")):i==="checked"&&g?(r.checked=h,b.cleanhtml&&h?r.setAttribute("checked",""):r.removeAttribute("checked")):i==="selected"&&y?(r.selected=h,b.cleanhtml&&h?r.setAttribute("selected",""):r.removeAttribute("selected")):r.setAttribute(i,h)}):u!=null&&u!==!1&&(i==="id"?(r.iid=u,b.cleanhtml?r.setAttribute("id",u):r.removeAttribute("id"),B(u,{name:u,caller:u+o,value:r})):i==="value"&&p?(r.value=u,b.cleanhtml?r.setAttribute("value",u):r.removeAttribute("value")):i==="checked"&&g?(r.checked=u,b.cleanhtml?r.setAttribute("checked",""):r.removeAttribute("checked")):i==="selected"&&y?(r.selected=u,b.cleanhtml?r.setAttribute("selected",""):r.removeAttribute("selected")):r.setAttribute(i,u))}return m?l.length===1&&(typeof l[0]=="string"||typeof l[0]=="number")?p&&(r.value=l[0],b.cleanhtml?r.setAttribute("value",l[0]):r.removeAttribute("value")):l.length>0&&console.warn(`Void element <${e}> should not have children.`):l.flat().forEach(i=>{if(typeof i=="function"){let u=document.createTextNode("");r.appendChild(u),j(()=>{let h=i();if(h instanceof Node){let w=u.parentNode;if(!w)return;w.nodeType===Node.DOCUMENT_FRAGMENT_NODE?w.replaceChildren(h):w.replaceChild(h,u),u=h}else{let w=h==null?"":String(h);u.nodeValue!==w&&(u.nodeValue=w)}})}else if(typeof i=="string"&&i.includes("{{")&&!i.includes("function"))r.appendChild(ie(i));else if(typeof i=="string"||typeof i=="number"){if(i.includes("function get(")||i.includes("function (")||i.includes("[native code]"))throw new Error("Detected reactive getter function used inside a template string. Use a function instead like: div(() => `Your text is: ${someState()}`)");r.appendChild(document.createTextNode(i))}else(i instanceof DocumentFragment||i instanceof Node)&&r.appendChild(i)}),r}c(T,"h");function ce(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/-+/g,"-").toLowerCase()}c(ce,"camelToDash");function Y(e,t=null){if(f.innerHTMLElements.includes(e)||f.valueElements.includes(e)||f.srcElements.includes(e)||f.hrefElements.includes(e)||f.voidElements.includes(e))return;let l=/[A-Z]/.test(e)?ce(e):e.toLowerCase();l.includes("-")||(l="s-"+l),e.includes("-")&&(l=e,e=q(e)),_.set(e,{tagName:l,nativeTag:t}),!f.innerHTMLElements.includes(e)&&t===null?f.innerHTMLElements.push(e):!f.innerHTMLElements.includes(e)&&t!==null&&(f.innerHTMLElements.includes(t)||f.innerHTMLElements.push(e)),!f.valueElements.includes(e)&&t===null?(f.valueElements.push(e),H.add(e)):!f.valueElements.includes(e)&&t!==null&&(f.valueElements.includes(t)||(f.valueElements.push(e),H.add(e))),!f.srcElements.includes(e)&&t===null?(f.srcElements.push(e),J.add(e)):!f.srcElements.includes(e)&&t!==null&&(f.srcElements.includes(t)||(f.srcElements.push(e),J.add(e))),!f.hrefElements.includes(e)&&t===null?(f.hrefElements.push(e),U.add(e)):!f.hrefElements.includes(e)&&t!==null&&(f.hrefElements.includes(t)||(f.hrefElements.push(e),U.add(e))),!f.voidElements.includes(e)&&t===null?(f.voidElements.push(e),P.add(e)):!f.voidElements.includes(e)&&t!==null&&(f.voidElements.includes(t)||(f.voidElements.push(e),P.add(e))),globalThis[e]=(...o)=>T(e,...o)}c(Y,"defineElement");export{ge as IsEmpty,b as MyApp,Q as Navigate,Ee as NavigateTo,ye as Route,Ce as addSigment,ke as clearComponentCache,j as createEffect,ve as createElement,fe as createGlobalSignal,Ae as createSigment,le as createSignal,Se as fetchCache,pe as getCookie,ae as getGlobalSignal,me as getStorage,L as getVirtualElementById,fe as globalSignal,L as gve,W as gvec,T as h,be as loadFunc,ne as loadRunFunc,se as memoizeFunc,xe as mount,te as parsePath,G as rpc,de as setCookie,he as setStorage,le as signal,we as updateNodeIfNeeded,ae as useGlobalSignal};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sigment",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "A lightweight reactive JavaScript framework built with signals and vanilla JS — no virtual DOM, no JSX, no transpilation.",
5
5
  "main": "./dist/index.js",
6
6
  "repository": {
package/types/index.d.ts CHANGED
@@ -46,17 +46,28 @@ export function NavigateTo(path: string, map: ComponentMap, key: string, statefu
46
46
  */
47
47
  export declare function createEffect(fn: () => void): void;
48
48
 
49
+
50
+
49
51
  /**
50
- * Creates an HTML element of the given tag name.
51
- * Returns void.
52
+ * Adds a sigment with an optional native tag.
53
+ * @param n - The segment identifier as a string.
54
+ * @param nativeTag - An optional native tag as a string (defaults to null).
52
55
  */
53
- export declare function createSigment(name: string): void;
56
+ export function createSigment(
57
+ n: string,
58
+ nativeTag?: string | null
59
+ ): void;
60
+
54
61
 
55
62
  /**
56
- * Creates an HTML element of the given tag name.
57
- * Returns void.
63
+ * Adds a sigment with an optional native tag.
64
+ * @param n - The segment identifier as a string.
65
+ * @param nativeTag - An optional native tag as a string (defaults to null).
58
66
  */
59
- export declare function addSigment(name: string): void;
67
+ export function addSigment(
68
+ n: string,
69
+ nativeTag?: string | null
70
+ ): void;
60
71
 
61
72
  /**
62
73
  * Fetches a URL with caching and TTL, returning parsed JSON.
@@ -526,6 +537,34 @@ declare global {
526
537
 
527
538
  }
528
539
 
540
+ /**
541
+ * Mounts a node to a target element in the DOM.
542
+ * @param selector - A string (element ID) or a DOM element to mount to.
543
+ * @param node - A DOM Node to insert as the sole child of the target.
544
+ * @throws Will throw an error if the target is not found.
545
+ */
546
+ export function mount(
547
+ selector: string | HTMLElement,
548
+ node: Node
549
+ ): void;
550
+
551
+ /**
552
+ * Updates the DOM element matching the selector with the given node,
553
+ * only if needed.
554
+ * @param target - A CSS selector string for the target element.
555
+ * @param node - The new DOM Node to compare or replace.
556
+ */
557
+ export function updateNodeIfNeeded(
558
+ target: string,
559
+ node: Node
560
+ ): void;
561
+
562
+
563
+ declare module '*.global.css' {
564
+ const content: string;
565
+ export default content;
566
+ }
567
+
529
568
 
530
569
  export function createElement(tagName: string, ...args: (string | HTMLElement)[]): HTMLElement;
531
570