@chayns-ui/tokens 0.4.0 → 0.6.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/README.md CHANGED
@@ -1,3 +1,25 @@
1
1
  # @chayns-ui/tokens
2
2
 
3
- Resolved, generated chayns UI Baseline and Patch CSS. This package has no JavaScript runtime.
3
+ Resolved chayns UI Baseline and Patch CSS plus a framework-independent global theme API.
4
+
5
+ ```ts
6
+ import { applyTheme } from '@chayns-ui/tokens';
7
+ import '@chayns-ui/tokens/baseline.css';
8
+ import '@chayns-ui/tokens/patch.css';
9
+
10
+ applyTheme({
11
+ colorMode: 'dark',
12
+ density: 'm',
13
+ accessibilityMode: 'high-contrast',
14
+ });
15
+ ```
16
+
17
+ `applyTheme` adds the selected global classes to `document.documentElement`. Calls are partial:
18
+ omitted options retain their current setting. Supported values are:
19
+
20
+ * `colorMode`: `light` or `dark`
21
+ * `density`: `s`, `m`, or `l`
22
+ * `accessibilityMode`: `standard`, `high-contrast`, or `color-deficiency`
23
+
24
+ A freely configurable primary/accent color is intentionally not part of this API until its required
25
+ token derivation and contrast-calibration rules are specified.
package/dist/baseline.css CHANGED
@@ -61,6 +61,16 @@
61
61
  --fs-meta: calc(13 * var(--u));
62
62
  --fs-caption: calc(12 * var(--u));
63
63
  --fs-micro: calc(11 * var(--u));
64
+ --grey-000: #ffffff;
65
+ --grey-001: #f7f7f7;
66
+ --grey-002: #e5e5e5;
67
+ --grey-003: #bfbfbf;
68
+ --grey-004: #999999;
69
+ --grey-005: #7f7f7f;
70
+ --grey-006: #666666;
71
+ --grey-007: #3f3f3f;
72
+ --grey-008: #191919;
73
+ --grey-009: #000000;
64
74
  --page: #f4f6f6;
65
75
  --surface: #ffffff;
66
76
  --surface-2: #fbfcfc;
@@ -78,7 +88,15 @@
78
88
  --accent-active: #0a4e5b;
79
89
  --on-accent: #ffffff;
80
90
  --accent-rgb: 15, 109, 126;
91
+ --on-accent-rgb: 255, 255, 255;
92
+ --accent-100: #eef7f8;
93
+ --accent-200: #d3e7eb;
81
94
  --accent-300: #a8c3ca;
95
+ --accent-400: #629fac;
96
+ --accent-500: #3f93a1;
97
+ --accent-600: #278090;
98
+ --accent-700: #0d6271;
99
+ --accent-800: #0c5765;
82
100
  --tint: #eef7f8;
83
101
  --toggle-bg: #e9eded;
84
102
  --danger: #a31919;
@@ -103,6 +121,16 @@
103
121
  }
104
122
 
105
123
  .chayns-theme--dark {
124
+ --grey-000: #000000;
125
+ --grey-001: #070707;
126
+ --grey-002: #191919;
127
+ --grey-003: #3f3f3f;
128
+ --grey-004: #666666;
129
+ --grey-005: #7f7f7f;
130
+ --grey-006: #999999;
131
+ --grey-007: #bfbfbf;
132
+ --grey-008: #e5e5e5;
133
+ --grey-009: #ffffff;
106
134
  --page: #0e171b;
107
135
  --surface: #16242a;
108
136
  --surface-2: #101b20;
@@ -120,7 +148,15 @@
120
148
  --accent-active: #3eaec4;
121
149
  --on-accent: #0d161a;
122
150
  --accent-rgb: 85, 191, 212;
151
+ --on-accent-rgb: 14, 23, 27;
152
+ --accent-100: #e2f7fa;
153
+ --accent-200: #caeff3;
123
154
  --accent-300: #aee4ed;
155
+ --accent-400: #90d8e5;
156
+ --accent-500: #72cbdd;
157
+ --accent-600: #55bfd4;
158
+ --accent-700: #3eaec4;
159
+ --accent-800: #2f90a3;
124
160
  --tint: #1a3138;
125
161
  --toggle-bg: #22333a;
126
162
  --danger: #ffb3ae;
@@ -0,0 +1,17 @@
1
+ export declare const COLOR_MODES: readonly ["light", "dark"];
2
+ export declare const DENSITIES: readonly ["s", "m", "l"];
3
+ export declare const ACCESSIBILITY_MODES: readonly ["standard", "high-contrast", "color-deficiency"];
4
+ export type ColorMode = (typeof COLOR_MODES)[number];
5
+ export type Density = (typeof DENSITIES)[number];
6
+ export type AccessibilityMode = (typeof ACCESSIBILITY_MODES)[number];
7
+ export interface ApplyThemeOptions {
8
+ accessibilityMode?: AccessibilityMode;
9
+ colorMode?: ColorMode;
10
+ density?: Density;
11
+ }
12
+ /**
13
+ * Applies global chayns UI theme classes to the document root.
14
+ * Omitted options retain their current setting.
15
+ */
16
+ export declare function applyTheme(options: ApplyThemeOptions): void;
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,4BAA6B,CAAC;AACtD,eAAO,MAAM,SAAS,0BAA2B,CAAC;AAClD,eAAO,MAAM,mBAAmB,4DAA6D,CAAC;AAE9F,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AACrD,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AACjD,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AA6BD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAoC3D"}
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ //#region src/index.ts
2
+ var COLOR_MODES = ["light", "dark"];
3
+ var DENSITIES = [
4
+ "s",
5
+ "m",
6
+ "l"
7
+ ];
8
+ var ACCESSIBILITY_MODES = [
9
+ "standard",
10
+ "high-contrast",
11
+ "color-deficiency"
12
+ ];
13
+ var COLOR_MODE_CLASSES = COLOR_MODES.map((mode) => `chayns-theme--${mode}`);
14
+ var DENSITY_CLASSES = DENSITIES.map((density) => `chayns-density--${density}`);
15
+ var ACCESSIBILITY_CLASSES = ["chayns-contrast--high", "chayns-theme--color-deficiency"];
16
+ function assertSupportedOption(name, value, supportedValues) {
17
+ if (typeof value !== "string" || !supportedValues.some((supportedValue) => supportedValue === value)) throw new TypeError(`${name} must be one of: ${supportedValues.map((supportedValue) => `'${supportedValue}'`).join(", ")}.`);
18
+ }
19
+ function documentRoot() {
20
+ if (typeof document === "undefined") throw new ReferenceError("applyTheme requires a browser document.");
21
+ return document.documentElement;
22
+ }
23
+ /**
24
+ * Applies global chayns UI theme classes to the document root.
25
+ * Omitted options retain their current setting.
26
+ */
27
+ function applyTheme(options) {
28
+ if (Object.hasOwn(options, "colorMode")) assertSupportedOption("colorMode", options.colorMode, COLOR_MODES);
29
+ if (Object.hasOwn(options, "density")) assertSupportedOption("density", options.density, DENSITIES);
30
+ if (Object.hasOwn(options, "accessibilityMode")) assertSupportedOption("accessibilityMode", options.accessibilityMode, ACCESSIBILITY_MODES);
31
+ const root = documentRoot();
32
+ if (Object.hasOwn(options, "colorMode")) {
33
+ root.classList.remove(...COLOR_MODE_CLASSES);
34
+ root.classList.add(`chayns-theme--${options.colorMode}`);
35
+ }
36
+ if (Object.hasOwn(options, "density")) {
37
+ root.classList.remove(...DENSITY_CLASSES);
38
+ root.classList.add(`chayns-density--${options.density}`);
39
+ }
40
+ if (Object.hasOwn(options, "accessibilityMode")) {
41
+ root.classList.remove(...ACCESSIBILITY_CLASSES);
42
+ if (options.accessibilityMode === "high-contrast") root.classList.add("chayns-contrast--high");
43
+ if (options.accessibilityMode === "color-deficiency") root.classList.add("chayns-theme--color-deficiency");
44
+ }
45
+ }
46
+ //#endregion
47
+ export { ACCESSIBILITY_MODES, COLOR_MODES, DENSITIES, applyTheme };
48
+
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export const COLOR_MODES = ['light', 'dark'] as const;\nexport const DENSITIES = ['s', 'm', 'l'] as const;\nexport const ACCESSIBILITY_MODES = ['standard', 'high-contrast', 'color-deficiency'] as const;\n\nexport type ColorMode = (typeof COLOR_MODES)[number];\nexport type Density = (typeof DENSITIES)[number];\nexport type AccessibilityMode = (typeof ACCESSIBILITY_MODES)[number];\n\nexport interface ApplyThemeOptions {\n accessibilityMode?: AccessibilityMode;\n colorMode?: ColorMode;\n density?: Density;\n}\n\nconst COLOR_MODE_CLASSES = COLOR_MODES.map((mode) => `chayns-theme--${mode}`);\nconst DENSITY_CLASSES = DENSITIES.map((density) => `chayns-density--${density}`);\nconst ACCESSIBILITY_CLASSES = ['chayns-contrast--high', 'chayns-theme--color-deficiency'] as const;\n\nfunction assertSupportedOption<Value extends string>(\n name: string,\n value: unknown,\n supportedValues: readonly Value[],\n): asserts value is Value {\n if (\n typeof value !== 'string' ||\n !supportedValues.some((supportedValue) => supportedValue === value)\n ) {\n throw new TypeError(\n `${name} must be one of: ${supportedValues.map((supportedValue) => `'${supportedValue}'`).join(', ')}.`,\n );\n }\n}\n\nfunction documentRoot(): HTMLElement {\n if (typeof document === 'undefined') {\n throw new ReferenceError('applyTheme requires a browser document.');\n }\n\n return document.documentElement;\n}\n\n/**\n * Applies global chayns UI theme classes to the document root.\n * Omitted options retain their current setting.\n */\nexport function applyTheme(options: ApplyThemeOptions): void {\n if (Object.hasOwn(options, 'colorMode')) {\n assertSupportedOption('colorMode', options.colorMode, COLOR_MODES);\n }\n\n if (Object.hasOwn(options, 'density')) {\n assertSupportedOption('density', options.density, DENSITIES);\n }\n\n if (Object.hasOwn(options, 'accessibilityMode')) {\n assertSupportedOption('accessibilityMode', options.accessibilityMode, ACCESSIBILITY_MODES);\n }\n\n const root = documentRoot();\n\n if (Object.hasOwn(options, 'colorMode')) {\n root.classList.remove(...COLOR_MODE_CLASSES);\n root.classList.add(`chayns-theme--${options.colorMode}`);\n }\n\n if (Object.hasOwn(options, 'density')) {\n root.classList.remove(...DENSITY_CLASSES);\n root.classList.add(`chayns-density--${options.density}`);\n }\n\n if (Object.hasOwn(options, 'accessibilityMode')) {\n root.classList.remove(...ACCESSIBILITY_CLASSES);\n\n if (options.accessibilityMode === 'high-contrast') {\n root.classList.add('chayns-contrast--high');\n }\n\n if (options.accessibilityMode === 'color-deficiency') {\n root.classList.add('chayns-theme--color-deficiency');\n }\n }\n}\n"],"mappings":";AAAA,IAAa,cAAc,CAAC,SAAS,MAAM;AAC3C,IAAa,YAAY;CAAC;CAAK;CAAK;AAAG;AACvC,IAAa,sBAAsB;CAAC;CAAY;CAAiB;AAAkB;AAYnF,IAAM,qBAAqB,YAAY,KAAK,SAAS,iBAAiB,MAAM;AAC5E,IAAM,kBAAkB,UAAU,KAAK,YAAY,mBAAmB,SAAS;AAC/E,IAAM,wBAAwB,CAAC,yBAAyB,gCAAgC;AAExF,SAAS,sBACP,MACA,OACA,iBACwB;CACxB,IACE,OAAO,UAAU,YACjB,CAAC,gBAAgB,MAAM,mBAAmB,mBAAmB,KAAK,GAElE,MAAM,IAAI,UACR,GAAG,KAAK,mBAAmB,gBAAgB,KAAK,mBAAmB,IAAI,eAAe,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,EACvG;AAEJ;AAEA,SAAS,eAA4B;CACnC,IAAI,OAAO,aAAa,aACtB,MAAM,IAAI,eAAe,yCAAyC;CAGpE,OAAO,SAAS;AAClB;;;;;AAMA,SAAgB,WAAW,SAAkC;CAC3D,IAAI,OAAO,OAAO,SAAS,WAAW,GACpC,sBAAsB,aAAa,QAAQ,WAAW,WAAW;CAGnE,IAAI,OAAO,OAAO,SAAS,SAAS,GAClC,sBAAsB,WAAW,QAAQ,SAAS,SAAS;CAG7D,IAAI,OAAO,OAAO,SAAS,mBAAmB,GAC5C,sBAAsB,qBAAqB,QAAQ,mBAAmB,mBAAmB;CAG3F,MAAM,OAAO,aAAa;CAE1B,IAAI,OAAO,OAAO,SAAS,WAAW,GAAG;EACvC,KAAK,UAAU,OAAO,GAAG,kBAAkB;EAC3C,KAAK,UAAU,IAAI,iBAAiB,QAAQ,WAAW;CACzD;CAEA,IAAI,OAAO,OAAO,SAAS,SAAS,GAAG;EACrC,KAAK,UAAU,OAAO,GAAG,eAAe;EACxC,KAAK,UAAU,IAAI,mBAAmB,QAAQ,SAAS;CACzD;CAEA,IAAI,OAAO,OAAO,SAAS,mBAAmB,GAAG;EAC/C,KAAK,UAAU,OAAO,GAAG,qBAAqB;EAE9C,IAAI,QAAQ,sBAAsB,iBAChC,KAAK,UAAU,IAAI,uBAAuB;EAG5C,IAAI,QAAQ,sBAAsB,oBAChC,KAAK,UAAU,IAAI,gCAAgC;CAEvD;AACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chayns-ui/tokens",
3
- "version": "0.4.0",
4
- "description": "Resolved CSS design tokens for chayns UI",
3
+ "version": "0.6.0",
4
+ "description": "Resolved CSS design tokens and global theme configuration for chayns UI",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "repository": {
@@ -19,6 +19,10 @@
19
19
  "README.md"
20
20
  ],
21
21
  "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js"
25
+ },
22
26
  "./baseline.css": "./dist/baseline.css",
23
27
  "./patch.css": "./dist/patch.css",
24
28
  "./package.json": "./package.json"
@@ -30,8 +34,8 @@
30
34
  "access": "public"
31
35
  },
32
36
  "scripts": {
33
- "build": "node style-dictionary.config.mjs",
37
+ "build": "vite build && tsc -b tsconfig.build.json --force && node style-dictionary.config.mjs",
34
38
  "clean": "node ../../tooling/clean-package.mjs tokens",
35
- "test": "vitest run"
39
+ "test": "vitest run --environment jsdom"
36
40
  }
37
41
  }
@@ -322,6 +322,56 @@
322
322
  }
323
323
  },
324
324
  "color": {
325
+ "grey-000": {
326
+ "$type": "color",
327
+ "$value": "#ffffff",
328
+ "$extensions": { "chayns": { "cssName": "--grey-000", "dark": "#000000" } }
329
+ },
330
+ "grey-001": {
331
+ "$type": "color",
332
+ "$value": "#f7f7f7",
333
+ "$extensions": { "chayns": { "cssName": "--grey-001", "dark": "#070707" } }
334
+ },
335
+ "grey-002": {
336
+ "$type": "color",
337
+ "$value": "#e5e5e5",
338
+ "$extensions": { "chayns": { "cssName": "--grey-002", "dark": "#191919" } }
339
+ },
340
+ "grey-003": {
341
+ "$type": "color",
342
+ "$value": "#bfbfbf",
343
+ "$extensions": { "chayns": { "cssName": "--grey-003", "dark": "#3f3f3f" } }
344
+ },
345
+ "grey-004": {
346
+ "$type": "color",
347
+ "$value": "#999999",
348
+ "$extensions": { "chayns": { "cssName": "--grey-004", "dark": "#666666" } }
349
+ },
350
+ "grey-005": {
351
+ "$type": "color",
352
+ "$value": "#7f7f7f",
353
+ "$extensions": { "chayns": { "cssName": "--grey-005", "dark": "#7f7f7f" } }
354
+ },
355
+ "grey-006": {
356
+ "$type": "color",
357
+ "$value": "#666666",
358
+ "$extensions": { "chayns": { "cssName": "--grey-006", "dark": "#999999" } }
359
+ },
360
+ "grey-007": {
361
+ "$type": "color",
362
+ "$value": "#3f3f3f",
363
+ "$extensions": { "chayns": { "cssName": "--grey-007", "dark": "#bfbfbf" } }
364
+ },
365
+ "grey-008": {
366
+ "$type": "color",
367
+ "$value": "#191919",
368
+ "$extensions": { "chayns": { "cssName": "--grey-008", "dark": "#e5e5e5" } }
369
+ },
370
+ "grey-009": {
371
+ "$type": "color",
372
+ "$value": "#000000",
373
+ "$extensions": { "chayns": { "cssName": "--grey-009", "dark": "#ffffff" } }
374
+ },
325
375
  "page": {
326
376
  "$type": "color",
327
377
  "$value": "#f4f6f6",
@@ -407,11 +457,51 @@
407
457
  "$value": "15, 109, 126",
408
458
  "$extensions": { "chayns": { "cssName": "--accent-rgb", "dark": "85, 191, 212" } }
409
459
  },
460
+ "on-accent-rgb": {
461
+ "$type": "string",
462
+ "$value": "255, 255, 255",
463
+ "$extensions": { "chayns": { "cssName": "--on-accent-rgb", "dark": "14, 23, 27" } }
464
+ },
465
+ "accent-100": {
466
+ "$type": "color",
467
+ "$value": "#eef7f8",
468
+ "$extensions": { "chayns": { "cssName": "--accent-100", "dark": "#e2f7fa" } }
469
+ },
470
+ "accent-200": {
471
+ "$type": "color",
472
+ "$value": "#d3e7eb",
473
+ "$extensions": { "chayns": { "cssName": "--accent-200", "dark": "#caeff3" } }
474
+ },
410
475
  "accent-300": {
411
476
  "$type": "color",
412
477
  "$value": "#a8c3ca",
413
478
  "$extensions": { "chayns": { "cssName": "--accent-300", "dark": "#aee4ed" } }
414
479
  },
480
+ "accent-400": {
481
+ "$type": "color",
482
+ "$value": "#629fac",
483
+ "$extensions": { "chayns": { "cssName": "--accent-400", "dark": "#90d8e5" } }
484
+ },
485
+ "accent-500": {
486
+ "$type": "color",
487
+ "$value": "#3f93a1",
488
+ "$extensions": { "chayns": { "cssName": "--accent-500", "dark": "#72cbdd" } }
489
+ },
490
+ "accent-600": {
491
+ "$type": "color",
492
+ "$value": "#278090",
493
+ "$extensions": { "chayns": { "cssName": "--accent-600", "dark": "#55bfd4" } }
494
+ },
495
+ "accent-700": {
496
+ "$type": "color",
497
+ "$value": "#0d6271",
498
+ "$extensions": { "chayns": { "cssName": "--accent-700", "dark": "#3eaec4" } }
499
+ },
500
+ "accent-800": {
501
+ "$type": "color",
502
+ "$value": "#0c5765",
503
+ "$extensions": { "chayns": { "cssName": "--accent-800", "dark": "#2f90a3" } }
504
+ },
415
505
  "tint": {
416
506
  "$type": "color",
417
507
  "$value": "#eef7f8",