@diskette/palette 0.18.0 → 0.20.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 (77) hide show
  1. package/README.md +90 -70
  2. package/dist/cli/cli.d.ts +1 -1
  3. package/dist/cli/cli.js +59 -9
  4. package/dist/colors/amber.d.ts +21 -109
  5. package/dist/colors/amber.js +126 -109
  6. package/dist/colors/blue.d.ts +21 -109
  7. package/dist/colors/blue.js +126 -109
  8. package/dist/colors/bronze.d.ts +21 -109
  9. package/dist/colors/bronze.js +126 -109
  10. package/dist/colors/brown.d.ts +21 -109
  11. package/dist/colors/brown.js +126 -109
  12. package/dist/colors/crimson.d.ts +21 -109
  13. package/dist/colors/crimson.js +126 -109
  14. package/dist/colors/cyan.d.ts +21 -109
  15. package/dist/colors/cyan.js +126 -109
  16. package/dist/colors/gold.d.ts +21 -109
  17. package/dist/colors/gold.js +126 -109
  18. package/dist/colors/grass.d.ts +21 -109
  19. package/dist/colors/grass.js +126 -109
  20. package/dist/colors/gray.d.ts +21 -109
  21. package/dist/colors/gray.js +126 -109
  22. package/dist/colors/green.d.ts +21 -109
  23. package/dist/colors/green.js +126 -109
  24. package/dist/colors/indigo.d.ts +21 -109
  25. package/dist/colors/indigo.js +126 -109
  26. package/dist/colors/iris.d.ts +21 -109
  27. package/dist/colors/iris.js +126 -109
  28. package/dist/colors/jade.d.ts +21 -109
  29. package/dist/colors/jade.js +126 -109
  30. package/dist/colors/lime.d.ts +21 -109
  31. package/dist/colors/lime.js +126 -109
  32. package/dist/colors/mauve.d.ts +21 -109
  33. package/dist/colors/mauve.js +126 -109
  34. package/dist/colors/mint.d.ts +21 -109
  35. package/dist/colors/mint.js +126 -109
  36. package/dist/colors/olive.d.ts +21 -109
  37. package/dist/colors/olive.js +126 -109
  38. package/dist/colors/orange.d.ts +21 -109
  39. package/dist/colors/orange.js +126 -109
  40. package/dist/colors/pink.d.ts +21 -109
  41. package/dist/colors/pink.js +126 -109
  42. package/dist/colors/plum.d.ts +21 -109
  43. package/dist/colors/plum.js +126 -109
  44. package/dist/colors/purple.d.ts +21 -109
  45. package/dist/colors/purple.js +126 -109
  46. package/dist/colors/red.d.ts +21 -109
  47. package/dist/colors/red.js +126 -109
  48. package/dist/colors/ruby.d.ts +21 -109
  49. package/dist/colors/ruby.js +126 -109
  50. package/dist/colors/sage.d.ts +21 -109
  51. package/dist/colors/sage.js +126 -109
  52. package/dist/colors/sand.d.ts +21 -109
  53. package/dist/colors/sand.js +126 -109
  54. package/dist/colors/sky.d.ts +21 -109
  55. package/dist/colors/sky.js +126 -109
  56. package/dist/colors/slate.d.ts +21 -109
  57. package/dist/colors/slate.js +126 -109
  58. package/dist/colors/teal.d.ts +21 -109
  59. package/dist/colors/teal.js +126 -109
  60. package/dist/colors/tomato.d.ts +21 -109
  61. package/dist/colors/tomato.js +126 -109
  62. package/dist/colors/violet.d.ts +21 -109
  63. package/dist/colors/violet.js +126 -109
  64. package/dist/colors/yellow.d.ts +21 -109
  65. package/dist/colors/yellow.js +126 -109
  66. package/dist/css.d.ts +3 -2
  67. package/dist/css.js +28 -9
  68. package/dist/index.d.ts +716 -3444
  69. package/dist/index.js +2 -3
  70. package/dist/types.d.ts +24 -23
  71. package/dist/utils.d.ts +9 -0
  72. package/dist/utils.js +44 -0
  73. package/package.json +4 -3
  74. package/dist/cli/commands/generate.d.ts +0 -64
  75. package/dist/cli/commands/generate.js +0 -87
  76. package/dist/cli/commands/list.d.ts +0 -48
  77. package/dist/cli/commands/list.js +0 -33
package/README.md CHANGED
@@ -27,30 +27,31 @@ import blue from '@diskette/palette/colors/blue'
27
27
 
28
28
  ### Color Structure
29
29
 
30
- Each color provides values for both color spaces and light/dark themes:
30
+ Each color provides separate 12-step arrays for solid and alpha scales, organized by theme and color space:
31
31
 
32
32
  ```ts
33
33
  import blue from '@diskette/palette/colors/blue'
34
34
 
35
- // sRGB values (hex)
36
- blue.srgb.light.blue9 // '#0090ff'
37
- blue.srgb.dark.blue9 // '#0090ff'
35
+ // sRGB solid values (hex) - 12-item array indexed 0-11
36
+ blue.light.srgb.solid[8] // '#0090ff' (step 9)
37
+ blue.dark.srgb.solid[8] // '#0090ff' (step 9)
38
38
 
39
- // Display P3 values
40
- blue.p3.light.blue9 // 'color(display-p3 0.247 0.556 0.969)'
41
- blue.p3.dark.blue9 // 'color(display-p3 0.247 0.556 0.969)'
39
+ // Display P3 solid values
40
+ blue.light.p3.solid[8] // 'color(display-p3 0.247 0.556 0.969)'
41
+ blue.dark.p3.solid[8] // 'color(display-p3 0.247 0.556 0.969)'
42
42
 
43
- // Alpha variants
44
- blue.srgb.light.blueA9 // '#0090ff' (with alpha)
43
+ // Alpha variants - separate 12-item array indexed 0-11
44
+ blue.light.srgb.alpha[8] // alpha step 9
45
+ blue.light.p3.alpha[8] // alpha step 9 in P3
45
46
 
46
47
  // Surface (translucent overlay)
47
48
  blue.surface.srgb.light // '#f1f9ffcc'
48
- blue.surface.p3.dark // 'color(display-p3 0.0706 0.1255 0.2196 / 0.5)'
49
+ blue.surface.p3.dark // 'color(display-p3 0.0706 0.1255 0.2196 / 0.5)'
49
50
 
50
51
  // Semantic values
51
- blue.contrast // 'white'
52
- blue.indicator // 'blue9'
53
- blue.track // 'blue9'
52
+ blue.contrast // 'white'
53
+ blue.indicator // 9 (step number)
54
+ blue.track // 9 (step number)
54
55
  ```
55
56
 
56
57
  ### Generating CSS
@@ -61,16 +62,16 @@ Use the `css` utility to generate CSS custom properties:
61
62
  import { css } from '@diskette/palette'
62
63
  import blue from '@diskette/palette/colors/blue'
63
64
 
64
- // Generate scale variables for light theme
65
- const blue = css.scale('light', blue)
66
- // Output: :root, .light, .light-theme { --blue-1: #fbfdff; ... }
65
+ // Generate CSS variables for light theme
66
+ css.palette(blue)
67
+ // Output: :root { --blue-contrast: white; ... }
68
+ // :root, .light, .light-theme { --blue-1: #fbfdff; ... }
67
69
 
68
- // Generate alpha variants
69
- css.scale('lightAlpha', blue)
70
+ // Include dark theme
71
+ css.palette(blue, { schemes: ['light', 'dark'] })
70
72
 
71
- // Generate semantic tokens
72
- css.semantic('blue', blue)
73
- // Output: :root { --blue-contrast: white; } ...
73
+ // Include alpha scale variables (--blue-a1, etc.)
74
+ css.palette(blue, { schemes: ['light'], alpha: true })
74
75
  ```
75
76
 
76
77
  ### Alpha Colors
@@ -81,7 +82,47 @@ For transparency overlays:
81
82
  import { blackAlpha, whiteAlpha } from '@diskette/palette/colors'
82
83
 
83
84
  blackAlpha.srgb.blackA5 // 'rgba(0, 0, 0, 0.3)'
84
- whiteAlpha.p3.whiteA5 // 'color(display-p3 1 1 1 / 0.3)'
85
+ whiteAlpha.p3.whiteA5 // 'color(display-p3 1 1 1 / 0.3)'
86
+ ```
87
+
88
+ ## CLI
89
+
90
+ The package includes a CLI for generating CSS files.
91
+
92
+ ### `palette generate`
93
+
94
+ Generate CSS files for color palettes.
95
+
96
+ ```bash
97
+ palette generate blue,red,slate -a -o ./styles
98
+ ```
99
+
100
+ ```
101
+ styles/
102
+ ├── index.css # Imports + Tailwind v4 @theme mappings
103
+ ├── accents.css # [data-accent-color] selectors (-a flag)
104
+ ├── blue.css # Light theme: --blue-1 through --blue-12, --blue-a1 through --blue-a12
105
+ ├── blue-dark.css # Dark theme variants
106
+ ├── red.css
107
+ ├── red-dark.css
108
+ ├── slate.css
109
+ ├── slate-dark.css
110
+ ├── black-alpha.css # --black-a1 through --black-a12
111
+ └── white-alpha.css # --white-a1 through --white-a12
112
+ ```
113
+
114
+ **Options:**
115
+ - `-o, --output <dir>` - Output directory (required)
116
+ - `-a, --accents` - Generate `accents.css` with `[data-accent-color]` and `[data-gray-color]` selectors
117
+
118
+ ### `palette list`
119
+
120
+ List available colors.
121
+
122
+ ```bash
123
+ palette list # List all colors
124
+ palette list --accent # List only accent colors
125
+ palette list --gray # List only gray colors
85
126
  ```
86
127
 
87
128
  ## Available Colors
@@ -117,18 +158,27 @@ Each color provides a 12-step scale following Radix Colors conventions:
117
158
 
118
159
  ## API Reference
119
160
 
120
- ### `css.scale(scheme, config)`
161
+ ### `css.palette(config, options?)`
121
162
 
122
- Generates CSS custom properties for a color scale.
163
+ Generates CSS custom properties for a color's scale and semantic tokens.
123
164
 
124
165
  ```ts
125
- css.scale(scheme: 'light' | 'lightAlpha' | 'dark' | 'darkAlpha', config: ColorConfig): string
166
+ css.palette(config: PaletteColor, options?: {
167
+ schemes?: ('light' | 'dark')[] // Defaults to ['light']
168
+ alpha?: boolean // Include alpha scale (--color-a1, etc.). Defaults to false
169
+ }): string
126
170
  ```
127
171
 
128
172
  <details>
129
173
  <summary>Example output</summary>
130
174
 
131
175
  ```css
176
+ :root {
177
+ --amber-contrast: #21201c;
178
+ --amber-indicator: var(--amber-9);
179
+ --amber-track: var(--amber-9);
180
+ }
181
+
132
182
  :root,
133
183
  .light,
134
184
  .light-theme {
@@ -152,17 +202,7 @@ css.scale(scheme: 'light' | 'lightAlpha' | 'dark' | 'darkAlpha', config: ColorCo
152
202
  .light,
153
203
  .light-theme {
154
204
  --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);
205
+ /* ... */
166
206
  }
167
207
  }
168
208
  }
@@ -180,49 +220,29 @@ Generates CSS custom properties for alpha color scales (blackAlpha, whiteAlpha).
180
220
  css.alpha(config: AlphaConfig): string
181
221
  ```
182
222
 
183
- ### `css.semantic(name, config)`
223
+ ### `css.accents(colorNames)`
184
224
 
185
- Generates semantic CSS custom properties for a color.
225
+ Generates CSS for `[data-accent-color]` attribute selectors, mapping accent variables to the specified color.
186
226
 
187
227
  ```ts
188
- css.semantic(name: string, config: ColorConfig): string
228
+ css.accents(colorNames: string[]): string
189
229
  ```
190
230
 
191
- <details>
192
- <summary>Example output</summary>
193
-
194
- ```css
195
- :root {
196
- --amber-contrast: #21201c;
197
- }
231
+ ### `css.grays(names, className)`
198
232
 
199
- :root,
200
- .light,
201
- .light-theme {
202
- --amber-surface: #fefae4cc;
203
- --amber-indicator: var(--amber-9);
204
- --amber-track: var(--amber-9);
205
- @supports (color: color(display-p3 1 1 1)) {
206
- @media (color-gamut: p3) {
207
- --amber-surface: color(display-p3 0.9922 0.9843 0.902 / 0.8);
208
- }
209
- }
210
- }
233
+ Generates CSS for `[data-gray-color]` attribute selectors nested under a class.
211
234
 
212
- .dark,
213
- .dark-theme {
214
- --amber-surface: #271f1380;
215
- --amber-indicator: var(--amber-9);
216
- --amber-track: var(--amber-9);
217
- @supports (color: color(display-p3 1 1 1)) {
218
- @media (color-gamut: p3) {
219
- --amber-surface: color(display-p3 0.1412 0.1176 0.0784 / 0.5);
220
- }
221
- }
222
- }
235
+ ```ts
236
+ css.grays(names: readonly string[], className: string): string
223
237
  ```
224
238
 
225
- </details>
239
+ ### `css.tailwind(colorNames)`
240
+
241
+ Generates Tailwind v4 `@theme inline` CSS that maps palette variables to Tailwind color utilities.
242
+
243
+ ```ts
244
+ css.tailwind(colorNames: string[]): string
245
+ ```
226
246
 
227
247
  ## Credits
228
248
 
package/dist/cli/cli.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export declare function writeIfNotExists(path: string, data: string | NodeJS.ArrayBufferView): boolean;
package/dist/cli/cli.js CHANGED
@@ -1,11 +1,61 @@
1
- import { cli } from 'cleye';
2
- import { generate } from "./commands/generate.js";
3
- import { list } from "./commands/list.js";
4
- const arg = cli({
5
- name: 'palette',
6
- // version: pkg.version,
7
- commands: [generate, list],
1
+ import { defineCommand, runMain } from 'citty';
2
+ import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
3
+ import { dirname, relative, resolve } from 'node:path';
4
+ import * as palette from "../colors/index.js";
5
+ import { css } from "../css.js";
6
+ import { accentColors, grayColors } from "../types.js";
7
+ import { getPackageJson } from "../utils.js";
8
+ const alphaColors = ['blackAlpha', 'whiteAlpha'];
9
+ // Combined list of all colors (deduplicated since 'gray' appears in both)
10
+ const allColors = [
11
+ ...new Set([...accentColors, ...grayColors]),
12
+ ...alphaColors,
13
+ ];
14
+ const { pkg, packageJsonPath } = getPackageJson(import.meta.url) ?? {};
15
+ const main = defineCommand({
16
+ meta: {
17
+ name: 'palette',
18
+ version: pkg?.version,
19
+ description: pkg?.description ?? '',
20
+ },
21
+ args: {
22
+ colors: {
23
+ type: 'positional',
24
+ description: 'Colors',
25
+ required: true,
26
+ },
27
+ output: {
28
+ type: 'string',
29
+ alias: 'o',
30
+ description: 'Output directory',
31
+ },
32
+ },
33
+ run({ args }) {
34
+ const selected = args._.filter((c) => allColors.includes(c));
35
+ const outputPath = resolve(process.cwd(), args.output);
36
+ mkdirSync(outputPath, { recursive: true });
37
+ for (const name of selected) {
38
+ if (alphaColors.includes(name)) {
39
+ const alphaName = name;
40
+ const config = palette[alphaName];
41
+ const fileName = alphaName === 'blackAlpha' ? 'black-alpha' : 'white-alpha';
42
+ writeIfNotExists(`${outputPath}/${fileName}.css`, css.alpha(config));
43
+ }
44
+ else {
45
+ const color = palette[name];
46
+ writeIfNotExists(`${outputPath}/${name}.css`, css.palette(color, { schemes: ['light'], alpha: true }));
47
+ writeIfNotExists(`${outputPath}/${name}-dark.css`, css.palette(color, { schemes: ['dark'], alpha: true }));
48
+ }
49
+ }
50
+ const path = relative(dirname(packageJsonPath), resolve(outputPath));
51
+ console.log(`\nCSS saved to ${outputPath}`);
52
+ },
8
53
  });
9
- if (!arg.command) {
10
- arg.showHelp();
54
+ runMain(main);
55
+ export function writeIfNotExists(path, data) {
56
+ if (existsSync(path)) {
57
+ return false;
58
+ }
59
+ writeFileSync(path, data);
60
+ return true;
11
61
  }
@@ -1,125 +1,37 @@
1
1
  declare const _default: {
2
- srgb: {
2
+ name: "amber";
3
+ indicator: number;
4
+ contrast: string;
5
+ track: number;
6
+ surface: {
3
7
  light: {
4
- amber1: string;
5
- amber2: string;
6
- amber3: string;
7
- amber4: string;
8
- amber5: string;
9
- amber6: string;
10
- amber7: string;
11
- amber8: string;
12
- amber9: string;
13
- amber10: string;
14
- amber11: string;
15
- amber12: string;
16
- amberA1: string;
17
- amberA2: string;
18
- amberA3: string;
19
- amberA4: string;
20
- amberA5: string;
21
- amberA6: string;
22
- amberA7: string;
23
- amberA8: string;
24
- amberA9: string;
25
- amberA10: string;
26
- amberA11: string;
27
- amberA12: string;
8
+ srgb: string;
9
+ p3: string;
28
10
  };
29
11
  dark: {
30
- amber1: string;
31
- amber2: string;
32
- amber3: string;
33
- amber4: string;
34
- amber5: string;
35
- amber6: string;
36
- amber7: string;
37
- amber8: string;
38
- amber9: string;
39
- amber10: string;
40
- amber11: string;
41
- amber12: string;
42
- amberA1: string;
43
- amberA2: string;
44
- amberA3: string;
45
- amberA4: string;
46
- amberA5: string;
47
- amberA6: string;
48
- amberA7: string;
49
- amberA8: string;
50
- amberA9: string;
51
- amberA10: string;
52
- amberA11: string;
53
- amberA12: string;
12
+ srgb: string;
13
+ p3: string;
54
14
  };
55
15
  };
56
- p3: {
57
- light: {
58
- amber1: string;
59
- amber2: string;
60
- amber3: string;
61
- amber4: string;
62
- amber5: string;
63
- amber6: string;
64
- amber7: string;
65
- amber8: string;
66
- amber9: string;
67
- amber10: string;
68
- amber11: string;
69
- amber12: string;
70
- amberA1: string;
71
- amberA2: string;
72
- amberA3: string;
73
- amberA4: string;
74
- amberA5: string;
75
- amberA6: string;
76
- amberA7: string;
77
- amberA8: string;
78
- amberA9: string;
79
- amberA10: string;
80
- amberA11: string;
81
- amberA12: string;
16
+ light: {
17
+ srgb: {
18
+ solid: [string, string, string, string, string, string, string, string, string, string, string, string];
19
+ alpha: [string, string, string, string, string, string, string, string, string, string, string, string];
82
20
  };
83
- dark: {
84
- amber1: string;
85
- amber2: string;
86
- amber3: string;
87
- amber4: string;
88
- amber5: string;
89
- amber6: string;
90
- amber7: string;
91
- amber8: string;
92
- amber9: string;
93
- amber10: string;
94
- amber11: string;
95
- amber12: string;
96
- amberA1: string;
97
- amberA2: string;
98
- amberA3: string;
99
- amberA4: string;
100
- amberA5: string;
101
- amberA6: string;
102
- amberA7: string;
103
- amberA8: string;
104
- amberA9: string;
105
- amberA10: string;
106
- amberA11: string;
107
- amberA12: string;
21
+ p3: {
22
+ solid: [string, string, string, string, string, string, string, string, string, string, string, string];
23
+ alpha: [string, string, string, string, string, string, string, string, string, string, string, string];
108
24
  };
109
25
  };
110
- contrast: string;
111
- indicator: string;
112
- track: string;
113
- surface: {
26
+ dark: {
114
27
  srgb: {
115
- light: string;
116
- dark: string;
28
+ solid: [string, string, string, string, string, string, string, string, string, string, string, string];
29
+ alpha: [string, string, string, string, string, string, string, string, string, string, string, string];
117
30
  };
118
31
  p3: {
119
- light: string;
120
- dark: string;
32
+ solid: [string, string, string, string, string, string, string, string, string, string, string, string];
33
+ alpha: [string, string, string, string, string, string, string, string, string, string, string, string];
121
34
  };
122
35
  };
123
- name: "amber";
124
36
  };
125
37
  export default _default;