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,567 @@
|
|
|
1
|
+
import { c as TokenType, L as InternalResolvedTokens, R as ResolvedToken, a as ResolvedTokens } from './types-TQHV1MrY.cjs';
|
|
2
|
+
import { F as Filter } from './types-CAdUV-fa.cjs';
|
|
3
|
+
import { P as Preprocessor } from './types-DUc4vLZH.cjs';
|
|
4
|
+
import { T as Transform } from './types-BltzwVYK.cjs';
|
|
5
|
+
import { i as ResolverDocument, O as OutputConfig, h as ModifierInputs, L as LifecycleHooks, b as BuildResult } from './types-B0cI70Bt.cjs';
|
|
6
|
+
import { B as BuildConfigBase, D as DispersaOptionsBase } from './config-schemas-DnEBhIg0.cjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @license MIT
|
|
10
|
+
* Copyright (c) 2025-present Dispersa
|
|
11
|
+
*
|
|
12
|
+
* This source code is licensed under the MIT license found in the
|
|
13
|
+
* LICENSE file in the root directory of this source tree.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview Core type definitions for the Dispersa linting system
|
|
17
|
+
*
|
|
18
|
+
* Inspired by ESLint and Terrazzo, this system provides a plugin-based
|
|
19
|
+
* architecture for validating design tokens against semantic rules.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Lint rule severity levels
|
|
24
|
+
*
|
|
25
|
+
* - `'off'` - Rule is disabled
|
|
26
|
+
* - `'warn'` - Rule issues warnings but doesn't fail the build
|
|
27
|
+
* - `'error'` - Rule issues errors and fails the build (if failOnError is true)
|
|
28
|
+
*/
|
|
29
|
+
type Severity = 'off' | 'warn' | 'error';
|
|
30
|
+
/**
|
|
31
|
+
* Metadata describing a lint rule
|
|
32
|
+
*
|
|
33
|
+
* @template MessageIds - Union type of message IDs this rule can produce
|
|
34
|
+
*/
|
|
35
|
+
type LintRuleMeta<MessageIds extends string = string> = {
|
|
36
|
+
/** Short name of the rule (e.g., 'require-description') */
|
|
37
|
+
name: string;
|
|
38
|
+
/** Human-readable description of what the rule checks */
|
|
39
|
+
description: string;
|
|
40
|
+
/** Optional URL to documentation for this rule */
|
|
41
|
+
url?: string;
|
|
42
|
+
/** Map of message IDs to message templates (supports {{placeholder}} interpolation) */
|
|
43
|
+
messages: Record<MessageIds, string>;
|
|
44
|
+
/** Token types this rule applies to. Default: 'all' */
|
|
45
|
+
appliesTo?: TokenType[] | 'all';
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Context object passed to rule's create() function
|
|
49
|
+
*
|
|
50
|
+
* Provides access to tokens, configuration, and the report function.
|
|
51
|
+
*
|
|
52
|
+
* @template MessageIds - Union type of message IDs this rule can produce
|
|
53
|
+
* @template Options - Rule-specific options type
|
|
54
|
+
*/
|
|
55
|
+
type LintRuleContext<MessageIds extends string = string, Options extends Record<string, unknown> = Record<string, never>> = {
|
|
56
|
+
/** Fully qualified rule ID (e.g., 'dispersa/require-description') */
|
|
57
|
+
id: string;
|
|
58
|
+
/** Merged options (defaultOptions + user config) */
|
|
59
|
+
options: Options;
|
|
60
|
+
/** All resolved tokens to validate */
|
|
61
|
+
tokens: InternalResolvedTokens;
|
|
62
|
+
/**
|
|
63
|
+
* Report a lint issue
|
|
64
|
+
*
|
|
65
|
+
* @param descriptor - Issue descriptor with token, message ID, and optional data
|
|
66
|
+
*/
|
|
67
|
+
report(descriptor: LintReportDescriptor<MessageIds>): void;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Descriptor for reporting a lint issue
|
|
71
|
+
*
|
|
72
|
+
* @template MessageIds - Union type of message IDs this rule can produce
|
|
73
|
+
*/
|
|
74
|
+
type LintReportDescriptor<MessageIds extends string = string> = {
|
|
75
|
+
/** The token that has the issue */
|
|
76
|
+
token: ResolvedToken;
|
|
77
|
+
/** ID of the message to use from rule's meta.messages */
|
|
78
|
+
messageId: MessageIds;
|
|
79
|
+
/** Data to interpolate into the message (replaces {{key}} placeholders) */
|
|
80
|
+
data?: Record<string, string | number>;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* A lint rule definition
|
|
84
|
+
*
|
|
85
|
+
* Rules are created using the `createRule()` factory function for type safety.
|
|
86
|
+
*
|
|
87
|
+
* @template MessageIds - Union type of message IDs this rule can produce
|
|
88
|
+
* @template Options - Rule-specific options type
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const myRule: LintRule<'MISSING_VALUE', { required: boolean }> = {
|
|
93
|
+
* meta: {
|
|
94
|
+
* name: 'require-value',
|
|
95
|
+
* description: 'Require tokens to have values',
|
|
96
|
+
* messages: {
|
|
97
|
+
* MISSING_VALUE: "Token '{{name}}' is missing a value",
|
|
98
|
+
* },
|
|
99
|
+
* },
|
|
100
|
+
* defaultOptions: { required: true },
|
|
101
|
+
* create({ tokens, report, options }) {
|
|
102
|
+
* for (const token of Object.values(tokens)) {
|
|
103
|
+
* if (options.required && !token.$value) {
|
|
104
|
+
* report({ token, messageId: 'MISSING_VALUE', data: { name: token.name } })
|
|
105
|
+
* }
|
|
106
|
+
* }
|
|
107
|
+
* },
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
type LintRule<MessageIds extends string = string, Options extends Record<string, unknown> = Record<string, never>> = {
|
|
112
|
+
/** Rule metadata */
|
|
113
|
+
meta: LintRuleMeta<MessageIds>;
|
|
114
|
+
/** Default options merged with user config */
|
|
115
|
+
defaultOptions?: Options;
|
|
116
|
+
/**
|
|
117
|
+
* Factory function that creates the rule's validation logic
|
|
118
|
+
*
|
|
119
|
+
* Called once per lint run with the context object.
|
|
120
|
+
*
|
|
121
|
+
* @param context - Rule context with tokens, options, and report function
|
|
122
|
+
*/
|
|
123
|
+
create(context: LintRuleContext<MessageIds, Options>): void | Promise<void>;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Base rule type without generic parameters for use in plugin definitions
|
|
127
|
+
*/
|
|
128
|
+
type AnyLintRule = LintRule<string, Record<string, unknown>>;
|
|
129
|
+
/**
|
|
130
|
+
* A lint plugin that provides rules and configurations
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const myPlugin: LintPlugin = {
|
|
135
|
+
* meta: {
|
|
136
|
+
* name: 'my-lint-plugin',
|
|
137
|
+
* version: '1.0.0',
|
|
138
|
+
* },
|
|
139
|
+
* rules: {
|
|
140
|
+
* 'my-rule': myRule,
|
|
141
|
+
* },
|
|
142
|
+
* configs: {
|
|
143
|
+
* recommended: {
|
|
144
|
+
* plugins: { my: myPlugin },
|
|
145
|
+
* rules: {
|
|
146
|
+
* 'my/my-rule': 'warn',
|
|
147
|
+
* },
|
|
148
|
+
* },
|
|
149
|
+
* },
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
type LintPlugin = {
|
|
154
|
+
/** Plugin metadata */
|
|
155
|
+
meta: {
|
|
156
|
+
/** Package name (e.g., '@dispersa/lint-plugin-a11y') */
|
|
157
|
+
name: string;
|
|
158
|
+
/** Semantic version (optional, for debugging/metadata) */
|
|
159
|
+
version?: string;
|
|
160
|
+
};
|
|
161
|
+
/** Rules provided by this plugin */
|
|
162
|
+
rules: Record<string, AnyLintRule>;
|
|
163
|
+
/** Predefined configurations */
|
|
164
|
+
configs?: Record<string, LintConfig>;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Rule configuration - either severity only or severity with options
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* // Severity only
|
|
172
|
+
* 'error'
|
|
173
|
+
*
|
|
174
|
+
* // Severity with options
|
|
175
|
+
* ['error', { format: 'kebab-case' }]
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
type RuleConfig = Severity | [Severity, Record<string, unknown>];
|
|
179
|
+
/**
|
|
180
|
+
* Resolved rule configuration with parsed severity and options
|
|
181
|
+
*/
|
|
182
|
+
type ResolvedRuleConfig = {
|
|
183
|
+
severity: Exclude<Severity, 'off'>;
|
|
184
|
+
options: Record<string, unknown>;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Registry for lint rule options types.
|
|
188
|
+
*
|
|
189
|
+
* Built-in dispersa rules are registered via declaration merging in `./rules/index.ts`.
|
|
190
|
+
* Plugin authors can augment this interface to add their own rule types:
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* // In your plugin file
|
|
195
|
+
* declare module 'dispersa/lint' {
|
|
196
|
+
* interface RulesRegistry {
|
|
197
|
+
* 'my-plugin/my-rule': MyRuleOptions
|
|
198
|
+
* }
|
|
199
|
+
* }
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
interface RulesRegistry {
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Type-safe configuration for a single rule from the registry.
|
|
206
|
+
*
|
|
207
|
+
* @template K - The rule ID key from RulesRegistry
|
|
208
|
+
*/
|
|
209
|
+
type RuleConfigFor<K extends keyof RulesRegistry> = Severity | [Severity, RulesRegistry[K]];
|
|
210
|
+
/**
|
|
211
|
+
* Typed rules configuration with intellisense for all registered rules.
|
|
212
|
+
*
|
|
213
|
+
* Provides autocomplete for rule IDs and their option types.
|
|
214
|
+
* Also allows arbitrary string keys for unregistered rules.
|
|
215
|
+
*/
|
|
216
|
+
type TypedRulesConfig = {
|
|
217
|
+
[K in keyof RulesRegistry]?: RuleConfigFor<K>;
|
|
218
|
+
} & Record<string, RuleConfig>;
|
|
219
|
+
/**
|
|
220
|
+
* Lint configuration
|
|
221
|
+
*
|
|
222
|
+
* @template Rules - Rules configuration type (defaults to TypedRulesConfig for intellisense)
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* const config: LintConfig = {
|
|
227
|
+
* plugins: {
|
|
228
|
+
* dispersa: dispersaPlugin,
|
|
229
|
+
* a11y: '@dispersa/lint-plugin-a11y', // Load by string
|
|
230
|
+
* },
|
|
231
|
+
* rules: {
|
|
232
|
+
* 'dispersa/require-description': 'warn',
|
|
233
|
+
* 'dispersa/naming-convention': ['error', { format: 'kebab-case' }],
|
|
234
|
+
* 'a11y/min-contrast': ['error', { level: 'AA' }],
|
|
235
|
+
* },
|
|
236
|
+
* }
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
type LintConfig<Rules extends Record<string, RuleConfig> = TypedRulesConfig> = {
|
|
240
|
+
/** Plugins to load (by object or module path string) */
|
|
241
|
+
plugins?: Record<string, LintPlugin | string>;
|
|
242
|
+
/** Rule configurations */
|
|
243
|
+
rules?: Rules;
|
|
244
|
+
/** Fail build on lint errors (default: true) */
|
|
245
|
+
failOnError?: boolean;
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* Configuration for lint within BuildConfig
|
|
249
|
+
*
|
|
250
|
+
* Extends {@link LintConfig} with an `enabled` toggle for opt-in build integration.
|
|
251
|
+
*
|
|
252
|
+
* @template Rules - Rules configuration type (defaults to TypedRulesConfig for intellisense)
|
|
253
|
+
*/
|
|
254
|
+
type LintBuildConfig<Rules extends Record<string, RuleConfig> = TypedRulesConfig> = LintConfig<Rules> & {
|
|
255
|
+
/** Enable linting (default: false, opt-in) */
|
|
256
|
+
enabled?: boolean;
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Resolved lint configuration with all plugins loaded
|
|
260
|
+
*/
|
|
261
|
+
type ResolvedLintConfig = {
|
|
262
|
+
/** Whether linting is enabled */
|
|
263
|
+
enabled: boolean;
|
|
264
|
+
/** Fail build on errors */
|
|
265
|
+
failOnError: boolean;
|
|
266
|
+
/** Loaded plugins indexed by namespace */
|
|
267
|
+
plugins: Record<string, LintPlugin>;
|
|
268
|
+
/** Resolved rule configurations */
|
|
269
|
+
rules: Record<string, ResolvedRuleConfig>;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* A single lint issue
|
|
273
|
+
*/
|
|
274
|
+
type LintIssue = {
|
|
275
|
+
/** Fully qualified rule ID (e.g., 'dispersa/require-description') */
|
|
276
|
+
ruleId: string;
|
|
277
|
+
/** Issue severity */
|
|
278
|
+
severity: Exclude<Severity, 'off'>;
|
|
279
|
+
/** Human-readable message */
|
|
280
|
+
message: string;
|
|
281
|
+
/** Token name (e.g., 'color.brand.primary') */
|
|
282
|
+
tokenName: string;
|
|
283
|
+
/** Token path segments (e.g., ['color', 'brand', 'primary']) */
|
|
284
|
+
tokenPath: string[];
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Result of a lint run
|
|
288
|
+
*/
|
|
289
|
+
type LintResult = {
|
|
290
|
+
/** All issues found */
|
|
291
|
+
issues: LintIssue[];
|
|
292
|
+
/** Count of error-severity issues */
|
|
293
|
+
errorCount: number;
|
|
294
|
+
/** Count of warning-severity issues */
|
|
295
|
+
warningCount: number;
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* Output format for lint results
|
|
299
|
+
*/
|
|
300
|
+
type LintOutputFormat = 'json' | 'stylish' | 'compact';
|
|
301
|
+
/**
|
|
302
|
+
* Formatter function that converts lint result to output string
|
|
303
|
+
*/
|
|
304
|
+
type LintFormatter = (result: LintResult) => string;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* @fileoverview Validation configuration types
|
|
308
|
+
*/
|
|
309
|
+
/** Controls how validation issues are reported */
|
|
310
|
+
type ValidationMode = 'error' | 'warn' | 'off';
|
|
311
|
+
/**
|
|
312
|
+
* Options that control token and resolver validation behavior.
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```typescript
|
|
316
|
+
* const dispersa = new Dispersa({
|
|
317
|
+
* validation: { mode: 'warn' },
|
|
318
|
+
* })
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
type ValidationOptions = {
|
|
322
|
+
/**
|
|
323
|
+
* Validation mode.
|
|
324
|
+
* - `'error'` (default) – throw on validation failures
|
|
325
|
+
* - `'warn'` – log warnings via `console.warn` but continue processing
|
|
326
|
+
* - `'off'` – skip validation entirely
|
|
327
|
+
*/
|
|
328
|
+
mode?: ValidationMode;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* @license
|
|
333
|
+
* Copyright (c) 2025 Dispersa Contributors
|
|
334
|
+
* SPDX-License-Identifier: MIT
|
|
335
|
+
*/
|
|
336
|
+
/**
|
|
337
|
+
* @fileoverview Build orchestration types
|
|
338
|
+
*
|
|
339
|
+
* Contains types for build configuration, permutation handling, and
|
|
340
|
+
* build-time options. These types define how to drive the build process.
|
|
341
|
+
*/
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Complete build configuration for Dispersa
|
|
345
|
+
*
|
|
346
|
+
* Defines all aspects of the token build process including input sources,
|
|
347
|
+
* output targets, transforms, and permutation handling.
|
|
348
|
+
*
|
|
349
|
+
* **Complete Token Processing Pipeline:**
|
|
350
|
+
*
|
|
351
|
+
* 1. **Preprocessors** (BuildConfig.preprocessors)
|
|
352
|
+
* - Operate on raw JSON before parsing
|
|
353
|
+
* - Transform raw data structures
|
|
354
|
+
* - Example: strip custom metadata, inject env vars
|
|
355
|
+
*
|
|
356
|
+
* 2. **Parse & Resolve**
|
|
357
|
+
* - Parse token files according to DTCG spec
|
|
358
|
+
* - Resolve references between tokens
|
|
359
|
+
* - Apply modifiers (themes, modes, etc.)
|
|
360
|
+
* - Output: ResolvedTokens
|
|
361
|
+
*
|
|
362
|
+
* 3. **Global Filters** (BuildConfig.filters)
|
|
363
|
+
* - Applied to all tokens for all outputs
|
|
364
|
+
* - Example: exclude deprecated tokens globally
|
|
365
|
+
*
|
|
366
|
+
* 4. **Global Transforms** (BuildConfig.transforms)
|
|
367
|
+
* - Applied to all tokens for all outputs
|
|
368
|
+
* - Example: global naming conventions
|
|
369
|
+
*
|
|
370
|
+
* 5. **Per-Output Processing** (for each OutputConfig):
|
|
371
|
+
* a. **Output Filters** - Select which tokens to include (AND logic)
|
|
372
|
+
* b. **Output Transforms** - Modify selected tokens only
|
|
373
|
+
* c. **Renderer** - Generate output format and bundle output
|
|
374
|
+
*
|
|
375
|
+
* All transforms and filters are applied in array order.
|
|
376
|
+
*
|
|
377
|
+
* @example Basic usage with global filters and transforms
|
|
378
|
+
* ```typescript
|
|
379
|
+
* import { build, css, json } from 'dispersa'
|
|
380
|
+
* import { byType } from 'dispersa/filters'
|
|
381
|
+
* import { colorToHex, nameKebabCase } from 'dispersa/transforms'
|
|
382
|
+
*
|
|
383
|
+
* await build({
|
|
384
|
+
* outputs: [
|
|
385
|
+
* css({ name: 'css', preset: 'bundle', selector: ':root' }),
|
|
386
|
+
* json({ name: 'json', preset: 'standalone', structure: 'flat' }),
|
|
387
|
+
* ],
|
|
388
|
+
* filters: [byType('color')], // Global filter - only include color tokens for all outputs
|
|
389
|
+
* transforms: [nameKebabCase(), colorToHex()], // Global transforms for all outputs
|
|
390
|
+
* })
|
|
391
|
+
* ```
|
|
392
|
+
*
|
|
393
|
+
* @example Combining global and output-specific filters
|
|
394
|
+
* ```typescript
|
|
395
|
+
* import { css, json } from 'dispersa'
|
|
396
|
+
* import { byType } from 'dispersa/filters'
|
|
397
|
+
* import { nameKebabCase } from 'dispersa/transforms'
|
|
398
|
+
*
|
|
399
|
+
* await build({
|
|
400
|
+
* outputs: [
|
|
401
|
+
* css({
|
|
402
|
+
* name: 'css',
|
|
403
|
+
* preset: 'bundle',
|
|
404
|
+
* selector: ':root',
|
|
405
|
+
* }),
|
|
406
|
+
* json({
|
|
407
|
+
* name: 'json',
|
|
408
|
+
* preset: 'standalone',
|
|
409
|
+
* structure: 'flat',
|
|
410
|
+
* }),
|
|
411
|
+
* ],
|
|
412
|
+
* filters: [byType('color')],
|
|
413
|
+
* transforms: [nameKebabCase()],
|
|
414
|
+
* })
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
417
|
+
type BuildConfig = Omit<BuildConfigBase, 'outputs' | 'filters' | 'transforms' | 'preprocessors' | 'permutations'> & {
|
|
418
|
+
/** Resolver configuration - file path or inline ResolverDocument */
|
|
419
|
+
resolver?: string | ResolverDocument;
|
|
420
|
+
/** Output directory for generated files */
|
|
421
|
+
buildPath?: string;
|
|
422
|
+
/** Validation mode for token resolution */
|
|
423
|
+
validation?: ValidationOptions;
|
|
424
|
+
/** Array of output configurations defining target formats */
|
|
425
|
+
outputs: OutputConfig[];
|
|
426
|
+
/** Global filters to apply to all outputs before output-specific filters */
|
|
427
|
+
filters?: Filter[];
|
|
428
|
+
/** Global transforms to apply to all tokens before output-specific transforms */
|
|
429
|
+
transforms?: Transform[];
|
|
430
|
+
/** Global preprocessors to apply to raw token data before parsing */
|
|
431
|
+
preprocessors?: Preprocessor[];
|
|
432
|
+
/** Explicit permutations to build (modifier inputs) */
|
|
433
|
+
permutations?: ModifierInputs[];
|
|
434
|
+
/** Linting configuration */
|
|
435
|
+
lint?: LintBuildConfig;
|
|
436
|
+
/** Global lifecycle hooks for the build process */
|
|
437
|
+
hooks?: LifecycleHooks;
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Dispersa options with runtime-only validation helpers
|
|
442
|
+
*
|
|
443
|
+
* Schema validation supports "validation.mode" but cannot validate functions.
|
|
444
|
+
*/
|
|
445
|
+
type DispersaOptions = Omit<DispersaOptionsBase, 'validation'> & {
|
|
446
|
+
/** Resolver configuration - file path or inline ResolverDocument */
|
|
447
|
+
resolver?: string | ResolverDocument;
|
|
448
|
+
/** Default output directory for generated files */
|
|
449
|
+
buildPath?: string;
|
|
450
|
+
validation?: ValidationOptions;
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* @license
|
|
455
|
+
* Copyright (c) 2025 Dispersa Contributors
|
|
456
|
+
* SPDX-License-Identifier: MIT
|
|
457
|
+
*/
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* DTCG design token processor with multi-format output support
|
|
461
|
+
*
|
|
462
|
+
* Dispersa processes DTCG-compliant design tokens through a configurable pipeline,
|
|
463
|
+
* resolves references and aliases, applies transforms and filters, and generates output
|
|
464
|
+
* in multiple formats (CSS, JSON, JavaScript).
|
|
465
|
+
*
|
|
466
|
+
* **Runtime Validation:**
|
|
467
|
+
* All functions validate their configuration inputs at runtime, including build configs,
|
|
468
|
+
* output configs, and custom component registrations. This catches configuration errors
|
|
469
|
+
* early with helpful error messages.
|
|
470
|
+
*
|
|
471
|
+
* Features:
|
|
472
|
+
* - **Transforms**: Modify token values and names (e.g., convert colors, change case)
|
|
473
|
+
* - **Filters**: Select which tokens to include in output
|
|
474
|
+
* - **Preprocessors**: Transform raw token data before parsing
|
|
475
|
+
* - **Renderers**: Generate output in various formats
|
|
476
|
+
* - **Runtime validation**: JSON schema validation for all user inputs
|
|
477
|
+
*
|
|
478
|
+
* @example Basic build usage
|
|
479
|
+
* ```typescript
|
|
480
|
+
* import { build, css } from 'dispersa'
|
|
481
|
+
* import { nameKebabCase } from 'dispersa/transforms'
|
|
482
|
+
*
|
|
483
|
+
* const result = await build({
|
|
484
|
+
* resolver: './tokens.resolver.json',
|
|
485
|
+
* buildPath: './output',
|
|
486
|
+
* outputs: [
|
|
487
|
+
* css({
|
|
488
|
+
* name: 'css',
|
|
489
|
+
* file: 'tokens.css',
|
|
490
|
+
* preset: 'bundle',
|
|
491
|
+
* selector: ':root',
|
|
492
|
+
* transforms: [nameKebabCase()]
|
|
493
|
+
* })
|
|
494
|
+
* ]
|
|
495
|
+
* })
|
|
496
|
+
* ```
|
|
497
|
+
*
|
|
498
|
+
* @example Mixed presets per output
|
|
499
|
+
* ```typescript
|
|
500
|
+
* import { build, css, json } from 'dispersa'
|
|
501
|
+
*
|
|
502
|
+
* const result = await build({
|
|
503
|
+
* resolver: './tokens.resolver.json',
|
|
504
|
+
* buildPath: './output',
|
|
505
|
+
* outputs: [
|
|
506
|
+
* css({
|
|
507
|
+
* name: 'css',
|
|
508
|
+
* file: 'tokens.css',
|
|
509
|
+
* preset: 'bundle',
|
|
510
|
+
* selector: ':root', // All themes in one CSS file
|
|
511
|
+
* transforms: [nameKebabCase()]
|
|
512
|
+
* }),
|
|
513
|
+
* json({
|
|
514
|
+
* name: 'json',
|
|
515
|
+
* file: 'tokens-{theme}.json', // Separate file per theme
|
|
516
|
+
* preset: 'standalone',
|
|
517
|
+
* structure: 'flat'
|
|
518
|
+
* })
|
|
519
|
+
* ]
|
|
520
|
+
* })
|
|
521
|
+
* ```
|
|
522
|
+
*
|
|
523
|
+
* @example Using filters and preprocessors
|
|
524
|
+
* ```typescript
|
|
525
|
+
* import { build, css } from 'dispersa'
|
|
526
|
+
* import { byType } from 'dispersa/filters'
|
|
527
|
+
* import { nameKebabCase } from 'dispersa/transforms'
|
|
528
|
+
*
|
|
529
|
+
* const result = await build({
|
|
530
|
+
* resolver: './tokens.resolver.json',
|
|
531
|
+
* buildPath: './output',
|
|
532
|
+
* outputs: [
|
|
533
|
+
* css({
|
|
534
|
+
* name: 'colors-only',
|
|
535
|
+
* file: 'colors.css',
|
|
536
|
+
* preset: 'standalone',
|
|
537
|
+
* selector: ':root',
|
|
538
|
+
* filters: [byType('color')],
|
|
539
|
+
* transforms: [nameKebabCase()]
|
|
540
|
+
* })
|
|
541
|
+
* ],
|
|
542
|
+
* permutations: [
|
|
543
|
+
* { theme: 'light' },
|
|
544
|
+
* { theme: 'dark' }
|
|
545
|
+
* ]
|
|
546
|
+
* })
|
|
547
|
+
* ```
|
|
548
|
+
*/
|
|
549
|
+
declare function build(config: BuildConfig): Promise<BuildResult>;
|
|
550
|
+
declare function buildOrThrow(config: BuildConfig): Promise<BuildResult>;
|
|
551
|
+
declare function buildPermutation(config: BuildConfig, modifierInputs?: ModifierInputs): Promise<BuildResult>;
|
|
552
|
+
declare function resolveTokens(resolver: string | ResolverDocument, modifierInputs?: ModifierInputs, validation?: ValidationOptions): Promise<ResolvedTokens>;
|
|
553
|
+
type LintOptions = {
|
|
554
|
+
resolver: string | ResolverDocument;
|
|
555
|
+
modifierInputs?: ModifierInputs;
|
|
556
|
+
validation?: ValidationOptions;
|
|
557
|
+
} & LintConfig;
|
|
558
|
+
declare function lint(options: LintOptions): Promise<LintResult>;
|
|
559
|
+
declare function resolveAllPermutations(resolver: string | ResolverDocument): Promise<{
|
|
560
|
+
tokens: ResolvedTokens;
|
|
561
|
+
modifierInputs: ModifierInputs;
|
|
562
|
+
}[]>;
|
|
563
|
+
declare function generateTypes(tokens: ResolvedTokens, fileName: string, options?: {
|
|
564
|
+
moduleName?: string;
|
|
565
|
+
}): Promise<void>;
|
|
566
|
+
|
|
567
|
+
export { type AnyLintRule as A, type BuildConfig as B, type DispersaOptions as D, type LintOptions as L, type RuleConfig as R, type Severity as S, type TypedRulesConfig as T, type ValidationMode as V, buildOrThrow as a, build as b, buildPermutation as c, resolveAllPermutations as d, type ValidationOptions as e, type LintRule as f, generateTypes as g, type LintConfig as h, type LintResult as i, type LintPlugin as j, type LintFormatter as k, lint as l, type LintRuleMeta as m, type LintRuleContext as n, type LintReportDescriptor as o, type ResolvedRuleConfig as p, type LintBuildConfig as q, resolveTokens as r, type ResolvedLintConfig as s, type LintIssue as t, type LintOutputFormat as u, type RulesRegistry as v, type RuleConfigFor as w };
|