@mlightcad/cad-viewer 1.4.10 → 1.4.11

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.
Files changed (49) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +392 -381
  3. package/dist/app/app.d.ts.map +1 -1
  4. package/dist/app/register.d.ts +1 -0
  5. package/dist/app/register.d.ts.map +1 -1
  6. package/dist/component/MlCadViewer.vue.d.ts +1 -1
  7. package/dist/component/MlCadViewer.vue.d.ts.map +1 -1
  8. package/dist/component/common/MlBaseDialog.vue.d.ts +6 -6
  9. package/dist/component/common/MlBaseDrawStyleToolbar.vue.d.ts +5 -5
  10. package/dist/component/common/MlBaseDrawStyleToolbar.vue.d.ts.map +1 -1
  11. package/dist/component/common/MlColorPickerDropdown.vue.d.ts +73 -0
  12. package/dist/component/common/MlColorPickerDropdown.vue.d.ts.map +1 -0
  13. package/dist/component/common/MlColorPickerTabs.vue.d.ts +41 -0
  14. package/dist/component/common/MlColorPickerTabs.vue.d.ts.map +1 -0
  15. package/dist/component/common/MlDialogManager.vue.d.ts +6 -0
  16. package/dist/component/common/MlDialogManager.vue.d.ts.map +1 -0
  17. package/dist/component/common/MlFileReader.vue.d.ts.map +1 -1
  18. package/dist/component/common/createMlColorIndexPickerToolbarFactory.d.ts +7 -0
  19. package/dist/component/common/createMlColorIndexPickerToolbarFactory.d.ts.map +1 -0
  20. package/dist/component/common/index.d.ts +3 -0
  21. package/dist/component/common/index.d.ts.map +1 -1
  22. package/dist/component/dialog/MlColorPickerDlg.vue.d.ts +1 -1
  23. package/dist/component/dialog/MlColorPickerDlg.vue.d.ts.map +1 -1
  24. package/dist/component/layout/MlEntityDrawStyleToolbar.vue.d.ts +3 -3
  25. package/dist/component/layout/MlEntityDrawStyleToolbar.vue.d.ts.map +1 -1
  26. package/dist/component/layout/MlToolBars.vue.d.ts.map +1 -1
  27. package/dist/component/palette/MlEntityProperties.vue.d.ts.map +1 -1
  28. package/dist/component/palette/MlLayerList.vue.d.ts.map +1 -1
  29. package/dist/composable/useDark.d.ts +4 -1
  30. package/dist/composable/useDark.d.ts.map +1 -1
  31. package/dist/composable/useDialogManager.d.ts +1 -1
  32. package/dist/composable/useDialogManager.d.ts.map +1 -1
  33. package/dist/composable/useEntityDrawStyle.d.ts +2 -2
  34. package/dist/composable/useEntityDrawStyle.d.ts.map +1 -1
  35. package/dist/composable/useHover.d.ts +66 -0
  36. package/dist/composable/useHover.d.ts.map +1 -1
  37. package/dist/composable/useLayers.d.ts +2 -1
  38. package/dist/composable/useLayers.d.ts.map +1 -1
  39. package/dist/composable/useSystemVars.d.ts +7 -0
  40. package/dist/composable/useSystemVars.d.ts.map +1 -1
  41. package/dist/index.css +1 -1
  42. package/dist/index.js +26509 -3440
  43. package/dist/locale/en/main.d.ts +24 -0
  44. package/dist/locale/en/main.d.ts.map +1 -1
  45. package/dist/locale/zh/main.d.ts +24 -0
  46. package/dist/locale/zh/main.d.ts.map +1 -1
  47. package/dist/svg/index.d.ts +6 -0
  48. package/dist/svg/index.d.ts.map +1 -1
  49. package/package.json +6 -7
package/README.md CHANGED
@@ -1,381 +1,392 @@
1
- # CAD Viewer Component
2
-
3
- CAD Viewer is a **high-performance** Vue 3 component for viewing and editing CAD files (DXF, DWG) **entirely in the browser without requiring any backend server**. It provides a modern user interface, state management, and seamless integration with optimized rendering engines for smooth browser-based CAD workflows with exceptional performance.
4
-
5
- ## Key Features
6
-
7
- - **High-performance** CAD editing and viewing with smooth 60+ FPS rendering
8
- - **No backend required** - Files are parsed and processed entirely in the browser
9
- - **Enhanced data security** - Files never leave your device, ensuring complete privacy
10
- - **Local file support** - Load DWG/DXF files directly from your computer via file dialog or drag & drop
11
- - **Remote file support** - Load CAD files from URLs automatically
12
- - **Easy integration** - No server setup or backend infrastructure needed for third-party integration
13
- - **Customizable UI** - Control visibility of toolbars, command line, coordinates, and performance stats
14
- - **Customizable Resources** - Set custom base URLs for fonts, templates, and example files
15
- - Modern UI optimized for large CAD file handling
16
- - State management for layers, entities, and settings
17
- - Integration with optimized SVG and THREE.js renderers
18
- - Dialogs, toolbars, and command line interface
19
- - Vue 3 component for embedding high-performance CAD viewers in your own apps
20
-
21
- ## When Should You Choose cad-viewer?
22
-
23
- Use `cad-viewer` if you want a **ready-to-use Vue 3 component** for viewing and editing CAD files with a modern UI, dialogs, toolbars, and state management. This package is ideal if:
24
-
25
- - You want to quickly embed a high-performance CAD viewer/editor into your Vue application with minimal setup.
26
- - You need support for both local file loading (from user's computer) and remote file loading (from URLs).
27
- - You need a solution that handles file loading, rendering, layer/entity management, and user interactions out of the box.
28
- - You want seamless integration with optimized SVG and THREE.js renderers, internationalization, and theming.
29
- - You do **not** want to build your own UI from scratch.
30
-
31
- **Recommended for:** Most web applications, dashboards, or platforms that need to display CAD files with a polished user interface.
32
-
33
- ## Browser-Only Architecture
34
-
35
- This Vue 3 component operates entirely in the browser with **no backend dependencies**. DWG/DXF files are parsed and processed locally using WebAssembly and JavaScript, providing:
36
-
37
- - **Zero server requirements** - Deploy the component anywhere with just static file hosting
38
- - **Complete data privacy** - CAD files never leave the user's device, whether loaded locally or from URLs
39
- - **Local file support** - Users can load files directly from their computer using the built-in file dialog
40
- - **Remote file support** - Automatically load files from URLs when provided
41
- - **Instant integration** - No complex backend setup or API configuration needed
42
- - **Offline capability** - Works without internet connectivity once loaded
43
- - **Third-party friendly** - Easy to embed in any Vue 3 application without server-side concerns
44
-
45
- ## File Loading Methods
46
-
47
- The MlCadViewer component supports multiple ways to load CAD files:
48
-
49
- ### 1. Local File Loading
50
- Users can load files directly from their computer:
51
- - **File Dialog**: Click the main menu (☰) and select "Open" to browse and select local DWG/DXF files
52
- - **Drag & Drop**: Drag and drop CAD files directly onto the viewer (if implemented in your application)
53
- - **File Input**: Use the built-in file reader component for programmatic file selection
54
- - **Component Prop**: Pass a File object directly to the `localFile` prop for automatic loading
55
-
56
- #### Example: Using localFile prop with file input
57
- ```vue
58
- <template>
59
- <div>
60
- <input
61
- type="file"
62
- accept=".dwg,.dxf"
63
- @change="handleFileSelect"
64
- />
65
- <MlCadViewer
66
- :local-file="selectedFile"
67
- />
68
- </div>
69
- </template>
70
-
71
- <script setup lang="ts">
72
- import { ref } from 'vue'
73
- import { MlCadViewer } from '@mlightcad/cad-viewer'
74
-
75
- const selectedFile = ref<File | undefined>()
76
-
77
- const handleFileSelect = (event: Event) => {
78
- const target = event.target as HTMLInputElement
79
- selectedFile.value = target.files?.[0]
80
- }
81
- </script>
82
- ```
83
-
84
- ### 2. Remote File Loading
85
- Automatically load files from URLs:
86
- - **URL Prop**: Provide a `url` prop to automatically load a file when the component mounts
87
- - **Dynamic Loading**: Change the `url` prop to load different files without remounting the component
88
-
89
- ### 3. Supported File Formats
90
- - **DWG files**: Binary AutoCAD drawing format (read as ArrayBuffer)
91
- - **DXF files**: ASCII/binary AutoCAD drawing exchange format (read as text)
92
-
93
- ## Directory Structure (partial)
94
-
95
- - `src/app/` – Application entry, store, and main logic
96
- - `src/component/` – UI components (dialogs, toolbars, status bar, etc.)
97
- - `src/composable/` – Vue composables for state and logic
98
- - `src/locale/` – Internationalization files
99
- - `src/style/` – Stylesheets
100
- - `src/svg/` – SVG assets
101
-
102
- ## Installation
103
-
104
- ```bash
105
- npm install @mlightcad/cad-viewer
106
- ```
107
-
108
- ## Usage
109
-
110
- Please refer to sub-package `cad-viewer-example` as one example.
111
-
112
- ### Basic Usage
113
-
114
- Firstly, add the following dependencies into your package.json.
115
-
116
- - @element-plus/icons-vue
117
- - @mlightcad/cad-simple-viewer
118
- - @mlightcad/cad-viewer
119
- - @mlightcad/data-model
120
- - @vueuse/core
121
- - element-plus
122
- - vue
123
- - vue-i18n
124
-
125
- Then create one vue component as follows.
126
-
127
- ```vue
128
- <template>
129
- <div>
130
- <!-- For local file loading (users can open files via menu) -->
131
- <MlCADViewer :background="0x808080" />
132
-
133
- <!-- For remote file loading (automatically loads from URL) -->
134
- <!-- <MlCADViewer
135
- :background="0x808080"
136
- :url="'https://example.com/drawing.dwg'"
137
- /> -->
138
-
139
- <!-- For local file loading (automatically loads from File object) -->
140
- <!-- <MlCADViewer
141
- :background="0x808080"
142
- :local-file="selectedFile"
143
- /> -->
144
-
145
- <!-- With custom base URL for fonts and templates -->
146
- <!-- <MlCADViewer
147
- :background="0x808080"
148
- :base-url="'https://my-cdn.com/cad-data/'"
149
- /> -->
150
- </div>
151
- </template>
152
-
153
- <script setup lang="ts">
154
- import 'uno.css'
155
- import 'element-plus/dist/index.css'
156
- import 'element-plus/dist/index.css'
157
-
158
- import {
159
- i18n,
160
- MlCadViewer
161
- } from '@mlightcad/cad-viewer'
162
- import ElementPlus from 'element-plus'
163
- import { createApp } from 'vue'
164
-
165
- const initApp = () => {
166
- const app = createApp(MlCadViewer)
167
- app.use(i18n)
168
- app.use(ElementPlus)
169
- app.mount('#app')
170
- }
171
-
172
- initApp()
173
- </script>
174
- ```
175
-
176
- ## MlCadViewer Component
177
-
178
- The `MlCadViewer` is the main Vue 3 component that provides a complete CAD viewing and editing interface. It includes toolbars, layer management, command line, status bar, and various dialogs for a full-featured CAD experience.
179
-
180
- ### Component Properties
181
-
182
- The `MlCadViewer` component accepts the following props:
183
-
184
- | Property | Type | Default | Description |
185
- |----------|------|---------|-------------|
186
- | `locale` | `'en' \| 'zh' \| 'default'` | `'default'` | Sets the language for the component interface. Use `'en'` for English, `'zh'` for Chinese, or `'default'` to use the browser's default language. |
187
- | `url` | `string` | `undefined` | Optional URL to automatically load a CAD file when the component mounts. The file will be fetched and opened automatically. **Note**: If not provided, users can still load local files using the main menu "Open" option. |
188
- | `localFile` | `File` | `undefined` | Optional local File object to automatically load a CAD file when the component mounts. The file will be read and opened automatically. **Note**: This takes precedence over the `url` prop if both are provided. |
189
- | `background` | `number` | `undefined` | Background color as 24-bit hexadecimal RGB (e.g., `0x000000` for black, `0x808080` for gray). |
190
- | `baseUrl` | `string` | `undefined` | Base URL for loading fonts, templates, and example files. This URL is used by the CAD viewer to load resources like fonts and drawing templates. **Note**: If not provided, uses the default URL. |
191
- | `useMainThreadDraw` | `boolean` | `false` | Optional flag whether to use main thread or webwork to render drawing. The true value means using main thread to render drawing. This approach take less memory and take longer time to show rendering results. The false value means using web worker to render drawing. This approach take more memory and take shorter time to show rendering results. |
192
- | `theme` | `'light' \| 'dark'` | `'dark'` | Initial theme of the CAD viewer. `'light'` applies the light theme (`ml-theme-light` class) and `'dark'` applies the dark theme (`ml-theme-dark` class). The theme can also be toggled at runtime using the status bar theme button. |
193
- | `mode` | `AcEdOpenMode` | `'AcEdOpenMode.Write'` | Access mode for opening CAD files. `'AcEdOpenMode.Read'` means read-only access. `'AcEdOpenMode.Review'` means review access, compatible with read. `'AcEdOpenMode.Write'` means full read/write access, compatible with review and read. |
194
- ### UI Settings
195
-
196
- The `MlCadViewer` reads its UI visibility from the global `AcApSettingManager` (provided by `@mlightcad/cad-simple-viewer`). Configure these flags anywhere before rendering the viewer to customize the UI.
197
-
198
- | Setting | Type | Default | Description |
199
- |---------|------|---------|-------------|
200
- | `isShowToolbar` | `boolean` | `true` | Controls toolbar visibility |
201
- | `isShowCommandLine` | `boolean` | `true` | Controls command line visibility |
202
- | `isShowCoordinate` | `boolean` | `true` | Controls coordinate display visibility |
203
- | `isShowEntityInfo` | `boolean` | `false` | Controls entity info card visibility |
204
- | `isShowLanguageSelector` | `boolean` | `true` | Controls language selector visibility |
205
- | `isShowMainMenu` | `boolean` | `true` | Controls main menu visibility |
206
- | `isShowStats` | `boolean` | `false` | Controls performance statistics display |
207
-
208
- #### Example (recommended)
209
- ```vue
210
- <template>
211
- <!-- Local file loading - users can open files via main menu -->
212
- <MlCadViewer locale="en" />
213
-
214
- <!-- Remote file loading - automatically loads from URL -->
215
- <!-- <MlCadViewer
216
- locale="en"
217
- :url="'https://example.com/drawing.dwg'"
218
- /> -->
219
-
220
- <!-- Local file loading - automatically loads from File object -->
221
- <!-- <MlCadViewer
222
- locale="en"
223
- :local-file="selectedFile"
224
- /> -->
225
-
226
- <!-- Custom baseUrl for fonts and templates -->
227
- <!-- <MlCadViewer
228
- locale="en"
229
- :base-url="'https://my-cdn.com/cad-data/'"
230
- /> -->
231
- </template>
232
-
233
- <script setup lang="ts">
234
- import { MlCadViewer } from '@mlightcad/cad-viewer'
235
- import { AcApSettingManager } from '@mlightcad/cad-simple-viewer'
236
-
237
- // Configure global UI flags before the viewer mounts
238
- AcApSettingManager.instance.isShowCommandLine = false
239
- // Optional toggles
240
- // AcApSettingManager.instance.isShowToolbar = false
241
- // AcApSettingManager.instance.isShowStats = true
242
- // AcApSettingManager.instance.isShowCoordinate = false
243
- // AcApSettingManager.instance.isShowEntityInfo = false
244
- </script>
245
- ```
246
-
247
- #### Notes
248
-
249
- - Settings are global and immediately reflected by `MlCadViewer`.
250
- - You can change them at runtime using the same `AcApSettingManager.instance` reference.
251
-
252
- ### Base URL Configuration
253
-
254
- The `baseUrl` property allows you to customize where the CAD viewer loads fonts, templates, and example files from. This is particularly useful for:
255
-
256
- - **Self-hosted resources**: Host your own fonts and templates on your CDN or server
257
- - **Corporate environments**: Use internal servers for CAD resources
258
- - **Offline deployments**: Serve resources from local file systems
259
- - **Custom branding**: Use your own templates and fonts
260
-
261
- #### Default Behavior
262
- If no `baseUrl` is provided, the viewer uses the default URL: `https://mlightcad.gitlab.io/cad-data/`
263
-
264
- #### Resource Structure
265
- When using a custom `baseUrl`, ensure your server has the following structure:
266
- ```
267
- your-base-url/
268
- ├── fonts/ # Font files for text rendering
269
- ├── templates/ # Drawing templates (e.g., acadiso.dxf)
270
- └── examples/ # Example CAD files
271
- ```
272
-
273
- #### Example: Custom Base URL
274
- ```vue
275
- <template>
276
- <MlCadViewer
277
- :base-url="'https://my-company.com/cad-resources/'"
278
- :url="'https://my-company.com/drawings/project.dwg'"
279
- />
280
- </template>
281
- ```
282
-
283
- This configuration will:
284
- - Load fonts from `https://my-company.com/cad-resources/fonts/`
285
- - Load templates from `https://my-company.com/cad-resources/templates/`
286
- - Use the custom base URL for any "Quick New" operations
287
-
288
- ### Component Features
289
-
290
- The `MlCadViewer` component includes:
291
-
292
- - **Main Menu** - File operations (including local file opening), view controls, and settings
293
- - **Toolbars** - Drawing tools, zoom controls, and selection tools
294
- - **Layer Manager** - Layer visibility and property management
295
- - **Command Line** - AutoCAD-style command input
296
- - **Status Bar** - Current position, zoom level, and system status
297
- - **Dialog Manager** - Modal dialogs for various operations
298
- - **File Reader** - Local file loading via file dialog and drag-and-drop support
299
- - **Entity Info** - Detailed information about selected entities
300
- - **Language Selector** - UI language switching
301
- - **Theme Support** - Dark/light mode toggle
302
-
303
- ### Event Handling
304
-
305
- The component automatically handles various events:
306
-
307
- - **File Loading** - Supports local file loading (via file dialog), drag-and-drop, and URL-based file loading
308
- - **Error Messages** - Displays user-friendly error messages for failed operations
309
- - **Font Loading** - Handles missing fonts with appropriate notifications
310
- - **System Messages** - Shows status updates and operation feedback
311
-
312
- ### Advanced Usage
313
-
314
- Please refer to [readme of cad-simple-viewer](../cad-simple-viewer/README.md) to learn the following advanced usage.
315
-
316
- - Register DWG converter to display drawings in DWG format
317
- - Define your own font loader to load fonts from your own server
318
- - Create drawing or modify drawing
319
-
320
- ## Available Exports
321
-
322
- ### Main Component
323
-
324
- - `MlCADViewer` - The main CAD viewer component
325
-
326
- ### Commands
327
-
328
- - `AcApLayerStateCmd` - Layer state command
329
- - `AcApLogCmd` - Log command
330
- - `AcApMissedDataCmd` - Missed data command
331
- - `AcApPointStyleCmd` - Point style command
332
-
333
- ### Components
334
-
335
- - `MlPointStyleDlg` - Point style dialog
336
- - `MlReplacementDlg` - Replacement dialog
337
- - Various layout and UI components
338
-
339
- ### Composables
340
-
341
- - `useCommands` - Command management
342
- - `useCurrentPos` - Current position tracking
343
- - `useDark` - Dark mode support
344
- - `useDialogManager` - Dialog management
345
- - `useFileTypes` - File type utilities
346
- - `useLayers` - Layer management
347
- - `useLayouts` - Layout management
348
- - `useMissedData` - Missed data handling
349
- - `useSettings` - Settings management
350
- - `useSystemVars` - System variables
351
-
352
- ### Locale
353
-
354
- - `i18n` - Internationalization instance
355
- - Language files for English and Chinese
356
-
357
- ### Styles
358
-
359
- - CSS and SCSS files for styling
360
- - Dark mode support
361
- - Element Plus integration
362
-
363
- ## Development
364
-
365
- ```bash
366
- # Install dependencies
367
- pnpm install
368
-
369
- # Start development server
370
- pnpm dev
371
-
372
- # Build the library
373
- pnpm build
374
-
375
- # Preview the build
376
- pnpm preview
377
- ```
378
-
379
- ## License
380
-
381
- MIT
1
+ # CAD Viewer Component
2
+
3
+ CAD Viewer is a **high-performance** Vue 3 component for viewing and editing CAD files (DXF, DWG) **entirely in the browser without requiring any backend server**. It provides a modern user interface, state management, and seamless integration with optimized rendering engines for smooth browser-based CAD workflows with exceptional performance.
4
+
5
+ ## Key Features
6
+
7
+ - **High-performance** CAD editing and viewing with smooth 60+ FPS rendering
8
+ - **No backend required** - Files are parsed and processed entirely in the browser
9
+ - **Enhanced data security** - Files never leave your device, ensuring complete privacy
10
+ - **Local file support** - Load DWG/DXF files directly from your computer via file dialog or drag & drop
11
+ - **Remote file support** - Load CAD files from URLs automatically
12
+ - **Easy integration** - No server setup or backend infrastructure needed for third-party integration
13
+ - **Customizable UI** - Control visibility of toolbars, command line, coordinates, and performance stats
14
+ - **Customizable Resources** - Set custom base URLs for fonts, templates, and example files
15
+ - Modern UI optimized for large CAD file handling
16
+ - State management for layers, entities, and settings
17
+ - Integration with optimized SVG and THREE.js renderers
18
+ - Dialogs, toolbars, and command line interface
19
+ - Vue 3 component for embedding high-performance CAD viewers in your own apps
20
+
21
+ ## When Should You Choose cad-viewer?
22
+
23
+ Use `cad-viewer` if you want a **ready-to-use Vue 3 component** for viewing and editing CAD files with a modern UI, dialogs, toolbars, and state management. This package is ideal if:
24
+
25
+ - You want to quickly embed a high-performance CAD viewer/editor into your Vue application with minimal setup.
26
+ - You need support for both local file loading (from user's computer) and remote file loading (from URLs).
27
+ - You need a solution that handles file loading, rendering, layer/entity management, and user interactions out of the box.
28
+ - You want seamless integration with optimized SVG and THREE.js renderers, internationalization, and theming.
29
+ - You do **not** want to build your own UI from scratch.
30
+
31
+ **Recommended for:** Most web applications, dashboards, or platforms that need to display CAD files with a polished user interface.
32
+
33
+ ## Browser-Only Architecture
34
+
35
+ This Vue 3 component operates entirely in the browser with **no backend dependencies**. DWG/DXF files are parsed and processed locally using WebAssembly and JavaScript, providing:
36
+
37
+ - **Zero server requirements** - Deploy the component anywhere with just static file hosting
38
+ - **Complete data privacy** - CAD files never leave the user's device, whether loaded locally or from URLs
39
+ - **Local file support** - Users can load files directly from their computer using the built-in file dialog
40
+ - **Remote file support** - Automatically load files from URLs when provided
41
+ - **Instant integration** - No complex backend setup or API configuration needed
42
+ - **Offline capability** - Works without internet connectivity once loaded
43
+ - **Third-party friendly** - Easy to embed in any Vue 3 application without server-side concerns
44
+
45
+ ## File Loading Methods
46
+
47
+ The MlCadViewer component supports multiple ways to load CAD files:
48
+
49
+ ### 1. Local File Loading
50
+ Users can load files directly from their computer:
51
+ - **File Dialog**: Click the main menu (☰) and select "Open" to browse and select local DWG/DXF files
52
+ - **Drag & Drop**: Drag and drop CAD files directly onto the viewer (if implemented in your application)
53
+ - **File Input**: Use the built-in file reader component for programmatic file selection
54
+ - **Component Prop**: Pass a File object directly to the `localFile` prop for automatic loading
55
+
56
+ #### Example: Using localFile prop with file input
57
+ ```vue
58
+ <template>
59
+ <div>
60
+ <input
61
+ type="file"
62
+ accept=".dwg,.dxf"
63
+ @change="handleFileSelect"
64
+ />
65
+ <MlCadViewer
66
+ :local-file="selectedFile"
67
+ />
68
+ </div>
69
+ </template>
70
+
71
+ <script setup lang="ts">
72
+ import { ref } from 'vue'
73
+ import { MlCadViewer } from '@mlightcad/cad-viewer'
74
+
75
+ const selectedFile = ref<File | undefined>()
76
+
77
+ const handleFileSelect = (event: Event) => {
78
+ const target = event.target as HTMLInputElement
79
+ selectedFile.value = target.files?.[0]
80
+ }
81
+ </script>
82
+ ```
83
+
84
+ ### 2. Remote File Loading
85
+ Automatically load files from URLs:
86
+ - **URL Prop**: Provide a `url` prop to automatically load a file when the component mounts
87
+ - **Dynamic Loading**: Change the `url` prop to load different files without remounting the component
88
+
89
+ ### 3. Supported File Formats
90
+ - **DWG files**: Binary AutoCAD drawing format (read as ArrayBuffer)
91
+ - **DXF files**: ASCII/binary AutoCAD drawing exchange format (read as text)
92
+
93
+ ## Directory Structure (partial)
94
+
95
+ - `src/app/` – Application entry, store, and main logic
96
+ - `src/component/` – UI components (dialogs, toolbars, status bar, etc.)
97
+ - `src/composable/` – Vue composables for state and logic
98
+ - `src/locale/` – Internationalization files
99
+ - `src/style/` – Stylesheets
100
+ - `src/svg/` – SVG assets
101
+
102
+ ## Installation
103
+
104
+ ```bash
105
+ npm install @mlightcad/cad-viewer
106
+ ```
107
+
108
+ ## Usage
109
+
110
+ Please refer to sub-package `cad-viewer-example` as one example.
111
+
112
+ ### Basic Usage
113
+
114
+ Firstly, add the following dependencies into your package.json.
115
+
116
+ - @element-plus/icons-vue
117
+ - @mlightcad/cad-simple-viewer
118
+ - @mlightcad/cad-viewer
119
+ - @mlightcad/data-model
120
+ - @vueuse/core
121
+ - element-plus
122
+ - vue
123
+ - vue-i18n
124
+
125
+ Then create one vue component as follows.
126
+
127
+ ```vue
128
+ <template>
129
+ <div>
130
+ <!-- For local file loading (users can open files via menu) -->
131
+ <MlCADViewer :background="0x808080" />
132
+
133
+ <!-- For remote file loading (automatically loads from URL) -->
134
+ <!-- <MlCADViewer
135
+ :background="0x808080"
136
+ :url="'https://example.com/drawing.dwg'"
137
+ /> -->
138
+
139
+ <!-- For local file loading (automatically loads from File object) -->
140
+ <!-- <MlCADViewer
141
+ :background="0x808080"
142
+ :local-file="selectedFile"
143
+ /> -->
144
+
145
+ <!-- With custom base URL for fonts and templates -->
146
+ <!-- <MlCADViewer
147
+ :background="0x808080"
148
+ :base-url="'https://my-cdn.com/cad-data/'"
149
+ /> -->
150
+ </div>
151
+ </template>
152
+
153
+ <script setup lang="ts">
154
+ import 'uno.css'
155
+ import 'element-plus/dist/index.css'
156
+ import 'element-plus/dist/index.css'
157
+
158
+ import {
159
+ i18n,
160
+ MlCadViewer
161
+ } from '@mlightcad/cad-viewer'
162
+ import ElementPlus from 'element-plus'
163
+ import { createApp } from 'vue'
164
+
165
+ const initApp = () => {
166
+ const app = createApp(MlCadViewer)
167
+ app.use(i18n)
168
+ app.use(ElementPlus)
169
+ app.mount('#app')
170
+ }
171
+
172
+ initApp()
173
+ </script>
174
+ ```
175
+
176
+ ## MlCadViewer Component
177
+
178
+ The `MlCadViewer` is the main Vue 3 component that provides a complete CAD viewing and editing interface. It includes toolbars, layer management, command line, status bar, and various dialogs for a full-featured CAD experience.
179
+
180
+ ### Component Properties
181
+
182
+ The `MlCadViewer` component accepts the following props:
183
+
184
+ | Property | Type | Default | Description |
185
+ |----------|------|---------|-------------|
186
+ | `locale` | `'en' \| 'zh' \| 'default'` | `'default'` | Sets the language for the component interface. Use `'en'` for English, `'zh'` for Chinese, or `'default'` to use the browser's default language. |
187
+ | `url` | `string` | `undefined` | Optional URL to automatically load a CAD file when the component mounts. The file will be fetched and opened automatically. **Note**: If not provided, users can still load local files using the main menu "Open" option. |
188
+ | `localFile` | `File` | `undefined` | Optional local File object to automatically load a CAD file when the component mounts. The file will be read and opened automatically. **Note**: This takes precedence over the `url` prop if both are provided. |
189
+ | `background` | `number` | `undefined` | Background color as 24-bit hexadecimal RGB (e.g., `0x000000` for black, `0x808080` for gray). |
190
+ | `baseUrl` | `string` | `undefined` | Base URL for loading fonts, templates, and example files. This URL is used by the CAD viewer to load resources like fonts and drawing templates. **Note**: If not provided, uses the default URL. |
191
+ | `useMainThreadDraw` | `boolean` | `false` | Optional flag whether to use main thread or webwork to render drawing. The true value means using main thread to render drawing. This approach take less memory and take longer time to show rendering results. The false value means using web worker to render drawing. This approach take more memory and take shorter time to show rendering results. |
192
+ | `theme` | `'light' \| 'dark'` | `'dark'` | Initial UI theme of the CAD viewer. On mount, this prop initializes the `COLORTHEME` system variable in the active database (`0 = dark`, `1 = light`). After that, the viewer theme is driven by `COLORTHEME`, so runtime changes from the status bar theme button or direct system-variable updates stay synchronized across `cad-viewer` and `cad-simple-viewer`. |
193
+ | `mode` | `AcEdOpenMode` | `'AcEdOpenMode.Write'` | Access mode for opening CAD files. `'AcEdOpenMode.Read'` means read-only access. `'AcEdOpenMode.Review'` means review access, compatible with read. `'AcEdOpenMode.Write'` means full read/write access, compatible with review and read. |
194
+ ### UI Settings
195
+
196
+ The `MlCadViewer` reads its UI visibility from the global `AcApSettingManager` (provided by `@mlightcad/cad-simple-viewer`). Configure these flags anywhere before rendering the viewer to customize the UI.
197
+
198
+ | Setting | Type | Default | Description |
199
+ |---------|------|---------|-------------|
200
+ | `isShowToolbar` | `boolean` | `true` | Controls toolbar visibility |
201
+ | `isShowCommandLine` | `boolean` | `true` | Controls command line visibility |
202
+ | `isShowCoordinate` | `boolean` | `true` | Controls coordinate display visibility |
203
+ | `isShowEntityInfo` | `boolean` | `false` | Controls entity info card visibility |
204
+ | `isShowLanguageSelector` | `boolean` | `true` | Controls language selector visibility |
205
+ | `isShowMainMenu` | `boolean` | `true` | Controls main menu visibility |
206
+ | `isShowStats` | `boolean` | `false` | Controls performance statistics display |
207
+
208
+ #### Example (recommended)
209
+ ```vue
210
+ <template>
211
+ <!-- Local file loading - users can open files via main menu -->
212
+ <MlCadViewer locale="en" />
213
+
214
+ <!-- Remote file loading - automatically loads from URL -->
215
+ <!-- <MlCadViewer
216
+ locale="en"
217
+ :url="'https://example.com/drawing.dwg'"
218
+ /> -->
219
+
220
+ <!-- Local file loading - automatically loads from File object -->
221
+ <!-- <MlCadViewer
222
+ locale="en"
223
+ :local-file="selectedFile"
224
+ /> -->
225
+
226
+ <!-- Custom baseUrl for fonts and templates -->
227
+ <!-- <MlCadViewer
228
+ locale="en"
229
+ :base-url="'https://my-cdn.com/cad-data/'"
230
+ /> -->
231
+ </template>
232
+
233
+ <script setup lang="ts">
234
+ import { MlCadViewer } from '@mlightcad/cad-viewer'
235
+ import { AcApSettingManager } from '@mlightcad/cad-simple-viewer'
236
+
237
+ // Configure global UI flags before the viewer mounts
238
+ AcApSettingManager.instance.isShowCommandLine = false
239
+ // Optional toggles
240
+ // AcApSettingManager.instance.isShowToolbar = false
241
+ // AcApSettingManager.instance.isShowStats = true
242
+ // AcApSettingManager.instance.isShowCoordinate = false
243
+ // AcApSettingManager.instance.isShowEntityInfo = false
244
+ </script>
245
+ ```
246
+
247
+ #### Notes
248
+
249
+ - Settings are global and immediately reflected by `MlCadViewer`.
250
+ - You can change them at runtime using the same `AcApSettingManager.instance` reference.
251
+
252
+ ### Base URL Configuration
253
+
254
+ The `baseUrl` property allows you to customize where the CAD viewer loads fonts, templates, and example files from. This is particularly useful for:
255
+
256
+ - **Self-hosted resources**: Host your own fonts and templates on your CDN or server
257
+ - **Corporate environments**: Use internal servers for CAD resources
258
+ - **Offline deployments**: Serve resources from local file systems
259
+ - **Custom branding**: Use your own templates and fonts
260
+
261
+ #### Default Behavior
262
+ If no `baseUrl` is provided, the viewer uses the default URL: `https://mlightcad.gitlab.io/cad-data/`
263
+
264
+ #### Resource Structure
265
+ When using a custom `baseUrl`, ensure your server has the following structure:
266
+ ```
267
+ your-base-url/
268
+ ├── fonts/ # Font files for text rendering
269
+ ├── templates/ # Drawing templates (e.g., acadiso.dxf)
270
+ └── examples/ # Example CAD files
271
+ ```
272
+
273
+ #### Example: Custom Base URL
274
+ ```vue
275
+ <template>
276
+ <MlCadViewer
277
+ :base-url="'https://my-company.com/cad-resources/'"
278
+ :url="'https://my-company.com/drawings/project.dwg'"
279
+ />
280
+ </template>
281
+ ```
282
+
283
+ This configuration will:
284
+ - Load fonts from `https://my-company.com/cad-resources/fonts/`
285
+ - Load templates from `https://my-company.com/cad-resources/templates/`
286
+ - Use the custom base URL for any "Quick New" operations
287
+
288
+ ### Component Features
289
+
290
+ The `MlCadViewer` component includes:
291
+
292
+ - **Main Menu** - File operations (including local file opening), view controls, and settings
293
+ - **Toolbars** - Drawing tools, zoom controls, and selection tools
294
+ - **Layer Manager** - Layer visibility and property management
295
+ - **Command Line** - AutoCAD-style command input
296
+ - **Status Bar** - Current position, zoom level, and system status
297
+ - **Dialog Manager** - Modal dialogs for various operations
298
+ - **File Reader** - Local file loading via file dialog and drag-and-drop support
299
+ - **Entity Info** - Detailed information about selected entities
300
+ - **Language Selector** - UI language switching
301
+ - **Theme Support** - Dark/light mode driven by the `COLORTHEME` system variable
302
+
303
+ ### Event Handling
304
+
305
+ The component automatically handles various events:
306
+
307
+ - **File Loading** - Supports local file loading (via file dialog), drag-and-drop, and URL-based file loading
308
+ - **Error Messages** - Displays user-friendly error messages for failed operations
309
+ - **Font Loading** - Handles missing fonts with appropriate notifications
310
+ - **System Messages** - Shows status updates and operation feedback
311
+
312
+ ### Advanced Usage
313
+
314
+ Please refer to [readme of cad-simple-viewer](../cad-simple-viewer/README.md) to learn the following advanced usage.
315
+
316
+ - Register DWG converter to display drawings in DWG format
317
+ - Define your own font loader to load fonts from your own server
318
+ - Create drawing or modify drawing
319
+
320
+ ## Available Exports
321
+
322
+ ### Main Component
323
+
324
+ - `MlCADViewer` - The main CAD viewer component
325
+
326
+ ### Commands
327
+
328
+ - `AcApLayerStateCmd` - Layer state command
329
+ - `AcApLogCmd` - Log command
330
+ - `AcApMissedDataCmd` - Missed data command
331
+ - `AcApPointStyleCmd` - Point style command
332
+
333
+ ### Components
334
+
335
+ - `MlPointStyleDlg` - Point style dialog
336
+ - `MlReplacementDlg` - Replacement dialog
337
+ - Various layout and UI components
338
+
339
+ ### Composables
340
+
341
+ - `useCommands` - Command management
342
+ - `useCurrentPos` - Current position tracking
343
+ - `useDark` - Reactive dark-mode state backed by the `COLORTHEME` system variable
344
+ - `useDialogManager` - Dialog management
345
+ - `useFileTypes` - File type utilities
346
+ - `useLayers` - Layer management
347
+ - `useLayouts` - Layout management
348
+ - `useMissedData` - Missed data handling
349
+ - `useSettings` - Settings management
350
+ - `useSystemVars` - System variables
351
+
352
+ ### Theme Synchronization
353
+
354
+ The viewer UI theme is synchronized through the `COLORTHEME` system variable managed by `AcDbSysVarManager`.
355
+
356
+ - `COLORTHEME = 0` means dark theme.
357
+ - `COLORTHEME = 1` means light theme.
358
+ - The `theme` prop provides the initial value when `MlCadViewer` mounts.
359
+ - Clicking the status bar theme button updates `COLORTHEME`.
360
+ - Any runtime change to `COLORTHEME` is reflected automatically in viewer UI and MTEXT-related UI.
361
+ - The exported `useDark` composable is still available, but it now wraps `COLORTHEME` instead of maintaining an isolated local dark-mode state.
362
+
363
+ ### Locale
364
+
365
+ - `i18n` - Internationalization instance
366
+ - Language files for English and Chinese
367
+
368
+ ### Styles
369
+
370
+ - CSS and SCSS files for styling
371
+ - Dark mode support
372
+ - Element Plus integration
373
+
374
+ ## Development
375
+
376
+ ```bash
377
+ # Install dependencies
378
+ pnpm install
379
+
380
+ # Start development server
381
+ pnpm dev
382
+
383
+ # Build the library
384
+ pnpm build
385
+
386
+ # Preview the build
387
+ pnpm preview
388
+ ```
389
+
390
+ ## License
391
+
392
+ MIT