@mlightcad/libredwg-web 0.6.10 → 0.7.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/lib/libredwg.d.ts CHANGED
@@ -19,6 +19,12 @@ export declare class LibreDwg {
19
19
  private decoder?;
20
20
  private constructor();
21
21
  dwg_read_data(fileContent: string | ArrayBuffer, fileType: number): number | undefined;
22
+ /**
23
+ * Converts DWG file content to DXF file content.
24
+ * @param fileContent DWG file content.
25
+ * @returns Returns DXF file content if conversion succeeds. Otherwise returns null.
26
+ */
27
+ dwg_write_dxf(fileContent: string | ArrayBuffer): Uint8Array | null;
22
28
  /**
23
29
  * Gets the version of the dwg.
24
30
  * @param data Pointer to Dwg_Data instance.
package/lib/libredwg.js CHANGED
@@ -29,13 +29,19 @@ export class LibreDwg {
29
29
  dwg_read_data(fileContent, fileType) {
30
30
  if (fileType == Dwg_File_Type.DWG) {
31
31
  const fileName = 'tmp.dwg';
32
- this.wasmInstance.FS.writeFile(fileName, new Uint8Array(fileContent));
33
- const result = this.wasmInstance.dwg_read_file(fileName);
34
- if (result.error != 0) {
35
- console.log('Open dwg file with error code: ', result.error);
32
+ try {
33
+ this.wasmInstance.FS.writeFile(fileName, new Uint8Array(fileContent));
34
+ const result = this.wasmInstance.dwg_read_file(fileName);
35
+ if (result.error != 0) {
36
+ console.log('Open dwg file with error code: ', result.error);
37
+ }
38
+ return result.data;
39
+ }
40
+ finally {
41
+ if (this.wasmInstance.FS.analyzePath(fileName, false).exists) {
42
+ this.wasmInstance.FS.unlink(fileName);
43
+ }
36
44
  }
37
- this.wasmInstance.FS.unlink(fileName);
38
- return result.data;
39
45
  }
40
46
  // else if (fileType == Dwg_File_Type.DXF) {
41
47
  // const fileName = "tmp.dxf";
@@ -48,6 +54,32 @@ export class LibreDwg {
48
54
  // return result.data as Dwg_Data_Ptr;
49
55
  // }
50
56
  }
57
+ /**
58
+ * Converts DWG file content to DXF file content.
59
+ * @param fileContent DWG file content.
60
+ * @returns Returns DXF file content if conversion succeeds. Otherwise returns null.
61
+ */
62
+ dwg_write_dxf(fileContent) {
63
+ const inputFileName = 'tmp.dwg';
64
+ const outputFileName = 'tmp.dxf';
65
+ try {
66
+ this.wasmInstance.FS.writeFile(inputFileName, new Uint8Array(fileContent));
67
+ const error = this.wasmInstance.dwg_write_dxf(inputFileName, outputFileName);
68
+ if (error != 0) {
69
+ console.log('Convert dwg to dxf with error code: ', error);
70
+ return null;
71
+ }
72
+ return this.wasmInstance.FS.readFile(outputFileName);
73
+ }
74
+ finally {
75
+ if (this.wasmInstance.FS.analyzePath(inputFileName, false).exists) {
76
+ this.wasmInstance.FS.unlink(inputFileName);
77
+ }
78
+ if (this.wasmInstance.FS.analyzePath(outputFileName, false).exists) {
79
+ this.wasmInstance.FS.unlink(outputFileName);
80
+ }
81
+ }
82
+ }
51
83
  /**
52
84
  * Gets the version of the dwg.
53
85
  * @param data Pointer to Dwg_Data instance.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A DWG/DXF JavaScript parser based on libredwg",
4
4
  "license": "GPL-3.0",
5
5
  "private": false,
6
- "version": "0.6.10",
6
+ "version": "0.7.0",
7
7
  "author": "MLight Lee <mlight.lee@outlook.com>",
8
8
  "type": "module",
9
9
  "repository": {
@@ -70,7 +70,7 @@
70
70
  "demo": "live-server examples --entry-file=index.html",
71
71
  "doc": "typedoc",
72
72
  "build": "tsc && vite build && cp -rf wasm examples/ && cp -rf dist examples/",
73
- "build:prepare": "mkdir -p ../../build-wasm && cd ../../build-wasm && emconfigure ../configure CFLAGS=\"-O2 -sUSE_ZLIB=1\" CC=emcc --enable-release --disable-docs --disable-write --disable-python --disable-bindings --disable-shared --disable-json --disable-dxf --enable-partial --enable-experimental",
73
+ "build:prepare": "mkdir -p ../../build-wasm && cd ../../build-wasm && emconfigure ../configure CFLAGS=\"-O2 -sUSE_ZLIB=1\" CC=emcc --enable-release --disable-docs --disable-write --disable-python --disable-bindings --disable-shared --disable-json --enable-partial --enable-experimental",
74
74
  "build:obj": "cd ../../build-wasm && emmake make",
75
75
  "build:wasm": "cd ../../build-wasm && emcc ../bindings/javascript/embind/*.cpp src/*.o -O2 -lembind -std=c++17 -Isrc -I../src -I../include -o libredwg-web.js -s ALLOW_MEMORY_GROWTH=1 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME=\"createModule\" -sEXPORTED_RUNTIME_METHODS=FS,ENV,ccall,cwrap,UTF8ToString,stringToNewUTF8,setValue --emit-tsd libredwg-web.d.ts",
76
76
  "clean": "rm -rf ../../build-wasm ./docs ./dist ./lib",
@@ -10,9 +10,10 @@ declare namespace RuntimeExports {
10
10
  export let currentPath: string;
11
11
  export let initialized: boolean;
12
12
  export let ignorePermissions: boolean;
13
+ export { ErrnoError };
13
14
  export let filesystems: any;
14
15
  export let syncFSRequests: number;
15
- export { ErrnoError };
16
+ export let readFiles: {};
16
17
  export { FSStream };
17
18
  export { FSNode };
18
19
  export function lookupPath(path: any, opts?: {}): {
@@ -113,10 +114,11 @@ declare namespace RuntimeExports {
113
114
  export function llseek(stream: any, offset: any, whence: any): any;
114
115
  export function read(stream: any, buffer: any, offset: any, length: any, position: any): any;
115
116
  export function write(stream: any, buffer: any, offset: any, length: any, position: any, canOwn: any): any;
117
+ export function allocate(stream: any, offset: any, length: any): void;
116
118
  export function mmap(stream: any, length: any, position: any, prot: any, flags: any): any;
117
119
  export function msync(stream: any, buffer: any, offset: any, length: any, mmapFlags: any): any;
118
120
  export function ioctl(stream: any, cmd: any, arg: any): any;
119
- export function readFile(path: any, opts?: {}): Uint8Array<any>;
121
+ export function readFile(path: any, opts?: {}): any;
120
122
  export function writeFile(path: any, data: any, opts?: {}): void;
121
123
  export function cwd(): any;
122
124
  export function chdir(path: any): void;
@@ -150,10 +152,10 @@ declare namespace RuntimeExports {
150
152
  /**
151
153
  * @param {string|null=} returnType
152
154
  * @param {Array=} argTypes
153
- * @param {Array=} args
155
+ * @param {Arguments|Array=} args
154
156
  * @param {Object=} opts
155
157
  */
156
- function ccall(ident: any, returnType?: (string | null) | undefined, argTypes?: any[] | undefined, args?: any[] | undefined, opts?: any | undefined): any;
158
+ function ccall(ident: any, returnType?: (string | null) | undefined, argTypes?: any[] | undefined, args?: (Arguments | any[]) | undefined, opts?: any | undefined): any;
157
159
  /**
158
160
  * @param {string=} returnType
159
161
  * @param {Array=} argTypes
@@ -169,11 +171,13 @@ declare namespace RuntimeExports {
169
171
  * maximum number of bytes to read. You can omit this parameter to scan the
170
172
  * string until the first 0 byte. If maxBytesToRead is passed, and the string
171
173
  * at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the
172
- * string will cut short at that byte index.
173
- * @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character.
174
+ * string will cut short at that byte index (i.e. maxBytesToRead will not
175
+ * produce a string of exact length [ptr, ptr+maxBytesToRead[) N.B. mixing
176
+ * frequent uses of UTF8ToString() with and without maxBytesToRead may throw
177
+ * JS JIT optimizations off, so it is worth to consider consistently using one
174
178
  * @return {string}
175
179
  */
176
- function UTF8ToString(ptr: number, maxBytesToRead?: number | undefined, ignoreNul?: boolean | undefined): string;
180
+ function UTF8ToString(ptr: number, maxBytesToRead?: number | undefined): string;
177
181
  function stringToNewUTF8(str: any): any;
178
182
  /**
179
183
  * @param {number} ptr
@@ -181,6 +185,17 @@ declare namespace RuntimeExports {
181
185
  * @param {string} type
182
186
  */
183
187
  function setValue(ptr: number, value: number, type?: string): void;
188
+ let HEAPF32: any;
189
+ let HEAPF64: any;
190
+ let HEAP_DATA_VIEW: any;
191
+ let HEAP8: any;
192
+ let HEAPU8: any;
193
+ let HEAP16: any;
194
+ let HEAPU16: any;
195
+ let HEAP32: any;
196
+ let HEAPU32: any;
197
+ let HEAP64: any;
198
+ let HEAPU64: any;
184
199
  }
185
200
  declare class ErrnoError {
186
201
  constructor(errno: any);
@@ -232,8 +247,6 @@ export interface ClassHandle {
232
247
  delete(): void;
233
248
  deleteLater(): this;
234
249
  isDeleted(): boolean;
235
- // @ts-ignore - If targeting lower than ESNext, this symbol might not exist.
236
- [Symbol.dispose](): void;
237
250
  clone(): this;
238
251
  }
239
252
  export interface Dwg_Version_TypeValue<T extends number> {
@@ -426,6 +439,7 @@ interface EmbindModule {
426
439
  dwg_dynapi_entity_set_value(_0: number, _1: EmbindString, _2: EmbindString, _3: number, _4: boolean): boolean;
427
440
  dwg_dynapi_common_set_value(_0: number, _1: EmbindString, _2: number, _3: boolean): boolean;
428
441
  dwg_dynapi_handle_name(_0: number, _1: number, _2: number): string;
442
+ dwg_write_dxf(_0: EmbindString, _1: EmbindString): number;
429
443
  dwg_find_tablehandle(_0: number, _1: EmbindString, _2: EmbindString): number;
430
444
  dwg_find_tablehandle_index(_0: number, _1: number, _2: EmbindString): number;
431
445
  dwg_handle_name(_0: number, _1: EmbindString, _2: number): string;