dxf-json 0.8.1 → 0.8.2

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/Readme.md CHANGED
@@ -8,27 +8,41 @@
8
8
 
9
9
  ![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)![GitHub Actions](https://img.shields.io/badge/github%20actions-%232671E5.svg?style=for-the-badge&logo=githubactions&logoColor=white)
10
10
 
11
- ![Visual Studio Code](https://img.shields.io/badge/Visual%20Studio%20Code-0078d7.svg?style=for-the-badge&logo=visual-studio-code&logoColor=white)![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white)![Webpack](https://img.shields.io/badge/webpack-%238DD6F9.svg?style=for-the-badge&logo=webpack&logoColor=black)
11
+ ![Visual Studio Code](https://img.shields.io/badge/Visual%20Studio%20Code-0078d7.svg?style=for-the-badge&logo=visual-studio-code&logoColor=white)![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white)
12
12
 
13
13
  [![NPM](https://img.shields.io/badge/NPM-%23CB3837.svg?style=for-the-badge&logo=npm&logoColor=white)](https://www.npmjs.com/package/dxf-json)
14
14
 
15
- ## Perfect Dxf Parser
15
+ DXF parser with rich type definitions.
16
16
 
17
- A library that reliably parses DXF files into JSON files without missing data.
17
+ > [!CAUTION]
18
+ > This is parser is not in stable state yet. Until version 1.0, we may often change name or type of the variables. We're adding rich unit/integration test, but there might be unexpected bug or uncovered situation. Note that [official DXF specification](https://documentation.help/AutoCAD-DXF/) is poorly documented, so that many informations are missing and even errors exist. Use your own risk. Thank you for your consideration.
18
19
 
19
- - It is typesafe.
20
- - Parse dxf at high speed.
21
- - Lightweight library
20
+ ## Quick Start
21
+
22
+ ```
23
+ npm i dxf-json # or your loved package manager
24
+ ```
25
+
26
+ ```ts
27
+ import { readFileSync } from 'fs'
28
+ import { DxfParser } from 'dxf-json'
29
+
30
+ const content = readFileSync('foo.dxf', 'utf-8');
31
+ const parser = new DxfParser()
32
+ const parsedDxf = parser.parseSync(content)
33
+
34
+ // play with your dxf file
35
+ const lwPolylines = parsedDxf.entities.filter(entity => entity.type === 'LWPOLYLINE')
36
+ ```
22
37
 
23
38
  ## Features
24
39
 
25
40
  - Synchronous parsing, asynchronous parsing, and url fetch are possible.
26
- - It was created for the purpose of parsing the AutoCad Dxf format. [Dxf ref](https://documentation.help/AutoCAD-DXF/)
27
- - It is modularized and divided into Header, Classes, Tables, Blocks, Entities, and Objects sections.
28
- - It's very simple to use.
29
- - When I input dxf file it returns json data.
41
+ - Support both ESM and CJS
42
+ - Support TypeScript
30
43
 
31
- The goal of this library is to fully analyze dxf files from AutoCad and convert them to json files.
44
+ > [!NOTE]
45
+ > We support standard specification of dxf and AutoCAD features only. We're trying our best to support universal dxf files, but we don't support 3rd party specification.
32
46
 
33
47
  <details><summary>Current Coverage</summary>
34
48
 
@@ -51,12 +65,12 @@ Based on [AutoCAD 2024 DXF Reference](https://help.autodesk.com/view/OARX/2024/E
51
65
  - [x] BLOCKS Section
52
66
  - [ ] ENTITIES Section
53
67
  - [x] 3DFACE
54
- - [ ] 3DSOLID
68
+ - [x] 3DSOLID
55
69
  - [ ] ACAD_PROXY_ENTITY
56
70
  - [x] ARC
57
71
  - [x] ATTDEF
58
72
  - [x] ATTRIB
59
- - [ ] BODY
73
+ - [x] BODY
60
74
  - [x] CIRCLE
61
75
  - [ ] COORDINATION MODEL
62
76
  - [x] DIMENSION
@@ -69,7 +83,7 @@ Based on [AutoCAD 2024 DXF Reference](https://help.autodesk.com/view/OARX/2024/E
69
83
  - [ ] LIGHT
70
84
  - [x] LINE
71
85
  - [x] LWPOLYLINE
72
- - [ ] MESH
86
+ - [x] MESH
73
87
  - [x] MLEADER
74
88
  - [ ] MLEADERSTYLE
75
89
  - [ ] MLINE
@@ -79,7 +93,7 @@ Based on [AutoCAD 2024 DXF Reference](https://help.autodesk.com/view/OARX/2024/E
79
93
  - [x] POINT
80
94
  - [x] POLYLINE
81
95
  - [x] RAY
82
- - [ ] REGION
96
+ - [x] REGION
83
97
  - [x] SECTION
84
98
  - [ ] SEQEND
85
99
  - [ ] SHAPE
@@ -89,13 +103,13 @@ Based on [AutoCAD 2024 DXF Reference](https://help.autodesk.com/view/OARX/2024/E
89
103
  - [ ] SURFACE
90
104
  - [ ] TABLE
91
105
  - [x] TEXT
92
- - [ ] TOLERANCE
106
+ - [x] TOLERANCE
93
107
  - [ ] TRACE
94
108
  - [ ] UNDERLAY
95
109
  - [x] VERTEX
96
110
  - [x] VIEWPORT
97
- - [ ] WIPEOUT
98
- - [ ] XLINE
111
+ - [x] WIPEOUT
112
+ - [x] XLINE
99
113
  - [ ] OBJECTS Section
100
114
  - [ ] DATATABLE
101
115
  - [x] DICTIONARY
@@ -119,7 +133,7 @@ Based on [AutoCAD 2024 DXF Reference](https://help.autodesk.com/view/OARX/2024/E
119
133
  - [ ] RENDER
120
134
  - [ ] SECTION
121
135
  - [ ] SORTENSTABLE
122
- - [ ] SPATIAL_FILTER
136
+ - [x] SPATIAL_FILTER
123
137
  - [ ] SPATIAL_INDEX
124
138
  - [ ] SUNSTUDY
125
139
  - [ ] TABLESTYLE
@@ -127,45 +141,22 @@ Based on [AutoCAD 2024 DXF Reference](https://help.autodesk.com/view/OARX/2024/E
127
141
  - [ ] VBA_PROJECT
128
142
  - [ ] VISUALSTYLE
129
143
  - [ ] WIPEOUTVARIABLES
130
- - [ ] XRECORD
144
+ - [x] XRECORD
131
145
  - [ ] THUMBNAILIMAGE Section
132
146
 
133
147
  </details>
134
148
 
135
- ## Reference
149
+ > [!NOTE]
150
+ > The documentation is not ready, but you can check the source code for used types [#1](https://github.com/dotoritos-kim/dxf-json/blob/main/src/parser/types.ts) and [#2](https://github.com/dotoritos-kim/dxf-json/blob/main/integration-test/src/types/import-test.ts)
136
151
 
137
- I was able to get a lot of ideas from the [dxf-parser](https://github.com/gdsestimating/dxf-parser) library.
138
-
139
- ## How do I use it?
140
-
141
- npm package:
142
-
143
- ```sh
144
- npm i dxf-json
145
- ```
146
-
147
- build:
148
-
149
- ```sh
150
- npm install
151
- npm run build
152
- ```
153
-
154
- test:
155
-
156
- ```sh
157
- npm install
158
- npm run test:parser
159
- ```
160
-
161
- parseSync:
152
+ ### `parseSync`
162
153
 
163
154
  ```ts
164
155
  const parser = new DxfParser()
165
156
  return parser.parseSync(buffer)
166
157
  ```
167
158
 
168
- parseStream:
159
+ ### `parseStream`
169
160
 
170
161
  ```ts
171
162
  import fs from 'fs'
@@ -174,454 +165,13 @@ const fileStream = fs.createReadStream("dxf file path", { encoding: 'utf8' });
174
165
  return await parser.parseStream(fileStream);
175
166
  ```
176
167
 
177
- parseUrl:
168
+ ### `parseUrl`
178
169
 
179
170
  ```ts
180
171
  const parser = new DxfParser();
181
172
  return await parser.parseFromUrl(url, encoding, RequestInit);
182
173
  ```
183
174
 
184
- ## Type
185
-
186
- ParsedDxf:
187
-
188
- ```ts
189
- interface ParsedDxf {
190
- header: DxfHeader;
191
- blocks: Record<string, DxfBlock>;
192
- entities: CommonDxfEntity[];
193
- tables: {
194
- BLOCK_RECORD?: DxfTable<BlockRecordTableEntry>;
195
- DIMSTYLE?: DxfTable<DimStylesTableEntry>;
196
- STYLE?: DxfTable<StyleTableEntry>;
197
- LAYER?: DxfTable<LayerTableEntry>;
198
- LTYPE?: DxfTable<LTypeTableEntry>;
199
- VPORT?: DxfTable<VPortTableEntry>;
200
- };
201
- objects: {
202
- byName: Record<string, CommonDXFObject[]>;
203
- byTree?: DxfObject;
204
- };
205
- }
206
- ```
207
-
208
- ### header
209
-
210
- DxfHeader:
211
-
212
- ```ts
213
- type DxfHeaderVariable =
214
- ...
215
- | 'DRAGVS'
216
- | 'INTERFERECOLOR'
217
- | 'INTERFEREOBJVS'
218
- | 'INTERFEREVPVS'
219
- | 'OBSLTYPE'
220
- | 'SHADEDIF'
221
- | 'MEASUREMENT';
222
-
223
- export type DxfHeader = typeof DefaultDxfHeaderVariables & {
224
- MEASUREMENT: Measurement;
225
- } & Record<string, any>;
226
- ```
227
-
228
- ### blocks
229
-
230
- DxfBlock:
231
-
232
- ```ts
233
- interface DxfBlock {
234
- type: number;
235
- name: string;
236
- name2: string;
237
- handle: string;
238
- ownerHandle: string;
239
- layer: string;
240
- position: Point3D;
241
- paperSpace: boolean;
242
- xrefPath: string;
243
- entities?: CommonDxfEntity[];
244
- }
245
- ```
246
-
247
- ### entities
248
-
249
- CommonDxfEntity:
250
-
251
- ```ts
252
- interface CommonDxfEntity {
253
- type: string;
254
- handle: string;
255
- ownerBlockRecordSoftId?: string;
256
- isInPaperSpace?: boolean;
257
- layer: string;
258
- lineType?: string;
259
- materialObjectHardId?: string;
260
- colorIndex?: ColorIndex;
261
- lineweight?: number;
262
- lineTypeScale?: number;
263
- isVisible?: boolean;
264
- proxyByte?: number;
265
- proxyEntity?: string;
266
- color?: ColorInstance;
267
- colorName?: string;
268
- transparency?: number;
269
- plotStyleHardId?: string;
270
- shadowMode?: ShadowMode;
271
- xdata?: XData;
272
- ownerdictionaryHardId?: string | number | boolean;
273
- ownerDictionarySoftId?: string | number | boolean;
274
- }
275
- ```
276
-
277
- ### tables
278
-
279
- ```ts
280
- tables: {
281
- BLOCK_RECORD?: DxfTable<BlockRecordTableEntry>;
282
- DIMSTYLE?: DxfTable<DimStylesTableEntry>;
283
- STYLE?: DxfTable<StyleTableEntry>;
284
- LAYER?: DxfTable<LayerTableEntry>;
285
- LTYPE?: DxfTable<LTypeTableEntry>;
286
- VPORT?: DxfTable<VPortTableEntry>;
287
- };
288
- ```
289
-
290
- #### DxfTable
291
-
292
- ```ts
293
- interface DxfTable<T extends CommonDxfTableEntry> {
294
- subclassMarker: 'AcDbSymbolTable';
295
- name: string;
296
- handle: string;
297
- ownerDictionaryIds?: string[];
298
- ownerObjectId: string;
299
- maxNumberOfEntries: number;
300
- entries: T[];
301
- }
302
- interface CommonDxfTableEntry {
303
- name: string;
304
- handle: string;
305
- ownerObjectId: string;
306
- }
307
- ```
308
-
309
- #### BLOCK_RECORD
310
-
311
- BlockRecordTableEntry:
312
-
313
- ```ts
314
- interface BlockRecordTableEntry extends CommonDxfTableEntry {
315
- subclassMarker: 'AcDbBlockTableRecord';
316
- name: string;
317
- layoutObjects: string;
318
- insertionUnits: number;
319
- explodability: number;
320
- scalability: number;
321
- bmpPreview: string;
322
- }
323
- ```
324
-
325
- #### DIMSTYLE
326
-
327
- ```ts
328
- type DimStyleVariable =
329
- | 'DIMPOST'
330
- | 'DIMAPOST'
331
- | 'DIMBLK_OBSOLETE'
332
- | 'DIMBLK1_OBSOLETE'
333
- | 'DIMBLK2_OBSOLETE'
334
- | 'DIMSCALE'
335
- | 'DIMASZ'
336
- | 'DIMEXO'
337
- | 'DIMDLI'
338
- | 'DIMEXE'
339
- | 'DIMRND'
340
- | 'DIMDLE'
341
- | 'DIMTP'
342
- | 'DIMTM'
343
- | 'DIMTXT'
344
- | 'DIMCEN'
345
- | 'DIMTSZ'
346
- | 'DIMALTF'
347
- | 'DIMLFAC'
348
- | 'DIMTVP'
349
- | 'DIMTFAC'
350
- | 'DIMGAP'
351
- | 'DIMALTRND'
352
- | 'DIMTOL'
353
- | 'DIMLIM'
354
- | 'DIMTIH'
355
- | 'DIMTOH'
356
- | 'DIMSE1'
357
- | 'DIMSE2'
358
- | 'DIMTAD'
359
- | 'DIMZIN'
360
- | 'DIMAZIN'
361
- | 'DIMALT'
362
- | 'DIMALTD'
363
- | 'DIMTOFL'
364
- | 'DIMSAH'
365
- | 'DIMTIX'
366
- | 'DIMSOXD'
367
- | 'DIMCLRD'
368
- | 'DIMCLRE'
369
- | 'DIMCLRT'
370
- | 'DIMADEC'
371
- | 'DIMUNIT'
372
- | 'DIMDEC'
373
- | 'DIMTDEC'
374
- | 'DIMALTU'
375
- | 'DIMALTTD'
376
- | 'DIMAUNIT'
377
- | 'DIMFRAC'
378
- | 'DIMLUNIT'
379
- | 'DIMDSEP'
380
- | 'DIMTMOVE'
381
- | 'DIMJUST'
382
- | 'DIMSD1'
383
- | 'DIMSD2'
384
- | 'DIMTOLJ'
385
- | 'DIMTZIN'
386
- | 'DIMALTZ'
387
- | 'DIMALTTZ'
388
- | 'DIMFIT'
389
- | 'DIMUPT'
390
- | 'DIMATFIT'
391
- | 'DIMTXSTY'
392
- | 'DIMLDRBLK'
393
- | 'DIMBLK'
394
- | 'DIMBLK1'
395
- | 'DIMBLK2'
396
- | 'DIMLWD'
397
- | 'DIMLWE';
398
-
399
- interface DimStyleVariableSchema {
400
- name: string;
401
- code: number;
402
- defaultValue?: string | number;
403
- defaultValueImperial?: string | number;
404
- }
405
-
406
- type DimStylesTableEntry = {
407
- subclassMarker: 'AcDbDimStyleTableRecord';
408
- styleName: string;
409
- DIMPOST?: string;
410
- DIMAPOST?: string;
411
- DIMBLK_OBSOLETE?: string;
412
- DIMBLK1_OBSOLETE?: string;
413
- DIMBLK2_OBSOLETE?: string;
414
- DIMSCALE: number;
415
- DIMASZ: number;
416
- DIMEXO: number;
417
- DIMDLI: number;
418
- DIMEXE: number;
419
- DIMRND: number;
420
- DIMDLE: number;
421
- DIMTP: number;
422
- DIMTM: number;
423
- DIMTXT: number;
424
- DIMCEN: number;
425
- DIMTSZ: number;
426
- DIMALTF: number;
427
- DIMLFAC: number;
428
- DIMTVP: number;
429
- DIMTFAC: number;
430
- DIMGAP: number;
431
- DIMALTRND: number;
432
- DIMTOL: number;
433
- DIMLIM: number;
434
- DIMTIH: number;
435
- DIMTOH: number;
436
- DIMSE1: 0 | 1;
437
- DIMSE2: 0 | 1;
438
- DIMTAD: DimensionTextVertical;
439
- DIMZIN: DimensionZeroSuppression;
440
- DIMAZIN: DimensionZeroSuppressionAngular;
441
- DIMALT: 0 | 1;
442
- DIMALTD: number;
443
- DIMTOFL: 0 | 1;
444
- DIMSAH: 0 | 1;
445
- DIMTIX: 0 | 1;
446
- DIMSOXD: 0 | 1;
447
- DIMCLRD: number;
448
- DIMCLRE: number;
449
- DIMCLRT: number;
450
- DIMADEC?: number;
451
- DIMUNIT?: number;
452
- DIMDEC: number;
453
- DIMTDEC: number;
454
- DIMALTU: number;
455
- DIMALTTD: number;
456
- DIMAUNIT: number;
457
- DIMFRAC: number;
458
- DIMLUNIT: number;
459
- DIMDSEP: string;
460
- DIMTMOVE: undefined; // 미사용
461
- DIMJUST: DimensionTextHorizontal;
462
- DIMSD1: 0 | 1;
463
- DIMSD2: 0 | 1;
464
- DIMTOLJ: DimensionTextVertical;
465
- DIMTZIN: DimensionZeroSuppression;
466
- DIMALTZ: DimensionZeroSuppression;
467
- DIMALTTZ: DimensionZeroSuppression;
468
- DIMFIT?: number;
469
- DIMUPT: number;
470
- DIMATFIT: number;
471
- DIMTXSTY?: string;
472
- DIMLDRBLK?: string;
473
- DIMBLK?: string;
474
- DIMBLK1?: string;
475
- DIMBLK2?: string;
476
- DIMLWD: number;
477
- DIMLWE: number;
478
- } & CommonDxfTableEntry;
479
-
480
- type StyleResolver = <Name extends DimStyleVariable>(
481
- variableName: Name,
482
- ) => DimStylesTableEntry[Name];
483
- ```
484
-
485
- #### STYLE
486
-
487
- ```ts
488
- interface StyleTableEntry extends CommonDxfTableEntry {
489
- subclassMarker: 'AcDbTextStyleTableRecord';
490
- name: string;
491
- standardFlag: number;
492
- fixedTextHeight: number;
493
- widthFactor: number;
494
- obliqueAngle: number;
495
- textGenerationFlag: number;
496
- lastHeight: number;
497
- font: string;
498
- bigFont: string;
499
- extendedFont?: string;
500
- }
501
- ```
502
-
503
- #### LAYER
504
-
505
- ```ts
506
- interface LayerTableEntry extends CommonDxfTableEntry {
507
- subclassMarker: 'AcDbLayerTableRecord';
508
- name: string;
509
- standardFlag: number;
510
- colorIndex: ColorIndex;
511
- lineType: string;
512
- isPlotting: boolean;
513
- lineweight: number;
514
- plotStyleNameObjectId?: string;
515
- materialObjectId?: string;
516
- }
517
- ```
518
-
519
- #### LTYPE
520
-
521
- ```ts
522
- interface LTypeTableEntry extends CommonDxfTableEntry {
523
- subclassMarker: 'AcDbLinetypeTableRecord';
524
- name: string;
525
- standardFlag: number;
526
- description: string;
527
- numberOfLineTypes: number;
528
- totalPatternLength: number;
529
- pattern?: LineTypeElement[];
530
- }
531
- interface LineTypeElement {
532
- elementLength: number;
533
- elementTypeFlag: number;
534
- shapeNumber?: number;
535
- styleObjectId?: string;
536
- scale?: number;
537
- rotation?: number;
538
- offsetX?: number;
539
- offsetY?: number;
540
- text?: string;
541
- }
542
- ```
543
-
544
- #### VPORT
545
-
546
- ```ts
547
- interface VPortTableEntry extends CommonDxfTableEntry {
548
- subclassMarker: 'AcDbViewportTableRecord';
549
- name: string;
550
- standardFlag: number;
551
- lowerLeftCorner: Point2D;
552
- upperRightCorner: Point2D;
553
- center: Point2D;
554
- snapBasePoint: Point2D;
555
- snapSpacing: Point2D;
556
- gridSpacing: Point2D;
557
- viewDirectionFromTarget: Point3D;
558
- viewTarget: Point3D;
559
- lensLength: number;
560
- frontClippingPlane: number;
561
- backClippingPlane: number;
562
- viewHeight: number;
563
- snapRotationAngle: number;
564
- viewTwistAngle: number;
565
- circleSides: number;
566
- frozenLayers: string[];
567
- styleSheet: string;
568
- renderMode: RenderMode;
569
- viewMode: number;
570
- ucsIconSetting: number;
571
- ucsOrigin: Point3D;
572
- ucsXAxis: Point3D;
573
- ucsYAxis: Point3D;
574
- orthographicType: OrthographicType;
575
- elevation: number;
576
- shadePlotSetting: number;
577
- majorGridLines: number;
578
- backgroundObjectId?: string;
579
- shadePlotObjectId?: string;
580
- visualStyleObjectId?: string;
581
- isDefaultLightingOn: boolean;
582
- defaultLightingType: DefaultLightingType;
583
- brightness: number;
584
- contrast: number;
585
- ambientColor?: number;
586
- }
587
- ```
588
-
589
- ### objects
590
-
591
- ```ts
592
- objects: {
593
- byName: Record<string, CommonDXFObject[]>;
594
- byTree?: DxfObject;
595
- };
596
- ```
597
-
598
- #### byName
599
-
600
- CommonDXFObject:
601
-
602
- ```ts
603
- interface CommonDXFObject {
604
- ownerObjectId: string;
605
- ownerDictionaryIdHard: string;
606
- ownerDictionaryIdSoft: string;
607
- handle: string;
608
- }
609
- ```
610
-
611
- #### DxfObject
612
-
613
- ```ts
614
- interface DxfObject {
615
- name: string;
616
- handle: string;
617
- ownerDictionaryIdSoft: string;
618
- ownerDictionaryIdHard?: string;
619
- ownerObjectId?: string;
620
- }
621
- ```
622
-
623
- Please refer to the dxf reference for undefined elements and leave them as issues!
624
-
625
- ## License
175
+ ## Contribution
626
176
 
627
- GPL-3.0 license
177
+ See [CONTRIBUTING.md](https://github.com/dotoritos-kim/dxf-json/blob/main/CONTRIBUTING.md)