@digdir/designsystemet-web 1.19.1 → 1.20.1
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/cjs/_vendors/@oddbird/popover-polyfill/dist/popover-fn.cjs +2 -2
- package/dist/cjs/_vendors/@oddbird/popover-polyfill/dist/popover-fn.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -1
- package/dist/cjs/clickdelegatefor/clickdelegatefor.cjs +1 -1
- package/dist/cjs/clickdelegatefor/clickdelegatefor.cjs.map +1 -1
- package/dist/cjs/field/field.cjs +1 -1
- package/dist/cjs/field/field.cjs.map +1 -1
- package/dist/cjs/fieldset/fieldset.cjs +1 -1
- package/dist/cjs/fieldset/fieldset.cjs.map +1 -1
- package/dist/cjs/packages/web/package.cjs +1 -1
- package/dist/cjs/popover/popover.cjs +1 -1
- package/dist/cjs/popover/popover.cjs.map +1 -1
- package/dist/cjs/suggestion/suggestion.cjs +1 -1
- package/dist/cjs/suggestion/suggestion.cjs.map +1 -1
- package/dist/custom-elements.json +2 -2
- package/dist/esm/_vendors/@oddbird/popover-polyfill/dist/popover-fn.js +2 -2
- package/dist/esm/_vendors/@oddbird/popover-polyfill/dist/popover-fn.js.map +1 -1
- package/dist/esm/clickdelegatefor/clickdelegatefor.js +1 -1
- package/dist/esm/clickdelegatefor/clickdelegatefor.js.map +1 -1
- package/dist/esm/field/field.js +1 -1
- package/dist/esm/field/field.js.map +1 -1
- package/dist/esm/fieldset/fieldset.js +1 -1
- package/dist/esm/fieldset/fieldset.js.map +1 -1
- package/dist/esm/packages/web/package.js +1 -1
- package/dist/esm/popover/popover.js +1 -1
- package/dist/esm/popover/popover.js.map +1 -1
- package/dist/esm/suggestion/suggestion.js +1 -1
- package/dist/esm/suggestion/suggestion.js.map +1 -1
- package/dist/index.d.ts +102 -108
- package/dist/index.js +95 -52
- package/dist/umd/index.js +8 -7
- package/dist/umd/index.js.map +1 -1
- package/package.json +8 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e=class extends Event{oldState;newState;constructor(e,t={}){let n=Object.assign({},t);delete n.oldState,delete n.newState,super(e,n),this.oldState=String(t.oldState||``),this.newState=String(t.newState||``)}},t=new WeakMap;function n(n,r,i){t.set(n,setTimeout(()=>{t.has(n)&&n.dispatchEvent(new e(`toggle`,{cancelable:!1,oldState:r,newState:i}))},0))}var r=globalThis.ShadowRoot||function(){},i=globalThis.HTMLDialogElement||function(){},a=new WeakMap,o=new WeakMap,s=new WeakMap,c=new WeakMap;function l(e){return c.get(e)||`hidden`}var u=new WeakMap;function d(e){return[...e].pop()}function f(e){let t=e.popoverTargetElement;if(!(t instanceof HTMLElement))return;let n=l(t);(e.popoverTargetAction!==`show`||n!==`showing`)&&(e.popoverTargetAction!==`hide`||n!==`hidden`)&&(n===`showing`?D(t,!0,!0):p(t,!1)&&(u.set(t,e),E(t)))}function p(e,t){return!(e.popover!==`auto`&&e.popover!==`manual`&&e.popover!==`hint`||!e.isConnected||t&&l(e)!==`showing`||!t&&l(e)!==`hidden`||e instanceof i&&e.hasAttribute(`open`)||document.fullscreenElement===e)}function m(e){if(!e)return 0;let t=o.get(document)||new Set,n=s.get(document)||new Set;return n.has(e)?[...n].indexOf(e)+t.size+1:t.has(e)?[...t].indexOf(e)+1:0}function h(e){let t=y(e),n=b(e);return m(t)>m(n)?t:n}function g(e){let t,n=s.get(e)||new Set,r=o.get(e)||new Set,i=n.size>0?n:r.size>0?r:null;return i?(t=d(i),t.isConnected?t:(i.delete(t),g(e))):null}function _(e){for(let t of e||[])if(!t.isConnected)e.delete(t);else return t;return null}function v(e){return typeof e.getRootNode==`function`?e.getRootNode():e.parentNode?v(e.parentNode):e}function y(e){for(;e;){if(e instanceof HTMLElement&&e.popover===`auto`&&c.get(e)===`showing`)return e;if(e=e instanceof Element&&e.assignedSlot||e.parentElement||v(e),e instanceof r&&(e=e.host),e instanceof Document)return}}function b(e){for(;e;){let t=e.popoverTargetElement;if(t instanceof HTMLElement)return t;if(e=e.parentElement||v(e),e instanceof r&&(e=e.host),e instanceof Document)return}}function x(e,t){let n=new Map,r=0;for(let e of t||[])n.set(e,r),r+=1;n.set(e,r),r+=1;let i=null;function a(t){if(!t)return;let r=!1,a=null;for(;!r;){if(a=y(t)||null,a===null||!n.has(a))return;(e.popover===`hint`||a.popover===`auto`)&&(r=!0),r||(t=a.parentElement)}let o=n.get(a)??null;(i===null||n.get(i)<o)&&(i=a)}return a(e.parentElement||v(e)),i}function S(e){return e.hidden||e instanceof r||(e instanceof HTMLButtonElement||e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement||e instanceof HTMLOptGroupElement||e instanceof HTMLOptionElement||e instanceof HTMLFieldSetElement)&&e.disabled||e instanceof HTMLInputElement&&e.type===`hidden`||e instanceof HTMLAnchorElement&&e.href===``?!1:typeof e.tabIndex==`number`&&e.tabIndex!==-1}function C(e){if(e.shadowRoot&&e.shadowRoot.delegatesFocus!==!0)return null;let t=e;t.shadowRoot&&(t=t.shadowRoot);let n=t.querySelector(`[autofocus]`);if(n)return n;{let e=t.querySelectorAll(`slot`);for(let t of e){let e=t.assignedElements({flatten:!0});for(let t of e)if(t.hasAttribute(`autofocus`))return t;else if(n=t.querySelector(`[autofocus]`),n)return n}}let r=e.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),i=r.currentNode;for(;i;){if(S(i))return i;i=r.nextNode()}}function w(e){var t;(t=C(e))==null||t.focus()}var T=new WeakMap;function E(t){if(!p(t,!1))return;let r=t.ownerDocument;if(!t.dispatchEvent(new e(`beforetoggle`,{cancelable:!0,oldState:`closed`,newState:`open`}))||!p(t,!1))return;let i=!1,l=t.popover,d=null,f=x(t,o.get(r)||new Set),m=x(t,s.get(r)||new Set);if(l===`auto`&&(k(s.get(r)||new Set,i,!0),j(f||r,i,!0),d=`auto`),l===`hint`&&(m?(j(m,i,!0),d=`hint`):(k(s.get(r)||new Set,i,!0),f?(j(f,i,!0),d=`auto`):d=`hint`)),l===`auto`||l===`hint`){if(l!==t.popover||!p(t,!1))return;g(r)||(i=!0),d===`auto`?(o.has(r)||o.set(r,new Set),o.get(r).add(t)):d===`hint`&&(s.has(r)||s.set(r,new Set),s.get(r).add(t))}T.delete(t);let h=r.activeElement;t.classList.add(`:popover-open`),c.set(t,`showing`),a.has(r)||a.set(r,new Set),a.get(r).add(t),F(u.get(t),!0),w(t),i&&h&&t.popover===`auto`&&T.set(t,h),n(t,`closed`,`open`)}function D(t,r=!1,i=!1){var l,f;if(!p(t,!0))return;let m=t.ownerDocument;if([`auto`,`hint`].includes(t.popover)&&(j(t,r,i),!p(t,!0)))return;let h=o.get(m)||new Set,g=h.has(t)&&d(h)===t;if(F(u.get(t),!1),u.delete(t),i&&(t.dispatchEvent(new e(`beforetoggle`,{oldState:`open`,newState:`closed`})),g&&d(h)!==t&&j(t,r,i),!p(t,!0)))return;(l=a.get(m))==null||l.delete(t),h.delete(t),(f=s.get(m))==null||f.delete(t),t.classList.remove(`:popover-open`),c.set(t,`hidden`),i&&n(t,`open`,`closed`);let _=T.get(t);_&&(T.delete(t),r&&_.focus())}function O(e,t=!1,n=!1){let r=g(e);for(;r;)D(r,t,n),r=g(e)}function k(e,t=!1,n=!1){let r=_(e);for(;r;)D(r,t,n),r=_(e)}function A(e,t,n,r){let i=!1,a=!1;for(;i||!a;){a=!0;let o=null,s=!1;for(let n of t)if(n===e)s=!0;else if(s){o=n;break}if(!o)return;for(;l(o)===`showing`&&t.size;)D(d(t),n,r);t.has(e)&&d(t)!==e&&(i=!0),i&&(r=!1)}}function j(e,t,n){let r=e.ownerDocument||e;if(e instanceof Document)return O(r,t,n);if(s.get(r)?.has(e)){A(e,s.get(r),t,n);return}k(s.get(r)||new Set,t,n),o.get(r)?.has(e)&&A(e,o.get(r),t,n)}var M=new WeakMap;function N(e){if(!e.isTrusted)return;let t=e.composedPath()[0];if(!t)return;let n=t.ownerDocument;if(!g(n))return;let r=h(t);if(r&&e.type===`pointerdown`)M.set(n,r);else if(e.type===`pointerup`){let e=M.get(n)===r;M.delete(n),e&&j(r||n,!1,!0)}}var P=new WeakMap;function F(e,t=!1){if(!e)return;P.has(e)||P.set(e,e.getAttribute(`aria-expanded`));let n=e.popoverTargetElement;if(n instanceof HTMLElement&&n.popover===`auto`)e.setAttribute(`aria-expanded`,String(t));else{let t=P.get(e);t?e.setAttribute(`aria-expanded`,t):e.removeAttribute(`aria-expanded`)}}var I=globalThis.ShadowRoot||function(){},L=`popover-polyfill`;function R(){return typeof HTMLElement<`u`&&typeof HTMLElement.prototype==`object`&&`popover`in HTMLElement.prototype}function z(){return!!(document.body?.showPopover&&!/native code/i.test(document.body.showPopover.toString()))}function B(e,t,n){let r=e[t];Object.defineProperty(e,t,{value(e){return r.call(this,n(e))}})}var V=/(^|[^\\]):popover-open\b/g;function H(){return typeof globalThis.CSSLayerBlockRule==`function`}function U(e){let t=H(),n=(e??window.POPOVER_POLYFILL_OPTIONS?.layerName??L).split(`.`).map(CSS.escape).join(`.`);return`
|
|
1
|
+
var e=class extends Event{oldState;newState;constructor(e,t={}){let n=Object.assign({},t);delete n.oldState,delete n.newState,super(e,n),this.oldState=String(t.oldState||``),this.newState=String(t.newState||``)}},t=new WeakMap;function n(n,r,i){t.set(n,setTimeout(()=>{t.has(n)&&n.dispatchEvent(new e(`toggle`,{cancelable:!1,oldState:r,newState:i}))},0))}var r=globalThis.ShadowRoot||function(){},i=globalThis.HTMLDialogElement||function(){},a=new WeakMap,o=new WeakMap,s=new WeakMap,c=new WeakMap;function l(e){return c.get(e)||`hidden`}var u=new WeakMap;function d(e){return[...e].pop()}function f(e){let t=e.popoverTargetElement;if(!(t instanceof HTMLElement))return;let n=l(t);(e.popoverTargetAction!==`show`||n!==`showing`)&&(e.popoverTargetAction!==`hide`||n!==`hidden`)&&(n===`showing`?D(t,!0,!0):p(t,!1)&&(u.set(t,e),E(t)))}function p(e,t){return!(e.popover!==`auto`&&e.popover!==`manual`&&e.popover!==`hint`||!e.isConnected||t&&l(e)!==`showing`||!t&&l(e)!==`hidden`||e instanceof i&&e.hasAttribute(`open`)||document.fullscreenElement===e)}function m(e){if(!e)return 0;let t=o.get(document)||new Set,n=s.get(document)||new Set;return n.has(e)?[...n].indexOf(e)+t.size+1:t.has(e)?[...t].indexOf(e)+1:0}function h(e){let t=y(e),n=b(e);return m(t)>m(n)?t:n}function g(e){let t,n=s.get(e)||new Set,r=o.get(e)||new Set,i=n.size>0?n:r.size>0?r:null;return i?(t=d(i),t.isConnected?t:(i.delete(t),g(e))):null}function _(e){for(let t of e||[])if(!t.isConnected)e.delete(t);else return t;return null}function v(e){return typeof e.getRootNode==`function`?e.getRootNode():e.parentNode?v(e.parentNode):e}function y(e){for(;e;){if(e instanceof HTMLElement&&e.popover===`auto`&&c.get(e)===`showing`)return e;if(e=e instanceof Element&&e.assignedSlot||e.parentElement||v(e),e instanceof r&&(e=e.host),e instanceof Document)return}}function b(e){for(;e;){let t=e.popoverTargetElement;if(t instanceof HTMLElement)return t;if(e=e.parentElement||v(e),e instanceof r&&(e=e.host),e instanceof Document)return}}function x(e,t){let n=new Map,r=0;for(let e of t||[])n.set(e,r),r+=1;n.set(e,r),r+=1;let i=null;function a(t){if(!t)return;let r=!1,a=null;for(;!r;){if(a=y(t)||null,a===null||!n.has(a))return;(e.popover===`hint`||a.popover===`auto`)&&(r=!0),r||(t=a.parentElement)}let o=n.get(a)??null;(i===null||n.get(i)<o)&&(i=a)}return a(e.parentElement||v(e)),i}function S(e){return e.hidden||e instanceof r||(e instanceof HTMLButtonElement||e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement||e instanceof HTMLOptGroupElement||e instanceof HTMLOptionElement||e instanceof HTMLFieldSetElement)&&e.disabled||e instanceof HTMLInputElement&&e.type===`hidden`||e instanceof HTMLAnchorElement&&e.href===``?!1:typeof e.tabIndex==`number`&&e.tabIndex!==-1}function C(e){if(e.shadowRoot&&e.shadowRoot.delegatesFocus!==!0)return null;let t=e;t.shadowRoot&&(t=t.shadowRoot);let n=t.querySelector(`[autofocus]`);if(n)return n;{let e=t.querySelectorAll(`slot`);for(let t of e){let e=t.assignedElements({flatten:!0});for(let t of e)if(t.hasAttribute(`autofocus`))return t;else if(n=t.querySelector(`[autofocus]`),n)return n}}let r=e.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),i=r.currentNode;for(;i;){if(S(i))return i;i=r.nextNode()}}function w(e){var t;(t=C(e))==null||t.focus()}var T=new WeakMap;function E(t){if(!p(t,!1))return;let r=t.ownerDocument;if(!t.dispatchEvent(new e(`beforetoggle`,{cancelable:!0,oldState:`closed`,newState:`open`}))||!p(t,!1))return;let i=!1,l=t.popover,d=null,f=x(t,o.get(r)||new Set),m=x(t,s.get(r)||new Set);if(l===`auto`&&(k(s.get(r)||new Set,i,!0),j(f||r,i,!0),d=`auto`),l===`hint`&&(m?(j(m,i,!0),d=`hint`):(k(s.get(r)||new Set,i,!0),f?(j(f,i,!0),d=`auto`):d=`hint`)),l===`auto`||l===`hint`){if(l!==t.popover||!p(t,!1))return;g(r)||(i=!0),d===`auto`?(o.has(r)||o.set(r,new Set),o.get(r).add(t)):d===`hint`&&(s.has(r)||s.set(r,new Set),s.get(r).add(t))}T.delete(t);let h=r.activeElement;t.classList.add(`:popover-open`),c.set(t,`showing`),a.has(r)||a.set(r,new Set),a.get(r).add(t),F(u.get(t),!0),w(t),i&&h&&t.popover===`auto`&&T.set(t,h),n(t,`closed`,`open`)}function D(t,r=!1,i=!1){var l,f;if(!p(t,!0))return;let m=t.ownerDocument;if([`auto`,`hint`].includes(t.popover)&&(j(t,r,i),!p(t,!0)))return;let h=o.get(m)||new Set,g=h.has(t)&&d(h)===t;if(F(u.get(t),!1),u.delete(t),i&&(t.dispatchEvent(new e(`beforetoggle`,{oldState:`open`,newState:`closed`})),g&&d(h)!==t&&j(t,r,i),!p(t,!0)))return;(l=a.get(m))==null||l.delete(t),h.delete(t),(f=s.get(m))==null||f.delete(t),t.classList.remove(`:popover-open`),c.set(t,`hidden`),i&&n(t,`open`,`closed`);let _=T.get(t);_&&(T.delete(t),r&&_.focus())}function O(e,t=!1,n=!1){let r=g(e);for(;r;)D(r,t,n),r=g(e)}function k(e,t=!1,n=!1){let r=_(e);for(;r;)D(r,t,n),r=_(e)}function A(e,t,n,r){let i=!1,a=!1;for(;i||!a;){a=!0;let o=null,s=!1;for(let n of t)if(n===e)s=!0;else if(s){o=n;break}if(!o)return;for(;l(o)===`showing`&&t.size;)D(d(t),n,r);t.has(e)&&d(t)!==e&&(i=!0),i&&(r=!1)}}function j(e,t,n){let r=e.ownerDocument||e;if(e instanceof Document)return O(r,t,n);if(s.get(r)?.has(e)){A(e,s.get(r),t,n);return}k(s.get(r)||new Set,t,n),o.get(r)?.has(e)&&A(e,o.get(r),t,n)}var M=new WeakMap;function N(e){if(!e.isTrusted)return;let t=e.composedPath()[0];if(!t)return;let n=t.ownerDocument;if(!g(n))return;let r=h(t);if(r&&e.type===`pointerdown`)M.set(n,r);else if(e.type===`pointerup`){let e=M.get(n)===r;M.delete(n),e&&j(r||n,!1,!0)}}var P=new WeakMap;function F(e,t=!1){if(!e)return;P.has(e)||P.set(e,e.getAttribute(`aria-expanded`));let n=e.popoverTargetElement;if(n instanceof HTMLElement&&n.popover===`auto`)e.setAttribute(`aria-expanded`,String(t));else{let t=P.get(e);t?e.setAttribute(`aria-expanded`,t):e.removeAttribute(`aria-expanded`)}}var I=globalThis.ShadowRoot||function(){},L=`popover-polyfill`;function R(){return typeof HTMLElement<`u`&&typeof HTMLElement.prototype==`object`&&`popover`in HTMLElement.prototype&&`showPopover`in HTMLElement.prototype}function z(){return!!(document.body?.showPopover&&!/native code/i.test(document.body.showPopover.toString()))}function B(e,t,n){let r=e[t];Object.defineProperty(e,t,{value(e){return r.call(this,n(e))}})}var V=/(^|[^\\]):popover-open\b/g;function H(){return typeof globalThis.CSSLayerBlockRule==`function`}function U(e){let t=H(),n=(e??window.POPOVER_POLYFILL_OPTIONS?.layerName??L).split(`.`).map(e=>CSS.escape(e)).join(`.`);return`
|
|
2
2
|
${t?`@layer ${n} {`:``}
|
|
3
3
|
:where([popover]) {
|
|
4
4
|
position: fixed;
|
|
@@ -60,5 +60,5 @@ ${t?`@layer ${n} {`:``}
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
${t?`}`:``}
|
|
63
|
-
`}var W=null;function G(e,t){let n=U(t);if(W===null)try{W=new CSSStyleSheet,W.replaceSync(n)}catch{W=!1}if(W===!1){let t=document.createElement(`style`);t.textContent=n,e instanceof Document?e.head.prepend(t):e.prepend(t)}else e.adoptedStyleSheets=[W,...e.adoptedStyleSheets]}function K(t){if(typeof window>`u`)return;let n=t?.layerName;window.ToggleEvent=window.ToggleEvent||e;function r(e){return e?.includes(`:popover-open`)&&(e=e.replace(V,`$1.\\:popover-open`)),e}B(Document.prototype,`querySelector`,r),B(Document.prototype,`querySelectorAll`,r),B(Element.prototype,`querySelector`,r),B(Element.prototype,`querySelectorAll`,r),B(Element.prototype,`matches`,r),B(Element.prototype,`closest`,r),B(DocumentFragment.prototype,`querySelectorAll`,r),Object.defineProperties(HTMLElement.prototype,{popover:{enumerable:!0,configurable:!0,get(){if(!this.hasAttribute(`popover`))return null;let e=(this.getAttribute(`popover`)||``).toLowerCase();return e===``||e==`auto`?`auto`:e==`hint`?`hint`:`manual`},set(e){e===null?this.removeAttribute(`popover`):this.setAttribute(`popover`,e)}},showPopover:{enumerable:!0,configurable:!0,value(e={}){E(this)}},hidePopover:{enumerable:!0,configurable:!0,value(){D(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,value(e={}){return typeof e==`boolean`&&(e={force:e}),c.get(this)===`showing`&&e.force===void 0||e.force===!1?D(this,!0,!0):(e.force===void 0||e.force===!0)&&E(this),c.get(this)===`showing`}}});let i=Element.prototype.attachShadow;i&&Object.defineProperties(Element.prototype,{attachShadow:{enumerable:!0,configurable:!0,writable:!0,value(e){let t=i.call(this,e);return G(t,n),t}}});let a=HTMLElement.prototype.attachInternals;a&&Object.defineProperties(HTMLElement.prototype,{attachInternals:{enumerable:!0,configurable:!0,writable:!0,value(){let e=a.call(this);return e.shadowRoot&&G(e.shadowRoot,n),e}}});let o=new WeakMap;function s(e){Object.defineProperties(e.prototype,{popoverTargetElement:{enumerable:!0,configurable:!0,set(e){if(e===null)this.removeAttribute(`popovertarget`),o.delete(this);else if(e instanceof Element)this.setAttribute(`popovertarget`,``),o.set(this,e);else throw TypeError(`popoverTargetElement must be an element or null`)},get(){if(this.localName!==`button`&&this.localName!==`input`||this.localName===`input`&&this.type!==`reset`&&this.type!==`image`&&this.type!==`button`||this.disabled||this.form&&this.type===`submit`)return null;let e=o.get(this);if(e&&e.isConnected)return e;if(e&&!e.isConnected)return o.delete(this),null;let t=v(this),n=this.getAttribute(`popovertarget`);return(t instanceof Document||t instanceof I)&&n&&t.getElementById(n)||null}},popoverTargetAction:{enumerable:!0,configurable:!0,get(){let e=(this.getAttribute(`popovertargetaction`)||``).toLowerCase();return e===`show`||e===`hide`?e:`toggle`},set(e){this.setAttribute(`popovertargetaction`,e)}}})}s(HTMLButtonElement),s(HTMLInputElement);let l=e=>{if(e.defaultPrevented)return;let t=e.composedPath(),n=t[0];if(!(n instanceof Element)||n?.shadowRoot)return;let r=v(n);if(!(r instanceof I||r instanceof Document))return;let i=t.find(e=>e.matches?.call(e,`[popovertargetaction],[popovertarget]`));if(i){f(i),e.preventDefault();return}},u=e=>{let t=e.key,n=e.target;!e.defaultPrevented&&n&&(t===`Escape`||t===`Esc`)&&j(n.ownerDocument,!0,!0)};(e=>{e.addEventListener(`click`,l),e.addEventListener(`keydown`,u),e.addEventListener(`pointerdown`,N),e.addEventListener(`pointerup`,N)})(document),G(document,n)}export{K as apply,G as injectStyles,z as isPolyfilled,R as isSupported};
|
|
63
|
+
`}var W=null;function G(e,t){let n=U(t);if(W===null)try{W=new CSSStyleSheet,W.replaceSync(n)}catch{W=!1}if(W===!1||!e.adoptedStyleSheets){let t=document.createElement(`style`);t.textContent=n,e instanceof Document?e.head.prepend(t):e.prepend(t)}else e.adoptedStyleSheets=[W,...e.adoptedStyleSheets]}function K(t){if(typeof window>`u`)return;let n=t?.layerName;window.ToggleEvent=window.ToggleEvent||e;function r(e){return e?.includes(`:popover-open`)&&(e=e.replace(V,`$1.\\:popover-open`)),e}B(Document.prototype,`querySelector`,r),B(Document.prototype,`querySelectorAll`,r),B(Element.prototype,`querySelector`,r),B(Element.prototype,`querySelectorAll`,r),B(Element.prototype,`matches`,r),B(Element.prototype,`closest`,r),B(DocumentFragment.prototype,`querySelectorAll`,r),Object.defineProperties(HTMLElement.prototype,{popover:{enumerable:!0,configurable:!0,get(){if(!this.hasAttribute(`popover`))return null;let e=(this.getAttribute(`popover`)||``).toLowerCase();return e===``||e==`auto`?`auto`:e==`hint`?`hint`:`manual`},set(e){e===null?this.removeAttribute(`popover`):this.setAttribute(`popover`,e)}},showPopover:{enumerable:!0,configurable:!0,writable:!0,value(e={}){E(this)}},hidePopover:{enumerable:!0,configurable:!0,writable:!0,value(){D(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,writable:!0,value(e={}){return typeof e==`boolean`&&(e={force:e}),c.get(this)===`showing`&&e.force===void 0||e.force===!1?D(this,!0,!0):(e.force===void 0||e.force===!0)&&E(this),c.get(this)===`showing`}}});let i=Element.prototype.attachShadow;i&&Object.defineProperties(Element.prototype,{attachShadow:{enumerable:!0,configurable:!0,writable:!0,value(e){let t=i.call(this,e);return G(t,n),t}}});let a=HTMLElement.prototype.attachInternals;a&&Object.defineProperties(HTMLElement.prototype,{attachInternals:{enumerable:!0,configurable:!0,writable:!0,value(){let e=a.call(this);return e.shadowRoot&&G(e.shadowRoot,n),e}}});let o=new WeakMap;function s(e){Object.defineProperties(e.prototype,{popoverTargetElement:{enumerable:!0,configurable:!0,set(e){if(e===null)this.removeAttribute(`popovertarget`),o.delete(this);else if(e instanceof Element)this.setAttribute(`popovertarget`,``),o.set(this,e);else throw TypeError(`popoverTargetElement must be an element or null`)},get(){if(this.localName!==`button`&&this.localName!==`input`||this.localName===`input`&&this.type!==`reset`&&this.type!==`image`&&this.type!==`button`||this.disabled||this.form&&this.type===`submit`)return null;let e=o.get(this);if(e&&e.isConnected)return e;if(e&&!e.isConnected)return o.delete(this),null;let t=v(this),n=this.getAttribute(`popovertarget`);return(t instanceof Document||t instanceof I)&&n&&t.getElementById(n)||null}},popoverTargetAction:{enumerable:!0,configurable:!0,get(){let e=(this.getAttribute(`popovertargetaction`)||``).toLowerCase();return e===`show`||e===`hide`?e:`toggle`},set(e){this.setAttribute(`popovertargetaction`,e)}}})}s(HTMLButtonElement),s(HTMLInputElement);let l=e=>{if(e.defaultPrevented)return;let t=e.composedPath(),n=t[0];if(!(n instanceof Element)||n?.shadowRoot)return;let r=v(n);if(!(r instanceof I||r instanceof Document))return;let i=t.find(e=>e.matches?.call(e,`[popovertargetaction],[popovertarget]`));if(i){f(i),e.preventDefault();return}},u=e=>{let t=e.key,n=e.target;!e.defaultPrevented&&n&&(t===`Escape`||t===`Esc`)&&j(n.ownerDocument||n,!0,!0)};(e=>{e.addEventListener(`click`,l),e.addEventListener(`keydown`,u),e.addEventListener(`pointerdown`,N),e.addEventListener(`pointerup`,N)})(document),G(document,n)}export{K as apply,G as injectStyles,z as isPolyfilled,R as isSupported};
|
|
64
64
|
//# sourceMappingURL=popover-fn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover-fn.js","names":[],"sources":["../../../../../../../../node_modules/.pnpm/@oddbird+popover-polyfill@0.7.1/node_modules/@oddbird/popover-polyfill/dist/popover-fn.js"],"sourcesContent":["// src/events.ts\nvar ToggleEvent = class extends Event {\n oldState;\n newState;\n constructor(type, init = {}) {\n const eventInit = Object.assign({}, init);\n delete eventInit.oldState;\n delete eventInit.newState;\n super(type, eventInit);\n this.oldState = String(init.oldState || \"\");\n this.newState = String(init.newState || \"\");\n }\n};\nvar popoverToggleTaskQueue = /* @__PURE__ */ new WeakMap();\nfunction queuePopoverToggleEventTask(element, oldState, newState) {\n popoverToggleTaskQueue.set(\n element,\n setTimeout(() => {\n if (!popoverToggleTaskQueue.has(element)) return;\n element.dispatchEvent(\n new ToggleEvent(\"toggle\", {\n cancelable: false,\n oldState,\n newState\n })\n );\n }, 0)\n );\n}\n\n// src/popover-helpers.ts\nvar ShadowRoot = globalThis.ShadowRoot || function() {\n};\nvar HTMLDialogElement = globalThis.HTMLDialogElement || function() {\n};\nvar topLayerElements = /* @__PURE__ */ new WeakMap();\nvar autoPopoverList = /* @__PURE__ */ new WeakMap();\nvar hintPopoverList = /* @__PURE__ */ new WeakMap();\nvar visibilityState = /* @__PURE__ */ new WeakMap();\nfunction getPopoverVisibilityState(popover) {\n return visibilityState.get(popover) || \"hidden\";\n}\nvar popoverInvoker = /* @__PURE__ */ new WeakMap();\nfunction lastSetElement(set) {\n return [...set].pop();\n}\nfunction popoverTargetAttributeActivationBehavior(element) {\n const popover = element.popoverTargetElement;\n if (!(popover instanceof HTMLElement)) {\n return;\n }\n const visibility = getPopoverVisibilityState(popover);\n if (element.popoverTargetAction === \"show\" && visibility === \"showing\") {\n return;\n }\n if (element.popoverTargetAction === \"hide\" && visibility === \"hidden\") return;\n if (visibility === \"showing\") {\n hidePopover(popover, true, true);\n } else if (checkPopoverValidity(popover, false)) {\n popoverInvoker.set(popover, element);\n showPopover(popover);\n }\n}\nfunction checkPopoverValidity(element, expectedToBeShowing) {\n if (element.popover !== \"auto\" && element.popover !== \"manual\" && element.popover !== \"hint\") {\n return false;\n }\n if (!element.isConnected) return false;\n if (expectedToBeShowing && getPopoverVisibilityState(element) !== \"showing\") {\n return false;\n }\n if (!expectedToBeShowing && getPopoverVisibilityState(element) !== \"hidden\") {\n return false;\n }\n if (element instanceof HTMLDialogElement && element.hasAttribute(\"open\")) {\n return false;\n }\n if (document.fullscreenElement === element) return false;\n return true;\n}\nfunction getStackPosition(popover) {\n if (!popover) return 0;\n const autoPopovers = autoPopoverList.get(document) || /* @__PURE__ */ new Set();\n const hintPopovers = hintPopoverList.get(document) || /* @__PURE__ */ new Set();\n if (hintPopovers.has(popover)) {\n return [...hintPopovers].indexOf(popover) + autoPopovers.size + 1;\n }\n if (autoPopovers.has(popover)) {\n return [...autoPopovers].indexOf(popover) + 1;\n }\n return 0;\n}\nfunction topMostClickedPopover(target) {\n const clickedPopover = nearestInclusiveOpenPopover(target);\n const invokerPopover = nearestInclusiveTargetPopoverForInvoker(target);\n if (getStackPosition(clickedPopover) > getStackPosition(invokerPopover)) {\n return clickedPopover;\n }\n return invokerPopover;\n}\nfunction topmostAutoOrHintPopover(document2) {\n let topmostPopover;\n const hintPopovers = hintPopoverList.get(document2) || /* @__PURE__ */ new Set();\n const autoPopovers = autoPopoverList.get(document2) || /* @__PURE__ */ new Set();\n const usedStack = hintPopovers.size > 0 ? hintPopovers : autoPopovers.size > 0 ? autoPopovers : null;\n if (usedStack) {\n topmostPopover = lastSetElement(usedStack);\n if (!topmostPopover.isConnected) {\n usedStack.delete(topmostPopover);\n return topmostAutoOrHintPopover(document2);\n }\n return topmostPopover;\n }\n return null;\n}\nfunction topMostPopoverInList(list) {\n for (const popover of list || []) {\n if (!popover.isConnected) {\n list.delete(popover);\n } else {\n return popover;\n }\n }\n return null;\n}\nfunction getRootNode(node) {\n if (typeof node.getRootNode === \"function\") {\n return node.getRootNode();\n }\n if (node.parentNode) return getRootNode(node.parentNode);\n return node;\n}\nfunction nearestInclusiveOpenPopover(node) {\n while (node) {\n if (node instanceof HTMLElement && node.popover === \"auto\" && visibilityState.get(node) === \"showing\") {\n return node;\n }\n node = node instanceof Element && node.assignedSlot || node.parentElement || getRootNode(node);\n if (node instanceof ShadowRoot) node = node.host;\n if (node instanceof Document) return;\n }\n}\nfunction nearestInclusiveTargetPopoverForInvoker(node) {\n while (node) {\n const nodePopover = node.popoverTargetElement;\n if (nodePopover instanceof HTMLElement) return nodePopover;\n node = node.parentElement || getRootNode(node);\n if (node instanceof ShadowRoot) node = node.host;\n if (node instanceof Document) return;\n }\n}\nfunction topMostPopoverAncestor(newPopover, list) {\n const popoverPositions = /* @__PURE__ */ new Map();\n let i = 0;\n for (const popover of list || []) {\n popoverPositions.set(popover, i);\n i += 1;\n }\n popoverPositions.set(newPopover, i);\n i += 1;\n let topMostPopoverAncestor2 = null;\n function checkAncestor(candidate) {\n if (!candidate) return;\n let okNesting = false;\n let candidateAncestor = null;\n while (!okNesting) {\n candidateAncestor = nearestInclusiveOpenPopover(candidate) || null;\n if (candidateAncestor === null) return;\n if (!popoverPositions.has(candidateAncestor)) return;\n if (newPopover.popover === \"hint\" || candidateAncestor.popover === \"auto\") {\n okNesting = true;\n }\n if (!okNesting) {\n candidate = candidateAncestor.parentElement;\n }\n }\n const candidatePosition = popoverPositions.get(candidateAncestor) ?? null;\n if (topMostPopoverAncestor2 === null || popoverPositions.get(topMostPopoverAncestor2) < candidatePosition) {\n topMostPopoverAncestor2 = candidateAncestor;\n }\n }\n checkAncestor(newPopover.parentElement || getRootNode(newPopover));\n return topMostPopoverAncestor2;\n}\nfunction isFocusable(focusTarget) {\n if (focusTarget.hidden || focusTarget instanceof ShadowRoot) return false;\n if (focusTarget instanceof HTMLButtonElement || focusTarget instanceof HTMLInputElement || focusTarget instanceof HTMLSelectElement || focusTarget instanceof HTMLTextAreaElement || focusTarget instanceof HTMLOptGroupElement || focusTarget instanceof HTMLOptionElement || focusTarget instanceof HTMLFieldSetElement) {\n if (focusTarget.disabled) return false;\n }\n if (focusTarget instanceof HTMLInputElement && focusTarget.type === \"hidden\") {\n return false;\n }\n if (focusTarget instanceof HTMLAnchorElement && focusTarget.href === \"\") {\n return false;\n }\n return typeof focusTarget.tabIndex === \"number\" && focusTarget.tabIndex !== -1;\n}\nfunction focusDelegate(focusTarget) {\n if (focusTarget.shadowRoot && focusTarget.shadowRoot.delegatesFocus !== true) {\n return null;\n }\n let whereToLook = focusTarget;\n if (whereToLook.shadowRoot) {\n whereToLook = whereToLook.shadowRoot;\n }\n let autoFocusDelegate = whereToLook.querySelector(\"[autofocus]\");\n if (autoFocusDelegate) {\n return autoFocusDelegate;\n } else {\n const slots = whereToLook.querySelectorAll(\"slot\");\n for (const slot of slots) {\n const assignedElements = slot.assignedElements({ flatten: true });\n for (const el of assignedElements) {\n if (el.hasAttribute(\"autofocus\")) {\n return el;\n } else {\n autoFocusDelegate = el.querySelector(\"[autofocus]\");\n if (autoFocusDelegate) {\n return autoFocusDelegate;\n }\n }\n }\n }\n }\n const walker = focusTarget.ownerDocument.createTreeWalker(\n whereToLook,\n NodeFilter.SHOW_ELEMENT\n );\n let descendant = walker.currentNode;\n while (descendant) {\n if (isFocusable(descendant)) {\n return descendant;\n }\n descendant = walker.nextNode();\n }\n}\nfunction popoverFocusingSteps(subject) {\n var _a;\n (_a = focusDelegate(subject)) == null ? void 0 : _a.focus();\n}\nvar previouslyFocusedElements = /* @__PURE__ */ new WeakMap();\nfunction showPopover(element) {\n if (!checkPopoverValidity(element, false)) {\n return;\n }\n const document2 = element.ownerDocument;\n if (!element.dispatchEvent(\n new ToggleEvent(\"beforetoggle\", {\n cancelable: true,\n oldState: \"closed\",\n newState: \"open\"\n })\n )) {\n return;\n }\n if (!checkPopoverValidity(element, false)) {\n return;\n }\n let shouldRestoreFocus = false;\n const originalType = element.popover;\n let stackToAppendTo = null;\n const autoAncestor = topMostPopoverAncestor(\n element,\n autoPopoverList.get(document2) || /* @__PURE__ */ new Set()\n );\n const hintAncestor = topMostPopoverAncestor(\n element,\n hintPopoverList.get(document2) || /* @__PURE__ */ new Set()\n );\n if (originalType === \"auto\") {\n closeAllOpenPopoversInList(\n hintPopoverList.get(document2) || /* @__PURE__ */ new Set(),\n shouldRestoreFocus,\n true\n );\n const ancestor = autoAncestor || document2;\n hideAllPopoversUntil(ancestor, shouldRestoreFocus, true);\n stackToAppendTo = \"auto\";\n }\n if (originalType === \"hint\") {\n if (hintAncestor) {\n hideAllPopoversUntil(hintAncestor, shouldRestoreFocus, true);\n stackToAppendTo = \"hint\";\n } else {\n closeAllOpenPopoversInList(\n hintPopoverList.get(document2) || /* @__PURE__ */ new Set(),\n shouldRestoreFocus,\n true\n );\n if (autoAncestor) {\n hideAllPopoversUntil(autoAncestor, shouldRestoreFocus, true);\n stackToAppendTo = \"auto\";\n } else {\n stackToAppendTo = \"hint\";\n }\n }\n }\n if (originalType === \"auto\" || originalType === \"hint\") {\n if (originalType !== element.popover || !checkPopoverValidity(element, false)) {\n return;\n }\n if (!topmostAutoOrHintPopover(document2)) {\n shouldRestoreFocus = true;\n }\n if (stackToAppendTo === \"auto\") {\n if (!autoPopoverList.has(document2)) {\n autoPopoverList.set(document2, /* @__PURE__ */ new Set());\n }\n autoPopoverList.get(document2).add(element);\n } else if (stackToAppendTo === \"hint\") {\n if (!hintPopoverList.has(document2)) {\n hintPopoverList.set(document2, /* @__PURE__ */ new Set());\n }\n hintPopoverList.get(document2).add(element);\n }\n }\n previouslyFocusedElements.delete(element);\n const originallyFocusedElement = document2.activeElement;\n element.classList.add(\":popover-open\");\n visibilityState.set(element, \"showing\");\n if (!topLayerElements.has(document2)) {\n topLayerElements.set(document2, /* @__PURE__ */ new Set());\n }\n topLayerElements.get(document2).add(element);\n setInvokerAriaExpanded(popoverInvoker.get(element), true);\n popoverFocusingSteps(element);\n if (shouldRestoreFocus && originallyFocusedElement && element.popover === \"auto\") {\n previouslyFocusedElements.set(element, originallyFocusedElement);\n }\n queuePopoverToggleEventTask(element, \"closed\", \"open\");\n}\nfunction hidePopover(element, focusPreviousElement = false, fireEvents = false) {\n var _a, _b;\n if (!checkPopoverValidity(element, true)) {\n return;\n }\n const document2 = element.ownerDocument;\n if ([\"auto\", \"hint\"].includes(element.popover)) {\n hideAllPopoversUntil(element, focusPreviousElement, fireEvents);\n if (!checkPopoverValidity(element, true)) {\n return;\n }\n }\n const autoList = autoPopoverList.get(document2) || /* @__PURE__ */ new Set();\n const autoPopoverListContainsElement = autoList.has(element) && lastSetElement(autoList) === element;\n setInvokerAriaExpanded(popoverInvoker.get(element), false);\n popoverInvoker.delete(element);\n if (fireEvents) {\n element.dispatchEvent(\n new ToggleEvent(\"beforetoggle\", {\n oldState: \"open\",\n newState: \"closed\"\n })\n );\n if (autoPopoverListContainsElement && lastSetElement(autoList) !== element) {\n hideAllPopoversUntil(element, focusPreviousElement, fireEvents);\n }\n if (!checkPopoverValidity(element, true)) {\n return;\n }\n }\n (_a = topLayerElements.get(document2)) == null ? void 0 : _a.delete(element);\n autoList.delete(element);\n (_b = hintPopoverList.get(document2)) == null ? void 0 : _b.delete(element);\n element.classList.remove(\":popover-open\");\n visibilityState.set(element, \"hidden\");\n if (fireEvents) {\n queuePopoverToggleEventTask(element, \"open\", \"closed\");\n }\n const previouslyFocusedElement = previouslyFocusedElements.get(element);\n if (previouslyFocusedElement) {\n previouslyFocusedElements.delete(element);\n if (focusPreviousElement) {\n previouslyFocusedElement.focus();\n }\n }\n}\nfunction closeAllOpenPopovers(document2, focusPreviousElement = false, fireEvents = false) {\n let popover = topmostAutoOrHintPopover(document2);\n while (popover) {\n hidePopover(popover, focusPreviousElement, fireEvents);\n popover = topmostAutoOrHintPopover(document2);\n }\n}\nfunction closeAllOpenPopoversInList(list, focusPreviousElement = false, fireEvents = false) {\n let popover = topMostPopoverInList(list);\n while (popover) {\n hidePopover(popover, focusPreviousElement, fireEvents);\n popover = topMostPopoverInList(list);\n }\n}\nfunction hidePopoverStackUntil(endpoint, set, focusPreviousElement, fireEvents) {\n let repeatingHide = false;\n let hasRunOnce = false;\n while (repeatingHide || !hasRunOnce) {\n hasRunOnce = true;\n let lastToHide = null;\n let foundEndpoint = false;\n for (const popover of set) {\n if (popover === endpoint) {\n foundEndpoint = true;\n } else if (foundEndpoint) {\n lastToHide = popover;\n break;\n }\n }\n if (!lastToHide) return;\n while (getPopoverVisibilityState(lastToHide) === \"showing\" && set.size) {\n hidePopover(lastSetElement(set), focusPreviousElement, fireEvents);\n }\n if (set.has(endpoint) && lastSetElement(set) !== endpoint) {\n repeatingHide = true;\n }\n if (repeatingHide) {\n fireEvents = false;\n }\n }\n}\nfunction hideAllPopoversUntil(endpoint, focusPreviousElement, fireEvents) {\n var _a, _b;\n const document2 = endpoint.ownerDocument || endpoint;\n if (endpoint instanceof Document) {\n return closeAllOpenPopovers(document2, focusPreviousElement, fireEvents);\n }\n if ((_a = hintPopoverList.get(document2)) == null ? void 0 : _a.has(endpoint)) {\n hidePopoverStackUntil(\n endpoint,\n hintPopoverList.get(document2),\n focusPreviousElement,\n fireEvents\n );\n return;\n }\n closeAllOpenPopoversInList(\n hintPopoverList.get(document2) || /* @__PURE__ */ new Set(),\n focusPreviousElement,\n fireEvents\n );\n if (!((_b = autoPopoverList.get(document2)) == null ? void 0 : _b.has(endpoint))) {\n return;\n }\n hidePopoverStackUntil(\n endpoint,\n autoPopoverList.get(document2),\n focusPreviousElement,\n fireEvents\n );\n}\nvar popoverPointerDownTargets = /* @__PURE__ */ new WeakMap();\nfunction lightDismissOpenPopovers(event) {\n if (!event.isTrusted) return;\n const target = event.composedPath()[0];\n if (!target) return;\n const document2 = target.ownerDocument;\n const topMostPopover = topmostAutoOrHintPopover(document2);\n if (!topMostPopover) return;\n const ancestor = topMostClickedPopover(target);\n if (ancestor && event.type === \"pointerdown\") {\n popoverPointerDownTargets.set(document2, ancestor);\n } else if (event.type === \"pointerup\") {\n const sameTarget = popoverPointerDownTargets.get(document2) === ancestor;\n popoverPointerDownTargets.delete(document2);\n if (sameTarget) {\n hideAllPopoversUntil(ancestor || document2, false, true);\n }\n }\n}\nvar initialAriaExpandedValue = /* @__PURE__ */ new WeakMap();\nfunction setInvokerAriaExpanded(el, force = false) {\n if (!el) return;\n if (!initialAriaExpandedValue.has(el)) {\n initialAriaExpandedValue.set(el, el.getAttribute(\"aria-expanded\"));\n }\n const popover = el.popoverTargetElement;\n if (popover instanceof HTMLElement && popover.popover === \"auto\") {\n el.setAttribute(\"aria-expanded\", String(force));\n } else {\n const initialValue = initialAriaExpandedValue.get(el);\n if (!initialValue) {\n el.removeAttribute(\"aria-expanded\");\n } else {\n el.setAttribute(\"aria-expanded\", initialValue);\n }\n }\n}\n\n// src/popover.ts\nvar ShadowRoot2 = globalThis.ShadowRoot || function() {\n};\nvar DEFAULT_LAYER_NAME = \"popover-polyfill\";\nfunction isSupported() {\n return typeof HTMLElement !== \"undefined\" && typeof HTMLElement.prototype === \"object\" && \"popover\" in HTMLElement.prototype;\n}\nfunction isHintSupported() {\n const el = document.createElement(\"div\");\n el.setAttribute(\"popover\", \"hint\");\n return el.popover === \"hint\";\n}\nfunction isPolyfilled() {\n var _a;\n return Boolean(\n ((_a = document.body) == null ? void 0 : _a.showPopover) && !/native code/i.test(document.body.showPopover.toString())\n );\n}\nfunction patchSelectorFn(object, name, mapper) {\n const original = object[name];\n Object.defineProperty(object, name, {\n value(selector) {\n return original.call(this, mapper(selector));\n }\n });\n}\nvar nonEscapedPopoverSelector = /(^|[^\\\\]):popover-open\\b/g;\nfunction hasLayerSupport() {\n return typeof globalThis.CSSLayerBlockRule === \"function\";\n}\nfunction getStyles(layerName) {\n var _a;\n const useLayer = hasLayerSupport();\n const layerNameEscaped = (layerName ?? ((_a = window.POPOVER_POLYFILL_OPTIONS) == null ? void 0 : _a.layerName) ?? DEFAULT_LAYER_NAME).split(\".\").map(CSS.escape).join(\".\");\n return `\n${useLayer ? `@layer ${layerNameEscaped} {` : \"\"}\n :where([popover]) {\n position: fixed;\n z-index: 2147483647;\n inset: 0;\n padding: 0.25em;\n width: fit-content;\n height: fit-content;\n border-width: initial;\n border-color: initial;\n border-image: initial;\n border-style: solid;\n background-color: canvas;\n color: canvastext;\n overflow: auto;\n margin: auto;\n }\n\n :where([popover]:not(.\\\\:popover-open)) {\n display: none;\n }\n\n :where(dialog[popover].\\\\:popover-open) {\n display: block;\n }\n\n :where(dialog[popover][open]) {\n display: revert;\n }\n\n :where([anchor].\\\\:popover-open) {\n inset: auto;\n }\n\n :where([anchor]:popover-open) {\n inset: auto;\n }\n\n @supports not (background-color: canvas) {\n :where([popover]) {\n background-color: white;\n color: black;\n }\n }\n\n @supports (width: -moz-fit-content) {\n :where([popover]) {\n width: -moz-fit-content;\n height: -moz-fit-content;\n }\n }\n\n @supports not (inset: 0) {\n :where([popover]) {\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n }\n }\n${useLayer ? \"}\" : \"\"}\n`;\n}\nvar popoverStyleSheet = null;\nfunction injectStyles(root, layerName) {\n const styles = getStyles(layerName);\n if (popoverStyleSheet === null) {\n try {\n popoverStyleSheet = new CSSStyleSheet();\n popoverStyleSheet.replaceSync(styles);\n } catch {\n popoverStyleSheet = false;\n }\n }\n if (popoverStyleSheet === false) {\n const sheet = document.createElement(\"style\");\n sheet.textContent = styles;\n if (root instanceof Document) {\n root.head.prepend(sheet);\n } else {\n root.prepend(sheet);\n }\n } else {\n root.adoptedStyleSheets = [popoverStyleSheet, ...root.adoptedStyleSheets];\n }\n}\nfunction apply(opts) {\n if (typeof window === \"undefined\") return;\n const layerName = opts == null ? void 0 : opts.layerName;\n window.ToggleEvent = window.ToggleEvent || ToggleEvent;\n function rewriteSelector(selector) {\n if (selector == null ? void 0 : selector.includes(\":popover-open\")) {\n selector = selector.replace(\n nonEscapedPopoverSelector,\n \"$1.\\\\:popover-open\"\n );\n }\n return selector;\n }\n patchSelectorFn(Document.prototype, \"querySelector\", rewriteSelector);\n patchSelectorFn(Document.prototype, \"querySelectorAll\", rewriteSelector);\n patchSelectorFn(Element.prototype, \"querySelector\", rewriteSelector);\n patchSelectorFn(Element.prototype, \"querySelectorAll\", rewriteSelector);\n patchSelectorFn(Element.prototype, \"matches\", rewriteSelector);\n patchSelectorFn(Element.prototype, \"closest\", rewriteSelector);\n patchSelectorFn(\n DocumentFragment.prototype,\n \"querySelectorAll\",\n rewriteSelector\n );\n Object.defineProperties(HTMLElement.prototype, {\n popover: {\n enumerable: true,\n configurable: true,\n get() {\n if (!this.hasAttribute(\"popover\")) return null;\n const value = (this.getAttribute(\"popover\") || \"\").toLowerCase();\n if (value === \"\" || value == \"auto\") return \"auto\";\n if (value == \"hint\") return \"hint\";\n return \"manual\";\n },\n set(value) {\n if (value === null) {\n this.removeAttribute(\"popover\");\n } else {\n this.setAttribute(\"popover\", value);\n }\n }\n },\n showPopover: {\n enumerable: true,\n configurable: true,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n value(options = {}) {\n showPopover(this);\n }\n },\n hidePopover: {\n enumerable: true,\n configurable: true,\n value() {\n hidePopover(this, true, true);\n }\n },\n togglePopover: {\n enumerable: true,\n configurable: true,\n value(options = {}) {\n if (typeof options === \"boolean\") {\n options = { force: options };\n }\n if (visibilityState.get(this) === \"showing\" && options.force === void 0 || options.force === false) {\n hidePopover(this, true, true);\n } else if (options.force === void 0 || options.force === true) {\n showPopover(this);\n }\n return visibilityState.get(this) === \"showing\";\n }\n }\n });\n const originalAttachShadow = Element.prototype.attachShadow;\n if (originalAttachShadow) {\n Object.defineProperties(Element.prototype, {\n attachShadow: {\n enumerable: true,\n configurable: true,\n writable: true,\n value(options) {\n const shadowRoot = originalAttachShadow.call(this, options);\n injectStyles(shadowRoot, layerName);\n return shadowRoot;\n }\n }\n });\n }\n const originalAttachInternals = HTMLElement.prototype.attachInternals;\n if (originalAttachInternals) {\n Object.defineProperties(HTMLElement.prototype, {\n attachInternals: {\n enumerable: true,\n configurable: true,\n writable: true,\n value() {\n const internals = originalAttachInternals.call(this);\n if (internals.shadowRoot) {\n injectStyles(internals.shadowRoot, layerName);\n }\n return internals;\n }\n }\n });\n }\n const popoverTargetAssociatedElements = /* @__PURE__ */ new WeakMap();\n function applyPopoverInvokerElementMixin(ElementClass) {\n Object.defineProperties(ElementClass.prototype, {\n popoverTargetElement: {\n enumerable: true,\n configurable: true,\n set(targetElement) {\n if (targetElement === null) {\n this.removeAttribute(\"popovertarget\");\n popoverTargetAssociatedElements.delete(this);\n } else if (!(targetElement instanceof Element)) {\n throw new TypeError(\n `popoverTargetElement must be an element or null`\n );\n } else {\n this.setAttribute(\"popovertarget\", \"\");\n popoverTargetAssociatedElements.set(this, targetElement);\n }\n },\n get() {\n if (this.localName !== \"button\" && this.localName !== \"input\") {\n return null;\n }\n if (this.localName === \"input\" && this.type !== \"reset\" && this.type !== \"image\" && this.type !== \"button\") {\n return null;\n }\n if (this.disabled) {\n return null;\n }\n if (this.form && this.type === \"submit\") {\n return null;\n }\n const targetElement = popoverTargetAssociatedElements.get(this);\n if (targetElement && targetElement.isConnected) {\n return targetElement;\n } else if (targetElement && !targetElement.isConnected) {\n popoverTargetAssociatedElements.delete(this);\n return null;\n }\n const root = getRootNode(this);\n const idref = this.getAttribute(\"popovertarget\");\n if ((root instanceof Document || root instanceof ShadowRoot2) && idref) {\n return root.getElementById(idref) || null;\n }\n return null;\n }\n },\n popoverTargetAction: {\n enumerable: true,\n configurable: true,\n get() {\n const value = (this.getAttribute(\"popovertargetaction\") || \"\").toLowerCase();\n if (value === \"show\" || value === \"hide\") return value;\n return \"toggle\";\n },\n set(value) {\n this.setAttribute(\"popovertargetaction\", value);\n }\n }\n });\n }\n applyPopoverInvokerElementMixin(HTMLButtonElement);\n applyPopoverInvokerElementMixin(HTMLInputElement);\n const handleInvokerActivation = (event) => {\n if (event.defaultPrevented) {\n return;\n }\n const composedPath = event.composedPath();\n const target = composedPath[0];\n if (!(target instanceof Element) || (target == null ? void 0 : target.shadowRoot)) {\n return;\n }\n const root = getRootNode(target);\n if (!(root instanceof ShadowRoot2 || root instanceof Document)) {\n return;\n }\n const invoker = composedPath.find(\n (el) => {\n var _a;\n return (_a = el.matches) == null ? void 0 : _a.call(el, \"[popovertargetaction],[popovertarget]\");\n }\n );\n if (invoker) {\n popoverTargetAttributeActivationBehavior(invoker);\n event.preventDefault();\n return;\n }\n };\n const onKeydown = (event) => {\n const key = event.key;\n const target = event.target;\n if (!event.defaultPrevented && target && (key === \"Escape\" || key === \"Esc\")) {\n hideAllPopoversUntil(target.ownerDocument, true, true);\n }\n };\n const addEventListeners = (root) => {\n root.addEventListener(\"click\", handleInvokerActivation);\n root.addEventListener(\"keydown\", onKeydown);\n root.addEventListener(\"pointerdown\", lightDismissOpenPopovers);\n root.addEventListener(\"pointerup\", lightDismissOpenPopovers);\n };\n addEventListeners(document);\n injectStyles(document, layerName);\n}\nexport {\n apply,\n injectStyles,\n isHintSupported,\n isPolyfilled,\n isSupported\n};\n//# sourceMappingURL=popover-fn.js.map\n"],"x_google_ignoreList":[0],"mappings":"AACA,IAAI,EAAc,cAAc,KAAM,CACpC,SACA,SACA,YAAY,EAAM,EAAO,CAAC,EAAG,CAC3B,IAAM,EAAY,OAAO,OAAO,CAAC,EAAG,CAAI,EACxC,OAAO,EAAU,SACjB,OAAO,EAAU,SACjB,MAAM,EAAM,CAAS,EACrB,KAAK,SAAW,OAAO,EAAK,UAAY,EAAE,EAC1C,KAAK,SAAW,OAAO,EAAK,UAAY,EAAE,CAC5C,CACF,EACI,EAAyC,IAAI,QACjD,SAAS,EAA4B,EAAS,EAAU,EAAU,CAChE,EAAuB,IACrB,EACA,eAAiB,CACV,EAAuB,IAAI,CAAO,GACvC,EAAQ,cACN,IAAI,EAAY,SAAU,CACxB,WAAY,GACZ,WACA,UACF,CAAC,CACH,CACF,EAAG,CAAC,CACN,CACF,CAGA,IAAI,EAAa,WAAW,YAAc,UAAW,CACrD,EACI,EAAoB,WAAW,mBAAqB,UAAW,CACnE,EACI,EAAmC,IAAI,QACvC,EAAkC,IAAI,QACtC,EAAkC,IAAI,QACtC,EAAkC,IAAI,QAC1C,SAAS,EAA0B,EAAS,CAC1C,OAAO,EAAgB,IAAI,CAAO,GAAK,QACzC,CACA,IAAI,EAAiC,IAAI,QACzC,SAAS,EAAe,EAAK,CAC3B,MAAO,CAAC,GAAG,CAAG,CAAC,CAAC,IAAI,CACtB,CACA,SAAS,EAAyC,EAAS,CACzD,IAAM,EAAU,EAAQ,qBACxB,GAAI,EAAE,aAAmB,aACvB,OAEF,IAAM,EAAa,EAA0B,CAAO,GAChD,EAAQ,sBAAwB,QAAU,IAAe,aAGzD,E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U,CACzC,GAAI,EAAM,iBACR,OAEF,IAAM,EAAe,EAAM,aAAa,EAClC,EAAS,EAAa,GAC5B,GAAI,EAAE,aAAkB,UAAa,GAAiC,WACpE,OAEF,IAAM,EAAO,EAAY,CAAM,EAC/B,GAAI,EAAE,aAAgB,GAAe,aAAgB,UACnD,OAEF,IAAM,EAAU,EAAa,KAC1B,GAEc,EAAG,SAA+B,KAAK,EAAI,uCAAuC,CAEnG,EACA,GAAI,EAAS,CACX,EAAyC,CAAO,EAChD,EAAM,eAAe,EACrB,MACF,CACF,EACM,EAAa,GAAU,CAC3B,IAAM,EAAM,EAAM,IACZ,EAAS,EAAM,OACjB,CAAC,EAAM,kBAAoB,IAAW,IAAQ,UAAY,IAAQ,QACpE,EAAqB,EAAO,cAAe,GAAM,EAAI,CAEzD,GAC2B,GAAS,CAClC,EAAK,iBAAiB,QAAS,CAAuB,EACtD,EAAK,iBAAiB,UAAW,CAAS,EAC1C,EAAK,iBAAiB,cAAe,CAAwB,EAC7D,EAAK,iBAAiB,YAAa,CAAwB,CAC7D,EACA,CAAkB,QAAQ,EAC1B,EAAa,SAAU,CAAS,CAClC"}
|
|
1
|
+
{"version":3,"file":"popover-fn.js","names":[],"sources":["../../../../../../../../node_modules/.pnpm/@oddbird+popover-polyfill@0.7.1_patch_hash=6227913935a153774e0e2569cb889d63767e7a5d572dbc6beeadfb2e77ed5c11/node_modules/@oddbird/popover-polyfill/dist/popover-fn.js"],"sourcesContent":["// src/events.ts\nvar ToggleEvent = class extends Event {\n oldState;\n newState;\n constructor(type, init = {}) {\n const eventInit = Object.assign({}, init);\n delete eventInit.oldState;\n delete eventInit.newState;\n super(type, eventInit);\n this.oldState = String(init.oldState || \"\");\n this.newState = String(init.newState || \"\");\n }\n};\nvar popoverToggleTaskQueue = /* @__PURE__ */ new WeakMap();\nfunction queuePopoverToggleEventTask(element, oldState, newState) {\n popoverToggleTaskQueue.set(\n element,\n setTimeout(() => {\n if (!popoverToggleTaskQueue.has(element)) return;\n element.dispatchEvent(\n new ToggleEvent(\"toggle\", {\n cancelable: false,\n oldState,\n newState\n })\n );\n }, 0)\n );\n}\n\n// src/popover-helpers.ts\nvar ShadowRoot = globalThis.ShadowRoot || function() {\n};\nvar HTMLDialogElement = globalThis.HTMLDialogElement || function() {\n};\nvar topLayerElements = /* @__PURE__ */ new WeakMap();\nvar autoPopoverList = /* @__PURE__ */ new WeakMap();\nvar hintPopoverList = /* @__PURE__ */ new WeakMap();\nvar visibilityState = /* @__PURE__ */ new WeakMap();\nfunction getPopoverVisibilityState(popover) {\n return visibilityState.get(popover) || \"hidden\";\n}\nvar popoverInvoker = /* @__PURE__ */ new WeakMap();\nfunction lastSetElement(set) {\n return [...set].pop();\n}\nfunction popoverTargetAttributeActivationBehavior(element) {\n const popover = element.popoverTargetElement;\n if (!(popover instanceof HTMLElement)) {\n return;\n }\n const visibility = getPopoverVisibilityState(popover);\n if (element.popoverTargetAction === \"show\" && visibility === \"showing\") {\n return;\n }\n if (element.popoverTargetAction === \"hide\" && visibility === \"hidden\") return;\n if (visibility === \"showing\") {\n hidePopover(popover, true, true);\n } else if (checkPopoverValidity(popover, false)) {\n popoverInvoker.set(popover, element);\n showPopover(popover);\n }\n}\nfunction checkPopoverValidity(element, expectedToBeShowing) {\n if (element.popover !== \"auto\" && element.popover !== \"manual\" && element.popover !== \"hint\") {\n return false;\n }\n if (!element.isConnected) return false;\n if (expectedToBeShowing && getPopoverVisibilityState(element) !== \"showing\") {\n return false;\n }\n if (!expectedToBeShowing && getPopoverVisibilityState(element) !== \"hidden\") {\n return false;\n }\n if (element instanceof HTMLDialogElement && element.hasAttribute(\"open\")) {\n return false;\n }\n if (document.fullscreenElement === element) return false;\n return true;\n}\nfunction getStackPosition(popover) {\n if (!popover) return 0;\n const autoPopovers = autoPopoverList.get(document) || /* @__PURE__ */ new Set();\n const hintPopovers = hintPopoverList.get(document) || /* @__PURE__ */ new Set();\n if (hintPopovers.has(popover)) {\n return [...hintPopovers].indexOf(popover) + autoPopovers.size + 1;\n }\n if (autoPopovers.has(popover)) {\n return [...autoPopovers].indexOf(popover) + 1;\n }\n return 0;\n}\nfunction topMostClickedPopover(target) {\n const clickedPopover = nearestInclusiveOpenPopover(target);\n const invokerPopover = nearestInclusiveTargetPopoverForInvoker(target);\n if (getStackPosition(clickedPopover) > getStackPosition(invokerPopover)) {\n return clickedPopover;\n }\n return invokerPopover;\n}\nfunction topmostAutoOrHintPopover(document2) {\n let topmostPopover;\n const hintPopovers = hintPopoverList.get(document2) || /* @__PURE__ */ new Set();\n const autoPopovers = autoPopoverList.get(document2) || /* @__PURE__ */ new Set();\n const usedStack = hintPopovers.size > 0 ? hintPopovers : autoPopovers.size > 0 ? autoPopovers : null;\n if (usedStack) {\n topmostPopover = lastSetElement(usedStack);\n if (!topmostPopover.isConnected) {\n usedStack.delete(topmostPopover);\n return topmostAutoOrHintPopover(document2);\n }\n return topmostPopover;\n }\n return null;\n}\nfunction topMostPopoverInList(list) {\n for (const popover of list || []) {\n if (!popover.isConnected) {\n list.delete(popover);\n } else {\n return popover;\n }\n }\n return null;\n}\nfunction getRootNode(node) {\n if (typeof node.getRootNode === \"function\") {\n return node.getRootNode();\n }\n if (node.parentNode) return getRootNode(node.parentNode);\n return node;\n}\nfunction nearestInclusiveOpenPopover(node) {\n while (node) {\n if (node instanceof HTMLElement && node.popover === \"auto\" && visibilityState.get(node) === \"showing\") {\n return node;\n }\n node = node instanceof Element && node.assignedSlot || node.parentElement || getRootNode(node);\n if (node instanceof ShadowRoot) node = node.host;\n if (node instanceof Document) return;\n }\n}\nfunction nearestInclusiveTargetPopoverForInvoker(node) {\n while (node) {\n const nodePopover = node.popoverTargetElement;\n if (nodePopover instanceof HTMLElement) return nodePopover;\n node = node.parentElement || getRootNode(node);\n if (node instanceof ShadowRoot) node = node.host;\n if (node instanceof Document) return;\n }\n}\nfunction topMostPopoverAncestor(newPopover, list) {\n const popoverPositions = /* @__PURE__ */ new Map();\n let i = 0;\n for (const popover of list || []) {\n popoverPositions.set(popover, i);\n i += 1;\n }\n popoverPositions.set(newPopover, i);\n i += 1;\n let topMostPopoverAncestor2 = null;\n function checkAncestor(candidate) {\n if (!candidate) return;\n let okNesting = false;\n let candidateAncestor = null;\n while (!okNesting) {\n candidateAncestor = nearestInclusiveOpenPopover(candidate) || null;\n if (candidateAncestor === null) return;\n if (!popoverPositions.has(candidateAncestor)) return;\n if (newPopover.popover === \"hint\" || candidateAncestor.popover === \"auto\") {\n okNesting = true;\n }\n if (!okNesting) {\n candidate = candidateAncestor.parentElement;\n }\n }\n const candidatePosition = popoverPositions.get(candidateAncestor) ?? null;\n if (topMostPopoverAncestor2 === null || popoverPositions.get(topMostPopoverAncestor2) < candidatePosition) {\n topMostPopoverAncestor2 = candidateAncestor;\n }\n }\n checkAncestor(newPopover.parentElement || getRootNode(newPopover));\n return topMostPopoverAncestor2;\n}\nfunction isFocusable(focusTarget) {\n if (focusTarget.hidden || focusTarget instanceof ShadowRoot) return false;\n if (focusTarget instanceof HTMLButtonElement || focusTarget instanceof HTMLInputElement || focusTarget instanceof HTMLSelectElement || focusTarget instanceof HTMLTextAreaElement || focusTarget instanceof HTMLOptGroupElement || focusTarget instanceof HTMLOptionElement || focusTarget instanceof HTMLFieldSetElement) {\n if (focusTarget.disabled) return false;\n }\n if (focusTarget instanceof HTMLInputElement && focusTarget.type === \"hidden\") {\n return false;\n }\n if (focusTarget instanceof HTMLAnchorElement && focusTarget.href === \"\") {\n return false;\n }\n return typeof focusTarget.tabIndex === \"number\" && focusTarget.tabIndex !== -1;\n}\nfunction focusDelegate(focusTarget) {\n if (focusTarget.shadowRoot && focusTarget.shadowRoot.delegatesFocus !== true) {\n return null;\n }\n let whereToLook = focusTarget;\n if (whereToLook.shadowRoot) {\n whereToLook = whereToLook.shadowRoot;\n }\n let autoFocusDelegate = whereToLook.querySelector(\"[autofocus]\");\n if (autoFocusDelegate) {\n return autoFocusDelegate;\n } else {\n const slots = whereToLook.querySelectorAll(\"slot\");\n for (const slot of slots) {\n const assignedElements = slot.assignedElements({ flatten: true });\n for (const el of assignedElements) {\n if (el.hasAttribute(\"autofocus\")) {\n return el;\n } else {\n autoFocusDelegate = el.querySelector(\"[autofocus]\");\n if (autoFocusDelegate) {\n return autoFocusDelegate;\n }\n }\n }\n }\n }\n const walker = focusTarget.ownerDocument.createTreeWalker(\n whereToLook,\n NodeFilter.SHOW_ELEMENT\n );\n let descendant = walker.currentNode;\n while (descendant) {\n if (isFocusable(descendant)) {\n return descendant;\n }\n descendant = walker.nextNode();\n }\n}\nfunction popoverFocusingSteps(subject) {\n var _a;\n (_a = focusDelegate(subject)) == null ? void 0 : _a.focus();\n}\nvar previouslyFocusedElements = /* @__PURE__ */ new WeakMap();\nfunction showPopover(element) {\n if (!checkPopoverValidity(element, false)) {\n return;\n }\n const document2 = element.ownerDocument;\n if (!element.dispatchEvent(\n new ToggleEvent(\"beforetoggle\", {\n cancelable: true,\n oldState: \"closed\",\n newState: \"open\"\n })\n )) {\n return;\n }\n if (!checkPopoverValidity(element, false)) {\n return;\n }\n let shouldRestoreFocus = false;\n const originalType = element.popover;\n let stackToAppendTo = null;\n const autoAncestor = topMostPopoverAncestor(\n element,\n autoPopoverList.get(document2) || /* @__PURE__ */ new Set()\n );\n const hintAncestor = topMostPopoverAncestor(\n element,\n hintPopoverList.get(document2) || /* @__PURE__ */ new Set()\n );\n if (originalType === \"auto\") {\n closeAllOpenPopoversInList(\n hintPopoverList.get(document2) || /* @__PURE__ */ new Set(),\n shouldRestoreFocus,\n true\n );\n const ancestor = autoAncestor || document2;\n hideAllPopoversUntil(ancestor, shouldRestoreFocus, true);\n stackToAppendTo = \"auto\";\n }\n if (originalType === \"hint\") {\n if (hintAncestor) {\n hideAllPopoversUntil(hintAncestor, shouldRestoreFocus, true);\n stackToAppendTo = \"hint\";\n } else {\n closeAllOpenPopoversInList(\n hintPopoverList.get(document2) || /* @__PURE__ */ new Set(),\n shouldRestoreFocus,\n true\n );\n if (autoAncestor) {\n hideAllPopoversUntil(autoAncestor, shouldRestoreFocus, true);\n stackToAppendTo = \"auto\";\n } else {\n stackToAppendTo = \"hint\";\n }\n }\n }\n if (originalType === \"auto\" || originalType === \"hint\") {\n if (originalType !== element.popover || !checkPopoverValidity(element, false)) {\n return;\n }\n if (!topmostAutoOrHintPopover(document2)) {\n shouldRestoreFocus = true;\n }\n if (stackToAppendTo === \"auto\") {\n if (!autoPopoverList.has(document2)) {\n autoPopoverList.set(document2, /* @__PURE__ */ new Set());\n }\n autoPopoverList.get(document2).add(element);\n } else if (stackToAppendTo === \"hint\") {\n if (!hintPopoverList.has(document2)) {\n hintPopoverList.set(document2, /* @__PURE__ */ new Set());\n }\n hintPopoverList.get(document2).add(element);\n }\n }\n previouslyFocusedElements.delete(element);\n const originallyFocusedElement = document2.activeElement;\n element.classList.add(\":popover-open\");\n visibilityState.set(element, \"showing\");\n if (!topLayerElements.has(document2)) {\n topLayerElements.set(document2, /* @__PURE__ */ new Set());\n }\n topLayerElements.get(document2).add(element);\n setInvokerAriaExpanded(popoverInvoker.get(element), true);\n popoverFocusingSteps(element);\n if (shouldRestoreFocus && originallyFocusedElement && element.popover === \"auto\") {\n previouslyFocusedElements.set(element, originallyFocusedElement);\n }\n queuePopoverToggleEventTask(element, \"closed\", \"open\");\n}\nfunction hidePopover(element, focusPreviousElement = false, fireEvents = false) {\n var _a, _b;\n if (!checkPopoverValidity(element, true)) {\n return;\n }\n const document2 = element.ownerDocument;\n if ([\"auto\", \"hint\"].includes(element.popover)) {\n hideAllPopoversUntil(element, focusPreviousElement, fireEvents);\n if (!checkPopoverValidity(element, true)) {\n return;\n }\n }\n const autoList = autoPopoverList.get(document2) || /* @__PURE__ */ new Set();\n const autoPopoverListContainsElement = autoList.has(element) && lastSetElement(autoList) === element;\n setInvokerAriaExpanded(popoverInvoker.get(element), false);\n popoverInvoker.delete(element);\n if (fireEvents) {\n element.dispatchEvent(\n new ToggleEvent(\"beforetoggle\", {\n oldState: \"open\",\n newState: \"closed\"\n })\n );\n if (autoPopoverListContainsElement && lastSetElement(autoList) !== element) {\n hideAllPopoversUntil(element, focusPreviousElement, fireEvents);\n }\n if (!checkPopoverValidity(element, true)) {\n return;\n }\n }\n (_a = topLayerElements.get(document2)) == null ? void 0 : _a.delete(element);\n autoList.delete(element);\n (_b = hintPopoverList.get(document2)) == null ? void 0 : _b.delete(element);\n element.classList.remove(\":popover-open\");\n visibilityState.set(element, \"hidden\");\n if (fireEvents) {\n queuePopoverToggleEventTask(element, \"open\", \"closed\");\n }\n const previouslyFocusedElement = previouslyFocusedElements.get(element);\n if (previouslyFocusedElement) {\n previouslyFocusedElements.delete(element);\n if (focusPreviousElement) {\n previouslyFocusedElement.focus();\n }\n }\n}\nfunction closeAllOpenPopovers(document2, focusPreviousElement = false, fireEvents = false) {\n let popover = topmostAutoOrHintPopover(document2);\n while (popover) {\n hidePopover(popover, focusPreviousElement, fireEvents);\n popover = topmostAutoOrHintPopover(document2);\n }\n}\nfunction closeAllOpenPopoversInList(list, focusPreviousElement = false, fireEvents = false) {\n let popover = topMostPopoverInList(list);\n while (popover) {\n hidePopover(popover, focusPreviousElement, fireEvents);\n popover = topMostPopoverInList(list);\n }\n}\nfunction hidePopoverStackUntil(endpoint, set, focusPreviousElement, fireEvents) {\n let repeatingHide = false;\n let hasRunOnce = false;\n while (repeatingHide || !hasRunOnce) {\n hasRunOnce = true;\n let lastToHide = null;\n let foundEndpoint = false;\n for (const popover of set) {\n if (popover === endpoint) {\n foundEndpoint = true;\n } else if (foundEndpoint) {\n lastToHide = popover;\n break;\n }\n }\n if (!lastToHide) return;\n while (getPopoverVisibilityState(lastToHide) === \"showing\" && set.size) {\n hidePopover(lastSetElement(set), focusPreviousElement, fireEvents);\n }\n if (set.has(endpoint) && lastSetElement(set) !== endpoint) {\n repeatingHide = true;\n }\n if (repeatingHide) {\n fireEvents = false;\n }\n }\n}\nfunction hideAllPopoversUntil(endpoint, focusPreviousElement, fireEvents) {\n var _a, _b;\n const document2 = endpoint.ownerDocument || endpoint;\n if (endpoint instanceof Document) {\n return closeAllOpenPopovers(document2, focusPreviousElement, fireEvents);\n }\n if ((_a = hintPopoverList.get(document2)) == null ? void 0 : _a.has(endpoint)) {\n hidePopoverStackUntil(\n endpoint,\n hintPopoverList.get(document2),\n focusPreviousElement,\n fireEvents\n );\n return;\n }\n closeAllOpenPopoversInList(\n hintPopoverList.get(document2) || /* @__PURE__ */ new Set(),\n focusPreviousElement,\n fireEvents\n );\n if (!((_b = autoPopoverList.get(document2)) == null ? void 0 : _b.has(endpoint))) {\n return;\n }\n hidePopoverStackUntil(\n endpoint,\n autoPopoverList.get(document2),\n focusPreviousElement,\n fireEvents\n );\n}\nvar popoverPointerDownTargets = /* @__PURE__ */ new WeakMap();\nfunction lightDismissOpenPopovers(event) {\n if (!event.isTrusted) return;\n const target = event.composedPath()[0];\n if (!target) return;\n const document2 = target.ownerDocument;\n const topMostPopover = topmostAutoOrHintPopover(document2);\n if (!topMostPopover) return;\n const ancestor = topMostClickedPopover(target);\n if (ancestor && event.type === \"pointerdown\") {\n popoverPointerDownTargets.set(document2, ancestor);\n } else if (event.type === \"pointerup\") {\n const sameTarget = popoverPointerDownTargets.get(document2) === ancestor;\n popoverPointerDownTargets.delete(document2);\n if (sameTarget) {\n hideAllPopoversUntil(ancestor || document2, false, true);\n }\n }\n}\nvar initialAriaExpandedValue = /* @__PURE__ */ new WeakMap();\nfunction setInvokerAriaExpanded(el, force = false) {\n if (!el) return;\n if (!initialAriaExpandedValue.has(el)) {\n initialAriaExpandedValue.set(el, el.getAttribute(\"aria-expanded\"));\n }\n const popover = el.popoverTargetElement;\n if (popover instanceof HTMLElement && popover.popover === \"auto\") {\n el.setAttribute(\"aria-expanded\", String(force));\n } else {\n const initialValue = initialAriaExpandedValue.get(el);\n if (!initialValue) {\n el.removeAttribute(\"aria-expanded\");\n } else {\n el.setAttribute(\"aria-expanded\", initialValue);\n }\n }\n}\n\n// src/popover.ts\nvar ShadowRoot2 = globalThis.ShadowRoot || function() {\n};\nvar DEFAULT_LAYER_NAME = \"popover-polyfill\";\nfunction isSupported() {\n return typeof HTMLElement !== \"undefined\" && typeof HTMLElement.prototype === \"object\" && \"popover\" in HTMLElement.prototype && \"showPopover\" in HTMLElement.prototype;\n}\nfunction isHintSupported() {\n const el = document.createElement(\"div\");\n el.setAttribute(\"popover\", \"hint\");\n return el.popover === \"hint\";\n}\nfunction isPolyfilled() {\n var _a;\n return Boolean(\n ((_a = document.body) == null ? void 0 : _a.showPopover) && !/native code/i.test(document.body.showPopover.toString())\n );\n}\nfunction patchSelectorFn(object, name, mapper) {\n const original = object[name];\n Object.defineProperty(object, name, {\n value(selector) {\n return original.call(this, mapper(selector));\n }\n });\n}\nvar nonEscapedPopoverSelector = /(^|[^\\\\]):popover-open\\b/g;\nfunction hasLayerSupport() {\n return typeof globalThis.CSSLayerBlockRule === \"function\";\n}\nfunction getStyles(layerName) {\n var _a;\n const useLayer = hasLayerSupport();\n const layerNameEscaped = (layerName ?? ((_a = window.POPOVER_POLYFILL_OPTIONS) == null ? void 0 : _a.layerName) ?? DEFAULT_LAYER_NAME).split(\".\").map((c) => CSS.escape(c)).join(\".\");\n return `\n${useLayer ? `@layer ${layerNameEscaped} {` : \"\"}\n :where([popover]) {\n position: fixed;\n z-index: 2147483647;\n inset: 0;\n padding: 0.25em;\n width: fit-content;\n height: fit-content;\n border-width: initial;\n border-color: initial;\n border-image: initial;\n border-style: solid;\n background-color: canvas;\n color: canvastext;\n overflow: auto;\n margin: auto;\n }\n\n :where([popover]:not(.\\\\:popover-open)) {\n display: none;\n }\n\n :where(dialog[popover].\\\\:popover-open) {\n display: block;\n }\n\n :where(dialog[popover][open]) {\n display: revert;\n }\n\n :where([anchor].\\\\:popover-open) {\n inset: auto;\n }\n\n :where([anchor]:popover-open) {\n inset: auto;\n }\n\n @supports not (background-color: canvas) {\n :where([popover]) {\n background-color: white;\n color: black;\n }\n }\n\n @supports (width: -moz-fit-content) {\n :where([popover]) {\n width: -moz-fit-content;\n height: -moz-fit-content;\n }\n }\n\n @supports not (inset: 0) {\n :where([popover]) {\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n }\n }\n${useLayer ? \"}\" : \"\"}\n`;\n}\nvar popoverStyleSheet = null;\nfunction injectStyles(root, layerName) {\n const styles = getStyles(layerName);\n if (popoverStyleSheet === null) {\n try {\n popoverStyleSheet = new CSSStyleSheet();\n popoverStyleSheet.replaceSync(styles);\n } catch {\n popoverStyleSheet = false;\n }\n }\n if (popoverStyleSheet === false || !root.adoptedStyleSheets) {\n const sheet = document.createElement(\"style\");\n sheet.textContent = styles;\n if (root instanceof Document) {\n root.head.prepend(sheet);\n } else {\n root.prepend(sheet);\n }\n } else {\n root.adoptedStyleSheets = [popoverStyleSheet, ...root.adoptedStyleSheets];\n }\n}\nfunction apply(opts) {\n if (typeof window === \"undefined\") return;\n const layerName = opts == null ? void 0 : opts.layerName;\n window.ToggleEvent = window.ToggleEvent || ToggleEvent;\n function rewriteSelector(selector) {\n if (selector == null ? void 0 : selector.includes(\":popover-open\")) {\n selector = selector.replace(\n nonEscapedPopoverSelector,\n \"$1.\\\\:popover-open\"\n );\n }\n return selector;\n }\n patchSelectorFn(Document.prototype, \"querySelector\", rewriteSelector);\n patchSelectorFn(Document.prototype, \"querySelectorAll\", rewriteSelector);\n patchSelectorFn(Element.prototype, \"querySelector\", rewriteSelector);\n patchSelectorFn(Element.prototype, \"querySelectorAll\", rewriteSelector);\n patchSelectorFn(Element.prototype, \"matches\", rewriteSelector);\n patchSelectorFn(Element.prototype, \"closest\", rewriteSelector);\n patchSelectorFn(\n DocumentFragment.prototype,\n \"querySelectorAll\",\n rewriteSelector\n );\n Object.defineProperties(HTMLElement.prototype, {\n popover: {\n enumerable: true,\n configurable: true,\n get() {\n if (!this.hasAttribute(\"popover\")) return null;\n const value = (this.getAttribute(\"popover\") || \"\").toLowerCase();\n if (value === \"\" || value == \"auto\") return \"auto\";\n if (value == \"hint\") return \"hint\";\n return \"manual\";\n },\n set(value) {\n if (value === null) {\n this.removeAttribute(\"popover\");\n } else {\n this.setAttribute(\"popover\", value);\n }\n }\n },\n showPopover: {\n enumerable: true,\n configurable: true,\n writable: true,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n value(options = {}) {\n showPopover(this);\n }\n },\n hidePopover: {\n enumerable: true,\n configurable: true,\n writable: true,\n value() {\n hidePopover(this, true, true);\n }\n },\n togglePopover: {\n enumerable: true,\n configurable: true,\n writable: true,\n value(options = {}) {\n if (typeof options === \"boolean\") {\n options = { force: options };\n }\n if (visibilityState.get(this) === \"showing\" && options.force === void 0 || options.force === false) {\n hidePopover(this, true, true);\n } else if (options.force === void 0 || options.force === true) {\n showPopover(this);\n }\n return visibilityState.get(this) === \"showing\";\n }\n }\n });\n const originalAttachShadow = Element.prototype.attachShadow;\n if (originalAttachShadow) {\n Object.defineProperties(Element.prototype, {\n attachShadow: {\n enumerable: true,\n configurable: true,\n writable: true,\n value(options) {\n const shadowRoot = originalAttachShadow.call(this, options);\n injectStyles(shadowRoot, layerName);\n return shadowRoot;\n }\n }\n });\n }\n const originalAttachInternals = HTMLElement.prototype.attachInternals;\n if (originalAttachInternals) {\n Object.defineProperties(HTMLElement.prototype, {\n attachInternals: {\n enumerable: true,\n configurable: true,\n writable: true,\n value() {\n const internals = originalAttachInternals.call(this);\n if (internals.shadowRoot) {\n injectStyles(internals.shadowRoot, layerName);\n }\n return internals;\n }\n }\n });\n }\n const popoverTargetAssociatedElements = /* @__PURE__ */ new WeakMap();\n function applyPopoverInvokerElementMixin(ElementClass) {\n Object.defineProperties(ElementClass.prototype, {\n popoverTargetElement: {\n enumerable: true,\n configurable: true,\n set(targetElement) {\n if (targetElement === null) {\n this.removeAttribute(\"popovertarget\");\n popoverTargetAssociatedElements.delete(this);\n } else if (!(targetElement instanceof Element)) {\n throw new TypeError(\n `popoverTargetElement must be an element or null`\n );\n } else {\n this.setAttribute(\"popovertarget\", \"\");\n popoverTargetAssociatedElements.set(this, targetElement);\n }\n },\n get() {\n if (this.localName !== \"button\" && this.localName !== \"input\") {\n return null;\n }\n if (this.localName === \"input\" && this.type !== \"reset\" && this.type !== \"image\" && this.type !== \"button\") {\n return null;\n }\n if (this.disabled) {\n return null;\n }\n if (this.form && this.type === \"submit\") {\n return null;\n }\n const targetElement = popoverTargetAssociatedElements.get(this);\n if (targetElement && targetElement.isConnected) {\n return targetElement;\n } else if (targetElement && !targetElement.isConnected) {\n popoverTargetAssociatedElements.delete(this);\n return null;\n }\n const root = getRootNode(this);\n const idref = this.getAttribute(\"popovertarget\");\n if ((root instanceof Document || root instanceof ShadowRoot2) && idref) {\n return root.getElementById(idref) || null;\n }\n return null;\n }\n },\n popoverTargetAction: {\n enumerable: true,\n configurable: true,\n get() {\n const value = (this.getAttribute(\"popovertargetaction\") || \"\").toLowerCase();\n if (value === \"show\" || value === \"hide\") return value;\n return \"toggle\";\n },\n set(value) {\n this.setAttribute(\"popovertargetaction\", value);\n }\n }\n });\n }\n applyPopoverInvokerElementMixin(HTMLButtonElement);\n applyPopoverInvokerElementMixin(HTMLInputElement);\n const handleInvokerActivation = (event) => {\n if (event.defaultPrevented) {\n return;\n }\n const composedPath = event.composedPath();\n const target = composedPath[0];\n if (!(target instanceof Element) || (target == null ? void 0 : target.shadowRoot)) {\n return;\n }\n const root = getRootNode(target);\n if (!(root instanceof ShadowRoot2 || root instanceof Document)) {\n return;\n }\n const invoker = composedPath.find(\n (el) => {\n var _a;\n return (_a = el.matches) == null ? void 0 : _a.call(el, \"[popovertargetaction],[popovertarget]\");\n }\n );\n if (invoker) {\n popoverTargetAttributeActivationBehavior(invoker);\n event.preventDefault();\n return;\n }\n };\n const onKeydown = (event) => {\n const key = event.key;\n const target = event.target;\n if (!event.defaultPrevented && target && (key === \"Escape\" || key === \"Esc\")) {\n const owner = target.ownerDocument || target;\n hideAllPopoversUntil(owner, true, true);\n }\n };\n const addEventListeners = (root) => {\n root.addEventListener(\"click\", handleInvokerActivation);\n root.addEventListener(\"keydown\", onKeydown);\n root.addEventListener(\"pointerdown\", lightDismissOpenPopovers);\n root.addEventListener(\"pointerup\", lightDismissOpenPopovers);\n };\n addEventListeners(document);\n injectStyles(document, layerName);\n}\nexport {\n apply,\n injectStyles,\n isHintSupported,\n isPolyfilled,\n isSupported\n};\n//# sourceMappingURL=popover-fn.js.map\n"],"x_google_ignoreList":[0],"mappings":"AACA,IAAI,EAAc,cAAc,KAAM,CACpC,SACA,SACA,YAAY,EAAM,EAAO,CAAC,EAAG,CAC3B,IAAM,EAAY,OAAO,OAAO,CAAC,EAAG,CAAI,EACxC,OAAO,EAAU,SACjB,OAAO,EAAU,SACjB,MAAM,EAAM,CAAS,EACrB,KAAK,SAAW,OAAO,EAAK,UAAY,EAAE,EAC1C,KAAK,SAAW,OAAO,EAAK,UAAY,EAAE,CAC5C,CACF,EACI,EAAyC,IAAI,QACjD,SAAS,EAA4B,EAAS,EAAU,EAAU,CAChE,EAAuB,IACrB,EACA,eAAiB,CACV,EAAuB,IAAI,CAAO,GACvC,EAAQ,cACN,IAAI,EAAY,SAAU,CACxB,WAAY,GACZ,WACA,UACF,CAAC,CACH,CACF,EAAG,CAAC,CACN,CACF,CAGA,IAAI,EAAa,WAAW,YAAc,UAAW,CACrD,EACI,EAAoB,WAAW,mBAAqB,UAAW,CACnE,EACI,EAAmC,IAAI,QACvC,EAAkC,IAAI,QACtC,EAAkC,IAAI,QACtC,EAAkC,IAAI,QAC1C,SAAS,EAA0B,EAAS,CAC1C,OAAO,EAAgB,IAAI,CAAO,GAAK,QACzC,CACA,IAAI,EAAiC,IAAI,QACzC,SAAS,EAAe,EAAK,CAC3B,MAAO,CAAC,GAAG,CAAG,CAAC,CAAC,IAAI,CACtB,CACA,SAAS,EAAyC,EAAS,CACzD,IAAM,EAAU,EAAQ,qBACxB,GAAI,EAAE,aAAmB,aACvB,OAEF,IAAM,EAAa,EAA0B,CAAO,GAChD,EAAQ,sBAAwB,QAAU,IAAe,aAGzD,EAAQ,sBAAwB,QAAU,IAAe,YACzD,I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AgC,iBAAiB,EACjD,EAAgC,gBAAgB,EAChD,IAAM,EAA2B,GAAU,CACzC,GAAI,EAAM,iBACR,OAEF,IAAM,EAAe,EAAM,aAAa,EAClC,EAAS,EAAa,GAC5B,GAAI,EAAE,aAAkB,UAAa,GAAiC,WACpE,OAEF,IAAM,EAAO,EAAY,CAAM,EAC/B,GAAI,EAAE,aAAgB,GAAe,aAAgB,UACnD,OAEF,IAAM,EAAU,EAAa,KAC1B,GAEc,EAAG,SAA+B,KAAK,EAAI,uCAAuC,CAEnG,EACA,GAAI,EAAS,CACX,EAAyC,CAAO,EAChD,EAAM,eAAe,EACrB,MACF,CACF,EACM,EAAa,GAAU,CAC3B,IAAM,EAAM,EAAM,IACZ,EAAS,EAAM,OACjB,CAAC,EAAM,kBAAoB,IAAW,IAAQ,UAAY,IAAQ,QAEpE,EADc,EAAO,eAAiB,EACV,GAAM,EAAI,CAE1C,GAC2B,GAAS,CAClC,EAAK,iBAAiB,QAAS,CAAuB,EACtD,EAAK,iBAAiB,UAAW,CAAS,EAC1C,EAAK,iBAAiB,cAAe,CAAwB,EAC7D,EAAK,iBAAiB,YAAa,CAAwB,CAC7D,EACA,CAAkB,QAAQ,EAC1B,EAAa,SAAU,CAAS,CAClC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{QUICK_EVENT as e,attr as t,
|
|
1
|
+
import{QUICK_EVENT as e,attr as t,getComposedPath as n,getComposedTarget as r,getRoot as i,on as a,onHotReload as o}from"../utils/utils.js";const s=`:click-delegate-hover`,c=new Set([`A`,`BUTTON`,`DETAILS`,`DIALOG`,`INPUT`,`LABEL`,`SELECT`,`TEXTAREA`]),l=e=>{let t=e.button===1||e.metaKey||e.ctrlKey,i=r(e),a=e.button<2&&p(e);if(!(!a||a.contains(i))){for(let e of n(i))if(e.control===a)return;if(t&&a instanceof HTMLAnchorElement)return window.open(a.href,void 0,a.rel);e.stopImmediatePropagation(),a.click()}};let u,d;const f=e=>{let t=r(e);if(!t||t===d)return;d=t;let n=p(e);u!==n&&(u&&u.classList.remove(s),n&&n.classList.add(s),u=n)},p=e=>{let t;for(let n of e.composedPath()){if(n.nodeType!==1)continue;n.nodeName===`LABEL`&&(n=n.control||n);let e=n.getAttribute(`data-clickdelegatefor`);if(e){let r=i(n).getElementById(e);return r&&!(t&&t!==r)&&!r.disabled&&!r.readOnly?r:void 0}!t&&m(n)&&(t=n)}},m=e=>e.isContentEditable||e.popover||c.has(e.nodeName)||t(e,`role`)===`button`;o(`clickdelegatefor`,()=>[a(window,`click auxclick`,l,!0),a(document,`mousemove`,f,e)]);
|
|
2
2
|
//# sourceMappingURL=clickdelegatefor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clickdelegatefor.js","names":[],"sources":["../../../src/clickdelegatefor/clickdelegatefor.ts"],"sourcesContent":["// Adding support for click deletagtion, following\n// https://open-ui.org/components/link-area-delegation-explainer/\n// and https://github.com/openui/open-ui/issues/1104#issuecomment-3151387080\nimport {\n attr,\n getComposedTarget,\n getRoot,\n on,\n onHotReload,\n QUICK_EVENT,\n} from '../utils/utils';\n\nconst ATTR_CLICKDELEGATEFOR = 'data-clickdelegatefor';\nconst CLASS_HOVER = ':click-delegate-hover';\nconst SKIP = new Set([\n 'A',\n 'BUTTON',\n 'DETAILS',\n 'DIALOG',\n 'INPUT',\n 'LABEL',\n 'SELECT',\n 'TEXTAREA',\n]); // Ignore interactive elements, and elements that create a new \"context\" or \"scope\"\n\nconst handleClickDelegateFor = (event: MouseEvent) => {\n const isNewTab = event.button === 1 || event.metaKey || event.ctrlKey; // Middle click or cmd/ctrl + click should open in new tab\n const target = getComposedTarget(event);\n const delegateTarget = event.button < 2 && getDelegateTarget(event); // Only accept left or middle clicks\n\n if (!delegateTarget || delegateTarget.contains(target)) return; // Only proxy event if delegated target isn't part of the original target\n if (isNewTab && delegateTarget instanceof HTMLAnchorElement)\n return window.open(delegateTarget.href, undefined, delegateTarget.rel); // If middle click or cmd/ctrl click on link, open in new tab\n event.stopImmediatePropagation(); // We'll trigger a new click event anyway, so prevent actions on this one\n
|
|
1
|
+
{"version":3,"file":"clickdelegatefor.js","names":[],"sources":["../../../src/clickdelegatefor/clickdelegatefor.ts"],"sourcesContent":["// Adding support for click deletagtion, following\n// https://open-ui.org/components/link-area-delegation-explainer/\n// and https://github.com/openui/open-ui/issues/1104#issuecomment-3151387080\nimport {\n attr,\n getComposedPath,\n getComposedTarget,\n getRoot,\n on,\n onHotReload,\n QUICK_EVENT,\n} from '../utils/utils';\n\nconst ATTR_CLICKDELEGATEFOR = 'data-clickdelegatefor';\nconst CLASS_HOVER = ':click-delegate-hover';\nconst SKIP = new Set([\n 'A',\n 'BUTTON',\n 'DETAILS',\n 'DIALOG',\n 'INPUT',\n 'LABEL',\n 'SELECT',\n 'TEXTAREA',\n]); // Ignore interactive elements, and elements that create a new \"context\" or \"scope\"\n\nconst handleClickDelegateFor = (event: MouseEvent) => {\n const isNewTab = event.button === 1 || event.metaKey || event.ctrlKey; // Middle click or cmd/ctrl + click should open in new tab\n const target = getComposedTarget(event);\n const delegateTarget = event.button < 2 && getDelegateTarget(event); // Only accept left or middle clicks\n\n if (!delegateTarget || delegateTarget.contains(target)) return; // Only proxy event if delegated target isn't part of the original target\n for (const el of getComposedPath(target))\n if ((el as HTMLLabelElement).control === delegateTarget) return; // Let labels forward click natively\n\n if (isNewTab && delegateTarget instanceof HTMLAnchorElement)\n return window.open(delegateTarget.href, undefined, delegateTarget.rel); // If middle click or cmd/ctrl click on link, open in new tab\n event.stopImmediatePropagation(); // We'll trigger a new click event anyway, so prevent actions on this one\n delegateTarget.click(); // Forward click to the clickable element\n};\n\nlet HOVER: Element | undefined;\nlet TARGET: EventTarget; // Used to speed up mouseover handling\nconst handleMouseMove = (event: Event) => {\n const target = getComposedTarget(event);\n if (!target || target === TARGET) return; // Same target, no need to check delegate target again\n TARGET = target;\n const delegateTarget = getDelegateTarget(event);\n if (HOVER === delegateTarget) return; // No change\n if (HOVER) HOVER.classList.remove(CLASS_HOVER);\n if (delegateTarget) delegateTarget.classList.add(CLASS_HOVER);\n HOVER = delegateTarget;\n};\n\nconst getDelegateTarget = (event: Event) => {\n let interactive: Element | undefined;\n for (let el of event.composedPath() as HTMLElement[]) {\n if (el.nodeType !== 1) continue; // Only check elements\n if (el.nodeName === 'LABEL') el = (el as HTMLLabelElement).control || el; // If label, return the associated control\n const id = el.getAttribute(ATTR_CLICKDELEGATEFOR);\n if (id) {\n const to = getRoot(el).getElementById(id) as HTMLInputElement;\n const hasInteractive = interactive && interactive !== to;\n const isClickable = to && !hasInteractive && !to.disabled && !to.readOnly;\n return isClickable ? to : undefined; // Only return if target is not disabled or readonly\n }\n if (!interactive && isInteractive(el)) interactive = el;\n }\n};\n\nconst isInteractive = (el: HTMLElement) =>\n el.isContentEditable ||\n el.popover ||\n SKIP.has(el.nodeName) ||\n attr(el, 'role') === 'button';\n\nonHotReload('clickdelegatefor', () => [\n on(window, 'click auxclick', handleClickDelegateFor as EventListener, true), // Use capture to ensure we run before other click listeners\n on(document, 'mousemove', handleMouseMove, QUICK_EVENT), // Use passive for better performance\n]);\n"],"mappings":"4IAaA,MACM,EAAc,wBACd,EAAO,IAAI,IAAI,CACnB,IACA,SACA,UACA,SACA,QACA,QACA,SACA,UACF,CAAC,EAEK,EAA0B,GAAsB,CACpD,IAAM,EAAW,EAAM,SAAW,GAAK,EAAM,SAAW,EAAM,QACxD,EAAS,EAAkB,CAAK,EAChC,EAAiB,EAAM,OAAS,GAAK,EAAkB,CAAK,EAE9D,MAAC,GAAkB,EAAe,SAAS,CAAM,GACrD,KAAK,IAAM,KAAM,EAAgB,CAAM,EACrC,GAAK,EAAwB,UAAY,EAAgB,OAE3D,GAAI,GAAY,aAA0B,kBACxC,OAAO,OAAO,KAAK,EAAe,KAAM,IAAA,GAAW,EAAe,GAAG,EACvE,EAAM,yBAAyB,EAC/B,EAAe,MAAM,CALsC,CAM7D,EAEA,IAAI,EACA,EACJ,MAAM,EAAmB,GAAiB,CACxC,IAAM,EAAS,EAAkB,CAAK,EACtC,GAAI,CAAC,GAAU,IAAW,EAAQ,OAClC,EAAS,EACT,IAAM,EAAiB,EAAkB,CAAK,EAC1C,IAAU,IACV,GAAO,EAAM,UAAU,OAAO,CAAW,EACzC,GAAgB,EAAe,UAAU,IAAI,CAAW,EAC5D,EAAQ,EACV,EAEM,EAAqB,GAAiB,CAC1C,IAAI,EACJ,IAAK,IAAI,KAAM,EAAM,aAAa,EAAoB,CACpD,GAAI,EAAG,WAAa,EAAG,SACnB,EAAG,WAAa,UAAS,EAAM,EAAwB,SAAW,GACtE,IAAM,EAAK,EAAG,aAAa,uBAAqB,EAChD,GAAI,EAAI,CACN,IAAM,EAAK,EAAQ,CAAE,CAAC,CAAC,eAAe,CAAE,EAGxC,OADoB,GAAM,EADH,GAAe,IAAgB,IACT,CAAC,EAAG,UAAY,CAAC,EAAG,SAC5C,EAAK,IAAA,EAC5B,CACI,CAAC,GAAe,EAAc,CAAE,IAAG,EAAc,EACvD,CACF,EAEM,EAAiB,GACrB,EAAG,mBACH,EAAG,SACH,EAAK,IAAI,EAAG,QAAQ,GACpB,EAAK,EAAI,MAAM,IAAM,SAEvB,EAAY,uBAA0B,CACpC,EAAG,OAAQ,iBAAkB,EAAyC,EAAI,EAC1E,EAAG,SAAU,YAAa,EAAiB,CAAW,CACxD,CAAC"}
|
package/dist/esm/field/field.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DSElement as e,QUICK_EVENT as t,announce as n,attr as r,attrOrCSS as i,customElements as a,debounce as o,isWindows as s,on as c,onMutation as l,useId as u,warn as d}from"../utils/utils.js";const f=`aria-invalid`,
|
|
1
|
+
import{DSElement as e,QUICK_EVENT as t,announce as n,attr as r,attrOrCSS as i,customElements as a,debounce as o,isWindows as s,on as c,onMutation as l,useId as u,warn as d}from"../utils/utils.js";const f=`data-field`,p=`data-limit`,m=`aria-invalid`,h=`aria-describedby`,g=`data-indeterminate`,_=`:scope > [${f}="validation"]`,v=s()?800:200,y=e=>{let t=[],n=[],i=e._descs||[],a=!1,o=!1;e._input?.hidden&&(e._input=void 0);for(let r of e.getElementsByTagName(`*`))if(r instanceof HTMLLabelElement&&t.push(r),!r.hidden)if(C(r))e._input?.isConnected&&e._input!==r?d(`Fields should only have one input element. Use <fieldset> to group multiple fields:`,e):e._input=r;else{let t=r.getAttribute(f);t===`counter`&&(e._counter=r),t===`validation`?(n.unshift(u(r)),a=!0,o||=S(r)):t&&n.push(u(r))}if(!e._input?.isConnected)return;let s=e._input;for(let e of t)r(e,`for`,u(s)||null);let c=e.closest(`fieldset`)?.querySelector(_);c&&!c?.hidden&&(a=!0,o||=S(c),n.unshift(u(c)));let l=r(s,g);l&&(s.indeterminate=l===`true`),(s.type===`radio`||s.type===`checkbox`)&&r(e,`data-clickdelegatefor`,u(s));let p=(r(s,h)?.trim().split(/\s+/))?.filter(e=>!i.includes(e))||[];r(s,h,[...n,...p].join(` `)||null),e._descs=n;let v=e._validation;a&&!v&&!s.hasAttribute(m)?(r(s,m,o?`true`:null),e._validation=!0):!a&&v&&(r(s,m,null),e._validation=void 0),e.handleEvent()},b={over:`%d tegn for mye`,under:`%d tegn igjen`},x=o((e,t)=>{document?.activeElement===e&&n(t)},v),S=e=>{let t=e.getAttribute(`data-color`);return!t||t===`danger`},C=e=>e instanceof HTMLElement&&`validity`in e&&!(e instanceof HTMLButtonElement)&&e.type!==`hidden`;var w=class extends e{_counter;_descs;_input;_validation;_unevents;_unmutate;connectedCallback(){this._unevents=c(this,`input`,this,t),this._unmutate=l(this,()=>y(this),{attributeFilter:[f,p,`hidden`,`id`,`value`,g],attributes:!0,childList:!0,subtree:!0})}handleEvent(e){let{_counter:t,_input:n}=this;if(t?.isConnected&&n){let a=(Number(r(t,p))||0)-n.value.length,o=a<0?`over`:`under`,s=(i(t,`data-${o}`)||b[o])?.replace(`%d`,`${Math.abs(a)}`);s||d(`Missing data-${o} on:`,t),r(t,`data-label`,s),r(t,`data-state`,o),r(t,`data-color`,a<0?`danger`:null),r(n,`aria-invalid`,a<0?`true`:null),e?.type===`input`&&s&&x(n,s)}n instanceof HTMLTextAreaElement&&(n.style.setProperty(`--_ds-field-sizing`,`auto`),n.style.setProperty(`--_ds-field-sizing`,`${n.scrollHeight}px`))}disconnectedCallback(){this._unevents?.(),this._unmutate?.(),this._unevents=this._unmutate=void 0,this._input=this._counter=this._descs=this._validation=void 0}};a.define(`ds-field`,w);export{w as DSFieldElement};
|
|
2
2
|
//# sourceMappingURL=field.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.js","names":[],"sources":["../../../src/field/field.ts"],"sourcesContent":["import {\n announce,\n attr,\n attrOrCSS,\n customElements,\n DSElement,\n debounce,\n isWindows,\n on,\n onMutation,\n QUICK_EVENT,\n useId,\n warn,\n} from '../utils/utils';\n\n// TODO: Document that Validation must be hidden with \"hidden\" attribute (or completely removed from DOM), not display: none\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-field': DSFieldElement;\n }\n}\n\nconst ATTR_INVALID = 'aria-invalid';\nconst ATTR_DESCRIBEDBY = 'aria-describedby';\nconst ATTR_INDETERMINATE = 'data-indeterminate';\nconst COUNTER_DEBOUNCE = isWindows() ? 800 : 200; // Longer debounce on Windows due to NVDA performance\nconst WARNING_MULTIPLE_INPUTS = `Fields should only have one input element. Use <fieldset> to group multiple fields:`;\n\nconst handleFieldMutation = (field: DSFieldElement) => {\n const labels: HTMLLabelElement[] = [];\n const nextDescs: string[] = []; // Keep track of descriptions we are adding in this mutation\n const prevDescs = field._descs || []; // Retrieve previously managed IDs for this field\n let hasValidation = false;\n let invalid = false;\n\n if (field._input?.hidden) field._input = undefined; // Reset input if it has been hidden\n\n for (const el of field.getElementsByTagName('*')) {\n if (el instanceof HTMLLabelElement) labels.push(el);\n if ((el as HTMLElement).hidden) continue; // Skip hidden elements except labels\n if (isInputLike(el)) {\n if (field._input?.isConnected && field._input !== el)\n warn(WARNING_MULTIPLE_INPUTS, field);\n else field._input = el; // Only register if visible input\n } else {\n const type = el.getAttribute('data-field'); // Using getAttribute instead of attr for best performance\n if (type === 'counter') field._counter = el;\n if (type === 'validation') {\n nextDescs.unshift(useId(el));\n hasValidation = true;\n invalid = invalid || isInvalid(el);\n } else if (type) nextDescs.push(useId(el)); // Adds both counter and descriptions\n }\n }\n\n if (!field._input?.isConnected) return; // Do not warn about missing input as virtual DOM libraries might give false positives\n\n const input = field._input;\n for (const label of labels) attr(label, 'for', useId(input) || null);\n\n const fieldsetValidation = field\n .closest('fieldset')\n ?.querySelector<HTMLElement>(':scope > [data-field=\"validation\"]');\n\n // Connect fieldset validation to inputs\n if (fieldsetValidation && !fieldsetValidation?.hidden) {\n hasValidation = true;\n invalid = invalid || isInvalid(fieldsetValidation);\n nextDescs.unshift(useId(fieldsetValidation));\n }\n\n // Add support for data-indeterminate attribute as this normally can only be set by javascript\n\n const indeterminate = attr(input, ATTR_INDETERMINATE);\n if (indeterminate) input.indeterminate = indeterminate === 'true';\n\n // Expand click area to ds-field if radio/checkbox\n const isBoolish = input.type === 'radio' || input.type === 'checkbox';\n if (isBoolish) attr(field, 'data-clickdelegatefor', useId(input));\n\n // Setup aria-describedby, but repsect existing ids in aria-describedby\n const describedby = attr(input, ATTR_DESCRIBEDBY)?.trim().split(/\\s+/);\n const keep = describedby?.filter((id) => !prevDescs.includes(id)) || []; // Find non-ds-field-managed aria-describedby IDs\n attr(input, ATTR_DESCRIBEDBY, [...nextDescs, ...keep].join(' ') || null);\n field._descs = nextDescs;\n\n // Only manage aria-invalid when field has validation elements, and aria-invalid does not already exist\n const hadValidation = field._validation;\n if (hasValidation && !hadValidation && !input.hasAttribute(ATTR_INVALID)) {\n attr(input, ATTR_INVALID, 'true');\n field._validation = true;\n } else if (!hasValidation && hadValidation) {\n attr(input, ATTR_INVALID, null); // Remove aria-invalid\n field._validation = undefined;\n }\n\n field.handleEvent(); // Update counter and textarea sizing\n};\n\n// Used as fallback in tests when CSS is not loaded\nconst TEXTS = {\n over: '%d tegn for mye',\n under: '%d tegn igjen',\n};\n\nconst debouncedCounterLiveRegion = debounce((input: Element, text: string) => {\n if (document.activeElement === input) announce(text); // Only announce if input is still focused\n}, COUNTER_DEBOUNCE);\n\nconst isInvalid = (el: Element) => el.getAttribute('data-color') !== 'success';\nconst isInputLike = (el: unknown): el is HTMLInputElement =>\n el instanceof HTMLElement &&\n 'validity' in el && // Adds support for custom elements implemeted with attachInternals()\n !(el instanceof HTMLButtonElement) && // But skip <button> elements\n (el as HTMLInputElement).type !== 'hidden'; // And skip input type=\"hidden\"\n\n// Custom element is used to performantly keep track of fields on the page\nexport class DSFieldElement extends DSElement {\n _counter?: Element; // Using underscore instead of private fields for backwards compatibility\n _descs?: string[];\n _input?: HTMLInputElement;\n _validation?: boolean;\n _unevents?: () => void;\n _unmutate?: () => void;\n\n connectedCallback() {\n this._unevents = on(this, 'input', this, QUICK_EVENT);\n this._unmutate = onMutation(this, () => handleFieldMutation(this), {\n attributeFilter: [\n 'data-field',\n 'data-limit',\n 'hidden', // Needed to check validation visibility\n 'id', // Needed to sync label \"for\" when ID of input/selec/textarea changes\n 'value', // Needed to detect changes in controlled React inputs as they do not trigger input events\n ATTR_INDETERMINATE,\n ],\n attributes: true,\n childList: true,\n subtree: true,\n });\n }\n handleEvent(event?: Event) {\n const { _counter, _input } = this;\n\n if (_counter?.isConnected && _input) {\n const limit = Number(attr(_counter, 'data-limit')) || 0;\n const count = limit - _input.value.length;\n const state = count < 0 ? 'over' : 'under';\n const label = (attrOrCSS(_counter, `data-${state}`) || TEXTS[state]) // Browser translation tools will not pick up dynamic text anyway, so no need to use aria-labelledby here\n ?.replace('%d', `${Math.abs(count)}`);\n\n if (!label) warn(`Missing data-${state} on:`, _counter);\n attr(_counter, 'data-label', label); // Using attribute to prevent hydration errors, not using aria-label to make axe tests happy\n attr(_counter, 'data-state', state);\n attr(_counter, 'data-color', count < 0 ? 'danger' : null);\n\n // Only update live region when user is actually typing\n if (event?.type === 'input' && label)\n debouncedCounterLiveRegion(_input, label); // Debounce live region to avoid NVDA interupting announcing typed text\n }\n if (_input instanceof HTMLTextAreaElement) {\n _input.style.setProperty('--_ds-field-sizing', 'auto');\n _input.style.setProperty(\n '--_ds-field-sizing',\n `${_input.scrollHeight}px`,\n );\n }\n }\n disconnectedCallback() {\n this._unevents?.();\n this._unmutate?.();\n this._unevents = this._unmutate = undefined;\n this._input = this._counter = this._descs = this._validation = undefined;\n }\n}\n\ncustomElements.define('ds-field', DSFieldElement);\n"],"mappings":"oMAsBA,MAAM,EAAe,eACf,EAAmB,mBACnB,EAAqB,qBACrB,EAAmB,EAAU,EAAI,IAAM,IAGvC,EAAuB,GAA0B,CACrD,IAAM,EAA6B,CAAC,EAC9B,EAAsB,CAAC,EACvB,EAAY,EAAM,QAAU,CAAC,EAC/B,EAAgB,GAChB,EAAU,GAEV,EAAM,QAAQ,SAAQ,EAAM,OAAS,IAAA,IAEzC,IAAK,IAAM,KAAM,EAAM,qBAAqB,GAAG,EAC7C,GAAI,aAAc,kBAAkB,EAAO,KAAK,CAAE,EAC7C,GAAmB,OACxB,GAAI,EAAY,CAAE,EACZ,EAAM,QAAQ,aAAe,EAAM,SAAW,EAChD,EAAK,sFAAyB,CAAK,EAChC,EAAM,OAAS,MACf,CACL,IAAM,EAAO,EAAG,aAAa,YAAY,EACrC,IAAS,YAAW,EAAM,SAAW,GACrC,IAAS,cACX,EAAU,QAAQ,EAAM,CAAE,CAAC,EAC3B,EAAgB,GAChB,IAAqB,EAAU,CAAE,GACxB,GAAM,EAAU,KAAK,EAAM,CAAE,CAAC,CAC3C,CAGF,GAAI,CAAC,EAAM,QAAQ,YAAa,OAEhC,IAAM,EAAQ,EAAM,OACpB,IAAK,IAAM,KAAS,EAAQ,EAAK,EAAO,MAAO,EAAM,CAAK,GAAK,IAAI,EAEnE,IAAM,EAAqB,EACxB,QAAQ,UAAU,CAAC,EAClB,cAA2B,oCAAoC,EAG/D,GAAsB,CAAC,GAAoB,SAC7C,E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A,YAAY,EAAe,CACzB,GAAM,CAAE,WAAU,UAAW,KAE7B,GAAI,GAAU,aAAe,EAAQ,CAEnC,IAAM,GADQ,OAAO,EAAK,EAAU,YAAY,CAAC,GAAK,GAChC,EAAO,MAAM,OAC7B,EAAQ,EAAQ,EAAI,OAAS,QAC7B,GAAS,EAAU,EAAU,QAAQ,GAAO,GAAK,EAAM,GAAA,EACzD,QAAQ,KAAM,GAAG,KAAK,IAAI,CAAK,GAAG,EAEjC,GAAO,EAAK,gBAAgB,EAAM,MAAO,CAAQ,EACtD,EAAK,EAAU,aAAc,CAAK,EAClC,EAAK,EAAU,aAAc,CAAK,EAClC,EAAK,EAAU,aAAc,EAAQ,EAAI,SAAW,IAAI,EAGpD,GAAO,OAAS,SAAW,GAC7B,EAA2B,EAAQ,CAAK,CAC5C,CACI,aAAkB,sBACpB,EAAO,MAAM,YAAY,qBAAsB,MAAM,EACrD,EAAO,MAAM,YACX,qBACA,GAAG,EAAO,aAAa,GACzB,EAEJ,CACA,sBAAuB,CACrB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,UAAY,KAAK,UAAY,IAAA,GAClC,KAAK,OAAS,KAAK,SAAW,KAAK,OAAS,KAAK,YAAc,IAAA,EACjE,CACF,EAEA,EAAe,OAAO,WAAY,CAAc"}
|
|
1
|
+
{"version":3,"file":"field.js","names":[],"sources":["../../../src/field/field.ts"],"sourcesContent":["import {\n announce,\n attr,\n attrOrCSS,\n customElements,\n DSElement,\n debounce,\n isWindows,\n on,\n onMutation,\n QUICK_EVENT,\n useId,\n warn,\n} from '../utils/utils';\n\n// TODO: Document that Validation must be hidden with \"hidden\" attribute (or completely removed from DOM), not display: none\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-field': DSFieldElement;\n }\n}\n\nconst ATTR_FIELD = 'data-field';\nconst ATTR_LIMIT = 'data-limit';\nconst ATTR_INVALID = 'aria-invalid';\nconst ATTR_DESCRIBEDBY = 'aria-describedby';\nconst ATTR_INDETERMINATE = 'data-indeterminate';\nconst SELECTOR_VALIDATION = `:scope > [${ATTR_FIELD}=\"validation\"]`;\nconst COUNTER_DEBOUNCE = isWindows() ? 800 : 200; // Longer debounce on Windows due to NVDA performance\nconst WARNING_MULTIPLE_INPUTS = `Fields should only have one input element. Use <fieldset> to group multiple fields:`;\n\nconst handleFieldMutation = (field: DSFieldElement) => {\n const labels: HTMLLabelElement[] = [];\n const nextDescs: string[] = []; // Keep track of descriptions we are adding in this mutation\n const prevDescs = field._descs || []; // Retrieve previously managed IDs for this field\n let hasValidation = false;\n let invalid = false;\n\n if (field._input?.hidden) field._input = undefined; // Reset input if it has been hidden\n\n for (const el of field.getElementsByTagName('*')) {\n if (el instanceof HTMLLabelElement) labels.push(el);\n if ((el as HTMLElement).hidden) continue; // Skip hidden elements except labels\n if (isInputLike(el)) {\n if (field._input?.isConnected && field._input !== el)\n warn(WARNING_MULTIPLE_INPUTS, field);\n else field._input = el; // Only register if visible input\n } else {\n const type = el.getAttribute(ATTR_FIELD); // Using getAttribute instead of attr for best performance\n if (type === 'counter') field._counter = el;\n if (type === 'validation') {\n nextDescs.unshift(useId(el));\n hasValidation = true;\n invalid = invalid || isInvalidColor(el);\n } else if (type) nextDescs.push(useId(el)); // Adds both counter and descriptions\n }\n }\n\n if (!field._input?.isConnected) return; // Do not warn about missing input as virtual DOM libraries might give false positives\n\n const input = field._input;\n for (const label of labels) attr(label, 'for', useId(input) || null);\n\n const fieldsetValidation = field\n .closest('fieldset')\n ?.querySelector<HTMLElement>(SELECTOR_VALIDATION);\n\n // Connect fieldset validation to inputs\n if (fieldsetValidation && !fieldsetValidation?.hidden) {\n hasValidation = true;\n invalid = invalid || isInvalidColor(fieldsetValidation);\n nextDescs.unshift(useId(fieldsetValidation));\n }\n\n // Add support for data-indeterminate attribute as this normally can only be set by javascript\n\n const indeterminate = attr(input, ATTR_INDETERMINATE);\n if (indeterminate) input.indeterminate = indeterminate === 'true';\n\n // Expand click area to ds-field if radio/checkbox\n const isBoolish = input.type === 'radio' || input.type === 'checkbox';\n if (isBoolish) attr(field, 'data-clickdelegatefor', useId(input));\n\n // Setup aria-describedby, but repsect existing ids in aria-describedby\n const describedby = attr(input, ATTR_DESCRIBEDBY)?.trim().split(/\\s+/);\n const keep = describedby?.filter((id) => !prevDescs.includes(id)) || []; // Find non-ds-field-managed aria-describedby IDs\n attr(input, ATTR_DESCRIBEDBY, [...nextDescs, ...keep].join(' ') || null);\n field._descs = nextDescs;\n\n // Only manage aria-invalid when field has validation elements, and aria-invalid does not already exist\n const hadValidation = field._validation;\n if (hasValidation && !hadValidation && !input.hasAttribute(ATTR_INVALID)) {\n attr(input, ATTR_INVALID, invalid ? 'true' : null);\n field._validation = true;\n } else if (!hasValidation && hadValidation) {\n attr(input, ATTR_INVALID, null); // Remove aria-invalid\n field._validation = undefined;\n }\n\n field.handleEvent(); // Update counter and textarea sizing\n};\n\n// Used as fallback in tests when CSS is not loaded\nconst TEXTS = {\n over: '%d tegn for mye',\n under: '%d tegn igjen',\n};\n\nconst debouncedCounterLiveRegion = debounce((input: Element, text: string) => {\n // Using document?. as this function might run after document is unmounted by tests\n if (document?.activeElement === input) announce(text); // Only announce if input is still focused\n}, COUNTER_DEBOUNCE);\n\nconst isInvalidColor = (el: Element) => {\n const color = el.getAttribute('data-color');\n return !color || color === 'danger';\n};\nconst isInputLike = (el: unknown): el is HTMLInputElement =>\n el instanceof HTMLElement &&\n 'validity' in el && // Adds support for custom elements implemeted with attachInternals()\n !(el instanceof HTMLButtonElement) && // But skip <button> elements\n (el as HTMLInputElement).type !== 'hidden'; // And skip input type=\"hidden\"\n\n// Custom element is used to performantly keep track of fields on the page\nexport class DSFieldElement extends DSElement {\n _counter?: Element; // Using underscore instead of private fields for backwards compatibility\n _descs?: string[];\n _input?: HTMLInputElement;\n _validation?: boolean;\n _unevents?: () => void;\n _unmutate?: () => void;\n\n connectedCallback() {\n this._unevents = on(this, 'input', this, QUICK_EVENT);\n this._unmutate = onMutation(this, () => handleFieldMutation(this), {\n attributeFilter: [\n ATTR_FIELD,\n ATTR_LIMIT,\n 'hidden', // Needed to check validation visibility\n 'id', // Needed to sync label \"for\" when ID of input/selec/textarea changes\n 'value', // Needed to detect changes in controlled React inputs as they do not trigger input events\n ATTR_INDETERMINATE,\n ],\n attributes: true,\n childList: true,\n subtree: true,\n });\n }\n handleEvent(event?: Event) {\n const { _counter, _input } = this;\n\n if (_counter?.isConnected && _input) {\n const limit = Number(attr(_counter, ATTR_LIMIT)) || 0;\n const count = limit - _input.value.length;\n const state = count < 0 ? 'over' : 'under';\n const label = (attrOrCSS(_counter, `data-${state}`) || TEXTS[state]) // Browser translation tools will not pick up dynamic text anyway, so no need to use aria-labelledby here\n ?.replace('%d', `${Math.abs(count)}`);\n\n if (!label) warn(`Missing data-${state} on:`, _counter);\n attr(_counter, 'data-label', label); // Using attribute to prevent hydration errors, not using aria-label to make axe tests happy\n attr(_counter, 'data-state', state);\n attr(_counter, 'data-color', count < 0 ? 'danger' : null);\n attr(_input, 'aria-invalid', count < 0 ? 'true' : null); // Toggle aria-invalid of textarea\n\n // Only update live region when user is actually typing\n if (event?.type === 'input' && label)\n debouncedCounterLiveRegion(_input, label); // Debounce live region to avoid NVDA interupting announcing typed text\n }\n if (_input instanceof HTMLTextAreaElement) {\n _input.style.setProperty('--_ds-field-sizing', 'auto');\n _input.style.setProperty(\n '--_ds-field-sizing',\n `${_input.scrollHeight}px`,\n );\n }\n }\n disconnectedCallback() {\n this._unevents?.();\n this._unmutate?.();\n this._unevents = this._unmutate = undefined;\n this._input = this._counter = this._descs = this._validation = undefined;\n }\n}\n\ncustomElements.define('ds-field', DSFieldElement);\n"],"mappings":"oMAsBA,MAAM,EAAa,aACb,EAAa,aACb,EAAe,eACf,EAAmB,mBACnB,EAAqB,qBACrB,EAAsB,aAAa,EAAW,gBAC9C,EAAmB,EAAU,EAAI,IAAM,IAGvC,EAAuB,GAA0B,CACrD,IAAM,EAA6B,CAAC,EAC9B,EAAsB,CAAC,EACvB,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,aAAc,EAAQ,EAAI,SAAW,IAAI,EACxD,EAAK,EAAQ,eAAgB,EAAQ,EAAI,OAAS,IAAI,EAGlD,GAAO,OAAS,SAAW,GAC7B,EAA2B,EAAQ,CAAK,CAC5C,CACI,aAAkB,sBACpB,EAAO,MAAM,YAAY,qBAAsB,MAAM,EACrD,EAAO,MAAM,YACX,qBACA,GAAG,EAAO,aAAa,GACzB,EAEJ,CACA,sBAAuB,CACrB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,UAAY,KAAK,UAAY,IAAA,GAClC,KAAK,OAAS,KAAK,SAAW,KAAK,OAAS,KAAK,YAAc,IAAA,EACjE,CACF,EAEA,EAAe,OAAO,WAAY,CAAc"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ARIA_LABELLEDBY as e,attr as t,isBrowser as n,onHotReload as r,onMutation as i,useId as a}from"../utils/utils.js";const o=n()?document.getElementsByTagName(`fieldset`):[],s=()=>{for(let n of o){if(n.hasAttribute(`aria-labelledby`))continue;let r
|
|
1
|
+
import{ARIA_LABELLEDBY as e,attr as t,isBrowser as n,onHotReload as r,onMutation as i,useId as a}from"../utils/utils.js";const o=n()?document.getElementsByTagName(`fieldset`):[],s=()=>{for(let n of o){if(n.hasAttribute(`aria-labelledby`))continue;let r=``;for(let e of n.children){let t=e.nodeName;(t===`LEGEND`||e.getAttribute(`data-field`)===`description`||t===`P`&&e.previousElementSibling?.nodeName===`LEGEND`)&&(r+=`${a(e)} `)}t(n,e,r.trim()||null)}};r(`fieldset`,()=>[i(document,s,{childList:!0,subtree:!0})]);
|
|
2
2
|
//# sourceMappingURL=fieldset.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldset.js","names":[],"sources":["../../../src/fieldset/fieldset.ts"],"sourcesContent":["import {\n ARIA_LABELLEDBY,\n attr,\n isBrowser,\n onHotReload,\n onMutation,\n useId,\n} from '../utils/utils';\n\nconst FIELDSETS = isBrowser() ? document.getElementsByTagName('fieldset') : [];\n\n// NOTE:\n// <fieldset> descriptions should be accessible to screen reader users. However, using aria-describedby\n// on <fieldset> causes all child <input> elements to inherit the same description, resulting in redundant and confusing announcements.\n// To avoid this, we use aria-labelledby to reference both the legend and the description.\n// aria-labelledby is only announced when screen readers enter the fieldset, not when navigating its child elements.\n// This means the accessible name of <fieldset> includes both the legend and description, which may differ from some test expectations,\n// but as of March 2026, this approach provides the best user experience across assistive technologies.\n// This approach is also verified by the chief of accessibility at NRK and the accessibility expert at NAV\nconst handleFieldsetMutations = () => {\n for (const
|
|
1
|
+
{"version":3,"file":"fieldset.js","names":[],"sources":["../../../src/fieldset/fieldset.ts"],"sourcesContent":["import {\n ARIA_LABELLEDBY,\n attr,\n isBrowser,\n onHotReload,\n onMutation,\n useId,\n} from '../utils/utils';\n\nconst FIELDSETS = isBrowser() ? document.getElementsByTagName('fieldset') : [];\n\n// NOTE:\n// <fieldset> descriptions should be accessible to screen reader users. However, using aria-describedby\n// on <fieldset> causes all child <input> elements to inherit the same description, resulting in redundant and confusing announcements.\n// To avoid this, we use aria-labelledby to reference both the legend and the description.\n// aria-labelledby is only announced when screen readers enter the fieldset, not when navigating its child elements.\n// This means the accessible name of <fieldset> includes both the legend and description, which may differ from some test expectations,\n// but as of March 2026, this approach provides the best user experience across assistive technologies.\n// This approach is also verified by the chief of accessibility at NRK and the accessibility expert at NAV\nconst handleFieldsetMutations = () => {\n for (const fieldset of FIELDSETS) {\n if (fieldset.hasAttribute(ARIA_LABELLEDBY)) continue; // Speed up by skipping labelled fieldsets\n\n let labelledby = '';\n for (const el of fieldset.children) {\n const name = el.nodeName;\n const isLegendOrDescription =\n name === 'LEGEND' ||\n el.getAttribute('data-field') === 'description' ||\n (name === 'P' && el.previousElementSibling?.nodeName === 'LEGEND'); // Backwards compatibility\n\n if (isLegendOrDescription) labelledby += `${useId(el)} `;\n }\n attr(fieldset, ARIA_LABELLEDBY, labelledby.trim() || null);\n }\n};\n\nonHotReload('fieldset', () => [\n onMutation(document, handleFieldsetMutations, {\n childList: true,\n subtree: true,\n }),\n]);\n"],"mappings":"yHASA,MAAM,EAAY,EAAU,EAAI,SAAS,qBAAqB,UAAU,EAAI,CAAC,EAUvE,MAAgC,CACpC,IAAK,IAAM,KAAY,EAAW,CAChC,GAAI,EAAS,aAAA,iBAA4B,EAAG,SAE5C,IAAI,EAAa,GACjB,IAAK,IAAM,KAAM,EAAS,SAAU,CAClC,IAAM,EAAO,EAAG,UAEd,IAAS,UACT,EAAG,aAAa,YAAY,IAAM,eACjC,IAAS,KAAO,EAAG,wBAAwB,WAAa,YAEhC,GAAc,GAAG,EAAM,CAAE,EAAE,GACxD,CACA,EAAK,EAAU,EAAiB,EAAW,KAAK,GAAK,IAAI,CAC3D,CACF,EAEA,EAAY,eAAkB,CAC5B,EAAW,SAAU,EAAyB,CAC5C,UAAW,GACX,QAAS,EACX,CAAC,CACH,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=`1.
|
|
1
|
+
var e=`1.20.1`;export{e as version};
|
|
2
2
|
//# sourceMappingURL=package.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{QUICK_EVENT as e,attr as t,getCSSProp as n,getComposedTarget as r,getRoot as i,isBrowser as a,on as o,onHotReload as s}from"../utils/utils.js";import{apply as c,isPolyfilled as l,isSupported as u}from"../_vendors/@oddbird/popover-polyfill/dist/popover-fn.js";import{autoUpdate as d,computePosition as f,flip as p,limitShift as m,offset as h,shift as g,size as _}from"@floating-ui/dom";a()&&!u()&&!l()&&c({layerName:`ds.base`});const v=new Map,y=`data-placement`,b=`data-autoplacement`,x=new Map,S=e=>C(r(e),e.newState,e.oldState,e.source||e.detail);function C(e,r,a,o){let s=e instanceof HTMLElement&&t(e,`popover`)!==null&&n(e,`--_ds-floating`),c=x.get(e);if(r===`open`&&c&&c.source===o||(c?.cleanup(),r===`closed`||!s))return;if(!o){let t=e.id&&`[popovertarget="${e.id}"],[commandfor="${e.id}"]`;o=t&&i(e).querySelector(t)||void 0}if(!o||o===e||a&&a===r)return;e.style.scrollMarginBottom=`var(--_ds-floating-arrow-size)`;let l=n(e,`--_ds-floating-overscroll`),u=t(e,y)||t(o,y)||s,v=t(e,b)||t(o,b),S=parseFloat(n(e,`scroll-margin-bottom`))||0,C=u.match(/left|right/gi)?`Height`:`Width`,w=o[`offset${C}`]/2+S;if(u===`none`)return;let T={strategy:`absolute`,placement:u,middleware:[h(S),g({padding:10,limiter:m({offset:{mainAxis:w}})}),D(),...v===`false`?[]:[p({padding:10,crossAxis:!1})],...l?[_({apply({availableHeight:t}){
|
|
1
|
+
import{QUICK_EVENT as e,attr as t,getCSSProp as n,getComposedTarget as r,getRoot as i,isBrowser as a,on as o,onHotReload as s}from"../utils/utils.js";import{apply as c,isPolyfilled as l,isSupported as u}from"../_vendors/@oddbird/popover-polyfill/dist/popover-fn.js";import{autoUpdate as d,computePosition as f,flip as p,limitShift as m,offset as h,shift as g,size as _}from"@floating-ui/dom";a()&&!u()&&!l()&&c({layerName:`ds.base`});const v=new Map,y=`data-placement`,b=`data-autoplacement`,x=new Map,S=e=>C(r(e),e.newState,e.oldState,e.source||e.detail);function C(e,r,a,o){let s=e instanceof HTMLElement&&t(e,`popover`)!==null&&n(e,`--_ds-floating`),c=x.get(e);if(r===`open`&&c&&c.source===o||(c?.cleanup(),r===`closed`||!s))return;if(!o){let t=e.id&&`[popovertarget="${e.id}"],[commandfor="${e.id}"]`;o=t&&i(e).querySelector(t)||void 0}if(!o||o===e||a&&a===r)return;e.style.scrollMarginBottom=`var(--_ds-floating-arrow-size)`;let l=n(e,`--_ds-floating-overscroll`),u=t(e,y)||t(o,y)||s,v=t(e,b)||t(o,b),S=parseFloat(n(e,`scroll-margin-bottom`))||0,C=u.match(/left|right/gi)?`Height`:`Width`,w=o[`offset${C}`]/2+S;if(u===`none`)return;let T=!1,E={strategy:`absolute`,placement:u,middleware:[h(S),g({padding:10,limiter:m({offset:{mainAxis:w}})}),D(),...v===`false`?[]:[p({padding:10,crossAxis:!1})],...l?[_({apply({availableHeight:t}){if(T)return;T=!0;let n=`${o.offsetWidth}px`,r=`${Math.max(50,t-20)}px`;requestAnimationFrame(()=>{l===`fit`&&e.style.width!==n&&(e.style.width=n),e.style.maxHeight!==r&&(e.style.maxHeight=r)})}})]:[]]},O=d(o,e,async()=>{if(!o?.isConnected)return x.get(e)?.cleanup();let{x:t,y:n}=await f(o,e,E);e.style.translate=`${t}px ${n}px`});x.set(e,{source:o,cleanup:()=>x.delete(e)&&O()})}let w;const T=e=>{if(e.type===`pointerdown`&&(w=!1),e.type===`scroll`&&w===!1&&(w=!0),e.type===`pointerup`&&w)for(let[e]of x)e.showPopover()},E=t=>{for(let[e,t]of v)!e.host?.isConnected&&v.delete(e)&&t();let n=i(r(t));n instanceof ShadowRoot&&!v.has(n)&&v.set(n,o(n,`toggle`,S,e))};s(`popover`,()=>{let t=Object.getOwnPropertyDescriptors(HTMLElement.prototype),n=HTMLElement.prototype.togglePopover,r=HTMLElement.prototype.showPopover,i=HTMLElement.prototype.hidePopover;return Object.defineProperties(HTMLElement.prototype,{togglePopover:{...t.togglePopover,value(e){let t=this.matches(`:popover-open`),r=typeof e==`boolean`,i=t?`open`:`closed`,a=(r?e:e?.force??!t)?`open`:`closed`,o=r?void 0:e?.source,s=n?.call(this,e);return C(this,a,i,o),s}},showPopover:{...t.showPopover,value(e){let t=this.matches(`:popover-open`)?`open`:`closed`,n=r?.call(this,e);return C(this,`open`,t,e?.source),n}},hidePopover:{...t.hidePopover,value(){let e=this.matches(`:popover-open`)?`open`:`closed`,t=i?.call(this);return C(this,`closed`,e),t}}}),[o(document,`click`,E,e),o(document,`pointerdown pointerup scroll`,T,e),o(document,`toggle ds-toggle-source`,S,e),()=>{Object.defineProperties(HTMLElement.prototype,{togglePopover:{...t.togglePopover,value:n},showPopover:{...t.showPopover,value:r},hidePopover:{...t.hidePopover,value:i}});for(let[,e]of v)e();v.clear()}]});const D=()=>({name:`arrowPseudo`,fn(e){let n=e.elements.floating,r=e.rects.reference,i=`${Math.round(r.width/2+r.x-e.x)}px`,a=`${Math.round(r.height/2+r.y-e.y)}px`;return n.style.setProperty(`--_ds-floating-arrow-x`,i),n.style.setProperty(`--_ds-floating-arrow-y`,a),t(n,`data-floating`,e.placement),e}});
|
|
2
2
|
//# sourceMappingURL=popover.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover.js","names":[],"sources":["../../../src/popover/popover.ts"],"sourcesContent":["import type { ComputePositionConfig, MiddlewareState } from '@floating-ui/dom';\nimport {\n autoUpdate,\n computePosition,\n flip,\n limitShift,\n offset,\n shift,\n size,\n} from '@floating-ui/dom';\nimport {\n isPolyfilled,\n isSupported,\n apply as polyfillPopover,\n} from '@oddbird/popover-polyfill/fn';\nimport {\n attr,\n getComposedTarget,\n getCSSProp,\n getRoot,\n isBrowser,\n on,\n onHotReload,\n QUICK_EVENT,\n} from '../utils/utils';\n\nif (isBrowser() && !isSupported() && !isPolyfilled())\n polyfillPopover({ layerName: 'ds.base' }); // Load popover polyfill in the ds.base CSS layer to keep cascade order consistent with Designsystemet layers.\n\n// NOTE:\n// The native popover event \"toggle\" is not composed, meaning it does not bubble out of shadow DOM.\n// This means that if a popover is inside a shadow root, the toggle event will not be visible outside of that shadow root.\n// To handle this, we monkey-patch the showPopover and hidePopover methods to manually trigger the toggle-function.\n// We also bind toggle events to shadow roots found during click events, so that we can listen for toggle events on shadow roots as well.\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'ds-toggle-source': CustomEvent<Element>;\n }\n}\n\nconst ROOTS = new Map<ShadowRoot, () => void>();\nconst ATTR_PLACE = 'data-placement';\nconst ATTR_AUTO = 'data-autoplacement';\nconst POPOVERS = new Map<\n HTMLElement,\n { source: Element; cleanup: () => void }\n>();\n\n// Sometimes use \"ds-toggle\" event while waiting for better support of\n// event.source (https://developer.mozilla.org/en-US/docs/Web/API/ToggleEvent/source)\n\nconst handleToggle = (\n e: Event &\n Partial<ToggleEvent> & { detail?: HTMLElement; source?: HTMLElement },\n) => toggle(getComposedTarget(e), e.newState, e.oldState, e.source || e.detail);\n\nfunction toggle(\n el: Element | null,\n newState?: string,\n oldState?: string,\n source?: HTMLElement,\n) {\n const isPopover = el instanceof HTMLElement && attr(el, 'popover') !== null;\n const float = isPopover && getCSSProp(el, '--_ds-floating');\n const prev = POPOVERS.get(el as HTMLElement);\n\n if (newState === 'open' && prev && prev.source === source) return; // Prevent double binding\n prev?.cleanup(); // Cleanup if previously bound popover exists to avoid multiple autoUpdate memory leaks\n if (newState === 'closed' || !float) return;\n if (!source) {\n const css = el.id && `[popovertarget=\"${el.id}\"],[commandfor=\"${el.id}\"]`;\n source = (css && getRoot(el).querySelector<HTMLElement>(css)) || undefined; // Polyfill ToggleEvent .source for older browsers\n }\n if (!source || source === el || (oldState && oldState === newState)) return; // No need to update\n\n // Use scroll-margin-bottom to measure computed arrow-size property as this does\n // not affect layout or position, makes the browser calculate the pixel value instead\n // of returning the calc() (as it would if reading the --_ds-floating-arrow-size directly)\n // and makes it possible to read the value even if ::before is not used to draw the arrow.\n el.style.scrollMarginBottom = `var(--_ds-floating-arrow-size)`;\n\n const padding = 10;\n const overscroll = getCSSProp(el, '--_ds-floating-overscroll');\n const placement = attr(el, ATTR_PLACE) || attr(source, ATTR_PLACE) || float;\n const auto = attr(el, ATTR_AUTO) || attr(source, ATTR_AUTO);\n const arrowSize = parseFloat(getCSSProp(el, 'scroll-margin-bottom')) || 0;\n const shiftProp = placement.match(/left|right/gi) ? 'Height' : 'Width';\n const shiftLimit = source[`offset${shiftProp}`] / 2 + arrowSize;\n\n if (placement === 'none') return; // No need to position\n\n const options = {\n strategy: 'absolute',\n placement,\n middleware: [\n offset(arrowSize),\n shift({\n padding,\n limiter: limitShift({ offset: { mainAxis: shiftLimit } }), // Prevent from shifing away from source\n }),\n arrowPseudo(),\n ...(auto !== 'false' ? [flip({ padding, crossAxis: false })] : []),\n ...(overscroll\n ? [\n size({\n apply({ availableHeight }) {\n if (overscroll === 'fit')\n el.style.width = `${source.offsetWidth}px`; // Use offsetWidth to include padding, matching the width of the source element\n el.style.maxHeight = `${Math.max(50, availableHeight - padding * 2)}px`;\n },\n }),\n ]\n : []),\n ],\n } as ComputePositionConfig;\n const unfloat = autoUpdate(source, el, async () => {\n if (!source?.isConnected) return POPOVERS.get(el)?.cleanup(); // Cleanup if source element is removed\n const { x, y } = await computePosition(source, el, options);\n el.style.translate = `${x}px ${y}px`;\n });\n POPOVERS.set(el, {\n source,\n cleanup: () => POPOVERS.delete(el) && unfloat(),\n });\n}\n\n// Prevent closing when pointer interacts with scrollbar\nlet IS_SCROLL: boolean | undefined;\nconst handleScrollbar = (e: Event) => {\n if (e.type === 'pointerdown') {\n IS_SCROLL = false;\n }\n if (e.type === 'scroll' && IS_SCROLL === false) IS_SCROLL = true;\n if (e.type === 'pointerup' && IS_SCROLL)\n for (const [popover] of POPOVERS) popover.showPopover(); // Immediately show again to prevent flicker\n};\n\n// And add listeners for toggle event on shadowRoots as \"toggle\" is not a composed event\nconst handleClick = (e: Event) => {\n for (const [root, off] of ROOTS)\n if (!root.host?.isConnected && ROOTS.delete(root)) off(); // Prune roots whose host is no longer connected (e.g. removed custom elements) to avoid unbounded growth\n\n const root = getRoot(getComposedTarget(e));\n if (root instanceof ShadowRoot && !ROOTS.has(root))\n ROOTS.set(root, on(root, 'toggle', handleToggle, QUICK_EVENT));\n};\n\nonHotReload('popover', () => {\n const isFunction = (fn: unknown) => typeof fn === 'function';\n const togglePopover = HTMLElement.prototype.togglePopover;\n const showPopover = HTMLElement.prototype.showPopover;\n const hidePopover = HTMLElement.prototype.hidePopover;\n\n // Since toggle event is not composed, we need to trigger it when programatically called inside shadow DOM\n if (isFunction(togglePopover))\n HTMLElement.prototype.togglePopover = function (opt) {\n const isOpen = this.matches(':popover-open');\n const isBool = typeof opt === 'boolean';\n const prev = isOpen ? 'open' : 'closed';\n const next = (isBool ? opt : (opt?.force ?? !isOpen)) ? 'open' : 'closed';\n const source = isBool ? undefined : opt?.source;\n const result = togglePopover.call(this, opt as TogglePopoverOptions);\n toggle(this, next, prev, source);\n return result;\n };\n if (isFunction(showPopover))\n HTMLElement.prototype.showPopover = function (opt) {\n const prev = this.matches(':popover-open') ? 'open' : 'closed';\n const result = showPopover.call(this, opt);\n toggle(this, 'open', prev, opt?.source);\n return result;\n };\n if (isFunction(hidePopover))\n HTMLElement.prototype.hidePopover = function () {\n const prev = this.matches(':popover-open') ? 'open' : 'closed';\n const result = hidePopover.call(this);\n toggle(this, 'closed', prev);\n return result;\n };\n\n return [\n on(document, 'click', handleClick, QUICK_EVENT),\n on(document, 'pointerdown pointerup scroll', handleScrollbar, QUICK_EVENT),\n on(document, 'toggle ds-toggle-source', handleToggle, QUICK_EVENT), // Use capture since the toggle event does not bubble\n () => {\n HTMLElement.prototype.togglePopover = togglePopover; // Restore original methods on hot reload\n HTMLElement.prototype.showPopover = showPopover;\n HTMLElement.prototype.hidePopover = hidePopover;\n for (const [, off] of ROOTS) off(); // Cleanup listeners on ShadowRoots on hot reload\n ROOTS.clear();\n },\n ];\n});\n\nconst arrowPseudo = () => ({\n name: 'arrowPseudo',\n fn(data: MiddlewareState) {\n const target = data.elements.floating;\n const source = data.rects.reference;\n const x = `${Math.round(source.width / 2 + source.x - data.x)}px`;\n const y = `${Math.round(source.height / 2 + source.y - data.y)}px`;\n\n target.style.setProperty('--_ds-floating-arrow-x', x);\n target.style.setProperty('--_ds-floating-arrow-y', y);\n attr(target, 'data-floating', data.placement);\n return data;\n },\n});\n"],"mappings":"wYA0BI,EAAU,GAAK,CAAC,EAAY,GAAK,CAAC,EAAa,GACjD,EAAgB,CAAE,UAAW,SAAU,CAAC,EAc1C,MAAM,EAAQ,IAAI,IACZ,EAAa,iBACb,EAAY,qBACZ,EAAW,IAAI,IAQf,EACJ,GAEG,EAAO,EAAkB,CAAC,EAAG,EAAE,SAAU,EAAE,SAAU,EAAE,QAAU,EAAE,MAAM,EAE9E,SAAS,EACP,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EAEnE,OADA,EAAO,KAAM,EAAM,EAAM,CAAM,EACxB,CACT,GACE,EAAW,CAAW,IACxB,YAAY,UAAU,YAAc,SAAU,EAAK,CACjD,IAAM,EAAO,KAAK,QAAQ,eAAe,EAAI,OAAS,SAChD,EAAS,EAAY,KAAK,KAAM,CAAG,EAEzC,OADA,EAAO,KAAM,OAAQ,EAAM,GAAK,MAAM,EAC/B,CACT,GACE,EAAW,CAAW,IACxB,YAAY,UAAU,YAAc,UAAY,CAC9C,IAAM,EAAO,KAAK,QAAQ,eAAe,EAAI,OAAS,SAChD,EAAS,EAAY,KAAK,IAAI,EAEpC,OADA,EAAO,KAAM,SAAU,CAAI,EACpB,CACT,GAEK,CACL,EAAG,SAAU,QAAS,EAAa,CAAW,EAC9C,EAAG,SAAU,+BAAgC,EAAiB,CAAW,EACzE,EAAG,SAAU,0BAA2B,EAAc,CAAW,MAC3D,CACJ,YAAY,UAAU,cAAgB,EACtC,YAAY,UAAU,YAAc,EACpC,YAAY,UAAU,YAAc,EACpC,IAAK,GAAM,EAAG,KAAQ,EAAO,EAAI,EACjC,EAAM,MAAM,CACd,CACF,CACF,CAAC,EAED,MAAM,OAAqB,CACzB,KAAM,cACN,GAAG,EAAuB,CACxB,IAAM,EAAS,EAAK,SAAS,SACvB,EAAS,EAAK,MAAM,UACpB,EAAI,GAAG,KAAK,MAAM,EAAO,MAAQ,EAAI,EAAO,EAAI,EAAK,CAAC,EAAE,IACxD,EAAI,GAAG,KAAK,MAAM,EAAO,OAAS,EAAI,EAAO,EAAI,EAAK,CAAC,EAAE,IAK/D,OAHA,EAAO,MAAM,YAAY,yBAA0B,CAAC,EACpD,EAAO,MAAM,YAAY,yBAA0B,CAAC,EACpD,EAAK,EAAQ,gBAAiB,EAAK,SAAS,EACrC,CACT,CACF"}
|
|
1
|
+
{"version":3,"file":"popover.js","names":[],"sources":["../../../src/popover/popover.ts"],"sourcesContent":["import type { ComputePositionConfig, MiddlewareState } from '@floating-ui/dom';\nimport {\n autoUpdate,\n computePosition,\n flip,\n limitShift,\n offset,\n shift,\n size,\n} from '@floating-ui/dom';\nimport {\n isPolyfilled,\n isSupported,\n apply as polyfillPopover,\n} from '@oddbird/popover-polyfill/fn';\nimport {\n attr,\n getComposedTarget,\n getCSSProp,\n getRoot,\n isBrowser,\n on,\n onHotReload,\n QUICK_EVENT,\n} from '../utils/utils';\n\nif (isBrowser() && !isSupported() && !isPolyfilled()) {\n polyfillPopover({ layerName: 'ds.base' }); // Load popover polyfill in the ds.base CSS layer to keep cascade order consistent with Designsystemet layers.\n}\n\n// NOTE:\n// The native popover event \"toggle\" is not composed, meaning it does not bubble out of shadow DOM.\n// This means that if a popover is inside a shadow root, the toggle event will not be visible outside of that shadow root.\n// To handle this, we monkey-patch the showPopover and hidePopover methods to manually trigger the toggle-function.\n// We also bind toggle events to shadow roots found during click events, so that we can listen for toggle events on shadow roots as well.\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'ds-toggle-source': CustomEvent<Element>;\n }\n}\n\nconst ROOTS = new Map<ShadowRoot, () => void>();\nconst ATTR_PLACE = 'data-placement';\nconst ATTR_AUTO = 'data-autoplacement';\nconst POPOVERS = new Map<\n HTMLElement,\n { source: Element; cleanup: () => void }\n>();\n\n// Sometimes use \"ds-toggle\" event while waiting for better support of\n// event.source (https://developer.mozilla.org/en-US/docs/Web/API/ToggleEvent/source)\n\nconst handleToggle = (\n e: Event &\n Partial<ToggleEvent> & { detail?: HTMLElement; source?: HTMLElement },\n) => toggle(getComposedTarget(e), e.newState, e.oldState, e.source || e.detail);\n\nfunction toggle(\n el: Element | null,\n newState?: string,\n oldState?: string,\n source?: HTMLElement,\n) {\n const isPopover = el instanceof HTMLElement && attr(el, 'popover') !== null;\n const float = isPopover && getCSSProp(el, '--_ds-floating');\n const prev = POPOVERS.get(el as HTMLElement);\n\n if (newState === 'open' && prev && prev.source === source) return; // Prevent double binding\n prev?.cleanup(); // Cleanup if previously bound popover exists to avoid multiple autoUpdate memory leaks\n if (newState === 'closed' || !float) return;\n if (!source) {\n const css = el.id && `[popovertarget=\"${el.id}\"],[commandfor=\"${el.id}\"]`;\n source = (css && getRoot(el).querySelector<HTMLElement>(css)) || undefined; // Polyfill ToggleEvent .source for older browsers\n }\n if (!source || source === el || (oldState && oldState === newState)) return; // No need to update\n\n // Use scroll-margin-bottom to measure computed arrow-size property as this does\n // not affect layout or position, makes the browser calculate the pixel value instead\n // of returning the calc() (as it would if reading the --_ds-floating-arrow-size directly)\n // and makes it possible to read the value even if ::before is not used to draw the arrow.\n el.style.scrollMarginBottom = `var(--_ds-floating-arrow-size)`;\n\n const padding = 10;\n const overscroll = getCSSProp(el, '--_ds-floating-overscroll');\n const placement = attr(el, ATTR_PLACE) || attr(source, ATTR_PLACE) || float;\n const auto = attr(el, ATTR_AUTO) || attr(source, ATTR_AUTO);\n const arrowSize = parseFloat(getCSSProp(el, 'scroll-margin-bottom')) || 0;\n const shiftProp = placement.match(/left|right/gi) ? 'Height' : 'Width';\n const shiftLimit = source[`offset${shiftProp}`] / 2 + arrowSize;\n\n if (placement === 'none') return; // No need to position\n\n let sized = false; // Only size once per open, so scrolling does not resize the popover\n const options = {\n strategy: 'absolute',\n placement,\n middleware: [\n offset(arrowSize),\n shift({\n padding,\n limiter: limitShift({ offset: { mainAxis: shiftLimit } }), // Prevent from shifing away from source\n }),\n arrowPseudo(),\n ...(auto !== 'false' ? [flip({ padding, crossAxis: false })] : []),\n ...(overscroll\n ? [\n size({\n apply({ availableHeight }) {\n if (sized) return;\n sized = true;\n const width = `${source.offsetWidth}px`; // Use offsetWidth to include padding, matching the width of the source element\n const maxHeight = `${Math.max(50, availableHeight - padding * 2)}px`;\n\n requestAnimationFrame(() => {\n // Avoid changing an observed element during ResizeObserver delivery.\n if (overscroll === 'fit' && el.style.width !== width)\n el.style.width = width;\n if (el.style.maxHeight !== maxHeight)\n el.style.maxHeight = maxHeight;\n });\n },\n }),\n ]\n : []),\n ],\n } as ComputePositionConfig;\n const unfloat = autoUpdate(source, el, async () => {\n if (!source?.isConnected) return POPOVERS.get(el)?.cleanup(); // Cleanup if source element is removed\n const { x, y } = await computePosition(source, el, options);\n el.style.translate = `${x}px ${y}px`;\n });\n POPOVERS.set(el, {\n source,\n cleanup: () => POPOVERS.delete(el) && unfloat(),\n });\n}\n\n// Prevent closing when pointer interacts with scrollbar\nlet IS_SCROLL: boolean | undefined;\nconst handleScrollbar = (e: Event) => {\n if (e.type === 'pointerdown') {\n IS_SCROLL = false;\n }\n if (e.type === 'scroll' && IS_SCROLL === false) IS_SCROLL = true;\n if (e.type === 'pointerup' && IS_SCROLL)\n for (const [popover] of POPOVERS) popover.showPopover(); // Immediately show again to prevent flicker\n};\n\n// And add listeners for toggle event on shadowRoots as \"toggle\" is not a composed event\nconst handleClick = (e: Event) => {\n for (const [root, off] of ROOTS)\n if (!root.host?.isConnected && ROOTS.delete(root)) off(); // Prune roots whose host is no longer connected (e.g. removed custom elements) to avoid unbounded growth\n\n const root = getRoot(getComposedTarget(e));\n if (root instanceof ShadowRoot && !ROOTS.has(root))\n ROOTS.set(root, on(root, 'toggle', handleToggle, QUICK_EVENT));\n};\n\nonHotReload('popover', () => {\n const descriptors = Object.getOwnPropertyDescriptors(HTMLElement.prototype);\n const togglePopover = HTMLElement.prototype.togglePopover;\n const showPopover = HTMLElement.prototype.showPopover;\n const hidePopover = HTMLElement.prototype.hidePopover;\n\n // Since toggle event is not composed, we need to trigger it when programatically called inside shadow DOM\n Object.defineProperties(HTMLElement.prototype, {\n togglePopover: {\n ...descriptors.togglePopover,\n value(opt: TogglePopoverOptions) {\n const isOpen = this.matches(':popover-open');\n const isBool = typeof opt === 'boolean';\n const prev = isOpen ? 'open' : 'closed';\n const next = (isBool ? opt : (opt?.force ?? !isOpen))\n ? 'open'\n : 'closed';\n const source = isBool ? undefined : opt?.source;\n const result = togglePopover?.call(this, opt as TogglePopoverOptions);\n toggle(this, next, prev, source);\n return result;\n },\n },\n showPopover: {\n ...descriptors.showPopover,\n value(opt: ShowPopoverOptions) {\n const prev = this.matches(':popover-open') ? 'open' : 'closed';\n const result = showPopover?.call(this, opt);\n toggle(this, 'open', prev, opt?.source);\n return result;\n },\n },\n hidePopover: {\n ...descriptors.hidePopover,\n value() {\n const prev = this.matches(':popover-open') ? 'open' : 'closed';\n const result = hidePopover?.call(this);\n toggle(this, 'closed', prev);\n return result;\n },\n },\n });\n\n return [\n on(document, 'click', handleClick, QUICK_EVENT),\n on(document, 'pointerdown pointerup scroll', handleScrollbar, QUICK_EVENT),\n on(document, 'toggle ds-toggle-source', handleToggle, QUICK_EVENT), // Use capture since the toggle event does not bubble\n () => {\n // Restore original methods on hot reload\n Object.defineProperties(HTMLElement.prototype, {\n togglePopover: { ...descriptors.togglePopover, value: togglePopover },\n showPopover: { ...descriptors.showPopover, value: showPopover },\n hidePopover: { ...descriptors.hidePopover, value: hidePopover },\n });\n for (const [, off] of ROOTS) off(); // Cleanup listeners on ShadowRoots on hot reload\n ROOTS.clear();\n },\n ];\n});\n\nconst arrowPseudo = () => ({\n name: 'arrowPseudo',\n fn(data: MiddlewareState) {\n const target = data.elements.floating;\n const source = data.rects.reference;\n const x = `${Math.round(source.width / 2 + source.x - data.x)}px`;\n const y = `${Math.round(source.height / 2 + source.y - data.y)}px`;\n\n target.style.setProperty('--_ds-floating-arrow-x', x);\n target.style.setProperty('--_ds-floating-arrow-y', y);\n attr(target, 'data-floating', data.placement);\n return data;\n },\n});\n"],"mappings":"wYA0BI,EAAU,GAAK,CAAC,EAAY,GAAK,CAAC,EAAa,GACjD,EAAgB,CAAE,UAAW,SAAU,CAAC,EAe1C,MAAM,EAAQ,IAAI,IACZ,EAAa,iBACb,EAAY,qBACZ,EAAW,IAAI,IAQf,EACJ,GAEG,EAAO,EAAkB,CAAC,EAAG,EAAE,SAAU,EAAE,SAAU,EAAE,QAAU,EAAE,MAAM,EAE9E,SAAS,EACP,EACA,EACA,EACA,EACA,CAEA,IAAM,EADY,aAAc,aAAe,EAAK,EAAI,SAAS,IAAM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yBAA0B,CAAC,EACpD,EAAO,MAAM,YAAY,yBAA0B,CAAC,EACpD,EAAK,EAAQ,gBAAiB,EAAK,SAAS,EACrC,CACT,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{QUICK_EVENT as e,attr as t,attrOrCSS as n,customElements as r,off as i,on as a,onMutation as o,useId as s,warn as c}from"../utils/utils.js";import{UHTMLComboboxElement as l}from"@u-elements/u-combobox";const u=`data-empty`;var d=class extends l{_unmutate;connectedCallback(){super.connectedCallback(),this._unmutate=o(this,f,{childList:!0}),a(this,`comboboxafterselect input`,p,e),a(this,`toggle`,m,e)}disconnectedCallback(){super.disconnectedCallback(),this._unmutate?.(),this._unmutate=void 0,i(this,`comboboxafterselect input`,p,e),i(this,`toggle`,m,e)}};const f=e=>{let{control:n,list:r}=e,i=r||e.querySelector(`u-datalist`);n&&
|
|
1
|
+
import{QUICK_EVENT as e,attr as t,attrOrCSS as n,customElements as r,off as i,on as a,onMutation as o,useId as s,warn as c}from"../utils/utils.js";import{UHTMLComboboxElement as l}from"@u-elements/u-combobox";const u=`data-empty`;var d=class extends l{_unmutate;connectedCallback(){super.connectedCallback(),this._unmutate=o(this,f,{childList:!0}),a(this,`comboboxafterselect input`,p,e),a(this,`toggle`,m,e)}disconnectedCallback(){super.disconnectedCallback(),this._unmutate?.(),this._unmutate=void 0,i(this,`comboboxafterselect input`,p,e),i(this,`toggle`,m,e)}};const f=e=>{let{control:n,list:r}=e,i=r||e.querySelector(`u-datalist`);n&&t(n,`popovertarget`,r?s(r):null),i&&(t(i,`popover`,`manual`),t(i,`data-is-floating`,`true`)),p({currentTarget:e})},p=({currentTarget:e})=>{let{creatable:r,control:i,options:a}=e;if(!a)return;let o=i?.value.trim()||``,s=o.toLowerCase(),l,d=!o;for(let e of a)if(!l&&e.hasAttribute(u)?l=e:!d&&e.label?.toLowerCase()===s&&(d=!0),d&&l)break;if(!l||(l.hidden=d,l.label=o,l.value=r?o:``,!r||l.textContent))return;let f=n(l,u);f?t(l,u,f):c(`Missing ${u} value on:`,l),t(l,`data-create`,f?.replace(`{value}`,o))},m=e=>{let t=e.currentTarget,n=e.newState===`open`&&t.control;n&&t.list?.dispatchEvent(new CustomEvent(`ds-toggle-source`,{bubbles:!0,composed:!0,detail:n}))};r.define(`ds-suggestion`,d);export{d as DSSuggestionElement};
|
|
2
2
|
//# sourceMappingURL=suggestion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suggestion.js","names":[],"sources":["../../../src/suggestion/suggestion.ts"],"sourcesContent":["import { UHTMLComboboxElement } from '@u-elements/u-combobox';\nimport {\n attr,\n attrOrCSS,\n customElements,\n off,\n on,\n onMutation,\n QUICK_EVENT,\n useId,\n warn,\n} from '../utils/utils';\n\nconst ATTR_EMPTY = 'data-empty';\nconst ATTR_CREATE = 'data-create';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-suggestion': DSSuggestionElement;\n }\n}\n\nexport class DSSuggestionElement extends UHTMLComboboxElement {\n _unmutate?: ReturnType<typeof onMutation>; // Using underscore instead of private fields for backwards compatibility\n\n connectedCallback() {\n super.connectedCallback();\n this._unmutate = onMutation(this, render, { childList: true }); // .control and .list are direct children of the custom element\n on(this, 'comboboxafterselect input', handleEmpty, QUICK_EVENT);\n on(this, 'toggle', polyfillToggleSource, QUICK_EVENT);\n }\n disconnectedCallback() {\n super.disconnectedCallback();\n this._unmutate?.();\n this._unmutate = undefined;\n off(this, 'comboboxafterselect input', handleEmpty, QUICK_EVENT);\n off(this, 'toggle', polyfillToggleSource, QUICK_EVENT);\n }\n}\n\
|
|
1
|
+
{"version":3,"file":"suggestion.js","names":[],"sources":["../../../src/suggestion/suggestion.ts"],"sourcesContent":["import { UHTMLComboboxElement } from '@u-elements/u-combobox';\nimport {\n attr,\n attrOrCSS,\n customElements,\n off,\n on,\n onMutation,\n QUICK_EVENT,\n useId,\n warn,\n} from '../utils/utils';\n\nconst ATTR_EMPTY = 'data-empty';\nconst ATTR_CREATE = 'data-create';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-suggestion': DSSuggestionElement;\n }\n}\n\nexport class DSSuggestionElement extends UHTMLComboboxElement {\n _unmutate?: ReturnType<typeof onMutation>; // Using underscore instead of private fields for backwards compatibility\n\n connectedCallback() {\n super.connectedCallback();\n this._unmutate = onMutation(this, render, { childList: true }); // .control and .list are direct children of the custom element\n on(this, 'comboboxafterselect input', handleEmpty, QUICK_EVENT);\n on(this, 'toggle', polyfillToggleSource, QUICK_EVENT);\n }\n disconnectedCallback() {\n super.disconnectedCallback();\n this._unmutate?.();\n this._unmutate = undefined;\n off(this, 'comboboxafterselect input', handleEmpty, QUICK_EVENT);\n off(this, 'toggle', polyfillToggleSource, QUICK_EVENT);\n }\n}\n\nconst render = (self: DSSuggestionElement) => {\n const { control, list } = self;\n const datalist = list || self.querySelector('u-datalist'); // Fallback to u-datalist since React can render the ds-suggestion before u-datalist is connected\n\n if (control) attr(control, 'popovertarget', list ? useId(list) : null);\n if (datalist) {\n attr(datalist, 'popover', 'manual'); // Ensure popover attribute is set on the list\n attr(datalist, 'data-is-floating', 'true'); // identifier for css to toggle opacity when it is placed by floating-ui.\n }\n handleEmpty({ currentTarget: self });\n};\n\nconst handleEmpty = ({ currentTarget: self }: Pick<Event, 'currentTarget'>) => {\n const { creatable, control, options } = self as DSSuggestionElement;\n if (!options) return;\n\n const value = control?.value.trim() || '';\n const query = value.toLowerCase();\n let empty: HTMLOptionElement | undefined;\n let exists = !value;\n\n for (const opt of options) {\n if (!empty && opt.hasAttribute(ATTR_EMPTY)) empty = opt;\n else if (!exists && opt.label?.toLowerCase() === query) exists = true; // Prevent creating an option that already exists\n if (exists && empty) break; // Speed up if both conditions are met\n }\n if (!empty) return;\n\n empty.hidden = exists;\n empty.label = value; // Ensures option is not filtered out by <u-combobox>\n empty.value = creatable ? value : ''; // Ensures clicking option does nothing\n\n if (!creatable || empty.textContent) return;\n const text = attrOrCSS(empty, ATTR_EMPTY);\n if (!text) warn(`Missing ${ATTR_EMPTY} value on:`, empty);\n else attr(empty, ATTR_EMPTY, text); // Speed up by caching attribute value\n attr(empty, ATTR_CREATE, text?.replace('{value}', value));\n};\n\n// Since showPopover({ source }) is not supported in all browsers yet:\nconst polyfillToggleSource = (event: Partial<ToggleEvent>) => {\n const self = event.currentTarget as DSSuggestionElement;\n const detail = event.newState === 'open' && self.control; // .control comes from UHTMLComboboxElement\n\n if (detail)\n self.list?.dispatchEvent(\n new CustomEvent('ds-toggle-source', {\n bubbles: true,\n composed: true, // Enable bubbling out of shadow DOM boundaries\n detail, // Since showPopover({ source }) is not supported in all browsers yet\n }),\n );\n};\n\n// Ensure u-datalist is defined before ds-suggestion\ncustomElements.define('ds-suggestion', DSSuggestionElement);\n"],"mappings":"iNAaA,MAAM,EAAa,aASnB,IAAa,EAAb,cAAyC,CAAqB,CAC5D,UAEA,mBAAoB,CAClB,MAAM,kBAAkB,EACxB,KAAK,UAAY,EAAW,KAAM,EAAQ,CAAE,UAAW,EAAK,CAAC,EAC7D,EAAG,KAAM,4BAA6B,EAAa,CAAW,EAC9D,EAAG,KAAM,SAAU,EAAsB,CAAW,CACtD,CACA,sBAAuB,CACrB,MAAM,qBAAqB,EAC3B,KAAK,YAAY,EACjB,KAAK,UAAY,IAAA,GACjB,EAAI,KAAM,4BAA6B,EAAa,CAAW,EAC/D,EAAI,KAAM,SAAU,EAAsB,CAAW,CACvD,CACF,EAEA,MAAM,EAAU,GAA8B,CAC5C,GAAM,CAAE,UAAS,QAAS,EACpB,EAAW,GAAQ,EAAK,cAAc,YAAY,EAEpD,GAAS,EAAK,EAAS,gBAAiB,EAAO,EAAM,CAAI,EAAI,IAAI,EACjE,IACF,EAAK,EAAU,UAAW,QAAQ,EAClC,EAAK,EAAU,mBAAoB,MAAM,GAE3C,EAAY,CAAE,cAAe,CAAK,CAAC,CACrC,EAEM,GAAe,CAAE,cAAe,KAAyC,CAC7E,GAAM,CAAE,YAAW,UAAS,WAAY,EACxC,GAAI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