@terrazzo/parser 0.0.10 → 0.0.11
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 -1
- package/package.json +2 -2
- package/parse/normalize.js +8 -2
- package/parse/validate.d.ts +2 -2
- package/parse/validate.js +3 -3
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrazzo/parser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Parser/validator for the Design Tokens Community Group (DTCG) standard.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"lint": "biome check .",
|
|
49
|
-
"test": "pnpm run \"/^test:.*/\"",
|
|
49
|
+
"test": "pnpm --filter @terrazzo/parser run \"/^test:.*/\"",
|
|
50
50
|
"test:js": "vitest run",
|
|
51
51
|
"test:ts": "tsc --noEmit"
|
|
52
52
|
}
|
package/parse/normalize.js
CHANGED
|
@@ -49,7 +49,7 @@ export default function normalizeValue(token) {
|
|
|
49
49
|
}
|
|
50
50
|
case 'dimension': {
|
|
51
51
|
if (token.$value === 0) {
|
|
52
|
-
return 0;
|
|
52
|
+
return '0';
|
|
53
53
|
}
|
|
54
54
|
return typeof token.$value === 'number' ? `${token.$value}px` : token.$value;
|
|
55
55
|
}
|
|
@@ -84,7 +84,13 @@ export default function normalizeValue(token) {
|
|
|
84
84
|
return typeof token.$value === 'number' ? token.$value : Number.parseFloat(token.$value);
|
|
85
85
|
}
|
|
86
86
|
case 'shadow': {
|
|
87
|
-
return Array.isArray(token.$value) ? token.$value : [token.$value]
|
|
87
|
+
return (Array.isArray(token.$value) ? token.$value : [token.$value]).map((layer) => ({
|
|
88
|
+
color: normalizeValue({ $type: 'color', $value: layer.color }),
|
|
89
|
+
offsetX: normalizeValue({ $type: 'dimension', $value: layer.offsetX ?? 0 }),
|
|
90
|
+
offsetY: normalizeValue({ $type: 'dimension', $value: layer.offsetY ?? 0 }),
|
|
91
|
+
blur: normalizeValue({ $type: 'dimension', $value: layer.blur ?? 0 }),
|
|
92
|
+
spread: normalizeValue({ $type: 'dimension', $value: layer.spread ?? 0 }),
|
|
93
|
+
}));
|
|
88
94
|
}
|
|
89
95
|
case 'strokeStyle': {
|
|
90
96
|
return token.$value;
|
package/parse/validate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyNode,
|
|
1
|
+
import type { AnyNode, MemberNode, ValueNode } from '@humanwhocodes/momoa';
|
|
2
2
|
import type Logger from '../logger.js';
|
|
3
3
|
|
|
4
4
|
declare const FONT_WEIGHT_VALUES: Set<string>;
|
|
@@ -17,7 +17,7 @@ export function validateBorder($value: ValueNode, node: AnyNode, options: Valida
|
|
|
17
17
|
|
|
18
18
|
export function validateColor($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
19
19
|
|
|
20
|
-
export function
|
|
20
|
+
export function validateCubicBezier($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
21
21
|
|
|
22
22
|
export function validateDimension($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
23
23
|
|
package/parse/validate.js
CHANGED
|
@@ -220,7 +220,7 @@ export function validateColor($value, node, { source, logger }) {
|
|
|
220
220
|
* @param {ValidateOptions} options
|
|
221
221
|
* @return {void}
|
|
222
222
|
*/
|
|
223
|
-
export function
|
|
223
|
+
export function validateCubicBezier($value, node, { source, logger }) {
|
|
224
224
|
if ($value.type !== 'Array') {
|
|
225
225
|
logger.error({ message: `Expected array of strings, received ${print($value)}`, node: $value, source });
|
|
226
226
|
} else if (
|
|
@@ -494,7 +494,7 @@ export function validateTransition($value, node, { source, logger }) {
|
|
|
494
494
|
{
|
|
495
495
|
duration: { validator: validateDuration, required: true },
|
|
496
496
|
delay: { validator: validateDuration, required: false }, // note: spec says delay is required, but Terrazzo makes delay optional
|
|
497
|
-
timingFunction: { validator:
|
|
497
|
+
timingFunction: { validator: validateCubicBezier, required: true },
|
|
498
498
|
},
|
|
499
499
|
node,
|
|
500
500
|
{ source, logger },
|
|
@@ -544,7 +544,7 @@ export default function validate(node, { source, logger }) {
|
|
|
544
544
|
break;
|
|
545
545
|
}
|
|
546
546
|
case 'cubicBezier': {
|
|
547
|
-
|
|
547
|
+
validateCubicBezier($value, node, { logger, source });
|
|
548
548
|
break;
|
|
549
549
|
}
|
|
550
550
|
case 'dimension': {
|