@titan-design/react-ui 0.4.0 → 0.6.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 (150) hide show
  1. package/dist/MesoStatusCard-CQk71hSi.d.mts +77 -0
  2. package/dist/MesoStatusCard-CQk71hSi.d.ts +77 -0
  3. package/dist/bodymap.d.mts +246 -3
  4. package/dist/bodymap.d.ts +246 -3
  5. package/dist/bodymap.js +232 -185
  6. package/dist/bodymap.js.map +1 -1
  7. package/dist/bodymap.mjs +1963 -11
  8. package/dist/bodymap.mjs.map +1 -1
  9. package/dist/index.d.mts +193 -744
  10. package/dist/index.d.ts +193 -744
  11. package/dist/index.js +1551 -1856
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +10770 -8213
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/pages-D7Jlssvp.d.ts +791 -0
  16. package/dist/pages-MO0JCySL.d.mts +791 -0
  17. package/dist/pages.d.mts +4 -0
  18. package/dist/pages.d.ts +4 -0
  19. package/dist/pages.js +6694 -0
  20. package/dist/pages.js.map +1 -0
  21. package/dist/pages.mjs +6674 -0
  22. package/dist/pages.mjs.map +1 -0
  23. package/dist/theme/index.d.mts +473 -211
  24. package/dist/theme/index.d.ts +473 -211
  25. package/dist/theme/index.js +341 -127
  26. package/dist/theme/index.js.map +1 -1
  27. package/dist/theme/index.mjs +2085 -2
  28. package/dist/theme/index.mjs.map +1 -1
  29. package/dist/theme/tokens-css.js +148 -139
  30. package/dist/theme/tokens-css.js.map +1 -1
  31. package/dist/theme/tokens-css.mjs +582 -1
  32. package/dist/theme/tokens-css.mjs.map +1 -1
  33. package/package.json +11 -7
  34. package/src/components/custom/DateTime/DateTime.stories.tsx +82 -6
  35. package/src/components/custom/DateTime/DateTime.test.tsx +29 -3
  36. package/src/components/custom/DateTime/DateTime.tsx +55 -15
  37. package/src/components/custom/Gauge/Gauge.test.tsx +2 -2
  38. package/src/components/custom/Gauge/Gauge.tsx +6 -3
  39. package/src/components/custom/Scatter/Scatter.tsx +3 -5
  40. package/src/components/custom/Treemap/Treemap.tsx +3 -5
  41. package/src/components/custom/Typography/Typography.stories.tsx +45 -27
  42. package/src/components/custom/Typography/Typography.test.tsx +13 -3
  43. package/src/components/custom/Typography/Typography.tsx +5 -0
  44. package/src/components/custom/Workout/ActiveWorkoutPage.tsx +2 -1
  45. package/src/components/custom/Workout/BaseBadge.stories.tsx +3 -3
  46. package/src/components/custom/Workout/BaseBadge.test.tsx +1 -1
  47. package/src/components/custom/Workout/BaseBadge.tsx +1 -1
  48. package/src/components/custom/Workout/BodyMap.tsx +6 -3
  49. package/src/components/custom/Workout/BodyMapDetailPanel.tsx +6 -3
  50. package/src/components/custom/Workout/CapacityBandChart.test.tsx +2 -2
  51. package/src/components/custom/Workout/CapacityBandChart.tsx +9 -6
  52. package/src/components/custom/Workout/DeviationBar.test.tsx +1 -1
  53. package/src/components/custom/Workout/DeviationBar.tsx +7 -4
  54. package/src/components/custom/Workout/ExerciseCard.tsx +5 -1
  55. package/src/components/custom/Workout/ExerciseDetailPage.tsx +19 -5
  56. package/src/components/custom/Workout/InputBar.tsx +2 -1
  57. package/src/components/custom/Workout/IntensityBar.test.tsx +112 -60
  58. package/src/components/custom/Workout/IntensityBar.tsx +113 -58
  59. package/src/components/custom/Workout/MesoCard.tsx +8 -3
  60. package/src/components/custom/Workout/MesoProgressBar.test.tsx +1 -1
  61. package/src/components/custom/Workout/MesoProgressBar.tsx +3 -2
  62. package/src/components/custom/Workout/MesoStatusCard.tsx +20 -13
  63. package/src/components/custom/Workout/MuscleGroupChip.tsx +7 -4
  64. package/src/components/custom/Workout/PlaceholderStrip.tsx +5 -9
  65. package/src/components/custom/Workout/PrBadge.tsx +7 -4
  66. package/src/components/custom/Workout/PrHistoryModal.tsx +6 -5
  67. package/src/components/custom/Workout/ProgramPlanningPage.tsx +2 -1
  68. package/src/components/custom/Workout/README.md +50 -0
  69. package/src/components/custom/Workout/ReadinessCheck.tsx +7 -4
  70. package/src/components/custom/Workout/RestTimer.test.tsx +41 -10
  71. package/src/components/custom/Workout/RestTimer.tsx +50 -44
  72. package/src/components/custom/Workout/SetRow.tsx +12 -2
  73. package/src/components/custom/Workout/Sparkline.tsx +2 -1
  74. package/src/components/custom/Workout/StatusDot.test.tsx +2 -2
  75. package/src/components/custom/Workout/StatusDot.tsx +12 -9
  76. package/src/components/custom/Workout/StrengthTrendChart.tsx +9 -6
  77. package/src/components/custom/Workout/SupersetWrapper.tsx +2 -1
  78. package/src/components/custom/Workout/TempoDisplay.stories.tsx +69 -2
  79. package/src/components/custom/Workout/TempoDisplay.test.tsx +35 -0
  80. package/src/components/custom/Workout/TempoDisplay.tsx +109 -3
  81. package/src/components/custom/Workout/VelocityStrip.test.tsx +89 -2
  82. package/src/components/custom/Workout/VelocityStrip.tsx +203 -38
  83. package/src/components/custom/Workout/WeekRow.test.tsx +2 -2
  84. package/src/components/custom/Workout/WeekRow.tsx +3 -2
  85. package/src/components/custom/Workout/WeightBadge.test.tsx +2 -2
  86. package/src/components/custom/Workout/WeightBadge.tsx +8 -4
  87. package/src/components/custom/Workout/WorkoutCard.tsx +5 -2
  88. package/src/components/custom/Workout/WorkoutPill.tsx +12 -8
  89. package/src/components/custom/Workout/icons.tsx +7 -0
  90. package/src/components/custom/Workout/index.ts +38 -47
  91. package/src/components/icons/SvgIcon.tsx +50 -0
  92. package/src/components/icons/icons.stories.tsx +57 -0
  93. package/src/components/icons/icons.test.tsx +43 -0
  94. package/src/components/icons/icons.tsx +45 -0
  95. package/src/components/icons/index.ts +4 -0
  96. package/src/components/index.ts +6 -0
  97. package/src/components/shell/BrandLockup.stories.tsx +27 -0
  98. package/src/components/shell/BrandLockup.test.tsx +23 -0
  99. package/src/components/shell/BrandLockup.tsx +47 -0
  100. package/src/components/shell/DeviceIndicator.stories.tsx +28 -0
  101. package/src/components/shell/DeviceIndicator.test.tsx +26 -0
  102. package/src/components/shell/DeviceIndicator.tsx +52 -0
  103. package/src/components/shell/DeviceMenu.stories.tsx +47 -0
  104. package/src/components/shell/DeviceMenu.test.tsx +40 -0
  105. package/src/components/shell/DeviceMenu.tsx +65 -0
  106. package/src/components/shell/DeviceRow.stories.tsx +38 -0
  107. package/src/components/shell/DeviceRow.test.tsx +37 -0
  108. package/src/components/shell/DeviceRow.tsx +58 -0
  109. package/src/components/shell/README.md +86 -0
  110. package/src/components/shell/SessionStatePill.stories.tsx +27 -0
  111. package/src/components/shell/SessionStatePill.test.tsx +25 -0
  112. package/src/components/shell/SessionStatePill.tsx +46 -0
  113. package/src/components/shell/TopBar.stories.tsx +49 -0
  114. package/src/components/shell/TopBar.test.tsx +36 -0
  115. package/src/components/shell/TopBar.tsx +89 -0
  116. package/src/components/shell/index.ts +8 -0
  117. package/src/components/ui/indicator/Indicator.stories.tsx +37 -1
  118. package/src/components/ui/indicator/Indicator.test.tsx +19 -1
  119. package/src/components/ui/indicator/Indicator.tsx +45 -6
  120. package/src/components/ui/indicator/index.ts +1 -1
  121. package/src/components/ui/spinner/Spinner.tsx +3 -2
  122. package/src/components/ui/toolbar-button/ToolbarButton.tsx +2 -1
  123. package/src/index.ts +3 -2
  124. package/src/pages.ts +61 -0
  125. package/src/test/stories-smoke.test.tsx +50 -0
  126. package/src/theme/ColorSystem.stories.tsx +323 -0
  127. package/src/theme/Colors.stories.tsx +69 -1
  128. package/src/theme/barrel.ts +54 -0
  129. package/src/theme/config.ts +16 -3
  130. package/src/theme/extracted-colors-dataviz.ts +21 -0
  131. package/src/theme/extracted-colors-ui.ts +20 -0
  132. package/src/theme/global.css +64 -52
  133. package/src/theme/gradients.test.ts +25 -0
  134. package/src/theme/gradients.ts +36 -0
  135. package/src/theme/index.ts +8 -43
  136. package/src/theme/native-theming-guard.test.ts +117 -0
  137. package/src/theme/tokens/primitives.test.ts +232 -0
  138. package/src/theme/tokens/primitives.ts +247 -0
  139. package/src/theme/tokens/semantic.ts +93 -81
  140. package/src/theme/workout-tokens.ts +22 -21
  141. package/src/utils/avatar-color.ts +3 -3
  142. package/tailwind.config.js +10 -3
  143. package/dist/bodymap-BhG55xHM.d.mts +0 -318
  144. package/dist/bodymap-BhG55xHM.d.ts +0 -318
  145. package/dist/chunk-2SISKTWM.mjs +0 -1027
  146. package/dist/chunk-2SISKTWM.mjs.map +0 -1
  147. package/dist/chunk-7XPB4NAO.mjs +0 -1013
  148. package/dist/chunk-7XPB4NAO.mjs.map +0 -1
  149. package/dist/chunk-SNVKL5WZ.mjs +0 -883
  150. package/dist/chunk-SNVKL5WZ.mjs.map +0 -1
@@ -0,0 +1,232 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import {
3
+ primitiveRamps,
4
+ categoricalPalette,
5
+ getCategoricalColor,
6
+ CATEGORICAL_CVD_SAFE_MAX,
7
+ divergingScale,
8
+ sequentialEffort,
9
+ bestTextColor,
10
+ } from './primitives'
11
+
12
+ // --- Minimal OKLab + Machado-2009 dichromacy math (ported from the color-system
13
+ // derivation tools) so the categorical CVD floor is a real, checked property. ---
14
+ const hexToRgb = (hex: string): [number, number, number] => {
15
+ const h = hex.replace('#', '')
16
+ return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16) / 255) as [number, number, number]
17
+ }
18
+ const lin = (c: number) => (c >= 0.04045 ? ((c + 0.055) / 1.055) ** 2.4 : c / 12.92)
19
+ const toOklab = ([r, g, b]: number[]): [number, number, number] => {
20
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b)
21
+ const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b)
22
+ const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b)
23
+ return [
24
+ 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
25
+ 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
26
+ 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
27
+ ]
28
+ }
29
+ const mul = (M: number[], v: number[]) => [
30
+ M[0] * v[0] + M[1] * v[1] + M[2] * v[2],
31
+ M[3] * v[0] + M[4] * v[1] + M[5] * v[2],
32
+ M[6] * v[0] + M[7] * v[1] + M[8] * v[2],
33
+ ]
34
+ // Machado-2009 dichromacy simulation matrices, severity 1.0. The palette solver
35
+ // optimizes worst-case deuteranopia/protanopia (red-green is the binding case) —
36
+ // match that 2-way metric here, not a stricter 3-way including tritan.
37
+ const DEUT = [0.367322, 0.860646, -0.227968, 0.280085, 0.672501, 0.047413, -0.01182, 0.04294, 0.968881]
38
+ const PROT = [0.152286, 1.052583, -0.204868, 0.114503, 0.786281, 0.099216, -0.003882, -0.048116, 1.051998]
39
+ const dist = (a: number[], b: number[]) => Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]) * 100
40
+ // worst-case perceived ΔE across deuteranopia and protanopia
41
+ const cvdDelta = (x: string, y: string) => {
42
+ const sim = (M: number[], hex: string) => toOklab(mul(M, hexToRgb(hex).map(lin)))
43
+ return Math.min(
44
+ ...[DEUT, PROT].map((M) => dist(sim(M, x), sim(M, y))),
45
+ )
46
+ }
47
+
48
+ const HEX6 = /^#[0-9A-F]{6}$/
49
+ const STEPS = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950] as const
50
+ const HUES = ['red', 'orange', 'amber', 'green', 'cyan', 'blue', 'magenta'] as const
51
+
52
+ describe('primitiveRamps', () => {
53
+ it('has all seven consolidated hues', () => {
54
+ expect(Object.keys(primitiveRamps).sort()).toEqual([...HUES].sort())
55
+ })
56
+
57
+ it('gives every hue all eleven perceptual steps as uppercase 6-digit hex', () => {
58
+ for (const hue of HUES) {
59
+ const ramp = primitiveRamps[hue] as Record<number, string>
60
+ for (const step of STEPS) {
61
+ expect(ramp[step], `${hue}-${step}`).toMatch(HEX6)
62
+ }
63
+ }
64
+ })
65
+
66
+ it('flows through each pinned anchor color at its step', () => {
67
+ // The step each ramp is pinned to its brand/semantic anchor hex.
68
+ const anchors: Record<string, string> = {
69
+ 'red-600': '#D14343', // status-error
70
+ 'orange-400': '#FF7900', // brand-primary
71
+ 'amber-300': '#F9B415', // status-warning
72
+ 'green-300': '#2ED573', // status-success
73
+ 'cyan-300': '#22D3EE', // vivid cyan identity
74
+ 'blue-500': '#2196F3', // status-info
75
+ 'magenta-700': '#9C0D7A',
76
+ }
77
+ for (const [key, hex] of Object.entries(anchors)) {
78
+ const [hue, step] = key.split('-')
79
+ expect((primitiveRamps as never)[hue][Number(step)]).toBe(hex)
80
+ }
81
+ })
82
+
83
+ it('increases in darkness monotonically (OKLab L descends 50 -> 950)', () => {
84
+ for (const hue of HUES) {
85
+ const ramp = primitiveRamps[hue] as Record<number, string>
86
+ const lightness = STEPS.map((s) => toOklab(hexToRgb(ramp[s]).map(lin))[0])
87
+ for (let i = 1; i < lightness.length; i++) {
88
+ expect(lightness[i], `${hue} ${STEPS[i - 1]}->${STEPS[i]}`).toBeLessThan(lightness[i - 1])
89
+ }
90
+ }
91
+ })
92
+ })
93
+
94
+ describe('categoricalPalette', () => {
95
+ it('has two ordered variants of seven colors', () => {
96
+ expect(categoricalPalette.default).toHaveLength(7)
97
+ expect(categoricalPalette.dark).toHaveLength(7)
98
+ })
99
+
100
+ it('is all uppercase 6-digit hex', () => {
101
+ for (const variant of ['default', 'dark'] as const) {
102
+ for (const hex of categoricalPalette[variant]) {
103
+ expect(hex).toMatch(HEX6)
104
+ }
105
+ }
106
+ })
107
+
108
+ it('holds the deut/protanopia dichromacy floor (deltaE >= 8) through the CVD-safe max', () => {
109
+ // The first CATEGORICAL_CVD_SAFE_MAX colors are legend-free CVD-safe; the 7th is extended.
110
+ for (const variant of ['default', 'dark'] as const) {
111
+ const colors = categoricalPalette[variant].slice(0, CATEGORICAL_CVD_SAFE_MAX)
112
+ let worst = Infinity
113
+ for (let i = 0; i < colors.length; i++) {
114
+ for (let j = i + 1; j < colors.length; j++) {
115
+ worst = Math.min(worst, cvdDelta(colors[i], colors[j]))
116
+ }
117
+ }
118
+ expect(worst, `${variant} min CVD deltaE (first ${CATEGORICAL_CVD_SAFE_MAX})`).toBeGreaterThanOrEqual(8)
119
+ }
120
+ })
121
+
122
+ it('is nested-stable: no color repeats within a variant', () => {
123
+ for (const variant of ['default', 'dark'] as const) {
124
+ expect(new Set(categoricalPalette[variant]).size).toBe(categoricalPalette[variant].length)
125
+ }
126
+ })
127
+
128
+ it('carries readable in-place text: default on black (>=4.5), dark on white (>=3.5)', () => {
129
+ const relLum = (hex: string) => {
130
+ const [r, g, b] = hexToRgb(hex).map(lin)
131
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b
132
+ }
133
+ const onBlack = (hex: string) => (relLum(hex) + 0.05) / 0.05
134
+ const onWhite = (hex: string) => 1.05 / (relLum(hex) + 0.05)
135
+ // The in-place text guarantee covers the CVD-safe range; the 7th extended
136
+ // color trades contrast for separation and is meant to be legend-paired.
137
+ for (const hex of categoricalPalette.default.slice(0, CATEGORICAL_CVD_SAFE_MAX)) {
138
+ expect(onBlack(hex), `default ${hex} black-text contrast`).toBeGreaterThanOrEqual(4.5)
139
+ }
140
+ for (const hex of categoricalPalette.dark.slice(0, CATEGORICAL_CVD_SAFE_MAX)) {
141
+ expect(onWhite(hex), `dark ${hex} white-text contrast`).toBeGreaterThanOrEqual(3.5)
142
+ }
143
+ })
144
+ })
145
+
146
+ describe('getCategoricalColor', () => {
147
+ it('returns default-variant colors by index', () => {
148
+ expect(getCategoricalColor(0)).toBe(categoricalPalette.default[0])
149
+ expect(getCategoricalColor(4)).toBe(categoricalPalette.default[4])
150
+ })
151
+
152
+ it('selects the requested variant', () => {
153
+ expect(getCategoricalColor(2, 'dark')).toBe(categoricalPalette.dark[2])
154
+ expect(getCategoricalColor(1, 'dark')).toBe(categoricalPalette.dark[1])
155
+ })
156
+
157
+ it('wraps past the end of the palette', () => {
158
+ expect(getCategoricalColor(7)).toBe(categoricalPalette.default[0])
159
+ expect(getCategoricalColor(9)).toBe(categoricalPalette.default[2])
160
+ })
161
+
162
+ it('clamps negative and fractional indices', () => {
163
+ expect(getCategoricalColor(-3)).toBe(categoricalPalette.default[0])
164
+ expect(getCategoricalColor(2.9)).toBe(categoricalPalette.default[2])
165
+ })
166
+ })
167
+
168
+ const relLum = (hex: string) => {
169
+ const [r, g, b] = hexToRgb(hex).map(lin)
170
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b
171
+ }
172
+ const bestContrast = (hex: string) => {
173
+ const l = relLum(hex)
174
+ return Math.max((l + 0.05) / 0.05, 1.05 / (l + 0.05))
175
+ }
176
+
177
+ describe('divergingScale', () => {
178
+ it('is a five-stop diverging scale of uppercase hex', () => {
179
+ expect(divergingScale).toHaveLength(5)
180
+ for (const hex of divergingScale) expect(hex).toMatch(HEX6)
181
+ })
182
+
183
+ it('has a light center and dark extremes (diverging shape)', () => {
184
+ const L = divergingScale.map((h) => toOklab(hexToRgb(h).map(lin))[0])
185
+ expect(L[2], 'optimal is the lightest').toBeGreaterThan(Math.max(L[0], L[4]))
186
+ expect(L[0], 'under is dark').toBeLessThan(L[1])
187
+ expect(L[4], 'over is dark').toBeLessThan(L[3])
188
+ })
189
+
190
+ it('holds a strong CVD floor (deltaE >= 10)', () => {
191
+ let worst = Infinity
192
+ for (let i = 0; i < divergingScale.length; i++) {
193
+ for (let j = i + 1; j < divergingScale.length; j++) {
194
+ worst = Math.min(worst, cvdDelta(divergingScale[i], divergingScale[j]))
195
+ }
196
+ }
197
+ expect(worst).toBeGreaterThanOrEqual(10)
198
+ })
199
+
200
+ it('every cell carries a legible label via best-contrast text (>=4.5)', () => {
201
+ for (const hex of divergingScale) {
202
+ expect(bestContrast(hex), `${hex}`).toBeGreaterThanOrEqual(4.5)
203
+ }
204
+ })
205
+ })
206
+
207
+ describe('sequentialEffort', () => {
208
+ it('is a six-stop ordinal scale of uppercase hex', () => {
209
+ expect(sequentialEffort).toHaveLength(6)
210
+ for (const hex of sequentialEffort) expect(hex).toMatch(HEX6)
211
+ })
212
+
213
+ it('keeps adjacent stops distinguishable', () => {
214
+ for (let i = 0; i < sequentialEffort.length - 1; i++) {
215
+ expect(cvdDelta(sequentialEffort[i], sequentialEffort[i + 1]), `stop ${i}->${i + 1}`).toBeGreaterThanOrEqual(4.5)
216
+ }
217
+ })
218
+
219
+ it('every stop carries a legible label via best-contrast text (>=4.5)', () => {
220
+ for (const hex of sequentialEffort) {
221
+ expect(bestContrast(hex), `${hex}`).toBeGreaterThanOrEqual(4.5)
222
+ }
223
+ })
224
+ })
225
+
226
+ describe('bestTextColor', () => {
227
+ it('picks black on light fills and white on dark fills', () => {
228
+ expect(bestTextColor(primitiveRamps.green[300])).toBe('#000000')
229
+ expect(bestTextColor(primitiveRamps.red[700])).toBe('#FFFFFF')
230
+ expect(bestTextColor(primitiveRamps.blue[700])).toBe('#FFFFFF')
231
+ })
232
+ })
@@ -62,6 +62,34 @@ export const primitiveColors = {
62
62
  900: '#7F1D1D',
63
63
  },
64
64
 
65
+ // Vivid green scale (live/go success)
66
+ greenVivid: {
67
+ 50: '#E9FBF0',
68
+ 100: '#C8F7DA',
69
+ 200: '#9FF0BF',
70
+ 300: '#6BE79D',
71
+ 400: '#47DE84', // Success vivid light
72
+ 500: '#2ED573', // Success vivid main
73
+ 600: '#22B85F',
74
+ 700: '#1A9950', // Success vivid dark
75
+ 800: '#157A40',
76
+ 900: '#105C30',
77
+ },
78
+
79
+ // Vivid red scale (alert)
80
+ redVivid: {
81
+ 50: '#FFECEE',
82
+ 100: '#FFD6DB',
83
+ 200: '#FFB3BC',
84
+ 300: '#FF8593',
85
+ 400: '#FF6070', // Error vivid light
86
+ 500: '#FF4757', // Error vivid main
87
+ 600: '#E63548',
88
+ 700: '#C42539', // Error vivid dark
89
+ 800: '#9E1C2C',
90
+ 900: '#7A1520',
91
+ },
92
+
65
93
  // Amber scale (warning)
66
94
  amber: {
67
95
  50: '#FFFBEB',
@@ -152,6 +180,225 @@ export const primitiveColors = {
152
180
  transparent: 'transparent',
153
181
  } as const
154
182
 
183
+ /**
184
+ * Derived tonal ramps (TD-05.09 color foundations)
185
+ *
186
+ * Seven OKLCH-generated hue ramps, 11 perceptual lightness steps each (50 -> 950).
187
+ * Built with hue-torsion + a chroma arc, anchored through existing brand/semantic
188
+ * hexes. `pin` marks the step each ramp flows through its anchor.
189
+ * This is the single source of truth for chromatic hexes — the categorical palette
190
+ * below references these steps rather than duplicating values.
191
+ * See coordination/design-explorations/foundations.
192
+ */
193
+ export const primitiveRamps = {
194
+ red: {
195
+ 50: '#FFF4F4',
196
+ 100: '#FFE3E5',
197
+ 200: '#FFC2C5',
198
+ 300: '#FF9A9D',
199
+ 400: '#F77175',
200
+ 500: '#E05254',
201
+ 600: '#D14343', // pin
202
+ 700: '#A4221C',
203
+ 800: '#7E1002',
204
+ 900: '#5A0900',
205
+ 950: '#3D0400',
206
+ },
207
+ orange: {
208
+ 50: '#FFF5ED',
209
+ 100: '#FFE6D4',
210
+ 200: '#FFC7A2',
211
+ 300: '#FFA063',
212
+ 400: '#FF7900', // pin
213
+ 500: '#DA5F00',
214
+ 600: '#B94A00',
215
+ 700: '#983804',
216
+ 800: '#6F290F',
217
+ 900: '#4E1C0C',
218
+ 950: '#331107',
219
+ },
220
+ amber: {
221
+ 50: '#FFF7DD',
222
+ 100: '#FFEAA9',
223
+ 200: '#FFD352',
224
+ 300: '#F9B415', // pin
225
+ 400: '#E08C00',
226
+ 500: '#C27400',
227
+ 600: '#A45E00',
228
+ 700: '#814D14',
229
+ 800: '#5B3A1A',
230
+ 900: '#442503',
231
+ 950: '#301500',
232
+ },
233
+ green: {
234
+ 50: '#E3FFEE',
235
+ 100: '#B5FFD2',
236
+ 200: '#58F69E',
237
+ 300: '#2ED573', // pin
238
+ 400: '#21C05D',
239
+ 500: '#22A444',
240
+ 600: '#298732',
241
+ 700: '#2B6B25',
242
+ 800: '#264D1C',
243
+ 900: '#1B3515',
244
+ 950: '#11220D',
245
+ },
246
+ cyan: {
247
+ 50: '#E6FBFF',
248
+ 100: '#C2F6FF',
249
+ 200: '#62EAFF',
250
+ 300: '#22D3EE', // pin
251
+ 400: '#01B5D1',
252
+ 500: '#2697B7',
253
+ 600: '#307B9B',
254
+ 700: '#2A617F',
255
+ 800: '#22465F',
256
+ 900: '#0B3149',
257
+ 950: '#001F36',
258
+ },
259
+ blue: {
260
+ 50: '#EFF8FF',
261
+ 100: '#D9EFFF',
262
+ 200: '#ACDBFF',
263
+ 300: '#78C2FF',
264
+ 400: '#3CA8FF',
265
+ 500: '#2196F3', // pin
266
+ 600: '#1072CB',
267
+ 700: '#135AA8',
268
+ 800: '#14407E',
269
+ 900: '#112C5A',
270
+ 950: '#091B3C',
271
+ },
272
+ magenta: {
273
+ 50: '#FFF3F9',
274
+ 100: '#FFE2F1',
275
+ 200: '#FFBDE2',
276
+ 300: '#FF8FD5',
277
+ 400: '#ED69C3',
278
+ 500: '#D548AF',
279
+ 600: '#BA2996',
280
+ 700: '#9C0D7A', // pin
281
+ 800: '#77005A',
282
+ 900: '#56003F',
283
+ 950: '#3B0029',
284
+ },
285
+ } as const
286
+
287
+ /**
288
+ * Categorical (qualitative) palette — an ordered, CVD-safe series expressed as
289
+ * references into {@link primitiveRamps} (one source of truth; the palette moves
290
+ * with the ramps).
291
+ *
292
+ * Design: a single canonical hue order (blue, magenta, red, orange, green, cyan,
293
+ * amber), with steps chosen vivid-midtone-first and fanned lighter/darker as the
294
+ * series grows to preserve separation. The sequence is nested-stable — a chart
295
+ * with N series uses the first N colors, and the series index is stable as N
296
+ * changes. Colorblind-safe worst-case deuteranopia/protanopia floor 8 holds
297
+ * through {@link CATEGORICAL_CVD_SAFE_MAX} colors; the 7th is an extended color
298
+ * that should be paired with a legend or other secondary encoding.
299
+ *
300
+ * Two variants: `default` (vivid, sits on neutral/light surfaces, legible under
301
+ * black text) and `dark` (deeper shades legible under white text on a fill). A
302
+ * separate "light" variant was dropped — the vivid `default` picks already clear
303
+ * black-text contrast, so it doubles as the light-context palette.
304
+ */
305
+ export const categoricalPalette = {
306
+ default: [
307
+ primitiveRamps.blue[500],
308
+ primitiveRamps.magenta[500],
309
+ primitiveRamps.red[500],
310
+ primitiveRamps.orange[400],
311
+ primitiveRamps.green[300],
312
+ primitiveRamps.cyan[300],
313
+ primitiveRamps.amber[600], // extended (7th) — pair with a legend
314
+ ],
315
+ dark: [
316
+ primitiveRamps.blue[600],
317
+ primitiveRamps.magenta[600],
318
+ primitiveRamps.red[500],
319
+ primitiveRamps.orange[600],
320
+ primitiveRamps.green[800],
321
+ primitiveRamps.cyan[800],
322
+ primitiveRamps.amber[500], // extended (7th) — pair with a legend
323
+ ],
324
+ } as const
325
+
326
+ /** Largest series count that holds the CVD floor without a legend. */
327
+ export const CATEGORICAL_CVD_SAFE_MAX = 6
328
+
329
+ /**
330
+ * Categorical palette variant.
331
+ * - `default` : vivid; neutral/light surfaces, legible under black text
332
+ * - `dark` : deeper shades, legible under white text on a filled swatch
333
+ */
334
+ export type CategoricalVariant = keyof typeof categoricalPalette
335
+
336
+ /**
337
+ * Get a color from the ordered categorical palette by series index.
338
+ * The palette is nested-stable, so the color for a given index does not change
339
+ * with the total series count; `index` simply wraps past the end.
340
+ *
341
+ * @param index - 0-based series index (wraps past the end)
342
+ * @param variant - `default` (black-text / light surfaces) or `dark` (white text)
343
+ * @returns The hex color string
344
+ */
345
+ export function getCategoricalColor(index: number, variant: CategoricalVariant = 'default'): string {
346
+ const palette = categoricalPalette[variant]
347
+ index = Math.max(0, Math.floor(index))
348
+ return palette[index % palette.length]
349
+ }
350
+
351
+ /**
352
+ * Diverging status scale (BodyMap training-status: under → optimal → over) as
353
+ * references into {@link primitiveRamps}. A true diverging shape — `optimal` is
354
+ * the lightest center, the extremes go darker — so the signal reads in lightness
355
+ * (colorblind-robust; worst-case deut/protanopia min ΔE ~10.9) and the direction
356
+ * reads in the blue↔red axis (the CVD-safe hue pair).
357
+ *
358
+ * Tuned so every stop is dark enough for the fill yet light enough that BLACK
359
+ * text clears 4.5:1 on all five — no per-cell white/black flipping. The value
360
+ * valley is symmetric: the two mid-arms (maintenance / approaching) sit at equal
361
+ * lightness (both ~0.53 relative luminance), the ends darker.
362
+ */
363
+ export const divergingScale = [
364
+ primitiveRamps.blue[500], // under
365
+ primitiveRamps.cyan[300], // maintenance
366
+ primitiveRamps.green[200], // optimal (light center)
367
+ primitiveRamps.amber[300], // approaching
368
+ primitiveRamps.red[600], // over
369
+ ] as const
370
+
371
+ /**
372
+ * Sequential "effort" scale (low → high intensity: green → yellow → orange → red)
373
+ * as references into {@link primitiveRamps}. A 6-stop ordinal palette; the
374
+ * velocity/RPE strip sub-samples it. Every adjacent pair clears the CVD floor
375
+ * (min deut/protan ΔE ≥ 4.5), and within that the hue walk is kept smooth —
376
+ * the amber-200 → amber-300 → orange-400 run steps the yellow→orange transition
377
+ * gradually rather than lurching. Order encodes magnitude, so it tolerates the
378
+ * green↔red CVD pair. Stops 0–3 take black text; the dark reds take white.
379
+ */
380
+ export const sequentialEffort = [
381
+ primitiveRamps.green[300],
382
+ primitiveRamps.amber[200],
383
+ primitiveRamps.amber[300],
384
+ primitiveRamps.orange[400],
385
+ primitiveRamps.red[600],
386
+ primitiveRamps.red[700],
387
+ ] as const
388
+
389
+ /**
390
+ * Best-contrast text color (black or white) for a solid fill — for labels sitting
391
+ * on categorical/diverging/effort swatches. Uses the WCAG relative-luminance ratio.
392
+ */
393
+ export function bestTextColor(hex: string): '#000000' | '#FFFFFF' {
394
+ const [r, g, b] = [0, 2, 4].map((i) => {
395
+ const c = parseInt(hex.replace('#', '').slice(i, i + 2), 16) / 255
396
+ return c >= 0.04045 ? ((c + 0.055) / 1.055) ** 2.4 : c / 12.92
397
+ })
398
+ const l = 0.2126 * r + 0.7152 * g + 0.0722 * b
399
+ return (l + 0.05) / 0.05 >= 1.05 / (l + 0.05) ? '#000000' : '#FFFFFF'
400
+ }
401
+
155
402
  /**
156
403
  * Discrete rainbow palette for data visualization
157
404
  * Based on Paul Tol's color schemes: https://personal.sron.nl/~pault/#fig:scheme_rainbow_discrete