@projectwallace/css-design-tokens 0.11.2 → 0.11.3
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/dist/index.js +26 -26
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import { analyze, colorFunctions, colorKeywords, cssKeywords, namedColors, syste
|
|
|
2
2
|
import { convert } from "css-time-sort";
|
|
3
3
|
import { convert as convert$1 } from "color-sorter";
|
|
4
4
|
import { parse_value } from "@projectwallace/css-parser/parse-value";
|
|
5
|
+
import { DIMENSION, FUNCTION, HASH, IDENTIFIER, NUMBER, OPERATOR } from "@projectwallace/css-parser/nodes";
|
|
5
6
|
import { A98RGB, A98RGB_Linear, ColorSpace, HSL, HSV, HWB, LCH, Lab, Lab_D65, OKLCH, OKLab, OKLrab, P3, P3_Linear, ProPhoto, ProPhoto_Linear, REC_2020, REC_2020_Linear, XYZ_ABS_D65, XYZ_D50, XYZ_D65, sRGB, sRGB_Linear, tryColor } from "colorjs.io/fn";
|
|
6
|
-
import { parse_value as parse_value$1 } from "@projectwallace/css-parser";
|
|
7
7
|
//#region src/group-colors.ts
|
|
8
8
|
const white = 0;
|
|
9
9
|
const black = 1;
|
|
@@ -126,16 +126,16 @@ function destructure_box_shadow(value) {
|
|
|
126
126
|
let ast = parse_value(value);
|
|
127
127
|
let current_shadow = create_destructured();
|
|
128
128
|
let destructured = [current_shadow];
|
|
129
|
-
if (ast.
|
|
130
|
-
for (let node of ast
|
|
129
|
+
if (ast.child_count < 2) return null;
|
|
130
|
+
for (let node of ast) if (node.type === IDENTIFIER) {
|
|
131
131
|
if (node.name.toLowerCase() === "inset") current_shadow.inset = true;
|
|
132
|
-
else if (namedColors.has(node.name) || systemColors.has(node.name)) {
|
|
132
|
+
else if (node.name && (namedColors.has(node.name) || systemColors.has(node.name))) {
|
|
133
133
|
let color_token = color_to_token(node.name);
|
|
134
134
|
if (color_token === null) continue;
|
|
135
135
|
current_shadow.color = color_token;
|
|
136
136
|
}
|
|
137
|
-
} else if (node.
|
|
138
|
-
let length = node.
|
|
137
|
+
} else if (node.type === DIMENSION || node.type === NUMBER && node.value === 0) {
|
|
138
|
+
let length = node.type === DIMENSION ? {
|
|
139
139
|
value: Number(node.value),
|
|
140
140
|
unit: node.unit
|
|
141
141
|
} : {
|
|
@@ -146,21 +146,21 @@ function destructure_box_shadow(value) {
|
|
|
146
146
|
else if (!current_shadow.offsetY) current_shadow.offsetY = length;
|
|
147
147
|
else if (!current_shadow.blur) current_shadow.blur = length;
|
|
148
148
|
else if (!current_shadow.spread) current_shadow.spread = length;
|
|
149
|
-
} else if (node.
|
|
149
|
+
} else if (node.type === FUNCTION) {
|
|
150
150
|
if (colorFunctions.has(node.name)) {
|
|
151
151
|
let color_token = color_to_token(node.text);
|
|
152
152
|
if (color_token === null) continue;
|
|
153
153
|
current_shadow.color = color_token;
|
|
154
|
-
} else if (node.name
|
|
154
|
+
} else if (node.name.toLowerCase() === "var" && !current_shadow.color) {
|
|
155
155
|
let color_token = color_to_token(node.text);
|
|
156
156
|
if (color_token === null) continue;
|
|
157
157
|
current_shadow.color = color_token;
|
|
158
158
|
}
|
|
159
|
-
} else if (node.
|
|
159
|
+
} else if (node.type === HASH) {
|
|
160
160
|
let color_token = color_to_token(node.text);
|
|
161
161
|
if (color_token === null) continue;
|
|
162
162
|
current_shadow.color = color_token;
|
|
163
|
-
} else if (node.
|
|
163
|
+
} else if (node.type === OPERATOR && node.value === ",") {
|
|
164
164
|
complete_shadow_token(current_shadow);
|
|
165
165
|
current_shadow = create_destructured();
|
|
166
166
|
destructured.push(current_shadow);
|
|
@@ -245,15 +245,15 @@ function destructure_font_family(value) {
|
|
|
245
245
|
let family_buffer = "";
|
|
246
246
|
let prev_type;
|
|
247
247
|
for (let node of children) {
|
|
248
|
-
if (node.
|
|
248
|
+
if (node.type === OPERATOR && node.value === ",") {
|
|
249
249
|
families.push(unquote(family_buffer));
|
|
250
250
|
family_buffer = "";
|
|
251
|
-
prev_type = node.
|
|
251
|
+
prev_type = node.type;
|
|
252
252
|
continue;
|
|
253
253
|
}
|
|
254
|
-
if (prev_type ===
|
|
254
|
+
if (prev_type === IDENTIFIER && node.type === IDENTIFIER) family_buffer += " ";
|
|
255
255
|
family_buffer += node.text;
|
|
256
|
-
prev_type = node.
|
|
256
|
+
prev_type = node.type;
|
|
257
257
|
}
|
|
258
258
|
families.push(unquote(family_buffer));
|
|
259
259
|
return families;
|
|
@@ -283,12 +283,12 @@ const ALLOWED_UNITS = new Set(["px", "rem"]);
|
|
|
283
283
|
* - the keyword `normal`.
|
|
284
284
|
*/
|
|
285
285
|
function destructure_line_height(value) {
|
|
286
|
-
let ast = parse_value
|
|
286
|
+
let ast = parse_value(value);
|
|
287
287
|
if (!ast.has_children) return null;
|
|
288
|
-
if (ast.
|
|
288
|
+
if (ast.child_count !== 1) return null;
|
|
289
289
|
let maybe_dimension = ast.first_child;
|
|
290
|
-
switch (maybe_dimension.
|
|
291
|
-
case
|
|
290
|
+
switch (maybe_dimension.type) {
|
|
291
|
+
case DIMENSION: {
|
|
292
292
|
let { value, unit } = maybe_dimension;
|
|
293
293
|
if (value === 0) return 0;
|
|
294
294
|
if (unit === "%") return Number(value) / 100;
|
|
@@ -299,8 +299,8 @@ function destructure_line_height(value) {
|
|
|
299
299
|
};
|
|
300
300
|
return null;
|
|
301
301
|
}
|
|
302
|
-
case
|
|
303
|
-
case
|
|
302
|
+
case NUMBER: return Number(maybe_dimension.value);
|
|
303
|
+
case IDENTIFIER: if (maybe_dimension.name.toLowerCase() === "normal") return 1.2;
|
|
304
304
|
}
|
|
305
305
|
return null;
|
|
306
306
|
}
|
|
@@ -324,11 +324,11 @@ let absolute_size_map = new Map([
|
|
|
324
324
|
* - the keyword `normal`.
|
|
325
325
|
*/
|
|
326
326
|
function parse_length(value) {
|
|
327
|
-
let ast = parse_value
|
|
328
|
-
if (!ast.has_children || ast.
|
|
327
|
+
let ast = parse_value(value);
|
|
328
|
+
if (!ast.has_children || ast.child_count !== 1) return null;
|
|
329
329
|
let maybe_length = ast.first_child;
|
|
330
|
-
switch (maybe_length.
|
|
331
|
-
case
|
|
330
|
+
switch (maybe_length.type) {
|
|
331
|
+
case DIMENSION: {
|
|
332
332
|
let unit = maybe_length.unit.toLowerCase();
|
|
333
333
|
if (unit === "px" || unit === "rem") {
|
|
334
334
|
let value = Number(maybe_length.value);
|
|
@@ -343,7 +343,7 @@ function parse_length(value) {
|
|
|
343
343
|
}
|
|
344
344
|
break;
|
|
345
345
|
}
|
|
346
|
-
case
|
|
346
|
+
case IDENTIFIER: {
|
|
347
347
|
let name = maybe_length.name.toLowerCase();
|
|
348
348
|
if (absolute_size_map.has(name)) return {
|
|
349
349
|
value: absolute_size_map.get(name),
|
|
@@ -351,7 +351,7 @@ function parse_length(value) {
|
|
|
351
351
|
};
|
|
352
352
|
break;
|
|
353
353
|
}
|
|
354
|
-
case
|
|
354
|
+
case NUMBER:
|
|
355
355
|
if (Number(maybe_length.value) === 0) return {
|
|
356
356
|
value: 0,
|
|
357
357
|
unit: "px"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@projectwallace/css-design-tokens",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"description": "Generate spec-compliant Design Tokens from CSS.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"color",
|
|
@@ -34,21 +34,21 @@
|
|
|
34
34
|
"lint": "oxlint; oxfmt --check"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@projectwallace/css-analyzer": "^9.
|
|
38
|
-
"@projectwallace/css-parser": "^0.
|
|
37
|
+
"@projectwallace/css-analyzer": "^9.6.2",
|
|
38
|
+
"@projectwallace/css-parser": "^0.14.8",
|
|
39
39
|
"color-sorter": "^7.0.2",
|
|
40
40
|
"colorjs.io": "^0.6.1",
|
|
41
41
|
"css-time-sort": "^3.0.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@codecov/rollup-plugin": "^1.9.1",
|
|
45
|
-
"@vitest/coverage-v8": "^4.
|
|
46
|
-
"oxfmt": "^0.
|
|
47
|
-
"oxlint": "^1.
|
|
45
|
+
"@vitest/coverage-v8": "^4.1.2",
|
|
46
|
+
"oxfmt": "^0.43.0",
|
|
47
|
+
"oxlint": "^1.58.0",
|
|
48
48
|
"publint": "^0.3.18",
|
|
49
|
-
"tsdown": "^0.21.
|
|
50
|
-
"typescript": "^
|
|
51
|
-
"vitest": "^4.
|
|
49
|
+
"tsdown": "^0.21.7",
|
|
50
|
+
"typescript": "^6.0.2",
|
|
51
|
+
"vitest": "^4.1.2"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=22"
|