@mlightcad/libredwg-web 0.7.2 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/libredwg-web.js +181 -4130
- package/dist/libredwg-web.umd.cjs +181 -4133
- package/lib/converter/converter.d.ts +1 -0
- package/lib/converter/converter.js +21 -6
- package/lib/converter/entityConverter.d.ts +5 -2
- package/lib/converter/entityConverter.js +77 -8
- package/lib/converter/utils.d.ts +1 -0
- package/lib/converter/utils.js +7 -0
- package/lib/database/entities/proxy.d.ts +38 -1
- package/lib/database/entities/proxy.js +9 -1
- package/lib/libredwg.d.ts +13 -1
- package/lib/libredwg.js +46 -3
- package/lib/types/common.d.ts +1 -0
- package/lib/types/enums.d.ts +17 -0
- package/lib/types/enums.js +18 -0
- package/package.json +24 -17
- package/wasm/libredwg-web.d.ts +32 -22
- package/wasm/libredwg-web.js +2 -15
- package/wasm/libredwg-web.wasm +0 -0
- package/lib/enums.d.ts +0 -340
- package/lib/enums.js +0 -351
- package/lib/libredwg-web.d.ts +0 -3
- package/lib/libredwg-web.js +0 -2360
- package/lib/svg/ToSVG.d.ts +0 -16
- package/lib/svg/ToSVG.js +0 -235
- package/lib/svg/util/boundingBox.d.ts +0 -9
- package/lib/svg/util/boundingBox.js +0 -19
- package/lib/svg/util/box2d.d.ts +0 -9
- package/lib/svg/util/box2d.js +0 -19
- package/lib/svg/util/denormalise.d.ts +0 -19
- package/lib/svg/util/denormalise.js +0 -24
- package/lib/svg/util/entityToPolyline.d.ts +0 -2
- package/lib/svg/util/entityToPolyline.js +0 -5
- package/lib/svg/util/getRGBForEntity.d.ts +0 -3
- package/lib/svg/util/getRGBForEntity.js +0 -9
- package/lib/svg/util/rgbToColorAttribute.d.ts +0 -6
- package/lib/svg/util/rgbToColorAttribute.js +0 -4
- package/lib/svg/util/rotate.d.ts +0 -6
- package/lib/svg/util/rotate.js +0 -9
- package/lib/svg/util/toPiecewiseBezier.d.ts +0 -9
- package/lib/svg/util/toPiecewiseBezier.js +0 -24
- package/lib/svg/util/transformBoundingBoxAndElement.d.ts +0 -19
- package/lib/svg/util/transformBoundingBoxAndElement.js +0 -20
- package/lib/types/database.d.ts +0 -17
- package/lib/types/database.js +0 -2
- package/lib/types/entities/arc.d.ts +0 -12
- package/lib/types/entities/arc.js +0 -2
- package/lib/types/entities/circle.d.ts +0 -10
- package/lib/types/entities/circle.js +0 -2
- package/lib/types/entities/dimension.d.ts +0 -108
- package/lib/types/entities/dimension.js +0 -2
- package/lib/types/entities/ellipse.d.ts +0 -12
- package/lib/types/entities/ellipse.js +0 -2
- package/lib/types/entities/entity.d.ts +0 -25
- package/lib/types/entities/entity.js +0 -2
- package/lib/types/entities/hatch.d.ts +0 -142
- package/lib/types/entities/hatch.js +0 -2
- package/lib/types/entities/image.d.ts +0 -36
- package/lib/types/entities/image.js +0 -2
- package/lib/types/entities/index.d.ts +0 -24
- package/lib/types/entities/index.js +0 -24
- package/lib/types/entities/insert.d.ts +0 -18
- package/lib/types/entities/insert.js +0 -2
- package/lib/types/entities/leader.d.ts +0 -28
- package/lib/types/entities/leader.js +0 -2
- package/lib/types/entities/line.d.ts +0 -10
- package/lib/types/entities/line.js +0 -2
- package/lib/types/entities/lwpolyline.d.ts +0 -19
- package/lib/types/entities/lwpolyline.js +0 -2
- package/lib/types/entities/mtext.d.ts +0 -37
- package/lib/types/entities/mtext.js +0 -2
- package/lib/types/entities/point.d.ts +0 -10
- package/lib/types/entities/point.js +0 -2
- package/lib/types/entities/polyline.d.ts +0 -34
- package/lib/types/entities/polyline.js +0 -2
- package/lib/types/entities/ray.d.ts +0 -8
- package/lib/types/entities/ray.js +0 -2
- package/lib/types/entities/section.d.ts +0 -19
- package/lib/types/entities/section.js +0 -2
- package/lib/types/entities/solid.d.ts +0 -9
- package/lib/types/entities/solid.js +0 -2
- package/lib/types/entities/spline.d.ts +0 -21
- package/lib/types/entities/spline.js +0 -2
- package/lib/types/entities/table.d.ts +0 -52
- package/lib/types/entities/table.js +0 -2
- package/lib/types/entities/text.d.ts +0 -38
- package/lib/types/entities/text.js +0 -2
- package/lib/types/entities/vertex.d.ts +0 -25
- package/lib/types/entities/vertex.js +0 -2
- package/lib/types/entities/viewport.d.ts +0 -105
- package/lib/types/entities/viewport.js +0 -2
- package/lib/types/entities/xline.d.ts +0 -8
- package/lib/types/entities/xline.js +0 -2
- package/lib/types/objects/common.d.ts +0 -5
- package/lib/types/objects/common.js +0 -2
- package/lib/types/objects/imageDef.d.ts +0 -10
- package/lib/types/objects/imageDef.js +0 -2
- package/lib/types/objects/index.d.ts +0 -5
- package/lib/types/objects/index.js +0 -5
- package/lib/types/objects/layout.d.ts +0 -23
- package/lib/types/objects/layout.js +0 -2
- package/lib/types/objects/plotSetting.d.ts +0 -35
- package/lib/types/objects/plotSetting.js +0 -2
- package/lib/types/shared/xdata.d.ts +0 -10
- package/lib/types/shared/xdata.js +0 -2
- package/lib/types/tables/blockRecord.d.ts +0 -12
- package/lib/types/tables/blockRecord.js +0 -2
- package/lib/types/tables/dimStyle.d.ts +0 -84
- package/lib/types/tables/dimStyle.js +0 -2
- package/lib/types/tables/index.d.ts +0 -8
- package/lib/types/tables/index.js +0 -8
- package/lib/types/tables/layer.d.ts +0 -16
- package/lib/types/tables/layer.js +0 -2
- package/lib/types/tables/ltype.d.ts +0 -21
- package/lib/types/tables/ltype.js +0 -2
- package/lib/types/tables/style.d.ts +0 -13
- package/lib/types/tables/style.js +0 -2
- package/lib/types/tables/table.d.ts +0 -9
- package/lib/types/tables/table.js +0 -2
- package/lib/types/tables/vport.d.ts +0 -42
- package/lib/types/tables/vport.js +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HEADER_VARIABLES } from '../database';
|
|
2
|
-
import { Dwg_Object_Type } from '../types';
|
|
2
|
+
import { Dwg_Object_Supertype, Dwg_Object_Type } from '../types';
|
|
3
3
|
import { LibreEntityConverter } from './entityConverter';
|
|
4
4
|
import { idToString, isModelSpace, isPaperSpace } from './utils';
|
|
5
5
|
/**
|
|
@@ -51,11 +51,12 @@ export class LibreDwgConverter {
|
|
|
51
51
|
const libredwg = this.libredwg;
|
|
52
52
|
this.convertHeader(data, db.header);
|
|
53
53
|
this.convertClasses(data, db.classes);
|
|
54
|
+
this.entityConverter.setClasses(db.classes);
|
|
54
55
|
const num_objects = libredwg.dwg_get_num_objects(data);
|
|
55
56
|
for (let i = 0; i < num_objects; i++) {
|
|
56
57
|
const obj = libredwg.dwg_get_object(data, i);
|
|
57
58
|
if (obj) {
|
|
58
|
-
const tio =
|
|
59
|
+
const tio = this.safeObjectTio(obj);
|
|
59
60
|
if (tio) {
|
|
60
61
|
const fixedtype = libredwg.dwg_object_get_fixedtype(obj);
|
|
61
62
|
switch (fixedtype) {
|
|
@@ -82,7 +83,7 @@ export class LibreDwgConverter {
|
|
|
82
83
|
for (let i = 0; i < num_objects; i++) {
|
|
83
84
|
const obj = libredwg.dwg_get_object(data, i);
|
|
84
85
|
if (obj) {
|
|
85
|
-
const tio =
|
|
86
|
+
const tio = this.safeObjectTio(obj);
|
|
86
87
|
if (tio) {
|
|
87
88
|
const fixedtype = libredwg.dwg_object_get_fixedtype(obj);
|
|
88
89
|
switch (fixedtype) {
|
|
@@ -155,6 +156,20 @@ export class LibreDwgConverter {
|
|
|
155
156
|
unknownEntityCount: this.entityConverter.unknownEntityCount
|
|
156
157
|
};
|
|
157
158
|
}
|
|
159
|
+
safeObjectTio(obj) {
|
|
160
|
+
const libredwg = this.libredwg;
|
|
161
|
+
try {
|
|
162
|
+
if (libredwg.dwg_object_get_supertype(obj) !=
|
|
163
|
+
Dwg_Object_Supertype.DWG_SUPERTYPE_OBJECT) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const tio = libredwg.dwg_object_to_object_tio(obj);
|
|
167
|
+
return tio ? tio : null;
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
158
173
|
convertHeader(data, header) {
|
|
159
174
|
const libredwg = this.libredwg;
|
|
160
175
|
HEADER_VARIABLES.forEach(name => {
|
|
@@ -171,10 +186,10 @@ export class LibreDwgConverter {
|
|
|
171
186
|
name == 'DIMSTYLE' ||
|
|
172
187
|
name == 'DIMTXSTY' ||
|
|
173
188
|
name == 'TEXTSTYLE') {
|
|
174
|
-
value =
|
|
189
|
+
value = value ? libredwg.dwg_ref_get_object_name(value) : '';
|
|
175
190
|
}
|
|
176
191
|
else if (name == 'DRAGVS') {
|
|
177
|
-
value =
|
|
192
|
+
value = value ? libredwg.dwg_ref_get_absref(value) : 2;
|
|
178
193
|
}
|
|
179
194
|
// @ts-expect-error header variable name
|
|
180
195
|
header[name] = value;
|
|
@@ -891,7 +906,7 @@ export class LibreDwgConverter {
|
|
|
891
906
|
const viewportId = idToString(libredwg.dwg_ref_get_absref(active_viewport_ref));
|
|
892
907
|
const named_ucs_ref = libredwg.dwg_dynapi_entity_value(item, 'named_ucs')
|
|
893
908
|
.data;
|
|
894
|
-
const namedUcsId =
|
|
909
|
+
const namedUcsId = named_ucs_ref
|
|
895
910
|
? idToString(libredwg.dwg_ref_get_absref(named_ucs_ref))
|
|
896
911
|
: undefined;
|
|
897
912
|
// BITCODE_H base_ucs;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { DwgDatabase, DwgEntity } from '../database';
|
|
1
|
+
import { DwgClassLookup, DwgDatabase, DwgEntity } from '../database';
|
|
2
2
|
import { LibreDwgEx } from '../libredwg';
|
|
3
3
|
import { Dwg_Object_Ptr } from '../types';
|
|
4
4
|
export declare class LibreEntityConverter {
|
|
5
5
|
libredwg: LibreDwgEx;
|
|
6
6
|
layers: Map<string, string>;
|
|
7
7
|
ltypes: Map<string, string>;
|
|
8
|
+
classes: DwgClassLookup[];
|
|
8
9
|
unknownEntityCount: number;
|
|
9
10
|
constructor(instance: LibreDwgEx);
|
|
10
11
|
prepare(db: DwgDatabase, force?: boolean): void;
|
|
12
|
+
setClasses(classes: DwgClassLookup[]): void;
|
|
11
13
|
clear(): void;
|
|
12
14
|
convert(object_ptr: Dwg_Object_Ptr): DwgEntity | undefined;
|
|
13
15
|
private convert3dFace;
|
|
@@ -36,7 +38,8 @@ export declare class LibreEntityConverter {
|
|
|
36
38
|
private convertPoint;
|
|
37
39
|
private convertPolyline2d;
|
|
38
40
|
private convertPolyline3d;
|
|
39
|
-
private
|
|
41
|
+
private convertProxyEntity;
|
|
42
|
+
private getOriginalDxfName;
|
|
40
43
|
private convertRay;
|
|
41
44
|
private convertSection;
|
|
42
45
|
private convertSolid;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { DwgBoundaryPathEdgeType, DwgHatchAssociativity, DwgHatchGradientColorFlag, DwgHatchGradientFlag, DwgHatchSolidFill } from '../database';
|
|
2
2
|
import { Dwg_Hatch_Edge_Type, Dwg_Object_Type } from '../types';
|
|
3
|
-
import { idToString } from './utils';
|
|
3
|
+
import { idToString, uint8ArrayToHexString } from './utils';
|
|
4
4
|
export class LibreEntityConverter {
|
|
5
5
|
libredwg;
|
|
6
6
|
layers = new Map();
|
|
7
7
|
ltypes = new Map();
|
|
8
|
+
classes = [];
|
|
8
9
|
unknownEntityCount;
|
|
9
10
|
constructor(instance) {
|
|
10
11
|
this.libredwg = instance;
|
|
@@ -23,11 +24,16 @@ export class LibreEntityConverter {
|
|
|
23
24
|
this.ltypes.set(ltype.handle, ltype.name);
|
|
24
25
|
});
|
|
25
26
|
}
|
|
27
|
+
this.classes = db.classes;
|
|
26
28
|
this.unknownEntityCount = 0;
|
|
27
29
|
}
|
|
30
|
+
setClasses(classes) {
|
|
31
|
+
this.classes = classes;
|
|
32
|
+
}
|
|
28
33
|
clear() {
|
|
29
34
|
this.layers.clear();
|
|
30
35
|
this.ltypes.clear();
|
|
36
|
+
this.classes = [];
|
|
31
37
|
this.unknownEntityCount = 0;
|
|
32
38
|
}
|
|
33
39
|
convert(object_ptr) {
|
|
@@ -114,7 +120,7 @@ export class LibreEntityConverter {
|
|
|
114
120
|
return this.convertPolyline3d(entity_tio, commonAttrs, object_ptr);
|
|
115
121
|
}
|
|
116
122
|
else if (fixedtype == Dwg_Object_Type.DWG_TYPE_PROXY_ENTITY) {
|
|
117
|
-
return this.
|
|
123
|
+
return this.convertProxyEntity(entity_tio, commonAttrs, object_ptr);
|
|
118
124
|
}
|
|
119
125
|
else if (fixedtype == Dwg_Object_Type.DWG_TYPE_RAY) {
|
|
120
126
|
return this.convertRay(entity_tio, commonAttrs);
|
|
@@ -1115,15 +1121,78 @@ export class LibreEntityConverter {
|
|
|
1115
1121
|
})
|
|
1116
1122
|
};
|
|
1117
1123
|
}
|
|
1118
|
-
|
|
1124
|
+
convertProxyEntity(entity, commonAttrs, objectPtr) {
|
|
1119
1125
|
const libredwg = this.libredwg;
|
|
1120
|
-
const
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1126
|
+
const proxyEntityClassId = libredwg.dwg_dynapi_entity_value(entity, 'proxy_id').data;
|
|
1127
|
+
const applicationEntityClassId = libredwg.dwg_dynapi_entity_value(entity, 'class_id').data;
|
|
1128
|
+
const entityDataSize = libredwg.dwg_dynapi_entity_value(entity, 'data_numbits').data;
|
|
1129
|
+
const objectDrawingFormat = libredwg.dwg_dynapi_entity_value(entity, 'version').data;
|
|
1130
|
+
const fromDxf = libredwg.dwg_dynapi_entity_value(entity, 'from_dxf')
|
|
1131
|
+
.data;
|
|
1132
|
+
const numObjIds = libredwg.dwg_dynapi_entity_value(entity, 'num_objids')
|
|
1133
|
+
.data;
|
|
1134
|
+
const graphicsBytes = libredwg.dwg_entity_get_preview(objectPtr);
|
|
1135
|
+
const graphicsDataSize = graphicsBytes?.length ?? 0;
|
|
1136
|
+
const entityBytes = libredwg.dwg_entity_proxy_entity_get_entity_data(entity);
|
|
1137
|
+
const graphicsData = graphicsBytes
|
|
1138
|
+
? uint8ArrayToHexString(graphicsBytes)
|
|
1139
|
+
: undefined;
|
|
1140
|
+
const entityData = entityBytes
|
|
1141
|
+
? uint8ArrayToHexString(entityBytes)
|
|
1142
|
+
: undefined;
|
|
1143
|
+
let linkedObjectIds;
|
|
1144
|
+
if (numObjIds > 0) {
|
|
1145
|
+
const objidsPtr = libredwg.dwg_dynapi_entity_value(entity, 'objids')
|
|
1146
|
+
.data;
|
|
1147
|
+
if (objidsPtr) {
|
|
1148
|
+
const objids = libredwg.dwg_ptr_to_object_ref_array(objidsPtr, numObjIds);
|
|
1149
|
+
linkedObjectIds = objids.map(ref => idToString(ref.absolute_ref));
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
const originalDxfName = this.getOriginalDxfName(applicationEntityClassId);
|
|
1153
|
+
const result = {
|
|
1154
|
+
type: 'ACAD_PROXY_ENTITY',
|
|
1155
|
+
subclassMarker: 'AcDbProxyEntity',
|
|
1124
1156
|
...commonAttrs,
|
|
1125
|
-
|
|
1157
|
+
proxyEntityClassId: proxyEntityClassId || 498,
|
|
1158
|
+
applicationEntityClassId
|
|
1126
1159
|
};
|
|
1160
|
+
if (originalDxfName) {
|
|
1161
|
+
result.originalDxfName = originalDxfName;
|
|
1162
|
+
}
|
|
1163
|
+
if (graphicsDataSize > 0) {
|
|
1164
|
+
result.graphicsDataSize = graphicsDataSize;
|
|
1165
|
+
}
|
|
1166
|
+
if (graphicsData) {
|
|
1167
|
+
result.graphicsData = graphicsData;
|
|
1168
|
+
}
|
|
1169
|
+
if (entityDataSize > 0) {
|
|
1170
|
+
result.entityDataSize = entityDataSize;
|
|
1171
|
+
}
|
|
1172
|
+
if (entityData) {
|
|
1173
|
+
result.entityData = entityData;
|
|
1174
|
+
}
|
|
1175
|
+
if (linkedObjectIds && linkedObjectIds.length > 0) {
|
|
1176
|
+
result.linkedObjectIds = linkedObjectIds;
|
|
1177
|
+
}
|
|
1178
|
+
if (objectDrawingFormat) {
|
|
1179
|
+
result.objectDrawingFormat = objectDrawingFormat;
|
|
1180
|
+
}
|
|
1181
|
+
if (fromDxf === 0 || fromDxf === 1) {
|
|
1182
|
+
result.originalDataFormat =
|
|
1183
|
+
fromDxf;
|
|
1184
|
+
}
|
|
1185
|
+
return result;
|
|
1186
|
+
}
|
|
1187
|
+
getOriginalDxfName(classId) {
|
|
1188
|
+
if (this.classes.length === 0 || classId < 0) {
|
|
1189
|
+
return undefined;
|
|
1190
|
+
}
|
|
1191
|
+
const index = classId >= 500 ? classId - 500 : classId;
|
|
1192
|
+
if (index >= 0 && index < this.classes.length) {
|
|
1193
|
+
return this.classes[index].dxfName;
|
|
1194
|
+
}
|
|
1195
|
+
return undefined;
|
|
1127
1196
|
}
|
|
1128
1197
|
convertRay(entity, commonAttrs) {
|
|
1129
1198
|
const libredwg = this.libredwg;
|
package/lib/converter/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const isModelSpace: (name: string) => boolean | "";
|
|
2
2
|
export declare const isPaperSpace: (name: string) => boolean | "";
|
|
3
3
|
export declare const idToString: (id: number | bigint) => string;
|
|
4
|
+
export declare const uint8ArrayToHexString: (bytes: Uint8Array) => string;
|
|
4
5
|
//# sourceMappingURL=utils.d.ts.map
|
package/lib/converter/utils.js
CHANGED
|
@@ -9,4 +9,11 @@ export const isPaperSpace = (name) => {
|
|
|
9
9
|
export const idToString = (id) => {
|
|
10
10
|
return id.toString(16).toUpperCase();
|
|
11
11
|
};
|
|
12
|
+
export const uint8ArrayToHexString = (bytes) => {
|
|
13
|
+
const hexChars = new Array(bytes.length);
|
|
14
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
15
|
+
hexChars[i] = bytes[i].toString(16).toUpperCase().padStart(2, '0');
|
|
16
|
+
}
|
|
17
|
+
return hexChars.join('');
|
|
18
|
+
};
|
|
12
19
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1,6 +1,43 @@
|
|
|
1
|
+
import { DwgClass } from '../classes';
|
|
1
2
|
import { DwgEntity } from './entity';
|
|
3
|
+
/**
|
|
4
|
+
* Original custom object data format (DXF group 70).
|
|
5
|
+
* @see https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-89A690F9-E859-4D57-89EA-750F3FB76C6B
|
|
6
|
+
*/
|
|
7
|
+
export declare enum DwgProxyOriginalDataFormat {
|
|
8
|
+
Dwg = 0,
|
|
9
|
+
Dxf = 1
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @see https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-89A690F9-E859-4D57-89EA-750F3FB76C6B
|
|
13
|
+
*/
|
|
2
14
|
export interface DwgProxyEntity extends DwgEntity {
|
|
3
|
-
type: '
|
|
15
|
+
type: 'ACAD_PROXY_ENTITY';
|
|
16
|
+
subclassMarker: 'AcDbProxyEntity';
|
|
17
|
+
/** Proxy entity class ID (always 498) */
|
|
18
|
+
proxyEntityClassId: number;
|
|
19
|
+
/** Application entity class ID from CLASSES section order (500+) */
|
|
4
20
|
applicationEntityClassId: number;
|
|
21
|
+
/** Original DXF entity name (group 1) */
|
|
22
|
+
originalDxfName?: string;
|
|
23
|
+
/** Size of graphics data in bytes */
|
|
24
|
+
graphicsDataSize?: number;
|
|
25
|
+
/** Binary graphics data as hex string */
|
|
26
|
+
graphicsData?: string;
|
|
27
|
+
/** Size of entity data in bits */
|
|
28
|
+
entityDataSize?: number;
|
|
29
|
+
/** Binary entity data as hex string */
|
|
30
|
+
entityData?: string;
|
|
31
|
+
/** Size of unknown binary data in bytes (R2010+: group 162) */
|
|
32
|
+
unknownDataSize?: number;
|
|
33
|
+
/** Unknown binary data as hex string (group 311) */
|
|
34
|
+
unknownData?: string;
|
|
35
|
+
/** Linked object IDs from the proxy entity */
|
|
36
|
+
linkedObjectIds?: string[];
|
|
37
|
+
/** Object drawing format when it becomes a proxy */
|
|
38
|
+
objectDrawingFormat?: number;
|
|
39
|
+
/** Original custom object data format */
|
|
40
|
+
originalDataFormat?: DwgProxyOriginalDataFormat;
|
|
5
41
|
}
|
|
42
|
+
export type DwgClassLookup = Pick<DwgClass, 'dxfName'>;
|
|
6
43
|
//# sourceMappingURL=proxy.d.ts.map
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Original custom object data format (DXF group 70).
|
|
3
|
+
* @see https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-89A690F9-E859-4D57-89EA-750F3FB76C6B
|
|
4
|
+
*/
|
|
5
|
+
export var DwgProxyOriginalDataFormat;
|
|
6
|
+
(function (DwgProxyOriginalDataFormat) {
|
|
7
|
+
DwgProxyOriginalDataFormat[DwgProxyOriginalDataFormat["Dwg"] = 0] = "Dwg";
|
|
8
|
+
DwgProxyOriginalDataFormat[DwgProxyOriginalDataFormat["Dxf"] = 1] = "Dxf";
|
|
9
|
+
})(DwgProxyOriginalDataFormat || (DwgProxyOriginalDataFormat = {}));
|
|
2
10
|
//# sourceMappingURL=proxy.js.map
|
package/lib/libredwg.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MainModule } from '../wasm/libredwg-web';
|
|
2
2
|
import createModule from '../wasm/libredwg-web.js';
|
|
3
3
|
import { DwgCodePage, DwgDatabase, DwgGradientColor, DwgPoint2D, DwgPoint3D, DwgPoint4D, DwgVersion, DwgXData } from './database';
|
|
4
|
-
import { Dwg_Array_Ptr, Dwg_Class, Dwg_Color, Dwg_Data_Ptr, Dwg_Entity_BLOCK, Dwg_Entity_IMAGE_Ptr, Dwg_Entity_LWPOLYLINE_Ptr, Dwg_Entity_MTEXT_Ptr, Dwg_Entity_POLYLINE_2D_Ptr, Dwg_Entity_POLYLINE_3D_Ptr, Dwg_Entity_TEXT_Ptr, Dwg_Entity_VERTEX_2D, Dwg_Entity_VERTEX_3D, Dwg_Field_Value, Dwg_Handle, Dwg_HATCH_DefLine, Dwg_HATCH_Path, Dwg_LTYPE_Dash, Dwg_MLINE_Vertex, Dwg_Object_BLOCK_HEADER_Ptr, Dwg_Object_BLOCK_Ptr, Dwg_Object_DIMSTYLE_Ptr, Dwg_Object_Entity_Ptr, Dwg_Object_Entity_TIO_Ptr, Dwg_Object_Generic_Ptr, Dwg_Object_IMAGEDEF_Ptr, Dwg_Object_LAYER_Ptr, Dwg_Object_LTYPE_Ptr, Dwg_Object_Object_Ptr, Dwg_Object_Object_TIO_Ptr, Dwg_Object_Ptr, Dwg_Object_Ref, Dwg_Object_Ref_Ptr, Dwg_Object_STYLE_Ptr, Dwg_Object_Type, Dwg_Object_VERTEX_2D_Ptr, Dwg_Object_VERTEX_3D_Ptr, Dwg_Object_VPORT_Ptr, Dwg_TABLE_Cell } from './types';
|
|
4
|
+
import { Dwg_Array_Ptr, Dwg_Class, Dwg_Color, Dwg_Data_Ptr, Dwg_Entity_BLOCK, Dwg_Entity_IMAGE_Ptr, Dwg_Entity_LWPOLYLINE_Ptr, Dwg_Entity_MTEXT_Ptr, Dwg_Entity_POLYLINE_2D_Ptr, Dwg_Entity_POLYLINE_3D_Ptr, Dwg_Entity_PROXY_ENTITY_Ptr, Dwg_Entity_TEXT_Ptr, Dwg_Entity_VERTEX_2D, Dwg_Entity_VERTEX_3D, Dwg_Field_Value, Dwg_Handle, Dwg_HATCH_DefLine, Dwg_HATCH_Path, Dwg_LTYPE_Dash, Dwg_MLINE_Vertex, Dwg_Object_BLOCK_HEADER_Ptr, Dwg_Object_BLOCK_Ptr, Dwg_Object_DIMSTYLE_Ptr, Dwg_Object_Entity_Ptr, Dwg_Object_Entity_TIO_Ptr, Dwg_Object_Generic_Ptr, Dwg_Object_IMAGEDEF_Ptr, Dwg_Object_LAYER_Ptr, Dwg_Object_LTYPE_Ptr, Dwg_Object_Object_Ptr, Dwg_Object_Object_TIO_Ptr, Dwg_Object_Ptr, Dwg_Object_Ref, Dwg_Object_Ref_Ptr, Dwg_Object_STYLE_Ptr, Dwg_Object_Type, Dwg_Object_VERTEX_2D_Ptr, Dwg_Object_VERTEX_3D_Ptr, Dwg_Object_VPORT_Ptr, Dwg_TABLE_Cell } from './types';
|
|
5
5
|
export { createModule };
|
|
6
6
|
export type LibreDwgEx = LibreDwg & MainModule;
|
|
7
7
|
export declare enum DwgThumbnailImageType {
|
|
@@ -640,6 +640,18 @@ export declare class LibreDwg {
|
|
|
640
640
|
* @returns Returns preview image of the block pointed by the specified block header.
|
|
641
641
|
*/
|
|
642
642
|
dwg_entity_block_header_get_preview(ptr: Dwg_Object_BLOCK_HEADER_Ptr): Uint8Array;
|
|
643
|
+
/**
|
|
644
|
+
* Returns preview binary data of one entity (common entity preview field).
|
|
645
|
+
* For PROXY_ENTITY this contains the proxy graphics data.
|
|
646
|
+
*/
|
|
647
|
+
dwg_entity_get_preview(ptr: Dwg_Object_Ptr): Uint8Array | null;
|
|
648
|
+
/**
|
|
649
|
+
* Returns entity binary data of one Dwg_Entity_PROXY_ENTITY instance.
|
|
650
|
+
* @group Dwg_Entity_PROXY_ENTITY Methods
|
|
651
|
+
* @param ptr Pointer to one Dwg_Entity_PROXY_ENTITY instance.
|
|
652
|
+
* @returns Entity data bytes, or null when absent.
|
|
653
|
+
*/
|
|
654
|
+
dwg_entity_proxy_entity_get_entity_data(ptr: Dwg_Entity_PROXY_ENTITY_Ptr): Uint8Array | null;
|
|
643
655
|
/**
|
|
644
656
|
* Returns the first entity owned by the block header or null
|
|
645
657
|
* @group Dwg_Entity_BLOCK_HEADER Methods
|
package/lib/libredwg.js
CHANGED
|
@@ -2,7 +2,7 @@ import createModule from '../wasm/libredwg-web.js';
|
|
|
2
2
|
import { LibreDwgConverter } from './converter';
|
|
3
3
|
import { dwgCodePageToEncoding, dwgVersions } from './database';
|
|
4
4
|
import { SvgConverter } from './svg';
|
|
5
|
-
import { Dwg_File_Type, Dwg_Object_Type } from './types';
|
|
5
|
+
import { Dwg_Error, Dwg_File_Type, Dwg_Object_Type } from './types';
|
|
6
6
|
export { createModule };
|
|
7
7
|
export var DwgThumbnailImageType;
|
|
8
8
|
(function (DwgThumbnailImageType) {
|
|
@@ -32,8 +32,12 @@ export class LibreDwg {
|
|
|
32
32
|
try {
|
|
33
33
|
this.wasmInstance.FS.writeFile(fileName, new Uint8Array(fileContent));
|
|
34
34
|
const result = this.wasmInstance.dwg_read_file(fileName);
|
|
35
|
+
if (result.error & Dwg_Error.OUTOFMEM) {
|
|
36
|
+
this.wasmInstance.dwg_abandon(result.data);
|
|
37
|
+
throw new Error('Failed to decode DWG: out of WASM memory. Rebuild with pnpm build:wasm (INITIAL_MEMORY=1GB) or use a smaller file.');
|
|
38
|
+
}
|
|
35
39
|
if (result.error != 0) {
|
|
36
|
-
console.
|
|
40
|
+
console.warn('Open dwg file with error code:', result.error);
|
|
37
41
|
}
|
|
38
42
|
return result.data;
|
|
39
43
|
}
|
|
@@ -168,7 +172,20 @@ export class LibreDwg {
|
|
|
168
172
|
* @param data Pointer to Dwg_Data instance.
|
|
169
173
|
*/
|
|
170
174
|
dwg_free(data) {
|
|
171
|
-
|
|
175
|
+
if (!data) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
this.wasmInstance.dwg_free(data);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
try {
|
|
183
|
+
this.wasmInstance.dwg_abandon(data);
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// best effort; wasm heap may already be corrupt
|
|
187
|
+
}
|
|
188
|
+
}
|
|
172
189
|
}
|
|
173
190
|
/**
|
|
174
191
|
* Frees the object (all three structs and its fields)
|
|
@@ -933,6 +950,32 @@ export class LibreDwg {
|
|
|
933
950
|
return wasmInstance.dwg_entity_block_header_get_preview(ptr)
|
|
934
951
|
.data;
|
|
935
952
|
}
|
|
953
|
+
/**
|
|
954
|
+
* Returns preview binary data of one entity (common entity preview field).
|
|
955
|
+
* For PROXY_ENTITY this contains the proxy graphics data.
|
|
956
|
+
*/
|
|
957
|
+
dwg_entity_get_preview(ptr) {
|
|
958
|
+
const wasm = this.wasmInstance;
|
|
959
|
+
if (typeof wasm.dwg_entity_get_preview !== 'function') {
|
|
960
|
+
return null;
|
|
961
|
+
}
|
|
962
|
+
const result = wasm.dwg_entity_get_preview(ptr);
|
|
963
|
+
return result?.data ?? null;
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Returns entity binary data of one Dwg_Entity_PROXY_ENTITY instance.
|
|
967
|
+
* @group Dwg_Entity_PROXY_ENTITY Methods
|
|
968
|
+
* @param ptr Pointer to one Dwg_Entity_PROXY_ENTITY instance.
|
|
969
|
+
* @returns Entity data bytes, or null when absent.
|
|
970
|
+
*/
|
|
971
|
+
dwg_entity_proxy_entity_get_entity_data(ptr) {
|
|
972
|
+
const wasm = this.wasmInstance;
|
|
973
|
+
if (typeof wasm.dwg_entity_proxy_entity_get_entity_data !== 'function') {
|
|
974
|
+
return null;
|
|
975
|
+
}
|
|
976
|
+
const result = wasm.dwg_entity_proxy_entity_get_entity_data(ptr);
|
|
977
|
+
return result?.data ?? null;
|
|
978
|
+
}
|
|
936
979
|
/**
|
|
937
980
|
* Returns the first entity owned by the block header or null
|
|
938
981
|
* @group Dwg_Entity_BLOCK_HEADER Methods
|
package/lib/types/common.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export type Dwg_Entity_IMAGE_Ptr = number;
|
|
|
25
25
|
export type Dwg_Entity_LWPOLYLINE_Ptr = number;
|
|
26
26
|
export type Dwg_Entity_MTEXT_Ptr = number;
|
|
27
27
|
export type Dwg_Entity_TEXT_Ptr = number;
|
|
28
|
+
export type Dwg_Entity_PROXY_ENTITY_Ptr = number;
|
|
28
29
|
export interface Dwg_Handle {
|
|
29
30
|
code: number;
|
|
30
31
|
size: number;
|
package/lib/types/enums.d.ts
CHANGED
|
@@ -2,6 +2,23 @@ export declare enum Dwg_Object_Supertype {
|
|
|
2
2
|
DWG_SUPERTYPE_ENTITY = 0,
|
|
3
3
|
DWG_SUPERTYPE_OBJECT = 1
|
|
4
4
|
}
|
|
5
|
+
/** Bit flags returned by dwg_read_file (see include/dwg.h DWG_ERROR). */
|
|
6
|
+
export declare enum Dwg_Error {
|
|
7
|
+
WRONGCRC = 1,
|
|
8
|
+
NOTYETSUPPORTED = 2,
|
|
9
|
+
UNHANDLEDCLASS = 4,
|
|
10
|
+
INVALIDTYPE = 8,
|
|
11
|
+
INVALIDHANDLE = 16,
|
|
12
|
+
INVALIDEED = 32,
|
|
13
|
+
VALUEOUTOFBOUNDS = 64,
|
|
14
|
+
CLASSESNOTFOUND = 128,
|
|
15
|
+
SECTIONNOTFOUND = 256,
|
|
16
|
+
PAGENOTFOUND = 512,
|
|
17
|
+
INTERNALERROR = 1024,
|
|
18
|
+
INVALIDDWG = 2048,
|
|
19
|
+
IOERROR = 4096,
|
|
20
|
+
OUTOFMEM = 8192
|
|
21
|
+
}
|
|
5
22
|
export declare enum Dwg_Object_Type {
|
|
6
23
|
DWG_TYPE_UNUSED = 0,
|
|
7
24
|
DWG_TYPE_TEXT = 1,
|
package/lib/types/enums.js
CHANGED
|
@@ -3,6 +3,24 @@ export var Dwg_Object_Supertype;
|
|
|
3
3
|
Dwg_Object_Supertype[Dwg_Object_Supertype["DWG_SUPERTYPE_ENTITY"] = 0] = "DWG_SUPERTYPE_ENTITY";
|
|
4
4
|
Dwg_Object_Supertype[Dwg_Object_Supertype["DWG_SUPERTYPE_OBJECT"] = 1] = "DWG_SUPERTYPE_OBJECT";
|
|
5
5
|
})(Dwg_Object_Supertype || (Dwg_Object_Supertype = {}));
|
|
6
|
+
/** Bit flags returned by dwg_read_file (see include/dwg.h DWG_ERROR). */
|
|
7
|
+
export var Dwg_Error;
|
|
8
|
+
(function (Dwg_Error) {
|
|
9
|
+
Dwg_Error[Dwg_Error["WRONGCRC"] = 1] = "WRONGCRC";
|
|
10
|
+
Dwg_Error[Dwg_Error["NOTYETSUPPORTED"] = 2] = "NOTYETSUPPORTED";
|
|
11
|
+
Dwg_Error[Dwg_Error["UNHANDLEDCLASS"] = 4] = "UNHANDLEDCLASS";
|
|
12
|
+
Dwg_Error[Dwg_Error["INVALIDTYPE"] = 8] = "INVALIDTYPE";
|
|
13
|
+
Dwg_Error[Dwg_Error["INVALIDHANDLE"] = 16] = "INVALIDHANDLE";
|
|
14
|
+
Dwg_Error[Dwg_Error["INVALIDEED"] = 32] = "INVALIDEED";
|
|
15
|
+
Dwg_Error[Dwg_Error["VALUEOUTOFBOUNDS"] = 64] = "VALUEOUTOFBOUNDS";
|
|
16
|
+
Dwg_Error[Dwg_Error["CLASSESNOTFOUND"] = 128] = "CLASSESNOTFOUND";
|
|
17
|
+
Dwg_Error[Dwg_Error["SECTIONNOTFOUND"] = 256] = "SECTIONNOTFOUND";
|
|
18
|
+
Dwg_Error[Dwg_Error["PAGENOTFOUND"] = 512] = "PAGENOTFOUND";
|
|
19
|
+
Dwg_Error[Dwg_Error["INTERNALERROR"] = 1024] = "INTERNALERROR";
|
|
20
|
+
Dwg_Error[Dwg_Error["INVALIDDWG"] = 2048] = "INVALIDDWG";
|
|
21
|
+
Dwg_Error[Dwg_Error["IOERROR"] = 4096] = "IOERROR";
|
|
22
|
+
Dwg_Error[Dwg_Error["OUTOFMEM"] = 8192] = "OUTOFMEM";
|
|
23
|
+
})(Dwg_Error || (Dwg_Error = {}));
|
|
6
24
|
export var Dwg_Object_Type;
|
|
7
25
|
(function (Dwg_Object_Type) {
|
|
8
26
|
Dwg_Object_Type[Dwg_Object_Type["DWG_TYPE_UNUSED"] = 0] = "DWG_TYPE_UNUSED";
|
package/package.json
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
"description": "A DWG/DXF JavaScript parser based on libredwg",
|
|
4
4
|
"license": "GPL-3.0",
|
|
5
5
|
"private": false,
|
|
6
|
-
"version": "0.7.
|
|
6
|
+
"version": "0.7.4",
|
|
7
7
|
"author": "MLight Lee <mlight.lee@outlook.com>",
|
|
8
8
|
"type": "module",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=20"
|
|
11
|
+
},
|
|
9
12
|
"repository": {
|
|
10
13
|
"type": "git",
|
|
11
14
|
"url": "https://github.com/mlightcad/libredwg-web"
|
|
@@ -24,21 +27,6 @@
|
|
|
24
27
|
"wasm",
|
|
25
28
|
"webassembly"
|
|
26
29
|
],
|
|
27
|
-
"scripts": {
|
|
28
|
-
"demo": "live-server examples --entry-file=index.html",
|
|
29
|
-
"doc": "typedoc",
|
|
30
|
-
"build": "tsc && vite build && cp -rf wasm examples/ && cp -rf dist examples/",
|
|
31
|
-
"build:prepare": "mkdir -p ../../build-wasm && cd ../../build-wasm && emconfigure ../configure CFLAGS=\"-O2 -sUSE_ZLIB=1\" CC=emcc --enable-release --disable-docs --disable-write --disable-python --disable-bindings --disable-shared --disable-json --enable-partial --enable-experimental",
|
|
32
|
-
"build:obj": "cd ../../build-wasm && emmake make",
|
|
33
|
-
"build:wasm": "cd ../../build-wasm && emcc ../bindings/javascript/embind/*.cpp src/*.o -O2 -lembind -std=c++17 -Isrc -I../src -I../include -o libredwg-web.js -s ALLOW_MEMORY_GROWTH=1 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME=\"createModule\" -sEXPORTED_RUNTIME_METHODS=FS,ENV,ccall,cwrap,UTF8ToString,stringToNewUTF8,setValue --emit-tsd libredwg-web.d.ts",
|
|
34
|
-
"clean": "rm -rf ../../build-wasm ./docs ./dist ./lib",
|
|
35
|
-
"copy": "cp -f ../../build-wasm/libredwg-web.d.ts ../../build-wasm/libredwg-web.js ../../build-wasm/libredwg-web.wasm wasm/ && cp -f ../../build-wasm/libredwg-web.js src/",
|
|
36
|
-
"format": "prettier --config ./.prettierrc.js --write src/**/*.{ts,js}",
|
|
37
|
-
"install:emsdk": "cd $EMSDK && ./emsdk install latest && ./emsdk activate latest",
|
|
38
|
-
"link": "node script/create-symlink.js ./wasm/libredwg-web.js ./src/libredwg-web.js",
|
|
39
|
-
"lint": "eslint src/",
|
|
40
|
-
"lint:fix": "eslint --fix --quiet src/"
|
|
41
|
-
},
|
|
42
30
|
"files": [
|
|
43
31
|
"dist",
|
|
44
32
|
"lib/**/*.js",
|
|
@@ -56,6 +44,7 @@
|
|
|
56
44
|
"require": "./dist/libredwg-web.umd.cjs"
|
|
57
45
|
},
|
|
58
46
|
"devDependencies": {
|
|
47
|
+
"@eslint/js": "^9.9.1",
|
|
59
48
|
"@typescript-eslint/parser": "^8.4.0",
|
|
60
49
|
"eslint": "^9.9.1",
|
|
61
50
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -80,5 +69,23 @@
|
|
|
80
69
|
"*.md": [
|
|
81
70
|
"prettier --config ./.prettierrc.js --write"
|
|
82
71
|
]
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"demo": "live-server examples --entry-file=index.html",
|
|
75
|
+
"doc": "typedoc",
|
|
76
|
+
"build": "tsc && vite build && cp -rf wasm examples/ && cp -rf dist examples/",
|
|
77
|
+
"build:prepare": "mkdir -p ../../build-wasm && cd ../../build-wasm && emconfigure ../configure CFLAGS=\"-O2 -sUSE_ZLIB=1 -DNDEBUG\" CC=emcc --enable-release --disable-docs --disable-write --disable-python --disable-bindings --disable-shared --disable-json --enable-partial --enable-experimental",
|
|
78
|
+
"build:obj": "cd ../../build-wasm && emmake make",
|
|
79
|
+
"build:wasm": "cd ../../build-wasm && emcc ../bindings/javascript/embind/*.cpp src/*.o -O2 -lembind -std=c++17 -Isrc -I../src -I../include -o libredwg-web.js -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=1GB -s MAXIMUM_MEMORY=4GB -s MALLOC=mimalloc -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME=\"createModule\" -sEXPORTED_RUNTIME_METHODS=FS,ENV,ccall,cwrap,UTF8ToString,stringToNewUTF8,setValue --emit-tsd libredwg-web.d.ts",
|
|
80
|
+
"clean": "rm -rf ../../build-wasm ./docs ./dist ./lib",
|
|
81
|
+
"copy": "cp -f ../../build-wasm/libredwg-web.d.ts ../../build-wasm/libredwg-web.js ../../build-wasm/libredwg-web.wasm wasm/ && cp -f ../../build-wasm/libredwg-web.js src/",
|
|
82
|
+
"format": "prettier --config ./.prettierrc.js --write src/**/*.{ts,js}",
|
|
83
|
+
"install:emsdk": "cd $EMSDK && ./emsdk install latest && ./emsdk activate latest",
|
|
84
|
+
"link": "node script/create-symlink.js ./wasm/libredwg-web.js ./src/libredwg-web.js",
|
|
85
|
+
"lint": "eslint src/",
|
|
86
|
+
"lint:fix": "eslint --fix --quiet src/",
|
|
87
|
+
"test": "node --test test/node-api.test.mjs",
|
|
88
|
+
"test:node": "pnpm build && pnpm test",
|
|
89
|
+
"publish:npm": "pnpm publish --access public --no-git-checks"
|
|
83
90
|
}
|
|
84
|
-
}
|
|
91
|
+
}
|