sigment 1.1.4 → 1.1.6
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 +5 -5
- package/package.json +1 -1
- package/types/index.d.ts +29 -34
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
|
|
2
|
-
Available components: ${
|
|
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}
|
|
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(
|
|
10
|
-
`);for(let
|
|
11
|
-
`);if(
|
|
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};
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,42 +1,46 @@
|
|
|
1
1
|
// index.d.ts
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
type ComponentLoader = () => Promise<{ default: (...args: any[]) => HTMLElement }>;
|
|
5
|
+
|
|
6
|
+
type ComponentMap = {
|
|
7
|
+
[key: string]: ComponentLoader;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export type Route = {
|
|
12
|
+
loader: () => Promise<any>;
|
|
13
|
+
// `urlParam` allows a string pattern like '{id}/{pageid}' for dynamic route parameters
|
|
14
|
+
urlParam?: string;
|
|
15
|
+
guard?: (params?: Record<string, any>) => boolean | Promise<boolean>;
|
|
16
|
+
logic?: () => void;
|
|
17
|
+
cacheExpiration?: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type RoutesMap = Record<string, Route | string>;
|
|
21
|
+
|
|
3
22
|
/**
|
|
4
23
|
* The main app object with some properties and functions
|
|
5
24
|
*/
|
|
6
25
|
export declare const MyApp: {
|
|
7
|
-
cleanHtml: (flag: boolean) => void;
|
|
26
|
+
cleanHtml: (flag: boolean) => void;
|
|
8
27
|
cleanhtml: true;
|
|
9
|
-
setMaxCacheSize: (size: number) => void;
|
|
28
|
+
setMaxCacheSize: (size: number) => void;
|
|
10
29
|
maxCacheSize: number;
|
|
30
|
+
setRoute: (routes: RoutesMap) => void; // <-- updated to accept RoutesMap
|
|
31
|
+
route: RoutesMap | null; // <-- updated here as well
|
|
11
32
|
};
|
|
12
33
|
|
|
13
34
|
|
|
35
|
+
export function NavigateTo(path: string): Promise<void>;
|
|
36
|
+
export function NavigateTo(path: string, stateful: boolean): Promise<void>;
|
|
37
|
+
export function NavigateTo(path: string, key: string): Promise<void>;
|
|
38
|
+
export function NavigateTo(path: string, key: string, stateful: boolean): Promise<void>;
|
|
39
|
+
export function NavigateTo(path: string, map: ComponentMap, stateful: boolean): Promise<void>;
|
|
40
|
+
export function NavigateTo(path: string, map: ComponentMap, key: string, stateful: boolean): Promise<void>;
|
|
14
41
|
|
|
15
42
|
|
|
16
43
|
|
|
17
|
-
type ComponentLoader = () => Promise<{ default: (...args: any[]) => HTMLElement }>;
|
|
18
|
-
|
|
19
|
-
type ComponentMap = {
|
|
20
|
-
[key: string]: ComponentLoader;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Navigate to a path and load/render a component.
|
|
25
|
-
*
|
|
26
|
-
* @param path - The URL path or route to navigate to.
|
|
27
|
-
* @param componentMap - Map of component keys to async loaders.
|
|
28
|
-
* @param componentKeyOrStateful - Either the key of the component to load, or a boolean indicating if stateful rendering is enabled.
|
|
29
|
-
* @param maybeStateful - Optional boolean, used if componentKey is provided explicitly as third param.
|
|
30
|
-
* @returns Promise<void>
|
|
31
|
-
*/
|
|
32
|
-
export function NavigateTo(
|
|
33
|
-
path: string,
|
|
34
|
-
componentMap: ComponentMap,
|
|
35
|
-
componentKeyOrStateful?: string | boolean,
|
|
36
|
-
maybeStateful?: boolean
|
|
37
|
-
): Promise<void>;
|
|
38
|
-
|
|
39
|
-
|
|
40
44
|
/**
|
|
41
45
|
* Creates a reactive effect that runs the given function and tracks dependencies.
|
|
42
46
|
*/
|
|
@@ -92,16 +96,7 @@ export function memoizeFunc<
|
|
|
92
96
|
|
|
93
97
|
|
|
94
98
|
|
|
95
|
-
export type Route = {
|
|
96
|
-
loader: () => Promise<any>;
|
|
97
|
-
// `urlParam` allows a string pattern like '{id}/{pageid}' for dynamic route parameters
|
|
98
|
-
urlParam?: string;
|
|
99
|
-
guard?: (params?: Record<string, any>) => boolean | Promise<boolean>;
|
|
100
|
-
logic?: () => void;
|
|
101
|
-
cacheExpiration?: number;
|
|
102
|
-
};
|
|
103
99
|
|
|
104
|
-
export type RoutesMap = Record<string, Route | string>;
|
|
105
100
|
|
|
106
101
|
/**
|
|
107
102
|
* Parses a path given a user-defined routes object.
|