@inertiaui/vanilla 0.6.0 → 1.0.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 (2) hide show
  1. package/dist/index.js +747 -825
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1,897 +1,819 @@
1
+ //#region src/helpers.ts
1
2
  function generateId(prefix = "inertiaui_") {
2
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
3
- return `${prefix}${crypto.randomUUID()}`;
4
- }
5
- return `${prefix}${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 11)}`;
3
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return `${prefix}${crypto.randomUUID()}`;
4
+ return `${prefix}${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 11)}`;
6
5
  }
7
6
  function strToLowercase(key) {
8
- return key.toLowerCase();
7
+ return key.toLowerCase();
9
8
  }
10
9
  function except(target, keys, ignoreCase = false) {
11
- if (ignoreCase) {
12
- keys = keys.map(strToLowercase);
13
- }
14
- if (Array.isArray(target)) {
15
- return target.filter((key) => !keys.includes(ignoreCase ? strToLowercase(key) : key));
16
- }
17
- return Object.keys(target).reduce((acc, key) => {
18
- if (!keys.includes(ignoreCase ? strToLowercase(key) : key)) {
19
- acc[key] = target[key];
20
- }
21
- return acc;
22
- }, {});
10
+ if (ignoreCase) keys = keys.map(strToLowercase);
11
+ if (Array.isArray(target)) return target.filter((key) => !keys.includes(ignoreCase ? strToLowercase(key) : key));
12
+ return Object.keys(target).reduce((acc, key) => {
13
+ if (!keys.includes(ignoreCase ? strToLowercase(key) : key)) acc[key] = target[key];
14
+ return acc;
15
+ }, {});
23
16
  }
24
17
  function only(target, keys, ignoreCase = false) {
25
- if (ignoreCase) {
26
- keys = keys.map(strToLowercase);
27
- }
28
- if (Array.isArray(target)) {
29
- return target.filter((key) => keys.includes(ignoreCase ? strToLowercase(key) : key));
30
- }
31
- return Object.keys(target).reduce((acc, key) => {
32
- if (keys.includes(ignoreCase ? strToLowercase(key) : key)) {
33
- acc[key] = target[key];
34
- }
35
- return acc;
36
- }, {});
18
+ if (ignoreCase) keys = keys.map(strToLowercase);
19
+ if (Array.isArray(target)) return target.filter((key) => keys.includes(ignoreCase ? strToLowercase(key) : key));
20
+ return Object.keys(target).reduce((acc, key) => {
21
+ if (keys.includes(ignoreCase ? strToLowercase(key) : key)) acc[key] = target[key];
22
+ return acc;
23
+ }, {});
37
24
  }
38
25
  function rejectNullValues(target) {
39
- if (Array.isArray(target)) {
40
- return target.filter((item) => item !== null);
41
- }
42
- return Object.keys(target).reduce((acc, key) => {
43
- if (key in target && target[key] !== null) {
44
- acc[key] = target[key];
45
- }
46
- return acc;
47
- }, {});
26
+ if (Array.isArray(target)) return target.filter((item) => item !== null);
27
+ return Object.keys(target).reduce((acc, key) => {
28
+ if (key in target && target[key] !== null) acc[key] = target[key];
29
+ return acc;
30
+ }, {});
48
31
  }
49
32
  function kebabCase(string) {
50
- if (!string) return "";
51
- return string.replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").replace(/([a-z\d])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").replace(/-+/g, "-").toLowerCase();
33
+ if (!string) return "";
34
+ return string.replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").replace(/([a-z\d])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").replace(/-+/g, "-").toLowerCase();
52
35
  }
53
36
  function isStandardDomEvent(eventName) {
54
- const lowerEventName = eventName.toLowerCase();
55
- const standardPatterns = [
56
- /^on(click|dblclick|mousedown|mouseup|mouseover|mouseout|mousemove|mouseenter|mouseleave)$/,
57
- /^on(keydown|keyup|keypress)$/,
58
- /^on(focus|blur|change|input|submit|reset)$/,
59
- /^on(load|unload|error|resize|scroll)$/,
60
- /^on(touchstart|touchend|touchmove|touchcancel)$/,
61
- /^on(pointerdown|pointerup|pointermove|pointerenter|pointerleave|pointercancel)$/,
62
- /^on(drag|dragstart|dragend|dragenter|dragleave|dragover|drop)$/,
63
- /^on(animationstart|animationend|animationiteration)$/,
64
- /^on(transitionstart|transitionend|transitionrun|transitioncancel)$/
65
- ];
66
- return standardPatterns.some((pattern) => pattern.test(lowerEventName));
37
+ const lowerEventName = eventName.toLowerCase();
38
+ return [
39
+ /^on(click|dblclick|mousedown|mouseup|mouseover|mouseout|mousemove|mouseenter|mouseleave)$/,
40
+ /^on(keydown|keyup|keypress)$/,
41
+ /^on(focus|blur|change|input|submit|reset)$/,
42
+ /^on(load|unload|error|resize|scroll)$/,
43
+ /^on(touchstart|touchend|touchmove|touchcancel)$/,
44
+ /^on(pointerdown|pointerup|pointermove|pointerenter|pointerleave|pointercancel)$/,
45
+ /^on(drag|dragstart|dragend|dragenter|dragleave|dragover|drop)$/,
46
+ /^on(animationstart|animationend|animationiteration)$/,
47
+ /^on(transitionstart|transitionend|transitionrun|transitioncancel)$/
48
+ ].some((pattern) => pattern.test(lowerEventName));
67
49
  }
68
50
  function onceChildrenRendered(element, callback) {
69
- if (element.children.length > 0) {
70
- callback();
71
- return;
72
- }
73
- const observer = new MutationObserver(() => {
74
- if (element.children.length > 0) {
75
- observer.disconnect();
76
- callback();
77
- }
78
- });
79
- observer.observe(element, { childList: true });
51
+ if (element.children.length > 0) {
52
+ callback();
53
+ return;
54
+ }
55
+ const observer = new MutationObserver(() => {
56
+ if (element.children.length > 0) {
57
+ observer.disconnect();
58
+ callback();
59
+ }
60
+ });
61
+ observer.observe(element, { childList: true });
80
62
  }
81
63
  function sameUrlPath(url1, url2) {
82
- if (!url1 || !url2) {
83
- return false;
84
- }
85
- const origin = typeof window !== "undefined" ? window.location.origin : "http://localhost";
86
- const parsed1 = typeof url1 === "string" ? new URL(url1, origin) : url1;
87
- const parsed2 = typeof url2 === "string" ? new URL(url2, origin) : url2;
88
- return `${parsed1.origin}${parsed1.pathname}` === `${parsed2.origin}${parsed2.pathname}`;
89
- }
90
- const easings = {
91
- linear: "linear",
92
- in: "cubic-bezier(0.4, 0, 1, 1)",
93
- out: "cubic-bezier(0, 0, 0.2, 1)",
94
- inOut: "cubic-bezier(0.4, 0, 0.2, 1)"
64
+ if (!url1 || !url2) return false;
65
+ const origin = typeof window !== "undefined" ? window.location.origin : "http://localhost";
66
+ const parsed1 = typeof url1 === "string" ? new URL(url1, origin) : url1;
67
+ const parsed2 = typeof url2 === "string" ? new URL(url2, origin) : url2;
68
+ return `${parsed1.origin}${parsed1.pathname}` === `${parsed2.origin}${parsed2.pathname}`;
69
+ }
70
+ //#endregion
71
+ //#region src/animate.ts
72
+ /**
73
+ * Tailwind CSS easing functions
74
+ */
75
+ var easings = {
76
+ linear: "linear",
77
+ in: "cubic-bezier(0.4, 0, 1, 1)",
78
+ out: "cubic-bezier(0, 0, 0.2, 1)",
79
+ inOut: "cubic-bezier(0.4, 0, 0.2, 1)"
95
80
  };
96
- const defaultOptions = {
97
- duration: 300,
98
- easing: "inOut",
99
- fill: "forwards"
81
+ var defaultOptions = {
82
+ duration: 300,
83
+ easing: "inOut",
84
+ fill: "forwards"
100
85
  };
86
+ /**
87
+ * Animate an element using the Web Animations API.
88
+ * Returns a promise that resolves when the animation completes.
89
+ *
90
+ * @example
91
+ * await animate(element, [
92
+ * { transform: 'scale(0.95)', opacity: 0 },
93
+ * { transform: 'scale(1)', opacity: 1 }
94
+ * ])
95
+ *
96
+ * @example
97
+ * await animate(element, keyframes.fadeIn, { duration: 200 })
98
+ */
101
99
  function animate(element, keyframes, options = {}) {
102
- const { duration, easing, fill } = { ...defaultOptions, ...options };
103
- const resolvedEasing = easing in easings ? easings[easing] : easing;
104
- const animation = element.animate(keyframes, {
105
- duration,
106
- easing: resolvedEasing,
107
- fill
108
- });
109
- return animation.finished.catch(() => animation);
110
- }
100
+ const { duration, easing, fill } = {
101
+ ...defaultOptions,
102
+ ...options
103
+ };
104
+ const resolvedEasing = easing in easings ? easings[easing] : easing;
105
+ const animation = element.animate(keyframes, {
106
+ duration,
107
+ easing: resolvedEasing,
108
+ fill
109
+ });
110
+ return animation.finished.catch(() => animation);
111
+ }
112
+ /**
113
+ * Cancel any running animations on an element
114
+ */
111
115
  function cancelAnimations(element) {
112
- element.getAnimations().forEach((animation) => animation.cancel());
113
- }
114
- const FOCUSABLE_SELECTORS = [
115
- "a[href]",
116
- "button:not([disabled])",
117
- "textarea:not([disabled])",
118
- "input:not([disabled])",
119
- "select:not([disabled])",
120
- '[tabindex]:not([tabindex="-1"])'
116
+ element.getAnimations().forEach((animation) => animation.cancel());
117
+ }
118
+ //#endregion
119
+ //#region src/dialog.ts
120
+ var FOCUSABLE_SELECTORS = [
121
+ "a[href]",
122
+ "button:not([disabled])",
123
+ "textarea:not([disabled])",
124
+ "input:not([disabled])",
125
+ "select:not([disabled])",
126
+ "[tabindex]:not([tabindex=\"-1\"])"
121
127
  ].join(", ");
122
- let scrollLockCount = 0;
123
- let originalOverflow = "";
124
- let originalPaddingRight = "";
128
+ var scrollLockCount = 0;
129
+ var originalOverflow = "";
130
+ var originalPaddingRight = "";
125
131
  function lockScroll() {
126
- if (scrollLockCount === 0) {
127
- originalOverflow = document.body.style.overflow;
128
- originalPaddingRight = document.body.style.paddingRight;
129
- const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
130
- document.body.style.overflow = "hidden";
131
- if (scrollbarWidth > 0) {
132
- document.body.style.paddingRight = `${scrollbarWidth}px`;
133
- }
134
- }
135
- scrollLockCount++;
136
- let unlocked = false;
137
- return function unlock() {
138
- if (unlocked) {
139
- return;
140
- }
141
- unlocked = true;
142
- unlockScroll();
143
- };
132
+ if (scrollLockCount === 0) {
133
+ originalOverflow = document.body.style.overflow;
134
+ originalPaddingRight = document.body.style.paddingRight;
135
+ const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
136
+ document.body.style.overflow = "hidden";
137
+ if (scrollbarWidth > 0) document.body.style.paddingRight = `${scrollbarWidth}px`;
138
+ }
139
+ scrollLockCount++;
140
+ let unlocked = false;
141
+ return function unlock() {
142
+ if (unlocked) return;
143
+ unlocked = true;
144
+ unlockScroll();
145
+ };
144
146
  }
145
147
  function unlockScroll() {
146
- scrollLockCount = Math.max(0, scrollLockCount - 1);
147
- if (scrollLockCount === 0) {
148
- document.body.style.overflow = originalOverflow;
149
- document.body.style.paddingRight = originalPaddingRight;
150
- }
148
+ scrollLockCount = Math.max(0, scrollLockCount - 1);
149
+ if (scrollLockCount === 0) {
150
+ document.body.style.overflow = originalOverflow;
151
+ document.body.style.paddingRight = originalPaddingRight;
152
+ }
151
153
  }
152
154
  function getFocusableElements(container) {
153
- if (!container) {
154
- return [];
155
- }
156
- return Array.from(container.querySelectorAll(FOCUSABLE_SELECTORS)).filter(
157
- (el) => el.getAttribute("aria-hidden") !== "true"
158
- );
159
- }
160
- const focusTrapStack = [];
155
+ if (!container) return [];
156
+ return Array.from(container.querySelectorAll(FOCUSABLE_SELECTORS)).filter((el) => el.getAttribute("aria-hidden") !== "true");
157
+ }
158
+ var focusTrapStack = [];
161
159
  function handleTrapKeyDown(event) {
162
- if (event.key !== "Tab" || focusTrapStack.length === 0) {
163
- return;
164
- }
165
- const { container } = focusTrapStack[focusTrapStack.length - 1];
166
- const focusableElements = getFocusableElements(container);
167
- if (focusableElements.length === 0) {
168
- return;
169
- }
170
- const firstElement = focusableElements[0];
171
- const lastElement = focusableElements[focusableElements.length - 1];
172
- if (event.shiftKey) {
173
- if (document.activeElement === firstElement || !container.contains(document.activeElement)) {
174
- event.preventDefault();
175
- lastElement.focus();
176
- }
177
- } else {
178
- if (document.activeElement === lastElement || !container.contains(document.activeElement)) {
179
- event.preventDefault();
180
- firstElement.focus();
181
- }
182
- }
160
+ if (event.key !== "Tab" || focusTrapStack.length === 0) return;
161
+ const { container } = focusTrapStack[focusTrapStack.length - 1];
162
+ const focusableElements = getFocusableElements(container);
163
+ if (focusableElements.length === 0) return;
164
+ const firstElement = focusableElements[0];
165
+ const lastElement = focusableElements[focusableElements.length - 1];
166
+ if (event.shiftKey) {
167
+ if (document.activeElement === firstElement || !container.contains(document.activeElement)) {
168
+ event.preventDefault();
169
+ lastElement.focus();
170
+ }
171
+ } else if (document.activeElement === lastElement || !container.contains(document.activeElement)) {
172
+ event.preventDefault();
173
+ firstElement.focus();
174
+ }
183
175
  }
184
176
  function handleTrapFocusIn(event) {
185
- if (focusTrapStack.length === 0) {
186
- return;
187
- }
188
- const { container } = focusTrapStack[focusTrapStack.length - 1];
189
- if (!container.contains(event.target)) {
190
- const focusableElements = getFocusableElements(container);
191
- if (focusableElements.length > 0) {
192
- focusableElements[0].focus();
193
- }
194
- }
177
+ if (focusTrapStack.length === 0) return;
178
+ const { container } = focusTrapStack[focusTrapStack.length - 1];
179
+ if (!container.contains(event.target)) {
180
+ const focusableElements = getFocusableElements(container);
181
+ if (focusableElements.length > 0) focusableElements[0].focus();
182
+ }
195
183
  }
196
184
  function createFocusTrap(container, options = {}) {
197
- const { initialFocus = true, initialFocusElement = null, returnFocus = true } = options;
198
- const previouslyFocused = document.activeElement;
199
- const entry = { container };
200
- if (focusTrapStack.length === 0) {
201
- document.addEventListener("keydown", handleTrapKeyDown);
202
- document.addEventListener("focusin", handleTrapFocusIn);
203
- }
204
- focusTrapStack.push(entry);
205
- function handleFocusOut(event) {
206
- if (event.relatedTarget !== null) {
207
- return;
208
- }
209
- queueMicrotask(() => {
210
- if (!container.contains(container.ownerDocument.activeElement)) {
211
- const focusableElements = getFocusableElements(container);
212
- if (focusableElements.length > 0) {
213
- focusableElements[0].focus();
214
- }
215
- }
216
- });
217
- }
218
- container.addEventListener("focusout", handleFocusOut);
219
- let rafId;
220
- if (initialFocus) {
221
- rafId = requestAnimationFrame(() => {
222
- rafId = void 0;
223
- if (initialFocusElement && container.contains(initialFocusElement)) {
224
- initialFocusElement.focus();
225
- } else {
226
- const focusableElements = getFocusableElements(container);
227
- if (focusableElements.length > 0) {
228
- focusableElements[0].focus();
229
- }
230
- }
231
- });
232
- }
233
- let cleaned = false;
234
- return function cleanup() {
235
- if (cleaned) {
236
- return;
237
- }
238
- cleaned = true;
239
- if (rafId !== void 0) {
240
- cancelAnimationFrame(rafId);
241
- }
242
- container.removeEventListener("focusout", handleFocusOut);
243
- const index = focusTrapStack.indexOf(entry);
244
- if (index >= 0) {
245
- focusTrapStack.splice(index, 1);
246
- }
247
- if (focusTrapStack.length === 0) {
248
- document.removeEventListener("keydown", handleTrapKeyDown);
249
- document.removeEventListener("focusin", handleTrapFocusIn);
250
- }
251
- if (returnFocus && previouslyFocused && typeof previouslyFocused.focus === "function" && previouslyFocused.isConnected) {
252
- previouslyFocused.focus();
253
- }
254
- };
185
+ const { initialFocus = true, initialFocusElement = null, returnFocus = true } = options;
186
+ const previouslyFocused = document.activeElement;
187
+ const entry = { container };
188
+ if (focusTrapStack.length === 0) {
189
+ document.addEventListener("keydown", handleTrapKeyDown);
190
+ document.addEventListener("focusin", handleTrapFocusIn);
191
+ }
192
+ focusTrapStack.push(entry);
193
+ function handleFocusOut(event) {
194
+ if (event.relatedTarget !== null) return;
195
+ queueMicrotask(() => {
196
+ if (!container.contains(container.ownerDocument.activeElement)) {
197
+ const focusableElements = getFocusableElements(container);
198
+ if (focusableElements.length > 0) focusableElements[0].focus();
199
+ }
200
+ });
201
+ }
202
+ container.addEventListener("focusout", handleFocusOut);
203
+ let rafId;
204
+ if (initialFocus) rafId = requestAnimationFrame(() => {
205
+ rafId = void 0;
206
+ if (initialFocusElement && container.contains(initialFocusElement)) initialFocusElement.focus();
207
+ else {
208
+ const focusableElements = getFocusableElements(container);
209
+ if (focusableElements.length > 0) focusableElements[0].focus();
210
+ }
211
+ });
212
+ let cleaned = false;
213
+ return function cleanup() {
214
+ if (cleaned) return;
215
+ cleaned = true;
216
+ if (rafId !== void 0) cancelAnimationFrame(rafId);
217
+ container.removeEventListener("focusout", handleFocusOut);
218
+ const index = focusTrapStack.indexOf(entry);
219
+ if (index >= 0) focusTrapStack.splice(index, 1);
220
+ if (focusTrapStack.length === 0) {
221
+ document.removeEventListener("keydown", handleTrapKeyDown);
222
+ document.removeEventListener("focusin", handleTrapFocusIn);
223
+ }
224
+ if (returnFocus && previouslyFocused && typeof previouslyFocused.focus === "function" && previouslyFocused.isConnected) previouslyFocused.focus();
225
+ };
255
226
  }
256
227
  function onEscapeKey(callback, options = {}) {
257
- const { preventDefault = false, stopPropagation = false } = options;
258
- function handler(event) {
259
- if (event.key === "Escape") {
260
- if (preventDefault) {
261
- event.preventDefault();
262
- }
263
- if (stopPropagation) {
264
- event.stopPropagation();
265
- }
266
- callback(event);
267
- }
268
- }
269
- document.addEventListener("keydown", handler);
270
- return function cleanup() {
271
- document.removeEventListener("keydown", handler);
272
- };
273
- }
274
- const ariaHiddenStack = [];
228
+ const { preventDefault = false, stopPropagation = false } = options;
229
+ function handler(event) {
230
+ if (event.key === "Escape") {
231
+ if (preventDefault) event.preventDefault();
232
+ if (stopPropagation) event.stopPropagation();
233
+ callback(event);
234
+ }
235
+ }
236
+ document.addEventListener("keydown", handler);
237
+ return function cleanup() {
238
+ document.removeEventListener("keydown", handler);
239
+ };
240
+ }
241
+ var ariaHiddenStack = [];
275
242
  function markAriaHidden(elementOrSelector) {
276
- const element = typeof elementOrSelector === "string" ? document.querySelector(elementOrSelector) : elementOrSelector;
277
- if (!element) {
278
- return function noop() {
279
- };
280
- }
281
- const existingIndex = ariaHiddenStack.findIndex((item) => item.element === element);
282
- if (existingIndex >= 0) {
283
- ariaHiddenStack[existingIndex].count++;
284
- } else {
285
- const originalValue = element.getAttribute("aria-hidden");
286
- ariaHiddenStack.push({ element, originalValue, count: 1 });
287
- element.setAttribute("aria-hidden", "true");
288
- }
289
- let cleaned = false;
290
- return function cleanup() {
291
- if (cleaned) {
292
- return;
293
- }
294
- cleaned = true;
295
- unmarkAriaHidden(element);
296
- };
243
+ const element = typeof elementOrSelector === "string" ? document.querySelector(elementOrSelector) : elementOrSelector;
244
+ if (!element) return function noop() {};
245
+ const existingIndex = ariaHiddenStack.findIndex((item) => item.element === element);
246
+ if (existingIndex >= 0) ariaHiddenStack[existingIndex].count++;
247
+ else {
248
+ const originalValue = element.getAttribute("aria-hidden");
249
+ ariaHiddenStack.push({
250
+ element,
251
+ originalValue,
252
+ count: 1
253
+ });
254
+ element.setAttribute("aria-hidden", "true");
255
+ }
256
+ let cleaned = false;
257
+ return function cleanup() {
258
+ if (cleaned) return;
259
+ cleaned = true;
260
+ unmarkAriaHidden(element);
261
+ };
297
262
  }
298
263
  function unmarkAriaHidden(element) {
299
- const index = ariaHiddenStack.findIndex((item) => item.element === element);
300
- if (index < 0) {
301
- return;
302
- }
303
- ariaHiddenStack[index].count--;
304
- if (ariaHiddenStack[index].count <= 0) {
305
- const { originalValue } = ariaHiddenStack[index];
306
- if (originalValue === null) {
307
- element.removeAttribute("aria-hidden");
308
- } else {
309
- element.setAttribute("aria-hidden", originalValue);
310
- }
311
- ariaHiddenStack.splice(index, 1);
312
- }
313
- }
264
+ const index = ariaHiddenStack.findIndex((item) => item.element === element);
265
+ if (index < 0) return;
266
+ ariaHiddenStack[index].count--;
267
+ if (ariaHiddenStack[index].count <= 0) {
268
+ const { originalValue } = ariaHiddenStack[index];
269
+ if (originalValue === null) element.removeAttribute("aria-hidden");
270
+ else element.setAttribute("aria-hidden", originalValue);
271
+ ariaHiddenStack.splice(index, 1);
272
+ }
273
+ }
274
+ //#endregion
275
+ //#region src/clickOutside.ts
314
276
  function onClickOutside(elements, callback) {
315
- const targets = Array.isArray(elements) ? elements : [elements];
316
- function handler(event) {
317
- const target = event.target;
318
- for (const el of targets) {
319
- if (el.contains(target)) {
320
- return;
321
- }
322
- }
323
- let node = target;
324
- while (node) {
325
- if (node instanceof HTMLElement && node.hasAttribute("data-inertiaui-portal")) {
326
- return;
327
- }
328
- node = node.parentNode;
329
- }
330
- callback(event);
331
- }
332
- const timeoutId = setTimeout(() => {
333
- document.addEventListener("pointerdown", handler, true);
334
- }, 0);
335
- let cleaned = false;
336
- return function cleanup() {
337
- if (cleaned) {
338
- return;
339
- }
340
- cleaned = true;
341
- clearTimeout(timeoutId);
342
- document.removeEventListener("pointerdown", handler, true);
343
- };
344
- }
277
+ const targets = Array.isArray(elements) ? elements : [elements];
278
+ function handler(event) {
279
+ const target = event.target;
280
+ for (const el of targets) if (el.contains(target)) return;
281
+ let node = target;
282
+ while (node) {
283
+ if (node instanceof HTMLElement && node.hasAttribute("data-inertiaui-portal")) return;
284
+ node = node.parentNode;
285
+ }
286
+ callback(event);
287
+ }
288
+ const timeoutId = setTimeout(() => {
289
+ document.addEventListener("pointerdown", handler, true);
290
+ }, 0);
291
+ let cleaned = false;
292
+ return function cleanup() {
293
+ if (cleaned) return;
294
+ cleaned = true;
295
+ clearTimeout(timeoutId);
296
+ document.removeEventListener("pointerdown", handler, true);
297
+ };
298
+ }
299
+ //#endregion
300
+ //#region src/menu.ts
345
301
  function createMenuNavigation(container, options = {}) {
346
- const {
347
- itemSelector = '[role="menuitem"]:not([disabled]):not([aria-disabled="true"])',
348
- orientation = "vertical",
349
- loop = true,
350
- typeAhead = true,
351
- onActivate
352
- } = options;
353
- let typeAheadBuffer = "";
354
- let typeAheadTimeout;
355
- function getItems() {
356
- return Array.from(container.querySelectorAll(itemSelector));
357
- }
358
- function getActiveIndex() {
359
- const items2 = getItems();
360
- const focused = document.activeElement;
361
- return items2.indexOf(focused);
362
- }
363
- function focusItem(index) {
364
- const items2 = getItems();
365
- if (items2.length === 0) {
366
- return;
367
- }
368
- const targetIndex = loop ? (index % items2.length + items2.length) % items2.length : Math.max(0, Math.min(index, items2.length - 1));
369
- const item = items2[targetIndex];
370
- items2.forEach((el) => el.setAttribute("tabindex", "-1"));
371
- item.setAttribute("tabindex", "0");
372
- item.focus();
373
- }
374
- function handleKeyDown(event) {
375
- const items2 = getItems();
376
- if (items2.length === 0) {
377
- return;
378
- }
379
- const nextKey = orientation === "vertical" ? "ArrowDown" : "ArrowRight";
380
- const prevKey = orientation === "vertical" ? "ArrowUp" : "ArrowLeft";
381
- switch (event.key) {
382
- case nextKey: {
383
- event.preventDefault();
384
- const currentIndex = getActiveIndex();
385
- focusItem(currentIndex + 1);
386
- break;
387
- }
388
- case prevKey: {
389
- event.preventDefault();
390
- const currentIndex = getActiveIndex();
391
- focusItem(currentIndex - 1);
392
- break;
393
- }
394
- case "Home": {
395
- event.preventDefault();
396
- focusItem(0);
397
- break;
398
- }
399
- case "End": {
400
- event.preventDefault();
401
- focusItem(items2.length - 1);
402
- break;
403
- }
404
- case "Enter":
405
- case " ": {
406
- event.preventDefault();
407
- const focused = document.activeElement;
408
- if (items2.includes(focused)) {
409
- focused.click();
410
- onActivate == null ? void 0 : onActivate(focused);
411
- }
412
- break;
413
- }
414
- default: {
415
- if (typeAhead && event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
416
- event.preventDefault();
417
- typeAheadBuffer += event.key.toLowerCase();
418
- if (typeAheadTimeout) {
419
- clearTimeout(typeAheadTimeout);
420
- }
421
- typeAheadTimeout = setTimeout(() => {
422
- typeAheadBuffer = "";
423
- }, 350);
424
- const match = items2.find((item) => {
425
- const text = (item.textContent || "").trim().toLowerCase();
426
- return text.startsWith(typeAheadBuffer);
427
- });
428
- if (match) {
429
- const index = items2.indexOf(match);
430
- focusItem(index);
431
- }
432
- }
433
- break;
434
- }
435
- }
436
- }
437
- container.addEventListener("keydown", handleKeyDown);
438
- const items = getItems();
439
- items.forEach((el, i) => el.setAttribute("tabindex", i === 0 ? "0" : "-1"));
440
- let rafId;
441
- if (items.length > 0) {
442
- rafId = requestAnimationFrame(() => {
443
- rafId = void 0;
444
- items[0].focus();
445
- });
446
- }
447
- let cleaned = false;
448
- return function cleanup() {
449
- if (cleaned) {
450
- return;
451
- }
452
- cleaned = true;
453
- if (rafId !== void 0) {
454
- cancelAnimationFrame(rafId);
455
- }
456
- if (typeAheadTimeout) {
457
- clearTimeout(typeAheadTimeout);
458
- }
459
- container.removeEventListener("keydown", handleKeyDown);
460
- };
461
- }
462
- const ANCHOR_CLASS_PREFIX = "iui-anchor-";
463
- let _supportsAnchor = null;
302
+ const { itemSelector = "[role=\"menuitem\"]:not([disabled]):not([aria-disabled=\"true\"])", orientation = "vertical", loop = true, typeAhead = true, onActivate } = options;
303
+ let typeAheadBuffer = "";
304
+ let typeAheadTimeout;
305
+ function getItems() {
306
+ return Array.from(container.querySelectorAll(itemSelector));
307
+ }
308
+ function getActiveIndex() {
309
+ const items = getItems();
310
+ const focused = document.activeElement;
311
+ return items.indexOf(focused);
312
+ }
313
+ function focusItem(index) {
314
+ const items = getItems();
315
+ if (items.length === 0) return;
316
+ const item = items[loop ? (index % items.length + items.length) % items.length : Math.max(0, Math.min(index, items.length - 1))];
317
+ items.forEach((el) => el.setAttribute("tabindex", "-1"));
318
+ item.setAttribute("tabindex", "0");
319
+ item.focus();
320
+ }
321
+ function handleKeyDown(event) {
322
+ const items = getItems();
323
+ if (items.length === 0) return;
324
+ const nextKey = orientation === "vertical" ? "ArrowDown" : "ArrowRight";
325
+ const prevKey = orientation === "vertical" ? "ArrowUp" : "ArrowLeft";
326
+ switch (event.key) {
327
+ case nextKey:
328
+ event.preventDefault();
329
+ focusItem(getActiveIndex() + 1);
330
+ break;
331
+ case prevKey:
332
+ event.preventDefault();
333
+ focusItem(getActiveIndex() - 1);
334
+ break;
335
+ case "Home":
336
+ event.preventDefault();
337
+ focusItem(0);
338
+ break;
339
+ case "End":
340
+ event.preventDefault();
341
+ focusItem(items.length - 1);
342
+ break;
343
+ case "Enter":
344
+ case " ": {
345
+ event.preventDefault();
346
+ const focused = document.activeElement;
347
+ if (items.includes(focused)) {
348
+ focused.click();
349
+ onActivate?.(focused);
350
+ }
351
+ break;
352
+ }
353
+ default:
354
+ if (typeAhead && event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
355
+ event.preventDefault();
356
+ typeAheadBuffer += event.key.toLowerCase();
357
+ if (typeAheadTimeout) clearTimeout(typeAheadTimeout);
358
+ typeAheadTimeout = setTimeout(() => {
359
+ typeAheadBuffer = "";
360
+ }, 350);
361
+ const match = items.find((item) => {
362
+ return (item.textContent || "").trim().toLowerCase().startsWith(typeAheadBuffer);
363
+ });
364
+ if (match) focusItem(items.indexOf(match));
365
+ }
366
+ break;
367
+ }
368
+ }
369
+ container.addEventListener("keydown", handleKeyDown);
370
+ const items = getItems();
371
+ items.forEach((el, i) => el.setAttribute("tabindex", i === 0 ? "0" : "-1"));
372
+ let rafId;
373
+ if (items.length > 0) rafId = requestAnimationFrame(() => {
374
+ rafId = void 0;
375
+ items[0].focus();
376
+ });
377
+ let cleaned = false;
378
+ return function cleanup() {
379
+ if (cleaned) return;
380
+ cleaned = true;
381
+ if (rafId !== void 0) cancelAnimationFrame(rafId);
382
+ if (typeAheadTimeout) clearTimeout(typeAheadTimeout);
383
+ container.removeEventListener("keydown", handleKeyDown);
384
+ };
385
+ }
386
+ //#endregion
387
+ //#region src/position.ts
388
+ var ANCHOR_CLASS_PREFIX = "iui-anchor-";
389
+ var _supportsAnchor = null;
464
390
  function supportsAnchorPositioning() {
465
- if (_supportsAnchor === null) {
466
- _supportsAnchor = typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("anchor-name", "--a");
467
- }
468
- return _supportsAnchor;
391
+ if (_supportsAnchor === null) _supportsAnchor = typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("anchor-name", "--a");
392
+ return _supportsAnchor;
469
393
  }
470
394
  function isRtl$1() {
471
- return typeof document !== "undefined" && document.documentElement.dir === "rtl";
395
+ return typeof document !== "undefined" && document.documentElement.dir === "rtl";
472
396
  }
473
397
  function getOppositePlacement(placement) {
474
- const map = {
475
- top: "bottom",
476
- "top-start": "bottom-start",
477
- "top-end": "bottom-end",
478
- bottom: "top",
479
- "bottom-start": "top-start",
480
- "bottom-end": "top-end",
481
- left: "right",
482
- "left-start": "right-start",
483
- "left-end": "right-end",
484
- right: "left",
485
- "right-start": "left-start",
486
- "right-end": "left-end"
487
- };
488
- return map[placement] || placement;
398
+ return {
399
+ top: "bottom",
400
+ "top-start": "bottom-start",
401
+ "top-end": "bottom-end",
402
+ bottom: "top",
403
+ "bottom-start": "top-start",
404
+ "bottom-end": "top-end",
405
+ left: "right",
406
+ "left-start": "right-start",
407
+ "left-end": "right-end",
408
+ right: "left",
409
+ "right-start": "left-start",
410
+ "right-end": "left-end"
411
+ }[placement] || placement;
489
412
  }
490
413
  function computePositionFromRect(refRect, floatingRect, placement, offset) {
491
- let x = 0;
492
- let y = 0;
493
- const [side, alignment] = placement.split("-");
494
- const rtl = isRtl$1();
495
- switch (side) {
496
- case "bottom":
497
- y = refRect.bottom + offset;
498
- break;
499
- case "top":
500
- y = refRect.top - floatingRect.height - offset;
501
- break;
502
- case "left":
503
- x = refRect.left - floatingRect.width - offset;
504
- break;
505
- case "right":
506
- x = refRect.right + offset;
507
- break;
508
- }
509
- if (side === "bottom" || side === "top") {
510
- const startIsLeft = !rtl;
511
- switch (alignment) {
512
- case "start":
513
- x = startIsLeft ? refRect.left : refRect.right - floatingRect.width;
514
- break;
515
- case "end":
516
- x = startIsLeft ? refRect.right - floatingRect.width : refRect.left;
517
- break;
518
- default:
519
- x = refRect.left + (refRect.width - floatingRect.width) / 2;
520
- break;
521
- }
522
- } else {
523
- switch (alignment) {
524
- case "start":
525
- y = refRect.top;
526
- break;
527
- case "end":
528
- y = refRect.bottom - floatingRect.height;
529
- break;
530
- default:
531
- y = refRect.top + (refRect.height - floatingRect.height) / 2;
532
- break;
533
- }
534
- }
535
- return { x, y };
414
+ let x = 0;
415
+ let y = 0;
416
+ const [side, alignment] = placement.split("-");
417
+ const rtl = isRtl$1();
418
+ switch (side) {
419
+ case "bottom":
420
+ y = refRect.bottom + offset;
421
+ break;
422
+ case "top":
423
+ y = refRect.top - floatingRect.height - offset;
424
+ break;
425
+ case "left":
426
+ x = refRect.left - floatingRect.width - offset;
427
+ break;
428
+ case "right":
429
+ x = refRect.right + offset;
430
+ break;
431
+ }
432
+ if (side === "bottom" || side === "top") {
433
+ const startIsLeft = !rtl;
434
+ switch (alignment) {
435
+ case "start":
436
+ x = startIsLeft ? refRect.left : refRect.right - floatingRect.width;
437
+ break;
438
+ case "end":
439
+ x = startIsLeft ? refRect.right - floatingRect.width : refRect.left;
440
+ break;
441
+ default:
442
+ x = refRect.left + (refRect.width - floatingRect.width) / 2;
443
+ break;
444
+ }
445
+ } else switch (alignment) {
446
+ case "start":
447
+ y = refRect.top;
448
+ break;
449
+ case "end":
450
+ y = refRect.bottom - floatingRect.height;
451
+ break;
452
+ default:
453
+ y = refRect.top + (refRect.height - floatingRect.height) / 2;
454
+ break;
455
+ }
456
+ return {
457
+ x,
458
+ y
459
+ };
536
460
  }
537
461
  function wouldOverflow(x, y, floatingRect, placement) {
538
- const [side] = placement.split("-");
539
- const vw = window.innerWidth;
540
- const vh = window.innerHeight;
541
- switch (side) {
542
- case "bottom":
543
- return y + floatingRect.height > vh;
544
- case "top":
545
- return y < 0;
546
- case "left":
547
- return x < 0;
548
- case "right":
549
- return x + floatingRect.width > vw;
550
- default:
551
- return false;
552
- }
462
+ const [side] = placement.split("-");
463
+ const vw = window.innerWidth;
464
+ const vh = window.innerHeight;
465
+ switch (side) {
466
+ case "bottom": return y + floatingRect.height > vh;
467
+ case "top": return y < 0;
468
+ case "left": return x < 0;
469
+ case "right": return x + floatingRect.width > vw;
470
+ default: return false;
471
+ }
553
472
  }
554
473
  function clampToViewport(x, y, floatingRect) {
555
- const vw = window.innerWidth;
556
- const vh = window.innerHeight;
557
- const margin = 4;
558
- return {
559
- x: Math.max(margin, Math.min(x, vw - floatingRect.width - margin)),
560
- y: Math.max(margin, Math.min(y, vh - floatingRect.height - margin))
561
- };
474
+ const vw = window.innerWidth;
475
+ const vh = window.innerHeight;
476
+ const margin = 4;
477
+ return {
478
+ x: Math.max(margin, Math.min(x, vw - floatingRect.width - margin)),
479
+ y: Math.max(margin, Math.min(y, vh - floatingRect.height - margin))
480
+ };
562
481
  }
563
482
  function computeWithFallback(reference, floating, options = {}) {
564
- const { placement = "bottom-start", offset = 0, flip = true } = options;
565
- const refRect = reference.getBoundingClientRect();
566
- const floatingRect = floating.getBoundingClientRect();
567
- let { x, y } = computePositionFromRect(refRect, floatingRect, placement, offset);
568
- let actualPlacement = placement;
569
- if (flip && wouldOverflow(x, y, floatingRect, placement)) {
570
- const flipped = getOppositePlacement(placement);
571
- const flippedPos = computePositionFromRect(refRect, floatingRect, flipped, offset);
572
- if (!wouldOverflow(flippedPos.x, flippedPos.y, floatingRect, flipped)) {
573
- x = flippedPos.x;
574
- y = flippedPos.y;
575
- actualPlacement = flipped;
576
- }
577
- }
578
- const clamped = clampToViewport(x, y, floatingRect);
579
- return { x: clamped.x, y: clamped.y, placement: actualPlacement };
580
- }
581
- const anchorStyleId = "inertiaui-anchor-styles";
483
+ const { placement = "bottom-start", offset = 0, flip = true } = options;
484
+ const refRect = reference.getBoundingClientRect();
485
+ const floatingRect = floating.getBoundingClientRect();
486
+ let { x, y } = computePositionFromRect(refRect, floatingRect, placement, offset);
487
+ let actualPlacement = placement;
488
+ if (flip && wouldOverflow(x, y, floatingRect, placement)) {
489
+ const flipped = getOppositePlacement(placement);
490
+ const flippedPos = computePositionFromRect(refRect, floatingRect, flipped, offset);
491
+ if (!wouldOverflow(flippedPos.x, flippedPos.y, floatingRect, flipped)) {
492
+ x = flippedPos.x;
493
+ y = flippedPos.y;
494
+ actualPlacement = flipped;
495
+ }
496
+ }
497
+ const clamped = clampToViewport(x, y, floatingRect);
498
+ return {
499
+ x: clamped.x,
500
+ y: clamped.y,
501
+ placement: actualPlacement
502
+ };
503
+ }
504
+ var anchorStyleId = "inertiaui-anchor-styles";
582
505
  function ensureAnchorStylesheet() {
583
- let style = document.getElementById(anchorStyleId);
584
- if (!style) {
585
- style = document.createElement("style");
586
- style.id = anchorStyleId;
587
- document.head.appendChild(style);
588
- }
589
- return style.sheet;
506
+ let style = document.getElementById(anchorStyleId);
507
+ if (!style) {
508
+ style = document.createElement("style");
509
+ style.id = anchorStyleId;
510
+ document.head.appendChild(style);
511
+ }
512
+ return style.sheet;
590
513
  }
591
514
  function findAnchorClass(element) {
592
- return Array.from(element.classList).find((c) => c.startsWith(ANCHOR_CLASS_PREFIX));
515
+ return Array.from(element.classList).find((c) => c.startsWith(ANCHOR_CLASS_PREFIX));
593
516
  }
594
517
  function setupAnchorPositioning(reference, floating, placement, offset, flip) {
595
- const id = generateId(ANCHOR_CLASS_PREFIX);
596
- const anchorName = `--${id}`;
597
- reference.style.anchorName = anchorName;
598
- floating.style.positionAnchor = anchorName;
599
- floating.style.position = "fixed";
600
- const [side, alignment] = placement.split("-");
601
- const sheet = ensureAnchorStylesheet();
602
- const className = id;
603
- let positionRules = "";
604
- let tryFallback = "";
605
- switch (side) {
606
- case "bottom":
607
- positionRules += `top: anchor(bottom);`;
608
- positionRules += `margin-top: ${offset}px;`;
609
- break;
610
- case "top":
611
- positionRules += `bottom: anchor(top);`;
612
- positionRules += `margin-bottom: ${offset}px;`;
613
- break;
614
- case "left":
615
- positionRules += `right: anchor(left);`;
616
- positionRules += `margin-right: ${offset}px;`;
617
- break;
618
- case "right":
619
- positionRules += `left: anchor(right);`;
620
- positionRules += `margin-left: ${offset}px;`;
621
- break;
622
- }
623
- if (side === "bottom" || side === "top") {
624
- switch (alignment) {
625
- case "start":
626
- positionRules += `left: anchor(left);`;
627
- break;
628
- case "end":
629
- positionRules += `right: anchor(right);`;
630
- break;
631
- default:
632
- positionRules += `left: anchor(center); translate: -50% 0;`;
633
- break;
634
- }
635
- } else {
636
- switch (alignment) {
637
- case "start":
638
- positionRules += `top: anchor(top);`;
639
- break;
640
- case "end":
641
- positionRules += `bottom: anchor(bottom);`;
642
- break;
643
- default:
644
- positionRules += `top: anchor(center); translate: 0 -50%;`;
645
- break;
646
- }
647
- }
648
- if (flip) {
649
- tryFallback = `position-try-fallbacks: flip-block, flip-inline;`;
650
- }
651
- const rule = `.${className} { ${positionRules} ${tryFallback} }`;
652
- sheet.insertRule(rule, sheet.cssRules.length);
653
- floating.classList.add(className);
654
- return className;
518
+ const id = generateId(ANCHOR_CLASS_PREFIX);
519
+ const anchorName = `--${id}`;
520
+ reference.style.anchorName = anchorName;
521
+ floating.style.positionAnchor = anchorName;
522
+ floating.style.position = "fixed";
523
+ const [side, alignment] = placement.split("-");
524
+ const sheet = ensureAnchorStylesheet();
525
+ const className = id;
526
+ let positionRules = "";
527
+ let tryFallback = "";
528
+ switch (side) {
529
+ case "bottom":
530
+ positionRules += `top: anchor(bottom);`;
531
+ positionRules += `margin-top: ${offset}px;`;
532
+ break;
533
+ case "top":
534
+ positionRules += `bottom: anchor(top);`;
535
+ positionRules += `margin-bottom: ${offset}px;`;
536
+ break;
537
+ case "left":
538
+ positionRules += `right: anchor(left);`;
539
+ positionRules += `margin-right: ${offset}px;`;
540
+ break;
541
+ case "right":
542
+ positionRules += `left: anchor(right);`;
543
+ positionRules += `margin-left: ${offset}px;`;
544
+ break;
545
+ }
546
+ if (side === "bottom" || side === "top") switch (alignment) {
547
+ case "start":
548
+ positionRules += `left: anchor(left);`;
549
+ break;
550
+ case "end":
551
+ positionRules += `right: anchor(right);`;
552
+ break;
553
+ default:
554
+ positionRules += `left: anchor(center); translate: -50% 0;`;
555
+ break;
556
+ }
557
+ else switch (alignment) {
558
+ case "start":
559
+ positionRules += `top: anchor(top);`;
560
+ break;
561
+ case "end":
562
+ positionRules += `bottom: anchor(bottom);`;
563
+ break;
564
+ default:
565
+ positionRules += `top: anchor(center); translate: 0 -50%;`;
566
+ break;
567
+ }
568
+ if (flip) tryFallback = `position-try-fallbacks: flip-block, flip-inline;`;
569
+ const rule = `.${className} { ${positionRules} ${tryFallback} }`;
570
+ sheet.insertRule(rule, sheet.cssRules.length);
571
+ floating.classList.add(className);
572
+ return className;
655
573
  }
656
574
  function cleanupAnchorPositioning(reference, floating, className) {
657
- reference.style.anchorName = "";
658
- floating.style.positionAnchor = "";
659
- floating.style.position = "";
660
- floating.classList.remove(className);
661
- const style = document.getElementById(anchorStyleId);
662
- if (style == null ? void 0 : style.sheet) {
663
- for (let i = 0; i < style.sheet.cssRules.length; i++) {
664
- const rule = style.sheet.cssRules[i];
665
- if (rule.selectorText === `.${className}`) {
666
- style.sheet.deleteRule(i);
667
- break;
668
- }
669
- }
670
- }
575
+ reference.style.anchorName = "";
576
+ floating.style.positionAnchor = "";
577
+ floating.style.position = "";
578
+ floating.classList.remove(className);
579
+ const style = document.getElementById(anchorStyleId);
580
+ if (style?.sheet) {
581
+ for (let i = 0; i < style.sheet.cssRules.length; i++) if (style.sheet.cssRules[i].selectorText === `.${className}`) {
582
+ style.sheet.deleteRule(i);
583
+ break;
584
+ }
585
+ }
671
586
  }
672
587
  function computePosition(reference, floating, options = {}) {
673
- const { placement = "bottom-start", offset = 0, flip = true } = options;
674
- if (supportsAnchorPositioning()) {
675
- const existingClass = findAnchorClass(floating);
676
- if (!existingClass) {
677
- setupAnchorPositioning(reference, floating, placement, offset, flip);
678
- }
679
- const rect = floating.getBoundingClientRect();
680
- return { x: rect.left, y: rect.top, placement };
681
- }
682
- const result = computeWithFallback(reference, floating, { placement, offset, flip });
683
- floating.style.position = "fixed";
684
- floating.style.top = `${result.y}px`;
685
- floating.style.left = `${result.x}px`;
686
- return result;
588
+ const { placement = "bottom-start", offset = 0, flip = true } = options;
589
+ if (supportsAnchorPositioning()) {
590
+ if (!findAnchorClass(floating)) setupAnchorPositioning(reference, floating, placement, offset, flip);
591
+ const rect = floating.getBoundingClientRect();
592
+ return {
593
+ x: rect.left,
594
+ y: rect.top,
595
+ placement
596
+ };
597
+ }
598
+ const result = computeWithFallback(reference, floating, {
599
+ placement,
600
+ offset,
601
+ flip
602
+ });
603
+ floating.style.position = "fixed";
604
+ floating.style.top = `${result.y}px`;
605
+ floating.style.left = `${result.x}px`;
606
+ return result;
687
607
  }
688
608
  function autoUpdate(reference, floating, update) {
689
- let rafId;
690
- function scheduleUpdate() {
691
- if (rafId !== void 0) {
692
- return;
693
- }
694
- rafId = requestAnimationFrame(() => {
695
- rafId = void 0;
696
- update();
697
- });
698
- }
699
- window.addEventListener("resize", scheduleUpdate);
700
- window.addEventListener("scroll", scheduleUpdate, true);
701
- const resizeObserver = new ResizeObserver(scheduleUpdate);
702
- resizeObserver.observe(reference);
703
- resizeObserver.observe(floating);
704
- let cleaned = false;
705
- return function cleanup() {
706
- if (cleaned) {
707
- return;
708
- }
709
- cleaned = true;
710
- if (rafId !== void 0) {
711
- cancelAnimationFrame(rafId);
712
- }
713
- window.removeEventListener("resize", scheduleUpdate);
714
- window.removeEventListener("scroll", scheduleUpdate, true);
715
- resizeObserver.disconnect();
716
- const anchorClass = findAnchorClass(floating);
717
- if (anchorClass) {
718
- cleanupAnchorPositioning(reference, floating, anchorClass);
719
- }
720
- };
721
- }
609
+ let rafId;
610
+ function scheduleUpdate() {
611
+ if (rafId !== void 0) return;
612
+ rafId = requestAnimationFrame(() => {
613
+ rafId = void 0;
614
+ update();
615
+ });
616
+ }
617
+ window.addEventListener("resize", scheduleUpdate);
618
+ window.addEventListener("scroll", scheduleUpdate, true);
619
+ const resizeObserver = new ResizeObserver(scheduleUpdate);
620
+ resizeObserver.observe(reference);
621
+ resizeObserver.observe(floating);
622
+ let cleaned = false;
623
+ return function cleanup() {
624
+ if (cleaned) return;
625
+ cleaned = true;
626
+ if (rafId !== void 0) cancelAnimationFrame(rafId);
627
+ window.removeEventListener("resize", scheduleUpdate);
628
+ window.removeEventListener("scroll", scheduleUpdate, true);
629
+ resizeObserver.disconnect();
630
+ const anchorClass = findAnchorClass(floating);
631
+ if (anchorClass) cleanupAnchorPositioning(reference, floating, anchorClass);
632
+ };
633
+ }
634
+ //#endregion
635
+ //#region src/blank.ts
636
+ /**
637
+ * Port of Laravel's `blank` function.
638
+ * Returns true if the value is "empty" — null, undefined, empty string, empty array/object, etc.
639
+ */
722
640
  function blank(value) {
723
- if (value === null || value === void 0) {
724
- return true;
725
- }
726
- if (typeof value === "string") {
727
- return value.trim() === "";
728
- }
729
- if (typeof value === "number" || typeof value === "boolean") {
730
- return false;
731
- }
732
- if (Array.isArray(value) || typeof value === "object" && value !== null && typeof value.length === "number") {
733
- return value.length === 0;
734
- }
735
- return !value;
736
- }
641
+ if (value === null || value === void 0) return true;
642
+ if (typeof value === "string") return value.trim() === "";
643
+ if (typeof value === "number" || typeof value === "boolean") return false;
644
+ if (Array.isArray(value) || typeof value === "object" && value !== null && typeof value.length === "number") return value.length === 0;
645
+ return !value;
646
+ }
647
+ //#endregion
648
+ //#region src/debounce.ts
649
+ /**
650
+ * Debounce a function using requestAnimationFrame.
651
+ * Ensures the function runs at most once per animation frame.
652
+ *
653
+ * @see https://pqina.nl/blog/applying-styles-based-on-the-user-scroll-position-with-smart-css/
654
+ */
737
655
  function debounce(fn) {
738
- let frame;
739
- return (...params) => {
740
- if (frame) {
741
- cancelAnimationFrame(frame);
742
- }
743
- frame = requestAnimationFrame(() => {
744
- fn(...params);
745
- });
746
- };
747
- }
656
+ let frame;
657
+ return (...params) => {
658
+ if (frame) cancelAnimationFrame(frame);
659
+ frame = requestAnimationFrame(() => {
660
+ fn(...params);
661
+ });
662
+ };
663
+ }
664
+ /**
665
+ * Detect the browser's current framerate.
666
+ * Returns a Promise that resolves with the detected FPS (capped to 30–240 range).
667
+ * Falls back to 60 if requestAnimationFrame is unavailable or detection times out.
668
+ */
748
669
  function detectFramerate() {
749
- return new Promise((resolve) => {
750
- if (typeof window === "undefined" || !window.requestAnimationFrame) {
751
- return resolve(60);
752
- }
753
- const timestamps = [];
754
- let rafId;
755
- function measure(now) {
756
- timestamps.unshift(now);
757
- if (timestamps.length > 10) {
758
- const lastTime = timestamps.pop();
759
- const fps = Math.floor(1e3 * 10 / (now - lastTime));
760
- cancelAnimationFrame(rafId);
761
- resolve(Math.min(Math.max(fps, 30), 240));
762
- return;
763
- }
764
- rafId = window.requestAnimationFrame(measure);
765
- }
766
- rafId = window.requestAnimationFrame(measure);
767
- setTimeout(() => {
768
- if (rafId !== void 0) {
769
- cancelAnimationFrame(rafId);
770
- }
771
- resolve(60);
772
- }, 1e3);
773
- });
774
- }
670
+ return new Promise((resolve) => {
671
+ if (typeof window === "undefined" || !window.requestAnimationFrame) return resolve(60);
672
+ const timestamps = [];
673
+ let rafId;
674
+ function measure(now) {
675
+ timestamps.unshift(now);
676
+ if (timestamps.length > 10) {
677
+ const lastTime = timestamps.pop();
678
+ const fps = Math.floor(1e3 * 10 / (now - lastTime));
679
+ cancelAnimationFrame(rafId);
680
+ resolve(Math.min(Math.max(fps, 30), 240));
681
+ return;
682
+ }
683
+ rafId = window.requestAnimationFrame(measure);
684
+ }
685
+ rafId = window.requestAnimationFrame(measure);
686
+ setTimeout(() => {
687
+ if (rafId !== void 0) cancelAnimationFrame(rafId);
688
+ resolve(60);
689
+ }, 1e3);
690
+ });
691
+ }
692
+ //#endregion
693
+ //#region src/darkMode.ts
694
+ /**
695
+ * Detect whether the user prefers dark mode.
696
+ *
697
+ * Strategies:
698
+ * - `'class'` / `'selector'` — checks `<html class="dark">`
699
+ * - `'media'` — checks `prefers-color-scheme: dark` media query
700
+ * - `'auto'` (default) — checks class first, then media query
701
+ * - custom function — called directly for full control
702
+ */
775
703
  function prefersDarkMode(strategy = "auto") {
776
- if (typeof strategy === "function") {
777
- return strategy();
778
- }
779
- const containsDarkClass = () => document.documentElement.classList.contains("dark");
780
- const matchesDarkMediaQuery = () => window.matchMedia("(prefers-color-scheme: dark)").matches;
781
- if (strategy === "class" || strategy === "selector") {
782
- return containsDarkClass();
783
- }
784
- if (strategy === "media") {
785
- return matchesDarkMediaQuery();
786
- }
787
- return containsDarkClass() || matchesDarkMediaQuery();
788
- }
704
+ if (typeof strategy === "function") return strategy();
705
+ const containsDarkClass = () => document.documentElement.classList.contains("dark");
706
+ const matchesDarkMediaQuery = () => window.matchMedia("(prefers-color-scheme: dark)").matches;
707
+ if (strategy === "class" || strategy === "selector") return containsDarkClass();
708
+ if (strategy === "media") return matchesDarkMediaQuery();
709
+ return containsDarkClass() || matchesDarkMediaQuery();
710
+ }
711
+ //#endregion
712
+ //#region src/rtl.ts
713
+ /**
714
+ * Check whether the document is currently in RTL direction.
715
+ */
789
716
  function isRtl() {
790
- return document.documentElement.dir === "rtl";
717
+ return document.documentElement.dir === "rtl";
791
718
  }
719
+ /**
720
+ * Observe changes to the document's `dir` attribute and invoke the callback
721
+ * whenever it changes. Returns a cleanup function to stop observing.
722
+ */
792
723
  function onRtlChange(callback) {
793
- const observer = new MutationObserver(() => {
794
- callback(document.documentElement.dir === "rtl");
795
- });
796
- observer.observe(document.documentElement, {
797
- attributes: true,
798
- attributeFilter: ["dir"]
799
- });
800
- return () => observer.disconnect();
801
- }
724
+ const observer = new MutationObserver(() => {
725
+ callback(document.documentElement.dir === "rtl");
726
+ });
727
+ observer.observe(document.documentElement, {
728
+ attributes: true,
729
+ attributeFilter: ["dir"]
730
+ });
731
+ return () => observer.disconnect();
732
+ }
733
+ //#endregion
734
+ //#region src/color.ts
735
+ /**
736
+ * Convert a hex color string to HSL values.
737
+ * Accepts with or without leading '#'.
738
+ */
802
739
  function hexToHsl(hex) {
803
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
804
- if (!result) return { h: 0, s: 100, l: 50 };
805
- let r = parseInt(result[1], 16) / 255;
806
- let g = parseInt(result[2], 16) / 255;
807
- let b = parseInt(result[3], 16) / 255;
808
- const max = Math.max(r, g, b);
809
- const min = Math.min(r, g, b);
810
- let h = 0;
811
- let s = 0;
812
- const l = (max + min) / 2;
813
- if (max !== min) {
814
- const d = max - min;
815
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
816
- switch (max) {
817
- case r:
818
- h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
819
- break;
820
- case g:
821
- h = ((b - r) / d + 2) / 6;
822
- break;
823
- case b:
824
- h = ((r - g) / d + 4) / 6;
825
- break;
826
- }
827
- }
828
- return { h: Math.round(h * 360), s: Math.round(s * 100), l: Math.round(l * 100) };
829
- }
740
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
741
+ if (!result) return {
742
+ h: 0,
743
+ s: 100,
744
+ l: 50
745
+ };
746
+ let r = parseInt(result[1], 16) / 255;
747
+ let g = parseInt(result[2], 16) / 255;
748
+ let b = parseInt(result[3], 16) / 255;
749
+ const max = Math.max(r, g, b);
750
+ const min = Math.min(r, g, b);
751
+ let h = 0;
752
+ let s = 0;
753
+ const l = (max + min) / 2;
754
+ if (max !== min) {
755
+ const d = max - min;
756
+ s = l > .5 ? d / (2 - max - min) : d / (max + min);
757
+ switch (max) {
758
+ case r:
759
+ h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
760
+ break;
761
+ case g:
762
+ h = ((b - r) / d + 2) / 6;
763
+ break;
764
+ case b:
765
+ h = ((r - g) / d + 4) / 6;
766
+ break;
767
+ }
768
+ }
769
+ return {
770
+ h: Math.round(h * 360),
771
+ s: Math.round(s * 100),
772
+ l: Math.round(l * 100)
773
+ };
774
+ }
775
+ /**
776
+ * Convert HSL values to a hex color string.
777
+ * h: 0-360, s: 0-100, l: 0-100
778
+ * Returns string with leading '#'.
779
+ */
830
780
  function hslToHex(h, s, l) {
831
- s /= 100;
832
- l /= 100;
833
- const c = (1 - Math.abs(2 * l - 1)) * s;
834
- const x = c * (1 - Math.abs(h / 60 % 2 - 1));
835
- const m = l - c / 2;
836
- let r = 0, g = 0, b = 0;
837
- if (0 <= h && h < 60) {
838
- r = c;
839
- g = x;
840
- b = 0;
841
- } else if (60 <= h && h < 120) {
842
- r = x;
843
- g = c;
844
- b = 0;
845
- } else if (120 <= h && h < 180) {
846
- r = 0;
847
- g = c;
848
- b = x;
849
- } else if (180 <= h && h < 240) {
850
- r = 0;
851
- g = x;
852
- b = c;
853
- } else if (240 <= h && h < 300) {
854
- r = x;
855
- g = 0;
856
- b = c;
857
- } else if (300 <= h && h < 360) {
858
- r = c;
859
- g = 0;
860
- b = x;
861
- }
862
- const toHex = (n) => {
863
- const hex = Math.round((n + m) * 255).toString(16);
864
- return hex.length === 1 ? "0" + hex : hex;
865
- };
866
- return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
867
- }
868
- export {
869
- animate,
870
- autoUpdate,
871
- blank,
872
- cancelAnimations,
873
- computePosition,
874
- createFocusTrap,
875
- createMenuNavigation,
876
- debounce,
877
- detectFramerate,
878
- easings,
879
- except,
880
- generateId,
881
- hexToHsl,
882
- hslToHex,
883
- isRtl,
884
- isStandardDomEvent,
885
- kebabCase,
886
- lockScroll,
887
- markAriaHidden,
888
- onClickOutside,
889
- onEscapeKey,
890
- onRtlChange,
891
- onceChildrenRendered,
892
- only,
893
- prefersDarkMode,
894
- rejectNullValues,
895
- sameUrlPath,
896
- supportsAnchorPositioning
897
- };
781
+ s /= 100;
782
+ l /= 100;
783
+ const c = (1 - Math.abs(2 * l - 1)) * s;
784
+ const x = c * (1 - Math.abs(h / 60 % 2 - 1));
785
+ const m = l - c / 2;
786
+ let r = 0, g = 0, b = 0;
787
+ if (0 <= h && h < 60) {
788
+ r = c;
789
+ g = x;
790
+ b = 0;
791
+ } else if (60 <= h && h < 120) {
792
+ r = x;
793
+ g = c;
794
+ b = 0;
795
+ } else if (120 <= h && h < 180) {
796
+ r = 0;
797
+ g = c;
798
+ b = x;
799
+ } else if (180 <= h && h < 240) {
800
+ r = 0;
801
+ g = x;
802
+ b = c;
803
+ } else if (240 <= h && h < 300) {
804
+ r = x;
805
+ g = 0;
806
+ b = c;
807
+ } else if (300 <= h && h < 360) {
808
+ r = c;
809
+ g = 0;
810
+ b = x;
811
+ }
812
+ const toHex = (n) => {
813
+ const hex = Math.round((n + m) * 255).toString(16);
814
+ return hex.length === 1 ? "0" + hex : hex;
815
+ };
816
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
817
+ }
818
+ //#endregion
819
+ export { animate, autoUpdate, blank, cancelAnimations, computePosition, createFocusTrap, createMenuNavigation, debounce, detectFramerate, easings, except, generateId, hexToHsl, hslToHex, isRtl, isStandardDomEvent, kebabCase, lockScroll, markAriaHidden, onClickOutside, onEscapeKey, onRtlChange, onceChildrenRendered, only, prefersDarkMode, rejectNullValues, sameUrlPath, supportsAnchorPositioning };