@cadview/svelte 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,50 @@
1
+ # @cadview/svelte
2
+
3
+ Svelte 5 wrapper for `@cadview/core` — a CAD/DXF file viewer.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @cadview/core @cadview/svelte
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```svelte
14
+ <script>
15
+ import { CadViewer } from '@cadview/svelte';
16
+
17
+ let file = $state(null);
18
+ </script>
19
+
20
+ <input type="file" accept=".dxf" onchange={(e) => file = e.target.files?.[0]} />
21
+
22
+ <div style="width: 100%; height: 100vh;">
23
+ <CadViewer
24
+ {file}
25
+ theme="dark"
26
+ tool="pan"
27
+ onselect={(e) => console.log('Selected:', e.entity.type)}
28
+ onmeasure={(e) => console.log('Distance:', e.distance)}
29
+ />
30
+ </div>
31
+ ```
32
+
33
+ ## Props
34
+
35
+ | Prop | Type | Default | Description |
36
+ |------|------|---------|-------------|
37
+ | `file` | `File \| null` | — | DXF file to load |
38
+ | `theme` | `'dark' \| 'light'` | `'dark'` | Color theme |
39
+ | `tool` | `'pan' \| 'select' \| 'measure'` | `'pan'` | Active tool |
40
+ | `options` | `CadViewerOptions` | — | Additional viewer options |
41
+ | `onselect` | `(e: SelectEvent) => void` | — | Selection callback |
42
+ | `onmeasure` | `(e: MeasureEvent) => void` | — | Measurement callback |
43
+ | `onviewchange` | `(vt: ViewTransform) => void` | — | View change callback |
44
+ | `onlayersloaded` | `(layers: DxfLayer[]) => void` | — | Layers loaded callback |
45
+
46
+ Requires Svelte 5 (runes mode).
47
+
48
+ ## License
49
+
50
+ MIT
@@ -0,0 +1,136 @@
1
+ <script lang="ts">
2
+ import { untrack } from 'svelte';
3
+ import {
4
+ CadViewer as CoreCadViewer,
5
+ type CadViewerOptions,
6
+ type DxfLayer,
7
+ type SelectEvent,
8
+ type MeasureEvent,
9
+ type ViewTransform,
10
+ type Tool,
11
+ type Theme,
12
+ } from '@cadview/core';
13
+
14
+ interface Props {
15
+ file?: File | ArrayBuffer | string | null;
16
+ theme?: Theme;
17
+ tool?: Tool;
18
+ options?: Omit<CadViewerOptions, 'theme' | 'initialTool'>;
19
+ class?: string;
20
+ onselect?: (event: SelectEvent) => void;
21
+ onmeasure?: (event: MeasureEvent) => void;
22
+ onviewchange?: (transform: ViewTransform) => void;
23
+ onlayersloaded?: (layers: DxfLayer[]) => void;
24
+ }
25
+
26
+ let {
27
+ file = null,
28
+ theme = 'dark',
29
+ tool = 'pan',
30
+ options = {},
31
+ class: className = '',
32
+ onselect,
33
+ onmeasure,
34
+ onviewchange,
35
+ onlayersloaded,
36
+ }: Props = $props();
37
+
38
+ let canvas: HTMLCanvasElement;
39
+ let viewer: CoreCadViewer | null = $state(null);
40
+
41
+ // Initialize viewer — untrack reactive reads to prevent re-creation
42
+ $effect(() => {
43
+ if (!canvas) return;
44
+
45
+ const initialTheme = untrack(() => theme);
46
+ const initialTool = untrack(() => tool);
47
+ const initialOptions = untrack(() => options);
48
+
49
+ const v = new CoreCadViewer(canvas, {
50
+ theme: initialTheme,
51
+ initialTool: initialTool,
52
+ ...initialOptions,
53
+ });
54
+ viewer = v;
55
+
56
+ return () => {
57
+ v.destroy();
58
+ viewer = null;
59
+ };
60
+ });
61
+
62
+ // React to theme changes
63
+ $effect(() => {
64
+ viewer?.setTheme(theme);
65
+ });
66
+
67
+ // React to tool changes
68
+ $effect(() => {
69
+ viewer?.setTool(tool);
70
+ });
71
+
72
+ // React to file changes
73
+ $effect(() => {
74
+ if (!viewer || !file) return;
75
+ const v = viewer;
76
+
77
+ if (file instanceof File) {
78
+ v.loadFile(file).then(
79
+ () => { untrack(() => onlayersloaded)?.(v.getLayers()); },
80
+ (err: unknown) => { console.error('CadViewer: failed to load file', err); },
81
+ );
82
+ } else if (file instanceof ArrayBuffer) {
83
+ v.loadArrayBuffer(file);
84
+ untrack(() => onlayersloaded)?.(v.getLayers());
85
+ } else if (typeof file === 'string') {
86
+ v.loadString(file);
87
+ untrack(() => onlayersloaded)?.(v.getLayers());
88
+ }
89
+ });
90
+
91
+ // Event listener management
92
+ $effect(() => {
93
+ if (!viewer) return;
94
+ const v = viewer;
95
+
96
+ const cleanups: Array<() => void> = [];
97
+
98
+ if (onselect) {
99
+ v.on('select', onselect);
100
+ cleanups.push(() => { v.off('select', onselect!); });
101
+ }
102
+ if (onmeasure) {
103
+ v.on('measure', onmeasure);
104
+ cleanups.push(() => { v.off('measure', onmeasure!); });
105
+ }
106
+ if (onviewchange) {
107
+ v.on('viewchange', onviewchange);
108
+ cleanups.push(() => { v.off('viewchange', onviewchange!); });
109
+ }
110
+
111
+ return () => { cleanups.forEach((c) => { c(); }); };
112
+ });
113
+
114
+ export function getViewer(): CoreCadViewer | null {
115
+ return viewer;
116
+ }
117
+
118
+ export function fitToView(): void {
119
+ viewer?.fitToView();
120
+ }
121
+
122
+ export function getLayers(): DxfLayer[] {
123
+ return viewer?.getLayers() ?? [];
124
+ }
125
+
126
+ export function setLayerVisible(name: string, visible: boolean): void {
127
+ viewer?.setLayerVisible(name, visible);
128
+ }
129
+ </script>
130
+
131
+ <div class={className} style="position: relative; overflow: hidden;">
132
+ <canvas
133
+ bind:this={canvas}
134
+ style="display: block; width: 100%; height: 100%;"
135
+ ></canvas>
136
+ </div>
@@ -0,0 +1,21 @@
1
+ import { CadViewer as CoreCadViewer, type CadViewerOptions, type DxfLayer, type SelectEvent, type MeasureEvent, type ViewTransform, type Tool, type Theme } from '@cadview/core';
2
+ interface Props {
3
+ file?: File | ArrayBuffer | string | null;
4
+ theme?: Theme;
5
+ tool?: Tool;
6
+ options?: Omit<CadViewerOptions, 'theme' | 'initialTool'>;
7
+ class?: string;
8
+ onselect?: (event: SelectEvent) => void;
9
+ onmeasure?: (event: MeasureEvent) => void;
10
+ onviewchange?: (transform: ViewTransform) => void;
11
+ onlayersloaded?: (layers: DxfLayer[]) => void;
12
+ }
13
+ declare const CadViewer: import("svelte").Component<Props, {
14
+ getViewer: () => CoreCadViewer | null;
15
+ fitToView: () => void;
16
+ getLayers: () => DxfLayer[];
17
+ setLayerVisible: (name: string, visible: boolean) => void;
18
+ }, "">;
19
+ type CadViewer = ReturnType<typeof CadViewer>;
20
+ export default CadViewer;
21
+ //# sourceMappingURL=CadViewer.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CadViewer.svelte.d.ts","sourceRoot":"","sources":["../src/lib/CadViewer.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,SAAS,IAAI,aAAa,EAC1B,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,IAAI,EACT,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AAGvB,UAAU,KAAK;IACb,IAAI,CAAC,EAAE,IAAI,GAAG,WAAW,GAAG,MAAM,GAAG,IAAI,CAAC;IAC1C,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,OAAO,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,aAAa,CAAC,CAAC;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACxC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IAC1C,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,aAAa,KAAK,IAAI,CAAC;IAClD,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,IAAI,CAAC;CAC/C;AAqHH,QAAA,MAAM,SAAS;qBAvBU,aAAa,GAAG,IAAI;qBAIpB,IAAI;qBAIJ,QAAQ,EAAE;4BAID,MAAM,WAAW,OAAO,KAAG,IAAI;MAWV,CAAC;AACxD,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAC9C,eAAe,SAAS,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { default as CadViewer } from './CadViewer.svelte';
2
+ export type { SelectEvent, MeasureEvent, ViewTransform, DxfLayer, DxfDocument, DxfEntity, Tool, Theme, CadViewerOptions, } from '@cadview/core';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG1D,YAAY,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,WAAW,EACX,SAAS,EACT,IAAI,EACJ,KAAK,EACL,gBAAgB,GACjB,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { default as CadViewer } from './CadViewer.svelte';
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@cadview/svelte",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "description": "Svelte 5 wrapper for @cadview/core — CAD/DXF file viewer component",
7
+ "author": "Wisnu Wicaksono",
8
+ "keywords": [
9
+ "cad",
10
+ "dxf",
11
+ "viewer",
12
+ "svelte",
13
+ "svelte5",
14
+ "component",
15
+ "canvas"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/wiscaksono/cadview.git",
20
+ "directory": "packages/svelte"
21
+ },
22
+ "homepage": "https://github.com/wiscaksono/cadview/tree/main/packages/svelte#readme",
23
+ "bugs": {
24
+ "url": "https://github.com/wiscaksono/cadview/issues"
25
+ },
26
+ "engines": {
27
+ "node": ">=18"
28
+ },
29
+ "main": "./dist/index.js",
30
+ "svelte": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "svelte": "./dist/index.js",
36
+ "default": "./dist/index.js"
37
+ }
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "LICENSE",
42
+ "README.md",
43
+ "!dist/**/*.test.*"
44
+ ],
45
+ "peerDependencies": {
46
+ "svelte": "^5.0.0",
47
+ "@cadview/core": "0.1.0"
48
+ },
49
+ "devDependencies": {
50
+ "@sveltejs/package": "^2.0.0",
51
+ "svelte": "^5.0.0",
52
+ "svelte-check": "^4.0.0",
53
+ "typescript": "^5.7.0",
54
+ "@cadview/core": "0.1.0"
55
+ },
56
+ "sideEffects": false,
57
+ "scripts": {
58
+ "build": "svelte-package",
59
+ "dev": "svelte-package --watch",
60
+ "typecheck": "svelte-check"
61
+ }
62
+ }