ofs-dxf-ts 1.0.0
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/API.md +411 -0
- package/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/README.md +119 -0
- package/dist/core/dxf-builder.d.ts +348 -0
- package/dist/core/dxf-builder.js +549 -0
- package/dist/core/dxf-document.d.ts +220 -0
- package/dist/core/dxf-document.js +529 -0
- package/dist/core/dxf-entities.d.ts +327 -0
- package/dist/core/dxf-entities.js +22 -0
- package/dist/core/dxf-serializer.d.ts +48 -0
- package/dist/core/dxf-serializer.js +595 -0
- package/dist/core/hatch-patterns.d.ts +15 -0
- package/dist/core/hatch-patterns.js +214 -0
- package/dist/core/modelspace.d.ts +106 -0
- package/dist/core/modelspace.js +351 -0
- package/dist/geometry/math.utils.d.ts +8 -0
- package/dist/geometry/math.utils.js +43 -0
- package/dist/geometry/offset.utils.d.ts +32 -0
- package/dist/geometry/offset.utils.js +87 -0
- package/dist/geometry/polyline.utils.d.ts +10 -0
- package/dist/geometry/polyline.utils.js +63 -0
- package/dist/geometry/text.utils.d.ts +15 -0
- package/dist/geometry/text.utils.js +28 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +29 -0
- package/dist/parser/auto-cad-color-index.d.ts +8 -0
- package/dist/parser/auto-cad-color-index.js +265 -0
- package/dist/parser/dim-style-codes.d.ts +5 -0
- package/dist/parser/dim-style-codes.js +32 -0
- package/dist/parser/dxf-parser.d.ts +16 -0
- package/dist/parser/dxf-parser.js +824 -0
- package/dist/parser/entities/3dface.d.ts +5 -0
- package/dist/parser/entities/3dface.js +76 -0
- package/dist/parser/entities/arc.d.ts +5 -0
- package/dist/parser/entities/arc.js +34 -0
- package/dist/parser/entities/attdef.d.ts +5 -0
- package/dist/parser/entities/attdef.js +86 -0
- package/dist/parser/entities/attribute.d.ts +5 -0
- package/dist/parser/entities/attribute.js +106 -0
- package/dist/parser/entities/circle.d.ts +5 -0
- package/dist/parser/entities/circle.js +40 -0
- package/dist/parser/entities/dimension.d.ts +5 -0
- package/dist/parser/entities/dimension.js +65 -0
- package/dist/parser/entities/ellipse.d.ts +5 -0
- package/dist/parser/entities/ellipse.js +42 -0
- package/dist/parser/entities/hatch.d.ts +5 -0
- package/dist/parser/entities/hatch.js +321 -0
- package/dist/parser/entities/insert.d.ts +5 -0
- package/dist/parser/entities/insert.js +52 -0
- package/dist/parser/entities/line.d.ts +5 -0
- package/dist/parser/entities/line.js +30 -0
- package/dist/parser/entities/lwpolyline.d.ts +5 -0
- package/dist/parser/entities/lwpolyline.js +101 -0
- package/dist/parser/entities/mtext.d.ts +5 -0
- package/dist/parser/entities/mtext.js +54 -0
- package/dist/parser/entities/point.d.ts +5 -0
- package/dist/parser/entities/point.js +30 -0
- package/dist/parser/entities/polyline.d.ts +5 -0
- package/dist/parser/entities/polyline.js +85 -0
- package/dist/parser/entities/solid.d.ts +5 -0
- package/dist/parser/entities/solid.js +35 -0
- package/dist/parser/entities/spline.d.ts +5 -0
- package/dist/parser/entities/spline.js +69 -0
- package/dist/parser/entities/text.d.ts +5 -0
- package/dist/parser/entities/text.js +47 -0
- package/dist/parser/entities/vertex.d.ts +5 -0
- package/dist/parser/entities/vertex.js +59 -0
- package/dist/parser/extended-data-parser.d.ts +18 -0
- package/dist/parser/extended-data-parser.js +100 -0
- package/dist/parser/index.d.ts +10 -0
- package/dist/parser/index.js +9 -0
- package/dist/parser/log.d.ts +14 -0
- package/dist/parser/log.js +39 -0
- package/dist/parser/parse-helpers.d.ts +23 -0
- package/dist/parser/parse-helpers.js +128 -0
- package/dist/parser/scanner.d.ts +29 -0
- package/dist/parser/scanner.js +143 -0
- package/dist/parser/types.d.ts +78 -0
- package/dist/parser/types.js +5 -0
- package/dist/symbols/slope-symbol.d.ts +21 -0
- package/dist/symbols/slope-symbol.js +81 -0
- package/dist/symbols/structures.d.ts +9 -0
- package/dist/symbols/structures.js +120 -0
- package/dist/template/blank-document.d.ts +13 -0
- package/dist/template/blank-document.js +13 -0
- package/dist/template/block-registry.d.ts +16 -0
- package/dist/template/block-registry.js +135 -0
- package/dist/template/index.d.ts +17 -0
- package/dist/template/index.js +17 -0
- package/dist/template/template-injector.d.ts +45 -0
- package/dist/template/template-injector.js +487 -0
- package/dist/template/template-reader.d.ts +28 -0
- package/dist/template/template-reader.js +80 -0
- package/dist/types/index.d.ts +24 -0
- package/dist/types/index.js +8 -0
- package/package.json +59 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
export const BLOCK_REGISTRY = {
|
|
2
|
+
'KM100': {
|
|
3
|
+
name: 'KM100',
|
|
4
|
+
entities: [{ type: 'CIRCLE', center: [0, 0], radius: 1.0, color: 7 }]
|
|
5
|
+
},
|
|
6
|
+
'KM500': {
|
|
7
|
+
name: 'KM500',
|
|
8
|
+
entities: [{ type: 'CIRCLE', center: [0, 0], radius: 1.5, color: 4 }]
|
|
9
|
+
},
|
|
10
|
+
'KM1000': {
|
|
11
|
+
name: 'KM1000',
|
|
12
|
+
entities: [
|
|
13
|
+
{ type: 'CIRCLE', center: [0, 0.15], radius: 0.75, color: 4 },
|
|
14
|
+
{ type: 'CIRCLE', center: [0, 0.15], radius: 1.75, color: 4 }
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
'1NFT': {
|
|
18
|
+
name: '1NFT',
|
|
19
|
+
entities: [
|
|
20
|
+
{ type: 'LINE', points: [[3.55, 0], [0, 0]], color: 7 },
|
|
21
|
+
{ type: 'CIRCLE', center: [0, 0.04], radius: 1.74, color: 7 },
|
|
22
|
+
{ type: 'LINE', points: [[0, -1.7], [0, 1.7]], color: 7 }
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
'1HCD': {
|
|
26
|
+
name: '1HCD',
|
|
27
|
+
entities: [
|
|
28
|
+
{ type: 'LINE', points: [[3.35, -1.18], [-3.34, -1.18]], color: 7 },
|
|
29
|
+
{ type: 'LINE', points: [[-3.34, 1.18], [3.35, 1.18]], color: 7 },
|
|
30
|
+
{ type: 'LINE', points: [[-3.34, -1.18], [-3.34, 1.18]], color: 7 },
|
|
31
|
+
{ type: 'LINE', points: [[3.35, -1.18], [3.35, 1.18]], color: 7 },
|
|
32
|
+
{ type: 'LINE', points: [[-3.34, 1.18], [-4.49, 2.15]], color: 7 },
|
|
33
|
+
{ type: 'LINE', points: [[-4.49, -2.15], [-3.34, -1.18]], color: 7 },
|
|
34
|
+
{ type: 'LINE', points: [[3.35, -1.18], [4.5, -2.15]], color: 7 },
|
|
35
|
+
{ type: 'LINE', points: [[3.35, 1.18], [4.5, 2.15]], color: 7 }
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
'END': {
|
|
39
|
+
name: 'END',
|
|
40
|
+
entities: [
|
|
41
|
+
{ type: 'CIRCLE', center: [0, 0], radius: 4.0, color: 7 },
|
|
42
|
+
{ type: 'LWPOLYLINE', points: [[0, 4], [0, 12]], color: 7 },
|
|
43
|
+
{ type: 'LWPOLYLINE', points: [[0, -4], [0, -12]], color: 7 },
|
|
44
|
+
{ type: 'LWPOLYLINE', points: [[0, -12], [6, -12]], color: 7 },
|
|
45
|
+
{ type: 'LWPOLYLINE', points: [[0, 12], [6, 12]], color: 7 }
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
'1FI': {
|
|
49
|
+
name: '1FI',
|
|
50
|
+
entities: [
|
|
51
|
+
{ type: 'CIRCLE', center: [1.0, 0], radius: 0.5, layer: 'STR_CYAN' },
|
|
52
|
+
{ type: 'LINE', points: [[2.97, 0.75], [2.97, -0.75]], layer: 'STR_CYAN' },
|
|
53
|
+
{ type: 'LWPOLYLINE', points: [[2.97, 0.75], [6.97, 0], [2.97, -0.75], [2.97, 0.75]], layer: 'STR_CYAN' }
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
'1FIS': {
|
|
57
|
+
name: '1FIS',
|
|
58
|
+
entities: [
|
|
59
|
+
{ type: 'CIRCLE', center: [1.0, 0], radius: 0.5, layer: 'STR_CYAN' },
|
|
60
|
+
{ type: 'CIRCLE', center: [3.0, 0], radius: 0.5, layer: 'STR_CYAN' },
|
|
61
|
+
{ type: 'LWPOLYLINE', points: [[4.97, 0.75], [8.97, 0], [4.97, -0.75], [4.97, 0.75]], layer: 'STR_CYAN' }
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
'1FID': {
|
|
65
|
+
name: '1FID',
|
|
66
|
+
entities: [
|
|
67
|
+
{ type: 'CIRCLE', center: [1.0, 0], radius: 0.5, layer: 'STR_CYAN' },
|
|
68
|
+
{ type: 'CIRCLE', center: [3.0, 0], radius: 0.5, layer: 'STR_CYAN' },
|
|
69
|
+
{ type: 'LWPOLYLINE', points: [[4.97, 0.75], [8.97, 0], [4.97, -0.75], [4.97, 0.75]], layer: 'STR_CYAN' }
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
'1FIU': {
|
|
73
|
+
name: '1FIU',
|
|
74
|
+
entities: [
|
|
75
|
+
{ type: 'CIRCLE', center: [1.0, 0], radius: 0.5, layer: 'STR_CYAN' },
|
|
76
|
+
{ type: 'CIRCLE', center: [2.9, 0], radius: 0.5, layer: 'STR_CYAN' },
|
|
77
|
+
{ type: 'LWPOLYLINE', points: [[4.9, 0.76], [8.9, 0], [4.9, -0.73], [4.9, 0.76]], layer: 'STR_CYAN' }
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
'1FIUD': {
|
|
81
|
+
name: '1FIUD',
|
|
82
|
+
entities: [
|
|
83
|
+
{ type: 'CIRCLE', center: [1.1, 0.1], radius: 0.5, layer: 'STR_CYAN' },
|
|
84
|
+
{ type: 'CIRCLE', center: [3.1, 0.1], radius: 0.5, layer: 'STR_CYAN' },
|
|
85
|
+
{ type: 'LWPOLYLINE', points: [[5.1, 0.95], [9.1, 0.2], [5.1, -0.54], [5.1, 0.95]], layer: 'STR_CYAN' }
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
'1FT': {
|
|
89
|
+
name: '1FT',
|
|
90
|
+
entities: [
|
|
91
|
+
{ type: 'CIRCLE', center: [0, 0], radius: 1.74, layer: 'STR_CYAN' },
|
|
92
|
+
{ type: 'LINE', points: [[0, -1.74], [0, 1.74]], layer: 'STR_CYAN' },
|
|
93
|
+
{ type: 'LINE', points: [[0, 0], [3.55, 0]], layer: 'STR_CYAN' }
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
'1DT': {
|
|
97
|
+
name: '1DT',
|
|
98
|
+
entities: [
|
|
99
|
+
{ type: 'CIRCLE', center: [1.5, 0], radius: 1.5, layer: 'STR_CYAN' },
|
|
100
|
+
{ type: 'LWPOLYLINE', points: [[4, 0.76], [8, 0], [4, -0.74], [4, 0.76]], layer: 'STR_CYAN' }
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
'1DC': {
|
|
104
|
+
name: '1DC',
|
|
105
|
+
entities: [
|
|
106
|
+
{ type: 'CIRCLE', center: [0, 0], radius: 1.5, color: 7 },
|
|
107
|
+
{ type: 'LWPOLYLINE', points: [[-2.1, -2.1], [-1.56, -1.6], [-1.56, 1.53], [-2.1, 2.06]], color: 7 },
|
|
108
|
+
{ type: 'LWPOLYLINE', points: [[2.1, -2.1], [1.56, -1.6], [1.56, 1.53], [2.1, 2.06]], color: 7 }
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
'm23_titlebox': {
|
|
112
|
+
name: 'm23_titlebox',
|
|
113
|
+
entities: [
|
|
114
|
+
// Standard 80x40 title box
|
|
115
|
+
{ type: 'LWPOLYLINE', points: [[0, 0], [80, 0], [80, 40], [0, 40], [0, 0]], color: 6 },
|
|
116
|
+
{ type: 'LINE', points: [[0, 20], [80, 20]], color: 6 },
|
|
117
|
+
{ type: 'LINE', points: [[0, 12], [80, 12]], color: 6 },
|
|
118
|
+
// Vertical dividers (based on extraction ratio)
|
|
119
|
+
{ type: 'LINE', points: [[10.3, 20], [10.3, 12]], color: 6 },
|
|
120
|
+
{ type: 'LINE', points: [[20.6, 20], [20.6, 12]], color: 6 },
|
|
121
|
+
{ type: 'LINE', points: [[31, 20], [31, 12]], color: 6 },
|
|
122
|
+
{ type: 'LINE', points: [[41.3, 20], [41.3, 12]], color: 6 },
|
|
123
|
+
{ type: 'LINE', points: [[51.6, 20], [51.6, 12]], color: 6 }
|
|
124
|
+
]
|
|
125
|
+
},
|
|
126
|
+
'frame': {
|
|
127
|
+
name: 'frame',
|
|
128
|
+
entities: [
|
|
129
|
+
// Standard A1 sheet (scaled to 791 x 554 units)
|
|
130
|
+
{ type: 'LWPOLYLINE', points: [[0, 0], [791, 0], [791, 554], [0, 554], [0, 0]], color: 6 },
|
|
131
|
+
// Inner margin (approx 10 units in)
|
|
132
|
+
{ type: 'LWPOLYLINE', points: [[10, 10], [781, 10], [781, 544], [10, 544], [10, 10]], color: 6 }
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template module — DXF template handling.
|
|
3
|
+
*
|
|
4
|
+
* Loading a `.dxf` template, preserving its layers/blocks/styles, and injecting
|
|
5
|
+
* new entities into it is a first-class concern of this library.
|
|
6
|
+
*
|
|
7
|
+
* - `template-reader` — parse a template string → structured TemplateData.
|
|
8
|
+
* - `template-injector` — emit a DXF by injecting new entities/layers into the
|
|
9
|
+
* template's verbatim sections.
|
|
10
|
+
* - `block-registry` — built-in parametric block definitions.
|
|
11
|
+
*
|
|
12
|
+
* `DxfDocument` uses the reader in `fromString()` and the injector in
|
|
13
|
+
* `toDxfString()` (template mode).
|
|
14
|
+
*/
|
|
15
|
+
export * from './template-reader.js';
|
|
16
|
+
export * from './template-injector.js';
|
|
17
|
+
export * from './block-registry.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template module — DXF template handling.
|
|
3
|
+
*
|
|
4
|
+
* Loading a `.dxf` template, preserving its layers/blocks/styles, and injecting
|
|
5
|
+
* new entities into it is a first-class concern of this library.
|
|
6
|
+
*
|
|
7
|
+
* - `template-reader` — parse a template string → structured TemplateData.
|
|
8
|
+
* - `template-injector` — emit a DXF by injecting new entities/layers into the
|
|
9
|
+
* template's verbatim sections.
|
|
10
|
+
* - `block-registry` — built-in parametric block definitions.
|
|
11
|
+
*
|
|
12
|
+
* `DxfDocument` uses the reader in `fromString()` and the injector in
|
|
13
|
+
* `toDxfString()` (template mode).
|
|
14
|
+
*/
|
|
15
|
+
export * from './template-reader.js';
|
|
16
|
+
export * from './template-injector.js';
|
|
17
|
+
export * from './block-registry.js';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template injector — emit a DXF by injecting new content into the verbatim
|
|
3
|
+
* sections of a base document: a user template, or the built-in blank R2018
|
|
4
|
+
* document for drawings created from scratch.
|
|
5
|
+
*
|
|
6
|
+
* Every section of the base is preserved (CLASSES, ACDSDATA, … included); we:
|
|
7
|
+
* - allocate new handles above $HANDSEED and write the new $HANDSEED,
|
|
8
|
+
* - set or replace HEADER variables,
|
|
9
|
+
* - add LTYPE / LAYER / STYLE / BLOCK_RECORD records (existing names are kept),
|
|
10
|
+
* - add block definitions and paper space layout blocks to BLOCKS,
|
|
11
|
+
* - append model space and active-layout entities to ENTITIES,
|
|
12
|
+
* - add LAYOUT / IMAGEDEF / reactor objects and their dictionary entries.
|
|
13
|
+
*
|
|
14
|
+
* Only the TABLES, OBJECTS and CLASSES sections are tag-scanned; BLOCKS and
|
|
15
|
+
* ENTITIES (usually the bulk of a template) are edited by string position.
|
|
16
|
+
*/
|
|
17
|
+
import { BlockDef, DxfEntity, LayerDef, LayoutDef, LinetypeDef, TextStyleDef } from '../core/dxf-entities.js';
|
|
18
|
+
type HeaderValue = {
|
|
19
|
+
code: number;
|
|
20
|
+
value: string;
|
|
21
|
+
};
|
|
22
|
+
/** Everything that goes into one DXF output. */
|
|
23
|
+
export interface DocumentContent {
|
|
24
|
+
/** Verbatim sections of the base document (see template-reader). */
|
|
25
|
+
rawSections: Map<string, string>;
|
|
26
|
+
modelspace: DxfEntity[];
|
|
27
|
+
layers?: LayerDef[];
|
|
28
|
+
linetypes?: LinetypeDef[];
|
|
29
|
+
styles?: TextStyleDef[];
|
|
30
|
+
blocks?: BlockDef[];
|
|
31
|
+
/** Paper space layouts to create. */
|
|
32
|
+
layouts?: LayoutDef[];
|
|
33
|
+
/** Layout name → entities for that layout (base-document or new layouts). */
|
|
34
|
+
paperspace?: Map<string, DxfEntity[]>;
|
|
35
|
+
headerVars?: Map<string, HeaderValue[]>;
|
|
36
|
+
}
|
|
37
|
+
/** Names of the layouts (tabs) defined in a base document, including "Model". */
|
|
38
|
+
export declare function listLayoutNames(rawSections: Map<string, string>): string[];
|
|
39
|
+
export declare function serializeDocument(doc: DocumentContent): string;
|
|
40
|
+
/**
|
|
41
|
+
* Inject entities and layers into a template.
|
|
42
|
+
* @deprecated Use `serializeDocument`, which also handles blocks, images and layouts.
|
|
43
|
+
*/
|
|
44
|
+
export declare function serializeWithTemplate(rawSections: Map<string, string>, newEntities: DxfEntity[], newLayers: LayerDef[], headerVars?: Map<string, HeaderValue[]>): string;
|
|
45
|
+
export {};
|