sigment 1.0.5 → 1.0.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/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # sigment
2
2
 
3
- **Sigment** – A lightweight, fine-grained reactive JavaScript framework built on signals and vanilla JS.
4
- No JSX. No transpilation. Just fast, native code.
3
+ **Sigment** – A lightweight reactive JavaScript framework built with signals and vanilla JS.
5
4
 
6
5
  ## 🚀 Installation
7
6
 
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var D=Object.defineProperty;var c=(e,t)=>D(e,"name",{value:t,configurable:!0});var y={cleanHtml:K,cleanhtml:!0,setMaxCacheSize:G,maxCacheSize:10},b={funcname:[],dataMap:new Map},C=null,w={},M=new Map,v=new Map,x={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(x).flat().forEach(e=>{globalThis[e]=(...t)=>S(e,...t)});var P=new Set(x.valueElements),Q=new Set(x.srcElements),X=new Set(x.hrefElements),I=new Set(x.voidElements);function Z(e,t){w[e]||(w[e]=V(t))}c(Z,"createGlobalSignal");function J(e){return w[e]}c(J,"getGlobalSignal");var ee=J;function te(e){k(e)}c(te,"getVirtualElementById");function R(e,t){b.dataMap.has(e)&&b.dataMap.delete(e),b.dataMap.set(e,t)}c(R,"addEntry");function k(e){A(k.name);let t=b.dataMap.get(e);return t?t.value:null}c(k,"gve");function ne(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(ne,"setCookie");function oe(e){let n=`; ${document.cookie}`.split(`; ${e}=`);if(n.length===2){let o=n.pop().split(";").shift();try{let i=JSON.parse(o);return typeof i=="object"&&i!==null&&"nodeType"in i&&i.nodeType===1,i}catch{return o}}return null}c(oe,"getCookie");function re(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(re,"setStorage");function ie(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(ie,"getStorage");function L(e,t=void 0){A(L.name),b.createInstance=L.name;let n="";t===void 0?n=e():n=e(t)}c(L,"createInstance");function z(e,t){A(z.name),b.rpc=z.name;let n={};for(let[o,i]of Object.entries(t))e[o]?n[o]=e[o].apply(null,i):(console.error(`Function ${o} not found!`),n[o]=null);return n}c(z,"rpc");function H(e,t=!1,n){A(H.name),b.gvec=H.name;let o=Object.keys(e),i=o[0],l=o[1],r=o[2];var a=e[i];a=a.name;var p=e[l];let f=e[l];var h=k(l)===null;if(h||t===!1){var m=""+l;b.dataMap.delete(m),L(p,e[r])}p=k(l);var s=k(i);if(s===null)throw new Error(` source id '${i} is not found in source component `);if(p===null)throw new Error(` target id '${l} is not found in target component `);if(s.replaceWith(p),n!==void 0)for(let g in f){let O=g.toString();if(typeof n=="object"){for(var u in n)if(O===u){var d=n[u];typeof d=="object"?f[g].apply(null,d):f[g].apply(null,[])}}else if(n.indexOf(",">-1)){let j=n.split(",");for(let T=0;T<j.length;T++)O===j[T]&&f[g].apply(null,[])}else O===n&&f[g].apply(null,[])}}c(H,"gvec");async function se(e,t={}){let{passRestriction:n=[]}=t,o=window.location.pathname.replace(/^\/|\/$/g,"").toLowerCase(),i=e.replace(/^\/|\/$/g,"").toLowerCase();if(!new RegExp("^"+i.replace(/:[^\/]+/g,"[^/]+")+"$").test(o))return!1;let r=Array.isArray(n)?n:[n];for(let a of r)try{let p=typeof a=="function"?a():a;if(p instanceof Promise){if(!await p)return!1}else if(!p)return!1}catch(p){return console.error("Route check failed:",p),!1}return!0}c(se,"Route");function ce(e){return e==null||e===""}c(ce,"IsEmpty");function le(e){window.history.pushState(e,e,e)}c(le,"Navigate");function G(e){y.maxCacheSize=e}c(G,"setMaxCacheSize");function K(e){y.cleanhtml=e}c(K,"cleanHtml");async function ae(e,t){let n=t.replace(/\//g,"").toLowerCase(),o=Object.keys(e).find(i=>i.toLowerCase()===n);if(!o){let i=Object.keys(e).join(", ");throw new Error(`Unknown component: "${t}".
1
+ var D=Object.defineProperty;var l=(e,t)=>D(e,"name",{value:t,configurable:!0});var y={cleanHtml:G,cleanhtml:!0,setMaxCacheSize:J,maxCacheSize:10},g={funcname:[],dataMap:new Map},C=null,w={},M=new Map,v=new Map,x={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(x).flat().forEach(e=>{globalThis[e]=(...t)=>S(e,...t)});var P=new Set(x.valueElements),Y=new Set(x.srcElements),Q=new Set(x.hrefElements),I=new Set(x.voidElements);function X(e,t){w[e]||(w[e]=K(t))}l(X,"createGlobalSignal");function Z(e){return w[e]}l(Z,"getGlobalSignal");function R(e,t){g.dataMap.has(e)&&g.dataMap.delete(e),g.dataMap.set(e,t)}l(R,"addEntry");function E(e){A(E.name);let t=g.dataMap.get(e);return t?t.value:null}l(E,"gve");function ee(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)}l(ee,"setCookie");function te(e){let n=`; ${document.cookie}`.split(`; ${e}=`);if(n.length===2){let o=n.pop().split(";").shift();try{let i=JSON.parse(o);return typeof i=="object"&&i!==null&&"nodeType"in i&&i.nodeType===1,i}catch{return o}}return null}l(te,"getCookie");function ne(e,t){let n;t instanceof HTMLElement?n=t.outerHTML:typeof t=="object"?n=JSON.stringify(t):n=t.toString(),localStorage.setItem(e,n)}l(ne,"setStorage");function oe(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}}l(oe,"getStorage");function L(e,t=void 0){A(L.name),g.createInstance=L.name;let n="";t===void 0?n=e():n=e(t)}l(L,"createInstance");function z(e,t){A(z.name),g.rpc=z.name;let n={};for(let[o,i]of Object.entries(t))e[o]?n[o]=e[o].apply(null,i):(console.error(`Function ${o} not found!`),n[o]=null);return n}l(z,"rpc");function H(e,t=!1,n){A(H.name),g.gvec=H.name;let o=Object.keys(e),i=o[0],c=o[1],r=o[2];var a=e[i];a=a.name;var p=e[c];let f=e[c];var h=E(c)===null;if(h||t===!1){var m=""+c;g.dataMap.delete(m),L(p,e[r])}p=E(c);var s=E(i);if(s===null)throw new Error(` source id '${i} is not found in source component `);if(p===null)throw new Error(` target id '${c} is not found in target component `);if(s.replaceWith(p),n!==void 0)for(let b in f){let O=b.toString();if(typeof n=="object"){for(var u in n)if(O===u){var d=n[u];typeof d=="object"?f[b].apply(null,d):f[b].apply(null,[])}}else if(n.indexOf(",">-1)){let j=n.split(",");for(let T=0;T<j.length;T++)O===j[T]&&f[b].apply(null,[])}else O===n&&f[b].apply(null,[])}}l(H,"gvec");async function re(e,t={}){let{passRestriction:n=[]}=t,o=window.location.pathname.replace(/^\/|\/$/g,"").toLowerCase(),i=e.replace(/^\/|\/$/g,"").toLowerCase();if(!new RegExp("^"+i.replace(/:[^\/]+/g,"[^/]+")+"$").test(o))return!1;let r=Array.isArray(n)?n:[n];for(let a of r)try{let p=typeof a=="function"?a():a;if(p instanceof Promise){if(!await p)return!1}else if(!p)return!1}catch(p){return console.error("Route check failed:",p),!1}return!0}l(re,"Route");function ie(e){return e==null||e===""}l(ie,"IsEmpty");function se(e){window.history.pushState(e,e,e)}l(se,"Navigate");function J(e){y.maxCacheSize=e}l(J,"setMaxCacheSize");function G(e){y.cleanhtml=e}l(G,"cleanHtml");async function le(e,t){let n=t.replace(/\//g,"").toLowerCase(),o=Object.keys(e).find(i=>i.toLowerCase()===n);if(!o){let i=Object.keys(e).join(", ");throw new Error(`Unknown component: "${t}".
2
2
  Available components: ${i}
3
3
 
4
4
  To add this component:
@@ -6,6 +6,6 @@ To add this component:
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(i){throw new Error(`Failed to load component "${o}": ${i.message}`)}}c(ae,"loadFunc");function ue(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(ue,"clearComponentCache");function fe(e){var a,p;let n=window.location.pathname.split("/").filter(Boolean),o=n[0]||"home",i=n.slice(1),l=(p=(a=e[o])==null?void 0:a.urlParam)==null?void 0:p.split(":"),r={};return l&&l.length&&l[0].includes("{")?(l.forEach((f,h)=>{f=f.replace(/[{}]/g,""),r[f]=i[h]}),{componentName:o,params:r}):{componentName:o,params:i}}c(fe,"parsePath");function E(e){return new DOMParser().parseFromString(e,"text/html").body.firstChild}c(E,"parseHTML");async function de(e,t,n=null,o=null){let i=e[t.toLowerCase()];if(i||(typeof e.fallback=="string"?i=e[e.fallback]:i=e.fallback),!i)return E("<h1>404 - Component not found</h1>");let{loader:l,guard:r,cacheExpiration:a=null,...p}=i;if(o===null&&typeof i.logic=="function"&&(o=i.logic),typeof r=="function"&&!await r(n))return E("<h1>403 - Forbidden</h1><p>You do not have access to this page.</p>");for(let f in p){let h=p[f];if(typeof h=="function")try{await h()}catch(m){console.error(m)}}try{let f=Date.now(),h=v.get(t);h&&a!==null&&f-h.cachedAt>a&&(v.delete(t),h=null);let m;if(h)m=h.component,v.set(t,{component:m,cachedAt:f});else{if(m=(await l()).default,v.size>=y.maxCacheSize){let u=v.keys().next().value;v.delete(u)}v.set(t,{component:m,cachedAt:f})}return typeof m!="function"?E("<h1>Invalid component</h1>"):typeof n=="object"&&!Array.isArray(n)?m(n):n?m(...n):m()}catch(f){return console.error(f),E("<h1>Error loading component</h1>")}}c(de,"loadRunFunc");function F(e=""){var i,l;A(F.name),b.buildRoadMap=F.name;var t="";let n=(i=new Error().stack)==null?void 0:i.toString();navigator.userAgent.toLowerCase().indexOf("firefox")>0?n=n.split("@"):n=n.split(`
9
+ };`)}if(v.has(o))return v.get(o);try{let c=(await e[o]()).default;return v.set(o,c),c}catch(i){throw new Error(`Failed to load component "${o}": ${i.message}`)}}l(le,"loadFunc");function ce(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}l(ce,"clearComponentCache");function ae(e){var a,p;let n=window.location.pathname.split("/").filter(Boolean),o=n[0]||"home",i=n.slice(1),c=(p=(a=e[o])==null?void 0:a.urlParam)==null?void 0:p.split(":"),r={};return c&&c.length&&c[0].includes("{")?(c.forEach((f,h)=>{f=f.replace(/[{}]/g,""),r[f]=i[h]}),{componentName:o,params:r}):{componentName:o,params:i}}l(ae,"parsePath");function k(e){return new DOMParser().parseFromString(e,"text/html").body.firstChild}l(k,"parseHTML");async function ue(e,t,n=null,o=null){let i=e[t.toLowerCase()];if(i||(typeof e.fallback=="string"?i=e[e.fallback]:i=e.fallback),!i)return k("<h1>404 - Component not found</h1>");let{loader:c,guard:r,cacheExpiration:a=null,...p}=i;if(o===null&&typeof i.logic=="function"&&(o=i.logic),typeof r=="function"&&!await r(n))return k("<h1>403 - Forbidden</h1><p>You do not have access to this page.</p>");for(let f in p){let h=p[f];if(typeof h=="function")try{await h()}catch(m){console.error(m)}}try{let f=Date.now(),h=v.get(t);h&&a!==null&&f-h.cachedAt>a&&(v.delete(t),h=null);let m;if(h)m=h.component,v.set(t,{component:m,cachedAt:f});else{if(m=(await c()).default,v.size>=y.maxCacheSize){let u=v.keys().next().value;v.delete(u)}v.set(t,{component:m,cachedAt:f})}return typeof m!="function"?k("<h1>Invalid component</h1>"):typeof n=="object"&&!Array.isArray(n)?m(n):n?m(...n):m()}catch(f){return console.error(f),k("<h1>Error loading component</h1>")}}l(ue,"loadRunFunc");function F(e=""){var i,c;A(F.name),g.buildRoadMap=F.name;var t="";let n=(i=new Error().stack)==null?void 0:i.toString();navigator.userAgent.toLowerCase().indexOf("firefox")>0?n=n.split("@"):n=n.split(`
10
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(!b.funcname.includes(o)&&!(o===void 0||o==="")&&!(o.indexOf("http://")>-1||o.indexOf("https://")>-1)){if(b.gvec!==void 0&&o.indexOf(b.gvec)>-1)break;t.indexOf("|"+o)>-1||(t+="|"+o.replace(".","|"))}}return e+t}c(F,"buildRoadMap");function A(e){!b.funcname.includes(e)&&b.funcname.push(e)}c(A,"setFuncName");function V(e){let t=e,n=new Set;function o(){return C&&n.add(C),t}c(o,"get");function i(l,r=!1){(r||t!==l)&&(t=l,n.forEach(a=>a()))}return c(i,"set"),[o,i]}c(V,"createSignal");function $(e){function t(){C=t,e(),C=null}c(t,"wrapped"),t()}c($,"createEffect");function B(e){e=e.toLowerCase(),x.innerHTMLElements.includes(e)||(x.innerHTMLElements.push(e),globalThis[e]=(...t)=>S(e,...t))}c(B,"createTypeElement");function U(e){e=e.toLowerCase(),x.innerHTMLElements.includes(e)||(x.innerHTMLElements.push(e),globalThis[e]=(...t)=>S(e,...t))}c(U,"createSigment");function pe(e){U(e)}c(pe,"addSigment");function me(e,...t){if(B(e),t.length!==0)return globalThis[e](...t)}c(me,"createElement");function _(e){let t=document.createTextNode("");return $(()=>{if(typeof w!="object"||w===null){t.textContent=e;return}let n=e.replace(/{{(.*?)}}/g,(o,i)=>{let l=i.trim();if(w.hasOwnProperty(l)){let r=w[l];if(r&&typeof r[0]=="function")return r[0]()??""}return""});t.textContent=n}),t}c(_,"interpolateReactiveText");function he(e,t=5e3,n={}){let o=JSON.stringify([e,n,t]);if(!M.has(o)){let i=W(async()=>{let l=await fetch(e,n);if(!l.ok)throw new Error(`Fetch failed: ${l.status}`);return l.json()},t);M.set(o,i)}return M.get(o)()}c(he,"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 q(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(q,"sortObjectShallow");function W(e,t=5e3,n={}){let o=new Map,i=c((...l)=>{let{deepSort:r}=n,a;r===!0?a=l.map(s=>s&&typeof s=="object"?N(s):s):r===!1?a=l.map(s=>s&&typeof s=="object"?q(s):s):a=l;let p=JSON.stringify(a),f=Date.now(),h=o.get(p);if(h&&f-h.timestamp<t)return h.value;let m=e(...l);return o.set(p,{value:m,timestamp:f}),m instanceof Promise&&m.catch(()=>o.delete(p)),m},"wrapped");return i.clear=()=>o.clear(),i}c(W,"memoizeFunc");function S(e,...t){let n={},o=[];A(S.name);var i="";i=F();var l=i.split("|");if(l.includes(b.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 p=I.has(e),f=P.has(e),h=e==="input"||e==="option",m=e==="option";if(!a)for(let s in n){let u=n[s];s.startsWith("on")&&typeof u=="function"?r.addEventListener(s.slice(2).toLowerCase(),u):typeof u=="function"&&s!=="children"?$(()=>{let d=u();d==null||d===!1?(r.removeAttribute(s),s==="value"&&f&&(r.value="",y.cleanhtml||r.removeAttribute("value")),s==="checked"&&h&&(r.checked=!1,y.cleanhtml||r.removeAttribute("checked")),s==="selected"&&m&&(r.selected=!1,y.cleanhtml||r.removeAttribute("selected")),s==="id"&&(r.iid="",y.cleanhtml||r.removeAttribute("id"))):s==="id"?(r.iid=d,y.cleanhtml?r.setAttribute("id",d):r.removeAttribute("id"),R(d,{name:d,caller:d+i,value:r})):s==="value"&&f?(r.value=d,y.cleanhtml?r.setAttribute("value",d):r.removeAttribute("value")):s==="checked"&&h?(r.checked=d,y.cleanhtml&&d?r.setAttribute("checked",""):r.removeAttribute("checked")):s==="selected"&&m?(r.selected=d,y.cleanhtml&&d?r.setAttribute("selected",""):r.removeAttribute("selected")):r.setAttribute(s,d)}):u!=null&&u!==!1&&(s==="id"?(r.iid=u,y.cleanhtml?r.setAttribute("id",u):r.removeAttribute("id"),R(u,{name:u,caller:u+i,value:r})):s==="value"&&f?(r.value=u,y.cleanhtml?r.setAttribute("value",u):r.removeAttribute("value")):s==="checked"&&h?(r.checked=u,y.cleanhtml?r.setAttribute("checked",""):r.removeAttribute("checked")):s==="selected"&&m?(r.selected=u,y.cleanhtml?r.setAttribute("selected",""):r.removeAttribute("selected")):r.setAttribute(s,u))}return p?o.length===1&&(typeof o[0]=="string"||typeof o[0]=="number")?f&&(r.value=o[0],y.cleanhtml?r.setAttribute("value",o[0]):r.removeAttribute("value")):o.length>0&&console.warn(`Void element <${e}> should not have children.`):o.flat().forEach(s=>{if(typeof s=="function"){let u=document.createTextNode("");r.appendChild(u),$(()=>{let d=s();if(d instanceof Node){let g=u.parentNode;if(!g)return;g.nodeType===Node.DOCUMENT_FRAGMENT_NODE?g.replaceChildren(d):g.replaceChild(d,u),u=d}else{let g=d==null?"":String(d);u.textContent!==g&&(u.textContent=g)}})}else if(typeof s=="string"&&s.includes("{{")&&!s.includes("function"))r.appendChild(_(s));else if(typeof s=="string"||typeof s=="number"){if(s.includes("function get(")||s.includes("function (")||s.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(s))}else(s instanceof DocumentFragment||s instanceof Node)&&r.appendChild(s)}),r}c(S,"h");export{ce as IsEmpty,y as MyApp,le as Navigate,se as Route,pe as addSigment,ue as clearComponentCache,$ as createEffect,me as createElement,Z as createGlobalSignal,U as createSigment,V as createSignal,he as fetchCache,oe as getCookie,J as getGlobalSignal,ie as getStorage,te as getVirtualElementById,k as gve,H as gvec,S as h,ae as loadFunc,de as loadRunFunc,W as memoizeFunc,fe as parsePath,z as rpc,ne as setCookie,re as setStorage,ee as useGlobalSignal};
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=(c=n[r])==null?void 0:c.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}l(F,"buildRoadMap");function A(e){!g.funcname.includes(e)&&g.funcname.push(e)}l(A,"setFuncName");function K(e){let t=e,n=new Set;function o(){return C&&n.add(C),t}l(o,"get");function i(c,r=!1){(r||t!==c)&&(t=c,n.forEach(a=>a()))}return l(i,"set"),[o,i]}l(K,"createSignal");function $(e){function t(){C=t,e(),C=null}l(t,"wrapped"),t()}l($,"createEffect");function V(e){e=e.toLowerCase(),x.innerHTMLElements.includes(e)||(x.innerHTMLElements.push(e),globalThis[e]=(...t)=>S(e,...t))}l(V,"createTypeElement");function B(e){e=e.toLowerCase(),x.innerHTMLElements.includes(e)||(x.innerHTMLElements.push(e),globalThis[e]=(...t)=>S(e,...t))}l(B,"createSigment");function fe(e){B(e)}l(fe,"addSigment");function de(e,...t){if(V(e),t.length!==0)return globalThis[e](...t)}l(de,"createElement");function U(e){let t=document.createTextNode("");return $(()=>{if(typeof w!="object"||w===null){t.textContent=e;return}let n=e.replace(/{{(.*?)}}/g,(o,i)=>{let c=i.trim();if(w.hasOwnProperty(c)){let r=w[c];if(r&&typeof r[0]=="function")return r[0]()??""}return""});t.textContent=n}),t}l(U,"interpolateReactiveText");function pe(e,t=5e3,n={}){let o=JSON.stringify([e,n,t]);if(!M.has(o)){let i=q(async()=>{let c=await fetch(e,n);if(!c.ok)throw new Error(`Fetch failed: ${c.status}`);return c.json()},t);M.set(o,i)}return M.get(o)()}l(pe,"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}l(N,"sortObjectDeep");function _(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}l(_,"sortObjectShallow");function q(e,t=5e3,n={}){let o=new Map,i=l((...c)=>{let{deepSort:r}=n,a;r===!0?a=c.map(s=>s&&typeof s=="object"?N(s):s):r===!1?a=c.map(s=>s&&typeof s=="object"?_(s):s):a=c;let p=JSON.stringify(a),f=Date.now(),h=o.get(p);if(h&&f-h.timestamp<t)return h.value;let m=e(...c);return o.set(p,{value:m,timestamp:f}),m instanceof Promise&&m.catch(()=>o.delete(p)),m},"wrapped");return i.clear=()=>o.clear(),i}l(q,"memoizeFunc");function S(e,...t){let n={},o=[];A(S.name);var i="";i=F();var c=i.split("|");if(c.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 p=I.has(e),f=P.has(e),h=e==="input"||e==="option",m=e==="option";if(!a)for(let s in n){let u=n[s];s.startsWith("on")&&typeof u=="function"?r.addEventListener(s.slice(2).toLowerCase(),u):typeof u=="function"&&s!=="children"?$(()=>{let d=u();d==null||d===!1?(r.removeAttribute(s),s==="value"&&f&&(r.value="",y.cleanhtml||r.removeAttribute("value")),s==="checked"&&h&&(r.checked=!1,y.cleanhtml||r.removeAttribute("checked")),s==="selected"&&m&&(r.selected=!1,y.cleanhtml||r.removeAttribute("selected")),s==="id"&&(r.iid="",y.cleanhtml||r.removeAttribute("id"))):s==="id"?(r.iid=d,y.cleanhtml?r.setAttribute("id",d):r.removeAttribute("id"),R(d,{name:d,caller:d+i,value:r})):s==="value"&&f?(r.value=d,y.cleanhtml?r.setAttribute("value",d):r.removeAttribute("value")):s==="checked"&&h?(r.checked=d,y.cleanhtml&&d?r.setAttribute("checked",""):r.removeAttribute("checked")):s==="selected"&&m?(r.selected=d,y.cleanhtml&&d?r.setAttribute("selected",""):r.removeAttribute("selected")):r.setAttribute(s,d)}):u!=null&&u!==!1&&(s==="id"?(r.iid=u,y.cleanhtml?r.setAttribute("id",u):r.removeAttribute("id"),R(u,{name:u,caller:u+i,value:r})):s==="value"&&f?(r.value=u,y.cleanhtml?r.setAttribute("value",u):r.removeAttribute("value")):s==="checked"&&h?(r.checked=u,y.cleanhtml?r.setAttribute("checked",""):r.removeAttribute("checked")):s==="selected"&&m?(r.selected=u,y.cleanhtml?r.setAttribute("selected",""):r.removeAttribute("selected")):r.setAttribute(s,u))}return p?o.length===1&&(typeof o[0]=="string"||typeof o[0]=="number")?f&&(r.value=o[0],y.cleanhtml?r.setAttribute("value",o[0]):r.removeAttribute("value")):o.length>0&&console.warn(`Void element <${e}> should not have children.`):o.flat().forEach(s=>{if(typeof s=="function"){let u=document.createTextNode("");r.appendChild(u),$(()=>{let d=s();if(d instanceof Node){let b=u.parentNode;if(!b)return;b.nodeType===Node.DOCUMENT_FRAGMENT_NODE?b.replaceChildren(d):b.replaceChild(d,u),u=d}else{let b=d==null?"":String(d);u.textContent!==b&&(u.textContent=b)}})}else if(typeof s=="string"&&s.includes("{{")&&!s.includes("function"))r.appendChild(U(s));else if(typeof s=="string"||typeof s=="number"){if(s.includes("function get(")||s.includes("function (")||s.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(s))}else(s instanceof DocumentFragment||s instanceof Node)&&r.appendChild(s)}),r}l(S,"h");export{ie as IsEmpty,y as MyApp,se as Navigate,re as Route,fe as addSigment,ce as clearComponentCache,$ as createEffect,de as createElement,X as createGlobalSignal,B as createSigment,K as createSignal,pe as fetchCache,te as getCookie,Z as getGlobalSignal,oe as getStorage,E as getVirtualElementById,X as globalSignal,E as gve,H as gvec,S as h,le as loadFunc,ue as loadRunFunc,q as memoizeFunc,ae as parsePath,z as rpc,ee as setCookie,ne as setStorage,K as signal,Z as useGlobalSignal};
@@ -10,13 +10,7 @@ export declare const MyApp: {
10
10
  maxCacheSize: number;
11
11
  };
12
12
 
13
- /**
14
- * Creates a reactive signal with getter and setter.
15
- * Setter optionally accepts a second argument 'force' (boolean).
16
- */
17
- export declare function createSignal<T = undefined>(
18
- initialValue?: T
19
- ): [() => T, (newValue: T, force?: boolean) => void];
13
+
20
14
 
21
15
  /**
22
16
  * Creates a reactive effect that runs the given function and tracks dependencies.
@@ -115,28 +109,53 @@ export declare function loadRunFunc(
115
109
  */
116
110
  export declare function clearComponentCache(componentName: string): void;
117
111
 
112
+ export declare function createGlobalSignal<T>(key: string, initialValue: T): [() => T, (v: T) => void];
113
+
118
114
  /**
119
- * Creates a global signal with a key and initial value.
115
+ * Alias for createGlobalSignal.
120
116
  */
121
- export declare function createGlobalSignal<T>(
122
- key: string,
123
- initialValue: T
124
- ): void;
117
+ export { createGlobalSignal as globalSignal };
118
+
119
+
120
+
121
+ export declare function getGlobalSignal<T>(key: string): [() => T, (v: T) => void];
125
122
 
126
123
  /**
127
- * Gets a global signal by key.
124
+ * Alias for getGlobalSignal.
128
125
  */
129
- export declare function getGlobalSignal<T>(key: string): [() => T, (newValue: T) => void];
126
+
127
+ export { getGlobalSignal as useGlobalSignal };
128
+
130
129
 
131
130
  /**
132
- * Alias for getGlobalSignal.
131
+ * Creates a reactive signal with getter and setter.
132
+ * Setter optionally accepts a second argument 'force' (boolean).
133
133
  */
134
- export declare const useGlobalSignal: typeof getGlobalSignal;
134
+ export declare function createSignal<T = undefined>(
135
+ initialValue?: T
136
+ ): [() => T, (newValue: T, force?: boolean) => void];
137
+
138
+
139
+ /**
140
+ * Alias for createSignal.
141
+ */
142
+
143
+ export { createSignal as signal };
144
+
135
145
 
136
146
  /**
137
147
  * Function gve creates an HTML element with the given name.
138
148
  */
139
- export declare function gve(name: string): HTMLElement;
149
+ export declare function gve(name: string): HTMLElement | null;
150
+ export { gve as getVirtualElementById };
151
+
152
+
153
+
154
+ export function gve(name: string): HTMLElement | null;
155
+
156
+ export { gve as getVirtualElementById };
157
+
158
+
140
159
 
141
160
  /**
142
161
  * Sets a cookie; value can be string or object (will be JSON.stringified).
@@ -194,13 +213,6 @@ export declare function IsEmpty(v: any): boolean;
194
213
  */
195
214
  export declare function Navigate(path: string): void;
196
215
 
197
- /**
198
- * Retrieves a virtual HTML element by its name using `gve`.
199
- *
200
- * @param e - The name of the element to retrieve.
201
- * @returns The corresponding HTMLElement.
202
- */
203
- export declare function getVirtualElementById(e: string): HTMLElement;
204
216
 
205
217
  /**
206
218
  * Loads a component module by name from a given map of dynamic import functions.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sigment",
3
- "version": "1.0.5",
4
- "description": "JavaScript Vanilla library",
3
+ "version": "1.0.7",
4
+ "description": "A lightweight reactive JavaScript framework using signals and vanilla JS",
5
5
  "main": "./dist/index.js",
6
6
  "repository": {
7
7
  "type": "git",
package/types/index.d.ts CHANGED
@@ -10,13 +10,7 @@ export declare const MyApp: {
10
10
  maxCacheSize: number;
11
11
  };
12
12
 
13
- /**
14
- * Creates a reactive signal with getter and setter.
15
- * Setter optionally accepts a second argument 'force' (boolean).
16
- */
17
- export declare function createSignal<T = undefined>(
18
- initialValue?: T
19
- ): [() => T, (newValue: T, force?: boolean) => void];
13
+
20
14
 
21
15
  /**
22
16
  * Creates a reactive effect that runs the given function and tracks dependencies.
@@ -115,28 +109,53 @@ export declare function loadRunFunc(
115
109
  */
116
110
  export declare function clearComponentCache(componentName: string): void;
117
111
 
112
+ export declare function createGlobalSignal<T>(key: string, initialValue: T): [() => T, (v: T) => void];
113
+
118
114
  /**
119
- * Creates a global signal with a key and initial value.
115
+ * Alias for createGlobalSignal.
120
116
  */
121
- export declare function createGlobalSignal<T>(
122
- key: string,
123
- initialValue: T
124
- ): void;
117
+ export { createGlobalSignal as globalSignal };
118
+
119
+
120
+
121
+ export declare function getGlobalSignal<T>(key: string): [() => T, (v: T) => void];
125
122
 
126
123
  /**
127
- * Gets a global signal by key.
124
+ * Alias for getGlobalSignal.
128
125
  */
129
- export declare function getGlobalSignal<T>(key: string): [() => T, (newValue: T) => void];
126
+
127
+ export { getGlobalSignal as useGlobalSignal };
128
+
130
129
 
131
130
  /**
132
- * Alias for getGlobalSignal.
131
+ * Creates a reactive signal with getter and setter.
132
+ * Setter optionally accepts a second argument 'force' (boolean).
133
133
  */
134
- export declare const useGlobalSignal: typeof getGlobalSignal;
134
+ export declare function createSignal<T = undefined>(
135
+ initialValue?: T
136
+ ): [() => T, (newValue: T, force?: boolean) => void];
137
+
138
+
139
+ /**
140
+ * Alias for createSignal.
141
+ */
142
+
143
+ export { createSignal as signal };
144
+
135
145
 
136
146
  /**
137
147
  * Function gve creates an HTML element with the given name.
138
148
  */
139
- export declare function gve(name: string): HTMLElement;
149
+ export declare function gve(name: string): HTMLElement | null;
150
+ export { gve as getVirtualElementById };
151
+
152
+
153
+
154
+ export function gve(name: string): HTMLElement | null;
155
+
156
+ export { gve as getVirtualElementById };
157
+
158
+
140
159
 
141
160
  /**
142
161
  * Sets a cookie; value can be string or object (will be JSON.stringified).
@@ -194,13 +213,6 @@ export declare function IsEmpty(v: any): boolean;
194
213
  */
195
214
  export declare function Navigate(path: string): void;
196
215
 
197
- /**
198
- * Retrieves a virtual HTML element by its name using `gve`.
199
- *
200
- * @param e - The name of the element to retrieve.
201
- * @returns The corresponding HTMLElement.
202
- */
203
- export declare function getVirtualElementById(e: string): HTMLElement;
204
216
 
205
217
  /**
206
218
  * Loads a component module by name from a given map of dynamic import functions.