@pure-ds/core 0.7.48 → 0.7.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/pds.d.ts +7 -5
- package/dist/types/public/assets/pds/components/pds-toaster.d.ts +4 -1
- package/dist/types/public/assets/pds/components/pds-toaster.d.ts.map +1 -1
- package/dist/types/src/js/common/toast.d.ts +9 -0
- package/dist/types/src/js/common/toast.d.ts.map +1 -1
- package/package.json +1 -1
- package/public/assets/js/app.js +2131 -5
- package/public/assets/js/app.js.map +7 -0
- package/public/assets/js/lit.js +1031 -3
- package/public/assets/js/lit.js.map +7 -0
- package/public/assets/js/pds-ask.js +464 -9
- package/public/assets/js/pds-ask.js.map +7 -0
- package/public/assets/js/pds-autocomplete.js +639 -7
- package/public/assets/js/pds-autocomplete.js.map +7 -0
- package/public/assets/js/pds-enhancers.js +1471 -1
- package/public/assets/js/pds-enhancers.js.map +7 -0
- package/public/assets/js/pds-manager.js +17568 -3384
- package/public/assets/js/pds-manager.js.map +7 -0
- package/public/assets/js/pds-toast.js +30 -1
- package/public/assets/js/pds-toast.js.map +7 -0
- package/public/assets/js/pds.js +1969 -2
- package/public/assets/js/pds.js.map +7 -0
- package/public/assets/pds/components/pds-toaster.js +25 -7
- package/public/assets/pds/core/pds-ask.js +464 -9
- package/public/assets/pds/core/pds-autocomplete.js +639 -7
- package/public/assets/pds/core/pds-enhancers.js +1471 -1
- package/public/assets/pds/core/pds-manager.js +17568 -3384
- package/public/assets/pds/core/pds-toast.js +30 -1
- package/public/assets/pds/core.js +1969 -2
- package/public/assets/pds/external/lit.js +1031 -3
- package/src/js/common/toast.js +8 -0
- package/src/js/pds-core/pds-generator.js +1 -1
- package/src/js/pds.d.ts +7 -5
|
@@ -1 +1,1471 @@
|
|
|
1
|
-
var ce=new Set(["log","warn","error","debug","info"]),le="__PURE_DS_PDS_SINGLETON__",N=null,U=null;function X(){try{let t=(typeof globalThis<"u"?globalThis:window)?.[le];if(t&&typeof t=="object")return t}catch{return null}return null}function ue(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 de(e){if(typeof e!="string")return"log";let t=e.toLowerCase();return ce.has(t)?t:"log"}function fe(){if(typeof U=="function")try{let t=ue(U());if(t)return t}catch{}let e=X();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 pe(){if(typeof N=="function")try{let t=N();if(typeof t=="function")return t}catch{}let e=X();return typeof e?.logHandler=="function"?e.logHandler:null}function G(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 ge(e,t){let n=t?.debug===!0;return!(t?.mode==="static"&&!n||!n&&e!=="error"&&e!=="warn")}function Y(e="log",t,...n){let o=de(e),r=fe(),a=pe();if(a)try{a.call(r?.thisArg,o,t,...n);return}catch(s){G("error","Custom log handler failed:",s)}ge(o,r)&&G(o,t,...n)}var he="en",l={defaultLocale:he,provider:null,messagesByLocale:new Map,loadingByLocale:new Map,observer:null,reconcileTimer:null,requestedKeys:new Set,textNodeKeyMap:new WeakMap,attributeKeyMap:new WeakMap,valueToKeys:new Map,missingWarnings:new Set},ye=["title","placeholder","aria-label","aria-description","aria-placeholder","aria-roledescription","alt","label"],be=e=>!!e&&typeof e!="string"&&typeof e=="object"&&"strTag"in e;function E(e){return String(e||"").trim().toLowerCase()}function me(e){let t=E(e);return t?t.split("-")[0]||t:""}function S(e){let t=E(e);if(!t)return l.defaultLocale;let n=l.provider?.resolveLocale;if(typeof n=="function"){let o=E(n(e));if(o)return o}return t}function Le(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 C(e,t){return String(e).replace(/\{(\d+)\}/g,(n,o)=>t(Number(o)))}function $(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 ve(e){let t=E(e);if(!t)return[l.defaultLocale];let n=me(t);return!n||n===t?[t]:[t,n]}function Z(e,t){let n=S(e);l.messagesByLocale.set(n,$(t))}function ee(e){typeof e=="string"&&e.length>0&&l.requestedKeys.add(e)}function J(e,t){if(typeof e!="string"||!e.length)return;let n=typeof t=="string"?t:String(t||"");n.length&&(l.valueToKeys.has(n)||l.valueToKeys.set(n,new Set),l.valueToKeys.get(n).add(e))}function q(e){let t=ve(e);for(let n of t)if(l.messagesByLocale.has(n))return{locale:n,messages:l.messagesByLocale.get(n)};return null}async function T(e,t="explicit"){let n=S(e),o=q(n);if(o)return o.messages;let r=n;if(l.loadingByLocale.has(r))return l.loadingByLocale.get(r);if(!l.provider)return{};let a=l.provider.loadLocale||l.provider.setLocale||null;if(typeof a!="function")return{};let s={locale:n,defaultLocale:l.defaultLocale,reason:t,loadedLocales:Array.from(l.messagesByLocale.keys()),messages:{...q(n)?.messages||{}},load:t==="set-default"||t==="explicit-load"},i;try{i=a(s)}catch{return{}}if(i&&typeof i.then=="function"){let c=i.then(p=>{let d=$(p);return Z(n,d),d}).catch(()=>({})).finally(()=>{l.loadingByLocale.delete(r)});return l.loadingByLocale.set(r,c),c}let u=$(i);return Z(n,u),u}function we(e){if(!e||typeof e!="object")return"";let n=typeof Element<"u"&&e instanceof Element||e?.nodeType===1?e:null;if(!n)return"";if(n.hasAttribute?.("lang"))return E(n.getAttribute("lang"));let o=n.closest?.("[lang]");return o&&o.getAttribute?E(o.getAttribute("lang")):""}function k(e={}){if(typeof e?.lang=="string"&&e.lang.trim())return S(e.lang);let t=e?.element||e?.scope||e?.host||e?.contextElement||null,n=we(t);if(n)return S(n);if(typeof document<"u"&&document.documentElement){let o=E(document.documentElement.getAttribute("lang"));if(o)return S(o)}return l.defaultLocale}function _e(){let e=new Set([l.defaultLocale]);if(typeof document>"u")return e;let t=E(document.documentElement?.getAttribute?.("lang"));t&&e.add(S(t));let n=document.querySelectorAll?.("[lang]")||[];for(let o of n){let r=E(o.getAttribute("lang"));r&&e.add(S(r))}return e}async function Ae(e){for(let t of e)await T(t,"lang-detected")}function Ee(e){for(let t of Array.from(l.messagesByLocale.keys()))e.has(t)||l.messagesByLocale.delete(t)}function xe(e){let t=String(e||""),n=(t.match(/^\s*/)||[""])[0],o=(t.match(/\s*$/)||[""])[0],r=n.length,a=t.length-o.length,s=a>=r?t.slice(r,a):"";return{leading:n,core:s,trailing:o}}function Q(e){return String(e||"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Se(e,t){let n=typeof e=="string"?e:String(e||""),o=typeof t=="string"?t:String(t||""),r=/\{(\d+)\}/g,a=Array.from(n.matchAll(r));if(!a.length)return n===o?[]:null;let s=[],i="^",u=0;for(let d of a){let g=d.index??0;i+=Q(n.slice(u,g)),i+="([\\s\\S]*?)",s.push(Number(d[1])),u=g+d[0].length}i+=Q(n.slice(u)),i+="$";let c=new RegExp(i).exec(o);if(!c)return null;let p=[];for(let d=1;d<c.length;d+=1){let g=s[d-1],y=c[d];if(Object.prototype.hasOwnProperty.call(p,g)&&p[g]!==y)return null;p[g]=y}return p}function I(e,t){if(typeof e!="string"||!e.length)return[];let n=[e];for(let[,o]of l.messagesByLocale.entries()){let r=o?.[e];typeof r=="string"&&r.length&&n.push(r)}for(let o of n){let r=Se(o,t);if(r)return r}return[]}function te(e){if(!e)return null;let t=l.valueToKeys.get(e);if(t&&t.size>0){for(let o of t)if(l.requestedKeys.has(o))return o}if(l.requestedKeys.has(e))return e;let n=Array.from(l.messagesByLocale.entries());for(let o of l.requestedKeys)for(let[,r]of n)if(r&&r[o]===e)return o;return null}function ne(e){if(!e)return null;let t=null;for(let[n,o]of l.valueToKeys.entries()){if(typeof n!="string"||!n.length||n===e)continue;let r=e.indexOf(n);if(r!==-1)for(let a of o){if(!l.requestedKeys.has(a))continue;let s=I(a,n),i={key:a,matchedText:n,start:r,end:r+n.length,values:s};(!t||i.matchedText.length>t.matchedText.length)&&(t=i);break}}return t}async function Me(e){if(!e||e.nodeType!==3)return;let t=e.parentElement||null;if(!t)return;let{leading:n,core:o,trailing:r}=xe(e.nodeValue);if(!o)return;let a=l.textNodeKeyMap.get(e)||null;if((!a||!l.requestedKeys.has(a))&&(a=te(o)),!a){let d=ne(o);if(!d)return;let g=k({element:t});await T(g,"text-node");let y=O(d.key,d.values,{element:t},null),m=d.values.length?C(y,D=>d.values[D]):y,v=o.slice(0,d.start)+m+o.slice(d.end),P=`${n}${v}${r}`;P!==e.nodeValue&&(e.nodeValue=P);return}l.textNodeKeyMap.set(e,a);let s=k({element:t});await T(s,"text-node");let i=I(a,o),u=O(a,i,{element:t},null),c=i.length?C(u,d=>i[d]):u,p=`${n}${c}${r}`;p!==e.nodeValue&&(e.nodeValue=p)}async function Ce(){if(typeof document>"u"||l.requestedKeys.size===0)return;let e=document.body||document.documentElement;if(!e||typeof document.createTreeWalker!="function")return;let t=[],n=new Set,o=a=>{!a||n.has(a)||(n.add(a),t.push(a))};o(e);for(let a=0;a<t.length;a+=1){let s=t[a];if(!s||typeof s.querySelectorAll!="function")continue;let i=s.querySelectorAll("*");for(let u of i){let c=u?.shadowRoot;c&&o(c)}}let r=[];for(let a of t){let s=document.createTreeWalker(a,NodeFilter.SHOW_TEXT);for(;s.nextNode();)r.push(s.currentNode)}for(let a of r)await Me(a)}function Te(e){let t=l.attributeKeyMap.get(e);return t||(t=new Map,l.attributeKeyMap.set(e,t)),t}async function Oe(e,t){if(!e||typeof e.getAttribute!="function")return;let n=e.getAttribute(t);if(typeof n!="string"||!n.length)return;let o=Te(e),r=o.get(t)||null;if((!r||!l.requestedKeys.has(r))&&(r=te(n)),!r){let c=ne(n);if(!c)return;let p=k({element:e});await T(p,"attribute");let d=O(c.key,c.values,{element:e},null),g=c.values.length?C(d,m=>c.values[m]):d,y=n.slice(0,c.start)+g+n.slice(c.end);y!==n&&e.setAttribute(t,y),o.set(t,c.key);return}o.set(t,r);let a=k({element:e});await T(a,"attribute");let s=I(r,n),i=O(r,s,{element:e},null),u=s.length?C(i,c=>s[c]):i;u!==n&&e.setAttribute(t,u)}async function qe(){if(typeof document>"u"||l.requestedKeys.size===0)return;let e=document.body||document.documentElement;if(!e)return;let t=[],n=new Set,o=r=>{!r||n.has(r)||(n.add(r),t.push(r))};o(e);for(let r=0;r<t.length;r+=1){let a=t[r];if(!a||typeof a.querySelectorAll!="function")continue;let s=a.querySelectorAll("*");for(let i of s){let u=i?.shadowRoot;u&&o(u)}}for(let r of t){if(!r||typeof r.querySelectorAll!="function")continue;let a=r.querySelectorAll("*");for(let s of a)for(let i of ye)s.hasAttribute(i)&&await Oe(s,i)}}async function ke(){let e=_e();await Ae(e),await Ce(),await qe(),Ee(e)}function Pe(){typeof window>"u"||(l.reconcileTimer&&clearTimeout(l.reconcileTimer),l.reconcileTimer=setTimeout(()=>{l.reconcileTimer=null,ke()},16))}function O(e,t=[],n={},o=null){let r=k(n),a=q(r);a||T(r,"msg");let s=q(r)?.messages||{},i=q(l.defaultLocale)?.messages||{},u={key:e,values:t,options:n,locale:r,defaultLocale:l.defaultLocale,messages:s,messagesByLocale:Object.fromEntries(Array.from(l.messagesByLocale.entries())),template:o},c,p=!!a,d=r===l.defaultLocale;typeof l.provider?.translate=="function"&&(c=l.provider.translate(u));let g=null;if(c==null&&(c=s[e]),c==null&&(c=i[e],g=c==null?null:"default"),c==null&&(c=e,g="key"),p&&!d&&g){let m=`${r}::${e}`;l.missingWarnings.has(m)||(l.missingWarnings.add(m),Y("warn",`[i18n] Missing translation for locale "${r}" and key "${e}"; using ${g} fallback.`))}let y=typeof c=="string"?c:String(c);if(J(e,y),Array.isArray(t)&&t.length>0){let m=C(y,v=>t[v]);m!==y&&J(e,m)}return y}var Re=(e,t,n={})=>{let o=Le(e);ee(o);let r=O(o,t,n,{strings:e,values:t});return C(r,a=>t[a])};var B=(e,t={})=>{if(!e)return"";if(be(e))return Re(e.strings,e.values,t);let n=String(e);ee(n);let o=O(n,[],t,null);return!t?.element&&!t?.scope&&!t?.host&&!t?.contextElement&&!t?.lang&&Pe(),o};var Be=[{selector:".accordion"},{selector:"nav[data-dropdown]"},{selector:"label[data-toggle]"},{selector:"label[data-color]"},{selector:'input[type="range"]'},{selector:"form[data-required]"},{selector:"fieldset[role=group][data-open]"},{selector:"[data-clip]"},{selector:"button, a[class*='btn-']"}];function De(e){e.dataset.enhancedAccordion||(e.dataset.enhancedAccordion="true",e.addEventListener("toggle",t=>{t.target.open&&t.target.parentElement===e&&e.querySelectorAll(":scope > details[open]").forEach(n=>{n!==t.target&&(n.open=!1)})},!0))}function Ke(e){if(e.dataset.enhancedDropdown)return;e.dataset.enhancedDropdown="true";let t=e.lastElementChild;if(!t)return;let n=e.querySelector("[data-dropdown-toggle]")||e.querySelector("button"),o=typeof HTMLElement<"u"&&"showPopover"in HTMLElement.prototype&&"hidePopover"in HTMLElement.prototype;n&&!n.hasAttribute("type")&&n.setAttribute("type","button"),t.id||(t.id=`dropdown-${Math.random().toString(36).slice(2,9)}`);let r=t.tagName?.toLowerCase()==="menu",a=8;if(r&&!t.hasAttribute("role")&&t.setAttribute("role","menu"),t.hasAttribute("aria-hidden")||t.setAttribute("aria-hidden","true"),n&&(n.setAttribute("aria-haspopup","true"),n.setAttribute("aria-controls",t.id),n.setAttribute("aria-expanded","false")),!o){let f="__PDS_DROPDOWN_POPOVER_WARNED__";globalThis[f]||(globalThis[f]=!0,console.warn("[PDS] nav[data-dropdown] requires the Popover API. Add a popover polyfill (recommended: @oddbird/popover-polyfill) for browsers without support."));return}t.setAttribute("popover","auto");let s=()=>{let f=t.getAttribute("style");t.style.visibility="hidden",t.style.display="inline-block",t.style.pointerEvents="none";let h=t.getBoundingClientRect(),L=Math.max(t.offsetWidth||0,t.scrollWidth||0,h.width||0,1),b=Math.max(t.offsetHeight||0,t.scrollHeight||0,h.height||0,1);return f===null?t.removeAttribute("style"):t.setAttribute("style",f),{width:L,height:b}},i=()=>{try{return t.matches(":popover-open")}catch{return!1}},u=()=>{t.setAttribute("aria-hidden","true"),n?.setAttribute("aria-expanded","false")},c=()=>{t.setAttribute("aria-hidden","false"),n?.setAttribute("aria-expanded","true")},p=()=>{let f=(e.getAttribute("data-direction")||e.getAttribute("data-dropdown-direction")||e.getAttribute("data-mode")||"auto").toLowerCase();if(f==="up"||f==="down")return f;let h=(n||e).getBoundingClientRect(),{height:L}=s(),b=Math.max(0,window.innerHeight-h.bottom),w=Math.max(0,h.top),A=b>=L,_=w>=L;return A&&!_?"down":_&&!A?"up":A&&_?"down":w>b?"up":"down"},d=()=>{let f=(e.getAttribute("data-align")||e.getAttribute("data-dropdown-align")||"auto").toLowerCase();if(f==="left"||f==="right"||f==="start"||f==="end")return f==="start"?"left":f==="end"?"right":f;let h=(n||e).getBoundingClientRect(),{width:L}=s(),b=Math.max(0,window.innerWidth-h.left),w=Math.max(0,h.right),A=b>=L,_=w>=L;return A&&!_?"left":_&&!A?"right":A&&_?"left":w>b?"right":"left"},g=(f,h=8)=>{let L=getComputedStyle(e).getPropertyValue(f).trim();if(!L)return h;let b=document.createElement("span");b.style.position="fixed",b.style.visibility="hidden",b.style.pointerEvents="none",b.style.height=L,document.body.appendChild(b);let w=Number.parseFloat(getComputedStyle(b).height);return b.remove(),Number.isFinite(w)?w:h},y=()=>{["position","left","top","right","bottom","margin-top","margin-bottom","max-width","max-inline-size","max-height","overflow"].forEach(f=>t.style.removeProperty(f))},m=()=>{if(!i())return;let f=(n||e).getBoundingClientRect(),h=window.visualViewport,L=h?.width||document.documentElement?.clientWidth||window.innerWidth,b=h?.height||document.documentElement?.clientHeight||window.innerHeight,w=h?.offsetLeft||0,A=h?.offsetTop||0,_=Math.max(1,L-a*2),ie=Math.max(1,b-a*2);t.style.maxWidth=`${Math.round(_)}px`,t.style.maxInlineSize=`${Math.round(_)}px`,t.style.maxHeight=`${Math.round(ie)}px`,t.style.overflow="auto";let{width:z,height:F}=s(),j=g("--spacing-2",8),V=p(),H=d();e.dataset.dropdownDirection=V,e.dataset.dropdownAlign=H;let R=H==="right"?f.right-z:f.left;z>=_-1?R=w+a:R=Math.max(w+a,Math.min(R,w+L-z-a));let W=V==="up"?f.top-j-F:f.bottom+j;W=Math.max(A+a,Math.min(W,A+b-F-a)),Object.assign(t.style,{position:"fixed",left:`${Math.round(R)}px`,top:`${Math.round(W)}px`,right:"auto",bottom:"auto",marginTop:"0",marginBottom:"0"})},v=null,P=()=>{v||(v=()=>m(),window.addEventListener("resize",v),window.addEventListener("scroll",v,!0))},D=()=>{v&&(window.removeEventListener("resize",v),window.removeEventListener("scroll",v,!0),v=null)},M=null,x=null,oe=()=>{M||typeof document>"u"||(M=()=>{i()&&(e.dataset.dropdownDirection=p(),e.dataset.dropdownAlign=d(),x!==null&&cancelAnimationFrame(x),x=requestAnimationFrame(()=>{x=null,i()&&m()}))},document.addEventListener("pds:config-changed",M))},re=()=>{!M||typeof document>"u"||(document.removeEventListener("pds:config-changed",M),M=null,x!==null&&(cancelAnimationFrame(x),x=null))};t.addEventListener("toggle",f=>{if(f.newState==="open"){c(),m(),P(),oe();return}u(),D(),re(),y()});let ae=()=>{i()||(e.dataset.dropdownDirection=p(),e.dataset.dropdownAlign=d(),t.showPopover(),requestAnimationFrame(()=>m()))},K=()=>{i()&&t.hidePopover()},se=()=>{i()?K():ae()};u(),t.addEventListener("click",f=>{let h=f.target instanceof Element?f.target:f.target?.parentElement;h&&h.closest("[data-dropdown-close]")&&K()}),n?.addEventListener("click",f=>{f.preventDefault(),f.stopPropagation(),se()}),e.addEventListener("keydown",f=>{f.key==="Escape"&&(K(),n?.focus())})}function ze(e){if(e.dataset.enhancedToggle)return;e.dataset.enhancedToggle="true";let t=e.querySelector('input[type="checkbox"]');if(!t)return;e.hasAttribute("tabindex")||e.setAttribute("tabindex","0"),e.setAttribute("role","switch"),e.setAttribute("aria-checked",t.checked?"true":"false");let n=document.createElement("span");n.className="toggle-switch",n.setAttribute("role","presentation"),n.setAttribute("aria-hidden","true");let o=document.createElement("span");o.className="toggle-knob",n.appendChild(o),e.insertBefore(n,t.nextSibling);let r=()=>{e.setAttribute("aria-checked",t.checked?"true":"false")},a=()=>{t.disabled||(t.checked=!t.checked,r(),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})))};e.addEventListener("click",s=>{s.preventDefault(),a()}),e.addEventListener("keydown",s=>{(s.key===" "||s.key==="Enter")&&(s.preventDefault(),a())}),t.addEventListener("change",r)}function We(e){if(e.dataset.enhancedColorInput)return;let t=e.querySelector('input[type="color"]');if(!t)return;e.dataset.enhancedColorInput="true";let n=e.querySelector(":scope > .color-control"),o=e.querySelector(":scope > .color-control > .color-swatch"),r=e.querySelector(":scope > .color-control > output");n||(n=document.createElement("span"),n.className="color-control",t.before(n)),o||(o=document.createElement("span"),o.className="color-swatch",n.appendChild(o)),t.parentElement!==o&&o.appendChild(t),r||(r=document.createElement("output"),n.appendChild(r));let a=()=>{if(t.dataset.colorUnset==="1"){r.value="",r.textContent=B("not set"),n.dataset.value="",n.dataset.unset="1",o.dataset.unset="1";return}r.value=t.value,r.textContent=t.value,n.dataset.value=t.value,delete n.dataset.unset,delete o.dataset.unset};a();let s=()=>{t.dataset.colorUnset==="1"&&(t.dataset.colorUnset="0"),a()};t.addEventListener("input",s,{passive:!0}),t.addEventListener("change",s,{passive:!0})}function $e(e){if(e.dataset.enhancedRange)return;let t=s=>{if(e.dataset.enhancedRangeProgrammatic)return;e.dataset.enhancedRangeProgrammatic="1";let i=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e),"value")||Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value");i?.get&&i?.set&&Object.defineProperty(e,"value",{configurable:!0,enumerable:i.enumerable,get(){return i.get.call(this)},set(c){i.set.call(this,c),s()}}),new MutationObserver(c=>{c.some(d=>{let g=d.attributeName;return g==="value"||g==="min"||g==="max"})&&s()}).observe(e,{attributes:!0,attributeFilter:["value","min","max"]})},n=e.closest("label"),o=n?.classList.contains("range-output"),r=e.id||`range-${Math.random().toString(36).substring(2,11)}`,a=`${r}-output`;if(e.id=r,o){let s=n.querySelector("span");if(s&&!s.classList.contains("range-output-wrapper")){let i=s.getAttribute("data-range-label")||n.getAttribute("data-range-label")||"",u=document.createElement("span");u.className="range-output-wrapper",u.style.display="flex",u.style.justifyContent="space-between",u.style.alignItems="center";let c=document.createElement("span");c.textContent=i||s.textContent,u.appendChild(c);let p=document.createElement("output");p.id=a,p.setAttribute("for",r),p.style.color="var(--surface-text-secondary, var(--color-text-secondary))",p.style.fontSize="0.875rem",p.textContent=e.value,u.appendChild(p),s.textContent="",s.appendChild(u);let d=()=>{p.textContent=e.value};e.addEventListener("input",d),e.addEventListener("change",d),t(d),d()}}else{let s=e.closest(".range-container");s||(s=document.createElement("div"),s.className="range-container",e.parentNode?.insertBefore(s,e),s.appendChild(e)),s.style.position="relative";let i=document.createElement("output");i.id=a,i.setAttribute("for",r),i.className="range-bubble",i.setAttribute("aria-live","polite"),s.appendChild(i);let u=()=>{let d=parseFloat(e.min)||0,g=parseFloat(e.max)||100,y=parseFloat(e.value),m=(y-d)/(g-d);i.style.left=`calc(${m*100}% )`,i.textContent=String(y)},c=()=>i.classList.add("visible"),p=()=>i.classList.remove("visible");e.addEventListener("input",u),e.addEventListener("pointerdown",c),e.addEventListener("pointerup",p),e.addEventListener("pointerleave",p),e.addEventListener("focus",c),e.addEventListener("blur",p),e.addEventListener("change",u),t(u),u()}e.dataset.enhancedRange="1"}function Ie(e){if(e.dataset.enhancedRequired)return;e.dataset.enhancedRequired="true";let t=n=>{let o;if(n.closest("[role$=group]")?o=n.closest("[role$=group]").querySelector("legend"):o=n.closest("label"),!o||o.querySelector(".required-asterisk"))return;let r=document.createElement("span");r.classList.add("required-asterisk"),r.textContent="*",r.style.marginLeft="4px";let a=o.querySelector("span, [data-label]");if(a)a.appendChild(r);else{let i=o.querySelector("input, select, textarea");i?o.insertBefore(r,i):o.appendChild(r)}let s=n.closest("form");if(s&&!s.querySelector(".required-legend")){let i=document.createElement("small");i.classList.add("required-legend"),i.textContent=B("* Required fields"),s.insertBefore(i,s.querySelector(".form-actions")||s.lastElementChild)}};e.querySelectorAll("[required]").forEach(n=>{t(n)})}function Fe(e){if(e.dataset.enhancedOpenGroup)return;e.dataset.enhancedOpenGroup="true",e.classList.add("flex","flex-wrap","buttons");let t=document.createElement("input");t.type="text",t.placeholder=B("Add item..."),t.classList.add("input-text","input-sm"),t.style.width="auto";let n=()=>e.querySelector('input[type="radio"], input[type="checkbox"]');e.appendChild(t),t.addEventListener("keydown",o=>{if(o.key==="Enter"||o.key==="Tab"){let r=t.value.trim();if(r){o.preventDefault();let a=n(),s=a?.type==="radio"?"radio":"checkbox",i=`open-group-${Math.random().toString(36).substring(2,11)}`,u=document.createElement("label"),c=document.createElement("span");c.setAttribute("data-label",""),c.textContent=r;let p=document.createElement("input");p.type=s,p.name=a?.name||e.getAttribute("data-name")||"open-group",p.value=r,p.id=i,u.appendChild(c),u.appendChild(p),e.insertBefore(u,t),t.value=""}}else if(o.key==="Backspace"&&t.value===""){o.preventDefault();let r=e.querySelectorAll("label");r.length>0&&r[r.length-1].remove()}})}function je(e){if(e.dataset.enhancedClip)return;e.dataset.enhancedClip="true",e.hasAttribute("tabindex")||e.setAttribute("tabindex","0"),e.hasAttribute("role")||e.setAttribute("role","button");let t=()=>{let o=e.getAttribute("data-clip-open")==="true";e.setAttribute("aria-expanded",o?"true":"false")},n=()=>{let o=e.getAttribute("data-clip-open")==="true";e.setAttribute("data-clip-open",o?"false":"true"),t()};e.addEventListener("click",o=>{o.defaultPrevented||n()}),e.addEventListener("keydown",o=>{(o.key===" "||o.key==="Enter")&&(o.preventDefault(),n())}),t()}function Ve(e){if(e.dataset.enhancedBtnWorking)return;e.dataset.enhancedBtnWorking="true";let t=null,n=!1;new MutationObserver(r=>{r.forEach(a=>{if(a.attributeName==="class"){let s=e.classList.contains("btn-working"),i=e.querySelector("pds-icon");if(s)if(i)t||(t=i.getAttribute("icon")),i.setAttribute("icon","circle-notch");else{let u=document.createElement("pds-icon");u.setAttribute("icon","circle-notch"),u.setAttribute("size","sm"),e.insertBefore(u,e.firstChild),n=!0}else a.oldValue?.includes("btn-working")&&i&&(n?(i.remove(),n=!1):t&&(i.setAttribute("icon",t),t=null))}})}).observe(e,{attributes:!0,attributeFilter:["class"],attributeOldValue:!0})}var He=new Map([[".accordion",De],["nav[data-dropdown]",Ke],["label[data-toggle]",ze],["label[data-color]",We],['input[type="range"]',$e],["form[data-required]",Ie],["fieldset[role=group][data-open]",Fe],["[data-clip]",je],["button, a[class*='btn-']",Ve]]),Ne=Be.map(e=>({...e,run:He.get(e.selector)||(()=>{})}));export{Ne as defaultPDSEnhancers};
|
|
1
|
+
// src/js/common/pds-log.js
|
|
2
|
+
var __SUPPORTED_LOG_LEVELS = /* @__PURE__ */ new Set(["log", "warn", "error", "debug", "info"]);
|
|
3
|
+
var __PDS_SINGLETON_KEY = "__PURE_DS_PDS_SINGLETON__";
|
|
4
|
+
var __logProvider = null;
|
|
5
|
+
var __contextProvider = null;
|
|
6
|
+
function __resolveGlobalPDS() {
|
|
7
|
+
try {
|
|
8
|
+
const scope = typeof globalThis !== "undefined" ? globalThis : window;
|
|
9
|
+
const candidate = scope?.[__PDS_SINGLETON_KEY];
|
|
10
|
+
if (candidate && typeof candidate === "object") {
|
|
11
|
+
return candidate;
|
|
12
|
+
}
|
|
13
|
+
} catch (error) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
function __normalizeContext(context) {
|
|
19
|
+
if (!context || typeof context !== "object") {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
mode: context.mode === "live" || context.mode === "static" ? context.mode : null,
|
|
24
|
+
debug: context.debug === true,
|
|
25
|
+
thisArg: context.thisArg
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function __normalizeLevel(level) {
|
|
29
|
+
if (typeof level !== "string")
|
|
30
|
+
return "log";
|
|
31
|
+
const normalized = level.toLowerCase();
|
|
32
|
+
return __SUPPORTED_LOG_LEVELS.has(normalized) ? normalized : "log";
|
|
33
|
+
}
|
|
34
|
+
function __resolveContext() {
|
|
35
|
+
if (typeof __contextProvider === "function") {
|
|
36
|
+
try {
|
|
37
|
+
const configuredContext = __normalizeContext(__contextProvider());
|
|
38
|
+
if (configuredContext) {
|
|
39
|
+
return configuredContext;
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const globalPDS = __resolveGlobalPDS();
|
|
45
|
+
if (globalPDS) {
|
|
46
|
+
const mode = globalPDS?.mode || globalPDS?.compiled?.mode || (globalPDS?.registry?.isLive ? "live" : "static");
|
|
47
|
+
const debug = (globalPDS?.debug || globalPDS?.currentConfig?.debug || globalPDS?.currentConfig?.design?.debug || globalPDS?.compiled?.debug || globalPDS?.compiled?.design?.debug || false) === true;
|
|
48
|
+
return {
|
|
49
|
+
mode,
|
|
50
|
+
debug,
|
|
51
|
+
thisArg: globalPDS
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return { mode: null, debug: false };
|
|
55
|
+
}
|
|
56
|
+
function __resolveLogger() {
|
|
57
|
+
if (typeof __logProvider === "function") {
|
|
58
|
+
try {
|
|
59
|
+
const logger = __logProvider();
|
|
60
|
+
if (typeof logger === "function") {
|
|
61
|
+
return logger;
|
|
62
|
+
}
|
|
63
|
+
} catch (error) {
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const globalPDS = __resolveGlobalPDS();
|
|
67
|
+
if (typeof globalPDS?.logHandler === "function") {
|
|
68
|
+
return globalPDS.logHandler;
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function __consoleLog(level, message, ...data) {
|
|
73
|
+
if (typeof console === "undefined")
|
|
74
|
+
return;
|
|
75
|
+
const method = typeof console[level] === "function" ? console[level].bind(console) : typeof console.log === "function" ? console.log.bind(console) : null;
|
|
76
|
+
if (!method)
|
|
77
|
+
return;
|
|
78
|
+
if (data.length > 0) {
|
|
79
|
+
method(message, ...data);
|
|
80
|
+
} else {
|
|
81
|
+
method(message);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function __shouldUseConsoleFallback(level, context) {
|
|
85
|
+
const debugEnabled = context?.debug === true;
|
|
86
|
+
const staticMode = context?.mode === "static";
|
|
87
|
+
if (staticMode && !debugEnabled) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (!debugEnabled && level !== "error" && level !== "warn") {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
function pdsLog(level = "log", message, ...data) {
|
|
96
|
+
const normalizedLevel = __normalizeLevel(level);
|
|
97
|
+
const context = __resolveContext();
|
|
98
|
+
const customLogger = __resolveLogger();
|
|
99
|
+
if (customLogger) {
|
|
100
|
+
try {
|
|
101
|
+
customLogger.call(context?.thisArg, normalizedLevel, message, ...data);
|
|
102
|
+
return;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
__consoleLog("error", "Custom log handler failed:", error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (!__shouldUseConsoleFallback(normalizedLevel, context)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
__consoleLog(normalizedLevel, message, ...data);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/js/common/localization.js
|
|
114
|
+
var __DEFAULT_LOCALE__ = "en";
|
|
115
|
+
var __localizationState = {
|
|
116
|
+
defaultLocale: __DEFAULT_LOCALE__,
|
|
117
|
+
provider: null,
|
|
118
|
+
messagesByLocale: /* @__PURE__ */ new Map(),
|
|
119
|
+
loadingByLocale: /* @__PURE__ */ new Map(),
|
|
120
|
+
observer: null,
|
|
121
|
+
reconcileTimer: null,
|
|
122
|
+
requestedKeys: /* @__PURE__ */ new Set(),
|
|
123
|
+
textNodeKeyMap: /* @__PURE__ */ new WeakMap(),
|
|
124
|
+
attributeKeyMap: /* @__PURE__ */ new WeakMap(),
|
|
125
|
+
valueToKeys: /* @__PURE__ */ new Map(),
|
|
126
|
+
missingWarnings: /* @__PURE__ */ new Set()
|
|
127
|
+
};
|
|
128
|
+
var __LOCALIZABLE_ATTRIBUTES = [
|
|
129
|
+
"title",
|
|
130
|
+
"placeholder",
|
|
131
|
+
"aria-label",
|
|
132
|
+
"aria-description",
|
|
133
|
+
"aria-placeholder",
|
|
134
|
+
"aria-roledescription",
|
|
135
|
+
"alt",
|
|
136
|
+
"label"
|
|
137
|
+
];
|
|
138
|
+
var __isStrTagged = (val) => Boolean(val) && typeof val !== "string" && typeof val === "object" && "strTag" in val;
|
|
139
|
+
function __normalizeLocale(locale) {
|
|
140
|
+
return String(locale || "").trim().toLowerCase();
|
|
141
|
+
}
|
|
142
|
+
function __toBaseLocale(locale) {
|
|
143
|
+
const normalized = __normalizeLocale(locale);
|
|
144
|
+
if (!normalized)
|
|
145
|
+
return "";
|
|
146
|
+
return normalized.split("-")[0] || normalized;
|
|
147
|
+
}
|
|
148
|
+
function __resolveLocaleCandidate(locale) {
|
|
149
|
+
const normalized = __normalizeLocale(locale);
|
|
150
|
+
if (!normalized) {
|
|
151
|
+
return __localizationState.defaultLocale;
|
|
152
|
+
}
|
|
153
|
+
const resolveLocale = __localizationState.provider?.resolveLocale;
|
|
154
|
+
if (typeof resolveLocale === "function") {
|
|
155
|
+
const resolved = __normalizeLocale(resolveLocale(locale));
|
|
156
|
+
if (resolved) {
|
|
157
|
+
return resolved;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return normalized;
|
|
161
|
+
}
|
|
162
|
+
function __collateStrings(strings) {
|
|
163
|
+
let result = "";
|
|
164
|
+
for (let index = 0; index <= strings.length - 1; index += 1) {
|
|
165
|
+
result += strings[index];
|
|
166
|
+
if (index < strings.length - 1) {
|
|
167
|
+
result += `{${index}}`;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
function __replacePlaceholders(input, callback) {
|
|
173
|
+
return String(input).replace(/\{(\d+)\}/g, (_match, index) => callback(Number(index)));
|
|
174
|
+
}
|
|
175
|
+
function __normalizeMessages(messages) {
|
|
176
|
+
if (!messages || typeof messages !== "object") {
|
|
177
|
+
return {};
|
|
178
|
+
}
|
|
179
|
+
const normalized = {};
|
|
180
|
+
for (const [key, value] of Object.entries(messages)) {
|
|
181
|
+
if (typeof value === "string") {
|
|
182
|
+
normalized[key] = value;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (value && typeof value === "object" && typeof value.content === "string") {
|
|
186
|
+
normalized[key] = value.content;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return normalized;
|
|
190
|
+
}
|
|
191
|
+
function __localeVariants(locale) {
|
|
192
|
+
const normalized = __normalizeLocale(locale);
|
|
193
|
+
if (!normalized) {
|
|
194
|
+
return [__localizationState.defaultLocale];
|
|
195
|
+
}
|
|
196
|
+
const base = __toBaseLocale(normalized);
|
|
197
|
+
if (!base || base === normalized) {
|
|
198
|
+
return [normalized];
|
|
199
|
+
}
|
|
200
|
+
return [normalized, base];
|
|
201
|
+
}
|
|
202
|
+
function __setLocaleMessages(locale, messages) {
|
|
203
|
+
const normalizedLocale = __resolveLocaleCandidate(locale);
|
|
204
|
+
__localizationState.messagesByLocale.set(
|
|
205
|
+
normalizedLocale,
|
|
206
|
+
__normalizeMessages(messages)
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
function __registerRequestedKey(key) {
|
|
210
|
+
if (typeof key === "string" && key.length > 0) {
|
|
211
|
+
__localizationState.requestedKeys.add(key);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function __indexTranslatedValue(key, value) {
|
|
215
|
+
if (typeof key !== "string" || !key.length) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const translatedValue = typeof value === "string" ? value : String(value || "");
|
|
219
|
+
if (!translatedValue.length) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (!__localizationState.valueToKeys.has(translatedValue)) {
|
|
223
|
+
__localizationState.valueToKeys.set(translatedValue, /* @__PURE__ */ new Set());
|
|
224
|
+
}
|
|
225
|
+
__localizationState.valueToKeys.get(translatedValue).add(key);
|
|
226
|
+
}
|
|
227
|
+
function __getLocaleMessages(locale) {
|
|
228
|
+
const variants = __localeVariants(locale);
|
|
229
|
+
for (const candidate of variants) {
|
|
230
|
+
if (__localizationState.messagesByLocale.has(candidate)) {
|
|
231
|
+
return {
|
|
232
|
+
locale: candidate,
|
|
233
|
+
messages: __localizationState.messagesByLocale.get(candidate)
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
async function __loadLocaleInternal(locale, reason = "explicit") {
|
|
240
|
+
const targetLocale = __resolveLocaleCandidate(locale);
|
|
241
|
+
const existing = __getLocaleMessages(targetLocale);
|
|
242
|
+
if (existing) {
|
|
243
|
+
return existing.messages;
|
|
244
|
+
}
|
|
245
|
+
const loadingKey = targetLocale;
|
|
246
|
+
if (__localizationState.loadingByLocale.has(loadingKey)) {
|
|
247
|
+
return __localizationState.loadingByLocale.get(loadingKey);
|
|
248
|
+
}
|
|
249
|
+
if (!__localizationState.provider) {
|
|
250
|
+
return {};
|
|
251
|
+
}
|
|
252
|
+
const loader = __localizationState.provider.loadLocale || __localizationState.provider.setLocale || null;
|
|
253
|
+
if (typeof loader !== "function") {
|
|
254
|
+
return {};
|
|
255
|
+
}
|
|
256
|
+
const context = {
|
|
257
|
+
locale: targetLocale,
|
|
258
|
+
defaultLocale: __localizationState.defaultLocale,
|
|
259
|
+
reason,
|
|
260
|
+
loadedLocales: Array.from(__localizationState.messagesByLocale.keys()),
|
|
261
|
+
messages: {
|
|
262
|
+
...__getLocaleMessages(targetLocale)?.messages || {}
|
|
263
|
+
},
|
|
264
|
+
load: reason === "set-default" || reason === "explicit-load"
|
|
265
|
+
};
|
|
266
|
+
let result;
|
|
267
|
+
try {
|
|
268
|
+
result = loader(context);
|
|
269
|
+
} catch {
|
|
270
|
+
return {};
|
|
271
|
+
}
|
|
272
|
+
if (result && typeof result.then === "function") {
|
|
273
|
+
const promise = result.then((value) => {
|
|
274
|
+
const normalized2 = __normalizeMessages(value);
|
|
275
|
+
__setLocaleMessages(targetLocale, normalized2);
|
|
276
|
+
return normalized2;
|
|
277
|
+
}).catch(() => ({})).finally(() => {
|
|
278
|
+
__localizationState.loadingByLocale.delete(loadingKey);
|
|
279
|
+
});
|
|
280
|
+
__localizationState.loadingByLocale.set(loadingKey, promise);
|
|
281
|
+
return promise;
|
|
282
|
+
}
|
|
283
|
+
const normalized = __normalizeMessages(result);
|
|
284
|
+
__setLocaleMessages(targetLocale, normalized);
|
|
285
|
+
return normalized;
|
|
286
|
+
}
|
|
287
|
+
function __resolveLocaleFromElementScope(element) {
|
|
288
|
+
if (!element || typeof element !== "object") {
|
|
289
|
+
return "";
|
|
290
|
+
}
|
|
291
|
+
const canUseElementCtor = typeof Element !== "undefined";
|
|
292
|
+
const el = canUseElementCtor && element instanceof Element ? element : element?.nodeType === 1 ? element : null;
|
|
293
|
+
if (!el) {
|
|
294
|
+
return "";
|
|
295
|
+
}
|
|
296
|
+
if (el.hasAttribute?.("lang")) {
|
|
297
|
+
return __normalizeLocale(el.getAttribute("lang"));
|
|
298
|
+
}
|
|
299
|
+
const scoped = el.closest?.("[lang]");
|
|
300
|
+
if (scoped && scoped.getAttribute) {
|
|
301
|
+
return __normalizeLocale(scoped.getAttribute("lang"));
|
|
302
|
+
}
|
|
303
|
+
return "";
|
|
304
|
+
}
|
|
305
|
+
function __resolveContextLocale(options = {}) {
|
|
306
|
+
if (typeof options?.lang === "string" && options.lang.trim()) {
|
|
307
|
+
return __resolveLocaleCandidate(options.lang);
|
|
308
|
+
}
|
|
309
|
+
const scopeElement = options?.element || options?.scope || options?.host || options?.contextElement || null;
|
|
310
|
+
const scopedLocale = __resolveLocaleFromElementScope(scopeElement);
|
|
311
|
+
if (scopedLocale) {
|
|
312
|
+
return __resolveLocaleCandidate(scopedLocale);
|
|
313
|
+
}
|
|
314
|
+
if (typeof document !== "undefined" && document.documentElement) {
|
|
315
|
+
const rootLocale = __normalizeLocale(document.documentElement.getAttribute("lang"));
|
|
316
|
+
if (rootLocale) {
|
|
317
|
+
return __resolveLocaleCandidate(rootLocale);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return __localizationState.defaultLocale;
|
|
321
|
+
}
|
|
322
|
+
function __collectDetectedLocales() {
|
|
323
|
+
const detected = /* @__PURE__ */ new Set([__localizationState.defaultLocale]);
|
|
324
|
+
if (typeof document === "undefined") {
|
|
325
|
+
return detected;
|
|
326
|
+
}
|
|
327
|
+
const rootLang = __normalizeLocale(document.documentElement?.getAttribute?.("lang"));
|
|
328
|
+
if (rootLang) {
|
|
329
|
+
detected.add(__resolveLocaleCandidate(rootLang));
|
|
330
|
+
}
|
|
331
|
+
const nodes = document.querySelectorAll?.("[lang]") || [];
|
|
332
|
+
for (const node of nodes) {
|
|
333
|
+
const lang = __normalizeLocale(node.getAttribute("lang"));
|
|
334
|
+
if (lang) {
|
|
335
|
+
detected.add(__resolveLocaleCandidate(lang));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return detected;
|
|
339
|
+
}
|
|
340
|
+
async function __ensureDetectedLocalesLoaded(detectedLocales) {
|
|
341
|
+
for (const locale of detectedLocales) {
|
|
342
|
+
await __loadLocaleInternal(locale, "lang-detected");
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function __pruneUndetectedLocales(detectedLocales) {
|
|
346
|
+
for (const loadedLocale of Array.from(__localizationState.messagesByLocale.keys())) {
|
|
347
|
+
if (!detectedLocales.has(loadedLocale)) {
|
|
348
|
+
__localizationState.messagesByLocale.delete(loadedLocale);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
function __splitTextWhitespace(value) {
|
|
353
|
+
const input = String(value || "");
|
|
354
|
+
const leading = (input.match(/^\s*/) || [""])[0];
|
|
355
|
+
const trailing = (input.match(/\s*$/) || [""])[0];
|
|
356
|
+
const start = leading.length;
|
|
357
|
+
const end = input.length - trailing.length;
|
|
358
|
+
const core = end >= start ? input.slice(start, end) : "";
|
|
359
|
+
return { leading, core, trailing };
|
|
360
|
+
}
|
|
361
|
+
function __escapeRegExp(value) {
|
|
362
|
+
return String(value || "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
363
|
+
}
|
|
364
|
+
function __extractValuesFromTemplate(template, text) {
|
|
365
|
+
const inputTemplate = typeof template === "string" ? template : String(template || "");
|
|
366
|
+
const inputText = typeof text === "string" ? text : String(text || "");
|
|
367
|
+
const placeholderPattern = /\{(\d+)\}/g;
|
|
368
|
+
const matches = Array.from(inputTemplate.matchAll(placeholderPattern));
|
|
369
|
+
if (!matches.length) {
|
|
370
|
+
return inputTemplate === inputText ? [] : null;
|
|
371
|
+
}
|
|
372
|
+
const placeholderOrder = [];
|
|
373
|
+
let pattern = "^";
|
|
374
|
+
let lastIndex = 0;
|
|
375
|
+
for (const match of matches) {
|
|
376
|
+
const matchIndex = match.index ?? 0;
|
|
377
|
+
pattern += __escapeRegExp(inputTemplate.slice(lastIndex, matchIndex));
|
|
378
|
+
pattern += "([\\s\\S]*?)";
|
|
379
|
+
placeholderOrder.push(Number(match[1]));
|
|
380
|
+
lastIndex = matchIndex + match[0].length;
|
|
381
|
+
}
|
|
382
|
+
pattern += __escapeRegExp(inputTemplate.slice(lastIndex));
|
|
383
|
+
pattern += "$";
|
|
384
|
+
const result = new RegExp(pattern).exec(inputText);
|
|
385
|
+
if (!result) {
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
const values = [];
|
|
389
|
+
for (let groupIndex = 1; groupIndex < result.length; groupIndex += 1) {
|
|
390
|
+
const placeholderIndex = placeholderOrder[groupIndex - 1];
|
|
391
|
+
const extractedValue = result[groupIndex];
|
|
392
|
+
if (Object.prototype.hasOwnProperty.call(values, placeholderIndex) && values[placeholderIndex] !== extractedValue) {
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
values[placeholderIndex] = extractedValue;
|
|
396
|
+
}
|
|
397
|
+
return values;
|
|
398
|
+
}
|
|
399
|
+
function __resolveTemplateValuesForText(key, text) {
|
|
400
|
+
if (typeof key !== "string" || !key.length) {
|
|
401
|
+
return [];
|
|
402
|
+
}
|
|
403
|
+
const templates = [key];
|
|
404
|
+
for (const [, messages] of __localizationState.messagesByLocale.entries()) {
|
|
405
|
+
const candidate = messages?.[key];
|
|
406
|
+
if (typeof candidate === "string" && candidate.length) {
|
|
407
|
+
templates.push(candidate);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
for (const template of templates) {
|
|
411
|
+
const extracted = __extractValuesFromTemplate(template, text);
|
|
412
|
+
if (extracted) {
|
|
413
|
+
return extracted;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return [];
|
|
417
|
+
}
|
|
418
|
+
function __findRequestedKeyForText(coreText) {
|
|
419
|
+
if (!coreText) {
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
const indexedKeys = __localizationState.valueToKeys.get(coreText);
|
|
423
|
+
if (indexedKeys && indexedKeys.size > 0) {
|
|
424
|
+
for (const key of indexedKeys) {
|
|
425
|
+
if (__localizationState.requestedKeys.has(key)) {
|
|
426
|
+
return key;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (__localizationState.requestedKeys.has(coreText)) {
|
|
431
|
+
return coreText;
|
|
432
|
+
}
|
|
433
|
+
const loadedEntries = Array.from(__localizationState.messagesByLocale.entries());
|
|
434
|
+
for (const key of __localizationState.requestedKeys) {
|
|
435
|
+
for (const [, messages] of loadedEntries) {
|
|
436
|
+
if (messages && messages[key] === coreText) {
|
|
437
|
+
return key;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
443
|
+
function __findRequestedSubsegmentForText(coreText) {
|
|
444
|
+
if (!coreText) {
|
|
445
|
+
return null;
|
|
446
|
+
}
|
|
447
|
+
let bestMatch = null;
|
|
448
|
+
for (const [indexedValue, indexedKeys] of __localizationState.valueToKeys.entries()) {
|
|
449
|
+
if (typeof indexedValue !== "string" || !indexedValue.length) {
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
if (indexedValue === coreText) {
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
const start = coreText.indexOf(indexedValue);
|
|
456
|
+
if (start === -1) {
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
for (const key of indexedKeys) {
|
|
460
|
+
if (!__localizationState.requestedKeys.has(key)) {
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
const values = __resolveTemplateValuesForText(key, indexedValue);
|
|
464
|
+
const candidate = {
|
|
465
|
+
key,
|
|
466
|
+
matchedText: indexedValue,
|
|
467
|
+
start,
|
|
468
|
+
end: start + indexedValue.length,
|
|
469
|
+
values
|
|
470
|
+
};
|
|
471
|
+
if (!bestMatch || candidate.matchedText.length > bestMatch.matchedText.length) {
|
|
472
|
+
bestMatch = candidate;
|
|
473
|
+
}
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return bestMatch;
|
|
478
|
+
}
|
|
479
|
+
async function __localizeTextNode(textNode) {
|
|
480
|
+
if (!textNode || textNode.nodeType !== 3) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
const parentElement = textNode.parentElement || null;
|
|
484
|
+
if (!parentElement) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
const { leading, core, trailing } = __splitTextWhitespace(textNode.nodeValue);
|
|
488
|
+
if (!core) {
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
let key = __localizationState.textNodeKeyMap.get(textNode) || null;
|
|
492
|
+
if (!key || !__localizationState.requestedKeys.has(key)) {
|
|
493
|
+
key = __findRequestedKeyForText(core);
|
|
494
|
+
}
|
|
495
|
+
if (!key) {
|
|
496
|
+
const segmentMatch = __findRequestedSubsegmentForText(core);
|
|
497
|
+
if (!segmentMatch) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
const scopedLocale2 = __resolveContextLocale({ element: parentElement });
|
|
501
|
+
await __loadLocaleInternal(scopedLocale2, "text-node");
|
|
502
|
+
const translated2 = __resolveTranslation(
|
|
503
|
+
segmentMatch.key,
|
|
504
|
+
segmentMatch.values,
|
|
505
|
+
{ element: parentElement },
|
|
506
|
+
null
|
|
507
|
+
);
|
|
508
|
+
const translatedText2 = segmentMatch.values.length ? __replacePlaceholders(translated2, (index) => segmentMatch.values[index]) : translated2;
|
|
509
|
+
const localizedCore = core.slice(0, segmentMatch.start) + translatedText2 + core.slice(segmentMatch.end);
|
|
510
|
+
const localizedText = `${leading}${localizedCore}${trailing}`;
|
|
511
|
+
if (localizedText !== textNode.nodeValue) {
|
|
512
|
+
textNode.nodeValue = localizedText;
|
|
513
|
+
}
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
__localizationState.textNodeKeyMap.set(textNode, key);
|
|
517
|
+
const scopedLocale = __resolveContextLocale({ element: parentElement });
|
|
518
|
+
await __loadLocaleInternal(scopedLocale, "text-node");
|
|
519
|
+
const values = __resolveTemplateValuesForText(key, core);
|
|
520
|
+
const translated = __resolveTranslation(key, values, { element: parentElement }, null);
|
|
521
|
+
const translatedText = values.length ? __replacePlaceholders(translated, (index) => values[index]) : translated;
|
|
522
|
+
const nextText = `${leading}${translatedText}${trailing}`;
|
|
523
|
+
if (nextText !== textNode.nodeValue) {
|
|
524
|
+
textNode.nodeValue = nextText;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
async function __localizeRequestedTextNodes() {
|
|
528
|
+
if (typeof document === "undefined" || __localizationState.requestedKeys.size === 0) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
const root = document.body || document.documentElement;
|
|
532
|
+
if (!root || typeof document.createTreeWalker !== "function") {
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
const roots = [];
|
|
536
|
+
const seenRoots = /* @__PURE__ */ new Set();
|
|
537
|
+
const addRoot = (candidateRoot) => {
|
|
538
|
+
if (!candidateRoot || seenRoots.has(candidateRoot)) {
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
seenRoots.add(candidateRoot);
|
|
542
|
+
roots.push(candidateRoot);
|
|
543
|
+
};
|
|
544
|
+
addRoot(root);
|
|
545
|
+
for (let index = 0; index < roots.length; index += 1) {
|
|
546
|
+
const currentRoot = roots[index];
|
|
547
|
+
if (!currentRoot || typeof currentRoot.querySelectorAll !== "function") {
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
const elements = currentRoot.querySelectorAll("*");
|
|
551
|
+
for (const element of elements) {
|
|
552
|
+
const shadowRoot = element?.shadowRoot;
|
|
553
|
+
if (shadowRoot) {
|
|
554
|
+
addRoot(shadowRoot);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
const nodes = [];
|
|
559
|
+
for (const scanRoot of roots) {
|
|
560
|
+
const walker = document.createTreeWalker(scanRoot, NodeFilter.SHOW_TEXT);
|
|
561
|
+
while (walker.nextNode()) {
|
|
562
|
+
nodes.push(walker.currentNode);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
for (const node of nodes) {
|
|
566
|
+
await __localizeTextNode(node);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function __getElementAttributeKeyMap(element) {
|
|
570
|
+
let map = __localizationState.attributeKeyMap.get(element);
|
|
571
|
+
if (!map) {
|
|
572
|
+
map = /* @__PURE__ */ new Map();
|
|
573
|
+
__localizationState.attributeKeyMap.set(element, map);
|
|
574
|
+
}
|
|
575
|
+
return map;
|
|
576
|
+
}
|
|
577
|
+
async function __localizeAttribute(element, attrName) {
|
|
578
|
+
if (!element || typeof element.getAttribute !== "function") {
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
const rawValue = element.getAttribute(attrName);
|
|
582
|
+
if (typeof rawValue !== "string" || !rawValue.length) {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
const keyMap = __getElementAttributeKeyMap(element);
|
|
586
|
+
let key = keyMap.get(attrName) || null;
|
|
587
|
+
if (!key || !__localizationState.requestedKeys.has(key)) {
|
|
588
|
+
key = __findRequestedKeyForText(rawValue);
|
|
589
|
+
}
|
|
590
|
+
if (!key) {
|
|
591
|
+
const segmentMatch = __findRequestedSubsegmentForText(rawValue);
|
|
592
|
+
if (!segmentMatch) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
const scopedLocale2 = __resolveContextLocale({ element });
|
|
596
|
+
await __loadLocaleInternal(scopedLocale2, "attribute");
|
|
597
|
+
const translated2 = __resolveTranslation(segmentMatch.key, segmentMatch.values, { element }, null);
|
|
598
|
+
const translatedText2 = segmentMatch.values.length ? __replacePlaceholders(translated2, (index) => segmentMatch.values[index]) : translated2;
|
|
599
|
+
const localizedValue = rawValue.slice(0, segmentMatch.start) + translatedText2 + rawValue.slice(segmentMatch.end);
|
|
600
|
+
if (localizedValue !== rawValue) {
|
|
601
|
+
element.setAttribute(attrName, localizedValue);
|
|
602
|
+
}
|
|
603
|
+
keyMap.set(attrName, segmentMatch.key);
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
keyMap.set(attrName, key);
|
|
607
|
+
const scopedLocale = __resolveContextLocale({ element });
|
|
608
|
+
await __loadLocaleInternal(scopedLocale, "attribute");
|
|
609
|
+
const values = __resolveTemplateValuesForText(key, rawValue);
|
|
610
|
+
const translated = __resolveTranslation(key, values, { element }, null);
|
|
611
|
+
const translatedText = values.length ? __replacePlaceholders(translated, (index) => values[index]) : translated;
|
|
612
|
+
if (translatedText !== rawValue) {
|
|
613
|
+
element.setAttribute(attrName, translatedText);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
async function __localizeRequestedAttributes() {
|
|
617
|
+
if (typeof document === "undefined" || __localizationState.requestedKeys.size === 0) {
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
const root = document.body || document.documentElement;
|
|
621
|
+
if (!root) {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
const roots = [];
|
|
625
|
+
const seenRoots = /* @__PURE__ */ new Set();
|
|
626
|
+
const addRoot = (candidateRoot) => {
|
|
627
|
+
if (!candidateRoot || seenRoots.has(candidateRoot)) {
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
seenRoots.add(candidateRoot);
|
|
631
|
+
roots.push(candidateRoot);
|
|
632
|
+
};
|
|
633
|
+
addRoot(root);
|
|
634
|
+
for (let index = 0; index < roots.length; index += 1) {
|
|
635
|
+
const currentRoot = roots[index];
|
|
636
|
+
if (!currentRoot || typeof currentRoot.querySelectorAll !== "function") {
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
const elements = currentRoot.querySelectorAll("*");
|
|
640
|
+
for (const element of elements) {
|
|
641
|
+
const shadowRoot = element?.shadowRoot;
|
|
642
|
+
if (shadowRoot) {
|
|
643
|
+
addRoot(shadowRoot);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
for (const scanRoot of roots) {
|
|
648
|
+
if (!scanRoot || typeof scanRoot.querySelectorAll !== "function") {
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
const elements = scanRoot.querySelectorAll("*");
|
|
652
|
+
for (const element of elements) {
|
|
653
|
+
for (const attrName of __LOCALIZABLE_ATTRIBUTES) {
|
|
654
|
+
if (element.hasAttribute(attrName)) {
|
|
655
|
+
await __localizeAttribute(element, attrName);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
async function __reconcileLocalization() {
|
|
662
|
+
const detectedLocales = __collectDetectedLocales();
|
|
663
|
+
await __ensureDetectedLocalesLoaded(detectedLocales);
|
|
664
|
+
await __localizeRequestedTextNodes();
|
|
665
|
+
await __localizeRequestedAttributes();
|
|
666
|
+
__pruneUndetectedLocales(detectedLocales);
|
|
667
|
+
}
|
|
668
|
+
function __scheduleReconcile() {
|
|
669
|
+
if (typeof window === "undefined") {
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
if (__localizationState.reconcileTimer) {
|
|
673
|
+
clearTimeout(__localizationState.reconcileTimer);
|
|
674
|
+
}
|
|
675
|
+
__localizationState.reconcileTimer = setTimeout(() => {
|
|
676
|
+
__localizationState.reconcileTimer = null;
|
|
677
|
+
__reconcileLocalization();
|
|
678
|
+
}, 16);
|
|
679
|
+
}
|
|
680
|
+
function __resolveTranslation(key, values = [], options = {}, template = null) {
|
|
681
|
+
const requestedLocale = __resolveContextLocale(options);
|
|
682
|
+
const resolvedMessages = __getLocaleMessages(requestedLocale);
|
|
683
|
+
if (!resolvedMessages) {
|
|
684
|
+
__loadLocaleInternal(requestedLocale, "msg");
|
|
685
|
+
}
|
|
686
|
+
const targetMessages = __getLocaleMessages(requestedLocale)?.messages || {};
|
|
687
|
+
const defaultMessages = __getLocaleMessages(__localizationState.defaultLocale)?.messages || {};
|
|
688
|
+
const context = {
|
|
689
|
+
key,
|
|
690
|
+
values,
|
|
691
|
+
options,
|
|
692
|
+
locale: requestedLocale,
|
|
693
|
+
defaultLocale: __localizationState.defaultLocale,
|
|
694
|
+
messages: targetMessages,
|
|
695
|
+
messagesByLocale: Object.fromEntries(
|
|
696
|
+
Array.from(__localizationState.messagesByLocale.entries())
|
|
697
|
+
),
|
|
698
|
+
template
|
|
699
|
+
};
|
|
700
|
+
let translated;
|
|
701
|
+
const localeLoaded = Boolean(resolvedMessages);
|
|
702
|
+
const isDefaultLocale = requestedLocale === __localizationState.defaultLocale;
|
|
703
|
+
if (typeof __localizationState.provider?.translate === "function") {
|
|
704
|
+
translated = __localizationState.provider.translate(context);
|
|
705
|
+
}
|
|
706
|
+
let fallbackKind = null;
|
|
707
|
+
if (translated === void 0 || translated === null) {
|
|
708
|
+
translated = targetMessages[key];
|
|
709
|
+
}
|
|
710
|
+
if (translated === void 0 || translated === null) {
|
|
711
|
+
translated = defaultMessages[key];
|
|
712
|
+
fallbackKind = translated === void 0 || translated === null ? null : "default";
|
|
713
|
+
}
|
|
714
|
+
if (translated === void 0 || translated === null) {
|
|
715
|
+
translated = key;
|
|
716
|
+
fallbackKind = "key";
|
|
717
|
+
}
|
|
718
|
+
if (localeLoaded && !isDefaultLocale && fallbackKind) {
|
|
719
|
+
const warningKey = `${requestedLocale}::${key}`;
|
|
720
|
+
if (!__localizationState.missingWarnings.has(warningKey)) {
|
|
721
|
+
__localizationState.missingWarnings.add(warningKey);
|
|
722
|
+
pdsLog(
|
|
723
|
+
"warn",
|
|
724
|
+
`[i18n] Missing translation for locale "${requestedLocale}" and key "${key}"; using ${fallbackKind} fallback.`
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
const resolved = typeof translated === "string" ? translated : String(translated);
|
|
729
|
+
__indexTranslatedValue(key, resolved);
|
|
730
|
+
if (Array.isArray(values) && values.length > 0) {
|
|
731
|
+
const materialized = __replacePlaceholders(resolved, (index) => values[index]);
|
|
732
|
+
if (materialized !== resolved) {
|
|
733
|
+
__indexTranslatedValue(key, materialized);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return resolved;
|
|
737
|
+
}
|
|
738
|
+
var joinStringsAndValues = (strings, values, options = {}) => {
|
|
739
|
+
const messageKey = __collateStrings(strings);
|
|
740
|
+
__registerRequestedKey(messageKey);
|
|
741
|
+
const translated = __resolveTranslation(messageKey, values, options, {
|
|
742
|
+
strings,
|
|
743
|
+
values
|
|
744
|
+
});
|
|
745
|
+
return __replacePlaceholders(translated, (index) => values[index]);
|
|
746
|
+
};
|
|
747
|
+
var msg = (template, options = {}) => {
|
|
748
|
+
if (!template) {
|
|
749
|
+
return "";
|
|
750
|
+
}
|
|
751
|
+
if (__isStrTagged(template)) {
|
|
752
|
+
return joinStringsAndValues(template.strings, template.values, options);
|
|
753
|
+
}
|
|
754
|
+
const key = String(template);
|
|
755
|
+
__registerRequestedKey(key);
|
|
756
|
+
const translated = __resolveTranslation(key, [], options, null);
|
|
757
|
+
if (!options?.element && !options?.scope && !options?.host && !options?.contextElement && !options?.lang) {
|
|
758
|
+
__scheduleReconcile();
|
|
759
|
+
}
|
|
760
|
+
return translated;
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
// src/js/pds-core/pds-enhancers.js
|
|
764
|
+
var enhancerDefinitions = [
|
|
765
|
+
{ selector: ".accordion" },
|
|
766
|
+
{ selector: "nav[data-dropdown]" },
|
|
767
|
+
{ selector: "label[data-toggle]" },
|
|
768
|
+
{ selector: "label[data-color]" },
|
|
769
|
+
{ selector: 'input[type="range"]' },
|
|
770
|
+
{ selector: "form[data-required]" },
|
|
771
|
+
{ selector: "fieldset[role=group][data-open]" },
|
|
772
|
+
{ selector: "[data-clip]" },
|
|
773
|
+
{ selector: "button, a[class*='btn-']" }
|
|
774
|
+
];
|
|
775
|
+
function enhanceAccordion(elem) {
|
|
776
|
+
if (elem.dataset.enhancedAccordion)
|
|
777
|
+
return;
|
|
778
|
+
elem.dataset.enhancedAccordion = "true";
|
|
779
|
+
elem.addEventListener(
|
|
780
|
+
"toggle",
|
|
781
|
+
(event) => {
|
|
782
|
+
if (event.target.open && event.target.parentElement === elem) {
|
|
783
|
+
elem.querySelectorAll(":scope > details[open]").forEach((details) => {
|
|
784
|
+
if (details !== event.target) {
|
|
785
|
+
details.open = false;
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
},
|
|
790
|
+
true
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
function enhanceDropdown(elem) {
|
|
794
|
+
if (elem.dataset.enhancedDropdown)
|
|
795
|
+
return;
|
|
796
|
+
elem.dataset.enhancedDropdown = "true";
|
|
797
|
+
const menu = elem.lastElementChild;
|
|
798
|
+
if (!menu)
|
|
799
|
+
return;
|
|
800
|
+
const trigger = elem.querySelector("[data-dropdown-toggle]") || elem.querySelector("button");
|
|
801
|
+
const supportsPopover = typeof HTMLElement !== "undefined" && "showPopover" in HTMLElement.prototype && "hidePopover" in HTMLElement.prototype;
|
|
802
|
+
if (trigger && !trigger.hasAttribute("type")) {
|
|
803
|
+
trigger.setAttribute("type", "button");
|
|
804
|
+
}
|
|
805
|
+
if (!menu.id) {
|
|
806
|
+
menu.id = `dropdown-${Math.random().toString(36).slice(2, 9)}`;
|
|
807
|
+
}
|
|
808
|
+
const isMenu = menu.tagName?.toLowerCase() === "menu";
|
|
809
|
+
const VIEWPORT_PADDING = 8;
|
|
810
|
+
if (isMenu && !menu.hasAttribute("role")) {
|
|
811
|
+
menu.setAttribute("role", "menu");
|
|
812
|
+
}
|
|
813
|
+
if (!menu.hasAttribute("aria-hidden")) {
|
|
814
|
+
menu.setAttribute("aria-hidden", "true");
|
|
815
|
+
}
|
|
816
|
+
if (trigger) {
|
|
817
|
+
trigger.setAttribute("aria-haspopup", "true");
|
|
818
|
+
trigger.setAttribute("aria-controls", menu.id);
|
|
819
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
820
|
+
}
|
|
821
|
+
if (!supportsPopover) {
|
|
822
|
+
const warnKey = "__PDS_DROPDOWN_POPOVER_WARNED__";
|
|
823
|
+
if (!globalThis[warnKey]) {
|
|
824
|
+
globalThis[warnKey] = true;
|
|
825
|
+
console.warn(
|
|
826
|
+
"[PDS] nav[data-dropdown] requires the Popover API. Add a popover polyfill (recommended: @oddbird/popover-polyfill) for browsers without support."
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
menu.setAttribute("popover", "auto");
|
|
832
|
+
const measureMenuSize = () => {
|
|
833
|
+
const previousStyle = menu.getAttribute("style");
|
|
834
|
+
menu.style.visibility = "hidden";
|
|
835
|
+
menu.style.display = "inline-block";
|
|
836
|
+
menu.style.pointerEvents = "none";
|
|
837
|
+
const rect = menu.getBoundingClientRect();
|
|
838
|
+
const width = Math.max(menu.offsetWidth || 0, menu.scrollWidth || 0, rect.width || 0, 1);
|
|
839
|
+
const height = Math.max(
|
|
840
|
+
menu.offsetHeight || 0,
|
|
841
|
+
menu.scrollHeight || 0,
|
|
842
|
+
rect.height || 0,
|
|
843
|
+
1
|
|
844
|
+
);
|
|
845
|
+
if (previousStyle === null) {
|
|
846
|
+
menu.removeAttribute("style");
|
|
847
|
+
} else {
|
|
848
|
+
menu.setAttribute("style", previousStyle);
|
|
849
|
+
}
|
|
850
|
+
return { width, height };
|
|
851
|
+
};
|
|
852
|
+
const isPopoverOpen = () => {
|
|
853
|
+
try {
|
|
854
|
+
return menu.matches(":popover-open");
|
|
855
|
+
} catch {
|
|
856
|
+
return false;
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
const syncClosedState = () => {
|
|
860
|
+
menu.setAttribute("aria-hidden", "true");
|
|
861
|
+
trigger?.setAttribute("aria-expanded", "false");
|
|
862
|
+
};
|
|
863
|
+
const syncOpenState = () => {
|
|
864
|
+
menu.setAttribute("aria-hidden", "false");
|
|
865
|
+
trigger?.setAttribute("aria-expanded", "true");
|
|
866
|
+
};
|
|
867
|
+
const resolveDirection = () => {
|
|
868
|
+
const mode = (elem.getAttribute("data-direction") || elem.getAttribute("data-dropdown-direction") || elem.getAttribute("data-mode") || "auto").toLowerCase();
|
|
869
|
+
if (mode === "up" || mode === "down")
|
|
870
|
+
return mode;
|
|
871
|
+
const anchorRect = (trigger || elem).getBoundingClientRect();
|
|
872
|
+
const { height: menuHeight } = measureMenuSize();
|
|
873
|
+
const spaceBelow = Math.max(0, window.innerHeight - anchorRect.bottom);
|
|
874
|
+
const spaceAbove = Math.max(0, anchorRect.top);
|
|
875
|
+
const fitsDown = spaceBelow >= menuHeight;
|
|
876
|
+
const fitsUp = spaceAbove >= menuHeight;
|
|
877
|
+
if (fitsDown && !fitsUp)
|
|
878
|
+
return "down";
|
|
879
|
+
if (fitsUp && !fitsDown)
|
|
880
|
+
return "up";
|
|
881
|
+
if (fitsDown && fitsUp)
|
|
882
|
+
return "down";
|
|
883
|
+
return spaceAbove > spaceBelow ? "up" : "down";
|
|
884
|
+
};
|
|
885
|
+
const resolveAlign = () => {
|
|
886
|
+
const align = (elem.getAttribute("data-align") || elem.getAttribute("data-dropdown-align") || "auto").toLowerCase();
|
|
887
|
+
if (align === "left" || align === "right" || align === "start" || align === "end") {
|
|
888
|
+
return align === "start" ? "left" : align === "end" ? "right" : align;
|
|
889
|
+
}
|
|
890
|
+
const anchorRect = (trigger || elem).getBoundingClientRect();
|
|
891
|
+
const { width: menuWidth } = measureMenuSize();
|
|
892
|
+
const spaceForLeftAligned = Math.max(0, window.innerWidth - anchorRect.left);
|
|
893
|
+
const spaceForRightAligned = Math.max(0, anchorRect.right);
|
|
894
|
+
const fitsLeft = spaceForLeftAligned >= menuWidth;
|
|
895
|
+
const fitsRight = spaceForRightAligned >= menuWidth;
|
|
896
|
+
if (fitsLeft && !fitsRight)
|
|
897
|
+
return "left";
|
|
898
|
+
if (fitsRight && !fitsLeft)
|
|
899
|
+
return "right";
|
|
900
|
+
if (fitsLeft && fitsRight)
|
|
901
|
+
return "left";
|
|
902
|
+
return spaceForRightAligned > spaceForLeftAligned ? "right" : "left";
|
|
903
|
+
};
|
|
904
|
+
const readLengthToken = (tokenName, fallback = 8) => {
|
|
905
|
+
const raw = getComputedStyle(elem).getPropertyValue(tokenName).trim();
|
|
906
|
+
if (!raw)
|
|
907
|
+
return fallback;
|
|
908
|
+
const probe = document.createElement("span");
|
|
909
|
+
probe.style.position = "fixed";
|
|
910
|
+
probe.style.visibility = "hidden";
|
|
911
|
+
probe.style.pointerEvents = "none";
|
|
912
|
+
probe.style.height = raw;
|
|
913
|
+
document.body.appendChild(probe);
|
|
914
|
+
const parsed = Number.parseFloat(getComputedStyle(probe).height);
|
|
915
|
+
probe.remove();
|
|
916
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
917
|
+
};
|
|
918
|
+
const clearFloatingMenuPosition = () => {
|
|
919
|
+
[
|
|
920
|
+
"position",
|
|
921
|
+
"left",
|
|
922
|
+
"top",
|
|
923
|
+
"right",
|
|
924
|
+
"bottom",
|
|
925
|
+
"margin-top",
|
|
926
|
+
"margin-bottom",
|
|
927
|
+
"max-width",
|
|
928
|
+
"max-inline-size",
|
|
929
|
+
"max-height",
|
|
930
|
+
"overflow"
|
|
931
|
+
].forEach((prop) => menu.style.removeProperty(prop));
|
|
932
|
+
};
|
|
933
|
+
const positionPopoverMenu = () => {
|
|
934
|
+
if (!isPopoverOpen())
|
|
935
|
+
return;
|
|
936
|
+
const anchorRect = (trigger || elem).getBoundingClientRect();
|
|
937
|
+
const viewport = window.visualViewport;
|
|
938
|
+
const viewportWidth = viewport?.width || document.documentElement?.clientWidth || window.innerWidth;
|
|
939
|
+
const viewportHeight = viewport?.height || document.documentElement?.clientHeight || window.innerHeight;
|
|
940
|
+
const viewportOffsetLeft = viewport?.offsetLeft || 0;
|
|
941
|
+
const viewportOffsetTop = viewport?.offsetTop || 0;
|
|
942
|
+
const maxMenuWidth = Math.max(1, viewportWidth - VIEWPORT_PADDING * 2);
|
|
943
|
+
const maxMenuHeight = Math.max(1, viewportHeight - VIEWPORT_PADDING * 2);
|
|
944
|
+
menu.style.maxWidth = `${Math.round(maxMenuWidth)}px`;
|
|
945
|
+
menu.style.maxInlineSize = `${Math.round(maxMenuWidth)}px`;
|
|
946
|
+
menu.style.maxHeight = `${Math.round(maxMenuHeight)}px`;
|
|
947
|
+
menu.style.overflow = "auto";
|
|
948
|
+
const { width: menuWidth, height: menuHeight } = measureMenuSize();
|
|
949
|
+
const spacing = readLengthToken("--spacing-2", 8);
|
|
950
|
+
const direction = resolveDirection();
|
|
951
|
+
const align = resolveAlign();
|
|
952
|
+
elem.dataset.dropdownDirection = direction;
|
|
953
|
+
elem.dataset.dropdownAlign = align;
|
|
954
|
+
let left = align === "right" ? anchorRect.right - menuWidth : anchorRect.left;
|
|
955
|
+
if (menuWidth >= maxMenuWidth - 1) {
|
|
956
|
+
left = viewportOffsetLeft + VIEWPORT_PADDING;
|
|
957
|
+
} else {
|
|
958
|
+
left = Math.max(
|
|
959
|
+
viewportOffsetLeft + VIEWPORT_PADDING,
|
|
960
|
+
Math.min(
|
|
961
|
+
left,
|
|
962
|
+
viewportOffsetLeft + viewportWidth - menuWidth - VIEWPORT_PADDING
|
|
963
|
+
)
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
let top = direction === "up" ? anchorRect.top - spacing - menuHeight : anchorRect.bottom + spacing;
|
|
967
|
+
top = Math.max(
|
|
968
|
+
viewportOffsetTop + VIEWPORT_PADDING,
|
|
969
|
+
Math.min(
|
|
970
|
+
top,
|
|
971
|
+
viewportOffsetTop + viewportHeight - menuHeight - VIEWPORT_PADDING
|
|
972
|
+
)
|
|
973
|
+
);
|
|
974
|
+
Object.assign(menu.style, {
|
|
975
|
+
position: "fixed",
|
|
976
|
+
left: `${Math.round(left)}px`,
|
|
977
|
+
top: `${Math.round(top)}px`,
|
|
978
|
+
right: "auto",
|
|
979
|
+
bottom: "auto",
|
|
980
|
+
marginTop: "0",
|
|
981
|
+
marginBottom: "0"
|
|
982
|
+
});
|
|
983
|
+
};
|
|
984
|
+
let repositionHandler = null;
|
|
985
|
+
const bindReposition = () => {
|
|
986
|
+
if (repositionHandler)
|
|
987
|
+
return;
|
|
988
|
+
repositionHandler = () => positionPopoverMenu();
|
|
989
|
+
window.addEventListener("resize", repositionHandler);
|
|
990
|
+
window.addEventListener("scroll", repositionHandler, true);
|
|
991
|
+
};
|
|
992
|
+
const unbindReposition = () => {
|
|
993
|
+
if (!repositionHandler)
|
|
994
|
+
return;
|
|
995
|
+
window.removeEventListener("resize", repositionHandler);
|
|
996
|
+
window.removeEventListener("scroll", repositionHandler, true);
|
|
997
|
+
repositionHandler = null;
|
|
998
|
+
};
|
|
999
|
+
let configChangedHandler = null;
|
|
1000
|
+
let configRepositionFrame = null;
|
|
1001
|
+
const bindConfigChanged = () => {
|
|
1002
|
+
if (configChangedHandler || typeof document === "undefined")
|
|
1003
|
+
return;
|
|
1004
|
+
configChangedHandler = () => {
|
|
1005
|
+
if (!isPopoverOpen())
|
|
1006
|
+
return;
|
|
1007
|
+
elem.dataset.dropdownDirection = resolveDirection();
|
|
1008
|
+
elem.dataset.dropdownAlign = resolveAlign();
|
|
1009
|
+
if (configRepositionFrame !== null) {
|
|
1010
|
+
cancelAnimationFrame(configRepositionFrame);
|
|
1011
|
+
}
|
|
1012
|
+
configRepositionFrame = requestAnimationFrame(() => {
|
|
1013
|
+
configRepositionFrame = null;
|
|
1014
|
+
if (!isPopoverOpen())
|
|
1015
|
+
return;
|
|
1016
|
+
positionPopoverMenu();
|
|
1017
|
+
});
|
|
1018
|
+
};
|
|
1019
|
+
document.addEventListener("pds:config-changed", configChangedHandler);
|
|
1020
|
+
};
|
|
1021
|
+
const unbindConfigChanged = () => {
|
|
1022
|
+
if (!configChangedHandler || typeof document === "undefined")
|
|
1023
|
+
return;
|
|
1024
|
+
document.removeEventListener("pds:config-changed", configChangedHandler);
|
|
1025
|
+
configChangedHandler = null;
|
|
1026
|
+
if (configRepositionFrame !== null) {
|
|
1027
|
+
cancelAnimationFrame(configRepositionFrame);
|
|
1028
|
+
configRepositionFrame = null;
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
menu.addEventListener("toggle", (event) => {
|
|
1032
|
+
const isOpen = event.newState === "open";
|
|
1033
|
+
if (isOpen) {
|
|
1034
|
+
syncOpenState();
|
|
1035
|
+
positionPopoverMenu();
|
|
1036
|
+
bindReposition();
|
|
1037
|
+
bindConfigChanged();
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
syncClosedState();
|
|
1041
|
+
unbindReposition();
|
|
1042
|
+
unbindConfigChanged();
|
|
1043
|
+
clearFloatingMenuPosition();
|
|
1044
|
+
});
|
|
1045
|
+
const openMenu = () => {
|
|
1046
|
+
if (isPopoverOpen())
|
|
1047
|
+
return;
|
|
1048
|
+
elem.dataset.dropdownDirection = resolveDirection();
|
|
1049
|
+
elem.dataset.dropdownAlign = resolveAlign();
|
|
1050
|
+
menu.showPopover();
|
|
1051
|
+
requestAnimationFrame(() => positionPopoverMenu());
|
|
1052
|
+
};
|
|
1053
|
+
const closeMenu = () => {
|
|
1054
|
+
if (!isPopoverOpen())
|
|
1055
|
+
return;
|
|
1056
|
+
menu.hidePopover();
|
|
1057
|
+
};
|
|
1058
|
+
const toggleMenu = () => {
|
|
1059
|
+
if (isPopoverOpen()) {
|
|
1060
|
+
closeMenu();
|
|
1061
|
+
} else {
|
|
1062
|
+
openMenu();
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
syncClosedState();
|
|
1066
|
+
menu.addEventListener("click", (event) => {
|
|
1067
|
+
const target = event.target instanceof Element ? event.target : event.target?.parentElement;
|
|
1068
|
+
if (!target)
|
|
1069
|
+
return;
|
|
1070
|
+
if (!target.closest("[data-dropdown-close]"))
|
|
1071
|
+
return;
|
|
1072
|
+
closeMenu();
|
|
1073
|
+
});
|
|
1074
|
+
trigger?.addEventListener("click", (event) => {
|
|
1075
|
+
event.preventDefault();
|
|
1076
|
+
event.stopPropagation();
|
|
1077
|
+
toggleMenu();
|
|
1078
|
+
});
|
|
1079
|
+
elem.addEventListener("keydown", (event) => {
|
|
1080
|
+
if (event.key === "Escape") {
|
|
1081
|
+
closeMenu();
|
|
1082
|
+
trigger?.focus();
|
|
1083
|
+
}
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
function enhanceToggle(elem) {
|
|
1087
|
+
if (elem.dataset.enhancedToggle)
|
|
1088
|
+
return;
|
|
1089
|
+
elem.dataset.enhancedToggle = "true";
|
|
1090
|
+
const checkbox = elem.querySelector('input[type="checkbox"]');
|
|
1091
|
+
if (!checkbox)
|
|
1092
|
+
return;
|
|
1093
|
+
if (!elem.hasAttribute("tabindex")) {
|
|
1094
|
+
elem.setAttribute("tabindex", "0");
|
|
1095
|
+
}
|
|
1096
|
+
elem.setAttribute("role", "switch");
|
|
1097
|
+
elem.setAttribute("aria-checked", checkbox.checked ? "true" : "false");
|
|
1098
|
+
const toggleSwitch = document.createElement("span");
|
|
1099
|
+
toggleSwitch.className = "toggle-switch";
|
|
1100
|
+
toggleSwitch.setAttribute("role", "presentation");
|
|
1101
|
+
toggleSwitch.setAttribute("aria-hidden", "true");
|
|
1102
|
+
const knob = document.createElement("span");
|
|
1103
|
+
knob.className = "toggle-knob";
|
|
1104
|
+
toggleSwitch.appendChild(knob);
|
|
1105
|
+
elem.insertBefore(toggleSwitch, checkbox.nextSibling);
|
|
1106
|
+
const updateAria = () => {
|
|
1107
|
+
elem.setAttribute("aria-checked", checkbox.checked ? "true" : "false");
|
|
1108
|
+
};
|
|
1109
|
+
const toggle = () => {
|
|
1110
|
+
if (checkbox.disabled)
|
|
1111
|
+
return;
|
|
1112
|
+
checkbox.checked = !checkbox.checked;
|
|
1113
|
+
updateAria();
|
|
1114
|
+
checkbox.dispatchEvent(new Event("input", { bubbles: true }));
|
|
1115
|
+
checkbox.dispatchEvent(new Event("change", { bubbles: true }));
|
|
1116
|
+
};
|
|
1117
|
+
elem.addEventListener("click", (event) => {
|
|
1118
|
+
event.preventDefault();
|
|
1119
|
+
toggle();
|
|
1120
|
+
});
|
|
1121
|
+
elem.addEventListener("keydown", (event) => {
|
|
1122
|
+
if (event.key === " " || event.key === "Enter") {
|
|
1123
|
+
event.preventDefault();
|
|
1124
|
+
toggle();
|
|
1125
|
+
}
|
|
1126
|
+
});
|
|
1127
|
+
checkbox.addEventListener("change", updateAria);
|
|
1128
|
+
}
|
|
1129
|
+
function enhanceColorInput(elem) {
|
|
1130
|
+
if (elem.dataset.enhancedColorInput)
|
|
1131
|
+
return;
|
|
1132
|
+
const input = elem.querySelector('input[type="color"]');
|
|
1133
|
+
if (!input)
|
|
1134
|
+
return;
|
|
1135
|
+
elem.dataset.enhancedColorInput = "true";
|
|
1136
|
+
let control = elem.querySelector(":scope > .color-control");
|
|
1137
|
+
let swatch = elem.querySelector(":scope > .color-control > .color-swatch");
|
|
1138
|
+
let output = elem.querySelector(":scope > .color-control > output");
|
|
1139
|
+
if (!control) {
|
|
1140
|
+
control = document.createElement("span");
|
|
1141
|
+
control.className = "color-control";
|
|
1142
|
+
input.before(control);
|
|
1143
|
+
}
|
|
1144
|
+
if (!swatch) {
|
|
1145
|
+
swatch = document.createElement("span");
|
|
1146
|
+
swatch.className = "color-swatch";
|
|
1147
|
+
control.appendChild(swatch);
|
|
1148
|
+
}
|
|
1149
|
+
if (input.parentElement !== swatch) {
|
|
1150
|
+
swatch.appendChild(input);
|
|
1151
|
+
}
|
|
1152
|
+
if (!output) {
|
|
1153
|
+
output = document.createElement("output");
|
|
1154
|
+
control.appendChild(output);
|
|
1155
|
+
}
|
|
1156
|
+
const sync = () => {
|
|
1157
|
+
const isUnset = input.dataset.colorUnset === "1";
|
|
1158
|
+
if (isUnset) {
|
|
1159
|
+
output.value = "";
|
|
1160
|
+
output.textContent = msg("not set");
|
|
1161
|
+
control.dataset.value = "";
|
|
1162
|
+
control.dataset.unset = "1";
|
|
1163
|
+
swatch.dataset.unset = "1";
|
|
1164
|
+
return;
|
|
1165
|
+
}
|
|
1166
|
+
output.value = input.value;
|
|
1167
|
+
output.textContent = input.value;
|
|
1168
|
+
control.dataset.value = input.value;
|
|
1169
|
+
delete control.dataset.unset;
|
|
1170
|
+
delete swatch.dataset.unset;
|
|
1171
|
+
};
|
|
1172
|
+
sync();
|
|
1173
|
+
const setResolved = () => {
|
|
1174
|
+
if (input.dataset.colorUnset === "1") {
|
|
1175
|
+
input.dataset.colorUnset = "0";
|
|
1176
|
+
}
|
|
1177
|
+
sync();
|
|
1178
|
+
};
|
|
1179
|
+
input.addEventListener("input", setResolved, { passive: true });
|
|
1180
|
+
input.addEventListener("change", setResolved, { passive: true });
|
|
1181
|
+
}
|
|
1182
|
+
function enhanceRange(elem) {
|
|
1183
|
+
if (elem.dataset.enhancedRange)
|
|
1184
|
+
return;
|
|
1185
|
+
const wireProgrammaticUpdates = (updateFn) => {
|
|
1186
|
+
if (elem.dataset.enhancedRangeProgrammatic)
|
|
1187
|
+
return;
|
|
1188
|
+
elem.dataset.enhancedRangeProgrammatic = "1";
|
|
1189
|
+
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(elem), "value") || Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value");
|
|
1190
|
+
if (descriptor?.get && descriptor?.set) {
|
|
1191
|
+
Object.defineProperty(elem, "value", {
|
|
1192
|
+
configurable: true,
|
|
1193
|
+
enumerable: descriptor.enumerable,
|
|
1194
|
+
get() {
|
|
1195
|
+
return descriptor.get.call(this);
|
|
1196
|
+
},
|
|
1197
|
+
set(nextValue) {
|
|
1198
|
+
descriptor.set.call(this, nextValue);
|
|
1199
|
+
updateFn();
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
const attrObserver = new MutationObserver((mutations) => {
|
|
1204
|
+
const shouldUpdate = mutations.some((mutation) => {
|
|
1205
|
+
const attr = mutation.attributeName;
|
|
1206
|
+
return attr === "value" || attr === "min" || attr === "max";
|
|
1207
|
+
});
|
|
1208
|
+
if (shouldUpdate)
|
|
1209
|
+
updateFn();
|
|
1210
|
+
});
|
|
1211
|
+
attrObserver.observe(elem, {
|
|
1212
|
+
attributes: true,
|
|
1213
|
+
attributeFilter: ["value", "min", "max"]
|
|
1214
|
+
});
|
|
1215
|
+
};
|
|
1216
|
+
const label = elem.closest("label");
|
|
1217
|
+
const hasRangeOutputClass = label?.classList.contains("range-output");
|
|
1218
|
+
const inputId = elem.id || `range-${Math.random().toString(36).substring(2, 11)}`;
|
|
1219
|
+
const outputId = `${inputId}-output`;
|
|
1220
|
+
elem.id = inputId;
|
|
1221
|
+
if (hasRangeOutputClass) {
|
|
1222
|
+
const labelSpan = label.querySelector("span");
|
|
1223
|
+
if (labelSpan && !labelSpan.classList.contains("range-output-wrapper")) {
|
|
1224
|
+
const explicitRangeLabel = labelSpan.getAttribute("data-range-label") || label.getAttribute("data-range-label") || "";
|
|
1225
|
+
const wrapper = document.createElement("span");
|
|
1226
|
+
wrapper.className = "range-output-wrapper";
|
|
1227
|
+
wrapper.style.display = "flex";
|
|
1228
|
+
wrapper.style.justifyContent = "space-between";
|
|
1229
|
+
wrapper.style.alignItems = "center";
|
|
1230
|
+
const textSpan = document.createElement("span");
|
|
1231
|
+
textSpan.textContent = explicitRangeLabel || labelSpan.textContent;
|
|
1232
|
+
wrapper.appendChild(textSpan);
|
|
1233
|
+
const output = document.createElement("output");
|
|
1234
|
+
output.id = outputId;
|
|
1235
|
+
output.setAttribute("for", inputId);
|
|
1236
|
+
output.style.color = "var(--surface-text-secondary, var(--color-text-secondary))";
|
|
1237
|
+
output.style.fontSize = "0.875rem";
|
|
1238
|
+
output.textContent = elem.value;
|
|
1239
|
+
wrapper.appendChild(output);
|
|
1240
|
+
labelSpan.textContent = "";
|
|
1241
|
+
labelSpan.appendChild(wrapper);
|
|
1242
|
+
const updateOutput = () => {
|
|
1243
|
+
output.textContent = elem.value;
|
|
1244
|
+
};
|
|
1245
|
+
elem.addEventListener("input", updateOutput);
|
|
1246
|
+
elem.addEventListener("change", updateOutput);
|
|
1247
|
+
wireProgrammaticUpdates(updateOutput);
|
|
1248
|
+
updateOutput();
|
|
1249
|
+
}
|
|
1250
|
+
} else {
|
|
1251
|
+
let container = elem.closest(".range-container");
|
|
1252
|
+
if (!container) {
|
|
1253
|
+
container = document.createElement("div");
|
|
1254
|
+
container.className = "range-container";
|
|
1255
|
+
elem.parentNode?.insertBefore(container, elem);
|
|
1256
|
+
container.appendChild(elem);
|
|
1257
|
+
}
|
|
1258
|
+
container.style.position = "relative";
|
|
1259
|
+
const bubble = document.createElement("output");
|
|
1260
|
+
bubble.id = outputId;
|
|
1261
|
+
bubble.setAttribute("for", inputId);
|
|
1262
|
+
bubble.className = "range-bubble";
|
|
1263
|
+
bubble.setAttribute("aria-live", "polite");
|
|
1264
|
+
container.appendChild(bubble);
|
|
1265
|
+
const updateBubble = () => {
|
|
1266
|
+
const min = parseFloat(elem.min) || 0;
|
|
1267
|
+
const max = parseFloat(elem.max) || 100;
|
|
1268
|
+
const value = parseFloat(elem.value);
|
|
1269
|
+
const pct = (value - min) / (max - min);
|
|
1270
|
+
bubble.style.left = `calc(${pct * 100}% )`;
|
|
1271
|
+
bubble.textContent = String(value);
|
|
1272
|
+
};
|
|
1273
|
+
const show = () => bubble.classList.add("visible");
|
|
1274
|
+
const hide = () => bubble.classList.remove("visible");
|
|
1275
|
+
elem.addEventListener("input", updateBubble);
|
|
1276
|
+
elem.addEventListener("pointerdown", show);
|
|
1277
|
+
elem.addEventListener("pointerup", hide);
|
|
1278
|
+
elem.addEventListener("pointerleave", hide);
|
|
1279
|
+
elem.addEventListener("focus", show);
|
|
1280
|
+
elem.addEventListener("blur", hide);
|
|
1281
|
+
elem.addEventListener("change", updateBubble);
|
|
1282
|
+
wireProgrammaticUpdates(updateBubble);
|
|
1283
|
+
updateBubble();
|
|
1284
|
+
}
|
|
1285
|
+
elem.dataset.enhancedRange = "1";
|
|
1286
|
+
}
|
|
1287
|
+
function enhanceRequired(elem) {
|
|
1288
|
+
if (elem.dataset.enhancedRequired)
|
|
1289
|
+
return;
|
|
1290
|
+
elem.dataset.enhancedRequired = "true";
|
|
1291
|
+
const enhanceRequiredField = (input) => {
|
|
1292
|
+
let label;
|
|
1293
|
+
if (input.closest("[role$=group]")) {
|
|
1294
|
+
label = input.closest("[role$=group]").querySelector("legend");
|
|
1295
|
+
} else {
|
|
1296
|
+
label = input.closest("label");
|
|
1297
|
+
}
|
|
1298
|
+
if (!label)
|
|
1299
|
+
return;
|
|
1300
|
+
if (label.querySelector(".required-asterisk"))
|
|
1301
|
+
return;
|
|
1302
|
+
const asterisk = document.createElement("span");
|
|
1303
|
+
asterisk.classList.add("required-asterisk");
|
|
1304
|
+
asterisk.textContent = "*";
|
|
1305
|
+
asterisk.style.marginLeft = "4px";
|
|
1306
|
+
const labelText = label.querySelector("span, [data-label]");
|
|
1307
|
+
if (labelText) {
|
|
1308
|
+
labelText.appendChild(asterisk);
|
|
1309
|
+
} else {
|
|
1310
|
+
const field = label.querySelector("input, select, textarea");
|
|
1311
|
+
if (field) {
|
|
1312
|
+
label.insertBefore(asterisk, field);
|
|
1313
|
+
} else {
|
|
1314
|
+
label.appendChild(asterisk);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
const form = input.closest("form");
|
|
1318
|
+
if (form && !form.querySelector(".required-legend")) {
|
|
1319
|
+
const legend = document.createElement("small");
|
|
1320
|
+
legend.classList.add("required-legend");
|
|
1321
|
+
legend.textContent = msg("* Required fields");
|
|
1322
|
+
form.insertBefore(
|
|
1323
|
+
legend,
|
|
1324
|
+
form.querySelector(".form-actions") || form.lastElementChild
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1327
|
+
};
|
|
1328
|
+
elem.querySelectorAll("[required]").forEach((input) => {
|
|
1329
|
+
enhanceRequiredField(input);
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
function enhanceOpenGroup(elem) {
|
|
1333
|
+
if (elem.dataset.enhancedOpenGroup)
|
|
1334
|
+
return;
|
|
1335
|
+
elem.dataset.enhancedOpenGroup = "true";
|
|
1336
|
+
elem.classList.add("flex", "flex-wrap", "buttons");
|
|
1337
|
+
const addInput = document.createElement("input");
|
|
1338
|
+
addInput.type = "text";
|
|
1339
|
+
addInput.placeholder = msg("Add item...");
|
|
1340
|
+
addInput.classList.add("input-text", "input-sm");
|
|
1341
|
+
addInput.style.width = "auto";
|
|
1342
|
+
const getFirstInput = () => elem.querySelector('input[type="radio"], input[type="checkbox"]');
|
|
1343
|
+
elem.appendChild(addInput);
|
|
1344
|
+
addInput.addEventListener("keydown", (event) => {
|
|
1345
|
+
if (event.key === "Enter" || event.key === "Tab") {
|
|
1346
|
+
const value = addInput.value.trim();
|
|
1347
|
+
if (value) {
|
|
1348
|
+
event.preventDefault();
|
|
1349
|
+
const firstInput = getFirstInput();
|
|
1350
|
+
const type = firstInput?.type === "radio" ? "radio" : "checkbox";
|
|
1351
|
+
const id = `open-group-${Math.random().toString(36).substring(2, 11)}`;
|
|
1352
|
+
const label = document.createElement("label");
|
|
1353
|
+
const span = document.createElement("span");
|
|
1354
|
+
span.setAttribute("data-label", "");
|
|
1355
|
+
span.textContent = value;
|
|
1356
|
+
const input = document.createElement("input");
|
|
1357
|
+
input.type = type;
|
|
1358
|
+
input.name = firstInput?.name || elem.getAttribute("data-name") || "open-group";
|
|
1359
|
+
input.value = value;
|
|
1360
|
+
input.id = id;
|
|
1361
|
+
label.appendChild(span);
|
|
1362
|
+
label.appendChild(input);
|
|
1363
|
+
elem.insertBefore(label, addInput);
|
|
1364
|
+
addInput.value = "";
|
|
1365
|
+
}
|
|
1366
|
+
} else if (event.key === "Backspace" && addInput.value === "") {
|
|
1367
|
+
event.preventDefault();
|
|
1368
|
+
const labels = elem.querySelectorAll("label");
|
|
1369
|
+
if (labels.length > 0) {
|
|
1370
|
+
const lastLabel = labels[labels.length - 1];
|
|
1371
|
+
lastLabel.remove();
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
function enhanceClip(elem) {
|
|
1377
|
+
if (elem.dataset.enhancedClip)
|
|
1378
|
+
return;
|
|
1379
|
+
elem.dataset.enhancedClip = "true";
|
|
1380
|
+
if (!elem.hasAttribute("tabindex")) {
|
|
1381
|
+
elem.setAttribute("tabindex", "0");
|
|
1382
|
+
}
|
|
1383
|
+
if (!elem.hasAttribute("role")) {
|
|
1384
|
+
elem.setAttribute("role", "button");
|
|
1385
|
+
}
|
|
1386
|
+
const syncAria = () => {
|
|
1387
|
+
const isOpen = elem.getAttribute("data-clip-open") === "true";
|
|
1388
|
+
elem.setAttribute("aria-expanded", isOpen ? "true" : "false");
|
|
1389
|
+
};
|
|
1390
|
+
const toggleOpen = () => {
|
|
1391
|
+
const isOpen = elem.getAttribute("data-clip-open") === "true";
|
|
1392
|
+
elem.setAttribute("data-clip-open", isOpen ? "false" : "true");
|
|
1393
|
+
syncAria();
|
|
1394
|
+
};
|
|
1395
|
+
elem.addEventListener("click", (event) => {
|
|
1396
|
+
if (event.defaultPrevented)
|
|
1397
|
+
return;
|
|
1398
|
+
toggleOpen();
|
|
1399
|
+
});
|
|
1400
|
+
elem.addEventListener("keydown", (event) => {
|
|
1401
|
+
if (event.key === " " || event.key === "Enter") {
|
|
1402
|
+
event.preventDefault();
|
|
1403
|
+
toggleOpen();
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
syncAria();
|
|
1407
|
+
}
|
|
1408
|
+
function enhanceButtonWorking(elem) {
|
|
1409
|
+
if (elem.dataset.enhancedBtnWorking)
|
|
1410
|
+
return;
|
|
1411
|
+
elem.dataset.enhancedBtnWorking = "true";
|
|
1412
|
+
let originalIcon = null;
|
|
1413
|
+
let addedIcon = false;
|
|
1414
|
+
const observer = new MutationObserver((mutations) => {
|
|
1415
|
+
mutations.forEach((mutation) => {
|
|
1416
|
+
if (mutation.attributeName === "class") {
|
|
1417
|
+
const hasWorking = elem.classList.contains("btn-working");
|
|
1418
|
+
const icon = elem.querySelector("pds-icon");
|
|
1419
|
+
if (hasWorking) {
|
|
1420
|
+
if (icon) {
|
|
1421
|
+
if (!originalIcon) {
|
|
1422
|
+
originalIcon = icon.getAttribute("icon");
|
|
1423
|
+
}
|
|
1424
|
+
icon.setAttribute("icon", "circle-notch");
|
|
1425
|
+
} else {
|
|
1426
|
+
const newIcon = document.createElement("pds-icon");
|
|
1427
|
+
newIcon.setAttribute("icon", "circle-notch");
|
|
1428
|
+
newIcon.setAttribute("size", "sm");
|
|
1429
|
+
elem.insertBefore(newIcon, elem.firstChild);
|
|
1430
|
+
addedIcon = true;
|
|
1431
|
+
}
|
|
1432
|
+
} else if (mutation.oldValue?.includes("btn-working")) {
|
|
1433
|
+
if (icon) {
|
|
1434
|
+
if (addedIcon) {
|
|
1435
|
+
icon.remove();
|
|
1436
|
+
addedIcon = false;
|
|
1437
|
+
} else if (originalIcon) {
|
|
1438
|
+
icon.setAttribute("icon", originalIcon);
|
|
1439
|
+
originalIcon = null;
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
});
|
|
1445
|
+
});
|
|
1446
|
+
observer.observe(elem, {
|
|
1447
|
+
attributes: true,
|
|
1448
|
+
attributeFilter: ["class"],
|
|
1449
|
+
attributeOldValue: true
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
var enhancerRunners = /* @__PURE__ */ new Map([
|
|
1453
|
+
[".accordion", enhanceAccordion],
|
|
1454
|
+
["nav[data-dropdown]", enhanceDropdown],
|
|
1455
|
+
["label[data-toggle]", enhanceToggle],
|
|
1456
|
+
["label[data-color]", enhanceColorInput],
|
|
1457
|
+
['input[type="range"]', enhanceRange],
|
|
1458
|
+
["form[data-required]", enhanceRequired],
|
|
1459
|
+
["fieldset[role=group][data-open]", enhanceOpenGroup],
|
|
1460
|
+
["[data-clip]", enhanceClip],
|
|
1461
|
+
["button, a[class*='btn-']", enhanceButtonWorking]
|
|
1462
|
+
]);
|
|
1463
|
+
var defaultPDSEnhancers = enhancerDefinitions.map((meta) => ({
|
|
1464
|
+
...meta,
|
|
1465
|
+
run: enhancerRunners.get(meta.selector) || (() => {
|
|
1466
|
+
})
|
|
1467
|
+
}));
|
|
1468
|
+
export {
|
|
1469
|
+
defaultPDSEnhancers
|
|
1470
|
+
};
|
|
1471
|
+
//# sourceMappingURL=pds-enhancers.js.map
|