@design-token-kit/core 0.3.0 → 0.3.2

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 (3) hide show
  1. package/README.md +161 -32
  2. package/lib/index.js +1 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,13 +1,25 @@
1
1
  # @design-token-kit/core
2
2
 
3
- Core library for Design Token Kit.
4
-
5
- It provides:
6
-
7
- - design token validation
8
- - DTCG JSON and HRDT YAML parsing
9
- - conversion of token documents to CSS
10
- - HTML showcase generation
3
+ The core package of Design Token Kit provides the runtime foundation
4
+ for working with [DTCG 2025.10 design tokens][dtcg]. It defines the
5
+ typed token model, performs schema and semantic validation, converts
6
+ tokens into CSS custom properties, and renders static HTML showcases.
7
+
8
+ ## Features
9
+
10
+ * **DTCG 2025.10 validation** - schema validation for DTCG JSON token
11
+ documents
12
+ * **Semantic checks** - unresolved references, circular references,
13
+ group references, type mismatches, and deprecated token usage
14
+ * **HRDT YAML support** - a compact, human-readable alternative to
15
+ DTCG JSON
16
+ * **Token format conversion** - read and write DTCG JSON and HRDT YAML
17
+ * **CSS generation** - base and theme token sets rendered as CSS
18
+ custom properties
19
+ * **Static showcase** - HTML showcase generation from token sources or
20
+ existing CSS
21
+ * **Source abstraction** - local files, stdin, URLs, and raw token
22
+ content strings
11
23
 
12
24
  Node.js 18 or newer is required.
13
25
 
@@ -17,41 +29,158 @@ Node.js 18 or newer is required.
17
29
  npm install @design-token-kit/core
18
30
  ```
19
31
 
20
- ## What It Does
32
+ ## Quick Start
33
+
34
+ ```ts
35
+ import {
36
+ DtcgListLoader,
37
+ DtcgTokenValidator,
38
+ DtcgTokenCssConverter,
39
+ createTokenHtmlShowcase,
40
+ } from "@design-token-kit/core";
41
+
42
+ const sources = ["./tokens.json", "./tokens.dark.yaml"];
43
+
44
+ const issues = await new DtcgTokenValidator().validate(sources);
45
+ if (issues.some((issue) => issue.severity === "error")) {
46
+ console.error(issues);
47
+ process.exit(1);
48
+ }
49
+
50
+ const list = await new DtcgListLoader().load(sources);
51
+ const css = new DtcgTokenCssConverter().convertList(list);
52
+ const html = await createTokenHtmlShowcase().showcase(sources);
53
+
54
+ console.log(css);
55
+ console.log(html.slice(0, 120));
56
+ ```
57
+
58
+ ## Input Formats
59
+
60
+ ### DTCG JSON
61
+
62
+ Use DTCG JSON token documents as the canonical source format for
63
+ validation, conversion, and showcase generation.
64
+
65
+ ### HRDT YAML
66
+
67
+ Use HRDT YAML for a more compact, human-readable authoring format. HRDT
68
+ documents are parsed into the same internal `Dtcg` model as DTCG JSON.
69
+
70
+ ### Base and theme sources
71
+
72
+ When multiple token sources are provided, the first source is treated
73
+ as the base token set and the remaining sources are treated as theme
74
+ overrides.
75
+
76
+ ### CSS input for showcase
77
+
78
+ For showcase generation, a single CSS source can be rendered directly
79
+ without going through token validation.
80
+
81
+ ## Output Formats
82
+
83
+ ### CSS custom properties
84
+
85
+ Generate token sets as CSS variables with a `:root` block for base
86
+ tokens and `:root[data-theme="<theme>"]` blocks for theme overrides.
21
87
 
22
- - validates DTCG token documents against schema and semantic rules
23
- - reads DTCG JSON into the internal `Dtcg` model
24
- - reads HRDT YAML into the same internal `Dtcg` model
25
- - writes DTCG JSON and HRDT YAML
26
- - converts token documents to CSS custom properties
27
- - builds an HTML showcase page from token files or CSS
88
+ ### HTML showcase
28
89
 
29
- ## Main Exports
90
+ Render a static HTML preview from DTCG JSON, HRDT YAML, or existing
91
+ CSS custom properties.
30
92
 
31
- Use these entry points for common tasks:
93
+ ### Serialized token documents
32
94
 
33
- - `DtcgTokenValidator` for validating token files
34
- - `DtcgJsonReader` and `HrdtTokenReader` for reading token documents
35
- - `DtcgJsonWriter` and `HrdtTokenWriter` for writing token documents
36
- - `DtcgTokenCssConverter` or `createTokenCssConverter()` for CSS conversion
37
- - `TokenHtmlShowcaseBuilder` or `createTokenHtmlShowcase()` for HTML showcase generation
38
- - `DtcgSchemaValidator` for schema-only validation
95
+ Convert token documents between DTCG JSON and HRDT YAML, or write a
96
+ parsed document back to either source format.
39
97
 
40
- ## Basic Usage
98
+ ## Main APIs
99
+
100
+ * `DtcgTokenValidator` - validate DTCG JSON and HRDT YAML token sources
101
+ * `DtcgListLoader` - load base and theme sources into a `DtcgList`
102
+ * `DtcgJsonReader` / `HrdtTokenReader` - parse supported token formats
103
+ * `DtcgJsonWriter` / `HrdtTokenWriter` - export token documents
104
+ * `DtcgTokenCssConverter` - generate CSS custom properties from tokens
105
+ * `createTokenHtmlShowcase()` - generate an HTML preview from token
106
+ sources or CSS
107
+
108
+ ## Validation
109
+
110
+ Use `DtcgTokenValidator` when you want the full validation pass:
111
+
112
+ - DTCG schema checks
113
+ - HRDT schema checks
114
+ - semantic checks on the resolved token graph
115
+
116
+ ```ts
117
+ import { DtcgTokenValidator } from "@design-token-kit/core";
118
+
119
+ const issues = await new DtcgTokenValidator().validate([
120
+ "./tokens.json",
121
+ "./tokens.dark.json",
122
+ ]);
123
+
124
+ for (const issue of issues) {
125
+ console.log(
126
+ issue.severity,
127
+ issue.sourcePath,
128
+ issue.tokenPath,
129
+ issue.message,
130
+ );
131
+ }
132
+ ```
133
+
134
+ Use `DtcgSchemaValidator` when you only need DTCG schema validation
135
+ without semantic checks.
136
+
137
+ ## Document Conversion
138
+
139
+ Use readers and writers to convert token documents between DTCG JSON
140
+ and HRDT YAML.
41
141
 
42
142
  ```ts
43
143
  import {
44
- DtcgTokenValidator,
45
144
  DtcgJsonReader,
46
- DtcgTokenCssConverter,
145
+ HrdtTokenWriter,
47
146
  } from "@design-token-kit/core";
48
147
 
49
- const validator = new DtcgTokenValidator();
50
- const issues = await validator.validate(["./tokens.json"]);
148
+ const doc = new DtcgJsonReader().parse(jsonString);
149
+ const yaml = new HrdtTokenWriter().write(doc);
150
+ ```
151
+
152
+ ## CSS Conversion
51
153
 
52
- const reader = new DtcgJsonReader();
53
- const doc = reader.parse(`{}`);
154
+ `DtcgTokenCssConverter` emits:
54
155
 
55
- const css = new DtcgTokenCssConverter().convertDocument(doc);
56
- console.log(css);
156
+ - base tokens under `:root`
157
+ - theme overrides under `:root[data-theme="<theme>"]`
158
+ - aliases as `var(--token-name)`
159
+
160
+ ```ts
161
+ import { DtcgTokenCssConverter } from "@design-token-kit/core";
162
+
163
+ const css = await new DtcgTokenCssConverter().convert([
164
+ "./tokens.json",
165
+ "./tokens.dark.json",
166
+ ]);
57
167
  ```
168
+
169
+ When you already have a parsed document or a prepared `DtcgList`, use
170
+ `convertDocument()` or `convertList()` instead of reloading sources.
171
+
172
+ ## HTML Showcase
173
+
174
+ Use `createTokenHtmlShowcase()` for the default pipeline or
175
+ `TokenHtmlShowcaseBuilder` when you want to inject your own validator,
176
+ converter, parser, or renderer.
177
+
178
+ ```ts
179
+ import { createTokenHtmlShowcase } from "@design-token-kit/core";
180
+
181
+ const html = await createTokenHtmlShowcase().showcase([
182
+ "./tokens.yaml",
183
+ ]);
184
+ ```
185
+
186
+ [dtcg]: https://www.designtokens.org/
package/lib/index.js CHANGED
@@ -164,8 +164,8 @@ var Source = class Source {
164
164
  constructor(input) {
165
165
  this.#input = input;
166
166
  if (input === "-") this.#type = SourceType.STDIN;
167
- else if (Source.#isUrl(input)) this.#type = SourceType.URL;
168
167
  else if (existsSync(input)) this.#type = SourceType.FILE;
168
+ else if (Source.#isUrl(input)) this.#type = SourceType.URL;
169
169
  else this.#type = SourceType.CONTENT;
170
170
  }
171
171
  static #isUrl(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@design-token-kit/core",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Core library for Design Token Kit: validate, convert, showcase.",
5
5
  "keywords": [
6
6
  "design-tokens",