@build-qube/takeoff-calculator-wasm32-wasi 2.0.4 → 2.3.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/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createOnMessage as __wasmCreateOnMessageForFsProxy,
|
|
3
2
|
getDefaultContext as __emnapiGetDefaultContext,
|
|
4
3
|
instantiateNapiModule as __emnapiInstantiateNapiModule,
|
|
5
4
|
WASI as __WASI,
|
|
6
|
-
} from
|
|
5
|
+
} from '@napi-rs/wasm-runtime';
|
|
7
6
|
|
|
8
7
|
const __wasi = new __WASI({
|
|
9
|
-
version:
|
|
8
|
+
version: 'preview1',
|
|
10
9
|
});
|
|
11
10
|
|
|
12
11
|
const __wasmUrl = new URL(
|
|
13
|
-
|
|
12
|
+
'./takeoff-calculator.wasm32-wasi.wasm',
|
|
14
13
|
import.meta.url,
|
|
15
14
|
).href;
|
|
16
15
|
const __emnapiContext = __emnapiGetDefaultContext();
|
|
@@ -33,9 +32,9 @@ const {
|
|
|
33
32
|
wasi: __wasi,
|
|
34
33
|
onCreateWorker() {
|
|
35
34
|
const worker = new Worker(
|
|
36
|
-
new URL(
|
|
35
|
+
new URL('@build-qube/takeoff-calculator-wasm32-wasi/wasi-worker-browser.mjs', import.meta.url),
|
|
37
36
|
{
|
|
38
|
-
type:
|
|
37
|
+
type: 'module',
|
|
39
38
|
},
|
|
40
39
|
);
|
|
41
40
|
|
|
@@ -52,19 +51,27 @@ const {
|
|
|
52
51
|
},
|
|
53
52
|
beforeInit({ instance }) {
|
|
54
53
|
for (const name of Object.keys(instance.exports)) {
|
|
55
|
-
if (name.startsWith(
|
|
54
|
+
if (name.startsWith('__napi_register__')) {
|
|
56
55
|
instance.exports[name]();
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
},
|
|
60
59
|
});
|
|
61
60
|
export default __napiModule.exports;
|
|
61
|
+
export const ContourWrapper = __napiModule.exports.ContourWrapper;
|
|
62
62
|
export const GroupWrapper = __napiModule.exports.GroupWrapper;
|
|
63
63
|
export const MeasurementWrapper = __napiModule.exports.MeasurementWrapper;
|
|
64
64
|
export const TakeoffStateHandler = __napiModule.exports.TakeoffStateHandler;
|
|
65
|
+
export const VolumetricUnitResult = __napiModule.exports.VolumetricUnitResult;
|
|
65
66
|
export const plus100 = __napiModule.exports.plus100;
|
|
67
|
+
export const plus200 = __napiModule.exports.plus200;
|
|
66
68
|
export const UnitValue = __napiModule.exports.UnitValue;
|
|
69
|
+
export const distance = __napiModule.exports.distance;
|
|
70
|
+
export const generateRandomId = __napiModule.exports.generateRandomId;
|
|
71
|
+
export const getCentroid = __napiModule.exports.getCentroid;
|
|
67
72
|
export const MeasurementType = __napiModule.exports.MeasurementType;
|
|
73
|
+
export const repositionMeasurementToCentroid =
|
|
74
|
+
__napiModule.exports.repositionMeasurementToCentroid;
|
|
68
75
|
export const simplifyPolyline = __napiModule.exports.simplifyPolyline;
|
|
69
76
|
export const Unit = __napiModule.exports.Unit;
|
|
70
77
|
export const UnitValueItemType = __napiModule.exports.UnitValueItemType;
|
|
@@ -3,57 +3,74 @@
|
|
|
3
3
|
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
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')
|
|
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
10
|
|
|
11
11
|
const {
|
|
12
12
|
createOnMessage: __wasmCreateOnMessageForFsProxy,
|
|
13
13
|
getDefaultContext: __emnapiGetDefaultContext,
|
|
14
14
|
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
|
|
15
|
-
} = require('@napi-rs/wasm-runtime')
|
|
15
|
+
} = require('@napi-rs/wasm-runtime');
|
|
16
16
|
|
|
17
|
-
const __rootDir = __nodePath.parse(process.cwd()).root
|
|
17
|
+
const __rootDir = __nodePath.parse(process.cwd()).root;
|
|
18
18
|
|
|
19
19
|
const __wasi = new __nodeWASI({
|
|
20
20
|
version: 'preview1',
|
|
21
21
|
env: process.env,
|
|
22
22
|
preopens: {
|
|
23
23
|
[__rootDir]: __rootDir,
|
|
24
|
-
}
|
|
25
|
-
})
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
26
|
|
|
27
|
-
const __emnapiContext = __emnapiGetDefaultContext()
|
|
27
|
+
const __emnapiContext = __emnapiGetDefaultContext();
|
|
28
28
|
|
|
29
29
|
const __sharedMemory = new WebAssembly.Memory({
|
|
30
30
|
initial: 4000,
|
|
31
31
|
maximum: 65536,
|
|
32
32
|
shared: true,
|
|
33
|
-
})
|
|
33
|
+
});
|
|
34
34
|
|
|
35
|
-
let __wasmFilePath = __nodePath.join(
|
|
36
|
-
|
|
35
|
+
let __wasmFilePath = __nodePath.join(
|
|
36
|
+
__dirname,
|
|
37
|
+
'takeoff-calculator.wasm32-wasi.wasm',
|
|
38
|
+
);
|
|
39
|
+
const __wasmDebugFilePath = __nodePath.join(
|
|
40
|
+
__dirname,
|
|
41
|
+
'takeoff-calculator.wasm32-wasi.debug.wasm',
|
|
42
|
+
);
|
|
37
43
|
|
|
38
44
|
if (__nodeFs.existsSync(__wasmDebugFilePath)) {
|
|
39
|
-
__wasmFilePath = __wasmDebugFilePath
|
|
45
|
+
__wasmFilePath = __wasmDebugFilePath;
|
|
40
46
|
} else if (!__nodeFs.existsSync(__wasmFilePath)) {
|
|
41
47
|
try {
|
|
42
|
-
__wasmFilePath = require.resolve(
|
|
48
|
+
__wasmFilePath = require.resolve(
|
|
49
|
+
'@build-qube/takeoff-calculator-wasm32-wasi/takeoff-calculator.wasm32-wasi.wasm',
|
|
50
|
+
);
|
|
43
51
|
} catch {
|
|
44
|
-
throw new Error(
|
|
52
|
+
throw new Error(
|
|
53
|
+
'Cannot find takeoff-calculator.wasm32-wasi.wasm file, and @build-qube/takeoff-calculator-wasm32-wasi package is not installed.',
|
|
54
|
+
);
|
|
45
55
|
}
|
|
46
56
|
}
|
|
47
57
|
|
|
48
|
-
const {
|
|
58
|
+
const {
|
|
59
|
+
instance: __napiInstance,
|
|
60
|
+
module: __wasiModule,
|
|
61
|
+
napiModule: __napiModule,
|
|
62
|
+
} = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
|
|
49
63
|
context: __emnapiContext,
|
|
50
|
-
asyncWorkPoolSize: (
|
|
51
|
-
const threadsSizeFromEnv = Number(
|
|
64
|
+
asyncWorkPoolSize: (() => {
|
|
65
|
+
const threadsSizeFromEnv = Number(
|
|
66
|
+
process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ??
|
|
67
|
+
process.env.UV_THREADPOOL_SIZE,
|
|
68
|
+
);
|
|
52
69
|
// NaN > 0 is false
|
|
53
70
|
if (threadsSizeFromEnv > 0) {
|
|
54
|
-
return threadsSizeFromEnv
|
|
71
|
+
return threadsSizeFromEnv;
|
|
55
72
|
} else {
|
|
56
|
-
return 4
|
|
73
|
+
return 4;
|
|
57
74
|
}
|
|
58
75
|
})(),
|
|
59
76
|
reuseWorker: true,
|
|
@@ -61,10 +78,10 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
|
|
|
61
78
|
onCreateWorker() {
|
|
62
79
|
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
|
|
63
80
|
env: process.env,
|
|
64
|
-
})
|
|
81
|
+
});
|
|
65
82
|
worker.onmessage = ({ data }) => {
|
|
66
|
-
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
|
|
67
|
-
}
|
|
83
|
+
__wasmCreateOnMessageForFsProxy(__nodeFs)(data);
|
|
84
|
+
};
|
|
68
85
|
|
|
69
86
|
// The main thread of Node.js waits for all the active handles before exiting.
|
|
70
87
|
// But Rust threads are never waited without `thread::join`.
|
|
@@ -72,15 +89,15 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
|
|
|
72
89
|
// According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
|
|
73
90
|
// a worker is consist of two handles: kPublicPort and kHandle.
|
|
74
91
|
{
|
|
75
|
-
const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
|
|
76
|
-
s.toString().includes(
|
|
92
|
+
const kPublicPort = Object.getOwnPropertySymbols(worker).find((s) =>
|
|
93
|
+
s.toString().includes('kPublicPort'),
|
|
77
94
|
);
|
|
78
95
|
if (kPublicPort) {
|
|
79
96
|
worker[kPublicPort].ref = () => {};
|
|
80
97
|
}
|
|
81
98
|
|
|
82
|
-
const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
|
|
83
|
-
s.toString().includes(
|
|
99
|
+
const kHandle = Object.getOwnPropertySymbols(worker).find((s) =>
|
|
100
|
+
s.toString().includes('kHandle'),
|
|
84
101
|
);
|
|
85
102
|
if (kHandle) {
|
|
86
103
|
worker[kHandle].ref = () => {};
|
|
@@ -88,7 +105,7 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
|
|
|
88
105
|
|
|
89
106
|
worker.unref();
|
|
90
107
|
}
|
|
91
|
-
return worker
|
|
108
|
+
return worker;
|
|
92
109
|
},
|
|
93
110
|
overwriteImports(importObject) {
|
|
94
111
|
importObject.env = {
|
|
@@ -96,24 +113,32 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
|
|
|
96
113
|
...importObject.napi,
|
|
97
114
|
...importObject.emnapi,
|
|
98
115
|
memory: __sharedMemory,
|
|
99
|
-
}
|
|
100
|
-
return importObject
|
|
116
|
+
};
|
|
117
|
+
return importObject;
|
|
101
118
|
},
|
|
102
119
|
beforeInit({ instance }) {
|
|
103
120
|
for (const name of Object.keys(instance.exports)) {
|
|
104
121
|
if (name.startsWith('__napi_register__')) {
|
|
105
|
-
instance.exports[name]()
|
|
122
|
+
instance.exports[name]();
|
|
106
123
|
}
|
|
107
124
|
}
|
|
108
125
|
},
|
|
109
|
-
})
|
|
110
|
-
module.exports = __napiModule.exports
|
|
111
|
-
module.exports.
|
|
112
|
-
module.exports.
|
|
113
|
-
module.exports.
|
|
114
|
-
module.exports.
|
|
115
|
-
module.exports.
|
|
116
|
-
module.exports.
|
|
117
|
-
module.exports.
|
|
118
|
-
module.exports.
|
|
119
|
-
module.exports.
|
|
126
|
+
});
|
|
127
|
+
module.exports = __napiModule.exports;
|
|
128
|
+
module.exports.ContourWrapper = __napiModule.exports.ContourWrapper;
|
|
129
|
+
module.exports.GroupWrapper = __napiModule.exports.GroupWrapper;
|
|
130
|
+
module.exports.MeasurementWrapper = __napiModule.exports.MeasurementWrapper;
|
|
131
|
+
module.exports.TakeoffStateHandler = __napiModule.exports.TakeoffStateHandler;
|
|
132
|
+
module.exports.VolumetricUnitResult = __napiModule.exports.VolumetricUnitResult;
|
|
133
|
+
module.exports.plus100 = __napiModule.exports.plus100;
|
|
134
|
+
module.exports.plus200 = __napiModule.exports.plus200;
|
|
135
|
+
module.exports.UnitValue = __napiModule.exports.UnitValue;
|
|
136
|
+
module.exports.distance = __napiModule.exports.distance;
|
|
137
|
+
module.exports.generateRandomId = __napiModule.exports.generateRandomId;
|
|
138
|
+
module.exports.getCentroid = __napiModule.exports.getCentroid;
|
|
139
|
+
module.exports.MeasurementType = __napiModule.exports.MeasurementType;
|
|
140
|
+
module.exports.repositionMeasurementToCentroid =
|
|
141
|
+
__napiModule.exports.repositionMeasurementToCentroid;
|
|
142
|
+
module.exports.simplifyPolyline = __napiModule.exports.simplifyPolyline;
|
|
143
|
+
module.exports.Unit = __napiModule.exports.Unit;
|
|
144
|
+
module.exports.UnitValueItemType = __napiModule.exports.UnitValueItemType;
|
|
Binary file
|
package/wasi-worker-browser.mjs
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
instantiateNapiModuleSync,
|
|
3
|
+
MessageHandler,
|
|
4
|
+
WASI,
|
|
5
|
+
} from '@napi-rs/wasm-runtime';
|
|
2
6
|
|
|
3
7
|
const handler = new MessageHandler({
|
|
4
8
|
onLoad({ wasmModule, wasmMemory }) {
|
|
5
9
|
const wasi = new WASI({
|
|
6
10
|
print: function () {
|
|
7
11
|
// eslint-disable-next-line no-console
|
|
8
|
-
console.log.apply(console, arguments)
|
|
12
|
+
console.log.apply(console, arguments);
|
|
9
13
|
},
|
|
10
|
-
printErr: function() {
|
|
14
|
+
printErr: function () {
|
|
11
15
|
// eslint-disable-next-line no-console
|
|
12
|
-
console.error.apply(console, arguments)
|
|
16
|
+
console.error.apply(console, arguments);
|
|
13
17
|
},
|
|
14
|
-
})
|
|
18
|
+
});
|
|
15
19
|
return instantiateNapiModuleSync(wasmModule, {
|
|
16
20
|
childThread: true,
|
|
17
21
|
wasi,
|
|
@@ -21,12 +25,12 @@ const handler = new MessageHandler({
|
|
|
21
25
|
...importObject.napi,
|
|
22
26
|
...importObject.emnapi,
|
|
23
27
|
memory: wasmMemory,
|
|
24
|
-
}
|
|
28
|
+
};
|
|
25
29
|
},
|
|
26
|
-
})
|
|
30
|
+
});
|
|
27
31
|
},
|
|
28
|
-
})
|
|
32
|
+
});
|
|
29
33
|
|
|
30
|
-
globalThis.onmessage =
|
|
31
|
-
handler.handle(e)
|
|
32
|
-
}
|
|
34
|
+
globalThis.onmessage = (e) => {
|
|
35
|
+
handler.handle(e);
|
|
36
|
+
};
|
package/wasi-worker.mjs
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import { createRequire } from
|
|
3
|
-
import { parse } from
|
|
4
|
-
import { WASI } from
|
|
5
|
-
import { parentPort, Worker } from
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { parse } from 'node:path';
|
|
4
|
+
import { WASI } from 'node:wasi';
|
|
5
|
+
import { parentPort, Worker } from 'node:worker_threads';
|
|
6
6
|
|
|
7
7
|
const require = createRequire(import.meta.url);
|
|
8
8
|
|
|
9
|
-
const {
|
|
9
|
+
const {
|
|
10
|
+
instantiateNapiModuleSync,
|
|
11
|
+
MessageHandler,
|
|
12
|
+
getDefaultContext,
|
|
13
|
+
} = require('@napi-rs/wasm-runtime');
|
|
10
14
|
|
|
11
15
|
if (parentPort) {
|
|
12
|
-
parentPort.on(
|
|
16
|
+
parentPort.on('message', (data) => {
|
|
13
17
|
globalThis.onmessage({ data });
|
|
14
18
|
});
|
|
15
19
|
}
|
|
@@ -18,10 +22,10 @@ Object.assign(globalThis, {
|
|
|
18
22
|
self: globalThis,
|
|
19
23
|
require,
|
|
20
24
|
Worker,
|
|
21
|
-
importScripts:
|
|
22
|
-
|
|
25
|
+
importScripts: (f) => {
|
|
26
|
+
(0, eval)(fs.readFileSync(f, 'utf8') + '//# sourceURL=' + f);
|
|
23
27
|
},
|
|
24
|
-
postMessage:
|
|
28
|
+
postMessage: (msg) => {
|
|
25
29
|
if (parentPort) {
|
|
26
30
|
parentPort.postMessage(msg);
|
|
27
31
|
}
|
|
@@ -51,13 +55,13 @@ const handler = new MessageHandler({
|
|
|
51
55
|
...importObject.env,
|
|
52
56
|
...importObject.napi,
|
|
53
57
|
...importObject.emnapi,
|
|
54
|
-
memory: wasmMemory
|
|
58
|
+
memory: wasmMemory,
|
|
55
59
|
};
|
|
56
60
|
},
|
|
57
61
|
});
|
|
58
62
|
},
|
|
59
63
|
});
|
|
60
64
|
|
|
61
|
-
globalThis.onmessage =
|
|
65
|
+
globalThis.onmessage = (e) => {
|
|
62
66
|
handler.handle(e);
|
|
63
67
|
};
|