@cadview/svelte 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.
@@ -3,6 +3,8 @@
3
3
  import {
4
4
  CadViewer as CoreCadViewer,
5
5
  type CadViewerOptions,
6
+ type FormatConverter,
7
+ type DebugOptions,
6
8
  type DxfLayer,
7
9
  type SelectEvent,
8
10
  type MeasureEvent,
@@ -15,7 +17,11 @@
15
17
  file?: File | ArrayBuffer | string | null;
16
18
  theme?: Theme;
17
19
  tool?: Tool;
18
- options?: Omit<CadViewerOptions, 'theme' | 'initialTool'>;
20
+ /** Enable debug overlay. Pass `true` for defaults, or a `DebugOptions` object. */
21
+ debug?: boolean | DebugOptions;
22
+ options?: Omit<CadViewerOptions, 'theme' | 'initialTool' | 'debug'>;
23
+ /** Format converters for non-DXF file formats (e.g. DWG via @cadview/dwg). */
24
+ formatConverters?: FormatConverter[];
19
25
  class?: string;
20
26
  onselect?: (event: SelectEvent) => void;
21
27
  onmeasure?: (event: MeasureEvent) => void;
@@ -27,7 +33,9 @@
27
33
  file = null,
28
34
  theme = 'dark',
29
35
  tool = 'pan',
36
+ debug,
30
37
  options = {},
38
+ formatConverters,
31
39
  class: className = '',
32
40
  onselect,
33
41
  onmeasure,
@@ -44,11 +52,16 @@
44
52
 
45
53
  const initialTheme = untrack(() => theme);
46
54
  const initialTool = untrack(() => tool);
55
+ const initialDebug = untrack(() => debug);
47
56
  const initialOptions = untrack(() => options);
48
57
 
58
+ const initialConverters = untrack(() => formatConverters);
59
+
49
60
  const v = new CoreCadViewer(canvas, {
50
61
  theme: initialTheme,
51
62
  initialTool: initialTool,
63
+ debug: initialDebug,
64
+ formatConverters: initialConverters,
52
65
  ...initialOptions,
53
66
  });
54
67
  viewer = v;
@@ -69,23 +82,43 @@
69
82
  viewer?.setTool(tool);
70
83
  });
71
84
 
85
+ // React to debug changes
86
+ $effect(() => {
87
+ if (debug !== undefined) {
88
+ viewer?.setDebug(debug);
89
+ }
90
+ });
91
+
72
92
  // React to file changes
73
93
  $effect(() => {
74
94
  if (!viewer || !file) return;
75
95
  const v = viewer;
96
+ let cancelled = false;
97
+
98
+ const load = async () => {
99
+ try {
100
+ if (file instanceof File) {
101
+ await v.loadFile(file);
102
+ } else if (file instanceof ArrayBuffer) {
103
+ await v.loadBuffer(file);
104
+ } else if (typeof file === 'string') {
105
+ v.loadString(file);
106
+ }
107
+ if (!cancelled) {
108
+ untrack(() => onlayersloaded)?.(v.getLayers());
109
+ }
110
+ } catch (err: unknown) {
111
+ if (!cancelled) {
112
+ console.error('CadViewer: failed to load file', err);
113
+ }
114
+ }
115
+ };
76
116
 
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
- }
117
+ load();
118
+
119
+ return () => {
120
+ cancelled = true;
121
+ };
89
122
  });
90
123
 
91
124
  // Event listener management
@@ -1,9 +1,13 @@
1
- import { CadViewer as CoreCadViewer, type CadViewerOptions, type DxfLayer, type SelectEvent, type MeasureEvent, type ViewTransform, type Tool, type Theme } from '@cadview/core';
1
+ import { CadViewer as CoreCadViewer, type CadViewerOptions, type FormatConverter, type DebugOptions, type DxfLayer, type SelectEvent, type MeasureEvent, type ViewTransform, type Tool, type Theme } from '@cadview/core';
2
2
  interface Props {
3
3
  file?: File | ArrayBuffer | string | null;
4
4
  theme?: Theme;
5
5
  tool?: Tool;
6
- options?: Omit<CadViewerOptions, 'theme' | 'initialTool'>;
6
+ /** Enable debug overlay. Pass `true` for defaults, or a `DebugOptions` object. */
7
+ debug?: boolean | DebugOptions;
8
+ options?: Omit<CadViewerOptions, 'theme' | 'initialTool' | 'debug'>;
9
+ /** Format converters for non-DXF file formats (e.g. DWG via @cadview/dwg). */
10
+ formatConverters?: FormatConverter[];
7
11
  class?: string;
8
12
  onselect?: (event: SelectEvent) => void;
9
13
  onmeasure?: (event: MeasureEvent) => void;
@@ -1 +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,C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C"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { default as CadViewer } from './CadViewer.svelte';
2
- export type { SelectEvent, MeasureEvent, ViewTransform, DxfLayer, DxfDocument, DxfEntity, Tool, Theme, CadViewerOptions, } from '@cadview/core';
2
+ export type { FormatConverter, SelectEvent, MeasureEvent, ViewTransform, DxfLayer, DxfDocument, DxfEntity, Tool, Theme, CadViewerOptions, } from '@cadview/core';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
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,eAAe,EACf,WAAW,EACX,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,WAAW,EACX,SAAS,EACT,IAAI,EACJ,KAAK,EACL,gBAAgB,GACjB,MAAM,eAAe,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cadview/svelte",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Svelte 5 wrapper for @cadview/core — CAD/DXF file viewer component",
@@ -44,14 +44,14 @@
44
44
  ],
45
45
  "peerDependencies": {
46
46
  "svelte": "^5.0.0",
47
- "@cadview/core": "0.1.0"
47
+ "@cadview/core": "0.3.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@sveltejs/package": "^2.0.0",
51
51
  "svelte": "^5.0.0",
52
52
  "svelte-check": "^4.0.0",
53
53
  "typescript": "^5.7.0",
54
- "@cadview/core": "0.1.0"
54
+ "@cadview/core": "0.3.0"
55
55
  },
56
56
  "sideEffects": false,
57
57
  "scripts": {