@pure-ds/core 0.7.21 → 0.7.23
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/types/pds.d.ts +2 -2
- package/dist/types/public/assets/js/pds-manager.d.ts +16 -16
- package/dist/types/public/assets/js/pds-manager.d.ts.map +1 -1
- package/dist/types/public/assets/js/pds.d.ts +4 -8
- package/dist/types/public/assets/js/pds.d.ts.map +1 -1
- package/dist/types/public/assets/pds/components/pds-icon.d.ts +12 -0
- package/dist/types/public/assets/pds/components/pds-icon.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-live.d.ts.map +1 -1
- package/dist/types/src/js/pds.d.ts +1 -39
- package/dist/types/src/js/pds.d.ts.map +1 -1
- package/package.json +1 -1
- package/public/assets/js/app.js +4 -4
- package/public/assets/js/pds-manager.js +26 -26
- package/public/assets/js/pds.js +2 -2
- package/public/assets/pds/components/pds-icon.js +77 -26
- package/public/assets/pds/core/pds-manager.js +26 -26
- package/public/assets/pds/core.js +2 -2
- package/src/js/pds-core/pds-live.js +54 -21
- package/src/js/pds.d.ts +2 -2
- package/src/js/pds.js +142 -76
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var De=Object.defineProperty;var Pe=(e,t)=>{for(var n in t)De(e,n,{get:t[n],enumerable:!0})};var Y=class{constructor(){this._mode="static",this._staticPaths={tokens:"/assets/pds/styles/pds-tokens.css.js",primitives:"/assets/pds/styles/pds-primitives.css.js",components:"/assets/pds/styles/pds-components.css.js",utilities:"/assets/pds/styles/pds-utilities.css.js",styles:"/assets/pds/styles/pds-styles.css.js"}}setLiveMode(){this._mode="live"}setStaticMode(t={}){this._mode="static",this._staticPaths={...this._staticPaths,...t}}async getStylesheet(t){if(this._mode==="live")return null;try{return(await import(this._staticPaths[t]))[t]}catch(n){console.error(`[PDS Registry] Failed to load static ${t}:`,n),console.error(`[PDS Registry] Looking for: ${this._staticPaths[t]}`),console.error("[PDS Registry] Make sure you've run 'npm run pds:build' and configured PDS.start() with the correct static.root path");let r=new CSSStyleSheet;return r.replaceSync("/* Failed to load "+t+" */"),r}}get mode(){return this._mode}get isLive(){return this._mode==="live"}},M=new Y;async function de(e,t=[],n=null){try{let r=n?.primitivesStylesheet?n.primitivesStylesheet:await M.getStylesheet("primitives");e.adoptedStyleSheets=[r,...t]}catch(r){let c=e.host?.tagName?.toLowerCase()||"unknown";console.error(`[PDS Adopter] <${c}> failed to adopt primitives:`,r),e.adoptedStyleSheets=t}}async function ue(e,t=["primitives"],n=[],r=null){let c=Array.isArray(n)?n.filter(Boolean):[];if(c.length){let l=(Array.isArray(e.adoptedStyleSheets)?e.adoptedStyleSheets:[]).filter(w=>!c.includes(w));e.adoptedStyleSheets=[...l,...c]}try{let l=(await Promise.all(t.map(async w=>{if(r)switch(w){case"tokens":return r.tokensStylesheet;case"primitives":return r.primitivesStylesheet;case"components":return r.componentsStylesheet;case"utilities":return r.utilitiesStylesheet;default:break}return M.getStylesheet(w)}))).filter(w=>w!==null);e.adoptedStyleSheets=[...l,...c]}catch(s){let l=e.host?.tagName?.toLowerCase()||"unknown";console.error(`[PDS Adopter] <${l}> failed to adopt layers:`,s),e.adoptedStyleSheets=c}}function pe(e){let t=new CSSStyleSheet;return t.replaceSync(e),t}var fe={FontWeights:{light:300,normal:400,medium:500,semibold:600,bold:700},LineHeights:{tight:1.25,normal:1.5,relaxed:1.75},BorderWidths:{hairline:.5,thin:1,medium:2,thick:3},RadiusSizes:{none:0,small:4,medium:8,large:16,xlarge:24,xxlarge:32},ShadowDepths:{none:"none",light:"0 1px 2px 0 rgba(0, 0, 0, 0.05)",medium:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)",deep:"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",extreme:"0 25px 50px -12px rgba(0, 0, 0, 0.25)"},TransitionSpeeds:{fast:150,normal:250,slow:350},AnimationEasings:{linear:"linear",ease:"ease","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out",bounce:"cubic-bezier(0.68, -0.55, 0.265, 1.55)"},TouchTargetSizes:{compact:36,standard:44,comfortable:48,spacious:56},LinkStyles:{inline:"inline",block:"block",button:"button"},FocusStyles:{ring:"ring",outline:"outline",border:"border",glow:"glow"},TabSizes:{compact:2,standard:4,wide:8},SelectIcons:{chevron:"chevron",arrow:"arrow",caret:"caret",none:"none"},IconSizes:{xs:16,sm:20,md:24,lg:32,xl:48,"2xl":64,"3xl":96}};var ee={};Pe(ee,{deepMerge:()=>me,fragmentFromTemplateLike:()=>Me,isObject:()=>I,parseHTML:()=>Z});function I(e){return e&&typeof e=="object"&&!Array.isArray(e)}function me(e,t){let n={...e};return I(e)&&I(t)&&Object.keys(t).forEach(r=>{I(t[r])?r in e?n[r]=me(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}function Me(e){let t=Array.isArray(e?.strings)?e.strings:[],n=Array.isArray(e?.values)?e.values:[],r=new Set,c=[],s=/(\s)(\.[\w-]+)=\s*$/;for(let a=0;a<t.length;a+=1){let S=t[a]??"",m=S.match(s);if(m&&a<n.length){let g=m[2].slice(1),L=`pds-val-${a}`;S=S.replace(s,`$1data-pds-prop="${g}:${L}"`),r.add(a)}c.push(S),a<n.length&&!r.has(a)&&c.push(`<!--pds-val-${a}-->`)}let l=document.createElement("template");l.innerHTML=c.join("");let w=(a,S)=>{let m=a.parentNode;if(!m)return;if(S==null){m.removeChild(a);return}let E=g=>{if(g!=null){if(g instanceof Node){m.insertBefore(g,a);return}if(Array.isArray(g)){g.forEach(L=>E(L));return}m.insertBefore(document.createTextNode(String(g)),a)}};E(S),m.removeChild(a)},b=document.createTreeWalker(l.content,NodeFilter.SHOW_COMMENT),h=[];for(;b.nextNode();){let a=b.currentNode;a?.nodeValue?.startsWith("pds-val-")&&h.push(a)}return h.forEach(a=>{let S=Number(a.nodeValue.replace("pds-val-",""));w(a,n[S])}),l.content.querySelectorAll("*").forEach(a=>{let S=a.getAttribute("data-pds-prop");if(!S)return;let[m,E]=S.split(":"),g=Number(String(E).replace("pds-val-",""));m&&Number.isInteger(g)&&(a[m]=n[g]),a.removeAttribute("data-pds-prop")}),l.content}function Z(e){return new DOMParser().parseFromString(e,"text/html").body.childNodes}var ye="pds",ke=/^([a-z][a-z0-9+\-.]*:)?\/\//i,he=/^[a-z]:/i;function U(e=""){return e.endsWith("/")?e:`${e}/`}function Te(e="",t=ye){let n=e.replace(/\/+$/,"");return new RegExp(`(?:^|/)${t}$`,"i").test(n)?n:`${n}/${t}`}function Ue(e){return e.replace(/^\.\/+/,"")}function Ce(e){return he.test(e)?e.replace(he,"").replace(/^\/+/,""):e}function je(e){return e.startsWith("public/")?e.substring(7):e}function N(e,t={}){let n=t.segment||ye,r=t.defaultRoot||`/assets/${n}/`,c=e?.public&&e.public?.root||e?.static&&e.static?.root||null;if(!c||typeof c!="string")return U(r);let s=c.trim();return s?(s=s.replace(/\\/g,"/"),s=Te(s,n),s=U(s),ke.test(s)?s:(s=Ue(s),s=Ce(s),s.startsWith("/")||(s=je(s),s.startsWith("/")||(s=`/${s}`),s=s.replace(/\/+/g,(l,w)=>w===0?l:"/")),U(s))):U(r)}async function $e(...e){let t={};e.length&&typeof e[e.length-1]=="object"&&(t=e.pop()||{});let n=e,{baseURL:r,mapper:c=h=>`${h}.js`,onError:s=(h,i)=>console.error(`[defineWebComponents] ${h}:`,i)}=t,l=r?new URL(r,typeof location<"u"?location.href:import.meta.url):new URL("./",import.meta.url),w=h=>h.toLowerCase().replace(/(^|-)([a-z])/g,(i,a,S)=>S.toUpperCase()),b=async h=>{try{if(customElements.get(h))return{tag:h,status:"already-defined"};let i=c(h),S=await import(i instanceof URL?i.href:new URL(i,l).href),m=S?.default??S?.[w(h)];if(!m){if(customElements.get(h))return{tag:h,status:"self-defined"};throw new Error(`No export found for ${h}. Expected default export or named export "${w(h)}".`)}return customElements.get(h)?{tag:h,status:"race-already-defined"}:(customElements.define(h,m),{tag:h,status:"defined"})}catch(i){throw s(h,i),i}};return Promise.all(n.map(b))}var z=class{constructor(t={}){let{baseURL:n,mapper:r,onError:c,predicate:s=()=>!0,attributeModule:l="data-module",root:w=document,scanExisting:b=!0,debounceMs:h=16,observeShadows:i=!0,enhancers:a=[],patchAttachShadow:S=!0}=t,m=new Set,E=new Set,g=new Set,L=new Map,x=new WeakMap,_=new WeakMap,p=0,y=!1,v=null,O=d=>{if(!d||!a.length)return;let f=_.get(d);f||(f=new Set,_.set(d,f));for(let u of a)if(!(!u.selector||!u.run)&&!f.has(u.selector))try{d.matches&&d.matches(u.selector)&&(u.run(d),f.add(u.selector))}catch(A){console.warn(`[AutoDefiner] Error applying enhancer for selector "${u.selector}":`,A)}},T=(d,f)=>{if(!y&&!(!d||!d.includes("-"))&&!customElements.get(d)&&!E.has(d)&&!g.has(d)){if(f&&f.getAttribute){let u=f.getAttribute(l);u&&!L.has(d)&&L.set(d,u)}m.add(d),Re()}},Re=()=>{p||(p=setTimeout(ie,h))},D=d=>{if(d){if(d.nodeType===1){let f=d,u=f.tagName?.toLowerCase();u&&u.includes("-")&&!customElements.get(u)&&s(u,f)&&T(u,f),O(f),i&&f.shadowRoot&&X(f.shadowRoot)}d.querySelectorAll&&d.querySelectorAll("*").forEach(f=>{let u=f.tagName?.toLowerCase();u&&u.includes("-")&&!customElements.get(u)&&s(u,f)&&T(u,f),O(f),i&&f.shadowRoot&&X(f.shadowRoot)})}},X=d=>{if(!d||x.has(d))return;D(d);let f=new MutationObserver(u=>{for(let A of u)A.addedNodes?.forEach(P=>{D(P)}),A.type==="attributes"&&A.target&&D(A.target)});f.observe(d,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[l,...a.map(u=>u.selector).filter(u=>u.startsWith("data-"))]}),x.set(d,f)};async function ie(){if(clearTimeout(p),p=0,!m.size)return;let d=Array.from(m);m.clear(),d.forEach(f=>E.add(f));try{let f=u=>L.get(u)??(r?r(u):`${u}.js`);await $e(...d,{baseURL:n,mapper:f,onError:(u,A)=>{g.add(u),c?.(u,A)}})}catch{}finally{d.forEach(f=>E.delete(f))}}let ce=w===document?document.documentElement:w,le=new MutationObserver(d=>{for(let f of d)f.addedNodes?.forEach(u=>{D(u)}),f.type==="attributes"&&f.target&&D(f.target)});if(le.observe(ce,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[l,...a.map(d=>d.selector).filter(d=>d.startsWith("data-"))]}),i&&S&&Element.prototype.attachShadow){let d=Element.prototype.attachShadow;Element.prototype.attachShadow=function(u){let A=d.call(this,u);if(u&&u.mode==="open"){X(A);let P=this.tagName?.toLowerCase();P&&P.includes("-")&&!customElements.get(P)&&T(P,this)}return A},v=()=>Element.prototype.attachShadow=d}return b&&D(ce),{stop(){y=!0,le.disconnect(),v&&v(),p&&(clearTimeout(p),p=0),x.forEach(d=>d.disconnect())},flush:ie}}static async define(...t){let n={};t.length&&typeof t[t.length-1]=="object"&&(n=t.pop()||{});let r=t,{baseURL:c,mapper:s=i=>`${i}.js`,onError:l=(i,a)=>console.error(`[defineWebComponents] ${i}:`,a)}=n,w=c?new URL(c,typeof location<"u"?location.href:import.meta.url):new URL("./",import.meta.url),b=i=>i.toLowerCase().replace(/(^|-)([a-z])/g,(a,S,m)=>m.toUpperCase()),h=async i=>{try{if(customElements.get(i))return{tag:i,status:"already-defined"};let a=s(i),m=await import(a instanceof URL?a.href:new URL(a,w).href),E=m?.default??m?.[b(i)];if(!E){if(customElements.get(i))return{tag:i,status:"self-defined"};throw new Error(`No export found for ${i}. Expected default export or named export "${b(i)}".`)}return customElements.get(i)?{tag:i,status:"race-already-defined"}:(customElements.define(i,E),{tag:i,status:"defined"})}catch(a){throw l(i,a),a}};return Promise.all(r.map(h))}};var Oe=/^[a-z][a-z0-9+\-.]*:\/\//i,C=(()=>{try{return import.meta.url}catch{return}})(),F=e=>typeof e=="string"&&e.length&&!e.endsWith("/")?`${e}/`:e;function W(e,t={}){if(!e||Oe.test(e))return e;let{preferModule:n=!0}=t,r=()=>{if(!C)return null;try{return new URL(e,C).href}catch{return null}},c=()=>{if(typeof window>"u"||!window.location?.origin)return null;try{return new URL(e,window.location.origin).href}catch{return null}};return(n?r()||c():c()||r())||e}var we=(()=>{if(C)try{let e=new URL(C);if(/\/public\/assets\/js\//.test(e.pathname))return new URL("../pds/",C).href}catch{return}})(),Se=!1;function ge(e){Se||typeof document>"u"||(Se=!0,e.addEventListener("pds:ready",t=>{let n=t.detail?.mode;n&&document.documentElement.classList.add(`pds-${n}`,"pds-ready")}))}function Ee({manageTheme:e,themeStorageKey:t,applyResolvedTheme:n,setupSystemListenerIfNeeded:r}){let c="light",s=null;if(e&&typeof window<"u"){try{s=localStorage.getItem(t)||null}catch{s=null}try{n?.(s),r?.(s)}catch{}s?s==="system"?c=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":c=s:c=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}return{resolvedTheme:c,storedTheme:s}}function B(e,{resolvePublicAssetURL:t}){let n=!!(e?.public?.root||e?.static?.root),r=t(e);return!n&&we&&(r=we),F(W(r))}async function be(e,{baseEnhancers:t=[]}={}){let{autoDefineBaseURL:n="/auto-define/",autoDefinePreload:r=[],autoDefineMapper:c=null,enhancers:s=[],autoDefineOverrides:l=null,autoDefinePreferModule:w=!0}=e,b=(()=>{let i=new Map;return(t||[]).forEach(a=>i.set(a.selector,a)),(s||[]).forEach(a=>i.set(a.selector,a)),Array.from(i.values())})(),h=null;if(typeof window<"u"&&typeof document<"u"){let i=z,a=p=>{switch(p){case"pds-tabpanel":return"pds-tabstrip.js";default:return`${p}.js`}},{mapper:S,enhancers:m,...E}=l&&typeof l=="object"?l:{},g=m?Array.isArray(m)?m:typeof m=="object"?Object.values(m):[]:[],L=(()=>{let p=new Map;return(b||[]).forEach(y=>{y?.selector&&p.set(y.selector,y)}),(g||[]).forEach(y=>{if(!y?.selector)return;let v=p.get(y.selector)||null;p.set(y.selector,{...v||{},...y,run:typeof y?.run=="function"?y.run:v?.run})}),Array.from(p.values())})(),_={baseURL:n&&F(W(n,{preferModule:w})),predefine:r,scanExisting:!0,observeShadows:!0,patchAttachShadow:!0,debounceMs:16,enhancers:L,onError:(p,y)=>{if(typeof p=="string"&&p.startsWith("pds-")){let O=["pds-form","pds-drawer"].includes(p),T=y?.message?.includes("#pds/lit")||y?.message?.includes("Failed to resolve module specifier");O&&T?console.error(`\u274C PDS component <${p}> requires Lit but #pds/lit is not in import map.
|
|
2
|
-
See: https://github.com/Pure-Web-Foundation/pure-ds/blob/main/readme.md#lit-components-not-working`):console.warn(`\u26A0\uFE0F PDS component <${
|
|
1
|
+
var Ue=Object.defineProperty;var Ce=(e,t)=>{for(var n in t)Ue(e,n,{get:t[n],enumerable:!0})};var X=class{constructor(){this._mode="static",this._staticPaths={tokens:"/assets/pds/styles/pds-tokens.css.js",primitives:"/assets/pds/styles/pds-primitives.css.js",components:"/assets/pds/styles/pds-components.css.js",utilities:"/assets/pds/styles/pds-utilities.css.js",styles:"/assets/pds/styles/pds-styles.css.js"}}setLiveMode(){this._mode="live"}setStaticMode(t={}){this._mode="static",this._staticPaths={...this._staticPaths,...t}}async getStylesheet(t){if(this._mode==="live")return null;try{return(await import(this._staticPaths[t]))[t]}catch(n){console.error(`[PDS Registry] Failed to load static ${t}:`,n),console.error(`[PDS Registry] Looking for: ${this._staticPaths[t]}`),console.error("[PDS Registry] Make sure you've run 'npm run pds:build' and configured PDS.start() with the correct static.root path");let r=new CSSStyleSheet;return r.replaceSync("/* Failed to load "+t+" */"),r}}get mode(){return this._mode}get isLive(){return this._mode==="live"}},M=new X;async function fe(e,t=[],n=null){try{let r=n?.primitivesStylesheet?n.primitivesStylesheet:await M.getStylesheet("primitives");e.adoptedStyleSheets=[r,...t]}catch(r){let a=e.host?.tagName?.toLowerCase()||"unknown";console.error(`[PDS Adopter] <${a}> failed to adopt primitives:`,r),e.adoptedStyleSheets=t}}async function me(e,t=["primitives"],n=[],r=null){let a=Array.isArray(n)?n.filter(Boolean):[];if(a.length){let l=(Array.isArray(e.adoptedStyleSheets)?e.adoptedStyleSheets:[]).filter(y=>!a.includes(y));e.adoptedStyleSheets=[...l,...a]}try{let l=(await Promise.all(t.map(async y=>{if(r)switch(y){case"tokens":return r.tokensStylesheet;case"primitives":return r.primitivesStylesheet;case"components":return r.componentsStylesheet;case"utilities":return r.utilitiesStylesheet;default:break}return M.getStylesheet(y)}))).filter(y=>y!==null);e.adoptedStyleSheets=[...l,...a]}catch(o){let l=e.host?.tagName?.toLowerCase()||"unknown";console.error(`[PDS Adopter] <${l}> failed to adopt layers:`,o),e.adoptedStyleSheets=a}}function he(e){let t=new CSSStyleSheet;return t.replaceSync(e),t}var ye={FontWeights:{light:300,normal:400,medium:500,semibold:600,bold:700},LineHeights:{tight:1.25,normal:1.5,relaxed:1.75},BorderWidths:{hairline:.5,thin:1,medium:2,thick:3},RadiusSizes:{none:0,small:4,medium:8,large:16,xlarge:24,xxlarge:32},ShadowDepths:{none:"none",light:"0 1px 2px 0 rgba(0, 0, 0, 0.05)",medium:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)",deep:"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",extreme:"0 25px 50px -12px rgba(0, 0, 0, 0.25)"},TransitionSpeeds:{fast:150,normal:250,slow:350},AnimationEasings:{linear:"linear",ease:"ease","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out",bounce:"cubic-bezier(0.68, -0.55, 0.265, 1.55)"},TouchTargetSizes:{compact:36,standard:44,comfortable:48,spacious:56},LinkStyles:{inline:"inline",block:"block",button:"button"},FocusStyles:{ring:"ring",outline:"outline",border:"border",glow:"glow"},TabSizes:{compact:2,standard:4,wide:8},SelectIcons:{chevron:"chevron",arrow:"arrow",caret:"caret",none:"none"},IconSizes:{xs:16,sm:20,md:24,lg:32,xl:48,"2xl":64,"3xl":96}};var ee={};Ce(ee,{deepMerge:()=>we,fragmentFromTemplateLike:()=>je,isObject:()=>I,parseHTML:()=>Z});function I(e){return e&&typeof e=="object"&&!Array.isArray(e)}function we(e,t){let n={...e};return I(e)&&I(t)&&Object.keys(t).forEach(r=>{I(t[r])?r in e?n[r]=we(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}function je(e){let t=Array.isArray(e?.strings)?e.strings:[],n=Array.isArray(e?.values)?e.values:[],r=new Set,a=[],o=/(\s)(\.[\w-]+)=\s*$/;for(let i=0;i<t.length;i+=1){let S=t[i]??"",f=S.match(o);if(f&&i<n.length){let g=f[2].slice(1),L=`pds-val-${i}`;S=S.replace(o,`$1data-pds-prop="${g}:${L}"`),r.add(i)}a.push(S),i<n.length&&!r.has(i)&&a.push(`<!--pds-val-${i}-->`)}let l=document.createElement("template");l.innerHTML=a.join("");let y=(i,S)=>{let f=i.parentNode;if(!f)return;if(S==null){f.removeChild(i);return}let b=g=>{if(g!=null){if(g instanceof Node){f.insertBefore(g,i);return}if(Array.isArray(g)){g.forEach(L=>b(L));return}f.insertBefore(document.createTextNode(String(g)),i)}};b(S),f.removeChild(i)},E=document.createTreeWalker(l.content,NodeFilter.SHOW_COMMENT),h=[];for(;E.nextNode();){let i=E.currentNode;i?.nodeValue?.startsWith("pds-val-")&&h.push(i)}return h.forEach(i=>{let S=Number(i.nodeValue.replace("pds-val-",""));y(i,n[S])}),l.content.querySelectorAll("*").forEach(i=>{let S=i.getAttribute("data-pds-prop");if(!S)return;let[f,b]=S.split(":"),g=Number(String(b).replace("pds-val-",""));f&&Number.isInteger(g)&&(i[f]=n[g]),i.removeAttribute("data-pds-prop")}),l.content}function Z(e){return new DOMParser().parseFromString(e,"text/html").body.childNodes}var ge="pds",$e=/^([a-z][a-z0-9+\-.]*:)?\/\//i,Se=/^[a-z]:/i;function U(e=""){return e.endsWith("/")?e:`${e}/`}function Oe(e="",t=ge){let n=e.replace(/\/+$/,"");return new RegExp(`(?:^|/)${t}$`,"i").test(n)?n:`${n}/${t}`}function Ie(e){return e.replace(/^\.\/+/,"")}function Ne(e){return Se.test(e)?e.replace(Se,"").replace(/^\/+/,""):e}function ze(e){return e.startsWith("public/")?e.substring(7):e}function N(e,t={}){let n=t.segment||ge,r=t.defaultRoot||`/assets/${n}/`,a=e?.public&&e.public?.root||e?.static&&e.static?.root||null;if(!a||typeof a!="string")return U(r);let o=a.trim();return o?(o=o.replace(/\\/g,"/"),o=Oe(o,n),o=U(o),$e.test(o)?o:(o=Ie(o),o=Ne(o),o.startsWith("/")||(o=ze(o),o.startsWith("/")||(o=`/${o}`),o=o.replace(/\/+/g,(l,y)=>y===0?l:"/")),U(o))):U(r)}async function Fe(...e){let t={};e.length&&typeof e[e.length-1]=="object"&&(t=e.pop()||{});let n=e,{baseURL:r,mapper:a=h=>`${h}.js`,onError:o=(h,c)=>console.error(`[defineWebComponents] ${h}:`,c)}=t,l=r?new URL(r,typeof location<"u"?location.href:import.meta.url):new URL("./",import.meta.url),y=h=>h.toLowerCase().replace(/(^|-)([a-z])/g,(c,i,S)=>S.toUpperCase()),E=async h=>{try{if(customElements.get(h))return{tag:h,status:"already-defined"};let c=a(h),S=await import(c instanceof URL?c.href:new URL(c,l).href),f=S?.default??S?.[y(h)];if(!f){if(customElements.get(h))return{tag:h,status:"self-defined"};throw new Error(`No export found for ${h}. Expected default export or named export "${y(h)}".`)}return customElements.get(h)?{tag:h,status:"race-already-defined"}:(customElements.define(h,f),{tag:h,status:"defined"})}catch(c){throw o(h,c),c}};return Promise.all(n.map(E))}var z=class{constructor(t={}){let{baseURL:n,mapper:r,onError:a,predicate:o=()=>!0,attributeModule:l="data-module",root:y=document,scanExisting:E=!0,debounceMs:h=16,observeShadows:c=!0,enhancers:i=[],patchAttachShadow:S=!0}=t,f=new Set,b=new Set,g=new Set,L=new Map,x=new WeakMap,_=new WeakMap,m=0,w=!1,v=null,O=d=>{if(!d||!i.length)return;let p=_.get(d);p||(p=new Set,_.set(d,p));for(let u of i)if(!(!u.selector||!u.run)&&!p.has(u.selector))try{d.matches&&d.matches(u.selector)&&(u.run(d),p.add(u.selector))}catch(A){console.warn(`[AutoDefiner] Error applying enhancer for selector "${u.selector}":`,A)}},k=(d,p)=>{if(!w&&!(!d||!d.includes("-"))&&!customElements.get(d)&&!b.has(d)&&!g.has(d)){if(p&&p.getAttribute){let u=p.getAttribute(l);u&&!L.has(d)&&L.set(d,u)}f.add(d),ke()}},ke=()=>{m||(m=setTimeout(de,h))},D=d=>{if(d){if(d.nodeType===1){let p=d,u=p.tagName?.toLowerCase();u&&u.includes("-")&&!customElements.get(u)&&o(u,p)&&k(u,p),O(p),c&&p.shadowRoot&&J(p.shadowRoot)}d.querySelectorAll&&d.querySelectorAll("*").forEach(p=>{let u=p.tagName?.toLowerCase();u&&u.includes("-")&&!customElements.get(u)&&o(u,p)&&k(u,p),O(p),c&&p.shadowRoot&&J(p.shadowRoot)})}},J=d=>{if(!d||x.has(d))return;D(d);let p=new MutationObserver(u=>{for(let A of u)A.addedNodes?.forEach(P=>{D(P)}),A.type==="attributes"&&A.target&&D(A.target)});p.observe(d,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[l,...i.map(u=>u.selector).filter(u=>u.startsWith("data-"))]}),x.set(d,p)};async function de(){if(clearTimeout(m),m=0,!f.size)return;let d=Array.from(f);f.clear(),d.forEach(p=>b.add(p));try{let p=u=>L.get(u)??(r?r(u):`${u}.js`);await Fe(...d,{baseURL:n,mapper:p,onError:(u,A)=>{g.add(u),a?.(u,A)}})}catch{}finally{d.forEach(p=>b.delete(p))}}let ue=y===document?document.documentElement:y,pe=new MutationObserver(d=>{for(let p of d)p.addedNodes?.forEach(u=>{D(u)}),p.type==="attributes"&&p.target&&D(p.target)});if(pe.observe(ue,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[l,...i.map(d=>d.selector).filter(d=>d.startsWith("data-"))]}),c&&S&&Element.prototype.attachShadow){let d=Element.prototype.attachShadow;Element.prototype.attachShadow=function(u){let A=d.call(this,u);if(u&&u.mode==="open"){J(A);let P=this.tagName?.toLowerCase();P&&P.includes("-")&&!customElements.get(P)&&k(P,this)}return A},v=()=>Element.prototype.attachShadow=d}return E&&D(ue),{stop(){w=!0,pe.disconnect(),v&&v(),m&&(clearTimeout(m),m=0),x.forEach(d=>d.disconnect())},flush:de}}static async define(...t){let n={};t.length&&typeof t[t.length-1]=="object"&&(n=t.pop()||{});let r=t,{baseURL:a,mapper:o=c=>`${c}.js`,onError:l=(c,i)=>console.error(`[defineWebComponents] ${c}:`,i)}=n,y=a?new URL(a,typeof location<"u"?location.href:import.meta.url):new URL("./",import.meta.url),E=c=>c.toLowerCase().replace(/(^|-)([a-z])/g,(i,S,f)=>f.toUpperCase()),h=async c=>{try{if(customElements.get(c))return{tag:c,status:"already-defined"};let i=o(c),f=await import(i instanceof URL?i.href:new URL(i,y).href),b=f?.default??f?.[E(c)];if(!b){if(customElements.get(c))return{tag:c,status:"self-defined"};throw new Error(`No export found for ${c}. Expected default export or named export "${E(c)}".`)}return customElements.get(c)?{tag:c,status:"race-already-defined"}:(customElements.define(c,b),{tag:c,status:"defined"})}catch(i){throw l(c,i),i}};return Promise.all(r.map(h))}};var We=/^[a-z][a-z0-9+\-.]*:\/\//i,C=(()=>{try{return import.meta.url}catch{return}})(),F=e=>typeof e=="string"&&e.length&&!e.endsWith("/")?`${e}/`:e;function W(e,t={}){if(!e||We.test(e))return e;let{preferModule:n=!0}=t,r=()=>{if(!C)return null;try{return new URL(e,C).href}catch{return null}},a=()=>{if(typeof window>"u"||!window.location?.origin)return null;try{return new URL(e,window.location.origin).href}catch{return null}};return(n?r()||a():a()||r())||e}var Ee=(()=>{if(C)try{let e=new URL(C);if(/\/public\/assets\/js\//.test(e.pathname))return new URL("../pds/",C).href}catch{return}})(),be=!1;function _e(e){be||typeof document>"u"||(be=!0,e.addEventListener("pds:ready",t=>{let n=t.detail?.mode;n&&document.documentElement.classList.add(`pds-${n}`,"pds-ready")}))}function Le({manageTheme:e,themeStorageKey:t,applyResolvedTheme:n,setupSystemListenerIfNeeded:r}){let a="light",o=null;if(e&&typeof window<"u"){try{o=localStorage.getItem(t)||null}catch{o=null}try{n?.(o),r?.(o)}catch{}o?o==="system"?a=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":a=o:a=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}return{resolvedTheme:a,storedTheme:o}}function B(e,{resolvePublicAssetURL:t}){let n=!!(e?.public?.root||e?.static?.root),r=t(e);return!n&&Ee&&(r=Ee),F(W(r))}async function Ae(e,{baseEnhancers:t=[]}={}){let{autoDefineBaseURL:n="/auto-define/",autoDefinePreload:r=[],autoDefineMapper:a=null,enhancers:o=[],autoDefineOverrides:l=null,autoDefinePreferModule:y=!0}=e,E=(()=>{let c=new Map;return(t||[]).forEach(i=>c.set(i.selector,i)),(o||[]).forEach(i=>c.set(i.selector,i)),Array.from(c.values())})(),h=null;if(typeof window<"u"&&typeof document<"u"){let c=z,i=m=>{switch(m){case"pds-tabpanel":return"pds-tabstrip.js";default:return`${m}.js`}},{mapper:S,enhancers:f,...b}=l&&typeof l=="object"?l:{},g=f?Array.isArray(f)?f:typeof f=="object"?Object.values(f):[]:[],L=(()=>{let m=new Map;return(E||[]).forEach(w=>{w?.selector&&m.set(w.selector,w)}),(g||[]).forEach(w=>{if(!w?.selector)return;let v=m.get(w.selector)||null;m.set(w.selector,{...v||{},...w,run:typeof w?.run=="function"?w.run:v?.run})}),Array.from(m.values())})(),_={baseURL:n&&F(W(n,{preferModule:y})),predefine:r,scanExisting:!0,observeShadows:!0,patchAttachShadow:!0,debounceMs:16,enhancers:L,onError:(m,w)=>{if(typeof m=="string"&&m.startsWith("pds-")){let O=["pds-form","pds-drawer"].includes(m),k=w?.message?.includes("#pds/lit")||w?.message?.includes("Failed to resolve module specifier");O&&k?console.error(`\u274C PDS component <${m}> requires Lit but #pds/lit is not in import map.
|
|
2
|
+
See: https://github.com/Pure-Web-Foundation/pure-ds/blob/main/readme.md#lit-components-not-working`):console.warn(`\u26A0\uFE0F PDS component <${m}> not found. Assets may not be installed.`)}else console.error(`\u274C Auto-define error for <${m}>:`,w)},...b,mapper:m=>{if(customElements.get(m))return null;if(typeof a=="function")try{let w=a(m);return w===void 0?i(m):w}catch(w){return console.warn("Custom autoDefine.mapper error; falling back to default:",w?.message||w),i(m)}return i(m)}};h=new c(_),r.length>0&&typeof c.define=="function"&&await c.define(...r,{baseURL:n,mapper:_.mapper,onError:_.onError})}return{autoDefiner:h,mergedEnhancers:E}}var te=["light","dark"],ne=new Set(te);function Be(e){let n=(Array.isArray(e?.themes)?e.themes.map(r=>String(r).toLowerCase()):te).filter(r=>ne.has(r));return n.length?n:te}function re(e,{preferDocument:t=!0}={}){let n=String(e||"").toLowerCase();if(ne.has(n))return n;if(t&&typeof document<"u"){let r=document.documentElement?.getAttribute("data-theme");if(ne.has(r))return r}return typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function xe(e,t){let n=re(t);return Be(e).includes(n)}var ie=class extends EventTarget{},Re="__PURE_DS_PDS_SINGLETON__",ae=typeof globalThis<"u"?globalThis:window,se=ae?.[Re],s=se&&typeof se.addEventListener=="function"?se:new ie;ae&&(ae[Re]=s);typeof s.initializing!="boolean"&&(s.initializing=!1);"currentPreset"in s||(s.currentPreset=null);typeof s.debug!="boolean"&&(s.debug=!1);"currentConfig"in s||(s.currentConfig=null);"compiled"in s||(s.compiled=null);var q=null,V=null,H=null,G=null;function K(e,t){return t&&typeof t=="string"?t:`${B(s.currentConfig||{},{resolvePublicAssetURL:N})}core/${e}`}async function qe(){return Array.isArray(s.defaultEnhancers)&&s.defaultEnhancers.length>0?s.defaultEnhancers:(G||(G=import(K("pds-enhancers.js",s.currentConfig?.enhancersURL)).then(t=>{let n=Array.isArray(t?.defaultPDSEnhancers)?t.defaultPDSEnhancers:[];return s.defaultEnhancers=n,n}).catch(t=>{throw G=null,t})),G)}async function Ve(){return typeof s.ask=="function"&&s.ask!==De?s.ask:(V||(V=import(K("pds-ask.js",s.currentConfig?.askURL)).then(t=>{let n=t?.ask;if(typeof n!="function")throw new Error("Failed to load ask helper");return s.ask=n,n}).catch(t=>{throw V=null,t})),V)}async function $(){return typeof s.toast=="function"&&s.toast!==T?s.toast:(H||(H=import(K("pds-toast.js",s.currentConfig?.toastURL)).then(t=>{let n=t?.toast;if(typeof n!="function")throw new Error("Failed to load toast helper");return s.toast=n,n}).catch(t=>{throw H=null,t})),H)}async function De(...e){return(await Ve())(...e)}async function T(...e){return(await $())(...e)}T.success=async(...e)=>(await $()).success(...e);T.error=async(...e)=>(await $()).error(...e);T.warning=async(...e)=>(await $()).warning(...e);T.info=async(...e)=>(await $()).info(...e);var ve=function(e="log",t,...n){let r=!!(s.registry&&!s.registry.isLive),a=(this?.debug||this?.design?.debug||s.debug||!1)===!0;if(r){if(!s.debug)return}else if(!a&&e!=="error"&&e!=="warn")return;let o=console[e]||console.log;n.length>0?o(t,...n):o(t)};function ce(e){if(e==null)return e;if(typeof e=="function")return;if(typeof e!="object")return e;if(Array.isArray(e))return e.map(n=>ce(n)).filter(n=>n!==void 0);let t={};for(let[n,r]of Object.entries(e)){let a=ce(r);a!==void 0&&(t[n]=a)}return t}function Pe(e,t=new WeakSet){if(!e||typeof e!="object"||t.has(e))return e;t.add(e),Object.freeze(e);for(let n of Object.keys(e))Pe(e[n],t);return e}function le(e){return e==null||typeof e!="object"?e:Pe(structuredClone(ce(e)))}async function He(e,t={}){if(t?.runtimeConfig===!1||typeof fetch!="function")return null;let n=t?.runtimeConfigURL||`${e}pds-runtime-config.json`;try{let r=await fetch(n,{cache:"no-store"});return r.ok?await r.json():null}catch{return null}}s.registry=M;s.enums=ye;s.adoptLayers=me;s.adoptPrimitives=fe;s.parse=Z;s.createStylesheet=he;s.isLiveMode=()=>M.isLive;s.ask=De;s.toast=T;s.common=ee;s.AutoComplete=null;s.loadAutoComplete=async()=>{if(s.AutoComplete&&typeof s.AutoComplete.connect=="function")return s.AutoComplete;let e=K("pds-autocomplete.js",s.currentConfig?.autoCompleteURL);return q||(q=import(e).then(t=>{let n=t?.AutoComplete||t?.default?.AutoComplete||t?.default||null;if(!n)throw new Error("AutoComplete export not found in module");return s.AutoComplete=n,n}).catch(t=>{throw q=null,t})),q};function Me(e){let t=typeof CustomEvent=="function";try{let n=t?new CustomEvent("pds:ready",{detail:e}):new Event("pds:ready");s.dispatchEvent(n)}catch{}if(typeof document<"u")if(t){let n={detail:e,bubbles:!0,composed:!0};try{document.dispatchEvent(new CustomEvent("pds:ready",n))}catch{}try{document.dispatchEvent(new CustomEvent("pds-ready",n))}catch{}}else{try{document.dispatchEvent(new Event("pds:ready"))}catch{}try{document.dispatchEvent(new Event("pds-ready"))}catch{}}}function Te(e={}){let t=typeof CustomEvent=="function",n={at:Date.now(),...e};try{let r=t?new CustomEvent("pds:config-changed",{detail:n}):new Event("pds:config-changed");s.dispatchEvent(r)}catch{}if(typeof document<"u")if(t){let r={detail:n,bubbles:!0,composed:!0};try{document.dispatchEvent(new CustomEvent("pds:config-changed",r))}catch{}}else try{document.dispatchEvent(new Event("pds:config-changed"))}catch{}}var oe="pure-ds-theme",R=null,j=null;function Q(e){try{if(typeof document>"u")return;let t="light";e?e==="system"?t=typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t=e:t=typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",document.documentElement.setAttribute("data-theme",t)}catch{}}function Y(e){try{if(R&&j){try{typeof R.removeEventListener=="function"?R.removeEventListener("change",j):typeof R.removeListener=="function"&&R.removeListener(j)}catch{}R=null,j=null}if(e==="system"&&typeof window<"u"&&window.matchMedia){let t=window.matchMedia("(prefers-color-scheme: dark)"),n=r=>{let a=r?.matches===void 0?t.matches:r.matches;try{let o=a?"dark":"light";document.documentElement.setAttribute("data-theme",o),s.dispatchEvent(new CustomEvent("pds:theme:changed",{detail:{theme:o,source:"system"}}))}catch{}};R=t,j=n,typeof t.addEventListener=="function"?t.addEventListener("change",n):typeof t.addListener=="function"&&t.addListener(n)}}catch{}}var Ge=Object.getOwnPropertyDescriptor(s,"theme");Ge||Object.defineProperty(s,"theme",{get(){try{return typeof window>"u"?null:localStorage.getItem(oe)||null}catch{return null}},set(e){try{if(typeof window>"u")return;let t=s.currentConfig?.design||null,n=re(e);if(t&&!xe(t,n)){let r=t?.name||s.currentPreset?.name||s.currentConfig?.preset||"current preset";console.warn(`PDS theme "${n}" not supported by preset "${r}".`),s.dispatchEvent(new CustomEvent("pds:theme:blocked",{detail:{theme:e,resolvedTheme:n,preset:r}}));return}e==null?localStorage.removeItem(oe):localStorage.setItem(oe,e),Q(e),Y(e),s.dispatchEvent(new CustomEvent("pds:theme:changed",{detail:{theme:e,source:"api"}}))}catch{}}});s.defaultEnhancers=[];async function Ke(e){s.initializing=!0;try{let t=e&&e.mode||"live",{mode:n,...r}=e||{};s.currentConfig=le(r);let a;if(t==="static")a=await Qe(r);else{let l=B(r,{resolvePublicAssetURL:N}),y=r?.managerURL||r?.public?.managerURL||r?.manager?.url||new URL("core/pds-manager.js",l).href||new URL("./pds-manager.js",import.meta.url).href,{startLive:E}=await import(y);a=await E(s,r,{emitReady:Me,emitConfigChanged:Te,applyResolvedTheme:Q,setupSystemListenerIfNeeded:Y})}s.compiled=le(a?.config||null);let o=s?.compiled?.design?.icons?.externalPath||"/assets/img/icons/";return typeof console<"u"&&typeof console.info=="function"&&console.info(`[PDS] startup ready; external icon path: ${o}`),a}finally{s.initializing=!1}}s.start=Ke;async function Qe(e){if(!e||typeof e!="object")throw new Error("PDS.start({ mode: 'static', ... }) requires a valid configuration object");let t=e.applyGlobalStyles??!0,n=e.manageTheme??!0,r=e.themeStorageKey??"pure-ds-theme",a=e.staticPaths??{},o=B(e,{resolvePublicAssetURL:N}),l=e&&e.autoDefine||null,y;l&&l.baseURL?y=F(W(l.baseURL,{preferModule:!1})):y=`${o}components/`;let E=l&&Array.isArray(l.predefine)&&l.predefine||[],h=l&&typeof l.mapper=="function"&&l.mapper||null;try{_e(s);let{resolvedTheme:c}=Le({manageTheme:n,themeStorageKey:r,applyResolvedTheme:Q,setupSystemListenerIfNeeded:Y}),i=await He(o,e),S=Array.isArray(e?.enhancers)?e.enhancers:e?.enhancers&&typeof e.enhancers=="object"?Object.values(e.enhancers):[],f=i?.config?{...i.config,...e,design:e?.design||i.config.design,preset:e?.preset||i.config.preset}:{...e},b={tokens:`${o}styles/pds-tokens.css.js`,primitives:`${o}styles/pds-primitives.css.js`,components:`${o}styles/pds-components.css.js`,utilities:`${o}styles/pds-utilities.css.js`,styles:`${o}styles/pds-styles.css.js`},g=i?.paths||{};if(a={...b,...g,...a},s.registry.setStaticMode(a),t&&typeof document<"u")try{let _=await s.registry.getStylesheet("styles");if(_){_._pds=!0;let m=(document.adoptedStyleSheets||[]).filter(w=>w._pds!==!0);document.adoptedStyleSheets=[...m,_],Te({mode:"static",source:"static:styles-applied"})}}catch(_){ve.call(s,"warn","Failed to apply static styles:",_)}let L=null,x=[];try{let _=await qe(),m=await Ae({autoDefineBaseURL:y,autoDefinePreload:E,autoDefineMapper:h,enhancers:S,autoDefineOverrides:l||null,autoDefinePreferModule:!(l&&l.baseURL)},{baseEnhancers:_});L=m.autoDefiner,x=m.mergedEnhancers||[]}catch(_){ve.call(s,"error","\u274C Failed to initialize AutoDefiner/Enhancers (static):",_)}return s.compiled=le({mode:"static",...f,theme:c,enhancers:x}),Me({mode:"static",config:f,theme:c,autoDefiner:L}),{config:f,theme:c,autoDefiner:L}}catch(c){throw s.dispatchEvent(new CustomEvent("pds:error",{detail:{error:c}})),c}}var pt=Q,ft=Y;export{s as PDS,pt as applyResolvedTheme,ft as setupSystemListenerIfNeeded};
|
|
@@ -41,6 +41,31 @@ let __liveApiReady = false;
|
|
|
41
41
|
const LIVE_EDIT_TOGGLE_ID = "pds-live-edit-toggle";
|
|
42
42
|
const LIVE_EDIT_TOGGLE_STYLE_ID = "pds-live-edit-toggle-style";
|
|
43
43
|
|
|
44
|
+
function deepFreeze(value, seen = new WeakSet()) {
|
|
45
|
+
if (!value || typeof value !== "object") {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
if (seen.has(value)) {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
seen.add(value);
|
|
52
|
+
Object.freeze(value);
|
|
53
|
+
for (const key of Object.keys(value)) {
|
|
54
|
+
deepFreeze(value[key], seen);
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function toReadonlyClone(value) {
|
|
60
|
+
if (value === null || value === undefined) {
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
if (typeof value !== "object") {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
return deepFreeze(structuredClone(stripFunctions(value)));
|
|
67
|
+
}
|
|
68
|
+
|
|
44
69
|
function whenDocumentBodyReady(callback) {
|
|
45
70
|
if (typeof document === "undefined" || typeof callback !== "function") return;
|
|
46
71
|
if (document.body) {
|
|
@@ -772,10 +797,10 @@ async function __attachLiveAPIs(PDS, { applyResolvedTheme, setupSystemListenerIf
|
|
|
772
797
|
|
|
773
798
|
const presetInfo = normalized.presetInfo || { id: presetId, name: presetId };
|
|
774
799
|
PDS.currentPreset = presetInfo;
|
|
775
|
-
PDS.
|
|
800
|
+
PDS.compiled = toReadonlyClone({
|
|
776
801
|
...baseConfig,
|
|
777
802
|
preset: normalized.generatorConfig.preset,
|
|
778
|
-
design:
|
|
803
|
+
design: normalized.generatorConfig.design,
|
|
779
804
|
theme: normalized.generatorConfig.theme || baseConfig.theme,
|
|
780
805
|
});
|
|
781
806
|
PDS.configEditorMetadata = getDesignConfigEditorMetadata(
|
|
@@ -811,20 +836,6 @@ async function __attachLiveAPIs(PDS, { applyResolvedTheme, setupSystemListenerIf
|
|
|
811
836
|
return true;
|
|
812
837
|
};
|
|
813
838
|
|
|
814
|
-
// Live-only compiled getter
|
|
815
|
-
if (!Object.getOwnPropertyDescriptor(PDS, "compiled")) {
|
|
816
|
-
Object.defineProperty(PDS, "compiled", {
|
|
817
|
-
get() {
|
|
818
|
-
if (PDS.registry?.isLive && Generator.instance) {
|
|
819
|
-
return Generator.instance.compiled;
|
|
820
|
-
}
|
|
821
|
-
return null;
|
|
822
|
-
},
|
|
823
|
-
enumerable: true,
|
|
824
|
-
configurable: false,
|
|
825
|
-
});
|
|
826
|
-
}
|
|
827
|
-
|
|
828
839
|
// Live-only preload helper
|
|
829
840
|
PDS.preloadCritical = function(config, options = {}) {
|
|
830
841
|
if (typeof window === "undefined" || !document.head || !config) {
|
|
@@ -885,8 +896,33 @@ export async function startLive(PDS, config, { emitReady, emitConfigChanged, app
|
|
|
885
896
|
);
|
|
886
897
|
}
|
|
887
898
|
|
|
899
|
+
const explicitExternalIconPath =
|
|
900
|
+
config?.design?.icons?.externalPath ||
|
|
901
|
+
config?.icons?.externalPath ||
|
|
902
|
+
null;
|
|
903
|
+
|
|
888
904
|
config = applyStoredConfigOverrides(config);
|
|
889
905
|
|
|
906
|
+
if (typeof explicitExternalIconPath === "string" && explicitExternalIconPath.trim()) {
|
|
907
|
+
const baseDesign =
|
|
908
|
+
config?.design && typeof config.design === "object" ? config.design : {};
|
|
909
|
+
const baseIcons =
|
|
910
|
+
baseDesign?.icons && typeof baseDesign.icons === "object"
|
|
911
|
+
? baseDesign.icons
|
|
912
|
+
: {};
|
|
913
|
+
|
|
914
|
+
config = {
|
|
915
|
+
...config,
|
|
916
|
+
design: {
|
|
917
|
+
...baseDesign,
|
|
918
|
+
icons: {
|
|
919
|
+
...baseIcons,
|
|
920
|
+
externalPath: explicitExternalIconPath,
|
|
921
|
+
},
|
|
922
|
+
},
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
|
|
890
926
|
// Attach live-only API surface (ontology, presets, query, etc.)
|
|
891
927
|
await __attachLiveAPIs(PDS, { applyResolvedTheme, setupSystemListenerIfNeeded, emitConfigChanged });
|
|
892
928
|
attachFoucListener(PDS);
|
|
@@ -1090,12 +1126,9 @@ export async function startLive(PDS, config, { emitReady, emitConfigChanged, app
|
|
|
1090
1126
|
|
|
1091
1127
|
const resolvedConfig = generator?.options || generatorConfig;
|
|
1092
1128
|
|
|
1093
|
-
|
|
1094
|
-
PDS.currentConfig = Object.freeze({
|
|
1129
|
+
PDS.compiled = toReadonlyClone({
|
|
1095
1130
|
mode: "live",
|
|
1096
|
-
...
|
|
1097
|
-
design: structuredClone(normalized.generatorConfig.design),
|
|
1098
|
-
preset: normalized.generatorConfig.preset,
|
|
1131
|
+
...resolvedConfig,
|
|
1099
1132
|
theme: resolvedTheme,
|
|
1100
1133
|
enhancers: mergedEnhancers,
|
|
1101
1134
|
});
|
package/src/js/pds.d.ts
CHANGED
|
@@ -279,14 +279,14 @@ export class PDS extends EventTarget {
|
|
|
279
279
|
* Current configuration after PDS.start() completes - read-only, frozen after initialization.
|
|
280
280
|
* Contains the complete configuration used to initialize PDS, including mode, design, preset, and theme.
|
|
281
281
|
*/
|
|
282
|
-
static readonly currentConfig: any;
|
|
282
|
+
static readonly currentConfig: any | null;
|
|
283
283
|
|
|
284
284
|
/**
|
|
285
285
|
* Compiled design system state - provides structured access to all generated tokens,
|
|
286
286
|
* layers, and metadata. Available in live mode when a generator is active.
|
|
287
287
|
* Returns null if not in live mode or if no generator is present.
|
|
288
288
|
*/
|
|
289
|
-
static readonly compiled
|
|
289
|
+
static readonly compiled: CompiledState | Record<string, any> | null;
|
|
290
290
|
|
|
291
291
|
// Static EventTarget-like facade for default instance
|
|
292
292
|
static addEventListener<K extends keyof PDSEventMap>(type: K, listener: (ev: PDSEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
package/src/js/pds.js
CHANGED
|
@@ -37,12 +37,34 @@
|
|
|
37
37
|
*/
|
|
38
38
|
class PDSBase extends EventTarget {}
|
|
39
39
|
/** @type {PDSAPI & PDSBase} */
|
|
40
|
-
const
|
|
40
|
+
const __PDS_SINGLETON_KEY__ = "__PURE_DS_PDS_SINGLETON__";
|
|
41
|
+
const __globalScope__ = typeof globalThis !== "undefined" ? globalThis : window;
|
|
42
|
+
const __existingPDS__ = __globalScope__?.[__PDS_SINGLETON_KEY__];
|
|
43
|
+
const PDS =
|
|
44
|
+
__existingPDS__ && typeof __existingPDS__.addEventListener === "function"
|
|
45
|
+
? __existingPDS__
|
|
46
|
+
: new PDSBase();
|
|
47
|
+
|
|
48
|
+
if (__globalScope__) {
|
|
49
|
+
__globalScope__[__PDS_SINGLETON_KEY__] = PDS;
|
|
50
|
+
}
|
|
41
51
|
|
|
42
52
|
// State properties
|
|
43
|
-
PDS.initializing
|
|
44
|
-
PDS.
|
|
45
|
-
|
|
53
|
+
if (typeof PDS.initializing !== "boolean") {
|
|
54
|
+
PDS.initializing = false;
|
|
55
|
+
}
|
|
56
|
+
if (!("currentPreset" in PDS)) {
|
|
57
|
+
PDS.currentPreset = null;
|
|
58
|
+
}
|
|
59
|
+
if (typeof PDS.debug !== "boolean") {
|
|
60
|
+
PDS.debug = false;
|
|
61
|
+
}
|
|
62
|
+
if (!("currentConfig" in PDS)) {
|
|
63
|
+
PDS.currentConfig = null;
|
|
64
|
+
}
|
|
65
|
+
if (!("compiled" in PDS)) {
|
|
66
|
+
PDS.compiled = null;
|
|
67
|
+
}
|
|
46
68
|
|
|
47
69
|
import {
|
|
48
70
|
adoptLayers,
|
|
@@ -225,6 +247,31 @@ function __stripFunctionsForClone(value) {
|
|
|
225
247
|
return result;
|
|
226
248
|
}
|
|
227
249
|
|
|
250
|
+
function __deepFreeze(value, seen = new WeakSet()) {
|
|
251
|
+
if (!value || typeof value !== "object") {
|
|
252
|
+
return value;
|
|
253
|
+
}
|
|
254
|
+
if (seen.has(value)) {
|
|
255
|
+
return value;
|
|
256
|
+
}
|
|
257
|
+
seen.add(value);
|
|
258
|
+
Object.freeze(value);
|
|
259
|
+
for (const key of Object.keys(value)) {
|
|
260
|
+
__deepFreeze(value[key], seen);
|
|
261
|
+
}
|
|
262
|
+
return value;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function __toReadonlyClone(value) {
|
|
266
|
+
if (value === null || value === undefined) {
|
|
267
|
+
return value;
|
|
268
|
+
}
|
|
269
|
+
if (typeof value !== "object") {
|
|
270
|
+
return value;
|
|
271
|
+
}
|
|
272
|
+
return __deepFreeze(structuredClone(__stripFunctionsForClone(value)));
|
|
273
|
+
}
|
|
274
|
+
|
|
228
275
|
async function __loadRuntimeConfig(assetRootURL, config = {}) {
|
|
229
276
|
if (config?.runtimeConfig === false) return null;
|
|
230
277
|
if (typeof fetch !== "function") return null;
|
|
@@ -435,56 +482,59 @@ function __setupSystemListenerIfNeeded(raw) {
|
|
|
435
482
|
} catch (e) {}
|
|
436
483
|
}
|
|
437
484
|
|
|
438
|
-
Object.
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
set(value) {
|
|
448
|
-
try {
|
|
449
|
-
if (typeof window === "undefined") return;
|
|
450
|
-
const currentPreset = PDS.currentConfig?.design || null;
|
|
451
|
-
const resolvedTheme = resolveThemePreference(value);
|
|
452
|
-
if (currentPreset && !isPresetThemeCompatible(currentPreset, resolvedTheme)) {
|
|
453
|
-
const presetName =
|
|
454
|
-
currentPreset?.name ||
|
|
455
|
-
PDS.currentPreset?.name ||
|
|
456
|
-
PDS.currentConfig?.preset ||
|
|
457
|
-
"current preset";
|
|
458
|
-
console.warn(
|
|
459
|
-
`PDS theme "${resolvedTheme}" not supported by preset "${presetName}".`
|
|
460
|
-
);
|
|
461
|
-
PDS.dispatchEvent(
|
|
462
|
-
new CustomEvent("pds:theme:blocked", {
|
|
463
|
-
detail: { theme: value, resolvedTheme, preset: presetName },
|
|
464
|
-
})
|
|
465
|
-
);
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
if (value === null || value === undefined) {
|
|
469
|
-
localStorage.removeItem(__themeStorageKey);
|
|
470
|
-
} else {
|
|
471
|
-
localStorage.setItem(__themeStorageKey, value);
|
|
485
|
+
const __themeDescriptor = Object.getOwnPropertyDescriptor(PDS, "theme");
|
|
486
|
+
if (!__themeDescriptor) {
|
|
487
|
+
Object.defineProperty(PDS, "theme", {
|
|
488
|
+
get() {
|
|
489
|
+
try {
|
|
490
|
+
if (typeof window === "undefined") return null;
|
|
491
|
+
return localStorage.getItem(__themeStorageKey) || null;
|
|
492
|
+
} catch (e) {
|
|
493
|
+
return null;
|
|
472
494
|
}
|
|
495
|
+
},
|
|
496
|
+
set(value) {
|
|
497
|
+
try {
|
|
498
|
+
if (typeof window === "undefined") return;
|
|
499
|
+
const currentPreset = PDS.currentConfig?.design || null;
|
|
500
|
+
const resolvedTheme = resolveThemePreference(value);
|
|
501
|
+
if (currentPreset && !isPresetThemeCompatible(currentPreset, resolvedTheme)) {
|
|
502
|
+
const presetName =
|
|
503
|
+
currentPreset?.name ||
|
|
504
|
+
PDS.currentPreset?.name ||
|
|
505
|
+
PDS.currentConfig?.preset ||
|
|
506
|
+
"current preset";
|
|
507
|
+
console.warn(
|
|
508
|
+
`PDS theme "${resolvedTheme}" not supported by preset "${presetName}".`
|
|
509
|
+
);
|
|
510
|
+
PDS.dispatchEvent(
|
|
511
|
+
new CustomEvent("pds:theme:blocked", {
|
|
512
|
+
detail: { theme: value, resolvedTheme, preset: presetName },
|
|
513
|
+
})
|
|
514
|
+
);
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
if (value === null || value === undefined) {
|
|
518
|
+
localStorage.removeItem(__themeStorageKey);
|
|
519
|
+
} else {
|
|
520
|
+
localStorage.setItem(__themeStorageKey, value);
|
|
521
|
+
}
|
|
473
522
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
523
|
+
// Apply resolved (light/dark) value to document
|
|
524
|
+
__applyResolvedTheme(value);
|
|
525
|
+
// Setup system change listener only when 'system' is selected
|
|
526
|
+
__setupSystemListenerIfNeeded(value);
|
|
478
527
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
});
|
|
528
|
+
// Emit a notification with the raw preference (value may be 'system')
|
|
529
|
+
PDS.dispatchEvent(
|
|
530
|
+
new CustomEvent("pds:theme:changed", {
|
|
531
|
+
detail: { theme: value, source: "api" },
|
|
532
|
+
})
|
|
533
|
+
);
|
|
534
|
+
} catch (e) {}
|
|
535
|
+
},
|
|
536
|
+
});
|
|
537
|
+
}
|
|
488
538
|
|
|
489
539
|
// ----------------------------------------------------------------------------
|
|
490
540
|
// Default Enhancers — first-class citizens alongside AutoDefiner
|
|
@@ -538,24 +588,45 @@ PDS.defaultEnhancers = [];
|
|
|
538
588
|
* @returns {Promise<any>} Live returns { generator, config, theme, autoDefiner }; Static returns { config, theme, autoDefiner }
|
|
539
589
|
*/
|
|
540
590
|
async function start(config) {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
591
|
+
PDS.initializing = true;
|
|
592
|
+
try {
|
|
593
|
+
const mode = (config && config.mode) || "live";
|
|
594
|
+
const { mode: _omit, ...rest } = config || {};
|
|
595
|
+
PDS.currentConfig = __toReadonlyClone(rest);
|
|
596
|
+
|
|
597
|
+
let startResult;
|
|
598
|
+
if (mode === "static") {
|
|
599
|
+
startResult = await staticInit(rest);
|
|
600
|
+
} else {
|
|
601
|
+
const assetRootURL = resolveRuntimeAssetRoot(rest, { resolvePublicAssetURL });
|
|
602
|
+
const managerUrl =
|
|
603
|
+
rest?.managerURL ||
|
|
604
|
+
rest?.public?.managerURL ||
|
|
605
|
+
rest?.manager?.url ||
|
|
606
|
+
new URL("core/pds-manager.js", assetRootURL).href ||
|
|
607
|
+
new URL("./pds-manager.js", import.meta.url).href;
|
|
608
|
+
const { startLive } = await import(managerUrl);
|
|
609
|
+
startResult = await startLive(PDS, rest, {
|
|
610
|
+
emitReady: __emitPDSReady,
|
|
611
|
+
emitConfigChanged: __emitPDSConfigChanged,
|
|
612
|
+
applyResolvedTheme: __applyResolvedTheme,
|
|
613
|
+
setupSystemListenerIfNeeded: __setupSystemListenerIfNeeded,
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
PDS.compiled = __toReadonlyClone(startResult?.config || null);
|
|
618
|
+
|
|
619
|
+
const resolvedExternalIconPath =
|
|
620
|
+
PDS?.compiled?.design?.icons?.externalPath || "/assets/img/icons/";
|
|
621
|
+
|
|
622
|
+
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
623
|
+
console.info(`[PDS] startup ready; external icon path: ${resolvedExternalIconPath}`);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
return startResult;
|
|
627
|
+
} finally {
|
|
628
|
+
PDS.initializing = false;
|
|
629
|
+
}
|
|
559
630
|
}
|
|
560
631
|
|
|
561
632
|
/** Primary unified entry point */
|
|
@@ -695,14 +766,9 @@ async function staticInit(config) {
|
|
|
695
766
|
);
|
|
696
767
|
}
|
|
697
768
|
|
|
698
|
-
|
|
699
|
-
// Strip functions before cloning to avoid DataCloneError
|
|
700
|
-
const cloneableConfig = __stripFunctionsForClone(config);
|
|
701
|
-
PDS.currentConfig = Object.freeze({
|
|
769
|
+
PDS.compiled = __toReadonlyClone({
|
|
702
770
|
mode: "static",
|
|
703
|
-
...
|
|
704
|
-
design: structuredClone(resolvedConfig.design || {}),
|
|
705
|
-
preset: resolvedConfig.preset,
|
|
771
|
+
...resolvedConfig,
|
|
706
772
|
theme: resolvedTheme,
|
|
707
773
|
enhancers: mergedEnhancers,
|
|
708
774
|
});
|