@destyler/tooltip 0.0.1-beta.5 → 0.0.1-beta.7
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/dist/index.cjs +631 -74
- package/dist/index.d.cts +903 -140
- package/dist/index.d.mts +903 -140
- package/dist/index.d.ts +903 -140
- package/dist/index.mjs +605 -74
- package/package.json +10 -4
package/dist/index.cjs
CHANGED
|
@@ -1,115 +1,672 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const vue = require('vue');
|
|
4
|
-
const
|
|
4
|
+
const primitive = require('@destyler/primitive');
|
|
5
|
+
const popper = require('@destyler/popper');
|
|
6
|
+
const composition = require('@destyler/composition');
|
|
7
|
+
const shared = require('@destyler/shared');
|
|
8
|
+
const core = require('@vueuse/core');
|
|
9
|
+
const dismissableLayer = require('@destyler/dismissable-layer');
|
|
10
|
+
const visuallyHidden = require('@destyler/visually-hidden');
|
|
11
|
+
const teleport = require('@destyler/teleport');
|
|
5
12
|
|
|
6
|
-
const
|
|
13
|
+
const destylerTooltipArrowProps = {
|
|
14
|
+
...primitive.destylerPrimitiveProps,
|
|
15
|
+
width: {
|
|
16
|
+
type: Number,
|
|
17
|
+
required: false,
|
|
18
|
+
default: 10
|
|
19
|
+
},
|
|
20
|
+
height: {
|
|
21
|
+
type: Number,
|
|
22
|
+
required: false,
|
|
23
|
+
default: 5
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const DestylerTooltipArrow = vue.defineComponent({
|
|
27
|
+
name: "DestylerTooltipArrow",
|
|
28
|
+
props: destylerTooltipArrowProps,
|
|
29
|
+
render() {
|
|
30
|
+
return vue.h(popper.DestylerPopperArrow, vue.mergeProps(this.$props), this.$slots.default?.());
|
|
31
|
+
}
|
|
32
|
+
});
|
|
7
33
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
34
|
+
const destylerTooltipProviderProps = {
|
|
35
|
+
delayDuration: {
|
|
36
|
+
type: Number,
|
|
37
|
+
required: false,
|
|
38
|
+
default: 700
|
|
39
|
+
},
|
|
40
|
+
skipDelayDuration: {
|
|
41
|
+
type: Number,
|
|
42
|
+
required: false,
|
|
43
|
+
default: 300
|
|
44
|
+
},
|
|
45
|
+
disableHoverableContent: {
|
|
46
|
+
type: Boolean,
|
|
47
|
+
required: false,
|
|
48
|
+
default: false
|
|
49
|
+
},
|
|
50
|
+
disableClosingTrigger: {
|
|
51
|
+
type: Boolean,
|
|
52
|
+
required: false,
|
|
53
|
+
default: false
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const [injectTooltipProviderContext, provideTooltipProviderContext] = shared.createContext("DestylerTooltipProvider");
|
|
57
|
+
const DestylerTooltipProvider = vue.defineComponent({
|
|
58
|
+
name: "DestylerTooltipProvider",
|
|
59
|
+
props: destylerTooltipProviderProps,
|
|
60
|
+
setup(props) {
|
|
61
|
+
const { delayDuration, skipDelayDuration, disableHoverableContent, disableClosingTrigger } = vue.toRefs(props);
|
|
62
|
+
const isOpenDelayed = vue.ref(true);
|
|
63
|
+
const isPointerInTransitRef = vue.ref(false);
|
|
64
|
+
const { start: startTimer, stop: clearTimer } = composition.useTimeoutFn(() => {
|
|
65
|
+
isOpenDelayed.value = true;
|
|
66
|
+
}, skipDelayDuration, { immediate: false });
|
|
67
|
+
provideTooltipProviderContext({
|
|
68
|
+
isOpenDelayed,
|
|
69
|
+
delayDuration,
|
|
70
|
+
onOpen() {
|
|
71
|
+
clearTimer();
|
|
72
|
+
isOpenDelayed.value = false;
|
|
73
|
+
},
|
|
74
|
+
onClose() {
|
|
75
|
+
startTimer();
|
|
76
|
+
},
|
|
77
|
+
isPointerInTransitRef,
|
|
78
|
+
onPointerInTransitChange(inTransit) {
|
|
79
|
+
isPointerInTransitRef.value = inTransit;
|
|
80
|
+
},
|
|
81
|
+
disableHoverableContent,
|
|
82
|
+
disableClosingTrigger
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
render() {
|
|
86
|
+
return this.$slots.default?.();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const TOOLTIP_OPEN = "tooltip.open";
|
|
91
|
+
function getExitSideFromRect(point, rect) {
|
|
92
|
+
const top = Math.abs(rect.top - point.y);
|
|
93
|
+
const bottom = Math.abs(rect.bottom - point.y);
|
|
94
|
+
const right = Math.abs(rect.right - point.x);
|
|
95
|
+
const left = Math.abs(rect.left - point.x);
|
|
96
|
+
switch (Math.min(top, bottom, right, left)) {
|
|
97
|
+
case left:
|
|
98
|
+
return "left";
|
|
99
|
+
case right:
|
|
100
|
+
return "right";
|
|
101
|
+
case top:
|
|
102
|
+
return "top";
|
|
103
|
+
case bottom:
|
|
104
|
+
return "bottom";
|
|
105
|
+
default:
|
|
106
|
+
throw new Error("unreachable");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function getPaddedExitPoints(exitPoint, exitSide, padding = 5) {
|
|
110
|
+
const paddedExitPoints = [];
|
|
111
|
+
switch (exitSide) {
|
|
112
|
+
case "top":
|
|
113
|
+
paddedExitPoints.push(
|
|
114
|
+
{ x: exitPoint.x - padding, y: exitPoint.y + padding },
|
|
115
|
+
{ x: exitPoint.x + padding, y: exitPoint.y + padding }
|
|
116
|
+
);
|
|
117
|
+
break;
|
|
118
|
+
case "bottom":
|
|
119
|
+
paddedExitPoints.push(
|
|
120
|
+
{ x: exitPoint.x - padding, y: exitPoint.y - padding },
|
|
121
|
+
{ x: exitPoint.x + padding, y: exitPoint.y - padding }
|
|
122
|
+
);
|
|
123
|
+
break;
|
|
124
|
+
case "left":
|
|
125
|
+
paddedExitPoints.push(
|
|
126
|
+
{ x: exitPoint.x + padding, y: exitPoint.y - padding },
|
|
127
|
+
{ x: exitPoint.x + padding, y: exitPoint.y + padding }
|
|
128
|
+
);
|
|
129
|
+
break;
|
|
130
|
+
case "right":
|
|
131
|
+
paddedExitPoints.push(
|
|
132
|
+
{ x: exitPoint.x - padding, y: exitPoint.y - padding },
|
|
133
|
+
{ x: exitPoint.x - padding, y: exitPoint.y + padding }
|
|
134
|
+
);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
return paddedExitPoints;
|
|
138
|
+
}
|
|
139
|
+
function getPointsFromRect(rect) {
|
|
140
|
+
const { top, right, bottom, left } = rect;
|
|
141
|
+
return [
|
|
142
|
+
{ x: left, y: top },
|
|
143
|
+
{ x: right, y: top },
|
|
144
|
+
{ x: right, y: bottom },
|
|
145
|
+
{ x: left, y: bottom }
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
function isPointInPolygon(point, polygon) {
|
|
149
|
+
const { x, y } = point;
|
|
150
|
+
let inside = false;
|
|
151
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
152
|
+
const xi = polygon[i].x;
|
|
153
|
+
const yi = polygon[i].y;
|
|
154
|
+
const xj = polygon[j].x;
|
|
155
|
+
const yj = polygon[j].y;
|
|
156
|
+
const intersect = yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
|
|
157
|
+
if (intersect)
|
|
158
|
+
inside = !inside;
|
|
159
|
+
}
|
|
160
|
+
return inside;
|
|
161
|
+
}
|
|
162
|
+
function getHull(points) {
|
|
163
|
+
const newPoints = points.slice();
|
|
164
|
+
newPoints.sort((a, b) => {
|
|
165
|
+
if (a.x < b.x)
|
|
166
|
+
return -1;
|
|
167
|
+
else if (a.x > b.x)
|
|
168
|
+
return 1;
|
|
169
|
+
else if (a.y < b.y)
|
|
170
|
+
return -1;
|
|
171
|
+
else if (a.y > b.y)
|
|
172
|
+
return 1;
|
|
173
|
+
else
|
|
174
|
+
return 0;
|
|
175
|
+
});
|
|
176
|
+
return getHullPresorted(newPoints);
|
|
177
|
+
}
|
|
178
|
+
function getHullPresorted(points) {
|
|
179
|
+
if (points.length <= 1)
|
|
180
|
+
return points.slice();
|
|
181
|
+
const upperHull = [];
|
|
182
|
+
for (let i = 0; i < points.length; i++) {
|
|
183
|
+
const p = points[i];
|
|
184
|
+
while (upperHull.length >= 2) {
|
|
185
|
+
const q = upperHull[upperHull.length - 1];
|
|
186
|
+
const r = upperHull[upperHull.length - 2];
|
|
187
|
+
if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x))
|
|
188
|
+
upperHull.pop();
|
|
189
|
+
else
|
|
190
|
+
break;
|
|
15
191
|
}
|
|
16
|
-
|
|
192
|
+
upperHull.push(p);
|
|
193
|
+
}
|
|
194
|
+
upperHull.pop();
|
|
195
|
+
const lowerHull = [];
|
|
196
|
+
for (let i = points.length - 1; i >= 0; i--) {
|
|
197
|
+
const p = points[i];
|
|
198
|
+
while (lowerHull.length >= 2) {
|
|
199
|
+
const q = lowerHull[lowerHull.length - 1];
|
|
200
|
+
const r = lowerHull[lowerHull.length - 2];
|
|
201
|
+
if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x))
|
|
202
|
+
lowerHull.pop();
|
|
203
|
+
else
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
lowerHull.push(p);
|
|
207
|
+
}
|
|
208
|
+
lowerHull.pop();
|
|
209
|
+
if (upperHull.length === 1 && lowerHull.length === 1 && upperHull[0].x === lowerHull[0].x && upperHull[0].y === lowerHull[0].y)
|
|
210
|
+
return upperHull;
|
|
211
|
+
else
|
|
212
|
+
return upperHull.concat(lowerHull);
|
|
17
213
|
}
|
|
18
214
|
|
|
19
|
-
const
|
|
20
|
-
|
|
215
|
+
const destylerTooltipRootProps = {
|
|
216
|
+
defaultOpen: {
|
|
21
217
|
type: Boolean,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"defaultShow": {
|
|
25
|
-
type: Boolean
|
|
218
|
+
required: false,
|
|
219
|
+
default: false
|
|
26
220
|
},
|
|
27
|
-
|
|
28
|
-
type:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"delay": {
|
|
32
|
-
type: Number,
|
|
33
|
-
default: 100
|
|
221
|
+
open: {
|
|
222
|
+
type: Boolean,
|
|
223
|
+
required: false,
|
|
224
|
+
default: void 0
|
|
34
225
|
},
|
|
35
|
-
|
|
226
|
+
delayDuration: {
|
|
36
227
|
type: Number,
|
|
37
|
-
|
|
228
|
+
required: false,
|
|
229
|
+
default: 400
|
|
38
230
|
},
|
|
39
|
-
|
|
40
|
-
type:
|
|
231
|
+
disableHoverableContent: {
|
|
232
|
+
type: Boolean,
|
|
233
|
+
required: false,
|
|
234
|
+
default: void 0
|
|
41
235
|
},
|
|
42
|
-
|
|
43
|
-
type:
|
|
236
|
+
disableClosingTrigger: {
|
|
237
|
+
type: Boolean,
|
|
238
|
+
required: false,
|
|
239
|
+
default: void 0
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
const [injectTooltipRootContext, provideTooltipRootContext] = shared.createContext("DestylerTooltipRoot");
|
|
243
|
+
const DestylerTooltipRoot = vue.defineComponent({
|
|
244
|
+
name: "DestylerTooltipRoot",
|
|
245
|
+
props: destylerTooltipRootProps,
|
|
246
|
+
emits: ["update:open"],
|
|
247
|
+
setup(props, { emit }) {
|
|
248
|
+
const providerContext = injectTooltipProviderContext();
|
|
249
|
+
const disableHoverableContent = vue.computed(() => {
|
|
250
|
+
return props.disableHoverableContent ?? providerContext.disableHoverableContent.value;
|
|
251
|
+
});
|
|
252
|
+
const disableClosingTrigger = vue.computed(() => props.disableClosingTrigger ?? providerContext.disableClosingTrigger.value);
|
|
253
|
+
const delayDuration = vue.computed(() => props.delayDuration ?? providerContext.delayDuration.value);
|
|
254
|
+
const openRef = composition.useVModel(props, "open", emit, {
|
|
255
|
+
defaultValue: props.defaultOpen,
|
|
256
|
+
passive: props.open === void 0
|
|
257
|
+
});
|
|
258
|
+
vue.watch(openRef, (isOpen) => {
|
|
259
|
+
if (!providerContext.onClose)
|
|
260
|
+
return;
|
|
261
|
+
if (isOpen) {
|
|
262
|
+
providerContext.onOpen();
|
|
263
|
+
document.dispatchEvent(new CustomEvent(TOOLTIP_OPEN));
|
|
264
|
+
} else {
|
|
265
|
+
providerContext.onClose();
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
const wasOpenDelayedRef = vue.ref(false);
|
|
269
|
+
const trigger = vue.ref();
|
|
270
|
+
const stateAttribute = vue.computed(() => {
|
|
271
|
+
if (!openRef.value)
|
|
272
|
+
return "closed";
|
|
273
|
+
return wasOpenDelayedRef.value ? "delayed-open" : "instant-open";
|
|
274
|
+
});
|
|
275
|
+
const { start: startTimer, stop: clearTimer } = composition.useTimeoutFn(() => {
|
|
276
|
+
wasOpenDelayedRef.value = true;
|
|
277
|
+
openRef.value = true;
|
|
278
|
+
}, delayDuration, { immediate: false });
|
|
279
|
+
function handleOpen() {
|
|
280
|
+
clearTimer();
|
|
281
|
+
wasOpenDelayedRef.value = false;
|
|
282
|
+
openRef.value = true;
|
|
283
|
+
}
|
|
284
|
+
function handleClose() {
|
|
285
|
+
clearTimer();
|
|
286
|
+
openRef.value = false;
|
|
287
|
+
}
|
|
288
|
+
function handleDelayedOpen() {
|
|
289
|
+
startTimer();
|
|
290
|
+
}
|
|
291
|
+
provideTooltipRootContext({
|
|
292
|
+
contentId: composition.useId(),
|
|
293
|
+
open: openRef,
|
|
294
|
+
stateAttribute,
|
|
295
|
+
trigger,
|
|
296
|
+
onTriggerChange(el) {
|
|
297
|
+
trigger.value = el;
|
|
298
|
+
},
|
|
299
|
+
onTriggerEnter() {
|
|
300
|
+
if (providerContext.isOpenDelayed.value)
|
|
301
|
+
handleDelayedOpen();
|
|
302
|
+
else
|
|
303
|
+
handleOpen();
|
|
304
|
+
},
|
|
305
|
+
onTriggerLeave() {
|
|
306
|
+
if (disableHoverableContent.value)
|
|
307
|
+
handleClose();
|
|
308
|
+
else
|
|
309
|
+
clearTimer();
|
|
310
|
+
},
|
|
311
|
+
onOpen: handleOpen,
|
|
312
|
+
onClose: handleClose,
|
|
313
|
+
disableHoverableContent,
|
|
314
|
+
disableClosingTrigger
|
|
315
|
+
});
|
|
44
316
|
},
|
|
45
|
-
|
|
46
|
-
|
|
317
|
+
render() {
|
|
318
|
+
return vue.h(popper.DestylerPopperRoot, this.$slots.default?.());
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
const destylerTooltipContentImplProps = {
|
|
323
|
+
...primitive.destylerPrimitiveProps,
|
|
324
|
+
side: {
|
|
325
|
+
type: String,
|
|
326
|
+
required: false,
|
|
327
|
+
default: "top"
|
|
47
328
|
},
|
|
48
|
-
|
|
49
|
-
type:
|
|
329
|
+
sideOffset: {
|
|
330
|
+
type: Number,
|
|
331
|
+
required: false,
|
|
332
|
+
default: 0
|
|
50
333
|
},
|
|
51
|
-
|
|
334
|
+
align: {
|
|
52
335
|
type: String,
|
|
53
|
-
|
|
336
|
+
required: false,
|
|
337
|
+
default: "center"
|
|
54
338
|
},
|
|
55
|
-
|
|
56
|
-
type: Number
|
|
339
|
+
alignOffset: {
|
|
340
|
+
type: Number,
|
|
341
|
+
required: false,
|
|
342
|
+
default: 0
|
|
57
343
|
},
|
|
58
|
-
|
|
59
|
-
type: Boolean
|
|
344
|
+
avoidCollisions: {
|
|
345
|
+
type: Boolean,
|
|
346
|
+
required: false,
|
|
347
|
+
default: true
|
|
60
348
|
},
|
|
61
|
-
|
|
62
|
-
type: Array,
|
|
349
|
+
collisionBoundary: {
|
|
350
|
+
type: [Object, Array, null],
|
|
351
|
+
required: false,
|
|
63
352
|
default: () => []
|
|
64
353
|
},
|
|
65
|
-
|
|
66
|
-
type:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
type: Function
|
|
354
|
+
collisionPadding: {
|
|
355
|
+
type: [Number, Object],
|
|
356
|
+
required: false,
|
|
357
|
+
default: 0
|
|
70
358
|
},
|
|
71
|
-
|
|
72
|
-
type:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
type: [Function, Array]
|
|
359
|
+
arrowPadding: {
|
|
360
|
+
type: Number,
|
|
361
|
+
required: false,
|
|
362
|
+
default: 0
|
|
76
363
|
},
|
|
77
|
-
|
|
78
|
-
type:
|
|
364
|
+
sticky: {
|
|
365
|
+
type: String,
|
|
366
|
+
required: false,
|
|
367
|
+
default: "partial"
|
|
79
368
|
},
|
|
80
|
-
|
|
81
|
-
type:
|
|
369
|
+
hideWhenDetached: {
|
|
370
|
+
type: Boolean,
|
|
371
|
+
required: false,
|
|
372
|
+
default: false
|
|
82
373
|
},
|
|
83
|
-
|
|
84
|
-
type:
|
|
374
|
+
ariaLabel: {
|
|
375
|
+
type: String,
|
|
376
|
+
required: false
|
|
85
377
|
}
|
|
86
378
|
};
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
379
|
+
const destylerTooltipContentImplEmits = ["escapeKeyDown", "pointerDownOutside"];
|
|
380
|
+
const DestylerTooltipContentImpl = vue.defineComponent({
|
|
381
|
+
name: "DestylerTooltipContentImpl",
|
|
382
|
+
props: destylerTooltipContentImplProps,
|
|
383
|
+
emits: destylerTooltipContentImplEmits,
|
|
90
384
|
setup(props) {
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
385
|
+
const contentElement = vue.ref();
|
|
386
|
+
const rootContext = injectTooltipRootContext();
|
|
387
|
+
const slot = vue.useSlots();
|
|
388
|
+
const defaultSlot = vue.computed(() => slot.default?.());
|
|
389
|
+
const ariaLabel = vue.computed(() => {
|
|
390
|
+
if (props.ariaLabel)
|
|
391
|
+
return props.ariaLabel;
|
|
392
|
+
let content = "";
|
|
393
|
+
function recursiveTextSearch(node) {
|
|
394
|
+
if (typeof node.children === "string")
|
|
395
|
+
content += node.children;
|
|
396
|
+
else if (Array.isArray(node.children))
|
|
397
|
+
node.children.forEach((child) => recursiveTextSearch(child));
|
|
398
|
+
}
|
|
399
|
+
defaultSlot.value?.forEach((node) => recursiveTextSearch(node));
|
|
400
|
+
return content;
|
|
401
|
+
});
|
|
402
|
+
const popperContentProps = vue.computed(() => {
|
|
403
|
+
const { ariaLabel: _, ...restProps } = props;
|
|
404
|
+
return restProps;
|
|
405
|
+
});
|
|
406
|
+
vue.onMounted(() => {
|
|
407
|
+
core.useEventListener(window, "scroll", (event) => {
|
|
408
|
+
const target = event.target;
|
|
409
|
+
if (target?.contains(rootContext.trigger.value))
|
|
410
|
+
rootContext.onClose();
|
|
411
|
+
});
|
|
412
|
+
core.useEventListener(window, TOOLTIP_OPEN, rootContext.onClose);
|
|
413
|
+
});
|
|
414
|
+
return {
|
|
415
|
+
contentElement,
|
|
416
|
+
rootContext,
|
|
417
|
+
popperContentProps,
|
|
418
|
+
ariaLabel
|
|
419
|
+
};
|
|
420
|
+
},
|
|
421
|
+
render() {
|
|
422
|
+
return vue.h(dismissableLayer.DestylerDismissableLayer, {
|
|
423
|
+
asChild: true,
|
|
424
|
+
disableOutsidePointerEvents: false,
|
|
425
|
+
onEscapeKeyDown: (event) => {
|
|
426
|
+
this.$emit("escapeKeyDown", event);
|
|
95
427
|
},
|
|
96
|
-
|
|
97
|
-
|
|
428
|
+
onPointerDownOutside: (event) => {
|
|
429
|
+
if (this.rootContext.disableClosingTrigger.value && this.rootContext.trigger.value?.contains(event.target))
|
|
430
|
+
event.preventDefault();
|
|
431
|
+
this.$emit("pointerDownOutside", event);
|
|
432
|
+
},
|
|
433
|
+
onDismiss: () => {
|
|
434
|
+
this.rootContext.onClose();
|
|
435
|
+
}
|
|
436
|
+
}, vue.h(popper.DestylerPopperContent, vue.mergeProps(this.$attrs, this.popperContentProps, {
|
|
437
|
+
"ref": "contentElement",
|
|
438
|
+
"data-state": this.rootContext.stateAttribute.value,
|
|
439
|
+
"style": {
|
|
440
|
+
"--destyler_tooltip_content_transform_origin": "var(--destyler_popper_transform_origin)",
|
|
441
|
+
"--destyler_tooltip_content_available_width": "var(--destyler_popper_available_width)",
|
|
442
|
+
"--destyler_tooltip_content_available_height": "var(--destyler_popper_available_height)",
|
|
443
|
+
"--destyler_tooltip_trigger_width": "var(--destyler_popper_anchor_width)",
|
|
444
|
+
"--destyler_tooltip_trigger_height": "var(--destyler_popper_anchor_height)"
|
|
445
|
+
}
|
|
446
|
+
}), [
|
|
447
|
+
this.$slots.default?.(),
|
|
448
|
+
vue.h(visuallyHidden.DestylerVisuallyhidden, {
|
|
449
|
+
role: "tooltip"
|
|
450
|
+
}, this.ariaLabel)
|
|
451
|
+
]));
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
const DestylerTooltipContentHoverable = vue.defineComponent({
|
|
456
|
+
name: "DestylerTooltipContentHoverable",
|
|
457
|
+
props: destylerTooltipContentImplProps,
|
|
458
|
+
setup() {
|
|
459
|
+
const { customElement, currentElement } = composition.useCustomElement();
|
|
460
|
+
const { trigger, onClose } = injectTooltipRootContext();
|
|
461
|
+
const providerContext = injectTooltipProviderContext();
|
|
462
|
+
const pointerGraceArea = vue.ref(null);
|
|
463
|
+
function handleRemoveGraceArea() {
|
|
464
|
+
pointerGraceArea.value = null;
|
|
465
|
+
providerContext.onPointerInTransitChange(false);
|
|
466
|
+
}
|
|
467
|
+
function handleCreateGraceArea(event, hoverTarget) {
|
|
468
|
+
const currentTarget = event.currentTarget;
|
|
469
|
+
const exitPoint = { x: event.clientX, y: event.clientY };
|
|
470
|
+
const exitSide = getExitSideFromRect(exitPoint, currentTarget.getBoundingClientRect());
|
|
471
|
+
const paddedExitPoints = getPaddedExitPoints(exitPoint, exitSide);
|
|
472
|
+
const hoverTargetPoints = getPointsFromRect(hoverTarget.getBoundingClientRect());
|
|
473
|
+
const graceArea = getHull([...paddedExitPoints, ...hoverTargetPoints]);
|
|
474
|
+
pointerGraceArea.value = graceArea;
|
|
475
|
+
providerContext.onPointerInTransitChange(true);
|
|
476
|
+
}
|
|
477
|
+
vue.watchEffect((cleanupFn) => {
|
|
478
|
+
if (trigger.value && currentElement.value) {
|
|
479
|
+
const handleTriggerLeave = (event) => handleCreateGraceArea(event, currentElement.value);
|
|
480
|
+
const handleContentLeave = (event) => handleCreateGraceArea(event, trigger.value);
|
|
481
|
+
trigger.value.addEventListener("pointerleave", handleTriggerLeave);
|
|
482
|
+
currentElement.value.addEventListener("pointerleave", handleContentLeave);
|
|
483
|
+
cleanupFn(() => {
|
|
484
|
+
trigger.value?.removeEventListener("pointerleave", handleTriggerLeave);
|
|
485
|
+
currentElement.value?.removeEventListener("pointerleave", handleContentLeave);
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
vue.watchEffect((cleanupFn) => {
|
|
490
|
+
if (pointerGraceArea.value) {
|
|
491
|
+
const handleTrackPointerGrace = (event) => {
|
|
492
|
+
if (!pointerGraceArea.value)
|
|
493
|
+
return;
|
|
494
|
+
const target = event.target;
|
|
495
|
+
const pointerPosition = { x: event.clientX, y: event.clientY };
|
|
496
|
+
const hasEnteredTarget = trigger.value?.contains(target) || currentElement.value?.contains(target);
|
|
497
|
+
const isPointerOutsideGraceArea = !isPointInPolygon(pointerPosition, pointerGraceArea.value);
|
|
498
|
+
if (hasEnteredTarget) {
|
|
499
|
+
handleRemoveGraceArea();
|
|
500
|
+
} else if (isPointerOutsideGraceArea) {
|
|
501
|
+
handleRemoveGraceArea();
|
|
502
|
+
onClose();
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
document.addEventListener("pointermove", handleTrackPointerGrace);
|
|
506
|
+
cleanupFn(() => document.removeEventListener("pointermove", handleTrackPointerGrace));
|
|
98
507
|
}
|
|
508
|
+
});
|
|
509
|
+
return {
|
|
510
|
+
customElement
|
|
99
511
|
};
|
|
512
|
+
},
|
|
513
|
+
render() {
|
|
514
|
+
return vue.h(DestylerTooltipContentImpl, {
|
|
515
|
+
ref: "customElement",
|
|
516
|
+
...vue.mergeProps(this.$props)
|
|
517
|
+
}, this.$slots.default?.());
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
const destylerTooltipContentProps = {
|
|
522
|
+
...destylerTooltipContentImplProps
|
|
523
|
+
};
|
|
524
|
+
const destylerTooltipContentEmits = [...destylerTooltipContentImplEmits];
|
|
525
|
+
const DestylerTooltipContent = vue.defineComponent({
|
|
526
|
+
name: "DestylerTooltipContent",
|
|
527
|
+
props: destylerTooltipContentProps,
|
|
528
|
+
emits: destylerTooltipContentEmits,
|
|
529
|
+
setup(props, { emit }) {
|
|
530
|
+
const rootContext = injectTooltipRootContext();
|
|
531
|
+
const forwarded = composition.useForwardPropsEmits(props, emit);
|
|
100
532
|
return {
|
|
101
|
-
|
|
102
|
-
|
|
533
|
+
rootContext,
|
|
534
|
+
forwarded
|
|
103
535
|
};
|
|
104
536
|
},
|
|
105
537
|
render() {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}, this.$slots);
|
|
538
|
+
const useVShow = this.rootContext.open.value;
|
|
539
|
+
return useVShow ? vue.h(this.rootContext.disableHoverableContent.value ? DestylerTooltipContentImpl : DestylerTooltipContentHoverable, {
|
|
540
|
+
...this.forwarded
|
|
541
|
+
}, this.$slots.default?.()) : null;
|
|
110
542
|
}
|
|
111
543
|
});
|
|
112
544
|
|
|
113
|
-
|
|
545
|
+
const destylerTooltipPortalProps = {
|
|
546
|
+
...teleport.destylerTeleportProps
|
|
547
|
+
};
|
|
548
|
+
const DestylerTooltipPortal = vue.defineComponent({
|
|
549
|
+
name: "DestylerTooltipPortal",
|
|
550
|
+
props: destylerTooltipPortalProps,
|
|
551
|
+
render() {
|
|
552
|
+
return vue.h(teleport.DestylerTeleport, vue.mergeProps(this.$props), this.$slots.default?.());
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
const destylerTooltipTriggerProps = {
|
|
557
|
+
...primitive.destylerPrimitiveProp,
|
|
558
|
+
as: {
|
|
559
|
+
type: [String, Object],
|
|
560
|
+
required: false,
|
|
561
|
+
default: "button"
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
const DestylerTooltipTrigger = vue.defineComponent({
|
|
565
|
+
name: "DestylerTooltipTrigger",
|
|
566
|
+
props: destylerTooltipTriggerProps,
|
|
567
|
+
setup() {
|
|
568
|
+
const rootContext = injectTooltipRootContext();
|
|
569
|
+
const providerContext = injectTooltipProviderContext();
|
|
570
|
+
const { customElement, currentElement: triggerElement } = composition.useCustomElement();
|
|
571
|
+
const isPointerDown = vue.ref(false);
|
|
572
|
+
const hasPointerMoveOpened = vue.ref(false);
|
|
573
|
+
function handlePointerUp() {
|
|
574
|
+
isPointerDown.value = false;
|
|
575
|
+
}
|
|
576
|
+
function handlePointerDown() {
|
|
577
|
+
isPointerDown.value = true;
|
|
578
|
+
document.addEventListener("pointerup", handlePointerUp, { once: true });
|
|
579
|
+
}
|
|
580
|
+
vue.onMounted(() => {
|
|
581
|
+
rootContext.onTriggerChange(triggerElement.value);
|
|
582
|
+
});
|
|
583
|
+
return {
|
|
584
|
+
rootContext,
|
|
585
|
+
providerContext,
|
|
586
|
+
customElement,
|
|
587
|
+
isPointerDown,
|
|
588
|
+
hasPointerMoveOpened,
|
|
589
|
+
handlePointerDown
|
|
590
|
+
};
|
|
591
|
+
},
|
|
592
|
+
render() {
|
|
593
|
+
return vue.h(popper.DestylerPopperAnchor, {
|
|
594
|
+
asChild: true
|
|
595
|
+
}, vue.h(primitive.DestylerPrimitive, {
|
|
596
|
+
"ref": "customElement",
|
|
597
|
+
"aria-describedby": this.rootContext.open.value ? this.rootContext.contentId : void 0,
|
|
598
|
+
"data-state": this.rootContext.stateAttribute.value,
|
|
599
|
+
"as": this.$props.as,
|
|
600
|
+
"asChild": this.$props.asChild,
|
|
601
|
+
"onPointermove": (event) => {
|
|
602
|
+
if (event.pointerType === "touch")
|
|
603
|
+
return;
|
|
604
|
+
if (!this.hasPointerMoveOpened && !this.providerContext.isPointerInTransitRef.value) {
|
|
605
|
+
this.rootContext.onTriggerEnter();
|
|
606
|
+
this.hasPointerMoveOpened = true;
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
"onPointerleave": () => {
|
|
610
|
+
this.rootContext.onTriggerLeave();
|
|
611
|
+
this.hasPointerMoveOpened = false;
|
|
612
|
+
},
|
|
613
|
+
"onPointerdown": () => {
|
|
614
|
+
this.handlePointerDown();
|
|
615
|
+
},
|
|
616
|
+
"onFocus": () => {
|
|
617
|
+
if (!this.isPointerDown)
|
|
618
|
+
this.rootContext.onOpen();
|
|
619
|
+
},
|
|
620
|
+
"onBlur": () => {
|
|
621
|
+
this.rootContext.onClose();
|
|
622
|
+
},
|
|
623
|
+
"onClick": () => {
|
|
624
|
+
if (!this.rootContext.disableClosingTrigger.value)
|
|
625
|
+
this.rootContext.onClose();
|
|
626
|
+
}
|
|
627
|
+
}, this.$slots.default?.()));
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
const name = "@destyler/tooltip";
|
|
632
|
+
|
|
633
|
+
const packageName = name;
|
|
634
|
+
function DestylerTooltipResolver() {
|
|
635
|
+
return {
|
|
636
|
+
type: "component",
|
|
637
|
+
resolve: (name2) => {
|
|
638
|
+
if (name2 === "DestylerTemplate")
|
|
639
|
+
return { name: name2, from: packageName };
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
exports.DestylerTooltipArrow = DestylerTooltipArrow;
|
|
645
|
+
exports.DestylerTooltipContent = DestylerTooltipContent;
|
|
646
|
+
exports.DestylerTooltipContentHoverable = DestylerTooltipContentHoverable;
|
|
647
|
+
exports.DestylerTooltipContentImpl = DestylerTooltipContentImpl;
|
|
648
|
+
exports.DestylerTooltipPortal = DestylerTooltipPortal;
|
|
649
|
+
exports.DestylerTooltipProvider = DestylerTooltipProvider;
|
|
114
650
|
exports.DestylerTooltipResolver = DestylerTooltipResolver;
|
|
115
|
-
exports.
|
|
651
|
+
exports.DestylerTooltipRoot = DestylerTooltipRoot;
|
|
652
|
+
exports.DestylerTooltipTrigger = DestylerTooltipTrigger;
|
|
653
|
+
exports.TOOLTIP_OPEN = TOOLTIP_OPEN;
|
|
654
|
+
exports.destylerTooltipArrowProps = destylerTooltipArrowProps;
|
|
655
|
+
exports.destylerTooltipContentEmits = destylerTooltipContentEmits;
|
|
656
|
+
exports.destylerTooltipContentImplEmits = destylerTooltipContentImplEmits;
|
|
657
|
+
exports.destylerTooltipContentImplProps = destylerTooltipContentImplProps;
|
|
658
|
+
exports.destylerTooltipContentProps = destylerTooltipContentProps;
|
|
659
|
+
exports.destylerTooltipPortalProps = destylerTooltipPortalProps;
|
|
660
|
+
exports.destylerTooltipProviderProps = destylerTooltipProviderProps;
|
|
661
|
+
exports.destylerTooltipRootProps = destylerTooltipRootProps;
|
|
662
|
+
exports.destylerTooltipTriggerProps = destylerTooltipTriggerProps;
|
|
663
|
+
exports.getExitSideFromRect = getExitSideFromRect;
|
|
664
|
+
exports.getHull = getHull;
|
|
665
|
+
exports.getHullPresorted = getHullPresorted;
|
|
666
|
+
exports.getPaddedExitPoints = getPaddedExitPoints;
|
|
667
|
+
exports.getPointsFromRect = getPointsFromRect;
|
|
668
|
+
exports.injectTooltipProviderContext = injectTooltipProviderContext;
|
|
669
|
+
exports.injectTooltipRootContext = injectTooltipRootContext;
|
|
670
|
+
exports.isPointInPolygon = isPointInPolygon;
|
|
671
|
+
exports.provideTooltipProviderContext = provideTooltipProviderContext;
|
|
672
|
+
exports.provideTooltipRootContext = provideTooltipRootContext;
|