@mlightcad/libredwg-web 0.6.5 → 0.6.7
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 +102 -6
- package/dist/libredwg-web.umd.cjs +102 -6
- package/lib/converter/converter.js +24 -2
- package/lib/converter/entityConverter.d.ts +1 -0
- package/lib/converter/entityConverter.js +56 -5
- package/lib/database/entities/attrib.d.ts +1 -1
- package/lib/database/entities/insert.d.ts +5 -0
- package/lib/enums.d.ts +340 -0
- package/lib/enums.js +351 -0
- package/lib/libredwg-web.js +33 -32
- package/lib/libredwg.d.ts +7 -0
- package/lib/libredwg.js +11 -0
- package/lib/svg/ToSVG.d.ts +16 -0
- package/lib/svg/ToSVG.js +235 -0
- package/lib/svg/util/boundingBox.d.ts +9 -0
- package/lib/svg/util/boundingBox.js +19 -0
- package/lib/svg/util/box2d.d.ts +9 -0
- package/lib/svg/util/box2d.js +19 -0
- package/lib/svg/util/denormalise.d.ts +19 -0
- package/lib/svg/util/denormalise.js +24 -0
- package/lib/svg/util/entityToPolyline.d.ts +2 -0
- package/lib/svg/util/entityToPolyline.js +5 -0
- package/lib/svg/util/getRGBForEntity.d.ts +3 -0
- package/lib/svg/util/getRGBForEntity.js +9 -0
- package/lib/svg/util/rgbToColorAttribute.d.ts +6 -0
- package/lib/svg/util/rgbToColorAttribute.js +4 -0
- package/lib/svg/util/rotate.d.ts +6 -0
- package/lib/svg/util/rotate.js +9 -0
- package/lib/svg/util/toPiecewiseBezier.d.ts +9 -0
- package/lib/svg/util/toPiecewiseBezier.js +24 -0
- package/lib/svg/util/transformBoundingBoxAndElement.d.ts +19 -0
- package/lib/svg/util/transformBoundingBoxAndElement.js +20 -0
- package/lib/types/common.d.ts +2 -1
- package/lib/types/database.d.ts +17 -0
- package/lib/types/database.js +2 -0
- package/lib/types/entities/arc.d.ts +12 -0
- package/lib/types/entities/arc.js +2 -0
- package/lib/types/entities/circle.d.ts +10 -0
- package/lib/types/entities/circle.js +2 -0
- package/lib/types/entities/dimension.d.ts +108 -0
- package/lib/types/entities/dimension.js +2 -0
- package/lib/types/entities/ellipse.d.ts +12 -0
- package/lib/types/entities/ellipse.js +2 -0
- package/lib/types/entities/entity.d.ts +25 -0
- package/lib/types/entities/entity.js +2 -0
- package/lib/types/entities/hatch.d.ts +142 -0
- package/lib/types/entities/hatch.js +2 -0
- package/lib/types/entities/image.d.ts +36 -0
- package/lib/types/entities/image.js +2 -0
- package/lib/types/entities/index.d.ts +24 -0
- package/lib/types/entities/index.js +24 -0
- package/lib/types/entities/insert.d.ts +18 -0
- package/lib/types/entities/insert.js +2 -0
- package/lib/types/entities/leader.d.ts +28 -0
- package/lib/types/entities/leader.js +2 -0
- package/lib/types/entities/line.d.ts +10 -0
- package/lib/types/entities/line.js +2 -0
- package/lib/types/entities/lwpolyline.d.ts +19 -0
- package/lib/types/entities/lwpolyline.js +2 -0
- package/lib/types/entities/mtext.d.ts +37 -0
- package/lib/types/entities/mtext.js +2 -0
- package/lib/types/entities/point.d.ts +10 -0
- package/lib/types/entities/point.js +2 -0
- package/lib/types/entities/polyline.d.ts +34 -0
- package/lib/types/entities/polyline.js +2 -0
- package/lib/types/entities/ray.d.ts +8 -0
- package/lib/types/entities/ray.js +2 -0
- package/lib/types/entities/section.d.ts +19 -0
- package/lib/types/entities/section.js +2 -0
- package/lib/types/entities/solid.d.ts +9 -0
- package/lib/types/entities/solid.js +2 -0
- package/lib/types/entities/spline.d.ts +21 -0
- package/lib/types/entities/spline.js +2 -0
- package/lib/types/entities/table.d.ts +52 -0
- package/lib/types/entities/table.js +2 -0
- package/lib/types/entities/text.d.ts +38 -0
- package/lib/types/entities/text.js +2 -0
- package/lib/types/entities/vertex.d.ts +25 -0
- package/lib/types/entities/vertex.js +2 -0
- package/lib/types/entities/viewport.d.ts +105 -0
- package/lib/types/entities/viewport.js +2 -0
- package/lib/types/entities/xline.d.ts +8 -0
- package/lib/types/entities/xline.js +2 -0
- package/lib/types/enums.d.ts +8 -0
- package/lib/types/enums.js +9 -0
- package/lib/types/objects/common.d.ts +5 -0
- package/lib/types/objects/common.js +2 -0
- package/lib/types/objects/imageDef.d.ts +10 -0
- package/lib/types/objects/imageDef.js +2 -0
- package/lib/types/objects/index.d.ts +5 -0
- package/lib/types/objects/index.js +5 -0
- package/lib/types/objects/layout.d.ts +23 -0
- package/lib/types/objects/layout.js +2 -0
- package/lib/types/objects/plotSetting.d.ts +35 -0
- package/lib/types/objects/plotSetting.js +2 -0
- package/lib/types/shared/xdata.d.ts +10 -0
- package/lib/types/shared/xdata.js +2 -0
- package/lib/types/tables/blockRecord.d.ts +12 -0
- package/lib/types/tables/blockRecord.js +2 -0
- package/lib/types/tables/dimStyle.d.ts +84 -0
- package/lib/types/tables/dimStyle.js +2 -0
- package/lib/types/tables/index.d.ts +8 -0
- package/lib/types/tables/index.js +8 -0
- package/lib/types/tables/layer.d.ts +16 -0
- package/lib/types/tables/layer.js +2 -0
- package/lib/types/tables/ltype.d.ts +21 -0
- package/lib/types/tables/ltype.js +2 -0
- package/lib/types/tables/style.d.ts +13 -0
- package/lib/types/tables/style.js +2 -0
- package/lib/types/tables/table.d.ts +9 -0
- package/lib/types/tables/table.js +2 -0
- package/lib/types/tables/vport.d.ts +42 -0
- package/lib/types/tables/vport.js +2 -0
- package/package.json +1 -1
- package/wasm/libredwg-web.d.ts +1 -0
- package/wasm/libredwg-web.wasm +0 -0
- package/lib/converter/stringConverter.d.ts +0 -3
- package/lib/converter/stringConverter.js +0 -7
- package/lib/database/entities/unknown.d.ts +0 -7
- package/lib/database/entities/unknown.js +0 -2
- package/lib/database/objects/unknown.d.ts +0 -7
- package/lib/database/objects/unknown.js +0 -2
- package/lib/utils/common.d.ts +0 -4
- package/lib/utils/common.js +0 -12
- package/lib/utils/index.d.ts +0 -2
- package/lib/utils/index.js +0 -2
package/lib/svg/ToSVG.js
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { entityToPolyline } from './util/entityToPolyline';
|
|
2
|
+
import { denormalise } from './util/denormalise';
|
|
3
|
+
import { rotate } from './util/rotate';
|
|
4
|
+
import { rgbToColorAttribute } from './util/rgbToColorAttribute';
|
|
5
|
+
import { toPiecewiseBezier, multiplicity } from './util/toPiecewiseBezier';
|
|
6
|
+
import { transformBoundingBoxAndElement } from './util/transformBoundingBoxAndElement';
|
|
7
|
+
import { BoundingBox } from './util/boundingBox';
|
|
8
|
+
import { Color } from './color';
|
|
9
|
+
export class LibreDwgSVGConverter {
|
|
10
|
+
addFlipXIfApplicable(entity, { bbox, element }) {
|
|
11
|
+
if (entity.extrusionZ === -1) {
|
|
12
|
+
return {
|
|
13
|
+
bbox: new BoundingBox()
|
|
14
|
+
.expandByPoint({ x: -bbox.min.x, y: bbox.min.y })
|
|
15
|
+
.expandByPoint({ x: -bbox.max.x, y: bbox.max.y }),
|
|
16
|
+
element: `<g transform="matrix(-1 0 0 1 0 0)">${element}</g>`
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return { bbox, element };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
polyline(entity) {
|
|
24
|
+
const vertices = entityToPolyline(entity);
|
|
25
|
+
const bbox = vertices.reduce((acc, [x, y]) => acc.expandByPoint({ x, y }), new BoundingBox());
|
|
26
|
+
const d = vertices.reduce((acc, point, i) => {
|
|
27
|
+
acc += i === 0 ? 'M' : 'L';
|
|
28
|
+
acc += point[0] + ',' + point[1];
|
|
29
|
+
return acc;
|
|
30
|
+
}, '');
|
|
31
|
+
return transformBoundingBoxAndElement(bbox, `<path d="${d}" />`, entity.transforms);
|
|
32
|
+
}
|
|
33
|
+
circle(entity) {
|
|
34
|
+
const bbox0 = new BoundingBox()
|
|
35
|
+
.expandByPoint({ x: entity.x + entity.r, y: entity.y + entity.r })
|
|
36
|
+
.expandByPoint({ x: entity.x - entity.r, y: entity.y - entity.r });
|
|
37
|
+
const element0 = `<circle cx="${entity.x}" cy="${entity.y}" r="${entity.r}" />`;
|
|
38
|
+
const { bbox, element } = this.addFlipXIfApplicable(entity, {
|
|
39
|
+
bbox: bbox0,
|
|
40
|
+
element: element0
|
|
41
|
+
});
|
|
42
|
+
return transformBoundingBoxAndElement(bbox, element, entity.transforms);
|
|
43
|
+
}
|
|
44
|
+
ellipseOrArc(cx, cy, majorX, majorY, axisRatio, startAngle, endAngle) {
|
|
45
|
+
const rx = Math.sqrt(majorX * majorX + majorY * majorY);
|
|
46
|
+
const ry = axisRatio * rx;
|
|
47
|
+
const rotationAngle = -Math.atan2(-majorY, majorX);
|
|
48
|
+
const bbox = this.bboxEllipseOrArc(cx, cy, majorX, majorY, axisRatio, startAngle, endAngle);
|
|
49
|
+
if (Math.abs(startAngle - endAngle) < 1e-9 ||
|
|
50
|
+
Math.abs(startAngle - endAngle + Math.PI * 2) < 1e-9) {
|
|
51
|
+
const element = `<g transform="rotate(${(rotationAngle / Math.PI) * 180} ${cx}, ${cy})"><ellipse cx="${cx}" cy="${cy}" rx="${rx}" ry="${ry}" /></g>`;
|
|
52
|
+
return { bbox, element };
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const startOffset = rotate({ x: Math.cos(startAngle) * rx, y: Math.sin(startAngle) * ry }, rotationAngle);
|
|
56
|
+
const startPoint = { x: cx + startOffset.x, y: cy + startOffset.y };
|
|
57
|
+
const endOffset = rotate({ x: Math.cos(endAngle) * rx, y: Math.sin(endAngle) * ry }, rotationAngle);
|
|
58
|
+
const endPoint = { x: cx + endOffset.x, y: cy + endOffset.y };
|
|
59
|
+
const adjustedEndAngle = endAngle < startAngle ? endAngle + Math.PI * 2 : endAngle;
|
|
60
|
+
const largeArcFlag = adjustedEndAngle - startAngle < Math.PI ? 0 : 1;
|
|
61
|
+
const d = `M ${startPoint.x} ${startPoint.y} A ${rx} ${ry} ${(rotationAngle / Math.PI) * 180} ${largeArcFlag} 1 ${endPoint.x} ${endPoint.y}`;
|
|
62
|
+
const element = `<path d="${d}" />`;
|
|
63
|
+
return { bbox, element };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
bboxEllipseOrArc(cx, cy, majorX, majorY, axisRatio, startAngle, endAngle) {
|
|
67
|
+
while (startAngle < 0)
|
|
68
|
+
startAngle += Math.PI * 2;
|
|
69
|
+
while (endAngle <= startAngle)
|
|
70
|
+
endAngle += Math.PI * 2;
|
|
71
|
+
const angles = [];
|
|
72
|
+
if (Math.abs(majorX) < 1e-12 || Math.abs(majorY) < 1e-12) {
|
|
73
|
+
for (let i = 0; i < 4; i++) {
|
|
74
|
+
angles.push((i / 2) * Math.PI);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
angles[0] = Math.atan((-majorY * axisRatio) / majorX) - Math.PI;
|
|
79
|
+
angles[1] = Math.atan((majorX * axisRatio) / majorY) - Math.PI;
|
|
80
|
+
angles[2] = angles[0] - Math.PI;
|
|
81
|
+
angles[3] = angles[1] - Math.PI;
|
|
82
|
+
}
|
|
83
|
+
for (let i = 4; i >= 0; i--) {
|
|
84
|
+
while (angles[i] < startAngle)
|
|
85
|
+
angles[i] += Math.PI * 2;
|
|
86
|
+
if (angles[i] > endAngle) {
|
|
87
|
+
angles.splice(i, 1);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
angles.push(startAngle);
|
|
91
|
+
angles.push(endAngle);
|
|
92
|
+
const pts = angles.map(a => ({ x: Math.cos(a), y: Math.sin(a) }));
|
|
93
|
+
const M = [
|
|
94
|
+
[majorX, -majorY * axisRatio],
|
|
95
|
+
[majorY, majorX * axisRatio]
|
|
96
|
+
];
|
|
97
|
+
const rotatedPts = pts.map(p => ({
|
|
98
|
+
x: p.x * M[0][0] + p.y * M[0][1] + cx,
|
|
99
|
+
y: p.x * M[1][0] + p.y * M[1][1] + cy
|
|
100
|
+
}));
|
|
101
|
+
const bbox = rotatedPts.reduce((acc, p) => {
|
|
102
|
+
acc.expandByPoint(p);
|
|
103
|
+
return acc;
|
|
104
|
+
}, new BoundingBox());
|
|
105
|
+
return bbox;
|
|
106
|
+
}
|
|
107
|
+
ellipse(entity) {
|
|
108
|
+
const { bbox: bbox0, element: element0 } = this.ellipseOrArc(entity.x, entity.y, entity.majorX, entity.majorY, entity.axisRatio, entity.startAngle, entity.endAngle);
|
|
109
|
+
const { bbox, element } = this.addFlipXIfApplicable(entity, {
|
|
110
|
+
bbox: bbox0,
|
|
111
|
+
element: element0
|
|
112
|
+
});
|
|
113
|
+
return transformBoundingBoxAndElement(bbox, element, entity.transforms);
|
|
114
|
+
}
|
|
115
|
+
arc(entity) {
|
|
116
|
+
const { bbox: bbox0, element: element0 } = this.ellipseOrArc(entity.x, entity.y, entity.r, 0, 1, entity.startAngle, entity.endAngle);
|
|
117
|
+
const { bbox, element } = this.addFlipXIfApplicable(entity, {
|
|
118
|
+
bbox: bbox0,
|
|
119
|
+
element: element0
|
|
120
|
+
});
|
|
121
|
+
return transformBoundingBoxAndElement(bbox, element, entity.transforms);
|
|
122
|
+
}
|
|
123
|
+
piecewiseToPaths(k, knots, controlPoints) {
|
|
124
|
+
const paths = [];
|
|
125
|
+
let controlPointIndex = 0;
|
|
126
|
+
let knotIndex = k;
|
|
127
|
+
while (knotIndex < knots.length - k + 1) {
|
|
128
|
+
const m = multiplicity(knots, knotIndex);
|
|
129
|
+
const cp = controlPoints.slice(controlPointIndex, controlPointIndex + k);
|
|
130
|
+
if (k === 4) {
|
|
131
|
+
paths.push(`<path d="M ${cp[0].x} ${cp[0].y} C ${cp[1].x} ${cp[1].y} ${cp[2].x} ${cp[2].y} ${cp[3].x} ${cp[3].y}" />`);
|
|
132
|
+
}
|
|
133
|
+
else if (k === 3) {
|
|
134
|
+
paths.push(`<path d="M ${cp[0].x} ${cp[0].y} Q ${cp[1].x} ${cp[1].y} ${cp[2].x} ${cp[2].y}" />`);
|
|
135
|
+
}
|
|
136
|
+
controlPointIndex += m;
|
|
137
|
+
knotIndex += m;
|
|
138
|
+
}
|
|
139
|
+
return paths;
|
|
140
|
+
}
|
|
141
|
+
bezier(entity) {
|
|
142
|
+
let bbox = new BoundingBox();
|
|
143
|
+
entity.controlPoints.forEach((p) => {
|
|
144
|
+
bbox = bbox.expandByPoint(p);
|
|
145
|
+
});
|
|
146
|
+
const k = entity.degree + 1;
|
|
147
|
+
const piecewise = toPiecewiseBezier(k, entity.controlPoints, entity.knots);
|
|
148
|
+
const paths = this.piecewiseToPaths(k, piecewise.knots, piecewise.controlPoints);
|
|
149
|
+
const element = `<g>${paths.join('')}</g>`;
|
|
150
|
+
return transformBoundingBoxAndElement(bbox, element, entity.transforms);
|
|
151
|
+
}
|
|
152
|
+
entityToBoundsAndElement(entity) {
|
|
153
|
+
switch (entity.type) {
|
|
154
|
+
case 'CIRCLE':
|
|
155
|
+
return this.circle(entity);
|
|
156
|
+
case 'ELLIPSE':
|
|
157
|
+
return this.ellipse(entity);
|
|
158
|
+
case 'ARC':
|
|
159
|
+
return this.arc(entity);
|
|
160
|
+
case 'SPLINE': {
|
|
161
|
+
const hasWeights = entity.weights && entity.weights.some((w) => w !== 1);
|
|
162
|
+
if ((entity.degree === 2 || entity.degree === 3) && !hasWeights) {
|
|
163
|
+
try {
|
|
164
|
+
return this.bezier(entity);
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
return this.polyline(entity);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
return this.polyline(entity);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
case 'LINE':
|
|
175
|
+
case 'LWPOLYLINE':
|
|
176
|
+
case 'POLYLINE':
|
|
177
|
+
return this.polyline(entity);
|
|
178
|
+
default:
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
getEntityColor(layers, entity) {
|
|
183
|
+
const layer = layers.find((layer) => layer.name === entity.layer);
|
|
184
|
+
if (layer) {
|
|
185
|
+
const color = new Color(layer.colorIndex);
|
|
186
|
+
return `rgb(${color.red}, ${color.green}, ${color.blue})`;
|
|
187
|
+
}
|
|
188
|
+
return "rgb(0, 0, 0)"; // Default to black if layer not found
|
|
189
|
+
}
|
|
190
|
+
convert(dwg) {
|
|
191
|
+
const entities = denormalise(dwg);
|
|
192
|
+
const { bbox, elements } = entities.reduce((acc, entity) => {
|
|
193
|
+
const rgb = this.getEntityColor(dwg.tables.LAYER.entries, entity);
|
|
194
|
+
const boundsAndElement = this.entityToBoundsAndElement(entity);
|
|
195
|
+
if (boundsAndElement) {
|
|
196
|
+
const { bbox, element } = boundsAndElement;
|
|
197
|
+
if (bbox.valid) {
|
|
198
|
+
acc.bbox.expandByPoint(bbox.min);
|
|
199
|
+
acc.bbox.expandByPoint(bbox.max);
|
|
200
|
+
}
|
|
201
|
+
acc.elements.push(`<g stroke="${rgbToColorAttribute(rgb)}">${element}</g>`);
|
|
202
|
+
}
|
|
203
|
+
return acc;
|
|
204
|
+
}, {
|
|
205
|
+
bbox: new BoundingBox(),
|
|
206
|
+
elements: []
|
|
207
|
+
});
|
|
208
|
+
const viewBox = bbox.valid
|
|
209
|
+
? {
|
|
210
|
+
x: bbox.min.x,
|
|
211
|
+
y: -bbox.max.y,
|
|
212
|
+
width: bbox.max.x - bbox.min.x,
|
|
213
|
+
height: bbox.max.y - bbox.min.y
|
|
214
|
+
}
|
|
215
|
+
: {
|
|
216
|
+
x: 0,
|
|
217
|
+
y: 0,
|
|
218
|
+
width: 0,
|
|
219
|
+
height: 0
|
|
220
|
+
};
|
|
221
|
+
return `<?xml version="1.0"?>
|
|
222
|
+
<svg
|
|
223
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
224
|
+
xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"
|
|
225
|
+
preserveAspectRatio="xMinYMin meet"
|
|
226
|
+
viewBox="${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}"
|
|
227
|
+
width="100%" height="100%"
|
|
228
|
+
>
|
|
229
|
+
<g stroke="#000000" stroke-width="0.1%" fill="none" transform="matrix(1,0,0,-1,0,0)">
|
|
230
|
+
${elements.join('\n')}
|
|
231
|
+
</g>
|
|
232
|
+
</svg>`;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=ToSVG.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class BoundingBox {
|
|
2
|
+
min;
|
|
3
|
+
max;
|
|
4
|
+
valid;
|
|
5
|
+
constructor() {
|
|
6
|
+
this.min = { x: Infinity, y: Infinity };
|
|
7
|
+
this.max = { x: -Infinity, y: -Infinity };
|
|
8
|
+
this.valid = false;
|
|
9
|
+
}
|
|
10
|
+
expandByPoint(point) {
|
|
11
|
+
this.min.x = Math.min(this.min.x, point.x);
|
|
12
|
+
this.min.y = Math.min(this.min.y, point.y);
|
|
13
|
+
this.max.x = Math.max(this.max.x, point.x);
|
|
14
|
+
this.max.y = Math.max(this.max.y, point.y);
|
|
15
|
+
this.valid = true;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=boundingBox.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class Box2D {
|
|
2
|
+
min;
|
|
3
|
+
max;
|
|
4
|
+
valid;
|
|
5
|
+
constructor() {
|
|
6
|
+
this.min = { x: Infinity, y: Infinity };
|
|
7
|
+
this.max = { x: -Infinity, y: -Infinity };
|
|
8
|
+
this.valid = false;
|
|
9
|
+
}
|
|
10
|
+
expandByPoint(point) {
|
|
11
|
+
this.min.x = Math.min(this.min.x, point.x);
|
|
12
|
+
this.min.y = Math.min(this.min.y, point.y);
|
|
13
|
+
this.max.x = Math.max(this.max.x, point.x);
|
|
14
|
+
this.max.y = Math.max(this.max.y, point.y);
|
|
15
|
+
this.valid = true;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=box2d.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DwgDatabase } from '../../database';
|
|
2
|
+
export declare const denormalise: (dwg: DwgDatabase) => {
|
|
3
|
+
type: string;
|
|
4
|
+
x: any;
|
|
5
|
+
y: any;
|
|
6
|
+
r: any;
|
|
7
|
+
majorX: any;
|
|
8
|
+
majorY: any;
|
|
9
|
+
axisRatio: any;
|
|
10
|
+
startAngle: any;
|
|
11
|
+
endAngle: any;
|
|
12
|
+
extrusionZ: any;
|
|
13
|
+
transforms: any;
|
|
14
|
+
controlPoints: any;
|
|
15
|
+
knots: any;
|
|
16
|
+
degree: any;
|
|
17
|
+
weights: any;
|
|
18
|
+
}[];
|
|
19
|
+
//# sourceMappingURL=denormalise.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const denormalise = (dwg) => {
|
|
2
|
+
// Implement the logic to process the parsed DXF data
|
|
3
|
+
// This function should convert the parsed data into a format suitable for SVG conversion
|
|
4
|
+
// For example, it might involve flattening nested structures or extracting relevant properties
|
|
5
|
+
// Placeholder implementation
|
|
6
|
+
return dwg.entities.map((entity) => ({
|
|
7
|
+
type: entity.type,
|
|
8
|
+
x: entity.x,
|
|
9
|
+
y: entity.y,
|
|
10
|
+
r: entity.r,
|
|
11
|
+
majorX: entity.majorX,
|
|
12
|
+
majorY: entity.majorY,
|
|
13
|
+
axisRatio: entity.axisRatio,
|
|
14
|
+
startAngle: entity.startAngle,
|
|
15
|
+
endAngle: entity.endAngle,
|
|
16
|
+
extrusionZ: entity.extrusionZ,
|
|
17
|
+
transforms: entity.transforms,
|
|
18
|
+
controlPoints: entity.controlPoints,
|
|
19
|
+
knots: entity.knots,
|
|
20
|
+
degree: entity.degree,
|
|
21
|
+
weights: entity.weights,
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=denormalise.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default function getRGBForEntity(layers, entity) {
|
|
2
|
+
const layer = layers.find((layer) => layer.name === entity.layer);
|
|
3
|
+
if (layer) {
|
|
4
|
+
const { r, g, b } = layer.color;
|
|
5
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
6
|
+
}
|
|
7
|
+
return "rgb(0, 0, 0)"; // Default to black if layer not found
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=getRGBForEntity.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const toPiecewiseBezier: (k: number, controlPoints: {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
}[], knots: number[]) => {
|
|
5
|
+
knots: never[];
|
|
6
|
+
controlPoints: never[];
|
|
7
|
+
};
|
|
8
|
+
export declare const multiplicity: (knots: number[], index: number) => number;
|
|
9
|
+
//# sourceMappingURL=toPiecewiseBezier.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const toPiecewiseBezier = (k, controlPoints, knots) => {
|
|
2
|
+
const piecewise = { knots: [], controlPoints: [] };
|
|
3
|
+
let controlPointIndex = 0;
|
|
4
|
+
let knotIndex = k;
|
|
5
|
+
while (knotIndex < knots.length - k + 1) {
|
|
6
|
+
const m = multiplicity(knots, knotIndex);
|
|
7
|
+
const cp = controlPoints.slice(controlPointIndex, controlPointIndex + k);
|
|
8
|
+
piecewise.knots.push(...knots.slice(knotIndex, knotIndex + m));
|
|
9
|
+
piecewise.controlPoints.push(...cp);
|
|
10
|
+
controlPointIndex += m;
|
|
11
|
+
knotIndex += m;
|
|
12
|
+
}
|
|
13
|
+
return piecewise;
|
|
14
|
+
};
|
|
15
|
+
export const multiplicity = (knots, index) => {
|
|
16
|
+
let count = 0;
|
|
17
|
+
const knotValue = knots[index];
|
|
18
|
+
while (index < knots.length && knots[index] === knotValue) {
|
|
19
|
+
count++;
|
|
20
|
+
index++;
|
|
21
|
+
}
|
|
22
|
+
return count;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=toPiecewiseBezier.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Box2D } from "../box2d";
|
|
2
|
+
type Transform = {
|
|
3
|
+
type: "translate";
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
} | {
|
|
7
|
+
type: "rotate";
|
|
8
|
+
angle: number;
|
|
9
|
+
} | {
|
|
10
|
+
type: "scale";
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
};
|
|
14
|
+
export declare const transformBoundingBoxAndElement: (bbox: Box2D, element: string, transforms: Transform[] | undefined) => {
|
|
15
|
+
bbox: Box2D;
|
|
16
|
+
element: string;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=transformBoundingBoxAndElement.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const transformBoundingBoxAndElement = (bbox, element, transforms) => {
|
|
2
|
+
if (!transforms || transforms.length === 0) {
|
|
3
|
+
return { bbox, element };
|
|
4
|
+
}
|
|
5
|
+
let transformedElement = element;
|
|
6
|
+
transforms.forEach((transform) => {
|
|
7
|
+
// Apply each transformation to the element
|
|
8
|
+
if (transform.type === "translate") {
|
|
9
|
+
transformedElement = `<g transform="translate(${transform.x}, ${transform.y})">${transformedElement}</g>`;
|
|
10
|
+
}
|
|
11
|
+
else if (transform.type === "rotate") {
|
|
12
|
+
transformedElement = `<g transform="rotate(${transform.angle})">${transformedElement}</g>`;
|
|
13
|
+
}
|
|
14
|
+
else if (transform.type === "scale") {
|
|
15
|
+
transformedElement = `<g transform="scale(${transform.x}, ${transform.y})">${transformedElement}</g>`;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return { bbox, element: transformedElement };
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=transformBoundingBoxAndElement.js.map
|
package/lib/types/common.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DwgPoint2D, DwgPoint2DWithWeight, DwgPoint3D } from '../database';
|
|
2
|
+
import { Dwg_Color_Method } from './enums';
|
|
2
3
|
export type Dwg_Array_Ptr = number;
|
|
3
4
|
export type Dwg_Data_Ptr = number;
|
|
4
5
|
export type Dwg_Object_Ptr = number;
|
|
@@ -68,7 +69,7 @@ export interface Dwg_Color {
|
|
|
68
69
|
* - 0xc5 for foreground color
|
|
69
70
|
* - 0xc8 for none (also c3 and rgb of 0x101)
|
|
70
71
|
*/
|
|
71
|
-
method:
|
|
72
|
+
method: Dwg_Color_Method;
|
|
72
73
|
/**
|
|
73
74
|
* DXF 430
|
|
74
75
|
*/
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DwgImageDefObject, DwgLayoutObject } from './objects';
|
|
2
|
+
import { DwgBlockRecordTableEntry, DwgDimStyleTableEntry, DwgLayerTableEntry, DwgLTypeTableEntry, DwgStyleTableEntry, DwgTable, DwgVPortTableEntry } from './tables';
|
|
3
|
+
export interface DwgDatabase {
|
|
4
|
+
tables: {
|
|
5
|
+
BLOCK_RECORD: DwgTable<DwgBlockRecordTableEntry>;
|
|
6
|
+
DIMSTYLE: DwgTable<DwgDimStyleTableEntry>;
|
|
7
|
+
LAYER: DwgTable<DwgLayerTableEntry>;
|
|
8
|
+
LTYPE: DwgTable<DwgLTypeTableEntry>;
|
|
9
|
+
STYLE: DwgTable<DwgStyleTableEntry>;
|
|
10
|
+
VPORT: DwgTable<DwgVPortTableEntry>;
|
|
11
|
+
};
|
|
12
|
+
objects: {
|
|
13
|
+
IMAGEDEF: DwgImageDefObject[];
|
|
14
|
+
LAYOUT: DwgLayoutObject[];
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=database.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DwgPoint3D } from '../common';
|
|
2
|
+
import { DwgEntity } from './entity';
|
|
3
|
+
export interface DwgArcEntity extends DwgEntity {
|
|
4
|
+
type: 'ARC';
|
|
5
|
+
thickness: number;
|
|
6
|
+
center: DwgPoint3D;
|
|
7
|
+
radius: number;
|
|
8
|
+
startAngle: number;
|
|
9
|
+
endAngle: number;
|
|
10
|
+
extrusionDirection: DwgPoint3D;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=arc.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DwgPoint3D } from '../common';
|
|
2
|
+
import { DwgEntity } from './entity';
|
|
3
|
+
export interface DwgCircleEntity extends DwgEntity {
|
|
4
|
+
type: 'CIRCLE';
|
|
5
|
+
thickness: number;
|
|
6
|
+
center: DwgPoint3D;
|
|
7
|
+
radius: number;
|
|
8
|
+
extrusionDirection: DwgPoint3D;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=circle.d.ts.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { DwgPoint3D } from '../common';
|
|
2
|
+
import { DwgEntity } from './entity';
|
|
3
|
+
export declare enum DwgDimensionType {
|
|
4
|
+
Rotated = 0,
|
|
5
|
+
Aligned = 1,
|
|
6
|
+
Angular = 2,
|
|
7
|
+
Diameter = 3,
|
|
8
|
+
Radius = 4,
|
|
9
|
+
Angular3Point = 5,
|
|
10
|
+
Ordinate = 6,
|
|
11
|
+
ReferenceIsExclusive = 32,
|
|
12
|
+
IsOrdinateXTypeFlag = 64,
|
|
13
|
+
IsCustomTextPositionFlag = 128
|
|
14
|
+
}
|
|
15
|
+
export declare enum DwgAttachmentPoint {
|
|
16
|
+
TopLeft = 1,
|
|
17
|
+
TopCenter = 2,
|
|
18
|
+
TopRight = 3,
|
|
19
|
+
MiddleLeft = 4,
|
|
20
|
+
MiddleCenter = 5,
|
|
21
|
+
MiddleRight = 6,
|
|
22
|
+
BottomLeft = 7,
|
|
23
|
+
BottomCenter = 8,
|
|
24
|
+
BottomRight = 9
|
|
25
|
+
}
|
|
26
|
+
export declare enum DwgDimensionTextLineSpacing {
|
|
27
|
+
AtLeast = 1,
|
|
28
|
+
Exact = 2
|
|
29
|
+
}
|
|
30
|
+
export declare enum DwgDimensionTextVertical {
|
|
31
|
+
Center = 0,
|
|
32
|
+
Above = 1,
|
|
33
|
+
Outside = 2,
|
|
34
|
+
JIS = 3,
|
|
35
|
+
Below = 4
|
|
36
|
+
}
|
|
37
|
+
export declare enum DwgDimensionZeroSuppression {
|
|
38
|
+
Feet = 0,
|
|
39
|
+
None = 1,
|
|
40
|
+
Inch = 2,
|
|
41
|
+
FeetAndInch = 3,
|
|
42
|
+
Leading = 4,
|
|
43
|
+
Trailing = 8,
|
|
44
|
+
LeadingAndTrailing = 12
|
|
45
|
+
}
|
|
46
|
+
export declare enum DwgDimensionZeroSuppressionAngular {
|
|
47
|
+
None = 0,
|
|
48
|
+
Leading = 1,
|
|
49
|
+
Trailing = 2,
|
|
50
|
+
LeadingAndTrailing = 3
|
|
51
|
+
}
|
|
52
|
+
export declare enum DwgDimensionTextHorizontal {
|
|
53
|
+
Center = 0,
|
|
54
|
+
Left = 1,
|
|
55
|
+
Right = 2,
|
|
56
|
+
OverFirst = 3,
|
|
57
|
+
OverSecond = 4
|
|
58
|
+
}
|
|
59
|
+
export declare enum DwgDimensionToleranceTextVertical {
|
|
60
|
+
Bottom = 0,
|
|
61
|
+
Center = 1,
|
|
62
|
+
Top = 2
|
|
63
|
+
}
|
|
64
|
+
export interface DwgDimensionEntityCommon extends DwgEntity {
|
|
65
|
+
type: 'DIMENSION';
|
|
66
|
+
subclassMarker: string;
|
|
67
|
+
version: string;
|
|
68
|
+
name: string;
|
|
69
|
+
definitionPoint: DwgPoint3D;
|
|
70
|
+
textPoint: DwgPoint3D;
|
|
71
|
+
dimensionType: DwgDimensionType;
|
|
72
|
+
attachmentPoint: DwgAttachmentPoint;
|
|
73
|
+
textLineSpacingStyle?: DwgDimensionTextLineSpacing;
|
|
74
|
+
textLineSpacingFactor?: number;
|
|
75
|
+
measurement?: number;
|
|
76
|
+
text?: string;
|
|
77
|
+
textRotation?: number;
|
|
78
|
+
ocsRotation?: number;
|
|
79
|
+
extrusionDirection?: DwgPoint3D;
|
|
80
|
+
styleName: string;
|
|
81
|
+
}
|
|
82
|
+
export interface DwgAlignedDimensionEntity extends DwgDimensionEntityCommon {
|
|
83
|
+
subclassMarker: 'AcDbAlignedDimension' | 'AcDbRotatedDimension';
|
|
84
|
+
insertionPoint?: DwgPoint3D;
|
|
85
|
+
subDefinitionPoint1: DwgPoint3D;
|
|
86
|
+
subDefinitionPoint2: DwgPoint3D;
|
|
87
|
+
rotationAngle: number;
|
|
88
|
+
obliqueAngle: number;
|
|
89
|
+
}
|
|
90
|
+
export interface DwgAngularDimensionEntity extends DwgDimensionEntityCommon {
|
|
91
|
+
subclassMarker: 'AcDb3PointAngularDimension';
|
|
92
|
+
subDefinitionPoint1: DwgPoint3D;
|
|
93
|
+
subDefinitionPoint2: DwgPoint3D;
|
|
94
|
+
centerPoint: DwgPoint3D;
|
|
95
|
+
arcPoint: DwgPoint3D;
|
|
96
|
+
}
|
|
97
|
+
export interface DwgOrdinateDimensionEntity extends DwgDimensionEntityCommon {
|
|
98
|
+
subclassMarker: 'AcDbOrdinateDimension';
|
|
99
|
+
subDefinitionPoint1: DwgPoint3D;
|
|
100
|
+
subDefinitionPoint2: DwgPoint3D;
|
|
101
|
+
}
|
|
102
|
+
export interface DwgRadialDiameterDimensionEntity extends DwgDimensionEntityCommon {
|
|
103
|
+
subclassMarker: 'AcDbRadialDimension' | 'AcDbDiametricDimension';
|
|
104
|
+
centerPoint: DwgPoint3D;
|
|
105
|
+
leaderLength: number;
|
|
106
|
+
}
|
|
107
|
+
export type DimensionEntity = DwgDimensionEntityCommon & (Partial<DwgAlignedDimensionEntity> | Partial<DwgAngularDimensionEntity> | Partial<DwgOrdinateDimensionEntity> | Partial<DwgRadialDiameterDimensionEntity>);
|
|
108
|
+
//# sourceMappingURL=dimension.d.ts.map
|