@oscarpalmer/oui 0.18.0 → 0.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.
Files changed (44) hide show
  1. package/dist/css/badge.css +10 -10
  2. package/dist/css/button.css +9 -9
  3. package/dist/css/color.css +99 -99
  4. package/dist/css/content.css +1 -1
  5. package/dist/css/flex.css +39 -39
  6. package/dist/css/form.css +29 -56
  7. package/dist/css/message.css +6 -6
  8. package/dist/css/reset.css +3 -2
  9. package/dist/css/table.css +4 -4
  10. package/dist/css/tooltip.css +18 -1
  11. package/dist/js/attributable.full.js +29 -41
  12. package/dist/js/floatable.full.js +322 -337
  13. package/dist/js/focus-trap/embedded.full.js +252 -195
  14. package/dist/js/focus-trap/standalone.full.js +283 -238
  15. package/dist/js/index.js +3 -3
  16. package/dist/js/oui.full.js +1170 -1193
  17. package/dist/js/popover.full.js +568 -630
  18. package/dist/js/popover.js +1 -1
  19. package/dist/js/splitter.full.js +533 -369
  20. package/dist/js/splitter.js +2 -2
  21. package/dist/js/tooltip.full.js +488 -554
  22. package/dist/js/tooltip.js +1 -1
  23. package/package.json +19 -19
  24. package/src/css/a11y.scss +1 -1
  25. package/src/css/badge.scss +23 -19
  26. package/src/css/button.scss +9 -9
  27. package/src/css/color.scss +99 -99
  28. package/src/css/content.scss +6 -8
  29. package/src/css/flex.scss +21 -20
  30. package/src/css/form.scss +37 -60
  31. package/src/css/message.scss +8 -12
  32. package/src/css/mixins.scss +11 -12
  33. package/src/css/popover.scss +2 -2
  34. package/src/css/reset.scss +14 -14
  35. package/src/css/splitter.scss +15 -13
  36. package/src/css/table.scss +11 -11
  37. package/src/css/tooltip.scss +25 -4
  38. package/src/js/attributable.ts +3 -10
  39. package/src/js/floatable.ts +7 -25
  40. package/src/js/focus-trap/embedded.ts +6 -24
  41. package/src/js/popover.ts +3 -3
  42. package/src/js/splitter.ts +9 -39
  43. package/src/js/tooltip.ts +5 -17
  44. package/dist/css/value.css +0 -1
@@ -1,50 +1,38 @@
1
1
  function attributable(attribute, add, remove) {
2
- const observer = new MutationObserver(entries => {
3
- const { length } = entries;
4
- for (let index = 0; index < length; index += 1) {
5
- const entry = entries[index];
6
- if (entry.type === 'attributes' && entry.target instanceof HTMLElement) {
7
- if (entry.target.hasAttribute(attribute)) {
8
- handleAdded(attribute, [entry.target], add);
9
- }
10
- else {
11
- handleRemoved([entry.target], remove);
12
- }
13
- }
14
- else if (entry.type === 'childList') {
15
- handleAdded(attribute, entry.addedNodes, add);
16
- handleRemoved(entry.removedNodes, remove);
17
- }
18
- }
19
- });
20
- observer.observe(document, {
21
- attributeFilter: [attribute],
22
- attributes: true,
23
- childList: true,
24
- subtree: true,
25
- });
26
- requestAnimationFrame(() => {
27
- handleAdded(attribute, document.querySelectorAll(`[${attribute}]`), add);
28
- });
2
+ new MutationObserver((entries) => {
3
+ const { length } = entries;
4
+ for (let index$3 = 0; index$3 < length; index$3 += 1) {
5
+ const entry = entries[index$3];
6
+ if (entry.type === "attributes" && entry.target instanceof HTMLElement) if (entry.target.hasAttribute(attribute)) handleAdded(attribute, [entry.target], add);
7
+ else handleRemoved([entry.target], remove);
8
+ else if (entry.type === "childList") {
9
+ handleAdded(attribute, entry.addedNodes, add);
10
+ handleRemoved(entry.removedNodes, remove);
11
+ }
12
+ }
13
+ }).observe(document, {
14
+ attributeFilter: [attribute],
15
+ attributes: true,
16
+ childList: true,
17
+ subtree: true
18
+ });
19
+ requestAnimationFrame(() => {
20
+ handleAdded(attribute, document.querySelectorAll(`[${attribute}]`), add);
21
+ });
29
22
  }
30
23
  function handleAdded(attribute, nodes, add) {
31
- const elements = [...nodes].filter(node => node instanceof HTMLElement);
32
- const { length } = elements;
33
- for (let index = 0; index < length; index += 1) {
34
- const element = elements[index];
35
- if (element.hasAttribute(attribute)) {
36
- add(element);
37
- }
38
- }
24
+ const elements = [...nodes].filter((node) => node instanceof HTMLElement);
25
+ const { length } = elements;
26
+ for (let index$3 = 0; index$3 < length; index$3 += 1) {
27
+ const element = elements[index$3];
28
+ if (element.hasAttribute(attribute)) add(element);
29
+ }
39
30
  }
40
31
  function handleRemoved(nodes, remove) {
41
- const elements = [...nodes].filter(node => node instanceof HTMLElement);
42
- const { length } = elements;
43
- for (let index = 0; index < length; index += 1) {
44
- remove(elements[index]);
45
- }
32
+ const elements = [...nodes].filter((node) => node instanceof HTMLElement);
33
+ const { length } = elements;
34
+ for (let index$3 = 0; index$3 < length; index$3 += 1) remove(elements[index$3]);
46
35
  }
47
-
48
36
  function isNumber(value) {
49
37
  return typeof value === "number" && !Number.isNaN(value);
50
38
  }
@@ -54,7 +42,6 @@ function isPlainObject(value) {
54
42
  const prototype = Object.getPrototypeOf(value);
55
43
  return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
56
44
  }
57
-
58
45
  function clamp(value, minimum, maximum, loop) {
59
46
  if (![
60
47
  value,
@@ -64,72 +51,192 @@ function clamp(value, minimum, maximum, loop) {
64
51
  if (value < minimum) return loop === true ? maximum : minimum;
65
52
  return value > maximum ? loop === true ? minimum : maximum : value;
66
53
  }
67
-
68
- function isEventTarget(value) {
69
- return typeof value === "object" && value != null && typeof value.addEventListener === "function" && typeof value.removeEventListener === "function" && typeof value.dispatchEvent === "function";
70
- }
71
- function isHTMLOrSVGElement(value) {
72
- return value instanceof HTMLElement || value instanceof SVGElement;
73
- }
74
-
75
54
  function compact(array, strict) {
76
55
  if (!Array.isArray(array)) return [];
56
+ if (strict === true) return array.filter(Boolean);
77
57
  const { length } = array;
78
58
  const compacted = [];
79
- for (let index = 0; index < length; index += 1) {
80
- const item = array[index];
59
+ for (let index$3 = 0; index$3 < length; index$3 += 1) {
60
+ const item = array[index$3];
81
61
  if (item != null) compacted.push(item);
82
62
  }
83
63
  return compacted;
84
64
  }
85
-
86
65
  function getString(value) {
87
66
  if (typeof value === "string") return value;
88
67
  if (value == null) return "";
68
+ if (typeof value === "function") return getString(value());
89
69
  if (typeof value !== "object") return String(value);
90
70
  const asString = String(value.valueOf?.() ?? value);
91
71
  return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
92
72
  }
93
73
  function join(value, delimiter) {
94
- return compact(value).map(getString).join(delimiter );
74
+ return compact(value).map(getString).join(typeof delimiter === "string" ? delimiter : "");
95
75
  }
96
76
  function words(value) {
97
77
  return typeof value === "string" ? value.match(EXPRESSION_WORDS) ?? [] : [];
98
78
  }
99
79
  var EXPRESSION_WORDS = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
100
-
80
+ function noop() {}
81
+ function calculate() {
82
+ return new Promise((resolve) => {
83
+ const values = [];
84
+ let last;
85
+ function step(now) {
86
+ if (last != null) values.push(now - last);
87
+ last = now;
88
+ if (values.length >= TOTAL) resolve(values.sort().slice(TRIM_PART, -TRIM_PART).reduce((first, second) => first + second, 0) / (values.length - TRIM_TOTAL));
89
+ else requestAnimationFrame(step);
90
+ }
91
+ requestAnimationFrame(step);
92
+ });
93
+ }
94
+ var TOTAL = 10;
95
+ var TRIM_PART = 2;
96
+ var TRIM_TOTAL = 4;
97
+ await calculate();
98
+ var SizedMap = class extends Map {
99
+ #maximumSize;
100
+ get full() {
101
+ return this.size >= this.#maximumSize;
102
+ }
103
+ get maximum() {
104
+ return this.#maximumSize;
105
+ }
106
+ constructor(first, second) {
107
+ const maximum = getMaximum(first, second);
108
+ super();
109
+ this.#maximumSize = maximum;
110
+ if (Array.isArray(first)) {
111
+ const { length } = first;
112
+ if (length <= maximum) for (let index$3 = 0; index$3 < length; index$3 += 1) this.set(...first[index$3]);
113
+ else for (let index$3 = 0; index$3 < maximum; index$3 += 1) this.set(...first[length - maximum + index$3]);
114
+ }
115
+ }
116
+ get(key) {
117
+ const value = super.get(key);
118
+ if (value !== void 0 || this.has(key)) this.set(key, value);
119
+ return value;
120
+ }
121
+ set(key, value) {
122
+ if (this.has(key)) this.delete(key);
123
+ else if (this.size >= this.#maximumSize) this.delete(this.keys().next().value);
124
+ return super.set(key, value);
125
+ }
126
+ };
127
+ function getMaximum(first, second) {
128
+ let actual;
129
+ if (typeof first === "number") actual = first;
130
+ else actual = typeof second === "number" ? second : MAXIMUM_DEFAULT;
131
+ return clamp(actual, 1, MAXIMUM_ABSOLUTE);
132
+ }
133
+ var MAXIMUM_ABSOLUTE = 16777216;
134
+ var MAXIMUM_DEFAULT = 1048576;
135
+ var Memoized = class {
136
+ #state;
137
+ get maximum() {
138
+ return this.#state.cache?.maximum ?? NaN;
139
+ }
140
+ get size() {
141
+ return this.#state.cache?.size ?? NaN;
142
+ }
143
+ constructor(callback, options) {
144
+ const cache = new SizedMap(options.cacheSize);
145
+ const getter = (...parameters) => {
146
+ const key = options.cacheKey?.(...parameters) ?? (parameters.length === 1 ? parameters[0] : join(parameters.map(getString), "_"));
147
+ if (cache.has(key)) return cache.get(key);
148
+ const value = callback(...parameters);
149
+ cache.set(key, value);
150
+ return value;
151
+ };
152
+ this.#state = {
153
+ cache,
154
+ getter
155
+ };
156
+ }
157
+ clear() {
158
+ this.#state.cache?.clear();
159
+ }
160
+ delete(key) {
161
+ return this.#state.cache?.delete(key) ?? false;
162
+ }
163
+ destroy() {
164
+ this.#state.cache?.clear();
165
+ this.#state.cache = void 0;
166
+ this.#state.getter = void 0;
167
+ }
168
+ get(key) {
169
+ return this.#state.cache?.get(key);
170
+ }
171
+ has(key) {
172
+ return this.#state.cache?.has(key) ?? false;
173
+ }
174
+ run(...parameters) {
175
+ if (this.#state.cache == null || this.#state.getter == null) throw new Error("The Memoized instance has been destroyed");
176
+ return this.#state.getter(...parameters);
177
+ }
178
+ };
179
+ function getMemoizationOptions(input) {
180
+ const { cacheKey, cacheSize } = isPlainObject(input) ? input : {};
181
+ return {
182
+ cacheKey: typeof cacheKey === "function" ? cacheKey : void 0,
183
+ cacheSize: typeof cacheSize === "number" && cacheSize > 0 ? cacheSize : DEFAULT_CACHE_SIZE
184
+ };
185
+ }
186
+ function memoize(callback, options) {
187
+ return new Memoized(callback, getMemoizationOptions(options));
188
+ }
189
+ var DEFAULT_CACHE_SIZE = 1024;
101
190
  function camelCase(value) {
102
- return toCase(value, "");
191
+ return toCase("camel", value, true, false);
103
192
  }
104
193
  function capitalize(value) {
105
194
  if (typeof value !== "string" || value.length === 0) return "";
106
- return value.length === 1 ? value.toLocaleUpperCase() : `${value.charAt(0).toLocaleUpperCase()}${value.slice(1).toLocaleLowerCase()}`;
107
- }
108
- function toCase(value, delimiter, capitalizeAny, capitalizeFirst) {
195
+ memoizedCapitalize ??= memoize((v) => v.length === 1 ? v.toLocaleUpperCase() : `${v.charAt(0).toLocaleUpperCase()}${v.slice(1).toLocaleLowerCase()}`);
196
+ return memoizedCapitalize.run(value);
197
+ }
198
+ function toCase(type, value, capitalizeAny, capitalizeFirst) {
199
+ memoizers[type] ??= memoize(toCaseCallback.bind({
200
+ type,
201
+ capitalizeAny,
202
+ capitalizeFirst
203
+ }));
204
+ return memoizers[type].run(value);
205
+ }
206
+ function toCaseCallback(value) {
109
207
  if (typeof value !== "string") return "";
110
208
  if (value.length < 1) return value;
209
+ const { capitalizeAny, capitalizeFirst, type } = this;
111
210
  const parts = words(value);
112
211
  const partsLength = parts.length;
113
212
  const result = [];
114
213
  for (let partIndex = 0; partIndex < partsLength; partIndex += 1) {
115
- const items = parts[partIndex].replace(EXPRESSION_ACRONYM, (full, one, two, three) => three === "s" ? full : `${one}-${two}${three}`).replace(EXPRESSION_CAMEL_CASE, "$1-$2").split("-");
214
+ const items = parts[partIndex].replace(EXPRESSION_ACRONYM, (full, one, two, three) => three === "s" ? full : `${one}-${two}${three}`).replace(EXPRESSION_CAMEL_CASE, REPLACEMENT_CAMEL_CASE).split("-");
116
215
  const itemsLength = items.length;
117
216
  const partResult = [];
118
217
  let itemCount = 0;
119
218
  for (let itemIndex = 0; itemIndex < itemsLength; itemIndex += 1) {
120
219
  const item = items[itemIndex];
121
220
  if (item.length === 0) continue;
122
- if (itemCount === 0 && partIndex === 0 && true) partResult.push(item.toLocaleLowerCase());
221
+ if (!capitalizeAny || itemCount === 0 && partIndex === 0 && !capitalizeFirst) partResult.push(item.toLocaleLowerCase());
123
222
  else partResult.push(capitalize(item));
124
223
  itemCount += 1;
125
224
  }
126
- result.push(join(partResult, delimiter));
225
+ result.push(join(partResult, delimiters[type]));
127
226
  }
128
- return join(result, delimiter);
227
+ return join(result, delimiters[type]);
129
228
  }
130
229
  var EXPRESSION_CAMEL_CASE = /(\p{Ll})(\p{Lu})/gu;
131
230
  var EXPRESSION_ACRONYM = /(\p{Lu}*)(\p{Lu})(\p{Ll}+)/gu;
132
-
231
+ var REPLACEMENT_CAMEL_CASE = "$1-$2";
232
+ var delimiters = {
233
+ camel: "",
234
+ kebab: "-",
235
+ pascal: "",
236
+ snake: "_"
237
+ };
238
+ var memoizers = {};
239
+ var memoizedCapitalize;
133
240
  function getBoolean(value, defaultValue) {
134
241
  return typeof value === "boolean" ? value : defaultValue ?? false;
135
242
  }
@@ -137,39 +244,103 @@ function getStyleValue(element, property, computed) {
137
244
  const name = camelCase(property);
138
245
  return computed ? getComputedStyle(element)[name] : element.style[name];
139
246
  }
140
-
141
- function isNullableOrWhitespace(value) {
142
- return value == null || EXPRESSION_WHITESPACE$1.test(getString(value));
247
+ function isEventTarget(value) {
248
+ return typeof value === "object" && value != null && typeof value.addEventListener === "function" && typeof value.removeEventListener === "function" && typeof value.dispatchEvent === "function";
143
249
  }
144
- var EXPRESSION_WHITESPACE$1 = /^\s*$/;
145
-
146
- function calculate() {
147
- return new Promise((resolve) => {
148
- const values = [];
149
- let last;
150
- function step(now) {
151
- if (last != null) values.push(now - last);
152
- last = now;
153
- if (values.length >= CALCULATION_TOTAL) {
154
- const median = values.sort().slice(2, -2).reduce((first, second) => first + second, 0) / (values.length - CALCULATION_TRIM);
155
- resolve(median);
156
- } else requestAnimationFrame(step);
250
+ function isHTMLOrSVGElement(value) {
251
+ return value instanceof HTMLElement || value instanceof SVGElement;
252
+ }
253
+ function addDelegatedHandler(doc, type, name, passive) {
254
+ if (DELEGATED.has(name)) return;
255
+ DELEGATED.add(name);
256
+ doc.addEventListener(type, passive ? HANDLER_PASSIVE : HANDLER_ACTIVE, { passive });
257
+ }
258
+ function addDelegatedListener(target, type, name, listener, passive) {
259
+ target[name] ??= /* @__PURE__ */ new Set();
260
+ target[name].add(listener);
261
+ addDelegatedHandler(document, type, name, passive);
262
+ return () => {
263
+ removeDelegatedListener(target, name, listener);
264
+ };
265
+ }
266
+ function delegatedEventHandler(event) {
267
+ const key = `${EVENT_PREFIX}${event.type}${this ? EVENT_SUFFIX_PASSIVE : EVENT_SUFFIX_ACTIVE}`;
268
+ const items = event.composedPath();
269
+ const { length } = items;
270
+ let target = items[0];
271
+ Object.defineProperties(event, {
272
+ currentTarget: {
273
+ configurable: true,
274
+ get() {
275
+ return target;
276
+ }
277
+ },
278
+ target: {
279
+ configurable: true,
280
+ value: target
157
281
  }
158
- requestAnimationFrame(step);
159
282
  });
283
+ for (let index$3 = 0; index$3 < length; index$3 += 1) {
284
+ const item = items[index$3];
285
+ const listeners = item[key];
286
+ if (item.disabled || listeners == null) continue;
287
+ target = item;
288
+ for (const listener of listeners) {
289
+ listener.call(item, event);
290
+ if (event.cancelBubble) return;
291
+ }
292
+ }
160
293
  }
161
- function noop() {}
162
- var CALCULATION_TOTAL = 10;
163
- var CALCULATION_TRIM = 4;
164
- calculate().then((value) => {
165
- });
166
-
294
+ function getDelegatedName(target, type, options) {
295
+ if (isEventTarget(target) && EVENT_TYPES.has(type) && !options.capture && !options.once && options.signal == null) return `${EVENT_PREFIX}${type}${options.passive ? EVENT_SUFFIX_PASSIVE : EVENT_SUFFIX_ACTIVE}`;
296
+ }
297
+ function removeDelegatedListener(target, name, listener) {
298
+ const handlers = target[name];
299
+ if (handlers == null || !handlers.has(listener)) return false;
300
+ handlers.delete(listener);
301
+ if (handlers.size === 0) target[name] = void 0;
302
+ return true;
303
+ }
304
+ var DELEGATED = /* @__PURE__ */ new Set();
305
+ var EVENT_PREFIX = "@";
306
+ var EVENT_SUFFIX_ACTIVE = ":active";
307
+ var EVENT_SUFFIX_PASSIVE = ":passive";
308
+ var EVENT_TYPES = new Set([
309
+ "beforeinput",
310
+ "click",
311
+ "dblclick",
312
+ "contextmenu",
313
+ "focusin",
314
+ "focusout",
315
+ "input",
316
+ "keydown",
317
+ "keyup",
318
+ "mousedown",
319
+ "mousemove",
320
+ "mouseout",
321
+ "mouseover",
322
+ "mouseup",
323
+ "pointerdown",
324
+ "pointermove",
325
+ "pointerout",
326
+ "pointerover",
327
+ "pointerup",
328
+ "touchend",
329
+ "touchmove",
330
+ "touchstart"
331
+ ]);
332
+ var HANDLER_ACTIVE = delegatedEventHandler.bind(false);
333
+ var HANDLER_PASSIVE = delegatedEventHandler.bind(true);
334
+ function isNullableOrWhitespace(value) {
335
+ return value == null || EXPRESSION_WHITESPACE$1.test(getString(value));
336
+ }
337
+ var EXPRESSION_WHITESPACE$1 = /^\s*$/;
167
338
  function createEventOptions(options) {
168
339
  return {
169
340
  capture: getBoolean(options?.capture),
170
341
  once: getBoolean(options?.once),
171
342
  passive: getBoolean(options?.passive, true),
172
- signal: options?.signal
343
+ signal: options?.signal instanceof AbortSignal ? options.signal : void 0
173
344
  };
174
345
  }
175
346
  function getPosition(event) {
@@ -190,12 +361,14 @@ function getPosition(event) {
190
361
  function on(target, type, listener, options) {
191
362
  if (!isEventTarget(target) || typeof type !== "string" || typeof listener !== "function") return noop;
192
363
  const extended = createEventOptions(options);
364
+ const delegated = getDelegatedName(target, type, extended);
365
+ if (delegated != null) return addDelegatedListener(target, type, delegated, listener, extended.passive);
193
366
  target.addEventListener(type, listener, extended);
367
+ if (extended.once) return noop;
194
368
  return () => {
195
369
  target.removeEventListener(type, listener, extended);
196
370
  };
197
371
  }
198
-
199
372
  function findAncestor(origin, selector) {
200
373
  if (!(origin instanceof Element) || selector == null) return null;
201
374
  if (typeof selector === "string") {
@@ -211,26 +384,42 @@ function findAncestor(origin, selector) {
211
384
  }
212
385
  return parent;
213
386
  }
214
-
215
387
  function getFocusable(parent) {
216
- return getValidElements(parent, FILTERS_FOCUSABLE);
388
+ return getValidElements(parent, FILTERS_FOCUSABLE, false);
217
389
  }
218
390
  function getItem(element, tabbable) {
219
391
  return {
220
392
  element,
221
- tabIndex: TABINDEX_DEFAULT
393
+ tabIndex: tabbable ? getTabIndex(element) : TABINDEX_DEFAULT
222
394
  };
223
395
  }
396
+ function getTabIndex(element) {
397
+ const tabIndex = element?.tabIndex ?? TABINDEX_DEFAULT;
398
+ if (tabIndex < TABINDEX_BASE && (EXPRESSION_SPECIAL_TABINDEX.test(element.tagName) || isEditable(element)) && !hasTabIndex(element)) return TABINDEX_BASE;
399
+ return tabIndex;
400
+ }
224
401
  function getValidElements(parent, filters, tabbable) {
225
402
  if (!(parent instanceof Element)) return [];
226
403
  const elements = [...parent.querySelectorAll(SELECTOR_FULL$1)];
227
404
  const items = [];
228
405
  let { length } = elements;
229
- for (let index = 0; index < length; index += 1) {
230
- const item = getItem(elements[index]);
406
+ for (let index$3 = 0; index$3 < length; index$3 += 1) {
407
+ const item = getItem(elements[index$3], tabbable);
231
408
  if (!filters.some((filter) => filter(item))) items.push(item);
232
409
  }
233
- return items.map((item) => item.element);
410
+ if (!tabbable) return items.map((item) => item.element);
411
+ const indiced = [];
412
+ const zeroed = [];
413
+ length = items.length;
414
+ for (let index$3 = 0; index$3 < length; index$3 += 1) {
415
+ const item = items[index$3];
416
+ if (item.tabIndex === TABINDEX_BASE) zeroed.push(item.element);
417
+ else indiced[item.tabIndex] = [...indiced[item.tabIndex] ?? [], item.element];
418
+ }
419
+ return [...indiced.flat(), ...zeroed];
420
+ }
421
+ function hasTabIndex(element) {
422
+ return !Number.isNaN(Number.parseInt(element.getAttribute(ATTRIBUTE_TABINDEX), 10));
234
423
  }
235
424
  function isDisabled$1(item) {
236
425
  if (EXPRESSION_DISABLEABLE.test(item.element.tagName) && isDisabledFromFieldset(item.element)) return true;
@@ -242,8 +431,8 @@ function isDisabledFromFieldset(element) {
242
431
  if (parent instanceof HTMLFieldSetElement && parent.disabled) {
243
432
  const children = Array.from(parent.children);
244
433
  const { length } = children;
245
- for (let index = 0; index < length; index += 1) {
246
- const child = children[index];
434
+ for (let index$3 = 0; index$3 < length; index$3 += 1) {
435
+ const child = children[index$3];
247
436
  if (child instanceof HTMLLegendElement) return parent.matches(SELECTOR_FIELDSET_DISABLED) || !child.contains(element);
248
437
  }
249
438
  return true;
@@ -252,6 +441,9 @@ function isDisabledFromFieldset(element) {
252
441
  }
253
442
  return false;
254
443
  }
444
+ function isEditable(element) {
445
+ return EXPRESSION_TRUEISH.test(element.getAttribute(ATTRIBUTE_CONTENTEDITABLE));
446
+ }
255
447
  function isHidden(item) {
256
448
  if ((item.element.hidden ?? false) || item.element instanceof HTMLInputElement && item.element.type === STYLE_HIDDEN) return true;
257
449
  if ((item.element.matches(SELECTOR_SUMMARY_FIRST) ? item.element.parentElement : item.element)?.matches(SELECTOR_DETAILS_CLOSED_CHILDREN) ?? false) return true;
@@ -262,13 +454,18 @@ function isHidden(item) {
262
454
  }
263
455
  function isInert(item) {
264
456
  return (item.element.inert ?? false) || EXPRESSION_TRUEISH.test(item.element.getAttribute(ATTRIBUTE_INERT)) || item.element.parentElement != null && isInert({
265
- element: item.element.parentElement});
457
+ element: item.element.parentElement,
458
+ tabIndex: TABINDEX_DEFAULT
459
+ });
266
460
  }
267
461
  function isSummarised(item) {
268
462
  return item.element instanceof HTMLDetailsElement && [...item.element.children].some((child) => EXPRESSION_SUMMARY.test(child.tagName));
269
463
  }
464
+ var ATTRIBUTE_CONTENTEDITABLE = "contenteditable";
270
465
  var ATTRIBUTE_INERT = "inert";
466
+ var ATTRIBUTE_TABINDEX = "tabindex";
271
467
  var EXPRESSION_DISABLEABLE = /^(button|input|select|textarea)$/i;
468
+ var EXPRESSION_SPECIAL_TABINDEX = /^(audio|details|video)$/i;
272
469
  var EXPRESSION_SUMMARY = /^summary$/i;
273
470
  var EXPRESSION_TRUEISH = /^(|true)$/i;
274
471
  var FILTERS_FOCUSABLE = [
@@ -277,6 +474,7 @@ var FILTERS_FOCUSABLE = [
277
474
  isHidden,
278
475
  isSummarised
279
476
  ];
477
+ [...FILTERS_FOCUSABLE];
280
478
  var SELECTOR_DETAILS_CLOSED_CHILDREN = "details:not([open]) *";
281
479
  var SELECTOR_FIELDSET_DISABLED = "fieldset[disabled] *";
282
480
  var SELECTOR_SUMMARY_FIRST = "details > summary:first-of-type";
@@ -295,698 +493,575 @@ var SELECTOR_FULL$1 = [
295
493
  ].map((selector) => `${selector}:not([inert])`).join(",");
296
494
  var STYLE_HIDDEN = "hidden";
297
495
  var STYLE_NONE = "none";
496
+ var TABINDEX_BASE = 0;
298
497
  var TABINDEX_DEFAULT = -1;
299
-
300
- class FocusTrap {
301
- disabled = false;
302
- connected = true;
303
- element;
304
- embedded;
305
- get contain() {
306
- return this.element.hasAttribute(FOCUS_TRAP_CONTAIN);
307
- }
308
- get noescape() {
309
- return this.element.hasAttribute(FOCUS_TRAP_NOESCAPE);
310
- }
311
- constructor(element, options) {
312
- this.element = element;
313
- this.embedded = options != null;
314
- element.setAttribute('tabindex', '-1');
315
- if (options != null) {
316
- element.setAttribute(FOCUS_TRAP_SELECTOR, '');
317
- }
318
- if (options?.noescape) {
319
- element.setAttribute(FOCUS_TRAP_NOESCAPE, '');
320
- }
321
- }
322
- connect() {
323
- setConnected(this, true);
324
- }
325
- destroy() {
326
- this.element = undefined;
327
- }
328
- disable() {
329
- if (!(this.disabled || this.noescape)) {
330
- setDisabled(this, true);
331
- }
332
- }
333
- disconnect() {
334
- setConnected(this, false);
335
- }
336
- enable() {
337
- if (this.disabled) {
338
- setDisabled(this, false);
339
- }
340
- }
341
- focus(last) {
342
- tabToTrap(this, getFocusable(this.element), this.element, last ? -1 : 0);
343
- }
344
- }
345
- //
498
+ var FocusTrap = class {
499
+ disabled = false;
500
+ connected = true;
501
+ element;
502
+ embedded;
503
+ get contain() {
504
+ return this.element.hasAttribute(FOCUS_TRAP_CONTAIN);
505
+ }
506
+ get noescape() {
507
+ return this.element.hasAttribute(FOCUS_TRAP_NOESCAPE);
508
+ }
509
+ constructor(element, options) {
510
+ this.element = element;
511
+ this.embedded = options != null;
512
+ element.setAttribute("tabindex", "-1");
513
+ if (options != null) element.setAttribute(FOCUS_TRAP_SELECTOR, "");
514
+ if (options?.noescape) element.setAttribute(FOCUS_TRAP_NOESCAPE, "");
515
+ }
516
+ connect() {
517
+ setConnected(this, true);
518
+ }
519
+ destroy() {
520
+ this.element = void 0;
521
+ }
522
+ disable() {
523
+ if (!(this.disabled || this.noescape)) setDisabled(this, true);
524
+ }
525
+ disconnect() {
526
+ setConnected(this, false);
527
+ }
528
+ enable() {
529
+ if (this.disabled) setDisabled(this, false);
530
+ }
531
+ focus(last) {
532
+ tabToTrap(this, getFocusable(this.element), this.element, last ? -1 : 0);
533
+ }
534
+ };
346
535
  function createFocusTrap(element, options) {
347
- let focusTrap = FOCUSTRAPS_ALL.get(element);
348
- if (focusTrap == null) {
349
- focusTrap = new FocusTrap(element, options);
350
- FOCUSTRAPS_ALL.set(element, focusTrap);
351
- }
352
- return focusTrap;
536
+ let focusTrap = FOCUSTRAPS_ALL.get(element);
537
+ if (focusTrap == null) {
538
+ focusTrap = new FocusTrap(element, options);
539
+ FOCUSTRAPS_ALL.set(element, focusTrap);
540
+ }
541
+ return focusTrap;
353
542
  }
354
543
  function onEscape(event) {
355
- let element = findAncestor(event.target, ATTRIBUTE_SELECTOR);
356
- let focusTrap = FOCUSTRAPS_ALL.get(element);
357
- if (element == null || focusTrap == null) {
358
- return;
359
- }
360
- while (focusTrap.disabled) {
361
- element = findAncestor(focusTrap.element.parentElement, ATTRIBUTE_SELECTOR);
362
- focusTrap = FOCUSTRAPS_ALL.get(element);
363
- if (element == null || focusTrap == null) {
364
- return;
365
- }
366
- if (!focusTrap.disabled) {
367
- break;
368
- }
369
- }
370
- focusTrap?.disable();
544
+ let element = findAncestor(event.target, ATTRIBUTE_SELECTOR);
545
+ let focusTrap = FOCUSTRAPS_ALL.get(element);
546
+ if (element == null || focusTrap == null) return;
547
+ while (focusTrap.disabled) {
548
+ element = findAncestor(focusTrap.element.parentElement, ATTRIBUTE_SELECTOR);
549
+ focusTrap = FOCUSTRAPS_ALL.get(element);
550
+ if (element == null || focusTrap == null) return;
551
+ if (!focusTrap.disabled) break;
552
+ }
553
+ focusTrap?.disable();
371
554
  }
372
555
  function onFocusIn(event) {
373
- const focusTrap = FOCUSTRAPS_ALL.get(findAncestor(event.target, ATTRIBUTE_SELECTOR));
374
- lastTarget = focusTrap == null ? undefined : event.target;
556
+ lastTarget = FOCUSTRAPS_ALL.get(findAncestor(event.target, ATTRIBUTE_SELECTOR)) == null ? void 0 : event.target;
375
557
  }
376
558
  function onKeydown$1(event) {
377
- switch (event.key) {
378
- case 'Escape':
379
- onEscape(event);
380
- break;
381
- case 'Tab':
382
- onTab(event);
383
- break;
384
- default:
385
- return;
386
- }
559
+ switch (event.key) {
560
+ case "Escape":
561
+ onEscape(event);
562
+ break;
563
+ case "Tab":
564
+ onTab(event);
565
+ break;
566
+ default: return;
567
+ }
387
568
  }
388
569
  function onPointerdown$1(event) {
389
- const lastFocusTrap = findAncestor(lastTarget, ATTRIBUTE_SELECTOR);
390
- const nextFocusTrap = findAncestor(event.target, ATTRIBUTE_SELECTOR);
391
- if (lastFocusTrap != null && nextFocusTrap !== lastFocusTrap) {
392
- if (FOCUSTRAPS_ALL.get(lastFocusTrap)?.contain ?? false) {
393
- event.preventDefault();
394
- lastTarget?.focus();
395
- }
396
- }
397
- if (FOCUSTRAPS_DISABLED.size === 0) {
398
- return;
399
- }
400
- for (const focusTrap of FOCUSTRAPS_DISABLED) {
401
- if (focusTrap.element !== nextFocusTrap) {
402
- focusTrap.enable();
403
- }
404
- }
570
+ const lastFocusTrap = findAncestor(lastTarget, ATTRIBUTE_SELECTOR);
571
+ const nextFocusTrap = findAncestor(event.target, ATTRIBUTE_SELECTOR);
572
+ if (lastFocusTrap != null && nextFocusTrap !== lastFocusTrap) {
573
+ if (FOCUSTRAPS_ALL.get(lastFocusTrap)?.contain ?? false) {
574
+ event.preventDefault();
575
+ lastTarget?.focus();
576
+ }
577
+ }
578
+ if (FOCUSTRAPS_DISABLED.size === 0) return;
579
+ for (const focusTrap of FOCUSTRAPS_DISABLED) if (focusTrap.element !== nextFocusTrap) focusTrap.enable();
405
580
  }
406
581
  function onTab(event) {
407
- const element = findAncestor(event.target, ATTRIBUTE_SELECTOR);
408
- const focusTrap = FOCUSTRAPS_ALL.get(element);
409
- if (focusTrap == null) {
410
- return;
411
- }
412
- if (!focusTrap.disabled) {
413
- event.preventDefault();
414
- }
415
- const elements = getFocusable(element);
416
- const index = elements.indexOf(event.target);
417
- if (index === -1 || elements.length === 0) {
418
- tabToTrap(focusTrap, elements, element);
419
- }
420
- else {
421
- tabToElement(focusTrap, elements, index, event.shiftKey ? -1 : 1);
422
- }
582
+ const element = findAncestor(event.target, ATTRIBUTE_SELECTOR);
583
+ const focusTrap = FOCUSTRAPS_ALL.get(element);
584
+ if (focusTrap == null) return;
585
+ if (!focusTrap.disabled) event.preventDefault();
586
+ const elements = getFocusable(element);
587
+ const index$3 = elements.indexOf(event.target);
588
+ if (index$3 === -1 || elements.length === 0) tabToTrap(focusTrap, elements, element);
589
+ else tabToElement(focusTrap, elements, index$3, event.shiftKey ? -1 : 1);
423
590
  }
424
591
  function setConnected(focusTrap, value) {
425
- if (!focusTrap.embedded || focusTrap.connected === value) {
426
- return;
427
- }
428
- focusTrap.connected = value;
592
+ if (!focusTrap.embedded || focusTrap.connected === value) return;
593
+ focusTrap.connected = value;
429
594
  }
430
595
  function setDisabled(focusTrap, value) {
431
- focusTrap.disabled = value;
432
- if (value) {
433
- FOCUSTRAPS_DISABLED.add(focusTrap);
434
- }
435
- else {
436
- FOCUSTRAPS_DISABLED.delete(focusTrap);
437
- }
438
- }
439
- function tabToElement(focusTrap, elements, index, modifier) {
440
- const { length } = elements;
441
- const next = clamp(index + modifier, 0, length - 1, true);
442
- if (focusTrap.disabled) {
443
- if ((index === length - 1 && next === 0) ||
444
- (index === 0 && next === length - 1)) {
445
- lastTarget = undefined;
446
- focusTrap.enable();
447
- }
448
- return;
449
- }
450
- const element = elements[next];
451
- const elementFocusTrap = FOCUSTRAPS_ALL.get(element);
452
- if (elementFocusTrap != null) {
453
- elementFocusTrap.focus(modifier === -1);
454
- }
455
- else {
456
- elements[next].focus();
457
- lastTarget = elements[next];
458
- }
459
- }
460
- function tabToTrap(focusTrap, elements, element, index) {
461
- if (focusTrap.disabled) {
462
- lastTarget = undefined;
463
- focusTrap.enable();
464
- }
465
- else {
466
- const next = elements.length === 0 ? element : elements.at(index ?? 0);
467
- next.focus();
468
- lastTarget = next;
469
- }
470
- }
471
- //
472
- const FOCUS_TRAP_SELECTOR = 'oui-focus-trap';
596
+ focusTrap.disabled = value;
597
+ if (value) FOCUSTRAPS_DISABLED.add(focusTrap);
598
+ else FOCUSTRAPS_DISABLED.delete(focusTrap);
599
+ }
600
+ function tabToElement(focusTrap, elements, index$3, modifier) {
601
+ const { length } = elements;
602
+ const next = clamp(index$3 + modifier, 0, length - 1, true);
603
+ if (focusTrap.disabled) {
604
+ if (index$3 === length - 1 && next === 0 || index$3 === 0 && next === length - 1) {
605
+ lastTarget = void 0;
606
+ focusTrap.enable();
607
+ }
608
+ return;
609
+ }
610
+ const element = elements[next];
611
+ const elementFocusTrap = FOCUSTRAPS_ALL.get(element);
612
+ if (elementFocusTrap != null) elementFocusTrap.focus(modifier === -1);
613
+ else {
614
+ elements[next].focus();
615
+ lastTarget = elements[next];
616
+ }
617
+ }
618
+ function tabToTrap(focusTrap, elements, element, index$3) {
619
+ if (focusTrap.disabled) {
620
+ lastTarget = void 0;
621
+ focusTrap.enable();
622
+ } else {
623
+ const next = elements.length === 0 ? element : elements.at(index$3 ?? 0);
624
+ next.focus();
625
+ lastTarget = next;
626
+ }
627
+ }
628
+ const FOCUS_TRAP_SELECTOR = "oui-focus-trap";
473
629
  const ATTRIBUTE_SELECTOR = `[${FOCUS_TRAP_SELECTOR}]`;
474
630
  const EVENT_OPTIONS = {
475
- capture: true,
476
- passive: false,
631
+ capture: true,
632
+ passive: false
477
633
  };
478
634
  const FOCUS_TRAP_CONTAIN = `${FOCUS_TRAP_SELECTOR}-contain`;
479
635
  const FOCUS_TRAP_NOESCAPE = `${FOCUS_TRAP_SELECTOR}-noescape`;
480
- const FOCUSTRAPS_ALL = new WeakMap();
481
- const FOCUSTRAPS_DISABLED = new Set();
636
+ const FOCUSTRAPS_ALL = /* @__PURE__ */ new WeakMap();
637
+ const FOCUSTRAPS_DISABLED = /* @__PURE__ */ new Set();
482
638
  let lastTarget;
483
- //
484
- on(document, 'focusin', onFocusIn, EVENT_OPTIONS);
485
- on(document, 'keydown', onKeydown$1, EVENT_OPTIONS);
486
- on(document, 'mousedown', onPointerdown$1, EVENT_OPTIONS);
487
- on(document, 'touchstart', onPointerdown$1, EVENT_OPTIONS);
488
-
639
+ on(document, "focusin", onFocusIn, EVENT_OPTIONS);
640
+ on(document, "keydown", onKeydown$1, EVENT_OPTIONS);
641
+ on(document, "mousedown", onPointerdown$1, EVENT_OPTIONS);
642
+ on(document, "touchstart", onPointerdown$1, EVENT_OPTIONS);
489
643
  function removeFocusTraps(element) {
490
- FOCUSTRAPS_ALL.get(element)?.destroy();
491
- FOCUSTRAPS_ALL.delete(element);
644
+ FOCUSTRAPS_ALL.get(element)?.destroy();
645
+ FOCUSTRAPS_ALL.delete(element);
492
646
  }
493
647
  attributable(FOCUS_TRAP_SELECTOR, createFocusTrap, removeFocusTraps);
494
-
495
- class Floatable {
496
- options;
497
- active = false;
498
- disabled = false;
499
- frame;
500
- ignoreFocus = false;
501
- constructor(options) {
502
- this.options = options;
503
- initialize(this);
504
- }
505
- destroy() {
506
- stop(this);
507
- const state = getState();
508
- state?.active.delete(this);
509
- state?.mapped.delete(this.options.anchor);
510
- state?.mapped.delete(this.options.content);
511
- this.options.anchor = undefined;
512
- this.options.content = undefined;
513
- }
514
- disable() {
515
- if (this.disabled) {
516
- return;
517
- }
518
- this.disabled = true;
519
- stop(this);
520
- getState()?.active.delete(this);
521
- }
522
- enable() {
523
- if (!this.disabled) {
524
- return;
525
- }
526
- this.disabled = false;
527
- initialize(this);
528
- }
529
- toggle(active, ignoreFocus) {
530
- if (this.disabled || this.active === active) {
531
- return;
532
- }
533
- const state = getState();
534
- if (state == null) {
535
- return;
536
- }
537
- this.ignoreFocus = !active && (ignoreFocus ?? false);
538
- stop(this);
539
- if (active) {
540
- state.active.add(this);
541
- }
542
- else {
543
- state.active.delete(this);
544
- }
545
- if (this.options.interactive) {
546
- if (active) {
547
- state.order.push(this);
548
- }
549
- else {
550
- const index = state.order.indexOf(this);
551
- if (index > -1) {
552
- state.order.splice(index, 1);
553
- }
554
- }
555
- }
556
- if (active) {
557
- activate(this);
558
- }
559
- else {
560
- deactivate(this);
561
- }
562
- }
563
- }
564
- //
648
+ var Floatable = class {
649
+ active = false;
650
+ disabled = false;
651
+ frame;
652
+ ignoreFocus = false;
653
+ constructor(options) {
654
+ this.options = options;
655
+ initialize(this);
656
+ }
657
+ destroy() {
658
+ stop(this);
659
+ const state = getState();
660
+ state?.active.delete(this);
661
+ state?.mapped.delete(this.options.anchor);
662
+ state?.mapped.delete(this.options.content);
663
+ this.options.anchor = void 0;
664
+ this.options.content = void 0;
665
+ }
666
+ disable() {
667
+ if (this.disabled) return;
668
+ this.disabled = true;
669
+ stop(this);
670
+ getState()?.active.delete(this);
671
+ }
672
+ enable() {
673
+ if (!this.disabled) return;
674
+ this.disabled = false;
675
+ initialize(this);
676
+ }
677
+ toggle(active, ignoreFocus) {
678
+ if (this.disabled || this.active === active) return;
679
+ const state = getState();
680
+ if (state == null) return;
681
+ this.ignoreFocus = !active && (ignoreFocus ?? false);
682
+ stop(this);
683
+ if (active) state.active.add(this);
684
+ else state.active.delete(this);
685
+ if (this.options.interactive) if (active) state.order.push(this);
686
+ else {
687
+ const index$3 = state.order.indexOf(this);
688
+ if (index$3 > -1) state.order.splice(index$3, 1);
689
+ }
690
+ if (active) activate(this);
691
+ else deactivate(this);
692
+ }
693
+ };
565
694
  function activate(floatable) {
566
- floatable.active = true;
567
- document.body.append(floatable.options.content);
568
- floatable.options.content.hidden = false;
569
- updatePosition(floatable);
695
+ floatable.active = true;
696
+ document.body.append(floatable.options.content);
697
+ floatable.options.content.hidden = false;
698
+ updatePosition(floatable);
570
699
  }
571
700
  function closeAbove(element) {
572
- const state = getState();
573
- if (state == null) {
574
- return;
575
- }
576
- const index = state.order.findIndex(floatable => floatable.options.anchor === element ||
577
- floatable.options.content === element);
578
- if (index === -1 || index === state.order.length - 1) {
579
- return;
580
- }
581
- while (index < state.order.length - 1) {
582
- void state.order.pop()?.toggle(false, true);
583
- }
701
+ const state = getState();
702
+ if (state == null) return;
703
+ const index$3 = state.order.findIndex((floatable) => floatable.options.anchor === element || floatable.options.content === element);
704
+ if (index$3 === -1 || index$3 === state.order.length - 1) return;
705
+ while (index$3 < state.order.length - 1) state.order.pop()?.toggle(false, true);
584
706
  }
585
707
  function closeAll() {
586
- const state = getState();
587
- const floatables = [...(state?.active ?? [])];
588
- state?.active.clear();
589
- for (const floatable of floatables) {
590
- void floatable.toggle(false, true);
591
- }
708
+ const state = getState();
709
+ const floatables = [...state?.active ?? []];
710
+ state?.active.clear();
711
+ for (const floatable of floatables) floatable.toggle(false, true);
592
712
  }
593
713
  function closeNonInteractive(state) {
594
- for (const floatable of state.active) {
595
- if (!floatable.options.interactive) {
596
- void floatable.toggle(false);
597
- }
598
- }
714
+ for (const floatable of state.active) if (!floatable.options.interactive) floatable.toggle(false);
599
715
  }
600
716
  function deactivate(floatable) {
601
- floatable.active = false;
602
- floatable.options.content.hidden = true;
603
- floatable.options.anchor.insertAdjacentElement(INSERT_AFTEREND, floatable.options.content);
604
- floatable.options.onAfter?.(false);
717
+ floatable.active = false;
718
+ floatable.options.content.hidden = true;
719
+ floatable.options.anchor.insertAdjacentElement(INSERT_AFTEREND, floatable.options.content);
720
+ floatable.options.onAfter?.(false);
605
721
  }
606
722
  function getState() {
607
- return window._oscarpalmer_oui_floatable;
723
+ return window._oscarpalmer_oui_floatable;
608
724
  }
609
725
  function getX(anchor, content, position) {
610
- if (position.endsWith(POSITION_SUFFIX_END)) {
611
- const end = anchor.right - content.width;
612
- return end < 0 ? 0 : end;
613
- }
614
- if (position.endsWith(POSITION_SUFFIX_START)) {
615
- const start = anchor.left;
616
- return start + content.width > window.innerWidth
617
- ? window.innerWidth - content.width
618
- : start;
619
- }
620
- if (position.startsWith(POSITION_END)) {
621
- return anchor.right;
622
- }
623
- if (position.startsWith(POSITION_START)) {
624
- return anchor.left - content.width;
625
- }
626
- if (position.startsWith(POSITION_HORIZONTAL)) {
627
- if (anchor.right + content.width <= window.innerWidth) {
628
- return anchor.right;
629
- }
630
- return anchor.left - content.width;
631
- }
632
- const left = anchor.left + (anchor.width - content.width) / 2;
633
- return left < 0 ? 0 : left;
726
+ if (position.endsWith(POSITION_SUFFIX_END)) {
727
+ const end = anchor.right - content.width;
728
+ return end < 0 ? 0 : end;
729
+ }
730
+ if (position.endsWith(POSITION_SUFFIX_START)) {
731
+ const start = anchor.left;
732
+ return start + content.width > window.innerWidth ? window.innerWidth - content.width : start;
733
+ }
734
+ if (position.startsWith(POSITION_END)) return anchor.right;
735
+ if (position.startsWith(POSITION_START)) return anchor.left - content.width;
736
+ if (position.startsWith(POSITION_HORIZONTAL)) {
737
+ if (anchor.right + content.width <= window.innerWidth) return anchor.right;
738
+ return anchor.left - content.width;
739
+ }
740
+ const left = anchor.left + (anchor.width - content.width) / 2;
741
+ return left < 0 ? 0 : left;
634
742
  }
635
743
  function getY(anchor, content, position, preferAbove) {
636
- if (position.startsWith(POSITION_ABOVE)) {
637
- return anchor.top - content.height;
638
- }
639
- if (position.startsWith(POSITION_BELOW)) {
640
- return anchor.bottom;
641
- }
642
- if (position.endsWith(POSITION_BOTTOM)) {
643
- const bottom = anchor.bottom - content.height;
644
- return bottom < 0 ? 0 : bottom;
645
- }
646
- if (position.endsWith(POSITION_TOP)) {
647
- const top = anchor.top;
648
- return top + content.height > window.innerHeight
649
- ? window.innerHeight - content.height
650
- : top;
651
- }
652
- if (position.startsWith(POSITION_VERTICAL)) {
653
- if (preferAbove && anchor.top - content.height >= 0) {
654
- return anchor.top - content.height;
655
- }
656
- if (anchor.bottom + content.height <= document.body.clientHeight) {
657
- return anchor.bottom;
658
- }
659
- return anchor.top - content.height;
660
- }
661
- return anchor.top + (anchor.height - content.height) / 2;
744
+ if (position.startsWith(POSITION_ABOVE)) return anchor.top - content.height;
745
+ if (position.startsWith(POSITION_BELOW)) return anchor.bottom;
746
+ if (position.endsWith(POSITION_BOTTOM)) {
747
+ const bottom = anchor.bottom - content.height;
748
+ return bottom < 0 ? 0 : bottom;
749
+ }
750
+ if (position.endsWith(POSITION_TOP)) {
751
+ const top = anchor.top;
752
+ return top + content.height > window.innerHeight ? window.innerHeight - content.height : top;
753
+ }
754
+ if (position.startsWith(POSITION_VERTICAL)) {
755
+ if (preferAbove && anchor.top - content.height >= 0) return anchor.top - content.height;
756
+ if (anchor.bottom + content.height <= document.body.clientHeight) return anchor.bottom;
757
+ return anchor.top - content.height;
758
+ }
759
+ return anchor.top + (anchor.height - content.height) / 2;
662
760
  }
663
761
  function initialize(floatable) {
664
- const { anchor, content, interactive } = floatable.options;
665
- if (interactive) {
666
- anchor.setAttribute(ATTRIBUTE_ANCHOR, '');
667
- content.setAttribute(ATTRIBUTE_CONTENT$1, '');
668
- }
669
- content.style.position = 'fixed';
670
- content.style.inset = '0 auto auto 0';
671
- content.style.zIndex = '10';
672
- const state = getState();
673
- state?.mapped.set(anchor, floatable);
674
- state?.mapped.set(content, floatable);
762
+ const { anchor, content, interactive } = floatable.options;
763
+ if (interactive) {
764
+ anchor.setAttribute(ATTRIBUTE_ANCHOR, "");
765
+ content.setAttribute(ATTRIBUTE_CONTENT$1, "");
766
+ }
767
+ content.style.position = "fixed";
768
+ content.style.inset = "0 auto auto 0";
769
+ content.style.zIndex = "10";
770
+ const state = getState();
771
+ state?.mapped.set(anchor, floatable);
772
+ state?.mapped.set(content, floatable);
675
773
  }
676
774
  function isDisabled(element) {
677
- return (element.disabled ||
678
- element.readOnly ||
679
- element.getAttribute('aria-disabled') === 'true');
775
+ return element.disabled || element.readOnly || element.getAttribute("aria-disabled") === "true";
680
776
  }
681
777
  function onClick$1(event) {
682
- const related = findAncestor(event.target, SELECTOR_ALL);
683
- if (!(related instanceof HTMLElement)) {
684
- closeAll();
685
- }
686
- else if (related.hasAttribute(ATTRIBUTE_CONTENT$1)) {
687
- closeAbove(related);
688
- }
689
- else if (!isDisabled(related)) {
690
- toggle$1(related);
691
- }
778
+ const related = findAncestor(event.target, SELECTOR_ALL);
779
+ if (!(related instanceof HTMLElement)) closeAll();
780
+ else if (related.hasAttribute(ATTRIBUTE_CONTENT$1)) closeAbove(related);
781
+ else if (!isDisabled(related)) toggle$1(related);
692
782
  }
693
783
  function onKeyDown(event) {
694
- if (event.key !== 'Escape') {
695
- return;
696
- }
697
- const state = getState();
698
- if (state == null || state.active.size === 0) {
699
- return;
700
- }
701
- closeNonInteractive(state);
702
- const related = findAncestor(event.target, SELECTOR_CONTENT$2);
703
- if (!(related instanceof HTMLElement)) {
704
- return;
705
- }
706
- closeAbove(related);
707
- const floatable = state.mapped.get(related);
708
- if (floatable != null) {
709
- void floatable.toggle(false);
710
- }
784
+ if (event.key !== "Escape") return;
785
+ const state = getState();
786
+ if (state == null || state.active.size === 0) return;
787
+ closeNonInteractive(state);
788
+ const related = findAncestor(event.target, SELECTOR_CONTENT$2);
789
+ if (!(related instanceof HTMLElement)) return;
790
+ closeAbove(related);
791
+ const floatable = state.mapped.get(related);
792
+ if (floatable != null) floatable.toggle(false);
711
793
  }
712
794
  function stop(floatable) {
713
- if (floatable.frame != null) {
714
- cancelAnimationFrame(floatable.frame);
715
- }
716
- floatable.frame = undefined;
795
+ if (floatable.frame != null) cancelAnimationFrame(floatable.frame);
796
+ floatable.frame = void 0;
717
797
  }
718
798
  function toggle$1(anchor) {
719
- const floatable = getState()?.mapped.get(anchor);
720
- if (floatable == null) {
721
- closeAll();
722
- return;
723
- }
724
- const active = Boolean(floatable.active);
725
- const content = findAncestor(floatable.options.anchor, SELECTOR_CONTENT$2);
726
- if (content == null) {
727
- closeAll();
728
- }
729
- else {
730
- closeAbove(content);
731
- }
732
- void floatable.toggle(!active);
799
+ const floatable = getState()?.mapped.get(anchor);
800
+ if (floatable == null) {
801
+ closeAll();
802
+ return;
803
+ }
804
+ const active = Boolean(floatable.active);
805
+ const content = findAncestor(floatable.options.anchor, SELECTOR_CONTENT$2);
806
+ if (content == null) closeAll();
807
+ else closeAbove(content);
808
+ floatable.toggle(!active);
733
809
  }
734
810
  function updatePosition(floatable) {
735
- let position = floatable.options.anchor
736
- .getAttribute(floatable.options.positionAttribute)
737
- ?.trim() ?? floatable.options.defaultPosition;
738
- if (!POSITIONS.has(position)) {
739
- position = floatable.options.defaultPosition;
740
- }
741
- let previousAnchor;
742
- let previousContent;
743
- let calculated = false;
744
- let runOnAfter = false;
745
- function run() {
746
- const anchor = floatable.options.anchor.getBoundingClientRect();
747
- const content = floatable.options.content.getBoundingClientRect();
748
- if (calculated) {
749
- if (previousAnchor != null && previousContent != null) {
750
- if (PROPERTIES.every(property => anchor[property] === previousAnchor[property]) &&
751
- PROPERTIES.every(property => content[property] === previousContent[property])) {
752
- floatable.frame = requestAnimationFrame(run);
753
- return;
754
- }
755
- }
756
- }
757
- else {
758
- calculated = true;
759
- }
760
- update(anchor, content);
761
- }
762
- function update(anchor, content) {
763
- previousAnchor = anchor;
764
- previousContent = content;
765
- const left = getX(anchor, content, position);
766
- const top = getY(anchor, content, position, floatable.options.preferAbove);
767
- if (top + content.height > window.innerHeight) {
768
- floatable.options.content.style.height = `${window.innerHeight - top}px`;
769
- }
770
- else {
771
- floatable.options.content.style.height = '';
772
- }
773
- if (left + content.width > window.innerWidth) {
774
- floatable.options.content.style.width = `${window.innerWidth - left}px`;
775
- }
776
- else {
777
- floatable.options.content.style.width = '';
778
- }
779
- // floatable.options.content.style.inset = `${top}px auto auto ${left}px`;
780
- floatable.options.content.style.transform = `translate3d(${left}px, ${top}px, 0)`;
781
- floatable.frame = requestAnimationFrame(run);
782
- if (!runOnAfter) {
783
- runOnAfter = true;
784
- floatable.options.onAfter?.(true);
785
- }
786
- }
787
- floatable.frame = requestAnimationFrame(run);
788
- }
789
- //
790
- const ATTRIBUTE_ANCHOR = 'oui-floatable-anchor';
791
- const ATTRIBUTE_CONTENT$1 = 'oui-floatable-content';
792
- const INSERT_AFTEREND = 'afterend';
793
- const POSITION_ABOVE = 'above';
794
- const POSITION_BELOW = 'below';
795
- const POSITION_BOTTOM = 'bottom';
796
- const POSITION_END = 'end';
797
- const POSITION_HORIZONTAL = 'horizontal';
798
- const POSITION_START = 'start';
799
- const POSITION_SUFFIX_END = '-end';
800
- const POSITION_SUFFIX_START = '-start';
801
- const POSITION_TOP = 'top';
802
- const POSITION_VERTICAL = 'vertical';
811
+ let position = floatable.options.anchor.getAttribute(floatable.options.positionAttribute)?.trim() ?? floatable.options.defaultPosition;
812
+ if (!POSITIONS.has(position)) position = floatable.options.defaultPosition;
813
+ let previousAnchor;
814
+ let previousContent;
815
+ let calculated = false;
816
+ let runOnAfter = false;
817
+ function run() {
818
+ const anchor = floatable.options.anchor.getBoundingClientRect();
819
+ const content = floatable.options.content.getBoundingClientRect();
820
+ if (calculated) {
821
+ if (previousAnchor != null && previousContent != null) {
822
+ if (PROPERTIES.every((property) => anchor[property] === previousAnchor[property]) && PROPERTIES.every((property) => content[property] === previousContent[property])) {
823
+ floatable.frame = requestAnimationFrame(run);
824
+ return;
825
+ }
826
+ }
827
+ } else calculated = true;
828
+ update(anchor, content);
829
+ }
830
+ function update(anchor, content) {
831
+ previousAnchor = anchor;
832
+ previousContent = content;
833
+ const left = getX(anchor, content, position);
834
+ const top = getY(anchor, content, position, floatable.options.preferAbove);
835
+ if (top + content.height > window.innerHeight) floatable.options.content.style.height = `${window.innerHeight - top}px`;
836
+ else floatable.options.content.style.height = "";
837
+ if (left + content.width > window.innerWidth) floatable.options.content.style.width = `${window.innerWidth - left}px`;
838
+ else floatable.options.content.style.width = "";
839
+ floatable.options.content.style.transform = `translate3d(${left}px, ${top}px, 0)`;
840
+ floatable.frame = requestAnimationFrame(run);
841
+ if (!runOnAfter) {
842
+ runOnAfter = true;
843
+ floatable.options.onAfter?.(true);
844
+ }
845
+ }
846
+ floatable.frame = requestAnimationFrame(run);
847
+ }
848
+ const ATTRIBUTE_ANCHOR = "oui-floatable-anchor";
849
+ const ATTRIBUTE_CONTENT$1 = "oui-floatable-content";
850
+ const INSERT_AFTEREND = "afterend";
851
+ const POSITION_ABOVE = "above";
852
+ const POSITION_BELOW = "below";
853
+ const POSITION_BOTTOM = "bottom";
854
+ const POSITION_END = "end";
855
+ const POSITION_HORIZONTAL = "horizontal";
856
+ const POSITION_START = "start";
857
+ const POSITION_SUFFIX_END = "-end";
858
+ const POSITION_SUFFIX_START = "-start";
859
+ const POSITION_TOP = "top";
860
+ const POSITION_VERTICAL = "vertical";
803
861
  const POSITIONS = new Set([
804
- 'above',
805
- 'above-end',
806
- 'above-start',
807
- 'below',
808
- 'below-end',
809
- 'below-start',
810
- 'end',
811
- 'end-bottom',
812
- 'end-top',
813
- 'horizontal',
814
- 'horizontal-bottom',
815
- 'horizontal-top',
816
- 'start',
817
- 'start-bottom',
818
- 'start-top',
819
- 'vertical',
820
- 'vertical-end',
821
- 'vertical-start',
862
+ "above",
863
+ "above-end",
864
+ "above-start",
865
+ "below",
866
+ "below-end",
867
+ "below-start",
868
+ "end",
869
+ "end-bottom",
870
+ "end-top",
871
+ "horizontal",
872
+ "horizontal-bottom",
873
+ "horizontal-top",
874
+ "start",
875
+ "start-bottom",
876
+ "start-top",
877
+ "vertical",
878
+ "vertical-end",
879
+ "vertical-start"
822
880
  ]);
823
- const PROPERTIES = ['bottom', 'left', 'right', 'top'];
881
+ const PROPERTIES = [
882
+ "bottom",
883
+ "left",
884
+ "right",
885
+ "top"
886
+ ];
824
887
  const SELECTOR_ALL = `[${ATTRIBUTE_ANCHOR}], [${ATTRIBUTE_CONTENT$1}]`;
825
888
  const SELECTOR_CONTENT$2 = `[${ATTRIBUTE_CONTENT$1}]`;
826
- //
827
889
  if (window._oscarpalmer_oui_floatable == null) {
828
- Object.defineProperty(window, '_oscarpalmer_oui_floatable', {
829
- enumerable: false,
830
- value: {
831
- active: new Set(),
832
- mapped: new Map(),
833
- order: [],
834
- },
835
- writable: false,
836
- });
837
- on(document, 'keydown', event => {
838
- onKeyDown(event);
839
- });
840
- on(document, 'click', event => {
841
- onClick$1(event);
842
- });
843
- }
844
-
890
+ Object.defineProperty(window, "_oscarpalmer_oui_floatable", {
891
+ enumerable: false,
892
+ value: {
893
+ active: /* @__PURE__ */ new Set(),
894
+ mapped: /* @__PURE__ */ new Map(),
895
+ order: []
896
+ },
897
+ writable: false
898
+ });
899
+ on(document, "keydown", (event) => {
900
+ onKeyDown(event);
901
+ });
902
+ on(document, "click", (event) => {
903
+ onClick$1(event);
904
+ });
905
+ }
845
906
  let index$2 = 0;
846
- class OuiPopoverElement extends HTMLElement {
847
- #floatable;
848
- #focusTrap;
849
- constructor() {
850
- super();
851
- const content = this.querySelector(SELECTOR_CONTENT$1);
852
- const toggle = this.querySelector(SELECTOR_TOGGLE);
853
- if (!(content instanceof HTMLElement)) {
854
- throw new Error('A oui-popover must have a direct child element with the [oui-popover-content]-attribute');
855
- }
856
- if (!(toggle instanceof HTMLButtonElement)) {
857
- throw new Error('A oui-popover must have a direct child element with the [oui-popover-toggle]-attribute and be a button');
858
- }
859
- content.hidden = true;
860
- content.setAttribute('role', 'dialog');
861
- content.setAttribute('aria-modal', 'true');
862
- if (isNullableOrWhitespace(content.id)) {
863
- content.setAttribute('id', `${ATTRIBUTE_ID_PREFIX}_${++index$2}`);
864
- }
865
- toggle.setAttribute('aria-controls', content.id);
866
- toggle.setAttribute('aria-haspopup', 'dialog');
867
- this.#floatable = new Floatable({
868
- content,
869
- anchor: toggle,
870
- defaultPosition: 'below-start',
871
- interactive: true,
872
- positionAttribute: 'position',
873
- preferAbove: false,
874
- onAfter: (active) => {
875
- if (active) {
876
- focus(content);
877
- }
878
- else if (!this.#floatable.ignoreFocus) {
879
- toggle.focus();
880
- }
881
- },
882
- });
883
- this.#focusTrap = createFocusTrap(content, {
884
- noescape: true,
885
- });
886
- POPOVERS.set(toggle, this.#floatable);
887
- POPOVERS.set(content, this.#floatable);
888
- }
889
- close() {
890
- this.hidePopover();
891
- }
892
- connectedCallback() {
893
- this.#floatable.enable();
894
- this.#focusTrap.connect();
895
- }
896
- disconnectedCallback() {
897
- this.#floatable.disable();
898
- this.#focusTrap.disconnect();
899
- }
900
- hidePopover() {
901
- if (this.#floatable.active && this.isConnected) {
902
- this.#floatable.toggle(false);
903
- }
904
- }
905
- open() {
906
- this.showPopover();
907
- }
908
- showPopover() {
909
- if (!this.#floatable.active && this.isConnected) {
910
- this.#floatable.toggle(true);
911
- }
912
- }
913
- toggle() {
914
- this.togglePopover();
915
- }
916
- togglePopover(options) {
917
- if (typeof options === 'boolean') {
918
- if (options === true) {
919
- this.showPopover();
920
- }
921
- else {
922
- this.hidePopover();
923
- }
924
- return options;
925
- }
926
- if (this.#floatable.active) {
927
- this.hidePopover();
928
- return false;
929
- }
930
- this.showPopover();
931
- return true;
932
- }
933
- }
934
- //
907
+ var OuiPopoverElement = class extends HTMLElement {
908
+ #floatable;
909
+ #focusTrap;
910
+ constructor() {
911
+ super();
912
+ const content = this.querySelector(SELECTOR_CONTENT$1);
913
+ const toggle$2 = this.querySelector(SELECTOR_TOGGLE);
914
+ if (!(content instanceof HTMLElement)) throw new Error("A oui-popover must have a direct child element with the [oui-popover-content]-attribute");
915
+ if (!(toggle$2 instanceof HTMLButtonElement)) throw new Error("A oui-popover must have a direct child element with the [oui-popover-toggle]-attribute and be a button");
916
+ content.hidden = true;
917
+ content.setAttribute("role", "dialog");
918
+ content.setAttribute("aria-modal", "true");
919
+ if (isNullableOrWhitespace(content.id)) content.setAttribute("id", `${ATTRIBUTE_ID_PREFIX}_${++index$2}`);
920
+ toggle$2.setAttribute("aria-controls", content.id);
921
+ toggle$2.setAttribute("aria-haspopup", "dialog");
922
+ this.#floatable = new Floatable({
923
+ content,
924
+ anchor: toggle$2,
925
+ defaultPosition: "below-start",
926
+ interactive: true,
927
+ positionAttribute: "position",
928
+ preferAbove: false,
929
+ onAfter: (active) => {
930
+ if (active) focus(content);
931
+ else if (!this.#floatable.ignoreFocus) toggle$2.focus();
932
+ }
933
+ });
934
+ this.#focusTrap = createFocusTrap(content, { noescape: true });
935
+ POPOVERS.set(toggle$2, this.#floatable);
936
+ POPOVERS.set(content, this.#floatable);
937
+ }
938
+ close() {
939
+ this.hidePopover();
940
+ }
941
+ connectedCallback() {
942
+ this.#floatable.enable();
943
+ this.#focusTrap.connect();
944
+ }
945
+ disconnectedCallback() {
946
+ this.#floatable.disable();
947
+ this.#focusTrap.disconnect();
948
+ }
949
+ hidePopover() {
950
+ if (this.#floatable.active && this.isConnected) this.#floatable.toggle(false);
951
+ }
952
+ open() {
953
+ this.showPopover();
954
+ }
955
+ showPopover() {
956
+ if (!this.#floatable.active && this.isConnected) this.#floatable.toggle(true);
957
+ }
958
+ toggle() {
959
+ this.togglePopover();
960
+ }
961
+ togglePopover(options) {
962
+ if (typeof options === "boolean") {
963
+ if (options === true) this.showPopover();
964
+ else this.hidePopover();
965
+ return options;
966
+ }
967
+ if (this.#floatable.active) {
968
+ this.hidePopover();
969
+ return false;
970
+ }
971
+ this.showPopover();
972
+ return true;
973
+ }
974
+ };
935
975
  function focus(content) {
936
- let target = getFocusable(content)[0];
937
- if (!(target instanceof HTMLElement)) {
938
- target = content;
939
- }
940
- requestAnimationFrame(() => {
941
- target.focus();
942
- });
943
- }
944
- //
945
- const ATTRIBUTE_ID_PREFIX = 'oui_popover_content_';
946
- const POPOVERS = new Map();
947
- const SELECTOR$2 = 'oui-popover';
976
+ let target = getFocusable(content)[0];
977
+ if (!(target instanceof HTMLElement)) target = content;
978
+ requestAnimationFrame(() => {
979
+ target.focus();
980
+ });
981
+ }
982
+ const ATTRIBUTE_ID_PREFIX = "oui_popover_content_";
983
+ const POPOVERS = /* @__PURE__ */ new Map();
984
+ const SELECTOR$2 = "oui-popover";
948
985
  const SELECTOR_CONTENT$1 = `:scope > [${SELECTOR$2}-content]`;
949
986
  const SELECTOR_TOGGLE = `:scope > [${SELECTOR$2}-toggle]`;
950
- //
951
987
  customElements.define(SELECTOR$2, OuiPopoverElement);
952
-
953
988
  function round(value, decimals) {
954
989
  if (typeof value !== "number") return NaN;
990
+ if (typeof decimals !== "number" || decimals < 1) return Math.round(value);
955
991
  const mod = 10 ** decimals;
956
992
  return Math.round((value + Number.EPSILON) * mod) / mod;
957
993
  }
958
-
959
- function setElementValues(element, first, second, callback) {
994
+ new Set([
995
+ Node.ELEMENT_NODE,
996
+ Node.TEXT_NODE,
997
+ Node.PROCESSING_INSTRUCTION_NODE,
998
+ Node.COMMENT_NODE,
999
+ Node.DOCUMENT_TYPE_NODE
1000
+ ]);
1001
+ Object.freeze([
1002
+ "async",
1003
+ "autofocus",
1004
+ "autoplay",
1005
+ "checked",
1006
+ "controls",
1007
+ "default",
1008
+ "defer",
1009
+ "disabled",
1010
+ "formnovalidate",
1011
+ "hidden",
1012
+ "inert",
1013
+ "ismap",
1014
+ "itemscope",
1015
+ "loop",
1016
+ "multiple",
1017
+ "muted",
1018
+ "nomodule",
1019
+ "novalidate",
1020
+ "open",
1021
+ "playsinline",
1022
+ "readonly",
1023
+ "required",
1024
+ "reversed",
1025
+ "selected"
1026
+ ]);
1027
+ document.createElement("form");
1028
+ function setElementValues(element, first, second, third, callback) {
960
1029
  if (!isHTMLOrSVGElement(element)) return;
961
- if (isPlainObject(first)) {
962
- const entries = Object.entries(first);
963
- const { length } = entries;
964
- for (let index = 0; index < length; index += 1) {
965
- const [key, value] = entries[index];
966
- callback(element, key, value);
967
- }
968
- } else if (typeof first === "string") callback(element, first, second);
1030
+ if (typeof first === "string") {
1031
+ callback(element, first, second, third);
1032
+ return;
1033
+ }
1034
+ const isArray = Array.isArray(first);
1035
+ if (!isArray && !(typeof first === "object" && first !== null)) return;
1036
+ const entries = isArray ? first : Object.entries(first).map(([name, value]) => ({
1037
+ name,
1038
+ value
1039
+ }));
1040
+ const { length } = entries;
1041
+ for (let index$3 = 0; index$3 < length; index$3 += 1) {
1042
+ const entry = entries[index$3];
1043
+ if (typeof entry === "object" && typeof entry?.name === "string") callback(element, entry.name, entry.value, third);
1044
+ }
969
1045
  }
970
- function updateElementValue(element, key, value, set, remove, json) {
971
- if (isNullableOrWhitespace(value)) remove.call(element, key);
972
- else set.call(element, key, String(value));
1046
+ function updateElementValue(element, key, value, set, remove, isBoolean, json) {
1047
+ if (isBoolean ? value == null : isNullableOrWhitespace(value)) remove.call(element, key);
1048
+ else set.call(element, key, json ? JSON.stringify(value) : String(value));
973
1049
  }
974
-
975
1050
  function getStyles(element, properties, computed) {
976
1051
  const styles = {};
977
1052
  if (!(isHTMLOrSVGElement(element) && Array.isArray(properties))) return styles;
978
1053
  const { length } = properties;
979
- for (let index = 0; index < length; index += 1) {
980
- const property = properties[index];
1054
+ for (let index$3 = 0; index$3 < length; index$3 += 1) {
1055
+ const property = properties[index$3];
981
1056
  if (typeof property === "string") styles[property] = getStyleValue(element, property, computed === true);
982
1057
  }
983
1058
  return styles;
984
1059
  }
985
1060
  function setStyles(element, styles) {
986
- setElementValues(element, styles, null, updateStyleProperty);
1061
+ setElementValues(element, styles, null, null, updateStyleProperty);
987
1062
  }
988
1063
  function toggleStyles(element, styles) {
989
- function toggle(set) {
1064
+ function toggle$2(set) {
990
1065
  hasSet = set;
991
1066
  let next;
992
1067
  if (set) {
@@ -1004,21 +1079,20 @@ function toggleStyles(element, styles) {
1004
1079
  let values = {};
1005
1080
  return {
1006
1081
  set() {
1007
- if (!hasSet) toggle(true);
1082
+ if (!hasSet) toggle$2(true);
1008
1083
  },
1009
1084
  remove() {
1010
- if (hasSet) toggle(false);
1085
+ if (hasSet) toggle$2(false);
1011
1086
  }
1012
1087
  };
1013
1088
  }
1014
1089
  function updateStyleProperty(element, key, value) {
1015
- updateElementValue(element, key, value, function(property, value$1) {
1016
- this.style[property] = value$1;
1090
+ updateElementValue(element, key, value, function(property, style) {
1091
+ this.style[property] = style;
1017
1092
  }, function(property) {
1018
1093
  this.style[property] = "";
1019
- });
1094
+ }, false, false);
1020
1095
  }
1021
-
1022
1096
  function getSupport() {
1023
1097
  if (window == null || navigator == null) return false;
1024
1098
  if ("matchMedia" in window) {
@@ -1046,551 +1120,454 @@ var touch_default = (() => {
1046
1120
  } });
1047
1121
  return instance;
1048
1122
  })();
1049
-
1050
- class OuiSplitterElement extends HTMLElement {
1051
- static observedAttributes = ['max', 'min', 'size', 'type'];
1052
- #splitter;
1053
- // Getters and setters
1054
- get max() {
1055
- return this.#splitter.values.max;
1056
- }
1057
- set max(value) {
1058
- this.setAttribute('max', String(value));
1059
- }
1060
- get min() {
1061
- return this.#splitter.values.min;
1062
- }
1063
- set min(value) {
1064
- this.setAttribute('min', String(value));
1065
- }
1066
- get size() {
1067
- return this.#splitter.values.now.current;
1068
- }
1069
- set size(value) {
1070
- this.setAttribute('size', String(value));
1071
- }
1072
- get type() {
1073
- return this.getAttribute('type') ?? 'vertical';
1074
- }
1075
- set type(value) {
1076
- this.setAttribute('type', value);
1077
- }
1078
- // Constructor
1079
- constructor() {
1080
- super();
1081
- const panels = [...this.children].filter(child => child instanceof HTMLElement);
1082
- if (panels.length !== 2) {
1083
- throw new Error(`${SELECTOR$1} must have exactly two panels.`);
1084
- }
1085
- this.#splitter = new Splitter(this, panels);
1086
- }
1087
- // Methods
1088
- connectedCallback() {
1089
- this.#splitter.updateConnections(1);
1090
- }
1091
- disconnectedCallback() {
1092
- this.#splitter.updateConnections(0);
1093
- }
1094
- attributeChangedCallback(name) {
1095
- switch (name) {
1096
- case 'max':
1097
- case 'min':
1098
- case 'size':
1099
- this.#splitter.updateValues();
1100
- break;
1101
- case 'type':
1102
- this.#splitter.updateOrientation();
1103
- break;
1104
- }
1105
- }
1106
- }
1123
+ var OuiSplitterElement = class extends HTMLElement {
1124
+ static observedAttributes = [
1125
+ "max",
1126
+ "min",
1127
+ "size",
1128
+ "type"
1129
+ ];
1130
+ #splitter;
1131
+ get max() {
1132
+ return this.#splitter.values.max;
1133
+ }
1134
+ set max(value) {
1135
+ this.setAttribute("max", String(value));
1136
+ }
1137
+ get min() {
1138
+ return this.#splitter.values.min;
1139
+ }
1140
+ set min(value) {
1141
+ this.setAttribute("min", String(value));
1142
+ }
1143
+ get size() {
1144
+ return this.#splitter.values.now.current;
1145
+ }
1146
+ set size(value) {
1147
+ this.setAttribute("size", String(value));
1148
+ }
1149
+ get type() {
1150
+ return this.getAttribute("type") ?? "vertical";
1151
+ }
1152
+ set type(value) {
1153
+ this.setAttribute("type", value);
1154
+ }
1155
+ constructor() {
1156
+ super();
1157
+ const panels = [...this.children].filter((child) => child instanceof HTMLElement);
1158
+ if (panels.length !== 2) throw new Error(`${SELECTOR$1} must have exactly two panels.`);
1159
+ this.#splitter = new Splitter(this, panels);
1160
+ }
1161
+ connectedCallback() {
1162
+ this.#splitter.updateConnections(1);
1163
+ }
1164
+ disconnectedCallback() {
1165
+ this.#splitter.updateConnections(0);
1166
+ }
1167
+ attributeChangedCallback(name) {
1168
+ switch (name) {
1169
+ case "max":
1170
+ case "min":
1171
+ case "size":
1172
+ this.#splitter.updateValues();
1173
+ break;
1174
+ case "type":
1175
+ this.#splitter.updateOrientation();
1176
+ break;
1177
+ default: break;
1178
+ }
1179
+ }
1180
+ };
1107
1181
  let index$1 = 0;
1108
- class Splitter {
1109
- element;
1110
- handle;
1111
- panels;
1112
- rectangle;
1113
- separator;
1114
- types;
1115
- values;
1116
- constructor(element, panels) {
1117
- this.element = element;
1118
- this.panels = panels;
1119
- if (isNullableOrWhitespace(element.id)) {
1120
- element.id = `oui_splitter_${++index$1}`;
1121
- }
1122
- this.values = getValues(element);
1123
- this.handle = createHandle();
1124
- this.rectangle = element.getBoundingClientRect();
1125
- this.separator = createSeparator(this);
1126
- this.separator.append(this.handle);
1127
- panels[0].insertAdjacentElement('afterend', this.separator);
1128
- this.updateOrientation();
1129
- this.updateValues();
1130
- }
1131
- updateConnections(add) {
1132
- const method = METHODS_CONNECT[add];
1133
- MAPPED_ELEMENTS[method](this.element, this);
1134
- MAPPED_ELEMENTS[method](this.handle, this);
1135
- MAPPED_ELEMENTS[method](this.separator, this);
1136
- if (this.types.auto) {
1137
- RESIZE_OBSERVER[METHODS_OBSERVE[add]](this.element);
1138
- }
1139
- }
1140
- updateOrientation() {
1141
- this.types = getTypes(this);
1142
- if (this.types.auto) {
1143
- RESIZE_OBSERVER.observe(this.element);
1144
- }
1145
- else {
1146
- RESIZE_OBSERVER.unobserve(this.element);
1147
- }
1148
- if (this.types.horizontal) {
1149
- this.element.setAttribute(ATTRIBUTE_HORIZONTAL, '');
1150
- }
1151
- else {
1152
- this.element.removeAttribute(ATTRIBUTE_HORIZONTAL);
1153
- }
1154
- setAriaOrientation(this);
1155
- }
1156
- updateValues() {
1157
- this.values = getValues(this.element);
1158
- requestAnimationFrame(() => {
1159
- setSize(this, this.values.now.current);
1160
- setAriaValue(this);
1161
- });
1162
- }
1163
- }
1164
- //
1182
+ var Splitter = class {
1183
+ element;
1184
+ handle;
1185
+ panels;
1186
+ rectangle;
1187
+ separator;
1188
+ types;
1189
+ values;
1190
+ constructor(element, panels) {
1191
+ this.element = element;
1192
+ this.panels = panels;
1193
+ if (isNullableOrWhitespace(element.id)) element.id = `oui_splitter_${++index$1}`;
1194
+ this.values = getValues(element);
1195
+ this.handle = createHandle();
1196
+ this.rectangle = element.getBoundingClientRect();
1197
+ this.separator = createSeparator(this);
1198
+ this.separator.append(this.handle);
1199
+ panels[0].insertAdjacentElement("afterend", this.separator);
1200
+ this.updateOrientation();
1201
+ this.updateValues();
1202
+ }
1203
+ updateConnections(add) {
1204
+ const method = METHODS_CONNECT[add];
1205
+ MAPPED_ELEMENTS[method](this.element, this);
1206
+ MAPPED_ELEMENTS[method](this.handle, this);
1207
+ MAPPED_ELEMENTS[method](this.separator, this);
1208
+ if (this.types.auto) RESIZE_OBSERVER[METHODS_OBSERVE[add]](this.element);
1209
+ }
1210
+ updateOrientation() {
1211
+ this.types = getTypes(this);
1212
+ if (this.types.auto) RESIZE_OBSERVER.observe(this.element);
1213
+ else RESIZE_OBSERVER.unobserve(this.element);
1214
+ if (this.types.horizontal) this.element.setAttribute(ATTRIBUTE_HORIZONTAL, "");
1215
+ else this.element.removeAttribute(ATTRIBUTE_HORIZONTAL);
1216
+ setAriaOrientation(this);
1217
+ }
1218
+ updateValues() {
1219
+ this.values = getValues(this.element);
1220
+ requestAnimationFrame(() => {
1221
+ setSize(this, this.values.now.current);
1222
+ setAriaValue(this);
1223
+ });
1224
+ }
1225
+ };
1165
1226
  function createHandle() {
1166
- const handle = document.createElement('span');
1167
- handle.setAttribute('aria-hidden', 'true');
1168
- handle.setAttribute(ATTRIBUTE_HANDLE, '');
1169
- return handle;
1170
- }
1171
- function createSeparator(splitter) {
1172
- const separator = document.createElement('div');
1173
- separator.role = 'separator';
1174
- separator.tabIndex = 0;
1175
- separator.setAttribute('aria-controls', splitter.element.id);
1176
- separator.setAttribute('aria-label', 'Resize panels');
1177
- separator.setAttribute(ATTRIBUTE_SEPARATOR, '');
1178
- return separator;
1227
+ const handle = document.createElement("span");
1228
+ handle.setAttribute("aria-hidden", "true");
1229
+ handle.setAttribute(ATTRIBUTE_HANDLE, "");
1230
+ return handle;
1231
+ }
1232
+ function createSeparator(splitter$1) {
1233
+ const separator = document.createElement("div");
1234
+ separator.role = "separator";
1235
+ separator.tabIndex = 0;
1236
+ separator.setAttribute("aria-controls", splitter$1.element.id);
1237
+ separator.setAttribute("aria-label", "Resize panels");
1238
+ separator.setAttribute(ATTRIBUTE_SEPARATOR, "");
1239
+ return separator;
1179
1240
  }
1180
1241
  function getContained(min, value, max) {
1181
- return round(clamp(value, min, max), VALUE_DECIMALS);
1182
- }
1183
- function getSize(splitter, value) {
1184
- const { height, left, top, width } = splitter.rectangle;
1185
- const offset = value - (splitter.types.horizontal ? top : left);
1186
- const fraction = offset / (splitter.types.horizontal ? height : width);
1187
- return getContained(splitter.values.min, fraction, splitter.values.max);
1188
- }
1189
- function getTypes(splitter, width, height) {
1190
- const type = splitter.element.getAttribute('type')?.trim() ?? '';
1191
- if (type === 'horizontal') {
1192
- return {
1193
- auto: false,
1194
- horizontal: true,
1195
- };
1196
- }
1197
- if (type === 'auto') {
1198
- return {
1199
- auto: true,
1200
- horizontal: (height ?? splitter.rectangle.height) >
1201
- (width ?? splitter.rectangle.width),
1202
- };
1203
- }
1204
- return {
1205
- auto: false,
1206
- horizontal: false,
1207
- };
1242
+ return round(clamp(value, min, max), VALUE_DECIMALS);
1243
+ }
1244
+ function getSize(splitter$1, value) {
1245
+ const { height, left, top, width } = splitter$1.rectangle;
1246
+ const fraction = (value - (splitter$1.types.horizontal ? top : left)) / (splitter$1.types.horizontal ? height : width);
1247
+ return getContained(splitter$1.values.min, fraction, splitter$1.values.max);
1248
+ }
1249
+ function getTypes(splitter$1, width, height) {
1250
+ const type = splitter$1.element.getAttribute("type")?.trim() ?? "";
1251
+ if (type === "horizontal") return {
1252
+ auto: false,
1253
+ horizontal: true
1254
+ };
1255
+ if (type === "auto") return {
1256
+ auto: true,
1257
+ horizontal: (height ?? splitter$1.rectangle.height) > (width ?? splitter$1.rectangle.width)
1258
+ };
1259
+ return {
1260
+ auto: false,
1261
+ horizontal: false
1262
+ };
1208
1263
  }
1209
1264
  function getValue(element, name, defaultValue) {
1210
- const value = element.getAttribute(name);
1211
- if (isNullableOrWhitespace(value)) {
1212
- return defaultValue;
1213
- }
1214
- const parsed = Number.parseFloat(value);
1215
- if (Number.isNaN(parsed)) {
1216
- return defaultValue;
1217
- }
1218
- if (parsed < 0) {
1219
- return defaultValue;
1220
- }
1221
- return parsed > 1 ? parsed / NAVIGATION_MAXIMUM_TOTAL : parsed;
1265
+ const value = element.getAttribute(name);
1266
+ if (isNullableOrWhitespace(value)) return defaultValue;
1267
+ const parsed = Number.parseFloat(value);
1268
+ if (Number.isNaN(parsed)) return defaultValue;
1269
+ if (parsed < 0) return defaultValue;
1270
+ return parsed > 1 ? parsed / NAVIGATION_MAXIMUM_TOTAL : parsed;
1222
1271
  }
1223
1272
  function getValues(element) {
1224
- const values = {
1225
- max: getValue(element, 'max', NAVIGATION_MAXIMUM_PERCENTAGE),
1226
- min: getValue(element, 'min', NAVIGATION_MINIMUM_PERCENTAGE),
1227
- now: {
1228
- current: 0.5,
1229
- previous: 0.5,
1230
- },
1231
- };
1232
- const value = getContained(values.min, getValue(element, 'size', values.now.current), values.max);
1233
- values.now.current = value;
1234
- values.now.previous = value;
1235
- return values;
1236
- }
1237
- function onEnd(reset) {
1238
- if (splitter == null) {
1239
- return;
1240
- }
1241
- splitter.handle.removeAttribute(ATTRIBUTE_ACTIVE);
1242
- splitter.separator.removeAttribute(ATTRIBUTE_ACTIVE);
1243
- if (reset) {
1244
- setSize(splitter, splitter.values.now.previous);
1245
- }
1246
- else {
1247
- splitter.values.now.previous = splitter.values.now.current;
1248
- }
1249
- splitter = undefined;
1250
- STYLING_TOGGLER.remove();
1273
+ const values = {
1274
+ max: getValue(element, "max", NAVIGATION_MAXIMUM_PERCENTAGE),
1275
+ min: getValue(element, "min", NAVIGATION_MINIMUM_PERCENTAGE),
1276
+ now: {
1277
+ current: .5,
1278
+ previous: .5
1279
+ }
1280
+ };
1281
+ const value = getContained(values.min, getValue(element, "size", values.now.current), values.max);
1282
+ values.now.current = value;
1283
+ values.now.previous = value;
1284
+ return values;
1285
+ }
1286
+ function onEnd(reset$1) {
1287
+ if (splitter == null) return;
1288
+ splitter.handle.removeAttribute(ATTRIBUTE_ACTIVE);
1289
+ splitter.separator.removeAttribute(ATTRIBUTE_ACTIVE);
1290
+ if (reset$1) setSize(splitter, splitter.values.now.previous);
1291
+ else splitter.values.now.previous = splitter.values.now.current;
1292
+ splitter = void 0;
1293
+ STYLING_TOGGLER.remove();
1251
1294
  }
1252
1295
  function onKeydown(event) {
1253
- switch (true) {
1254
- case KEYS_ALL.has(event.key):
1255
- onNavigate(event);
1256
- break;
1257
- case event.key === 'Escape':
1258
- onEnd(true);
1259
- break;
1260
- }
1296
+ switch (true) {
1297
+ case KEYS_ALL.has(event.key):
1298
+ onNavigate(event);
1299
+ break;
1300
+ case event.key === "Escape":
1301
+ onEnd(true);
1302
+ break;
1303
+ default: break;
1304
+ }
1261
1305
  }
1262
1306
  function onNavigate(event) {
1263
- const splitter = MAPPED_ELEMENTS.get(findAncestor(event.target, '[oui-splitter-separator]'));
1264
- if (splitter == null) {
1265
- return;
1266
- }
1267
- const { types, values } = splitter;
1268
- if (KEYS_ABSOLUTE.has(event.key)) {
1269
- setSize(splitter, event.key === 'End' ? values.max : values.min, true);
1270
- return;
1271
- }
1272
- if ((types.horizontal && !KEYS_HORIZONTAL.has(event.key)) ||
1273
- !(types.horizontal || KEYS_VERTICAL.has(event.key))) {
1274
- return;
1275
- }
1276
- const offset = KEYS_NEGATIVE.has(event.key) ? -1 : 1;
1277
- setSize(splitter, getContained(values.min, values.now.current + offset * NAVIGATION_MODIFIER, values.max), true);
1307
+ const splitter$1 = MAPPED_ELEMENTS.get(findAncestor(event.target, "[oui-splitter-separator]"));
1308
+ if (splitter$1 == null) return;
1309
+ const { types, values } = splitter$1;
1310
+ if (KEYS_ABSOLUTE.has(event.key)) {
1311
+ setSize(splitter$1, event.key === "End" ? values.max : values.min, true);
1312
+ return;
1313
+ }
1314
+ if (types.horizontal && !KEYS_HORIZONTAL.has(event.key) || !(types.horizontal || KEYS_VERTICAL.has(event.key))) return;
1315
+ const offset = KEYS_NEGATIVE.has(event.key) ? -1 : 1;
1316
+ setSize(splitter$1, getContained(values.min, values.now.current + offset * NAVIGATION_MODIFIER, values.max), true);
1278
1317
  }
1279
1318
  function onObservation(entries) {
1280
- if (frame != null) {
1281
- cancelAnimationFrame(frame);
1282
- }
1283
- frame = requestAnimationFrame(() => {
1284
- for (const entry of entries) {
1285
- const splitter = MAPPED_ELEMENTS.get(entry.target);
1286
- if (splitter == null) {
1287
- return;
1288
- }
1289
- splitter.types = getTypes(splitter, entry.contentRect.width, entry.contentRect.height);
1290
- if (splitter.types.horizontal) {
1291
- splitter.element.setAttribute(ATTRIBUTE_HORIZONTAL, '');
1292
- }
1293
- else {
1294
- splitter.element.removeAttribute(ATTRIBUTE_HORIZONTAL);
1295
- }
1296
- setAriaOrientation(splitter);
1297
- }
1298
- frame = undefined;
1299
- });
1319
+ if (frame != null) cancelAnimationFrame(frame);
1320
+ frame = requestAnimationFrame(() => {
1321
+ for (const entry of entries) {
1322
+ const splitter$1 = MAPPED_ELEMENTS.get(entry.target);
1323
+ if (splitter$1 == null) return;
1324
+ splitter$1.types = getTypes(splitter$1, entry.contentRect.width, entry.contentRect.height);
1325
+ if (splitter$1.types.horizontal) splitter$1.element.setAttribute(ATTRIBUTE_HORIZONTAL, "");
1326
+ else splitter$1.element.removeAttribute(ATTRIBUTE_HORIZONTAL);
1327
+ setAriaOrientation(splitter$1);
1328
+ }
1329
+ frame = void 0;
1330
+ });
1300
1331
  }
1301
1332
  function onPointerdown(event) {
1302
- if ((event.type === 'mousedown' && touch_default.value) ||
1303
- (event.type === 'touchstart' && !touch_default.value)) {
1304
- return;
1305
- }
1306
- splitter = MAPPED_ELEMENTS.get(findAncestor(event.target, SELECTOR_HANDLE));
1307
- if (splitter == null) {
1308
- return;
1309
- }
1310
- if (touch_default.value) {
1311
- event.preventDefault();
1312
- }
1313
- splitter.handle.setAttribute(ATTRIBUTE_ACTIVE, '');
1314
- splitter.separator.setAttribute(ATTRIBUTE_ACTIVE, '');
1315
- splitter.rectangle = splitter.element.getBoundingClientRect();
1316
- STYLING_TOGGLER.set();
1333
+ if (event.type === "mousedown" && touch_default.value || event.type === "touchstart" && !touch_default.value) return;
1334
+ splitter = MAPPED_ELEMENTS.get(findAncestor(event.target, SELECTOR_HANDLE));
1335
+ if (splitter == null) return;
1336
+ if (touch_default.value) event.preventDefault();
1337
+ splitter.handle.setAttribute(ATTRIBUTE_ACTIVE, "");
1338
+ splitter.separator.setAttribute(ATTRIBUTE_ACTIVE, "");
1339
+ splitter.rectangle = splitter.element.getBoundingClientRect();
1340
+ STYLING_TOGGLER.set();
1317
1341
  }
1318
1342
  function onPointermove(event) {
1319
- if (splitter == null) {
1320
- return;
1321
- }
1322
- const position = getPosition(event);
1323
- if (position != null) {
1324
- splitter.values.now.current = getSize(splitter, splitter.types.horizontal ? position.y : position.x);
1325
- setSize(splitter, splitter.values.now.current);
1326
- }
1343
+ if (splitter == null) return;
1344
+ const position = getPosition(event);
1345
+ if (position != null) {
1346
+ splitter.values.now.current = getSize(splitter, splitter.types.horizontal ? position.y : position.x);
1347
+ setSize(splitter, splitter.values.now.current);
1348
+ }
1327
1349
  }
1328
1350
  function onPointerup() {
1329
- if (splitter != null) {
1330
- onEnd(false);
1331
- }
1332
- }
1333
- function setAriaOrientation(splitter) {
1334
- splitter.separator.setAttribute('aria-orientation', splitter.types.horizontal ? 'horizontal' : 'vertical');
1335
- }
1336
- function setAriaValue(splitter) {
1337
- splitter.separator.setAttribute('aria-valuemax', String(splitter.values.max));
1338
- splitter.separator.setAttribute('aria-valuemin', String(splitter.values.min));
1339
- splitter.separator.setAttribute('aria-valuenow', String(splitter.values.now.current));
1340
- }
1341
- function setSize(splitter, size, previous) {
1342
- splitter.values.now.current = size;
1343
- if (previous) {
1344
- splitter.values.now.previous = size;
1345
- }
1346
- splitter.element.style.setProperty('--oui-splitter-size', `${size}`);
1347
- setAriaValue(splitter);
1348
- }
1349
- //
1350
- const SELECTOR$1 = 'oui-splitter';
1351
+ if (splitter != null) onEnd(false);
1352
+ }
1353
+ function setAriaOrientation(splitter$1) {
1354
+ splitter$1.separator.setAttribute("aria-orientation", splitter$1.types.horizontal ? "horizontal" : "vertical");
1355
+ }
1356
+ function setAriaValue(splitter$1) {
1357
+ splitter$1.separator.setAttribute("aria-valuemax", String(splitter$1.values.max));
1358
+ splitter$1.separator.setAttribute("aria-valuemin", String(splitter$1.values.min));
1359
+ splitter$1.separator.setAttribute("aria-valuenow", String(splitter$1.values.now.current));
1360
+ }
1361
+ function setSize(splitter$1, size, previous) {
1362
+ splitter$1.values.now.current = size;
1363
+ if (previous) splitter$1.values.now.previous = size;
1364
+ splitter$1.element.style.setProperty("--oui-splitter-size", `${size}`);
1365
+ setAriaValue(splitter$1);
1366
+ }
1367
+ const SELECTOR$1 = "oui-splitter";
1351
1368
  const ATTRIBUTE_ACTIVE = `${SELECTOR$1}-active`;
1352
1369
  const ATTRIBUTE_HANDLE = `${SELECTOR$1}-handle`;
1353
1370
  const ATTRIBUTE_HORIZONTAL = `${SELECTOR$1}-horizontal`;
1354
1371
  const ATTRIBUTE_SEPARATOR = `${SELECTOR$1}-separator`;
1355
- const KEYS_ABSOLUTE = new Set(['End', 'Home']);
1356
- const KEYS_HORIZONTAL = new Set(['ArrowDown', 'ArrowUp']);
1357
- const KEYS_NEGATIVE = new Set(['ArrowLeft', 'ArrowUp']);
1358
- const KEYS_VERTICAL = new Set(['ArrowLeft', 'ArrowRight']);
1372
+ const KEYS_ABSOLUTE = new Set(["End", "Home"]);
1373
+ const KEYS_HORIZONTAL = new Set(["ArrowDown", "ArrowUp"]);
1374
+ const KEYS_NEGATIVE = new Set(["ArrowLeft", "ArrowUp"]);
1375
+ const KEYS_VERTICAL = new Set(["ArrowLeft", "ArrowRight"]);
1359
1376
  const KEYS_ALL = new Set([
1360
- ...KEYS_ABSOLUTE,
1361
- ...KEYS_HORIZONTAL,
1362
- ...KEYS_VERTICAL,
1377
+ ...KEYS_ABSOLUTE,
1378
+ ...KEYS_HORIZONTAL,
1379
+ ...KEYS_VERTICAL
1363
1380
  ]);
1364
- const MAPPED_ELEMENTS = new WeakMap();
1365
- const METHODS_CONNECT = ['delete', 'set'];
1366
- const METHODS_OBSERVE = ['unobserve', 'observe'];
1367
- const NAVIGATION_MAXIMUM_PERCENTAGE = 0.9;
1381
+ const MAPPED_ELEMENTS = /* @__PURE__ */ new WeakMap();
1382
+ const METHODS_CONNECT = ["delete", "set"];
1383
+ const METHODS_OBSERVE = ["unobserve", "observe"];
1384
+ const NAVIGATION_MAXIMUM_PERCENTAGE = .9;
1368
1385
  const NAVIGATION_MAXIMUM_TOTAL = 100;
1369
- const NAVIGATION_MINIMUM_PERCENTAGE = 0.1;
1370
- const NAVIGATION_MODIFIER = 0.05;
1386
+ const NAVIGATION_MINIMUM_PERCENTAGE = .1;
1387
+ const NAVIGATION_MODIFIER = .05;
1371
1388
  const RESIZE_OBSERVER = new ResizeObserver(onObservation);
1372
1389
  const SELECTOR_HANDLE = `[${ATTRIBUTE_HANDLE}]`;
1373
1390
  const STYLING_TOGGLER = toggleStyles(document.body, {
1374
- touchAction: 'none',
1375
- userSelect: 'none',
1376
- webkitUserSelect: 'none',
1391
+ touchAction: "none",
1392
+ userSelect: "none",
1393
+ webkitUserSelect: "none"
1377
1394
  });
1378
1395
  const VALUE_DECIMALS = 6;
1379
1396
  let frame;
1380
1397
  let splitter;
1381
- //
1382
1398
  customElements.define(SELECTOR$1, OuiSplitterElement);
1383
- on(document, 'keydown', onKeydown);
1384
- on(document, 'mousedown', onPointerdown);
1385
- on(document, 'pointermove', onPointermove);
1386
- on(document, 'pointerup', onPointerup);
1387
- on(document, 'touchcancel', onPointerup, { passive: false });
1388
- on(document, 'touchstart', onPointerdown, { passive: false });
1389
-
1390
- class Tooltip {
1391
- attributes;
1392
- floatable;
1393
- timer;
1394
- constructor(anchor, content) {
1395
- this.attributes = content.attributes;
1396
- this.floatable = new Floatable({
1397
- anchor,
1398
- content: content.element,
1399
- defaultPosition: 'vertical',
1400
- interactive: false,
1401
- preferAbove: true,
1402
- positionAttribute: ATTRIBUTE_POSITION,
1403
- });
1404
- anchor.insertAdjacentElement('afterend', content.element);
1405
- TOOLTIPS_ALL.set(content.element, this);
1406
- }
1407
- destroy() {
1408
- const { attributes, floatable } = this;
1409
- TOOLTIPS_ACTIVE.delete(this);
1410
- TOOLTIPS_ALL.delete(floatable.options.anchor);
1411
- TOOLTIPS_ALL.delete(floatable.options.content);
1412
- reset(floatable.options.anchor, attributes);
1413
- floatable.options.content.remove();
1414
- floatable.destroy();
1415
- this.attributes = undefined;
1416
- this.floatable = undefined;
1417
- }
1418
- }
1399
+ on(document, "keydown", onKeydown);
1400
+ on(document, "mousedown", onPointerdown);
1401
+ on(document, "pointermove", onPointermove);
1402
+ on(document, "pointerup", onPointerup);
1403
+ on(document, "touchcancel", onPointerup, { passive: false });
1404
+ on(document, "touchstart", onPointerdown, { passive: false });
1405
+ var Tooltip = class {
1406
+ attributes;
1407
+ floatable;
1408
+ timer;
1409
+ constructor(anchor, content) {
1410
+ this.attributes = content.attributes;
1411
+ this.floatable = new Floatable({
1412
+ anchor,
1413
+ content: content.element,
1414
+ defaultPosition: "vertical",
1415
+ interactive: false,
1416
+ preferAbove: true,
1417
+ positionAttribute: ATTRIBUTE_POSITION
1418
+ });
1419
+ anchor.insertAdjacentElement("afterend", content.element);
1420
+ TOOLTIPS_ALL.set(content.element, this);
1421
+ }
1422
+ destroy() {
1423
+ const { attributes, floatable } = this;
1424
+ TOOLTIPS_ACTIVE.delete(this);
1425
+ TOOLTIPS_ALL.delete(floatable.options.anchor);
1426
+ TOOLTIPS_ALL.delete(floatable.options.content);
1427
+ reset(floatable.options.anchor, attributes);
1428
+ floatable.options.content.remove();
1429
+ floatable.destroy();
1430
+ this.attributes = void 0;
1431
+ this.floatable = void 0;
1432
+ }
1433
+ };
1419
1434
  function addTooltip(anchor) {
1420
- if (TOOLTIPS_ALL.has(anchor)) {
1421
- return;
1422
- }
1423
- const content = getContent(anchor);
1424
- if (content != null) {
1425
- TOOLTIPS_ALL.set(anchor, new Tooltip(anchor, content));
1426
- }
1435
+ if (TOOLTIPS_ALL.has(anchor)) return;
1436
+ const content = getContent(anchor);
1437
+ if (content != null) TOOLTIPS_ALL.set(anchor, new Tooltip(anchor, content));
1427
1438
  }
1428
1439
  function closeTooltips(next) {
1429
- const tooltips = [...TOOLTIPS_ACTIVE];
1430
- for (const active of tooltips) {
1431
- if (active === next) {
1432
- continue;
1433
- }
1434
- if (active.timer != null) {
1435
- clearTimeout(active.timer);
1436
- }
1437
- active.floatable.options.content.removeAttribute('oui-tooltip-content-active');
1438
- requestAnimationFrame(() => {
1439
- active.timer = setTimeout(() => {
1440
- TOOLTIPS_ACTIVE.delete(active);
1441
- active.floatable.toggle(false);
1442
- }, delay);
1443
- });
1444
- }
1440
+ const tooltips = [...TOOLTIPS_ACTIVE];
1441
+ for (const active of tooltips) {
1442
+ if (active === next) continue;
1443
+ if (active.timer != null) clearTimeout(active.timer);
1444
+ active.floatable.options.content.removeAttribute("oui-tooltip-content-active");
1445
+ requestAnimationFrame(() => {
1446
+ active.timer = setTimeout(() => {
1447
+ TOOLTIPS_ACTIVE.delete(active);
1448
+ active.floatable.toggle(false);
1449
+ }, delay);
1450
+ });
1451
+ }
1445
1452
  }
1446
1453
  function getContent(anchor) {
1447
- const attributes = {
1448
- ariaDescribedby: anchor.getAttribute('aria-describedby'),
1449
- ariaLabelledBy: anchor.getAttribute('aria-labelledby'),
1450
- };
1451
- const wrapper = getWrapper(anchor);
1452
- const labelledElements = getElements(attributes.ariaLabelledBy);
1453
- if (labelledElements.length > 0) {
1454
- anchor.setAttribute('aria-labelledby', wrapper.id);
1455
- for (const element of labelledElements) {
1456
- wrapper.append(element);
1457
- }
1458
- return {
1459
- attributes,
1460
- element: wrapper,
1461
- };
1462
- }
1463
- const describedElements = getElements(attributes.ariaDescribedby);
1464
- if (describedElements.length > 0) {
1465
- anchor.setAttribute('aria-describedby', wrapper.id);
1466
- for (const element of describedElements) {
1467
- wrapper.append(element);
1468
- }
1469
- return {
1470
- attributes,
1471
- element: wrapper,
1472
- };
1473
- }
1474
- let content = anchor.getAttribute('aria-label');
1475
- if (isNullableOrWhitespace(content)) {
1476
- content = anchor.getAttribute('aria-description');
1477
- }
1478
- if (isNullableOrWhitespace(content)) {
1479
- return;
1480
- }
1481
- const paragraph = document.createElement('p');
1482
- paragraph.textContent = content;
1483
- wrapper.append(paragraph);
1484
- return {
1485
- attributes,
1486
- element: wrapper,
1487
- };
1454
+ const attributes = {
1455
+ ariaDescribedby: anchor.getAttribute("aria-describedby"),
1456
+ ariaLabelledBy: anchor.getAttribute("aria-labelledby")
1457
+ };
1458
+ const wrapper = getWrapper(anchor);
1459
+ const labelledElements = getElements(attributes.ariaLabelledBy);
1460
+ if (labelledElements.length > 0) {
1461
+ anchor.setAttribute("aria-labelledby", wrapper.id);
1462
+ for (const element of labelledElements) wrapper.append(element);
1463
+ return {
1464
+ attributes,
1465
+ element: wrapper
1466
+ };
1467
+ }
1468
+ const describedElements = getElements(attributes.ariaDescribedby);
1469
+ if (describedElements.length > 0) {
1470
+ anchor.setAttribute("aria-describedby", wrapper.id);
1471
+ for (const element of describedElements) wrapper.append(element);
1472
+ return {
1473
+ attributes,
1474
+ element: wrapper
1475
+ };
1476
+ }
1477
+ let content = anchor.getAttribute("aria-label");
1478
+ if (isNullableOrWhitespace(content)) content = anchor.getAttribute("aria-description");
1479
+ if (isNullableOrWhitespace(content)) return;
1480
+ const paragraph = document.createElement("p");
1481
+ paragraph.textContent = content;
1482
+ wrapper.append(paragraph);
1483
+ return {
1484
+ attributes,
1485
+ element: wrapper
1486
+ };
1488
1487
  }
1489
1488
  function getElements(attribute) {
1490
- const ids = attribute?.split(EXPRESSION_WHITESPACE) ?? [];
1491
- const elements = [];
1492
- for (const id of ids) {
1493
- if (isNullableOrWhitespace(id)) {
1494
- continue;
1495
- }
1496
- const element = document.querySelector(`#${id}`);
1497
- if (element instanceof HTMLElement) {
1498
- const cloned = element.cloneNode(true);
1499
- cloned.hidden = false;
1500
- elements.push(cloned);
1501
- }
1502
- }
1503
- return elements;
1489
+ const ids = attribute?.split(EXPRESSION_WHITESPACE) ?? [];
1490
+ const elements = [];
1491
+ for (const id of ids) {
1492
+ if (isNullableOrWhitespace(id)) continue;
1493
+ const element = document.querySelector(`#${id}`);
1494
+ if (element instanceof HTMLElement) {
1495
+ const cloned = element.cloneNode(true);
1496
+ cloned.hidden = false;
1497
+ elements.push(cloned);
1498
+ }
1499
+ }
1500
+ return elements;
1504
1501
  }
1505
1502
  function getWrapper(anchor) {
1506
- const wrapper = document.createElement('div');
1507
- wrapper.setAttribute(ATTRIBUTE_CONTENT, '');
1508
- wrapper.className = anchor.getAttribute(ATTRIBUTE_CLASS) ?? '';
1509
- wrapper.hidden = true;
1510
- wrapper.id = `${SELECTOR}-${++index}`;
1511
- wrapper.role = 'tooltip';
1512
- wrapper.tabIndex = -1;
1513
- return wrapper;
1503
+ const wrapper = document.createElement("div");
1504
+ wrapper.setAttribute(ATTRIBUTE_CONTENT, "");
1505
+ wrapper.className = anchor.getAttribute(ATTRIBUTE_CLASS) ?? "";
1506
+ wrapper.hidden = true;
1507
+ wrapper.id = `${SELECTOR}-${++index}`;
1508
+ wrapper.role = "tooltip";
1509
+ wrapper.tabIndex = -1;
1510
+ return wrapper;
1514
1511
  }
1515
1512
  function onActivate(event) {
1516
- onToggle(event, true);
1513
+ onToggle(event, true);
1517
1514
  }
1518
1515
  function onClick(event) {
1519
- if (findAncestor(event.target, SELECTOR_CONTENT) != null) {
1520
- event.stopPropagation();
1521
- }
1516
+ if (findAncestor(event.target, SELECTOR_CONTENT) != null) event.stopPropagation();
1522
1517
  }
1523
1518
  function onDeactivate(event) {
1524
- onToggle(event, false);
1525
- }
1526
- function onToggle(event, activate) {
1527
- if (toggle != null) {
1528
- cancelAnimationFrame(toggle);
1529
- }
1530
- toggle = requestAnimationFrame(() => {
1531
- toggle = undefined;
1532
- const element = findAncestor(event.target, SELECTOR_FULL);
1533
- const tooltip = TOOLTIPS_ALL.get(element);
1534
- if (TOOLTIPS_ACTIVE.size > 0) {
1535
- closeTooltips(tooltip);
1536
- }
1537
- if (tooltip == null ||
1538
- tooltip.floatable.options.content.hasAttribute('oui-tooltip-content-active') === activate) {
1539
- return;
1540
- }
1541
- if (activate) {
1542
- if (tooltip.timer != null) {
1543
- clearTimeout(tooltip.timer);
1544
- }
1545
- TOOLTIPS_ACTIVE.add(tooltip);
1546
- tooltip.floatable.toggle(true);
1547
- requestAnimationFrame(() => {
1548
- tooltip.floatable.options.content.setAttribute('oui-tooltip-content-active', '');
1549
- });
1550
- return;
1551
- }
1552
- tooltip.floatable.options.content.removeAttribute('oui-tooltip-content-active');
1553
- tooltip.timer ??= setTimeout(() => {
1554
- TOOLTIPS_ACTIVE.delete(tooltip);
1555
- tooltip.floatable.toggle(false);
1556
- }, delay);
1557
- });
1519
+ onToggle(event, false);
1520
+ }
1521
+ function onToggle(event, activate$1) {
1522
+ if (toggle != null) cancelAnimationFrame(toggle);
1523
+ toggle = requestAnimationFrame(() => {
1524
+ toggle = void 0;
1525
+ const element = findAncestor(event.target, SELECTOR_FULL);
1526
+ const tooltip = TOOLTIPS_ALL.get(element);
1527
+ if (TOOLTIPS_ACTIVE.size > 0) closeTooltips(tooltip);
1528
+ if (tooltip == null || tooltip.floatable.options.content.hasAttribute("oui-tooltip-content-active") === activate$1) return;
1529
+ if (activate$1) {
1530
+ if (tooltip.timer != null) clearTimeout(tooltip.timer);
1531
+ TOOLTIPS_ACTIVE.add(tooltip);
1532
+ tooltip.floatable.toggle(true);
1533
+ requestAnimationFrame(() => {
1534
+ tooltip.floatable.options.content.setAttribute("oui-tooltip-content-active", "");
1535
+ });
1536
+ return;
1537
+ }
1538
+ tooltip.floatable.options.content.removeAttribute("oui-tooltip-content-active");
1539
+ tooltip.timer ??= setTimeout(() => {
1540
+ TOOLTIPS_ACTIVE.delete(tooltip);
1541
+ tooltip.floatable.toggle(false);
1542
+ }, delay);
1543
+ });
1558
1544
  }
1559
1545
  function removeTooltip(element) {
1560
- if (!element.hasAttribute(ATTRIBUTE_CONTENT)) {
1561
- TOOLTIPS_ALL.get(element)?.destroy();
1562
- }
1546
+ if (!element.hasAttribute(ATTRIBUTE_CONTENT)) TOOLTIPS_ALL.get(element)?.destroy();
1563
1547
  }
1564
1548
  function reset(anchor, attributes) {
1565
- if (attributes.ariaDescribedby == null) {
1566
- anchor.removeAttribute('aria-describedby');
1567
- }
1568
- else {
1569
- anchor.setAttribute('aria-describedby', attributes.ariaDescribedby);
1570
- }
1549
+ if (attributes.ariaDescribedby == null) anchor.removeAttribute("aria-describedby");
1550
+ else anchor.setAttribute("aria-describedby", attributes.ariaDescribedby);
1571
1551
  }
1572
1552
  function setDelay(value) {
1573
- delay = typeof value === 'number' && value >= 0 ? value : delay;
1553
+ delay = typeof value === "number" && value >= 0 ? value : delay;
1574
1554
  }
1575
- //
1576
- const SELECTOR = 'oui-tooltip';
1555
+ const SELECTOR = "oui-tooltip";
1577
1556
  const ATTRIBUTE_CLASS = `${SELECTOR}-class`;
1578
1557
  const ATTRIBUTE_CONTENT = `${SELECTOR}-content`;
1579
1558
  const ATTRIBUTE_POSITION = `${SELECTOR}-position`;
1580
1559
  const SELECTOR_CONTENT = `[${ATTRIBUTE_CONTENT}]`;
1581
1560
  const SELECTOR_FULL = `[${SELECTOR}], [${ATTRIBUTE_CONTENT}]`;
1582
1561
  const EXPRESSION_WHITESPACE = /\s+/;
1583
- const TOOLTIPS_ACTIVE = new Set();
1584
- const TOOLTIPS_ALL = new WeakMap();
1562
+ const TOOLTIPS_ACTIVE = /* @__PURE__ */ new Set();
1563
+ const TOOLTIPS_ALL = /* @__PURE__ */ new WeakMap();
1585
1564
  let delay = 250;
1586
1565
  let index = 0;
1587
1566
  let toggle;
1588
- //
1589
1567
  attributable(SELECTOR, addTooltip, removeTooltip);
1590
- on(document, 'click', onClick, { capture: true });
1591
- on(document, 'focusin', onActivate);
1592
- on(document, 'focusout', onDeactivate);
1593
- on(document, 'mousemove', onActivate);
1594
- on(document, 'touchstart', onActivate);
1595
-
1568
+ on(document, "click", onClick, { capture: true });
1569
+ on(document, "focusin", onActivate);
1570
+ on(document, "focusout", onDeactivate);
1571
+ on(document, "mousemove", onActivate);
1572
+ on(document, "touchstart", onActivate);
1596
1573
  export { OuiPopoverElement, OuiSplitterElement, setDelay };