@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
package/dist/cli/args.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export class CliUsageError extends Error {
|
|
2
|
-
name = "CliUsageError";
|
|
3
|
-
}
|
|
4
|
-
export const HELP_TEXT = `palette-kit <command>
|
|
5
|
-
|
|
6
|
-
Commands:
|
|
7
|
-
palette-kit init [--force] [--path <dir>]
|
|
8
|
-
palette-kit build [--config <path>] [--outDir <dir>] [--report]
|
|
9
|
-
|
|
10
|
-
Options:
|
|
11
|
-
-h, --help Show help
|
|
12
|
-
-v, --version Show version
|
|
13
|
-
`;
|
|
14
|
-
export const COMMANDS = ["init", "build"];
|
|
15
|
-
export const parseArgs = (argv) => {
|
|
16
|
-
const first = argv[0];
|
|
17
|
-
const command = first && !first.startsWith("-") ? first : undefined;
|
|
18
|
-
const rest = command ? argv.slice(1) : argv;
|
|
19
|
-
const flags = {};
|
|
20
|
-
let i = 0;
|
|
21
|
-
while (i < rest.length) {
|
|
22
|
-
const value = rest[i];
|
|
23
|
-
if (value === undefined)
|
|
24
|
-
break;
|
|
25
|
-
if (value === "-h" || value === "--help") {
|
|
26
|
-
flags.help = true;
|
|
27
|
-
i += 1;
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
if (value === "-v" || value === "--version") {
|
|
31
|
-
flags.version = true;
|
|
32
|
-
i += 1;
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
if (value.startsWith("--")) {
|
|
36
|
-
const key = value.slice(2);
|
|
37
|
-
const next = rest[i + 1];
|
|
38
|
-
if (next && !next.startsWith("--")) {
|
|
39
|
-
flags[key] = next;
|
|
40
|
-
i += 2;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
flags[key] = true;
|
|
44
|
-
i += 1;
|
|
45
|
-
}
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
throw new CliUsageError(`Unknown argument: ${value}`);
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
command,
|
|
52
|
-
help: Boolean(flags.help),
|
|
53
|
-
version: Boolean(flags.version),
|
|
54
|
-
flags,
|
|
55
|
-
};
|
|
56
|
-
};
|
package/dist/cli/args.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/cli/args.test.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { CliUsageError, parseArgs } from "./args.js";
|
|
3
|
-
describe("cli args", () => {
|
|
4
|
-
it("parses init command", () => {
|
|
5
|
-
const parsed = parseArgs(["init"]);
|
|
6
|
-
expect(parsed.command).toBe("init");
|
|
7
|
-
});
|
|
8
|
-
it("parses build command with flags", () => {
|
|
9
|
-
const parsed = parseArgs(["build", "--config", "custom.ts", "--outDir", "out", "--report"]);
|
|
10
|
-
expect(parsed.command).toBe("build");
|
|
11
|
-
expect(parsed.flags.config).toBe("custom.ts");
|
|
12
|
-
expect(parsed.flags.outDir).toBe("out");
|
|
13
|
-
expect(parsed.flags.report).toBe(true);
|
|
14
|
-
});
|
|
15
|
-
it("recognizes help and version flags", () => {
|
|
16
|
-
expect(parseArgs(["--help"]).help).toBe(true);
|
|
17
|
-
expect(parseArgs(["--version"]).version).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
it("throws on unknown arguments", () => {
|
|
20
|
-
expect(() => parseArgs(["build", "wat"])).toThrow(CliUsageError);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`codegen tokens > generates navigable tokens.ts and tokens.d.ts 1`] = `
|
|
4
|
-
"/* This file is generated by palette-kit build (Phase 7). */
|
|
5
|
-
|
|
6
|
-
export const tokens = {
|
|
7
|
-
bg: {
|
|
8
|
-
/**
|
|
9
|
-
* App background.
|
|
10
|
-
* @token bg.app
|
|
11
|
-
* @category bg
|
|
12
|
-
*/
|
|
13
|
-
app: "bg.app",
|
|
14
|
-
},
|
|
15
|
-
border: {
|
|
16
|
-
/**
|
|
17
|
-
* Default border color.
|
|
18
|
-
* @token border.default
|
|
19
|
-
* @category border
|
|
20
|
-
*/
|
|
21
|
-
"default": "border.default",
|
|
22
|
-
},
|
|
23
|
-
text: {
|
|
24
|
-
/**
|
|
25
|
-
* Primary text on standard surfaces.
|
|
26
|
-
* @token text.primary
|
|
27
|
-
* @category text
|
|
28
|
-
* @states hover
|
|
29
|
-
*/
|
|
30
|
-
primary: "text.primary",
|
|
31
|
-
},
|
|
32
|
-
} as const;
|
|
33
|
-
|
|
34
|
-
export const tokenNames = [
|
|
35
|
-
"bg.app",
|
|
36
|
-
"border.default",
|
|
37
|
-
"text.primary"
|
|
38
|
-
] as const;
|
|
39
|
-
|
|
40
|
-
export type TokenName = (typeof tokenNames)[number];
|
|
41
|
-
|
|
42
|
-
export type ColorRole = TokenName;
|
|
43
|
-
"
|
|
44
|
-
`;
|
|
45
|
-
|
|
46
|
-
exports[`codegen tokens > generates navigable tokens.ts and tokens.d.ts 2`] = `
|
|
47
|
-
"/* This file is generated by palette-kit build (Phase 7). */
|
|
48
|
-
|
|
49
|
-
export declare const tokens: {
|
|
50
|
-
bg: {
|
|
51
|
-
/**
|
|
52
|
-
* App background.
|
|
53
|
-
* @token bg.app
|
|
54
|
-
* @category bg
|
|
55
|
-
*/
|
|
56
|
-
app: "bg.app";
|
|
57
|
-
};
|
|
58
|
-
border: {
|
|
59
|
-
/**
|
|
60
|
-
* Default border color.
|
|
61
|
-
* @token border.default
|
|
62
|
-
* @category border
|
|
63
|
-
*/
|
|
64
|
-
"default": "border.default";
|
|
65
|
-
};
|
|
66
|
-
text: {
|
|
67
|
-
/**
|
|
68
|
-
* Primary text on standard surfaces.
|
|
69
|
-
* @token text.primary
|
|
70
|
-
* @category text
|
|
71
|
-
* @states hover
|
|
72
|
-
*/
|
|
73
|
-
primary: "text.primary";
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export declare const tokenNames: readonly [
|
|
78
|
-
"bg.app",
|
|
79
|
-
"border.default",
|
|
80
|
-
"text.primary"
|
|
81
|
-
];
|
|
82
|
-
|
|
83
|
-
export type TokenName = (typeof tokenNames)[number];
|
|
84
|
-
|
|
85
|
-
export type ColorRole = TokenName;
|
|
86
|
-
"
|
|
87
|
-
`;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { TokenRegistry } from "../../types/index.js";
|
|
2
|
-
export type GeneratedTokens = {
|
|
3
|
-
tokenNames: string[];
|
|
4
|
-
tokensTs: string;
|
|
5
|
-
tokensDts: string;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Generate `dist/palette/tokens.ts` and `dist/palette/tokens.d.ts` sources.
|
|
9
|
-
*
|
|
10
|
-
* Output is deterministic and derived from the token registry.
|
|
11
|
-
*/
|
|
12
|
-
export declare const generateTokenArtifacts: (registry: TokenRegistry) => GeneratedTokens;
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
const RESERVED_WORDS = new Set([
|
|
2
|
-
"break",
|
|
3
|
-
"case",
|
|
4
|
-
"catch",
|
|
5
|
-
"class",
|
|
6
|
-
"const",
|
|
7
|
-
"continue",
|
|
8
|
-
"debugger",
|
|
9
|
-
"default",
|
|
10
|
-
"delete",
|
|
11
|
-
"do",
|
|
12
|
-
"else",
|
|
13
|
-
"export",
|
|
14
|
-
"extends",
|
|
15
|
-
"finally",
|
|
16
|
-
"for",
|
|
17
|
-
"function",
|
|
18
|
-
"if",
|
|
19
|
-
"import",
|
|
20
|
-
"in",
|
|
21
|
-
"instanceof",
|
|
22
|
-
"new",
|
|
23
|
-
"return",
|
|
24
|
-
"super",
|
|
25
|
-
"switch",
|
|
26
|
-
"this",
|
|
27
|
-
"throw",
|
|
28
|
-
"try",
|
|
29
|
-
"typeof",
|
|
30
|
-
"var",
|
|
31
|
-
"void",
|
|
32
|
-
"while",
|
|
33
|
-
"with",
|
|
34
|
-
"yield",
|
|
35
|
-
]);
|
|
36
|
-
const isValidIdentifier = (value) => {
|
|
37
|
-
if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value))
|
|
38
|
-
return false;
|
|
39
|
-
return !RESERVED_WORDS.has(value);
|
|
40
|
-
};
|
|
41
|
-
const toPropertyKey = (key) => (isValidIdentifier(key) ? key : JSON.stringify(key));
|
|
42
|
-
const indentLines = (lines, spaces) => {
|
|
43
|
-
const prefix = " ".repeat(spaces);
|
|
44
|
-
return lines.map((line) => (line.length ? `${prefix}${line}` : line));
|
|
45
|
-
};
|
|
46
|
-
const escapeJsDoc = (value) => value.replace(/\*\//g, "*\\/");
|
|
47
|
-
const buildTokenJsDocLines = (tokenName, token) => {
|
|
48
|
-
const lines = [];
|
|
49
|
-
if (token.description?.trim()) {
|
|
50
|
-
lines.push(escapeJsDoc(token.description.trim()));
|
|
51
|
-
}
|
|
52
|
-
lines.push(`@token ${tokenName}`);
|
|
53
|
-
if (token.category?.trim()) {
|
|
54
|
-
lines.push(`@category ${escapeJsDoc(token.category.trim())}`);
|
|
55
|
-
}
|
|
56
|
-
const states = token.states ? Object.keys(token.states).sort() : [];
|
|
57
|
-
if (states.length > 0) {
|
|
58
|
-
lines.push(`@states ${states.join(", ")}`);
|
|
59
|
-
}
|
|
60
|
-
return ["/**", ...lines.map((line) => ` * ${line}`), " */"];
|
|
61
|
-
};
|
|
62
|
-
const buildTree = (registry) => {
|
|
63
|
-
const root = { children: new Map() };
|
|
64
|
-
const entries = Object.entries(registry.tokens).sort(([a], [b]) => a.localeCompare(b));
|
|
65
|
-
for (const [tokenName, token] of entries) {
|
|
66
|
-
const segments = tokenName.split(".").filter(Boolean);
|
|
67
|
-
if (segments.length === 0)
|
|
68
|
-
continue;
|
|
69
|
-
let node = root;
|
|
70
|
-
for (const segment of segments) {
|
|
71
|
-
let child = node.children.get(segment);
|
|
72
|
-
if (!child) {
|
|
73
|
-
child = { children: new Map() };
|
|
74
|
-
node.children.set(segment, child);
|
|
75
|
-
}
|
|
76
|
-
node = child;
|
|
77
|
-
}
|
|
78
|
-
node.token = token;
|
|
79
|
-
}
|
|
80
|
-
return root;
|
|
81
|
-
};
|
|
82
|
-
const renderTreeTs = (node, tokenNamePrefix) => {
|
|
83
|
-
const lines = ["{"];
|
|
84
|
-
const keys = [...node.children.keys()].sort((a, b) => a.localeCompare(b));
|
|
85
|
-
for (const key of keys) {
|
|
86
|
-
const child = node.children.get(key);
|
|
87
|
-
if (!child)
|
|
88
|
-
continue;
|
|
89
|
-
const fullTokenName = tokenNamePrefix ? `${tokenNamePrefix}.${key}` : key;
|
|
90
|
-
const propKey = toPropertyKey(key);
|
|
91
|
-
if (child.token && child.children.size === 0) {
|
|
92
|
-
lines.push(...buildTokenJsDocLines(fullTokenName, child.token));
|
|
93
|
-
lines.push(`${propKey}: "${fullTokenName}",`);
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
const childLines = renderTreeTs(child, fullTokenName);
|
|
97
|
-
lines.push(`${propKey}: ${childLines[0]}`);
|
|
98
|
-
lines.push(...indentLines(childLines.slice(1), 2));
|
|
99
|
-
lines[lines.length - 1] = `${lines[lines.length - 1]},`;
|
|
100
|
-
}
|
|
101
|
-
lines.push("}");
|
|
102
|
-
return lines;
|
|
103
|
-
};
|
|
104
|
-
const renderTreeDts = (node, tokenNamePrefix) => {
|
|
105
|
-
const lines = ["{"];
|
|
106
|
-
const keys = [...node.children.keys()].sort((a, b) => a.localeCompare(b));
|
|
107
|
-
for (const key of keys) {
|
|
108
|
-
const child = node.children.get(key);
|
|
109
|
-
if (!child)
|
|
110
|
-
continue;
|
|
111
|
-
const fullTokenName = tokenNamePrefix ? `${tokenNamePrefix}.${key}` : key;
|
|
112
|
-
const propKey = toPropertyKey(key);
|
|
113
|
-
if (child.token && child.children.size === 0) {
|
|
114
|
-
lines.push(...buildTokenJsDocLines(fullTokenName, child.token));
|
|
115
|
-
lines.push(`${propKey}: "${fullTokenName}";`);
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
const childLines = renderTreeDts(child, fullTokenName);
|
|
119
|
-
lines.push(`${propKey}: ${childLines[0]}`);
|
|
120
|
-
lines.push(...indentLines(childLines.slice(1), 2));
|
|
121
|
-
lines[lines.length - 1] = `${lines[lines.length - 1]};`;
|
|
122
|
-
}
|
|
123
|
-
lines.push("}");
|
|
124
|
-
return lines;
|
|
125
|
-
};
|
|
126
|
-
/**
|
|
127
|
-
* Generate `dist/palette/tokens.ts` and `dist/palette/tokens.d.ts` sources.
|
|
128
|
-
*
|
|
129
|
-
* Output is deterministic and derived from the token registry.
|
|
130
|
-
*/
|
|
131
|
-
export const generateTokenArtifacts = (registry) => {
|
|
132
|
-
const tokenNames = Object.keys(registry.tokens).sort((a, b) => a.localeCompare(b));
|
|
133
|
-
const tree = buildTree(registry);
|
|
134
|
-
const tokensObject = renderTreeTs(tree, "");
|
|
135
|
-
const tokensDtsObject = renderTreeDts(tree, "");
|
|
136
|
-
const tokensTs = `/* This file is generated by palette-kit build (Phase 7). */\n\nexport const tokens = ${tokensObject.join("\n")} as const;\n\nexport const tokenNames = ${JSON.stringify(tokenNames, null, 2)} as const;\n\nexport type TokenName = (typeof tokenNames)[number];\n\nexport type ColorRole = TokenName;\n`;
|
|
137
|
-
const tokensDts = `/* This file is generated by palette-kit build (Phase 7). */\n\nexport declare const tokens: ${tokensDtsObject.join("\n")};\n\nexport declare const tokenNames: readonly ${JSON.stringify(tokenNames, null, 2)};\n\nexport type TokenName = (typeof tokenNames)[number];\n\nexport type ColorRole = TokenName;\n`;
|
|
138
|
-
return { tokenNames, tokensTs, tokensDts };
|
|
139
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { generateTokenArtifacts } from "./tokens.js";
|
|
3
|
-
describe("codegen tokens", () => {
|
|
4
|
-
const registry = {
|
|
5
|
-
tokens: {
|
|
6
|
-
"bg.app": {
|
|
7
|
-
name: "bg.app",
|
|
8
|
-
description: "App background.",
|
|
9
|
-
category: "bg",
|
|
10
|
-
query: { role: "bg.app", usage: "bg", surface: "app" },
|
|
11
|
-
},
|
|
12
|
-
"text.primary": {
|
|
13
|
-
name: "text.primary",
|
|
14
|
-
description: "Primary text on standard surfaces.",
|
|
15
|
-
category: "text",
|
|
16
|
-
query: { role: "text.primary", usage: "text", surface: "surface" },
|
|
17
|
-
states: { hover: true },
|
|
18
|
-
},
|
|
19
|
-
"border.default": {
|
|
20
|
-
name: "border.default",
|
|
21
|
-
description: "Default border color.",
|
|
22
|
-
category: "border",
|
|
23
|
-
query: { role: "border.default", usage: "border", surface: "surface" },
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
it("generates navigable tokens.ts and tokens.d.ts", () => {
|
|
28
|
-
const { tokensTs, tokensDts } = generateTokenArtifacts(registry);
|
|
29
|
-
expect(tokensTs).toContain('export const tokens = {');
|
|
30
|
-
expect(tokensTs).toContain('bg: {');
|
|
31
|
-
expect(tokensTs).toContain('app: "bg.app"');
|
|
32
|
-
expect(tokensTs).toContain('text: {');
|
|
33
|
-
expect(tokensTs).toContain('primary: "text.primary"');
|
|
34
|
-
expect(tokensTs).toMatchSnapshot();
|
|
35
|
-
expect(tokensDts).toMatchSnapshot();
|
|
36
|
-
});
|
|
37
|
-
it("is deterministic regardless of registry object order", () => {
|
|
38
|
-
const shuffled = {
|
|
39
|
-
tokens: {
|
|
40
|
-
"text.primary": registry.tokens["text.primary"],
|
|
41
|
-
"bg.app": registry.tokens["bg.app"],
|
|
42
|
-
"border.default": registry.tokens["border.default"],
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
const a = generateTokenArtifacts(registry);
|
|
46
|
-
const b = generateTokenArtifacts(shuffled);
|
|
47
|
-
expect(b.tokenNames).toEqual(a.tokenNames);
|
|
48
|
-
expect(b.tokensTs).toBe(a.tokensTs);
|
|
49
|
-
expect(b.tokensDts).toBe(a.tokensDts);
|
|
50
|
-
});
|
|
51
|
-
});
|
package/dist/cli/config.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { ThemeConfig } from "../engine/resolveBaseColor.js";
|
|
2
|
-
import type { OutputOptions } from "../types/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Official token preset names supported by Palette Kit tooling.
|
|
5
|
-
*
|
|
6
|
-
* These map to `src/presets/tokens/*` registries.
|
|
7
|
-
*/
|
|
8
|
-
export type TokenPresetName = "minimal-ui" | "radixLike-ui" | "modern-ui";
|
|
9
|
-
/**
|
|
10
|
-
* Configuration contract for `palette-kit build`.
|
|
11
|
-
*
|
|
12
|
-
* This file is consumed by the CLI and is intended to be used from
|
|
13
|
-
* `palette.config.ts` created by `palette-kit init`.
|
|
14
|
-
*/
|
|
15
|
-
export type PaletteConfig = {
|
|
16
|
-
/**
|
|
17
|
-
* Theme inputs for palette generation (seed colors + optional variants).
|
|
18
|
-
*/
|
|
19
|
-
theme: ThemeConfig;
|
|
20
|
-
/**
|
|
21
|
-
* Token preset selection for exporters/CLI.
|
|
22
|
-
*/
|
|
23
|
-
tokens: {
|
|
24
|
-
preset: TokenPresetName;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Exporter options (formatting, gamut mapping, precision).
|
|
28
|
-
*/
|
|
29
|
-
output?: OutputOptions;
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Build a `palette.config.ts` template for `palette-kit init`.
|
|
33
|
-
*
|
|
34
|
-
* @param packageName - Import path used for `PaletteConfig` typing (usually the package name).
|
|
35
|
-
*/
|
|
36
|
-
export declare const buildConfigTemplate: (packageName: string) => string;
|
|
37
|
-
/**
|
|
38
|
-
* Runtime guard for token preset strings coming from user config.
|
|
39
|
-
*/
|
|
40
|
-
export declare const isTokenPresetName: (value: string) => value is TokenPresetName;
|
package/dist/cli/config.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Build a `palette.config.ts` template for `palette-kit init`.
|
|
3
|
-
*
|
|
4
|
-
* @param packageName - Import path used for `PaletteConfig` typing (usually the package name).
|
|
5
|
-
*/
|
|
6
|
-
export const buildConfigTemplate = (packageName) => `import type { PaletteConfig } from "${packageName}";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Palette Kit configuration.
|
|
10
|
-
* Update seeds, preset, and output options to match your design system.
|
|
11
|
-
*/
|
|
12
|
-
const config: PaletteConfig = {
|
|
13
|
-
theme: {
|
|
14
|
-
seeds: {
|
|
15
|
-
light: { neutral: "#8B8D98", accent: "#3D63DD" },
|
|
16
|
-
dark: { neutral: "#8B8D98", accent: "#3D63DD" },
|
|
17
|
-
},
|
|
18
|
-
preset: "modern",
|
|
19
|
-
},
|
|
20
|
-
tokens: {
|
|
21
|
-
preset: "modern-ui",
|
|
22
|
-
},
|
|
23
|
-
output: {
|
|
24
|
-
preferSpace: "oklch",
|
|
25
|
-
includeSpaces: ["srgb", "p3"],
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default config;
|
|
30
|
-
`;
|
|
31
|
-
/**
|
|
32
|
-
* Runtime guard for token preset strings coming from user config.
|
|
33
|
-
*/
|
|
34
|
-
export const isTokenPresetName = (value) => value === "minimal-ui" || value === "radixLike-ui" || value === "modern-ui";
|
package/dist/cli/validate.d.ts
DELETED
package/dist/cli/validate.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { isTokenPresetName } from "./config.js";
|
|
2
|
-
const validateSeed = (context, value) => {
|
|
3
|
-
if (!value || typeof value !== "object") {
|
|
4
|
-
throw new Error(`Config.theme.seeds.${context} must be an object`);
|
|
5
|
-
}
|
|
6
|
-
const seed = value;
|
|
7
|
-
if (typeof seed.neutral !== "string") {
|
|
8
|
-
throw new Error(`Config.theme.seeds.${context}.neutral must be a string color`);
|
|
9
|
-
}
|
|
10
|
-
if (typeof seed.accent !== "string") {
|
|
11
|
-
throw new Error(`Config.theme.seeds.${context}.accent must be a string color`);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
export const validateConfig = (config) => {
|
|
15
|
-
if (!config || typeof config !== "object") {
|
|
16
|
-
throw new Error("Config must export a default object");
|
|
17
|
-
}
|
|
18
|
-
if (!config.theme) {
|
|
19
|
-
throw new Error("Config.theme is required");
|
|
20
|
-
}
|
|
21
|
-
const seeds = config.theme.seeds;
|
|
22
|
-
if (!seeds?.light || !seeds?.dark) {
|
|
23
|
-
throw new Error("Config.theme.seeds.light and .dark are required");
|
|
24
|
-
}
|
|
25
|
-
validateSeed("light", seeds.light);
|
|
26
|
-
validateSeed("dark", seeds.dark);
|
|
27
|
-
if (!config.tokens?.preset) {
|
|
28
|
-
throw new Error("Config.tokens.preset is required");
|
|
29
|
-
}
|
|
30
|
-
if (!isTokenPresetName(config.tokens.preset)) {
|
|
31
|
-
throw new Error(`Unsupported token preset: ${config.tokens.preset}`);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { validateConfig } from "./validate.js";
|
|
3
|
-
describe("cli config validation", () => {
|
|
4
|
-
it("accepts a valid config", () => {
|
|
5
|
-
const config = {
|
|
6
|
-
theme: {
|
|
7
|
-
seeds: {
|
|
8
|
-
light: { neutral: "#111827", accent: "#3d63dd" },
|
|
9
|
-
dark: { neutral: "#111827", accent: "#3d63dd" },
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
tokens: { preset: "modern-ui" },
|
|
13
|
-
};
|
|
14
|
-
expect(() => validateConfig(config)).not.toThrow();
|
|
15
|
-
});
|
|
16
|
-
it("rejects missing neutral/accent", () => {
|
|
17
|
-
const config = {
|
|
18
|
-
theme: {
|
|
19
|
-
seeds: {
|
|
20
|
-
light: { neutral: "#111827" },
|
|
21
|
-
dark: { accent: "#3d63dd" },
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
tokens: { preset: "modern-ui" },
|
|
25
|
-
};
|
|
26
|
-
expect(() => validateConfig(config)).toThrow(/must be a string color/);
|
|
27
|
-
});
|
|
28
|
-
it("rejects invalid preset", () => {
|
|
29
|
-
const config = {
|
|
30
|
-
theme: {
|
|
31
|
-
seeds: {
|
|
32
|
-
light: { neutral: "#111827", accent: "#3d63dd" },
|
|
33
|
-
dark: { neutral: "#111827", accent: "#3d63dd" },
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
tokens: { preset: "nope" },
|
|
37
|
-
};
|
|
38
|
-
expect(() => validateConfig(config)).toThrow(/Unsupported token preset/);
|
|
39
|
-
});
|
|
40
|
-
});
|
package/dist/cli.d.ts
DELETED