@omnitron-dev/prism 0.1.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/LICENSE +21 -0
- package/README.md +44 -0
- package/bin/prism.js +13 -0
- package/dist/accessibility/index.d.ts +157 -0
- package/dist/accessibility/index.js +186 -0
- package/dist/accessibility/index.js.map +1 -0
- package/dist/blocks/index.d.ts +1239 -0
- package/dist/blocks/index.js +1712 -0
- package/dist/blocks/index.js.map +1 -0
- package/dist/chunk-77KIJLPP.js +37 -0
- package/dist/chunk-77KIJLPP.js.map +1 -0
- package/dist/chunk-BTIT7WYH.js +339 -0
- package/dist/chunk-BTIT7WYH.js.map +1 -0
- package/dist/chunk-BV32OJ2A.js +1409 -0
- package/dist/chunk-BV32OJ2A.js.map +1 -0
- package/dist/chunk-DDY7TLUI.js +139 -0
- package/dist/chunk-DDY7TLUI.js.map +1 -0
- package/dist/chunk-DXXZ3ITR.js +4227 -0
- package/dist/chunk-DXXZ3ITR.js.map +1 -0
- package/dist/chunk-E3XANPTO.js +2319 -0
- package/dist/chunk-E3XANPTO.js.map +1 -0
- package/dist/chunk-FU52GL2E.js +3 -0
- package/dist/chunk-FU52GL2E.js.map +1 -0
- package/dist/chunk-GYDT5EKX.js +16505 -0
- package/dist/chunk-GYDT5EKX.js.map +1 -0
- package/dist/chunk-HO2GKTWJ.js +28 -0
- package/dist/chunk-HO2GKTWJ.js.map +1 -0
- package/dist/chunk-JDTC2SBY.js +140 -0
- package/dist/chunk-JDTC2SBY.js.map +1 -0
- package/dist/chunk-JNU4QHJK.js +6 -0
- package/dist/chunk-JNU4QHJK.js.map +1 -0
- package/dist/chunk-LAEY5USO.js +2621 -0
- package/dist/chunk-LAEY5USO.js.map +1 -0
- package/dist/chunk-UR6X3W5I.js +530 -0
- package/dist/chunk-UR6X3W5I.js.map +1 -0
- package/dist/chunk-WC2WM2JD.js +883 -0
- package/dist/chunk-WC2WM2JD.js.map +1 -0
- package/dist/chunk-XWL6J6IO.js +40 -0
- package/dist/chunk-XWL6J6IO.js.map +1 -0
- package/dist/cli/index.js +2695 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/config-BA6IeTq9.d.ts +100 -0
- package/dist/core/index.d.ts +454 -0
- package/dist/core/index.js +9 -0
- package/dist/core/index.js.map +1 -0
- package/dist/forms/index.d.ts +562 -0
- package/dist/forms/index.js +545 -0
- package/dist/forms/index.js.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.js +10 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/http/index.d.ts +233 -0
- package/dist/http/index.js +282 -0
- package/dist/http/index.js.map +1 -0
- package/dist/index-odhPSv9I.d.ts +2491 -0
- package/dist/index.css +131 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +9109 -0
- package/dist/index.js +13280 -0
- package/dist/index.js.map +1 -0
- package/dist/layouts/index.d.ts +854 -0
- package/dist/layouts/index.js +6 -0
- package/dist/layouts/index.js.map +1 -0
- package/dist/netron/index.d.ts +4 -0
- package/dist/netron/index.js +4 -0
- package/dist/netron/index.js.map +1 -0
- package/dist/registry/index.d.ts +352 -0
- package/dist/registry/index.js +4 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry-BrDNftd5.d.ts +574 -0
- package/dist/settings-plpR26Xk.d.ts +455 -0
- package/dist/state/index.d.ts +981 -0
- package/dist/state/index.js +5 -0
- package/dist/state/index.js.map +1 -0
- package/dist/theme/index.d.ts +1049 -0
- package/dist/theme/index.js +5 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme-CrXLfP1c.d.ts +389 -0
- package/dist/types/index.d.ts +146 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/use-timeout-D7U3EAtH.d.ts +808 -0
- package/package.json +194 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 LuxQuant
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @omnitron-dev/prism
|
|
2
|
+
|
|
3
|
+
> Design system constructor — high-level UI building blocks for complex frontends
|
|
4
|
+
|
|
5
|
+
Part of the [Omni](../../README.md) monorepo — Fullstack Type-Safe RPC Framework.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @omnitron-dev/prism
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
Prism is a design system built on MUI v7, providing pre-composed, theme-aware components for building production frontends. All reusable UI — layouts, forms, navigation, data display — lives here so that application code stays thin.
|
|
16
|
+
|
|
17
|
+
### Key Features
|
|
18
|
+
|
|
19
|
+
- **MUI v7 foundation** — themed components with full customization
|
|
20
|
+
- **Layout system** — `DashboardLayout`, navigation items, sidebar, breadcrumbs
|
|
21
|
+
- **Form components** — integrated with react-hook-form + zod validation
|
|
22
|
+
- **Auth-aware** — components that respect authentication state
|
|
23
|
+
- **OTP input** — standalone OTP code input component
|
|
24
|
+
- **Avatar system** — default avatars, upload, presigned URL support
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import { PrismProvider, DashboardLayout } from '@omnitron-dev/prism';
|
|
30
|
+
|
|
31
|
+
function App() {
|
|
32
|
+
return (
|
|
33
|
+
<PrismProvider>
|
|
34
|
+
<DashboardLayout navItems={items}>
|
|
35
|
+
<Outlet />
|
|
36
|
+
</DashboardLayout>
|
|
37
|
+
</PrismProvider>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
MIT
|
package/bin/prism.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Prism CLI Entry Point
|
|
4
|
+
*
|
|
5
|
+
* @module @omnitron-dev/prism/cli
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import('../dist/cli/index.js').then(({ cli }) => {
|
|
9
|
+
cli().catch((error) => {
|
|
10
|
+
console.error('Error:', error.message);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { PropsWithChildren, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vision Mode Accessibility System
|
|
5
|
+
*
|
|
6
|
+
* Simulates color vision deficiencies to help designers and developers
|
|
7
|
+
* test their applications for accessibility. Uses SVG color matrix filters
|
|
8
|
+
* applied globally to simulate how users with different types of color
|
|
9
|
+
* blindness perceive content.
|
|
10
|
+
*
|
|
11
|
+
* Vision Deficiency Types:
|
|
12
|
+
* - Protanopia: Red-blind (affects ~1% of males)
|
|
13
|
+
* - Deuteranopia: Green-blind (affects ~1% of males)
|
|
14
|
+
* - Tritanopia: Blue-blind (rare, affects <0.01% of population)
|
|
15
|
+
* - Achromatopsia: Complete color blindness (grayscale)
|
|
16
|
+
*
|
|
17
|
+
* @module @omnitron-dev/prism/accessibility
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Available vision modes for color blindness simulation.
|
|
22
|
+
*/
|
|
23
|
+
type VisionMode = 'normal' | 'protanopia' | 'deuteranopia' | 'tritanopia' | 'achromatopsia';
|
|
24
|
+
/**
|
|
25
|
+
* Vision mode metadata for UI display.
|
|
26
|
+
*/
|
|
27
|
+
interface VisionModeOption {
|
|
28
|
+
/** Mode identifier */
|
|
29
|
+
value: VisionMode;
|
|
30
|
+
/** Human-readable label */
|
|
31
|
+
label: string;
|
|
32
|
+
/** Description of the vision deficiency */
|
|
33
|
+
description: string;
|
|
34
|
+
/** Percentage of population affected (for educational purposes) */
|
|
35
|
+
prevalence?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Vision mode context value.
|
|
39
|
+
*/
|
|
40
|
+
interface VisionModeContextValue {
|
|
41
|
+
/** Current vision mode */
|
|
42
|
+
mode: VisionMode;
|
|
43
|
+
/** Set the vision mode */
|
|
44
|
+
setMode: (mode: VisionMode) => void;
|
|
45
|
+
/** Toggle between normal and a specific mode */
|
|
46
|
+
toggle: (mode?: VisionMode) => void;
|
|
47
|
+
/** Reset to normal vision */
|
|
48
|
+
reset: () => void;
|
|
49
|
+
/** Whether vision filters are active */
|
|
50
|
+
isFiltered: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Available vision mode options with descriptions.
|
|
54
|
+
*/
|
|
55
|
+
declare const VISION_MODE_OPTIONS: VisionModeOption[];
|
|
56
|
+
/**
|
|
57
|
+
* Props for VisionModeProvider.
|
|
58
|
+
*/
|
|
59
|
+
interface VisionModeProviderProps extends PropsWithChildren {
|
|
60
|
+
/** Initial vision mode (default: 'normal' or from localStorage) */
|
|
61
|
+
defaultMode?: VisionMode;
|
|
62
|
+
/** Storage key for persistence (default: 'prism-vision-mode') */
|
|
63
|
+
storageKey?: string;
|
|
64
|
+
/** Disable persistence to localStorage */
|
|
65
|
+
disablePersistence?: boolean;
|
|
66
|
+
/** CSS selector attribute name (default: 'data-vision') */
|
|
67
|
+
attributeName?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* VisionModeProvider - Provides vision mode context and renders filters.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```tsx
|
|
74
|
+
* // In your app root
|
|
75
|
+
* import { VisionModeProvider } from '@omnitron-dev/prism/accessibility';
|
|
76
|
+
*
|
|
77
|
+
* function App() {
|
|
78
|
+
* return (
|
|
79
|
+
* <VisionModeProvider>
|
|
80
|
+
* <YourApp />
|
|
81
|
+
* </VisionModeProvider>
|
|
82
|
+
* );
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* // In a component
|
|
86
|
+
* import { useVisionMode, VISION_MODE_OPTIONS } from '@omnitron-dev/prism/accessibility';
|
|
87
|
+
*
|
|
88
|
+
* function AccessibilityPanel() {
|
|
89
|
+
* const { mode, setMode } = useVisionMode();
|
|
90
|
+
*
|
|
91
|
+
* return (
|
|
92
|
+
* <select value={mode} onChange={(e) => setMode(e.target.value as VisionMode)}>
|
|
93
|
+
* {VISION_MODE_OPTIONS.map((option) => (
|
|
94
|
+
* <option key={option.value} value={option.value}>
|
|
95
|
+
* {option.label}
|
|
96
|
+
* </option>
|
|
97
|
+
* ))}
|
|
98
|
+
* </select>
|
|
99
|
+
* );
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
declare function VisionModeProvider({ children, defaultMode, storageKey, disablePersistence, attributeName, }: VisionModeProviderProps): ReactNode;
|
|
104
|
+
/**
|
|
105
|
+
* useVisionMode - Hook to access vision mode context.
|
|
106
|
+
*
|
|
107
|
+
* @throws Error if used outside of VisionModeProvider
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```tsx
|
|
111
|
+
* function AccessibilityToggle() {
|
|
112
|
+
* const { mode, setMode, isFiltered, reset } = useVisionMode();
|
|
113
|
+
*
|
|
114
|
+
* return (
|
|
115
|
+
* <div>
|
|
116
|
+
* <p>Current mode: {mode}</p>
|
|
117
|
+
* <button onClick={() => setMode('protanopia')}>
|
|
118
|
+
* Simulate Protanopia
|
|
119
|
+
* </button>
|
|
120
|
+
* {isFiltered && (
|
|
121
|
+
* <button onClick={reset}>Reset to Normal</button>
|
|
122
|
+
* )}
|
|
123
|
+
* </div>
|
|
124
|
+
* );
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
declare function useVisionMode(): VisionModeContextValue;
|
|
129
|
+
/**
|
|
130
|
+
* Generate CSS styles for vision mode filters.
|
|
131
|
+
* Use this in your theme's CssBaseline or global styles.
|
|
132
|
+
*
|
|
133
|
+
* @param attributeName - The data attribute name (default: 'data-vision')
|
|
134
|
+
* @returns CSS styles object for MUI CssBaseline styleOverrides
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```tsx
|
|
138
|
+
* // In your theme configuration
|
|
139
|
+
* import { getVisionModeStyles } from '@omnitron-dev/prism/accessibility';
|
|
140
|
+
*
|
|
141
|
+
* const theme = createTheme({
|
|
142
|
+
* components: {
|
|
143
|
+
* MuiCssBaseline: {
|
|
144
|
+
* styleOverrides: (theme) => ({
|
|
145
|
+
* ...getVisionModeStyles(),
|
|
146
|
+
* // ... other styles
|
|
147
|
+
* }),
|
|
148
|
+
* },
|
|
149
|
+
* },
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
declare function getVisionModeStyles(attributeName?: string): Record<string, {
|
|
154
|
+
filter: string;
|
|
155
|
+
}>;
|
|
156
|
+
|
|
157
|
+
export { VISION_MODE_OPTIONS, type VisionMode, type VisionModeContextValue, type VisionModeOption, VisionModeProvider, type VisionModeProviderProps, getVisionModeStyles, useVisionMode };
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import '../chunk-77KIJLPP.js';
|
|
2
|
+
import { createContext, useState, useEffect, useCallback, useContext } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
4
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
var STORAGE_KEY = "prism-vision-mode";
|
|
7
|
+
var FILTER_CONTAINER_ID = "prism-vision-filters";
|
|
8
|
+
var VISION_MODE_OPTIONS = [
|
|
9
|
+
{
|
|
10
|
+
value: "normal",
|
|
11
|
+
label: "Normal Vision",
|
|
12
|
+
description: "Shows all colors normally"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
value: "protanopia",
|
|
16
|
+
label: "Protanopia",
|
|
17
|
+
description: "Difficulty distinguishing red from green (red-blind)",
|
|
18
|
+
prevalence: "~1% of males"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
value: "deuteranopia",
|
|
22
|
+
label: "Deuteranopia",
|
|
23
|
+
description: "Difficulty distinguishing green from red (green-blind)",
|
|
24
|
+
prevalence: "~1% of males"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
value: "tritanopia",
|
|
28
|
+
label: "Tritanopia",
|
|
29
|
+
description: "Difficulty distinguishing blue from yellow (blue-blind)",
|
|
30
|
+
prevalence: "<0.01%"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
value: "achromatopsia",
|
|
34
|
+
label: "Achromatopsia",
|
|
35
|
+
description: "Complete color blindness (grayscale only)",
|
|
36
|
+
prevalence: "~0.003%"
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
var FILTER_MATRICES = {
|
|
40
|
+
// Protanopia: Reduced sensitivity to red light
|
|
41
|
+
protanopia: `
|
|
42
|
+
0.10889 0.89111 0.00000 0 0
|
|
43
|
+
0.10889 0.89111 0.00000 0 0
|
|
44
|
+
0.00447 -0.00447 1.00000 0 0
|
|
45
|
+
0 0 0 1 0
|
|
46
|
+
`,
|
|
47
|
+
// Deuteranopia: Reduced sensitivity to green light
|
|
48
|
+
deuteranopia: `
|
|
49
|
+
0.4251 0.6934 -0.1147 0 0
|
|
50
|
+
0.3417 0.5882 0.0692 0 0
|
|
51
|
+
-0.0105 0.0234 0.9870 0 0
|
|
52
|
+
0 0 0 1 0
|
|
53
|
+
`,
|
|
54
|
+
// Tritanopia: Reduced sensitivity to blue light
|
|
55
|
+
tritanopia: `
|
|
56
|
+
0.95 0.05 0 0 0
|
|
57
|
+
0 0.433 0.567 0 0
|
|
58
|
+
0 0.475 0.525 0 0
|
|
59
|
+
0 0 0 1 0
|
|
60
|
+
`,
|
|
61
|
+
// Achromatopsia: Complete color blindness (luminance only)
|
|
62
|
+
achromatopsia: `
|
|
63
|
+
0.299 0.587 0.114 0 0
|
|
64
|
+
0.299 0.587 0.114 0 0
|
|
65
|
+
0.299 0.587 0.114 0 0
|
|
66
|
+
0 0 0 1 0
|
|
67
|
+
`
|
|
68
|
+
};
|
|
69
|
+
function VisionFilters() {
|
|
70
|
+
return /* @__PURE__ */ jsx(
|
|
71
|
+
"div",
|
|
72
|
+
{
|
|
73
|
+
id: FILTER_CONTAINER_ID,
|
|
74
|
+
style: {
|
|
75
|
+
position: "absolute",
|
|
76
|
+
width: 0,
|
|
77
|
+
height: 0,
|
|
78
|
+
overflow: "hidden",
|
|
79
|
+
pointerEvents: "none"
|
|
80
|
+
},
|
|
81
|
+
"aria-hidden": "true",
|
|
82
|
+
children: /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true", children: /* @__PURE__ */ jsx("defs", { children: Object.entries(FILTER_MATRICES).map(([mode, matrix]) => /* @__PURE__ */ jsx("filter", { id: `${mode}-filter`, children: /* @__PURE__ */ jsx("feColorMatrix", { type: "matrix", in: "SourceGraphic", values: matrix }) }, mode)) }) })
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
var VisionModeContext = createContext(null);
|
|
87
|
+
function VisionModeProvider({
|
|
88
|
+
children,
|
|
89
|
+
defaultMode,
|
|
90
|
+
storageKey = STORAGE_KEY,
|
|
91
|
+
disablePersistence = false,
|
|
92
|
+
attributeName = "data-vision"
|
|
93
|
+
}) {
|
|
94
|
+
const [mode, setModeState] = useState(() => {
|
|
95
|
+
if (typeof window === "undefined") return defaultMode ?? "normal";
|
|
96
|
+
if (disablePersistence) return defaultMode ?? "normal";
|
|
97
|
+
try {
|
|
98
|
+
const stored = localStorage.getItem(storageKey);
|
|
99
|
+
if (stored) {
|
|
100
|
+
const parsed = JSON.parse(stored);
|
|
101
|
+
if (VISION_MODE_OPTIONS.some((opt) => opt.value === parsed)) {
|
|
102
|
+
return parsed;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
} catch {
|
|
106
|
+
}
|
|
107
|
+
return defaultMode ?? "normal";
|
|
108
|
+
});
|
|
109
|
+
const [needsFilters, setNeedsFilters] = useState(false);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (typeof document !== "undefined" && !document.getElementById(FILTER_CONTAINER_ID)) {
|
|
112
|
+
setNeedsFilters(true);
|
|
113
|
+
}
|
|
114
|
+
}, []);
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (typeof document === "undefined") return void 0;
|
|
117
|
+
if (mode === "normal") {
|
|
118
|
+
document.documentElement.removeAttribute(attributeName);
|
|
119
|
+
} else {
|
|
120
|
+
document.documentElement.setAttribute(attributeName, mode);
|
|
121
|
+
}
|
|
122
|
+
return () => {
|
|
123
|
+
document.documentElement.removeAttribute(attributeName);
|
|
124
|
+
};
|
|
125
|
+
}, [mode, attributeName]);
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
if (disablePersistence || typeof localStorage === "undefined") return void 0;
|
|
128
|
+
try {
|
|
129
|
+
localStorage.setItem(storageKey, JSON.stringify(mode));
|
|
130
|
+
} catch {
|
|
131
|
+
}
|
|
132
|
+
return void 0;
|
|
133
|
+
}, [mode, storageKey, disablePersistence]);
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (disablePersistence || typeof window === "undefined") return void 0;
|
|
136
|
+
const handleStorage = (e) => {
|
|
137
|
+
if (e.key !== storageKey || !e.newValue) return;
|
|
138
|
+
try {
|
|
139
|
+
const parsed = JSON.parse(e.newValue);
|
|
140
|
+
if (VISION_MODE_OPTIONS.some((opt) => opt.value === parsed)) {
|
|
141
|
+
setModeState(parsed);
|
|
142
|
+
}
|
|
143
|
+
} catch {
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
window.addEventListener("storage", handleStorage);
|
|
147
|
+
return () => window.removeEventListener("storage", handleStorage);
|
|
148
|
+
}, [storageKey, disablePersistence]);
|
|
149
|
+
const setMode = useCallback((newMode) => {
|
|
150
|
+
setModeState(newMode);
|
|
151
|
+
}, []);
|
|
152
|
+
const toggle = useCallback((targetMode = "protanopia") => {
|
|
153
|
+
setModeState((current) => current === "normal" ? targetMode : "normal");
|
|
154
|
+
}, []);
|
|
155
|
+
const reset = useCallback(() => {
|
|
156
|
+
setModeState("normal");
|
|
157
|
+
}, []);
|
|
158
|
+
const value = {
|
|
159
|
+
mode,
|
|
160
|
+
setMode,
|
|
161
|
+
toggle,
|
|
162
|
+
reset,
|
|
163
|
+
isFiltered: mode !== "normal"
|
|
164
|
+
};
|
|
165
|
+
return /* @__PURE__ */ jsxs(VisionModeContext.Provider, { value, children: [
|
|
166
|
+
needsFilters && typeof document !== "undefined" && document.body ? createPortal(/* @__PURE__ */ jsx(VisionFilters, {}), document.body) : null,
|
|
167
|
+
children
|
|
168
|
+
] });
|
|
169
|
+
}
|
|
170
|
+
function useVisionMode() {
|
|
171
|
+
const context = useContext(VisionModeContext);
|
|
172
|
+
if (!context) {
|
|
173
|
+
throw new Error("useVisionMode must be used within a VisionModeProvider");
|
|
174
|
+
}
|
|
175
|
+
return context;
|
|
176
|
+
}
|
|
177
|
+
function getVisionModeStyles(attributeName = "data-vision") {
|
|
178
|
+
const modes = ["protanopia", "deuteranopia", "tritanopia", "achromatopsia"];
|
|
179
|
+
return Object.fromEntries(
|
|
180
|
+
modes.map((mode) => [`html[${attributeName}="${mode}"]:not([data-showcase])`, { filter: `url("#${mode}-filter")` }])
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export { VISION_MODE_OPTIONS, VisionModeProvider, getVisionModeStyles, useVisionMode };
|
|
185
|
+
//# sourceMappingURL=index.js.map
|
|
186
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/accessibility/vision-mode.tsx"],"names":[],"mappings":";;;;;AAyEA,IAAM,WAAA,GAAc,mBAAA;AACpB,IAAM,mBAAA,GAAsB,sBAAA;AAKrB,IAAM,mBAAA,GAA0C;AAAA,EACrD;AAAA,IACE,KAAA,EAAO,QAAA;AAAA,IACP,KAAA,EAAO,eAAA;AAAA,IACP,WAAA,EAAa;AAAA,GACf;AAAA,EACA;AAAA,IACE,KAAA,EAAO,YAAA;AAAA,IACP,KAAA,EAAO,YAAA;AAAA,IACP,WAAA,EAAa,sDAAA;AAAA,IACb,UAAA,EAAY;AAAA,GACd;AAAA,EACA;AAAA,IACE,KAAA,EAAO,cAAA;AAAA,IACP,KAAA,EAAO,cAAA;AAAA,IACP,WAAA,EAAa,wDAAA;AAAA,IACb,UAAA,EAAY;AAAA,GACd;AAAA,EACA;AAAA,IACE,KAAA,EAAO,YAAA;AAAA,IACP,KAAA,EAAO,YAAA;AAAA,IACP,WAAA,EAAa,yDAAA;AAAA,IACb,UAAA,EAAY;AAAA,GACd;AAAA,EACA;AAAA,IACE,KAAA,EAAO,eAAA;AAAA,IACP,KAAA,EA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ACT;AA8BO,SAAS,mBAAA,CAAoB,gBAAgB,aAAA,EAAmD;AACrG,EAAA,MAAM,KAAA,GAA8C,CAAC,YAAA,EAAc,cAAA,EAAgB,cAAc,eAAe,CAAA;AAEhH,EAAA,OAAO,MAAA,CAAO,WAAA;AAAA,IACZ,MAAM,GAAA,CAAI,CAAC,IAAA,KAAS,CAAC,QAAQ,aAAa,CAAA,EAAA,EAAK,IAAI,CAAA,uBAAA,CAAA,EAA2B,EAAE,MAAA,EAAQ,CAAA,MAAA,EAAS,IAAI,CAAA,SAAA,CAAA,EAAa,CAAC;AAAA,GACrH;AACF","file":"index.js","sourcesContent":["'use client';\n\n/**\n * Vision Mode Accessibility System\n *\n * Simulates color vision deficiencies to help designers and developers\n * test their applications for accessibility. Uses SVG color matrix filters\n * applied globally to simulate how users with different types of color\n * blindness perceive content.\n *\n * Vision Deficiency Types:\n * - Protanopia: Red-blind (affects ~1% of males)\n * - Deuteranopia: Green-blind (affects ~1% of males)\n * - Tritanopia: Blue-blind (rare, affects <0.01% of population)\n * - Achromatopsia: Complete color blindness (grayscale)\n *\n * @module @omnitron-dev/prism/accessibility\n */\n\nimport {\n createContext,\n useContext,\n useState,\n useEffect,\n useCallback,\n type PropsWithChildren,\n type ReactNode,\n} from 'react';\nimport { createPortal } from 'react-dom';\n\n// =============================================================================\n// TYPES\n// =============================================================================\n\n/**\n * Available vision modes for color blindness simulation.\n */\nexport type VisionMode = 'normal' | 'protanopia' | 'deuteranopia' | 'tritanopia' | 'achromatopsia';\n\n/**\n * Vision mode metadata for UI display.\n */\nexport interface VisionModeOption {\n /** Mode identifier */\n value: VisionMode;\n /** Human-readable label */\n label: string;\n /** Description of the vision deficiency */\n description: string;\n /** Percentage of population affected (for educational purposes) */\n prevalence?: string;\n}\n\n/**\n * Vision mode context value.\n */\nexport interface VisionModeContextValue {\n /** Current vision mode */\n mode: VisionMode;\n /** Set the vision mode */\n setMode: (mode: VisionMode) => void;\n /** Toggle between normal and a specific mode */\n toggle: (mode?: VisionMode) => void;\n /** Reset to normal vision */\n reset: () => void;\n /** Whether vision filters are active */\n isFiltered: boolean;\n}\n\n// =============================================================================\n// CONSTANTS\n// =============================================================================\n\nconst STORAGE_KEY = 'prism-vision-mode';\nconst FILTER_CONTAINER_ID = 'prism-vision-filters';\n\n/**\n * Available vision mode options with descriptions.\n */\nexport const VISION_MODE_OPTIONS: VisionModeOption[] = [\n {\n value: 'normal',\n label: 'Normal Vision',\n description: 'Shows all colors normally',\n },\n {\n value: 'protanopia',\n label: 'Protanopia',\n description: 'Difficulty distinguishing red from green (red-blind)',\n prevalence: '~1% of males',\n },\n {\n value: 'deuteranopia',\n label: 'Deuteranopia',\n description: 'Difficulty distinguishing green from red (green-blind)',\n prevalence: '~1% of males',\n },\n {\n value: 'tritanopia',\n label: 'Tritanopia',\n description: 'Difficulty distinguishing blue from yellow (blue-blind)',\n prevalence: '<0.01%',\n },\n {\n value: 'achromatopsia',\n label: 'Achromatopsia',\n description: 'Complete color blindness (grayscale only)',\n prevalence: '~0.003%',\n },\n];\n\n// =============================================================================\n// SVG FILTERS\n// =============================================================================\n\n/**\n * Color matrix values for vision deficiency simulation.\n * These matrices transform colors to simulate how they appear to people\n * with various types of color blindness.\n */\nconst FILTER_MATRICES = {\n // Protanopia: Reduced sensitivity to red light\n protanopia: `\n 0.10889 0.89111 0.00000 0 0\n 0.10889 0.89111 0.00000 0 0\n 0.00447 -0.00447 1.00000 0 0\n 0 0 0 1 0\n `,\n // Deuteranopia: Reduced sensitivity to green light\n deuteranopia: `\n 0.4251 0.6934 -0.1147 0 0\n 0.3417 0.5882 0.0692 0 0\n -0.0105 0.0234 0.9870 0 0\n 0 0 0 1 0\n `,\n // Tritanopia: Reduced sensitivity to blue light\n tritanopia: `\n 0.95 0.05 0 0 0\n 0 0.433 0.567 0 0\n 0 0.475 0.525 0 0\n 0 0 0 1 0\n `,\n // Achromatopsia: Complete color blindness (luminance only)\n achromatopsia: `\n 0.299 0.587 0.114 0 0\n 0.299 0.587 0.114 0 0\n 0.299 0.587 0.114 0 0\n 0 0 0 1 0\n `,\n} as const;\n\n/**\n * SVG filters for vision mode simulation.\n * Rendered as a hidden element and referenced by CSS.\n */\nfunction VisionFilters(): ReactNode {\n return (\n <div\n id={FILTER_CONTAINER_ID}\n style={{\n position: 'absolute',\n width: 0,\n height: 0,\n overflow: 'hidden',\n pointerEvents: 'none',\n }}\n aria-hidden=\"true\"\n >\n <svg xmlns=\"http://www.w3.org/2000/svg\" aria-hidden=\"true\">\n <defs>\n {Object.entries(FILTER_MATRICES).map(([mode, matrix]) => (\n <filter key={mode} id={`${mode}-filter`}>\n <feColorMatrix type=\"matrix\" in=\"SourceGraphic\" values={matrix} />\n </filter>\n ))}\n </defs>\n </svg>\n </div>\n );\n}\n\n// =============================================================================\n// CONTEXT\n// =============================================================================\n\nconst VisionModeContext = createContext<VisionModeContextValue | null>(null);\n\n// =============================================================================\n// PROVIDER\n// =============================================================================\n\n/**\n * Props for VisionModeProvider.\n */\nexport interface VisionModeProviderProps extends PropsWithChildren {\n /** Initial vision mode (default: 'normal' or from localStorage) */\n defaultMode?: VisionMode;\n /** Storage key for persistence (default: 'prism-vision-mode') */\n storageKey?: string;\n /** Disable persistence to localStorage */\n disablePersistence?: boolean;\n /** CSS selector attribute name (default: 'data-vision') */\n attributeName?: string;\n}\n\n/**\n * VisionModeProvider - Provides vision mode context and renders filters.\n *\n * @example\n * ```tsx\n * // In your app root\n * import { VisionModeProvider } from '@omnitron-dev/prism/accessibility';\n *\n * function App() {\n * return (\n * <VisionModeProvider>\n * <YourApp />\n * </VisionModeProvider>\n * );\n * }\n *\n * // In a component\n * import { useVisionMode, VISION_MODE_OPTIONS } from '@omnitron-dev/prism/accessibility';\n *\n * function AccessibilityPanel() {\n * const { mode, setMode } = useVisionMode();\n *\n * return (\n * <select value={mode} onChange={(e) => setMode(e.target.value as VisionMode)}>\n * {VISION_MODE_OPTIONS.map((option) => (\n * <option key={option.value} value={option.value}>\n * {option.label}\n * </option>\n * ))}\n * </select>\n * );\n * }\n * ```\n */\nexport function VisionModeProvider({\n children,\n defaultMode,\n storageKey = STORAGE_KEY,\n disablePersistence = false,\n attributeName = 'data-vision',\n}: VisionModeProviderProps): ReactNode {\n // Initialize from localStorage or default\n const [mode, setModeState] = useState<VisionMode>(() => {\n if (typeof window === 'undefined') return defaultMode ?? 'normal';\n if (disablePersistence) return defaultMode ?? 'normal';\n\n try {\n const stored = localStorage.getItem(storageKey);\n if (stored) {\n const parsed = JSON.parse(stored) as VisionMode;\n if (VISION_MODE_OPTIONS.some((opt) => opt.value === parsed)) {\n return parsed;\n }\n }\n } catch {\n // Ignore localStorage errors\n }\n return defaultMode ?? 'normal';\n });\n\n const [needsFilters, setNeedsFilters] = useState(false);\n\n // Check if filters need to be rendered\n useEffect(() => {\n if (typeof document !== 'undefined' && !document.getElementById(FILTER_CONTAINER_ID)) {\n setNeedsFilters(true);\n }\n }, []);\n\n // Apply data attribute to document element\n useEffect(() => {\n if (typeof document === 'undefined') return undefined;\n\n if (mode === 'normal') {\n document.documentElement.removeAttribute(attributeName);\n } else {\n document.documentElement.setAttribute(attributeName, mode);\n }\n\n return () => {\n document.documentElement.removeAttribute(attributeName);\n };\n }, [mode, attributeName]);\n\n // Persist to localStorage\n useEffect(() => {\n if (disablePersistence || typeof localStorage === 'undefined') return undefined;\n\n try {\n localStorage.setItem(storageKey, JSON.stringify(mode));\n } catch {\n // Ignore localStorage errors\n }\n return undefined;\n }, [mode, storageKey, disablePersistence]);\n\n // Cross-tab sync via storage event\n useEffect(() => {\n if (disablePersistence || typeof window === 'undefined') return undefined;\n\n const handleStorage = (e: StorageEvent) => {\n if (e.key !== storageKey || !e.newValue) return;\n try {\n const parsed = JSON.parse(e.newValue) as VisionMode;\n if (VISION_MODE_OPTIONS.some((opt) => opt.value === parsed)) {\n setModeState(parsed);\n }\n } catch {\n // Ignore parse errors\n }\n };\n\n window.addEventListener('storage', handleStorage);\n return () => window.removeEventListener('storage', handleStorage);\n }, [storageKey, disablePersistence]);\n\n const setMode = useCallback((newMode: VisionMode) => {\n setModeState(newMode);\n }, []);\n\n const toggle = useCallback((targetMode: VisionMode = 'protanopia') => {\n setModeState((current) => (current === 'normal' ? targetMode : 'normal'));\n }, []);\n\n const reset = useCallback(() => {\n setModeState('normal');\n }, []);\n\n const value: VisionModeContextValue = {\n mode,\n setMode,\n toggle,\n reset,\n isFiltered: mode !== 'normal',\n };\n\n return (\n <VisionModeContext.Provider value={value}>\n {needsFilters && typeof document !== 'undefined' && document.body\n ? createPortal(<VisionFilters />, document.body)\n : null}\n {children}\n </VisionModeContext.Provider>\n );\n}\n\n// =============================================================================\n// HOOK\n// =============================================================================\n\n/**\n * useVisionMode - Hook to access vision mode context.\n *\n * @throws Error if used outside of VisionModeProvider\n *\n * @example\n * ```tsx\n * function AccessibilityToggle() {\n * const { mode, setMode, isFiltered, reset } = useVisionMode();\n *\n * return (\n * <div>\n * <p>Current mode: {mode}</p>\n * <button onClick={() => setMode('protanopia')}>\n * Simulate Protanopia\n * </button>\n * {isFiltered && (\n * <button onClick={reset}>Reset to Normal</button>\n * )}\n * </div>\n * );\n * }\n * ```\n */\nexport function useVisionMode(): VisionModeContextValue {\n const context = useContext(VisionModeContext);\n\n if (!context) {\n throw new Error('useVisionMode must be used within a VisionModeProvider');\n }\n\n return context;\n}\n\n// =============================================================================\n// CSS STYLES HELPER\n// =============================================================================\n\n/**\n * Generate CSS styles for vision mode filters.\n * Use this in your theme's CssBaseline or global styles.\n *\n * @param attributeName - The data attribute name (default: 'data-vision')\n * @returns CSS styles object for MUI CssBaseline styleOverrides\n *\n * @example\n * ```tsx\n * // In your theme configuration\n * import { getVisionModeStyles } from '@omnitron-dev/prism/accessibility';\n *\n * const theme = createTheme({\n * components: {\n * MuiCssBaseline: {\n * styleOverrides: (theme) => ({\n * ...getVisionModeStyles(),\n * // ... other styles\n * }),\n * },\n * },\n * });\n * ```\n */\nexport function getVisionModeStyles(attributeName = 'data-vision'): Record<string, { filter: string }> {\n const modes: Array<Exclude<VisionMode, 'normal'>> = ['protanopia', 'deuteranopia', 'tritanopia', 'achromatopsia'];\n\n return Object.fromEntries(\n modes.map((mode) => [`html[${attributeName}=\"${mode}\"]:not([data-showcase])`, { filter: `url(\"#${mode}-filter\")` }])\n ) as Record<string, { filter: string }>;\n}\n"]}
|