@tbela99/css-parser 1.4.2 → 1.4.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 (122) hide show
  1. package/CHANGELOG.md +354 -4
  2. package/README.md +69 -1077
  3. package/dist/config.json.js +76 -3
  4. package/dist/index-umd-web.js +26838 -18743
  5. package/dist/index.cjs +26819 -18731
  6. package/dist/index.d.ts +2471 -1884
  7. package/dist/lib/ast/clone.js +46 -0
  8. package/dist/lib/ast/expand.js +90 -65
  9. package/dist/lib/ast/features/calc.js +86 -43
  10. package/dist/lib/ast/features/if.js +221 -0
  11. package/dist/lib/ast/features/index.js +1 -0
  12. package/dist/lib/ast/features/inlinecssvariables.js +33 -28
  13. package/dist/lib/ast/features/prefix.js +406 -44
  14. package/dist/lib/ast/features/shorthand.js +6 -9
  15. package/dist/lib/ast/features/transform.js +14 -15
  16. package/dist/lib/ast/find.js +175 -0
  17. package/dist/lib/ast/math/expression.js +145 -99
  18. package/dist/lib/ast/math/math.js +30 -41
  19. package/dist/lib/ast/minify.js +551 -232
  20. package/dist/lib/ast/transform/compute.js +82 -69
  21. package/dist/lib/ast/transform/matrix.js +12 -26
  22. package/dist/lib/ast/transform/minify.js +154 -150
  23. package/dist/lib/ast/transform/perspective.js +1 -1
  24. package/dist/lib/ast/transform/rotate.js +1 -1
  25. package/dist/lib/ast/transform/scale.js +1 -1
  26. package/dist/lib/ast/transform/skew.js +1 -1
  27. package/dist/lib/ast/transform/translate.js +1 -1
  28. package/dist/lib/ast/transform/utils.js +3 -2
  29. package/dist/lib/ast/types.js +345 -30
  30. package/dist/lib/ast/walk.js +119 -64
  31. package/dist/lib/fs/resolve.js +94 -88
  32. package/dist/lib/parser/declaration/list.js +117 -26
  33. package/dist/lib/parser/declaration/map.js +141 -96
  34. package/dist/lib/parser/declaration/set.js +30 -25
  35. package/dist/lib/parser/parse.js +1810 -1739
  36. package/dist/lib/parser/tokenize.js +662 -403
  37. package/dist/lib/parser/utils/angle.js +29 -0
  38. package/dist/lib/parser/utils/at-rule-container.js +486 -0
  39. package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
  40. package/dist/lib/parser/utils/at-rule-generic.js +118 -0
  41. package/dist/lib/parser/utils/at-rule-import.js +393 -0
  42. package/dist/lib/parser/utils/at-rule-media.js +603 -0
  43. package/dist/lib/parser/utils/at-rule-support.js +431 -0
  44. package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
  45. package/dist/lib/parser/utils/at-rule.js +31 -0
  46. package/dist/lib/parser/utils/cache.js +19 -0
  47. package/dist/lib/parser/utils/config.js +1 -0
  48. package/dist/lib/parser/utils/declaration.js +672 -91
  49. package/dist/lib/parser/utils/hash.js +1 -1
  50. package/dist/lib/parser/utils/selector.js +518 -0
  51. package/dist/lib/parser/utils/text.js +17 -1
  52. package/dist/lib/parser/utils/token.js +104 -0
  53. package/dist/lib/parser/utils/type.js +29 -18
  54. package/dist/lib/renderer/render.js +870 -269
  55. package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
  56. package/dist/lib/syntax/color/a98rgb.js +8 -12
  57. package/dist/lib/syntax/color/alpha.js +64 -0
  58. package/dist/lib/syntax/color/cmyk.js +23 -21
  59. package/dist/lib/syntax/color/color-mix.js +311 -237
  60. package/dist/lib/syntax/color/color.js +98 -92
  61. package/dist/lib/syntax/color/hex.js +29 -33
  62. package/dist/lib/syntax/color/hsl.js +7 -14
  63. package/dist/lib/syntax/color/hwb.js +14 -27
  64. package/dist/lib/syntax/color/lab.js +23 -24
  65. package/dist/lib/syntax/color/lch.js +16 -18
  66. package/dist/lib/syntax/color/oklab.js +21 -40
  67. package/dist/lib/syntax/color/oklch.js +16 -18
  68. package/dist/lib/syntax/color/p3.js +0 -8
  69. package/dist/lib/syntax/color/rec2020.js +9 -13
  70. package/dist/lib/syntax/color/relativecolor.js +160 -48
  71. package/dist/lib/syntax/color/rgb.js +14 -18
  72. package/dist/lib/syntax/color/srgb.js +30 -29
  73. package/dist/lib/syntax/color/utils/color-type.js +18 -0
  74. package/dist/lib/syntax/color/utils/colorspace.js +46 -0
  75. package/dist/lib/syntax/color/utils/components.js +36 -16
  76. package/dist/lib/syntax/color/utils/distance.js +21 -11
  77. package/dist/lib/syntax/color/utils/make-color.js +56 -0
  78. package/dist/lib/syntax/color/xyz.js +10 -22
  79. package/dist/lib/syntax/color/xyzd50.js +6 -20
  80. package/dist/lib/syntax/constants.js +464 -0
  81. package/dist/lib/syntax/syntax.js +825 -592
  82. package/dist/lib/validation/config.js +72 -33
  83. package/dist/lib/validation/config.json.js +1185 -85
  84. package/dist/lib/validation/match.js +3120 -0
  85. package/dist/lib/validation/parser/parse.js +683 -935
  86. package/dist/lib/validation/parser/typedef.js +106 -0
  87. package/dist/lib/validation/utils/list.js +4 -11
  88. package/dist/lib/validation/utils/whitespace.js +2 -8
  89. package/dist/node.js +102 -57
  90. package/dist/web.js +100 -48
  91. package/package.json +31 -17
  92. package/dist/lib/syntax/color/utils/constants.js +0 -214
  93. package/dist/lib/syntax/utils.js +0 -70
  94. package/dist/lib/validation/at-rules/container.js +0 -342
  95. package/dist/lib/validation/at-rules/counter-style.js +0 -90
  96. package/dist/lib/validation/at-rules/custom-media.js +0 -50
  97. package/dist/lib/validation/at-rules/document.js +0 -89
  98. package/dist/lib/validation/at-rules/else.js +0 -5
  99. package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
  100. package/dist/lib/validation/at-rules/import.js +0 -150
  101. package/dist/lib/validation/at-rules/keyframes.js +0 -67
  102. package/dist/lib/validation/at-rules/layer.js +0 -41
  103. package/dist/lib/validation/at-rules/media.js +0 -255
  104. package/dist/lib/validation/at-rules/namespace.js +0 -81
  105. package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
  106. package/dist/lib/validation/at-rules/page.js +0 -100
  107. package/dist/lib/validation/at-rules/supports.js +0 -295
  108. package/dist/lib/validation/at-rules/when.js +0 -185
  109. package/dist/lib/validation/atrule.js +0 -184
  110. package/dist/lib/validation/selector.js +0 -36
  111. package/dist/lib/validation/syntax.js +0 -1073
  112. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
  113. package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
  114. package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
  115. package/dist/lib/validation/syntaxes/family-name.js +0 -57
  116. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
  117. package/dist/lib/validation/syntaxes/layer-name.js +0 -57
  118. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
  119. package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
  120. package/dist/lib/validation/syntaxes/selector-list.js +0 -5
  121. package/dist/lib/validation/syntaxes/selector.js +0 -5
  122. package/dist/lib/validation/syntaxes/url.js +0 -40
@@ -1,4 +1,5 @@
1
- import { multiply, identity, epsilon, decompose, round, toZero } from './utils.js';
1
+ import { multiply, decompose, round, toZero, identity } from './utils.js';
2
+ import { epsilon } from '../../syntax/constants.js';
2
3
  import { EnumToken } from '../types.js';
3
4
  import { computeMatrix } from './compute.js';
4
5
  import { parseMatrix } from './matrix.js';
@@ -9,233 +10,237 @@ function minify(matrix) {
9
10
  if (decomposed == null) {
10
11
  return null;
11
12
  }
12
- const transforms = new Set(['translate', 'scale', 'skew', 'perspective', 'rotate']);
13
- const scales = new Set(['x', 'y', 'z']);
14
- const skew = new Set(['x', 'y']);
13
+ const transforms = new Set(["translate", "scale", "skew", "perspective", "rotate"]);
14
+ const scales = new Set(["x", "y", "z"]);
15
+ const skew = new Set(["x", "y"]);
15
16
  let result = [];
16
17
  // check identity
17
- if (round(decomposed.translate[0]) == 0 && round(decomposed.translate[1]) == 0 && round(decomposed.translate[2]) == 0) {
18
- transforms.delete('translate');
18
+ if (round(decomposed.translate[0]) == 0 &&
19
+ round(decomposed.translate[1]) == 0 &&
20
+ round(decomposed.translate[2]) == 0) {
21
+ transforms.delete("translate");
19
22
  }
20
23
  if (round(decomposed.scale[0]) == 1 && round(decomposed.scale[1]) == 1 && round(decomposed.scale[2]) == 1) {
21
- transforms.delete('scale');
24
+ transforms.delete("scale");
22
25
  }
23
26
  if (round(decomposed.skew[0]) == 0 && round(decomposed.skew[1]) == 0) {
24
- transforms.delete('skew');
27
+ transforms.delete("skew");
25
28
  }
26
29
  if (round(decomposed.perspective[2]) == 0) {
27
- transforms.delete('perspective');
30
+ transforms.delete("perspective");
28
31
  }
29
32
  if (round(decomposed.rotate[3]) == 0) {
30
- transforms.delete('rotate');
33
+ transforms.delete("rotate");
31
34
  }
32
- if (transforms.has('translate')) {
33
- let coordinates = new Set(['x', 'y', 'z']);
35
+ if (transforms.has("translate")) {
36
+ let coordinates = new Set(["x", "y", "z"]);
34
37
  for (let i = 0; i < 3; i++) {
35
38
  if (round(decomposed.translate[i]) == 0) {
36
- coordinates.delete(i == 0 ? 'x' : i == 1 ? 'y' : 'z');
39
+ coordinates.delete(i == 0 ? "x" : i == 1 ? "y" : "z");
37
40
  }
38
41
  }
39
42
  if (coordinates.size == 1) {
40
- if (coordinates.has('x')) {
43
+ if (coordinates.has("x")) {
41
44
  result.push({
42
- typ: EnumToken.FunctionTokenType,
43
- val: 'translate',
44
- chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: 'px' }]
45
+ typ: EnumToken.TransformFunctionTokenType,
46
+ val: "translate",
47
+ chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: "px" }],
45
48
  });
46
49
  }
47
50
  else {
48
- let axis = coordinates.has('y') ? 'y' : 'z';
49
- let index = axis == 'y' ? 1 : 2;
51
+ let axis = coordinates.has("y") ? "y" : "z";
52
+ let index = axis == "y" ? 1 : 2;
50
53
  result.push({
51
- typ: EnumToken.FunctionTokenType,
52
- val: 'translate' + axis.toUpperCase(),
53
- chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[index]), unit: 'px' }]
54
+ typ: EnumToken.TransformFunctionTokenType,
55
+ val: "translate" + axis.toUpperCase(),
56
+ chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[index]), unit: "px" }],
54
57
  });
55
58
  }
56
59
  }
57
- else if (coordinates.has('z')) {
60
+ else if (coordinates.has("z")) {
58
61
  result.push({
59
- typ: EnumToken.FunctionTokenType,
60
- val: 'translate3d',
62
+ typ: EnumToken.TransformFunctionTokenType,
63
+ val: "translate3d",
61
64
  chi: [
62
- decomposed.translate[0] == 0 ? {
63
- typ: EnumToken.NumberTokenType,
64
- val: 0
65
- } : { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: 'px' },
65
+ decomposed.translate[0] == 0
66
+ ? {
67
+ typ: EnumToken.NumberTokenType,
68
+ val: 0,
69
+ }
70
+ : { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: "px" },
66
71
  { typ: EnumToken.CommaTokenType },
67
- decomposed.translate[1] == 0 ? {
68
- typ: EnumToken.NumberTokenType,
69
- val: 0
70
- } : { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit: 'px' },
72
+ decomposed.translate[1] == 0
73
+ ? {
74
+ typ: EnumToken.NumberTokenType,
75
+ val: 0,
76
+ }
77
+ : { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit: "px" },
71
78
  { typ: EnumToken.CommaTokenType },
72
- { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[2]), unit: 'px' }
73
- ]
79
+ { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[2]), unit: "px" },
80
+ ],
74
81
  });
75
82
  }
76
83
  else {
77
84
  result.push({
78
- typ: EnumToken.FunctionTokenType,
79
- val: 'translate',
85
+ typ: EnumToken.TransformFunctionTokenType,
86
+ val: "translate",
80
87
  chi: [
81
- { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: 'px' },
88
+ { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: "px" },
82
89
  { typ: EnumToken.CommaTokenType },
83
- { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit: 'px' }
84
- ]
90
+ { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit: "px" },
91
+ ],
85
92
  });
86
93
  }
87
94
  }
88
- if (transforms.has('rotate')) {
95
+ if (transforms.has("rotate")) {
89
96
  const [x, y, z, angle] = decomposed.rotate;
90
97
  if (y == 0 && z == 0) {
91
98
  result.push({
92
- typ: EnumToken.FunctionTokenType,
93
- val: 'rotateX',
99
+ typ: EnumToken.TransformFunctionTokenType,
100
+ val: "rotateX",
94
101
  chi: [
95
102
  {
96
103
  typ: EnumToken.AngleTokenType,
97
104
  val: round(angle),
98
- unit: 'deg'
99
- }
100
- ]
105
+ unit: "deg",
106
+ },
107
+ ],
101
108
  });
102
109
  }
103
110
  else if (x == 0 && z == 0) {
104
111
  result.push({
105
- typ: EnumToken.FunctionTokenType,
106
- val: 'rotateY',
112
+ typ: EnumToken.TransformFunctionTokenType,
113
+ val: "rotateY",
107
114
  chi: [
108
115
  {
109
116
  typ: EnumToken.AngleTokenType,
110
117
  val: round(angle),
111
- unit: 'deg'
112
- }
113
- ]
118
+ unit: "deg",
119
+ },
120
+ ],
114
121
  });
115
122
  }
116
123
  else if (x == 0 && y == 0) {
117
124
  result.push({
118
- typ: EnumToken.FunctionTokenType,
119
- val: 'rotate',
125
+ typ: EnumToken.TransformFunctionTokenType,
126
+ val: "rotate",
120
127
  chi: [
121
128
  {
122
129
  typ: EnumToken.AngleTokenType,
123
130
  val: round(angle),
124
- unit: 'deg'
125
- }
126
- ]
131
+ unit: "deg",
132
+ },
133
+ ],
127
134
  });
128
135
  }
129
136
  else {
130
137
  result.push({
131
- typ: EnumToken.FunctionTokenType,
132
- val: 'rotate3d',
138
+ typ: EnumToken.TransformFunctionTokenType,
139
+ val: "rotate3d",
133
140
  chi: [
134
141
  {
135
142
  typ: EnumToken.NumberTokenType,
136
- val: round(x)
143
+ val: round(x),
137
144
  },
138
145
  { typ: EnumToken.CommaTokenType },
139
146
  {
140
147
  typ: EnumToken.NumberTokenType,
141
- val: round(y)
148
+ val: round(y),
142
149
  },
143
150
  { typ: EnumToken.CommaTokenType },
144
151
  {
145
152
  typ: EnumToken.NumberTokenType,
146
- val: round(z)
153
+ val: round(z),
147
154
  },
148
155
  { typ: EnumToken.CommaTokenType },
149
156
  {
150
157
  typ: EnumToken.AngleTokenType,
151
158
  val: round(angle),
152
- unit: 'deg'
153
- }
154
- ]
159
+ unit: "deg",
160
+ },
161
+ ],
155
162
  });
156
163
  }
157
164
  }
158
- if (transforms.has('skew')) {
165
+ if (transforms.has("skew")) {
159
166
  if (round(decomposed.skew[1]) == 0) {
160
- skew.delete('y');
167
+ skew.delete("y");
161
168
  }
162
169
  for (let i = 0; i < 2; i++) {
163
- decomposed.skew[i] = round(Math.atan(decomposed.skew[i]) * 180 / Math.PI);
170
+ decomposed.skew[i] = round((Math.atan(decomposed.skew[i]) * 180) / Math.PI);
164
171
  }
165
172
  if (skew.size == 1) {
166
173
  result.push({
167
- typ: EnumToken.FunctionTokenType,
168
- val: 'skew' + (skew.has('x') ? '' : 'Y'),
169
- chi: [
170
- { typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: 'deg' }
171
- ]
174
+ typ: EnumToken.TransformFunctionTokenType,
175
+ val: "skew" + (skew.has("x") ? "" : "Y"),
176
+ chi: [{ typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: "deg" }],
172
177
  });
173
178
  }
174
179
  else {
175
180
  result.push({
176
- typ: EnumToken.FunctionTokenType,
177
- val: 'skew',
181
+ typ: EnumToken.TransformFunctionTokenType,
182
+ val: "skew",
178
183
  chi: [
179
- { typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: 'deg' },
184
+ { typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: "deg" },
180
185
  { typ: EnumToken.CommaTokenType },
181
- { typ: EnumToken.AngleTokenType, val: round(decomposed.skew[1]), unit: 'deg' }
182
- ]
186
+ { typ: EnumToken.AngleTokenType, val: round(decomposed.skew[1]), unit: "deg" },
187
+ ],
183
188
  });
184
189
  }
185
190
  }
186
- if (transforms.has('scale')) {
191
+ if (transforms.has("scale")) {
187
192
  const [sx, sy, sz] = toZero(decomposed.scale);
188
193
  if (sz == 1) {
189
- scales.delete('z');
194
+ scales.delete("z");
190
195
  }
191
196
  if (sy == 1) {
192
- scales.delete('y');
197
+ scales.delete("y");
193
198
  }
194
199
  if (sx == 1) {
195
- scales.delete('x');
200
+ scales.delete("x");
196
201
  }
197
202
  if (scales.size == 1) {
198
- let prefix = scales.has('x') ? 'X' : scales.has('y') ? 'Y' : 'Z';
203
+ let prefix = scales.has("x") ? "X" : scales.has("y") ? "Y" : "Z";
199
204
  result.push({
200
- typ: EnumToken.FunctionTokenType,
201
- val: 'scale' + prefix,
202
- chi: [
203
- { typ: EnumToken.NumberTokenType, val: round(prefix == 'Z' ? sz : prefix == 'Y' ? sy : sx) }
204
- ]
205
+ typ: EnumToken.TransformFunctionTokenType,
206
+ val: "scale" + prefix,
207
+ chi: [{ typ: EnumToken.NumberTokenType, val: round(prefix == "Z" ? sz : prefix == "Y" ? sy : sx) }],
205
208
  });
206
209
  }
207
- else if (!scales.has('z')) {
210
+ else if (!scales.has("z")) {
208
211
  result.push({
209
- typ: EnumToken.FunctionTokenType,
210
- val: 'scale',
212
+ typ: EnumToken.TransformFunctionTokenType,
213
+ val: "scale",
211
214
  chi: [
212
215
  { typ: EnumToken.NumberTokenType, val: round(sx) },
213
216
  { typ: EnumToken.CommaTokenType },
214
217
  { typ: EnumToken.NumberTokenType, val: round(sy) },
215
- ]
218
+ ],
216
219
  });
217
220
  }
218
221
  else {
219
222
  result.push({
220
- typ: EnumToken.FunctionTokenType,
221
- val: 'scale3d',
223
+ typ: EnumToken.TransformFunctionTokenType,
224
+ val: "scale3d",
222
225
  chi: [
223
226
  { typ: EnumToken.NumberTokenType, val: round(sx) },
224
227
  { typ: EnumToken.CommaTokenType },
225
228
  { typ: EnumToken.NumberTokenType, val: round(sy) },
226
229
  { typ: EnumToken.CommaTokenType },
227
- { typ: EnumToken.NumberTokenType, val: round(sz) }
228
- ]
230
+ { typ: EnumToken.NumberTokenType, val: round(sz) },
231
+ ],
229
232
  });
230
233
  }
231
234
  }
232
235
  // identity
233
- return result.length == 0 || (result.length == 1 && eqMatrix(identity(), result)) ? [
234
- {
235
- typ: EnumToken.IdenTokenType,
236
- val: 'none'
237
- }
238
- ] : result;
236
+ return result.length == 0 || (result.length == 1 && eqMatrix(identity(), result))
237
+ ? [
238
+ {
239
+ typ: EnumToken.IdenTokenType,
240
+ val: "none",
241
+ },
242
+ ]
243
+ : result;
239
244
  }
240
245
  function eqMatrix(a, b) {
241
246
  let mat = identity();
@@ -262,102 +267,101 @@ function eqMatrix(a, b) {
262
267
  }
263
268
  function minifyTransformFunctions(transform) {
264
269
  const name = transform.val.toLowerCase();
265
- if ('skewx' == name) {
266
- transform.val = 'skew';
270
+ if ("skewx" == name) {
271
+ transform.val = "skew";
267
272
  return transform;
268
273
  }
269
- if (!['translate', 'translate3d', 'scale', 'scale3d'].includes(name)) {
274
+ if (!["translate", "translate3d", "scale", "scale3d"].includes(name)) {
270
275
  return transform;
271
276
  }
272
277
  const values = [];
273
278
  for (const token of transform.chi) {
274
- if (token.typ == EnumToken.CommentTokenType || token.typ == EnumToken.WhitespaceTokenType || token.typ == EnumToken.CommaTokenType) {
279
+ if (token.typ == EnumToken.CommentTokenType ||
280
+ token.typ == EnumToken.WhitespaceTokenType ||
281
+ token.typ == EnumToken.CommaTokenType) {
275
282
  continue;
276
283
  }
277
- if (![EnumToken.NumberTokenType, EnumToken.LengthTokenType, EnumToken.AngleTokenType, EnumToken.PercentageTokenType].includes(token.typ)) {
284
+ if (![
285
+ EnumToken.NumberTokenType,
286
+ EnumToken.LengthTokenType,
287
+ EnumToken.AngleTokenType,
288
+ EnumToken.PercentageTokenType,
289
+ ].includes(token.typ)) {
278
290
  return transform;
279
291
  }
280
- if (token.typ == EnumToken.PercentageTokenType && typeof token.val == 'number' && name.startsWith('scale')) {
281
- Object.assign(token, { typ: EnumToken.NumberTokenType, val: token.val / 100 });
292
+ if (token.typ == EnumToken.PercentageTokenType &&
293
+ typeof token.val == "number" &&
294
+ name.startsWith("scale")) {
295
+ Object.assign(token, {
296
+ typ: EnumToken.NumberTokenType,
297
+ val: token.val / 100,
298
+ });
282
299
  }
283
300
  values.push(token);
284
301
  }
285
- if ((name == 'translate' || name == 'scale') && values.length > 2) {
302
+ if (values.length == 0) {
286
303
  return transform;
287
304
  }
288
- const ignoredValue = name.startsWith('scale') ? 1 : 0;
289
- const t = new Set(['x', 'y', 'z']);
305
+ if ((name == "translate" || name == "scale") && values.length > 2) {
306
+ return transform;
307
+ }
308
+ const ignoredValue = name.startsWith("scale") ? 1 : 0;
309
+ const t = new Set(["x", "y", "z"]);
290
310
  let i = 3;
291
311
  while (i--) {
292
312
  if (values.length <= i || values[i].val == ignoredValue) {
293
- t.delete(i == 0 ? 'x' : i == 1 ? 'y' : 'z');
313
+ t.delete(i == 0 ? "x" : i == 1 ? "y" : "z");
294
314
  }
295
315
  }
296
- if (name == 'translate3d' || name == 'translate') {
316
+ if (name == "translate3d" || name == "translate") {
297
317
  if (t.size == 0) {
298
318
  return {
299
- typ: EnumToken.FunctionTokenType,
300
- val: 'translate',
301
- chi: [
302
- { typ: EnumToken.NumberTokenType, val: 0 }
303
- ]
319
+ typ: EnumToken.TransformFunctionTokenType,
320
+ val: "translate",
321
+ chi: [{ typ: EnumToken.NumberTokenType, val: 0 }],
304
322
  };
305
323
  }
306
324
  if (t.size == 1) {
307
325
  return {
308
- typ: EnumToken.FunctionTokenType,
309
- val: 'translate' + (t.has('x') ? '' : t.has('y') ? 'Y' : 'Z'),
310
- chi: [
311
- values[t.has('x') ? 0 : t.has('y') ? 1 : 2]
312
- ]
326
+ typ: EnumToken.TransformFunctionTokenType,
327
+ val: "translate" + (t.has("x") ? "" : t.has("y") ? "Y" : "Z"),
328
+ chi: [values[t.has("x") ? 0 : t.has("y") ? 1 : 2]],
313
329
  };
314
330
  }
315
331
  if (t.size == 2) {
316
- if (t.has('z')) {
332
+ if (t.has("z")) {
317
333
  return transform;
318
334
  }
319
335
  return {
320
- typ: EnumToken.FunctionTokenType,
321
- val: 'translate',
322
- chi: [
323
- values[0],
324
- { typ: EnumToken.CommaTokenType },
325
- values[1]
326
- ]
336
+ typ: EnumToken.TransformFunctionTokenType,
337
+ val: "translate",
338
+ chi: [values[0], { typ: EnumToken.CommaTokenType }, values[1]],
327
339
  };
328
340
  }
329
341
  }
330
- if (name == 'scale3d' || name == 'scale') {
342
+ if (name == "scale3d" || name == "scale") {
331
343
  if (t.size == 0) {
332
344
  return {
333
- typ: EnumToken.FunctionTokenType,
334
- val: 'scale',
335
- chi: [
336
- { typ: EnumToken.NumberTokenType, val: 1 }
337
- ]
345
+ typ: EnumToken.TransformFunctionTokenType,
346
+ val: "scale",
347
+ chi: [{ typ: EnumToken.NumberTokenType, val: 1 }],
338
348
  };
339
349
  }
340
350
  if (t.size == 1) {
341
351
  return {
342
- typ: EnumToken.FunctionTokenType,
343
- val: 'scale' + (t.has('x') ? 'X' : t.has('y') ? 'Y' : 'Z'),
344
- chi: [
345
- values[t.has('x') ? 0 : t.has('y') ? 1 : 2]
346
- ]
352
+ typ: EnumToken.TransformFunctionTokenType,
353
+ val: "scale" + (t.has("x") ? "X" : t.has("y") ? "Y" : "Z"),
354
+ chi: [values[t.has("x") ? 0 : t.has("y") ? 1 : 2]],
347
355
  };
348
356
  }
349
357
  if (t.size == 2) {
350
- if (t.has('z')) {
358
+ if (t.has("z")) {
351
359
  return transform;
352
360
  }
353
361
  return {
354
- typ: EnumToken.FunctionTokenType,
355
- val: 'scale',
356
- chi: [
357
- values[0],
358
- { typ: EnumToken.CommaTokenType },
359
- values[1]
360
- ]
362
+ typ: EnumToken.TransformFunctionTokenType,
363
+ val: "scale",
364
+ chi: [values[0], { typ: EnumToken.CommaTokenType }, values[1]],
361
365
  };
362
366
  }
363
367
  }
@@ -1,4 +1,4 @@
1
- import { identity, multiply } from './utils.js';
1
+ import { multiply, identity } from './utils.js';
2
2
 
3
3
  function perspective(x, from) {
4
4
  const matrix = identity();
@@ -1,4 +1,4 @@
1
- import { identity, multiply } from './utils.js';
1
+ import { multiply, identity } from './utils.js';
2
2
 
3
3
  /**
4
4
  * angle in radian
@@ -1,4 +1,4 @@
1
- import { identity, multiply } from './utils.js';
1
+ import { multiply, identity } from './utils.js';
2
2
 
3
3
  function scaleX(x, from) {
4
4
  const matrix = identity();
@@ -1,4 +1,4 @@
1
- import { identity, multiply } from './utils.js';
1
+ import { multiply, identity } from './utils.js';
2
2
 
3
3
  function skewX(x, from) {
4
4
  const matrix = identity();
@@ -1,4 +1,4 @@
1
- import { identity, multiply } from './utils.js';
1
+ import { multiply, identity } from './utils.js';
2
2
 
3
3
  function translateX(x, from) {
4
4
  const matrix = identity();
@@ -1,4 +1,5 @@
1
- const epsilon = 1e-5;
1
+ import { epsilon } from '../../syntax/constants.js';
2
+
2
3
  function identity() {
3
4
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
4
5
  }
@@ -240,4 +241,4 @@ function is2DMatrix(matrix) {
240
241
  matrix[15] === 1;
241
242
  }
242
243
 
243
- export { decompose, epsilon, identity, is2DMatrix, multiply, round, toZero };
244
+ export { decompose, identity, is2DMatrix, multiply, round, toZero };