@baukit/a11y-core 0.5.0 → 0.5.2

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
@@ -10,9 +10,9 @@ product's Expo SDK decides the versions, and React Native is optional.
10
10
  ## Two entry points
11
11
 
12
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
- `useRovingMenu`, `nextEnabledMenuIndex`, `useSingleFlight`, `createRouteFocusController`, and the
15
- `dom-boundary` helpers. Nothing reachable
13
+ `@baukit/a11y-core/web` and gets `announce`, `useFocusTrap`, `useInert`, `useAriaHiddenInert`,
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.
@@ -20,8 +20,9 @@ reason.
20
20
  The DOM hooks ask whether a document exists rather than asking `Platform` which OS this is. The
21
21
  two questions have the same answer here: every branch those hooks guard reads or writes the DOM,
22
22
  React Native Web gives them a real document, and React Native has none. Hooks with a genuine
23
- platform split, such as `announce` and `useOverlayA11y`, keep reading `Platform` and stay behind
24
- the root entry.
23
+ platform split, such as `useOverlayA11y`, keep reading `Platform` and stay behind the root entry.
24
+ `announce` and `useReducedMotion` exist on both entries: the root version reads `Platform`, and the
25
+ `/web` version is its DOM half.
25
26
 
26
27
  ## Overlays
27
28
 
@@ -172,6 +173,12 @@ forcing a reflow first so the same message twice is spoken twice. Blank messages
172
173
  The region's DOM id defaults to `baukit-announcer`. Pass `liveRegionId` to place it under a
173
174
  product-owned id, and `assertive: true` to interrupt rather than wait for a pause.
174
175
 
176
+ `announce` from `@baukit/a11y-core/web` takes the same arguments and is the web half alone, so a
177
+ plain React app gets the live region without React Native. It creates the region on the first
178
+ call, or adopts an element the product already rendered under that id, and needs no component or
179
+ provider. Filtering which messages deserve speech stays in the product: call `announce` only for
180
+ the ones that do.
181
+
175
182
  ## Reduced motion, groups, and forms
176
183
 
177
184
  `useReducedMotionPreference` returns `{ reducedMotion, resolved }` and follows preference changes
@@ -180,6 +187,12 @@ on both platforms. Web resolves during the first render. The native query is asy
180
187
  non-essential motion until it is `true`. `useReducedMotion` remains the boolean form for existing
181
188
  callers.
182
189
 
190
+ The web entry exports both hooks with the same names and return shapes, built on `matchMedia` and
191
+ `useSyncExternalStore` alone. They read the media query during the first client render and follow
192
+ its `change` events. During server rendering and the hydration render they report
193
+ `{ reducedMotion: false, resolved: false }`, then resolve on the client. A host without
194
+ `matchMedia` reports no preference, resolved.
195
+
183
196
  `useRovingRadioGroup` gives a radio group a single tab stop and arrow-key movement between its
184
197
  options, wrapping at both ends and honoring Home and End. `radioProps(index)` returns the
185
198
  `tabIndex`, `ref`, and `onKeyDown` for one option.
@@ -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 through a visually hidden ARIA live region. */
10
+ export declare function announce(message: string, { assertive, liveRegionId }?: AnnounceOptions): void;
11
+ //# sourceMappingURL=announce-web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"announce-web.d.ts","sourceRoot":"","sources":["../src/announce-web.ts"],"names":[],"mappings":"AAAA,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,uEAAuE;AACvE,wBAAgB,QAAQ,CACtB,OAAO,EAAE,MAAM,EACf,EAAE,SAAiB,EAAE,YAAqC,EAAE,GAAE,eAAoB,GACjF,IAAI,CASN"}
@@ -0,0 +1,32 @@
1
+ /** Default DOM id of the shared web live region. Override it per product. */
2
+ export const DEFAULT_LIVE_REGION_ID = 'baukit-announcer';
3
+ 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;';
4
+ function liveRegion(assertive, liveRegionId) {
5
+ if (typeof document === 'undefined')
6
+ return null;
7
+ let region = document.getElementById(liveRegionId);
8
+ if (!region) {
9
+ region = document.createElement('div');
10
+ region.id = liveRegionId;
11
+ region.style.cssText = VISUALLY_HIDDEN;
12
+ document.body.appendChild(region);
13
+ }
14
+ region.setAttribute('aria-atomic', 'true');
15
+ region.setAttribute('aria-live', assertive ? 'assertive' : 'polite');
16
+ region.setAttribute('role', assertive ? 'alert' : 'status');
17
+ return region;
18
+ }
19
+ /** Announces an outcome through a visually hidden ARIA live region. */
20
+ export function announce(message, { assertive = false, liveRegionId = DEFAULT_LIVE_REGION_ID } = {}) {
21
+ const trimmed = message.trim();
22
+ if (!trimmed)
23
+ return;
24
+ const region = liveRegion(assertive, liveRegionId);
25
+ if (!region)
26
+ return;
27
+ region.textContent = '';
28
+ // Force a distinct mutation so the same message twice is spoken twice.
29
+ void region.offsetWidth;
30
+ region.textContent = trimmed;
31
+ }
32
+ //# sourceMappingURL=announce-web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"announce-web.js","sourceRoot":"","sources":["../src/announce-web.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AAEzD,MAAM,eAAe,GACnB,8HAA8H,CAAC;AASjI,SAAS,UAAU,CAAC,SAAkB,EAAE,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. */
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
- }
1
+ import { type AnnounceOptions } from './announce-web.js';
2
+ export { DEFAULT_LIVE_REGION_ID, type AnnounceOptions } from './announce-web.js';
9
3
  /** Announces an outcome without requiring a visible live-region component. */
10
- export declare function announce(message: string, { assertive, liveRegionId }?: AnnounceOptions): void;
4
+ export declare function announce(message: string, options?: AnnounceOptions): void;
11
5
  //# sourceMappingURL=announce.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"announce.d.ts","sourceRoot":"","sources":["../src/announce.ts"],"names":[],"mappings":"AAEA,OAAO,EAA6B,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpF,OAAO,EAAE,sBAAsB,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEjF,8EAA8E;AAC9E,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,IAAI,CAQ7E"}
package/dist/announce.js CHANGED
@@ -1,37 +1,15 @@
1
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
- }
2
+ import { announce as announceOnWeb } from './announce-web.js';
3
+ export { DEFAULT_LIVE_REGION_ID } from './announce-web.js';
20
4
  /** 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);
5
+ export function announce(message, options = {}) {
6
+ if (Platform.OS === 'web') {
7
+ announceOnWeb(message, options);
27
8
  return;
28
9
  }
29
- const region = webLiveRegion(assertive, liveRegionId);
30
- if (!region)
10
+ const trimmed = message.trim();
11
+ if (!trimmed)
31
12
  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;
13
+ AccessibilityInfo.announceForAccessibility(trimmed);
36
14
  }
37
15
  //# sourceMappingURL=announce.js.map
@@ -1 +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,sBAA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ACtD,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"}
1
+ {"version":3,"file":"announce.js","sourceRoot":"","sources":["../src/announce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE3D,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAwB,MAAM,mBAAmB,CAAC;AAEpF,OAAO,EAAE,sBAAsB,EAAwB,MAAM,mBAAmB,CAAC;AAEjF,8EAA8E;AAC9E,MAAM,UAAU,QAAQ,CAAC,OAAe,EAAE,UAA2B,EAAE;IACrE,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;QAC1B,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAChC,OAAO;IACT,CAAC;IACD,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/B,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,iBAAiB,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;AACtD,CAAC"}
@@ -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,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,C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E;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
@@ -4,10 +4,12 @@
4
4
  * dependency tree can bundle it. React Native products import the package root
5
5
  * instead and get these exports plus the native ones.
6
6
  */
7
+ export * from './announce-web.js';
7
8
  export * from './dom-boundary.js';
8
9
  export * from './route-focus.js';
9
10
  export * from './use-focus-trap.js';
10
11
  export * from './use-inert.js';
12
+ export { useReducedMotion, useReducedMotionPreference, type ReducedMotionPreference, } from './use-reduced-motion-web.js';
11
13
  export * from './use-roving-menu.js';
12
14
  export * from './use-single-flight.js';
13
15
  //# 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,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
@@ -4,10 +4,12 @@
4
4
  * dependency tree can bundle it. React Native products import the package root
5
5
  * instead and get these exports plus the native ones.
6
6
  */
7
+ export * from './announce-web.js';
7
8
  export * from './dom-boundary.js';
8
9
  export * from './route-focus.js';
9
10
  export * from './use-focus-trap.js';
10
11
  export * from './use-inert.js';
12
+ export { useReducedMotion, useReducedMotionPreference, } from './use-reduced-motion-web.js';
11
13
  export * from './use-roving-menu.js';
12
14
  export * from './use-single-flight.js';
13
15
  //# 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,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.2",
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",