leafer-x-tooltip-canvas 1.0.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) 2024 214L
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.en.md ADDED
@@ -0,0 +1,394 @@
1
+ # leafer-x-tooltip-canvas
2
+
3
+ <p>
4
+ English | <a href="./README.md">简体中文</a>
5
+ </p>
6
+
7
+ ## Introduction
8
+
9
+ leafer-x-tooltip-canvas is a third-party tooltip plugin for [Leafer-ui](https://leaferjs.com/ui/), designed to display information to users.
10
+
11
+ <!-- - [在线体验(尚未完成)]() -->
12
+
13
+ ## Quick Start
14
+
15
+ ### Installation
16
+
17
+ ```node
18
+ npm i leafer-x-tooltip-canvas --save
19
+ ```
20
+
21
+ ### Usage
22
+
23
+ When using the plugin, create an instance of the plugin and pass in an App or Leafer instance. (It is recommended to use App)
24
+
25
+ If an App is passed in, the popup will be drawn in the sky layer. If a Leafer is passed in, the popup will be drawn in the Leafer layer that is passed in.
26
+
27
+ > Note: If the sky layer has not been created when passing in App, it will be automatically created.
28
+
29
+ ```js
30
+ import { TooltipPlugin } from 'leafer-x-tooltip-canvas'
31
+ const app = new App({ view: window })
32
+ const plugin = new TooltipPlugin(app)
33
+ ```
34
+
35
+ ### Config overview
36
+
37
+ Config can be passed as the second parameter when creating an instance of tooltipPlugin.
38
+
39
+ ```js
40
+ new TooltipPlugin(app, {
41
+ info: ['width', 'height', 'innerId'],
42
+ includesType: ['Rect'],
43
+ excludesType: [],
44
+ ...
45
+ })
46
+ ```
47
+
48
+ The specific config options are as follows. Click on the field name to jump to [Config Details](#Config details)
49
+
50
+ <table class="styled-table jump-table">
51
+ <thead>
52
+ <tr>
53
+ <th>Field</th>
54
+ <th>Type</th>
55
+ <th>Default</th>
56
+ <th>Description</th>
57
+ </tr>
58
+ </thead>
59
+ <tbody>
60
+ <tr>
61
+ <td><a href="#display-information">info</a></td>
62
+ <td>Array&lt;string&gt;</td>
63
+ <td>['tag']</td>
64
+ <td>The attribute fields to be displayed</td>
65
+ </tr>
66
+ <tr>
67
+ <td><a href="#display-type">showType</a></td>
68
+ <td>'value'&#124;'key-value'</td>
69
+ <td>'value'</td>
70
+ <td>The way tooltip information is displayed</td>
71
+ </tr>
72
+ <tr>
73
+ <td><a href="#formatter">formatter</a></td>
74
+ <td>() => string</td>
75
+ <td>() => undefined</td>
76
+ <td>The function to format the content displayed in the tooltip</td>
77
+ </tr>
78
+ <tr>
79
+ <td><a href="#delayed-displayhide">showDelay</a></td>
80
+ <td>number</td>
81
+ <td>500</td>
82
+ <td>The time in milliseconds to delay before showing the tooltip</td>
83
+ </tr>
84
+ <tr>
85
+ <td><a href="#delayed-displayhide">hideDelay</a></td>
86
+ <td>number</td>
87
+ <td>0</td>
88
+ <td>The time in milliseconds to delay before hiding the tooltip</td>
89
+ </tr>
90
+ <tr>
91
+ <td><a href="#includeexclude-types">includesType</a></td>
92
+ <td>Array&lt;string&gt;</td>
93
+ <td>[]</td>
94
+ <td>The tags of elements that need to display the tooltip</td>
95
+ </tr>
96
+ <tr>
97
+ <td><a href="#includeexclude-types">excludesType</a></td>
98
+ <td>Array&lt;string&gt;</td>
99
+ <td>[]</td>
100
+ <td>The tags of elements that should not display the tooltip</td>
101
+ </tr>
102
+ <tr>
103
+ <td><a href="#offset">offset</a></td>
104
+ <td>Array&lt;number&gt;</td>
105
+ <td>[5, 5]</td>
106
+ <td>The offset of the tooltip relative to the position</td>
107
+ </tr>
108
+ <tr>
109
+ <td><a href="#lightdark-themes">theme</a></td>
110
+ <td>string</td>
111
+ <td>'light'</td>
112
+ <td>The theme of the tooltip, with the options being 'light' and 'dark'</td>
113
+ </tr>
114
+ <tr>
115
+ <td><a href="#style">style</a></td>
116
+ <td>IStyle</td>
117
+ <td>see below</td>
118
+ <td>The style configuration for the tooltip</td>
119
+ </tr>
120
+ </tbody>
121
+ </table>
122
+
123
+
124
+
125
+ IStyle Properties
126
+ <table class="styled-table">
127
+ <tr>
128
+ <th>Field</th>
129
+ <th>Type</th>
130
+ <th>Default</th>
131
+ <th>Description</th>
132
+ </tr>
133
+ <tr>
134
+ <td>backgroundColor</td>
135
+ <td>string</td>
136
+ <td>"white"</td>
137
+ <td>The background color of the tooltip</td>
138
+ </tr>
139
+ <tr>
140
+ <td>stroke</td>
141
+ <td>string</td>
142
+ <td>"black"</td>
143
+ <td>The border color of the tooltip</td>
144
+ </tr>
145
+ <tr>
146
+ <td>color</td>
147
+ <td>string</td>
148
+ <td>"black"</td>
149
+ <td>The text color of the tooltip</td>
150
+ </tr>
151
+ <tr>
152
+ <td>borderRadius</td>
153
+ <td>number</td>
154
+ <td>8</td>
155
+ <td>The border radius of the tooltip for rounded corners</td>
156
+ </tr>
157
+ <tr>
158
+ <td>padding</td>
159
+ <td>number</td>
160
+ <td>8</td>
161
+ <td>The padding inside the tooltip</td>
162
+ </tr>
163
+ <tr>
164
+ <td>fontSize</td>
165
+ <td>number</td>
166
+ <td>14</td>
167
+ <td>The font size of the tooltip text</td>
168
+ </tr>
169
+ <tr>
170
+ <td>fontWeight</td>
171
+ <td>number</td>
172
+ <td>400</td>
173
+ <td>The font weight of the tooltip text, where 400 is normal and 700 is bold</td>
174
+ </tr>
175
+ <tr>
176
+ <td>fontFamily</td>
177
+ <td>string</td>
178
+ <td>"Punctuation SC"</td>
179
+ <td>The font family of the tooltip text, which can include multiple fonts separated by commas, similar to CSS font-family styling</td>
180
+ </tr>
181
+ </table>
182
+
183
+ ### Todo
184
+
185
+ - Display/Hide
186
+ - [x] Basic Display/Hide
187
+ - [x] Delayed Display/Hide
188
+ - Style
189
+ - [ ] Triangle Arrow
190
+ - [x] Light/Dark Themes
191
+ - [x] Custom Style
192
+ - Position
193
+ - [x] offset
194
+ - [x] Custom Style
195
+ - [ ] Relative to Element Position
196
+ - [ ] Display Avoidance
197
+ - Information
198
+ - [x] Custom Information
199
+ - [x] formatter
200
+ - Interaction
201
+ - [x] Include/Exclude Type Function
202
+ - [ ] Trigger Method
203
+ - [ ] Virtual Trigger
204
+
205
+ ### Config details
206
+ <a href="#config-overview" class="fixed-right">:dizzy:Config Overview</a>
207
+
208
+ #### Content
209
+ ##### Display Information
210
+ Configure the displayed attribute fields by passing in the `info` field.
211
+ <table class="center-table">
212
+ <tr>
213
+ <td>
214
+ <span>info : ['tag','width','height']</span>
215
+ </td>
216
+ <td>
217
+ <img src="./.github/assets/info.png">
218
+ </td>
219
+ </tr>
220
+ </table>
221
+
222
+ ##### Display Type
223
+ Configure the display method of the information, there are two types: `value`,`key-value`.
224
+ <table class="center-table">
225
+ <tr>
226
+ <td>
227
+ <span>showType : 'value'</span>
228
+ </td>
229
+ <td>
230
+ <img src="./.github/assets/value.png">
231
+ </td>
232
+ </tr>
233
+ <tr>
234
+ <td>
235
+ <span>showType : 'key-value'</span>
236
+ </td>
237
+ <td>
238
+ <img src="./.github/assets/key-value.png">
239
+ </td>
240
+ </tr>
241
+ </table>
242
+
243
+ ##### Formatter
244
+ Configure the formatting function for the information, the parameter is the attribute collection of the element being acted upon. The returned value serves as the text for the tooltip.
245
+
246
+ ```js
247
+ formatter: (item) => {
248
+ return `${item.tag}(${item.innerId})`
249
+ }
250
+ ```
251
+ <img src="./.github/assets/formatter.png">
252
+
253
+ #### Display/Hide
254
+ ##### Delayed Display/Hide
255
+ Configure the delay time for display and the delay time for hiding.
256
+ <table class="center-table">
257
+ <tr>
258
+ <td>
259
+ <span>showDelay : 500</span>
260
+ </td>
261
+ <td>
262
+ <img src="./.github/assets/show-delay.gif">
263
+ </td>
264
+ </tr>
265
+ <tr>
266
+ <td>
267
+ <span>hideDelay : 500</span>
268
+ </td>
269
+ <td>
270
+ <img src="./.github/assets/hide-delay.gif">
271
+ </td>
272
+ </tr>
273
+ </table>
274
+
275
+ #### Interaction
276
+ ##### Include/Exclude Types
277
+ Configure the element tags to be displayed/hidden by setting the `includesType` and `excludesType` property.
278
+
279
+ - When only `includesType` is configured, only the elements configured in `includesType` are displayed.
280
+ - When only `excludesType` is configured, only the elements configured in `excludesType` are not displayed.
281
+ - Both `includesType` and `excludesType` can be configured at the same time.
282
+ - The priority of `includesType` is higher than `excludesType`.
283
+ <table class="center-table">
284
+ <tr>
285
+ <td>
286
+ <span>includesType : ['Rect']</span>
287
+ </td>
288
+ <td>
289
+ <img src="./.github/assets/includes-type.gif">
290
+ </td>
291
+ </tr>
292
+ </table>
293
+
294
+
295
+ #### Style
296
+ ##### Light/Dark Themes
297
+ The plugin provides two themes by default, `light` and `dark`, which can be switched by configuring the theme field. The default theme is light.
298
+ <table class="center-table">
299
+ <tr>
300
+ <td>
301
+ <span>theme : 'light'</span>
302
+ </td>
303
+ <td>
304
+ <img src="./.github/assets/light-theme.png">
305
+ </td>
306
+ </tr>
307
+ <tr>
308
+ <td>
309
+ <span>theme : 'dark'</span>
310
+ </td>
311
+ <td>
312
+ <img src="./.github/assets/dark-theme.png">
313
+ </td>
314
+ </tr>
315
+ </table>
316
+
317
+ #### Position
318
+ ##### Offset
319
+ Configure the offset of the tooltip relative to the mouse position, the first parameter is the offset on the x-axis, and the second parameter is the offset on the y-axis.
320
+ <table class="center-table">
321
+ <tr>
322
+ <td>
323
+ <span>offset : [10,20]</span>
324
+ </td>
325
+ <td>
326
+ <img src="./.github/assets/offset-10-20.png">
327
+ </td>
328
+ </tr>
329
+ </table>
330
+
331
+ ##### Custom Style
332
+ Users can customize the style by configuring the `style` field.
333
+ <table class="center-table">
334
+ </table>
335
+ <tr>
336
+ <td>
337
+ <span>
338
+
339
+ style: {
340
+ backgroundColor: '#32cd79',
341
+ stroke: '#32cd79',
342
+ color: 'white',
343
+ borderRadius: 16,
344
+ padding: 8,
345
+ fontSize: 16,
346
+ fontWeight: 400,
347
+ }
348
+ </span>
349
+ </td>
350
+ <td>
351
+ <img src="./.github/assets/style.png">
352
+ </td>
353
+ </tr>
354
+ </table>
355
+
356
+
357
+ [Github](https://github.com/214L/leafer-x-popup-canvas)
358
+
359
+
360
+ <style>
361
+ .center-table {
362
+ margin-left: auto;
363
+ margin-right: auto;
364
+ }
365
+ .center-table td {
366
+ border: 0px;
367
+ }
368
+ .center-table span {
369
+ background-color: rgb(220,220,220);
370
+ padding: 2px 5px 2px 5px;
371
+ }
372
+
373
+ .styled-table {
374
+ width: 100%;
375
+ border-collapse: collapse;
376
+ text-align: center; /* 文字居中 */
377
+ }
378
+ .styled-table th, .styled-table td {
379
+ border: 1px solid #ddd; /* 边框颜色 */
380
+ padding: 8px; /* 单元格内边距 */
381
+ }
382
+ .styled-table tr:nth-child(even) {
383
+ background-color: #f2f2f2; /* 斑马格效果 */
384
+ }
385
+ .jump-table th:first-child:hover, .styled-table td:first-child:hover {
386
+ cursor: pointer;
387
+ }
388
+ .fixed-right {
389
+ position: fixed;
390
+ bottom: 20%;
391
+ right: 10px;
392
+ transform: translateY(-50%);
393
+ }**
394
+ </style>