dispersa 1.2.0 → 1.3.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 +1 -2
- package/dist/{builders.d.cts → builders-B7_pBy58.d.cts} +180 -6
- package/dist/{builders.d.ts → builders-BEoMaLal.d.ts} +180 -6
- package/dist/{types-8MLtztK3.d.ts → config-schemas-DnEBhIg0.d.cts} +1 -158
- package/dist/{types-BHBHRm0a.d.cts → config-schemas-DnEBhIg0.d.ts} +1 -158
- package/dist/dispersa-DF2ZkG2O.d.ts +567 -0
- package/dist/dispersa-DJeCN0cP.d.cts +567 -0
- package/dist/index.cjs +2117 -2098
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +2117 -2098
- package/dist/index.js.map +1 -1
- package/dist/{lint.cjs → lint/index.cjs} +2 -2
- package/dist/lint/index.cjs.map +1 -0
- package/dist/{lint.d.ts → lint/index.d.cts} +8 -7
- package/dist/{lint.d.cts → lint/index.d.ts} +8 -7
- package/dist/{lint.js → lint/index.js} +2 -2
- package/dist/lint/index.js.map +1 -0
- package/dist/{renderers.d.ts → output-tree-BRbfWSmG.d.ts} +3 -10
- package/dist/{renderers.d.cts → output-tree-Hmi77EMv.d.cts} +3 -10
- package/dist/{builders.cjs → outputs/builders.cjs} +30 -30
- package/dist/outputs/builders.cjs.map +1 -0
- package/dist/outputs/builders.d.cts +7 -0
- package/dist/outputs/builders.d.ts +7 -0
- package/dist/{builders.js → outputs/builders.js} +30 -30
- package/dist/outputs/builders.js.map +1 -0
- package/dist/outputs/index.cjs +3750 -0
- package/dist/outputs/index.cjs.map +1 -0
- package/dist/outputs/index.d.cts +73 -0
- package/dist/outputs/index.d.ts +73 -0
- package/dist/outputs/index.js +3730 -0
- package/dist/outputs/index.js.map +1 -0
- package/dist/{filters.cjs → processing/filters/index.cjs} +24 -18
- package/dist/processing/filters/index.cjs.map +1 -0
- package/dist/processing/filters/index.d.cts +36 -0
- package/dist/processing/filters/index.d.ts +36 -0
- package/dist/{filters.js → processing/filters/index.js} +24 -18
- package/dist/processing/filters/index.js.map +1 -0
- package/dist/{preprocessors.cjs → processing/preprocessors/index.cjs} +3 -3
- package/dist/processing/preprocessors/index.cjs.map +1 -0
- package/dist/processing/preprocessors/index.d.cts +29 -0
- package/dist/processing/preprocessors/index.d.ts +29 -0
- package/dist/{preprocessors.js → processing/preprocessors/index.js} +3 -3
- package/dist/processing/preprocessors/index.js.map +1 -0
- package/dist/{transforms.cjs → processing/transforms/index.cjs} +2 -7
- package/dist/processing/transforms/index.cjs.map +1 -0
- package/dist/{transforms.d.ts → processing/transforms/index.d.cts} +2 -2
- package/dist/{transforms.d.cts → processing/transforms/index.d.ts} +2 -2
- package/dist/{transforms.js → processing/transforms/index.js} +2 -7
- package/dist/processing/transforms/index.js.map +1 -0
- package/dist/{errors.cjs → shared/errors/index.cjs} +12 -2
- package/dist/shared/errors/index.cjs.map +1 -0
- package/dist/{errors-qT4sJgSA.d.ts → shared/errors/index.d.cts} +11 -2
- package/dist/{errors-qT4sJgSA.d.cts → shared/errors/index.d.ts} +11 -2
- package/dist/{errors.js → shared/errors/index.js} +12 -3
- package/dist/shared/errors/index.js.map +1 -0
- package/dist/types-B0cI70Bt.d.cts +453 -0
- package/dist/types-BxDEUCos.d.ts +453 -0
- package/dist/types-DUc4vLZH.d.cts +36 -0
- package/dist/types-s3UoDRKl.d.ts +36 -0
- package/package.json +26 -36
- package/dist/android-CRDfSB3_.d.cts +0 -126
- package/dist/android-DANJjjPO.d.ts +0 -126
- package/dist/builders.cjs.map +0 -1
- package/dist/builders.js.map +0 -1
- package/dist/dispersa-BC1kDF5u.d.ts +0 -118
- package/dist/dispersa-DL3J_Pmz.d.cts +0 -118
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.cts +0 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/filters.cjs.map +0 -1
- package/dist/filters.d.cts +0 -83
- package/dist/filters.d.ts +0 -83
- package/dist/filters.js.map +0 -1
- package/dist/index-Dajm5rvM.d.ts +0 -895
- package/dist/index-De6SjZYH.d.cts +0 -895
- package/dist/lint.cjs.map +0 -1
- package/dist/lint.js.map +0 -1
- package/dist/preprocessors.cjs.map +0 -1
- package/dist/preprocessors.d.cts +0 -17
- package/dist/preprocessors.d.ts +0 -17
- package/dist/preprocessors.js.map +0 -1
- package/dist/renderers.cjs +0 -28
- package/dist/renderers.cjs.map +0 -1
- package/dist/renderers.js +0 -24
- package/dist/renderers.js.map +0 -1
- package/dist/transforms.cjs.map +0 -1
- package/dist/transforms.js.map +0 -1
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import { F as Filter } from './types-ebxDimRz.js';
|
|
2
|
+
import { a as ResolvedTokens } from './types-TQHV1MrY.js';
|
|
3
|
+
import { T as Transform } from './types-DztXKlka.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview DTCG Resolver types (2025.10 specification)
|
|
7
|
+
*
|
|
8
|
+
* The resolver system allows defining token sources, modifiers (themes, modes),
|
|
9
|
+
* and the order in which they should be resolved and merged.
|
|
10
|
+
*
|
|
11
|
+
* ResolverDocument type is defined here to match DTCG 2025.10.
|
|
12
|
+
*/
|
|
13
|
+
type ReferenceObject = {
|
|
14
|
+
$ref: string;
|
|
15
|
+
};
|
|
16
|
+
type TokenSource = ReferenceObject | Record<string, unknown>;
|
|
17
|
+
type Set = {
|
|
18
|
+
sources: TokenSource[];
|
|
19
|
+
description?: string;
|
|
20
|
+
$extensions?: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
type Modifier = {
|
|
23
|
+
contexts: Record<string, TokenSource[]>;
|
|
24
|
+
description?: string;
|
|
25
|
+
default?: string;
|
|
26
|
+
$extensions?: Record<string, unknown>;
|
|
27
|
+
};
|
|
28
|
+
type InlineSet = Set & {
|
|
29
|
+
name: string;
|
|
30
|
+
type: 'set';
|
|
31
|
+
};
|
|
32
|
+
type InlineModifier = Modifier & {
|
|
33
|
+
name: string;
|
|
34
|
+
type: 'modifier';
|
|
35
|
+
};
|
|
36
|
+
type ResolverDocument = {
|
|
37
|
+
$schema?: string;
|
|
38
|
+
name?: string;
|
|
39
|
+
version: '2025.10';
|
|
40
|
+
description?: string;
|
|
41
|
+
sets?: Record<string, Set>;
|
|
42
|
+
modifiers?: Record<string, Modifier>;
|
|
43
|
+
resolutionOrder: (ReferenceObject | InlineSet | InlineModifier)[];
|
|
44
|
+
$defs?: Record<string, unknown>;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Map of modifier names to selected context values
|
|
48
|
+
*
|
|
49
|
+
* Used to specify which variation of each modifier to use when resolving tokens.
|
|
50
|
+
* Can be made type-safe by providing a generic type parameter.
|
|
51
|
+
*
|
|
52
|
+
* @template T - Optional specific type for modifier values (defaults to generic Record)
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Generic (default):
|
|
57
|
+
* const inputs: ModifierInputs = {
|
|
58
|
+
* theme: 'dark',
|
|
59
|
+
* platform: 'mobile'
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* // Type-safe:
|
|
63
|
+
* type MyModifiers = { theme: 'light' | 'dark', platform: 'web' | 'mobile' }
|
|
64
|
+
* const inputs: ModifierInputs<MyModifiers> = {
|
|
65
|
+
* theme: 'dark', // ✅ Autocomplete!
|
|
66
|
+
* platform: 'mobile'
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
type ModifierInputs<T extends Record<string, string> = Record<string, string>> = T;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @fileoverview Renderer system types for token output generation
|
|
74
|
+
*
|
|
75
|
+
* Note: outputs/types has types for both renderers (Renderer, RenderContext)
|
|
76
|
+
* and output configuration (OutputConfig, LifecycleHooks). This works because
|
|
77
|
+
* they're all related to the output phase of token processing.
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Generic options object for renderers
|
|
82
|
+
*
|
|
83
|
+
* Each renderer can define its own specific options that extend this base type.
|
|
84
|
+
*/
|
|
85
|
+
type FormatOptions = Record<string, unknown>;
|
|
86
|
+
/**
|
|
87
|
+
* Data for a single permutation (combination of modifier values)
|
|
88
|
+
*/
|
|
89
|
+
type PermutationData = {
|
|
90
|
+
tokens: ResolvedTokens;
|
|
91
|
+
modifierInputs: ModifierInputs;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Metadata for renderers to reason about modifier dimensions.
|
|
95
|
+
*/
|
|
96
|
+
type RenderMeta = {
|
|
97
|
+
dimensions: string[];
|
|
98
|
+
defaults: Record<string, string>;
|
|
99
|
+
basePermutation: ModifierInputs;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Context provided to renderer formatters.
|
|
103
|
+
*/
|
|
104
|
+
type RenderContext<TOptions extends FormatOptions = FormatOptions> = {
|
|
105
|
+
permutations: PermutationData[];
|
|
106
|
+
output: OutputConfig<TOptions>;
|
|
107
|
+
resolver: ResolverDocument;
|
|
108
|
+
meta: RenderMeta;
|
|
109
|
+
buildPath?: string;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Multi-file output representation for renderers.
|
|
113
|
+
*/
|
|
114
|
+
type OutputTree = {
|
|
115
|
+
kind: 'outputTree';
|
|
116
|
+
files: Record<string, string>;
|
|
117
|
+
};
|
|
118
|
+
type RenderOutput = string | OutputTree;
|
|
119
|
+
/**
|
|
120
|
+
* Output from a build operation
|
|
121
|
+
*/
|
|
122
|
+
type BuildOutput = {
|
|
123
|
+
name: string;
|
|
124
|
+
/** File path where output was written (undefined for in-memory mode) */
|
|
125
|
+
path?: string;
|
|
126
|
+
content: string;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Renderer definition for converting tokens to output format
|
|
130
|
+
*
|
|
131
|
+
* Renderers implement a single `format()` method that can return either
|
|
132
|
+
* a single string or an OutputTree for multi-file outputs.
|
|
133
|
+
*
|
|
134
|
+
* @example Simple renderer with format()
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const scssRenderer: Renderer = {
|
|
137
|
+
* format: (context) => {
|
|
138
|
+
* const tokens = context.permutations[0]?.tokens ?? {}
|
|
139
|
+
* return Object.entries(tokens)
|
|
140
|
+
* .map(([name, token]) => `$${name}: ${token.$value};`)
|
|
141
|
+
* .join('\n')
|
|
142
|
+
* },
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
type Renderer<TOptions extends FormatOptions = FormatOptions> = {
|
|
147
|
+
/**
|
|
148
|
+
* Preset identifier (e.g., 'bundle', 'standalone', 'modifier')
|
|
149
|
+
* Indicates which variant of the renderer this is
|
|
150
|
+
*/
|
|
151
|
+
preset?: string;
|
|
152
|
+
/**
|
|
153
|
+
* Convert tokens to output content.
|
|
154
|
+
*
|
|
155
|
+
* Renderers receive all resolved permutations and modifier metadata via context.
|
|
156
|
+
* They can return either a single string (single output file) or an OutputTree
|
|
157
|
+
* for multi-file outputs.
|
|
158
|
+
*/
|
|
159
|
+
format: (context: RenderContext<TOptions>, options?: TOptions) => RenderOutput | Promise<RenderOutput>;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Helper for defining custom renderers with full type inference.
|
|
163
|
+
*
|
|
164
|
+
* Works like Vue's `defineComponent()` or Vite's `defineConfig()` --
|
|
165
|
+
* an identity function that enables TypeScript to infer the options type
|
|
166
|
+
* from the generic parameter, giving you autocomplete and type-checking
|
|
167
|
+
* on both `context` and `options` inside `format()`.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* import { defineRenderer } from 'dispersa/outputs'
|
|
172
|
+
*
|
|
173
|
+
* type MyOptions = { prefix: string; minify?: boolean }
|
|
174
|
+
*
|
|
175
|
+
* const myRenderer = defineRenderer<MyOptions>({
|
|
176
|
+
* format(context, options) {
|
|
177
|
+
* // options is typed as MyOptions | undefined
|
|
178
|
+
* // context.output.options is typed as MyOptions | undefined
|
|
179
|
+
* const prefix = options?.prefix ?? 'token'
|
|
180
|
+
* return Object.entries(context.permutations[0]?.tokens ?? {})
|
|
181
|
+
* .map(([name, token]) => `${prefix}-${name}: ${token.$value}`)
|
|
182
|
+
* .join('\n')
|
|
183
|
+
* },
|
|
184
|
+
* })
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
declare function defineRenderer<T extends FormatOptions>(renderer: Renderer<T>): Renderer<T>;
|
|
188
|
+
/**
|
|
189
|
+
* Function type for dynamically generating CSS selectors based on modifier context
|
|
190
|
+
*
|
|
191
|
+
* @param modifierName - Name of the modifier (e.g., 'theme', 'breakpoint')
|
|
192
|
+
* @param context - Context value of the modifier (e.g., 'dark', 'mobile')
|
|
193
|
+
* @param isBase - Whether this is the base permutation
|
|
194
|
+
* @param allModifierInputs - All modifier inputs for this permutation
|
|
195
|
+
* @returns CSS selector string (e.g., '[data-theme="dark"]')
|
|
196
|
+
*/
|
|
197
|
+
type SelectorFunction = (modifierName: string, context: string, isBase: boolean, allModifierInputs: Record<string, string>) => string;
|
|
198
|
+
/**
|
|
199
|
+
* Function type for dynamically generating media queries based on modifier context
|
|
200
|
+
*
|
|
201
|
+
* @param modifierName - Name of the modifier (e.g., 'theme', 'breakpoint')
|
|
202
|
+
* @param context - Context value of the modifier (e.g., 'dark', 'mobile')
|
|
203
|
+
* @param isBase - Whether this is the base permutation
|
|
204
|
+
* @param allModifierInputs - All modifier inputs for this permutation
|
|
205
|
+
* @returns Media query string (e.g., '(max-width: 768px)') or empty string for no media query
|
|
206
|
+
*/
|
|
207
|
+
type MediaQueryFunction = (modifierName: string, context: string, isBase: boolean, allModifierInputs: Record<string, string>) => string;
|
|
208
|
+
/**
|
|
209
|
+
* Options for CSS custom properties renderer
|
|
210
|
+
*
|
|
211
|
+
* Controls how tokens are converted to CSS custom properties (CSS variables).
|
|
212
|
+
*
|
|
213
|
+
* **Note:** Token naming is controlled through transforms, not renderer options.
|
|
214
|
+
* Use `nameKebabCase()` and `namePrefix()` for naming control.
|
|
215
|
+
*
|
|
216
|
+
* @example String-based selectors
|
|
217
|
+
* ```typescript
|
|
218
|
+
* css({
|
|
219
|
+
* name: 'tokens',
|
|
220
|
+
* file: 'tokens.css',
|
|
221
|
+
* transforms: [nameKebabCase(), namePrefix('ds-')],
|
|
222
|
+
* preset: 'bundle',
|
|
223
|
+
* selector: ':root',
|
|
224
|
+
* })
|
|
225
|
+
* ```
|
|
226
|
+
*
|
|
227
|
+
* @example Function-based selectors
|
|
228
|
+
* ```typescript
|
|
229
|
+
* outputs: [{
|
|
230
|
+
* renderer: cssRenderer(),
|
|
231
|
+
* options: {
|
|
232
|
+
* preset: 'bundle',
|
|
233
|
+
* selector: (modifier, context, isBase, allInputs) => {
|
|
234
|
+
* if (isBase) return ':root'
|
|
235
|
+
* return `[data-${modifier}="${context}"]`
|
|
236
|
+
* },
|
|
237
|
+
* mediaQuery: (modifier, context) => {
|
|
238
|
+
* if (modifier === 'breakpoint' && context === 'mobile') {
|
|
239
|
+
* return '(max-width: 768px)'
|
|
240
|
+
* }
|
|
241
|
+
* return ''
|
|
242
|
+
* }
|
|
243
|
+
* }
|
|
244
|
+
* }]
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
type CssRendererOptions = {
|
|
248
|
+
preset?: 'bundle' | 'standalone' | 'modifier';
|
|
249
|
+
selector?: string | SelectorFunction;
|
|
250
|
+
mediaQuery?: string | MediaQueryFunction;
|
|
251
|
+
minify?: boolean;
|
|
252
|
+
preserveReferences?: boolean;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Result of a token build operation
|
|
257
|
+
*
|
|
258
|
+
* Contains success status, generated output files, and any errors encountered.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* const result = await build(config)
|
|
263
|
+
* if (result.success) {
|
|
264
|
+
* result.outputs.forEach(output => {
|
|
265
|
+
* console.log(`Generated ${output.name}: ${output.path}`)
|
|
266
|
+
* })
|
|
267
|
+
* } else {
|
|
268
|
+
* console.error('Build errors:', result.errors)
|
|
269
|
+
* }
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
/**
|
|
273
|
+
* Error code identifying the type of build error
|
|
274
|
+
*/
|
|
275
|
+
type ErrorCode = 'TOKEN_REFERENCE' | 'CIRCULAR_REFERENCE' | 'VALIDATION' | 'FILE_OPERATION' | 'CONFIGURATION' | 'BASE_PERMUTATION' | 'MODIFIER' | 'UNKNOWN';
|
|
276
|
+
/**
|
|
277
|
+
* Structured error from a build operation
|
|
278
|
+
*
|
|
279
|
+
* Preserves typed context from the error hierarchy so consumers
|
|
280
|
+
* can programmatically react to specific failure modes.
|
|
281
|
+
*/
|
|
282
|
+
type BuildError = {
|
|
283
|
+
/** Human-readable error message */
|
|
284
|
+
message: string;
|
|
285
|
+
/** Machine-readable error code identifying the failure type */
|
|
286
|
+
code: ErrorCode;
|
|
287
|
+
/** File path where the error occurred (for file operation errors) */
|
|
288
|
+
path?: string;
|
|
289
|
+
/** Token path where the error occurred (e.g. 'color.primary') */
|
|
290
|
+
tokenPath?: string;
|
|
291
|
+
/** Error severity */
|
|
292
|
+
severity: 'error' | 'warning';
|
|
293
|
+
/** Suggested alternatives (e.g. similar token names for TOKEN_REFERENCE errors) */
|
|
294
|
+
suggestions?: string[];
|
|
295
|
+
};
|
|
296
|
+
type BuildResult = {
|
|
297
|
+
/** Whether the build completed successfully */
|
|
298
|
+
success: boolean;
|
|
299
|
+
/** Array of generated output files */
|
|
300
|
+
outputs: BuildOutput[];
|
|
301
|
+
/** Array of errors encountered during build (only present if success is false) */
|
|
302
|
+
errors?: BuildError[];
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Lifecycle hooks for the build process.
|
|
306
|
+
*
|
|
307
|
+
* The same hook type is used on both global build config (BuildConfig.hooks) and
|
|
308
|
+
* per-output config (OutputConfig.hooks). All hooks are optional and support
|
|
309
|
+
* both sync and async functions.
|
|
310
|
+
*
|
|
311
|
+
* **Execution order:**
|
|
312
|
+
* 1. Global `onBuildStart`
|
|
313
|
+
* 2. For each output: per-output `onBuildStart` → process → per-output `onBuildEnd`
|
|
314
|
+
* 3. Global `onBuildEnd`
|
|
315
|
+
*/
|
|
316
|
+
type LifecycleHooks = {
|
|
317
|
+
/** Called before permutation resolution and output processing begins */
|
|
318
|
+
onBuildStart?: (context: {
|
|
319
|
+
config: unknown;
|
|
320
|
+
resolver: string | ResolverDocument;
|
|
321
|
+
}) => void | Promise<void>;
|
|
322
|
+
/** Called after all outputs have been processed (success or failure) */
|
|
323
|
+
onBuildEnd?: (result: BuildResult) => void | Promise<void>;
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* Function that generates an output file path based on modifier inputs.
|
|
327
|
+
*
|
|
328
|
+
* Used as the `file` property on OutputConfig and builder configs when
|
|
329
|
+
* the file name needs to vary per permutation.
|
|
330
|
+
*/
|
|
331
|
+
type FileFunction = (modifierInputs: ModifierInputs) => string;
|
|
332
|
+
/**
|
|
333
|
+
* Output configuration for a single build target
|
|
334
|
+
*
|
|
335
|
+
* Defines how tokens should be formatted and output for a specific target
|
|
336
|
+
* format (CSS, JSON, JavaScript, etc.).
|
|
337
|
+
*
|
|
338
|
+
* **Processing Order:**
|
|
339
|
+
* - Global filters (from BuildConfig) are applied first to all outputs
|
|
340
|
+
* - Then output-specific filters are applied (AND logic with global filters)
|
|
341
|
+
* - Global transforms are applied next
|
|
342
|
+
* - Finally output-specific transforms are applied
|
|
343
|
+
*
|
|
344
|
+
* **Output File Names:**
|
|
345
|
+
* The `file` field supports subdirectories and dynamic naming patterns.
|
|
346
|
+
* Parent directories are created automatically.
|
|
347
|
+
*
|
|
348
|
+
* @example Using builder helpers (recommended)
|
|
349
|
+
* ```typescript
|
|
350
|
+
* import { css, json } from 'dispersa'
|
|
351
|
+
* import { colorToHex, dimensionToPx } from 'dispersa/transforms'
|
|
352
|
+
*
|
|
353
|
+
* // CSS output with transforms
|
|
354
|
+
* css({
|
|
355
|
+
* name: 'css',
|
|
356
|
+
* file: 'css/tokens.css',
|
|
357
|
+
* preset: 'bundle',
|
|
358
|
+
* selector: ':root',
|
|
359
|
+
* transforms: [colorToHex(), dimensionToPx()],
|
|
360
|
+
* })
|
|
361
|
+
*
|
|
362
|
+
* // JSON output with static filename
|
|
363
|
+
* json({
|
|
364
|
+
* name: 'json',
|
|
365
|
+
* file: 'json/tokens.json',
|
|
366
|
+
* preset: 'standalone',
|
|
367
|
+
* structure: 'flat',
|
|
368
|
+
* })
|
|
369
|
+
* ```
|
|
370
|
+
*
|
|
371
|
+
* @example Pattern-based and function-based filenames
|
|
372
|
+
* ```typescript
|
|
373
|
+
* import { css } from 'dispersa'
|
|
374
|
+
*
|
|
375
|
+
* // Standalone mode with pattern-based filename
|
|
376
|
+
* css({
|
|
377
|
+
* name: 'css-standalone',
|
|
378
|
+
* file: 'tokens-{theme}-{platform}.css', // → tokens-light-web.css, tokens-dark-mobile.css
|
|
379
|
+
* preset: 'standalone',
|
|
380
|
+
* selector: ':root',
|
|
381
|
+
* })
|
|
382
|
+
*
|
|
383
|
+
* // Function-based filename
|
|
384
|
+
* css({
|
|
385
|
+
* name: 'css-custom',
|
|
386
|
+
* preset: 'standalone',
|
|
387
|
+
* selector: ':root',
|
|
388
|
+
* file: (modifierInputs) => {
|
|
389
|
+
* const parts = Object.entries(modifierInputs).map(([k, v]) => `${k}-${v}`)
|
|
390
|
+
* return `tokens-${parts.join('-')}.css`
|
|
391
|
+
* },
|
|
392
|
+
* })
|
|
393
|
+
* ```
|
|
394
|
+
*
|
|
395
|
+
* @see CssRendererOptions
|
|
396
|
+
* @see JsonRendererOptions
|
|
397
|
+
* @see JsModuleRendererOptions
|
|
398
|
+
*/
|
|
399
|
+
type OutputConfig<TOptions extends FormatOptions = FormatOptions> = {
|
|
400
|
+
/** Unique identifier for this output */
|
|
401
|
+
name: string;
|
|
402
|
+
/** Renderer instance (created via renderer factory function) */
|
|
403
|
+
renderer: Renderer<TOptions>;
|
|
404
|
+
/**
|
|
405
|
+
* Array of filter objects to apply
|
|
406
|
+
* Filters are applied before transforms (to select which tokens to process)
|
|
407
|
+
*/
|
|
408
|
+
filters?: Filter[];
|
|
409
|
+
/** Array of transform objects to apply */
|
|
410
|
+
transforms?: Transform[];
|
|
411
|
+
/**
|
|
412
|
+
* Output file path, can be static or dynamic
|
|
413
|
+
*
|
|
414
|
+
* Supports subdirectories (e.g., "css/tokens.css").
|
|
415
|
+
* In standalone preset (one file per permutation), supports:
|
|
416
|
+
* - Pattern strings with placeholders: `tokens-{theme}-{platform}.css`
|
|
417
|
+
* - Function that receives modifierInputs: `(modifierInputs) => \`tokens-${...}.css\``
|
|
418
|
+
* - Plain string (applies default pattern with all modifiers)
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```typescript
|
|
422
|
+
* // Static filename (bundle preset or single permutation)
|
|
423
|
+
* file: 'tokens.css'
|
|
424
|
+
*
|
|
425
|
+
* // With subdirectory
|
|
426
|
+
* file: 'css/tokens.css'
|
|
427
|
+
*
|
|
428
|
+
* // Pattern with placeholders (standalone preset)
|
|
429
|
+
* file: 'tokens-{theme}-{platform}.css'
|
|
430
|
+
*
|
|
431
|
+
* // Function for complex logic (standalone preset)
|
|
432
|
+
* file: (modifierInputs) => {
|
|
433
|
+
* const parts = Object.entries(modifierInputs).map(([k, v]) => `${k}-${v}`)
|
|
434
|
+
* return `output/${parts.join('-')}/tokens.css`
|
|
435
|
+
* }
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
file?: string | FileFunction;
|
|
439
|
+
/**
|
|
440
|
+
* Renderer-specific options passed to the formatter.
|
|
441
|
+
*/
|
|
442
|
+
options?: TOptions;
|
|
443
|
+
/**
|
|
444
|
+
* Lifecycle hooks for this output.
|
|
445
|
+
*
|
|
446
|
+
* Per-output hooks fire in addition to global hooks on BuildConfig.
|
|
447
|
+
* `onBuildStart` fires before this output is processed,
|
|
448
|
+
* `onBuildEnd` fires after this output finishes (success or failure).
|
|
449
|
+
*/
|
|
450
|
+
hooks?: LifecycleHooks;
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
export { type BuildError as B, type CssRendererOptions as C, type ErrorCode as E, type FileFunction as F, type LifecycleHooks as L, type MediaQueryFunction as M, type OutputConfig as O, type PermutationData as P, type Renderer as R, type SelectorFunction as S, type BuildOutput as a, type BuildResult as b, type FormatOptions as c, type OutputTree as d, type RenderContext as e, type RenderMeta as f, type RenderOutput as g, type ModifierInputs as h, type ResolverDocument as i, defineRenderer as j };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { K as InternalTokenDocument } from './types-TQHV1MrY.cjs';
|
|
2
|
+
import { P as PreprocessorPluginBase } from './config-schemas-DnEBhIg0.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Preprocessor system types for raw token transformation
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Preprocessor definition for transforming raw token data
|
|
10
|
+
*
|
|
11
|
+
* Preprocessors operate on the raw token object before parsing and resolution.
|
|
12
|
+
* They are useful for normalizing data, stripping metadata, or adapting tokens
|
|
13
|
+
* from external sources to match expected formats.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const stripMetadata: Preprocessor = {
|
|
18
|
+
* name: 'strip-metadata',
|
|
19
|
+
* preprocess: (rawTokens) => {
|
|
20
|
+
* const { _metadata, ...tokens } = rawTokens
|
|
21
|
+
* return tokens
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
type Preprocessor = Pick<PreprocessorPluginBase, 'name'> & {
|
|
27
|
+
/**
|
|
28
|
+
* Function that transforms raw token data
|
|
29
|
+
*
|
|
30
|
+
* @param rawTokens - Raw token object before parsing
|
|
31
|
+
* @returns Transformed token object (can be async)
|
|
32
|
+
*/
|
|
33
|
+
preprocess: (rawTokens: InternalTokenDocument) => InternalTokenDocument | Promise<InternalTokenDocument>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type { Preprocessor as P };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { K as InternalTokenDocument } from './types-TQHV1MrY.js';
|
|
2
|
+
import { P as PreprocessorPluginBase } from './config-schemas-DnEBhIg0.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Preprocessor system types for raw token transformation
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Preprocessor definition for transforming raw token data
|
|
10
|
+
*
|
|
11
|
+
* Preprocessors operate on the raw token object before parsing and resolution.
|
|
12
|
+
* They are useful for normalizing data, stripping metadata, or adapting tokens
|
|
13
|
+
* from external sources to match expected formats.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const stripMetadata: Preprocessor = {
|
|
18
|
+
* name: 'strip-metadata',
|
|
19
|
+
* preprocess: (rawTokens) => {
|
|
20
|
+
* const { _metadata, ...tokens } = rawTokens
|
|
21
|
+
* return tokens
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
type Preprocessor = Pick<PreprocessorPluginBase, 'name'> & {
|
|
27
|
+
/**
|
|
28
|
+
* Function that transforms raw token data
|
|
29
|
+
*
|
|
30
|
+
* @param rawTokens - Raw token object before parsing
|
|
31
|
+
* @returns Transformed token object (can be async)
|
|
32
|
+
*/
|
|
33
|
+
preprocess: (rawTokens: InternalTokenDocument) => InternalTokenDocument | Promise<InternalTokenDocument>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type { Preprocessor as P };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dispersa",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Core library for processing DTCG design tokens",
|
|
5
5
|
"author": "Tim Gesemann",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,62 +48,52 @@
|
|
|
48
48
|
},
|
|
49
49
|
"./transforms": {
|
|
50
50
|
"import": {
|
|
51
|
-
"types": "./dist/transforms.d.ts",
|
|
52
|
-
"default": "./dist/transforms.js"
|
|
51
|
+
"types": "./dist/processing/transforms/index.d.ts",
|
|
52
|
+
"default": "./dist/processing/transforms/index.js"
|
|
53
53
|
},
|
|
54
54
|
"require": {
|
|
55
|
-
"types": "./dist/transforms.d.cts",
|
|
56
|
-
"default": "./dist/transforms.cjs"
|
|
55
|
+
"types": "./dist/processing/transforms/index.d.cts",
|
|
56
|
+
"default": "./dist/processing/transforms/index.cjs"
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
"./filters": {
|
|
60
60
|
"import": {
|
|
61
|
-
"types": "./dist/filters.d.ts",
|
|
62
|
-
"default": "./dist/filters.js"
|
|
61
|
+
"types": "./dist/processing/filters/index.d.ts",
|
|
62
|
+
"default": "./dist/processing/filters/index.js"
|
|
63
63
|
},
|
|
64
64
|
"require": {
|
|
65
|
-
"types": "./dist/filters.d.cts",
|
|
66
|
-
"default": "./dist/filters.cjs"
|
|
65
|
+
"types": "./dist/processing/filters/index.d.cts",
|
|
66
|
+
"default": "./dist/processing/filters/index.cjs"
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
|
-
"./
|
|
69
|
+
"./outputs": {
|
|
70
70
|
"import": {
|
|
71
|
-
"types": "./dist/
|
|
72
|
-
"default": "./dist/
|
|
71
|
+
"types": "./dist/outputs/index.d.ts",
|
|
72
|
+
"default": "./dist/outputs/index.js"
|
|
73
73
|
},
|
|
74
74
|
"require": {
|
|
75
|
-
"types": "./dist/
|
|
76
|
-
"default": "./dist/
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
"./renderers": {
|
|
80
|
-
"import": {
|
|
81
|
-
"types": "./dist/renderers.d.ts",
|
|
82
|
-
"default": "./dist/renderers.js"
|
|
83
|
-
},
|
|
84
|
-
"require": {
|
|
85
|
-
"types": "./dist/renderers.d.cts",
|
|
86
|
-
"default": "./dist/renderers.cjs"
|
|
75
|
+
"types": "./dist/outputs/index.d.cts",
|
|
76
|
+
"default": "./dist/outputs/index.cjs"
|
|
87
77
|
}
|
|
88
78
|
},
|
|
89
79
|
"./preprocessors": {
|
|
90
80
|
"import": {
|
|
91
|
-
"types": "./dist/preprocessors.d.ts",
|
|
92
|
-
"default": "./dist/preprocessors.js"
|
|
81
|
+
"types": "./dist/processing/preprocessors/index.d.ts",
|
|
82
|
+
"default": "./dist/processing/preprocessors/index.js"
|
|
93
83
|
},
|
|
94
84
|
"require": {
|
|
95
|
-
"types": "./dist/preprocessors.d.cts",
|
|
96
|
-
"default": "./dist/preprocessors.cjs"
|
|
85
|
+
"types": "./dist/processing/preprocessors/index.d.cts",
|
|
86
|
+
"default": "./dist/processing/preprocessors/index.cjs"
|
|
97
87
|
}
|
|
98
88
|
},
|
|
99
89
|
"./errors": {
|
|
100
90
|
"import": {
|
|
101
|
-
"types": "./dist/errors.d.ts",
|
|
102
|
-
"default": "./dist/errors.js"
|
|
91
|
+
"types": "./dist/shared/errors/index.d.ts",
|
|
92
|
+
"default": "./dist/shared/errors/index.js"
|
|
103
93
|
},
|
|
104
94
|
"require": {
|
|
105
|
-
"types": "./dist/errors.d.cts",
|
|
106
|
-
"default": "./dist/errors.cjs"
|
|
95
|
+
"types": "./dist/shared/errors/index.d.cts",
|
|
96
|
+
"default": "./dist/shared/errors/index.cjs"
|
|
107
97
|
}
|
|
108
98
|
},
|
|
109
99
|
"./config": {
|
|
@@ -120,12 +110,12 @@
|
|
|
120
110
|
},
|
|
121
111
|
"./lint": {
|
|
122
112
|
"import": {
|
|
123
|
-
"types": "./dist/lint.d.ts",
|
|
124
|
-
"default": "./dist/lint.js"
|
|
113
|
+
"types": "./dist/lint/index.d.ts",
|
|
114
|
+
"default": "./dist/lint/index.js"
|
|
125
115
|
},
|
|
126
116
|
"require": {
|
|
127
|
-
"types": "./dist/lint.d.cts",
|
|
128
|
-
"default": "./dist/lint.cjs"
|
|
117
|
+
"types": "./dist/lint/index.d.cts",
|
|
118
|
+
"default": "./dist/lint/index.cjs"
|
|
129
119
|
}
|
|
130
120
|
}
|
|
131
121
|
},
|