@cadview/core 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Wisnu Wicaksono
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # @cadview/core
2
+
3
+ Framework-agnostic CAD file viewer engine with DXF parser and Canvas 2D renderer.
4
+
5
+ ## Features
6
+
7
+ - Fast DXF parser with support for 13 entity types (LINE, CIRCLE, ARC, LWPOLYLINE, POLYLINE, ELLIPSE, SPLINE, TEXT, MTEXT, INSERT, DIMENSION, HATCH, POINT)
8
+ - Canvas 2D renderer with DPR-aware rendering and dark/light themes
9
+ - Interactive viewer with pan, zoom (mouse wheel + pinch), and pointer capture
10
+ - Entity selection with spatial indexing (R-tree) and geometric hit-testing
11
+ - Measurement tool with snap-to-geometry (endpoint, midpoint, center)
12
+ - Layer management with visibility toggle and color overrides
13
+ - ACI color table (256 colors) with theme-aware color 7 swap
14
+ - Block INSERT rendering with nested block support
15
+ - Zero framework dependencies — works with any UI framework or vanilla JS
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @cadview/core
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ```ts
26
+ import { CadViewer } from '@cadview/core';
27
+
28
+ const canvas = document.getElementById('canvas') as HTMLCanvasElement;
29
+ const viewer = new CadViewer(canvas, { theme: 'dark' });
30
+
31
+ // Load a DXF file
32
+ const response = await fetch('/drawing.dxf');
33
+ const buffer = await response.arrayBuffer();
34
+ viewer.loadArrayBuffer(buffer);
35
+
36
+ // Or load from File input
37
+ const file = input.files[0];
38
+ await viewer.loadFile(file);
39
+
40
+ // Controls
41
+ viewer.fitToView();
42
+ viewer.setTheme('light');
43
+ viewer.setTool('select'); // 'pan' | 'select' | 'measure'
44
+
45
+ // Events
46
+ viewer.on('select', (e) => {
47
+ console.log('Selected:', e.entity.type, 'on layer:', e.entity.layer);
48
+ });
49
+
50
+ viewer.on('measure', (e) => {
51
+ console.log('Distance:', e.distance);
52
+ });
53
+
54
+ // Cleanup
55
+ viewer.destroy();
56
+ ```
57
+
58
+ ## API
59
+
60
+ ### `CadViewer`
61
+
62
+ Main viewer class that orchestrates parsing, rendering, and interaction.
63
+
64
+ #### Constructor
65
+
66
+ ```ts
67
+ new CadViewer(canvas: HTMLCanvasElement, options?: CadViewerOptions)
68
+ ```
69
+
70
+ #### Options
71
+
72
+ | Option | Type | Default | Description |
73
+ |--------|------|---------|-------------|
74
+ | `theme` | `'dark' \| 'light'` | `'dark'` | Color theme |
75
+ | `minZoom` | `number` | `0.0001` | Minimum zoom scale |
76
+ | `maxZoom` | `number` | `100000` | Maximum zoom scale |
77
+ | `zoomSpeed` | `number` | `1.1` | Zoom factor per wheel tick |
78
+ | `initialTool` | `Tool` | `'pan'` | Active tool on init |
79
+
80
+ #### Methods
81
+
82
+ | Method | Description |
83
+ |--------|-------------|
84
+ | `loadFile(file: File)` | Load DXF from a File object |
85
+ | `loadString(dxf: string)` | Load DXF from a string |
86
+ | `loadArrayBuffer(buffer: ArrayBuffer)` | Load DXF from an ArrayBuffer |
87
+ | `fitToView()` | Fit drawing to canvas bounds |
88
+ | `setTheme(theme)` | Set color theme |
89
+ | `setTool(tool)` | Set active tool (`pan`, `select`, `measure`) |
90
+ | `getLayers()` | Get all layers |
91
+ | `setLayerVisible(name, visible)` | Toggle layer visibility |
92
+ | `on(event, callback)` | Subscribe to events |
93
+ | `off(event, callback)` | Unsubscribe from events |
94
+ | `destroy()` | Clean up all resources |
95
+
96
+ ### `parseDxf`
97
+
98
+ Standalone DXF parser — use this if you only need parsing without the viewer.
99
+
100
+ ```ts
101
+ import { parseDxf } from '@cadview/core';
102
+
103
+ const doc = parseDxf(dxfString);
104
+ console.log(doc.entities.length, 'entities');
105
+ console.log(doc.layers.size, 'layers');
106
+ ```
107
+
108
+ ## Supported DXF Entities
109
+
110
+ LINE, CIRCLE, ARC, LWPOLYLINE, POLYLINE, ELLIPSE, SPLINE, TEXT, MTEXT, INSERT (with MINSERT grid), DIMENSION (with geometry blocks), HATCH (line/arc/circle edges), POINT.
111
+
112
+ ## License
113
+
114
+ MIT