@baukit/a11y-core 0.5.0 → 0.5.1

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 CHANGED
@@ -11,8 +11,8 @@ 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
- `useRovingMenu`, `nextEnabledMenuIndex`, `useSingleFlight`, `createRouteFocusController`, and the
15
- `dom-boundary` helpers. Nothing reachable
14
+ `useReducedMotion`, `useReducedMotionPreference`, `useRovingMenu`, `nextEnabledMenuIndex`,
15
+ `useSingleFlight`, `createRouteFocusController`, and the `dom-boundary` helpers. Nothing reachable
16
16
  from that entry imports `react-native`, at runtime or in its types, so the app needs no React
17
17
  Native in its dependency tree. `react-native` is an optional peer dependency for exactly that
18
18
  reason.
@@ -180,6 +180,12 @@ on both platforms. Web resolves during the first render. The native query is asy
180
180
  non-essential motion until it is `true`. `useReducedMotion` remains the boolean form for existing
181
181
  callers.
182
182
 
183
+ The web entry exports both hooks with the same names and return shapes, built on `matchMedia` and
184
+ `useSyncExternalStore` alone. They read the media query during the first client render and follow
185
+ its `change` events. During server rendering and the hydration render they report
186
+ `{ reducedMotion: false, resolved: false }`, then resolve on the client. A host without
187
+ `matchMedia` reports no preference, resolved.
188
+
183
189
  `useRovingRadioGroup` gives a radio group a single tab stop and arrow-key movement between its
184
190
  options, wrapping at both ends and honoring Home and End. `radioProps(index)` returns the
185
191
  `tabIndex`, `ref`, and `onKeyDown` for one option.
@@ -0,0 +1,14 @@
1
+ export interface ReducedMotionPreference {
2
+ reducedMotion: boolean;
3
+ resolved: boolean;
4
+ }
5
+ /** The `prefers-reduced-motion` media query, or `null` where the host has no `matchMedia`. */
6
+ export declare function reducedMotionQuery(): MediaQueryList | null;
7
+ /**
8
+ * Follows `prefers-reduced-motion` through `matchMedia`. `resolved` is `false` only while
9
+ * rendering on a server, which cannot see the user's setting.
10
+ */
11
+ export declare function useReducedMotionPreference(): ReducedMotionPreference;
12
+ /** Follows `prefers-reduced-motion` and its changes during the session. */
13
+ export declare function useReducedMotion(): boolean;
14
+ //# sourceMappingURL=use-reduced-motion-web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-reduced-motion-web.d.ts","sourceRoot":"","sources":["../src/use-reduced-motion-web.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,uBAAuB;IACtC,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,8FAA8F;AAC9F,wBAAgB,kBAAkB,IAAI,cAAc,GAAG,IAAI,CAI1D;AAqBD;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,uBAAuB,CAIpE;AAED,2EAA2E;AAC3E,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C"}
@@ -0,0 +1,38 @@
1
+ import { useMemo, useSyncExternalStore } from 'react';
2
+ const REDUCED_MOTION_QUERY = '(prefers-reduced-motion: reduce)';
3
+ /** The `prefers-reduced-motion` media query, or `null` where the host has no `matchMedia`. */
4
+ export function reducedMotionQuery() {
5
+ return typeof window !== 'undefined' && typeof window.matchMedia === 'function'
6
+ ? window.matchMedia(REDUCED_MOTION_QUERY)
7
+ : null;
8
+ }
9
+ function subscribeToQuery(onChange) {
10
+ const query = reducedMotionQuery();
11
+ if (query === null) {
12
+ return () => undefined;
13
+ }
14
+ query.addEventListener('change', onChange);
15
+ return () => {
16
+ query.removeEventListener('change', onChange);
17
+ };
18
+ }
19
+ function subscribeToNothing() {
20
+ return () => undefined;
21
+ }
22
+ const readQuery = () => reducedMotionQuery()?.matches ?? false;
23
+ const onClient = () => true;
24
+ const onServer = () => false;
25
+ /**
26
+ * Follows `prefers-reduced-motion` through `matchMedia`. `resolved` is `false` only while
27
+ * rendering on a server, which cannot see the user's setting.
28
+ */
29
+ export function useReducedMotionPreference() {
30
+ const reducedMotion = useSyncExternalStore(subscribeToQuery, readQuery, onServer);
31
+ const resolved = useSyncExternalStore(subscribeToNothing, onClient, onServer);
32
+ return useMemo(() => ({ reducedMotion, resolved }), [reducedMotion, resolved]);
33
+ }
34
+ /** Follows `prefers-reduced-motion` and its changes during the session. */
35
+ export function useReducedMotion() {
36
+ return useSyncExternalStore(subscribeToQuery, readQuery, onServer);
37
+ }
38
+ //# sourceMappingURL=use-reduced-motion-web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-reduced-motion-web.js","sourceRoot":"","sources":["../src/use-reduced-motion-web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAEtD,MAAM,oBAAoB,GAAG,kCAAkC,CAAC;AAOhE,8FAA8F;AAC9F,MAAM,UAAU,kBAAkB;IAChC,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,SAAS,gBAAgB,CAAC,QAAoB;IAC5C,MAAM,KAAK,GAAG,kBAAkB,EAAE,CAAC;IACnC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC;IACzB,CAAC;IACD,KAAK,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC3C,OAAO,GAAG,EAAE;QACV,KAAK,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAChD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB;IACzB,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC;AACzB,CAAC;AAED,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,kBAAkB,EAAE,EAAE,OAAO,IAAI,KAAK,CAAC;AAC/D,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;AAC5B,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC;AAE7B;;;GAGG;AACH,MAAM,UAAU,0BAA0B;IACxC,MAAM,aAAa,GAAG,oBAAoB,CAAC,gBAAgB,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IAClF,MAAM,QAAQ,GAAG,oBAAoB,CAAC,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC9E,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC;AACjF,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,gBAAgB;IAC9B,OAAO,oBAAoB,CAAC,gBAAgB,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AACrE,CAAC"}
@@ -1,7 +1,5 @@
1
- export interface ReducedMotionPreference {
2
- reducedMotion: boolean;
3
- resolved: boolean;
4
- }
1
+ import { type ReducedMotionPreference } from './use-reduced-motion-web.js';
2
+ export type { ReducedMotionPreference };
5
3
  /** Tracks when the reduced-motion preference is ready and follows later changes. */
6
4
  export declare function useReducedMotionPreference(): ReducedMotionPreference;
7
5
  /** Tracks the reduced-motion preference and follows changes during the session. */
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"use-reduced-motion.d.ts","sourceRoot":"","sources":["../src/use-reduced-motion.ts"],"names":[],"mappings":"AAGA,OAAO,EAAsB,KAAK,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE/F,YAAY,EAAE,uBAAuB,EAAE,CAAC;AAExC,oFAAoF;AACpF,wBAAgB,0BAA0B,IAAI,uBAAuB,CA+CpE;AAED,mFAAmF;AACnF,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C"}
@@ -1,23 +1,18 @@
1
1
  import { useEffect, useState } from 'react';
2
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
- }
3
+ import { reducedMotionQuery } from './use-reduced-motion-web.js';
9
4
  /** Tracks when the reduced-motion preference is ready and follows later changes. */
10
5
  export function useReducedMotionPreference() {
11
6
  const [preference, setPreference] = useState(() => {
12
7
  const web = Platform.OS === 'web';
13
8
  return {
14
- reducedMotion: web && (mediaQuery()?.matches ?? false),
9
+ reducedMotion: web && (reducedMotionQuery()?.matches ?? false),
15
10
  resolved: web,
16
11
  };
17
12
  });
18
13
  useEffect(() => {
19
14
  if (Platform.OS === 'web') {
20
- const query = mediaQuery();
15
+ const query = reducedMotionQuery();
21
16
  if (!query)
22
17
  return;
23
18
  const onChange = (event) => {
@@ -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;AAOhE,SAAS,UAAU;IACjB,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU;QAC7E,CAAC,CAAC,MAAM,CAA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AO,EAAE,EAAE;YACzF,IAAI,CAAC,OAAO;gBAAE,OAAO;YACrB,iBAAiB,GAAG,IAAI,CAAC;YACzB,aAAa,CAAC,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5D,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,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
@@ -8,6 +8,7 @@ export * from './dom-boundary.js';
8
8
  export * from './route-focus.js';
9
9
  export * from './use-focus-trap.js';
10
10
  export * from './use-inert.js';
11
+ export { useReducedMotion, useReducedMotionPreference, type ReducedMotionPreference, } from './use-reduced-motion-web.js';
11
12
  export * from './use-roving-menu.js';
12
13
  export * from './use-single-flight.js';
13
14
  //# sourceMappingURL=web.d.ts.map
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,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,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,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,KAAK,uBAAuB,GAC7B,MAAM,6BAA6B,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC"}
package/dist/web.js CHANGED
@@ -8,6 +8,7 @@ export * from './dom-boundary.js';
8
8
  export * from './route-focus.js';
9
9
  export * from './use-focus-trap.js';
10
10
  export * from './use-inert.js';
11
+ export { useReducedMotion, useReducedMotionPreference, } from './use-reduced-motion-web.js';
11
12
  export * from './use-roving-menu.js';
12
13
  export * from './use-single-flight.js';
13
14
  //# sourceMappingURL=web.js.map
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,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,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,OAAO,EACL,gBAAgB,EAChB,0BAA0B,GAE3B,MAAM,6BAA6B,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baukit/a11y-core",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
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",