@flyfish-dev/cad-viewer 0.6.3 → 0.6.4
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 +15 -6
- package/README.zh-CN.md +15 -6
- package/dist/cad-viewer.es.js +388 -386
- package/dist/cad-viewer.es.js.map +1 -1
- package/dist/cad-viewer.umd.cjs +6 -6
- package/dist/cad-viewer.umd.cjs.map +1 -1
- package/dist/types/loaders/dwg/DwgWorkerClient.d.ts.map +1 -1
- package/dist/wasm/dwg-worker.js +24 -0
- package/dist/wasm/dwg-worker.js.map +1 -0
- package/package.json +7 -4
- package/dist/assets/DwgWorker-CuZJ5EUe.js +0 -349
- package/dist/assets/DwgWorker-CuZJ5EUe.js.map +0 -1
- package/dist/assets/index-C365l3i9.js +0 -4161
- package/dist/assets/index-C365l3i9.js.map +0 -1
package/README.md
CHANGED
|
@@ -12,6 +12,12 @@ The project provides a clean loader architecture for **DWG**, **DXF**, **DWF**,
|
|
|
12
12
|
|
|
13
13
|
> DWG support uses `@mlightcad/libredwg-web` / LibreDWG WebAssembly in a worker. DXF support uses JavaScript parsing plus a built-in fallback parser. DWF, DWFx and XPS support is powered by `dwf-viewer` 0.6.x, including DWF 6+ ZIP containers, WHIP/W2D 2D sheets, W3D/HSF 3D eModel geometry, DWFx/OPC/XPS pages, adaptive CAD line weights and an optional raster WASM fallback.
|
|
14
14
|
|
|
15
|
+
## What changed in 0.6.4
|
|
16
|
+
|
|
17
|
+
- Added a stable package export for `@flyfish-dev/cad-viewer/wasm/dwg-worker.js`.
|
|
18
|
+
- DWG worker loading now defaults to the page-relative runtime asset `wasm/dwg-worker.js`, making npm package assets and static demo deployments use the same worker file.
|
|
19
|
+
- Dev, demo, Cloudflare Pages and npm library builds now build and copy the DWG worker asset explicitly before serving or packaging runtime files.
|
|
20
|
+
|
|
15
21
|
## What changed in 0.6.3
|
|
16
22
|
|
|
17
23
|
- Added `dxfEncoding` for overriding DXF text decoding when legacy files omit or misdeclare `$DWGCODEPAGE`.
|
|
@@ -99,16 +105,18 @@ npm install
|
|
|
99
105
|
npm run dev
|
|
100
106
|
```
|
|
101
107
|
|
|
102
|
-
The DWG and DWF render paths need runtime
|
|
108
|
+
The DWG and DWF render paths need runtime assets in a public directory: `libredwg-web.js`, `libredwg-web.wasm`, `dwg-worker.js` and `dwfv-render.wasm`. This repository copies, builds and validates them for the demo:
|
|
103
109
|
|
|
104
110
|
```bash
|
|
105
111
|
npm run copy:wasm
|
|
112
|
+
npm run build:worker
|
|
113
|
+
npm run copy:worker
|
|
106
114
|
npm run check:wasm
|
|
107
115
|
```
|
|
108
116
|
|
|
109
|
-
The demo resolves `wasmPath` to an absolute URL before sending it to the DWG worker and uses the same directory for `dwfv-render.wasm`. In your own app, prefer
|
|
117
|
+
The demo resolves `wasmPath` to an absolute URL before sending it to the DWG worker and uses the same directory for `dwfv-render.wasm`. The default DWG worker URL is `wasm/dwg-worker.js`, resolved against the page URL. In your own app, prefer absolute paths or URLs, for example `/wasm`, `/wasm/dwg-worker.js` or `new URL('wasm/', document.baseURI).href`. Avoid passing a worker-relative path such as `./wasm` unless it is resolved on the UI thread first.
|
|
110
118
|
|
|
111
|
-
When publishing the npm package, `build:lib` copies these files into `dist/wasm` and exposes them as package subpaths. Applications still need to serve the
|
|
119
|
+
When publishing the npm package, `build:lib` copies these files into `dist/wasm` and exposes them as package subpaths, including `./wasm/dwg-worker.js`. Applications still need to serve the runtime files from a public URL and pass that directory as `wasmPath`, or pass `dwfWasmUrl` / `workerUrl` explicitly.
|
|
112
120
|
|
|
113
121
|
|
|
114
122
|
## Demo startup notes
|
|
@@ -198,7 +206,7 @@ For very large drawings, lower `maxCurveSegments`, increase `spatialIndexCellCou
|
|
|
198
206
|
|
|
199
207
|
## Worker-backed DWG parsing
|
|
200
208
|
|
|
201
|
-
`DwgLoader` uses a module Web Worker by default in browsers. The worker imports `@mlightcad/libredwg-web`, initializes LibreDWG WASM inside the worker thread, caches that WASM instance, decodes DWG bytes, normalizes the result into a structured-clone-safe `CadDocument`, and sends only the normalized scene back to the UI thread. Canvas rendering remains on the main thread.
|
|
209
|
+
`DwgLoader` uses a module Web Worker by default in browsers. The default worker URL is `wasm/dwg-worker.js`, resolved relative to the page. The worker imports `@mlightcad/libredwg-web`, initializes LibreDWG WASM inside the worker thread, caches that WASM instance, decodes DWG bytes, normalizes the result into a structured-clone-safe `CadDocument`, and sends only the normalized scene back to the UI thread. Canvas rendering remains on the main thread.
|
|
202
210
|
|
|
203
211
|
```ts
|
|
204
212
|
const controller = new AbortController();
|
|
@@ -221,7 +229,7 @@ await viewer.loadFile(file, { signal: controller.signal });
|
|
|
221
229
|
controller.abort();
|
|
222
230
|
```
|
|
223
231
|
|
|
224
|
-
Advanced deployments can override the worker constructor when the bundler or CDN has a custom asset layout:
|
|
232
|
+
Advanced deployments can override the worker URL or constructor when the bundler or CDN has a custom asset layout:
|
|
225
233
|
|
|
226
234
|
```ts
|
|
227
235
|
new CadViewer({
|
|
@@ -241,7 +249,7 @@ const viewer = new CadViewer({
|
|
|
241
249
|
container, // HTMLElement; creates a canvas inside
|
|
242
250
|
canvas, // optional existing HTMLCanvasElement
|
|
243
251
|
renderer: 'auto', // 'auto' | 'webgl' | 'canvas2d'
|
|
244
|
-
wasmPath: '/wasm', // directory containing libredwg-web.wasm and dwfv-render.wasm
|
|
252
|
+
wasmPath: '/wasm', // directory containing libredwg-web.js, libredwg-web.wasm and dwfv-render.wasm
|
|
245
253
|
dxfEncoding: 'gb18030', // optional override when legacy DXF codepage metadata is wrong
|
|
246
254
|
dwfWasmUrl: '/wasm/dwfv-render.wasm',
|
|
247
255
|
autoFit: true,
|
|
@@ -261,6 +269,7 @@ const viewer = new CadViewer({
|
|
|
261
269
|
maxVisibleTextLabels: 2400
|
|
262
270
|
},
|
|
263
271
|
useWorker: true, // default for DWG
|
|
272
|
+
workerUrl: '/wasm/dwg-worker.js', // optional override; this is the default path
|
|
264
273
|
workerTimeoutMs: 0, // 0 = disabled
|
|
265
274
|
dwfPreferWebgl: true,
|
|
266
275
|
dwfPreferWasm: true,
|
package/README.zh-CN.md
CHANGED
|
@@ -12,6 +12,12 @@
|
|
|
12
12
|
|
|
13
13
|
> DWG 使用 `@mlightcad/libredwg-web` / LibreDWG WebAssembly,并默认运行在 Worker 中。DXF 使用 JavaScript 解析器并带内置 fallback。DWF、DWFx、XPS 由 `dwf-viewer` 0.6.x 驱动,覆盖 DWF 6+ ZIP 包、WHIP/W2D 2D 图纸、W3D/HSF 3D eModel、DWFx/OPC/XPS 页面、自适应 CAD 线宽和可选 raster WASM fallback。
|
|
14
14
|
|
|
15
|
+
## 0.6.4 变更
|
|
16
|
+
|
|
17
|
+
- 新增稳定的 package subpath:`@flyfish-dev/cad-viewer/wasm/dwg-worker.js`。
|
|
18
|
+
- DWG worker 默认改为页面相对运行时资源 `wasm/dwg-worker.js`,npm 包资源和静态 Demo 部署使用同一份 worker 文件。
|
|
19
|
+
- dev、demo、Cloudflare Pages 和 npm library 构建都会显式构建并复制 DWG worker 运行时资源。
|
|
20
|
+
|
|
15
21
|
## 0.6.3 变更
|
|
16
22
|
|
|
17
23
|
- 新增 `dxfEncoding`,用于旧 DXF 缺少或误写 `$DWGCODEPAGE` 时显式指定文本编码。
|
|
@@ -99,16 +105,18 @@ npm install
|
|
|
99
105
|
npm run dev
|
|
100
106
|
```
|
|
101
107
|
|
|
102
|
-
DWG 和 DWF
|
|
108
|
+
DWG 和 DWF 渲染链路需要把运行时资源放到公开目录:`libredwg-web.js`、`libredwg-web.wasm`、`dwg-worker.js` 和 `dwfv-render.wasm`。Demo 使用以下命令复制、构建并校验到 `public/wasm`:
|
|
103
109
|
|
|
104
110
|
```bash
|
|
105
111
|
npm run copy:wasm
|
|
112
|
+
npm run build:worker
|
|
113
|
+
npm run copy:worker
|
|
106
114
|
npm run check:wasm
|
|
107
115
|
```
|
|
108
116
|
|
|
109
|
-
Demo 会先把 `wasmPath` 解析为绝对 URL,再发送给 DWG worker,并复用同一目录查找 `dwfv-render.wasm
|
|
117
|
+
Demo 会先把 `wasmPath` 解析为绝对 URL,再发送给 DWG worker,并复用同一目录查找 `dwfv-render.wasm`。默认 DWG worker 地址是 `wasm/dwg-worker.js`,相对于页面 URL 解析。你自己的应用也建议使用绝对路径或绝对 URL,例如 `/wasm`、`/wasm/dwg-worker.js` 或 `new URL('wasm/', document.baseURI).href`。不要直接把未解析的 `./wasm` 传入 worker,否则它可能会相对于 worker 请求资源。
|
|
110
118
|
|
|
111
|
-
发布 npm 包时,`build:lib` 会把这些文件复制到 `dist/wasm` 并作为 package subpath
|
|
119
|
+
发布 npm 包时,`build:lib` 会把这些文件复制到 `dist/wasm` 并作为 package subpath 暴露出来,包括 `./wasm/dwg-worker.js`。应用侧仍需要把运行时资源放到可公开访问的 URL,并把该目录传给 `wasmPath`,或者显式传入 `dwfWasmUrl` / `workerUrl`。
|
|
112
120
|
|
|
113
121
|
|
|
114
122
|
## Demo 启动说明
|
|
@@ -198,7 +206,7 @@ new CadViewer({
|
|
|
198
206
|
|
|
199
207
|
## Worker 化 DWG 解析
|
|
200
208
|
|
|
201
|
-
`DwgLoader` 在浏览器里默认使用 module Web Worker
|
|
209
|
+
`DwgLoader` 在浏览器里默认使用 module Web Worker。默认 worker 地址是 `wasm/dwg-worker.js`,相对于页面 URL 解析。Worker 内部导入 `@mlightcad/libredwg-web`,初始化 LibreDWG WASM,缓存该 WASM 实例,解码 DWG 字节,并把结果归一化为可 structured-clone 的 `CadDocument` 后发送回 UI 线程。Canvas 渲染仍然留在主线程。
|
|
202
210
|
|
|
203
211
|
```ts
|
|
204
212
|
const controller = new AbortController();
|
|
@@ -221,7 +229,7 @@ await viewer.loadFile(file, { signal: controller.signal });
|
|
|
221
229
|
controller.abort();
|
|
222
230
|
```
|
|
223
231
|
|
|
224
|
-
如果你的构建系统或 CDN 对 worker 资源路径有特殊要求,可以显式传入 worker
|
|
232
|
+
如果你的构建系统或 CDN 对 worker 资源路径有特殊要求,可以显式传入 worker 地址或构造器:
|
|
225
233
|
|
|
226
234
|
```ts
|
|
227
235
|
new CadViewer({
|
|
@@ -241,7 +249,7 @@ const viewer = new CadViewer({
|
|
|
241
249
|
container, // 容器元素,组件会自动创建 canvas
|
|
242
250
|
canvas, // 也可以传入已有 canvas
|
|
243
251
|
renderer: 'auto', // 'auto' | 'webgl' | 'canvas2d'
|
|
244
|
-
wasmPath: '/wasm', //
|
|
252
|
+
wasmPath: '/wasm', // 包含 libredwg-web.js、libredwg-web.wasm 和 dwfv-render.wasm 的目录
|
|
245
253
|
dxfEncoding: 'gb18030', // 可选:旧 DXF codepage 元数据错误时显式指定编码
|
|
246
254
|
dwfWasmUrl: '/wasm/dwfv-render.wasm',
|
|
247
255
|
autoFit: true,
|
|
@@ -261,6 +269,7 @@ const viewer = new CadViewer({
|
|
|
261
269
|
maxVisibleTextLabels: 2400
|
|
262
270
|
},
|
|
263
271
|
useWorker: true, // DWG 默认开启
|
|
272
|
+
workerUrl: '/wasm/dwg-worker.js', // 可选覆盖;这是默认地址
|
|
264
273
|
workerTimeoutMs: 0, // 0 表示不限制
|
|
265
274
|
dwfPreferWebgl: true,
|
|
266
275
|
dwfPreferWasm: true,
|