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
package/dist/index-Dajm5rvM.d.ts
DELETED
|
@@ -1,895 +0,0 @@
|
|
|
1
|
-
import { c as TokenType, L as InternalResolvedTokens, R as ResolvedToken, a as ResolvedTokens } from './types-TQHV1MrY.js';
|
|
2
|
-
import { F as Filter } from './types-ebxDimRz.js';
|
|
3
|
-
import { B as BuildConfigBase, O as OutputConfigBase, P as Preprocessor, D as DispersaOptionsBase } from './types-8MLtztK3.js';
|
|
4
|
-
import { T as Transform } from './types-DztXKlka.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @license MIT
|
|
8
|
-
* Copyright (c) 2025-present Dispersa
|
|
9
|
-
*
|
|
10
|
-
* This source code is licensed under the MIT license found in the
|
|
11
|
-
* LICENSE file in the root directory of this source tree.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* @fileoverview Core type definitions for the Dispersa linting system
|
|
15
|
-
*
|
|
16
|
-
* Inspired by ESLint and Terrazzo, this system provides a plugin-based
|
|
17
|
-
* architecture for validating design tokens against semantic rules.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Lint rule severity levels
|
|
22
|
-
*
|
|
23
|
-
* - `'off'` - Rule is disabled
|
|
24
|
-
* - `'warn'` - Rule issues warnings but doesn't fail the build
|
|
25
|
-
* - `'error'` - Rule issues errors and fails the build (if failOnError is true)
|
|
26
|
-
*/
|
|
27
|
-
type Severity = 'off' | 'warn' | 'error';
|
|
28
|
-
/**
|
|
29
|
-
* Metadata describing a lint rule
|
|
30
|
-
*
|
|
31
|
-
* @template MessageIds - Union type of message IDs this rule can produce
|
|
32
|
-
*/
|
|
33
|
-
type LintRuleMeta<MessageIds extends string = string> = {
|
|
34
|
-
/** Short name of the rule (e.g., 'require-description') */
|
|
35
|
-
name: string;
|
|
36
|
-
/** Human-readable description of what the rule checks */
|
|
37
|
-
description: string;
|
|
38
|
-
/** Optional URL to documentation for this rule */
|
|
39
|
-
url?: string;
|
|
40
|
-
/** Map of message IDs to message templates (supports {{placeholder}} interpolation) */
|
|
41
|
-
messages: Record<MessageIds, string>;
|
|
42
|
-
/** Token types this rule applies to. Default: 'all' */
|
|
43
|
-
appliesTo?: TokenType[] | 'all';
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Context object passed to rule's create() function
|
|
47
|
-
*
|
|
48
|
-
* Provides access to tokens, configuration, and the report function.
|
|
49
|
-
*
|
|
50
|
-
* @template MessageIds - Union type of message IDs this rule can produce
|
|
51
|
-
* @template Options - Rule-specific options type
|
|
52
|
-
*/
|
|
53
|
-
type LintRuleContext<MessageIds extends string = string, Options extends Record<string, unknown> = Record<string, never>> = {
|
|
54
|
-
/** Fully qualified rule ID (e.g., 'dispersa/require-description') */
|
|
55
|
-
id: string;
|
|
56
|
-
/** Merged options (defaultOptions + user config) */
|
|
57
|
-
options: Options;
|
|
58
|
-
/** All resolved tokens to validate */
|
|
59
|
-
tokens: InternalResolvedTokens;
|
|
60
|
-
/**
|
|
61
|
-
* Report a lint issue
|
|
62
|
-
*
|
|
63
|
-
* @param descriptor - Issue descriptor with token, message ID, and optional data
|
|
64
|
-
*/
|
|
65
|
-
report(descriptor: LintReportDescriptor<MessageIds>): void;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Descriptor for reporting a lint issue
|
|
69
|
-
*
|
|
70
|
-
* @template MessageIds - Union type of message IDs this rule can produce
|
|
71
|
-
*/
|
|
72
|
-
type LintReportDescriptor<MessageIds extends string = string> = {
|
|
73
|
-
/** The token that has the issue */
|
|
74
|
-
token: ResolvedToken;
|
|
75
|
-
/** ID of the message to use from rule's meta.messages */
|
|
76
|
-
messageId: MessageIds;
|
|
77
|
-
/** Data to interpolate into the message (replaces {{key}} placeholders) */
|
|
78
|
-
data?: Record<string, string | number>;
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* A lint rule definition
|
|
82
|
-
*
|
|
83
|
-
* Rules are created using the `createRule()` factory function for type safety.
|
|
84
|
-
*
|
|
85
|
-
* @template MessageIds - Union type of message IDs this rule can produce
|
|
86
|
-
* @template Options - Rule-specific options type
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* const myRule: LintRule<'MISSING_VALUE', { required: boolean }> = {
|
|
91
|
-
* meta: {
|
|
92
|
-
* name: 'require-value',
|
|
93
|
-
* description: 'Require tokens to have values',
|
|
94
|
-
* messages: {
|
|
95
|
-
* MISSING_VALUE: "Token '{{name}}' is missing a value",
|
|
96
|
-
* },
|
|
97
|
-
* },
|
|
98
|
-
* defaultOptions: { required: true },
|
|
99
|
-
* create({ tokens, report, options }) {
|
|
100
|
-
* for (const token of Object.values(tokens)) {
|
|
101
|
-
* if (options.required && !token.$value) {
|
|
102
|
-
* report({ token, messageId: 'MISSING_VALUE', data: { name: token.name } })
|
|
103
|
-
* }
|
|
104
|
-
* }
|
|
105
|
-
* },
|
|
106
|
-
* }
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
type LintRule<MessageIds extends string = string, Options extends Record<string, unknown> = Record<string, never>> = {
|
|
110
|
-
/** Rule metadata */
|
|
111
|
-
meta: LintRuleMeta<MessageIds>;
|
|
112
|
-
/** Default options merged with user config */
|
|
113
|
-
defaultOptions?: Options;
|
|
114
|
-
/**
|
|
115
|
-
* Factory function that creates the rule's validation logic
|
|
116
|
-
*
|
|
117
|
-
* Called once per lint run with the context object.
|
|
118
|
-
*
|
|
119
|
-
* @param context - Rule context with tokens, options, and report function
|
|
120
|
-
*/
|
|
121
|
-
create(context: LintRuleContext<MessageIds, Options>): void | Promise<void>;
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* Base rule type without generic parameters for use in plugin definitions
|
|
125
|
-
*/
|
|
126
|
-
type AnyLintRule = LintRule<string, Record<string, unknown>>;
|
|
127
|
-
/**
|
|
128
|
-
* A lint plugin that provides rules and configurations
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```typescript
|
|
132
|
-
* const myPlugin: LintPlugin = {
|
|
133
|
-
* meta: {
|
|
134
|
-
* name: 'my-lint-plugin',
|
|
135
|
-
* version: '1.0.0',
|
|
136
|
-
* },
|
|
137
|
-
* rules: {
|
|
138
|
-
* 'my-rule': myRule,
|
|
139
|
-
* },
|
|
140
|
-
* configs: {
|
|
141
|
-
* recommended: {
|
|
142
|
-
* plugins: { my: myPlugin },
|
|
143
|
-
* rules: {
|
|
144
|
-
* 'my/my-rule': 'warn',
|
|
145
|
-
* },
|
|
146
|
-
* },
|
|
147
|
-
* },
|
|
148
|
-
* }
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
|
-
type LintPlugin = {
|
|
152
|
-
/** Plugin metadata */
|
|
153
|
-
meta: {
|
|
154
|
-
/** Package name (e.g., '@dispersa/lint-plugin-a11y') */
|
|
155
|
-
name: string;
|
|
156
|
-
/** Semantic version (optional, for debugging/metadata) */
|
|
157
|
-
version?: string;
|
|
158
|
-
};
|
|
159
|
-
/** Rules provided by this plugin */
|
|
160
|
-
rules: Record<string, AnyLintRule>;
|
|
161
|
-
/** Predefined configurations */
|
|
162
|
-
configs?: Record<string, LintConfig>;
|
|
163
|
-
};
|
|
164
|
-
/**
|
|
165
|
-
* Rule configuration - either severity only or severity with options
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* ```typescript
|
|
169
|
-
* // Severity only
|
|
170
|
-
* 'error'
|
|
171
|
-
*
|
|
172
|
-
* // Severity with options
|
|
173
|
-
* ['error', { format: 'kebab-case' }]
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
type RuleConfig = Severity | [Severity, Record<string, unknown>];
|
|
177
|
-
/**
|
|
178
|
-
* Resolved rule configuration with parsed severity and options
|
|
179
|
-
*/
|
|
180
|
-
type ResolvedRuleConfig = {
|
|
181
|
-
severity: Exclude<Severity, 'off'>;
|
|
182
|
-
options: Record<string, unknown>;
|
|
183
|
-
};
|
|
184
|
-
/**
|
|
185
|
-
* Registry for lint rule options types.
|
|
186
|
-
*
|
|
187
|
-
* Built-in dispersa rules are registered via declaration merging in `./rules/index.ts`.
|
|
188
|
-
* Plugin authors can augment this interface to add their own rule types:
|
|
189
|
-
*
|
|
190
|
-
* @example
|
|
191
|
-
* ```typescript
|
|
192
|
-
* // In your plugin file
|
|
193
|
-
* declare module 'dispersa/lint' {
|
|
194
|
-
* interface RulesRegistry {
|
|
195
|
-
* 'my-plugin/my-rule': MyRuleOptions
|
|
196
|
-
* }
|
|
197
|
-
* }
|
|
198
|
-
* ```
|
|
199
|
-
*/
|
|
200
|
-
interface RulesRegistry {
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Type-safe configuration for a single rule from the registry.
|
|
204
|
-
*
|
|
205
|
-
* @template K - The rule ID key from RulesRegistry
|
|
206
|
-
*/
|
|
207
|
-
type RuleConfigFor<K extends keyof RulesRegistry> = Severity | [Severity, RulesRegistry[K]];
|
|
208
|
-
/**
|
|
209
|
-
* Typed rules configuration with intellisense for all registered rules.
|
|
210
|
-
*
|
|
211
|
-
* Provides autocomplete for rule IDs and their option types.
|
|
212
|
-
* Also allows arbitrary string keys for unregistered rules.
|
|
213
|
-
*/
|
|
214
|
-
type TypedRulesConfig = {
|
|
215
|
-
[K in keyof RulesRegistry]?: RuleConfigFor<K>;
|
|
216
|
-
} & Record<string, RuleConfig>;
|
|
217
|
-
/**
|
|
218
|
-
* Lint configuration
|
|
219
|
-
*
|
|
220
|
-
* @template Rules - Rules configuration type (defaults to TypedRulesConfig for intellisense)
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```typescript
|
|
224
|
-
* const config: LintConfig = {
|
|
225
|
-
* plugins: {
|
|
226
|
-
* dispersa: dispersaPlugin,
|
|
227
|
-
* a11y: '@dispersa/lint-plugin-a11y', // Load by string
|
|
228
|
-
* },
|
|
229
|
-
* rules: {
|
|
230
|
-
* 'dispersa/require-description': 'warn',
|
|
231
|
-
* 'dispersa/naming-convention': ['error', { format: 'kebab-case' }],
|
|
232
|
-
* 'a11y/min-contrast': ['error', { level: 'AA' }],
|
|
233
|
-
* },
|
|
234
|
-
* }
|
|
235
|
-
* ```
|
|
236
|
-
*/
|
|
237
|
-
type LintConfig<Rules extends Record<string, RuleConfig> = TypedRulesConfig> = {
|
|
238
|
-
/** Plugins to load (by object or module path string) */
|
|
239
|
-
plugins?: Record<string, LintPlugin | string>;
|
|
240
|
-
/** Rule configurations */
|
|
241
|
-
rules?: Rules;
|
|
242
|
-
/** Fail build on lint errors (default: true) */
|
|
243
|
-
failOnError?: boolean;
|
|
244
|
-
};
|
|
245
|
-
/**
|
|
246
|
-
* Configuration for lint within BuildConfig
|
|
247
|
-
*
|
|
248
|
-
* Extends {@link LintConfig} with an `enabled` toggle for opt-in build integration.
|
|
249
|
-
*
|
|
250
|
-
* @template Rules - Rules configuration type (defaults to TypedRulesConfig for intellisense)
|
|
251
|
-
*/
|
|
252
|
-
type LintBuildConfig<Rules extends Record<string, RuleConfig> = TypedRulesConfig> = LintConfig<Rules> & {
|
|
253
|
-
/** Enable linting (default: false, opt-in) */
|
|
254
|
-
enabled?: boolean;
|
|
255
|
-
};
|
|
256
|
-
/**
|
|
257
|
-
* Resolved lint configuration with all plugins loaded
|
|
258
|
-
*/
|
|
259
|
-
type ResolvedLintConfig = {
|
|
260
|
-
/** Whether linting is enabled */
|
|
261
|
-
enabled: boolean;
|
|
262
|
-
/** Fail build on errors */
|
|
263
|
-
failOnError: boolean;
|
|
264
|
-
/** Loaded plugins indexed by namespace */
|
|
265
|
-
plugins: Record<string, LintPlugin>;
|
|
266
|
-
/** Resolved rule configurations */
|
|
267
|
-
rules: Record<string, ResolvedRuleConfig>;
|
|
268
|
-
};
|
|
269
|
-
/**
|
|
270
|
-
* A single lint issue
|
|
271
|
-
*/
|
|
272
|
-
type LintIssue = {
|
|
273
|
-
/** Fully qualified rule ID (e.g., 'dispersa/require-description') */
|
|
274
|
-
ruleId: string;
|
|
275
|
-
/** Issue severity */
|
|
276
|
-
severity: Exclude<Severity, 'off'>;
|
|
277
|
-
/** Human-readable message */
|
|
278
|
-
message: string;
|
|
279
|
-
/** Token name (e.g., 'color.brand.primary') */
|
|
280
|
-
tokenName: string;
|
|
281
|
-
/** Token path segments (e.g., ['color', 'brand', 'primary']) */
|
|
282
|
-
tokenPath: string[];
|
|
283
|
-
};
|
|
284
|
-
/**
|
|
285
|
-
* Result of a lint run
|
|
286
|
-
*/
|
|
287
|
-
type LintResult = {
|
|
288
|
-
/** All issues found */
|
|
289
|
-
issues: LintIssue[];
|
|
290
|
-
/** Count of error-severity issues */
|
|
291
|
-
errorCount: number;
|
|
292
|
-
/** Count of warning-severity issues */
|
|
293
|
-
warningCount: number;
|
|
294
|
-
};
|
|
295
|
-
/**
|
|
296
|
-
* Output format for lint results
|
|
297
|
-
*/
|
|
298
|
-
type LintOutputFormat = 'json' | 'stylish' | 'compact';
|
|
299
|
-
/**
|
|
300
|
-
* Formatter function that converts lint result to output string
|
|
301
|
-
*/
|
|
302
|
-
type LintFormatter = (result: LintResult) => string;
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* @fileoverview DTCG Resolver types (2025.10 specification)
|
|
306
|
-
*
|
|
307
|
-
* The resolver system allows defining token sources, modifiers (themes, modes),
|
|
308
|
-
* and the order in which they should be resolved and merged.
|
|
309
|
-
*
|
|
310
|
-
* ResolverDocument type is defined here to match DTCG 2025.10.
|
|
311
|
-
*/
|
|
312
|
-
type ReferenceObject = {
|
|
313
|
-
$ref: string;
|
|
314
|
-
};
|
|
315
|
-
type TokenSource = ReferenceObject | Record<string, unknown>;
|
|
316
|
-
type Set = {
|
|
317
|
-
sources: TokenSource[];
|
|
318
|
-
description?: string;
|
|
319
|
-
$extensions?: Record<string, unknown>;
|
|
320
|
-
};
|
|
321
|
-
type Modifier = {
|
|
322
|
-
contexts: Record<string, TokenSource[]>;
|
|
323
|
-
description?: string;
|
|
324
|
-
default?: string;
|
|
325
|
-
$extensions?: Record<string, unknown>;
|
|
326
|
-
};
|
|
327
|
-
type InlineSet = Set & {
|
|
328
|
-
name: string;
|
|
329
|
-
type: 'set';
|
|
330
|
-
};
|
|
331
|
-
type InlineModifier = Modifier & {
|
|
332
|
-
name: string;
|
|
333
|
-
type: 'modifier';
|
|
334
|
-
};
|
|
335
|
-
type ResolverDocument = {
|
|
336
|
-
$schema?: string;
|
|
337
|
-
name?: string;
|
|
338
|
-
version: '2025.10';
|
|
339
|
-
description?: string;
|
|
340
|
-
sets?: Record<string, Set>;
|
|
341
|
-
modifiers?: Record<string, Modifier>;
|
|
342
|
-
resolutionOrder: (ReferenceObject | InlineSet | InlineModifier)[];
|
|
343
|
-
$defs?: Record<string, unknown>;
|
|
344
|
-
};
|
|
345
|
-
/**
|
|
346
|
-
* Map of modifier names to selected context values
|
|
347
|
-
*
|
|
348
|
-
* Used to specify which variation of each modifier to use when resolving tokens.
|
|
349
|
-
* Can be made type-safe by providing a generic type parameter.
|
|
350
|
-
*
|
|
351
|
-
* @template T - Optional specific type for modifier values (defaults to generic Record)
|
|
352
|
-
*
|
|
353
|
-
* @example
|
|
354
|
-
* ```typescript
|
|
355
|
-
* // Generic (default):
|
|
356
|
-
* const inputs: ModifierInputs = {
|
|
357
|
-
* theme: 'dark',
|
|
358
|
-
* platform: 'mobile'
|
|
359
|
-
* }
|
|
360
|
-
*
|
|
361
|
-
* // Type-safe:
|
|
362
|
-
* type MyModifiers = { theme: 'light' | 'dark', platform: 'web' | 'mobile' }
|
|
363
|
-
* const inputs: ModifierInputs<MyModifiers> = {
|
|
364
|
-
* theme: 'dark', // ✅ Autocomplete!
|
|
365
|
-
* platform: 'mobile'
|
|
366
|
-
* }
|
|
367
|
-
* ```
|
|
368
|
-
*/
|
|
369
|
-
type ModifierInputs<T extends Record<string, string> = Record<string, string>> = T;
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* @fileoverview Renderer system types for token output generation
|
|
373
|
-
*
|
|
374
|
-
* Note: renderers/types and config have a mutual type-only dependency.
|
|
375
|
-
* RenderContext references OutputConfig, while OutputConfig references
|
|
376
|
-
* Renderer/FormatOptions. This is acceptable because type imports are
|
|
377
|
-
* erased at runtime and the coupling is genuine.
|
|
378
|
-
*/
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Generic options object for renderers
|
|
382
|
-
*
|
|
383
|
-
* Each renderer can define its own specific options that extend this base type.
|
|
384
|
-
*/
|
|
385
|
-
type FormatOptions = Record<string, unknown>;
|
|
386
|
-
/**
|
|
387
|
-
* Data for a single permutation (combination of modifier values)
|
|
388
|
-
*/
|
|
389
|
-
type PermutationData = {
|
|
390
|
-
tokens: ResolvedTokens;
|
|
391
|
-
modifierInputs: ModifierInputs;
|
|
392
|
-
};
|
|
393
|
-
/**
|
|
394
|
-
* Metadata for renderers to reason about modifier dimensions.
|
|
395
|
-
*/
|
|
396
|
-
type RenderMeta = {
|
|
397
|
-
dimensions: string[];
|
|
398
|
-
defaults: Record<string, string>;
|
|
399
|
-
basePermutation: ModifierInputs;
|
|
400
|
-
};
|
|
401
|
-
/**
|
|
402
|
-
* Context provided to renderer formatters.
|
|
403
|
-
*/
|
|
404
|
-
type RenderContext<TOptions extends FormatOptions = FormatOptions> = {
|
|
405
|
-
permutations: PermutationData[];
|
|
406
|
-
output: OutputConfig<TOptions>;
|
|
407
|
-
resolver: ResolverDocument;
|
|
408
|
-
meta: RenderMeta;
|
|
409
|
-
buildPath?: string;
|
|
410
|
-
};
|
|
411
|
-
/**
|
|
412
|
-
* Multi-file output representation for renderers.
|
|
413
|
-
*/
|
|
414
|
-
type OutputTree = {
|
|
415
|
-
kind: 'outputTree';
|
|
416
|
-
files: Record<string, string>;
|
|
417
|
-
};
|
|
418
|
-
type RenderOutput = string | OutputTree;
|
|
419
|
-
/**
|
|
420
|
-
* Output from a build operation
|
|
421
|
-
*/
|
|
422
|
-
type BuildOutput = {
|
|
423
|
-
name: string;
|
|
424
|
-
/** File path where output was written (undefined for in-memory mode) */
|
|
425
|
-
path?: string;
|
|
426
|
-
content: string;
|
|
427
|
-
};
|
|
428
|
-
/**
|
|
429
|
-
* Renderer definition for converting tokens to output format
|
|
430
|
-
*
|
|
431
|
-
* Renderers implement a single `format()` method that can return either
|
|
432
|
-
* a single string or an OutputTree for multi-file outputs.
|
|
433
|
-
*
|
|
434
|
-
* @example Simple renderer with format()
|
|
435
|
-
* ```typescript
|
|
436
|
-
* const scssRenderer: Renderer = {
|
|
437
|
-
* format: (context) => {
|
|
438
|
-
* const tokens = context.permutations[0]?.tokens ?? {}
|
|
439
|
-
* return Object.entries(tokens)
|
|
440
|
-
* .map(([name, token]) => `$${name}: ${token.$value};`)
|
|
441
|
-
* .join('\n')
|
|
442
|
-
* },
|
|
443
|
-
* }
|
|
444
|
-
* ```
|
|
445
|
-
*/
|
|
446
|
-
type Renderer<TOptions extends FormatOptions = FormatOptions> = {
|
|
447
|
-
/**
|
|
448
|
-
* Preset identifier (e.g., 'bundle', 'standalone', 'modifier')
|
|
449
|
-
* Indicates which variant of the renderer this is
|
|
450
|
-
*/
|
|
451
|
-
preset?: string;
|
|
452
|
-
/**
|
|
453
|
-
* Convert tokens to output content.
|
|
454
|
-
*
|
|
455
|
-
* Renderers receive all resolved permutations and modifier metadata via context.
|
|
456
|
-
* They can return either a single string (single output file) or an OutputTree
|
|
457
|
-
* for multi-file outputs.
|
|
458
|
-
*/
|
|
459
|
-
format: (context: RenderContext<TOptions>, options?: TOptions) => RenderOutput | Promise<RenderOutput>;
|
|
460
|
-
};
|
|
461
|
-
/**
|
|
462
|
-
* Helper for defining custom renderers with full type inference.
|
|
463
|
-
*
|
|
464
|
-
* Works like Vue's `defineComponent()` or Vite's `defineConfig()` --
|
|
465
|
-
* an identity function that enables TypeScript to infer the options type
|
|
466
|
-
* from the generic parameter, giving you autocomplete and type-checking
|
|
467
|
-
* on both `context` and `options` inside `format()`.
|
|
468
|
-
*
|
|
469
|
-
* @example
|
|
470
|
-
* ```typescript
|
|
471
|
-
* import { defineRenderer } from 'dispersa/renderers'
|
|
472
|
-
*
|
|
473
|
-
* type MyOptions = { prefix: string; minify?: boolean }
|
|
474
|
-
*
|
|
475
|
-
* const myRenderer = defineRenderer<MyOptions>({
|
|
476
|
-
* format(context, options) {
|
|
477
|
-
* // options is typed as MyOptions | undefined
|
|
478
|
-
* // context.output.options is typed as MyOptions | undefined
|
|
479
|
-
* const prefix = options?.prefix ?? 'token'
|
|
480
|
-
* return Object.entries(context.permutations[0]?.tokens ?? {})
|
|
481
|
-
* .map(([name, token]) => `${prefix}-${name}: ${token.$value}`)
|
|
482
|
-
* .join('\n')
|
|
483
|
-
* },
|
|
484
|
-
* })
|
|
485
|
-
* ```
|
|
486
|
-
*/
|
|
487
|
-
declare function defineRenderer<T extends FormatOptions>(renderer: Renderer<T>): Renderer<T>;
|
|
488
|
-
/**
|
|
489
|
-
* Function type for dynamically generating CSS selectors based on modifier context
|
|
490
|
-
*
|
|
491
|
-
* @param modifierName - Name of the modifier (e.g., 'theme', 'breakpoint')
|
|
492
|
-
* @param context - Context value of the modifier (e.g., 'dark', 'mobile')
|
|
493
|
-
* @param isBase - Whether this is the base permutation
|
|
494
|
-
* @param allModifierInputs - All modifier inputs for this permutation
|
|
495
|
-
* @returns CSS selector string (e.g., '[data-theme="dark"]')
|
|
496
|
-
*/
|
|
497
|
-
type SelectorFunction = (modifierName: string, context: string, isBase: boolean, allModifierInputs: Record<string, string>) => string;
|
|
498
|
-
/**
|
|
499
|
-
* Function type for dynamically generating media queries based on modifier context
|
|
500
|
-
*
|
|
501
|
-
* @param modifierName - Name of the modifier (e.g., 'theme', 'breakpoint')
|
|
502
|
-
* @param context - Context value of the modifier (e.g., 'dark', 'mobile')
|
|
503
|
-
* @param isBase - Whether this is the base permutation
|
|
504
|
-
* @param allModifierInputs - All modifier inputs for this permutation
|
|
505
|
-
* @returns Media query string (e.g., '(max-width: 768px)') or empty string for no media query
|
|
506
|
-
*/
|
|
507
|
-
type MediaQueryFunction = (modifierName: string, context: string, isBase: boolean, allModifierInputs: Record<string, string>) => string;
|
|
508
|
-
/**
|
|
509
|
-
* Options for CSS custom properties renderer
|
|
510
|
-
*
|
|
511
|
-
* Controls how tokens are converted to CSS custom properties (CSS variables).
|
|
512
|
-
*
|
|
513
|
-
* **Note:** Token naming is controlled through transforms, not renderer options.
|
|
514
|
-
* Use `nameKebabCase()` and `namePrefix()` for naming control.
|
|
515
|
-
*
|
|
516
|
-
* @example String-based selectors
|
|
517
|
-
* ```typescript
|
|
518
|
-
* css({
|
|
519
|
-
* name: 'tokens',
|
|
520
|
-
* file: 'tokens.css',
|
|
521
|
-
* transforms: [nameKebabCase(), namePrefix('ds-')],
|
|
522
|
-
* preset: 'bundle',
|
|
523
|
-
* selector: ':root',
|
|
524
|
-
* })
|
|
525
|
-
* ```
|
|
526
|
-
*
|
|
527
|
-
* @example Function-based selectors
|
|
528
|
-
* ```typescript
|
|
529
|
-
* outputs: [{
|
|
530
|
-
* renderer: cssRenderer(),
|
|
531
|
-
* options: {
|
|
532
|
-
* preset: 'bundle',
|
|
533
|
-
* selector: (modifier, context, isBase, allInputs) => {
|
|
534
|
-
* if (isBase) return ':root'
|
|
535
|
-
* return `[data-${modifier}="${context}"]`
|
|
536
|
-
* },
|
|
537
|
-
* mediaQuery: (modifier, context) => {
|
|
538
|
-
* if (modifier === 'breakpoint' && context === 'mobile') {
|
|
539
|
-
* return '(max-width: 768px)'
|
|
540
|
-
* }
|
|
541
|
-
* return ''
|
|
542
|
-
* }
|
|
543
|
-
* }
|
|
544
|
-
* }]
|
|
545
|
-
* ```
|
|
546
|
-
*/
|
|
547
|
-
type CssRendererOptions = {
|
|
548
|
-
preset?: 'bundle' | 'standalone' | 'modifier';
|
|
549
|
-
selector?: string | SelectorFunction;
|
|
550
|
-
mediaQuery?: string | MediaQueryFunction;
|
|
551
|
-
minify?: boolean;
|
|
552
|
-
preserveReferences?: boolean;
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
/**
|
|
556
|
-
* Result of a token build operation
|
|
557
|
-
*
|
|
558
|
-
* Contains success status, generated output files, and any errors encountered.
|
|
559
|
-
*
|
|
560
|
-
* @example
|
|
561
|
-
* ```typescript
|
|
562
|
-
* const result = await build(config)
|
|
563
|
-
* if (result.success) {
|
|
564
|
-
* result.outputs.forEach(output => {
|
|
565
|
-
* console.log(`Generated ${output.name}: ${output.path}`)
|
|
566
|
-
* })
|
|
567
|
-
* } else {
|
|
568
|
-
* console.error('Build errors:', result.errors)
|
|
569
|
-
* }
|
|
570
|
-
* ```
|
|
571
|
-
*/
|
|
572
|
-
/**
|
|
573
|
-
* Error code identifying the type of build error
|
|
574
|
-
*/
|
|
575
|
-
type ErrorCode = 'TOKEN_REFERENCE' | 'CIRCULAR_REFERENCE' | 'VALIDATION' | 'FILE_OPERATION' | 'CONFIGURATION' | 'BASE_PERMUTATION' | 'MODIFIER' | 'UNKNOWN';
|
|
576
|
-
/**
|
|
577
|
-
* Structured error from a build operation
|
|
578
|
-
*
|
|
579
|
-
* Preserves typed context from the error hierarchy so consumers
|
|
580
|
-
* can programmatically react to specific failure modes.
|
|
581
|
-
*/
|
|
582
|
-
type BuildError = {
|
|
583
|
-
/** Human-readable error message */
|
|
584
|
-
message: string;
|
|
585
|
-
/** Machine-readable error code identifying the failure type */
|
|
586
|
-
code: ErrorCode;
|
|
587
|
-
/** File path where the error occurred (for file operation errors) */
|
|
588
|
-
path?: string;
|
|
589
|
-
/** Token path where the error occurred (e.g. 'color.primary') */
|
|
590
|
-
tokenPath?: string;
|
|
591
|
-
/** Error severity */
|
|
592
|
-
severity: 'error' | 'warning';
|
|
593
|
-
/** Suggested alternatives (e.g. similar token names for TOKEN_REFERENCE errors) */
|
|
594
|
-
suggestions?: string[];
|
|
595
|
-
};
|
|
596
|
-
type BuildResult = {
|
|
597
|
-
/** Whether the build completed successfully */
|
|
598
|
-
success: boolean;
|
|
599
|
-
/** Array of generated output files */
|
|
600
|
-
outputs: BuildOutput[];
|
|
601
|
-
/** Array of errors encountered during build (only present if success is false) */
|
|
602
|
-
errors?: BuildError[];
|
|
603
|
-
};
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* @fileoverview Validation configuration types
|
|
607
|
-
*/
|
|
608
|
-
/** Controls how validation issues are reported */
|
|
609
|
-
type ValidationMode = 'error' | 'warn' | 'off';
|
|
610
|
-
/**
|
|
611
|
-
* Options that control token and resolver validation behavior.
|
|
612
|
-
*
|
|
613
|
-
* @example
|
|
614
|
-
* ```typescript
|
|
615
|
-
* const dispersa = new Dispersa({
|
|
616
|
-
* validation: { mode: 'warn' },
|
|
617
|
-
* })
|
|
618
|
-
* ```
|
|
619
|
-
*/
|
|
620
|
-
type ValidationOptions = {
|
|
621
|
-
/**
|
|
622
|
-
* Validation mode.
|
|
623
|
-
* - `'error'` (default) – throw on validation failures
|
|
624
|
-
* - `'warn'` – log warnings via `console.warn` but continue processing
|
|
625
|
-
* - `'off'` – skip validation entirely
|
|
626
|
-
*/
|
|
627
|
-
mode?: ValidationMode;
|
|
628
|
-
};
|
|
629
|
-
|
|
630
|
-
/**
|
|
631
|
-
* @fileoverview Configuration types for Dispersa
|
|
632
|
-
*
|
|
633
|
-
* Note: config and renderers/types have a mutual type-only dependency.
|
|
634
|
-
* OutputConfig references Renderer/FormatOptions, while RenderContext
|
|
635
|
-
* references OutputConfig. This is acceptable because type imports are
|
|
636
|
-
* erased at runtime and the coupling is genuine (config describes how
|
|
637
|
-
* to drive renderers).
|
|
638
|
-
*/
|
|
639
|
-
|
|
640
|
-
/**
|
|
641
|
-
* Lifecycle hooks for the build process.
|
|
642
|
-
*
|
|
643
|
-
* The same hook type is used on both `BuildConfig.hooks` (global) and
|
|
644
|
-
* `OutputConfig.hooks` (per-output). All hooks are optional and support
|
|
645
|
-
* both sync and async functions.
|
|
646
|
-
*
|
|
647
|
-
* **Execution order:**
|
|
648
|
-
* 1. Global `onBuildStart`
|
|
649
|
-
* 2. For each output: per-output `onBuildStart` → process → per-output `onBuildEnd`
|
|
650
|
-
* 3. Global `onBuildEnd`
|
|
651
|
-
*/
|
|
652
|
-
type LifecycleHooks = {
|
|
653
|
-
/** Called before permutation resolution and output processing begins */
|
|
654
|
-
onBuildStart?: (context: {
|
|
655
|
-
config: BuildConfig;
|
|
656
|
-
resolver: string | ResolverDocument;
|
|
657
|
-
}) => void | Promise<void>;
|
|
658
|
-
/** Called after all outputs have been processed (success or failure) */
|
|
659
|
-
onBuildEnd?: (result: BuildResult) => void | Promise<void>;
|
|
660
|
-
};
|
|
661
|
-
/**
|
|
662
|
-
* Function that generates an output file path based on modifier inputs.
|
|
663
|
-
*
|
|
664
|
-
* Used as the `file` property on `OutputConfig` and builder configs when
|
|
665
|
-
* the file name needs to vary per permutation.
|
|
666
|
-
*/
|
|
667
|
-
type FileFunction = (modifierInputs: ModifierInputs) => string;
|
|
668
|
-
/**
|
|
669
|
-
* Output configuration for a single build target
|
|
670
|
-
*
|
|
671
|
-
* Defines how tokens should be formatted and output for a specific target
|
|
672
|
-
* format (CSS, JSON, JavaScript, etc.).
|
|
673
|
-
*
|
|
674
|
-
* **Processing Order:**
|
|
675
|
-
* - Global filters (from BuildConfig) are applied first to all outputs
|
|
676
|
-
* - Then output-specific filters are applied (AND logic with global filters)
|
|
677
|
-
* - Global transforms are applied next
|
|
678
|
-
* - Finally output-specific transforms are applied
|
|
679
|
-
*
|
|
680
|
-
* **Output File Names:**
|
|
681
|
-
* The `file` field supports subdirectories and dynamic naming patterns.
|
|
682
|
-
* Parent directories are created automatically.
|
|
683
|
-
*
|
|
684
|
-
* @example Using builder helpers (recommended)
|
|
685
|
-
* ```typescript
|
|
686
|
-
* import { css, json } from 'dispersa'
|
|
687
|
-
* import { colorToHex, dimensionToPx } from 'dispersa/transforms'
|
|
688
|
-
*
|
|
689
|
-
* // CSS output with transforms
|
|
690
|
-
* css({
|
|
691
|
-
* name: 'css',
|
|
692
|
-
* file: 'css/tokens.css',
|
|
693
|
-
* preset: 'bundle',
|
|
694
|
-
* selector: ':root',
|
|
695
|
-
* transforms: [colorToHex(), dimensionToPx()],
|
|
696
|
-
* })
|
|
697
|
-
*
|
|
698
|
-
* // JSON output with static filename
|
|
699
|
-
* json({
|
|
700
|
-
* name: 'json',
|
|
701
|
-
* file: 'json/tokens.json',
|
|
702
|
-
* preset: 'standalone',
|
|
703
|
-
* structure: 'flat',
|
|
704
|
-
* })
|
|
705
|
-
* ```
|
|
706
|
-
*
|
|
707
|
-
* @example Pattern-based and function-based filenames
|
|
708
|
-
* ```typescript
|
|
709
|
-
* import { css } from 'dispersa'
|
|
710
|
-
*
|
|
711
|
-
* // Standalone mode with pattern-based filename
|
|
712
|
-
* css({
|
|
713
|
-
* name: 'css-standalone',
|
|
714
|
-
* file: 'tokens-{theme}-{platform}.css', // → tokens-light-web.css, tokens-dark-mobile.css
|
|
715
|
-
* preset: 'standalone',
|
|
716
|
-
* selector: ':root',
|
|
717
|
-
* })
|
|
718
|
-
*
|
|
719
|
-
* // Function-based filename
|
|
720
|
-
* css({
|
|
721
|
-
* name: 'css-custom',
|
|
722
|
-
* preset: 'standalone',
|
|
723
|
-
* selector: ':root',
|
|
724
|
-
* file: (modifierInputs) => {
|
|
725
|
-
* const parts = Object.entries(modifierInputs).map(([k, v]) => `${k}-${v}`)
|
|
726
|
-
* return `tokens-${parts.join('-')}.css`
|
|
727
|
-
* },
|
|
728
|
-
* })
|
|
729
|
-
* ```
|
|
730
|
-
*
|
|
731
|
-
* @see CssRendererOptions
|
|
732
|
-
* @see JsonRendererOptions
|
|
733
|
-
* @see JsModuleRendererOptions
|
|
734
|
-
*/
|
|
735
|
-
type OutputConfig<TOptions extends FormatOptions = FormatOptions> = Omit<OutputConfigBase, 'renderer' | 'transforms' | 'filters' | 'file'> & {
|
|
736
|
-
/** Renderer instance (created via renderer factory function) */
|
|
737
|
-
renderer: Renderer<TOptions>;
|
|
738
|
-
/**
|
|
739
|
-
* Array of filter objects to apply
|
|
740
|
-
* Filters are applied before transforms (to select which tokens to process)
|
|
741
|
-
*/
|
|
742
|
-
filters?: Filter[];
|
|
743
|
-
/** Array of transform objects to apply */
|
|
744
|
-
transforms?: Transform[];
|
|
745
|
-
/**
|
|
746
|
-
* Output file path, can be static or dynamic
|
|
747
|
-
*
|
|
748
|
-
* Supports subdirectories (e.g., "css/tokens.css").
|
|
749
|
-
* In standalone preset (one file per permutation), supports:
|
|
750
|
-
* - Pattern strings with placeholders: `tokens-{theme}-{platform}.css`
|
|
751
|
-
* - Function that receives modifierInputs: `(modifierInputs) => \`tokens-${...}.css\``
|
|
752
|
-
* - Plain string (applies default pattern with all modifiers)
|
|
753
|
-
*
|
|
754
|
-
* @example
|
|
755
|
-
* ```typescript
|
|
756
|
-
* // Static filename (bundle preset or single permutation)
|
|
757
|
-
* file: 'tokens.css'
|
|
758
|
-
*
|
|
759
|
-
* // With subdirectory
|
|
760
|
-
* file: 'css/tokens.css'
|
|
761
|
-
*
|
|
762
|
-
* // Pattern with placeholders (standalone preset)
|
|
763
|
-
* file: 'tokens-{theme}-{platform}.css'
|
|
764
|
-
*
|
|
765
|
-
* // Function for complex logic (standalone preset)
|
|
766
|
-
* file: (modifierInputs) => {
|
|
767
|
-
* const parts = Object.entries(modifierInputs).map(([k, v]) => `${k}-${v}`)
|
|
768
|
-
* return `output/${parts.join('-')}/tokens.css`
|
|
769
|
-
* }
|
|
770
|
-
* ```
|
|
771
|
-
*/
|
|
772
|
-
file?: string | FileFunction;
|
|
773
|
-
/**
|
|
774
|
-
* Renderer-specific options passed to the formatter.
|
|
775
|
-
*/
|
|
776
|
-
options?: TOptions;
|
|
777
|
-
/**
|
|
778
|
-
* Lifecycle hooks for this output.
|
|
779
|
-
*
|
|
780
|
-
* Per-output hooks fire in addition to global hooks on BuildConfig.
|
|
781
|
-
* `onBuildStart` fires before this output is processed,
|
|
782
|
-
* `onBuildEnd` fires after this output finishes (success or failure).
|
|
783
|
-
*/
|
|
784
|
-
hooks?: LifecycleHooks;
|
|
785
|
-
};
|
|
786
|
-
/**
|
|
787
|
-
* Complete build configuration for Dispersa
|
|
788
|
-
*
|
|
789
|
-
* Defines all aspects of the token build process including input sources,
|
|
790
|
-
* output targets, transforms, and permutation handling.
|
|
791
|
-
*
|
|
792
|
-
* **Complete Token Processing Pipeline:**
|
|
793
|
-
*
|
|
794
|
-
* 1. **Preprocessors** (BuildConfig.preprocessors)
|
|
795
|
-
* - Operate on raw JSON before parsing
|
|
796
|
-
* - Transform raw data structures
|
|
797
|
-
* - Example: strip custom metadata, inject env vars
|
|
798
|
-
*
|
|
799
|
-
* 2. **Parse & Resolve**
|
|
800
|
-
* - Parse token files according to DTCG spec
|
|
801
|
-
* - Resolve references between tokens
|
|
802
|
-
* - Apply modifiers (themes, modes, etc.)
|
|
803
|
-
* - Output: ResolvedTokens
|
|
804
|
-
*
|
|
805
|
-
* 3. **Global Filters** (BuildConfig.filters)
|
|
806
|
-
* - Applied to all tokens for all outputs
|
|
807
|
-
* - Example: exclude deprecated tokens globally
|
|
808
|
-
*
|
|
809
|
-
* 4. **Global Transforms** (BuildConfig.transforms)
|
|
810
|
-
* - Applied to all tokens for all outputs
|
|
811
|
-
* - Example: global naming conventions
|
|
812
|
-
*
|
|
813
|
-
* 5. **Per-Output Processing** (for each OutputConfig):
|
|
814
|
-
* a. **Output Filters** - Select which tokens to include (AND logic)
|
|
815
|
-
* b. **Output Transforms** - Modify selected tokens only
|
|
816
|
-
* c. **Renderer** - Generate output format and bundle output
|
|
817
|
-
*
|
|
818
|
-
* All transforms and filters are applied in array order.
|
|
819
|
-
*
|
|
820
|
-
* @example Basic usage with global filters and transforms
|
|
821
|
-
* ```typescript
|
|
822
|
-
* import { build, css, json } from 'dispersa'
|
|
823
|
-
* import { byType } from 'dispersa/filters'
|
|
824
|
-
* import { colorToHex, nameKebabCase } from 'dispersa/transforms'
|
|
825
|
-
*
|
|
826
|
-
* await build({
|
|
827
|
-
* outputs: [
|
|
828
|
-
* css({ name: 'css', preset: 'bundle', selector: ':root' }),
|
|
829
|
-
* json({ name: 'json', preset: 'standalone', structure: 'flat' }),
|
|
830
|
-
* ],
|
|
831
|
-
* filters: [byType('color')], // Global filter - only include color tokens for all outputs
|
|
832
|
-
* transforms: [nameKebabCase(), colorToHex()], // Global transforms for all outputs
|
|
833
|
-
* })
|
|
834
|
-
* ```
|
|
835
|
-
*
|
|
836
|
-
* @example Combining global and output-specific filters
|
|
837
|
-
* ```typescript
|
|
838
|
-
* import { css, json } from 'dispersa'
|
|
839
|
-
* import { byType } from 'dispersa/filters'
|
|
840
|
-
* import { nameKebabCase } from 'dispersa/transforms'
|
|
841
|
-
*
|
|
842
|
-
* await build({
|
|
843
|
-
* outputs: [
|
|
844
|
-
* css({
|
|
845
|
-
* name: 'css',
|
|
846
|
-
* preset: 'bundle',
|
|
847
|
-
* selector: ':root',
|
|
848
|
-
* }),
|
|
849
|
-
* json({
|
|
850
|
-
* name: 'json',
|
|
851
|
-
* preset: 'standalone',
|
|
852
|
-
* structure: 'flat',
|
|
853
|
-
* }),
|
|
854
|
-
* ],
|
|
855
|
-
* filters: [byType('color')],
|
|
856
|
-
* transforms: [nameKebabCase()],
|
|
857
|
-
* })
|
|
858
|
-
* ```
|
|
859
|
-
*/
|
|
860
|
-
type BuildConfig = Omit<BuildConfigBase, 'outputs' | 'filters' | 'transforms' | 'preprocessors' | 'permutations'> & {
|
|
861
|
-
/** Resolver configuration - file path or inline ResolverDocument */
|
|
862
|
-
resolver?: string | ResolverDocument;
|
|
863
|
-
/** Output directory for generated files */
|
|
864
|
-
buildPath?: string;
|
|
865
|
-
/** Validation mode for token resolution */
|
|
866
|
-
validation?: ValidationOptions;
|
|
867
|
-
/** Array of output configurations defining target formats */
|
|
868
|
-
outputs: OutputConfig[];
|
|
869
|
-
/** Global filters to apply to all outputs before output-specific filters */
|
|
870
|
-
filters?: Filter[];
|
|
871
|
-
/** Global transforms to apply to all tokens before output-specific transforms */
|
|
872
|
-
transforms?: Transform[];
|
|
873
|
-
/** Global preprocessors to apply to raw token data before parsing */
|
|
874
|
-
preprocessors?: Preprocessor[];
|
|
875
|
-
/** Explicit permutations to build (modifier inputs) */
|
|
876
|
-
permutations?: ModifierInputs[];
|
|
877
|
-
/** Linting configuration */
|
|
878
|
-
lint?: LintBuildConfig;
|
|
879
|
-
/** Global lifecycle hooks for the build process */
|
|
880
|
-
hooks?: LifecycleHooks;
|
|
881
|
-
};
|
|
882
|
-
/**
|
|
883
|
-
* Dispersa options with runtime-only validation helpers
|
|
884
|
-
*
|
|
885
|
-
* Schema validation supports "validation.mode" but cannot validate functions.
|
|
886
|
-
*/
|
|
887
|
-
type DispersaOptions = Omit<DispersaOptionsBase, 'validation'> & {
|
|
888
|
-
/** Resolver configuration - file path or inline ResolverDocument */
|
|
889
|
-
resolver?: string | ResolverDocument;
|
|
890
|
-
/** Default output directory for generated files */
|
|
891
|
-
buildPath?: string;
|
|
892
|
-
validation?: ValidationOptions;
|
|
893
|
-
};
|
|
894
|
-
|
|
895
|
-
export { type AnyLintRule as A, type BuildConfig as B, type CssRendererOptions as C, type DispersaOptions as D, type ErrorCode as E, type FileFunction as F, type LintOutputFormat as G, type RulesRegistry as H, type RuleConfigFor as I, 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 TypedRulesConfig as T, type ValidationMode as V, type ValidationOptions as a, type BuildError as b, type BuildOutput as c, type BuildResult as d, type FormatOptions as e, type OutputTree as f, type RenderContext as g, type RenderMeta as h, type RenderOutput as i, type ModifierInputs as j, type ResolverDocument as k, defineRenderer as l, type LintConfig as m, type LintResult as n, type LintRule as o, type LintPlugin as p, type LintFormatter as q, type Severity as r, type LintRuleMeta as s, type LintRuleContext as t, type LintReportDescriptor as u, type RuleConfig as v, type ResolvedRuleConfig as w, type LintBuildConfig as x, type ResolvedLintConfig as y, type LintIssue as z };
|