@digdir/designsystemet-web 1.14.0 → 1.15.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.
Files changed (43) hide show
  1. package/dist/cjs/_vendors/invokers-polyfill/invoker.cjs.map +1 -1
  2. package/dist/cjs/breadcrumbs/breadcrumbs.cjs.map +1 -1
  3. package/dist/cjs/clickdelegatefor/clickdelegatefor.cjs.map +1 -1
  4. package/dist/cjs/dialog/dialog.cjs.map +1 -1
  5. package/dist/cjs/error-summary/error-summary.cjs +2 -1
  6. package/dist/cjs/error-summary/error-summary.cjs.map +1 -1
  7. package/dist/cjs/field/field.cjs.map +1 -1
  8. package/dist/cjs/fieldset/fieldset.cjs.map +1 -1
  9. package/dist/cjs/index.cjs.map +1 -1
  10. package/dist/cjs/pagination/pagination.cjs.map +1 -1
  11. package/dist/cjs/popover/popover.cjs +1 -1
  12. package/dist/cjs/popover/popover.cjs.map +1 -1
  13. package/dist/cjs/readonly/readonly.cjs.map +1 -1
  14. package/dist/cjs/suggestion/suggestion.cjs.map +1 -1
  15. package/dist/cjs/tabs/tabs.cjs +1 -1
  16. package/dist/cjs/tabs/tabs.cjs.map +1 -1
  17. package/dist/cjs/toggle-group/toggle-group.cjs.map +1 -1
  18. package/dist/cjs/tooltip/tooltip.cjs.map +1 -1
  19. package/dist/cjs/utils/utils.cjs.map +1 -1
  20. package/dist/esm/_vendors/invokers-polyfill/invoker.js.map +1 -1
  21. package/dist/esm/breadcrumbs/breadcrumbs.js.map +1 -1
  22. package/dist/esm/clickdelegatefor/clickdelegatefor.js.map +1 -1
  23. package/dist/esm/dialog/dialog.js.map +1 -1
  24. package/dist/esm/error-summary/error-summary.js +2 -1
  25. package/dist/esm/error-summary/error-summary.js.map +1 -1
  26. package/dist/esm/field/field.js.map +1 -1
  27. package/dist/esm/fieldset/fieldset.js.map +1 -1
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/pagination/pagination.js.map +1 -1
  30. package/dist/esm/popover/popover.js +1 -1
  31. package/dist/esm/popover/popover.js.map +1 -1
  32. package/dist/esm/readonly/readonly.js.map +1 -1
  33. package/dist/esm/suggestion/suggestion.js.map +1 -1
  34. package/dist/esm/tabs/tabs.js.map +1 -1
  35. package/dist/esm/toggle-group/toggle-group.js.map +1 -1
  36. package/dist/esm/tooltip/tooltip.js.map +1 -1
  37. package/dist/esm/utils/utils.js.map +1 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +6 -2
  40. package/dist/index.js.map +1 -1
  41. package/dist/umd/index.js +3 -2
  42. package/dist/umd/index.js.map +1 -1
  43. package/package.json +6 -6
@@ -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,EAAE,EAAE,WAAa,EAAE,EAQhE,SAAgB,GAAQ,CAOtB,SAAS,iBACP,SACC,GAAM,CACD,EAAE,MAAQ,UAAY,EAAE,YAC1B,EAAE,0BAA0B,CAC5B,EAAE,gBAAgB,GAGtB,GACD,CACD,SAAS,iBACP,UACC,GAAM,CACD,EAAE,MAAQ,WAAa,EAAE,YAC3B,EAAE,0BAA0B,CAC5B,EAAE,gBAAgB,GAGtB,GACD,CAED,SAAS,EAAU,EAAK,EAAK,EAAa,GAAM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EAAY,EAAgB,KAAK,KAAK,CAE5C,OADI,EAAU,YAAY,EAAS,EAAU,WAAW,CACjD,GAIX,EAAkB,kBAAkB,CAEpC,EAAmB,YAAc,GAAW,CAC1C,EAAqB,EAAO,CAC5B,EAAkB,QAAQ,EAAQ,CAAE,gBAAiB,CAAC,YAAY,CAAE,CAAC,CACrE,EAAsB,EAAO,iBAAiB,cAAc,CAAC,EAC7D,CAEF,EAAqB,SAAS,CAE9B,OAAO,OAAO,WAAY,CAAE,eAAc,CAAC"}
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,GAAG,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,yBAAyB,EAAK,CAAG,EAC3C,YAC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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 +1 @@
1
- {"version":3,"file":"breadcrumbs.cjs","names":["DSElement","debounce","attrOrCSS","on","onMutation","customElements"],"sources":["../../../src/breadcrumbs/breadcrumbs.ts"],"sourcesContent":["import {\n attr,\n attrOrCSS,\n customElements,\n DSElement,\n debounce,\n on,\n onMutation,\n} from '../utils/utils';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-breadcrumbs': DSBreadcrumbsElement;\n }\n}\n\nconst ATTR_LABEL = 'aria-label';\n\nexport class DSBreadcrumbsElement extends DSElement {\n _items?: HTMLCollectionOf<HTMLAnchorElement>; // Using underscore instead of private fields for backwards compatibility\n _label: string | null = null;\n _unresize?: () => void;\n _unmutate?: () => void;\n\n static get observedAttributes() {\n return [ATTR_LABEL]; // Using ES2015 syntax for backwards compatibility\n }\n connectedCallback() {\n const resize = debounce(() => render(this), 100);\n this._label = attrOrCSS(this, ATTR_LABEL); // Label can have been set by attributeChangedCallback before connectedCallback\n this._items = this.getElementsByTagName('a'); // Speed up by caching HTMLCollection\n this._unresize = on(window, 'resize', resize);\n this._unmutate = onMutation(this, render, {\n childList: true,\n subtree: true,\n });\n }\n attributeChangedCallback(_name: string, _prev?: string, next?: string) {\n if (!this._unmutate || !next) return; // Ensure we do not run unless connected and we have a label to set\n this._label = next; // Update cacheed label if aria-label attribute changes\n render(this);\n }\n disconnectedCallback() {\n this._unresize?.();\n this._unmutate?.();\n this._unresize = this._unmutate = this._items = undefined;\n }\n}\n\nconst render = (self: DSBreadcrumbsElement) => {\n const lastItem = self._items?.[self._items.length - 1];\n const lastItemInList = lastItem?.parentElement === self ? null : lastItem;\n const isListHidden = !lastItemInList?.offsetHeight;\n\n attr(self, 'role', isListHidden ? null : 'navigation');\n attr(self, ATTR_LABEL, isListHidden ? null : self._label); // Remove aria-label if list is hidden to prevent screen readers from announcing as breadcrumbs\n\n for (const item of self._items || [])\n attr(item, 'aria-current', item === lastItemInList ? 'page' : null);\n};\n\ncustomElements.define('ds-breadcrumbs', DSBreadcrumbsElement);\n"],"mappings":"sCAgBM,EAAa,aAEnB,IAAa,EAAb,cAA0CA,EAAAA,SAAU,CAClD,OACA,OAAwB,KACxB,UACA,UAEA,WAAW,oBAAqB,CAC9B,MAAO,CAAC,EAAW,CAErB,mBAAoB,CAClB,IAAM,EAASC,EAAAA,aAAe,EAAO,KAAK,CAAE,IAAI,CAChD,KAAK,OAASC,EAAAA,UAAU,KAAM,EAAW,CACzC,KAAK,OAAS,KAAK,qBAAqB,IAAI,CAC5C,KAAK,UAAYC,EAAAA,GAAG,OAAQ,SAAU,EAAO,CAC7C,KAAK,UAAYC,EAAAA,WAAW,KAAM,EAAQ,CACxC,UAAW,GACX,QAAS,GACV,CAAC,CAEJ,yBAAyB,EAAe,EAAgB,EAAe,CACjE,CAAC,KAAK,WAAa,CAAC,IACxB,KAAK,OAAS,EACd,EAAO,KAAK,EAEd,sBAAuB,CACrB,KAAK,aAAa,CAClB,KAAK,aAAa,CAClB,KAAK,UAAY,KAAK,UAAY,KAAK,OAAS,IAAA,KAIpD,MAAM,EAAU,GAA+B,CAC7C,IAAM,EAAW,EAAK,SAAS,EAAK,OAAO,OAAS,GAC9C,EAAiB,GAAU,gBAAkB,EAAO,KAAO,EAC3D,EAAe,CAAC,GAAgB,aAEtC,EAAA,KAAK,EAAM,OAAQ,EAAe,KAAO,aAAa,CACtD,EAAA,KAAK,EAAM,EAAY,EAAe,KAAO,EAAK,OAAO,CAEzD,IAAK,IAAM,KAAQ,EAAK,QAAU,EAAE,CAClC,EAAA,KAAK,EAAM,eAAgB,IAAS,EAAiB,OAAS,KAAK,EAGvEC,EAAAA,eAAe,OAAO,iBAAkB,EAAqB"}
1
+ {"version":3,"file":"breadcrumbs.cjs","names":["DSElement","debounce","attrOrCSS","on","onMutation","customElements"],"sources":["../../../src/breadcrumbs/breadcrumbs.ts"],"sourcesContent":["import {\n attr,\n attrOrCSS,\n customElements,\n DSElement,\n debounce,\n on,\n onMutation,\n} from '../utils/utils';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-breadcrumbs': DSBreadcrumbsElement;\n }\n}\n\nconst ATTR_LABEL = 'aria-label';\n\nexport class DSBreadcrumbsElement extends DSElement {\n _items?: HTMLCollectionOf<HTMLAnchorElement>; // Using underscore instead of private fields for backwards compatibility\n _label: string | null = null;\n _unresize?: () => void;\n _unmutate?: () => void;\n\n static get observedAttributes() {\n return [ATTR_LABEL]; // Using ES2015 syntax for backwards compatibility\n }\n connectedCallback() {\n const resize = debounce(() => render(this), 100);\n this._label = attrOrCSS(this, ATTR_LABEL); // Label can have been set by attributeChangedCallback before connectedCallback\n this._items = this.getElementsByTagName('a'); // Speed up by caching HTMLCollection\n this._unresize = on(window, 'resize', resize);\n this._unmutate = onMutation(this, render, {\n childList: true,\n subtree: true,\n });\n }\n attributeChangedCallback(_name: string, _prev?: string, next?: string) {\n if (!this._unmutate || !next) return; // Ensure we do not run unless connected and we have a label to set\n this._label = next; // Update cacheed label if aria-label attribute changes\n render(this);\n }\n disconnectedCallback() {\n this._unresize?.();\n this._unmutate?.();\n this._unresize = this._unmutate = this._items = undefined;\n }\n}\n\nconst render = (self: DSBreadcrumbsElement) => {\n const lastItem = self._items?.[self._items.length - 1];\n const lastItemInList = lastItem?.parentElement === self ? null : lastItem;\n const isListHidden = !lastItemInList?.offsetHeight;\n\n attr(self, 'role', isListHidden ? null : 'navigation');\n attr(self, ATTR_LABEL, isListHidden ? null : self._label); // Remove aria-label if list is hidden to prevent screen readers from announcing as breadcrumbs\n\n for (const item of self._items || [])\n attr(item, 'aria-current', item === lastItemInList ? 'page' : null);\n};\n\ncustomElements.define('ds-breadcrumbs', DSBreadcrumbsElement);\n"],"mappings":"sCAgBM,EAAa,aAEnB,IAAa,EAAb,cAA0CA,EAAAA,SAAU,CAClD,OACA,OAAwB,KACxB,UACA,UAEA,WAAW,oBAAqB,CAC9B,MAAO,CAAC,CAAU,CACpB,CACA,mBAAoB,CAClB,IAAM,EAASC,EAAAA,aAAe,EAAO,IAAI,EAAG,GAAG,EAC/C,KAAK,OAASC,EAAAA,UAAU,KAAM,CAAU,EACxC,KAAK,OAAS,KAAK,qBAAqB,GAAG,EAC3C,KAAK,UAAYC,EAAAA,GAAG,OAAQ,SAAU,CAAM,EAC5C,KAAK,UAAYC,EAAAA,WAAW,KAAM,EAAQ,CACxC,UAAW,GACX,QAAS,EACX,CAAC,CACH,CACA,yBAAyB,EAAe,EAAgB,EAAe,CACjE,CAAC,KAAK,WAAa,CAAC,IACxB,KAAK,OAAS,EACd,EAAO,IAAI,EACb,CACA,sBAAuB,CACrB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,UAAY,KAAK,UAAY,KAAK,OAAS,IAAA,EAClD,CACF,EAEA,MAAM,EAAU,GAA+B,CAC7C,IAAM,EAAW,EAAK,SAAS,EAAK,OAAO,OAAS,GAC9C,EAAiB,GAAU,gBAAkB,EAAO,KAAO,EAC3D,EAAe,CAAC,GAAgB,aAEtC,EAAA,KAAK,EAAM,OAAQ,EAAe,KAAO,YAAY,EACrD,EAAA,KAAK,EAAM,EAAY,EAAe,KAAO,EAAK,MAAM,EAExD,IAAK,IAAM,KAAQ,EAAK,QAAU,CAAC,EACjC,EAAA,KAAK,EAAM,eAAgB,IAAS,EAAiB,OAAS,IAAI,CACtE,EAEAC,EAAAA,eAAe,OAAO,iBAAkB,CAAoB"}
@@ -1 +1 @@
1
- {"version":3,"file":"clickdelegatefor.cjs","names":["onHotReload","on","QUICK_EVENT"],"sources":["../../../src/clickdelegatefor/clickdelegatefor.ts"],"sourcesContent":["// Adding support for click deletagtion, following\n// https://open-ui.org/components/link-area-delegation-explainer/\n// and https://github.com/openui/open-ui/issues/1104#issuecomment-3151387080\nimport { on, onHotReload, QUICK_EVENT } from '../utils/utils';\n\nconst CLASS_HOVER = ':click-delegate-hover';\nconst ATTR_CLICKDELEGATEFOR = 'data-clickdelegatefor';\nconst SELECTOR_CLICKDELEGATEFOR = `[${ATTR_CLICKDELEGATEFOR}]`;\nconst SELECTOR_SKIP =\n 'a,button,label,input,select,textarea,details,dialog,[role=\"button\"],[popover],[contenteditable]';\n\nconst handleClickDelegateFor = (event: MouseEvent) => {\n const isNewTab = event.button === 1 || event.metaKey || event.ctrlKey; // Middle click or cmd/ctrl + click should open in new tab\n const delegateTarget = event.button < 2 && getDelegateTarget(event); // Only accept left or middle clicks\n\n if (!delegateTarget || delegateTarget.contains(event.target as Node)) return; // Only proxy event if delegated target isn't part of the original target\n if (isNewTab && delegateTarget instanceof HTMLAnchorElement)\n return window.open(delegateTarget.href, undefined, delegateTarget.rel); // If middle click or cmd/ctrl click on link, open in new tab\n event.stopImmediatePropagation(); // We'll trigger a new click event anyway, so prevent actions on this one\n delegateTarget.click(); // Forward click to the clickable element\n};\n\nlet HOVER: Element | undefined;\nconst handleMouseOver = (event: Event) => {\n const delegateTarget = getDelegateTarget(event);\n if (HOVER === delegateTarget) return; // No change\n if (HOVER) HOVER.classList.remove(CLASS_HOVER);\n if (delegateTarget) delegateTarget.classList.add(CLASS_HOVER);\n HOVER = delegateTarget;\n};\n\nconst getDelegateTarget = ({ target: el }: Event) => {\n const scope =\n el instanceof Element ? el.closest(SELECTOR_CLICKDELEGATEFOR) : null;\n const id = scope?.getAttribute(ATTR_CLICKDELEGATEFOR);\n const target = (id && document.getElementById(id)) || undefined;\n const skip = target && (el as Element).closest(SELECTOR_SKIP); // Ignore if interactive\n\n return (!skip || skip === target) && !(target as HTMLInputElement)?.disabled\n ? target\n : undefined; // Skip disabled inputs\n};\n\nonHotReload('clickdelegatefor', () => [\n on(window, 'click auxclick', handleClickDelegateFor as EventListener, true), // Use capture to ensure we run before other click listeners\n on(document, 'mouseover', handleMouseOver, QUICK_EVENT), // Use passive for better performance\n]);\n"],"mappings":"sCAKM,EAAc,wBACd,EAAwB,wBACxB,EAA4B,IAAI,EAAsB,GAItD,EAA0B,GAAsB,CACpD,IAAM,EAAW,EAAM,SAAW,GAAK,EAAM,SAAW,EAAM,QACxD,EAAiB,EAAM,OAAS,GAAK,EAAkB,EAAM,CAE/D,MAAC,GAAkB,EAAe,SAAS,EAAM,OAAe,EACpE,IAAI,GAAY,aAA0B,kBACxC,OAAO,OAAO,KAAK,EAAe,KAAM,IAAA,GAAW,EAAe,IAAI,CACxE,EAAM,0BAA0B,CAChC,EAAe,OAAO,GAGxB,IAAI,EACJ,MAAM,EAAmB,GAAiB,CACxC,IAAM,EAAiB,EAAkB,EAAM,CAC3C,IAAU,IACV,GAAO,EAAM,UAAU,OAAO,EAAY,CAC1C,GAAgB,EAAe,UAAU,IAAI,EAAY,CAC7D,EAAQ,IAGJ,GAAqB,CAAE,OAAQ,KAAgB,CAGnD,IAAM,GADJ,aAAc,QAAU,EAAG,QAAQ,EAA0B,CAAG,OAChD,aAAa,EAAsB,CAC/C,EAAU,GAAM,SAAS,eAAe,EAAG,EAAK,IAAA,GAChD,EAAO,GAAW,EAAe,QAAQ,kGAAc,CAE7D,OAAQ,CAAC,GAAQ,IAAS,IAAW,CAAE,GAA6B,SAChE,EACA,IAAA,IAGNA,EAAAA,YAAY,uBAA0B,CACpCC,EAAAA,GAAG,OAAQ,iBAAkB,EAAyC,GAAK,CAC3EA,EAAAA,GAAG,SAAU,YAAa,EAAiBC,EAAAA,YAAY,CACxD,CAAC"}
1
+ {"version":3,"file":"clickdelegatefor.cjs","names":["onHotReload","on","QUICK_EVENT"],"sources":["../../../src/clickdelegatefor/clickdelegatefor.ts"],"sourcesContent":["// Adding support for click deletagtion, following\n// https://open-ui.org/components/link-area-delegation-explainer/\n// and https://github.com/openui/open-ui/issues/1104#issuecomment-3151387080\nimport { on, onHotReload, QUICK_EVENT } from '../utils/utils';\n\nconst CLASS_HOVER = ':click-delegate-hover';\nconst ATTR_CLICKDELEGATEFOR = 'data-clickdelegatefor';\nconst SELECTOR_CLICKDELEGATEFOR = `[${ATTR_CLICKDELEGATEFOR}]`;\nconst SELECTOR_SKIP =\n 'a,button,label,input,select,textarea,details,dialog,[role=\"button\"],[popover],[contenteditable]';\n\nconst handleClickDelegateFor = (event: MouseEvent) => {\n const isNewTab = event.button === 1 || event.metaKey || event.ctrlKey; // Middle click or cmd/ctrl + click should open in new tab\n const delegateTarget = event.button < 2 && getDelegateTarget(event); // Only accept left or middle clicks\n\n if (!delegateTarget || delegateTarget.contains(event.target as Node)) return; // Only proxy event if delegated target isn't part of the original target\n if (isNewTab && delegateTarget instanceof HTMLAnchorElement)\n return window.open(delegateTarget.href, undefined, delegateTarget.rel); // If middle click or cmd/ctrl click on link, open in new tab\n event.stopImmediatePropagation(); // We'll trigger a new click event anyway, so prevent actions on this one\n delegateTarget.click(); // Forward click to the clickable element\n};\n\nlet HOVER: Element | undefined;\nconst handleMouseOver = (event: Event) => {\n const delegateTarget = getDelegateTarget(event);\n if (HOVER === delegateTarget) return; // No change\n if (HOVER) HOVER.classList.remove(CLASS_HOVER);\n if (delegateTarget) delegateTarget.classList.add(CLASS_HOVER);\n HOVER = delegateTarget;\n};\n\nconst getDelegateTarget = ({ target: el }: Event) => {\n const scope =\n el instanceof Element ? el.closest(SELECTOR_CLICKDELEGATEFOR) : null;\n const id = scope?.getAttribute(ATTR_CLICKDELEGATEFOR);\n const target = (id && document.getElementById(id)) || undefined;\n const skip = target && (el as Element).closest(SELECTOR_SKIP); // Ignore if interactive\n\n return (!skip || skip === target) && !(target as HTMLInputElement)?.disabled\n ? target\n : undefined; // Skip disabled inputs\n};\n\nonHotReload('clickdelegatefor', () => [\n on(window, 'click auxclick', handleClickDelegateFor as EventListener, true), // Use capture to ensure we run before other click listeners\n on(document, 'mouseover', handleMouseOver, QUICK_EVENT), // Use passive for better performance\n]);\n"],"mappings":"sCAKM,EAAc,wBACd,EAAwB,wBACxB,EAA4B,IAAI,EAAsB,GAItD,EAA0B,GAAsB,CACpD,IAAM,EAAW,EAAM,SAAW,GAAK,EAAM,SAAW,EAAM,QACxD,EAAiB,EAAM,OAAS,GAAK,EAAkB,CAAK,EAE9D,MAAC,GAAkB,EAAe,SAAS,EAAM,MAAc,GACnE,IAAI,GAAY,aAA0B,kBACxC,OAAO,OAAO,KAAK,EAAe,KAAM,IAAA,GAAW,EAAe,GAAG,EACvE,EAAM,yBAAyB,EAC/B,EAAe,MAAM,CAFkD,CAGzE,EAEA,IAAI,EACJ,MAAM,EAAmB,GAAiB,CACxC,IAAM,EAAiB,EAAkB,CAAK,EAC1C,IAAU,IACV,GAAO,EAAM,UAAU,OAAO,CAAW,EACzC,GAAgB,EAAe,UAAU,IAAI,CAAW,EAC5D,EAAQ,EACV,EAEM,GAAqB,CAAE,OAAQ,KAAgB,CAGnD,IAAM,GADJ,aAAc,QAAU,EAAG,QAAQ,CAAyB,EAAI,OAChD,aAAa,CAAqB,EAC9C,EAAU,GAAM,SAAS,eAAe,CAAE,GAAM,IAAA,GAChD,EAAO,GAAW,EAAe,QAAQ,iGAAa,EAE5D,OAAQ,CAAC,GAAQ,IAAS,IAAW,CAAE,GAA6B,SAChE,EACA,IAAA,EACN,EAEAA,EAAAA,YAAY,uBAA0B,CACpCC,EAAAA,GAAG,OAAQ,iBAAkB,EAAyC,EAAI,EAC1EA,EAAAA,GAAG,SAAU,YAAa,EAAiBC,EAAAA,WAAW,CACxD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"dialog.cjs","names":["attr","isBrowser","onHotReload","on","QUICK_EVENT","onMutation"],"sources":["../../../src/dialog/dialog.ts"],"sourcesContent":["import {\n attr,\n isBrowser,\n on,\n onHotReload,\n onMutation,\n QUICK_EVENT,\n} from '../utils/utils';\n\n// Polyfill closedby functionaliy in Safari\n// Also in Safari 26.2 where `closedBy` property is supported natively,\n// but no corresponding functionality/behavior is implemented.\nlet DOWN_INSIDE = false; // Prevent close if selecting text inside dialog\nconst handleClosedbyAny = ({\n type,\n target: el,\n clientX: x = 0,\n clientY: y = 0,\n}: Partial<MouseEvent>) => {\n if (type === 'pointerdown') {\n const r = (el as Element)?.closest?.('dialog')?.getBoundingClientRect();\n const isInside =\n r && r.top <= y && y <= r.bottom && r.left <= x && x <= r.right;\n\n DOWN_INSIDE = !!isInside;\n } else {\n const isDialog = el instanceof HTMLDialogElement;\n const isClose = isDialog && !DOWN_INSIDE && attr(el, 'closedby') === 'any';\n\n DOWN_INSIDE = false; // Reset on every pointerup\n if (isClose) requestAnimationFrame(() => el.open && el.close()); // Close if browser did not do it\n }\n};\n\n// Ensure buttons that trigger a modeal dialog has aria-haspopup=\"dialog\" for better screen reader experience\nconst BUTTONS = isBrowser() ? document.getElementsByTagName('button') : [];\nconst handleAriaAttributes = () => {\n for (const btn of BUTTONS)\n if (btn.getAttribute('command')?.endsWith('-modal'))\n btn.setAttribute('aria-haspopup', 'dialog'); // Using get/setAttribute for performance\n};\n\nconst handleCommand = ({ command, target }: Event & { command?: string }) =>\n command === '--show-non-modal' &&\n target instanceof HTMLDialogElement &&\n target.show();\n\nonHotReload('dialog', () => [\n on(document, 'command', handleCommand, QUICK_EVENT),\n on(document, 'pointerdown pointerup', handleClosedbyAny, QUICK_EVENT),\n onMutation(document, handleAriaAttributes, {\n attributeFilter: ['command'],\n attributes: true,\n childList: true,\n subtree: true,\n }),\n]);\n"],"mappings":"sCAYA,IAAI,EAAc,GAClB,MAAM,GAAqB,CACzB,OACA,OAAQ,EACR,QAAS,EAAI,EACb,QAAS,EAAI,KACY,CACzB,GAAI,IAAS,cAAe,CAC1B,IAAM,EAAK,GAAgB,UAAU,SAAS,EAAE,uBAAuB,CAIvE,EAAc,CAAC,EAFb,GAAK,EAAE,KAAO,GAAK,GAAK,EAAE,QAAU,EAAE,MAAQ,GAAK,GAAK,EAAE,WAGvD,CAEL,IAAM,EADW,aAAc,mBACH,CAAC,GAAeA,EAAAA,KAAK,EAAI,WAAW,GAAK,MAErE,EAAc,GACV,GAAS,0BAA4B,EAAG,MAAQ,EAAG,OAAO,CAAC,GAK7D,EAAUC,EAAAA,WAAW,CAAG,SAAS,qBAAqB,SAAS,CAAG,EAAE,CACpE,MAA6B,CACjC,IAAK,IAAM,KAAO,EACZ,EAAI,aAAa,UAAU,EAAE,SAAS,SAAS,EACjD,EAAI,aAAa,gBAAiB,SAAS,EAG3C,GAAiB,CAAE,UAAS,YAChC,IAAY,oBACZ,aAAkB,mBAClB,EAAO,MAAM,CAEfC,EAAAA,YAAY,aAAgB,CAC1BC,EAAAA,GAAG,SAAU,UAAW,EAAeC,EAAAA,YAAY,CACnDD,EAAAA,GAAG,SAAU,wBAAyB,EAAmBC,EAAAA,YAAY,CACrEC,EAAAA,WAAW,SAAU,EAAsB,CACzC,gBAAiB,CAAC,UAAU,CAC5B,WAAY,GACZ,UAAW,GACX,QAAS,GACV,CAAC,CACH,CAAC"}
1
+ {"version":3,"file":"dialog.cjs","names":["attr","isBrowser","onHotReload","on","QUICK_EVENT","onMutation"],"sources":["../../../src/dialog/dialog.ts"],"sourcesContent":["import {\n attr,\n isBrowser,\n on,\n onHotReload,\n onMutation,\n QUICK_EVENT,\n} from '../utils/utils';\n\n// Polyfill closedby functionaliy in Safari\n// Also in Safari 26.2 where `closedBy` property is supported natively,\n// but no corresponding functionality/behavior is implemented.\nlet DOWN_INSIDE = false; // Prevent close if selecting text inside dialog\nconst handleClosedbyAny = ({\n type,\n target: el,\n clientX: x = 0,\n clientY: y = 0,\n}: Partial<MouseEvent>) => {\n if (type === 'pointerdown') {\n const r = (el as Element)?.closest?.('dialog')?.getBoundingClientRect();\n const isInside =\n r && r.top <= y && y <= r.bottom && r.left <= x && x <= r.right;\n\n DOWN_INSIDE = !!isInside;\n } else {\n const isDialog = el instanceof HTMLDialogElement;\n const isClose = isDialog && !DOWN_INSIDE && attr(el, 'closedby') === 'any';\n\n DOWN_INSIDE = false; // Reset on every pointerup\n if (isClose) requestAnimationFrame(() => el.open && el.close()); // Close if browser did not do it\n }\n};\n\n// Ensure buttons that trigger a modeal dialog has aria-haspopup=\"dialog\" for better screen reader experience\nconst BUTTONS = isBrowser() ? document.getElementsByTagName('button') : [];\nconst handleAriaAttributes = () => {\n for (const btn of BUTTONS)\n if (btn.getAttribute('command')?.endsWith('-modal'))\n btn.setAttribute('aria-haspopup', 'dialog'); // Using get/setAttribute for performance\n};\n\nconst handleCommand = ({ command, target }: Event & { command?: string }) =>\n command === '--show-non-modal' &&\n target instanceof HTMLDialogElement &&\n target.show();\n\nonHotReload('dialog', () => [\n on(document, 'command', handleCommand, QUICK_EVENT),\n on(document, 'pointerdown pointerup', handleClosedbyAny, QUICK_EVENT),\n onMutation(document, handleAriaAttributes, {\n attributeFilter: ['command'],\n attributes: true,\n childList: true,\n subtree: true,\n }),\n]);\n"],"mappings":"sCAYA,IAAI,EAAc,GAClB,MAAM,GAAqB,CACzB,OACA,OAAQ,EACR,QAAS,EAAI,EACb,QAAS,EAAI,KACY,CACzB,GAAI,IAAS,cAAe,CAC1B,IAAM,EAAK,GAAgB,UAAU,QAAQ,GAAG,sBAAsB,EAItE,EAAc,CAAC,EAFb,GAAK,EAAE,KAAO,GAAK,GAAK,EAAE,QAAU,EAAE,MAAQ,GAAK,GAAK,EAAE,MAG9D,KAAO,CAEL,IAAM,EADW,aAAc,mBACH,CAAC,GAAeA,EAAAA,KAAK,EAAI,UAAU,IAAM,MAErE,EAAc,GACV,GAAS,0BAA4B,EAAG,MAAQ,EAAG,MAAM,CAAC,CAChE,CACF,EAGM,EAAUC,EAAAA,UAAU,EAAI,SAAS,qBAAqB,QAAQ,EAAI,CAAC,EACnE,MAA6B,CACjC,IAAK,IAAM,KAAO,EACZ,EAAI,aAAa,SAAS,GAAG,SAAS,QAAQ,GAChD,EAAI,aAAa,gBAAiB,QAAQ,CAChD,EAEM,GAAiB,CAAE,UAAS,YAChC,IAAY,oBACZ,aAAkB,mBAClB,EAAO,KAAK,EAEdC,EAAAA,YAAY,aAAgB,CAC1BC,EAAAA,GAAG,SAAU,UAAW,EAAeC,EAAAA,WAAW,EAClDD,EAAAA,GAAG,SAAU,wBAAyB,EAAmBC,EAAAA,WAAW,EACpEC,EAAAA,WAAW,SAAU,EAAsB,CACzC,gBAAiB,CAAC,SAAS,EAC3B,WAAY,GACZ,UAAW,GACX,QAAS,EACX,CAAC,CACH,CAAC"}
@@ -1,2 +1,3 @@
1
- const e=require(`../utils/utils.cjs`);var t=class extends e.DSElement{_unmutate;connectedCallback(){e.on(this,`animationend`,this,e.QUICK_EVENT),e.attr(this,`tabindex`,`-1`),this._unmutate=e.onMutation(this,n,{childList:!0,subtree:!0}),this.focus()}handleEvent({target:e}){e===this&&this.focus()}disconnectedCallback(){e.off(this,`animationend`,this,e.QUICK_EVENT),this._unmutate?.(),this._unmutate=void 0}};const n=t=>{let n=t.querySelector(`h2,h3,h4,h5,h6`);n&&e.attr(t,`aria-labelledby`,e.useId(n))};e.customElements.define(`ds-error-summary`,t),exports.DSErrorSummaryElement=t;
1
+ const e=require(`../utils/utils.cjs`);var t=class extends e.DSElement{_unmutate;connectedCallback(){e.on(this,`animationend`,this,e.QUICK_EVENT),e.attr(this,`role`,`group`),e.attr(this,`tabindex`,`-1`),this._unmutate=e.onMutation(this,n,{childList:!0,subtree:!0}),this.focus()}handleEvent({target:e}){e===this&&this.focus()}disconnectedCallback(){e.off(this,`animationend`,this,e.QUICK_EVENT),this._unmutate?.(),this._unmutate=void 0}};const n=t=>{let n=e.attr(t,`aria-label`)?.trim(),r=e.attr(t,`aria-labelledby`)?.trim(),i=t.querySelector(`h2,h3,h4,h5,h6`);i&&!n&&!r&&e.attr(t,`aria-labelledby`,e.useId(i)),!i&&!n&&!r&&e.warn(`Missing accessible name on:`,t,`
2
+ Add a heading (h2–h6), or set aria-label or aria-labelledby to provide an accessible name for screen readers.`)};e.customElements.define(`ds-error-summary`,t),exports.DSErrorSummaryElement=t;
2
3
  //# sourceMappingURL=error-summary.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-summary.cjs","names":["DSElement","QUICK_EVENT","onMutation","useId","customElements"],"sources":["../../../src/error-summary/error-summary.ts"],"sourcesContent":["import {\n attr,\n customElements,\n DSElement,\n off,\n on,\n onMutation,\n QUICK_EVENT,\n useId,\n} from '../utils/utils';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-error-summary': DSErrorSummaryElement;\n }\n}\n\nexport class DSErrorSummaryElement extends DSElement {\n _unmutate?: () => void; // Using underscore instead of private fields for backwards compatibility\n\n connectedCallback() {\n on(this, 'animationend', this, QUICK_EVENT); // Using animationend to detect when element is visible\n attr(this, 'tabindex', '-1');\n this._unmutate = onMutation(this, render, {\n childList: true,\n subtree: true,\n });\n this.focus();\n }\n handleEvent({ target }: Event) {\n if (target === this) this.focus(); // Ignore if animation event was triggered by child\n }\n disconnectedCallback() {\n off(this, 'animationend', this, QUICK_EVENT);\n this._unmutate?.();\n this._unmutate = undefined;\n }\n}\n\nconst render = (self: DSErrorSummaryElement) => {\n const heading = self.querySelector('h2,h3,h4,h5,h6');\n if (heading) attr(self, 'aria-labelledby', useId(heading));\n};\n\ncustomElements.define('ds-error-summary', DSErrorSummaryElement);\n"],"mappings":"sCAiBA,IAAa,EAAb,cAA2CA,EAAAA,SAAU,CACnD,UAEA,mBAAoB,CAClB,EAAA,GAAG,KAAM,eAAgB,KAAMC,EAAAA,YAAY,CAC3C,EAAA,KAAK,KAAM,WAAY,KAAK,CAC5B,KAAK,UAAYC,EAAAA,WAAW,KAAM,EAAQ,CACxC,UAAW,GACX,QAAS,GACV,CAAC,CACF,KAAK,OAAO,CAEd,YAAY,CAAE,UAAiB,CACzB,IAAW,MAAM,KAAK,OAAO,CAEnC,sBAAuB,CACrB,EAAA,IAAI,KAAM,eAAgB,KAAMD,EAAAA,YAAY,CAC5C,KAAK,aAAa,CAClB,KAAK,UAAY,IAAA,KAIrB,MAAM,EAAU,GAAgC,CAC9C,IAAM,EAAU,EAAK,cAAc,iBAAiB,CAChD,GAAS,EAAA,KAAK,EAAM,kBAAmBE,EAAAA,MAAM,EAAQ,CAAC,EAG5DC,EAAAA,eAAe,OAAO,mBAAoB,EAAsB"}
1
+ {"version":3,"file":"error-summary.cjs","names":["DSElement","QUICK_EVENT","onMutation","attr","useId","customElements"],"sources":["../../../src/error-summary/error-summary.ts"],"sourcesContent":["import {\n attr,\n customElements,\n DSElement,\n off,\n on,\n onMutation,\n QUICK_EVENT,\n useId,\n warn,\n} from '../utils/utils';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-error-summary': DSErrorSummaryElement;\n }\n}\n\nexport class DSErrorSummaryElement extends DSElement {\n _unmutate?: () => void; // Using underscore instead of private fields for backwards compatibility\n\n connectedCallback() {\n on(this, 'animationend', this, QUICK_EVENT); // Using animationend to detect when element is visible\n attr(this, 'role', 'group');\n attr(this, 'tabindex', '-1');\n this._unmutate = onMutation(this, render, {\n childList: true,\n subtree: true,\n });\n this.focus();\n }\n handleEvent({ target }: Event) {\n if (target === this) this.focus(); // Ignore if animation event was triggered by child\n }\n disconnectedCallback() {\n off(this, 'animationend', this, QUICK_EVENT);\n this._unmutate?.();\n this._unmutate = undefined;\n }\n}\n\nconst render = (self: DSErrorSummaryElement) => {\n const label = attr(self, 'aria-label')?.trim();\n const labelledBy = attr(self, 'aria-labelledby')?.trim();\n const heading = self.querySelector('h2,h3,h4,h5,h6');\n if (heading && !label && !labelledBy) {\n attr(self, 'aria-labelledby', useId(heading));\n }\n if (!heading && !label && !labelledBy) {\n warn(\n 'Missing accessible name on:',\n self,\n '\\nAdd a heading (h2–h6), or set aria-label or aria-labelledby to provide an accessible name for screen readers.',\n );\n }\n};\n\ncustomElements.define('ds-error-summary', DSErrorSummaryElement);\n"],"mappings":"sCAkBA,IAAa,EAAb,cAA2CA,EAAAA,SAAU,CACnD,UAEA,mBAAoB,CAClB,EAAA,GAAG,KAAM,eAAgB,KAAMC,EAAAA,WAAW,EAC1C,EAAA,KAAK,KAAM,OAAQ,OAAO,EAC1B,EAAA,KAAK,KAAM,WAAY,IAAI,EAC3B,KAAK,UAAYC,EAAAA,WAAW,KAAM,EAAQ,CACxC,UAAW,GACX,QAAS,EACX,CAAC,EACD,KAAK,MAAM,CACb,CACA,YAAY,CAAE,UAAiB,CACzB,IAAW,MAAM,KAAK,MAAM,CAClC,CACA,sBAAuB,CACrB,EAAA,IAAI,KAAM,eAAgB,KAAMD,EAAAA,WAAW,EAC3C,KAAK,YAAY,EACjB,KAAK,UAAY,IAAA,EACnB,CACF,EAEA,MAAM,EAAU,GAAgC,CAC9C,IAAM,EAAQE,EAAAA,KAAK,EAAM,YAAY,GAAG,KAAK,EACvC,EAAaA,EAAAA,KAAK,EAAM,iBAAiB,GAAG,KAAK,EACjD,EAAU,EAAK,cAAc,gBAAgB,EAC/C,GAAW,CAAC,GAAS,CAAC,GACxB,EAAA,KAAK,EAAM,kBAAmBC,EAAAA,MAAM,CAAO,CAAC,EAE1C,CAAC,GAAW,CAAC,GAAS,CAAC,GACzB,EAAA,KACE,8BACA,EACA;8GACF,CAEJ,EAEAC,EAAAA,eAAe,OAAO,mBAAoB,CAAqB"}
@@ -1 +1 @@
1
- {"version":3,"file":"field.cjs","names":["isWindows","useId","attr","attrOrCSS","debounce","DSElement","customElements","onHotReload","on","QUICK_EVENT","onMutation"],"sources":["../../../src/field/field.ts"],"sourcesContent":["import {\n announce,\n attr,\n attrOrCSS,\n customElements,\n DSElement,\n debounce,\n isWindows,\n on,\n onHotReload,\n onMutation,\n QUICK_EVENT,\n useId,\n warn,\n} from '../utils/utils';\n\n// TODO: Document that Validation must be hidden with \"hidden\" attribute (or completely removed from DOM), not display: none\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-field': DSFieldElement;\n }\n}\n\nconst ATTR_INVALID = 'aria-invalid';\nconst ATTR_DESCRIBEDBY = 'aria-describedby';\nconst ATTR_INDETERMINATE = 'data-indeterminate';\nconst COUNTER_DEBOUNCE = isWindows() ? 800 : 200; // Longer debounce on Windows due to NVDA performance\nconst COUNTS = new WeakMap<HTMLInputElement, Element>(); // Using WeakMap so removed inputs/counts does not cause memory leaks\nconst FIELDS = new Map<DSFieldElement, string[]>(); // Map of Field and its describedby IDs so we can identify the ones we add/remove\nconst VALIDATIONS = new WeakSet<HTMLInputElement>(); // Used to ensure we only take control of aria-invalid if the current is or has been a validation element\nconst WARNING_MULTIPLE_INPUTS = `Fields should only have one input element. Use <fieldset> to group multiple fields:`;\n\nconst handleFieldMutations = (_doc: Node, records: MutationRecord[] = []) => {\n for (const { target } of records) {\n const isFieldset = target instanceof HTMLFieldSetElement;\n for (const [field] of FIELDS)\n if (isFieldset ? target.contains(field) : field.contains(target))\n handleFieldMutation(field);\n }\n};\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 = FIELDS.get(field) || []; // Retrieve previously managed IDs for this field\n let input: HTMLInputElement | undefined;\n let counter: Element | undefined;\n let hasValidation = false;\n let invalid = false;\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 (input) warn(WARNING_MULTIPLE_INPUTS, field);\n else input = el; // Only register if visible input\n } else {\n const type = el.getAttribute('data-field'); // Using getAttribute instead of attr for best performance\n if (type === 'counter') counter = el;\n if (type === 'validation') {\n nextDescs.unshift(useId(el));\n hasValidation = true;\n invalid = invalid || isInvalid(el);\n } else if (type) nextDescs.push(useId(el)); // Adds both counter and descriptions\n }\n }\n\n if (!input) return; // Do not warn about missing input as virtual DOM libraries might give false positives\n if (counter) COUNTS.set(input, counter);\n for (const label of labels) attr(label, 'for', useId(input));\n\n const fieldsetValidation = field\n .closest('fieldset')\n ?.querySelector<HTMLElement>(':scope > [data-field=\"validation\"]');\n\n // Connect fieldset validation to inputs\n if (fieldsetValidation && !fieldsetValidation?.hidden) {\n hasValidation = true;\n invalid = invalid || isInvalid(fieldsetValidation);\n nextDescs.unshift(useId(fieldsetValidation));\n }\n\n // Add support for data-indeterminate attribute as this normally can only be set by javascript\n 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 FIELDS.set(field, nextDescs);\n\n // Only manage aria-invalid when field has validation elements, and aria-invalid does not already exist\n const hadValidation = VALIDATIONS.has(input);\n if (hasValidation && !hadValidation && !input.hasAttribute(ATTR_INVALID)) {\n attr(input, ATTR_INVALID, 'true');\n VALIDATIONS.add(input);\n } else if (!hasValidation && hadValidation) {\n attr(input, ATTR_INVALID, null); // Remove aria-invalid\n VALIDATIONS.delete(input);\n }\n\n handleFieldInput(input); // 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 handleFieldInput = (e: Event | Element) => {\n const input = ((e as Event).target || e) as HTMLInputElement;\n const counter = COUNTS.get(input);\n\n if (counter?.isConnected) {\n const limit = Number(attr(counter, 'data-limit')) || 0;\n const count = limit - input.value.length;\n const state = count < 0 ? 'over' : 'under';\n const label = (\n attrOrCSS(counter, `data-${state}`) || TEXTS[state]\n )?.replace('%d', `${Math.abs(count)}`);\n\n attr(counter, 'data-label', label); // Using attribute to prevent hydation errors, not using aria-label to make axe tests happy\n attr(counter, 'data-state', state);\n attr(counter, 'data-color', count < 0 ? 'danger' : null);\n\n // Only update live region when user is actually typing\n if ((e as 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('--_ds-field-sizing', `${input.scrollHeight}px`);\n }\n};\n\nconst debouncedCounterLiveRegion = debounce((input: Element, text: string) => {\n if (document.activeElement === input) announce(text); // Only announce if input is still focused\n}, COUNTER_DEBOUNCE);\n\nconst isInvalid = (el: Element) => el.getAttribute('data-color') !== 'success';\nconst isInputLike = (el: unknown): el is HTMLInputElement =>\n el instanceof HTMLElement &&\n 'validity' in el && // Adds support for custom elements implemeted with attachInternals()\n !(el instanceof HTMLButtonElement) && // But skip <button> elements\n (el as HTMLInputElement).type !== 'hidden'; // And skip input type=\"hidden\"\n\n// Custom element is used to performantly keep track of fields on the page\nexport class DSFieldElement extends DSElement {\n connectedCallback() {\n FIELDS.set(this, []); // Register field\n handleFieldMutation(this); // Initial setup\n }\n disconnectedCallback() {\n FIELDS.delete(this);\n }\n}\n\ncustomElements.define('ds-field', DSFieldElement);\n\nonHotReload('field', () => [\n on(document, 'input', handleFieldInput, QUICK_EVENT),\n onMutation(document, handleFieldMutations, {\n attributeFilter: [\n 'data-field',\n 'data-limit',\n 'hidden', // Needed to check validation visibility\n 'id', // Needed to sync label \"for\" when ID of input/selec/textarea changes\n 'value', // Needed to detect changes in controlled React inputs as they do not trigger input events\n ATTR_INDETERMINATE,\n ],\n attributes: true,\n childList: true,\n subtree: true,\n }),\n]);\n"],"mappings":"sCAuBM,EAAe,eACf,EAAmB,mBACnB,EAAqB,qBACrB,EAAmBA,EAAAA,WAA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AAM,aAAa,IAAI,GAItE,EAA6BC,EAAAA,UAAU,EAAgB,IAAiB,CACxE,SAAS,gBAAkB,GAAO,EAAA,SAAS,EAAK,EACnD,EAAiB,CAEd,EAAa,GAAgB,EAAG,aAAa,aAAa,GAAK,UAC/D,EAAe,GACnB,aAAc,aACd,aAAc,GACd,EAAE,aAAc,oBACf,EAAwB,OAAS,SAGpC,IAAa,EAAb,cAAoCC,EAAAA,SAAU,CAC5C,mBAAoB,CAClB,EAAO,IAAI,KAAM,EAAE,CAAC,CACpB,EAAoB,KAAK,CAE3B,sBAAuB,CACrB,EAAO,OAAO,KAAK,GAIvBC,EAAAA,eAAe,OAAO,WAAY,EAAe,CAEjDC,EAAAA,YAAY,YAAe,CACzBC,EAAAA,GAAG,SAAU,QAAS,EAAkBC,EAAAA,YAAY,CACpDC,EAAAA,WAAW,SAAU,EAAsB,CACzC,gBAAiB,CACf,aACA,aACA,SACA,KACA,QACA,EACD,CACD,WAAY,GACZ,UAAW,GACX,QAAS,GACV,CAAC,CACH,CAAC"}
1
+ {"version":3,"file":"field.cjs","names":["isWindows","useId","attr","attrOrCSS","debounce","DSElement","customElements","onHotReload","on","QUICK_EVENT","onMutation"],"sources":["../../../src/field/field.ts"],"sourcesContent":["import {\n announce,\n attr,\n attrOrCSS,\n customElements,\n DSElement,\n debounce,\n isWindows,\n on,\n onHotReload,\n onMutation,\n QUICK_EVENT,\n useId,\n warn,\n} from '../utils/utils';\n\n// TODO: Document that Validation must be hidden with \"hidden\" attribute (or completely removed from DOM), not display: none\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-field': DSFieldElement;\n }\n}\n\nconst ATTR_INVALID = 'aria-invalid';\nconst ATTR_DESCRIBEDBY = 'aria-describedby';\nconst ATTR_INDETERMINATE = 'data-indeterminate';\nconst COUNTER_DEBOUNCE = isWindows() ? 800 : 200; // Longer debounce on Windows due to NVDA performance\nconst COUNTS = new WeakMap<HTMLInputElement, Element>(); // Using WeakMap so removed inputs/counts does not cause memory leaks\nconst FIELDS = new Map<DSFieldElement, string[]>(); // Map of Field and its describedby IDs so we can identify the ones we add/remove\nconst VALIDATIONS = new WeakSet<HTMLInputElement>(); // Used to ensure we only take control of aria-invalid if the current is or has been a validation element\nconst WARNING_MULTIPLE_INPUTS = `Fields should only have one input element. Use <fieldset> to group multiple fields:`;\n\nconst handleFieldMutations = (_doc: Node, records: MutationRecord[] = []) => {\n for (const { target } of records) {\n const isFieldset = target instanceof HTMLFieldSetElement;\n for (const [field] of FIELDS)\n if (isFieldset ? target.contains(field) : field.contains(target))\n handleFieldMutation(field);\n }\n};\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 = FIELDS.get(field) || []; // Retrieve previously managed IDs for this field\n let input: HTMLInputElement | undefined;\n let counter: Element | undefined;\n let hasValidation = false;\n let invalid = false;\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 (input) warn(WARNING_MULTIPLE_INPUTS, field);\n else input = el; // Only register if visible input\n } else {\n const type = el.getAttribute('data-field'); // Using getAttribute instead of attr for best performance\n if (type === 'counter') counter = el;\n if (type === 'validation') {\n nextDescs.unshift(useId(el));\n hasValidation = true;\n invalid = invalid || isInvalid(el);\n } else if (type) nextDescs.push(useId(el)); // Adds both counter and descriptions\n }\n }\n\n if (!input) return; // Do not warn about missing input as virtual DOM libraries might give false positives\n if (counter) COUNTS.set(input, counter);\n for (const label of labels) attr(label, 'for', useId(input));\n\n const fieldsetValidation = field\n .closest('fieldset')\n ?.querySelector<HTMLElement>(':scope > [data-field=\"validation\"]');\n\n // Connect fieldset validation to inputs\n if (fieldsetValidation && !fieldsetValidation?.hidden) {\n hasValidation = true;\n invalid = invalid || isInvalid(fieldsetValidation);\n nextDescs.unshift(useId(fieldsetValidation));\n }\n\n // Add support for data-indeterminate attribute as this normally can only be set by javascript\n 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 FIELDS.set(field, nextDescs);\n\n // Only manage aria-invalid when field has validation elements, and aria-invalid does not already exist\n const hadValidation = VALIDATIONS.has(input);\n if (hasValidation && !hadValidation && !input.hasAttribute(ATTR_INVALID)) {\n attr(input, ATTR_INVALID, 'true');\n VALIDATIONS.add(input);\n } else if (!hasValidation && hadValidation) {\n attr(input, ATTR_INVALID, null); // Remove aria-invalid\n VALIDATIONS.delete(input);\n }\n\n handleFieldInput(input); // 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 handleFieldInput = (e: Event | Element) => {\n const input = ((e as Event).target || e) as HTMLInputElement;\n const counter = COUNTS.get(input);\n\n if (counter?.isConnected) {\n const limit = Number(attr(counter, 'data-limit')) || 0;\n const count = limit - input.value.length;\n const state = count < 0 ? 'over' : 'under';\n const label = (\n attrOrCSS(counter, `data-${state}`) || TEXTS[state]\n )?.replace('%d', `${Math.abs(count)}`);\n\n attr(counter, 'data-label', label); // Using attribute to prevent hydation errors, not using aria-label to make axe tests happy\n attr(counter, 'data-state', state);\n attr(counter, 'data-color', count < 0 ? 'danger' : null);\n\n // Only update live region when user is actually typing\n if ((e as 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('--_ds-field-sizing', `${input.scrollHeight}px`);\n }\n};\n\nconst debouncedCounterLiveRegion = debounce((input: Element, text: string) => {\n if (document.activeElement === input) announce(text); // Only announce if input is still focused\n}, COUNTER_DEBOUNCE);\n\nconst isInvalid = (el: Element) => el.getAttribute('data-color') !== 'success';\nconst isInputLike = (el: unknown): el is HTMLInputElement =>\n el instanceof HTMLElement &&\n 'validity' in el && // Adds support for custom elements implemeted with attachInternals()\n !(el instanceof HTMLButtonElement) && // But skip <button> elements\n (el as HTMLInputElement).type !== 'hidden'; // And skip input type=\"hidden\"\n\n// Custom element is used to performantly keep track of fields on the page\nexport class DSFieldElement extends DSElement {\n connectedCallback() {\n FIELDS.set(this, []); // Register field\n handleFieldMutation(this); // Initial setup\n }\n disconnectedCallback() {\n FIELDS.delete(this);\n }\n}\n\ncustomElements.define('ds-field', DSFieldElement);\n\nonHotReload('field', () => [\n on(document, 'input', handleFieldInput, QUICK_EVENT),\n onMutation(document, handleFieldMutations, {\n attributeFilter: [\n 'data-field',\n 'data-limit',\n 'hidden', // Needed to check validation visibility\n 'id', // Needed to sync label \"for\" when ID of input/selec/textarea changes\n 'value', // Needed to detect changes in controlled React inputs as they do not trigger input events\n ATTR_INDETERMINATE,\n ],\n attributes: true,\n childList: true,\n subtree: true,\n }),\n]);\n"],"mappings":"sCAuBM,EAAe,eACf,EAAmB,mBACnB,EAAqB,qBACrB,EAAmBA,EAAAA,UAAU,EAAI,IAAM,IACvC,EAAS,IAAI,QACb,EAAS,IAAI,IACb,EAAc,IAAI,QAGlB,GAAwB,EAAY,EAA4B,CAAC,IAAM,CAC3E,IAAK,GAAM,CAAE,YAAY,EAAS,CAChC,IAAM,EAAa,aAAkB,oBACrC,IAAK,GAAM,CAAC,KAAU,GAChB,EAAa,EAAO,SAAS,CAAK,EAAI,EAAM,SAAS,CAAM,IAC7D,EAAo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AAS,SAGpC,IAAa,EAAb,cAAoCC,EAAAA,SAAU,CAC5C,mBAAoB,CAClB,EAAO,IAAI,KAAM,CAAC,CAAC,EACnB,EAAoB,IAAI,CAC1B,CACA,sBAAuB,CACrB,EAAO,OAAO,IAAI,CACpB,CACF,EAEAC,EAAAA,eAAe,OAAO,WAAY,CAAc,EAEhDC,EAAAA,YAAY,YAAe,CACzBC,EAAAA,GAAG,SAAU,QAAS,EAAkBC,EAAAA,WAAW,EACnDC,EAAAA,WAAW,SAAU,EAAsB,CACzC,gBAAiB,CACf,aACA,aACA,SACA,KACA,QACA,CACF,EACA,WAAY,GACZ,UAAW,GACX,QAAS,EACX,CAAC,CACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"fieldset.cjs","names":["isBrowser","useId","onHotReload","onMutation"],"sources":["../../../src/fieldset/fieldset.ts"],"sourcesContent":["import {\n attr,\n isBrowser,\n onHotReload,\n onMutation,\n useId,\n} from '../utils/utils';\n\nconst FIELDSETS = isBrowser() ? document.getElementsByTagName('fieldset') : [];\n\n// NOTE:\n// <fieldset> descriptions should be accessible to screen reader users. However, using aria-describedby\n// on <fieldset> causes all child <input> elements to inherit the same description, resulting in redundant and confusing announcements.\n// To avoid this, we use aria-labelledby to reference both the legend and the description.\n// aria-labelledby is only announced when screen readers enter the fieldset, not when navigating its child elements.\n// This means the accessible name of <fieldset> includes both the legend and description, which may differ from some test expectations,\n// but as of March 2026, this approach provides the best user experience across assistive technologies.\n// This approach is also verified by the chief of accessibility at NRK and the accessibility expert at NAV\nconst handleFieldsetMutations = () => {\n for (const el of FIELDSETS) {\n if (el.hasAttribute('aria-labelledby')) continue; // Speed up by skipping labelled fieldsets\n const labelledby = `${useId(el.querySelector('legend'))} ${useId(el.querySelector(':scope > :is([data-field=\"description\"],legend + p)'))}`;\n attr(el, 'aria-labelledby', labelledby.trim() || null);\n }\n};\n\nonHotReload('fieldset', () => [\n onMutation(document, handleFieldsetMutations, {\n childList: true,\n subtree: true,\n }),\n]);\n"],"mappings":"sCAQM,EAAYA,EAAAA,WAAW,CAAG,SAAS,qBAAqB,WAAW,CAAG,EAAE,CAUxE,MAAgC,CACpC,IAAK,IAAM,KAAM,EACX,EAAG,aAAa,kBAAkB,EAEtC,EAAA,KAAK,EAAI,kBADU,GAAGC,EAAAA,MAAM,EAAG,cAAc,SAAS,CAAC,CAAC,GAAGA,EAAAA,MAAM,EAAG,cAAc,sDAAsD,CAAC,GAClG,MAAM,EAAI,KAAK,EAI1DC,EAAAA,YAAY,eAAkB,CAC5BC,EAAAA,WAAW,SAAU,EAAyB,CAC5C,UAAW,GACX,QAAS,GACV,CAAC,CACH,CAAC"}
1
+ {"version":3,"file":"fieldset.cjs","names":["isBrowser","useId","onHotReload","onMutation"],"sources":["../../../src/fieldset/fieldset.ts"],"sourcesContent":["import {\n attr,\n isBrowser,\n onHotReload,\n onMutation,\n useId,\n} from '../utils/utils';\n\nconst FIELDSETS = isBrowser() ? document.getElementsByTagName('fieldset') : [];\n\n// NOTE:\n// <fieldset> descriptions should be accessible to screen reader users. However, using aria-describedby\n// on <fieldset> causes all child <input> elements to inherit the same description, resulting in redundant and confusing announcements.\n// To avoid this, we use aria-labelledby to reference both the legend and the description.\n// aria-labelledby is only announced when screen readers enter the fieldset, not when navigating its child elements.\n// This means the accessible name of <fieldset> includes both the legend and description, which may differ from some test expectations,\n// but as of March 2026, this approach provides the best user experience across assistive technologies.\n// This approach is also verified by the chief of accessibility at NRK and the accessibility expert at NAV\nconst handleFieldsetMutations = () => {\n for (const el of FIELDSETS) {\n if (el.hasAttribute('aria-labelledby')) continue; // Speed up by skipping labelled fieldsets\n const labelledby = `${useId(el.querySelector('legend'))} ${useId(el.querySelector(':scope > :is([data-field=\"description\"],legend + p)'))}`;\n attr(el, 'aria-labelledby', labelledby.trim() || null);\n }\n};\n\nonHotReload('fieldset', () => [\n onMutation(document, handleFieldsetMutations, {\n childList: true,\n subtree: true,\n }),\n]);\n"],"mappings":"sCAQM,EAAYA,EAAAA,UAAU,EAAI,SAAS,qBAAqB,UAAU,EAAI,CAAC,EAUvE,MAAgC,CACpC,IAAK,IAAM,KAAM,EACX,EAAG,aAAa,iBAAiB,GAErC,EAAA,KAAK,EAAI,kBAAmB,GADNC,EAAAA,MAAM,EAAG,cAAc,QAAQ,CAAC,EAAE,GAAGA,EAAAA,MAAM,EAAG,cAAc,qDAAqD,CAAC,IACjG,KAAK,GAAK,IAAI,CAEzD,EAEAC,EAAAA,YAAY,eAAkB,CAC5BC,EAAAA,WAAW,SAAU,EAAyB,CAC5C,UAAW,GACX,QAAS,EACX,CAAC,CACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["isBrowser","isSupported"],"sources":["../../src/index.ts"],"sourcesContent":["import { isSupported, apply as polyfillInvokers } from 'invokers-polyfill/fn';\nimport { isBrowser } from './utils/utils';\nimport '@u-elements/u-details/polyfill'; // Polyfill for <details> element for Android Firefox + Talkback\nimport './clickdelegatefor/clickdelegatefor';\nimport './dialog/dialog';\nimport './fieldset/fieldset';\nimport './popover/popover';\nimport './readonly/readonly';\nimport './toggle-group/toggle-group';\nimport './tooltip/tooltip';\n\nexport * from '@u-elements/u-datalist'; // Re-export u-datalist since this is a pure polyfill and not custom Designsystemet elements\nexport * from './breadcrumbs/breadcrumbs';\nexport * from './error-summary/error-summary';\nexport * from './field/field';\nexport * from './pagination/pagination';\nexport * from './suggestion/suggestion';\nexport * from './tabs/tabs';\nexport * from './tooltip/tooltip';\n\nif (isBrowser() && !isSupported()) polyfillInvokers(); // Ensure invoker commands polyfill is loaded in browser environment only\n"],"mappings":"6rBAoBIA,EAAAA,WAAW,EAAI,CAACC,EAAAA,aAAa,EAAE,EAAA,OAAkB"}
1
+ {"version":3,"file":"index.cjs","names":["isBrowser","isSupported"],"sources":["../../src/index.ts"],"sourcesContent":["import { isSupported, apply as polyfillInvokers } from 'invokers-polyfill/fn';\nimport { isBrowser } from './utils/utils';\nimport '@u-elements/u-details/polyfill'; // Polyfill for <details> element for Android Firefox + Talkback\nimport './clickdelegatefor/clickdelegatefor';\nimport './dialog/dialog';\nimport './fieldset/fieldset';\nimport './popover/popover';\nimport './readonly/readonly';\nimport './toggle-group/toggle-group';\nimport './tooltip/tooltip';\n\nexport * from '@u-elements/u-datalist'; // Re-export u-datalist since this is a pure polyfill and not custom Designsystemet elements\nexport * from './breadcrumbs/breadcrumbs';\nexport * from './error-summary/error-summary';\nexport * from './field/field';\nexport * from './pagination/pagination';\nexport * from './suggestion/suggestion';\nexport * from './tabs/tabs';\nexport * from './tooltip/tooltip';\n\nif (isBrowser() && !isSupported()) polyfillInvokers(); // Ensure invoker commands polyfill is loaded in browser environment only\n"],"mappings":"6rBAoBIA,EAAAA,UAAU,GAAK,CAACC,EAAAA,YAAY,GAAG,EAAA,MAAiB"}
@@ -1 +1 @@
1
- {"version":3,"file":"pagination.cjs","names":["DSElement","attr","attrOrCSS","onMutation","customElements"],"sources":["../../../src/pagination/pagination.ts"],"sourcesContent":["import {\n attr,\n attrOrCSS,\n customElements,\n DSElement,\n onMutation,\n warn,\n} from '../utils/utils';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-pagination': DSPaginationElement;\n }\n}\n\nconst ATTR_LABEL = 'aria-label';\nconst ATTR_CURRENT = 'data-current';\nconst ATTR_TOTAL = 'data-total';\nconst ATTR_HREF = 'data-href';\n\n// Expose pagination logic if wanting to do custom rendering (i.e. in React/Vue/etc)\nexport const pagination = ({ current = 1, total = 10, show = 7 }) => ({\n prev: current > 1 ? current - 1 : 0,\n next: current < total ? current + 1 : 0,\n pages: getSteps(current, total, show).map((page, index) => ({\n current: page === current && ('page' as const),\n key: `key-${page}-${index}`,\n page,\n })),\n});\n\nexport class DSPaginationElement extends DSElement {\n _unmutate?: () => void; // Using underscore instead of private fields for backwards compatibility\n _render?: () => void;\n\n static get observedAttributes() {\n return [ATTR_LABEL, ATTR_CURRENT, ATTR_TOTAL, ATTR_HREF]; // Using ES2015 syntax for backwards compatibility\n }\n connectedCallback() {\n // Check for required attributes\n const total = attr(this, ATTR_TOTAL);\n const current = attr(this, ATTR_CURRENT);\n if (current && !total) warn(`Missing ${ATTR_TOTAL} attribute on:`, this);\n if (total && !current) warn(`Missing ${ATTR_CURRENT} attribute on:`, this);\n\n attr(this, ATTR_LABEL, attrOrCSS(this, ATTR_LABEL));\n attr(this, 'role', 'navigation');\n this._unmutate = onMutation(this, render, {\n childList: true,\n subtree: true,\n });\n }\n attributeChangedCallback() {\n if (this._unmutate) render(this); // Ensure we do not run any renders before connectedCallback\n }\n disconnectedCallback() {\n this._unmutate?.();\n this._unmutate = this._render = undefined;\n }\n}\n\nconst render = (self: DSPaginationElement) => {\n const current = Number(attr(self, ATTR_CURRENT));\n const total = Number(attr(self, ATTR_TOTAL));\n\n // Allowing server side generated pagination, buy only doing client side updates if total/current attributes are provided\n if (current && total) {\n const items = self.querySelectorAll('button,a');\n const show = items.length - 2;\n const href = attr(self, ATTR_HREF);\n const { next, prev, pages } = pagination({ current, total, show });\n items.forEach((item, i) => {\n const page = i ? (items[i + 1] ? pages[i - 1]?.page : next) : prev; // First is prev, last is next\n attr(item, 'aria-current', pages[i - 1]?.current ? 'true' : null);\n attr(item, 'aria-label', `${page ?? 'hidden'}`); // Used for CSS content and to hide if more items than pages, using aria-label to make Axe tests and VoiceOver rotor happy\n attr(item, 'role', page ? null : 'none'); // Prevent validation errors for aria-hidden buttons\n attr(item, 'tabindex', page ? null : '-1');\n if (item instanceof HTMLButtonElement) attr(item, 'value', `${page}`);\n if (href && item instanceof HTMLAnchorElement)\n attr(item, 'href', href.replace('%d', `${page}`));\n });\n }\n};\n\nconst getSteps = (\n now: number,\n max: number,\n show = Number.POSITIVE_INFINITY,\n) => {\n const offset = (show - 1) / 2;\n const start = Math.max(Math.min(now - Math.floor(offset), max - show + 1), 1);\n const end = Math.min(Math.max(now + Math.ceil(offset), show), max);\n const pages = Array.from({ length: end + 1 - start }, (_, i) => i + start);\n\n if (show > 4 && start > 1) pages.splice(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/pagination.ts"],"sourcesContent":["import {\n attr,\n attrOrCSS,\n customElements,\n DSElement,\n onMutation,\n warn,\n} from '../utils/utils';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-pagination': DSPaginationElement;\n }\n}\n\nconst ATTR_LABEL = 'aria-label';\nconst ATTR_CURRENT = 'data-current';\nconst ATTR_TOTAL = 'data-total';\nconst ATTR_HREF = 'data-href';\n\n// Expose pagination logic if wanting to do custom rendering (i.e. in React/Vue/etc)\nexport const pagination = ({ current = 1, total = 10, show = 7 }) => ({\n prev: current > 1 ? current - 1 : 0,\n next: current < total ? current + 1 : 0,\n pages: getSteps(current, total, show).map((page, index) => ({\n current: page === current && ('page' as const),\n key: `key-${page}-${index}`,\n page,\n })),\n});\n\nexport class DSPaginationElement extends DSElement {\n _unmutate?: () => void; // Using underscore instead of private fields for backwards compatibility\n _render?: () => void;\n\n static get observedAttributes() {\n return [ATTR_LABEL, ATTR_CURRENT, ATTR_TOTAL, ATTR_HREF]; // Using ES2015 syntax for backwards compatibility\n }\n connectedCallback() {\n // Check for required attributes\n const total = attr(this, ATTR_TOTAL);\n const current = attr(this, ATTR_CURRENT);\n if (current && !total) warn(`Missing ${ATTR_TOTAL} attribute on:`, this);\n if (total && !current) warn(`Missing ${ATTR_CURRENT} attribute on:`, this);\n\n attr(this, ATTR_LABEL, attrOrCSS(this, ATTR_LABEL));\n attr(this, 'role', 'navigation');\n this._unmutate = onMutation(this, render, {\n childList: true,\n subtree: true,\n });\n }\n attributeChangedCallback() {\n if (this._unmutate) render(this); // Ensure we do not run any renders before connectedCallback\n }\n disconnectedCallback() {\n this._unmutate?.();\n this._unmutate = this._render = undefined;\n }\n}\n\nconst render = (self: DSPaginationElement) => {\n const current = Number(attr(self, ATTR_CURRENT));\n const total = Number(attr(self, ATTR_TOTAL));\n\n // Allowing server side generated pagination, buy only doing client side updates if total/current attributes are provided\n if (current && total) {\n const items = self.querySelectorAll('button,a');\n const show = items.length - 2;\n const href = attr(self, ATTR_HREF);\n const { next, prev, pages } = pagination({ current, total, show });\n items.forEach((item, i) => {\n const page = i ? (items[i + 1] ? pages[i - 1]?.page : next) : prev; // First is prev, last is next\n attr(item, 'aria-current', pages[i - 1]?.current ? 'true' : null);\n attr(item, 'aria-label', `${page ?? 'hidden'}`); // Used for CSS content and to hide if more items than pages, using aria-label to make Axe tests and VoiceOver rotor happy\n attr(item, 'role', page ? null : 'none'); // Prevent validation errors for aria-hidden buttons\n attr(item, 'tabindex', page ? null : '-1');\n if (item instanceof HTMLButtonElement) attr(item, 'value', `${page}`);\n if (href && item instanceof HTMLAnchorElement)\n attr(item, 'href', href.replace('%d', `${page}`));\n });\n }\n};\n\nconst getSteps = (\n now: number,\n max: number,\n show = Number.POSITIVE_INFINITY,\n) => {\n const offset = (show - 1) / 2;\n const start = Math.max(Math.min(now - Math.floor(offset), max - show + 1), 1);\n const end = Math.min(Math.max(now + Math.ceil(offset), show), max);\n const pages = Array.from({ length: end + 1 - start }, (_, i) => i + start);\n\n if (show > 4 && start > 1) pages.splice(0, 2, 1, 0);\n if (show > 3 && end < max) pages.splice(-2, 2, 0, max);\n return pages;\n};\n\ncustomElements.define('ds-pagination', DSPaginationElement);\n"],"mappings":"sCAeM,EAAa,aACb,EAAe,eACf,EAAa,aACb,EAAY,YAGL,GAAc,CAAE,UAAU,EAAG,QAAQ,GAAI,OAAO,MAAS,CACpE,KAAM,EAAU,EAAI,EAAU,EAAI,EAClC,KAAM,EAAU,EAAQ,EAAU,EAAI,EACtC,MAAO,EAAS,EAAS,EAAO,CAAI,EAAE,KAAK,EAAM,KAAW,CAC1D,QAAS,IAAS,GAAY,OAC9B,IAAK,OAAO,EAAK,GAAG,IACpB,MACF,EAAE,CACJ,GAEA,IAAa,EAAb,cAAyCA,EAAAA,SAAU,CACjD,UACA,QAEA,WAAW,oBAAqB,CAC9B,MAAO,CAAC,EAAY,EAAc,EAAY,CAAS,CACzD,CACA,mBAAoB,CAElB,IAAM,EAAQC,EAAAA,KAAK,KA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AAK,EAAM,OAAQ,EAAK,QAAQ,KAAM,GAAG,GAAM,CAAC,CACpD,CAAC,CACH,CACF,EAEM,GACJ,EACA,EACA,EAAO,MACJ,CACH,IAAM,GAAU,EAAO,GAAK,EACtB,EAAQ,KAAK,IAAI,KAAK,IAAI,EAAM,KAAK,MAAM,CAAM,EAAG,EAAM,EAAO,CAAC,EAAG,CAAC,EACtE,EAAM,KAAK,IAAI,KAAK,IAAI,EAAM,KAAK,KAAK,CAAM,EAAG,CAAI,EAAG,CAAG,EAC3D,EAAQ,MAAM,KAAK,CAAE,OAAQ,EAAM,EAAI,CAAM,GAAI,EAAG,IAAM,EAAI,CAAK,EAIzE,OAFI,EAAO,GAAK,EAAQ,GAAG,EAAM,OAAO,EAAG,EAAG,EAAG,CAAC,EAC9C,EAAO,GAAK,EAAM,GAAK,EAAM,OAAO,GAAI,EAAG,EAAG,CAAG,EAC9C,CACT,EAEAG,EAAAA,eAAe,OAAO,gBAAiB,CAAmB"}
@@ -1,2 +1,2 @@
1
- require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../utils/utils.cjs`);let t=require(`@floating-ui/dom`);const n=`data-placement`,r=`data-autoplacement`,i=new Map;function a(a){let{newState:o,oldState:s,target:l,source:u=a.detail}=a,d=l instanceof HTMLElement&&e.attr(l,`popover`)!==null&&e.getCSSProp(l,`--_ds-floating`);if(!d)return;if(o===`closed`)return i.get(l)?.();if(!u){let e=l.getRootNode(),t=`[popovertarget="${l.id}"],[commandfor="${l.id}"]`;u=l.id&&e?.querySelector?.(t)||void 0}if(!u||u===l||s&&s===o)return;let f=e.getCSSProp(l,`--_ds-floating-overscroll`),p=e.attr(l,n)||e.attr(u,n)||d,m=e.attr(l,r)||e.attr(u,r),h=parseFloat(getComputedStyle(l,`::before`).height)||0,g=p.match(/left|right/gi)?`Height`:`Width`,_=u[`offset${g}`]/2+h;if(p===`none`)return;let v={strategy:`absolute`,placement:p,middleware:[(0,t.offset)(h||0),(0,t.shift)({padding:10,limiter:(0,t.limitShift)({offset:{mainAxis:_}})}),c(),...m===`false`?[]:[(0,t.flip)({padding:10,crossAxis:!1})],...f?[(0,t.size)({apply({availableHeight:e}){f===`fit`&&(l.style.width=`${u.clientWidth}px`),l.style.maxHeight=`${Math.max(50,e-20)}px`}})]:[]]},y=(0,t.autoUpdate)(u,l,async()=>{if(!u?.isConnected)return i.get(l)?.();let{x:e,y:n}=await(0,t.computePosition)(u,l,v);l.style.translate=`${e}px ${n}px`});i.set(l,()=>i.delete(l)&&y())}let o;const s=({type:e})=>{if(e===`mousedown`&&(o=!1),e===`scroll`&&o===!1&&(o=!0),e===`mouseup`&&o)for(let[e]of i)e.showPopover()};e.onHotReload(`popover`,()=>[e.on(document,`mousedown scroll mouseup`,s,!0),e.on(document,`toggle ds-toggle-source`,a,e.QUICK_EVENT)]);const c=()=>({name:`arrowPseudo`,fn(t){let n=t.elements.floating,r=t.rects.reference,i=`${Math.round(r.width/2+r.x-t.x)}px`,a=`${Math.round(r.height/2+r.y-t.y)}px`;return n.style.setProperty(`--_ds-floating-arrow-x`,i),n.style.setProperty(`--_ds-floating-arrow-y`,a),e.attr(n,`data-floating`,t.placement),t}});
1
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../utils/utils.cjs`);let t=require(`@floating-ui/dom`);const n=`data-placement`,r=`data-autoplacement`,i=new Map;function a(a){let{newState:o,oldState:s,target:l,source:u=a.detail}=a,d=l instanceof HTMLElement&&e.attr(l,`popover`)!==null&&e.getCSSProp(l,`--_ds-floating`);if(!d)return;if(o===`closed`)return i.get(l)?.();if(!u){let e=l.getRootNode(),t=`[popovertarget="${l.id}"],[commandfor="${l.id}"]`;u=l.id&&e?.querySelector?.(t)||void 0}if(!u||u===l||s&&s===o)return;let f=e.getCSSProp(l,`--_ds-floating-overscroll`),p=e.attr(l,n)||e.attr(u,n)||d,m=e.attr(l,r)||e.attr(u,r),h=parseFloat(getComputedStyle(l,`::before`).height)||0,g=p.match(/left|right/gi)?`Height`:`Width`,_=u[`offset${g}`]/2+h;if(p===`none`)return;let v={strategy:`absolute`,placement:p,middleware:[(0,t.offset)(h||0),(0,t.shift)({padding:10,limiter:(0,t.limitShift)({offset:{mainAxis:_}})}),c(),...m===`false`?[]:[(0,t.flip)({padding:10,crossAxis:!1})],...f?[(0,t.size)({apply({availableHeight:e}){f===`fit`&&(l.style.width=`${u.offsetWidth}px`),l.style.maxHeight=`${Math.max(50,e-20)}px`}})]:[]]},y=(0,t.autoUpdate)(u,l,async()=>{if(!u?.isConnected)return i.get(l)?.();let{x:e,y:n}=await(0,t.computePosition)(u,l,v);l.style.translate=`${e}px ${n}px`});i.set(l,()=>i.delete(l)&&y())}let o;const s=({type:e})=>{if(e===`mousedown`&&(o=!1),e===`scroll`&&o===!1&&(o=!0),e===`mouseup`&&o)for(let[e]of i)e.showPopover()};e.onHotReload(`popover`,()=>[e.on(document,`mousedown scroll mouseup`,s,!0),e.on(document,`toggle ds-toggle-source`,a,e.QUICK_EVENT)]);const c=()=>({name:`arrowPseudo`,fn(t){let n=t.elements.floating,r=t.rects.reference,i=`${Math.round(r.width/2+r.x-t.x)}px`,a=`${Math.round(r.height/2+r.y-t.y)}px`;return n.style.setProperty(`--_ds-floating-arrow-x`,i),n.style.setProperty(`--_ds-floating-arrow-y`,a),e.attr(n,`data-floating`,t.placement),t}});
2
2
  //# sourceMappingURL=popover.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"popover.cjs","names":["attr","getCSSProp","onHotReload","on","QUICK_EVENT"],"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 { attr, getCSSProp, on, onHotReload, QUICK_EVENT } from '../utils/utils';\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'ds-toggle-source': CustomEvent<Element>;\n }\n}\n\nconst ATTR_PLACE = 'data-placement';\nconst ATTR_AUTO = 'data-autoplacement';\nconst POPOVERS = new Map<HTMLElement, () => void>();\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)\nfunction handleToggle(\n event: Partial<ToggleEvent> & {\n detail?: HTMLElement;\n source?: HTMLElement;\n },\n) {\n let { newState, oldState, target: el, source = event.detail } = event;\n const isPopover = el instanceof HTMLElement && attr(el, 'popover') !== null;\n const float = isPopover && getCSSProp(el, '--_ds-floating');\n\n if (!float) return;\n if (newState === 'closed') return POPOVERS.get(el)?.(); // Cleanup on close\n if (!source) {\n const root = el.getRootNode() as Document; // Support shadow DOM\n const css = `[popovertarget=\"${el.id}\"],[commandfor=\"${el.id}\"]`;\n source = (el.id && root?.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 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(getComputedStyle(el, '::before').height) || 0;\n const shiftProp = placement.match(/left|right/gi) ? 'Height' : 'Width';\n const shiftLimit = source[`offset${shiftProp}`] / 2 + arrowSize;\n\n if (placement === 'none') return; // No need to position\n\n const options = {\n strategy: 'absolute',\n placement,\n middleware: [\n offset(arrowSize || 0), // Add space for arrow or default to 8px\n shift({\n padding,\n limiter: limitShift({ offset: { mainAxis: shiftLimit } }), // Prevent from shifing away from source\n }),\n arrowPseudo(),\n ...(auto !== 'false' ? [flip({ padding, crossAxis: false })] : []),\n ...(overscroll\n ? [\n size({\n apply({ availableHeight }) {\n if (overscroll === 'fit')\n el.style.width = `${source.clientWidth}px`;\n el.style.maxHeight = `${Math.max(50, availableHeight - padding * 2)}px`;\n },\n }),\n ]\n : []),\n ],\n } as ComputePositionConfig;\n const unfloat = autoUpdate(source, el, async () => {\n if (!source?.isConnected) return POPOVERS.get(el)?.(); // Cleanup 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, () => POPOVERS.delete(el) && unfloat());\n}\n\n// Prevent closing when mouse interacts with scrollbar\nlet IS_SCROLL: boolean | undefined;\nconst handleScrollbar = ({ type }: Event) => {\n if (type === 'mousedown') IS_SCROLL = false;\n if (type === 'scroll' && IS_SCROLL === false) IS_SCROLL = true;\n if (type === 'mouseup' && IS_SCROLL)\n for (const [popover] of POPOVERS) popover.showPopover(); // Immediately show again to prevent flicker\n};\n\nonHotReload('popover', () => [\n on(document, 'mousedown scroll mouseup', handleScrollbar, true),\n on(document, 'toggle ds-toggle-source', handleToggle, QUICK_EVENT), // Use capture since the toggle event does not bubble\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":"qHAkBA,MAAM,EAAa,iBACb,EAAY,qBACZ,EAAW,IAAI,IAIrB,SAAS,EACP,EAIA,CACA,GAAI,CAAE,WAAU,WAAU,OAAQ,EAAI,SAAS,EAAM,QAAW,EAE1D,EADY,aAAc,aAAeA,EAAAA,KAAK,EAAI,UAAU,GAAK,MAC5CC,EAAAA,WAAW,EAAI,iBAAiB,CAE3D,GAAI,CAAC,EAAO,OACZ,GAAI,IAAa,SAAU,OAAO,EAAS,IAAI,EAAG,IAAI,CACtD,GAAI,CAAC,EAAQ,CACX,IAAM,EAAO,EAAG,aAAa,CACvB,EAAM,mBAAmB,EAAG,GAAG,kBAAkB,EAAG,GAAG,IAC7D,EAAU,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EAAG,EAAI,GAAS,CAAC,CAI1D,IAAI,EACJ,MAAM,GAAmB,CAAE,UAAkB,CAG3C,GAFI,IAAS,cAAa,EAAY,IAClC,IAAS,UAAY,IAAc,KAAO,EAAY,IACtD,IAAS,WAAa,EACxB,IAAK,GAAM,CAAC,KAAY,EAAU,EAAQ,aAAa,EAG3DE,EAAAA,YAAY,cAAiB,CAC3BC,EAAAA,GAAG,SAAU,2BAA4B,EAAiB,GAAK,CAC/DA,EAAAA,GAAG,SAAU,0BAA2B,EAAcC,EAAAA,YAAY,CACnE,CAAC,CAEF,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,EAAE,CAAC,IACxD,EAAI,GAAG,KAAK,MAAM,EAAO,OAAS,EAAI,EAAO,EAAI,EAAK,EAAE,CAAC,IAK/D,OAHA,EAAO,MAAM,YAAY,yBAA0B,EAAE,CACrD,EAAO,MAAM,YAAY,yBAA0B,EAAE,CACrD,EAAA,KAAK,EAAQ,gBAAiB,EAAK,UAAU,CACtC,GAEV"}
1
+ {"version":3,"file":"popover.cjs","names":["attr","getCSSProp","onHotReload","on","QUICK_EVENT"],"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 { attr, getCSSProp, on, onHotReload, QUICK_EVENT } from '../utils/utils';\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'ds-toggle-source': CustomEvent<Element>;\n }\n}\n\nconst ATTR_PLACE = 'data-placement';\nconst ATTR_AUTO = 'data-autoplacement';\nconst POPOVERS = new Map<HTMLElement, () => void>();\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)\nfunction handleToggle(\n event: Partial<ToggleEvent> & {\n detail?: HTMLElement;\n source?: HTMLElement;\n },\n) {\n let { newState, oldState, target: el, source = event.detail } = event;\n const isPopover = el instanceof HTMLElement && attr(el, 'popover') !== null;\n const float = isPopover && getCSSProp(el, '--_ds-floating');\n\n if (!float) return;\n if (newState === 'closed') return POPOVERS.get(el)?.(); // Cleanup on close\n if (!source) {\n const root = el.getRootNode() as Document; // Support shadow DOM\n const css = `[popovertarget=\"${el.id}\"],[commandfor=\"${el.id}\"]`;\n source = (el.id && root?.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 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(getComputedStyle(el, '::before').height) || 0;\n const shiftProp = placement.match(/left|right/gi) ? 'Height' : 'Width';\n const shiftLimit = source[`offset${shiftProp}`] / 2 + arrowSize;\n\n if (placement === 'none') return; // No need to position\n\n const options = {\n strategy: 'absolute',\n placement,\n middleware: [\n offset(arrowSize || 0), // Add space for arrow or default to 8px\n shift({\n padding,\n limiter: limitShift({ offset: { mainAxis: shiftLimit } }), // Prevent from shifing away from source\n }),\n arrowPseudo(),\n ...(auto !== 'false' ? [flip({ padding, crossAxis: false })] : []),\n ...(overscroll\n ? [\n size({\n apply({ availableHeight }) {\n if (overscroll === 'fit')\n el.style.width = `${source.offsetWidth}px`; // Use offsetWidth to include padding, matching the width of the source element\n el.style.maxHeight = `${Math.max(50, availableHeight - padding * 2)}px`;\n },\n }),\n ]\n : []),\n ],\n } as ComputePositionConfig;\n const unfloat = autoUpdate(source, el, async () => {\n if (!source?.isConnected) return POPOVERS.get(el)?.(); // Cleanup 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, () => POPOVERS.delete(el) && unfloat());\n}\n\n// Prevent closing when mouse interacts with scrollbar\nlet IS_SCROLL: boolean | undefined;\nconst handleScrollbar = ({ type }: Event) => {\n if (type === 'mousedown') IS_SCROLL = false;\n if (type === 'scroll' && IS_SCROLL === false) IS_SCROLL = true;\n if (type === 'mouseup' && IS_SCROLL)\n for (const [popover] of POPOVERS) popover.showPopover(); // Immediately show again to prevent flicker\n};\n\nonHotReload('popover', () => [\n on(document, 'mousedown scroll mouseup', handleScrollbar, true),\n on(document, 'toggle ds-toggle-source', handleToggle, QUICK_EVENT), // Use capture since the toggle event does not bubble\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":"qHAkBA,MAAM,EAAa,iBACb,EAAY,qBACZ,EAAW,IAAI,IAIrB,SAAS,EACP,EAIA,CACA,GAAI,CAAE,WAAU,WAAU,OAAQ,EAAI,SAAS,EAAM,QAAW,EAE1D,EADY,aAAc,aAAeA,EAAAA,KAAK,EAAI,SAAS,IAAM,MAC5CC,EAAAA,WAAW,EAAI,gBAAgB,EAE1D,GAAI,CAAC,EAAO,OACZ,GAAI,IAAa,SAAU,OAAO,EAAS,IAAI,CAAE,IAAI,EACrD,GAAI,CAAC,EAAQ,CACX,IAAM,EAAO,EAAG,YAAY,EACtB,EAAM,mBAAmB,EAAG,GAAG,kBAAkB,EAAG,GAAG,IAC7D,EAAU,EAAG,IAAM,GAAM,gBAA6B,CAAG,GAAM,IAAA,EACjE,CACA,GAAI,CAAC,GAAU,IAAW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E,UAAkB,CAG3C,GAFI,IAAS,cAAa,EAAY,IAClC,IAAS,UAAY,IAAc,KAAO,EAAY,IACtD,IAAS,WAAa,EACxB,IAAK,GAAM,CAAC,KAAY,EAAU,EAAQ,YAAY,CAC1D,EAEAE,EAAAA,YAAY,cAAiB,CAC3BC,EAAAA,GAAG,SAAU,2BAA4B,EAAiB,EAAI,EAC9DA,EAAAA,GAAG,SAAU,0BAA2B,EAAcC,EAAAA,WAAW,CACnE,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 +1 @@
1
- {"version":3,"file":"readonly.cjs","names":["attr","onHotReload","on"],"sources":["../../../src/readonly/readonly.ts"],"sourcesContent":["import { attr, on, onHotReload } from '../utils/utils';\n\nconst isReadOnly = (el: unknown): el is HTMLInputElement | HTMLSelectElement =>\n (el instanceof HTMLSelectElement || el instanceof HTMLInputElement) &&\n (el.hasAttribute('readonly') || attr(el, 'aria-readonly') === 'true');\n\n// Allow tabbing when readonly, and only fix readonly input/select elements (since type select and non-text-inputs do not support readonly)\n// If radio buttons, move focus without changing checked state\nconst handleKeyDown = (e: Event & Partial<KeyboardEvent>) => {\n if (e.key !== 'Tab' && isReadOnly(e.target)) {\n const isArrow = e.key?.startsWith('Arrow'); // Always control arrow keys\n const isModifier = e.altKey || e.ctrlKey || e.metaKey; // Allow modifier keys so native functions like CMD + D to bookmark etc. still works\n\n if (isArrow || !isModifier) e.preventDefault(); // Prevent changing <select> value with keyboard, but allow non-arrow modifier keys\n if (isArrow && attr(e.target, 'type') === 'radio') {\n const all = document.querySelectorAll(`input[name=\"${e.target.name}\"]`);\n const move = e.key?.match(/Arrow(Right|Down)/) ? 1 : -1;\n const next = all.length + [...all].indexOf(e.target) + move;\n (all[next % all.length] as HTMLElement)?.focus();\n }\n }\n};\n\nconst handleClick = (e: Event) => {\n const input = (e.target as Element)?.closest?.('label')?.control || e.target;\n if (isReadOnly(input)) {\n e.preventDefault();\n input.focus();\n }\n};\n\nconst handleMouseDown = (e: Event) => {\n if (e.target instanceof HTMLSelectElement && isReadOnly(e.target))\n e.preventDefault();\n};\n\nonHotReload('readonly', () => [\n on(document, 'keydown', handleKeyDown),\n on(document, 'click', handleClick), // click needed for <label> and <input>\n on(document, 'mousedown', handleMouseDown), // mousedown needed for <select>\n]);\n"],"mappings":"sCAEM,EAAc,IACjB,aAAc,mBAAqB,aAAc,oBACjD,EAAG,aAAa,WAAW,EAAIA,EAAAA,KAAK,EAAI,gBAAgB,GAAK,QAI1D,EAAiB,GAAsC,CAC3D,GAAI,EAAE,MAAQ,OAAS,EAAW,EAAE,OAAO,CAAE,CAC3C,IAAM,EAAU,EAAE,KAAK,WAAW,QAAQ,CACpC,EAAa,EAAE,QAAU,EAAE,SAAW,EAAE,QAG9C,IADI,GAAW,CAAC,IAAY,EAAE,gBAAgB,CAC1C,GAAWA,EAAAA,KAAK,EAAE,OAAQ,OAAO,GAAK,QAAS,CACjD,IAAM,EAAM,SAAS,iBAAiB,eAAe,EAAE,OAAO,KAAK,IAAI,CACjE,EAAO,EAAE,KAAK,MAAM,oBAAoB,CAAG,EAAI,GAEpD,GADY,EAAI,OAAS,CAAC,GAAG,EAAI,CAAC,QAAQ,EAAE,OAAO,CAAG,GAC3C,EAAI,SAAyB,OAAO,IAKhD,EAAe,GAAa,CAChC,IAAM,EAAS,EAAE,QAAoB,UAAU,QAAQ,EAAE,SAAW,EAAE,OAClE,EAAW,EAAM,GACnB,EAAE,gBAAgB,CAClB,EAAM,OAAO,GAIX,EAAmB,GAAa,CAChC,EAAE,kBAAkB,mBAAqB,EAAW,EAAE,OAAO,EAC/D,EAAE,gBAAgB,EAGtBC,EAAAA,YAAY,eAAkB,CAC5BC,EAAAA,GAAG,SAAU,UAAW,EAAc,CACtCA,EAAAA,GAAG,SAAU,QAAS,EAAY,CAClCA,EAAAA,GAAG,SAAU,YAAa,EAAgB,CAC3C,CAAC"}
1
+ {"version":3,"file":"readonly.cjs","names":["attr","onHotReload","on"],"sources":["../../../src/readonly/readonly.ts"],"sourcesContent":["import { attr, on, onHotReload } from '../utils/utils';\n\nconst isReadOnly = (el: unknown): el is HTMLInputElement | HTMLSelectElement =>\n (el instanceof HTMLSelectElement || el instanceof HTMLInputElement) &&\n (el.hasAttribute('readonly') || attr(el, 'aria-readonly') === 'true');\n\n// Allow tabbing when readonly, and only fix readonly input/select elements (since type select and non-text-inputs do not support readonly)\n// If radio buttons, move focus without changing checked state\nconst handleKeyDown = (e: Event & Partial<KeyboardEvent>) => {\n if (e.key !== 'Tab' && isReadOnly(e.target)) {\n const isArrow = e.key?.startsWith('Arrow'); // Always control arrow keys\n const isModifier = e.altKey || e.ctrlKey || e.metaKey; // Allow modifier keys so native functions like CMD + D to bookmark etc. still works\n\n if (isArrow || !isModifier) e.preventDefault(); // Prevent changing <select> value with keyboard, but allow non-arrow modifier keys\n if (isArrow && attr(e.target, 'type') === 'radio') {\n const all = document.querySelectorAll(`input[name=\"${e.target.name}\"]`);\n const move = e.key?.match(/Arrow(Right|Down)/) ? 1 : -1;\n const next = all.length + [...all].indexOf(e.target) + move;\n (all[next % all.length] as HTMLElement)?.focus();\n }\n }\n};\n\nconst handleClick = (e: Event) => {\n const input = (e.target as Element)?.closest?.('label')?.control || e.target;\n if (isReadOnly(input)) {\n e.preventDefault();\n input.focus();\n }\n};\n\nconst handleMouseDown = (e: Event) => {\n if (e.target instanceof HTMLSelectElement && isReadOnly(e.target))\n e.preventDefault();\n};\n\nonHotReload('readonly', () => [\n on(document, 'keydown', handleKeyDown),\n on(document, 'click', handleClick), // click needed for <label> and <input>\n on(document, 'mousedown', handleMouseDown), // mousedown needed for <select>\n]);\n"],"mappings":"sCAEM,EAAc,IACjB,aAAc,mBAAqB,aAAc,oBACjD,EAAG,aAAa,UAAU,GAAKA,EAAAA,KAAK,EAAI,eAAe,IAAM,QAI1D,EAAiB,GAAsC,CAC3D,GAAI,EAAE,MAAQ,OAAS,EAAW,EAAE,MAAM,EAAG,CAC3C,IAAM,EAAU,EAAE,KAAK,WAAW,OAAO,EACnC,EAAa,EAAE,QAAU,EAAE,SAAW,EAAE,QAG9C,IADI,GAAW,CAAC,IAAY,EAAE,eAAe,EACzC,GAAWA,EAAAA,KAAK,EAAE,OAAQ,MAAM,IAAM,QAAS,CACjD,IAAM,EAAM,SAAS,iBAAiB,eAAe,EAAE,OAAO,KAAK,GAAG,EAChE,EAAO,EAAE,KAAK,MAAM,mBAAmB,EAAI,EAAI,GAErD,GADa,EAAI,OAAS,CAAC,GAAG,CAAG,EAAE,QAAQ,EAAE,MAAM,EAAI,GAC3C,EAAI,SAAyB,MAAM,CACjD,CACF,CACF,EAEM,EAAe,GAAa,CAChC,IAAM,EAAS,EAAE,QAAoB,UAAU,OAAO,GAAG,SAAW,EAAE,OAClE,EAAW,CAAK,IAClB,EAAE,eAAe,EACjB,EAAM,MAAM,EAEhB,EAEM,EAAmB,GAAa,CAChC,EAAE,kBAAkB,mBAAqB,EAAW,EAAE,MAAM,GAC9D,EAAE,eAAe,CACrB,EAEAC,EAAAA,YAAY,eAAkB,CAC5BC,EAAAA,GAAG,SAAU,UAAW,CAAa,EACrCA,EAAAA,GAAG,SAAU,QAAS,CAAW,EACjCA,EAAAA,GAAG,SAAU,YAAa,CAAe,CAC3C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"suggestion.cjs","names":["UHTMLComboboxElement","onMutation","QUICK_EVENT","useId","customElements"],"sources":["../../../src/suggestion/suggestion.ts"],"sourcesContent":["import { UHTMLComboboxElement } from '@u-elements/u-combobox';\nimport {\n attr,\n customElements,\n off,\n on,\n onMutation,\n QUICK_EVENT,\n useId,\n} from '../utils/utils';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-suggestion': DSSuggestionElement;\n }\n}\n\nexport class DSSuggestionElement extends UHTMLComboboxElement {\n _unmutate?: ReturnType<typeof onMutation>; // Using underscore instead of private fields for backwards compatibility\n\n connectedCallback() {\n super.connectedCallback();\n this._unmutate = onMutation(this, render, { childList: true }); // .control and .list are direct children of the custom element\n on(this, 'toggle', polyfillToggleSource, QUICK_EVENT);\n }\n disconnectedCallback() {\n super.disconnectedCallback();\n this._unmutate?.();\n this._unmutate = undefined;\n off(this, 'toggle', polyfillToggleSource, QUICK_EVENT);\n }\n}\n\n// A non-empty placeholder attribute is required to activate the :placeholder-shown pseudo selector used in our chevron styling\nconst render = ({ control, list }: DSSuggestionElement) => {\n if (control && !control.placeholder) attr(control, 'placeholder', ' '); // .control comes from UHTMLComboboxElement\n if (control) attr(control, 'popovertarget', useId(list) || null);\n if (list) attr(list, 'popover', 'manual'); // Ensure popover attribute is set on the list\n if (list) attr(list, 'data-is-floating', 'true'); // identifier for css to toggle opacity when it is placed by floating-ui.\n};\n\n// Since showPopover({ source }) is not supported in all browsers yet:\nconst polyfillToggleSource = (event: Partial<ToggleEvent>) => {\n const self = event.currentTarget as DSSuggestionElement;\n const detail = event.newState === 'open' && self.control; // .control comes from UHTMLComboboxElement\n\n if (detail)\n self.list?.dispatchEvent(new CustomEvent('ds-toggle-source', { detail }));\n};\n\ncustomElements.define('ds-suggestion', DSSuggestionElement);\n"],"mappings":"2HAiBA,IAAa,EAAb,cAAyCA,EAAAA,oBAAqB,CAC5D,UAEA,mBAAoB,CAClB,MAAM,mBAAmB,CACzB,KAAK,UAAYC,EAAAA,WAAW,KAAM,EAAQ,CAAE,UAAW,GAAM,CAAC,CAC9D,EAAA,GAAG,KAAM,SAAU,EAAsBC,EAAAA,YAAY,CAEvD,sBAAuB,CACrB,MAAM,sBAAsB,CAC5B,KAAK,aAAa,CAClB,KAAK,UAAY,IAAA,GACjB,EAAA,IAAI,KAAM,SAAU,EAAsBA,EAAAA,YAAY,GAK1D,MAAM,GAAU,CAAE,UAAS,UAAgC,CACrD,GAAW,CAAC,EAAQ,aAAa,EAAA,KAAK,EAAS,cAAe,IAAI,CAClE,GAAS,EAAA,KAAK,EAAS,gBAAiBC,EAAAA,MAAM,EAAK,EAAI,KAAK,CAC5D,GAAM,EAAA,KAAK,EAAM,UAAW,SAAS,CACrC,GAAM,EAAA,KAAK,EAAM,mBAAoB,OAAO,EAI5C,EAAwB,GAAgC,CAC5D,IAAM,EAAO,EAAM,cACb,EAAS,EAAM,WAAa,QAAU,EAAK,QAE7C,GACF,EAAK,MAAM,cAAc,IAAI,YAAY,mBAAoB,CAAE,SAAQ,CAAC,CAAC,EAG7EC,EAAAA,eAAe,OAAO,gBAAiB,EAAoB"}
1
+ {"version":3,"file":"suggestion.cjs","names":["UHTMLComboboxElement","onMutation","QUICK_EVENT","useId","customElements"],"sources":["../../../src/suggestion/suggestion.ts"],"sourcesContent":["import { UHTMLComboboxElement } from '@u-elements/u-combobox';\nimport {\n attr,\n customElements,\n off,\n on,\n onMutation,\n QUICK_EVENT,\n useId,\n} from '../utils/utils';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-suggestion': DSSuggestionElement;\n }\n}\n\nexport class DSSuggestionElement extends UHTMLComboboxElement {\n _unmutate?: ReturnType<typeof onMutation>; // Using underscore instead of private fields for backwards compatibility\n\n connectedCallback() {\n super.connectedCallback();\n this._unmutate = onMutation(this, render, { childList: true }); // .control and .list are direct children of the custom element\n on(this, 'toggle', polyfillToggleSource, QUICK_EVENT);\n }\n disconnectedCallback() {\n super.disconnectedCallback();\n this._unmutate?.();\n this._unmutate = undefined;\n off(this, 'toggle', polyfillToggleSource, QUICK_EVENT);\n }\n}\n\n// A non-empty placeholder attribute is required to activate the :placeholder-shown pseudo selector used in our chevron styling\nconst render = ({ control, list }: DSSuggestionElement) => {\n if (control && !control.placeholder) attr(control, 'placeholder', ' '); // .control comes from UHTMLComboboxElement\n if (control) attr(control, 'popovertarget', useId(list) || null);\n if (list) attr(list, 'popover', 'manual'); // Ensure popover attribute is set on the list\n if (list) attr(list, 'data-is-floating', 'true'); // identifier for css to toggle opacity when it is placed by floating-ui.\n};\n\n// Since showPopover({ source }) is not supported in all browsers yet:\nconst polyfillToggleSource = (event: Partial<ToggleEvent>) => {\n const self = event.currentTarget as DSSuggestionElement;\n const detail = event.newState === 'open' && self.control; // .control comes from UHTMLComboboxElement\n\n if (detail)\n self.list?.dispatchEvent(new CustomEvent('ds-toggle-source', { detail }));\n};\n\ncustomElements.define('ds-suggestion', DSSuggestionElement);\n"],"mappings":"2HAiBA,IAAa,EAAb,cAAyCA,EAAAA,oBAAqB,CAC5D,UAEA,mBAAoB,CAClB,MAAM,kBAAkB,EACxB,KAAK,UAAYC,EAAAA,WAAW,KAAM,EAAQ,CAAE,UAAW,EAAK,CAAC,EAC7D,EAAA,GAAG,KAAM,SAAU,EAAsBC,EAAAA,WAAW,CACtD,CACA,sBAAuB,CACrB,MAAM,qBAAqB,EAC3B,KAAK,YAAY,EACjB,KAAK,UAAY,IAAA,GACjB,EAAA,IAAI,KAAM,SAAU,EAAsBA,EAAAA,WAAW,CACvD,CACF,EAGA,MAAM,GAAU,CAAE,UAAS,UAAgC,CACrD,GAAW,CAAC,EAAQ,aAAa,EAAA,KAAK,EAAS,cAAe,GAAG,EACjE,GAAS,EAAA,KAAK,EAAS,gBAAiBC,EAAAA,MAAM,CAAI,GAAK,IAAI,EAC3D,GAAM,EAAA,KAAK,EAAM,UAAW,QAAQ,EACpC,GAAM,EAAA,KAAK,EAAM,mBAAoB,MAAM,CACjD,EAGM,EAAwB,GAAgC,CAC5D,IAAM,EAAO,EAAM,cACb,EAAS,EAAM,WAAa,QAAU,EAAK,QAE7C,GACF,EAAK,MAAM,cAAc,IAAI,YAAY,mBAAoB,CAAE,QAAO,CAAC,CAAC,CAC5E,EAEAC,EAAAA,eAAe,OAAO,gBAAiB,CAAmB"}
@@ -1,2 +1,2 @@
1
- const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`../utils/utils.cjs`);let n=require(`@u-elements/u-tabs`);n=e.__toESM(n);var r=class extends n.UHTMLTabsElement{},i=class extends n.UHTMLTabListElement{},a=class extends n.UHTMLTabElement{},o=class extends n.UHTMLTabPanelElement{};t.customElements.define(`ds-tabs`,r),t.customElements.define(`ds-tablist`,i),t.customElements.define(`ds-tab`,a),t.customElements.define(`ds-tabpanel`,o),exports.DSTabElement=a,exports.DSTabListElement=i,exports.DSTabPanelElement=o,exports.DSTabsElement=r;
1
+ const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`../utils/utils.cjs`);let n=require(`@u-elements/u-tabs`);n=e.__toESM(n,1);var r=class extends n.UHTMLTabsElement{},i=class extends n.UHTMLTabListElement{},a=class extends n.UHTMLTabElement{},o=class extends n.UHTMLTabPanelElement{};t.customElements.define(`ds-tabs`,r),t.customElements.define(`ds-tablist`,i),t.customElements.define(`ds-tab`,a),t.customElements.define(`ds-tabpanel`,o),exports.DSTabElement=a,exports.DSTabListElement=i,exports.DSTabPanelElement=o,exports.DSTabsElement=r;
2
2
  //# sourceMappingURL=tabs.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"tabs.cjs","names":["UTabs","customElements"],"sources":["../../../src/tabs/tabs.ts"],"sourcesContent":["import * as UTabs from '@u-elements/u-tabs';\nimport { customElements } from '../utils/utils';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-tabs': DSTabsElement;\n 'ds-tablist': DSTabListElement;\n 'ds-tab': DSTabElement;\n 'ds-tabpanel': DSTabPanelElement;\n }\n}\n\nexport class DSTabsElement extends UTabs.UHTMLTabsElement {}\nexport class DSTabListElement extends UTabs.UHTMLTabListElement {}\nexport class DSTabElement extends UTabs.UHTMLTabElement {}\nexport class DSTabPanelElement extends UTabs.UHTMLTabPanelElement {}\n\ncustomElements.define('ds-tabs', DSTabsElement);\ncustomElements.define('ds-tablist', DSTabListElement);\ncustomElements.define('ds-tab', DSTabElement);\ncustomElements.define('ds-tabpanel', DSTabPanelElement);\n"],"mappings":"wIAYA,IAAa,EAAb,cAAmCA,EAAM,gBAAiB,GAC7C,EAAb,cAAsCA,EAAM,mBAAoB,GACnD,EAAb,cAAkCA,EAAM,eAAgB,GAC3C,EAAb,cAAuCA,EAAM,oBAAqB,GAElEC,EAAAA,eAAe,OAAO,UAAW,EAAc,CAC/CA,EAAAA,eAAe,OAAO,aAAc,EAAiB,CACrDA,EAAAA,eAAe,OAAO,SAAU,EAAa,CAC7CA,EAAAA,eAAe,OAAO,cAAe,EAAkB"}
1
+ {"version":3,"file":"tabs.cjs","names":["UTabs","customElements"],"sources":["../../../src/tabs/tabs.ts"],"sourcesContent":["import * as UTabs from '@u-elements/u-tabs';\nimport { customElements } from '../utils/utils';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-tabs': DSTabsElement;\n 'ds-tablist': DSTabListElement;\n 'ds-tab': DSTabElement;\n 'ds-tabpanel': DSTabPanelElement;\n }\n}\n\nexport class DSTabsElement extends UTabs.UHTMLTabsElement {}\nexport class DSTabListElement extends UTabs.UHTMLTabListElement {}\nexport class DSTabElement extends UTabs.UHTMLTabElement {}\nexport class DSTabPanelElement extends UTabs.UHTMLTabPanelElement {}\n\ncustomElements.define('ds-tabs', DSTabsElement);\ncustomElements.define('ds-tablist', DSTabListElement);\ncustomElements.define('ds-tab', DSTabElement);\ncustomElements.define('ds-tabpanel', DSTabPanelElement);\n"],"mappings":"0IAYA,IAAa,EAAb,cAAmCA,EAAM,gBAAiB,CAAC,EAC9C,EAAb,cAAsCA,EAAM,mBAAoB,CAAC,EACpD,EAAb,cAAkCA,EAAM,eAAgB,CAAC,EAC5C,EAAb,cAAuCA,EAAM,oBAAqB,CAAC,EAEnEC,EAAAA,eAAe,OAAO,UAAW,CAAa,EAC9CA,EAAAA,eAAe,OAAO,aAAc,CAAgB,EACpDA,EAAAA,eAAe,OAAO,SAAU,CAAY,EAC5CA,EAAAA,eAAe,OAAO,cAAe,CAAiB"}
@@ -1 +1 @@
1
- {"version":3,"file":"toggle-group.cjs","names":["attrOrCSS","attr","onHotReload","on","onMutation"],"sources":["../../../src/toggle-group/toggle-group.ts"],"sourcesContent":["import { attr, attrOrCSS, on, onHotReload, onMutation } from '../utils/utils';\n\nconst ARIA_LABELLEDBY = 'aria-labelledby';\nconst ARIA_LABEL = 'aria-label';\nconst ATTR_TOGGLEGROUP = 'data-toggle-group';\nconst SELECTOR_TOGGLEGROUP = `[${ATTR_TOGGLEGROUP}]`;\n\nconst handleAriaAttributes = () => {\n for (const group of document.querySelectorAll(SELECTOR_TOGGLEGROUP))\n attr(group, 'aria-label', attrOrCSS(group, ATTR_TOGGLEGROUP));\n};\n\nconst handleKeydown = (event: Partial<KeyboardEvent>) => {\n const { key, target: el } = event;\n const group =\n el instanceof HTMLInputElement && el.closest(SELECTOR_TOGGLEGROUP);\n\n if (!group) return;\n if (!attr(group, ARIA_LABEL) && !attr(group, ARIA_LABELLEDBY))\n attr(group, ARIA_LABEL, attrOrCSS(group, ATTR_TOGGLEGROUP));\n if (key === 'Enter') el.click(); // Forward Enter, but no need to listen for space key, as this is handled by the browser\n if (key?.startsWith('Arrow')) {\n event.preventDefault?.();\n const inputs = [...group.getElementsByTagName('input')];\n const index = inputs.indexOf(el);\n const move = key.match(/Arrow(Right|Down)/) ? 1 : -1;\n let nextIndex = index;\n\n for (let i = 0; i < inputs.length; i++) {\n nextIndex = (inputs.length + nextIndex + move) % inputs.length;\n if (!inputs[nextIndex]?.disabled) {\n inputs[nextIndex]?.focus();\n break;\n }\n }\n }\n};\n\nonHotReload('toggle-group', () => [\n on(document, 'keydown', handleKeydown),\n onMutation(document, handleAriaAttributes, {\n attributeFilter: [ATTR_TOGGLEGROUP],\n attributes: true,\n childList: true,\n subtree: true,\n }),\n]);\n"],"mappings":"sCAGM,EAAa,aACb,EAAmB,oBACnB,EAAuB,IAAI,EAAiB,GAE5C,MAA6B,CACjC,IAAK,IAAM,KAAS,SAAS,iBAAiB,EAAqB,CACjE,EAAA,KAAK,EAAO,aAAcA,EAAAA,UAAU,EAAO,EAAiB,CAAC,EAG3D,EAAiB,GAAkC,CACvD,GAAM,CAAE,MAAK,OAAQ,GAAO,EACtB,EACJ,aAAc,kBAAoB,EAAG,QAAQ,EAAqB,CAE/D,OACD,CAACC,EAAAA,KAAK,EAAO,EAAW,EAAI,CAACA,EAAAA,KAAK,EAAO,kBAAgB,EAC3D,EAAA,KAAK,EAAO,EAAYD,EAAAA,UAAU,EAAO,EAAiB,CAAC,CACzD,IAAQ,SAAS,EAAG,OAAO,CAC3B,GAAK,WAAW,QAAQ,EAAE,CAC5B,EAAM,kBAAkB,CACxB,IAAM,EAAS,CAAC,GAAG,EAAM,qBAAqB,QAAQ,CAAC,CACjD,EAAQ,EAAO,QAAQ,EAAG,CAC1B,EAAO,EAAI,MAAM,oBAAoB,CAAG,EAAI,GAC9C,EAAY,EAEhB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,OAAQ,IAEjC,GADA,GAAa,EAAO,OAAS,EAAY,GAAQ,EAAO,OACpD,CAAC,EAAO,IAAY,SAAU,CAChC,EAAO,IAAY,OAAO,CAC1B,SAMRE,EAAAA,YAAY,mBAAsB,CAChCC,EAAAA,GAAG,SAAU,UAAW,EAAc,CACtCC,EAAAA,WAAW,SAAU,EAAsB,CACzC,gBAAiB,CAAC,EAAiB,CACnC,WAAY,GACZ,UAAW,GACX,QAAS,GACV,CAAC,CACH,CAAC"}
1
+ {"version":3,"file":"toggle-group.cjs","names":["attrOrCSS","attr","onHotReload","on","onMutation"],"sources":["../../../src/toggle-group/toggle-group.ts"],"sourcesContent":["import { attr, attrOrCSS, on, onHotReload, onMutation } from '../utils/utils';\n\nconst ARIA_LABELLEDBY = 'aria-labelledby';\nconst ARIA_LABEL = 'aria-label';\nconst ATTR_TOGGLEGROUP = 'data-toggle-group';\nconst SELECTOR_TOGGLEGROUP = `[${ATTR_TOGGLEGROUP}]`;\n\nconst handleAriaAttributes = () => {\n for (const group of document.querySelectorAll(SELECTOR_TOGGLEGROUP))\n attr(group, 'aria-label', attrOrCSS(group, ATTR_TOGGLEGROUP));\n};\n\nconst handleKeydown = (event: Partial<KeyboardEvent>) => {\n const { key, target: el } = event;\n const group =\n el instanceof HTMLInputElement && el.closest(SELECTOR_TOGGLEGROUP);\n\n if (!group) return;\n if (!attr(group, ARIA_LABEL) && !attr(group, ARIA_LABELLEDBY))\n attr(group, ARIA_LABEL, attrOrCSS(group, ATTR_TOGGLEGROUP));\n if (key === 'Enter') el.click(); // Forward Enter, but no need to listen for space key, as this is handled by the browser\n if (key?.startsWith('Arrow')) {\n event.preventDefault?.();\n const inputs = [...group.getElementsByTagName('input')];\n const index = inputs.indexOf(el);\n const move = key.match(/Arrow(Right|Down)/) ? 1 : -1;\n let nextIndex = index;\n\n for (let i = 0; i < inputs.length; i++) {\n nextIndex = (inputs.length + nextIndex + move) % inputs.length;\n if (!inputs[nextIndex]?.disabled) {\n inputs[nextIndex]?.focus();\n break;\n }\n }\n }\n};\n\nonHotReload('toggle-group', () => [\n on(document, 'keydown', handleKeydown),\n onMutation(document, handleAriaAttributes, {\n attributeFilter: [ATTR_TOGGLEGROUP],\n attributes: true,\n childList: true,\n subtree: true,\n }),\n]);\n"],"mappings":"sCAGM,EAAa,aACb,EAAmB,oBACnB,EAAuB,IAAI,EAAiB,GAE5C,MAA6B,CACjC,IAAK,IAAM,KAAS,SAAS,iBAAiB,CAAoB,EAChE,EAAA,KAAK,EAAO,aAAcA,EAAAA,UAAU,EAAO,CAAgB,CAAC,CAChE,EAEM,EAAiB,GAAkC,CACvD,GAAM,CAAE,MAAK,OAAQ,GAAO,EACtB,EACJ,aAAc,kBAAoB,EAAG,QAAQ,CAAoB,EAE9D,OACD,CAACC,EAAAA,KAAK,EAAO,CAAU,GAAK,CAACA,EAAAA,KAAK,EAAO,iBAAe,GAC1D,EAAA,KAAK,EAAO,EAAYD,EAAAA,UAAU,EAAO,CAAgB,CAAC,EACxD,IAAQ,SAAS,EAAG,MAAM,EAC1B,GAAK,WAAW,OAAO,GAAG,CAC5B,EAAM,iBAAiB,EACvB,IAAM,EAAS,CAAC,GAAG,EAAM,qBAAqB,OAAO,CAAC,EAChD,EAAQ,EAAO,QAAQ,CAAE,EACzB,EAAO,EAAI,MAAM,mBAAmB,EAAI,EAAI,GAC9C,EAAY,EAEhB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,OAAQ,IAEjC,GADA,GAAa,EAAO,OAAS,EAAY,GAAQ,EAAO,OACpD,CAAC,EAAO,IAAY,SAAU,CAChC,EAAO,IAAY,MAAM,EACzB,KACF,CAEJ,CACF,EAEAE,EAAAA,YAAY,mBAAsB,CAChCC,EAAAA,GAAG,SAAU,UAAW,CAAa,EACrCC,EAAAA,WAAW,SAAU,EAAsB,CACzC,gBAAiB,CAAC,CAAgB,EAClC,WAAY,GACZ,UAAW,GACX,QAAS,EACX,CAAC,CACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip.cjs","names":["isBrowser","attrOrCSS","attr","tag","onHotReload","on","QUICK_EVENT","onMutation"],"sources":["../../../src/tooltip/tooltip.ts"],"sourcesContent":["import {\n announce,\n attr,\n attrOrCSS,\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 SOURCE: Element | undefined;\nlet IS_HOVERING = false;\nlet HOVER_TIMER: number | ReturnType<typeof setTimeout> = 0;\nlet SKIP_TIMER: number | ReturnType<typeof setTimeout> = 0;\nconst IS_IOS = isBrowser() && /iPad|iPhone|iPod/.test(navigator.userAgent); // Needed to omit DELAY_HOVER since iOS triggers mouseover before click\nconst ATTR_TOOLTIP = 'data-tooltip';\nconst ATTR_COLOR = 'data-color';\nconst ARIA_LABEL = 'aria-label';\nconst ARIA_DESC = 'aria-description';\nconst SELECTOR_COLOR = `[${ATTR_COLOR}]`;\nconst SELECTOR_TOOLTIP = `[${ATTR_TOOLTIP}]`;\nconst ATTR_SCHEME = 'data-color-scheme';\nconst SELECTOR_SCHEME = `[${ATTR_SCHEME}]`;\nconst SELECTOR_INTERACTIVE = 'a,button,input,label,select,textarea,[tabindex]';\nconst DELAY_HOVER = 300;\nconst DELAY_SKIP = 300;\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 clearTimeout(SKIP_TIMER); // Reset when changing source\n clearTimeout(HOVER_TIMER);\n SOURCE = undefined;\n IS_HOVERING = false;\n TIP = el || undefined;\n};\n\nconst handleAriaAttributes = () => {\n for (const el of document.querySelectorAll(SELECTOR_TOOLTIP)) {\n const text = attrOrCSS(el, ATTR_TOOLTIP);\n\n if (!text) return; // Early return if no tooltip text\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.matches(SELECTOR_INTERACTIVE))\n warn('Missing tabindex=\"0\" attribute on: ', el);\n }\n\n // If an existing tooltip has changed programmatically, update tooltip text and announce change\n const isCurrent = el === SOURCE && TIP?.offsetHeight && TIP?.offsetWidth; // Using offsetHeight+Width to check visibility as :popover-open is not well supported by JSDOM\n const isChanged = isCurrent && text && TIP?.textContent !== text; // Only update if mutation is on source element and tooltip is open to avoid unnecessary updates\n if (isCurrent && isChanged) {\n if (TIP) TIP.textContent = text;\n if (document.activeElement === el) announce(text); // Only announce if focus is on the button\n }\n }\n};\n\nconst handleInterest = ({ type, target }: Event) => {\n clearTimeout(HOVER_TIMER);\n\n if (target === TIP) return; // Allow tooltip to be hovered, following https://www.w3.org/TR/WCAG21/#content-on-hover-or-focus\n if (type === 'mouseover' && !IS_HOVERING && !IS_IOS) {\n HOVER_TIMER = setTimeout(handleInterest, DELAY_HOVER, { target }); // Delay mouse showing tooltip if not already shown\n return;\n }\n\n const source = (target as Element)?.closest?.(`[${ATTR_TOOLTIP}]`);\n if (source === SOURCE) return; // No need to update\n if (!source) return hideTooltip(); // If no new anchor, cleanup previous autoUpdate\n if (!TIP) TIP = tag('div', { class: 'ds-tooltip' });\n if (!TIP.isConnected) document.body.appendChild(TIP); // Ensure connected\n\n const color = source.closest(SELECTOR_COLOR); // Match source color of source element\n const scheme = source.closest(SELECTOR_SCHEME); // Match source color-scheme 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 clearTimeout(SKIP_TIMER);\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 TIP.textContent = attr(source, ATTR_TOOLTIP);\n TIP.showPopover();\n TIP.dispatchEvent(new CustomEvent('ds-toggle-source', { detail: source })); // Since showPopover({ source }) is not supported in all browsers yet\n IS_HOVERING = true;\n SOURCE = source;\n};\n\nconst hideTooltip = () => TIP?.isConnected && TIP.popover && TIP.hidePopover(); // Only hide if connected and activated\n\nconst handleClose = (event?: Partial<ToggleEvent & KeyboardEvent>) => {\n if (event?.type === 'keydown')\n return event?.key === 'Escape' && hideTooltip();\n if (!event) IS_HOVERING = false;\n else if (event.target === TIP && event.newState === 'closed') {\n SOURCE = undefined;\n SKIP_TIMER = setTimeout(handleClose, DELAY_SKIP);\n }\n};\n\nonHotReload('tooltip', () => [\n on(document, 'blur focus mouseover', handleInterest, QUICK_EVENT),\n on(document, 'toggle keydown', handleClose, QUICK_EVENT),\n onMutation(document, handleAriaAttributes, {\n attributeFilter: [ATTR_TOOLTIP],\n attributes: true,\n childList: true,\n subtree: true,\n }),\n]);\n"],"mappings":"sCAaA,IAAI,EACA,EACA,EAAc,GACd,EAAsD,EACtD,EAAqD,EACzD,MAAM,EAASA,EAAAA,WAAW,EAAI,mBAAmB,KAAK,UAAU,UAAU,CACpE,EAAe,eACf,EAAa,aACb,EAAa,aACb,EAAY,mBACZ,EAAiB,IAAI,EAAW,GAChC,EAAmB,IAAI,EAAa,GACpC,EAAc,oBACd,EAAkB,IAAI,EAAY,GAU3B,EAAqB,GAA4B,CACxD,GAAM,EAAE,aAAc,cACxB,EAAA,KAAK,kDAAmD,EAAG,CAC7D,aAAa,EAAW,CACxB,aAAa,EAAY,CACzB,EAAS,IAAA,GACT,EAAc,GACd,EAAM,GAAM,IAAA,IAGR,MAA6B,CACjC,IAAK,IAAM,KAAM,SAAS,iBAAiB,EAAiB,CAAE,CAC5D,IAAM,EAAOC,EAAAA,UAAU,EAAI,EAAa,CAExC,GAAI,CAAC,EAAM,OACX,GAAI,KAAU,EAAG,aAAa,EAAW,EAAI,EAAG,aAAa,EAAU,EAAG,CACxE,IAAM,EAAUC,EAAAA,KAAK,EAAI,OAAO,GAAK,OAAS,EAAG,aAAa,MAAM,CACpE,EAAA,KAAK,EAAI,EAAc,EAAK,CAC5B,EAAA,KAAK,EAAI,EAAY,EAAU,KAAO,EAAK,CAC3C,EAAA,KAAK,EAAI,EAAW,EAAU,EAAO,KAAK,CACrC,EAAG,QAAQ,kDAAqB,EACnC,EAAA,KAAK,sCAAuC,EAAG,CAInD,IAAM,EAAY,IAAO,GAAU,GAAK,cAAgB,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YAAY,cAAiB,CAC3BC,EAAAA,GAAG,SAAU,uBAAwB,EAAgBC,EAAAA,YAAY,CACjED,EAAAA,GAAG,SAAU,iBAAkB,EAAaC,EAAAA,YAAY,CACxDC,EAAAA,WAAW,SAAU,EAAsB,CACzC,gBAAiB,CAAC,EAAa,CAC/B,WAAY,GACZ,UAAW,GACX,QAAS,GACV,CAAC,CACH,CAAC"}
1
+ {"version":3,"file":"tooltip.cjs","names":["isBrowser","attrOrCSS","attr","tag","onHotReload","on","QUICK_EVENT","onMutation"],"sources":["../../../src/tooltip/tooltip.ts"],"sourcesContent":["import {\n announce,\n attr,\n attrOrCSS,\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 SOURCE: Element | undefined;\nlet IS_HOVERING = false;\nlet HOVER_TIMER: number | ReturnType<typeof setTimeout> = 0;\nlet SKIP_TIMER: number | ReturnType<typeof setTimeout> = 0;\nconst IS_IOS = isBrowser() && /iPad|iPhone|iPod/.test(navigator.userAgent); // Needed to omit DELAY_HOVER since iOS triggers mouseover before click\nconst ATTR_TOOLTIP = 'data-tooltip';\nconst ATTR_COLOR = 'data-color';\nconst ARIA_LABEL = 'aria-label';\nconst ARIA_DESC = 'aria-description';\nconst SELECTOR_COLOR = `[${ATTR_COLOR}]`;\nconst SELECTOR_TOOLTIP = `[${ATTR_TOOLTIP}]`;\nconst ATTR_SCHEME = 'data-color-scheme';\nconst SELECTOR_SCHEME = `[${ATTR_SCHEME}]`;\nconst SELECTOR_INTERACTIVE = 'a,button,input,label,select,textarea,[tabindex]';\nconst DELAY_HOVER = 300;\nconst DELAY_SKIP = 300;\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 clearTimeout(SKIP_TIMER); // Reset when changing source\n clearTimeout(HOVER_TIMER);\n SOURCE = undefined;\n IS_HOVERING = false;\n TIP = el || undefined;\n};\n\nconst handleAriaAttributes = () => {\n for (const el of document.querySelectorAll(SELECTOR_TOOLTIP)) {\n const text = attrOrCSS(el, ATTR_TOOLTIP);\n\n if (!text) return; // Early return if no tooltip text\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.matches(SELECTOR_INTERACTIVE))\n warn('Missing tabindex=\"0\" attribute on: ', el);\n }\n\n // If an existing tooltip has changed programmatically, update tooltip text and announce change\n const isCurrent = el === SOURCE && TIP?.offsetHeight && TIP?.offsetWidth; // Using offsetHeight+Width to check visibility as :popover-open is not well supported by JSDOM\n const isChanged = isCurrent && text && TIP?.textContent !== text; // Only update if mutation is on source element and tooltip is open to avoid unnecessary updates\n if (isCurrent && isChanged) {\n if (TIP) TIP.textContent = text;\n if (document.activeElement === el) announce(text); // Only announce if focus is on the button\n }\n }\n};\n\nconst handleInterest = ({ type, target }: Event) => {\n clearTimeout(HOVER_TIMER);\n\n if (target === TIP) return; // Allow tooltip to be hovered, following https://www.w3.org/TR/WCAG21/#content-on-hover-or-focus\n if (type === 'mouseover' && !IS_HOVERING && !IS_IOS) {\n HOVER_TIMER = setTimeout(handleInterest, DELAY_HOVER, { target }); // Delay mouse showing tooltip if not already shown\n return;\n }\n\n const source = (target as Element)?.closest?.(`[${ATTR_TOOLTIP}]`);\n if (source === SOURCE) return; // No need to update\n if (!source) return hideTooltip(); // If no new anchor, cleanup previous autoUpdate\n if (!TIP) TIP = tag('div', { class: 'ds-tooltip' });\n if (!TIP.isConnected) document.body.appendChild(TIP); // Ensure connected\n\n const color = source.closest(SELECTOR_COLOR); // Match source color of source element\n const scheme = source.closest(SELECTOR_SCHEME); // Match source color-scheme 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 clearTimeout(SKIP_TIMER);\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 TIP.textContent = attr(source, ATTR_TOOLTIP);\n TIP.showPopover();\n TIP.dispatchEvent(new CustomEvent('ds-toggle-source', { detail: source })); // Since showPopover({ source }) is not supported in all browsers yet\n IS_HOVERING = true;\n SOURCE = source;\n};\n\nconst hideTooltip = () => TIP?.isConnected && TIP.popover && TIP.hidePopover(); // Only hide if connected and activated\n\nconst handleClose = (event?: Partial<ToggleEvent & KeyboardEvent>) => {\n if (event?.type === 'keydown')\n return event?.key === 'Escape' && hideTooltip();\n if (!event) IS_HOVERING = false;\n else if (event.target === TIP && event.newState === 'closed') {\n SOURCE = undefined;\n SKIP_TIMER = setTimeout(handleClose, DELAY_SKIP);\n }\n};\n\nonHotReload('tooltip', () => [\n on(document, 'blur focus mouseover', handleInterest, QUICK_EVENT),\n on(document, 'toggle keydown', handleClose, QUICK_EVENT),\n onMutation(document, handleAriaAttributes, {\n attributeFilter: [ATTR_TOOLTIP],\n attributes: true,\n childList: true,\n subtree: true,\n }),\n]);\n"],"mappings":"sCAaA,IAAI,EACA,EACA,EAAc,GACd,EAAsD,EACtD,EAAqD,EACzD,MAAM,EAASA,EAAAA,UAAU,GAAK,mBAAmB,KAAK,UAAU,SAAS,EACnE,EAAe,eACf,EAAa,aACb,EAAa,aACb,EAAY,mBACZ,EAAiB,IAAI,EAAW,GAChC,EAA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Aa,CAAC,EAC7C,EAAI,aAAa,SAAS,KAAK,YAAY,CAAG,EAEnD,IAAM,EAAQ,EAAO,QAAQ,CAAc,EACrC,EAAS,EAAO,QAAQ,CAAe,EACvC,EAAU,IAAU,GAAU,GAAO,SAAS,CAAc,EAElE,aAAa,CAAU,EACvB,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,EAAI,YAAcD,EAAAA,KAAK,EAAQ,CAAY,EAC3C,EAAI,YAAY,EAChB,EAAI,cAAc,IAAI,YAAY,mBAAoB,CAAE,OAAQ,CAAO,CAAC,CAAC,EACzE,EAAc,GACd,EAAS,CACX,EAEM,MAAoB,GAAK,aAAe,EAAI,SAAW,EAAI,YAAY,EAEvE,EAAe,GAAiD,CACpE,GAAI,GAAO,OAAS,UAClB,OAAO,GAAO,MAAQ,UAAY,EAAY,EAC3C,EACI,EAAM,SAAW,GAAO,EAAM,WAAa,WAClD,EAAS,IAAA,GACT,EAAa,WAAW,EAAa,GAAU,GAHrC,EAAc,EAK5B,EAEAE,EAAAA,YAAY,cAAiB,CAC3BC,EAAAA,GAAG,SAAU,uBAAwB,EAAgBC,EAAAA,WAAW,EAChED,EAAAA,GAAG,SAAU,iBAAkB,EAAaC,EAAAA,WAAW,EACvDC,EAAAA,WAAW,SAAU,EAAsB,CACzC,gBAAiB,CAAC,CAAY,EAC9B,WAAY,GACZ,UAAW,GACX,QAAS,EACX,CAAC,CACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","names":[],"sources":["../../../src/utils/utils.ts"],"sourcesContent":["export const QUICK_EVENT = { passive: true, capture: true };\n\n// Using function instead of constant to support evnironments where DOM can be unloaded (like Vitest with jsdom)\nexport const isBrowser = () =>\n typeof window !== 'undefined' && typeof document !== 'undefined';\n\nexport const isWindows = () =>\n isBrowser() &&\n // @ts-expect-error Typescript has not implemented userAgentData yet https://stackoverflow.com/a/71392474\n /^Win/i.test(navigator.userAgentData?.platform || navigator.platform);\n\n// Make sure we have a HTMLElement to extend (for server side rendering)\nexport const DSElement =\n typeof HTMLElement === 'undefined'\n ? (class {} as typeof HTMLElement)\n : HTMLElement;\n\nexport function debounce<T extends unknown[]>(\n callback: (...args: T) => void,\n delay: number,\n) {\n let timer: ReturnType<typeof setTimeout>;\n\n return function (this: unknown, ...args: T) {\n clearTimeout(timer);\n timer = setTimeout(() => callback.apply(this, args), delay);\n };\n}\n\n/**\n * warn\n * @description Utility to console.log, but can be silenced in production with window.dsWarnings = false;\n */\ndeclare global {\n interface Window {\n dsWarnings?: boolean;\n }\n}\nexport const warn = (\n message: string,\n ...args: Parameters<typeof console.log> // Using console.log, not console.warn, to prevent stopping test runners such as Jest\n) =>\n !isBrowser() ||\n window.dsWarnings === false ||\n console.log(`\\x1B[1mDesignsystemet:\\x1B[m ${message}`, ...args);\n\n/**\n * attr\n * @description Utility to quickly get, set and remove attributes\n * @param el The Element to read/write attributes from\n * @param name The attribute name to get, set or remove, or a object to set multiple attributes\n * @param value A valid attribute value or null to remove attribute\n */\nexport const attr = (\n el: Element,\n name: string,\n value?: string | null,\n): string | null => {\n if (value === undefined) return el.getAttribute(name) ?? null; // Fallback to null only if el is undefined\n if (value === null) el.removeAttribute(name);\n else if (el.getAttribute(name) !== value) el.setAttribute(name, value);\n return null;\n};\n\n/**\n * getCSSProp\n * @description Retrieves and CSS property value and trims it\n * @param el The Element to read attributes/CSS from\n * @param name Attribute or CSS property to get\n * @return string CSS property value\n */\nexport const getCSSProp = (el: Element, prop: string) =>\n getComputedStyle(el).getPropertyValue(prop).trim();\n\nconst STRIP_QUOTES = /^[\"']|[\"']$/g; // Matches surrounding single or double quotes\n/**\n * attrOrCSS\n * @description Retrieves and updates attribute based on attribute or CSS property value\n * @param el The Element to read attributes/CSS from\n * @param name Attribute or CSS property to get\n * @return string attribute or CSS property value\n */\nexport const attrOrCSS = (el: Element, name: string) => {\n let value = attr(el, name);\n if (!value)\n value = getCSSProp(el, `--_ds-${name}`).replace(STRIP_QUOTES, '').trim();\n if (!value) warn(`Missing ${name} on:`, el);\n return value || null;\n};\n\n/**\n * on\n * @param el The Element to use as EventTarget\n * @param types A space separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const on = (\n el: Node | Window | ShadowRoot,\n ...rest: Parameters<typeof Element.prototype.addEventListener>\n): (() => void) => {\n const [types, ...options] = rest;\n for (const type of types.split(' ')) el.addEventListener(type, ...options);\n return () => off(el, ...rest);\n};\n\n/**\n * off\n * @param el The Element to use as EventTarget\n * @param types A space separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const off = (\n el: Node | Window | ShadowRoot,\n ...rest: Parameters<typeof Element.prototype.removeEventListener>\n): void => {\n const [types, ...options] = rest;\n for (const type of types.split(' ')) el.removeEventListener(type, ...options);\n};\n\n// Used to store cleanup functions for hot-reloading\ndeclare global {\n interface Window {\n _dsHotReloadCleanup?: Map<string, Array<() => void>>;\n }\n}\n\n/**\n * onHotReload\n * @description Runs a callback when window is loaded in browser, and ensures cleanup when hot-reloading\n * @param key The key to identify setup and corresponding cleanup\n * @param callback The callback to run when the page is ready\n */\nexport const onHotReload = (key: string, setup: () => Array<() => void>) => {\n if (!isBrowser()) return; // Skip if not in modern browser environment, but on each call as Vitest might have unloaded jsdom between tests\n if (!window._dsHotReloadCleanup) window._dsHotReloadCleanup = new Map(); // Hot reload cleanup support supporting all build tools\n\n window._dsHotReloadCleanup?.get(key)?.map((cleanup) => cleanup()); // Run previous cleanup\n window._dsHotReloadCleanup?.set(key, setup()); // Store new cleanup\n};\n\n/**\n * MutationObserver wrapper with automatic cleanup\n * @return new MutaionObserver\n */\nexport const onMutation = <T extends Node>(\n el: T,\n callback: (el: T, records?: MutationRecord[]) => void,\n options: MutationObserverInit,\n) => {\n const cleanup = () => observer.disconnect();\n const observer = new MutationObserver((records) => {\n if (!isBrowser() || !el.isConnected) return cleanup(); // Stop observing if element is removed from DOM or document is removed by jdsom tests\n callback(el, records);\n });\n\n callback(el); // Initial is run instantly to make test markup predictable\n observer.observe(el, options);\n return cleanup;\n};\n\n/**\n * tag\n * @description creates element and assigns properties\n * @param tagName The tagname of element to create\n * @param attrs Optional attributes to add to the element\n * @param text Optional text content to add to the element\n * @return HTMLElement with props\n */\nexport const tag = <TagName extends keyof HTMLElementTagNameMap>(\n tagName: TagName,\n attrs?: Record<string, string | null> | null,\n): HTMLElementTagNameMap[TagName] => {\n const el = document.createElement(tagName);\n if (attrs) for (const [key, val] of Object.entries(attrs)) attr(el, key, val);\n return el;\n};\n\n/**\n * customElements.define\n * @description Defines a customElement if running in browser and if not already registered\n * Scoped/named \"customElements.define\" so @custom-elements-manifest/analyzer can find tag names\n */\nexport const customElements = {\n define: (name: string, instance: CustomElementConstructor) =>\n !isBrowser() ||\n window.customElements.get(name) ||\n window.customElements.define(name, instance),\n};\n\n/**\n * useId\n * @return A generated unique ID\n */\ndeclare global {\n interface Window {\n dsUseId?: number; // Use a global counter to ensure this works even when loading designsystemet multiple times\n }\n}\nlet id = 0;\nexport function useId(el?: Element | null) {\n if (!isBrowser()) return `:ds:${++id}`; // Emulate browser environment if window not available\n if (!window.dsUseId) window.dsUseId = 0; // Make sure we have a global to support multiple instances of designsystemet in same page\n if (el && !el.id) el.id = `:ds:${++window.dsUseId}`;\n return el?.id || '';\n}\n\n/**\n * @description Based off speak function from [U-elements](https://github.com/u-elements/u-elements/blob/main/packages/utils.ts#L210)\n * @param text The text to announce\n */\nlet LIVE_EL: HTMLElement | undefined;\nlet LIVE_FIX = 0;\nlet LIVE_CLEAR: ReturnType<typeof setTimeout> | number = 0;\nexport const announce = (text: string) => {\n clearTimeout(LIVE_CLEAR);\n if (LIVE_EL) LIVE_EL.textContent = `${text}${LIVE_FIX++ % 2 ? '\\u00A0' : ''}`; // Non-breaking space to ensure screen reader announces\n if (text) LIVE_CLEAR = setTimeout(announce, 2000, ''); // Clear prevent old announcements being found by screen readers, with 2 seconds brace period to avoid cutting of Android Talkback\n};\n\n// Mount live region on first focus so its ready to be used\nconst announceMount = () => {\n if (document.readyState !== 'complete') return; // Ensure page is loaded trying to avoid issues with React hydration\n if (!LIVE_EL) {\n LIVE_EL = tag('div', { 'aria-live': 'assertive' });\n LIVE_EL.style.overflow = 'hidden'; // Settings styles individually to prevent issues with CSP\n LIVE_EL.style.position = 'fixed';\n LIVE_EL.style.whiteSpace = 'nowrap';\n LIVE_EL.style.width = '1px';\n }\n if (!LIVE_EL.isConnected) document.body.appendChild(LIVE_EL);\n};\nonHotReload('announce', () => [\n on(document, 'focus mouseover', announceMount, QUICK_EVENT),\n]);\n"],"mappings":"AAAA,MAAa,EAAc,CAAE,QAAS,GAAM,QAAS,GAAM,CAG9C,MACX,OAAO,OAAW,KAAe,OAAO,SAAa,IAE1C,MACX,GAAW,EAEX,QAAQ,KAAK,UAAU,eAAe,UAAY,UAAU,SAAS,CAG1D,EACX,OAAO,YAAgB,IAClB,KAAM,GACP,YAEN,SAAgB,EACd,EACA,EACA,CACA,IAAI,EAEJ,OAAO,SAAyB,GAAG,EAAS,CAC1C,aAAa,EAAM,CACnB,EAAQ,eAAiB,EAAS,MAAM,KAAM,EAAK,CAAE,EAAM,EAa/D,MAAa,GACX,EACA,GAAG,IAEH,CAAC,GAAW,EACZ,OAAO,aAAe,IACtB,QAAQ,IAAI,gCAAgC,IAAW,GAAG,EAAK,CASpD,GACX,EACA,EACA,IAEI,IAAU,IAAA,GAAkB,EAAG,aAAa,EAAK,EAAI,MACrD,IAAU,KAAM,EAAG,gBAAgB,EAAK,CACnC,EAAG,aAAa,EAAK,GAAK,GAAO,EAAG,aAAa,EAAM,EAAM,CAC/D,MAUI,GAAc,EAAa,IACtC,iBAAiB,EAAG,CAAC,iBAAiB,EAAK,CAAC,MAAM,CAE9C,EAAe,eAQR,GAAa,EAAa,IAAiB,CACtD,IAAI,EAAQ,EAAK,EAAI,EAAK,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EAAqB,CAIzC,OAHK,GAAW,EACX,OAAO,UAAS,OAAO,QAAU,GAClC,GAAM,CAAC,EAAG,KAAI,EAAG,GAAK,OAAO,EAAE,OAAO,WACnC,GAAI,IAAM,IAHQ,OAAO,EAAE,IAUpC,IAAI,EACA,EAAW,EACX,EAAqD,EACzD,MAAa,EAAY,GAAiB,CACxC,aAAa,EAAW,CACpB,IAAS,EAAQ,YAAc,GAAG,IAAO,IAAa,EAAI,OAAW,MACrE,IAAM,EAAa,WAAW,EAAU,IAAM,GAAG,GAIjD,MAAsB,CACtB,SAAS,aAAe,aACvB,IACH,EAAU,EAAI,MAAO,CAAE,YAAa,YAAa,CAAC,CAClD,EAAQ,MAAM,SAAW,SACzB,EAAQ,MAAM,SAAW,QACzB,EAAQ,MAAM,WAAa,SAC3B,EAAQ,MAAM,MAAQ,OAEnB,EAAQ,aAAa,SAAS,KAAK,YAAY,EAAQ,GAE9D,EAAY,eAAkB,CAC5B,EAAG,SAAU,kBAAmB,EAAe,EAAY,CAC5D,CAAC"}
1
+ {"version":3,"file":"utils.cjs","names":[],"sources":["../../../src/utils/utils.ts"],"sourcesContent":["export const QUICK_EVENT = { passive: true, capture: true };\n\n// Using function instead of constant to support evnironments where DOM can be unloaded (like Vitest with jsdom)\nexport const isBrowser = () =>\n typeof window !== 'undefined' && typeof document !== 'undefined';\n\nexport const isWindows = () =>\n isBrowser() &&\n // @ts-expect-error Typescript has not implemented userAgentData yet https://stackoverflow.com/a/71392474\n /^Win/i.test(navigator.userAgentData?.platform || navigator.platform);\n\n// Make sure we have a HTMLElement to extend (for server side rendering)\nexport const DSElement =\n typeof HTMLElement === 'undefined'\n ? (class {} as typeof HTMLElement)\n : HTMLElement;\n\nexport function debounce<T extends unknown[]>(\n callback: (...args: T) => void,\n delay: number,\n) {\n let timer: ReturnType<typeof setTimeout>;\n\n return function (this: unknown, ...args: T) {\n clearTimeout(timer);\n timer = setTimeout(() => callback.apply(this, args), delay);\n };\n}\n\n/**\n * warn\n * @description Utility to console.log, but can be silenced in production with window.dsWarnings = false;\n */\ndeclare global {\n interface Window {\n dsWarnings?: boolean;\n }\n}\nexport const warn = (\n message: string,\n ...args: Parameters<typeof console.log> // Using console.log, not console.warn, to prevent stopping test runners such as Jest\n) =>\n !isBrowser() ||\n window.dsWarnings === false ||\n console.log(`\\x1B[1mDesignsystemet:\\x1B[m ${message}`, ...args);\n\n/**\n * attr\n * @description Utility to quickly get, set and remove attributes\n * @param el The Element to read/write attributes from\n * @param name The attribute name to get, set or remove, or a object to set multiple attributes\n * @param value A valid attribute value or null to remove attribute\n */\nexport const attr = (\n el: Element,\n name: string,\n value?: string | null,\n): string | null => {\n if (value === undefined) return el.getAttribute(name) ?? null; // Fallback to null only if el is undefined\n if (value === null) el.removeAttribute(name);\n else if (el.getAttribute(name) !== value) el.setAttribute(name, value);\n return null;\n};\n\n/**\n * getCSSProp\n * @description Retrieves and CSS property value and trims it\n * @param el The Element to read attributes/CSS from\n * @param name Attribute or CSS property to get\n * @return string CSS property value\n */\nexport const getCSSProp = (el: Element, prop: string) =>\n getComputedStyle(el).getPropertyValue(prop).trim();\n\nconst STRIP_QUOTES = /^[\"']|[\"']$/g; // Matches surrounding single or double quotes\n/**\n * attrOrCSS\n * @description Retrieves and updates attribute based on attribute or CSS property value\n * @param el The Element to read attributes/CSS from\n * @param name Attribute or CSS property to get\n * @return string attribute or CSS property value\n */\nexport const attrOrCSS = (el: Element, name: string) => {\n let value = attr(el, name);\n if (!value)\n value = getCSSProp(el, `--_ds-${name}`).replace(STRIP_QUOTES, '').trim();\n if (!value) warn(`Missing ${name} on:`, el);\n return value || null;\n};\n\n/**\n * on\n * @param el The Element to use as EventTarget\n * @param types A space separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const on = (\n el: Node | Window | ShadowRoot,\n ...rest: Parameters<typeof Element.prototype.addEventListener>\n): (() => void) => {\n const [types, ...options] = rest;\n for (const type of types.split(' ')) el.addEventListener(type, ...options);\n return () => off(el, ...rest);\n};\n\n/**\n * off\n * @param el The Element to use as EventTarget\n * @param types A space separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const off = (\n el: Node | Window | ShadowRoot,\n ...rest: Parameters<typeof Element.prototype.removeEventListener>\n): void => {\n const [types, ...options] = rest;\n for (const type of types.split(' ')) el.removeEventListener(type, ...options);\n};\n\n// Used to store cleanup functions for hot-reloading\ndeclare global {\n interface Window {\n _dsHotReloadCleanup?: Map<string, Array<() => void>>;\n }\n}\n\n/**\n * onHotReload\n * @description Runs a callback when window is loaded in browser, and ensures cleanup when hot-reloading\n * @param key The key to identify setup and corresponding cleanup\n * @param callback The callback to run when the page is ready\n */\nexport const onHotReload = (key: string, setup: () => Array<() => void>) => {\n if (!isBrowser()) return; // Skip if not in modern browser environment, but on each call as Vitest might have unloaded jsdom between tests\n if (!window._dsHotReloadCleanup) window._dsHotReloadCleanup = new Map(); // Hot reload cleanup support supporting all build tools\n\n window._dsHotReloadCleanup?.get(key)?.map((cleanup) => cleanup()); // Run previous cleanup\n window._dsHotReloadCleanup?.set(key, setup()); // Store new cleanup\n};\n\n/**\n * MutationObserver wrapper with automatic cleanup\n * @return new MutaionObserver\n */\nexport const onMutation = <T extends Node>(\n el: T,\n callback: (el: T, records?: MutationRecord[]) => void,\n options: MutationObserverInit,\n) => {\n const cleanup = () => observer.disconnect();\n const observer = new MutationObserver((records) => {\n if (!isBrowser() || !el.isConnected) return cleanup(); // Stop observing if element is removed from DOM or document is removed by jdsom tests\n callback(el, records);\n });\n\n callback(el); // Initial is run instantly to make test markup predictable\n observer.observe(el, options);\n return cleanup;\n};\n\n/**\n * tag\n * @description creates element and assigns properties\n * @param tagName The tagname of element to create\n * @param attrs Optional attributes to add to the element\n * @param text Optional text content to add to the element\n * @return HTMLElement with props\n */\nexport const tag = <TagName extends keyof HTMLElementTagNameMap>(\n tagName: TagName,\n attrs?: Record<string, string | null> | null,\n): HTMLElementTagNameMap[TagName] => {\n const el = document.createElement(tagName);\n if (attrs) for (const [key, val] of Object.entries(attrs)) attr(el, key, val);\n return el;\n};\n\n/**\n * customElements.define\n * @description Defines a customElement if running in browser and if not already registered\n * Scoped/named \"customElements.define\" so @custom-elements-manifest/analyzer can find tag names\n */\nexport const customElements = {\n define: (name: string, instance: CustomElementConstructor) =>\n !isBrowser() ||\n window.customElements.get(name) ||\n window.customElements.define(name, instance),\n};\n\n/**\n * useId\n * @return A generated unique ID\n */\ndeclare global {\n interface Window {\n dsUseId?: number; // Use a global counter to ensure this works even when loading designsystemet multiple times\n }\n}\nlet id = 0;\nexport function useId(el?: Element | null) {\n if (!isBrowser()) return `:ds:${++id}`; // Emulate browser environment if window not available\n if (!window.dsUseId) window.dsUseId = 0; // Make sure we have a global to support multiple instances of designsystemet in same page\n if (el && !el.id) el.id = `:ds:${++window.dsUseId}`;\n return el?.id || '';\n}\n\n/**\n * @description Based off speak function from [U-elements](https://github.com/u-elements/u-elements/blob/main/packages/utils.ts#L210)\n * @param text The text to announce\n */\nlet LIVE_EL: HTMLElement | undefined;\nlet LIVE_FIX = 0;\nlet LIVE_CLEAR: ReturnType<typeof setTimeout> | number = 0;\nexport const announce = (text: string) => {\n clearTimeout(LIVE_CLEAR);\n if (LIVE_EL) LIVE_EL.textContent = `${text}${LIVE_FIX++ % 2 ? '\\u00A0' : ''}`; // Non-breaking space to ensure screen reader announces\n if (text) LIVE_CLEAR = setTimeout(announce, 2000, ''); // Clear prevent old announcements being found by screen readers, with 2 seconds brace period to avoid cutting of Android Talkback\n};\n\n// Mount live region on first focus so its ready to be used\nconst announceMount = () => {\n if (document.readyState !== 'complete') return; // Ensure page is loaded trying to avoid issues with React hydration\n if (!LIVE_EL) {\n LIVE_EL = tag('div', { 'aria-live': 'assertive' });\n LIVE_EL.style.overflow = 'hidden'; // Settings styles individually to prevent issues with CSP\n LIVE_EL.style.position = 'fixed';\n LIVE_EL.style.whiteSpace = 'nowrap';\n LIVE_EL.style.width = '1px';\n }\n if (!LIVE_EL.isConnected) document.body.appendChild(LIVE_EL);\n};\nonH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