@clhaas/palette-kit 0.3.0 → 0.4.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/CHANGELOG.md +25 -0
- package/README.md +80 -87
- package/dist/contrast/contrast.d.ts +16 -0
- package/dist/contrast/contrast.js +102 -0
- package/dist/core/intent-registry.d.ts +11 -0
- package/dist/core/intent-registry.js +70 -0
- package/dist/core/oklch.d.ts +16 -0
- package/dist/core/oklch.js +56 -0
- package/dist/create-palette-kit.d.ts +9 -0
- package/dist/create-palette-kit.js +67 -0
- package/dist/engine/context/context.d.ts +13 -0
- package/dist/engine/context/context.js +37 -0
- package/dist/engine/level/curves.d.ts +17 -0
- package/dist/engine/level/curves.js +49 -0
- package/dist/engine/level/level.d.ts +4 -0
- package/dist/engine/level/level.js +13 -0
- package/dist/engine/relation/relation.d.ts +105 -0
- package/dist/engine/relation/relation.js +137 -0
- package/dist/engine/resolve/resolve.d.ts +36 -0
- package/dist/engine/resolve/resolve.js +116 -0
- package/dist/engine/state/state.d.ts +46 -0
- package/dist/engine/state/state.js +68 -0
- package/dist/engine/usage/fill.d.ts +9 -0
- package/dist/engine/usage/fill.js +9 -0
- package/dist/engine/usage/lines.d.ts +9 -0
- package/dist/engine/usage/lines.js +9 -0
- package/dist/engine/usage/overlays.d.ts +9 -0
- package/dist/engine/usage/overlays.js +9 -0
- package/dist/engine/usage/strategy.d.ts +56 -0
- package/dist/engine/usage/strategy.js +30 -0
- package/dist/engine/usage/visualVocabulary.d.ts +9 -0
- package/dist/engine/usage/visualVocabulary.js +9 -0
- package/dist/export/serialize.d.ts +14 -0
- package/dist/export/serialize.js +89 -0
- package/dist/export/types.d.ts +37 -0
- package/dist/export/types.js +31 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/operators/convert.d.ts +32 -0
- package/dist/operators/convert.js +80 -0
- package/dist/presets/presets.d.ts +95 -0
- package/dist/presets/presets.js +308 -0
- package/dist/types/index.d.ts +111 -187
- package/dist/utils/errors/errors.d.ts +17 -0
- package/dist/utils/errors/errors.js +22 -0
- package/docs/API.md +167 -0
- package/docs/Alpha.md +14 -0
- package/docs/Architecture.md +56 -0
- package/docs/CLI.md +22 -0
- package/docs/Concepts.md +73 -0
- package/docs/Config.md +144 -0
- package/docs/Diagnostics.md +22 -0
- package/docs/Exporters.md +33 -0
- package/docs/FAQ.md +59 -0
- package/docs/Migration.md +61 -0
- package/docs/Overlays.md +33 -0
- package/docs/README.md +60 -0
- package/docs/Text.md +41 -0
- package/docs/Tokens.md +42 -0
- package/docs/Usage-JSON.md +39 -0
- package/docs/Usage-ReactNative.md +63 -0
- package/docs/Usage-Web.md +66 -0
- package/docs/Validation.md +97 -0
- package/docs/Why.md +37 -0
- package/docs/_api-surface.md +53 -0
- package/docs/snippets/serialize-oklch.md +9 -0
- package/docs/spec.md +98 -0
- package/package.json +74 -59
- package/.codex/skills/color-pipeline-implementer/SKILL.md +0 -23
- package/.codex/skills/commit-message-crafter/SKILL.md +0 -63
- package/.codex/skills/commit-message-crafter/references/benchmarks.md +0 -20
- package/.codex/skills/contrast-solver-helper/SKILL.md +0 -20
- package/.codex/skills/exporters-builder/SKILL.md +0 -20
- package/.codex/skills/markdownlint-writer/SKILL.md +0 -32
- package/.codex/skills/phase-implementation-runbook/SKILL.md +0 -92
- package/.codex/skills/type-contract-auditor/SKILL.md +0 -21
- package/.github/skills/review-guide/SKILL.md +0 -23
- package/.github/skills/review-guide/references/review-guide-v0.3.md +0 -629
- package/.markdownlint.json +0 -4
- package/AGENTS.md +0 -16
- package/biome.json +0 -43
- package/dist/cli/args.d.ts +0 -12
- package/dist/cli/args.js +0 -56
- package/dist/cli/args.test.d.ts +0 -1
- package/dist/cli/args.test.js +0 -22
- package/dist/cli/codegen/__snapshots__/tokens.test.js.snap +0 -87
- package/dist/cli/codegen/tokens.d.ts +0 -12
- package/dist/cli/codegen/tokens.js +0 -139
- package/dist/cli/codegen/tokens.test.d.ts +0 -1
- package/dist/cli/codegen/tokens.test.js +0 -51
- package/dist/cli/config.d.ts +0 -40
- package/dist/cli/config.js +0 -34
- package/dist/cli/validate.d.ts +0 -2
- package/dist/cli/validate.js +0 -33
- package/dist/cli/validate.test.d.ts +0 -1
- package/dist/cli/validate.test.js +0 -40
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -148
- package/dist/contrast/apca.d.ts +0 -2
- package/dist/contrast/apca.js +0 -15
- package/dist/contrast/apca.test.d.ts +0 -1
- package/dist/contrast/apca.test.js +0 -16
- package/dist/contrast/index.d.ts +0 -4
- package/dist/contrast/index.js +0 -4
- package/dist/contrast/scoring.d.ts +0 -4
- package/dist/contrast/scoring.js +0 -31
- package/dist/contrast/scoring.test.d.ts +0 -1
- package/dist/contrast/scoring.test.js +0 -148
- package/dist/contrast/solver.d.ts +0 -13
- package/dist/contrast/solver.js +0 -170
- package/dist/contrast/solver.test.d.ts +0 -1
- package/dist/contrast/solver.test.js +0 -75
- package/dist/contrast/types.d.ts +0 -17
- package/dist/contrast/types.js +0 -1
- package/dist/contrast/utils.d.ts +0 -4
- package/dist/contrast/utils.js +0 -18
- package/dist/contrast/wcag2.d.ts +0 -3
- package/dist/contrast/wcag2.js +0 -19
- package/dist/contrast/wcag2.test.d.ts +0 -1
- package/dist/contrast/wcag2.test.js +0 -17
- package/dist/core/createTheme.d.ts +0 -35
- package/dist/core/createTheme.js +0 -24
- package/dist/core/dx-helpers.test.d.ts +0 -1
- package/dist/core/dx-helpers.test.js +0 -61
- package/dist/core/index.d.ts +0 -2
- package/dist/core/index.js +0 -2
- package/dist/core/onSolid.test.d.ts +0 -1
- package/dist/core/onSolid.test.js +0 -118
- package/dist/core/qa.v1.test.d.ts +0 -1
- package/dist/core/qa.v1.test.js +0 -112
- package/dist/core/resolve.d.ts +0 -3
- package/dist/core/resolve.js +0 -8
- package/dist/core/resolve.test.d.ts +0 -1
- package/dist/core/resolve.test.js +0 -89
- package/dist/core/resolveMany.d.ts +0 -8
- package/dist/core/resolveMany.js +0 -17
- package/dist/core/tokenRegistry.d.ts +0 -23
- package/dist/core/tokenRegistry.js +0 -83
- package/dist/core/tokenRegistry.test.d.ts +0 -1
- package/dist/core/tokenRegistry.test.js +0 -133
- package/dist/engine/applyOperators.d.ts +0 -3
- package/dist/engine/applyOperators.js +0 -23
- package/dist/engine/context.d.ts +0 -4
- package/dist/engine/context.js +0 -1
- package/dist/engine/gamut.d.ts +0 -13
- package/dist/engine/gamut.js +0 -101
- package/dist/engine/gamut.test.d.ts +0 -1
- package/dist/engine/gamut.test.js +0 -23
- package/dist/engine/generateScale.d.ts +0 -15
- package/dist/engine/generateScale.js +0 -29
- package/dist/engine/generateScale.test.d.ts +0 -1
- package/dist/engine/generateScale.test.js +0 -32
- package/dist/engine/index.d.ts +0 -8
- package/dist/engine/index.js +0 -4
- package/dist/engine/normalize.d.ts +0 -43
- package/dist/engine/normalize.js +0 -403
- package/dist/engine/normalize.test.d.ts +0 -1
- package/dist/engine/normalize.test.js +0 -136
- package/dist/engine/onSolid.d.ts +0 -3
- package/dist/engine/onSolid.js +0 -110
- package/dist/engine/resolveBaseColor.d.ts +0 -25
- package/dist/engine/resolveBaseColor.js +0 -127
- package/dist/engine/resolveBaseColor.test.d.ts +0 -1
- package/dist/engine/resolveBaseColor.test.js +0 -97
- package/dist/export/__snapshots__/exportTheme.test.js.snap +0 -74
- package/dist/export/exportTheme.d.ts +0 -47
- package/dist/export/exportTheme.js +0 -170
- package/dist/export/exportTheme.test.d.ts +0 -1
- package/dist/export/exportTheme.test.js +0 -118
- package/dist/export/index.d.ts +0 -1
- package/dist/export/index.js +0 -1
- package/dist/export/serializeColor.d.ts +0 -1
- package/dist/export/serializeColor.js +0 -1
- package/dist/export/serializeColor.test.d.ts +0 -1
- package/dist/export/serializeColor.test.js +0 -54
- package/dist/export.d.ts +0 -1
- package/dist/export.js +0 -1
- package/dist/operators/emphasis.d.ts +0 -3
- package/dist/operators/emphasis.js +0 -113
- package/dist/operators/emphasis.test.d.ts +0 -1
- package/dist/operators/emphasis.test.js +0 -69
- package/dist/operators/index.d.ts +0 -3
- package/dist/operators/index.js +0 -2
- package/dist/operators/state.d.ts +0 -3
- package/dist/operators/state.js +0 -102
- package/dist/operators/state.test.d.ts +0 -1
- package/dist/operators/state.test.js +0 -48
- package/dist/operators/types.d.ts +0 -13
- package/dist/operators/types.js +0 -1
- package/dist/operators/utils.d.ts +0 -16
- package/dist/operators/utils.js +0 -23
- package/dist/presets/curves.d.ts +0 -28
- package/dist/presets/curves.js +0 -145
- package/dist/presets/index.d.ts +0 -2
- package/dist/presets/index.js +0 -1
- package/dist/presets/tokens/index.d.ts +0 -3
- package/dist/presets/tokens/index.js +0 -3
- package/dist/presets/tokens/minimal-ui.d.ts +0 -6
- package/dist/presets/tokens/minimal-ui.js +0 -53
- package/dist/presets/tokens/modern-ui.d.ts +0 -5
- package/dist/presets/tokens/modern-ui.js +0 -83
- package/dist/presets/tokens/presets.test.d.ts +0 -1
- package/dist/presets/tokens/presets.test.js +0 -31
- package/dist/presets/tokens/radixLike-ui.d.ts +0 -6
- package/dist/presets/tokens/radixLike-ui.js +0 -77
- package/dist/serialize/index.d.ts +0 -1
- package/dist/serialize/index.js +0 -1
- package/dist/serialize/normalizeOutput.d.ts +0 -6
- package/dist/serialize/normalizeOutput.js +0 -45
- package/dist/serialize/serializeColor.d.ts +0 -21
- package/dist/serialize/serializeColor.js +0 -178
- package/dist/serialize/serializeResolved.test.d.ts +0 -1
- package/dist/serialize/serializeResolved.test.js +0 -45
- package/dist/serialize.d.ts +0 -1
- package/dist/serialize.js +0 -1
- package/dist/utils/clamp.d.ts +0 -1
- package/dist/utils/clamp.js +0 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/lerp.d.ts +0 -1
- package/dist/utils/lerp.js +0 -1
- package/dist/utils/parseColor.d.ts +0 -6
- package/dist/utils/parseColor.js +0 -67
- package/dist/utils/parseColor.test.d.ts +0 -1
- package/dist/utils/parseColor.test.js +0 -51
- package/dist/utils/smoothstep.d.ts +0 -1
- package/dist/utils/smoothstep.js +0 -5
- package/planning/phase-10-review.md +0 -550
- package/planning/phase-7-review.md +0 -411
- package/planning/phase-8-review.md +0 -669
- package/planning/phase-9-review.md +0 -564
- package/planning/roadmap-v0.3.md +0 -284
- package/planning/spec-serializer-v0.3.md +0 -324
- package/planning/spec-v0.3.md +0 -305
- package/src/cli/args.test.ts +0 -28
- package/src/cli/args.ts +0 -66
- package/src/cli/codegen/__snapshots__/tokens.test.ts.snap +0 -87
- package/src/cli/codegen/tokens.test.ts +0 -61
- package/src/cli/codegen/tokens.ts +0 -191
- package/src/cli/config.ts +0 -71
- package/src/cli/validate.test.ts +0 -49
- package/src/cli/validate.ts +0 -38
- package/src/cli.ts +0 -183
- package/src/contrast/apca.test.ts +0 -20
- package/src/contrast/apca.ts +0 -26
- package/src/contrast/index.ts +0 -4
- package/src/contrast/scoring.test.ts +0 -188
- package/src/contrast/scoring.ts +0 -48
- package/src/contrast/solver.test.ts +0 -147
- package/src/contrast/solver.ts +0 -235
- package/src/contrast/types.ts +0 -20
- package/src/contrast/utils.ts +0 -28
- package/src/contrast/wcag2.test.ts +0 -21
- package/src/contrast/wcag2.ts +0 -24
- package/src/core/createTheme.ts +0 -78
- package/src/core/dx-helpers.test.ts +0 -82
- package/src/core/index.ts +0 -7
- package/src/core/onSolid.test.ts +0 -146
- package/src/core/qa.v1.test.ts +0 -149
- package/src/core/resolve.test.ts +0 -99
- package/src/core/resolve.ts +0 -11
- package/src/core/resolveMany.ts +0 -22
- package/src/core/tokenRegistry.test.ts +0 -153
- package/src/core/tokenRegistry.ts +0 -114
- package/src/engine/applyOperators.ts +0 -32
- package/src/engine/context.ts +0 -8
- package/src/engine/gamut.test.ts +0 -30
- package/src/engine/gamut.ts +0 -144
- package/src/engine/generateScale.test.ts +0 -46
- package/src/engine/generateScale.ts +0 -48
- package/src/engine/index.ts +0 -8
- package/src/engine/normalize.test.ts +0 -222
- package/src/engine/normalize.ts +0 -550
- package/src/engine/onSolid.ts +0 -178
- package/src/engine/resolveBaseColor.test.ts +0 -117
- package/src/engine/resolveBaseColor.ts +0 -203
- package/src/export/__snapshots__/exportTheme.test.ts.snap +0 -74
- package/src/export/exportTheme.test.ts +0 -144
- package/src/export/exportTheme.ts +0 -251
- package/src/export/index.ts +0 -1
- package/src/export/serializeColor.test.ts +0 -73
- package/src/export/serializeColor.ts +0 -1
- package/src/export.ts +0 -1
- package/src/index.ts +0 -3
- package/src/operators/emphasis.test.ts +0 -85
- package/src/operators/emphasis.ts +0 -132
- package/src/operators/index.ts +0 -3
- package/src/operators/state.test.ts +0 -66
- package/src/operators/state.ts +0 -122
- package/src/operators/types.ts +0 -14
- package/src/operators/utils.ts +0 -44
- package/src/presets/curves.ts +0 -168
- package/src/presets/index.ts +0 -2
- package/src/presets/tokens/index.ts +0 -3
- package/src/presets/tokens/minimal-ui.ts +0 -55
- package/src/presets/tokens/modern-ui.ts +0 -85
- package/src/presets/tokens/presets.test.ts +0 -46
- package/src/presets/tokens/radixLike-ui.ts +0 -79
- package/src/serialize/index.ts +0 -1
- package/src/serialize/normalizeOutput.ts +0 -63
- package/src/serialize/serializeColor.ts +0 -260
- package/src/serialize/serializeResolved.test.ts +0 -57
- package/src/serialize.ts +0 -1
- package/src/types/index.ts +0 -207
- package/src/utils/clamp.ts +0 -2
- package/src/utils/index.ts +0 -1
- package/src/utils/lerp.ts +0 -1
- package/src/utils/parseColor.test.ts +0 -66
- package/src/utils/parseColor.ts +0 -87
- package/src/utils/smoothstep.ts +0 -6
- package/tsconfig.build.json +0 -11
- package/tsconfig.json +0 -15
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { COLOR_STATES, normalizeQuery } from "../engine/normalize.js";
|
|
2
|
-
const ALLOWED_TOKEN_STATES = COLOR_STATES.filter((state) => state !== "default");
|
|
3
|
-
const validateTokenStates = (states, name) => {
|
|
4
|
-
if (!states)
|
|
5
|
-
return;
|
|
6
|
-
for (const [state, enabled] of Object.entries(states)) {
|
|
7
|
-
if (enabled !== true) {
|
|
8
|
-
throw new Error(`Token "${name}" state "${state}" must be true`);
|
|
9
|
-
}
|
|
10
|
-
if (!ALLOWED_TOKEN_STATES.includes(state)) {
|
|
11
|
-
throw new Error(`Invalid token state "${state}" for "${name}"`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Validate a token definition for safe registry usage.
|
|
17
|
-
*
|
|
18
|
-
* Guarantees (Phase 3):
|
|
19
|
-
* - registry stays declarative (no output options / no embedded color literals)
|
|
20
|
-
* - tokens are base tokens (interactive states declared via `token.states`)
|
|
21
|
-
*/
|
|
22
|
-
export const validateTokenDefinition = (token) => {
|
|
23
|
-
if (typeof token.name !== "string" || !token.name.trim()) {
|
|
24
|
-
throw new Error("Token name is required");
|
|
25
|
-
}
|
|
26
|
-
if (typeof token.query?.role !== "string" || !token.query.role.trim()) {
|
|
27
|
-
throw new Error(`Token "${token.name}" requires a query role`);
|
|
28
|
-
}
|
|
29
|
-
if (!token.query.usage) {
|
|
30
|
-
throw new Error(`Token "${token.name}" requires a usage`);
|
|
31
|
-
}
|
|
32
|
-
if (!token.query.surface) {
|
|
33
|
-
throw new Error(`Token "${token.name}" requires a surface`);
|
|
34
|
-
}
|
|
35
|
-
const rawState = token.query.state;
|
|
36
|
-
const normalizedState = typeof rawState === "string" ? rawState.trim() : rawState;
|
|
37
|
-
if (normalizedState && normalizedState !== "default") {
|
|
38
|
-
throw new Error(`Token "${token.name}" must not encode state in query; declare supported states via token.states`);
|
|
39
|
-
}
|
|
40
|
-
const onKind = token.query.on?.kind;
|
|
41
|
-
if (onKind === "color") {
|
|
42
|
-
throw new Error(`Token "${token.name}" must not include a literal background color hint; use { kind: "role" } or { kind: "auto" }`);
|
|
43
|
-
}
|
|
44
|
-
if (token.query.output) {
|
|
45
|
-
throw new Error(`Token "${token.name}" must not include output options`);
|
|
46
|
-
}
|
|
47
|
-
validateTokenStates(token.states, token.name);
|
|
48
|
-
// Delegate to core validation for strict field validation.
|
|
49
|
-
normalizeQuery({ ...token.query, output: { strict: true } });
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Validate a token registry and each token definition it contains.
|
|
53
|
-
*/
|
|
54
|
-
export const validateTokenRegistry = (registry) => {
|
|
55
|
-
const entries = Object.entries(registry.tokens);
|
|
56
|
-
if (entries.length === 0) {
|
|
57
|
-
throw new Error("Token registry must include at least one token");
|
|
58
|
-
}
|
|
59
|
-
for (const [name, token] of entries) {
|
|
60
|
-
if (token.name !== name) {
|
|
61
|
-
throw new Error(`Token name mismatch: expected "${name}", got "${token.name}"`);
|
|
62
|
-
}
|
|
63
|
-
validateTokenDefinition(token);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Resolve a token definition through the provided theme.
|
|
68
|
-
*/
|
|
69
|
-
export const resolveToken = (token, theme) => {
|
|
70
|
-
validateTokenDefinition(token);
|
|
71
|
-
return theme.resolve(token.query);
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Resolve all tokens in a registry while preserving key order.
|
|
75
|
-
*/
|
|
76
|
-
export const resolveTokenRegistry = (registry, theme) => {
|
|
77
|
-
validateTokenRegistry(registry);
|
|
78
|
-
const resolved = {};
|
|
79
|
-
for (const [name, token] of Object.entries(registry.tokens)) {
|
|
80
|
-
resolved[name] = theme.resolve(token.query);
|
|
81
|
-
}
|
|
82
|
-
return resolved;
|
|
83
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { createTheme } from "./createTheme.js";
|
|
3
|
-
import { resolveToken, resolveTokenRegistry, validateTokenRegistry } from "./tokenRegistry.js";
|
|
4
|
-
describe("token registry", () => {
|
|
5
|
-
const theme = createTheme({
|
|
6
|
-
seeds: {
|
|
7
|
-
light: { neutral: "#8B8D98", accent: "#3D63DD" },
|
|
8
|
-
dark: { neutral: "#8B8D98", accent: "#3D63DD" },
|
|
9
|
-
},
|
|
10
|
-
preset: "modern",
|
|
11
|
-
});
|
|
12
|
-
it("validates tokens and resolves through theme.resolve", () => {
|
|
13
|
-
const registry = {
|
|
14
|
-
tokens: {
|
|
15
|
-
"bg.app": {
|
|
16
|
-
name: "bg.app",
|
|
17
|
-
description: "App background",
|
|
18
|
-
category: "background",
|
|
19
|
-
query: { role: "bg.app", usage: "bg", surface: "app" },
|
|
20
|
-
states: { hover: true },
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
validateTokenRegistry(registry);
|
|
25
|
-
const resolved = resolveTokenRegistry(registry, theme);
|
|
26
|
-
expect(resolved["bg.app"].step).toBeGreaterThan(0);
|
|
27
|
-
const single = resolveToken(registry.tokens["bg.app"], theme);
|
|
28
|
-
const expected = theme.resolve(registry.tokens["bg.app"].query);
|
|
29
|
-
expect(single.step).toBe(expected.step);
|
|
30
|
-
});
|
|
31
|
-
it("throws when required query fields are missing", () => {
|
|
32
|
-
const registry = {
|
|
33
|
-
tokens: {
|
|
34
|
-
"text.primary": {
|
|
35
|
-
name: "text.primary",
|
|
36
|
-
query: { role: "text.primary", usage: "text" },
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
expect(() => validateTokenRegistry(registry)).toThrow(/requires a surface/i);
|
|
41
|
-
});
|
|
42
|
-
it("throws when output options are provided", () => {
|
|
43
|
-
const registry = {
|
|
44
|
-
tokens: {
|
|
45
|
-
"bg.app": {
|
|
46
|
-
name: "bg.app",
|
|
47
|
-
query: {
|
|
48
|
-
role: "bg.app",
|
|
49
|
-
usage: "bg",
|
|
50
|
-
surface: "app",
|
|
51
|
-
output: { strict: true },
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
expect(() => validateTokenRegistry(registry)).toThrow(/must not include output/i);
|
|
57
|
-
});
|
|
58
|
-
it("treats whitespace-padded default state as default", () => {
|
|
59
|
-
const registry = {
|
|
60
|
-
tokens: {
|
|
61
|
-
"bg.app": {
|
|
62
|
-
name: "bg.app",
|
|
63
|
-
query: {
|
|
64
|
-
role: "bg.app",
|
|
65
|
-
usage: "bg",
|
|
66
|
-
surface: "app",
|
|
67
|
-
state: " default ",
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
expect(() => validateTokenRegistry(registry)).not.toThrow();
|
|
73
|
-
});
|
|
74
|
-
it("throws when token query encodes a non-default state", () => {
|
|
75
|
-
const registry = {
|
|
76
|
-
tokens: {
|
|
77
|
-
"bg.app": {
|
|
78
|
-
name: "bg.app",
|
|
79
|
-
query: { role: "bg.app", usage: "bg", surface: "app", state: "hover" },
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
expect(() => validateTokenRegistry(registry)).toThrow(/must not encode state/i);
|
|
84
|
-
});
|
|
85
|
-
it("throws when token query includes a literal background color hint", () => {
|
|
86
|
-
const registry = {
|
|
87
|
-
tokens: {
|
|
88
|
-
"bg.app": {
|
|
89
|
-
name: "bg.app",
|
|
90
|
-
query: {
|
|
91
|
-
role: "bg.app",
|
|
92
|
-
usage: "bg",
|
|
93
|
-
surface: "app",
|
|
94
|
-
on: { kind: "color", value: "#fff" },
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
expect(() => validateTokenRegistry(registry)).toThrow(/literal background color/i);
|
|
100
|
-
});
|
|
101
|
-
it("throws when token states include invalid keys or non-true values", () => {
|
|
102
|
-
const invalidKey = {
|
|
103
|
-
tokens: {
|
|
104
|
-
"bg.app": {
|
|
105
|
-
name: "bg.app",
|
|
106
|
-
query: { role: "bg.app", usage: "bg", surface: "app" },
|
|
107
|
-
states: { nope: true },
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
expect(() => validateTokenRegistry(invalidKey)).toThrow(/Invalid token state/i);
|
|
112
|
-
const includesDefault = {
|
|
113
|
-
tokens: {
|
|
114
|
-
"bg.app": {
|
|
115
|
-
name: "bg.app",
|
|
116
|
-
query: { role: "bg.app", usage: "bg", surface: "app" },
|
|
117
|
-
states: { default: true },
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
expect(() => validateTokenRegistry(includesDefault)).toThrow(/Invalid token state/i);
|
|
122
|
-
const nonTrueValue = {
|
|
123
|
-
tokens: {
|
|
124
|
-
"bg.app": {
|
|
125
|
-
name: "bg.app",
|
|
126
|
-
query: { role: "bg.app", usage: "bg", surface: "app" },
|
|
127
|
-
states: { hover: false },
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
expect(() => validateTokenRegistry(nonTrueValue)).toThrow(/must be true/i);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { applyEmphasisOperator } from "../operators/emphasis.js";
|
|
2
|
-
import { applyStateOperator } from "../operators/state.js";
|
|
3
|
-
import { mapColorContextToEngine } from "./context.js";
|
|
4
|
-
export const applyOperators = (base, normalized, theme) => {
|
|
5
|
-
const context = mapColorContextToEngine(normalized.context);
|
|
6
|
-
const operatorInput = {
|
|
7
|
-
oklch: base.oklch,
|
|
8
|
-
context,
|
|
9
|
-
surface: normalized.surface,
|
|
10
|
-
usage: normalized.usage,
|
|
11
|
-
state: normalized.state,
|
|
12
|
-
emphasis: normalized.emphasis,
|
|
13
|
-
preset: theme.preset,
|
|
14
|
-
step: base.step,
|
|
15
|
-
};
|
|
16
|
-
// Emphasis defines the baseline hierarchy; state applies transient interaction.
|
|
17
|
-
const emphasized = applyEmphasisOperator(operatorInput);
|
|
18
|
-
const stated = applyStateOperator({ ...operatorInput, oklch: emphasized });
|
|
19
|
-
return {
|
|
20
|
-
...base,
|
|
21
|
-
oklch: stated,
|
|
22
|
-
};
|
|
23
|
-
};
|
package/dist/engine/context.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { ColorContext } from "../types/index.js";
|
|
2
|
-
import type { NormalizedQuery } from "./normalize.js";
|
|
3
|
-
export type EngineContext = "light" | "dark";
|
|
4
|
-
export declare const mapColorContextToEngine: (context: ColorContext | NormalizedQuery["context"]) => EngineContext;
|
package/dist/engine/context.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const mapColorContextToEngine = (context) => (context === "dark" || context === "dimmed" ? "dark" : "light");
|
package/dist/engine/gamut.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { OutputOptions } from "../types/index.js";
|
|
2
|
-
import type { OkLchColor } from "./generateScale.js";
|
|
3
|
-
export type GamutTarget = "srgb" | "p3";
|
|
4
|
-
export type GamutMapping = NonNullable<OutputOptions["gamutMapping"]>;
|
|
5
|
-
type GamutRgb = {
|
|
6
|
-
r: number;
|
|
7
|
-
g: number;
|
|
8
|
-
b: number;
|
|
9
|
-
};
|
|
10
|
-
export declare const isInGamut: (color: OkLchColor, target: GamutTarget) => boolean;
|
|
11
|
-
export declare const mapToGamut: (color: OkLchColor, target: GamutTarget, mapping: GamutMapping, strict: boolean) => OkLchColor;
|
|
12
|
-
export declare const toGamutRgb: (color: OkLchColor, target: GamutTarget) => GamutRgb | null;
|
|
13
|
-
export {};
|
package/dist/engine/gamut.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { clampChroma, converter } from "culori";
|
|
2
|
-
import { clamp } from "../utils/clamp.js";
|
|
3
|
-
const toRgb = converter("rgb");
|
|
4
|
-
const toP3 = converter("p3");
|
|
5
|
-
const toOklch = converter("oklch");
|
|
6
|
-
const normalizeHue = (hue) => ((hue % 360) + 360) % 360;
|
|
7
|
-
const toCuloriOklch = (color) => ({
|
|
8
|
-
mode: "oklch",
|
|
9
|
-
l: clamp(color.l, 0, 100) / 100,
|
|
10
|
-
c: Math.max(0, color.c),
|
|
11
|
-
h: color.h,
|
|
12
|
-
alpha: color.alpha ?? 1,
|
|
13
|
-
});
|
|
14
|
-
const fromCuloriOklch = (color) => ({
|
|
15
|
-
l: clamp(typeof color.l === "number" && Number.isFinite(color.l) ? color.l * 100 : 0, 0, 100),
|
|
16
|
-
c: Math.max(0, typeof color.c === "number" && Number.isFinite(color.c) ? color.c : 0),
|
|
17
|
-
h: normalizeHue(typeof color.h === "number" && Number.isFinite(color.h) ? color.h : 0),
|
|
18
|
-
...(typeof color.alpha === "number" ? { alpha: color.alpha } : {}),
|
|
19
|
-
});
|
|
20
|
-
const clamp01 = (value) => Math.min(1, Math.max(0, value));
|
|
21
|
-
const toTargetRgb = (color, target) => {
|
|
22
|
-
const source = toCuloriOklch(color);
|
|
23
|
-
const rgb = target === "p3" ? toP3(source) : toRgb(source);
|
|
24
|
-
if (!rgb) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
const r = typeof rgb.r === "number" && Number.isFinite(rgb.r) ? rgb.r : Number.NaN;
|
|
28
|
-
const g = typeof rgb.g === "number" && Number.isFinite(rgb.g) ? rgb.g : Number.NaN;
|
|
29
|
-
const b = typeof rgb.b === "number" && Number.isFinite(rgb.b) ? rgb.b : Number.NaN;
|
|
30
|
-
if (!Number.isFinite(r) || !Number.isFinite(g) || !Number.isFinite(b)) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
return { r, g, b };
|
|
34
|
-
};
|
|
35
|
-
const toOklchFromRgb = (rgb, target) => {
|
|
36
|
-
const converted = toOklch({
|
|
37
|
-
mode: (target === "p3" ? "p3" : "rgb"),
|
|
38
|
-
r: clamp01(rgb.r),
|
|
39
|
-
g: clamp01(rgb.g),
|
|
40
|
-
b: clamp01(rgb.b),
|
|
41
|
-
});
|
|
42
|
-
if (!converted) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
return fromCuloriOklch(converted);
|
|
46
|
-
};
|
|
47
|
-
const GAMUT_EPSILON = 1e-6;
|
|
48
|
-
const inGamut = (rgb) => !!rgb &&
|
|
49
|
-
Number.isFinite(rgb.r) &&
|
|
50
|
-
Number.isFinite(rgb.g) &&
|
|
51
|
-
Number.isFinite(rgb.b) &&
|
|
52
|
-
rgb.r >= -GAMUT_EPSILON &&
|
|
53
|
-
rgb.r <= 1 + GAMUT_EPSILON &&
|
|
54
|
-
rgb.g >= -GAMUT_EPSILON &&
|
|
55
|
-
rgb.g <= 1 + GAMUT_EPSILON &&
|
|
56
|
-
rgb.b >= -GAMUT_EPSILON &&
|
|
57
|
-
rgb.b <= 1 + GAMUT_EPSILON;
|
|
58
|
-
const fallbackColor = (color) => ({
|
|
59
|
-
l: 0,
|
|
60
|
-
c: 0,
|
|
61
|
-
h: 0,
|
|
62
|
-
alpha: color.alpha ?? 1,
|
|
63
|
-
});
|
|
64
|
-
export const isInGamut = (color, target) => inGamut(toTargetRgb(color, target));
|
|
65
|
-
export const mapToGamut = (color, target, mapping, strict) => {
|
|
66
|
-
// Note:
|
|
67
|
-
// `preferP3ThenCompress` is primarily a caller-level strategy (e.g. serializeColor prefers P3 when possible).
|
|
68
|
-
// Inside this mapper, any non-clip mapping uses chroma compression (via clampChroma) when mapping is needed.
|
|
69
|
-
const rgb = toTargetRgb(color, target);
|
|
70
|
-
if (!rgb) {
|
|
71
|
-
if (strict) {
|
|
72
|
-
throw new Error(`Unable to convert color to ${target}`);
|
|
73
|
-
}
|
|
74
|
-
return fallbackColor(color);
|
|
75
|
-
}
|
|
76
|
-
if (mapping === "clip") {
|
|
77
|
-
if (inGamut(rgb)) {
|
|
78
|
-
return color;
|
|
79
|
-
}
|
|
80
|
-
const clipped = { r: clamp01(rgb.r), g: clamp01(rgb.g), b: clamp01(rgb.b) };
|
|
81
|
-
const clippedOklch = toOklchFromRgb(clipped, target);
|
|
82
|
-
return clippedOklch
|
|
83
|
-
? {
|
|
84
|
-
...clippedOklch,
|
|
85
|
-
...(typeof color.alpha === "number" ? { alpha: color.alpha } : {}),
|
|
86
|
-
}
|
|
87
|
-
: fallbackColor(color);
|
|
88
|
-
}
|
|
89
|
-
if (inGamut(rgb)) {
|
|
90
|
-
return color;
|
|
91
|
-
}
|
|
92
|
-
const clamped = clampChroma(toCuloriOklch(color), "oklch", target === "p3" ? "p3" : "rgb");
|
|
93
|
-
if (!clamped) {
|
|
94
|
-
if (strict) {
|
|
95
|
-
throw new Error(`Unable to clamp chroma for ${target}`);
|
|
96
|
-
}
|
|
97
|
-
return fallbackColor(color);
|
|
98
|
-
}
|
|
99
|
-
return fromCuloriOklch(clamped);
|
|
100
|
-
};
|
|
101
|
-
export const toGamutRgb = (color, target) => toTargetRgb(color, target);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { isInGamut, mapToGamut } from "./gamut.js";
|
|
3
|
-
describe("gamut mapping", () => {
|
|
4
|
-
const outOfSrgbInP3 = { l: 60, c: 0.2, h: 40 };
|
|
5
|
-
it("detects out-of-gamut sRGB colors", () => {
|
|
6
|
-
expect(isInGamut(outOfSrgbInP3, "srgb")).toBe(false);
|
|
7
|
-
expect(isInGamut(outOfSrgbInP3, "p3")).toBe(true);
|
|
8
|
-
});
|
|
9
|
-
it("clips to sRGB gamut", () => {
|
|
10
|
-
const clipped = mapToGamut(outOfSrgbInP3, "srgb", "clip", false);
|
|
11
|
-
expect(isInGamut(clipped, "srgb")).toBe(true);
|
|
12
|
-
});
|
|
13
|
-
it("compresses chroma to sRGB gamut", () => {
|
|
14
|
-
const compressed = mapToGamut(outOfSrgbInP3, "srgb", "compressChroma", false);
|
|
15
|
-
expect(isInGamut(compressed, "srgb")).toBe(true);
|
|
16
|
-
expect(compressed.c).toBeLessThanOrEqual(outOfSrgbInP3.c);
|
|
17
|
-
});
|
|
18
|
-
it("keeps chroma when already in P3", () => {
|
|
19
|
-
const mapped = mapToGamut(outOfSrgbInP3, "p3", "preferP3ThenCompress", false);
|
|
20
|
-
expect(isInGamut(mapped, "p3")).toBe(true);
|
|
21
|
-
expect(mapped.c).toBeCloseTo(outOfSrgbInP3.c, 4);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { CurvePresetName } from "../presets/index.js";
|
|
2
|
-
import type { SurfaceIntent } from "../types/index.js";
|
|
3
|
-
export type OkLchColor = {
|
|
4
|
-
l: number;
|
|
5
|
-
c: number;
|
|
6
|
-
h: number;
|
|
7
|
-
alpha?: number;
|
|
8
|
-
};
|
|
9
|
-
type GenerateScaleOptions = {
|
|
10
|
-
context: "light" | "dark";
|
|
11
|
-
surface: SurfaceIntent;
|
|
12
|
-
preset?: CurvePresetName;
|
|
13
|
-
};
|
|
14
|
-
export declare function generateScale(seed: OkLchColor, options: GenerateScaleOptions): OkLchColor[];
|
|
15
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { curvePresets } from "../presets/index.js";
|
|
2
|
-
import { clamp } from "../utils/clamp.js";
|
|
3
|
-
import { lerp } from "../utils/lerp.js";
|
|
4
|
-
const STEPS = 12;
|
|
5
|
-
const OKLCH_L_MIN = 0;
|
|
6
|
-
const OKLCH_L_MAX = 100;
|
|
7
|
-
export function generateScale(seed, options) {
|
|
8
|
-
const presetName = options.preset ?? "modern";
|
|
9
|
-
const preset = curvePresets[presetName];
|
|
10
|
-
const surfaceCurve = preset.surfaces[options.surface];
|
|
11
|
-
const range = surfaceCurve.ranges[options.context];
|
|
12
|
-
return Array.from({ length: STEPS }, (_, index) => {
|
|
13
|
-
const t = index / (STEPS - 1);
|
|
14
|
-
const lightnessT = surfaceCurve.l(t);
|
|
15
|
-
const chromaT = surfaceCurve.c(lightnessT);
|
|
16
|
-
const l = clamp(lerp(range.l[0], range.l[1], lightnessT), OKLCH_L_MIN, OKLCH_L_MAX);
|
|
17
|
-
// Allow select surfaces to exceed seed chroma slightly while staying within range caps.
|
|
18
|
-
const chromaBoost = range.chromaBoost ?? 1;
|
|
19
|
-
const boostedSeed = (seed.c ?? range.cMax) * chromaBoost;
|
|
20
|
-
const maxChroma = Math.min(range.cMax, Math.max(0, boostedSeed));
|
|
21
|
-
const c = clamp(lerp(range.cMin, maxChroma, chromaT), 0, range.cMax);
|
|
22
|
-
return {
|
|
23
|
-
l,
|
|
24
|
-
c,
|
|
25
|
-
h: seed.h,
|
|
26
|
-
alpha: seed.alpha,
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { generateScale } from "./generateScale.js";
|
|
3
|
-
const seed = { l: 49.5, c: 0.19, h: 264.0 };
|
|
4
|
-
const isMonotonic = (values) => values.every((value, index) => index === 0 || value >= values[index - 1] - 1e-6);
|
|
5
|
-
describe("generateScale", () => {
|
|
6
|
-
it("returns 12 steps", () => {
|
|
7
|
-
const result = generateScale(seed, { context: "light", surface: "surface" });
|
|
8
|
-
expect(result).toHaveLength(12);
|
|
9
|
-
});
|
|
10
|
-
it("keeps lightness monotonic in light context", () => {
|
|
11
|
-
const result = generateScale(seed, { context: "light", surface: "surface" });
|
|
12
|
-
const lightness = result.map((step) => step.l);
|
|
13
|
-
expect(isMonotonic(lightness)).toBe(true);
|
|
14
|
-
});
|
|
15
|
-
it("keeps lightness monotonic in dark context", () => {
|
|
16
|
-
const result = generateScale(seed, { context: "dark", surface: "surface" });
|
|
17
|
-
const lightness = result.map((step) => step.l);
|
|
18
|
-
expect(isMonotonic(lightness)).toBe(true);
|
|
19
|
-
});
|
|
20
|
-
it("keeps hue constant across steps", () => {
|
|
21
|
-
const result = generateScale(seed, { context: "light", surface: "surface" });
|
|
22
|
-
result.forEach((step) => {
|
|
23
|
-
expect(step.h).toBeCloseTo(seed.h, 6);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
it("never produces negative chroma", () => {
|
|
27
|
-
const result = generateScale(seed, { context: "light", surface: "surface" });
|
|
28
|
-
result.forEach((step) => {
|
|
29
|
-
expect(step.c).toBeGreaterThanOrEqual(0);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
});
|
package/dist/engine/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export type { EngineContext } from "./context.js";
|
|
2
|
-
export { mapColorContextToEngine } from "./context.js";
|
|
3
|
-
export type { OkLchColor } from "./generateScale.js";
|
|
4
|
-
export { generateScale } from "./generateScale.js";
|
|
5
|
-
export type { NormalizedOnSolidQuery, NormalizedQuery } from "./normalize.js";
|
|
6
|
-
export { normalizeOnSolidQuery, normalizeQuery } from "./normalize.js";
|
|
7
|
-
export type { BaseResolvedColor, ThemeConfig } from "./resolveBaseColor.js";
|
|
8
|
-
export { resolveBaseColor } from "./resolveBaseColor.js";
|
package/dist/engine/index.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { ColorQuery, ColorState, OnSolidQuery, OutputOptions } from "../types/index.js";
|
|
2
|
-
export type NormalizedQuery = Required<Pick<ColorQuery, "role" | "usage" | "context" | "surface" | "state" | "emphasis">> & {
|
|
3
|
-
variant?: ColorQuery["variant"];
|
|
4
|
-
on?: ColorQuery["on"];
|
|
5
|
-
contrast?: ColorQuery["contrast"];
|
|
6
|
-
alpha?: ColorQuery["alpha"];
|
|
7
|
-
output: Required<Omit<OutputOptions, "format">>;
|
|
8
|
-
};
|
|
9
|
-
export type NormalizedOnSolidQuery = Required<Pick<OnSolidQuery, "bgRole" | "usage" | "context" | "state" | "emphasis">> & {
|
|
10
|
-
alpha?: OnSolidQuery["alpha"];
|
|
11
|
-
contrast?: OnSolidQuery["contrast"];
|
|
12
|
-
output: Required<Omit<OutputOptions, "format">>;
|
|
13
|
-
};
|
|
14
|
-
export declare const COLOR_STATES: readonly ColorState[];
|
|
15
|
-
/**
|
|
16
|
-
* Normalize a user-facing ColorQuery into a fully populated, validated structure.
|
|
17
|
-
*
|
|
18
|
-
* - Applies defaults for missing fields (context, surface, state, emphasis, output).
|
|
19
|
-
* - Infers usage and surface from role naming patterns when not provided.
|
|
20
|
-
* - In strict mode, missing required fields throw actionable errors.
|
|
21
|
-
* - In non-strict mode, safe defaults are applied with explicit warnings.
|
|
22
|
-
* - Validates nested objects (background hints, contrast requirements, alpha strategies).
|
|
23
|
-
* - Trims string inputs and enforces allowed enum values.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* normalizeQuery({ role: "text.primary" });
|
|
27
|
-
* @example
|
|
28
|
-
* normalizeQuery({
|
|
29
|
-
* role: "bg.canvas",
|
|
30
|
-
* on: { kind: "color", value: "#fff" },
|
|
31
|
-
* contrast: { model: "apca", targetLc: 60 },
|
|
32
|
-
* output: { strict: true },
|
|
33
|
-
* });
|
|
34
|
-
*/
|
|
35
|
-
export declare function normalizeQuery(q: ColorQuery): NormalizedQuery;
|
|
36
|
-
/**
|
|
37
|
-
* Normalize a user-facing OnSolidQuery into a fully populated, validated structure.
|
|
38
|
-
*
|
|
39
|
-
* - Applies defaults for missing fields (context, state, emphasis, output).
|
|
40
|
-
* - Validates usage ("text" | "icon") and required background role.
|
|
41
|
-
* - Validates nested objects (contrast requirements, alpha strategies).
|
|
42
|
-
*/
|
|
43
|
-
export declare function normalizeOnSolidQuery(q: OnSolidQuery): NormalizedOnSolidQuery;
|