@mlightcad/libredwg-converter 3.5.21 → 3.5.23
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/LICENSE +21 -21
- package/README.md +52 -52
- package/dist/libredwg-converter.js +108 -106
- package/dist/libredwg-converter.umd.cjs +1 -1
- package/dist/libredwg-parser-worker.js +102 -102
- package/lib/AcDbEntitiyConverter.d.ts.map +1 -1
- package/lib/AcDbEntitiyConverter.js +18 -2
- package/lib/AcDbEntitiyConverter.js.map +1 -1
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 mlight-lee
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 mlight-lee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
# @mlightcad/libredwg-converter
|
|
2
|
-
|
|
3
|
-
The `libredwg-converter` package provides a DWG file converter for the RealDWG-Web ecosystem, enabling reading and conversion of DWG files into the AutoCAD-like drawing database structure. It is based on the [LibreDWG](https://www.gnu.org/software/libredwg/) library compiled to WebAssembly.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
This package implements a DWG file converter compatible with the RealDWG-Web data model. It allows you to register DWG file support in your application and convert DWG files into the in-memory drawing database.
|
|
8
|
-
|
|
9
|
-
## Key Features
|
|
10
|
-
|
|
11
|
-
- **DWG File Support**: Read and convert DWG files to the drawing database
|
|
12
|
-
- **Integration**: Designed to work with the RealDWG-Web data model and converter manager
|
|
13
|
-
- **WebAssembly Powered**: Uses LibreDWG compiled to WASM for fast, browser-compatible parsing
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm install @mlightcad/libredwg-converter
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
> **Peer dependencies:**
|
|
22
|
-
> - `@mlightcad/data-model`
|
|
23
|
-
> - `@mlightcad/libredwg-web`
|
|
24
|
-
|
|
25
|
-
## Usage Example
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import { AcDbDatabaseConverterManager, AcDbFileType } from '@mlightcad/data-model';
|
|
29
|
-
import { AcDbLibreDwgConverter } from '@mlightcad/libredwg-converter';
|
|
30
|
-
|
|
31
|
-
// WASM module loading (async)
|
|
32
|
-
import('@mlightcad/libredwg-web/wasm/libredwg-web').then(libredwgModule => {
|
|
33
|
-
const dwgConverter = new AcDbLibreDwgConverter(libredwgModule);
|
|
34
|
-
AcDbDatabaseConverterManager.instance.register(AcDbFileType.DWG, dwgConverter);
|
|
35
|
-
});
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## API
|
|
39
|
-
|
|
40
|
-
- **AcDbLibreDwgConverter**: Main converter class for DWG files (extends `AcDbDatabaseConverter`)
|
|
41
|
-
|
|
42
|
-
## Dependencies
|
|
43
|
-
|
|
44
|
-
- **@mlightcad/data-model**: Drawing database and entity definitions
|
|
45
|
-
- **@mlightcad/libredwg-web**: WASM wrapper for LibreDWG
|
|
46
|
-
|
|
47
|
-
## API Documentation
|
|
48
|
-
|
|
49
|
-
For detailed API documentation, visit the [RealDWG-Web documentation](https://mlight-lee.github.io/realdwg-web/).
|
|
50
|
-
|
|
51
|
-
## Contributing
|
|
52
|
-
|
|
1
|
+
# @mlightcad/libredwg-converter
|
|
2
|
+
|
|
3
|
+
The `libredwg-converter` package provides a DWG file converter for the RealDWG-Web ecosystem, enabling reading and conversion of DWG files into the AutoCAD-like drawing database structure. It is based on the [LibreDWG](https://www.gnu.org/software/libredwg/) library compiled to WebAssembly.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package implements a DWG file converter compatible with the RealDWG-Web data model. It allows you to register DWG file support in your application and convert DWG files into the in-memory drawing database.
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
- **DWG File Support**: Read and convert DWG files to the drawing database
|
|
12
|
+
- **Integration**: Designed to work with the RealDWG-Web data model and converter manager
|
|
13
|
+
- **WebAssembly Powered**: Uses LibreDWG compiled to WASM for fast, browser-compatible parsing
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @mlightcad/libredwg-converter
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
> **Peer dependencies:**
|
|
22
|
+
> - `@mlightcad/data-model`
|
|
23
|
+
> - `@mlightcad/libredwg-web`
|
|
24
|
+
|
|
25
|
+
## Usage Example
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { AcDbDatabaseConverterManager, AcDbFileType } from '@mlightcad/data-model';
|
|
29
|
+
import { AcDbLibreDwgConverter } from '@mlightcad/libredwg-converter';
|
|
30
|
+
|
|
31
|
+
// WASM module loading (async)
|
|
32
|
+
import('@mlightcad/libredwg-web/wasm/libredwg-web').then(libredwgModule => {
|
|
33
|
+
const dwgConverter = new AcDbLibreDwgConverter(libredwgModule);
|
|
34
|
+
AcDbDatabaseConverterManager.instance.register(AcDbFileType.DWG, dwgConverter);
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## API
|
|
39
|
+
|
|
40
|
+
- **AcDbLibreDwgConverter**: Main converter class for DWG files (extends `AcDbDatabaseConverter`)
|
|
41
|
+
|
|
42
|
+
## Dependencies
|
|
43
|
+
|
|
44
|
+
- **@mlightcad/data-model**: Drawing database and entity definitions
|
|
45
|
+
- **@mlightcad/libredwg-web**: WASM wrapper for LibreDWG
|
|
46
|
+
|
|
47
|
+
## API Documentation
|
|
48
|
+
|
|
49
|
+
For detailed API documentation, visit the [RealDWG-Web documentation](https://mlight-lee.github.io/realdwg-web/).
|
|
50
|
+
|
|
51
|
+
## Contributing
|
|
52
|
+
|
|
53
53
|
This package is part of the RealDWG-Web monorepo. Please refer to the main project README for contribution guidelines.
|
|
@@ -28,22 +28,22 @@ class C {
|
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
convertEllipse(e) {
|
|
31
|
-
const n = new D(e.majorAxisEndPoint),
|
|
31
|
+
const n = new D(e.majorAxisEndPoint), s = n.length();
|
|
32
32
|
return new k(
|
|
33
33
|
e.center,
|
|
34
34
|
e.extrusionDirection ?? D.Z_AXIS,
|
|
35
35
|
n,
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
s,
|
|
37
|
+
s * e.axisRatio,
|
|
38
38
|
e.startAngle,
|
|
39
39
|
e.endAngle
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
42
|
convertLine(e) {
|
|
43
|
-
const n = e.startPoint,
|
|
43
|
+
const n = e.startPoint, s = e.endPoint;
|
|
44
44
|
return new F(
|
|
45
45
|
new w(n.x, n.y, n.z),
|
|
46
|
-
new w(
|
|
46
|
+
new w(s.x, s.y, s.z)
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
convertSpline(e) {
|
|
@@ -80,18 +80,20 @@ class C {
|
|
|
80
80
|
}
|
|
81
81
|
convertLWPolyline(e) {
|
|
82
82
|
const n = new N();
|
|
83
|
-
|
|
83
|
+
n.closed = !!(e.flag & 512);
|
|
84
|
+
const s = e.constantWidth ?? -1;
|
|
85
|
+
return e.vertices.forEach((o, t) => {
|
|
84
86
|
n.addVertexAt(
|
|
85
|
-
|
|
86
|
-
new b(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
t,
|
|
88
|
+
new b(o.x, o.y),
|
|
89
|
+
o.bulge,
|
|
90
|
+
o.startWidth ?? s,
|
|
91
|
+
o.endWidth ?? s
|
|
90
92
|
);
|
|
91
93
|
}), n;
|
|
92
94
|
}
|
|
93
95
|
convertPolyline2d(e) {
|
|
94
|
-
const n = !!(e.flag & 1),
|
|
96
|
+
const n = !!(e.flag & 1), s = !!(e.flag & 16), o = !!(e.flag & 64), t = !!(e.flag & 32), r = [], a = [], c = [];
|
|
95
97
|
if (e.vertices.map((i) => {
|
|
96
98
|
if (!(i.flag & 16))
|
|
97
99
|
if (o && i.flag & 128)
|
|
@@ -111,9 +113,9 @@ class C {
|
|
|
111
113
|
y: i.y,
|
|
112
114
|
z: i.z
|
|
113
115
|
}), a.push(i.bulge ?? 0);
|
|
114
|
-
}),
|
|
116
|
+
}), s) {
|
|
115
117
|
const i = e.meshMVertexCount ?? 2, d = e.meshNVertexCount ?? 2;
|
|
116
|
-
return new B(i, d, r, n,
|
|
118
|
+
return new B(i, d, r, n, t);
|
|
117
119
|
} else {
|
|
118
120
|
if (o)
|
|
119
121
|
return new z(r, c);
|
|
@@ -132,30 +134,30 @@ class C {
|
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
convertPolyline3d(e) {
|
|
135
|
-
const n = !!(e.flag & 1),
|
|
136
|
-
e.vertices.map((
|
|
137
|
-
|
|
138
|
-
x:
|
|
139
|
-
y:
|
|
140
|
-
z:
|
|
137
|
+
const n = !!(e.flag & 1), s = [];
|
|
138
|
+
e.vertices.map((t) => {
|
|
139
|
+
t.flag & 16 || s.push({
|
|
140
|
+
x: t.x,
|
|
141
|
+
y: t.y,
|
|
142
|
+
z: t.z
|
|
141
143
|
});
|
|
142
144
|
});
|
|
143
145
|
let o = y.SimplePoly;
|
|
144
|
-
return e.flag & 4 && (e.smoothType == 6 ? o = y.CubicSplinePoly : e.smoothType == 5 && (o = y.QuadSplinePoly)), new W(o,
|
|
146
|
+
return e.flag & 4 && (e.smoothType == 6 ? o = y.CubicSplinePoly : e.smoothType == 5 && (o = y.QuadSplinePoly)), new W(o, s, n);
|
|
145
147
|
}
|
|
146
148
|
convertHatch(e) {
|
|
147
149
|
var o;
|
|
148
150
|
const n = new H();
|
|
149
|
-
return (o = e.definitionLines) == null || o.forEach((
|
|
151
|
+
return (o = e.definitionLines) == null || o.forEach((t) => {
|
|
150
152
|
n.definitionLines.push({
|
|
151
|
-
angle:
|
|
152
|
-
base:
|
|
153
|
-
offset:
|
|
154
|
-
dashLengths:
|
|
153
|
+
angle: t.angle,
|
|
154
|
+
base: t.base,
|
|
155
|
+
offset: t.offset,
|
|
156
|
+
dashLengths: t.numberOfDashLengths > 0 ? t.dashLengths : []
|
|
155
157
|
});
|
|
156
|
-
}), n.isSolidFill = e.solidFill == 1, n.hatchStyle = e.hatchStyle, n.patternName = e.patternName, n.patternType = e.patternType, n.patternAngle = e.patternAngle == null ? 0 : e.patternAngle, n.patternScale = e.patternScale == null ? 0 : e.patternScale, e.boundaryPaths.forEach((
|
|
157
|
-
if (
|
|
158
|
-
const a =
|
|
158
|
+
}), n.isSolidFill = e.solidFill == 1, n.hatchStyle = e.hatchStyle, n.patternName = e.patternName, n.patternType = e.patternType, n.patternAngle = e.patternAngle == null ? 0 : e.patternAngle, n.patternScale = e.patternScale == null ? 0 : e.patternScale, e.boundaryPaths.forEach((t) => {
|
|
159
|
+
if (t.boundaryPathTypeFlag & 2) {
|
|
160
|
+
const a = t, c = new X();
|
|
159
161
|
c.closed = a.isClosed, a.vertices.forEach((i, d) => {
|
|
160
162
|
c.addVertexAt(d, {
|
|
161
163
|
x: i.x,
|
|
@@ -164,7 +166,7 @@ class C {
|
|
|
164
166
|
});
|
|
165
167
|
}), n.add(c);
|
|
166
168
|
} else {
|
|
167
|
-
const a =
|
|
169
|
+
const a = t, c = [];
|
|
168
170
|
a.edges.forEach((d) => {
|
|
169
171
|
if (d != null) {
|
|
170
172
|
if (d.type == 1) {
|
|
@@ -242,11 +244,11 @@ class C {
|
|
|
242
244
|
e.columnCount
|
|
243
245
|
);
|
|
244
246
|
return n.tableStyleId = e.tableStyleId, n.owningBlockRecordId = e.blockRecordHandle, e.directionVector && (n.horizontalDirection = new D(e.directionVector)), n.attachmentPoint = e.attachmentPoint, n.position.copy(e.startPoint), n.tableValueFlag = e.tableValue, n.tableOverrideFlag = e.overrideFlag, n.borderColorOverrideFlag = e.borderColorOverrideFlag, n.borderLineweightOverrideFlag = e.borderLineWeightOverrideFlag, n.borderVisibilityOverrideFlag = e.borderVisibilityOverrideFlag, e.columnWidthArr.forEach(
|
|
245
|
-
(
|
|
247
|
+
(s, o) => n.setColumnWidth(o, s)
|
|
246
248
|
), e.rowHeightArr.forEach(
|
|
247
|
-
(
|
|
248
|
-
), e.cells.forEach((
|
|
249
|
-
n.setCell(o,
|
|
249
|
+
(s, o) => n.setRowHeight(o, s)
|
|
250
|
+
), e.cells.forEach((s, o) => {
|
|
251
|
+
n.setCell(o, s);
|
|
250
252
|
}), n;
|
|
251
253
|
}
|
|
252
254
|
convertText(e) {
|
|
@@ -259,56 +261,56 @@ class C {
|
|
|
259
261
|
}
|
|
260
262
|
convertLeader(e) {
|
|
261
263
|
const n = new J();
|
|
262
|
-
return e.vertices.forEach((
|
|
263
|
-
n.appendVertex(
|
|
264
|
+
return e.vertices.forEach((s) => {
|
|
265
|
+
n.appendVertex(s);
|
|
264
266
|
}), n.hasArrowHead = e.isArrowheadEnabled, n.hasHookLine = e.isHooklineExists, n.isSplined = e.isSpline, n.dimensionStyle = e.styleName, n.annoType = e.leaderCreationFlag, n;
|
|
265
267
|
}
|
|
266
268
|
convertDimension(e) {
|
|
267
269
|
if (e.subclassMarker == "AcDbAlignedDimension" || e.subclassMarker == "AcDbRotatedDimension") {
|
|
268
|
-
const n = e,
|
|
270
|
+
const n = e, s = new Q(
|
|
269
271
|
n.subDefinitionPoint1,
|
|
270
272
|
n.subDefinitionPoint2,
|
|
271
273
|
n.definitionPoint
|
|
272
274
|
);
|
|
273
|
-
return n.insertionPoint && (
|
|
275
|
+
return n.insertionPoint && (s.dimBlockPosition = {
|
|
274
276
|
x: n.insertionPoint.x,
|
|
275
277
|
y: n.insertionPoint.y,
|
|
276
278
|
z: 0
|
|
277
|
-
}),
|
|
279
|
+
}), s.rotation = n.rotationAngle, this.processDimensionCommonAttrs(e, s), s;
|
|
278
280
|
} else if (e.subclassMarker == "AcDb3PointAngularDimension") {
|
|
279
|
-
const n = e,
|
|
281
|
+
const n = e, s = new $(
|
|
280
282
|
n.centerPoint,
|
|
281
283
|
n.subDefinitionPoint1,
|
|
282
284
|
n.subDefinitionPoint2,
|
|
283
285
|
n.definitionPoint
|
|
284
286
|
);
|
|
285
|
-
return this.processDimensionCommonAttrs(e,
|
|
287
|
+
return this.processDimensionCommonAttrs(e, s), s;
|
|
286
288
|
} else if (e.subclassMarker == "AcDbOrdinateDimension") {
|
|
287
|
-
const n = e,
|
|
289
|
+
const n = e, s = new ee(
|
|
288
290
|
n.subDefinitionPoint1,
|
|
289
291
|
n.subDefinitionPoint2
|
|
290
292
|
);
|
|
291
|
-
return this.processDimensionCommonAttrs(e,
|
|
293
|
+
return this.processDimensionCommonAttrs(e, s), s;
|
|
292
294
|
} else if (e.subclassMarker == "AcDbRadialDimension") {
|
|
293
|
-
const n = e,
|
|
295
|
+
const n = e, s = new ne(
|
|
294
296
|
n.definitionPoint,
|
|
295
297
|
n.centerPoint,
|
|
296
298
|
n.leaderLength
|
|
297
299
|
);
|
|
298
|
-
return this.processDimensionCommonAttrs(e,
|
|
300
|
+
return this.processDimensionCommonAttrs(e, s), s;
|
|
299
301
|
} else if (e.subclassMarker == "AcDbDiametricDimension") {
|
|
300
|
-
const n = e,
|
|
302
|
+
const n = e, s = new oe(
|
|
301
303
|
n.definitionPoint,
|
|
302
304
|
n.centerPoint,
|
|
303
305
|
n.leaderLength
|
|
304
306
|
);
|
|
305
|
-
return this.processDimensionCommonAttrs(e,
|
|
307
|
+
return this.processDimensionCommonAttrs(e, s), s;
|
|
306
308
|
}
|
|
307
309
|
return null;
|
|
308
310
|
}
|
|
309
311
|
processImage(e, n) {
|
|
310
|
-
n.position.copy(e.position), n.brightness = e.brightness, n.contrast = e.contrast, n.fade = e.fade, n.imageSize.copy(e.imageSize), n.imageDefId = e.imageDefHandle, n.isClipped = e.clipping > 0, n.isShownClipped = (e.flags | 4) > 0, n.isImageShown = (e.flags | 3) > 0, n.isImageTransparent = (e.flags | 8) > 0, e.clippingBoundaryPath.forEach((
|
|
311
|
-
n.clipBoundary.push(new b(
|
|
312
|
+
n.position.copy(e.position), n.brightness = e.brightness, n.contrast = e.contrast, n.fade = e.fade, n.imageSize.copy(e.imageSize), n.imageDefId = e.imageDefHandle, n.isClipped = e.clipping > 0, n.isShownClipped = (e.flags | 4) > 0, n.isImageShown = (e.flags | 3) > 0, n.isImageTransparent = (e.flags | 8) > 0, e.clippingBoundaryPath.forEach((s) => {
|
|
313
|
+
n.clipBoundary.push(new b(s));
|
|
312
314
|
}), n.clipBoundaryType = e.clippingBoundaryType, n.width = Math.sqrt(
|
|
313
315
|
e.uPixel.x ** 2 + e.uPixel.y ** 2 + e.uPixel.z ** 2
|
|
314
316
|
) * e.imageSize.x, n.height = Math.sqrt(
|
|
@@ -336,8 +338,8 @@ class C {
|
|
|
336
338
|
return n.basePoint.copy(e.firstPoint), n.unitDir.copy(e.unitDirection), n;
|
|
337
339
|
}
|
|
338
340
|
convertAttributeCommon(e, n) {
|
|
339
|
-
const
|
|
340
|
-
n.textString =
|
|
341
|
+
const s = e.text;
|
|
342
|
+
n.textString = s.text, n.styleName = s.styleName, n.height = s.textHeight, n.position.copy(s.startPoint), n.rotation = s.rotation, n.oblique = s.obliqueAngle ?? 0, n.thickness = s.thickness, n.horizontalMode = s.halign, n.verticalMode = s.valign, n.widthFactor = s.xScale ?? 1, n.tag = e.tag, n.fieldLength = e.fieldLength, n.isInvisible = (e.flags & I.Invisible) !== 0, n.isConst = (e.flags & I.Const) !== 0, n.isVerifiable = (e.flags & I.Verifiable) !== 0, n.isPreset = (e.flags & I.Preset) !== 0, n.lockPositionInBlock = e.lockPositionFlag, n.isReallyLocked = e.isReallyLocked, n.isMTextAttribute = (e.mtextFlag & M.MultiLine) !== 0, n.isConstMTextAttribute = (e.mtextFlag & M.ConstMultiLine) !== 0;
|
|
341
343
|
}
|
|
342
344
|
convertAttribute(e) {
|
|
343
345
|
const n = new le();
|
|
@@ -349,8 +351,8 @@ class C {
|
|
|
349
351
|
}
|
|
350
352
|
convertBlockReference(e) {
|
|
351
353
|
const n = new de(e.name);
|
|
352
|
-
return e.insertionPoint && n.position.copy(e.insertionPoint), n.scaleFactors.x = e.xScale, n.scaleFactors.y = e.yScale, n.scaleFactors.z = e.zScale, n.rotation = e.rotation, n.normal.copy(e.extrusionDirection), e.attribs && e.attribs.forEach((
|
|
353
|
-
const o = this.convertAttribute(
|
|
354
|
+
return e.insertionPoint && n.position.copy(e.insertionPoint), n.scaleFactors.x = e.xScale, n.scaleFactors.y = e.yScale, n.scaleFactors.z = e.zScale, n.rotation = e.rotation, n.normal.copy(e.extrusionDirection), e.attribs && e.attribs.forEach((s) => {
|
|
355
|
+
const o = this.convertAttribute(s);
|
|
354
356
|
n.appendAttributes(o);
|
|
355
357
|
}), n;
|
|
356
358
|
}
|
|
@@ -358,9 +360,9 @@ class C {
|
|
|
358
360
|
n.dimBlockId = e.name, n.textPosition.copy(e.textPoint), n.textRotation = e.textRotation || 0, e.textLineSpacingFactor && (n.textLineSpacingFactor = e.textLineSpacingFactor), e.textLineSpacingStyle && (n.textLineSpacingStyle = e.textLineSpacingStyle), n.dimensionStyleName = e.styleName, n.dimensionText = e.text || "", n.measurement = e.measurement;
|
|
359
361
|
}
|
|
360
362
|
processCommonAttrs(e, n) {
|
|
361
|
-
if (n.layer = e.layer || "0", n.objectId = e.handle, n.ownerId = e.ownerBlockRecordSoftId, e.lineType != null && (n.lineType = e.lineType), e.lineweight != null && (n.lineWeight = e.lineweight), e.lineTypeScale != null && (n.linetypeScale = e.lineTypeScale), e.color != null && n.color.setRGBValue(e.color), e.colorIndex != null && (n.color.colorIndex = e.colorIndex), e.colorName && (n.color.colorName = e.colorName), e.isVisible != null && (n.visibility = e.isVisible), e.transparency != null) {
|
|
362
|
-
const
|
|
363
|
-
|
|
363
|
+
if (n.layer = e.layer || "0", n.objectId = e.handle, n.ownerId = e.ownerBlockRecordSoftId, e.lineType != null && (n.lineType = e.lineType), e.lineweight != null && (n.lineWeight = e.lineweight), e.lineTypeScale != null && (n.linetypeScale = e.lineTypeScale), e.color != null && n.color.setRGBValue(e.color), e.colorIndex != null && (e.color == null || e.colorIndex === 7) && (n.color.colorIndex = e.colorIndex), e.colorName && (n.color.colorName = e.colorName), e.isVisible != null && (n.visibility = e.isVisible), e.transparency != null) {
|
|
364
|
+
const s = new pe();
|
|
365
|
+
s.method = e.transparencyType, (s.isByBlock || s.isByBlock) && (s.alpha = e.transparency), n.transparency = s;
|
|
364
366
|
}
|
|
365
367
|
}
|
|
366
368
|
}
|
|
@@ -370,14 +372,14 @@ class Ce extends ue {
|
|
|
370
372
|
super(e), e.useWorker = !0, e.parserWorkerUrl || (e.parserWorkerUrl = "/assets/libredwg-parser-worker.js");
|
|
371
373
|
}
|
|
372
374
|
async parse(e, n) {
|
|
373
|
-
const
|
|
374
|
-
if (
|
|
375
|
-
const
|
|
376
|
-
workerUrl:
|
|
375
|
+
const s = this.config, o = this.getParserWorkerTimeout(e, n);
|
|
376
|
+
if (s.useWorker && s.parserWorkerUrl) {
|
|
377
|
+
const t = fe({
|
|
378
|
+
workerUrl: s.parserWorkerUrl,
|
|
377
379
|
timeout: o,
|
|
378
380
|
maxConcurrentWorkers: 1
|
|
379
|
-
}), r = await
|
|
380
|
-
if (
|
|
381
|
+
}), r = await t.execute(e);
|
|
382
|
+
if (t.destroy(), r.success)
|
|
381
383
|
return r.data;
|
|
382
384
|
throw new Error(
|
|
383
385
|
`Failed to parse drawing due to error: '${r.error}'`
|
|
@@ -390,7 +392,7 @@ class Ce extends ue {
|
|
|
390
392
|
e.tables.BLOCK_RECORD.entries.forEach((r) => {
|
|
391
393
|
n.set(r.name, r);
|
|
392
394
|
});
|
|
393
|
-
const
|
|
395
|
+
const s = /* @__PURE__ */ new Map(), o = (r) => {
|
|
394
396
|
if (r) {
|
|
395
397
|
const a = r.lastIndexOf(".");
|
|
396
398
|
return a >= 0 ? r.substring(0, a).toLowerCase() : r.toLowerCase();
|
|
@@ -399,51 +401,51 @@ class Ce extends ue {
|
|
|
399
401
|
e.tables.STYLE.entries.forEach((r) => {
|
|
400
402
|
const a = [];
|
|
401
403
|
let c = o(r.font);
|
|
402
|
-
c && a.push(c), c = o(r.bigFont), c && a.push(c),
|
|
404
|
+
c && a.push(c), c = o(r.bigFont), c && a.push(c), s.set(r.name, a);
|
|
403
405
|
});
|
|
404
|
-
const
|
|
405
|
-
return this.getFontsInBlock(e.entities, n,
|
|
406
|
+
const t = /* @__PURE__ */ new Set();
|
|
407
|
+
return this.getFontsInBlock(e.entities, n, s, t), Array.from(t);
|
|
406
408
|
}
|
|
407
|
-
getFontsInBlock(e, n,
|
|
408
|
-
const
|
|
409
|
+
getFontsInBlock(e, n, s, o) {
|
|
410
|
+
const t = /\\f(.*?)\|/g;
|
|
409
411
|
e.forEach((r) => {
|
|
410
412
|
if (r.type == "MTEXT") {
|
|
411
413
|
const a = r;
|
|
412
|
-
[...a.text.matchAll(
|
|
414
|
+
[...a.text.matchAll(t)].forEach((i) => {
|
|
413
415
|
o.add(i[1].toLowerCase());
|
|
414
416
|
});
|
|
415
|
-
const c =
|
|
417
|
+
const c = s.get(a.styleName);
|
|
416
418
|
c == null || c.forEach((i) => o.add(i));
|
|
417
419
|
} else if (r.type == "TEXT") {
|
|
418
|
-
const a = r, c =
|
|
420
|
+
const a = r, c = s.get(a.styleName);
|
|
419
421
|
c == null || c.forEach((i) => o.add(i));
|
|
420
422
|
} else if (r.type == "INSERT") {
|
|
421
423
|
const a = r, c = n.get(a.name);
|
|
422
|
-
c && this.getFontsInBlock(c.entities, n,
|
|
424
|
+
c && this.getFontsInBlock(c.entities, n, s, o);
|
|
423
425
|
}
|
|
424
426
|
});
|
|
425
427
|
}
|
|
426
428
|
processLineTypes(e, n) {
|
|
427
429
|
e.tables.LTYPE.entries.forEach((o) => {
|
|
428
|
-
const
|
|
430
|
+
const t = {
|
|
429
431
|
name: o.name,
|
|
430
432
|
description: o.description,
|
|
431
433
|
standardFlag: o.standardFlag,
|
|
432
434
|
totalPatternLength: o.totalPatternLength,
|
|
433
435
|
pattern: o.pattern
|
|
434
|
-
}, r = new he(
|
|
436
|
+
}, r = new he(t);
|
|
435
437
|
this.processCommonTableEntryAttrs(o, r), r.name = o.name, n.tables.linetypeTable.add(r);
|
|
436
438
|
});
|
|
437
439
|
}
|
|
438
440
|
processTextStyles(e, n) {
|
|
439
441
|
e.tables.STYLE.entries.forEach((o) => {
|
|
440
|
-
const
|
|
441
|
-
this.processCommonTableEntryAttrs(o,
|
|
442
|
+
const t = new ge(o);
|
|
443
|
+
this.processCommonTableEntryAttrs(o, t), n.tables.textStyleTable.add(t);
|
|
442
444
|
});
|
|
443
445
|
}
|
|
444
446
|
processDimStyles(e, n) {
|
|
445
447
|
e.tables.DIMSTYLE.entries.forEach((o) => {
|
|
446
|
-
const
|
|
448
|
+
const t = {
|
|
447
449
|
name: o.name,
|
|
448
450
|
ownerId: o.ownerHandle,
|
|
449
451
|
dimpost: o.DIMPOST || "",
|
|
@@ -512,21 +514,21 @@ class Ce extends ue {
|
|
|
512
514
|
dimblk2: o.DIMBLK2 || "",
|
|
513
515
|
dimlwd: o.DIMLWD,
|
|
514
516
|
dimlwe: o.DIMLWE
|
|
515
|
-
}, r = new De(
|
|
517
|
+
}, r = new De(t);
|
|
516
518
|
this.processCommonTableEntryAttrs(o, r), n.tables.dimStyleTable.add(r);
|
|
517
519
|
});
|
|
518
520
|
}
|
|
519
521
|
processLayers(e, n) {
|
|
520
522
|
e.tables.LAYER.entries.forEach((o) => {
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
+
const t = new Ae();
|
|
524
|
+
t.colorIndex = o.colorIndex;
|
|
523
525
|
const r = new Ie({
|
|
524
526
|
name: o.name,
|
|
525
527
|
standardFlags: o.standardFlag,
|
|
526
528
|
linetype: o.lineType,
|
|
527
529
|
lineWeight: o.lineweight,
|
|
528
530
|
isOff: o.off,
|
|
529
|
-
color:
|
|
531
|
+
color: t,
|
|
530
532
|
isPlottable: o.plotFlag != 0
|
|
531
533
|
});
|
|
532
534
|
this.processCommonTableEntryAttrs(o, r), n.tables.layerTable.add(r);
|
|
@@ -534,27 +536,27 @@ class Ce extends ue {
|
|
|
534
536
|
}
|
|
535
537
|
processViewports(e, n) {
|
|
536
538
|
e.tables.VPORT.entries.forEach((o) => {
|
|
537
|
-
const
|
|
538
|
-
this.processCommonTableEntryAttrs(o,
|
|
539
|
+
const t = new ye();
|
|
540
|
+
this.processCommonTableEntryAttrs(o, t), o.circleSides && (t.circleSides = o.circleSides), t.standardFlag = o.standardFlag, t.center.copy(o.center), t.lowerLeftCorner.copy(o.lowerLeftCorner), t.upperRightCorner.copy(o.upperRightCorner), o.snapBasePoint && t.snapBase.copy(o.snapBasePoint), o.snapRotationAngle && (t.snapAngle = o.snapRotationAngle), o.snapSpacing && t.snapIncrements.copy(o.snapSpacing), o.majorGridLines && (t.gridMajor = o.majorGridLines), o.gridSpacing && t.gridIncrements.copy(o.gridSpacing), o.backgroundObjectId && (t.backgroundObjectId = o.backgroundObjectId), t.gsView.center.copy(o.center), t.gsView.viewDirectionFromTarget.copy(o.viewDirectionFromTarget), t.gsView.viewTarget.copy(o.viewTarget), o.lensLength && (t.gsView.lensLength = o.lensLength), o.frontClippingPlane && (t.gsView.frontClippingPlane = o.frontClippingPlane), o.backClippingPlane && (t.gsView.backClippingPlane = o.backClippingPlane), o.viewHeight && (t.gsView.viewHeight = o.viewHeight), o.viewTwistAngle && (t.gsView.viewTwistAngle = o.viewTwistAngle), o.frozenLayers && (t.gsView.frozenLayers = o.frozenLayers), o.styleSheet && (t.gsView.styleSheet = o.styleSheet), o.renderMode && (t.gsView.renderMode = o.renderMode), o.viewMode && (t.gsView.viewMode = o.viewMode), o.ucsIconSetting && (t.gsView.ucsIconSetting = o.ucsIconSetting), o.ucsOrigin && t.gsView.ucsOrigin.copy(o.ucsOrigin), o.ucsXAxis && t.gsView.ucsXAxis.copy(o.ucsXAxis), o.ucsYAxis && t.gsView.ucsYAxis.copy(o.ucsYAxis), o.orthographicType && (t.gsView.orthographicType = o.orthographicType), o.shadePlotSetting && (t.gsView.shadePlotSetting = o.shadePlotSetting), o.shadePlotObjectId && (t.gsView.shadePlotObjectId = o.shadePlotObjectId), o.visualStyleObjectId && (t.gsView.visualStyleObjectId = o.visualStyleObjectId), o.isDefaultLightingOn && (t.gsView.isDefaultLightingOn = o.isDefaultLightingOn), o.defaultLightingType && (t.gsView.defaultLightingType = o.defaultLightingType), o.brightness && (t.gsView.brightness = o.brightness), o.contrast && (t.gsView.contrast = o.contrast), o.ambientColor && (t.gsView.ambientColor = o.ambientColor), n.tables.viewportTable.add(t);
|
|
539
541
|
});
|
|
540
542
|
}
|
|
541
543
|
processBlockTables(e, n) {
|
|
542
544
|
e.tables.BLOCK_RECORD.entries.forEach((o) => {
|
|
543
|
-
let
|
|
544
|
-
|
|
545
|
+
let t = n.tables.blockTable.getAt(o.name);
|
|
546
|
+
t || (t = new we(), t.objectId = o.handle, t.name = o.name, t.ownerId = o.ownerHandle, t.origin.copy(o.basePoint), t.layoutId = o.layout, t.blockInsertUnits = o.insertionUnits, t.explodability = o.explodability, t.blockScaling = o.scalability, o.bmpPreview && (t.bmpPreview = o.bmpPreview), n.tables.blockTable.add(t)), !t.isModelSapce && o.entities && o.entities.length > 0 && this.processEntitiesInBlock(o.entities, t);
|
|
545
547
|
});
|
|
546
548
|
}
|
|
547
549
|
processBlocks(e, n) {
|
|
548
550
|
}
|
|
549
551
|
async processEntitiesInBlock(e, n) {
|
|
550
|
-
const
|
|
552
|
+
const s = new C(), o = e.length, t = [];
|
|
551
553
|
for (let r = 0; r < o; r++) {
|
|
552
|
-
const a = e[r], c =
|
|
553
|
-
c &&
|
|
554
|
+
const a = e[r], c = s.convert(a);
|
|
555
|
+
c && t.push(c);
|
|
554
556
|
}
|
|
555
|
-
n.appendEntity(
|
|
557
|
+
n.appendEntity(t);
|
|
556
558
|
}
|
|
557
|
-
async processEntities(e, n,
|
|
559
|
+
async processEntities(e, n, s, o, t) {
|
|
558
560
|
const r = new C();
|
|
559
561
|
let a = [];
|
|
560
562
|
e.tables.BLOCK_RECORD.entries.forEach((l) => {
|
|
@@ -563,7 +565,7 @@ class Ce extends ue {
|
|
|
563
565
|
const c = a.length, i = new Te(
|
|
564
566
|
c,
|
|
565
567
|
100 - o.value,
|
|
566
|
-
|
|
568
|
+
s
|
|
567
569
|
);
|
|
568
570
|
this.config.convertByEntityType && (a = this.groupAndFlattenByType(a));
|
|
569
571
|
const d = n.tables.blockTable.modelSpace;
|
|
@@ -573,15 +575,15 @@ class Ce extends ue {
|
|
|
573
575
|
const f = a[u], g = r.convert(f);
|
|
574
576
|
g && p.push(g);
|
|
575
577
|
}
|
|
576
|
-
if (d.appendEntity(p),
|
|
578
|
+
if (d.appendEntity(p), t) {
|
|
577
579
|
let u = o.value + h / c * (100 - o.value);
|
|
578
|
-
u > 100 && (u = 100), await
|
|
580
|
+
u > 100 && (u = 100), await t(u, "ENTITY", "IN-PROGRESS");
|
|
579
581
|
}
|
|
580
582
|
});
|
|
581
583
|
}
|
|
582
584
|
processHeader(e, n) {
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
+
const s = e.header;
|
|
586
|
+
s.CECOLOR && (s.CECOLOR.index >= 0 && s.CECOLOR.index <= 256 ? n.cecolor.colorIndex = s.CECOLOR.index : n.cecolor.setRGBValue(s.CECOLOR.rgb)), n.angBase = s.ANGBASE ?? 0, n.angDir = s.ANGDIR ?? 0, n.aunits = s.AUNITS ?? 0, n.celtype = s.CELTYPE ?? be, n.celtscale = s.CELTSCALE ?? 1, n.ltscale = s.LTSCALE ?? 1, s.EXTMAX && (n.extmax = s.EXTMAX), s.EXTMIN && (n.extmin = s.EXTMIN), n.insunits = s.INSUNITS ?? 1, n.pdmode = s.PDMODE ?? 0, n.pdsize = s.PDSIZE ?? 0, n.textstyle = s.TEXTSTYLE ?? L;
|
|
585
587
|
}
|
|
586
588
|
processCommonTableEntryAttrs(e, n) {
|
|
587
589
|
n.name = e.name, n.objectId = e.handle, n.ownerId = e.ownerHandle;
|
|
@@ -590,35 +592,35 @@ class Ce extends ue {
|
|
|
590
592
|
this.processLayouts(e, n), this.processImageDefs(e, n);
|
|
591
593
|
}
|
|
592
594
|
processLayouts(e, n) {
|
|
593
|
-
const
|
|
594
|
-
e.objects.LAYOUT.forEach((
|
|
595
|
+
const s = n.objects.layout;
|
|
596
|
+
e.objects.LAYOUT.forEach((t) => {
|
|
595
597
|
const r = new Pe();
|
|
596
|
-
r.layoutName =
|
|
598
|
+
r.layoutName = t.layoutName, r.tabOrder = t.tabOrder;
|
|
597
599
|
const a = n.tables.blockTable.newIterator();
|
|
598
|
-
r.objectId =
|
|
600
|
+
r.objectId = t.handle;
|
|
599
601
|
for (const c of a)
|
|
600
602
|
if (c.layoutId === r.objectId) {
|
|
601
603
|
r.blockTableRecordId = c.objectId;
|
|
602
604
|
break;
|
|
603
605
|
}
|
|
604
|
-
r.blockTableRecordId ||
|
|
606
|
+
r.blockTableRecordId || t.layoutName === "Model" && (r.blockTableRecordId = n.tables.blockTable.modelSpace.objectId), r.limits.min.copy(t.minLimit), r.limits.max.copy(t.maxLimit), r.extents.min.copy(t.minExtent), r.extents.max.copy(t.maxExtent), t.viewportId && r.viewportArray.push(t.viewportId), this.processCommonObjectAttrs(t, r), s.setAt(r.layoutName, r);
|
|
605
607
|
});
|
|
606
608
|
}
|
|
607
609
|
processImageDefs(e, n) {
|
|
608
|
-
const
|
|
609
|
-
e.objects.IMAGEDEF.forEach((
|
|
610
|
+
const s = n.objects.imageDefinition;
|
|
611
|
+
e.objects.IMAGEDEF.forEach((t) => {
|
|
610
612
|
const r = new Ee();
|
|
611
|
-
r.sourceFileName =
|
|
613
|
+
r.sourceFileName = t.fileName, this.processCommonObjectAttrs(t, r), s.setAt(r.objectId, r);
|
|
612
614
|
});
|
|
613
615
|
}
|
|
614
616
|
processCommonObjectAttrs(e, n) {
|
|
615
617
|
n.objectId = e.handle, n.ownerId = e.ownerHandle;
|
|
616
618
|
}
|
|
617
619
|
groupAndFlattenByType(e) {
|
|
618
|
-
const n = {},
|
|
620
|
+
const n = {}, s = [];
|
|
619
621
|
for (const o of e)
|
|
620
|
-
n[o.type] || (n[o.type] = [],
|
|
621
|
-
return
|
|
622
|
+
n[o.type] || (n[o.type] = [], s.push(o.type)), n[o.type].push(o);
|
|
623
|
+
return s.flatMap((o) => n[o]);
|
|
622
624
|
}
|
|
623
625
|
isModelSpace(e) {
|
|
624
626
|
return e && e.toUpperCase() == Me;
|