@napi-rs/image-wasm32-wasi 1.9.2 → 1.11.0
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/image.wasi-browser.js +15 -48
- package/image.wasi.cjs +48 -43
- package/image.wasm32-wasi.wasm +0 -0
- package/package.json +2 -2
- package/wasi-worker-browser.mjs +0 -8
- package/wasi-worker.mjs +16 -3
package/image.wasi-browser.js
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createOnMessage as __wasmCreateOnMessageForFsProxy,
|
|
3
3
|
getDefaultContext as __emnapiGetDefaultContext,
|
|
4
|
+
instantiateNapiModule as __emnapiInstantiateNapiModule,
|
|
4
5
|
WASI as __WASI,
|
|
5
6
|
} from '@napi-rs/wasm-runtime'
|
|
6
|
-
import { Volume as __Volume, createFsFromVolume as __createFsFromVolume } from '@napi-rs/wasm-runtime/fs'
|
|
7
7
|
|
|
8
|
-
import __wasmUrl from './image.wasm32-wasi.wasm?url'
|
|
9
|
-
|
|
10
|
-
const __fs = __createFsFromVolume(
|
|
11
|
-
__Volume.fromJSON({
|
|
12
|
-
'/': null,
|
|
13
|
-
}),
|
|
14
|
-
)
|
|
15
8
|
|
|
16
9
|
const __wasi = new __WASI({
|
|
17
10
|
version: 'preview1',
|
|
18
|
-
fs: __fs,
|
|
19
11
|
})
|
|
20
12
|
|
|
13
|
+
const __wasmUrl = new URL('./image.wasm32-wasi.wasm', import.meta.url).href
|
|
21
14
|
const __emnapiContext = __emnapiGetDefaultContext()
|
|
22
15
|
|
|
23
16
|
const __sharedMemory = new WebAssembly.Memory({
|
|
24
|
-
initial:
|
|
25
|
-
maximum:
|
|
17
|
+
initial: 4000,
|
|
18
|
+
maximum: 65536,
|
|
26
19
|
shared: true,
|
|
27
20
|
})
|
|
28
21
|
|
|
@@ -32,14 +25,16 @@ const {
|
|
|
32
25
|
instance: __napiInstance,
|
|
33
26
|
module: __wasiModule,
|
|
34
27
|
napiModule: __napiModule,
|
|
35
|
-
} =
|
|
28
|
+
} = await __emnapiInstantiateNapiModule(__wasmFile, {
|
|
36
29
|
context: __emnapiContext,
|
|
37
30
|
asyncWorkPoolSize: 4,
|
|
38
31
|
wasi: __wasi,
|
|
39
32
|
onCreateWorker() {
|
|
40
|
-
|
|
33
|
+
const worker = new Worker(new URL('@napi-rs/image-wasm32-wasi/wasi-worker-browser.mjs', import.meta.url), {
|
|
41
34
|
type: 'module',
|
|
42
35
|
})
|
|
36
|
+
|
|
37
|
+
return worker
|
|
43
38
|
},
|
|
44
39
|
overwriteImports(importObject) {
|
|
45
40
|
importObject.env = {
|
|
@@ -51,42 +46,14 @@ const {
|
|
|
51
46
|
return importObject
|
|
52
47
|
},
|
|
53
48
|
beforeInit({ instance }) {
|
|
54
|
-
|
|
49
|
+
for (const name of Object.keys(instance.exports)) {
|
|
50
|
+
if (name.startsWith('__napi_register__')) {
|
|
51
|
+
instance.exports[name]()
|
|
52
|
+
}
|
|
53
|
+
}
|
|
55
54
|
},
|
|
56
55
|
})
|
|
57
|
-
|
|
58
|
-
function __napi_rs_initialize_modules(__napiInstance) {
|
|
59
|
-
__napiInstance.exports['__napi_register__AvifConfig_struct_0']?.()
|
|
60
|
-
__napiInstance.exports['__napi_register__ChromaSubsampling_1']?.()
|
|
61
|
-
__napiInstance.exports['__napi_register__FastResizeFilter_2']?.()
|
|
62
|
-
__napiInstance.exports['__napi_register__ResizeFit_3']?.()
|
|
63
|
-
__napiInstance.exports['__napi_register__FastResizeOptions_struct_4']?.()
|
|
64
|
-
__napiInstance.exports['__napi_register__JpegCompressOptions_struct_5']?.()
|
|
65
|
-
__napiInstance.exports['__napi_register__compress_jpeg_sync_6']?.()
|
|
66
|
-
__napiInstance.exports['__napi_register__CompressJpegTask_impl_7']?.()
|
|
67
|
-
__napiInstance.exports['__napi_register__compress_jpeg_8']?.()
|
|
68
|
-
__napiInstance.exports['__napi_register__CompressionType_9']?.()
|
|
69
|
-
__napiInstance.exports['__napi_register__FilterType_10']?.()
|
|
70
|
-
__napiInstance.exports['__napi_register__PngEncodeOptions_struct_11']?.()
|
|
71
|
-
__napiInstance.exports['__napi_register__PngRowFilter_12']?.()
|
|
72
|
-
__napiInstance.exports['__napi_register__PNGLosslessOptions_struct_13']?.()
|
|
73
|
-
__napiInstance.exports['__napi_register__lossless_compress_png_sync_14']?.()
|
|
74
|
-
__napiInstance.exports['__napi_register__LosslessPngTask_impl_15']?.()
|
|
75
|
-
__napiInstance.exports['__napi_register__lossless_compress_png_16']?.()
|
|
76
|
-
__napiInstance.exports['__napi_register__PngQuantOptions_struct_17']?.()
|
|
77
|
-
__napiInstance.exports['__napi_register__png_quantize_sync_18']?.()
|
|
78
|
-
__napiInstance.exports['__napi_register__PngQuantTask_impl_19']?.()
|
|
79
|
-
__napiInstance.exports['__napi_register__png_quantize_20']?.()
|
|
80
|
-
__napiInstance.exports['__napi_register__Orientation_21']?.()
|
|
81
|
-
__napiInstance.exports['__napi_register__ResizeFilterType_22']?.()
|
|
82
|
-
__napiInstance.exports['__napi_register__JsColorType_23']?.()
|
|
83
|
-
__napiInstance.exports['__napi_register__Metadata_struct_24']?.()
|
|
84
|
-
__napiInstance.exports['__napi_register__MetadataTask_impl_25']?.()
|
|
85
|
-
__napiInstance.exports['__napi_register__ResizeOptions_struct_26']?.()
|
|
86
|
-
__napiInstance.exports['__napi_register__EncodeTask_impl_27']?.()
|
|
87
|
-
__napiInstance.exports['__napi_register__Transformer_struct_28']?.()
|
|
88
|
-
__napiInstance.exports['__napi_register__Transformer_impl_70']?.()
|
|
89
|
-
}
|
|
56
|
+
export default __napiModule.exports
|
|
90
57
|
export const Transformer = __napiModule.exports.Transformer
|
|
91
58
|
export const ChromaSubsampling = __napiModule.exports.ChromaSubsampling
|
|
92
59
|
export const CompressionType = __napiModule.exports.CompressionType
|
package/image.wasi.cjs
CHANGED
|
@@ -3,35 +3,41 @@
|
|
|
3
3
|
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
|
-
const __nodeFs= require('node:fs')
|
|
6
|
+
const __nodeFs = require('node:fs')
|
|
7
7
|
const __nodePath = require('node:path')
|
|
8
8
|
const { WASI: __nodeWASI } = require('node:wasi')
|
|
9
9
|
const { Worker } = require('node:worker_threads')
|
|
10
10
|
|
|
11
11
|
const {
|
|
12
|
-
|
|
12
|
+
createOnMessage: __wasmCreateOnMessageForFsProxy,
|
|
13
13
|
getDefaultContext: __emnapiGetDefaultContext,
|
|
14
|
+
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
|
|
14
15
|
} = require('@napi-rs/wasm-runtime')
|
|
15
16
|
|
|
17
|
+
const __rootDir = __nodePath.parse(process.cwd()).root
|
|
18
|
+
|
|
16
19
|
const __wasi = new __nodeWASI({
|
|
17
20
|
version: 'preview1',
|
|
18
21
|
env: process.env,
|
|
19
22
|
preopens: {
|
|
20
|
-
|
|
23
|
+
[__rootDir]: __rootDir,
|
|
21
24
|
}
|
|
22
25
|
})
|
|
23
26
|
|
|
24
27
|
const __emnapiContext = __emnapiGetDefaultContext()
|
|
25
28
|
|
|
26
29
|
const __sharedMemory = new WebAssembly.Memory({
|
|
27
|
-
initial:
|
|
28
|
-
maximum:
|
|
30
|
+
initial: 4000,
|
|
31
|
+
maximum: 65536,
|
|
29
32
|
shared: true,
|
|
30
33
|
})
|
|
31
34
|
|
|
32
35
|
let __wasmFilePath = __nodePath.join(__dirname, 'image.wasm32-wasi.wasm')
|
|
36
|
+
const __wasmDebugFilePath = __nodePath.join(__dirname, 'image.wasm32-wasi.debug.wasm')
|
|
33
37
|
|
|
34
|
-
if (
|
|
38
|
+
if (__nodeFs.existsSync(__wasmDebugFilePath)) {
|
|
39
|
+
__wasmFilePath = __wasmDebugFilePath
|
|
40
|
+
} else if (!__nodeFs.existsSync(__wasmFilePath)) {
|
|
35
41
|
try {
|
|
36
42
|
__wasmFilePath = __nodePath.resolve('@napi-rs/image-wasm32-wasi')
|
|
37
43
|
} catch {
|
|
@@ -50,12 +56,39 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
|
|
|
50
56
|
return 4
|
|
51
57
|
}
|
|
52
58
|
})(),
|
|
59
|
+
reuseWorker: true,
|
|
53
60
|
wasi: __wasi,
|
|
54
61
|
onCreateWorker() {
|
|
55
|
-
|
|
62
|
+
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
|
|
56
63
|
env: process.env,
|
|
57
|
-
execArgv: ['--experimental-wasi-unstable-preview1'],
|
|
58
64
|
})
|
|
65
|
+
worker.onmessage = ({ data }) => {
|
|
66
|
+
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// The main thread of Node.js waits for all the active handles before exiting.
|
|
70
|
+
// But Rust threads are never waited without `thread::join`.
|
|
71
|
+
// So here we hack the code of Node.js to prevent the workers from being referenced (active).
|
|
72
|
+
// According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
|
|
73
|
+
// a worker is consist of two handles: kPublicPort and kHandle.
|
|
74
|
+
{
|
|
75
|
+
const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
|
|
76
|
+
s.toString().includes("kPublicPort")
|
|
77
|
+
);
|
|
78
|
+
if (kPublicPort) {
|
|
79
|
+
worker[kPublicPort].ref = () => {};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
|
|
83
|
+
s.toString().includes("kHandle")
|
|
84
|
+
);
|
|
85
|
+
if (kPublicPort) {
|
|
86
|
+
worker[kHandle].ref = () => {};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
worker.unref();
|
|
90
|
+
}
|
|
91
|
+
return worker
|
|
59
92
|
},
|
|
60
93
|
overwriteImports(importObject) {
|
|
61
94
|
importObject.env = {
|
|
@@ -67,42 +100,14 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
|
|
|
67
100
|
return importObject
|
|
68
101
|
},
|
|
69
102
|
beforeInit({ instance }) {
|
|
70
|
-
|
|
71
|
-
|
|
103
|
+
for (const name of Object.keys(instance.exports)) {
|
|
104
|
+
if (name.startsWith('__napi_register__')) {
|
|
105
|
+
instance.exports[name]()
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
72
109
|
})
|
|
73
|
-
|
|
74
|
-
function __napi_rs_initialize_modules(__napiInstance) {
|
|
75
|
-
__napiInstance.exports['__napi_register__AvifConfig_struct_0']?.()
|
|
76
|
-
__napiInstance.exports['__napi_register__ChromaSubsampling_1']?.()
|
|
77
|
-
__napiInstance.exports['__napi_register__FastResizeFilter_2']?.()
|
|
78
|
-
__napiInstance.exports['__napi_register__ResizeFit_3']?.()
|
|
79
|
-
__napiInstance.exports['__napi_register__FastResizeOptions_struct_4']?.()
|
|
80
|
-
__napiInstance.exports['__napi_register__JpegCompressOptions_struct_5']?.()
|
|
81
|
-
__napiInstance.exports['__napi_register__compress_jpeg_sync_6']?.()
|
|
82
|
-
__napiInstance.exports['__napi_register__CompressJpegTask_impl_7']?.()
|
|
83
|
-
__napiInstance.exports['__napi_register__compress_jpeg_8']?.()
|
|
84
|
-
__napiInstance.exports['__napi_register__CompressionType_9']?.()
|
|
85
|
-
__napiInstance.exports['__napi_register__FilterType_10']?.()
|
|
86
|
-
__napiInstance.exports['__napi_register__PngEncodeOptions_struct_11']?.()
|
|
87
|
-
__napiInstance.exports['__napi_register__PngRowFilter_12']?.()
|
|
88
|
-
__napiInstance.exports['__napi_register__PNGLosslessOptions_struct_13']?.()
|
|
89
|
-
__napiInstance.exports['__napi_register__lossless_compress_png_sync_14']?.()
|
|
90
|
-
__napiInstance.exports['__napi_register__LosslessPngTask_impl_15']?.()
|
|
91
|
-
__napiInstance.exports['__napi_register__lossless_compress_png_16']?.()
|
|
92
|
-
__napiInstance.exports['__napi_register__PngQuantOptions_struct_17']?.()
|
|
93
|
-
__napiInstance.exports['__napi_register__png_quantize_sync_18']?.()
|
|
94
|
-
__napiInstance.exports['__napi_register__PngQuantTask_impl_19']?.()
|
|
95
|
-
__napiInstance.exports['__napi_register__png_quantize_20']?.()
|
|
96
|
-
__napiInstance.exports['__napi_register__Orientation_21']?.()
|
|
97
|
-
__napiInstance.exports['__napi_register__ResizeFilterType_22']?.()
|
|
98
|
-
__napiInstance.exports['__napi_register__JsColorType_23']?.()
|
|
99
|
-
__napiInstance.exports['__napi_register__Metadata_struct_24']?.()
|
|
100
|
-
__napiInstance.exports['__napi_register__MetadataTask_impl_25']?.()
|
|
101
|
-
__napiInstance.exports['__napi_register__ResizeOptions_struct_26']?.()
|
|
102
|
-
__napiInstance.exports['__napi_register__EncodeTask_impl_27']?.()
|
|
103
|
-
__napiInstance.exports['__napi_register__Transformer_struct_28']?.()
|
|
104
|
-
__napiInstance.exports['__napi_register__Transformer_impl_70']?.()
|
|
105
|
-
}
|
|
110
|
+
module.exports = __napiModule.exports
|
|
106
111
|
module.exports.Transformer = __napiModule.exports.Transformer
|
|
107
112
|
module.exports.ChromaSubsampling = __napiModule.exports.ChromaSubsampling
|
|
108
113
|
module.exports.CompressionType = __napiModule.exports.CompressionType
|
package/image.wasm32-wasi.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/image-wasm32-wasi",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"cpu": [
|
|
5
5
|
"wasm32"
|
|
6
6
|
],
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
"repository": "git@github.com:Brooooooklyn/Image.git",
|
|
39
39
|
"browser": "image.wasi-browser.js",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@napi-rs/wasm-runtime": "^0.2.
|
|
41
|
+
"@napi-rs/wasm-runtime": "^0.2.11"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/wasi-worker-browser.mjs
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
|
|
2
|
-
import { Volume, createFsFromVolume } from '@napi-rs/wasm-runtime/fs'
|
|
3
|
-
|
|
4
|
-
const fs = createFsFromVolume(
|
|
5
|
-
Volume.fromJSON({
|
|
6
|
-
'/': null,
|
|
7
|
-
}),
|
|
8
|
-
)
|
|
9
2
|
|
|
10
3
|
const handler = new MessageHandler({
|
|
11
4
|
onLoad({ wasmModule, wasmMemory }) {
|
|
12
5
|
const wasi = new WASI({
|
|
13
|
-
fs,
|
|
14
6
|
print: function () {
|
|
15
7
|
// eslint-disable-next-line no-console
|
|
16
8
|
console.log.apply(console, arguments)
|
package/wasi-worker.mjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
+
import { parse } from "node:path";
|
|
4
|
+
import { WASI } from "node:wasi";
|
|
3
5
|
import { parentPort, Worker } from "node:worker_threads";
|
|
4
6
|
|
|
5
|
-
import { instantiateNapiModuleSync, MessageHandler, WASI } from "@napi-rs/wasm-runtime";
|
|
6
|
-
|
|
7
7
|
const require = createRequire(import.meta.url);
|
|
8
8
|
|
|
9
|
+
const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime");
|
|
10
|
+
|
|
9
11
|
if (parentPort) {
|
|
10
12
|
parentPort.on("message", (data) => {
|
|
11
13
|
globalThis.onmessage({ data });
|
|
@@ -26,13 +28,24 @@ Object.assign(globalThis, {
|
|
|
26
28
|
},
|
|
27
29
|
});
|
|
28
30
|
|
|
31
|
+
const emnapiContext = getDefaultContext();
|
|
32
|
+
|
|
33
|
+
const __rootDir = parse(process.cwd()).root;
|
|
34
|
+
|
|
29
35
|
const handler = new MessageHandler({
|
|
30
36
|
onLoad({ wasmModule, wasmMemory }) {
|
|
31
|
-
const wasi = new WASI({
|
|
37
|
+
const wasi = new WASI({
|
|
38
|
+
version: 'preview1',
|
|
39
|
+
env: process.env,
|
|
40
|
+
preopens: {
|
|
41
|
+
[__rootDir]: __rootDir,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
32
44
|
|
|
33
45
|
return instantiateNapiModuleSync(wasmModule, {
|
|
34
46
|
childThread: true,
|
|
35
47
|
wasi,
|
|
48
|
+
context: emnapiContext,
|
|
36
49
|
overwriteImports(importObject) {
|
|
37
50
|
importObject.env = {
|
|
38
51
|
...importObject.env,
|