@rcarls/rc-common 0.0.0-next-20260921045401

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.
@@ -0,0 +1,1760 @@
1
+ import { nothing as E } from "lit";
2
+ import { PartType as L } from "lit/directive.js";
3
+ import { directive as C, AsyncDirective as A } from "lit/async-directive.js";
4
+ import { state as M } from "lit/decorators.js";
5
+ let $ = 0;
6
+ class et {
7
+ constructor(t, e) {
8
+ this._activeItem = null, this._activeIndex = -1, this._itemCounter = 0, this._opts = e, this._instanceId = `rc-adc-${++$}`, t.addController(this);
9
+ }
10
+ hostConnected() {
11
+ }
12
+ hostDisconnected() {
13
+ this.clear();
14
+ }
15
+ /** The currently active item, or `null` when cleared. */
16
+ get activeItem() {
17
+ return this._activeItem;
18
+ }
19
+ /** Index into the current `items()` array. `-1` when cleared. */
20
+ get activeIndex() {
21
+ return this._activeIndex;
22
+ }
23
+ /**
24
+ * Move the virtual cursor by `delta` steps (+1 forward, -1 backward),
25
+ * skipping any items for which `isSkipped` returns true.
26
+ */
27
+ navigate(t) {
28
+ const e = this._opts.items();
29
+ if (e.length === 0) return;
30
+ const i = this._opts.wrap ?? !0;
31
+ let s = this._activeIndex < 0 ? t > 0 ? -1 : e.length : this._activeIndex;
32
+ const n = e.length;
33
+ let r = 0;
34
+ do
35
+ if (s += t, i ? s = (s % n + n) % n : s = Math.max(0, Math.min(n - 1, s)), r++, !this._isSkipped(e[s])) break;
36
+ while (r < n);
37
+ this._setActive(e[s] ?? null, s);
38
+ }
39
+ /** Move the virtual cursor to the first non-skipped item. */
40
+ navigateToFirst() {
41
+ const t = this._opts.items(), e = t.findIndex((i) => !this._isSkipped(i));
42
+ e >= 0 && this._setActive(t[e], e);
43
+ }
44
+ /** Move the virtual cursor to the last non-skipped item. */
45
+ navigateToLast() {
46
+ const t = this._opts.items();
47
+ let e = -1;
48
+ for (let i = t.length - 1; i >= 0; i--)
49
+ if (!this._isSkipped(t[i])) {
50
+ e = i;
51
+ break;
52
+ }
53
+ e >= 0 && this._setActive(t[e], e);
54
+ }
55
+ /** Move the virtual cursor to the item at `index`. */
56
+ navigateTo(t) {
57
+ const i = this._opts.items()[t];
58
+ i && !this._isSkipped(i) && this._setActive(i, t);
59
+ }
60
+ /** Move the virtual cursor to a specific item reference. */
61
+ navigateToItem(t) {
62
+ const i = this._opts.items().indexOf(t);
63
+ i >= 0 && !this._isSkipped(t) && this._setActive(t, i);
64
+ }
65
+ /**
66
+ * Clear the virtual cursor: removes `aria-activedescendant` from the host,
67
+ * removes `data-active` from the previously active item, and resets internal state.
68
+ */
69
+ clear() {
70
+ this._activeItem?.removeAttribute("data-active"), this._activeItem = null, this._activeIndex = -1;
71
+ const t = this._opts.host();
72
+ t && t.removeAttribute("aria-activedescendant");
73
+ }
74
+ _isSkipped(t) {
75
+ return !t || t.hidden || t.getAttribute("aria-disabled") === "true" ? !0 : this._opts.isSkipped?.(t) ?? !1;
76
+ }
77
+ _setActive(t, e) {
78
+ this._activeItem?.removeAttribute("data-active"), this._activeItem = t, this._activeIndex = e;
79
+ const i = this._opts.host();
80
+ if (i) {
81
+ if (!t) {
82
+ i.removeAttribute("aria-activedescendant");
83
+ return;
84
+ }
85
+ t.id || (t.id = `${this._instanceId}-${++this._itemCounter}`), i.setAttribute("aria-activedescendant", t.id), t.setAttribute("data-active", ""), t.scrollIntoView({ block: "nearest" });
86
+ }
87
+ }
88
+ }
89
+ const z = 'a[href], button, input, select, textarea, summary, [role="button"], [role="link"], [contenteditable]:not([contenteditable="false"]), [tabindex]:not([tabindex="-1"])';
90
+ function O(o, t, e = {}) {
91
+ const i = e.interactiveSelector ?? z;
92
+ for (const s of o.composedPath()) {
93
+ if (s === t)
94
+ return !1;
95
+ if (s instanceof Element && s.matches(i))
96
+ return !0;
97
+ }
98
+ return !1;
99
+ }
100
+ function F(o, t, e, i = {}) {
101
+ return !e || i.disabled || o.defaultPrevented || o.button !== 0 || o.altKey || o.ctrlKey || o.metaKey || o.shiftKey || O(o, t, i) ? !1 : (o.preventDefault(), e.click(), !0);
102
+ }
103
+ class it {
104
+ constructor(t, e) {
105
+ this._handleClick = (i) => {
106
+ F(i, this._host, this._options.target(), {
107
+ interactiveSelector: this._options.interactiveSelector,
108
+ disabled: this._options.disabled?.()
109
+ });
110
+ }, this._host = t, this._options = e, t.addController(this);
111
+ }
112
+ hostConnected() {
113
+ this._host.addEventListener("click", this._handleClick);
114
+ }
115
+ hostDisconnected() {
116
+ this._host.removeEventListener("click", this._handleClick);
117
+ }
118
+ }
119
+ const w = class w {
120
+ constructor(t, e) {
121
+ this._ul = null, this._options = [], this._liElements = [], this._createLi = null, this._createOption = null, this._selectedValues = /* @__PURE__ */ new Set(), this._filterText = "", this._filterStrategy = "contains", this._checkmark = !1, this._optionsInitialized = !1, this._pendingTouchActivation = null, this._onPointerDown = (i) => {
122
+ const s = i, n = this._resolveOptionLi(s.target);
123
+ if (n) {
124
+ if (s.pointerType === "touch") {
125
+ if (this._pendingTouchActivation) return;
126
+ this._pendingTouchActivation = {
127
+ pointerId: s.pointerId,
128
+ li: n,
129
+ startX: s.clientX,
130
+ startY: s.clientY
131
+ };
132
+ return;
133
+ }
134
+ this._activateLi(n, s);
135
+ }
136
+ }, this._onPointerMove = (i) => {
137
+ const s = this._pendingTouchActivation, n = i;
138
+ if (!s || n.pointerId !== s.pointerId) return;
139
+ Math.hypot(
140
+ n.clientX - s.startX,
141
+ n.clientY - s.startY
142
+ ) > w._TOUCH_TAP_THRESHOLD && (this._pendingTouchActivation = null);
143
+ }, this._onPointerUp = (i) => {
144
+ const s = this._pendingTouchActivation, n = i;
145
+ !s || n.pointerId !== s.pointerId || (this._pendingTouchActivation = null, this._activateLi(s.li, n));
146
+ }, this._onPointerCancel = (i) => {
147
+ const s = i;
148
+ this._pendingTouchActivation?.pointerId === s.pointerId && (this._pendingTouchActivation = null);
149
+ }, this._host = t, this._idPrefix = e.idPrefix, this._onInitFromDom = e.onInitFromDom, this._onActivate = e.onActivate, t.addController(this);
150
+ }
151
+ hostConnected() {
152
+ this._host.addEventListener("pointerdown", this._onPointerDown), this._host.addEventListener("pointermove", this._onPointerMove), this._host.addEventListener("pointerup", this._onPointerUp), this._host.addEventListener("pointercancel", this._onPointerCancel), this._optionsInitialized || this._bootstrapFromDom();
153
+ }
154
+ hostDisconnected() {
155
+ this._host.removeEventListener("pointerdown", this._onPointerDown), this._host.removeEventListener("pointermove", this._onPointerMove), this._host.removeEventListener("pointerup", this._onPointerUp), this._host.removeEventListener("pointercancel", this._onPointerCancel), this._pendingTouchActivation = null;
156
+ }
157
+ // -- Accessors --
158
+ get allOptions() {
159
+ return this._options;
160
+ }
161
+ get selectedValues() {
162
+ return [...this._selectedValues];
163
+ }
164
+ get filterText() {
165
+ return this._filterText;
166
+ }
167
+ isSelected(t) {
168
+ return this._selectedValues.has(t);
169
+ }
170
+ optionForElement(t) {
171
+ if (t === this._createLi)
172
+ return this._createOption;
173
+ const e = this._liElements.indexOf(t);
174
+ return e === -1 ? null : this._options[e] ?? null;
175
+ }
176
+ /**
177
+ * Navigable option elements: visible (not `[hidden]`) and not `aria-disabled`.
178
+ * Includes the create option when set. Consumed by `ActiveDescendantController`.
179
+ */
180
+ get navigableItems() {
181
+ const t = [];
182
+ for (let e = 0; e < this._liElements.length; e++) {
183
+ const i = this._liElements[e];
184
+ this._options[e]?.disabled || i.hidden || t.push(i);
185
+ }
186
+ return this._createLi !== null && t.push(this._createLi), t;
187
+ }
188
+ set checkmark(t) {
189
+ this._checkmark !== t && (this._checkmark = t, this._syncCheckmarks());
190
+ }
191
+ // -- Mutation methods --
192
+ /** Replace the full option list. Sets the controller as authoritative, preventing DOM bootstrap. */
193
+ setOptions(t) {
194
+ this._optionsInitialized = !0, this._options = [...t], this._ensureContainer(), this._syncOptionsToDom();
195
+ }
196
+ /** Append a single option without replacing the list. */
197
+ appendOption(t) {
198
+ this._optionsInitialized = !0, this._options = [...this._options, t], this._ensureContainer();
199
+ const e = this._createLiElement(t, this._options.length - 1);
200
+ this._liElements.push(e), this._createLi ? this._ul.insertBefore(e, this._createLi) : this._ul.appendChild(e), this._applyFilterToLi(e, t);
201
+ }
202
+ /** Update `aria-selected` on all option elements to match `values`. */
203
+ setSelectedValues(t) {
204
+ const e = new Set(
205
+ this._options.filter((i) => i.kind === "action").map((i) => i.value)
206
+ );
207
+ this._createOption && e.add(this._createOption.value), this._selectedValues = new Set(t.filter((i) => !e.has(i))), this._syncSelectedToDom();
208
+ }
209
+ /**
210
+ * Apply a filter — sets `[hidden]` on non-matching `<li>` elements.
211
+ * The strategy is stored and re-used when options change.
212
+ */
213
+ filterOptions(t, e = "contains") {
214
+ this._filterText = t, this._filterStrategy = e, this._syncFilterToDom();
215
+ }
216
+ /** Remove `[hidden]` from all option elements. */
217
+ clearFilter() {
218
+ this._filterText = "", this._syncFilterToDom();
219
+ }
220
+ /**
221
+ * Show or hide the synthetic "Create" option at the end of the list.
222
+ * Pass `null` to remove it.
223
+ */
224
+ setCreateOption(t) {
225
+ if (t === null) {
226
+ this._createLi?.remove(), this._createLi = null, this._createOption = null;
227
+ return;
228
+ }
229
+ const e = t.trim();
230
+ if (this._createOption = {
231
+ kind: "action",
232
+ action: "create",
233
+ value: `create:${e}`,
234
+ label: `Create "${e}"`,
235
+ data: { text: e }
236
+ }, !this._createLi) {
237
+ this._ensureContainer();
238
+ const i = document.createElement("li");
239
+ i.setAttribute("id", `${this._idPrefix}-create`), i.setAttribute("role", "option"), i.setAttribute("aria-selected", "false"), i.setAttribute("part", "option create-option"), this._checkmark && this._ensureCheckmark(i), this._ul.appendChild(i), this._createLi = i;
240
+ }
241
+ this._createLi.setAttribute("data-value", this._createOption.value), this._createLi.setAttribute("data-kind", "action"), this._createLi.setAttribute("data-action", this._createOption.action), this._setLabelText(this._createLi, this._createOption.label);
242
+ }
243
+ // -- Private: DOM management --
244
+ _ensureContainer() {
245
+ if (this._ul) return this._ul;
246
+ let t = this._host.querySelector(":scope > ul");
247
+ return t || (t = document.createElement("ul"), this._host.appendChild(t)), t.setAttribute("role", "presentation"), t.setAttribute("aria-hidden", "true"), this._ul = t, t;
248
+ }
249
+ _bootstrapFromDom() {
250
+ const t = this._host.querySelector(":scope > ul");
251
+ if (!t) return;
252
+ this._ul = t, t.setAttribute("role", "presentation"), t.setAttribute("aria-hidden", "true");
253
+ const e = Array.from(t.querySelectorAll(":scope > li"));
254
+ if (e.length === 0) return;
255
+ const i = [];
256
+ for (let s = 0; s < e.length; s++) {
257
+ const n = e[s], r = n.getAttribute("data-value") ?? n.getAttribute("value") ?? n.textContent?.trim() ?? "", a = n.textContent?.trim() ?? "", h = n.hasAttribute("disabled") || n.getAttribute("aria-disabled") === "true";
258
+ i.push({ value: r, label: a, disabled: h }), n.setAttribute("role", "option"), n.setAttribute("id", `${this._idPrefix}-${s}`), n.setAttribute("part", "option"), n.setAttribute("data-value", r), n.setAttribute("aria-selected", this._selectedValues.has(r) ? "true" : "false"), n.setAttribute("aria-disabled", h ? "true" : "false"), this._checkmark && this._ensureCheckmark(n);
259
+ }
260
+ this._options = i, this._liElements = e, this._onInitFromDom?.(i);
261
+ }
262
+ _syncOptionsToDom() {
263
+ const t = this._ensureContainer();
264
+ for (const e of this._liElements) e.remove();
265
+ this._liElements = [];
266
+ for (let e = 0; e < this._options.length; e++) {
267
+ const i = this._createLiElement(this._options[e], e);
268
+ this._liElements.push(i), t.appendChild(i);
269
+ }
270
+ this._createLi && t.appendChild(this._createLi), this._syncFilterToDom();
271
+ }
272
+ _createLiElement(t, e) {
273
+ const i = document.createElement("li");
274
+ return i.setAttribute("role", "option"), i.setAttribute("id", `${this._idPrefix}-${e}`), i.setAttribute("part", "option"), i.setAttribute("data-value", t.value), i.setAttribute("data-kind", t.kind ?? "option"), t.kind === "action" ? i.setAttribute("data-action", t.action) : i.removeAttribute("data-action"), i.setAttribute("aria-selected", this._selectedValues.has(t.value) ? "true" : "false"), i.setAttribute("aria-disabled", t.disabled ? "true" : "false"), this._checkmark && this._ensureCheckmark(i), this._setLabelText(i, t.label), i;
275
+ }
276
+ _setLabelText(t, e) {
277
+ for (const i of t.childNodes)
278
+ if (i.nodeType === Node.TEXT_NODE) {
279
+ i.textContent = e;
280
+ return;
281
+ }
282
+ t.appendChild(document.createTextNode(e));
283
+ }
284
+ _ensureCheckmark(t) {
285
+ if (t.querySelector('[part="option-checkmark"]')) return;
286
+ const e = document.createElement("span");
287
+ e.setAttribute("part", "option-checkmark"), e.setAttribute("aria-hidden", "true"), e.textContent = "✓", t.insertBefore(e, t.firstChild);
288
+ }
289
+ _removeCheckmark(t) {
290
+ t.querySelector('[part="option-checkmark"]')?.remove();
291
+ }
292
+ _syncCheckmarks() {
293
+ const t = this._createLi ? [...this._liElements, this._createLi] : [...this._liElements];
294
+ for (const e of t)
295
+ this._checkmark ? this._ensureCheckmark(e) : this._removeCheckmark(e);
296
+ }
297
+ _syncSelectedToDom() {
298
+ for (let t = 0; t < this._liElements.length; t++) {
299
+ const e = this._options[t];
300
+ e && this._liElements[t].setAttribute(
301
+ "aria-selected",
302
+ this._selectedValues.has(e.value) ? "true" : "false"
303
+ );
304
+ }
305
+ }
306
+ _syncFilterToDom() {
307
+ for (let t = 0; t < this._liElements.length; t++) {
308
+ const e = this._options[t];
309
+ e && this._applyFilterToLi(this._liElements[t], e);
310
+ }
311
+ }
312
+ _applyFilterToLi(t, e) {
313
+ t.hidden = !this._isVisible(e);
314
+ }
315
+ _isVisible(t) {
316
+ if (!this._filterText) return !0;
317
+ const e = t.label.toLowerCase(), i = this._filterText.toLowerCase();
318
+ return typeof this._filterStrategy == "function" ? this._filterStrategy(e, i) : this._filterStrategy === "contains" ? e.includes(i) : e.startsWith(i);
319
+ }
320
+ _resolveOptionLi(t) {
321
+ if (!t) return null;
322
+ const e = t.closest("li[data-value]");
323
+ return !e || e.getAttribute("role") !== "option" || e.parentElement !== this._ul ? null : e;
324
+ }
325
+ /**
326
+ * Claims a pointer event as an option activation: stops it from continuing
327
+ * to bubble/compose past this point (left unstopped, a composed event can
328
+ * still be observed by ancestors outside this component — e.g. a <label>
329
+ * wrapping an unrelated sibling control — and be reinterpreted as an
330
+ * interaction with something else entirely), then activates the option.
331
+ */
332
+ _activateLi(t, e) {
333
+ e.preventDefault(), e.stopPropagation();
334
+ const i = this.optionForElement(t);
335
+ i && this._onActivate(i);
336
+ }
337
+ };
338
+ w._TOUCH_TAP_THRESHOLD = 10;
339
+ let T = w;
340
+ class R extends A {
341
+ constructor(t) {
342
+ if (super(t), this._options = {}, this._isPointerFocus = !1, this._onPointerdown = () => {
343
+ this._isPointerFocus = !0, this._target?.removeAttribute("data-interaction-mode");
344
+ }, this._onFocusin = () => {
345
+ this._isPointerFocus ? this._isPointerFocus = !1 : this._target?.setAttribute("data-interaction-mode", "keyboard");
346
+ }, this._onKeydown = () => {
347
+ this._target?.setAttribute("data-interaction-mode", "keyboard");
348
+ }, t.type !== L.ELEMENT)
349
+ throw new Error("The `keyInteraction` directive must be used on an element.");
350
+ }
351
+ get _target() {
352
+ return this._options.attributeTarget ?? this._element?.deref();
353
+ }
354
+ _init() {
355
+ const t = this._element?.deref();
356
+ t instanceof HTMLElement && (t.addEventListener("pointerdown", this._onPointerdown, { capture: !0 }), t.addEventListener("focusin", this._onFocusin), t.addEventListener("keydown", this._onKeydown));
357
+ }
358
+ render(t) {
359
+ return E;
360
+ }
361
+ update(t, [e]) {
362
+ this.isConnected && this._element?.deref() === void 0 && (this._element = new WeakRef(t.element), this._init()), this._options = e ?? {};
363
+ }
364
+ disconnected() {
365
+ const t = this._element?.deref();
366
+ t instanceof HTMLElement && (t.removeEventListener("pointerdown", this._onPointerdown, { capture: !0 }), t.removeEventListener("focusin", this._onFocusin), t.removeEventListener("keydown", this._onKeydown));
367
+ }
368
+ reconnected() {
369
+ this._init();
370
+ }
371
+ }
372
+ const st = C(R);
373
+ class H extends A {
374
+ constructor(t) {
375
+ if (super(t), this._options = {}, t.type !== L.ELEMENT)
376
+ throw new Error("The `keyNavigation` directive must be used on an element.");
377
+ }
378
+ /**
379
+ * The navigation axis determines which arrow keys map to 'next'/'prev'.
380
+ * Checks the explicit `navigationAxis` option first, then auto-detects
381
+ * from the element's ARIA role and aria-orientation attribute.
382
+ */
383
+ get navigationAxis() {
384
+ if (this._options.navigationAxis) return this._options.navigationAxis;
385
+ switch (this._element?.deref()?.role) {
386
+ case "slider":
387
+ case "tablist":
388
+ case "toolbar":
389
+ case "menubar":
390
+ return this._element?.deref()?.ariaOrientation === "vertical" ? "vertical" : "horizontal";
391
+ case "separator":
392
+ return this._element?.deref()?.ariaOrientation === "vertical" ? "horizontal" : "vertical";
393
+ default:
394
+ return this._element?.deref()?.ariaOrientation === "horizontal" ? "horizontal" : "vertical";
395
+ }
396
+ }
397
+ _normalizeKey(t) {
398
+ switch (t) {
399
+ case "Up":
400
+ return "ArrowUp";
401
+ case "Down":
402
+ return "ArrowDown";
403
+ case "Left":
404
+ return "ArrowLeft";
405
+ case "Right":
406
+ return "ArrowRight";
407
+ default:
408
+ return t;
409
+ }
410
+ }
411
+ _onKeydown(t) {
412
+ const e = this._normalizeKey(t.key), i = this.navigationAxis, s = this._element?.deref(), n = i === "horizontal" && s != null && getComputedStyle(s).direction === "rtl", r = i === "horizontal" ? n ? "ArrowLeft" : "ArrowRight" : "ArrowDown", a = i === "horizontal" ? n ? "ArrowRight" : "ArrowLeft" : "ArrowUp", h = i === "horizontal" ? "ArrowDown" : "ArrowRight", c = i === "horizontal" ? "ArrowUp" : "ArrowLeft";
413
+ let l;
414
+ this._options.handleNavAxis !== !1 && (e === r ? l = t.shiftKey ? "next-large" : "next" : e === a ? l = t.shiftKey ? "prev-large" : "prev" : e === "Home" ? l = "start" : e === "End" && (l = "end")), !l && this._options.handleOpenAxis && (e === h ? l = "open-to-first" : e === c && (l = "open-to-last")), l || (e === "Enter" ? l = this._options.handleActivate ? "activate" : "toggle" : e === " " && this._options.handleActivate ? l = "activate" : e === "Escape" && this._options.handleEscape && (l = "escape")), l != null && (this._callback(l), t.stopPropagation(), t.preventDefault());
415
+ }
416
+ _init() {
417
+ const t = this._element?.deref();
418
+ t != null && t instanceof HTMLElement && (this._keyDownHandle = this._onKeydown.bind(this), t.addEventListener("keydown", this._keyDownHandle));
419
+ }
420
+ /**
421
+ * @param _cb - Callback function invoked with the navigation action
422
+ * @param _options - Keyboard navigation behavior options.
423
+ */
424
+ render(t, e) {
425
+ return E;
426
+ }
427
+ update(t, [e, i]) {
428
+ this.isConnected && this._element?.deref() === void 0 && (this._element = new WeakRef(t.element), this._init()), this._callback = e.bind(t.options?.host ?? t.element), this._options = { ...i };
429
+ }
430
+ disconnected() {
431
+ const t = this._element?.deref();
432
+ t != null && t instanceof HTMLElement && t.removeEventListener("keydown", this._keyDownHandle);
433
+ }
434
+ reconnected() {
435
+ this._init();
436
+ }
437
+ }
438
+ const nt = C(H);
439
+ class W extends A {
440
+ constructor(t) {
441
+ if (super(t), this._activePointerId = null, t.type !== L.ELEMENT)
442
+ throw new Error("The `mouseMove` directive must be used on an element.");
443
+ this._pointerDownHandle = this._onPointerDown.bind(this), this._pointerMoveHandle = this._onPointerMove.bind(this), this._pointerEndHandle = this._onPointerEnd.bind(this);
444
+ }
445
+ /** Start a pointer drag cycle on the directive-decorated element. */
446
+ _onPointerDown(t) {
447
+ if (this._activePointerId !== null) return;
448
+ t.preventDefault();
449
+ const e = t.currentTarget;
450
+ this._activePointerId = t.pointerId, this._capturePointer(e, t.pointerId), e.addEventListener("pointermove", this._pointerMoveHandle), e.addEventListener("pointerup", this._pointerEndHandle), e.addEventListener("pointercancel", this._pointerEndHandle), e.addEventListener("lostpointercapture", this._pointerEndHandle), e.focus();
451
+ }
452
+ /** Forward pointer movement during an active drag cycle. */
453
+ _onPointerMove(t) {
454
+ t.pointerId === this._activePointerId && (t.preventDefault(), this._callback(t));
455
+ }
456
+ /** Finish the active pointer drag cycle and remove temporary listeners. */
457
+ _onPointerEnd(t) {
458
+ if (t.pointerId !== this._activePointerId) return;
459
+ t.preventDefault();
460
+ const e = t.currentTarget;
461
+ this._releasePointer(e, t.pointerId), this._removePointerCycleListeners(e), this._activePointerId = null;
462
+ }
463
+ /** Attach the permanent pointerdown listener to the current element. */
464
+ _init() {
465
+ const t = this._element?.deref();
466
+ t && (t.removeEventListener("pointerdown", this._pointerDownHandle), t.addEventListener("pointerdown", this._pointerDownHandle));
467
+ }
468
+ /** Remove all listeners associated with the active drag cycle. */
469
+ _removePointerCycleListeners(t) {
470
+ t.removeEventListener("pointermove", this._pointerMoveHandle), t.removeEventListener("pointerup", this._pointerEndHandle), t.removeEventListener("pointercancel", this._pointerEndHandle), t.removeEventListener("lostpointercapture", this._pointerEndHandle);
471
+ }
472
+ _capturePointer(t, e) {
473
+ try {
474
+ t.setPointerCapture(e);
475
+ } catch {
476
+ }
477
+ }
478
+ _releasePointer(t, e) {
479
+ try {
480
+ t.hasPointerCapture(e) && t.releasePointerCapture(e);
481
+ } catch {
482
+ }
483
+ }
484
+ /** Render no DOM; this directive only wires pointer listeners. */
485
+ render(t) {
486
+ return E;
487
+ }
488
+ update(t, [e]) {
489
+ if (this._callback = e.bind(t.options?.host ?? t.element), !this.isConnected || !(t.element instanceof HTMLElement)) return;
490
+ const i = this._element?.deref();
491
+ i !== t.element && (i?.removeEventListener("pointerdown", this._pointerDownHandle), i && this._removePointerCycleListeners(i), this._activePointerId = null, this._element = new WeakRef(t.element), this._init());
492
+ }
493
+ disconnected() {
494
+ const t = this._element?.deref();
495
+ t && (t.removeEventListener("pointerdown", this._pointerDownHandle), this._removePointerCycleListeners(t), this._activePointerId = null);
496
+ }
497
+ reconnected() {
498
+ this._init();
499
+ }
500
+ }
501
+ const ot = C(W);
502
+ class S {
503
+ constructor(t, e) {
504
+ this._$target = null, this._pointerId = null, this._startX = 0, this._startY = 0, this._startTime = 0, this._samples = [], this._activated = !1, this._rejected = !1, this._onPointerDown = (i) => {
505
+ if (this._pointerId !== null || !i.isPrimary && i.pointerId !== 1 || i.pointerType === "mouse" && i.button !== 0 || this._options.canStart?.(i) === !1)
506
+ return;
507
+ this._pointerId = i.pointerId, this._startX = i.clientX, this._startY = i.clientY, this._startTime = i.timeStamp, this._samples = [{ x: i.clientX, y: i.clientY, time: i.timeStamp }], this._activated = !1, this._rejected = !1;
508
+ const s = this._$target;
509
+ s && (s.addEventListener("pointermove", this._onPointerMove), s.addEventListener("pointerup", this._onPointerUp), s.addEventListener("pointercancel", this._onPointerCancel), s.addEventListener("lostpointercapture", this._onLostPointerCapture), this._options.activation === "immediate" && this._activate(i));
510
+ }, this._onPointerMove = (i) => {
511
+ i.pointerId !== this._pointerId || this._rejected || (this._recordSample(i), !(!this._activated && !this._resolveIntent(i)) && (this._options.onMove?.(this._detail(i)), this._options.preventDefault && i.preventDefault()));
512
+ }, this._onPointerUp = (i) => {
513
+ i.pointerId === this._pointerId && (this._recordSample(i), this._activated && this._options.onEnd?.(this._detail(i)), this._finish());
514
+ }, this._onPointerCancel = (i) => {
515
+ this._cancel(i);
516
+ }, this._onLostPointerCapture = (i) => {
517
+ i.pointerId === this._pointerId && this._cancel(i);
518
+ }, this._options = {
519
+ axis: "both",
520
+ activation: "immediate",
521
+ activationDistance: 8,
522
+ axisLockRatio: 1.25,
523
+ velocityWindow: 100,
524
+ minVelocityDuration: 8,
525
+ capture: !1,
526
+ stopPropagation: !1,
527
+ preventDefault: !0,
528
+ focusOnStart: !1,
529
+ ...e
530
+ }, t.addController(this);
531
+ }
532
+ /** Updates behavior or the target resolver and safely rebinds listeners. */
533
+ setOptions(t) {
534
+ Object.assign(this._options, t), this._bindTarget();
535
+ }
536
+ hostConnected() {
537
+ this._bindTarget();
538
+ }
539
+ hostUpdated() {
540
+ this._bindTarget();
541
+ }
542
+ hostDisconnected() {
543
+ this._unbindTarget();
544
+ }
545
+ _resolveTarget() {
546
+ const t = typeof this._options.target == "function" ? this._options.target() : this._options.target;
547
+ return t instanceof HTMLElement ? t : null;
548
+ }
549
+ _bindTarget() {
550
+ const t = this._resolveTarget();
551
+ t !== this._$target && (this._unbindTarget(), this._$target = t, this._$target?.addEventListener("pointerdown", this._onPointerDown, {
552
+ capture: this._options.capture
553
+ }));
554
+ }
555
+ _unbindTarget() {
556
+ this._$target && (this._$target.removeEventListener("pointerdown", this._onPointerDown, {
557
+ capture: this._options.capture
558
+ }), this._removeCycleListeners(this._$target), this._reset(), this._$target = null);
559
+ }
560
+ _resolveIntent(t) {
561
+ const e = t.clientX - this._startX, i = t.clientY - this._startY;
562
+ if (Math.hypot(e, i) < this._options.activationDistance)
563
+ return !1;
564
+ const { axis: n, axisLockRatio: r } = this._options, a = Math.abs(e), h = Math.abs(i);
565
+ return n === "x" && a < h * r || n === "y" && h < a * r ? (this._rejected = !0, this._finish(), !1) : (this._activate(t), !0);
566
+ }
567
+ _activate(t) {
568
+ const e = this._$target;
569
+ !e || this._activated || (this._activated = !0, this._capturePointer(e, t.pointerId), this._options.focusOnStart && e.focus(), this._options.stopPropagation && t.stopPropagation(), this._options.preventDefault && t.preventDefault(), this._options.onStart?.(this._detail(t)));
570
+ }
571
+ _cancel(t) {
572
+ t.pointerId === this._pointerId && (this._activated && this._options.onCancel?.(this._detail(t)), this._finish());
573
+ }
574
+ _finish() {
575
+ const t = this._$target, e = this._pointerId;
576
+ t && (this._removeCycleListeners(t), e !== null && this._releasePointer(t, e)), this._reset();
577
+ }
578
+ _removeCycleListeners(t) {
579
+ t.removeEventListener("pointermove", this._onPointerMove), t.removeEventListener("pointerup", this._onPointerUp), t.removeEventListener("pointercancel", this._onPointerCancel), t.removeEventListener("lostpointercapture", this._onLostPointerCapture);
580
+ }
581
+ _recordSample(t) {
582
+ this._samples.push({ x: t.clientX, y: t.clientY, time: t.timeStamp });
583
+ const e = t.timeStamp - this._options.velocityWindow;
584
+ for (; this._samples.length > 2 && this._samples[0].time < e; )
585
+ this._samples.shift();
586
+ }
587
+ _detail(t) {
588
+ const e = this._samples[0], i = this._samples.at(-1) ?? e, s = i.time - e.time, n = s >= this._options.minVelocityDuration;
589
+ return {
590
+ event: t,
591
+ pointerId: t.pointerId,
592
+ pointerType: t.pointerType,
593
+ startX: this._startX,
594
+ startY: this._startY,
595
+ x: t.clientX,
596
+ y: t.clientY,
597
+ deltaX: t.clientX - this._startX,
598
+ deltaY: t.clientY - this._startY,
599
+ duration: Math.max(0, t.timeStamp - this._startTime),
600
+ velocityX: n ? (i.x - e.x) / s * 1e3 : 0,
601
+ velocityY: n ? (i.y - e.y) / s * 1e3 : 0
602
+ };
603
+ }
604
+ _capturePointer(t, e) {
605
+ try {
606
+ t.setPointerCapture(e);
607
+ } catch (i) {
608
+ if (!(i instanceof DOMException) || i.name !== "NotFoundError")
609
+ throw i;
610
+ }
611
+ }
612
+ _releasePointer(t, e) {
613
+ try {
614
+ t.hasPointerCapture(e) && t.releasePointerCapture(e);
615
+ } catch {
616
+ }
617
+ }
618
+ _reset() {
619
+ this._pointerId = null, this._samples = [], this._activated = !1, this._rejected = !1;
620
+ }
621
+ }
622
+ class rt {
623
+ constructor(t, e) {
624
+ this._dragging = !1, this._startLeft = 0, this._startTop = 0, this._opts = {
625
+ axis: "both",
626
+ step: 4,
627
+ disabled: !1,
628
+ handle: null,
629
+ bounds: "viewport",
630
+ ...e
631
+ }, this._onKeyDown = this._handleKeyDown.bind(this), this._gesture = new S(t, {
632
+ target: () => this._handle(),
633
+ axis: this._opts.axis,
634
+ canStart: (i) => this._canStartGesture(i),
635
+ onStart: (i) => this._startDrag(i),
636
+ onMove: (i) => this._moveDrag(i),
637
+ onEnd: () => this._finishDrag(),
638
+ onCancel: () => this._finishDrag()
639
+ }), t.addController(this);
640
+ }
641
+ setOptions(t) {
642
+ const e = this._handle();
643
+ Object.assign(this._opts, t), this._gesture.setOptions({ axis: this._opts.axis, target: () => this._handle() });
644
+ const i = this._handle();
645
+ e !== i && (this._detachFrom(e), this._attachTo(i));
646
+ }
647
+ hostConnected() {
648
+ this._attachTo(this._handle());
649
+ }
650
+ hostDisconnected() {
651
+ this._detachFrom(this._handle());
652
+ }
653
+ _handle() {
654
+ return this._opts.handle ?? this._opts.target;
655
+ }
656
+ _target() {
657
+ return this._opts.target;
658
+ }
659
+ _attachTo(t) {
660
+ t.addEventListener("keydown", this._onKeyDown), t.hasAttribute("tabindex") || t.setAttribute("tabindex", "0");
661
+ }
662
+ _detachFrom(t) {
663
+ t.removeEventListener("keydown", this._onKeyDown);
664
+ }
665
+ _canStartGesture(t) {
666
+ return this._opts.disabled ? !1 : !t.target.closest('button, [role="button"], a');
667
+ }
668
+ _startDrag(t) {
669
+ const e = this._target(), i = e.getBoundingClientRect();
670
+ getComputedStyle(e).position === "static" && (e.style.position = "fixed"), e.style.translate = "none", e.style.inset = "auto", e.style.margin = "0", e.style.left = `${i.left}px`, e.style.top = `${i.top}px`, this._startLeft = i.left, this._startTop = i.top, this._dragging = !0;
671
+ }
672
+ _moveDrag(t) {
673
+ if (!this._dragging)
674
+ return;
675
+ const e = this._target(), { axis: i } = this._opts, [s, n, r, a] = this._boundsRect(), h = i !== "y" ? Math.min(Math.max(this._startLeft + t.deltaX, s), r - e.offsetWidth) : parseFloat(e.style.left) || 0, c = i !== "x" ? Math.min(Math.max(this._startTop + t.deltaY, n), a - e.offsetHeight) : parseFloat(e.style.top) || 0;
676
+ e.style.left = `${h}px`, e.style.top = `${c}px`;
677
+ }
678
+ _finishDrag() {
679
+ this._dragging && (this._dragging = !1);
680
+ }
681
+ _handleKeyDown(t) {
682
+ if (this._opts.disabled || t.currentTarget !== t.target)
683
+ return;
684
+ const { axis: e } = this._opts, i = t.shiftKey ? this._opts.step * 10 : this._opts.step;
685
+ let s = 0, n = 0;
686
+ switch (t.key) {
687
+ case "ArrowLeft":
688
+ if (e === "y")
689
+ return;
690
+ s = -i;
691
+ break;
692
+ case "ArrowRight":
693
+ if (e === "y")
694
+ return;
695
+ s = i;
696
+ break;
697
+ case "ArrowUp":
698
+ if (e === "x")
699
+ return;
700
+ n = -i;
701
+ break;
702
+ case "ArrowDown":
703
+ if (e === "x")
704
+ return;
705
+ n = i;
706
+ break;
707
+ default:
708
+ return;
709
+ }
710
+ const r = this._target();
711
+ if (getComputedStyle(r).position === "static") {
712
+ const _ = r.getBoundingClientRect();
713
+ r.style.position = "fixed", r.style.translate = "none", r.style.left = `${_.left}px`, r.style.top = `${_.top}px`;
714
+ }
715
+ const [a, h, c, l] = this._boundsRect(), u = parseFloat(r.style.left) || 0, d = parseFloat(r.style.top) || 0;
716
+ r.style.left = `${Math.min(Math.max(u + s, a), c - r.offsetWidth)}px`, r.style.top = `${Math.min(Math.max(d + n, h), l - r.offsetHeight)}px`, t.preventDefault(), t.stopPropagation();
717
+ }
718
+ _boundsRect() {
719
+ const { bounds: t } = this._opts;
720
+ if (!t || t === "viewport")
721
+ return [0, 0, window.innerWidth, window.innerHeight];
722
+ if (t === "parent") {
723
+ const i = this._opts.target.parentElement;
724
+ if (!i)
725
+ return [0, 0, window.innerWidth, window.innerHeight];
726
+ const s = i.getBoundingClientRect();
727
+ return [s.left, s.top, s.right, s.bottom];
728
+ }
729
+ const e = t.getBoundingClientRect();
730
+ return [e.left, e.top, e.right, e.bottom];
731
+ }
732
+ }
733
+ function B(o) {
734
+ const t = o.getBoundingClientRect(), e = o.offsetParent, i = e ? t.left - e.getBoundingClientRect().left - e.clientLeft + e.scrollLeft : t.left, s = e ? t.top - e.getBoundingClientRect().top - e.clientTop + e.scrollTop : t.top;
735
+ return getComputedStyle(o).position === "static" && (o.style.position = "fixed"), o.style.translate = "none", o.style.inset = "auto", o.style.margin = "0", o.style.boxSizing = "border-box", o.style.left = `${i}px`, o.style.top = `${s}px`, o.style.width = `${t.width}px`, o.style.height = `${t.height}px`, t;
736
+ }
737
+ class at {
738
+ constructor(t, e) {
739
+ this._resizing = null, this._startW = 0, this._startH = 0, this._startLeft = 0, this._startTop = 0, this._lastDeltaX = 0, this._lastDeltaY = 0, this._velocityX = 0, this._velocityY = 0, this._pendingEdge = null, this._effectiveMinW = 0, this._effectiveMinH = 0, this._effectiveMaxW = 1 / 0, this._effectiveMaxH = 1 / 0, this._cornerBtn = null, this._opts = {
740
+ direction: "none",
741
+ threshold: 8,
742
+ step: 4,
743
+ disabled: !1,
744
+ minWidth: 100,
745
+ minHeight: 60,
746
+ handle: null,
747
+ origin: "",
748
+ bounds: "viewport",
749
+ ...e
750
+ }, this._onPointerMove = this._handlePointerMove.bind(this), this._onPointerLeave = this._handlePointerLeave.bind(this), this._onKeyDown = this._handleKeyDown.bind(this), this._gesture = new S(t, {
751
+ target: () => this._handle() ?? this._target(),
752
+ capture: !0,
753
+ stopPropagation: !0,
754
+ canStart: (i) => this._canStartGesture(i),
755
+ onStart: (i) => this._startGestureResize(i),
756
+ onMove: (i) => this._moveGestureResize(i),
757
+ onEnd: (i) => this._endGestureResize(i),
758
+ onCancel: () => this._cancelResize()
759
+ }), t.addController(this);
760
+ }
761
+ setOptions(t) {
762
+ const e = this._opts.handle;
763
+ Object.assign(this._opts, t), this._gesture.setOptions({ target: () => this._handle() ?? this._target() }), e !== this._opts.handle && (this._detachFromHandle(e), this._attachToHandle(this._opts.handle));
764
+ }
765
+ hostConnected() {
766
+ if (this._opts.direction === "none")
767
+ return;
768
+ if (this._opts.handle) {
769
+ this._attachToHandle(this._opts.handle);
770
+ return;
771
+ }
772
+ const t = this._target();
773
+ t.addEventListener("pointermove", this._onPointerMove), t.addEventListener("pointerleave", this._onPointerLeave), this._injectCornerButton();
774
+ }
775
+ hostDisconnected() {
776
+ if (this._opts.handle) {
777
+ this._detachFromHandle(this._opts.handle);
778
+ return;
779
+ }
780
+ const t = this._target();
781
+ t.removeEventListener("pointermove", this._onPointerMove), t.removeEventListener("pointerleave", this._onPointerLeave), this._removeCornerButton();
782
+ }
783
+ _target() {
784
+ return this._opts.target;
785
+ }
786
+ _handle() {
787
+ return this._opts.handle;
788
+ }
789
+ _attachToHandle(t) {
790
+ !t || this._opts.direction === "none" || (t.addEventListener("keydown", this._onKeyDown), t.style.cursor = this._edgeCursor(this._handleEdge()), t.style.touchAction = "none", t.hasAttribute("tabindex") || t.setAttribute("tabindex", "0"));
791
+ }
792
+ _detachFromHandle(t) {
793
+ t && t.removeEventListener("keydown", this._onKeyDown);
794
+ }
795
+ _injectCornerButton() {
796
+ if (this._opts.handle)
797
+ return;
798
+ const t = this._target();
799
+ getComputedStyle(t).position === "static" && (t.style.position = "relative");
800
+ const e = document.createElement("button");
801
+ e.setAttribute("data-rc-resize-corner", ""), e.setAttribute("aria-label", "Resize"), e.type = "button", Object.assign(e.style, {
802
+ position: "absolute",
803
+ bottom: "0",
804
+ right: "0",
805
+ width: "12px",
806
+ height: "12px",
807
+ padding: "0",
808
+ border: "none",
809
+ background: "transparent",
810
+ cursor: this._cornerCursor(),
811
+ zIndex: "1"
812
+ }), e.addEventListener("keydown", this._onKeyDown), t.appendChild(e), this._cornerBtn = e;
813
+ }
814
+ _removeCornerButton() {
815
+ this._cornerBtn && (this._cornerBtn.removeEventListener("keydown", this._onKeyDown), this._cornerBtn.remove(), this._cornerBtn = null);
816
+ }
817
+ _cornerCursor() {
818
+ switch (this._opts.direction) {
819
+ case "both":
820
+ return "se-resize";
821
+ case "horizontal":
822
+ return "ew-resize";
823
+ case "vertical":
824
+ return "ns-resize";
825
+ default:
826
+ return "default";
827
+ }
828
+ }
829
+ _edgeCursor(t) {
830
+ return {
831
+ n: "n-resize",
832
+ s: "s-resize",
833
+ e: "e-resize",
834
+ w: "w-resize",
835
+ ne: "ne-resize",
836
+ nw: "nw-resize",
837
+ se: "se-resize",
838
+ sw: "sw-resize"
839
+ }[t];
840
+ }
841
+ _handleEdge() {
842
+ return this._edgeForOrigin(this._opts.origin) ?? this._defaultHandleEdge();
843
+ }
844
+ _defaultHandleEdge() {
845
+ switch (this._opts.direction) {
846
+ case "both":
847
+ return "se";
848
+ case "horizontal":
849
+ return "e";
850
+ case "vertical":
851
+ return "s";
852
+ default:
853
+ return "se";
854
+ }
855
+ }
856
+ _edgeForOrigin(t) {
857
+ if (!t)
858
+ return null;
859
+ const e = t.includes("top"), i = t.includes("bottom"), s = t.includes("left"), n = t.includes("right");
860
+ if (this._opts.direction === "vertical")
861
+ return e ? "n" : i ? "s" : null;
862
+ if (this._opts.direction === "horizontal")
863
+ return s ? "w" : n ? "e" : null;
864
+ if (this._opts.direction === "both") {
865
+ if (e && s)
866
+ return "nw";
867
+ if (e && n)
868
+ return "ne";
869
+ if (i && s)
870
+ return "sw";
871
+ if (i && n)
872
+ return "se";
873
+ if (e)
874
+ return "n";
875
+ if (i)
876
+ return "s";
877
+ if (s)
878
+ return "w";
879
+ if (n)
880
+ return "e";
881
+ }
882
+ return null;
883
+ }
884
+ _edgeAllowsPointer(t, e) {
885
+ const { threshold: i } = this._opts, s = this._target().getBoundingClientRect(), n = e.clientX, r = e.clientY, a = n >= s.right - i && n <= s.right + i, h = n >= s.left - i && n <= s.left + i, c = r >= s.bottom - i && r <= s.bottom + i, l = r >= s.top - i && r <= s.top + i, u = n >= s.left && n <= s.right, d = r >= s.top && r <= s.bottom;
886
+ switch (t) {
887
+ case "n":
888
+ return l && u;
889
+ case "s":
890
+ return c && u;
891
+ case "e":
892
+ return a && d;
893
+ case "w":
894
+ return h && d;
895
+ case "ne":
896
+ return l && a;
897
+ case "nw":
898
+ return l && h;
899
+ case "se":
900
+ return c && a;
901
+ case "sw":
902
+ return c && h;
903
+ }
904
+ }
905
+ _detectEdge(t) {
906
+ const { direction: e, threshold: i } = this._opts;
907
+ if (e === "none")
908
+ return null;
909
+ const s = this._edgeForOrigin(this._opts.origin);
910
+ if (s)
911
+ return this._edgeAllowsPointer(s, t) ? s : null;
912
+ const n = this._target().getBoundingClientRect(), r = t.clientX, a = t.clientY, h = r >= n.right - i && r <= n.right + i, c = r >= n.left - i && r <= n.left + i, l = a >= n.bottom - i && a <= n.bottom + i, u = a >= n.top - i && a <= n.top + i, d = r >= n.left && r <= n.right, _ = a >= n.top && a <= n.bottom;
913
+ if (e === "both") {
914
+ if (h && l)
915
+ return "se";
916
+ if (c && l)
917
+ return "sw";
918
+ if (h && u)
919
+ return "ne";
920
+ if (c && u)
921
+ return "nw";
922
+ if (h && _)
923
+ return "e";
924
+ if (c && _)
925
+ return "w";
926
+ if (l && d)
927
+ return "s";
928
+ if (u && d)
929
+ return "n";
930
+ }
931
+ if (e === "horizontal") {
932
+ if (h && _)
933
+ return "e";
934
+ if (c && _)
935
+ return "w";
936
+ }
937
+ if (e === "vertical") {
938
+ if (l && d)
939
+ return "s";
940
+ if (u && d)
941
+ return "n";
942
+ }
943
+ return null;
944
+ }
945
+ _pinPosition(t) {
946
+ return B(t);
947
+ }
948
+ _canStartGesture(t) {
949
+ if (this._opts.disabled)
950
+ return !1;
951
+ const i = this._handle() ? this._handleEdge() : this._detectEdge(t);
952
+ return this._pendingEdge = i, i !== null;
953
+ }
954
+ _startGestureResize(t) {
955
+ this._pendingEdge && (this._velocityX = 0, this._velocityY = 0, this._startResize(this._pendingEdge));
956
+ }
957
+ _moveGestureResize(t) {
958
+ this._resizing && (this._lastDeltaX = t.deltaX, this._lastDeltaY = t.deltaY, this._velocityX = t.velocityX, this._velocityY = t.velocityY, this._applyDelta(this._resizing, t.deltaX, t.deltaY), this._opts.onResize?.(this._lifecycleDetail("pointer")));
959
+ }
960
+ _endGestureResize(t) {
961
+ this._velocityX = t.velocityX, this._velocityY = t.velocityY, this._finishResize("pointer");
962
+ }
963
+ _startResize(t) {
964
+ const e = this._target(), i = this._pinPosition(e);
965
+ this._startW = i.width, this._startH = i.height, this._startLeft = Number.parseFloat(e.style.left), this._startTop = Number.parseFloat(e.style.top), this._lastDeltaX = 0, this._lastDeltaY = 0, this._resizing = t, this._computeEffectiveExtents(e), this._opts.onResizeStart?.(this._lifecycleDetail("pointer"));
966
+ }
967
+ /**
968
+ * Computed once per resize gesture (pointer-down or keyboard step) so the
969
+ * browser's enforcement of CSS min/max-width/height doesn't fight the JS
970
+ * math — otherwise a CSS-only max (e.g. a themed `max-block-size`) clips
971
+ * the rendered box while the pinned edge keeps moving, making the whole
972
+ * element appear to slide once dragged past its extent.
973
+ */
974
+ _computeEffectiveExtents(t) {
975
+ const e = getComputedStyle(t);
976
+ this._effectiveMinW = Math.max(this._opts.minWidth, parseFloat(e.minWidth) || 0), this._effectiveMinH = Math.max(this._opts.minHeight, parseFloat(e.minHeight) || 0), this._effectiveMaxW = Math.min(
977
+ this._opts.maxWidth ?? 1 / 0,
978
+ parseFloat(e.maxWidth) || 1 / 0
979
+ ), this._effectiveMaxH = Math.min(
980
+ this._opts.maxHeight ?? 1 / 0,
981
+ parseFloat(e.maxHeight) || 1 / 0
982
+ );
983
+ }
984
+ _lifecycleDetail(t) {
985
+ const e = this._target();
986
+ return {
987
+ edge: this._resizing ?? this._handleEdge(),
988
+ inputType: t,
989
+ startWidth: this._startW,
990
+ startHeight: this._startH,
991
+ width: e.getBoundingClientRect().width,
992
+ height: e.getBoundingClientRect().height,
993
+ deltaX: this._lastDeltaX,
994
+ deltaY: this._lastDeltaY,
995
+ velocityX: t === "pointer" ? this._velocityX : 0,
996
+ velocityY: t === "pointer" ? this._velocityY : 0
997
+ };
998
+ }
999
+ _handlePointerMove(t) {
1000
+ if (this._resizing || this._opts.handle)
1001
+ return;
1002
+ const e = this._detectEdge(t), i = this._target();
1003
+ i.style.cursor = e ? this._edgeCursor(e) : "";
1004
+ }
1005
+ _finishResize(t) {
1006
+ if (!this._resizing)
1007
+ return;
1008
+ const e = this._lifecycleDetail(t);
1009
+ this._resizing = null, this._pendingEdge = null, this._opts.onResizeEnd?.(e);
1010
+ }
1011
+ _cancelResize() {
1012
+ this._resizing = null, this._pendingEdge = null;
1013
+ }
1014
+ _handlePointerLeave(t) {
1015
+ this._resizing || (this._target().style.cursor = "");
1016
+ }
1017
+ _handleKeyDown(t) {
1018
+ if (this._opts.disabled)
1019
+ return;
1020
+ const { direction: e } = this._opts, i = t.key === "ArrowRight" || t.key === "ArrowLeft", s = t.key === "ArrowDown" || t.key === "ArrowUp";
1021
+ if (i && e === "vertical" || s && e === "horizontal" || !i && !s)
1022
+ return;
1023
+ t.preventDefault(), t.stopPropagation();
1024
+ const n = this._target(), r = this._pinPosition(n), a = this._keyboardEdge(t.key);
1025
+ if (!a)
1026
+ return;
1027
+ this._resizing = a, this._startW = r.width, this._startH = r.height, this._startLeft = r.left, this._startTop = r.top;
1028
+ const h = t.shiftKey ? this._opts.step * 10 : this._opts.step;
1029
+ this._computeEffectiveExtents(n);
1030
+ const c = t.key === "ArrowRight" ? h : t.key === "ArrowLeft" ? -h : 0, l = t.key === "ArrowDown" ? h : t.key === "ArrowUp" ? -h : 0;
1031
+ this._lastDeltaX = c, this._lastDeltaY = l, this._applyDelta(a, c, l), this._opts.onResize?.(this._lifecycleDetail("keyboard")), this._finishResize("keyboard");
1032
+ }
1033
+ _keyboardEdge(t) {
1034
+ const e = this._edgeForOrigin(this._opts.origin);
1035
+ return e || (t === "ArrowRight" || t === "ArrowLeft" ? this._opts.direction === "both" || this._opts.direction === "horizontal" ? "e" : null : (t === "ArrowDown" || t === "ArrowUp") && (this._opts.direction === "both" || this._opts.direction === "vertical") ? "s" : null);
1036
+ }
1037
+ _applyDelta(t, e, i) {
1038
+ const s = this._target(), [n, r, a, h] = this._boundsRect(), c = this._effectiveMinW, l = this._effectiveMinH, u = this._effectiveMaxW, d = this._effectiveMaxH;
1039
+ if (t === "e" || t === "se" || t === "ne") {
1040
+ const _ = Math.min(u, a - this._startLeft);
1041
+ s.style.width = `${Math.min(Math.max(this._startW + e, c), _)}px`;
1042
+ }
1043
+ if (t === "w" || t === "sw" || t === "nw") {
1044
+ const _ = this._startLeft + this._startW, p = Math.min(
1045
+ Math.max(this._startLeft + e, n, _ - u),
1046
+ _ - c
1047
+ );
1048
+ s.style.left = `${p}px`, s.style.width = `${_ - p}px`;
1049
+ }
1050
+ if (t === "s" || t === "se" || t === "sw") {
1051
+ const _ = Math.min(d, h - this._startTop);
1052
+ s.style.height = `${Math.min(Math.max(this._startH + i, l), _)}px`;
1053
+ }
1054
+ if (t === "n" || t === "ne" || t === "nw") {
1055
+ const _ = this._startTop + this._startH, p = Math.min(
1056
+ Math.max(this._startTop + i, r, _ - d),
1057
+ _ - l
1058
+ );
1059
+ s.style.top = `${p}px`, s.style.height = `${_ - p}px`;
1060
+ }
1061
+ }
1062
+ _boundsRect() {
1063
+ const { bounds: t } = this._opts;
1064
+ if (!t || t === "viewport")
1065
+ return [0, 0, window.innerWidth, window.innerHeight];
1066
+ if (t === "parent") {
1067
+ const i = this._opts.target.parentElement;
1068
+ if (!i)
1069
+ return [0, 0, window.innerWidth, window.innerHeight];
1070
+ const s = i.getBoundingClientRect();
1071
+ return [s.left, s.top, s.right, s.bottom];
1072
+ }
1073
+ const e = t.getBoundingClientRect();
1074
+ return [e.left, e.top, e.right, e.bottom];
1075
+ }
1076
+ }
1077
+ class Y {
1078
+ constructor(t) {
1079
+ this._callback = null, this._frame = 0, t?.addController(this);
1080
+ }
1081
+ get pending() {
1082
+ return this._frame !== 0;
1083
+ }
1084
+ schedule(t) {
1085
+ this._callback = t, !this._frame && (this._frame = requestAnimationFrame((e) => {
1086
+ const i = this._callback;
1087
+ this._frame = 0, this._callback = null, i?.(e);
1088
+ }));
1089
+ }
1090
+ cancel() {
1091
+ this._frame && (cancelAnimationFrame(this._frame), this._frame = 0, this._callback = null);
1092
+ }
1093
+ hostDisconnected() {
1094
+ this.cancel();
1095
+ }
1096
+ }
1097
+ function k(o) {
1098
+ const t = o.visualViewport, e = t?.offsetLeft ?? 0, i = t?.offsetTop ?? 0, s = t?.width ?? o.innerWidth, n = t?.height ?? o.innerHeight;
1099
+ return {
1100
+ left: e,
1101
+ top: i,
1102
+ width: s,
1103
+ height: n,
1104
+ right: e + s,
1105
+ bottom: i + n
1106
+ };
1107
+ }
1108
+ function y(o, t) {
1109
+ const e = `${t}px`;
1110
+ switch (o) {
1111
+ case "top":
1112
+ return `position-area: top; margin-bottom: ${e};`;
1113
+ case "top-start":
1114
+ return `bottom: anchor(top); top: auto; left: anchor(left); right: auto; margin-bottom: ${e};`;
1115
+ case "top-end":
1116
+ return `bottom: anchor(top); top: auto; left: auto; right: anchor(right); margin-bottom: ${e};`;
1117
+ case "bottom":
1118
+ return `position-area: bottom; margin-top: ${e};`;
1119
+ case "bottom-start":
1120
+ return `top: anchor(bottom); bottom: auto; left: anchor(left); right: auto; margin-top: ${e};`;
1121
+ case "bottom-end":
1122
+ return `top: anchor(bottom); bottom: auto; left: auto; right: anchor(right); margin-top: ${e};`;
1123
+ case "left":
1124
+ return `position-area: left; margin-right: ${e};`;
1125
+ case "left-start":
1126
+ return `top: anchor(top); bottom: auto; right: anchor(left); left: auto; margin-right: ${e};`;
1127
+ case "left-end":
1128
+ return `top: auto; bottom: anchor(bottom); right: anchor(left); left: auto; margin-right: ${e};`;
1129
+ case "right":
1130
+ return `position-area: right; margin-left: ${e};`;
1131
+ case "right-start":
1132
+ return `top: anchor(top); bottom: auto; left: anchor(right); right: auto; margin-left: ${e};`;
1133
+ case "right-end":
1134
+ return `top: auto; bottom: anchor(bottom); left: anchor(right); right: auto; margin-left: ${e};`;
1135
+ }
1136
+ }
1137
+ const D = {
1138
+ top: "bottom",
1139
+ "top-start": "bottom-start",
1140
+ "top-end": "bottom-end",
1141
+ bottom: "top",
1142
+ "bottom-start": "top-start",
1143
+ "bottom-end": "top-end",
1144
+ left: "right",
1145
+ "left-start": "right-start",
1146
+ "left-end": "right-end",
1147
+ right: "left",
1148
+ "right-start": "left-start",
1149
+ "right-end": "left-end"
1150
+ }, X = {
1151
+ top: "top",
1152
+ "top-start": "top-end",
1153
+ "top-end": "top-start",
1154
+ bottom: "bottom",
1155
+ "bottom-start": "bottom-end",
1156
+ "bottom-end": "bottom-start",
1157
+ left: "left",
1158
+ "left-start": "left-end",
1159
+ "left-end": "left-start",
1160
+ right: "right",
1161
+ "right-start": "right-end",
1162
+ "right-end": "right-start"
1163
+ }, I = typeof CSS < "u" && CSS.supports("position-try-fallbacks: flip-block") && CSS.supports("min-width: anchor-size(width)");
1164
+ let P = null, x = null;
1165
+ function N() {
1166
+ return I ? Promise.resolve(null) : (x || (x = import("./css-anchor-positioning-fn-hFYJeBk4.js").then((o) => (P = o.default, P)).catch(() => null)), x);
1167
+ }
1168
+ let V = 0;
1169
+ class ht {
1170
+ constructor(t, e) {
1171
+ this._styleEl = null, this._adoptedSheet = null, this._connected = !1, this._clampScheduler = new Y(), this._clampLoopActive = !1, this._settleFramesRemaining = 0, this._stableFrames = 0, this._lastNaturalRect = "", this._appliedDx = 0, this._appliedDy = 0, this._geometryAbort = null, this._resizeObserver = null, this._intersectionObserver = null, this._mutationObserver = null, this._$observedAnchor = null, this._$observedFloating = null, this._handleGeometryChange = () => {
1172
+ this._scheduleClamp();
1173
+ }, this._opts = e, this._uid = `rc-anchor-${++V}`, t.addController(this);
1174
+ }
1175
+ setOptions(t) {
1176
+ Object.assign(this._opts, t), this._applyAndPolyfill();
1177
+ }
1178
+ /** Re-apply positioning after the popup becomes visible or the anchor moves. */
1179
+ update() {
1180
+ this._applyAndPolyfill();
1181
+ }
1182
+ hostConnected() {
1183
+ this._connected = !0, this._applyAndPolyfill();
1184
+ }
1185
+ hostDisconnected() {
1186
+ this._connected = !1, this._cleanup();
1187
+ }
1188
+ _anchor() {
1189
+ const { anchor: t } = this._opts;
1190
+ return typeof t == "function" ? t() : t;
1191
+ }
1192
+ _floating() {
1193
+ const { floating: t } = this._opts;
1194
+ return typeof t == "function" ? t() : t;
1195
+ }
1196
+ _shadowHost() {
1197
+ const { shadowHost: t } = this._opts;
1198
+ return typeof t == "function" ? t() : t ?? null;
1199
+ }
1200
+ _applyAndPolyfill() {
1201
+ !this._connected || !this._apply() || (I ? (this._startWatchingGeometry(), this._scheduleClamp()) : this._applyPolyfillOrFallback().then(() => {
1202
+ this._connected && !this._opts.disabled && (this._startWatchingGeometry(), this._scheduleClamp());
1203
+ }));
1204
+ }
1205
+ /**
1206
+ * Checks viewport overflow during a bounded post-open settling window.
1207
+ * Observers and viewport events restart the window when geometry changes,
1208
+ * avoiding permanent layout polling while a popup is idle.
1209
+ */
1210
+ _scheduleClamp() {
1211
+ !this._connected || this._opts.disabled || (this._clampLoopActive || (this._clampLoopActive = !0), this._settleFramesRemaining = 10, this._stableFrames = 0, this._lastNaturalRect = "", this._clampScheduler.schedule(() => this._runClampTick()));
1212
+ }
1213
+ _runClampTick() {
1214
+ if (!this._connected || this._opts.disabled) {
1215
+ this._stopClampLoop();
1216
+ return;
1217
+ }
1218
+ const t = this._floating();
1219
+ if (!t) {
1220
+ this._stopClampLoop();
1221
+ return;
1222
+ }
1223
+ const e = t.getBoundingClientRect();
1224
+ if (!(e.width > 0 || e.height > 0)) {
1225
+ this._stopClampLoop(), this._stopWatchingGeometry();
1226
+ return;
1227
+ }
1228
+ const s = [
1229
+ e.left - this._appliedDx,
1230
+ e.top - this._appliedDy,
1231
+ e.width,
1232
+ e.height
1233
+ ].map((n) => Math.round(n * 4) / 4).join(":");
1234
+ if (this._stableFrames = s === this._lastNaturalRect ? this._stableFrames + 1 : 0, this._lastNaturalRect = s, this._settleFramesRemaining -= 1, this._clampToViewport(e), this._stableFrames >= 3 || this._settleFramesRemaining <= 0) {
1235
+ this._stopClampLoop();
1236
+ return;
1237
+ }
1238
+ this._clampScheduler.schedule(() => this._runClampTick());
1239
+ }
1240
+ _stopClampLoop() {
1241
+ this._clampScheduler.cancel(), this._clampLoopActive = !1, this._settleFramesRemaining = 0, this._stableFrames = 0, this._lastNaturalRect = "";
1242
+ }
1243
+ _startWatchingGeometry() {
1244
+ const t = this._anchor(), e = this._floating();
1245
+ if (!t || !e) {
1246
+ this._stopWatchingGeometry();
1247
+ return;
1248
+ }
1249
+ if (this._geometryAbort && this._$observedAnchor === t && this._$observedFloating === e)
1250
+ return;
1251
+ this._stopWatchingGeometry(), this._$observedAnchor = t, this._$observedFloating = e, this._geometryAbort = new AbortController();
1252
+ const i = e.ownerDocument.defaultView, s = { passive: !0, signal: this._geometryAbort.signal };
1253
+ e.ownerDocument.addEventListener("scroll", this._handleGeometryChange, {
1254
+ ...s,
1255
+ capture: !0
1256
+ }), i?.addEventListener("resize", this._handleGeometryChange, s), i?.visualViewport?.addEventListener("resize", this._handleGeometryChange, s), i?.visualViewport?.addEventListener("scroll", this._handleGeometryChange, s), typeof ResizeObserver == "function" && (this._resizeObserver = new ResizeObserver(this._handleGeometryChange), this._resizeObserver.observe(t), this._resizeObserver.observe(e)), typeof IntersectionObserver == "function" && (this._intersectionObserver = new IntersectionObserver(this._handleGeometryChange, {
1257
+ threshold: [0, 1]
1258
+ }), this._intersectionObserver.observe(e)), typeof MutationObserver == "function" && (this._mutationObserver = new MutationObserver(this._handleGeometryChange), this._mutationObserver.observe(t, {
1259
+ attributes: !0,
1260
+ attributeFilter: ["class", "style", "hidden", "open"]
1261
+ }), this._mutationObserver.observe(e, {
1262
+ attributes: !0,
1263
+ attributeFilter: ["class", "style", "hidden", "open"]
1264
+ }));
1265
+ }
1266
+ _stopWatchingGeometry() {
1267
+ this._geometryAbort?.abort(), this._geometryAbort = null, this._resizeObserver?.disconnect(), this._resizeObserver = null, this._intersectionObserver?.disconnect(), this._intersectionObserver = null, this._mutationObserver?.disconnect(), this._mutationObserver = null, this._$observedAnchor = null, this._$observedFloating = null;
1268
+ }
1269
+ /**
1270
+ * Nudges the floating element back on-screen via `translate` if whatever
1271
+ * positioned it (native or otherwise) still left it overflowing the
1272
+ * viewport. `translate` is used rather than adjusting `left`/`top`/etc.
1273
+ * directly because it's a pure visual offset on top of the existing
1274
+ * positioning, independent of which mechanism produced it — no need to
1275
+ * know or reconstruct the underlying `left`/`right`/`position-anchor`
1276
+ * values to correct them. It's safe to apply even to a popover-promoted
1277
+ * element with its own further-nested anchor-positioned descendants (e.g.
1278
+ * a submenu): top-layer promotion means a nested popover isn't contained
1279
+ * by this element's box for `position: fixed` purposes, so translating
1280
+ * this one doesn't drag a nested popup along or break its own anchoring.
1281
+ *
1282
+ * `getBoundingClientRect()` reflects whatever `translate` the previous
1283
+ * update applied, and computing the new correction directly
1284
+ * off that rect would see the already-corrected (on-screen) position,
1285
+ * clear the correction as unnecessary, then reapply it next frame once
1286
+ * the underlying overflow reappears — an every-frame flicker confirmed
1287
+ * by a real click landing on a mid-flicker frame in the browser test
1288
+ * suite. `_appliedDx`/`_appliedDy` track the offset this method itself
1289
+ * last applied so it can subtract it back out and compute against the
1290
+ * element's natural, uncorrected position each time.
1291
+ */
1292
+ _clampToViewport(t) {
1293
+ const e = this._floating();
1294
+ if (!e)
1295
+ return;
1296
+ const i = 4, s = t ?? e.getBoundingClientRect();
1297
+ if (s.width === 0 && s.height === 0)
1298
+ return;
1299
+ const n = e.ownerDocument.defaultView;
1300
+ if (!n)
1301
+ return;
1302
+ const r = k(n), a = s.left - this._appliedDx, h = s.right - this._appliedDx, c = s.top - this._appliedDy, l = s.bottom - this._appliedDy;
1303
+ let u = 0, d = 0;
1304
+ h > r.right - i && (u = r.right - i - h), a + u < r.left + i && (u = r.left + i - a), l > r.bottom - i && (d = r.bottom - i - l), c + d < r.top + i && (d = r.top + i - c), this._appliedDx = u, this._appliedDy = d;
1305
+ const _ = u || d ? `${u}px ${d}px` : "", p = `${Math.max(0, r.width - i * 2)}px`, f = `${Math.max(0, r.height - i * 2)}px`;
1306
+ e.style.translate !== _ && (e.style.translate = _), e.style.getPropertyValue("--rc-anchor-viewport-inline-size") !== p && e.style.setProperty("--rc-anchor-viewport-inline-size", p), e.style.getPropertyValue("--rc-anchor-viewport-block-size") !== f && e.style.setProperty("--rc-anchor-viewport-block-size", f);
1307
+ }
1308
+ async _applyPolyfillOrFallback() {
1309
+ const t = await N();
1310
+ if (!this._connected || this._opts.disabled)
1311
+ return;
1312
+ const e = this._shadowHost();
1313
+ t ? await t({ roots: e ? [e] : void 0, useAnimationFrame: !1 }) : this._positionFallback();
1314
+ }
1315
+ _apply() {
1316
+ if (this._opts.disabled)
1317
+ return this._cleanup(), !1;
1318
+ const t = this._anchor(), e = this._floating();
1319
+ if (!t || !e)
1320
+ return this._stopClampLoop(), !1;
1321
+ const i = this._opts.placement ?? "bottom-start", s = this._opts.offset ?? 4, n = this._opts.flip ?? !0, r = `--${this._uid}`, a = this._uid;
1322
+ t.style.setProperty("anchor-name", r), e.setAttribute("data-rc-anchor", a);
1323
+ const h = D[i], c = X[i], l = D[c], u = n ? `
1324
+ @position-try --${a}-end { ${y(c, s)} }
1325
+ @position-try --${a}-flip { ${y(h, s)} }
1326
+ @position-try --${a}-both { ${y(l, s)} }
1327
+ ` : "", d = n ? `position-try-fallbacks: --${a}-end, --${a}-flip, --${a}-both;` : "", _ = `
1328
+ ${u}
1329
+ [data-rc-anchor="${a}"] {
1330
+ position: fixed;
1331
+ position-anchor: ${r};
1332
+ box-sizing: border-box;
1333
+ min-width: anchor-size(width);
1334
+ ${y(i, s)}
1335
+ ${d}
1336
+ }
1337
+ `;
1338
+ return this._injectStyles(_), !0;
1339
+ }
1340
+ _injectStyles(t) {
1341
+ const e = this._shadowHost();
1342
+ if (e?.shadowRoot)
1343
+ this._adoptedSheet || (this._adoptedSheet = new CSSStyleSheet(), e.shadowRoot.adoptedStyleSheets = [
1344
+ ...e.shadowRoot.adoptedStyleSheets,
1345
+ this._adoptedSheet
1346
+ ]), this._adoptedSheet.replaceSync(t);
1347
+ else {
1348
+ this._styleEl?.remove();
1349
+ const i = this._floating()?.ownerDocument ?? this._anchor()?.ownerDocument;
1350
+ if (!i)
1351
+ return;
1352
+ this._styleEl = i.createElement("style"), this._styleEl.setAttribute("data-rc-anchor-style", this._uid), this._styleEl.textContent = t, i.head.appendChild(this._styleEl);
1353
+ }
1354
+ }
1355
+ /**
1356
+ * Hand-rolled positioning for browsers where neither native anchor
1357
+ * positioning nor the polyfill is usable. Handles all four placement
1358
+ * sides (not just top/bottom — a side flyout like a cascading submenu
1359
+ * needs its primary axis to be horizontal, offsetting by the anchor's
1360
+ * own width/height rather than always stacking below it), with the
1361
+ * `-start`/`-end` suffix controlling cross-axis alignment and an
1362
+ * unsuffixed placement centering on the cross axis.
1363
+ */
1364
+ _positionFallback() {
1365
+ const t = this._anchor(), e = this._floating();
1366
+ if (!t || !e)
1367
+ return;
1368
+ const i = this._opts.placement ?? "bottom-start", s = this._opts.offset ?? 4, n = this._opts.flip ?? !0, r = 4, a = t.getBoundingClientRect(), h = t.ownerDocument.defaultView;
1369
+ if (!h)
1370
+ return;
1371
+ const c = k(h), l = h.innerWidth, u = h.innerHeight;
1372
+ e.style.position = "fixed", e.style.boxSizing = "border-box", e.style.minWidth = `${a.width}px`, e.style.top = "", e.style.bottom = "", e.style.left = "", e.style.right = "";
1373
+ const d = e.offsetWidth || a.width, _ = e.offsetHeight || 0, p = i.split("-")[0], f = i.endsWith("-start") ? "start" : i.endsWith("-end") ? "end" : "center";
1374
+ let b = p;
1375
+ if (p === "top" || p === "bottom") {
1376
+ const m = c.bottom - a.bottom, g = a.top - c.top;
1377
+ n && (p === "bottom" && m < _ + s && g > m ? b = "top" : p === "top" && g < _ + s && m > g && (b = "bottom")), b === "top" ? e.style.bottom = `${u - a.top + s}px` : e.style.top = `${a.bottom + s}px`;
1378
+ let v = f === "end" ? a.right - d : f === "start" ? a.left : a.left + a.width / 2 - d / 2;
1379
+ v = Math.max(c.left + r, Math.min(v, c.right - d - r)), e.style.left = `${v}px`;
1380
+ } else {
1381
+ const m = c.right - a.right, g = a.left - c.left;
1382
+ n && (p === "right" && m < d + s && g > m ? b = "left" : p === "left" && g < d + s && m > g && (b = "right")), b === "left" ? e.style.right = `${l - a.left + s}px` : e.style.left = `${a.right + s}px`;
1383
+ let v = f === "end" ? a.bottom - _ : f === "start" ? a.top : a.top + a.height / 2 - _ / 2;
1384
+ v = Math.max(c.top + r, Math.min(v, c.bottom - _ - r)), e.style.top = `${v}px`;
1385
+ }
1386
+ }
1387
+ _cleanup() {
1388
+ this._stopClampLoop(), this._stopWatchingGeometry(), this._appliedDx = 0, this._appliedDy = 0;
1389
+ const t = this._anchor(), e = this._floating();
1390
+ t && t.style.removeProperty("anchor-name"), e && (e.removeAttribute("data-rc-anchor"), e.style.translate = "", e.style.removeProperty("--rc-anchor-viewport-inline-size"), e.style.removeProperty("--rc-anchor-viewport-block-size")), this._styleEl?.remove(), this._styleEl = null;
1391
+ const i = this._shadowHost();
1392
+ i?.shadowRoot && this._adoptedSheet && (i.shadowRoot.adoptedStyleSheets = i.shadowRoot.adoptedStyleSheets.filter(
1393
+ (s) => s !== this._adoptedSheet
1394
+ ), this._adoptedSheet = null);
1395
+ }
1396
+ }
1397
+ class lt {
1398
+ constructor(t, e) {
1399
+ this._attached = null, this._scrolled = !1, this._onScroll = () => this._evaluate(), this._host = t, this._opts = e, t.addController(this);
1400
+ }
1401
+ /** Whether the observed target is currently scrolled past the threshold. */
1402
+ get scrolled() {
1403
+ return this._scrolled;
1404
+ }
1405
+ /** Reconfigure the controller: detaches, merges options, and reattaches. */
1406
+ setOptions(t) {
1407
+ this._detach(), Object.assign(this._opts, t), this._attach();
1408
+ }
1409
+ hostConnected() {
1410
+ this._attach();
1411
+ }
1412
+ hostDisconnected() {
1413
+ this._detach();
1414
+ }
1415
+ _resolveTarget() {
1416
+ const { target: t } = this._opts;
1417
+ return typeof t == "function" ? t() : t ?? null;
1418
+ }
1419
+ _attach() {
1420
+ if (this._opts.disabled || this._attached) return;
1421
+ const t = this._resolveTarget();
1422
+ t && (this._attached = t, t.addEventListener("scroll", this._onScroll, { passive: !0 }), this._evaluate());
1423
+ }
1424
+ _detach() {
1425
+ this._attached?.removeEventListener("scroll", this._onScroll), this._attached = null, this._lastScrollTop = void 0;
1426
+ }
1427
+ _scrollTop() {
1428
+ const t = this._attached;
1429
+ return t instanceof Element ? t.scrollTop : t instanceof Document ? t.scrollingElement?.scrollTop ?? 0 : t?.scrollY ?? 0;
1430
+ }
1431
+ _evaluate() {
1432
+ if (!this._attached) return;
1433
+ const t = this._scrollTop(), e = t - (this._lastScrollTop ?? t);
1434
+ this._lastScrollTop = t, this._opts.onScroll?.(t, e);
1435
+ const i = t > (this._opts.threshold ?? 4);
1436
+ i !== this._scrolled && (this._scrolled = i, this._opts.onChange?.(i, t), this._host.requestUpdate());
1437
+ }
1438
+ }
1439
+ class ct {
1440
+ constructor(t, e) {
1441
+ this._attached = null, this._observer = null, this._options = e, t.addController(this);
1442
+ }
1443
+ setOptions(t) {
1444
+ this._detach(), Object.assign(this._options, t), this._attach();
1445
+ }
1446
+ hostConnected() {
1447
+ this._attach();
1448
+ }
1449
+ hostDisconnected() {
1450
+ this._detach();
1451
+ }
1452
+ _resolveTarget() {
1453
+ const { target: t } = this._options;
1454
+ return typeof t == "function" ? t() : t ?? null;
1455
+ }
1456
+ _attach() {
1457
+ if (this._options.disabled || this._attached) return;
1458
+ const t = this._resolveTarget();
1459
+ t && (this._observer ??= new MutationObserver(this._options.callback), this._observer.observe(t, this._options.observerOptions ?? { childList: !0 }), this._attached = t);
1460
+ }
1461
+ _detach() {
1462
+ this._observer?.disconnect(), this._attached = null;
1463
+ }
1464
+ }
1465
+ class _t {
1466
+ constructor(t, e) {
1467
+ this._frame = 0, this._links = [], this._host = t, this._options = e, t.addController(this);
1468
+ }
1469
+ hostConnected() {
1470
+ this.sync();
1471
+ }
1472
+ hostDisconnected() {
1473
+ this._mutationObserver?.disconnect(), this._resizeObserver?.disconnect(), this._mutationObserver = void 0, this._resizeObserver = void 0, this._frame && cancelAnimationFrame(this._frame), this._frame = 0;
1474
+ }
1475
+ sync() {
1476
+ this._collectLinks(), this._observeLinks(), this.update();
1477
+ }
1478
+ update() {
1479
+ this._frame && cancelAnimationFrame(this._frame), this._frame = requestAnimationFrame(() => {
1480
+ this._frame = 0, this._positionIndicator();
1481
+ });
1482
+ }
1483
+ _collectLinks() {
1484
+ const e = this._options.slot()?.assignedElements({ flatten: !0 }) ?? [], i = /* @__PURE__ */ new Set();
1485
+ for (const s of e)
1486
+ s instanceof HTMLAnchorElement && i.add(s), s.querySelectorAll("a").forEach((n) => i.add(n));
1487
+ this._links = Array.from(i);
1488
+ }
1489
+ _observeLinks() {
1490
+ this._mutationObserver?.disconnect(), this._resizeObserver?.disconnect(), this._mutationObserver = new MutationObserver(() => {
1491
+ this._collectLinks(), this._observeLinks(), this.update();
1492
+ }), this._resizeObserver = new ResizeObserver(() => this.update()), this._resizeObserver.observe(this._host);
1493
+ for (const t of this._links) {
1494
+ this._mutationObserver.observe(t, {
1495
+ attributes: !0,
1496
+ attributeFilter: ["aria-current", "class", "data-active"],
1497
+ childList: !0,
1498
+ subtree: !0
1499
+ }), this._resizeObserver.observe(t);
1500
+ const e = this._targetFor(t);
1501
+ e && e !== t && this._resizeObserver.observe(e);
1502
+ }
1503
+ }
1504
+ _activeLink() {
1505
+ const t = this._options.activeSelector().trim();
1506
+ if (t) {
1507
+ const e = this._links.find((i) => i.matches(t));
1508
+ if (e)
1509
+ return e;
1510
+ }
1511
+ return this._links.find((e) => {
1512
+ const i = e.getAttribute("aria-current");
1513
+ return i !== null && i !== "" && i !== "false";
1514
+ }) ?? null;
1515
+ }
1516
+ _targetFor(t) {
1517
+ const e = this._options.indicatorTargetSelector().trim();
1518
+ if (e) {
1519
+ const i = t.matches(e) ? t : t.querySelector(e);
1520
+ if (i)
1521
+ return i;
1522
+ }
1523
+ return t.querySelector("[data-rc-navigation-indicator]") ?? t.querySelector("[data-rc-navigation-icon]") ?? t;
1524
+ }
1525
+ _positionIndicator() {
1526
+ const t = this._options.container(), e = this._options.indicator(), i = this._activeLink();
1527
+ if (this._host.toggleAttribute("has-active", !!i), !t || !e || !i) {
1528
+ e?.toggleAttribute("hidden", !0);
1529
+ return;
1530
+ }
1531
+ const s = this._targetFor(i), n = t.getBoundingClientRect(), r = s.getBoundingClientRect();
1532
+ if (!r.width || !r.height) {
1533
+ e.toggleAttribute("hidden", !0);
1534
+ return;
1535
+ }
1536
+ e.toggleAttribute("hidden", !1), e.style.inlineSize = `${r.width}px`, e.style.blockSize = `${r.height}px`, e.style.transform = `translate(${r.left - n.left}px, ${r.top - n.top}px)`;
1537
+ }
1538
+ }
1539
+ class dt {
1540
+ constructor(t) {
1541
+ this._buffer = "", this._timer = 0, this._options = t;
1542
+ }
1543
+ get buffer() {
1544
+ return this._buffer;
1545
+ }
1546
+ reset() {
1547
+ this._buffer = "", this._clearTimer();
1548
+ }
1549
+ handleKeydown(t) {
1550
+ return t.key.length !== 1 || t.altKey || t.ctrlKey || t.metaKey ? !1 : (this.search(t.key), t.preventDefault(), !0);
1551
+ }
1552
+ search(t) {
1553
+ this._buffer += t.toLocaleLowerCase(), this._scheduleReset();
1554
+ const e = this._options.items();
1555
+ if (!e.length) return null;
1556
+ const i = this._options.startIndex?.() ?? 0, s = e.length;
1557
+ for (let n = 1; n <= s; n += 1) {
1558
+ const r = (i + n) % s, a = e[r];
1559
+ if (this._options.text(a).trim().toLocaleLowerCase().startsWith(this._buffer))
1560
+ return this._options.onMatch(a, r), a;
1561
+ }
1562
+ return null;
1563
+ }
1564
+ _scheduleReset() {
1565
+ this._clearTimer(), this._timer = window.setTimeout(() => this.reset(), this._options.timeout ?? 500);
1566
+ }
1567
+ _clearTimer() {
1568
+ this._timer && (window.clearTimeout(this._timer), this._timer = 0);
1569
+ }
1570
+ }
1571
+ function ut(o) {
1572
+ let t = o.parentElement;
1573
+ for (; t && t !== document.documentElement; ) {
1574
+ const { overflow: e, overflowY: i } = getComputedStyle(t);
1575
+ if (/auto|scroll/.test(i) || /auto|scroll/.test(e)) return t;
1576
+ t = t.parentElement;
1577
+ }
1578
+ return document.scrollingElement ?? document.documentElement;
1579
+ }
1580
+ function K(o) {
1581
+ return o == null || o.hasAttribute("disabled") ? !1 : !!((o instanceof HTMLAnchorElement || o instanceof HTMLAreaElement) && o.hasAttribute("href") || o instanceof HTMLButtonElement || o instanceof HTMLInputElement || o instanceof HTMLTextAreaElement || o instanceof HTMLSelectElement || o.hasAttribute("tabindex") || o.shadowRoot?.delegatesFocus === !0);
1582
+ }
1583
+ function G(o, t) {
1584
+ return o.querySelector(t);
1585
+ }
1586
+ function U(o, t) {
1587
+ return Array.from(o.querySelectorAll(t));
1588
+ }
1589
+ function pt(o, t) {
1590
+ if (U(o, t.selector).length >= (t.minimum ?? 1)) return !1;
1591
+ const e = t.hostName ?? o.localName, i = t.childDescription ?? t.selector.replace(":scope > ", ""), s = t.message ?? `[${e}] No direct child ${i} found. Place ${i} inside <${e}>.`;
1592
+ return console.warn(s, o), !0;
1593
+ }
1594
+ class ft {
1595
+ constructor(t, e) {
1596
+ this._observer = null, this._child = null, this._host = t, this._options = e, t.addController(this);
1597
+ }
1598
+ get child() {
1599
+ return this._child;
1600
+ }
1601
+ hostConnected() {
1602
+ if (this.sync(), !this._options.observe) return;
1603
+ this._observer ??= new MutationObserver(() => this.sync());
1604
+ const t = this._options.observe === !0 ? { childList: !0 } : this._options.observe;
1605
+ this._observer.observe(this._host, t);
1606
+ }
1607
+ hostDisconnected() {
1608
+ this._observer?.disconnect(), this._child = null;
1609
+ }
1610
+ /** Re-read the child from the host and invoke `onChange` when it changes. */
1611
+ sync() {
1612
+ const t = this._child, e = G(this._host, this._options.selector);
1613
+ return this._child = e, e || this._options.onMissing?.(this._host), e !== t && this._options.onChange?.(e, t), e;
1614
+ }
1615
+ }
1616
+ var j = Object.defineProperty, q = (o, t, e, i) => {
1617
+ for (var s = void 0, n = o.length - 1, r; n >= 0; n--)
1618
+ (r = o[n]) && (s = r(t, e, s) || s);
1619
+ return s && j(t, e, s), s;
1620
+ };
1621
+ function mt(o) {
1622
+ class t extends o {
1623
+ constructor() {
1624
+ super(...arguments), this._items = [];
1625
+ }
1626
+ get items() {
1627
+ return this._items.map((i) => i.deref()).filter((i) => K(i));
1628
+ }
1629
+ get firstItem() {
1630
+ return this.items.at(0);
1631
+ }
1632
+ get lastItem() {
1633
+ return this.items.at(-1);
1634
+ }
1635
+ get nextItem() {
1636
+ const i = this._lastFocused ? this.items.indexOf(this._lastFocused) : 0;
1637
+ return this.items.at((i + 1) % this.items.length);
1638
+ }
1639
+ get previousItem() {
1640
+ const i = this._lastFocused ? this.items.indexOf(this._lastFocused) : 0;
1641
+ return this.items.at((i - 1) % this.items.length);
1642
+ }
1643
+ focusItem(i) {
1644
+ i?.focus();
1645
+ }
1646
+ focusItemAt(i) {
1647
+ this.focusItem(this.items.at(i));
1648
+ }
1649
+ focusFirst() {
1650
+ this.focusItem(this.firstItem);
1651
+ }
1652
+ focusLast() {
1653
+ this.focusItem(this.lastItem);
1654
+ }
1655
+ /**
1656
+ * Returns the elements to register from a slot.
1657
+ *
1658
+ * Override in subclasses to customise item collection — for example, to
1659
+ * traverse into `role="group"` containers or to skip `role="separator"`
1660
+ * elements. The default collects ALL direct assigned elements; the `items`
1661
+ * getter then filters by `isFocusable` at access time so that elements
1662
+ * toggling `disabled` are reflected without a new `slotchange`.
1663
+ */
1664
+ _collectItems(i) {
1665
+ return i.assignedElements();
1666
+ }
1667
+ _handleItemFocus(i) {
1668
+ const s = i.composedPath().find((n) => this.items.includes(n));
1669
+ s != null && (this._lastFocused = s, this.items.forEach((n) => n.setAttribute("tabindex", "-1")), s.setAttribute("tabindex", "0"));
1670
+ }
1671
+ _onSlotChange(i) {
1672
+ const s = this._items;
1673
+ this._items = this._collectItems(i.currentTarget).map(
1674
+ (n) => new WeakRef(n)
1675
+ ), queueMicrotask(() => {
1676
+ this.isConnected && (s.forEach((n) => n.deref()?.removeAttribute("tabindex")), this._initItems());
1677
+ });
1678
+ }
1679
+ /**
1680
+ * Called after slot contents change and the item list is rebuilt.
1681
+ * Override to configure items (set ARIA roles, move focus, etc.).
1682
+ *
1683
+ * Default implementation sets `tabindex="-1"` on all collected elements
1684
+ * (including currently-disabled ones, so they don't enter the tab order
1685
+ * if re-enabled before the next slotchange) and `tabindex="0"` on the
1686
+ * first currently-focusable item.
1687
+ */
1688
+ _initItems() {
1689
+ this._items.forEach((s) => s.deref()?.setAttribute("tabindex", "-1"));
1690
+ const i = this.items[0];
1691
+ i && i.setAttribute("tabindex", "0");
1692
+ }
1693
+ }
1694
+ return q([
1695
+ M()
1696
+ ], t.prototype, "_lastFocused"), t;
1697
+ }
1698
+ function gt(o, t, e, i) {
1699
+ const s = Math.min(Math.max(o, t), e);
1700
+ if (i <= 0) return s;
1701
+ const n = Math.round((s - t) / i) * i + t;
1702
+ return Math.min(Math.max(n, t), e);
1703
+ }
1704
+ function vt(o, t, e) {
1705
+ return e === t ? 0 : Math.min(Math.max((o - t) / (e - t), 0), 1);
1706
+ }
1707
+ function bt(o, t) {
1708
+ let e = -1, i = 1 / 0;
1709
+ return o.forEach((s, n) => {
1710
+ const r = Math.abs(s - t);
1711
+ Number.isFinite(s) && r < i && (e = n, i = r);
1712
+ }), e;
1713
+ }
1714
+ function yt(o, t, e) {
1715
+ if (e > 0) {
1716
+ const i = o.findIndex((s) => Number.isFinite(s) && s > t);
1717
+ return i >= 0 ? i : o.length - 1;
1718
+ }
1719
+ for (let i = o.length - 1; i >= 0; i -= 1)
1720
+ if (Number.isFinite(o[i]) && o[i] < t)
1721
+ return i;
1722
+ return o.length > 0 ? 0 : -1;
1723
+ }
1724
+ function wt(o, t) {
1725
+ return o.length === 0 ? -1 : t > 0 ? o.length - 1 : 0;
1726
+ }
1727
+ export {
1728
+ et as ActiveDescendantController,
1729
+ ht as AnchorController,
1730
+ it as ClickDelegateController,
1731
+ z as DEFAULT_INTERACTIVE_SELECTOR,
1732
+ rt as DragController,
1733
+ S as DragGestureController,
1734
+ T as ItemsCollectionController,
1735
+ ct as MutationObserverController,
1736
+ ft as NativeChildController,
1737
+ _t as NavigationIndicatorController,
1738
+ Y as RafScheduler,
1739
+ at as ResizeController,
1740
+ mt as RovingTabIndexMixin,
1741
+ lt as ScrollObserverController,
1742
+ dt as TypeaheadController,
1743
+ F as delegateClickTo,
1744
+ wt as findExtremeSnapIndex,
1745
+ ut as findNearestScrollAncestor,
1746
+ bt as findNearestSnapIndex,
1747
+ yt as findNextSnapIndex,
1748
+ G as getDirectChild,
1749
+ U as getDirectChildren,
1750
+ k as getVisualViewportBounds,
1751
+ O as isEventFromInteractiveDescendant,
1752
+ K as isFocusable,
1753
+ st as keyInteraction,
1754
+ nt as keyNavigation,
1755
+ ot as mouseMove,
1756
+ B as pinElementBox,
1757
+ gt as snapToStep,
1758
+ vt as valueToPercent,
1759
+ pt as warnMissingDirectChild
1760
+ };