dxf-json 0.0.1

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.
Files changed (167) hide show
  1. package/.github/FUNDING.yml +1 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  3. package/.github/ISSUE_TEMPLATE/custom.md +10 -0
  4. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  5. package/.github/pull_request_template.md +23 -0
  6. package/.github/workflows/npm-publish.yml +55 -0
  7. package/.swcrc +8 -0
  8. package/LICENSE +674 -0
  9. package/README.md +567 -0
  10. package/jest.config.js +20 -0
  11. package/package.json +56 -0
  12. package/src/consts/block.ts +22 -0
  13. package/src/consts/color.ts +6 -0
  14. package/src/consts/config.ts +2 -0
  15. package/src/consts/dimension.ts +69 -0
  16. package/src/consts/hatch.ts +52 -0
  17. package/src/consts/header.ts +10 -0
  18. package/src/consts/index.ts +9 -0
  19. package/src/consts/lineweight.ts +5 -0
  20. package/src/consts/measurement.ts +4 -0
  21. package/src/consts/obscuredLineTypes.ts +21 -0
  22. package/src/consts/scene.ts +2 -0
  23. package/src/consts/viewport.ts +62 -0
  24. package/src/index.ts +6 -0
  25. package/src/parser/AutoCadColorIndex.ts +265 -0
  26. package/src/parser/DxfArrayScanner.ts +161 -0
  27. package/src/parser/DxfParser.ts +108 -0
  28. package/src/parser/ParseHelpers.ts +124 -0
  29. package/src/parser/blocks/blocks.test.ts +97 -0
  30. package/src/parser/blocks/index.ts +88 -0
  31. package/src/parser/blocks/types.ts +15 -0
  32. package/src/parser/entities/arc/index.ts +2 -0
  33. package/src/parser/entities/arc/parser.ts +67 -0
  34. package/src/parser/entities/arc/types.ts +13 -0
  35. package/src/parser/entities/attdef/consts.ts +12 -0
  36. package/src/parser/entities/attdef/index.ts +3 -0
  37. package/src/parser/entities/attdef/parser.ts +119 -0
  38. package/src/parser/entities/attdef/types.ts +19 -0
  39. package/src/parser/entities/attribute/consts.ts +6 -0
  40. package/src/parser/entities/attribute/index.ts +3 -0
  41. package/src/parser/entities/attribute/parser.ts +198 -0
  42. package/src/parser/entities/attribute/types.ts +31 -0
  43. package/src/parser/entities/circle/index.ts +2 -0
  44. package/src/parser/entities/circle/parser.ts +58 -0
  45. package/src/parser/entities/circle/types.ts +11 -0
  46. package/src/parser/entities/dimension/common.ts +98 -0
  47. package/src/parser/entities/dimension/index.ts +24 -0
  48. package/src/parser/entities/dimension/types.ts +65 -0
  49. package/src/parser/entities/ellipse/index.ts +2 -0
  50. package/src/parser/entities/ellipse/parser.ts +66 -0
  51. package/src/parser/entities/ellipse/types.ts +13 -0
  52. package/src/parser/entities/entities.test.ts +86 -0
  53. package/src/parser/entities/hatch/boundaryPathData/edge.ts +190 -0
  54. package/src/parser/entities/hatch/boundaryPathData/index.ts +27 -0
  55. package/src/parser/entities/hatch/boundaryPathData/polyline.ts +43 -0
  56. package/src/parser/entities/hatch/boundaryPathData/shared.ts +16 -0
  57. package/src/parser/entities/hatch/index.ts +189 -0
  58. package/src/parser/entities/hatch/patternData.ts +57 -0
  59. package/src/parser/entities/hatch/types/boundaryPath.ts +72 -0
  60. package/src/parser/entities/hatch/types/definitionLine.ts +14 -0
  61. package/src/parser/entities/hatch/types/hatch.ts +47 -0
  62. package/src/parser/entities/hatch/types/index.ts +3 -0
  63. package/src/parser/entities/index.ts +87 -0
  64. package/src/parser/entities/insert/index.ts +2 -0
  65. package/src/parser/entities/insert/parser.ts +106 -0
  66. package/src/parser/entities/insert/types.ts +19 -0
  67. package/src/parser/entities/leader/consts.ts +6 -0
  68. package/src/parser/entities/leader/index.ts +3 -0
  69. package/src/parser/entities/leader/parser.ts +119 -0
  70. package/src/parser/entities/leader/types.ts +24 -0
  71. package/src/parser/entities/line/index.ts +2 -0
  72. package/src/parser/entities/line/parser.ts +55 -0
  73. package/src/parser/entities/line/types.ts +11 -0
  74. package/src/parser/entities/lwpolyline/consts.ts +4 -0
  75. package/src/parser/entities/lwpolyline/index.ts +3 -0
  76. package/src/parser/entities/lwpolyline/parser.ts +122 -0
  77. package/src/parser/entities/lwpolyline/types.ts +21 -0
  78. package/src/parser/entities/mtext/consts.ts +5 -0
  79. package/src/parser/entities/mtext/index.ts +3 -0
  80. package/src/parser/entities/mtext/parser.ts +195 -0
  81. package/src/parser/entities/mtext/types.ts +34 -0
  82. package/src/parser/entities/point/index.ts +2 -0
  83. package/src/parser/entities/point/parser.ts +60 -0
  84. package/src/parser/entities/point/types.ts +10 -0
  85. package/src/parser/entities/polyline/consts.ts +17 -0
  86. package/src/parser/entities/polyline/index.ts +3 -0
  87. package/src/parser/entities/polyline/parser.ts +126 -0
  88. package/src/parser/entities/polyline/types.ts +20 -0
  89. package/src/parser/entities/section/index.ts +2 -0
  90. package/src/parser/entities/section/parser.ts +104 -0
  91. package/src/parser/entities/section/types.ts +20 -0
  92. package/src/parser/entities/shared.ts +166 -0
  93. package/src/parser/entities/solid/index.ts +2 -0
  94. package/src/parser/entities/solid/parser.ts +56 -0
  95. package/src/parser/entities/solid/types.ts +10 -0
  96. package/src/parser/entities/spline/consts.ts +8 -0
  97. package/src/parser/entities/spline/index.ts +3 -0
  98. package/src/parser/entities/spline/parser.ts +121 -0
  99. package/src/parser/entities/spline/types.ts +22 -0
  100. package/src/parser/entities/text/consts.ts +21 -0
  101. package/src/parser/entities/text/index.ts +3 -0
  102. package/src/parser/entities/text/parser.ts +117 -0
  103. package/src/parser/entities/text/types.ts +21 -0
  104. package/src/parser/entities/vertex/consts.ts +10 -0
  105. package/src/parser/entities/vertex/index.ts +3 -0
  106. package/src/parser/entities/vertex/parser.ts +90 -0
  107. package/src/parser/entities/vertex/types.ts +17 -0
  108. package/src/parser/entities/viewport/index.ts +178 -0
  109. package/src/parser/entities/viewport/types.ts +58 -0
  110. package/src/parser/filterDummyBlocks.ts +49 -0
  111. package/src/parser/header/index.ts +30 -0
  112. package/src/parser/objects/common.ts +55 -0
  113. package/src/parser/objects/dictionary.ts +61 -0
  114. package/src/parser/objects/index.ts +45 -0
  115. package/src/parser/objects/layout.ts +136 -0
  116. package/src/parser/objects/plotSettings.ts +231 -0
  117. package/src/parser/objects/treefy.ts +53 -0
  118. package/src/parser/objects/types.ts +17 -0
  119. package/src/parser/shared/index.ts +21 -0
  120. package/src/parser/shared/parsePoint.ts +37 -0
  121. package/src/parser/shared/parserGenerator.test.ts +164 -0
  122. package/src/parser/shared/parserGenerator.ts +180 -0
  123. package/src/parser/shared/xdata/index.ts +3 -0
  124. package/src/parser/shared/xdata/interpreter.test.ts +85 -0
  125. package/src/parser/shared/xdata/interpreter.ts +65 -0
  126. package/src/parser/shared/xdata/parser.test.ts +66 -0
  127. package/src/parser/shared/xdata/parser.ts +140 -0
  128. package/src/parser/shared/xdata/types.ts +22 -0
  129. package/src/parser/tables/blockRecord/index.ts +2 -0
  130. package/src/parser/tables/blockRecord/parser.ts +49 -0
  131. package/src/parser/tables/blockRecord/types.ts +11 -0
  132. package/src/parser/tables/dimStyle/consts.ts +428 -0
  133. package/src/parser/tables/dimStyle/index.ts +3 -0
  134. package/src/parser/tables/dimStyle/parser.ts +37 -0
  135. package/src/parser/tables/dimStyle/types.ts +164 -0
  136. package/src/parser/tables/index.ts +2 -0
  137. package/src/parser/tables/layer/index.ts +2 -0
  138. package/src/parser/tables/layer/parser.ts +58 -0
  139. package/src/parser/tables/layer/types.ts +14 -0
  140. package/src/parser/tables/ltype/consts.ts +6 -0
  141. package/src/parser/tables/ltype/index.ts +3 -0
  142. package/src/parser/tables/ltype/parser.ts +110 -0
  143. package/src/parser/tables/ltype/types.ts +23 -0
  144. package/src/parser/tables/parser.ts +100 -0
  145. package/src/parser/tables/shared.ts +32 -0
  146. package/src/parser/tables/style/index.ts +2 -0
  147. package/src/parser/tables/style/parser.ts +70 -0
  148. package/src/parser/tables/style/types.ts +15 -0
  149. package/src/parser/tables/types.ts +15 -0
  150. package/src/parser/tables/vport/index.ts +2 -0
  151. package/src/parser/tables/vport/parser.ts +205 -0
  152. package/src/parser/tables/vport/types.ts +48 -0
  153. package/src/parser/types.ts +30 -0
  154. package/src/types/color.ts +5 -0
  155. package/src/types/dxfHeader.ts +21 -0
  156. package/src/types/entity.ts +7 -0
  157. package/src/types/index.ts +30 -0
  158. package/src/utils/binarySearch.ts +20 -0
  159. package/src/utils/disjointSet.ts +52 -0
  160. package/src/utils/flooding.ts +37 -0
  161. package/src/utils/functional.ts +124 -0
  162. package/src/utils/graph.ts +53 -0
  163. package/src/utils/index.ts +102 -0
  164. package/src/utils/queue.ts +77 -0
  165. package/src/utils/triangle.ts +28 -0
  166. package/tsconfig.json +34 -0
  167. package/webpack.config.js +46 -0
package/README.md ADDED
@@ -0,0 +1,567 @@
1
+ # DXF-JSON
2
+
3
+ <p align="center">
4
+ <img width="100%" src="https://github.com/dotoritos-kim/dxf-json/assets/14037015/a534bedc-3191-4f7b-a610-f3291a77ca6c">
5
+ </p>
6
+
7
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
8
+
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
+
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)
12
+
13
+ ![NPM](https://img.shields.io/badge/NPM-%23CB3837.svg?style=for-the-badge&logo=npm&logoColor=white)
14
+
15
+ ## Perfect Dxf Parser
16
+
17
+ A library that reliably parses DXF files into JSON files without missing data.
18
+
19
+ - It is typesafe.
20
+ - Parse dxf at high speed.
21
+ - Lightweight library
22
+
23
+ ## Features
24
+
25
+ - 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.
30
+
31
+ The goal of this library is to fully analyze dxf files from AutoCad and convert them to json files.
32
+
33
+ ## Coverage
34
+
35
+ Block:
36
+
37
+ - The BLOCKS section of the DXF file contains an entry for each block reference in the drawing.
38
+
39
+ Header:
40
+
41
+ - Most headers can be loaded. All that remains is to add types and add descriptions.
42
+
43
+ Entity:
44
+
45
+ - arc
46
+ - attdef
47
+ - attribute
48
+ - circle
49
+ - dimension
50
+ - ellipse
51
+ - hatch
52
+ - insert
53
+ - leader
54
+ - line
55
+ - lwpolyline
56
+ - mtext
57
+ - point
58
+ - polyline
59
+ - section
60
+ - solid
61
+ - spline
62
+ - text
63
+ - vertex
64
+ - viewport
65
+
66
+ Tables:
67
+
68
+ - blockRecord
69
+ - dimStyle
70
+ - layer
71
+ - ltype
72
+ - style
73
+ - vport
74
+
75
+ Objects:
76
+
77
+ - dictionary
78
+ - layout
79
+ - plotSettings
80
+
81
+ ## Reference
82
+
83
+ I was able to get a lot of ideas from the [dxf-parser](https://github.com/gdsestimating/dxf-parser) library.
84
+
85
+ ## How do I use it?
86
+
87
+ build:
88
+
89
+ ```sh
90
+ npm install
91
+ npm run build
92
+ ```
93
+
94
+ test:
95
+
96
+ ```sh
97
+ npm install
98
+ npm run test:parser
99
+ ```
100
+
101
+ parseSync:
102
+
103
+ ```ts
104
+ const parser = new DxfParser()
105
+ return parser.parseSync(buffer)
106
+ ```
107
+
108
+ parseStream:
109
+
110
+ ```ts
111
+ import fs from 'fs'
112
+ const parser = new DxfParser();
113
+ const fileStream = fs.createReadStream("dxf file path", { encoding: 'utf8' });
114
+ return await parser.parseStream(fileStream);
115
+ ```
116
+
117
+ parseUrl:
118
+
119
+ ```ts
120
+ const parser = new DxfParser();
121
+ return await parser.parseFromUrl(url, encoding, RequestInit);
122
+ ```
123
+
124
+ ## Type
125
+
126
+ ParsedDxf:
127
+
128
+ ```ts
129
+ interface ParsedDxf {
130
+ header: DxfHeader;
131
+ blocks: Record<string, DxfBlock>;
132
+ entities: CommonDxfEntity[];
133
+ tables: {
134
+ BLOCK_RECORD?: DxfTable<BlockRecordTableEntry>;
135
+ DIMSTYLE?: DxfTable<DimStylesTableEntry>;
136
+ STYLE?: DxfTable<StyleTableEntry>;
137
+ LAYER?: DxfTable<LayerTableEntry>;
138
+ LTYPE?: DxfTable<LTypeTableEntry>;
139
+ VPORT?: DxfTable<VPortTableEntry>;
140
+ };
141
+ objects: {
142
+ byName: Record<string, CommonDXFObject[]>;
143
+ byTree?: DxfObject;
144
+ };
145
+ }
146
+ ```
147
+
148
+ ### header
149
+
150
+ DxfHeader:
151
+
152
+ ```ts
153
+ type DxfHeaderVariable =
154
+ ...
155
+ | 'DRAGVS'
156
+ | 'INTERFERECOLOR'
157
+ | 'INTERFEREOBJVS'
158
+ | 'INTERFEREVPVS'
159
+ | 'OBSLTYPE'
160
+ | 'SHADEDIF'
161
+ | 'MEASUREMENT';
162
+
163
+ export type DxfHeader = typeof DefaultDxfHeaderVariables & {
164
+ MEASUREMENT: Measurement;
165
+ } & Record<string, any>;
166
+ ```
167
+
168
+ ### blocks
169
+
170
+ DxfBlock:
171
+
172
+ ```ts
173
+ interface DxfBlock {
174
+ type: number;
175
+ name: string;
176
+ name2: string;
177
+ handle: string;
178
+ ownerHandle: string;
179
+ layer: string;
180
+ position: Point3D;
181
+ paperSpace: boolean;
182
+ xrefPath: string;
183
+ entities?: CommonDxfEntity[];
184
+ }
185
+ ```
186
+
187
+ ### entities
188
+
189
+ CommonDxfEntity:
190
+
191
+ ```ts
192
+ interface CommonDxfEntity {
193
+ type: string;
194
+ handle: string;
195
+ ownerBlockRecordSoftId?: string;
196
+ isInPaperSpace?: boolean;
197
+ layer: string;
198
+ lineType?: string;
199
+ materialObjectHardId?: string;
200
+ colorIndex?: ColorIndex;
201
+ lineweight?: number;
202
+ lineTypeScale?: number;
203
+ isVisible?: boolean;
204
+ proxyByte?: number;
205
+ proxyEntity?: string;
206
+ color?: ColorInstance;
207
+ colorName?: string;
208
+ transparency?: number;
209
+ plotStyleHardId?: string;
210
+ shadowMode?: ShadowMode;
211
+ xdata?: XData;
212
+ ownerdictionaryHardId?: string | number | boolean;
213
+ ownerDictionarySoftId?: string | number | boolean;
214
+ }
215
+ ```
216
+
217
+ ### tables
218
+
219
+ ```ts
220
+ tables: {
221
+ BLOCK_RECORD?: DxfTable<BlockRecordTableEntry>;
222
+ DIMSTYLE?: DxfTable<DimStylesTableEntry>;
223
+ STYLE?: DxfTable<StyleTableEntry>;
224
+ LAYER?: DxfTable<LayerTableEntry>;
225
+ LTYPE?: DxfTable<LTypeTableEntry>;
226
+ VPORT?: DxfTable<VPortTableEntry>;
227
+ };
228
+ ```
229
+
230
+ #### DxfTable
231
+
232
+ ```ts
233
+ interface DxfTable<T extends CommonDxfTableEntry> {
234
+ subclassMarker: 'AcDbSymbolTable';
235
+ name: string;
236
+ handle: string;
237
+ ownerDictionaryIds?: string[];
238
+ ownerObjectId: string;
239
+ maxNumberOfEntries: number;
240
+ entries: T[];
241
+ }
242
+ interface CommonDxfTableEntry {
243
+ name: string;
244
+ handle: string;
245
+ ownerObjectId: string;
246
+ }
247
+ ```
248
+
249
+ #### BLOCK_RECORD
250
+
251
+ BlockRecordTableEntry:
252
+
253
+ ```ts
254
+ interface BlockRecordTableEntry extends CommonDxfTableEntry {
255
+ subclassMarker: 'AcDbBlockTableRecord';
256
+ name: string;
257
+ layoutObjects: string;
258
+ insertionUnits: number;
259
+ explodability: number;
260
+ scalability: number;
261
+ bmpPreview: string;
262
+ }
263
+ ```
264
+
265
+ #### DIMSTYLE
266
+
267
+ ```ts
268
+ type DimStyleVariable =
269
+ | 'DIMPOST'
270
+ | 'DIMAPOST'
271
+ | 'DIMBLK_OBSOLETE'
272
+ | 'DIMBLK1_OBSOLETE'
273
+ | 'DIMBLK2_OBSOLETE'
274
+ | 'DIMSCALE'
275
+ | 'DIMASZ'
276
+ | 'DIMEXO'
277
+ | 'DIMDLI'
278
+ | 'DIMEXE'
279
+ | 'DIMRND'
280
+ | 'DIMDLE'
281
+ | 'DIMTP'
282
+ | 'DIMTM'
283
+ | 'DIMTXT'
284
+ | 'DIMCEN'
285
+ | 'DIMTSZ'
286
+ | 'DIMALTF'
287
+ | 'DIMLFAC'
288
+ | 'DIMTVP'
289
+ | 'DIMTFAC'
290
+ | 'DIMGAP'
291
+ | 'DIMALTRND'
292
+ | 'DIMTOL'
293
+ | 'DIMLIM'
294
+ | 'DIMTIH'
295
+ | 'DIMTOH'
296
+ | 'DIMSE1'
297
+ | 'DIMSE2'
298
+ | 'DIMTAD'
299
+ | 'DIMZIN'
300
+ | 'DIMAZIN'
301
+ | 'DIMALT'
302
+ | 'DIMALTD'
303
+ | 'DIMTOFL'
304
+ | 'DIMSAH'
305
+ | 'DIMTIX'
306
+ | 'DIMSOXD'
307
+ | 'DIMCLRD'
308
+ | 'DIMCLRE'
309
+ | 'DIMCLRT'
310
+ | 'DIMADEC'
311
+ | 'DIMUNIT'
312
+ | 'DIMDEC'
313
+ | 'DIMTDEC'
314
+ | 'DIMALTU'
315
+ | 'DIMALTTD'
316
+ | 'DIMAUNIT'
317
+ | 'DIMFRAC'
318
+ | 'DIMLUNIT'
319
+ | 'DIMDSEP'
320
+ | 'DIMTMOVE'
321
+ | 'DIMJUST'
322
+ | 'DIMSD1'
323
+ | 'DIMSD2'
324
+ | 'DIMTOLJ'
325
+ | 'DIMTZIN'
326
+ | 'DIMALTZ'
327
+ | 'DIMALTTZ'
328
+ | 'DIMFIT'
329
+ | 'DIMUPT'
330
+ | 'DIMATFIT'
331
+ | 'DIMTXSTY'
332
+ | 'DIMLDRBLK'
333
+ | 'DIMBLK'
334
+ | 'DIMBLK1'
335
+ | 'DIMBLK2'
336
+ | 'DIMLWD'
337
+ | 'DIMLWE';
338
+
339
+ interface DimStyleVariableSchema {
340
+ name: string;
341
+ code: number;
342
+ defaultValue?: string | number;
343
+ defaultValueImperial?: string | number;
344
+ }
345
+
346
+ type DimStylesTableEntry = {
347
+ subclassMarker: 'AcDbDimStyleTableRecord';
348
+ styleName: string;
349
+ DIMPOST?: string;
350
+ DIMAPOST?: string;
351
+ DIMBLK_OBSOLETE?: string;
352
+ DIMBLK1_OBSOLETE?: string;
353
+ DIMBLK2_OBSOLETE?: string;
354
+ DIMSCALE: number;
355
+ DIMASZ: number;
356
+ DIMEXO: number;
357
+ DIMDLI: number;
358
+ DIMEXE: number;
359
+ DIMRND: number;
360
+ DIMDLE: number;
361
+ DIMTP: number;
362
+ DIMTM: number;
363
+ DIMTXT: number;
364
+ DIMCEN: number;
365
+ DIMTSZ: number;
366
+ DIMALTF: number;
367
+ DIMLFAC: number;
368
+ DIMTVP: number;
369
+ DIMTFAC: number;
370
+ DIMGAP: number;
371
+ DIMALTRND: number;
372
+ DIMTOL: number;
373
+ DIMLIM: number;
374
+ DIMTIH: number;
375
+ DIMTOH: number;
376
+ DIMSE1: 0 | 1;
377
+ DIMSE2: 0 | 1;
378
+ DIMTAD: DimensionTextVertical;
379
+ DIMZIN: DimensionZeroSuppression;
380
+ DIMAZIN: DimensionZeroSuppressionAngular;
381
+ DIMALT: 0 | 1;
382
+ DIMALTD: number;
383
+ DIMTOFL: 0 | 1;
384
+ DIMSAH: 0 | 1;
385
+ DIMTIX: 0 | 1;
386
+ DIMSOXD: 0 | 1;
387
+ DIMCLRD: number;
388
+ DIMCLRE: number;
389
+ DIMCLRT: number;
390
+ DIMADEC?: number;
391
+ DIMUNIT?: number;
392
+ DIMDEC: number;
393
+ DIMTDEC: number;
394
+ DIMALTU: number;
395
+ DIMALTTD: number;
396
+ DIMAUNIT: number;
397
+ DIMFRAC: number;
398
+ DIMLUNIT: number;
399
+ DIMDSEP: string;
400
+ DIMTMOVE: undefined; // 미사용
401
+ DIMJUST: DimensionTextHorizontal;
402
+ DIMSD1: 0 | 1;
403
+ DIMSD2: 0 | 1;
404
+ DIMTOLJ: DimensionTextVertical;
405
+ DIMTZIN: DimensionZeroSuppression;
406
+ DIMALTZ: DimensionZeroSuppression;
407
+ DIMALTTZ: DimensionZeroSuppression;
408
+ DIMFIT?: number;
409
+ DIMUPT: number;
410
+ DIMATFIT: number;
411
+ DIMTXSTY?: string;
412
+ DIMLDRBLK?: string;
413
+ DIMBLK?: string;
414
+ DIMBLK1?: string;
415
+ DIMBLK2?: string;
416
+ DIMLWD: number;
417
+ DIMLWE: number;
418
+ } & CommonDxfTableEntry;
419
+
420
+ type StyleResolver = <Name extends DimStyleVariable>(
421
+ variableName: Name,
422
+ ) => DimStylesTableEntry[Name];
423
+ ```
424
+
425
+ #### STYLE
426
+
427
+ ```ts
428
+ interface StyleTableEntry extends CommonDxfTableEntry {
429
+ subclassMarker: 'AcDbTextStyleTableRecord';
430
+ name: string;
431
+ standardFlag: number;
432
+ fixedTextHeight: number;
433
+ widthFactor: number;
434
+ obliqueAngle: number;
435
+ textGenerationFlag: number;
436
+ lastHeight: number;
437
+ font: string;
438
+ bigFont: string;
439
+ extendedFont?: string;
440
+ }
441
+ ```
442
+
443
+ #### LAYER
444
+
445
+ ```ts
446
+ interface LayerTableEntry extends CommonDxfTableEntry {
447
+ subclassMarker: 'AcDbLayerTableRecord';
448
+ name: string;
449
+ standardFlag: number;
450
+ colorIndex: ColorIndex;
451
+ lineType: string;
452
+ isPlotting: boolean;
453
+ lineweight: number;
454
+ plotStyleNameObjectId?: string;
455
+ materialObjectId?: string;
456
+ }
457
+ ```
458
+
459
+ #### LTYPE
460
+
461
+ ```ts
462
+ interface LTypeTableEntry extends CommonDxfTableEntry {
463
+ subclassMarker: 'AcDbLinetypeTableRecord';
464
+ name: string;
465
+ standardFlag: number;
466
+ description: string;
467
+ numberOfLineTypes: number;
468
+ totalPatternLength: number;
469
+ pattern?: LineTypeElement[];
470
+ }
471
+ interface LineTypeElement {
472
+ elementLength: number;
473
+ elementTypeFlag: number;
474
+ shapeNumber?: number;
475
+ styleObjectId?: string;
476
+ scale?: number;
477
+ rotation?: number;
478
+ offsetX?: number;
479
+ offsetY?: number;
480
+ text?: string;
481
+ }
482
+ ```
483
+
484
+ #### VPORT
485
+
486
+ ```ts
487
+ interface VPortTableEntry extends CommonDxfTableEntry {
488
+ subclassMarker: 'AcDbViewportTableRecord';
489
+ name: string;
490
+ standardFlag: number;
491
+ lowerLeftCorner: Point2D;
492
+ upperRightCorner: Point2D;
493
+ center: Point2D;
494
+ snapBasePoint: Point2D;
495
+ snapSpacing: Point2D;
496
+ gridSpacing: Point2D;
497
+ viewDirectionFromTarget: Point3D;
498
+ viewTarget: Point3D;
499
+ lensLength: number;
500
+ frontClippingPlane: number;
501
+ backClippingPlane: number;
502
+ viewHeight: number;
503
+ snapRotationAngle: number;
504
+ viewTwistAngle: number;
505
+ circleSides: number;
506
+ frozenLayers: string[];
507
+ styleSheet: string;
508
+ renderMode: RenderMode;
509
+ viewMode: number;
510
+ ucsIconSetting: number;
511
+ ucsOrigin: Point3D;
512
+ ucsXAxis: Point3D;
513
+ ucsYAxis: Point3D;
514
+ orthographicType: OrthographicType;
515
+ elevation: number;
516
+ shadePlotSetting: number;
517
+ majorGridLines: number;
518
+ backgroundObjectId?: string;
519
+ shadePlotObjectId?: string;
520
+ visualStyleObjectId?: string;
521
+ isDefaultLightingOn: boolean;
522
+ defaultLightingType: DefaultLightingType;
523
+ brightness: number;
524
+ contrast: number;
525
+ ambientColor?: number;
526
+ }
527
+ ```
528
+
529
+ ### objects
530
+
531
+ ```ts
532
+ objects: {
533
+ byName: Record<string, CommonDXFObject[]>;
534
+ byTree?: DxfObject;
535
+ };
536
+ ```
537
+
538
+ #### byName
539
+
540
+ CommonDXFObject:
541
+
542
+ ```ts
543
+ interface CommonDXFObject {
544
+ ownerObjectId: string;
545
+ ownerDictionaryIdHard: string;
546
+ ownerDictionaryIdSoft: string;
547
+ handle: string;
548
+ }
549
+ ```
550
+
551
+ #### DxfObject
552
+
553
+ ```ts
554
+ interface DxfObject {
555
+ name: string;
556
+ handle: string;
557
+ ownerDictionaryIdSoft: string;
558
+ ownerDictionaryIdHard?: string;
559
+ ownerObjectId?: string;
560
+ }
561
+ ```
562
+
563
+ Please refer to the dxf reference for undefined elements and leave them as issues!
564
+
565
+ ## License
566
+
567
+ GPL-3.0 license
package/jest.config.js ADDED
@@ -0,0 +1,20 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
2
+ export default {
3
+ preset: 'ts-jest/presets/js-with-ts-esm',
4
+ extensionsToTreatAsEsm: ['.ts', '.tsx'],
5
+ moduleNameMapper: {
6
+ '^(\\.{1,2}/.*)\\.js$': '$1',
7
+ '^@src/(.*)$': '<rootDir>/src/$1',
8
+ },
9
+ transform: {
10
+ '^.+\\.[tj]sx?$': [
11
+ 'ts-jest',
12
+ {
13
+ useESM: true,
14
+ isolatedModules: true,
15
+ },
16
+ ],
17
+ },
18
+ testEnvironment: 'node',
19
+ transformIgnorePatterns: [],
20
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "dxf-json",
3
+ "version": "0.0.1",
4
+ "description": "perfect dxf parser",
5
+ "main": "./src/index.ts",
6
+ "type": "module",
7
+ "scripts": {
8
+ "build": "tsc && webpack --mode production",
9
+ "test:parser": "jest --silent=false"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/kimkanghyune/dxf-json.git"
14
+ },
15
+ "keywords": [
16
+ "dxf",
17
+ "cad",
18
+ "dxf-json",
19
+ "json",
20
+ "type-safe-dxf",
21
+ "type-safe",
22
+ "typescript"
23
+ ],
24
+ "author": {
25
+ "name": "kanghyune kim",
26
+ "email": "wwponv158@gmail.com"
27
+ },
28
+ "publishConfig": {
29
+ "registry": "https://registry.npmjs.org/"
30
+ },
31
+ "license": "GPL-3.0",
32
+ "bugs": {
33
+ "url": "https://github.com/kimkanghyune/dxf-json/issues",
34
+ "email": "wwponv158@gmail.com"
35
+ },
36
+ "homepage": "https://github.com/kimkanghyune/dxf-json#readme",
37
+ "dependencies": {
38
+ "@fxts/core": "^0.23.0",
39
+ "@swc/cli": "^0.1.63",
40
+ "@swc/core": "^1.3.104",
41
+ "readable-stream": "^4.5.2",
42
+ "swc-loader": "^0.2.3",
43
+ "three": "^0.160.0",
44
+ "webpack": "^5.89.0",
45
+ "webpack-cli": "^5.1.4",
46
+ "webpack-dev-server": "^4.15.1"
47
+ },
48
+ "devDependencies": {
49
+ "@types/jest": "^29.5.11",
50
+ "@types/readable-stream": "^4.0.10",
51
+ "@types/three": "^0.160.0",
52
+ "jest": "^29.7.0",
53
+ "ts-jest": "^29.1.1",
54
+ "typescript": "^5.3.3"
55
+ }
56
+ }
@@ -0,0 +1,22 @@
1
+ export enum BlockTypeFlag {
2
+ None = 0,
3
+
4
+ // anonymous block generated by hatching, associative dimensioning,
5
+ // other internal operations, or an application
6
+ Anonymous = 1,
7
+
8
+ // this bit is not set if the block has any attribute definitions that
9
+ // are constant, or has no attribute definitions at all
10
+ NonConstant = 2,
11
+
12
+ // external referenced
13
+ Xref = 4,
14
+ XrefOverlay = 8,
15
+ ExternallyDependent = 16,
16
+
17
+ // resolved external reference, or dependent of an external reference
18
+ ResolvedOrDependent = 32,
19
+
20
+ // referenced external reference
21
+ ReferencedXref = 64,
22
+ }
@@ -0,0 +1,6 @@
1
+ export enum ColorCode {
2
+ BYBLOCK = 0,
3
+ BYLAYER = 256,
4
+ }
5
+
6
+ export const UndeterminedBlockColor = -1;
@@ -0,0 +1,2 @@
1
+ export const SPLINE_SUBDIVISION = 4;
2
+ export const TESSELLATION_ANGLE = Math.PI / 24;