@rcarls/rc-common 0.1.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.
- package/README.md +206 -0
- package/dist/css-anchor-positioning-fn-hFYJeBk4.js +6371 -0
- package/dist/rc-common.js +811 -0
- package/dist/rc-common.umd.cjs +31 -0
- package/dist/types/ActiveDescendantController.d.ts +86 -0
- package/dist/types/AnchorController.d.ts +55 -0
- package/dist/types/DragController.d.ts +53 -0
- package/dist/types/KeyboardNavigationDirective.d.ts +76 -0
- package/dist/types/KeyboardNavigationDirective.test.d.ts +1 -0
- package/dist/types/MouseMoveDirective.d.ts +42 -0
- package/dist/types/MouseMoveDirective.test.d.ts +1 -0
- package/dist/types/ResizeController.d.ts +78 -0
- package/dist/types/RovingTabIndexMixin.d.ts +58 -0
- package/dist/types/ScrollObserverController.d.ts +61 -0
- package/dist/types/ScrollObserverController.test.d.ts +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/isFocusable.d.ts +10 -0
- package/dist/types/isFocusable.test.d.ts +1 -0
- package/dist/types/sliderUtils.d.ts +12 -0
- package/package.json +62 -0
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
import { nothing as x } from "lit";
|
|
2
|
+
import { PartType as P } from "lit/directive.js";
|
|
3
|
+
import { directive as E, AsyncDirective as L } from "lit/async-directive.js";
|
|
4
|
+
import { state as A } from "lit/decorators.js";
|
|
5
|
+
let C = 0;
|
|
6
|
+
class U {
|
|
7
|
+
constructor(t, e) {
|
|
8
|
+
this._activeItem = null, this._activeIndex = -1, this._itemCounter = 0, this._opts = e, this._instanceId = `rc-adc-${++C}`, 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 n = this._activeIndex < 0 ? t > 0 ? -1 : e.length : this._activeIndex;
|
|
32
|
+
const s = e.length;
|
|
33
|
+
let o = 0;
|
|
34
|
+
do
|
|
35
|
+
if (n += t, i ? n = (n % s + s) % s : n = Math.max(0, Math.min(s - 1, n)), o++, !this._isSkipped(e[n])) break;
|
|
36
|
+
while (o < s);
|
|
37
|
+
this._setActive(e[n] ?? null, n);
|
|
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
|
+
class I extends L {
|
|
90
|
+
constructor(t) {
|
|
91
|
+
if (super(t), this._options = {}, t.type !== P.ELEMENT)
|
|
92
|
+
throw new Error(
|
|
93
|
+
"The `keyNavigation` directive must be used on an element."
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The navigation axis determines which arrow keys map to 'next'/'prev'.
|
|
98
|
+
* Checks the explicit `navigationAxis` option first, then auto-detects
|
|
99
|
+
* from the element's ARIA role and aria-orientation attribute.
|
|
100
|
+
*/
|
|
101
|
+
get navigationAxis() {
|
|
102
|
+
if (this._options.navigationAxis) return this._options.navigationAxis;
|
|
103
|
+
switch (this._element?.deref()?.role) {
|
|
104
|
+
case "slider":
|
|
105
|
+
case "tablist":
|
|
106
|
+
case "toolbar":
|
|
107
|
+
case "menubar":
|
|
108
|
+
return this._element?.deref()?.ariaOrientation === "vertical" ? "vertical" : "horizontal";
|
|
109
|
+
default:
|
|
110
|
+
return this._element?.deref()?.ariaOrientation === "horizontal" ? "horizontal" : "vertical";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
_normalizeKey(t) {
|
|
114
|
+
switch (t) {
|
|
115
|
+
case "Up":
|
|
116
|
+
return "ArrowUp";
|
|
117
|
+
case "Down":
|
|
118
|
+
return "ArrowDown";
|
|
119
|
+
case "Left":
|
|
120
|
+
return "ArrowLeft";
|
|
121
|
+
case "Right":
|
|
122
|
+
return "ArrowRight";
|
|
123
|
+
default:
|
|
124
|
+
return t;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
_onKeydown(t) {
|
|
128
|
+
const e = this._normalizeKey(t.key), i = this.navigationAxis, n = this._element?.deref(), s = i === "horizontal" && n != null && getComputedStyle(n).direction === "rtl", o = i === "horizontal" ? s ? "ArrowLeft" : "ArrowRight" : "ArrowDown", a = i === "horizontal" ? s ? "ArrowRight" : "ArrowLeft" : "ArrowUp", d = i === "horizontal" ? "ArrowDown" : "ArrowRight", l = i === "horizontal" ? "ArrowUp" : "ArrowLeft";
|
|
129
|
+
let h;
|
|
130
|
+
this._options.handleNavAxis !== !1 && (e === o ? h = "next" : e === a ? h = "prev" : e === "Home" ? h = "start" : e === "End" && (h = "end")), !h && this._options.handleOpenAxis && (e === d ? h = "open-to-first" : e === l && (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" : e === "Tab" && this._options.useInteractionModeAttr && this._element?.deref()?.setAttribute("data-interaction-mode", "keyboard")), h != null && (this._callback(h), this._options.useInteractionModeAttr && this._element?.deref()?.setAttribute("data-interaction-mode", "keyboard"), t.stopPropagation(), t.preventDefault());
|
|
131
|
+
}
|
|
132
|
+
_onMouseClick(t) {
|
|
133
|
+
this._options.useInteractionModeAttr && this._element?.deref()?.removeAttribute("data-interaction-mode");
|
|
134
|
+
}
|
|
135
|
+
_init() {
|
|
136
|
+
const t = this._element?.deref();
|
|
137
|
+
t != null && t instanceof HTMLElement && (this._keyDownHandle = this._onKeydown.bind(this), this._mouseClickHandle = this._onMouseClick.bind(this), t.addEventListener("keydown", this._keyDownHandle), t.addEventListener("click", this._mouseClickHandle));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @param _cb - Callback function invoked with the navigation action
|
|
141
|
+
* @param _options - Options object or deprecated boolean for useInteractionModeAttr
|
|
142
|
+
* @deprecated Passing a boolean as the second parameter is deprecated.
|
|
143
|
+
* Use an options object instead: `{ useInteractionModeAttr: true }`
|
|
144
|
+
*/
|
|
145
|
+
render(t, e) {
|
|
146
|
+
return x;
|
|
147
|
+
}
|
|
148
|
+
update(t, [e, i]) {
|
|
149
|
+
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 = { useInteractionModeAttr: i } : this._options = {
|
|
150
|
+
useInteractionModeAttr: !0,
|
|
151
|
+
...i
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
disconnected() {
|
|
155
|
+
const t = this._element?.deref();
|
|
156
|
+
t != null && t instanceof HTMLElement && (t.removeEventListener("keydown", this._keyDownHandle), t.removeEventListener("click", this._mouseClickHandle));
|
|
157
|
+
}
|
|
158
|
+
reconnected() {
|
|
159
|
+
this._init();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const K = E(I);
|
|
163
|
+
class H extends L {
|
|
164
|
+
constructor(t) {
|
|
165
|
+
if (super(t), this._activePointerId = null, t.type !== P.ELEMENT)
|
|
166
|
+
throw new Error("The `mouseMove` directive must be used on an element.");
|
|
167
|
+
this._pointerDownHandle = this._onPointerDown.bind(this), this._pointerMoveHandle = this._onPointerMove.bind(this), this._pointerEndHandle = this._onPointerEnd.bind(this);
|
|
168
|
+
}
|
|
169
|
+
/** Start a pointer drag cycle on the directive-decorated element. */
|
|
170
|
+
_onPointerDown(t) {
|
|
171
|
+
if (this._activePointerId !== null) return;
|
|
172
|
+
t.preventDefault();
|
|
173
|
+
const e = t.currentTarget;
|
|
174
|
+
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();
|
|
175
|
+
}
|
|
176
|
+
/** Forward pointer movement during an active drag cycle. */
|
|
177
|
+
_onPointerMove(t) {
|
|
178
|
+
t.pointerId === this._activePointerId && (t.preventDefault(), this._callback(t));
|
|
179
|
+
}
|
|
180
|
+
/** Finish the active pointer drag cycle and remove temporary listeners. */
|
|
181
|
+
_onPointerEnd(t) {
|
|
182
|
+
if (t.pointerId !== this._activePointerId) return;
|
|
183
|
+
t.preventDefault();
|
|
184
|
+
const e = t.currentTarget;
|
|
185
|
+
this._releasePointer(e, t.pointerId), this._removePointerCycleListeners(e), this._activePointerId = null;
|
|
186
|
+
}
|
|
187
|
+
/** Attach the permanent pointerdown listener to the current element. */
|
|
188
|
+
_init() {
|
|
189
|
+
const t = this._element?.deref();
|
|
190
|
+
t && (t.removeEventListener("pointerdown", this._pointerDownHandle), t.addEventListener("pointerdown", this._pointerDownHandle));
|
|
191
|
+
}
|
|
192
|
+
/** Remove all listeners associated with the active drag cycle. */
|
|
193
|
+
_removePointerCycleListeners(t) {
|
|
194
|
+
t.removeEventListener("pointermove", this._pointerMoveHandle), t.removeEventListener("pointerup", this._pointerEndHandle), t.removeEventListener("pointercancel", this._pointerEndHandle), t.removeEventListener("lostpointercapture", this._pointerEndHandle);
|
|
195
|
+
}
|
|
196
|
+
_capturePointer(t, e) {
|
|
197
|
+
try {
|
|
198
|
+
t.setPointerCapture(e);
|
|
199
|
+
} catch {
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
_releasePointer(t, e) {
|
|
203
|
+
try {
|
|
204
|
+
t.hasPointerCapture(e) && t.releasePointerCapture(e);
|
|
205
|
+
} catch {
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/** Render no DOM; this directive only wires pointer listeners. */
|
|
209
|
+
render(t) {
|
|
210
|
+
return x;
|
|
211
|
+
}
|
|
212
|
+
update(t, [e]) {
|
|
213
|
+
if (this._callback = e.bind(t.options?.host ?? t.element), !this.isConnected || !(t.element instanceof HTMLElement)) return;
|
|
214
|
+
const i = this._element?.deref();
|
|
215
|
+
i !== t.element && (i?.removeEventListener("pointerdown", this._pointerDownHandle), i && this._removePointerCycleListeners(i), this._activePointerId = null, this._element = new WeakRef(t.element), this._init());
|
|
216
|
+
}
|
|
217
|
+
disconnected() {
|
|
218
|
+
const t = this._element?.deref();
|
|
219
|
+
t && (t.removeEventListener("pointerdown", this._pointerDownHandle), this._removePointerCycleListeners(t), this._activePointerId = null);
|
|
220
|
+
}
|
|
221
|
+
reconnected() {
|
|
222
|
+
this._init();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const O = E(H);
|
|
226
|
+
class N {
|
|
227
|
+
constructor(t, e) {
|
|
228
|
+
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);
|
|
229
|
+
}
|
|
230
|
+
setOptions(t) {
|
|
231
|
+
const e = this._handle();
|
|
232
|
+
Object.assign(this._opts, t);
|
|
233
|
+
const i = this._handle();
|
|
234
|
+
e !== i && (this._detachFrom(e), this._attachTo(i));
|
|
235
|
+
}
|
|
236
|
+
hostConnected() {
|
|
237
|
+
this._attachTo(this._handle());
|
|
238
|
+
}
|
|
239
|
+
hostDisconnected() {
|
|
240
|
+
this._detachFrom(this._handle());
|
|
241
|
+
}
|
|
242
|
+
_handle() {
|
|
243
|
+
return this._opts.handle ?? this._opts.target;
|
|
244
|
+
}
|
|
245
|
+
_target() {
|
|
246
|
+
return this._opts.target;
|
|
247
|
+
}
|
|
248
|
+
_attachTo(t) {
|
|
249
|
+
t.addEventListener("pointerdown", this._onPointerDown), t.addEventListener("keydown", this._onKeyDown), t.hasAttribute("tabindex") || t.setAttribute("tabindex", "0");
|
|
250
|
+
}
|
|
251
|
+
_detachFrom(t) {
|
|
252
|
+
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);
|
|
253
|
+
}
|
|
254
|
+
_handlePointerDown(t) {
|
|
255
|
+
if (this._opts.disabled || t.target.closest('button, [role="button"], a')) return;
|
|
256
|
+
const e = this._target(), i = e.getBoundingClientRect();
|
|
257
|
+
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;
|
|
258
|
+
const n = this._handle();
|
|
259
|
+
n.setPointerCapture(t.pointerId), n.addEventListener("pointermove", this._onPointerMove), n.addEventListener("pointerup", this._onPointerUp), n.addEventListener("pointercancel", this._onPointerCancel), n.addEventListener("lostpointercapture", this._onLostPointerCapture), t.preventDefault();
|
|
260
|
+
}
|
|
261
|
+
_handlePointerMove(t) {
|
|
262
|
+
if (!this._dragging) return;
|
|
263
|
+
const e = this._target(), { axis: i } = this._opts, [n, s, o, a] = this._boundsRect(), d = i !== "y" ? Math.min(Math.max(this._startLeft + t.clientX - this._startX, n), o - e.offsetWidth) : parseFloat(e.style.left) || 0, l = i !== "x" ? Math.min(Math.max(this._startTop + t.clientY - this._startY, s), a - e.offsetHeight) : parseFloat(e.style.top) || 0;
|
|
264
|
+
e.style.left = `${d}px`, e.style.top = `${l}px`;
|
|
265
|
+
}
|
|
266
|
+
_handlePointerUp(t) {
|
|
267
|
+
this._cancelDrag();
|
|
268
|
+
}
|
|
269
|
+
_handleLostPointerCapture(t) {
|
|
270
|
+
this._cancelDrag();
|
|
271
|
+
}
|
|
272
|
+
_cancelDrag() {
|
|
273
|
+
if (!this._dragging) return;
|
|
274
|
+
this._dragging = !1;
|
|
275
|
+
const t = this._handle();
|
|
276
|
+
t.removeEventListener("pointermove", this._onPointerMove), t.removeEventListener("pointerup", this._onPointerUp), t.removeEventListener("pointercancel", this._onPointerCancel), t.removeEventListener("lostpointercapture", this._onLostPointerCapture);
|
|
277
|
+
}
|
|
278
|
+
_handleKeyDown(t) {
|
|
279
|
+
if (this._opts.disabled || t.currentTarget !== t.target) return;
|
|
280
|
+
const { axis: e } = this._opts, i = t.shiftKey ? this._opts.step * 10 : this._opts.step;
|
|
281
|
+
let n = 0, s = 0;
|
|
282
|
+
switch (t.key) {
|
|
283
|
+
case "ArrowLeft":
|
|
284
|
+
if (e === "y") return;
|
|
285
|
+
n = -i;
|
|
286
|
+
break;
|
|
287
|
+
case "ArrowRight":
|
|
288
|
+
if (e === "y") return;
|
|
289
|
+
n = i;
|
|
290
|
+
break;
|
|
291
|
+
case "ArrowUp":
|
|
292
|
+
if (e === "x") return;
|
|
293
|
+
s = -i;
|
|
294
|
+
break;
|
|
295
|
+
case "ArrowDown":
|
|
296
|
+
if (e === "x") return;
|
|
297
|
+
s = i;
|
|
298
|
+
break;
|
|
299
|
+
default:
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const o = this._target();
|
|
303
|
+
if (getComputedStyle(o).position === "static") {
|
|
304
|
+
const p = o.getBoundingClientRect();
|
|
305
|
+
o.style.position = "fixed", o.style.translate = "none", o.style.left = `${p.left}px`, o.style.top = `${p.top}px`;
|
|
306
|
+
}
|
|
307
|
+
const [a, d, l, h] = this._boundsRect(), u = parseFloat(o.style.left) || 0, c = parseFloat(o.style.top) || 0;
|
|
308
|
+
o.style.left = `${Math.min(Math.max(u + n, a), l - o.offsetWidth)}px`, o.style.top = `${Math.min(Math.max(c + s, d), h - o.offsetHeight)}px`, t.preventDefault(), t.stopPropagation();
|
|
309
|
+
}
|
|
310
|
+
_boundsRect() {
|
|
311
|
+
const { bounds: t } = this._opts;
|
|
312
|
+
if (!t || t === "viewport")
|
|
313
|
+
return [0, 0, window.innerWidth, window.innerHeight];
|
|
314
|
+
if (t === "parent") {
|
|
315
|
+
const i = this._opts.target.parentElement;
|
|
316
|
+
if (!i) return [0, 0, window.innerWidth, window.innerHeight];
|
|
317
|
+
const n = i.getBoundingClientRect();
|
|
318
|
+
return [n.left, n.top, n.right, n.bottom];
|
|
319
|
+
}
|
|
320
|
+
const e = t.getBoundingClientRect();
|
|
321
|
+
return [e.left, e.top, e.right, e.bottom];
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
class Y {
|
|
325
|
+
constructor(t, e) {
|
|
326
|
+
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 = {
|
|
327
|
+
direction: "none",
|
|
328
|
+
threshold: 8,
|
|
329
|
+
step: 4,
|
|
330
|
+
disabled: !1,
|
|
331
|
+
minWidth: 100,
|
|
332
|
+
minHeight: 60,
|
|
333
|
+
handle: null,
|
|
334
|
+
bounds: "viewport",
|
|
335
|
+
...e
|
|
336
|
+
}, 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);
|
|
337
|
+
}
|
|
338
|
+
setOptions(t) {
|
|
339
|
+
Object.assign(this._opts, t);
|
|
340
|
+
}
|
|
341
|
+
hostConnected() {
|
|
342
|
+
if (this._opts.direction === "none") return;
|
|
343
|
+
const t = this._target();
|
|
344
|
+
t.addEventListener("pointermove", this._onPointerMove), t.addEventListener("pointerdown", this._onPointerDown, { capture: !0 }), t.addEventListener("pointerup", this._onPointerUp), t.addEventListener("pointerleave", this._onPointerLeave), this._injectCornerButton();
|
|
345
|
+
}
|
|
346
|
+
hostDisconnected() {
|
|
347
|
+
const t = this._target();
|
|
348
|
+
t.removeEventListener("pointermove", this._onPointerMove), t.removeEventListener("pointerdown", this._onPointerDown, { capture: !0 }), t.removeEventListener("pointerup", this._onPointerUp), t.removeEventListener("pointerleave", this._onPointerLeave), this._removeCornerButton();
|
|
349
|
+
}
|
|
350
|
+
_target() {
|
|
351
|
+
return this._opts.target;
|
|
352
|
+
}
|
|
353
|
+
_injectCornerButton() {
|
|
354
|
+
if (this._opts.handle) return;
|
|
355
|
+
const t = this._target();
|
|
356
|
+
getComputedStyle(t).position === "static" && (t.style.position = "relative");
|
|
357
|
+
const e = document.createElement("button");
|
|
358
|
+
e.setAttribute("data-rc-resize-corner", ""), e.setAttribute("aria-label", "Resize"), e.type = "button", Object.assign(e.style, {
|
|
359
|
+
position: "absolute",
|
|
360
|
+
bottom: "0",
|
|
361
|
+
right: "0",
|
|
362
|
+
width: "12px",
|
|
363
|
+
height: "12px",
|
|
364
|
+
padding: "0",
|
|
365
|
+
border: "none",
|
|
366
|
+
background: "transparent",
|
|
367
|
+
cursor: this._cornerCursor(),
|
|
368
|
+
zIndex: "1"
|
|
369
|
+
}), e.addEventListener("keydown", this._onKeyDown), t.appendChild(e), this._cornerBtn = e;
|
|
370
|
+
}
|
|
371
|
+
_removeCornerButton() {
|
|
372
|
+
this._cornerBtn && (this._cornerBtn.removeEventListener("keydown", this._onKeyDown), this._cornerBtn.remove(), this._cornerBtn = null);
|
|
373
|
+
}
|
|
374
|
+
_cornerCursor() {
|
|
375
|
+
switch (this._opts.direction) {
|
|
376
|
+
case "both":
|
|
377
|
+
return "se-resize";
|
|
378
|
+
case "horizontal":
|
|
379
|
+
return "ew-resize";
|
|
380
|
+
case "vertical":
|
|
381
|
+
return "ns-resize";
|
|
382
|
+
default:
|
|
383
|
+
return "default";
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
_edgeCursor(t) {
|
|
387
|
+
return {
|
|
388
|
+
n: "n-resize",
|
|
389
|
+
s: "s-resize",
|
|
390
|
+
e: "e-resize",
|
|
391
|
+
w: "w-resize",
|
|
392
|
+
ne: "ne-resize",
|
|
393
|
+
nw: "nw-resize",
|
|
394
|
+
se: "se-resize",
|
|
395
|
+
sw: "sw-resize"
|
|
396
|
+
}[t];
|
|
397
|
+
}
|
|
398
|
+
_detectEdge(t) {
|
|
399
|
+
const { direction: e, threshold: i } = this._opts;
|
|
400
|
+
if (e === "none") return null;
|
|
401
|
+
const n = this._target().getBoundingClientRect(), s = t.clientX, o = t.clientY, a = s >= n.right - i && s <= n.right + i, d = s >= n.left - i && s <= n.left + i, l = o >= n.bottom - i && o <= n.bottom + i, h = o >= n.top - i && o <= n.top + i, u = s >= n.left && s <= n.right, c = o >= n.top && o <= n.bottom;
|
|
402
|
+
if (e === "both") {
|
|
403
|
+
if (a && l) return "se";
|
|
404
|
+
if (d && l) return "sw";
|
|
405
|
+
if (a && h) return "ne";
|
|
406
|
+
if (d && h) return "nw";
|
|
407
|
+
if (a && c) return "e";
|
|
408
|
+
if (d && c) return "w";
|
|
409
|
+
if (l && u) return "s";
|
|
410
|
+
if (h && u) return "n";
|
|
411
|
+
}
|
|
412
|
+
if (e === "horizontal") {
|
|
413
|
+
if (a && c) return "e";
|
|
414
|
+
if (d && c) return "w";
|
|
415
|
+
}
|
|
416
|
+
if (e === "vertical") {
|
|
417
|
+
if (l && u) return "s";
|
|
418
|
+
if (h && u) return "n";
|
|
419
|
+
}
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Pins position and size as explicit border-box pixel values.
|
|
424
|
+
*
|
|
425
|
+
* Required before any resize so that:
|
|
426
|
+
* - UA centering styles (`inset:0; margin:auto` on `<dialog>`) don't fight
|
|
427
|
+
* explicit left/top changes on n/w edges.
|
|
428
|
+
* - Changing width/height alone doesn't redistribute auto-margins and shift
|
|
429
|
+
* the element for e/s edges.
|
|
430
|
+
* - box-sizing is known, so `style.width = rect.width` is a no-op visually.
|
|
431
|
+
*/
|
|
432
|
+
_pinPosition(t) {
|
|
433
|
+
const e = t.getBoundingClientRect();
|
|
434
|
+
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;
|
|
435
|
+
}
|
|
436
|
+
_handlePointerDown(t) {
|
|
437
|
+
if (this._opts.disabled) return;
|
|
438
|
+
const e = this._detectEdge(t);
|
|
439
|
+
if (!e) return;
|
|
440
|
+
t.stopPropagation();
|
|
441
|
+
const i = this._target(), n = this._pinPosition(i);
|
|
442
|
+
this._startX = t.clientX, this._startY = t.clientY, this._startW = n.width, this._startH = n.height, this._startLeft = n.left, this._startTop = n.top, this._resizing = e;
|
|
443
|
+
const s = getComputedStyle(i);
|
|
444
|
+
this._effectiveMinW = Math.max(this._opts.minWidth, parseFloat(s.minWidth) || 0), this._effectiveMinH = Math.max(this._opts.minHeight, parseFloat(s.minHeight) || 0), i.setPointerCapture(t.pointerId), t.preventDefault();
|
|
445
|
+
}
|
|
446
|
+
_handlePointerMove(t) {
|
|
447
|
+
if (this._resizing) {
|
|
448
|
+
const n = this._target(), [s, o, a, d] = this._boundsRect(), { maxWidth: l, maxHeight: h } = this._opts, u = this._effectiveMinW, c = this._effectiveMinH, p = t.clientX - this._startX, m = t.clientY - this._startY, _ = this._resizing;
|
|
449
|
+
if (_ === "e" || _ === "se" || _ === "ne") {
|
|
450
|
+
const f = Math.min(l ?? 1 / 0, a - this._startLeft);
|
|
451
|
+
n.style.width = `${Math.min(Math.max(this._startW + p, u), f)}px`;
|
|
452
|
+
}
|
|
453
|
+
if (_ === "w" || _ === "sw" || _ === "nw") {
|
|
454
|
+
const f = this._startLeft + this._startW, g = Math.min(
|
|
455
|
+
Math.max(this._startLeft + p, s, l !== void 0 ? f - l : -1 / 0),
|
|
456
|
+
f - u
|
|
457
|
+
);
|
|
458
|
+
n.style.left = `${g}px`, n.style.width = `${f - g}px`;
|
|
459
|
+
}
|
|
460
|
+
if (_ === "s" || _ === "se" || _ === "sw") {
|
|
461
|
+
const f = Math.min(h ?? 1 / 0, d - this._startTop);
|
|
462
|
+
n.style.height = `${Math.min(Math.max(this._startH + m, c), f)}px`;
|
|
463
|
+
}
|
|
464
|
+
if (_ === "n" || _ === "ne" || _ === "nw") {
|
|
465
|
+
const f = this._startTop + this._startH, g = Math.min(
|
|
466
|
+
Math.max(this._startTop + m, o, h !== void 0 ? f - h : -1 / 0),
|
|
467
|
+
f - c
|
|
468
|
+
);
|
|
469
|
+
n.style.top = `${g}px`, n.style.height = `${f - g}px`;
|
|
470
|
+
}
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
if (this._opts.handle) return;
|
|
474
|
+
const e = this._detectEdge(t), i = this._target();
|
|
475
|
+
i.style.cursor = e ? this._edgeCursor(e) : "";
|
|
476
|
+
}
|
|
477
|
+
_handlePointerUp(t) {
|
|
478
|
+
this._resizing = null;
|
|
479
|
+
}
|
|
480
|
+
_handlePointerLeave(t) {
|
|
481
|
+
this._resizing || (this._target().style.cursor = "");
|
|
482
|
+
}
|
|
483
|
+
_handleKeyDown(t) {
|
|
484
|
+
if (this._opts.disabled) return;
|
|
485
|
+
const { direction: e } = this._opts, i = t.key === "ArrowRight" || t.key === "ArrowLeft", n = t.key === "ArrowDown" || t.key === "ArrowUp";
|
|
486
|
+
if (i && e === "vertical" || n && e === "horizontal" || !i && !n) return;
|
|
487
|
+
t.preventDefault(), t.stopPropagation();
|
|
488
|
+
const s = this._target(), o = this._pinPosition(s), a = t.shiftKey ? this._opts.step * 10 : this._opts.step, [, , d, l] = this._boundsRect(), { maxWidth: h, maxHeight: u } = this._opts, c = getComputedStyle(s), p = Math.max(this._opts.minWidth, parseFloat(c.minWidth) || 0), m = Math.max(this._opts.minHeight, parseFloat(c.minHeight) || 0);
|
|
489
|
+
if (t.key === "ArrowRight") {
|
|
490
|
+
const _ = Math.min(h ?? 1 / 0, d - o.left);
|
|
491
|
+
s.style.width = `${Math.min(Math.max(s.offsetWidth + a, p), _)}px`;
|
|
492
|
+
}
|
|
493
|
+
if (t.key === "ArrowLeft" && (s.style.width = `${Math.max(s.offsetWidth - a, p)}px`), t.key === "ArrowDown") {
|
|
494
|
+
const _ = Math.min(u ?? 1 / 0, l - o.top);
|
|
495
|
+
s.style.height = `${Math.min(Math.max(s.offsetHeight + a, m), _)}px`;
|
|
496
|
+
}
|
|
497
|
+
t.key === "ArrowUp" && (s.style.height = `${Math.max(s.offsetHeight - a, m)}px`);
|
|
498
|
+
}
|
|
499
|
+
_boundsRect() {
|
|
500
|
+
const { bounds: t } = this._opts;
|
|
501
|
+
if (!t || t === "viewport")
|
|
502
|
+
return [0, 0, window.innerWidth, window.innerHeight];
|
|
503
|
+
if (t === "parent") {
|
|
504
|
+
const i = this._opts.target.parentElement;
|
|
505
|
+
if (!i) return [0, 0, window.innerWidth, window.innerHeight];
|
|
506
|
+
const n = i.getBoundingClientRect();
|
|
507
|
+
return [n.left, n.top, n.right, n.bottom];
|
|
508
|
+
}
|
|
509
|
+
const e = t.getBoundingClientRect();
|
|
510
|
+
return [e.left, e.top, e.right, e.bottom];
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
function v(r, t) {
|
|
514
|
+
const e = `${t}px`;
|
|
515
|
+
switch (r) {
|
|
516
|
+
case "top":
|
|
517
|
+
return `position-area: top; margin-bottom: ${e};`;
|
|
518
|
+
case "top-start":
|
|
519
|
+
return `bottom: anchor(top); top: auto; left: anchor(left); right: auto; margin-bottom: ${e};`;
|
|
520
|
+
case "top-end":
|
|
521
|
+
return `bottom: anchor(top); top: auto; left: auto; right: anchor(right); margin-bottom: ${e};`;
|
|
522
|
+
case "bottom":
|
|
523
|
+
return `position-area: bottom; margin-top: ${e};`;
|
|
524
|
+
case "bottom-start":
|
|
525
|
+
return `top: anchor(bottom); bottom: auto; left: anchor(left); right: auto; margin-top: ${e};`;
|
|
526
|
+
case "bottom-end":
|
|
527
|
+
return `top: anchor(bottom); bottom: auto; left: auto; right: anchor(right); margin-top: ${e};`;
|
|
528
|
+
case "left":
|
|
529
|
+
return `position-area: left; margin-right: ${e};`;
|
|
530
|
+
case "left-start":
|
|
531
|
+
return `top: anchor(top); bottom: auto; right: anchor(left); left: auto; margin-right: ${e};`;
|
|
532
|
+
case "left-end":
|
|
533
|
+
return `top: auto; bottom: anchor(bottom); right: anchor(left); left: auto; margin-right: ${e};`;
|
|
534
|
+
case "right":
|
|
535
|
+
return `position-area: right; margin-left: ${e};`;
|
|
536
|
+
case "right-start":
|
|
537
|
+
return `top: anchor(top); bottom: auto; left: anchor(right); right: auto; margin-left: ${e};`;
|
|
538
|
+
case "right-end":
|
|
539
|
+
return `top: auto; bottom: anchor(bottom); left: anchor(right); right: auto; margin-left: ${e};`;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
const y = {
|
|
543
|
+
top: "bottom",
|
|
544
|
+
"top-start": "bottom-start",
|
|
545
|
+
"top-end": "bottom-end",
|
|
546
|
+
bottom: "top",
|
|
547
|
+
"bottom-start": "top-start",
|
|
548
|
+
"bottom-end": "top-end",
|
|
549
|
+
left: "right",
|
|
550
|
+
"left-start": "right-start",
|
|
551
|
+
"left-end": "right-end",
|
|
552
|
+
right: "left",
|
|
553
|
+
"right-start": "left-start",
|
|
554
|
+
"right-end": "left-end"
|
|
555
|
+
}, k = {
|
|
556
|
+
top: "top",
|
|
557
|
+
"top-start": "top-end",
|
|
558
|
+
"top-end": "top-start",
|
|
559
|
+
bottom: "bottom",
|
|
560
|
+
"bottom-start": "bottom-end",
|
|
561
|
+
"bottom-end": "bottom-start",
|
|
562
|
+
left: "left",
|
|
563
|
+
"left-start": "left-end",
|
|
564
|
+
"left-end": "left-start",
|
|
565
|
+
right: "right",
|
|
566
|
+
"right-start": "right-end",
|
|
567
|
+
"right-end": "right-start"
|
|
568
|
+
}, M = CSS.supports("position-try-fallbacks: flip-block");
|
|
569
|
+
let w = null, b = null;
|
|
570
|
+
function T() {
|
|
571
|
+
return M ? Promise.resolve(null) : (b || (b = import("./css-anchor-positioning-fn-hFYJeBk4.js").then((r) => (w = r.default, w)).catch(() => null)), b);
|
|
572
|
+
}
|
|
573
|
+
let D = 0;
|
|
574
|
+
class X {
|
|
575
|
+
constructor(t, e) {
|
|
576
|
+
this._styleEl = null, this._adoptedSheet = null, this._opts = e, this._uid = `rc-anchor-${++D}`, t.addController(this);
|
|
577
|
+
}
|
|
578
|
+
setOptions(t) {
|
|
579
|
+
Object.assign(this._opts, t), this._applyAndPolyfill();
|
|
580
|
+
}
|
|
581
|
+
/** Re-apply positioning — call when the popup opens or the anchor moves. */
|
|
582
|
+
update() {
|
|
583
|
+
this._applyAndPolyfill();
|
|
584
|
+
}
|
|
585
|
+
hostConnected() {
|
|
586
|
+
this._applyAndPolyfill();
|
|
587
|
+
}
|
|
588
|
+
hostDisconnected() {
|
|
589
|
+
this._cleanup();
|
|
590
|
+
}
|
|
591
|
+
_anchor() {
|
|
592
|
+
const { anchor: t } = this._opts;
|
|
593
|
+
return typeof t == "function" ? t() : t;
|
|
594
|
+
}
|
|
595
|
+
_floating() {
|
|
596
|
+
const { floating: t } = this._opts;
|
|
597
|
+
return typeof t == "function" ? t() : t;
|
|
598
|
+
}
|
|
599
|
+
_shadowHost() {
|
|
600
|
+
const { shadowHost: t } = this._opts;
|
|
601
|
+
return typeof t == "function" ? t() : t ?? null;
|
|
602
|
+
}
|
|
603
|
+
_applyAndPolyfill() {
|
|
604
|
+
this._apply(), M || this._applyPolyfillOrFallback();
|
|
605
|
+
}
|
|
606
|
+
async _applyPolyfillOrFallback() {
|
|
607
|
+
const t = await T(), e = this._shadowHost();
|
|
608
|
+
t ? await t({ roots: e ? [e] : void 0, useAnimationFrame: !1 }) : this._positionFallback();
|
|
609
|
+
}
|
|
610
|
+
_apply() {
|
|
611
|
+
if (this._opts.disabled) {
|
|
612
|
+
this._cleanup();
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
const t = this._anchor(), e = this._floating();
|
|
616
|
+
if (!t || !e) return;
|
|
617
|
+
const i = this._opts.placement ?? "bottom-start", n = this._opts.offset ?? 4, s = this._opts.flip ?? !0, o = `--${this._uid}`, a = this._uid;
|
|
618
|
+
t.style.setProperty("anchor-name", o), e.setAttribute("data-rc-anchor", a);
|
|
619
|
+
const d = y[i], l = k[i], h = y[l], u = s ? `
|
|
620
|
+
@position-try --${a}-end { ${v(l, n)} }
|
|
621
|
+
@position-try --${a}-flip { ${v(d, n)} }
|
|
622
|
+
@position-try --${a}-both { ${v(h, n)} }
|
|
623
|
+
` : "", c = s ? `position-try-fallbacks: --${a}-end, --${a}-flip, --${a}-both;` : "", p = `
|
|
624
|
+
${u}
|
|
625
|
+
[data-rc-anchor="${a}"] {
|
|
626
|
+
position: fixed;
|
|
627
|
+
position-anchor: ${o};
|
|
628
|
+
box-sizing: border-box;
|
|
629
|
+
min-width: anchor-size(width);
|
|
630
|
+
${v(i, n)}
|
|
631
|
+
${c}
|
|
632
|
+
}
|
|
633
|
+
`;
|
|
634
|
+
this._injectStyles(p);
|
|
635
|
+
}
|
|
636
|
+
_injectStyles(t) {
|
|
637
|
+
const e = this._shadowHost();
|
|
638
|
+
e?.shadowRoot ? (this._adoptedSheet || (this._adoptedSheet = new CSSStyleSheet(), e.shadowRoot.adoptedStyleSheets = [
|
|
639
|
+
...e.shadowRoot.adoptedStyleSheets,
|
|
640
|
+
this._adoptedSheet
|
|
641
|
+
]), this._adoptedSheet.replaceSync(t)) : (this._styleEl?.remove(), this._styleEl = document.createElement("style"), this._styleEl.setAttribute("data-rc-anchor-style", this._uid), this._styleEl.textContent = t, document.head.appendChild(this._styleEl));
|
|
642
|
+
}
|
|
643
|
+
_positionFallback() {
|
|
644
|
+
const t = this._anchor(), e = this._floating();
|
|
645
|
+
if (!t || !e) return;
|
|
646
|
+
const i = this._opts.placement ?? "bottom-start", n = this._opts.offset ?? 4, s = t.getBoundingClientRect(), o = window.innerWidth, a = window.innerHeight;
|
|
647
|
+
e.style.position = "fixed", e.style.boxSizing = "border-box", e.style.minWidth = `${s.width}px`;
|
|
648
|
+
const d = i.startsWith("bottom") || i === "bottom", l = a - s.bottom;
|
|
649
|
+
d && l < 120 && s.top > l ? (e.style.top = "", e.style.bottom = `${a - s.top + n}px`) : (e.style.bottom = "", e.style.top = `${s.bottom + n}px`);
|
|
650
|
+
const u = i.endsWith("-end"), c = e.offsetWidth || parseFloat(getComputedStyle(e).minWidth) || 0;
|
|
651
|
+
let p = u ? s.right - c : s.left;
|
|
652
|
+
p + c > o - 4 && (p = s.right - c), p = Math.max(4, Math.min(p, o - c - 4)), e.style.left = `${p}px`;
|
|
653
|
+
}
|
|
654
|
+
_cleanup() {
|
|
655
|
+
const t = this._anchor(), e = this._floating();
|
|
656
|
+
t && t.style.removeProperty("anchor-name"), e && e.removeAttribute("data-rc-anchor"), this._styleEl?.remove(), this._styleEl = null;
|
|
657
|
+
const i = this._shadowHost();
|
|
658
|
+
i?.shadowRoot && this._adoptedSheet && (i.shadowRoot.adoptedStyleSheets = i.shadowRoot.adoptedStyleSheets.filter(
|
|
659
|
+
(n) => n !== this._adoptedSheet
|
|
660
|
+
), this._adoptedSheet = null);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
class j {
|
|
664
|
+
constructor(t, e) {
|
|
665
|
+
this._attached = null, this._scrolled = !1, this._onScroll = () => this._evaluate(), this._host = t, this._opts = e, t.addController(this);
|
|
666
|
+
}
|
|
667
|
+
/** Whether the observed target is currently scrolled past the threshold. */
|
|
668
|
+
get scrolled() {
|
|
669
|
+
return this._scrolled;
|
|
670
|
+
}
|
|
671
|
+
/** Reconfigure the controller: detaches, merges options, and reattaches. */
|
|
672
|
+
setOptions(t) {
|
|
673
|
+
this._detach(), Object.assign(this._opts, t), this._attach();
|
|
674
|
+
}
|
|
675
|
+
hostConnected() {
|
|
676
|
+
this._attach();
|
|
677
|
+
}
|
|
678
|
+
hostDisconnected() {
|
|
679
|
+
this._detach();
|
|
680
|
+
}
|
|
681
|
+
_resolveTarget() {
|
|
682
|
+
const { target: t } = this._opts;
|
|
683
|
+
return typeof t == "function" ? t() : t ?? null;
|
|
684
|
+
}
|
|
685
|
+
_attach() {
|
|
686
|
+
if (this._opts.disabled || this._attached) return;
|
|
687
|
+
const t = this._resolveTarget();
|
|
688
|
+
t && (this._attached = t, t.addEventListener("scroll", this._onScroll, { passive: !0 }), this._evaluate());
|
|
689
|
+
}
|
|
690
|
+
_detach() {
|
|
691
|
+
this._attached?.removeEventListener("scroll", this._onScroll), this._attached = null, this._lastScrollTop = void 0;
|
|
692
|
+
}
|
|
693
|
+
_scrollTop() {
|
|
694
|
+
const t = this._attached;
|
|
695
|
+
return t instanceof Element ? t.scrollTop : t instanceof Document ? t.scrollingElement?.scrollTop ?? 0 : t?.scrollY ?? 0;
|
|
696
|
+
}
|
|
697
|
+
_evaluate() {
|
|
698
|
+
if (!this._attached) return;
|
|
699
|
+
const t = this._scrollTop(), e = t - (this._lastScrollTop ?? t);
|
|
700
|
+
this._lastScrollTop = t, this._opts.onScroll?.(t, e);
|
|
701
|
+
const i = t > (this._opts.threshold ?? 4);
|
|
702
|
+
i !== this._scrolled && (this._scrolled = i, this._opts.onChange?.(i, t), this._host.requestUpdate());
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
function $(r) {
|
|
706
|
+
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);
|
|
707
|
+
}
|
|
708
|
+
var S = Object.defineProperty, R = (r, t, e, i) => {
|
|
709
|
+
for (var n = void 0, s = r.length - 1, o; s >= 0; s--)
|
|
710
|
+
(o = r[s]) && (n = o(t, e, n) || n);
|
|
711
|
+
return n && S(t, e, n), n;
|
|
712
|
+
};
|
|
713
|
+
function V(r) {
|
|
714
|
+
class t extends r {
|
|
715
|
+
constructor() {
|
|
716
|
+
super(...arguments), this._items = [];
|
|
717
|
+
}
|
|
718
|
+
get items() {
|
|
719
|
+
return this._items.map((i) => i.deref()).filter((i) => $(i));
|
|
720
|
+
}
|
|
721
|
+
get firstItem() {
|
|
722
|
+
return this.items.at(0);
|
|
723
|
+
}
|
|
724
|
+
get lastItem() {
|
|
725
|
+
return this.items.at(-1);
|
|
726
|
+
}
|
|
727
|
+
get nextItem() {
|
|
728
|
+
const i = this._lastFocused ? this.items.indexOf(this._lastFocused) : 0;
|
|
729
|
+
return this.items.at((i + 1) % this.items.length);
|
|
730
|
+
}
|
|
731
|
+
get previousItem() {
|
|
732
|
+
const i = this._lastFocused ? this.items.indexOf(this._lastFocused) : 0;
|
|
733
|
+
return this.items.at((i - 1) % this.items.length);
|
|
734
|
+
}
|
|
735
|
+
focusItem(i) {
|
|
736
|
+
i?.focus();
|
|
737
|
+
}
|
|
738
|
+
focusItemAt(i) {
|
|
739
|
+
this.focusItem(this.items.at(i));
|
|
740
|
+
}
|
|
741
|
+
focusFirst() {
|
|
742
|
+
this.focusItem(this.firstItem);
|
|
743
|
+
}
|
|
744
|
+
focusLast() {
|
|
745
|
+
this.focusItem(this.lastItem);
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Returns the elements to register from a slot.
|
|
749
|
+
*
|
|
750
|
+
* Override in subclasses to customise item collection — for example, to
|
|
751
|
+
* traverse into `role="group"` containers or to skip `role="separator"`
|
|
752
|
+
* elements. The default collects ALL direct assigned elements; the `items`
|
|
753
|
+
* getter then filters by `isFocusable` at access time so that elements
|
|
754
|
+
* toggling `disabled` are reflected without a new `slotchange`.
|
|
755
|
+
*/
|
|
756
|
+
_collectItems(i) {
|
|
757
|
+
return i.assignedElements();
|
|
758
|
+
}
|
|
759
|
+
_handleItemFocus(i) {
|
|
760
|
+
const n = i.composedPath().find(
|
|
761
|
+
(s) => this.items.includes(s)
|
|
762
|
+
);
|
|
763
|
+
n != null && (this._lastFocused = n, this.items.forEach((s) => s.setAttribute("tabindex", "-1")), n.setAttribute("tabindex", "0"));
|
|
764
|
+
}
|
|
765
|
+
_onSlotChange(i) {
|
|
766
|
+
const n = this._items;
|
|
767
|
+
this._items = this._collectItems(i.currentTarget).map((s) => new WeakRef(s)), queueMicrotask(() => {
|
|
768
|
+
this.isConnected && (n.forEach((s) => s.deref()?.removeAttribute("tabindex")), this._initItems());
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Called after slot contents change and the item list is rebuilt.
|
|
773
|
+
* Override to configure items (set ARIA roles, move focus, etc.).
|
|
774
|
+
*
|
|
775
|
+
* Default implementation sets `tabindex="-1"` on all collected elements
|
|
776
|
+
* (including currently-disabled ones, so they don't enter the tab order
|
|
777
|
+
* if re-enabled before the next slotchange) and `tabindex="0"` on the
|
|
778
|
+
* first currently-focusable item.
|
|
779
|
+
*/
|
|
780
|
+
_initItems() {
|
|
781
|
+
this._items.forEach((n) => n.deref()?.setAttribute("tabindex", "-1"));
|
|
782
|
+
const i = this.items[0];
|
|
783
|
+
i && i.setAttribute("tabindex", "0");
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
return R([
|
|
787
|
+
A()
|
|
788
|
+
], t.prototype, "_lastFocused"), t;
|
|
789
|
+
}
|
|
790
|
+
function q(r, t, e, i) {
|
|
791
|
+
const n = Math.min(Math.max(r, t), e);
|
|
792
|
+
if (i <= 0) return n;
|
|
793
|
+
const s = Math.round((n - t) / i) * i + t;
|
|
794
|
+
return Math.min(Math.max(s, t), e);
|
|
795
|
+
}
|
|
796
|
+
function G(r, t, e) {
|
|
797
|
+
return e === t ? 0 : Math.min(Math.max((r - t) / (e - t), 0), 1);
|
|
798
|
+
}
|
|
799
|
+
export {
|
|
800
|
+
U as ActiveDescendantController,
|
|
801
|
+
X as AnchorController,
|
|
802
|
+
N as DragController,
|
|
803
|
+
Y as ResizeController,
|
|
804
|
+
V as RovingTabIndexMixin,
|
|
805
|
+
j as ScrollObserverController,
|
|
806
|
+
$ as isFocusable,
|
|
807
|
+
K as keyNavigation,
|
|
808
|
+
O as mouseMove,
|
|
809
|
+
q as snapToStep,
|
|
810
|
+
G as valueToPercent
|
|
811
|
+
};
|