@fragments-sdk/cli 0.10.1 → 0.12.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/dist/ai-client-I6MDWNYA.js +21 -0
- package/dist/bin.js +292 -367
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-PW7QTQA6.js → chunk-4OC7FTJB.js} +2 -2
- package/dist/{chunk-HRFUSSZI.js → chunk-AM4MRTMN.js} +2 -2
- package/dist/{chunk-5G3VZH43.js → chunk-GVDSFQ4E.js} +281 -351
- package/dist/chunk-GVDSFQ4E.js.map +1 -0
- package/dist/chunk-JJ2VRTBU.js +626 -0
- package/dist/chunk-JJ2VRTBU.js.map +1 -0
- package/dist/{chunk-D5PYOXEI.js → chunk-LVWFOLUZ.js} +148 -13
- package/dist/{chunk-D5PYOXEI.js.map → chunk-LVWFOLUZ.js.map} +1 -1
- package/dist/{chunk-WXSR2II7.js → chunk-OQKMEFOS.js} +58 -6
- package/dist/chunk-OQKMEFOS.js.map +1 -0
- package/dist/chunk-SXTKFDCR.js +104 -0
- package/dist/chunk-SXTKFDCR.js.map +1 -0
- package/dist/chunk-T5OMVL7E.js +443 -0
- package/dist/chunk-T5OMVL7E.js.map +1 -0
- package/dist/{chunk-ZM4ZQZWZ.js → chunk-TPWGL2XS.js} +39 -37
- package/dist/chunk-TPWGL2XS.js.map +1 -0
- package/dist/{chunk-OQO55NKV.js → chunk-WFS63PCW.js} +85 -11
- package/dist/chunk-WFS63PCW.js.map +1 -0
- package/dist/core/index.js +9 -1
- package/dist/{discovery-NEOY4MPN.js → discovery-ZJQSXF56.js} +3 -3
- package/dist/{generate-FBHSXR3D.js → generate-RJFS2JWA.js} +4 -4
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/init-ZSX3NRCZ.js +636 -0
- package/dist/init-ZSX3NRCZ.js.map +1 -0
- package/dist/mcp-bin.js +2 -2
- package/dist/{scan-CJF2DOQW.js → scan-3PMCJ4RB.js} +6 -6
- package/dist/scan-generate-SYU4PYZD.js +1115 -0
- package/dist/scan-generate-SYU4PYZD.js.map +1 -0
- package/dist/{service-TQYWY65E.js → service-VMGNJZ42.js} +3 -3
- package/dist/snapshot-XOISO2IS.js +139 -0
- package/dist/snapshot-XOISO2IS.js.map +1 -0
- package/dist/{static-viewer-NUBFPKWH.js → static-viewer-5GXH2MGE.js} +3 -3
- package/dist/static-viewer-5GXH2MGE.js.map +1 -0
- package/dist/{test-Z5LVO724.js → test-SI4NSHQX.js} +4 -4
- package/dist/{tokens-CE46OTMD.js → tokens-T6SIVUT5.js} +5 -5
- package/dist/{viewer-DNMNC5VS.js → viewer-7ZEAFBVN.js} +80 -58
- package/dist/viewer-7ZEAFBVN.js.map +1 -0
- package/package.json +6 -14
- package/src/ai-client.ts +156 -0
- package/src/bin.ts +74 -2
- package/src/build.ts +95 -33
- package/src/commands/__tests__/drift-sync.test.ts +252 -0
- package/src/commands/__tests__/scan-generate.test.ts +497 -45
- package/src/commands/enhance.ts +11 -35
- package/src/commands/init.ts +296 -193
- package/src/commands/scan-generate.ts +740 -139
- package/src/commands/scan.ts +37 -32
- package/src/commands/setup.ts +143 -52
- package/src/commands/snapshot.ts +197 -0
- package/src/commands/sync.ts +357 -0
- package/src/commands/validate.ts +43 -1
- package/src/core/component-extractor.test.ts +282 -0
- package/src/core/component-extractor.ts +1030 -0
- package/src/core/discovery.ts +93 -7
- package/src/service/enhance/props-extractor.ts +235 -13
- package/src/validators.ts +236 -0
- package/src/viewer/__tests__/viewer-integration.test.ts +85 -74
- package/src/viewer/server.ts +37 -22
- package/src/viewer/vite-plugin.ts +25 -9
- package/dist/chunk-5G3VZH43.js.map +0 -1
- package/dist/chunk-OQO55NKV.js.map +0 -1
- package/dist/chunk-WXSR2II7.js.map +0 -1
- package/dist/chunk-ZM4ZQZWZ.js.map +0 -1
- package/dist/init-NDQXUWDU.js +0 -796
- package/dist/init-NDQXUWDU.js.map +0 -1
- package/dist/scan-generate-SJAN5MVI.js +0 -691
- package/dist/scan-generate-SJAN5MVI.js.map +0 -1
- package/dist/viewer-DNMNC5VS.js.map +0 -1
- package/src/ai.ts +0 -266
- package/src/commands/init-framework.ts +0 -414
- package/src/mcp/bin.ts +0 -36
- package/src/migrate/bin.ts +0 -114
- package/src/theme/index.ts +0 -77
- package/src/viewer/__tests__/a11y-fixes.test.ts +0 -358
- package/src/viewer/__tests__/jsx-parser.test.ts +0 -502
- package/src/viewer/__tests__/render-utils.test.ts +0 -232
- package/src/viewer/__tests__/style-utils.test.ts +0 -404
- package/src/viewer/assets/fragments-logo.ts +0 -4
- package/src/viewer/assets/fragments_logo.png +0 -0
- package/src/viewer/bin.ts +0 -86
- package/src/viewer/cli/health.ts +0 -256
- package/src/viewer/cli/index.ts +0 -33
- package/src/viewer/cli/scan.ts +0 -124
- package/src/viewer/cli/utils.ts +0 -174
- package/src/viewer/components/AccessibilityPanel.tsx +0 -1457
- package/src/viewer/components/ActionCapture.tsx +0 -172
- package/src/viewer/components/ActionsPanel.tsx +0 -332
- package/src/viewer/components/AllVariantsPreview.tsx +0 -78
- package/src/viewer/components/App.tsx +0 -582
- package/src/viewer/components/BottomPanel.tsx +0 -288
- package/src/viewer/components/CodePanel.naming.test.tsx +0 -59
- package/src/viewer/components/CodePanel.tsx +0 -118
- package/src/viewer/components/CommandPalette.tsx +0 -392
- package/src/viewer/components/ComponentDocView.tsx +0 -164
- package/src/viewer/components/ComponentGraph.tsx +0 -380
- package/src/viewer/components/ComponentHeader.tsx +0 -88
- package/src/viewer/components/ContractPanel.tsx +0 -241
- package/src/viewer/components/EmptyVariantMessage.tsx +0 -54
- package/src/viewer/components/ErrorBoundary.tsx +0 -97
- package/src/viewer/components/FigmaEmbed.tsx +0 -238
- package/src/viewer/components/FragmentEditor.tsx +0 -525
- package/src/viewer/components/FragmentRenderer.tsx +0 -61
- package/src/viewer/components/HeaderSearch.tsx +0 -24
- package/src/viewer/components/HealthDashboard.tsx +0 -441
- package/src/viewer/components/HmrStatusIndicator.tsx +0 -61
- package/src/viewer/components/Icons.tsx +0 -479
- package/src/viewer/components/InteractionsPanel.tsx +0 -757
- package/src/viewer/components/IsolatedPreviewFrame.tsx +0 -346
- package/src/viewer/components/IsolatedRender.tsx +0 -113
- package/src/viewer/components/KeyboardShortcutsHelp.tsx +0 -53
- package/src/viewer/components/LandingPage.tsx +0 -421
- package/src/viewer/components/Layout.tsx +0 -27
- package/src/viewer/components/LeftSidebar.tsx +0 -472
- package/src/viewer/components/LoadErrorMessage.tsx +0 -102
- package/src/viewer/components/MultiViewportPreview.tsx +0 -522
- package/src/viewer/components/NoVariantsMessage.tsx +0 -59
- package/src/viewer/components/PanelShell.tsx +0 -161
- package/src/viewer/components/PerformancePanel.tsx +0 -304
- package/src/viewer/components/PreviewArea.tsx +0 -472
- package/src/viewer/components/PreviewAside.tsx +0 -168
- package/src/viewer/components/PreviewFrameHost.tsx +0 -303
- package/src/viewer/components/PreviewPane.tsx +0 -149
- package/src/viewer/components/PreviewToolbar.tsx +0 -80
- package/src/viewer/components/PropsEditor.tsx +0 -506
- package/src/viewer/components/PropsTable.tsx +0 -111
- package/src/viewer/components/RelationsSection.tsx +0 -88
- package/src/viewer/components/ResizablePanel.tsx +0 -271
- package/src/viewer/components/RightSidebar.tsx +0 -102
- package/src/viewer/components/RuntimeToolsRegistrar.tsx +0 -17
- package/src/viewer/components/ScreenshotButton.tsx +0 -90
- package/src/viewer/components/Sidebar.tsx +0 -169
- package/src/viewer/components/SkeletonLoader.tsx +0 -161
- package/src/viewer/components/ThemeProvider.tsx +0 -42
- package/src/viewer/components/Toast.tsx +0 -3
- package/src/viewer/components/TokenStylePanel.tsx +0 -699
- package/src/viewer/components/TopToolbar.tsx +0 -159
- package/src/viewer/components/UsageSection.tsx +0 -95
- package/src/viewer/components/VariantMatrix.tsx +0 -388
- package/src/viewer/components/VariantRenderer.tsx +0 -131
- package/src/viewer/components/VariantTabs.tsx +0 -40
- package/src/viewer/components/ViewerHeader.tsx +0 -69
- package/src/viewer/components/ViewerStateSync.tsx +0 -52
- package/src/viewer/components/ViewportSelector.tsx +0 -172
- package/src/viewer/components/WebMCPDevTools.tsx +0 -503
- package/src/viewer/components/WebMCPIntegration.tsx +0 -47
- package/src/viewer/components/WebMCPStatusIndicator.tsx +0 -60
- package/src/viewer/components/_future/CreatePage.tsx +0 -836
- package/src/viewer/components/viewer-utils.ts +0 -16
- package/src/viewer/composition-renderer.ts +0 -381
- package/src/viewer/constants/index.ts +0 -1
- package/src/viewer/constants/ui.ts +0 -166
- package/src/viewer/entry.tsx +0 -335
- package/src/viewer/hooks/index.ts +0 -2
- package/src/viewer/hooks/useA11yCache.ts +0 -383
- package/src/viewer/hooks/useA11yService.ts +0 -364
- package/src/viewer/hooks/useActions.ts +0 -138
- package/src/viewer/hooks/useAppState.ts +0 -147
- package/src/viewer/hooks/useCompiledFragments.ts +0 -42
- package/src/viewer/hooks/useFigmaIntegration.ts +0 -132
- package/src/viewer/hooks/useHmrStatus.ts +0 -109
- package/src/viewer/hooks/useKeyboardShortcuts.ts +0 -270
- package/src/viewer/hooks/usePreviewBridge.ts +0 -347
- package/src/viewer/hooks/useScrollSpy.ts +0 -78
- package/src/viewer/hooks/useUrlState.ts +0 -318
- package/src/viewer/hooks/useViewSettings.ts +0 -111
- package/src/viewer/index.html +0 -28
- package/src/viewer/intelligence/healthReport.ts +0 -505
- package/src/viewer/intelligence/styleDrift.ts +0 -340
- package/src/viewer/intelligence/usageScanner.ts +0 -309
- package/src/viewer/jsx-parser.ts +0 -486
- package/src/viewer/preview-frame-entry.tsx +0 -25
- package/src/viewer/preview-frame.html +0 -125
- package/src/viewer/public/favicon.ico +0 -0
- package/src/viewer/render-template.html +0 -68
- package/src/viewer/styles/globals.css +0 -278
- package/src/viewer/types/a11y.ts +0 -197
- package/src/viewer/utils/a11y-fixes.ts +0 -509
- package/src/viewer/utils/actionExport.ts +0 -372
- package/src/viewer/utils/colorSchemes.ts +0 -201
- package/src/viewer/utils/detectRelationships.ts +0 -256
- package/src/viewer/vendor/shared/src/ComponentDocContent.module.scss +0 -10
- package/src/viewer/vendor/shared/src/ComponentDocContent.module.scss.d.ts +0 -2
- package/src/viewer/vendor/shared/src/ComponentDocContent.tsx +0 -274
- package/src/viewer/vendor/shared/src/DocsHeaderBar.tsx +0 -129
- package/src/viewer/vendor/shared/src/DocsPageAsideHost.tsx +0 -89
- package/src/viewer/vendor/shared/src/DocsPageShell.tsx +0 -124
- package/src/viewer/vendor/shared/src/DocsSearchCommand.tsx +0 -99
- package/src/viewer/vendor/shared/src/DocsSidebarNav.tsx +0 -66
- package/src/viewer/vendor/shared/src/PropsTable.module.scss +0 -68
- package/src/viewer/vendor/shared/src/PropsTable.module.scss.d.ts +0 -2
- package/src/viewer/vendor/shared/src/PropsTable.tsx +0 -76
- package/src/viewer/vendor/shared/src/VariantPreviewCard.module.scss +0 -114
- package/src/viewer/vendor/shared/src/VariantPreviewCard.module.scss.d.ts +0 -2
- package/src/viewer/vendor/shared/src/VariantPreviewCard.tsx +0 -137
- package/src/viewer/vendor/shared/src/docs-data/index.ts +0 -32
- package/src/viewer/vendor/shared/src/docs-data/mcp-configs.ts +0 -72
- package/src/viewer/vendor/shared/src/docs-data/palettes.ts +0 -75
- package/src/viewer/vendor/shared/src/docs-data/setup-examples.ts +0 -55
- package/src/viewer/vendor/shared/src/docs-layout.scss +0 -28
- package/src/viewer/vendor/shared/src/docs-layout.scss.d.ts +0 -2
- package/src/viewer/vendor/shared/src/index.ts +0 -34
- package/src/viewer/vendor/shared/src/types.ts +0 -53
- package/src/viewer/webmcp/__tests__/analytics.test.ts +0 -108
- package/src/viewer/webmcp/analytics.ts +0 -165
- package/src/viewer/webmcp/index.ts +0 -3
- package/src/viewer/webmcp/posthog-bridge.ts +0 -39
- package/src/viewer/webmcp/runtime-tools.ts +0 -152
- package/src/viewer/webmcp/scan-utils.ts +0 -135
- package/src/viewer/webmcp/use-tool-analytics.ts +0 -69
- package/src/viewer/webmcp/viewer-state.ts +0 -45
- /package/dist/{discovery-NEOY4MPN.js.map → ai-client-I6MDWNYA.js.map} +0 -0
- /package/dist/{chunk-PW7QTQA6.js.map → chunk-4OC7FTJB.js.map} +0 -0
- /package/dist/{chunk-HRFUSSZI.js.map → chunk-AM4MRTMN.js.map} +0 -0
- /package/dist/{scan-CJF2DOQW.js.map → discovery-ZJQSXF56.js.map} +0 -0
- /package/dist/{generate-FBHSXR3D.js.map → generate-RJFS2JWA.js.map} +0 -0
- /package/dist/{service-TQYWY65E.js.map → scan-3PMCJ4RB.js.map} +0 -0
- /package/dist/{static-viewer-NUBFPKWH.js.map → service-VMGNJZ42.js.map} +0 -0
- /package/dist/{test-Z5LVO724.js.map → test-SI4NSHQX.js.map} +0 -0
- /package/dist/{tokens-CE46OTMD.js.map → tokens-T6SIVUT5.js.map} +0 -0
package/src/migrate/bin.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* CLI entry point for migration tool.
|
|
4
|
-
*
|
|
5
|
-
* Can be run standalone or integrated with the main fragments CLI.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { Command } from "commander";
|
|
9
|
-
import pc from "picocolors";
|
|
10
|
-
import { readFileSync } from "node:fs";
|
|
11
|
-
import { fileURLToPath } from "node:url";
|
|
12
|
-
import { dirname, join } from "node:path";
|
|
13
|
-
import { BRAND } from "../core/index.js";
|
|
14
|
-
import { migrate } from "./migrate.js";
|
|
15
|
-
|
|
16
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
17
|
-
const pkg = JSON.parse(readFileSync(join(__dirname, "../../package.json"), "utf-8")) as { version: string };
|
|
18
|
-
|
|
19
|
-
const program = new Command();
|
|
20
|
-
|
|
21
|
-
program
|
|
22
|
-
.name("fragments-migrate")
|
|
23
|
-
.description(`${BRAND.name} Storybook Migration Tool`)
|
|
24
|
-
.version(pkg.version);
|
|
25
|
-
|
|
26
|
-
program
|
|
27
|
-
.command("migrate")
|
|
28
|
-
.description("Migrate Storybook stories to Fragments")
|
|
29
|
-
.argument("<source>", "Source directory or file containing .stories.tsx files")
|
|
30
|
-
.option("-o, --output <dir>", "Output directory (default: same as source)")
|
|
31
|
-
.option("--dry-run", "Show what would be generated without writing files")
|
|
32
|
-
.option("--overwrite", "Overwrite existing fragment files")
|
|
33
|
-
.option("--report", "Generate HTML migration report")
|
|
34
|
-
.option("--report-path <path>", "Path for the migration report")
|
|
35
|
-
.option("-v, --verbose", "Verbose output")
|
|
36
|
-
.action(async (source, options) => {
|
|
37
|
-
try {
|
|
38
|
-
console.log(pc.cyan(`\n${BRAND.name} Migration Tool\n`));
|
|
39
|
-
console.log(pc.dim("Discovering Storybook files...\n"));
|
|
40
|
-
|
|
41
|
-
const report = await migrate({
|
|
42
|
-
from: source,
|
|
43
|
-
to: options.output,
|
|
44
|
-
dryRun: options.dryRun,
|
|
45
|
-
overwrite: options.overwrite,
|
|
46
|
-
report: options.report,
|
|
47
|
-
reportPath: options.reportPath,
|
|
48
|
-
verbose: options.verbose,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// Print results
|
|
52
|
-
if (report.totalStoryFiles === 0) {
|
|
53
|
-
console.log(pc.yellow("No story files found.\n"));
|
|
54
|
-
console.log(pc.dim("Looking for: *.stories.tsx, *.stories.ts, *.stories.jsx, *.stories.js"));
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
console.log(pc.dim(`Found ${report.totalStoryFiles} story file(s)\n`));
|
|
59
|
-
|
|
60
|
-
// Print each conversion
|
|
61
|
-
for (const result of report.results) {
|
|
62
|
-
if (result.success) {
|
|
63
|
-
console.log(`${pc.green("✓")} ${pc.bold(result.componentName)} → ${result.outputFile}`);
|
|
64
|
-
console.log(pc.dim(` ${result.variantCount} variant(s), ${result.todos.length} TODO(s)`));
|
|
65
|
-
} else {
|
|
66
|
-
console.log(`${pc.red("✗")} ${result.sourceFile}`);
|
|
67
|
-
for (const warning of result.warnings) {
|
|
68
|
-
console.log(pc.dim(` ${warning}`));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
console.log();
|
|
74
|
-
|
|
75
|
-
// Summary
|
|
76
|
-
if (report.successfulConversions > 0) {
|
|
77
|
-
console.log(pc.green(`✓ Converted ${report.successfulConversions} component(s)`));
|
|
78
|
-
}
|
|
79
|
-
if (report.failedConversions > 0) {
|
|
80
|
-
console.log(pc.red(`✗ Failed ${report.failedConversions} conversion(s)`));
|
|
81
|
-
}
|
|
82
|
-
console.log(pc.dim(` ${report.totalVariants} variant(s) total`));
|
|
83
|
-
console.log(pc.dim(` ${report.totalTodos} TODO(s) need attention`));
|
|
84
|
-
|
|
85
|
-
if (options.dryRun) {
|
|
86
|
-
console.log(pc.yellow("\n[Dry run - no files were written]"));
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (options.report) {
|
|
90
|
-
const reportPath = options.reportPath ?? `${source}/migration-report.html`;
|
|
91
|
-
console.log(pc.cyan(`\n📊 Report generated: ${reportPath}`));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Next steps
|
|
95
|
-
console.log(pc.dim("\n───────────────────────────────────────"));
|
|
96
|
-
console.log(pc.bold("\nNext steps:"));
|
|
97
|
-
console.log(` 1. Review generated ${BRAND.fileExtension} files`);
|
|
98
|
-
console.log(` 2. Fill in TODO comments (usage.when, usage.whenNot, etc.)`);
|
|
99
|
-
console.log(` 3. Run ${pc.cyan(`${BRAND.cliCommand} build`)} to compile`);
|
|
100
|
-
console.log(` 4. Run ${pc.cyan(`${BRAND.cliCommand} dev`)} to view your design system`);
|
|
101
|
-
console.log();
|
|
102
|
-
} catch (error) {
|
|
103
|
-
console.error(pc.red("Error:"), error instanceof Error ? error.message : error);
|
|
104
|
-
process.exit(1);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// Also support direct execution without subcommand
|
|
109
|
-
if (process.argv.length > 2 && !process.argv[2].startsWith("-") && process.argv[2] !== "migrate") {
|
|
110
|
-
// Insert "migrate" as the command
|
|
111
|
-
process.argv.splice(2, 0, "migrate");
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
program.parse();
|
package/src/theme/index.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Theme Customization Module
|
|
3
|
-
*
|
|
4
|
-
* Provides theme configuration, validation, serialization, and generation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// Types
|
|
8
|
-
export type {
|
|
9
|
-
ThemeConfig,
|
|
10
|
-
ThemeColors,
|
|
11
|
-
ThemeSurfaces,
|
|
12
|
-
ThemeText,
|
|
13
|
-
ThemeBorders,
|
|
14
|
-
ThemeTypography,
|
|
15
|
-
ThemeRadius,
|
|
16
|
-
ThemeShadows,
|
|
17
|
-
ThemeDarkMode,
|
|
18
|
-
TokenOutputFormat,
|
|
19
|
-
TokenGeneratorOptions,
|
|
20
|
-
TokenGeneratorResult,
|
|
21
|
-
PresetName,
|
|
22
|
-
ContrastPair,
|
|
23
|
-
ContrastWarning,
|
|
24
|
-
ContrastValidationResult,
|
|
25
|
-
} from "./types.js";
|
|
26
|
-
|
|
27
|
-
// Schema validation
|
|
28
|
-
export {
|
|
29
|
-
themeConfigSchema,
|
|
30
|
-
themeColorsSchema,
|
|
31
|
-
themeSurfacesSchema,
|
|
32
|
-
themeTextSchema,
|
|
33
|
-
themeBordersSchema,
|
|
34
|
-
themeTypographySchema,
|
|
35
|
-
themeRadiusSchema,
|
|
36
|
-
themeShadowsSchema,
|
|
37
|
-
themeDarkModeSchema,
|
|
38
|
-
validateThemeConfig,
|
|
39
|
-
} from "./schema.js";
|
|
40
|
-
export type { ThemeValidationResult } from "./schema.js";
|
|
41
|
-
|
|
42
|
-
// Serialization
|
|
43
|
-
export {
|
|
44
|
-
encodeThemeToUrl,
|
|
45
|
-
decodeThemeFromUrl,
|
|
46
|
-
compressTheme,
|
|
47
|
-
decompressTheme,
|
|
48
|
-
} from "./serializer.js";
|
|
49
|
-
|
|
50
|
-
// Generation
|
|
51
|
-
export {
|
|
52
|
-
generateScssTokens,
|
|
53
|
-
generateCssTokens,
|
|
54
|
-
generateTokenFiles,
|
|
55
|
-
validateContrast,
|
|
56
|
-
} from "./generator.js";
|
|
57
|
-
|
|
58
|
-
// Contrast utilities
|
|
59
|
-
export {
|
|
60
|
-
parseColor,
|
|
61
|
-
relativeLuminance,
|
|
62
|
-
contrastRatio,
|
|
63
|
-
meetsAA,
|
|
64
|
-
meetsAAA,
|
|
65
|
-
rgbToHex,
|
|
66
|
-
suggestFix,
|
|
67
|
-
} from "./contrast.js";
|
|
68
|
-
export type { RGB } from "./contrast.js";
|
|
69
|
-
|
|
70
|
-
// Presets
|
|
71
|
-
export {
|
|
72
|
-
DEFAULT_PRESET,
|
|
73
|
-
PRESETS,
|
|
74
|
-
getPreset,
|
|
75
|
-
listPresets,
|
|
76
|
-
isValidPresetName,
|
|
77
|
-
} from "./presets.js";
|
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
getStaticFix,
|
|
4
|
-
generateElementFix,
|
|
5
|
-
getImpactDescription,
|
|
6
|
-
getImpactColorClass,
|
|
7
|
-
extractWcagTags,
|
|
8
|
-
parseWcagTag,
|
|
9
|
-
} from '../utils/a11y-fixes.js';
|
|
10
|
-
import type { SerializedNode } from '../types/a11y.js';
|
|
11
|
-
|
|
12
|
-
function makeNode(overrides?: Partial<SerializedNode>): SerializedNode {
|
|
13
|
-
return {
|
|
14
|
-
html: '<div>test</div>',
|
|
15
|
-
target: ['div'],
|
|
16
|
-
...overrides,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function makeContrastNode(
|
|
21
|
-
fg: string,
|
|
22
|
-
bg: string,
|
|
23
|
-
ratio: number,
|
|
24
|
-
required: number
|
|
25
|
-
): SerializedNode {
|
|
26
|
-
return {
|
|
27
|
-
html: '<span style="color: ' + fg + '; background: ' + bg + '">text</span>',
|
|
28
|
-
target: ['span'],
|
|
29
|
-
any: [
|
|
30
|
-
{
|
|
31
|
-
id: 'color-contrast',
|
|
32
|
-
data: {
|
|
33
|
-
fgColor: fg,
|
|
34
|
-
bgColor: bg,
|
|
35
|
-
contrastRatio: ratio,
|
|
36
|
-
expectedContrastRatio: required,
|
|
37
|
-
fontSize: '16px',
|
|
38
|
-
fontWeight: 'normal',
|
|
39
|
-
},
|
|
40
|
-
impact: 'serious',
|
|
41
|
-
message: 'Element has insufficient color contrast',
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
describe('getStaticFix', () => {
|
|
48
|
-
const knownRules = [
|
|
49
|
-
'color-contrast',
|
|
50
|
-
'image-alt',
|
|
51
|
-
'button-name',
|
|
52
|
-
'link-name',
|
|
53
|
-
'label',
|
|
54
|
-
'aria-valid-attr',
|
|
55
|
-
'aria-valid-attr-value',
|
|
56
|
-
'aria-required-attr',
|
|
57
|
-
'heading-order',
|
|
58
|
-
'tabindex',
|
|
59
|
-
'duplicate-id',
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
for (const ruleId of knownRules) {
|
|
63
|
-
it(`returns fix for "${ruleId}"`, () => {
|
|
64
|
-
const fix = getStaticFix(ruleId);
|
|
65
|
-
expect(fix).not.toBeNull();
|
|
66
|
-
expect(fix!.whyItMatters).toBeTruthy();
|
|
67
|
-
expect(fix!.howToFix).toBeTruthy();
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
it('returns null for unknown rule', () => {
|
|
72
|
-
expect(getStaticFix('unknown-rule')).toBeNull();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('color-contrast has wcagCriterion 1.4.3 AA', () => {
|
|
76
|
-
const fix = getStaticFix('color-contrast');
|
|
77
|
-
expect(fix!.wcagCriterion).toBeDefined();
|
|
78
|
-
expect(fix!.wcagCriterion!.id).toBe('1.4.3');
|
|
79
|
-
expect(fix!.wcagCriterion!.level).toBe('AA');
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe('generateElementFix — color-contrast', () => {
|
|
84
|
-
it('valid colors → autoFixable: true with suggested hex', () => {
|
|
85
|
-
const node = makeContrastNode('#888888', '#ffffff', 3.54, 4.5);
|
|
86
|
-
const fix = generateElementFix('color-contrast', node);
|
|
87
|
-
expect(fix).not.toBeNull();
|
|
88
|
-
expect(fix!.autoFixable).toBe(true);
|
|
89
|
-
expect(fix!.explanation).toMatch(/#[0-9a-f]{6}/);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('includes ratio in explanation', () => {
|
|
93
|
-
const node = makeContrastNode('#888888', '#ffffff', 3.54, 4.5);
|
|
94
|
-
const fix = generateElementFix('color-contrast', node);
|
|
95
|
-
expect(fix!.explanation).toContain('3.54');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('includes required ratio in explanation', () => {
|
|
99
|
-
const node = makeContrastNode('#888888', '#ffffff', 3.54, 4.5);
|
|
100
|
-
const fix = generateElementFix('color-contrast', node);
|
|
101
|
-
expect(fix!.explanation).toContain('4.5');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('missing fg color → null', () => {
|
|
105
|
-
const node = makeNode({
|
|
106
|
-
any: [{
|
|
107
|
-
id: 'color-contrast',
|
|
108
|
-
data: { bgColor: '#ffffff' },
|
|
109
|
-
impact: 'serious',
|
|
110
|
-
message: 'Insufficient contrast',
|
|
111
|
-
}],
|
|
112
|
-
});
|
|
113
|
-
const fix = generateElementFix('color-contrast', node);
|
|
114
|
-
expect(fix).toBeNull();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('missing bg color → null', () => {
|
|
118
|
-
const node = makeNode({
|
|
119
|
-
any: [{
|
|
120
|
-
id: 'color-contrast',
|
|
121
|
-
data: { fgColor: '#888888' },
|
|
122
|
-
impact: 'serious',
|
|
123
|
-
message: 'Insufficient contrast',
|
|
124
|
-
}],
|
|
125
|
-
});
|
|
126
|
-
const fix = generateElementFix('color-contrast', node);
|
|
127
|
-
expect(fix).toBeNull();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('CSS variable colors → autoFixable: false', () => {
|
|
131
|
-
const node = makeNode({
|
|
132
|
-
html: '<span>text</span>',
|
|
133
|
-
any: [{
|
|
134
|
-
id: 'color-contrast',
|
|
135
|
-
data: {
|
|
136
|
-
fgColor: 'var(--text-color)',
|
|
137
|
-
bgColor: '#ffffff',
|
|
138
|
-
contrastRatio: 3.0,
|
|
139
|
-
expectedContrastRatio: 4.5,
|
|
140
|
-
},
|
|
141
|
-
impact: 'serious',
|
|
142
|
-
message: 'Insufficient contrast',
|
|
143
|
-
}],
|
|
144
|
-
});
|
|
145
|
-
const fix = generateElementFix('color-contrast', node);
|
|
146
|
-
expect(fix).not.toBeNull();
|
|
147
|
-
expect(fix!.autoFixable).toBe(false);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('no any data → null', () => {
|
|
151
|
-
const node = makeNode({ html: '<span>text</span>' });
|
|
152
|
-
const fix = generateElementFix('color-contrast', node);
|
|
153
|
-
expect(fix).toBeNull();
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
describe('generateElementFix — image-alt', () => {
|
|
158
|
-
it('missing alt → adds alt attribute', () => {
|
|
159
|
-
const node = makeNode({ html: '<img src="hero.jpg">' });
|
|
160
|
-
const fix = generateElementFix('image-alt', node);
|
|
161
|
-
expect(fix).not.toBeNull();
|
|
162
|
-
expect(fix!.fixedHtml).toContain('alt=');
|
|
163
|
-
expect(fix!.autoFixable).toBe(true);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('empty alt → replaces with descriptive text', () => {
|
|
167
|
-
const node = makeNode({ html: '<img src="photo.jpg" alt="">' });
|
|
168
|
-
const fix = generateElementFix('image-alt', node);
|
|
169
|
-
expect(fix).not.toBeNull();
|
|
170
|
-
expect(fix!.fixedHtml).toContain('alt="photo"');
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('derives alt text from filename', () => {
|
|
174
|
-
const node = makeNode({ html: '<img src="/images/user-profile.png">' });
|
|
175
|
-
const fix = generateElementFix('image-alt', node);
|
|
176
|
-
expect(fix!.fixedHtml).toContain('user profile');
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('handles camelCase filenames', () => {
|
|
180
|
-
const node = makeNode({ html: '<img src="teamPhoto.jpg">' });
|
|
181
|
-
const fix = generateElementFix('image-alt', node);
|
|
182
|
-
expect(fix!.fixedHtml).toContain('team photo');
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('autoFixable is true', () => {
|
|
186
|
-
const node = makeNode({ html: '<img src="test.jpg">' });
|
|
187
|
-
const fix = generateElementFix('image-alt', node);
|
|
188
|
-
expect(fix!.autoFixable).toBe(true);
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
describe('generateElementFix — button-name', () => {
|
|
193
|
-
it('SVG-only button → aria-label suggestion', () => {
|
|
194
|
-
const node = makeNode({
|
|
195
|
-
html: '<button><svg xmlns="http://www.w3.org/2000/svg"><path d="M10 10"/></svg></button>',
|
|
196
|
-
});
|
|
197
|
-
const fix = generateElementFix('button-name', node);
|
|
198
|
-
expect(fix).not.toBeNull();
|
|
199
|
-
expect(fix!.fixedHtml).toContain('aria-label');
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it('empty button → text suggestion', () => {
|
|
203
|
-
const node = makeNode({ html: '<button></button>' });
|
|
204
|
-
const fix = generateElementFix('button-name', node);
|
|
205
|
-
expect(fix).not.toBeNull();
|
|
206
|
-
expect(fix!.fixedHtml).toContain('[Button text]');
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it('autoFixable is false (requires human decision)', () => {
|
|
210
|
-
const node = makeNode({ html: '<button></button>' });
|
|
211
|
-
const fix = generateElementFix('button-name', node);
|
|
212
|
-
expect(fix!.autoFixable).toBe(false);
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
describe('generateElementFix — link-name', () => {
|
|
217
|
-
it('SVG-only link → aria-label suggestion', () => {
|
|
218
|
-
const node = makeNode({
|
|
219
|
-
html: '<a href="/"><svg xmlns="http://www.w3.org/2000/svg"><path d="M10 10"/></svg></a>',
|
|
220
|
-
});
|
|
221
|
-
const fix = generateElementFix('link-name', node);
|
|
222
|
-
expect(fix).not.toBeNull();
|
|
223
|
-
expect(fix!.fixedHtml).toContain('aria-label');
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it('empty link → text suggestion', () => {
|
|
227
|
-
const node = makeNode({ html: '<a href="/about"></a>' });
|
|
228
|
-
const fix = generateElementFix('link-name', node);
|
|
229
|
-
expect(fix).not.toBeNull();
|
|
230
|
-
expect(fix!.fixedHtml).toContain('[Link text]');
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('text link → explanation only (no fixedHtml change needed)', () => {
|
|
234
|
-
const node = makeNode({ html: '<a href="/about">Click here</a>' });
|
|
235
|
-
const fix = generateElementFix('link-name', node);
|
|
236
|
-
expect(fix).not.toBeNull();
|
|
237
|
-
expect(fix!.explanation).toContain('descriptive');
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it('autoFixable is false', () => {
|
|
241
|
-
const node = makeNode({ html: '<a href="/"></a>' });
|
|
242
|
-
const fix = generateElementFix('link-name', node);
|
|
243
|
-
expect(fix!.autoFixable).toBe(false);
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
describe('generateElementFix — label', () => {
|
|
248
|
-
it('input with id → label suggestion', () => {
|
|
249
|
-
const node = makeNode({ html: '<input type="email" id="email-input">' });
|
|
250
|
-
const fix = generateElementFix('label', node);
|
|
251
|
-
expect(fix).not.toBeNull();
|
|
252
|
-
expect(fix!.explanation).toContain('email-input');
|
|
253
|
-
expect(fix!.explanation).toContain('<label');
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it('input without id → adds id', () => {
|
|
257
|
-
const node = makeNode({ html: '<input type="text">' });
|
|
258
|
-
const fix = generateElementFix('label', node);
|
|
259
|
-
expect(fix).not.toBeNull();
|
|
260
|
-
expect(fix!.fixedHtml).toContain('id=');
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it('autoFixable is false', () => {
|
|
264
|
-
const node = makeNode({ html: '<input type="text">' });
|
|
265
|
-
const fix = generateElementFix('label', node);
|
|
266
|
-
expect(fix!.autoFixable).toBe(false);
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
describe('generateElementFix — unknown rule', () => {
|
|
271
|
-
it('heading-order → null (no generator registered)', () => {
|
|
272
|
-
const node = makeNode({ html: '<h4>Section</h4>' });
|
|
273
|
-
const fix = generateElementFix('heading-order', node);
|
|
274
|
-
expect(fix).toBeNull();
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
describe('getImpactDescription', () => {
|
|
279
|
-
it('critical → correct description', () => {
|
|
280
|
-
expect(getImpactDescription('critical')).toContain('completely block');
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
it('serious → correct description', () => {
|
|
284
|
-
expect(getImpactDescription('serious')).toContain('very difficult');
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('moderate → correct description', () => {
|
|
288
|
-
expect(getImpactDescription('moderate')).toContain('some difficulty');
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
it('minor → correct description', () => {
|
|
292
|
-
expect(getImpactDescription('minor')).toContain('slight inconvenience');
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
it('null → fallback description', () => {
|
|
296
|
-
expect(getImpactDescription(null)).toContain('not determined');
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
describe('getImpactColorClass', () => {
|
|
301
|
-
it('critical → error variant with danger color', () => {
|
|
302
|
-
const result = getImpactColorClass('critical');
|
|
303
|
-
expect(result.variant).toBe('error');
|
|
304
|
-
expect(result.color).toContain('danger');
|
|
305
|
-
expect(result.bg).toContain('danger');
|
|
306
|
-
expect(result.borderLeft).toContain('danger');
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
it('serious → error variant with danger color', () => {
|
|
310
|
-
const result = getImpactColorClass('serious');
|
|
311
|
-
expect(result.variant).toBe('error');
|
|
312
|
-
expect(result.color).toContain('danger');
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it('moderate → warning variant', () => {
|
|
316
|
-
const result = getImpactColorClass('moderate');
|
|
317
|
-
expect(result.variant).toBe('warning');
|
|
318
|
-
expect(result.color).toContain('warning');
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it('minor/null → info variant', () => {
|
|
322
|
-
const minorResult = getImpactColorClass('minor');
|
|
323
|
-
expect(minorResult.variant).toBe('info');
|
|
324
|
-
expect(minorResult.color).toContain('info');
|
|
325
|
-
const nullResult = getImpactColorClass(null);
|
|
326
|
-
expect(nullResult.variant).toBe('info');
|
|
327
|
-
expect(nullResult.color).toContain('info');
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
describe('extractWcagTags', () => {
|
|
332
|
-
it('filters wcag-prefixed tags only', () => {
|
|
333
|
-
const tags = ['wcag2a', 'wcag143', 'cat.color', 'best-practice'];
|
|
334
|
-
const result = extractWcagTags(tags);
|
|
335
|
-
expect(result).toEqual(['wcag2a', 'wcag143']);
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
it('returns empty when no wcag tags', () => {
|
|
339
|
-
const tags = ['best-practice', 'cat.aria'];
|
|
340
|
-
const result = extractWcagTags(tags);
|
|
341
|
-
expect(result).toEqual([]);
|
|
342
|
-
});
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
describe('parseWcagTag', () => {
|
|
346
|
-
it('wcag143 → 1.4.3', () => {
|
|
347
|
-
expect(parseWcagTag('wcag143')).toBe('1.4.3');
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
it('wcag111 → 1.1.1', () => {
|
|
351
|
-
expect(parseWcagTag('wcag111')).toBe('1.1.1');
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
it('non-matching → null', () => {
|
|
355
|
-
expect(parseWcagTag('wcag2a')).toBeNull();
|
|
356
|
-
expect(parseWcagTag('best-practice')).toBeNull();
|
|
357
|
-
});
|
|
358
|
-
});
|