@rcarls/rc-common 0.5.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.
- package/CHANGELOG.md +315 -0
- package/README.md +167 -50
- package/dist/modules/ActiveDescendantController.js +89 -0
- package/dist/modules/AnchorController.js +317 -0
- package/dist/modules/ControllerEffects.js +60 -0
- package/dist/modules/DragController.js +128 -0
- package/dist/modules/DragGestureController.js +174 -0
- package/dist/modules/FlowController.js +35 -0
- package/dist/modules/ItemsCollectionController.js +233 -0
- package/dist/modules/KeyboardInteractionDirective.js +39 -0
- package/dist/modules/KeyboardNavigationDirective.js +88 -0
- package/dist/modules/LiveAnnouncer.js +36 -0
- package/dist/modules/MutationObserverController.js +30 -0
- package/dist/modules/NavigationIndicatorController.js +81 -0
- package/dist/modules/PopoverController.js +44 -0
- package/dist/modules/RafScheduler.js +83 -0
- package/dist/modules/ReorderController.js +361 -0
- package/dist/modules/ResizeController.js +425 -0
- package/dist/modules/RovingTabIndexMixin.js +87 -0
- package/dist/modules/ScrollObserverController.js +78 -0
- package/dist/modules/TypeaheadController.js +59 -0
- package/dist/modules/anchorPlacement.js +13 -0
- package/dist/modules/clickDelegate.js +31 -0
- package/dist/modules/cssText.js +6 -0
- package/dist/modules/cssTime.js +11 -0
- package/dist/modules/cssZoom.js +16 -0
- package/dist/modules/findNearestScrollAncestor.js +22 -0
- package/dist/modules/flow.js +94 -0
- package/dist/modules/isFocusable.js +6 -0
- package/dist/modules/localeFormat.js +38 -0
- package/dist/modules/messages.js +77 -0
- package/dist/modules/nativeChild.js +37 -0
- package/dist/modules/observeLocale.js +70 -0
- package/dist/modules/sliderUtils.js +14 -0
- package/dist/modules/snapUtils.js +25 -0
- package/dist/modules/softKeyboard.js +72 -0
- package/dist/modules/visualViewport.js +14 -0
- package/dist/rc-common.js +99 -1575
- package/dist/rc-common.umd.cjs +10 -26
- package/dist/types/AnchorController.d.ts +82 -12
- package/dist/types/ControllerEffects.d.ts +15 -0
- package/dist/types/DragController.d.ts +13 -0
- package/dist/types/DragGestureController.d.ts +31 -7
- package/dist/types/FlowController.d.ts +31 -0
- package/dist/types/ItemsCollectionController.d.ts +3 -2
- package/dist/types/KeyboardInteractionDirective.d.ts +1 -2
- package/dist/types/KeyboardNavigationDirective.d.ts +16 -7
- package/dist/types/LiveAnnouncer.d.ts +22 -0
- package/dist/types/MutationObserverController.d.ts +0 -1
- package/dist/types/NavigationIndicatorController.d.ts +1 -1
- package/dist/types/PopoverController.d.ts +21 -0
- package/dist/types/RafScheduler.d.ts +36 -1
- package/dist/types/ReorderController.d.ts +131 -0
- package/dist/types/ResizeController.d.ts +46 -0
- package/dist/types/RovingTabIndexMixin.d.ts +1 -1
- package/dist/types/ScrollObserverController.d.ts +13 -2
- package/dist/types/TypeaheadController.d.ts +8 -2
- package/dist/types/anchorPlacement.d.ts +24 -0
- package/dist/types/clickDelegate.d.ts +69 -0
- package/dist/types/cssText.d.ts +17 -0
- package/dist/types/cssTime.d.ts +14 -0
- package/dist/types/cssZoom.d.ts +12 -0
- package/dist/types/findNearestScrollAncestor.d.ts +3 -3
- package/dist/types/flow.d.ts +121 -0
- package/dist/types/index.d.ts +33 -20
- package/dist/types/localeFormat.d.ts +4 -0
- package/dist/types/messages.d.ts +105 -0
- package/dist/types/nativeChild.d.ts +0 -3
- package/dist/types/observeLocale.d.ts +23 -0
- package/dist/types/softKeyboard.d.ts +79 -0
- package/dist/types/visualViewport.d.ts +21 -0
- package/package.json +1 -4
- package/dist/css-anchor-positioning-fn-hFYJeBk4.js +0 -6371
- package/dist/types/DragGestureController.test.d.ts +0 -1
- package/dist/types/KeyboardInteractionDirective.test.d.ts +0 -1
- package/dist/types/KeyboardNavigationDirective.test.d.ts +0 -1
- package/dist/types/MouseMoveDirective.d.ts +0 -42
- package/dist/types/MouseMoveDirective.test.d.ts +0 -1
- package/dist/types/MutationObserverController.test.d.ts +0 -1
- package/dist/types/RafScheduler.test.d.ts +0 -1
- package/dist/types/ScrollObserverController.test.d.ts +0 -1
- package/dist/types/TypeaheadController.test.d.ts +0 -1
- package/dist/types/isFocusable.test.d.ts +0 -1
- package/dist/types/nativeChild.test.d.ts +0 -1
- package/dist/types/snapUtils.unit.test.d.ts +0 -1
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import { ControllerEffects as p } from "./ControllerEffects.js";
|
|
2
|
+
import { cssZoom as g } from "./cssZoom.js";
|
|
3
|
+
import { DragGestureController as w } from "./DragGestureController.js";
|
|
4
|
+
import { resolveFlow as y, isPhysicalReversed as m } from "./flow.js";
|
|
5
|
+
import { resolveMessages as v } from "./messages.js";
|
|
6
|
+
import { observeLocale as E } from "./observeLocale.js";
|
|
7
|
+
const b = Object.freeze({
|
|
8
|
+
grip: "Resize"
|
|
9
|
+
});
|
|
10
|
+
function z(a) {
|
|
11
|
+
const t = a.getBoundingClientRect(), e = a.offsetParent, i = g(a), s = e ? (t.left - e.getBoundingClientRect().left) / i - e.clientLeft + e.scrollLeft : t.left / i, n = e ? (t.top - e.getBoundingClientRect().top) / i - e.clientTop + e.scrollTop : t.top / i;
|
|
12
|
+
return getComputedStyle(a).position === "static" && (a.style.position = "fixed"), a.style.translate = "none", a.style.inset = "auto", a.style.margin = "0", a.style.boxSizing = "border-box", a.style.left = `${s}px`, a.style.top = `${n}px`, a.style.width = `${t.width / i}px`, a.style.height = `${t.height / i}px`, t;
|
|
13
|
+
}
|
|
14
|
+
class H {
|
|
15
|
+
constructor(t, e) {
|
|
16
|
+
this._resizing = null, this._startW = 0, this._startH = 0, this._startLeft = 0, this._startTop = 0, this._zoom = 1, 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._handleEffects = /* @__PURE__ */ new Map(), this._targetEffects = null, this._positionEffects = null, this._flowEffects = null, this._connected = !1, this._disposed = !1, this._onFlowInteraction = () => this._syncFlowStyles(), this._host = t, this._opts = {
|
|
17
|
+
direction: "none",
|
|
18
|
+
threshold: 8,
|
|
19
|
+
step: 4,
|
|
20
|
+
disabled: !1,
|
|
21
|
+
minWidth: 100,
|
|
22
|
+
minHeight: 60,
|
|
23
|
+
handle: null,
|
|
24
|
+
origin: "",
|
|
25
|
+
bounds: "viewport",
|
|
26
|
+
...e
|
|
27
|
+
}, this._onPointerMove = this._handlePointerMove.bind(this), this._onPointerLeave = this._handlePointerLeave.bind(this), this._onKeyDown = this._handleKeyDown.bind(this), this._gesture = new w(t, {
|
|
28
|
+
target: () => this._handle() ?? this._target(),
|
|
29
|
+
// A resize starts only after the pointer moves past the activation
|
|
30
|
+
// distance, like Android's touch slop, so a tap on a handle that is
|
|
31
|
+
// also a button stays a click and doesn't resize and settle first.
|
|
32
|
+
activation: "axis",
|
|
33
|
+
capture: !0,
|
|
34
|
+
stopPropagation: !0,
|
|
35
|
+
canStart: (i) => this._canStartGesture(i),
|
|
36
|
+
onStart: (i) => this._startGestureResize(i),
|
|
37
|
+
onMove: (i) => this._moveGestureResize(i),
|
|
38
|
+
onEnd: (i) => this._endGestureResize(i),
|
|
39
|
+
onCancel: () => this._cancelResize()
|
|
40
|
+
}), t.addController(this);
|
|
41
|
+
}
|
|
42
|
+
/** Reconfigures resize behavior, replacing bindings when the handle or target changes. */
|
|
43
|
+
setOptions(t) {
|
|
44
|
+
if (this._disposed)
|
|
45
|
+
return;
|
|
46
|
+
const e = this._opts.target, i = this._opts.handle, s = this._opts.direction !== "none", n = this._connected, o = t.target !== void 0 && t.target !== e || t.handle !== void 0 && t.handle !== i || t.direction !== void 0 && t.direction !== "none" !== s;
|
|
47
|
+
n && o && this.hostDisconnected(), Object.assign(this._opts, t), this._gesture.setOptions({ target: () => this._handle() ?? this._target() }), n && o ? this.hostConnected() : n && this._syncFlowStyles();
|
|
48
|
+
}
|
|
49
|
+
hostConnected() {
|
|
50
|
+
if (this._disposed || this._connected || (this._connected = !0, this._opts.direction === "none"))
|
|
51
|
+
return;
|
|
52
|
+
if (this._observeFlow(), this._opts.handle) {
|
|
53
|
+
this._attachToHandle(this._opts.handle);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const t = this._target();
|
|
57
|
+
this._targetEffects = new p(), this._targetEffects.listen(t, "pointermove", this._onPointerMove), this._targetEffects.listen(t, "pointerleave", this._onPointerLeave), this._injectCornerButton();
|
|
58
|
+
}
|
|
59
|
+
hostDisconnected() {
|
|
60
|
+
this._connected = !1, this._unobserveFlow(), this._opts.handle && this._detachFromHandle(this._opts.handle), this._removeCornerButton(), this._targetEffects?.dispose(), this._targetEffects = null, this._positionEffects?.dispose(), this._positionEffects = null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Detaches every listener, injected grip, and handle style, then removes
|
|
64
|
+
* the controller (and its gesture) from the host for good. Use it to
|
|
65
|
+
* replace a controller when resize options change after setup.
|
|
66
|
+
*/
|
|
67
|
+
dispose() {
|
|
68
|
+
this._disposed || (this._disposed = !0, this._gesture.dispose(), this._cancelResize(), this.hostDisconnected(), this._host.removeController(this));
|
|
69
|
+
}
|
|
70
|
+
_target() {
|
|
71
|
+
return this._opts.target;
|
|
72
|
+
}
|
|
73
|
+
_handle() {
|
|
74
|
+
return this._opts.handle;
|
|
75
|
+
}
|
|
76
|
+
_attachToHandle(t) {
|
|
77
|
+
if (!t || this._opts.direction === "none" || this._handleEffects.has(t))
|
|
78
|
+
return;
|
|
79
|
+
const e = new p();
|
|
80
|
+
e.listen(t, "keydown", this._onKeyDown), e.setStyle(t, "cursor", this._edgeCursor(this._handleEdge())), e.setStyle(t, "touch-action", "none"), t.hasAttribute("tabindex") || e.setAttribute(t, "tabindex", "0"), this._handleEffects.set(t, e);
|
|
81
|
+
}
|
|
82
|
+
_observeFlow() {
|
|
83
|
+
if (this._flowEffects)
|
|
84
|
+
return;
|
|
85
|
+
const t = new p();
|
|
86
|
+
t.add(E(this._onFlowInteraction, this._target())), t.listen(this._handle() ?? this._target(), "pointerenter", this._onFlowInteraction), this._flowEffects = t;
|
|
87
|
+
}
|
|
88
|
+
_unobserveFlow() {
|
|
89
|
+
this._flowEffects?.dispose(), this._flowEffects = null;
|
|
90
|
+
}
|
|
91
|
+
/** Re-places the corner grip and re-derives handle cursors from the current flow. */
|
|
92
|
+
_syncFlowStyles() {
|
|
93
|
+
if (this._resizing)
|
|
94
|
+
return;
|
|
95
|
+
const t = this._handle();
|
|
96
|
+
t && this._handleEffects.get(t)?.setStyle(t, "cursor", this._edgeCursor(this._handleEdge())), this._cornerBtn && (this._placeCornerButton(this._cornerBtn), this._labelCornerButton(this._cornerBtn));
|
|
97
|
+
}
|
|
98
|
+
_detachFromHandle(t) {
|
|
99
|
+
t && (this._handleEffects.get(t)?.dispose(), this._handleEffects.delete(t));
|
|
100
|
+
}
|
|
101
|
+
_injectCornerButton() {
|
|
102
|
+
if (this._opts.handle)
|
|
103
|
+
return;
|
|
104
|
+
const t = this._target();
|
|
105
|
+
getComputedStyle(t).position === "static" && (this._positionEffects = new p(), this._positionEffects.setStyle(t, "position", "relative"));
|
|
106
|
+
const e = document.createElement("button");
|
|
107
|
+
e.setAttribute("data-rc-resize-corner", ""), e.type = "button", Object.assign(e.style, {
|
|
108
|
+
position: "absolute",
|
|
109
|
+
width: "12px",
|
|
110
|
+
height: "12px",
|
|
111
|
+
padding: "0",
|
|
112
|
+
border: "none",
|
|
113
|
+
background: "transparent",
|
|
114
|
+
zIndex: "1"
|
|
115
|
+
}), this._placeCornerButton(e), this._labelCornerButton(e), e.addEventListener("keydown", this._onKeyDown), e.addEventListener("focus", this._onFlowInteraction), this._targetEffects?.append(t, e), this._cornerBtn = e;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Puts the grip at the end corner, where browsers put the native resize
|
|
119
|
+
* grip: bottom-left in RTL and in vertical-rl.
|
|
120
|
+
*/
|
|
121
|
+
_placeCornerButton(t) {
|
|
122
|
+
const { x: e, y: i } = this._endEdges();
|
|
123
|
+
Object.assign(t.style, {
|
|
124
|
+
top: i === "n" ? "0" : "",
|
|
125
|
+
bottom: i === "s" ? "0" : "",
|
|
126
|
+
left: e === "w" ? "0" : "",
|
|
127
|
+
right: e === "e" ? "0" : "",
|
|
128
|
+
cursor: this._cornerCursor()
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/** Names the grip in the target's locale; the flow observer re-runs it when `lang` changes. */
|
|
132
|
+
_labelCornerButton(t) {
|
|
133
|
+
const { grip: e } = v(
|
|
134
|
+
this._target(),
|
|
135
|
+
"resize",
|
|
136
|
+
b,
|
|
137
|
+
this._opts.messages
|
|
138
|
+
);
|
|
139
|
+
t.getAttribute("aria-label") !== e && t.setAttribute("aria-label", e);
|
|
140
|
+
}
|
|
141
|
+
_removeCornerButton() {
|
|
142
|
+
this._cornerBtn && (this._cornerBtn.removeEventListener("keydown", this._onKeyDown), this._cornerBtn.removeEventListener("focus", this._onFlowInteraction), this._cornerBtn.remove(), this._cornerBtn = null);
|
|
143
|
+
}
|
|
144
|
+
_cornerCursor() {
|
|
145
|
+
switch (this._opts.direction) {
|
|
146
|
+
case "both":
|
|
147
|
+
return `${this._defaultHandleEdge()}-resize`;
|
|
148
|
+
case "horizontal":
|
|
149
|
+
return "ew-resize";
|
|
150
|
+
case "vertical":
|
|
151
|
+
return "ns-resize";
|
|
152
|
+
default:
|
|
153
|
+
return "default";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
_edgeCursor(t) {
|
|
157
|
+
return {
|
|
158
|
+
n: "n-resize",
|
|
159
|
+
s: "s-resize",
|
|
160
|
+
e: "e-resize",
|
|
161
|
+
w: "w-resize",
|
|
162
|
+
ne: "ne-resize",
|
|
163
|
+
nw: "nw-resize",
|
|
164
|
+
se: "se-resize",
|
|
165
|
+
sw: "sw-resize"
|
|
166
|
+
}[t];
|
|
167
|
+
}
|
|
168
|
+
_handleEdge() {
|
|
169
|
+
return this._edgeForOrigin(this._opts.origin) ?? this._defaultHandleEdge();
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The physical edges at the target's end corner, where a resize grip and
|
|
173
|
+
* keyboard resizing act by default: right and bottom in LTR, left in RTL
|
|
174
|
+
* and in vertical-rl, top where the inline axis runs bottom to top.
|
|
175
|
+
*/
|
|
176
|
+
_endEdges() {
|
|
177
|
+
const t = y(this._target());
|
|
178
|
+
return {
|
|
179
|
+
x: m("x", t) ? "w" : "e",
|
|
180
|
+
y: m("y", t) ? "n" : "s"
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
_defaultHandleEdge() {
|
|
184
|
+
const { x: t, y: e } = this._endEdges();
|
|
185
|
+
switch (this._opts.direction) {
|
|
186
|
+
case "horizontal":
|
|
187
|
+
return t;
|
|
188
|
+
case "vertical":
|
|
189
|
+
return e;
|
|
190
|
+
default:
|
|
191
|
+
return `${e}${t}`;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
_edgeForOrigin(t) {
|
|
195
|
+
if (!t)
|
|
196
|
+
return null;
|
|
197
|
+
const e = t.includes("top"), i = t.includes("bottom"), s = t.includes("left"), n = t.includes("right");
|
|
198
|
+
if (this._opts.direction === "vertical")
|
|
199
|
+
return e ? "n" : i ? "s" : null;
|
|
200
|
+
if (this._opts.direction === "horizontal")
|
|
201
|
+
return s ? "w" : n ? "e" : null;
|
|
202
|
+
if (this._opts.direction === "both") {
|
|
203
|
+
if (e && s)
|
|
204
|
+
return "nw";
|
|
205
|
+
if (e && n)
|
|
206
|
+
return "ne";
|
|
207
|
+
if (i && s)
|
|
208
|
+
return "sw";
|
|
209
|
+
if (i && n)
|
|
210
|
+
return "se";
|
|
211
|
+
if (e)
|
|
212
|
+
return "n";
|
|
213
|
+
if (i)
|
|
214
|
+
return "s";
|
|
215
|
+
if (s)
|
|
216
|
+
return "w";
|
|
217
|
+
if (n)
|
|
218
|
+
return "e";
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
_edgeAllowsPointer(t, e) {
|
|
223
|
+
const { threshold: i } = this._opts, s = this._target().getBoundingClientRect(), n = e.clientX, o = e.clientY, h = n >= s.right - i && n <= s.right + i, c = n >= s.left - i && n <= s.left + i, l = o >= s.bottom - i && o <= s.bottom + i, _ = o >= s.top - i && o <= s.top + i, f = n >= s.left && n <= s.right, d = o >= s.top && o <= s.bottom;
|
|
224
|
+
switch (t) {
|
|
225
|
+
case "n":
|
|
226
|
+
return _ && f;
|
|
227
|
+
case "s":
|
|
228
|
+
return l && f;
|
|
229
|
+
case "e":
|
|
230
|
+
return h && d;
|
|
231
|
+
case "w":
|
|
232
|
+
return c && d;
|
|
233
|
+
case "ne":
|
|
234
|
+
return _ && h;
|
|
235
|
+
case "nw":
|
|
236
|
+
return _ && c;
|
|
237
|
+
case "se":
|
|
238
|
+
return l && h;
|
|
239
|
+
case "sw":
|
|
240
|
+
return l && c;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
_detectEdge(t) {
|
|
244
|
+
const { direction: e, threshold: i } = this._opts;
|
|
245
|
+
if (e === "none")
|
|
246
|
+
return null;
|
|
247
|
+
const s = this._edgeForOrigin(this._opts.origin);
|
|
248
|
+
if (s)
|
|
249
|
+
return this._edgeAllowsPointer(s, t) ? s : null;
|
|
250
|
+
const n = this._target().getBoundingClientRect(), o = t.clientX, h = t.clientY, c = o >= n.right - i && o <= n.right + i, l = o >= n.left - i && o <= n.left + i, _ = h >= n.bottom - i && h <= n.bottom + i, f = h >= n.top - i && h <= n.top + i, d = o >= n.left && o <= n.right, r = h >= n.top && h <= n.bottom;
|
|
251
|
+
if (e === "both") {
|
|
252
|
+
if (c && _)
|
|
253
|
+
return "se";
|
|
254
|
+
if (l && _)
|
|
255
|
+
return "sw";
|
|
256
|
+
if (c && f)
|
|
257
|
+
return "ne";
|
|
258
|
+
if (l && f)
|
|
259
|
+
return "nw";
|
|
260
|
+
if (c && r)
|
|
261
|
+
return "e";
|
|
262
|
+
if (l && r)
|
|
263
|
+
return "w";
|
|
264
|
+
if (_ && d)
|
|
265
|
+
return "s";
|
|
266
|
+
if (f && d)
|
|
267
|
+
return "n";
|
|
268
|
+
}
|
|
269
|
+
if (e === "horizontal") {
|
|
270
|
+
if (c && r)
|
|
271
|
+
return "e";
|
|
272
|
+
if (l && r)
|
|
273
|
+
return "w";
|
|
274
|
+
}
|
|
275
|
+
if (e === "vertical") {
|
|
276
|
+
if (_ && d)
|
|
277
|
+
return "s";
|
|
278
|
+
if (f && d)
|
|
279
|
+
return "n";
|
|
280
|
+
}
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
_pinPosition(t) {
|
|
284
|
+
return z(t);
|
|
285
|
+
}
|
|
286
|
+
_canStartGesture(t) {
|
|
287
|
+
if (this._opts.disabled || this._opts.direction === "none")
|
|
288
|
+
return !1;
|
|
289
|
+
const i = this._handle() ? this._handleEdge() : this._detectEdge(t);
|
|
290
|
+
return this._pendingEdge = i, i !== null;
|
|
291
|
+
}
|
|
292
|
+
_startGestureResize(t) {
|
|
293
|
+
this._pendingEdge && (this._velocityX = 0, this._velocityY = 0, this._startResize(this._pendingEdge));
|
|
294
|
+
}
|
|
295
|
+
_moveGestureResize(t) {
|
|
296
|
+
this._resizing && (this._lastDeltaX = t.deltaX, this._lastDeltaY = t.deltaY, this._velocityX = t.velocityX, this._velocityY = t.velocityY, this._applyDelta(this._resizing, t.deltaX / this._zoom, t.deltaY / this._zoom), this._opts.onResize?.(this._lifecycleDetail("pointer")));
|
|
297
|
+
}
|
|
298
|
+
_endGestureResize(t) {
|
|
299
|
+
this._velocityX = t.velocityX, this._velocityY = t.velocityY, this._finishResize("pointer");
|
|
300
|
+
}
|
|
301
|
+
_startResize(t) {
|
|
302
|
+
this._positionEffects?.abandon(), this._positionEffects = null;
|
|
303
|
+
const e = this._target();
|
|
304
|
+
this._pinPosition(e), this._zoom = g(e), this._startW = Number.parseFloat(e.style.width), this._startH = Number.parseFloat(e.style.height), this._startLeft = Number.parseFloat(e.style.left), this._startTop = Number.parseFloat(e.style.top), this._lastDeltaX = 0, this._lastDeltaY = 0, this._resizing = t, this._computeEffectiveExtents(e), this._opts.onResizeStart?.(this._lifecycleDetail("pointer"));
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Computed once per resize gesture (pointer-down or keyboard step) so the
|
|
308
|
+
* browser's enforcement of CSS min/max-width/height doesn't fight the JS
|
|
309
|
+
* math — otherwise a CSS-only max (e.g. a themed `max-block-size`) clips
|
|
310
|
+
* the rendered box while the pinned edge keeps moving, making the whole
|
|
311
|
+
* element appear to slide once dragged past its extent.
|
|
312
|
+
*/
|
|
313
|
+
_computeEffectiveExtents(t) {
|
|
314
|
+
const e = getComputedStyle(t);
|
|
315
|
+
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(
|
|
316
|
+
this._opts.maxWidth ?? 1 / 0,
|
|
317
|
+
parseFloat(e.maxWidth) || 1 / 0
|
|
318
|
+
), this._effectiveMaxH = Math.min(
|
|
319
|
+
this._opts.maxHeight ?? 1 / 0,
|
|
320
|
+
parseFloat(e.maxHeight) || 1 / 0
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
_lifecycleDetail(t) {
|
|
324
|
+
const e = this._target();
|
|
325
|
+
return {
|
|
326
|
+
edge: this._resizing ?? this._handleEdge(),
|
|
327
|
+
inputType: t,
|
|
328
|
+
startWidth: this._startW * this._zoom,
|
|
329
|
+
startHeight: this._startH * this._zoom,
|
|
330
|
+
width: e.getBoundingClientRect().width,
|
|
331
|
+
height: e.getBoundingClientRect().height,
|
|
332
|
+
deltaX: this._lastDeltaX,
|
|
333
|
+
deltaY: this._lastDeltaY,
|
|
334
|
+
velocityX: t === "pointer" ? this._velocityX : 0,
|
|
335
|
+
velocityY: t === "pointer" ? this._velocityY : 0
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
_handlePointerMove(t) {
|
|
339
|
+
if (this._resizing || this._opts.handle)
|
|
340
|
+
return;
|
|
341
|
+
const e = this._detectEdge(t), i = this._target();
|
|
342
|
+
this._targetEffects?.setStyle(i, "cursor", e ? this._edgeCursor(e) : "");
|
|
343
|
+
}
|
|
344
|
+
_finishResize(t) {
|
|
345
|
+
if (!this._resizing)
|
|
346
|
+
return;
|
|
347
|
+
const e = this._lifecycleDetail(t);
|
|
348
|
+
this._resizing = null, this._pendingEdge = null, this._opts.onResizeEnd?.(e);
|
|
349
|
+
}
|
|
350
|
+
_cancelResize() {
|
|
351
|
+
this._resizing = null, this._pendingEdge = null;
|
|
352
|
+
}
|
|
353
|
+
_handlePointerLeave(t) {
|
|
354
|
+
this._resizing || this._targetEffects?.setStyle(this._target(), "cursor", "");
|
|
355
|
+
}
|
|
356
|
+
_handleKeyDown(t) {
|
|
357
|
+
if (this._opts.disabled || this._opts.direction === "none")
|
|
358
|
+
return;
|
|
359
|
+
const { direction: e } = this._opts, i = t.key === "ArrowRight" || t.key === "ArrowLeft", s = t.key === "ArrowDown" || t.key === "ArrowUp";
|
|
360
|
+
if (i && e === "vertical" || s && e === "horizontal" || !i && !s)
|
|
361
|
+
return;
|
|
362
|
+
t.preventDefault(), t.stopPropagation();
|
|
363
|
+
const n = this._target();
|
|
364
|
+
this._positionEffects?.abandon(), this._positionEffects = null, this._pinPosition(n);
|
|
365
|
+
const o = this._keyboardEdge(t.key);
|
|
366
|
+
if (!o)
|
|
367
|
+
return;
|
|
368
|
+
this._resizing = o, this._zoom = g(n), this._startW = Number.parseFloat(n.style.width), this._startH = Number.parseFloat(n.style.height), this._startLeft = Number.parseFloat(n.style.left), this._startTop = Number.parseFloat(n.style.top);
|
|
369
|
+
const h = t.shiftKey ? this._opts.step * 10 : this._opts.step;
|
|
370
|
+
this._computeEffectiveExtents(n);
|
|
371
|
+
const c = t.key === "ArrowRight" ? h : t.key === "ArrowLeft" ? -h : 0, l = t.key === "ArrowDown" ? h : t.key === "ArrowUp" ? -h : 0;
|
|
372
|
+
this._lastDeltaX = c, this._lastDeltaY = l, this._applyDelta(o, c, l), this._opts.onResize?.(this._lifecycleDetail("keyboard")), this._finishResize("keyboard");
|
|
373
|
+
}
|
|
374
|
+
_keyboardEdge(t) {
|
|
375
|
+
const e = this._edgeForOrigin(this._opts.origin);
|
|
376
|
+
if (e)
|
|
377
|
+
return e;
|
|
378
|
+
const { x: i, y: s } = this._endEdges();
|
|
379
|
+
return t === "ArrowRight" || t === "ArrowLeft" ? this._opts.direction === "both" || this._opts.direction === "horizontal" ? i : null : (t === "ArrowDown" || t === "ArrowUp") && (this._opts.direction === "both" || this._opts.direction === "vertical") ? s : null;
|
|
380
|
+
}
|
|
381
|
+
_applyDelta(t, e, i) {
|
|
382
|
+
const s = this._target(), [n, o, h, c] = this._boundsRect().map((r) => r / this._zoom), l = this._effectiveMinW, _ = this._effectiveMinH, f = this._effectiveMaxW, d = this._effectiveMaxH;
|
|
383
|
+
if (t === "e" || t === "se" || t === "ne") {
|
|
384
|
+
const r = Math.min(f, h - this._startLeft);
|
|
385
|
+
s.style.width = `${Math.min(Math.max(this._startW + e, l), r)}px`;
|
|
386
|
+
}
|
|
387
|
+
if (t === "w" || t === "sw" || t === "nw") {
|
|
388
|
+
const r = this._startLeft + this._startW, u = Math.min(
|
|
389
|
+
Math.max(this._startLeft + e, n, r - f),
|
|
390
|
+
r - l
|
|
391
|
+
);
|
|
392
|
+
s.style.left = `${u}px`, s.style.width = `${r - u}px`;
|
|
393
|
+
}
|
|
394
|
+
if (t === "s" || t === "se" || t === "sw") {
|
|
395
|
+
const r = Math.min(d, c - this._startTop);
|
|
396
|
+
s.style.height = `${Math.min(Math.max(this._startH + i, _), r)}px`;
|
|
397
|
+
}
|
|
398
|
+
if (t === "n" || t === "ne" || t === "nw") {
|
|
399
|
+
const r = this._startTop + this._startH, u = Math.min(
|
|
400
|
+
Math.max(this._startTop + i, o, r - d),
|
|
401
|
+
r - _
|
|
402
|
+
);
|
|
403
|
+
s.style.top = `${u}px`, s.style.height = `${r - u}px`;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
_boundsRect() {
|
|
407
|
+
const { bounds: t } = this._opts;
|
|
408
|
+
if (!t || t === "viewport")
|
|
409
|
+
return [0, 0, window.innerWidth, window.innerHeight];
|
|
410
|
+
if (t === "parent") {
|
|
411
|
+
const i = this._opts.target.parentElement;
|
|
412
|
+
if (!i)
|
|
413
|
+
return [0, 0, window.innerWidth, window.innerHeight];
|
|
414
|
+
const s = i.getBoundingClientRect();
|
|
415
|
+
return [s.left, s.top, s.right, s.bottom];
|
|
416
|
+
}
|
|
417
|
+
const e = t.getBoundingClientRect();
|
|
418
|
+
return [e.left, e.top, e.right, e.bottom];
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
export {
|
|
422
|
+
b as DEFAULT_RESIZE_MESSAGES,
|
|
423
|
+
H as ResizeController,
|
|
424
|
+
z as pinElementBox
|
|
425
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { state as m } from "lit/decorators.js";
|
|
2
|
+
import { isFocusable as u } from "./isFocusable.js";
|
|
3
|
+
var a = Object.defineProperty, h = (r, i, n, t) => {
|
|
4
|
+
for (var e = void 0, s = r.length - 1, o; s >= 0; s--)
|
|
5
|
+
(o = r[s]) && (e = o(i, n, e) || e);
|
|
6
|
+
return e && a(i, n, e), e;
|
|
7
|
+
};
|
|
8
|
+
function d(r) {
|
|
9
|
+
class i extends r {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments), this._items = [];
|
|
12
|
+
}
|
|
13
|
+
get items() {
|
|
14
|
+
return this._items.map((t) => t.deref()).filter((t) => u(t));
|
|
15
|
+
}
|
|
16
|
+
get firstItem() {
|
|
17
|
+
return this.items.at(0);
|
|
18
|
+
}
|
|
19
|
+
get lastItem() {
|
|
20
|
+
return this.items.at(-1);
|
|
21
|
+
}
|
|
22
|
+
get nextItem() {
|
|
23
|
+
const t = this._lastFocused ? this.items.indexOf(this._lastFocused) : 0;
|
|
24
|
+
return this.items.at((t + 1) % this.items.length);
|
|
25
|
+
}
|
|
26
|
+
get previousItem() {
|
|
27
|
+
const t = this._lastFocused ? this.items.indexOf(this._lastFocused) : 0;
|
|
28
|
+
return this.items.at((t - 1) % this.items.length);
|
|
29
|
+
}
|
|
30
|
+
focusItem(t) {
|
|
31
|
+
t?.focus();
|
|
32
|
+
}
|
|
33
|
+
focusItemAt(t) {
|
|
34
|
+
this.focusItem(this.items.at(t));
|
|
35
|
+
}
|
|
36
|
+
focusFirst() {
|
|
37
|
+
this.focusItem(this.firstItem);
|
|
38
|
+
}
|
|
39
|
+
focusLast() {
|
|
40
|
+
this.focusItem(this.lastItem);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns the elements to register from a slot.
|
|
44
|
+
*
|
|
45
|
+
* Override in subclasses to customise item collection — for example, to
|
|
46
|
+
* traverse into `role="group"` containers or to skip `role="separator"`
|
|
47
|
+
* elements. The default collects ALL direct assigned elements; the `items`
|
|
48
|
+
* getter then filters by `isFocusable` at access time so that elements
|
|
49
|
+
* toggling `disabled` are reflected without a new `slotchange`.
|
|
50
|
+
*/
|
|
51
|
+
_collectItems(t) {
|
|
52
|
+
return t.assignedElements();
|
|
53
|
+
}
|
|
54
|
+
_handleItemFocus(t) {
|
|
55
|
+
const e = t.composedPath().find((s) => this.items.includes(s));
|
|
56
|
+
e != null && (this._lastFocused = e, this.items.forEach((s) => s.setAttribute("tabindex", "-1")), e.setAttribute("tabindex", "0"));
|
|
57
|
+
}
|
|
58
|
+
_onSlotChange(t) {
|
|
59
|
+
const e = this._items;
|
|
60
|
+
this._items = this._collectItems(t.currentTarget).map(
|
|
61
|
+
(s) => new WeakRef(s)
|
|
62
|
+
), queueMicrotask(() => {
|
|
63
|
+
this.isConnected && (e.forEach((s) => s.deref()?.removeAttribute("tabindex")), this._initItems());
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Called after slot contents change and the item list is rebuilt.
|
|
68
|
+
* Override to configure items (set ARIA roles, move focus, etc.).
|
|
69
|
+
*
|
|
70
|
+
* Default implementation sets `tabindex="-1"` on all collected elements
|
|
71
|
+
* (including currently-disabled ones, so they don't enter the tab order
|
|
72
|
+
* if re-enabled before the next slotchange) and `tabindex="0"` on the
|
|
73
|
+
* first currently-focusable item.
|
|
74
|
+
*/
|
|
75
|
+
_initItems() {
|
|
76
|
+
this._items.forEach((e) => e.deref()?.setAttribute("tabindex", "-1"));
|
|
77
|
+
const t = this.items[0];
|
|
78
|
+
t && t.setAttribute("tabindex", "0");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return h([
|
|
82
|
+
m()
|
|
83
|
+
], i.prototype, "_lastFocused"), i;
|
|
84
|
+
}
|
|
85
|
+
export {
|
|
86
|
+
d as RovingTabIndexMixin
|
|
87
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { RafScheduler as i } from "./RafScheduler.js";
|
|
2
|
+
class h {
|
|
3
|
+
constructor(t, s) {
|
|
4
|
+
this._attached = null, this._scrolled = !1, this._initialFrame = new i(), this._onScroll = () => this._evaluate(), this._disposed = !1, this._host = t, this._opts = s, t.addController(this);
|
|
5
|
+
}
|
|
6
|
+
/** Whether the observed target is currently scrolled past the threshold. */
|
|
7
|
+
get scrolled() {
|
|
8
|
+
return this._scrolled;
|
|
9
|
+
}
|
|
10
|
+
/** Reconfigure the controller: detaches, merges options, and reattaches. */
|
|
11
|
+
setOptions(t) {
|
|
12
|
+
this._disposed || (this._detach(), Object.assign(this._opts, t), this._attach());
|
|
13
|
+
}
|
|
14
|
+
hostConnected() {
|
|
15
|
+
this._disposed || this._attach();
|
|
16
|
+
}
|
|
17
|
+
hostDisconnected() {
|
|
18
|
+
this._detach();
|
|
19
|
+
}
|
|
20
|
+
/** Detaches the listener or pending frame and removes the controller permanently. */
|
|
21
|
+
dispose() {
|
|
22
|
+
this._disposed || (this._disposed = !0, this._detach(), this._host.removeController(this));
|
|
23
|
+
}
|
|
24
|
+
_resolveTarget() {
|
|
25
|
+
const { target: t } = this._opts;
|
|
26
|
+
return typeof t == "function" ? t() : t ?? null;
|
|
27
|
+
}
|
|
28
|
+
_attach() {
|
|
29
|
+
if (!(this._opts.disabled || this._attached)) {
|
|
30
|
+
if (this._opts.initialEvaluation === "frame") {
|
|
31
|
+
this._queueAttach();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this._attachNow();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
_attachNow() {
|
|
38
|
+
if (this._opts.disabled || this._attached)
|
|
39
|
+
return;
|
|
40
|
+
const t = this._resolveTarget();
|
|
41
|
+
t && (this._attached = t, t.addEventListener("scroll", this._onScroll, { passive: !0 }), this._evaluate());
|
|
42
|
+
}
|
|
43
|
+
_queueAttach() {
|
|
44
|
+
this._initialFrame.schedulePhased(
|
|
45
|
+
() => {
|
|
46
|
+
const t = this._resolveTarget();
|
|
47
|
+
return t ? { target: t, scrollTop: this._scrollTop(t) } : null;
|
|
48
|
+
},
|
|
49
|
+
(t) => {
|
|
50
|
+
if (!(!t || this._opts.disabled || this._attached)) {
|
|
51
|
+
if (this._resolveTarget() !== t.target) {
|
|
52
|
+
this._attach();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this._attached = t.target, t.target.addEventListener("scroll", this._onScroll, { passive: !0 }), this._applyScrollTop(t.scrollTop);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
_detach() {
|
|
61
|
+
this._initialFrame.cancel(), this._attached?.removeEventListener("scroll", this._onScroll), this._attached = null, this._lastScrollTop = void 0;
|
|
62
|
+
}
|
|
63
|
+
_scrollTop(t = this._attached) {
|
|
64
|
+
return t instanceof Element ? t.scrollTop : t instanceof Document ? t.scrollingElement?.scrollTop ?? 0 : t?.scrollY ?? 0;
|
|
65
|
+
}
|
|
66
|
+
_evaluate() {
|
|
67
|
+
this._attached && this._applyScrollTop(this._scrollTop());
|
|
68
|
+
}
|
|
69
|
+
_applyScrollTop(t) {
|
|
70
|
+
const s = t - (this._lastScrollTop ?? t);
|
|
71
|
+
this._lastScrollTop = t, this._opts.onScroll?.(t, s);
|
|
72
|
+
const e = t > (this._opts.threshold ?? 4);
|
|
73
|
+
e !== this._scrolled && (this._scrolled = e, this._opts.onChange?.(e, t), this._host.requestUpdate());
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
h as ScrollObserverController
|
|
78
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { collator as u } from "./localeFormat.js";
|
|
2
|
+
const l = /* @__PURE__ */ new Map();
|
|
3
|
+
function* _(i, e) {
|
|
4
|
+
if (typeof Intl.Segmenter == "function") {
|
|
5
|
+
const s = e ?? "";
|
|
6
|
+
let t = l.get(s);
|
|
7
|
+
if (!t) {
|
|
8
|
+
try {
|
|
9
|
+
t = new Intl.Segmenter(e, { granularity: "grapheme" });
|
|
10
|
+
} catch {
|
|
11
|
+
t = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
12
|
+
}
|
|
13
|
+
l.set(s, t);
|
|
14
|
+
}
|
|
15
|
+
for (const n of t.segment(i))
|
|
16
|
+
yield i.slice(0, n.index + n.segment.length);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
let r = 0;
|
|
20
|
+
for (const s of i)
|
|
21
|
+
r += s.length, yield i.slice(0, r);
|
|
22
|
+
}
|
|
23
|
+
class p {
|
|
24
|
+
constructor(e) {
|
|
25
|
+
this._buffer = "", this._timer = 0, this._options = e;
|
|
26
|
+
}
|
|
27
|
+
get buffer() {
|
|
28
|
+
return this._buffer;
|
|
29
|
+
}
|
|
30
|
+
reset() {
|
|
31
|
+
this._buffer = "", this._clearTimer();
|
|
32
|
+
}
|
|
33
|
+
handleKeydown(e) {
|
|
34
|
+
return e.key.length !== 1 || e.altKey || e.ctrlKey || e.metaKey ? !1 : (this.search(e.key), e.preventDefault(), !0);
|
|
35
|
+
}
|
|
36
|
+
search(e) {
|
|
37
|
+
this._buffer += e, this._scheduleReset();
|
|
38
|
+
const r = this._options.items();
|
|
39
|
+
if (!r.length)
|
|
40
|
+
return null;
|
|
41
|
+
const s = this._options.startIndex?.() ?? 0, t = r.length, n = this._options.locale?.(), f = u(n, { sensitivity: "base", usage: "search" });
|
|
42
|
+
for (let o = 1; o <= t; o += 1) {
|
|
43
|
+
const h = (s + o) % t, c = r[h], a = this._options.text(c).trim();
|
|
44
|
+
for (const m of _(a, n))
|
|
45
|
+
if (f.compare(m, this._buffer) === 0)
|
|
46
|
+
return this._options.onMatch(c, h), c;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
_scheduleReset() {
|
|
51
|
+
this._clearTimer(), this._timer = window.setTimeout(() => this.reset(), this._options.timeout ?? 500);
|
|
52
|
+
}
|
|
53
|
+
_clearTimer() {
|
|
54
|
+
this._timer && (window.clearTimeout(this._timer), this._timer = 0);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
p as TypeaheadController
|
|
59
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isPhysicalReversed as b } from "./flow.js";
|
|
2
|
+
function h(o, e) {
|
|
3
|
+
const [, s, r, c] = /^(block|inline)-(start|end)(?:-(start|end))?$/.exec(
|
|
4
|
+
o
|
|
5
|
+
) ?? ["", "block", "end", "start"], d = s === "inline" ? e.inline : e.block, l = s === "inline" ? e.inlineReversed : e.blockReversed, i = r === "end" !== l, t = d === "x" ? i ? "right" : "left" : i ? "bottom" : "top", n = c;
|
|
6
|
+
if (!n)
|
|
7
|
+
return t;
|
|
8
|
+
const a = b(t === "top" || t === "bottom" ? "x" : "y", e) ? n === "start" ? "end" : "start" : n;
|
|
9
|
+
return `${t}-${a}`;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
h as resolveAnchorPlacement
|
|
13
|
+
};
|