@baukit/a11y-core 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/route-focus.d.ts +21 -0
- package/dist/route-focus.d.ts.map +1 -0
- package/dist/route-focus.js +137 -0
- package/dist/route-focus.js.map +1 -0
- package/dist/use-reduced-motion.d.ts +6 -0
- package/dist/use-reduced-motion.d.ts.map +1 -1
- package/dist/use-reduced-motion.js +30 -9
- package/dist/use-reduced-motion.js.map +1 -1
- package/dist/web.d.ts +1 -0
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +1 -0
- package/dist/web.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,9 +11,10 @@ product's Expo SDK decides the versions, and React Native is optional.
|
|
|
11
11
|
|
|
12
12
|
A React Native product imports the package root and gets everything. A plain React web app imports
|
|
13
13
|
`@baukit/a11y-core/web` and gets `useFocusTrap`, `useInert`, `useAriaHiddenInert`,
|
|
14
|
-
`useSingleFlight`, and the `dom-boundary` helpers. Nothing reachable
|
|
15
|
-
`react-native`, at runtime or in its types, so the app needs no React
|
|
16
|
-
tree. `react-native` is an optional peer dependency for exactly that
|
|
14
|
+
`useSingleFlight`, `createRouteFocusController`, and the `dom-boundary` helpers. Nothing reachable
|
|
15
|
+
from that entry imports `react-native`, at runtime or in its types, so the app needs no React
|
|
16
|
+
Native in its dependency tree. `react-native` is an optional peer dependency for exactly that
|
|
17
|
+
reason.
|
|
17
18
|
|
|
18
19
|
The DOM hooks ask whether a document exists rather than asking `Platform` which OS this is. The
|
|
19
20
|
two questions have the same answer here: every branch those hooks guard reads or writes the DOM,
|
|
@@ -56,7 +57,7 @@ const deferFocus = (task: () => void) => {
|
|
|
56
57
|
};
|
|
57
58
|
```
|
|
58
59
|
|
|
59
|
-
Spread `backgroundProps` onto the content
|
|
60
|
+
Spread `backgroundProps` onto the content _behind_ the overlay, never the overlay itself. It sets
|
|
60
61
|
`accessibilityElementsHidden` and `importantForAccessibility` while the overlay is open, and is
|
|
61
62
|
empty on web and while closed. Spread `containerProps` onto the overlay container.
|
|
62
63
|
|
|
@@ -65,6 +66,29 @@ overlay. `useAriaHiddenInert` covers a separate problem: routers mark inactive w
|
|
|
65
66
|
`aria-hidden`, which leaves their descendants in the keyboard focus order. Mount it once at the
|
|
66
67
|
app root. Put `ARIA_HIDDEN_INERT_OPT_OUT` on an element that must stay focusable anyway.
|
|
67
68
|
|
|
69
|
+
## Route focus
|
|
70
|
+
|
|
71
|
+
WebKit can blur the initiating control to `body` when a router makes the outgoing scene inert.
|
|
72
|
+
Create one `createRouteFocusController` at app startup so it can remember the last reachable
|
|
73
|
+
focused element. Enter a route with a target getter, then run the returned cleanup when the route
|
|
74
|
+
becomes inactive:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
const routeFocus = createRouteFocusController();
|
|
78
|
+
|
|
79
|
+
const leaveRoute = routeFocus.enterRoute(() =>
|
|
80
|
+
document.querySelector<HTMLElement>('[data-route-heading]'),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
leaveRoute();
|
|
84
|
+
routeFocus.dispose();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The controller waits for the destination target to mount and retries on animation frames for up to
|
|
88
|
+
1.5 seconds. It waits for inert or hidden return targets to become reachable. It stops if the user
|
|
89
|
+
moves focus to another reachable element, and it never focuses a target below `inert`,
|
|
90
|
+
`aria-hidden="true"`, or `hidden`.
|
|
91
|
+
|
|
68
92
|
## The React Native to DOM boundary
|
|
69
93
|
|
|
70
94
|
React Native Web renders a `View` as a DOM element, but the `View` type never says so. Every
|
|
@@ -85,8 +109,11 @@ product-owned id, and `assertive: true` to interrupt rather than wait for a paus
|
|
|
85
109
|
|
|
86
110
|
## Reduced motion, groups, and forms
|
|
87
111
|
|
|
88
|
-
`
|
|
89
|
-
|
|
112
|
+
`useReducedMotionPreference` returns `{ reducedMotion, resolved }` and follows preference changes
|
|
113
|
+
on both platforms. Web resolves during the first render. The native query is asynchronous, so
|
|
114
|
+
`resolved` starts as `false` and becomes `true` whether the query succeeds or fails. Do not start
|
|
115
|
+
non-essential motion until it is `true`. `useReducedMotion` remains the boolean form for existing
|
|
116
|
+
callers.
|
|
90
117
|
|
|
91
118
|
`useRovingRadioGroup` gives a radio group a single tab stop and arrow-key movement between its
|
|
92
119
|
options, wrapping at both ends and honoring Home and End. `radioProps(index)` returns the
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,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
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +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"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,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,21 @@
|
|
|
1
|
+
export type RouteFocusTarget = Element & {
|
|
2
|
+
focus(options?: FocusOptions): void;
|
|
3
|
+
};
|
|
4
|
+
export interface RouteFocusRuntime {
|
|
5
|
+
document: Document;
|
|
6
|
+
requestAnimationFrame(callback: FrameRequestCallback): number;
|
|
7
|
+
cancelAnimationFrame(handle: number): void;
|
|
8
|
+
setTimeout(callback: () => void, delayMs: number): number;
|
|
9
|
+
clearTimeout(handle: number): void;
|
|
10
|
+
now(): number;
|
|
11
|
+
}
|
|
12
|
+
export interface RouteFocusControllerOptions {
|
|
13
|
+
focusRetryTimeoutMs?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface RouteFocusController {
|
|
16
|
+
enterRoute(target: () => RouteFocusTarget | null): () => void;
|
|
17
|
+
dispose(): void;
|
|
18
|
+
}
|
|
19
|
+
/** Tracks route entry and restores focus when the returned cleanup runs. */
|
|
20
|
+
export declare function createRouteFocusController(runtime?: RouteFocusRuntime, options?: RouteFocusControllerOptions): RouteFocusController;
|
|
21
|
+
//# sourceMappingURL=route-focus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-focus.d.ts","sourceRoot":"","sources":["../src/route-focus.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG;IACvC,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CACrC,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,QAAQ,CAAC;IACnB,qBAAqB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,CAAC;IAC9D,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1D,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,GAAG,IAAI,MAAM,CAAC;CACf;AAED,MAAM,WAAW,2BAA2B;IAC1C,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,MAAM,EAAE,MAAM,gBAAgB,GAAG,IAAI,GAAG,MAAM,IAAI,CAAC;IAC9D,OAAO,IAAI,IAAI,CAAC;CACjB;AAyBD,4EAA4E;AAC5E,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,iBAAoC,EAC7C,OAAO,GAAE,2BAAgC,GACxC,oBAAoB,CA4HtB"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const DEFAULT_FOCUS_RETRY_TIMEOUT_MS = 1500;
|
|
2
|
+
const UNREACHABLE_ANCESTOR = '[inert], [aria-hidden="true"], [hidden]';
|
|
3
|
+
function browserRuntime() {
|
|
4
|
+
return {
|
|
5
|
+
document: globalThis.document,
|
|
6
|
+
requestAnimationFrame: (callback) => globalThis.requestAnimationFrame(callback),
|
|
7
|
+
cancelAnimationFrame: (handle) => {
|
|
8
|
+
globalThis.cancelAnimationFrame(handle);
|
|
9
|
+
},
|
|
10
|
+
setTimeout: (callback, delayMs) => globalThis.setTimeout(callback, delayMs),
|
|
11
|
+
clearTimeout: (handle) => {
|
|
12
|
+
globalThis.clearTimeout(handle);
|
|
13
|
+
},
|
|
14
|
+
now: () => Date.now(),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function asRouteFocusTarget(value) {
|
|
18
|
+
if (typeof value !== 'object' || value === null)
|
|
19
|
+
return null;
|
|
20
|
+
const candidate = value;
|
|
21
|
+
return typeof candidate.focus === 'function' && typeof candidate.closest === 'function'
|
|
22
|
+
? candidate
|
|
23
|
+
: null;
|
|
24
|
+
}
|
|
25
|
+
/** Tracks route entry and restores focus when the returned cleanup runs. */
|
|
26
|
+
export function createRouteFocusController(runtime = browserRuntime(), options = {}) {
|
|
27
|
+
const { document } = runtime;
|
|
28
|
+
const focusRetryTimeoutMs = Math.max(0, options.focusRetryTimeoutMs ?? DEFAULT_FOCUS_RETRY_TIMEOUT_MS);
|
|
29
|
+
let lastFocusedTarget = null;
|
|
30
|
+
let cancelRetry = () => undefined;
|
|
31
|
+
let disposed = false;
|
|
32
|
+
let session = 0;
|
|
33
|
+
const reachable = (target) => {
|
|
34
|
+
if (target.ownerDocument !== document || !target.isConnected)
|
|
35
|
+
return false;
|
|
36
|
+
if (target.closest(UNREACHABLE_ANCESTOR) !== null)
|
|
37
|
+
return false;
|
|
38
|
+
return !('disabled' in target && target.disabled === true);
|
|
39
|
+
};
|
|
40
|
+
const activeTarget = () => asRouteFocusTarget(document.activeElement);
|
|
41
|
+
const onFocusIn = (event) => {
|
|
42
|
+
const target = asRouteFocusTarget(event.target);
|
|
43
|
+
if (target !== null && target !== document.body && reachable(target)) {
|
|
44
|
+
lastFocusedTarget = target;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
document.addEventListener('focusin', onFocusIn, true);
|
|
48
|
+
const retryFocus = (getTarget, allowedActiveTargets, observedTargets) => {
|
|
49
|
+
const startedAt = runtime.now();
|
|
50
|
+
let frame = null;
|
|
51
|
+
let timer = null;
|
|
52
|
+
let stopped = false;
|
|
53
|
+
const stop = () => {
|
|
54
|
+
if (stopped)
|
|
55
|
+
return;
|
|
56
|
+
stopped = true;
|
|
57
|
+
if (frame !== null)
|
|
58
|
+
runtime.cancelAnimationFrame(frame);
|
|
59
|
+
if (timer !== null)
|
|
60
|
+
runtime.clearTimeout(timer);
|
|
61
|
+
frame = null;
|
|
62
|
+
timer = null;
|
|
63
|
+
};
|
|
64
|
+
const attempt = () => {
|
|
65
|
+
frame = null;
|
|
66
|
+
if (stopped)
|
|
67
|
+
return;
|
|
68
|
+
if (runtime.now() - startedAt >= focusRetryTimeoutMs) {
|
|
69
|
+
stop();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const target = getTarget();
|
|
73
|
+
if (target !== null)
|
|
74
|
+
observedTargets?.add(target);
|
|
75
|
+
const active = activeTarget();
|
|
76
|
+
if (active === target && target !== null && reachable(target)) {
|
|
77
|
+
stop();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (active !== null &&
|
|
81
|
+
active !== document.body &&
|
|
82
|
+
reachable(active) &&
|
|
83
|
+
!allowedActiveTargets.has(active)) {
|
|
84
|
+
stop();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (target !== null && reachable(target)) {
|
|
88
|
+
target.focus({ preventScroll: true });
|
|
89
|
+
const focused = activeTarget();
|
|
90
|
+
if (focused === target ||
|
|
91
|
+
(focused !== null &&
|
|
92
|
+
focused !== document.body &&
|
|
93
|
+
reachable(focused) &&
|
|
94
|
+
!allowedActiveTargets.has(focused))) {
|
|
95
|
+
stop();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
frame = runtime.requestAnimationFrame(attempt);
|
|
100
|
+
};
|
|
101
|
+
timer = runtime.setTimeout(stop, focusRetryTimeoutMs);
|
|
102
|
+
frame = runtime.requestAnimationFrame(attempt);
|
|
103
|
+
return stop;
|
|
104
|
+
};
|
|
105
|
+
const enterRoute = (getTarget) => {
|
|
106
|
+
cancelRetry();
|
|
107
|
+
const id = ++session;
|
|
108
|
+
const active = activeTarget();
|
|
109
|
+
const returnTarget = active !== null && active !== document.body && reachable(active) ? active : lastFocusedTarget;
|
|
110
|
+
const allowedOnEntry = new Set();
|
|
111
|
+
if (returnTarget !== null)
|
|
112
|
+
allowedOnEntry.add(returnTarget);
|
|
113
|
+
const entryTargets = new Set();
|
|
114
|
+
cancelRetry = retryFocus(getTarget, allowedOnEntry, entryTargets);
|
|
115
|
+
return () => {
|
|
116
|
+
if (disposed || id !== session)
|
|
117
|
+
return;
|
|
118
|
+
session += 1;
|
|
119
|
+
cancelRetry();
|
|
120
|
+
if (returnTarget === null)
|
|
121
|
+
return;
|
|
122
|
+
cancelRetry = retryFocus(() => returnTarget, entryTargets);
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
enterRoute,
|
|
127
|
+
dispose() {
|
|
128
|
+
if (disposed)
|
|
129
|
+
return;
|
|
130
|
+
disposed = true;
|
|
131
|
+
session += 1;
|
|
132
|
+
cancelRetry();
|
|
133
|
+
document.removeEventListener('focusin', onFocusIn, true);
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=route-focus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-focus.js","sourceRoot":"","sources":["../src/route-focus.ts"],"names":[],"mappings":"AAAA,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAC5C,MAAM,oBAAoB,GAAG,yCAAyC,CAAC;AAwBvE,SAAS,cAAc;IACrB,OAAO;QACL,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,qBAAqB,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,QAAQ,CAAC;QAC/E,oBAAoB,EAAE,CAAC,MAAM,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E,CAAC;YACd,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QAC3D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export interface ReducedMotionPreference {
|
|
2
|
+
reducedMotion: boolean;
|
|
3
|
+
resolved: boolean;
|
|
4
|
+
}
|
|
5
|
+
/** Tracks when the reduced-motion preference is ready and follows later changes. */
|
|
6
|
+
export declare function useReducedMotionPreference(): ReducedMotionPreference;
|
|
1
7
|
/** Tracks the reduced-motion preference and follows changes during the session. */
|
|
2
8
|
export declare function useReducedMotion(): boolean;
|
|
3
9
|
//# sourceMappingURL=use-reduced-motion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-reduced-motion.d.ts","sourceRoot":"","sources":["../src/use-reduced-motion.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-reduced-motion.d.ts","sourceRoot":"","sources":["../src/use-reduced-motion.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,uBAAuB;IACtC,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAQD,oFAAoF;AACpF,wBAAgB,0BAA0B,IAAI,uBAAuB,CA+CpE;AAED,mFAAmF;AACnF,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C"}
|
|
@@ -6,16 +6,22 @@ function mediaQuery() {
|
|
|
6
6
|
? window.matchMedia(REDUCED_MOTION_QUERY)
|
|
7
7
|
: null;
|
|
8
8
|
}
|
|
9
|
-
/** Tracks the reduced-motion preference and follows changes
|
|
10
|
-
export function
|
|
11
|
-
const [
|
|
9
|
+
/** Tracks when the reduced-motion preference is ready and follows later changes. */
|
|
10
|
+
export function useReducedMotionPreference() {
|
|
11
|
+
const [preference, setPreference] = useState(() => {
|
|
12
|
+
const web = Platform.OS === 'web';
|
|
13
|
+
return {
|
|
14
|
+
reducedMotion: web && (mediaQuery()?.matches ?? false),
|
|
15
|
+
resolved: web,
|
|
16
|
+
};
|
|
17
|
+
});
|
|
12
18
|
useEffect(() => {
|
|
13
19
|
if (Platform.OS === 'web') {
|
|
14
20
|
const query = mediaQuery();
|
|
15
21
|
if (!query)
|
|
16
22
|
return;
|
|
17
23
|
const onChange = (event) => {
|
|
18
|
-
|
|
24
|
+
setPreference({ reducedMotion: event.matches, resolved: true });
|
|
19
25
|
};
|
|
20
26
|
query.addEventListener('change', onChange);
|
|
21
27
|
return () => {
|
|
@@ -23,18 +29,33 @@ export function useReducedMotion() {
|
|
|
23
29
|
};
|
|
24
30
|
}
|
|
25
31
|
let mounted = true;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
let preferenceChanged = false;
|
|
33
|
+
const settle = (reducedMotion) => {
|
|
34
|
+
if (!mounted)
|
|
35
|
+
return;
|
|
36
|
+
setPreference((current) => ({
|
|
37
|
+
reducedMotion: reducedMotion === undefined || preferenceChanged ? current.reducedMotion : reducedMotion,
|
|
38
|
+
resolved: true,
|
|
39
|
+
}));
|
|
40
|
+
};
|
|
41
|
+
void AccessibilityInfo.isReduceMotionEnabled().then(settle, () => {
|
|
42
|
+
settle();
|
|
29
43
|
});
|
|
30
44
|
const subscription = AccessibilityInfo.addEventListener('reduceMotionChanged', (enabled) => {
|
|
31
|
-
|
|
45
|
+
if (!mounted)
|
|
46
|
+
return;
|
|
47
|
+
preferenceChanged = true;
|
|
48
|
+
setPreference({ reducedMotion: enabled, resolved: true });
|
|
32
49
|
});
|
|
33
50
|
return () => {
|
|
34
51
|
mounted = false;
|
|
35
52
|
subscription.remove();
|
|
36
53
|
};
|
|
37
54
|
}, []);
|
|
38
|
-
return
|
|
55
|
+
return preference;
|
|
56
|
+
}
|
|
57
|
+
/** Tracks the reduced-motion preference and follows changes during the session. */
|
|
58
|
+
export function useReducedMotion() {
|
|
59
|
+
return useReducedMotionPreference().reducedMotion;
|
|
39
60
|
}
|
|
40
61
|
//# sourceMappingURL=use-reduced-motion.js.map
|
|
@@ -1 +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;
|
|
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;AAOhE,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,oFAAoF;AACpF,MAAM,UAAU,0BAA0B;IACxC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAA0B,GAAG,EAAE;QACzE,MAAM,GAAG,GAAG,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC;QAClC,OAAO;YACL,aAAa,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,EAAE,OAAO,IAAI,KAAK,CAAC;YACtD,QAAQ,EAAE,GAAG;SACd,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;YAC1B,MAAM,KAAK,GAAG,UAAU,EAAE,CAAC;YAC3B,IAAI,CAAC,KAAK;gBAA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EAAE,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,gBAAgB;IAC9B,OAAO,0BAA0B,EAAE,CAAC,aAAa,CAAC;AACpD,CAAC"}
|
package/dist/web.d.ts
CHANGED
package/dist/web.d.ts.map
CHANGED
|
@@ -1 +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"}
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC"}
|
package/dist/web.js
CHANGED
package/dist/web.js.map
CHANGED
|
@@ -1 +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"}
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baukit/a11y-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Accessibility behavior shared by web and React Native products: overlay focus, inert background content, announcements, reduced motion, and keyboard movement.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Patrick Koss",
|