@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.
Files changed (312) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +80 -87
  3. package/dist/contrast/contrast.d.ts +16 -0
  4. package/dist/contrast/contrast.js +102 -0
  5. package/dist/core/intent-registry.d.ts +11 -0
  6. package/dist/core/intent-registry.js +70 -0
  7. package/dist/core/oklch.d.ts +16 -0
  8. package/dist/core/oklch.js +56 -0
  9. package/dist/create-palette-kit.d.ts +9 -0
  10. package/dist/create-palette-kit.js +67 -0
  11. package/dist/engine/context/context.d.ts +13 -0
  12. package/dist/engine/context/context.js +37 -0
  13. package/dist/engine/level/curves.d.ts +17 -0
  14. package/dist/engine/level/curves.js +49 -0
  15. package/dist/engine/level/level.d.ts +4 -0
  16. package/dist/engine/level/level.js +13 -0
  17. package/dist/engine/relation/relation.d.ts +105 -0
  18. package/dist/engine/relation/relation.js +137 -0
  19. package/dist/engine/resolve/resolve.d.ts +36 -0
  20. package/dist/engine/resolve/resolve.js +116 -0
  21. package/dist/engine/state/state.d.ts +46 -0
  22. package/dist/engine/state/state.js +68 -0
  23. package/dist/engine/usage/fill.d.ts +9 -0
  24. package/dist/engine/usage/fill.js +9 -0
  25. package/dist/engine/usage/lines.d.ts +9 -0
  26. package/dist/engine/usage/lines.js +9 -0
  27. package/dist/engine/usage/overlays.d.ts +9 -0
  28. package/dist/engine/usage/overlays.js +9 -0
  29. package/dist/engine/usage/strategy.d.ts +56 -0
  30. package/dist/engine/usage/strategy.js +30 -0
  31. package/dist/engine/usage/visualVocabulary.d.ts +9 -0
  32. package/dist/engine/usage/visualVocabulary.js +9 -0
  33. package/dist/export/serialize.d.ts +14 -0
  34. package/dist/export/serialize.js +89 -0
  35. package/dist/export/types.d.ts +37 -0
  36. package/dist/export/types.js +31 -0
  37. package/dist/index.d.ts +3 -3
  38. package/dist/index.js +2 -2
  39. package/dist/operators/convert.d.ts +32 -0
  40. package/dist/operators/convert.js +80 -0
  41. package/dist/presets/presets.d.ts +95 -0
  42. package/dist/presets/presets.js +308 -0
  43. package/dist/types/index.d.ts +111 -187
  44. package/dist/utils/errors/errors.d.ts +17 -0
  45. package/dist/utils/errors/errors.js +22 -0
  46. package/docs/API.md +167 -0
  47. package/docs/Alpha.md +14 -0
  48. package/docs/Architecture.md +56 -0
  49. package/docs/CLI.md +22 -0
  50. package/docs/Concepts.md +73 -0
  51. package/docs/Config.md +144 -0
  52. package/docs/Diagnostics.md +22 -0
  53. package/docs/Exporters.md +33 -0
  54. package/docs/FAQ.md +59 -0
  55. package/docs/Migration.md +61 -0
  56. package/docs/Overlays.md +33 -0
  57. package/docs/README.md +60 -0
  58. package/docs/Text.md +41 -0
  59. package/docs/Tokens.md +42 -0
  60. package/docs/Usage-JSON.md +39 -0
  61. package/docs/Usage-ReactNative.md +63 -0
  62. package/docs/Usage-Web.md +66 -0
  63. package/docs/Validation.md +97 -0
  64. package/docs/Why.md +37 -0
  65. package/docs/_api-surface.md +53 -0
  66. package/docs/snippets/serialize-oklch.md +9 -0
  67. package/docs/spec.md +98 -0
  68. package/package.json +74 -59
  69. package/.codex/skills/color-pipeline-implementer/SKILL.md +0 -23
  70. package/.codex/skills/commit-message-crafter/SKILL.md +0 -63
  71. package/.codex/skills/commit-message-crafter/references/benchmarks.md +0 -20
  72. package/.codex/skills/contrast-solver-helper/SKILL.md +0 -20
  73. package/.codex/skills/exporters-builder/SKILL.md +0 -20
  74. package/.codex/skills/markdownlint-writer/SKILL.md +0 -32
  75. package/.codex/skills/phase-implementation-runbook/SKILL.md +0 -92
  76. package/.codex/skills/type-contract-auditor/SKILL.md +0 -21
  77. package/.github/skills/review-guide/SKILL.md +0 -23
  78. package/.github/skills/review-guide/references/review-guide-v0.3.md +0 -629
  79. package/.markdownlint.json +0 -4
  80. package/AGENTS.md +0 -16
  81. package/biome.json +0 -43
  82. package/dist/cli/args.d.ts +0 -12
  83. package/dist/cli/args.js +0 -56
  84. package/dist/cli/args.test.d.ts +0 -1
  85. package/dist/cli/args.test.js +0 -22
  86. package/dist/cli/codegen/__snapshots__/tokens.test.js.snap +0 -87
  87. package/dist/cli/codegen/tokens.d.ts +0 -12
  88. package/dist/cli/codegen/tokens.js +0 -139
  89. package/dist/cli/codegen/tokens.test.d.ts +0 -1
  90. package/dist/cli/codegen/tokens.test.js +0 -51
  91. package/dist/cli/config.d.ts +0 -40
  92. package/dist/cli/config.js +0 -34
  93. package/dist/cli/validate.d.ts +0 -2
  94. package/dist/cli/validate.js +0 -33
  95. package/dist/cli/validate.test.d.ts +0 -1
  96. package/dist/cli/validate.test.js +0 -40
  97. package/dist/cli.d.ts +0 -2
  98. package/dist/cli.js +0 -148
  99. package/dist/contrast/apca.d.ts +0 -2
  100. package/dist/contrast/apca.js +0 -15
  101. package/dist/contrast/apca.test.d.ts +0 -1
  102. package/dist/contrast/apca.test.js +0 -16
  103. package/dist/contrast/index.d.ts +0 -4
  104. package/dist/contrast/index.js +0 -4
  105. package/dist/contrast/scoring.d.ts +0 -4
  106. package/dist/contrast/scoring.js +0 -31
  107. package/dist/contrast/scoring.test.d.ts +0 -1
  108. package/dist/contrast/scoring.test.js +0 -148
  109. package/dist/contrast/solver.d.ts +0 -13
  110. package/dist/contrast/solver.js +0 -170
  111. package/dist/contrast/solver.test.d.ts +0 -1
  112. package/dist/contrast/solver.test.js +0 -75
  113. package/dist/contrast/types.d.ts +0 -17
  114. package/dist/contrast/types.js +0 -1
  115. package/dist/contrast/utils.d.ts +0 -4
  116. package/dist/contrast/utils.js +0 -18
  117. package/dist/contrast/wcag2.d.ts +0 -3
  118. package/dist/contrast/wcag2.js +0 -19
  119. package/dist/contrast/wcag2.test.d.ts +0 -1
  120. package/dist/contrast/wcag2.test.js +0 -17
  121. package/dist/core/createTheme.d.ts +0 -35
  122. package/dist/core/createTheme.js +0 -24
  123. package/dist/core/dx-helpers.test.d.ts +0 -1
  124. package/dist/core/dx-helpers.test.js +0 -61
  125. package/dist/core/index.d.ts +0 -2
  126. package/dist/core/index.js +0 -2
  127. package/dist/core/onSolid.test.d.ts +0 -1
  128. package/dist/core/onSolid.test.js +0 -118
  129. package/dist/core/qa.v1.test.d.ts +0 -1
  130. package/dist/core/qa.v1.test.js +0 -112
  131. package/dist/core/resolve.d.ts +0 -3
  132. package/dist/core/resolve.js +0 -8
  133. package/dist/core/resolve.test.d.ts +0 -1
  134. package/dist/core/resolve.test.js +0 -89
  135. package/dist/core/resolveMany.d.ts +0 -8
  136. package/dist/core/resolveMany.js +0 -17
  137. package/dist/core/tokenRegistry.d.ts +0 -23
  138. package/dist/core/tokenRegistry.js +0 -83
  139. package/dist/core/tokenRegistry.test.d.ts +0 -1
  140. package/dist/core/tokenRegistry.test.js +0 -133
  141. package/dist/engine/applyOperators.d.ts +0 -3
  142. package/dist/engine/applyOperators.js +0 -23
  143. package/dist/engine/context.d.ts +0 -4
  144. package/dist/engine/context.js +0 -1
  145. package/dist/engine/gamut.d.ts +0 -13
  146. package/dist/engine/gamut.js +0 -101
  147. package/dist/engine/gamut.test.d.ts +0 -1
  148. package/dist/engine/gamut.test.js +0 -23
  149. package/dist/engine/generateScale.d.ts +0 -15
  150. package/dist/engine/generateScale.js +0 -29
  151. package/dist/engine/generateScale.test.d.ts +0 -1
  152. package/dist/engine/generateScale.test.js +0 -32
  153. package/dist/engine/index.d.ts +0 -8
  154. package/dist/engine/index.js +0 -4
  155. package/dist/engine/normalize.d.ts +0 -43
  156. package/dist/engine/normalize.js +0 -403
  157. package/dist/engine/normalize.test.d.ts +0 -1
  158. package/dist/engine/normalize.test.js +0 -136
  159. package/dist/engine/onSolid.d.ts +0 -3
  160. package/dist/engine/onSolid.js +0 -110
  161. package/dist/engine/resolveBaseColor.d.ts +0 -25
  162. package/dist/engine/resolveBaseColor.js +0 -127
  163. package/dist/engine/resolveBaseColor.test.d.ts +0 -1
  164. package/dist/engine/resolveBaseColor.test.js +0 -97
  165. package/dist/export/__snapshots__/exportTheme.test.js.snap +0 -74
  166. package/dist/export/exportTheme.d.ts +0 -47
  167. package/dist/export/exportTheme.js +0 -170
  168. package/dist/export/exportTheme.test.d.ts +0 -1
  169. package/dist/export/exportTheme.test.js +0 -118
  170. package/dist/export/index.d.ts +0 -1
  171. package/dist/export/index.js +0 -1
  172. package/dist/export/serializeColor.d.ts +0 -1
  173. package/dist/export/serializeColor.js +0 -1
  174. package/dist/export/serializeColor.test.d.ts +0 -1
  175. package/dist/export/serializeColor.test.js +0 -54
  176. package/dist/export.d.ts +0 -1
  177. package/dist/export.js +0 -1
  178. package/dist/operators/emphasis.d.ts +0 -3
  179. package/dist/operators/emphasis.js +0 -113
  180. package/dist/operators/emphasis.test.d.ts +0 -1
  181. package/dist/operators/emphasis.test.js +0 -69
  182. package/dist/operators/index.d.ts +0 -3
  183. package/dist/operators/index.js +0 -2
  184. package/dist/operators/state.d.ts +0 -3
  185. package/dist/operators/state.js +0 -102
  186. package/dist/operators/state.test.d.ts +0 -1
  187. package/dist/operators/state.test.js +0 -48
  188. package/dist/operators/types.d.ts +0 -13
  189. package/dist/operators/types.js +0 -1
  190. package/dist/operators/utils.d.ts +0 -16
  191. package/dist/operators/utils.js +0 -23
  192. package/dist/presets/curves.d.ts +0 -28
  193. package/dist/presets/curves.js +0 -145
  194. package/dist/presets/index.d.ts +0 -2
  195. package/dist/presets/index.js +0 -1
  196. package/dist/presets/tokens/index.d.ts +0 -3
  197. package/dist/presets/tokens/index.js +0 -3
  198. package/dist/presets/tokens/minimal-ui.d.ts +0 -6
  199. package/dist/presets/tokens/minimal-ui.js +0 -53
  200. package/dist/presets/tokens/modern-ui.d.ts +0 -5
  201. package/dist/presets/tokens/modern-ui.js +0 -83
  202. package/dist/presets/tokens/presets.test.d.ts +0 -1
  203. package/dist/presets/tokens/presets.test.js +0 -31
  204. package/dist/presets/tokens/radixLike-ui.d.ts +0 -6
  205. package/dist/presets/tokens/radixLike-ui.js +0 -77
  206. package/dist/serialize/index.d.ts +0 -1
  207. package/dist/serialize/index.js +0 -1
  208. package/dist/serialize/normalizeOutput.d.ts +0 -6
  209. package/dist/serialize/normalizeOutput.js +0 -45
  210. package/dist/serialize/serializeColor.d.ts +0 -21
  211. package/dist/serialize/serializeColor.js +0 -178
  212. package/dist/serialize/serializeResolved.test.d.ts +0 -1
  213. package/dist/serialize/serializeResolved.test.js +0 -45
  214. package/dist/serialize.d.ts +0 -1
  215. package/dist/serialize.js +0 -1
  216. package/dist/utils/clamp.d.ts +0 -1
  217. package/dist/utils/clamp.js +0 -1
  218. package/dist/utils/index.d.ts +0 -1
  219. package/dist/utils/index.js +0 -1
  220. package/dist/utils/lerp.d.ts +0 -1
  221. package/dist/utils/lerp.js +0 -1
  222. package/dist/utils/parseColor.d.ts +0 -6
  223. package/dist/utils/parseColor.js +0 -67
  224. package/dist/utils/parseColor.test.d.ts +0 -1
  225. package/dist/utils/parseColor.test.js +0 -51
  226. package/dist/utils/smoothstep.d.ts +0 -1
  227. package/dist/utils/smoothstep.js +0 -5
  228. package/planning/phase-10-review.md +0 -550
  229. package/planning/phase-7-review.md +0 -411
  230. package/planning/phase-8-review.md +0 -669
  231. package/planning/phase-9-review.md +0 -564
  232. package/planning/roadmap-v0.3.md +0 -284
  233. package/planning/spec-serializer-v0.3.md +0 -324
  234. package/planning/spec-v0.3.md +0 -305
  235. package/src/cli/args.test.ts +0 -28
  236. package/src/cli/args.ts +0 -66
  237. package/src/cli/codegen/__snapshots__/tokens.test.ts.snap +0 -87
  238. package/src/cli/codegen/tokens.test.ts +0 -61
  239. package/src/cli/codegen/tokens.ts +0 -191
  240. package/src/cli/config.ts +0 -71
  241. package/src/cli/validate.test.ts +0 -49
  242. package/src/cli/validate.ts +0 -38
  243. package/src/cli.ts +0 -183
  244. package/src/contrast/apca.test.ts +0 -20
  245. package/src/contrast/apca.ts +0 -26
  246. package/src/contrast/index.ts +0 -4
  247. package/src/contrast/scoring.test.ts +0 -188
  248. package/src/contrast/scoring.ts +0 -48
  249. package/src/contrast/solver.test.ts +0 -147
  250. package/src/contrast/solver.ts +0 -235
  251. package/src/contrast/types.ts +0 -20
  252. package/src/contrast/utils.ts +0 -28
  253. package/src/contrast/wcag2.test.ts +0 -21
  254. package/src/contrast/wcag2.ts +0 -24
  255. package/src/core/createTheme.ts +0 -78
  256. package/src/core/dx-helpers.test.ts +0 -82
  257. package/src/core/index.ts +0 -7
  258. package/src/core/onSolid.test.ts +0 -146
  259. package/src/core/qa.v1.test.ts +0 -149
  260. package/src/core/resolve.test.ts +0 -99
  261. package/src/core/resolve.ts +0 -11
  262. package/src/core/resolveMany.ts +0 -22
  263. package/src/core/tokenRegistry.test.ts +0 -153
  264. package/src/core/tokenRegistry.ts +0 -114
  265. package/src/engine/applyOperators.ts +0 -32
  266. package/src/engine/context.ts +0 -8
  267. package/src/engine/gamut.test.ts +0 -30
  268. package/src/engine/gamut.ts +0 -144
  269. package/src/engine/generateScale.test.ts +0 -46
  270. package/src/engine/generateScale.ts +0 -48
  271. package/src/engine/index.ts +0 -8
  272. package/src/engine/normalize.test.ts +0 -222
  273. package/src/engine/normalize.ts +0 -550
  274. package/src/engine/onSolid.ts +0 -178
  275. package/src/engine/resolveBaseColor.test.ts +0 -117
  276. package/src/engine/resolveBaseColor.ts +0 -203
  277. package/src/export/__snapshots__/exportTheme.test.ts.snap +0 -74
  278. package/src/export/exportTheme.test.ts +0 -144
  279. package/src/export/exportTheme.ts +0 -251
  280. package/src/export/index.ts +0 -1
  281. package/src/export/serializeColor.test.ts +0 -73
  282. package/src/export/serializeColor.ts +0 -1
  283. package/src/export.ts +0 -1
  284. package/src/index.ts +0 -3
  285. package/src/operators/emphasis.test.ts +0 -85
  286. package/src/operators/emphasis.ts +0 -132
  287. package/src/operators/index.ts +0 -3
  288. package/src/operators/state.test.ts +0 -66
  289. package/src/operators/state.ts +0 -122
  290. package/src/operators/types.ts +0 -14
  291. package/src/operators/utils.ts +0 -44
  292. package/src/presets/curves.ts +0 -168
  293. package/src/presets/index.ts +0 -2
  294. package/src/presets/tokens/index.ts +0 -3
  295. package/src/presets/tokens/minimal-ui.ts +0 -55
  296. package/src/presets/tokens/modern-ui.ts +0 -85
  297. package/src/presets/tokens/presets.test.ts +0 -46
  298. package/src/presets/tokens/radixLike-ui.ts +0 -79
  299. package/src/serialize/index.ts +0 -1
  300. package/src/serialize/normalizeOutput.ts +0 -63
  301. package/src/serialize/serializeColor.ts +0 -260
  302. package/src/serialize/serializeResolved.test.ts +0 -57
  303. package/src/serialize.ts +0 -1
  304. package/src/types/index.ts +0 -207
  305. package/src/utils/clamp.ts +0 -2
  306. package/src/utils/index.ts +0 -1
  307. package/src/utils/lerp.ts +0 -1
  308. package/src/utils/parseColor.test.ts +0 -66
  309. package/src/utils/parseColor.ts +0 -87
  310. package/src/utils/smoothstep.ts +0 -6
  311. package/tsconfig.build.json +0 -11
  312. package/tsconfig.json +0 -15
@@ -1,3 +0,0 @@
1
- export { applyEmphasisOperator } from "./emphasis.js";
2
- export { applyStateOperator } from "./state.js";
3
- export type { OperatorInput } from "./types.js";
@@ -1,66 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import { applyStateOperator } from "./state.js";
4
-
5
- const base = {
6
- oklch: { l: 60, c: 0.12, h: 210 },
7
- context: "light" as const,
8
- surface: "surface" as const,
9
- usage: "bg" as const,
10
- state: "default" as const,
11
- emphasis: "default" as const,
12
- preset: "modern" as const,
13
- step: 9,
14
- };
15
-
16
- describe("applyStateOperator", () => {
17
- it("darkens hover in light context", () => {
18
- const result = applyStateOperator({ ...base, state: "hover" });
19
-
20
- expect(result.l).toBeLessThan(base.oklch.l);
21
- });
22
-
23
- it("lightens hover in dark context", () => {
24
- const result = applyStateOperator({ ...base, context: "dark", state: "hover" });
25
-
26
- expect(result.l).toBeGreaterThan(base.oklch.l);
27
- });
28
-
29
- it("active is stronger than hover", () => {
30
- const hover = applyStateOperator({ ...base, state: "hover" });
31
- const active = applyStateOperator({ ...base, state: "active" });
32
-
33
- expect(Math.abs(active.l - base.oklch.l)).toBeGreaterThan(Math.abs(hover.l - base.oklch.l));
34
- });
35
-
36
- it("selected is less aggressive than active", () => {
37
- const selected = applyStateOperator({ ...base, state: "selected" });
38
- const active = applyStateOperator({ ...base, state: "active" });
39
-
40
- expect(Math.abs(selected.l - base.oklch.l)).toBeLessThan(Math.abs(active.l - base.oklch.l));
41
- });
42
-
43
- it("disabled reduces chroma", () => {
44
- const disabled = applyStateOperator({ ...base, state: "disabled" });
45
-
46
- expect(disabled.c).toBeLessThan(base.oklch.c * 0.6);
47
- });
48
-
49
- it("returns the original color for default state", () => {
50
- const result = applyStateOperator({ ...base, state: "default" });
51
-
52
- expect(result).toEqual(base.oklch);
53
- });
54
-
55
- it("focus only affects ring and border usage", () => {
56
- const bgFocus = applyStateOperator({ ...base, usage: "bg", state: "focus" });
57
- const ringFocus = applyStateOperator({ ...base, usage: "ring", state: "focus" });
58
- const borderFocus = applyStateOperator({ ...base, usage: "border", state: "focus" });
59
-
60
- expect(bgFocus.l).toBeCloseTo(base.oklch.l, 6);
61
- expect(ringFocus.l).not.toBeCloseTo(base.oklch.l, 6);
62
- expect(Math.abs(borderFocus.l - base.oklch.l)).toBeLessThan(
63
- Math.abs(ringFocus.l - base.oklch.l),
64
- );
65
- });
66
- });
@@ -1,122 +0,0 @@
1
- import type { OkLchColor } from "../engine/generateScale.js";
2
- import { clamp } from "../utils/clamp.js";
3
- import type { OperatorInput } from "./types.js";
4
- import { getNeutralL, getSurfaceRange } from "./utils.js";
5
-
6
- type StateTuning = {
7
- hover: number;
8
- active: number;
9
- selected: number;
10
- focus: number;
11
- disabledChroma: number;
12
- disabledNeutralPull: number;
13
- };
14
-
15
- const STATE_TUNING: Record<OperatorInput["surface"], StateTuning> = {
16
- app: {
17
- hover: 2,
18
- active: 4,
19
- selected: 3,
20
- focus: 2,
21
- disabledChroma: 0.45,
22
- disabledNeutralPull: 0.45,
23
- },
24
- surface: {
25
- hover: 2.5,
26
- active: 4.5,
27
- selected: 3.5,
28
- focus: 2.5,
29
- disabledChroma: 0.45,
30
- disabledNeutralPull: 0.45,
31
- },
32
- subtle: {
33
- hover: 3,
34
- active: 5.5,
35
- selected: 4,
36
- focus: 3,
37
- disabledChroma: 0.45,
38
- disabledNeutralPull: 0.5,
39
- },
40
- solid: {
41
- hover: 4,
42
- active: 7,
43
- selected: 5,
44
- focus: 4,
45
- disabledChroma: 0.4,
46
- disabledNeutralPull: 0.55,
47
- },
48
- overlay: {
49
- hover: 3,
50
- active: 5.5,
51
- selected: 4,
52
- focus: 3,
53
- disabledChroma: 0.45,
54
- disabledNeutralPull: 0.5,
55
- },
56
- data: {
57
- hover: 4,
58
- active: 7,
59
- selected: 5,
60
- focus: 4,
61
- disabledChroma: 0.4,
62
- disabledNeutralPull: 0.55,
63
- },
64
- transparent: {
65
- hover: 2,
66
- active: 4,
67
- selected: 3,
68
- focus: 2,
69
- disabledChroma: 0.45,
70
- disabledNeutralPull: 0.45,
71
- },
72
- };
73
-
74
- const FOCUS_BORDER_SCALE = 0.6;
75
-
76
- const clampOkLch = (color: OkLchColor, maxChroma: number): OkLchColor => ({
77
- ...color,
78
- l: clamp(color.l, 0, 100),
79
- c: clamp(color.c, 0, maxChroma),
80
- });
81
-
82
- export const applyStateOperator = (input: OperatorInput): OkLchColor => {
83
- const { state, context, surface, usage } = input;
84
- const tuning = STATE_TUNING[surface];
85
- const range = getSurfaceRange(input.preset, surface, context);
86
- const neutralL = getNeutralL(input.preset, surface, context);
87
- const direction = context === "light" ? -1 : 1;
88
-
89
- if (state === "default") {
90
- return input.oklch;
91
- }
92
-
93
- if (state === "focus" && usage !== "ring" && usage !== "border") {
94
- return input.oklch;
95
- }
96
-
97
- const next: OkLchColor = { ...input.oklch };
98
-
99
- switch (state) {
100
- case "hover":
101
- next.l += direction * tuning.hover;
102
- break;
103
- case "active":
104
- next.l += direction * tuning.active;
105
- break;
106
- case "selected":
107
- next.l += direction * tuning.selected;
108
- break;
109
- case "focus":
110
- next.l += direction * tuning.focus * (usage === "border" ? FOCUS_BORDER_SCALE : 1);
111
- break;
112
- case "disabled":
113
- next.c *= tuning.disabledChroma;
114
- next.l += (neutralL - next.l) * tuning.disabledNeutralPull;
115
- break;
116
- default:
117
- // Allow unknown/future states to be no-ops to avoid unexpected shifts.
118
- return input.oklch;
119
- }
120
-
121
- return clampOkLch(next, range.cMax);
122
- };
@@ -1,14 +0,0 @@
1
- import type { OkLchColor } from "../engine/generateScale.js";
2
- import type { CurvePresetName } from "../presets/index.js";
3
- import type { ColorEmphasis, ColorState, ColorUsage, SurfaceIntent } from "../types/index.js";
4
-
5
- export type OperatorInput = {
6
- oklch: OkLchColor;
7
- context: "light" | "dark";
8
- surface: SurfaceIntent;
9
- usage: ColorUsage;
10
- state: ColorState;
11
- emphasis: ColorEmphasis;
12
- preset?: CurvePresetName;
13
- step: number;
14
- };
@@ -1,44 +0,0 @@
1
- import type { CurvePresetName } from "../presets/index.js";
2
- import { curvePresets } from "../presets/index.js";
3
- import type { SurfaceIntent } from "../types/index.js";
4
- import { clamp } from "../utils/clamp.js";
5
- import { lerp } from "../utils/lerp.js";
6
-
7
- // TODO: deduplicate with generateScale constants and helpers.
8
- const STEPS = 12;
9
- const OKLCH_L_MIN = 0;
10
- const OKLCH_L_MAX = 100;
11
-
12
- export type OperatorContext = "light" | "dark";
13
-
14
- export const getSurfaceRange = (
15
- presetName: CurvePresetName | undefined,
16
- surface: SurfaceIntent,
17
- context: OperatorContext,
18
- ) => {
19
- const preset = curvePresets[presetName ?? "modern"];
20
- return preset.surfaces[surface].ranges[context];
21
- };
22
-
23
- export const getNeutralL = (
24
- presetName: CurvePresetName | undefined,
25
- surface: SurfaceIntent,
26
- context: OperatorContext,
27
- ) => {
28
- const range = getSurfaceRange(presetName, surface, context);
29
- return (range.l[0] + range.l[1]) / 2;
30
- };
31
-
32
- export const getStepLightness = (
33
- presetName: CurvePresetName | undefined,
34
- surface: SurfaceIntent,
35
- context: OperatorContext,
36
- step: number,
37
- ) => {
38
- const preset = curvePresets[presetName ?? "modern"];
39
- const surfaceCurve = preset.surfaces[surface];
40
- const range = surfaceCurve.ranges[context];
41
- const t = clamp((step - 1) / (STEPS - 1), 0, 1);
42
- const lightnessT = surfaceCurve.l(t);
43
- return clamp(lerp(range.l[0], range.l[1], lightnessT), OKLCH_L_MIN, OKLCH_L_MAX);
44
- };
@@ -1,168 +0,0 @@
1
- import type { SurfaceIntent } from "../types/index.js";
2
- import { clamp } from "../utils/clamp.js";
3
- import { smoothstep } from "../utils/smoothstep.js";
4
-
5
- export type CurvePresetName = "modern" | "radixLike";
6
-
7
- export type CurveFn = (t: number) => number;
8
-
9
- export type SurfaceCurve = {
10
- l: CurveFn;
11
- c: CurveFn;
12
- ranges: {
13
- light: { l: [number, number]; cMin: number; cMax: number; chromaBoost?: number };
14
- dark: { l: [number, number]; cMin: number; cMax: number; chromaBoost?: number };
15
- };
16
- };
17
-
18
- export type CurvePreset = {
19
- name: CurvePresetName;
20
- surfaces: Record<SurfaceIntent, SurfaceCurve>;
21
- };
22
-
23
- const normalizeT = (t: number) => clamp(t, 0, 1);
24
- const lightnessCurve: CurveFn = (t) => smoothstep(normalizeT(t));
25
- const chromaCurve: CurveFn = (t) => Math.sin(Math.PI * normalizeT(t));
26
-
27
- export const modern: CurvePreset = {
28
- name: "modern",
29
- surfaces: {
30
- // app: fundo do app (separação mínima, chroma baixíssimo)
31
- app: {
32
- l: lightnessCurve,
33
- c: chromaCurve,
34
- ranges: {
35
- light: { l: [90, 99], cMin: 0.004, cMax: 0.05 },
36
- dark: { l: [6, 22], cMin: 0.004, cMax: 0.07 },
37
- },
38
- },
39
- // surface: cards/panels (separação leve do app bg, chroma baixo)
40
- surface: {
41
- l: lightnessCurve,
42
- c: chromaCurve,
43
- ranges: {
44
- light: { l: [84, 97], cMin: 0.008, cMax: 0.08 },
45
- dark: { l: [8, 28], cMin: 0.008, cMax: 0.09 },
46
- },
47
- },
48
- // subtle: tints/hover backgrounds (um pouco mais de chroma, ainda calmo)
49
- subtle: {
50
- l: lightnessCurve,
51
- c: chromaCurve,
52
- ranges: {
53
- light: { l: [78, 95], cMin: 0.012, cMax: 0.1 },
54
- dark: { l: [10, 32], cMin: 0.012, cMax: 0.11 },
55
- },
56
- },
57
- // solid: backgrounds sólidos (chroma mais alto, pensado para onSolid)
58
- solid: {
59
- l: lightnessCurve,
60
- c: chromaCurve,
61
- ranges: {
62
- light: { l: [46, 90], cMin: 0.03, cMax: 0.18, chromaBoost: 1.25 },
63
- dark: { l: [12, 42], cMin: 0.03, cMax: 0.2, chromaBoost: 1.25 },
64
- },
65
- },
66
- // overlay: modal surfaces/scrims (chroma baixo, controle forte de L)
67
- overlay: {
68
- l: lightnessCurve,
69
- c: chromaCurve,
70
- ranges: {
71
- light: { l: [72, 96], cMin: 0.01, cMax: 0.09 },
72
- dark: { l: [14, 40], cMin: 0.01, cMax: 0.1 },
73
- },
74
- },
75
- // data: charts/heatmaps (pode usar chroma maior sem “gritar”)
76
- data: {
77
- l: lightnessCurve,
78
- c: chromaCurve,
79
- ranges: {
80
- light: { l: [38, 86], cMin: 0.04, cMax: 0.22, chromaBoost: 1.3 },
81
- dark: { l: [18, 48], cMin: 0.04, cMax: 0.24, chromaBoost: 1.3 },
82
- },
83
- },
84
- // transparent: base quase neutra (chroma quase zero; usado para ghost)
85
- transparent: {
86
- l: lightnessCurve,
87
- c: chromaCurve,
88
- ranges: {
89
- light: { l: [62, 96], cMin: 0, cMax: 0.06 },
90
- dark: { l: [8, 30], cMin: 0, cMax: 0.07 },
91
- },
92
- },
93
- },
94
- };
95
-
96
- export const radixLike: CurvePreset = {
97
- name: "radixLike",
98
- surfaces: {
99
- // app: fundo do app (separação mínima, chroma baixíssimo)
100
- app: {
101
- l: lightnessCurve,
102
- c: chromaCurve,
103
- ranges: {
104
- light: { l: [92, 99], cMin: 0.003, cMax: 0.06 },
105
- dark: { l: [4, 18], cMin: 0.003, cMax: 0.08 },
106
- },
107
- },
108
- // surface: cards/panels (separação leve do app bg, chroma baixo)
109
- surface: {
110
- l: lightnessCurve,
111
- c: chromaCurve,
112
- ranges: {
113
- light: { l: [86, 97], cMin: 0.006, cMax: 0.1 },
114
- dark: { l: [6, 24], cMin: 0.006, cMax: 0.11 },
115
- },
116
- },
117
- // subtle: tints/hover backgrounds (um pouco mais de chroma, ainda calmo)
118
- subtle: {
119
- l: lightnessCurve,
120
- c: chromaCurve,
121
- ranges: {
122
- light: { l: [80, 94], cMin: 0.01, cMax: 0.12 },
123
- dark: { l: [8, 30], cMin: 0.01, cMax: 0.13 },
124
- },
125
- },
126
- // solid: backgrounds sólidos (chroma mais alto, pensado para onSolid)
127
- solid: {
128
- l: lightnessCurve,
129
- c: chromaCurve,
130
- ranges: {
131
- light: { l: [50, 88], cMin: 0.035, cMax: 0.2, chromaBoost: 1.25 },
132
- dark: { l: [10, 38], cMin: 0.035, cMax: 0.22, chromaBoost: 1.25 },
133
- },
134
- },
135
- // overlay: modal surfaces/scrims (chroma baixo, controle forte de L)
136
- overlay: {
137
- l: lightnessCurve,
138
- c: chromaCurve,
139
- ranges: {
140
- light: { l: [74, 96], cMin: 0.01, cMax: 0.11 },
141
- dark: { l: [12, 38], cMin: 0.01, cMax: 0.12 },
142
- },
143
- },
144
- // data: charts/heatmaps (pode usar chroma maior sem “gritar”)
145
- data: {
146
- l: lightnessCurve,
147
- c: chromaCurve,
148
- ranges: {
149
- light: { l: [40, 84], cMin: 0.05, cMax: 0.24, chromaBoost: 1.3 },
150
- dark: { l: [16, 46], cMin: 0.05, cMax: 0.26, chromaBoost: 1.3 },
151
- },
152
- },
153
- // transparent: base quase neutra (chroma quase zero; usado para ghost)
154
- transparent: {
155
- l: lightnessCurve,
156
- c: chromaCurve,
157
- ranges: {
158
- light: { l: [60, 94], cMin: 0, cMax: 0.08 },
159
- dark: { l: [6, 28], cMin: 0, cMax: 0.09 },
160
- },
161
- },
162
- },
163
- };
164
-
165
- export const curvePresets: Record<CurvePresetName, CurvePreset> = {
166
- modern,
167
- radixLike,
168
- };
@@ -1,2 +0,0 @@
1
- export type { CurveFn, CurvePreset, CurvePresetName, SurfaceCurve } from "./curves.js";
2
- export { curvePresets, modern, radixLike } from "./curves.js";
@@ -1,3 +0,0 @@
1
- export { minimalUiTokens } from "./minimal-ui.js";
2
- export { modernUiTokens } from "./modern-ui.js";
3
- export { radixLikeUiTokens } from "./radixLike-ui.js";
@@ -1,55 +0,0 @@
1
- import type { TokenRegistry } from "../../types/index.js";
2
-
3
- /**
4
- * Minimal token preset aimed at quick adoption.
5
- * Focuses on a small, coherent base set for app surfaces and text.
6
- */
7
- export const minimalUiTokens: TokenRegistry = {
8
- tokens: {
9
- "bg.app": {
10
- name: "bg.app",
11
- description: "Base application background.",
12
- category: "background",
13
- query: { role: "bg.app", usage: "bg", surface: "app" },
14
- },
15
- "bg.surface": {
16
- name: "bg.surface",
17
- description: "Default surface background for containers.",
18
- category: "background",
19
- query: { role: "bg.surface", usage: "bg", surface: "surface" },
20
- },
21
- "text.primary": {
22
- name: "text.primary",
23
- description: "Primary text on standard surfaces.",
24
- category: "text",
25
- query: { role: "text.primary", usage: "text", surface: "surface" },
26
- },
27
- "text.secondary": {
28
- name: "text.secondary",
29
- description: "Secondary text on standard surfaces.",
30
- category: "text",
31
- query: { role: "text.secondary", usage: "text", surface: "surface", emphasis: "muted" },
32
- },
33
- "border.default": {
34
- name: "border.default",
35
- description: "Default border for surfaces and containers.",
36
- category: "border",
37
- query: { role: "border.default", usage: "border", surface: "surface" },
38
- states: { hover: true },
39
- },
40
- "icon.default": {
41
- name: "icon.default",
42
- description: "Default icon color on standard surfaces.",
43
- category: "icon",
44
- query: { role: "icon.default", usage: "icon", surface: "surface" },
45
- states: { hover: true },
46
- },
47
- "ring.default": {
48
- name: "ring.default",
49
- description: "Base ring color (derive focus via state operator).",
50
- category: "ring",
51
- query: { role: "ring.default", usage: "ring", surface: "surface", emphasis: "strong" },
52
- states: { focus: true },
53
- },
54
- },
55
- };
@@ -1,85 +0,0 @@
1
- import type { TokenRegistry } from "../../types/index.js";
2
-
3
- /**
4
- * Modern preset aimed at richer UI surfaces with strong emphasis options.
5
- */
6
- export const modernUiTokens: TokenRegistry = {
7
- tokens: {
8
- "bg.app": {
9
- name: "bg.app",
10
- description: "Primary application background.",
11
- category: "background",
12
- query: { role: "bg.app", usage: "bg", surface: "app" },
13
- },
14
- "bg.surface": {
15
- name: "bg.surface",
16
- description: "Default surface background for content containers.",
17
- category: "background",
18
- query: { role: "bg.surface", usage: "bg", surface: "surface" },
19
- },
20
- "bg.subtle": {
21
- name: "bg.subtle",
22
- description: "Subtle surface for secondary sections.",
23
- category: "background",
24
- query: { role: "bg.subtle", usage: "bg", surface: "subtle" },
25
- },
26
- "bg.solid": {
27
- name: "bg.solid",
28
- description: "Solid surface for emphasized elements.",
29
- category: "background",
30
- query: { role: "bg.solid", usage: "bg", surface: "solid" },
31
- states: { hover: true, active: true },
32
- },
33
- "text.primary": {
34
- name: "text.primary",
35
- description: "Primary text for default surfaces.",
36
- category: "text",
37
- query: { role: "text.primary", usage: "text", surface: "surface" },
38
- },
39
- "text.secondary": {
40
- name: "text.secondary",
41
- description: "Secondary text for supporting content.",
42
- category: "text",
43
- query: { role: "text.secondary", usage: "text", surface: "surface", emphasis: "muted" },
44
- },
45
- "text.inverse": {
46
- name: "text.inverse",
47
- description: "Inverse text for solid or accented surfaces.",
48
- category: "text",
49
- query: { role: "text.inverse", usage: "text", surface: "solid", emphasis: "inverted" },
50
- },
51
- "border.default": {
52
- name: "border.default",
53
- description: "Default border for containers and layout.",
54
- category: "border",
55
- query: { role: "border.default", usage: "border", surface: "surface" },
56
- },
57
- "border.strong": {
58
- name: "border.strong",
59
- description: "High-emphasis border for focused containers.",
60
- category: "border",
61
- query: { role: "border.strong", usage: "border", surface: "surface", emphasis: "strong" },
62
- states: { hover: true },
63
- },
64
- "icon.default": {
65
- name: "icon.default",
66
- description: "Primary icon color for default surfaces.",
67
- category: "icon",
68
- query: { role: "icon.default", usage: "icon", surface: "surface" },
69
- states: { hover: true },
70
- },
71
- "icon.muted": {
72
- name: "icon.muted",
73
- description: "Muted icons for less prominent actions.",
74
- category: "icon",
75
- query: { role: "icon.muted", usage: "icon", surface: "surface", emphasis: "muted" },
76
- },
77
- "ring.default": {
78
- name: "ring.default",
79
- description: "Base ring color (derive focus via state operator).",
80
- category: "ring",
81
- query: { role: "ring.default", usage: "ring", surface: "surface", emphasis: "strong" },
82
- states: { focus: true },
83
- },
84
- },
85
- };
@@ -1,46 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import { createTheme } from "../../core/createTheme.js";
4
- import type { TokenRegistry } from "../../types/index.js";
5
- import {
6
- minimalUiTokens,
7
- modernUiTokens,
8
- radixLikeUiTokens,
9
- } from "./index.js";
10
- import { validateTokenRegistry } from "../../core/tokenRegistry.js";
11
- import { exportThemeCss, exportThemeJson } from "../../export/exportTheme.js";
12
-
13
- const toThemeTokens = (registry: TokenRegistry) =>
14
- Object.fromEntries(
15
- Object.entries(registry.tokens).map(([name, token]) => [name, token.query]),
16
- );
17
-
18
- describe("token presets", () => {
19
- const theme = createTheme({
20
- seeds: {
21
- light: { neutral: "#8B8D98", accent: "#3D63DD" },
22
- dark: { neutral: "#8B8D98", accent: "#3D63DD" },
23
- },
24
- preset: "modern",
25
- });
26
-
27
- it("validates all preset registries", () => {
28
- expect(() => validateTokenRegistry(minimalUiTokens)).not.toThrow();
29
- expect(() => validateTokenRegistry(radixLikeUiTokens)).not.toThrow();
30
- expect(() => validateTokenRegistry(modernUiTokens)).not.toThrow();
31
- });
32
-
33
- it("exports CSS/JSON for each preset", () => {
34
- const registries = [minimalUiTokens, radixLikeUiTokens, modernUiTokens];
35
-
36
- for (const registry of registries) {
37
- const tokens = toThemeTokens(registry);
38
- const css = exportThemeCss(theme, tokens, { preferSpace: "oklch" }).css;
39
- const json = exportThemeJson(theme, tokens, { preferSpace: "oklch" }).tokens;
40
-
41
- expect(css.length).toBeGreaterThan(0);
42
- expect(Object.keys(json.light).length).toBeGreaterThan(0);
43
- expect(Object.keys(json.dark).length).toBeGreaterThan(0);
44
- }
45
- });
46
- });