@cadview/core 0.1.0 → 0.3.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/README.md +36 -3
- package/dist/index.cjs +422 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +133 -3
- package/dist/index.d.ts +133 -3
- package/dist/index.js +422 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -76,14 +76,18 @@ new CadViewer(canvas: HTMLCanvasElement, options?: CadViewerOptions)
|
|
|
76
76
|
| `maxZoom` | `number` | `100000` | Maximum zoom scale |
|
|
77
77
|
| `zoomSpeed` | `number` | `1.1` | Zoom factor per wheel tick |
|
|
78
78
|
| `initialTool` | `Tool` | `'pan'` | Active tool on init |
|
|
79
|
+
| `formatConverters` | `FormatConverter[]` | `[]` | Format converters for non-DXF files (e.g. DWG) |
|
|
79
80
|
|
|
80
81
|
#### Methods
|
|
81
82
|
|
|
82
83
|
| Method | Description |
|
|
83
84
|
|--------|-------------|
|
|
84
|
-
| `loadFile(file: File)` | Load
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
85
|
+
| `loadFile(file: File)` | Load from a File object (async, runs format converters) |
|
|
86
|
+
| `loadBuffer(buffer: ArrayBuffer)` | Load from an ArrayBuffer (async, runs format converters) |
|
|
87
|
+
| `loadString(dxf: string)` | Load DXF from a string (sync, no conversion) |
|
|
88
|
+
| `loadArrayBuffer(buffer: ArrayBuffer)` | Load DXF from an ArrayBuffer (sync, no conversion) |
|
|
89
|
+
| `loadDocument(doc: DxfDocument)` | Load a pre-parsed DxfDocument directly |
|
|
90
|
+
| `clearDocument()` | Clear the current document without destroying the viewer |
|
|
87
91
|
| `fitToView()` | Fit drawing to canvas bounds |
|
|
88
92
|
| `setTheme(theme)` | Set color theme |
|
|
89
93
|
| `setTool(tool)` | Set active tool (`pan`, `select`, `measure`) |
|
|
@@ -93,6 +97,35 @@ new CadViewer(canvas: HTMLCanvasElement, options?: CadViewerOptions)
|
|
|
93
97
|
| `off(event, callback)` | Unsubscribe from events |
|
|
94
98
|
| `destroy()` | Clean up all resources |
|
|
95
99
|
|
|
100
|
+
### `FormatConverter`
|
|
101
|
+
|
|
102
|
+
Interface for registering custom file format converters. Converters are checked in order during `loadFile()` and `loadBuffer()` — the first match wins.
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
interface FormatConverter {
|
|
106
|
+
/** Return true if the buffer is in this format (check magic bytes, not extensions). */
|
|
107
|
+
detect(buffer: ArrayBuffer): boolean;
|
|
108
|
+
/** Convert the buffer to a DXF string. */
|
|
109
|
+
convert(buffer: ArrayBuffer): Promise<string>;
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Example — DWG support via `@cadview/dwg`:**
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { CadViewer } from '@cadview/core';
|
|
117
|
+
import { dwgConverter } from '@cadview/dwg';
|
|
118
|
+
|
|
119
|
+
const viewer = new CadViewer(canvas, {
|
|
120
|
+
formatConverters: [dwgConverter],
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// loadFile and loadBuffer now handle both DXF and DWG
|
|
124
|
+
await viewer.loadFile(file);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
> **Note:** `@cadview/dwg` is licensed under GPL-3.0 (due to LibreDWG). `@cadview/core` remains MIT. See the [@cadview/dwg README](../dwg/README.md) for details.
|
|
128
|
+
|
|
96
129
|
### `parseDxf`
|
|
97
130
|
|
|
98
131
|
Standalone DXF parser — use this if you only need parsing without the viewer.
|