@pure-ds/core 0.7.57 → 0.7.59

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,3 @@
1
- var rt=Object.defineProperty;var st=(e,t)=>{for(var n in t)rt(e,n,{get:t[n],enumerable:!0})};var ce=class extends EventTarget{constructor(){super(),this.mode=null,this.compiled=null,this.log=()=>{},this.logHandler=null}},Ae="__PURE_DS_PDS_SINGLETON__",le=typeof globalThis<"u"?globalThis:window,ae=le?.[Ae],r=ae&&typeof ae.addEventListener=="function"?ae:new ce;le&&(le[Ae]=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 ue=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"}},k=new ue;async function Pe(e,t=[],n=null){try{let o=n?.primitivesStylesheet?n.primitivesStylesheet:await k.getStylesheet("primitives");e.adoptedStyleSheets=[o,...t]}catch(o){let a=e.host?.tagName?.toLowerCase()||"unknown";r.log("error",`Adopter: <${a}> failed to adopt primitives:`,o),e.adoptedStyleSheets=t}}async function xe(e,t=["primitives"],n=[],o=null){let a=Array.isArray(n)?n.filter(Boolean):[];if(a.length){let l=(Array.isArray(e.adoptedStyleSheets)?e.adoptedStyleSheets:[]).filter(S=>!a.includes(S));e.adoptedStyleSheets=[...l,...a]}try{let l=(await Promise.all(t.map(async S=>{if(o)switch(S){case"tokens":return o.tokensStylesheet;case"primitives":return o.primitivesStylesheet;case"components":return o.componentsStylesheet;case"utilities":return o.utilitiesStylesheet;default:break}return k.getStylesheet(S)}))).filter(S=>S!==null);e.adoptedStyleSheets=[...l,...a]}catch(s){let l=e.host?.tagName?.toLowerCase()||"unknown";r.log("error",`Adopter: <${l}> failed to adopt layers:`,s),e.adoptedStyleSheets=a}}function Re(e){let t=new CSSStyleSheet;return t.replaceSync(e),t}var De={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 pe={};st(pe,{deepMerge:()=>Te,fragmentFromTemplateLike:()=>de,isObject:()=>B,parseFragment:()=>H,parseHTML:()=>fe});function B(e){return e&&typeof e=="object"&&!Array.isArray(e)}function Te(e,t){let n={...e};return B(e)&&B(t)&&Object.keys(t).forEach(o=>{B(t[o])?o in e?n[o]=Te(e[o],t[o]):Object.assign(n,{[o]:t[o]}):Object.assign(n,{[o]:t[o]})}),n}function de(e){let t=Array.isArray(e?.strings)?e.strings:[],n=Array.isArray(e?.values)?e.values:[],o=new Set,a=[],s=/(\s)(\.[\w-]+)=["']?\s*$/,l=/(\s)(@[\w-]+)=["']?\s*$/,S=/(\s)(\?[\w-]+)=["']?\s*$/,w=/(\s)([\w:-]+)=["']?\s*$/,u=/=["']\s*$/,i=!1;for(let c=0;c<t.length;c+=1){let y=t[c]??"";if(i&&(y=y.replace(/^["']/,""),i=!1),c<n.length){let b=`pds-val-${c}`,d=y.match(s),h=y.match(l),L=y.match(S),D=y.match(w);if(d){let v=d[2].slice(1);i=u.test(t[c]??""),y=y.replace(s,`$1data-pds-bind-${c}="prop:${v}:${b}"`),o.add(c)}else if(h){let v=h[2].slice(1);i=u.test(t[c]??""),y=y.replace(l,`$1data-pds-bind-${c}="event:${v}:${b}"`),o.add(c)}else if(L){let v=L[2].slice(1);i=u.test(t[c]??""),y=y.replace(S,`$1data-pds-bind-${c}="boolean:${v}:${b}"`),o.add(c)}else if(D){let v=D[2];i=u.test(t[c]??""),y=y.replace(w,`$1data-pds-bind-${c}="attr:${v}:${b}"`),o.add(c)}}a.push(y),c<n.length&&!o.has(c)&&a.push(`<!--pds-val-${c}-->`)}let f=document.createElement("template");f.innerHTML=a.join("");let A=(c,y)=>{let b=c.parentNode;if(!b)return;if(y==null){b.removeChild(c);return}let d=h=>{if(h!=null){if(h instanceof Node){b.insertBefore(h,c);return}if(Array.isArray(h)){h.forEach(L=>d(L));return}b.insertBefore(document.createTextNode(String(h)),c)}};d(y),b.removeChild(c)},_=document.createTreeWalker(f.content,NodeFilter.SHOW_COMMENT),P=[];for(;_.nextNode();){let c=_.currentNode;c?.nodeValue?.startsWith("pds-val-")&&P.push(c)}return P.forEach(c=>{let y=Number(c.nodeValue.replace("pds-val-",""));A(c,n[y])}),f.content.querySelectorAll("*").forEach(c=>{[...c.attributes].forEach(y=>{if(!y.name.startsWith("data-pds-bind-"))return;let b=y.value.indexOf(":"),d=y.value.lastIndexOf(":");if(b<=0||d<=b){c.removeAttribute(y.name);return}let h=y.value.slice(0,b),L=y.value.slice(b+1,d),D=y.value.slice(d+1),v=Number(String(D).replace("pds-val-","")),x=n[v];if(!L||!Number.isInteger(v)){c.removeAttribute(y.name);return}h==="prop"?c[L]=x:h==="event"?(typeof x=="function"||x&&typeof x.handleEvent=="function")&&c.addEventListener(L,x):h==="boolean"?x?c.setAttribute(L,""):c.removeAttribute(L):h==="attr"&&(x==null||x===!1?c.removeAttribute(L):c.setAttribute(L,String(x))),c.removeAttribute(y.name)})}),f.content}function H(e,...t){if(Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,"raw"))return de({strings:Array.from(e),values:t});if(Array.isArray(e?.strings)&&Array.isArray(e?.values))return de({strings:e.strings,values:e.values});let o=document.createElement("template");return o.innerHTML=String(e??""),o.content}function fe(e,...t){return H(e,...t).childNodes}var Ce="pds",it=/^([a-z][a-z0-9+\-.]*:)?\/\//i,ze=/^[a-z]:/i;function $(e=""){return e.endsWith("/")?e:`${e}/`}function at(e="",t=Ce){let n=e.replace(/\/+$/,"");return new RegExp(`(?:^|/)${t}$`,"i").test(n)?n:`${n}/${t}`}function ct(e){return e.replace(/^\.\/+/,"")}function lt(e){return ze.test(e)?e.replace(ze,"").replace(/^\/+/,""):e}function ut(e){return e.startsWith("public/")?e.substring(7):e}function K(e,t={}){let n=t.segment||Ce,o=t.defaultRoot||`/assets/${n}/`,a=e?.public&&e.public?.root||e?.static&&e.static?.root||null;if(!a||typeof a!="string")return $(o);let s=a.trim();return s?(s=s.replace(/\\/g,"/"),s=at(s,n),s=$(s),it.test(s)?s:(s=ct(s),s=lt(s),s.startsWith("/")||(s=ut(s),s.startsWith("/")||(s=`/${s}`),s=s.replace(/\/+/g,(l,S)=>S===0?l:"/")),$(s))):$(o)}async function dt(...e){let t={};e.length&&typeof e[e.length-1]=="object"&&(t=e.pop()||{});let n=e,{baseURL:o,mapper:a=u=>`${u}.js`,onError:s=(u,i)=>console.error(`[defineWebComponents] ${u}:`,i)}=t,l=o?new URL(o,typeof location<"u"?location.href:import.meta.url):new URL("./",import.meta.url),S=u=>u.toLowerCase().replace(/(^|-)([a-z])/g,(i,f,A)=>A.toUpperCase()),w=async u=>{try{if(customElements.get(u))return{tag:u,status:"already-defined"};let i=a(u),A=await import(i instanceof URL?i.href:new URL(i,l).href),_=A?.default??A?.[S(u)];if(!_){if(customElements.get(u))return{tag:u,status:"self-defined"};throw new Error(`No export found for ${u}. Expected default export or named export "${S(u)}".`)}return customElements.get(u)?{tag:u,status:"race-already-defined"}:(customElements.define(u,_),{tag:u,status:"defined"})}catch(i){throw s(u,i),i}};return Promise.all(n.map(w))}var G=class{constructor(t={}){let{baseURL:n,mapper:o,onError:a,predicate:s=()=>!0,attributeModule:l="data-module",root:S=document,scanExisting:w=!0,debounceMs:u=16,observeShadows:i=!0,enhancers:f=[],patchAttachShadow:A=!0}=t,_=new Set,P=new Set,T=new Set,c=new Map,y=new WeakMap,b=new WeakMap,d=0,h=!1,L=null,D=p=>{if(!p||!f.length)return;let g=b.get(p);g||(g=new Set,b.set(p,g));for(let m of f)if(!(!m.selector||!m.run)&&!g.has(m.selector))try{p.matches&&p.matches(m.selector)&&(m.run(p),g.add(m.selector))}catch(R){console.warn(`[AutoDefiner] Error applying enhancer for selector "${m.selector}":`,R)}},v=(p,g)=>{if(!h&&!(!p||!p.includes("-"))&&!customElements.get(p)&&!P.has(p)&&!T.has(p)){if(g&&g.getAttribute){let m=g.getAttribute(l);m&&!c.has(p)&&c.set(p,m)}_.add(p),x()}},x=()=>{d||(d=setTimeout(Le,u))},C=p=>{if(p){if(p.nodeType===1){let g=p,m=g.tagName?.toLowerCase();m&&m.includes("-")&&!customElements.get(m)&&s(m,g)&&v(m,g),D(g),i&&g.shadowRoot&&ie(g.shadowRoot)}p.querySelectorAll&&p.querySelectorAll("*").forEach(g=>{let m=g.tagName?.toLowerCase();m&&m.includes("-")&&!customElements.get(m)&&s(m,g)&&v(m,g),D(g),i&&g.shadowRoot&&ie(g.shadowRoot)})}},ie=p=>{if(!p||y.has(p))return;C(p);let g=new MutationObserver(m=>{for(let R of m)R.addedNodes?.forEach(M=>{C(M)}),R.type==="attributes"&&R.target&&C(R.target)});g.observe(p,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[l,...f.map(m=>m.selector).filter(m=>m.startsWith("data-"))]}),y.set(p,g)};async function Le(){if(clearTimeout(d),d=0,!_.size)return;let p=Array.from(_);_.clear(),p.forEach(g=>P.add(g));try{let g=m=>c.get(m)??(o?o(m):`${m}.js`);await dt(...p,{baseURL:n,mapper:g,onError:(m,R)=>{T.add(m),a?.(m,R)}})}catch{}finally{p.forEach(g=>P.delete(g))}}let Ee=S===document?document.documentElement:S,ve=new MutationObserver(p=>{for(let g of p)g.addedNodes?.forEach(m=>{C(m)}),g.type==="attributes"&&g.target&&C(g.target)});if(ve.observe(Ee,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[l,...f.map(p=>p.selector).filter(p=>p.startsWith("data-"))]}),i&&A&&Element.prototype.attachShadow){let p=Element.prototype.attachShadow;Element.prototype.attachShadow=function(m){let R=p.call(this,m);if(m&&m.mode==="open"){ie(R);let M=this.tagName?.toLowerCase();M&&M.includes("-")&&!customElements.get(M)&&v(M,this)}return R},L=()=>Element.prototype.attachShadow=p}return w&&C(Ee),{stop(){h=!0,ve.disconnect(),L&&L(),d&&(clearTimeout(d),d=0),y.forEach(p=>p.disconnect())},flush:Le}}static async define(...t){let n={};t.length&&typeof t[t.length-1]=="object"&&(n=t.pop()||{});let o=t,{baseURL:a,mapper:s=i=>`${i}.js`,onError:l=(i,f)=>console.error(`[defineWebComponents] ${i}:`,f)}=n,S=a?new URL(a,typeof location<"u"?location.href:import.meta.url):new URL("./",import.meta.url),w=i=>i.toLowerCase().replace(/(^|-)([a-z])/g,(f,A,_)=>_.toUpperCase()),u=async i=>{try{if(customElements.get(i))return{tag:i,status:"already-defined"};let f=s(i),_=await import(f instanceof URL?f.href:new URL(f,S).href),P=_?.default??_?.[w(i)];if(!P){if(customElements.get(i))return{tag:i,status:"self-defined"};throw new Error(`No export found for ${i}. Expected default export or named export "${w(i)}".`)}return customElements.get(i)?{tag:i,status:"race-already-defined"}:(customElements.define(i,P),{tag:i,status:"defined"})}catch(f){throw l(i,f),f}};return Promise.all(o.map(u))}};var ft=/^[a-z][a-z0-9+\-.]*:\/\//i,O=(()=>{try{return import.meta.url}catch{return}})(),q=e=>typeof e=="string"&&e.length&&!e.endsWith("/")?`${e}/`:e;function J(e,t={}){if(!e||ft.test(e))return e;let{preferModule:n=!0}=t,o=()=>{if(!O)return null;try{return new URL(e,O).href}catch{return null}},a=()=>{if(typeof window>"u"||!window.location?.origin)return null;try{return new URL(e,window.location.origin).href}catch{return null}};return(n?o()||a():a()||o())||e}var Me=(()=>{if(O)try{let e=new URL(O);if(/\/public\/assets\/js\//.test(e.pathname))return new URL("../pds/",O).href}catch{return}})(),ke=!1;function Ue(e){ke||typeof document>"u"||(ke=!0,e.addEventListener("pds:ready",t=>{let n=t.detail?.mode;n&&document.documentElement.classList.add(`pds-${n}`,"pds-ready")}))}function je({manageTheme:e,themeStorageKey:t,applyResolvedTheme:n,setupSystemListenerIfNeeded:o}){let a="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"?a=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":a=s:a=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}return{resolvedTheme:a,storedTheme:s}}function V(e,{resolvePublicAssetURL:t}){let n=!!(e?.public?.root||e?.static?.root),o=t(e);return!n&&Me&&(o=Me),q(J(o))}async function $e(e,{baseEnhancers:t=[]}={}){let{autoDefineBaseURL:n="/auto-define/",autoDefinePreload:o=[],autoDefineMapper:a=null,enhancers:s=[],autoDefineOverrides:l=null,autoDefinePreferModule:S=!0}=e,w=(()=>{let i=new Map;return(t||[]).forEach(f=>i.set(f.selector,f)),(s||[]).forEach(f=>i.set(f.selector,f)),Array.from(i.values())})(),u=null;if(typeof window<"u"&&typeof document<"u"){let i=G,f=d=>{switch(d){case"pds-tabpanel":return"pds-tabstrip.js";default:return`${d}.js`}},{mapper:A,enhancers:_,...P}=l&&typeof l=="object"?l:{},T=_?Array.isArray(_)?_:typeof _=="object"?Object.values(_):[]:[],c=(()=>{let d=new Map;return(w||[]).forEach(h=>{h?.selector&&d.set(h.selector,h)}),(T||[]).forEach(h=>{if(!h?.selector)return;let L=d.get(h.selector)||null;d.set(h.selector,{...L||{},...h,run:typeof h?.run=="function"?h.run:L?.run})}),Array.from(d.values())})(),b={baseURL:n&&q(J(n,{preferModule:S})),predefine:o,scanExisting:!0,observeShadows:!0,patchAttachShadow:!0,debounceMs:16,enhancers:c,onError:(d,h)=>{if(typeof d=="string"&&d.startsWith("pds-")){let D=["pds-form","pds-drawer"].includes(d),v=h?.message?.includes("#pds/lit")||h?.message?.includes("Failed to resolve module specifier");D&&v?r.log("error",`\u274C PDS component <${d}> 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 <${d}> not found. Assets may not be installed.`)}else r.log("error",`\u274C Auto-define error for <${d}>:`,h)},...P,mapper:d=>{if(customElements.get(d))return null;if(typeof a=="function")try{let h=a(d);return h===void 0?f(d):h}catch(h){return r.log("warn","Custom autoDefine.mapper error; falling back to default:",h?.message||h),f(d)}return f(d)}};u=new i(b),o.length>0&&typeof i.define=="function"&&await i.define(...o,{baseURL:n,mapper:b.mapper,onError:b.onError})}return{autoDefiner:u,mergedEnhancers:w}}var me=["light","dark"],he=new Set(me);function pt(e){let n=(Array.isArray(e?.themes)?e.themes.map(o=>String(o).toLowerCase()):me).filter(o=>he.has(o));return n.length?n:me}function ye(e,{preferDocument:t=!0}={}){let n=String(e||"").toLowerCase();if(he.has(n))return n;if(t&&typeof document<"u"){let o=document.documentElement?.getAttribute("data-theme");if(he.has(o))return o}return typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Oe(e,t){let n=ye(t);return pt(e).includes(n)}var mt=new Set(["log","warn","error","debug","info"]),ht="__PURE_DS_PDS_SINGLETON__",ge=null,we=null;function Ie(){try{let t=(typeof globalThis<"u"?globalThis:window)?.[ht];if(t&&typeof t=="object")return t}catch{return null}return null}function yt(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 gt(e){if(typeof e!="string")return"log";let t=e.toLowerCase();return mt.has(t)?t:"log"}function wt(){if(typeof we=="function")try{let t=yt(we());if(t)return t}catch{}let e=Ie();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 bt(){if(typeof ge=="function")try{let t=ge();if(typeof t=="function")return t}catch{}let e=Ie();return typeof e?.logHandler=="function"?e.logHandler:null}function Ne(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 Fe({getLogger:e,getContext:t}={}){ge=typeof e=="function"?e:null,we=typeof t=="function"?t:null}function We(e="log",t,...n){let o=gt(e),a=wt(),s=bt();if(s)try{s.call(a?.thisArg,o,t,...n);return}catch(l){Ne("error","Custom log handler failed:",l)}St(o,a)&&Ne(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 Q=null,Y=null,Z=null,X=null,ee=null,te=null,He="__pdsLocalizationRuntime";function U(){if(te)return te;let e=r?.[He];return e&&typeof e=="object"?(te=e,e):null}function _t(e){let t=e&&typeof e=="object"?e:null;te=t,r[He]=t}Fe({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)=>{We(e,t,...n)};var E={locale:"en",messages:{},hasProvider:!1},ne=new Set;function Ke(e){return!!e&&typeof e!="string"&&typeof e=="object"&&"strTag"in e}function Ge(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 Lt(e,t){return String(e).replace(/\{(\d+)\}/g,(n,o)=>t(Number(o)))}function Et(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 vt(e,...t){return{strTag:!0,strings:Array.from(e||[]),values:t,raw:Array.from(e?.raw||[])}}function At(e){if(!e)return"";if(Ke(e)){let n=Ge(e.strings||[]),o=E.messages[n]||n;return Lt(o,a=>e.values?.[a])}let t=String(e);return E.messages[t]||t}function Pt(e){if(!e)return;let t=Ke(e)?Ge(e.strings||[]):String(e);typeof t=="string"&&t.length>0&&ne.add(t)}function qe(e){if(!e||typeof e.msg!="function"||ne.size===0)return;let t=Array.from(ne);ne.clear();for(let n of t)try{e.msg(n)}catch{}}async function I(){let e=U();return e||(ee||(ee=import(F("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),qe(n),n}).catch(n=>{throw ee=null,n})),ee)}var Je=(e,t={})=>{let n=U();return typeof n?.msg=="function"?n.msg(e,t):(Pt(e),At(e,t))},Ve=(e,...t)=>{let n=U();return typeof n?.str=="function"?n.str(e,...t):vt(e,...t)},oe=(e=null)=>{let t=U();if(typeof t?.configureLocalization=="function")return t.configureLocalization(e);if(!e||typeof e!="object")return E.locale="en",E.messages={},E.hasProvider=!1,{locale:E.locale,messages:{...E.messages},hasProvider:E.hasProvider};typeof e.locale=="string"&&e.locale.trim()&&(E.locale=e.locale.trim()),Object.prototype.hasOwnProperty.call(e,"messages")&&(E.messages=Et(e.messages));let n=!!(e.provider||e.translate||e.loadLocale||e.setLocale);return E.hasProvider=n,n&&I().then(o=>{o.configureLocalization(e),qe(o)}).catch(()=>{}),{locale:E.locale,messages:{...E.messages},hasProvider:E.hasProvider}},Qe=async e=>(await I()).loadLocale(e),Ye=async(e,t={})=>(await I()).setLocale(e,t),Ze=()=>{let e=U();return typeof e?.getLocalizationState=="function"?e.getLocalizationState():{locale:E.locale,messages:{...E.messages},hasProvider:E.hasProvider}},Xe=(e={})=>{let t=U();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(w=>String(w||"").trim().toLowerCase()).filter(Boolean):[],a=Array.from(new Set([n,...o])),s=null,l=async()=>(s||(s=I().then(w=>typeof w?.createJSONLocalization=="function"?w.createJSONLocalization(e):null).catch(()=>null)),s),S=async(w="loadLocale")=>{let u=await l();if(!u||typeof u!="object")return null;let i=u.provider;if(!i||typeof i!="object")return null;let f=i[w];return typeof f=="function"?f:w==="setLocale"&&typeof i.loadLocale=="function"?i.loadLocale:null};return{locale:n,locales:[...a],provider:{locales:[...a],async loadLocale(w={}){let u=await S("loadLocale");return typeof u!="function"?{}:u(w)},async setLocale(w={}){let u=await S("setLocale");return typeof u!="function"?{}:u(w)}}}};function F(e,t){return t&&typeof t=="string"?t:`${V(r.currentConfig||{},{resolvePublicAssetURL:K})}core/${e}`}async function xt(){return Array.isArray(r.defaultEnhancers)&&r.defaultEnhancers.length>0?r.defaultEnhancers:(X||(X=import(F("pds-enhancers.js",r.currentConfig?.enhancersURL)).then(t=>{let n=Array.isArray(t?.defaultPDSEnhancers)?t.defaultPDSEnhancers:[];return r.defaultEnhancers=n,n}).catch(t=>{throw X=null,t})),X)}async function Rt(){return typeof r.ask=="function"&&r.ask!==et?r.ask:(Y||(Y=import(F("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 Y=null,t})),Y)}async function W(){return typeof r.toast=="function"&&r.toast!==j?r.toast:(Z||(Z=import(F("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 Z=null,t})),Z)}async function et(...e){return(await Rt())(...e)}async function j(...e){return(await W())(...e)}j.success=async(...e)=>(await W()).success(...e);j.error=async(...e)=>(await W()).error(...e);j.warning=async(...e)=>(await W()).warning(...e);j.info=async(...e)=>(await W()).info(...e);var Be=function(e="log",t,...n){r.log(e,t,...n)};function Se(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=>Se(n)).filter(n=>n!==void 0);let t={};for(let[n,o]of Object.entries(e)){let a=Se(o);a!==void 0&&(t[n]=a)}return t}function tt(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))tt(e[n],t);return e}function _e(e){return e==null||typeof e!="object"?e:tt(structuredClone(Se(e)))}async function Dt(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=k;r.enums=De;r.adoptLayers=xe;r.adoptPrimitives=Pe;var Tt=fe;r.parse=Tt;var zt=H;r.html=zt;r.createStylesheet=Re;r.isLiveMode=()=>k.isLive;r.ask=et;r.toast=j;r.common=pe;r.msg=Je;r.str=Ve;r.configureLocalization=oe;r.loadLocale=Qe;r.setLocale=Ye;r.getLocalizationState=Ze;r.createJSONLocalization=Xe;r.i18n={msg:Je,str:Ve,configure:oe,loadLocale:Qe,setLocale:Ye,getState:Ze,createJSONLocalization:Xe};r.AutoComplete=null;r.loadAutoComplete=async()=>{if(r.AutoComplete&&typeof r.AutoComplete.connect=="function")return r.AutoComplete;let e=F("pds-autocomplete.js",r.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 r.AutoComplete=n,n}).catch(t=>{throw Q=null,t})),Q};function nt(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 ot(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 be="pure-ds-theme",z=null,N=null;function re(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 se(e){try{if(z&&N){try{typeof z.removeEventListener=="function"?z.removeEventListener("change",N):typeof z.removeListener=="function"&&z.removeListener(N)}catch{}z=null,N=null}if(e==="system"&&typeof window<"u"&&window.matchMedia){let t=window.matchMedia("(prefers-color-scheme: dark)"),n=o=>{let a=o?.matches===void 0?t.matches:o.matches;try{let s=a?"dark":"light";document.documentElement.setAttribute("data-theme",s),r.dispatchEvent(new CustomEvent("pds:theme:changed",{detail:{theme:s,source:"system"}}))}catch{}};z=t,N=n,typeof t.addEventListener=="function"?t.addEventListener("change",n):typeof t.addListener=="function"&&t.addListener(n)}}catch{}}var Ct=Object.getOwnPropertyDescriptor(r,"theme");Ct||Object.defineProperty(r,"theme",{get(){try{return typeof window>"u"?null:localStorage.getItem(be)||null}catch{return null}},set(e){try{if(typeof window>"u")return;let t=r.currentConfig?.design||null,n=ye(e);if(t&&!Oe(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(be):localStorage.setItem(be,e),re(e),se(e),r.dispatchEvent(new CustomEvent("pds:theme:changed",{detail:{theme:e,source:"api"}}))}catch{}}});r.defaultEnhancers=[];async function Mt(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=_e(o);let a=o&&typeof o.localization=="object"&&o.localization?o.localization:null;a?(await I(),oe(a)):oe(null);let s;if(t==="static")s=await kt(o);else{let{localization:S,...w}=o||{},u=V(w,{resolvePublicAssetURL:K}),i=w?.managerURL||w?.public?.managerURL||w?.manager?.url||new URL("core/pds-manager.js",u).href||new URL("./pds-manager.js",import.meta.url).href,{startLive:f}=await import(i);s=await f(r,w,{emitReady:nt,emitConfigChanged:ot,applyResolvedTheme:re,setupSystemListenerIfNeeded:se})}r.compiled=_e(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=Mt;async function kt(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",a=e.staticPaths??{},s=V(e,{resolvePublicAssetURL:K}),l=e&&e.autoDefine||null,S;l&&l.baseURL?S=q(J(l.baseURL,{preferModule:!1})):S=`${s}components/`;let w=l&&Array.isArray(l.predefine)&&l.predefine||[],u=l&&typeof l.mapper=="function"&&l.mapper||null;try{Ue(r);let{resolvedTheme:i}=je({manageTheme:n,themeStorageKey:o,applyResolvedTheme:re,setupSystemListenerIfNeeded:se}),f=await Dt(s,e),A=Array.isArray(e?.enhancers)?e.enhancers:e?.enhancers&&typeof e.enhancers=="object"?Object.values(e.enhancers):[],_=f?.config?{...f.config,...e,design:e?.design||f.config.design,preset:e?.preset||f.config.preset}:{...e},P={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`},T=f?.paths||{};if(a={...P,...T,...a},r.registry.setStaticMode(a),t&&typeof document<"u")try{let b=await r.registry.getStylesheet("styles");if(b){b._pds=!0;let d=(document.adoptedStyleSheets||[]).filter(h=>h._pds!==!0);document.adoptedStyleSheets=[...d,b],ot({mode:"static",source:"static:styles-applied"})}}catch(b){Be.call(r,"warn","Failed to apply static styles:",b)}let c=null,y=[];try{let b=await xt(),d=await $e({autoDefineBaseURL:S,autoDefinePreload:w,autoDefineMapper:u,enhancers:A,autoDefineOverrides:l||null,autoDefinePreferModule:!(l&&l.baseURL)},{baseEnhancers:b});c=d.autoDefiner,y=d.mergedEnhancers||[]}catch(b){Be.call(r,"error","\u274C Failed to initialize AutoDefiner/Enhancers (static):",b)}return r.compiled=_e({mode:"static",..._,theme:i,enhancers:y}),nt({mode:"static",config:_,theme:i,autoDefiner:c}),{config:_,theme:i,autoDefiner:c}}catch(i){throw r.dispatchEvent(new CustomEvent("pds:error",{detail:{error:i}})),i}}var rn=re,sn=se;export{r as PDS,rn as applyResolvedTheme,oe as configureLocalization,Xe as createJSONLocalization,Ze as getLocalizationState,zt as html,Qe as loadLocale,Je as msg,Tt as parse,Ye as setLocale,sn as setupSystemListenerIfNeeded,Ve as str};
1
+ var ut=Object.defineProperty;var dt=(e,t)=>()=>(e&&(t=e(e=0)),t);var Pe=(e,t)=>{for(var n in t)ut(e,n,{get:t[n],enumerable:!0})};var Ue={};Pe(Ue,{AutoDefiner:()=>me});async function vt(...e){let t={};e.length&&typeof e[e.length-1]=="object"&&(t=e.pop()||{});let n=e,{baseURL:r,mapper:i=f=>`${f}.js`,onError:s=(f,c)=>console.error(`[defineWebComponents] ${f}:`,c)}=t,u=r?new URL(r,typeof location<"u"?location.href:import.meta.url):new URL("./",import.meta.url),S=f=>f.toLowerCase().replace(/(^|-)([a-z])/g,(c,p,A)=>A.toUpperCase()),_=async f=>{try{if(customElements.get(f))return{tag:f,status:"already-defined"};let c=i(f),A=await import(c instanceof URL?c.href:new URL(c,u).href),m=A?.default??A?.[S(f)];if(!m){if(customElements.get(f))return{tag:f,status:"self-defined"};throw new Error(`No export found for ${f}. Expected default export or named export "${S(f)}".`)}return customElements.get(f)?{tag:f,status:"race-already-defined"}:(customElements.define(f,m),{tag:f,status:"defined"})}catch(c){throw s(f,c),c}};return Promise.all(n.map(_))}var me,Oe=dt(()=>{me=class{constructor(t={}){let{baseURL:n,mapper:r,onError:i,predicate:s=()=>!0,attributeModule:u="data-module",root:S=document,scanExisting:_=!0,debounceMs:f=16,observeShadows:c=!0,enhancers:p=[],patchAttachShadow:A=!0}=t,m=new Set,L=new Set,P=new Set,a=new Map,l=new WeakMap,h=new WeakMap,d=0,y=!1,E=null,C=g=>{if(!g||!p.length)return;let b=h.get(g);b||(b=new Set,h.set(g,b));for(let w of p)if(!(!w.selector||!w.run)&&!b.has(w.selector))try{g.matches&&g.matches(w.selector)&&(w.run(g),b.add(w.selector))}catch(D){console.warn(`[AutoDefiner] Error applying enhancer for selector "${w.selector}":`,D)}},x=(g,b)=>{if(!y&&!(!g||!g.includes("-"))&&!customElements.get(g)&&!L.has(g)&&!P.has(g)){if(b&&b.getAttribute){let w=b.getAttribute(u);w&&!a.has(g)&&a.set(g,w)}m.add(g),R()}},R=()=>{d||(d=setTimeout(ve,f))},z=g=>{if(g){if(g.nodeType===1){let b=g,w=b.tagName?.toLowerCase();w&&w.includes("-")&&!customElements.get(w)&&s(w,b)&&x(w,b),C(b),c&&b.shadowRoot&&ie(b.shadowRoot)}g.querySelectorAll&&g.querySelectorAll("*").forEach(b=>{let w=b.tagName?.toLowerCase();w&&w.includes("-")&&!customElements.get(w)&&s(w,b)&&x(w,b),C(b),c&&b.shadowRoot&&ie(b.shadowRoot)})}},ie=g=>{if(!g||l.has(g))return;z(g);let b=new MutationObserver(w=>{for(let D of w)D.addedNodes?.forEach($=>{z($)}),D.type==="attributes"&&D.target&&z(D.target)});b.observe(g,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[u,...p.map(w=>w.selector).filter(w=>w.startsWith("data-"))]}),l.set(g,b)};async function ve(){if(clearTimeout(d),d=0,!m.size)return;let g=Array.from(m);m.clear(),g.forEach(b=>L.add(b));try{let b=w=>a.get(w)??(r?r(w):`${w}.js`);await vt(...g,{baseURL:n,mapper:b,onError:(w,D)=>{P.add(w),i?.(w,D)}})}catch{}finally{g.forEach(b=>L.delete(b))}}let Ae=S===document?document.documentElement:S,xe=new MutationObserver(g=>{for(let b of g)b.addedNodes?.forEach(w=>{z(w)}),b.type==="attributes"&&b.target&&z(b.target)});if(xe.observe(Ae,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[u,...p.map(g=>g.selector).filter(g=>g.startsWith("data-"))]}),c&&A&&Element.prototype.attachShadow){let g=Element.prototype.attachShadow;Element.prototype.attachShadow=function(w){let D=g.call(this,w);if(w&&w.mode==="open"){ie(D);let $=this.tagName?.toLowerCase();$&&$.includes("-")&&!customElements.get($)&&x($,this)}return D},E=()=>Element.prototype.attachShadow=g}return _&&z(Ae),{stop(){y=!0,xe.disconnect(),E&&E(),d&&(clearTimeout(d),d=0),l.forEach(g=>g.disconnect())},flush:ve}}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:u=(c,p)=>console.error(`[defineWebComponents] ${c}:`,p)}=n,S=i?new URL(i,typeof location<"u"?location.href:import.meta.url):new URL("./",import.meta.url),_=c=>c.toLowerCase().replace(/(^|-)([a-z])/g,(p,A,m)=>m.toUpperCase()),f=async c=>{try{if(customElements.get(c))return{tag:c,status:"already-defined"};let p=s(c),m=await import(p instanceof URL?p.href:new URL(p,S).href),L=m?.default??m?.[_(c)];if(!L){if(customElements.get(c))return{tag:c,status:"self-defined"};throw new Error(`No export found for ${c}. Expected default export or named export "${_(c)}".`)}return customElements.get(c)?{tag:c,status:"race-already-defined"}:(customElements.define(c,L),{tag:c,status:"defined"})}catch(p){throw u(c,p),p}};return Promise.all(r.map(f))}}});var ce=class extends EventTarget{constructor(){super(),this.mode=null,this.compiled=null,this.log=()=>{},this.logHandler=null}},Re="__PURE_DS_PDS_SINGLETON__",le=typeof globalThis<"u"?globalThis:window,ae=le?.[Re],o=ae&&typeof ae.addEventListener=="function"?ae:new ce;le&&(le[Re]=o);typeof o.log!="function"&&(o.log=(e="log",t,...n)=>{if(typeof console>"u")return;let r=typeof console[e]=="function"?console[e].bind(console):typeof console.log=="function"?console.log.bind(console):null;r&&(n.length>0?r(t,...n):r(t))});typeof o.logHandler!="function"&&(o.logHandler=null);var ue=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){o.log("error",`Registry: failed to load static ${t}:`,n),o.log("error",`Registry: looking for ${this._staticPaths[t]}`),o.log("error","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 ue;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";o.log("error",`Adopter: <${i}> failed to adopt primitives:`,r),e.adoptedStyleSheets=t}}async function Ce(e,t=["primitives"],n=[],r=null){let i=Array.isArray(n)?n.filter(Boolean):[];if(i.length){let u=(Array.isArray(e.adoptedStyleSheets)?e.adoptedStyleSheets:[]).filter(S=>!i.includes(S));e.adoptedStyleSheets=[...u,...i]}try{let u=(await Promise.all(t.map(async S=>{if(r)switch(S){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(S)}))).filter(S=>S!==null);e.adoptedStyleSheets=[...u,...i]}catch(s){let u=e.host?.tagName?.toLowerCase()||"unknown";o.log("error",`Adopter: <${u}> failed to adopt layers:`,s),e.adoptedStyleSheets=i}}function Te(e){let t=new CSSStyleSheet;return t.replaceSync(e),t}var ze={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 pe={};Pe(pe,{deepMerge:()=>$e,enQueue:()=>pt,escapeForRegExp:()=>yt,fragmentFromTemplateLike:()=>de,humanizeIdentifier:()=>wt,isObject:()=>H,isUrl:()=>mt,openCenteredWindow:()=>gt,parseFragment:()=>K,parseHTML:()=>fe,throttle:()=>ft,withTimeout:()=>ht});function H(e){return e&&typeof e=="object"&&!Array.isArray(e)}function $e(e,t){let n={...e};return H(e)&&H(t)&&Object.keys(t).forEach(r=>{H(t[r])?r in e?n[r]=$e(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}function de(e){let t=Array.isArray(e?.strings)?e.strings:[],n=Array.isArray(e?.values)?e.values:[],r=new Set,i=[],s=/(\s)(\.[\w-]+)=["']?\s*$/,u=/(\s)(@[\w-]+)=["']?\s*$/,S=/(\s)(\?[\w-]+)=["']?\s*$/,_=/(\s)([\w:-]+)=["']?\s*$/,f=/=["']\s*$/,c=!1;for(let a=0;a<t.length;a+=1){let l=t[a]??"";if(c&&(l=l.replace(/^["']/,""),c=!1),a<n.length){let h=`pds-val-${a}`,d=l.match(s),y=l.match(u),E=l.match(S),C=l.match(_);if(d){let x=d[2].slice(1);c=f.test(t[a]??""),l=l.replace(s,`$1data-pds-bind-${a}="prop:${x}:${h}"`),r.add(a)}else if(y){let x=y[2].slice(1);c=f.test(t[a]??""),l=l.replace(u,`$1data-pds-bind-${a}="event:${x}:${h}"`),r.add(a)}else if(E){let x=E[2].slice(1);c=f.test(t[a]??""),l=l.replace(S,`$1data-pds-bind-${a}="boolean:${x}:${h}"`),r.add(a)}else if(C){let x=C[2];c=f.test(t[a]??""),l=l.replace(_,`$1data-pds-bind-${a}="attr:${x}:${h}"`),r.add(a)}}i.push(l),a<n.length&&!r.has(a)&&i.push(`<!--pds-val-${a}-->`)}let p=document.createElement("template");p.innerHTML=i.join("");let A=(a,l)=>{let h=a.parentNode;if(!h)return;if(l==null){h.removeChild(a);return}let d=y=>{if(y!=null){if(y instanceof Node){h.insertBefore(y,a);return}if(Array.isArray(y)){y.forEach(E=>d(E));return}h.insertBefore(document.createTextNode(String(y)),a)}};d(l),h.removeChild(a)},m=document.createTreeWalker(p.content,NodeFilter.SHOW_COMMENT),L=[];for(;m.nextNode();){let a=m.currentNode;a?.nodeValue?.startsWith("pds-val-")&&L.push(a)}return L.forEach(a=>{let l=Number(a.nodeValue.replace("pds-val-",""));A(a,n[l])}),p.content.querySelectorAll("*").forEach(a=>{[...a.attributes].forEach(l=>{if(!l.name.startsWith("data-pds-bind-"))return;let h=l.value.indexOf(":"),d=l.value.lastIndexOf(":");if(h<=0||d<=h){a.removeAttribute(l.name);return}let y=l.value.slice(0,h),E=l.value.slice(h+1,d),C=l.value.slice(d+1),x=Number(String(C).replace("pds-val-","")),R=n[x];if(!E||!Number.isInteger(x)){a.removeAttribute(l.name);return}y==="prop"?a[E]=R:y==="event"?(typeof R=="function"||R&&typeof R.handleEvent=="function")&&a.addEventListener(E,R):y==="boolean"?R?a.setAttribute(E,""):a.removeAttribute(E):y==="attr"&&(R==null||R===!1?a.removeAttribute(E):a.setAttribute(E,String(R))),a.removeAttribute(l.name)})}),p.content}function K(e,...t){if(Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,"raw"))return de({strings:Array.from(e),values:t});if(Array.isArray(e?.strings)&&Array.isArray(e?.values))return de({strings:e.strings,values:e.values});let r=document.createElement("template");return r.innerHTML=String(e??""),r.content}function fe(e,...t){return K(e,...t).childNodes}function ft(e,t=100){let n;return function(...i){let s=()=>{clearTimeout(n),e(...i)};clearTimeout(n),n=setTimeout(s,t)}}function pt(e){setTimeout(e,0)}function mt(e){try{if(typeof e!="string"||e.indexOf(`
2
+ `)!==-1||e.indexOf(" ")!==-1||e.startsWith("#/"))return!1;let t=new URL(e,window.location.origin);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}}function ht(e,t,n="Operation"){return!t||t<=0?e:new Promise((r,i)=>{let s=setTimeout(()=>{i(new Error(`${n} timed out after ${t}ms`))},t);Promise.resolve(e).then(u=>{clearTimeout(s),r(u)}).catch(u=>{clearTimeout(s),i(u)})})}function yt(e){return String(e).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function gt(e,t,n){let r=window.screen.width/2-t/2,i=window.screen.height/2-n/2;return window.open(e,"",`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=${t}, height=${n}, top=${i}, left=${r}`)}function wt(e){if(e==null)return"";let t=String(e).trim();return t?t.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/\s+/g," ").trim():""}var ke="pds",bt=/^([a-z][a-z0-9+\-.]*:)?\/\//i,Me=/^[a-z]:/i;function O(e=""){return e.endsWith("/")?e:`${e}/`}function St(e="",t=ke){let n=e.replace(/\/+$/,"");return new RegExp(`(?:^|/)${t}$`,"i").test(n)?n:`${n}/${t}`}function _t(e){return e.replace(/^\.\/+/,"")}function Lt(e){return Me.test(e)?e.replace(Me,"").replace(/^\/+/,""):e}function Et(e){return e.startsWith("public/")?e.substring(7):e}function G(e,t={}){let n=t.segment||ke,r=t.defaultRoot||`/assets/${n}/`,i=e?.public&&e.public?.root||e?.static&&e.static?.root||null;if(!i||typeof i!="string")return O(r);let s=i.trim();return s?(s=s.replace(/\\/g,"/"),s=St(s,n),s=O(s),bt.test(s)?s:(s=_t(s),s=Lt(s),s.startsWith("/")||(s=Et(s),s.startsWith("/")||(s=`/${s}`),s=s.replace(/\/+/g,(u,S)=>S===0?u:"/")),O(s))):O(r)}var he=null;async function At(){return he||(he=Promise.resolve().then(()=>(Oe(),Ue)).then(e=>e?.AutoDefiner||e?.default?.AutoDefiner||e?.default).then(e=>{if(typeof e!="function")throw new Error("AutoDefiner constructor not found in pure-web/auto-definer");return e})),he}var xt=/^[a-z][a-z0-9+\-.]*:\/\//i,j=(()=>{try{return import.meta.url}catch{return}})(),q=e=>typeof e=="string"&&e.length&&!e.endsWith("/")?`${e}/`:e;function V(e,t={}){if(!e||xt.test(e))return e;let{preferModule:n=!0}=t,r=()=>{if(!j)return null;try{return new URL(e,j).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 je=(()=>{if(j)try{let e=new URL(j);if(/\/public\/assets\/js\//.test(e.pathname))return new URL("../pds/",j).href}catch{return}})(),Ne=!1;function Ie(e){Ne||typeof document>"u"||(Ne=!0,e.addEventListener("pds:ready",t=>{let n=t.detail?.mode;n&&document.documentElement.classList.add(`pds-${n}`,"pds-ready")}))}function Fe({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 J(e,{resolvePublicAssetURL:t}){let n=!!(e?.public?.root||e?.static?.root),r=t(e);return!n&&je&&(r=je),q(V(r))}async function We(e,{baseEnhancers:t=[]}={}){let{autoDefineBaseURL:n="/auto-define/",autoDefinePreload:r=[],autoDefineMapper:i=null,enhancers:s=[],autoDefineOverrides:u=null,autoDefinePreferModule:S=!0}=e,_=(()=>{let c=new Map;return(t||[]).forEach(p=>c.set(p.selector,p)),(s||[]).forEach(p=>c.set(p.selector,p)),Array.from(c.values())})(),f=null;if(typeof window<"u"&&typeof document<"u"){let c=await At(),p=d=>{switch(d){case"pds-tabpanel":return"pds-tabstrip.js";default:return`${d}.js`}},{mapper:A,enhancers:m,...L}=u&&typeof u=="object"?u:{},P=m?Array.isArray(m)?m:typeof m=="object"?Object.values(m):[]:[],a=(()=>{let d=new Map;return(_||[]).forEach(y=>{y?.selector&&d.set(y.selector,y)}),(P||[]).forEach(y=>{if(!y?.selector)return;let E=d.get(y.selector)||null;d.set(y.selector,{...E||{},...y,run:typeof y?.run=="function"?y.run:E?.run})}),Array.from(d.values())})(),h={baseURL:n&&q(V(n,{preferModule:S})),predefine:r,scanExisting:!0,observeShadows:!0,patchAttachShadow:!0,debounceMs:16,enhancers:a,onError:(d,y)=>{if(typeof d=="string"&&d.startsWith("pds-")){let C=["pds-form","pds-drawer"].includes(d),x=y?.message?.includes("#pds/lit")||y?.message?.includes("Failed to resolve module specifier");C&&x?o.log("error",`\u274C PDS component <${d}> requires Lit but #pds/lit is not in import map.
3
+ See: https://github.com/Pure-Web-Foundation/pure-ds/blob/main/readme.md#lit-components-not-working`):o.log("warn",`\u26A0\uFE0F PDS component <${d}> not found. Assets may not be installed.`)}else o.log("error",`\u274C Auto-define error for <${d}>:`,y)},...L,mapper:d=>{if(customElements.get(d))return null;if(typeof i=="function")try{let y=i(d);return y===void 0?p(d):y}catch(y){return o.log("warn","Custom autoDefine.mapper error; falling back to default:",y?.message||y),p(d)}return p(d)}};f=new c(h),r.length>0&&typeof c.define=="function"&&await c.define(...r,{baseURL:n,mapper:h.mapper,onError:h.onError})}return{autoDefiner:f,mergedEnhancers:_}}var ye=["light","dark"],ge=new Set(ye);function Pt(e){let n=(Array.isArray(e?.themes)?e.themes.map(r=>String(r).toLowerCase()):ye).filter(r=>ge.has(r));return n.length?n:ye}function we(e,{preferDocument:t=!0}={}){let n=String(e||"").toLowerCase();if(ge.has(n))return n;if(t&&typeof document<"u"){let r=document.documentElement?.getAttribute("data-theme");if(ge.has(r))return r}return typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Be(e,t){let n=we(t);return Pt(e).includes(n)}var Rt=new Set(["log","warn","error","debug","info"]),Dt="__PURE_DS_PDS_SINGLETON__",be=null,Se=null;function Ke(){try{let t=(typeof globalThis<"u"?globalThis:window)?.[Dt];if(t&&typeof t=="object")return t}catch{return null}return null}function Ct(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 Tt(e){if(typeof e!="string")return"log";let t=e.toLowerCase();return Rt.has(t)?t:"log"}function zt(){if(typeof Se=="function")try{let t=Ct(Se());if(t)return t}catch{}let e=Ke();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 $t(){if(typeof be=="function")try{let t=be();if(typeof t=="function")return t}catch{}let e=Ke();return typeof e?.logHandler=="function"?e.logHandler:null}function He(e,t,...n){if(typeof console>"u")return;let r=typeof console[e]=="function"?console[e].bind(console):typeof console.log=="function"?console.log.bind(console):null;r&&(n.length>0?r(t,...n):r(t))}function Mt(e,t){let n=t?.debug===!0;return!(t?.mode==="static"&&!n||!n&&e!=="error"&&e!=="warn")}function Ge({getLogger:e,getContext:t}={}){be=typeof e=="function"?e:null,Se=typeof t=="function"?t:null}function qe(e="log",t,...n){let r=Tt(e),i=zt(),s=$t();if(s)try{s.call(i?.thisArg,r,t,...n);return}catch(u){He("error","Custom log handler failed:",u)}Mt(r,i)&&He(r,t,...n)}var N=class{constructor(t={},n=null){let r=t&&typeof t=="object"?t:{},i=n||(typeof document<"u"?document:new EventTarget),s=new WeakMap,u=m=>m.map(L=>String(L)).join("."),S,_=(m,L,P,a)=>{let l=u(m),h={property:L,path:l,value:P,oldValue:a};i.dispatchEvent(new CustomEvent(`change:${l}`,{detail:h,bubbles:!0,composed:!0})),i.dispatchEvent(new CustomEvent("change",{detail:{...h,state:S},bubbles:!0,composed:!0}))},f=(m,L)=>(typeof L=="function"&&i.addEventListener(m,L),S),c=(m,L)=>(typeof L=="function"&&i.removeEventListener(m,L),S),p=(m,L)=>{if(typeof L=="function"){let P=a=>{L(a),i.removeEventListener(m,P)};i.addEventListener(m,P)}return S},A=(m,L)=>{if(!m||typeof m!="object")return m;if(s.has(m))return s.get(m);let P=new Proxy(m,{get(a,l,h){if(l==="on")return f;if(l==="off")return c;if(l==="once")return p;let d=Reflect.get(a,l,h);return d&&typeof d=="object"?A(d,[...L,l]):d},set(a,l,h,d){let y=Reflect.get(a,l,d);return Object.is(y,h)?!0:Reflect.set(a,l,h,d)?(_([...L,l],l,h,y),!0):!1},deleteProperty(a,l){if(!Reflect.has(a,l))return!0;let h=a[l];return Reflect.deleteProperty(a,l)?(_([...L,l],l,void 0,h),!0):!1}});return s.set(m,P),P};return S=A(r,[]),S}};function kt(e,t,n){let r=new N(e),i=()=>{n.replaceChildren();let s=t(r);(s instanceof DocumentFragment||s instanceof Node)&&n.appendChild(s)};return i(),r.on("change",i),r}function Ve(e,t,n){if(!e||!t||typeof n!="object")return()=>{};let r={};return Object.entries(n).forEach(([i,s])=>{r[i]=u=>{typeof s=="function"&&s(e,u.detail.value,u.detail.oldValue)},t.on(`change:${i}`,r[i])}),()=>{Object.entries(r).forEach(([i,s])=>{t.off(`change:${i}`,s)})}}typeof o.initializing!="boolean"&&(o.initializing=!1);"currentPreset"in o||(o.currentPreset=null);typeof o.debug!="boolean"&&(o.debug=!1);"currentConfig"in o||(o.currentConfig=null);"compiled"in o||(o.compiled=null);typeof o.logHandler!="function"&&(o.logHandler=null);"mode"in o||(o.mode=null);var Q=null,Y=null,Z=null,X=null,ee=null,te=null,Qe="__pdsLocalizationRuntime";function k(){if(te)return te;let e=o?.[Qe];return e&&typeof e=="object"?(te=e,e):null}function Ut(e){let t=e&&typeof e=="object"?e:null;te=t,o[Qe]=t}Ge({getLogger:()=>typeof o.logHandler=="function"?o.logHandler:null,getContext:()=>{let e=o?.mode||o?.compiled?.mode||(o?.registry?.isLive?"live":"static"),t=(o?.debug||o?.currentConfig?.debug||o?.currentConfig?.design?.debug||o?.compiled?.debug||o?.compiled?.design?.debug||!1)===!0;return{mode:e,debug:t,thisArg:o}}});o.log=(e="log",t,...n)=>{qe(e,t,...n)};var v={locale:"en",messages:{},hasProvider:!1},ne=new Set;function Ye(e){return!!e&&typeof e!="string"&&typeof e=="object"&&"strTag"in e}function Ze(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 Ot(e,t){return String(e).replace(/\{(\d+)\}/g,(n,r)=>t(Number(r)))}function jt(e){if(!e||typeof e!="object")return{};let t={};for(let[n,r]of Object.entries(e)){if(typeof r=="string"){t[n]=r;continue}r&&typeof r=="object"&&typeof r.content=="string"&&(t[n]=r.content)}return t}function Nt(e,...t){return{strTag:!0,strings:Array.from(e||[]),values:t,raw:Array.from(e?.raw||[])}}function It(e){if(!e)return"";if(Ye(e)){let n=Ze(e.strings||[]),r=v.messages[n]||n;return Ot(r,i=>e.values?.[i])}let t=String(e);return v.messages[t]||t}function Ft(e){if(!e)return;let t=Ye(e)?Ze(e.strings||[]):String(e);typeof t=="string"&&t.length>0&&ne.add(t)}function Xe(e){if(!e||typeof e.msg!="function"||ne.size===0)return;let t=Array.from(ne);ne.clear();for(let n of t)try{e.msg(n)}catch{}}async function F(){let e=k();return e||(ee||(ee=import(W("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 Ut(n),Xe(n),n}).catch(n=>{throw ee=null,n})),ee)}var et=(e,t={})=>{let n=k();return typeof n?.msg=="function"?n.msg(e,t):(Ft(e),It(e,t))},tt=(e,...t)=>{let n=k();return typeof n?.str=="function"?n.str(e,...t):Nt(e,...t)},re=(e=null)=>{let t=k();if(typeof t?.configureLocalization=="function")return t.configureLocalization(e);if(!e||typeof e!="object")return v.locale="en",v.messages={},v.hasProvider=!1,{locale:v.locale,messages:{...v.messages},hasProvider:v.hasProvider};typeof e.locale=="string"&&e.locale.trim()&&(v.locale=e.locale.trim()),Object.prototype.hasOwnProperty.call(e,"messages")&&(v.messages=jt(e.messages));let n=!!(e.provider||e.translate||e.loadLocale||e.setLocale);return v.hasProvider=n,n&&F().then(r=>{r.configureLocalization(e),Xe(r)}).catch(()=>{}),{locale:v.locale,messages:{...v.messages},hasProvider:v.hasProvider}},nt=async e=>(await F()).loadLocale(e),rt=async(e,t={})=>(await F()).setLocale(e,t),ot=()=>{let e=k();return typeof e?.getLocalizationState=="function"?e.getLocalizationState():{locale:v.locale,messages:{...v.messages},hasProvider:v.hasProvider}},st=(e={})=>{let t=k();if(typeof t?.createJSONLocalization=="function")return t.createJSONLocalization(e);let n=typeof e?.locale=="string"&&e.locale.trim()?e.locale.trim().toLowerCase():"en",r=Array.isArray(e?.locales)?e.locales.map(_=>String(_||"").trim().toLowerCase()).filter(Boolean):[],i=Array.from(new Set([n,...r])),s=null,u=async()=>(s||(s=F().then(_=>typeof _?.createJSONLocalization=="function"?_.createJSONLocalization(e):null).catch(()=>null)),s),S=async(_="loadLocale")=>{let f=await u();if(!f||typeof f!="object")return null;let c=f.provider;if(!c||typeof c!="object")return null;let p=c[_];return typeof p=="function"?p:_==="setLocale"&&typeof c.loadLocale=="function"?c.loadLocale:null};return{locale:n,locales:[...i],provider:{locales:[...i],async loadLocale(_={}){let f=await S("loadLocale");return typeof f!="function"?{}:f(_)},async setLocale(_={}){let f=await S("setLocale");return typeof f!="function"?{}:f(_)}}}};function W(e,t){return t&&typeof t=="string"?t:`${J(o.currentConfig||{},{resolvePublicAssetURL:G})}core/${e}`}async function Wt(){return Array.isArray(o.defaultEnhancers)&&o.defaultEnhancers.length>0?o.defaultEnhancers:(X||(X=import(W("pds-enhancers.js",o.currentConfig?.enhancersURL)).then(t=>{let n=Array.isArray(t?.defaultPDSEnhancers)?t.defaultPDSEnhancers:[];return o.defaultEnhancers=n,n}).catch(t=>{throw X=null,t})),X)}async function Bt(){return typeof o.ask=="function"&&o.ask!==it?o.ask:(Y||(Y=import(W("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 Y=null,t})),Y)}async function B(){return typeof o.toast=="function"&&o.toast!==U?o.toast:(Z||(Z=import(W("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 Z=null,t})),Z)}async function it(...e){return(await Bt())(...e)}async function U(...e){return(await B())(...e)}U.success=async(...e)=>(await B()).success(...e);U.error=async(...e)=>(await B()).error(...e);U.warning=async(...e)=>(await B()).warning(...e);U.info=async(...e)=>(await B()).info(...e);var Je=function(e="log",t,...n){o.log(e,t,...n)};function Le(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=>Le(n)).filter(n=>n!==void 0);let t={};for(let[n,r]of Object.entries(e)){let i=Le(r);i!==void 0&&(t[n]=i)}return t}function at(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))at(e[n],t);return e}function Ee(e){return e==null||typeof e!="object"?e:at(structuredClone(Le(e)))}async function Ht(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=ze;o.adoptLayers=Ce;o.adoptPrimitives=De;var Kt=fe;o.parse=Kt;var Gt=K;o.html=Gt;o.State=N;o.bindState=Ve;o.createStylesheet=Te;o.isLiveMode=()=>M.isLive;o.ask=it;o.toast=U;o.common=pe;o.msg=et;o.str=tt;o.configureLocalization=re;o.loadLocale=nt;o.setLocale=rt;o.getLocalizationState=ot;o.createJSONLocalization=st;o.i18n={msg:et,str:tt,configure:re,loadLocale:nt,setLocale:rt,getState:ot,createJSONLocalization:st};o.AutoComplete=null;o.loadAutoComplete=async()=>{if(o.AutoComplete&&typeof o.AutoComplete.connect=="function")return o.AutoComplete;let e=W("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 ct(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 lt(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 _e="pure-ds-theme",T=null,I=null;function oe(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 se(e){try{if(T&&I){try{typeof T.removeEventListener=="function"?T.removeEventListener("change",I):typeof T.removeListener=="function"&&T.removeListener(I)}catch{}T=null,I=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{}};T=t,I=n,typeof t.addEventListener=="function"?t.addEventListener("change",n):typeof t.addListener=="function"&&t.addListener(n)}}catch{}}var qt=Object.getOwnPropertyDescriptor(o,"theme");qt||Object.defineProperty(o,"theme",{get(){try{return typeof window>"u"?null:localStorage.getItem(_e)||null}catch{return null}},set(e){try{if(typeof window>"u")return;let t=o.currentConfig?.design||null,n=we(e);if(t&&!Be(t,n)){let r=t?.name||o.currentPreset?.name||o.currentConfig?.preset||"current preset";o.log("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(_e):localStorage.setItem(_e,e),oe(e),se(e),o.dispatchEvent(new CustomEvent("pds:theme:changed",{detail:{theme:e,source:"api"}}))}catch{}}});o.defaultEnhancers=[];async function Vt(e){o.initializing=!0;try{let t=e&&e.mode||"live",{mode:n,...r}=e||{};o.mode=t,o.logHandler=typeof r?.log=="function"?r.log:null,o.currentConfig=Ee(r);let i=r&&typeof r.localization=="object"&&r.localization?r.localization:null;i?(await F(),re(i)):re(null);let s;if(t==="static")s=await Jt(r);else{let{localization:S,..._}=r||{},f=J(_,{resolvePublicAssetURL:G}),c=_?.managerURL||_?.public?.managerURL||_?.manager?.url||new URL("core/pds-manager.js",f).href||new URL("./pds-manager.js",import.meta.url).href,{startLive:p}=await import(c);s=await p(o,_,{emitReady:ct,emitConfigChanged:lt,applyResolvedTheme:oe,setupSystemListenerIfNeeded:se})}o.compiled=Ee(s?.config||null);let u=o?.compiled?.design?.icons?.externalPath||"/assets/img/icons/";return o.log("info",`startup ready; external icon path: ${u}`),s}finally{o.initializing=!1}}o.start=Vt;async function Jt(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=J(e,{resolvePublicAssetURL:G}),u=e&&e.autoDefine||null,S;u&&u.baseURL?S=q(V(u.baseURL,{preferModule:!1})):S=`${s}components/`;let _=u&&Array.isArray(u.predefine)&&u.predefine||[],f=u&&typeof u.mapper=="function"&&u.mapper||null;try{Ie(o);let{resolvedTheme:c}=Fe({manageTheme:n,themeStorageKey:r,applyResolvedTheme:oe,setupSystemListenerIfNeeded:se}),p=await Ht(s,e),A=Array.isArray(e?.enhancers)?e.enhancers:e?.enhancers&&typeof e.enhancers=="object"?Object.values(e.enhancers):[],m=p?.config?{...p.config,...e,design:e?.design||p.config.design,preset:e?.preset||p.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`},P=p?.paths||{};if(i={...L,...P,...i},o.registry.setStaticMode(i),t&&typeof document<"u")try{let h=await o.registry.getStylesheet("styles");if(h){h._pds=!0;let d=(document.adoptedStyleSheets||[]).filter(y=>y._pds!==!0);document.adoptedStyleSheets=[...d,h],lt({mode:"static",source:"static:styles-applied"})}}catch(h){Je.call(o,"warn","Failed to apply static styles:",h)}let a=null,l=[];try{let h=await Wt(),d=await We({autoDefineBaseURL:S,autoDefinePreload:_,autoDefineMapper:f,enhancers:A,autoDefineOverrides:u||null,autoDefinePreferModule:!(u&&u.baseURL)},{baseEnhancers:h});a=d.autoDefiner,l=d.mergedEnhancers||[]}catch(h){Je.call(o,"error","\u274C Failed to initialize AutoDefiner/Enhancers (static):",h)}return o.compiled=Ee({mode:"static",...m,theme:c,enhancers:l}),ct({mode:"static",config:m,theme:c,autoDefiner:a}),{config:m,theme:c,autoDefiner:a}}catch(c){throw o.dispatchEvent(new CustomEvent("pds:error",{detail:{error:c}})),c}}var Sn=oe,_n=se;export{o as PDS,N as State,Sn as applyResolvedTheme,Ve as bindState,re as configureLocalization,st as createJSONLocalization,kt as createReactiveComponent,ot as getLocalizationState,Gt as html,nt as loadLocale,et as msg,Kt as parse,rt as setLocale,_n as setupSystemListenerIfNeeded,tt as str};
@@ -1,8 +1,8 @@
1
- function N(o){let t=Array.isArray(o?.strings)?o.strings:[],c=Array.isArray(o?.values)?o.values:[],m=new Set,$=[],w=/(\s)(\.[\w-]+)=["']?\s*$/,s=/(\s)(@[\w-]+)=["']?\s*$/,r=/(\s)(\?[\w-]+)=["']?\s*$/,u=/(\s)([\w:-]+)=["']?\s*$/,d=/=["']\s*$/,h=!1;for(let e=0;e<t.length;e+=1){let n=t[e]??"";if(h&&(n=n.replace(/^["']/,""),h=!1),e<c.length){let l=`pds-val-${e}`,b=n.match(w),p=n.match(s),f=n.match(r),C=n.match(u);if(b){let y=b[2].slice(1);h=d.test(t[e]??""),n=n.replace(w,`$1data-pds-bind-${e}="prop:${y}:${l}"`),m.add(e)}else if(p){let y=p[2].slice(1);h=d.test(t[e]??""),n=n.replace(s,`$1data-pds-bind-${e}="event:${y}:${l}"`),m.add(e)}else if(f){let y=f[2].slice(1);h=d.test(t[e]??""),n=n.replace(r,`$1data-pds-bind-${e}="boolean:${y}:${l}"`),m.add(e)}else if(C){let y=C[2];h=d.test(t[e]??""),n=n.replace(u,`$1data-pds-bind-${e}="attr:${y}:${l}"`),m.add(e)}}$.push(n),e<c.length&&!m.has(e)&&$.push(`<!--pds-val-${e}-->`)}let g=document.createElement("template");g.innerHTML=$.join("");let a=(e,n)=>{let l=e.parentNode;if(!l)return;if(n==null){l.removeChild(e);return}let b=p=>{if(p!=null){if(p instanceof Node){l.insertBefore(p,e);return}if(Array.isArray(p)){p.forEach(f=>b(f));return}l.insertBefore(document.createTextNode(String(p)),e)}};b(n),l.removeChild(e)},S=document.createTreeWalker(g.content,NodeFilter.SHOW_COMMENT),E=[];for(;S.nextNode();){let e=S.currentNode;e?.nodeValue?.startsWith("pds-val-")&&E.push(e)}return E.forEach(e=>{let n=Number(e.nodeValue.replace("pds-val-",""));a(e,c[n])}),g.content.querySelectorAll("*").forEach(e=>{[...e.attributes].forEach(n=>{if(!n.name.startsWith("data-pds-bind-"))return;let l=n.value.indexOf(":"),b=n.value.lastIndexOf(":");if(l<=0||b<=l){e.removeAttribute(n.name);return}let p=n.value.slice(0,l),f=n.value.slice(l+1,b),C=n.value.slice(b+1),y=Number(String(C).replace("pds-val-","")),v=c[y];if(!f||!Number.isInteger(y)){e.removeAttribute(n.name);return}p==="prop"?e[f]=v:p==="event"?(typeof v=="function"||v&&typeof v.handleEvent=="function")&&e.addEventListener(f,v):p==="boolean"?v?e.setAttribute(f,""):e.removeAttribute(f):p==="attr"&&(v==null||v===!1?e.removeAttribute(f):e.setAttribute(f,String(v))),e.removeAttribute(n.name)})}),g.content}var T=class extends EventTarget{constructor(){super(),this.mode=null,this.compiled=null,this.log=()=>{},this.logHandler=null}},F="__PURE_DS_PDS_SINGLETON__",L=typeof globalThis<"u"?globalThis:window,x=L?.[F],A=x&&typeof x.addEventListener=="function"?x:new T;L&&(L[F]=A);typeof A.log!="function"&&(A.log=(o="log",t,...c)=>{if(typeof console>"u")return;let m=typeof console[o]=="function"?console[o].bind(console):typeof console.log=="function"?console.log.bind(console):null;m&&(c.length>0?m(t,...c):m(t))});typeof A.logHandler!="function"&&(A.logHandler=null);function M(o,t){if(t==null)return;if(typeof t=="object"&&Array.isArray(t.strings)&&Array.isArray(t.values)){o.appendChild(N(t));return}if(t instanceof Node){o.appendChild(t);return}if(Array.isArray(t)){t.forEach(m=>M(o,m));return}let c=typeof t=="string"?t:String(t);o.appendChild(document.createTextNode(c))}function P(o){if(!o)return!0;let t=!0,c=r=>{if(!r||typeof r!="object")return"<unknown>";let u=r.tagName?String(r.tagName).toLowerCase():"node",d=r.id?`#${r.id}`:"",h=typeof r.getAttribute=="function"?r.getAttribute("name"):null,g=h?`[name="${h}"]`:"";return`${u}${d}${g}`},m=(r,u)=>{if(!r||typeof r.querySelectorAll!="function")return;let d=Array.from(r.querySelectorAll(":invalid"));if(!d.length)return;let h=d.map(g=>{let a=typeof g.validationMessage=="string"?g.validationMessage:"";return`${c(g)}${a?` \u2014 ${a}`:""}`});A.log("warn",`ask.validateDialogFormTree: invalid controls in ${u}:`,h)},$=(r,u)=>{try{let d=typeof r.reportValidity=="function"?r.reportValidity():r.checkValidity?.()??!0;return d||m(r,u),d}catch(d){return A.log("error",`ask.validateDialogFormTree: validation threw in ${u}`,d),!1}};t=$(o,"host dialog form")&&t;let w=Array.from(o.querySelectorAll("form"));for(let r of w){if(r===o)continue;t=$(r,`nested light DOM form ${c(r)}`)&&t}let s=Array.from(o.querySelectorAll("*"));for(let r of s){let u=r?.shadowRoot;if(!u)continue;let d=Array.from(u.querySelectorAll("form"));for(let h of d)t=$(h,`shadow form under ${c(r)}`)&&t}return t}function V(){let o=navigator.userAgent,t=/Safari/i.test(o),c=/(Chrome|Chromium|CriOS|FxiOS|EdgiOS|OPiOS|Opera)/i.test(o);return t&&!c}function k(o){if(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;let t=window.matchMedia?.("(max-width: 639px)").matches,c=o.classList.contains("dialog-no-scale-animation")?"pds-dialog-fade-enter":t?"pds-dialog-enter-mobile":"pds-dialog-enter";o.style.animation="none",o.offsetWidth,o.style.animation=`${c} var(--transition-normal) ease`,o.addEventListener("animationend",()=>{o.style.animation=""},{once:!0})}function D(o={}){return o?.liquidGlassEffects===!0}async function j(o,t={}){let c={title:"Confirm",type:"confirm",buttons:{ok:{name:"OK",primary:!0},cancel:{name:"Cancel",cancel:!0}}};t={...c,...t};let m=t.buttons&&typeof t.buttons=="object"?t.buttons:c.buttons,$=s=>{if(s==null)return{actionCode:"dismiss",actionKind:"dismiss",button:null};let r=m?.[s]??null,u=s==="ok"?"ok":s==="dismiss"?"dismiss":r?.cancel||s==="cancel"?"cancel":"custom";return{actionCode:s,actionKind:u,button:r}},w=s=>{if(typeof s>"u"||s===null||s===!0)return{allow:!0};if(s===!1)return{allow:!1};if(typeof s=="object"){let r=Object.prototype.hasOwnProperty.call(s,"result")||Object.prototype.hasOwnProperty.call(s,"value");return{allow:s.allow!==!1,hasResult:r,result:Object.prototype.hasOwnProperty.call(s,"result")?s.result:s.value}}return{allow:!!s}};return new Promise(s=>{let r=!1,u=(i,e,{shouldClose:n=!0}={})=>{if(!r&&(r=!0,s(i),!(!n||!e?.open)))try{e.close()}catch(l){A.log("warn","ask: dialog.close() failed",l)}},d=async i=>{if(i.actionKind!=="ok"||typeof t.beforeClose!="function")return{allow:!0};try{let e=await t.beforeClose(i);return w(e)}catch(e){return A.log("error","ask.beforeClose: validation failed",e),{allow:!1}}},h=({actionKind:i,form:e})=>i==="ok"?t.useForm&&e?new FormData(e):!0:!1,g=async({actionCode:i,form:e,submitter:n,originalEvent:l,bypassValidation:b=!1,shouldClose:p=!0})=>{if(r)return;let{actionKind:f,button:C}=$(i),y=e||a.querySelector("form")||null;if(t.useForm&&f==="ok"&&y&&!b&&!P(y))return;let v=h({actionKind:f,form:y}),O=await d({actionCode:i,actionKind:f,dialog:a,form:y,formData:t.useForm&&f==="ok"&&y?v:null,submitter:n,originalEvent:l,options:t,button:C,defaultResult:v});if(!O.allow)return;let q=O.hasResult?O.result:v;u(q,a,{shouldClose:p})},a=document.createElement("dialog");V()&&a.classList.add("dialog-no-scale-animation"),D(t)&&a.classList.add("liquid-glass"),t.size&&a.classList.add(`dialog-${t.size}`),t.type&&a.classList.add(`dialog-${t.type}`),t.class&&(Array.isArray(t.class)?a.classList.add(...t.class):a.classList.add(t.class)),t.maxHeight&&a.style.setProperty("--dialog-max-height",t.maxHeight);let S=Object.entries(m).map(([i,e])=>{let n=e.primary?"btn-primary btn-sm":"btn-outline btn-sm",l=e.cancel?"button":"submit",b=e.formNoValidate?" formnovalidate":"";return`<button type="${l}" class="${n}" value="${i}"${b}>${e.name}</button>`});if(t.useForm){let i=document.createElement("div");M(i,o);let e=i.querySelector("form");if(e){a.innerHTML=`
1
+ function N(o){let t=Array.isArray(o?.strings)?o.strings:[],c=Array.isArray(o?.values)?o.values:[],m=new Set,$=[],A=/(\s)(\.[\w-]+)=["']?\s*$/,s=/(\s)(@[\w-]+)=["']?\s*$/,r=/(\s)(\?[\w-]+)=["']?\s*$/,u=/(\s)([\w:-]+)=["']?\s*$/,d=/=["']\s*$/,y=!1;for(let e=0;e<t.length;e+=1){let n=t[e]??"";if(y&&(n=n.replace(/^["']/,""),y=!1),e<c.length){let l=`pds-val-${e}`,b=n.match(A),p=n.match(s),f=n.match(r),x=n.match(u);if(b){let h=b[2].slice(1);y=d.test(t[e]??""),n=n.replace(A,`$1data-pds-bind-${e}="prop:${h}:${l}"`),m.add(e)}else if(p){let h=p[2].slice(1);y=d.test(t[e]??""),n=n.replace(s,`$1data-pds-bind-${e}="event:${h}:${l}"`),m.add(e)}else if(f){let h=f[2].slice(1);y=d.test(t[e]??""),n=n.replace(r,`$1data-pds-bind-${e}="boolean:${h}:${l}"`),m.add(e)}else if(x){let h=x[2];y=d.test(t[e]??""),n=n.replace(u,`$1data-pds-bind-${e}="attr:${h}:${l}"`),m.add(e)}}$.push(n),e<c.length&&!m.has(e)&&$.push(`<!--pds-val-${e}-->`)}let g=document.createElement("template");g.innerHTML=$.join("");let i=(e,n)=>{let l=e.parentNode;if(!l)return;if(n==null){l.removeChild(e);return}let b=p=>{if(p!=null){if(p instanceof Node){l.insertBefore(p,e);return}if(Array.isArray(p)){p.forEach(f=>b(f));return}l.insertBefore(document.createTextNode(String(p)),e)}};b(n),l.removeChild(e)},S=document.createTreeWalker(g.content,NodeFilter.SHOW_COMMENT),C=[];for(;S.nextNode();){let e=S.currentNode;e?.nodeValue?.startsWith("pds-val-")&&C.push(e)}return C.forEach(e=>{let n=Number(e.nodeValue.replace("pds-val-",""));i(e,c[n])}),g.content.querySelectorAll("*").forEach(e=>{[...e.attributes].forEach(n=>{if(!n.name.startsWith("data-pds-bind-"))return;let l=n.value.indexOf(":"),b=n.value.lastIndexOf(":");if(l<=0||b<=l){e.removeAttribute(n.name);return}let p=n.value.slice(0,l),f=n.value.slice(l+1,b),x=n.value.slice(b+1),h=Number(String(x).replace("pds-val-","")),v=c[h];if(!f||!Number.isInteger(h)){e.removeAttribute(n.name);return}p==="prop"?e[f]=v:p==="event"?(typeof v=="function"||v&&typeof v.handleEvent=="function")&&e.addEventListener(f,v):p==="boolean"?v?e.setAttribute(f,""):e.removeAttribute(f):p==="attr"&&(v==null||v===!1?e.removeAttribute(f):e.setAttribute(f,String(v))),e.removeAttribute(n.name)})}),g.content}var O=class extends EventTarget{constructor(){super(),this.mode=null,this.compiled=null,this.log=()=>{},this.logHandler=null}},P="__PURE_DS_PDS_SINGLETON__",L=typeof globalThis<"u"?globalThis:window,T=L?.[P],w=T&&typeof T.addEventListener=="function"?T:new O;L&&(L[P]=w);typeof w.log!="function"&&(w.log=(o="log",t,...c)=>{if(typeof console>"u")return;let m=typeof console[o]=="function"?console[o].bind(console):typeof console.log=="function"?console.log.bind(console):null;m&&(c.length>0?m(t,...c):m(t))});typeof w.logHandler!="function"&&(w.logHandler=null);function F(o,t){if(t==null)return;if(typeof t=="object"&&Array.isArray(t.strings)&&Array.isArray(t.values)){o.appendChild(N(t));return}if(t instanceof Node){o.appendChild(t);return}if(Array.isArray(t)){t.forEach(m=>F(o,m));return}let c=typeof t=="string"?t:String(t);o.appendChild(document.createTextNode(c))}function M(o){if(!o)return!0;let t=!0,c=r=>{if(!r||typeof r!="object")return"<unknown>";let u=r.tagName?String(r.tagName).toLowerCase():"node",d=r.id?`#${r.id}`:"",y=typeof r.getAttribute=="function"?r.getAttribute("name"):null,g=y?`[name="${y}"]`:"";return`${u}${d}${g}`},m=(r,u)=>{if(!r||typeof r.querySelectorAll!="function")return;let d=Array.from(r.querySelectorAll(":invalid"));if(!d.length)return;let y=d.map(g=>{let i=typeof g.validationMessage=="string"?g.validationMessage:"";return`${c(g)}${i?` \u2014 ${i}`:""}`});w.log("warn",`ask.validateDialogFormTree: invalid controls in ${u}:`,y)},$=(r,u)=>{try{let d=typeof r.reportValidity=="function"?r.reportValidity():r.checkValidity?.()??!0;return d||m(r,u),d}catch(d){return w.log("error",`ask.validateDialogFormTree: validation threw in ${u}`,d),!1}};t=$(o,"host dialog form")&&t;let A=Array.from(o.querySelectorAll("form"));for(let r of A){if(r===o)continue;t=$(r,`nested light DOM form ${c(r)}`)&&t}let s=Array.from(o.querySelectorAll("*"));for(let r of s){let u=r?.shadowRoot;if(!u)continue;let d=Array.from(u.querySelectorAll("form"));for(let y of d)t=$(y,`shadow form under ${c(r)}`)&&t}return t}function V(){let o=navigator.userAgent,t=/Safari/i.test(o),c=/(Chrome|Chromium|CriOS|FxiOS|EdgiOS|OPiOS|Opera)/i.test(o);return t&&!c}function k(o){if(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;let t=window.matchMedia?.("(max-width: 639px)").matches,c=o.classList.contains("dialog-no-scale-animation")?"pds-dialog-fade-enter":t?"pds-dialog-enter-mobile":"pds-dialog-enter";o.style.animation="none",o.offsetWidth,o.style.animation=`${c} var(--transition-normal) ease`,o.addEventListener("animationend",()=>{o.style.animation=""},{once:!0})}function D(o={}){return o?.liquidGlassEffects===!0}async function j(o,t={}){let c={title:"Confirm",type:"confirm",buttons:{ok:{name:"OK",primary:!0},cancel:{name:"Cancel",cancel:!0}}};t={...c,...t};let m=t.buttons&&typeof t.buttons=="object"?t.buttons:c.buttons,$=s=>{if(s==null)return{actionCode:"dismiss",actionKind:"dismiss",button:null};let r=m?.[s]??null,u=s==="ok"?"ok":s==="dismiss"?"dismiss":r?.cancel||s==="cancel"?"cancel":"custom";return{actionCode:s,actionKind:u,button:r}},A=s=>{if(typeof s>"u"||s===null||s===!0)return{allow:!0};if(s===!1)return{allow:!1};if(typeof s=="object"){let r=Object.prototype.hasOwnProperty.call(s,"result")||Object.prototype.hasOwnProperty.call(s,"value");return{allow:s.allow!==!1,hasResult:r,result:Object.prototype.hasOwnProperty.call(s,"result")?s.result:s.value}}return{allow:!!s}};return new Promise(s=>{let r=!1,u=(a,e,{shouldClose:n=!0}={})=>{if(!r&&(r=!0,s(a),!(!n||!e?.open)))try{e.close()}catch(l){w.log("warn","ask: dialog.close() failed",l)}},d=async a=>{if(a.actionKind!=="ok"||typeof t.beforeClose!="function")return{allow:!0};try{let e=await t.beforeClose(a);return A(e)}catch(e){return w.log("error","ask.beforeClose: validation failed",e),{allow:!1}}},y=({actionKind:a,form:e})=>a==="ok"?t.useForm&&e?new FormData(e):!0:!1,g=async({actionCode:a,form:e,submitter:n,originalEvent:l,bypassValidation:b=!1,shouldClose:p=!0})=>{if(r)return;let{actionKind:f,button:x}=$(a),h=e||i.querySelector("form")||null;if(t.useForm&&f==="ok"&&h&&!b&&!M(h))return;let v=y({actionKind:f,form:h}),E=await d({actionCode:a,actionKind:f,dialog:i,form:h,formData:t.useForm&&f==="ok"&&h?v:null,submitter:n,originalEvent:l,options:t,button:x,defaultResult:v});if(!E.allow)return;let q=E.hasResult?E.result:v;u(q,i,{shouldClose:p})},i=document.createElement("dialog");V()&&i.classList.add("dialog-no-scale-animation"),D(t)&&i.classList.add("liquid-glass"),t.size&&i.classList.add(`dialog-${t.size}`),t.type&&i.classList.add(`dialog-${t.type}`),t.class&&(Array.isArray(t.class)?i.classList.add(...t.class):i.classList.add(t.class)),t.maxHeight&&i.style.setProperty("--dialog-max-height",t.maxHeight);let S=Object.entries(m).map(([a,e])=>{let n=e.primary?"btn-primary btn-sm":"btn-outline btn-sm",l=e.cancel?"button":"submit",b=e.formNoValidate?" formnovalidate":"";return`<button type="${l}" class="${n}" value="${a}"${b}>${e.name}</button>`});if(t.useForm){let a=document.createElement("div");F(a,o);let e=a.querySelector("form");if(e){i.innerHTML=`
2
2
  <header>
3
3
  <h2>${t.title}</h2>
4
4
  </header>
5
- `;let n=document.createElement("article");for(n.className="dialog-body";e.firstChild;)n.appendChild(e.firstChild);e.appendChild(n);let l=document.createElement("footer");l.innerHTML=S.join(""),e.appendChild(l),a.appendChild(e)}else a.innerHTML=`
5
+ `;let n=document.createElement("article");for(n.className="dialog-body";e.firstChild;)n.appendChild(e.firstChild);e.appendChild(n);let l=document.createElement("footer");l.innerHTML=S.join(""),e.appendChild(l),i.appendChild(e)}else i.innerHTML=`
6
6
  <header>
7
7
  <h2>${t.title}</h2>
8
8
  </header>
@@ -10,7 +10,7 @@ function N(o){let t=Array.isArray(o?.strings)?o.strings:[],c=Array.isArray(o?.va
10
10
  <footer>
11
11
  ${S.join("")}
12
12
  </footer>
13
- `,a.querySelector("#msg-container").appendChild(i)}else{a.innerHTML=`
13
+ `,i.querySelector("#msg-container").appendChild(a)}else{i.innerHTML=`
14
14
  <form method="dialog">
15
15
  <header>
16
16
  <h2>${t.title}</h2>
@@ -22,4 +22,4 @@ function N(o){let t=Array.isArray(o?.strings)?o.strings:[],c=Array.isArray(o?.va
22
22
  ${S.join("")}
23
23
  </footer>
24
24
  </form>
25
- `;let i=a.querySelector("#msg-container");M(i,o)}a.addEventListener("click",i=>{let e=i.target.closest('button[value="cancel"]');e&&g({actionCode:"cancel",form:a.querySelector("form"),submitter:e,originalEvent:i})});let E=()=>{let i=a.querySelector("form");if(i){if(i.dataset.askSubmitBound==="true")return;i.dataset.askSubmitBound="true",i.addEventListener("submit",e=>{e.preventDefault();let n=e.submitter?.value??(t.useForm?"ok":void 0),l=!!e.submitter?.hasAttribute("formnovalidate");g({actionCode:n,form:i,submitter:e.submitter,originalEvent:e,bypassValidation:l})})}else requestAnimationFrame(E)};a.addEventListener("cancel",i=>{i.preventDefault(),g({actionCode:"dismiss",form:a.querySelector("form"),originalEvent:i})}),a.addEventListener("close",()=>{r||u(!1,a,{shouldClose:!1}),setTimeout(()=>a.remove(),200)}),document.body.appendChild(a),requestAnimationFrame(E),typeof t.rendered=="function"&&t.rendered(a),a.showModal(),requestAnimationFrame(()=>k(a))})}export{j as ask};
25
+ `;let a=i.querySelector("#msg-container");F(a,o)}i.addEventListener("click",a=>{let e=a.target.closest('button[value="cancel"]');e&&g({actionCode:"cancel",form:i.querySelector("form"),submitter:e,originalEvent:a})});let C=()=>{let a=i.querySelector("form");if(a){if(a.dataset.askSubmitBound==="true")return;a.dataset.askSubmitBound="true",a.addEventListener("submit",e=>{e.preventDefault();let n=e.submitter?.value??(t.useForm?"ok":void 0),l=!!e.submitter?.hasAttribute("formnovalidate");g({actionCode:n,form:a,submitter:e.submitter,originalEvent:e,bypassValidation:l})})}else requestAnimationFrame(C)};i.addEventListener("cancel",a=>{a.preventDefault(),g({actionCode:"dismiss",form:i.querySelector("form"),originalEvent:a})}),i.addEventListener("close",()=>{r||u(!1,i,{shouldClose:!1}),setTimeout(()=>i.remove(),200)}),document.body.appendChild(i),requestAnimationFrame(C),typeof t.rendered=="function"&&t.rendered(i),i.showModal(),requestAnimationFrame(()=>k(i))})}export{j as ask};
@@ -1,7 +1,7 @@
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
- ${this.handleImageOrIcon(n)}
5
- <span class="text">${this.formatResultItem(n,e,r)}</span>
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(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};
1
+ function A(a){let t=Array.isArray(a?.strings)?a.strings:[],e=Array.isArray(a?.values)?a.values:[],s=new Set,r=[],n=/(\s)(\.[\w-]+)=["']?\s*$/,i=/(\s)(@[\w-]+)=["']?\s*$/,l=/(\s)(\?[\w-]+)=["']?\s*$/,h=/(\s)([\w:-]+)=["']?\s*$/,f=/=["']\s*$/,g=!1;for(let o=0;o<t.length;o+=1){let u=t[o]??"";if(g&&(u=u.replace(/^["']/,""),g=!1),o<e.length){let m=`pds-val-${o}`,x=u.match(n),y=u.match(i),b=u.match(l),C=u.match(h);if(x){let w=x[2].slice(1);g=f.test(t[o]??""),u=u.replace(n,`$1data-pds-bind-${o}="prop:${w}:${m}"`),s.add(o)}else if(y){let w=y[2].slice(1);g=f.test(t[o]??""),u=u.replace(i,`$1data-pds-bind-${o}="event:${w}:${m}"`),s.add(o)}else if(b){let w=b[2].slice(1);g=f.test(t[o]??""),u=u.replace(l,`$1data-pds-bind-${o}="boolean:${w}:${m}"`),s.add(o)}else if(C){let w=C[2];g=f.test(t[o]??""),u=u.replace(h,`$1data-pds-bind-${o}="attr:${w}:${m}"`),s.add(o)}}r.push(u),o<e.length&&!s.has(o)&&r.push(`<!--pds-val-${o}-->`)}let p=document.createElement("template");p.innerHTML=r.join("");let c=(o,u)=>{let m=o.parentNode;if(!m)return;if(u==null){m.removeChild(o);return}let x=y=>{if(y!=null){if(y instanceof Node){m.insertBefore(y,o);return}if(Array.isArray(y)){y.forEach(b=>x(b));return}m.insertBefore(document.createTextNode(String(y)),o)}};x(u),m.removeChild(o)},d=document.createTreeWalker(p.content,NodeFilter.SHOW_COMMENT),v=[];for(;d.nextNode();){let o=d.currentNode;o?.nodeValue?.startsWith("pds-val-")&&v.push(o)}return v.forEach(o=>{let u=Number(o.nodeValue.replace("pds-val-",""));c(o,e[u])}),p.content.querySelectorAll("*").forEach(o=>{[...o.attributes].forEach(u=>{if(!u.name.startsWith("data-pds-bind-"))return;let m=u.value.indexOf(":"),x=u.value.lastIndexOf(":");if(m<=0||x<=m){o.removeAttribute(u.name);return}let y=u.value.slice(0,m),b=u.value.slice(m+1,x),C=u.value.slice(x+1),w=Number(String(C).replace("pds-val-","")),$=e[w];if(!b||!Number.isInteger(w)){o.removeAttribute(u.name);return}y==="prop"?o[b]=$:y==="event"?(typeof $=="function"||$&&typeof $.handleEvent=="function")&&o.addEventListener(b,$):y==="boolean"?$?o.setAttribute(b,""):o.removeAttribute(b):y==="attr"&&($==null||$===!1?o.removeAttribute(b):o.setAttribute(b,String($))),o.removeAttribute(u.name)})}),p.content}function N(a,...t){if(Array.isArray(a)&&Object.prototype.hasOwnProperty.call(a,"raw"))return A({strings:Array.from(a),values:t});if(Array.isArray(a?.strings)&&Array.isArray(a?.values))return A({strings:a.strings,values:a.values});let s=document.createElement("template");return s.innerHTML=String(a??""),s.content}function S(a,...t){return N(a,...t).childNodes}function D(a,t=100){let e;return function(...r){let n=()=>{clearTimeout(e),a(...r)};clearTimeout(e),e=setTimeout(n,t)}}function I(a){setTimeout(a,0)}function k(a){try{if(typeof a!="string"||a.indexOf(`
2
+ `)!==-1||a.indexOf(" ")!==-1||a.startsWith("#/"))return!1;let t=new URL(a,window.location.origin);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}}function P(a,t,e="Operation"){return!t||t<=0?a:new Promise((s,r)=>{let n=setTimeout(()=>{r(new Error(`${e} timed out after ${t}ms`))},t);Promise.resolve(a).then(i=>{clearTimeout(n),s(i)}).catch(i=>{clearTimeout(n),r(i)})})}function H(a){return String(a).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function L(a,t,e){let s=window.screen.width/2-t/2,r=window.screen.height/2-e/2;return window.open(a,"",`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=${t}, height=${e}, top=${r}, left=${s}`)}function M(a){if(a==null)return"";let t=String(a).trim();return t?t.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/\s+/g," ").trim():""}var E={result:"ac-suggestion",item:"ac-itm"},O=class a extends EventTarget{constructor(t,e,s={}){super(),this.settings={emptyResultsText:"",progressive:!0,maxConcurrentCategories:3,categoryTimeoutMs:0,...s},this.container=t,this.input=e,this.input.setAttribute("autocomplete","off"),this.categories=s.categories||{},this.caches=new Map,this.rowIndex=-1,this.results=[],this.requestToken=0,I(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 a(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(E.result),this.container.offsetWidth>100&&(this.resultsDiv.style.width=`${this.container.offsetWidth}px`),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=t.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",D(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??0;if(!e)return;this.rowIndex=this.rowIndex+t,this.rowIndex<=0?this.rowIndex=0:this.rowIndex>e-1&&(this.rowIndex=0);for(let r of this.acItems)r.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){let e=t||this.getSelectedDiv();if(!e)return;let s=Number.parseInt(e.getAttribute("data-index"),10);this.resultClicked=!0;let r=Number.isInteger(s)?this.results[s]:null;if(!r)return;let n=this.categories[r.category]??{},i=typeof n.action=="function"?n.action:this.setText.bind(this);n.newTab&&(this.tabWindow=L("about:blank",960,700));let l={...r,search:this.input.value,selectedItem:e};e.classList.add("ac-active"),setTimeout(()=>{this.controller().hide("result-selected"),typeof l.action=="function"?l.action(l):(i(l),n.newTab&&this.tabWindow&&(l.url?this.tabWindow.location.href=l.url:this.tabWindow.close())),this.input.dispatchEvent(new Event("change",{bubbles:!0})),this.controller().clear("result-selected");let h=new Event("result-selected");h.detail=l,this.input.dispatchEvent(h)},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(`.${E.item}`))}blurHandler(){setTimeout(()=>{this.resultClicked||this.controller().clear("blurred"),this.resultClicked=!1},100)}clear(t,e={}){this.settings.debug||this.resultsDiv&&(this.resultsDiv.innerHTML="",e.preserveOpen||this.controller().hide("clear"),this.cacheTmr&&clearTimeout(this.cacheTmr),this.cacheTmr=setTimeout(()=>{this.caches.clear()},5*60*1e3))}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()}async inputHandler(t){this.cacheTmr&&clearTimeout(this.cacheTmr);let e={search:t.target.value,categories:this.categories},s=this.requestToken+1,r=this.settings.progressive===!0,n="",i=!1;this.container.classList.add("search-running");let l=(g,p={})=>{!r||p.token!==this.requestToken||(i=!0,n=this.resultsSignature(g),this.resultsHandler(g,e),this.input.dispatchEvent(new CustomEvent("results:partial",{detail:{results:g,token:p.token,pending:p.pending??0,completed:p.completed??0,settled:p.settled??!1}})))},h=await this.getItems(e,t,{onProgress:l,forceToken:s}).catch(()=>[]);if(s!==this.requestToken){this.container.classList.remove("search-running");return}let f=this.resultsSignature(h);(!i||f!==n)&&this.resultsHandler(h,e),this.input.dispatchEvent(new CustomEvent("results:complete",{detail:{results:h,token:s,pending:0,completed:Object.keys(this.categories||{}).length,settled:!0}})),this.container.classList.remove("search-running")}keyDownHandler(t){switch(t.key){case"Enter":t.stopPropagation(),t.preventDefault();break;case"ArrowDown":I(()=>this.moveResult(1));break;case"ArrowUp":I(()=>this.moveResult(-1));break;default: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"),this.suggest(t.target.value,t)}suggest(t,e){this.input.focus();let s={suggest:!0,search:t||"",categories:this.categories};this.getItems(s,e).then(r=>{this.input.dispatchEvent(new CustomEvent("show-results",{detail:{results:r}})),this.resultsHandler(r,s)})}sort(t,e){return t.sort((s,r)=>{let n=e.categories[s.category],i=e.categories[r.category],l=typeof n.sortIndex=="function"?n.sortIndex(e):n.sortIndex??0;return(typeof i.sortIndex=="function"?i.sortIndex(e):i.sortIndex??0)>l?1:-1})}resultsHandler(t,e){this.results=t,this.rowIndex=-1,this.resultsDiv.innerHTML="";let s=0,r=(n,i)=>{let l=this.formatCategoryLabel(i.category);return`
3
+ <div title="${i.tooltip||""}" data-index="${s}" class="${`${E.item} cat-${i.category} ${i.class??""}`.trim()}"${i.style?` style="${i.style}"`:""}>
4
+ ${this.handleImageOrIcon(i)}
5
+ <span class="text">${this.formatResultItem(i,e,n)}</span>
6
+ ${this.settings.hideCategory?"":`<span class="category">${l}</span>`}
7
+ </div>`};t.forEach(n=>{let i=e.categories[n.category]||{};if(n.element)this.resultsDiv.appendChild(n.element);else{let h=S(r(i,typeof n=="string"?{text:n}:n)),f=Array.from(h).find(g=>g&&g.nodeType===Node.ELEMENT_NODE);f&&this.resultsDiv.appendChild(f)}s+=1}),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 r=typeof t=="string"?{text:t}:t,n=r.text;return e.search&&(n=n.replace("%search%",e.search),r.description=r.description?.replace("%search%",e.search)),n=this.highlight(n,e.search),r.description&&(n=`<div>${n}</div><small>${r.description}</small>`),s.format&&(n=s.format({item:r,result:n,options:e})),n}formatCategoryLabel(t){return this.settings.humanizeCategoryLabels===!1?t||"":M(t||"")}highlight(t,e){if(!e)return t;try{let s=new RegExp(`(${H(e)})`,"gi");return t.replace(s,'<span class="txt-hl">$1</span>')}catch{return t}}resultsSignature(t){return!Array.isArray(t)||t.length===0?"":t.map(e=>!e||typeof e!="object"?String(e):`${e.category??""}|${e.id??""}|${e.value??""}|${e.text??""}`).join("||")}getCacheKey(t){let e=this.settings.locale||document?.documentElement?.lang||navigator?.language||"",s=String(t?.search??"").trim().toLowerCase(),r=Object.keys(t?.categories||{}).join(",");return`${e}::${s}::${r}`}async getItems(t,e,s={}){this.aborter&&this.aborter.abort();let r=s.forceToken||this.requestToken+1;this.requestToken=r;let n=this.getCacheKey(t);if(this.settings.cache!==!1&&this.caches.has(n)){let c=this.caches.get(n);return typeof s.onProgress=="function"&&s.onProgress(c,{token:r,pending:0,completed:Object.keys(t.categories||{}).length,settled:!0}),c}this.aborter=new AbortController,this.aborterSignal=this.aborter.signal;let i=this.items,l=this.settings.map,h=c=>typeof c=="string"?{text:c}:c,f=c=>l?c.map(d=>({text:d[l]})):c.map(d=>h(d)),g=c=>(this.settings.max&&this.settings.max>0&&(c.length=this.settings.max),c),p=c=>{let d=this.sort(c,t);return this.settings.cache!==!1&&this.caches.set(n,d),d};if(k(i)){if(this.settings.minlength>0&&(!t.search||t.search.length<this.settings.minlength))return p([]);let c=this.formatSearch(i,t),d=await fetch(c,{signal:this.aborterSignal});if(d.status!==200)throw Error(`HTTP error ${d.status} - ${c}`);let T=f(await d.json()).filter(o=>this.isMatch(t,o));return p(g(T))}if(Array.isArray(i)){let c=!0;return this.items=i.map(d=>typeof d=="string"?{text:d}:(c=!1,d)),c&&this.container.classList.add("simple"),p(g(f(this.items)))}if(typeof i=="function"){t.control=this.container;let c=this.settings.progressive===!0,d=await this.items(t,e,{progressive:c,token:r,onProgress:s.onProgress});return p(f(d))}return Promise.resolve(i.apply(this,t)).then(c=>p(c))}async runCategorySearch(t,e,s){let r=Number(this.settings.categoryTimeoutMs||0),n={...t,signal:this.aborterSignal};try{let i=await P(Promise.resolve(s.getItems(n)),r,`Category "${e}"`);return(Array.isArray(i)?i:[]).map(h=>{let f=typeof h=="string"?{text:h}:h;return f.category=e,f})}catch(i){return console.warn(`Error loading items for omniBox category '${e}'.`,i),[]}}async runCategoriesSequentially(t,e,s={}){let r=[],n=0;for(let[i,l]of e){let h=l||{};if(h.trigger=h.trigger??(()=>!0),h.getItems=h.getItems??(()=>[]),t.results=r,!h.trigger(t)){n+=1;continue}let f=await this.runCategorySearch(t,i,h);if(this.aborterSignal?.aborted)return r;if(r=r.concat(f),n+=1,typeof s.onProgress=="function"&&this.requestToken===s.token){let g=this.sort([...r],t);s.onProgress(g,{token:s.token,pending:Math.max(0,e.length-n),completed:n,settled:n===e.length})}}return r}async runCategoriesProgressive(t,e,s={}){let r=Math.max(1,Number(this.settings.maxConcurrentCategories||3)),n=[];for(let[c,d]of e){let v=d||{};v.trigger=v.trigger??(()=>!0),v.getItems=v.getItems??(()=>[]),t.results=[],v.trigger(t)&&n.push([c,v])}if(!n.length)return[];let i=0,l=0,h=[],f=async()=>{for(;i<n.length;){let c=i;i+=1;let[d,v]=n[c],T=await this.runCategorySearch(t,d,v);if(this.aborterSignal?.aborted)return;if(h.push(...T),l+=1,typeof s.onProgress=="function"&&this.requestToken===s.token){let o=this.sort([...h],t);s.onProgress(o,{token:s.token,pending:Math.max(0,n.length-l),completed:l,settled:l===n.length})}}},g=[],p=Math.min(r,n.length);for(let c=0;c<p;c+=1)g.push(f());return await Promise.all(g),h}async items(t,e,s={}){t.results=[],t.signal=this.aborterSignal;let r=Object.entries(t.categories||{});return r.length?s.progressive?this.runCategoriesProgressive(t,r,s):this.runCategoriesSequentially(t,r,s):[]}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(r){if(!t.search)return!0;if(r.hidden)return!1;let i=(e?r[e]:r).match(new RegExp(t.search,"gi"));return i||(r.config?.tags?r.config.tags.some(l=>l.match(new RegExp(t.search,"gi"))):!1)}}};export{O as AutoComplete};