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