@crewlethq/tokens 0.49.0 → 0.50.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/dist/themes.js CHANGED
@@ -1,283 +1,8 @@
1
1
  /* Generated by style-dictionary. Do not edit. */
2
- /**
3
- * The two palettes, for JavaScript that cannot read a custom property: the
4
- * tool chrome around a preview, a chart library that wants a series' colour
5
- * as a string, a canvas that paints its own pixels.
6
- *
7
- * PREFER THE CUSTOM PROPERTY wherever CSS can reach: a value read here is a
8
- * value taken at build time, so it does not follow a theme the reader
9
- * changes. This is for the places where there is no element to read from.
2
+ /*
3
+ * The theme registry: the themes this build ships, as a picker lists them.
4
+ * The palettes themselves are palettes.ts, a module of their own.
10
5
  */
11
- export const themes = {
12
- "light": {
13
- "color": {
14
- "surface": {
15
- "frame": "#e9ecf3",
16
- "background": "#f6f7fb",
17
- "subtle": "#fcfcfc",
18
- "elevated": "#f1f2f6",
19
- "hover": "rgba(7, 8, 13, 0.044)",
20
- "pressed": "rgba(7, 8, 13, 0.088)",
21
- "inset": "rgba(7, 8, 13, 0.026)",
22
- "glass": "rgba(252, 252, 252, 0.90)",
23
- "scrim": "rgba(0, 0, 0, 0.6)",
24
- "veil": "rgba(233, 236, 243, 0.65)",
25
- "inverse": "#07080d"
26
- },
27
- "text": {
28
- "primary": "#121625",
29
- "secondary": "#3e4459",
30
- "linkQuiet": "#484e99",
31
- "tertiary": "#585e73",
32
- "muted": "#878d9f",
33
- "onAccent": "#ffffff",
34
- "onDanger": "#ffffff",
35
- "onScrim": "#ffffff",
36
- "inverse": "#f6f7fb"
37
- },
38
- "brand": {
39
- "accent": "#735af2",
40
- "accentHover": "#674ee4",
41
- "accentActive": "#5b3dc7",
42
- "accentInk": "#4f51bd",
43
- "accentSoft": "rgba(115, 90, 242, 0.125)",
44
- "accentRgb": "115, 90, 242",
45
- "accentSoftStrong": "rgba(115, 90, 242, 0.32)"
46
- },
47
- "border": {
48
- "default": "#e5e6ea",
49
- "hover": "#c9cfdc",
50
- "strong": "#c9cfdc",
51
- "strongHover": "#acb6cc",
52
- "hatch": "#dbdfe8",
53
- "control": "#777a83",
54
- "field": "#838894",
55
- "selected": "rgba(115, 90, 242, 0.6)"
56
- },
57
- "focus": "#735af2",
58
- "feedback": {
59
- "success": "#0b9a74",
60
- "successInk": "#0b6a4b",
61
- "warning": "#c17300",
62
- "warningInk": "#8c4e00",
63
- "danger": "#b9112c",
64
- "dangerHover": "#ad0023",
65
- "dangerInk": "#b20d23",
66
- "info": "#2f92b4",
67
- "infoInk": "#1a6588",
68
- "successSoft": "rgba(11, 154, 116, 0.12)",
69
- "successLine": "rgba(11, 154, 116, 0.3)",
70
- "warningSoft": "rgba(193, 115, 0, 0.12)",
71
- "warningLine": "rgba(193, 115, 0, 0.3)",
72
- "dangerSoft": "rgba(185, 17, 44, 0.12)",
73
- "dangerLine": "rgba(185, 17, 44, 0.3)",
74
- "infoSoft": "rgba(47, 146, 180, 0.12)",
75
- "infoLine": "rgba(47, 146, 180, 0.3)"
76
- },
77
- "data": {
78
- "1": "#5c76c3",
79
- "2": "#dd5920",
80
- "3": "#00956e",
81
- "4": "#c27600",
82
- "other": "#85868d"
83
- },
84
- "node": {
85
- "purple": "#7150b3",
86
- "purpleInk": "#573394",
87
- "cyan": "#166b80",
88
- "cyanInk": "#004f62",
89
- "green": "#2c7046",
90
- "greenInk": "#05532b",
91
- "amber": "#865a28",
92
- "amberInk": "#683e03",
93
- "rose": "#984a55",
94
- "roseInk": "#7a2f3c",
95
- "blue": "#4062a7",
96
- "blueInk": "#264588",
97
- "purpleFill": "rgba(113, 80, 179, 0.12)",
98
- "purpleLine": "rgba(113, 80, 179, 0.38)",
99
- "purpleHalo": "rgba(113, 80, 179, 0.16)",
100
- "cyanFill": "rgba(22, 107, 128, 0.12)",
101
- "cyanLine": "rgba(22, 107, 128, 0.38)",
102
- "cyanHalo": "rgba(22, 107, 128, 0.16)",
103
- "greenFill": "rgba(44, 112, 70, 0.12)",
104
- "greenLine": "rgba(44, 112, 70, 0.38)",
105
- "greenHalo": "rgba(44, 112, 70, 0.16)",
106
- "amberFill": "rgba(134, 90, 40, 0.12)",
107
- "amberLine": "rgba(134, 90, 40, 0.38)",
108
- "amberHalo": "rgba(134, 90, 40, 0.16)",
109
- "roseFill": "rgba(152, 74, 85, 0.12)",
110
- "roseLine": "rgba(152, 74, 85, 0.38)",
111
- "roseHalo": "rgba(152, 74, 85, 0.16)",
112
- "blueFill": "rgba(64, 98, 167, 0.12)",
113
- "blueLine": "rgba(64, 98, 167, 0.38)",
114
- "blueHalo": "rgba(64, 98, 167, 0.16)"
115
- },
116
- "presence": {
117
- "flagText": "#ffffff"
118
- },
119
- "artifact": {
120
- "kind": {
121
- "brand": "#8f3884",
122
- "brandInk": "#74246a",
123
- "brandFill": "rgba(143, 56, 132, 0.12)",
124
- "brandLine": "rgba(143, 56, 132, 0.38)"
125
- }
126
- },
127
- "scrollbar": "rgba(7, 8, 13, 0.2)",
128
- "scrollbarHover": "rgba(7, 8, 13, 0.32)"
129
- },
130
- "shadow": {
131
- "xs": "0 1px 2px rgba(7, 8, 13, 0.06)",
132
- "sm": "0 2px 8px rgba(7, 8, 13, 0.07)",
133
- "md": "0 4px 12px rgba(7, 8, 13, 0.08), 0 1px 3px rgba(7, 8, 13, 0.06)",
134
- "lg": "0 8px 24px rgba(7, 8, 13, 0.12)",
135
- "xl": "0 16px 40px rgba(7, 8, 13, 0.16), 0 2px 8px rgba(7, 8, 13, 0.08)",
136
- "sheet": "-16px 0 40px rgba(7, 8, 13, 0.16), -2px 0 8px rgba(7, 8, 13, 0.08)",
137
- "2xl": "0 16px 64px rgba(7, 8, 13, 0.20)",
138
- "card": "0 8px 24px rgba(7, 8, 13, 0.07)",
139
- "rimLit": "0 4px 24px rgba(7, 8, 13, 0.10), inset 0 1px 0 rgba(255, 255, 255, 0.6)",
140
- "hairline": "none",
141
- "focus": "0 0 0 2px var(--color-surface-background), 0 0 0 4px var(--color-focus)",
142
- "selection": "inset 0 0 0 2px var(--color-brand-accent)",
143
- "glow": "0 4px 24px rgba(var(--color-brand-accent-rgb), 0.22)"
144
- }
145
- },
146
- "dark": {
147
- "color": {
148
- "surface": {
149
- "frame": "#07080d",
150
- "background": "#0c0e16",
151
- "subtle": "#11141d",
152
- "elevated": "#242833",
153
- "hover": "rgba(255, 255, 255, 0.061)",
154
- "pressed": "rgba(255, 255, 255, 0.098)",
155
- "inset": "rgba(255, 255, 255, 0.028)",
156
- "glass": "rgba(17, 20, 29, 0.90)",
157
- "scrim": "rgba(0, 0, 0, 0.6)",
158
- "veil": "rgba(7, 8, 13, 0.65)",
159
- "inverse": "#fcfcfc"
160
- },
161
- "text": {
162
- "primary": "#e7eaf3",
163
- "secondary": "#a9b0c3",
164
- "linkQuiet": "#a9b0ea",
165
- "tertiary": "#9fa7bc",
166
- "muted": "#5a6176",
167
- "onAccent": "#ffffff",
168
- "onDanger": "#ffffff",
169
- "onScrim": "#ffffff",
170
- "inverse": "#07080d"
171
- },
172
- "brand": {
173
- "accent": "#725be6",
174
- "accentHover": "#674ee4",
175
- "accentActive": "#5b3dc7",
176
- "accentInk": "#a9b0ff",
177
- "accentSoft": "rgba(114, 91, 230, 0.16)",
178
- "accentRgb": "114, 91, 230",
179
- "accentSoftStrong": "rgba(114, 91, 230, 0.32)"
180
- },
181
- "border": {
182
- "default": "#1e2025",
183
- "hover": "#2d3448",
184
- "strong": "#2d3448",
185
- "strongHover": "#424f74",
186
- "hatch": "#202534",
187
- "control": "#7f879c",
188
- "field": "#687187",
189
- "selected": "rgba(114, 91, 230, 0.6)"
190
- },
191
- "focus": "#8572fe",
192
- "feedback": {
193
- "success": "#34c98b",
194
- "successInk": "#74dcae",
195
- "warning": "#f0b425",
196
- "warningInk": "#f6cd72",
197
- "danger": "#d73756",
198
- "dangerHover": "#cc2b4e",
199
- "dangerInk": "#ff9fb0",
200
- "info": "#61d0ff",
201
- "infoInk": "#8ad6fb",
202
- "successSoft": "rgba(52, 201, 139, 0.12)",
203
- "successLine": "rgba(52, 201, 139, 0.3)",
204
- "warningSoft": "rgba(240, 180, 37, 0.12)",
205
- "warningLine": "rgba(240, 180, 37, 0.3)",
206
- "dangerSoft": "rgba(215, 55, 86, 0.12)",
207
- "dangerLine": "rgba(215, 55, 86, 0.3)",
208
- "infoSoft": "rgba(97, 208, 255, 0.12)",
209
- "infoLine": "rgba(97, 208, 255, 0.3)"
210
- },
211
- "data": {
212
- "1": "#4d8ff6",
213
- "2": "#e67737",
214
- "3": "#26b582",
215
- "4": "#eab106",
216
- "other": "#6a7186"
217
- },
218
- "node": {
219
- "purple": "#8e6ed4",
220
- "purpleInk": "#cabae0",
221
- "cyan": "#5ca8be",
222
- "cyanInk": "#b3d7e0",
223
- "green": "#62a578",
224
- "greenInk": "#b8d8c0",
225
- "amber": "#c89866",
226
- "amberInk": "#e0c89e",
227
- "rose": "#c8757f",
228
- "roseInk": "#e0bfc4",
229
- "blue": "#5b7fc7",
230
- "blueInk": "#b9c5e0",
231
- "purpleFill": "rgba(142, 110, 212, 0.12)",
232
- "purpleLine": "rgba(142, 110, 212, 0.38)",
233
- "purpleHalo": "rgba(142, 110, 212, 0.16)",
234
- "cyanFill": "rgba(92, 168, 190, 0.12)",
235
- "cyanLine": "rgba(92, 168, 190, 0.38)",
236
- "cyanHalo": "rgba(92, 168, 190, 0.16)",
237
- "greenFill": "rgba(98, 165, 120, 0.12)",
238
- "greenLine": "rgba(98, 165, 120, 0.38)",
239
- "greenHalo": "rgba(98, 165, 120, 0.16)",
240
- "amberFill": "rgba(200, 152, 102, 0.12)",
241
- "amberLine": "rgba(200, 152, 102, 0.38)",
242
- "amberHalo": "rgba(200, 152, 102, 0.16)",
243
- "roseFill": "rgba(200, 117, 127, 0.12)",
244
- "roseLine": "rgba(200, 117, 127, 0.38)",
245
- "roseHalo": "rgba(200, 117, 127, 0.16)",
246
- "blueFill": "rgba(91, 127, 199, 0.12)",
247
- "blueLine": "rgba(91, 127, 199, 0.38)",
248
- "blueHalo": "rgba(91, 127, 199, 0.16)"
249
- },
250
- "presence": {
251
- "flagText": "#07080d"
252
- },
253
- "artifact": {
254
- "kind": {
255
- "brand": "#cc7bd1",
256
- "brandInk": "#dabcdb",
257
- "brandFill": "rgba(204, 123, 209, 0.12)",
258
- "brandLine": "rgba(204, 123, 209, 0.38)"
259
- }
260
- },
261
- "scrollbar": "rgba(255, 255, 255, 0.16)",
262
- "scrollbarHover": "rgba(255, 255, 255, 0.26)"
263
- },
264
- "shadow": {
265
- "xs": "0 1px 2px rgba(0, 0, 0, 0.2)",
266
- "sm": "0 2px 8px rgba(0, 0, 0, 0.15)",
267
- "md": "0 4px 12px rgba(0, 0, 0, 0.25)",
268
- "lg": "0 8px 24px rgba(0, 0, 0, 0.3)",
269
- "xl": "0 12px 32px rgba(0, 0, 0, 0.4)",
270
- "sheet": "-8px 0 32px rgba(0, 0, 0, 0.4)",
271
- "2xl": "0 16px 64px rgba(0, 0, 0, 0.6)",
272
- "card": "0 8px 24px rgba(0, 0, 0, 0.1)",
273
- "rimLit": "0 4px 24px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.04)",
274
- "hairline": "inset 0 1px 0 rgba(255, 255, 255, 0.04)",
275
- "focus": "0 0 0 2px var(--color-surface-background), 0 0 0 4px var(--color-focus)",
276
- "selection": "inset 0 0 0 2px var(--color-brand-accent)",
277
- "glow": "0 4px 24px rgba(var(--color-brand-accent-rgb), 0.3)"
278
- }
279
- }
280
- };
281
6
  /** The groups a theme picker lists the themes under, in order. */
282
7
  export const themeGroups = [
283
8
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewlethq/tokens",
3
- "version": "0.49.0",
3
+ "version": "0.50.0",
4
4
  "description": "Crewlet design tokens. Single JSON source compiled to CSS variables and typed JS modules.",
5
5
  "license": "MIT AND OFL-1.1",
6
6
  "repository": {
@@ -55,7 +55,7 @@
55
55
  "lint": "eslint scripts test",
56
56
  "typecheck": "tsc -p tsconfig.json --noEmit",
57
57
  "test": "node --test \"test/*.test.mjs\"",
58
- "clean": "rm -rf dist src/index.ts src/themes.ts"
58
+ "clean": "rm -rf dist src/index.ts src/themes.ts src/palettes.ts"
59
59
  },
60
60
  "devDependencies": {
61
61
  "style-dictionary": "^5.6.0"
package/test/color.mjs CHANGED
@@ -13,16 +13,30 @@
13
13
  * It is published as part of `@crewlethq/tokens/test/palette`, so a consumer
14
14
  * runs the same maths over the version it installed.
15
15
  *
16
- * The colour values and the WCAG ratio are not implemented here: they are the
17
- * package's runtime module (`src/color.ts`, built to `dist/color.js`), which
18
- * `@crewlethq/tokens` itself exports, and this file re-exports them. An
19
- * interface that shows a contrast ratio and the suite that holds a theme to
20
- * one therefore compute it with the same code.
16
+ * The colour values, the WCAG ratio and the OKLab conversions are not
17
+ * implemented here: they are the package's runtime module (`src/color.ts`,
18
+ * built to `dist/color.js`), which `@crewlethq/tokens` itself exports, and
19
+ * this file re-exports them. An interface that shows a contrast ratio, or
20
+ * suggests the nearest shade that clears one, and the suite that holds a theme
21
+ * to one therefore compute it with the same code.
21
22
  */
22
23
 
23
- import { contrast, linearChannel, luminance, parseHex, parseRgba, withAlpha } from '../dist/color.js';
24
-
25
- export { contrast, luminance, parseHex, parseRgba, withAlpha };
24
+ import {
25
+ contrast,
26
+ formatHex,
27
+ fromLinear,
28
+ fromOklab,
29
+ linearChannel,
30
+ luminance,
31
+ oklabToLinear,
32
+ parseHex,
33
+ parseRgba,
34
+ toOklab,
35
+ withAlpha,
36
+ } from '../dist/color.js';
37
+
38
+ export { contrast, fromOklab, luminance, oklabToLinear, parseHex, parseRgba, toOklab, withAlpha };
39
+ export { formatHex as hex };
26
40
 
27
41
  /** @typedef {{ r: number, g: number, b: number }} RGB */
28
42
 
@@ -132,20 +146,6 @@ export function flatten(value, backdrop) {
132
146
  // greens a reader cannot tell apart at 11px.
133
147
  // ---------------------------------------------------------------------------
134
148
 
135
- export function toOklab({ r, g, b }) {
136
- const lr = linearChannel(r);
137
- const lg = linearChannel(g);
138
- const lb = linearChannel(b);
139
- const l = Math.cbrt(0.4122214708 * lr + 0.5363325363 * lg + 0.0514459929 * lb);
140
- const m = Math.cbrt(0.2119034982 * lr + 0.6806995451 * lg + 0.1073969566 * lb);
141
- const s = Math.cbrt(0.0883024619 * lr + 0.2817188376 * lg + 0.6299787005 * lb);
142
- return {
143
- L: 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
144
- a: 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
145
- b: 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
146
- };
147
- }
148
-
149
149
  /** Perceptual distance, scaled to roughly CIE dE units so floors read familiar. */
150
150
  export function deltaE(x, y) {
151
151
  const a = toOklab(x);
@@ -164,38 +164,6 @@ export function chroma(c) {
164
164
  return Math.hypot(a, b) * 100;
165
165
  }
166
166
 
167
- function fromLinear(v) {
168
- const c = v <= 0.0031308 ? v * 12.92 : 1.055 * v ** (1 / 2.4) - 0.055;
169
- return Math.min(255, Math.max(0, c * 255));
170
- }
171
-
172
- /**
173
- * OKLab to LINEAR sRGB, unclipped. A channel under 0 or over 1 says the
174
- * colour is outside what a screen can show, which fromOklab hides by clipping
175
- * each channel on its own, and clipping one channel turns the hue: a search
176
- * that walks chroma has to know where the gamut ends rather than be handed a
177
- * different colour from the one it asked for.
178
- */
179
- export function oklabToLinear({ L, a, b }) {
180
- const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
181
- const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
182
- const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
183
- return {
184
- r: 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
185
- g: -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
186
- b: -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,
187
- };
188
- }
189
-
190
- /** OKLab to sRGB, clipped. Used to search for the nearest passing value. */
191
- export function fromOklab(lab) {
192
- const { r, g, b } = oklabToLinear(lab);
193
- return { r: Math.round(fromLinear(r)), g: Math.round(fromLinear(g)), b: Math.round(fromLinear(b)) };
194
- }
195
-
196
- export const hex = ({ r, g, b }) =>
197
- `#${[r, g, b].map((v) => Math.round(v).toString(16).padStart(2, '0')).join('')}`;
198
-
199
167
  /**
200
168
  * Move a colour along OKLab lightness only, keeping hue and chroma, until
201
169
  * `ok` holds. A failing token moves MINIMALLY and inside its own hue family;
@@ -205,7 +173,7 @@ export function nudge(value, direction, ok, step = 0.002) {
205
173
  const lab = toOklab(parseHex(value));
206
174
  for (let i = 0; i <= 500; i += 1) {
207
175
  const candidate = fromOklab({ L: lab.L + direction * step * i, a: lab.a, b: lab.b });
208
- if (ok(candidate)) return { value: hex(candidate), dL: +(direction * step * i * 100).toFixed(1) };
176
+ if (ok(candidate)) return { value: formatHex(candidate), dL: +(direction * step * i * 100).toFixed(1) };
209
177
  }
210
178
  return null;
211
179
  }