@build-qube/takeoff-calculator-wasm32-wasi 2.1.0 → 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,6 +1,6 @@
1
1
  {
2
2
  "name": "@build-qube/takeoff-calculator-wasm32-wasi",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "cpu": [
5
5
  "wasm32"
6
6
  ],
@@ -1,73 +1,77 @@
1
1
  import {
2
- getDefaultContext as __emnapiGetDefaultContext,
3
- instantiateNapiModule as __emnapiInstantiateNapiModule,
4
- WASI as __WASI,
5
- } from "@napi-rs/wasm-runtime";
2
+ getDefaultContext as __emnapiGetDefaultContext,
3
+ instantiateNapiModule as __emnapiInstantiateNapiModule,
4
+ WASI as __WASI,
5
+ } from '@napi-rs/wasm-runtime';
6
6
 
7
7
  const __wasi = new __WASI({
8
- version: "preview1",
8
+ version: 'preview1',
9
9
  });
10
10
 
11
11
  const __wasmUrl = new URL(
12
- "./takeoff-calculator.wasm32-wasi.wasm",
13
- import.meta.url,
12
+ './takeoff-calculator.wasm32-wasi.wasm',
13
+ import.meta.url,
14
14
  ).href;
15
15
  const __emnapiContext = __emnapiGetDefaultContext();
16
16
 
17
17
  const __sharedMemory = new WebAssembly.Memory({
18
- initial: 4000,
19
- maximum: 65536,
20
- shared: true,
18
+ initial: 4000,
19
+ maximum: 65536,
20
+ shared: true,
21
21
  });
22
22
 
23
23
  const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer());
24
24
 
25
25
  const {
26
- instance: __napiInstance,
27
- module: __wasiModule,
28
- napiModule: __napiModule,
26
+ instance: __napiInstance,
27
+ module: __wasiModule,
28
+ napiModule: __napiModule,
29
29
  } = await __emnapiInstantiateNapiModule(__wasmFile, {
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
- );
30
+ context: __emnapiContext,
31
+ asyncWorkPoolSize: 4,
32
+ wasi: __wasi,
33
+ onCreateWorker() {
34
+ const worker = new Worker(
35
+ new URL('@build-qube/takeoff-calculator-wasm32-wasi/wasi-worker-browser.mjs', import.meta.url),
36
+ {
37
+ type: 'module',
38
+ },
39
+ );
40
40
 
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
- },
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
+ },
59
59
  });
60
60
  export default __napiModule.exports;
61
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;
66
67
  export const plus200 = __napiModule.exports.plus200;
67
68
  export const UnitValue = __napiModule.exports.UnitValue;
68
69
  export const distance = __napiModule.exports.distance;
70
+ export const generateRandomId = __napiModule.exports.generateRandomId;
69
71
  export const getCentroid = __napiModule.exports.getCentroid;
70
72
  export const MeasurementType = __napiModule.exports.MeasurementType;
73
+ export const repositionMeasurementToCentroid =
74
+ __napiModule.exports.repositionMeasurementToCentroid;
71
75
  export const simplifyPolyline = __napiModule.exports.simplifyPolyline;
72
76
  export const Unit = __napiModule.exports.Unit;
73
77
  export const UnitValueItemType = __napiModule.exports.UnitValueItemType;
@@ -3,138 +3,142 @@
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
- createOnMessage: __wasmCreateOnMessageForFsProxy,
13
- getDefaultContext: __emnapiGetDefaultContext,
14
- instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
15
- } = require("@napi-rs/wasm-runtime");
12
+ createOnMessage: __wasmCreateOnMessageForFsProxy,
13
+ getDefaultContext: __emnapiGetDefaultContext,
14
+ instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
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: (() => {
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
128
  module.exports.ContourWrapper = __napiModule.exports.ContourWrapper;
129
129
  module.exports.GroupWrapper = __napiModule.exports.GroupWrapper;
130
130
  module.exports.MeasurementWrapper = __napiModule.exports.MeasurementWrapper;
131
131
  module.exports.TakeoffStateHandler = __napiModule.exports.TakeoffStateHandler;
132
+ module.exports.VolumetricUnitResult = __napiModule.exports.VolumetricUnitResult;
132
133
  module.exports.plus100 = __napiModule.exports.plus100;
133
134
  module.exports.plus200 = __napiModule.exports.plus200;
134
135
  module.exports.UnitValue = __napiModule.exports.UnitValue;
135
136
  module.exports.distance = __napiModule.exports.distance;
137
+ module.exports.generateRandomId = __napiModule.exports.generateRandomId;
136
138
  module.exports.getCentroid = __napiModule.exports.getCentroid;
137
139
  module.exports.MeasurementType = __napiModule.exports.MeasurementType;
140
+ module.exports.repositionMeasurementToCentroid =
141
+ __napiModule.exports.repositionMeasurementToCentroid;
138
142
  module.exports.simplifyPolyline = __napiModule.exports.simplifyPolyline;
139
143
  module.exports.Unit = __napiModule.exports.Unit;
140
144
  module.exports.UnitValueItemType = __napiModule.exports.UnitValueItemType;
Binary file
@@ -1,36 +1,36 @@
1
1
  import {
2
- instantiateNapiModuleSync,
3
- MessageHandler,
4
- WASI,
5
- } from "@napi-rs/wasm-runtime";
2
+ instantiateNapiModuleSync,
3
+ MessageHandler,
4
+ WASI,
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
34
  globalThis.onmessage = (e) => {
35
- handler.handle(e);
35
+ handler.handle(e);
36
36
  };
package/wasi-worker.mjs CHANGED
@@ -1,35 +1,35 @@
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";
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
9
  const {
10
- instantiateNapiModuleSync,
11
- MessageHandler,
12
- getDefaultContext,
13
- } = require("@napi-rs/wasm-runtime");
10
+ instantiateNapiModuleSync,
11
+ MessageHandler,
12
+ getDefaultContext,
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: (f) => {
26
- (0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
27
- },
28
- postMessage: (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
65
  globalThis.onmessage = (e) => {
66
- handler.handle(e);
66
+ handler.handle(e);
67
67
  };