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 +5 -5
- package/package.json +1 -1
- package/types/index.d.ts +45 -6
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
Available components: ${
|
|
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(
|
|
10
|
-
`);for(let r=0;r<n.length;r++){var
|
|
11
|
-
`);if(
|
|
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
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
|
-
*
|
|
51
|
-
*
|
|
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
|
|
56
|
+
export function createSigment(
|
|
57
|
+
n: string,
|
|
58
|
+
nativeTag?: string | null
|
|
59
|
+
): void;
|
|
60
|
+
|
|
54
61
|
|
|
55
62
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
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
|
|
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
|
|