@diskette/palette 0.9.0 → 0.9.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.
- package/README.md +176 -0
- package/package.json +13 -4
package/README.md
CHANGED
|
@@ -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/package.json
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diskette/palette",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.1",
|
|
5
5
|
"exports": {
|
|
6
|
-
".":
|
|
7
|
-
|
|
8
|
-
|
|
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"
|