@tbela99/rust-css-parser-wasm 2.3.1 → 2.3.2

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/api.js CHANGED
@@ -2,6 +2,7 @@
2
2
  // are completed like the typescript entry points, the work is done by rust.
3
3
 
4
4
  import { readAll, rt as defaultRuntime, runtimeOf } from "./core.js";
5
+ import { getStreamSize } from "./runtime.js";
5
6
  import "./ast/arena.js";
6
7
  import { ModuleScopeEnumOptions } from "./ast/types.js";
7
8
  import { ResponseType } from "./enums-extra.js";
@@ -46,7 +47,10 @@ function transformResult(result) {
46
47
 
47
48
  function transformDefaults(options) {
48
49
  options = { ...options };
49
- options.minify ??= true;
50
+ // the fast mode sets the default value of minify (see fastModeOptions)
51
+ if (!options.fastMode) {
52
+ options.minify ??= true;
53
+ }
50
54
  options.removeEmpty ??= true;
51
55
  options.removeCharset ??= true;
52
56
  return options;
@@ -64,6 +68,39 @@ function splitArguments(args, stream) {
64
68
  return [input, options, file];
65
69
  }
66
70
 
71
+ /**
72
+ * the arguments of an async parse: a stream is read by rust while the css is parsed, chunk by chunk. the `stream`
73
+ * option is the reader of the chunks: it returns the next chunk (bytes or text), `null` at the end of the stream
74
+ * @param input the css: a string, an ArrayBuffer, a view of an ArrayBuffer or a stream
75
+ * @param options
76
+ */
77
+ function streamArguments(input, options) {
78
+ if (typeof ReadableStream === "undefined" || !(input instanceof ReadableStream)) {
79
+ return [input, options];
80
+ }
81
+
82
+ const reader = input.getReader();
83
+
84
+ return [
85
+ null,
86
+ {
87
+ ...options,
88
+ // the size of the css when it is known: rust allocates the code units and the arena once
89
+ streamSize: getStreamSize(input),
90
+ stream: async function stream() {
91
+ const { done, value } = await reader.read();
92
+
93
+ if (done) {
94
+ reader.releaseLock();
95
+ return null;
96
+ }
97
+
98
+ return value;
99
+ },
100
+ },
101
+ ];
102
+ }
103
+
67
104
  /**
68
105
  * @param host `{ load, cwd(), runtime }`: the default loader, the current directory of the platform and the runtime of
69
106
  * the backend (the default runtime when it is not set)
@@ -79,6 +116,8 @@ export function createApi(host) {
79
116
  function parseSync(...args) {
80
117
  const [stream, options] = splitArguments(args, false);
81
118
 
119
+ options?.signal?.throwIfAborted();
120
+
82
121
  if (options != null) {
83
122
  validateSyncArguments(options);
84
123
  }
@@ -89,6 +128,8 @@ export function createApi(host) {
89
128
  function transformSync(...args) {
90
129
  const [stream, opts] = splitArguments(args, false);
91
130
 
131
+ opts?.signal?.throwIfAborted();
132
+
92
133
  if (opts != null) {
93
134
  validateSyncArguments(opts);
94
135
  }
@@ -110,18 +151,22 @@ export function createApi(host) {
110
151
  async function parse(...args) {
111
152
  const [stream, options = {}, file] = splitArguments(args, true);
112
153
 
154
+ options.signal?.throwIfAborted();
155
+
113
156
  if (file != null) {
114
157
  return loadFile(file, options).then((stream) => parse(stream, { src: file, ...options }));
115
158
  }
116
159
 
117
- const input = await readAll(stream);
118
-
119
- return rt.run(rt.call("parse", input, { ...options, load: options.load ?? load, cwd: options.cwd ?? host.cwd() }));
160
+ return rt.run(
161
+ rt.call("parse", ...streamArguments(stream, { ...options, load: options.load ?? load, cwd: options.cwd ?? host.cwd() })),
162
+ );
120
163
  }
121
164
 
122
165
  async function transform(...args) {
123
166
  const [stream, opts = {}, file] = splitArguments(args, true);
124
167
 
168
+ opts.signal?.throwIfAborted();
169
+
125
170
  if (file != null) {
126
171
  return loadFile(file, opts).then((stream) => transform(stream, { src: file, ...opts }));
127
172
  }
@@ -131,9 +176,7 @@ export function createApi(host) {
131
176
  options.load ??= load;
132
177
  options.cwd ??= host.cwd();
133
178
 
134
- const input = await readAll(stream);
135
-
136
- return transformResult(await rt.run(rt.call("transform", input, options)));
179
+ return transformResult(await rt.run(rt.call("transform", ...streamArguments(stream, options))));
137
180
  }
138
181
 
139
182
  return { render, parse, parseSync, transform, transformSync };
package/dist/ast/arena.js CHANGED
@@ -119,7 +119,8 @@ export function structuredFields(typ) {
119
119
  * state of an arena wrapper: rust handle, cached column views, javascript columns (transfer)
120
120
  */
121
121
  const states = new WeakMap();
122
- // the wrappers by handle are `runtime.arenas`: an arena returned twice by rust is the same object
122
+ // the wrappers by handle are `runtime.arenas`: an arena returned twice by rust is the same object. the rust arena is
123
+ // released when its wrapper is garbage collected
123
124
  const registry = new FinalizationRegistry(({ runtime, handle }) => {
124
125
  runtime.arenas.delete(handle);
125
126
 
@@ -617,11 +618,14 @@ for (const method of [
617
618
  "getRight",
618
619
  "setOp",
619
620
  "getOp",
621
+ "setOp2",
622
+ "getOp2",
620
623
  "setSpan",
621
624
  "copySpan",
622
625
  "getSourceId",
623
626
  "getSpanStart",
624
627
  "getSpanEnd",
628
+ "setSpandStart",
625
629
  "setSpanEnd",
626
630
  "resolveString",
627
631
  "detach",
@@ -1,4 +1,4 @@
1
- // Enums of the typescript API (data only). Generated by scripts/gen-enums.mjs.
1
+ // Enums of the typescript API (data only). Generated by scripts/gen-enums.js.
2
2
 
3
3
  export const FeatureWalkMode = Object.freeze({
4
4
  "Pre": 1,
package/dist/ast/types.js CHANGED
@@ -1,4 +1,4 @@
1
- // Enums of the typescript API (data only). Generated by scripts/gen-enums.mjs.
1
+ // Enums of the typescript API (data only). Generated by scripts/gen-enums.js.
2
2
 
3
3
  export const ColorType = Object.freeze({
4
4
  "NONE": 0,
@@ -414,6 +414,15 @@ export const EnumToken = Object.freeze({
414
414
  "17": "TimelineFunction",
415
415
  });
416
416
 
417
+ export const MergeRulesEnum = Object.freeze({
418
+ "None": 0,
419
+ "Identical": 1,
420
+ "All": 2,
421
+ "0": "None",
422
+ "1": "Identical",
423
+ "2": "All",
424
+ });
425
+
417
426
  export const ModuleCaseTransformEnum = Object.freeze({
418
427
  "IgnoreCase": 1,
419
428
  "CamelCase": 2,
Binary file
@@ -1,4 +1,4 @@
1
- // Enums of the typescript API (data only). Generated by scripts/gen-enums.mjs.
1
+ // Enums of the typescript API (data only). Generated by scripts/gen-enums.js.
2
2
 
3
3
  export const ResponseType = Object.freeze({
4
4
  "Text": 0,
package/dist/exports.js CHANGED
@@ -7,10 +7,15 @@ export { convertColor } from "./syntax/color/color.js";
7
7
  export { isOkLabClose, okLabDistance } from "./syntax/color/utils/distance.js";
8
8
  export { Arena, AstArena, TokenField, arenaColumns } from "./ast/arena.js";
9
9
  export { ARENA, ARENAID, AstArenaNode } from "./ast/arena-node.js";
10
- export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, ModuleScopeEnumOptions, WalkerEvent, WalkerOptionEnum } from "./ast/types.js";
10
+ export { ColorType, EnumAstNodeStatus, EnumToken, MergeRulesEnum, ModuleCaseTransformEnum, ModuleScopeEnumOptions, WalkerEvent, WalkerOptionEnum } from "./ast/types.js";
11
11
  export { SourceMap } from "./printer/sourcemap.js";
12
12
  export { FeatureWalkMode } from "./ast/features/type.js";
13
13
  export { parseSyntax } from "./validation/parser/parse.js";
14
14
  export { ResponseType } from "./enums-extra.js";
15
15
  export { dirname, resolve } from "./fs/resolve.js";
16
16
  export { version } from "./version.js";
17
+ export { ValidationTokenEnum } from "./validation/parser/typedef.js";
18
+ /**
19
+ * key of the position of a validation token in the syntax, see {@link ValidationToken}
20
+ */
21
+ export const LOC = Symbol.for("loc");