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