@mlightcad/libredwg-converter 3.5.30 → 3.5.32
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 +46 -42
- package/dist/libredwg-converter.umd.cjs +1 -1
- package/dist/libredwg-parser-worker.js +95 -79
- package/lib/AcDbEntitiyConverter.d.ts.map +1 -1
- package/lib/AcDbEntitiyConverter.js +41 -6
- 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.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AcDbFace as H, AcGeVector3d as A, AcDbArc as j, transformOcsPointToWcs as
|
|
1
|
+
import { AcDbFace as H, AcGeVector3d as A, AcDbArc as j, transformOcsPointToWcs as x, AcDbCircle as z, AcDbEllipse as W, AcDbLine as X, AcGePoint3d as S, AcDbSpline as M, AcDbPoint as U, AcDbTrace as G, AcDbPolyline as Y, AcGePoint2d as m, AcDbPolygonMesh as Z, AcDbPolyFaceMesh as _, AcDbPoly2dType as b, AcDb2dPolyline as K, AcDbPoly3dType as I, AcDb3dPolyline as q, AcDbHatch as J, AcGePolyline2d as Q, AcGeLine2d as $, AcGeCircArc2d as ee, AcGeVector2d as te, AcGeEllipseArc2d as ne, AcGeSpline3d as v, AcGeLoop2d as k, AcDbHatchObjectType as oe, AcDbTable as re, AcDbText as ie, AcDbMText as se, AcDbLeader as ce, AcDbMLine as ae, AcDbMLeader as le, AcDbMLeaderLineType as de, AcDbMLeaderContentType as T, AcDbAlignedDimension as fe, AcDbRotatedDimension as pe, AcDb3PointAngularDimension as ge, AcDbOrdinateDimension as ue, AcDbRadialDimension as he, AcDbDiametricDimension as De, AcDbRasterImage as ye, AcDbWipeout as Ae, AcDbViewport as be, AcDbRay as Pe, AcDbXline as Ie, AcDbAttributeFlags as P, AcDbAttributeMTextFlag as O, AcDbAttribute as N, AcDbAttributeDefinition as Te, AcDbBlockReference as we, AcCmTransparency as Le, AcDbDatabaseConverter as Ce, createWorkerApi as Ee, AcDbLinetypeTableRecord as xe, AcDbTextStyleTableRecord as Se, DEFAULT_TEXT_STYLE as R, AcDbDimStyleTableRecord as Me, AcCmColor as me, AcDbLayerTableRecord as ve, AcDbViewportTableRecord as ke, AcDbBlockTableRecord as Oe, AcDbBatchProcessing as Ne, ByLayer as Re, AcDbLayout as Ve, AcDbRasterImageDef as Fe } from "@mlightcad/data-model";
|
|
2
2
|
class V {
|
|
3
3
|
convert(e) {
|
|
4
4
|
const t = this.createEntity(e);
|
|
@@ -14,7 +14,7 @@ class V {
|
|
|
14
14
|
convertArc(e) {
|
|
15
15
|
const t = e.extrusionDirection ?? A.Z_AXIS;
|
|
16
16
|
return new j(
|
|
17
|
-
|
|
17
|
+
x(e.center, t),
|
|
18
18
|
e.radius,
|
|
19
19
|
e.startAngle,
|
|
20
20
|
e.endAngle,
|
|
@@ -23,15 +23,15 @@ class V {
|
|
|
23
23
|
}
|
|
24
24
|
convertCirle(e) {
|
|
25
25
|
const t = e.extrusionDirection ?? A.Z_AXIS;
|
|
26
|
-
return new
|
|
27
|
-
|
|
26
|
+
return new z(
|
|
27
|
+
x(e.center, t),
|
|
28
28
|
e.radius,
|
|
29
29
|
t
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
convertEllipse(e) {
|
|
33
33
|
const t = new A(e.majorAxisEndPoint), o = t.length();
|
|
34
|
-
return new
|
|
34
|
+
return new W(
|
|
35
35
|
e.center,
|
|
36
36
|
e.extrusionDirection ?? A.Z_AXIS,
|
|
37
37
|
t,
|
|
@@ -117,10 +117,10 @@ class V {
|
|
|
117
117
|
}), a.push(c.bulge ?? 0);
|
|
118
118
|
}), o) {
|
|
119
119
|
const c = e.meshMVertexCount ?? 2, d = e.meshNVertexCount ?? 2;
|
|
120
|
-
return new
|
|
120
|
+
return new Z(c, d, i, t, r);
|
|
121
121
|
} else {
|
|
122
122
|
if (n)
|
|
123
|
-
return new
|
|
123
|
+
return new _(i, s);
|
|
124
124
|
{
|
|
125
125
|
let c = b.SimplePoly;
|
|
126
126
|
return e.flag & 2 ? c = b.FitCurvePoly : e.flag & 4 && (e.smoothType == 6 ? c = b.CubicSplinePoly : e.smoothType == 5 && (c = b.QuadSplinePoly)), new K(
|
|
@@ -144,8 +144,8 @@ class V {
|
|
|
144
144
|
z: r.z
|
|
145
145
|
});
|
|
146
146
|
});
|
|
147
|
-
let n =
|
|
148
|
-
return e.flag & 4 && (e.smoothType == 6 ? n =
|
|
147
|
+
let n = I.SimplePoly;
|
|
148
|
+
return e.flag & 4 && (e.smoothType == 6 ? n = I.CubicSplinePoly : e.smoothType == 5 && (n = I.QuadSplinePoly)), new q(n, o, t);
|
|
149
149
|
}
|
|
150
150
|
convertHatch(e) {
|
|
151
151
|
var n;
|
|
@@ -190,15 +190,15 @@ class V {
|
|
|
190
190
|
new te().subVectors(l.end, l.center);
|
|
191
191
|
const p = Math.sqrt(
|
|
192
192
|
Math.pow(l.end.x, 2) + Math.pow(l.end.y, 2)
|
|
193
|
-
),
|
|
194
|
-
let
|
|
193
|
+
), g = p * l.lengthOfMinorAxis;
|
|
194
|
+
let u = l.startAngle, y = l.endAngle;
|
|
195
195
|
const h = Math.atan2(l.end.y, l.end.x);
|
|
196
|
-
l.isCCW || (
|
|
196
|
+
l.isCCW || (u = Math.PI * 2 - u, y = Math.PI * 2 - y), s.push(
|
|
197
197
|
new ne(
|
|
198
198
|
{ ...l.center, z: 0 },
|
|
199
199
|
p,
|
|
200
|
-
u,
|
|
201
200
|
g,
|
|
201
|
+
u,
|
|
202
202
|
y,
|
|
203
203
|
!l.isCCW,
|
|
204
204
|
h
|
|
@@ -208,19 +208,19 @@ class V {
|
|
|
208
208
|
const l = d;
|
|
209
209
|
if (l.numberOfControlPoints > 0 && l.numberOfKnots > 0) {
|
|
210
210
|
const f = l.controlPoints.map(
|
|
211
|
-
(
|
|
212
|
-
x:
|
|
213
|
-
y:
|
|
211
|
+
(u) => ({
|
|
212
|
+
x: u.x,
|
|
213
|
+
y: u.y,
|
|
214
214
|
z: 0
|
|
215
215
|
})
|
|
216
216
|
);
|
|
217
217
|
let p = !0;
|
|
218
|
-
const
|
|
218
|
+
const g = l.controlPoints.map((u) => (u.weight == null && (p = !1), u.weight || 1));
|
|
219
219
|
s.push(
|
|
220
220
|
new v(
|
|
221
221
|
f,
|
|
222
222
|
l.knots,
|
|
223
|
-
p ?
|
|
223
|
+
p ? g : void 0
|
|
224
224
|
)
|
|
225
225
|
);
|
|
226
226
|
} else if (l.numberOfFitData > 0) {
|
|
@@ -262,7 +262,9 @@ class V {
|
|
|
262
262
|
}
|
|
263
263
|
convertText(e) {
|
|
264
264
|
const t = new ie();
|
|
265
|
-
|
|
265
|
+
t.textString = e.text, t.styleName = e.styleName, t.height = e.textHeight, t.position.copy(e.startPoint);
|
|
266
|
+
const o = !e.endPoint || e.endPoint.x === 0 && e.endPoint.y === 0 && (e.endPoint.z ?? 0) === 0;
|
|
267
|
+
return e.endPoint && !o ? t.alignmentPoint.copy(e.endPoint) : t.alignmentPoint.copy(e.startPoint), t.rotation = e.rotation, t.oblique = e.obliqueAngle ?? 0, t.thickness = e.thickness, t.horizontalMode = e.halign, t.verticalMode = e.valign, t.widthFactor = e.xScale ?? 1, t;
|
|
266
268
|
}
|
|
267
269
|
convertMText(e) {
|
|
268
270
|
const t = new se();
|
|
@@ -289,14 +291,14 @@ class V {
|
|
|
289
291
|
})), t;
|
|
290
292
|
}
|
|
291
293
|
convertMLeader(e) {
|
|
292
|
-
var p,
|
|
294
|
+
var p, g, u, y;
|
|
293
295
|
const t = new le(), o = e;
|
|
294
296
|
t.leaderLineType = this.readNumber(o, [
|
|
295
297
|
"multileaderType",
|
|
296
298
|
"leaderLineType",
|
|
297
299
|
"leaderType"
|
|
298
300
|
]) ?? de.StraightLeader;
|
|
299
|
-
const n = this.readNumber(o, ["contentType"]) ?? (e.textContent ?
|
|
301
|
+
const n = this.readNumber(o, ["contentType"]) ?? (e.textContent ? T.MTextContent : e.blockContent ? T.BlockContent : T.NoneContent);
|
|
300
302
|
t.contentType = n, t.doglegEnabled = this.readBoolean(o, ["doglegEnabled", "enableDogleg"]) ?? !1, t.doglegLength = this.readNumber(o, ["doglegLength"]) ?? 0, e.landingPoint && (t.landingPoint = e.landingPoint), e.doglegVector && (t.doglegVector = e.doglegVector);
|
|
301
303
|
const r = this.readString(o, [
|
|
302
304
|
"mleaderStyleId",
|
|
@@ -348,7 +350,7 @@ class V {
|
|
|
348
350
|
]);
|
|
349
351
|
h != null && D && (t.mtextContent = { text: h, anchorPoint: D });
|
|
350
352
|
}
|
|
351
|
-
if ((
|
|
353
|
+
if ((g = e.blockContent) != null && g.blockHandle && e.blockContent.position)
|
|
352
354
|
t.blockContent = {
|
|
353
355
|
blockHandle: e.blockContent.blockHandle,
|
|
354
356
|
position: e.blockContent.position
|
|
@@ -367,21 +369,21 @@ class V {
|
|
|
367
369
|
position: D
|
|
368
370
|
});
|
|
369
371
|
}
|
|
370
|
-
return (
|
|
371
|
-
var
|
|
372
|
+
return (u = e.leaders) == null || u.forEach((h) => {
|
|
373
|
+
var w;
|
|
372
374
|
const D = t.addLeader({
|
|
373
375
|
landingPoint: h.landingPoint ?? e.landingPoint,
|
|
374
376
|
doglegVector: h.doglegVector ?? e.doglegVector,
|
|
375
377
|
doglegLength: h.doglegLength ?? e.doglegLength
|
|
376
378
|
});
|
|
377
|
-
(
|
|
378
|
-
var
|
|
379
|
+
(w = h.leaderLines) == null || w.forEach((L) => {
|
|
380
|
+
var C;
|
|
379
381
|
const B = t.addLeaderLine(
|
|
380
382
|
D,
|
|
381
383
|
L.vertices ?? []
|
|
382
384
|
);
|
|
383
|
-
(
|
|
384
|
-
t.addBreak(D, B,
|
|
385
|
+
(C = L.breaks) == null || C.forEach((E) => {
|
|
386
|
+
t.addBreak(D, B, E.start, E.end);
|
|
385
387
|
});
|
|
386
388
|
});
|
|
387
389
|
}), t.numberOfLeaders === 0 && ((y = this.readLeaderLineArray(o)) == null || y.forEach((h) => {
|
|
@@ -417,7 +419,7 @@ class V {
|
|
|
417
419
|
z: 0
|
|
418
420
|
}), o.rotation = t.rotationAngle, this.processDimensionCommonAttrs(e, o), o;
|
|
419
421
|
} else if (e.subclassMarker == "AcDb3PointAngularDimension") {
|
|
420
|
-
const t = e, o = new
|
|
422
|
+
const t = e, o = new ge(
|
|
421
423
|
t.centerPoint,
|
|
422
424
|
t.subDefinitionPoint1,
|
|
423
425
|
t.subDefinitionPoint2,
|
|
@@ -425,7 +427,7 @@ class V {
|
|
|
425
427
|
);
|
|
426
428
|
return this.processDimensionCommonAttrs(e, o), o;
|
|
427
429
|
} else if (e.subclassMarker == "AcDbOrdinateDimension") {
|
|
428
|
-
const t = e, o = new
|
|
430
|
+
const t = e, o = new ue(
|
|
429
431
|
t.subDefinitionPoint1,
|
|
430
432
|
t.subDefinitionPoint2
|
|
431
433
|
);
|
|
@@ -469,27 +471,29 @@ class V {
|
|
|
469
471
|
return t.number = e.viewportId, t.centerPoint.copy(e.viewportCenter), t.height = e.height, t.width = e.width, t.viewCenter.copy(e.displayCenter), t.viewHeight = e.viewHeight, t;
|
|
470
472
|
}
|
|
471
473
|
convertRay(e) {
|
|
472
|
-
const t = new
|
|
474
|
+
const t = new Pe();
|
|
473
475
|
return t.basePoint.copy(e.firstPoint), t.unitDir.copy(e.unitDirection), t;
|
|
474
476
|
}
|
|
475
477
|
convertXline(e) {
|
|
476
|
-
const t = new
|
|
478
|
+
const t = new Ie();
|
|
477
479
|
return t.basePoint.copy(e.firstPoint), t.unitDir.copy(e.unitDirection), t;
|
|
478
480
|
}
|
|
479
481
|
convertAttributeCommon(e, t) {
|
|
480
482
|
const o = e.text;
|
|
481
|
-
t.textString = o.text, t.styleName = o.styleName, t.height = o.textHeight, t.position.copy(o.startPoint)
|
|
483
|
+
t.textString = o.text, t.styleName = o.styleName, t.height = o.textHeight, t.position.copy(o.startPoint);
|
|
484
|
+
const n = e.alignmentPoint ?? o.endPoint, r = !n || n.x === 0 && n.y === 0 && (n.z ?? 0) === 0;
|
|
485
|
+
n && !r ? t.alignmentPoint.copy(n) : t.alignmentPoint.copy(o.startPoint), t.rotation = o.rotation, t.oblique = o.obliqueAngle ?? 0, t.thickness = o.thickness, t.horizontalMode = o.halign, t.verticalMode = o.valign, t.widthFactor = o.xScale ?? 1, t.tag = e.tag, t.fieldLength = e.fieldLength, t.isInvisible = (e.flags & P.Invisible) !== 0, t.isConst = (e.flags & P.Const) !== 0, t.isVerifiable = (e.flags & P.Verifiable) !== 0, t.isPreset = (e.flags & P.Preset) !== 0, t.lockPositionInBlock = e.lockPositionFlag, t.isReallyLocked = e.isReallyLocked, t.isMTextAttribute = (e.mtextFlag & O.MultiLine) !== 0, t.isConstMTextAttribute = (e.mtextFlag & O.ConstMultiLine) !== 0;
|
|
482
486
|
}
|
|
483
487
|
convertAttribute(e) {
|
|
484
488
|
const t = new N();
|
|
485
489
|
return this.convertAttributeCommon(e, t), t;
|
|
486
490
|
}
|
|
487
491
|
convertAttributeDefinition(e) {
|
|
488
|
-
const t = new
|
|
492
|
+
const t = new Te();
|
|
489
493
|
return this.convertAttributeCommon(e, t), t.prompt = e.prompt, t;
|
|
490
494
|
}
|
|
491
495
|
convertBlockReference(e) {
|
|
492
|
-
const t = new
|
|
496
|
+
const t = new we(e.name);
|
|
493
497
|
return e.insertionPoint && t.position.copy(e.insertionPoint), t.scaleFactors.x = e.xScale, t.scaleFactors.y = e.yScale, t.scaleFactors.z = e.zScale, t.rotation = e.rotation, t.normal.copy(e.extrusionDirection), e.handle != null && (t.objectId = e.handle), e.attribs && e.attribs.forEach((o) => {
|
|
494
498
|
const n = this.convert(o);
|
|
495
499
|
n instanceof N && t.appendAttributes(n);
|
|
@@ -550,14 +554,14 @@ class V {
|
|
|
550
554
|
}
|
|
551
555
|
}
|
|
552
556
|
const Be = "*MODEL_SPACE";
|
|
553
|
-
class je extends
|
|
557
|
+
class je extends Ce {
|
|
554
558
|
constructor(e = {}) {
|
|
555
559
|
super(e), e.useWorker = !0, e.parserWorkerUrl || (e.parserWorkerUrl = "/assets/libredwg-parser-worker.js");
|
|
556
560
|
}
|
|
557
561
|
async parse(e, t) {
|
|
558
562
|
const o = this.config, n = this.getParserWorkerTimeout(e, t);
|
|
559
563
|
if (o.useWorker && o.parserWorkerUrl) {
|
|
560
|
-
const r =
|
|
564
|
+
const r = Ee({
|
|
561
565
|
workerUrl: o.parserWorkerUrl,
|
|
562
566
|
timeout: n,
|
|
563
567
|
maxConcurrentWorkers: 1
|
|
@@ -623,7 +627,7 @@ class je extends xe {
|
|
|
623
627
|
standardFlag: n.standardFlag,
|
|
624
628
|
totalPatternLength: n.totalPatternLength,
|
|
625
629
|
pattern: n.pattern
|
|
626
|
-
}, i = new
|
|
630
|
+
}, i = new xe(r);
|
|
627
631
|
this.processCommonTableEntryAttrs(n, i), i.name = n.name, t.tables.linetypeTable.add(i);
|
|
628
632
|
});
|
|
629
633
|
}
|
|
@@ -761,13 +765,13 @@ class je extends xe {
|
|
|
761
765
|
const d = t.tables.blockTable.modelSpace;
|
|
762
766
|
await c.processChunk(async (l, f) => {
|
|
763
767
|
const p = [];
|
|
764
|
-
for (let
|
|
765
|
-
const
|
|
768
|
+
for (let g = l; g < f; g++) {
|
|
769
|
+
const u = a[g], y = i.convert(u);
|
|
766
770
|
y && p.push(y);
|
|
767
771
|
}
|
|
768
772
|
if (d.appendEntity(p), r) {
|
|
769
|
-
let
|
|
770
|
-
|
|
773
|
+
let g = n.value + f / s * (100 - n.value);
|
|
774
|
+
g > 100 && (g = 100), await r(g, "ENTITY", "IN-PROGRESS");
|
|
771
775
|
}
|
|
772
776
|
});
|
|
773
777
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(b,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],i):(b=typeof globalThis<"u"?globalThis:b||self,i(b["libredwg-converter"]={},b.dataModel))})(this,function(b,i){"use strict";class T{convert(e){const t=this.createEntity(e);return t&&this.processCommonAttrs(e,t),t}createEntity(e){return e.type=="3DFACE"?this.convertFace(e):e.type=="ARC"?this.convertArc(e):e.type=="ATTDEF"?this.convertAttributeDefinition(e):e.type=="ATTRIB"?this.convertAttribute(e):e.type=="CIRCLE"?this.convertCirle(e):e.type=="DIMENSION"?this.convertDimension(e):e.type=="ELLIPSE"?this.convertEllipse(e):e.type=="HATCH"?this.convertHatch(e):e.type=="IMAGE"?this.convertImage(e):e.type=="LEADER"?this.convertLeader(e):e.type=="LINE"?this.convertLine(e):e.type=="LWPOLYLINE"?this.convertLWPolyline(e):e.type=="MLINE"?this.convertMLine(e):e.type=="MTEXT"?this.convertMText(e):e.type=="MULTILEADER"||e.type=="MLEADER"?this.convertMLeader(e):e.type=="POINT"?this.convertPoint(e):e.type=="POLYLINE2D"?this.convertPolyline2d(e):e.type=="POLYLINE3D"?this.convertPolyline3d(e):e.type=="RAY"?this.convertRay(e):e.type=="SPLINE"?this.convertSpline(e):e.type=="ACAD_TABLE"?this.convertTable(e):e.type=="TEXT"?this.convertText(e):e.type=="SOLID"?this.convertSolid(e):e.type=="VIEWPORT"?this.convertViewport(e):e.type=="WIPEOUT"?this.convertWipeout(e):e.type=="XLINE"?this.convertXline(e):e.type=="INSERT"?this.convertBlockReference(e):null}convertFace(e){const t=new i.AcDbFace;return e.corner1&&t.setVertexAt(0,e.corner1),e.corner2&&t.setVertexAt(1,e.corner2),e.corner3&&t.setVertexAt(2,e.corner3),e.corner4&&t.setVertexAt(3,e.corner4),t.setEdgeInvisibilities(e.flag),t}convertArc(e){const t=e.extrusionDirection??i.AcGeVector3d.Z_AXIS;return new i.AcDbArc(i.transformOcsPointToWcs(e.center,t),e.radius,e.startAngle,e.endAngle,t)}convertCirle(e){const t=e.extrusionDirection??i.AcGeVector3d.Z_AXIS;return new i.AcDbCircle(i.transformOcsPointToWcs(e.center,t),e.radius,t)}convertEllipse(e){const t=new i.AcGeVector3d(e.majorAxisEndPoint),o=t.length();return new i.AcDbEllipse(e.center,e.extrusionDirection??i.AcGeVector3d.Z_AXIS,t,o,o*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const t=e.startPoint,o=e.endPoint;return new i.AcDbLine(new i.AcGePoint3d(t.x,t.y,t.z),new i.AcGePoint3d(o.x,o.y,o.z))}convertSpline(e){try{if(e.numberOfControlPoints>0&&e.numberOfKnots>0)return new i.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1));if(e.numberOfFitPoints>0)return new i.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1))}catch{}return null}convertPoint(e){const t=new i.AcDbPoint;return t.position=e.position,t}convertSolid(e){const t=new i.AcDbTrace;return t.setPointAt(0,{...e.corner1,z:0}),t.setPointAt(1,{...e.corner2,z:0}),t.setPointAt(2,{...e.corner3,z:0}),t.setPointAt(3,e.corner4?{...e.corner4,z:0}:{...e.corner3,z:0}),t.thickness=e.thickness,t}convertLWPolyline(e){const t=new i.AcDbPolyline;t.closed=!!(e.flag&512);const o=e.constantWidth??-1;return e.vertices.forEach((n,r)=>{t.addVertexAt(r,new i.AcGePoint2d(n.x,n.y),n.bulge,n.startWidth??o,n.endWidth??o)}),t}convertPolyline2d(e){const t=!!(e.flag&1),o=!!(e.flag&16),n=!!(e.flag&64),r=!!(e.flag&32),s=[],a=[],c=[];if(e.vertices.map(l=>{if(!(l.flag&16))if(n&&l.flag&128)if(l.flag&64)s.push({x:l.x,y:l.y,z:l.z}),a.push(l.bulge??0);else{const p=[];l.polyfaceIndex0!=null&&l.polyfaceIndex0!=0&&p.push(Math.abs(l.polyfaceIndex0)-1),l.polyfaceIndex1!=null&&l.polyfaceIndex1!=0&&p.push(Math.abs(l.polyfaceIndex1)-1),l.polyfaceIndex2!=null&&l.polyfaceIndex2!=0&&p.push(Math.abs(l.polyfaceIndex2)-1),l.polyfaceIndex3!=null&&l.polyfaceIndex3!=0&&p.push(Math.abs(l.polyfaceIndex3)-1),p.length>=3&&c.push(p)}else s.push({x:l.x,y:l.y,z:l.z}),a.push(l.bulge??0)}),o){const l=e.meshMVertexCount??2,p=e.meshNVertexCount??2;return new i.AcDbPolygonMesh(l,p,s,t,r)}else{if(n)return new i.AcDbPolyFaceMesh(s,c);{let l=i.AcDbPoly2dType.SimplePoly;return e.flag&2?l=i.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?l=i.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(l=i.AcDbPoly2dType.QuadSplinePoly)),new i.AcDb2dPolyline(l,s,0,t,e.startWidth,e.endWidth,a)}}}convertPolyline3d(e){const t=!!(e.flag&1),o=[];e.vertices.map(r=>{r.flag&16||o.push({x:r.x,y:r.y,z:r.z})});let n=i.AcDbPoly3dType.SimplePoly;return e.flag&4&&(e.smoothType==6?n=i.AcDbPoly3dType.CubicSplinePoly:e.smoothType==5&&(n=i.AcDbPoly3dType.QuadSplinePoly)),new i.AcDb3dPolyline(n,o,t)}convertHatch(e){var n;const t=new i.AcDbHatch;if((n=e.definitionLines)==null||n.forEach(r=>{t.definitionLines.push({angle:r.angle,base:r.base,offset:r.offset,dashLengths:r.numberOfDashLengths>0?r.dashLengths:[]})}),t.isSolidFill=e.solidFill==1,t.hatchStyle=e.hatchStyle,t.patternName=e.patternName,t.patternType=e.patternType,t.patternAngle=e.patternAngle==null?0:e.patternAngle,t.patternScale=e.patternScale==null?0:e.patternScale,e.boundaryPaths.forEach(r=>{if(r.boundaryPathTypeFlag&2){const a=r,c=new i.AcGePolyline2d;c.closed=a.isClosed,a.vertices.forEach((l,p)=>{c.addVertexAt(p,{x:l.x,y:l.y,bulge:l.bulge})}),t.add(c)}else{const a=r,c=[];a.edges.forEach(p=>{if(p!=null){if(p.type==1){const f=p;c.push(new i.AcGeLine2d(f.start,f.end))}else if(p.type==2){const f=p;c.push(new i.AcGeCircArc2d(f.center,f.radius,f.startAngle,f.endAngle,!f.isCCW))}else if(p.type==3){const f=p;new i.AcGeVector2d().subVectors(f.end,f.center);const g=Math.sqrt(Math.pow(f.end.x,2)+Math.pow(f.end.y,2)),d=g*f.lengthOfMinorAxis;let h=f.startAngle,A=f.endAngle;const D=Math.atan2(f.end.y,f.end.x);f.isCCW||(h=Math.PI*2-h,A=Math.PI*2-A),c.push(new i.AcGeEllipseArc2d({...f.center,z:0},g,d,h,A,!f.isCCW,D))}else if(p.type==4){const f=p;if(f.numberOfControlPoints>0&&f.numberOfKnots>0){const u=f.controlPoints.map(h=>({x:h.x,y:h.y,z:0}));let g=!0;const d=f.controlPoints.map(h=>(h.weight==null&&(g=!1),h.weight||1));c.push(new i.AcGeSpline3d(u,f.knots,g?d:void 0))}else if(f.numberOfFitData>0){const u=f.fitDatum.map(g=>({x:g.x,y:g.y,z:0}));c.push(new i.AcGeSpline3d(u,"Uniform"))}}}});const l=i.AcGeLoop2d.buildFromEdges(c);l.length==0&&c.length>0?t.add(new i.AcGeLoop2d(c)):l.forEach(p=>t.add(p))}}),e.gradientFlag){const r=e;if(t.hatchObjectType=i.AcDbHatchObjectType.GradientObject,t.gradientName=r.gradientName,t.gradientAngle=r.gradientRotation??0,t.gradientShift=r.gradientDefinition??0,t.gradientOneColorMode=r.gradientColorFlag==1,t.shadeTintValue=r.colorTint??0,r.gradientColors){const s=r.gradientColors.length;s>1?(t.gradientStartColor=r.gradientColors[0].rgb,t.gradientEndColor=r.gradientColors[1].rgb):s>0&&(t.gradientStartColor=r.gradientColors[0].rgb)}}return t}convertTable(e){const t=new i.AcDbTable(e.name,e.rowCount,e.columnCount);return t.tableStyleId=e.tableStyleId,t.owningBlockRecordId=e.blockRecordHandle,e.directionVector&&(t.horizontalDirection=new i.AcGeVector3d(e.directionVector)),t.attachmentPoint=e.attachmentPoint,t.position.copy(e.startPoint),t.tableValueFlag=e.tableValue,t.tableOverrideFlag=e.overrideFlag,t.borderColorOverrideFlag=e.borderColorOverrideFlag,t.borderLineweightOverrideFlag=e.borderLineWeightOverrideFlag,t.borderVisibilityOverrideFlag=e.borderVisibilityOverrideFlag,e.columnWidthArr.forEach((o,n)=>t.setColumnWidth(n,o)),e.rowHeightArr.forEach((o,n)=>t.setRowHeight(n,o)),e.cells.forEach((o,n)=>{t.setCell(n,o)}),t}convertText(e){const t=new i.AcDbText;return t.textString=e.text,t.styleName=e.styleName,t.height=e.textHeight,t.position.copy(e.startPoint),t.rotation=e.rotation,t.oblique=e.obliqueAngle??0,t.thickness=e.thickness,t.horizontalMode=e.halign,t.verticalMode=e.valign,t.widthFactor=e.xScale??1,t}convertMText(e){const t=new i.AcDbMText;return t.contents=e.text,e.styleName!=null&&(t.styleName=e.styleName),t.height=e.textHeight,t.width=e.rectWidth,t.rotation=e.rotation||0,t.location=e.insertionPoint,t.attachmentPoint=e.attachmentPoint,e.direction&&(t.direction=new i.AcGeVector3d(e.direction)),t.drawingDirection=e.drawingDirection,t}convertLeader(e){const t=new i.AcDbLeader;return e.vertices.forEach(o=>{t.appendVertex(o)}),t.hasArrowHead=e.isArrowheadEnabled,t.hasHookLine=e.isHooklineExists,t.isSplined=e.isSpline,t.dimensionStyle=e.styleName,t.annoType=e.leaderCreationFlag,t}convertMLine(e){const t=new i.AcDbMLine;return t.styleName=e.mlineStyle||"STANDARD",t.scale=e.scale,t.flags=e.flags,t.justification=e.justification,t.startPosition=e.startPoint,t.normal=e.extrusionDirection??i.AcGeVector3d.Z_AXIS,t.styleCount=e.numberOfLines??0,t.segments=(e.vertices??[]).map(o=>({position:o.vertex,direction:o.vertexDirection,miterDirection:o.miterDirection,elements:(o.lines??[]).map(n=>({parameterCount:n.numberOfSegmentParams,parameters:n.segmentParams??[],fillCount:n.numberOfAreaFillParams,fillParameters:n.areaFillParams??[]}))})),t}convertMLeader(e){var g,d,h,A;const t=new i.AcDbMLeader,o=e;t.leaderLineType=this.readNumber(o,["multileaderType","leaderLineType","leaderType"])??i.AcDbMLeaderLineType.StraightLeader;const n=this.readNumber(o,["contentType"])??(e.textContent?i.AcDbMLeaderContentType.MTextContent:e.blockContent?i.AcDbMLeaderContentType.BlockContent:i.AcDbMLeaderContentType.NoneContent);t.contentType=n,t.doglegEnabled=this.readBoolean(o,["doglegEnabled","enableDogleg"])??!1,t.doglegLength=this.readNumber(o,["doglegLength"])??0,e.landingPoint&&(t.landingPoint=e.landingPoint),e.doglegVector&&(t.doglegVector=e.doglegVector);const r=this.readString(o,["mleaderStyleId","mLeaderStyleId","mleaderStyleHandle","styleHandle","styleName"]);r&&(t.mleaderStyleId=r);const s=this.readPoint(o,["normal","extrusionDirection"]);s&&(t.normal=s);const a=e.textContent,c=this.readString(a??{},["styleName","textStyleName"])??this.readString(o,["textStyleName","textStyle","styleName"]);c&&(t.textStyleName=c),t.textHeight=this.readNumber(a??{},["textHeight","height"])??this.readNumber(o,["textHeight","mtextHeight","textContentHeight"])??t.textHeight,t.textWidth=this.readNumber(a??{},["textWidth","width"])??this.readNumber(o,["textWidth","mtextWidth","textContentWidth"])??t.textWidth;const l=this.readNumber(a??{},["textRotation","rotation"])??this.readNumber(o,["textRotation","mtextRotation","textContentRotation"]);l!=null&&(t.textRotation=l);const p=this.readPoint(o,["textDirection","mtextDirection","textDirectionVector"]);p&&(t.textDirection=p);const f=this.readNumber(o,["textAttachmentPoint","attachmentPoint"]);f!=null&&(t.textAttachmentPoint=f);const u=this.readNumber(o,["textDrawingDirection","drawingDirection"]);if(u!=null&&(t.textDrawingDirection=u),((g=e.textContent)==null?void 0:g.text)!=null&&e.textContent.anchorPoint)t.mtextContent={text:e.textContent.text,anchorPoint:e.textContent.anchorPoint};else{const D=this.readString(o,["text","contents","mtext"]),y=this.readPoint(o,["textLocation","textPosition","textAnchorPoint"]);D!=null&&y&&(t.mtextContent={text:D,anchorPoint:y})}if((d=e.blockContent)!=null&&d.blockHandle&&e.blockContent.position)t.blockContent={blockHandle:e.blockContent.blockHandle,position:e.blockContent.position};else{const D=this.readString(o,["blockHandle","blockContentHandle","blockId"]),y=this.readPoint(o,["blockPosition","blockContentPosition"]);D&&y&&(t.blockContent={blockHandle:D,position:y})}return(h=e.leaders)==null||h.forEach(D=>{var I;const y=t.addLeader({landingPoint:D.landingPoint??e.landingPoint,doglegVector:D.doglegVector??e.doglegVector,doglegLength:D.doglegLength??e.doglegLength});(I=D.leaderLines)==null||I.forEach(P=>{var w;const S=t.addLeaderLine(y,P.vertices??[]);(w=P.breaks)==null||w.forEach(L=>{t.addBreak(y,S,L.start,L.end)})})}),t.numberOfLeaders===0&&((A=this.readLeaderLineArray(o))==null||A.forEach(D=>{const y=t.addLeader({landingPoint:e.landingPoint,doglegVector:e.doglegVector,doglegLength:e.doglegLength});t.addLeaderLine(y,D)})),t}convertDimension(e){if(e.subclassMarker=="AcDbAlignedDimension"){const t=e,o=new i.AcDbAlignedDimension(t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return t.insertionPoint&&(o.dimBlockPosition={x:t.insertionPoint.x,y:t.insertionPoint.y,z:0}),o.rotation=t.rotationAngle,this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbRotatedDimension"){const t=e,o=new i.AcDbRotatedDimension(t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return t.insertionPoint&&(o.dimBlockPosition={x:t.insertionPoint.x,y:t.insertionPoint.y,z:0}),o.rotation=t.rotationAngle,this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const t=e,o=new i.AcDb3PointAngularDimension(t.centerPoint,t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbOrdinateDimension"){const t=e,o=new i.AcDbOrdinateDimension(t.subDefinitionPoint1,t.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbRadialDimension"){const t=e,o=new i.AcDbRadialDimension(t.definitionPoint,t.centerPoint,t.leaderLength);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbDiametricDimension"){const t=e,o=new i.AcDbDiametricDimension(t.definitionPoint,t.centerPoint,t.leaderLength);return this.processDimensionCommonAttrs(e,o),o}return null}processImage(e,t){t.position.copy(e.position),t.brightness=e.brightness,t.contrast=e.contrast,t.fade=e.fade,t.imageSize.copy(e.imageSize),t.imageDefId=e.imageDefHandle,t.isClipped=e.clipping>0,t.isShownClipped=(e.flags|4)>0,t.isImageShown=(e.flags|3)>0,t.isImageTransparent=(e.flags|8)>0,e.clippingBoundaryPath.forEach(o=>{t.clipBoundary.push(new i.AcGePoint2d(o))}),t.clipBoundaryType=e.clippingBoundaryType,t.width=Math.sqrt(e.uPixel.x**2+e.uPixel.y**2+e.uPixel.z**2)*e.imageSize.x,t.height=Math.sqrt(e.vPixel.x**2+e.vPixel.y**2+e.vPixel.z**2)*e.imageSize.y,t.rotation=Math.atan2(e.uPixel.y,e.uPixel.x)}convertImage(e){const t=new i.AcDbRasterImage;return this.processImage(e,t),t}convertWipeout(e){const t=new i.AcDbWipeout;return this.processImage(e,t),t}convertViewport(e){const t=new i.AcDbViewport;return t.number=e.viewportId,t.centerPoint.copy(e.viewportCenter),t.height=e.height,t.width=e.width,t.viewCenter.copy(e.displayCenter),t.viewHeight=e.viewHeight,t}convertRay(e){const t=new i.AcDbRay;return t.basePoint.copy(e.firstPoint),t.unitDir.copy(e.unitDirection),t}convertXline(e){const t=new i.AcDbXline;return t.basePoint.copy(e.firstPoint),t.unitDir.copy(e.unitDirection),t}convertAttributeCommon(e,t){const o=e.text;t.textString=o.text,t.styleName=o.styleName,t.height=o.textHeight,t.position.copy(o.startPoint),t.rotation=o.rotation,t.oblique=o.obliqueAngle??0,t.thickness=o.thickness,t.horizontalMode=o.halign,t.verticalMode=o.valign,t.widthFactor=o.xScale??1,t.tag=e.tag,t.fieldLength=e.fieldLength,t.isInvisible=(e.flags&i.AcDbAttributeFlags.Invisible)!==0,t.isConst=(e.flags&i.AcDbAttributeFlags.Const)!==0,t.isVerifiable=(e.flags&i.AcDbAttributeFlags.Verifiable)!==0,t.isPreset=(e.flags&i.AcDbAttributeFlags.Preset)!==0,t.lockPositionInBlock=e.lockPositionFlag,t.isReallyLocked=e.isReallyLocked,t.isMTextAttribute=(e.mtextFlag&i.AcDbAttributeMTextFlag.MultiLine)!==0,t.isConstMTextAttribute=(e.mtextFlag&i.AcDbAttributeMTextFlag.ConstMultiLine)!==0}convertAttribute(e){const t=new i.AcDbAttribute;return this.convertAttributeCommon(e,t),t}convertAttributeDefinition(e){const t=new i.AcDbAttributeDefinition;return this.convertAttributeCommon(e,t),t.prompt=e.prompt,t}convertBlockReference(e){const t=new i.AcDbBlockReference(e.name);return e.insertionPoint&&t.position.copy(e.insertionPoint),t.scaleFactors.x=e.xScale,t.scaleFactors.y=e.yScale,t.scaleFactors.z=e.zScale,t.rotation=e.rotation,t.normal.copy(e.extrusionDirection),e.handle!=null&&(t.objectId=e.handle),e.attribs&&e.attribs.forEach(o=>{const n=this.convert(o);n instanceof i.AcDbAttribute&&t.appendAttributes(n)}),t}processDimensionCommonAttrs(e,t){t.dimBlockId=e.name,t.textPosition.copy(e.textPoint),t.textRotation=e.textRotation||0,e.textLineSpacingFactor&&(t.textLineSpacingFactor=e.textLineSpacingFactor),e.textLineSpacingStyle&&(t.textLineSpacingStyle=e.textLineSpacingStyle),t.dimensionStyleName=e.styleName,t.dimensionText=e.text||"",t.measurement=e.measurement}processCommonAttrs(e,t){if(t.layer=e.layer||"0",t.objectId=e.handle,e.ownerBlockRecordSoftId!=null&&(t.ownerId=e.ownerBlockRecordSoftId),e.lineType!=null&&(t.lineType=e.lineType),e.lineweight!=null&&(t.lineWeight=e.lineweight),e.lineTypeScale!=null&&(t.linetypeScale=e.lineTypeScale),e.color!=null&&t.color.setRGBValue(e.color),e.colorIndex!=null&&(e.color==null||e.colorIndex===7)&&(t.color.colorIndex=e.colorIndex),e.colorName&&(t.color.colorName=e.colorName),e.isVisible!=null&&(t.visibility=e.isVisible),e.transparency!=null){const o=new i.AcCmTransparency;o.method=e.transparencyType,(o.isByBlock||o.isByBlock)&&(o.alpha=e.transparency),t.transparency=o}}readNumber(e,t){for(const o of t){const n=e[o];if(typeof n=="number"&&Number.isFinite(n))return n}}readString(e,t){for(const o of t){const n=e[o];if(typeof n=="string")return n}}readBoolean(e,t){for(const o of t){const n=e[o];if(typeof n=="boolean")return n;if(typeof n=="number")return n!==0}}readPoint(e,t){for(const o of t){const n=e[o];if(this.isPointLike(n))return n;if(Array.isArray(n)&&typeof n[0]=="number"&&typeof n[1]=="number")return{x:n[0],y:n[1],z:n[2]??0}}}readLeaderLineArray(e){const t=e.leaderLines;if(Array.isArray(t))return t.map(n=>{if(!n||typeof n!="object")return;const r=n.vertices;return Array.isArray(r)?r.filter(s=>this.isPointLike(s)):void 0}).filter(n=>!!n&&n.length>0);const o=e.vertices;if(Array.isArray(o)){const n=o.filter(r=>this.isPointLike(r));return n.length>0?[n]:void 0}}isPointLike(e){return!!e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}}const x="*MODEL_SPACE";class C extends i.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e,t){const o=this.config,n=this.getParserWorkerTimeout(e,t);if(o.useWorker&&o.parserWorkerUrl){const r=i.createWorkerApi({workerUrl:o.parserWorkerUrl,timeout:n,maxConcurrentWorkers:1}),s=await r.execute(e);if(r.destroy(),s.success)return s.data;throw new Error(`Failed to parse drawing due to error: '${s.error}'`)}else throw new Error("dwg converter can run in web worker only!")}getFonts(e){const t=new Map;e.tables.BLOCK_RECORD.entries.forEach(s=>{t.set(s.name,s)});const o=new Map,n=s=>{if(s){const a=s.lastIndexOf(".");return a>=0?s.substring(0,a).toLowerCase():s.toLowerCase()}};e.tables.STYLE.entries.forEach(s=>{const a=[];let c=n(s.font);c&&a.push(c),c=n(s.bigFont),c&&a.push(c),o.set(s.name,a)});const r=new Set;return this.getFontsInBlock(e.entities,t,o,r),Array.from(r)}getFontsInBlock(e,t,o,n){const r=/\\f(.*?)\|/g;e.forEach(s=>{if(s.type=="MTEXT"){const a=s;[...a.text.matchAll(r)].forEach(l=>{n.add(l[1].toLowerCase())});const c=o.get(a.styleName);c==null||c.forEach(l=>n.add(l))}else if(s.type=="TEXT"){const a=s,c=o.get(a.styleName);c==null||c.forEach(l=>n.add(l))}else if(s.type=="MULTILEADER"||s.type=="MLEADER"){const a=s,c=a.textContent;[...(typeof(c==null?void 0:c.text)=="string"?c.text:"").matchAll(r)].forEach(u=>{n.add(u[1].toLowerCase())});const p=typeof(c==null?void 0:c.styleName)=="string"?c.styleName:typeof a.textStyleName=="string"?a.textStyleName:typeof a.styleName=="string"?a.styleName:void 0,f=p?o.get(p):void 0;f==null||f.forEach(u=>n.add(u))}else if(s.type=="INSERT"){const a=s,c=t.get(a.name);c&&this.getFontsInBlock(c.entities,t,o,n)}})}processLineTypes(e,t){e.tables.LTYPE.entries.forEach(n=>{const r={name:n.name,description:n.description,standardFlag:n.standardFlag,totalPatternLength:n.totalPatternLength,pattern:n.pattern},s=new i.AcDbLinetypeTableRecord(r);this.processCommonTableEntryAttrs(n,s),s.name=n.name,t.tables.linetypeTable.add(s)})}processTextStyles(e,t){e.tables.STYLE.entries.forEach(n=>{const r=new i.AcDbTextStyleTableRecord(n);this.processCommonTableEntryAttrs(n,r),t.tables.textStyleTable.add(r)})}processDimStyles(e,t){e.tables.DIMSTYLE.entries.forEach(n=>{const r={name:n.name,ownerId:n.ownerHandle,dimpost:n.DIMPOST||"",dimapost:n.DIMAPOST||"",dimscale:n.DIMSCALE,dimasz:n.DIMASZ,dimexo:n.DIMEXO,dimdli:n.DIMDLI,dimexe:n.DIMEXE,dimrnd:n.DIMRND,dimdle:n.DIMDLE,dimtp:n.DIMTP,dimtm:n.DIMTM,dimtxt:n.DIMTXT,dimcen:n.DIMCEN,dimtsz:n.DIMTSZ,dimaltf:n.DIMALTF,dimlfac:n.DIMLFAC,dimtvp:n.DIMTVP,dimtfac:n.DIMTFAC,dimgap:n.DIMGAP,dimaltrnd:n.DIMALTRND,dimtol:n.DIMTOL==null||n.DIMTOL==0?0:1,dimlim:n.DIMLIM==null||n.DIMLIM==0?0:1,dimtih:n.DIMTIH==null||n.DIMTIH==0?0:1,dimtoh:n.DIMTOH==null||n.DIMTOH==0?0:1,dimse1:n.DIMSE1==null||n.DIMSE1==0?0:1,dimse2:n.DIMSE2==null||n.DIMSE2==0?0:1,dimtad:n.DIMTAD,dimzin:n.DIMZIN,dimazin:n.DIMAZIN,dimalt:n.DIMALT,dimaltd:n.DIMALTD,dimtofl:n.DIMTOFL,dimsah:n.DIMSAH,dimtix:n.DIMTIX,dimsoxd:n.DIMSOXD,dimclrd:n.DIMCLRD,dimclre:n.DIMCLRE,dimclrt:n.DIMCLRT,dimadec:n.DIMADEC||0,dimunit:n.DIMUNIT||2,dimdec:n.DIMDEC,dimtdec:n.DIMTDEC,dimaltu:n.DIMALTU,dimalttd:n.DIMALTTD,dimaunit:n.DIMAUNIT,dimfrac:n.DIMFRAC,dimlunit:n.DIMLUNIT,dimdsep:n.DIMDSEP||".",dimtmove:n.DIMTMOVE||0,dimjust:n.DIMJUST,dimsd1:n.DIMSD1,dimsd2:n.DIMSD2,dimtolj:n.DIMTOLJ,dimtzin:n.DIMTZIN,dimaltz:n.DIMALTZ,dimalttz:n.DIMALTTZ,dimfit:n.DIMFIT||0,dimupt:n.DIMUPT,dimatfit:n.DIMATFIT,dimtxsty:i.DEFAULT_TEXT_STYLE,dimldrblk:"",dimblk:n.DIMBLK||"",dimblk1:n.DIMBLK1||"",dimblk2:n.DIMBLK2||"",dimlwd:n.DIMLWD,dimlwe:n.DIMLWE},s=new i.AcDbDimStyleTableRecord(r);this.processCommonTableEntryAttrs(n,s),t.tables.dimStyleTable.add(s)})}processLayers(e,t){e.tables.LAYER.entries.forEach(n=>{const r=new i.AcCmColor;r.colorIndex=n.colorIndex;const s=new i.AcDbLayerTableRecord({name:n.name,standardFlags:n.standardFlag,linetype:n.lineType,lineWeight:n.lineweight,isOff:n.off,color:r,isPlottable:n.plotFlag!=0});this.processCommonTableEntryAttrs(n,s),t.tables.layerTable.add(s)})}processViewports(e,t){e.tables.VPORT.entries.forEach(n=>{const r=new i.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(n,r),n.circleSides&&(r.circleSides=n.circleSides),r.standardFlag=n.standardFlag,r.center.copy(n.center),r.lowerLeftCorner.copy(n.lowerLeftCorner),r.upperRightCorner.copy(n.upperRightCorner),n.snapBasePoint&&r.snapBase.copy(n.snapBasePoint),n.snapRotationAngle&&(r.snapAngle=n.snapRotationAngle),n.snapSpacing&&r.snapIncrements.copy(n.snapSpacing),n.majorGridLines&&(r.gridMajor=n.majorGridLines),n.gridSpacing&&r.gridIncrements.copy(n.gridSpacing),n.backgroundObjectId&&(r.backgroundObjectId=n.backgroundObjectId),r.gsView.center.copy(n.center),r.gsView.viewDirectionFromTarget.copy(n.viewDirectionFromTarget),r.gsView.viewTarget.copy(n.viewTarget),n.lensLength&&(r.gsView.lensLength=n.lensLength),n.frontClippingPlane&&(r.gsView.frontClippingPlane=n.frontClippingPlane),n.backClippingPlane&&(r.gsView.backClippingPlane=n.backClippingPlane),n.viewHeight&&(r.gsView.viewHeight=n.viewHeight),n.viewTwistAngle&&(r.gsView.viewTwistAngle=n.viewTwistAngle),n.frozenLayers&&(r.gsView.frozenLayers=n.frozenLayers),n.styleSheet&&(r.gsView.styleSheet=n.styleSheet),n.renderMode&&(r.gsView.renderMode=n.renderMode),n.viewMode&&(r.gsView.viewMode=n.viewMode),n.ucsIconSetting&&(r.gsView.ucsIconSetting=n.ucsIconSetting),n.ucsOrigin&&r.gsView.ucsOrigin.copy(n.ucsOrigin),n.ucsXAxis&&r.gsView.ucsXAxis.copy(n.ucsXAxis),n.ucsYAxis&&r.gsView.ucsYAxis.copy(n.ucsYAxis),n.orthographicType&&(r.gsView.orthographicType=n.orthographicType),n.shadePlotSetting&&(r.gsView.shadePlotSetting=n.shadePlotSetting),n.shadePlotObjectId&&(r.gsView.shadePlotObjectId=n.shadePlotObjectId),n.visualStyleObjectId&&(r.gsView.visualStyleObjectId=n.visualStyleObjectId),n.isDefaultLightingOn&&(r.gsView.isDefaultLightingOn=n.isDefaultLightingOn),n.defaultLightingType&&(r.gsView.defaultLightingType=n.defaultLightingType),n.brightness&&(r.gsView.brightness=n.brightness),n.contrast&&(r.gsView.contrast=n.contrast),n.ambientColor&&(r.gsView.ambientColor=n.ambientColor),t.tables.viewportTable.add(r)})}processBlockTables(e,t){e.tables.BLOCK_RECORD.entries.forEach(n=>{let r=t.tables.blockTable.getAt(n.name);r||(r=new i.AcDbBlockTableRecord,r.objectId=n.handle,r.name=n.name,r.ownerId=n.ownerHandle,r.origin.copy(n.basePoint),r.layoutId=n.layout,r.blockInsertUnits=n.insertionUnits,r.explodability=n.explodability,r.blockScaling=n.scalability,n.bmpPreview&&(r.bmpPreview=n.bmpPreview),t.tables.blockTable.add(r)),!r.isModelSapce&&n.entities&&n.entities.length>0&&this.processEntitiesInBlock(n.entities,r)})}processBlocks(e,t){}async processEntitiesInBlock(e,t){const o=new T,n=e.length,r=[];for(let s=0;s<n;s++){const a=e[s],c=o.convert(a);c&&r.push(c)}t.appendEntity(r)}async processEntities(e,t,o,n,r){const s=new T;let a=[];e.tables.BLOCK_RECORD.entries.forEach(f=>{this.isModelSpace(f.name)&&(a=f.entities)});const c=a.length,l=new i.AcDbBatchProcessing(c,100-n.value,o);this.config.convertByEntityType&&(a=this.groupAndFlattenByType(a));const p=t.tables.blockTable.modelSpace;await l.processChunk(async(f,u)=>{const g=[];for(let d=f;d<u;d++){const h=a[d],A=s.convert(h);A&&g.push(A)}if(p.appendEntity(g),r){let d=n.value+u/c*(100-n.value);d>100&&(d=100),await r(d,"ENTITY","IN-PROGRESS")}})}processHeader(e,t){const o=e.header;o.CECOLOR&&(o.CECOLOR.index>=0&&o.CECOLOR.index<=256?t.cecolor.colorIndex=o.CECOLOR.index:t.cecolor.setRGBValue(o.CECOLOR.rgb)),t.angBase=o.ANGBASE??0,t.angDir=o.ANGDIR??0,t.aunits=o.AUNITS??0,t.celtype=o.CELTYPE??i.ByLayer,t.celtscale=o.CELTSCALE??1,t.ltscale=o.LTSCALE??1,o.EXTMAX&&(t.extmax=o.EXTMAX),o.EXTMIN&&(t.extmin=o.EXTMIN),t.insunits=o.INSUNITS??1,t.pdmode=o.PDMODE??0,t.pdsize=o.PDSIZE??0,t.textstyle=o.TEXTSTYLE??i.DEFAULT_TEXT_STYLE}processCommonTableEntryAttrs(e,t){t.name=e.name,t.objectId=e.handle,e.ownerHandle!=null&&(t.ownerId=e.ownerHandle)}processObjects(e,t){this.processLayouts(e,t),this.processImageDefs(e,t)}processLayouts(e,t){const o=t.objects.layout;e.objects.LAYOUT.forEach(r=>{const s=new i.AcDbLayout;s.layoutName=r.layoutName,s.tabOrder=r.tabOrder;const a=t.tables.blockTable.newIterator();s.objectId=r.handle;for(const c of a)if(c.layoutId===s.objectId){s.blockTableRecordId=c.objectId;break}s.blockTableRecordId||r.layoutName==="Model"&&(s.blockTableRecordId=t.tables.blockTable.modelSpace.objectId),s.limits.min.copy(r.minLimit),s.limits.max.copy(r.maxLimit),s.extents.min.copy(r.minExtent),s.extents.max.copy(r.maxExtent),r.viewportId&&s.viewportArray.push(r.viewportId),this.processCommonObjectAttrs(r,s),o.setAt(s.layoutName,s)})}processImageDefs(e,t){const o=t.objects.imageDefinition;e.objects.IMAGEDEF.forEach(r=>{const s=new i.AcDbRasterImageDef;s.sourceFileName=r.fileName,this.processCommonObjectAttrs(r,s),o.setAt(s.objectId,s)})}processCommonObjectAttrs(e,t){t.objectId=e.handle,e.ownerHandle!=null&&(t.ownerId=e.ownerHandle)}groupAndFlattenByType(e){const t={},o=[];for(const n of e)t[n.type]||(t[n.type]=[],o.push(n.type)),t[n.type].push(n);return o.flatMap(n=>t[n])}isModelSpace(e){return e&&e.toUpperCase()==x}}b.AcDbLibreDwgConverter=C,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(b,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],r):(b=typeof globalThis<"u"?globalThis:b||self,r(b["libredwg-converter"]={},b.dataModel))})(this,function(b,r){"use strict";class P{convert(e){const n=this.createEntity(e);return n&&this.processCommonAttrs(e,n),n}createEntity(e){return e.type=="3DFACE"?this.convertFace(e):e.type=="ARC"?this.convertArc(e):e.type=="ATTDEF"?this.convertAttributeDefinition(e):e.type=="ATTRIB"?this.convertAttribute(e):e.type=="CIRCLE"?this.convertCirle(e):e.type=="DIMENSION"?this.convertDimension(e):e.type=="ELLIPSE"?this.convertEllipse(e):e.type=="HATCH"?this.convertHatch(e):e.type=="IMAGE"?this.convertImage(e):e.type=="LEADER"?this.convertLeader(e):e.type=="LINE"?this.convertLine(e):e.type=="LWPOLYLINE"?this.convertLWPolyline(e):e.type=="MLINE"?this.convertMLine(e):e.type=="MTEXT"?this.convertMText(e):e.type=="MULTILEADER"||e.type=="MLEADER"?this.convertMLeader(e):e.type=="POINT"?this.convertPoint(e):e.type=="POLYLINE2D"?this.convertPolyline2d(e):e.type=="POLYLINE3D"?this.convertPolyline3d(e):e.type=="RAY"?this.convertRay(e):e.type=="SPLINE"?this.convertSpline(e):e.type=="ACAD_TABLE"?this.convertTable(e):e.type=="TEXT"?this.convertText(e):e.type=="SOLID"?this.convertSolid(e):e.type=="VIEWPORT"?this.convertViewport(e):e.type=="WIPEOUT"?this.convertWipeout(e):e.type=="XLINE"?this.convertXline(e):e.type=="INSERT"?this.convertBlockReference(e):null}convertFace(e){const n=new r.AcDbFace;return e.corner1&&n.setVertexAt(0,e.corner1),e.corner2&&n.setVertexAt(1,e.corner2),e.corner3&&n.setVertexAt(2,e.corner3),e.corner4&&n.setVertexAt(3,e.corner4),n.setEdgeInvisibilities(e.flag),n}convertArc(e){const n=e.extrusionDirection??r.AcGeVector3d.Z_AXIS;return new r.AcDbArc(r.transformOcsPointToWcs(e.center,n),e.radius,e.startAngle,e.endAngle,n)}convertCirle(e){const n=e.extrusionDirection??r.AcGeVector3d.Z_AXIS;return new r.AcDbCircle(r.transformOcsPointToWcs(e.center,n),e.radius,n)}convertEllipse(e){const n=new r.AcGeVector3d(e.majorAxisEndPoint),o=n.length();return new r.AcDbEllipse(e.center,e.extrusionDirection??r.AcGeVector3d.Z_AXIS,n,o,o*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const n=e.startPoint,o=e.endPoint;return new r.AcDbLine(new r.AcGePoint3d(n.x,n.y,n.z),new r.AcGePoint3d(o.x,o.y,o.z))}convertSpline(e){try{if(e.numberOfControlPoints>0&&e.numberOfKnots>0)return new r.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1));if(e.numberOfFitPoints>0)return new r.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1))}catch{}return null}convertPoint(e){const n=new r.AcDbPoint;return n.position=e.position,n}convertSolid(e){const n=new r.AcDbTrace;return n.setPointAt(0,{...e.corner1,z:0}),n.setPointAt(1,{...e.corner2,z:0}),n.setPointAt(2,{...e.corner3,z:0}),n.setPointAt(3,e.corner4?{...e.corner4,z:0}:{...e.corner3,z:0}),n.thickness=e.thickness,n}convertLWPolyline(e){const n=new r.AcDbPolyline;n.closed=!!(e.flag&512);const o=e.constantWidth??-1;return e.vertices.forEach((t,i)=>{n.addVertexAt(i,new r.AcGePoint2d(t.x,t.y),t.bulge,t.startWidth??o,t.endWidth??o)}),n}convertPolyline2d(e){const n=!!(e.flag&1),o=!!(e.flag&16),t=!!(e.flag&64),i=!!(e.flag&32),s=[],a=[],c=[];if(e.vertices.map(l=>{if(!(l.flag&16))if(t&&l.flag&128)if(l.flag&64)s.push({x:l.x,y:l.y,z:l.z}),a.push(l.bulge??0);else{const f=[];l.polyfaceIndex0!=null&&l.polyfaceIndex0!=0&&f.push(Math.abs(l.polyfaceIndex0)-1),l.polyfaceIndex1!=null&&l.polyfaceIndex1!=0&&f.push(Math.abs(l.polyfaceIndex1)-1),l.polyfaceIndex2!=null&&l.polyfaceIndex2!=0&&f.push(Math.abs(l.polyfaceIndex2)-1),l.polyfaceIndex3!=null&&l.polyfaceIndex3!=0&&f.push(Math.abs(l.polyfaceIndex3)-1),f.length>=3&&c.push(f)}else s.push({x:l.x,y:l.y,z:l.z}),a.push(l.bulge??0)}),o){const l=e.meshMVertexCount??2,f=e.meshNVertexCount??2;return new r.AcDbPolygonMesh(l,f,s,n,i)}else{if(t)return new r.AcDbPolyFaceMesh(s,c);{let l=r.AcDbPoly2dType.SimplePoly;return e.flag&2?l=r.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?l=r.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(l=r.AcDbPoly2dType.QuadSplinePoly)),new r.AcDb2dPolyline(l,s,0,n,e.startWidth,e.endWidth,a)}}}convertPolyline3d(e){const n=!!(e.flag&1),o=[];e.vertices.map(i=>{i.flag&16||o.push({x:i.x,y:i.y,z:i.z})});let t=r.AcDbPoly3dType.SimplePoly;return e.flag&4&&(e.smoothType==6?t=r.AcDbPoly3dType.CubicSplinePoly:e.smoothType==5&&(t=r.AcDbPoly3dType.QuadSplinePoly)),new r.AcDb3dPolyline(t,o,n)}convertHatch(e){var t;const n=new r.AcDbHatch;if((t=e.definitionLines)==null||t.forEach(i=>{n.definitionLines.push({angle:i.angle,base:i.base,offset:i.offset,dashLengths:i.numberOfDashLengths>0?i.dashLengths:[]})}),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(i=>{if(i.boundaryPathTypeFlag&2){const a=i,c=new r.AcGePolyline2d;c.closed=a.isClosed,a.vertices.forEach((l,f)=>{c.addVertexAt(f,{x:l.x,y:l.y,bulge:l.bulge})}),n.add(c)}else{const a=i,c=[];a.edges.forEach(f=>{if(f!=null){if(f.type==1){const p=f;c.push(new r.AcGeLine2d(p.start,p.end))}else if(f.type==2){const p=f;c.push(new r.AcGeCircArc2d(p.center,p.radius,p.startAngle,p.endAngle,!p.isCCW))}else if(f.type==3){const p=f;new r.AcGeVector2d().subVectors(p.end,p.center);const g=Math.sqrt(Math.pow(p.end.x,2)+Math.pow(p.end.y,2)),d=g*p.lengthOfMinorAxis;let h=p.startAngle,A=p.endAngle;const D=Math.atan2(p.end.y,p.end.x);p.isCCW||(h=Math.PI*2-h,A=Math.PI*2-A),c.push(new r.AcGeEllipseArc2d({...p.center,z:0},g,d,h,A,!p.isCCW,D))}else if(f.type==4){const p=f;if(p.numberOfControlPoints>0&&p.numberOfKnots>0){const u=p.controlPoints.map(h=>({x:h.x,y:h.y,z:0}));let g=!0;const d=p.controlPoints.map(h=>(h.weight==null&&(g=!1),h.weight||1));c.push(new r.AcGeSpline3d(u,p.knots,g?d:void 0))}else if(p.numberOfFitData>0){const u=p.fitDatum.map(g=>({x:g.x,y:g.y,z:0}));c.push(new r.AcGeSpline3d(u,"Uniform"))}}}});const l=r.AcGeLoop2d.buildFromEdges(c);l.length==0&&c.length>0?n.add(new r.AcGeLoop2d(c)):l.forEach(f=>n.add(f))}}),e.gradientFlag){const i=e;if(n.hatchObjectType=r.AcDbHatchObjectType.GradientObject,n.gradientName=i.gradientName,n.gradientAngle=i.gradientRotation??0,n.gradientShift=i.gradientDefinition??0,n.gradientOneColorMode=i.gradientColorFlag==1,n.shadeTintValue=i.colorTint??0,i.gradientColors){const s=i.gradientColors.length;s>1?(n.gradientStartColor=i.gradientColors[0].rgb,n.gradientEndColor=i.gradientColors[1].rgb):s>0&&(n.gradientStartColor=i.gradientColors[0].rgb)}}return n}convertTable(e){const n=new r.AcDbTable(e.name,e.rowCount,e.columnCount);return n.tableStyleId=e.tableStyleId,n.owningBlockRecordId=e.blockRecordHandle,e.directionVector&&(n.horizontalDirection=new r.AcGeVector3d(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((o,t)=>n.setColumnWidth(t,o)),e.rowHeightArr.forEach((o,t)=>n.setRowHeight(t,o)),e.cells.forEach((o,t)=>{n.setCell(t,o)}),n}convertText(e){const n=new r.AcDbText;n.textString=e.text,n.styleName=e.styleName,n.height=e.textHeight,n.position.copy(e.startPoint);const o=!e.endPoint||e.endPoint.x===0&&e.endPoint.y===0&&(e.endPoint.z??0)===0;return e.endPoint&&!o?n.alignmentPoint.copy(e.endPoint):n.alignmentPoint.copy(e.startPoint),n.rotation=e.rotation,n.oblique=e.obliqueAngle??0,n.thickness=e.thickness,n.horizontalMode=e.halign,n.verticalMode=e.valign,n.widthFactor=e.xScale??1,n}convertMText(e){const n=new r.AcDbMText;return n.contents=e.text,e.styleName!=null&&(n.styleName=e.styleName),n.height=e.textHeight,n.width=e.rectWidth,n.rotation=e.rotation||0,n.location=e.insertionPoint,n.attachmentPoint=e.attachmentPoint,e.direction&&(n.direction=new r.AcGeVector3d(e.direction)),n.drawingDirection=e.drawingDirection,n}convertLeader(e){const n=new r.AcDbLeader;return e.vertices.forEach(o=>{n.appendVertex(o)}),n.hasArrowHead=e.isArrowheadEnabled,n.hasHookLine=e.isHooklineExists,n.isSplined=e.isSpline,n.dimensionStyle=e.styleName,n.annoType=e.leaderCreationFlag,n}convertMLine(e){const n=new r.AcDbMLine;return n.styleName=e.mlineStyle||"STANDARD",n.scale=e.scale,n.flags=e.flags,n.justification=e.justification,n.startPosition=e.startPoint,n.normal=e.extrusionDirection??r.AcGeVector3d.Z_AXIS,n.styleCount=e.numberOfLines??0,n.segments=(e.vertices??[]).map(o=>({position:o.vertex,direction:o.vertexDirection,miterDirection:o.miterDirection,elements:(o.lines??[]).map(t=>({parameterCount:t.numberOfSegmentParams,parameters:t.segmentParams??[],fillCount:t.numberOfAreaFillParams,fillParameters:t.areaFillParams??[]}))})),n}convertMLeader(e){var g,d,h,A;const n=new r.AcDbMLeader,o=e;n.leaderLineType=this.readNumber(o,["multileaderType","leaderLineType","leaderType"])??r.AcDbMLeaderLineType.StraightLeader;const t=this.readNumber(o,["contentType"])??(e.textContent?r.AcDbMLeaderContentType.MTextContent:e.blockContent?r.AcDbMLeaderContentType.BlockContent:r.AcDbMLeaderContentType.NoneContent);n.contentType=t,n.doglegEnabled=this.readBoolean(o,["doglegEnabled","enableDogleg"])??!1,n.doglegLength=this.readNumber(o,["doglegLength"])??0,e.landingPoint&&(n.landingPoint=e.landingPoint),e.doglegVector&&(n.doglegVector=e.doglegVector);const i=this.readString(o,["mleaderStyleId","mLeaderStyleId","mleaderStyleHandle","styleHandle","styleName"]);i&&(n.mleaderStyleId=i);const s=this.readPoint(o,["normal","extrusionDirection"]);s&&(n.normal=s);const a=e.textContent,c=this.readString(a??{},["styleName","textStyleName"])??this.readString(o,["textStyleName","textStyle","styleName"]);c&&(n.textStyleName=c),n.textHeight=this.readNumber(a??{},["textHeight","height"])??this.readNumber(o,["textHeight","mtextHeight","textContentHeight"])??n.textHeight,n.textWidth=this.readNumber(a??{},["textWidth","width"])??this.readNumber(o,["textWidth","mtextWidth","textContentWidth"])??n.textWidth;const l=this.readNumber(a??{},["textRotation","rotation"])??this.readNumber(o,["textRotation","mtextRotation","textContentRotation"]);l!=null&&(n.textRotation=l);const f=this.readPoint(o,["textDirection","mtextDirection","textDirectionVector"]);f&&(n.textDirection=f);const p=this.readNumber(o,["textAttachmentPoint","attachmentPoint"]);p!=null&&(n.textAttachmentPoint=p);const u=this.readNumber(o,["textDrawingDirection","drawingDirection"]);if(u!=null&&(n.textDrawingDirection=u),((g=e.textContent)==null?void 0:g.text)!=null&&e.textContent.anchorPoint)n.mtextContent={text:e.textContent.text,anchorPoint:e.textContent.anchorPoint};else{const D=this.readString(o,["text","contents","mtext"]),y=this.readPoint(o,["textLocation","textPosition","textAnchorPoint"]);D!=null&&y&&(n.mtextContent={text:D,anchorPoint:y})}if((d=e.blockContent)!=null&&d.blockHandle&&e.blockContent.position)n.blockContent={blockHandle:e.blockContent.blockHandle,position:e.blockContent.position};else{const D=this.readString(o,["blockHandle","blockContentHandle","blockId"]),y=this.readPoint(o,["blockPosition","blockContentPosition"]);D&&y&&(n.blockContent={blockHandle:D,position:y})}return(h=e.leaders)==null||h.forEach(D=>{var T;const y=n.addLeader({landingPoint:D.landingPoint??e.landingPoint,doglegVector:D.doglegVector??e.doglegVector,doglegLength:D.doglegLength??e.doglegLength});(T=D.leaderLines)==null||T.forEach(I=>{var w;const S=n.addLeaderLine(y,I.vertices??[]);(w=I.breaks)==null||w.forEach(L=>{n.addBreak(y,S,L.start,L.end)})})}),n.numberOfLeaders===0&&((A=this.readLeaderLineArray(o))==null||A.forEach(D=>{const y=n.addLeader({landingPoint:e.landingPoint,doglegVector:e.doglegVector,doglegLength:e.doglegLength});n.addLeaderLine(y,D)})),n}convertDimension(e){if(e.subclassMarker=="AcDbAlignedDimension"){const n=e,o=new r.AcDbAlignedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return n.insertionPoint&&(o.dimBlockPosition={x:n.insertionPoint.x,y:n.insertionPoint.y,z:0}),o.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbRotatedDimension"){const n=e,o=new r.AcDbRotatedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return n.insertionPoint&&(o.dimBlockPosition={x:n.insertionPoint.x,y:n.insertionPoint.y,z:0}),o.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const n=e,o=new r.AcDb3PointAngularDimension(n.centerPoint,n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbOrdinateDimension"){const n=e,o=new r.AcDbOrdinateDimension(n.subDefinitionPoint1,n.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbRadialDimension"){const n=e,o=new r.AcDbRadialDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbDiametricDimension"){const n=e,o=new r.AcDbDiametricDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,o),o}return null}processImage(e,n){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(o=>{n.clipBoundary.push(new r.AcGePoint2d(o))}),n.clipBoundaryType=e.clippingBoundaryType,n.width=Math.sqrt(e.uPixel.x**2+e.uPixel.y**2+e.uPixel.z**2)*e.imageSize.x,n.height=Math.sqrt(e.vPixel.x**2+e.vPixel.y**2+e.vPixel.z**2)*e.imageSize.y,n.rotation=Math.atan2(e.uPixel.y,e.uPixel.x)}convertImage(e){const n=new r.AcDbRasterImage;return this.processImage(e,n),n}convertWipeout(e){const n=new r.AcDbWipeout;return this.processImage(e,n),n}convertViewport(e){const n=new r.AcDbViewport;return n.number=e.viewportId,n.centerPoint.copy(e.viewportCenter),n.height=e.height,n.width=e.width,n.viewCenter.copy(e.displayCenter),n.viewHeight=e.viewHeight,n}convertRay(e){const n=new r.AcDbRay;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertXline(e){const n=new r.AcDbXline;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertAttributeCommon(e,n){const o=e.text;n.textString=o.text,n.styleName=o.styleName,n.height=o.textHeight,n.position.copy(o.startPoint);const t=e.alignmentPoint??o.endPoint,i=!t||t.x===0&&t.y===0&&(t.z??0)===0;t&&!i?n.alignmentPoint.copy(t):n.alignmentPoint.copy(o.startPoint),n.rotation=o.rotation,n.oblique=o.obliqueAngle??0,n.thickness=o.thickness,n.horizontalMode=o.halign,n.verticalMode=o.valign,n.widthFactor=o.xScale??1,n.tag=e.tag,n.fieldLength=e.fieldLength,n.isInvisible=(e.flags&r.AcDbAttributeFlags.Invisible)!==0,n.isConst=(e.flags&r.AcDbAttributeFlags.Const)!==0,n.isVerifiable=(e.flags&r.AcDbAttributeFlags.Verifiable)!==0,n.isPreset=(e.flags&r.AcDbAttributeFlags.Preset)!==0,n.lockPositionInBlock=e.lockPositionFlag,n.isReallyLocked=e.isReallyLocked,n.isMTextAttribute=(e.mtextFlag&r.AcDbAttributeMTextFlag.MultiLine)!==0,n.isConstMTextAttribute=(e.mtextFlag&r.AcDbAttributeMTextFlag.ConstMultiLine)!==0}convertAttribute(e){const n=new r.AcDbAttribute;return this.convertAttributeCommon(e,n),n}convertAttributeDefinition(e){const n=new r.AcDbAttributeDefinition;return this.convertAttributeCommon(e,n),n.prompt=e.prompt,n}convertBlockReference(e){const n=new r.AcDbBlockReference(e.name);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.handle!=null&&(n.objectId=e.handle),e.attribs&&e.attribs.forEach(o=>{const t=this.convert(o);t instanceof r.AcDbAttribute&&n.appendAttributes(t)}),n}processDimensionCommonAttrs(e,n){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}processCommonAttrs(e,n){if(n.layer=e.layer||"0",n.objectId=e.handle,e.ownerBlockRecordSoftId!=null&&(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){const o=new r.AcCmTransparency;o.method=e.transparencyType,(o.isByBlock||o.isByBlock)&&(o.alpha=e.transparency),n.transparency=o}}readNumber(e,n){for(const o of n){const t=e[o];if(typeof t=="number"&&Number.isFinite(t))return t}}readString(e,n){for(const o of n){const t=e[o];if(typeof t=="string")return t}}readBoolean(e,n){for(const o of n){const t=e[o];if(typeof t=="boolean")return t;if(typeof t=="number")return t!==0}}readPoint(e,n){for(const o of n){const t=e[o];if(this.isPointLike(t))return t;if(Array.isArray(t)&&typeof t[0]=="number"&&typeof t[1]=="number")return{x:t[0],y:t[1],z:t[2]??0}}}readLeaderLineArray(e){const n=e.leaderLines;if(Array.isArray(n))return n.map(t=>{if(!t||typeof t!="object")return;const i=t.vertices;return Array.isArray(i)?i.filter(s=>this.isPointLike(s)):void 0}).filter(t=>!!t&&t.length>0);const o=e.vertices;if(Array.isArray(o)){const t=o.filter(i=>this.isPointLike(i));return t.length>0?[t]:void 0}}isPointLike(e){return!!e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}}const C="*MODEL_SPACE";class E extends r.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e,n){const o=this.config,t=this.getParserWorkerTimeout(e,n);if(o.useWorker&&o.parserWorkerUrl){const i=r.createWorkerApi({workerUrl:o.parserWorkerUrl,timeout:t,maxConcurrentWorkers:1}),s=await i.execute(e);if(i.destroy(),s.success)return s.data;throw new Error(`Failed to parse drawing due to error: '${s.error}'`)}else throw new Error("dwg converter can run in web worker only!")}getFonts(e){const n=new Map;e.tables.BLOCK_RECORD.entries.forEach(s=>{n.set(s.name,s)});const o=new Map,t=s=>{if(s){const a=s.lastIndexOf(".");return a>=0?s.substring(0,a).toLowerCase():s.toLowerCase()}};e.tables.STYLE.entries.forEach(s=>{const a=[];let c=t(s.font);c&&a.push(c),c=t(s.bigFont),c&&a.push(c),o.set(s.name,a)});const i=new Set;return this.getFontsInBlock(e.entities,n,o,i),Array.from(i)}getFontsInBlock(e,n,o,t){const i=/\\f(.*?)\|/g;e.forEach(s=>{if(s.type=="MTEXT"){const a=s;[...a.text.matchAll(i)].forEach(l=>{t.add(l[1].toLowerCase())});const c=o.get(a.styleName);c==null||c.forEach(l=>t.add(l))}else if(s.type=="TEXT"){const a=s,c=o.get(a.styleName);c==null||c.forEach(l=>t.add(l))}else if(s.type=="MULTILEADER"||s.type=="MLEADER"){const a=s,c=a.textContent;[...(typeof(c==null?void 0:c.text)=="string"?c.text:"").matchAll(i)].forEach(u=>{t.add(u[1].toLowerCase())});const f=typeof(c==null?void 0:c.styleName)=="string"?c.styleName:typeof a.textStyleName=="string"?a.textStyleName:typeof a.styleName=="string"?a.styleName:void 0,p=f?o.get(f):void 0;p==null||p.forEach(u=>t.add(u))}else if(s.type=="INSERT"){const a=s,c=n.get(a.name);c&&this.getFontsInBlock(c.entities,n,o,t)}})}processLineTypes(e,n){e.tables.LTYPE.entries.forEach(t=>{const i={name:t.name,description:t.description,standardFlag:t.standardFlag,totalPatternLength:t.totalPatternLength,pattern:t.pattern},s=new r.AcDbLinetypeTableRecord(i);this.processCommonTableEntryAttrs(t,s),s.name=t.name,n.tables.linetypeTable.add(s)})}processTextStyles(e,n){e.tables.STYLE.entries.forEach(t=>{const i=new r.AcDbTextStyleTableRecord(t);this.processCommonTableEntryAttrs(t,i),n.tables.textStyleTable.add(i)})}processDimStyles(e,n){e.tables.DIMSTYLE.entries.forEach(t=>{const i={name:t.name,ownerId:t.ownerHandle,dimpost:t.DIMPOST||"",dimapost:t.DIMAPOST||"",dimscale:t.DIMSCALE,dimasz:t.DIMASZ,dimexo:t.DIMEXO,dimdli:t.DIMDLI,dimexe:t.DIMEXE,dimrnd:t.DIMRND,dimdle:t.DIMDLE,dimtp:t.DIMTP,dimtm:t.DIMTM,dimtxt:t.DIMTXT,dimcen:t.DIMCEN,dimtsz:t.DIMTSZ,dimaltf:t.DIMALTF,dimlfac:t.DIMLFAC,dimtvp:t.DIMTVP,dimtfac:t.DIMTFAC,dimgap:t.DIMGAP,dimaltrnd:t.DIMALTRND,dimtol:t.DIMTOL==null||t.DIMTOL==0?0:1,dimlim:t.DIMLIM==null||t.DIMLIM==0?0:1,dimtih:t.DIMTIH==null||t.DIMTIH==0?0:1,dimtoh:t.DIMTOH==null||t.DIMTOH==0?0:1,dimse1:t.DIMSE1==null||t.DIMSE1==0?0:1,dimse2:t.DIMSE2==null||t.DIMSE2==0?0:1,dimtad:t.DIMTAD,dimzin:t.DIMZIN,dimazin:t.DIMAZIN,dimalt:t.DIMALT,dimaltd:t.DIMALTD,dimtofl:t.DIMTOFL,dimsah:t.DIMSAH,dimtix:t.DIMTIX,dimsoxd:t.DIMSOXD,dimclrd:t.DIMCLRD,dimclre:t.DIMCLRE,dimclrt:t.DIMCLRT,dimadec:t.DIMADEC||0,dimunit:t.DIMUNIT||2,dimdec:t.DIMDEC,dimtdec:t.DIMTDEC,dimaltu:t.DIMALTU,dimalttd:t.DIMALTTD,dimaunit:t.DIMAUNIT,dimfrac:t.DIMFRAC,dimlunit:t.DIMLUNIT,dimdsep:t.DIMDSEP||".",dimtmove:t.DIMTMOVE||0,dimjust:t.DIMJUST,dimsd1:t.DIMSD1,dimsd2:t.DIMSD2,dimtolj:t.DIMTOLJ,dimtzin:t.DIMTZIN,dimaltz:t.DIMALTZ,dimalttz:t.DIMALTTZ,dimfit:t.DIMFIT||0,dimupt:t.DIMUPT,dimatfit:t.DIMATFIT,dimtxsty:r.DEFAULT_TEXT_STYLE,dimldrblk:"",dimblk:t.DIMBLK||"",dimblk1:t.DIMBLK1||"",dimblk2:t.DIMBLK2||"",dimlwd:t.DIMLWD,dimlwe:t.DIMLWE},s=new r.AcDbDimStyleTableRecord(i);this.processCommonTableEntryAttrs(t,s),n.tables.dimStyleTable.add(s)})}processLayers(e,n){e.tables.LAYER.entries.forEach(t=>{const i=new r.AcCmColor;i.colorIndex=t.colorIndex;const s=new r.AcDbLayerTableRecord({name:t.name,standardFlags:t.standardFlag,linetype:t.lineType,lineWeight:t.lineweight,isOff:t.off,color:i,isPlottable:t.plotFlag!=0});this.processCommonTableEntryAttrs(t,s),n.tables.layerTable.add(s)})}processViewports(e,n){e.tables.VPORT.entries.forEach(t=>{const i=new r.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(t,i),t.circleSides&&(i.circleSides=t.circleSides),i.standardFlag=t.standardFlag,i.center.copy(t.center),i.lowerLeftCorner.copy(t.lowerLeftCorner),i.upperRightCorner.copy(t.upperRightCorner),t.snapBasePoint&&i.snapBase.copy(t.snapBasePoint),t.snapRotationAngle&&(i.snapAngle=t.snapRotationAngle),t.snapSpacing&&i.snapIncrements.copy(t.snapSpacing),t.majorGridLines&&(i.gridMajor=t.majorGridLines),t.gridSpacing&&i.gridIncrements.copy(t.gridSpacing),t.backgroundObjectId&&(i.backgroundObjectId=t.backgroundObjectId),i.gsView.center.copy(t.center),i.gsView.viewDirectionFromTarget.copy(t.viewDirectionFromTarget),i.gsView.viewTarget.copy(t.viewTarget),t.lensLength&&(i.gsView.lensLength=t.lensLength),t.frontClippingPlane&&(i.gsView.frontClippingPlane=t.frontClippingPlane),t.backClippingPlane&&(i.gsView.backClippingPlane=t.backClippingPlane),t.viewHeight&&(i.gsView.viewHeight=t.viewHeight),t.viewTwistAngle&&(i.gsView.viewTwistAngle=t.viewTwistAngle),t.frozenLayers&&(i.gsView.frozenLayers=t.frozenLayers),t.styleSheet&&(i.gsView.styleSheet=t.styleSheet),t.renderMode&&(i.gsView.renderMode=t.renderMode),t.viewMode&&(i.gsView.viewMode=t.viewMode),t.ucsIconSetting&&(i.gsView.ucsIconSetting=t.ucsIconSetting),t.ucsOrigin&&i.gsView.ucsOrigin.copy(t.ucsOrigin),t.ucsXAxis&&i.gsView.ucsXAxis.copy(t.ucsXAxis),t.ucsYAxis&&i.gsView.ucsYAxis.copy(t.ucsYAxis),t.orthographicType&&(i.gsView.orthographicType=t.orthographicType),t.shadePlotSetting&&(i.gsView.shadePlotSetting=t.shadePlotSetting),t.shadePlotObjectId&&(i.gsView.shadePlotObjectId=t.shadePlotObjectId),t.visualStyleObjectId&&(i.gsView.visualStyleObjectId=t.visualStyleObjectId),t.isDefaultLightingOn&&(i.gsView.isDefaultLightingOn=t.isDefaultLightingOn),t.defaultLightingType&&(i.gsView.defaultLightingType=t.defaultLightingType),t.brightness&&(i.gsView.brightness=t.brightness),t.contrast&&(i.gsView.contrast=t.contrast),t.ambientColor&&(i.gsView.ambientColor=t.ambientColor),n.tables.viewportTable.add(i)})}processBlockTables(e,n){e.tables.BLOCK_RECORD.entries.forEach(t=>{let i=n.tables.blockTable.getAt(t.name);i||(i=new r.AcDbBlockTableRecord,i.objectId=t.handle,i.name=t.name,i.ownerId=t.ownerHandle,i.origin.copy(t.basePoint),i.layoutId=t.layout,i.blockInsertUnits=t.insertionUnits,i.explodability=t.explodability,i.blockScaling=t.scalability,t.bmpPreview&&(i.bmpPreview=t.bmpPreview),n.tables.blockTable.add(i)),!i.isModelSapce&&t.entities&&t.entities.length>0&&this.processEntitiesInBlock(t.entities,i)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const o=new P,t=e.length,i=[];for(let s=0;s<t;s++){const a=e[s],c=o.convert(a);c&&i.push(c)}n.appendEntity(i)}async processEntities(e,n,o,t,i){const s=new P;let a=[];e.tables.BLOCK_RECORD.entries.forEach(p=>{this.isModelSpace(p.name)&&(a=p.entities)});const c=a.length,l=new r.AcDbBatchProcessing(c,100-t.value,o);this.config.convertByEntityType&&(a=this.groupAndFlattenByType(a));const f=n.tables.blockTable.modelSpace;await l.processChunk(async(p,u)=>{const g=[];for(let d=p;d<u;d++){const h=a[d],A=s.convert(h);A&&g.push(A)}if(f.appendEntity(g),i){let d=t.value+u/c*(100-t.value);d>100&&(d=100),await i(d,"ENTITY","IN-PROGRESS")}})}processHeader(e,n){const o=e.header;o.CECOLOR&&(o.CECOLOR.index>=0&&o.CECOLOR.index<=256?n.cecolor.colorIndex=o.CECOLOR.index:n.cecolor.setRGBValue(o.CECOLOR.rgb)),n.angBase=o.ANGBASE??0,n.angDir=o.ANGDIR??0,n.aunits=o.AUNITS??0,n.celtype=o.CELTYPE??r.ByLayer,n.celtscale=o.CELTSCALE??1,n.ltscale=o.LTSCALE??1,o.EXTMAX&&(n.extmax=o.EXTMAX),o.EXTMIN&&(n.extmin=o.EXTMIN),n.insunits=o.INSUNITS??1,n.pdmode=o.PDMODE??0,n.pdsize=o.PDSIZE??0,n.textstyle=o.TEXTSTYLE??r.DEFAULT_TEXT_STYLE}processCommonTableEntryAttrs(e,n){n.name=e.name,n.objectId=e.handle,e.ownerHandle!=null&&(n.ownerId=e.ownerHandle)}processObjects(e,n){this.processLayouts(e,n),this.processImageDefs(e,n)}processLayouts(e,n){const o=n.objects.layout;e.objects.LAYOUT.forEach(i=>{const s=new r.AcDbLayout;s.layoutName=i.layoutName,s.tabOrder=i.tabOrder;const a=n.tables.blockTable.newIterator();s.objectId=i.handle;for(const c of a)if(c.layoutId===s.objectId){s.blockTableRecordId=c.objectId;break}s.blockTableRecordId||i.layoutName==="Model"&&(s.blockTableRecordId=n.tables.blockTable.modelSpace.objectId),s.limits.min.copy(i.minLimit),s.limits.max.copy(i.maxLimit),s.extents.min.copy(i.minExtent),s.extents.max.copy(i.maxExtent),i.viewportId&&s.viewportArray.push(i.viewportId),this.processCommonObjectAttrs(i,s),o.setAt(s.layoutName,s)})}processImageDefs(e,n){const o=n.objects.imageDefinition;e.objects.IMAGEDEF.forEach(i=>{const s=new r.AcDbRasterImageDef;s.sourceFileName=i.fileName,this.processCommonObjectAttrs(i,s),o.setAt(s.objectId,s)})}processCommonObjectAttrs(e,n){n.objectId=e.handle,e.ownerHandle!=null&&(n.ownerId=e.ownerHandle)}groupAndFlattenByType(e){const n={},o=[];for(const t of e)n[t.type]||(n[t.type]=[],o.push(t.type)),n[t.type].push(t);return o.flatMap(t=>n[t])}isModelSpace(e){return e&&e.toUpperCase()==C}}b.AcDbLibreDwgConverter=E,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|