@terrazzo/parser 0.10.4 → 2.0.0-alpha.1
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/CHANGELOG.md +67 -0
- package/dist/index.d.ts +112 -325
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2194 -3621
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/build/index.ts +42 -42
- package/src/config.ts +13 -6
- package/src/lib/code-frame.ts +3 -0
- package/src/lib/momoa.ts +10 -0
- package/src/lint/index.ts +41 -37
- package/src/lint/plugin-core/index.ts +73 -16
- package/src/lint/plugin-core/rules/colorspace.ts +4 -0
- package/src/lint/plugin-core/rules/duplicate-values.ts +2 -0
- package/src/lint/plugin-core/rules/max-gamut.ts +24 -4
- package/src/lint/plugin-core/rules/no-type-on-alias.ts +29 -0
- package/src/lint/plugin-core/rules/required-modes.ts +2 -0
- package/src/lint/plugin-core/rules/required-typography-properties.ts +13 -3
- package/src/lint/plugin-core/rules/valid-boolean.ts +41 -0
- package/src/lint/plugin-core/rules/valid-border.ts +57 -0
- package/src/lint/plugin-core/rules/valid-color.ts +265 -0
- package/src/lint/plugin-core/rules/valid-cubic-bezier.ts +83 -0
- package/src/lint/plugin-core/rules/valid-dimension.ts +199 -0
- package/src/lint/plugin-core/rules/valid-duration.ts +123 -0
- package/src/lint/plugin-core/rules/valid-font-family.ts +68 -0
- package/src/lint/plugin-core/rules/valid-font-weight.ts +89 -0
- package/src/lint/plugin-core/rules/valid-gradient.ts +79 -0
- package/src/lint/plugin-core/rules/valid-link.ts +41 -0
- package/src/lint/plugin-core/rules/valid-number.ts +63 -0
- package/src/lint/plugin-core/rules/valid-shadow.ts +67 -0
- package/src/lint/plugin-core/rules/valid-string.ts +41 -0
- package/src/lint/plugin-core/rules/valid-stroke-style.ts +104 -0
- package/src/lint/plugin-core/rules/valid-transition.ts +61 -0
- package/src/lint/plugin-core/rules/valid-typography.ts +67 -0
- package/src/logger.ts +70 -59
- package/src/parse/index.ts +23 -328
- package/src/parse/load.ts +257 -0
- package/src/parse/normalize.ts +134 -170
- package/src/parse/token.ts +530 -0
- package/src/types.ts +106 -28
- package/src/parse/alias.ts +0 -369
- package/src/parse/json.ts +0 -211
- package/src/parse/validate.ts +0 -961
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,72 @@
|
|
|
1
1
|
# @terrazzo/parser
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - ⚠️ Breaking change; DTCG 2nd Editors draft format will throw errors by default. This means converting all colors and dimensions to the new object format.
|
|
8
|
+
|
|
9
|
+
Though this is a breaking change in default behavior, you can opt back into the old behavior by adjusting your config’s lint settings. See https://terrazzo.app/docs/cli/lint/.
|
|
10
|
+
|
|
11
|
+
List of changes:
|
|
12
|
+
- **color**: `channels` is invalid; `components` is required (“channels” was never part of the spec; this just deprecates an in-progress draft that was briefly supported)
|
|
13
|
+
- **dimension**: object notation (`{ value: 16, unit: 'px' }`) required.
|
|
14
|
+
- **dimension**: `0` is no longer automatically expanded to`{ value: 0, unit: 'px' }`.
|
|
15
|
+
- **duration**: object notation (`{ value: 100, unit: 'ms' }`) required.
|
|
16
|
+
- **dimension**: `{ $value: 0 }` no longer allowed.
|
|
17
|
+
- **typography**: `fontFamily`, `fontSize`, `fontWeight`, `lineHeight`, and `letterSpacing` are all required at a minimum (additional properties are still allowed).
|
|
18
|
+
|
|
19
|
+
- [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - Soft deprecate core/required-typography-properties in favor of core/valid-typography
|
|
20
|
+
|
|
21
|
+
- [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - ⚠️ Minor breaking change: the transform() API now returns the Momoa node as the 1st parameter. The 2nd parameter is now an object with more context. Lastly, it requires returning a momoa node, rather than raw JSON.
|
|
22
|
+
|
|
23
|
+
```diff
|
|
24
|
+
+ import * as momoa from "@humanwhocodes/momoa";
|
|
25
|
+
|
|
26
|
+
transform: {
|
|
27
|
+
- color(json, path, node) {
|
|
28
|
+
+ color(node, { path, filename }) {
|
|
29
|
+
+ const json = momoa.evaluate(node);
|
|
30
|
+
- return json;
|
|
31
|
+
+ return momoa.parse(json);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
This should result in a little less work overall. For example, instead of writing `if (typeof json === 'object' && !Array.isArray(json))` that could be shortened to `if (node.type === 'Object')`, among many other such advantages. You can call `evaluate()` manually if you’re more used to working with the raw JSON instead. Similarly, you can call `parse()` if you’re working with
|
|
36
|
+
|
|
37
|
+
- [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - ⚠️ Breaking change: lint on plugins no longer runs on individual files, rather, the full set once merged.
|
|
38
|
+
|
|
39
|
+
If your lint plugin is not using the `src` context value, no changes are needed. If it is, you’ll need to instead read from the `sources` array, and look up sources with a token’s `source.loc` filename manually. This change was because lint rules now run on all files in one pass, essentially.
|
|
40
|
+
|
|
41
|
+
- [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - ⚠️ [Plugin API] Minor breaking change: token.originalValue may be undefined for tokens created with $ref. This shouldn’t affect any tokens or plugins not using $refs. But going forward this value will be missing if the token was created dynamically via $ref.
|
|
42
|
+
|
|
43
|
+
- [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - Minor breaking change: build() and buildEnd() plugin hooks are now executed in parallel. The other hooks are still executed sequentially.
|
|
44
|
+
|
|
45
|
+
- [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - ⚠️ Breaking change: the following token types have more strict requirements about all properties being present:
|
|
46
|
+
- Border
|
|
47
|
+
- Transition
|
|
48
|
+
- Typography
|
|
49
|
+
|
|
50
|
+
These behaviors may be opted out individually by adjusting the new lint rules ([see documentation](https://terrazzo.app/docs/cli/lint/)).
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - Fix bug where border tokens’ partial aliases would sometimes refer to themselves
|
|
55
|
+
|
|
56
|
+
- [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - Fix bug of lint warning of rules turned off being unused
|
|
57
|
+
|
|
58
|
+
- [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - Validation moved to lint rules, which means token validation can be individually configured, and optionally extended.
|
|
59
|
+
|
|
60
|
+
- [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - Add first class support for JSON $refs, both remote and local.
|
|
61
|
+
|
|
62
|
+
Under-the-hood this transforms DTCG aliase to JSON $refs, so they’re interchangeable.
|
|
63
|
+
|
|
64
|
+
- [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - Bugfix: fix strokeStyle partialAliasOf
|
|
65
|
+
|
|
66
|
+
- [#530](https://github.com/terrazzoapp/terrazzo/pull/530) [`370ed7b`](https://github.com/terrazzoapp/terrazzo/commit/370ed7b0f578a64824124145d7f4936536b37bb3) Thanks [@drwpow](https://github.com/drwpow)! - Add missing $deprecated property to group types
|
|
67
|
+
|
|
68
|
+
- [#553](https://github.com/terrazzoapp/terrazzo/pull/553) [`e63a627`](https://github.com/terrazzoapp/terrazzo/commit/e63a6277f61282fb608744a8348689b16f977076) Thanks [@Sidnioulz](https://github.com/Sidnioulz)! - Add support for the Token Listing format
|
|
69
|
+
|
|
3
70
|
## 0.10.4
|
|
4
71
|
|
|
5
72
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import * as momoa from "@humanwhocodes/momoa";
|
|
2
|
+
import { AliasToken, AliasValue, BooleanToken, BooleanTokenNormalized, BooleanValue, BorderToken, BorderTokenNormalized, BorderValue, BorderValueNormalized, ColorSpace, ColorToken, ColorTokenNormalized, ColorValue, ColorValueNormalized, CubicBezierToken, CubicBezierTokenNormalized, CubicBezierValue, CustomTransformOptions, DimensionToken, DimensionTokenNormalized, DimensionValue, DurationToken, DurationTokenNormalized, DurationValue, FontFamilyToken, FontFamilyTokenNormalized, FontFamilyValue, FontFamilyValueNormalized, FontWeightToken, FontWeightTokenNormalized, FontWeightValue, FontWeightValueNormalized, GradientStop, GradientStopNormalized, GradientToken, GradientTokenNormalized, GradientValue, GradientValueNormalized, Group, GroupCore, GroupOrToken, LinkToken, LinkTokenNormalized, LinkValue, ModeMap, NumberToken, NumberTokenNormalized, NumberValue, ShadowToken, ShadowTokenNormalized, ShadowValue, ShadowValueNormalized, StringToken, StringTokenNormalized, StringValue, StrokeStyleToken, StrokeStyleTokenNormalized, StrokeStyleValue, StrokeStyleValueExpanded, Token, TokenCore, TokenMode, TokenNormalized, TokenNormalized as TokenNormalized$1, TokenNormalizedCore, TokenNormalizedSet, TokenNormalizedSet as TokenNormalizedSet$1, TokensSet, TransitionToken, TransitionTokenNormalized, TransitionValue, TransitionValueNormalized, TypographyToken, TypographyTokenNormalized, TypographyValue, TypographyValueNormalized } from "@terrazzo/token-tools";
|
|
3
3
|
import ytm from "yaml-to-momoa";
|
|
4
4
|
|
|
5
5
|
//#region src/logger.d.ts
|
|
@@ -22,7 +22,7 @@ interface LogEntry {
|
|
|
22
22
|
*/
|
|
23
23
|
continueOnError?: boolean;
|
|
24
24
|
/** Show a code frame for the erring node */
|
|
25
|
-
node?: AnyNode;
|
|
25
|
+
node?: momoa.AnyNode;
|
|
26
26
|
/** To show a code frame, provide the original source code */
|
|
27
27
|
src?: string;
|
|
28
28
|
}
|
|
@@ -60,13 +60,13 @@ declare class Logger {
|
|
|
60
60
|
});
|
|
61
61
|
setLevel(level: LogLevel): void;
|
|
62
62
|
/** Log an error message (always; can’t be silenced) */
|
|
63
|
-
error(
|
|
63
|
+
error(...entries: LogEntry[]): void;
|
|
64
64
|
/** Log an info message (if logging level permits) */
|
|
65
|
-
info(
|
|
65
|
+
info(...entries: LogEntry[]): void;
|
|
66
66
|
/** Log a warning message (if logging level permits) */
|
|
67
|
-
warn(
|
|
67
|
+
warn(...entries: LogEntry[]): void;
|
|
68
68
|
/** Log a diagnostics message (if logging level permits) */
|
|
69
|
-
debug(
|
|
69
|
+
debug(...entries: DebugEntry[]): void;
|
|
70
70
|
/** Get stats for current logger instance */
|
|
71
71
|
stats(): {
|
|
72
72
|
errorCount: number;
|
|
@@ -80,7 +80,12 @@ declare class TokensJSONError extends Error {
|
|
|
80
80
|
}
|
|
81
81
|
//#endregion
|
|
82
82
|
//#region src/types.d.ts
|
|
83
|
+
interface PluginHookContext {
|
|
84
|
+
logger: Logger;
|
|
85
|
+
}
|
|
83
86
|
interface BuildHookOptions {
|
|
87
|
+
/** Plugin hook context (provides access to shared logger) */
|
|
88
|
+
context: PluginHookContext;
|
|
84
89
|
/** Map of tokens */
|
|
85
90
|
tokens: Record<string, TokenNormalized$1>;
|
|
86
91
|
/** Query transformed values */
|
|
@@ -92,9 +97,11 @@ interface BuildHookOptions {
|
|
|
92
97
|
contents: string | Buffer) => void;
|
|
93
98
|
}
|
|
94
99
|
interface BuildRunnerResult {
|
|
95
|
-
outputFiles:
|
|
100
|
+
outputFiles: OutputFileExpanded[];
|
|
96
101
|
}
|
|
97
102
|
interface BuildEndHookOptions {
|
|
103
|
+
/** Plugin hook context (provides access to shared logger) */
|
|
104
|
+
context: PluginHookContext;
|
|
98
105
|
/** Map of tokens */
|
|
99
106
|
tokens: Record<string, TokenNormalized$1>;
|
|
100
107
|
/** Query transformed values */
|
|
@@ -138,6 +145,33 @@ interface Config {
|
|
|
138
145
|
deprecated?: boolean;
|
|
139
146
|
};
|
|
140
147
|
}
|
|
148
|
+
interface VisitorContext {
|
|
149
|
+
parent?: momoa.AnyNode;
|
|
150
|
+
filename: URL;
|
|
151
|
+
path: string[];
|
|
152
|
+
}
|
|
153
|
+
type Visitor<T extends momoa.AnyNode = momoa.ObjectNode | momoa.DocumentNode> = (node: T, context: VisitorContext) => T | void | null | undefined;
|
|
154
|
+
interface TransformVisitors {
|
|
155
|
+
boolean?: Visitor;
|
|
156
|
+
border?: Visitor;
|
|
157
|
+
color?: Visitor;
|
|
158
|
+
cubicBezier?: Visitor;
|
|
159
|
+
dimension?: Visitor;
|
|
160
|
+
duration?: Visitor;
|
|
161
|
+
fontFamily?: Visitor;
|
|
162
|
+
fontWeight?: Visitor;
|
|
163
|
+
gradient?: Visitor;
|
|
164
|
+
group?: Visitor;
|
|
165
|
+
link?: Visitor;
|
|
166
|
+
number?: Visitor;
|
|
167
|
+
root?: Visitor;
|
|
168
|
+
shadow?: Visitor;
|
|
169
|
+
strokeStyle?: Visitor;
|
|
170
|
+
token?: Visitor;
|
|
171
|
+
transition?: Visitor;
|
|
172
|
+
typography?: Visitor;
|
|
173
|
+
[key: string]: Visitor | undefined;
|
|
174
|
+
}
|
|
141
175
|
interface ConfigInit {
|
|
142
176
|
tokens: URL[];
|
|
143
177
|
outDir: URL;
|
|
@@ -159,13 +193,13 @@ interface ConfigOptions {
|
|
|
159
193
|
interface InputSource {
|
|
160
194
|
filename?: URL;
|
|
161
195
|
src: any;
|
|
162
|
-
document: DocumentNode;
|
|
196
|
+
document: momoa.DocumentNode;
|
|
163
197
|
}
|
|
164
198
|
interface LintNotice {
|
|
165
199
|
/** Lint message shown to the user */
|
|
166
200
|
message: string;
|
|
167
201
|
/** Erring node (used to point to a specific line) */
|
|
168
|
-
node?: AnyNode;
|
|
202
|
+
node?: momoa.AnyNode;
|
|
169
203
|
}
|
|
170
204
|
type LintRuleSeverity = 'error' | 'warn' | 'off';
|
|
171
205
|
type LintRuleShorthand = LintRuleSeverity | 0 | 1 | 2;
|
|
@@ -176,10 +210,10 @@ interface LintRuleNormalized<O = any> {
|
|
|
176
210
|
options?: O;
|
|
177
211
|
}
|
|
178
212
|
type LintReportDescriptor<MessageIds extends string> = {
|
|
179
|
-
/** To error on a specific token source file, provide
|
|
180
|
-
node?: AnyNode;
|
|
181
|
-
/** To
|
|
182
|
-
|
|
213
|
+
/** To error on a specific token source file, provide a Momoa node */
|
|
214
|
+
node?: momoa.AnyNode;
|
|
215
|
+
/** To provide correct line numbers, specify the filename (usually found on `token.source.loc`) */
|
|
216
|
+
filename?: string;
|
|
183
217
|
/** Provide data for messages */
|
|
184
218
|
data?: Record<string, unknown>;
|
|
185
219
|
} & ({
|
|
@@ -191,7 +225,7 @@ type LintReportDescriptor<MessageIds extends string> = {
|
|
|
191
225
|
/** Provide the error message ID */
|
|
192
226
|
messageId: MessageIds;
|
|
193
227
|
});
|
|
194
|
-
interface LintRule<MessageIds extends string, LintRuleOptions extends
|
|
228
|
+
interface LintRule<MessageIds extends string, LintRuleOptions extends Record<string, any> = Record<string, never>, LintRuleDocs = unknown> {
|
|
195
229
|
meta?: LintRuleMetaData<MessageIds, LintRuleOptions, LintRuleDocs>;
|
|
196
230
|
/**
|
|
197
231
|
* Function which returns an object with methods that ESLint calls to “visit”
|
|
@@ -213,8 +247,11 @@ interface LintRuleContext<MessageIds extends string, LintRuleOptions extends obj
|
|
|
213
247
|
options: LintRuleOptions;
|
|
214
248
|
/** The current working directory. */
|
|
215
249
|
cwd?: URL;
|
|
216
|
-
/**
|
|
217
|
-
|
|
250
|
+
/**
|
|
251
|
+
* All source files present in this run. To find the original source, match a
|
|
252
|
+
* token’s `source.loc` filename to one of the source’s `filename`s.
|
|
253
|
+
*/
|
|
254
|
+
sources: InputSource[];
|
|
218
255
|
/** Source file location. */
|
|
219
256
|
filename?: URL;
|
|
220
257
|
/** ID:Token map of all tokens. */
|
|
@@ -261,6 +298,29 @@ interface OutputFileExpanded extends OutputFile {
|
|
|
261
298
|
/** How long this output took to make. */
|
|
262
299
|
time: number;
|
|
263
300
|
}
|
|
301
|
+
interface ParseOptions {
|
|
302
|
+
logger?: Logger;
|
|
303
|
+
config: ConfigInit;
|
|
304
|
+
/**
|
|
305
|
+
* Skip lint step
|
|
306
|
+
* @default false
|
|
307
|
+
*/
|
|
308
|
+
skipLint?: boolean;
|
|
309
|
+
/**
|
|
310
|
+
* Continue on error? (Useful for `tz check`)
|
|
311
|
+
* @default false
|
|
312
|
+
*/
|
|
313
|
+
continueOnError?: boolean;
|
|
314
|
+
/** Provide yamlToMomoa module to parse YAML (by default, this isn’t shipped to cut down on package weight) */
|
|
315
|
+
yamlToMomoa?: typeof ytm;
|
|
316
|
+
/**
|
|
317
|
+
* Transform API
|
|
318
|
+
* @see https://terrazzo.app/docs/api/js#transform-api
|
|
319
|
+
*/
|
|
320
|
+
transform?: TransformVisitors;
|
|
321
|
+
/** (internal cache; do not use) */
|
|
322
|
+
_sources?: Record<string, InputSource>;
|
|
323
|
+
}
|
|
264
324
|
interface Plugin {
|
|
265
325
|
name: string;
|
|
266
326
|
/** Read config, and optionally modify */
|
|
@@ -276,16 +336,13 @@ interface Plugin {
|
|
|
276
336
|
lint?(): Record<string, LintRule<any, any, any>>;
|
|
277
337
|
transform?(options: TransformHookOptions): Promise<void>;
|
|
278
338
|
build?(options: BuildHookOptions): Promise<void>;
|
|
279
|
-
buildEnd?(
|
|
339
|
+
buildEnd?(options: BuildEndHookOptions): Promise<void>;
|
|
280
340
|
}
|
|
281
|
-
|
|
282
|
-
interface TokenTransformedSingleValue {
|
|
341
|
+
interface TokenTransformedBase {
|
|
283
342
|
/** Original Token ID */
|
|
284
343
|
id: string;
|
|
285
344
|
/** ID unique to this format. */
|
|
286
345
|
localID?: string;
|
|
287
|
-
type: 'SINGLE_VALUE';
|
|
288
|
-
value: string;
|
|
289
346
|
/**
|
|
290
347
|
* The mode of this value
|
|
291
348
|
* @default "."
|
|
@@ -293,22 +350,27 @@ interface TokenTransformedSingleValue {
|
|
|
293
350
|
mode: string;
|
|
294
351
|
/** The original token. */
|
|
295
352
|
token: TokenNormalized$1;
|
|
353
|
+
/** Arbitrary metadata set by plugins. */
|
|
354
|
+
meta?: Record<string | number | symbol, unknown> & {
|
|
355
|
+
/**
|
|
356
|
+
* Metadata for the token-listing plugin. Plugins can
|
|
357
|
+
* set this to be the name of a token as it appears in code,
|
|
358
|
+
* and the token-listing plugin will pick it up and use it.
|
|
359
|
+
*/
|
|
360
|
+
'token-listing'?: {
|
|
361
|
+
name: string | undefined;
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
/** Transformed token with a single value. Note that this may be any type! */
|
|
366
|
+
interface TokenTransformedSingleValue extends TokenTransformedBase {
|
|
367
|
+
type: 'SINGLE_VALUE';
|
|
368
|
+
value: string;
|
|
296
369
|
}
|
|
297
370
|
/** Transformed token with multiple values. Note that this may be any type! */
|
|
298
|
-
interface TokenTransformedMultiValue {
|
|
299
|
-
/** Original Token ID */
|
|
300
|
-
id: string;
|
|
301
|
-
/** ID unique to this format.*/
|
|
302
|
-
localID?: string;
|
|
371
|
+
interface TokenTransformedMultiValue extends TokenTransformedBase {
|
|
303
372
|
type: 'MULTI_VALUE';
|
|
304
373
|
value: Record<string, string>;
|
|
305
|
-
/**
|
|
306
|
-
* The mode of this value
|
|
307
|
-
* @default "."
|
|
308
|
-
*/
|
|
309
|
-
mode: string;
|
|
310
|
-
/** The original token */
|
|
311
|
-
token: TokenNormalized$1;
|
|
312
374
|
}
|
|
313
375
|
type TokenTransformed = TokenTransformedSingleValue | TokenTransformedMultiValue;
|
|
314
376
|
interface TransformParams {
|
|
@@ -325,6 +387,8 @@ interface TransformParams {
|
|
|
325
387
|
mode?: string | string[];
|
|
326
388
|
}
|
|
327
389
|
interface TransformHookOptions {
|
|
390
|
+
/** Plugin hook context (provides access to shared logger) */
|
|
391
|
+
context: PluginHookContext;
|
|
328
392
|
/** Map of tokens */
|
|
329
393
|
tokens: Record<string, TokenNormalized$1>;
|
|
330
394
|
/** Query transformed values */
|
|
@@ -335,17 +399,21 @@ interface TransformHookOptions {
|
|
|
335
399
|
localID?: string;
|
|
336
400
|
value: string | Record<string, string>;
|
|
337
401
|
mode?: string;
|
|
402
|
+
meta?: TokenTransformedBase['meta'];
|
|
338
403
|
}): void;
|
|
339
404
|
/** Momoa documents */
|
|
340
405
|
sources: InputSource[];
|
|
341
406
|
}
|
|
407
|
+
interface ReferenceObject {
|
|
408
|
+
$ref: string;
|
|
409
|
+
}
|
|
342
410
|
//#endregion
|
|
343
411
|
//#region src/build/index.d.ts
|
|
344
412
|
interface BuildRunnerOptions {
|
|
345
413
|
sources: {
|
|
346
414
|
filename?: URL;
|
|
347
415
|
src: string;
|
|
348
|
-
document: DocumentNode;
|
|
416
|
+
document: momoa.DocumentNode;
|
|
349
417
|
}[];
|
|
350
418
|
config: ConfigInit;
|
|
351
419
|
logger?: Logger;
|
|
@@ -370,308 +438,28 @@ declare function defineConfig(rawConfig: Config, {
|
|
|
370
438
|
/** Merge configs */
|
|
371
439
|
declare function mergeConfigs(a: Config, b: Config): Config;
|
|
372
440
|
//#endregion
|
|
441
|
+
//#region src/lint/plugin-core/index.d.ts
|
|
442
|
+
declare const RECOMMENDED_CONFIG: Record<string, LintRuleLonghand>;
|
|
443
|
+
//#endregion
|
|
373
444
|
//#region src/lint/index.d.ts
|
|
374
445
|
interface LintRunnerOptions {
|
|
375
|
-
tokens:
|
|
446
|
+
tokens: TokenNormalizedSet$1;
|
|
376
447
|
filename?: URL;
|
|
377
448
|
config: ConfigInit;
|
|
378
|
-
|
|
449
|
+
sources: InputSource[];
|
|
379
450
|
logger: Logger;
|
|
380
451
|
}
|
|
381
452
|
declare function lintRunner({
|
|
382
453
|
tokens,
|
|
383
454
|
filename,
|
|
384
455
|
config,
|
|
385
|
-
|
|
456
|
+
sources,
|
|
386
457
|
logger
|
|
387
458
|
}: LintRunnerOptions): Promise<void>;
|
|
388
459
|
//#endregion
|
|
389
|
-
//#region src/parse/normalize.d.ts
|
|
390
|
-
declare const FONT_WEIGHT_MAP: {
|
|
391
|
-
thin: number;
|
|
392
|
-
hairline: number;
|
|
393
|
-
'extra-light': number;
|
|
394
|
-
'ultra-light': number;
|
|
395
|
-
light: number;
|
|
396
|
-
normal: number;
|
|
397
|
-
regular: number;
|
|
398
|
-
book: number;
|
|
399
|
-
medium: number;
|
|
400
|
-
'semi-bold': number;
|
|
401
|
-
'demi-bold': number;
|
|
402
|
-
bold: number;
|
|
403
|
-
'extra-bold': number;
|
|
404
|
-
'ultra-bold': number;
|
|
405
|
-
black: number;
|
|
406
|
-
heavy: number;
|
|
407
|
-
'extra-black': number;
|
|
408
|
-
'ultra-black': number;
|
|
409
|
-
};
|
|
410
|
-
/** Fill in defaults, and return predictable shapes for tokens */
|
|
411
|
-
declare function normalizeValue<T extends Token$1>(token: T): T['$value'];
|
|
412
|
-
//#endregion
|
|
413
|
-
//#region src/parse/validate.d.ts
|
|
414
|
-
interface ValidateOptions {
|
|
415
|
-
filename?: URL;
|
|
416
|
-
src: string;
|
|
417
|
-
logger: Logger;
|
|
418
|
-
}
|
|
419
|
-
interface Visitors {
|
|
420
|
-
color?: Visitor;
|
|
421
|
-
dimension?: Visitor;
|
|
422
|
-
fontFamily?: Visitor;
|
|
423
|
-
fontWeight?: Visitor;
|
|
424
|
-
duration?: Visitor;
|
|
425
|
-
cubicBezier?: Visitor;
|
|
426
|
-
number?: Visitor;
|
|
427
|
-
link?: Visitor;
|
|
428
|
-
boolean?: Visitor;
|
|
429
|
-
strokeStyle?: Visitor;
|
|
430
|
-
border?: Visitor;
|
|
431
|
-
transition?: Visitor;
|
|
432
|
-
shadow?: Visitor;
|
|
433
|
-
gradient?: Visitor;
|
|
434
|
-
typography?: Visitor;
|
|
435
|
-
root?: Visitor;
|
|
436
|
-
group?: Visitor;
|
|
437
|
-
[key: string]: Visitor | undefined;
|
|
438
|
-
}
|
|
439
|
-
type Visitor = (json: any, path: string, ast: AnyNode) => any | undefined | null;
|
|
440
|
-
declare const VALID_COLORSPACES: Set<string>;
|
|
441
|
-
declare const FONT_WEIGHT_VALUES: Set<string>;
|
|
442
|
-
declare const STROKE_STYLE_VALUES: Set<string>;
|
|
443
|
-
declare const STROKE_STYLE_LINE_CAP_VALUES: Set<string>;
|
|
444
|
-
/** Verify an Alias $value is formatted correctly */
|
|
445
|
-
declare function validateAliasSyntax($value: ValueNode, _node: AnyNode, {
|
|
446
|
-
filename,
|
|
447
|
-
src,
|
|
448
|
-
logger
|
|
449
|
-
}: ValidateOptions): void;
|
|
450
|
-
/** Verify a Border token is valid */
|
|
451
|
-
declare function validateBorder($value: ValueNode, node: AnyNode, {
|
|
452
|
-
filename,
|
|
453
|
-
src,
|
|
454
|
-
logger
|
|
455
|
-
}: ValidateOptions): void;
|
|
456
|
-
/** Verify a Color token is valid */
|
|
457
|
-
declare function validateColor($value: ValueNode, node: AnyNode, {
|
|
458
|
-
filename,
|
|
459
|
-
src,
|
|
460
|
-
logger
|
|
461
|
-
}: ValidateOptions): void;
|
|
462
|
-
/** Verify a Cubic Bézier token is valid */
|
|
463
|
-
declare function validateCubicBezier($value: ValueNode, _node: AnyNode, {
|
|
464
|
-
filename,
|
|
465
|
-
src,
|
|
466
|
-
logger
|
|
467
|
-
}: ValidateOptions): void;
|
|
468
|
-
/** Verify a Dimension token is valid */
|
|
469
|
-
declare function validateDimension($value: ValueNode, _node: AnyNode, {
|
|
470
|
-
filename,
|
|
471
|
-
src,
|
|
472
|
-
logger
|
|
473
|
-
}: ValidateOptions): void;
|
|
474
|
-
/** Verify a Duration token is valid */
|
|
475
|
-
declare function validateDuration($value: ValueNode, _node: AnyNode, {
|
|
476
|
-
filename,
|
|
477
|
-
src,
|
|
478
|
-
logger
|
|
479
|
-
}: ValidateOptions): void;
|
|
480
|
-
/** Verify a Font Family token is valid */
|
|
481
|
-
declare function validateFontFamily($value: ValueNode, _node: AnyNode, {
|
|
482
|
-
filename,
|
|
483
|
-
src,
|
|
484
|
-
logger
|
|
485
|
-
}: ValidateOptions): void;
|
|
486
|
-
/** Verify a Font Weight token is valid */
|
|
487
|
-
declare function validateFontWeight($value: ValueNode, _node: AnyNode, {
|
|
488
|
-
filename,
|
|
489
|
-
src,
|
|
490
|
-
logger
|
|
491
|
-
}: ValidateOptions): void;
|
|
492
|
-
/** Verify a Gradient token is valid */
|
|
493
|
-
declare function validateGradient($value: ValueNode, _node: AnyNode, {
|
|
494
|
-
filename,
|
|
495
|
-
src,
|
|
496
|
-
logger
|
|
497
|
-
}: ValidateOptions): void;
|
|
498
|
-
/** Verify a Number token is valid */
|
|
499
|
-
declare function validateNumber($value: ValueNode, _node: AnyNode, {
|
|
500
|
-
filename,
|
|
501
|
-
src,
|
|
502
|
-
logger
|
|
503
|
-
}: ValidateOptions): void;
|
|
504
|
-
/** Verify a Boolean token is valid */
|
|
505
|
-
declare function validateBoolean($value: ValueNode, _node: AnyNode, {
|
|
506
|
-
filename,
|
|
507
|
-
src,
|
|
508
|
-
logger
|
|
509
|
-
}: ValidateOptions): void;
|
|
510
|
-
/** Verify a Shadow token’s value is valid */
|
|
511
|
-
declare function validateShadowLayer($value: ValueNode, node: AnyNode, {
|
|
512
|
-
filename,
|
|
513
|
-
src,
|
|
514
|
-
logger
|
|
515
|
-
}: ValidateOptions): void;
|
|
516
|
-
/** Verify a Stroke Style token is valid. */
|
|
517
|
-
declare function validateStrokeStyle($value: ValueNode, node: AnyNode, {
|
|
518
|
-
filename,
|
|
519
|
-
src,
|
|
520
|
-
logger
|
|
521
|
-
}: ValidateOptions): void;
|
|
522
|
-
/** Verify a Transition token is valid */
|
|
523
|
-
declare function validateTransition($value: ValueNode, node: AnyNode, {
|
|
524
|
-
filename,
|
|
525
|
-
src,
|
|
526
|
-
logger
|
|
527
|
-
}: ValidateOptions): void;
|
|
528
|
-
/**
|
|
529
|
-
* Validate a MemberNode (the entire token object, plus its key in the parent
|
|
530
|
-
* object) to see if it’s a valid DTCG token or not. Keeping the parent key
|
|
531
|
-
* really helps in debug messages.
|
|
532
|
-
*/
|
|
533
|
-
declare function validateTokenMemberNode(node: MemberNode, {
|
|
534
|
-
filename,
|
|
535
|
-
src,
|
|
536
|
-
logger
|
|
537
|
-
}: ValidateOptions): void;
|
|
538
|
-
/** Return whether a MemberNode is a group (has no `$value`).
|
|
539
|
-
* Groups can have properties that their child nodes will inherit. */
|
|
540
|
-
declare function isGroupNode(node: ObjectNode): boolean;
|
|
541
|
-
/** Check if a token node has the specified property name, and if it does, stores
|
|
542
|
-
* the value in the `inherited` object as a side effect for future use. If not,
|
|
543
|
-
* traverses the `inherited` object to find the closest parent that has the property.
|
|
544
|
-
*
|
|
545
|
-
* Returns the property value if found locally or in a parent, otherwise undefined. */
|
|
546
|
-
declare function computeInheritedProperty(node: MemberNode, propertyName: string, {
|
|
547
|
-
subpath,
|
|
548
|
-
inherited
|
|
549
|
-
}: {
|
|
550
|
-
subpath: string[];
|
|
551
|
-
inherited?: Record<string, MemberNode>;
|
|
552
|
-
}): MemberNode | undefined;
|
|
553
|
-
interface ValidateTokenNodeOptions {
|
|
554
|
-
subpath: string[];
|
|
555
|
-
src: string;
|
|
556
|
-
filename: URL;
|
|
557
|
-
config: ConfigInit;
|
|
558
|
-
logger: Logger;
|
|
559
|
-
parent: AnyNode | undefined;
|
|
560
|
-
transform?: Visitors;
|
|
561
|
-
inheritedDeprecatedNode?: MemberNode;
|
|
562
|
-
inheritedTypeNode?: MemberNode;
|
|
563
|
-
}
|
|
564
|
-
/**
|
|
565
|
-
* Validate does a little more than validate; it also converts to TokenNormalized
|
|
566
|
-
* and sets up the basic data structure. But aliases are unresolved, and we need
|
|
567
|
-
* a 2nd normalization pass afterward.
|
|
568
|
-
*/
|
|
569
|
-
declare function validateTokenNode(node: MemberNode, {
|
|
570
|
-
config,
|
|
571
|
-
filename,
|
|
572
|
-
logger,
|
|
573
|
-
parent,
|
|
574
|
-
inheritedDeprecatedNode,
|
|
575
|
-
inheritedTypeNode,
|
|
576
|
-
src,
|
|
577
|
-
subpath
|
|
578
|
-
}: ValidateTokenNodeOptions): TokenNormalized$1 | undefined;
|
|
579
|
-
//#endregion
|
|
580
|
-
//#region src/parse/alias.d.ts
|
|
581
|
-
interface ApplyAliasOptions {
|
|
582
|
-
tokensSet: TokenNormalizedSet$1;
|
|
583
|
-
filename: URL;
|
|
584
|
-
src: string;
|
|
585
|
-
node: ObjectNode;
|
|
586
|
-
logger: Logger;
|
|
587
|
-
}
|
|
588
|
-
type PreAliased<T extends TokenNormalized$1> = {
|
|
589
|
-
$value: T['$value'] | string;
|
|
590
|
-
mode: Record<string, T['mode'][string] & {
|
|
591
|
-
$value: T['$value'] | string;
|
|
592
|
-
}>;
|
|
593
|
-
};
|
|
594
|
-
//#endregion
|
|
595
|
-
//#region src/parse/json.d.ts
|
|
596
|
-
interface JSONVisitor {
|
|
597
|
-
enter?: (node: AnyNode, parent: AnyNode | undefined, path: string[]) => void;
|
|
598
|
-
exit?: (node: AnyNode, parent: AnyNode | undefined, path: string[]) => void;
|
|
599
|
-
}
|
|
600
|
-
declare const CHILD_KEYS: {
|
|
601
|
-
Document: readonly ["body"];
|
|
602
|
-
Object: readonly ["members"];
|
|
603
|
-
Member: readonly ["name", "value"];
|
|
604
|
-
Element: readonly ["value"];
|
|
605
|
-
Array: readonly ["elements"];
|
|
606
|
-
String: readonly [];
|
|
607
|
-
Number: readonly [];
|
|
608
|
-
Boolean: readonly [];
|
|
609
|
-
Null: readonly [];
|
|
610
|
-
Identifier: readonly [];
|
|
611
|
-
NaN: readonly [];
|
|
612
|
-
Infinity: readonly [];
|
|
613
|
-
};
|
|
614
|
-
/** Determines if a given value is an AST node. */
|
|
615
|
-
declare function isNode(value: unknown): boolean;
|
|
616
|
-
type ValueNodeWithIndex = ValueNode & {
|
|
617
|
-
index: number;
|
|
618
|
-
};
|
|
619
|
-
/** Get ObjectNode members as object */
|
|
620
|
-
declare function getObjMembers(node: ObjectNode): Record<string | number, ValueNodeWithIndex>;
|
|
621
|
-
/** Inject members to ObjectNode */
|
|
622
|
-
declare function injectObjMembers(node: ObjectNode, members?: MemberNode[]): void;
|
|
623
|
-
/** Replace an ObjectNode’s contents outright with another */
|
|
624
|
-
declare function replaceObjMembers(a: ObjectNode, b: DocumentNode | ObjectNode): void;
|
|
625
|
-
/**
|
|
626
|
-
* Variation of Momoa’s traverse(), which keeps track of global path.
|
|
627
|
-
* Allows mutation of AST (along with any consequences)
|
|
628
|
-
*/
|
|
629
|
-
declare function traverse(root: AnyNode, visitor: JSONVisitor): void;
|
|
630
|
-
/** Determine if an input is likely a JSON string */
|
|
631
|
-
declare function maybeRawJSON(input: string): boolean;
|
|
632
|
-
/** Find Momoa node by traversing paths */
|
|
633
|
-
declare function findNode<T = AnyNode>(node: AnyNode, path: string[]): T | undefined;
|
|
634
|
-
interface ToMomoaOptions {
|
|
635
|
-
filename?: URL;
|
|
636
|
-
continueOnError?: boolean;
|
|
637
|
-
logger: Logger;
|
|
638
|
-
yamlToMomoa?: typeof ytm;
|
|
639
|
-
}
|
|
640
|
-
declare function toMomoa(input: string | Record<string, any>, {
|
|
641
|
-
continueOnError,
|
|
642
|
-
filename,
|
|
643
|
-
logger,
|
|
644
|
-
yamlToMomoa: ytm
|
|
645
|
-
}: ToMomoaOptions): InputSource;
|
|
646
|
-
/** Momoa, just with default options pre-set */
|
|
647
|
-
declare function parseJSON(input: string | Record<string, any>, options?: ParseOptions$1): any;
|
|
648
|
-
//#endregion
|
|
649
460
|
//#region src/parse/index.d.ts
|
|
650
|
-
interface ParseOptions {
|
|
651
|
-
logger?: Logger;
|
|
652
|
-
config: ConfigInit;
|
|
653
|
-
/**
|
|
654
|
-
* Skip lint step
|
|
655
|
-
* @default false
|
|
656
|
-
*/
|
|
657
|
-
skipLint?: boolean;
|
|
658
|
-
/**
|
|
659
|
-
* Continue on error? (Useful for `tz check`)
|
|
660
|
-
* @default false
|
|
661
|
-
*/
|
|
662
|
-
continueOnError?: boolean;
|
|
663
|
-
/** Provide yamlToMomoa module to parse YAML (by default, this isn’t shipped to cut down on package weight) */
|
|
664
|
-
yamlToMomoa?: typeof ytm;
|
|
665
|
-
/**
|
|
666
|
-
* Transform API
|
|
667
|
-
* @see https://terrazzo.app/docs/api/js#transform-api
|
|
668
|
-
*/
|
|
669
|
-
transform?: Visitors;
|
|
670
|
-
/** (internal cache; do not use) */
|
|
671
|
-
_sources?: Record<string, InputSource>;
|
|
672
|
-
}
|
|
673
461
|
interface ParseResult {
|
|
674
|
-
tokens:
|
|
462
|
+
tokens: TokenNormalizedSet$1;
|
|
675
463
|
sources: InputSource[];
|
|
676
464
|
}
|
|
677
465
|
/** Parse */
|
|
@@ -681,9 +469,8 @@ declare function parse(_input: Omit<InputSource, 'document'> | Omit<InputSource,
|
|
|
681
469
|
config,
|
|
682
470
|
continueOnError,
|
|
683
471
|
yamlToMomoa,
|
|
684
|
-
transform
|
|
685
|
-
_sources
|
|
472
|
+
transform
|
|
686
473
|
}?: ParseOptions): Promise<ParseResult>;
|
|
687
474
|
//#endregion
|
|
688
|
-
export { type AliasToken, type AliasValue,
|
|
475
|
+
export { type AliasToken, type AliasValue, type BooleanToken, type BooleanTokenNormalized, type BooleanValue, type BorderToken, type BorderTokenNormalized, type BorderValue, type BorderValueNormalized, BuildEndHookOptions, BuildHookOptions, BuildRunnerOptions, BuildRunnerResult, type ColorSpace, type ColorToken, type ColorTokenNormalized, type ColorValue, type ColorValueNormalized, Config, ConfigInit, ConfigOptions, type CubicBezierToken, type CubicBezierTokenNormalized, type CubicBezierValue, type CustomTransformOptions, DebugEntry, type DimensionToken, type DimensionTokenNormalized, type DimensionValue, type DurationToken, type DurationTokenNormalized, type DurationValue, type FontFamilyToken, type FontFamilyTokenNormalized, type FontFamilyValue, type FontFamilyValueNormalized, type FontWeightToken, type FontWeightTokenNormalized, type FontWeightValue, type FontWeightValueNormalized, type GradientStop, type GradientStopNormalized, type GradientToken, type GradientTokenNormalized, type GradientValue, type GradientValueNormalized, type Group, type GroupCore, type GroupOrToken, InputSource, LOG_ORDER, type LinkToken, type LinkTokenNormalized, type LinkValue, LintNotice, LintReportDescriptor, LintRule, LintRuleContext, LintRuleLonghand, LintRuleMetaData, LintRuleMetaDataDocs, LintRuleNormalized, LintRuleSeverity, LintRuleShorthand, LintRunnerOptions, LogEntry, LogGroup, LogLevel, LogSeverity, Logger, MULTI_VALUE, type ModeMap, type NumberToken, type NumberTokenNormalized, type NumberValue, OutputFile, OutputFileExpanded, ParseOptions, ParseResult, Plugin, PluginHookContext, RECOMMENDED_CONFIG, ReferenceObject, SINGLE_VALUE, type ShadowToken, type ShadowTokenNormalized, type ShadowValue, type ShadowValueNormalized, type StringToken, type StringTokenNormalized, type StringValue, type StrokeStyleToken, type StrokeStyleTokenNormalized, type StrokeStyleValue, type StrokeStyleValueExpanded, type Token, type TokenCore, type TokenMode, type TokenNormalized, type TokenNormalizedCore, type TokenNormalizedSet, TokenTransformed, TokenTransformedMultiValue, TokenTransformedSingleValue, TokensJSONError, type TokensSet, TransformHookOptions, TransformParams, TransformVisitors, type TransitionToken, type TransitionTokenNormalized, type TransitionValue, type TransitionValueNormalized, type TypographyToken, type TypographyTokenNormalized, type TypographyValue, type TypographyValueNormalized, Visitor, VisitorContext, build, defineConfig, formatMessage, lintRunner, mergeConfigs, parse };
|
|
689
476
|
//# sourceMappingURL=index.d.ts.map
|