@contractspec/lib.accessibility 3.7.16 → 3.7.17

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.
@@ -1,362 +1 @@
1
- // src/preferences.tsx
2
- import React from "react";
3
- import { jsxDEV } from "react/jsx-dev-runtime";
4
- "use client";
5
- var DEFAULT_PREFERENCES = {
6
- textSize: "m",
7
- textSpacing: "normal",
8
- lineHeight: "normal",
9
- underlineLinks: false,
10
- focusRing: "normal",
11
- reduceMotion: "system",
12
- highContrast: false,
13
- dyslexiaFont: false
14
- };
15
- var STORAGE_KEY = "a11y:preferences:v1";
16
- function getStoredPreferences() {
17
- try {
18
- const raw = typeof window !== "undefined" ? window.localStorage.getItem(STORAGE_KEY) : null;
19
- if (!raw)
20
- return null;
21
- const parsed = JSON.parse(raw);
22
- return { ...DEFAULT_PREFERENCES, ...parsed };
23
- } catch {
24
- return null;
25
- }
26
- }
27
- function savePreferences(prefs) {
28
- try {
29
- if (typeof window !== "undefined") {
30
- window.localStorage.setItem(STORAGE_KEY, JSON.stringify(prefs));
31
- }
32
- } catch {}
33
- }
34
- function applyCssVariables(prefs) {
35
- if (typeof document === "undefined")
36
- return;
37
- const root = document.documentElement;
38
- const body = document.body;
39
- const sizeMap = {
40
- s: "0.95",
41
- m: "1",
42
- l: "1.1",
43
- xl: "1.25"
44
- };
45
- root.style.setProperty("--a11y-text-scale", sizeMap[prefs.textSize]);
46
- const targetMin = prefs.textSize === "l" || prefs.textSize === "xl" ? "44px" : "0px";
47
- root.style.setProperty("--a11y-target-min", targetMin);
48
- root.style.setProperty("--a11y-letter-spacing", prefs.textSpacing === "increased" ? "0.12em" : "normal");
49
- root.style.setProperty("--a11y-word-spacing", prefs.textSpacing === "increased" ? "0.16em" : "normal");
50
- root.style.setProperty("--a11y-line-height", prefs.lineHeight === "increased" ? "1.6" : "1.5");
51
- root.style.setProperty("--a11y-underline-links", prefs.underlineLinks ? "underline" : "revert");
52
- root.style.setProperty("--a11y-focus-ring-width", prefs.focusRing === "thick" ? "4px" : "2px");
53
- root.style.setProperty("--a11y-reduce-motion", prefs.reduceMotion);
54
- root.style.setProperty("--a11y-contrast-mode", prefs.highContrast ? "high" : "normal");
55
- if (prefs.highContrast) {
56
- root.setAttribute("data-contrast", "high");
57
- } else {
58
- root.removeAttribute("data-contrast");
59
- }
60
- root.style.setProperty("--a11y-font-family-alt-enabled", prefs.dyslexiaFont ? "1" : "0");
61
- if (body) {
62
- if (prefs.textSpacing === "increased") {
63
- body.style.letterSpacing = "0.12em";
64
- body.style.wordSpacing = "0.16em";
65
- } else {
66
- body.style.letterSpacing = "";
67
- body.style.wordSpacing = "";
68
- }
69
- body.style.lineHeight = prefs.lineHeight === "increased" ? "1.6" : "";
70
- }
71
- }
72
- var PreferencesContext = React.createContext(null);
73
- function useA11YPreferences() {
74
- const ctx = React.useContext(PreferencesContext);
75
- if (!ctx)
76
- throw new Error("useA11YPreferences must be used within A11YPreferencesProvider");
77
- return ctx;
78
- }
79
- function A11YPreferencesProvider({
80
- children
81
- }) {
82
- const [preferences, setPreferencesState] = React.useState(DEFAULT_PREFERENCES);
83
- const [hydrated, setHydrated] = React.useState(false);
84
- React.useEffect(() => {
85
- const stored = getStoredPreferences();
86
- const next = stored ?? DEFAULT_PREFERENCES;
87
- setPreferencesState(next);
88
- setHydrated(true);
89
- applyCssVariables(next);
90
- }, []);
91
- const setPreferences = React.useCallback((updater) => {
92
- setPreferencesState((prev) => {
93
- const next = typeof updater === "function" ? updater(prev) : { ...prev, ...updater };
94
- savePreferences(next);
95
- applyCssVariables(next);
96
- try {
97
- if (typeof window !== "undefined") {
98
- const changed = {};
99
- for (const key of Object.keys(next)) {
100
- if (next[key] !== prev[key]) {
101
- changed[key] = next[key];
102
- }
103
- }
104
- window.dispatchEvent(new CustomEvent("a11y:pref_changed", {
105
- detail: {
106
- previous: prev,
107
- current: next,
108
- changed
109
- }
110
- }));
111
- }
112
- } catch {}
113
- return next;
114
- });
115
- }, []);
116
- const value = React.useMemo(() => ({ preferences, setPreferences }), [preferences, setPreferences]);
117
- return /* @__PURE__ */ jsxDEV(PreferencesContext, {
118
- value,
119
- children: [
120
- children,
121
- !hydrated ? null : null
122
- ]
123
- }, undefined, true, undefined, this);
124
- }
125
- function a11yRootClassName() {
126
- return "a11y-root";
127
- }
128
-
129
- // src/AccessibilityPanel.tsx
130
- import { Button } from "@contractspec/lib.design-system";
131
- import {
132
- Dialog,
133
- DialogClose,
134
- DialogContent,
135
- DialogOverlay,
136
- DialogPortal,
137
- DialogTitle,
138
- DialogTrigger
139
- } from "@contractspec/lib.ui-kit-web/ui/dialog";
140
- import { Label } from "@contractspec/lib.ui-kit-web/ui/label";
141
- import {
142
- Select,
143
- SelectContent,
144
- SelectItem,
145
- SelectTrigger,
146
- SelectValue
147
- } from "@contractspec/lib.ui-kit-web/ui/select";
148
- import { Switch } from "@contractspec/lib.ui-kit-web/ui/switch";
149
- import { cn } from "@contractspec/lib.ui-kit-web/ui/utils";
150
- import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
151
- "use client";
152
- function AccessibilityPanel({ className }) {
153
- const { preferences, setPreferences } = useA11YPreferences();
154
- return /* @__PURE__ */ jsxDEV2(Dialog, {
155
- children: [
156
- /* @__PURE__ */ jsxDEV2(DialogTrigger, {
157
- asChild: true,
158
- children: /* @__PURE__ */ jsxDEV2(Button, {
159
- variant: "outline",
160
- "aria-haspopup": "dialog",
161
- children: "Accessibility"
162
- }, undefined, false, undefined, this)
163
- }, undefined, false, undefined, this),
164
- /* @__PURE__ */ jsxDEV2(DialogPortal, {
165
- children: [
166
- /* @__PURE__ */ jsxDEV2(DialogOverlay, {
167
- className: "fixed inset-0 z-50 bg-black/40"
168
- }, undefined, false, undefined, this),
169
- /* @__PURE__ */ jsxDEV2(DialogContent, {
170
- className: cn("max-w-md bg-background p-6 shadow-lg outline-hidden focus-visible:ring-2 focus-visible:ring-ring", className),
171
- "aria-describedby": "a11y-panel-desc",
172
- children: [
173
- /* @__PURE__ */ jsxDEV2(DialogTitle, {
174
- className: "font-semibold text-lg",
175
- children: "Accessibility settings"
176
- }, undefined, false, undefined, this),
177
- /* @__PURE__ */ jsxDEV2("p", {
178
- id: "a11y-panel-desc",
179
- className: "text-muted-foreground text-sm",
180
- children: "Adjust text size, spacing, focus and motion to suit your needs."
181
- }, undefined, false, undefined, this),
182
- /* @__PURE__ */ jsxDEV2("div", {
183
- className: "mt-6 space-y-6",
184
- children: [
185
- /* @__PURE__ */ jsxDEV2("div", {
186
- className: "space-y-2",
187
- children: [
188
- /* @__PURE__ */ jsxDEV2(Label, {
189
- children: "Text size"
190
- }, undefined, false, undefined, this),
191
- /* @__PURE__ */ jsxDEV2(Select, {
192
- value: preferences.textSize,
193
- onValueChange: (v) => setPreferences({ textSize: v }),
194
- children: [
195
- /* @__PURE__ */ jsxDEV2(SelectTrigger, {
196
- "aria-label": "Text size",
197
- children: /* @__PURE__ */ jsxDEV2(SelectValue, {}, undefined, false, undefined, this)
198
- }, undefined, false, undefined, this),
199
- /* @__PURE__ */ jsxDEV2(SelectContent, {
200
- children: [
201
- /* @__PURE__ */ jsxDEV2(SelectItem, {
202
- value: "s",
203
- children: "Small"
204
- }, undefined, false, undefined, this),
205
- /* @__PURE__ */ jsxDEV2(SelectItem, {
206
- value: "m",
207
- children: "Medium"
208
- }, undefined, false, undefined, this),
209
- /* @__PURE__ */ jsxDEV2(SelectItem, {
210
- value: "l",
211
- children: "Large"
212
- }, undefined, false, undefined, this),
213
- /* @__PURE__ */ jsxDEV2(SelectItem, {
214
- value: "xl",
215
- children: "Extra Large"
216
- }, undefined, false, undefined, this)
217
- ]
218
- }, undefined, true, undefined, this)
219
- ]
220
- }, undefined, true, undefined, this)
221
- ]
222
- }, undefined, true, undefined, this),
223
- /* @__PURE__ */ jsxDEV2("div", {
224
- className: "flex items-center justify-between",
225
- children: [
226
- /* @__PURE__ */ jsxDEV2(Label, {
227
- htmlFor: "text-spacing",
228
- children: "Increase text spacing (WCAG 1.4.12)"
229
- }, undefined, false, undefined, this),
230
- /* @__PURE__ */ jsxDEV2(Switch, {
231
- id: "text-spacing",
232
- checked: preferences.textSpacing === "increased",
233
- onCheckedChange: (c) => setPreferences({ textSpacing: c ? "increased" : "normal" })
234
- }, undefined, false, undefined, this)
235
- ]
236
- }, undefined, true, undefined, this),
237
- /* @__PURE__ */ jsxDEV2("div", {
238
- className: "flex items-center justify-between",
239
- children: [
240
- /* @__PURE__ */ jsxDEV2(Label, {
241
- htmlFor: "line-height",
242
- children: "Increase line height"
243
- }, undefined, false, undefined, this),
244
- /* @__PURE__ */ jsxDEV2(Switch, {
245
- id: "line-height",
246
- checked: preferences.lineHeight === "increased",
247
- onCheckedChange: (c) => setPreferences({ lineHeight: c ? "increased" : "normal" })
248
- }, undefined, false, undefined, this)
249
- ]
250
- }, undefined, true, undefined, this),
251
- /* @__PURE__ */ jsxDEV2("div", {
252
- className: "flex items-center justify-between",
253
- children: [
254
- /* @__PURE__ */ jsxDEV2(Label, {
255
- htmlFor: "underline-links",
256
- children: "Always underline links"
257
- }, undefined, false, undefined, this),
258
- /* @__PURE__ */ jsxDEV2(Switch, {
259
- id: "underline-links",
260
- checked: preferences.underlineLinks,
261
- onCheckedChange: (c) => setPreferences({ underlineLinks: c })
262
- }, undefined, false, undefined, this)
263
- ]
264
- }, undefined, true, undefined, this),
265
- /* @__PURE__ */ jsxDEV2("div", {
266
- className: "flex items-center justify-between",
267
- children: [
268
- /* @__PURE__ */ jsxDEV2(Label, {
269
- htmlFor: "focus-ring",
270
- children: "Thick focus ring"
271
- }, undefined, false, undefined, this),
272
- /* @__PURE__ */ jsxDEV2(Switch, {
273
- id: "focus-ring",
274
- checked: preferences.focusRing === "thick",
275
- onCheckedChange: (c) => setPreferences({ focusRing: c ? "thick" : "normal" })
276
- }, undefined, false, undefined, this)
277
- ]
278
- }, undefined, true, undefined, this),
279
- /* @__PURE__ */ jsxDEV2("div", {
280
- className: "space-y-2",
281
- children: [
282
- /* @__PURE__ */ jsxDEV2(Label, {
283
- children: "Motion"
284
- }, undefined, false, undefined, this),
285
- /* @__PURE__ */ jsxDEV2(Select, {
286
- value: preferences.reduceMotion,
287
- onValueChange: (v) => setPreferences({ reduceMotion: v }),
288
- children: [
289
- /* @__PURE__ */ jsxDEV2(SelectTrigger, {
290
- "aria-label": "Motion preferences",
291
- children: /* @__PURE__ */ jsxDEV2(SelectValue, {}, undefined, false, undefined, this)
292
- }, undefined, false, undefined, this),
293
- /* @__PURE__ */ jsxDEV2(SelectContent, {
294
- children: [
295
- /* @__PURE__ */ jsxDEV2(SelectItem, {
296
- value: "system",
297
- children: "Follow system"
298
- }, undefined, false, undefined, this),
299
- /* @__PURE__ */ jsxDEV2(SelectItem, {
300
- value: "reduce",
301
- children: "Reduce motion"
302
- }, undefined, false, undefined, this),
303
- /* @__PURE__ */ jsxDEV2(SelectItem, {
304
- value: "no-preference",
305
- children: "Allow motion"
306
- }, undefined, false, undefined, this)
307
- ]
308
- }, undefined, true, undefined, this)
309
- ]
310
- }, undefined, true, undefined, this)
311
- ]
312
- }, undefined, true, undefined, this),
313
- /* @__PURE__ */ jsxDEV2("div", {
314
- className: "flex items-center justify-between",
315
- children: [
316
- /* @__PURE__ */ jsxDEV2(Label, {
317
- htmlFor: "contrast",
318
- children: "High contrast"
319
- }, undefined, false, undefined, this),
320
- /* @__PURE__ */ jsxDEV2(Switch, {
321
- id: "contrast",
322
- checked: preferences.highContrast,
323
- onCheckedChange: (c) => setPreferences({ highContrast: c })
324
- }, undefined, false, undefined, this)
325
- ]
326
- }, undefined, true, undefined, this),
327
- /* @__PURE__ */ jsxDEV2("div", {
328
- className: "flex items-center justify-between",
329
- children: [
330
- /* @__PURE__ */ jsxDEV2(Label, {
331
- htmlFor: "dyslexia-font",
332
- children: "Dyslexia-friendly font"
333
- }, undefined, false, undefined, this),
334
- /* @__PURE__ */ jsxDEV2(Switch, {
335
- id: "dyslexia-font",
336
- checked: preferences.dyslexiaFont,
337
- onCheckedChange: (c) => setPreferences({ dyslexiaFont: c })
338
- }, undefined, false, undefined, this)
339
- ]
340
- }, undefined, true, undefined, this)
341
- ]
342
- }, undefined, true, undefined, this),
343
- /* @__PURE__ */ jsxDEV2("div", {
344
- className: "mt-8 flex justify-end gap-2",
345
- children: /* @__PURE__ */ jsxDEV2(DialogClose, {
346
- asChild: true,
347
- children: /* @__PURE__ */ jsxDEV2(Button, {
348
- variant: "secondary",
349
- children: "Close"
350
- }, undefined, false, undefined, this)
351
- }, undefined, false, undefined, this)
352
- }, undefined, false, undefined, this)
353
- ]
354
- }, undefined, true, undefined, this)
355
- ]
356
- }, undefined, true, undefined, this)
357
- ]
358
- }, undefined, true, undefined, this);
359
- }
360
- export {
361
- AccessibilityPanel
362
- };
1
+ import G from"react";import{jsxs as v}from"react/jsx-runtime";var Y={textSize:"m",textSpacing:"normal",lineHeight:"normal",underlineLinks:!1,focusRing:"normal",reduceMotion:"system",highContrast:!1,dyslexiaFont:!1},A="a11y:preferences:v1";function h(){try{let J=typeof window<"u"?window.localStorage.getItem(A):null;if(!J)return null;let Q=JSON.parse(J);return{...Y,...Q}}catch{return null}}function m(J){try{if(typeof window<"u")window.localStorage.setItem(A,JSON.stringify(J))}catch{}}function k(J){if(typeof document>"u")return;let{documentElement:Q,body:X}=document,W={s:"0.95",m:"1",l:"1.1",xl:"1.25"};Q.style.setProperty("--a11y-text-scale",W[J.textSize]);let U=J.textSize==="l"||J.textSize==="xl"?"44px":"0px";if(Q.style.setProperty("--a11y-target-min",U),Q.style.setProperty("--a11y-letter-spacing",J.textSpacing==="increased"?"0.12em":"normal"),Q.style.setProperty("--a11y-word-spacing",J.textSpacing==="increased"?"0.16em":"normal"),Q.style.setProperty("--a11y-line-height",J.lineHeight==="increased"?"1.6":"1.5"),Q.style.setProperty("--a11y-underline-links",J.underlineLinks?"underline":"revert"),Q.style.setProperty("--a11y-focus-ring-width",J.focusRing==="thick"?"4px":"2px"),Q.style.setProperty("--a11y-reduce-motion",J.reduceMotion),Q.style.setProperty("--a11y-contrast-mode",J.highContrast?"high":"normal"),J.highContrast)Q.setAttribute("data-contrast","high");else Q.removeAttribute("data-contrast");if(Q.style.setProperty("--a11y-font-family-alt-enabled",J.dyslexiaFont?"1":"0"),X){if(J.textSpacing==="increased")X.style.letterSpacing="0.12em",X.style.wordSpacing="0.16em";else X.style.letterSpacing="",X.style.wordSpacing="";X.style.lineHeight=J.lineHeight==="increased"?"1.6":""}}var F=G.createContext(null);function N(){let J=G.useContext(F);if(!J)throw Error("useA11YPreferences must be used within A11YPreferencesProvider");return J}function i({children:J}){let[Q,X]=G.useState(Y),[W,U]=G.useState(!1);G.useEffect(()=>{let z=h()??Y;X(z),U(!0),k(z)},[]);let V=G.useCallback((M)=>{X((z)=>{let B=typeof M==="function"?M(z):{...z,...M};m(B),k(B);try{if(typeof window<"u"){let _={};for(let O of Object.keys(B))if(B[O]!==z[O])_[O]=B[O];window.dispatchEvent(new CustomEvent("a11y:pref_changed",{detail:{previous:z,current:B,changed:_}}))}}catch{}return B})},[]),L=G.useMemo(()=>({preferences:Q,setPreferences:V}),[Q,V]);return v(F,{value:L,children:[J,!W?null:null]})}function l(){return"a11y-root"}import{Button as I}from"@contractspec/lib.design-system";import{Dialog as y,DialogClose as R,DialogContent as g,DialogOverlay as b,DialogPortal as u,DialogTitle as E,DialogTrigger as P}from"@contractspec/lib.ui-kit-web/ui/dialog";import{Label as $}from"@contractspec/lib.ui-kit-web/ui/label";import{Select as w,SelectContent as T,SelectItem as H,SelectTrigger as D,SelectValue as C}from"@contractspec/lib.ui-kit-web/ui/select";import{Switch as K}from"@contractspec/lib.ui-kit-web/ui/switch";import{cn as d}from"@contractspec/lib.ui-kit-web/ui/utils";import{jsx as q,jsxs as Z}from"react/jsx-runtime";function r({className:J}){let{preferences:Q,setPreferences:X}=N();return Z(y,{children:[q(P,{asChild:!0,children:q(I,{variant:"outline","aria-haspopup":"dialog",children:"Accessibility"})}),Z(u,{children:[q(b,{className:"fixed inset-0 z-50 bg-black/40"}),Z(g,{className:d("max-w-md bg-background p-6 shadow-lg outline-hidden focus-visible:ring-2 focus-visible:ring-ring",J),"aria-describedby":"a11y-panel-desc",children:[q(E,{className:"font-semibold text-lg",children:"Accessibility settings"}),q("p",{id:"a11y-panel-desc",className:"text-muted-foreground text-sm",children:"Adjust text size, spacing, focus and motion to suit your needs."}),Z("div",{className:"mt-6 space-y-6",children:[Z("div",{className:"space-y-2",children:[q($,{children:"Text size"}),Z(w,{value:Q.textSize,onValueChange:(W)=>X({textSize:W}),children:[q(D,{"aria-label":"Text size",children:q(C,{})}),Z(T,{children:[q(H,{value:"s",children:"Small"}),q(H,{value:"m",children:"Medium"}),q(H,{value:"l",children:"Large"}),q(H,{value:"xl",children:"Extra Large"})]})]})]}),Z("div",{className:"flex items-center justify-between",children:[q($,{htmlFor:"text-spacing",children:"Increase text spacing (WCAG 1.4.12)"}),q(K,{id:"text-spacing",checked:Q.textSpacing==="increased",onCheckedChange:(W)=>X({textSpacing:W?"increased":"normal"})})]}),Z("div",{className:"flex items-center justify-between",children:[q($,{htmlFor:"line-height",children:"Increase line height"}),q(K,{id:"line-height",checked:Q.lineHeight==="increased",onCheckedChange:(W)=>X({lineHeight:W?"increased":"normal"})})]}),Z("div",{className:"flex items-center justify-between",children:[q($,{htmlFor:"underline-links",children:"Always underline links"}),q(K,{id:"underline-links",checked:Q.underlineLinks,onCheckedChange:(W)=>X({underlineLinks:W})})]}),Z("div",{className:"flex items-center justify-between",children:[q($,{htmlFor:"focus-ring",children:"Thick focus ring"}),q(K,{id:"focus-ring",checked:Q.focusRing==="thick",onCheckedChange:(W)=>X({focusRing:W?"thick":"normal"})})]}),Z("div",{className:"space-y-2",children:[q($,{children:"Motion"}),Z(w,{value:Q.reduceMotion,onValueChange:(W)=>X({reduceMotion:W}),children:[q(D,{"aria-label":"Motion preferences",children:q(C,{})}),Z(T,{children:[q(H,{value:"system",children:"Follow system"}),q(H,{value:"reduce",children:"Reduce motion"}),q(H,{value:"no-preference",children:"Allow motion"})]})]})]}),Z("div",{className:"flex items-center justify-between",children:[q($,{htmlFor:"contrast",children:"High contrast"}),q(K,{id:"contrast",checked:Q.highContrast,onCheckedChange:(W)=>X({highContrast:W})})]}),Z("div",{className:"flex items-center justify-between",children:[q($,{htmlFor:"dyslexia-font",children:"Dyslexia-friendly font"}),q(K,{id:"dyslexia-font",checked:Q.dyslexiaFont,onCheckedChange:(W)=>X({dyslexiaFont:W})})]})]}),q("div",{className:"mt-8 flex justify-end gap-2",children:q(R,{asChild:!0,children:q(I,{variant:"secondary",children:"Close"})})})]})]})]})}export{r as AccessibilityPanel};
@@ -1,173 +1 @@
1
- // src/preferences.tsx
2
- import React from "react";
3
- import { jsxDEV } from "react/jsx-dev-runtime";
4
- "use client";
5
- var DEFAULT_PREFERENCES = {
6
- textSize: "m",
7
- textSpacing: "normal",
8
- lineHeight: "normal",
9
- underlineLinks: false,
10
- focusRing: "normal",
11
- reduceMotion: "system",
12
- highContrast: false,
13
- dyslexiaFont: false
14
- };
15
- var STORAGE_KEY = "a11y:preferences:v1";
16
- function getStoredPreferences() {
17
- try {
18
- const raw = typeof window !== "undefined" ? window.localStorage.getItem(STORAGE_KEY) : null;
19
- if (!raw)
20
- return null;
21
- const parsed = JSON.parse(raw);
22
- return { ...DEFAULT_PREFERENCES, ...parsed };
23
- } catch {
24
- return null;
25
- }
26
- }
27
- function savePreferences(prefs) {
28
- try {
29
- if (typeof window !== "undefined") {
30
- window.localStorage.setItem(STORAGE_KEY, JSON.stringify(prefs));
31
- }
32
- } catch {}
33
- }
34
- function applyCssVariables(prefs) {
35
- if (typeof document === "undefined")
36
- return;
37
- const root = document.documentElement;
38
- const body = document.body;
39
- const sizeMap = {
40
- s: "0.95",
41
- m: "1",
42
- l: "1.1",
43
- xl: "1.25"
44
- };
45
- root.style.setProperty("--a11y-text-scale", sizeMap[prefs.textSize]);
46
- const targetMin = prefs.textSize === "l" || prefs.textSize === "xl" ? "44px" : "0px";
47
- root.style.setProperty("--a11y-target-min", targetMin);
48
- root.style.setProperty("--a11y-letter-spacing", prefs.textSpacing === "increased" ? "0.12em" : "normal");
49
- root.style.setProperty("--a11y-word-spacing", prefs.textSpacing === "increased" ? "0.16em" : "normal");
50
- root.style.setProperty("--a11y-line-height", prefs.lineHeight === "increased" ? "1.6" : "1.5");
51
- root.style.setProperty("--a11y-underline-links", prefs.underlineLinks ? "underline" : "revert");
52
- root.style.setProperty("--a11y-focus-ring-width", prefs.focusRing === "thick" ? "4px" : "2px");
53
- root.style.setProperty("--a11y-reduce-motion", prefs.reduceMotion);
54
- root.style.setProperty("--a11y-contrast-mode", prefs.highContrast ? "high" : "normal");
55
- if (prefs.highContrast) {
56
- root.setAttribute("data-contrast", "high");
57
- } else {
58
- root.removeAttribute("data-contrast");
59
- }
60
- root.style.setProperty("--a11y-font-family-alt-enabled", prefs.dyslexiaFont ? "1" : "0");
61
- if (body) {
62
- if (prefs.textSpacing === "increased") {
63
- body.style.letterSpacing = "0.12em";
64
- body.style.wordSpacing = "0.16em";
65
- } else {
66
- body.style.letterSpacing = "";
67
- body.style.wordSpacing = "";
68
- }
69
- body.style.lineHeight = prefs.lineHeight === "increased" ? "1.6" : "";
70
- }
71
- }
72
- var PreferencesContext = React.createContext(null);
73
- function useA11YPreferences() {
74
- const ctx = React.useContext(PreferencesContext);
75
- if (!ctx)
76
- throw new Error("useA11YPreferences must be used within A11YPreferencesProvider");
77
- return ctx;
78
- }
79
- function A11YPreferencesProvider({
80
- children
81
- }) {
82
- const [preferences, setPreferencesState] = React.useState(DEFAULT_PREFERENCES);
83
- const [hydrated, setHydrated] = React.useState(false);
84
- React.useEffect(() => {
85
- const stored = getStoredPreferences();
86
- const next = stored ?? DEFAULT_PREFERENCES;
87
- setPreferencesState(next);
88
- setHydrated(true);
89
- applyCssVariables(next);
90
- }, []);
91
- const setPreferences = React.useCallback((updater) => {
92
- setPreferencesState((prev) => {
93
- const next = typeof updater === "function" ? updater(prev) : { ...prev, ...updater };
94
- savePreferences(next);
95
- applyCssVariables(next);
96
- try {
97
- if (typeof window !== "undefined") {
98
- const changed = {};
99
- for (const key of Object.keys(next)) {
100
- if (next[key] !== prev[key]) {
101
- changed[key] = next[key];
102
- }
103
- }
104
- window.dispatchEvent(new CustomEvent("a11y:pref_changed", {
105
- detail: {
106
- previous: prev,
107
- current: next,
108
- changed
109
- }
110
- }));
111
- }
112
- } catch {}
113
- return next;
114
- });
115
- }, []);
116
- const value = React.useMemo(() => ({ preferences, setPreferences }), [preferences, setPreferences]);
117
- return /* @__PURE__ */ jsxDEV(PreferencesContext, {
118
- value,
119
- children: [
120
- children,
121
- !hydrated ? null : null
122
- ]
123
- }, undefined, true, undefined, this);
124
- }
125
- function a11yRootClassName() {
126
- return "a11y-root";
127
- }
128
-
129
- // src/next-route-announcer.tsx
130
- import { usePathname } from "next/navigation";
131
- import * as React2 from "react";
132
- import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
133
- "use client";
134
- function NextRouteAnnouncer() {
135
- const pathname = usePathname();
136
- const [message, setMessage] = React2.useState("");
137
- React2.useEffect(() => {
138
- if (typeof document !== "undefined") {
139
- setMessage(document.title || pathname || "");
140
- }
141
- }, [pathname]);
142
- return /* @__PURE__ */ jsxDEV2("div", {
143
- "aria-live": "polite",
144
- "aria-atomic": "true",
145
- className: "sr-only",
146
- children: message
147
- }, undefined, false, undefined, this);
148
- }
149
-
150
- // src/AccessibilityProvider.tsx
151
- import { SRLiveRegionProvider } from "@contractspec/lib.ui-kit-web/ui/live-region";
152
- import { SkipLink } from "@contractspec/lib.ui-kit-web/ui/skip-link";
153
- import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
154
- "use client";
155
- function AccessibilityProvider({
156
- children,
157
- skipTargetId = "main"
158
- }) {
159
- return /* @__PURE__ */ jsxDEV3(A11YPreferencesProvider, {
160
- children: /* @__PURE__ */ jsxDEV3(SRLiveRegionProvider, {
161
- children: [
162
- /* @__PURE__ */ jsxDEV3(SkipLink, {
163
- targetId: skipTargetId
164
- }, undefined, false, undefined, this),
165
- /* @__PURE__ */ jsxDEV3(NextRouteAnnouncer, {}, undefined, false, undefined, this),
166
- children
167
- ]
168
- }, undefined, true, undefined, this)
169
- }, undefined, false, undefined, this);
170
- }
171
- export {
172
- AccessibilityProvider
173
- };
1
+ import X from"react";import{jsxs as F}from"react/jsx-runtime";var I={textSize:"m",textSpacing:"normal",lineHeight:"normal",underlineLinks:!1,focusRing:"normal",reduceMotion:"system",highContrast:!1,dyslexiaFont:!1},M="a11y:preferences:v1";function N(){try{let q=typeof window<"u"?window.localStorage.getItem(M):null;if(!q)return null;let B=JSON.parse(q);return{...I,...B}}catch{return null}}function _(q){try{if(typeof window<"u")window.localStorage.setItem(M,JSON.stringify(q))}catch{}}function D(q){if(typeof document>"u")return;let{documentElement:B,body:J}=document,G={s:"0.95",m:"1",l:"1.1",xl:"1.25"};B.style.setProperty("--a11y-text-scale",G[q.textSize]);let H=q.textSize==="l"||q.textSize==="xl"?"44px":"0px";if(B.style.setProperty("--a11y-target-min",H),B.style.setProperty("--a11y-letter-spacing",q.textSpacing==="increased"?"0.12em":"normal"),B.style.setProperty("--a11y-word-spacing",q.textSpacing==="increased"?"0.16em":"normal"),B.style.setProperty("--a11y-line-height",q.lineHeight==="increased"?"1.6":"1.5"),B.style.setProperty("--a11y-underline-links",q.underlineLinks?"underline":"revert"),B.style.setProperty("--a11y-focus-ring-width",q.focusRing==="thick"?"4px":"2px"),B.style.setProperty("--a11y-reduce-motion",q.reduceMotion),B.style.setProperty("--a11y-contrast-mode",q.highContrast?"high":"normal"),q.highContrast)B.setAttribute("data-contrast","high");else B.removeAttribute("data-contrast");if(B.style.setProperty("--a11y-font-family-alt-enabled",q.dyslexiaFont?"1":"0"),J){if(q.textSpacing==="increased")J.style.letterSpacing="0.12em",J.style.wordSpacing="0.16em";else J.style.letterSpacing="",J.style.wordSpacing="";J.style.lineHeight=q.lineHeight==="increased"?"1.6":""}}var U=X.createContext(null);function g(){let q=X.useContext(U);if(!q)throw Error("useA11YPreferences must be used within A11YPreferencesProvider");return q}function Y({children:q}){let[B,J]=X.useState(I),[G,H]=X.useState(!1);X.useEffect(()=>{let Q=N()??I;J(Q),H(!0),D(Q)},[]);let O=X.useCallback((Z)=>{J((Q)=>{let W=typeof Z==="function"?Z(Q):{...Q,...Z};_(W),D(W);try{if(typeof window<"u"){let V={};for(let $ of Object.keys(W))if(W[$]!==Q[$])V[$]=W[$];window.dispatchEvent(new CustomEvent("a11y:pref_changed",{detail:{previous:Q,current:W,changed:V}}))}}catch{}return W})},[]),L=X.useMemo(()=>({preferences:B,setPreferences:O}),[B,O]);return F(U,{value:L,children:[q,!G?null:null]})}function m(){return"a11y-root"}import{usePathname as A}from"next/navigation";import*as z from"react";import{jsx as C}from"react/jsx-runtime";function w(){let q=A(),[B,J]=z.useState("");return z.useEffect(()=>{if(typeof document<"u")J(document.title||q||"")},[q]),C("div",{"aria-live":"polite","aria-atomic":"true",className:"sr-only",children:B})}import{SRLiveRegionProvider as T}from"@contractspec/lib.ui-kit-web/ui/live-region";import{SkipLink as j}from"@contractspec/lib.ui-kit-web/ui/skip-link";import{jsx as K,jsxs as b}from"react/jsx-runtime";function x({children:q,skipTargetId:B="main"}){return K(Y,{children:b(T,{children:[K(j,{targetId:B}),K(w,{}),q]})})}export{x as AccessibilityProvider};
@@ -1,60 +1 @@
1
- /* src/styles.css */
2
- :root {
3
- --a11y-text-scale: 1;
4
- --a11y-letter-spacing: normal;
5
- --a11y-word-spacing: normal;
6
- --a11y-line-height: 1.5;
7
- --a11y-underline-links: auto;
8
- --a11y-focus-ring-width: 2px;
9
- --a11y-reduce-motion: system;
10
- --a11y-contrast-mode: normal;
11
- --a11y-font-family-alt-enabled: 0;
12
- }
13
-
14
- html, body {
15
- font-size: calc(16px * var(--a11y-text-scale));
16
- }
17
-
18
- body, p, li {
19
- letter-spacing: var(--a11y-letter-spacing);
20
- word-spacing: var(--a11y-word-spacing);
21
- line-height: var(--a11y-line-height);
22
- }
23
-
24
- a {
25
- text-decoration: var(--a11y-underline-links);
26
- }
27
-
28
- :where(button, [role="button"], a, input, select, textarea) {
29
- outline-offset: 2px;
30
- min-height: var(--a11y-target-min, 0);
31
- min-width: var(--a11y-target-min, 0);
32
- }
33
-
34
- :where(:focus-visible) {
35
- outline: var(--a11y-focus-ring-width) solid currentColor;
36
- }
37
-
38
- :root[style*="--a11y-font-family-alt-enabled: 1"] body {
39
- font-family: var(--font-dyslexia, system-ui, sans-serif);
40
- }
41
-
42
- @media (prefers-reduced-motion: reduce) {
43
- :root[style*="--a11y-reduce-motion: system"] * {
44
- animation: none !important;
45
- scroll-behavior: auto !important;
46
- transition: none !important;
47
- }
48
- }
49
-
50
- :root[style*="--a11y-reduce-motion: reduce"] * {
51
- animation: none !important;
52
- scroll-behavior: auto !important;
53
- transition: none !important;
54
- }
55
-
56
- body {
57
- letter-spacing: var(--a11y-letter-spacing, normal);
58
- word-spacing: var(--a11y-word-spacing, normal);
59
- line-height: var(--a11y-line-height, 1.5);
60
- }
1
+ :root{--a11y-text-scale:1;--a11y-letter-spacing:normal;--a11y-word-spacing:normal;--a11y-line-height:1.5;--a11y-underline-links:auto;--a11y-focus-ring-width:2px;--a11y-reduce-motion:system;--a11y-contrast-mode:normal;--a11y-font-family-alt-enabled:0}html,body{font-size:calc(16px*var(--a11y-text-scale))}body,p,li{letter-spacing:var(--a11y-letter-spacing);word-spacing:var(--a11y-word-spacing);line-height:var(--a11y-line-height)}a{text-decoration:var(--a11y-underline-links)}:where(button,[role=button],a,input,select,textarea){outline-offset:2px;min-height:var(--a11y-target-min,0);min-width:var(--a11y-target-min,0)}:where(:focus-visible){outline:var(--a11y-focus-ring-width)solid currentColor}:root[style*="--a11y-font-family-alt-enabled: 1"] body{font-family:var(--font-dyslexia,system-ui,sans-serif)}@media (prefers-reduced-motion:reduce){:root[style*="--a11y-reduce-motion: system"] *{animation:none!important;scroll-behavior:auto!important;transition:none!important}}:root[style*="--a11y-reduce-motion: reduce"] *{animation:none!important;scroll-behavior:auto!important;transition:none!important}body{letter-spacing:var(--a11y-letter-spacing,normal);word-spacing:var(--a11y-word-spacing,normal);line-height:var(--a11y-line-height,1.5)}
@@ -1,14 +1 @@
1
- export {
2
- useSRLiveRegion,
3
- useReducedMotion,
4
- useA11YPreferences,
5
- VisuallyHidden,
6
- SkipLink,
7
- SRLiveRegionProvider,
8
- RouteAnnouncer,
9
- NextRouteAnnouncer,
10
- FocusOnRouteChange,
11
- AccessibilityProvider,
12
- AccessibilityPanel,
13
- A11YPreferencesProvider
14
- };
1
+ export{B as useSRLiveRegion,H as useReducedMotion,M as useA11YPreferences,J as VisuallyHidden,F as SkipLink,z as SRLiveRegionProvider,D as RouteAnnouncer,T as NextRouteAnnouncer,m as FocusOnRouteChange,R as AccessibilityProvider,O as AccessibilityPanel,L as A11YPreferencesProvider};
@@ -1,23 +1 @@
1
- // src/next-route-announcer.tsx
2
- import { usePathname } from "next/navigation";
3
- import * as React from "react";
4
- import { jsxDEV } from "react/jsx-dev-runtime";
5
- "use client";
6
- function NextRouteAnnouncer() {
7
- const pathname = usePathname();
8
- const [message, setMessage] = React.useState("");
9
- React.useEffect(() => {
10
- if (typeof document !== "undefined") {
11
- setMessage(document.title || pathname || "");
12
- }
13
- }, [pathname]);
14
- return /* @__PURE__ */ jsxDEV("div", {
15
- "aria-live": "polite",
16
- "aria-atomic": "true",
17
- className: "sr-only",
18
- children: message
19
- }, undefined, false, undefined, this);
20
- }
21
- export {
22
- NextRouteAnnouncer
23
- };
1
+ import{usePathname as y}from"next/navigation";import*as b from"react";import{jsx as z}from"react/jsx-runtime";function B(){let f=y(),[k,q]=b.useState("");return b.useEffect(()=>{if(typeof document<"u")q(document.title||f||"")},[f]),z("div",{"aria-live":"polite","aria-atomic":"true",className:"sr-only",children:k})}export{B as NextRouteAnnouncer};