@projectwallace/css-design-tokens 0.11.2 → 0.11.4

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.
Files changed (2) hide show
  1. package/dist/index.js +30 -31
  2. package/package.json +11 -11
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.children.length < 2) return null;
130
- for (let node of ast.children) if (node.type_name === "Identifier") {
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.type_name === "Dimension" || node.type_name === "Number" && node.value === 0) {
138
- let length = node.type_name === "Dimension" ? {
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.type_name === "Function") {
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?.toLowerCase() === "var" && !current_shadow.color) {
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.type_name === "Hash") {
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.type_name === "Operator" && node.value === ",") {
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.type_name === "Operator" && node.value === ",") {
248
+ if (node.type === OPERATOR && node.value === ",") {
249
249
  families.push(unquote(family_buffer));
250
250
  family_buffer = "";
251
- prev_type = node.type_name;
251
+ prev_type = node.type;
252
252
  continue;
253
253
  }
254
- if (prev_type === "Identifier" && node.type_name === "Identifier") family_buffer += " ";
254
+ if (prev_type === IDENTIFIER && node.type === IDENTIFIER) family_buffer += " ";
255
255
  family_buffer += node.text;
256
- prev_type = node.type_name;
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$1(value);
286
+ let ast = parse_value(value);
287
287
  if (!ast.has_children) return null;
288
- if (ast.children.length !== 1) return null;
288
+ if (ast.child_count !== 1) return null;
289
289
  let maybe_dimension = ast.first_child;
290
- switch (maybe_dimension.type_name) {
291
- case "Dimension": {
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 "Number": return Number(maybe_dimension.value);
303
- case "Identifier": if (maybe_dimension.name?.toLowerCase() === "normal") return 1.2;
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$1(value);
328
- if (!ast.has_children || ast.children.length !== 1) return null;
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.type_name) {
331
- case "Dimension": {
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 "Identifier": {
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 "Number":
354
+ case NUMBER:
355
355
  if (Number(maybe_length.value) === 0) return {
356
356
  value: 0,
357
357
  unit: "px"
@@ -452,15 +452,14 @@ function analysis_to_tokens(analysis) {
452
452
  let unique = get_unique(analysis.values.fontFamilies);
453
453
  for (let font_family in unique) {
454
454
  let parsed = destructure_font_family(font_family);
455
- let name = `fontFamily-${hash(font_family)}`;
455
+ if (!parsed) continue;
456
+ let [main] = parsed;
457
+ let name = `fontFamily-${hash(main)}`;
456
458
  let extensions = {
457
459
  [EXTENSION_AUTHORED_AS]: font_family,
458
460
  [EXTENSION_USAGE_COUNT]: get_count(unique[font_family])
459
461
  };
460
- if (parsed === void 0) families[name] = {
461
- $value: font_family,
462
- $extensions: extensions
463
- };
462
+ if (families[name]) families[name].$extensions[EXTENSION_USAGE_COUNT] += extensions[EXTENSION_USAGE_COUNT];
464
463
  else families[name] = {
465
464
  $type: "fontFamily",
466
465
  $value: parsed,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectwallace/css-design-tokens",
3
- "version": "0.11.2",
3
+ "version": "0.11.4",
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.3.0",
38
- "@projectwallace/css-parser": "^0.13.6",
39
- "color-sorter": "^7.0.2",
37
+ "@projectwallace/css-analyzer": "^9.6.3",
38
+ "@projectwallace/css-parser": "^0.14.10",
39
+ "color-sorter": "^8.0.0",
40
40
  "colorjs.io": "^0.6.1",
41
41
  "css-time-sort": "^3.0.1"
42
42
  },
43
43
  "devDependencies": {
44
- "@codecov/rollup-plugin": "^1.9.1",
45
- "@vitest/coverage-v8": "^4.0.18",
46
- "oxfmt": "^0.37.0",
47
- "oxlint": "^1.52.0",
44
+ "@codecov/rollup-plugin": "^2.0.1",
45
+ "@vitest/coverage-v8": "^4.1.4",
46
+ "oxfmt": "^0.46.0",
47
+ "oxlint": "^1.61.0",
48
48
  "publint": "^0.3.18",
49
- "tsdown": "^0.21.1",
50
- "typescript": "^5.9.3",
51
- "vitest": "^4.0.18"
49
+ "tsdown": "^0.21.9",
50
+ "typescript": "^6.0.3",
51
+ "vitest": "^4.1.4"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22"