@rcarls/rc-common 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/CHANGELOG.md +295 -0
  2. package/README.md +148 -72
  3. package/dist/modules/ActiveDescendantController.js +89 -0
  4. package/dist/modules/AnchorController.js +317 -0
  5. package/dist/modules/ControllerEffects.js +60 -0
  6. package/dist/modules/DragController.js +128 -0
  7. package/dist/modules/DragGestureController.js +174 -0
  8. package/dist/modules/FlowController.js +35 -0
  9. package/dist/modules/ItemsCollectionController.js +233 -0
  10. package/dist/modules/KeyboardInteractionDirective.js +39 -0
  11. package/dist/modules/KeyboardNavigationDirective.js +88 -0
  12. package/dist/modules/LiveAnnouncer.js +36 -0
  13. package/dist/modules/MutationObserverController.js +30 -0
  14. package/dist/modules/NavigationIndicatorController.js +81 -0
  15. package/dist/modules/PopoverController.js +44 -0
  16. package/dist/modules/RafScheduler.js +83 -0
  17. package/dist/modules/ReorderController.js +361 -0
  18. package/dist/modules/ResizeController.js +425 -0
  19. package/dist/modules/RovingTabIndexMixin.js +87 -0
  20. package/dist/modules/ScrollObserverController.js +78 -0
  21. package/dist/modules/TypeaheadController.js +59 -0
  22. package/dist/modules/anchorPlacement.js +13 -0
  23. package/dist/modules/clickDelegate.js +31 -0
  24. package/dist/modules/cssText.js +6 -0
  25. package/dist/modules/cssTime.js +11 -0
  26. package/dist/modules/cssZoom.js +16 -0
  27. package/dist/modules/findNearestScrollAncestor.js +22 -0
  28. package/dist/modules/flow.js +94 -0
  29. package/dist/modules/isFocusable.js +6 -0
  30. package/dist/modules/localeFormat.js +38 -0
  31. package/dist/modules/messages.js +77 -0
  32. package/dist/modules/nativeChild.js +37 -0
  33. package/dist/modules/observeLocale.js +70 -0
  34. package/dist/modules/sliderUtils.js +14 -0
  35. package/dist/modules/snapUtils.js +25 -0
  36. package/dist/modules/softKeyboard.js +72 -0
  37. package/dist/modules/visualViewport.js +14 -0
  38. package/dist/rc-common.js +99 -1711
  39. package/dist/rc-common.umd.cjs +10 -26
  40. package/dist/types/AnchorController.d.ts +45 -22
  41. package/dist/types/ControllerEffects.d.ts +15 -0
  42. package/dist/types/DragController.d.ts +13 -0
  43. package/dist/types/DragGestureController.d.ts +31 -7
  44. package/dist/types/FlowController.d.ts +31 -0
  45. package/dist/types/ItemsCollectionController.d.ts +3 -2
  46. package/dist/types/KeyboardInteractionDirective.d.ts +1 -2
  47. package/dist/types/KeyboardNavigationDirective.d.ts +16 -7
  48. package/dist/types/LiveAnnouncer.d.ts +22 -0
  49. package/dist/types/MutationObserverController.d.ts +0 -1
  50. package/dist/types/NavigationIndicatorController.d.ts +1 -1
  51. package/dist/types/PopoverController.d.ts +21 -0
  52. package/dist/types/RafScheduler.d.ts +36 -1
  53. package/dist/types/ReorderController.d.ts +131 -0
  54. package/dist/types/ResizeController.d.ts +46 -0
  55. package/dist/types/ScrollObserverController.d.ts +13 -2
  56. package/dist/types/TypeaheadController.d.ts +8 -2
  57. package/dist/types/anchorPlacement.d.ts +24 -0
  58. package/dist/types/clickDelegate.d.ts +9 -56
  59. package/dist/types/cssText.d.ts +17 -0
  60. package/dist/types/cssTime.d.ts +14 -0
  61. package/dist/types/cssZoom.d.ts +12 -0
  62. package/dist/types/findNearestScrollAncestor.d.ts +3 -3
  63. package/dist/types/flow.d.ts +121 -0
  64. package/dist/types/index.d.ts +13 -1
  65. package/dist/types/localeFormat.d.ts +4 -0
  66. package/dist/types/messages.d.ts +105 -0
  67. package/dist/types/nativeChild.d.ts +0 -3
  68. package/dist/types/observeLocale.d.ts +23 -0
  69. package/dist/types/softKeyboard.d.ts +79 -0
  70. package/dist/types/visualViewport.d.ts +21 -0
  71. package/package.json +1 -4
  72. package/dist/css-anchor-positioning-fn-hFYJeBk4.js +0 -6371
  73. package/dist/types/MouseMoveDirective.d.ts +0 -42
@@ -0,0 +1,174 @@
1
+ class _ {
2
+ constructor(i, e) {
3
+ this._$target = null, this._$captureTarget = null, this._pointerId = null, this._startX = 0, this._startY = 0, this._startTime = 0, this._samples = [], this._activated = !1, this._rejected = !1, this._lastEvent = null, this._boundCapture = !1, this._disposed = !1, this._onPointerDown = (t) => {
4
+ if (this._pointerId !== null || !t.isPrimary && t.pointerId !== 1 || t.pointerType === "mouse" && t.button !== 0 || this._options.canStart?.(t) === !1)
5
+ return;
6
+ this._pointerId = t.pointerId, this._startX = t.clientX, this._startY = t.clientY, this._startTime = t.timeStamp, this._lastEvent = t, this._samples = [{ x: t.clientX, y: t.clientY, time: t.timeStamp }], this._activated = !1, this._rejected = !1;
7
+ const s = this._$target;
8
+ if (!s)
9
+ return;
10
+ const n = t.composedPath()[0];
11
+ this._$captureTarget = t.pointerType === "mouse" || !(n instanceof Element) ? s : n, s.addEventListener("pointermove", this._onPointerMove), s.addEventListener("pointerup", this._onPointerUp), s.addEventListener("pointercancel", this._onPointerCancel), this._$captureTarget.addEventListener("lostpointercapture", this._onLostPointerCapture);
12
+ const o = s.ownerDocument;
13
+ o.addEventListener("lostpointercapture", this._onLostPointerCapture), o.addEventListener("pointerup", this._onDocumentPointerUp), o.addEventListener("pointercancel", this._onPointerCancel), this._options.activation === "immediate" ? this._activate(t) : this._options.activation === "press" && this._startPress(s);
14
+ }, this._onTouchMove = (t) => {
15
+ this._activated && t.cancelable && t.preventDefault();
16
+ }, this._onContextMenu = (t) => {
17
+ this._activated ? t.preventDefault() : this._finish();
18
+ }, this._onPointerMove = (t) => {
19
+ t.pointerId !== this._pointerId || this._rejected || (this._recordSample(t), this._lastEvent = t, !(!this._activated && !this._resolveIntent(t)) && (this._options.onMove?.(this._detail(t)), this._options.preventDefault && t.preventDefault()));
20
+ }, this._onPointerUp = (t) => {
21
+ t.pointerId === this._pointerId && (this._recordSample(t), this._lastEvent = t, this._activated && this._options.onEnd?.(this._detail(t)), this._finish());
22
+ }, this._onPointerCancel = (t) => {
23
+ this._cancel(t);
24
+ }, this._onDocumentPointerUp = (t) => {
25
+ if (t.pointerId === this._pointerId) {
26
+ if (this._$captureTarget && !this._$captureTarget.isConnected) {
27
+ this._cancel(t);
28
+ return;
29
+ }
30
+ this._onPointerUp(t);
31
+ }
32
+ }, this._onLostPointerCapture = (t) => {
33
+ t instanceof PointerEvent && t.pointerId === this._pointerId && (t.composedPath()[0] === this._$captureTarget || !this._$captureTarget?.isConnected) && this._cancel(t);
34
+ }, this._host = i, this._options = {
35
+ axis: "both",
36
+ activation: "immediate",
37
+ activationDistance: 8,
38
+ pressDelay: 400,
39
+ axisLockRatio: 1.25,
40
+ velocityWindow: 100,
41
+ minVelocityDuration: 8,
42
+ capture: !1,
43
+ stopPropagation: !1,
44
+ preventDefault: !0,
45
+ focusOnStart: !1,
46
+ ...e
47
+ }, i.addController(this);
48
+ }
49
+ /** Updates behavior or the target resolver, cancelling any active gesture first. */
50
+ setOptions(i) {
51
+ this._disposed || (this._pointerId !== null && this._lastEvent && this._cancel(this._lastEvent), Object.assign(this._options, i), this._bindTarget());
52
+ }
53
+ hostConnected() {
54
+ this._disposed || this._bindTarget();
55
+ }
56
+ hostUpdated() {
57
+ this._disposed || this._bindTarget();
58
+ }
59
+ hostDisconnected() {
60
+ this._unbindTarget();
61
+ }
62
+ /** Cancels an active gesture, then removes listeners and the controller permanently. */
63
+ dispose() {
64
+ this._disposed || (this._disposed = !0, this._unbindTarget(), this._host.removeController(this));
65
+ }
66
+ _resolveTarget() {
67
+ const i = typeof this._options.target == "function" ? this._options.target() : this._options.target;
68
+ return i instanceof HTMLElement ? i : null;
69
+ }
70
+ _bindTarget() {
71
+ const i = this._resolveTarget();
72
+ i === this._$target && this._boundCapture === this._options.capture || (this._unbindTarget(), this._$target = i, this._boundCapture = this._options.capture, this._$target?.addEventListener("pointerdown", this._onPointerDown, {
73
+ capture: this._boundCapture
74
+ }));
75
+ }
76
+ _unbindTarget() {
77
+ this._$target && (this._pointerId !== null && this._lastEvent && this._cancel(this._lastEvent), this._$target.removeEventListener("pointerdown", this._onPointerDown, {
78
+ capture: this._boundCapture
79
+ }), this._$target = null);
80
+ }
81
+ /**
82
+ * Waits out a long press. Until it activates, the browser keeps the pointer
83
+ * and may scroll. Once it does, touch scrolling and the browser's own
84
+ * long-press behavior, a context menu or text selection, are held off.
85
+ */
86
+ _startPress(i) {
87
+ i.addEventListener("touchmove", this._onTouchMove, { passive: !1 }), i.addEventListener("contextmenu", this._onContextMenu), this._pressTimer = setTimeout(() => {
88
+ this._pressTimer = void 0, this._lastEvent && !this._rejected && this._activate(this._lastEvent);
89
+ }, this._options.pressDelay);
90
+ }
91
+ _resolveIntent(i) {
92
+ const e = i.clientX - this._startX, t = i.clientY - this._startY;
93
+ if (Math.hypot(e, t) < this._options.activationDistance)
94
+ return !1;
95
+ if (this._options.activation === "press")
96
+ return this._rejected = !0, this._finish(), !1;
97
+ const { axis: n, axisLockRatio: o } = this._options, r = Math.abs(e), a = Math.abs(t);
98
+ return n === "x" && r < a * o || n === "y" && a < r * o ? (this._rejected = !0, this._finish(), !1) : (this._activate(i), !0);
99
+ }
100
+ _activate(i) {
101
+ const e = this._$target;
102
+ if (!e || this._activated)
103
+ return;
104
+ this._activated = !0;
105
+ const t = this._$captureTarget ?? e;
106
+ t.hasPointerCapture(i.pointerId) || this._capturePointer(t, i.pointerId), this._options.focusOnStart && e.focus(), this._options.stopPropagation && i.stopPropagation(), this._options.preventDefault && i.preventDefault(), this._options.onStart?.(this._detail(i));
107
+ }
108
+ _cancel(i) {
109
+ if (i.pointerId === this._pointerId) {
110
+ if (this._activated) {
111
+ this._activated = !1;
112
+ try {
113
+ this._options.onCancel?.(this._detail(i));
114
+ } finally {
115
+ this._finish();
116
+ }
117
+ return;
118
+ }
119
+ this._finish();
120
+ }
121
+ }
122
+ _finish() {
123
+ const i = this._$target, e = this._$captureTarget, t = this._pointerId;
124
+ i && this._removeCycleListeners(i), e && t !== null && this._releasePointer(e, t), this._reset();
125
+ }
126
+ _removeCycleListeners(i) {
127
+ clearTimeout(this._pressTimer), this._pressTimer = void 0, i.removeEventListener("touchmove", this._onTouchMove), i.removeEventListener("contextmenu", this._onContextMenu), i.removeEventListener("pointermove", this._onPointerMove), i.removeEventListener("pointerup", this._onPointerUp), i.removeEventListener("pointercancel", this._onPointerCancel), this._$captureTarget?.removeEventListener("lostpointercapture", this._onLostPointerCapture);
128
+ const e = i.ownerDocument;
129
+ e.removeEventListener("lostpointercapture", this._onLostPointerCapture), e.removeEventListener("pointerup", this._onDocumentPointerUp), e.removeEventListener("pointercancel", this._onPointerCancel);
130
+ }
131
+ _recordSample(i) {
132
+ this._samples.push({ x: i.clientX, y: i.clientY, time: i.timeStamp });
133
+ const e = i.timeStamp - this._options.velocityWindow;
134
+ for (; this._samples.length > 2 && this._samples[0].time < e; )
135
+ this._samples.shift();
136
+ }
137
+ _detail(i) {
138
+ const e = this._samples[0], t = this._samples.at(-1) ?? e, s = t.time - e.time, n = s >= this._options.minVelocityDuration;
139
+ return {
140
+ event: i,
141
+ pointerId: i.pointerId,
142
+ pointerType: i.pointerType,
143
+ startX: this._startX,
144
+ startY: this._startY,
145
+ x: i.clientX,
146
+ y: i.clientY,
147
+ deltaX: i.clientX - this._startX,
148
+ deltaY: i.clientY - this._startY,
149
+ duration: Math.max(0, i.timeStamp - this._startTime),
150
+ velocityX: n ? (t.x - e.x) / s * 1e3 : 0,
151
+ velocityY: n ? (t.y - e.y) / s * 1e3 : 0
152
+ };
153
+ }
154
+ _capturePointer(i, e) {
155
+ try {
156
+ i.setPointerCapture(e);
157
+ } catch (t) {
158
+ if (!(t instanceof DOMException) || t.name !== "NotFoundError")
159
+ throw t;
160
+ }
161
+ }
162
+ _releasePointer(i, e) {
163
+ try {
164
+ i.hasPointerCapture(e) && i.releasePointerCapture(e);
165
+ } catch {
166
+ }
167
+ }
168
+ _reset() {
169
+ this._pointerId = null, this._$captureTarget = null, this._lastEvent = null, this._samples = [], this._activated = !1, this._rejected = !1;
170
+ }
171
+ }
172
+ export {
173
+ _ as DragGestureController
174
+ };
@@ -0,0 +1,35 @@
1
+ import { HORIZONTAL_LTR_FLOW as r, resolveFlow as t } from "./flow.js";
2
+ import { observeLocale as o } from "./observeLocale.js";
3
+ import { RafScheduler as h } from "./RafScheduler.js";
4
+ function i(s, e) {
5
+ return s.inline === e.inline && s.inlineReversed === e.inlineReversed && s.blockReversed === e.blockReversed && s.rtl === e.rtl;
6
+ }
7
+ class c {
8
+ constructor(e) {
9
+ this._flow = r, this._observer = null, this._unobserveLocale = null, this._frame = new h(), this._host = e, e.addController(this);
10
+ }
11
+ get flow() {
12
+ return this._flow;
13
+ }
14
+ hostConnected() {
15
+ this._scheduleRefresh(), this._unobserveLocale ??= o(() => this._scheduleRefresh(), this._host), typeof ResizeObserver == "function" && (this._observer ??= new ResizeObserver(() => this._scheduleRefresh()), this._observer.observe(this._host));
16
+ }
17
+ hostDisconnected() {
18
+ this._frame.cancel(), this._observer?.disconnect(), this._unobserveLocale?.(), this._unobserveLocale = null;
19
+ }
20
+ refresh() {
21
+ this._frame.cancel(), this._apply(t(this._host));
22
+ }
23
+ _scheduleRefresh() {
24
+ this._frame.schedulePhased(
25
+ () => t(this._host),
26
+ (e) => this._apply(e)
27
+ );
28
+ }
29
+ _apply(e) {
30
+ i(e, this._flow) || (this._flow = e, this._host.requestUpdate());
31
+ }
32
+ }
33
+ export {
34
+ c as FlowController
35
+ };
@@ -0,0 +1,233 @@
1
+ const o = class o {
2
+ constructor(t, e) {
3
+ 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) => {
4
+ const n = i, s = this._resolveOptionLi(n.target);
5
+ if (s) {
6
+ if (n.pointerType === "touch") {
7
+ if (this._pendingTouchActivation)
8
+ return;
9
+ this._pendingTouchActivation = {
10
+ pointerId: n.pointerId,
11
+ li: s,
12
+ startX: n.clientX,
13
+ startY: n.clientY
14
+ };
15
+ return;
16
+ }
17
+ this._activateLi(s, n);
18
+ }
19
+ }, this._onPointerMove = (i) => {
20
+ const n = this._pendingTouchActivation, s = i;
21
+ if (!n || s.pointerId !== n.pointerId)
22
+ return;
23
+ Math.hypot(
24
+ s.clientX - n.startX,
25
+ s.clientY - n.startY
26
+ ) > o._TOUCH_TAP_THRESHOLD && (this._pendingTouchActivation = null);
27
+ }, this._onPointerUp = (i) => {
28
+ const n = this._pendingTouchActivation, s = i;
29
+ !n || s.pointerId !== n.pointerId || (this._pendingTouchActivation = null, this._activateLi(n.li, s));
30
+ }, this._onPointerCancel = (i) => {
31
+ const n = i;
32
+ this._pendingTouchActivation?.pointerId === n.pointerId && (this._pendingTouchActivation = null);
33
+ }, this._host = t, this._idPrefix = e.idPrefix, this._onInitFromDom = e.onInitFromDom, this._onActivate = e.onActivate, t.addController(this);
34
+ }
35
+ hostConnected() {
36
+ 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();
37
+ }
38
+ hostDisconnected() {
39
+ 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;
40
+ }
41
+ // -- Accessors --
42
+ get allOptions() {
43
+ return this._options;
44
+ }
45
+ get selectedValues() {
46
+ return [...this._selectedValues];
47
+ }
48
+ get filterText() {
49
+ return this._filterText;
50
+ }
51
+ isSelected(t) {
52
+ return this._selectedValues.has(t);
53
+ }
54
+ optionForElement(t) {
55
+ if (t === this._createLi)
56
+ return this._createOption;
57
+ const e = this._liElements.indexOf(t);
58
+ return e === -1 ? null : this._options[e] ?? null;
59
+ }
60
+ /**
61
+ * Navigable option elements: visible (not `[hidden]`) and not `aria-disabled`.
62
+ * Includes the create option when set. Consumed by `ActiveDescendantController`.
63
+ */
64
+ get navigableItems() {
65
+ const t = [];
66
+ for (let e = 0; e < this._liElements.length; e++) {
67
+ const i = this._liElements[e];
68
+ this._options[e]?.disabled || i.hidden || t.push(i);
69
+ }
70
+ return this._createLi !== null && t.push(this._createLi), t;
71
+ }
72
+ set checkmark(t) {
73
+ this._checkmark !== t && (this._checkmark = t, this._syncCheckmarks());
74
+ }
75
+ // -- Mutation methods --
76
+ /** Replace the full option list. Sets the controller as authoritative, preventing DOM bootstrap. */
77
+ setOptions(t) {
78
+ this._optionsInitialized = !0, this._options = [...t], this._ensureContainer(), this._syncOptionsToDom();
79
+ }
80
+ /** Append a single option without replacing the list. */
81
+ appendOption(t) {
82
+ this._optionsInitialized = !0, this._options = [...this._options, t];
83
+ const e = this._ensureContainer(), i = this._createLiElement(t, this._options.length - 1);
84
+ this._liElements.push(i), this._createLi ? e.insertBefore(i, this._createLi) : e.appendChild(i), this._applyFilterToLi(i, t);
85
+ }
86
+ /** Update `aria-selected` on all option elements to match `values`. */
87
+ setSelectedValues(t) {
88
+ const e = new Set(
89
+ this._options.filter((i) => i.kind === "action").map((i) => i.value)
90
+ );
91
+ this._createOption && e.add(this._createOption.value), this._selectedValues = new Set(t.filter((i) => !e.has(i))), this._syncSelectedToDom();
92
+ }
93
+ /**
94
+ * Apply a filter — sets `[hidden]` on non-matching `<li>` elements.
95
+ * The strategy is stored and re-used when options change.
96
+ */
97
+ filterOptions(t, e = "contains") {
98
+ this._filterText = t, this._filterStrategy = e, this._syncFilterToDom();
99
+ }
100
+ /** Remove `[hidden]` from all option elements. */
101
+ clearFilter() {
102
+ this._filterText = "", this._syncFilterToDom();
103
+ }
104
+ /**
105
+ * Show or hide the synthetic "Create" option at the end of the list.
106
+ * Pass `null` to remove it. `label` is the option's visible text, such as
107
+ * `Create "pears"`; it defaults to the text itself.
108
+ */
109
+ setCreateOption(t, e) {
110
+ if (t === null) {
111
+ this._createLi?.remove(), this._createLi = null, this._createOption = null;
112
+ return;
113
+ }
114
+ const i = t.trim();
115
+ if (this._createOption = {
116
+ kind: "action",
117
+ action: "create",
118
+ value: `create:${i}`,
119
+ label: e ?? i,
120
+ data: { text: i }
121
+ }, !this._createLi) {
122
+ const n = this._ensureContainer(), s = document.createElement("li");
123
+ s.setAttribute("id", `${this._idPrefix}-create`), s.setAttribute("role", "option"), s.setAttribute("aria-selected", "false"), s.setAttribute("part", "option create-option"), this._checkmark && this._ensureCheckmark(s), n.appendChild(s), this._createLi = s;
124
+ }
125
+ 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);
126
+ }
127
+ // -- Private: DOM management --
128
+ _ensureContainer() {
129
+ if (this._ul)
130
+ return this._ul;
131
+ let t = this._host.querySelector(":scope > ul");
132
+ return t || (t = document.createElement("ul"), this._host.appendChild(t)), t.setAttribute("role", "presentation"), t.setAttribute("aria-hidden", "true"), this._ul = t, t;
133
+ }
134
+ _bootstrapFromDom() {
135
+ const t = this._host.querySelector(":scope > ul");
136
+ if (!t)
137
+ return;
138
+ this._ul = t, t.setAttribute("role", "presentation"), t.setAttribute("aria-hidden", "true");
139
+ const e = Array.from(t.querySelectorAll(":scope > li"));
140
+ if (e.length === 0)
141
+ return;
142
+ const i = [];
143
+ for (let n = 0; n < e.length; n++) {
144
+ const s = e[n], r = s.getAttribute("data-value") ?? s.getAttribute("value") ?? s.textContent?.trim() ?? "", h = s.textContent?.trim() ?? "", a = s.hasAttribute("disabled") || s.getAttribute("aria-disabled") === "true";
145
+ i.push({ value: r, label: h, disabled: a }), s.setAttribute("role", "option"), s.setAttribute("id", `${this._idPrefix}-${n}`), s.setAttribute("part", "option"), s.setAttribute("data-value", r), s.setAttribute("aria-selected", this._selectedValues.has(r) ? "true" : "false"), s.setAttribute("aria-disabled", a ? "true" : "false"), this._checkmark && this._ensureCheckmark(s);
146
+ }
147
+ this._options = i, this._liElements = e, this._onInitFromDom?.(i);
148
+ }
149
+ _syncOptionsToDom() {
150
+ const t = this._ensureContainer();
151
+ for (const e of this._liElements)
152
+ e.remove();
153
+ this._liElements = [];
154
+ for (let e = 0; e < this._options.length; e++) {
155
+ const i = this._createLiElement(this._options[e], e);
156
+ this._liElements.push(i), t.appendChild(i);
157
+ }
158
+ this._createLi && t.appendChild(this._createLi), this._syncFilterToDom();
159
+ }
160
+ _createLiElement(t, e) {
161
+ const i = document.createElement("li");
162
+ 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;
163
+ }
164
+ _setLabelText(t, e) {
165
+ for (const i of t.childNodes)
166
+ if (i.nodeType === Node.TEXT_NODE) {
167
+ i.textContent = e;
168
+ return;
169
+ }
170
+ t.appendChild(document.createTextNode(e));
171
+ }
172
+ _ensureCheckmark(t) {
173
+ if (t.querySelector('[part="option-checkmark"]'))
174
+ return;
175
+ const e = document.createElement("span");
176
+ e.setAttribute("part", "option-checkmark"), e.setAttribute("aria-hidden", "true"), e.textContent = "✓", t.insertBefore(e, t.firstChild);
177
+ }
178
+ _removeCheckmark(t) {
179
+ t.querySelector('[part="option-checkmark"]')?.remove();
180
+ }
181
+ _syncCheckmarks() {
182
+ const t = this._createLi ? [...this._liElements, this._createLi] : [...this._liElements];
183
+ for (const e of t)
184
+ this._checkmark ? this._ensureCheckmark(e) : this._removeCheckmark(e);
185
+ }
186
+ _syncSelectedToDom() {
187
+ for (let t = 0; t < this._liElements.length; t++) {
188
+ const e = this._options[t];
189
+ e && this._liElements[t].setAttribute(
190
+ "aria-selected",
191
+ this._selectedValues.has(e.value) ? "true" : "false"
192
+ );
193
+ }
194
+ }
195
+ _syncFilterToDom() {
196
+ for (let t = 0; t < this._liElements.length; t++) {
197
+ const e = this._options[t];
198
+ e && this._applyFilterToLi(this._liElements[t], e);
199
+ }
200
+ }
201
+ _applyFilterToLi(t, e) {
202
+ t.hidden = !this._isVisible(e);
203
+ }
204
+ _isVisible(t) {
205
+ if (!this._filterText)
206
+ return !0;
207
+ const e = t.label.toLowerCase(), i = this._filterText.toLowerCase();
208
+ return typeof this._filterStrategy == "function" ? this._filterStrategy(e, i) : this._filterStrategy === "contains" ? e.includes(i) : e.startsWith(i);
209
+ }
210
+ _resolveOptionLi(t) {
211
+ if (!t)
212
+ return null;
213
+ const e = t.closest("li[data-value]");
214
+ return !e || e.getAttribute("role") !== "option" || e.parentElement !== this._ul ? null : e;
215
+ }
216
+ /**
217
+ * Claims a pointer event as an option activation: stops it from continuing
218
+ * to bubble/compose past this point (left unstopped, a composed event can
219
+ * still be observed by ancestors outside this component — e.g. a <label>
220
+ * wrapping an unrelated sibling control — and be reinterpreted as an
221
+ * interaction with something else entirely), then activates the option.
222
+ */
223
+ _activateLi(t, e) {
224
+ e.preventDefault(), e.stopPropagation();
225
+ const i = this.optionForElement(t);
226
+ i && this._onActivate(i);
227
+ }
228
+ };
229
+ o._TOUCH_TAP_THRESHOLD = 10;
230
+ let l = o;
231
+ export {
232
+ l as ItemsCollectionController
233
+ };
@@ -0,0 +1,39 @@
1
+ import { nothing as n } from "lit";
2
+ import { PartType as i } from "lit/directive.js";
3
+ import { directive as o, AsyncDirective as r } from "lit/async-directive.js";
4
+ class s extends r {
5
+ constructor(e) {
6
+ if (super(e), this._options = {}, this._isPointerFocus = !1, this._onPointerdown = () => {
7
+ this._isPointerFocus = !0, this._target?.removeAttribute("data-interaction-mode");
8
+ }, this._onFocusin = () => {
9
+ this._isPointerFocus ? this._isPointerFocus = !1 : this._target?.setAttribute("data-interaction-mode", "keyboard");
10
+ }, this._onKeydown = () => {
11
+ this._target?.setAttribute("data-interaction-mode", "keyboard");
12
+ }, e.type !== i.ELEMENT)
13
+ throw new Error("The `keyInteraction` directive must be used on an element.");
14
+ }
15
+ get _target() {
16
+ return this._options.attributeTarget ?? this._element?.deref();
17
+ }
18
+ _init() {
19
+ const e = this._element?.deref();
20
+ e instanceof HTMLElement && (e.addEventListener("pointerdown", this._onPointerdown, { capture: !0 }), e.addEventListener("focusin", this._onFocusin), e.addEventListener("keydown", this._onKeydown));
21
+ }
22
+ render(e) {
23
+ return n;
24
+ }
25
+ update(e, [t]) {
26
+ this.isConnected && this._element?.deref() === void 0 && (this._element = new WeakRef(e.element), this._init()), this._options = t ?? {};
27
+ }
28
+ disconnected() {
29
+ const e = this._element?.deref();
30
+ e instanceof HTMLElement && (e.removeEventListener("pointerdown", this._onPointerdown, { capture: !0 }), e.removeEventListener("focusin", this._onFocusin), e.removeEventListener("keydown", this._onKeydown));
31
+ }
32
+ reconnected() {
33
+ this._init();
34
+ }
35
+ }
36
+ const _ = o(s);
37
+ export {
38
+ _ as keyInteraction
39
+ };
@@ -0,0 +1,88 @@
1
+ import { nothing as f } from "lit";
2
+ import { PartType as p } from "lit/directive.js";
3
+ import { directive as v, AsyncDirective as _ } from "lit/async-directive.js";
4
+ import { HORIZONTAL_LTR_FLOW as r, resolveFlow as a, renderedOrientation as o, arrowKeys as u } from "./flow.js";
5
+ class m extends _ {
6
+ constructor(e) {
7
+ if (super(e), this._options = {}, e.type !== p.ELEMENT)
8
+ throw new Error("The `keyNavigation` directive must be used on an element.");
9
+ }
10
+ /**
11
+ * The physical axis whose arrow keys map to 'next'/'prev'.
12
+ *
13
+ * An explicit `aria-orientation` attribute is already physical and is used
14
+ * as is. Everything else describes layout, so it is converted to the
15
+ * orientation it renders in: an explicit `navigationAxis` option or a role
16
+ * default of `horizontal` runs along the inline axis and turns vertical in
17
+ * vertical writing modes, like a native range input does.
18
+ */
19
+ get navigationAxis() {
20
+ const e = this._element?.deref();
21
+ return this._resolveAxis(e, e ? a(e) : r);
22
+ }
23
+ _resolveAxis(e, t) {
24
+ if (this._options.navigationAxis)
25
+ return o(this._options.navigationAxis, t);
26
+ const n = e?.getAttribute("aria-orientation"), s = n === "horizontal" || n === "vertical" ? n : null;
27
+ switch (e?.role) {
28
+ case "slider":
29
+ case "tablist":
30
+ case "toolbar":
31
+ case "menubar":
32
+ return s ?? o("horizontal", t);
33
+ case "separator":
34
+ return s ? s === "vertical" ? "horizontal" : "vertical" : o("vertical", t);
35
+ default:
36
+ return s ?? o("vertical", t);
37
+ }
38
+ }
39
+ _normalizeKey(e) {
40
+ switch (e) {
41
+ case "Up":
42
+ return "ArrowUp";
43
+ case "Down":
44
+ return "ArrowDown";
45
+ case "Left":
46
+ return "ArrowLeft";
47
+ case "Right":
48
+ return "ArrowRight";
49
+ default:
50
+ return e;
51
+ }
52
+ }
53
+ _onKeydown(e) {
54
+ const t = this._normalizeKey(e.key), n = this._element?.deref(), s = n ? a(n) : r, {
55
+ next: l,
56
+ prev: c,
57
+ openFirst: h,
58
+ openLast: d
59
+ } = u(this._resolveAxis(n, s), s);
60
+ let i;
61
+ this._options.handleNavAxis !== !1 && (t === l ? i = e.shiftKey ? "next-large" : "next" : t === c ? i = e.shiftKey ? "prev-large" : "prev" : t === "Home" ? i = "start" : t === "End" && (i = "end")), !i && this._options.handleOpenAxis && (t === h ? i = "open-to-first" : t === d && (i = "open-to-last")), i || (t === "Enter" ? i = this._options.handleActivate ? "activate" : "toggle" : t === " " && this._options.handleActivate ? i = "activate" : t === "Escape" && this._options.handleEscape && (i = "escape")), i != null && (this._callback(i), e.stopPropagation(), e.preventDefault());
62
+ }
63
+ _init() {
64
+ const e = this._element?.deref();
65
+ e != null && e instanceof HTMLElement && (this._keyDownHandle = this._onKeydown.bind(this), e.addEventListener("keydown", this._keyDownHandle));
66
+ }
67
+ /**
68
+ * @param _cb - callback function invoked with the navigation action
69
+ * @param _options - keyboard navigation behavior options
70
+ */
71
+ render(e, t) {
72
+ return f;
73
+ }
74
+ update(e, [t, n]) {
75
+ this.isConnected && this._element?.deref() === void 0 && (this._element = new WeakRef(e.element), this._init()), this._callback = t.bind(e.options?.host ?? e.element), this._options = { ...n };
76
+ }
77
+ disconnected() {
78
+ const e = this._element?.deref();
79
+ e != null && e instanceof HTMLElement && e.removeEventListener("keydown", this._keyDownHandle);
80
+ }
81
+ reconnected() {
82
+ this._init();
83
+ }
84
+ }
85
+ const E = v(m);
86
+ export {
87
+ E as keyNavigation
88
+ };
@@ -0,0 +1,36 @@
1
+ class n {
2
+ constructor(e) {
3
+ const t = e.ownerDocument ?? e;
4
+ this._$region = t.createElement("div"), this._$region.setAttribute("role", "status"), this._$region.setAttribute("aria-live", "polite"), this._$region.setAttribute("aria-atomic", "true"), this._$region.setAttribute("data-rc-live-announcer", ""), Object.assign(this._$region.style, {
5
+ position: "absolute",
6
+ inlineSize: "1px",
7
+ blockSize: "1px",
8
+ margin: "-1px",
9
+ padding: "0",
10
+ overflow: "hidden",
11
+ clipPath: "inset(50%)",
12
+ whiteSpace: "nowrap",
13
+ border: "0"
14
+ }), e.appendChild(this._$region);
15
+ }
16
+ /** The region element, for tests and for callers that need to reposition it. */
17
+ get element() {
18
+ return this._$region;
19
+ }
20
+ /**
21
+ * Speaks `message`. The region is emptied first so a message identical to
22
+ * the previous one is still announced.
23
+ */
24
+ announce(e) {
25
+ clearTimeout(this._clearTimer), this._$region.textContent = "", this._clearTimer = setTimeout(() => {
26
+ this._$region.textContent = e;
27
+ }, 50);
28
+ }
29
+ /** Removes the region. */
30
+ dispose() {
31
+ clearTimeout(this._clearTimer), this._$region.remove();
32
+ }
33
+ }
34
+ export {
35
+ n as LiveAnnouncer
36
+ };
@@ -0,0 +1,30 @@
1
+ class o {
2
+ constructor(t, s) {
3
+ this._attached = null, this._observer = null, this._options = s, t.addController(this);
4
+ }
5
+ setOptions(t) {
6
+ this._detach(), Object.assign(this._options, t), this._attach();
7
+ }
8
+ hostConnected() {
9
+ this._attach();
10
+ }
11
+ hostDisconnected() {
12
+ this._detach();
13
+ }
14
+ _resolveTarget() {
15
+ const { target: t } = this._options;
16
+ return typeof t == "function" ? t() : t ?? null;
17
+ }
18
+ _attach() {
19
+ if (this._options.disabled || this._attached)
20
+ return;
21
+ const t = this._resolveTarget();
22
+ t && (this._observer ??= new MutationObserver(this._options.callback), this._observer.observe(t, this._options.observerOptions ?? { childList: !0 }), this._attached = t);
23
+ }
24
+ _detach() {
25
+ this._observer?.disconnect(), this._attached = null;
26
+ }
27
+ }
28
+ export {
29
+ o as MutationObserverController
30
+ };