@baukit/a11y-core 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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +107 -0
  3. package/dist/announce.d.ts +11 -0
  4. package/dist/announce.d.ts.map +1 -0
  5. package/dist/announce.js +37 -0
  6. package/dist/announce.js.map +1 -0
  7. package/dist/dom-boundary.d.ts +46 -0
  8. package/dist/dom-boundary.d.ts.map +1 -0
  9. package/dist/dom-boundary.js +33 -0
  10. package/dist/dom-boundary.js.map +1 -0
  11. package/dist/index.d.ts +10 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +10 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/platform.d.ts +15 -0
  16. package/dist/platform.d.ts.map +1 -0
  17. package/dist/platform.js +17 -0
  18. package/dist/platform.js.map +1 -0
  19. package/dist/use-enter-to-next.d.ts +17 -0
  20. package/dist/use-enter-to-next.d.ts.map +1 -0
  21. package/dist/use-enter-to-next.js +45 -0
  22. package/dist/use-enter-to-next.js.map +1 -0
  23. package/dist/use-focus-trap.d.ts +32 -0
  24. package/dist/use-focus-trap.d.ts.map +1 -0
  25. package/dist/use-focus-trap.js +104 -0
  26. package/dist/use-focus-trap.js.map +1 -0
  27. package/dist/use-inert.d.ts +16 -0
  28. package/dist/use-inert.d.ts.map +1 -0
  29. package/dist/use-inert.js +107 -0
  30. package/dist/use-inert.js.map +1 -0
  31. package/dist/use-overlay-a11y.d.ts +35 -0
  32. package/dist/use-overlay-a11y.d.ts.map +1 -0
  33. package/dist/use-overlay-a11y.js +56 -0
  34. package/dist/use-overlay-a11y.js.map +1 -0
  35. package/dist/use-reduced-motion.d.ts +3 -0
  36. package/dist/use-reduced-motion.d.ts.map +1 -0
  37. package/dist/use-reduced-motion.js +40 -0
  38. package/dist/use-reduced-motion.js.map +1 -0
  39. package/dist/use-roving-radio-group.d.ts +25 -0
  40. package/dist/use-roving-radio-group.d.ts.map +1 -0
  41. package/dist/use-roving-radio-group.js +48 -0
  42. package/dist/use-roving-radio-group.js.map +1 -0
  43. package/dist/use-single-flight.d.ts +7 -0
  44. package/dist/use-single-flight.d.ts.map +1 -0
  45. package/dist/use-single-flight.js +20 -0
  46. package/dist/use-single-flight.js.map +1 -0
  47. package/dist/web.d.ts +11 -0
  48. package/dist/web.d.ts.map +1 -0
  49. package/dist/web.js +11 -0
  50. package/dist/web.js.map +1 -0
  51. package/package.json +65 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Patrick Koss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # @baukit/a11y-core
2
+
3
+ `@baukit/a11y-core` holds the accessibility behavior that web and React Native products share:
4
+ overlay focus, inert background content, announcements, reduced motion, and keyboard movement
5
+ through groups and forms. Products keep their components, copy, and visual design local.
6
+
7
+ The package imports React and React Native and nothing else. Both are peer dependencies, so the
8
+ product's Expo SDK decides the versions, and React Native is optional.
9
+
10
+ ## Two entry points
11
+
12
+ A React Native product imports the package root and gets everything. A plain React web app imports
13
+ `@baukit/a11y-core/web` and gets `useFocusTrap`, `useInert`, `useAriaHiddenInert`,
14
+ `useSingleFlight`, and the `dom-boundary` helpers. Nothing reachable from that entry imports
15
+ `react-native`, at runtime or in its types, so the app needs no React Native in its dependency
16
+ tree. `react-native` is an optional peer dependency for exactly that reason.
17
+
18
+ The DOM hooks ask whether a document exists rather than asking `Platform` which OS this is. The
19
+ two questions have the same answer here: every branch those hooks guard reads or writes the DOM,
20
+ React Native Web gives them a real document, and React Native has none. Hooks with a genuine
21
+ platform split, such as `announce` and `useOverlayA11y`, keep reading `Platform` and stay behind
22
+ the root entry.
23
+
24
+ ## Overlays
25
+
26
+ `useOverlayA11y` is one contract over two platforms that behave nothing alike.
27
+
28
+ ```ts
29
+ const { backgroundProps, containerProps } = useOverlayA11y({
30
+ active: visible,
31
+ containerRef: panelRef,
32
+ inertContainerRef: overlayRootRef,
33
+ initialFocusRef,
34
+ onEscape: onClose,
35
+ triggerRef,
36
+ });
37
+ ```
38
+
39
+ On web it moves focus into the overlay, contains Tab and Shift+Tab, calls `onEscape`, makes
40
+ everything outside `inertContainerRef` inert, and restores focus to whatever had it before. The
41
+ restore runs on the next task because the browser rejects focus on a still-inert trigger.
42
+
43
+ On native it waits before requesting accessibility focus, so no focus lands before layout. On
44
+ close it returns focus to `triggerRef`. Native cannot discover what previously held accessibility
45
+ focus, so the caller owns that ref. Pass `triggerHandle` instead when the node tag is already
46
+ resolved.
47
+
48
+ The wait defaults to `InteractionManager.runAfterInteractions`, which React Native 0.86 deprecates
49
+ without offering a replacement for "after the overlay presented". Products with a real
50
+ presentation event should pass `deferFocus` and drive the focus request from it:
51
+
52
+ ```ts
53
+ const deferFocus = (task: () => void) => {
54
+ layoutTasks.push(task);
55
+ return { cancel: () => remove(task) };
56
+ };
57
+ ```
58
+
59
+ Spread `backgroundProps` onto the content *behind* the overlay, never the overlay itself. It sets
60
+ `accessibilityElementsHidden` and `importantForAccessibility` while the overlay is open, and is
61
+ empty on web and while closed. Spread `containerProps` onto the overlay container.
62
+
63
+ `useFocusTrap` and `useInert` are the web halves on their own, for products that compose their own
64
+ overlay. `useAriaHiddenInert` covers a separate problem: routers mark inactive web scenes
65
+ `aria-hidden`, which leaves their descendants in the keyboard focus order. Mount it once at the
66
+ app root. Put `ARIA_HIDDEN_INERT_OPT_OUT` on an element that must stay focusable anyway.
67
+
68
+ ## The React Native to DOM boundary
69
+
70
+ React Native Web renders a `View` as a DOM element, but the `View` type never says so. Every
71
+ crossing goes through `dom-boundary`, which checks for the method it needs and returns null
72
+ otherwise. `asFocusTarget`, `asFocusContainer`, and `asTreeElement` take a `HostRef` and narrow
73
+ it; a native host that has no DOM capability simply yields null instead of throwing. `HostRef` is
74
+ `RefObject<object | null>`, which accepts a `View` ref and an element ref without naming either
75
+ type.
76
+
77
+ ## Announcements
78
+
79
+ `announce(message, options)` speaks an outcome without a visible live-region component. Native
80
+ calls `announceForAccessibility`. Web writes into a visually hidden region, clearing the text and
81
+ forcing a reflow first so the same message twice is spoken twice. Blank messages are dropped.
82
+
83
+ The region's DOM id defaults to `baukit-announcer`. Pass `liveRegionId` to place it under a
84
+ product-owned id, and `assertive: true` to interrupt rather than wait for a pause.
85
+
86
+ ## Reduced motion, groups, and forms
87
+
88
+ `useReducedMotion` reads the web media query or `AccessibilityInfo.isReduceMotionEnabled`, and
89
+ follows changes made during a running session on both platforms.
90
+
91
+ `useRovingRadioGroup` gives a radio group a single tab stop and arrow-key movement between its
92
+ options, wrapping at both ends and honoring Home and End. `radioProps(index)` returns the
93
+ `tabIndex`, `ref`, and `onKeyDown` for one option.
94
+
95
+ `useEnterToNext` makes Enter walk a web form field by field and submit from the last one.
96
+ Multiline fields keep their newline behavior and are skipped along the way. On native it returns
97
+ only the `ref`, leaving the platform keyboard alone.
98
+
99
+ `useSingleFlight` is a synchronous mutex for async UI mutations. React state cannot lock within a
100
+ single tick, so a double tap would submit twice. A rejected call resolves to `undefined`, and the
101
+ lock is released even when the operation throws.
102
+
103
+ ## Boundaries
104
+
105
+ This package renders nothing and ships no components, styles, or copy. It does not decide which
106
+ outcomes deserve an announcement, which motion is essential, or what an overlay looks like. Layout
107
+ breakpoint arithmetic lives in `@baukit/ui-tokens`, not here.
@@ -0,0 +1,11 @@
1
+ /** Default DOM id of the shared web live region. Override it per product. */
2
+ export declare const DEFAULT_LIVE_REGION_ID = "baukit-announcer";
3
+ export interface AnnounceOptions {
4
+ /** Interrupts the screen reader instead of waiting for a pause. */
5
+ assertive?: boolean;
6
+ /** DOM id of the web live region. Defaults to `DEFAULT_LIVE_REGION_ID`. */
7
+ liveRegionId?: string;
8
+ }
9
+ /** Announces an outcome without requiring a visible live-region component. */
10
+ export declare function announce(message: string, { assertive, liveRegionId }?: AnnounceOptions): void;
11
+ //# sourceMappingURL=announce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"announce.d.ts","sourceRoot":"","sources":["../src/announce.ts"],"names":[],"mappings":"AAEA,6EAA6E;AAC7E,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AAKzD,MAAM,WAAW,eAAe;IAC9B,mEAAmE;IACnE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAiBD,8EAA8E;AAC9E,wBAAgB,QAAQ,CACtB,OAAO,EAAE,MAAM,EACf,EAAE,SAAiB,EAAE,YAAqC,EAAE,GAAE,eAAoB,GACjF,IAAI,CAeN"}
@@ -0,0 +1,37 @@
1
+ import { AccessibilityInfo, Platform } from 'react-native';
2
+ /** Default DOM id of the shared web live region. Override it per product. */
3
+ export const DEFAULT_LIVE_REGION_ID = 'baukit-announcer';
4
+ const VISUALLY_HIDDEN = 'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;';
5
+ function webLiveRegion(assertive, liveRegionId) {
6
+ if (typeof document === 'undefined')
7
+ return null;
8
+ let region = document.getElementById(liveRegionId);
9
+ if (!region) {
10
+ region = document.createElement('div');
11
+ region.id = liveRegionId;
12
+ region.style.cssText = VISUALLY_HIDDEN;
13
+ document.body.appendChild(region);
14
+ }
15
+ region.setAttribute('aria-atomic', 'true');
16
+ region.setAttribute('aria-live', assertive ? 'assertive' : 'polite');
17
+ region.setAttribute('role', assertive ? 'alert' : 'status');
18
+ return region;
19
+ }
20
+ /** Announces an outcome without requiring a visible live-region component. */
21
+ export function announce(message, { assertive = false, liveRegionId = DEFAULT_LIVE_REGION_ID } = {}) {
22
+ const trimmed = message.trim();
23
+ if (!trimmed)
24
+ return;
25
+ if (Platform.OS !== 'web') {
26
+ AccessibilityInfo.announceForAccessibility(trimmed);
27
+ return;
28
+ }
29
+ const region = webLiveRegion(assertive, liveRegionId);
30
+ if (!region)
31
+ return;
32
+ region.textContent = '';
33
+ // Force a distinct mutation so the same message twice is spoken twice.
34
+ void region.offsetWidth;
35
+ region.textContent = trimmed;
36
+ }
37
+ //# sourceMappingURL=announce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"announce.js","sourceRoot":"","sources":["../src/announce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE3D,6EAA6E;AAC7E,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AAEzD,MAAM,eAAe,GACnB,8HAA8H,CAAC;AASjI,SAAS,aAAa,CAAC,SAAkB,EAAE,YAAoB;IAC7D,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IACjD,IAAI,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;IACnD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,CAAC,EAAE,GAAG,YAAY,CAAC;QACzB,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,eAAe,CAAC;QACvC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IAC3C,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACrE,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,QAAQ,CACtB,OAAe,EACf,EAAE,SAAS,GAAG,KAAK,EAAE,YAAY,GAAG,sBAAsB,KAAsB,EAAE;IAElF,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/B,IAAI,CAAC,OAAO;QAAE,OAAO;IAErB,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;QAC1B,iBAAiB,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;QACpD,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IACtD,IAAI,CAAC,MAAM;QAAE,OAAO;IACpB,MAAM,CAAC,WAAW,GAAG,EAAE,CAAC;IACxB,uEAAuE;IACvE,KAAK,MAAM,CAAC,WAAW,CAAC;IACxB,MAAM,CAAC,WAAW,GAAG,OAAO,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { RefObject } from 'react';
2
+ /**
3
+ * React Native Web renders a `View` as a DOM element, but the `View` type never
4
+ * says so. Every crossing from a ref to a DOM capability goes through this
5
+ * module so the unchecked cast exists once instead of at each call site.
6
+ */
7
+ /**
8
+ * A ref to whatever the host rendered: a `View` instance under React Native, an
9
+ * element under React DOM. Naming neither type keeps this module importable
10
+ * from a product that has no React Native types installed.
11
+ */
12
+ export type HostRef = RefObject<object | null>;
13
+ export interface FocusTarget {
14
+ focus(options?: {
15
+ preventScroll?: boolean;
16
+ }): void;
17
+ }
18
+ export interface AttributeHost {
19
+ getAttribute(name: string): string | null;
20
+ hasAttribute(name: string): boolean;
21
+ removeAttribute(name: string): void;
22
+ setAttribute(name: string, value: string): void;
23
+ }
24
+ export interface FocusableElement extends FocusTarget {
25
+ disabled?: boolean;
26
+ getAttribute(name: string): string | null;
27
+ hasAttribute(name: string): boolean;
28
+ }
29
+ export interface QueryRoot {
30
+ querySelectorAll(selector: string): Iterable<AttributeHost>;
31
+ }
32
+ export interface FocusContainer extends FocusableElement {
33
+ querySelectorAll(selector: string): Iterable<FocusableElement>;
34
+ }
35
+ export interface TreeElement extends AttributeHost {
36
+ children: ArrayLike<TreeElement>;
37
+ parentElement: TreeElement | null;
38
+ }
39
+ /** Reads the host object behind a ref, or null when the ref is empty. */
40
+ export declare function hostElement(ref: HostRef | undefined): object | null;
41
+ export declare function asFocusTarget(ref: HostRef | undefined): FocusTarget | null;
42
+ export declare function asFocusContainer(ref: HostRef | undefined): FocusContainer | null;
43
+ export declare function asTreeElement(ref: HostRef | undefined): TreeElement | null;
44
+ /** The element that currently holds DOM focus, or null outside a browser document. */
45
+ export declare function activeFocusTarget(): FocusTarget | null;
46
+ //# sourceMappingURL=dom-boundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom-boundary.d.ts","sourceRoot":"","sources":["../src/dom-boundary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,GAAG,IAAI,CAA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S,GAAG,cAAc,GAAG,IAAI,CAMhF;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,GAAG,WAAW,GAAG,IAAI,CAG1E;AAED,sFAAsF;AACtF,wBAAgB,iBAAiB,IAAI,WAAW,GAAG,IAAI,CAMtD"}
@@ -0,0 +1,33 @@
1
+ function hasMethod(value, name) {
2
+ return typeof value[name] === 'function';
3
+ }
4
+ /** Reads the host object behind a ref, or null when the ref is empty. */
5
+ export function hostElement(ref) {
6
+ const current = ref?.current;
7
+ return typeof current === 'object' && current !== null ? current : null;
8
+ }
9
+ export function asFocusTarget(ref) {
10
+ const host = hostElement(ref);
11
+ return host !== null && hasMethod(host, 'focus') ? host : null;
12
+ }
13
+ export function asFocusContainer(ref) {
14
+ const host = hostElement(ref);
15
+ if (host === null || !hasMethod(host, 'querySelectorAll') || !hasMethod(host, 'focus')) {
16
+ return null;
17
+ }
18
+ return host;
19
+ }
20
+ export function asTreeElement(ref) {
21
+ const host = hostElement(ref);
22
+ return host !== null && hasMethod(host, 'setAttribute') ? host : null;
23
+ }
24
+ /** The element that currently holds DOM focus, or null outside a browser document. */
25
+ export function activeFocusTarget() {
26
+ if (typeof document === 'undefined')
27
+ return null;
28
+ const active = document.activeElement;
29
+ return typeof active === 'object' && active !== null && hasMethod(active, 'focus')
30
+ ? active
31
+ : null;
32
+ }
33
+ //# sourceMappingURL=dom-boundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom-boundary.js","sourceRoot":"","sources":["../src/dom-boundary.ts"],"names":[],"mappings":"AA6CA,SAAS,SAAS,CAChB,KAAa,EACb,IAAO;IAEP,OAAO,OAAQ,KAAiC,CAAC,IAAI,CAAC,KAAK,UAAU,CAAC;AACxE,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,WAAW,CAAC,GAAwB;IAClD,MAAM,OAAO,GAAG,GAAG,EAAE,OAAO,CAAC;IAC7B,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,OA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+ export * from './use-enter-to-next.js';
4
+ export * from './use-focus-trap.js';
5
+ export * from './use-inert.js';
6
+ export * from './use-overlay-a11y.js';
7
+ export * from './use-reduced-motion.js';
8
+ export * from './use-roving-radio-group.js';
9
+ export * from './use-single-flight.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export * from './announce.js';
2
+ export * from './dom-boundary.js';
3
+ export * from './use-enter-to-next.js';
4
+ export * from './use-focus-trap.js';
5
+ export * from './use-inert.js';
6
+ export * from './use-overlay-a11y.js';
7
+ export * from './use-reduced-motion.js';
8
+ export * from './use-roving-radio-group.js';
9
+ export * from './use-single-flight.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The DOM-only hooks must be importable from a plain React web app that has no
3
+ * React Native in its dependency tree. A static `react-native` import would put
4
+ * React Native's Flow source in that app's bundler, so those hooks ask for a
5
+ * document instead of asking `Platform` which OS this is.
6
+ *
7
+ * The two questions have the same answer for this package. Every branch guarded
8
+ * by `Platform.OS === 'web'` in `use-focus-trap` and `use-inert` reads or writes
9
+ * the DOM, React Native Web runs them against a real document, and React Native
10
+ * has no document at all. Hooks that need a genuine platform split, such as
11
+ * `announce` and `useOverlayA11y`, keep importing `Platform` directly.
12
+ */
13
+ /** True when a DOM document is available to read and mutate. */
14
+ export declare function hasDocument(): boolean;
15
+ //# sourceMappingURL=platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,gEAAgE;AAChE,wBAAgB,WAAW,IAAI,OAAO,CAErC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The DOM-only hooks must be importable from a plain React web app that has no
3
+ * React Native in its dependency tree. A static `react-native` import would put
4
+ * React Native's Flow source in that app's bundler, so those hooks ask for a
5
+ * document instead of asking `Platform` which OS this is.
6
+ *
7
+ * The two questions have the same answer for this package. Every branch guarded
8
+ * by `Platform.OS === 'web'` in `use-focus-trap` and `use-inert` reads or writes
9
+ * the DOM, React Native Web runs them against a real document, and React Native
10
+ * has no document at all. Hooks that need a genuine platform split, such as
11
+ * `announce` and `useOverlayA11y`, keep importing `Platform` directly.
12
+ */
13
+ /** True when a DOM document is available to read and mutate. */
14
+ export function hasDocument() {
15
+ return typeof document !== 'undefined';
16
+ }
17
+ //# sourceMappingURL=platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,gEAAgE;AAChE,MAAM,UAAU,WAAW;IACzB,OAAO,OAAO,QAAQ,KAAK,WAAW,CAAC;AACzC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type TextInput, type TextInputProps } from 'react-native';
2
+ export interface RegisterFieldOptions {
3
+ multiline?: boolean;
4
+ }
5
+ export type RegisteredFieldProps = Pick<TextInputProps, 'onSubmitEditing' | 'returnKeyType'> & {
6
+ ref: (node: TextInput | null) => void;
7
+ };
8
+ export interface EnterToNextResult {
9
+ registerField: (index: number, options?: RegisterFieldOptions) => RegisteredFieldProps;
10
+ submit: () => void;
11
+ }
12
+ /**
13
+ * Makes Enter walk a web form field by field and submit from the last one.
14
+ * Multiline fields keep their newline behavior and are skipped on the way.
15
+ */
16
+ export declare function useEnterToNext(fieldCount: number, onSubmit: () => void): EnterToNextResult;
17
+ //# sourceMappingURL=use-enter-to-next.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-enter-to-next.d.ts","sourceRoot":"","sources":["../src/use-enter-to-next.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAE7E,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,cAAc,EAAE,iBAAiB,GAAG,eAAe,CAAC,GAAG;IAC7F,GAAG,EAAE,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,KAAK,IAAI,CAAC;CACvC,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,KAAK,oBAAoB,CAAC;IACvF,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,iBAAiB,CA0C1F"}
@@ -0,0 +1,45 @@
1
+ import { useCallback, useRef } from 'react';
2
+ import { Platform } from 'react-native';
3
+ /**
4
+ * Makes Enter walk a web form field by field and submit from the last one.
5
+ * Multiline fields keep their newline behavior and are skipped on the way.
6
+ */
7
+ export function useEnterToNext(fieldCount, onSubmit) {
8
+ const fieldRefs = useRef([]);
9
+ const multilineFields = useRef(new Set());
10
+ const submit = useCallback(() => {
11
+ onSubmit();
12
+ }, [onSubmit]);
13
+ const registerField = useCallback((index, options = {}) => {
14
+ if (options.multiline === true)
15
+ multilineFields.current.add(index);
16
+ else
17
+ multilineFields.current.delete(index);
18
+ const ref = (node) => {
19
+ fieldRefs.current[index] = node;
20
+ };
21
+ if (Platform.OS !== 'web' || options.multiline === true)
22
+ return { ref };
23
+ const lastSingleLineField = Array.from({ length: fieldCount }, (_, candidate) => candidate)
24
+ .reverse()
25
+ .find((candidate) => !multilineFields.current.has(candidate));
26
+ return {
27
+ ref,
28
+ returnKeyType: index === lastSingleLineField ? 'done' : 'next',
29
+ onSubmitEditing: () => {
30
+ for (let nextIndex = index + 1; nextIndex < fieldCount; nextIndex += 1) {
31
+ if (multilineFields.current.has(nextIndex))
32
+ continue;
33
+ const nextField = fieldRefs.current[nextIndex];
34
+ if (nextField) {
35
+ nextField.focus();
36
+ return;
37
+ }
38
+ }
39
+ submit();
40
+ },
41
+ };
42
+ }, [fieldCount, submit]);
43
+ return { registerField, submit };
44
+ }
45
+ //# sourceMappingURL=use-enter-to-next.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-enter-to-next.js","sourceRoot":"","sources":["../src/use-enter-to-next.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAuC,MAAM,cAAc,CAAC;AAe7E;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,UAAkB,EAAE,QAAoB;IACrE,MAAM,SAAS,GAAG,MAAM,CAAuB,EAAE,CAAC,CAAC;IACnD,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,GAAG,EAAU,CAAC,CAAC;IAElD,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE;QAC9B,QAAQ,EAAE,CAAC;IACb,CAAC,EAAE,CAA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,KAAK,EAAE,CAAC;wBAClB,OAAO;oBACT,CAAC;gBACH,CAAC;gBACD,MAAM,EAAE,CAAC;YACX,CAAC;SACF,CAAC;IACJ,CAAC,EACD,CAAC,UAAU,EAAE,MAAM,CAAC,CACrB,CAAC;IAEF,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;AACnC,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { type FocusContainer, type FocusableElement, type FocusTarget, type HostRef } from './dom-boundary.js';
2
+ export interface FocusTrapKeyEvent {
3
+ nativeEvent: {
4
+ key: string;
5
+ shiftKey?: boolean;
6
+ target?: unknown;
7
+ };
8
+ preventDefault(): void;
9
+ stopPropagation?(): void;
10
+ }
11
+ export interface FocusTrapOptions {
12
+ active: boolean;
13
+ containerRef: HostRef;
14
+ initialFocusRef?: HostRef | undefined;
15
+ onEscape?: (() => void) | undefined;
16
+ }
17
+ export interface FocusTrapProps {
18
+ onKeyDown: (event: FocusTrapKeyEvent) => void;
19
+ }
20
+ export declare function focusableElements(container: FocusContainer): FocusableElement[];
21
+ /** Moves focus to the far end when Tab leaves the trap, reporting whether it wrapped. */
22
+ export declare function wrapFocusAtBoundary(focusable: readonly FocusTarget[], activeElement: unknown, movingBackward: boolean): boolean;
23
+ /** Contains web Tab order inside an overlay and restores focus to its opener. */
24
+ /** Focuses the requested target, else the first focusable child, else the container. */
25
+ export declare function focusOverlayEntry(container: FocusContainer | null, requestedInitial: FocusTarget | null): void;
26
+ /**
27
+ * Applies one key press to a trapped container. Returns `escape` when the caller
28
+ * should close, `wrapped` when focus moved, and `ignored` otherwise.
29
+ */
30
+ export declare function applyFocusTrapKey(container: FocusContainer | null, event: FocusTrapKeyEvent): 'escape' | 'wrapped' | 'ignored';
31
+ export declare function useFocusTrap({ active, containerRef, initialFocusRef, onEscape, }: FocusTrapOptions): FocusTrapProps;
32
+ //# sourceMappingURL=use-focus-trap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-focus-trap.d.ts","sour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,EACN,YAAY,EACZ,eAAe,EACf,QAAQ,GACT,EAAE,gBAAgB,GAAG,cAAc,CAuCnC"}
@@ -0,0 +1,104 @@
1
+ import { useCallback, useEffect, useRef } from 'react';
2
+ import { activeFocusTarget, asFocusContainer, asFocusTarget, } from './dom-boundary.js';
3
+ import { hasDocument } from './platform.js';
4
+ const FOCUSABLE_SELECTOR = [
5
+ 'a[href]',
6
+ 'button:not([disabled])',
7
+ 'input:not([disabled])',
8
+ 'select:not([disabled])',
9
+ 'textarea:not([disabled])',
10
+ '[role="button"]:not([aria-disabled="true"])',
11
+ '[role="link"]',
12
+ '[role="menuitem"]:not([aria-disabled="true"])',
13
+ '[role="radio"]:not([aria-disabled="true"])',
14
+ '[tabindex]:not([tabindex="-1"])',
15
+ ].join(',');
16
+ function isAvailable(element) {
17
+ return (element.disabled !== true &&
18
+ element.getAttribute('tabindex') !== '-1' &&
19
+ element.getAttribute('aria-disabled') !== 'true' &&
20
+ element.getAttribute('aria-hidden') !== 'true' &&
21
+ !element.hasAttribute('inert'));
22
+ }
23
+ export function focusableElements(container) {
24
+ return Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter(isAvailable);
25
+ }
26
+ /** Moves focus to the far end when Tab leaves the trap, reporting whether it wrapped. */
27
+ export function wrapFocusAtBoundary(focusable, activeElement, movingBackward) {
28
+ if (focusable.length === 0)
29
+ return false;
30
+ const currentIndex = focusable.findIndex((element) => element === activeElement);
31
+ const shouldWrap = movingBackward
32
+ ? currentIndex <= 0
33
+ : currentIndex === -1 || currentIndex === focusable.length - 1;
34
+ if (!shouldWrap)
35
+ return false;
36
+ focusable[movingBackward ? focusable.length - 1 : 0]?.focus({ preventScroll: true });
37
+ return true;
38
+ }
39
+ /** Contains web Tab order inside an overlay and restores focus to its opener. */
40
+ /** Focuses the requested target, else the first focusable child, else the container. */
41
+ export function focusOverlayEntry(container, requestedInitial) {
42
+ const firstFocusable = container ? focusableElements(container)[0] : undefined;
43
+ (requestedInitial ?? firstFocusable ?? container)?.focus({ preventScroll: true });
44
+ }
45
+ /**
46
+ * Applies one key press to a trapped container. Returns `escape` when the caller
47
+ * should close, `wrapped` when focus moved, and `ignored` otherwise.
48
+ */
49
+ export function applyFocusTrapKey(container, event) {
50
+ const key = event.nativeEvent.key;
51
+ if (key === 'Escape') {
52
+ event.preventDefault();
53
+ event.stopPropagation?.();
54
+ return 'escape';
55
+ }
56
+ if (key !== 'Tab' || !container)
57
+ return 'ignored';
58
+ const focusable = focusableElements(container);
59
+ if (focusable.length === 0) {
60
+ event.preventDefault();
61
+ container.focus({ preventScroll: true });
62
+ return 'wrapped';
63
+ }
64
+ const activeElement = activeFocusTarget() ?? event.nativeEvent.target;
65
+ if (!wrapFocusAtBoundary(focusable, activeElement, event.nativeEvent.shiftKey === true)) {
66
+ return 'ignored';
67
+ }
68
+ event.preventDefault();
69
+ return 'wrapped';
70
+ }
71
+ export function useFocusTrap({ active, containerRef, initialFocusRef, onEscape, }) {
72
+ const onEscapeRef = useRef(onEscape);
73
+ const restoreTimerRef = useRef(undefined);
74
+ useEffect(() => {
75
+ onEscapeRef.current = onEscape;
76
+ }, [onEscape]);
77
+ useEffect(() => {
78
+ if (!hasDocument() || !active)
79
+ return;
80
+ if (restoreTimerRef.current !== undefined) {
81
+ clearTimeout(restoreTimerRef.current);
82
+ restoreTimerRef.current = undefined;
83
+ }
84
+ const previouslyFocused = activeFocusTarget();
85
+ focusOverlayEntry(asFocusContainer(containerRef), asFocusTarget(initialFocusRef));
86
+ return () => {
87
+ // useInert releases outside siblings in a sibling effect cleanup. Restore on
88
+ // the next task so the browser does not reject focus on a still-inert trigger.
89
+ restoreTimerRef.current = setTimeout(() => {
90
+ restoreTimerRef.current = undefined;
91
+ previouslyFocused?.focus({ preventScroll: true });
92
+ }, 0);
93
+ };
94
+ }, [active, containerRef, initialFocusRef]);
95
+ const onKeyDown = useCallback((event) => {
96
+ if (!hasDocument() || !active)
97
+ return;
98
+ if (applyFocusTrapKey(asFocusContainer(containerRef), event) === 'escape') {
99
+ onEscapeRef.current?.();
100
+ }
101
+ }, [active, containerRef]);
102
+ return { onKeyDown };
103
+ }
104
+ //# sourceMappingURL=use-focus-trap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-focus-trap.js","sourceRoot":"","sources":["../src/use-focus-trap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,GAKd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,kBAAkB,GAAG;IACzB,SAAS;IACT,wBAAwB;IACxB,uBAAuB;IACvB,wBAAwB;IACxB,0BAA0B;IAC1B,6CAA6C;IAC7C,eAAe;IACf,+CAA+C;IAC/C,4CAA4C;IAC5C,iCAAiC;CAClC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAmBZ,SAAS,WAAW,CAAC,OAAyB;IAC5C,OAAO,CACL,OAAO,CAAC,QAAQ,KAAK,IAAI;QACzB,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,IAAI;QACzC,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,KAAK,MAAM;QAChD,OAAO,CAAC,YAAY,CAAC,aAAa,CAAC,KAAK,MAAM;QAC9C,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAC/B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,SAAyB;IACzD,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AACxF,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,mBAAmB,CACjC,SAAiC,EACjC,aAAsB,EACtB,cAAuB;IAEvB,IAAI,SAAS,CAAC,MAAM,KAAK,CA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AAC,eAAe,CAAC,CAAC,CAAC;QAElF,OAAO,GAAG,EAAE;YACV,6EAA6E;YAC7E,+EAA+E;YAC/E,eAAe,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;gBACxC,eAAe,CAAC,OAAO,GAAG,SAAS,CAAC;gBACpC,iBAAiB,EAAE,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;YACpD,CAAC,EAAE,CAAC,CAAC,CAAC;QACR,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC;IAE5C,MAAM,SAAS,GAAG,WAAW,CAC3B,CAAC,KAAwB,EAAE,EAAE;QAC3B,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM;YAAE,OAAO;QACtC,IAAI,iBAAiB,CAAC,gBAAgB,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC;YAC1E,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;QAC1B,CAAC;IACH,CAAC,EACD,CAAC,MAAM,EAAE,YAAY,CAAC,CACvB,CAAC;IAEF,OAAO,EAAE,SAAS,EAAE,CAAC;AACvB,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { type HostRef, type QueryRoot, type TreeElement } from './dom-boundary.js';
2
+ /** Put this attribute on an element that must stay focusable while aria-hidden. */
3
+ export declare const ARIA_HIDDEN_INERT_OPT_OUT = "data-baukit-inert-opt-out";
4
+ /**
5
+ * Routers mark inactive web scenes aria-hidden, but aria-hidden alone leaves
6
+ * their descendants in the keyboard focus order. This keeps inert in lockstep
7
+ * without relying on React Native Web to forward an unknown DOM prop.
8
+ */
9
+ export declare function syncAriaHiddenInert(root: QueryRoot): void;
10
+ /** Mirrors aria-hidden onto inert for the whole document while mounted. */
11
+ export declare function useAriaHiddenInert(): void;
12
+ /** Marks every ancestor sibling of the container inert, preserving its own subtree. */
13
+ export declare function makeOutsideSiblingsInert(container: TreeElement): () => void;
14
+ /** Makes content outside a web overlay unavailable while the overlay is active. */
15
+ export declare function useInert(containerRef: HostRef, active: boolean): void;
16
+ //# sourceMappingURL=use-inert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-inert.d.ts","sourceRoot":"","sources":["../src/use-inert.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,WAAW,EACjB,MAAM,mBAAmB,CAAC;AAK3B,mFAAmF;AACnF,eAAO,MAAM,yBAAyB,8BAA8B,CAAC;AAErE;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAkBzD;AAED,2EAA2E;AAC3E,wBAAgB,kBAAkB,IAAI,IAAI,CA2BzC;AA4BD,uFAAuF;AACvF,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,WAAW,GAAG,MAAM,IAAI,CAiB3E;AAED,mFAAmF;AACnF,wBAAgB,QAAQ,CAAC,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAOrE"}
@@ -0,0 +1,107 @@
1
+ import { useEffect } from 'react';
2
+ import { asTreeElement, } from './dom-boundary.js';
3
+ import { hasDocument } from './platform.js';
4
+ const MANAGED_ARIA_HIDDEN_INERT = 'data-baukit-aria-hidden-inert';
5
+ /** Put this attribute on an element that must stay focusable while aria-hidden. */
6
+ export const ARIA_HIDDEN_INERT_OPT_OUT = 'data-baukit-inert-opt-out';
7
+ /**
8
+ * Routers mark inactive web scenes aria-hidden, but aria-hidden alone leaves
9
+ * their descendants in the keyboard focus order. This keeps inert in lockstep
10
+ * without relying on React Native Web to forward an unknown DOM prop.
11
+ */
12
+ export function syncAriaHiddenInert(root) {
13
+ for (const element of root.querySelectorAll(`[aria-hidden="true"], [${MANAGED_ARIA_HIDDEN_INERT}]`)) {
14
+ const shouldBeInert = element.getAttribute('aria-hidden') === 'true' &&
15
+ !element.hasAttribute(ARIA_HIDDEN_INERT_OPT_OUT);
16
+ if (shouldBeInert) {
17
+ if (!element.hasAttribute('inert')) {
18
+ element.setAttribute('inert', '');
19
+ element.setAttribute(MANAGED_ARIA_HIDDEN_INERT, '');
20
+ }
21
+ }
22
+ else if (element.hasAttribute(MANAGED_ARIA_HIDDEN_INERT)) {
23
+ element.removeAttribute(MANAGED_ARIA_HIDDEN_INERT);
24
+ element.removeAttribute('inert');
25
+ }
26
+ }
27
+ }
28
+ /** Mirrors aria-hidden onto inert for the whole document while mounted. */
29
+ export function useAriaHiddenInert() {
30
+ useEffect(() => {
31
+ if (!hasDocument())
32
+ return;
33
+ const root = document.body;
34
+ syncAriaHiddenInert(root);
35
+ const observer = new MutationObserver(() => {
36
+ syncAriaHiddenInert(root);
37
+ });
38
+ observer.observe(document.body, {
39
+ attributeFilter: ['aria-hidden'],
40
+ attributes: true,
41
+ childList: true,
42
+ subtree: true,
43
+ });
44
+ return () => {
45
+ observer.disconnect();
46
+ const managed = root.querySelectorAll(`[${MANAGED_ARIA_HIDDEN_INERT}]`);
47
+ for (const element of managed) {
48
+ element.removeAttribute(MANAGED_ARIA_HIDDEN_INERT);
49
+ element.removeAttribute('inert');
50
+ }
51
+ };
52
+ }, []);
53
+ }
54
+ const overlayInertStates = new WeakMap();
55
+ function acquireInert(element) {
56
+ const current = overlayInertStates.get(element);
57
+ if (current) {
58
+ current.count += 1;
59
+ }
60
+ else {
61
+ overlayInertStates.set(element, { count: 1, wasInert: element.hasAttribute('inert') });
62
+ element.setAttribute('inert', '');
63
+ }
64
+ return () => {
65
+ const state = overlayInertStates.get(element);
66
+ if (!state)
67
+ return;
68
+ state.count -= 1;
69
+ if (state.count > 0)
70
+ return;
71
+ overlayInertStates.delete(element);
72
+ if (!state.wasInert)
73
+ element.removeAttribute('inert');
74
+ };
75
+ }
76
+ /** Marks every ancestor sibling of the container inert, preserving its own subtree. */
77
+ export function makeOutsideSiblingsInert(container) {
78
+ const releases = [];
79
+ const body = typeof document === 'undefined' ? undefined : document.body;
80
+ let branch = container;
81
+ while (branch.parentElement !== null) {
82
+ const parent = branch.parentElement;
83
+ for (const sibling of Array.from(parent.children)) {
84
+ if (sibling !== branch)
85
+ releases.push(acquireInert(sibling));
86
+ }
87
+ branch = parent;
88
+ if (body !== undefined && parent === body)
89
+ break;
90
+ }
91
+ return () => {
92
+ for (const release of releases.reverse())
93
+ release();
94
+ };
95
+ }
96
+ /** Makes content outside a web overlay unavailable while the overlay is active. */
97
+ export function useInert(containerRef, active) {
98
+ useEffect(() => {
99
+ if (!hasDocument() || !active)
100
+ return;
101
+ const container = asTreeElement(containerRef);
102
+ if (!container?.parentElement)
103
+ return;
104
+ return makeOutsideSiblingsInert(container);
105
+ }, [active, containerRef]);
106
+ }
107
+ //# sourceMappingURL=use-inert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-inert.js","sourceRoot":"","sources":["../src/use-inert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EACL,aAAa,GAKd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,yBAAyB,GAAG,+BAA+B,CAAC;AAElE,mFAAmF;AACnF,MAAM,CAAC,MAAM,yBAAyB,GAAG,2BAA2B,CAAC;AAErE;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAe;IACjD,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,gBAAgB,CACzC,0BAA0B,yBAAyB,GAAG,CACvD,EAAE,CAAC;QACF,MAAM,aAAa,GACjB,OAAO,CAAC,YAAY,CAAC,aAAa,CAAC,KAAK,MAAM;YAC9C,CAAC,OAAO,CAAC,YAAY,CAAC,yBAAyB,CAAC,CAAC;QAEnD,IAAI,aAAa,EAAE,CAAC;YAClB,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;gBACnC,OAAO,CA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AAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YAClD,IAAI,OAAO,KAAK,MAAM;gBAAE,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;QAC/D,CAAC;QACD,MAAM,GAAG,MAAM,CAAC;QAChB,IAAI,IAAI,KAAK,SAAS,IAAK,MAAkB,KAAK,IAAI;YAAE,MAAM;IAChE,CAAC;IAED,OAAO,GAAG,EAAE;QACV,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE;YAAE,OAAO,EAAE,CAAC;IACtD,CAAC,CAAC;AACJ,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,QAAQ,CAAC,YAAqB,EAAE,MAAe;IAC7D,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM;YAAE,OAAO;QACtC,MAAM,SAAS,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;QAC9C,IAAI,CAAC,SAAS,EAAE,aAAa;YAAE,OAAO;QACtC,OAAO,wBAAwB,CAAC,SAAS,CAAC,CAAC;IAC7C,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { type RefObject } from 'react';
2
+ import { type View, type ViewProps } from 'react-native';
3
+ import { type FocusTrapProps } from './use-focus-trap.js';
4
+ /**
5
+ * Runs `task` once the overlay has laid out and returns a canceller. Products
6
+ * that already have a presentation event should pass their own.
7
+ */
8
+ export type DeferFocus = (task: () => void) => {
9
+ cancel: () => void;
10
+ };
11
+ export interface OverlayA11yOptions {
12
+ active: boolean;
13
+ containerRef: RefObject<View | null>;
14
+ /** Overrides how the native focus request waits for layout. */
15
+ deferFocus?: DeferFocus | undefined;
16
+ /** Container whose outside siblings go inert. Defaults to `containerRef`. */
17
+ inertContainerRef?: RefObject<View | null> | undefined;
18
+ initialFocusRef?: RefObject<View | null> | undefined;
19
+ onEscape?: (() => void) | undefined;
20
+ /** Native tag of the opener, when the caller already resolved it. */
21
+ triggerHandle?: number | null | undefined;
22
+ triggerRef?: RefObject<View | null> | undefined;
23
+ }
24
+ export type OverlayBackgroundProps = Pick<ViewProps, 'accessibilityElementsHidden' | 'importantForAccessibility'>;
25
+ export interface OverlayA11yResult {
26
+ backgroundProps: OverlayBackgroundProps;
27
+ containerProps: FocusTrapProps;
28
+ }
29
+ /**
30
+ * One contract for overlay focus on both platforms. Web traps Tab, closes on
31
+ * Escape, and makes the background inert. Native moves accessibility focus into
32
+ * the overlay after layout and returns it to the trigger on close.
33
+ */
34
+ export declare function useOverlayA11y({ active, containerRef, deferFocus, inertContainerRef, initialFocusRef, onEscape, triggerHandle, triggerRef, }: OverlayA11yOptions): OverlayA11yResult;
35
+ //# sourceMappingURL=use-overlay-a11y.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-overlay-a11y.d.ts","sourceRoot":"","sources":["../src/use-overlay-a11y.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAKL,KAAK,IAAI,EACT,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGxE;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,IAAI,KAAK;IAAE,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,CAAC;AAEtE,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IACrC,+DAA+D;IAC/D,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IACpC,6EAA6E;IAC7E,iBAAiB,CAAC,EAAE,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;IACvD,eAAe,CAAC,EAAE,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;IACrD,QAAQ,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IACpC,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1C,UAAU,CAAC,EAAE,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;CACjD;AAED,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACvC,SAAS,EACT,6BAA6B,GAAG,2BAA2B,CAC5D,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,sBAAsB,CAAC;IACxC,cAAc,EAAE,cAAc,CAAC;CAChC;AAmBD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,YAAY,EACZ,UAAuC,EACvC,iBAAiB,EACjB,eAAe,EACf,QAAQ,EACR,aAAa,EACb,UAAU,GACX,EAAE,kBAAkB,GAAG,iBAAiB,CA6BxC"}
@@ -0,0 +1,56 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { AccessibilityInfo, findNodeHandle, InteractionManager, Platform, } from 'react-native';
3
+ import { hostElement } from './dom-boundary.js';
4
+ import { useFocusTrap } from './use-focus-trap.js';
5
+ import { useInert } from './use-inert.js';
6
+ // InteractionManager is deprecated in React Native 0.86 with no replacement for
7
+ // "after the overlay presented". It stays the default so existing callers keep
8
+ // working; pass `deferFocus` to drive focus from a real layout event instead.
9
+ const deferUntilInteractionsDone = (task) =>
10
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
11
+ InteractionManager.runAfterInteractions(task);
12
+ function nodeHandle(ref) {
13
+ const host = hostElement(ref);
14
+ if (host === null)
15
+ return null;
16
+ try {
17
+ return findNodeHandle(host);
18
+ }
19
+ catch {
20
+ return null;
21
+ }
22
+ }
23
+ /**
24
+ * One contract for overlay focus on both platforms. Web traps Tab, closes on
25
+ * Escape, and makes the background inert. Native moves accessibility focus into
26
+ * the overlay after layout and returns it to the trigger on close.
27
+ */
28
+ export function useOverlayA11y({ active, containerRef, deferFocus = deferUntilInteractionsDone, inertContainerRef, initialFocusRef, onEscape, triggerHandle, triggerRef, }) {
29
+ const triggerHandleRef = useRef(null);
30
+ const containerProps = useFocusTrap({ active, containerRef, initialFocusRef, onEscape });
31
+ useInert(inertContainerRef ?? containerRef, active);
32
+ useEffect(() => {
33
+ if (Platform.OS === 'web' || !active)
34
+ return;
35
+ triggerHandleRef.current = triggerHandle ?? nodeHandle(triggerRef);
36
+ const task = deferFocus(() => {
37
+ const containerHandle = nodeHandle(containerRef);
38
+ if (containerHandle !== null)
39
+ AccessibilityInfo.setAccessibilityFocus(containerHandle);
40
+ });
41
+ return () => {
42
+ task.cancel();
43
+ const openerHandle = triggerHandleRef.current;
44
+ triggerHandleRef.current = null;
45
+ if (openerHandle !== null)
46
+ AccessibilityInfo.setAccessibilityFocus(openerHandle);
47
+ };
48
+ }, [active, containerRef, deferFocus, triggerHandle, triggerRef]);
49
+ return {
50
+ backgroundProps: Platform.OS !== 'web' && active
51
+ ? { accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' }
52
+ : {},
53
+ containerProps,
54
+ };
55
+ }
56
+ //# sourceMappingURL=use-overlay-a11y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-overlay-a11y.js","sourceRoot":"","sources":["../src/use-overlay-a11y.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAkB,MAAM,OAAO,CAAC;AAC1D,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,QAAQ,GAGT,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAuB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAgC1C,gF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;YACV,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,MAAM,YAAY,GAAG,gBAAgB,CAAC,OAAO,CAAC;YAC9C,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAC;YAChC,IAAI,YAAY,KAAK,IAAI;gBAAE,iBAAiB,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;QACnF,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC;IAElE,OAAO;QACL,eAAe,EACb,QAAQ,CAAC,EAAE,KAAK,KAAK,IAAI,MAAM;YAC7B,CAAC,CAAC,EAAE,2BAA2B,EAAE,IAAI,EAAE,yBAAyB,EAAE,qBAAqB,EAAE;YACzF,CAAC,CAAC,EAAE;QACR,cAAc;KACf,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Tracks the reduced-motion preference and follows changes during the session. */
2
+ export declare function useReducedMotion(): boolean;
3
+ //# sourceMappingURL=use-reduced-motion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-reduced-motion.d.ts","sourceRoot":"","sources":["../src/use-reduced-motion.ts"],"names":[],"mappings":"AAWA,mFAAmF;AACnF,wBAAgB,gBAAgB,IAAI,OAAO,CAgC1C"}
@@ -0,0 +1,40 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { AccessibilityInfo, Platform } from 'react-native';
3
+ const REDUCED_MOTION_QUERY = '(prefers-reduced-motion: reduce)';
4
+ function mediaQuery() {
5
+ return typeof window !== 'undefined' && typeof window.matchMedia === 'function'
6
+ ? window.matchMedia(REDUCED_MOTION_QUERY)
7
+ : null;
8
+ }
9
+ /** Tracks the reduced-motion preference and follows changes during the session. */
10
+ export function useReducedMotion() {
11
+ const [reducedMotion, setReducedMotion] = useState(() => Platform.OS === 'web' && (mediaQuery()?.matches ?? false));
12
+ useEffect(() => {
13
+ if (Platform.OS === 'web') {
14
+ const query = mediaQuery();
15
+ if (!query)
16
+ return;
17
+ const onChange = (event) => {
18
+ setReducedMotion(event.matches);
19
+ };
20
+ query.addEventListener('change', onChange);
21
+ return () => {
22
+ query.removeEventListener('change', onChange);
23
+ };
24
+ }
25
+ let mounted = true;
26
+ void AccessibilityInfo.isReduceMotionEnabled().then((enabled) => {
27
+ if (mounted)
28
+ setReducedMotion(enabled);
29
+ });
30
+ const subscription = AccessibilityInfo.addEventListener('reduceMotionChanged', (enabled) => {
31
+ setReducedMotion(enabled);
32
+ });
33
+ return () => {
34
+ mounted = false;
35
+ subscription.remove();
36
+ };
37
+ }, []);
38
+ return reducedMotion;
39
+ }
40
+ //# sourceMappingURL=use-reduced-motion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-reduced-motion.js","sourceRoot":"","sources":["../src/use-reduced-motion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,oBAAoB,GAAG,kCAAkC,CAAC;AAEhE,SAAS,UAAU;IACjB,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU;QAC7E,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC;QACzC,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,gBAAgB;IAC9B,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAChD,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,UAAU,EAAE,EAAE,OAAO,IAAI,KAAK,CAAC,CAChE,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;YAC1B,MAAM,KAAK,GAAG,UAAU,EAAE,CAAC;YAC3B,IAAI,CAAC,KAAK;gBAAE,OAAO;YACnB,MAAM,QAAQ,GAAG,CAAC,KAA0B,EAAE,EAAE;gBAC9C,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAClC,CAAC,CAAC;YACF,KAAK,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAC3C,OAAO,GAAG,EAAE;gBACV,KAAK,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAChD,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,KAAK,iBAAiB,CAAC,qBAAqB,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9D,IAAI,OAAO;gBAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;QACH,MAAM,YAAY,GAAG,iBAAiB,CAAC,gBAAgB,CAAC,qBAAqB,EAAE,CAAC,OAAO,EAAE,EAAE;YACzF,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE;YACV,OAAO,GAAG,KAAK,CAAC;YAChB,YAAY,CAAC,MAAM,EAAE,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { View } from 'react-native';
2
+ export interface RovingKeyEvent {
3
+ nativeEvent: {
4
+ key: string;
5
+ };
6
+ preventDefault: () => void;
7
+ }
8
+ export interface RovingRadioGroupOptions<T> {
9
+ onChange: (value: T) => void;
10
+ options: readonly T[];
11
+ value: T;
12
+ }
13
+ export interface RovingRadioProps {
14
+ onKeyDown: (event: RovingKeyEvent) => void;
15
+ ref: (node: View | null) => void;
16
+ tabIndex: 0 | -1;
17
+ }
18
+ export interface RovingRadioGroupResult {
19
+ radioProps: (index: number) => RovingRadioProps;
20
+ }
21
+ /** Maps an arrow/Home/End key to the option it should move to, or null to ignore it. */
22
+ export declare function nextIndexFor(key: string, index: number, length: number): number | null;
23
+ /** Gives a radio group one tab stop and arrow-key movement between its options. */
24
+ export declare function useRovingRadioGroup<T>({ onChange, options, value, }: RovingRadioGroupOptions<T>): RovingRadioGroupResult;
25
+ //# sourceMappingURL=use-roving-radio-group.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-roving-radio-group.d.ts","sourceRoot":"","sources":["../src/use-roving-radio-group.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAIzC,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7B,cAAc,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACxC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC7B,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC;IACtB,KAAK,EAAE,CAAC,CAAC;CACV;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAC3C,GAAG,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC;IACjC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAClB;AAED,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,gBAAgB,CAAC;CACjD;AAED,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAetF;AAED,mFAAmF;AACnF,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,EACrC,QAAQ,EACR,OAAO,EACP,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAAG,sBAAsB,CA6BrD"}
@@ -0,0 +1,48 @@
1
+ import { useRef } from 'react';
2
+ import { asFocusTarget } from './dom-boundary.js';
3
+ /** Maps an arrow/Home/End key to the option it should move to, or null to ignore it. */
4
+ export function nextIndexFor(key, index, length) {
5
+ switch (key) {
6
+ case 'ArrowDown':
7
+ case 'ArrowRight':
8
+ return (index + 1) % length;
9
+ case 'ArrowLeft':
10
+ case 'ArrowUp':
11
+ return (index - 1 + length) % length;
12
+ case 'Home':
13
+ return 0;
14
+ case 'End':
15
+ return length - 1;
16
+ default:
17
+ return null;
18
+ }
19
+ }
20
+ /** Gives a radio group one tab stop and arrow-key movement between its options. */
21
+ export function useRovingRadioGroup({ onChange, options, value, }) {
22
+ const optionRefs = useRef([]);
23
+ const selectedIndex = Math.max(0, options.findIndex((option) => Object.is(option, value)));
24
+ const onKeyDown = (event, index) => {
25
+ if (options.length === 0)
26
+ return;
27
+ const nextIndex = nextIndexFor(event.nativeEvent.key, index, options.length);
28
+ if (nextIndex === null)
29
+ return;
30
+ event.preventDefault();
31
+ const nextValue = options[nextIndex];
32
+ if (nextValue !== undefined)
33
+ onChange(nextValue);
34
+ asFocusTarget({ current: optionRefs.current[nextIndex] ?? null })?.focus();
35
+ };
36
+ return {
37
+ radioProps: (index) => ({
38
+ onKeyDown: (event) => {
39
+ onKeyDown(event, index);
40
+ },
41
+ ref: (node) => {
42
+ optionRefs.current[index] = node;
43
+ },
44
+ tabIndex: index === selectedIndex ? 0 : -1,
45
+ }),
46
+ };
47
+ }
48
+ //# sourceMappingURL=use-roving-radio-group.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-roving-radio-group.js","sourceRoot":"","sources":["../src/use-roving-radio-group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,aAAa,EAAE,MAAM,mBA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AAC;QACjD,aAAa,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;IAC7E,CAAC,CAAC;IAEF,OAAO;QACL,UAAU,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC;YAC9B,SAAS,EAAE,CAAC,KAAqB,EAAE,EAAE;gBACnC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAC1B,CAAC;YACD,GAAG,EAAE,CAAC,IAAiB,EAAE,EAAE;gBACzB,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;YACnC,CAAC;YACD,QAAQ,EAAE,KAAK,KAAK,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3C,CAAC;KACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type SingleFlightRunner = <T>(operation: () => Promise<T>) => Promise<T | undefined>;
2
+ /**
3
+ * A synchronous mutex for async UI mutations. React state alone cannot lock the
4
+ * same tick, so a double tap would submit twice. A rejected call returns undefined.
5
+ */
6
+ export declare function useSingleFlight(): SingleFlightRunner;
7
+ //# sourceMappingURL=use-single-flight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-single-flight.d.ts","sourceRoot":"","sources":["../src/use-single-flight.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AAE5F;;;GAGG;AACH,wBAAgB,eAAe,IAAI,kBAAkB,CAapD"}
@@ -0,0 +1,20 @@
1
+ import { useCallback, useRef } from 'react';
2
+ /**
3
+ * A synchronous mutex for async UI mutations. React state alone cannot lock the
4
+ * same tick, so a double tap would submit twice. A rejected call returns undefined.
5
+ */
6
+ export function useSingleFlight() {
7
+ const active = useRef(false);
8
+ return useCallback(async (operation) => {
9
+ if (active.current)
10
+ return undefined;
11
+ active.current = true;
12
+ try {
13
+ return await operation();
14
+ }
15
+ finally {
16
+ active.current = false;
17
+ }
18
+ }, []);
19
+ }
20
+ //# sourceMappingURL=use-single-flight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-single-flight.js","sourceRoot":"","sources":["../src/use-single-flight.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAI5C;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAE7B,OAAO,WAAW,CAAC,KAAK,EAAK,SAA2B,EAAE,EAAE;QAC1D,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO,SAAS,CAAC;QAErC,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC;YACH,OAAO,MAAM,SAAS,EAAE,CAAC;QAC3B,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;QACzB,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
package/dist/web.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The entry point for a plain React web app. Nothing reachable from here
3
+ * imports `react-native` at runtime, so a product without React Native in its
4
+ * dependency tree can bundle it. React Native products import the package root
5
+ * instead and get these exports plus the native ones.
6
+ */
7
+ export * from './dom-boundary.js';
8
+ export * from './use-focus-trap.js';
9
+ export * from './use-inert.js';
10
+ export * from './use-single-flight.js';
11
+ //# sourceMappingURL=web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC"}
package/dist/web.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The entry point for a plain React web app. Nothing reachable from here
3
+ * imports `react-native` at runtime, so a product without React Native in its
4
+ * dependency tree can bundle it. React Native products import the package root
5
+ * instead and get these exports plus the native ones.
6
+ */
7
+ export * from './dom-boundary.js';
8
+ export * from './use-focus-trap.js';
9
+ export * from './use-inert.js';
10
+ export * from './use-single-flight.js';
11
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@baukit/a11y-core",
3
+ "version": "0.1.0",
4
+ "description": "Accessibility behavior shared by web and React Native products: overlay focus, inert background content, announcements, reduced motion, and keyboard movement.",
5
+ "license": "MIT",
6
+ "author": "Patrick Koss",
7
+ "homepage": "https://github.com/PatrickKoss/baukit#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/PatrickKoss/baukit.git",
11
+ "directory": "typescript/packages/a11y-core"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/PatrickKoss/baukit/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "type": "module",
20
+ "engines": {
21
+ "node": ">=24.0.0"
22
+ },
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ },
29
+ "./web": {
30
+ "types": "./dist/web.d.ts",
31
+ "import": "./dist/web.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md",
37
+ "LICENSE"
38
+ ],
39
+ "devDependencies": {
40
+ "@testing-library/dom": "10.4.1",
41
+ "@testing-library/react": "16.3.2",
42
+ "@types/react": "19.2.18",
43
+ "jsdom": "30.0.1",
44
+ "react": "19.2.8",
45
+ "react-dom": "19.2.8",
46
+ "react-native": "0.86.2",
47
+ "typescript": "6.0.3",
48
+ "vitest": "4.1.10"
49
+ },
50
+ "peerDependencies": {
51
+ "react": "^19.2.0",
52
+ "react-native": "^0.86.2"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "react-native": {
56
+ "optional": true
57
+ }
58
+ },
59
+ "scripts": {
60
+ "build": "tsc -p tsconfig.json",
61
+ "test": "vitest run --config ../../vitest.config.ts",
62
+ "lint": "eslint src --max-warnings=0",
63
+ "format:check": "prettier --check src package.json tsconfig.json"
64
+ }
65
+ }