@digdir/designsystemet-web 1.16.0 → 1.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_vendors/@oddbird/popover-polyfill/dist/popover-fn.cjs.map +1 -1
- package/dist/cjs/_vendors/invokers-polyfill/invoker.cjs.map +1 -1
- package/dist/cjs/breadcrumbs/breadcrumbs.cjs +1 -1
- package/dist/cjs/clickdelegatefor/clickdelegatefor.cjs +1 -1
- package/dist/cjs/clickdelegatefor/clickdelegatefor.cjs.map +1 -1
- package/dist/cjs/details/details.cjs +1 -1
- package/dist/cjs/dialog/dialog.cjs +1 -1
- package/dist/cjs/dialog/dialog.cjs.map +1 -1
- package/dist/cjs/error-summary/error-summary.cjs +1 -1
- package/dist/cjs/error-summary/error-summary.cjs.map +1 -1
- package/dist/cjs/field/field.cjs +1 -1
- package/dist/cjs/field/field.cjs.map +1 -1
- package/dist/cjs/fieldset/fieldset.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/invokers/invokers.cjs +1 -1
- package/dist/cjs/pagination/pagination.cjs +1 -1
- package/dist/cjs/pagination/pagination.cjs.map +1 -1
- package/dist/cjs/popover/popover.cjs +1 -1
- package/dist/cjs/popover/popover.cjs.map +1 -1
- package/dist/cjs/readonly/readonly.cjs +1 -1
- package/dist/cjs/readonly/readonly.cjs.map +1 -1
- package/dist/cjs/suggestion/suggestion.cjs +1 -1
- package/dist/cjs/suggestion/suggestion.cjs.map +1 -1
- package/dist/cjs/tabs/tabs.cjs +1 -1
- package/dist/cjs/toggle-group/toggle-group.cjs +1 -1
- package/dist/cjs/toggle-group/toggle-group.cjs.map +1 -1
- package/dist/cjs/tooltip/tooltip.cjs +1 -1
- package/dist/cjs/utils/utils.cjs.map +1 -1
- package/dist/custom-elements.json +2 -2
- package/dist/esm/_vendors/@oddbird/popover-polyfill/dist/popover-fn.js.map +1 -1
- package/dist/esm/_vendors/invokers-polyfill/invoker.js.map +1 -1
- package/dist/esm/clickdelegatefor/clickdelegatefor.js.map +1 -1
- package/dist/esm/dialog/dialog.js.map +1 -1
- package/dist/esm/error-summary/error-summary.js.map +1 -1
- package/dist/esm/field/field.js.map +1 -1
- package/dist/esm/pagination/pagination.js.map +1 -1
- package/dist/esm/popover/popover.js.map +1 -1
- package/dist/esm/readonly/readonly.js.map +1 -1
- package/dist/esm/toggle-group/toggle-group.js.map +1 -1
- package/dist/esm/utils/utils.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.js","names":[],"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(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":"qHAeA,MAAM,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,
|
|
1
|
+
{"version":3,"file":"pagination.js","names":[],"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(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":"qHAeA,MAAM,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,CAAC,CAAC,KAAK,EAAM,KAAW,CAC1D,QAAS,IAAS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AK,EAAM,WAAY,EAAO,KAAO,IAAI,EACrC,aAAgB,mBAAmB,EAAK,EAAM,QAAS,GAAG,GAAM,EAChE,GAAQ,aAAgB,mBAC1B,EAAK,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,EAEA,EAAe,OAAO,gBAAiB,CAAmB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover.js","names":[],"sources":["../../../src/popover/popover.ts"],"sourcesContent":["import type { ComputePositionConfig, MiddlewareState } from '@floating-ui/dom';\nimport {\n autoUpdate,\n computePosition,\n flip,\n limitShift,\n offset,\n shift,\n size,\n} from '@floating-ui/dom';\nimport {\n isSupported,\n apply as polyfillPopover,\n} from '@oddbird/popover-polyfill/fn';\nimport {\n attr,\n getCSSProp,\n isBrowser,\n on,\n onHotReload,\n QUICK_EVENT,\n} from '../utils/utils';\n\nif (isBrowser() && !isSupported()) polyfillPopover(); // Ensure popover polyfill is loaded in browser environment only\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\n // Use scroll-margin-bottom to measure computed arrow-size property as this does\n // not affect layout or position, makes the browser calculate the pixel value instead\n // of returning the calc() (as it would if reading the --_ds-floating-arrow-size directly)\n // and makes it possible to read the value even if ::before is not used to draw the arrow.\n el.style.scrollMarginBottom = `var(--_ds-floating-arrow-size)`;\n\n const padding = 10;\n const overscroll = getCSSProp(el, '--_ds-floating-overscroll');\n const placement = attr(el, ATTR_PLACE) || attr(source, ATTR_PLACE) || float;\n const auto = attr(el, ATTR_AUTO) || attr(source, ATTR_AUTO);\n const arrowSize = parseFloat(getCSSProp(el, 'scroll-margin-bottom')) || 0;\n const shiftProp = placement.match(/left|right/gi) ? 'Height' : 'Width';\n const shiftLimit = source[`offset${shiftProp}`] / 2 + arrowSize;\n\n if (placement === 'none') return; // No need to position\n\n const options = {\n strategy: 'absolute',\n placement,\n middleware: [\n offset(arrowSize),\n shift({\n padding,\n limiter: limitShift({ offset: { mainAxis: shiftLimit } }), // Prevent from shifing away from source\n }),\n arrowPseudo(),\n ...(auto !== 'false' ? [flip({ padding, crossAxis: false })] : []),\n ...(overscroll\n ? [\n size({\n apply({ availableHeight }) {\n if (overscroll === 'fit')\n el.style.width = `${source.offsetWidth}px`; // Use offsetWidth to include padding, matching the width of the source element\n el.style.maxHeight = `${Math.max(50, availableHeight - padding * 2)}px`;\n },\n }),\n ]\n : []),\n ],\n } as ComputePositionConfig;\n const unfloat = autoUpdate(source, el, async () => {\n if (!source?.isConnected) return POPOVERS.get(el)?.(); // Cleanup 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":"kVAuBI,EAAU,GAAK,CAAC,EAAY,GAAG,EAAgB,EAQnD,MAAM,EAAa,iBACb,EAAY,qBACZ,EAAW,IAAI,IAIrB,SAAS,EACP,EAIA,CACA,GAAI,CAAE,WAAU,WAAU,OAAQ,EAAI,SAAS,EAAM,QAAW,EAE1D,EADY,aAAc,aAAe,EAAK,EAAI,SAAS,IAAM,MAC5C,EAAW,EAAI,gBAAgB,EAE1D,GAAI,CAAC,EAAO,OACZ,GAAI,IAAa,SAAU,OAAO,EAAS,IAAI,CAAE,
|
|
1
|
+
{"version":3,"file":"popover.js","names":[],"sources":["../../../src/popover/popover.ts"],"sourcesContent":["import type { ComputePositionConfig, MiddlewareState } from '@floating-ui/dom';\nimport {\n autoUpdate,\n computePosition,\n flip,\n limitShift,\n offset,\n shift,\n size,\n} from '@floating-ui/dom';\nimport {\n isSupported,\n apply as polyfillPopover,\n} from '@oddbird/popover-polyfill/fn';\nimport {\n attr,\n getCSSProp,\n isBrowser,\n on,\n onHotReload,\n QUICK_EVENT,\n} from '../utils/utils';\n\nif (isBrowser() && !isSupported()) polyfillPopover(); // Ensure popover polyfill is loaded in browser environment only\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\n // Use scroll-margin-bottom to measure computed arrow-size property as this does\n // not affect layout or position, makes the browser calculate the pixel value instead\n // of returning the calc() (as it would if reading the --_ds-floating-arrow-size directly)\n // and makes it possible to read the value even if ::before is not used to draw the arrow.\n el.style.scrollMarginBottom = `var(--_ds-floating-arrow-size)`;\n\n const padding = 10;\n const overscroll = getCSSProp(el, '--_ds-floating-overscroll');\n const placement = attr(el, ATTR_PLACE) || attr(source, ATTR_PLACE) || float;\n const auto = attr(el, ATTR_AUTO) || attr(source, ATTR_AUTO);\n const arrowSize = parseFloat(getCSSProp(el, 'scroll-margin-bottom')) || 0;\n const shiftProp = placement.match(/left|right/gi) ? 'Height' : 'Width';\n const shiftLimit = source[`offset${shiftProp}`] / 2 + arrowSize;\n\n if (placement === 'none') return; // No need to position\n\n const options = {\n strategy: 'absolute',\n placement,\n middleware: [\n offset(arrowSize),\n shift({\n padding,\n limiter: limitShift({ offset: { mainAxis: shiftLimit } }), // Prevent from shifing away from source\n }),\n arrowPseudo(),\n ...(auto !== 'false' ? [flip({ padding, crossAxis: false })] : []),\n ...(overscroll\n ? [\n size({\n apply({ availableHeight }) {\n if (overscroll === 'fit')\n el.style.width = `${source.offsetWidth}px`; // Use offsetWidth to include padding, matching the width of the source element\n el.style.maxHeight = `${Math.max(50, availableHeight - padding * 2)}px`;\n },\n }),\n ]\n : []),\n ],\n } as ComputePositionConfig;\n const unfloat = autoUpdate(source, el, async () => {\n if (!source?.isConnected) return POPOVERS.get(el)?.(); // Cleanup 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":"kVAuBI,EAAU,GAAK,CAAC,EAAY,GAAG,EAAgB,EAQnD,MAAM,EAAa,iBACb,EAAY,qBACZ,EAAW,IAAI,IAIrB,SAAS,EACP,EAIA,CACA,GAAI,CAAE,WAAU,WAAU,OAAQ,EAAI,SAAS,EAAM,QAAW,EAE1D,EADY,aAAc,aAAe,EAAK,EAAI,SAAS,IAAM,MAC5C,EAAW,EAAI,gBAAgB,EAE1D,GAAI,CAAC,EAAO,OACZ,GAAI,IAAa,SAAU,OAAO,EAAS,IAAI,CAAE,CAAC,GAAG,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,GAAO,GAAY,IAAa,EAAW,OAMrE,EAAG,MAAM,mBAAqB,iCAE9B,IACM,EAAa,EAAW,EAAI,2BAA2B,EACvD,EAAY,EAAK,EAAI,CAAU,GAAK,EAAK,EAAQ,CAAU,GAAK,EAChE,EAAO,EAAK,EAAI,CAAS,GAAK,EAAK,EAAQ,CAAS,EACpD,EAAY,WAAW,EAAW,EAAI,sBAAsB,CAAC,GAAK,EAClE,EAAY,EAAU,MAAM,cAAc,EAAI,SAAW,QACzD,EAAa,EAAO,SAAS,KAAe,EAAI,E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,EAAI,EAAO,EAAI,EAAK,CAAC,EAAE,IACxD,EAAI,GAAG,KAAK,MAAM,EAAO,OAAS,EAAI,EAAO,EAAI,EAAK,CAAC,EAAE,IAK/D,OAHA,EAAO,MAAM,YAAY,yBAA0B,CAAC,EACpD,EAAO,MAAM,YAAY,yBAA0B,CAAC,EACpD,EAAK,EAAQ,gBAAiB,EAAK,SAAS,EACrC,CACT,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readonly.js","names":[],"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":"kEAEA,MAAM,EAAc,IACjB,aAAc,mBAAqB,aAAc,oBACjD,EAAG,aAAa,UAAU,GAAK,EAAK,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,GAAW,EAAK,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,
|
|
1
|
+
{"version":3,"file":"readonly.js","names":[],"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":"kEAEA,MAAM,EAAc,IACjB,aAAc,mBAAqB,aAAc,oBACjD,EAAG,aAAa,UAAU,GAAK,EAAK,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,GAAW,EAAK,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,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAI,GAC3C,EAAI,OAAO,EAAkB,MAAM,CACjD,CACF,CACF,EAEM,EAAe,GAAa,CAChC,IAAM,EAAS,EAAE,QAAoB,UAAU,OAAO,CAAC,EAAE,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,EAEA,EAAY,eAAkB,CAC5B,EAAG,SAAU,UAAW,CAAa,EACrC,EAAG,SAAU,QAAS,CAAW,EACjC,EAAG,SAAU,YAAa,CAAe,CAC3C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-group.js","names":[],"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":"iGAEA,MACM,EAAa,aACb,EAAmB,oBACnB,EAAuB,IAAI,EAAiB,GAE5C,MAA6B,CACjC,IAAK,IAAM,KAAS,SAAS,iBAAiB,CAAoB,EAChE,EAAK,EAAO,aAAc,EAAU,EAAO,CAAgB,CAAC,CAChE,EAEM,EAAiB,GAAkC,CACvD,GAAM,CAAE,MAAK,OAAQ,GAAO,EACtB,EACJ,aAAc,kBAAoB,EAAG,QAAQ,CAAoB,EAE9D,OACD,CAAC,EAAK,EAAO,CAAU,GAAK,CAAC,EAAK,EAAO,iBAAe,GAC1D,EAAK,EAAO,EAAY,EAAU,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,
|
|
1
|
+
{"version":3,"file":"toggle-group.js","names":[],"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":"iGAEA,MACM,EAAa,aACb,EAAmB,oBACnB,EAAuB,IAAI,EAAiB,GAE5C,MAA6B,CACjC,IAAK,IAAM,KAAS,SAAS,iBAAiB,CAAoB,EAChE,EAAK,EAAO,aAAc,EAAU,EAAO,CAAgB,CAAC,CAChE,EAEM,EAAiB,GAAkC,CACvD,GAAM,CAAE,MAAK,OAAQ,GAAO,EACtB,EACJ,aAAc,kBAAoB,EAAG,QAAQ,CAAoB,EAE9D,OACD,CAAC,EAAK,EAAO,CAAU,GAAK,CAAC,EAAK,EAAO,iBAAe,GAC1D,EAAK,EAAO,EAAY,EAAU,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,EAAU,EAAE,SAAU,CAChC,EAAO,EAAU,EAAE,MAAM,EACzB,KACF,CAEJ,CACF,EAEA,EAAY,mBAAsB,CAChC,EAAG,SAAU,UAAW,CAAa,EACrC,EAAW,SAAU,EAAsB,CACzC,gBAAiB,CAAC,CAAgB,EAClC,WAAY,GACZ,UAAW,GACX,QAAS,EACX,CAAC,CACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","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,EAAK,EAG7C,MACX,OAAO,OAAW,KAAe,OAAO,SAAa,IAE1C,MACX,EAAU,GAEV,QAAQ,KAAK,UAAU,eAA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,aAAa,SAAS,KAAK,YAAY,CAAO,EAC7D,EACA,EAAY,eAAkB,CAC5B,EAAG,SAAU,kBAAmB,EAAe,CAAW,CAC5D,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.js","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,EAAK,EAG7C,MACX,OAAO,OAAW,KAAe,OAAO,SAAa,IAE1C,MACX,EAAU,GAEV,QAAQ,KAAK,UAAU,eAAe,UAAY,UAAU,QAAQ,EAGzD,EACX,OAAO,YAAgB,IAClB,KAAM,CAAC,EACR,YAEN,SAAgB,EACd,EACA,EACA,CACA,IAAI,EAEJ,OAAO,SAAyB,GAAG,EAAS,CAC1C,aAAa,CAAK,EAClB,EAAQ,eAAiB,EAAS,MAAM,KAAM,CAAI,EAAG,CAAK,CAC5D,CACF,CAWA,MAAa,GACX,EACA,GAAG,IAEH,CAAC,EAAU,GACX,OAAO,aAAe,IACtB,QAAQ,IAAI,gCAAgC,I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,EAID,OAFA,EAAS,CAAE,EACX,EAAS,QAAQ,EAAI,CAAO,EACrB,CACT,EAUa,GACX,EACA,IACmC,CACnC,IAAM,EAAK,SAAS,cAAc,CAAO,EACzC,GAAI,EAAO,IAAK,GAAM,CAAC,EAAK,KAAQ,OAAO,QAAQ,CAAK,EAAG,EAAK,EAAI,EAAK,CAAG,EAC5E,OAAO,CACT,EAOa,EAAiB,CAC5B,QAAS,EAAc,IACrB,CAAC,EAAU,GACX,OAAO,eAAe,IAAI,CAAI,GAC9B,OAAO,eAAe,OAAO,EAAM,CAAQ,CAC/C,EAWA,IAAI,EAAK,EACT,SAAgB,EAAM,EAAqB,CAIzC,OAHK,EAAU,GACV,OAAO,UAAS,OAAO,QAAU,GAClC,GAAM,CAAC,EAAG,KAAI,EAAG,GAAK,OAAO,EAAE,OAAO,WACnC,GAAI,IAAM,IAHQ,OAAO,EAAE,GAIpC,CAMA,IAAI,EACA,EAAW,EACX,EAAqD,EACzD,MAAa,EAAY,GAAiB,CACxC,aAAa,CAAU,EACnB,IAAS,EAAQ,YAAc,GAAG,IAAO,IAAa,EAAI,OAAW,MACrE,IAAM,EAAa,WAAW,EAAU,IAAM,EAAE,EACtD,EAGM,MAAsB,CACtB,SAAS,aAAe,aACvB,IACH,EAAU,EAAI,MAAO,CAAE,YAAa,WAAY,CAAC,EACjD,EAAQ,MAAM,SAAW,SACzB,EAAQ,MAAM,SAAW,QACzB,EAAQ,MAAM,WAAa,SAC3B,EAAQ,MAAM,MAAQ,OAEnB,EAAQ,aAAa,SAAS,KAAK,YAAY,CAAO,EAC7D,EACA,EAAY,eAAkB,CAC5B,EAAG,SAAU,kBAAmB,EAAe,CAAW,CAC5D,CAAC"}
|
package/dist/umd/index.js
CHANGED
|
@@ -63,7 +63,7 @@ ${e?`}`:``}
|
|
|
63
63
|
`}var In=null;function Ln(e){let t=Fn();if(In===null)try{In=new CSSStyleSheet,In.replaceSync(t)}catch{In=!1}if(In===!1){let n=document.createElement(`style`);n.textContent=t,e instanceof Document?e.head.prepend(n):e.prepend(n)}else e.adoptedStyleSheets=[In,...e.adoptedStyleSheets]}function Rn(){if(typeof window>`u`)return;window.ToggleEvent=window.ToggleEvent||Qt;function e(e){return e?.includes(`:popover-open`)&&(e=e.replace(Nn,`$1.\\:popover-open`)),e}U(Document.prototype,`querySelector`,e),U(Document.prototype,`querySelectorAll`,e),U(Element.prototype,`querySelector`,e),U(Element.prototype,`querySelectorAll`,e),U(Element.prototype,`matches`,e),U(Element.prototype,`closest`,e),U(DocumentFragment.prototype,`querySelectorAll`,e),Object.defineProperties(HTMLElement.prototype,{popover:{enumerable:!0,configurable:!0,get(){if(!this.hasAttribute(`popover`))return null;let e=(this.getAttribute(`popover`)||``).toLowerCase();return e===``||e==`auto`?`auto`:e==`hint`?`hint`:`manual`},set(e){e===null?this.removeAttribute(`popover`):this.setAttribute(`popover`,e)}},showPopover:{enumerable:!0,configurable:!0,value(e={}){Sn(this)}},hidePopover:{enumerable:!0,configurable:!0,value(){Cn(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,value(e={}){return typeof e==`boolean`&&(e={force:e}),an.get(this)===`showing`&&e.force===void 0||e.force===!1?Cn(this,!0,!0):(e.force===void 0||e.force===!0)&&Sn(this),an.get(this)===`showing`}}});let t=Element.prototype.attachShadow;t&&Object.defineProperties(Element.prototype,{attachShadow:{enumerable:!0,configurable:!0,writable:!0,value(e){let n=t.call(this,e);return Ln(n),n}}});let n=HTMLElement.prototype.attachInternals;n&&Object.defineProperties(HTMLElement.prototype,{attachInternals:{enumerable:!0,configurable:!0,writable:!0,value(){let e=n.call(this);return e.shadowRoot&&Ln(e.shadowRoot),e}}});let r=new WeakMap;function i(e){Object.defineProperties(e.prototype,{popoverTargetElement:{enumerable:!0,configurable:!0,set(e){if(e===null)this.removeAttribute(`popovertarget`),r.delete(this);else if(e instanceof Element)this.setAttribute(`popovertarget`,``),r.set(this,e);else throw TypeError(`popoverTargetElement must be an element or null`)},get(){if(this.localName!==`button`&&this.localName!==`input`||this.localName===`input`&&this.type!==`reset`&&this.type!==`image`&&this.type!==`button`||this.disabled||this.form&&this.type===`submit`)return null;let e=r.get(this);if(e&&e.isConnected)return e;if(e&&!e.isConnected)return r.delete(this),null;let t=mn(this),n=this.getAttribute(`popovertarget`);return(t instanceof Document||t instanceof jn)&&n&&t.getElementById(n)||null}},popoverTargetAction:{enumerable:!0,configurable:!0,get(){let e=(this.getAttribute(`popovertargetaction`)||``).toLowerCase();return e===`show`||e===`hide`?e:`toggle`},set(e){this.setAttribute(`popovertargetaction`,e)}}})}i(HTMLButtonElement),i(HTMLInputElement);let a=e=>{if(e.defaultPrevented)return;let t=e.composedPath(),n=t[0];if(!(n instanceof Element)||n?.shadowRoot)return;let r=mn(n);if(!(r instanceof jn||r instanceof Document))return;let i=t.find(e=>e.matches?.call(e,`[popovertargetaction],[popovertarget]`));if(i){ln(i),e.preventDefault();return}},o=e=>{let t=e.key,n=e.target;!e.defaultPrevented&&n&&(t===`Escape`||t===`Esc`)&&H(n.ownerDocument,!0,!0)};(e=>{e.addEventListener(`click`,a),e.addEventListener(`keydown`,o),e.addEventListener(`pointerdown`,On),e.addEventListener(`pointerup`,On)})(document),Ln(document)}n()&&!Mn()&&Rn();let zn=`data-placement`,Bn=`data-autoplacement`,Vn=new Map;function Hn(e){let{newState:t,oldState:n,target:r,source:i=e.detail}=e,a=r instanceof HTMLElement&&s(r,`popover`)!==null&&c(r,`--_ds-floating`);if(!a)return;if(t===`closed`)return Vn.get(r)?.();if(!i){let e=r.getRootNode(),t=`[popovertarget="${r.id}"],[commandfor="${r.id}"]`;i=r.id&&e?.querySelector?.(t)||void 0}if(!i||i===r||n&&n===t)return;r.style.scrollMarginBottom=`var(--_ds-floating-arrow-size)`;let o=c(r,`--_ds-floating-overscroll`),l=s(r,zn)||s(i,zn)||a,u=s(r,Bn)||s(i,Bn),d=parseFloat(c(r,`scroll-margin-bottom`))||0,f=l.match(/left|right/gi)?`Height`:`Width`,p=i[`offset${f}`]/2+d;if(l===`none`)return;let m={strategy:`absolute`,placement:l,middleware:[Kt(d),qt({padding:10,limiter:Xt({offset:{mainAxis:p}})}),Gn(),...u===`false`?[]:[Jt({padding:10,crossAxis:!1})],...o?[Yt({apply({availableHeight:e}){o===`fit`&&(r.style.width=`${i.offsetWidth}px`),r.style.maxHeight=`${Math.max(50,e-20)}px`}})]:[]]},h=Gt(i,r,async()=>{if(!i?.isConnected)return Vn.get(r)?.();let{x:e,y:t}=await Zt(i,r,m);r.style.translate=`${e}px ${t}px`});Vn.set(r,()=>Vn.delete(r)&&h())}let Un,Wn=({type:e})=>{if(e===`mousedown`&&(Un=!1),e===`scroll`&&Un===!1&&(Un=!0),e===`mouseup`&&Un)for(let[e]of Vn)e.showPopover()};p(`popover`,()=>[d(document,`mousedown scroll mouseup`,Wn,!0),d(document,`toggle ds-toggle-source`,Hn,t)]);let Gn=()=>({name:`arrowPseudo`,fn(e){let t=e.elements.floating,n=e.rects.reference,r=`${Math.round(n.width/2+n.x-e.x)}px`,i=`${Math.round(n.height/2+n.y-e.y)}px`;return t.style.setProperty(`--_ds-floating-arrow-x`,r),t.style.setProperty(`--_ds-floating-arrow-y`,i),s(t,`data-floating`,e.placement),e}}),Kn=e=>(e instanceof HTMLSelectElement||e instanceof HTMLInputElement)&&(e.hasAttribute(`readonly`)||s(e,`aria-readonly`)===`true`),qn=e=>{if(e.key!==`Tab`&&Kn(e.target)){let t=e.key?.startsWith(`Arrow`),n=e.altKey||e.ctrlKey||e.metaKey;if((t||!n)&&e.preventDefault(),t&&s(e.target,`type`)===`radio`){let t=document.querySelectorAll(`input[name="${e.target.name}"]`),n=e.key?.match(/Arrow(Right|Down)/)?1:-1;t[(t.length+[...t].indexOf(e.target)+n)%t.length]?.focus()}}},Jn=e=>{let t=e.target?.closest?.(`label`)?.control||e.target;Kn(t)&&(e.preventDefault(),t.focus())},Yn=e=>{e.target instanceof HTMLSelectElement&&Kn(e.target)&&e.preventDefault()};p(`readonly`,()=>[d(document,`keydown`,qn),d(document,`click`,Jn),d(document,`mousedown`,Yn)]);let Xn=`aria-label`,Zn=`data-toggle-group`,Qn=`[${Zn}]`,$n=()=>{for(let e of document.querySelectorAll(Qn))s(e,`aria-label`,u(e,Zn))},er=e=>{let{key:t,target:n}=e,r=n instanceof HTMLInputElement&&n.closest(Qn);if(r&&(!s(r,Xn)&&!s(r,`aria-labelledby`)&&s(r,Xn,u(r,Zn)),t===`Enter`&&n.click(),t?.startsWith(`Arrow`))){e.preventDefault?.();let i=[...r.getElementsByTagName(`input`)],a=i.indexOf(n),o=t.match(/Arrow(Right|Down)/)?1:-1,s=a;for(let e=0;e<i.length;e++)if(s=(i.length+s+o)%i.length,!i[s]?.disabled){i[s]?.focus();break}}};p(`toggle-group`,()=>[d(document,`keydown`,er),m(document,$n,{attributeFilter:[Zn],attributes:!0,childList:!0,subtree:!0})]);let W,tr,nr=!1,rr=0,ir=0,ar=n()&&/iPad|iPhone|iPod/.test(navigator.userAgent),or=`data-tooltip`,sr=`data-color`,cr=`aria-label`,lr=`aria-description`,ur=`[${sr}]`,dr=`[${or}]`,fr=`data-color-scheme`,pr=`[${fr}]`,mr=e=>{e&&!(e instanceof HTMLElement)&&o(`setTooltipElement expects an HTMLElement, got: `,e),clearTimeout(ir),clearTimeout(rr),tr=void 0,nr=!1,W=e||void 0},hr=()=>{for(let e of document.querySelectorAll(dr)){let t=u(e,or);if(!t)return;if(t!==(e.getAttribute(cr)||e.getAttribute(lr))){let n=s(e,`role`)!==`img`&&e.textContent?.trim();s(e,or,t),s(e,cr,n?null:t),s(e,lr,n?t:null),e.matches(`a,button,input,label,select,textarea,[tabindex]`)||o(`Missing tabindex="0" attribute on: `,e)}let n=e===tr&&W?.offsetHeight&&W?.offsetWidth,r=n&&t&&W?.textContent!==t;n&&r&&(W&&(W.textContent=t),document.activeElement===e&&ee(t))}},gr=({type:e,target:t})=>{if(clearTimeout(rr),t===W)return;if(e===`mouseover`&&!nr&&!ar){rr=setTimeout(gr,300,{target:t});return}let n=t?.closest?.(`[${or}]`);if(n===tr)return;if(!n)return _r();W||=h(`div`,{class:`ds-tooltip`}),W.isConnected||document.body.appendChild(W);let r=n.closest(ur),i=n.closest(pr),a=r!==i&&r?.contains(i);clearTimeout(ir),s(W,`popover`,`manual`),s(W,fr,i?.getAttribute(fr)||null),s(W,sr,a&&r?.getAttribute(sr)||null),W.textContent=s(n,or),W.showPopover(),W.dispatchEvent(new CustomEvent(`ds-toggle-source`,{detail:n})),nr=!0,tr=n},_r=()=>W?.isConnected&&W.popover&&W.hidePopover(),vr=e=>{if(e?.type===`keydown`)return e?.key===`Escape`&&_r();e?e.target===W&&e.newState===`closed`&&(tr=void 0,ir=setTimeout(vr,300)):nr=!1};p(`tooltip`,()=>[d(document,`blur focus mouseover`,gr,t),d(document,`toggle keydown`,vr,t),m(document,hr,{attributeFilter:[or],attributes:!0,childList:!0,subtree:!0})]);var yr=Object.defineProperty,br=Object.getOwnPropertySymbols,xr=Object.prototype.hasOwnProperty,Sr=Object.prototype.propertyIsEnumerable,Cr=(e,t,n)=>t in e?yr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,wr=(e,t)=>{for(var n in t||={})xr.call(t,n)&&Cr(e,n,t[n]);if(br)for(var n of br(t))Sr.call(t,n)&&Cr(e,n,t[n]);return e},Tr=()=>typeof window<`u`&&window.document!==void 0&&window.navigator!==void 0,Er=Tr(),Dr=Er?navigator.userAgent:``,Or=/android/i.test(Dr),kr=/firefox/i.test(Dr),Ar=/iPad|iPhone|iPod/.test(Dr),jr=Er&&/^Mac/i.test(navigator.userAgentData?.platform||navigator.platform),Mr=Er&&window.CSSStyleSheet&&document.adoptedStyleSheets,Nr={once:!0,capture:!0,passive:!0},Pr=`:host(:not([hidden])) { display: block }`,Fr=`outline: 1px dotted; outline: 5px auto Highlight; outline: 5px auto -webkit-focus-ring-color`,Ir=`${Or?`data`:`aria`}-multiselectable`,Lr=typeof HTMLElement>`u`?class{}:HTMLElement,G=(e,t,n)=>n===void 0?e.getAttribute(t):(n===null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n),null),Rr=(e,...t)=>{let[n,...r]=t;for(let t of n.split(` `))e.addEventListener(t,...r);return()=>zr(e,...t)},zr=(e,...t)=>{let[n,...r]=t;for(let t of n.split(` `))e.removeEventListener(t,...r)},Br=(e,t)=>{let n=e.shadowRoot||e.attachShadow({mode:`open`});if(n.querySelector(`slot`)||n.append(Gr(`slot`)),!n.querySelector(`style`))if(!Mr)n.append(Gr(`style`,null,t));else{let e=new CSSStyleSheet;e.replaceSync(t),n.adoptedStyleSheets=[e]}return n},Vr=(e,t,n)=>{let r=new MutationObserver(n=>{if(!Tr()||!e.isConnected)return i();t(e,n)}),i=Object.assign(()=>r.disconnect(),{takeRecords:()=>r.takeRecords()});return t(e),r.observe(e,n),i},Hr=e=>{let t=e.getRootNode?.call(e)||e.ownerDocument;return t instanceof Document||t instanceof ShadowRoot?t:document},Ur=e=>Hr(e).activeElement,Wr=e=>{if(!e||!Er)return null;if(window.uElementsId||(window.uElementsId={}),!e.id){let t=e.nodeName.toLowerCase();window.uElementsId[t]||(window.uElementsId[t]=1),e.id=`:${t}${window.uElementsId[t]++}`}return e.id},Gr=(e,t,n)=>{let r=document.createElement(e);if(n&&(r.textContent=n),t)for(let[e,n]of Object.entries(t))G(r,e,n);return r},Kr={define:(e,t)=>!Tr()||window.customElements.get(e)||window.customElements.define(e,t)},qr=(e,t,n=``)=>{var r;let i={bubbles:!0,composed:!0,data:t,inputType:n},a=HTMLInputElement.prototype;e.dispatchEvent(new InputEvent(`beforeinput`,i)),(r=Object.getOwnPropertyDescriptor(a,`value`)?.set)==null||r.call(e,t),e.dispatchEvent(new InputEvent(`input`,i)),e.dispatchEvent(new Event(`change`,{bubbles:!0}))},Jr=!1,Yr=e=>(e?.type===`pointerup`&&(Jr=!1),e?.type===`pointerdown`&&(Jr=!0,Rr(document,`pointerup`,Yr,Nr)),Jr),Xr=(e,t=`<slot></slot>`)=>`<template shadowrootmode="open">${t}<style>${e}</style></template>`,Zr=e=>{let t=G(e,`form`);G(e,`form`,`#`),setTimeout(Qr,0,e,t)},Qr=(e,t)=>G(e,`form`,t),K,$r=0,ei=0,ti=e=>{clearTimeout(ei),K||(K=Gr(`div`,{"aria-live":`assertive`}),K.style.overflow=`hidden`,K.style.position=`fixed`,K.style.whiteSpace=`nowrap`,K.style.width=`1px`),K.isConnected||document.body.append(K),e===``&&(K.textContent=``),e&&(K.textContent=`${e}${$r++%2?`\xA0`:``}`,ei=setTimeout(ti,!jr&&kr?2e3:300,``))},ni=`disabled`,ri=`selected`,ii=class extends Lr{constructor(){super(...arguments),this._skipAttrChange=!1}static get observedAttributes(){return[`id`,ni,ri]}connectedCallback(){Or&&(this.tabIndex=-1),this.hasAttribute(`role`)||G(this,`role`,`option`),G(this,`aria-disabled`,`${this.disabled}`),G(this,`aria-selected`,`${this.selected}`),Wr(this)}attributeChangedCallback(e){this._skipAttrChange||=(this._skipAttrChange=!0,e===`id`?Wr(this):G(this,`aria-${e}`,`${this[e]}`),!1)}get defaultSelected(){return this[ri]}set defaultSelected(e){this[ri]=e}get disabled(){return G(this,ni)!==null}set disabled(e){G(this,ni,e?``:null)}get form(){return this.closest(`form`)}get index(){return[...this.parentElement?.options||[this]].indexOf(this)}get label(){return G(this,`label`)??this.text}set label(e){G(this,`label`,e)}get selected(){return G(this,ri)!==null}set selected(e){G(this,ri,e?``:null)}get text(){return this.textContent?.trim()||``}set text(e){this.textContent=e}get value(){return G(this,`value`)??this.text}set value(e){G(this,`value`,e)}};Kr.define(`u-option`,ii);var ai=`data-activedescendant`,oi=`aria-hidden`,si=`${Pr}
|
|
64
64
|
::slotted([role="option"]) { display: block; cursor: pointer }
|
|
65
65
|
::slotted([role="option"][${ai}]) { ${Fr} }
|
|
66
|
-
::slotted([role="option"]:is([${oi}="true"], [disabled], [hidden])) { display: none !important }`,ci=Xr(si),li,ui=`focus click keydown`,di=`focusout input pointerdown`,fi={of:`of`,plural:`%d hits`,singular:`%d hit`},pi=class extends Lr{constructor(){super(),this._texts=wr({},fi),Br(this,si)}static get observedAttributes(){return[`id`,...Object.keys(fi).map(e=>`data-sr-${e}`)]}connectedCallback(){this._root=Hr(this),G(this,`hidden`,``),G(this,`role`,`listbox`),G(this,`tabindex`,`-1`),Rr(this._root,ui,this,!0),this._umutate=Vr(this,Ei,{attributeFilter:[`disabled`,`hidden`,`label`,`value`],attributes:!0,characterData:!0,childList:!0,subtree:!0})}disconnectedCallback(){var e;this._root&&zr(this._root,ui,this,!0),this._root&&zr(this._root,di,this),yi(this,null),(e=this._umutate)==null||e.call(this),this._umutate=this._root=this._input=void 0}attributeChangedCallback(e,t,n){let r=e?.split(`data-sr-`)[1];if(fi[r])this._texts[r]=n||fi[r];else if(this.id){let e=`input[list="${this.id}"]`,t=Hr(this).querySelector(e);t&&yi(this,t)}}handleEvent(e){e.defaultPrevented||(e.type===`focus`&&bi(this,e),e.type===`focusout`&&xi(this,e),e.type===`click`&&wi(this,e),e.type===`input`&&Ei(this),e.type===`keydown`&&Ti(this,e),e.type===`pointerdown`&&Ci(this,e))}get options(){let e=!this._options&&this.querySelector(`[role="option"],option`);return e&&(this._options=this.getElementsByTagName(e?.nodeName)),this._options||this.getElementsByTagName(`option`)}},mi=e=>e.disabled||e.readOnly,hi=e=>e instanceof HTMLInputElement,gi=e=>G(e,oi)!==`true`&&e.clientHeight,_i=(e,t)=>{e._input&&G(e._input,`aria-expanded`,`${t}`),!(!e.isConnected||e.hidden!==t)&&(t||vi(e),e.popover&&e.togglePopover(t),t&&setTimeout(()=>clearTimeout(li)),e.hidden=!t)},vi=(e,t)=>{e._input&&G(e._input,`aria-activedescendant`,Wr(t));for(let n of e.options)G(n,ai,n===t?``:null);t?.scrollIntoView({block:`nearest`})},yi=(e,t)=>{let n=t||e._input;n&&(e.popover&&(G(e,`popover`,`manual`),G(n,`popovertarget`,t&&Wr(e))),G(n,`aria-autocomplete`,t&&`list`),G(n,`aria-controls`,t&&Wr(e)),G(n,`autocomplete`,t&&`off`),G(n,`enterkeyhint`,`done`),G(n,`role`,t&&!mi(n)?`combobox`:null))},bi=(e,{target:t})=>{if(e._input!==t)if(hi(t)&&t.getAttribute(`list`)===e.id){if(yi(e,null),yi(e,t),mi(t))return;e._root&&Rr(e._root,di,e),G(e,`aria-label`,(t.labels?.[0])?.textContent.trim()||null),ti(),e._input=t,Or&&_i(e,!0)}else Si(e)},xi=(e,t)=>{Yr()?t.stopImmediatePropagation():Or||setTimeout(Si,0,e,t)},Si=e=>{let t=Ur(e);e._input===t||e.contains(t)||(e._root&&zr(e._root,di,e),_i(e,!1),e._input=void 0)},Ci=(e,t)=>e.contains(t.target)&&Yr(t),wi=(e,t)=>{var n;if(hi(t.target)&&bi(e,t),e._input===t.target)return _i(e,!0);if(!e.contains(t.target))return Si(e);for(let r of e.options)if(r.contains(t.target))return(n=e._input)==null||n.focus(),e._input&&qr(e._input,r.value),_i(e,G(e,Ir)===`true`)},Ti=(e,t)=>{if(hi(t.target)&&bi(e,t),e._input!==t.target)return;let{key:n,ctrlKey:r,metaKey:i,shiftKey:a,altKey:o}=t;if(r||i||a||n===`Tab`||o&&!n.startsWith(`Arrow`))return;n===`Escape`&&!e.hidden&&t.preventDefault(),_i(e,n!==`Escape`);let s=n===`Enter`,c=G(e._input,`aria-activedescendant`),l=[],u=-1,d=-1;for(let t of e.options)gi(t)&&(l.push(t),t.id===c&&(u=l.length-1));!o&&n===`ArrowDown`&&(d=(u+1)%l.length),!o&&n===`ArrowUp`&&(d=(u||l.length)-1),~u&&((n===`Home`||n===`PageUp`)&&(d=0),(n===`End`||n===`PageDown`)&&(d=l.length-1),s&&(d=u)),l[d]&&(t.preventDefault(),e._input.focus()),s&&l[d]?(t.stopImmediatePropagation(),Zr(e._input),l[d].click()):vi(e,l[d])},Ei=e=>{var t;if(!e._input||e.hidden)return;let n=e._input.value.toLowerCase().trim()||``,r=!e.hasAttribute(`data-nofilter`),i=[],a=[];for(let t of e.options)(t.disabled||t.hidden||r&&!t.label.toLowerCase().includes(n)?i:a).push(t);for(let e of i)G(e,oi,`true`);for(let e of a)G(e,oi,`false`);clearTimeout(li),li=setTimeout(Di,500,e,a),Ar&&a.forEach((t,n,{length:r})=>{G(t,`title`,`${n+1} ${e._texts.of} ${r}`)}),(t=e._umutate)==null||t.takeRecords()},Di=(e,t)=>!e.hidden&&e._input===Ur(e)&&ti(`${t.some(({value:e})=>e)?`${e._texts[t[1]?`plural`:`singular`]}`.replace(`%d`,`${t.length}`):e.innerText}`);Tr()&&Object.defineProperty(HTMLInputElement.prototype
|
|
66
|
+
::slotted([role="option"]:is([${oi}="true"], [disabled], [hidden])) { display: none !important }`,ci=Xr(si),li,ui=`focus click keydown`,di=`focusout input pointerdown`,fi={of:`of`,plural:`%d hits`,singular:`%d hit`},pi=class extends Lr{constructor(){super(),this._texts=wr({},fi),Br(this,si)}static get observedAttributes(){return[`id`,...Object.keys(fi).map(e=>`data-sr-${e}`)]}connectedCallback(){this._root=Hr(this),G(this,`hidden`,``),G(this,`role`,`listbox`),G(this,`tabindex`,`-1`),Rr(this._root,ui,this,!0),this._umutate=Vr(this,Ei,{attributeFilter:[`disabled`,`hidden`,`label`,`value`],attributes:!0,characterData:!0,childList:!0,subtree:!0})}disconnectedCallback(){var e;this._root&&zr(this._root,ui,this,!0),this._root&&zr(this._root,di,this),yi(this,null),(e=this._umutate)==null||e.call(this),this._umutate=this._root=this._input=void 0}attributeChangedCallback(e,t,n){let r=e?.split(`data-sr-`)[1];if(fi[r])this._texts[r]=n||fi[r];else if(this.id){let e=`input[list="${this.id}"]`,t=Hr(this).querySelector(e);t&&yi(this,t)}}handleEvent(e){e.defaultPrevented||(e.type===`focus`&&bi(this,e),e.type===`focusout`&&xi(this,e),e.type===`click`&&wi(this,e),e.type===`input`&&Ei(this),e.type===`keydown`&&Ti(this,e),e.type===`pointerdown`&&Ci(this,e))}get options(){let e=!this._options&&this.querySelector(`[role="option"],option`);return e&&(this._options=this.getElementsByTagName(e?.nodeName)),this._options||this.getElementsByTagName(`option`)}},mi=e=>e.disabled||e.readOnly,hi=e=>e instanceof HTMLInputElement,gi=e=>G(e,oi)!==`true`&&e.clientHeight,_i=(e,t)=>{e._input&&G(e._input,`aria-expanded`,`${t}`),!(!e.isConnected||e.hidden!==t)&&(t||vi(e),e.popover&&e.togglePopover(t),t&&setTimeout(()=>clearTimeout(li)),e.hidden=!t)},vi=(e,t)=>{e._input&&G(e._input,`aria-activedescendant`,Wr(t));for(let n of e.options)G(n,ai,n===t?``:null);t?.scrollIntoView({block:`nearest`})},yi=(e,t)=>{let n=t||e._input;n&&(e.popover&&(G(e,`popover`,`manual`),G(n,`popovertarget`,t&&Wr(e))),G(n,`aria-autocomplete`,t&&`list`),G(n,`aria-controls`,t&&Wr(e)),G(n,`autocomplete`,t&&`off`),G(n,`enterkeyhint`,`done`),G(n,`role`,t&&!mi(n)?`combobox`:null))},bi=(e,{target:t})=>{if(e._input!==t)if(hi(t)&&t.getAttribute(`list`)===e.id){if(yi(e,null),yi(e,t),mi(t))return;e._root&&Rr(e._root,di,e),G(e,`aria-label`,(t.labels?.[0])?.textContent.trim()||null),ti(),e._input=t,Or&&_i(e,!0)}else Si(e)},xi=(e,t)=>{Yr()?t.stopImmediatePropagation():Or||setTimeout(Si,0,e,t)},Si=e=>{let t=Ur(e);e._input===t||e.contains(t)||(e._root&&zr(e._root,di,e),_i(e,!1),e._input=void 0)},Ci=(e,t)=>e.contains(t.target)&&Yr(t),wi=(e,t)=>{var n;if(hi(t.target)&&bi(e,t),e._input===t.target)return _i(e,!0);if(!e.contains(t.target))return Si(e);for(let r of e.options)if(r.contains(t.target))return(n=e._input)==null||n.focus(),e._input&&qr(e._input,r.value),_i(e,G(e,Ir)===`true`)},Ti=(e,t)=>{if(hi(t.target)&&bi(e,t),e._input!==t.target)return;let{key:n,ctrlKey:r,metaKey:i,shiftKey:a,altKey:o}=t;if(r||i||a||n===`Tab`||o&&!n.startsWith(`Arrow`))return;n===`Escape`&&!e.hidden&&t.preventDefault(),_i(e,n!==`Escape`);let s=n===`Enter`,c=G(e._input,`aria-activedescendant`),l=[],u=-1,d=-1;for(let t of e.options)gi(t)&&(l.push(t),t.id===c&&(u=l.length-1));!o&&n===`ArrowDown`&&(d=(u+1)%l.length),!o&&n===`ArrowUp`&&(d=(u||l.length)-1),~u&&((n===`Home`||n===`PageUp`)&&(d=0),(n===`End`||n===`PageDown`)&&(d=l.length-1),s&&(d=u)),l[d]&&(t.preventDefault(),e._input.focus()),s&&l[d]?(t.stopImmediatePropagation(),Zr(e._input),l[d].click()):vi(e,l[d])},Ei=e=>{var t;if(!e._input||e.hidden)return;let n=e._input.value.toLowerCase().trim()||``,r=!e.hasAttribute(`data-nofilter`),i=[],a=[];for(let t of e.options)(t.disabled||t.hidden||r&&!t.label.toLowerCase().includes(n)?i:a).push(t);for(let e of i)G(e,oi,`true`);for(let e of a)G(e,oi,`false`);clearTimeout(li),li=setTimeout(Di,500,e,a),Ar&&a.forEach((t,n,{length:r})=>{G(t,`title`,`${n+1} ${e._texts.of} ${r}`)}),(t=e._umutate)==null||t.takeRecords()},Di=(e,t)=>!e.hidden&&e._input===Ur(e)&&ti(`${t.some(({value:e})=>e)?`${e._texts[t[1]?`plural`:`singular`]}`.replace(`%d`,`${t.length}`):e.innerText}`);Tr()&&Object.defineProperty(HTMLInputElement.prototype,"list",{configurable:!0,enumerable:!0,get(){let e=G(this,`list`);return e&&Hr(this).getElementById(e)}}),Kr.define(`u-datalist`,pi);let Oi=`aria-label`;var ki=class extends i{_items;_label=null;_unresize;_unmutate;static get observedAttributes(){return[Oi]}connectedCallback(){let e=a(()=>Ai(this),100);this._label=u(this,Oi),this._items=this.getElementsByTagName(`a`),this._unresize=d(window,`resize`,e),this._unmutate=m(this,Ai,{childList:!0,subtree:!0})}attributeChangedCallback(e,t,n){!this._unmutate||!n||(this._label=n,Ai(this))}disconnectedCallback(){this._unresize?.(),this._unmutate?.(),this._unresize=this._unmutate=this._items=void 0}};let Ai=e=>{let t=e._items?.[e._items.length-1],n=t?.parentElement===e?null:t,r=!n?.offsetHeight;s(e,`role`,r?null:`navigation`),s(e,Oi,r?null:e._label);for(let t of e._items||[])s(t,`aria-current`,t===n?`page`:null)};g.define(`ds-breadcrumbs`,ki);var ji=class extends i{_unmutate;connectedCallback(){d(this,`animationend`,this,t),s(this,`role`,`group`),s(this,`tabindex`,`-1`),this._unmutate=m(this,Mi,{childList:!0,subtree:!0}),this.focus()}handleEvent({target:e}){e===this&&this.focus()}disconnectedCallback(){f(this,`animationend`,this,t),this._unmutate?.(),this._unmutate=void 0}};let Mi=e=>{let t=s(e,`aria-label`)?.trim(),n=s(e,`aria-labelledby`)?.trim(),r=e.querySelector(`h2,h3,h4,h5,h6`);r&&!t&&!n&&s(e,`aria-labelledby`,v(r)),!r&&!t&&!n&&o(`Missing accessible name on:`,e,`
|
|
67
67
|
Add a heading (h2–h6), or set aria-label or aria-labelledby to provide an accessible name for screen readers.`)};g.define(`ds-error-summary`,ji);let Ni=`aria-invalid`,Pi=`aria-describedby`,Fi=`data-indeterminate`,Ii=r()?800:200,Li=new WeakMap,Ri=new Map,zi=new WeakSet,Bi=(e,t=[])=>{for(let{target:e}of t){let t=e instanceof HTMLFieldSetElement;for(let[n]of Ri)(t?e.contains(n):n.contains(e))&&Vi(n)}},Vi=e=>{let t=[],n=[],r=Ri.get(e)||[],i,a,c=!1,l=!1;for(let r of e.getElementsByTagName(`*`))if(r instanceof HTMLLabelElement&&t.push(r),!r.hidden)if(Ki(r))i?o(`Fields should only have one input element. Use <fieldset> to group multiple fields:`,e):i=r;else{let e=r.getAttribute(`data-field`);e===`counter`&&(a=r),e===`validation`?(n.unshift(v(r)),c=!0,l||=Gi(r)):e&&n.push(v(r))}if(!i)return;a&&Li.set(i,a);for(let e of t)s(e,`for`,v(i));let u=e.closest(`fieldset`)?.querySelector(`:scope > [data-field="validation"]`);u&&!u?.hidden&&(c=!0,l||=Gi(u),n.unshift(v(u)));let d=s(i,Fi);d&&(i.indeterminate=d===`true`),(i.type===`radio`||i.type===`checkbox`)&&s(e,`data-clickdelegatefor`,v(i));let f=(s(i,Pi)?.trim().split(/\s+/))?.filter(e=>!r.includes(e))||[];s(i,Pi,[...n,...f].join(` `)||null),Ri.set(e,n);let p=zi.has(i);c&&!p&&!i.hasAttribute(Ni)?(s(i,Ni,`true`),zi.add(i)):!c&&p&&(s(i,Ni,null),zi.delete(i)),Ui(i)},Hi={over:`%d tegn for mye`,under:`%d tegn igjen`},Ui=e=>{let t=e.target||e,n=Li.get(t);if(n?.isConnected){let r=(Number(s(n,`data-limit`))||0)-t.value.length,i=r<0?`over`:`under`,a=(u(n,`data-${i}`)||Hi[i])?.replace(`%d`,`${Math.abs(r)}`);s(n,`data-label`,a),s(n,`data-state`,i),s(n,`data-color`,r<0?`danger`:null),e.type===`input`&&a&&Wi(t,a)}t instanceof HTMLTextAreaElement&&(t.style.setProperty(`--_ds-field-sizing`,`auto`),t.style.setProperty(`--_ds-field-sizing`,`${t.scrollHeight}px`))},Wi=a((e,t)=>{document.activeElement===e&&ee(t)},Ii),Gi=e=>e.getAttribute(`data-color`)!==`success`,Ki=e=>e instanceof HTMLElement&&`validity`in e&&!(e instanceof HTMLButtonElement)&&e.type!==`hidden`;var qi=class extends i{connectedCallback(){Ri.set(this,[]),Vi(this)}disconnectedCallback(){Ri.delete(this)}};g.define(`ds-field`,qi),p(`field`,()=>[d(document,`input`,Ui,t),m(document,Bi,{attributeFilter:[`data-field`,`data-limit`,`hidden`,`id`,`value`,Fi],attributes:!0,childList:!0,subtree:!0})]);let Ji=`aria-label`,Yi=`data-current`,Xi=`data-total`,Zi=`data-href`,Qi=({current:e=1,total:t=10,show:n=7})=>({prev:e>1?e-1:0,next:e<t?e+1:0,pages:ta(e,t,n).map((t,n)=>({current:t===e&&`page`,key:`key-${t}-${n}`,page:t}))});var $i=class extends i{_unmutate;_render;static get observedAttributes(){return[Ji,Yi,Xi,Zi]}connectedCallback(){let e=s(this,Xi),t=s(this,Yi);t&&!e&&o(`Missing ${Xi} attribute on:`,this),e&&!t&&o(`Missing ${Yi} attribute on:`,this),s(this,Ji,u(this,Ji)),s(this,`role`,`navigation`),this._unmutate=m(this,ea,{childList:!0,subtree:!0})}attributeChangedCallback(){this._unmutate&&ea(this)}disconnectedCallback(){this._unmutate?.(),this._unmutate=this._render=void 0}};let ea=e=>{let t=Number(s(e,Yi)),n=Number(s(e,Xi));if(t&&n){let r=e.querySelectorAll(`button,a`),i=r.length-2,a=s(e,Zi),{next:o,prev:c,pages:l}=Qi({current:t,total:n,show:i});r.forEach((e,t)=>{let n=t?r[t+1]?l[t-1]?.page:o:c;s(e,`aria-current`,l[t-1]?.current?`true`:null),s(e,`aria-label`,`${n??`hidden`}`),s(e,`role`,n?null:`none`),s(e,`tabindex`,n?null:`-1`),e instanceof HTMLButtonElement&&s(e,`value`,`${n}`),a&&e instanceof HTMLAnchorElement&&s(e,`href`,a.replace(`%d`,`${n}`))})}},ta=(e,t,n=1/0)=>{let r=(n-1)/2,i=Math.max(Math.min(e-Math.floor(r),t-n+1),1),a=Math.min(Math.max(e+Math.ceil(r),n),t),o=Array.from({length:a+1-i},(e,t)=>t+i);return n>4&&i>1&&o.splice(0,2,1,0),n>3&&a<t&&o.splice(-2,2,0,t),o};g.define(`ds-pagination`,$i);var na=Object.defineProperty,ra=Object.getOwnPropertySymbols,ia=Object.prototype.hasOwnProperty,aa=Object.prototype.propertyIsEnumerable,oa=(e,t,n)=>t in e?na(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,sa=(e,t)=>{for(var n in t||={})ia.call(t,n)&&oa(e,n,t[n]);if(ra)for(var n of ra(t))aa.call(t,n)&&oa(e,n,t[n]);return e},ca=()=>typeof window<`u`&&window.document!==void 0&&window.navigator!==void 0,la=ca(),ua=la?navigator.userAgent:``,da=/android/i.test(ua),fa=/firefox/i.test(ua),pa=/iPad|iPhone|iPod/.test(ua),ma=la&&/^Mac/i.test(navigator.userAgentData?.platform||navigator.platform),ha=la&&window.CSSStyleSheet&&document.adoptedStyleSheets,ga={once:!0,capture:!0,passive:!0},_a=`:host(:not([hidden])) { display: block }`,va=`outline: 1px dotted; outline: 5px auto Highlight; outline: 5px auto -webkit-focus-ring-color`,ya=`${da?`data`:`aria`}-multiselectable`,ba=typeof HTMLElement>`u`?class{}:HTMLElement,q=(e,t,n)=>n===void 0?e.getAttribute(t):(n===null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n),null),xa=(e,...t)=>{let[n,...r]=t;for(let t of n.split(` `))e.addEventListener(t,...r);return()=>Sa(e,...t)},Sa=(e,...t)=>{let[n,...r]=t;for(let t of n.split(` `))e.removeEventListener(t,...r)},Ca=(e,t)=>{let n=e.shadowRoot||e.attachShadow({mode:`open`});if(n.querySelector(`slot`)||n.append(ka(`slot`)),!n.querySelector(`style`))if(!ha)n.append(ka(`style`,null,t));else{let e=new CSSStyleSheet;e.replaceSync(t),n.adoptedStyleSheets=[e]}return n},wa=(e,t,n)=>{let r=new MutationObserver(n=>{if(!ca()||!e.isConnected)return i();t(e,n)}),i=Object.assign(()=>r.disconnect(),{takeRecords:()=>r.takeRecords()});return t(e),r.observe(e,n),i},Ta=e=>{let t=e.getRootNode?.call(e)||e.ownerDocument;return t instanceof Document||t instanceof ShadowRoot?t:document},Ea=e=>Ta(e).activeElement,Da=e=>{let t=q(e,`aria-label`)||``;return[...(q(e,`aria-labelledby`)?.split(` `)||[]).map(e=>document.getElementById(e.trim()||`-`)),...Array.from(e.labels||[])].reduce((e,t)=>e||(t?.innerText)?.trim()||``,t).trim()},Oa=e=>{if(!e||!la)return null;if(window.uElementsId||(window.uElementsId={}),!e.id){let t=e.nodeName.toLowerCase();window.uElementsId[t]||(window.uElementsId[t]=1),e.id=`:${t}${window.uElementsId[t]++}`}return e.id},ka=(e,t,n)=>{let r=document.createElement(e);if(n&&(r.textContent=n),t)for(let[e,n]of Object.entries(t))q(r,e,n);return r},Aa={define:(e,t)=>!ca()||window.customElements.get(e)||window.customElements.define(e,t)},ja=(e,t,n=``)=>{var r;let i={bubbles:!0,composed:!0,data:t,inputType:n},a=HTMLInputElement.prototype;e.dispatchEvent(new InputEvent(`beforeinput`,i)),(r=Object.getOwnPropertyDescriptor(a,`value`)?.set)==null||r.call(e,t),e.dispatchEvent(new InputEvent(`input`,i)),e.dispatchEvent(new Event(`change`,{bubbles:!0}))},Ma=new WeakSet,Na=(e,t)=>(t?.type===`pointerdown`&&(Ma.add(e),xa(document,`pointerup`,()=>Ma.delete(e),ga)),Ma.has(e)),Pa=(e,t=`<slot></slot>`)=>`<template shadowrootmode="open">${t}<style>${e}</style></template>`,Fa=e=>{let t=q(e,`form`);q(e,`form`,`#`),setTimeout(Ia,0,e,t)},Ia=(e,t)=>q(e,`form`,t),J=e=>(e?.textContent)?.trim()||``,Y,La=0,Ra=0,za=e=>{clearTimeout(Ra),Y||(Y=ka(`div`,{"aria-live":`assertive`}),Y.style.overflow=`hidden`,Y.style.position=`fixed`,Y.style.whiteSpace=`nowrap`,Y.style.width=`1px`),Y.isConnected||document.body.append(Y),e===``&&(Y.textContent=``),e&&(Y.textContent=`${e}${La++%2?`\xA0`:``}`,Ra=setTimeout(za,!ma&&fa?2e3:300,``))},Ba=`${_a}
|
|
68
68
|
:is(:host(:not([data-multiple])), :host([data-multiple="false"])) [part="items"] { display: none }
|
|
69
69
|
[role="listbox"] { display: inline-flex } /* Can not be "contents" as this confuses VoiceOver */
|