dispersa 0.4.3 → 1.0.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 +65 -30
- package/dist/android-CRDfSB3_.d.cts +126 -0
- package/dist/android-DANJjjPO.d.ts +126 -0
- package/dist/builders.cjs +206 -62
- package/dist/builders.cjs.map +1 -1
- package/dist/builders.d.cts +12 -11
- package/dist/builders.d.ts +12 -11
- package/dist/builders.js +206 -62
- package/dist/builders.js.map +1 -1
- package/dist/cli/cli.js +120 -7
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/config.d.ts +321 -0
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/index.js +119 -7
- package/dist/cli/index.js.map +1 -1
- package/dist/dispersa-BC1kDF5u.d.ts +118 -0
- package/dist/dispersa-DL3J_Pmz.d.cts +118 -0
- package/dist/errors-qT4sJgSA.d.cts +104 -0
- package/dist/errors-qT4sJgSA.d.ts +104 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +1 -83
- package/dist/errors.d.ts +1 -83
- package/dist/errors.js.map +1 -1
- package/dist/filters.cjs.map +1 -1
- package/dist/filters.d.cts +2 -2
- package/dist/filters.d.ts +2 -2
- package/dist/filters.js.map +1 -1
- package/dist/{index-CNT2Meyf.d.cts → index-Dajm5rvM.d.ts} +311 -132
- package/dist/{index-CqdaN3X0.d.ts → index-De6SjZYH.d.cts} +311 -132
- package/dist/index.cjs +799 -353
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -329
- package/dist/index.d.ts +8 -329
- package/dist/index.js +793 -353
- package/dist/index.js.map +1 -1
- package/dist/lint.cjs +1017 -0
- package/dist/lint.cjs.map +1 -0
- package/dist/lint.d.cts +463 -0
- package/dist/lint.d.ts +463 -0
- package/dist/lint.js +997 -0
- package/dist/lint.js.map +1 -0
- package/dist/preprocessors.d.cts +2 -2
- package/dist/preprocessors.d.ts +2 -2
- package/dist/renderers.cjs.map +1 -1
- package/dist/renderers.d.cts +7 -6
- package/dist/renderers.d.ts +7 -6
- package/dist/renderers.js.map +1 -1
- package/dist/transforms.d.cts +2 -2
- package/dist/transforms.d.ts +2 -2
- package/dist/{types-CZb19kiq.d.ts → types-8MLtztK3.d.ts} +56 -1
- package/dist/{types-CussyWwe.d.cts → types-BHBHRm0a.d.cts} +56 -1
- package/dist/{types-BAv39mum.d.cts → types-BltzwVYK.d.cts} +1 -1
- package/dist/{types-DWKq-eJj.d.cts → types-CAdUV-fa.d.cts} +1 -1
- package/dist/{types-CzHa7YkW.d.ts → types-DztXKlka.d.ts} +1 -1
- package/dist/{types-Bc0kA7De.d.ts → types-TQHV1MrY.d.cts} +19 -1
- package/dist/{types-Bc0kA7De.d.cts → types-TQHV1MrY.d.ts} +19 -1
- package/dist/{types-BzNcG-rI.d.ts → types-ebxDimRz.d.ts} +1 -1
- package/package.json +11 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,332 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { J as JsModuleRendererOptions, a as JsonRendererOptions, P as Preprocessor } from './types-CussyWwe.cjs';
|
|
1
|
+
export { L as LintOptions, b as build, a as buildOrThrow, c as buildPermutation, g as generateTypes, l as lint, d as resolveAllPermutations, r as resolveTokens } from './dispersa-DL3J_Pmz.cjs';
|
|
2
|
+
export { B as BuildConfig, b as BuildError, c as BuildOutput, d as BuildResult, C as CssRendererOptions, D as DispersaOptions, E as ErrorCode, F as FileFunction, e as FormatOptions, L as LifecycleHooks, M as MediaQueryFunction, j as ModifierInputs, O as OutputConfig, f as OutputTree, P as PermutationData, g as RenderContext, h as RenderMeta, i as RenderOutput, R as Renderer, k as ResolverDocument, S as SelectorFunction, V as ValidationMode, a as ValidationOptions, l as defineRenderer } from './index-De6SjZYH.cjs';
|
|
3
|
+
export { B as BorderToken, r as BorderValue, k as ColorComponent, j as ColorSpace, C as ColorToken, i as ColorValue, h as ColorValueObject, o as CubicBezierValue, D as DesignTokenValue, d as DimensionToken, l as DimensionValue, e as DurationToken, m as DurationValue, F as FontFamilyValue, n as FontWeightValue, w as GradientStop, G as GradientToken, v as GradientValue, R as ResolvedToken, a as ResolvedTokens, S as ShadowToken, p as ShadowValueObject, s as StrokeStyleValue, t as StrokeStyleValueObject, c as TokenType, T as TokenValue, b as TokenValueReference, g as TransitionToken, u as TransitionValue, f as TypographyToken, q as TypographyValue, E as isBorderToken, x as isColorToken, y as isDimensionToken, H as isDurationToken, J as isGradientToken, z as isShadowToken, I as isTransitionToken, A as isTypographyToken } from './types-TQHV1MrY.cjs';
|
|
4
|
+
export { T as Transform } from './types-BltzwVYK.cjs';
|
|
5
|
+
export { F as Filter } from './types-CAdUV-fa.cjs';
|
|
6
|
+
export { J as JsModuleRendererOptions, a as JsonRendererOptions, P as Preprocessor } from './types-BHBHRm0a.cjs';
|
|
8
7
|
export { AndroidBuilderConfig, CssBuilderConfig, IosBuilderConfig, JsBuilderConfig, JsonBuilderConfig, TailwindBuilderConfig, android, css, ios, js, json, tailwind } from './builders.cjs';
|
|
9
8
|
export { isOutputTree, outputTree } from './renderers.cjs';
|
|
10
|
-
export { BasePermutationError, CircularReferenceError, ConfigurationError, DispersaError, FileOperationError, ModifierError, TokenReferenceError, ValidationError } from './errors.cjs';
|
|
9
|
+
export { B as BasePermutationError, C as CircularReferenceError, a as ConfigurationError, D as DispersaError, F as FileOperationError, L as LintError, M as ModifierError, T as TokenReferenceError, V as ValidationError } from './errors-qT4sJgSA.cjs';
|
|
10
|
+
export { A as AndroidRendererOptions, I as IosRendererOptions, T as TailwindRendererOptions } from './android-CRDfSB3_.cjs';
|
|
11
11
|
import 'json-schema-to-ts';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @license
|
|
15
|
-
* Copyright (c) 2025 Dispersa Contributors
|
|
16
|
-
* SPDX-License-Identifier: MIT
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* DTCG design token processor with multi-format output support
|
|
21
|
-
*
|
|
22
|
-
* Dispersa processes DTCG-compliant design tokens through a configurable pipeline,
|
|
23
|
-
* resolves references and aliases, applies transforms and filters, and generates output
|
|
24
|
-
* in multiple formats (CSS, JSON, JavaScript).
|
|
25
|
-
*
|
|
26
|
-
* **Runtime Validation:**
|
|
27
|
-
* Dispersa validates all configuration inputs at runtime, including constructor options,
|
|
28
|
-
* build configs, output configs, and custom component registrations. This catches
|
|
29
|
-
* configuration errors early with helpful error messages.
|
|
30
|
-
*
|
|
31
|
-
* Features:
|
|
32
|
-
* - **Transforms**: Modify token values and names (e.g., convert colors, change case)
|
|
33
|
-
* - **Filters**: Select which tokens to include in output
|
|
34
|
-
* - **Preprocessors**: Transform raw token data before parsing
|
|
35
|
-
* - **Renderers**: Generate output in various formats
|
|
36
|
-
* - **Runtime validation**: JSON schema validation for all user inputs
|
|
37
|
-
*
|
|
38
|
-
* @example Basic usage with constructor defaults
|
|
39
|
-
* ```typescript
|
|
40
|
-
* const dispersa = new Dispersa({
|
|
41
|
-
* resolver: './tokens.resolver.json',
|
|
42
|
-
* buildPath: './output'
|
|
43
|
-
* })
|
|
44
|
-
*
|
|
45
|
-
* const result = await dispersa.build({
|
|
46
|
-
* outputs: [
|
|
47
|
-
* css({
|
|
48
|
-
* name: 'css',
|
|
49
|
-
* file: 'tokens.css',
|
|
50
|
-
* preset: 'bundle',
|
|
51
|
-
* selector: ':root',
|
|
52
|
-
* transforms: [nameKebabCase()]
|
|
53
|
-
* })
|
|
54
|
-
* ]
|
|
55
|
-
* })
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @example Mixed presets per output
|
|
59
|
-
* ```typescript
|
|
60
|
-
* import { css, json } from 'dispersa'
|
|
61
|
-
*
|
|
62
|
-
* const dispersa = new Dispersa({
|
|
63
|
-
* resolver: './tokens.resolver.json',
|
|
64
|
-
* buildPath: './output'
|
|
65
|
-
* })
|
|
66
|
-
*
|
|
67
|
-
* await dispersa.build({
|
|
68
|
-
* outputs: [
|
|
69
|
-
* css({
|
|
70
|
-
* name: 'css',
|
|
71
|
-
* file: 'tokens.css',
|
|
72
|
-
* preset: 'bundle',
|
|
73
|
-
* selector: ':root', // All themes in one CSS file
|
|
74
|
-
* transforms: [nameKebabCase()]
|
|
75
|
-
* }),
|
|
76
|
-
* json({
|
|
77
|
-
* name: 'json',
|
|
78
|
-
* file: 'tokens-{theme}.json', // Separate file per theme
|
|
79
|
-
* preset: 'standalone',
|
|
80
|
-
* structure: 'flat'
|
|
81
|
-
* })
|
|
82
|
-
* ]
|
|
83
|
-
* })
|
|
84
|
-
* ```
|
|
85
|
-
*
|
|
86
|
-
* @example Using filters and preprocessors
|
|
87
|
-
* ```typescript
|
|
88
|
-
* import { css } from 'dispersa'
|
|
89
|
-
* import { byType } from 'dispersa/filters'
|
|
90
|
-
* import { nameKebabCase } from 'dispersa/transforms'
|
|
91
|
-
*
|
|
92
|
-
* const dispersa = new Dispersa({
|
|
93
|
-
* resolver: './tokens.resolver.json',
|
|
94
|
-
* buildPath: './output'
|
|
95
|
-
* })
|
|
96
|
-
*
|
|
97
|
-
* await dispersa.build({
|
|
98
|
-
* outputs: [
|
|
99
|
-
* css({
|
|
100
|
-
* name: 'colors-only',
|
|
101
|
-
* file: 'colors.css',
|
|
102
|
-
* preset: 'standalone',
|
|
103
|
-
* selector: ':root',
|
|
104
|
-
* filters: [byType('color')],
|
|
105
|
-
* transforms: [nameKebabCase()]
|
|
106
|
-
* })
|
|
107
|
-
* ],
|
|
108
|
-
* permutations: [
|
|
109
|
-
* { theme: 'light' },
|
|
110
|
-
* { theme: 'dark' }
|
|
111
|
-
* ]
|
|
112
|
-
* })
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
declare class Dispersa {
|
|
116
|
-
private validator;
|
|
117
|
-
private pipeline;
|
|
118
|
-
private outputProcessor;
|
|
119
|
-
private orchestrator;
|
|
120
|
-
private options;
|
|
121
|
-
/**
|
|
122
|
-
* Creates a new Dispersa instance
|
|
123
|
-
*
|
|
124
|
-
* @param options - Configuration options (optional, can be empty object)
|
|
125
|
-
* @param options.resolver - Default resolver (file path or inline object, optional if provided at build time)
|
|
126
|
-
* @param options.buildPath - Default output directory for generated files (omit for in-memory mode)
|
|
127
|
-
* @throws {ConfigurationError} If options are invalid and validation is enabled
|
|
128
|
-
*/
|
|
129
|
-
constructor(options?: DispersaOptions);
|
|
130
|
-
/**
|
|
131
|
-
* Builds design tokens from a resolver configuration
|
|
132
|
-
*
|
|
133
|
-
* Processes tokens through the resolution pipeline, applies preprocessors,
|
|
134
|
-
* transforms, and filters, then generates output files in multiple formats
|
|
135
|
-
* for specified outputs.
|
|
136
|
-
*
|
|
137
|
-
* **Runtime Validation:**
|
|
138
|
-
* This method validates the build configuration
|
|
139
|
-
* and all output configurations before processing, throwing helpful errors for
|
|
140
|
-
* invalid inputs.
|
|
141
|
-
*
|
|
142
|
-
* **Permutation Handling:**
|
|
143
|
-
* - If `config.permutations` is provided and non-empty, builds those specific permutations
|
|
144
|
-
* - If `config.permutations` is undefined or empty, auto-discovers all permutations from resolver
|
|
145
|
-
*
|
|
146
|
-
* @param config - Build configuration
|
|
147
|
-
* @param config.resolver - Resolver configuration (file path or inline object, optional if set in constructor)
|
|
148
|
-
* @param config.outputs - Array of output configurations (renderers, transforms, filters)
|
|
149
|
-
* @param config.buildPath - Output directory for generated files (omit for in-memory mode, optional if set in constructor)
|
|
150
|
-
* @param config.transforms - Global transforms to apply to all tokens
|
|
151
|
-
* @param config.preprocessors - Global preprocessors to apply before parsing
|
|
152
|
-
* @param config.permutations - Array of modifier inputs for generating variations
|
|
153
|
-
* @returns Build result with success status and generated output files
|
|
154
|
-
* @throws {ConfigurationError} If configuration is invalid
|
|
155
|
-
* @throws {FileOperationError} If file operations fail
|
|
156
|
-
*
|
|
157
|
-
* @example Basic build
|
|
158
|
-
* ```typescript
|
|
159
|
-
* const dispersa = new Dispersa({
|
|
160
|
-
* resolver: './tokens.resolver.json',
|
|
161
|
-
* buildPath: './output'
|
|
162
|
-
* })
|
|
163
|
-
*
|
|
164
|
-
* const result = await dispersa.build({
|
|
165
|
-
* outputs: [
|
|
166
|
-
* css({
|
|
167
|
-
* name: 'css',
|
|
168
|
-
* file: 'tokens.css',
|
|
169
|
-
* preset: 'bundle',
|
|
170
|
-
* selector: ':root',
|
|
171
|
-
* transforms: [nameKebabCase()]
|
|
172
|
-
* })
|
|
173
|
-
* ]
|
|
174
|
-
* })
|
|
175
|
-
* ```
|
|
176
|
-
*
|
|
177
|
-
* @example With filters and multiple presets
|
|
178
|
-
* ```typescript
|
|
179
|
-
* const result = await dispersa.build({
|
|
180
|
-
* resolver: './tokens.resolver.json',
|
|
181
|
-
* outputs: [
|
|
182
|
-
* css({
|
|
183
|
-
* name: 'css',
|
|
184
|
-
* file: 'tokens.css',
|
|
185
|
-
* preset: 'bundle',
|
|
186
|
-
* selector: ':root', // All themes in one file
|
|
187
|
-
* transforms: [nameKebabCase()]
|
|
188
|
-
* }),
|
|
189
|
-
* json({
|
|
190
|
-
* name: 'json',
|
|
191
|
-
* file: 'tokens-{theme}.json', // Separate file per theme
|
|
192
|
-
* preset: 'standalone',
|
|
193
|
-
* structure: 'flat'
|
|
194
|
-
* })
|
|
195
|
-
* ],
|
|
196
|
-
* buildPath: './output',
|
|
197
|
-
* permutations: [
|
|
198
|
-
* { theme: 'light' },
|
|
199
|
-
* { theme: 'dark' }
|
|
200
|
-
* ]
|
|
201
|
-
* })
|
|
202
|
-
* ```
|
|
203
|
-
*/
|
|
204
|
-
build(config: BuildConfig): Promise<BuildResult>;
|
|
205
|
-
/**
|
|
206
|
-
* Builds design tokens and throws on any failure.
|
|
207
|
-
*
|
|
208
|
-
* Unlike {@link build}, which catches errors and returns them inside
|
|
209
|
-
* `BuildResult.errors`, this method propagates the first error as an
|
|
210
|
-
* exception. Use it when you want fail-fast behavior in CLI or CI workflows.
|
|
211
|
-
*
|
|
212
|
-
* @param config - Build configuration specifying resolver, outputs, transforms, etc.
|
|
213
|
-
* @returns A successful `BuildResult` (never contains errors)
|
|
214
|
-
* @throws {ConfigurationError} When the build config or resolver is invalid
|
|
215
|
-
* @throws {DispersaError} When token resolution, transforms, or rendering fails
|
|
216
|
-
*
|
|
217
|
-
* @example
|
|
218
|
-
* ```typescript
|
|
219
|
-
* try {
|
|
220
|
-
* const result = await dispersa.buildOrThrow({
|
|
221
|
-
* resolver: './tokens.resolver.json',
|
|
222
|
-
* outputs: [css({ name: 'css', file: 'tokens.css' })],
|
|
223
|
-
* buildPath: './output',
|
|
224
|
-
* })
|
|
225
|
-
* } catch (error) {
|
|
226
|
-
* process.exit(1)
|
|
227
|
-
* }
|
|
228
|
-
* ```
|
|
229
|
-
*/
|
|
230
|
-
buildOrThrow(config: BuildConfig): Promise<BuildResult>;
|
|
231
|
-
/**
|
|
232
|
-
* Builds tokens for a single permutation with all configured outputs
|
|
233
|
-
*
|
|
234
|
-
* Convenience wrapper around `build()` that forces a single permutation.
|
|
235
|
-
* This means it has the same runtime validation and error semantics as `build()`:
|
|
236
|
-
* it returns a `BuildResult` object rather than throwing (use `buildOrThrow()` if you
|
|
237
|
-
* want fail-fast behavior).
|
|
238
|
-
*
|
|
239
|
-
* @param config - Build configuration
|
|
240
|
-
* @param modifierInputs - Modifier values (e.g., `{ theme: 'dark' }`)
|
|
241
|
-
* @returns Build result (success, outputs, optional errors)
|
|
242
|
-
*/
|
|
243
|
-
buildPermutation(config: BuildConfig, modifierInputs?: ModifierInputs): Promise<BuildResult>;
|
|
244
|
-
/**
|
|
245
|
-
* Resolve configuration with constructor defaults
|
|
246
|
-
*/
|
|
247
|
-
private resolveConfig;
|
|
248
|
-
/**
|
|
249
|
-
* Resolves tokens for a specific permutation without generating output files
|
|
250
|
-
*
|
|
251
|
-
* Useful for programmatic access to resolved token values, testing,
|
|
252
|
-
* or implementing custom output logic. Returns fully resolved tokens
|
|
253
|
-
* with all references and aliases resolved.
|
|
254
|
-
*
|
|
255
|
-
* @param resolver - Resolver configuration (file path or inline object)
|
|
256
|
-
* @param modifierInputs - Modifier values for this permutation (e.g., `{ theme: 'dark' }`)
|
|
257
|
-
* @returns Object mapping token names to resolved token objects
|
|
258
|
-
* @throws {FileOperationError} If resolver file cannot be read
|
|
259
|
-
* @throws {TokenReferenceError} If token references cannot be resolved (when validate is enabled)
|
|
260
|
-
*
|
|
261
|
-
* @example
|
|
262
|
-
* ```typescript
|
|
263
|
-
* const tokens = await dispersa.resolveTokens(
|
|
264
|
-
* './tokens.resolver.json',
|
|
265
|
-
* { theme: 'dark' }
|
|
266
|
-
* )
|
|
267
|
-
*
|
|
268
|
-
* console.log(tokens['color.background'].$value) // '#1a1a1a'
|
|
269
|
-
* ```
|
|
270
|
-
*/
|
|
271
|
-
resolveTokens(resolver: string | ResolverDocument, modifierInputs?: ModifierInputs): Promise<ResolvedTokens>;
|
|
272
|
-
/**
|
|
273
|
-
* Resolves tokens for all permutations defined in the resolver
|
|
274
|
-
*
|
|
275
|
-
* Auto-discovers all possible permutations from the resolver's modifier
|
|
276
|
-
* definitions and resolves tokens for each one. Useful for generating
|
|
277
|
-
* comprehensive token sets or validating all theme variations.
|
|
278
|
-
*
|
|
279
|
-
* @param resolver - Resolver configuration (file path or inline object)
|
|
280
|
-
* @returns Array of resolved token sets with their modifier inputs
|
|
281
|
-
* @throws {FileOperationError} If resolver file cannot be read
|
|
282
|
-
* @throws {TokenReferenceError} If token references cannot be resolved (when validate is enabled)
|
|
283
|
-
*
|
|
284
|
-
* @example
|
|
285
|
-
* ```typescript
|
|
286
|
-
* const permutations = await dispersa.resolveAllPermutations(
|
|
287
|
-
* './tokens.resolver.json'
|
|
288
|
-
* )
|
|
289
|
-
*
|
|
290
|
-
* permutations.forEach(({ tokens, modifierInputs }) => {
|
|
291
|
-
* console.log(`Theme: ${modifierInputs.theme}`)
|
|
292
|
-
* console.log(`Tokens: ${Object.keys(tokens).length}`)
|
|
293
|
-
* })
|
|
294
|
-
* ```
|
|
295
|
-
*/
|
|
296
|
-
resolveAllPermutations(resolver: string | ResolverDocument): Promise<{
|
|
297
|
-
tokens: ResolvedTokens;
|
|
298
|
-
modifierInputs: ModifierInputs;
|
|
299
|
-
}[]>;
|
|
300
|
-
/**
|
|
301
|
-
* Generates TypeScript type definitions from resolved tokens
|
|
302
|
-
*
|
|
303
|
-
* Creates a `.d.ts` file with type-safe token definitions including:
|
|
304
|
-
* - Token name union type for autocomplete
|
|
305
|
-
* - Token value types
|
|
306
|
-
* - Nested structure types matching token organization
|
|
307
|
-
*
|
|
308
|
-
* @param tokens - Resolved tokens object
|
|
309
|
-
* @param fileName - Path for the generated `.d.ts` file
|
|
310
|
-
* @param options - Generation options
|
|
311
|
-
* @param options.moduleName - Name for the exported types (default: 'Tokens')
|
|
312
|
-
* @returns Promise that resolves when file is written
|
|
313
|
-
* @throws {FileOperationError} If file cannot be written
|
|
314
|
-
*
|
|
315
|
-
* @example
|
|
316
|
-
* ```typescript
|
|
317
|
-
* const tokens = await dispersa.resolveTokens('./tokens.resolver.json')
|
|
318
|
-
* await dispersa.generateTypes(tokens, './src/tokens.d.ts', {
|
|
319
|
-
* moduleName: 'DesignTokens'
|
|
320
|
-
* })
|
|
321
|
-
*
|
|
322
|
-
* // Generated types can be used like:
|
|
323
|
-
* // const tokenName: TokenName = 'color.background'
|
|
324
|
-
* // const tokens: DesignTokens = { ... }
|
|
325
|
-
* ```
|
|
326
|
-
*/
|
|
327
|
-
generateTypes(tokens: ResolvedTokens, fileName: string, options?: {
|
|
328
|
-
moduleName?: string;
|
|
329
|
-
}): Promise<void>;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
export { BuildConfig, BuildResult, Dispersa, DispersaOptions, ModifierInputs, ResolvedTokens, ResolverDocument };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,332 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { J as JsModuleRendererOptions, a as JsonRendererOptions, P as Preprocessor } from './types-CZb19kiq.js';
|
|
1
|
+
export { L as LintOptions, b as build, a as buildOrThrow, c as buildPermutation, g as generateTypes, l as lint, d as resolveAllPermutations, r as resolveTokens } from './dispersa-BC1kDF5u.js';
|
|
2
|
+
export { B as BuildConfig, b as BuildError, c as BuildOutput, d as BuildResult, C as CssRendererOptions, D as DispersaOptions, E as ErrorCode, F as FileFunction, e as FormatOptions, L as LifecycleHooks, M as MediaQueryFunction, j as ModifierInputs, O as OutputConfig, f as OutputTree, P as PermutationData, g as RenderContext, h as RenderMeta, i as RenderOutput, R as Renderer, k as ResolverDocument, S as SelectorFunction, V as ValidationMode, a as ValidationOptions, l as defineRenderer } from './index-Dajm5rvM.js';
|
|
3
|
+
export { B as BorderToken, r as BorderValue, k as ColorComponent, j as ColorSpace, C as ColorToken, i as ColorValue, h as ColorValueObject, o as CubicBezierValue, D as DesignTokenValue, d as DimensionToken, l as DimensionValue, e as DurationToken, m as DurationValue, F as FontFamilyValue, n as FontWeightValue, w as GradientStop, G as GradientToken, v as GradientValue, R as ResolvedToken, a as ResolvedTokens, S as ShadowToken, p as ShadowValueObject, s as StrokeStyleValue, t as StrokeStyleValueObject, c as TokenType, T as TokenValue, b as TokenValueReference, g as TransitionToken, u as TransitionValue, f as TypographyToken, q as TypographyValue, E as isBorderToken, x as isColorToken, y as isDimensionToken, H as isDurationToken, J as isGradientToken, z as isShadowToken, I as isTransitionToken, A as isTypographyToken } from './types-TQHV1MrY.js';
|
|
4
|
+
export { T as Transform } from './types-DztXKlka.js';
|
|
5
|
+
export { F as Filter } from './types-ebxDimRz.js';
|
|
6
|
+
export { J as JsModuleRendererOptions, a as JsonRendererOptions, P as Preprocessor } from './types-8MLtztK3.js';
|
|
8
7
|
export { AndroidBuilderConfig, CssBuilderConfig, IosBuilderConfig, JsBuilderConfig, JsonBuilderConfig, TailwindBuilderConfig, android, css, ios, js, json, tailwind } from './builders.js';
|
|
9
8
|
export { isOutputTree, outputTree } from './renderers.js';
|
|
10
|
-
export { BasePermutationError, CircularReferenceError, ConfigurationError, DispersaError, FileOperationError, ModifierError, TokenReferenceError, ValidationError } from './errors.js';
|
|
9
|
+
export { B as BasePermutationError, C as CircularReferenceError, a as ConfigurationError, D as DispersaError, F as FileOperationError, L as LintError, M as ModifierError, T as TokenReferenceError, V as ValidationError } from './errors-qT4sJgSA.js';
|
|
10
|
+
export { A as AndroidRendererOptions, I as IosRendererOptions, T as TailwindRendererOptions } from './android-DANJjjPO.js';
|
|
11
11
|
import 'json-schema-to-ts';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @license
|
|
15
|
-
* Copyright (c) 2025 Dispersa Contributors
|
|
16
|
-
* SPDX-License-Identifier: MIT
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* DTCG design token processor with multi-format output support
|
|
21
|
-
*
|
|
22
|
-
* Dispersa processes DTCG-compliant design tokens through a configurable pipeline,
|
|
23
|
-
* resolves references and aliases, applies transforms and filters, and generates output
|
|
24
|
-
* in multiple formats (CSS, JSON, JavaScript).
|
|
25
|
-
*
|
|
26
|
-
* **Runtime Validation:**
|
|
27
|
-
* Dispersa validates all configuration inputs at runtime, including constructor options,
|
|
28
|
-
* build configs, output configs, and custom component registrations. This catches
|
|
29
|
-
* configuration errors early with helpful error messages.
|
|
30
|
-
*
|
|
31
|
-
* Features:
|
|
32
|
-
* - **Transforms**: Modify token values and names (e.g., convert colors, change case)
|
|
33
|
-
* - **Filters**: Select which tokens to include in output
|
|
34
|
-
* - **Preprocessors**: Transform raw token data before parsing
|
|
35
|
-
* - **Renderers**: Generate output in various formats
|
|
36
|
-
* - **Runtime validation**: JSON schema validation for all user inputs
|
|
37
|
-
*
|
|
38
|
-
* @example Basic usage with constructor defaults
|
|
39
|
-
* ```typescript
|
|
40
|
-
* const dispersa = new Dispersa({
|
|
41
|
-
* resolver: './tokens.resolver.json',
|
|
42
|
-
* buildPath: './output'
|
|
43
|
-
* })
|
|
44
|
-
*
|
|
45
|
-
* const result = await dispersa.build({
|
|
46
|
-
* outputs: [
|
|
47
|
-
* css({
|
|
48
|
-
* name: 'css',
|
|
49
|
-
* file: 'tokens.css',
|
|
50
|
-
* preset: 'bundle',
|
|
51
|
-
* selector: ':root',
|
|
52
|
-
* transforms: [nameKebabCase()]
|
|
53
|
-
* })
|
|
54
|
-
* ]
|
|
55
|
-
* })
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @example Mixed presets per output
|
|
59
|
-
* ```typescript
|
|
60
|
-
* import { css, json } from 'dispersa'
|
|
61
|
-
*
|
|
62
|
-
* const dispersa = new Dispersa({
|
|
63
|
-
* resolver: './tokens.resolver.json',
|
|
64
|
-
* buildPath: './output'
|
|
65
|
-
* })
|
|
66
|
-
*
|
|
67
|
-
* await dispersa.build({
|
|
68
|
-
* outputs: [
|
|
69
|
-
* css({
|
|
70
|
-
* name: 'css',
|
|
71
|
-
* file: 'tokens.css',
|
|
72
|
-
* preset: 'bundle',
|
|
73
|
-
* selector: ':root', // All themes in one CSS file
|
|
74
|
-
* transforms: [nameKebabCase()]
|
|
75
|
-
* }),
|
|
76
|
-
* json({
|
|
77
|
-
* name: 'json',
|
|
78
|
-
* file: 'tokens-{theme}.json', // Separate file per theme
|
|
79
|
-
* preset: 'standalone',
|
|
80
|
-
* structure: 'flat'
|
|
81
|
-
* })
|
|
82
|
-
* ]
|
|
83
|
-
* })
|
|
84
|
-
* ```
|
|
85
|
-
*
|
|
86
|
-
* @example Using filters and preprocessors
|
|
87
|
-
* ```typescript
|
|
88
|
-
* import { css } from 'dispersa'
|
|
89
|
-
* import { byType } from 'dispersa/filters'
|
|
90
|
-
* import { nameKebabCase } from 'dispersa/transforms'
|
|
91
|
-
*
|
|
92
|
-
* const dispersa = new Dispersa({
|
|
93
|
-
* resolver: './tokens.resolver.json',
|
|
94
|
-
* buildPath: './output'
|
|
95
|
-
* })
|
|
96
|
-
*
|
|
97
|
-
* await dispersa.build({
|
|
98
|
-
* outputs: [
|
|
99
|
-
* css({
|
|
100
|
-
* name: 'colors-only',
|
|
101
|
-
* file: 'colors.css',
|
|
102
|
-
* preset: 'standalone',
|
|
103
|
-
* selector: ':root',
|
|
104
|
-
* filters: [byType('color')],
|
|
105
|
-
* transforms: [nameKebabCase()]
|
|
106
|
-
* })
|
|
107
|
-
* ],
|
|
108
|
-
* permutations: [
|
|
109
|
-
* { theme: 'light' },
|
|
110
|
-
* { theme: 'dark' }
|
|
111
|
-
* ]
|
|
112
|
-
* })
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
declare class Dispersa {
|
|
116
|
-
private validator;
|
|
117
|
-
private pipeline;
|
|
118
|
-
private outputProcessor;
|
|
119
|
-
private orchestrator;
|
|
120
|
-
private options;
|
|
121
|
-
/**
|
|
122
|
-
* Creates a new Dispersa instance
|
|
123
|
-
*
|
|
124
|
-
* @param options - Configuration options (optional, can be empty object)
|
|
125
|
-
* @param options.resolver - Default resolver (file path or inline object, optional if provided at build time)
|
|
126
|
-
* @param options.buildPath - Default output directory for generated files (omit for in-memory mode)
|
|
127
|
-
* @throws {ConfigurationError} If options are invalid and validation is enabled
|
|
128
|
-
*/
|
|
129
|
-
constructor(options?: DispersaOptions);
|
|
130
|
-
/**
|
|
131
|
-
* Builds design tokens from a resolver configuration
|
|
132
|
-
*
|
|
133
|
-
* Processes tokens through the resolution pipeline, applies preprocessors,
|
|
134
|
-
* transforms, and filters, then generates output files in multiple formats
|
|
135
|
-
* for specified outputs.
|
|
136
|
-
*
|
|
137
|
-
* **Runtime Validation:**
|
|
138
|
-
* This method validates the build configuration
|
|
139
|
-
* and all output configurations before processing, throwing helpful errors for
|
|
140
|
-
* invalid inputs.
|
|
141
|
-
*
|
|
142
|
-
* **Permutation Handling:**
|
|
143
|
-
* - If `config.permutations` is provided and non-empty, builds those specific permutations
|
|
144
|
-
* - If `config.permutations` is undefined or empty, auto-discovers all permutations from resolver
|
|
145
|
-
*
|
|
146
|
-
* @param config - Build configuration
|
|
147
|
-
* @param config.resolver - Resolver configuration (file path or inline object, optional if set in constructor)
|
|
148
|
-
* @param config.outputs - Array of output configurations (renderers, transforms, filters)
|
|
149
|
-
* @param config.buildPath - Output directory for generated files (omit for in-memory mode, optional if set in constructor)
|
|
150
|
-
* @param config.transforms - Global transforms to apply to all tokens
|
|
151
|
-
* @param config.preprocessors - Global preprocessors to apply before parsing
|
|
152
|
-
* @param config.permutations - Array of modifier inputs for generating variations
|
|
153
|
-
* @returns Build result with success status and generated output files
|
|
154
|
-
* @throws {ConfigurationError} If configuration is invalid
|
|
155
|
-
* @throws {FileOperationError} If file operations fail
|
|
156
|
-
*
|
|
157
|
-
* @example Basic build
|
|
158
|
-
* ```typescript
|
|
159
|
-
* const dispersa = new Dispersa({
|
|
160
|
-
* resolver: './tokens.resolver.json',
|
|
161
|
-
* buildPath: './output'
|
|
162
|
-
* })
|
|
163
|
-
*
|
|
164
|
-
* const result = await dispersa.build({
|
|
165
|
-
* outputs: [
|
|
166
|
-
* css({
|
|
167
|
-
* name: 'css',
|
|
168
|
-
* file: 'tokens.css',
|
|
169
|
-
* preset: 'bundle',
|
|
170
|
-
* selector: ':root',
|
|
171
|
-
* transforms: [nameKebabCase()]
|
|
172
|
-
* })
|
|
173
|
-
* ]
|
|
174
|
-
* })
|
|
175
|
-
* ```
|
|
176
|
-
*
|
|
177
|
-
* @example With filters and multiple presets
|
|
178
|
-
* ```typescript
|
|
179
|
-
* const result = await dispersa.build({
|
|
180
|
-
* resolver: './tokens.resolver.json',
|
|
181
|
-
* outputs: [
|
|
182
|
-
* css({
|
|
183
|
-
* name: 'css',
|
|
184
|
-
* file: 'tokens.css',
|
|
185
|
-
* preset: 'bundle',
|
|
186
|
-
* selector: ':root', // All themes in one file
|
|
187
|
-
* transforms: [nameKebabCase()]
|
|
188
|
-
* }),
|
|
189
|
-
* json({
|
|
190
|
-
* name: 'json',
|
|
191
|
-
* file: 'tokens-{theme}.json', // Separate file per theme
|
|
192
|
-
* preset: 'standalone',
|
|
193
|
-
* structure: 'flat'
|
|
194
|
-
* })
|
|
195
|
-
* ],
|
|
196
|
-
* buildPath: './output',
|
|
197
|
-
* permutations: [
|
|
198
|
-
* { theme: 'light' },
|
|
199
|
-
* { theme: 'dark' }
|
|
200
|
-
* ]
|
|
201
|
-
* })
|
|
202
|
-
* ```
|
|
203
|
-
*/
|
|
204
|
-
build(config: BuildConfig): Promise<BuildResult>;
|
|
205
|
-
/**
|
|
206
|
-
* Builds design tokens and throws on any failure.
|
|
207
|
-
*
|
|
208
|
-
* Unlike {@link build}, which catches errors and returns them inside
|
|
209
|
-
* `BuildResult.errors`, this method propagates the first error as an
|
|
210
|
-
* exception. Use it when you want fail-fast behavior in CLI or CI workflows.
|
|
211
|
-
*
|
|
212
|
-
* @param config - Build configuration specifying resolver, outputs, transforms, etc.
|
|
213
|
-
* @returns A successful `BuildResult` (never contains errors)
|
|
214
|
-
* @throws {ConfigurationError} When the build config or resolver is invalid
|
|
215
|
-
* @throws {DispersaError} When token resolution, transforms, or rendering fails
|
|
216
|
-
*
|
|
217
|
-
* @example
|
|
218
|
-
* ```typescript
|
|
219
|
-
* try {
|
|
220
|
-
* const result = await dispersa.buildOrThrow({
|
|
221
|
-
* resolver: './tokens.resolver.json',
|
|
222
|
-
* outputs: [css({ name: 'css', file: 'tokens.css' })],
|
|
223
|
-
* buildPath: './output',
|
|
224
|
-
* })
|
|
225
|
-
* } catch (error) {
|
|
226
|
-
* process.exit(1)
|
|
227
|
-
* }
|
|
228
|
-
* ```
|
|
229
|
-
*/
|
|
230
|
-
buildOrThrow(config: BuildConfig): Promise<BuildResult>;
|
|
231
|
-
/**
|
|
232
|
-
* Builds tokens for a single permutation with all configured outputs
|
|
233
|
-
*
|
|
234
|
-
* Convenience wrapper around `build()` that forces a single permutation.
|
|
235
|
-
* This means it has the same runtime validation and error semantics as `build()`:
|
|
236
|
-
* it returns a `BuildResult` object rather than throwing (use `buildOrThrow()` if you
|
|
237
|
-
* want fail-fast behavior).
|
|
238
|
-
*
|
|
239
|
-
* @param config - Build configuration
|
|
240
|
-
* @param modifierInputs - Modifier values (e.g., `{ theme: 'dark' }`)
|
|
241
|
-
* @returns Build result (success, outputs, optional errors)
|
|
242
|
-
*/
|
|
243
|
-
buildPermutation(config: BuildConfig, modifierInputs?: ModifierInputs): Promise<BuildResult>;
|
|
244
|
-
/**
|
|
245
|
-
* Resolve configuration with constructor defaults
|
|
246
|
-
*/
|
|
247
|
-
private resolveConfig;
|
|
248
|
-
/**
|
|
249
|
-
* Resolves tokens for a specific permutation without generating output files
|
|
250
|
-
*
|
|
251
|
-
* Useful for programmatic access to resolved token values, testing,
|
|
252
|
-
* or implementing custom output logic. Returns fully resolved tokens
|
|
253
|
-
* with all references and aliases resolved.
|
|
254
|
-
*
|
|
255
|
-
* @param resolver - Resolver configuration (file path or inline object)
|
|
256
|
-
* @param modifierInputs - Modifier values for this permutation (e.g., `{ theme: 'dark' }`)
|
|
257
|
-
* @returns Object mapping token names to resolved token objects
|
|
258
|
-
* @throws {FileOperationError} If resolver file cannot be read
|
|
259
|
-
* @throws {TokenReferenceError} If token references cannot be resolved (when validate is enabled)
|
|
260
|
-
*
|
|
261
|
-
* @example
|
|
262
|
-
* ```typescript
|
|
263
|
-
* const tokens = await dispersa.resolveTokens(
|
|
264
|
-
* './tokens.resolver.json',
|
|
265
|
-
* { theme: 'dark' }
|
|
266
|
-
* )
|
|
267
|
-
*
|
|
268
|
-
* console.log(tokens['color.background'].$value) // '#1a1a1a'
|
|
269
|
-
* ```
|
|
270
|
-
*/
|
|
271
|
-
resolveTokens(resolver: string | ResolverDocument, modifierInputs?: ModifierInputs): Promise<ResolvedTokens>;
|
|
272
|
-
/**
|
|
273
|
-
* Resolves tokens for all permutations defined in the resolver
|
|
274
|
-
*
|
|
275
|
-
* Auto-discovers all possible permutations from the resolver's modifier
|
|
276
|
-
* definitions and resolves tokens for each one. Useful for generating
|
|
277
|
-
* comprehensive token sets or validating all theme variations.
|
|
278
|
-
*
|
|
279
|
-
* @param resolver - Resolver configuration (file path or inline object)
|
|
280
|
-
* @returns Array of resolved token sets with their modifier inputs
|
|
281
|
-
* @throws {FileOperationError} If resolver file cannot be read
|
|
282
|
-
* @throws {TokenReferenceError} If token references cannot be resolved (when validate is enabled)
|
|
283
|
-
*
|
|
284
|
-
* @example
|
|
285
|
-
* ```typescript
|
|
286
|
-
* const permutations = await dispersa.resolveAllPermutations(
|
|
287
|
-
* './tokens.resolver.json'
|
|
288
|
-
* )
|
|
289
|
-
*
|
|
290
|
-
* permutations.forEach(({ tokens, modifierInputs }) => {
|
|
291
|
-
* console.log(`Theme: ${modifierInputs.theme}`)
|
|
292
|
-
* console.log(`Tokens: ${Object.keys(tokens).length}`)
|
|
293
|
-
* })
|
|
294
|
-
* ```
|
|
295
|
-
*/
|
|
296
|
-
resolveAllPermutations(resolver: string | ResolverDocument): Promise<{
|
|
297
|
-
tokens: ResolvedTokens;
|
|
298
|
-
modifierInputs: ModifierInputs;
|
|
299
|
-
}[]>;
|
|
300
|
-
/**
|
|
301
|
-
* Generates TypeScript type definitions from resolved tokens
|
|
302
|
-
*
|
|
303
|
-
* Creates a `.d.ts` file with type-safe token definitions including:
|
|
304
|
-
* - Token name union type for autocomplete
|
|
305
|
-
* - Token value types
|
|
306
|
-
* - Nested structure types matching token organization
|
|
307
|
-
*
|
|
308
|
-
* @param tokens - Resolved tokens object
|
|
309
|
-
* @param fileName - Path for the generated `.d.ts` file
|
|
310
|
-
* @param options - Generation options
|
|
311
|
-
* @param options.moduleName - Name for the exported types (default: 'Tokens')
|
|
312
|
-
* @returns Promise that resolves when file is written
|
|
313
|
-
* @throws {FileOperationError} If file cannot be written
|
|
314
|
-
*
|
|
315
|
-
* @example
|
|
316
|
-
* ```typescript
|
|
317
|
-
* const tokens = await dispersa.resolveTokens('./tokens.resolver.json')
|
|
318
|
-
* await dispersa.generateTypes(tokens, './src/tokens.d.ts', {
|
|
319
|
-
* moduleName: 'DesignTokens'
|
|
320
|
-
* })
|
|
321
|
-
*
|
|
322
|
-
* // Generated types can be used like:
|
|
323
|
-
* // const tokenName: TokenName = 'color.background'
|
|
324
|
-
* // const tokens: DesignTokens = { ... }
|
|
325
|
-
* ```
|
|
326
|
-
*/
|
|
327
|
-
generateTypes(tokens: ResolvedTokens, fileName: string, options?: {
|
|
328
|
-
moduleName?: string;
|
|
329
|
-
}): Promise<void>;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
export { BuildConfig, BuildResult, Dispersa, DispersaOptions, ModifierInputs, ResolvedTokens, ResolverDocument };
|