@napi-rs/image-wasm32-wasi 1.8.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/README.md +3 -0
- package/image.wasi-browser.js +105 -0
- package/image.wasi.cjs +121 -0
- package/image.wasm32-wasi.wasm +0 -0
- package/package.json +43 -0
- package/wasi-worker-browser.mjs +40 -0
- package/wasi-worker.mjs +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
|
|
3
|
+
getDefaultContext as __emnapiGetDefaultContext,
|
|
4
|
+
WASI as __WASI,
|
|
5
|
+
} from '@napi-rs/wasm-runtime'
|
|
6
|
+
import { Volume as __Volume, createFsFromVolume as __createFsFromVolume } from '@napi-rs/wasm-runtime/fs'
|
|
7
|
+
|
|
8
|
+
import __wasmUrl from './image.wasm32-wasi.wasm?url'
|
|
9
|
+
|
|
10
|
+
const __fs = __createFsFromVolume(
|
|
11
|
+
__Volume.fromJSON({
|
|
12
|
+
'/': null,
|
|
13
|
+
}),
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
const __wasi = new __WASI({
|
|
17
|
+
version: 'preview1',
|
|
18
|
+
fs: __fs,
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const __emnapiContext = __emnapiGetDefaultContext()
|
|
22
|
+
|
|
23
|
+
const __sharedMemory = new WebAssembly.Memory({
|
|
24
|
+
initial: 1024,
|
|
25
|
+
maximum: 10240,
|
|
26
|
+
shared: true,
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
instance: __napiInstance,
|
|
33
|
+
module: __wasiModule,
|
|
34
|
+
napiModule: __napiModule,
|
|
35
|
+
} = __emnapiInstantiateNapiModuleSync(__wasmFile, {
|
|
36
|
+
context: __emnapiContext,
|
|
37
|
+
asyncWorkPoolSize: 4,
|
|
38
|
+
wasi: __wasi,
|
|
39
|
+
onCreateWorker() {
|
|
40
|
+
return new Worker(new URL('@napi-rs/image-wasm32-wasi/wasi-worker-browser.mjs', import.meta.url), {
|
|
41
|
+
type: 'module',
|
|
42
|
+
})
|
|
43
|
+
},
|
|
44
|
+
overwriteImports(importObject) {
|
|
45
|
+
importObject.env = {
|
|
46
|
+
...importObject.env,
|
|
47
|
+
...importObject.napi,
|
|
48
|
+
...importObject.emnapi,
|
|
49
|
+
memory: __sharedMemory,
|
|
50
|
+
}
|
|
51
|
+
return importObject
|
|
52
|
+
},
|
|
53
|
+
beforeInit({ instance }) {
|
|
54
|
+
__napi_rs_initialize_modules(instance)
|
|
55
|
+
},
|
|
56
|
+
})
|
|
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
|
+
}
|
|
90
|
+
export const Transformer = __napiModule.exports.Transformer
|
|
91
|
+
export const ChromaSubsampling = __napiModule.exports.ChromaSubsampling
|
|
92
|
+
export const CompressionType = __napiModule.exports.CompressionType
|
|
93
|
+
export const compressJpeg = __napiModule.exports.compressJpeg
|
|
94
|
+
export const compressJpegSync = __napiModule.exports.compressJpegSync
|
|
95
|
+
export const FastResizeFilter = __napiModule.exports.FastResizeFilter
|
|
96
|
+
export const FilterType = __napiModule.exports.FilterType
|
|
97
|
+
export const JsColorType = __napiModule.exports.JsColorType
|
|
98
|
+
export const losslessCompressPng = __napiModule.exports.losslessCompressPng
|
|
99
|
+
export const losslessCompressPngSync = __napiModule.exports.losslessCompressPngSync
|
|
100
|
+
export const Orientation = __napiModule.exports.Orientation
|
|
101
|
+
export const pngQuantize = __napiModule.exports.pngQuantize
|
|
102
|
+
export const pngQuantizeSync = __napiModule.exports.pngQuantizeSync
|
|
103
|
+
export const PngRowFilter = __napiModule.exports.PngRowFilter
|
|
104
|
+
export const ResizeFilterType = __napiModule.exports.ResizeFilterType
|
|
105
|
+
export const ResizeFit = __napiModule.exports.ResizeFit
|
package/image.wasi.cjs
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* prettier-ignore */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
const __nodeFs= require('node:fs')
|
|
7
|
+
const __nodePath = require('node:path')
|
|
8
|
+
const { WASI: __nodeWASI } = require('node:wasi')
|
|
9
|
+
const { Worker } = require('node:worker_threads')
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
|
|
13
|
+
getDefaultContext: __emnapiGetDefaultContext,
|
|
14
|
+
} = require('@napi-rs/wasm-runtime')
|
|
15
|
+
|
|
16
|
+
const __wasi = new __nodeWASI({
|
|
17
|
+
version: 'preview1',
|
|
18
|
+
env: process.env,
|
|
19
|
+
preopens: {
|
|
20
|
+
'/': '/'
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const __emnapiContext = __emnapiGetDefaultContext()
|
|
25
|
+
|
|
26
|
+
const __sharedMemory = new WebAssembly.Memory({
|
|
27
|
+
initial: 1024,
|
|
28
|
+
maximum: 10240,
|
|
29
|
+
shared: true,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
let __wasmFilePath = __nodePath.join(__dirname, 'image.wasm32-wasi.wasm')
|
|
33
|
+
|
|
34
|
+
if (!__nodeFs.existsSync(__wasmFilePath)) {
|
|
35
|
+
try {
|
|
36
|
+
__wasmFilePath = __nodePath.resolve('@napi-rs/image-wasm32-wasi')
|
|
37
|
+
} catch {
|
|
38
|
+
throw new Error('Cannot find image.wasm32-wasi.wasm file, and @napi-rs/image-wasm32-wasi package is not installed.')
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
|
|
43
|
+
context: __emnapiContext,
|
|
44
|
+
asyncWorkPoolSize: (function() {
|
|
45
|
+
const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE)
|
|
46
|
+
// NaN > 0 is false
|
|
47
|
+
if (threadsSizeFromEnv > 0) {
|
|
48
|
+
return threadsSizeFromEnv
|
|
49
|
+
} else {
|
|
50
|
+
return 4
|
|
51
|
+
}
|
|
52
|
+
})(),
|
|
53
|
+
wasi: __wasi,
|
|
54
|
+
onCreateWorker() {
|
|
55
|
+
return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
|
|
56
|
+
env: process.env,
|
|
57
|
+
execArgv: ['--experimental-wasi-unstable-preview1'],
|
|
58
|
+
})
|
|
59
|
+
},
|
|
60
|
+
overwriteImports(importObject) {
|
|
61
|
+
importObject.env = {
|
|
62
|
+
...importObject.env,
|
|
63
|
+
...importObject.napi,
|
|
64
|
+
...importObject.emnapi,
|
|
65
|
+
memory: __sharedMemory,
|
|
66
|
+
}
|
|
67
|
+
return importObject
|
|
68
|
+
},
|
|
69
|
+
beforeInit({ instance }) {
|
|
70
|
+
__napi_rs_initialize_modules(instance)
|
|
71
|
+
}
|
|
72
|
+
})
|
|
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
|
+
}
|
|
106
|
+
module.exports.Transformer = __napiModule.exports.Transformer
|
|
107
|
+
module.exports.ChromaSubsampling = __napiModule.exports.ChromaSubsampling
|
|
108
|
+
module.exports.CompressionType = __napiModule.exports.CompressionType
|
|
109
|
+
module.exports.compressJpeg = __napiModule.exports.compressJpeg
|
|
110
|
+
module.exports.compressJpegSync = __napiModule.exports.compressJpegSync
|
|
111
|
+
module.exports.FastResizeFilter = __napiModule.exports.FastResizeFilter
|
|
112
|
+
module.exports.FilterType = __napiModule.exports.FilterType
|
|
113
|
+
module.exports.JsColorType = __napiModule.exports.JsColorType
|
|
114
|
+
module.exports.losslessCompressPng = __napiModule.exports.losslessCompressPng
|
|
115
|
+
module.exports.losslessCompressPngSync = __napiModule.exports.losslessCompressPngSync
|
|
116
|
+
module.exports.Orientation = __napiModule.exports.Orientation
|
|
117
|
+
module.exports.pngQuantize = __napiModule.exports.pngQuantize
|
|
118
|
+
module.exports.pngQuantizeSync = __napiModule.exports.pngQuantizeSync
|
|
119
|
+
module.exports.PngRowFilter = __napiModule.exports.PngRowFilter
|
|
120
|
+
module.exports.ResizeFilterType = __napiModule.exports.ResizeFilterType
|
|
121
|
+
module.exports.ResizeFit = __napiModule.exports.ResizeFit
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@napi-rs/image-wasm32-wasi",
|
|
3
|
+
"version": "1.8.0",
|
|
4
|
+
"cpu": [
|
|
5
|
+
"wasm32"
|
|
6
|
+
],
|
|
7
|
+
"main": "image.wasi.cjs",
|
|
8
|
+
"files": [
|
|
9
|
+
"image.wasm32-wasi.wasm",
|
|
10
|
+
"image.wasi.cjs",
|
|
11
|
+
"image.wasi-browser.js",
|
|
12
|
+
"wasi-worker.mjs",
|
|
13
|
+
"wasi-worker-browser.mjs"
|
|
14
|
+
],
|
|
15
|
+
"description": "Image processing library",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"image",
|
|
18
|
+
"lossless",
|
|
19
|
+
"compression",
|
|
20
|
+
"jpeg",
|
|
21
|
+
"jpg",
|
|
22
|
+
"png",
|
|
23
|
+
"svg"
|
|
24
|
+
],
|
|
25
|
+
"author": {
|
|
26
|
+
"email": "github@lyn.one",
|
|
27
|
+
"name": "LongYinan",
|
|
28
|
+
"url": "https://lyn.one"
|
|
29
|
+
},
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=14.0.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"registry": "https://registry.npmjs.org/",
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"repository": "git@github.com:Brooooooklyn/Image.git",
|
|
39
|
+
"browser": "image.wasi-browser.js",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@napi-rs/wasm-runtime": "^0.1.1"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
|
|
10
|
+
const handler = new MessageHandler({
|
|
11
|
+
onLoad({ wasmModule, wasmMemory }) {
|
|
12
|
+
const wasi = new WASI({
|
|
13
|
+
fs,
|
|
14
|
+
print: function () {
|
|
15
|
+
// eslint-disable-next-line no-console
|
|
16
|
+
console.log.apply(console, arguments)
|
|
17
|
+
},
|
|
18
|
+
printErr: function() {
|
|
19
|
+
// eslint-disable-next-line no-console
|
|
20
|
+
console.error.apply(console, arguments)
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
return instantiateNapiModuleSync(wasmModule, {
|
|
24
|
+
childThread: true,
|
|
25
|
+
wasi,
|
|
26
|
+
overwriteImports(importObject) {
|
|
27
|
+
importObject.env = {
|
|
28
|
+
...importObject.env,
|
|
29
|
+
...importObject.napi,
|
|
30
|
+
...importObject.emnapi,
|
|
31
|
+
memory: wasmMemory,
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
globalThis.onmessage = function (e) {
|
|
39
|
+
handler.handle(e)
|
|
40
|
+
}
|
package/wasi-worker.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { parentPort, Worker } from "node:worker_threads";
|
|
4
|
+
|
|
5
|
+
import { instantiateNapiModuleSync, MessageHandler, WASI } from "@napi-rs/wasm-runtime";
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
if (parentPort) {
|
|
10
|
+
parentPort.on("message", (data) => {
|
|
11
|
+
globalThis.onmessage({ data });
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Object.assign(globalThis, {
|
|
16
|
+
self: globalThis,
|
|
17
|
+
require,
|
|
18
|
+
Worker,
|
|
19
|
+
importScripts: function (f) {
|
|
20
|
+
;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
|
|
21
|
+
},
|
|
22
|
+
postMessage: function (msg) {
|
|
23
|
+
if (parentPort) {
|
|
24
|
+
parentPort.postMessage(msg);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const handler = new MessageHandler({
|
|
30
|
+
onLoad({ wasmModule, wasmMemory }) {
|
|
31
|
+
const wasi = new WASI({ fs });
|
|
32
|
+
|
|
33
|
+
return instantiateNapiModuleSync(wasmModule, {
|
|
34
|
+
childThread: true,
|
|
35
|
+
wasi,
|
|
36
|
+
overwriteImports(importObject) {
|
|
37
|
+
importObject.env = {
|
|
38
|
+
...importObject.env,
|
|
39
|
+
...importObject.napi,
|
|
40
|
+
...importObject.emnapi,
|
|
41
|
+
memory: wasmMemory
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
globalThis.onmessage = function (e) {
|
|
49
|
+
handler.handle(e);
|
|
50
|
+
};
|