@digdir/designsystemet-web 1.20.0 → 1.21.0

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2024 Digitaliseringsdirektoratet (Digdir)
1
+ Copyright Digitaliseringsdirektoratet (Digdir)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
@@ -1,2 +1,2 @@
1
- function e(){return typeof HTMLButtonElement<`u`&&`command`in HTMLButtonElement.prototype&&`source`in((globalThis.CommandEvent||{}).prototype||{})}function t(){document.addEventListener(`invoke`,e=>{e.type==`invoke`&&e.isTrusted&&(e.stopImmediatePropagation(),e.preventDefault())},!0),document.addEventListener(`command`,e=>{e.type==`command`&&e.isTrusted&&(e.stopImmediatePropagation(),e.preventDefault())},!0);function e(e,t,n=!0){Object.defineProperty(e,t,{...Object.getOwnPropertyDescriptor(e,t),enumerable:n})}function t(e){return e&&typeof e.getRootNode==`function`?e.getRootNode():e&&e.parentNode?t(e.parentNode):e}let n=new WeakMap,r=new WeakMap;class i extends Event{constructor(e,t={}){super(e,t);let{source:i,command:a}=t;if(i!=null&&!(i instanceof Element))throw TypeError(`source must be an element`);n.set(this,i||null),r.set(this,a===void 0?``:String(a))}get[Symbol.toStringTag](){return`CommandEvent`}get source(){if(!n.has(this))throw TypeError(`illegal invocation`);let e=n.get(this);if(!(e instanceof Element))return null;let r=t(e);return r===t(this.target||document)?e:r.host}get command(){if(!r.has(this))throw TypeError(`illegal invocation`);return r.get(this)}}e(i.prototype,`source`),e(i.prototype,`command`);let a=new WeakMap;function o(e){Object.defineProperties(e.prototype,{commandForElement:{enumerable:!0,configurable:!0,set(e){if(e===null)this.removeAttribute(`commandfor`),a.delete(this);else if(e instanceof Element){this.setAttribute(`commandfor`,``);let n=t(e);t(this)===n||n===this.ownerDocument?a.set(this,e):a.delete(this)}else throw TypeError(`commandForElement must be an element or null`)},get(){if(this.localName!==`button`||this.disabled)return null;if(this.form&&this.getAttribute(`type`)!==`button`)return console.warn("Element with `commandFor` is a form participant. It should explicitly set `type=button` in order for `commandFor` to work"),null;let e=a.get(this);if(e)return e.isConnected?e:(a.delete(this),null);let n=t(this),r=this.getAttribute(`commandfor`);return(n instanceof Document||n instanceof ShadowRoot)&&r&&n.getElementById(r)||null}},command:{enumerable:!0,configurable:!0,get(){let e=this.getAttribute(`command`)||``;if(e.startsWith(`--`))return e;let t=e.toLowerCase();switch(t){case`show-modal`:case`request-close`:case`close`:case`toggle-popover`:case`hide-popover`:case`show-popover`:return t}return``},set(e){this.setAttribute(`command`,e)}}})}let s=new WeakMap;Object.defineProperties(HTMLElement.prototype,{oncommand:{enumerable:!0,configurable:!0,get(){return l.takeRecords(),s.get(this)||null},set(e){let t=s.get(this)||null;t&&this.removeEventListener(`command`,t),s.set(this,typeof e==`object`||typeof e==`function`?e:null),typeof e==`function`&&this.addEventListener(`command`,e)}}});function c(e){for(let t of e)t.oncommand=Function(`event`,t.getAttribute(`oncommand`))}let l=new MutationObserver(e=>{for(let t of e){let{target:e}=t;t.type===`childList`?c(e.querySelectorAll(`[oncommand]`)):c([e])}});l.observe(document,{subtree:!0,childList:!0,attributeFilter:[`oncommand`]}),c(document.querySelectorAll(`[oncommand]`));let u=new WeakSet;function d(e){if(u.has(e)||(u.add(e),e.defaultPrevented)||e.type!==`click`)return;let t=e.composedPath().find(e=>e.matches?.(`button[commandfor], button[command]`));if(!t)return;if(t.form&&t.getAttribute(`type`)!==`button`)throw e.preventDefault(),Error("Element with `commandFor` is a form participant. It should explicitly set `type=button` in order for `commandFor` to work. In order for it to act as a Submit button, it must not have command or commandfor attributes");if(t.hasAttribute(`command`)!==t.hasAttribute(`commandfor`)){let e=t.hasAttribute(`command`)?`command`:`commandfor`,n=t.hasAttribute(`command`)?`commandfor`:`command`;throw Error(`Element with ${e} attribute must also have a ${n} attribute to function.`)}if(t.command!==`show-popover`&&t.command!==`hide-popover`&&t.command!==`toggle-popover`&&t.command!==`show-modal`&&t.command!==`request-close`&&t.command!==`close`&&!t.command.startsWith(`--`)){console.warn(`"${t.command}" is not a valid command value. Custom commands must begin with --`);return}let n=t.commandForElement;if(!n)return;let r=new i(`command`,{command:t.command,source:t,cancelable:!0});if(n.dispatchEvent(r),r.defaultPrevented)return;let a=r.command.toLowerCase();if(n.popover){let e=!n.matches(`:popover-open`);e&&(a===`toggle-popover`||a===`show-popover`)?n.showPopover({source:t}):!e&&a===`hide-popover`&&n.hidePopover()}else if(n.localName===`dialog`){let e=!n.hasAttribute(`open`);e&&a==`show-modal`?n.showModal():!e&&a==`close`?n.close(t.value?t.value:void 0):!e&&a==`request-close`&&(HTMLDialogElement.prototype.requestClose||(HTMLDialogElement.prototype.requestClose=function(){let e=new Event(`cancel`,{cancelable:!0});this.dispatchEvent(e),e.defaultPrevented||this.close()}),n.requestClose(t.value?t.value:void 0))}}function f(e){e.addEventListener(`click`,d,!0)}function p(e,t){let n=e.prototype.attachShadow;e.prototype.attachShadow=function(e){let r=n.call(this,e);return t(r),r};let r=e.prototype.attachInternals;e.prototype.attachInternals=function(){let e=r.call(this);return e.shadowRoot&&t(e.shadowRoot),e}}o(HTMLButtonElement),p(HTMLElement,e=>{f(e),l.observe(e,{attributeFilter:[`oncommand`]}),c(e.querySelectorAll(`[oncommand]`))}),f(document),Object.assign(globalThis,{CommandEvent:i})}exports.apply=t,exports.isSupported=e;
1
+ function e(){return typeof HTMLButtonElement<`u`&&`command`in HTMLButtonElement.prototype&&`source`in((globalThis.CommandEvent||{}).prototype||{})}function t(){document.addEventListener(`command`,e=>{e.type==`command`&&e.isTrusted&&(e.stopImmediatePropagation(),e.preventDefault())},!0);function e(e,t,n=!0){Object.defineProperty(e,t,{...Object.getOwnPropertyDescriptor(e,t),enumerable:n})}function t(e){return e&&typeof e.getRootNode==`function`?e.getRootNode():e&&e.parentNode?t(e.parentNode):e}let n=new WeakMap,r=new WeakMap;class i extends Event{constructor(e,t={}){super(e,t);let{source:i,command:a}=t;if(i!=null&&!(i instanceof Element))throw TypeError(`source must be an element`);n.set(this,i||null),r.set(this,a===void 0?``:String(a))}get[Symbol.toStringTag](){return`CommandEvent`}get source(){if(!n.has(this))throw TypeError(`illegal invocation`);let e=n.get(this);if(!(e instanceof Element))return null;let r=t(e);return r===t(this.target||document)?e:r.host}get command(){if(!r.has(this))throw TypeError(`illegal invocation`);return r.get(this)}}e(i.prototype,`source`),e(i.prototype,`command`);let a=new WeakMap;function o(e){Object.defineProperties(e.prototype,{commandForElement:{enumerable:!0,configurable:!0,set(e){if(e===null)this.removeAttribute(`commandfor`),a.delete(this);else if(e instanceof Element){this.setAttribute(`commandfor`,``);let n=t(e);t(this)===n||n===this.ownerDocument?a.set(this,e):a.delete(this)}else throw TypeError(`commandForElement must be an element or null`)},get(){if(this.localName!==`button`||this.disabled)return null;if(this.form&&this.getAttribute(`type`)!==`button`)return console.warn("Element with `commandFor` is a form participant. It should explicitly set `type=button` in order for `commandFor` to work"),null;let e=a.get(this);if(e)return e.isConnected?e:(a.delete(this),null);let n=t(this),r=this.getAttribute(`commandfor`);return(n instanceof Document||n instanceof ShadowRoot)&&r&&n.getElementById(r)||null}},command:{enumerable:!0,configurable:!0,get(){let e=this.getAttribute(`command`)||``;if(e.startsWith(`--`))return e;let t=e.toLowerCase();switch(t){case`show-modal`:case`request-close`:case`close`:case`toggle-popover`:case`hide-popover`:case`show-popover`:return t}return``},set(e){this.setAttribute(`command`,e)}}})}let s=new WeakMap;Object.defineProperties(HTMLElement.prototype,{oncommand:{enumerable:!0,configurable:!0,get(){return l.takeRecords(),s.get(this)||null},set(e){let t=s.get(this)||null;t&&this.removeEventListener(`command`,t),s.set(this,typeof e==`object`||typeof e==`function`?e:null),typeof e==`function`&&this.addEventListener(`command`,e)}}});function c(e){for(let t of e)t.oncommand=Function(`event`,t.getAttribute(`oncommand`))}let l=new MutationObserver(e=>{for(let t of e){let{target:e}=t;t.type===`childList`?c(e.querySelectorAll(`[oncommand]`)):c([e])}});l.observe(document,{subtree:!0,childList:!0,attributeFilter:[`oncommand`]}),c(document.querySelectorAll(`[oncommand]`));let u=new WeakSet;function d(e){if(u.has(e)||(u.add(e),e.defaultPrevented)||e.type!==`click`)return;let t=e.composedPath().find(e=>e.matches?.(`button[commandfor], button[command]`));if(!t)return;if(t.form&&t.getAttribute(`type`)!==`button`)throw e.preventDefault(),Error("Element with `commandFor` is a form participant. It should explicitly set `type=button` in order for `commandFor` to work. In order for it to act as a Submit button, it must not have command or commandfor attributes");if(t.hasAttribute(`command`)!==t.hasAttribute(`commandfor`)){let e=t.hasAttribute(`command`)?`command`:`commandfor`,n=t.hasAttribute(`command`)?`commandfor`:`command`;throw Error(`Element with ${e} attribute must also have a ${n} attribute to function.`)}if(t.command!==`show-popover`&&t.command!==`hide-popover`&&t.command!==`toggle-popover`&&t.command!==`show-modal`&&t.command!==`request-close`&&t.command!==`close`&&!t.command.startsWith(`--`)){console.warn(`"${t.command}" is not a valid command value. Custom commands must begin with --`);return}let n=t.commandForElement;if(!n)return;let r=new i(`command`,{command:t.command,source:t,cancelable:!0});if(n.dispatchEvent(r),r.defaultPrevented)return;let a=r.command.toLowerCase();if(n.popover){let e=!n.matches(`:popover-open`);e&&(a===`toggle-popover`||a===`show-popover`)?n.showPopover({source:t}):!e&&(a===`toggle-popover`||a===`hide-popover`)&&n.hidePopover()}else if(n.localName===`dialog`){let e=!n.hasAttribute(`open`);e&&a==`show-modal`?n.showModal():!e&&a==`close`?n.close(t.value?t.value:void 0):!e&&a==`request-close`&&(HTMLDialogElement.prototype.requestClose||(HTMLDialogElement.prototype.requestClose=function(){let e=new Event(`cancel`,{cancelable:!0});this.dispatchEvent(e),e.defaultPrevented||this.close()}),n.requestClose(t.value?t.value:void 0))}}function f(e){e.addEventListener(`click`,d,!0)}function p(e,t){let n=e.prototype.attachShadow;e.prototype.attachShadow=function(e){let r=n.call(this,e);return t(r),r};let r=e.prototype.attachInternals;e.prototype.attachInternals=function(){let e=r.call(this);return e.shadowRoot&&t(e.shadowRoot),e}}o(HTMLButtonElement),p(HTMLElement,e=>{f(e),l.observe(e,{attributeFilter:[`oncommand`]}),c(e.querySelectorAll(`[oncommand]`))}),f(document),Object.assign(globalThis,{CommandEvent:i})}exports.apply=t,exports.isSupported=e;
2
2
  //# sourceMappingURL=invoker.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"invoker.cjs","names":[],"sources":["../../../../../../node_modules/.pnpm/invokers-polyfill@1.0.3/node_modules/invokers-polyfill/invoker.js"],"sourcesContent":["export function isSupported() {\n return (\n typeof HTMLButtonElement !== \"undefined\" &&\n \"command\" in HTMLButtonElement.prototype &&\n \"source\" in ((globalThis.CommandEvent || {}).prototype || {})\n );\n}\n\nexport function isPolyfilled() {\n return !/native code/i.test((globalThis.CommandEvent || {}).toString());\n}\n\nexport function apply() {\n // XXX: Invoker Buttons used to dispatch 'invoke' events instead of\n // 'command' events. We should ensure to prevent 'invoke' events being\n // fired in those browsers.\n // XXX: https://bugs.chromium.org/p/chromium/issues/detail?id=1523183\n // Chrome will dispatch invoke events even with the flag disabled; so\n // we need to capture those to prevent duplicate events.\n document.addEventListener(\n \"invoke\",\n (e) => {\n if (e.type == \"invoke\" && e.isTrusted) {\n e.stopImmediatePropagation();\n e.preventDefault();\n }\n },\n true,\n );\n document.addEventListener(\n \"command\",\n (e) => {\n if (e.type == \"command\" && e.isTrusted) {\n e.stopImmediatePropagation();\n e.preventDefault();\n }\n },\n true,\n );\n\n function enumerate(obj, key, enumerable = true) {\n Object.defineProperty(obj, key, {\n ...Object.getOwnPropertyDescriptor(obj, key),\n enumerable,\n });\n }\n\n function getRootNode(node) {\n if (node && typeof node.getRootNode === \"function\") {\n return node.getRootNode();\n }\n if (node && node.parentNode) return getRootNode(node.parentNode);\n return node;\n }\n\n const commandEventSourceElements = new WeakMap();\n const commandEventActions = new WeakMap();\n\n class CommandEvent extends Event {\n constructor(type, invokeEventInit = {}) {\n super(type, invokeEventInit);\n const { source, command } = invokeEventInit;\n if (source != null && !(source instanceof Element)) {\n throw new TypeError(`source must be an element`);\n }\n commandEventSourceElements.set(this, source || null);\n commandEventActions.set(\n this,\n command !== undefined ? String(command) : \"\",\n );\n }\n\n get [Symbol.toStringTag]() {\n return \"CommandEvent\";\n }\n\n get source() {\n if (!commandEventSourceElements.has(this)) {\n throw new TypeError(\"illegal invocation\");\n }\n const source = commandEventSourceElements.get(this);\n if (!(source instanceof Element)) return null;\n const invokerRoot = getRootNode(source);\n if (invokerRoot !== getRootNode(this.target || document)) {\n return invokerRoot.host;\n }\n return source;\n }\n\n get command() {\n if (!commandEventActions.has(this)) {\n throw new TypeError(\"illegal invocation\");\n }\n return commandEventActions.get(this);\n }\n }\n enumerate(CommandEvent.prototype, \"source\");\n enumerate(CommandEvent.prototype, \"command\");\n\n const invokerAssociatedElements = new WeakMap();\n\n function applyInvokerMixin(ElementClass) {\n Object.defineProperties(ElementClass.prototype, {\n commandForElement: {\n enumerable: true,\n configurable: true,\n set(targetElement) {\n if (targetElement === null) {\n this.removeAttribute(\"commandfor\");\n invokerAssociatedElements.delete(this);\n } else if (!(targetElement instanceof Element)) {\n throw new TypeError(`commandForElement must be an element or null`);\n } else {\n this.setAttribute(\"commandfor\", \"\");\n const targetRootNode = getRootNode(targetElement);\n const thisRootNode = getRootNode(this);\n if (\n thisRootNode === targetRootNode ||\n targetRootNode === this.ownerDocument\n ) {\n invokerAssociatedElements.set(this, targetElement);\n } else {\n invokerAssociatedElements.delete(this);\n }\n }\n },\n get() {\n if (this.localName !== \"button\") {\n return null;\n }\n if (this.disabled) {\n return null;\n }\n if (this.form && this.getAttribute(\"type\") !== \"button\") {\n console.warn(\n \"Element with `commandFor` is a form participant. \" +\n \"It should explicitly set `type=button` in order for `commandFor` to work\",\n );\n return null;\n }\n const targetElement = invokerAssociatedElements.get(this);\n if (targetElement) {\n if (targetElement.isConnected) {\n return targetElement;\n } else {\n invokerAssociatedElements.delete(this);\n return null;\n }\n }\n const root = getRootNode(this);\n const idref = this.getAttribute(\"commandfor\");\n if (\n (root instanceof Document || root instanceof ShadowRoot) &&\n idref\n ) {\n return root.getElementById(idref) || null;\n }\n return null;\n },\n },\n command: {\n enumerable: true,\n configurable: true,\n get() {\n const value = this.getAttribute(\"command\") || \"\";\n if (value.startsWith(\"--\")) return value;\n const valueLower = value.toLowerCase();\n switch (valueLower) {\n case \"show-modal\":\n case \"request-close\":\n case \"close\":\n case \"toggle-popover\":\n case \"hide-popover\":\n case \"show-popover\":\n return valueLower;\n }\n return \"\";\n },\n set(value) {\n this.setAttribute(\"command\", value);\n },\n },\n });\n }\n\n const onHandlers = new WeakMap();\n Object.defineProperties(HTMLElement.prototype, {\n oncommand: {\n enumerable: true,\n configurable: true,\n get() {\n oncommandObserver.takeRecords();\n return onHandlers.get(this) || null;\n },\n set(handler) {\n const existing = onHandlers.get(this) || null;\n if (existing) {\n this.removeEventListener(\"command\", existing);\n }\n onHandlers.set(\n this,\n typeof handler === \"object\" || typeof handler === \"function\"\n ? handler\n : null,\n );\n if (typeof handler == \"function\") {\n this.addEventListener(\"command\", handler);\n }\n },\n },\n });\n function applyOnCommandHandler(els) {\n for (const el of els) {\n el.oncommand = new Function(\"event\", el.getAttribute(\"oncommand\"));\n }\n }\n const oncommandObserver = new MutationObserver((records) => {\n for (const record of records) {\n const { target } = record;\n if (record.type === \"childList\") {\n applyOnCommandHandler(target.querySelectorAll(\"[oncommand]\"));\n } else {\n applyOnCommandHandler([target]);\n }\n }\n });\n oncommandObserver.observe(document, {\n subtree: true,\n childList: true,\n attributeFilter: [\"oncommand\"],\n });\n applyOnCommandHandler(document.querySelectorAll(\"[oncommand]\"));\n\n const processedEvents = new WeakSet();\n\n function handleInvokerActivation(event) {\n if (processedEvents.has(event)) return;\n\n processedEvents.add(event);\n\n if (event.defaultPrevented) return;\n if (event.type !== \"click\") return;\n const source = event.composedPath().find((el) => el.matches?.(\"button[commandfor], button[command]\"));\n if (!source) return;\n\n if (source.form && source.getAttribute(\"type\") !== \"button\") {\n event.preventDefault();\n throw new Error(\n \"Element with `commandFor` is a form participant. \" +\n \"It should explicitly set `type=button` in order for `commandFor` to work. \" +\n \"In order for it to act as a Submit button, it must not have command or commandfor attributes\",\n );\n }\n\n if (source.hasAttribute(\"command\") !== source.hasAttribute(\"commandfor\")) {\n const attr = source.hasAttribute(\"command\") ? \"command\" : \"commandfor\";\n const missing = source.hasAttribute(\"command\") ? \"commandfor\" : \"command\";\n throw new Error(\n `Element with ${attr} attribute must also have a ${missing} attribute to function.`,\n );\n }\n\n if (\n source.command !== \"show-popover\" &&\n source.command !== \"hide-popover\" &&\n source.command !== \"toggle-popover\" &&\n source.command !== \"show-modal\" &&\n source.command !== \"request-close\" &&\n source.command !== \"close\" &&\n !source.command.startsWith(\"--\")\n ) {\n console.warn(\n `\"${source.command}\" is not a valid command value. Custom commands must begin with --`,\n );\n return;\n }\n\n const invokee = source.commandForElement;\n if (!invokee) return;\n const invokeEvent = new CommandEvent(\"command\", {\n command: source.command,\n source,\n cancelable: true,\n });\n invokee.dispatchEvent(invokeEvent);\n if (invokeEvent.defaultPrevented) return;\n\n const command = invokeEvent.command.toLowerCase();\n\n if (invokee.popover) {\n const canShow = !invokee.matches(\":popover-open\");\n const shouldShow =\n canShow && (command === \"toggle-popover\" || command === \"show-popover\");\n const shouldHide = !canShow && command === \"hide-popover\";\n\n if (shouldShow) {\n invokee.showPopover({ source });\n } else if (shouldHide) {\n invokee.hidePopover();\n }\n } else if (invokee.localName === \"dialog\") {\n const canShow = !invokee.hasAttribute(\"open\");\n\n if (canShow && command == \"show-modal\") {\n invokee.showModal();\n } else if (!canShow && command == \"close\") {\n invokee.close(source.value ? source.value : undefined);\n } else if (!canShow && command == \"request-close\") {\n // requestClose is only supported from Safari 18.4, so we polyfill it on older browsers\n if (!HTMLDialogElement.prototype.requestClose) {\n HTMLDialogElement.prototype.requestClose = function () {\n const cancelEvent = new Event(\"cancel\", { cancelable: true });\n this.dispatchEvent(cancelEvent);\n\n if (!cancelEvent.defaultPrevented) {\n this.close();\n }\n };\n }\n\n invokee.requestClose(source.value ? source.value : undefined);\n }\n }\n }\n\n function setupInvokeListeners(target) {\n target.addEventListener(\"click\", handleInvokerActivation, true);\n }\n\n function observeShadowRoots(ElementClass, callback) {\n const attachShadow = ElementClass.prototype.attachShadow;\n ElementClass.prototype.attachShadow = function (init) {\n const shadow = attachShadow.call(this, init);\n callback(shadow);\n return shadow;\n };\n const attachInternals = ElementClass.prototype.attachInternals;\n ElementClass.prototype.attachInternals = function () {\n const internals = attachInternals.call(this);\n if (internals.shadowRoot) callback(internals.shadowRoot);\n return internals;\n };\n }\n\n applyInvokerMixin(HTMLButtonElement);\n\n observeShadowRoots(HTMLElement, (shadow) => {\n setupInvokeListeners(shadow);\n oncommandObserver.observe(shadow, { attributeFilter: [\"oncommand\"] });\n applyOnCommandHandler(shadow.querySelectorAll(\"[oncommand]\"));\n });\n\n setupInvokeListeners(document);\n\n Object.assign(globalThis, { CommandEvent });\n}\n"],"x_google_ignoreList":[0],"mappings":"AAAA,SAAgB,GAAc,CAC5B,OACE,OAAO,kBAAsB,KAC7B,YAAa,kBAAkB,WAC/B,YAAc,WAAW,cAAgB,CAAC,EAAA,CAAG,WAAa,CAAC,EAE/D,CAMA,SAAgB,GAAQ,CAOtB,SAAS,iBACP,SACC,GAAM,CACD,EAAE,MAAQ,UAAY,EAAE,YAC1B,EAAE,yBAAyB,EAC3B,EAAE,eAAe,EAErB,EACA,EACF,EACA,SAAS,iBACP,UACC,GAAM,CACD,EAAE,MAAQ,WAAa,EAAE,YAC3B,EAAE,yBAAyB,EAC3B,EAAE,eAAe,EAErB,EACA,EACF,EAEA,SAAS,EAAU,EAAK,EAAK,EAAa,GAAM,CAC9C,OAAO,eAAe,EAAK,EAAK,CAC9B,GAAG,OAAO,yBAA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,EACA,IAAM,EAAkB,EAAa,UAAU,gBAC/C,EAAa,UAAU,gBAAkB,UAAY,CACnD,IAAM,EAAY,EAAgB,KAAK,IAAI,EAE3C,OADI,EAAU,YAAY,EAAS,EAAU,UAAU,EAChD,CACT,CACF,CAEA,EAAkB,iBAAiB,EAEnC,EAAmB,YAAc,GAAW,CAC1C,EAAqB,CAAM,EAC3B,EAAkB,QAAQ,EAAQ,CAAE,gBAAiB,CAAC,WAAW,CAAE,CAAC,EACpE,EAAsB,EAAO,iBAAiB,aAAa,CAAC,CAC9D,CAAC,EAED,EAAqB,QAAQ,EAE7B,OAAO,OAAO,WAAY,CAAE,cAAa,CAAC,CAC5C"}
1
+ {"version":3,"file":"invoker.cjs","names":[],"sources":["../../../../../../node_modules/.pnpm/invokers-polyfill@1.0.4/node_modules/invokers-polyfill/invoker.js"],"sourcesContent":["export function isSupported() {\n return (\n typeof HTMLButtonElement !== \"undefined\" &&\n \"command\" in HTMLButtonElement.prototype &&\n \"source\" in ((globalThis.CommandEvent || {}).prototype || {})\n );\n}\n\nexport function isPolyfilled() {\n return !/native code/i.test((globalThis.CommandEvent || {}).toString());\n}\n\nexport function apply() {\n document.addEventListener(\n \"command\",\n (e) => {\n if (e.type == \"command\" && e.isTrusted) {\n e.stopImmediatePropagation();\n e.preventDefault();\n }\n },\n true,\n );\n\n function enumerate(obj, key, enumerable = true) {\n Object.defineProperty(obj, key, {\n ...Object.getOwnPropertyDescriptor(obj, key),\n enumerable,\n });\n }\n\n function getRootNode(node) {\n if (node && typeof node.getRootNode === \"function\") {\n return node.getRootNode();\n }\n if (node && node.parentNode) return getRootNode(node.parentNode);\n return node;\n }\n\n const commandEventSourceElements = new WeakMap();\n const commandEventActions = new WeakMap();\n\n class CommandEvent extends Event {\n constructor(type, invokeEventInit = {}) {\n super(type, invokeEventInit);\n const { source, command } = invokeEventInit;\n if (source != null && !(source instanceof Element)) {\n throw new TypeError(`source must be an element`);\n }\n commandEventSourceElements.set(this, source || null);\n commandEventActions.set(\n this,\n command !== undefined ? String(command) : \"\",\n );\n }\n\n get [Symbol.toStringTag]() {\n return \"CommandEvent\";\n }\n\n get source() {\n if (!commandEventSourceElements.has(this)) {\n throw new TypeError(\"illegal invocation\");\n }\n const source = commandEventSourceElements.get(this);\n if (!(source instanceof Element)) return null;\n const invokerRoot = getRootNode(source);\n if (invokerRoot !== getRootNode(this.target || document)) {\n return invokerRoot.host;\n }\n return source;\n }\n\n get command() {\n if (!commandEventActions.has(this)) {\n throw new TypeError(\"illegal invocation\");\n }\n return commandEventActions.get(this);\n }\n }\n enumerate(CommandEvent.prototype, \"source\");\n enumerate(CommandEvent.prototype, \"command\");\n\n const invokerAssociatedElements = new WeakMap();\n\n function applyInvokerMixin(ElementClass) {\n Object.defineProperties(ElementClass.prototype, {\n commandForElement: {\n enumerable: true,\n configurable: true,\n set(targetElement) {\n if (targetElement === null) {\n this.removeAttribute(\"commandfor\");\n invokerAssociatedElements.delete(this);\n } else if (!(targetElement instanceof Element)) {\n throw new TypeError(`commandForElement must be an element or null`);\n } else {\n this.setAttribute(\"commandfor\", \"\");\n const targetRootNode = getRootNode(targetElement);\n const thisRootNode = getRootNode(this);\n if (\n thisRootNode === targetRootNode ||\n targetRootNode === this.ownerDocument\n ) {\n invokerAssociatedElements.set(this, targetElement);\n } else {\n invokerAssociatedElements.delete(this);\n }\n }\n },\n get() {\n if (this.localName !== \"button\") {\n return null;\n }\n if (this.disabled) {\n return null;\n }\n if (this.form && this.getAttribute(\"type\") !== \"button\") {\n console.warn(\n \"Element with `commandFor` is a form participant. \" +\n \"It should explicitly set `type=button` in order for `commandFor` to work\",\n );\n return null;\n }\n const targetElement = invokerAssociatedElements.get(this);\n if (targetElement) {\n if (targetElement.isConnected) {\n return targetElement;\n } else {\n invokerAssociatedElements.delete(this);\n return null;\n }\n }\n const root = getRootNode(this);\n const idref = this.getAttribute(\"commandfor\");\n if (\n (root instanceof Document || root instanceof ShadowRoot) &&\n idref\n ) {\n return root.getElementById(idref) || null;\n }\n return null;\n },\n },\n command: {\n enumerable: true,\n configurable: true,\n get() {\n const value = this.getAttribute(\"command\") || \"\";\n if (value.startsWith(\"--\")) return value;\n const valueLower = value.toLowerCase();\n switch (valueLower) {\n case \"show-modal\":\n case \"request-close\":\n case \"close\":\n case \"toggle-popover\":\n case \"hide-popover\":\n case \"show-popover\":\n return valueLower;\n }\n return \"\";\n },\n set(value) {\n this.setAttribute(\"command\", value);\n },\n },\n });\n }\n\n const onHandlers = new WeakMap();\n Object.defineProperties(HTMLElement.prototype, {\n oncommand: {\n enumerable: true,\n configurable: true,\n get() {\n oncommandObserver.takeRecords();\n return onHandlers.get(this) || null;\n },\n set(handler) {\n const existing = onHandlers.get(this) || null;\n if (existing) {\n this.removeEventListener(\"command\", existing);\n }\n onHandlers.set(\n this,\n typeof handler === \"object\" || typeof handler === \"function\"\n ? handler\n : null,\n );\n if (typeof handler == \"function\") {\n this.addEventListener(\"command\", handler);\n }\n },\n },\n });\n function applyOnCommandHandler(els) {\n for (const el of els) {\n el.oncommand = new Function(\"event\", el.getAttribute(\"oncommand\"));\n }\n }\n const oncommandObserver = new MutationObserver((records) => {\n for (const record of records) {\n const { target } = record;\n if (record.type === \"childList\") {\n applyOnCommandHandler(target.querySelectorAll(\"[oncommand]\"));\n } else {\n applyOnCommandHandler([target]);\n }\n }\n });\n oncommandObserver.observe(document, {\n subtree: true,\n childList: true,\n attributeFilter: [\"oncommand\"],\n });\n applyOnCommandHandler(document.querySelectorAll(\"[oncommand]\"));\n\n const processedEvents = new WeakSet();\n\n function handleInvokerActivation(event) {\n if (processedEvents.has(event)) return;\n\n processedEvents.add(event);\n\n if (event.defaultPrevented) return;\n if (event.type !== \"click\") return;\n const source = event.composedPath().find((el) => el.matches?.(\"button[commandfor], button[command]\"));\n if (!source) return;\n\n if (source.form && source.getAttribute(\"type\") !== \"button\") {\n event.preventDefault();\n throw new Error(\n \"Element with `commandFor` is a form participant. \" +\n \"It should explicitly set `type=button` in order for `commandFor` to work. \" +\n \"In order for it to act as a Submit button, it must not have command or commandfor attributes\",\n );\n }\n\n if (source.hasAttribute(\"command\") !== source.hasAttribute(\"commandfor\")) {\n const attr = source.hasAttribute(\"command\") ? \"command\" : \"commandfor\";\n const missing = source.hasAttribute(\"command\") ? \"commandfor\" : \"command\";\n throw new Error(\n `Element with ${attr} attribute must also have a ${missing} attribute to function.`,\n );\n }\n\n if (\n source.command !== \"show-popover\" &&\n source.command !== \"hide-popover\" &&\n source.command !== \"toggle-popover\" &&\n source.command !== \"show-modal\" &&\n source.command !== \"request-close\" &&\n source.command !== \"close\" &&\n !source.command.startsWith(\"--\")\n ) {\n console.warn(\n `\"${source.command}\" is not a valid command value. Custom commands must begin with --`,\n );\n return;\n }\n\n const invokee = source.commandForElement;\n if (!invokee) return;\n const invokeEvent = new CommandEvent(\"command\", {\n command: source.command,\n source,\n cancelable: true,\n });\n invokee.dispatchEvent(invokeEvent);\n if (invokeEvent.defaultPrevented) return;\n\n const command = invokeEvent.command.toLowerCase();\n\n if (invokee.popover) {\n const canShow = !invokee.matches(\":popover-open\");\n const shouldShow =\n canShow && (command === \"toggle-popover\" || command === \"show-popover\");\n const shouldHide =\n !canShow &&\n (command === \"toggle-popover\" || command === \"hide-popover\");\n\n if (shouldShow) {\n invokee.showPopover({ source });\n } else if (shouldHide) {\n invokee.hidePopover();\n }\n } else if (invokee.localName === \"dialog\") {\n const canShow = !invokee.hasAttribute(\"open\");\n\n if (canShow && command == \"show-modal\") {\n invokee.showModal();\n } else if (!canShow && command == \"close\") {\n invokee.close(source.value ? source.value : undefined);\n } else if (!canShow && command == \"request-close\") {\n // requestClose is only supported from Safari 18.4, so we polyfill it on older browsers\n if (!HTMLDialogElement.prototype.requestClose) {\n HTMLDialogElement.prototype.requestClose = function () {\n const cancelEvent = new Event(\"cancel\", { cancelable: true });\n this.dispatchEvent(cancelEvent);\n\n if (!cancelEvent.defaultPrevented) {\n this.close();\n }\n };\n }\n\n invokee.requestClose(source.value ? source.value : undefined);\n }\n }\n }\n\n function setupInvokeListeners(target) {\n target.addEventListener(\"click\", handleInvokerActivation, true);\n }\n\n function observeShadowRoots(ElementClass, callback) {\n const attachShadow = ElementClass.prototype.attachShadow;\n ElementClass.prototype.attachShadow = function (init) {\n const shadow = attachShadow.call(this, init);\n callback(shadow);\n return shadow;\n };\n const attachInternals = ElementClass.prototype.attachInternals;\n ElementClass.prototype.attachInternals = function () {\n const internals = attachInternals.call(this);\n if (internals.shadowRoot) callback(internals.shadowRoot);\n return internals;\n };\n }\n\n applyInvokerMixin(HTMLButtonElement);\n\n observeShadowRoots(HTMLElement, (shadow) => {\n setupInvokeListeners(shadow);\n oncommandObserver.observe(shadow, { attributeFilter: [\"oncommand\"] });\n applyOnCommandHandler(shadow.querySelectorAll(\"[oncommand]\"));\n });\n\n setupInvokeListeners(document);\n\n Object.assign(globalThis, { CommandEvent });\n}\n"],"x_google_ignoreList":[0],"mappings":"AAAA,SAAgB,GAAc,CAC5B,OACE,OAAO,kBAAsB,KAC7B,YAAa,kBAAkB,WAC/B,YAAc,WAAW,cAAgB,CAAC,EAAA,CAAG,WAAa,CAAC,EAE/D,CAMA,SAAgB,GAAQ,CACtB,SAAS,iBACP,UACC,GAAM,CACD,EAAE,MAAQ,WAAa,EAAE,YAC3B,EAAE,yBAAyB,EAC3B,EAAE,eAAe,EAErB,EACA,EACF,EAEA,SAAS,EAAU,EAAK,EAAK,EAAa,GAAM,CAC9C,OAAO,eAAe,EAAK,EAAK,CAC9B,GAAG,OAAO,yBAAyB,EAAK,CAAG,EAC3C,YACF,CAAC,CACH,CAEA,SAAS,EAAY,EAAM,CAKzB,OAJI,GAAQ,OAAO,EAAK,aAAgB,WAC/B,EAAK,YAAY,EAEtB,GAAQ,EAAK,WAAmB,EAAY,EAAK,UAAU,EACxD,CACT,CAEA,IAAM,EAA6B,IAAI,QACjC,EAAsB,IAAI,QAEhC,MAAM,UAAqB,KAAM,CAC/B,YAAY,EAAM,EAAkB,CAAC,EAAG,CACtC,MAA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AW,CAAE,CAAC,EACpE,EAAsB,EAAO,iBAAiB,aAAa,CAAC,CAC9D,CAAC,EAED,EAAqB,QAAQ,EAE7B,OAAO,OAAO,WAAY,CAAE,cAAa,CAAC,CAC5C"}
@@ -1 +1 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));exports.__toESM=s;
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));exports.__toESM=s;
@@ -1,2 +1,2 @@
1
- const e=require("../utils/utils.cjs"),t=`data-field`,n=`data-limit`,r=`aria-invalid`,i=`aria-describedby`,a=`data-indeterminate`,o=`:scope > [${t}="validation"]`,s=e.isWindows()?800:200,c=n=>{let s=[],c=[],l=n._descs||[],u=!1,p=!1;n._input?.hidden&&(n._input=void 0);for(let r of n.getElementsByTagName(`*`))if(r instanceof HTMLLabelElement&&s.push(r),!r.hidden){if(f(r))n._input?.isConnected&&n._input!==r?e.warn(`Fields should only have one input element. Use <fieldset> to group multiple fields:`,n):n._input=r;else{let i=r.getAttribute(t);i===`counter`&&(n._counter=r),i===`validation`?(c.unshift(e.useId(r)),u=!0,p||=d(r)):i&&c.push(e.useId(r))}}if(!n._input?.isConnected)return;let m=n._input;for(let t of s)e.attr(t,`for`,e.useId(m)||null);let h=n.closest(`fieldset`)?.querySelector(o);h&&!h?.hidden&&(u=!0,p||=d(h),c.unshift(e.useId(h)));let g=e.attr(m,a);g&&(m.indeterminate=g===`true`),(m.type===`radio`||m.type===`checkbox`)&&e.attr(n,`data-clickdelegatefor`,e.useId(m));let _=(e.attr(m,i)?.trim().split(/\s+/))?.filter(e=>!l.includes(e))||[];e.attr(m,i,[...c,..._].join(` `)||null),n._descs=c;let v=n._validation;u&&!v&&!m.hasAttribute(r)?(e.attr(m,r,p?`true`:null),n._validation=!0):!u&&v&&(e.attr(m,r,null),n._validation=void 0),n.handleEvent()},l={over:`%d tegn for mye`,under:`%d tegn igjen`},u=e.debounce((t,n)=>{document?.activeElement===t&&e.announce(n)},s),d=e=>{let t=e.getAttribute(`data-color`);return!t||t===`danger`},f=e=>e instanceof HTMLElement&&`validity`in e&&!(e instanceof HTMLButtonElement)&&e.type!==`hidden`;var p=class extends e.DSElement{_counter;_descs;_input;_validation;_unevents;_unmutate;connectedCallback(){this._unevents=e.on(this,`input`,this,e.QUICK_EVENT),this._unmutate=e.onMutation(this,()=>c(this),{attributeFilter:[t,n,`hidden`,`id`,`value`,a],attributes:!0,childList:!0,subtree:!0})}handleEvent(t){let{_counter:r,_input:i}=this;if(r?.isConnected&&i){let a=(Number(e.attr(r,n))||0)-i.value.length,o=a<0?`over`:`under`,s=(e.attrOrCSS(r,`data-${o}`)||l[o])?.replace(`%d`,`${Math.abs(a)}`);s||e.warn(`Missing data-${o} on:`,r),e.attr(r,`data-label`,s),e.attr(r,`data-state`,o),e.attr(r,`data-color`,a<0?`danger`:null),e.attr(i,`aria-invalid`,a<0?`true`:null),t?.type===`input`&&s&&u(i,s)}i instanceof HTMLTextAreaElement&&(i.style.setProperty(`--_ds-field-sizing`,`auto`),i.style.setProperty(`--_ds-field-sizing`,`${i.scrollHeight}px`))}disconnectedCallback(){this._unevents?.(),this._unmutate?.(),this._unevents=this._unmutate=void 0,this._input=this._counter=this._descs=this._validation=void 0}};e.customElements.define(`ds-field`,p),exports.DSFieldElement=p;
1
+ const e=require("../utils/utils.cjs"),t=`data-field`,n=`data-limit`,r=`aria-invalid`,i=`aria-describedby`,a=`data-indeterminate`,o=`:scope > [${t}="validation"]`,s=e.isWindows()?800:200,c=n=>{let s=[],c=[],l=n._descs||[],u=!1,p=!1;n._input?.hidden&&(n._input=void 0);for(let r of n.getElementsByTagName(`*`))if(r instanceof HTMLLabelElement&&s.push(r),!r.hidden)if(f(r))n._input?.isConnected&&n._input!==r?e.warn(`Fields should only have one input element. Use <fieldset> to group multiple fields:`,n):n._input=r;else{let i=r.getAttribute(t);i===`counter`&&(n._counter=r),i===`validation`?(c.unshift(e.useId(r)),u=!0,p||=d(r)):i&&c.push(e.useId(r))}if(!n._input?.isConnected)return;let m=n._input;for(let t of s)e.attr(t,`for`,e.useId(m)||null);let h=n.closest(`fieldset`)?.querySelector(o);h&&!h?.hidden&&(u=!0,p||=d(h),c.unshift(e.useId(h)));let g=e.attr(m,a);g&&(m.indeterminate=g===`true`),(m.type===`radio`||m.type===`checkbox`)&&e.attr(n,`data-clickdelegatefor`,e.useId(m));let _=(e.attr(m,i)?.trim().split(/\s+/))?.filter(e=>!l.includes(e))||[];e.attr(m,i,[...c,..._].join(` `)||null),n._descs=c;let v=n._validation;u&&!v&&!m.hasAttribute(r)?(e.attr(m,r,p?`true`:null),n._validation=!0):!u&&v&&(e.attr(m,r,null),n._validation=void 0),n.handleEvent()},l={over:`%d tegn for mye`,under:`%d tegn igjen`},u=e.debounce((t,n)=>{e.isBrowser()&&document.activeElement===t&&e.announce(n)},s),d=e=>{let t=e.getAttribute(`data-color`);return!t||t===`danger`},f=e=>e instanceof HTMLElement&&`validity`in e&&!(e instanceof HTMLButtonElement)&&e.type!==`hidden`;var p=class extends e.DSElement{_counter;_descs;_input;_validation;_unevents;_unmutate;connectedCallback(){this._unevents=e.on(this,`input`,this,e.QUICK_EVENT),this._unmutate=e.onMutation(this,()=>c(this),{attributeFilter:[t,n,`hidden`,`id`,`value`,a],attributes:!0,childList:!0,subtree:!0})}handleEvent(t){let{_counter:r,_input:i}=this;if(r?.isConnected&&i){let a=(Number(e.attr(r,n))||0)-i.value.length,o=a<0?`over`:`under`,s=(e.attrOrCSS(r,`data-${o}`)||l[o])?.replace(`%d`,`${Math.abs(a)}`);s||e.warn(`Missing data-${o} on:`,r),e.attr(r,`data-label`,s),e.attr(r,`data-state`,o),e.attr(r,`data-color`,a<0?`danger`:null),e.attr(i,`aria-invalid`,a<0?`true`:null),t?.type===`input`&&s&&u(i,s)}i instanceof HTMLTextAreaElement&&(i.style.setProperty(`--_ds-field-sizing`,`auto`),i.style.setProperty(`--_ds-field-sizing`,`${i.scrollHeight}px`))}disconnectedCallback(){this._unevents?.(),this._unmutate?.(),this._unevents=this._unmutate=void 0,this._input=this._counter=this._descs=this._validation=void 0}};e.customElements.define(`ds-field`,p),exports.DSFieldElement=p;
2
2
  //# sourceMappingURL=field.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"field.cjs","names":["isWindows","useId","attr","debounce","DSElement","on","QUICK_EVENT","onMutation","attrOrCSS","customElements"],"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":"sCAsBM,EAAa,aACb,EAAa,aACb,EAAe,eACf,EAAmB,mBACnB,EAAqB,qBACrB,EAAsB,aAAa,EAAW,gBAC9C,EAAmBA,EAAAA,UAAU,EAAI,IAAM,IAGvC,EAAuB,GAA0B,CACrD,IAAM,EAA6B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AAK,EAAM,GAAA,EACzD,QAAQ,KAAM,GAAG,KAAK,IAAI,CAAK,GAAG,EAEjC,GAAO,EAAA,KAAK,gBAAgB,EAAM,MAAO,CAAQ,EACtD,EAAA,KAAK,EAAU,aAAc,CAAK,EAClC,EAAA,KAAK,EAAU,aAAc,CAAK,EAClC,EAAA,KAAK,EAAU,aAAc,EAAQ,EAAI,SAAW,IAAI,EACxD,EAAA,KAAK,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,EAEAC,EAAAA,eAAe,OAAO,WAAY,CAAc"}
1
+ {"version":3,"file":"field.cjs","names":["isWindows","useId","attr","debounce","isBrowser","DSElement","on","QUICK_EVENT","onMutation","attrOrCSS","customElements"],"sources":["../../../src/field/field.ts"],"sourcesContent":["import {\n announce,\n attr,\n attrOrCSS,\n customElements,\n DSElement,\n debounce,\n isBrowser,\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 isBrowser() to check if environment still exits and is not unmounted by tests\n if (isBrowser() && 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":"sCAuBM,EAAa,aACb,EAAa,aACb,EAAe,eACf,EAAmB,mBACnB,EAAqB,qBACrB,EAAsB,aAAa,EAAW,gBAC9C,EAAmBA,EAAAA,UAAU,EAAI,IAAM,IAGvC,EAAuB,GAA0B,CACrD,IAAM,EAA6B,CAAC,EAC9B,EAAsB,CAAC,EACvB,EAAY,EAAM,QAAU,CAAC,EAC/B,EAAgB,GAChB,E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GAAG,EAEjC,GAAO,EAAA,KAAK,gBAAgB,EAAM,MAAO,CAAQ,EACtD,EAAA,KAAK,EAAU,aAAc,CAAK,EAClC,EAAA,KAAK,EAAU,aAAc,CAAK,EAClC,EAAA,KAAK,EAAU,aAAc,EAAQ,EAAI,SAAW,IAAI,EACxD,EAAA,KAAK,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,EAEAC,EAAAA,eAAe,OAAO,WAAY,CAAc"}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,"version",{enumerable:!0,get:function(){return`1.20.0`}});
1
+ Object.defineProperty(exports,"version",{enumerable:!0,get:function(){return`1.21.0`}});
2
2
  //# sourceMappingURL=package.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"popover.cjs","names":["isBrowser","isSupported","isPolyfilled","getComposedTarget","attr","getCSSProp","getRoot","offset","shift","limitShift","flip","size","autoUpdate","computePosition","on","QUICK_EVENT","onHotReload"],"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":"+IA0BIA,EAAAA,UAAU,GAAK,CAACC,EAAAA,YAAY,GAAK,CAACC,EAAAA,aAAa,GACjD,EAAA,MAAgB,CAAE,UAAW,SAAU,CAAC,EAe1C,MAAM,EAAQ,IAAI,IACZ,EAAa,iBACb,EAAY,qBACZ,EAAW,IAAI,IAQf,EACJ,GAEG,EAAOC,EAAAA,kBAAkB,CAAC,EAAG,EAAE,SAAU,EAAE,SAAU,EAAE,QAAU,EAAE,MAAM,EAE9E,SAAS,EACP,EACA,EACA,EACA,EACA,CAEA,IAAM,EADY,aAAc,aAAeC,EAAAA,KAAK,EAAI,SAAS,IAAM,MAC5CC,EAAAA,WAAW,EAAI,gBAAgB,EACpD,EAAO,EAAS,IAAI,CAAiB,EAI3C,GAFI,IAAa,QAAU,GAAQ,EAAK,SAAW,IACnD,GAAM,QAAQ,EACV,IAAa,UAAY,CAAC,GAAO,OACrC,GAAI,CAAC,EAAQ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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,EAAA,KAAK,EAAQ,gBAAiB,EAAK,SAAS,EACrC,CACT,CACF"}
1
+ {"version":3,"file":"popover.cjs","names":["isBrowser","isSupported","isPolyfilled","getComposedTarget","attr","getCSSProp","getRoot","on","QUICK_EVENT","onHotReload"],"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":"+IA0BIA,EAAAA,UAAU,GAAK,CAACC,EAAAA,YAAY,GAAK,CAACC,EAAAA,aAAa,GACjD,EAAA,MAAgB,CAAE,UAAW,SAAU,CAAC,EAe1C,MAAM,EAAQ,IAAI,IACZ,EAAa,iBACb,EAAY,qBACZ,EAAW,IAAI,IAQf,EACJ,GAEG,EAAOC,EAAAA,kBAAkB,CAAC,EAAG,EAAE,SAAU,EAAE,SAAU,EAAE,QAAU,EAAE,MAAM,EAE9E,SAAS,EACP,EACA,EACA,EACA,EACA,CAEA,IAAM,EADY,aAAc,aAAeC,EAAAA,KAAK,EAAI,SAAS,IAAM,MAC5CC,EAAAA,WAAW,EAAI,gBAAgB,EACpD,EAAO,EAAS,IAAI,CAAiB,EAI3C,GAFI,IAAa,QAAU,GAAQ,EAAK,SAAW,IACnD,GAAM,QAAQ,EACV,IAAa,UAAY,CAAC,GAAO,OACrC,GAAI,CAAC,EAAQ,CACX,IAAM,EAAM,EAAG,IAAM,mBAAmB,EAAG,GAAG,kBAAkB,EAAG,GAAG,IACtE,EAAU,GAAOC,EAAAA,QAAQ,CAAE,CAAC,CAAC,cAA2B,CAAG,GAAM,IAAA,EACnE,CACA,GAAI,CAAC,GAAU,IAAW,GAAO,GAAY,IAAa,EAAW,OAMrE,EAAG,MAAM,mBAAqB,iCAE9B,IACM,EAAaD,EAAAA,WAAW,EAAI,2BAA2B,EACvD,EAAYD,EAAAA,KAAK,EAAI,CAAU,GAAKA,EAAAA,KAAK,EAAQ,CAAU,GAAK,EAChE,EAAOA,EAAAA,KAAK,EAAI,CAAS,GAAKA,EAAAA,KAAK,EAAQ,CAAS,EACpD,EAAY,WAAWC,EAAAA,WAAW,EAAI,sBAAsB,CAAC,GAAK,EAClE,EAAY,EAAU,MAAM,cAAc,EAAI,SAAW,QACzD,EAAa,EAAO,SAAS,KAAe,EAA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ACpB,CACT,CACF,CACF,CAAC,EAEM,CACLF,EAAAA,GAAG,SAAU,QAAS,EAAaC,EAAAA,WAAW,EAC9CD,EAAAA,GAAG,SAAU,+BAAgC,EAAiBC,EAAAA,WAAW,EACzED,EAAAA,GAAG,SAAU,0BAA2B,EAAcC,EAAAA,WAAW,MAC3D,CAEJ,OAAO,iBAAiB,YAAY,UAAW,CAC7C,cAAe,CAAE,GAAG,EAAY,cAAe,MAAO,CAAc,EACpE,YAAa,CAAE,GAAG,EAAY,YAAa,MAAO,CAAY,EAC9D,YAAa,CAAE,GAAG,EAAY,YAAa,MAAO,CAAY,CAChE,CAAC,EACD,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,EAAA,KAAK,EAAQ,gBAAiB,EAAK,SAAS,EACrC,CACT,CACF"}
@@ -1,2 +1,2 @@
1
- const e=require("../utils/utils.cjs");require("../popover/popover.cjs");let t,n,r,i,a=0;const o=`data-color`,s=`data-color-scheme`,c=`data-size`,l=`data-tooltip`,u=e.isBrowser()&&/iPad|iPhone|iPod/.test(navigator.userAgent),d=`[${o}]`,f=`[${s}]`,p=`[${c}]`,m=`[${l}]`,h=n=>{n&&!(n instanceof HTMLElement)&&e.warn(`setTooltipElement expects an HTMLElement, got: `,n),x(),a=0,t=n||void 0},g=(e=document)=>{for(let t of e?.querySelectorAll(m)||[])v(t)},_=(e,n)=>{if(!n)return g();for(let e of n)if(e.target!==t){if(e.attributeName===l)v(e.target);else for(let t of e.addedNodes)t.nodeType===1&&(t.hasAttribute(l)?v(t):g(t))}},v=(n,r=!0)=>{let a=e.attrOrCSS(n,l)||``;if(a[0]===`#`&&(a=e.getRoot(n).getElementById(a.slice(1))?.textContent?.trim()||``),a!==(n.getAttribute(`aria-label`)||n.getAttribute(`aria-description`))){let t=e.attr(n,`role`)!==`img`&&n.textContent?.trim();e.attr(n,l,a),e.attr(n,e.ARIA_LABEL,t?null:a),e.attr(n,e.ARIA_DESC,t?a:null),n.tabIndex===-1&&e.warn(`Missing tabindex="0" attribute on: `,n)}n===i&&t?.textContent!==a&&(t&&(t.textContent=a),a&&r&&document.activeElement===n&&e.announce(a))},y=o=>{let s=e.getComposedTarget(o);if(!s||r===s||t?.contains(s))return;r=s;let c=r?.closest?.(m)||void 0;if(i!==c&&(i&&x(),i=c,c)){if(o.type===`focus`||u||300>Date.now()-a)return b();o.type===`mousemove`&&(n=setTimeout(b,300))}},b=()=>{if(!i)return x();t||=e.tag(`div`,{class:`ds-tooltip`}),t.isConnected||document.body.appendChild(t);let n=i.closest(d),r=i.closest(f),a=i.closest(p),l=n!==r&&n?.contains(r);e.attr(t,`popover`,`manual`),e.attr(t,s,r?.getAttribute(s)||null),e.attr(t,o,l&&n?.getAttribute(o)||null),e.attr(t,c,a?.getAttribute(c)||null),v(i,!1),t.showPopover(),t.dispatchEvent(new CustomEvent(`ds-toggle-source`,{bubbles:!0,composed:!0,detail:i}))},x=e=>{(e?.type!==`keydown`||e?.key===`Escape`)&&(i&&t?.isConnected&&t.popover&&t.hidePopover(),e||(a=Date.now()),clearTimeout(n),i=void 0)};e.onHotReload(`tooltip`,()=>[e.on(document,`focus mousemove`,y,e.QUICK_EVENT),e.on(document,`keydown`,x,e.QUICK_EVENT),e.onMutation(document,_,{attributeFilter:[l],attributes:!0,childList:!0,subtree:!0})]),exports.initTooltips=g,exports.setTooltipElement=h;
1
+ const e=require("../utils/utils.cjs");require("../popover/popover.cjs");let t,n,r,i,a=0;const o=`data-color`,s=`data-color-scheme`,c=`data-size`,l=`data-tooltip`,u=e.isBrowser()&&/iPad|iPhone|iPod/.test(navigator.userAgent),d=`[${o}]`,f=`[${s}]`,p=`[${c}]`,m=`[${l}]`,h=n=>{n&&!(n instanceof HTMLElement)&&e.warn(`setTooltipElement expects an HTMLElement, got: `,n),x(),a=0,t=n||void 0},g=(e=document)=>{for(let t of e?.querySelectorAll(m)||[])v(t)},_=(e,n)=>{if(!n)return g();for(let e of n)if(e.target!==t)if(e.attributeName===l)v(e.target);else for(let t of e.addedNodes)t.nodeType===1&&(t.hasAttribute(l)?v(t):g(t))},v=(n,r=!0)=>{let a=e.attrOrCSS(n,l)||``;if(a[0]===`#`&&(a=e.getRoot(n).getElementById(a.slice(1))?.textContent?.trim()||``),a!==(n.getAttribute(`aria-label`)||n.getAttribute(`aria-description`))){let t=e.attr(n,`role`)!==`img`&&n.textContent?.trim();e.attr(n,l,a),e.attr(n,e.ARIA_LABEL,t?null:a),e.attr(n,e.ARIA_DESC,t?a:null),n.tabIndex===-1&&e.warn(`Missing tabindex="0" attribute on: `,n)}n===i&&t?.textContent!==a&&(t&&(t.textContent=a),a&&r&&document.activeElement===n&&e.announce(a))},y=o=>{let s=e.getComposedTarget(o);if(!s||r===s||t?.contains(s))return;r=s;let c=r?.closest?.(m)||void 0;if(i!==c&&(i&&x(),i=c,c)){if(o.type===`focus`||u||300>Date.now()-a)return b();o.type===`mousemove`&&(n=setTimeout(b,300))}},b=()=>{if(!i)return x();t||=e.tag(`div`,{class:`ds-tooltip`}),t.isConnected||document.body.appendChild(t);let n=i.closest(d),r=i.closest(f),a=i.closest(p),l=n!==r&&n?.contains(r);e.attr(t,`popover`,`manual`),e.attr(t,s,r?.getAttribute(s)||null),e.attr(t,o,l&&n?.getAttribute(o)||null),e.attr(t,c,a?.getAttribute(c)||null),v(i,!1),t.showPopover(),t.dispatchEvent(new CustomEvent(`ds-toggle-source`,{bubbles:!0,composed:!0,detail:i}))},x=e=>{(e?.type!==`keydown`||e?.key===`Escape`)&&(i&&t?.isConnected&&t.popover&&t.hidePopover(),e||(a=Date.now()),clearTimeout(n),i=void 0)};e.onHotReload(`tooltip`,()=>[e.on(document,`focus mousemove`,y,e.QUICK_EVENT),e.on(document,`keydown`,x,e.QUICK_EVENT),e.onMutation(document,_,{attributeFilter:[l],attributes:!0,childList:!0,subtree:!0})]),exports.initTooltips=g,exports.setTooltipElement=h;
2
2
  //# sourceMappingURL=tooltip.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip.cjs","names":["isBrowser","attrOrCSS","getRoot","attr","ARIA_LABEL","ARIA_DESC","getComposedTarget","tag","onHotReload","on","QUICK_EVENT","onMutation"],"sources":["../../../src/tooltip/tooltip.ts"],"sourcesContent":["import '../popover/popover'; // Ensure popover is imported when using individual imports, since tooltip relies on it\nimport {\n ARIA_DESC,\n ARIA_LABEL,\n announce,\n attr,\n attrOrCSS,\n getComposedTarget,\n getRoot,\n isBrowser,\n on,\n onHotReload,\n onMutation,\n QUICK_EVENT,\n tag,\n warn,\n} from '../utils/utils';\n\nlet TIP: HTMLElement | undefined;\nlet TIMER: ReturnType<typeof setTimeout> | undefined;\nlet TARGET: Element | undefined; // Used to speed up mousemove handling\nlet OPEN: Element | undefined;\nlet LAST_HIDE = 0;\nconst ATTR_COLOR = 'data-color';\nconst ATTR_SCHEME = 'data-color-scheme';\nconst ATTR_SIZE = 'data-size';\nconst ATTR_TOOLTIP = 'data-tooltip';\nconst DELAY_HOVER = 300;\nconst DELAY_SKIP = 300;\nconst IS_IOS = isBrowser() && /iPad|iPhone|iPod/.test(navigator.userAgent); // Needed to omit DELAY_HOVER since iOS triggers mousemove before click\nconst SELECTOR_COLOR = `[${ATTR_COLOR}]`;\nconst SELECTOR_SCHEME = `[${ATTR_SCHEME}]`;\nconst SELECTOR_SIZE = `[${ATTR_SIZE}]`;\nconst SELECTOR_TOOLTIP = `[${ATTR_TOOLTIP}]`;\n\n/**\n * setTooltipElement\n * @description Allows setting a custom tooltip element. It does not need to, and should not, be injected to document.body, as we inject on hover to ensure React hydration works as expected.\n * @param el The HTMLElement to use as tooltip\n */\nexport const setTooltipElement = (el?: HTMLElement | null) => {\n if (el && !(el instanceof HTMLElement))\n warn('setTooltipElement expects an HTMLElement, got: ', el);\n hide(); // Reset when changing source\n LAST_HIDE = 0; // Reset last hide time to re-enable delay\n TIP = el || undefined;\n};\n\nexport const initTooltips = (\n scope: Element | ShadowRoot | Document | null = document,\n) => {\n for (const el of scope?.querySelectorAll(SELECTOR_TOOLTIP) || [])\n setupText(el);\n};\n\n// Initial run has no MutationRecords, so we set records to [null] to ensure we run the querySelectorAll for any existing elements with data-tooltip\nconst handleMutations = (_: Document, records?: MutationRecord[]) => {\n if (!records) return initTooltips();\n for (const r of records) {\n if (r.target === TIP) continue; // Ignore mutations on tooltip itself\n if (r.attributeName === ATTR_TOOLTIP) setupText(r.target as Element);\n else\n for (const el of r.addedNodes as NodeListOf<Element>) {\n if (el.nodeType !== 1) continue;\n if (el.hasAttribute(ATTR_TOOLTIP)) setupText(el);\n else initTooltips(el); // Check for any child elements with data-tooltip\n }\n }\n};\n\nconst setupText = (el: Element, canAnnounce = true) => {\n let text = attrOrCSS(el, ATTR_TOOLTIP) || '';\n\n // Allow using another element as source.\n // Note: Only checks on initial mutation, as we do not want to keep checking if the source element is removed or changed,\n // since this would be a performance issue. If the source element is removed, the tooltip will be empty and not shown.\n if (text[0] === '#')\n text = getRoot(el).getElementById(text.slice(1))?.textContent?.trim() || '';\n\n if (text !== (el.getAttribute(ARIA_LABEL) || el.getAttribute(ARIA_DESC))) {\n const hasText = attr(el, 'role') !== 'img' && el.textContent?.trim(); // If role=\"img\", ignore text\n attr(el, ATTR_TOOLTIP, text); // Set data-tooltip attribute to speed up future mutations\n attr(el, ARIA_LABEL, hasText ? null : text); // Set aria-label if element does not have text\n attr(el, ARIA_DESC, hasText ? text : null); // Set aria-description if element has text\n if ((el as HTMLElement).tabIndex === -1)\n warn('Missing tabindex=\"0\" attribute on: ', el);\n }\n if (el === OPEN && TIP?.textContent !== text) {\n if (TIP) TIP.textContent = text; // Update tooltip text if it is already open\n if (text && canAnnounce && document.activeElement === el) announce(text); // Only announce if focus is on the source\n }\n};\n\nconst handleInterest = (e: Event) => {\n const target = getComposedTarget(e);\n if (!target || TARGET === target || TIP?.contains(target as Node)) return; // Same target, or allow tooltip to be hovered (following https://www.w3.org/TR/WCAG21/#content-on-hover-or-focus)\n TARGET = target;\n\n const source = TARGET?.closest?.(SELECTOR_TOOLTIP) || undefined;\n if (OPEN === source) return; // Same source, no need to update\n if (OPEN) hide(); // Reset previous tooltip, since we are moving to a new source\n OPEN = source;\n\n if (!source) return; // No source, no need to show tooltip\n if (e.type === 'focus' || IS_IOS || DELAY_SKIP > Date.now() - LAST_HIDE)\n return show(); // Instantly show if focus or if we just closed a tooltip\n if (e.type === 'mousemove') TIMER = setTimeout(show, DELAY_HOVER); // Delay mouse showing tooltip if not already shown\n};\n\nconst show = () => {\n if (!OPEN) return hide(); // If no new anchor, cleanup previous autoUpdate\n if (!TIP) TIP = tag('div', { class: 'ds-tooltip' });\n if (!TIP.isConnected) document.body.appendChild(TIP);\n\n const color = OPEN.closest(SELECTOR_COLOR); // Match source color of source element\n const scheme = OPEN.closest(SELECTOR_SCHEME); // Match source color-scheme of source element\n const size = OPEN.closest(SELECTOR_SIZE); // Match source size of source element\n const isReset = color !== scheme && color?.contains(scheme as Node); // If data-scheme is closer to target, it will reset data-color\n\n attr(TIP, 'popover', 'manual'); // Ensure popover behavior\n attr(TIP, ATTR_SCHEME, scheme?.getAttribute(ATTR_SCHEME) || null); // Fallback to null to reset if not scheme found\n attr(TIP, ATTR_COLOR, (isReset && color?.getAttribute(ATTR_COLOR)) || null); // Fallback to null to reset if not scheme found\n attr(TIP, ATTR_SIZE, size?.getAttribute(ATTR_SIZE) || null); // Fallback to null to reset if not size found\n setupText(OPEN, false); // If mutation observer is not triggered, ensure tooltip text is updated\n TIP.showPopover();\n TIP.dispatchEvent(\n new CustomEvent('ds-toggle-source', {\n bubbles: true,\n composed: true, // Enable bubbling out of shadow DOM boundaries\n detail: OPEN, // Since showPopover({ source }) is not supported in all browsers yet\n }),\n );\n};\n\nconst hide = (event?: Partial<KeyboardEvent>) => {\n if (event?.type === 'keydown' && event?.key !== 'Escape') return;\n if (OPEN && TIP?.isConnected && TIP.popover) TIP.hidePopover(); // Only hide if connected and activated\n if (!event) LAST_HIDE = Date.now(); // If closing with keyboard, do not show next tooltip instantly\n clearTimeout(TIMER);\n OPEN = undefined;\n};\n\nonHotReload('tooltip', () => [\n on(document, 'focus mousemove', handleInterest, QUICK_EVENT),\n on(document, 'keydown', hide, QUICK_EVENT),\n onMutation(document, handleMutations, {\n attributeFilter: [ATTR_TOOLTIP],\n attributes: true,\n childList: true,\n subtree: true,\n }),\n]);\n"],"mappings":"wEAkBA,IAAI,EACA,EACA,EACA,EACA,EAAY,EAChB,MAAM,EAAa,aACb,EAAc,oBACd,EAAY,YACZ,EAAe,eAGf,EAASA,EAAAA,UAAU,GAAK,mBAAmB,KAAK,UAAU,SAAS,EACnE,EAAiB,IAAI,EAAW,GAChC,EAAkB,IAAI,EAAY,GAClC,EAAgB,IAAI,EAAU,GAC9B,EAAmB,IAAI,EAAa,GAO7B,EAAqB,GAA4B,CACxD,GAAM,EAAE,aAAc,cACxB,EAAA,KAAK,kDAAmD,CAAE,EAC5D,EAAK,EACL,EAAY,EACZ,EAAM,GAAM,IAAA,EACd,EAEa,GACX,EAAgD,WAC7C,CACH,IAAK,IAAM,KAAM,GAAO,iBAAiB,CAAgB,GAAK,CAAC,EAC7D,EAAU,CAAE,CAChB,EAGM,GAAmB,EAAa,IAA+B,CACnE,GAAI,CAAC,EAAS,OAAO,EAAa,EAClC,IAAK,IAAM,KAAK,EACV,KAAE,SAAW,EACjB,IAAI,EAAE,gBAAkB,EAAc,EAAU,EAAE,MAAiB,OAEjE,IAAK,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AI,MAAO,CAAE,MAAO,YAAa,CAAC,EAC7C,EAAI,aAAa,SAAS,KAAK,YAAY,CAAG,EAEnD,IAAM,EAAQ,EAAK,QAAQ,CAAc,EACnC,EAAS,EAAK,QAAQ,CAAe,EACrC,EAAO,EAAK,QAAQ,CAAa,EACjC,EAAU,IAAU,GAAU,GAAO,SAAS,CAAc,EAElE,EAAA,KAAK,EAAK,UAAW,QAAQ,EAC7B,EAAA,KAAK,EAAK,EAAa,GAAQ,aAAa,CAAW,GAAK,IAAI,EAChE,EAAA,KAAK,EAAK,EAAa,GAAW,GAAO,aAAa,CAAU,GAAM,IAAI,EAC1E,EAAA,KAAK,EAAK,EAAW,GAAM,aAAa,CAAS,GAAK,IAAI,EAC1D,EAAU,EAAM,EAAK,EACrB,EAAI,YAAY,EAChB,EAAI,cACF,IAAI,YAAY,mBAAoB,CAClC,QAAS,GACT,SAAU,GACV,OAAQ,CACV,CAAC,CACH,CACF,EAEM,EAAQ,GAAmC,EAC3C,GAAO,OAAS,WAAa,GAAO,MAAQ,YAC5C,GAAQ,GAAK,aAAe,EAAI,SAAS,EAAI,YAAY,EACxD,IAAO,EAAY,KAAK,IAAI,GACjC,aAAa,CAAK,EAClB,EAAO,IAAA,GACT,EAEAC,EAAAA,YAAY,cAAiB,CAC3BC,EAAAA,GAAG,SAAU,kBAAmB,EAAgBC,EAAAA,WAAW,EAC3DD,EAAAA,GAAG,SAAU,UAAW,EAAMC,EAAAA,WAAW,EACzCC,EAAAA,WAAW,SAAU,EAAiB,CACpC,gBAAiB,CAAC,CAAY,EAC9B,WAAY,GACZ,UAAW,GACX,QAAS,EACX,CAAC,CACH,CAAC"}
1
+ {"version":3,"file":"tooltip.cjs","names":["isBrowser","attrOrCSS","getRoot","attr","ARIA_LABEL","ARIA_DESC","getComposedTarget","tag","onHotReload","on","QUICK_EVENT","onMutation"],"sources":["../../../src/tooltip/tooltip.ts"],"sourcesContent":["import '../popover/popover'; // Ensure popover is imported when using individual imports, since tooltip relies on it\nimport {\n ARIA_DESC,\n ARIA_LABEL,\n announce,\n attr,\n attrOrCSS,\n getComposedTarget,\n getRoot,\n isBrowser,\n on,\n onHotReload,\n onMutation,\n QUICK_EVENT,\n tag,\n warn,\n} from '../utils/utils';\n\nlet TIP: HTMLElement | undefined;\nlet TIMER: ReturnType<typeof setTimeout> | undefined;\nlet TARGET: Element | undefined; // Used to speed up mousemove handling\nlet OPEN: Element | undefined;\nlet LAST_HIDE = 0;\nconst ATTR_COLOR = 'data-color';\nconst ATTR_SCHEME = 'data-color-scheme';\nconst ATTR_SIZE = 'data-size';\nconst ATTR_TOOLTIP = 'data-tooltip';\nconst DELAY_HOVER = 300;\nconst DELAY_SKIP = 300;\nconst IS_IOS = isBrowser() && /iPad|iPhone|iPod/.test(navigator.userAgent); // Needed to omit DELAY_HOVER since iOS triggers mousemove before click\nconst SELECTOR_COLOR = `[${ATTR_COLOR}]`;\nconst SELECTOR_SCHEME = `[${ATTR_SCHEME}]`;\nconst SELECTOR_SIZE = `[${ATTR_SIZE}]`;\nconst SELECTOR_TOOLTIP = `[${ATTR_TOOLTIP}]`;\n\n/**\n * setTooltipElement\n * @description Allows setting a custom tooltip element. It does not need to, and should not, be injected to document.body, as we inject on hover to ensure React hydration works as expected.\n * @param el The HTMLElement to use as tooltip\n */\nexport const setTooltipElement = (el?: HTMLElement | null) => {\n if (el && !(el instanceof HTMLElement))\n warn('setTooltipElement expects an HTMLElement, got: ', el);\n hide(); // Reset when changing source\n LAST_HIDE = 0; // Reset last hide time to re-enable delay\n TIP = el || undefined;\n};\n\nexport const initTooltips = (\n scope: Element | ShadowRoot | Document | null = document,\n) => {\n for (const el of scope?.querySelectorAll(SELECTOR_TOOLTIP) || [])\n setupText(el);\n};\n\n// Initial run has no MutationRecords, so we set records to [null] to ensure we run the querySelectorAll for any existing elements with data-tooltip\nconst handleMutations = (_: Document, records?: MutationRecord[]) => {\n if (!records) return initTooltips();\n for (const r of records) {\n if (r.target === TIP) continue; // Ignore mutations on tooltip itself\n if (r.attributeName === ATTR_TOOLTIP) setupText(r.target as Element);\n else\n for (const el of r.addedNodes as NodeListOf<Element>) {\n if (el.nodeType !== 1) continue;\n if (el.hasAttribute(ATTR_TOOLTIP)) setupText(el);\n else initTooltips(el); // Check for any child elements with data-tooltip\n }\n }\n};\n\nconst setupText = (el: Element, canAnnounce = true) => {\n let text = attrOrCSS(el, ATTR_TOOLTIP) || '';\n\n // Allow using another element as source.\n // Note: Only checks on initial mutation, as we do not want to keep checking if the source element is removed or changed,\n // since this would be a performance issue. If the source element is removed, the tooltip will be empty and not shown.\n if (text[0] === '#')\n text = getRoot(el).getElementById(text.slice(1))?.textContent?.trim() || '';\n\n if (text !== (el.getAttribute(ARIA_LABEL) || el.getAttribute(ARIA_DESC))) {\n const hasText = attr(el, 'role') !== 'img' && el.textContent?.trim(); // If role=\"img\", ignore text\n attr(el, ATTR_TOOLTIP, text); // Set data-tooltip attribute to speed up future mutations\n attr(el, ARIA_LABEL, hasText ? null : text); // Set aria-label if element does not have text\n attr(el, ARIA_DESC, hasText ? text : null); // Set aria-description if element has text\n if ((el as HTMLElement).tabIndex === -1)\n warn('Missing tabindex=\"0\" attribute on: ', el);\n }\n if (el === OPEN && TIP?.textContent !== text) {\n if (TIP) TIP.textContent = text; // Update tooltip text if it is already open\n if (text && canAnnounce && document.activeElement === el) announce(text); // Only announce if focus is on the source\n }\n};\n\nconst handleInterest = (e: Event) => {\n const target = getComposedTarget(e);\n if (!target || TARGET === target || TIP?.contains(target as Node)) return; // Same target, or allow tooltip to be hovered (following https://www.w3.org/TR/WCAG21/#content-on-hover-or-focus)\n TARGET = target;\n\n const source = TARGET?.closest?.(SELECTOR_TOOLTIP) || undefined;\n if (OPEN === source) return; // Same source, no need to update\n if (OPEN) hide(); // Reset previous tooltip, since we are moving to a new source\n OPEN = source;\n\n if (!source) return; // No source, no need to show tooltip\n if (e.type === 'focus' || IS_IOS || DELAY_SKIP > Date.now() - LAST_HIDE)\n return show(); // Instantly show if focus or if we just closed a tooltip\n if (e.type === 'mousemove') TIMER = setTimeout(show, DELAY_HOVER); // Delay mouse showing tooltip if not already shown\n};\n\nconst show = () => {\n if (!OPEN) return hide(); // If no new anchor, cleanup previous autoUpdate\n if (!TIP) TIP = tag('div', { class: 'ds-tooltip' });\n if (!TIP.isConnected) document.body.appendChild(TIP);\n\n const color = OPEN.closest(SELECTOR_COLOR); // Match source color of source element\n const scheme = OPEN.closest(SELECTOR_SCHEME); // Match source color-scheme of source element\n const size = OPEN.closest(SELECTOR_SIZE); // Match source size of source element\n const isReset = color !== scheme && color?.contains(scheme as Node); // If data-scheme is closer to target, it will reset data-color\n\n attr(TIP, 'popover', 'manual'); // Ensure popover behavior\n attr(TIP, ATTR_SCHEME, scheme?.getAttribute(ATTR_SCHEME) || null); // Fallback to null to reset if not scheme found\n attr(TIP, ATTR_COLOR, (isReset && color?.getAttribute(ATTR_COLOR)) || null); // Fallback to null to reset if not scheme found\n attr(TIP, ATTR_SIZE, size?.getAttribute(ATTR_SIZE) || null); // Fallback to null to reset if not size found\n setupText(OPEN, false); // If mutation observer is not triggered, ensure tooltip text is updated\n TIP.showPopover();\n TIP.dispatchEvent(\n new CustomEvent('ds-toggle-source', {\n bubbles: true,\n composed: true, // Enable bubbling out of shadow DOM boundaries\n detail: OPEN, // Since showPopover({ source }) is not supported in all browsers yet\n }),\n );\n};\n\nconst hide = (event?: Partial<KeyboardEvent>) => {\n if (event?.type === 'keydown' && event?.key !== 'Escape') return;\n if (OPEN && TIP?.isConnected && TIP.popover) TIP.hidePopover(); // Only hide if connected and activated\n if (!event) LAST_HIDE = Date.now(); // If closing with keyboard, do not show next tooltip instantly\n clearTimeout(TIMER);\n OPEN = undefined;\n};\n\nonHotReload('tooltip', () => [\n on(document, 'focus mousemove', handleInterest, QUICK_EVENT),\n on(document, 'keydown', hide, QUICK_EVENT),\n onMutation(document, handleMutations, {\n attributeFilter: [ATTR_TOOLTIP],\n attributes: true,\n childList: true,\n subtree: true,\n }),\n]);\n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,CAAC,CACH,CACF,EAEM,EAAQ,GAAmC,EAC3C,GAAO,OAAS,WAAa,GAAO,MAAQ,YAC5C,GAAQ,GAAK,aAAe,EAAI,SAAS,EAAI,YAAY,EACxD,IAAO,EAAY,KAAK,IAAI,GACjC,aAAa,CAAK,EAClB,EAAO,IAAA,GACT,EAEAC,EAAAA,YAAY,cAAiB,CAC3BC,EAAAA,GAAG,SAAU,kBAAmB,EAAgBC,EAAAA,WAAW,EAC3DD,EAAAA,GAAG,SAAU,UAAW,EAAMC,EAAAA,WAAW,EACzCC,EAAAA,WAAW,SAAU,EAAiB,CACpC,gBAAiB,CAAC,CAAY,EAC9B,WAAY,GACZ,UAAW,GACX,QAAS,EACX,CAAC,CACH,CAAC"}
@@ -141,13 +141,13 @@
141
141
  },
142
142
  {
143
143
  "kind": "javascript-module",
144
- "path": "src/details/details.ts",
144
+ "path": "src/clickdelegatefor/clickdelegatefor.ts",
145
145
  "declarations": [],
146
146
  "exports": []
147
147
  },
148
148
  {
149
149
  "kind": "javascript-module",
150
- "path": "src/clickdelegatefor/clickdelegatefor.ts",
150
+ "path": "src/details/details.ts",
151
151
  "declarations": [],
152
152
  "exports": []
153
153
  },
@@ -1,2 +1,2 @@
1
- function e(){return typeof HTMLButtonElement<`u`&&`command`in HTMLButtonElement.prototype&&`source`in((globalThis.CommandEvent||{}).prototype||{})}function t(){document.addEventListener(`invoke`,e=>{e.type==`invoke`&&e.isTrusted&&(e.stopImmediatePropagation(),e.preventDefault())},!0),document.addEventListener(`command`,e=>{e.type==`command`&&e.isTrusted&&(e.stopImmediatePropagation(),e.preventDefault())},!0);function e(e,t,n=!0){Object.defineProperty(e,t,{...Object.getOwnPropertyDescriptor(e,t),enumerable:n})}function t(e){return e&&typeof e.getRootNode==`function`?e.getRootNode():e&&e.parentNode?t(e.parentNode):e}let n=new WeakMap,r=new WeakMap;class i extends Event{constructor(e,t={}){super(e,t);let{source:i,command:a}=t;if(i!=null&&!(i instanceof Element))throw TypeError(`source must be an element`);n.set(this,i||null),r.set(this,a===void 0?``:String(a))}get[Symbol.toStringTag](){return`CommandEvent`}get source(){if(!n.has(this))throw TypeError(`illegal invocation`);let e=n.get(this);if(!(e instanceof Element))return null;let r=t(e);return r===t(this.target||document)?e:r.host}get command(){if(!r.has(this))throw TypeError(`illegal invocation`);return r.get(this)}}e(i.prototype,`source`),e(i.prototype,`command`);let a=new WeakMap;function o(e){Object.defineProperties(e.prototype,{commandForElement:{enumerable:!0,configurable:!0,set(e){if(e===null)this.removeAttribute(`commandfor`),a.delete(this);else if(e instanceof Element){this.setAttribute(`commandfor`,``);let n=t(e);t(this)===n||n===this.ownerDocument?a.set(this,e):a.delete(this)}else throw TypeError(`commandForElement must be an element or null`)},get(){if(this.localName!==`button`||this.disabled)return null;if(this.form&&this.getAttribute(`type`)!==`button`)return console.warn("Element with `commandFor` is a form participant. It should explicitly set `type=button` in order for `commandFor` to work"),null;let e=a.get(this);if(e)return e.isConnected?e:(a.delete(this),null);let n=t(this),r=this.getAttribute(`commandfor`);return(n instanceof Document||n instanceof ShadowRoot)&&r&&n.getElementById(r)||null}},command:{enumerable:!0,configurable:!0,get(){let e=this.getAttribute(`command`)||``;if(e.startsWith(`--`))return e;let t=e.toLowerCase();switch(t){case`show-modal`:case`request-close`:case`close`:case`toggle-popover`:case`hide-popover`:case`show-popover`:return t}return``},set(e){this.setAttribute(`command`,e)}}})}let s=new WeakMap;Object.defineProperties(HTMLElement.prototype,{oncommand:{enumerable:!0,configurable:!0,get(){return l.takeRecords(),s.get(this)||null},set(e){let t=s.get(this)||null;t&&this.removeEventListener(`command`,t),s.set(this,typeof e==`object`||typeof e==`function`?e:null),typeof e==`function`&&this.addEventListener(`command`,e)}}});function c(e){for(let t of e)t.oncommand=Function(`event`,t.getAttribute(`oncommand`))}let l=new MutationObserver(e=>{for(let t of e){let{target:e}=t;t.type===`childList`?c(e.querySelectorAll(`[oncommand]`)):c([e])}});l.observe(document,{subtree:!0,childList:!0,attributeFilter:[`oncommand`]}),c(document.querySelectorAll(`[oncommand]`));let u=new WeakSet;function d(e){if(u.has(e)||(u.add(e),e.defaultPrevented)||e.type!==`click`)return;let t=e.composedPath().find(e=>e.matches?.(`button[commandfor], button[command]`));if(!t)return;if(t.form&&t.getAttribute(`type`)!==`button`)throw e.preventDefault(),Error("Element with `commandFor` is a form participant. It should explicitly set `type=button` in order for `commandFor` to work. In order for it to act as a Submit button, it must not have command or commandfor attributes");if(t.hasAttribute(`command`)!==t.hasAttribute(`commandfor`)){let e=t.hasAttribute(`command`)?`command`:`commandfor`,n=t.hasAttribute(`command`)?`commandfor`:`command`;throw Error(`Element with ${e} attribute must also have a ${n} attribute to function.`)}if(t.command!==`show-popover`&&t.command!==`hide-popover`&&t.command!==`toggle-popover`&&t.command!==`show-modal`&&t.command!==`request-close`&&t.command!==`close`&&!t.command.startsWith(`--`)){console.warn(`"${t.command}" is not a valid command value. Custom commands must begin with --`);return}let n=t.commandForElement;if(!n)return;let r=new i(`command`,{command:t.command,source:t,cancelable:!0});if(n.dispatchEvent(r),r.defaultPrevented)return;let a=r.command.toLowerCase();if(n.popover){let e=!n.matches(`:popover-open`);e&&(a===`toggle-popover`||a===`show-popover`)?n.showPopover({source:t}):!e&&a===`hide-popover`&&n.hidePopover()}else if(n.localName===`dialog`){let e=!n.hasAttribute(`open`);e&&a==`show-modal`?n.showModal():!e&&a==`close`?n.close(t.value?t.value:void 0):!e&&a==`request-close`&&(HTMLDialogElement.prototype.requestClose||(HTMLDialogElement.prototype.requestClose=function(){let e=new Event(`cancel`,{cancelable:!0});this.dispatchEvent(e),e.defaultPrevented||this.close()}),n.requestClose(t.value?t.value:void 0))}}function f(e){e.addEventListener(`click`,d,!0)}function p(e,t){let n=e.prototype.attachShadow;e.prototype.attachShadow=function(e){let r=n.call(this,e);return t(r),r};let r=e.prototype.attachInternals;e.prototype.attachInternals=function(){let e=r.call(this);return e.shadowRoot&&t(e.shadowRoot),e}}o(HTMLButtonElement),p(HTMLElement,e=>{f(e),l.observe(e,{attributeFilter:[`oncommand`]}),c(e.querySelectorAll(`[oncommand]`))}),f(document),Object.assign(globalThis,{CommandEvent:i})}export{t as apply,e as isSupported};
1
+ function e(){return typeof HTMLButtonElement<`u`&&`command`in HTMLButtonElement.prototype&&`source`in((globalThis.CommandEvent||{}).prototype||{})}function t(){document.addEventListener(`command`,e=>{e.type==`command`&&e.isTrusted&&(e.stopImmediatePropagation(),e.preventDefault())},!0);function e(e,t,n=!0){Object.defineProperty(e,t,{...Object.getOwnPropertyDescriptor(e,t),enumerable:n})}function t(e){return e&&typeof e.getRootNode==`function`?e.getRootNode():e&&e.parentNode?t(e.parentNode):e}let n=new WeakMap,r=new WeakMap;class i extends Event{constructor(e,t={}){super(e,t);let{source:i,command:a}=t;if(i!=null&&!(i instanceof Element))throw TypeError(`source must be an element`);n.set(this,i||null),r.set(this,a===void 0?``:String(a))}get[Symbol.toStringTag](){return`CommandEvent`}get source(){if(!n.has(this))throw TypeError(`illegal invocation`);let e=n.get(this);if(!(e instanceof Element))return null;let r=t(e);return r===t(this.target||document)?e:r.host}get command(){if(!r.has(this))throw TypeError(`illegal invocation`);return r.get(this)}}e(i.prototype,`source`),e(i.prototype,`command`);let a=new WeakMap;function o(e){Object.defineProperties(e.prototype,{commandForElement:{enumerable:!0,configurable:!0,set(e){if(e===null)this.removeAttribute(`commandfor`),a.delete(this);else if(e instanceof Element){this.setAttribute(`commandfor`,``);let n=t(e);t(this)===n||n===this.ownerDocument?a.set(this,e):a.delete(this)}else throw TypeError(`commandForElement must be an element or null`)},get(){if(this.localName!==`button`||this.disabled)return null;if(this.form&&this.getAttribute(`type`)!==`button`)return console.warn("Element with `commandFor` is a form participant. It should explicitly set `type=button` in order for `commandFor` to work"),null;let e=a.get(this);if(e)return e.isConnected?e:(a.delete(this),null);let n=t(this),r=this.getAttribute(`commandfor`);return(n instanceof Document||n instanceof ShadowRoot)&&r&&n.getElementById(r)||null}},command:{enumerable:!0,configurable:!0,get(){let e=this.getAttribute(`command`)||``;if(e.startsWith(`--`))return e;let t=e.toLowerCase();switch(t){case`show-modal`:case`request-close`:case`close`:case`toggle-popover`:case`hide-popover`:case`show-popover`:return t}return``},set(e){this.setAttribute(`command`,e)}}})}let s=new WeakMap;Object.defineProperties(HTMLElement.prototype,{oncommand:{enumerable:!0,configurable:!0,get(){return l.takeRecords(),s.get(this)||null},set(e){let t=s.get(this)||null;t&&this.removeEventListener(`command`,t),s.set(this,typeof e==`object`||typeof e==`function`?e:null),typeof e==`function`&&this.addEventListener(`command`,e)}}});function c(e){for(let t of e)t.oncommand=Function(`event`,t.getAttribute(`oncommand`))}let l=new MutationObserver(e=>{for(let t of e){let{target:e}=t;t.type===`childList`?c(e.querySelectorAll(`[oncommand]`)):c([e])}});l.observe(document,{subtree:!0,childList:!0,attributeFilter:[`oncommand`]}),c(document.querySelectorAll(`[oncommand]`));let u=new WeakSet;function d(e){if(u.has(e)||(u.add(e),e.defaultPrevented)||e.type!==`click`)return;let t=e.composedPath().find(e=>e.matches?.(`button[commandfor], button[command]`));if(!t)return;if(t.form&&t.getAttribute(`type`)!==`button`)throw e.preventDefault(),Error("Element with `commandFor` is a form participant. It should explicitly set `type=button` in order for `commandFor` to work. In order for it to act as a Submit button, it must not have command or commandfor attributes");if(t.hasAttribute(`command`)!==t.hasAttribute(`commandfor`)){let e=t.hasAttribute(`command`)?`command`:`commandfor`,n=t.hasAttribute(`command`)?`commandfor`:`command`;throw Error(`Element with ${e} attribute must also have a ${n} attribute to function.`)}if(t.command!==`show-popover`&&t.command!==`hide-popover`&&t.command!==`toggle-popover`&&t.command!==`show-modal`&&t.command!==`request-close`&&t.command!==`close`&&!t.command.startsWith(`--`)){console.warn(`"${t.command}" is not a valid command value. Custom commands must begin with --`);return}let n=t.commandForElement;if(!n)return;let r=new i(`command`,{command:t.command,source:t,cancelable:!0});if(n.dispatchEvent(r),r.defaultPrevented)return;let a=r.command.toLowerCase();if(n.popover){let e=!n.matches(`:popover-open`);e&&(a===`toggle-popover`||a===`show-popover`)?n.showPopover({source:t}):!e&&(a===`toggle-popover`||a===`hide-popover`)&&n.hidePopover()}else if(n.localName===`dialog`){let e=!n.hasAttribute(`open`);e&&a==`show-modal`?n.showModal():!e&&a==`close`?n.close(t.value?t.value:void 0):!e&&a==`request-close`&&(HTMLDialogElement.prototype.requestClose||(HTMLDialogElement.prototype.requestClose=function(){let e=new Event(`cancel`,{cancelable:!0});this.dispatchEvent(e),e.defaultPrevented||this.close()}),n.requestClose(t.value?t.value:void 0))}}function f(e){e.addEventListener(`click`,d,!0)}function p(e,t){let n=e.prototype.attachShadow;e.prototype.attachShadow=function(e){let r=n.call(this,e);return t(r),r};let r=e.prototype.attachInternals;e.prototype.attachInternals=function(){let e=r.call(this);return e.shadowRoot&&t(e.shadowRoot),e}}o(HTMLButtonElement),p(HTMLElement,e=>{f(e),l.observe(e,{attributeFilter:[`oncommand`]}),c(e.querySelectorAll(`[oncommand]`))}),f(document),Object.assign(globalThis,{CommandEvent:i})}export{t as apply,e as isSupported};
2
2
  //# sourceMappingURL=invoker.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"invoker.js","names":[],"sources":["../../../../../../node_modules/.pnpm/invokers-polyfill@1.0.3/node_modules/invokers-polyfill/invoker.js"],"sourcesContent":["export function isSupported() {\n return (\n typeof HTMLButtonElement !== \"undefined\" &&\n \"command\" in HTMLButtonElement.prototype &&\n \"source\" in ((globalThis.CommandEvent || {}).prototype || {})\n );\n}\n\nexport function isPolyfilled() {\n return !/native code/i.test((globalThis.CommandEvent || {}).toString());\n}\n\nexport function apply() {\n // XXX: Invoker Buttons used to dispatch 'invoke' events instead of\n // 'command' events. We should ensure to prevent 'invoke' events being\n // fired in those browsers.\n // XXX: https://bugs.chromium.org/p/chromium/issues/detail?id=1523183\n // Chrome will dispatch invoke events even with the flag disabled; so\n // we need to capture those to prevent duplicate events.\n document.addEventListener(\n \"invoke\",\n (e) => {\n if (e.type == \"invoke\" && e.isTrusted) {\n e.stopImmediatePropagation();\n e.preventDefault();\n }\n },\n true,\n );\n document.addEventListener(\n \"command\",\n (e) => {\n if (e.type == \"command\" && e.isTrusted) {\n e.stopImmediatePropagation();\n e.preventDefault();\n }\n },\n true,\n );\n\n function enumerate(obj, key, enumerable = true) {\n Object.defineProperty(obj, key, {\n ...Object.getOwnPropertyDescriptor(obj, key),\n enumerable,\n });\n }\n\n function getRootNode(node) {\n if (node && typeof node.getRootNode === \"function\") {\n return node.getRootNode();\n }\n if (node && node.parentNode) return getRootNode(node.parentNode);\n return node;\n }\n\n const commandEventSourceElements = new WeakMap();\n const commandEventActions = new WeakMap();\n\n class CommandEvent extends Event {\n constructor(type, invokeEventInit = {}) {\n super(type, invokeEventInit);\n const { source, command } = invokeEventInit;\n if (source != null && !(source instanceof Element)) {\n throw new TypeError(`source must be an element`);\n }\n commandEventSourceElements.set(this, source || null);\n commandEventActions.set(\n this,\n command !== undefined ? String(command) : \"\",\n );\n }\n\n get [Symbol.toStringTag]() {\n return \"CommandEvent\";\n }\n\n get source() {\n if (!commandEventSourceElements.has(this)) {\n throw new TypeError(\"illegal invocation\");\n }\n const source = commandEventSourceElements.get(this);\n if (!(source instanceof Element)) return null;\n const invokerRoot = getRootNode(source);\n if (invokerRoot !== getRootNode(this.target || document)) {\n return invokerRoot.host;\n }\n return source;\n }\n\n get command() {\n if (!commandEventActions.has(this)) {\n throw new TypeError(\"illegal invocation\");\n }\n return commandEventActions.get(this);\n }\n }\n enumerate(CommandEvent.prototype, \"source\");\n enumerate(CommandEvent.prototype, \"command\");\n\n const invokerAssociatedElements = new WeakMap();\n\n function applyInvokerMixin(ElementClass) {\n Object.defineProperties(ElementClass.prototype, {\n commandForElement: {\n enumerable: true,\n configurable: true,\n set(targetElement) {\n if (targetElement === null) {\n this.removeAttribute(\"commandfor\");\n invokerAssociatedElements.delete(this);\n } else if (!(targetElement instanceof Element)) {\n throw new TypeError(`commandForElement must be an element or null`);\n } else {\n this.setAttribute(\"commandfor\", \"\");\n const targetRootNode = getRootNode(targetElement);\n const thisRootNode = getRootNode(this);\n if (\n thisRootNode === targetRootNode ||\n targetRootNode === this.ownerDocument\n ) {\n invokerAssociatedElements.set(this, targetElement);\n } else {\n invokerAssociatedElements.delete(this);\n }\n }\n },\n get() {\n if (this.localName !== \"button\") {\n return null;\n }\n if (this.disabled) {\n return null;\n }\n if (this.form && this.getAttribute(\"type\") !== \"button\") {\n console.warn(\n \"Element with `commandFor` is a form participant. \" +\n \"It should explicitly set `type=button` in order for `commandFor` to work\",\n );\n return null;\n }\n const targetElement = invokerAssociatedElements.get(this);\n if (targetElement) {\n if (targetElement.isConnected) {\n return targetElement;\n } else {\n invokerAssociatedElements.delete(this);\n return null;\n }\n }\n const root = getRootNode(this);\n const idref = this.getAttribute(\"commandfor\");\n if (\n (root instanceof Document || root instanceof ShadowRoot) &&\n idref\n ) {\n return root.getElementById(idref) || null;\n }\n return null;\n },\n },\n command: {\n enumerable: true,\n configurable: true,\n get() {\n const value = this.getAttribute(\"command\") || \"\";\n if (value.startsWith(\"--\")) return value;\n const valueLower = value.toLowerCase();\n switch (valueLower) {\n case \"show-modal\":\n case \"request-close\":\n case \"close\":\n case \"toggle-popover\":\n case \"hide-popover\":\n case \"show-popover\":\n return valueLower;\n }\n return \"\";\n },\n set(value) {\n this.setAttribute(\"command\", value);\n },\n },\n });\n }\n\n const onHandlers = new WeakMap();\n Object.defineProperties(HTMLElement.prototype, {\n oncommand: {\n enumerable: true,\n configurable: true,\n get() {\n oncommandObserver.takeRecords();\n return onHandlers.get(this) || null;\n },\n set(handler) {\n const existing = onHandlers.get(this) || null;\n if (existing) {\n this.removeEventListener(\"command\", existing);\n }\n onHandlers.set(\n this,\n typeof handler === \"object\" || typeof handler === \"function\"\n ? handler\n : null,\n );\n if (typeof handler == \"function\") {\n this.addEventListener(\"command\", handler);\n }\n },\n },\n });\n function applyOnCommandHandler(els) {\n for (const el of els) {\n el.oncommand = new Function(\"event\", el.getAttribute(\"oncommand\"));\n }\n }\n const oncommandObserver = new MutationObserver((records) => {\n for (const record of records) {\n const { target } = record;\n if (record.type === \"childList\") {\n applyOnCommandHandler(target.querySelectorAll(\"[oncommand]\"));\n } else {\n applyOnCommandHandler([target]);\n }\n }\n });\n oncommandObserver.observe(document, {\n subtree: true,\n childList: true,\n attributeFilter: [\"oncommand\"],\n });\n applyOnCommandHandler(document.querySelectorAll(\"[oncommand]\"));\n\n const processedEvents = new WeakSet();\n\n function handleInvokerActivation(event) {\n if (processedEvents.has(event)) return;\n\n processedEvents.add(event);\n\n if (event.defaultPrevented) return;\n if (event.type !== \"click\") return;\n const source = event.composedPath().find((el) => el.matches?.(\"button[commandfor], button[command]\"));\n if (!source) return;\n\n if (source.form && source.getAttribute(\"type\") !== \"button\") {\n event.preventDefault();\n throw new Error(\n \"Element with `commandFor` is a form participant. \" +\n \"It should explicitly set `type=button` in order for `commandFor` to work. \" +\n \"In order for it to act as a Submit button, it must not have command or commandfor attributes\",\n );\n }\n\n if (source.hasAttribute(\"command\") !== source.hasAttribute(\"commandfor\")) {\n const attr = source.hasAttribute(\"command\") ? \"command\" : \"commandfor\";\n const missing = source.hasAttribute(\"command\") ? \"commandfor\" : \"command\";\n throw new Error(\n `Element with ${attr} attribute must also have a ${missing} attribute to function.`,\n );\n }\n\n if (\n source.command !== \"show-popover\" &&\n source.command !== \"hide-popover\" &&\n source.command !== \"toggle-popover\" &&\n source.command !== \"show-modal\" &&\n source.command !== \"request-close\" &&\n source.command !== \"close\" &&\n !source.command.startsWith(\"--\")\n ) {\n console.warn(\n `\"${source.command}\" is not a valid command value. Custom commands must begin with --`,\n );\n return;\n }\n\n const invokee = source.commandForElement;\n if (!invokee) return;\n const invokeEvent = new CommandEvent(\"command\", {\n command: source.command,\n source,\n cancelable: true,\n });\n invokee.dispatchEvent(invokeEvent);\n if (invokeEvent.defaultPrevented) return;\n\n const command = invokeEvent.command.toLowerCase();\n\n if (invokee.popover) {\n const canShow = !invokee.matches(\":popover-open\");\n const shouldShow =\n canShow && (command === \"toggle-popover\" || command === \"show-popover\");\n const shouldHide = !canShow && command === \"hide-popover\";\n\n if (shouldShow) {\n invokee.showPopover({ source });\n } else if (shouldHide) {\n invokee.hidePopover();\n }\n } else if (invokee.localName === \"dialog\") {\n const canShow = !invokee.hasAttribute(\"open\");\n\n if (canShow && command == \"show-modal\") {\n invokee.showModal();\n } else if (!canShow && command == \"close\") {\n invokee.close(source.value ? source.value : undefined);\n } else if (!canShow && command == \"request-close\") {\n // requestClose is only supported from Safari 18.4, so we polyfill it on older browsers\n if (!HTMLDialogElement.prototype.requestClose) {\n HTMLDialogElement.prototype.requestClose = function () {\n const cancelEvent = new Event(\"cancel\", { cancelable: true });\n this.dispatchEvent(cancelEvent);\n\n if (!cancelEvent.defaultPrevented) {\n this.close();\n }\n };\n }\n\n invokee.requestClose(source.value ? source.value : undefined);\n }\n }\n }\n\n function setupInvokeListeners(target) {\n target.addEventListener(\"click\", handleInvokerActivation, true);\n }\n\n function observeShadowRoots(ElementClass, callback) {\n const attachShadow = ElementClass.prototype.attachShadow;\n ElementClass.prototype.attachShadow = function (init) {\n const shadow = attachShadow.call(this, init);\n callback(shadow);\n return shadow;\n };\n const attachInternals = ElementClass.prototype.attachInternals;\n ElementClass.prototype.attachInternals = function () {\n const internals = attachInternals.call(this);\n if (internals.shadowRoot) callback(internals.shadowRoot);\n return internals;\n };\n }\n\n applyInvokerMixin(HTMLButtonElement);\n\n observeShadowRoots(HTMLElement, (shadow) => {\n setupInvokeListeners(shadow);\n oncommandObserver.observe(shadow, { attributeFilter: [\"oncommand\"] });\n applyOnCommandHandler(shadow.querySelectorAll(\"[oncommand]\"));\n });\n\n setupInvokeListeners(document);\n\n Object.assign(globalThis, { CommandEvent });\n}\n"],"x_google_ignoreList":[0],"mappings":"AAAA,SAAgB,GAAc,CAC5B,OACE,OAAO,kBAAsB,KAC7B,YAAa,kBAAkB,WAC/B,YAAc,WAAW,cAAgB,CAAC,EAAA,CAAG,WAAa,CAAC,EAE/D,CAMA,SAAgB,GAAQ,CAOtB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,CAEf,GAGF,EAAQ,aAAa,EAAO,MAAQ,EAAO,MAAQ,IAAA,EAAS,EAEhE,CACF,CAEA,SAAS,EAAqB,EAAQ,CACpC,EAAO,iBAAiB,QAAS,EAAyB,EAAI,CAChE,CAEA,SAAS,EAAmB,EAAc,EAAU,CAClD,IAAM,EAAe,EAAa,UAAU,aAC5C,EAAa,UAAU,aAAe,SAAU,EAAM,CACpD,IAAM,EAAS,EAAa,KAAK,KAAM,CAAI,EAE3C,OADA,EAAS,CAAM,EACR,CACT,EACA,IAAM,EAAkB,EAAa,UAAU,gBAC/C,EAAa,UAAU,gBAAkB,UAAY,CACnD,IAAM,EAAY,EAAgB,KAAK,IAAI,EAE3C,OADI,EAAU,YAAY,EAAS,EAAU,UAAU,EAChD,CACT,CACF,CAEA,EAAkB,iBAAiB,EAEnC,EAAmB,YAAc,GAAW,CAC1C,EAAqB,CAAM,EAC3B,EAAkB,QAAQ,EAAQ,CAAE,gBAAiB,CAAC,WAAW,CAAE,CAAC,EACpE,EAAsB,EAAO,iBAAiB,aAAa,CAAC,CAC9D,CAAC,EAED,EAAqB,QAAQ,EAE7B,OAAO,OAAO,WAAY,CAAE,cAAa,CAAC,CAC5C"}
1
+ {"version":3,"file":"invoker.js","names":[],"sources":["../../../../../../node_modules/.pnpm/invokers-polyfill@1.0.4/node_modules/invokers-polyfill/invoker.js"],"sourcesContent":["export function isSupported() {\n return (\n typeof HTMLButtonElement !== \"undefined\" &&\n \"command\" in HTMLButtonElement.prototype &&\n \"source\" in ((globalThis.CommandEvent || {}).prototype || {})\n );\n}\n\nexport function isPolyfilled() {\n return !/native code/i.test((globalThis.CommandEvent || {}).toString());\n}\n\nexport function apply() {\n document.addEventListener(\n \"command\",\n (e) => {\n if (e.type == \"command\" && e.isTrusted) {\n e.stopImmediatePropagation();\n e.preventDefault();\n }\n },\n true,\n );\n\n function enumerate(obj, key, enumerable = true) {\n Object.defineProperty(obj, key, {\n ...Object.getOwnPropertyDescriptor(obj, key),\n enumerable,\n });\n }\n\n function getRootNode(node) {\n if (node && typeof node.getRootNode === \"function\") {\n return node.getRootNode();\n }\n if (node && node.parentNode) return getRootNode(node.parentNode);\n return node;\n }\n\n const commandEventSourceElements = new WeakMap();\n const commandEventActions = new WeakMap();\n\n class CommandEvent extends Event {\n constructor(type, invokeEventInit = {}) {\n super(type, invokeEventInit);\n const { source, command } = invokeEventInit;\n if (source != null && !(source instanceof Element)) {\n throw new TypeError(`source must be an element`);\n }\n commandEventSourceElements.set(this, source || null);\n commandEventActions.set(\n this,\n command !== undefined ? String(command) : \"\",\n );\n }\n\n get [Symbol.toStringTag]() {\n return \"CommandEvent\";\n }\n\n get source() {\n if (!commandEventSourceElements.has(this)) {\n throw new TypeError(\"illegal invocation\");\n }\n const source = commandEventSourceElements.get(this);\n if (!(source instanceof Element)) return null;\n const invokerRoot = getRootNode(source);\n if (invokerRoot !== getRootNode(this.target || document)) {\n return invokerRoot.host;\n }\n return source;\n }\n\n get command() {\n if (!commandEventActions.has(this)) {\n throw new TypeError(\"illegal invocation\");\n }\n return commandEventActions.get(this);\n }\n }\n enumerate(CommandEvent.prototype, \"source\");\n enumerate(CommandEvent.prototype, \"command\");\n\n const invokerAssociatedElements = new WeakMap();\n\n function applyInvokerMixin(ElementClass) {\n Object.defineProperties(ElementClass.prototype, {\n commandForElement: {\n enumerable: true,\n configurable: true,\n set(targetElement) {\n if (targetElement === null) {\n this.removeAttribute(\"commandfor\");\n invokerAssociatedElements.delete(this);\n } else if (!(targetElement instanceof Element)) {\n throw new TypeError(`commandForElement must be an element or null`);\n } else {\n this.setAttribute(\"commandfor\", \"\");\n const targetRootNode = getRootNode(targetElement);\n const thisRootNode = getRootNode(this);\n if (\n thisRootNode === targetRootNode ||\n targetRootNode === this.ownerDocument\n ) {\n invokerAssociatedElements.set(this, targetElement);\n } else {\n invokerAssociatedElements.delete(this);\n }\n }\n },\n get() {\n if (this.localName !== \"button\") {\n return null;\n }\n if (this.disabled) {\n return null;\n }\n if (this.form && this.getAttribute(\"type\") !== \"button\") {\n console.warn(\n \"Element with `commandFor` is a form participant. \" +\n \"It should explicitly set `type=button` in order for `commandFor` to work\",\n );\n return null;\n }\n const targetElement = invokerAssociatedElements.get(this);\n if (targetElement) {\n if (targetElement.isConnected) {\n return targetElement;\n } else {\n invokerAssociatedElements.delete(this);\n return null;\n }\n }\n const root = getRootNode(this);\n const idref = this.getAttribute(\"commandfor\");\n if (\n (root instanceof Document || root instanceof ShadowRoot) &&\n idref\n ) {\n return root.getElementById(idref) || null;\n }\n return null;\n },\n },\n command: {\n enumerable: true,\n configurable: true,\n get() {\n const value = this.getAttribute(\"command\") || \"\";\n if (value.startsWith(\"--\")) return value;\n const valueLower = value.toLowerCase();\n switch (valueLower) {\n case \"show-modal\":\n case \"request-close\":\n case \"close\":\n case \"toggle-popover\":\n case \"hide-popover\":\n case \"show-popover\":\n return valueLower;\n }\n return \"\";\n },\n set(value) {\n this.setAttribute(\"command\", value);\n },\n },\n });\n }\n\n const onHandlers = new WeakMap();\n Object.defineProperties(HTMLElement.prototype, {\n oncommand: {\n enumerable: true,\n configurable: true,\n get() {\n oncommandObserver.takeRecords();\n return onHandlers.get(this) || null;\n },\n set(handler) {\n const existing = onHandlers.get(this) || null;\n if (existing) {\n this.removeEventListener(\"command\", existing);\n }\n onHandlers.set(\n this,\n typeof handler === \"object\" || typeof handler === \"function\"\n ? handler\n : null,\n );\n if (typeof handler == \"function\") {\n this.addEventListener(\"command\", handler);\n }\n },\n },\n });\n function applyOnCommandHandler(els) {\n for (const el of els) {\n el.oncommand = new Function(\"event\", el.getAttribute(\"oncommand\"));\n }\n }\n const oncommandObserver = new MutationObserver((records) => {\n for (const record of records) {\n const { target } = record;\n if (record.type === \"childList\") {\n applyOnCommandHandler(target.querySelectorAll(\"[oncommand]\"));\n } else {\n applyOnCommandHandler([target]);\n }\n }\n });\n oncommandObserver.observe(document, {\n subtree: true,\n childList: true,\n attributeFilter: [\"oncommand\"],\n });\n applyOnCommandHandler(document.querySelectorAll(\"[oncommand]\"));\n\n const processedEvents = new WeakSet();\n\n function handleInvokerActivation(event) {\n if (processedEvents.has(event)) return;\n\n processedEvents.add(event);\n\n if (event.defaultPrevented) return;\n if (event.type !== \"click\") return;\n const source = event.composedPath().find((el) => el.matches?.(\"button[commandfor], button[command]\"));\n if (!source) return;\n\n if (source.form && source.getAttribute(\"type\") !== \"button\") {\n event.preventDefault();\n throw new Error(\n \"Element with `commandFor` is a form participant. \" +\n \"It should explicitly set `type=button` in order for `commandFor` to work. \" +\n \"In order for it to act as a Submit button, it must not have command or commandfor attributes\",\n );\n }\n\n if (source.hasAttribute(\"command\") !== source.hasAttribute(\"commandfor\")) {\n const attr = source.hasAttribute(\"command\") ? \"command\" : \"commandfor\";\n const missing = source.hasAttribute(\"command\") ? \"commandfor\" : \"command\";\n throw new Error(\n `Element with ${attr} attribute must also have a ${missing} attribute to function.`,\n );\n }\n\n if (\n source.command !== \"show-popover\" &&\n source.command !== \"hide-popover\" &&\n source.command !== \"toggle-popover\" &&\n source.command !== \"show-modal\" &&\n source.command !== \"request-close\" &&\n source.command !== \"close\" &&\n !source.command.startsWith(\"--\")\n ) {\n console.warn(\n `\"${source.command}\" is not a valid command value. Custom commands must begin with --`,\n );\n return;\n }\n\n const invokee = source.commandForElement;\n if (!invokee) return;\n const invokeEvent = new CommandEvent(\"command\", {\n command: source.command,\n source,\n cancelable: true,\n });\n invokee.dispatchEvent(invokeEvent);\n if (invokeEvent.defaultPrevented) return;\n\n const command = invokeEvent.command.toLowerCase();\n\n if (invokee.popover) {\n const canShow = !invokee.matches(\":popover-open\");\n const shouldShow =\n canShow && (command === \"toggle-popover\" || command === \"show-popover\");\n const shouldHide =\n !canShow &&\n (command === \"toggle-popover\" || command === \"hide-popover\");\n\n if (shouldShow) {\n invokee.showPopover({ source });\n } else if (shouldHide) {\n invokee.hidePopover();\n }\n } else if (invokee.localName === \"dialog\") {\n const canShow = !invokee.hasAttribute(\"open\");\n\n if (canShow && command == \"show-modal\") {\n invokee.showModal();\n } else if (!canShow && command == \"close\") {\n invokee.close(source.value ? source.value : undefined);\n } else if (!canShow && command == \"request-close\") {\n // requestClose is only supported from Safari 18.4, so we polyfill it on older browsers\n if (!HTMLDialogElement.prototype.requestClose) {\n HTMLDialogElement.prototype.requestClose = function () {\n const cancelEvent = new Event(\"cancel\", { cancelable: true });\n this.dispatchEvent(cancelEvent);\n\n if (!cancelEvent.defaultPrevented) {\n this.close();\n }\n };\n }\n\n invokee.requestClose(source.value ? source.value : undefined);\n }\n }\n }\n\n function setupInvokeListeners(target) {\n target.addEventListener(\"click\", handleInvokerActivation, true);\n }\n\n function observeShadowRoots(ElementClass, callback) {\n const attachShadow = ElementClass.prototype.attachShadow;\n ElementClass.prototype.attachShadow = function (init) {\n const shadow = attachShadow.call(this, init);\n callback(shadow);\n return shadow;\n };\n const attachInternals = ElementClass.prototype.attachInternals;\n ElementClass.prototype.attachInternals = function () {\n const internals = attachInternals.call(this);\n if (internals.shadowRoot) callback(internals.shadowRoot);\n return internals;\n };\n }\n\n applyInvokerMixin(HTMLButtonElement);\n\n observeShadowRoots(HTMLElement, (shadow) => {\n setupInvokeListeners(shadow);\n oncommandObserver.observe(shadow, { attributeFilter: [\"oncommand\"] });\n applyOnCommandHandler(shadow.querySelectorAll(\"[oncommand]\"));\n });\n\n setupInvokeListeners(document);\n\n Object.assign(globalThis, { CommandEvent });\n}\n"],"x_google_ignoreList":[0],"mappings":"AAAA,SAAgB,GAAc,CAC5B,OACE,OAAO,kBAAsB,KAC7B,YAAa,kBAAkB,WAC/B,YAAc,WAAW,cAAgB,CAAC,EAAA,CAAG,WAAa,CAAC,EAE/D,CAMA,SAAgB,GAAQ,CACtB,SAAS,iBACP,UACC,GAAM,CACD,EAAE,MAAQ,WAAa,EAAE,YAC3B,EAAE,yBAAyB,EAC3B,EAAE,eAAe,EAErB,EACA,EACF,EAEA,SAAS,EAAU,EAAK,EAAK,EAAa,GAAM,CAC9C,OAAO,eAAe,EAAK,EAAK,C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CAAI,EAE3C,OADA,EAAS,CAAM,EACR,CACT,EACA,IAAM,EAAkB,EAAa,UAAU,gBAC/C,EAAa,UAAU,gBAAkB,UAAY,CACnD,IAAM,EAAY,EAAgB,KAAK,IAAI,EAE3C,OADI,EAAU,YAAY,EAAS,EAAU,UAAU,EAChD,CACT,CACF,CAEA,EAAkB,iBAAiB,EAEnC,EAAmB,YAAc,GAAW,CAC1C,EAAqB,CAAM,EAC3B,EAAkB,QAAQ,EAAQ,CAAE,gBAAiB,CAAC,WAAW,CAAE,CAAC,EACpE,EAAsB,EAAO,iBAAiB,aAAa,CAAC,CAC9D,CAAC,EAED,EAAqB,QAAQ,EAE7B,OAAO,OAAO,WAAY,CAAE,cAAa,CAAC,CAC5C"}
@@ -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=`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};
1
+ import{DSElement as e,QUICK_EVENT as t,announce as n,attr as r,attrOrCSS as i,customElements as a,debounce as o,isBrowser as s,isWindows as c,on as l,onMutation as u,useId as d,warn as f}from"../utils/utils.js";const p=`data-field`,m=`data-limit`,h=`aria-invalid`,g=`aria-describedby`,_=`data-indeterminate`,v=`:scope > [${p}="validation"]`,y=c()?800:200,b=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(w(r))e._input?.isConnected&&e._input!==r?f(`Fields should only have one input element. Use <fieldset> to group multiple fields:`,e):e._input=r;else{let t=r.getAttribute(p);t===`counter`&&(e._counter=r),t===`validation`?(n.unshift(d(r)),a=!0,o||=C(r)):t&&n.push(d(r))}if(!e._input?.isConnected)return;let s=e._input;for(let e of t)r(e,`for`,d(s)||null);let c=e.closest(`fieldset`)?.querySelector(v);c&&!c?.hidden&&(a=!0,o||=C(c),n.unshift(d(c)));let l=r(s,_);l&&(s.indeterminate=l===`true`),(s.type===`radio`||s.type===`checkbox`)&&r(e,`data-clickdelegatefor`,d(s));let u=(r(s,g)?.trim().split(/\s+/))?.filter(e=>!i.includes(e))||[];r(s,g,[...n,...u].join(` `)||null),e._descs=n;let m=e._validation;a&&!m&&!s.hasAttribute(h)?(r(s,h,o?`true`:null),e._validation=!0):!a&&m&&(r(s,h,null),e._validation=void 0),e.handleEvent()},x={over:`%d tegn for mye`,under:`%d tegn igjen`},S=o((e,t)=>{s()&&document.activeElement===e&&n(t)},y),C=e=>{let t=e.getAttribute(`data-color`);return!t||t===`danger`},w=e=>e instanceof HTMLElement&&`validity`in e&&!(e instanceof HTMLButtonElement)&&e.type!==`hidden`;var T=class extends e{_counter;_descs;_input;_validation;_unevents;_unmutate;connectedCallback(){this._unevents=l(this,`input`,this,t),this._unmutate=u(this,()=>b(this),{attributeFilter:[p,m,`hidden`,`id`,`value`,_],attributes:!0,childList:!0,subtree:!0})}handleEvent(e){let{_counter:t,_input:n}=this;if(t?.isConnected&&n){let a=(Number(r(t,m))||0)-n.value.length,o=a<0?`over`:`under`,s=(i(t,`data-${o}`)||x[o])?.replace(`%d`,`${Math.abs(a)}`);s||f(`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&&S(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`,T);export{T 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_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,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,IAAI,EAAY,CAAE,EACZ,EAAM,QAAQ,aAAe,EAAM,SAAW,EAChD,EAAK,sFAAyB,CAAK,EAChC,EAAM,OAAS,MACf,CACL,IAAM,EAAO,EAAG,aAAa,CAAU,EACnC,IAAS,YAAW,EAAM,SAAW,GACrC,IAAS,cACX,EAAU,QAAQ,EAAM,CAAE,CAAC,EAC3B,EAAgB,GAChB,IAAqB,EAAe,CAAE,GAC7B,GAAM,EAAU,KAAK,EAAM,CAAE,CAAC,CAC3C,EAGF,GAAI,CAAC,EAAM,QAAQ,YA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IAAa,EAAb,cAAoC,CAAU,CAC5C,SACA,OACA,OACA,YACA,UACA,UAEA,mBAAoB,CAClB,KAAK,UAAY,EAAG,KAAM,QAAS,KAAM,CAAW,EACpD,KAAK,UAAY,EAAW,SAAY,EAAoB,IAAI,EAAG,CACjE,gBAAiB,CACf,EACA,EACA,SACA,KACA,QACA,CACF,EACA,WAAY,GACZ,UAAW,GACX,QAAS,EACX,CAAC,CACH,CACA,YAAY,EAAe,CACzB,GAAM,CAAE,WAAU,UAAW,KAE7B,GAAI,GAAU,aAAe,EAAQ,CAEnC,IAAM,GADQ,OAAO,EAAK,EAAU,CAAU,CAAC,GAAK,GAC9B,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,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
+ {"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 isBrowser,\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 isBrowser() to check if environment still exits and is not unmounted by tests\n if (isBrowser() && 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":"mNAuBA,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,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,CAAU,EACnC,IAAS,YAAW,EAAM,SAAW,GACrC,IAAS,cACX,EAAU,QAAQ,EAAM,CAAE,CAAC,EAC3B,EAAgB,GAChB,IAAqB,EAAe,CAAE,GAC7B,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,CAAmB,EAG9C,GAAsB,CAAC,GAAoB,SAC7C,EAAgB,GAChB,IAAqB,EAAe,CAAkB,EACtD,EAAU,QAAQ,EAAM,CAAkB,CAAC,GAK7C,IAAM,EAAgB,EAAK,EAAO,CAAkB,EAChD,IAAe,EAAM,cAAgB,IAA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AAe,EAAQ,CAEnC,IAAM,GADQ,OAAO,EAAK,EAAU,CAAU,CAAC,GAAK,GAC9B,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,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
- var e=`1.20.0`;export{e as version};
1
+ var e=`1.21.0`;export{e as version};
2
2
  //# sourceMappingURL=package.js.map
@@ -1,2 +1,2 @@
1
- import{ARIA_DESC as e,ARIA_LABEL as t,QUICK_EVENT as n,announce as r,attr as i,attrOrCSS as a,getComposedTarget as o,getRoot as s,isBrowser as c,on as l,onHotReload as u,onMutation as d,tag as f,warn as p}from"../utils/utils.js";import"../popover/popover.js";let m,h,g,_,v=0;const y=`data-color`,b=`data-color-scheme`,x=`data-size`,S=`data-tooltip`,C=c()&&/iPad|iPhone|iPod/.test(navigator.userAgent),w=`[${y}]`,T=`[${b}]`,E=`[${x}]`,D=`[${S}]`,O=e=>{e&&!(e instanceof HTMLElement)&&p(`setTooltipElement expects an HTMLElement, got: `,e),P(),v=0,m=e||void 0},k=(e=document)=>{for(let t of e?.querySelectorAll(D)||[])j(t)},A=(e,t)=>{if(!t)return k();for(let e of t)if(e.target!==m){if(e.attributeName===S)j(e.target);else for(let t of e.addedNodes)t.nodeType===1&&(t.hasAttribute(S)?j(t):k(t))}},j=(n,o=!0)=>{let c=a(n,S)||``;if(c[0]===`#`&&(c=s(n).getElementById(c.slice(1))?.textContent?.trim()||``),c!==(n.getAttribute(`aria-label`)||n.getAttribute(`aria-description`))){let r=i(n,`role`)!==`img`&&n.textContent?.trim();i(n,S,c),i(n,t,r?null:c),i(n,e,r?c:null),n.tabIndex===-1&&p(`Missing tabindex="0" attribute on: `,n)}n===_&&m?.textContent!==c&&(m&&(m.textContent=c),c&&o&&document.activeElement===n&&r(c))},M=e=>{let t=o(e);if(!t||g===t||m?.contains(t))return;g=t;let n=g?.closest?.(D)||void 0;if(_!==n&&(_&&P(),_=n,n)){if(e.type===`focus`||C||300>Date.now()-v)return N();e.type===`mousemove`&&(h=setTimeout(N,300))}},N=()=>{if(!_)return P();m||=f(`div`,{class:`ds-tooltip`}),m.isConnected||document.body.appendChild(m);let e=_.closest(w),t=_.closest(T),n=_.closest(E),r=e!==t&&e?.contains(t);i(m,`popover`,`manual`),i(m,b,t?.getAttribute(b)||null),i(m,y,r&&e?.getAttribute(y)||null),i(m,x,n?.getAttribute(x)||null),j(_,!1),m.showPopover(),m.dispatchEvent(new CustomEvent(`ds-toggle-source`,{bubbles:!0,composed:!0,detail:_}))},P=e=>{(e?.type!==`keydown`||e?.key===`Escape`)&&(_&&m?.isConnected&&m.popover&&m.hidePopover(),e||(v=Date.now()),clearTimeout(h),_=void 0)};u(`tooltip`,()=>[l(document,`focus mousemove`,M,n),l(document,`keydown`,P,n),d(document,A,{attributeFilter:[S],attributes:!0,childList:!0,subtree:!0})]);export{k as initTooltips,O as setTooltipElement};
1
+ import{ARIA_DESC as e,ARIA_LABEL as t,QUICK_EVENT as n,announce as r,attr as i,attrOrCSS as a,getComposedTarget as o,getRoot as s,isBrowser as c,on as l,onHotReload as u,onMutation as d,tag as f,warn as p}from"../utils/utils.js";import"../popover/popover.js";let m,h,g,_,v=0;const y=`data-color`,b=`data-color-scheme`,x=`data-size`,S=`data-tooltip`,C=c()&&/iPad|iPhone|iPod/.test(navigator.userAgent),w=`[${y}]`,T=`[${b}]`,E=`[${x}]`,D=`[${S}]`,O=e=>{e&&!(e instanceof HTMLElement)&&p(`setTooltipElement expects an HTMLElement, got: `,e),P(),v=0,m=e||void 0},k=(e=document)=>{for(let t of e?.querySelectorAll(D)||[])j(t)},A=(e,t)=>{if(!t)return k();for(let e of t)if(e.target!==m)if(e.attributeName===S)j(e.target);else for(let t of e.addedNodes)t.nodeType===1&&(t.hasAttribute(S)?j(t):k(t))},j=(n,o=!0)=>{let c=a(n,S)||``;if(c[0]===`#`&&(c=s(n).getElementById(c.slice(1))?.textContent?.trim()||``),c!==(n.getAttribute(`aria-label`)||n.getAttribute(`aria-description`))){let r=i(n,`role`)!==`img`&&n.textContent?.trim();i(n,S,c),i(n,t,r?null:c),i(n,e,r?c:null),n.tabIndex===-1&&p(`Missing tabindex="0" attribute on: `,n)}n===_&&m?.textContent!==c&&(m&&(m.textContent=c),c&&o&&document.activeElement===n&&r(c))},M=e=>{let t=o(e);if(!t||g===t||m?.contains(t))return;g=t;let n=g?.closest?.(D)||void 0;if(_!==n&&(_&&P(),_=n,n)){if(e.type===`focus`||C||300>Date.now()-v)return N();e.type===`mousemove`&&(h=setTimeout(N,300))}},N=()=>{if(!_)return P();m||=f(`div`,{class:`ds-tooltip`}),m.isConnected||document.body.appendChild(m);let e=_.closest(w),t=_.closest(T),n=_.closest(E),r=e!==t&&e?.contains(t);i(m,`popover`,`manual`),i(m,b,t?.getAttribute(b)||null),i(m,y,r&&e?.getAttribute(y)||null),i(m,x,n?.getAttribute(x)||null),j(_,!1),m.showPopover(),m.dispatchEvent(new CustomEvent(`ds-toggle-source`,{bubbles:!0,composed:!0,detail:_}))},P=e=>{(e?.type!==`keydown`||e?.key===`Escape`)&&(_&&m?.isConnected&&m.popover&&m.hidePopover(),e||(v=Date.now()),clearTimeout(h),_=void 0)};u(`tooltip`,()=>[l(document,`focus mousemove`,M,n),l(document,`keydown`,P,n),d(document,A,{attributeFilter:[S],attributes:!0,childList:!0,subtree:!0})]);export{k as initTooltips,O as setTooltipElement};
2
2
  //# sourceMappingURL=tooltip.js.map