@moon-inferno/core 0.1.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.
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Moon-Inferno Core Design Tokens
3
+ * Framework-independent token definitions for colors, typography, spacing, shadows, and retro visual effects.
4
+ */
5
+ declare const colors: {
6
+ readonly inferno: {
7
+ readonly 50: "#FFF5F0";
8
+ readonly 100: "#FFE6D9";
9
+ readonly 200: "#FFBF9B";
10
+ readonly 300: "#FF975E";
11
+ readonly 400: "#FF7026";
12
+ readonly 500: "#FF4D00";
13
+ readonly 600: "#FF2E00";
14
+ readonly 700: "#CC1F00";
15
+ readonly 800: "#991200";
16
+ readonly 900: "#660900";
17
+ readonly 950: "#3D0300";
18
+ };
19
+ readonly moon: {
20
+ readonly 50: "#F8FAFC";
21
+ readonly 100: "#F1F5F9";
22
+ readonly 200: "#E2E8F0";
23
+ readonly 300: "#CBD5E1";
24
+ readonly 400: "#94A3B8";
25
+ readonly 500: "#64748B";
26
+ readonly 600: "#475569";
27
+ readonly 700: "#334155";
28
+ readonly 800: "#1E293B";
29
+ readonly 900: "#0F172A";
30
+ readonly 950: "#020617";
31
+ };
32
+ readonly obsidian: {
33
+ readonly 900: "#120F16";
34
+ readonly 950: "#0A090D";
35
+ };
36
+ readonly status: {
37
+ readonly success: "#00FF66";
38
+ readonly warning: "#FFCC00";
39
+ readonly error: "#FF0033";
40
+ readonly info: "#00E5FF";
41
+ };
42
+ };
43
+ declare const typography: {
44
+ readonly fontFamily: {
45
+ readonly sans: "system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif";
46
+ readonly mono: "\"JetBrains Mono\", \"Fira Code\", \"Courier New\", Courier, monospace";
47
+ readonly pixel: "\"Press Start 2P\", \"VT323\", \"Courier New\", monospace";
48
+ };
49
+ readonly fontSize: {
50
+ readonly xs: "0.75rem";
51
+ readonly sm: "0.875rem";
52
+ readonly base: "1rem";
53
+ readonly lg: "1.125rem";
54
+ readonly xl: "1.25rem";
55
+ readonly '2xl': "1.5rem";
56
+ readonly '3xl': "1.875rem";
57
+ readonly '4xl': "2.25rem";
58
+ };
59
+ readonly fontWeight: {
60
+ readonly normal: "400";
61
+ readonly medium: "500";
62
+ readonly semibold: "600";
63
+ readonly bold: "700";
64
+ };
65
+ readonly lineHeight: {
66
+ readonly tight: "1.2";
67
+ readonly normal: "1.5";
68
+ readonly relaxed: "1.75";
69
+ };
70
+ };
71
+ declare const spacing: {
72
+ readonly 0: "0px";
73
+ readonly 1: "0.25rem";
74
+ readonly 2: "0.5rem";
75
+ readonly 3: "0.75rem";
76
+ readonly 4: "1rem";
77
+ readonly 5: "1.25rem";
78
+ readonly 6: "1.5rem";
79
+ readonly 8: "2rem";
80
+ readonly 10: "2.5rem";
81
+ readonly 12: "3rem";
82
+ readonly 16: "4rem";
83
+ };
84
+ declare const radii: {
85
+ readonly none: "0px";
86
+ readonly sm: "2px";
87
+ readonly base: "4px";
88
+ readonly md: "6px";
89
+ readonly lg: "8px";
90
+ readonly full: "9999px";
91
+ };
92
+ declare const shadows: {
93
+ readonly none: "none";
94
+ readonly infernoGlow: "0 0 12px rgba(255, 77, 0, 0.4), 0 0 24px rgba(255, 77, 0, 0.15)";
95
+ readonly cyanGlow: "0 0 12px rgba(0, 229, 255, 0.4), 0 0 24px rgba(0, 229, 255, 0.15)";
96
+ readonly pixelShadow: "3px 3px 0px #0A090D";
97
+ readonly retroBox: "4px 4px 0px rgba(0, 0, 0, 0.9), inset -2px -2px 0px rgba(255, 255, 255, 0.1)";
98
+ };
99
+ declare const retroEffects: {
100
+ readonly scanlineOpacity: "0.15";
101
+ readonly crtFlickerSpeed: "0.15s";
102
+ readonly pixelBorderWidth: "2px";
103
+ };
104
+ declare const zIndex: {
105
+ readonly hide: -1;
106
+ readonly auto: "auto";
107
+ readonly base: 0;
108
+ readonly docked: 10;
109
+ readonly dropdown: 1000;
110
+ readonly sticky: 1100;
111
+ readonly banner: 1200;
112
+ readonly overlay: 1300;
113
+ readonly modal: 1400;
114
+ readonly popover: 1500;
115
+ readonly skipLink: 1600;
116
+ readonly toast: 1700;
117
+ readonly tooltip: 1800;
118
+ };
119
+
120
+ /**
121
+ * Generates Moon-Inferno CSS Custom Property key-value pairs.
122
+ */
123
+ declare function getCSSVariableObject(): Record<string, string>;
124
+ /**
125
+ * Converts CSS variable object to string format for CSS rules.
126
+ */
127
+ declare function getCSSVariableString(): string;
128
+
129
+ /**
130
+ * Accessibility Focus Utilities
131
+ * Provides helpers for focus containment (focus traps), focus restoration, and tabbable elements.
132
+ */
133
+ /**
134
+ * Returns all focusable elements within a given container.
135
+ */
136
+ declare function getFocusableElements(container: HTMLElement): HTMLElement[];
137
+ /**
138
+ * Traps focus within a given container element.
139
+ * Useful for modal dialogs, drawers, and overlay menus.
140
+ */
141
+ declare function trapFocus(container: HTMLElement, event: KeyboardEvent): void;
142
+ /**
143
+ * Stores the previously focused element and provides a restoration function.
144
+ */
145
+ declare function createFocusStore(): {
146
+ save(): void;
147
+ restore(): void;
148
+ };
149
+
150
+ /**
151
+ * Reduced Motion Helper
152
+ * Utility to check if user prefers reduced motion.
153
+ */
154
+ /**
155
+ * Returns true if user has enabled prefers-reduced-motion in OS settings.
156
+ */
157
+ declare function isReducedMotionPreferred(): boolean;
158
+ /**
159
+ * Subscribes to changes in reduced motion user preferences.
160
+ */
161
+ declare function onReducedMotionChange(callback: (reduced: boolean) => void): () => void;
162
+
163
+ /**
164
+ * Keyboard Key Constants & Event Helpers
165
+ */
166
+ declare const KEYS: {
167
+ readonly ENTER: "Enter";
168
+ readonly SPACE: " ";
169
+ readonly ESCAPE: "Escape";
170
+ readonly TAB: "Tab";
171
+ readonly ARROW_UP: "ArrowUp";
172
+ readonly ARROW_DOWN: "ArrowDown";
173
+ readonly ARROW_LEFT: "ArrowLeft";
174
+ readonly ARROW_RIGHT: "ArrowRight";
175
+ readonly HOME: "Home";
176
+ readonly END: "End";
177
+ };
178
+ declare function isKey(event: KeyboardEvent, key: keyof typeof KEYS): boolean;
179
+ declare function isActionKey(event: KeyboardEvent): boolean;
180
+
181
+ export { KEYS, colors, createFocusStore, getCSSVariableObject, getCSSVariableString, getFocusableElements, isActionKey, isKey, isReducedMotionPreferred, onReducedMotionChange, radii, retroEffects, shadows, spacing, trapFocus, typography, zIndex };
package/dist/index.js ADDED
@@ -0,0 +1,321 @@
1
+ // src/tokens.ts
2
+ var colors = {
3
+ // Infernal Palette (Solar Fire / Lava / Amber)
4
+ inferno: {
5
+ 50: "#FFF5F0",
6
+ 100: "#FFE6D9",
7
+ 200: "#FFBF9B",
8
+ 300: "#FF975E",
9
+ 400: "#FF7026",
10
+ 500: "#FF4D00",
11
+ // Primary Inferno Orange
12
+ 600: "#FF2E00",
13
+ // Crimson Fire
14
+ 700: "#CC1F00",
15
+ 800: "#991200",
16
+ 900: "#660900",
17
+ 950: "#3D0300"
18
+ },
19
+ // Lunar Palette (Platinum / Silver / Ethereal Cyan)
20
+ moon: {
21
+ 50: "#F8FAFC",
22
+ 100: "#F1F5F9",
23
+ // Primary Text Light
24
+ 200: "#E2E8F0",
25
+ 300: "#CBD5E1",
26
+ 400: "#94A3B8",
27
+ 500: "#64748B",
28
+ 600: "#475569",
29
+ 700: "#334155",
30
+ 800: "#1E293B",
31
+ 900: "#0F172A",
32
+ 950: "#020617"
33
+ },
34
+ // Obsidian Palette (Deep Space / CRT Backlight / Magma Shadow)
35
+ obsidian: {
36
+ 900: "#120F16",
37
+ 950: "#0A090D"
38
+ // Primary Dark Background
39
+ },
40
+ // Retro CRT Status Colors
41
+ status: {
42
+ success: "#00FF66",
43
+ // Neon Terminal Green
44
+ warning: "#FFCC00",
45
+ // Amber Warning
46
+ error: "#FF0033",
47
+ // Cyber Red
48
+ info: "#00E5FF"
49
+ // Neon Cyan
50
+ }
51
+ };
52
+ var typography = {
53
+ fontFamily: {
54
+ sans: 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
55
+ mono: '"JetBrains Mono", "Fira Code", "Courier New", Courier, monospace',
56
+ pixel: '"Press Start 2P", "VT323", "Courier New", monospace'
57
+ },
58
+ fontSize: {
59
+ xs: "0.75rem",
60
+ // 12px
61
+ sm: "0.875rem",
62
+ // 14px
63
+ base: "1rem",
64
+ // 16px
65
+ lg: "1.125rem",
66
+ // 18px
67
+ xl: "1.25rem",
68
+ // 20px
69
+ "2xl": "1.5rem",
70
+ // 24px
71
+ "3xl": "1.875rem",
72
+ // 30px
73
+ "4xl": "2.25rem"
74
+ // 36px
75
+ },
76
+ fontWeight: {
77
+ normal: "400",
78
+ medium: "500",
79
+ semibold: "600",
80
+ bold: "700"
81
+ },
82
+ lineHeight: {
83
+ tight: "1.2",
84
+ normal: "1.5",
85
+ relaxed: "1.75"
86
+ }
87
+ };
88
+ var spacing = {
89
+ 0: "0px",
90
+ 1: "0.25rem",
91
+ // 4px
92
+ 2: "0.5rem",
93
+ // 8px
94
+ 3: "0.75rem",
95
+ // 12px
96
+ 4: "1rem",
97
+ // 16px
98
+ 5: "1.25rem",
99
+ // 20px
100
+ 6: "1.5rem",
101
+ // 24px
102
+ 8: "2rem",
103
+ // 32px
104
+ 10: "2.5rem",
105
+ // 40px
106
+ 12: "3rem",
107
+ // 48px
108
+ 16: "4rem"
109
+ // 64px
110
+ };
111
+ var radii = {
112
+ none: "0px",
113
+ sm: "2px",
114
+ base: "4px",
115
+ md: "6px",
116
+ lg: "8px",
117
+ full: "9999px"
118
+ };
119
+ var shadows = {
120
+ none: "none",
121
+ infernoGlow: "0 0 12px rgba(255, 77, 0, 0.4), 0 0 24px rgba(255, 77, 0, 0.15)",
122
+ cyanGlow: "0 0 12px rgba(0, 229, 255, 0.4), 0 0 24px rgba(0, 229, 255, 0.15)",
123
+ pixelShadow: "3px 3px 0px #0A090D",
124
+ retroBox: "4px 4px 0px rgba(0, 0, 0, 0.9), inset -2px -2px 0px rgba(255, 255, 255, 0.1)"
125
+ };
126
+ var retroEffects = {
127
+ scanlineOpacity: "0.15",
128
+ crtFlickerSpeed: "0.15s",
129
+ pixelBorderWidth: "2px"
130
+ };
131
+ var zIndex = {
132
+ hide: -1,
133
+ auto: "auto",
134
+ base: 0,
135
+ docked: 10,
136
+ dropdown: 1e3,
137
+ sticky: 1100,
138
+ banner: 1200,
139
+ overlay: 1300,
140
+ modal: 1400,
141
+ popover: 1500,
142
+ skipLink: 1600,
143
+ toast: 1700,
144
+ tooltip: 1800
145
+ };
146
+
147
+ // src/css-variables.ts
148
+ function getCSSVariableObject() {
149
+ return {
150
+ // Colors - Inferno
151
+ "--mi-color-inferno-50": colors.inferno[50],
152
+ "--mi-color-inferno-100": colors.inferno[100],
153
+ "--mi-color-inferno-500": colors.inferno[500],
154
+ "--mi-color-inferno-600": colors.inferno[600],
155
+ "--mi-color-inferno-900": colors.inferno[900],
156
+ // Colors - Moon & Obsidian
157
+ "--mi-color-moon-50": colors.moon[50],
158
+ "--mi-color-moon-100": colors.moon[100],
159
+ "--mi-color-moon-400": colors.moon[400],
160
+ "--mi-color-moon-900": colors.moon[900],
161
+ "--mi-color-obsidian-900": colors.obsidian[900],
162
+ "--mi-color-obsidian-950": colors.obsidian[950],
163
+ // Status
164
+ "--mi-color-success": colors.status.success,
165
+ "--mi-color-warning": colors.status.warning,
166
+ "--mi-color-error": colors.status.error,
167
+ "--mi-color-info": colors.status.info,
168
+ // Typography
169
+ "--mi-font-sans": typography.fontFamily.sans,
170
+ "--mi-font-mono": typography.fontFamily.mono,
171
+ "--mi-font-pixel": typography.fontFamily.pixel,
172
+ // Spacing
173
+ "--mi-space-1": spacing[1],
174
+ "--mi-space-2": spacing[2],
175
+ "--mi-space-3": spacing[3],
176
+ "--mi-space-4": spacing[4],
177
+ "--mi-space-6": spacing[6],
178
+ "--mi-space-8": spacing[8],
179
+ // Radii
180
+ "--mi-radius-sm": radii.sm,
181
+ "--mi-radius-base": radii.base,
182
+ "--mi-radius-md": radii.md,
183
+ "--mi-radius-full": radii.full,
184
+ // Shadows & Glows
185
+ "--mi-shadow-glow": shadows.infernoGlow,
186
+ "--mi-shadow-pixel": shadows.pixelShadow,
187
+ // Focus Ring
188
+ "--mi-focus-ring-color": colors.inferno[500],
189
+ "--mi-focus-ring-width": "2px",
190
+ "--mi-focus-ring-offset": "2px",
191
+ // Z-Indices
192
+ "--mi-z-modal": String(zIndex.modal),
193
+ "--mi-z-toast": String(zIndex.toast),
194
+ "--mi-z-tooltip": String(zIndex.tooltip)
195
+ };
196
+ }
197
+ function getCSSVariableString() {
198
+ const vars = getCSSVariableObject();
199
+ return Object.entries(vars).map(([key, val]) => `${key}: ${val};`).join("\n ");
200
+ }
201
+
202
+ // src/a11y/focus.ts
203
+ var TABBABLE_SELECTOR = `
204
+ a[href],
205
+ button:not([disabled]),
206
+ area[href],
207
+ input:not([disabled]):not([type="hidden"]),
208
+ select:not([disabled]),
209
+ textarea:not([disabled]),
210
+ iframe,
211
+ object,
212
+ embed,
213
+ [tabindex]:not([tabindex="-1"]),
214
+ [contenteditable]
215
+ `;
216
+ function getFocusableElements(container) {
217
+ const elements = Array.from(container.querySelectorAll(TABBABLE_SELECTOR));
218
+ return elements.filter((el) => {
219
+ return (el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0) && getComputedStyle(el).visibility !== "hidden";
220
+ });
221
+ }
222
+ function trapFocus(container, event) {
223
+ if (event.key !== "Tab") return;
224
+ const focusables = getFocusableElements(container);
225
+ if (focusables.length === 0) {
226
+ event.preventDefault();
227
+ return;
228
+ }
229
+ const first = focusables[0];
230
+ const last = focusables[focusables.length - 1];
231
+ const active = document.activeElement;
232
+ if (event.shiftKey) {
233
+ if (active === first || !container.contains(active)) {
234
+ last?.focus();
235
+ event.preventDefault();
236
+ }
237
+ } else {
238
+ if (active === last || !container.contains(active)) {
239
+ first?.focus();
240
+ event.preventDefault();
241
+ }
242
+ }
243
+ }
244
+ function createFocusStore() {
245
+ let previousElement = null;
246
+ return {
247
+ save() {
248
+ if (document.activeElement instanceof HTMLElement) {
249
+ previousElement = document.activeElement;
250
+ }
251
+ },
252
+ restore() {
253
+ if (previousElement && typeof previousElement.focus === "function") {
254
+ previousElement.focus();
255
+ previousElement = null;
256
+ }
257
+ }
258
+ };
259
+ }
260
+
261
+ // src/a11y/motion.ts
262
+ var REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
263
+ function isReducedMotionPreferred() {
264
+ if (typeof window === "undefined" || !window.matchMedia) {
265
+ return false;
266
+ }
267
+ return window.matchMedia(REDUCED_MOTION_QUERY).matches;
268
+ }
269
+ function onReducedMotionChange(callback) {
270
+ if (typeof window === "undefined" || !window.matchMedia) {
271
+ return () => {
272
+ };
273
+ }
274
+ const mediaQuery = window.matchMedia(REDUCED_MOTION_QUERY);
275
+ const listener = (event) => callback(event.matches);
276
+ if (mediaQuery.addEventListener) {
277
+ mediaQuery.addEventListener("change", listener);
278
+ return () => mediaQuery.removeEventListener("change", listener);
279
+ }
280
+ return () => {
281
+ };
282
+ }
283
+
284
+ // src/a11y/keys.ts
285
+ var KEYS = {
286
+ ENTER: "Enter",
287
+ SPACE: " ",
288
+ ESCAPE: "Escape",
289
+ TAB: "Tab",
290
+ ARROW_UP: "ArrowUp",
291
+ ARROW_DOWN: "ArrowDown",
292
+ ARROW_LEFT: "ArrowLeft",
293
+ ARROW_RIGHT: "ArrowRight",
294
+ HOME: "Home",
295
+ END: "End"
296
+ };
297
+ function isKey(event, key) {
298
+ return event.key === KEYS[key];
299
+ }
300
+ function isActionKey(event) {
301
+ return event.key === KEYS.ENTER || event.key === KEYS.SPACE;
302
+ }
303
+ export {
304
+ KEYS,
305
+ colors,
306
+ createFocusStore,
307
+ getCSSVariableObject,
308
+ getCSSVariableString,
309
+ getFocusableElements,
310
+ isActionKey,
311
+ isKey,
312
+ isReducedMotionPreferred,
313
+ onReducedMotionChange,
314
+ radii,
315
+ retroEffects,
316
+ shadows,
317
+ spacing,
318
+ trapFocus,
319
+ typography,
320
+ zIndex
321
+ };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@moon-inferno/core",
3
+ "version": "0.1.0",
4
+ "description": "Framework-independent design tokens, CSS variables, responsive primitives, and accessibility utilities for Moon-Inferno.",
5
+ "license": "MIT",
6
+ "author": "Biagio Scaglia",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/biagio-scaglia/moon-inferno.git",
10
+ "directory": "packages/core"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "keywords": [
16
+ "css",
17
+ "design-tokens",
18
+ "accessibility",
19
+ "wcag",
20
+ "retro",
21
+ "cyberpunk",
22
+ "moon-inferno"
23
+ ],
24
+ "type": "module",
25
+ "main": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js"
31
+ }
32
+ },
33
+ "scripts": {
34
+ "build": "tsup src/index.ts --format esm,cjs --dts",
35
+ "typecheck": "tsc --noEmit"
36
+ }
37
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Accessibility Focus Utilities
3
+ * Provides helpers for focus containment (focus traps), focus restoration, and tabbable elements.
4
+ */
5
+
6
+ const TABBABLE_SELECTOR = `
7
+ a[href],
8
+ button:not([disabled]),
9
+ area[href],
10
+ input:not([disabled]):not([type="hidden"]),
11
+ select:not([disabled]),
12
+ textarea:not([disabled]),
13
+ iframe,
14
+ object,
15
+ embed,
16
+ [tabindex]:not([tabindex="-1"]),
17
+ [contenteditable]
18
+ `;
19
+
20
+ /**
21
+ * Returns all focusable elements within a given container.
22
+ */
23
+ export function getFocusableElements(container: HTMLElement): HTMLElement[] {
24
+ const elements = Array.from(container.querySelectorAll<HTMLElement>(TABBABLE_SELECTOR));
25
+ return elements.filter((el) => {
26
+ return (
27
+ el.offsetWidth > 0 ||
28
+ el.offsetHeight > 0 ||
29
+ el.getClientRects().length > 0
30
+ ) && getComputedStyle(el).visibility !== 'hidden';
31
+ });
32
+ }
33
+
34
+ /**
35
+ * Traps focus within a given container element.
36
+ * Useful for modal dialogs, drawers, and overlay menus.
37
+ */
38
+ export function trapFocus(container: HTMLElement, event: KeyboardEvent): void {
39
+ if (event.key !== 'Tab') return;
40
+
41
+ const focusables = getFocusableElements(container);
42
+ if (focusables.length === 0) {
43
+ event.preventDefault();
44
+ return;
45
+ }
46
+
47
+ const first = focusables[0];
48
+ const last = focusables[focusables.length - 1];
49
+ const active = document.activeElement as HTMLElement | null;
50
+
51
+ if (event.shiftKey) {
52
+ if (active === first || !container.contains(active)) {
53
+ last?.focus();
54
+ event.preventDefault();
55
+ }
56
+ } else {
57
+ if (active === last || !container.contains(active)) {
58
+ first?.focus();
59
+ event.preventDefault();
60
+ }
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Stores the previously focused element and provides a restoration function.
66
+ */
67
+ export function createFocusStore() {
68
+ let previousElement: HTMLElement | null = null;
69
+
70
+ return {
71
+ save() {
72
+ if (document.activeElement instanceof HTMLElement) {
73
+ previousElement = document.activeElement;
74
+ }
75
+ },
76
+ restore() {
77
+ if (previousElement && typeof previousElement.focus === 'function') {
78
+ previousElement.focus();
79
+ previousElement = null;
80
+ }
81
+ },
82
+ };
83
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Keyboard Key Constants & Event Helpers
3
+ */
4
+
5
+ export const KEYS = {
6
+ ENTER: 'Enter',
7
+ SPACE: ' ',
8
+ ESCAPE: 'Escape',
9
+ TAB: 'Tab',
10
+ ARROW_UP: 'ArrowUp',
11
+ ARROW_DOWN: 'ArrowDown',
12
+ ARROW_LEFT: 'ArrowLeft',
13
+ ARROW_RIGHT: 'ArrowRight',
14
+ HOME: 'Home',
15
+ END: 'End',
16
+ } as const;
17
+
18
+ export function isKey(event: KeyboardEvent, key: keyof typeof KEYS): boolean {
19
+ return event.key === KEYS[key];
20
+ }
21
+
22
+ export function isActionKey(event: KeyboardEvent): boolean {
23
+ return event.key === KEYS.ENTER || event.key === KEYS.SPACE;
24
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Reduced Motion Helper
3
+ * Utility to check if user prefers reduced motion.
4
+ */
5
+
6
+ const REDUCED_MOTION_QUERY = '(prefers-reduced-motion: reduce)';
7
+
8
+ /**
9
+ * Returns true if user has enabled prefers-reduced-motion in OS settings.
10
+ */
11
+ export function isReducedMotionPreferred(): boolean {
12
+ if (typeof window === 'undefined' || !window.matchMedia) {
13
+ return false;
14
+ }
15
+ return window.matchMedia(REDUCED_MOTION_QUERY).matches;
16
+ }
17
+
18
+ /**
19
+ * Subscribes to changes in reduced motion user preferences.
20
+ */
21
+ export function onReducedMotionChange(callback: (reduced: boolean) => void): () => void {
22
+ if (typeof window === 'undefined' || !window.matchMedia) {
23
+ return () => {};
24
+ }
25
+
26
+ const mediaQuery = window.matchMedia(REDUCED_MOTION_QUERY);
27
+ const listener = (event: MediaQueryListEvent) => callback(event.matches);
28
+
29
+ if (mediaQuery.addEventListener) {
30
+ mediaQuery.addEventListener('change', listener);
31
+ return () => mediaQuery.removeEventListener('change', listener);
32
+ }
33
+
34
+ return () => {};
35
+ }