@rcarls/rc-common 0.3.2 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rc-common.js CHANGED
@@ -1,11 +1,11 @@
1
- import { nothing as y } from "lit";
2
- import { PartType as w } from "lit/directive.js";
3
- import { directive as x, AsyncDirective as E } from "lit/async-directive.js";
4
- import { state as P } from "lit/decorators.js";
5
- let k = 0;
6
- class U {
1
+ import { nothing as g } from "lit";
2
+ import { PartType as b } from "lit/directive.js";
3
+ import { directive as v, AsyncDirective as y } from "lit/async-directive.js";
4
+ import { state as A } from "lit/decorators.js";
5
+ let C = 0;
6
+ class X {
7
7
  constructor(t, e) {
8
- this._activeItem = null, this._activeIndex = -1, this._itemCounter = 0, this._opts = e, this._instanceId = `rc-adc-${++k}`, t.addController(this);
8
+ this._activeItem = null, this._activeIndex = -1, this._itemCounter = 0, this._opts = e, this._instanceId = `rc-adc-${++C}`, t.addController(this);
9
9
  }
10
10
  hostConnected() {
11
11
  }
@@ -30,10 +30,10 @@ class U {
30
30
  const i = this._opts.wrap ?? !0;
31
31
  let s = this._activeIndex < 0 ? t > 0 ? -1 : e.length : this._activeIndex;
32
32
  const n = e.length;
33
- let o = 0;
33
+ let r = 0;
34
34
  do
35
- if (s += t, i ? s = (s % n + n) % n : s = Math.max(0, Math.min(n - 1, s)), o++, !this._isSkipped(e[s])) break;
36
- while (o < n);
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
37
  this._setActive(e[s] ?? null, s);
38
38
  }
39
39
  /** Move the virtual cursor to the first non-skipped item. */
@@ -86,7 +86,7 @@ class U {
86
86
  }
87
87
  }
88
88
  }
89
- class V {
89
+ class N {
90
90
  constructor(t, e) {
91
91
  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._onPointerDown = (i) => {
92
92
  const s = i.target;
@@ -94,8 +94,8 @@ class V {
94
94
  const n = s.closest("li[data-value]");
95
95
  if (!n || n.getAttribute("role") !== "option" || n.parentElement !== this._ul) return;
96
96
  i.preventDefault(), i.stopPropagation();
97
- const o = this.optionForElement(n);
98
- o && this._onActivate(o);
97
+ const r = this.optionForElement(n);
98
+ r && this._onActivate(r);
99
99
  }, this._host = t, this._idPrefix = e.idPrefix, this._onInitFromDom = e.onInitFromDom, this._onActivate = e.onActivate, t.addController(this);
100
100
  }
101
101
  hostConnected() {
@@ -204,8 +204,8 @@ class V {
204
204
  if (e.length === 0) return;
205
205
  const i = [];
206
206
  for (let s = 0; s < e.length; s++) {
207
- const n = e[s], o = n.getAttribute("data-value") ?? n.getAttribute("value") ?? n.textContent?.trim() ?? "", a = n.textContent?.trim() ?? "", l = n.hasAttribute("disabled") || n.getAttribute("aria-disabled") === "true";
208
- i.push({ value: o, label: a, disabled: l }), n.setAttribute("role", "option"), n.setAttribute("id", `${this._idPrefix}-${s}`), n.setAttribute("part", "option"), n.setAttribute("data-value", o), n.setAttribute("aria-selected", this._selectedValues.has(o) ? "true" : "false"), n.setAttribute("aria-disabled", l ? "true" : "false"), this._checkmark && this._ensureCheckmark(n);
207
+ const n = e[s], r = n.getAttribute("data-value") ?? n.getAttribute("value") ?? n.textContent?.trim() ?? "", a = n.textContent?.trim() ?? "", l = n.hasAttribute("disabled") || n.getAttribute("aria-disabled") === "true";
208
+ i.push({ value: r, label: a, disabled: l }), 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", l ? "true" : "false"), this._checkmark && this._ensureCheckmark(n);
209
209
  }
210
210
  this._options = i, this._liElements = e, this._onInitFromDom?.(i);
211
211
  }
@@ -268,7 +268,7 @@ class V {
268
268
  return typeof this._filterStrategy == "function" ? this._filterStrategy(e, i) : this._filterStrategy === "contains" ? e.includes(i) : e.startsWith(i);
269
269
  }
270
270
  }
271
- class T extends E {
271
+ class k extends y {
272
272
  constructor(t) {
273
273
  if (super(t), this._options = {}, this._isPointerFocus = !1, this._onPointerdown = () => {
274
274
  this._isPointerFocus = !0, this._target?.removeAttribute("data-interaction-mode");
@@ -276,7 +276,7 @@ class T extends E {
276
276
  this._isPointerFocus ? this._isPointerFocus = !1 : this._target?.setAttribute("data-interaction-mode", "keyboard");
277
277
  }, this._onKeydown = () => {
278
278
  this._target?.setAttribute("data-interaction-mode", "keyboard");
279
- }, t.type !== w.ELEMENT)
279
+ }, t.type !== b.ELEMENT)
280
280
  throw new Error("The `keyInteraction` directive must be used on an element.");
281
281
  }
282
282
  get _target() {
@@ -287,7 +287,7 @@ class T extends E {
287
287
  t instanceof HTMLElement && (t.addEventListener("pointerdown", this._onPointerdown, { capture: !0 }), t.addEventListener("focusin", this._onFocusin), t.addEventListener("keydown", this._onKeydown));
288
288
  }
289
289
  render(t) {
290
- return y;
290
+ return g;
291
291
  }
292
292
  update(t, [e]) {
293
293
  this.isConnected && this._element?.deref() === void 0 && (this._element = new WeakRef(t.element), this._init()), this._options = e ?? {};
@@ -300,10 +300,10 @@ class T extends E {
300
300
  this._init();
301
301
  }
302
302
  }
303
- const Y = x(T);
304
- class M extends E {
303
+ const K = v(k);
304
+ class T extends y {
305
305
  constructor(t) {
306
- if (super(t), this._options = {}, t.type !== w.ELEMENT)
306
+ if (super(t), this._options = {}, t.type !== b.ELEMENT)
307
307
  throw new Error(
308
308
  "The `keyNavigation` directive must be used on an element."
309
309
  );
@@ -342,9 +342,9 @@ class M extends E {
342
342
  }
343
343
  }
344
344
  _onKeydown(t) {
345
- const e = this._normalizeKey(t.key), i = this.navigationAxis, s = this._element?.deref(), n = i === "horizontal" && s != null && getComputedStyle(s).direction === "rtl", o = i === "horizontal" ? n ? "ArrowLeft" : "ArrowRight" : "ArrowDown", a = i === "horizontal" ? n ? "ArrowRight" : "ArrowLeft" : "ArrowUp", l = i === "horizontal" ? "ArrowDown" : "ArrowRight", c = i === "horizontal" ? "ArrowUp" : "ArrowLeft";
345
+ 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", l = i === "horizontal" ? "ArrowDown" : "ArrowRight", _ = i === "horizontal" ? "ArrowUp" : "ArrowLeft";
346
346
  let h;
347
- this._options.handleNavAxis !== !1 && (e === o ? h = t.shiftKey ? "next-large" : "next" : e === a ? h = t.shiftKey ? "prev-large" : "prev" : e === "Home" ? h = "start" : e === "End" && (h = "end")), !h && this._options.handleOpenAxis && (e === l ? h = "open-to-first" : e === c && (h = "open-to-last")), h || (e === "Enter" ? h = this._options.handleActivate ? "activate" : "toggle" : e === " " && this._options.handleActivate ? h = "activate" : e === "Escape" && this._options.handleEscape && (h = "escape")), h != null && (this._callback(h), t.stopPropagation(), t.preventDefault());
347
+ this._options.handleNavAxis !== !1 && (e === r ? h = t.shiftKey ? "next-large" : "next" : e === a ? h = t.shiftKey ? "prev-large" : "prev" : e === "Home" ? h = "start" : e === "End" && (h = "end")), !h && this._options.handleOpenAxis && (e === l ? h = "open-to-first" : e === _ && (h = "open-to-last")), h || (e === "Enter" ? h = this._options.handleActivate ? "activate" : "toggle" : e === " " && this._options.handleActivate ? h = "activate" : e === "Escape" && this._options.handleEscape && (h = "escape")), h != null && (this._callback(h), t.stopPropagation(), t.preventDefault());
348
348
  }
349
349
  _init() {
350
350
  const t = this._element?.deref();
@@ -357,7 +357,7 @@ class M extends E {
357
357
  * Use an options object instead.
358
358
  */
359
359
  render(t, e) {
360
- return y;
360
+ return g;
361
361
  }
362
362
  update(t, [e, i]) {
363
363
  this.isConnected && this._element?.deref() === void 0 && (this._element = new WeakRef(t.element), this._init()), this._callback = e.bind(t.options?.host ?? t.element), typeof i == "boolean" ? this._options = {} : this._options = { ...i };
@@ -370,10 +370,10 @@ class M extends E {
370
370
  this._init();
371
371
  }
372
372
  }
373
- const X = x(M);
374
- class D extends E {
373
+ const V = v(T);
374
+ class D extends y {
375
375
  constructor(t) {
376
- if (super(t), this._activePointerId = null, t.type !== w.ELEMENT)
376
+ if (super(t), this._activePointerId = null, t.type !== b.ELEMENT)
377
377
  throw new Error("The `mouseMove` directive must be used on an element.");
378
378
  this._pointerDownHandle = this._onPointerDown.bind(this), this._pointerMoveHandle = this._onPointerMove.bind(this), this._pointerEndHandle = this._onPointerEnd.bind(this);
379
379
  }
@@ -418,7 +418,7 @@ class D extends E {
418
418
  }
419
419
  /** Render no DOM; this directive only wires pointer listeners. */
420
420
  render(t) {
421
- return y;
421
+ return g;
422
422
  }
423
423
  update(t, [e]) {
424
424
  if (this._callback = e.bind(t.options?.host ?? t.element), !this.isConnected || !(t.element instanceof HTMLElement)) return;
@@ -433,14 +433,149 @@ class D extends E {
433
433
  this._init();
434
434
  }
435
435
  }
436
- const j = x(D);
436
+ const j = v(D);
437
+ class E {
438
+ constructor(t, e) {
439
+ 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) => {
440
+ if (this._pointerId !== null || !i.isPrimary && i.pointerId !== 1 || i.pointerType === "mouse" && i.button !== 0 || this._options.canStart?.(i) === !1)
441
+ return;
442
+ 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;
443
+ const s = this._$target;
444
+ 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));
445
+ }, this._onPointerMove = (i) => {
446
+ 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()));
447
+ }, this._onPointerUp = (i) => {
448
+ i.pointerId === this._pointerId && (this._recordSample(i), this._activated && this._options.onEnd?.(this._detail(i)), this._finish());
449
+ }, this._onPointerCancel = (i) => {
450
+ this._cancel(i);
451
+ }, this._onLostPointerCapture = (i) => {
452
+ i.pointerId === this._pointerId && this._cancel(i);
453
+ }, this._options = {
454
+ axis: "both",
455
+ activation: "immediate",
456
+ activationDistance: 8,
457
+ axisLockRatio: 1.25,
458
+ velocityWindow: 100,
459
+ minVelocityDuration: 8,
460
+ capture: !1,
461
+ stopPropagation: !1,
462
+ preventDefault: !0,
463
+ focusOnStart: !1,
464
+ ...e
465
+ }, t.addController(this);
466
+ }
467
+ /** Updates behavior or the target resolver and safely rebinds listeners. */
468
+ setOptions(t) {
469
+ Object.assign(this._options, t), this._bindTarget();
470
+ }
471
+ hostConnected() {
472
+ this._bindTarget();
473
+ }
474
+ hostUpdated() {
475
+ this._bindTarget();
476
+ }
477
+ hostDisconnected() {
478
+ this._unbindTarget();
479
+ }
480
+ _resolveTarget() {
481
+ const t = typeof this._options.target == "function" ? this._options.target() : this._options.target;
482
+ return t instanceof HTMLElement ? t : null;
483
+ }
484
+ _bindTarget() {
485
+ const t = this._resolveTarget();
486
+ t !== this._$target && (this._unbindTarget(), this._$target = t, this._$target?.addEventListener("pointerdown", this._onPointerDown, {
487
+ capture: this._options.capture
488
+ }));
489
+ }
490
+ _unbindTarget() {
491
+ this._$target && (this._$target.removeEventListener("pointerdown", this._onPointerDown, {
492
+ capture: this._options.capture
493
+ }), this._removeCycleListeners(this._$target), this._reset(), this._$target = null);
494
+ }
495
+ _resolveIntent(t) {
496
+ const e = t.clientX - this._startX, i = t.clientY - this._startY;
497
+ if (Math.hypot(e, i) < this._options.activationDistance)
498
+ return !1;
499
+ const { axis: n, axisLockRatio: r } = this._options, a = Math.abs(e), l = Math.abs(i);
500
+ return n === "x" && a < l * r || n === "y" && l < a * r ? (this._rejected = !0, this._finish(), !1) : (this._activate(t), !0);
501
+ }
502
+ _activate(t) {
503
+ const e = this._$target;
504
+ !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)));
505
+ }
506
+ _cancel(t) {
507
+ t.pointerId === this._pointerId && (this._activated && this._options.onCancel?.(this._detail(t)), this._finish());
508
+ }
509
+ _finish() {
510
+ const t = this._$target, e = this._pointerId;
511
+ t && (this._removeCycleListeners(t), e !== null && this._releasePointer(t, e)), this._reset();
512
+ }
513
+ _removeCycleListeners(t) {
514
+ t.removeEventListener("pointermove", this._onPointerMove), t.removeEventListener("pointerup", this._onPointerUp), t.removeEventListener("pointercancel", this._onPointerCancel), t.removeEventListener("lostpointercapture", this._onLostPointerCapture);
515
+ }
516
+ _recordSample(t) {
517
+ this._samples.push({ x: t.clientX, y: t.clientY, time: t.timeStamp });
518
+ const e = t.timeStamp - this._options.velocityWindow;
519
+ for (; this._samples.length > 2 && this._samples[0].time < e; )
520
+ this._samples.shift();
521
+ }
522
+ _detail(t) {
523
+ const e = this._samples[0], i = this._samples.at(-1) ?? e, s = i.time - e.time, n = s >= this._options.minVelocityDuration;
524
+ return {
525
+ event: t,
526
+ pointerId: t.pointerId,
527
+ pointerType: t.pointerType,
528
+ startX: this._startX,
529
+ startY: this._startY,
530
+ x: t.clientX,
531
+ y: t.clientY,
532
+ deltaX: t.clientX - this._startX,
533
+ deltaY: t.clientY - this._startY,
534
+ duration: Math.max(0, t.timeStamp - this._startTime),
535
+ velocityX: n ? (i.x - e.x) / s * 1e3 : 0,
536
+ velocityY: n ? (i.y - e.y) / s * 1e3 : 0
537
+ };
538
+ }
539
+ _capturePointer(t, e) {
540
+ try {
541
+ t.setPointerCapture(e);
542
+ } catch (i) {
543
+ if (!(i instanceof DOMException) || i.name !== "NotFoundError")
544
+ throw i;
545
+ }
546
+ }
547
+ _releasePointer(t, e) {
548
+ try {
549
+ t.hasPointerCapture(e) && t.releasePointerCapture(e);
550
+ } catch {
551
+ }
552
+ }
553
+ _reset() {
554
+ this._pointerId = null, this._samples = [], this._activated = !1, this._rejected = !1;
555
+ }
556
+ }
437
557
  class q {
438
558
  constructor(t, e) {
439
- this._dragging = !1, this._startX = 0, this._startY = 0, this._startLeft = 0, this._startTop = 0, this._opts = { axis: "both", step: 4, disabled: !1, handle: null, bounds: "viewport", ...e }, this._onPointerDown = this._handlePointerDown.bind(this), this._onPointerMove = this._handlePointerMove.bind(this), this._onPointerUp = this._handlePointerUp.bind(this), this._onPointerCancel = this._cancelDrag.bind(this), this._onLostPointerCapture = this._handleLostPointerCapture.bind(this), this._onKeyDown = this._handleKeyDown.bind(this), t.addController(this);
559
+ this._dragging = !1, this._startLeft = 0, this._startTop = 0, this._opts = {
560
+ axis: "both",
561
+ step: 4,
562
+ disabled: !1,
563
+ handle: null,
564
+ bounds: "viewport",
565
+ ...e
566
+ }, this._onKeyDown = this._handleKeyDown.bind(this), this._gesture = new E(t, {
567
+ target: () => this._handle(),
568
+ axis: this._opts.axis,
569
+ canStart: (i) => this._canStartGesture(i),
570
+ onStart: (i) => this._startDrag(i),
571
+ onMove: (i) => this._moveDrag(i),
572
+ onEnd: () => this._finishDrag(),
573
+ onCancel: () => this._finishDrag()
574
+ }), t.addController(this);
440
575
  }
441
576
  setOptions(t) {
442
577
  const e = this._handle();
443
- Object.assign(this._opts, t);
578
+ Object.assign(this._opts, t), this._gesture.setOptions({ axis: this._opts.axis, target: () => this._handle() });
444
579
  const i = this._handle();
445
580
  e !== i && (this._detachFrom(e), this._attachTo(i));
446
581
  }
@@ -457,66 +592,63 @@ class q {
457
592
  return this._opts.target;
458
593
  }
459
594
  _attachTo(t) {
460
- t.addEventListener("pointerdown", this._onPointerDown), t.addEventListener("keydown", this._onKeyDown), t.hasAttribute("tabindex") || t.setAttribute("tabindex", "0");
595
+ t.addEventListener("keydown", this._onKeyDown), t.hasAttribute("tabindex") || t.setAttribute("tabindex", "0");
461
596
  }
462
597
  _detachFrom(t) {
463
- t.removeEventListener("pointerdown", this._onPointerDown), t.removeEventListener("keydown", this._onKeyDown), t.removeEventListener("pointermove", this._onPointerMove), t.removeEventListener("pointerup", this._onPointerUp), t.removeEventListener("pointercancel", this._onPointerCancel), t.removeEventListener("lostpointercapture", this._onLostPointerCapture);
464
- }
465
- _handlePointerDown(t) {
466
- if (this._opts.disabled || t.target.closest('button, [role="button"], a')) return;
467
- const e = this._target(), i = e.getBoundingClientRect();
468
- 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._startX = t.clientX, this._startY = t.clientY, this._startLeft = i.left, this._startTop = i.top, this._dragging = !0;
469
- const s = this._handle();
470
- s.setPointerCapture(t.pointerId), s.addEventListener("pointermove", this._onPointerMove), s.addEventListener("pointerup", this._onPointerUp), s.addEventListener("pointercancel", this._onPointerCancel), s.addEventListener("lostpointercapture", this._onLostPointerCapture), t.preventDefault();
598
+ t.removeEventListener("keydown", this._onKeyDown);
471
599
  }
472
- _handlePointerMove(t) {
473
- if (!this._dragging) return;
474
- const e = this._target(), { axis: i } = this._opts, [s, n, o, a] = this._boundsRect(), l = i !== "y" ? Math.min(Math.max(this._startLeft + t.clientX - this._startX, s), o - e.offsetWidth) : parseFloat(e.style.left) || 0, c = i !== "x" ? Math.min(Math.max(this._startTop + t.clientY - this._startY, n), a - e.offsetHeight) : parseFloat(e.style.top) || 0;
475
- e.style.left = `${l}px`, e.style.top = `${c}px`;
600
+ _canStartGesture(t) {
601
+ return this._opts.disabled ? !1 : !t.target.closest('button, [role="button"], a');
476
602
  }
477
- _handlePointerUp(t) {
478
- this._cancelDrag();
603
+ _startDrag(t) {
604
+ const e = this._target(), i = e.getBoundingClientRect();
605
+ 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;
479
606
  }
480
- _handleLostPointerCapture(t) {
481
- this._cancelDrag();
607
+ _moveDrag(t) {
608
+ if (!this._dragging)
609
+ return;
610
+ const e = this._target(), { axis: i } = this._opts, [s, n, r, a] = this._boundsRect(), l = i !== "y" ? Math.min(Math.max(this._startLeft + t.deltaX, s), r - e.offsetWidth) : parseFloat(e.style.left) || 0, _ = i !== "x" ? Math.min(Math.max(this._startTop + t.deltaY, n), a - e.offsetHeight) : parseFloat(e.style.top) || 0;
611
+ e.style.left = `${l}px`, e.style.top = `${_}px`;
482
612
  }
483
- _cancelDrag() {
484
- if (!this._dragging) return;
485
- this._dragging = !1;
486
- const t = this._handle();
487
- t.removeEventListener("pointermove", this._onPointerMove), t.removeEventListener("pointerup", this._onPointerUp), t.removeEventListener("pointercancel", this._onPointerCancel), t.removeEventListener("lostpointercapture", this._onLostPointerCapture);
613
+ _finishDrag() {
614
+ this._dragging && (this._dragging = !1);
488
615
  }
489
616
  _handleKeyDown(t) {
490
- if (this._opts.disabled || t.currentTarget !== t.target) return;
617
+ if (this._opts.disabled || t.currentTarget !== t.target)
618
+ return;
491
619
  const { axis: e } = this._opts, i = t.shiftKey ? this._opts.step * 10 : this._opts.step;
492
620
  let s = 0, n = 0;
493
621
  switch (t.key) {
494
622
  case "ArrowLeft":
495
- if (e === "y") return;
623
+ if (e === "y")
624
+ return;
496
625
  s = -i;
497
626
  break;
498
627
  case "ArrowRight":
499
- if (e === "y") return;
628
+ if (e === "y")
629
+ return;
500
630
  s = i;
501
631
  break;
502
632
  case "ArrowUp":
503
- if (e === "x") return;
633
+ if (e === "x")
634
+ return;
504
635
  n = -i;
505
636
  break;
506
637
  case "ArrowDown":
507
- if (e === "x") return;
638
+ if (e === "x")
639
+ return;
508
640
  n = i;
509
641
  break;
510
642
  default:
511
643
  return;
512
644
  }
513
- const o = this._target();
514
- if (getComputedStyle(o).position === "static") {
515
- const _ = o.getBoundingClientRect();
516
- o.style.position = "fixed", o.style.translate = "none", o.style.left = `${_.left}px`, o.style.top = `${_.top}px`;
645
+ const r = this._target();
646
+ if (getComputedStyle(r).position === "static") {
647
+ const c = r.getBoundingClientRect();
648
+ r.style.position = "fixed", r.style.translate = "none", r.style.left = `${c.left}px`, r.style.top = `${c.top}px`;
517
649
  }
518
- const [a, l, c, h] = this._boundsRect(), p = parseFloat(o.style.left) || 0, d = parseFloat(o.style.top) || 0;
519
- o.style.left = `${Math.min(Math.max(p + s, a), c - o.offsetWidth)}px`, o.style.top = `${Math.min(Math.max(d + n, l), h - o.offsetHeight)}px`, t.preventDefault(), t.stopPropagation();
650
+ const [a, l, _, h] = this._boundsRect(), u = parseFloat(r.style.left) || 0, d = parseFloat(r.style.top) || 0;
651
+ r.style.left = `${Math.min(Math.max(u + s, a), _ - r.offsetWidth)}px`, r.style.top = `${Math.min(Math.max(d + n, l), h - r.offsetHeight)}px`, t.preventDefault(), t.stopPropagation();
520
652
  }
521
653
  _boundsRect() {
522
654
  const { bounds: t } = this._opts;
@@ -524,7 +656,8 @@ class q {
524
656
  return [0, 0, window.innerWidth, window.innerHeight];
525
657
  if (t === "parent") {
526
658
  const i = this._opts.target.parentElement;
527
- if (!i) return [0, 0, window.innerWidth, window.innerHeight];
659
+ if (!i)
660
+ return [0, 0, window.innerWidth, window.innerHeight];
528
661
  const s = i.getBoundingClientRect();
529
662
  return [s.left, s.top, s.right, s.bottom];
530
663
  }
@@ -532,9 +665,13 @@ class q {
532
665
  return [e.left, e.top, e.right, e.bottom];
533
666
  }
534
667
  }
535
- class G {
668
+ function P(o) {
669
+ const t = o.getBoundingClientRect();
670
+ 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 = `${t.left}px`, o.style.top = `${t.top}px`, o.style.width = `${t.width}px`, o.style.height = `${t.height}px`, t;
671
+ }
672
+ class U {
536
673
  constructor(t, e) {
537
- this._resizing = null, this._startX = 0, this._startY = 0, this._startW = 0, this._startH = 0, this._startLeft = 0, this._startTop = 0, this._effectiveMinW = 0, this._effectiveMinH = 0, this._cornerBtn = null, this._opts = {
674
+ 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 = {
538
675
  direction: "none",
539
676
  threshold: 8,
540
677
  step: 4,
@@ -542,27 +679,57 @@ class G {
542
679
  minWidth: 100,
543
680
  minHeight: 60,
544
681
  handle: null,
682
+ origin: "",
545
683
  bounds: "viewport",
546
684
  ...e
547
- }, this._onPointerMove = this._handlePointerMove.bind(this), this._onPointerDown = this._handlePointerDown.bind(this), this._onPointerUp = this._handlePointerUp.bind(this), this._onPointerLeave = this._handlePointerLeave.bind(this), this._onKeyDown = this._handleKeyDown.bind(this), t.addController(this);
685
+ }, this._onPointerMove = this._handlePointerMove.bind(this), this._onPointerLeave = this._handlePointerLeave.bind(this), this._onKeyDown = this._handleKeyDown.bind(this), this._gesture = new E(t, {
686
+ target: () => this._handle() ?? this._target(),
687
+ capture: !0,
688
+ stopPropagation: !0,
689
+ canStart: (i) => this._canStartGesture(i),
690
+ onStart: (i) => this._startGestureResize(i),
691
+ onMove: (i) => this._moveGestureResize(i),
692
+ onEnd: (i) => this._endGestureResize(i),
693
+ onCancel: () => this._cancelResize()
694
+ }), t.addController(this);
548
695
  }
549
696
  setOptions(t) {
550
- Object.assign(this._opts, t);
697
+ const e = this._opts.handle;
698
+ 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));
551
699
  }
552
700
  hostConnected() {
553
- if (this._opts.direction === "none") return;
701
+ if (this._opts.direction === "none")
702
+ return;
703
+ if (this._opts.handle) {
704
+ this._attachToHandle(this._opts.handle);
705
+ return;
706
+ }
554
707
  const t = this._target();
555
- t.addEventListener("pointermove", this._onPointerMove), t.addEventListener("pointerdown", this._onPointerDown, { capture: !0 }), t.addEventListener("pointerup", this._onPointerUp), t.addEventListener("pointerleave", this._onPointerLeave), this._injectCornerButton();
708
+ t.addEventListener("pointermove", this._onPointerMove), t.addEventListener("pointerleave", this._onPointerLeave), this._injectCornerButton();
556
709
  }
557
710
  hostDisconnected() {
711
+ if (this._opts.handle) {
712
+ this._detachFromHandle(this._opts.handle);
713
+ return;
714
+ }
558
715
  const t = this._target();
559
- t.removeEventListener("pointermove", this._onPointerMove), t.removeEventListener("pointerdown", this._onPointerDown, { capture: !0 }), t.removeEventListener("pointerup", this._onPointerUp), t.removeEventListener("pointerleave", this._onPointerLeave), this._removeCornerButton();
716
+ t.removeEventListener("pointermove", this._onPointerMove), t.removeEventListener("pointerleave", this._onPointerLeave), this._removeCornerButton();
560
717
  }
561
718
  _target() {
562
719
  return this._opts.target;
563
720
  }
721
+ _handle() {
722
+ return this._opts.handle;
723
+ }
724
+ _attachToHandle(t) {
725
+ !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"));
726
+ }
727
+ _detachFromHandle(t) {
728
+ t && t.removeEventListener("keydown", this._onKeyDown);
729
+ }
564
730
  _injectCornerButton() {
565
- if (this._opts.handle) return;
731
+ if (this._opts.handle)
732
+ return;
566
733
  const t = this._target();
567
734
  getComputedStyle(t).position === "static" && (t.style.position = "relative");
568
735
  const e = document.createElement("button");
@@ -606,106 +773,226 @@ class G {
606
773
  sw: "sw-resize"
607
774
  }[t];
608
775
  }
776
+ _handleEdge() {
777
+ return this._edgeForOrigin(this._opts.origin) ?? this._defaultHandleEdge();
778
+ }
779
+ _defaultHandleEdge() {
780
+ switch (this._opts.direction) {
781
+ case "both":
782
+ return "se";
783
+ case "horizontal":
784
+ return "e";
785
+ case "vertical":
786
+ return "s";
787
+ default:
788
+ return "se";
789
+ }
790
+ }
791
+ _edgeForOrigin(t) {
792
+ if (!t)
793
+ return null;
794
+ const e = t.includes("top"), i = t.includes("bottom"), s = t.includes("left"), n = t.includes("right");
795
+ if (this._opts.direction === "vertical")
796
+ return e ? "n" : i ? "s" : null;
797
+ if (this._opts.direction === "horizontal")
798
+ return s ? "w" : n ? "e" : null;
799
+ if (this._opts.direction === "both") {
800
+ if (e && s)
801
+ return "nw";
802
+ if (e && n)
803
+ return "ne";
804
+ if (i && s)
805
+ return "sw";
806
+ if (i && n)
807
+ return "se";
808
+ if (e)
809
+ return "n";
810
+ if (i)
811
+ return "s";
812
+ if (s)
813
+ return "w";
814
+ if (n)
815
+ return "e";
816
+ }
817
+ return null;
818
+ }
819
+ _edgeAllowsPointer(t, e) {
820
+ const { threshold: i } = this._opts, s = this._target().getBoundingClientRect(), n = e.clientX, r = e.clientY, a = n >= s.right - i && n <= s.right + i, l = n >= s.left - i && n <= s.left + i, _ = r >= s.bottom - i && r <= s.bottom + i, h = r >= s.top - i && r <= s.top + i, u = n >= s.left && n <= s.right, d = r >= s.top && r <= s.bottom;
821
+ switch (t) {
822
+ case "n":
823
+ return h && u;
824
+ case "s":
825
+ return _ && u;
826
+ case "e":
827
+ return a && d;
828
+ case "w":
829
+ return l && d;
830
+ case "ne":
831
+ return h && a;
832
+ case "nw":
833
+ return h && l;
834
+ case "se":
835
+ return _ && a;
836
+ case "sw":
837
+ return _ && l;
838
+ }
839
+ }
609
840
  _detectEdge(t) {
610
841
  const { direction: e, threshold: i } = this._opts;
611
- if (e === "none") return null;
612
- const s = this._target().getBoundingClientRect(), n = t.clientX, o = t.clientY, a = n >= s.right - i && n <= s.right + i, l = n >= s.left - i && n <= s.left + i, c = o >= s.bottom - i && o <= s.bottom + i, h = o >= s.top - i && o <= s.top + i, p = n >= s.left && n <= s.right, d = o >= s.top && o <= s.bottom;
842
+ if (e === "none")
843
+ return null;
844
+ const s = this._edgeForOrigin(this._opts.origin);
845
+ if (s)
846
+ return this._edgeAllowsPointer(s, t) ? s : null;
847
+ const n = this._target().getBoundingClientRect(), r = t.clientX, a = t.clientY, l = r >= n.right - i && r <= n.right + i, _ = r >= n.left - i && r <= n.left + i, h = a >= n.bottom - i && a <= n.bottom + i, u = a >= n.top - i && a <= n.top + i, d = r >= n.left && r <= n.right, c = a >= n.top && a <= n.bottom;
613
848
  if (e === "both") {
614
- if (a && c) return "se";
615
- if (l && c) return "sw";
616
- if (a && h) return "ne";
617
- if (l && h) return "nw";
618
- if (a && d) return "e";
619
- if (l && d) return "w";
620
- if (c && p) return "s";
621
- if (h && p) return "n";
849
+ if (l && h)
850
+ return "se";
851
+ if (_ && h)
852
+ return "sw";
853
+ if (l && u)
854
+ return "ne";
855
+ if (_ && u)
856
+ return "nw";
857
+ if (l && c)
858
+ return "e";
859
+ if (_ && c)
860
+ return "w";
861
+ if (h && d)
862
+ return "s";
863
+ if (u && d)
864
+ return "n";
622
865
  }
623
866
  if (e === "horizontal") {
624
- if (a && d) return "e";
625
- if (l && d) return "w";
867
+ if (l && c)
868
+ return "e";
869
+ if (_ && c)
870
+ return "w";
626
871
  }
627
872
  if (e === "vertical") {
628
- if (c && p) return "s";
629
- if (h && p) return "n";
873
+ if (h && d)
874
+ return "s";
875
+ if (u && d)
876
+ return "n";
630
877
  }
631
878
  return null;
632
879
  }
880
+ _pinPosition(t) {
881
+ return P(t);
882
+ }
883
+ _canStartGesture(t) {
884
+ if (this._opts.disabled)
885
+ return !1;
886
+ const i = this._handle() ? this._handleEdge() : this._detectEdge(t);
887
+ return this._pendingEdge = i, i !== null;
888
+ }
889
+ _startGestureResize(t) {
890
+ this._pendingEdge && (this._velocityX = 0, this._velocityY = 0, this._startResize(this._pendingEdge));
891
+ }
892
+ _moveGestureResize(t) {
893
+ 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")));
894
+ }
895
+ _endGestureResize(t) {
896
+ this._velocityX = t.velocityX, this._velocityY = t.velocityY, this._finishResize("pointer");
897
+ }
898
+ _startResize(t) {
899
+ const e = this._target(), i = this._pinPosition(e);
900
+ this._startW = i.width, this._startH = i.height, this._startLeft = i.left, this._startTop = i.top, this._lastDeltaX = 0, this._lastDeltaY = 0, this._resizing = t, this._computeEffectiveExtents(e), this._opts.onResizeStart?.(this._lifecycleDetail("pointer"));
901
+ }
633
902
  /**
634
- * Pins position and size as explicit border-box pixel values.
635
- *
636
- * Required before any resize so that:
637
- * - UA centering styles (`inset:0; margin:auto` on `<dialog>`) don't fight
638
- * explicit left/top changes on n/w edges.
639
- * - Changing width/height alone doesn't redistribute auto-margins and shift
640
- * the element for e/s edges.
641
- * - box-sizing is known, so `style.width = rect.width` is a no-op visually.
903
+ * Computed once per resize gesture (pointer-down or keyboard step) so the
904
+ * browser's enforcement of CSS min/max-width/height doesn't fight the JS
905
+ * math — otherwise a CSS-only max (e.g. a themed `max-block-size`) clips
906
+ * the rendered box while the pinned edge keeps moving, making the whole
907
+ * element appear to slide once dragged past its extent.
642
908
  */
643
- _pinPosition(t) {
644
- const e = t.getBoundingClientRect();
645
- return getComputedStyle(t).position === "static" && (t.style.position = "fixed"), t.style.translate = "none", t.style.inset = "auto", t.style.margin = "0", t.style.boxSizing = "border-box", t.style.left = `${e.left}px`, t.style.top = `${e.top}px`, t.style.width = `${e.width}px`, t.style.height = `${e.height}px`, e;
646
- }
647
- _handlePointerDown(t) {
648
- if (this._opts.disabled) return;
649
- const e = this._detectEdge(t);
650
- if (!e) return;
651
- t.stopPropagation();
652
- const i = this._target(), s = this._pinPosition(i);
653
- this._startX = t.clientX, this._startY = t.clientY, this._startW = s.width, this._startH = s.height, this._startLeft = s.left, this._startTop = s.top, this._resizing = e;
654
- const n = getComputedStyle(i);
655
- this._effectiveMinW = Math.max(this._opts.minWidth, parseFloat(n.minWidth) || 0), this._effectiveMinH = Math.max(this._opts.minHeight, parseFloat(n.minHeight) || 0), i.setPointerCapture(t.pointerId), t.preventDefault();
909
+ _computeEffectiveExtents(t) {
910
+ const e = getComputedStyle(t);
911
+ 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(
912
+ this._opts.maxWidth ?? 1 / 0,
913
+ parseFloat(e.maxWidth) || 1 / 0
914
+ ), this._effectiveMaxH = Math.min(
915
+ this._opts.maxHeight ?? 1 / 0,
916
+ parseFloat(e.maxHeight) || 1 / 0
917
+ );
918
+ }
919
+ _lifecycleDetail(t) {
920
+ const e = this._target();
921
+ return {
922
+ edge: this._resizing ?? this._handleEdge(),
923
+ inputType: t,
924
+ startWidth: this._startW,
925
+ startHeight: this._startH,
926
+ width: e.getBoundingClientRect().width,
927
+ height: e.getBoundingClientRect().height,
928
+ deltaX: this._lastDeltaX,
929
+ deltaY: this._lastDeltaY,
930
+ velocityX: t === "pointer" ? this._velocityX : 0,
931
+ velocityY: t === "pointer" ? this._velocityY : 0
932
+ };
656
933
  }
657
934
  _handlePointerMove(t) {
658
- if (this._resizing) {
659
- const s = this._target(), [n, o, a, l] = this._boundsRect(), { maxWidth: c, maxHeight: h } = this._opts, p = this._effectiveMinW, d = this._effectiveMinH, _ = t.clientX - this._startX, m = t.clientY - this._startY, u = this._resizing;
660
- if (u === "e" || u === "se" || u === "ne") {
661
- const f = Math.min(c ?? 1 / 0, a - this._startLeft);
662
- s.style.width = `${Math.min(Math.max(this._startW + _, p), f)}px`;
663
- }
664
- if (u === "w" || u === "sw" || u === "nw") {
665
- const f = this._startLeft + this._startW, g = Math.min(
666
- Math.max(this._startLeft + _, n, c !== void 0 ? f - c : -1 / 0),
667
- f - p
668
- );
669
- s.style.left = `${g}px`, s.style.width = `${f - g}px`;
670
- }
671
- if (u === "s" || u === "se" || u === "sw") {
672
- const f = Math.min(h ?? 1 / 0, l - this._startTop);
673
- s.style.height = `${Math.min(Math.max(this._startH + m, d), f)}px`;
674
- }
675
- if (u === "n" || u === "ne" || u === "nw") {
676
- const f = this._startTop + this._startH, g = Math.min(
677
- Math.max(this._startTop + m, o, h !== void 0 ? f - h : -1 / 0),
678
- f - d
679
- );
680
- s.style.top = `${g}px`, s.style.height = `${f - g}px`;
681
- }
935
+ if (this._resizing || this._opts.handle)
682
936
  return;
683
- }
684
- if (this._opts.handle) return;
685
937
  const e = this._detectEdge(t), i = this._target();
686
938
  i.style.cursor = e ? this._edgeCursor(e) : "";
687
939
  }
688
- _handlePointerUp(t) {
689
- this._resizing = null;
940
+ _finishResize(t) {
941
+ if (!this._resizing)
942
+ return;
943
+ const e = this._lifecycleDetail(t);
944
+ this._resizing = null, this._pendingEdge = null, this._opts.onResizeEnd?.(e);
945
+ }
946
+ _cancelResize() {
947
+ this._resizing = null, this._pendingEdge = null;
690
948
  }
691
949
  _handlePointerLeave(t) {
692
950
  this._resizing || (this._target().style.cursor = "");
693
951
  }
694
952
  _handleKeyDown(t) {
695
- if (this._opts.disabled) return;
953
+ if (this._opts.disabled)
954
+ return;
696
955
  const { direction: e } = this._opts, i = t.key === "ArrowRight" || t.key === "ArrowLeft", s = t.key === "ArrowDown" || t.key === "ArrowUp";
697
- if (i && e === "vertical" || s && e === "horizontal" || !i && !s) return;
956
+ if (i && e === "vertical" || s && e === "horizontal" || !i && !s)
957
+ return;
698
958
  t.preventDefault(), t.stopPropagation();
699
- const n = this._target(), o = this._pinPosition(n), a = t.shiftKey ? this._opts.step * 10 : this._opts.step, [, , l, c] = this._boundsRect(), { maxWidth: h, maxHeight: p } = this._opts, d = getComputedStyle(n), _ = Math.max(this._opts.minWidth, parseFloat(d.minWidth) || 0), m = Math.max(this._opts.minHeight, parseFloat(d.minHeight) || 0);
700
- if (t.key === "ArrowRight") {
701
- const u = Math.min(h ?? 1 / 0, l - o.left);
702
- n.style.width = `${Math.min(Math.max(n.offsetWidth + a, _), u)}px`;
959
+ const n = this._target(), r = this._pinPosition(n), a = this._keyboardEdge(t.key);
960
+ if (!a)
961
+ return;
962
+ this._resizing = a, this._startW = r.width, this._startH = r.height, this._startLeft = r.left, this._startTop = r.top;
963
+ const l = t.shiftKey ? this._opts.step * 10 : this._opts.step;
964
+ this._computeEffectiveExtents(n);
965
+ const _ = t.key === "ArrowRight" ? l : t.key === "ArrowLeft" ? -l : 0, h = t.key === "ArrowDown" ? l : t.key === "ArrowUp" ? -l : 0;
966
+ this._lastDeltaX = _, this._lastDeltaY = h, this._applyDelta(a, _, h), this._opts.onResize?.(this._lifecycleDetail("keyboard")), this._finishResize("keyboard");
967
+ }
968
+ _keyboardEdge(t) {
969
+ const e = this._edgeForOrigin(this._opts.origin);
970
+ 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);
971
+ }
972
+ _applyDelta(t, e, i) {
973
+ const s = this._target(), [n, r, a, l] = this._boundsRect(), _ = this._effectiveMinW, h = this._effectiveMinH, u = this._effectiveMaxW, d = this._effectiveMaxH;
974
+ if (t === "e" || t === "se" || t === "ne") {
975
+ const c = Math.min(u, a - this._startLeft);
976
+ s.style.width = `${Math.min(Math.max(this._startW + e, _), c)}px`;
703
977
  }
704
- if (t.key === "ArrowLeft" && (n.style.width = `${Math.max(n.offsetWidth - a, _)}px`), t.key === "ArrowDown") {
705
- const u = Math.min(p ?? 1 / 0, c - o.top);
706
- n.style.height = `${Math.min(Math.max(n.offsetHeight + a, m), u)}px`;
978
+ if (t === "w" || t === "sw" || t === "nw") {
979
+ const c = this._startLeft + this._startW, p = Math.min(
980
+ Math.max(this._startLeft + e, n, c - u),
981
+ c - _
982
+ );
983
+ s.style.left = `${p}px`, s.style.width = `${c - p}px`;
984
+ }
985
+ if (t === "s" || t === "se" || t === "sw") {
986
+ const c = Math.min(d, l - this._startTop);
987
+ s.style.height = `${Math.min(Math.max(this._startH + i, h), c)}px`;
988
+ }
989
+ if (t === "n" || t === "ne" || t === "nw") {
990
+ const c = this._startTop + this._startH, p = Math.min(
991
+ Math.max(this._startTop + i, r, c - d),
992
+ c - h
993
+ );
994
+ s.style.top = `${p}px`, s.style.height = `${c - p}px`;
707
995
  }
708
- t.key === "ArrowUp" && (n.style.height = `${Math.max(n.offsetHeight - a, m)}px`);
709
996
  }
710
997
  _boundsRect() {
711
998
  const { bounds: t } = this._opts;
@@ -713,7 +1000,8 @@ class G {
713
1000
  return [0, 0, window.innerWidth, window.innerHeight];
714
1001
  if (t === "parent") {
715
1002
  const i = this._opts.target.parentElement;
716
- if (!i) return [0, 0, window.innerWidth, window.innerHeight];
1003
+ if (!i)
1004
+ return [0, 0, window.innerWidth, window.innerHeight];
717
1005
  const s = i.getBoundingClientRect();
718
1006
  return [s.left, s.top, s.right, s.bottom];
719
1007
  }
@@ -721,9 +1009,9 @@ class G {
721
1009
  return [e.left, e.top, e.right, e.bottom];
722
1010
  }
723
1011
  }
724
- function v(r, t) {
1012
+ function f(o, t) {
725
1013
  const e = `${t}px`;
726
- switch (r) {
1014
+ switch (o) {
727
1015
  case "top":
728
1016
  return `position-area: top; margin-bottom: ${e};`;
729
1017
  case "top-start":
@@ -750,7 +1038,7 @@ function v(r, t) {
750
1038
  return `top: auto; bottom: anchor(bottom); left: anchor(right); right: auto; margin-left: ${e};`;
751
1039
  }
752
1040
  }
753
- const L = {
1041
+ const w = {
754
1042
  top: "bottom",
755
1043
  "top-start": "bottom-start",
756
1044
  "top-end": "bottom-end",
@@ -776,15 +1064,15 @@ const L = {
776
1064
  right: "right",
777
1065
  "right-start": "right-end",
778
1066
  "right-end": "right-start"
779
- }, C = CSS.supports("position-try-fallbacks: flip-block") && CSS.supports("min-width: anchor-size(width)");
780
- let A = null, b = null;
1067
+ }, L = CSS.supports("position-try-fallbacks: flip-block") && CSS.supports("min-width: anchor-size(width)");
1068
+ let x = null, m = null;
781
1069
  function I() {
782
- return C ? Promise.resolve(null) : (b || (b = import("./css-anchor-positioning-fn-hFYJeBk4.js").then((r) => (A = r.default, A)).catch(() => null)), b);
1070
+ return L ? Promise.resolve(null) : (m || (m = import("./css-anchor-positioning-fn-hFYJeBk4.js").then((o) => (x = o.default, x)).catch(() => null)), m);
783
1071
  }
784
- let $ = 0;
785
- class J {
1072
+ let M = 0;
1073
+ class G {
786
1074
  constructor(t, e) {
787
- this._styleEl = null, this._adoptedSheet = null, this._opts = e, this._uid = `rc-anchor-${++$}`, t.addController(this);
1075
+ this._styleEl = null, this._adoptedSheet = null, this._opts = e, this._uid = `rc-anchor-${++M}`, t.addController(this);
788
1076
  }
789
1077
  setOptions(t) {
790
1078
  Object.assign(this._opts, t), this._applyAndPolyfill();
@@ -812,7 +1100,7 @@ class J {
812
1100
  return typeof t == "function" ? t() : t ?? null;
813
1101
  }
814
1102
  _applyAndPolyfill() {
815
- this._apply(), C || this._applyPolyfillOrFallback();
1103
+ this._apply(), L || this._applyPolyfillOrFallback();
816
1104
  }
817
1105
  async _applyPolyfillOrFallback() {
818
1106
  const t = await I(), e = this._shadowHost();
@@ -825,24 +1113,24 @@ class J {
825
1113
  }
826
1114
  const t = this._anchor(), e = this._floating();
827
1115
  if (!t || !e) return;
828
- const i = this._opts.placement ?? "bottom-start", s = this._opts.offset ?? 4, n = this._opts.flip ?? !0, o = `--${this._uid}`, a = this._uid;
829
- t.style.setProperty("anchor-name", o), e.setAttribute("data-rc-anchor", a);
830
- const l = L[i], c = S[i], h = L[c], p = n ? `
831
- @position-try --${a}-end { ${v(c, s)} }
832
- @position-try --${a}-flip { ${v(l, s)} }
833
- @position-try --${a}-both { ${v(h, s)} }
834
- ` : "", d = n ? `position-try-fallbacks: --${a}-end, --${a}-flip, --${a}-both;` : "", _ = `
835
- ${p}
1116
+ const i = this._opts.placement ?? "bottom-start", s = this._opts.offset ?? 4, n = this._opts.flip ?? !0, r = `--${this._uid}`, a = this._uid;
1117
+ t.style.setProperty("anchor-name", r), e.setAttribute("data-rc-anchor", a);
1118
+ const l = w[i], _ = S[i], h = w[_], u = n ? `
1119
+ @position-try --${a}-end { ${f(_, s)} }
1120
+ @position-try --${a}-flip { ${f(l, s)} }
1121
+ @position-try --${a}-both { ${f(h, s)} }
1122
+ ` : "", d = n ? `position-try-fallbacks: --${a}-end, --${a}-flip, --${a}-both;` : "", c = `
1123
+ ${u}
836
1124
  [data-rc-anchor="${a}"] {
837
1125
  position: fixed;
838
- position-anchor: ${o};
1126
+ position-anchor: ${r};
839
1127
  box-sizing: border-box;
840
1128
  min-width: anchor-size(width);
841
- ${v(i, s)}
1129
+ ${f(i, s)}
842
1130
  ${d}
843
1131
  }
844
1132
  `;
845
- this._injectStyles(_);
1133
+ this._injectStyles(c);
846
1134
  }
847
1135
  _injectStyles(t) {
848
1136
  const e = this._shadowHost();
@@ -854,13 +1142,13 @@ class J {
854
1142
  _positionFallback() {
855
1143
  const t = this._anchor(), e = this._floating();
856
1144
  if (!t || !e) return;
857
- const i = this._opts.placement ?? "bottom-start", s = this._opts.offset ?? 4, n = t.getBoundingClientRect(), o = window.innerWidth, a = window.innerHeight;
1145
+ const i = this._opts.placement ?? "bottom-start", s = this._opts.offset ?? 4, n = t.getBoundingClientRect(), r = window.innerWidth, a = window.innerHeight;
858
1146
  e.style.position = "fixed", e.style.boxSizing = "border-box", e.style.minWidth = `${n.width}px`;
859
- const l = i.startsWith("bottom") || i === "bottom", c = a - n.bottom;
860
- l && c < 120 && n.top > c ? (e.style.top = "", e.style.bottom = `${a - n.top + s}px`) : (e.style.bottom = "", e.style.top = `${n.bottom + s}px`);
861
- const p = i.endsWith("-end"), d = e.offsetWidth || parseFloat(getComputedStyle(e).minWidth) || 0;
862
- let _ = p ? n.right - d : n.left;
863
- _ + d > o - 4 && (_ = n.right - d), _ = Math.max(4, Math.min(_, o - d - 4)), e.style.left = `${_}px`;
1147
+ const l = i.startsWith("bottom") || i === "bottom", _ = a - n.bottom;
1148
+ l && _ < 120 && n.top > _ ? (e.style.top = "", e.style.bottom = `${a - n.top + s}px`) : (e.style.bottom = "", e.style.top = `${n.bottom + s}px`);
1149
+ const u = i.endsWith("-end"), d = e.offsetWidth || parseFloat(getComputedStyle(e).minWidth) || 0;
1150
+ let c = u ? n.right - d : n.left;
1151
+ c + d > r - 4 && (c = n.right - d), c = Math.max(4, Math.min(c, r - d - 4)), e.style.left = `${c}px`;
864
1152
  }
865
1153
  _cleanup() {
866
1154
  const t = this._anchor(), e = this._floating();
@@ -871,7 +1159,7 @@ class J {
871
1159
  ), this._adoptedSheet = null);
872
1160
  }
873
1161
  }
874
- class Q {
1162
+ class J {
875
1163
  constructor(t, e) {
876
1164
  this._attached = null, this._scrolled = !1, this._onScroll = () => this._evaluate(), this._host = t, this._opts = e, t.addController(this);
877
1165
  }
@@ -913,7 +1201,7 @@ class Q {
913
1201
  i !== this._scrolled && (this._scrolled = i, this._opts.onChange?.(i, t), this._host.requestUpdate());
914
1202
  }
915
1203
  }
916
- class Z {
1204
+ class Q {
917
1205
  constructor(t, e) {
918
1206
  this._attached = null, this._observer = null, this._options = e, t.addController(this);
919
1207
  }
@@ -939,6 +1227,80 @@ class Z {
939
1227
  this._observer?.disconnect(), this._attached = null;
940
1228
  }
941
1229
  }
1230
+ class Z {
1231
+ constructor(t, e) {
1232
+ this._frame = 0, this._links = [], this._host = t, this._options = e, t.addController(this);
1233
+ }
1234
+ hostConnected() {
1235
+ this.sync();
1236
+ }
1237
+ hostDisconnected() {
1238
+ this._mutationObserver?.disconnect(), this._resizeObserver?.disconnect(), this._mutationObserver = void 0, this._resizeObserver = void 0, this._frame && cancelAnimationFrame(this._frame), this._frame = 0;
1239
+ }
1240
+ sync() {
1241
+ this._collectLinks(), this._observeLinks(), this.update();
1242
+ }
1243
+ update() {
1244
+ this._frame && cancelAnimationFrame(this._frame), this._frame = requestAnimationFrame(() => {
1245
+ this._frame = 0, this._positionIndicator();
1246
+ });
1247
+ }
1248
+ _collectLinks() {
1249
+ const e = this._options.slot()?.assignedElements({ flatten: !0 }) ?? [], i = /* @__PURE__ */ new Set();
1250
+ for (const s of e)
1251
+ s instanceof HTMLAnchorElement && i.add(s), s.querySelectorAll("a").forEach((n) => i.add(n));
1252
+ this._links = Array.from(i);
1253
+ }
1254
+ _observeLinks() {
1255
+ this._mutationObserver?.disconnect(), this._resizeObserver?.disconnect(), this._mutationObserver = new MutationObserver(() => {
1256
+ this._collectLinks(), this._observeLinks(), this.update();
1257
+ }), this._resizeObserver = new ResizeObserver(() => this.update()), this._resizeObserver.observe(this._host);
1258
+ for (const t of this._links) {
1259
+ this._mutationObserver.observe(t, {
1260
+ attributes: !0,
1261
+ attributeFilter: ["aria-current", "class", "data-active"],
1262
+ childList: !0,
1263
+ subtree: !0
1264
+ }), this._resizeObserver.observe(t);
1265
+ const e = this._targetFor(t);
1266
+ e && e !== t && this._resizeObserver.observe(e);
1267
+ }
1268
+ }
1269
+ _activeLink() {
1270
+ const t = this._options.activeSelector().trim();
1271
+ if (t) {
1272
+ const e = this._links.find((i) => i.matches(t));
1273
+ if (e)
1274
+ return e;
1275
+ }
1276
+ return this._links.find((e) => {
1277
+ const i = e.getAttribute("aria-current");
1278
+ return i !== null && i !== "" && i !== "false";
1279
+ }) ?? null;
1280
+ }
1281
+ _targetFor(t) {
1282
+ const e = this._options.indicatorTargetSelector().trim();
1283
+ if (e) {
1284
+ const i = t.matches(e) ? t : t.querySelector(e);
1285
+ if (i)
1286
+ return i;
1287
+ }
1288
+ return t.querySelector("[data-rc-navigation-indicator]") ?? t.querySelector("[data-rc-navigation-icon]") ?? t;
1289
+ }
1290
+ _positionIndicator() {
1291
+ const t = this._options.container(), e = this._options.indicator(), i = this._activeLink();
1292
+ if (this._host.toggleAttribute("has-active", !!i), !t || !e || !i) {
1293
+ e?.toggleAttribute("hidden", !0);
1294
+ return;
1295
+ }
1296
+ const s = this._targetFor(i), n = t.getBoundingClientRect(), r = s.getBoundingClientRect();
1297
+ if (!r.width || !r.height) {
1298
+ e.toggleAttribute("hidden", !0);
1299
+ return;
1300
+ }
1301
+ 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)`;
1302
+ }
1303
+ }
942
1304
  class tt {
943
1305
  constructor(t) {
944
1306
  this._callback = null, this._frame = 0, t?.addController(this);
@@ -978,9 +1340,9 @@ class et {
978
1340
  if (!e.length) return null;
979
1341
  const i = this._options.startIndex?.() ?? 0, s = e.length;
980
1342
  for (let n = 1; n <= s; n += 1) {
981
- const o = (i + n) % s, a = e[o];
1343
+ const r = (i + n) % s, a = e[r];
982
1344
  if (this._options.text(a).trim().toLocaleLowerCase().startsWith(this._buffer))
983
- return this._options.onMatch(a, o), a;
1345
+ return this._options.onMatch(a, r), a;
984
1346
  }
985
1347
  return null;
986
1348
  }
@@ -991,8 +1353,8 @@ class et {
991
1353
  this._timer && (window.clearTimeout(this._timer), this._timer = 0);
992
1354
  }
993
1355
  }
994
- function it(r) {
995
- let t = r.parentElement;
1356
+ function it(o) {
1357
+ let t = o.parentElement;
996
1358
  for (; t && t !== document.documentElement; ) {
997
1359
  const { overflow: e, overflowY: i } = getComputedStyle(t);
998
1360
  if (/auto|scroll/.test(i) || /auto|scroll/.test(e)) return t;
@@ -1000,19 +1362,19 @@ function it(r) {
1000
1362
  }
1001
1363
  return document.scrollingElement ?? document.documentElement;
1002
1364
  }
1003
- function H(r) {
1004
- return r == null || r.hasAttribute("disabled") ? !1 : !!((r instanceof HTMLAnchorElement || r instanceof HTMLAreaElement) && r.hasAttribute("href") || r instanceof HTMLButtonElement || r instanceof HTMLInputElement || r instanceof HTMLTextAreaElement || r instanceof HTMLSelectElement || r.hasAttribute("tabindex") || r.shadowRoot?.delegatesFocus === !0);
1365
+ function z(o) {
1366
+ 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);
1005
1367
  }
1006
- function F(r, t) {
1007
- return r.querySelector(t);
1368
+ function $(o, t) {
1369
+ return o.querySelector(t);
1008
1370
  }
1009
- function z(r, t) {
1010
- return Array.from(r.querySelectorAll(t));
1371
+ function H(o, t) {
1372
+ return Array.from(o.querySelectorAll(t));
1011
1373
  }
1012
- function st(r, t) {
1013
- if (z(r, t.selector).length >= (t.minimum ?? 1)) return !1;
1014
- const e = t.hostName ?? r.localName, i = t.childDescription ?? t.selector.replace(":scope > ", ""), s = t.message ?? `[${e}] No direct child ${i} found. Place ${i} inside <${e}>.`;
1015
- return console.warn(s, r), !0;
1374
+ function st(o, t) {
1375
+ if (H(o, t.selector).length >= (t.minimum ?? 1)) return !1;
1376
+ 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}>.`;
1377
+ return console.warn(s, o), !0;
1016
1378
  }
1017
1379
  class nt {
1018
1380
  constructor(t, e) {
@@ -1032,22 +1394,22 @@ class nt {
1032
1394
  }
1033
1395
  /** Re-read the child from the host and invoke `onChange` when it changes. */
1034
1396
  sync() {
1035
- const t = this._child, e = F(this._host, this._options.selector);
1397
+ const t = this._child, e = $(this._host, this._options.selector);
1036
1398
  return this._child = e, e || this._options.onMissing?.(this._host), e !== t && this._options.onChange?.(e, t), e;
1037
1399
  }
1038
1400
  }
1039
- var R = Object.defineProperty, O = (r, t, e, i) => {
1040
- for (var s = void 0, n = r.length - 1, o; n >= 0; n--)
1041
- (o = r[n]) && (s = o(t, e, s) || s);
1042
- return s && R(t, e, s), s;
1401
+ var F = Object.defineProperty, R = (o, t, e, i) => {
1402
+ for (var s = void 0, n = o.length - 1, r; n >= 0; n--)
1403
+ (r = o[n]) && (s = r(t, e, s) || s);
1404
+ return s && F(t, e, s), s;
1043
1405
  };
1044
- function ot(r) {
1045
- class t extends r {
1406
+ function ot(o) {
1407
+ class t extends o {
1046
1408
  constructor() {
1047
1409
  super(...arguments), this._items = [];
1048
1410
  }
1049
1411
  get items() {
1050
- return this._items.map((i) => i.deref()).filter((i) => H(i));
1412
+ return this._items.map((i) => i.deref()).filter((i) => z(i));
1051
1413
  }
1052
1414
  get firstItem() {
1053
1415
  return this.items.at(0);
@@ -1114,38 +1476,64 @@ function ot(r) {
1114
1476
  i && i.setAttribute("tabindex", "0");
1115
1477
  }
1116
1478
  }
1117
- return O([
1118
- P()
1479
+ return R([
1480
+ A()
1119
1481
  ], t.prototype, "_lastFocused"), t;
1120
1482
  }
1121
- function rt(r, t, e, i) {
1122
- const s = Math.min(Math.max(r, t), e);
1483
+ function rt(o, t, e, i) {
1484
+ const s = Math.min(Math.max(o, t), e);
1123
1485
  if (i <= 0) return s;
1124
1486
  const n = Math.round((s - t) / i) * i + t;
1125
1487
  return Math.min(Math.max(n, t), e);
1126
1488
  }
1127
- function at(r, t, e) {
1128
- return e === t ? 0 : Math.min(Math.max((r - t) / (e - t), 0), 1);
1489
+ function at(o, t, e) {
1490
+ return e === t ? 0 : Math.min(Math.max((o - t) / (e - t), 0), 1);
1491
+ }
1492
+ function ht(o, t) {
1493
+ let e = -1, i = 1 / 0;
1494
+ return o.forEach((s, n) => {
1495
+ const r = Math.abs(s - t);
1496
+ Number.isFinite(s) && r < i && (e = n, i = r);
1497
+ }), e;
1498
+ }
1499
+ function lt(o, t, e) {
1500
+ if (e > 0) {
1501
+ const i = o.findIndex((s) => Number.isFinite(s) && s > t);
1502
+ return i >= 0 ? i : o.length - 1;
1503
+ }
1504
+ for (let i = o.length - 1; i >= 0; i -= 1)
1505
+ if (Number.isFinite(o[i]) && o[i] < t)
1506
+ return i;
1507
+ return o.length > 0 ? 0 : -1;
1508
+ }
1509
+ function ct(o, t) {
1510
+ return o.length === 0 ? -1 : t > 0 ? o.length - 1 : 0;
1129
1511
  }
1130
1512
  export {
1131
- U as ActiveDescendantController,
1132
- J as AnchorController,
1513
+ X as ActiveDescendantController,
1514
+ G as AnchorController,
1133
1515
  q as DragController,
1134
- V as ItemsCollectionController,
1135
- Z as MutationObserverController,
1516
+ E as DragGestureController,
1517
+ N as ItemsCollectionController,
1518
+ Q as MutationObserverController,
1136
1519
  nt as NativeChildController,
1520
+ Z as NavigationIndicatorController,
1137
1521
  tt as RafScheduler,
1138
- G as ResizeController,
1522
+ U as ResizeController,
1139
1523
  ot as RovingTabIndexMixin,
1140
- Q as ScrollObserverController,
1524
+ J as ScrollObserverController,
1141
1525
  et as TypeaheadController,
1526
+ ct as findExtremeSnapIndex,
1142
1527
  it as findNearestScrollAncestor,
1143
- F as getDirectChild,
1144
- z as getDirectChildren,
1145
- H as isFocusable,
1146
- Y as keyInteraction,
1147
- X as keyNavigation,
1528
+ ht as findNearestSnapIndex,
1529
+ lt as findNextSnapIndex,
1530
+ $ as getDirectChild,
1531
+ H as getDirectChildren,
1532
+ z as isFocusable,
1533
+ K as keyInteraction,
1534
+ V as keyNavigation,
1148
1535
  j as mouseMove,
1536
+ P as pinElementBox,
1149
1537
  rt as snapToStep,
1150
1538
  at as valueToPercent,
1151
1539
  st as warnMissingDirectChild