@rafters/shared 0.4.3 → 0.4.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rafters/shared",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "description": "Shared W3C DTCG schemas, base types, and utilities for Rafters design system",
5
5
  "homepage": "https://rafters.studio",
6
6
  "license": "MIT",
package/src/types.ts CHANGED
@@ -70,16 +70,32 @@ export const DTCGTokenBaseSchema = z.object({
70
70
  export type DTCGTokenBase = z.infer<typeof DTCGTokenBaseSchema>;
71
71
 
72
72
  /**
73
- * W3C DTCG Color Value (OKLCH format)
73
+ * W3C DTCG Color Value (Design Tokens Color Module 2025.10, section 4.1)
74
+ * https://www.designtokens.org/TR/2025.10/color/
74
75
  */
75
76
  export const DTCGColorValueSchema = z.object({
76
- colorSpace: z.literal('oklch'),
77
- channels: z.tuple([
78
- z.number().min(0).max(1), // Lightness
79
- z.number().min(0), // Chroma
80
- z.number().min(0).max(360), // Hue
77
+ colorSpace: z.enum([
78
+ 'srgb',
79
+ 'srgb-linear',
80
+ 'hsl',
81
+ 'hwb',
82
+ 'lab',
83
+ 'lch',
84
+ 'oklab',
85
+ 'oklch',
86
+ 'display-p3',
87
+ 'a98-rgb',
88
+ 'prophoto-rgb',
89
+ 'rec2020',
90
+ 'xyz-d65',
91
+ 'xyz-d50',
81
92
  ]),
82
- alpha: z.number().min(0).max(1).optional().default(1),
93
+ components: z.array(z.union([z.number(), z.literal('none')])),
94
+ alpha: z.number().min(0).max(1).optional(),
95
+ hex: z
96
+ .string()
97
+ .regex(/^#[0-9a-fA-F]{6}$/)
98
+ .optional(),
83
99
  });
84
100
 
85
101
  export type DTCGColorValue = z.infer<typeof DTCGColorValueSchema>;
@@ -126,26 +142,27 @@ export const DTCGFileSchema = z.record(z.string(), z.union([DTCGTokenBaseSchema,
126
142
  export type DTCGFile = z.infer<typeof DTCGFileSchema>;
127
143
 
128
144
  /**
129
- * Helper: Convert OKLCH to DTCG Color Value
145
+ * Helper: Convert OKLCH to DTCG Color Value.
146
+ * `alpha` is present only when it is below 1 (Color Module 2025.10 defaults it to 1).
130
147
  */
131
148
  export function oklchToDTCG(oklch: OKLCH): DTCGColorValue {
132
- return {
133
- colorSpace: 'oklch',
134
- channels: [oklch.l, oklch.c, oklch.h],
135
- alpha: oklch.alpha ?? 1,
136
- };
149
+ const value: DTCGColorValue = { colorSpace: 'oklch', components: [oklch.l, oklch.c, oklch.h] };
150
+ if (oklch.alpha !== undefined && oklch.alpha < 1) value.alpha = oklch.alpha;
151
+ return value;
137
152
  }
138
153
 
139
154
  /**
140
- * Helper: Convert DTCG Color Value to OKLCH
155
+ * Helper: Convert an oklch DTCG Color Value to OKLCH. A `none` component reads as 0.
141
156
  */
142
157
  export function dtcgToOKLCH(dtcg: DTCGColorValue): OKLCH {
143
- return {
144
- l: dtcg.channels[0],
145
- c: dtcg.channels[1],
146
- h: dtcg.channels[2],
147
- alpha: dtcg.alpha ?? 1,
158
+ if (dtcg.colorSpace !== 'oklch') {
159
+ throw new Error(`dtcgToOKLCH: colorSpace "${dtcg.colorSpace}" is not oklch`);
160
+ }
161
+ const component = (i: number): number => {
162
+ const c = dtcg.components[i];
163
+ return typeof c === 'number' ? c : 0;
148
164
  };
165
+ return { l: component(0), c: component(1), h: component(2), alpha: dtcg.alpha ?? 1 };
149
166
  }
150
167
 
151
168
  /**
@@ -371,6 +388,25 @@ export type PerceptualWeight = z.infer<typeof PerceptualWeightSchema>;
371
388
  export const SEMANTIC_STATUS_ROLES = ['destructive', 'success', 'warning', 'info'] as const;
372
389
  export type SemanticStatusRole = (typeof SEMANTIC_STATUS_ROLES)[number];
373
390
 
391
+ // Family roles: the semantic tokens a designer assigns a palette to. Every
392
+ // other semantic colour belongs to one of these (its owner), and the CSS
393
+ // exporter emits one 50-950 scale per role so a role change moves everything
394
+ // it owns.
395
+ export const SEMANTIC_FAMILY_ROLES = [
396
+ 'primary',
397
+ 'secondary',
398
+ 'tertiary',
399
+ 'accent',
400
+ 'highlight',
401
+ 'neutral',
402
+ 'muted',
403
+ 'success',
404
+ 'warning',
405
+ 'destructive',
406
+ 'info',
407
+ ] as const;
408
+ export type SemanticFamilyRole = (typeof SEMANTIC_FAMILY_ROLES)[number];
409
+
374
410
  // Semantic Color Suggestions Schema.
375
411
  // 'danger' is a deprecated mirror of 'destructive', kept while apps/api (which
376
412
  // asserts .danger) migrates to platform. Inputs with only the legacy key parse
@@ -416,6 +452,18 @@ export const ColorValueSchema = z.object({
416
452
 
417
453
  // Unique token ID for quick color lookups (e.g., "color-0.500-0.120-240.0")
418
454
  tokenId: z.string().optional(),
455
+
456
+ // The gamut each scale step sits in, index-aligned with `scale`. Generated
457
+ // steps are 'srgb' or 'p3'; only an imported seed pinned as typed can be 'out'.
458
+ gamut: z.array(z.enum(['srgb', 'p3', 'out'])).optional(),
459
+ // Present when the family was built from a different seed than requested
460
+ seedAdjusted: z
461
+ .object({
462
+ from: OKLCHSchema,
463
+ to: OKLCHSchema,
464
+ reason: z.enum(['lightness-bounds', 'gamut']),
465
+ })
466
+ .optional(),
419
467
  });
420
468
 
421
469
  export type ColorValue = z.infer<typeof ColorValueSchema>;
package/src/version.ts CHANGED
@@ -4,4 +4,4 @@
4
4
  * Written by packages/cli/scripts/sync-version.ts from the CLI's own
5
5
  * package.json version at build time -- do not edit by hand.
6
6
  */
7
- export const RAFTERS_VERSION = '0.4.3';
7
+ export const RAFTERS_VERSION = '0.4.5';