@zerolith/a11y 0.0.0-stage → 0.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +33 -2
- package/dist/announce.d.ts +26 -0
- package/dist/announce.d.ts.map +1 -0
- package/dist/announce.js +58 -0
- package/dist/announce.js.map +1 -0
- package/dist/focus.d.ts +58 -0
- package/dist/focus.d.ts.map +1 -0
- package/dist/focus.js +240 -0
- package/dist/focus.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/media.d.ts +12 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +32 -0
- package/dist/media.js.map +1 -0
- package/dist/production/announce.js +4 -0
- package/dist/production/announce.js.map +1 -0
- package/dist/production/focus.js +2 -0
- package/dist/production/focus.js.map +1 -0
- package/dist/production/index.js +2 -0
- package/dist/production/index.js.map +1 -0
- package/dist/production/media.js +2 -0
- package/dist/production/media.js.map +1 -0
- package/package.json +50 -5
- package/src/announce.ts +79 -0
- package/src/focus.ts +331 -0
- package/src/index.ts +11 -0
- package/src/media.ts +41 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zerolith/a11y: the accessibility primitives every component library
|
|
3
|
+
* rebuilds, as functions over the DOM. The public surface is assembled here.
|
|
4
|
+
*/
|
|
5
|
+
export type { FocusOrigin, FocusOriginMonitor, FocusTrapOptions, RovingOptions } from "./focus.js";
|
|
6
|
+
export { focusOrigin, focusTrap, focusables, rovingTabindex } from "./focus.js";
|
|
7
|
+
|
|
8
|
+
export type { Announcer, Politeness } from "./announce.js";
|
|
9
|
+
export { createAnnouncer, visuallyHidden } from "./announce.js";
|
|
10
|
+
|
|
11
|
+
export { forcedColors, mediaQuery, reducedMotion } from "./media.js";
|
package/src/media.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Media queries as signals, for the preferences a component should follow:
|
|
3
|
+
* forced colors and reduced motion first.
|
|
4
|
+
*/
|
|
5
|
+
import { type ReadableSignal, signal } from "zerolith";
|
|
6
|
+
|
|
7
|
+
const queries = new Map<string, ReadableSignal<boolean>>();
|
|
8
|
+
|
|
9
|
+
/** A media query as a signal that follows the query's matches; false wherever `matchMedia` does not exist, such as on the server. */
|
|
10
|
+
export function mediaQuery(query: string): ReadableSignal<boolean>
|
|
11
|
+
{
|
|
12
|
+
let existing = queries.get(query);
|
|
13
|
+
if (existing === undefined)
|
|
14
|
+
{
|
|
15
|
+
if (typeof matchMedia === "undefined")
|
|
16
|
+
{
|
|
17
|
+
existing = signal(false);
|
|
18
|
+
}
|
|
19
|
+
else
|
|
20
|
+
{
|
|
21
|
+
const list = matchMedia(query);
|
|
22
|
+
const matches = signal(list.matches);
|
|
23
|
+
list.addEventListener("change", (event) => matches.set(event.matches));
|
|
24
|
+
existing = matches;
|
|
25
|
+
}
|
|
26
|
+
queries.set(query, existing);
|
|
27
|
+
}
|
|
28
|
+
return existing;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** True while the user agent is in forced colors mode, such as Windows high contrast, where author colors are replaced by system ones. */
|
|
32
|
+
export function forcedColors(): ReadableSignal<boolean>
|
|
33
|
+
{
|
|
34
|
+
return mediaQuery("(forced-colors: active)");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** True while the user has asked for reduced motion. */
|
|
38
|
+
export function reducedMotion(): ReadableSignal<boolean>
|
|
39
|
+
{
|
|
40
|
+
return mediaQuery("(prefers-reduced-motion: reduce)");
|
|
41
|
+
}
|