@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 +50 -7
- package/dist/ast/arena.js +5 -1
- package/dist/ast/features/type.js +1 -1
- package/dist/ast/types.js +10 -1
- package/dist/css_parser.wasm +0 -0
- package/dist/enums-extra.js +1 -1
- package/dist/exports.js +6 -1
- package/dist/index.d.ts +8664 -0
- package/dist/node.js +6 -2
- package/dist/runtime.js +37 -0
- package/dist/validation/parser/typedef.js +1 -1
- package/dist/version.js +1 -1
- package/dist/web.js +4 -1
- package/package.json +12 -4
package/dist/node.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* @ts-self-types="./index.d.ts" */
|
|
1
2
|
// node entry point (port of src/node.ts)
|
|
2
3
|
import { Readable } from "node:stream";
|
|
3
4
|
import { createReadStream } from "node:fs";
|
|
@@ -6,6 +7,7 @@ import { cwd } from "node:process";
|
|
|
6
7
|
import { createApi } from "./api.js";
|
|
7
8
|
import { matchUrl, resolve } from "./fs/resolve.js";
|
|
8
9
|
import { ResponseType } from "./enums-extra.js";
|
|
10
|
+
import { responseSize, setStreamSize } from "./runtime.js";
|
|
9
11
|
|
|
10
12
|
export * from "./exports.js";
|
|
11
13
|
|
|
@@ -30,7 +32,8 @@ export async function load(url, currentDirectory = ".", responseType = false) {
|
|
|
30
32
|
return response.json();
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
// the size of the body: rust allocates its buffers once
|
|
36
|
+
return responseType === ResponseType.ReadableStream ? setStreamSize(response.body, responseSize(response)) : response.text();
|
|
34
37
|
});
|
|
35
38
|
}
|
|
36
39
|
|
|
@@ -50,7 +53,8 @@ export async function load(url, currentDirectory = ".", responseType = false) {
|
|
|
50
53
|
);
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
// the size of the file: rust allocates its buffers once
|
|
57
|
+
return setStreamSize(Readable.toWeb(createReadStream(resolved.absolute, { encoding: "utf-8", highWaterMark: 64 * 1024 })), stats.size);
|
|
54
58
|
}
|
|
55
59
|
} catch (error) {}
|
|
56
60
|
|
package/dist/runtime.js
CHANGED
|
@@ -503,3 +503,40 @@ export class Runtime {
|
|
|
503
503
|
}
|
|
504
504
|
}
|
|
505
505
|
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* the size of the css of the streams, in bytes, when it is known (a file, a response with a content length)
|
|
509
|
+
*/
|
|
510
|
+
const streamSizes = new WeakMap();
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* record the size of the css of a stream, in bytes: rust allocates the code units and the arena once, like for an
|
|
514
|
+
* ArrayBuffer, instead of growing them as the stream is read. 0: the size is not known
|
|
515
|
+
*/
|
|
516
|
+
export function setStreamSize(stream, size) {
|
|
517
|
+
if (size > 0) {
|
|
518
|
+
streamSizes.set(stream, size);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
return stream;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* the size of the css of a stream, in bytes, see setStreamSize(). 0: the size is not known
|
|
526
|
+
*/
|
|
527
|
+
export function getStreamSize(stream) {
|
|
528
|
+
return stream == null ? 0 : (streamSizes.get(stream) ?? 0);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* the size of the body of a response: its content length, 0 when it is not known or when the body is compressed
|
|
533
|
+
*/
|
|
534
|
+
export function responseSize(response) {
|
|
535
|
+
if (response.headers.get("content-encoding") != null) {
|
|
536
|
+
return 0;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
const length = Number(response.headers.get("content-length"));
|
|
540
|
+
|
|
541
|
+
return Number.isFinite(length) && length > 0 ? length : 0;
|
|
542
|
+
}
|
package/dist/version.js
CHANGED
package/dist/web.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/* @ts-self-types="./index.d.ts" */
|
|
1
2
|
// browser entry point (port of src/web.ts)
|
|
2
3
|
import { createApi } from "./api.js";
|
|
3
4
|
import { getRuntime } from "./core.js";
|
|
4
5
|
import { dirname, matchUrl, resolve } from "./fs/resolve.js";
|
|
5
6
|
import { ResponseType } from "./enums-extra.js";
|
|
7
|
+
import { responseSize, setStreamSize } from "./runtime.js";
|
|
6
8
|
|
|
7
9
|
export * from "./exports.js";
|
|
8
10
|
export { PropertyList } from "./parser/declaration/list.js";
|
|
@@ -40,7 +42,8 @@ export async function load(url, currentDirectory = ".", responseType = false) {
|
|
|
40
42
|
return response.json();
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
// the size of the body: rust allocates its buffers once
|
|
46
|
+
return responseType === ResponseType.ReadableStream ? setStreamSize(response.body, responseSize(response)) : response.text();
|
|
44
47
|
});
|
|
45
48
|
}
|
|
46
49
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbela99/rust-css-parser-wasm",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,21 +11,29 @@
|
|
|
11
11
|
],
|
|
12
12
|
"description": "CSS parser, validator and minifier for node and the browsers: the rust port of @tbela99/css-parser as a WebAssembly module",
|
|
13
13
|
"main": "./dist/node.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
14
15
|
"browser": "./dist/web.js",
|
|
15
16
|
"exports": {
|
|
16
17
|
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
17
19
|
"node": "./dist/node.js",
|
|
18
20
|
"default": "./dist/web.js"
|
|
19
21
|
},
|
|
20
|
-
"./node":
|
|
21
|
-
|
|
22
|
+
"./node": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/node.js"
|
|
25
|
+
},
|
|
26
|
+
"./web": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/web.js"
|
|
29
|
+
},
|
|
22
30
|
"./package.json": "./package.json"
|
|
23
31
|
},
|
|
24
32
|
"scripts": {
|
|
25
33
|
"build": "sh ../../build-bindings.sh wasm",
|
|
26
34
|
"test": "cd ../.. && npm run test:wasm && npm run test:web",
|
|
27
35
|
"prepublishOnly": "cd ../.. && npm run build:wasm && npm run test:wasm",
|
|
28
|
-
"prepare": "node ../../scripts/prepare-extension.
|
|
36
|
+
"prepare": "node ../../scripts/prepare-extension.js wasm"
|
|
29
37
|
},
|
|
30
38
|
"author": "Thierry Bela",
|
|
31
39
|
"repository": {
|