@larose-ui/accessibility 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 laRose contributors
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.
@@ -0,0 +1,19 @@
1
+ type A11ySeverity = 'error' | 'warning';
2
+ interface A11yViolation {
3
+ severity: A11ySeverity;
4
+ rule: string;
5
+ message: string;
6
+ file?: string;
7
+ line?: number;
8
+ fix?: string;
9
+ }
10
+ interface A11yScanResult {
11
+ passed: boolean;
12
+ violations: A11yViolation[];
13
+ }
14
+ declare function scanComponentSource(source: string, filePath?: string): A11yScanResult;
15
+ declare function formatA11yReport(result: A11yScanResult): string;
16
+ /** Recommended CSP for apps using laRose runtime tokens. */
17
+ declare const RECOMMENDED_CSP: string;
18
+
19
+ export { type A11yScanResult, type A11ySeverity, type A11yViolation, RECOMMENDED_CSP, formatA11yReport, scanComponentSource };
package/dist/index.js ADDED
@@ -0,0 +1,96 @@
1
+ // src/index.ts
2
+ var RULES = [
3
+ {
4
+ id: "dialog-label",
5
+ pattern: /role=["']dialog["']/,
6
+ missing: /aria-labelledby|aria-label/,
7
+ message: "Dialog/Modal may be missing accessible label",
8
+ fix: "Add title prop or aria-labelledby",
9
+ severity: "error"
10
+ },
11
+ {
12
+ id: "empty-button",
13
+ pattern: /<button[^>]*>\s*<\/button>/,
14
+ missing: /aria-label/,
15
+ message: "Empty button without aria-label",
16
+ fix: "Add aria-label or visible text",
17
+ severity: "warning"
18
+ },
19
+ {
20
+ id: "img-alt",
21
+ pattern: /<img(?![^>]*\balt=)/,
22
+ message: "Image missing alt attribute",
23
+ fix: 'Add alt="" for decorative or descriptive alt text',
24
+ severity: "error"
25
+ },
26
+ {
27
+ id: "input-label",
28
+ pattern: /<input[^>]*\bid=["']([^"']+)["']/,
29
+ requiresLabelFor: true,
30
+ message: "Input with id may be missing associated label",
31
+ fix: 'Use <label htmlFor="..."> or aria-label',
32
+ severity: "warning"
33
+ }
34
+ ];
35
+ function scanComponentSource(source, filePath) {
36
+ const violations = [];
37
+ const lines = source.split("\n");
38
+ for (const rule of RULES) {
39
+ if (rule.id === "input-label") {
40
+ for (let i = 0; i < lines.length; i++) {
41
+ const line = lines[i];
42
+ const idMatch = line.match(/<input[^>]*\bid=["']([^"']+)["']/);
43
+ if (!idMatch) continue;
44
+ const id = idMatch[1];
45
+ const hasLabel = source.includes(`htmlFor="${id}"`) || source.includes(`htmlFor='${id}'`) || line.includes("aria-label");
46
+ if (!hasLabel) {
47
+ violations.push({
48
+ severity: rule.severity,
49
+ rule: rule.id,
50
+ message: rule.message,
51
+ file: filePath,
52
+ line: i + 1,
53
+ fix: rule.fix
54
+ });
55
+ }
56
+ }
57
+ continue;
58
+ }
59
+ if (!rule.pattern.test(source)) continue;
60
+ if ("missing" in rule && rule.missing && rule.missing.test(source)) continue;
61
+ violations.push({
62
+ severity: rule.severity,
63
+ rule: rule.id,
64
+ message: rule.message,
65
+ file: filePath,
66
+ fix: rule.fix
67
+ });
68
+ }
69
+ return {
70
+ passed: violations.filter((v) => v.severity === "error").length === 0,
71
+ violations
72
+ };
73
+ }
74
+ function formatA11yReport(result) {
75
+ if (result.violations.length === 0) return "Accessibility scan passed.";
76
+ const lines = ["Accessibility scan report:", ""];
77
+ for (const v of result.violations) {
78
+ lines.push(`[${v.severity.toUpperCase()}] ${v.rule}: ${v.message}`);
79
+ if (v.file) lines.push(` File: ${v.file}${v.line ? `:${v.line}` : ""}`);
80
+ if (v.fix) lines.push(` Fix: ${v.fix}`);
81
+ lines.push("");
82
+ }
83
+ lines.push(result.passed ? "Result: PASS (warnings only)" : "Result: FAIL");
84
+ return lines.join("\n");
85
+ }
86
+ var RECOMMENDED_CSP = [
87
+ "default-src 'self'",
88
+ "script-src 'self'",
89
+ "style-src 'self' 'unsafe-inline'",
90
+ "img-src 'self' data: https:"
91
+ ].join("; ");
92
+ export {
93
+ RECOMMENDED_CSP,
94
+ formatA11yReport,
95
+ scanComponentSource
96
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@larose-ui/accessibility",
3
+ "version": "0.1.0",
4
+ "description": "Accessibility utilities and source scanners for laRose",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "@larose-ui/core": "0.1.0"
20
+ },
21
+ "devDependencies": {
22
+ "tsup": "^8.3.5",
23
+ "typescript": "^5.7.2",
24
+ "vitest": "^2.1.8"
25
+ },
26
+ "license": "MIT",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/larose-ui/larose.git",
33
+ "directory": "packages/accessibility"
34
+ },
35
+ "keywords": [
36
+ "larose",
37
+ "react",
38
+ "ui-platform",
39
+ "design-system",
40
+ "saas"
41
+ ],
42
+ "scripts": {
43
+ "build": "tsup src/index.ts --format esm --dts --clean",
44
+ "test": "vitest run",
45
+ "typecheck": "tsc --noEmit",
46
+ "clean": "rm -rf dist"
47
+ }
48
+ }