@tbela99/css-parser 1.4.3 → 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 (166) hide show
  1. package/CHANGELOG.md +192 -2
  2. package/README.md +69 -1120
  3. package/dist/config.json.js +43 -2
  4. package/dist/index-umd-web.js +17226 -15037
  5. package/dist/index.cjs +16889 -14705
  6. package/dist/index.d.ts +1804 -1684
  7. package/dist/lib/ast/clone.js +4 -3
  8. package/dist/lib/ast/expand.js +2 -2
  9. package/dist/lib/ast/features/calc.js +59 -54
  10. package/dist/lib/ast/features/if.js +22 -16
  11. package/dist/lib/ast/features/inlinecssvariables.js +2 -2
  12. package/dist/lib/ast/features/prefix.js +343 -6
  13. package/dist/lib/ast/features/transform.js +7 -4
  14. package/dist/lib/ast/find.js +5 -5
  15. package/dist/lib/ast/math/expression.js +12 -8
  16. package/dist/lib/ast/minify.js +28 -33
  17. package/dist/lib/ast/transform/minify.js +135 -131
  18. package/dist/lib/ast/transform/utils.js +3 -2
  19. package/dist/lib/ast/types.js +69 -8
  20. package/dist/lib/ast/walk.js +4 -5
  21. package/dist/lib/fs/resolve.js +71 -57
  22. package/dist/lib/parser/declaration/list.js +92 -3
  23. package/dist/lib/parser/declaration/map.js +5 -5
  24. package/dist/lib/parser/parse.js +528 -466
  25. package/dist/lib/parser/tokenize.js +110 -4
  26. package/dist/lib/parser/utils/angle.js +29 -0
  27. package/dist/lib/parser/utils/at-rule-container.js +2 -2
  28. package/dist/lib/parser/utils/at-rule-font-feature-values.js +2 -2
  29. package/dist/lib/parser/utils/at-rule-generic.js +1 -1
  30. package/dist/lib/parser/utils/at-rule-media.js +2 -2
  31. package/dist/lib/parser/utils/at-rule-support.js +73 -8
  32. package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
  33. package/dist/lib/parser/utils/at-rule.js +2 -8
  34. package/dist/lib/parser/utils/declaration.js +179 -76
  35. package/dist/lib/parser/utils/selector.js +53 -11
  36. package/dist/lib/parser/utils/token.js +13 -11
  37. package/dist/lib/renderer/render.js +501 -59
  38. package/dist/lib/syntax/color/alpha.js +64 -0
  39. package/dist/lib/syntax/color/cmyk.js +2 -2
  40. package/dist/lib/syntax/color/color-mix.js +283 -220
  41. package/dist/lib/syntax/color/color.js +37 -28
  42. package/dist/lib/syntax/color/hex.js +2 -2
  43. package/dist/lib/syntax/color/hsl.js +3 -3
  44. package/dist/lib/syntax/color/hwb.js +7 -7
  45. package/dist/lib/syntax/color/lab.js +5 -5
  46. package/dist/lib/syntax/color/lch.js +4 -4
  47. package/dist/lib/syntax/color/oklab.js +3 -3
  48. package/dist/lib/syntax/color/oklch.js +3 -3
  49. package/dist/lib/syntax/color/relativecolor.js +97 -12
  50. package/dist/lib/syntax/color/srgb.js +5 -5
  51. package/dist/lib/syntax/color/utils/color-type.js +18 -0
  52. package/dist/lib/syntax/color/utils/colorspace.js +46 -0
  53. package/dist/lib/syntax/color/utils/components.js +7 -3
  54. package/dist/lib/syntax/color/utils/distance.js +21 -4
  55. package/dist/lib/syntax/color/utils/make-color.js +56 -0
  56. package/dist/lib/syntax/color/xyz.js +2 -2
  57. package/dist/lib/syntax/constants.js +29 -1
  58. package/dist/lib/syntax/syntax.js +307 -39
  59. package/dist/lib/validation/config.js +2 -2
  60. package/dist/lib/validation/config.json.js +32 -17
  61. package/dist/lib/validation/match.js +239 -104
  62. package/dist/lib/validation/parser/parse.js +0 -1
  63. package/dist/lib/validation/parser/typedef.js +6 -0
  64. package/dist/node.js +64 -22
  65. package/dist/web.js +65 -18
  66. package/package.json +26 -15
  67. package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
  68. package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
  69. package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
  70. package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
  71. package/.repl_history +0 -4
  72. package/badges/coverage.svg +0 -20
  73. package/deno.lock +0 -2861
  74. package/dist/lib/ast/clone.d.ts +0 -10
  75. package/dist/lib/ast/expand.d.ts +0 -14
  76. package/dist/lib/ast/features/calc.d.ts +0 -10
  77. package/dist/lib/ast/features/if.d.ts +0 -10
  78. package/dist/lib/ast/features/index.d.ts +0 -6
  79. package/dist/lib/ast/features/inlinecssvariables.d.ts +0 -15
  80. package/dist/lib/ast/features/prefix.d.ts +0 -8
  81. package/dist/lib/ast/features/shorthand.d.ts +0 -12
  82. package/dist/lib/ast/features/transform.d.ts +0 -10
  83. package/dist/lib/ast/features/type.d.ts +0 -15
  84. package/dist/lib/ast/find.d.ts +0 -165
  85. package/dist/lib/ast/math/expression.d.ts +0 -18
  86. package/dist/lib/ast/math/math.d.ts +0 -6
  87. package/dist/lib/ast/minify.d.ts +0 -19
  88. package/dist/lib/ast/transform/compute.d.ts +0 -8
  89. package/dist/lib/ast/transform/matrix.d.ts +0 -22
  90. package/dist/lib/ast/transform/minify.d.ts +0 -5
  91. package/dist/lib/ast/transform/perspective.d.ts +0 -3
  92. package/dist/lib/ast/transform/rotate.d.ts +0 -12
  93. package/dist/lib/ast/transform/scale.d.ts +0 -6
  94. package/dist/lib/ast/transform/skew.d.ts +0 -4
  95. package/dist/lib/ast/transform/translate.d.ts +0 -6
  96. package/dist/lib/ast/transform/utils.d.ts +0 -9
  97. package/dist/lib/ast/types.d.ts +0 -903
  98. package/dist/lib/ast/walk.d.ts +0 -162
  99. package/dist/lib/fs/resolve.d.ts +0 -20
  100. package/dist/lib/parser/declaration/list.d.ts +0 -16
  101. package/dist/lib/parser/declaration/map.d.ts +0 -15
  102. package/dist/lib/parser/declaration/set.d.ts +0 -9
  103. package/dist/lib/parser/node.d.ts +0 -7
  104. package/dist/lib/parser/parse.d.ts +0 -107
  105. package/dist/lib/parser/tokenize.d.ts +0 -57
  106. package/dist/lib/parser/utils/at-rule-container.d.ts +0 -5
  107. package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +0 -5
  108. package/dist/lib/parser/utils/at-rule-generic.d.ts +0 -5
  109. package/dist/lib/parser/utils/at-rule-import.d.ts +0 -5
  110. package/dist/lib/parser/utils/at-rule-media.d.ts +0 -5
  111. package/dist/lib/parser/utils/at-rule-page.d.ts +0 -5
  112. package/dist/lib/parser/utils/at-rule-page.js +0 -28
  113. package/dist/lib/parser/utils/at-rule-support.d.ts +0 -5
  114. package/dist/lib/parser/utils/at-rule-token.d.ts +0 -1
  115. package/dist/lib/parser/utils/at-rule-when-else.d.ts +0 -5
  116. package/dist/lib/parser/utils/at-rule.d.ts +0 -13
  117. package/dist/lib/parser/utils/cache.d.ts +0 -6
  118. package/dist/lib/parser/utils/config.d.ts +0 -2
  119. package/dist/lib/parser/utils/declaration-list.d.ts +0 -5
  120. package/dist/lib/parser/utils/declaration.d.ts +0 -18
  121. package/dist/lib/parser/utils/eq.d.ts +0 -1
  122. package/dist/lib/parser/utils/hash.d.ts +0 -21
  123. package/dist/lib/parser/utils/selector.d.ts +0 -5
  124. package/dist/lib/parser/utils/text.d.ts +0 -3
  125. package/dist/lib/parser/utils/token.d.ts +0 -14
  126. package/dist/lib/parser/utils/type.d.ts +0 -2
  127. package/dist/lib/renderer/render.d.ts +0 -28
  128. package/dist/lib/renderer/sourcemap/lib/encode.d.ts +0 -1
  129. package/dist/lib/renderer/sourcemap/sourcemap.d.ts +0 -26
  130. package/dist/lib/syntax/color/a98rgb.d.ts +0 -2
  131. package/dist/lib/syntax/color/cmyk.d.ts +0 -10
  132. package/dist/lib/syntax/color/color-mix.d.ts +0 -2
  133. package/dist/lib/syntax/color/color.d.ts +0 -42
  134. package/dist/lib/syntax/color/hex.d.ts +0 -16
  135. package/dist/lib/syntax/color/hsl.d.ts +0 -20
  136. package/dist/lib/syntax/color/hsv.d.ts +0 -2
  137. package/dist/lib/syntax/color/hwb.d.ts +0 -21
  138. package/dist/lib/syntax/color/lab.d.ts +0 -25
  139. package/dist/lib/syntax/color/lch.d.ts +0 -23
  140. package/dist/lib/syntax/color/oklab.d.ts +0 -22
  141. package/dist/lib/syntax/color/oklch.d.ts +0 -20
  142. package/dist/lib/syntax/color/p3.d.ts +0 -6
  143. package/dist/lib/syntax/color/prophotorgb.d.ts +0 -2
  144. package/dist/lib/syntax/color/rec2020.d.ts +0 -2
  145. package/dist/lib/syntax/color/relativecolor.d.ts +0 -13
  146. package/dist/lib/syntax/color/rgb.d.ts +0 -20
  147. package/dist/lib/syntax/color/srgb.d.ts +0 -23
  148. package/dist/lib/syntax/color/utils/components.d.ts +0 -2
  149. package/dist/lib/syntax/color/utils/distance.d.ts +0 -18
  150. package/dist/lib/syntax/color/utils/matrix.d.ts +0 -6
  151. package/dist/lib/syntax/color/xyz.d.ts +0 -5
  152. package/dist/lib/syntax/color/xyzd50.d.ts +0 -4
  153. package/dist/lib/syntax/constants.d.ts +0 -67
  154. package/dist/lib/syntax/syntax.d.ts +0 -38
  155. package/dist/lib/validation/config.d.ts +0 -14
  156. package/dist/lib/validation/json.d.ts +0 -2
  157. package/dist/lib/validation/match.d.ts +0 -38
  158. package/dist/lib/validation/parser/parse.d.ts +0 -8
  159. package/dist/lib/validation/parser/typedef.d.ts +0 -95
  160. package/dist/lib/validation/utils/list.d.ts +0 -4
  161. package/dist/lib/validation/utils/whitespace.d.ts +0 -2
  162. package/dist/node.d.ts +0 -207
  163. package/dist/web.d.ts +0 -169
  164. package/playground/index.html +0 -1328
  165. package/playground/sw.js +0 -55
  166. package/playground/tree.js +0 -176
package/dist/node.js CHANGED
@@ -5,12 +5,13 @@ import { lstat, readFile } from 'node:fs/promises';
5
5
  import { doParse } from './lib/parser/parse.js';
6
6
  export { parseDeclarations, parseString } from './lib/parser/parse.js';
7
7
  import { doRender } from './lib/renderer/render.js';
8
- export { renderToken } from './lib/renderer/render.js';
8
+ export { renderValue as renderToken } from './lib/renderer/render.js';
9
9
  import { ModuleScopeEnumOptions } from './lib/ast/types.js';
10
- export { ColorType, EnumToken, ModuleCaseTransformEnum, ValidationLevel } from './lib/ast/types.js';
10
+ export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, ValidationLevel } from './lib/ast/types.js';
11
11
  import { tokenizeStream, tokenize } from './lib/parser/tokenize.js';
12
- import { resolve, matchUrl, dirname } from './lib/fs/resolve.js';
12
+ import { dirname, resolve, matchUrl } from './lib/fs/resolve.js';
13
13
  import { ResponseType } from './types.js';
14
+ import { deprecate } from 'util';
14
15
  export { minify } from './lib/ast/minify.js';
15
16
  export { expand } from './lib/ast/expand.js';
16
17
  export { WalkerEvent, WalkerOptionEnum, walk, walkValues } from './lib/ast/walk.js';
@@ -18,11 +19,12 @@ export { convertColor } from './lib/syntax/color/color.js';
18
19
  export { isOkLabClose, okLabDistance } from './lib/syntax/color/utils/distance.js';
19
20
  export { find, findAll, findByValue, findLast } from './lib/ast/find.js';
20
21
  export { cloneNode } from './lib/ast/clone.js';
22
+ export { replaceNodeOrValue } from './lib/parser/utils/token.js';
21
23
  export { SourceMap } from './lib/renderer/sourcemap/sourcemap.js';
22
24
  export { FeatureWalkMode } from './lib/ast/features/type.js';
23
25
 
24
26
  /**
25
- * load file or url
27
+ * Load file or url
26
28
  * @param url
27
29
  * @param currentDirectory
28
30
  * @param responseType
@@ -34,7 +36,7 @@ export { FeatureWalkMode } from './lib/ast/features/type.js';
34
36
  * ```
35
37
  */
36
38
  async function load(url, currentDirectory = ".", responseType = false) {
37
- const resolved = resolve(url, currentDirectory);
39
+ const resolved = typeof url == "string" ? resolve(url, currentDirectory) : url;
38
40
  if (typeof responseType == "boolean") {
39
41
  responseType = responseType ? ResponseType.ReadableStream : ResponseType.Text;
40
42
  }
@@ -72,7 +74,7 @@ async function load(url, currentDirectory = ".", responseType = false) {
72
74
  throw new Error(`File not found: '${resolved.absolute || url}'`);
73
75
  }
74
76
  /**
75
- * render the ast tree
77
+ * Render the ast tree
76
78
  * @param data
77
79
  * @param options
78
80
  * @param mapping
@@ -104,11 +106,12 @@ function render(data, options = {}, mapping) {
104
106
  return doRender(data, Object.assign(options, { resolve, dirname, cwd: options.cwd ?? process.cwd() }), mapping);
105
107
  }
106
108
  /**
107
- * parse css file
109
+ * Parse css file
108
110
  * @param file url or path
109
111
  * @param options
110
112
  * @param asStream load file as stream
111
113
  *
114
+ * @deprecated
112
115
  * @throws Error file not found
113
116
  *
114
117
  * Example:
@@ -126,14 +129,14 @@ function render(data, options = {}, mapping) {
126
129
  * console.log(result.ast);
127
130
  * ```
128
131
  */
129
- async function parseFile(file, options = {}, asStream = false) {
130
- return Promise.resolve((options.load ?? load)(file, ".", asStream)).then((stream) => parse(stream, { src: file, ...options }));
131
- }
132
+ const parseFile = deprecate(async (file, options = {}, asStream = false) => parse({ file, asStream, ...options }), "parseFile is deprecated, use parse instead as parse({file, asStream, ...options})");
132
133
  /**
133
- * parse css
134
+ * Parse css
134
135
  * @param stream
135
136
  * @param options
136
137
  *
138
+ * @throws Error file not found
139
+ *
137
140
  * Example:
138
141
  *
139
142
  * ```ts
@@ -172,7 +175,25 @@ async function parseFile(file, options = {}, asStream = false) {
172
175
  * console.log(result.ast);
173
176
  * ```
174
177
  */
175
- async function parse(stream, options = {}) {
178
+ async function parse(...args) {
179
+ let options;
180
+ let stream;
181
+ if (typeof args[0] === "string" || args[0] instanceof ReadableStream) {
182
+ stream = args[0];
183
+ options = args[1];
184
+ }
185
+ else {
186
+ // @ts-expect-error
187
+ const { file, input, ...opt } = args[0];
188
+ options = opt;
189
+ if (file != null) {
190
+ return Promise.resolve((options.load ?? load)(file, ".", options.asStream ?? false)).then((stream) => parse(stream, { src: file, ...options }));
191
+ }
192
+ else {
193
+ stream = input;
194
+ }
195
+ }
196
+ options ??= {};
176
197
  options.parseInfo = {
177
198
  stream,
178
199
  buffer: "",
@@ -193,33 +214,36 @@ async function parse(stream, options = {}) {
193
214
  });
194
215
  }
195
216
  /**
196
- * transform css file
217
+ * Transform css file
197
218
  * @param file url or path
198
219
  * @param options
199
220
  * @param asStream load file as stream
200
221
  *
222
+ * @deprecated Use transform() instead.
201
223
  * @throws Error file not found
202
224
  *
203
225
  * Example:
204
226
  *
205
227
  * ```ts
206
228
  *
207
- * import {transformFile} from '@tbela99/css-parser';
229
+ * import {transform} from '@tbela99/css-parser';
208
230
  *
209
231
  * // remote file
210
- * let result = await transformFile('https://docs.deno.com/styles.css');
232
+ * let result = await transform({file: 'https://docs.deno.com/styles.css'});
211
233
  * console.log(result.code);
212
234
  *
213
235
  * // local file
214
- * result = await transformFile('./css/styles.css');
236
+ * result = await transform({file: './css/styles.css'});
215
237
  * console.log(result.code);
216
238
  * ```
217
239
  */
218
- async function transformFile(file, options = {}, asStream = false) {
219
- return Promise.resolve((options.load ?? load)(file, ".", asStream)).then((stream) => transform(stream, { src: file, ...options }));
220
- }
240
+ const transformFile = deprecate(async (file, options = {}, asStream = false) => transform({
241
+ file,
242
+ asStream,
243
+ ...options,
244
+ }), "transformFile is deprecated, use transform instead as transform({file, asStream, ...options})");
221
245
  /**
222
- * transform css
246
+ * Transform css
223
247
  * @param css
224
248
  * @param options
225
249
  *
@@ -261,10 +285,28 @@ async function transformFile(file, options = {}, asStream = false) {
261
285
  * console.log(result.code);
262
286
  * ```
263
287
  */
264
- async function transform(css, options = {}) {
288
+ async function transform(...args) {
289
+ let options;
290
+ let stream;
291
+ if (typeof args[0] === "string" || args[0] instanceof ReadableStream) {
292
+ stream = args[0];
293
+ options = args[1];
294
+ }
295
+ else {
296
+ // @ts-expect-error
297
+ const { file, input, ...opt } = args[0];
298
+ options = opt;
299
+ if (file != null) {
300
+ return Promise.resolve((options.load ?? load)(file, ".", options.asStream ?? false)).then((stream) => transform(stream, { src: file, ...options }));
301
+ }
302
+ else {
303
+ stream = input;
304
+ }
305
+ }
306
+ options ??= {};
265
307
  options = { minify: true, removeEmpty: true, removeCharset: true, ...options };
266
308
  const startTime = performance.now();
267
- return parse(css, options).then((parseResult) => {
309
+ return parse(stream, options).then((parseResult) => {
268
310
  let mapping = null;
269
311
  let importMapping = null;
270
312
  if (typeof options.module == "number" && options.module & ModuleScopeEnumOptions.ICSS) {
package/dist/web.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { doParse } from './lib/parser/parse.js';
2
2
  export { parseDeclarations, parseString } from './lib/parser/parse.js';
3
3
  import { doRender } from './lib/renderer/render.js';
4
- export { renderToken } from './lib/renderer/render.js';
4
+ export { renderValue as renderToken } from './lib/renderer/render.js';
5
5
  import { ModuleScopeEnumOptions } from './lib/ast/types.js';
6
- export { ColorType, EnumToken, ModuleCaseTransformEnum, ValidationLevel } from './lib/ast/types.js';
6
+ export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, ValidationLevel } from './lib/ast/types.js';
7
7
  import { tokenizeStream, tokenize } from './lib/parser/tokenize.js';
8
8
  import { matchUrl, resolve, dirname } from './lib/fs/resolve.js';
9
9
  import { ResponseType } from './types.js';
@@ -14,11 +14,12 @@ export { convertColor } from './lib/syntax/color/color.js';
14
14
  export { isOkLabClose, okLabDistance } from './lib/syntax/color/utils/distance.js';
15
15
  export { find, findAll, findByValue, findLast } from './lib/ast/find.js';
16
16
  export { cloneNode } from './lib/ast/clone.js';
17
+ export { replaceNodeOrValue } from './lib/parser/utils/token.js';
17
18
  export { SourceMap } from './lib/renderer/sourcemap/sourcemap.js';
18
19
  export { FeatureWalkMode } from './lib/ast/features/type.js';
19
20
 
20
21
  /**
21
- * load file or url
22
+ * Load file or url
22
23
  * @param url
23
24
  * @param currentDirectory
24
25
  * @param responseType
@@ -34,7 +35,10 @@ async function load(url, currentDirectory = ".", responseType = false) {
34
35
  responseType = responseType ? ResponseType.ReadableStream : ResponseType.Text;
35
36
  }
36
37
  let t;
37
- if (matchUrl.test(url)) {
38
+ if (typeof url == "object") {
39
+ t = new URL(url.absolute, self.origin);
40
+ }
41
+ else if (matchUrl.test(url)) {
38
42
  t = new URL(url);
39
43
  }
40
44
  else if (currentDirectory != null && matchUrl.test(currentDirectory)) {
@@ -55,7 +59,7 @@ async function load(url, currentDirectory = ".", responseType = false) {
55
59
  });
56
60
  }
57
61
  /**
58
- * render the ast tree
62
+ * Render the ast tree
59
63
  * @param data
60
64
  * @param options
61
65
  * @param mapping
@@ -93,11 +97,12 @@ function render(data, options = {}, mapping) {
93
97
  }), mapping);
94
98
  }
95
99
  /**
96
- * parse css file
100
+ * Parse css file
97
101
  * @param file url or path
98
102
  * @param options
99
103
  * @param asStream load file as stream
100
104
  *
105
+ * @deprecated
101
106
  * @throws Error file not found
102
107
  *
103
108
  * Example:
@@ -116,10 +121,11 @@ function render(data, options = {}, mapping) {
116
121
  * ```
117
122
  */
118
123
  async function parseFile(file, options = {}, asStream = false) {
119
- return Promise.resolve((options.load ?? load)(file, ".", asStream)).then((stream) => parse(stream, { src: file, ...options }));
124
+ console.warn("DeprecationWarning: parseFile is deprecated, use parse instead as parse({file, asStream, ...options})");
125
+ return parse({ file, asStream, ...options });
120
126
  }
121
127
  /**
122
- * parse css
128
+ * Parse css
123
129
  * @param stream
124
130
  * @param options
125
131
  *
@@ -146,7 +152,25 @@ async function parseFile(file, options = {}, asStream = false) {
146
152
  * console.log(result.ast);
147
153
  * ```
148
154
  */
149
- async function parse(stream, options = {}) {
155
+ async function parse(...args) {
156
+ let options;
157
+ let stream;
158
+ if (typeof args[0] === "string" || args[0] instanceof ReadableStream) {
159
+ stream = args[0];
160
+ options = args[1];
161
+ }
162
+ else {
163
+ // @ts-expect-error
164
+ const { file, input, ...opt } = args[0];
165
+ options = opt;
166
+ if (file != null) {
167
+ return Promise.resolve((options.load ?? load)(file, ".", options.asStream ?? false)).then((stream) => parse(stream, { src: options.file, ...options }));
168
+ }
169
+ else {
170
+ stream = input;
171
+ }
172
+ }
173
+ options ??= {};
150
174
  options.parseInfo = {
151
175
  stream,
152
176
  buffer: "",
@@ -169,31 +193,37 @@ async function parse(stream, options = {}) {
169
193
  });
170
194
  }
171
195
  /**
172
- * transform css file
196
+ * Transform css file
173
197
  * @param file url or path
174
198
  * @param options
175
199
  * @param asStream load file as stream
176
200
  *
201
+ * @deprecated
177
202
  * Example:
178
203
  *
179
204
  * ```ts
180
205
  *
181
- * import {transformFile} from '@tbela99/css-parser/web';
206
+ * import {transform} from '@tbela99/css-parser/web';
182
207
  *
183
- * // remote file
184
- * let result = await transformFile('https://docs.deno.com/styles.css');
208
+ * // remote file
209
+ * let result = await transform({file: 'https://docs.deno.com/styles.css'});
185
210
  * console.log(result.code);
186
211
  *
187
212
  * // local file
188
- * result = await transformFile('./css/styles.css');
213
+ * result = await transform({file: './css/styles.css'});
189
214
  * console.log(result.code);
190
215
  * ```
191
216
  */
192
217
  async function transformFile(file, options = {}, asStream = false) {
193
- return Promise.resolve((options.load ?? load)(file, ".", asStream)).then((stream) => transform(stream, { src: file, ...options }));
218
+ console.error("DeprecationWarning: transformFile is deprecated, use transform instead as transform({file, asStream, ...options})");
219
+ return transform({
220
+ file,
221
+ asStream,
222
+ ...options,
223
+ });
194
224
  }
195
225
  /**
196
- * transform css
226
+ * Transform css
197
227
  * @param css
198
228
  * @param options
199
229
  *
@@ -214,10 +244,27 @@ async function transformFile(file, options = {}, asStream = false) {
214
244
  * console.log(result.code);
215
245
  * ```
216
246
  */
217
- async function transform(css, options = {}) {
247
+ async function transform(...args) {
248
+ let options;
249
+ let stream;
250
+ if (typeof args[0] === "string" || args[0] instanceof ReadableStream) {
251
+ stream = args[0];
252
+ options = args[1];
253
+ }
254
+ else {
255
+ // @ts-expect-error
256
+ const { file, input, ...opt } = args[0];
257
+ options = opt;
258
+ if (file != null) {
259
+ return Promise.resolve((options.load ?? load)(file, ".", options.asStream ?? false)).then((stream) => transform(stream, { src: options.file, ...options }));
260
+ }
261
+ else {
262
+ stream = input;
263
+ }
264
+ }
218
265
  options = { minify: true, removeEmpty: true, removeCharset: true, ...options };
219
266
  const startTime = performance.now();
220
- return parse(css, options).then((parseResult) => {
267
+ return parse(stream, options).then((parseResult) => {
221
268
  let mapping = null;
222
269
  let importMapping = null;
223
270
  if (typeof options.module == "number" && options.module & ModuleScopeEnumOptions.ICSS) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tbela99/css-parser",
3
3
  "description": "CSS parser, minifier and validator for node and the browser",
4
- "version": "1.4.3",
4
+ "version": "1.4.4",
5
5
  "exports": {
6
6
  ".": "./dist/node.js",
7
7
  "./node": "./dist/node.js",
@@ -21,11 +21,13 @@
21
21
  "test": "web-test-runner \"./test/**/web.spec.js\" --timeout=10000 --node-resolve --playwright --browsers chromium firefox webkit --root-dir=.; mocha --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test/**/node.spec.js\"",
22
22
  "test:web": "web-test-runner \"./test/**/web.spec.js\" --timeout 30000 --node-resolve --playwright --browsers chromium firefox webkit --root-dir=.",
23
23
  "test:node": "mocha -p --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test/**/node.spec.js\"",
24
- "test:cov": "c8 -x 'test/specs/**/*.js' --reporter=html --reporter=text --reporter=json-summary mocha --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test/**/node.spec.js\"",
24
+ "test:cov": "superc8 -x 'test/specs/**/*.js' --reporter=html --reporter=text --reporter=json-summary mocha --reporter-options='maxDiffSize=1801920' --timeout=10000 'test/**/node.spec.js'",
25
25
  "test:web-cov": "web-test-runner -x 'test/specs/**/*.js' \"test/**/web.spec.js\" --node-resolve --playwright --browsers chromium firefox webkit --root-dir=. --coverage",
26
- "profile": "node --enable-source-maps --inspect-brk test/inspect.js",
27
- "syntax-update": "esno tools/validation.ts",
28
- "debug": "web-test-runner \"./test/**/web.spec.js\" --manual --open --node-resolve --root-dir=."
26
+ "profile": "deno run --allow-read --cpu-prof --cpu-prof-flamegraph test/inspect.js",
27
+ "config-update": "esno scripts/shorthand.ts",
28
+ "syntax-update": "esno scripts/validation.ts",
29
+ "debug:node": "mocha --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test/**/node.spec.js\"",
30
+ "debug:web": "web-test-runner \"./test/**/web.spec.js\" --manual --open --node-resolve --root-dir=."
29
31
  },
30
32
  "repository": {
31
33
  "type": "git",
@@ -65,19 +67,28 @@
65
67
  "@rollup/plugin-typescript": "^12.3.0",
66
68
  "@types/chai": "^5.2.3",
67
69
  "@types/mocha": "^10.0.10",
68
- "@types/node": "^25.9.3",
69
- "@types/web": "^0.0.350",
70
- "@web/test-runner": "^0.20.2",
71
- "@web/test-runner-playwright": "^0.11.1",
72
- "c8": "^11.0.0",
70
+ "@types/node": "^26.1.1",
71
+ "@types/web": "^0.0.352",
72
+ "@web/test-runner": "^1.0.0",
73
+ "@web/test-runner-playwright": "^1.0.0",
73
74
  "esno": "^4.8.0",
75
+ "markdown-it-task-lists": "^2.1.1",
74
76
  "mocha": "^11.7.6",
75
- "playwright": "^1.60.0",
76
- "rollup": "^4.61.1",
77
+ "playwright": "^1.61.1",
78
+ "rollup": "^4.62.2",
77
79
  "rollup-plugin-dts": "^6.4.1",
80
+ "superc8": "^12.7.0",
78
81
  "tslib": "^2.8.1",
79
- "typedoc": "^0.28.19",
80
- "typedoc-material-theme": "^1.4.1"
82
+ "typedoc": "^0.28.20",
83
+ "typedoc-plugin-coverage": "^4.0.3",
84
+ "typedoc-plugin-redirect": "^1.3.0",
85
+ "typedoc-unhoax-theme": "^0.5.3"
81
86
  },
82
- "sideEffects": false
87
+ "sideEffects": false,
88
+ "allowScripts": {
89
+ "esbuild@0.28.0": true,
90
+ "esbuild@0.28.1": true,
91
+ "fsevents@2.3.2": true,
92
+ "fsevents@2.3.3": true
93
+ }
83
94
  }
@@ -1 +0,0 @@
1
- {"/Users/thierrybela/web/WebstormProjects/css/src/lib/validation/json.ts":{"path":"/Users/thierrybela/web/WebstormProjects/css/src/lib/validation/json.ts","statementMap":{},"fnMap":{},"branchMap":{},"s":{},"f":{},"b":{},"all":true},"/Users/thierrybela/web/WebstormProjects/css/src/lib/parser/utils/at-rule-token.ts":{"path":"/Users/thierrybela/web/WebstormProjects/css/src/lib/parser/utils/at-rule-token.ts","statementMap":{},"fnMap":{"0":{"name":"parseAtRuleToken","decl":{"start":{"line":3,"column":16},"end":{"line":3,"column":32}},"loc":{"start":{"line":3,"column":35},"end":{"line":5,"column":1}},"line":3}},"branchMap":{},"s":{},"f":{"0":0},"b":{},"all":true},"/Users/thierrybela/web/WebstormProjects/css/src/lib/ast/features/index.ts":{"path":"/Users/thierrybela/web/WebstormProjects/css/src/lib/ast/features/index.ts","statementMap":{},"fnMap":{},"branchMap":{},"s":{},"f":{},"b":{},"all":true}}
@@ -1 +0,0 @@
1
- {"parent":null,"pid":30852,"argv":["/Users/thierrybela/.nvm/versions/node/v25.9.0/bin/node","/Users/thierrybela/web/WebstormProjects/css/node_modules/.bin/nyc","test/specs/node.spec.js"],"execArgv":[],"cwd":"/Users/thierrybela/web/WebstormProjects/css","time":1778344578772,"ppid":30830,"coverageFilename":"/Users/thierrybela/web/WebstormProjects/css/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json","externalId":"","uuid":"4874b20e-6f53-4d7a-be5a-cf68316925f2","files":["/Users/thierrybela/web/WebstormProjects/css/src/lib/validation/json.ts","/Users/thierrybela/web/WebstormProjects/css/src/lib/parser/utils/at-rule-token.ts","/Users/thierrybela/web/WebstormProjects/css/src/lib/ast/features/index.ts"]}
@@ -1 +0,0 @@
1
- {"parent":null,"pid":30856,"argv":["/Users/thierrybela/.nvm/versions/node/v25.9.0/bin/node","undefined"],"execArgv":["-e","\nconst pid = parseInt(process.argv[1], 10)\nprocess.title = 'node (foreground-child watchdog pid=' + pid + ')'\nif (!isNaN(pid)) {\n let barked = false\n // keepalive\n const interval = setInterval(() => {}, 60000)\n const bark = () => {\n clearInterval(interval)\n if (barked) return\n barked = true\n process.removeListener('SIGHUP', bark)\n setTimeout(() => {\n try {\n process.kill(pid, 'SIGKILL')\n setTimeout(() => process.exit(), 200)\n } catch (_) {}\n }, 500)\n })\n process.on('SIGHUP', bark)\n}\n"],"cwd":"/Users/thierrybela/web/WebstormProjects/css","time":1778344579338,"ppid":1,"coverageFilename":"/Users/thierrybela/web/WebstormProjects/css/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json","externalId":"","uuid":"6193bc4c-6f5f-4898-8950-c628825e6342","files":[]}
package/.repl_history DELETED
@@ -1,4 +0,0 @@
1
- exit()
2
- exit
3
- quit()
4
- quit
@@ -1,20 +0,0 @@
1
- <svg width="114.3" height="20" viewBox="0 0 1143 200" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="coverage: 85.25%">
2
- <title>coverage: 85.25%</title>
3
- <linearGradient id="AQOpN" x2="0" y2="100%">
4
- <stop offset="0" stop-opacity=".1" stop-color="#EEE"/>
5
- <stop offset="1" stop-opacity=".1"/>
6
- </linearGradient>
7
- <mask id="sgbWQ"><rect width="1143" height="200" rx="30" fill="#FFF"/></mask>
8
- <g mask="url(#sgbWQ)">
9
- <rect width="603" height="200" fill="#555"/>
10
- <rect width="540" height="200" fill="#F73" x="603"/>
11
- <rect width="1143" height="200" fill="url(#AQOpN)"/>
12
- </g>
13
- <g aria-hidden="true" fill="#fff" text-anchor="start" font-family="Verdana,DejaVu Sans,sans-serif" font-size="110">
14
- <text x="60" y="148" textLength="503" fill="#000" opacity="0.25">coverage</text>
15
- <text x="50" y="138" textLength="503">coverage</text>
16
- <text x="658" y="148" textLength="440" fill="#000" opacity="0.25">85.25%</text>
17
- <text x="648" y="138" textLength="440">85.25%</text>
18
- </g>
19
-
20
- </svg>