@digdir/designsystemet-web 1.18.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -15
- package/dist/cjs/_vendors/@oddbird/popover-polyfill/dist/popover-fn.cjs +4 -4
- package/dist/cjs/_vendors/@oddbird/popover-polyfill/dist/popover-fn.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -1
- package/dist/cjs/breadcrumbs/breadcrumbs.cjs +1 -1
- package/dist/cjs/breadcrumbs/breadcrumbs.cjs.map +1 -1
- package/dist/cjs/clickdelegatefor/clickdelegatefor.cjs +1 -1
- package/dist/cjs/clickdelegatefor/clickdelegatefor.cjs.map +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 -2
- 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/fieldset/fieldset.cjs.map +1 -1
- package/dist/cjs/focusgroup/focusgroup.cjs +2 -0
- package/dist/cjs/focusgroup/focusgroup.cjs.map +1 -0
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/invokers/invokers.cjs.map +1 -1
- package/dist/cjs/packages/web/package.cjs +2 -0
- package/dist/cjs/packages/web/package.cjs.map +1 -0
- 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/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/tooltip/tooltip.cjs.map +1 -1
- package/dist/cjs/utils/utils.cjs +1 -1
- package/dist/cjs/utils/utils.cjs.map +1 -1
- package/dist/custom-elements.json +189 -4
- package/dist/esm/_vendors/@oddbird/popover-polyfill/dist/popover-fn.js +4 -4
- package/dist/esm/_vendors/@oddbird/popover-polyfill/dist/popover-fn.js.map +1 -1
- package/dist/esm/breadcrumbs/breadcrumbs.js +1 -1
- package/dist/esm/breadcrumbs/breadcrumbs.js.map +1 -1
- package/dist/esm/clickdelegatefor/clickdelegatefor.js +1 -1
- package/dist/esm/clickdelegatefor/clickdelegatefor.js.map +1 -1
- package/dist/esm/dialog/dialog.js +1 -1
- package/dist/esm/dialog/dialog.js.map +1 -1
- package/dist/esm/error-summary/error-summary.js +1 -2
- package/dist/esm/error-summary/error-summary.js.map +1 -1
- package/dist/esm/field/field.js +1 -1
- package/dist/esm/field/field.js.map +1 -1
- package/dist/esm/fieldset/fieldset.js +1 -1
- package/dist/esm/fieldset/fieldset.js.map +1 -1
- package/dist/esm/focusgroup/focusgroup.js +2 -0
- package/dist/esm/focusgroup/focusgroup.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/invokers/invokers.js.map +1 -1
- package/dist/esm/packages/web/package.js +2 -0
- package/dist/esm/packages/web/package.js.map +1 -0
- package/dist/esm/pagination/pagination.js +1 -1
- package/dist/esm/pagination/pagination.js.map +1 -1
- package/dist/esm/popover/popover.js +1 -1
- package/dist/esm/popover/popover.js.map +1 -1
- package/dist/esm/readonly/readonly.js +1 -1
- package/dist/esm/readonly/readonly.js.map +1 -1
- package/dist/esm/suggestion/suggestion.js +1 -1
- package/dist/esm/suggestion/suggestion.js.map +1 -1
- package/dist/esm/toggle-group/toggle-group.js +1 -1
- package/dist/esm/toggle-group/toggle-group.js.map +1 -1
- package/dist/esm/tooltip/tooltip.js +1 -1
- package/dist/esm/tooltip/tooltip.js.map +1 -1
- package/dist/esm/utils/utils.js +1 -1
- package/dist/esm/utils/utils.js.map +1 -1
- package/dist/index.d.ts +18 -22
- package/dist/index.js +636 -263
- package/dist/umd/index.js +16 -11
- package/dist/umd/index.js.map +1 -1
- package/package.json +15 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focusgroup.cjs","names":["isBrowser","getComposedTarget","getComposedPath","on","QUICK_EVENT"],"sources":["../../../src/focusgroup/focusgroup.ts"],"sourcesContent":["import {\n attr,\n getComposedPath,\n getComposedTarget,\n isBrowser,\n on,\n onHotReload,\n QUICK_EVENT,\n} from '../utils/utils';\n\n// Intentionally not implemented:\n// - Clearing memory based on attribute changes: https://open-ui.org/components/scoped-focusgroup.explainer/#disabling-focusgroup-memory\n// - Setting ARIA roles before focus or keydown occurs (this is too performance consuming, and does not affect a11y much)\n\nconst ATTR_GROUP = 'focusgroup';\nconst PROP_GROUP = 'focusGroup';\nconst ATTR_START = `${ATTR_GROUP}start`;\nconst GROUPS = new WeakMap<Element, ReturnType<typeof parseGroup>>();\nconst ROOTS = new Map<Node, () => void>(); // ShadowRoots we listen for focus events on, since focus only triggers once on ShadowDOM due to event retargeting\nconst ROLES = {\n listbox: { block: true, wrap: false, items: 'option' },\n menu: { block: true, wrap: true, items: 'menuitem' },\n menubar: { block: false, wrap: true, items: 'menuitem' },\n radiogroup: { block: null, wrap: true, items: 'radio' },\n tablist: { block: false, wrap: true, items: 'tab' },\n toolbar: { block: false, wrap: false, items: null },\n};\nlet IS_TAB = false; // Used to check if focus event is a result of tabbing\nconst IS_CONFLICT = new Set([\n 'AUDIO',\n 'VIDEO',\n 'TEXTAREA',\n 'SELECT',\n 'date',\n 'datetime-local',\n 'email',\n 'month',\n 'number',\n 'password',\n 'range',\n 'search',\n 'tel',\n 'text',\n 'time',\n 'url',\n 'week',\n]);\n\n// Chrome has implemented camel case \"focusGroup\", but several polyfills checks both camel case and kebab case, so we support both for now\nconst IS_SUPPORTED =\n isBrowser() &&\n (ATTR_GROUP in HTMLElement.prototype || PROP_GROUP in HTMLElement.prototype);\n\nconst setIsTab = (state: boolean) => (IS_TAB = state);\nconst handleKeydown = (e: Event & Partial<KeyboardEvent>) => {\n if (e.defaultPrevented || e.altKey || e.metaKey || e.ctrlKey) return;\n\n const isTab = e.key === 'Tab';\n const isBlock = e.key === 'ArrowUp' || e.key === 'ArrowDown';\n const isArrow = isBlock || e.key === 'ArrowLeft' || e.key === 'ArrowRight';\n if (!isTab && !isArrow && e.key !== 'Home' && e.key !== 'End') return;\n if (isTab) {\n setIsTab(true);\n setTimeout(setIsTab, 100, false); // Reset after event loop so we can check if next focus event is a result of tabbing\n }\n\n const target = getComposedTarget(e) as Element | null;\n if (!target || isConflict(target)) return; // See https://open-ui.org/components/scoped-focusgroup.explainer/#key-conflict-elements\n\n let group = getGroup(getComposedPath(target));\n\n if (group?.role && group?.el === target)\n group = getGroup(getComposedPath(group.el.parentNode)); // If focus is on the group itself, check if it is nested inside another group\n if (!group?.role) return; // Ignore invalid parent groups\n\n const items = getItems(group.el, target); // Include target so we can move from tabindex=\"-1\" as according to spec\n let next = 0;\n\n if (isTab) return setTimeout(setTab, 0, items, setTab(items)); // Make sure next tab stop is outside focusgroup\n if (e.key === 'Home') next = 0;\n else if (e.key === 'End') next = items.length - 1;\n else {\n const { direction: dir, writingMode: mode } = getComputedStyle(target);\n const isFlipped = mode.startsWith('vertical');\n const isReverse = isFlipped ? mode === 'vertical-rl' : dir === 'rtl';\n const isForward = e.key === 'ArrowDown' || e.key === 'ArrowRight';\n\n const moveBlock = isBlock !== isFlipped;\n const moveForward = isForward !== (!isBlock && isReverse);\n\n if ((group.block ?? moveBlock) !== moveBlock) return; // Ignore if group direction does not match move direction\n next = items.indexOf(target) + (moveForward ? 1 : -1);\n\n if (group.wrap) next = (items.length + next) % items.length;\n else next = Math.max(0, Math.min(next, items.length - 1));\n }\n\n // Note: preventDefault() prevents native <input type=\"radio\"> elements from changing checked state with arrow keys.\n // Although this differs from native behavior, it matches focusgroup=\"radiogroup\" for <button role=\"radio\">.\n // toggle-group.ts already normalizes this for both <input type=\"radio\"> and <button role=\"radio\">,\n // meaning the following preventDefault() introduces no inconsistencies:\n if (items[next] !== target) e.preventDefault(); // Prevent scrolling if changing item\n (items[next] as HTMLElement)?.focus?.();\n};\n\nconst handleFocus = (e: Event & Partial<FocusEvent>) => {\n const target = getComposedTarget(e);\n const path = getComposedPath(target);\n\n for (const [el, off] of ROOTS) if (!path.has(el) && ROOTS.delete(el)) off(); // Remove focus listener on previous roots\n for (const el of path)\n if (el.nodeType === 11 && !ROOTS.has(el))\n ROOTS.set(el, on(el, 'focus', handleFocus, QUICK_EVENT)); // Listener will instantly dispatch since we are binding during triggering\n\n if ((e.target as Element)?.shadowRoot) return; // Avoid double handling by only processing focus events that are not already handled in a shadowRoot\n\n const group = getGroup(path);\n if (!group?.role) return;\n if (IS_TAB && !isConflict(group.focus)) {\n const segment = getSegment(getItems(group.el, null), target); // See https://open-ui.org/components/scoped-focusgroup.explainer/#focusgroup-segments\n const start =\n (group.memory && segment.includes(group.focus) && group.focus) ||\n segment.find((el) => el?.hasAttribute(ATTR_START)) ||\n segment[0];\n if (start !== target) return (start as HTMLElement)?.focus?.(); // Fix focus position if tabbing into segment\n }\n group.focus = target; // Always store focus\n};\n\nexport const getGroup = (path: Set<Node>) => {\n for (const el of path as Set<Element>) {\n if (el.nodeType !== Node.ELEMENT_NODE) continue;\n\n const key = el.getAttribute(ATTR_GROUP);\n if (key !== null) {\n let group = GROUPS.get(el);\n if (group?.key === key) return group; // Return cache if attribute is unchanged\n\n group = parseGroup(el, key);\n GROUPS.set(el, group);\n for (const item of getItems(el))\n if (item && !item.hasAttribute('role')) attr(item, 'role', group.items);\n if (!el.hasAttribute('role')) attr(el, 'role', group.role);\n return group;\n }\n if (isTopLayer(el)) return;\n }\n};\n\nconst parseGroup = (el: Element, key: string) => {\n const opts = new Set(key.toLowerCase().split(' '));\n const role = [...opts].find((t) => t in ROLES) as keyof typeof ROLES;\n const base = ROLES[role];\n const x = opts.has('inline');\n const y = opts.has('block');\n\n return {\n key,\n el,\n role,\n block: x && y ? null : y || (x ? false : base?.block),\n focus: null as Element | null,\n items: base?.items,\n memory: !opts.has('nomemory'),\n wrap: opts.has('wrap') || (opts.has('nowrap') ? false : base?.wrap),\n };\n};\n\nexport const getItems = (\n root?: Element | null,\n keep?: Element | null, // Provide Element to include, or null to keep segments (https://open-ui.org/components/scoped-focusgroup.explainer/#focusgroup-segments)\n items: (Element | null)[] = [], // Used only for recursion\n isNested = false, // Used only for recursion, to check if already inside a nested group\n) => {\n const children =\n root?.nodeName === 'SLOT'\n ? (root as HTMLSlotElement).assignedElements({ flatten: true })\n : (root?.shadowRoot || root)?.children;\n\n for (let i = 0, l = children?.length || i; children && i < l; i++) {\n const el = children[i] as HTMLElement;\n if (el.nodeName === 'SLOT') getItems(el, keep, items, isNested);\n else if (isKeyboardReachable(el) && !isTopLayer(el) && isVisible(el)) {\n const group = el.getAttribute(ATTR_GROUP);\n if (el === keep || (!isNested && group !== 'none' && isFocusable(el)))\n items.push(el);\n else if (group !== null && keep === null) items.push(null);\n else getItems(el, keep, items, isNested || group !== null);\n }\n }\n return items;\n};\n\n// Treats the null returned from getItems as a separator and returns segment containing \"item\"\nconst getSegment = <T>(acc: (T | null)[], item: T) => {\n const at = acc.indexOf(item);\n const to = acc.indexOf(null, at);\n return acc.slice(acc.lastIndexOf(null, at) + 1, to === -1 ? undefined : to);\n};\n\nconst isKeyboardReachable = (el: HTMLElement) =>\n !el.inert && !el.hidden && !(el as HTMLInputElement).disabled;\n\nconst isTopLayer = (el: Element | null) =>\n el?.nodeName === 'DIALOG' || el?.hasAttribute('popover'); // See https://open-ui.org/components/scoped-focusgroup.explainer/#top-layer-elements)\n\nconst isVisible =\n isBrowser() && typeof Element.prototype.checkVisibility === 'function'\n ? (el: HTMLElement) => el.checkVisibility()\n : (el: HTMLElement) => el.offsetParent !== null;\n\nexport const isFocusable = (el: HTMLElement) =>\n el.isContentEditable ||\n (el.tabIndex >= 0 && !(el as HTMLInputElement).disabled);\n\nexport const isConflict = (el: Node | null) =>\n (el as HTMLElement)?.isContentEditable ||\n IS_CONFLICT.has(el?.nodeName as string) ||\n (el?.nodeName === 'INPUT' && IS_CONFLICT.has((el as HTMLInputElement).type));\n\nconst setTab = (items: ReturnType<typeof getItems>, prevs?: string[]) =>\n Array.from(items, (item, index) => {\n const prev = item?.getAttribute('tabindex');\n if (item) attr(item, 'tabindex', prevs ? prevs[index] : '-1'); // Restore previous tabindex if provided\n return prev;\n });\n\nif (!IS_SUPPORTED)\n onHotReload(ATTR_GROUP, () => [\n on(document, 'keydown', handleKeydown),\n on(document, 'focus', handleFocus, QUICK_EVENT),\n () => {\n for (const [, off] of ROOTS) off(); // Cleanup listeners on ShadowRoots on hot reload\n ROOTS.clear();\n },\n ]);\n"],"mappings":"sCAcM,EAAa,aAEb,EAAa,GAAG,EAAW,OAC3B,EAAS,IAAI,QACb,EAAQ,IAAI,IACZ,EAAQ,CACZ,QAAS,CAAE,MAAO,GAAM,KAAM,GAAO,MAAO,QAAS,EACrD,KAAM,CAAE,MAAO,GAAM,KAAM,GAAM,MAAO,UAAW,EACnD,QAAS,CAAE,MAAO,GAAO,KAAM,GAAM,MAAO,UAAW,EACvD,WAAY,CAAE,MAAO,KAAM,KAAM,GAAM,MAAO,OAAQ,EACtD,QAAS,CAAE,MAAO,GAAO,KAAM,GAAM,MAAO,KAAM,EAClD,QAAS,CAAE,MAAO,GAAO,KAAM,GAAO,MAAO,IAAK,CACpD,EACA,IAAI,EAAS,GACb,MAAM,EAAc,IAAI,IAAI,CAC1B,QACA,QACA,WACA,SACA,OACA,iBACA,QACA,QACA,SACA,WACA,QACA,SACA,MACA,OACA,OACA,MACA,MACF,CAAC,EAGK,EACJA,EAAAA,UAAU,IACT,KAAc,YAAY,WA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AAY,IAAU,IAAI,CAC3D,CACF,CACA,OAAO,CACT,EAGM,GAAiB,EAAmB,IAAY,CACpD,IAAM,EAAK,EAAI,QAAQ,CAAI,EACrB,EAAK,EAAI,QAAQ,KAAM,CAAE,EAC/B,OAAO,EAAI,MAAM,EAAI,YAAY,KAAM,CAAE,EAAI,EAAG,IAAO,GAAK,IAAA,GAAY,CAAE,CAC5E,EAEM,EAAuB,GAC3B,CAAC,EAAG,OAAS,CAAC,EAAG,QAAU,CAAE,EAAwB,SAEjD,EAAc,GAClB,GAAI,WAAa,UAAY,GAAI,aAAa,SAAS,EAEnD,EACJJ,EAAAA,UAAU,GAAK,OAAO,QAAQ,UAAU,iBAAoB,WACvD,GAAoB,EAAG,gBAAgB,EACvC,GAAoB,EAAG,eAAiB,KAElC,EAAe,GAC1B,EAAG,mBACF,EAAG,UAAY,GAAK,CAAE,EAAwB,SAEpC,EAAc,GACxB,GAAoB,mBACrB,EAAY,IAAI,GAAI,QAAkB,GACrC,GAAI,WAAa,SAAW,EAAY,IAAK,EAAwB,IAAI,EAEtE,GAAU,EAAoC,IAClD,MAAM,KAAK,GAAQ,EAAM,IAAU,CACjC,IAAM,EAAO,GAAM,aAAa,UAAU,EAE1C,OADI,GAAM,EAAA,KAAK,EAAM,WAAY,EAAQ,EAAM,GAAS,IAAI,EACrD,CACT,CAAC,EAEE,GACH,EAAA,YAAY,MAAkB,CAC5BG,EAAAA,GAAG,SAAU,UAAW,CAAa,EACrCA,EAAAA,GAAG,SAAU,QAAS,EAAaC,EAAAA,WAAW,MACxC,CACJ,IAAK,GAAM,EAAG,KAAQ,EAAO,EAAI,EACjC,EAAM,MAAM,CACd,CACF,CAAC"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("./clickdelegatefor/clickdelegatefor.cjs"),require("./details/details.cjs"),require("./dialog/dialog.cjs"),require("./fieldset/fieldset.cjs"),require("./invokers/invokers.cjs"),require("./popover/popover.cjs"),require("./readonly/readonly.cjs"),require("./toggle-group/toggle-group.cjs");const e=require("./tooltip/tooltip.cjs"),t=require("./breadcrumbs/breadcrumbs.cjs"),n=require("./error-summary/error-summary.cjs"),r=require("./field/field.cjs"),i=require("./pagination/pagination.cjs"),a=require("./suggestion/suggestion.cjs"),o=require("./tabs/tabs.cjs");exports.DSBreadcrumbsElement=t.DSBreadcrumbsElement,exports.DSErrorSummaryElement=n.DSErrorSummaryElement,exports.DSFieldElement=r.DSFieldElement,exports.DSPaginationElement=i.DSPaginationElement,exports.DSSuggestionElement=a.DSSuggestionElement,exports.DSTabElement=o.DSTabElement,exports.DSTabListElement=o.DSTabListElement,exports.DSTabPanelElement=o.DSTabPanelElement,exports.DSTabsElement=o.DSTabsElement,exports.pagination=i.pagination,exports.setTooltipElement=e.setTooltipElement;var s=require("@u-elements/u-datalist");Object.keys(s).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return s[e]}})});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("./clickdelegatefor/clickdelegatefor.cjs"),require("./details/details.cjs"),require("./dialog/dialog.cjs"),require("./fieldset/fieldset.cjs"),require("./focusgroup/focusgroup.cjs"),require("./invokers/invokers.cjs"),require("./popover/popover.cjs"),require("./readonly/readonly.cjs"),require("./toggle-group/toggle-group.cjs");const e=require("./tooltip/tooltip.cjs"),t=require("./breadcrumbs/breadcrumbs.cjs"),n=require("./error-summary/error-summary.cjs"),r=require("./field/field.cjs"),i=require("./pagination/pagination.cjs"),a=require("./suggestion/suggestion.cjs"),o=require("./tabs/tabs.cjs");exports.DSBreadcrumbsElement=t.DSBreadcrumbsElement,exports.DSErrorSummaryElement=n.DSErrorSummaryElement,exports.DSFieldElement=r.DSFieldElement,exports.DSPaginationElement=i.DSPaginationElement,exports.DSSuggestionElement=a.DSSuggestionElement,exports.DSTabElement=o.DSTabElement,exports.DSTabListElement=o.DSTabListElement,exports.DSTabPanelElement=o.DSTabPanelElement,exports.DSTabsElement=o.DSTabsElement,exports.initTooltips=e.initTooltips,exports.pagination=i.pagination,exports.setTooltipElement=e.setTooltipElement;var s=require("@u-elements/u-datalist");Object.keys(s).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return s[e]}})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invokers.cjs","names":["isBrowser","isSupported"],"sources":["../../../src/invokers/invokers.ts"],"sourcesContent":["import { isSupported, apply as polyfillInvokers } from 'invokers-polyfill/fn';\nimport { isBrowser } from '../utils/utils';\n\nif (isBrowser() && !isSupported()) polyfillInvokers(); // Ensure invoker commands polyfill is loaded in browser environment only\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"invokers.cjs","names":["isBrowser","isSupported"],"sources":["../../../src/invokers/invokers.ts"],"sourcesContent":["import { isSupported, apply as polyfillInvokers } from 'invokers-polyfill/fn';\nimport { isBrowser } from '../utils/utils';\n\n// isPolyfilled is not used here as isSupported is enough to determine if the polyfill needs to be applied as it checks for the presence of the invoker commands in the environment. If they are not present, it means the polyfill is not applied and needs to be applied.\nif (isBrowser() && !isSupported()) polyfillInvokers(); // Ensure invoker commands polyfill is loaded in browser environment only\n"],"mappings":"6FAIIA,EAAAA,UAAU,GAAK,CAACC,EAAAA,YAAY,GAAG,EAAA,MAAiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.cjs","names":[],"sources":["../../../../package.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../utils/utils.cjs"),t=`
|
|
1
|
+
const e=require("../utils/utils.cjs"),t=`data-current`,n=`data-total`,r=`data-href`,i=({current:e=1,total:t=10,show:n=7})=>({prev:e>1?e-1:0,next:e<t?e+1:0,pages:s(e,t,n).map((t,n)=>({current:t===e&&`page`,key:`key-${t}-${n}`,page:t}))});var a=class extends e.DSElement{_unmutate;_render;static get observedAttributes(){return[e.ARIA_LABEL,e.ARIA_LABELLEDBY,t,n,r]}connectedCallback(){let r=e.attr(this,n),i=e.attr(this,t);i&&!r&&e.warn(`Missing ${n} attribute on:`,this),r&&!i&&e.warn(`Missing ${t} attribute on:`,this);let a=e.attrOrCSS(this,e.ARIA_LABEL),s=e.attr(this,e.ARIA_LABELLEDBY)?.trim();a||s?e.attr(this,e.ARIA_LABEL,s?null:a):e.warn(`Missing ${e.ARIA_LABEL} on:`,this),e.attr(this,`role`,`navigation`),this._unmutate=e.onMutation(this,o,{childList:!0,subtree:!0})}attributeChangedCallback(){this._unmutate&&o(this)}disconnectedCallback(){this._unmutate?.(),this._unmutate=this._render=void 0}};const o=a=>{let o=Number(e.attr(a,t)),s=Number(e.attr(a,n));if(o&&s){let t=a.querySelectorAll(`button,a`),n=t.length-2,c=e.attr(a,r),{next:l,prev:u,pages:d}=i({current:o,total:s,show:n});t.forEach((n,r)=>{let i=r?t[r+1]?d[r-1]?.page:l:u;e.attr(n,`aria-current`,d[r-1]?.current?`true`:null),e.attr(n,e.ARIA_LABEL,`${i??`hidden`}`),e.attr(n,`role`,i?null:`none`),e.attr(n,`tabindex`,i?null:`-1`),n instanceof HTMLButtonElement&&e.attr(n,`value`,`${i}`),c&&n instanceof HTMLAnchorElement&&e.attr(n,`href`,c.replace(`%d`,`${i}`))})}},s=(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};e.customElements.define(`ds-pagination`,a),exports.DSPaginationElement=a,exports.pagination=i;
|
|
2
2
|
//# sourceMappingURL=pagination.cjs.map
|
|
@@ -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
|
|
1
|
+
{"version":3,"file":"pagination.cjs","names":["DSElement","ARIA_LABEL","ARIA_LABELLEDBY","attr","attrOrCSS","onMutation","customElements"],"sources":["../../../src/pagination/pagination.ts"],"sourcesContent":["import {\n ARIA_LABEL,\n ARIA_LABELLEDBY,\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_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 [ARIA_LABEL, ARIA_LABELLEDBY, 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 const label = attrOrCSS(this, ARIA_LABEL);\n const labelledby = attr(this, ARIA_LABELLEDBY)?.trim();\n if (label || labelledby) attr(this, ARIA_LABEL, labelledby ? null : label);\n else warn(`Missing ${ARIA_LABEL} on:`, this);\n\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":"sCAiBM,EAAe,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AAG,EAC9C,CACT,EAEAK,EAAAA,eAAe,OAAO,gBAAiB,CAAmB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../utils/utils.cjs"),t=require("../_vendors/@oddbird/popover-polyfill/dist/popover-fn.cjs");let n=require("@floating-ui/dom");e.isBrowser()&&!t.isSupported()&&t.apply();const r=`data-placement`,
|
|
1
|
+
const e=require("../utils/utils.cjs"),t=require("../_vendors/@oddbird/popover-polyfill/dist/popover-fn.cjs");let n=require("@floating-ui/dom");e.isBrowser()&&!t.isSupported()&&!t.isPolyfilled()&&t.apply({layerName:`ds.base`});const r=new Map,i=`data-placement`,a=`data-autoplacement`,o=new Map,s=t=>c(e.getComposedTarget(t),t.newState,t.oldState,t.source||t.detail);function c(t,r,s,c){let l=t instanceof HTMLElement&&e.attr(t,`popover`)!==null&&e.getCSSProp(t,`--_ds-floating`),u=o.get(t);if(r===`open`&&u&&u.source===c||(u?.cleanup(),r===`closed`||!l))return;if(!c){let n=t.id&&`[popovertarget="${t.id}"],[commandfor="${t.id}"]`;c=n&&e.getRoot(t).querySelector(n)||void 0}if(!c||c===t||s&&s===r)return;t.style.scrollMarginBottom=`var(--_ds-floating-arrow-size)`;let d=e.getCSSProp(t,`--_ds-floating-overscroll`),p=e.attr(t,i)||e.attr(c,i)||l,m=e.attr(t,a)||e.attr(c,a),h=parseFloat(e.getCSSProp(t,`scroll-margin-bottom`))||0,g=p.match(/left|right/gi)?`Height`:`Width`,_=c[`offset${g}`]/2+h;if(p===`none`)return;let v={strategy:`absolute`,placement:p,middleware:[(0,n.offset)(h),(0,n.shift)({padding:10,limiter:(0,n.limitShift)({offset:{mainAxis:_}})}),f(),...m===`false`?[]:[(0,n.flip)({padding:10,crossAxis:!1})],...d?[(0,n.size)({apply({availableHeight:e}){d===`fit`&&(t.style.width=`${c.offsetWidth}px`),t.style.maxHeight=`${Math.max(50,e-20)}px`}})]:[]]},y=(0,n.autoUpdate)(c,t,async()=>{if(!c?.isConnected)return o.get(t)?.cleanup();let{x:e,y:r}=await(0,n.computePosition)(c,t,v);t.style.translate=`${e}px ${r}px`});o.set(t,{source:c,cleanup:()=>o.delete(t)&&y()})}let l;const u=e=>{if(e.type===`pointerdown`&&(l=!1),e.type===`scroll`&&l===!1&&(l=!0),e.type===`pointerup`&&l)for(let[e]of o)e.showPopover()},d=t=>{for(let[e,t]of r)!e.host?.isConnected&&r.delete(e)&&t();let n=e.getRoot(e.getComposedTarget(t));n instanceof ShadowRoot&&!r.has(n)&&r.set(n,e.on(n,`toggle`,s,e.QUICK_EVENT))};e.onHotReload(`popover`,()=>{let t=e=>typeof e==`function`,n=HTMLElement.prototype.togglePopover,i=HTMLElement.prototype.showPopover,a=HTMLElement.prototype.hidePopover;return t(n)&&(HTMLElement.prototype.togglePopover=function(e){let t=this.matches(`:popover-open`),r=typeof e==`boolean`,i=t?`open`:`closed`,a=(r?e:e?.force??!t)?`open`:`closed`,o=r?void 0:e?.source,s=n.call(this,e);return c(this,a,i,o),s}),t(i)&&(HTMLElement.prototype.showPopover=function(e){let t=this.matches(`:popover-open`)?`open`:`closed`,n=i.call(this,e);return c(this,`open`,t,e?.source),n}),t(a)&&(HTMLElement.prototype.hidePopover=function(){let e=this.matches(`:popover-open`)?`open`:`closed`,t=a.call(this);return c(this,`closed`,e),t}),[e.on(document,`click`,d,e.QUICK_EVENT),e.on(document,`pointerdown pointerup scroll`,u,e.QUICK_EVENT),e.on(document,`toggle ds-toggle-source`,s,e.QUICK_EVENT),()=>{HTMLElement.prototype.togglePopover=n,HTMLElement.prototype.showPopover=i,HTMLElement.prototype.hidePopover=a;for(let[,e]of r)e();r.clear()}]});const f=()=>({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":["isBrowser","isSupported","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 {\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":"+IAuBIA,EAAAA,UAAU,GAAK,CAACC,EAAAA,YAAY,GAAG,EAAA,MAAgB,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,aAAeC,EAAAA,KAAK,EAAI,SAAS,IAAM,MAC5CC,EAAAA,WAAW,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,EAAaA,EAAAA,WAAW,EAAI,2BAA2B,EACvD,EAAYD,EAAAA,KAAK,EAAI,CAAU,GAAKA,EAAAA,KAAK,EAAQ,CAAU,GAAK,EAChE,EAAOA,EAAAA,KAAK,EAAI,CAAS,GAAKA,EAAAA,KAAK,EAAQ,CAAS,EACpD,EAAY,WAAWC,EAAAA,WAAW,EAA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AI,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
|
+
{"version":3,"file":"popover.cjs","names":["isBrowser","isSupported","isPolyfilled","getComposedTarget","attr","getCSSProp","getRoot","offset","shift","limitShift","flip","size","autoUpdate","computePosition","on","QUICK_EVENT","onHotReload"],"sources":["../../../src/popover/popover.ts"],"sourcesContent":["import type { ComputePositionConfig, MiddlewareState } from '@floating-ui/dom';\nimport {\n autoUpdate,\n computePosition,\n flip,\n limitShift,\n offset,\n shift,\n size,\n} from '@floating-ui/dom';\nimport {\n isPolyfilled,\n isSupported,\n apply as polyfillPopover,\n} from '@oddbird/popover-polyfill/fn';\nimport {\n attr,\n getComposedTarget,\n getCSSProp,\n getRoot,\n isBrowser,\n on,\n onHotReload,\n QUICK_EVENT,\n} from '../utils/utils';\n\nif (isBrowser() && !isSupported() && !isPolyfilled())\n polyfillPopover({ layerName: 'ds.base' }); // Load popover polyfill in the ds.base CSS layer to keep cascade order consistent with Designsystemet layers.\n\n// NOTE:\n// The native popover event \"toggle\" is not composed, meaning it does not bubble out of shadow DOM.\n// This means that if a popover is inside a shadow root, the toggle event will not be visible outside of that shadow root.\n// To handle this, we monkey-patch the showPopover and hidePopover methods to manually trigger the toggle-function.\n// We also bind toggle events to shadow roots found during click events, so that we can listen for toggle events on shadow roots as well.\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'ds-toggle-source': CustomEvent<Element>;\n }\n}\n\nconst ROOTS = new Map<ShadowRoot, () => void>();\nconst ATTR_PLACE = 'data-placement';\nconst ATTR_AUTO = 'data-autoplacement';\nconst POPOVERS = new Map<\n HTMLElement,\n { source: Element; cleanup: () => void }\n>();\n\n// Sometimes use \"ds-toggle\" event while waiting for better support of\n// event.source (https://developer.mozilla.org/en-US/docs/Web/API/ToggleEvent/source)\n\nconst handleToggle = (\n e: Event &\n Partial<ToggleEvent> & { detail?: HTMLElement; source?: HTMLElement },\n) => toggle(getComposedTarget(e), e.newState, e.oldState, e.source || e.detail);\n\nfunction toggle(\n el: Element | null,\n newState?: string,\n oldState?: string,\n source?: HTMLElement,\n) {\n const isPopover = el instanceof HTMLElement && attr(el, 'popover') !== null;\n const float = isPopover && getCSSProp(el, '--_ds-floating');\n const prev = POPOVERS.get(el as HTMLElement);\n\n if (newState === 'open' && prev && prev.source === source) return; // Prevent double binding\n prev?.cleanup(); // Cleanup if previously bound popover exists to avoid multiple autoUpdate memory leaks\n if (newState === 'closed' || !float) return;\n if (!source) {\n const css = el.id && `[popovertarget=\"${el.id}\"],[commandfor=\"${el.id}\"]`;\n source = (css && getRoot(el).querySelector<HTMLElement>(css)) || undefined; // Polyfill ToggleEvent .source for older browsers\n }\n if (!source || source === el || (oldState && oldState === newState)) return; // No need to update\n\n // Use scroll-margin-bottom to measure computed arrow-size property as this does\n // not affect layout or position, makes the browser calculate the pixel value instead\n // of returning the calc() (as it would if reading the --_ds-floating-arrow-size directly)\n // and makes it possible to read the value even if ::before is not used to draw the arrow.\n el.style.scrollMarginBottom = `var(--_ds-floating-arrow-size)`;\n\n const padding = 10;\n const overscroll = getCSSProp(el, '--_ds-floating-overscroll');\n const placement = attr(el, ATTR_PLACE) || attr(source, ATTR_PLACE) || float;\n const auto = attr(el, ATTR_AUTO) || attr(source, ATTR_AUTO);\n const arrowSize = parseFloat(getCSSProp(el, 'scroll-margin-bottom')) || 0;\n const shiftProp = placement.match(/left|right/gi) ? 'Height' : 'Width';\n const shiftLimit = source[`offset${shiftProp}`] / 2 + arrowSize;\n\n if (placement === 'none') return; // No need to position\n\n const options = {\n strategy: 'absolute',\n placement,\n middleware: [\n offset(arrowSize),\n shift({\n padding,\n limiter: limitShift({ offset: { mainAxis: shiftLimit } }), // Prevent from shifing away from source\n }),\n arrowPseudo(),\n ...(auto !== 'false' ? [flip({ padding, crossAxis: false })] : []),\n ...(overscroll\n ? [\n size({\n apply({ availableHeight }) {\n if (overscroll === 'fit')\n el.style.width = `${source.offsetWidth}px`; // Use offsetWidth to include padding, matching the width of the source element\n el.style.maxHeight = `${Math.max(50, availableHeight - padding * 2)}px`;\n },\n }),\n ]\n : []),\n ],\n } as ComputePositionConfig;\n const unfloat = autoUpdate(source, el, async () => {\n if (!source?.isConnected) return POPOVERS.get(el)?.cleanup(); // Cleanup if source element is removed\n const { x, y } = await computePosition(source, el, options);\n el.style.translate = `${x}px ${y}px`;\n });\n POPOVERS.set(el, {\n source,\n cleanup: () => POPOVERS.delete(el) && unfloat(),\n });\n}\n\n// Prevent closing when pointer interacts with scrollbar\nlet IS_SCROLL: boolean | undefined;\nconst handleScrollbar = (e: Event) => {\n if (e.type === 'pointerdown') {\n IS_SCROLL = false;\n }\n if (e.type === 'scroll' && IS_SCROLL === false) IS_SCROLL = true;\n if (e.type === 'pointerup' && IS_SCROLL)\n for (const [popover] of POPOVERS) popover.showPopover(); // Immediately show again to prevent flicker\n};\n\n// And add listeners for toggle event on shadowRoots as \"toggle\" is not a composed event\nconst handleClick = (e: Event) => {\n for (const [root, off] of ROOTS)\n if (!root.host?.isConnected && ROOTS.delete(root)) off(); // Prune roots whose host is no longer connected (e.g. removed custom elements) to avoid unbounded growth\n\n const root = getRoot(getComposedTarget(e));\n if (root instanceof ShadowRoot && !ROOTS.has(root))\n ROOTS.set(root, on(root, 'toggle', handleToggle, QUICK_EVENT));\n};\n\nonHotReload('popover', () => {\n const isFunction = (fn: unknown) => typeof fn === 'function';\n const togglePopover = HTMLElement.prototype.togglePopover;\n const showPopover = HTMLElement.prototype.showPopover;\n const hidePopover = HTMLElement.prototype.hidePopover;\n\n // Since toggle event is not composed, we need to trigger it when programatically called inside shadow DOM\n if (isFunction(togglePopover))\n HTMLElement.prototype.togglePopover = function (opt) {\n const isOpen = this.matches(':popover-open');\n const isBool = typeof opt === 'boolean';\n const prev = isOpen ? 'open' : 'closed';\n const next = (isBool ? opt : (opt?.force ?? !isOpen)) ? 'open' : 'closed';\n const source = isBool ? undefined : opt?.source;\n const result = togglePopover.call(this, opt as TogglePopoverOptions);\n toggle(this, next, prev, source);\n return result;\n };\n if (isFunction(showPopover))\n HTMLElement.prototype.showPopover = function (opt) {\n const prev = this.matches(':popover-open') ? 'open' : 'closed';\n const result = showPopover.call(this, opt);\n toggle(this, 'open', prev, opt?.source);\n return result;\n };\n if (isFunction(hidePopover))\n HTMLElement.prototype.hidePopover = function () {\n const prev = this.matches(':popover-open') ? 'open' : 'closed';\n const result = hidePopover.call(this);\n toggle(this, 'closed', prev);\n return result;\n };\n\n return [\n on(document, 'click', handleClick, QUICK_EVENT),\n on(document, 'pointerdown pointerup scroll', handleScrollbar, QUICK_EVENT),\n on(document, 'toggle ds-toggle-source', handleToggle, QUICK_EVENT), // Use capture since the toggle event does not bubble\n () => {\n HTMLElement.prototype.togglePopover = togglePopover; // Restore original methods on hot reload\n HTMLElement.prototype.showPopover = showPopover;\n HTMLElement.prototype.hidePopover = hidePopover;\n for (const [, off] of ROOTS) off(); // Cleanup listeners on ShadowRoots on hot reload\n ROOTS.clear();\n },\n ];\n});\n\nconst arrowPseudo = () => ({\n name: 'arrowPseudo',\n fn(data: MiddlewareState) {\n const target = data.elements.floating;\n const source = data.rects.reference;\n const x = `${Math.round(source.width / 2 + source.x - data.x)}px`;\n const y = `${Math.round(source.height / 2 + source.y - data.y)}px`;\n\n target.style.setProperty('--_ds-floating-arrow-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AA2B,EAAcC,EAAAA,WAAW,MAC3D,CACJ,YAAY,UAAU,cAAgB,EACtC,YAAY,UAAU,YAAc,EACpC,YAAY,UAAU,YAAc,EACpC,IAAK,GAAM,EAAG,KAAQ,EAAO,EAAI,EACjC,EAAM,MAAM,CACd,CACF,CACF,CAAC,EAED,MAAM,OAAqB,CACzB,KAAM,cACN,GAAG,EAAuB,CACxB,IAAM,EAAS,EAAK,SAAS,SACvB,EAAS,EAAK,MAAM,UACpB,EAAI,GAAG,KAAK,MAAM,EAAO,MAAQ,EAAI,EAAO,EAAI,EAAK,CAAC,EAAE,IACxD,EAAI,GAAG,KAAK,MAAM,EAAO,OAAS,EAAI,EAAO,EAAI,EAAK,CAAC,EAAE,IAK/D,OAHA,EAAO,MAAM,YAAY,yBAA0B,CAAC,EACpD,EAAO,MAAM,YAAY,yBAA0B,CAAC,EACpD,EAAA,KAAK,EAAQ,gBAAiB,EAAK,SAAS,EACrC,CACT,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../utils/utils.cjs"),t=t=>(t
|
|
1
|
+
const e=require("../utils/utils.cjs"),t=t=>e.attr(t,`readonly`)!==null||e.attr(t,`aria-readonly`)===`true`,n=e=>{(!(e.key===`Tab`||e.altKey||e.ctrlKey||e.metaKey)||e.key?.startsWith(`Arrow`))&&r(e)},r=n=>{let r=e.getComposedTarget(n);r?.nodeName===`SELECT`&&t(r)&&n.preventDefault()},i=e=>{for(let n of e.composedPath())if(n?.nodeName===`LABEL`&&(n=n.control),n?.nodeName===`INPUT`||n?.nodeName===`SELECT`){t(n)&&(e.stopImmediatePropagation(),e.preventDefault(),n[n.nodeName===`SELECT`?`blur`:`focus`](),requestAnimationFrame(()=>n.isConnected&&n.focus()));return}};e.onHotReload(`readonly`,()=>[e.on(document,`keydown`,n),e.on(document,`click`,i,!0),e.on(document,`mousedown`,r,!0)]);
|
|
2
2
|
//# sourceMappingURL=readonly.cjs.map
|
|
@@ -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:
|
|
1
|
+
{"version":3,"file":"readonly.cjs","names":["attr","getComposedTarget","onHotReload","on"],"sources":["../../../src/readonly/readonly.ts"],"sourcesContent":["import { attr, getComposedTarget, on, onHotReload } from '../utils/utils';\n\nconst isReadOnly = (el: Element) =>\n attr(el, 'readonly') !== null || attr(el, 'aria-readonly') === 'true';\n\nconst handleKeydown = (e: Event & Partial<KeyboardEvent>) => {\n const allow = e.key === 'Tab' || e.altKey || e.ctrlKey || e.metaKey; // Allow modifier keys so native functions like CMD + D to bookmark etc. still works\n if (!allow || e.key?.startsWith('Arrow')) handleSelect(e);\n};\n\nconst handleSelect = (e: Event) => {\n const el = getComposedTarget(e) as HTMLSelectElement | null;\n if (el?.nodeName === 'SELECT' && isReadOnly(el)) e.preventDefault();\n};\n\nconst handleClick = (e: Event) => {\n for (let el of e.composedPath() as HTMLLabelElement[]) {\n if (el?.nodeName === 'LABEL') el = el.control as HTMLLabelElement;\n if (el?.nodeName === 'INPUT' || el?.nodeName === 'SELECT') {\n if (isReadOnly(el)) {\n e.stopImmediatePropagation(); // Prevent click from reaching React and other listeners\n e.preventDefault();\n el[el.nodeName === 'SELECT' ? 'blur' : 'focus'](); // Blur select to prevent opening on mobile, focus input to recreate <label>-click behavior\n requestAnimationFrame(() => el.isConnected && el.focus()); // Move focus back to select after event has finished bubbling\n }\n return;\n }\n }\n};\n\nonHotReload('readonly', () => [\n on(document, 'keydown', handleKeydown),\n on(document, 'click', handleClick, true), // click needed for <label> and <input type=\"checkbox|radio\">, using capture to ensure we run before React\n on(document, 'mousedown', handleSelect, true), // needed for <select> on desktop\n]);\n"],"mappings":"sCAEM,EAAc,GAClBA,EAAAA,KAAK,EAAI,UAAU,IAAM,MAAQA,EAAAA,KAAK,EAAI,eAAe,IAAM,OAE3D,EAAiB,GAAsC,EAEvD,EADU,EAAE,MAAQ,OAAS,EAAE,QAAU,EAAE,SAAW,EAAE,UAC9C,EAAE,KAAK,WAAW,OAAO,IAAG,EAAa,CAAC,CAC1D,EAEM,EAAgB,GAAa,CACjC,IAAM,EAAKC,EAAAA,kBAAkB,CAAC,EAC1B,GAAI,WAAa,UAAY,EAAW,CAAE,GAAG,EAAE,eAAe,CACpE,EAEM,EAAe,GAAa,CAChC,IAAK,IAAI,KAAM,EAAE,aAAa,EAE5B,GADI,GAAI,WAAa,UAAS,EAAK,EAAG,SAClC,GAAI,WAAa,SAAW,GAAI,WAAa,SAAU,CACrD,EAAW,CAAE,IACf,EAAE,yBAAyB,EAC3B,EAAE,eAAe,EACjB,EAAG,EAAG,WAAa,SAAW,OAAS,QAAQ,CAAC,EAChD,0BAA4B,EAAG,aAAe,EAAG,MAAM,CAAC,GAE1D,MACF,CAEJ,EAEAC,EAAAA,YAAY,eAAkB,CAC5BC,EAAAA,GAAG,SAAU,UAAW,CAAa,EACrCA,EAAAA,GAAG,SAAU,QAAS,EAAa,EAAI,EACvCA,EAAAA,GAAG,SAAU,YAAa,EAAc,EAAI,CAC9C,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../utils/utils.cjs");let t=require("@u-elements/u-combobox");var
|
|
1
|
+
const e=require("../utils/utils.cjs");let t=require("@u-elements/u-combobox");const n=`data-empty`;var r=class extends t.UHTMLComboboxElement{_unmutate;connectedCallback(){super.connectedCallback(),this._unmutate=e.onMutation(this,i,{childList:!0}),e.on(this,`comboboxafterselect input`,a,e.QUICK_EVENT),e.on(this,`toggle`,o,e.QUICK_EVENT)}disconnectedCallback(){super.disconnectedCallback(),this._unmutate?.(),this._unmutate=void 0,e.off(this,`comboboxafterselect input`,a,e.QUICK_EVENT),e.off(this,`toggle`,o,e.QUICK_EVENT)}};const i=t=>{let{control:n,list:r}=t,i=r||t.querySelector(`u-datalist`);n&&(e.attr(n,`popovertarget`,r?e.useId(r):null),n.placeholder||e.attr(n,`placeholder`,` `)),i&&(e.attr(i,`popover`,`manual`),e.attr(i,`data-is-floating`,`true`))},a=({currentTarget:t})=>{let{creatable:r,control:i,options:a}=t;if(!a)return;let o=i?.value.trim()||``,s=o.toLowerCase(),c,l=!o;for(let e of a)if(!c&&e.hasAttribute(n)?c=e:!l&&e.label?.toLowerCase()===s&&(l=!0),l&&c)break;if(!c||(c.hidden=l,c.label=o,c.value=r?o:``,!r||c.textContent))return;let u=e.attrOrCSS(c,n);u?e.attr(c,n,u):e.warn(`Missing ${n} value on:`,c),e.attr(c,`data-create`,u?.replace(`{value}`,o))},o=e=>{let t=e.currentTarget,n=e.newState===`open`&&t.control;n&&t.list?.dispatchEvent(new CustomEvent(`ds-toggle-source`,{bubbles:!0,composed:!0,detail:n}))};e.customElements.define(`ds-suggestion`,r),exports.DSSuggestionElement=r;
|
|
2
2
|
//# sourceMappingURL=suggestion.cjs.map
|
|
@@ -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 = (self: DSSuggestionElement) => {\n const { control, list } = self;\n const datalist = list || self.querySelector('u-datalist'); // Fallback to u-datalist since React can render the ds-suggestion before u-datalist is connected\n\n if (control
|
|
1
|
+
{"version":3,"file":"suggestion.cjs","names":["UHTMLComboboxElement","onMutation","QUICK_EVENT","useId","attrOrCSS","customElements"],"sources":["../../../src/suggestion/suggestion.ts"],"sourcesContent":["import { UHTMLComboboxElement } from '@u-elements/u-combobox';\nimport {\n attr,\n attrOrCSS,\n customElements,\n off,\n on,\n onMutation,\n QUICK_EVENT,\n useId,\n warn,\n} from '../utils/utils';\n\nconst ATTR_EMPTY = 'data-empty';\nconst ATTR_CREATE = 'data-create';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ds-suggestion': DSSuggestionElement;\n }\n}\n\nexport class DSSuggestionElement extends UHTMLComboboxElement {\n _unmutate?: ReturnType<typeof onMutation>; // Using underscore instead of private fields for backwards compatibility\n\n connectedCallback() {\n super.connectedCallback();\n this._unmutate = onMutation(this, render, { childList: true }); // .control and .list are direct children of the custom element\n on(this, 'comboboxafterselect input', handleEmpty, QUICK_EVENT);\n on(this, 'toggle', polyfillToggleSource, QUICK_EVENT);\n }\n disconnectedCallback() {\n super.disconnectedCallback();\n this._unmutate?.();\n this._unmutate = undefined;\n off(this, 'comboboxafterselect input', handleEmpty, QUICK_EVENT);\n off(this, 'toggle', polyfillToggleSource, QUICK_EVENT);\n }\n}\n\n// A non-empty placeholder attribute is required to activate the :placeholder-shown pseudo selector used in our chevron styling\nconst render = (self: DSSuggestionElement) => {\n const { control, list } = self;\n const datalist = list || self.querySelector('u-datalist'); // Fallback to u-datalist since React can render the ds-suggestion before u-datalist is connected\n\n if (control) {\n attr(control, 'popovertarget', list ? useId(list) : null);\n if (!control.placeholder) attr(control, 'placeholder', ' '); // .control comes from UHTMLComboboxElement\n }\n if (datalist) {\n attr(datalist, 'popover', 'manual'); // Ensure popover attribute is set on the list\n attr(datalist, 'data-is-floating', 'true'); // identifier for css to toggle opacity when it is placed by floating-ui.\n }\n};\n\nconst handleEmpty = ({ currentTarget: self }: Event) => {\n const { creatable, control, options } = self as DSSuggestionElement;\n if (!options) return;\n\n const value = control?.value.trim() || '';\n const query = value.toLowerCase();\n let empty: HTMLOptionElement | undefined;\n let exists = !value;\n\n for (const opt of options) {\n if (!empty && opt.hasAttribute(ATTR_EMPTY)) empty = opt;\n else if (!exists && opt.label?.toLowerCase() === query) exists = true; // Prevent creating an option that already exists\n if (exists && empty) break; // Speed up if both conditions are met\n }\n if (!empty) return;\n\n empty.hidden = exists;\n empty.label = value; // Ensures option is not filtered out by <u-combobox>\n empty.value = creatable ? value : ''; // Ensures clicking option does nothing\n\n if (!creatable || empty.textContent) return;\n const text = attrOrCSS(empty, ATTR_EMPTY);\n if (!text) warn(`Missing ${ATTR_EMPTY} value on:`, empty);\n else attr(empty, ATTR_EMPTY, text); // Speed up by caching attribute value\n attr(empty, ATTR_CREATE, text?.replace('{value}', value));\n};\n\n// Since showPopover({ source }) is not supported in all browsers yet:\nconst polyfillToggleSource = (event: Partial<ToggleEvent>) => {\n const self = event.currentTarget as DSSuggestionElement;\n const detail = event.newState === 'open' && self.control; // .control comes from UHTMLComboboxElement\n\n if (detail)\n self.list?.dispatchEvent(\n new CustomEvent('ds-toggle-source', {\n bubbles: true,\n composed: true, // Enable bubbling out of shadow DOM boundaries\n detail, // Since showPopover({ source }) is not supported in all browsers yet\n }),\n );\n};\n\n// Ensure u-datalist is defined before ds-suggestion\ncustomElements.define('ds-suggestion', DSSuggestionElement);\n"],"mappings":"8EAaA,MAAM,EAAa,aASnB,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,4BAA6B,EAAaC,EAAAA,WAAW,EAC9D,EAAA,GAA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AO,EAAM,cACb,EAAS,EAAM,WAAa,QAAU,EAAK,QAE7C,GACF,EAAK,MAAM,cACT,IAAI,YAAY,mBAAoB,CAClC,QAAS,GACT,SAAU,GACV,QACF,CAAC,CACH,CACJ,EAGAC,EAAAA,eAAe,OAAO,gBAAiB,CAAmB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../utils/utils.cjs"),t=`
|
|
1
|
+
const e=require("../utils/utils.cjs"),t=`focusgroup`,n=`data-toggle-group`,r=`[${n}]`;let i;const a=(e,t)=>{for(let i of t||[null])if(i?.attributeName===n)u(i.target);else if(!i||i.addedNodes.length){let t=i?.target||e;for(let e of t.querySelectorAll(r))u(e)}},o=e=>{i&&l(e)&&(e.preventDefault(),e.stopImmediatePropagation())},s=()=>i=!1,c=e=>{i=e.key?.startsWith(`Arrow`),e.key===`Enter`&&l(e)?.click(),i&&setTimeout(s,0)},l=n=>{let r=e.getComposedTarget(n);if(!(r?.nodeName!==`INPUT`||r.type!==`radio`||!r.name)){for(let n of e.getComposedPath(r))if(!(n.nodeType!==1||!n.hasAttribute(t)))return e.attr(n,t)?.includes(`radiogroup`)?r:void 0}},u=r=>{if(r.hasAttribute(t))return;let i=e.attrOrCSS(r,n),a=e.attr(r,e.ARIA_LABELLEDBY)?.trim(),o=`Please use ${t}="radiogroup" and ${a?e.ARIA_LABELLEDBY:e.ARIA_LABEL}="${a||i}" instead of deprecated ${n} on:`;e.attr(r,e.ARIA_LABEL,a?null:i),e.attr(r,t,`radiogroup`),e.warn(o,r)};e.onHotReload(`toggle-group`,()=>[e.on(document,`click`,o,!0),e.on(document,`keydown`,c),e.onMutation(document,a,{attributeFilter:[n],attributes:!0,childList:!0,subtree:!0})]);
|
|
2
2
|
//# sourceMappingURL=toggle-group.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-group.cjs","names":["
|
|
1
|
+
{"version":3,"file":"toggle-group.cjs","names":["getComposedTarget","getComposedPath","attr","attrOrCSS","ARIA_LABELLEDBY","ARIA_LABEL","onHotReload","on","onMutation"],"sources":["../../../src/toggle-group/toggle-group.ts"],"sourcesContent":["import {\n ARIA_LABEL,\n ARIA_LABELLEDBY,\n attr,\n attrOrCSS,\n getComposedPath,\n getComposedTarget,\n on,\n onHotReload,\n onMutation,\n warn,\n} from '../utils/utils';\n\nconst ATTR_FOCUSGROUP = 'focusgroup';\nconst ATTR_TOGGLEGROUP = 'data-toggle-group';\nconst SELECTOR_TOGGLEGROUP = `[${ATTR_TOGGLEGROUP}]`;\nlet IS_ARROW: boolean | undefined; // Used to prevent clicks that are a result of keyboard navigation\n\nconst handleMutations = (root: Document, records?: MutationRecord[]) => {\n for (const r of records || [null]) {\n if (r?.attributeName === ATTR_TOGGLEGROUP) deprecate(r.target as Element);\n else if (!r || r.addedNodes.length) {\n const scope = (r?.target as Element) || root;\n for (const el of scope.querySelectorAll(SELECTOR_TOGGLEGROUP))\n deprecate(el);\n }\n }\n};\n\n// Prevent clicks that are a result of keyboard navigation\nconst handleRadioClick = (e: Event & Partial<PointerEvent>) => {\n if (IS_ARROW && getRadioInFocusGroup(e)) {\n e.preventDefault(); // Only handle clicks that are a result of keyboard navigation\n e.stopImmediatePropagation(); // Prevent stopped \"click\" from reaching React and other listeners\n }\n};\n\nconst resetIsArrow = () => (IS_ARROW = false);\nconst handleKeydown = (e: Event & Partial<KeyboardEvent>) => {\n IS_ARROW = e.key?.startsWith('Arrow');\n if (e.key === 'Enter') getRadioInFocusGroup(e)?.click(); // Allow Enter to activate the radio input\n if (IS_ARROW) setTimeout(resetIsArrow, 0); // Reset after event loop so we can check if next focus event is a result of arrow key navigation\n};\n\n// This function does not handle nested focusgroups, but toggle-groups should not be nested so this is not a problem\nconst getRadioInFocusGroup = (e: Event) => {\n const el = getComposedTarget(e) as HTMLInputElement | null;\n if (el?.nodeName !== 'INPUT' || el.type !== 'radio' || !el.name) return;\n for (const group of getComposedPath(el) as Set<Element>) {\n if (group.nodeType !== 1 || !group.hasAttribute(ATTR_FOCUSGROUP)) continue; // Ignore non-group nodes\n if (!attr(group, ATTR_FOCUSGROUP)?.includes('radiogroup')) return; // Ignore invalid groups\n return el;\n }\n};\n\nconst deprecate = (el: Element) => {\n if (el.hasAttribute(ATTR_FOCUSGROUP)) return; // Ignore if already migrated\n const label = attrOrCSS(el, ATTR_TOGGLEGROUP);\n const labelledby = attr(el, ARIA_LABELLEDBY)?.trim();\n const message = `Please use ${ATTR_FOCUSGROUP}=\"radiogroup\" and ${labelledby ? ARIA_LABELLEDBY : ARIA_LABEL}=\"${labelledby || label}\" instead of deprecated ${ATTR_TOGGLEGROUP} on:`;\n\n attr(el, ARIA_LABEL, labelledby ? null : label);\n attr(el, ATTR_FOCUSGROUP, 'radiogroup');\n warn(message, el);\n};\n\nonHotReload('toggle-group', () => [\n on(document, 'click', handleRadioClick, true), // Use capture to ensure we run before React and other listeners\n on(document, 'keydown', handleKeydown),\n onMutation(document, handleMutations, {\n attributeFilter: [ATTR_TOGGLEGROUP],\n attributes: true,\n childList: true,\n subtree: true,\n }),\n]);\n"],"mappings":"sCAaM,EAAkB,aAClB,EAAmB,oBACnB,EAAuB,IAAI,EAAiB,GAClD,IAAI,EAEJ,MAAM,GAAmB,EAAgB,IAA+B,CACtE,IAAK,IAAM,KAAK,GAAW,CAAC,IAAI,EAC9B,GAAI,GAAG,gBAAkB,EAAkB,EAAU,EAAE,MAAiB,OACnE,GAAI,CAAC,GAAK,EAAE,WAAW,OAAQ,CAClC,IAAM,EAAS,GAAG,QAAsB,EACxC,IAAK,IAAM,KAAM,EAAM,iBAAiB,CAAoB,EAC1D,EAAU,CAAE,CAChB,CAEJ,EAGM,EAAoB,GAAqC,CACzD,GAAY,EAAqB,CAAC,IACpC,EAAE,eAAe,EACjB,EAAE,yBAAyB,EAE/B,EAEM,MAAsB,EAAW,GACjC,EAAiB,GAAsC,CAC3D,EAAW,EAAE,KAAK,WAAW,OAAO,EAChC,EAAE,MAAQ,SAAS,EAAqB,CAAC,CAAC,EAAE,MAAM,EAClD,GAAU,WAAW,EAAc,CAAC,CAC1C,EAGM,EAAwB,GAAa,CACzC,IAAM,EAAKA,EAAAA,kBAAkB,CAAC,EAC1B,QAAI,WAAa,SAAW,EAAG,OAAS,SAAW,CAAC,EAAG,MAC3D,KAAK,IAAM,KAASC,EAAAA,gBAAgB,CAAE,EAChC,OAAM,WAAa,GAAK,CAAC,EAAM,aAAa,CAAe,GAE/D,OADKC,EAAAA,KAAK,EAAO,CAAe,CAAC,EAAE,SAAS,YAAY,EACjD,EADoD,MAE7D,CACF,EAEM,EAAa,GAAgB,CACjC,GAAI,EAAG,aAAa,CAAe,EAAG,OACtC,IAAM,EAAQC,EAAAA,UAAU,EAAI,CAAgB,EACtC,EAAaD,EAAAA,KAAK,EAAIE,EAAAA,eAAe,CAAC,EAAE,KAAK,EAC7C,EAAU,cAAc,EAAgB,oBAAoB,EAAaA,EAAAA,gBAAkBC,EAAAA,WAAW,IAAI,GAAc,EAAM,0BAA0B,EAAiB,MAE/K,EAAA,KAAK,EAAIA,EAAAA,WAAY,EAAa,KAAO,CAAK,EAC9C,EAAA,KAAK,EAAI,EAAiB,YAAY,EACtC,EAAA,KAAK,EAAS,CAAE,CAClB,EAEAC,EAAAA,YAAY,mBAAsB,CAChCC,EAAAA,GAAG,SAAU,QAAS,EAAkB,EAAI,EAC5CA,EAAAA,GAAG,SAAU,UAAW,CAAa,EACrCC,EAAAA,WAAW,SAAU,EAAiB,CACpC,gBAAiB,CAAC,CAAgB,EAClC,WAAY,GACZ,UAAW,GACX,QAAS,EACX,CAAC,CACH,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../utils/utils.cjs");require("../popover/popover.cjs");let t,n,r
|
|
1
|
+
const e=require("../utils/utils.cjs");require("../popover/popover.cjs");let t,n,r,i,a=0;const o=`data-color`,s=`data-color-scheme`,c=`data-size`,l=`data-tooltip`,u=e.isBrowser()&&/iPad|iPhone|iPod/.test(navigator.userAgent),d=`[${o}]`,f=`[${s}]`,p=`[${c}]`,m=`[${l}]`,h=n=>{n&&!(n instanceof HTMLElement)&&e.warn(`setTooltipElement expects an HTMLElement, got: `,n),x(),a=0,t=n||void 0},g=(e=document)=>{for(let t of e?.querySelectorAll(m)||[])v(t)},_=(e,n)=>{if(!n)return g();for(let e of n)if(e.target!==t)if(e.attributeName===l)v(e.target);else for(let t of e.addedNodes)t.nodeType===1&&(t.hasAttribute(l)?v(t):g(t))},v=(n,r=!0)=>{let a=e.attrOrCSS(n,l)||``;if(a[0]===`#`&&(a=e.getRoot(n).getElementById(a.slice(1))?.textContent?.trim()||``),a!==(n.getAttribute(`aria-label`)||n.getAttribute(`aria-description`))){let t=e.attr(n,`role`)!==`img`&&n.textContent?.trim();e.attr(n,l,a),e.attr(n,e.ARIA_LABEL,t?null:a),e.attr(n,e.ARIA_DESC,t?a:null),n.tabIndex===-1&&e.warn(`Missing tabindex="0" attribute on: `,n)}n===i&&t?.textContent!==a&&(t&&(t.textContent=a),a&&r&&document.activeElement===n&&e.announce(a))},y=o=>{let s=e.getComposedTarget(o);if(!s||r===s||t?.contains(s))return;r=s;let c=r?.closest?.(m)||void 0;if(i!==c&&(i&&x(),i=c,c)){if(o.type===`focus`||u||300>Date.now()-a)return b();o.type===`mousemove`&&(n=setTimeout(b,300))}},b=()=>{if(!i)return x();t||=e.tag(`div`,{class:`ds-tooltip`}),t.isConnected||document.body.appendChild(t);let n=i.closest(d),r=i.closest(f),a=i.closest(p),l=n!==r&&n?.contains(r);e.attr(t,`popover`,`manual`),e.attr(t,s,r?.getAttribute(s)||null),e.attr(t,o,l&&n?.getAttribute(o)||null),e.attr(t,c,a?.getAttribute(c)||null),v(i,!1),t.showPopover(),t.dispatchEvent(new CustomEvent(`ds-toggle-source`,{bubbles:!0,composed:!0,detail:i}))},x=e=>{(e?.type!==`keydown`||e?.key===`Escape`)&&(i&&t?.isConnected&&t.popover&&t.hidePopover(),e||(a=Date.now()),clearTimeout(n),i=void 0)};e.onHotReload(`tooltip`,()=>[e.on(document,`focus mousemove`,y,e.QUICK_EVENT),e.on(document,`keydown`,x,e.QUICK_EVENT),e.onMutation(document,_,{attributeFilter:[l],attributes:!0,childList:!0,subtree:!0})]),exports.initTooltips=g,exports.setTooltipElement=h;
|
|
2
2
|
//# sourceMappingURL=tooltip.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.cjs","names":["isBrowser","attrOrCSS","attr","tag","onHotReload","on","QUICK_EVENT","onMutation"],"sources":["../../../src/tooltip/tooltip.ts"],"sourcesContent":["import '../popover/popover'; // Ensure popover is imported when using individual imports, since tooltip relies on it\nimport {\n 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
|
|
1
|
+
{"version":3,"file":"tooltip.cjs","names":["isBrowser","attrOrCSS","getRoot","attr","ARIA_LABEL","ARIA_DESC","getComposedTarget","tag","onHotReload","on","QUICK_EVENT","onMutation"],"sources":["../../../src/tooltip/tooltip.ts"],"sourcesContent":["import '../popover/popover'; // Ensure popover is imported when using individual imports, since tooltip relies on it\nimport {\n ARIA_DESC,\n ARIA_LABEL,\n announce,\n attr,\n attrOrCSS,\n getComposedTarget,\n getRoot,\n isBrowser,\n on,\n onHotReload,\n onMutation,\n QUICK_EVENT,\n tag,\n warn,\n} from '../utils/utils';\n\nlet TIP: HTMLElement | undefined;\nlet TIMER: ReturnType<typeof setTimeout> | undefined;\nlet TARGET: Element | undefined; // Used to speed up mousemove handling\nlet OPEN: Element | undefined;\nlet LAST_HIDE = 0;\nconst ATTR_COLOR = 'data-color';\nconst ATTR_SCHEME = 'data-color-scheme';\nconst ATTR_SIZE = 'data-size';\nconst ATTR_TOOLTIP = 'data-tooltip';\nconst DELAY_HOVER = 300;\nconst DELAY_SKIP = 300;\nconst IS_IOS = isBrowser() && /iPad|iPhone|iPod/.test(navigator.userAgent); // Needed to omit DELAY_HOVER since iOS triggers mousemove before click\nconst SELECTOR_COLOR = `[${ATTR_COLOR}]`;\nconst SELECTOR_SCHEME = `[${ATTR_SCHEME}]`;\nconst SELECTOR_SIZE = `[${ATTR_SIZE}]`;\nconst SELECTOR_TOOLTIP = `[${ATTR_TOOLTIP}]`;\n\n/**\n * setTooltipElement\n * @description Allows setting a custom tooltip element. It does not need to, and should not, be injected to document.body, as we inject on hover to ensure React hydration works as expected.\n * @param el The HTMLElement to use as tooltip\n */\nexport const setTooltipElement = (el?: HTMLElement | null) => {\n if (el && !(el instanceof HTMLElement))\n warn('setTooltipElement expects an HTMLElement, got: ', el);\n hide(); // Reset when changing source\n LAST_HIDE = 0; // Reset last hide time to re-enable delay\n TIP = el || undefined;\n};\n\nexport const initTooltips = (\n scope: Element | ShadowRoot | Document | null = document,\n) => {\n for (const el of scope?.querySelectorAll(SELECTOR_TOOLTIP) || [])\n setupText(el);\n};\n\n// Initial run has no MutationRecords, so we set records to [null] to ensure we run the querySelectorAll for any existing elements with data-tooltip\nconst handleMutations = (_: Document, records?: MutationRecord[]) => {\n if (!records) return initTooltips();\n for (const r of records) {\n if (r.target === TIP) continue; // Ignore mutations on tooltip itself\n if (r.attributeName === ATTR_TOOLTIP) setupText(r.target as Element);\n else\n for (const el of r.addedNodes as NodeListOf<Element>) {\n if (el.nodeType !== 1) continue;\n if (el.hasAttribute(ATTR_TOOLTIP)) setupText(el);\n else initTooltips(el); // Check for any child elements with data-tooltip\n }\n }\n};\n\nconst setupText = (el: Element, canAnnounce = true) => {\n let text = attrOrCSS(el, ATTR_TOOLTIP) || '';\n\n // Allow using another element as source.\n // Note: Only checks on initial mutation, as we do not want to keep checking if the source element is removed or changed,\n // since this would be a performance issue. If the source element is removed, the tooltip will be empty and not shown.\n if (text[0] === '#')\n text = getRoot(el).getElementById(text.slice(1))?.textContent?.trim() || '';\n\n if (text !== (el.getAttribute(ARIA_LABEL) || el.getAttribute(ARIA_DESC))) {\n const hasText = attr(el, 'role') !== 'img' && el.textContent?.trim(); // If role=\"img\", ignore text\n attr(el, ATTR_TOOLTIP, text); // Set data-tooltip attribute to speed up future mutations\n attr(el, ARIA_LABEL, hasText ? null : text); // Set aria-label if element does not have text\n attr(el, ARIA_DESC, hasText ? text : null); // Set aria-description if element has text\n if ((el as HTMLElement).tabIndex === -1)\n warn('Missing tabindex=\"0\" attribute on: ', el);\n }\n if (el === OPEN && TIP?.textContent !== text) {\n if (TIP) TIP.textContent = text; // Update tooltip text if it is already open\n if (text && canAnnounce && document.activeElement === el) announce(text); // Only announce if focus is on the source\n }\n};\n\nconst handleInterest = (e: Event) => {\n const target = getComposedTarget(e);\n if (!target || TARGET === target || TIP?.contains(target as Node)) return; // Same target, or allow tooltip to be hovered (following https://www.w3.org/TR/WCAG21/#content-on-hover-or-focus)\n TARGET = target;\n\n const source = TARGET?.closest?.(SELECTOR_TOOLTIP) || undefined;\n if (OPEN === source) return; // Same source, no need to update\n if (OPEN) hide(); // Reset previous tooltip, since we are moving to a new source\n OPEN = source;\n\n if (!source) return; // No source, no need to show tooltip\n if (e.type === 'focus' || IS_IOS || DELAY_SKIP > Date.now() - LAST_HIDE)\n return show(); // Instantly show if focus or if we just closed a tooltip\n if (e.type === 'mousemove') TIMER = setTimeout(show, DELAY_HOVER); // Delay mouse showing tooltip if not already shown\n};\n\nconst show = () => {\n if (!OPEN) return hide(); // If no new anchor, cleanup previous autoUpdate\n if (!TIP) TIP = tag('div', { class: 'ds-tooltip' });\n if (!TIP.isConnected) document.body.appendChild(TIP);\n\n const color = OPEN.closest(SELECTOR_COLOR); // Match source color of source element\n const scheme = OPEN.closest(SELECTOR_SCHEME); // Match source color-scheme of source element\n const size = OPEN.closest(SELECTOR_SIZE); // Match source size of source element\n const isReset = color !== scheme && color?.contains(scheme as Node); // If data-scheme is closer to target, it will reset data-color\n\n attr(TIP, 'popover', 'manual'); // Ensure popover behavior\n attr(TIP, ATTR_SCHEME, scheme?.getAttribute(ATTR_SCHEME) || null); // Fallback to null to reset if not scheme found\n attr(TIP, ATTR_COLOR, (isReset && color?.getAttribute(ATTR_COLOR)) || null); // Fallback to null to reset if not scheme found\n attr(TIP, ATTR_SIZE, size?.getAttribute(ATTR_SIZE) || null); // Fallback to null to reset if not size found\n setupText(OPEN, false); // If mutation observer is not triggered, ensure tooltip text is updated\n TIP.showPopover();\n TIP.dispatchEvent(\n new CustomEvent('ds-toggle-source', {\n bubbles: true,\n composed: true, // Enable bubbling out of shadow DOM boundaries\n detail: OPEN, // Since showPopover({ source }) is not supported in all browsers yet\n }),\n );\n};\n\nconst hide = (event?: Partial<KeyboardEvent>) => {\n if (event?.type === 'keydown' && event?.key !== 'Escape') return;\n if (OPEN && TIP?.isConnected && TIP.popover) TIP.hidePopover(); // Only hide if connected and activated\n if (!event) LAST_HIDE = Date.now(); // If closing with keyboard, do not show next tooltip instantly\n clearTimeout(TIMER);\n OPEN = undefined;\n};\n\nonHotReload('tooltip', () => [\n on(document, 'focus mousemove', handleInterest, QUICK_EVENT),\n on(document, 'keydown', hide, QUICK_EVENT),\n onMutation(document, handleMutations, {\n attributeFilter: [ATTR_TOOLTIP],\n attributes: true,\n childList: true,\n subtree: true,\n }),\n]);\n"],"mappings":"wEAkBA,IAAI,EACA,EACA,EACA,EACA,EAAY,EAChB,MAAM,EAAa,aACb,EAAc,oBACd,EAAY,YACZ,EAAe,eAGf,EAASA,EAAAA,UAAU,GAAK,mBAAmB,KAAK,UAAU,SAAS,EACnE,EAAiB,IAAI,EAAW,GAChC,EAAkB,IAAI,EAAY,GAClC,EAAgB,IAAI,EAAU,GAC9B,EAAmB,IAAI,EAAa,GAO7B,EAAqB,GAA4B,CACxD,GAAM,EAAE,aAAc,cACxB,EAAA,KAAK,kDAAmD,CAAE,EAC5D,EAAK,EACL,EAAY,EACZ,EAAM,GAAM,IAAA,EACd,EAEa,GACX,EAAgD,WAC7C,CACH,IAAK,IAAM,KAAM,GAAO,iBAAiB,CAAgB,GAAK,CAAC,EAC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js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={passive:!0,capture:!0},
|
|
1
|
+
const e=require("../packages/web/package.cjs"),t={passive:!0,capture:!0},n=()=>typeof window<`u`&&typeof document<`u`,r=()=>n()&&/^Win/i.test(navigator.userAgentData?.platform||navigator.platform),i=typeof HTMLElement>`u`?class{}:HTMLElement;function a(e,t){let n;return function(...r){clearTimeout(n),n=setTimeout(()=>e.apply(this,r),t)}}const o=(e,...t)=>!n()||window.dsWarnings===!1||console.log(`\x1B[1mDesignsystemet:\x1B[m ${e}`,...t),s=(e,t,n)=>n===void 0?e.getAttribute(t):(n===null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n),null),c=(e,t)=>getComputedStyle(e).getPropertyValue(t).trim(),l=/^["']|["']$/g,u=(e,t)=>{let n=s(e,t);return n||=c(e,`--_ds-${t}`).replace(l,``).trim(),n||null},d=e=>{let t=e?.getRootNode?.()||e?.ownerDocument;return t instanceof Document||t instanceof ShadowRoot?t:e?.ownerDocument||document},f=e=>{let t=e.target?.shadowRoot&&e.composedPath()[0]||e.target;return t?.nodeType===1?t:null},p=e=>{let t=new Set;for(;e;)t.add(e),e=e.nodeType===11?e.host:e.assignedSlot||e.parentNode;return t},m=(e,...t)=>{let[n,...r]=t;for(let t of n.split(` `))e.addEventListener(t,...r);return()=>h(e,...t)},h=(e,...t)=>{let[n,...r]=t;for(let t of n.split(` `))e.removeEventListener(t,...r)},g=`_dsHotReloadCleanup${e.version}`,_=(e,t)=>{if(n()){window[g]||(window[g]=new Map);for(let t of window[g]?.get(e)||[])t();window[g]?.set(e,t())}},v=(e,t,r)=>{let i=()=>a.disconnect(),a=new MutationObserver(r=>{if(!n()||!e.isConnected)return i();t(e,r)});return t(e),a.observe(e,r),i},y=(e,t)=>{let n=document.createElement(e);if(t)for(let[e,r]of Object.entries(t))s(n,e,r);return n},b={define:(e,t)=>!n()||window.customElements.get(e)||window.customElements.define(e,t)};let x=0;function S(e){return n()?(window.dsUseId||(window.dsUseId=0),e&&!e.id&&(e.id=`:ds:${++window.dsUseId}`),e?.id||``):`:ds:${++x}`}let C,w=0,T=0;const E=e=>{clearTimeout(T),C&&(C.textContent=`${e}${w++%2?`\xA0`:``}`),e&&(T=setTimeout(E,2e3,``))},D=()=>{document.readyState===`complete`&&(C||(C=y(`div`,{"aria-live":`assertive`}),C.style.overflow=`hidden`,C.style.position=`fixed`,C.style.whiteSpace=`nowrap`,C.style.width=`1px`),C.isConnected||document.body.appendChild(C))};_(`announce`,()=>[m(document,`focus mouseover`,D,t)]),exports.ARIA_DESC=`aria-description`,exports.ARIA_LABEL=`aria-label`,exports.ARIA_LABELLEDBY=`aria-labelledby`,exports.DSElement=i,exports.QUICK_EVENT=t,exports.announce=E,exports.attr=s,exports.attrOrCSS=u,exports.customElements=b,exports.debounce=a,exports.getCSSProp=c,exports.getComposedPath=p,exports.getComposedTarget=f,exports.getRoot=d,exports.isBrowser=n,exports.isWindows=r,exports.off=h,exports.on=m,exports.onHotReload=_,exports.onMutation=v,exports.tag=y,exports.useId=S,exports.warn=o;
|
|
2
2
|
//# sourceMappingURL=utils.cjs.map
|
|
@@ -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,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,IAAW,GAAG,CAAI,EASnD,GACX,EACA,EACA,IAEI,IAAU,IAAA,GAAkB,EAAG,aAAa,CAAI,GAAK,MACrD,IAAU,KAAM,EAAG,gBAAgB,CAAI,EAClC,EAAG,aAAa,CAAI,IAAM,GAAO,EAAG,aAAa,EAAM,CAAK,EAC9D,MAUI,GAAc,EAAa,IACtC,iBAAiB,CAAE,CAAC,CAAC,iBAAiB,CAAI,CAAC,CAAC,KAAK,EAE7C,EAAe,eAQR,GAAa,EAAa,IAAiB,CACtD,IAAI,EAAQ,EAAK,EAAI,CAAI,EAIzB,MAHA,CACE,IAAQ,EAAW,EAAI,SAAS,GAAM,CAAC,CAAC,QAAQ,EAAc,EAAE,CAAC,CAAC,KAAK,EACpE,GAAO,EAAK,WAAW,EAAK,MAAO,CAAE,EACnC,GAAS,IAClB,EAQa,GACX,EACA,GAAG,IACc,CACjB,GAAM,CAAC,EAAO,GAAG,GAAW,EAC5B,IAAK,IAAM,KAAQ,EAAM,MA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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"}
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":["version"],"sources":["../../../src/utils/utils.ts"],"sourcesContent":["export const ARIA_DESC = 'aria-description';\nexport const ARIA_LABEL = 'aria-label';\nexport const ARIA_LABELLEDBY = 'aria-labelledby';\nexport const QUICK_EVENT = { passive: true, capture: true };\n\nimport { version } from '../../package.json' with { type: 'json' };\n\n// Using function instead of constant to support environments 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);\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 return value || null;\n};\n\n/**\n * getRoot\n * @description Helper for better compatibility\n * @param node The target node\n * @return The shadow root or document\n */\nexport const getRoot = (node?: Node | null): Document | ShadowRoot => {\n const root = node?.getRootNode?.() || node?.ownerDocument;\n if (root instanceof Document || root instanceof ShadowRoot) return root;\n return node?.ownerDocument || document;\n};\n\n/**\n * getComposedTarget\n * @description Helper to get the composed target of an event, supporting ShadowDOM rendering\n * @param event The event\n * @return The target Element\n */\nexport const getComposedTarget = (e: Event): Element | null => {\n const el =\n ((e.target as Element)?.shadowRoot && e.composedPath()[0]) || e.target; // Only use composedPath if the target has a shadowRoot to boost performance\n return (el as Node)?.nodeType === 1 ? (el as Element) : null;\n};\n\n/**\n * getComposedPath\n * @description Helper to get the full composed path even if listener is bound to a ShadowRoot (unlike event.composedPath())\n * @param el The element to start traversing from\n * @return Set of nodes in the path\n */\nexport const getComposedPath = (el: Node | null) => {\n const path = new Set<Node>();\n while (el) {\n path.add(el);\n if (el.nodeType === 11) el = (el as ShadowRoot).host;\n else el = (el as Element).assignedSlot || el.parentNode;\n }\n return path;\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\nconst HOT_RELOAD_KEY = `_dsHotReloadCleanup${version}` as const; // Ensure multiple versions of Designsystemet can run on same page\ndeclare global {\n interface Window {\n [HOT_RELOAD_KEY]?: 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[HOT_RELOAD_KEY]) window[HOT_RELOAD_KEY] = new Map(); // Hot reload cleanup support supporting all build tools\n for (const cleanup of window[HOT_RELOAD_KEY]?.get(key) || []) cleanup(); // Run previous cleanup\n window[HOT_RELOAD_KEY]?.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":"+CAGa,EAAc,CAAE,QAAS,GAAM,QAAS,EAAK,EAK7C,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,IAAW,GAAG,CAAI,EASnD,GACX,EACA,EACA,IAEI,IAAU,IAAA,GAAkB,EAAG,aAAa,CAAI,GAChD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