@libs-ui/components-minimap 0.2.355-9 → 0.2.356-1

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 (2) hide show
  1. package/README.md +90 -196
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,244 +1,138 @@
1
1
  # @libs-ui/components-minimap
2
2
 
3
- Directive tạo minimap (bản đồ thu nhỏ) để điều hướng nhanh trong nội dung thể cuộn lớn. Giúp người dùng dễ dàng xem tổng quan và di chuyển đến vị trí mong muốn trong một vùng nội dung lớn.
3
+ > Thêm bản đồ thu nhỏ (Minimap) cho các vùng chứa nội dung lớn hoặc cuộn.
4
4
 
5
- ## Tính năng
5
+ ## Giới thiệu
6
6
 
7
- **Minimap tự động**: Tạo bản đồ thu nhỏ của element thể cuộn
8
- • **Navigation tương tác**: Click và kéo thả để di chuyển viewport
9
- • **Tùy chỉnh style**: Cấu hình màu sắc, kích thước, vị trí minimap
10
- • **Responsive**: Tự động cập nhật khi nội dung thay đổi
11
- • **Performance tối ưu**: Sử dụng signal và RxJS cho hiệu suất cao
12
- • **Hỗ trợ scale**: Làm việc với element có transform scale
13
- • **Control functions**: API để show/hide/toggle minimap từ code
7
+ `LibsUiComponentsMinimapDirective` một standalone directive giúp tạo ra một trải nghiệm chuyển hướng trực quan cho người dùng trong các bảng vẽ (canvas), sơ đồ hoặc các vùng nội dung rộng lớn. Nó tự động theo dõi thay đổi trong DOM đồng bộ hóa vị trí cuộn giữa nội dung chính và bản đồ thu nhỏ.
14
8
 
15
- ## 📦 Cài đặt
9
+ ### Tính năng
16
10
 
17
- ```bash
18
- npm install @libs-ui/components-minimap
19
- ```
11
+ - ✅ **Standalone Directive**: Dễ dàng tích hợp vào bất kỳ phần tử nào có thuộc tính cuộn.
12
+ - **Đồng bộ hai chiều**: Cuộn nội dung chính cập nhật Minimap, kéo viewport trên Minimap cập nhật nội dung chính.
13
+ - ✅ **Theo dõi thay đổi**: Sử dụng `MutationObserver` để tự động cập nhật hình ảnh trên Minimap khi nội dung thay đổi.
14
+ - ✅ **Tùy biến cao**: Cho phép cấu hình vị trí, kích thước, màu sắc và z-index của cả Minimap và Viewport.
15
+ - ✅ **Hỗ trợ Scale**: Khả năng nhận diện tỷ lệ phóng to/thu nhỏ của nội dung để hiển thị chính xác.
20
16
 
21
- <button onclick="navigator.clipboard.writeText('npm install @libs-ui/components-minimap')" class="copy-btn">📋 Sao chép</button>
17
+ ## Khi nào sử dụng
18
+
19
+ - Khi có các vùng chứa nội dung lớn vượt quá kích thước màn hình (sơ đồ, bản đồ văn phòng, editor đồ họa).
20
+ - Khi người dùng cần cái nhìn tổng quan về cấu trúc nội dung và khả năng di chuyển nhanh chóng đến các vùng cụ thể.
21
+ - Thay thế hoặc hỗ trợ cho thanh cuộn truyền thống trên các giao diện phức tạp.
22
+
23
+ ## Cài đặt
22
24
 
23
25
  ```bash
26
+ # npm
27
+ npm install @libs-ui/components-minimap
28
+
29
+ # yarn
24
30
  yarn add @libs-ui/components-minimap
25
31
  ```
26
32
 
27
- <button onclick="navigator.clipboard.writeText('yarn add @libs-ui/components-minimap')" class="copy-btn">📋 Sao chép</button>
28
-
29
- ## 🚀 Sử dụng
30
-
31
- ### Ví dụ cơ bản (Inline Template)
33
+ ## Import
32
34
 
33
35
  ```typescript
34
- import { Component } from '@angular/core';
35
36
  import { LibsUiComponentsMinimapDirective } from '@libs-ui/components-minimap';
36
37
 
37
38
  @Component({
38
- selector: 'app-example',
39
39
  standalone: true,
40
40
  imports: [LibsUiComponentsMinimapDirective],
41
- template: `
42
- <div
43
- LibsUiComponentsMinimapDirective
44
- class="scrollable-content"
45
- style="width: 500px; height: 300px; overflow: auto;">
46
- <!-- Nội dung lớn cần minimap -->
47
- <div style="width: 1500px; height: 1000px; background: linear-gradient(45deg, #ff6b6b, #4ecdc4);">
48
- <h2>Nội dung rất lớn</h2>
49
- <p>Cuộn để xem minimap hoạt động...</p>
50
- </div>
51
- </div>
52
- `,
41
+ // ...
53
42
  })
54
- export class ExampleComponent {}
43
+ export class YourComponent {}
55
44
  ```
56
45
 
57
- ### Ví dụ với file HTML riêng
46
+ ## Ví dụ
58
47
 
59
- **Component:**
48
+ ### Cơ bản
60
49
 
61
- ```typescript
62
- import { Component } from '@angular/core';
63
- import { LibsUiComponentsMinimapDirective, IMiniMapFunctionControl, IMiniMapStyleConfig } from '@libs-ui/components-minimap';
64
-
65
- @Component({
66
- selector: 'app-minimap-demo',
67
- standalone: true,
68
- imports: [LibsUiComponentsMinimapDirective],
69
- templateUrl: './minimap-demo.component.html',
70
- styleUrls: ['./minimap-demo.component.scss'],
71
- })
72
- export class MinimapDemoComponent {
73
- // Cấu hình style cho minimap container
74
- minimapStyle: IMiniMapStyleConfig = {
75
- width: 250,
76
- height: 150,
77
- top: 20,
78
- right: 20,
79
- background: '#f8f9fa',
80
- border: '2px solid #007bff',
81
- borderRadius: 8,
82
- zIndex: 1500,
83
- };
84
-
85
- // Cấu hình style cho viewport rectangle
86
- viewportStyle: IMiniMapStyleConfig = {
87
- border: '2px solid #ff6b6b',
88
- background: 'rgba(255, 107, 107, 0.1)',
89
- borderRadius: 4,
90
- };
91
-
92
- minimapControls: IMiniMapFunctionControl | null = null;
93
-
94
- // Nhận function controls từ directive
95
- onMinimapReady(controls: IMiniMapFunctionControl) {
96
- this.minimapControls = controls;
97
- }
98
-
99
- // Các method điều khiển minimap
100
- showMinimap() {
101
- this.minimapControls?.show();
102
- }
103
-
104
- hideMinimap() {
105
- this.minimapControls?.hidden();
106
- }
107
-
108
- toggleMinimap() {
109
- this.minimapControls?.toggle();
110
- }
111
- }
50
+ ```html
51
+ <div
52
+ class="w-full h-[500px] overflow-auto"
53
+ LibsUiComponentsMinimapDirective>
54
+ <!-- Nội dung lớn ở đây -->
55
+ <div class="w-[2000px] h-[2000px]">...</div>
56
+ </div>
112
57
  ```
113
58
 
114
- **Template (minimap-demo.component.html):**
59
+ ### Với cấu hình Styles và Controls
115
60
 
116
61
  ```html
117
- <div class="demo-container">
118
- <!-- Control buttons -->
119
- <div class="controls mb-3">
120
- <button
121
- (click)="showMinimap()"
122
- class="btn btn-success me-2">
123
- Hiện Minimap
124
- </button>
125
- <button
126
- (click)="hideMinimap()"
127
- class="btn btn-warning me-2">
128
- Ẩn Minimap
129
- </button>
130
- <button
131
- (click)="toggleMinimap()"
132
- class="btn btn-info">
133
- Toggle Minimap
134
- </button>
135
- </div>
136
-
137
- <!-- Scrollable content với minimap -->
138
- <div
139
- LibsUiComponentsMinimapDirective
140
- [styleImageElement]="minimapStyle"
141
- [styleRectangleElement]="viewportStyle"
142
- [timerStartDrawMinimap]="500"
143
- (outFunctionControls)="onMinimapReady($event)"
144
- class="scrollable-area"
145
- style="width: 600px; height: 400px; overflow: auto; border: 1px solid #ddd;">
146
- <!-- Large content -->
147
- <div
148
- class="large-content"
149
- style="width: 1200px; height: 800px; padding: 20px;">
150
- <h1>Nội dung lớn với Minimap</h1>
151
-
152
- <div
153
- class="mo-minimap-flag-element-scale"
154
- style="transform: scale(1.2);">
155
- <!-- Element có scale để test tính năng scale detection -->
156
- <div class="grid-content">
157
- <!-- Tạo grid content để dễ nhận biết vị trí -->
158
- <div
159
- *ngFor="let row of [1,2,3,4,5,6,7,8,9,10]"
160
- class="row"
161
- style="display: flex; margin: 10px 0;">
162
- <div
163
- *ngFor="let col of [1,2,3,4,5,6,7,8,9,10]"
164
- class="cell"
165
- style="width: 80px; height: 60px; border: 1px solid #ccc;
166
- margin: 2px; display: flex; align-items: center;
167
- justify-content: center; background: #f0f0f0;">
168
- {{row}}-{{col}}
169
- </div>
170
- </div>
171
- </div>
172
- </div>
173
- </div>
174
- </div>
62
+ <div
63
+ class="scroll-container"
64
+ LibsUiComponentsMinimapDirective
65
+ [styleImageElement]="{ bottom: 20, right: 20, width: 200, height: 120 }"
66
+ [styleRectangleElement]="{ border: '2px solid #3b82f6' }"
67
+ (outFunctionControls)="controls = $event">
68
+ ...
175
69
  </div>
70
+
71
+ <button (click)="controls.toggle()">Bật/Tắt Minimap</button>
176
72
  ```
177
73
 
178
- ## 🛠️ Công nghệ sử dụng
74
+ ## API
179
75
 
180
- - **Angular 18+**: Framework chính
181
- - **RxJS**: Quản lý events và reactive programming
182
- - **TypeScript**: Ngôn ngữ phát triển
183
- - **Signals**: Quản lý state hiện đại của Angular
76
+ ### [LibsUiComponentsMinimapDirective]
184
77
 
185
- ## 📖 API Reference
78
+ #### Inputs
186
79
 
187
- ### Inputs
80
+ | Property | Type | Default | Description |
81
+ | ----------------------------- | --------------------- | -------------------------------------- | ---------------------------------------------------- |
82
+ | `[elementScroll]` | `HTMLElement` | `Host Element` | Phần tử đích để theo dõi cuộn (nếu khác host). |
83
+ | `[styleImageElement]` | `IMiniMapStyleConfig` | `undefined` | Cấu hình phong cách và vị trí cho khung Minimap. |
84
+ | `[styleRectangleElement]` | `IMiniMapStyleConfig` | `undefined` | Cấu hình cho khung Viewport trên Minimap. |
85
+ | `[timerStartDrawMinimap]` | `number` | `250` | Thời gian chờ (ms) trước khi bắt đầu vẽ Minimap. |
86
+ | `[classNameFlagElementScale]` | `string` | `'libs-ui-minimap-flag-element-scale'` | Class name để xác định phần tử chứa scale transform. |
188
87
 
189
- | Tên | Kiểu | Mặc định | Mô tả |
190
- | --------------------------- | --------------------- | --------------------------------- | ------------------------------------------------------------- |
191
- | `classNameFlagElementScale` | `string` | `'mo-minimap-flag-element-scale'` | Class name của element có scale transform để directive detect |
192
- | `timerStartDrawMinimap` | `number` | `250` | Thời gian delay (ms) trước khi bắt đầu vẽ minimap |
193
- | `elementScroll` | `HTMLElement` | `undefined` | Element cuộn tùy chỉnh (mặc định dùng host element) |
194
- | `styleRectangleElement` | `IMiniMapStyleConfig` | `undefined` | Cấu hình style cho viewport rectangle |
195
- | `styleImageElement` | `IMiniMapStyleConfig` | `undefined` | Cấu hình style cho minimap container |
88
+ #### Outputs
196
89
 
197
- ### Outputs
90
+ | Property | Type | Description |
91
+ | ----------------------- | --------------------------------------- | ---------------------------------------------------- |
92
+ | `(outFunctionControls)` | `EventEmitter<IMiniMapFunctionControl>` | Phát ra bộ điều khiển để điều khiển Minimap từ code. |
198
93
 
199
- | Tên | Kiểu | Mô tả |
200
- | --------------------- | ------------------------- | ------------------------------------------------ |
201
- | `outFunctionControls` | `IMiniMapFunctionControl` | Emit object chứa các function để control minimap |
94
+ #### Methods (via Controls)
202
95
 
203
- ### Interfaces
96
+ | Method | Parameters | Description |
97
+ | ---------- | ---------- | ------------------------------- |
98
+ | `show()` | `-` | Hiển thị Minimap. |
99
+ | `hidden()` | `-` | Ẩn Minimap. |
100
+ | `toggle()` | `-` | Chuyển đổi trạng thái hiển thị. |
204
101
 
205
- #### `IMiniMapStyleConfig`
102
+ ## Types & Interfaces
206
103
 
207
104
  ```typescript
208
- interface IMiniMapStyleConfig {
209
- x?: number; // Vị trí x (không sử dụng)
210
- y?: number; // Vị trí y (không sử dụng)
211
- width?: number; // Chiều rộng minimap (px)
212
- height?: number; // Chiều cao minimap (px)
213
- zIndex?: number; // Z-index layer
214
- border?: string; // CSS border
215
- borderRadius?: number; // CSS border-radius (px)
216
- background?: string; // CSS background
217
- top?: number; // Vị trí top (px)
218
- left?: number; // Vị trí left (px)
219
- bottom?: number; // Vị trí bottom (px) - ưu tiên hơn top
220
- right?: number; // Vị trí right (px) - ưu tiên hơn left
105
+ export interface IMiniMapStyleConfig {
106
+ zIndex?: number;
107
+ border?: string;
108
+ borderRadius?: number;
109
+ background?: string;
110
+ top?: number;
111
+ left?: number;
112
+ bottom?: number;
113
+ right?: number;
114
+ width?: number;
115
+ height?: number;
116
+ x?: number;
117
+ y?: number;
221
118
  }
222
- ```
223
-
224
- Cấu hình style cho minimap container hoặc viewport rectangle. Tất cả thuộc tính đều optional.
225
119
 
226
- #### `IMiniMapFunctionControl`
227
-
228
- ```typescript
229
- interface IMiniMapFunctionControl {
230
- show: () => void; // Hiển thị minimap
231
- hidden: () => void; // Ẩn minimap
232
- toggle: () => void; // Toggle hiển thị/ẩn minimap
120
+ export interface IMiniMapFunctionControl {
121
+ show: () => void;
122
+ hidden: () => void;
123
+ toggle: () => void;
233
124
  }
234
125
  ```
235
126
 
236
- Object chứa các function để điều khiển minimap từ code. Nhận được qua output `outFunctionControls`.
127
+ ## Công nghệ
128
+
129
+ | Technology | Purpose |
130
+ | ---------------- | ------------------------- |
131
+ | Angular 18+ | Framework chính |
132
+ | Angular Signals | Quản lý trạng thái nội bộ |
133
+ | MutationObserver | Theo dõi thay đổi DOM |
134
+ | DOM Cloning | Tạo hình ảnh thu nhỏ |
237
135
 
238
- ## 💡 Lưu ý
136
+ ## License
239
137
 
240
- - Directive tự động tạo minimap container và thêm vào `document.body`
241
- - Sử dụng class `mo-minimap-flag-element-scale` để đánh dấu element có scale transform
242
- - Minimap tự động cập nhật khi nội dung hoặc kích thước thay đổi
243
- - Viewport rectangle có thể click và kéo thả để điều hướng
244
- - Memory được quản lý tự động, tự cleanup khi component destroy
138
+ MIT
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@libs-ui/components-minimap",
3
- "version": "0.2.355-9",
3
+ "version": "0.2.356-1",
4
4
  "peerDependencies": {
5
5
  "@angular/core": ">=18.0.0",
6
- "@libs-ui/interfaces-types": "0.2.355-9",
7
- "@libs-ui/utils": "0.2.355-9",
6
+ "@libs-ui/interfaces-types": "0.2.356-1",
7
+ "@libs-ui/utils": "0.2.356-1",
8
8
  "rxjs": "~7.8.0"
9
9
  },
10
10
  "sideEffects": false,