@diskette/palette 0.9.0 → 0.9.2

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 (3) hide show
  1. package/README.md +200 -24
  2. package/dist/lib.js +7 -5
  3. package/package.json +13 -4
package/README.md CHANGED
@@ -132,18 +132,18 @@ css.scale(scheme: 'light' | 'lightAlpha' | 'dark' | 'darkAlpha', config: ColorCo
132
132
  :root,
133
133
  .light,
134
134
  .light-theme {
135
- amber1: #fefdfb;
136
- amber2: #fefbe9;
137
- amber3: #fff7c2;
138
- amber4: #ffee9c;
139
- amber5: #fbe577;
140
- amber6: #f3d673;
141
- amber7: #e9c162;
142
- amber8: #e2a336;
143
- amber9: #ffc53d;
144
- amber10: #ffba18;
145
- amber11: #ab6400;
146
- amber12: #4f3422;
135
+ --amber-1: #fefdfb;
136
+ --amber-2: #fefbe9;
137
+ --amber-3: #fff7c2;
138
+ --amber-4: #ffee9c;
139
+ --amber-5: #fbe577;
140
+ --amber-6: #f3d673;
141
+ --amber-7: #e9c162;
142
+ --amber-8: #e2a336;
143
+ --amber-9: #ffc53d;
144
+ --amber-10: #ffba18;
145
+ --amber-11: #ab6400;
146
+ --amber-12: #4f3422;
147
147
  }
148
148
 
149
149
  @supports (color: color(display-p3 1 1 1)) {
@@ -151,18 +151,18 @@ css.scale(scheme: 'light' | 'lightAlpha' | 'dark' | 'darkAlpha', config: ColorCo
151
151
  :root,
152
152
  .light,
153
153
  .light-theme {
154
- amber1: color(display-p3 0.995 0.992 0.985);
155
- amber2: color(display-p3 0.994 0.986 0.921);
156
- amber3: color(display-p3 0.994 0.969 0.782);
157
- amber4: color(display-p3 0.989 0.937 0.65);
158
- amber5: color(display-p3 0.97 0.902 0.527);
159
- amber6: color(display-p3 0.936 0.844 0.506);
160
- amber7: color(display-p3 0.89 0.762 0.443);
161
- amber8: color(display-p3 0.85 0.65 0.3);
162
- amber9: color(display-p3 1 0.77 0.26);
163
- amber10: color(display-p3 0.959 0.741 0.274);
164
- amber11: color(display-p3 0.64 0.4 0);
165
- amber12: color(display-p3 0.294 0.208 0.145);
154
+ --amber-1: color(display-p3 0.995 0.992 0.985);
155
+ --amber-2: color(display-p3 0.994 0.986 0.921);
156
+ --amber-3: color(display-p3 0.994 0.969 0.782);
157
+ --amber-4: color(display-p3 0.989 0.937 0.65);
158
+ --amber-5: color(display-p3 0.97 0.902 0.527);
159
+ --amber-6: color(display-p3 0.936 0.844 0.506);
160
+ --amber-7: color(display-p3 0.89 0.762 0.443);
161
+ --amber-8: color(display-p3 0.85 0.65 0.3);
162
+ --amber-9: color(display-p3 1 0.77 0.26);
163
+ --amber-10: color(display-p3 0.959 0.741 0.274);
164
+ --amber-11: color(display-p3 0.64 0.4 0);
165
+ --amber-12: color(display-p3 0.294 0.208 0.145);
166
166
  }
167
167
  }
168
168
  }
@@ -224,6 +224,182 @@ css.semantic(name: string, config: ColorConfig): string
224
224
 
225
225
  </details>
226
226
 
227
+ ## Examples
228
+
229
+ ### Generate a Complete CSS File
230
+
231
+ ```ts
232
+ // scripts/generate-css.ts
233
+ import { writeFileSync } from 'node:fs'
234
+ import { css, colors } from '@diskette/palette'
235
+ import { blackAlpha, whiteAlpha } from '@diskette/palette/colors'
236
+
237
+ let output = ''
238
+
239
+ // Generate scales for all colors
240
+ for (const color of colors) {
241
+ output += css.scale('light', color)
242
+ output += css.scale('lightAlpha', color)
243
+ output += css.scale('dark', color)
244
+ output += css.scale('darkAlpha', color)
245
+ }
246
+
247
+ // Generate alpha colors
248
+ output += css.alpha(blackAlpha)
249
+ output += css.alpha(whiteAlpha)
250
+
251
+ writeFileSync('dist/colors.css', output)
252
+ ```
253
+
254
+ ### Generate CSS for Selected Colors
255
+
256
+ ```ts
257
+ // scripts/generate-theme.ts
258
+ import { writeFileSync } from 'node:fs'
259
+ import { css } from '@diskette/palette'
260
+ import blue from '@diskette/palette/colors/blue'
261
+ import gray from '@diskette/palette/colors/gray'
262
+
263
+ const output = [
264
+ // Base scales
265
+ css.scale('light', blue),
266
+ css.scale('dark', blue),
267
+ css.scale('light', gray),
268
+ css.scale('dark', gray),
269
+
270
+ // Semantic tokens
271
+ css.semantic('blue', blue),
272
+ css.semantic('gray', gray),
273
+ ].join('\n')
274
+
275
+ writeFileSync('src/styles/theme.css', output)
276
+ ```
277
+
278
+ ### Generate CSS with Custom Build Script
279
+
280
+ ```ts
281
+ // build-colors.ts
282
+ import { writeFileSync, mkdirSync } from 'node:fs'
283
+ import { css, colors } from '@diskette/palette'
284
+
285
+ mkdirSync('dist', { recursive: true })
286
+
287
+ // Generate individual files per color
288
+ for (const color of colors) {
289
+ const name = Object.keys(color.srgb.light)[0].replace(/\d+$/, '')
290
+
291
+ const content = [
292
+ css.scale('light', color),
293
+ css.scale('dark', color),
294
+ css.semantic(name, color),
295
+ ].join('\n')
296
+
297
+ writeFileSync(`dist/${name}.css`, content)
298
+ }
299
+
300
+ // Generate combined file
301
+ let combined = ''
302
+ for (const color of colors) {
303
+ const name = Object.keys(color.srgb.light)[0].replace(/\d+$/, '')
304
+ combined += css.scale('light', color)
305
+ combined += css.scale('dark', color)
306
+ combined += css.semantic(name, color)
307
+ }
308
+ writeFileSync('dist/all-colors.css', combined)
309
+ ```
310
+
311
+ ### Use with vanilla-extract
312
+
313
+ ```ts
314
+ // src/styles/colors.css.ts
315
+ import { createGlobalTheme } from '@vanilla-extract/css'
316
+ import blue from '@diskette/palette/colors/blue'
317
+ import gray from '@diskette/palette/colors/gray'
318
+
319
+ // Create CSS variables from the palette
320
+ createGlobalTheme(':root', {
321
+ colors: {
322
+ blue1: blue.srgb.light.blue1,
323
+ blue2: blue.srgb.light.blue2,
324
+ blue3: blue.srgb.light.blue3,
325
+ // ... etc
326
+ blue9: blue.srgb.light.blue9,
327
+ blue10: blue.srgb.light.blue10,
328
+ blue11: blue.srgb.light.blue11,
329
+ blue12: blue.srgb.light.blue12,
330
+ gray1: gray.srgb.light.gray1,
331
+ // ... etc
332
+ },
333
+ })
334
+
335
+ // For dark mode
336
+ createGlobalTheme('.dark', {
337
+ colors: {
338
+ blue1: blue.srgb.dark.blue1,
339
+ blue2: blue.srgb.dark.blue2,
340
+ // ... etc
341
+ },
342
+ })
343
+ ```
344
+
345
+ ### Generate Semantic Tokens Only
346
+
347
+ ```ts
348
+ // scripts/semantic-tokens.ts
349
+ import { writeFileSync } from 'node:fs'
350
+ import { css, colors } from '@diskette/palette'
351
+
352
+ let output = ''
353
+
354
+ for (const color of colors) {
355
+ // Extract color name from first key (e.g., "blue1" -> "blue")
356
+ const name = Object.keys(color.srgb.light)[0].replace(/\d+$/, '')
357
+ output += css.semantic(name, color)
358
+ }
359
+
360
+ writeFileSync('dist/semantic.css', output)
361
+ ```
362
+
363
+ ### Access Colors Directly in JavaScript
364
+
365
+ ```ts
366
+ import blue from '@diskette/palette/colors/blue'
367
+
368
+ // Use in CSS-in-JS libraries
369
+ const styles = {
370
+ button: {
371
+ backgroundColor: blue.srgb.light.blue9,
372
+ color: blue.contrast,
373
+ '&:hover': {
374
+ backgroundColor: blue.srgb.light.blue10,
375
+ },
376
+ },
377
+ }
378
+
379
+ // Use P3 colors for wider gamut displays
380
+ const p3Styles = {
381
+ button: {
382
+ backgroundColor: blue.p3.light.blue9,
383
+ },
384
+ }
385
+
386
+ // Access surface colors for overlays
387
+ const overlay = {
388
+ backgroundColor: blue.surface.srgb.light, // '#f1f9ffcc'
389
+ }
390
+ ```
391
+
392
+ ### NPM Script Integration
393
+
394
+ ```json
395
+ {
396
+ "scripts": {
397
+ "build:css": "tsx scripts/generate-css.ts",
398
+ "build": "pnpm build:css && vite build"
399
+ }
400
+ }
401
+ ```
402
+
227
403
  ## Credits
228
404
 
229
405
  Color values are derived from [Radix Colors](https://www.radix-ui.com/colors) by [WorkOS](https://workos.com/).
package/dist/lib.js CHANGED
@@ -1,5 +1,7 @@
1
1
  const lightSelector = `:root, .light, .light-theme`;
2
2
  const darkSelector = `.dark, .dark-theme`;
3
+ /** Convert color key to CSS variable name (e.g., "blue1" → "--blue-1", "blueA1" → "--blue-a1") */
4
+ const toVarName = (key) => '--' + key.replace(/A?(\d)/, (_, num) => (key.includes('A') ? `-a${num}` : `-${num}`));
3
5
  export const css = {
4
6
  scale(scheme, config) {
5
7
  const isLight = scheme === 'light' || scheme === 'lightAlpha';
@@ -14,10 +16,10 @@ export const css = {
14
16
  return isAlpha ? hasAlpha : !hasAlpha;
15
17
  });
16
18
  const baseVars = filterEntries(srgbScale)
17
- .map(([key, value]) => ` ${key}: ${value};`)
19
+ .map(([key, value]) => ` ${toVarName(key)}: ${value};`)
18
20
  .join('\n');
19
21
  const p3Vars = filterEntries(p3Scale)
20
- .map(([key, value]) => ` ${key}: ${value};`)
22
+ .map(([key, value]) => ` ${toVarName(key)}: ${value};`)
21
23
  .join('\n');
22
24
  return `${selector} {
23
25
  ${baseVars}
@@ -34,10 +36,10 @@ ${p3Vars}
34
36
  },
35
37
  alpha(config) {
36
38
  const baseVars = Object.entries(config.srgb)
37
- .map(([key, value]) => ` ${key}: ${value};`)
39
+ .map(([key, value]) => ` ${toVarName(key)}: ${value};`)
38
40
  .join('\n');
39
41
  const p3Vars = Object.entries(config.p3)
40
- .map(([key, value]) => ` ${key}: ${value};`)
42
+ .map(([key, value]) => ` ${toVarName(key)}: ${value};`)
41
43
  .join('\n');
42
44
  return `:root {
43
45
  ${baseVars}
@@ -53,7 +55,7 @@ ${p3Vars}
53
55
  `;
54
56
  },
55
57
  semantic(name, config) {
56
- const varRef = (key) => `var(--${key.replace(/(\d+)$/, '-$1')})`;
58
+ const varRef = (key) => `var(${toVarName(key)})`;
57
59
  return `:root {
58
60
  --${name}-contrast: ${config.contrast};
59
61
  }
package/package.json CHANGED
@@ -1,11 +1,20 @@
1
1
  {
2
2
  "name": "@diskette/palette",
3
3
  "type": "module",
4
- "version": "0.9.0",
4
+ "version": "0.9.2",
5
5
  "exports": {
6
- ".": "./dist/colors.js",
7
- "./colors": "./dist/colors/index.js",
8
- "./colors/*": "./dist/colors/*.js"
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "default": "./dist/index.js"
9
+ },
10
+ "./colors": {
11
+ "types": "./dist/colors/index.d.ts",
12
+ "default": "./dist/colors/index.js"
13
+ },
14
+ "./colors/*": {
15
+ "types": "./dist/colors/*.d.ts",
16
+ "default": "./dist/colors/*.js"
17
+ }
9
18
  },
10
19
  "files": [
11
20
  "dist"