@clhaas/palette-kit 0.1.8 → 0.3.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/.codex/skills/color-pipeline-implementer/SKILL.md +23 -0
- package/.codex/skills/commit-message-crafter/SKILL.md +63 -0
- package/.codex/skills/commit-message-crafter/references/benchmarks.md +20 -0
- package/.codex/skills/contrast-solver-helper/SKILL.md +20 -0
- package/.codex/skills/exporters-builder/SKILL.md +20 -0
- package/.codex/skills/markdownlint-writer/SKILL.md +32 -0
- package/.codex/skills/phase-implementation-runbook/SKILL.md +92 -0
- package/.codex/skills/type-contract-auditor/SKILL.md +21 -0
- package/.github/skills/review-guide/SKILL.md +23 -0
- package/.github/skills/review-guide/references/review-guide-v0.3.md +629 -0
- package/.markdownlint.json +4 -0
- package/AGENTS.md +16 -0
- package/CHANGELOG.md +34 -0
- package/README.md +79 -169
- package/biome.json +43 -0
- package/dist/cli/args.d.ts +12 -0
- package/dist/cli/args.js +56 -0
- package/dist/cli/args.test.js +22 -0
- package/dist/cli/codegen/__snapshots__/tokens.test.js.snap +87 -0
- package/dist/cli/codegen/tokens.d.ts +12 -0
- package/dist/cli/codegen/tokens.js +139 -0
- package/dist/cli/codegen/tokens.test.d.ts +1 -0
- package/dist/cli/codegen/tokens.test.js +51 -0
- package/dist/cli/config.d.ts +40 -0
- package/dist/cli/config.js +34 -0
- package/dist/cli/validate.d.ts +2 -0
- package/dist/cli/validate.js +33 -0
- package/dist/cli/validate.test.d.ts +1 -0
- package/dist/cli/validate.test.js +40 -0
- package/dist/cli.js +138 -140
- package/dist/contrast/apca.d.ts +2 -2
- package/dist/contrast/apca.js +14 -4
- package/dist/contrast/apca.test.d.ts +1 -0
- package/dist/contrast/apca.test.js +16 -0
- package/dist/contrast/index.d.ts +4 -0
- package/dist/contrast/index.js +4 -0
- package/dist/contrast/scoring.d.ts +4 -0
- package/dist/contrast/scoring.js +31 -0
- package/dist/contrast/scoring.test.d.ts +1 -0
- package/dist/contrast/scoring.test.js +148 -0
- package/dist/contrast/solver.d.ts +13 -0
- package/dist/contrast/solver.js +170 -0
- package/dist/contrast/solver.test.d.ts +1 -0
- package/dist/contrast/solver.test.js +75 -0
- package/dist/contrast/types.d.ts +17 -0
- package/dist/contrast/types.js +1 -0
- package/dist/contrast/utils.d.ts +4 -0
- package/dist/contrast/utils.js +18 -0
- package/dist/contrast/wcag2.d.ts +3 -0
- package/dist/contrast/wcag2.js +19 -0
- package/dist/contrast/wcag2.test.d.ts +1 -0
- package/dist/contrast/wcag2.test.js +17 -0
- package/dist/core/createTheme.d.ts +35 -0
- package/dist/core/createTheme.js +24 -0
- package/dist/core/dx-helpers.test.d.ts +1 -0
- package/dist/core/dx-helpers.test.js +61 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +2 -0
- package/dist/core/onSolid.test.d.ts +1 -0
- package/dist/core/onSolid.test.js +118 -0
- package/dist/core/qa.v1.test.d.ts +1 -0
- package/dist/core/qa.v1.test.js +112 -0
- package/dist/core/resolve.d.ts +3 -0
- package/dist/core/resolve.js +8 -0
- package/dist/core/resolve.test.d.ts +1 -0
- package/dist/core/resolve.test.js +89 -0
- package/dist/core/resolveMany.d.ts +8 -0
- package/dist/core/resolveMany.js +17 -0
- package/dist/core/tokenRegistry.d.ts +23 -0
- package/dist/core/tokenRegistry.js +83 -0
- package/dist/core/tokenRegistry.test.d.ts +1 -0
- package/dist/core/tokenRegistry.test.js +133 -0
- package/dist/engine/applyOperators.d.ts +3 -0
- package/dist/engine/applyOperators.js +23 -0
- package/dist/engine/context.d.ts +4 -0
- package/dist/engine/context.js +1 -0
- package/dist/engine/gamut.d.ts +13 -0
- package/dist/engine/gamut.js +101 -0
- package/dist/engine/gamut.test.d.ts +1 -0
- package/dist/engine/gamut.test.js +23 -0
- package/dist/engine/generateScale.d.ts +15 -0
- package/dist/engine/generateScale.js +29 -0
- package/dist/engine/generateScale.test.d.ts +1 -0
- package/dist/engine/generateScale.test.js +32 -0
- package/dist/engine/index.d.ts +8 -0
- package/dist/engine/index.js +4 -0
- package/dist/engine/normalize.d.ts +43 -0
- package/dist/engine/normalize.js +403 -0
- package/dist/engine/normalize.test.d.ts +1 -0
- package/dist/engine/normalize.test.js +136 -0
- package/dist/engine/onSolid.d.ts +3 -0
- package/dist/engine/onSolid.js +110 -0
- package/dist/engine/resolveBaseColor.d.ts +25 -0
- package/dist/engine/resolveBaseColor.js +127 -0
- package/dist/engine/resolveBaseColor.test.d.ts +1 -0
- package/dist/engine/resolveBaseColor.test.js +97 -0
- package/dist/export/__snapshots__/exportTheme.test.js.snap +74 -0
- package/dist/export/exportTheme.d.ts +47 -0
- package/dist/export/exportTheme.js +170 -0
- package/dist/export/exportTheme.test.d.ts +1 -0
- package/dist/export/exportTheme.test.js +118 -0
- package/dist/export/index.d.ts +1 -0
- package/dist/export/index.js +1 -0
- package/dist/export/serializeColor.d.ts +1 -0
- package/dist/export/serializeColor.js +1 -0
- package/dist/export/serializeColor.test.d.ts +1 -0
- package/dist/export/serializeColor.test.js +54 -0
- package/dist/export.d.ts +1 -0
- package/dist/export.js +1 -0
- package/dist/index.d.ts +3 -22
- package/dist/index.js +2 -18
- package/dist/operators/emphasis.d.ts +3 -0
- package/dist/operators/emphasis.js +113 -0
- package/dist/operators/emphasis.test.d.ts +1 -0
- package/dist/operators/emphasis.test.js +69 -0
- package/dist/operators/index.d.ts +3 -0
- package/dist/operators/index.js +2 -0
- package/dist/operators/state.d.ts +3 -0
- package/dist/operators/state.js +102 -0
- package/dist/operators/state.test.d.ts +1 -0
- package/dist/operators/state.test.js +48 -0
- package/dist/operators/types.d.ts +13 -0
- package/dist/operators/types.js +1 -0
- package/dist/operators/utils.d.ts +16 -0
- package/dist/operators/utils.js +23 -0
- package/dist/presets/curves.d.ts +28 -0
- package/dist/presets/curves.js +145 -0
- package/dist/presets/index.d.ts +2 -0
- package/dist/presets/index.js +1 -0
- package/dist/presets/tokens/index.d.ts +3 -0
- package/dist/presets/tokens/index.js +3 -0
- package/dist/presets/tokens/minimal-ui.d.ts +6 -0
- package/dist/presets/tokens/minimal-ui.js +53 -0
- package/dist/presets/tokens/modern-ui.d.ts +5 -0
- package/dist/presets/tokens/modern-ui.js +83 -0
- package/dist/presets/tokens/presets.test.d.ts +1 -0
- package/dist/presets/tokens/presets.test.js +31 -0
- package/dist/presets/tokens/radixLike-ui.d.ts +6 -0
- package/dist/presets/tokens/radixLike-ui.js +77 -0
- package/dist/serialize/index.d.ts +1 -0
- package/dist/serialize/index.js +1 -0
- package/dist/serialize/normalizeOutput.d.ts +6 -0
- package/dist/serialize/normalizeOutput.js +45 -0
- package/dist/serialize/serializeColor.d.ts +21 -0
- package/dist/serialize/serializeColor.js +178 -0
- package/dist/serialize/serializeResolved.test.d.ts +1 -0
- package/dist/serialize/serializeResolved.test.js +45 -0
- package/dist/serialize.d.ts +1 -0
- package/dist/serialize.js +1 -0
- package/dist/types/index.d.ts +187 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/clamp.d.ts +1 -0
- package/dist/utils/clamp.js +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/lerp.d.ts +1 -0
- package/dist/utils/lerp.js +1 -0
- package/dist/utils/parseColor.d.ts +6 -0
- package/dist/utils/parseColor.js +67 -0
- package/dist/utils/parseColor.test.d.ts +1 -0
- package/dist/utils/parseColor.test.js +51 -0
- package/dist/utils/smoothstep.d.ts +1 -0
- package/dist/utils/smoothstep.js +5 -0
- package/package.json +19 -12
- package/planning/phase-10-review.md +550 -0
- package/planning/phase-7-review.md +411 -0
- package/planning/phase-8-review.md +669 -0
- package/planning/phase-9-review.md +564 -0
- package/planning/roadmap-v0.3.md +284 -0
- package/planning/spec-serializer-v0.3.md +324 -0
- package/planning/spec-v0.3.md +305 -0
- package/src/cli/args.test.ts +28 -0
- package/src/cli/args.ts +66 -0
- package/src/cli/codegen/__snapshots__/tokens.test.ts.snap +87 -0
- package/src/cli/codegen/tokens.test.ts +61 -0
- package/src/cli/codegen/tokens.ts +191 -0
- package/src/cli/config.ts +71 -0
- package/src/cli/validate.test.ts +49 -0
- package/src/cli/validate.ts +38 -0
- package/src/cli.ts +183 -0
- package/src/contrast/apca.test.ts +20 -0
- package/src/contrast/apca.ts +26 -0
- package/src/contrast/index.ts +4 -0
- package/src/contrast/scoring.test.ts +188 -0
- package/src/contrast/scoring.ts +48 -0
- package/src/contrast/solver.test.ts +147 -0
- package/src/contrast/solver.ts +235 -0
- package/src/contrast/types.ts +20 -0
- package/src/contrast/utils.ts +28 -0
- package/src/contrast/wcag2.test.ts +21 -0
- package/src/contrast/wcag2.ts +24 -0
- package/src/core/createTheme.ts +78 -0
- package/src/core/dx-helpers.test.ts +82 -0
- package/src/core/index.ts +7 -0
- package/src/core/onSolid.test.ts +146 -0
- package/src/core/qa.v1.test.ts +149 -0
- package/src/core/resolve.test.ts +99 -0
- package/src/core/resolve.ts +11 -0
- package/src/core/resolveMany.ts +22 -0
- package/src/core/tokenRegistry.test.ts +153 -0
- package/src/core/tokenRegistry.ts +114 -0
- package/src/engine/applyOperators.ts +32 -0
- package/src/engine/context.ts +8 -0
- package/src/engine/gamut.test.ts +30 -0
- package/src/engine/gamut.ts +144 -0
- package/src/engine/generateScale.test.ts +46 -0
- package/src/engine/generateScale.ts +48 -0
- package/src/engine/index.ts +8 -0
- package/src/engine/normalize.test.ts +222 -0
- package/src/engine/normalize.ts +550 -0
- package/src/engine/onSolid.ts +178 -0
- package/src/engine/resolveBaseColor.test.ts +117 -0
- package/src/engine/resolveBaseColor.ts +203 -0
- package/src/export/__snapshots__/exportTheme.test.ts.snap +74 -0
- package/src/export/exportTheme.test.ts +144 -0
- package/src/export/exportTheme.ts +251 -0
- package/src/export/index.ts +1 -0
- package/src/export/serializeColor.test.ts +73 -0
- package/src/export/serializeColor.ts +1 -0
- package/src/export.ts +1 -0
- package/src/index.ts +3 -0
- package/src/operators/emphasis.test.ts +85 -0
- package/src/operators/emphasis.ts +132 -0
- package/src/operators/index.ts +3 -0
- package/src/operators/state.test.ts +66 -0
- package/src/operators/state.ts +122 -0
- package/src/operators/types.ts +14 -0
- package/src/operators/utils.ts +44 -0
- package/src/presets/curves.ts +168 -0
- package/src/presets/index.ts +2 -0
- package/src/presets/tokens/index.ts +3 -0
- package/src/presets/tokens/minimal-ui.ts +55 -0
- package/src/presets/tokens/modern-ui.ts +85 -0
- package/src/presets/tokens/presets.test.ts +46 -0
- package/src/presets/tokens/radixLike-ui.ts +79 -0
- package/src/serialize/index.ts +1 -0
- package/src/serialize/normalizeOutput.ts +63 -0
- package/src/serialize/serializeColor.ts +260 -0
- package/src/serialize/serializeResolved.test.ts +57 -0
- package/src/serialize.ts +1 -0
- package/src/types/index.ts +207 -0
- package/src/utils/clamp.ts +2 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/lerp.ts +1 -0
- package/src/utils/parseColor.test.ts +66 -0
- package/src/utils/parseColor.ts +87 -0
- package/src/utils/smoothstep.ts +6 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +15 -0
- package/dist/alpha/generateAlphaScale.d.ts +0 -5
- package/dist/alpha/generateAlphaScale.js +0 -34
- package/dist/contrast/onSolid.d.ts +0 -6
- package/dist/contrast/onSolid.js +0 -28
- package/dist/contrast/solveText.d.ts +0 -2
- package/dist/contrast/solveText.js +0 -31
- package/dist/createTheme.d.ts +0 -38
- package/dist/createTheme.js +0 -148
- package/dist/data/radixSeeds.d.ts +0 -3
- package/dist/data/radixSeeds.js +0 -34
- package/dist/diagnostics/analyzeScale.d.ts +0 -2
- package/dist/diagnostics/analyzeScale.js +0 -7
- package/dist/diagnostics/analyzeTheme.d.ts +0 -2
- package/dist/diagnostics/analyzeTheme.js +0 -35
- package/dist/diagnostics/warnings.d.ts +0 -2
- package/dist/diagnostics/warnings.js +0 -20
- package/dist/engine/curves.d.ts +0 -9
- package/dist/engine/curves.js +0 -48
- package/dist/engine/oklch.d.ts +0 -8
- package/dist/engine/oklch.js +0 -40
- package/dist/engine/templates.d.ts +0 -14
- package/dist/engine/templates.js +0 -45
- package/dist/exporters/selectColorMode.d.ts +0 -2
- package/dist/exporters/selectColorMode.js +0 -19
- package/dist/exporters/toCssVars.d.ts +0 -13
- package/dist/exporters/toCssVars.js +0 -108
- package/dist/exporters/toJson.d.ts +0 -3
- package/dist/exporters/toJson.js +0 -25
- package/dist/exporters/toReactNative.d.ts +0 -54
- package/dist/exporters/toReactNative.js +0 -33
- package/dist/exporters/toTailwind.d.ts +0 -17
- package/dist/exporters/toTailwind.js +0 -111
- package/dist/exporters/toTs.d.ts +0 -3
- package/dist/exporters/toTs.js +0 -43
- package/dist/generateScale.d.ts +0 -48
- package/dist/generateScale.js +0 -274
- package/dist/overlays/generateOverlayScale.d.ts +0 -2
- package/dist/overlays/generateOverlayScale.js +0 -34
- package/dist/text/generateTextScale.d.ts +0 -8
- package/dist/text/generateTextScale.js +0 -18
- package/dist/text/resolveOnBgText.d.ts +0 -9
- package/dist/text/resolveOnBgText.js +0 -28
- package/dist/tokens/presetRadixLikeUi.d.ts +0 -5
- package/dist/tokens/presetRadixLikeUi.js +0 -55
- package/dist/types.d.ts +0 -69
- /package/dist/{types.js → cli/args.test.d.ts} +0 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { normalizeQuery } from "./normalize.js";
|
|
4
|
+
|
|
5
|
+
describe("normalizeQuery", () => {
|
|
6
|
+
it("applies defaults", () => {
|
|
7
|
+
const result = normalizeQuery({ role: "text.primary", surface: "surface" });
|
|
8
|
+
|
|
9
|
+
expect(result.usage).toBe("text");
|
|
10
|
+
expect(result.context).toBe("light");
|
|
11
|
+
expect(result.surface).toBe("surface");
|
|
12
|
+
expect(result.state).toBe("default");
|
|
13
|
+
expect(result.emphasis).toBe("default");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("throws when role is missing", () => {
|
|
17
|
+
expect(() => normalizeQuery({} as never)).toThrowError(/role/i);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("applies output defaults", () => {
|
|
21
|
+
const result = normalizeQuery({ role: "text.primary", surface: "surface" });
|
|
22
|
+
|
|
23
|
+
expect(result.output.preferSpace).toBe("oklch");
|
|
24
|
+
expect(result.output.gamutMapping).toBe("preferP3ThenCompress");
|
|
25
|
+
expect(result.output.precision).toMatchObject({ l: 1, c: 3, h: 1 });
|
|
26
|
+
expect(result.output.strict).toBe(false);
|
|
27
|
+
expect(result.output.includeMeta).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("infers usage from role prefixes", () => {
|
|
31
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
expect(normalizeQuery({ role: "icon.primary" }).usage).toBe("icon");
|
|
35
|
+
expect(normalizeQuery({ role: "border.muted" }).usage).toBe("border");
|
|
36
|
+
expect(normalizeQuery({ role: "bg.canvas" }).usage).toBe("bg");
|
|
37
|
+
expect(normalizeQuery({ role: "ring.focus" }).usage).toBe("ring");
|
|
38
|
+
expect(normalizeQuery({ role: "chart.axis.stroke" }).usage).toBe("stroke");
|
|
39
|
+
expect(normalizeQuery({ role: "chart.fill.primary" }).usage).toBe("fill");
|
|
40
|
+
expect(normalizeQuery({ role: "chart.grid.muted" }).usage).toBe("border");
|
|
41
|
+
expect(normalizeQuery({ role: "chart.label" }).usage).toBe("text");
|
|
42
|
+
} finally {
|
|
43
|
+
warnSpy.mockRestore();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("infers surface when obvious", () => {
|
|
48
|
+
expect(normalizeQuery({ role: "bg.app" }).surface).toBe("app");
|
|
49
|
+
expect(normalizeQuery({ role: "bg.surface" }).surface).toBe("surface");
|
|
50
|
+
expect(normalizeQuery({ role: "app.bg", usage: "bg" }).surface).toBe("app");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("infers variant from role token", () => {
|
|
54
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
expect(
|
|
58
|
+
normalizeQuery({ role: "success.bg", usage: "bg", surface: "surface" }).variant,
|
|
59
|
+
).toBe("success");
|
|
60
|
+
expect(
|
|
61
|
+
normalizeQuery({ role: "warning.text", usage: "text", surface: "surface" }).variant,
|
|
62
|
+
).toBe("warning");
|
|
63
|
+
expect(
|
|
64
|
+
normalizeQuery({ role: "danger.border", usage: "border", surface: "surface" }).variant,
|
|
65
|
+
).toBe("danger");
|
|
66
|
+
expect(
|
|
67
|
+
normalizeQuery({ role: "category:sales.fill", usage: "fill", surface: "surface" }).variant,
|
|
68
|
+
).toBe("category:sales");
|
|
69
|
+
expect(
|
|
70
|
+
normalizeQuery({
|
|
71
|
+
role: "chart:revenue.stroke",
|
|
72
|
+
usage: "stroke",
|
|
73
|
+
surface: "surface",
|
|
74
|
+
}).variant,
|
|
75
|
+
).toBe("chart:revenue");
|
|
76
|
+
|
|
77
|
+
expect(
|
|
78
|
+
normalizeQuery({ role: "text.primary", usage: "text", surface: "surface" }).variant,
|
|
79
|
+
).toBeUndefined();
|
|
80
|
+
} finally {
|
|
81
|
+
warnSpy.mockRestore();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("requires usage when strict and inference fails", () => {
|
|
86
|
+
expect(() =>
|
|
87
|
+
normalizeQuery({ role: "brand.primary", output: { strict: true } }),
|
|
88
|
+
).toThrowError(/Provide usage explicitly/i);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("warns when usage cannot be inferred in non-strict mode", () => {
|
|
92
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
93
|
+
|
|
94
|
+
expect(normalizeQuery({ role: "brand.primary" }).usage).toBe("bg");
|
|
95
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
96
|
+
expect.stringContaining('Defaulting usage to "bg"'),
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
warnSpy.mockRestore();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("requires surface when strict and inference fails", () => {
|
|
103
|
+
expect(() =>
|
|
104
|
+
normalizeQuery({ role: "text.primary", output: { strict: true } }),
|
|
105
|
+
).toThrowError(/Provide surface explicitly/i);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("warns when surface cannot be inferred in non-strict mode", () => {
|
|
109
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
110
|
+
|
|
111
|
+
expect(normalizeQuery({ role: "text.primary" }).surface).toBe("surface");
|
|
112
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
113
|
+
expect.stringContaining('Defaulting surface to "surface"'),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
warnSpy.mockRestore();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("validates background hint color values", () => {
|
|
120
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
121
|
+
|
|
122
|
+
expect(
|
|
123
|
+
normalizeQuery({ role: "bg.canvas", surface: "surface", on: { kind: "color", value: "#fff" } })
|
|
124
|
+
.on,
|
|
125
|
+
).toEqual({ kind: "color", value: "#fff" });
|
|
126
|
+
expect(
|
|
127
|
+
normalizeQuery({
|
|
128
|
+
role: "bg.canvas",
|
|
129
|
+
surface: "surface",
|
|
130
|
+
on: { kind: "color", value: "oklch(62% 0.18 265)" },
|
|
131
|
+
}).on,
|
|
132
|
+
).toEqual({ kind: "color", value: "oklch(62% 0.18 265)" });
|
|
133
|
+
expect(
|
|
134
|
+
normalizeQuery({
|
|
135
|
+
role: "bg.canvas",
|
|
136
|
+
surface: "surface",
|
|
137
|
+
on: { kind: "color", value: "color(display-p3 1 0.5 0.25)" },
|
|
138
|
+
}).on,
|
|
139
|
+
).toEqual({ kind: "color", value: "color(display-p3 1 0.5 0.25)" });
|
|
140
|
+
expect(
|
|
141
|
+
normalizeQuery({ role: "bg.canvas", surface: "surface", on: { kind: "color", value: "banana" } })
|
|
142
|
+
.on,
|
|
143
|
+
).toEqual({ kind: "color", value: "banana" });
|
|
144
|
+
|
|
145
|
+
expect(warnSpy).toHaveBeenCalledTimes(3);
|
|
146
|
+
warnSpy.mockRestore();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("normalizes nested background hints", () => {
|
|
150
|
+
expect(
|
|
151
|
+
normalizeQuery({
|
|
152
|
+
role: "bg.canvas",
|
|
153
|
+
surface: "surface",
|
|
154
|
+
on: { kind: "role", role: " text.primary " },
|
|
155
|
+
})
|
|
156
|
+
.on,
|
|
157
|
+
).toEqual({ kind: "role", role: "text.primary" });
|
|
158
|
+
expect(
|
|
159
|
+
normalizeQuery({ role: "bg.canvas", surface: "surface", on: { kind: "auto" } }).on,
|
|
160
|
+
).toEqual({
|
|
161
|
+
kind: "auto",
|
|
162
|
+
});
|
|
163
|
+
expect(() =>
|
|
164
|
+
normalizeQuery({ role: "bg.canvas", surface: "surface", on: { kind: "color", value: " " } }),
|
|
165
|
+
).toThrowError(/color value is required/i);
|
|
166
|
+
expect(() =>
|
|
167
|
+
normalizeQuery({
|
|
168
|
+
role: "bg.canvas",
|
|
169
|
+
surface: "surface",
|
|
170
|
+
on: { kind: "color", value: "banana" },
|
|
171
|
+
output: { strict: true },
|
|
172
|
+
}),
|
|
173
|
+
).toThrowError(/background hint color value/i);
|
|
174
|
+
expect(() =>
|
|
175
|
+
normalizeQuery({ role: "bg.canvas", surface: "surface", on: { kind: "nope" } as never }),
|
|
176
|
+
).toThrowError(/background hint kind/i);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("validates contrast requirements", () => {
|
|
180
|
+
expect(
|
|
181
|
+
normalizeQuery({ role: "text.primary", contrast: { model: "apca", targetLc: 75 } })
|
|
182
|
+
.contrast,
|
|
183
|
+
).toEqual({ model: "apca", targetLc: 75 });
|
|
184
|
+
expect(
|
|
185
|
+
normalizeQuery({ role: "text.primary", contrast: { model: "wcag2", minRatio: 4.5 } })
|
|
186
|
+
.contrast,
|
|
187
|
+
).toEqual({ model: "wcag2", minRatio: 4.5 });
|
|
188
|
+
expect(
|
|
189
|
+
normalizeQuery({ role: "text.primary", contrast: { model: "none" } }).contrast,
|
|
190
|
+
).toEqual({ model: "none" });
|
|
191
|
+
expect(() =>
|
|
192
|
+
normalizeQuery({ role: "text.primary", contrast: { model: "apca" } as never }),
|
|
193
|
+
).toThrowError(/targetLc/i);
|
|
194
|
+
expect(() =>
|
|
195
|
+
normalizeQuery({ role: "text.primary", contrast: { model: "wcag2" } as never }),
|
|
196
|
+
).toThrowError(/minRatio.*ratio/i);
|
|
197
|
+
expect(() =>
|
|
198
|
+
normalizeQuery({ role: "text.primary", contrast: { model: "wcag2", minRatio: NaN } as never }),
|
|
199
|
+
).toThrowError(/minRatio must be a number/i);
|
|
200
|
+
expect(() =>
|
|
201
|
+
normalizeQuery({ role: "text.primary", contrast: { model: "nope" } as never }),
|
|
202
|
+
).toThrowError(/contrast model/i);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("validates alpha strategies", () => {
|
|
206
|
+
expect(
|
|
207
|
+
normalizeQuery({ role: "bg.canvas", alpha: { mode: "none" } }).alpha,
|
|
208
|
+
).toEqual({ mode: "none" });
|
|
209
|
+
expect(
|
|
210
|
+
normalizeQuery({ role: "bg.canvas", alpha: { mode: "fixed", alpha: 0.5 } }).alpha,
|
|
211
|
+
).toEqual({ mode: "fixed", alpha: 0.5 });
|
|
212
|
+
expect(
|
|
213
|
+
normalizeQuery({ role: "bg.canvas", alpha: { mode: "solveOnBackground" } }).alpha,
|
|
214
|
+
).toEqual({ mode: "solveOnBackground" });
|
|
215
|
+
expect(() =>
|
|
216
|
+
normalizeQuery({ role: "bg.canvas", alpha: { mode: "fixed" } as never }),
|
|
217
|
+
).toThrowError(/fixed alpha/i);
|
|
218
|
+
expect(() =>
|
|
219
|
+
normalizeQuery({ role: "bg.canvas", alpha: { mode: "nope" } as never }),
|
|
220
|
+
).toThrowError(/alpha strategy mode/i);
|
|
221
|
+
});
|
|
222
|
+
});
|