@digdir/designsystemet-web 0.0.0-chore-remove-cli-tsx-20260701060359

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +333 -0
  3. package/dist/cjs/_vendors/@oddbird/popover-polyfill/dist/popover-fn.cjs +64 -0
  4. package/dist/cjs/_vendors/@oddbird/popover-polyfill/dist/popover-fn.cjs.map +1 -0
  5. package/dist/cjs/_vendors/invokers-polyfill/invoker.cjs +2 -0
  6. package/dist/cjs/_vendors/invokers-polyfill/invoker.cjs.map +1 -0
  7. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -0
  8. package/dist/cjs/breadcrumbs/breadcrumbs.cjs +2 -0
  9. package/dist/cjs/breadcrumbs/breadcrumbs.cjs.map +1 -0
  10. package/dist/cjs/clickdelegatefor/clickdelegatefor.cjs +2 -0
  11. package/dist/cjs/clickdelegatefor/clickdelegatefor.cjs.map +1 -0
  12. package/dist/cjs/details/details.cjs +1 -0
  13. package/dist/cjs/dialog/dialog.cjs +2 -0
  14. package/dist/cjs/dialog/dialog.cjs.map +1 -0
  15. package/dist/cjs/error-summary/error-summary.cjs +3 -0
  16. package/dist/cjs/error-summary/error-summary.cjs.map +1 -0
  17. package/dist/cjs/field/field.cjs +2 -0
  18. package/dist/cjs/field/field.cjs.map +1 -0
  19. package/dist/cjs/fieldset/fieldset.cjs +2 -0
  20. package/dist/cjs/fieldset/fieldset.cjs.map +1 -0
  21. package/dist/cjs/index.cjs +1 -0
  22. package/dist/cjs/invokers/invokers.cjs +2 -0
  23. package/dist/cjs/invokers/invokers.cjs.map +1 -0
  24. package/dist/cjs/pagination/pagination.cjs +2 -0
  25. package/dist/cjs/pagination/pagination.cjs.map +1 -0
  26. package/dist/cjs/popover/popover.cjs +2 -0
  27. package/dist/cjs/popover/popover.cjs.map +1 -0
  28. package/dist/cjs/readonly/readonly.cjs +2 -0
  29. package/dist/cjs/readonly/readonly.cjs.map +1 -0
  30. package/dist/cjs/suggestion/suggestion.cjs +2 -0
  31. package/dist/cjs/suggestion/suggestion.cjs.map +1 -0
  32. package/dist/cjs/tabs/tabs.cjs +2 -0
  33. package/dist/cjs/tabs/tabs.cjs.map +1 -0
  34. package/dist/cjs/toggle-group/toggle-group.cjs +2 -0
  35. package/dist/cjs/toggle-group/toggle-group.cjs.map +1 -0
  36. package/dist/cjs/tooltip/tooltip.cjs +2 -0
  37. package/dist/cjs/tooltip/tooltip.cjs.map +1 -0
  38. package/dist/cjs/utils/utils.cjs +2 -0
  39. package/dist/cjs/utils/utils.cjs.map +1 -0
  40. package/dist/custom-elements.json +542 -0
  41. package/dist/esm/_vendors/@oddbird/popover-polyfill/dist/popover-fn.js +64 -0
  42. package/dist/esm/_vendors/@oddbird/popover-polyfill/dist/popover-fn.js.map +1 -0
  43. package/dist/esm/_vendors/invokers-polyfill/invoker.js +2 -0
  44. package/dist/esm/_vendors/invokers-polyfill/invoker.js.map +1 -0
  45. package/dist/esm/breadcrumbs/breadcrumbs.js +2 -0
  46. package/dist/esm/breadcrumbs/breadcrumbs.js.map +1 -0
  47. package/dist/esm/clickdelegatefor/clickdelegatefor.js +2 -0
  48. package/dist/esm/clickdelegatefor/clickdelegatefor.js.map +1 -0
  49. package/dist/esm/details/details.js +1 -0
  50. package/dist/esm/dialog/dialog.js +2 -0
  51. package/dist/esm/dialog/dialog.js.map +1 -0
  52. package/dist/esm/error-summary/error-summary.js +3 -0
  53. package/dist/esm/error-summary/error-summary.js.map +1 -0
  54. package/dist/esm/field/field.js +2 -0
  55. package/dist/esm/field/field.js.map +1 -0
  56. package/dist/esm/fieldset/fieldset.js +2 -0
  57. package/dist/esm/fieldset/fieldset.js.map +1 -0
  58. package/dist/esm/index.js +1 -0
  59. package/dist/esm/invokers/invokers.js +2 -0
  60. package/dist/esm/invokers/invokers.js.map +1 -0
  61. package/dist/esm/pagination/pagination.js +2 -0
  62. package/dist/esm/pagination/pagination.js.map +1 -0
  63. package/dist/esm/popover/popover.js +2 -0
  64. package/dist/esm/popover/popover.js.map +1 -0
  65. package/dist/esm/readonly/readonly.js +2 -0
  66. package/dist/esm/readonly/readonly.js.map +1 -0
  67. package/dist/esm/suggestion/suggestion.js +2 -0
  68. package/dist/esm/suggestion/suggestion.js.map +1 -0
  69. package/dist/esm/tabs/tabs.js +2 -0
  70. package/dist/esm/tabs/tabs.js.map +1 -0
  71. package/dist/esm/toggle-group/toggle-group.js +2 -0
  72. package/dist/esm/toggle-group/toggle-group.js.map +1 -0
  73. package/dist/esm/tooltip/tooltip.js +2 -0
  74. package/dist/esm/tooltip/tooltip.js.map +1 -0
  75. package/dist/esm/utils/utils.js +2 -0
  76. package/dist/esm/utils/utils.js.map +1 -0
  77. package/dist/index.d.ts +351 -0
  78. package/dist/index.d.ts.map +1 -0
  79. package/dist/index.js +1584 -0
  80. package/dist/index.js.map +1 -0
  81. package/dist/umd/index.js +83 -0
  82. package/dist/umd/index.js.map +1 -0
  83. package/dist/vscode.html-custom-data.json +60 -0
  84. package/package.json +132 -0
package/dist/index.js ADDED
@@ -0,0 +1,1584 @@
1
+ import "@u-elements/u-details/polyfill";
2
+ import { autoUpdate, computePosition, flip, limitShift, offset, shift, size } from "@floating-ui/dom";
3
+ import { UHTMLComboboxElement } from "@u-elements/u-combobox";
4
+ import * as UTabs from "@u-elements/u-tabs";
5
+ export * from "@u-elements/u-datalist";
6
+ //#region src/utils/utils.ts
7
+ const QUICK_EVENT = {
8
+ passive: true,
9
+ capture: true
10
+ };
11
+ const isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined";
12
+ const isWindows = () => isBrowser() && /^Win/i.test(navigator.userAgentData?.platform || navigator.platform);
13
+ const DSElement = typeof HTMLElement === "undefined" ? class {} : HTMLElement;
14
+ function debounce(callback, delay) {
15
+ let timer;
16
+ return function(...args) {
17
+ clearTimeout(timer);
18
+ timer = setTimeout(() => callback.apply(this, args), delay);
19
+ };
20
+ }
21
+ const warn = (message, ...args) => !isBrowser() || window.dsWarnings === false || console.log(`\x1B[1mDesignsystemet:\x1B[m ${message}`, ...args);
22
+ /**
23
+ * attr
24
+ * @description Utility to quickly get, set and remove attributes
25
+ * @param el The Element to read/write attributes from
26
+ * @param name The attribute name to get, set or remove, or a object to set multiple attributes
27
+ * @param value A valid attribute value or null to remove attribute
28
+ */
29
+ const attr = (el, name, value) => {
30
+ if (value === void 0) return el.getAttribute(name) ?? null;
31
+ if (value === null) el.removeAttribute(name);
32
+ else if (el.getAttribute(name) !== value) el.setAttribute(name, value);
33
+ return null;
34
+ };
35
+ /**
36
+ * getCSSProp
37
+ * @description Retrieves and CSS property value and trims it
38
+ * @param el The Element to read attributes/CSS from
39
+ * @param name Attribute or CSS property to get
40
+ * @return string CSS property value
41
+ */
42
+ const getCSSProp = (el, prop) => getComputedStyle(el).getPropertyValue(prop).trim();
43
+ const STRIP_QUOTES = /^["']|["']$/g;
44
+ /**
45
+ * attrOrCSS
46
+ * @description Retrieves and updates attribute based on attribute or CSS property value
47
+ * @param el The Element to read attributes/CSS from
48
+ * @param name Attribute or CSS property to get
49
+ * @return string attribute or CSS property value
50
+ */
51
+ const attrOrCSS = (el, name) => {
52
+ let value = attr(el, name);
53
+ if (!value) value = getCSSProp(el, `--_ds-${name}`).replace(STRIP_QUOTES, "").trim();
54
+ if (!value) warn(`Missing ${name} on:`, el);
55
+ return value || null;
56
+ };
57
+ /**
58
+ * on
59
+ * @param el The Element to use as EventTarget
60
+ * @param types A space separated string of event types
61
+ * @param listener An event listener function or listener object
62
+ */
63
+ const on = (el, ...rest) => {
64
+ const [types, ...options] = rest;
65
+ for (const type of types.split(" ")) el.addEventListener(type, ...options);
66
+ return () => off(el, ...rest);
67
+ };
68
+ /**
69
+ * off
70
+ * @param el The Element to use as EventTarget
71
+ * @param types A space separated string of event types
72
+ * @param listener An event listener function or listener object
73
+ */
74
+ const off = (el, ...rest) => {
75
+ const [types, ...options] = rest;
76
+ for (const type of types.split(" ")) el.removeEventListener(type, ...options);
77
+ };
78
+ /**
79
+ * onHotReload
80
+ * @description Runs a callback when window is loaded in browser, and ensures cleanup when hot-reloading
81
+ * @param key The key to identify setup and corresponding cleanup
82
+ * @param callback The callback to run when the page is ready
83
+ */
84
+ const onHotReload = (key, setup) => {
85
+ if (!isBrowser()) return;
86
+ if (!window._dsHotReloadCleanup) window._dsHotReloadCleanup = /* @__PURE__ */ new Map();
87
+ window._dsHotReloadCleanup?.get(key)?.map((cleanup) => cleanup());
88
+ window._dsHotReloadCleanup?.set(key, setup());
89
+ };
90
+ /**
91
+ * MutationObserver wrapper with automatic cleanup
92
+ * @return new MutaionObserver
93
+ */
94
+ const onMutation = (el, callback, options) => {
95
+ const cleanup = () => observer.disconnect();
96
+ const observer = new MutationObserver((records) => {
97
+ if (!isBrowser() || !el.isConnected) return cleanup();
98
+ callback(el, records);
99
+ });
100
+ callback(el);
101
+ observer.observe(el, options);
102
+ return cleanup;
103
+ };
104
+ /**
105
+ * tag
106
+ * @description creates element and assigns properties
107
+ * @param tagName The tagname of element to create
108
+ * @param attrs Optional attributes to add to the element
109
+ * @param text Optional text content to add to the element
110
+ * @return HTMLElement with props
111
+ */
112
+ const tag = (tagName, attrs) => {
113
+ const el = document.createElement(tagName);
114
+ if (attrs) for (const [key, val] of Object.entries(attrs)) attr(el, key, val);
115
+ return el;
116
+ };
117
+ /**
118
+ * customElements.define
119
+ * @description Defines a customElement if running in browser and if not already registered
120
+ * Scoped/named "customElements.define" so @custom-elements-manifest/analyzer can find tag names
121
+ */
122
+ const customElements = { define: (name, instance) => !isBrowser() || window.customElements.get(name) || window.customElements.define(name, instance) };
123
+ let id = 0;
124
+ function useId(el) {
125
+ if (!isBrowser()) return `:ds:${++id}`;
126
+ if (!window.dsUseId) window.dsUseId = 0;
127
+ if (el && !el.id) el.id = `:ds:${++window.dsUseId}`;
128
+ return el?.id || "";
129
+ }
130
+ /**
131
+ * @description Based off speak function from [U-elements](https://github.com/u-elements/u-elements/blob/main/packages/utils.ts#L210)
132
+ * @param text The text to announce
133
+ */
134
+ let LIVE_EL;
135
+ let LIVE_FIX = 0;
136
+ let LIVE_CLEAR = 0;
137
+ const announce = (text) => {
138
+ clearTimeout(LIVE_CLEAR);
139
+ if (LIVE_EL) LIVE_EL.textContent = `${text}${LIVE_FIX++ % 2 ? "\xA0" : ""}`;
140
+ if (text) LIVE_CLEAR = setTimeout(announce, 2e3, "");
141
+ };
142
+ const announceMount = () => {
143
+ if (document.readyState !== "complete") return;
144
+ if (!LIVE_EL) {
145
+ LIVE_EL = tag("div", { "aria-live": "assertive" });
146
+ LIVE_EL.style.overflow = "hidden";
147
+ LIVE_EL.style.position = "fixed";
148
+ LIVE_EL.style.whiteSpace = "nowrap";
149
+ LIVE_EL.style.width = "1px";
150
+ }
151
+ if (!LIVE_EL.isConnected) document.body.appendChild(LIVE_EL);
152
+ };
153
+ onHotReload("announce", () => [on(document, "focus mouseover", announceMount, QUICK_EVENT)]);
154
+ //#endregion
155
+ //#region src/clickdelegatefor/clickdelegatefor.ts
156
+ const CLASS_HOVER = ":click-delegate-hover";
157
+ const ATTR_CLICKDELEGATEFOR = "data-clickdelegatefor";
158
+ const SELECTOR_CLICKDELEGATEFOR = `[${ATTR_CLICKDELEGATEFOR}]`;
159
+ const SELECTOR_SKIP = "a,button,label,input,select,textarea,details,dialog,[role=\"button\"],[popover],[contenteditable]";
160
+ const handleClickDelegateFor = (event) => {
161
+ const isNewTab = event.button === 1 || event.metaKey || event.ctrlKey;
162
+ const delegateTarget = event.button < 2 && getDelegateTarget(event);
163
+ if (!delegateTarget || delegateTarget.contains(event.target)) return;
164
+ if (isNewTab && delegateTarget instanceof HTMLAnchorElement) return window.open(delegateTarget.href, void 0, delegateTarget.rel);
165
+ event.stopImmediatePropagation();
166
+ delegateTarget.click();
167
+ };
168
+ let HOVER;
169
+ const handleMouseOver = (event) => {
170
+ const delegateTarget = getDelegateTarget(event);
171
+ if (HOVER === delegateTarget) return;
172
+ if (HOVER) HOVER.classList.remove(CLASS_HOVER);
173
+ if (delegateTarget) delegateTarget.classList.add(CLASS_HOVER);
174
+ HOVER = delegateTarget;
175
+ };
176
+ const getDelegateTarget = ({ target: el }) => {
177
+ const id = (el instanceof Element ? el.closest(SELECTOR_CLICKDELEGATEFOR) : null)?.getAttribute(ATTR_CLICKDELEGATEFOR);
178
+ const target = id && document.getElementById(id) || void 0;
179
+ const skip = target && el.closest(SELECTOR_SKIP);
180
+ return (!skip || skip === target) && !target?.disabled ? target : void 0;
181
+ };
182
+ onHotReload("clickdelegatefor", () => [on(window, "click auxclick", handleClickDelegateFor, true), on(document, "mouseover", handleMouseOver, QUICK_EVENT)]);
183
+ //#endregion
184
+ //#region src/dialog/dialog.ts
185
+ let DOWN_INSIDE = false;
186
+ const handleClosedbyAny = ({ type, target: el, clientX: x = 0, clientY: y = 0 }) => {
187
+ if (type === "pointerdown") {
188
+ const r = el?.closest?.("dialog")?.getBoundingClientRect();
189
+ DOWN_INSIDE = !!(r && r.top <= y && y <= r.bottom && r.left <= x && x <= r.right);
190
+ } else {
191
+ const isClose = el instanceof HTMLDialogElement && !DOWN_INSIDE && attr(el, "closedby") === "any";
192
+ DOWN_INSIDE = false;
193
+ if (isClose) requestAnimationFrame(() => el.open && el.close());
194
+ }
195
+ };
196
+ const BUTTONS = isBrowser() ? document.getElementsByTagName("button") : [];
197
+ const handleAriaAttributes$2 = () => {
198
+ for (const btn of BUTTONS) if (btn.getAttribute("command")?.endsWith("-modal")) btn.setAttribute("aria-haspopup", "dialog");
199
+ };
200
+ const handleCommand = ({ command, target }) => command === "--show-non-modal" && target instanceof HTMLDialogElement && target.show();
201
+ onHotReload("dialog", () => [
202
+ on(document, "command", handleCommand, QUICK_EVENT),
203
+ on(document, "pointerdown pointerup", handleClosedbyAny, QUICK_EVENT),
204
+ onMutation(document, handleAriaAttributes$2, {
205
+ attributeFilter: ["command"],
206
+ attributes: true,
207
+ childList: true,
208
+ subtree: true
209
+ })
210
+ ]);
211
+ //#endregion
212
+ //#region src/fieldset/fieldset.ts
213
+ const FIELDSETS = isBrowser() ? document.getElementsByTagName("fieldset") : [];
214
+ const handleFieldsetMutations = () => {
215
+ for (const el of FIELDSETS) {
216
+ if (el.hasAttribute("aria-labelledby")) continue;
217
+ attr(el, "aria-labelledby", `${useId(el.querySelector("legend"))} ${useId(el.querySelector(":scope > :is([data-field=\"description\"],legend + p)"))}`.trim() || null);
218
+ }
219
+ };
220
+ onHotReload("fieldset", () => [onMutation(document, handleFieldsetMutations, {
221
+ childList: true,
222
+ subtree: true
223
+ })]);
224
+ //#endregion
225
+ //#region ../../node_modules/.pnpm/invokers-polyfill@1.0.3/node_modules/invokers-polyfill/invoker.js
226
+ function isSupported$1() {
227
+ return typeof HTMLButtonElement !== "undefined" && "command" in HTMLButtonElement.prototype && "source" in ((globalThis.CommandEvent || {}).prototype || {});
228
+ }
229
+ function apply$1() {
230
+ document.addEventListener("invoke", (e) => {
231
+ if (e.type == "invoke" && e.isTrusted) {
232
+ e.stopImmediatePropagation();
233
+ e.preventDefault();
234
+ }
235
+ }, true);
236
+ document.addEventListener("command", (e) => {
237
+ if (e.type == "command" && e.isTrusted) {
238
+ e.stopImmediatePropagation();
239
+ e.preventDefault();
240
+ }
241
+ }, true);
242
+ function enumerate(obj, key, enumerable = true) {
243
+ Object.defineProperty(obj, key, {
244
+ ...Object.getOwnPropertyDescriptor(obj, key),
245
+ enumerable
246
+ });
247
+ }
248
+ function getRootNode(node) {
249
+ if (node && typeof node.getRootNode === "function") return node.getRootNode();
250
+ if (node && node.parentNode) return getRootNode(node.parentNode);
251
+ return node;
252
+ }
253
+ const commandEventSourceElements = /* @__PURE__ */ new WeakMap();
254
+ const commandEventActions = /* @__PURE__ */ new WeakMap();
255
+ class CommandEvent extends Event {
256
+ constructor(type, invokeEventInit = {}) {
257
+ super(type, invokeEventInit);
258
+ const { source, command } = invokeEventInit;
259
+ if (source != null && !(source instanceof Element)) throw new TypeError(`source must be an element`);
260
+ commandEventSourceElements.set(this, source || null);
261
+ commandEventActions.set(this, command !== void 0 ? String(command) : "");
262
+ }
263
+ get [Symbol.toStringTag]() {
264
+ return "CommandEvent";
265
+ }
266
+ get source() {
267
+ if (!commandEventSourceElements.has(this)) throw new TypeError("illegal invocation");
268
+ const source = commandEventSourceElements.get(this);
269
+ if (!(source instanceof Element)) return null;
270
+ const invokerRoot = getRootNode(source);
271
+ if (invokerRoot !== getRootNode(this.target || document)) return invokerRoot.host;
272
+ return source;
273
+ }
274
+ get command() {
275
+ if (!commandEventActions.has(this)) throw new TypeError("illegal invocation");
276
+ return commandEventActions.get(this);
277
+ }
278
+ }
279
+ enumerate(CommandEvent.prototype, "source");
280
+ enumerate(CommandEvent.prototype, "command");
281
+ const invokerAssociatedElements = /* @__PURE__ */ new WeakMap();
282
+ function applyInvokerMixin(ElementClass) {
283
+ Object.defineProperties(ElementClass.prototype, {
284
+ commandForElement: {
285
+ enumerable: true,
286
+ configurable: true,
287
+ set(targetElement) {
288
+ if (targetElement === null) {
289
+ this.removeAttribute("commandfor");
290
+ invokerAssociatedElements.delete(this);
291
+ } else if (!(targetElement instanceof Element)) throw new TypeError(`commandForElement must be an element or null`);
292
+ else {
293
+ this.setAttribute("commandfor", "");
294
+ const targetRootNode = getRootNode(targetElement);
295
+ if (getRootNode(this) === targetRootNode || targetRootNode === this.ownerDocument) invokerAssociatedElements.set(this, targetElement);
296
+ else invokerAssociatedElements.delete(this);
297
+ }
298
+ },
299
+ get() {
300
+ if (this.localName !== "button") return null;
301
+ if (this.disabled) return null;
302
+ if (this.form && this.getAttribute("type") !== "button") {
303
+ console.warn("Element with `commandFor` is a form participant. It should explicitly set `type=button` in order for `commandFor` to work");
304
+ return null;
305
+ }
306
+ const targetElement = invokerAssociatedElements.get(this);
307
+ if (targetElement) if (targetElement.isConnected) return targetElement;
308
+ else {
309
+ invokerAssociatedElements.delete(this);
310
+ return null;
311
+ }
312
+ const root = getRootNode(this);
313
+ const idref = this.getAttribute("commandfor");
314
+ if ((root instanceof Document || root instanceof ShadowRoot) && idref) return root.getElementById(idref) || null;
315
+ return null;
316
+ }
317
+ },
318
+ command: {
319
+ enumerable: true,
320
+ configurable: true,
321
+ get() {
322
+ const value = this.getAttribute("command") || "";
323
+ if (value.startsWith("--")) return value;
324
+ const valueLower = value.toLowerCase();
325
+ switch (valueLower) {
326
+ case "show-modal":
327
+ case "request-close":
328
+ case "close":
329
+ case "toggle-popover":
330
+ case "hide-popover":
331
+ case "show-popover": return valueLower;
332
+ }
333
+ return "";
334
+ },
335
+ set(value) {
336
+ this.setAttribute("command", value);
337
+ }
338
+ }
339
+ });
340
+ }
341
+ const onHandlers = /* @__PURE__ */ new WeakMap();
342
+ Object.defineProperties(HTMLElement.prototype, { oncommand: {
343
+ enumerable: true,
344
+ configurable: true,
345
+ get() {
346
+ oncommandObserver.takeRecords();
347
+ return onHandlers.get(this) || null;
348
+ },
349
+ set(handler) {
350
+ const existing = onHandlers.get(this) || null;
351
+ if (existing) this.removeEventListener("command", existing);
352
+ onHandlers.set(this, typeof handler === "object" || typeof handler === "function" ? handler : null);
353
+ if (typeof handler == "function") this.addEventListener("command", handler);
354
+ }
355
+ } });
356
+ function applyOnCommandHandler(els) {
357
+ for (const el of els) el.oncommand = new Function("event", el.getAttribute("oncommand"));
358
+ }
359
+ const oncommandObserver = new MutationObserver((records) => {
360
+ for (const record of records) {
361
+ const { target } = record;
362
+ if (record.type === "childList") applyOnCommandHandler(target.querySelectorAll("[oncommand]"));
363
+ else applyOnCommandHandler([target]);
364
+ }
365
+ });
366
+ oncommandObserver.observe(document, {
367
+ subtree: true,
368
+ childList: true,
369
+ attributeFilter: ["oncommand"]
370
+ });
371
+ applyOnCommandHandler(document.querySelectorAll("[oncommand]"));
372
+ const processedEvents = /* @__PURE__ */ new WeakSet();
373
+ function handleInvokerActivation(event) {
374
+ if (processedEvents.has(event)) return;
375
+ processedEvents.add(event);
376
+ if (event.defaultPrevented) return;
377
+ if (event.type !== "click") return;
378
+ const source = event.composedPath().find((el) => el.matches?.("button[commandfor], button[command]"));
379
+ if (!source) return;
380
+ if (source.form && source.getAttribute("type") !== "button") {
381
+ event.preventDefault();
382
+ throw new Error("Element with `commandFor` is a form participant. It should explicitly set `type=button` in order for `commandFor` to work. In order for it to act as a Submit button, it must not have command or commandfor attributes");
383
+ }
384
+ if (source.hasAttribute("command") !== source.hasAttribute("commandfor")) {
385
+ const attr = source.hasAttribute("command") ? "command" : "commandfor";
386
+ const missing = source.hasAttribute("command") ? "commandfor" : "command";
387
+ throw new Error(`Element with ${attr} attribute must also have a ${missing} attribute to function.`);
388
+ }
389
+ if (source.command !== "show-popover" && source.command !== "hide-popover" && source.command !== "toggle-popover" && source.command !== "show-modal" && source.command !== "request-close" && source.command !== "close" && !source.command.startsWith("--")) {
390
+ console.warn(`"${source.command}" is not a valid command value. Custom commands must begin with --`);
391
+ return;
392
+ }
393
+ const invokee = source.commandForElement;
394
+ if (!invokee) return;
395
+ const invokeEvent = new CommandEvent("command", {
396
+ command: source.command,
397
+ source,
398
+ cancelable: true
399
+ });
400
+ invokee.dispatchEvent(invokeEvent);
401
+ if (invokeEvent.defaultPrevented) return;
402
+ const command = invokeEvent.command.toLowerCase();
403
+ if (invokee.popover) {
404
+ const canShow = !invokee.matches(":popover-open");
405
+ const shouldShow = canShow && (command === "toggle-popover" || command === "show-popover");
406
+ const shouldHide = !canShow && command === "hide-popover";
407
+ if (shouldShow) invokee.showPopover({ source });
408
+ else if (shouldHide) invokee.hidePopover();
409
+ } else if (invokee.localName === "dialog") {
410
+ const canShow = !invokee.hasAttribute("open");
411
+ if (canShow && command == "show-modal") invokee.showModal();
412
+ else if (!canShow && command == "close") invokee.close(source.value ? source.value : void 0);
413
+ else if (!canShow && command == "request-close") {
414
+ if (!HTMLDialogElement.prototype.requestClose) HTMLDialogElement.prototype.requestClose = function() {
415
+ const cancelEvent = new Event("cancel", { cancelable: true });
416
+ this.dispatchEvent(cancelEvent);
417
+ if (!cancelEvent.defaultPrevented) this.close();
418
+ };
419
+ invokee.requestClose(source.value ? source.value : void 0);
420
+ }
421
+ }
422
+ }
423
+ function setupInvokeListeners(target) {
424
+ target.addEventListener("click", handleInvokerActivation, true);
425
+ }
426
+ function observeShadowRoots(ElementClass, callback) {
427
+ const attachShadow = ElementClass.prototype.attachShadow;
428
+ ElementClass.prototype.attachShadow = function(init) {
429
+ const shadow = attachShadow.call(this, init);
430
+ callback(shadow);
431
+ return shadow;
432
+ };
433
+ const attachInternals = ElementClass.prototype.attachInternals;
434
+ ElementClass.prototype.attachInternals = function() {
435
+ const internals = attachInternals.call(this);
436
+ if (internals.shadowRoot) callback(internals.shadowRoot);
437
+ return internals;
438
+ };
439
+ }
440
+ applyInvokerMixin(HTMLButtonElement);
441
+ observeShadowRoots(HTMLElement, (shadow) => {
442
+ setupInvokeListeners(shadow);
443
+ oncommandObserver.observe(shadow, { attributeFilter: ["oncommand"] });
444
+ applyOnCommandHandler(shadow.querySelectorAll("[oncommand]"));
445
+ });
446
+ setupInvokeListeners(document);
447
+ Object.assign(globalThis, { CommandEvent });
448
+ }
449
+ //#endregion
450
+ //#region src/invokers/invokers.ts
451
+ if (isBrowser() && !isSupported$1()) apply$1();
452
+ //#endregion
453
+ //#region ../../node_modules/.pnpm/@oddbird+popover-polyfill@0.6.1/node_modules/@oddbird/popover-polyfill/dist/popover-fn.js
454
+ var ToggleEvent = class extends Event {
455
+ oldState;
456
+ newState;
457
+ constructor(type, { oldState = "", newState = "", ...init } = {}) {
458
+ super(type, init);
459
+ this.oldState = String(oldState || "");
460
+ this.newState = String(newState || "");
461
+ }
462
+ };
463
+ var popoverToggleTaskQueue = /* @__PURE__ */ new WeakMap();
464
+ function queuePopoverToggleEventTask(element, oldState, newState) {
465
+ popoverToggleTaskQueue.set(element, setTimeout(() => {
466
+ if (!popoverToggleTaskQueue.has(element)) return;
467
+ element.dispatchEvent(new ToggleEvent("toggle", {
468
+ cancelable: false,
469
+ oldState,
470
+ newState
471
+ }));
472
+ }, 0));
473
+ }
474
+ var ShadowRoot$1 = globalThis.ShadowRoot || function() {};
475
+ var HTMLDialogElement$1 = globalThis.HTMLDialogElement || function() {};
476
+ var topLayerElements = /* @__PURE__ */ new WeakMap();
477
+ var autoPopoverList = /* @__PURE__ */ new WeakMap();
478
+ var hintPopoverList = /* @__PURE__ */ new WeakMap();
479
+ var visibilityState = /* @__PURE__ */ new WeakMap();
480
+ function getPopoverVisibilityState(popover) {
481
+ return visibilityState.get(popover) || "hidden";
482
+ }
483
+ var popoverInvoker = /* @__PURE__ */ new WeakMap();
484
+ function lastSetElement(set) {
485
+ return [...set].pop();
486
+ }
487
+ function popoverTargetAttributeActivationBehavior(element) {
488
+ const popover = element.popoverTargetElement;
489
+ if (!(popover instanceof HTMLElement)) return;
490
+ const visibility = getPopoverVisibilityState(popover);
491
+ if (element.popoverTargetAction === "show" && visibility === "showing") return;
492
+ if (element.popoverTargetAction === "hide" && visibility === "hidden") return;
493
+ if (visibility === "showing") hidePopover(popover, true, true);
494
+ else if (checkPopoverValidity(popover, false)) {
495
+ popoverInvoker.set(popover, element);
496
+ showPopover(popover);
497
+ }
498
+ }
499
+ function checkPopoverValidity(element, expectedToBeShowing) {
500
+ if (element.popover !== "auto" && element.popover !== "manual" && element.popover !== "hint") return false;
501
+ if (!element.isConnected) return false;
502
+ if (expectedToBeShowing && getPopoverVisibilityState(element) !== "showing") return false;
503
+ if (!expectedToBeShowing && getPopoverVisibilityState(element) !== "hidden") return false;
504
+ if (element instanceof HTMLDialogElement$1 && element.hasAttribute("open")) return false;
505
+ if (document.fullscreenElement === element) return false;
506
+ return true;
507
+ }
508
+ function getStackPosition(popover) {
509
+ if (!popover) return 0;
510
+ const autoPopovers = autoPopoverList.get(document) || /* @__PURE__ */ new Set();
511
+ const hintPopovers = hintPopoverList.get(document) || /* @__PURE__ */ new Set();
512
+ if (hintPopovers.has(popover)) return [...hintPopovers].indexOf(popover) + autoPopovers.size + 1;
513
+ if (autoPopovers.has(popover)) return [...autoPopovers].indexOf(popover) + 1;
514
+ return 0;
515
+ }
516
+ function topMostClickedPopover(target) {
517
+ const clickedPopover = nearestInclusiveOpenPopover(target);
518
+ const invokerPopover = nearestInclusiveTargetPopoverForInvoker(target);
519
+ if (getStackPosition(clickedPopover) > getStackPosition(invokerPopover)) return clickedPopover;
520
+ return invokerPopover;
521
+ }
522
+ function topmostAutoOrHintPopover(document2) {
523
+ let topmostPopover;
524
+ const hintPopovers = hintPopoverList.get(document2) || /* @__PURE__ */ new Set();
525
+ const autoPopovers = autoPopoverList.get(document2) || /* @__PURE__ */ new Set();
526
+ const usedStack = hintPopovers.size > 0 ? hintPopovers : autoPopovers.size > 0 ? autoPopovers : null;
527
+ if (usedStack) {
528
+ topmostPopover = lastSetElement(usedStack);
529
+ if (!topmostPopover.isConnected) {
530
+ usedStack.delete(topmostPopover);
531
+ return topmostAutoOrHintPopover(document2);
532
+ }
533
+ return topmostPopover;
534
+ }
535
+ return null;
536
+ }
537
+ function topMostPopoverInList(list) {
538
+ for (const popover of list || []) if (!popover.isConnected) list.delete(popover);
539
+ else return popover;
540
+ return null;
541
+ }
542
+ function getRootNode(node) {
543
+ if (typeof node.getRootNode === "function") return node.getRootNode();
544
+ if (node.parentNode) return getRootNode(node.parentNode);
545
+ return node;
546
+ }
547
+ function nearestInclusiveOpenPopover(node) {
548
+ while (node) {
549
+ if (node instanceof HTMLElement && node.popover === "auto" && visibilityState.get(node) === "showing") return node;
550
+ node = node instanceof Element && node.assignedSlot || node.parentElement || getRootNode(node);
551
+ if (node instanceof ShadowRoot$1) node = node.host;
552
+ if (node instanceof Document) return;
553
+ }
554
+ }
555
+ function nearestInclusiveTargetPopoverForInvoker(node) {
556
+ while (node) {
557
+ const nodePopover = node.popoverTargetElement;
558
+ if (nodePopover instanceof HTMLElement) return nodePopover;
559
+ node = node.parentElement || getRootNode(node);
560
+ if (node instanceof ShadowRoot$1) node = node.host;
561
+ if (node instanceof Document) return;
562
+ }
563
+ }
564
+ function topMostPopoverAncestor(newPopover, list) {
565
+ const popoverPositions = /* @__PURE__ */ new Map();
566
+ let i = 0;
567
+ for (const popover of list || []) {
568
+ popoverPositions.set(popover, i);
569
+ i += 1;
570
+ }
571
+ popoverPositions.set(newPopover, i);
572
+ i += 1;
573
+ let topMostPopoverAncestor2 = null;
574
+ function checkAncestor(candidate) {
575
+ if (!candidate) return;
576
+ let okNesting = false;
577
+ let candidateAncestor = null;
578
+ let candidatePosition = null;
579
+ while (!okNesting) {
580
+ candidateAncestor = nearestInclusiveOpenPopover(candidate) || null;
581
+ if (candidateAncestor === null) return;
582
+ if (!popoverPositions.has(candidateAncestor)) return;
583
+ if (newPopover.popover === "hint" || candidateAncestor.popover === "auto") okNesting = true;
584
+ if (!okNesting) candidate = candidateAncestor.parentElement;
585
+ }
586
+ candidatePosition = popoverPositions.get(candidateAncestor);
587
+ if (topMostPopoverAncestor2 === null || popoverPositions.get(topMostPopoverAncestor2) < candidatePosition) topMostPopoverAncestor2 = candidateAncestor;
588
+ }
589
+ checkAncestor(newPopover.parentElement || getRootNode(newPopover));
590
+ return topMostPopoverAncestor2;
591
+ }
592
+ function isFocusable(focusTarget) {
593
+ if (focusTarget.hidden || focusTarget instanceof ShadowRoot$1) return false;
594
+ if (focusTarget instanceof HTMLButtonElement || focusTarget instanceof HTMLInputElement || focusTarget instanceof HTMLSelectElement || focusTarget instanceof HTMLTextAreaElement || focusTarget instanceof HTMLOptGroupElement || focusTarget instanceof HTMLOptionElement || focusTarget instanceof HTMLFieldSetElement) {
595
+ if (focusTarget.disabled) return false;
596
+ }
597
+ if (focusTarget instanceof HTMLInputElement && focusTarget.type === "hidden") return false;
598
+ if (focusTarget instanceof HTMLAnchorElement && focusTarget.href === "") return false;
599
+ return typeof focusTarget.tabIndex === "number" && focusTarget.tabIndex !== -1;
600
+ }
601
+ function focusDelegate(focusTarget) {
602
+ if (focusTarget.shadowRoot && focusTarget.shadowRoot.delegatesFocus !== true) return null;
603
+ let whereToLook = focusTarget;
604
+ if (whereToLook.shadowRoot) whereToLook = whereToLook.shadowRoot;
605
+ let autoFocusDelegate = whereToLook.querySelector("[autofocus]");
606
+ if (autoFocusDelegate) return autoFocusDelegate;
607
+ else {
608
+ const slots = whereToLook.querySelectorAll("slot");
609
+ for (const slot of slots) {
610
+ const assignedElements = slot.assignedElements({ flatten: true });
611
+ for (const el of assignedElements) if (el.hasAttribute("autofocus")) return el;
612
+ else {
613
+ autoFocusDelegate = el.querySelector("[autofocus]");
614
+ if (autoFocusDelegate) return autoFocusDelegate;
615
+ }
616
+ }
617
+ }
618
+ const walker = focusTarget.ownerDocument.createTreeWalker(whereToLook, NodeFilter.SHOW_ELEMENT);
619
+ let descendant = walker.currentNode;
620
+ while (descendant) {
621
+ if (isFocusable(descendant)) return descendant;
622
+ descendant = walker.nextNode();
623
+ }
624
+ }
625
+ function popoverFocusingSteps(subject) {
626
+ var _a;
627
+ (_a = focusDelegate(subject)) == null || _a.focus();
628
+ }
629
+ var previouslyFocusedElements = /* @__PURE__ */ new WeakMap();
630
+ function showPopover(element) {
631
+ if (!checkPopoverValidity(element, false)) return;
632
+ const document2 = element.ownerDocument;
633
+ if (!element.dispatchEvent(new ToggleEvent("beforetoggle", {
634
+ cancelable: true,
635
+ oldState: "closed",
636
+ newState: "open"
637
+ }))) return;
638
+ if (!checkPopoverValidity(element, false)) return;
639
+ let shouldRestoreFocus = false;
640
+ const originalType = element.popover;
641
+ let stackToAppendTo = null;
642
+ const autoAncestor = topMostPopoverAncestor(element, autoPopoverList.get(document2) || /* @__PURE__ */ new Set());
643
+ const hintAncestor = topMostPopoverAncestor(element, hintPopoverList.get(document2) || /* @__PURE__ */ new Set());
644
+ if (originalType === "auto") {
645
+ closeAllOpenPopoversInList(hintPopoverList.get(document2) || /* @__PURE__ */ new Set(), shouldRestoreFocus, true);
646
+ hideAllPopoversUntil(autoAncestor || document2, shouldRestoreFocus, true);
647
+ stackToAppendTo = "auto";
648
+ }
649
+ if (originalType === "hint") if (hintAncestor) {
650
+ hideAllPopoversUntil(hintAncestor, shouldRestoreFocus, true);
651
+ stackToAppendTo = "hint";
652
+ } else {
653
+ closeAllOpenPopoversInList(hintPopoverList.get(document2) || /* @__PURE__ */ new Set(), shouldRestoreFocus, true);
654
+ if (autoAncestor) {
655
+ hideAllPopoversUntil(autoAncestor, shouldRestoreFocus, true);
656
+ stackToAppendTo = "auto";
657
+ } else stackToAppendTo = "hint";
658
+ }
659
+ if (originalType === "auto" || originalType === "hint") {
660
+ if (originalType !== element.popover || !checkPopoverValidity(element, false)) return;
661
+ if (!topmostAutoOrHintPopover(document2)) shouldRestoreFocus = true;
662
+ if (stackToAppendTo === "auto") {
663
+ if (!autoPopoverList.has(document2)) autoPopoverList.set(document2, /* @__PURE__ */ new Set());
664
+ autoPopoverList.get(document2).add(element);
665
+ } else if (stackToAppendTo === "hint") {
666
+ if (!hintPopoverList.has(document2)) hintPopoverList.set(document2, /* @__PURE__ */ new Set());
667
+ hintPopoverList.get(document2).add(element);
668
+ }
669
+ }
670
+ previouslyFocusedElements.delete(element);
671
+ const originallyFocusedElement = document2.activeElement;
672
+ element.classList.add(":popover-open");
673
+ visibilityState.set(element, "showing");
674
+ if (!topLayerElements.has(document2)) topLayerElements.set(document2, /* @__PURE__ */ new Set());
675
+ topLayerElements.get(document2).add(element);
676
+ setInvokerAriaExpanded(popoverInvoker.get(element), true);
677
+ popoverFocusingSteps(element);
678
+ if (shouldRestoreFocus && originallyFocusedElement && element.popover === "auto") previouslyFocusedElements.set(element, originallyFocusedElement);
679
+ queuePopoverToggleEventTask(element, "closed", "open");
680
+ }
681
+ function hidePopover(element, focusPreviousElement = false, fireEvents = false) {
682
+ var _a, _b;
683
+ if (!checkPopoverValidity(element, true)) return;
684
+ const document2 = element.ownerDocument;
685
+ if (["auto", "hint"].includes(element.popover)) {
686
+ hideAllPopoversUntil(element, focusPreviousElement, fireEvents);
687
+ if (!checkPopoverValidity(element, true)) return;
688
+ }
689
+ const autoList = autoPopoverList.get(document2) || /* @__PURE__ */ new Set();
690
+ const autoPopoverListContainsElement = autoList.has(element) && lastSetElement(autoList) === element;
691
+ setInvokerAriaExpanded(popoverInvoker.get(element), false);
692
+ popoverInvoker.delete(element);
693
+ if (fireEvents) {
694
+ element.dispatchEvent(new ToggleEvent("beforetoggle", {
695
+ oldState: "open",
696
+ newState: "closed"
697
+ }));
698
+ if (autoPopoverListContainsElement && lastSetElement(autoList) !== element) hideAllPopoversUntil(element, focusPreviousElement, fireEvents);
699
+ if (!checkPopoverValidity(element, true)) return;
700
+ }
701
+ (_a = topLayerElements.get(document2)) == null || _a.delete(element);
702
+ autoList.delete(element);
703
+ (_b = hintPopoverList.get(document2)) == null || _b.delete(element);
704
+ element.classList.remove(":popover-open");
705
+ visibilityState.set(element, "hidden");
706
+ if (fireEvents) queuePopoverToggleEventTask(element, "open", "closed");
707
+ const previouslyFocusedElement = previouslyFocusedElements.get(element);
708
+ if (previouslyFocusedElement) {
709
+ previouslyFocusedElements.delete(element);
710
+ if (focusPreviousElement) previouslyFocusedElement.focus();
711
+ }
712
+ }
713
+ function closeAllOpenPopovers(document2, focusPreviousElement = false, fireEvents = false) {
714
+ let popover = topmostAutoOrHintPopover(document2);
715
+ while (popover) {
716
+ hidePopover(popover, focusPreviousElement, fireEvents);
717
+ popover = topmostAutoOrHintPopover(document2);
718
+ }
719
+ }
720
+ function closeAllOpenPopoversInList(list, focusPreviousElement = false, fireEvents = false) {
721
+ let popover = topMostPopoverInList(list);
722
+ while (popover) {
723
+ hidePopover(popover, focusPreviousElement, fireEvents);
724
+ popover = topMostPopoverInList(list);
725
+ }
726
+ }
727
+ function hidePopoverStackUntil(endpoint, set, focusPreviousElement, fireEvents) {
728
+ let repeatingHide = false;
729
+ let hasRunOnce = false;
730
+ while (repeatingHide || !hasRunOnce) {
731
+ hasRunOnce = true;
732
+ let lastToHide = null;
733
+ let foundEndpoint = false;
734
+ for (const popover of set) if (popover === endpoint) foundEndpoint = true;
735
+ else if (foundEndpoint) {
736
+ lastToHide = popover;
737
+ break;
738
+ }
739
+ if (!lastToHide) return;
740
+ while (getPopoverVisibilityState(lastToHide) === "showing" && set.size) hidePopover(lastSetElement(set), focusPreviousElement, fireEvents);
741
+ if (set.has(endpoint) && lastSetElement(set) !== endpoint) repeatingHide = true;
742
+ if (repeatingHide) fireEvents = false;
743
+ }
744
+ }
745
+ function hideAllPopoversUntil(endpoint, focusPreviousElement, fireEvents) {
746
+ var _a, _b;
747
+ const document2 = endpoint.ownerDocument || endpoint;
748
+ if (endpoint instanceof Document) return closeAllOpenPopovers(document2, focusPreviousElement, fireEvents);
749
+ if ((_a = hintPopoverList.get(document2)) == null ? void 0 : _a.has(endpoint)) {
750
+ hidePopoverStackUntil(endpoint, hintPopoverList.get(document2), focusPreviousElement, fireEvents);
751
+ return;
752
+ }
753
+ closeAllOpenPopoversInList(hintPopoverList.get(document2) || /* @__PURE__ */ new Set(), focusPreviousElement, fireEvents);
754
+ if (!((_b = autoPopoverList.get(document2)) == null ? void 0 : _b.has(endpoint))) return;
755
+ hidePopoverStackUntil(endpoint, autoPopoverList.get(document2), focusPreviousElement, fireEvents);
756
+ }
757
+ var popoverPointerDownTargets = /* @__PURE__ */ new WeakMap();
758
+ function lightDismissOpenPopovers(event) {
759
+ if (!event.isTrusted) return;
760
+ const target = event.composedPath()[0];
761
+ if (!target) return;
762
+ const document2 = target.ownerDocument;
763
+ if (!topmostAutoOrHintPopover(document2)) return;
764
+ const ancestor = topMostClickedPopover(target);
765
+ if (ancestor && event.type === "pointerdown") popoverPointerDownTargets.set(document2, ancestor);
766
+ else if (event.type === "pointerup") {
767
+ const sameTarget = popoverPointerDownTargets.get(document2) === ancestor;
768
+ popoverPointerDownTargets.delete(document2);
769
+ if (sameTarget) hideAllPopoversUntil(ancestor || document2, false, true);
770
+ }
771
+ }
772
+ var initialAriaExpandedValue = /* @__PURE__ */ new WeakMap();
773
+ function setInvokerAriaExpanded(el, force = false) {
774
+ if (!el) return;
775
+ if (!initialAriaExpandedValue.has(el)) initialAriaExpandedValue.set(el, el.getAttribute("aria-expanded"));
776
+ const popover = el.popoverTargetElement;
777
+ if (popover instanceof HTMLElement && popover.popover === "auto") el.setAttribute("aria-expanded", String(force));
778
+ else {
779
+ const initialValue = initialAriaExpandedValue.get(el);
780
+ if (!initialValue) el.removeAttribute("aria-expanded");
781
+ else el.setAttribute("aria-expanded", initialValue);
782
+ }
783
+ }
784
+ var ShadowRoot2 = globalThis.ShadowRoot || function() {};
785
+ function isSupported() {
786
+ return typeof HTMLElement !== "undefined" && typeof HTMLElement.prototype === "object" && "popover" in HTMLElement.prototype;
787
+ }
788
+ function patchSelectorFn(object, name, mapper) {
789
+ const original = object[name];
790
+ Object.defineProperty(object, name, { value(selector) {
791
+ return original.call(this, mapper(selector));
792
+ } });
793
+ }
794
+ var nonEscapedPopoverSelector = /(^|[^\\]):popover-open\b/g;
795
+ function hasLayerSupport() {
796
+ return typeof globalThis.CSSLayerBlockRule === "function";
797
+ }
798
+ function getStyles() {
799
+ const useLayer = hasLayerSupport();
800
+ return `
801
+ ${useLayer ? "@layer popover-polyfill {" : ""}
802
+ :where([popover]) {
803
+ position: fixed;
804
+ z-index: 2147483647;
805
+ inset: 0;
806
+ padding: 0.25em;
807
+ width: fit-content;
808
+ height: fit-content;
809
+ border-width: initial;
810
+ border-color: initial;
811
+ border-image: initial;
812
+ border-style: solid;
813
+ background-color: canvas;
814
+ color: canvastext;
815
+ overflow: auto;
816
+ margin: auto;
817
+ }
818
+
819
+ :where([popover]:not(.\\:popover-open)) {
820
+ display: none;
821
+ }
822
+
823
+ :where(dialog[popover].\\:popover-open) {
824
+ display: block;
825
+ }
826
+
827
+ :where(dialog[popover][open]) {
828
+ display: revert;
829
+ }
830
+
831
+ :where([anchor].\\:popover-open) {
832
+ inset: auto;
833
+ }
834
+
835
+ :where([anchor]:popover-open) {
836
+ inset: auto;
837
+ }
838
+
839
+ @supports not (background-color: canvas) {
840
+ :where([popover]) {
841
+ background-color: white;
842
+ color: black;
843
+ }
844
+ }
845
+
846
+ @supports (width: -moz-fit-content) {
847
+ :where([popover]) {
848
+ width: -moz-fit-content;
849
+ height: -moz-fit-content;
850
+ }
851
+ }
852
+
853
+ @supports not (inset: 0) {
854
+ :where([popover]) {
855
+ top: 0;
856
+ left: 0;
857
+ right: 0;
858
+ bottom: 0;
859
+ }
860
+ }
861
+ ${useLayer ? "}" : ""}
862
+ `;
863
+ }
864
+ var popoverStyleSheet = null;
865
+ function injectStyles(root) {
866
+ const styles = getStyles();
867
+ if (popoverStyleSheet === null) try {
868
+ popoverStyleSheet = new CSSStyleSheet();
869
+ popoverStyleSheet.replaceSync(styles);
870
+ } catch {
871
+ popoverStyleSheet = false;
872
+ }
873
+ if (popoverStyleSheet === false) {
874
+ const sheet = document.createElement("style");
875
+ sheet.textContent = styles;
876
+ if (root instanceof Document) root.head.prepend(sheet);
877
+ else root.prepend(sheet);
878
+ } else root.adoptedStyleSheets = [popoverStyleSheet, ...root.adoptedStyleSheets];
879
+ }
880
+ function apply() {
881
+ if (typeof window === "undefined") return;
882
+ window.ToggleEvent = window.ToggleEvent || ToggleEvent;
883
+ function rewriteSelector(selector) {
884
+ if (selector == null ? void 0 : selector.includes(":popover-open")) selector = selector.replace(nonEscapedPopoverSelector, "$1.\\:popover-open");
885
+ return selector;
886
+ }
887
+ patchSelectorFn(Document.prototype, "querySelector", rewriteSelector);
888
+ patchSelectorFn(Document.prototype, "querySelectorAll", rewriteSelector);
889
+ patchSelectorFn(Element.prototype, "querySelector", rewriteSelector);
890
+ patchSelectorFn(Element.prototype, "querySelectorAll", rewriteSelector);
891
+ patchSelectorFn(Element.prototype, "matches", rewriteSelector);
892
+ patchSelectorFn(Element.prototype, "closest", rewriteSelector);
893
+ patchSelectorFn(DocumentFragment.prototype, "querySelectorAll", rewriteSelector);
894
+ Object.defineProperties(HTMLElement.prototype, {
895
+ popover: {
896
+ enumerable: true,
897
+ configurable: true,
898
+ get() {
899
+ if (!this.hasAttribute("popover")) return null;
900
+ const value = (this.getAttribute("popover") || "").toLowerCase();
901
+ if (value === "" || value == "auto") return "auto";
902
+ if (value == "hint") return "hint";
903
+ return "manual";
904
+ },
905
+ set(value) {
906
+ if (value === null) this.removeAttribute("popover");
907
+ else this.setAttribute("popover", value);
908
+ }
909
+ },
910
+ showPopover: {
911
+ enumerable: true,
912
+ configurable: true,
913
+ value(options = {}) {
914
+ showPopover(this);
915
+ }
916
+ },
917
+ hidePopover: {
918
+ enumerable: true,
919
+ configurable: true,
920
+ value() {
921
+ hidePopover(this, true, true);
922
+ }
923
+ },
924
+ togglePopover: {
925
+ enumerable: true,
926
+ configurable: true,
927
+ value(options = {}) {
928
+ if (typeof options === "boolean") options = { force: options };
929
+ if (visibilityState.get(this) === "showing" && options.force === void 0 || options.force === false) hidePopover(this, true, true);
930
+ else if (options.force === void 0 || options.force === true) showPopover(this);
931
+ return visibilityState.get(this) === "showing";
932
+ }
933
+ }
934
+ });
935
+ const originalAttachShadow = Element.prototype.attachShadow;
936
+ if (originalAttachShadow) Object.defineProperties(Element.prototype, { attachShadow: {
937
+ enumerable: true,
938
+ configurable: true,
939
+ writable: true,
940
+ value(options) {
941
+ const shadowRoot = originalAttachShadow.call(this, options);
942
+ injectStyles(shadowRoot);
943
+ return shadowRoot;
944
+ }
945
+ } });
946
+ const originalAttachInternals = HTMLElement.prototype.attachInternals;
947
+ if (originalAttachInternals) Object.defineProperties(HTMLElement.prototype, { attachInternals: {
948
+ enumerable: true,
949
+ configurable: true,
950
+ writable: true,
951
+ value() {
952
+ const internals = originalAttachInternals.call(this);
953
+ if (internals.shadowRoot) injectStyles(internals.shadowRoot);
954
+ return internals;
955
+ }
956
+ } });
957
+ const popoverTargetAssociatedElements = /* @__PURE__ */ new WeakMap();
958
+ function applyPopoverInvokerElementMixin(ElementClass) {
959
+ Object.defineProperties(ElementClass.prototype, {
960
+ popoverTargetElement: {
961
+ enumerable: true,
962
+ configurable: true,
963
+ set(targetElement) {
964
+ if (targetElement === null) {
965
+ this.removeAttribute("popovertarget");
966
+ popoverTargetAssociatedElements.delete(this);
967
+ } else if (!(targetElement instanceof Element)) throw new TypeError(`popoverTargetElement must be an element or null`);
968
+ else {
969
+ this.setAttribute("popovertarget", "");
970
+ popoverTargetAssociatedElements.set(this, targetElement);
971
+ }
972
+ },
973
+ get() {
974
+ if (this.localName !== "button" && this.localName !== "input") return null;
975
+ if (this.localName === "input" && this.type !== "reset" && this.type !== "image" && this.type !== "button") return null;
976
+ if (this.disabled) return null;
977
+ if (this.form && this.type === "submit") return null;
978
+ const targetElement = popoverTargetAssociatedElements.get(this);
979
+ if (targetElement && targetElement.isConnected) return targetElement;
980
+ else if (targetElement && !targetElement.isConnected) {
981
+ popoverTargetAssociatedElements.delete(this);
982
+ return null;
983
+ }
984
+ const root = getRootNode(this);
985
+ const idref = this.getAttribute("popovertarget");
986
+ if ((root instanceof Document || root instanceof ShadowRoot2) && idref) return root.getElementById(idref) || null;
987
+ return null;
988
+ }
989
+ },
990
+ popoverTargetAction: {
991
+ enumerable: true,
992
+ configurable: true,
993
+ get() {
994
+ const value = (this.getAttribute("popovertargetaction") || "").toLowerCase();
995
+ if (value === "show" || value === "hide") return value;
996
+ return "toggle";
997
+ },
998
+ set(value) {
999
+ this.setAttribute("popovertargetaction", value);
1000
+ }
1001
+ }
1002
+ });
1003
+ }
1004
+ applyPopoverInvokerElementMixin(HTMLButtonElement);
1005
+ applyPopoverInvokerElementMixin(HTMLInputElement);
1006
+ const handleInvokerActivation = (event) => {
1007
+ if (event.defaultPrevented) return;
1008
+ const composedPath = event.composedPath();
1009
+ const target = composedPath[0];
1010
+ if (!(target instanceof Element) || (target == null ? void 0 : target.shadowRoot)) return;
1011
+ const root = getRootNode(target);
1012
+ if (!(root instanceof ShadowRoot2 || root instanceof Document)) return;
1013
+ const invoker = composedPath.find((el) => {
1014
+ var _a;
1015
+ return (_a = el.matches) == null ? void 0 : _a.call(el, "[popovertargetaction],[popovertarget]");
1016
+ });
1017
+ if (invoker) {
1018
+ popoverTargetAttributeActivationBehavior(invoker);
1019
+ event.preventDefault();
1020
+ return;
1021
+ }
1022
+ };
1023
+ const onKeydown = (event) => {
1024
+ const key = event.key;
1025
+ const target = event.target;
1026
+ if (!event.defaultPrevented && target && (key === "Escape" || key === "Esc")) hideAllPopoversUntil(target.ownerDocument, true, true);
1027
+ };
1028
+ const addEventListeners = (root) => {
1029
+ root.addEventListener("click", handleInvokerActivation);
1030
+ root.addEventListener("keydown", onKeydown);
1031
+ root.addEventListener("pointerdown", lightDismissOpenPopovers);
1032
+ root.addEventListener("pointerup", lightDismissOpenPopovers);
1033
+ };
1034
+ addEventListeners(document);
1035
+ injectStyles(document);
1036
+ }
1037
+ //#endregion
1038
+ //#region src/popover/popover.ts
1039
+ if (isBrowser() && !isSupported()) apply();
1040
+ const ATTR_PLACE = "data-placement";
1041
+ const ATTR_AUTO = "data-autoplacement";
1042
+ const POPOVERS = /* @__PURE__ */ new Map();
1043
+ function handleToggle(event) {
1044
+ let { newState, oldState, target: el, source = event.detail } = event;
1045
+ const float = el instanceof HTMLElement && attr(el, "popover") !== null && getCSSProp(el, "--_ds-floating");
1046
+ if (!float) return;
1047
+ if (newState === "closed") return POPOVERS.get(el)?.();
1048
+ if (!source) {
1049
+ const root = el.getRootNode();
1050
+ const css = `[popovertarget="${el.id}"],[commandfor="${el.id}"]`;
1051
+ source = el.id && root?.querySelector?.(css) || void 0;
1052
+ }
1053
+ if (!source || source === el || oldState && oldState === newState) return;
1054
+ el.style.scrollMarginBottom = `var(--_ds-floating-arrow-size)`;
1055
+ const padding = 10;
1056
+ const overscroll = getCSSProp(el, "--_ds-floating-overscroll");
1057
+ const placement = attr(el, ATTR_PLACE) || attr(source, ATTR_PLACE) || float;
1058
+ const auto = attr(el, ATTR_AUTO) || attr(source, ATTR_AUTO);
1059
+ const arrowSize = parseFloat(getCSSProp(el, "scroll-margin-bottom")) || 0;
1060
+ const shiftProp = placement.match(/left|right/gi) ? "Height" : "Width";
1061
+ const shiftLimit = source[`offset${shiftProp}`] / 2 + arrowSize;
1062
+ if (placement === "none") return;
1063
+ const options = {
1064
+ strategy: "absolute",
1065
+ placement,
1066
+ middleware: [
1067
+ offset(arrowSize),
1068
+ shift({
1069
+ padding,
1070
+ limiter: limitShift({ offset: { mainAxis: shiftLimit } })
1071
+ }),
1072
+ arrowPseudo(),
1073
+ ...auto !== "false" ? [flip({
1074
+ padding,
1075
+ crossAxis: false
1076
+ })] : [],
1077
+ ...overscroll ? [size({ apply({ availableHeight }) {
1078
+ if (overscroll === "fit") el.style.width = `${source.offsetWidth}px`;
1079
+ el.style.maxHeight = `${Math.max(50, availableHeight - padding * 2)}px`;
1080
+ } })] : []
1081
+ ]
1082
+ };
1083
+ const unfloat = autoUpdate(source, el, async () => {
1084
+ if (!source?.isConnected) return POPOVERS.get(el)?.();
1085
+ const { x, y } = await computePosition(source, el, options);
1086
+ el.style.translate = `${x}px ${y}px`;
1087
+ });
1088
+ POPOVERS.set(el, () => POPOVERS.delete(el) && unfloat());
1089
+ }
1090
+ let IS_SCROLL;
1091
+ const handleScrollbar = ({ type }) => {
1092
+ if (type === "mousedown") IS_SCROLL = false;
1093
+ if (type === "scroll" && IS_SCROLL === false) IS_SCROLL = true;
1094
+ if (type === "mouseup" && IS_SCROLL) for (const [popover] of POPOVERS) popover.showPopover();
1095
+ };
1096
+ onHotReload("popover", () => [on(document, "mousedown scroll mouseup", handleScrollbar, true), on(document, "toggle ds-toggle-source", handleToggle, QUICK_EVENT)]);
1097
+ const arrowPseudo = () => ({
1098
+ name: "arrowPseudo",
1099
+ fn(data) {
1100
+ const target = data.elements.floating;
1101
+ const source = data.rects.reference;
1102
+ const x = `${Math.round(source.width / 2 + source.x - data.x)}px`;
1103
+ const y = `${Math.round(source.height / 2 + source.y - data.y)}px`;
1104
+ target.style.setProperty("--_ds-floating-arrow-x", x);
1105
+ target.style.setProperty("--_ds-floating-arrow-y", y);
1106
+ attr(target, "data-floating", data.placement);
1107
+ return data;
1108
+ }
1109
+ });
1110
+ //#endregion
1111
+ //#region src/readonly/readonly.ts
1112
+ const isReadOnly = (el) => (el instanceof HTMLSelectElement || el instanceof HTMLInputElement) && (el.hasAttribute("readonly") || attr(el, "aria-readonly") === "true");
1113
+ const handleKeyDown = (e) => {
1114
+ if (e.key !== "Tab" && isReadOnly(e.target)) {
1115
+ const isArrow = e.key?.startsWith("Arrow");
1116
+ const isModifier = e.altKey || e.ctrlKey || e.metaKey;
1117
+ if (isArrow || !isModifier) e.preventDefault();
1118
+ if (isArrow && attr(e.target, "type") === "radio") {
1119
+ const all = document.querySelectorAll(`input[name="${e.target.name}"]`);
1120
+ const move = e.key?.match(/Arrow(Right|Down)/) ? 1 : -1;
1121
+ all[(all.length + [...all].indexOf(e.target) + move) % all.length]?.focus();
1122
+ }
1123
+ }
1124
+ };
1125
+ const handleClick = (e) => {
1126
+ const input = e.target?.closest?.("label")?.control || e.target;
1127
+ if (isReadOnly(input)) {
1128
+ e.preventDefault();
1129
+ input.focus();
1130
+ }
1131
+ };
1132
+ const handleMouseDown = (e) => {
1133
+ if (e.target instanceof HTMLSelectElement && isReadOnly(e.target)) e.preventDefault();
1134
+ };
1135
+ onHotReload("readonly", () => [
1136
+ on(document, "keydown", handleKeyDown),
1137
+ on(document, "click", handleClick),
1138
+ on(document, "mousedown", handleMouseDown)
1139
+ ]);
1140
+ //#endregion
1141
+ //#region src/toggle-group/toggle-group.ts
1142
+ const ARIA_LABELLEDBY = "aria-labelledby";
1143
+ const ARIA_LABEL$1 = "aria-label";
1144
+ const ATTR_TOGGLEGROUP = "data-toggle-group";
1145
+ const SELECTOR_TOGGLEGROUP = `[${ATTR_TOGGLEGROUP}]`;
1146
+ const handleAriaAttributes$1 = () => {
1147
+ for (const group of document.querySelectorAll(SELECTOR_TOGGLEGROUP)) attr(group, "aria-label", attrOrCSS(group, ATTR_TOGGLEGROUP));
1148
+ };
1149
+ const handleKeydown = (event) => {
1150
+ const { key, target: el } = event;
1151
+ const group = el instanceof HTMLInputElement && el.closest(SELECTOR_TOGGLEGROUP);
1152
+ if (!group) return;
1153
+ if (!attr(group, ARIA_LABEL$1) && !attr(group, ARIA_LABELLEDBY)) attr(group, ARIA_LABEL$1, attrOrCSS(group, ATTR_TOGGLEGROUP));
1154
+ if (key === "Enter") el.click();
1155
+ if (key?.startsWith("Arrow")) {
1156
+ event.preventDefault?.();
1157
+ const inputs = [...group.getElementsByTagName("input")];
1158
+ const index = inputs.indexOf(el);
1159
+ const move = key.match(/Arrow(Right|Down)/) ? 1 : -1;
1160
+ let nextIndex = index;
1161
+ for (let i = 0; i < inputs.length; i++) {
1162
+ nextIndex = (inputs.length + nextIndex + move) % inputs.length;
1163
+ if (!inputs[nextIndex]?.disabled) {
1164
+ inputs[nextIndex]?.focus();
1165
+ break;
1166
+ }
1167
+ }
1168
+ }
1169
+ };
1170
+ onHotReload("toggle-group", () => [on(document, "keydown", handleKeydown), onMutation(document, handleAriaAttributes$1, {
1171
+ attributeFilter: [ATTR_TOGGLEGROUP],
1172
+ attributes: true,
1173
+ childList: true,
1174
+ subtree: true
1175
+ })]);
1176
+ //#endregion
1177
+ //#region src/tooltip/tooltip.ts
1178
+ let TIP;
1179
+ let SOURCE;
1180
+ let IS_HOVERING = false;
1181
+ let HOVER_TIMER = 0;
1182
+ let SKIP_TIMER = 0;
1183
+ const IS_IOS = isBrowser() && /iPad|iPhone|iPod/.test(navigator.userAgent);
1184
+ const ATTR_TOOLTIP = "data-tooltip";
1185
+ const ATTR_COLOR = "data-color";
1186
+ const ARIA_LABEL = "aria-label";
1187
+ const ARIA_DESC = "aria-description";
1188
+ const SELECTOR_COLOR = `[${ATTR_COLOR}]`;
1189
+ const SELECTOR_TOOLTIP = `[${ATTR_TOOLTIP}]`;
1190
+ const ATTR_SCHEME = "data-color-scheme";
1191
+ const SELECTOR_SCHEME = `[${ATTR_SCHEME}]`;
1192
+ const SELECTOR_INTERACTIVE = "a,button,input,label,select,textarea,[tabindex]";
1193
+ const DELAY_HOVER = 300;
1194
+ const DELAY_SKIP = 300;
1195
+ /**
1196
+ * setTooltipElement
1197
+ * @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.
1198
+ * @param el The HTMLElement to use as tooltip
1199
+ */
1200
+ const setTooltipElement = (el) => {
1201
+ if (el && !(el instanceof HTMLElement)) warn("setTooltipElement expects an HTMLElement, got: ", el);
1202
+ clearTimeout(SKIP_TIMER);
1203
+ clearTimeout(HOVER_TIMER);
1204
+ SOURCE = void 0;
1205
+ IS_HOVERING = false;
1206
+ TIP = el || void 0;
1207
+ };
1208
+ const handleAriaAttributes = () => {
1209
+ for (const el of document.querySelectorAll(SELECTOR_TOOLTIP)) {
1210
+ const text = attrOrCSS(el, ATTR_TOOLTIP);
1211
+ if (!text) return;
1212
+ if (text !== (el.getAttribute(ARIA_LABEL) || el.getAttribute(ARIA_DESC))) {
1213
+ const hasText = attr(el, "role") !== "img" && el.textContent?.trim();
1214
+ attr(el, ATTR_TOOLTIP, text);
1215
+ attr(el, ARIA_LABEL, hasText ? null : text);
1216
+ attr(el, ARIA_DESC, hasText ? text : null);
1217
+ if (!el.matches(SELECTOR_INTERACTIVE)) warn("Missing tabindex=\"0\" attribute on: ", el);
1218
+ }
1219
+ const isCurrent = el === SOURCE && TIP?.offsetHeight && TIP?.offsetWidth;
1220
+ const isChanged = isCurrent && text && TIP?.textContent !== text;
1221
+ if (isCurrent && isChanged) {
1222
+ if (TIP) TIP.textContent = text;
1223
+ if (document.activeElement === el) announce(text);
1224
+ }
1225
+ }
1226
+ };
1227
+ const handleInterest = (event) => {
1228
+ const { type, target } = event;
1229
+ clearTimeout(HOVER_TIMER);
1230
+ if (target === TIP) return;
1231
+ const source = target?.closest?.(SELECTOR_TOOLTIP);
1232
+ if (type === "blur") {
1233
+ const next = event.relatedTarget;
1234
+ if (source === SOURCE && !next?.closest?.(SELECTOR_TOOLTIP)) hideTooltip();
1235
+ return;
1236
+ }
1237
+ if (type === "mouseover" && !IS_HOVERING && !IS_IOS) {
1238
+ HOVER_TIMER = setTimeout(handleInterest, DELAY_HOVER, { target });
1239
+ return;
1240
+ }
1241
+ if (source === SOURCE) return;
1242
+ if (!source) return hideTooltip();
1243
+ if (!TIP) TIP = tag("div", { class: "ds-tooltip" });
1244
+ if (!TIP.isConnected) document.body.appendChild(TIP);
1245
+ const color = source.closest(SELECTOR_COLOR);
1246
+ const scheme = source.closest(SELECTOR_SCHEME);
1247
+ const isReset = color !== scheme && color?.contains(scheme);
1248
+ clearTimeout(SKIP_TIMER);
1249
+ attr(TIP, "popover", "manual");
1250
+ attr(TIP, ATTR_SCHEME, scheme?.getAttribute(ATTR_SCHEME) || null);
1251
+ attr(TIP, ATTR_COLOR, isReset && color?.getAttribute(ATTR_COLOR) || null);
1252
+ TIP.textContent = attr(source, ATTR_TOOLTIP);
1253
+ TIP.showPopover();
1254
+ TIP.dispatchEvent(new CustomEvent("ds-toggle-source", { detail: source }));
1255
+ IS_HOVERING = true;
1256
+ SOURCE = source;
1257
+ };
1258
+ const hideTooltip = () => TIP?.isConnected && TIP.popover && TIP.hidePopover();
1259
+ const handleClose = (event) => {
1260
+ if (event?.type === "keydown") return event?.key === "Escape" && hideTooltip();
1261
+ if (!event) IS_HOVERING = false;
1262
+ else if (event.target === TIP && event.newState === "closed") {
1263
+ SOURCE = void 0;
1264
+ SKIP_TIMER = setTimeout(handleClose, DELAY_SKIP);
1265
+ }
1266
+ };
1267
+ onHotReload("tooltip", () => [
1268
+ on(document, "blur focus mouseover", handleInterest, QUICK_EVENT),
1269
+ on(document, "toggle keydown", handleClose, QUICK_EVENT),
1270
+ onMutation(document, handleAriaAttributes, {
1271
+ attributeFilter: [ATTR_TOOLTIP],
1272
+ attributes: true,
1273
+ childList: true,
1274
+ subtree: true
1275
+ })
1276
+ ]);
1277
+ //#endregion
1278
+ //#region src/breadcrumbs/breadcrumbs.ts
1279
+ const ATTR_LABEL$1 = "aria-label";
1280
+ var DSBreadcrumbsElement = class extends DSElement {
1281
+ _items;
1282
+ _label = null;
1283
+ _unresize;
1284
+ _unmutate;
1285
+ static get observedAttributes() {
1286
+ return [ATTR_LABEL$1];
1287
+ }
1288
+ connectedCallback() {
1289
+ const resize = debounce(() => render$3(this), 100);
1290
+ this._label = attrOrCSS(this, ATTR_LABEL$1);
1291
+ this._items = this.getElementsByTagName("a");
1292
+ this._unresize = on(window, "resize", resize);
1293
+ this._unmutate = onMutation(this, render$3, {
1294
+ childList: true,
1295
+ subtree: true
1296
+ });
1297
+ }
1298
+ attributeChangedCallback(_name, _prev, next) {
1299
+ if (!this._unmutate || !next) return;
1300
+ this._label = next;
1301
+ render$3(this);
1302
+ }
1303
+ disconnectedCallback() {
1304
+ this._unresize?.();
1305
+ this._unmutate?.();
1306
+ this._unresize = this._unmutate = this._items = void 0;
1307
+ }
1308
+ };
1309
+ const render$3 = (self) => {
1310
+ const lastItem = self._items?.[self._items.length - 1];
1311
+ const lastItemInList = lastItem?.parentElement === self ? null : lastItem;
1312
+ const isListHidden = !lastItemInList?.offsetHeight;
1313
+ attr(self, "role", isListHidden ? null : "navigation");
1314
+ attr(self, ATTR_LABEL$1, isListHidden ? null : self._label);
1315
+ for (const item of self._items || []) attr(item, "aria-current", item === lastItemInList ? "page" : null);
1316
+ };
1317
+ customElements.define("ds-breadcrumbs", DSBreadcrumbsElement);
1318
+ //#endregion
1319
+ //#region src/error-summary/error-summary.ts
1320
+ var DSErrorSummaryElement = class extends DSElement {
1321
+ _unmutate;
1322
+ connectedCallback() {
1323
+ on(this, "animationend", this, QUICK_EVENT);
1324
+ attr(this, "role", "group");
1325
+ attr(this, "tabindex", "-1");
1326
+ this._unmutate = onMutation(this, render$2, {
1327
+ childList: true,
1328
+ subtree: true
1329
+ });
1330
+ this.focus();
1331
+ }
1332
+ handleEvent({ target }) {
1333
+ if (target === this) this.focus();
1334
+ }
1335
+ disconnectedCallback() {
1336
+ off(this, "animationend", this, QUICK_EVENT);
1337
+ this._unmutate?.();
1338
+ this._unmutate = void 0;
1339
+ }
1340
+ };
1341
+ const render$2 = (self) => {
1342
+ const label = attr(self, "aria-label")?.trim();
1343
+ const labelledBy = attr(self, "aria-labelledby")?.trim();
1344
+ const heading = self.querySelector("h2,h3,h4,h5,h6");
1345
+ if (heading && !label && !labelledBy) attr(self, "aria-labelledby", useId(heading));
1346
+ if (!heading && !label && !labelledBy) warn("Missing accessible name on:", self, "\nAdd a heading (h2–h6), or set aria-label or aria-labelledby to provide an accessible name for screen readers.");
1347
+ };
1348
+ customElements.define("ds-error-summary", DSErrorSummaryElement);
1349
+ //#endregion
1350
+ //#region src/field/field.ts
1351
+ const ATTR_INVALID = "aria-invalid";
1352
+ const ATTR_DESCRIBEDBY = "aria-describedby";
1353
+ const ATTR_INDETERMINATE = "data-indeterminate";
1354
+ const COUNTER_DEBOUNCE = isWindows() ? 800 : 200;
1355
+ const COUNTS = /* @__PURE__ */ new WeakMap();
1356
+ const FIELDS = /* @__PURE__ */ new Map();
1357
+ const VALIDATIONS = /* @__PURE__ */ new WeakSet();
1358
+ const WARNING_MULTIPLE_INPUTS = `Fields should only have one input element. Use <fieldset> to group multiple fields:`;
1359
+ const handleFieldMutations = (_doc, records = []) => {
1360
+ for (const { target } of records) {
1361
+ const isFieldset = target instanceof HTMLFieldSetElement;
1362
+ for (const [field] of FIELDS) if (isFieldset ? target.contains(field) : field.contains(target)) handleFieldMutation(field);
1363
+ }
1364
+ };
1365
+ const handleFieldMutation = (field) => {
1366
+ const labels = [];
1367
+ const nextDescs = [];
1368
+ const prevDescs = FIELDS.get(field) || [];
1369
+ let input;
1370
+ let counter;
1371
+ let hasValidation = false;
1372
+ let invalid = false;
1373
+ for (const el of field.getElementsByTagName("*")) {
1374
+ if (el instanceof HTMLLabelElement) labels.push(el);
1375
+ if (el.hidden) continue;
1376
+ if (isInputLike(el)) if (input) warn(WARNING_MULTIPLE_INPUTS, field);
1377
+ else input = el;
1378
+ else {
1379
+ const type = el.getAttribute("data-field");
1380
+ if (type === "counter") counter = el;
1381
+ if (type === "validation") {
1382
+ nextDescs.unshift(useId(el));
1383
+ hasValidation = true;
1384
+ invalid = invalid || isInvalid(el);
1385
+ } else if (type) nextDescs.push(useId(el));
1386
+ }
1387
+ }
1388
+ if (!input) return;
1389
+ if (counter) COUNTS.set(input, counter);
1390
+ for (const label of labels) attr(label, "for", useId(input));
1391
+ const fieldsetValidation = field.closest("fieldset")?.querySelector(":scope > [data-field=\"validation\"]");
1392
+ if (fieldsetValidation && !fieldsetValidation?.hidden) {
1393
+ hasValidation = true;
1394
+ invalid = invalid || isInvalid(fieldsetValidation);
1395
+ nextDescs.unshift(useId(fieldsetValidation));
1396
+ }
1397
+ const indeterminate = attr(input, ATTR_INDETERMINATE);
1398
+ if (indeterminate) input.indeterminate = indeterminate === "true";
1399
+ if (input.type === "radio" || input.type === "checkbox") attr(field, "data-clickdelegatefor", useId(input));
1400
+ const keep = (attr(input, ATTR_DESCRIBEDBY)?.trim().split(/\s+/))?.filter((id) => !prevDescs.includes(id)) || [];
1401
+ attr(input, ATTR_DESCRIBEDBY, [...nextDescs, ...keep].join(" ") || null);
1402
+ FIELDS.set(field, nextDescs);
1403
+ const hadValidation = VALIDATIONS.has(input);
1404
+ if (hasValidation && !hadValidation && !input.hasAttribute(ATTR_INVALID)) {
1405
+ attr(input, ATTR_INVALID, "true");
1406
+ VALIDATIONS.add(input);
1407
+ } else if (!hasValidation && hadValidation) {
1408
+ attr(input, ATTR_INVALID, null);
1409
+ VALIDATIONS.delete(input);
1410
+ }
1411
+ handleFieldInput(input);
1412
+ };
1413
+ const TEXTS = {
1414
+ over: "%d tegn for mye",
1415
+ under: "%d tegn igjen"
1416
+ };
1417
+ const handleFieldInput = (e) => {
1418
+ const input = e.target || e;
1419
+ const counter = COUNTS.get(input);
1420
+ if (counter?.isConnected) {
1421
+ const count = (Number(attr(counter, "data-limit")) || 0) - input.value.length;
1422
+ const state = count < 0 ? "over" : "under";
1423
+ const label = (attrOrCSS(counter, `data-${state}`) || TEXTS[state])?.replace("%d", `${Math.abs(count)}`);
1424
+ attr(counter, "data-label", label);
1425
+ attr(counter, "data-state", state);
1426
+ attr(counter, "data-color", count < 0 ? "danger" : null);
1427
+ if (e.type === "input" && label) debouncedCounterLiveRegion(input, label);
1428
+ }
1429
+ if (input instanceof HTMLTextAreaElement) {
1430
+ input.style.setProperty("--_ds-field-sizing", "auto");
1431
+ input.style.setProperty("--_ds-field-sizing", `${input.scrollHeight}px`);
1432
+ }
1433
+ };
1434
+ const debouncedCounterLiveRegion = debounce((input, text) => {
1435
+ if (document.activeElement === input) announce(text);
1436
+ }, COUNTER_DEBOUNCE);
1437
+ const isInvalid = (el) => el.getAttribute("data-color") !== "success";
1438
+ const isInputLike = (el) => el instanceof HTMLElement && "validity" in el && !(el instanceof HTMLButtonElement) && el.type !== "hidden";
1439
+ var DSFieldElement = class extends DSElement {
1440
+ connectedCallback() {
1441
+ FIELDS.set(this, []);
1442
+ handleFieldMutation(this);
1443
+ }
1444
+ disconnectedCallback() {
1445
+ FIELDS.delete(this);
1446
+ }
1447
+ };
1448
+ customElements.define("ds-field", DSFieldElement);
1449
+ onHotReload("field", () => [on(document, "input", handleFieldInput, QUICK_EVENT), onMutation(document, handleFieldMutations, {
1450
+ attributeFilter: [
1451
+ "data-field",
1452
+ "data-limit",
1453
+ "hidden",
1454
+ "id",
1455
+ "value",
1456
+ ATTR_INDETERMINATE
1457
+ ],
1458
+ attributes: true,
1459
+ childList: true,
1460
+ subtree: true
1461
+ })]);
1462
+ //#endregion
1463
+ //#region src/pagination/pagination.ts
1464
+ const ATTR_LABEL = "aria-label";
1465
+ const ATTR_CURRENT = "data-current";
1466
+ const ATTR_TOTAL = "data-total";
1467
+ const ATTR_HREF = "data-href";
1468
+ const pagination = ({ current = 1, total = 10, show = 7 }) => ({
1469
+ prev: current > 1 ? current - 1 : 0,
1470
+ next: current < total ? current + 1 : 0,
1471
+ pages: getSteps(current, total, show).map((page, index) => ({
1472
+ current: page === current && "page",
1473
+ key: `key-${page}-${index}`,
1474
+ page
1475
+ }))
1476
+ });
1477
+ var DSPaginationElement = class extends DSElement {
1478
+ _unmutate;
1479
+ _render;
1480
+ static get observedAttributes() {
1481
+ return [
1482
+ ATTR_LABEL,
1483
+ ATTR_CURRENT,
1484
+ ATTR_TOTAL,
1485
+ ATTR_HREF
1486
+ ];
1487
+ }
1488
+ connectedCallback() {
1489
+ const total = attr(this, ATTR_TOTAL);
1490
+ const current = attr(this, ATTR_CURRENT);
1491
+ if (current && !total) warn(`Missing ${ATTR_TOTAL} attribute on:`, this);
1492
+ if (total && !current) warn(`Missing ${ATTR_CURRENT} attribute on:`, this);
1493
+ attr(this, ATTR_LABEL, attrOrCSS(this, ATTR_LABEL));
1494
+ attr(this, "role", "navigation");
1495
+ this._unmutate = onMutation(this, render$1, {
1496
+ childList: true,
1497
+ subtree: true
1498
+ });
1499
+ }
1500
+ attributeChangedCallback() {
1501
+ if (this._unmutate) render$1(this);
1502
+ }
1503
+ disconnectedCallback() {
1504
+ this._unmutate?.();
1505
+ this._unmutate = this._render = void 0;
1506
+ }
1507
+ };
1508
+ const render$1 = (self) => {
1509
+ const current = Number(attr(self, ATTR_CURRENT));
1510
+ const total = Number(attr(self, ATTR_TOTAL));
1511
+ if (current && total) {
1512
+ const items = self.querySelectorAll("button,a");
1513
+ const show = items.length - 2;
1514
+ const href = attr(self, ATTR_HREF);
1515
+ const { next, prev, pages } = pagination({
1516
+ current,
1517
+ total,
1518
+ show
1519
+ });
1520
+ items.forEach((item, i) => {
1521
+ const page = i ? items[i + 1] ? pages[i - 1]?.page : next : prev;
1522
+ attr(item, "aria-current", pages[i - 1]?.current ? "true" : null);
1523
+ attr(item, "aria-label", `${page ?? "hidden"}`);
1524
+ attr(item, "role", page ? null : "none");
1525
+ attr(item, "tabindex", page ? null : "-1");
1526
+ if (item instanceof HTMLButtonElement) attr(item, "value", `${page}`);
1527
+ if (href && item instanceof HTMLAnchorElement) attr(item, "href", href.replace("%d", `${page}`));
1528
+ });
1529
+ }
1530
+ };
1531
+ const getSteps = (now, max, show = Number.POSITIVE_INFINITY) => {
1532
+ const offset = (show - 1) / 2;
1533
+ const start = Math.max(Math.min(now - Math.floor(offset), max - show + 1), 1);
1534
+ const end = Math.min(Math.max(now + Math.ceil(offset), show), max);
1535
+ const pages = Array.from({ length: end + 1 - start }, (_, i) => i + start);
1536
+ if (show > 4 && start > 1) pages.splice(0, 2, 1, 0);
1537
+ if (show > 3 && end < max) pages.splice(-2, 2, 0, max);
1538
+ return pages;
1539
+ };
1540
+ customElements.define("ds-pagination", DSPaginationElement);
1541
+ //#endregion
1542
+ //#region src/suggestion/suggestion.ts
1543
+ var DSSuggestionElement = class extends UHTMLComboboxElement {
1544
+ _unmutate;
1545
+ connectedCallback() {
1546
+ super.connectedCallback();
1547
+ this._unmutate = onMutation(this, render, { childList: true });
1548
+ on(this, "toggle", polyfillToggleSource, QUICK_EVENT);
1549
+ }
1550
+ disconnectedCallback() {
1551
+ super.disconnectedCallback();
1552
+ this._unmutate?.();
1553
+ this._unmutate = void 0;
1554
+ off(this, "toggle", polyfillToggleSource, QUICK_EVENT);
1555
+ }
1556
+ };
1557
+ const render = (self) => {
1558
+ const { control, list } = self;
1559
+ const datalist = list || self.querySelector("u-datalist");
1560
+ if (control && !control.placeholder) attr(control, "placeholder", " ");
1561
+ if (control) attr(control, "popovertarget", useId(list) || null);
1562
+ if (datalist) attr(datalist, "popover", "manual");
1563
+ if (datalist) attr(datalist, "data-is-floating", "true");
1564
+ };
1565
+ const polyfillToggleSource = (event) => {
1566
+ const self = event.currentTarget;
1567
+ const detail = event.newState === "open" && self.control;
1568
+ if (detail) self.list?.dispatchEvent(new CustomEvent("ds-toggle-source", { detail }));
1569
+ };
1570
+ customElements.define("ds-suggestion", DSSuggestionElement);
1571
+ //#endregion
1572
+ //#region src/tabs/tabs.ts
1573
+ var DSTabsElement = class extends UTabs.UHTMLTabsElement {};
1574
+ var DSTabListElement = class extends UTabs.UHTMLTabListElement {};
1575
+ var DSTabElement = class extends UTabs.UHTMLTabElement {};
1576
+ var DSTabPanelElement = class extends UTabs.UHTMLTabPanelElement {};
1577
+ customElements.define("ds-tabs", DSTabsElement);
1578
+ customElements.define("ds-tablist", DSTabListElement);
1579
+ customElements.define("ds-tab", DSTabElement);
1580
+ customElements.define("ds-tabpanel", DSTabPanelElement);
1581
+ //#endregion
1582
+ export { DSBreadcrumbsElement, DSErrorSummaryElement, DSFieldElement, DSPaginationElement, DSSuggestionElement, DSTabElement, DSTabListElement, DSTabPanelElement, DSTabsElement, pagination, setTooltipElement };
1583
+
1584
+ //# sourceMappingURL=index.js.map