jww-parser 2025.12.2 → 2025.12.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/index.d.ts +809 -30
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +845 -166
- package/package.json +3 -3
- package/wasm/jww-parser.wasm +0 -0
- package/dist/index.d.mts +0 -168
- package/dist/index.mjs +0 -130
package/dist/index.d.ts
CHANGED
|
@@ -3,129 +3,829 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This module provides functionality to parse JWW binary files
|
|
5
5
|
* and convert them to DXF format using WebAssembly.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Error codes for JWW parser operations
|
|
11
|
+
*/
|
|
12
|
+
export declare enum JwwErrorCode {
|
|
13
|
+
/** Parser has not been initialized */
|
|
14
|
+
NOT_INITIALIZED = "NOT_INITIALIZED",
|
|
15
|
+
/** WASM module failed to load */
|
|
16
|
+
WASM_LOAD_FAILED = "WASM_LOAD_FAILED",
|
|
17
|
+
/** WASM functions not available after timeout */
|
|
18
|
+
WASM_TIMEOUT = "WASM_TIMEOUT",
|
|
19
|
+
/** Invalid JWW file signature */
|
|
20
|
+
INVALID_SIGNATURE = "INVALID_SIGNATURE",
|
|
21
|
+
/** Unsupported JWW version */
|
|
22
|
+
UNSUPPORTED_VERSION = "UNSUPPORTED_VERSION",
|
|
23
|
+
/** General parse error */
|
|
24
|
+
PARSE_ERROR = "PARSE_ERROR",
|
|
25
|
+
/** DXF conversion error */
|
|
26
|
+
CONVERSION_ERROR = "CONVERSION_ERROR",
|
|
27
|
+
/** Validation error */
|
|
28
|
+
VALIDATION_ERROR = "VALIDATION_ERROR",
|
|
29
|
+
/** Memory allocation error */
|
|
30
|
+
MEMORY_ERROR = "MEMORY_ERROR",
|
|
31
|
+
/** Invalid argument provided */
|
|
32
|
+
INVALID_ARGUMENT = "INVALID_ARGUMENT"
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Base error class for JWW parser errors
|
|
36
|
+
*/
|
|
37
|
+
export declare class JwwParserError extends Error {
|
|
38
|
+
/** Error code identifying the error type */
|
|
39
|
+
readonly code: JwwErrorCode;
|
|
40
|
+
/** Original error that caused this error, if any */
|
|
41
|
+
readonly cause?: Error;
|
|
42
|
+
/** Additional context about the error */
|
|
43
|
+
readonly context?: Record<string, unknown>;
|
|
44
|
+
/** Timestamp when the error occurred */
|
|
45
|
+
readonly timestamp: Date;
|
|
46
|
+
constructor(code: JwwErrorCode, message: string, options?: {
|
|
47
|
+
cause?: Error;
|
|
48
|
+
context?: Record<string, unknown>;
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* Returns a detailed string representation of the error
|
|
52
|
+
*/
|
|
53
|
+
toDetailedString(): string;
|
|
54
|
+
/**
|
|
55
|
+
* Converts the error to a plain object for logging/serialization
|
|
56
|
+
*/
|
|
57
|
+
toJSON(): Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Error thrown when the parser is not initialized
|
|
61
|
+
*/
|
|
62
|
+
export declare class NotInitializedError extends JwwParserError {
|
|
63
|
+
constructor();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Error thrown when WASM module fails to load
|
|
67
|
+
*/
|
|
68
|
+
export declare class WasmLoadError extends JwwParserError {
|
|
69
|
+
constructor(message: string, cause?: Error);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Error thrown when file validation fails
|
|
6
73
|
*/
|
|
7
|
-
|
|
74
|
+
export declare class ValidationError extends JwwParserError {
|
|
75
|
+
/** Specific validation issues found */
|
|
76
|
+
readonly issues: ValidationIssue[];
|
|
77
|
+
constructor(message: string, issues: ValidationIssue[]);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Error thrown during parsing
|
|
81
|
+
*/
|
|
82
|
+
export declare class ParseError extends JwwParserError {
|
|
83
|
+
/** Byte offset where the error occurred, if available */
|
|
84
|
+
readonly offset?: number;
|
|
85
|
+
/** Section being parsed when the error occurred */
|
|
86
|
+
readonly section?: string;
|
|
87
|
+
constructor(message: string, options?: {
|
|
88
|
+
cause?: Error;
|
|
89
|
+
offset?: number;
|
|
90
|
+
section?: string;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Complete JWW document structure
|
|
95
|
+
*/
|
|
96
|
+
export interface JwwDocument {
|
|
97
|
+
/** JWW file version number */
|
|
8
98
|
Version: number;
|
|
99
|
+
/** Document memo/comments */
|
|
9
100
|
Memo: string;
|
|
101
|
+
/** Paper size code */
|
|
10
102
|
PaperSize: number;
|
|
11
|
-
|
|
103
|
+
/** Layer groups (16 groups) */
|
|
104
|
+
LayerGroups: JwwLayerGroup[];
|
|
105
|
+
/** All entities in the document */
|
|
12
106
|
Entities: JwwEntity[];
|
|
107
|
+
/** Block definitions */
|
|
13
108
|
Blocks: JwwBlock[];
|
|
14
109
|
}
|
|
15
|
-
|
|
110
|
+
/**
|
|
111
|
+
* JWW layer group containing 16 layers
|
|
112
|
+
*/
|
|
113
|
+
export interface JwwLayerGroup {
|
|
114
|
+
/** Layer group name */
|
|
16
115
|
Name: string;
|
|
17
|
-
Layers
|
|
116
|
+
/** Layers within this group (16 layers) */
|
|
117
|
+
Layers: JwwLayer[];
|
|
18
118
|
}
|
|
19
|
-
|
|
119
|
+
/**
|
|
120
|
+
* JWW layer within a layer group
|
|
121
|
+
*/
|
|
122
|
+
export interface JwwLayer {
|
|
123
|
+
/** Layer name */
|
|
20
124
|
Name: string;
|
|
125
|
+
/** Whether the layer is visible */
|
|
21
126
|
Visible: boolean;
|
|
127
|
+
/** Whether the layer is locked */
|
|
22
128
|
Locked: boolean;
|
|
23
129
|
}
|
|
24
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Base interface for all JWW entities
|
|
132
|
+
*/
|
|
133
|
+
export interface JwwEntityBase {
|
|
134
|
+
/** Entity type discriminator */
|
|
25
135
|
Type: string;
|
|
136
|
+
/** Curve attribute number */
|
|
26
137
|
Group: number;
|
|
138
|
+
/** Line type/style */
|
|
27
139
|
PenStyle: number;
|
|
140
|
+
/** Color code */
|
|
28
141
|
PenColor: number;
|
|
142
|
+
/** Line width */
|
|
29
143
|
PenWidth: number;
|
|
144
|
+
/** Layer index within the group (0-15) */
|
|
30
145
|
Layer: number;
|
|
146
|
+
/** Layer group index (0-15) */
|
|
31
147
|
LayerGroup: number;
|
|
32
148
|
}
|
|
33
|
-
|
|
149
|
+
/**
|
|
150
|
+
* JWW Line entity
|
|
151
|
+
*/
|
|
152
|
+
export interface JwwLine extends JwwEntityBase {
|
|
34
153
|
Type: "Line";
|
|
154
|
+
/** Start X coordinate */
|
|
35
155
|
X1: number;
|
|
156
|
+
/** Start Y coordinate */
|
|
36
157
|
Y1: number;
|
|
158
|
+
/** End X coordinate */
|
|
37
159
|
X2: number;
|
|
160
|
+
/** End Y coordinate */
|
|
38
161
|
Y2: number;
|
|
39
162
|
}
|
|
40
|
-
|
|
163
|
+
/**
|
|
164
|
+
* JWW Arc entity (includes circles and ellipses)
|
|
165
|
+
*/
|
|
166
|
+
export interface JwwArc extends JwwEntityBase {
|
|
41
167
|
Type: "Arc";
|
|
168
|
+
/** Center X coordinate */
|
|
42
169
|
CenterX: number;
|
|
170
|
+
/** Center Y coordinate */
|
|
43
171
|
CenterY: number;
|
|
172
|
+
/** Arc radius */
|
|
44
173
|
Radius: number;
|
|
174
|
+
/** Start angle in degrees */
|
|
45
175
|
StartAngle: number;
|
|
176
|
+
/** End angle in degrees */
|
|
46
177
|
EndAngle: number;
|
|
178
|
+
/** Flatness ratio (1.0 for circles, other values for ellipses) */
|
|
47
179
|
Flatness: number;
|
|
48
180
|
}
|
|
49
|
-
|
|
181
|
+
/**
|
|
182
|
+
* JWW Point entity
|
|
183
|
+
*/
|
|
184
|
+
export interface JwwPoint extends JwwEntityBase {
|
|
50
185
|
Type: "Point";
|
|
186
|
+
/** X coordinate */
|
|
51
187
|
X: number;
|
|
188
|
+
/** Y coordinate */
|
|
52
189
|
Y: number;
|
|
190
|
+
/** Point code/type */
|
|
53
191
|
Code: number;
|
|
54
192
|
}
|
|
55
|
-
|
|
193
|
+
/**
|
|
194
|
+
* JWW Text entity
|
|
195
|
+
*/
|
|
196
|
+
export interface JwwText extends JwwEntityBase {
|
|
56
197
|
Type: "Text";
|
|
198
|
+
/** Text insertion X coordinate */
|
|
57
199
|
X: number;
|
|
200
|
+
/** Text insertion Y coordinate */
|
|
58
201
|
Y: number;
|
|
202
|
+
/** Text content */
|
|
59
203
|
Text: string;
|
|
204
|
+
/** Font name */
|
|
60
205
|
FontName: string;
|
|
206
|
+
/** Text height */
|
|
61
207
|
Height: number;
|
|
208
|
+
/** Text width (character width) */
|
|
62
209
|
Width: number;
|
|
210
|
+
/** Rotation angle in degrees */
|
|
63
211
|
Angle: number;
|
|
64
212
|
}
|
|
65
|
-
|
|
213
|
+
/**
|
|
214
|
+
* JWW Solid (filled polygon) entity
|
|
215
|
+
*/
|
|
216
|
+
export interface JwwSolid extends JwwEntityBase {
|
|
66
217
|
Type: "Solid";
|
|
218
|
+
/** Array of [x, y] coordinate pairs */
|
|
67
219
|
Points: [number, number][];
|
|
68
220
|
}
|
|
69
|
-
|
|
221
|
+
/**
|
|
222
|
+
* JWW Block reference entity
|
|
223
|
+
*/
|
|
224
|
+
export interface JwwBlockRef extends JwwEntityBase {
|
|
70
225
|
Type: "Block";
|
|
226
|
+
/** Insertion X coordinate */
|
|
71
227
|
X: number;
|
|
228
|
+
/** Insertion Y coordinate */
|
|
72
229
|
Y: number;
|
|
230
|
+
/** X scale factor */
|
|
73
231
|
ScaleX: number;
|
|
232
|
+
/** Y scale factor */
|
|
74
233
|
ScaleY: number;
|
|
234
|
+
/** Rotation angle in degrees */
|
|
75
235
|
Angle: number;
|
|
236
|
+
/** Referenced block definition number */
|
|
76
237
|
BlockNumber: number;
|
|
77
238
|
}
|
|
78
|
-
|
|
79
|
-
|
|
239
|
+
/**
|
|
240
|
+
* Union type of all JWW entity types
|
|
241
|
+
*/
|
|
242
|
+
export type JwwEntity = JwwLine | JwwArc | JwwPoint | JwwText | JwwSolid | JwwBlockRef;
|
|
243
|
+
/**
|
|
244
|
+
* JWW block definition
|
|
245
|
+
*/
|
|
246
|
+
export interface JwwBlock {
|
|
247
|
+
/** Block name */
|
|
80
248
|
Name: string;
|
|
249
|
+
/** Entities within the block */
|
|
81
250
|
Entities: JwwEntity[];
|
|
82
251
|
}
|
|
83
|
-
|
|
252
|
+
/**
|
|
253
|
+
* DXF document structure
|
|
254
|
+
*/
|
|
255
|
+
export interface DxfDocument {
|
|
256
|
+
/** DXF layers */
|
|
84
257
|
Layers: DxfLayer[];
|
|
258
|
+
/** All entities in the document */
|
|
85
259
|
Entities: DxfEntity[];
|
|
260
|
+
/** Block definitions */
|
|
86
261
|
Blocks: DxfBlock[];
|
|
87
262
|
}
|
|
88
|
-
|
|
263
|
+
/**
|
|
264
|
+
* DXF layer definition
|
|
265
|
+
*/
|
|
266
|
+
export interface DxfLayer {
|
|
267
|
+
/** Layer name */
|
|
89
268
|
Name: string;
|
|
269
|
+
/** ACI color code (1-255) */
|
|
90
270
|
Color: number;
|
|
271
|
+
/** Whether the layer is frozen */
|
|
91
272
|
Frozen: boolean;
|
|
273
|
+
/** Whether the layer is locked */
|
|
92
274
|
Locked: boolean;
|
|
93
275
|
}
|
|
94
|
-
|
|
276
|
+
/**
|
|
277
|
+
* Base interface for all DXF entities
|
|
278
|
+
*/
|
|
279
|
+
export interface DxfEntityBase {
|
|
280
|
+
/** Entity type (LINE, CIRCLE, ARC, etc.) */
|
|
95
281
|
Type: string;
|
|
282
|
+
/** Layer name */
|
|
96
283
|
Layer: string;
|
|
284
|
+
/** Optional ACI color code */
|
|
97
285
|
Color?: number;
|
|
98
|
-
|
|
286
|
+
/** Optional line type name */
|
|
287
|
+
LineType?: string;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* DXF LINE entity
|
|
291
|
+
*/
|
|
292
|
+
export interface DxfLine extends DxfEntityBase {
|
|
293
|
+
Type: "LINE";
|
|
294
|
+
/** Start X coordinate */
|
|
295
|
+
X1: number;
|
|
296
|
+
/** Start Y coordinate */
|
|
297
|
+
Y1: number;
|
|
298
|
+
/** Start Z coordinate */
|
|
299
|
+
Z1?: number;
|
|
300
|
+
/** End X coordinate */
|
|
301
|
+
X2: number;
|
|
302
|
+
/** End Y coordinate */
|
|
303
|
+
Y2: number;
|
|
304
|
+
/** End Z coordinate */
|
|
305
|
+
Z2?: number;
|
|
99
306
|
}
|
|
100
|
-
|
|
307
|
+
/**
|
|
308
|
+
* DXF CIRCLE entity
|
|
309
|
+
*/
|
|
310
|
+
export interface DxfCircle extends DxfEntityBase {
|
|
311
|
+
Type: "CIRCLE";
|
|
312
|
+
/** Center X coordinate */
|
|
313
|
+
CenterX: number;
|
|
314
|
+
/** Center Y coordinate */
|
|
315
|
+
CenterY: number;
|
|
316
|
+
/** Center Z coordinate */
|
|
317
|
+
CenterZ?: number;
|
|
318
|
+
/** Circle radius */
|
|
319
|
+
Radius: number;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* DXF ARC entity
|
|
323
|
+
*/
|
|
324
|
+
export interface DxfArc extends DxfEntityBase {
|
|
325
|
+
Type: "ARC";
|
|
326
|
+
/** Center X coordinate */
|
|
327
|
+
CenterX: number;
|
|
328
|
+
/** Center Y coordinate */
|
|
329
|
+
CenterY: number;
|
|
330
|
+
/** Center Z coordinate */
|
|
331
|
+
CenterZ?: number;
|
|
332
|
+
/** Arc radius */
|
|
333
|
+
Radius: number;
|
|
334
|
+
/** Start angle in degrees */
|
|
335
|
+
StartAngle: number;
|
|
336
|
+
/** End angle in degrees */
|
|
337
|
+
EndAngle: number;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* DXF ELLIPSE entity
|
|
341
|
+
*/
|
|
342
|
+
export interface DxfEllipse extends DxfEntityBase {
|
|
343
|
+
Type: "ELLIPSE";
|
|
344
|
+
/** Center X coordinate */
|
|
345
|
+
CenterX: number;
|
|
346
|
+
/** Center Y coordinate */
|
|
347
|
+
CenterY: number;
|
|
348
|
+
/** Center Z coordinate */
|
|
349
|
+
CenterZ?: number;
|
|
350
|
+
/** Major axis X component (relative to center) */
|
|
351
|
+
MajorAxisX: number;
|
|
352
|
+
/** Major axis Y component (relative to center) */
|
|
353
|
+
MajorAxisY: number;
|
|
354
|
+
/** Major axis Z component (relative to center) */
|
|
355
|
+
MajorAxisZ?: number;
|
|
356
|
+
/** Minor to major axis ratio (0 to 1) */
|
|
357
|
+
MinorRatio: number;
|
|
358
|
+
/** Start parameter (0 to 2*PI) */
|
|
359
|
+
StartParam: number;
|
|
360
|
+
/** End parameter (0 to 2*PI) */
|
|
361
|
+
EndParam: number;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* DXF POINT entity
|
|
365
|
+
*/
|
|
366
|
+
export interface DxfPoint extends DxfEntityBase {
|
|
367
|
+
Type: "POINT";
|
|
368
|
+
/** X coordinate */
|
|
369
|
+
X: number;
|
|
370
|
+
/** Y coordinate */
|
|
371
|
+
Y: number;
|
|
372
|
+
/** Z coordinate */
|
|
373
|
+
Z?: number;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* DXF TEXT entity
|
|
377
|
+
*/
|
|
378
|
+
export interface DxfText extends DxfEntityBase {
|
|
379
|
+
Type: "TEXT";
|
|
380
|
+
/** Insertion X coordinate */
|
|
381
|
+
X: number;
|
|
382
|
+
/** Insertion Y coordinate */
|
|
383
|
+
Y: number;
|
|
384
|
+
/** Insertion Z coordinate */
|
|
385
|
+
Z?: number;
|
|
386
|
+
/** Text height */
|
|
387
|
+
Height: number;
|
|
388
|
+
/** Text content */
|
|
389
|
+
Content: string;
|
|
390
|
+
/** Rotation angle in degrees */
|
|
391
|
+
Rotation?: number;
|
|
392
|
+
/** Text style name */
|
|
393
|
+
Style?: string;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* DXF MTEXT (multiline text) entity
|
|
397
|
+
*/
|
|
398
|
+
export interface DxfMText extends DxfEntityBase {
|
|
399
|
+
Type: "MTEXT";
|
|
400
|
+
/** Insertion X coordinate */
|
|
401
|
+
X: number;
|
|
402
|
+
/** Insertion Y coordinate */
|
|
403
|
+
Y: number;
|
|
404
|
+
/** Insertion Z coordinate */
|
|
405
|
+
Z?: number;
|
|
406
|
+
/** Text height */
|
|
407
|
+
Height: number;
|
|
408
|
+
/** Text content (with formatting codes) */
|
|
409
|
+
Content: string;
|
|
410
|
+
/** Rotation angle in degrees */
|
|
411
|
+
Rotation?: number;
|
|
412
|
+
/** Reference rectangle width */
|
|
413
|
+
Width?: number;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* DXF SOLID entity (filled triangle or quadrilateral)
|
|
417
|
+
*/
|
|
418
|
+
export interface DxfSolid extends DxfEntityBase {
|
|
419
|
+
Type: "SOLID";
|
|
420
|
+
/** First corner X */
|
|
421
|
+
X1: number;
|
|
422
|
+
/** First corner Y */
|
|
423
|
+
Y1: number;
|
|
424
|
+
/** Second corner X */
|
|
425
|
+
X2: number;
|
|
426
|
+
/** Second corner Y */
|
|
427
|
+
Y2: number;
|
|
428
|
+
/** Third corner X */
|
|
429
|
+
X3: number;
|
|
430
|
+
/** Third corner Y */
|
|
431
|
+
Y3: number;
|
|
432
|
+
/** Fourth corner X (same as third for triangles) */
|
|
433
|
+
X4: number;
|
|
434
|
+
/** Fourth corner Y (same as third for triangles) */
|
|
435
|
+
Y4: number;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* DXF INSERT entity (block reference)
|
|
439
|
+
*/
|
|
440
|
+
export interface DxfInsert extends DxfEntityBase {
|
|
441
|
+
Type: "INSERT";
|
|
442
|
+
/** Block name */
|
|
443
|
+
BlockName: string;
|
|
444
|
+
/** Insertion X coordinate */
|
|
445
|
+
X: number;
|
|
446
|
+
/** Insertion Y coordinate */
|
|
447
|
+
Y: number;
|
|
448
|
+
/** Insertion Z coordinate */
|
|
449
|
+
Z?: number;
|
|
450
|
+
/** X scale factor */
|
|
451
|
+
ScaleX?: number;
|
|
452
|
+
/** Y scale factor */
|
|
453
|
+
ScaleY?: number;
|
|
454
|
+
/** Z scale factor */
|
|
455
|
+
ScaleZ?: number;
|
|
456
|
+
/** Rotation angle in degrees */
|
|
457
|
+
Rotation?: number;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* DXF POLYLINE vertex
|
|
461
|
+
*/
|
|
462
|
+
export interface DxfVertex {
|
|
463
|
+
/** X coordinate */
|
|
464
|
+
X: number;
|
|
465
|
+
/** Y coordinate */
|
|
466
|
+
Y: number;
|
|
467
|
+
/** Z coordinate */
|
|
468
|
+
Z?: number;
|
|
469
|
+
/** Bulge factor (for curved segments) */
|
|
470
|
+
Bulge?: number;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* DXF LWPOLYLINE entity
|
|
474
|
+
*/
|
|
475
|
+
export interface DxfLwPolyline extends DxfEntityBase {
|
|
476
|
+
Type: "LWPOLYLINE";
|
|
477
|
+
/** Whether the polyline is closed */
|
|
478
|
+
Closed: boolean;
|
|
479
|
+
/** Polyline vertices */
|
|
480
|
+
Vertices: DxfVertex[];
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Union type of all DXF entity types
|
|
484
|
+
*/
|
|
485
|
+
export type DxfEntity = DxfLine | DxfCircle | DxfArc | DxfEllipse | DxfPoint | DxfText | DxfMText | DxfSolid | DxfInsert | DxfLwPolyline | (DxfEntityBase & Record<string, unknown>);
|
|
486
|
+
/**
|
|
487
|
+
* DXF block definition
|
|
488
|
+
*/
|
|
489
|
+
export interface DxfBlock {
|
|
490
|
+
/** Block name */
|
|
101
491
|
Name: string;
|
|
492
|
+
/** Base point X coordinate */
|
|
493
|
+
BaseX?: number;
|
|
494
|
+
/** Base point Y coordinate */
|
|
495
|
+
BaseY?: number;
|
|
496
|
+
/** Base point Z coordinate */
|
|
497
|
+
BaseZ?: number;
|
|
498
|
+
/** Entities within the block */
|
|
102
499
|
Entities: DxfEntity[];
|
|
103
500
|
}
|
|
501
|
+
/**
|
|
502
|
+
* Progress stages during parsing
|
|
503
|
+
*/
|
|
504
|
+
export type ProgressStage = "loading" | "parsing_header" | "parsing_layers" | "parsing_entities" | "parsing_blocks" | "converting" | "complete";
|
|
505
|
+
/**
|
|
506
|
+
* Progress information during parsing
|
|
507
|
+
*/
|
|
508
|
+
export interface ProgressInfo {
|
|
509
|
+
/** Current stage of parsing */
|
|
510
|
+
stage: ProgressStage;
|
|
511
|
+
/** Progress within the current stage (0-100) */
|
|
512
|
+
progress: number;
|
|
513
|
+
/** Overall progress (0-100) */
|
|
514
|
+
overallProgress: number;
|
|
515
|
+
/** Optional message about current operation */
|
|
516
|
+
message?: string;
|
|
517
|
+
/** Number of entities processed so far */
|
|
518
|
+
entitiesProcessed?: number;
|
|
519
|
+
/** Total number of entities (if known) */
|
|
520
|
+
totalEntities?: number;
|
|
521
|
+
/** Elapsed time in milliseconds */
|
|
522
|
+
elapsedMs: number;
|
|
523
|
+
/** Estimated remaining time in milliseconds (if available) */
|
|
524
|
+
estimatedRemainingMs?: number;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Callback function for reporting progress
|
|
528
|
+
*/
|
|
529
|
+
export type ProgressCallback = (progress: ProgressInfo) => void;
|
|
530
|
+
/**
|
|
531
|
+
* Options for parsing JWW files
|
|
532
|
+
*/
|
|
533
|
+
export interface ParseOptions {
|
|
534
|
+
/**
|
|
535
|
+
* Enable streaming mode for lower memory usage
|
|
536
|
+
* When enabled, entities are processed in chunks
|
|
537
|
+
* @default false
|
|
538
|
+
*/
|
|
539
|
+
streamingMode?: boolean;
|
|
540
|
+
/**
|
|
541
|
+
* Skip parsing of specific entity types
|
|
542
|
+
* Useful for improving performance when not all entities are needed
|
|
543
|
+
*/
|
|
544
|
+
skipEntityTypes?: Array<JwwEntity["Type"]>;
|
|
545
|
+
/**
|
|
546
|
+
* Only parse entities on specific layer groups
|
|
547
|
+
* Array of layer group indices (0-15)
|
|
548
|
+
*/
|
|
549
|
+
layerGroupFilter?: number[];
|
|
550
|
+
/**
|
|
551
|
+
* Only parse entities on specific layers
|
|
552
|
+
* Format: { layerGroup: layerIndex[] }
|
|
553
|
+
*/
|
|
554
|
+
layerFilter?: Record<number, number[]>;
|
|
555
|
+
/**
|
|
556
|
+
* Limit the number of entities to parse
|
|
557
|
+
* Useful for previewing large files
|
|
558
|
+
*/
|
|
559
|
+
maxEntities?: number;
|
|
560
|
+
/**
|
|
561
|
+
* Include block definitions in the output
|
|
562
|
+
* @default true
|
|
563
|
+
*/
|
|
564
|
+
includeBlocks?: boolean;
|
|
565
|
+
/**
|
|
566
|
+
* Expand block references inline (replaces INSERT with actual entities)
|
|
567
|
+
* Warning: May significantly increase output size
|
|
568
|
+
* @default false
|
|
569
|
+
*/
|
|
570
|
+
expandBlockReferences?: boolean;
|
|
571
|
+
/**
|
|
572
|
+
* Progress callback function
|
|
573
|
+
* Called periodically during parsing with progress information
|
|
574
|
+
*/
|
|
575
|
+
onProgress?: ProgressCallback;
|
|
576
|
+
/**
|
|
577
|
+
* Abort signal for cancelling the parse operation
|
|
578
|
+
*/
|
|
579
|
+
signal?: AbortSignal;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Options for DXF conversion
|
|
583
|
+
*/
|
|
584
|
+
export interface ConvertOptions extends ParseOptions {
|
|
585
|
+
/**
|
|
586
|
+
* Convert temporary points (Code > 0)
|
|
587
|
+
* @default false
|
|
588
|
+
*/
|
|
589
|
+
includeTemporaryPoints?: boolean;
|
|
590
|
+
/**
|
|
591
|
+
* Color mapping override
|
|
592
|
+
* Maps JWW color codes to DXF ACI colors
|
|
593
|
+
*/
|
|
594
|
+
colorMapping?: Record<number, number>;
|
|
595
|
+
/**
|
|
596
|
+
* Layer naming pattern
|
|
597
|
+
* Use {group} and {layer} placeholders
|
|
598
|
+
* @default "{group}-{layer}"
|
|
599
|
+
*/
|
|
600
|
+
layerNamePattern?: string;
|
|
601
|
+
/**
|
|
602
|
+
* Precision for coordinate values (decimal places)
|
|
603
|
+
* @default 6
|
|
604
|
+
*/
|
|
605
|
+
precision?: number;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Severity level for validation issues
|
|
609
|
+
*/
|
|
610
|
+
export type ValidationSeverity = "error" | "warning" | "info";
|
|
611
|
+
/**
|
|
612
|
+
* A single validation issue
|
|
613
|
+
*/
|
|
614
|
+
export interface ValidationIssue {
|
|
615
|
+
/** Severity of the issue */
|
|
616
|
+
severity: ValidationSeverity;
|
|
617
|
+
/** Issue code */
|
|
618
|
+
code: string;
|
|
619
|
+
/** Human-readable message */
|
|
620
|
+
message: string;
|
|
621
|
+
/** Byte offset where the issue was found, if applicable */
|
|
622
|
+
offset?: number;
|
|
623
|
+
/** Additional details */
|
|
624
|
+
details?: Record<string, unknown>;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Result of file validation
|
|
628
|
+
*/
|
|
629
|
+
export interface ValidationResult {
|
|
630
|
+
/** Whether the file is valid (no errors) */
|
|
631
|
+
valid: boolean;
|
|
632
|
+
/** File format version, if detected */
|
|
633
|
+
version?: number;
|
|
634
|
+
/** Estimated file size category */
|
|
635
|
+
sizeCategory: "small" | "medium" | "large" | "very_large";
|
|
636
|
+
/** Estimated entity count, if detectable */
|
|
637
|
+
estimatedEntityCount?: number;
|
|
638
|
+
/** List of validation issues found */
|
|
639
|
+
issues: ValidationIssue[];
|
|
640
|
+
/** Validation took this many milliseconds */
|
|
641
|
+
validationTimeMs: number;
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Debug log levels
|
|
645
|
+
*/
|
|
646
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
647
|
+
/**
|
|
648
|
+
* Debug log entry
|
|
649
|
+
*/
|
|
650
|
+
export interface DebugLogEntry {
|
|
651
|
+
/** Timestamp of the log entry */
|
|
652
|
+
timestamp: Date;
|
|
653
|
+
/** Log level */
|
|
654
|
+
level: LogLevel;
|
|
655
|
+
/** Log message */
|
|
656
|
+
message: string;
|
|
657
|
+
/** Additional data */
|
|
658
|
+
data?: Record<string, unknown>;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Debug callback function
|
|
662
|
+
*/
|
|
663
|
+
export type DebugCallback = (entry: DebugLogEntry) => void;
|
|
664
|
+
/**
|
|
665
|
+
* Debug options
|
|
666
|
+
*/
|
|
667
|
+
export interface DebugOptions {
|
|
668
|
+
/**
|
|
669
|
+
* Enable debug mode
|
|
670
|
+
* @default false
|
|
671
|
+
*/
|
|
672
|
+
enabled?: boolean;
|
|
673
|
+
/**
|
|
674
|
+
* Minimum log level to capture
|
|
675
|
+
* @default "info"
|
|
676
|
+
*/
|
|
677
|
+
logLevel?: LogLevel;
|
|
678
|
+
/**
|
|
679
|
+
* Debug callback function
|
|
680
|
+
* If not provided, logs will be stored internally
|
|
681
|
+
*/
|
|
682
|
+
onDebug?: DebugCallback;
|
|
683
|
+
/**
|
|
684
|
+
* Log to console
|
|
685
|
+
* @default false
|
|
686
|
+
*/
|
|
687
|
+
logToConsole?: boolean;
|
|
688
|
+
/**
|
|
689
|
+
* Maximum number of log entries to store
|
|
690
|
+
* @default 1000
|
|
691
|
+
*/
|
|
692
|
+
maxLogEntries?: number;
|
|
693
|
+
/**
|
|
694
|
+
* Include timing information
|
|
695
|
+
* @default true
|
|
696
|
+
*/
|
|
697
|
+
includeTiming?: boolean;
|
|
698
|
+
/**
|
|
699
|
+
* Include memory usage information
|
|
700
|
+
* @default false
|
|
701
|
+
*/
|
|
702
|
+
includeMemoryUsage?: boolean;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Memory usage statistics
|
|
706
|
+
*/
|
|
707
|
+
export interface MemoryStats {
|
|
708
|
+
/** WASM memory buffer size in bytes */
|
|
709
|
+
wasmMemoryBytes: number;
|
|
710
|
+
/** Estimated JS heap usage in bytes (if available) */
|
|
711
|
+
jsHeapBytes?: number;
|
|
712
|
+
/** Total estimated memory usage */
|
|
713
|
+
totalBytes: number;
|
|
714
|
+
/** Human-readable total */
|
|
715
|
+
totalFormatted: string;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Parser statistics
|
|
719
|
+
*/
|
|
720
|
+
export interface ParserStats {
|
|
721
|
+
/** Number of parse operations performed */
|
|
722
|
+
parseCount: number;
|
|
723
|
+
/** Total bytes processed */
|
|
724
|
+
totalBytesProcessed: number;
|
|
725
|
+
/** Average parse time in milliseconds */
|
|
726
|
+
averageParseTimeMs: number;
|
|
727
|
+
/** Fastest parse time in milliseconds */
|
|
728
|
+
fastestParseTimeMs: number;
|
|
729
|
+
/** Slowest parse time in milliseconds */
|
|
730
|
+
slowestParseTimeMs: number;
|
|
731
|
+
/** Number of errors encountered */
|
|
732
|
+
errorCount: number;
|
|
733
|
+
/** Current memory usage */
|
|
734
|
+
memoryStats: MemoryStats;
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Result type from WASM operations
|
|
738
|
+
* @internal
|
|
739
|
+
*/
|
|
104
740
|
interface WasmResult {
|
|
105
741
|
ok: boolean;
|
|
106
742
|
data?: string;
|
|
107
743
|
error?: string;
|
|
744
|
+
errorCode?: string;
|
|
745
|
+
offset?: number;
|
|
746
|
+
section?: string;
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Validation result from WASM
|
|
750
|
+
* @internal
|
|
751
|
+
*/
|
|
752
|
+
interface WasmValidationResult {
|
|
753
|
+
ok: boolean;
|
|
754
|
+
valid: boolean;
|
|
755
|
+
version?: number;
|
|
756
|
+
estimatedEntities?: number;
|
|
757
|
+
issues?: Array<{
|
|
758
|
+
severity: string;
|
|
759
|
+
code: string;
|
|
760
|
+
message: string;
|
|
761
|
+
offset?: number;
|
|
762
|
+
}>;
|
|
763
|
+
error?: string;
|
|
108
764
|
}
|
|
109
765
|
declare global {
|
|
110
766
|
var Go: new () => GoInstance;
|
|
111
|
-
var jwwParse: (data: Uint8Array) => WasmResult;
|
|
112
|
-
var jwwToDxf: (data: Uint8Array) => WasmResult;
|
|
113
|
-
var jwwToDxfString: (data: Uint8Array) => WasmResult;
|
|
767
|
+
var jwwParse: ((data: Uint8Array) => WasmResult) | undefined;
|
|
768
|
+
var jwwToDxf: ((data: Uint8Array) => WasmResult) | undefined;
|
|
769
|
+
var jwwToDxfString: ((data: Uint8Array) => WasmResult) | undefined;
|
|
770
|
+
var jwwValidate: ((data: Uint8Array) => WasmValidationResult) | undefined;
|
|
771
|
+
var jwwGetVersion: (() => string) | undefined;
|
|
772
|
+
var jwwSetDebug: ((enabled: boolean) => void) | undefined;
|
|
114
773
|
}
|
|
115
774
|
interface GoInstance {
|
|
116
775
|
importObject: WebAssembly.Imports;
|
|
117
776
|
run(instance: WebAssembly.Instance): Promise<void>;
|
|
777
|
+
_inst?: WebAssembly.Instance;
|
|
118
778
|
}
|
|
119
|
-
|
|
779
|
+
/**
|
|
780
|
+
* JWW file parser with WebAssembly backend
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* ```typescript
|
|
784
|
+
* // Using the factory function (recommended)
|
|
785
|
+
* const parser = await createParser();
|
|
786
|
+
* const doc = parser.parse(fileData);
|
|
787
|
+
*
|
|
788
|
+
* // Manual initialization
|
|
789
|
+
* const parser = new JwwParser();
|
|
790
|
+
* await parser.init();
|
|
791
|
+
* const doc = parser.parse(fileData);
|
|
792
|
+
* ```
|
|
793
|
+
*/
|
|
794
|
+
export declare class JwwParser {
|
|
120
795
|
private initialized;
|
|
121
796
|
private initPromise;
|
|
122
797
|
private wasmPath;
|
|
798
|
+
private goInstance;
|
|
799
|
+
private wasmInstance;
|
|
800
|
+
private debugOptions;
|
|
801
|
+
private debugLogs;
|
|
802
|
+
private stats;
|
|
123
803
|
/**
|
|
124
804
|
* Create a new JWW parser instance
|
|
125
805
|
* @param wasmPath - Path to the jww-parser.wasm file
|
|
126
806
|
*/
|
|
127
807
|
constructor(wasmPath?: string);
|
|
128
808
|
private getDefaultWasmPath;
|
|
809
|
+
/**
|
|
810
|
+
* Enable or configure debug mode
|
|
811
|
+
* @param options - Debug configuration options
|
|
812
|
+
*/
|
|
813
|
+
setDebug(options: DebugOptions | boolean): void;
|
|
814
|
+
/**
|
|
815
|
+
* Get debug logs
|
|
816
|
+
* @param level - Optional minimum log level to filter
|
|
817
|
+
* @returns Array of debug log entries
|
|
818
|
+
*/
|
|
819
|
+
getDebugLogs(level?: LogLevel): DebugLogEntry[];
|
|
820
|
+
/**
|
|
821
|
+
* Clear debug logs
|
|
822
|
+
*/
|
|
823
|
+
clearDebugLogs(): void;
|
|
824
|
+
private log;
|
|
825
|
+
/**
|
|
826
|
+
* Check if the parser is initialized
|
|
827
|
+
*/
|
|
828
|
+
isInitialized(): boolean;
|
|
129
829
|
/**
|
|
130
830
|
* Initialize the WASM module
|
|
131
831
|
* Must be called before using parse methods
|
|
@@ -135,34 +835,113 @@ declare class JwwParser {
|
|
|
135
835
|
private loadWasmExec;
|
|
136
836
|
private waitForWasmFunctions;
|
|
137
837
|
private ensureInitialized;
|
|
838
|
+
/**
|
|
839
|
+
* Validate a JWW file without fully parsing it
|
|
840
|
+
* Useful for checking file validity before processing
|
|
841
|
+
*
|
|
842
|
+
* @param data - JWW file content as Uint8Array
|
|
843
|
+
* @returns Validation result with any issues found
|
|
844
|
+
*/
|
|
845
|
+
validate(data: Uint8Array): ValidationResult;
|
|
846
|
+
/**
|
|
847
|
+
* Validate and throw if invalid
|
|
848
|
+
* Convenience method that throws a ValidationError if the file is invalid
|
|
849
|
+
*
|
|
850
|
+
* @param data - JWW file content as Uint8Array
|
|
851
|
+
* @throws {ValidationError} If the file is invalid
|
|
852
|
+
*/
|
|
853
|
+
validateOrThrow(data: Uint8Array): void;
|
|
138
854
|
/**
|
|
139
855
|
* Parse a JWW file and return the document structure
|
|
856
|
+
*
|
|
140
857
|
* @param data - JWW file content as Uint8Array
|
|
858
|
+
* @param options - Optional parsing options
|
|
141
859
|
* @returns Parsed JWW document
|
|
860
|
+
* @throws {NotInitializedError} If parser is not initialized
|
|
861
|
+
* @throws {ParseError} If parsing fails
|
|
142
862
|
*/
|
|
143
|
-
parse(data: Uint8Array): JwwDocument;
|
|
863
|
+
parse(data: Uint8Array, options?: ParseOptions): JwwDocument;
|
|
864
|
+
private applyParseOptions;
|
|
144
865
|
/**
|
|
145
866
|
* Parse a JWW file and convert to DXF document structure
|
|
867
|
+
*
|
|
146
868
|
* @param data - JWW file content as Uint8Array
|
|
869
|
+
* @param options - Optional conversion options
|
|
147
870
|
* @returns DXF document object
|
|
148
871
|
*/
|
|
149
|
-
toDxf(data: Uint8Array): DxfDocument;
|
|
872
|
+
toDxf(data: Uint8Array, options?: ConvertOptions): DxfDocument;
|
|
150
873
|
/**
|
|
151
874
|
* Parse a JWW file and convert to DXF file content string
|
|
875
|
+
*
|
|
152
876
|
* @param data - JWW file content as Uint8Array
|
|
153
|
-
* @
|
|
877
|
+
* @param options - Optional conversion options
|
|
878
|
+
* @returns DXF file content as string (ready to save as .dxf file)
|
|
879
|
+
*/
|
|
880
|
+
toDxfString(data: Uint8Array, options?: ConvertOptions): string;
|
|
881
|
+
/**
|
|
882
|
+
* Get current memory usage statistics
|
|
883
|
+
*/
|
|
884
|
+
getMemoryStats(): MemoryStats;
|
|
885
|
+
/**
|
|
886
|
+
* Get parser statistics
|
|
887
|
+
*/
|
|
888
|
+
getStats(): ParserStats;
|
|
889
|
+
/**
|
|
890
|
+
* Reset parser statistics
|
|
891
|
+
*/
|
|
892
|
+
resetStats(): void;
|
|
893
|
+
/**
|
|
894
|
+
* Clean up resources and release memory
|
|
895
|
+
* Call this when you're done using the parser to free WASM memory
|
|
896
|
+
*/
|
|
897
|
+
dispose(): void;
|
|
898
|
+
/**
|
|
899
|
+
* Get the WASM module version
|
|
154
900
|
*/
|
|
155
|
-
|
|
901
|
+
getVersion(): string;
|
|
156
902
|
}
|
|
157
903
|
/**
|
|
158
904
|
* Create and initialize a JWW parser instance
|
|
905
|
+
*
|
|
159
906
|
* @param wasmPath - Optional path to the jww-parser.wasm file
|
|
907
|
+
* @param options - Optional debug options
|
|
160
908
|
* @returns Initialized JwwParser instance
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
* ```typescript
|
|
912
|
+
* const parser = await createParser();
|
|
913
|
+
* const doc = parser.parse(fileData);
|
|
914
|
+
* ```
|
|
915
|
+
*/
|
|
916
|
+
export declare function createParser(wasmPath?: string, options?: {
|
|
917
|
+
debug?: DebugOptions;
|
|
918
|
+
}): Promise<JwwParser>;
|
|
919
|
+
/**
|
|
920
|
+
* Quick validate a JWW file without initializing a full parser
|
|
921
|
+
* Performs basic validation only (signature, version check)
|
|
922
|
+
*
|
|
923
|
+
* @param data - JWW file content as Uint8Array
|
|
924
|
+
* @returns Validation result
|
|
925
|
+
*/
|
|
926
|
+
export declare function quickValidate(data: Uint8Array): ValidationResult;
|
|
927
|
+
/**
|
|
928
|
+
* Check if a Uint8Array looks like a JWW file
|
|
929
|
+
*
|
|
930
|
+
* @param data - File content as Uint8Array
|
|
931
|
+
* @returns true if the file appears to be a JWW file
|
|
161
932
|
*/
|
|
162
|
-
declare function
|
|
933
|
+
export declare function isJwwFile(data: Uint8Array): boolean;
|
|
163
934
|
declare const _default: {
|
|
164
935
|
JwwParser: typeof JwwParser;
|
|
165
936
|
createParser: typeof createParser;
|
|
937
|
+
quickValidate: typeof quickValidate;
|
|
938
|
+
isJwwFile: typeof isJwwFile;
|
|
939
|
+
JwwParserError: typeof JwwParserError;
|
|
940
|
+
NotInitializedError: typeof NotInitializedError;
|
|
941
|
+
WasmLoadError: typeof WasmLoadError;
|
|
942
|
+
ValidationError: typeof ValidationError;
|
|
943
|
+
ParseError: typeof ParseError;
|
|
944
|
+
JwwErrorCode: typeof JwwErrorCode;
|
|
166
945
|
};
|
|
167
|
-
|
|
168
|
-
|
|
946
|
+
export default _default;
|
|
947
|
+
//# sourceMappingURL=index.d.ts.map
|