what-core 0.14.0 → 0.15.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/LICENSE +21 -0
- package/README.md +64 -38
- package/a11y.d.ts +128 -0
- package/data.d.ts +294 -0
- package/dist/a11y.js +510 -0
- package/dist/a11y.min.js +413 -0
- package/dist/actions.js +158 -0
- package/dist/actions.min.js +112 -0
- package/dist/animation.js +481 -0
- package/dist/animation.min.js +295 -0
- package/dist/async.js +180 -0
- package/dist/async.min.js +134 -0
- package/dist/components.js +577 -0
- package/dist/components.min.js +413 -0
- package/dist/data.js +1212 -0
- package/dist/data.min.js +918 -0
- package/dist/diagnostics.js +187 -0
- package/dist/diagnostics.min.js +134 -0
- package/dist/dom.js +796 -0
- package/dist/dom.min.js +603 -0
- package/dist/entries/a11y.js +43 -0
- package/dist/entries/a11y.min.js +43 -0
- package/dist/entries/data.js +29 -0
- package/dist/entries/data.min.js +29 -0
- package/dist/entries/dom.js +45 -0
- package/dist/entries/dom.min.js +45 -0
- package/dist/entries/form.js +31 -0
- package/dist/entries/form.min.js +31 -0
- package/dist/entries/internal.js +123 -0
- package/dist/entries/internal.min.js +123 -0
- package/dist/entries/motion.js +23 -0
- package/dist/entries/motion.min.js +23 -0
- package/dist/entries/ui.js +25 -0
- package/dist/entries/ui.min.js +25 -0
- package/dist/env.js +5 -0
- package/dist/env.min.js +5 -0
- package/dist/errors.js +1518 -0
- package/dist/errors.min.js +548 -0
- package/dist/form.js +936 -0
- package/dist/form.min.js +703 -0
- package/dist/guardrails.js +84 -0
- package/dist/guardrails.min.js +55 -0
- package/dist/h.js +232 -0
- package/dist/h.min.js +171 -0
- package/dist/head.js +241 -0
- package/dist/head.min.js +207 -0
- package/dist/helpers.js +126 -0
- package/dist/helpers.min.js +98 -0
- package/dist/hooks.js +255 -0
- package/dist/hooks.min.js +153 -0
- package/dist/hot.js +215 -0
- package/dist/hot.min.js +24 -0
- package/dist/hydration-data.js +495 -0
- package/dist/hydration-data.min.js +371 -0
- package/dist/import-changes.js +273 -0
- package/dist/import-changes.min.js +272 -0
- package/dist/index.js +95 -0
- package/dist/index.min.js +95 -227
- package/dist/jsx-dev-runtime.js +10 -0
- package/dist/jsx-dev-runtime.min.js +10 -1
- package/dist/jsx-runtime.js +27 -0
- package/dist/jsx-runtime.min.js +15 -1
- package/dist/live.js +54 -0
- package/dist/live.min.js +49 -0
- package/dist/markup-rules.js +250 -0
- package/dist/markup-rules.min.js +213 -0
- package/dist/reactive.js +3334 -0
- package/dist/reactive.min.js +2033 -0
- package/dist/render.js +4746 -0
- package/dist/render.min.js +2797 -1
- package/dist/scheduler.js +225 -0
- package/dist/scheduler.min.js +162 -0
- package/dist/selector.js +11 -0
- package/dist/selector.min.js +10 -0
- package/dist/server-context.js +148 -0
- package/dist/server-context.min.js +121 -0
- package/dist/skeleton.js +342 -0
- package/dist/skeleton.min.js +310 -0
- package/dist/store.js +72 -0
- package/dist/store.min.js +50 -0
- package/dist/testing.js +720 -0
- package/dist/testing.min.js +458 -1
- package/dist/vnode-adoption.js +19 -0
- package/dist/vnode-adoption.min.js +19 -0
- package/dist/vnode-renderer.js +61 -0
- package/dist/vnode-renderer.min.js +47 -0
- package/dom.d.ts +44 -0
- package/form.d.ts +218 -0
- package/hot.d.ts +35 -0
- package/index.d.ts +421 -736
- package/internal.d.ts +284 -0
- package/jsx-runtime.d.ts +160 -137
- package/markup-rules.d.ts +83 -0
- package/motion.d.ts +156 -0
- package/package.json +117 -3
- package/render.d.ts +278 -29
- package/src/a11y.js +64 -59
- package/src/actions.js +226 -0
- package/src/animation.js +105 -57
- package/src/async.js +259 -0
- package/src/components.js +495 -144
- package/src/data.js +1410 -1159
- package/src/diagnostics.js +263 -0
- package/src/dom.js +1159 -872
- package/src/entries/a11y.js +24 -0
- package/src/entries/data.js +17 -0
- package/src/entries/dom.js +29 -0
- package/src/entries/form.js +16 -0
- package/src/entries/internal.js +63 -0
- package/src/entries/motion.js +13 -0
- package/src/entries/ui.js +13 -0
- package/src/env-development.js +12 -0
- package/src/env.js +33 -0
- package/src/errors.js +1144 -168
- package/src/form.js +723 -225
- package/src/guardrails.js +38 -126
- package/src/h.js +227 -152
- package/src/head.js +189 -19
- package/src/helpers.js +47 -75
- package/src/hooks.js +233 -248
- package/src/hot.js +316 -0
- package/src/hydration-data.js +859 -16
- package/src/import-changes.js +156 -0
- package/src/index.js +38 -188
- package/src/jsx-dev-runtime.js +7 -14
- package/src/jsx-runtime.js +25 -9
- package/src/live.js +80 -0
- package/src/markup-rules.js +387 -0
- package/src/reactive.js +4400 -862
- package/src/render.js +6502 -2570
- package/src/scheduler.js +56 -21
- package/src/selector.js +31 -0
- package/src/server-context.js +252 -22
- package/src/skeleton.js +22 -12
- package/src/store.js +17 -31
- package/src/testing.js +389 -63
- package/src/vnode-adoption.js +48 -0
- package/src/vnode-renderer.js +114 -0
- package/testing.d.ts +81 -1
- package/ui.d.ts +20 -0
- package/dist/chunk-6YOUZ6T4.min.js +0 -1
- package/dist/chunk-FN6HXME3.min.js +0 -11
- package/dist/chunk-VKZY7JPN.min.js +0 -1
- package/src/agent-context.js +0 -127
- package/src/warnings.js +0 -193
package/dist/a11y.js
ADDED
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
// src/a11y.js
|
|
2
|
+
import { signal, effect, onCleanup } from "./reactive.js";
|
|
3
|
+
import { h } from "./h.js";
|
|
4
|
+
import { getServerContext } from "./server-context.js";
|
|
5
|
+
var focusedElement = null;
|
|
6
|
+
function trackFocus() {
|
|
7
|
+
if (focusedElement === null) {
|
|
8
|
+
const active = typeof document !== "undefined" ? document.activeElement : null;
|
|
9
|
+
focusedElement = signal(active && active !== document.body ? active : null);
|
|
10
|
+
if (typeof document !== "undefined") {
|
|
11
|
+
document.addEventListener("focusin", (e) => focusedElement.set(e.target));
|
|
12
|
+
document.addEventListener("focusout", () => focusedElement.set(null));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return focusedElement;
|
|
16
|
+
}
|
|
17
|
+
function useFocus() {
|
|
18
|
+
const focused = trackFocus();
|
|
19
|
+
return {
|
|
20
|
+
current: () => focused(),
|
|
21
|
+
focus: (element) => element?.focus(),
|
|
22
|
+
blur: () => (
|
|
23
|
+
/** @type {HTMLElement | null} */
|
|
24
|
+
document.activeElement?.blur()
|
|
25
|
+
)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function useFocusRestore() {
|
|
29
|
+
const previousFocusRef = { current: null };
|
|
30
|
+
function capture(target) {
|
|
31
|
+
if (typeof document === "undefined") return;
|
|
32
|
+
previousFocusRef.current = target || document.activeElement || null;
|
|
33
|
+
}
|
|
34
|
+
function restore(fallbackTarget) {
|
|
35
|
+
const target = previousFocusRef.current || fallbackTarget;
|
|
36
|
+
if (target && typeof target.focus === "function") {
|
|
37
|
+
target.focus();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
capture,
|
|
42
|
+
restore,
|
|
43
|
+
previous: () => previousFocusRef.current
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function useFocusTrap(containerRef) {
|
|
47
|
+
let previousFocus = null;
|
|
48
|
+
function activate() {
|
|
49
|
+
if (typeof document === "undefined") return;
|
|
50
|
+
previousFocus = /** @type {HTMLElement | null} */
|
|
51
|
+
document.activeElement;
|
|
52
|
+
const container = containerRef.current || containerRef;
|
|
53
|
+
if (!container || typeof container.querySelectorAll !== "function") return;
|
|
54
|
+
const focusables = getFocusableElements(container);
|
|
55
|
+
if (focusables.length === 0) return;
|
|
56
|
+
focusables[0].focus();
|
|
57
|
+
function handleKeydown(e) {
|
|
58
|
+
if (e.key !== "Tab") return;
|
|
59
|
+
const focusables2 = getFocusableElements(container);
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
if (focusables2.length === 0) return;
|
|
62
|
+
const at = focusables2.indexOf(
|
|
63
|
+
/** @type {HTMLElement} */
|
|
64
|
+
document.activeElement
|
|
65
|
+
);
|
|
66
|
+
const last = focusables2.length - 1;
|
|
67
|
+
const next = e.shiftKey ? focusables2[at <= 0 ? last : at - 1] : focusables2[at === -1 || at === last ? 0 : at + 1];
|
|
68
|
+
next.focus();
|
|
69
|
+
}
|
|
70
|
+
container.addEventListener("keydown", handleKeydown);
|
|
71
|
+
return () => {
|
|
72
|
+
container.removeEventListener("keydown", handleKeydown);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function deactivate() {
|
|
76
|
+
if (previousFocus && typeof previousFocus.focus === "function") {
|
|
77
|
+
previousFocus.focus();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { activate, deactivate };
|
|
81
|
+
}
|
|
82
|
+
function getFocusableElements(container) {
|
|
83
|
+
const selector = [
|
|
84
|
+
"button:not([disabled])",
|
|
85
|
+
"a[href]",
|
|
86
|
+
"input:not([disabled])",
|
|
87
|
+
"select:not([disabled])",
|
|
88
|
+
"textarea:not([disabled])",
|
|
89
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
90
|
+
].join(",");
|
|
91
|
+
return Array.from(container.querySelectorAll(selector)).filter((el) => {
|
|
92
|
+
return el.offsetParent !== null;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
var FocusTrap = /* @__PURE__ */ Object.assign(function FocusTrap2({ children, active = true }) {
|
|
96
|
+
const containerRef = { current: null };
|
|
97
|
+
const refVersion = signal(0);
|
|
98
|
+
const trap = useFocusTrap(containerRef);
|
|
99
|
+
let trapCleanup = null;
|
|
100
|
+
const setRef = (el) => {
|
|
101
|
+
containerRef.current = el;
|
|
102
|
+
refVersion.set((v) => v + 1);
|
|
103
|
+
};
|
|
104
|
+
effect(() => {
|
|
105
|
+
refVersion();
|
|
106
|
+
if (trapCleanup) {
|
|
107
|
+
trapCleanup();
|
|
108
|
+
trapCleanup = null;
|
|
109
|
+
trap.deactivate();
|
|
110
|
+
}
|
|
111
|
+
if (active && containerRef.current) {
|
|
112
|
+
trapCleanup = trap.activate();
|
|
113
|
+
return () => {
|
|
114
|
+
trapCleanup?.();
|
|
115
|
+
trapCleanup = null;
|
|
116
|
+
trap.deactivate();
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
onCleanup(() => {
|
|
121
|
+
trapCleanup?.();
|
|
122
|
+
trapCleanup = null;
|
|
123
|
+
trap.deactivate();
|
|
124
|
+
});
|
|
125
|
+
return h("div", { ref: setRef }, children);
|
|
126
|
+
}, { _deferChildren: true });
|
|
127
|
+
var announcer = null;
|
|
128
|
+
var announcerId = 0;
|
|
129
|
+
function getAnnouncer() {
|
|
130
|
+
if (typeof document === "undefined") return null;
|
|
131
|
+
if (!announcer) {
|
|
132
|
+
announcer = document.createElement("div");
|
|
133
|
+
announcer.id = "what-announcer";
|
|
134
|
+
announcer.setAttribute("aria-live", "polite");
|
|
135
|
+
announcer.setAttribute("aria-atomic", "true");
|
|
136
|
+
announcer.style.cssText = `
|
|
137
|
+
position: absolute;
|
|
138
|
+
width: 1px;
|
|
139
|
+
height: 1px;
|
|
140
|
+
padding: 0;
|
|
141
|
+
margin: -1px;
|
|
142
|
+
overflow: hidden;
|
|
143
|
+
clip: rect(0, 0, 0, 0);
|
|
144
|
+
white-space: nowrap;
|
|
145
|
+
border: 0;
|
|
146
|
+
`;
|
|
147
|
+
document.body.appendChild(announcer);
|
|
148
|
+
}
|
|
149
|
+
return announcer;
|
|
150
|
+
}
|
|
151
|
+
function announce(message, options = {}) {
|
|
152
|
+
const { priority = "polite", timeout = 1e3 } = options;
|
|
153
|
+
const announcer2 = getAnnouncer();
|
|
154
|
+
if (!announcer2) return;
|
|
155
|
+
announcer2.setAttribute("aria-live", priority);
|
|
156
|
+
const id = ++announcerId;
|
|
157
|
+
announcer2.textContent = "";
|
|
158
|
+
requestAnimationFrame(() => {
|
|
159
|
+
if (announcerId === id) {
|
|
160
|
+
announcer2.textContent = message;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
setTimeout(() => {
|
|
164
|
+
if (announcerId === id) {
|
|
165
|
+
announcer2.textContent = "";
|
|
166
|
+
}
|
|
167
|
+
}, timeout);
|
|
168
|
+
}
|
|
169
|
+
function announceAssertive(message) {
|
|
170
|
+
return announce(message, { priority: "assertive" });
|
|
171
|
+
}
|
|
172
|
+
var SkipLink = /* @__PURE__ */ Object.assign(function SkipLink2({ href = "#main", children = "Skip to content" }) {
|
|
173
|
+
return h("a", {
|
|
174
|
+
href,
|
|
175
|
+
class: "what-skip-link",
|
|
176
|
+
onClick: (e) => {
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
const target = (
|
|
179
|
+
/** @type {HTMLElement | null} */
|
|
180
|
+
document.querySelector(href)
|
|
181
|
+
);
|
|
182
|
+
if (target) {
|
|
183
|
+
target.focus();
|
|
184
|
+
target.scrollIntoView();
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
style: {
|
|
188
|
+
position: "absolute",
|
|
189
|
+
top: "-40px",
|
|
190
|
+
left: "0",
|
|
191
|
+
padding: "8px",
|
|
192
|
+
background: "#000",
|
|
193
|
+
color: "#fff",
|
|
194
|
+
textDecoration: "none",
|
|
195
|
+
zIndex: "10000"
|
|
196
|
+
},
|
|
197
|
+
onFocus: (e) => {
|
|
198
|
+
e.target.style.top = "0";
|
|
199
|
+
},
|
|
200
|
+
onBlur: (e) => {
|
|
201
|
+
e.target.style.top = "-40px";
|
|
202
|
+
}
|
|
203
|
+
}, children);
|
|
204
|
+
}, { _deferChildren: true });
|
|
205
|
+
function ariaBool(value) {
|
|
206
|
+
return value ? "true" : "false";
|
|
207
|
+
}
|
|
208
|
+
function useAriaExpanded(initialExpanded = false) {
|
|
209
|
+
const expanded = signal(initialExpanded);
|
|
210
|
+
return {
|
|
211
|
+
expanded: () => expanded(),
|
|
212
|
+
toggle: () => expanded.set(!expanded.peek()),
|
|
213
|
+
open: () => expanded.set(true),
|
|
214
|
+
close: () => expanded.set(false),
|
|
215
|
+
buttonProps: () => ({
|
|
216
|
+
"aria-expanded": () => ariaBool(expanded()),
|
|
217
|
+
onClick: () => expanded.set(!expanded.peek())
|
|
218
|
+
}),
|
|
219
|
+
panelProps: () => ({
|
|
220
|
+
// `hidden` is a genuine HTML boolean attribute, so it stays a boolean:
|
|
221
|
+
// present-or-absent is the correct serialization here, unlike ARIA.
|
|
222
|
+
hidden: () => !expanded()
|
|
223
|
+
})
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function useAriaSelected(initialSelected = null) {
|
|
227
|
+
const selected = signal(initialSelected);
|
|
228
|
+
return {
|
|
229
|
+
selected: () => selected(),
|
|
230
|
+
select: (value) => selected.set(value),
|
|
231
|
+
isSelected: (value) => selected() === value,
|
|
232
|
+
itemProps: (value) => ({
|
|
233
|
+
"aria-selected": () => ariaBool(selected() === value),
|
|
234
|
+
onClick: () => selected.set(value)
|
|
235
|
+
})
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function useAriaChecked(initialChecked = false) {
|
|
239
|
+
const checked = signal(initialChecked);
|
|
240
|
+
return {
|
|
241
|
+
checked: () => checked(),
|
|
242
|
+
toggle: () => checked.set(!checked.peek()),
|
|
243
|
+
set: (value) => checked.set(value),
|
|
244
|
+
checkboxProps: () => ({
|
|
245
|
+
role: "checkbox",
|
|
246
|
+
"aria-checked": () => ariaBool(checked()),
|
|
247
|
+
tabIndex: 0,
|
|
248
|
+
onClick: () => checked.set(!checked.peek()),
|
|
249
|
+
onKeyDown: (e) => {
|
|
250
|
+
if (e.key === " " || e.key === "Enter") {
|
|
251
|
+
e.preventDefault();
|
|
252
|
+
checked.set(!checked.peek());
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
})
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function useRovingTabIndex(itemCountOrSignal, options = {}) {
|
|
259
|
+
const getCount = typeof itemCountOrSignal === "function" ? itemCountOrSignal : () => itemCountOrSignal;
|
|
260
|
+
const focusIndex = signal(0);
|
|
261
|
+
const configuredRole = options?.role || null;
|
|
262
|
+
const itemEls = [];
|
|
263
|
+
const itemRefs = [];
|
|
264
|
+
const callerRefs = [];
|
|
265
|
+
function refFor(index) {
|
|
266
|
+
let ref = itemRefs[index];
|
|
267
|
+
if (!ref) {
|
|
268
|
+
ref = {
|
|
269
|
+
get current() {
|
|
270
|
+
return itemEls[index] || null;
|
|
271
|
+
},
|
|
272
|
+
set current(el) {
|
|
273
|
+
itemEls[index] = el || null;
|
|
274
|
+
const caller = callerRefs[index];
|
|
275
|
+
if (typeof caller === "function") caller(el);
|
|
276
|
+
else if (caller && typeof caller === "object") caller.current = el;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
itemRefs[index] = ref;
|
|
280
|
+
}
|
|
281
|
+
return ref;
|
|
282
|
+
}
|
|
283
|
+
function itemElement(index) {
|
|
284
|
+
const el = itemEls[index];
|
|
285
|
+
if (!el) return null;
|
|
286
|
+
return el.isConnected === false ? null : el;
|
|
287
|
+
}
|
|
288
|
+
function focusItemElement(index) {
|
|
289
|
+
const el = itemElement(index);
|
|
290
|
+
if (!el || typeof el.focus !== "function") return null;
|
|
291
|
+
if (typeof document === "undefined" || document.activeElement !== el) el.focus();
|
|
292
|
+
return el;
|
|
293
|
+
}
|
|
294
|
+
function groupHasFocus() {
|
|
295
|
+
if (typeof document === "undefined") return false;
|
|
296
|
+
const active = document.activeElement;
|
|
297
|
+
if (!active) return false;
|
|
298
|
+
for (let i = 0; i < itemEls.length; i++) {
|
|
299
|
+
const el = itemEls[i];
|
|
300
|
+
if (!el) continue;
|
|
301
|
+
if (el === active) return true;
|
|
302
|
+
if (typeof el.contains === "function" && el.contains(active)) return true;
|
|
303
|
+
}
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
function clampIndex(index, count) {
|
|
307
|
+
if (!(count > 0)) return 0;
|
|
308
|
+
if (index < 0) return 0;
|
|
309
|
+
if (index > count - 1) return count - 1;
|
|
310
|
+
return index;
|
|
311
|
+
}
|
|
312
|
+
function activeIndex() {
|
|
313
|
+
return clampIndex(focusIndex(), getCount());
|
|
314
|
+
}
|
|
315
|
+
function isValidIndex(i) {
|
|
316
|
+
return Number.isInteger(i) && i >= 0 && i < getCount();
|
|
317
|
+
}
|
|
318
|
+
function handleKeyDown(e) {
|
|
319
|
+
const count = getCount();
|
|
320
|
+
if (count <= 0) return;
|
|
321
|
+
const current = clampIndex(focusIndex.peek(), count);
|
|
322
|
+
let next = current;
|
|
323
|
+
switch (e.key) {
|
|
324
|
+
case "ArrowDown":
|
|
325
|
+
case "ArrowRight":
|
|
326
|
+
next = (current + 1) % count;
|
|
327
|
+
break;
|
|
328
|
+
case "ArrowUp":
|
|
329
|
+
case "ArrowLeft":
|
|
330
|
+
next = (current - 1 + count) % count;
|
|
331
|
+
break;
|
|
332
|
+
case "Home":
|
|
333
|
+
next = 0;
|
|
334
|
+
break;
|
|
335
|
+
case "End":
|
|
336
|
+
next = count - 1;
|
|
337
|
+
break;
|
|
338
|
+
default:
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
e.preventDefault();
|
|
342
|
+
focusIndex.set(next);
|
|
343
|
+
focusItemElement(next);
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
focusIndex: () => activeIndex(),
|
|
347
|
+
// Follows focus only when the group already owns it, so syncing the index
|
|
348
|
+
// from application state cannot steal focus from elsewhere on the page.
|
|
349
|
+
// Use focusItem() when moving focus is the intent.
|
|
350
|
+
setFocusIndex: (i) => {
|
|
351
|
+
if (!isValidIndex(i)) return;
|
|
352
|
+
focusIndex.set(i);
|
|
353
|
+
if (groupHasFocus()) focusItemElement(i);
|
|
354
|
+
},
|
|
355
|
+
// Explicitly move focus to an item, e.g. a menu focusing its first item on
|
|
356
|
+
// open. Returns the element it focused, or null when the index is out of
|
|
357
|
+
// range or the item is not in the DOM.
|
|
358
|
+
focusItem: (i) => {
|
|
359
|
+
if (!isValidIndex(i)) return null;
|
|
360
|
+
focusIndex.set(i);
|
|
361
|
+
return focusItemElement(i);
|
|
362
|
+
},
|
|
363
|
+
// `overrides` are spread last and win, except for `ref`, which is chained
|
|
364
|
+
// (see refFor) because this hook needs the node to move focus at all.
|
|
365
|
+
getItemProps: (index, overrides) => {
|
|
366
|
+
const { ref: callerRef, ...rest } = overrides || {};
|
|
367
|
+
callerRefs[index] = callerRef || null;
|
|
368
|
+
return {
|
|
369
|
+
ref: refFor(index),
|
|
370
|
+
// Accessor, not a snapshot: exactly one item is tabbable at a time and
|
|
371
|
+
// which one has to change as focus roves. See the ariaBool note above
|
|
372
|
+
// for why a resolved value cannot survive a spread.
|
|
373
|
+
tabIndex: () => activeIndex() === index ? 0 : -1,
|
|
374
|
+
onKeyDown: handleKeyDown,
|
|
375
|
+
// The ref is the registration; this is a free corrective for it. A call
|
|
376
|
+
// site that spreads its own ref AFTER getItemProps() replaces ours, and
|
|
377
|
+
// an element reporting its own focus event is first-hand evidence of
|
|
378
|
+
// which node index `index` rendered to.
|
|
379
|
+
onFocus: (e) => {
|
|
380
|
+
const el = e && (e.currentTarget || e.target);
|
|
381
|
+
if (el) itemEls[index] = el;
|
|
382
|
+
focusIndex.set(index);
|
|
383
|
+
},
|
|
384
|
+
...rest
|
|
385
|
+
};
|
|
386
|
+
},
|
|
387
|
+
containerProps: (overrides) => configuredRole ? { role: configuredRole, ...overrides } : { ...overrides }
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
var VisuallyHidden = /* @__PURE__ */ Object.assign(function VisuallyHidden2({ children, as = "span" }) {
|
|
391
|
+
return h(as, {
|
|
392
|
+
style: {
|
|
393
|
+
position: "absolute",
|
|
394
|
+
width: "1px",
|
|
395
|
+
height: "1px",
|
|
396
|
+
padding: "0",
|
|
397
|
+
margin: "-1px",
|
|
398
|
+
overflow: "hidden",
|
|
399
|
+
clip: "rect(0, 0, 0, 0)",
|
|
400
|
+
whiteSpace: "nowrap",
|
|
401
|
+
border: "0"
|
|
402
|
+
}
|
|
403
|
+
}, children);
|
|
404
|
+
}, { _deferChildren: true });
|
|
405
|
+
var LiveRegion = /* @__PURE__ */ Object.assign(function LiveRegion2({ children, priority = "polite", atomic = true }) {
|
|
406
|
+
return h("div", {
|
|
407
|
+
"aria-live": priority,
|
|
408
|
+
"aria-atomic": atomic
|
|
409
|
+
}, children);
|
|
410
|
+
}, { _deferChildren: true });
|
|
411
|
+
var idCounter = 0;
|
|
412
|
+
function nextIdSuffix() {
|
|
413
|
+
const ctx = getServerContext();
|
|
414
|
+
if (ctx) {
|
|
415
|
+
ctx.idCounter = (ctx.idCounter || 0) + 1;
|
|
416
|
+
return ctx.idCounter;
|
|
417
|
+
}
|
|
418
|
+
return ++idCounter;
|
|
419
|
+
}
|
|
420
|
+
function __resetIdCounter() {
|
|
421
|
+
idCounter = 0;
|
|
422
|
+
}
|
|
423
|
+
function useId(prefix = "what") {
|
|
424
|
+
return `${prefix}-${nextIdSuffix()}`;
|
|
425
|
+
}
|
|
426
|
+
function useIds(count, prefix = "what") {
|
|
427
|
+
const ids = [];
|
|
428
|
+
for (let i = 0; i < count; i++) {
|
|
429
|
+
ids.push(`${prefix}-${nextIdSuffix()}`);
|
|
430
|
+
}
|
|
431
|
+
return ids;
|
|
432
|
+
}
|
|
433
|
+
function useDescribedBy(description) {
|
|
434
|
+
const id = useId("desc");
|
|
435
|
+
return {
|
|
436
|
+
descriptionId: id,
|
|
437
|
+
descriptionProps: () => ({
|
|
438
|
+
id,
|
|
439
|
+
style: { display: "none" }
|
|
440
|
+
}),
|
|
441
|
+
describedByProps: () => ({
|
|
442
|
+
"aria-describedby": id
|
|
443
|
+
}),
|
|
444
|
+
Description: () => h("div", {
|
|
445
|
+
id,
|
|
446
|
+
style: { display: "none" }
|
|
447
|
+
}, description)
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
function useLabelledBy(_label) {
|
|
451
|
+
const id = useId("label");
|
|
452
|
+
return {
|
|
453
|
+
labelId: id,
|
|
454
|
+
labelProps: () => ({
|
|
455
|
+
id
|
|
456
|
+
}),
|
|
457
|
+
labelledByProps: () => ({
|
|
458
|
+
"aria-labelledby": id
|
|
459
|
+
})
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
var Keys = {
|
|
463
|
+
Enter: "Enter",
|
|
464
|
+
Space: " ",
|
|
465
|
+
Escape: "Escape",
|
|
466
|
+
ArrowUp: "ArrowUp",
|
|
467
|
+
ArrowDown: "ArrowDown",
|
|
468
|
+
ArrowLeft: "ArrowLeft",
|
|
469
|
+
ArrowRight: "ArrowRight",
|
|
470
|
+
Home: "Home",
|
|
471
|
+
End: "End",
|
|
472
|
+
Tab: "Tab"
|
|
473
|
+
};
|
|
474
|
+
function onKey(key, handler) {
|
|
475
|
+
return (e) => {
|
|
476
|
+
if (e.key === key) {
|
|
477
|
+
handler(e);
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
function onKeys(keys, handler) {
|
|
482
|
+
return (e) => {
|
|
483
|
+
if (keys.includes(e.key)) {
|
|
484
|
+
handler(e);
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
export {
|
|
489
|
+
FocusTrap,
|
|
490
|
+
Keys,
|
|
491
|
+
LiveRegion,
|
|
492
|
+
SkipLink,
|
|
493
|
+
VisuallyHidden,
|
|
494
|
+
__resetIdCounter,
|
|
495
|
+
announce,
|
|
496
|
+
announceAssertive,
|
|
497
|
+
onKey,
|
|
498
|
+
onKeys,
|
|
499
|
+
useAriaChecked,
|
|
500
|
+
useAriaExpanded,
|
|
501
|
+
useAriaSelected,
|
|
502
|
+
useDescribedBy,
|
|
503
|
+
useFocus,
|
|
504
|
+
useFocusRestore,
|
|
505
|
+
useFocusTrap,
|
|
506
|
+
useId,
|
|
507
|
+
useIds,
|
|
508
|
+
useLabelledBy,
|
|
509
|
+
useRovingTabIndex
|
|
510
|
+
};
|