@chayns-ui/tokens 0.5.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.
@@ -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;C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AK,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.5.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
  }