@pure-ds/core 0.7.39 → 0.7.41

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.
@@ -1,2 +1,2 @@
1
- var nt=Object.defineProperty;var ot=(e,t)=>{for(var n in t)nt(e,n,{get:t[n],enumerable:!0})};var ie=class extends EventTarget{constructor(){super(),this.mode=null,this.compiled=null,this.log=()=>{},this.logHandler=null}},Le="__PURE_DS_PDS_SINGLETON__",ae=typeof globalThis<"u"?globalThis:window,se=ae?.[Le],r=se&&typeof se.addEventListener=="function"?se:new ie;ae&&(ae[Le]=r);typeof r.log!="function"&&(r.log=(e="log",t,...n)=>{if(typeof console>"u")return;let o=typeof console[e]=="function"?console[e].bind(console):typeof console.log=="function"?console.log.bind(console):null;o&&(n.length>0?o(t,...n):o(t))});typeof r.logHandler!="function"&&(r.logHandler=null);var ce=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){r.log("error",`Registry: failed to load static ${t}:`,n),r.log("error",`Registry: looking for ${this._staticPaths[t]}`),r.log("error","Registry: make sure you've run 'npm run pds:build' and configured PDS.start() with the correct static.root path");let o=new CSSStyleSheet;return o.replaceSync("/* Failed to load "+t+" */"),o}}get mode(){return this._mode}get isLive(){return this._mode==="live"}},C=new ce;async function Ee(e,t=[],n=null){try{let o=n?.primitivesStylesheet?n.primitivesStylesheet:await C.getStylesheet("primitives");e.adoptedStyleSheets=[o,...t]}catch(o){let c=e.host?.tagName?.toLowerCase()||"unknown";r.log("error",`Adopter: <${c}> failed to adopt primitives:`,o),e.adoptedStyleSheets=t}}async function Ae(e,t=["primitives"],n=[],o=null){let c=Array.isArray(n)?n.filter(Boolean):[];if(c.length){let l=(Array.isArray(e.adoptedStyleSheets)?e.adoptedStyleSheets:[]).filter(y=>!c.includes(y));e.adoptedStyleSheets=[...l,...c]}try{let l=(await Promise.all(t.map(async y=>{if(o)switch(y){case"tokens":return o.tokensStylesheet;case"primitives":return o.primitivesStylesheet;case"components":return o.componentsStylesheet;case"utilities":return o.utilitiesStylesheet;default:break}return C.getStylesheet(y)}))).filter(y=>y!==null);e.adoptedStyleSheets=[...l,...c]}catch(s){let l=e.host?.tagName?.toLowerCase()||"unknown";r.log("error",`Adopter: <${l}> failed to adopt layers:`,s),e.adoptedStyleSheets=c}}function ve(e){let t=new CSSStyleSheet;return t.replaceSync(e),t}var Pe={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 ue={};ot(ue,{deepMerge:()=>Re,fragmentFromTemplateLike:()=>rt,isObject:()=>W,parseHTML:()=>le});function W(e){return e&&typeof e=="object"&&!Array.isArray(e)}function Re(e,t){let n={...e};return W(e)&&W(t)&&Object.keys(t).forEach(o=>{W(t[o])?o in e?n[o]=Re(e[o],t[o]):Object.assign(n,{[o]:t[o]}):Object.assign(n,{[o]:t[o]})}),n}function rt(e){let t=Array.isArray(e?.strings)?e.strings:[],n=Array.isArray(e?.values)?e.values:[],o=new Set,c=[],s=/(\s)(\.[\w-]+)=\s*$/;for(let i=0;i<t.length;i+=1){let S=t[i]??"",m=S.match(s);if(m&&i<n.length){let b=m[2].slice(1),A=`pds-val-${i}`;S=S.replace(s,`$1data-pds-prop="${b}:${A}"`),o.add(i)}c.push(S),i<n.length&&!o.has(i)&&c.push(`<!--pds-val-${i}-->`)}let l=document.createElement("template");l.innerHTML=c.join("");let y=(i,S)=>{let m=i.parentNode;if(!m)return;if(S==null){m.removeChild(i);return}let L=b=>{if(b!=null){if(b instanceof Node){m.insertBefore(b,i);return}if(Array.isArray(b)){b.forEach(A=>L(A));return}m.insertBefore(document.createTextNode(String(b)),i)}};L(S),m.removeChild(i)},g=document.createTreeWalker(l.content,NodeFilter.SHOW_COMMENT),u=[];for(;g.nextNode();){let i=g.currentNode;i?.nodeValue?.startsWith("pds-val-")&&u.push(i)}return u.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[m,L]=S.split(":"),b=Number(String(L).replace("pds-val-",""));m&&Number.isInteger(b)&&(i[m]=n[b]),i.removeAttribute("data-pds-prop")}),l.content}function le(e){return new DOMParser().parseFromString(e,"text/html").body.childNodes}var De="pds",st=/^([a-z][a-z0-9+\-.]*:)?\/\//i,xe=/^[a-z]:/i;function U(e=""){return e.endsWith("/")?e:`${e}/`}function it(e="",t=De){let n=e.replace(/\/+$/,"");return new RegExp(`(?:^|/)${t}$`,"i").test(n)?n:`${n}/${t}`}function at(e){return e.replace(/^\.\/+/,"")}function ct(e){return xe.test(e)?e.replace(xe,"").replace(/^\/+/,""):e}function lt(e){return e.startsWith("public/")?e.substring(7):e}function H(e,t={}){let n=t.segment||De,o=t.defaultRoot||`/assets/${n}/`,c=e?.public&&e.public?.root||e?.static&&e.static?.root||null;if(!c||typeof c!="string")return U(o);let s=c.trim();return s?(s=s.replace(/\\/g,"/"),s=it(s,n),s=U(s),st.test(s)?s:(s=at(s),s=ct(s),s.startsWith("/")||(s=lt(s),s.startsWith("/")||(s=`/${s}`),s=s.replace(/\/+/g,(l,y)=>y===0?l:"/")),U(s))):U(o)}async function ut(...e){let t={};e.length&&typeof e[e.length-1]=="object"&&(t=e.pop()||{});let n=e,{baseURL:o,mapper:c=u=>`${u}.js`,onError:s=(u,a)=>console.error(`[defineWebComponents] ${u}:`,a)}=t,l=o?new URL(o,typeof location<"u"?location.href:import.meta.url):new URL("./",import.meta.url),y=u=>u.toLowerCase().replace(/(^|-)([a-z])/g,(a,i,S)=>S.toUpperCase()),g=async u=>{try{if(customElements.get(u))return{tag:u,status:"already-defined"};let a=c(u),S=await import(a instanceof URL?a.href:new URL(a,l).href),m=S?.default??S?.[y(u)];if(!m){if(customElements.get(u))return{tag:u,status:"self-defined"};throw new Error(`No export found for ${u}. Expected default export or named export "${y(u)}".`)}return customElements.get(u)?{tag:u,status:"race-already-defined"}:(customElements.define(u,m),{tag:u,status:"defined"})}catch(a){throw s(u,a),a}};return Promise.all(n.map(g))}var B=class{constructor(t={}){let{baseURL:n,mapper:o,onError:c,predicate:s=()=>!0,attributeModule:l="data-module",root:y=document,scanExisting:g=!0,debounceMs:u=16,observeShadows:a=!0,enhancers:i=[],patchAttachShadow:S=!0}=t,m=new Set,L=new Set,b=new Set,A=new Map,P=new WeakMap,E=new WeakMap,h=0,w=!1,R=null,F=d=>{if(!d||!i.length)return;let p=E.get(d);p||(p=new Set,E.set(d,p));for(let f of i)if(!(!f.selector||!f.run)&&!p.has(f.selector))try{d.matches&&d.matches(f.selector)&&(f.run(d),p.add(f.selector))}catch(v){console.warn(`[AutoDefiner] Error applying enhancer for selector "${f.selector}":`,v)}},M=(d,p)=>{if(!w&&!(!d||!d.includes("-"))&&!customElements.get(d)&&!L.has(d)&&!b.has(d)){if(p&&p.getAttribute){let f=p.getAttribute(l);f&&!A.has(d)&&A.set(d,f)}m.add(d),tt()}},tt=()=>{h||(h=setTimeout(Se,u))},D=d=>{if(d){if(d.nodeType===1){let p=d,f=p.tagName?.toLowerCase();f&&f.includes("-")&&!customElements.get(f)&&s(f,p)&&M(f,p),F(p),a&&p.shadowRoot&&re(p.shadowRoot)}d.querySelectorAll&&d.querySelectorAll("*").forEach(p=>{let f=p.tagName?.toLowerCase();f&&f.includes("-")&&!customElements.get(f)&&s(f,p)&&M(f,p),F(p),a&&p.shadowRoot&&re(p.shadowRoot)})}},re=d=>{if(!d||P.has(d))return;D(d);let p=new MutationObserver(f=>{for(let v of f)v.addedNodes?.forEach(z=>{D(z)}),v.type==="attributes"&&v.target&&D(v.target)});p.observe(d,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[l,...i.map(f=>f.selector).filter(f=>f.startsWith("data-"))]}),P.set(d,p)};async function Se(){if(clearTimeout(h),h=0,!m.size)return;let d=Array.from(m);m.clear(),d.forEach(p=>L.add(p));try{let p=f=>A.get(f)??(o?o(f):`${f}.js`);await ut(...d,{baseURL:n,mapper:p,onError:(f,v)=>{b.add(f),c?.(f,v)}})}catch{}finally{d.forEach(p=>L.delete(p))}}let be=y===document?document.documentElement:y,_e=new MutationObserver(d=>{for(let p of d)p.addedNodes?.forEach(f=>{D(f)}),p.type==="attributes"&&p.target&&D(p.target)});if(_e.observe(be,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[l,...i.map(d=>d.selector).filter(d=>d.startsWith("data-"))]}),a&&S&&Element.prototype.attachShadow){let d=Element.prototype.attachShadow;Element.prototype.attachShadow=function(f){let v=d.call(this,f);if(f&&f.mode==="open"){re(v);let z=this.tagName?.toLowerCase();z&&z.includes("-")&&!customElements.get(z)&&M(z,this)}return v},R=()=>Element.prototype.attachShadow=d}return g&&D(be),{stop(){w=!0,_e.disconnect(),R&&R(),h&&(clearTimeout(h),h=0),P.forEach(d=>d.disconnect())},flush:Se}}static async define(...t){let n={};t.length&&typeof t[t.length-1]=="object"&&(n=t.pop()||{});let o=t,{baseURL:c,mapper:s=a=>`${a}.js`,onError:l=(a,i)=>console.error(`[defineWebComponents] ${a}:`,i)}=n,y=c?new URL(c,typeof location<"u"?location.href:import.meta.url):new URL("./",import.meta.url),g=a=>a.toLowerCase().replace(/(^|-)([a-z])/g,(i,S,m)=>m.toUpperCase()),u=async a=>{try{if(customElements.get(a))return{tag:a,status:"already-defined"};let i=s(a),m=await import(i instanceof URL?i.href:new URL(i,y).href),L=m?.default??m?.[g(a)];if(!L){if(customElements.get(a))return{tag:a,status:"self-defined"};throw new Error(`No export found for ${a}. Expected default export or named export "${g(a)}".`)}return customElements.get(a)?{tag:a,status:"race-already-defined"}:(customElements.define(a,L),{tag:a,status:"defined"})}catch(i){throw l(a,i),i}};return Promise.all(o.map(u))}};var dt=/^[a-z][a-z0-9+\-.]*:\/\//i,j=(()=>{try{return import.meta.url}catch{return}})(),K=e=>typeof e=="string"&&e.length&&!e.endsWith("/")?`${e}/`:e;function G(e,t={}){if(!e||dt.test(e))return e;let{preferModule:n=!0}=t,o=()=>{if(!j)return null;try{return new URL(e,j).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?o()||c():c()||o())||e}var ze=(()=>{if(j)try{let e=new URL(j);if(/\/public\/assets\/js\//.test(e.pathname))return new URL("../pds/",j).href}catch{return}})(),Ce=!1;function Te(e){Ce||typeof document>"u"||(Ce=!0,e.addEventListener("pds:ready",t=>{let n=t.detail?.mode;n&&document.documentElement.classList.add(`pds-${n}`,"pds-ready")}))}function ke({manageTheme:e,themeStorageKey:t,applyResolvedTheme:n,setupSystemListenerIfNeeded:o}){let c="light",s=null;if(e&&typeof window<"u"){try{s=localStorage.getItem(t)||null}catch{s=null}try{n?.(s),o?.(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 q(e,{resolvePublicAssetURL:t}){let n=!!(e?.public?.root||e?.static?.root),o=t(e);return!n&&ze&&(o=ze),K(G(o))}async function Me(e,{baseEnhancers:t=[]}={}){let{autoDefineBaseURL:n="/auto-define/",autoDefinePreload:o=[],autoDefineMapper:c=null,enhancers:s=[],autoDefineOverrides:l=null,autoDefinePreferModule:y=!0}=e,g=(()=>{let a=new Map;return(t||[]).forEach(i=>a.set(i.selector,i)),(s||[]).forEach(i=>a.set(i.selector,i)),Array.from(a.values())})(),u=null;if(typeof window<"u"&&typeof document<"u"){let a=B,i=h=>{switch(h){case"pds-tabpanel":return"pds-tabstrip.js";default:return`${h}.js`}},{mapper:S,enhancers:m,...L}=l&&typeof l=="object"?l:{},b=m?Array.isArray(m)?m:typeof m=="object"?Object.values(m):[]:[],A=(()=>{let h=new Map;return(g||[]).forEach(w=>{w?.selector&&h.set(w.selector,w)}),(b||[]).forEach(w=>{if(!w?.selector)return;let R=h.get(w.selector)||null;h.set(w.selector,{...R||{},...w,run:typeof w?.run=="function"?w.run:R?.run})}),Array.from(h.values())})(),E={baseURL:n&&K(G(n,{preferModule:y})),predefine:o,scanExisting:!0,observeShadows:!0,patchAttachShadow:!0,debounceMs:16,enhancers:A,onError:(h,w)=>{if(typeof h=="string"&&h.startsWith("pds-")){let F=["pds-form","pds-drawer"].includes(h),M=w?.message?.includes("#pds/lit")||w?.message?.includes("Failed to resolve module specifier");F&&M?r.log("error",`\u274C PDS component <${h}> 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`):r.log("warn",`\u26A0\uFE0F PDS component <${h}> not found. Assets may not be installed.`)}else r.log("error",`\u274C Auto-define error for <${h}>:`,w)},...L,mapper:h=>{if(customElements.get(h))return null;if(typeof c=="function")try{let w=c(h);return w===void 0?i(h):w}catch(w){return r.log("warn","Custom autoDefine.mapper error; falling back to default:",w?.message||w),i(h)}return i(h)}};u=new a(E),o.length>0&&typeof a.define=="function"&&await a.define(...o,{baseURL:n,mapper:E.mapper,onError:E.onError})}return{autoDefiner:u,mergedEnhancers:g}}var de=["light","dark"],fe=new Set(de);function ft(e){let n=(Array.isArray(e?.themes)?e.themes.map(o=>String(o).toLowerCase()):de).filter(o=>fe.has(o));return n.length?n:de}function pe(e,{preferDocument:t=!0}={}){let n=String(e||"").toLowerCase();if(fe.has(n))return n;if(t&&typeof document<"u"){let o=document.documentElement?.getAttribute("data-theme");if(fe.has(o))return o}return typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Ue(e,t){let n=pe(t);return ft(e).includes(n)}var pt=new Set(["log","warn","error","debug","info"]),mt="__PURE_DS_PDS_SINGLETON__",me=null,he=null;function Oe(){try{let t=(typeof globalThis<"u"?globalThis:window)?.[mt];if(t&&typeof t=="object")return t}catch{return null}return null}function ht(e){return!e||typeof e!="object"?null:{mode:e.mode==="live"||e.mode==="static"?e.mode:null,debug:e.debug===!0,thisArg:e.thisArg}}function yt(e){if(typeof e!="string")return"log";let t=e.toLowerCase();return pt.has(t)?t:"log"}function gt(){if(typeof he=="function")try{let t=ht(he());if(t)return t}catch{}let e=Oe();if(e){let t=e?.mode||e?.compiled?.mode||(e?.registry?.isLive?"live":"static"),n=(e?.debug||e?.currentConfig?.debug||e?.currentConfig?.design?.debug||e?.compiled?.debug||e?.compiled?.design?.debug||!1)===!0;return{mode:t,debug:n,thisArg:e}}return{mode:null,debug:!1}}function wt(){if(typeof me=="function")try{let t=me();if(typeof t=="function")return t}catch{}let e=Oe();return typeof e?.logHandler=="function"?e.logHandler:null}function je(e,t,...n){if(typeof console>"u")return;let o=typeof console[e]=="function"?console[e].bind(console):typeof console.log=="function"?console.log.bind(console):null;o&&(n.length>0?o(t,...n):o(t))}function St(e,t){let n=t?.debug===!0;return!(t?.mode==="static"&&!n||!n&&e!=="error"&&e!=="warn")}function Ne({getLogger:e,getContext:t}={}){me=typeof e=="function"?e:null,he=typeof t=="function"?t:null}function $e(e="log",t,...n){let o=yt(e),c=gt(),s=wt();if(s)try{s.call(c?.thisArg,o,t,...n);return}catch(l){je("error","Custom log handler failed:",l)}St(o,c)&&je(o,t,...n)}typeof r.initializing!="boolean"&&(r.initializing=!1);"currentPreset"in r||(r.currentPreset=null);typeof r.debug!="boolean"&&(r.debug=!1);"currentConfig"in r||(r.currentConfig=null);"compiled"in r||(r.compiled=null);typeof r.logHandler!="function"&&(r.logHandler=null);"mode"in r||(r.mode=null);var V=null,J=null,Y=null,Q=null,Z=null,X=null,Fe="__pdsLocalizationRuntime";function T(){if(X)return X;let e=r?.[Fe];return e&&typeof e=="object"?(X=e,e):null}function bt(e){let t=e&&typeof e=="object"?e:null;X=t,r[Fe]=t}Ne({getLogger:()=>typeof r.logHandler=="function"?r.logHandler:null,getContext:()=>{let e=r?.mode||r?.compiled?.mode||(r?.registry?.isLive?"live":"static"),t=(r?.debug||r?.currentConfig?.debug||r?.currentConfig?.design?.debug||r?.compiled?.debug||r?.compiled?.design?.debug||!1)===!0;return{mode:e,debug:t,thisArg:r}}});r.log=(e="log",t,...n)=>{$e(e,t,...n)};var _={locale:"en",messages:{},hasProvider:!1},ee=new Set;function We(e){return!!e&&typeof e!="string"&&typeof e=="object"&&"strTag"in e}function He(e=[]){let t="";for(let n=0;n<=e.length-1;n+=1)t+=e[n],n<e.length-1&&(t+=`{${n}}`);return t}function _t(e,t){return String(e).replace(/\{(\d+)\}/g,(n,o)=>t(Number(o)))}function Lt(e){if(!e||typeof e!="object")return{};let t={};for(let[n,o]of Object.entries(e)){if(typeof o=="string"){t[n]=o;continue}o&&typeof o=="object"&&typeof o.content=="string"&&(t[n]=o.content)}return t}function Et(e,...t){return{strTag:!0,strings:Array.from(e||[]),values:t,raw:Array.from(e?.raw||[])}}function At(e){if(!e)return"";if(We(e)){let n=He(e.strings||[]),o=_.messages[n]||n;return _t(o,c=>e.values?.[c])}let t=String(e);return _.messages[t]||t}function vt(e){if(!e)return;let t=We(e)?He(e.strings||[]):String(e);typeof t=="string"&&t.length>0&&ee.add(t)}function Be(e){if(!e||typeof e.msg!="function"||ee.size===0)return;let t=Array.from(ee);ee.clear();for(let n of t)try{e.msg(n)}catch{}}async function N(){let e=T();return e||(Z||(Z=import($("pds-localization.js")).then(n=>{if(typeof n?.msg!="function"||typeof n?.str!="function"||typeof n?.configureLocalization!="function"||typeof n?.loadLocale!="function"||typeof n?.setLocale!="function"||typeof n?.getLocalizationState!="function")throw new Error("Failed to load localization runtime exports");return bt(n),Be(n),n}).catch(n=>{throw Z=null,n})),Z)}var Ke=(e,t={})=>{let n=T();return typeof n?.msg=="function"?n.msg(e,t):(vt(e),At(e,t))},Ge=(e,...t)=>{let n=T();return typeof n?.str=="function"?n.str(e,...t):Et(e,...t)},te=(e=null)=>{let t=T();if(typeof t?.configureLocalization=="function")return t.configureLocalization(e);if(!e||typeof e!="object")return _.locale="en",_.messages={},_.hasProvider=!1,{locale:_.locale,messages:{..._.messages},hasProvider:_.hasProvider};typeof e.locale=="string"&&e.locale.trim()&&(_.locale=e.locale.trim()),Object.prototype.hasOwnProperty.call(e,"messages")&&(_.messages=Lt(e.messages));let n=!!(e.provider||e.translate||e.loadLocale||e.setLocale);return _.hasProvider=n,n&&N().then(o=>{o.configureLocalization(e),Be(o)}).catch(()=>{}),{locale:_.locale,messages:{..._.messages},hasProvider:_.hasProvider}},qe=async e=>(await N()).loadLocale(e),Ve=async(e,t={})=>(await N()).setLocale(e,t),Je=()=>{let e=T();return typeof e?.getLocalizationState=="function"?e.getLocalizationState():{locale:_.locale,messages:{..._.messages},hasProvider:_.hasProvider}},Ye=(e={})=>{let t=T();if(typeof t?.createJSONLocalization=="function")return t.createJSONLocalization(e);let n=typeof e?.locale=="string"&&e.locale.trim()?e.locale.trim().toLowerCase():"en",o=Array.isArray(e?.locales)?e.locales.map(g=>String(g||"").trim().toLowerCase()).filter(Boolean):[],c=Array.from(new Set([n,...o])),s=null,l=async()=>(s||(s=N().then(g=>typeof g?.createJSONLocalization=="function"?g.createJSONLocalization(e):null).catch(()=>null)),s),y=async(g="loadLocale")=>{let u=await l();if(!u||typeof u!="object")return null;let a=u.provider;if(!a||typeof a!="object")return null;let i=a[g];return typeof i=="function"?i:g==="setLocale"&&typeof a.loadLocale=="function"?a.loadLocale:null};return{locale:n,locales:[...c],provider:{locales:[...c],async loadLocale(g={}){let u=await y("loadLocale");return typeof u!="function"?{}:u(g)},async setLocale(g={}){let u=await y("setLocale");return typeof u!="function"?{}:u(g)}}}};function $(e,t){return t&&typeof t=="string"?t:`${q(r.currentConfig||{},{resolvePublicAssetURL:H})}core/${e}`}async function Pt(){return Array.isArray(r.defaultEnhancers)&&r.defaultEnhancers.length>0?r.defaultEnhancers:(Q||(Q=import($("pds-enhancers.js",r.currentConfig?.enhancersURL)).then(t=>{let n=Array.isArray(t?.defaultPDSEnhancers)?t.defaultPDSEnhancers:[];return r.defaultEnhancers=n,n}).catch(t=>{throw Q=null,t})),Q)}async function Rt(){return typeof r.ask=="function"&&r.ask!==Qe?r.ask:(J||(J=import($("pds-ask.js",r.currentConfig?.askURL)).then(t=>{let n=t?.ask;if(typeof n!="function")throw new Error("Failed to load ask helper");return r.ask=n,n}).catch(t=>{throw J=null,t})),J)}async function I(){return typeof r.toast=="function"&&r.toast!==k?r.toast:(Y||(Y=import($("pds-toast.js",r.currentConfig?.toastURL)).then(t=>{let n=t?.toast;if(typeof n!="function")throw new Error("Failed to load toast helper");return r.toast=n,n}).catch(t=>{throw Y=null,t})),Y)}async function Qe(...e){return(await Rt())(...e)}async function k(...e){return(await I())(...e)}k.success=async(...e)=>(await I()).success(...e);k.error=async(...e)=>(await I()).error(...e);k.warning=async(...e)=>(await I()).warning(...e);k.info=async(...e)=>(await I()).info(...e);var Ie=function(e="log",t,...n){r.log(e,t,...n)};function ge(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=>ge(n)).filter(n=>n!==void 0);let t={};for(let[n,o]of Object.entries(e)){let c=ge(o);c!==void 0&&(t[n]=c)}return t}function Ze(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))Ze(e[n],t);return e}function we(e){return e==null||typeof e!="object"?e:Ze(structuredClone(ge(e)))}async function xt(e,t={}){if(t?.runtimeConfig===!1||typeof fetch!="function")return null;let n=t?.runtimeConfigURL||`${e}pds-runtime-config.json`;try{let o=await fetch(n,{cache:"no-store"});return o.ok?await o.json():null}catch{return null}}r.registry=C;r.enums=Pe;r.adoptLayers=Ae;r.adoptPrimitives=Ee;r.parse=le;r.createStylesheet=ve;r.isLiveMode=()=>C.isLive;r.ask=Qe;r.toast=k;r.common=ue;r.msg=Ke;r.str=Ge;r.configureLocalization=te;r.loadLocale=qe;r.setLocale=Ve;r.getLocalizationState=Je;r.createJSONLocalization=Ye;r.i18n={msg:Ke,str:Ge,configure:te,loadLocale:qe,setLocale:Ve,getState:Je,createJSONLocalization:Ye};r.AutoComplete=null;r.loadAutoComplete=async()=>{if(r.AutoComplete&&typeof r.AutoComplete.connect=="function")return r.AutoComplete;let e=$("pds-autocomplete.js",r.currentConfig?.autoCompleteURL);return V||(V=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 r.AutoComplete=n,n}).catch(t=>{throw V=null,t})),V};function Xe(e){let t=typeof CustomEvent=="function";try{let n=t?new CustomEvent("pds:ready",{detail:e}):new Event("pds:ready");r.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 et(e={}){let t=typeof CustomEvent=="function",n={at:Date.now(),...e};try{let o=t?new CustomEvent("pds:config-changed",{detail:n}):new Event("pds:config-changed");r.dispatchEvent(o)}catch{}if(typeof document<"u")if(t){let o={detail:n,bubbles:!0,composed:!0};try{document.dispatchEvent(new CustomEvent("pds:config-changed",o))}catch{}}else try{document.dispatchEvent(new Event("pds:config-changed"))}catch{}}var ye="pure-ds-theme",x=null,O=null;function ne(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 oe(e){try{if(x&&O){try{typeof x.removeEventListener=="function"?x.removeEventListener("change",O):typeof x.removeListener=="function"&&x.removeListener(O)}catch{}x=null,O=null}if(e==="system"&&typeof window<"u"&&window.matchMedia){let t=window.matchMedia("(prefers-color-scheme: dark)"),n=o=>{let c=o?.matches===void 0?t.matches:o.matches;try{let s=c?"dark":"light";document.documentElement.setAttribute("data-theme",s),r.dispatchEvent(new CustomEvent("pds:theme:changed",{detail:{theme:s,source:"system"}}))}catch{}};x=t,O=n,typeof t.addEventListener=="function"?t.addEventListener("change",n):typeof t.addListener=="function"&&t.addListener(n)}}catch{}}var Dt=Object.getOwnPropertyDescriptor(r,"theme");Dt||Object.defineProperty(r,"theme",{get(){try{return typeof window>"u"?null:localStorage.getItem(ye)||null}catch{return null}},set(e){try{if(typeof window>"u")return;let t=r.currentConfig?.design||null,n=pe(e);if(t&&!Ue(t,n)){let o=t?.name||r.currentPreset?.name||r.currentConfig?.preset||"current preset";r.log("warn",`PDS theme "${n}" not supported by preset "${o}".`),r.dispatchEvent(new CustomEvent("pds:theme:blocked",{detail:{theme:e,resolvedTheme:n,preset:o}}));return}e==null?localStorage.removeItem(ye):localStorage.setItem(ye,e),ne(e),oe(e),r.dispatchEvent(new CustomEvent("pds:theme:changed",{detail:{theme:e,source:"api"}}))}catch{}}});r.defaultEnhancers=[];async function zt(e){r.initializing=!0;try{let t=e&&e.mode||"live",{mode:n,...o}=e||{};r.mode=t,r.logHandler=typeof o?.log=="function"?o.log:null,r.currentConfig=we(o);let c=o&&typeof o.localization=="object"&&o.localization?o.localization:null;c?(await N(),te(c)):te(null);let s;if(t==="static")s=await Ct(o);else{let y=q(o,{resolvePublicAssetURL:H}),g=o?.managerURL||o?.public?.managerURL||o?.manager?.url||new URL("core/pds-manager.js",y).href||new URL("./pds-manager.js",import.meta.url).href,{startLive:u}=await import(g);s=await u(r,o,{emitReady:Xe,emitConfigChanged:et,applyResolvedTheme:ne,setupSystemListenerIfNeeded:oe})}r.compiled=we(s?.config||null);let l=r?.compiled?.design?.icons?.externalPath||"/assets/img/icons/";return r.log("info",`startup ready; external icon path: ${l}`),s}finally{r.initializing=!1}}r.start=zt;async function Ct(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,o=e.themeStorageKey??"pure-ds-theme",c=e.staticPaths??{},s=q(e,{resolvePublicAssetURL:H}),l=e&&e.autoDefine||null,y;l&&l.baseURL?y=K(G(l.baseURL,{preferModule:!1})):y=`${s}components/`;let g=l&&Array.isArray(l.predefine)&&l.predefine||[],u=l&&typeof l.mapper=="function"&&l.mapper||null;try{Te(r);let{resolvedTheme:a}=ke({manageTheme:n,themeStorageKey:o,applyResolvedTheme:ne,setupSystemListenerIfNeeded:oe}),i=await xt(s,e),S=Array.isArray(e?.enhancers)?e.enhancers:e?.enhancers&&typeof e.enhancers=="object"?Object.values(e.enhancers):[],m=i?.config?{...i.config,...e,design:e?.design||i.config.design,preset:e?.preset||i.config.preset}:{...e},L={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`},b=i?.paths||{};if(c={...L,...b,...c},r.registry.setStaticMode(c),t&&typeof document<"u")try{let E=await r.registry.getStylesheet("styles");if(E){E._pds=!0;let h=(document.adoptedStyleSheets||[]).filter(w=>w._pds!==!0);document.adoptedStyleSheets=[...h,E],et({mode:"static",source:"static:styles-applied"})}}catch(E){Ie.call(r,"warn","Failed to apply static styles:",E)}let A=null,P=[];try{let E=await Pt(),h=await Me({autoDefineBaseURL:y,autoDefinePreload:g,autoDefineMapper:u,enhancers:S,autoDefineOverrides:l||null,autoDefinePreferModule:!(l&&l.baseURL)},{baseEnhancers:E});A=h.autoDefiner,P=h.mergedEnhancers||[]}catch(E){Ie.call(r,"error","\u274C Failed to initialize AutoDefiner/Enhancers (static):",E)}return r.compiled=we({mode:"static",...m,theme:a,enhancers:P}),Xe({mode:"static",config:m,theme:a,autoDefiner:A}),{config:m,theme:a,autoDefiner:A}}catch(a){throw r.dispatchEvent(new CustomEvent("pds:error",{detail:{error:a}})),a}}var tn=ne,nn=oe;export{r as PDS,tn as applyResolvedTheme,te as configureLocalization,Ye as createJSONLocalization,Je as getLocalizationState,qe as loadLocale,Ke as msg,Ve as setLocale,nn as setupSystemListenerIfNeeded,Ge as str};
1
+ var nt=Object.defineProperty;var ot=(e,t)=>{for(var n in t)nt(e,n,{get:t[n],enumerable:!0})};var ie=class extends EventTarget{constructor(){super(),this.mode=null,this.compiled=null,this.log=()=>{},this.logHandler=null}},Le="__PURE_DS_PDS_SINGLETON__",ae=typeof globalThis<"u"?globalThis:window,se=ae?.[Le],r=se&&typeof se.addEventListener=="function"?se:new ie;ae&&(ae[Le]=r);typeof r.log!="function"&&(r.log=(e="log",t,...n)=>{if(typeof console>"u")return;let o=typeof console[e]=="function"?console[e].bind(console):typeof console.log=="function"?console.log.bind(console):null;o&&(n.length>0?o(t,...n):o(t))});typeof r.logHandler!="function"&&(r.logHandler=null);var ce=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){r.log("error",`Registry: failed to load static ${t}:`,n),r.log("error",`Registry: looking for ${this._staticPaths[t]}`),r.log("error","Registry: make sure you've run 'npm run pds:build' and configured PDS.start() with the correct static.root path");let o=new CSSStyleSheet;return o.replaceSync("/* Failed to load "+t+" */"),o}}get mode(){return this._mode}get isLive(){return this._mode==="live"}},C=new ce;async function Ee(e,t=[],n=null){try{let o=n?.primitivesStylesheet?n.primitivesStylesheet:await C.getStylesheet("primitives");e.adoptedStyleSheets=[o,...t]}catch(o){let c=e.host?.tagName?.toLowerCase()||"unknown";r.log("error",`Adopter: <${c}> failed to adopt primitives:`,o),e.adoptedStyleSheets=t}}async function Ae(e,t=["primitives"],n=[],o=null){let c=Array.isArray(n)?n.filter(Boolean):[];if(c.length){let l=(Array.isArray(e.adoptedStyleSheets)?e.adoptedStyleSheets:[]).filter(g=>!c.includes(g));e.adoptedStyleSheets=[...l,...c]}try{let l=(await Promise.all(t.map(async g=>{if(o)switch(g){case"tokens":return o.tokensStylesheet;case"primitives":return o.primitivesStylesheet;case"components":return o.componentsStylesheet;case"utilities":return o.utilitiesStylesheet;default:break}return C.getStylesheet(g)}))).filter(g=>g!==null);e.adoptedStyleSheets=[...l,...c]}catch(s){let l=e.host?.tagName?.toLowerCase()||"unknown";r.log("error",`Adopter: <${l}> failed to adopt layers:`,s),e.adoptedStyleSheets=c}}function ve(e){let t=new CSSStyleSheet;return t.replaceSync(e),t}var Pe={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 ue={};ot(ue,{deepMerge:()=>Re,fragmentFromTemplateLike:()=>rt,isObject:()=>W,parseHTML:()=>le});function W(e){return e&&typeof e=="object"&&!Array.isArray(e)}function Re(e,t){let n={...e};return W(e)&&W(t)&&Object.keys(t).forEach(o=>{W(t[o])?o in e?n[o]=Re(e[o],t[o]):Object.assign(n,{[o]:t[o]}):Object.assign(n,{[o]:t[o]})}),n}function rt(e){let t=Array.isArray(e?.strings)?e.strings:[],n=Array.isArray(e?.values)?e.values:[],o=new Set,c=[],s=/(\s)(\.[\w-]+)=\s*$/;for(let i=0;i<t.length;i+=1){let S=t[i]??"",m=S.match(s);if(m&&i<n.length){let _=m[2].slice(1),A=`pds-val-${i}`;S=S.replace(s,`$1data-pds-prop="${_}:${A}"`),o.add(i)}c.push(S),i<n.length&&!o.has(i)&&c.push(`<!--pds-val-${i}-->`)}let l=document.createElement("template");l.innerHTML=c.join("");let g=(i,S)=>{let m=i.parentNode;if(!m)return;if(S==null){m.removeChild(i);return}let L=_=>{if(_!=null){if(_ instanceof Node){m.insertBefore(_,i);return}if(Array.isArray(_)){_.forEach(A=>L(A));return}m.insertBefore(document.createTextNode(String(_)),i)}};L(S),m.removeChild(i)},y=document.createTreeWalker(l.content,NodeFilter.SHOW_COMMENT),u=[];for(;y.nextNode();){let i=y.currentNode;i?.nodeValue?.startsWith("pds-val-")&&u.push(i)}return u.forEach(i=>{let S=Number(i.nodeValue.replace("pds-val-",""));g(i,n[S])}),l.content.querySelectorAll("*").forEach(i=>{let S=i.getAttribute("data-pds-prop");if(!S)return;let[m,L]=S.split(":"),_=Number(String(L).replace("pds-val-",""));m&&Number.isInteger(_)&&(i[m]=n[_]),i.removeAttribute("data-pds-prop")}),l.content}function le(e){return new DOMParser().parseFromString(e,"text/html").body.childNodes}var De="pds",st=/^([a-z][a-z0-9+\-.]*:)?\/\//i,xe=/^[a-z]:/i;function U(e=""){return e.endsWith("/")?e:`${e}/`}function it(e="",t=De){let n=e.replace(/\/+$/,"");return new RegExp(`(?:^|/)${t}$`,"i").test(n)?n:`${n}/${t}`}function at(e){return e.replace(/^\.\/+/,"")}function ct(e){return xe.test(e)?e.replace(xe,"").replace(/^\/+/,""):e}function lt(e){return e.startsWith("public/")?e.substring(7):e}function H(e,t={}){let n=t.segment||De,o=t.defaultRoot||`/assets/${n}/`,c=e?.public&&e.public?.root||e?.static&&e.static?.root||null;if(!c||typeof c!="string")return U(o);let s=c.trim();return s?(s=s.replace(/\\/g,"/"),s=it(s,n),s=U(s),st.test(s)?s:(s=at(s),s=ct(s),s.startsWith("/")||(s=lt(s),s.startsWith("/")||(s=`/${s}`),s=s.replace(/\/+/g,(l,g)=>g===0?l:"/")),U(s))):U(o)}async function ut(...e){let t={};e.length&&typeof e[e.length-1]=="object"&&(t=e.pop()||{});let n=e,{baseURL:o,mapper:c=u=>`${u}.js`,onError:s=(u,a)=>console.error(`[defineWebComponents] ${u}:`,a)}=t,l=o?new URL(o,typeof location<"u"?location.href:import.meta.url):new URL("./",import.meta.url),g=u=>u.toLowerCase().replace(/(^|-)([a-z])/g,(a,i,S)=>S.toUpperCase()),y=async u=>{try{if(customElements.get(u))return{tag:u,status:"already-defined"};let a=c(u),S=await import(a instanceof URL?a.href:new URL(a,l).href),m=S?.default??S?.[g(u)];if(!m){if(customElements.get(u))return{tag:u,status:"self-defined"};throw new Error(`No export found for ${u}. Expected default export or named export "${g(u)}".`)}return customElements.get(u)?{tag:u,status:"race-already-defined"}:(customElements.define(u,m),{tag:u,status:"defined"})}catch(a){throw s(u,a),a}};return Promise.all(n.map(y))}var B=class{constructor(t={}){let{baseURL:n,mapper:o,onError:c,predicate:s=()=>!0,attributeModule:l="data-module",root:g=document,scanExisting:y=!0,debounceMs:u=16,observeShadows:a=!0,enhancers:i=[],patchAttachShadow:S=!0}=t,m=new Set,L=new Set,_=new Set,A=new Map,P=new WeakMap,E=new WeakMap,h=0,w=!1,R=null,F=d=>{if(!d||!i.length)return;let p=E.get(d);p||(p=new Set,E.set(d,p));for(let f of i)if(!(!f.selector||!f.run)&&!p.has(f.selector))try{d.matches&&d.matches(f.selector)&&(f.run(d),p.add(f.selector))}catch(v){console.warn(`[AutoDefiner] Error applying enhancer for selector "${f.selector}":`,v)}},M=(d,p)=>{if(!w&&!(!d||!d.includes("-"))&&!customElements.get(d)&&!L.has(d)&&!_.has(d)){if(p&&p.getAttribute){let f=p.getAttribute(l);f&&!A.has(d)&&A.set(d,f)}m.add(d),tt()}},tt=()=>{h||(h=setTimeout(Se,u))},D=d=>{if(d){if(d.nodeType===1){let p=d,f=p.tagName?.toLowerCase();f&&f.includes("-")&&!customElements.get(f)&&s(f,p)&&M(f,p),F(p),a&&p.shadowRoot&&re(p.shadowRoot)}d.querySelectorAll&&d.querySelectorAll("*").forEach(p=>{let f=p.tagName?.toLowerCase();f&&f.includes("-")&&!customElements.get(f)&&s(f,p)&&M(f,p),F(p),a&&p.shadowRoot&&re(p.shadowRoot)})}},re=d=>{if(!d||P.has(d))return;D(d);let p=new MutationObserver(f=>{for(let v of f)v.addedNodes?.forEach(z=>{D(z)}),v.type==="attributes"&&v.target&&D(v.target)});p.observe(d,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[l,...i.map(f=>f.selector).filter(f=>f.startsWith("data-"))]}),P.set(d,p)};async function Se(){if(clearTimeout(h),h=0,!m.size)return;let d=Array.from(m);m.clear(),d.forEach(p=>L.add(p));try{let p=f=>A.get(f)??(o?o(f):`${f}.js`);await ut(...d,{baseURL:n,mapper:p,onError:(f,v)=>{_.add(f),c?.(f,v)}})}catch{}finally{d.forEach(p=>L.delete(p))}}let _e=g===document?document.documentElement:g,be=new MutationObserver(d=>{for(let p of d)p.addedNodes?.forEach(f=>{D(f)}),p.type==="attributes"&&p.target&&D(p.target)});if(be.observe(_e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[l,...i.map(d=>d.selector).filter(d=>d.startsWith("data-"))]}),a&&S&&Element.prototype.attachShadow){let d=Element.prototype.attachShadow;Element.prototype.attachShadow=function(f){let v=d.call(this,f);if(f&&f.mode==="open"){re(v);let z=this.tagName?.toLowerCase();z&&z.includes("-")&&!customElements.get(z)&&M(z,this)}return v},R=()=>Element.prototype.attachShadow=d}return y&&D(_e),{stop(){w=!0,be.disconnect(),R&&R(),h&&(clearTimeout(h),h=0),P.forEach(d=>d.disconnect())},flush:Se}}static async define(...t){let n={};t.length&&typeof t[t.length-1]=="object"&&(n=t.pop()||{});let o=t,{baseURL:c,mapper:s=a=>`${a}.js`,onError:l=(a,i)=>console.error(`[defineWebComponents] ${a}:`,i)}=n,g=c?new URL(c,typeof location<"u"?location.href:import.meta.url):new URL("./",import.meta.url),y=a=>a.toLowerCase().replace(/(^|-)([a-z])/g,(i,S,m)=>m.toUpperCase()),u=async a=>{try{if(customElements.get(a))return{tag:a,status:"already-defined"};let i=s(a),m=await import(i instanceof URL?i.href:new URL(i,g).href),L=m?.default??m?.[y(a)];if(!L){if(customElements.get(a))return{tag:a,status:"self-defined"};throw new Error(`No export found for ${a}. Expected default export or named export "${y(a)}".`)}return customElements.get(a)?{tag:a,status:"race-already-defined"}:(customElements.define(a,L),{tag:a,status:"defined"})}catch(i){throw l(a,i),i}};return Promise.all(o.map(u))}};var dt=/^[a-z][a-z0-9+\-.]*:\/\//i,j=(()=>{try{return import.meta.url}catch{return}})(),K=e=>typeof e=="string"&&e.length&&!e.endsWith("/")?`${e}/`:e;function G(e,t={}){if(!e||dt.test(e))return e;let{preferModule:n=!0}=t,o=()=>{if(!j)return null;try{return new URL(e,j).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?o()||c():c()||o())||e}var ze=(()=>{if(j)try{let e=new URL(j);if(/\/public\/assets\/js\//.test(e.pathname))return new URL("../pds/",j).href}catch{return}})(),Ce=!1;function Te(e){Ce||typeof document>"u"||(Ce=!0,e.addEventListener("pds:ready",t=>{let n=t.detail?.mode;n&&document.documentElement.classList.add(`pds-${n}`,"pds-ready")}))}function ke({manageTheme:e,themeStorageKey:t,applyResolvedTheme:n,setupSystemListenerIfNeeded:o}){let c="light",s=null;if(e&&typeof window<"u"){try{s=localStorage.getItem(t)||null}catch{s=null}try{n?.(s),o?.(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 q(e,{resolvePublicAssetURL:t}){let n=!!(e?.public?.root||e?.static?.root),o=t(e);return!n&&ze&&(o=ze),K(G(o))}async function Me(e,{baseEnhancers:t=[]}={}){let{autoDefineBaseURL:n="/auto-define/",autoDefinePreload:o=[],autoDefineMapper:c=null,enhancers:s=[],autoDefineOverrides:l=null,autoDefinePreferModule:g=!0}=e,y=(()=>{let a=new Map;return(t||[]).forEach(i=>a.set(i.selector,i)),(s||[]).forEach(i=>a.set(i.selector,i)),Array.from(a.values())})(),u=null;if(typeof window<"u"&&typeof document<"u"){let a=B,i=h=>{switch(h){case"pds-tabpanel":return"pds-tabstrip.js";default:return`${h}.js`}},{mapper:S,enhancers:m,...L}=l&&typeof l=="object"?l:{},_=m?Array.isArray(m)?m:typeof m=="object"?Object.values(m):[]:[],A=(()=>{let h=new Map;return(y||[]).forEach(w=>{w?.selector&&h.set(w.selector,w)}),(_||[]).forEach(w=>{if(!w?.selector)return;let R=h.get(w.selector)||null;h.set(w.selector,{...R||{},...w,run:typeof w?.run=="function"?w.run:R?.run})}),Array.from(h.values())})(),E={baseURL:n&&K(G(n,{preferModule:g})),predefine:o,scanExisting:!0,observeShadows:!0,patchAttachShadow:!0,debounceMs:16,enhancers:A,onError:(h,w)=>{if(typeof h=="string"&&h.startsWith("pds-")){let F=["pds-form","pds-drawer"].includes(h),M=w?.message?.includes("#pds/lit")||w?.message?.includes("Failed to resolve module specifier");F&&M?r.log("error",`\u274C PDS component <${h}> 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`):r.log("warn",`\u26A0\uFE0F PDS component <${h}> not found. Assets may not be installed.`)}else r.log("error",`\u274C Auto-define error for <${h}>:`,w)},...L,mapper:h=>{if(customElements.get(h))return null;if(typeof c=="function")try{let w=c(h);return w===void 0?i(h):w}catch(w){return r.log("warn","Custom autoDefine.mapper error; falling back to default:",w?.message||w),i(h)}return i(h)}};u=new a(E),o.length>0&&typeof a.define=="function"&&await a.define(...o,{baseURL:n,mapper:E.mapper,onError:E.onError})}return{autoDefiner:u,mergedEnhancers:y}}var de=["light","dark"],fe=new Set(de);function ft(e){let n=(Array.isArray(e?.themes)?e.themes.map(o=>String(o).toLowerCase()):de).filter(o=>fe.has(o));return n.length?n:de}function pe(e,{preferDocument:t=!0}={}){let n=String(e||"").toLowerCase();if(fe.has(n))return n;if(t&&typeof document<"u"){let o=document.documentElement?.getAttribute("data-theme");if(fe.has(o))return o}return typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Ue(e,t){let n=pe(t);return ft(e).includes(n)}var pt=new Set(["log","warn","error","debug","info"]),mt="__PURE_DS_PDS_SINGLETON__",me=null,he=null;function Oe(){try{let t=(typeof globalThis<"u"?globalThis:window)?.[mt];if(t&&typeof t=="object")return t}catch{return null}return null}function ht(e){return!e||typeof e!="object"?null:{mode:e.mode==="live"||e.mode==="static"?e.mode:null,debug:e.debug===!0,thisArg:e.thisArg}}function yt(e){if(typeof e!="string")return"log";let t=e.toLowerCase();return pt.has(t)?t:"log"}function gt(){if(typeof he=="function")try{let t=ht(he());if(t)return t}catch{}let e=Oe();if(e){let t=e?.mode||e?.compiled?.mode||(e?.registry?.isLive?"live":"static"),n=(e?.debug||e?.currentConfig?.debug||e?.currentConfig?.design?.debug||e?.compiled?.debug||e?.compiled?.design?.debug||!1)===!0;return{mode:t,debug:n,thisArg:e}}return{mode:null,debug:!1}}function wt(){if(typeof me=="function")try{let t=me();if(typeof t=="function")return t}catch{}let e=Oe();return typeof e?.logHandler=="function"?e.logHandler:null}function je(e,t,...n){if(typeof console>"u")return;let o=typeof console[e]=="function"?console[e].bind(console):typeof console.log=="function"?console.log.bind(console):null;o&&(n.length>0?o(t,...n):o(t))}function St(e,t){let n=t?.debug===!0;return!(t?.mode==="static"&&!n||!n&&e!=="error"&&e!=="warn")}function Ne({getLogger:e,getContext:t}={}){me=typeof e=="function"?e:null,he=typeof t=="function"?t:null}function $e(e="log",t,...n){let o=yt(e),c=gt(),s=wt();if(s)try{s.call(c?.thisArg,o,t,...n);return}catch(l){je("error","Custom log handler failed:",l)}St(o,c)&&je(o,t,...n)}typeof r.initializing!="boolean"&&(r.initializing=!1);"currentPreset"in r||(r.currentPreset=null);typeof r.debug!="boolean"&&(r.debug=!1);"currentConfig"in r||(r.currentConfig=null);"compiled"in r||(r.compiled=null);typeof r.logHandler!="function"&&(r.logHandler=null);"mode"in r||(r.mode=null);var J=null,V=null,Y=null,Q=null,Z=null,X=null,Fe="__pdsLocalizationRuntime";function T(){if(X)return X;let e=r?.[Fe];return e&&typeof e=="object"?(X=e,e):null}function _t(e){let t=e&&typeof e=="object"?e:null;X=t,r[Fe]=t}Ne({getLogger:()=>typeof r.logHandler=="function"?r.logHandler:null,getContext:()=>{let e=r?.mode||r?.compiled?.mode||(r?.registry?.isLive?"live":"static"),t=(r?.debug||r?.currentConfig?.debug||r?.currentConfig?.design?.debug||r?.compiled?.debug||r?.compiled?.design?.debug||!1)===!0;return{mode:e,debug:t,thisArg:r}}});r.log=(e="log",t,...n)=>{$e(e,t,...n)};var b={locale:"en",messages:{},hasProvider:!1},ee=new Set;function We(e){return!!e&&typeof e!="string"&&typeof e=="object"&&"strTag"in e}function He(e=[]){let t="";for(let n=0;n<=e.length-1;n+=1)t+=e[n],n<e.length-1&&(t+=`{${n}}`);return t}function bt(e,t){return String(e).replace(/\{(\d+)\}/g,(n,o)=>t(Number(o)))}function Lt(e){if(!e||typeof e!="object")return{};let t={};for(let[n,o]of Object.entries(e)){if(typeof o=="string"){t[n]=o;continue}o&&typeof o=="object"&&typeof o.content=="string"&&(t[n]=o.content)}return t}function Et(e,...t){return{strTag:!0,strings:Array.from(e||[]),values:t,raw:Array.from(e?.raw||[])}}function At(e){if(!e)return"";if(We(e)){let n=He(e.strings||[]),o=b.messages[n]||n;return bt(o,c=>e.values?.[c])}let t=String(e);return b.messages[t]||t}function vt(e){if(!e)return;let t=We(e)?He(e.strings||[]):String(e);typeof t=="string"&&t.length>0&&ee.add(t)}function Be(e){if(!e||typeof e.msg!="function"||ee.size===0)return;let t=Array.from(ee);ee.clear();for(let n of t)try{e.msg(n)}catch{}}async function N(){let e=T();return e||(Z||(Z=import($("pds-localization.js")).then(n=>{if(typeof n?.msg!="function"||typeof n?.str!="function"||typeof n?.configureLocalization!="function"||typeof n?.loadLocale!="function"||typeof n?.setLocale!="function"||typeof n?.getLocalizationState!="function")throw new Error("Failed to load localization runtime exports");return _t(n),Be(n),n}).catch(n=>{throw Z=null,n})),Z)}var Ke=(e,t={})=>{let n=T();return typeof n?.msg=="function"?n.msg(e,t):(vt(e),At(e,t))},Ge=(e,...t)=>{let n=T();return typeof n?.str=="function"?n.str(e,...t):Et(e,...t)},te=(e=null)=>{let t=T();if(typeof t?.configureLocalization=="function")return t.configureLocalization(e);if(!e||typeof e!="object")return b.locale="en",b.messages={},b.hasProvider=!1,{locale:b.locale,messages:{...b.messages},hasProvider:b.hasProvider};typeof e.locale=="string"&&e.locale.trim()&&(b.locale=e.locale.trim()),Object.prototype.hasOwnProperty.call(e,"messages")&&(b.messages=Lt(e.messages));let n=!!(e.provider||e.translate||e.loadLocale||e.setLocale);return b.hasProvider=n,n&&N().then(o=>{o.configureLocalization(e),Be(o)}).catch(()=>{}),{locale:b.locale,messages:{...b.messages},hasProvider:b.hasProvider}},qe=async e=>(await N()).loadLocale(e),Je=async(e,t={})=>(await N()).setLocale(e,t),Ve=()=>{let e=T();return typeof e?.getLocalizationState=="function"?e.getLocalizationState():{locale:b.locale,messages:{...b.messages},hasProvider:b.hasProvider}},Ye=(e={})=>{let t=T();if(typeof t?.createJSONLocalization=="function")return t.createJSONLocalization(e);let n=typeof e?.locale=="string"&&e.locale.trim()?e.locale.trim().toLowerCase():"en",o=Array.isArray(e?.locales)?e.locales.map(y=>String(y||"").trim().toLowerCase()).filter(Boolean):[],c=Array.from(new Set([n,...o])),s=null,l=async()=>(s||(s=N().then(y=>typeof y?.createJSONLocalization=="function"?y.createJSONLocalization(e):null).catch(()=>null)),s),g=async(y="loadLocale")=>{let u=await l();if(!u||typeof u!="object")return null;let a=u.provider;if(!a||typeof a!="object")return null;let i=a[y];return typeof i=="function"?i:y==="setLocale"&&typeof a.loadLocale=="function"?a.loadLocale:null};return{locale:n,locales:[...c],provider:{locales:[...c],async loadLocale(y={}){let u=await g("loadLocale");return typeof u!="function"?{}:u(y)},async setLocale(y={}){let u=await g("setLocale");return typeof u!="function"?{}:u(y)}}}};function $(e,t){return t&&typeof t=="string"?t:`${q(r.currentConfig||{},{resolvePublicAssetURL:H})}core/${e}`}async function Pt(){return Array.isArray(r.defaultEnhancers)&&r.defaultEnhancers.length>0?r.defaultEnhancers:(Q||(Q=import($("pds-enhancers.js",r.currentConfig?.enhancersURL)).then(t=>{let n=Array.isArray(t?.defaultPDSEnhancers)?t.defaultPDSEnhancers:[];return r.defaultEnhancers=n,n}).catch(t=>{throw Q=null,t})),Q)}async function Rt(){return typeof r.ask=="function"&&r.ask!==Qe?r.ask:(V||(V=import($("pds-ask.js",r.currentConfig?.askURL)).then(t=>{let n=t?.ask;if(typeof n!="function")throw new Error("Failed to load ask helper");return r.ask=n,n}).catch(t=>{throw V=null,t})),V)}async function I(){return typeof r.toast=="function"&&r.toast!==k?r.toast:(Y||(Y=import($("pds-toast.js",r.currentConfig?.toastURL)).then(t=>{let n=t?.toast;if(typeof n!="function")throw new Error("Failed to load toast helper");return r.toast=n,n}).catch(t=>{throw Y=null,t})),Y)}async function Qe(...e){return(await Rt())(...e)}async function k(...e){return(await I())(...e)}k.success=async(...e)=>(await I()).success(...e);k.error=async(...e)=>(await I()).error(...e);k.warning=async(...e)=>(await I()).warning(...e);k.info=async(...e)=>(await I()).info(...e);var Ie=function(e="log",t,...n){r.log(e,t,...n)};function ge(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=>ge(n)).filter(n=>n!==void 0);let t={};for(let[n,o]of Object.entries(e)){let c=ge(o);c!==void 0&&(t[n]=c)}return t}function Ze(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))Ze(e[n],t);return e}function we(e){return e==null||typeof e!="object"?e:Ze(structuredClone(ge(e)))}async function xt(e,t={}){if(t?.runtimeConfig===!1||typeof fetch!="function")return null;let n=t?.runtimeConfigURL||`${e}pds-runtime-config.json`;try{let o=await fetch(n,{cache:"no-store"});return o.ok?await o.json():null}catch{return null}}r.registry=C;r.enums=Pe;r.adoptLayers=Ae;r.adoptPrimitives=Ee;r.parse=le;r.createStylesheet=ve;r.isLiveMode=()=>C.isLive;r.ask=Qe;r.toast=k;r.common=ue;r.msg=Ke;r.str=Ge;r.configureLocalization=te;r.loadLocale=qe;r.setLocale=Je;r.getLocalizationState=Ve;r.createJSONLocalization=Ye;r.i18n={msg:Ke,str:Ge,configure:te,loadLocale:qe,setLocale:Je,getState:Ve,createJSONLocalization:Ye};r.AutoComplete=null;r.loadAutoComplete=async()=>{if(r.AutoComplete&&typeof r.AutoComplete.connect=="function")return r.AutoComplete;let e=$("pds-autocomplete.js",r.currentConfig?.autoCompleteURL);return J||(J=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 r.AutoComplete=n,n}).catch(t=>{throw J=null,t})),J};function Xe(e){let t=typeof CustomEvent=="function";try{let n=t?new CustomEvent("pds:ready",{detail:e}):new Event("pds:ready");r.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 et(e={}){let t=typeof CustomEvent=="function",n={at:Date.now(),...e};try{let o=t?new CustomEvent("pds:config-changed",{detail:n}):new Event("pds:config-changed");r.dispatchEvent(o)}catch{}if(typeof document<"u")if(t){let o={detail:n,bubbles:!0,composed:!0};try{document.dispatchEvent(new CustomEvent("pds:config-changed",o))}catch{}}else try{document.dispatchEvent(new Event("pds:config-changed"))}catch{}}var ye="pure-ds-theme",x=null,O=null;function ne(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 oe(e){try{if(x&&O){try{typeof x.removeEventListener=="function"?x.removeEventListener("change",O):typeof x.removeListener=="function"&&x.removeListener(O)}catch{}x=null,O=null}if(e==="system"&&typeof window<"u"&&window.matchMedia){let t=window.matchMedia("(prefers-color-scheme: dark)"),n=o=>{let c=o?.matches===void 0?t.matches:o.matches;try{let s=c?"dark":"light";document.documentElement.setAttribute("data-theme",s),r.dispatchEvent(new CustomEvent("pds:theme:changed",{detail:{theme:s,source:"system"}}))}catch{}};x=t,O=n,typeof t.addEventListener=="function"?t.addEventListener("change",n):typeof t.addListener=="function"&&t.addListener(n)}}catch{}}var Dt=Object.getOwnPropertyDescriptor(r,"theme");Dt||Object.defineProperty(r,"theme",{get(){try{return typeof window>"u"?null:localStorage.getItem(ye)||null}catch{return null}},set(e){try{if(typeof window>"u")return;let t=r.currentConfig?.design||null,n=pe(e);if(t&&!Ue(t,n)){let o=t?.name||r.currentPreset?.name||r.currentConfig?.preset||"current preset";r.log("warn",`PDS theme "${n}" not supported by preset "${o}".`),r.dispatchEvent(new CustomEvent("pds:theme:blocked",{detail:{theme:e,resolvedTheme:n,preset:o}}));return}e==null?localStorage.removeItem(ye):localStorage.setItem(ye,e),ne(e),oe(e),r.dispatchEvent(new CustomEvent("pds:theme:changed",{detail:{theme:e,source:"api"}}))}catch{}}});r.defaultEnhancers=[];async function zt(e){r.initializing=!0;try{let t=e&&e.mode||"live",{mode:n,...o}=e||{};r.mode=t,r.logHandler=typeof o?.log=="function"?o.log:null,r.currentConfig=we(o);let c=o&&typeof o.localization=="object"&&o.localization?o.localization:null;c?(await N(),te(c)):te(null);let s;if(t==="static")s=await Ct(o);else{let{localization:g,...y}=o||{},u=q(y,{resolvePublicAssetURL:H}),a=y?.managerURL||y?.public?.managerURL||y?.manager?.url||new URL("core/pds-manager.js",u).href||new URL("./pds-manager.js",import.meta.url).href,{startLive:i}=await import(a);s=await i(r,y,{emitReady:Xe,emitConfigChanged:et,applyResolvedTheme:ne,setupSystemListenerIfNeeded:oe})}r.compiled=we(s?.config||null);let l=r?.compiled?.design?.icons?.externalPath||"/assets/img/icons/";return r.log("info",`startup ready; external icon path: ${l}`),s}finally{r.initializing=!1}}r.start=zt;async function Ct(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,o=e.themeStorageKey??"pure-ds-theme",c=e.staticPaths??{},s=q(e,{resolvePublicAssetURL:H}),l=e&&e.autoDefine||null,g;l&&l.baseURL?g=K(G(l.baseURL,{preferModule:!1})):g=`${s}components/`;let y=l&&Array.isArray(l.predefine)&&l.predefine||[],u=l&&typeof l.mapper=="function"&&l.mapper||null;try{Te(r);let{resolvedTheme:a}=ke({manageTheme:n,themeStorageKey:o,applyResolvedTheme:ne,setupSystemListenerIfNeeded:oe}),i=await xt(s,e),S=Array.isArray(e?.enhancers)?e.enhancers:e?.enhancers&&typeof e.enhancers=="object"?Object.values(e.enhancers):[],m=i?.config?{...i.config,...e,design:e?.design||i.config.design,preset:e?.preset||i.config.preset}:{...e},L={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`},_=i?.paths||{};if(c={...L,..._,...c},r.registry.setStaticMode(c),t&&typeof document<"u")try{let E=await r.registry.getStylesheet("styles");if(E){E._pds=!0;let h=(document.adoptedStyleSheets||[]).filter(w=>w._pds!==!0);document.adoptedStyleSheets=[...h,E],et({mode:"static",source:"static:styles-applied"})}}catch(E){Ie.call(r,"warn","Failed to apply static styles:",E)}let A=null,P=[];try{let E=await Pt(),h=await Me({autoDefineBaseURL:g,autoDefinePreload:y,autoDefineMapper:u,enhancers:S,autoDefineOverrides:l||null,autoDefinePreferModule:!(l&&l.baseURL)},{baseEnhancers:E});A=h.autoDefiner,P=h.mergedEnhancers||[]}catch(E){Ie.call(r,"error","\u274C Failed to initialize AutoDefiner/Enhancers (static):",E)}return r.compiled=we({mode:"static",...m,theme:a,enhancers:P}),Xe({mode:"static",config:m,theme:a,autoDefiner:A}),{config:m,theme:a,autoDefiner:A}}catch(a){throw r.dispatchEvent(new CustomEvent("pds:error",{detail:{error:a}})),a}}var tn=ne,nn=oe;export{r as PDS,tn as applyResolvedTheme,te as configureLocalization,Ye as createJSONLocalization,Ve as getLocalizationState,qe as loadLocale,Ke as msg,Je as setLocale,nn as setupSystemListenerIfNeeded,Ge as str};
@@ -162,7 +162,8 @@ export class SvgIcon extends HTMLElement {
162
162
  const attrIcon = this.getAttribute('icon') || 'missing';
163
163
  const icon = this._morphing ? (this._currentIcon || attrIcon) : attrIcon;
164
164
  const sizeAttr = this.getAttribute('size') || '24';
165
- const color = this.getAttribute('color') || 'currentColor';
165
+ const colorAttr = this.getAttribute('color');
166
+ const color = colorAttr || 'currentColor';
166
167
  const label = this.getAttribute('label');
167
168
  const spriteOverride = this.getAttribute('sprite');
168
169
  const rotate = this.getAttribute('rotate') || '0';
@@ -379,6 +380,13 @@ export class SvgIcon extends HTMLElement {
379
380
  return;
380
381
  }
381
382
 
383
+ // Keep host color in sync for external SVGs that rely on fill="currentColor".
384
+ if (colorAttr) {
385
+ this.style.setProperty('color', colorAttr);
386
+ } else {
387
+ this.style.removeProperty('color');
388
+ }
389
+
382
390
  this._stackEl.setAttribute('class', `icon-stack${morphClass ? ` ${morphClass}` : ''}`);
383
391
  this._stackEl.style.width = `${size}px`;
384
392
  this._stackEl.style.height = `${size}px`;
@@ -65,6 +65,7 @@ export class PdsOmnibox extends HTMLElement {
65
65
  #lengthProbe;
66
66
  #suggestionsUpdatedHandler;
67
67
  #suggestionsObserver;
68
+ #overlayOverflowOverrides = new Map();
68
69
 
69
70
  constructor() {
70
71
  super();
@@ -96,6 +97,7 @@ export class PdsOmnibox extends HTMLElement {
96
97
  }
97
98
  this.#teardownAutoCompleteSizing();
98
99
  this.#teardownSuggestionsObserver();
100
+ this.#setOverlayClippingOverride(false);
99
101
  const autoComplete = this.#input?._autoComplete;
100
102
  if (autoComplete) {
101
103
  autoComplete.controller?.().clear?.("disconnected");
@@ -765,6 +767,7 @@ export class PdsOmnibox extends HTMLElement {
765
767
  this.#suggestionsObserver = new MutationObserver(() => {
766
768
  if (!suggestion.classList.contains("ac-active")) {
767
769
  this.removeAttribute("data-suggestions-open");
770
+ this.#setOverlayClippingOverride(false);
768
771
  this.#clearSuggestionOverlayStyles(suggestion);
769
772
  this.#resetIconToDefault();
770
773
  }
@@ -819,7 +822,7 @@ export class PdsOmnibox extends HTMLElement {
819
822
  return null;
820
823
  }
821
824
 
822
- #hasTransformedAncestor(startNode) {
825
+ #getFixedContainingBlock(startNode) {
823
826
  let current = startNode;
824
827
  let safety = 0;
825
828
  while (current && safety < 80) {
@@ -831,19 +834,21 @@ export class PdsOmnibox extends HTMLElement {
831
834
  style.filter !== "none" ||
832
835
  style.backdropFilter !== "none"
833
836
  ) {
834
- return true;
837
+ return current;
835
838
  }
836
839
  }
837
840
  current = this.#getComposedParent(current);
838
841
  safety += 1;
839
842
  }
840
- return false;
843
+ return null;
841
844
  }
842
845
 
843
846
  #shouldUseFixedSuggestionOverlay(container) {
844
847
  if (!container) return false;
845
- if (this.closest("pds-drawer, dialog")) return false;
846
- return !this.#hasTransformedAncestor(this);
848
+
849
+ // Always prefer viewport overlay positioning so results are not clipped by
850
+ // parent overflow containers (for example dialog bodies or drawers).
851
+ return true;
847
852
  }
848
853
 
849
854
  #positionSuggestionInline({ container, suggestion, rect, direction, offset, maxHeight }) {
@@ -865,6 +870,7 @@ export class PdsOmnibox extends HTMLElement {
865
870
  container,
866
871
  suggestion,
867
872
  rect,
873
+ containingBlock,
868
874
  viewportHeight,
869
875
  viewportWidth,
870
876
  direction,
@@ -878,21 +884,28 @@ export class PdsOmnibox extends HTMLElement {
878
884
  return;
879
885
  }
880
886
 
887
+ const blockRect = containingBlock?.getBoundingClientRect?.();
888
+ const originLeft = Number.isFinite(blockRect?.left) ? blockRect.left : 0;
889
+ const originTop = Number.isFinite(blockRect?.top) ? blockRect.top : 0;
890
+ const blockBottom = Number.isFinite(blockRect?.bottom)
891
+ ? blockRect.bottom
892
+ : viewportHeight;
893
+
881
894
  const clampedLeft = Math.max(gap, Math.min(rect.left, viewportWidth - rect.width - gap));
882
895
  const clampedWidth = Math.max(0, Math.min(rect.width, viewportWidth - gap * 2));
883
896
 
884
897
  suggestion.style.position = "fixed";
885
- suggestion.style.left = `${Math.round(clampedLeft)}px`;
898
+ suggestion.style.left = `${Math.round(clampedLeft - originLeft)}px`;
886
899
  suggestion.style.width = `${Math.round(clampedWidth)}px`;
887
900
  suggestion.style.maxWidth = `${Math.round(Math.max(0, viewportWidth - gap * 2))}px`;
888
901
  suggestion.style.right = "auto";
889
902
 
890
903
  if (direction === "up") {
891
904
  suggestion.style.top = "auto";
892
- suggestion.style.bottom = `${Math.round(viewportHeight - rect.top + offset)}px`;
905
+ suggestion.style.bottom = `${Math.round(blockBottom - rect.top + offset)}px`;
893
906
  } else {
894
907
  suggestion.style.bottom = "auto";
895
- suggestion.style.top = `${Math.round(rect.bottom + offset)}px`;
908
+ suggestion.style.top = `${Math.round(rect.bottom - originTop + offset)}px`;
896
909
  }
897
910
 
898
911
  container.setAttribute("data-direction", direction);
@@ -900,6 +913,68 @@ export class PdsOmnibox extends HTMLElement {
900
913
  container.style.setProperty("--ac-max-height", `${maxHeight}px`);
901
914
  }
902
915
 
916
+ #collectClippingAncestors(startNode, stopAt) {
917
+ const targets = [];
918
+ let current = this.#getComposedParent(startNode);
919
+
920
+ while (current instanceof Element) {
921
+ const tagName = String(current.tagName || "").toUpperCase();
922
+ if (tagName === "HTML" || tagName === "BODY") {
923
+ break;
924
+ }
925
+
926
+ const style = getComputedStyle(current);
927
+ const clips = [style.overflow, style.overflowX, style.overflowY].some(
928
+ (value) => value && value !== "visible",
929
+ );
930
+
931
+ if (clips) {
932
+ targets.push(current);
933
+ }
934
+
935
+ if (stopAt && current === stopAt) {
936
+ break;
937
+ }
938
+
939
+ current = this.#getComposedParent(current);
940
+ }
941
+
942
+ return targets;
943
+ }
944
+
945
+ #setOverlayClippingOverride(enabled, stopAt) {
946
+ if (enabled) {
947
+ if (this.#overlayOverflowOverrides.size) {
948
+ return;
949
+ }
950
+
951
+ const startNode = this.#input?.parentElement || this;
952
+ const targets = this.#collectClippingAncestors(startNode, stopAt);
953
+
954
+ targets.forEach((element) => {
955
+ this.#overlayOverflowOverrides.set(element, {
956
+ overflow: element.style.overflow,
957
+ overflowX: element.style.overflowX,
958
+ overflowY: element.style.overflowY,
959
+ });
960
+
961
+ element.style.overflow = "visible";
962
+ element.style.overflowX = "visible";
963
+ element.style.overflowY = "visible";
964
+ });
965
+
966
+ return;
967
+ }
968
+
969
+ this.#overlayOverflowOverrides.forEach((previous, element) => {
970
+ element.style.overflow = previous.overflow;
971
+ element.style.overflowX = previous.overflowX;
972
+ element.style.overflowY = previous.overflowY;
973
+ });
974
+
975
+ this.#overlayOverflowOverrides.clear();
976
+ }
977
+
903
978
  #updateSuggestionMaxHeight() {
904
979
  if (!this.#input) return;
905
980
  const container = this.#input.parentElement;
@@ -908,6 +983,7 @@ export class PdsOmnibox extends HTMLElement {
908
983
  const rect = container.getBoundingClientRect();
909
984
  const viewportHeight = window.visualViewport?.height || window.innerHeight;
910
985
  const gap = this.#readSpacingToken(container, "--ac-viewport-gap") || 0;
986
+ const containingBlock = this.#getFixedContainingBlock(container);
911
987
  const root = container.shadowRoot ?? container;
912
988
  const suggestion = root?.querySelector?.(".ac-suggestion");
913
989
  const currentDirection =
@@ -948,10 +1024,13 @@ export class PdsOmnibox extends HTMLElement {
948
1024
  this.toggleAttribute("data-suggestions-open", Boolean(isSuggestionActive));
949
1025
 
950
1026
  if (!suggestion || !isSuggestionActive || suggestion.classList.contains("full-mobile")) {
1027
+ this.#setOverlayClippingOverride(false);
951
1028
  this.#clearSuggestionOverlayStyles(suggestion);
952
1029
  return;
953
1030
  }
954
1031
 
1032
+ this.#setOverlayClippingOverride(true, containingBlock);
1033
+
955
1034
  if (!this.#shouldUseFixedSuggestionOverlay(container)) {
956
1035
  this.#positionSuggestionInline({
957
1036
  container,
@@ -969,6 +1048,7 @@ export class PdsOmnibox extends HTMLElement {
969
1048
  container,
970
1049
  suggestion,
971
1050
  rect,
1051
+ containingBlock,
972
1052
  viewportHeight,
973
1053
  viewportWidth,
974
1054
  direction,
@@ -1,7 +1,7 @@
1
- function m(o){return new DOMParser().parseFromString(o,"text/html").body.childNodes}function y(o,t=100){let e;return function(...i){let r=()=>{clearTimeout(e),o(...i)};clearTimeout(e),e=setTimeout(r,t)}}function p(o){setTimeout(o,0)}function b(o){try{if(typeof o!="string"||o.indexOf(`
2
- `)!==-1||o.indexOf(" ")!==-1||o.startsWith("#/"))return!1;let t=new URL(o,window.location.origin);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}}function x(o,t,e){let s=window.screen.width/2-t/2,i=window.screen.height/2-e/2;return window.open(o,"",`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=${t}, height=${e}, top=${i}, left=${s}`)}var g={result:"ac-suggestion",item:"ac-itm"},f=class o extends EventTarget{constructor(t,e,s){super(),this.settings={emptyResultsText:"",...s},this.container=t,this.input=e,this.input.setAttribute("autocomplete","off"),this.categories=s.categories||{},this.caches=new Map,p(this.attach.bind(this))}static connect(t,e){let s=t.target;if(!s._autoComplete){if(!e?.categories)throw Error("Missing autocomplete settings");s._autoComplete=new o(s.parentNode,s,e),t.type==="focus"&&setTimeout(()=>{s._autoComplete.focusHandler(t)},100)}return s._autoComplete}on(t,e){return this.input.addEventListener(t,e),this}attach(){this.resultsDiv=document.createElement("div"),this.resultsDiv.title="",this.resultsDiv.classList.add(g.result),this.container.offsetWidth>100&&(this.resultsDiv.style.width=this.container.offsetWidth),this.resultsDiv.addEventListener("mousedown",this.resultClick.bind(this)),this.container.classList.add("ac-container"),this.input.classList.add("ac-input");let t=getComputedStyle(this.input);this.container.style.setProperty("--ac-bg-default",t.backgroundColor),this.container.style.setProperty("--ac-color-default",t.color);let e=getComputedStyle(this.input).accentColor;e!=="auto"&&this.container.style.setProperty("--ac-accent-color",e),(this.container?.shadowRoot??this.container).appendChild(this.resultsDiv),this.controller().clear("attach"),this.on("input",y(this.inputHandler.bind(this),this.settings.throttleInputMs??300)).on("focus",this.focusHandler.bind(this)).on("focusout",this.blurHandler.bind(this)).on("keyup",this.keyUpHandler.bind(this)).on("keydown",this.keyDownHandler.bind(this))}controller(){let t=this.internalController();return typeof this.settings.controller=="function"&&(t=this.settings.controller(this)??t),t}internalController(){return{show:this.show.bind(this),hide:this.hide.bind(this),clear:this.clear.bind(this),empty:()=>{}}}moveResult(t){this.controller().show();let e=this.acItems.length;this.rowIndex=this.rowIndex+t,this.rowIndex<=0?this.rowIndex=0:this.rowIndex>e-1&&(this.rowIndex=0);for(let i of this.acItems)i.classList.remove("selected");let s=this.getSelectedDiv();s?(s.classList.add("selected"),s.scrollIntoView({behavior:"smooth",block:"end",inline:"nearest"})):this.focusHandler({target:this.input})}getSelectedDiv(){return this.resultsDiv.querySelector(`div:nth-child(${this.rowIndex+1})`)}selectResult(t){if(t=t||this.getSelectedDiv(),t){let e=parseInt(t.getAttribute("data-index"));this.resultClicked=!0;let s=this.results[e],i=this.categories[s.category]??{};i.action=i.action??this.setText.bind(this),i.newTab&&(this.tabWindow=x("about:blank"));let r={...s,search:this.input.value};t.classList.add("ac-active"),setTimeout(()=>{this.controller().hide("result-selected"),r.action?r.action(r):(i.action(r),i.newTab&&(r.url?this.tabWindow.location.href=r.url:this.tabWindow.close()));var n=new Event("change",{bubbles:!0});this.input.dispatchEvent(n),this.controller().clear("result-selected");let u=new Event("result-selected");u.detail=r,this.input.dispatchEvent(u)},0)}}setText(t){let e=!1;this.input?(this.input.value=t.text,e=!0):this.container?.autoCompleteInput?(this.container.autoCompleteInput.value=t.text,e=!0):"value"in this.container&&(this.container.value=t.text,e=!0),e&&this.input&&this.input.dispatchEvent(new Event("input",{bubbles:!0})),this.controller().hide("settext")}resultClick(t){this.selectResult(t.target.closest(`.${g.item}`))}blurHandler(){setTimeout(()=>{this.resultClicked||this.controller().clear("blurred"),this.resultClicked=!1},100)}clear(){this.settings.debug||this.resultsDiv&&(this.resultsDiv.innerHTML="",this.controller().hide("clear"),this.cacheTmr&&clearTimeout(this.cacheTmr),this.cacheTmr=setTimeout(()=>{this.caches.clear()},60*1e3*5))}show(){if(!this.resultsDiv.classList.contains("ac-active")){let t=this.getViewBounds();this.resultsDiv.style.position="absolute",t.rect.width>100&&(this.resultsDiv.style.width=`${t.rect.width}px`),this.settings.direction=this.settings.direction??t.suggestedDirection,this.resultsDiv.setAttribute("data-direction",this.settings.direction),this.settings.direction==="up"?(this.resultsDiv.style.top="unset",this.resultsDiv.style.bottom=`${t.rect.height+20}px`,this.rowIndex=this.acItems.length):(this.resultsDiv.style.bottom="unset",this.resultsDiv.style.top=`${t.rect.height}px`,this.rowIndex=-1),this.resultsDiv.style.maxWidth="unset",this.resultsDiv.classList.toggle("ac-active",!0)}}getViewBounds(){let t=this.input.getBoundingClientRect();return{rect:t,suggestedDirection:t.top+t.height+500>window.innerHeight?"up":"down"}}hide(){this.resultsDiv.classList.toggle("ac-active",!1)}empty(){this.resultsDiv.innerHTML=`<div class="ac-empty">${this.settings.emptyResultsText}</div>`,this.controller().show()}inputHandler(t){this.cacheTmr&&clearTimeout(this.cacheTmr);let e={search:t.target.value,categories:this.categories};this.container.classList.add("search-running"),this.getItems(e,t).then(s=>{this.controller().clear("new-results"),this.resultsHandler(s,e),this.container.classList.remove("search-running")})}keyDownHandler(t){switch(t.key){case"Enter":t.stopPropagation(),t.preventDefault();break;case"ArrowDown":p(this.moveResult(1));break;case"ArrowUp":p(this.moveResult(-1));break}}keyUpHandler(t){switch(t.key){case"Escape":this.controller().hide("escape");break;case"Enter":this.getSelectedDiv()&&(this.container.preventEnter=!0,t.stopPropagation(),t.preventDefault(),this.selectResult(),setTimeout(()=>{this.container.preventEnter=!1},10));break;default:break}}focusHandler(t){this.controller().clear("focus");let e=t.target.value;this.suggest(e,t)}suggest(t,e){this.input.focus();let s={suggest:!0,search:t||"",categories:this.categories};this.getItems(s,e).then(i=>{this.input.dispatchEvent(new CustomEvent("show-results",{detail:{results:i}})),this.resultsHandler(i,s)})}sort(t,e){return t.sort((s,i)=>{let r=e.categories[s.category],n=e.categories[i.category],u=typeof r.sortIndex=="function"?r.sortIndex(e):r.sortIndex??0;return(typeof n.sortIndex=="function"?n.sortIndex(e):n.sortIndex??0)>u?1:-1})}resultsHandler(t,e){this.results=t,this.rowIndex=-1;let s=0,i=(r,n)=>`
3
- <div title="${n.tooltip||""}" data-index="${s}" class="${`${g.item} cat-${n.category} ${n.class??""}`.trim()}"${n.style?` style="${n.style}"`:""}>
1
+ function w(c){return new DOMParser().parseFromString(c,"text/html").body.childNodes}function v(c,t=100){let e;return function(...i){let r=()=>{clearTimeout(e),c(...i)};clearTimeout(e),e=setTimeout(r,t)}}function m(c){setTimeout(c,0)}function I(c){try{if(typeof c!="string"||c.indexOf(`
2
+ `)!==-1||c.indexOf(" ")!==-1||c.startsWith("#/"))return!1;let t=new URL(c,window.location.origin);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}}function A(c,t,e){let s=window.screen.width/2-t/2,i=window.screen.height/2-e/2;return window.open(c,"",`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=${t}, height=${e}, top=${i}, left=${s}`)}var y={result:"ac-suggestion",item:"ac-itm"},p=class c extends EventTarget{constructor(t,e,s){super(),this.settings={emptyResultsText:"",...s},this.container=t,this.input=e,this.input.setAttribute("autocomplete","off"),this.categories=s.categories||{},this.caches=new Map,m(this.attach.bind(this))}static connect(t,e){let s=t.target;if(!s._autoComplete){if(!e?.categories)throw Error("Missing autocomplete settings");s._autoComplete=new c(s.parentNode,s,e),t.type==="focus"&&setTimeout(()=>{s._autoComplete.focusHandler(t)},100)}return s._autoComplete}on(t,e){return this.input.addEventListener(t,e),this}attach(){this.resultsDiv=document.createElement("div"),this.resultsDiv.title="",this.resultsDiv.classList.add(y.result),this.container.offsetWidth>100&&(this.resultsDiv.style.width=this.container.offsetWidth),this.resultsDiv.addEventListener("mousedown",this.resultClick.bind(this)),this.container.classList.add("ac-container"),this.input.classList.add("ac-input");let t=getComputedStyle(this.input);this.container.style.setProperty("--ac-bg-default",t.backgroundColor),this.container.style.setProperty("--ac-color-default",t.color);let e=getComputedStyle(this.input).accentColor;e!=="auto"&&this.container.style.setProperty("--ac-accent-color",e),(this.container?.shadowRoot??this.container).appendChild(this.resultsDiv),this.controller().clear("attach"),this.on("input",v(this.inputHandler.bind(this),this.settings.throttleInputMs??300)).on("focus",this.focusHandler.bind(this)).on("focusout",this.blurHandler.bind(this)).on("keyup",this.keyUpHandler.bind(this)).on("keydown",this.keyDownHandler.bind(this))}controller(){let t=this.internalController();return typeof this.settings.controller=="function"&&(t=this.settings.controller(this)??t),t}internalController(){return{show:this.show.bind(this),hide:this.hide.bind(this),clear:this.clear.bind(this),empty:()=>{}}}moveResult(t){this.controller().show();let e=this.acItems.length;this.rowIndex=this.rowIndex+t,this.rowIndex<=0?this.rowIndex=0:this.rowIndex>e-1&&(this.rowIndex=0);for(let i of this.acItems)i.classList.remove("selected");let s=this.getSelectedDiv();s?(s.classList.add("selected"),s.scrollIntoView({behavior:"smooth",block:"end",inline:"nearest"})):this.focusHandler({target:this.input})}getSelectedDiv(){return this.resultsDiv.querySelector(`div:nth-child(${this.rowIndex+1})`)}selectResult(t){if(t=t||this.getSelectedDiv(),t){let e=parseInt(t.getAttribute("data-index"));this.resultClicked=!0;let s=this.results[e],i=this.categories[s.category]??{};i.action=i.action??this.setText.bind(this),i.newTab&&(this.tabWindow=A("about:blank"));let r={...s,search:this.input.value};t.classList.add("ac-active"),setTimeout(()=>{this.controller().hide("result-selected"),r.action?r.action(r):(i.action(r),i.newTab&&(r.url?this.tabWindow.location.href=r.url:this.tabWindow.close()));var n=new Event("change",{bubbles:!0});this.input.dispatchEvent(n),this.controller().clear("result-selected");let u=new Event("result-selected");u.detail=r,this.input.dispatchEvent(u)},0)}}setText(t){let e=!1;this.input?(this.input.value=t.text,e=!0):this.container?.autoCompleteInput?(this.container.autoCompleteInput.value=t.text,e=!0):"value"in this.container&&(this.container.value=t.text,e=!0),e&&this.input&&this.input.dispatchEvent(new Event("input",{bubbles:!0})),this.controller().hide("settext")}resultClick(t){this.selectResult(t.target.closest(`.${y.item}`))}blurHandler(){setTimeout(()=>{this.resultClicked||this.controller().clear("blurred"),this.resultClicked=!1},100)}clear(){this.settings.debug||this.resultsDiv&&(this.resultsDiv.innerHTML="",this.controller().hide("clear"),this.cacheTmr&&clearTimeout(this.cacheTmr),this.cacheTmr=setTimeout(()=>{this.caches.clear()},60*1e3*5))}show(){if(!this.resultsDiv.classList.contains("ac-active")){let t=this.getViewBounds();this.resultsDiv.style.position="absolute",t.rect.width>100&&(this.resultsDiv.style.width=`${t.rect.width}px`),this.settings.direction=this.settings.direction??t.suggestedDirection,this.resultsDiv.setAttribute("data-direction",this.settings.direction),this.settings.direction==="up"?(this.resultsDiv.style.top="unset",this.resultsDiv.style.bottom=`${t.rect.height+20}px`,this.rowIndex=this.acItems.length):(this.resultsDiv.style.bottom="unset",this.resultsDiv.style.top=`${t.rect.height}px`,this.rowIndex=-1),this.resultsDiv.style.maxWidth="unset",this.resultsDiv.classList.toggle("ac-active",!0)}}getViewBounds(){let t=this.input.getBoundingClientRect();return{rect:t,suggestedDirection:t.top+t.height+500>window.innerHeight?"up":"down"}}hide(){this.resultsDiv.classList.toggle("ac-active",!1)}empty(){this.resultsDiv.innerHTML=`<div class="ac-empty">${this.settings.emptyResultsText}</div>`,this.controller().show()}inputHandler(t){this.cacheTmr&&clearTimeout(this.cacheTmr);let e={search:t.target.value,categories:this.categories};this.container.classList.add("search-running"),this.getItems(e,t).then(s=>{this.controller().clear("new-results"),this.resultsHandler(s,e),this.container.classList.remove("search-running")})}keyDownHandler(t){switch(t.key){case"Enter":t.stopPropagation(),t.preventDefault();break;case"ArrowDown":m(this.moveResult(1));break;case"ArrowUp":m(this.moveResult(-1));break}}keyUpHandler(t){switch(t.key){case"Escape":this.controller().hide("escape");break;case"Enter":this.getSelectedDiv()&&(this.container.preventEnter=!0,t.stopPropagation(),t.preventDefault(),this.selectResult(),setTimeout(()=>{this.container.preventEnter=!1},10));break;default:break}}focusHandler(t){this.controller().clear("focus");let e=t.target.value;this.suggest(e,t)}suggest(t,e){this.input.focus();let s={suggest:!0,search:t||"",categories:this.categories};this.getItems(s,e).then(i=>{this.input.dispatchEvent(new CustomEvent("show-results",{detail:{results:i}})),this.resultsHandler(i,s)})}sort(t,e){return t.sort((s,i)=>{let r=e.categories[s.category],n=e.categories[i.category],u=typeof r.sortIndex=="function"?r.sortIndex(e):r.sortIndex??0;return(typeof n.sortIndex=="function"?n.sortIndex(e):n.sortIndex??0)>u?1:-1})}resultsHandler(t,e){this.results=t,this.rowIndex=-1;let s=0,i=(r,n)=>`
3
+ <div title="${n.tooltip||""}" data-index="${s}" class="${`${y.item} cat-${n.category} ${n.class??""}`.trim()}"${n.style?` style="${n.style}"`:""}>
4
4
  ${this.handleImageOrIcon(n)}
5
5
  <span class="text">${this.formatResultItem(n,e,r)}</span>
6
6
  ${this.settings.hideCategory?"":`<span class="category">${n.category||""}</span>`}
7
- </div>`;t.forEach(r=>{let n=e.categories[r.category]||{};r.element?this.resultsDiv.appendChild(r.element):(r=typeof r=="string"?{text:r}:r,this.resultsDiv.appendChild(m(i(n,r))[0])),s++}),t.length?(this.acItems=this.resultsDiv.querySelectorAll(".ac-itm"),this.controller().show()):e.search.length&&this.controller().empty()}handleImageOrIcon(t){return t.image?`<img src="${t.image}"/>`:typeof this.settings.iconHandler=="function"?this.settings.iconHandler(t):`<svg-icon icon="${t.icon}"></svg-icon>`}formatResultItem(t,e,s){let i=typeof t=="string"?{text:t}:t,r=i.text;return e.search&&(r=r.replace("%search%",e.search),i.description=i.description?.replace("%search%",e.search)),r=this.highlight(r,e.search),i.description&&(r=`<div>${r}</div><small>${i.description}</small>`),s.format&&(r=s.format({item:i,result:r,options:e})),r}highlight(t,e){var s=new RegExp("("+e+")","gi");return t.replace(s,'<span class="txt-hl">$1</span>')}async getItems(t,e){this.aborter&&this.aborter.abort();let s=this.caches.get(t.search);if(s)return s;let i=this.settings.map,r=a=>(typeof a=="string"&&(a={text:a}),a),n=a=>i?a.map(h=>({text:h[i]})):a.map(h=>r(h)),u=a=>(this.settings.max&&this.settings.max>0&&(a.length=this.settings.max),a);return this.aborter=new AbortController,this.aborterSignal=this.aborter.signal,new Promise(a=>{let h=l=>{l=this.sort(l,t),this.settings.cache!==!1&&this.caches.set(t.search,l),a(l)};if(b(this.items)){if(this.settings.minlength>0&&(!t.search||t.search.length<this.settings.minlength)){h([]);return}let l=this.formatSearch(this.items,t);fetch(l).then(c=>{if(c.status===200){c.json().then(d=>{d=n(d),h(u(d.filter(w=>this.isMatch(t,w))))});return}throw Error(`HTTP error ${c.status} - ${l}`)})}else if(Array.isArray(this.items)){let l=!0;this.items=this.items.map(c=>typeof c=="string"?{text:c}:(l=!1,c)),l&&this.container.classList.add("simple"),h(u(n(this.items)))}else if(typeof this.items=="function")t.control=this.container,Promise.resolve(this.items(t,e)).then(c=>{c=c.map(d=>r(d)),c=n(c),h(c)});else return h(Promise.resolve(this.items.apply(this,t)))})}async items(t){let e=[];t.results=[],t.signal=this.aborterSignal;for(var s in t.categories){let i=t.categories[s];if(i.trigger=i.trigger??(()=>!0),t.results=e,i.trigger(t)){let r=[];try{r=await i.getItems(t)}catch(n){console.warn(`Error loading items for omniBox category '${s}'.`,n)}e=e.concat(r.map(n=>(n.category=s,n)))}}return e}formatSearch(t,e){return t.indexOf("%search%")?t.replace("%search%",e.search||""):t+"?"+this.createQueryParam(e)}createQueryParam(t){let e=t.suggest?"&suggest=true":"";return`q=${t.text}${e}`}isMatch(t,e){return e.text?.indexOf("%search%")>=0?!0:t.search?e.text?.toLowerCase().indexOf(t.search.toLowerCase())>=0:t.suggest}static textFilter(t,e){return function(s){if(!t.search)return!0;if(s.hidden)return!1;let r=(e?s[e]:s).match(new RegExp(t.search,"gi"));if(r)return r;if(s.config?.tags)return s.config.tags.some(n=>n.match(new RegExp(t.search,"gi")))}}};export{f as AutoComplete};
7
+ </div>`;t.forEach(r=>{let n=e.categories[r.category]||{};r.element?this.resultsDiv.appendChild(r.element):(r=typeof r=="string"?{text:r}:r,this.resultsDiv.appendChild(w(i(n,r))[0])),s++}),t.length?(this.acItems=this.resultsDiv.querySelectorAll(".ac-itm"),this.controller().show()):e.search.length&&this.controller().empty()}handleImageOrIcon(t){return t.image?`<img src="${t.image}"/>`:typeof this.settings.iconHandler=="function"?this.settings.iconHandler(t):`<svg-icon icon="${t.icon}"></svg-icon>`}formatResultItem(t,e,s){let i=typeof t=="string"?{text:t}:t,r=i.text;return e.search&&(r=r.replace("%search%",e.search),i.description=i.description?.replace("%search%",e.search)),r=this.highlight(r,e.search),i.description&&(r=`<div>${r}</div><small>${i.description}</small>`),s.format&&(r=s.format({item:i,result:r,options:e})),r}highlight(t,e){var s=new RegExp("("+e+")","gi");return t.replace(s,'<span class="txt-hl">$1</span>')}async getItems(t,e){this.aborter&&this.aborter.abort();let s=this.caches.get(t.search);if(s)return s;let i=this.settings.map,r=l=>(typeof l=="string"&&(l={text:l}),l),n=l=>i?l.map(h=>({text:h[i]})):l.map(h=>r(h)),u=l=>(this.settings.max&&this.settings.max>0&&(l.length=this.settings.max),l);return this.aborter=new AbortController,this.aborterSignal=this.aborter.signal,new Promise(l=>{let h=o=>{o=this.sort(o,t),this.settings.cache!==!1&&this.caches.set(t.search,o),l(o)};if(I(this.items)){if(this.settings.minlength>0&&(!t.search||t.search.length<this.settings.minlength)){h([]);return}let o=this.formatSearch(this.items,t);fetch(o).then(a=>{if(a.status===200){a.json().then(d=>{d=n(d),h(u(d.filter(g=>this.isMatch(t,g))))});return}throw Error(`HTTP error ${a.status} - ${o}`)})}else if(Array.isArray(this.items)){let o=!0;this.items=this.items.map(a=>typeof a=="string"?{text:a}:(o=!1,a)),o&&this.container.classList.add("simple"),h(u(n(this.items)))}else if(typeof this.items=="function")t.control=this.container,Promise.resolve(this.items(t,e)).then(a=>{a=a.map(d=>r(d)),a=n(a),h(a)});else return h(Promise.resolve(this.items.apply(this,t)))})}async items(t){let e=[];t.results=[],t.signal=this.aborterSignal;for(var s in t.categories){let i=t.categories[s];if(i.trigger=i.trigger??(()=>!0),t.results=e,i.trigger(t)){let r=[];try{r=await i.getItems(t)}catch(n){console.warn(`Error loading items for omniBox category '${s}'.`,n)}e=e.concat(r.map(n=>(n.category=s,n)))}}return e}formatSearch(t,e){return t.indexOf("%search%")?t.replace("%search%",e.search||""):t+"?"+this.createQueryParam(e)}createQueryParam(t){let e=t.suggest?"&suggest=true":"";return`q=${t.text}${e}`}isMatch(t,e){return e.text?.indexOf("%search%")>=0?!0:t.search?e.text?.toLowerCase().indexOf(t.search.toLowerCase())>=0:t.suggest}static textFilter(t,e){return function(s){if(!t.search)return!0;if(s.hidden)return!1;let r=(e?s[e]:s).match(new RegExp(t.search,"gi"));if(r)return r;if(s.config?.tags)return s.config.tags.some(n=>n.match(new RegExp(t.search,"gi")))}}};var b=p?.prototype?.selectResult;typeof b=="function"&&p?.prototype?.__pdsSelectedItemPatched!==!0&&(p.prototype.selectResult=function(t){let e=t||this.getSelectedDiv?.();if(!e)return b.call(this,t);let s=e.getAttribute?.("data-index")??"",i=Number.parseInt(s,10),r=Number.isInteger(i)?this.results?.[i]:null,n=r&&this.categories?this.categories[r.category]:null,u=[],l=(o,a)=>{if(!o||typeof o[a]!="function")return;let d=o[a],g=!1,x=()=>{g||(o[a]=d,g=!0)};o[a]=function(f={},...C){try{return f&&typeof f=="object"&&!("selectedItem"in f)&&(f.selectedItem=e),d.call(this,f,...C)}finally{x()}},u.push(x)};l(r,"action"),l(n,"action");let h=b.call(this,e);return setTimeout(()=>{for(let o of u)o()},1e3),h},p.prototype.__pdsSelectedItemPatched=!0);export{p as AutoComplete};