@ankhorage/zora 0.12.2 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/internal/color/colorToneRecipes.d.ts +23 -0
  3. package/dist/internal/color/colorToneRecipes.d.ts.map +1 -0
  4. package/dist/internal/color/colorToneRecipes.js +139 -0
  5. package/dist/internal/color/colorToneRecipes.js.map +1 -0
  6. package/dist/internal/color/index.d.ts +3 -1
  7. package/dist/internal/color/index.d.ts.map +1 -1
  8. package/dist/internal/color/index.js +2 -0
  9. package/dist/internal/color/index.js.map +1 -1
  10. package/dist/internal/color/roleScales.d.ts +20 -0
  11. package/dist/internal/color/roleScales.d.ts.map +1 -0
  12. package/dist/internal/color/roleScales.js +79 -0
  13. package/dist/internal/color/roleScales.js.map +1 -0
  14. package/dist/internal/color/scales.d.ts +9 -0
  15. package/dist/internal/color/scales.d.ts.map +1 -1
  16. package/dist/internal/color/scales.js +25 -0
  17. package/dist/internal/color/scales.js.map +1 -1
  18. package/dist/theme/createZoraThemeConfig.js +2 -2
  19. package/dist/theme/createZoraThemeConfig.js.map +1 -1
  20. package/dist/theme/types.d.ts +6 -4
  21. package/dist/theme/types.d.ts.map +1 -1
  22. package/dist/theme/types.js +20 -1
  23. package/dist/theme/types.js.map +1 -1
  24. package/dist/theme/zoraDefaultTheme.js +1 -1
  25. package/dist/theme/zoraDefaultTheme.js.map +1 -1
  26. package/package.json +2 -2
  27. package/src/internal/color/colorToneRecipes.test.ts +89 -0
  28. package/src/internal/color/colorToneRecipes.ts +167 -0
  29. package/src/internal/color/index.ts +17 -0
  30. package/src/internal/color/roleHues.test.ts +1 -1
  31. package/src/internal/color/roleScales.test.ts +220 -0
  32. package/src/internal/color/roleScales.ts +127 -0
  33. package/src/internal/color/scales.ts +49 -0
  34. package/src/theme/createZoraThemeConfig.test.ts +5 -5
  35. package/src/theme/createZoraThemeConfig.ts +2 -2
  36. package/src/theme/types.ts +26 -10
  37. package/src/theme/zoraDefaultTheme.ts +1 -1
@@ -0,0 +1,89 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+
3
+ import { ZORA_COLOR_TONES } from '../../theme/types';
4
+ import {
5
+ getZoraColorToneRecipe,
6
+ getZoraColorToneRoleChromaFactor,
7
+ type ZoraColorToneRecipe,
8
+ type ZoraHueScaleRoleId,
9
+ } from './index';
10
+
11
+ const HUE_BACKED_ROLES: readonly ZoraHueScaleRoleId[] = [
12
+ 'primary',
13
+ 'secondary',
14
+ 'accent',
15
+ 'highlight',
16
+ 'surfaceTint',
17
+ ];
18
+
19
+ function expectFinitePositive(value: number) {
20
+ expect(Number.isFinite(value)).toBe(true);
21
+ expect(value).toBeGreaterThan(0);
22
+ }
23
+
24
+ function expectSaneRecipe(recipe: ZoraColorToneRecipe) {
25
+ expectFinitePositive(recipe.maxChroma);
26
+ expectFinitePositive(recipe.minMidChroma);
27
+ expect(recipe.minMidChroma).toBeLessThan(recipe.maxChroma);
28
+
29
+ for (const role of HUE_BACKED_ROLES) {
30
+ expectFinitePositive(getZoraColorToneRoleChromaFactor(recipe, role));
31
+ }
32
+ }
33
+
34
+ describe('color tone recipes', () => {
35
+ test('every ZORA color tone has a recipe', () => {
36
+ for (const colorTone of ZORA_COLOR_TONES) {
37
+ expect(getZoraColorToneRecipe(colorTone).colorTone).toBe(colorTone);
38
+ }
39
+ });
40
+
41
+ test('every recipe has sane chroma values and all hue-backed role factors', () => {
42
+ for (const colorTone of ZORA_COLOR_TONES) {
43
+ expectSaneRecipe(getZoraColorToneRecipe(colorTone));
44
+ }
45
+ });
46
+
47
+ test('records the initial background and foreground lane pairings', () => {
48
+ expect(getZoraColorToneRecipe('fluorescent').laneRecipe).toEqual({
49
+ backgroundTone: 'obsidian',
50
+ foregroundTone: 'fluorescent',
51
+ });
52
+ expect(getZoraColorToneRecipe('obsidian').laneRecipe).toEqual({
53
+ backgroundTone: 'obsidian',
54
+ foregroundTone: 'fluorescent',
55
+ });
56
+ expect(getZoraColorToneRecipe('pastel').laneRecipe).toEqual({
57
+ backgroundTone: 'pastel',
58
+ foregroundTone: 'jewel',
59
+ });
60
+ expect(getZoraColorToneRecipe('earth').laneRecipe).toEqual({
61
+ backgroundTone: 'earth',
62
+ foregroundTone: 'mineral',
63
+ });
64
+ });
65
+
66
+ test('surface tint remains lower intensity than foreground action roles', () => {
67
+ for (const colorTone of ZORA_COLOR_TONES) {
68
+ const recipe = getZoraColorToneRecipe(colorTone);
69
+ const surfaceTint = getZoraColorToneRoleChromaFactor(recipe, 'surfaceTint');
70
+
71
+ expect(surfaceTint).toBeLessThan(getZoraColorToneRoleChromaFactor(recipe, 'primary'));
72
+ expect(surfaceTint).toBeLessThan(getZoraColorToneRoleChromaFactor(recipe, 'accent'));
73
+ expect(surfaceTint).toBeLessThan(getZoraColorToneRoleChromaFactor(recipe, 'highlight'));
74
+ }
75
+ });
76
+
77
+ test('high-energy tones allow higher chroma than neutral and pastel', () => {
78
+ expect(getZoraColorToneRecipe('fluorescent').maxChroma).toBeGreaterThan(
79
+ getZoraColorToneRecipe('neutral').maxChroma,
80
+ );
81
+ expect(getZoraColorToneRecipe('fluorescent').maxChroma).toBeGreaterThan(
82
+ getZoraColorToneRecipe('pastel').maxChroma,
83
+ );
84
+ });
85
+
86
+ test('getter is deterministic', () => {
87
+ expect(getZoraColorToneRecipe('jewel')).toEqual(getZoraColorToneRecipe('jewel'));
88
+ });
89
+ });
@@ -0,0 +1,167 @@
1
+ import type { ZoraColorTone } from '../../theme/types';
2
+ import type { ZoraHueScaleRoleId } from './scales';
3
+
4
+ export interface ZoraColorToneLaneRecipe {
5
+ backgroundTone: ZoraColorTone;
6
+ foregroundTone: ZoraColorTone;
7
+ }
8
+
9
+ export interface ZoraColorToneRoleChromaFactors {
10
+ primary: number;
11
+ secondary: number;
12
+ accent: number;
13
+ highlight: number;
14
+ surfaceTint: number;
15
+ }
16
+
17
+ export interface ZoraColorToneRecipe {
18
+ colorTone: ZoraColorTone;
19
+ laneRecipe: ZoraColorToneLaneRecipe;
20
+ roleChromaFactors: ZoraColorToneRoleChromaFactors;
21
+ maxChroma: number;
22
+ minMidChroma: number;
23
+ }
24
+
25
+ const ZORA_COLOR_TONE_RECIPES = {
26
+ neutral: {
27
+ colorTone: 'neutral',
28
+ laneRecipe: { backgroundTone: 'neutral', foregroundTone: 'jewel' },
29
+ roleChromaFactors: {
30
+ primary: 0.72,
31
+ secondary: 0.48,
32
+ accent: 0.56,
33
+ highlight: 0.6,
34
+ surfaceTint: 0.12,
35
+ },
36
+ maxChroma: 0.14,
37
+ minMidChroma: 0.025,
38
+ },
39
+ pastel: {
40
+ colorTone: 'pastel',
41
+ laneRecipe: { backgroundTone: 'pastel', foregroundTone: 'jewel' },
42
+ roleChromaFactors: {
43
+ primary: 0.58,
44
+ secondary: 0.48,
45
+ accent: 0.55,
46
+ highlight: 0.62,
47
+ surfaceTint: 0.2,
48
+ },
49
+ maxChroma: 0.12,
50
+ minMidChroma: 0.02,
51
+ },
52
+ earth: {
53
+ colorTone: 'earth',
54
+ laneRecipe: { backgroundTone: 'earth', foregroundTone: 'mineral' },
55
+ roleChromaFactors: {
56
+ primary: 0.64,
57
+ secondary: 0.52,
58
+ accent: 0.58,
59
+ highlight: 0.6,
60
+ surfaceTint: 0.16,
61
+ },
62
+ maxChroma: 0.13,
63
+ minMidChroma: 0.022,
64
+ },
65
+ mineral: {
66
+ colorTone: 'mineral',
67
+ laneRecipe: { backgroundTone: 'mineral', foregroundTone: 'jewel' },
68
+ roleChromaFactors: {
69
+ primary: 0.7,
70
+ secondary: 0.56,
71
+ accent: 0.64,
72
+ highlight: 0.68,
73
+ surfaceTint: 0.16,
74
+ },
75
+ maxChroma: 0.14,
76
+ minMidChroma: 0.025,
77
+ },
78
+ muted: {
79
+ colorTone: 'muted',
80
+ laneRecipe: { backgroundTone: 'muted', foregroundTone: 'jewel' },
81
+ roleChromaFactors: {
82
+ primary: 0.6,
83
+ secondary: 0.5,
84
+ accent: 0.56,
85
+ highlight: 0.6,
86
+ surfaceTint: 0.14,
87
+ },
88
+ maxChroma: 0.12,
89
+ minMidChroma: 0.02,
90
+ },
91
+ jewel: {
92
+ colorTone: 'jewel',
93
+ laneRecipe: { backgroundTone: 'neutral', foregroundTone: 'jewel' },
94
+ roleChromaFactors: {
95
+ primary: 1,
96
+ secondary: 0.72,
97
+ accent: 0.85,
98
+ highlight: 1,
99
+ surfaceTint: 0.18,
100
+ },
101
+ maxChroma: 0.2,
102
+ minMidChroma: 0.04,
103
+ },
104
+ fluorescent: {
105
+ colorTone: 'fluorescent',
106
+ laneRecipe: { backgroundTone: 'obsidian', foregroundTone: 'fluorescent' },
107
+ roleChromaFactors: {
108
+ primary: 1.12,
109
+ secondary: 0.82,
110
+ accent: 1.05,
111
+ highlight: 1.18,
112
+ surfaceTint: 0.22,
113
+ },
114
+ maxChroma: 0.24,
115
+ minMidChroma: 0.045,
116
+ },
117
+ obsidian: {
118
+ colorTone: 'obsidian',
119
+ laneRecipe: { backgroundTone: 'obsidian', foregroundTone: 'fluorescent' },
120
+ roleChromaFactors: {
121
+ primary: 1.08,
122
+ secondary: 0.78,
123
+ accent: 1,
124
+ highlight: 1.12,
125
+ surfaceTint: 0.2,
126
+ },
127
+ maxChroma: 0.22,
128
+ minMidChroma: 0.04,
129
+ },
130
+ vaporwave: {
131
+ colorTone: 'vaporwave',
132
+ laneRecipe: { backgroundTone: 'pastel', foregroundTone: 'fluorescent' },
133
+ roleChromaFactors: {
134
+ primary: 0.95,
135
+ secondary: 0.72,
136
+ accent: 1,
137
+ highlight: 1.08,
138
+ surfaceTint: 0.24,
139
+ },
140
+ maxChroma: 0.2,
141
+ minMidChroma: 0.035,
142
+ },
143
+ monochromeAccent: {
144
+ colorTone: 'monochromeAccent',
145
+ laneRecipe: { backgroundTone: 'neutral', foregroundTone: 'jewel' },
146
+ roleChromaFactors: {
147
+ primary: 0.88,
148
+ secondary: 0.36,
149
+ accent: 0.95,
150
+ highlight: 0.88,
151
+ surfaceTint: 0.08,
152
+ },
153
+ maxChroma: 0.18,
154
+ minMidChroma: 0.035,
155
+ },
156
+ } satisfies Record<ZoraColorTone, ZoraColorToneRecipe>;
157
+
158
+ export function getZoraColorToneRecipe(colorTone: ZoraColorTone): ZoraColorToneRecipe {
159
+ return ZORA_COLOR_TONE_RECIPES[colorTone];
160
+ }
161
+
162
+ export function getZoraColorToneRoleChromaFactor(
163
+ recipe: ZoraColorToneRecipe,
164
+ role: ZoraHueScaleRoleId,
165
+ ): number {
166
+ return recipe.roleChromaFactors[role];
167
+ }
@@ -1,3 +1,10 @@
1
+ export {
2
+ getZoraColorToneRecipe,
3
+ getZoraColorToneRoleChromaFactor,
4
+ type ZoraColorToneLaneRecipe,
5
+ type ZoraColorToneRecipe,
6
+ type ZoraColorToneRoleChromaFactors,
7
+ } from './colorToneRecipes';
1
8
  export {
2
9
  computeZoraHarmony,
3
10
  type ZoraComputedHarmony,
@@ -13,10 +20,20 @@ export {
13
20
  type ZoraHueRoleAssignment,
14
21
  type ZoraHueRoleId,
15
22
  } from './roleHues';
23
+ export {
24
+ createZoraRoleColorScales,
25
+ getZoraRoleColorScale,
26
+ ZORA_COLOR_SCALE_ROLE_ORDER,
27
+ type ZoraColorScaleRoleId,
28
+ type ZoraComputedRoleColorScales,
29
+ type ZoraRoleColorScale,
30
+ } from './roleScales';
16
31
  export {
17
32
  createZoraColorScale,
18
33
  type CreateZoraColorScaleOptions,
34
+ type CreateZoraHueScaleOptions,
19
35
  createZoraNeutralScale,
20
36
  createZoraPrimaryScale,
37
+ type ZoraHueScaleRoleId,
21
38
  } from './scales';
22
39
  export { ZORA_COLOR_SCALE_STEPS, type ZoraColorScale, type ZoraColorScaleStep } from './types';
@@ -25,7 +25,7 @@ const ROLE_ORDER: readonly ZoraHueRoleId[] = [
25
25
 
26
26
  function expectEveryRoleOnce(roles: ReturnType<typeof assignZoraHarmonyRoleHues>) {
27
27
  expect(roles.assignments).toHaveLength(ROLE_ORDER.length);
28
- expect(roles.assignments.map((assignment) => assignment.role)).toEqual(ROLE_ORDER);
28
+ expect(roles.assignments.map((assignment) => assignment.role)).toEqual([...ROLE_ORDER]);
29
29
  }
30
30
 
31
31
  describe('assignZoraHarmonyRoleHues', () => {
@@ -0,0 +1,220 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+
3
+ import type { ZoraColorTone, ZoraHexColor } from '../../theme/types';
4
+ import {
5
+ assignZoraHarmonyRoleHues,
6
+ computeZoraHarmony,
7
+ createZoraRoleColorScales,
8
+ getZoraRoleColorScale,
9
+ parseHexToOklch,
10
+ ZORA_COLOR_SCALE_ROLE_ORDER,
11
+ ZORA_COLOR_SCALE_STEPS,
12
+ type ZoraColorScale,
13
+ type ZoraColorScaleStep,
14
+ type ZoraComputedHueRoles,
15
+ type ZoraRoleColorScale,
16
+ } from './index';
17
+
18
+ function isSixDigitLowercaseHexColor(value: string): value is ZoraHexColor {
19
+ return /^#[0-9a-f]{6}$/.test(value);
20
+ }
21
+
22
+ function hueDeltaDegrees(a: number, b: number): number {
23
+ const raw = Math.abs(a - b) % 360;
24
+ return Math.min(raw, 360 - raw);
25
+ }
26
+
27
+ function getStepValues(scale: ZoraColorScale): { step: ZoraColorScaleStep; hex: ZoraHexColor }[] {
28
+ return ZORA_COLOR_SCALE_STEPS.map((step) => ({ step, hex: scale[step] }));
29
+ }
30
+
31
+ function assertScaleKeys(scale: ZoraColorScale) {
32
+ const keys = Object.keys(scale)
33
+ .map((key) => Number(key))
34
+ .sort((a, b) => a - b);
35
+
36
+ expect(keys).toEqual([...ZORA_COLOR_SCALE_STEPS]);
37
+ }
38
+
39
+ function assertNoPureBlackOrWhite(scale: ZoraColorScale) {
40
+ const values = getStepValues(scale).map(({ hex }) => hex);
41
+ expect(values).not.toContain('#000000');
42
+ expect(values).not.toContain('#ffffff');
43
+ }
44
+
45
+ function buildHueRoles(assignments: ZoraComputedHueRoles['assignments']): ZoraComputedHueRoles {
46
+ return {
47
+ harmony: 'tetradic',
48
+ assignments,
49
+ };
50
+ }
51
+
52
+ function createCompleteHueRoles(): ZoraComputedHueRoles {
53
+ return buildHueRoles([
54
+ { role: 'primary', hue: 120, sourceSlotId: 'base' },
55
+ { role: 'secondary', hue: 200, sourceSlotId: 'a' },
56
+ { role: 'accent', hue: 280, sourceSlotId: 'b' },
57
+ { role: 'highlight', hue: 20, sourceSlotId: 'c' },
58
+ { role: 'surfaceTint', hue: 160, sourceSlotId: 'a' },
59
+ ]);
60
+ }
61
+
62
+ function createScales(colorTone: ZoraColorTone = 'jewel') {
63
+ return createZoraRoleColorScales({
64
+ colorTone,
65
+ hueRoles: createCompleteHueRoles(),
66
+ seed: '#0f766e',
67
+ });
68
+ }
69
+
70
+ function requireHueBackedSourceHue(role: ZoraRoleColorScale): number {
71
+ if (typeof role.sourceHue !== 'number') {
72
+ throw new Error(`[zora] Expected "${role.role}" role scale to include a sourceHue.`);
73
+ }
74
+ return role.sourceHue;
75
+ }
76
+
77
+ describe('createZoraRoleColorScales', () => {
78
+ test('returns all roles exactly once in deterministic order', () => {
79
+ const scales = createScales();
80
+
81
+ expect(scales.roles).toHaveLength(ZORA_COLOR_SCALE_ROLE_ORDER.length);
82
+ expect(scales.roles.map((entry) => entry.role)).toEqual([...ZORA_COLOR_SCALE_ROLE_ORDER]);
83
+ expect(new Set(scales.roles.map((entry) => entry.role)).size).toBe(
84
+ ZORA_COLOR_SCALE_ROLE_ORDER.length,
85
+ );
86
+ });
87
+
88
+ test('every scale contains exactly all 50–950 keys and valid lowercase 6-digit hex values', () => {
89
+ const scales = createScales();
90
+
91
+ for (const role of scales.roles) {
92
+ assertScaleKeys(role.scale);
93
+ for (const { hex } of getStepValues(role.scale)) {
94
+ expect(isSixDigitLowercaseHexColor(hex)).toBe(true);
95
+ }
96
+ }
97
+ });
98
+
99
+ test('output is deterministic for the same input', () => {
100
+ expect(createScales()).toEqual(createScales());
101
+ });
102
+
103
+ test('role hue is preserved approximately for mid steps', () => {
104
+ const scales = createZoraRoleColorScales({
105
+ colorTone: 'jewel',
106
+ hueRoles: buildHueRoles([
107
+ { role: 'primary', hue: 115, sourceSlotId: 'base' },
108
+ { role: 'secondary', hue: 210, sourceSlotId: 'a' },
109
+ { role: 'accent', hue: 300, sourceSlotId: 'b' },
110
+ { role: 'highlight', hue: 25, sourceSlotId: 'c' },
111
+ { role: 'surfaceTint', hue: 165, sourceSlotId: 'a' },
112
+ ]),
113
+ seed: '#0f766e',
114
+ });
115
+
116
+ const midSteps: ZoraColorScaleStep[] = [400, 500, 600, 700];
117
+ for (const roleId of ['primary', 'secondary', 'accent', 'highlight', 'surfaceTint'] as const) {
118
+ const role = getZoraRoleColorScale(scales, roleId);
119
+ const expectedHue = requireHueBackedSourceHue(role);
120
+
121
+ for (const step of midSteps) {
122
+ const oklch = parseHexToOklch(role.scale[step]);
123
+ expect(hueDeltaDegrees(expectedHue, oklch.h)).toBeLessThan(25);
124
+ }
125
+ }
126
+ });
127
+
128
+ test('surfaceTint scale has lower chroma than primary/accent/highlight for mid steps', () => {
129
+ const scales = createScales('jewel');
130
+ const surfaceTint = getZoraRoleColorScale(scales, 'surfaceTint').scale;
131
+ const primary = getZoraRoleColorScale(scales, 'primary').scale;
132
+ const accent = getZoraRoleColorScale(scales, 'accent').scale;
133
+ const highlight = getZoraRoleColorScale(scales, 'highlight').scale;
134
+ const step: ZoraColorScaleStep = 500;
135
+ const surfaceTintChroma = parseHexToOklch(surfaceTint[step]).c;
136
+
137
+ expect(surfaceTintChroma).toBeLessThan(parseHexToOklch(primary[step]).c);
138
+ expect(surfaceTintChroma).toBeLessThan(parseHexToOklch(accent[step]).c);
139
+ expect(surfaceTintChroma).toBeLessThan(parseHexToOklch(highlight[step]).c);
140
+ });
141
+
142
+ test('colorTone changes role chroma behavior internally', () => {
143
+ const neutral = createScales('neutral');
144
+ const fluorescent = createScales('fluorescent');
145
+ const step: ZoraColorScaleStep = 500;
146
+
147
+ const neutralPrimary = parseHexToOklch(getZoraRoleColorScale(neutral, 'primary').scale[step]).c;
148
+ const fluorescentPrimary = parseHexToOklch(
149
+ getZoraRoleColorScale(fluorescent, 'primary').scale[step],
150
+ ).c;
151
+
152
+ expect(fluorescentPrimary).toBeGreaterThan(neutralPrimary);
153
+ });
154
+
155
+ test('pastel keeps surfaceTint lower chroma than fluorescent foreground roles', () => {
156
+ const pastel = createScales('pastel');
157
+ const fluorescent = createScales('fluorescent');
158
+ const step: ZoraColorScaleStep = 500;
159
+
160
+ const pastelSurfaceTint = parseHexToOklch(
161
+ getZoraRoleColorScale(pastel, 'surfaceTint').scale[step],
162
+ ).c;
163
+ const fluorescentAccent = parseHexToOklch(
164
+ getZoraRoleColorScale(fluorescent, 'accent').scale[step],
165
+ ).c;
166
+
167
+ expect(pastelSurfaceTint).toBeLessThan(fluorescentAccent);
168
+ });
169
+
170
+ test('neutral scale has low chroma', () => {
171
+ const neutral = getZoraRoleColorScale(createScales(), 'neutral').scale;
172
+
173
+ for (const { hex } of getStepValues(neutral)) {
174
+ expect(parseHexToOklch(hex).c).toBeLessThanOrEqual(0.03);
175
+ }
176
+ });
177
+
178
+ test('missing required hue role throws a clear error', () => {
179
+ const hueRoles = buildHueRoles([
180
+ { role: 'primary', hue: 120, sourceSlotId: 'base' },
181
+ { role: 'secondary', hue: 200, sourceSlotId: 'a' },
182
+ { role: 'accent', hue: 280, sourceSlotId: 'b' },
183
+ { role: 'surfaceTint', hue: 160, sourceSlotId: 'a' },
184
+ ]);
185
+
186
+ expect(() =>
187
+ createZoraRoleColorScales({ colorTone: 'jewel', hueRoles, seed: '#0f766e' }),
188
+ ).toThrow('highlight');
189
+ });
190
+
191
+ test('no role scale contains pure black/white by default', () => {
192
+ const scales = createScales();
193
+
194
+ for (const role of scales.roles) {
195
+ assertNoPureBlackOrWhite(role.scale);
196
+ }
197
+ });
198
+
199
+ test('does not mutate input hueRoles', () => {
200
+ const hueRoles = createCompleteHueRoles();
201
+ const snapshot = JSON.stringify(hueRoles);
202
+
203
+ createZoraRoleColorScales({ colorTone: 'jewel', hueRoles, seed: '#0f766e' });
204
+
205
+ expect(JSON.stringify(hueRoles)).toBe(snapshot);
206
+ });
207
+
208
+ test('integration: harmony -> role hues -> role scales pipeline connects', () => {
209
+ const seed: ZoraHexColor = '#0f766e';
210
+ const harmony = computeZoraHarmony(seed, 'tetradic');
211
+ const hueRoles = assignZoraHarmonyRoleHues(harmony);
212
+
213
+ const scales = createZoraRoleColorScales({ colorTone: 'jewel', hueRoles, seed });
214
+
215
+ expect(scales.roles.map((entry) => entry.role)).toEqual([...ZORA_COLOR_SCALE_ROLE_ORDER]);
216
+ for (const role of scales.roles) {
217
+ assertScaleKeys(role.scale);
218
+ }
219
+ });
220
+ });
@@ -0,0 +1,127 @@
1
+ import type { ZoraColorTone, ZoraHexColor } from '../../theme/types';
2
+ import { getZoraColorToneRecipe } from './colorToneRecipes';
3
+ import { parseHexToOklch } from './oklch';
4
+ import {
5
+ getZoraHueRoleAssignment,
6
+ type ZoraComputedHueRoles,
7
+ type ZoraHueRoleId,
8
+ } from './roleHues';
9
+ import {
10
+ createZoraHueScale,
11
+ type CreateZoraHueScaleOptions,
12
+ createZoraNeutralScale,
13
+ type ZoraHueScaleRoleId,
14
+ } from './scales';
15
+ import type { ZoraColorScale } from './types';
16
+
17
+ export type ZoraColorScaleRoleId =
18
+ | 'primary'
19
+ | 'secondary'
20
+ | 'accent'
21
+ | 'highlight'
22
+ | 'surfaceTint'
23
+ | 'neutral';
24
+
25
+ export const ZORA_COLOR_SCALE_ROLE_ORDER: readonly ZoraColorScaleRoleId[] = [
26
+ 'primary',
27
+ 'secondary',
28
+ 'accent',
29
+ 'highlight',
30
+ 'surfaceTint',
31
+ 'neutral',
32
+ ];
33
+
34
+ export interface ZoraRoleColorScale {
35
+ role: ZoraColorScaleRoleId;
36
+ sourceHue?: number;
37
+ scale: ZoraColorScale;
38
+ }
39
+
40
+ export interface ZoraComputedRoleColorScales {
41
+ roles: readonly ZoraRoleColorScale[];
42
+ }
43
+
44
+ export function getZoraRoleColorScale(
45
+ scales: ZoraComputedRoleColorScales,
46
+ role: ZoraColorScaleRoleId,
47
+ ): ZoraRoleColorScale {
48
+ const found = scales.roles.find((entry) => entry.role === role);
49
+ if (!found) {
50
+ throw new Error(`[zora] Expected role color scales to include "${role}".`);
51
+ }
52
+ return found;
53
+ }
54
+
55
+ function resolveSeedChroma(seed: ZoraHexColor): number {
56
+ return parseHexToOklch(seed).c;
57
+ }
58
+
59
+ function createHueBackedRoleScale(options: {
60
+ colorTone: ZoraColorTone;
61
+ hueRoles: ZoraComputedHueRoles;
62
+ seedChroma: number;
63
+ role: ZoraHueRoleId;
64
+ }): ZoraRoleColorScale {
65
+ const assignment = getZoraHueRoleAssignment(options.hueRoles, options.role);
66
+ const colorToneRecipe = getZoraColorToneRecipe(options.colorTone);
67
+ const hueScaleRole: ZoraHueScaleRoleId = options.role;
68
+ const hueScaleOptions: CreateZoraHueScaleOptions = {
69
+ hue: assignment.hue,
70
+ seedChroma: options.seedChroma,
71
+ role: hueScaleRole,
72
+ colorToneRecipe,
73
+ };
74
+
75
+ return {
76
+ role: options.role,
77
+ sourceHue: assignment.hue,
78
+ scale: createZoraHueScale(hueScaleOptions),
79
+ };
80
+ }
81
+
82
+ export function createZoraRoleColorScales(options: {
83
+ hueRoles: ZoraComputedHueRoles;
84
+ seed: ZoraHexColor;
85
+ colorTone: ZoraColorTone;
86
+ }): ZoraComputedRoleColorScales {
87
+ const seedChroma = resolveSeedChroma(options.seed);
88
+
89
+ const roles: ZoraRoleColorScale[] = [
90
+ createHueBackedRoleScale({
91
+ colorTone: options.colorTone,
92
+ hueRoles: options.hueRoles,
93
+ seedChroma,
94
+ role: 'primary',
95
+ }),
96
+ createHueBackedRoleScale({
97
+ colorTone: options.colorTone,
98
+ hueRoles: options.hueRoles,
99
+ seedChroma,
100
+ role: 'secondary',
101
+ }),
102
+ createHueBackedRoleScale({
103
+ colorTone: options.colorTone,
104
+ hueRoles: options.hueRoles,
105
+ seedChroma,
106
+ role: 'accent',
107
+ }),
108
+ createHueBackedRoleScale({
109
+ colorTone: options.colorTone,
110
+ hueRoles: options.hueRoles,
111
+ seedChroma,
112
+ role: 'highlight',
113
+ }),
114
+ createHueBackedRoleScale({
115
+ colorTone: options.colorTone,
116
+ hueRoles: options.hueRoles,
117
+ seedChroma,
118
+ role: 'surfaceTint',
119
+ }),
120
+ {
121
+ role: 'neutral',
122
+ scale: createZoraNeutralScale(options.seed),
123
+ },
124
+ ];
125
+
126
+ return { roles };
127
+ }