@pure-ds/core 0.7.21 → 0.7.22
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/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/package.json +1 -1
- package/public/assets/js/app.js +4 -4
- package/public/assets/js/pds-manager.js +25 -25
- package/public/assets/js/pds.js +2 -2
- package/public/assets/pds/components/pds-icon.js +86 -15
- package/public/assets/pds/core/pds-manager.js +25 -25
- package/public/assets/pds/core.js +2 -2
- package/src/js/pds-core/pds-live.js +25 -0
- package/src/js/pds.js +42 -18
package/public/assets/js/pds.js
CHANGED
|
@@ -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 <${p}> not found. Assets may not be installed.`)}else console.error(`\u274C Auto-define error for <${p}>:`,y)},...
|
|
1
|
+
var Pe=Object.defineProperty;var De=(e,t)=>{for(var n in t)Pe(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 i=e.host?.tagName?.toLowerCase()||"unknown";console.error(`[PDS Adopter] <${i}> failed to adopt primitives:`,r),e.adoptedStyleSheets=t}}async function ue(e,t=["primitives"],n=[],r=null){let i=Array.isArray(n)?n.filter(Boolean):[];if(i.length){let l=(Array.isArray(e.adoptedStyleSheets)?e.adoptedStyleSheets:[]).filter(w=>!i.includes(w));e.adoptedStyleSheets=[...l,...i]}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,...i]}catch(s){let l=e.host?.tagName?.toLowerCase()||"unknown";console.error(`[PDS Adopter] <${l}> failed to adopt layers:`,s),e.adoptedStyleSheets=i}}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={};De(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,i=[],s=/(\s)(\.[\w-]+)=\s*$/;for(let a=0;a<t.length;a+=1){let g=t[a]??"",m=g.match(s);if(m&&a<n.length){let S=m[2].slice(1),L=`pds-val-${a}`;g=g.replace(s,`$1data-pds-prop="${S}:${L}"`),r.add(a)}i.push(g),a<n.length&&!r.has(a)&&i.push(`<!--pds-val-${a}-->`)}let l=document.createElement("template");l.innerHTML=i.join("");let w=(a,g)=>{let m=a.parentNode;if(!m)return;if(g==null){m.removeChild(a);return}let b=S=>{if(S!=null){if(S instanceof Node){m.insertBefore(S,a);return}if(Array.isArray(S)){S.forEach(L=>b(L));return}m.insertBefore(document.createTextNode(String(S)),a)}};b(g),m.removeChild(a)},E=document.createTreeWalker(l.content,NodeFilter.SHOW_COMMENT),h=[];for(;E.nextNode();){let a=E.currentNode;a?.nodeValue?.startsWith("pds-val-")&&h.push(a)}return h.forEach(a=>{let g=Number(a.nodeValue.replace("pds-val-",""));w(a,n[g])}),l.content.querySelectorAll("*").forEach(a=>{let g=a.getAttribute("data-pds-prop");if(!g)return;let[m,b]=g.split(":"),S=Number(String(b).replace("pds-val-",""));m&&Number.isInteger(S)&&(a[m]=n[S]),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 C(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 Ce(e){return e.replace(/^\.\/+/,"")}function Ue(e){return he.test(e)?e.replace(he,"").replace(/^\/+/,""):e}function $e(e){return e.startsWith("public/")?e.substring(7):e}function N(e,t={}){let n=t.segment||ye,r=t.defaultRoot||`/assets/${n}/`,i=e?.public&&e.public?.root||e?.static&&e.static?.root||null;if(!i||typeof i!="string")return C(r);let s=i.trim();return s?(s=s.replace(/\\/g,"/"),s=Te(s,n),s=C(s),ke.test(s)?s:(s=Ce(s),s=Ue(s),s.startsWith("/")||(s=$e(s),s.startsWith("/")||(s=`/${s}`),s=s.replace(/\/+/g,(l,w)=>w===0?l:"/")),C(s))):C(r)}async function je(...e){let t={};e.length&&typeof e[e.length-1]=="object"&&(t=e.pop()||{});let n=e,{baseURL:r,mapper:i=h=>`${h}.js`,onError:s=(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),w=h=>h.toLowerCase().replace(/(^|-)([a-z])/g,(c,a,g)=>g.toUpperCase()),E=async h=>{try{if(customElements.get(h))return{tag:h,status:"already-defined"};let c=i(h),g=await import(c instanceof URL?c.href:new URL(c,l).href),m=g?.default??g?.[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(c){throw s(h,c),c}};return Promise.all(n.map(E))}var z=class{constructor(t={}){let{baseURL:n,mapper:r,onError:i,predicate:s=()=>!0,attributeModule:l="data-module",root:w=document,scanExisting:E=!0,debounceMs:h=16,observeShadows:c=!0,enhancers:a=[],patchAttachShadow:g=!0}=t,m=new Set,b=new Set,S=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)&&!b.has(d)&&!S.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))},P=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),c&&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),c&&f.shadowRoot&&X(f.shadowRoot)})}},X=d=>{if(!d||x.has(d))return;P(d);let f=new MutationObserver(u=>{for(let A of u)A.addedNodes?.forEach(D=>{P(D)}),A.type==="attributes"&&A.target&&P(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=>b.add(f));try{let f=u=>L.get(u)??(r?r(u):`${u}.js`);await je(...d,{baseURL:n,mapper:f,onError:(u,A)=>{S.add(u),i?.(u,A)}})}catch{}finally{d.forEach(f=>b.delete(f))}}let ce=w===document?document.documentElement:w,le=new MutationObserver(d=>{for(let f of d)f.addedNodes?.forEach(u=>{P(u)}),f.type==="attributes"&&f.target&&P(f.target)});if(le.observe(ce,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[l,...a.map(d=>d.selector).filter(d=>d.startsWith("data-"))]}),c&&g&&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 D=this.tagName?.toLowerCase();D&&D.includes("-")&&!customElements.get(D)&&T(D,this)}return A},v=()=>Element.prototype.attachShadow=d}return E&&P(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:i,mapper:s=c=>`${c}.js`,onError:l=(c,a)=>console.error(`[defineWebComponents] ${c}:`,a)}=n,w=i?new URL(i,typeof location<"u"?location.href:import.meta.url):new URL("./",import.meta.url),E=c=>c.toLowerCase().replace(/(^|-)([a-z])/g,(a,g,m)=>m.toUpperCase()),h=async c=>{try{if(customElements.get(c))return{tag:c,status:"already-defined"};let a=s(c),m=await import(a instanceof URL?a.href:new URL(a,w).href),b=m?.default??m?.[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(a){throw l(c,a),a}};return Promise.all(r.map(h))}};var Oe=/^[a-z][a-z0-9+\-.]*:\/\//i,U=(()=>{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(!U)return null;try{return new URL(e,U).href}catch{return null}},i=()=>{if(typeof window>"u"||!window.location?.origin)return null;try{return new URL(e,window.location.origin).href}catch{return null}};return(n?r()||i():i()||r())||e}var we=(()=>{if(U)try{let e=new URL(U);if(/\/public\/assets\/js\//.test(e.pathname))return new URL("../pds/",U).href}catch{return}})(),ge=!1;function Se(e){ge||typeof document>"u"||(ge=!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 i="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"?i=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":i=s:i=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}return{resolvedTheme:i,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:i=null,enhancers:s=[],autoDefineOverrides:l=null,autoDefinePreferModule:w=!0}=e,E=(()=>{let c=new Map;return(t||[]).forEach(a=>c.set(a.selector,a)),(s||[]).forEach(a=>c.set(a.selector,a)),Array.from(c.values())})(),h=null;if(typeof window<"u"&&typeof document<"u"){let c=z,a=p=>{switch(p){case"pds-tabpanel":return"pds-tabstrip.js";default:return`${p}.js`}},{mapper:g,enhancers:m,...b}=l&&typeof l=="object"?l:{},S=m?Array.isArray(m)?m:typeof m=="object"?Object.values(m):[]:[],L=(()=>{let p=new Map;return(E||[]).forEach(y=>{y?.selector&&p.set(y.selector,y)}),(S||[]).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 <${p}> not found. Assets may not be installed.`)}else console.error(`\u274C Auto-define error for <${p}>:`,y)},...b,mapper:p=>{if(customElements.get(p))return null;if(typeof i=="function")try{let y=i(p);return y===void 0?a(p):y}catch(y){return console.warn("Custom autoDefine.mapper error; falling back to default:",y?.message||y),a(p)}return a(p)}};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 Ie(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 Le(e,t){let n=re(t);return Ie(e).includes(n)}var oe=class extends EventTarget{},o=new oe;o.initializing=!1;o.currentPreset=null;o.debug=!1;var q=null,V=null,H=null,K=null;function G(e,t){return t&&typeof t=="string"?t:`${B(o.currentConfig||{},{resolvePublicAssetURL:N})}core/${e}`}async function Ne(){return Array.isArray(o.defaultEnhancers)&&o.defaultEnhancers.length>0?o.defaultEnhancers:(K||(K=import(G("pds-enhancers.js",o.currentConfig?.enhancersURL)).then(t=>{let n=Array.isArray(t?.defaultPDSEnhancers)?t.defaultPDSEnhancers:[];return o.defaultEnhancers=n,n}).catch(t=>{throw K=null,t})),K)}async function ze(){return typeof o.ask=="function"&&o.ask!==ve?o.ask:(V||(V=import(G("pds-ask.js",o.currentConfig?.askURL)).then(t=>{let n=t?.ask;if(typeof n!="function")throw new Error("Failed to load ask helper");return o.ask=n,n}).catch(t=>{throw V=null,t})),V)}async function j(){return typeof o.toast=="function"&&o.toast!==k?o.toast:(H||(H=import(G("pds-toast.js",o.currentConfig?.toastURL)).then(t=>{let n=t?.toast;if(typeof n!="function")throw new Error("Failed to load toast helper");return o.toast=n,n}).catch(t=>{throw H=null,t})),H)}async function ve(...e){return(await ze())(...e)}async function k(...e){return(await j())(...e)}k.success=async(...e)=>(await j()).success(...e);k.error=async(...e)=>(await j()).error(...e);k.warning=async(...e)=>(await j()).warning(...e);k.info=async(...e)=>(await j()).info(...e);var Ae=function(e="log",t,...n){let r=!!(o.registry&&!o.registry.isLive),i=(this?.debug||this?.design?.debug||o.debug||!1)===!0;if(r){if(!o.debug)return}else if(!i&&e!=="error"&&e!=="warn")return;let s=console[e]||console.log;n.length>0?s(t,...n):s(t)};function ae(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=>ae(n)).filter(n=>n!==void 0);let t={};for(let[n,r]of Object.entries(e)){let i=ae(r);i!==void 0&&(t[n]=i)}return t}async function Fe(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}}o.registry=M;o.enums=fe;o.adoptLayers=ue;o.adoptPrimitives=de;o.parse=Z;o.createStylesheet=pe;o.isLiveMode=()=>M.isLive;o.ask=ve;o.toast=k;o.common=ee;o.AutoComplete=null;o.loadAutoComplete=async()=>{if(o.AutoComplete&&typeof o.AutoComplete.connect=="function")return o.AutoComplete;let e=G("pds-autocomplete.js",o.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 o.AutoComplete=n,n}).catch(t=>{throw q=null,t})),q};function _e(e){let t=typeof CustomEvent=="function";try{let n=t?new CustomEvent("pds:ready",{detail:e}):new Event("pds:ready");o.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 xe(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");o.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 se="pure-ds-theme",R=null,$=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 J(e){try{if(R&&$){try{typeof R.removeEventListener=="function"?R.removeEventListener("change",$):typeof R.removeListener=="function"&&R.removeListener($)}catch{}R=null,$=null}if(e==="system"&&typeof window<"u"&&window.matchMedia){let t=window.matchMedia("(prefers-color-scheme: dark)"),n=r=>{let i=r?.matches===void 0?t.matches:r.matches;try{let s=i?"dark":"light";document.documentElement.setAttribute("data-theme",s),o.dispatchEvent(new CustomEvent("pds:theme:changed",{detail:{theme:s,source:"system"}}))}catch{}};R=t,$=n,typeof t.addEventListener=="function"?t.addEventListener("change",n):typeof t.addListener=="function"&&t.addListener(n)}}catch{}}Object.defineProperty(o,"theme",{get(){try{return typeof window>"u"?null:localStorage.getItem(se)||null}catch{return null}},set(e){try{if(typeof window>"u")return;let t=o.currentConfig?.design||null,n=re(e);if(t&&!Le(t,n)){let r=t?.name||o.currentPreset?.name||o.currentConfig?.preset||"current preset";console.warn(`PDS theme "${n}" not supported by preset "${r}".`),o.dispatchEvent(new CustomEvent("pds:theme:blocked",{detail:{theme:e,resolvedTheme:n,preset:r}}));return}e==null?localStorage.removeItem(se):localStorage.setItem(se,e),Q(e),J(e),o.dispatchEvent(new CustomEvent("pds:theme:changed",{detail:{theme:e,source:"api"}}))}catch{}}});o.defaultEnhancers=[];async function We(e){o.initializing=!0;try{let t=e&&e.mode||"live",{mode:n,...r}=e||{},i;if(t==="static")i=await Be(r);else{let l=B(r,{resolvePublicAssetURL:N}),w=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(w);i=await E(o,r,{emitReady:_e,emitConfigChanged:xe,applyResolvedTheme:Q,setupSystemListenerIfNeeded:J})}let s=o?.currentConfig?.design?.icons?.externalPath||o?.currentConfig?.icons?.externalPath||i?.config?.design?.icons?.externalPath||i?.config?.icons?.externalPath||"/assets/img/icons/";return o.externalIconPath=s,typeof console<"u"&&typeof console.info=="function"&&console.info(`[PDS] startup ready; external icon path: ${s}`),i}finally{o.initializing=!1}}o.start=We;async function Be(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",i=e.staticPaths??{},s=B(e,{resolvePublicAssetURL:N}),l=e&&e.autoDefine||null,w;l&&l.baseURL?w=F(W(l.baseURL,{preferModule:!1})):w=`${s}components/`;let E=l&&Array.isArray(l.predefine)&&l.predefine||[],h=l&&typeof l.mapper=="function"&&l.mapper||null;try{Se(o);let{resolvedTheme:c}=Ee({manageTheme:n,themeStorageKey:r,applyResolvedTheme:Q,setupSystemListenerIfNeeded:J}),a=await Fe(s,e),g=Array.isArray(e?.enhancers)?e.enhancers:e?.enhancers&&typeof e.enhancers=="object"?Object.values(e.enhancers):[],m=a?.config?{...a.config,...e,design:e?.design||a.config.design,preset:e?.preset||a.config.preset}:{...e},b={tokens:`${s}styles/pds-tokens.css.js`,primitives:`${s}styles/pds-primitives.css.js`,components:`${s}styles/pds-components.css.js`,utilities:`${s}styles/pds-utilities.css.js`,styles:`${s}styles/pds-styles.css.js`},S=a?.paths||{};if(i={...b,...S,...i},o.registry.setStaticMode(i),t&&typeof document<"u")try{let p=await o.registry.getStylesheet("styles");if(p){p._pds=!0;let y=(document.adoptedStyleSheets||[]).filter(v=>v._pds!==!0);document.adoptedStyleSheets=[...y,p],xe({mode:"static",source:"static:styles-applied"})}}catch(p){Ae.call(o,"warn","Failed to apply static styles:",p)}let L=null,x=[];try{let p=await Ne(),y=await be({autoDefineBaseURL:w,autoDefinePreload:E,autoDefineMapper:h,enhancers:g,autoDefineOverrides:l||null,autoDefinePreferModule:!(l&&l.baseURL)},{baseEnhancers:p});L=y.autoDefiner,x=y.mergedEnhancers||[]}catch(p){Ae.call(o,"error","\u274C Failed to initialize AutoDefiner/Enhancers (static):",p)}let _=ae(e);return o.currentConfig=Object.freeze({mode:"static",...structuredClone(_),design:structuredClone(m.design||{}),preset:m.preset,theme:c,enhancers:x}),_e({mode:"static",config:m,theme:c,autoDefiner:L}),{config:m,theme:c,autoDefiner:L}}catch(c){throw o.dispatchEvent(new CustomEvent("pds:error",{detail:{error:c}})),c}}var at=Q,it=J;export{o as PDS,at as applyResolvedTheme,it as setupSystemListenerIfNeeded};
|
|
@@ -23,6 +23,7 @@ import { PDS } from "#pds";
|
|
|
23
23
|
|
|
24
24
|
export class SvgIcon extends HTMLElement {
|
|
25
25
|
static observedAttributes = ['icon', 'size', 'color', 'label', 'rotate', 'morph'];
|
|
26
|
+
static #configListenersAttached = false;
|
|
26
27
|
|
|
27
28
|
// Inline fallback icons for critical UI elements (when sprite fails to load)
|
|
28
29
|
static #fallbackIcons = {
|
|
@@ -126,6 +127,7 @@ export class SvgIcon extends HTMLElement {
|
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
connectedCallback() {
|
|
130
|
+
SvgIcon.ensureConfigListeners();
|
|
129
131
|
SvgIcon.instances.add(this);
|
|
130
132
|
this.render();
|
|
131
133
|
}
|
|
@@ -589,13 +591,14 @@ export class SvgIcon extends HTMLElement {
|
|
|
589
591
|
static getExternalIconPath() {
|
|
590
592
|
try {
|
|
591
593
|
const candidates = [
|
|
592
|
-
PDS?.
|
|
594
|
+
PDS?.externalIconPath,
|
|
595
|
+
PDS?.currentConfig?.design?.icons?.externalPath,
|
|
596
|
+
PDS?.currentConfig?.icons?.externalPath,
|
|
593
597
|
PDS?.compiled?.config?.design?.icons?.externalPath,
|
|
594
598
|
PDS?.compiled?.config?.icons?.externalPath,
|
|
595
599
|
PDS?.compiled?.options?.design?.icons?.externalPath,
|
|
596
600
|
PDS?.compiled?.options?.icons?.externalPath,
|
|
597
|
-
PDS?.
|
|
598
|
-
PDS?.currentConfig?.icons?.externalPath,
|
|
601
|
+
PDS?.compiled?.tokens?.icons?.externalPath,
|
|
599
602
|
];
|
|
600
603
|
|
|
601
604
|
for (const value of candidates) {
|
|
@@ -610,6 +613,46 @@ export class SvgIcon extends HTMLElement {
|
|
|
610
613
|
return '/assets/img/icons/';
|
|
611
614
|
}
|
|
612
615
|
|
|
616
|
+
/**
|
|
617
|
+
* Returns true when externalPath is explicitly present in runtime config.
|
|
618
|
+
* @private
|
|
619
|
+
* @returns {boolean}
|
|
620
|
+
*/
|
|
621
|
+
static hasConfiguredExternalIconPath() {
|
|
622
|
+
try {
|
|
623
|
+
const candidates = [
|
|
624
|
+
PDS?.compiled?.tokens?.icons?.externalPath,
|
|
625
|
+
PDS?.compiled?.config?.design?.icons?.externalPath,
|
|
626
|
+
PDS?.compiled?.config?.icons?.externalPath,
|
|
627
|
+
PDS?.compiled?.options?.design?.icons?.externalPath,
|
|
628
|
+
PDS?.compiled?.options?.icons?.externalPath,
|
|
629
|
+
PDS?.currentConfig?.design?.icons?.externalPath,
|
|
630
|
+
PDS?.currentConfig?.icons?.externalPath,
|
|
631
|
+
];
|
|
632
|
+
return candidates.some((value) => typeof value === 'string' && value.trim().length > 0);
|
|
633
|
+
} catch (error) {
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Ensures one-time config lifecycle listeners so icons re-render when config becomes available.
|
|
640
|
+
* @private
|
|
641
|
+
*/
|
|
642
|
+
static ensureConfigListeners() {
|
|
643
|
+
if (SvgIcon.#configListenersAttached || typeof document === 'undefined') {
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
const rerender = () => {
|
|
648
|
+
SvgIcon.notifyInstances();
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
document.addEventListener('pds:ready', rerender);
|
|
652
|
+
document.addEventListener('pds:config-changed', rerender);
|
|
653
|
+
SvgIcon.#configListenersAttached = true;
|
|
654
|
+
}
|
|
655
|
+
|
|
613
656
|
/**
|
|
614
657
|
* Normalize the external icon path to make cache keys and URL joining stable.
|
|
615
658
|
* @private
|
|
@@ -679,6 +722,10 @@ export class SvgIcon extends HTMLElement {
|
|
|
679
722
|
return false;
|
|
680
723
|
}
|
|
681
724
|
|
|
725
|
+
if (PDS?.initializing === true && !SvgIcon.hasConfiguredExternalIconPath()) {
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
|
|
682
729
|
const normalizedBasePath = SvgIcon.normalizeExternalIconPath(basePath);
|
|
683
730
|
const cacheKey = SvgIcon.getExternalIconCacheKey(iconName, normalizedBasePath);
|
|
684
731
|
|
|
@@ -707,22 +754,46 @@ export class SvgIcon extends HTMLElement {
|
|
|
707
754
|
}
|
|
708
755
|
const svgText = await response.text();
|
|
709
756
|
const parser = new DOMParser();
|
|
710
|
-
const
|
|
711
|
-
const
|
|
757
|
+
const xmlDoc = parser.parseFromString(svgText, 'image/svg+xml');
|
|
758
|
+
const htmlDoc = parser.parseFromString(svgText, 'text/html');
|
|
712
759
|
|
|
760
|
+
let svg = xmlDoc.querySelector('svg') || htmlDoc.querySelector('svg');
|
|
761
|
+
let symbol = null;
|
|
713
762
|
if (!svg) {
|
|
714
|
-
|
|
763
|
+
symbol = xmlDoc.querySelector('symbol') || htmlDoc.querySelector('symbol');
|
|
715
764
|
}
|
|
716
765
|
|
|
717
|
-
// Extract viewBox and content
|
|
718
|
-
const viewBox = svg.getAttribute('viewBox') || '0 0 24 24';
|
|
719
|
-
const preserveAspectRatio = svg.getAttribute('preserveAspectRatio');
|
|
720
|
-
|
|
721
|
-
// Serialize the inner content
|
|
722
766
|
const serializer = new XMLSerializer();
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
767
|
+
let viewBox = '0 0 24 24';
|
|
768
|
+
let preserveAspectRatio = null;
|
|
769
|
+
let content = '';
|
|
770
|
+
|
|
771
|
+
if (svg) {
|
|
772
|
+
viewBox = svg.getAttribute('viewBox') || '0 0 24 24';
|
|
773
|
+
preserveAspectRatio = svg.getAttribute('preserveAspectRatio');
|
|
774
|
+
content = Array.from(svg.childNodes)
|
|
775
|
+
.map((node) => serializer.serializeToString(node))
|
|
776
|
+
.join('');
|
|
777
|
+
} else if (symbol) {
|
|
778
|
+
viewBox = symbol.getAttribute('viewBox') || '0 0 24 24';
|
|
779
|
+
preserveAspectRatio = symbol.getAttribute('preserveAspectRatio');
|
|
780
|
+
content = Array.from(symbol.childNodes)
|
|
781
|
+
.map((node) => serializer.serializeToString(node))
|
|
782
|
+
.join('');
|
|
783
|
+
} else {
|
|
784
|
+
const trimmed = svgText.trim();
|
|
785
|
+
const appearsToBeSvgMarkup = /^<(path|g|defs|circle|ellipse|line|polyline|polygon|rect|use|mask|clipPath|linearGradient|radialGradient)\b/i.test(trimmed);
|
|
786
|
+
if (appearsToBeSvgMarkup) {
|
|
787
|
+
content = trimmed;
|
|
788
|
+
} else {
|
|
789
|
+
const preview = trimmed.slice(0, 120).replace(/\s+/g, ' ');
|
|
790
|
+
throw new Error(`Invalid SVG payload from ${iconUrl}: no <svg>/<symbol> found (preview: ${preview})`);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
if (!content) {
|
|
795
|
+
throw new Error(`Invalid SVG payload from ${iconUrl}: empty icon markup`);
|
|
796
|
+
}
|
|
726
797
|
|
|
727
798
|
SvgIcon.externalIconCache.set(cacheKey, {
|
|
728
799
|
loaded: true,
|
|
@@ -738,7 +809,7 @@ export class SvgIcon extends HTMLElement {
|
|
|
738
809
|
.catch((error) => {
|
|
739
810
|
// Only log if not a 404 (expected for non-existent icons)
|
|
740
811
|
if (!error.message?.includes('404')) {
|
|
741
|
-
console.debug('[pds-icon] External icon not found:', iconName, error.message);
|
|
812
|
+
console.debug('[pds-icon] External icon not found:', iconName, iconUrl, error.message);
|
|
742
813
|
}
|
|
743
814
|
SvgIcon.externalIconCache.set(cacheKey, {
|
|
744
815
|
loaded: false,
|