@mlightcad/common 1.0.1 → 1.0.2
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 +134 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# @mlightcad/common
|
|
2
|
+
|
|
3
|
+
The common package provides shared utilities and base classes that are used across the RealDWG-Web ecosystem. This package contains fundamental components for color management, event handling, logging, performance monitoring, and file loading operations.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package serves as the foundation for the RealDWG-Web project, providing essential utilities and base classes that mimic AutoCAD ObjectARX's AcCm (Common) classes. It includes color management, event dispatching, logging utilities, performance monitoring, and file loading capabilities.
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
- **Color Management**: Comprehensive color handling with support for AutoCAD color indices and RGB values
|
|
12
|
+
- **Event System**: Event dispatching and management for decoupled communication between components
|
|
13
|
+
- **Logging**: Structured logging utilities with different log levels
|
|
14
|
+
- **Performance Monitoring**: Tools for collecting and analyzing performance metrics
|
|
15
|
+
- **File Loading**: Asynchronous file loading with progress tracking and error handling
|
|
16
|
+
- **Task Scheduling**: Background task management and scheduling capabilities
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @mlightcad/common
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Key Classes
|
|
25
|
+
|
|
26
|
+
### Color Management
|
|
27
|
+
- **AcCmColor**: Represents colors in AutoCAD format with support for color indices and RGB values
|
|
28
|
+
- **AcCmColorUtil**: Utility functions for color conversion and manipulation
|
|
29
|
+
|
|
30
|
+
### Event System
|
|
31
|
+
- **AcCmEventDispatcher**: Dispatches events to registered listeners
|
|
32
|
+
- **AcCmEventManager**: Manages event registration and dispatching across the application
|
|
33
|
+
|
|
34
|
+
### Logging and Utilities
|
|
35
|
+
- **AcCmLogUtil**: Structured logging with different log levels (debug, info, warn, error)
|
|
36
|
+
- **AcCmStringUtil**: String manipulation and formatting utilities
|
|
37
|
+
- **AcCmErrors**: Error handling and custom error types
|
|
38
|
+
|
|
39
|
+
### Performance and Tasks
|
|
40
|
+
- **AcCmPerformanceCollector**: Collects and analyzes performance metrics
|
|
41
|
+
- **AcCmTaskScheduler**: Manages background tasks and scheduling
|
|
42
|
+
|
|
43
|
+
### File Loading
|
|
44
|
+
- **AcCmFileLoader**: Handles asynchronous file loading with progress tracking
|
|
45
|
+
- **AcCmLoadingManager**: Manages multiple file loading operations
|
|
46
|
+
- **AcCmLoader**: Base class for implementing custom file loaders
|
|
47
|
+
|
|
48
|
+
### Base Classes
|
|
49
|
+
- **AcCmObject**: Base class for common objects with event handling capabilities
|
|
50
|
+
|
|
51
|
+
## Usage Examples
|
|
52
|
+
|
|
53
|
+
### Color Management
|
|
54
|
+
```typescript
|
|
55
|
+
import { AcCmColor, AcCmColorUtil } from '@mlightcad/common';
|
|
56
|
+
|
|
57
|
+
// Create a color from AutoCAD color index
|
|
58
|
+
const color = new AcCmColor(1); // Red
|
|
59
|
+
|
|
60
|
+
// Create a color from RGB values
|
|
61
|
+
const rgbColor = new AcCmColor(255, 0, 0);
|
|
62
|
+
|
|
63
|
+
// Convert between formats
|
|
64
|
+
const rgb = AcCmColorUtil.toRgb(color);
|
|
65
|
+
const index = AcCmColorUtil.toColorIndex(rgbColor);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Event Handling
|
|
69
|
+
```typescript
|
|
70
|
+
import { AcCmEventManager, AcCmEventDispatcher } from '@mlightcad/common';
|
|
71
|
+
|
|
72
|
+
// Create an event dispatcher
|
|
73
|
+
const dispatcher = new AcCmEventDispatcher();
|
|
74
|
+
|
|
75
|
+
// Register an event listener
|
|
76
|
+
dispatcher.addEventListener('fileLoaded', (event) => {
|
|
77
|
+
console.log('File loaded:', event.data);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Dispatch an event
|
|
81
|
+
dispatcher.dispatchEvent('fileLoaded', { fileName: 'drawing.dwg' });
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Logging
|
|
85
|
+
```typescript
|
|
86
|
+
import { AcCmLogUtil } from '@mlightcad/common';
|
|
87
|
+
|
|
88
|
+
// Configure logging
|
|
89
|
+
AcCmLogUtil.setLevel('info');
|
|
90
|
+
|
|
91
|
+
// Log messages
|
|
92
|
+
AcCmLogUtil.info('Application started');
|
|
93
|
+
AcCmLogUtil.warn('Deprecated feature used');
|
|
94
|
+
AcCmLogUtil.error('Failed to load file', error);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### File Loading
|
|
98
|
+
```typescript
|
|
99
|
+
import { AcCmFileLoader, AcCmLoadingManager } from '@mlightcad/common';
|
|
100
|
+
|
|
101
|
+
// Create a file loader
|
|
102
|
+
const loader = new AcCmFileLoader();
|
|
103
|
+
|
|
104
|
+
// Load a file with progress tracking
|
|
105
|
+
loader.load('drawing.dwg', {
|
|
106
|
+
onProgress: (progress) => {
|
|
107
|
+
console.log(`Loading: ${progress}%`);
|
|
108
|
+
},
|
|
109
|
+
onComplete: (data) => {
|
|
110
|
+
console.log('File loaded successfully');
|
|
111
|
+
},
|
|
112
|
+
onError: (error) => {
|
|
113
|
+
console.error('Failed to load file:', error);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Use loading manager for multiple files
|
|
118
|
+
const manager = new AcCmLoadingManager();
|
|
119
|
+
manager.addLoader(loader);
|
|
120
|
+
manager.start();
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Dependencies
|
|
124
|
+
|
|
125
|
+
- **loglevel**: For logging functionality
|
|
126
|
+
- **lodash-es**: For utility functions (peer dependency)
|
|
127
|
+
|
|
128
|
+
## API Documentation
|
|
129
|
+
|
|
130
|
+
For detailed API documentation, visit the [RealDWG-Web documentation](https://mlight-lee.github.io/realdwg-web/).
|
|
131
|
+
|
|
132
|
+
## Contributing
|
|
133
|
+
|
|
134
|
+
This package is part of the RealDWG-Web monorepo. Please refer to the main project README for contribution guidelines.
|