@mlightcad/libredwg-web 0.0.1
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 +85 -0
- package/dist/libredwg-web.mjs +2969 -0
- package/dist/libredwg-web.umd.js +17 -0
- package/dist/libredwg-web.wasm +0 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/libredwg-web.d.ts +3 -0
- package/lib/libredwg-web.js +2452 -0
- package/lib/libredwg.d.ts +73 -0
- package/lib/libredwg.js +181 -0
- package/lib/utils.d.ts +342 -0
- package/lib/utils.js +352 -0
- package/package.json +69 -0
- package/wasm/libredwg-web.d.ts +2485 -0
- package/wasm/libredwg-web.js +15 -0
- package/wasm/libredwg-web.wasm +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# libredwg-web
|
|
2
|
+
|
|
3
|
+
This is a webassembly version of libredwg. It can be used in browser and Node.js environments.
|
|
4
|
+
|
|
5
|
+
You can play with it through this [live demo](https://mlight-lee.github.io/libredwg-web/).
|
|
6
|
+
|
|
7
|
+
## Build WebAssembly
|
|
8
|
+
|
|
9
|
+
Download and install emscripten according to [this doc](https://emscripten.org/docs/getting_started/downloads.html). Please make sure the following command is executed to activate `PATH` and other environment variables in the current terminal before building web assembly.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Activate PATH and other environment variables for emscripten in the current terminal
|
|
13
|
+
source ./emsdk_env.sh
|
|
14
|
+
|
|
15
|
+
./autogen.sh
|
|
16
|
+
|
|
17
|
+
# Install npm dependencies to build JavaScript bindings for libredwg
|
|
18
|
+
pnpm install
|
|
19
|
+
|
|
20
|
+
# Check for dependencies, available tools, and system configurations and prepare the software package for building libredwg on a specific system
|
|
21
|
+
pnpm build:prepare
|
|
22
|
+
|
|
23
|
+
# Compile and build libredwg
|
|
24
|
+
pnpm build:obj
|
|
25
|
+
|
|
26
|
+
# Use emscripten to build web assembly for libredwg
|
|
27
|
+
pnpm build:wasm
|
|
28
|
+
|
|
29
|
+
# Copy web assembly (wasm file and JavaScript glue code file) from build directory to distribution directory of this package
|
|
30
|
+
nnpm copy
|
|
31
|
+
|
|
32
|
+
# Build web assembly wrapper so that it is easier to use it
|
|
33
|
+
pnpm build
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
In order to reduce the size of wasm file, the following functionalities are not included by default when building web assembly.
|
|
37
|
+
|
|
38
|
+
- write dwg file
|
|
39
|
+
- read/write dxf file
|
|
40
|
+
- import/export json file
|
|
41
|
+
|
|
42
|
+
If you want those functionalities, just modify command `build:prepare` defined in [package.json](./package.json) and remove the following options.
|
|
43
|
+
|
|
44
|
+
- disable-write
|
|
45
|
+
- disable-json
|
|
46
|
+
- disable-dxf
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
There are two approaches to use this package. No matter which approach to use, please do remember copying wasm file (libredwg.wasm) to the same folder as your JavaScript bundle file when deploying your application.
|
|
51
|
+
|
|
52
|
+
### Use Raw Web Assembly
|
|
53
|
+
|
|
54
|
+
The raw web assembly module (wasm file and JavaScript glue code file) is stored in folder [wasm](./wasm/).
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
import createModule from "@mlightcad/libredwg-web/wasm/libredwg-web.js";
|
|
58
|
+
const libredwg = await createModule();
|
|
59
|
+
|
|
60
|
+
// The second paramter represents file types
|
|
61
|
+
// - 0: dwg file
|
|
62
|
+
// - 1: dxf file
|
|
63
|
+
const dwg = libredwg.dwg_read_data(fileContent, 0);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Use Web Assembly Wrapper
|
|
67
|
+
|
|
68
|
+
Web assembly wrapper is stored in folder [dist](./dist/). It provides one class `LibreDwg` to wrap the web assembly. This class provides
|
|
69
|
+
|
|
70
|
+
- More methods that the raw web assembly API doesn't provide.
|
|
71
|
+
- More accurated type definition so that it is easy to understand API.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { Dwg_File_Type, LibreDwg } from '@mlightcad/libredwg-web';
|
|
75
|
+
const libredwg = await LibreDwg.create();
|
|
76
|
+
const dwg = libredwg.dwg_read_data(fileContent, Dwg_File_Type.DWG);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Demo App
|
|
80
|
+
|
|
81
|
+
One demo app is provided in folder [test](./test/). You can run the following command to launch it.
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
pnpm dev
|
|
85
|
+
```
|