@huin-core/react-tooltip 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +100 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.js +579 -0
- package/dist/index.js.map +7 -0
- package/dist/index.mjs +547 -0
- package/dist/index.mjs.map +7 -0
- package/package.json +1 -1
package/dist/index.js
ADDED
@@ -0,0 +1,579 @@
|
|
1
|
+
"use strict";
|
2
|
+
"use client";
|
3
|
+
var __create = Object.create;
|
4
|
+
var __defProp = Object.defineProperty;
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
9
|
+
var __export = (target, all) => {
|
10
|
+
for (var name in all)
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
12
|
+
};
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
15
|
+
for (let key of __getOwnPropNames(from))
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
18
|
+
}
|
19
|
+
return to;
|
20
|
+
};
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
27
|
+
mod
|
28
|
+
));
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
30
|
+
|
31
|
+
// packages/react/tooltip/src/index.ts
|
32
|
+
var src_exports = {};
|
33
|
+
__export(src_exports, {
|
34
|
+
Root: () => Root2,
|
35
|
+
Tooltip: () => Tooltip,
|
36
|
+
TooltipArrow: () => TooltipArrow,
|
37
|
+
TooltipContent: () => TooltipContent,
|
38
|
+
TooltipPortal: () => TooltipPortal,
|
39
|
+
TooltipProvider: () => TooltipProvider,
|
40
|
+
TooltipTrigger: () => TooltipTrigger
|
41
|
+
});
|
42
|
+
module.exports = __toCommonJS(src_exports);
|
43
|
+
|
44
|
+
// packages/react/tooltip/src/Tooltip.tsx
|
45
|
+
var React2 = __toESM(require("react"));
|
46
|
+
var import_react_context = require("@huin-core/react-context");
|
47
|
+
var import_react_id = require("@huin-core/react-id");
|
48
|
+
var PopperPrimitive = __toESM(require("@huin-core/react-popper"));
|
49
|
+
var import_react_popper = require("@huin-core/react-popper");
|
50
|
+
var import_react_use_controllable_state = require("@huin-core/react-use-controllable-state");
|
51
|
+
|
52
|
+
// packages/react/tooltip/src/TooltipProvider.tsx
|
53
|
+
var import_react = __toESM(require("react"));
|
54
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
55
|
+
var PROVIDER_NAME = "TooltipProvider";
|
56
|
+
var DEFAULT_DELAY_DURATION = 700;
|
57
|
+
var [TooltipProviderContextProvider, useTooltipProviderContext] = createTooltipContext(PROVIDER_NAME);
|
58
|
+
var TooltipProvider = (props) => {
|
59
|
+
const {
|
60
|
+
__scopeTooltip,
|
61
|
+
delayDuration = DEFAULT_DELAY_DURATION,
|
62
|
+
skipDelayDuration = 300,
|
63
|
+
disableHoverableContent = false,
|
64
|
+
children
|
65
|
+
} = props;
|
66
|
+
const [isOpenDelayed, setIsOpenDelayed] = import_react.default.useState(true);
|
67
|
+
const isPointerInTransitRef = import_react.default.useRef(false);
|
68
|
+
const skipDelayTimerRef = import_react.default.useRef(0);
|
69
|
+
import_react.default.useEffect(() => {
|
70
|
+
const skipDelayTimer = skipDelayTimerRef.current;
|
71
|
+
return () => window.clearTimeout(skipDelayTimer);
|
72
|
+
}, []);
|
73
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
74
|
+
TooltipProviderContextProvider,
|
75
|
+
{
|
76
|
+
scope: __scopeTooltip,
|
77
|
+
isOpenDelayed,
|
78
|
+
delayDuration,
|
79
|
+
onOpen: import_react.default.useCallback(() => {
|
80
|
+
window.clearTimeout(skipDelayTimerRef.current);
|
81
|
+
setIsOpenDelayed(false);
|
82
|
+
}, []),
|
83
|
+
onClose: import_react.default.useCallback(() => {
|
84
|
+
window.clearTimeout(skipDelayTimerRef.current);
|
85
|
+
skipDelayTimerRef.current = window.setTimeout(
|
86
|
+
() => setIsOpenDelayed(true),
|
87
|
+
skipDelayDuration
|
88
|
+
);
|
89
|
+
}, [skipDelayDuration]),
|
90
|
+
isPointerInTransitRef,
|
91
|
+
onPointerInTransitChange: import_react.default.useCallback((inTransit) => {
|
92
|
+
isPointerInTransitRef.current = inTransit;
|
93
|
+
}, []),
|
94
|
+
disableHoverableContent,
|
95
|
+
children
|
96
|
+
}
|
97
|
+
);
|
98
|
+
};
|
99
|
+
TooltipProvider.displayName = PROVIDER_NAME;
|
100
|
+
|
101
|
+
// packages/react/tooltip/src/Tooltip.tsx
|
102
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
103
|
+
var [createTooltipContext, createTooltipScope] = (0, import_react_context.createContextScope)(
|
104
|
+
"Tooltip",
|
105
|
+
[import_react_popper.createPopperScope]
|
106
|
+
);
|
107
|
+
var usePopperScope = (0, import_react_popper.createPopperScope)();
|
108
|
+
var TOOLTIP_OPEN = "tooltip.open";
|
109
|
+
var TOOLTIP_NAME = "Tooltip";
|
110
|
+
var [TooltipContextProvider, useTooltipContext] = createTooltipContext(TOOLTIP_NAME);
|
111
|
+
var Tooltip = (props) => {
|
112
|
+
const {
|
113
|
+
__scopeTooltip,
|
114
|
+
children,
|
115
|
+
open: openProp,
|
116
|
+
defaultOpen = false,
|
117
|
+
onOpenChange,
|
118
|
+
disableHoverableContent: disableHoverableContentProp,
|
119
|
+
delayDuration: delayDurationProp
|
120
|
+
} = props;
|
121
|
+
const providerContext = useTooltipProviderContext(
|
122
|
+
TOOLTIP_NAME,
|
123
|
+
props.__scopeTooltip
|
124
|
+
);
|
125
|
+
const popperScope = usePopperScope(__scopeTooltip);
|
126
|
+
const [trigger, setTrigger] = React2.useState(null);
|
127
|
+
const contentId = (0, import_react_id.useId)();
|
128
|
+
const openTimerRef = React2.useRef(0);
|
129
|
+
const disableHoverableContent = disableHoverableContentProp ?? providerContext.disableHoverableContent;
|
130
|
+
const delayDuration = delayDurationProp ?? providerContext.delayDuration;
|
131
|
+
const wasOpenDelayedRef = React2.useRef(false);
|
132
|
+
const [open = false, setOpen] = (0, import_react_use_controllable_state.useControllableState)({
|
133
|
+
prop: openProp,
|
134
|
+
defaultProp: defaultOpen,
|
135
|
+
onChange: (open2) => {
|
136
|
+
if (open2) {
|
137
|
+
providerContext.onOpen();
|
138
|
+
document.dispatchEvent(new CustomEvent(TOOLTIP_OPEN));
|
139
|
+
} else {
|
140
|
+
providerContext.onClose();
|
141
|
+
}
|
142
|
+
onOpenChange?.(open2);
|
143
|
+
}
|
144
|
+
});
|
145
|
+
const stateAttribute = React2.useMemo(() => {
|
146
|
+
return open ? wasOpenDelayedRef.current ? "delayed-open" : "instant-open" : "closed";
|
147
|
+
}, [open]);
|
148
|
+
const handleOpen = React2.useCallback(() => {
|
149
|
+
window.clearTimeout(openTimerRef.current);
|
150
|
+
wasOpenDelayedRef.current = false;
|
151
|
+
setOpen(true);
|
152
|
+
}, [setOpen]);
|
153
|
+
const handleClose = React2.useCallback(() => {
|
154
|
+
window.clearTimeout(openTimerRef.current);
|
155
|
+
setOpen(false);
|
156
|
+
}, [setOpen]);
|
157
|
+
const handleDelayedOpen = React2.useCallback(() => {
|
158
|
+
window.clearTimeout(openTimerRef.current);
|
159
|
+
openTimerRef.current = window.setTimeout(() => {
|
160
|
+
wasOpenDelayedRef.current = true;
|
161
|
+
setOpen(true);
|
162
|
+
}, delayDuration);
|
163
|
+
}, [delayDuration, setOpen]);
|
164
|
+
React2.useEffect(() => {
|
165
|
+
return () => window.clearTimeout(openTimerRef.current);
|
166
|
+
}, []);
|
167
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PopperPrimitive.Root, { ...popperScope, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
168
|
+
TooltipContextProvider,
|
169
|
+
{
|
170
|
+
scope: __scopeTooltip,
|
171
|
+
contentId,
|
172
|
+
open,
|
173
|
+
stateAttribute,
|
174
|
+
trigger,
|
175
|
+
onTriggerChange: setTrigger,
|
176
|
+
onTriggerEnter: React2.useCallback(() => {
|
177
|
+
if (providerContext.isOpenDelayed) handleDelayedOpen();
|
178
|
+
else handleOpen();
|
179
|
+
}, [providerContext.isOpenDelayed, handleDelayedOpen, handleOpen]),
|
180
|
+
onTriggerLeave: React2.useCallback(() => {
|
181
|
+
if (disableHoverableContent) {
|
182
|
+
handleClose();
|
183
|
+
} else {
|
184
|
+
window.clearTimeout(openTimerRef.current);
|
185
|
+
}
|
186
|
+
}, [handleClose, disableHoverableContent]),
|
187
|
+
onOpen: handleOpen,
|
188
|
+
onClose: handleClose,
|
189
|
+
disableHoverableContent,
|
190
|
+
children
|
191
|
+
}
|
192
|
+
) });
|
193
|
+
};
|
194
|
+
Tooltip.displayName = TOOLTIP_NAME;
|
195
|
+
var Root2 = Tooltip;
|
196
|
+
|
197
|
+
// packages/react/tooltip/src/TooltipPortal.tsx
|
198
|
+
var import_react_presence = require("@huin-core/react-presence");
|
199
|
+
var import_react_portal = require("@huin-core/react-portal");
|
200
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
201
|
+
var PORTAL_NAME = "TooltipPortal";
|
202
|
+
var [PortalProvider, usePortalContext] = createTooltipContext(PORTAL_NAME, {
|
203
|
+
forceMount: void 0
|
204
|
+
});
|
205
|
+
var TooltipPortal = (props) => {
|
206
|
+
const { __scopeTooltip, forceMount, children, container } = props;
|
207
|
+
const context = useTooltipContext(PORTAL_NAME, __scopeTooltip);
|
208
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PortalProvider, { scope: __scopeTooltip, forceMount, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_presence.Presence, { present: forceMount || context.open, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_portal.Portal, { asChild: true, container, children }) }) });
|
209
|
+
};
|
210
|
+
TooltipPortal.displayName = PORTAL_NAME;
|
211
|
+
|
212
|
+
// packages/react/tooltip/src/TooltipContent.tsx
|
213
|
+
var import_react2 = __toESM(require("react"));
|
214
|
+
var import_react_presence2 = require("@huin-core/react-presence");
|
215
|
+
var import_react_compose_refs = require("@huin-core/react-compose-refs");
|
216
|
+
var import_react_slot = require("@huin-core/react-slot");
|
217
|
+
var VisuallyHiddenPrimitive = __toESM(require("@huin-core/react-visually-hidden"));
|
218
|
+
var PopperPrimitive2 = __toESM(require("@huin-core/react-popper"));
|
219
|
+
var import_react_dismissable_layer = require("@huin-core/react-dismissable-layer");
|
220
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
221
|
+
var CONTENT_NAME = "TooltipContent";
|
222
|
+
var TooltipContent = import_react2.default.forwardRef((props, forwardedRef) => {
|
223
|
+
const portalContext = usePortalContext(CONTENT_NAME, props.__scopeTooltip);
|
224
|
+
const { forceMount = portalContext.forceMount, side = "top", ...contentProps } = props;
|
225
|
+
const context = useTooltipContext(CONTENT_NAME, props.__scopeTooltip);
|
226
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_presence2.Presence, { present: forceMount || context.open, children: context.disableHoverableContent ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TooltipContentImpl, { side, ...contentProps, ref: forwardedRef }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TooltipContentHoverable, { side, ...contentProps, ref: forwardedRef }) });
|
227
|
+
});
|
228
|
+
var TooltipContentHoverable = import_react2.default.forwardRef((props, forwardedRef) => {
|
229
|
+
const context = useTooltipContext(CONTENT_NAME, props.__scopeTooltip);
|
230
|
+
const providerContext = useTooltipProviderContext(
|
231
|
+
CONTENT_NAME,
|
232
|
+
props.__scopeTooltip
|
233
|
+
);
|
234
|
+
const ref = import_react2.default.useRef(null);
|
235
|
+
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
|
236
|
+
const [pointerGraceArea, setPointerGraceArea] = import_react2.default.useState(null);
|
237
|
+
const { trigger, onClose } = context;
|
238
|
+
const content = ref.current;
|
239
|
+
const { onPointerInTransitChange } = providerContext;
|
240
|
+
const handleRemoveGraceArea = import_react2.default.useCallback(() => {
|
241
|
+
setPointerGraceArea(null);
|
242
|
+
onPointerInTransitChange(false);
|
243
|
+
}, [onPointerInTransitChange]);
|
244
|
+
const handleCreateGraceArea = import_react2.default.useCallback(
|
245
|
+
(event, hoverTarget) => {
|
246
|
+
const currentTarget = event.currentTarget;
|
247
|
+
const exitPoint = { x: event.clientX, y: event.clientY };
|
248
|
+
const exitSide = getExitSideFromRect(
|
249
|
+
exitPoint,
|
250
|
+
currentTarget.getBoundingClientRect()
|
251
|
+
);
|
252
|
+
const paddedExitPoints = getPaddedExitPoints(exitPoint, exitSide);
|
253
|
+
const hoverTargetPoints = getPointsFromRect(
|
254
|
+
hoverTarget.getBoundingClientRect()
|
255
|
+
);
|
256
|
+
const graceArea = getHull([...paddedExitPoints, ...hoverTargetPoints]);
|
257
|
+
setPointerGraceArea(graceArea);
|
258
|
+
onPointerInTransitChange(true);
|
259
|
+
},
|
260
|
+
[onPointerInTransitChange]
|
261
|
+
);
|
262
|
+
import_react2.default.useEffect(() => {
|
263
|
+
return () => handleRemoveGraceArea();
|
264
|
+
}, [handleRemoveGraceArea]);
|
265
|
+
import_react2.default.useEffect(() => {
|
266
|
+
if (trigger && content) {
|
267
|
+
const handleTriggerLeave = (event) => handleCreateGraceArea(event, content);
|
268
|
+
const handleContentLeave = (event) => handleCreateGraceArea(event, trigger);
|
269
|
+
trigger.addEventListener("pointerleave", handleTriggerLeave);
|
270
|
+
content.addEventListener("pointerleave", handleContentLeave);
|
271
|
+
return () => {
|
272
|
+
trigger.removeEventListener("pointerleave", handleTriggerLeave);
|
273
|
+
content.removeEventListener("pointerleave", handleContentLeave);
|
274
|
+
};
|
275
|
+
}
|
276
|
+
}, [trigger, content, handleCreateGraceArea, handleRemoveGraceArea]);
|
277
|
+
import_react2.default.useEffect(() => {
|
278
|
+
if (pointerGraceArea) {
|
279
|
+
const handleTrackPointerGrace = (event) => {
|
280
|
+
const target = event.target;
|
281
|
+
const pointerPosition = { x: event.clientX, y: event.clientY };
|
282
|
+
const hasEnteredTarget = trigger?.contains(target) || content?.contains(target);
|
283
|
+
const isPointerOutsideGraceArea = !isPointInPolygon(
|
284
|
+
pointerPosition,
|
285
|
+
pointerGraceArea
|
286
|
+
);
|
287
|
+
if (hasEnteredTarget) {
|
288
|
+
handleRemoveGraceArea();
|
289
|
+
} else if (isPointerOutsideGraceArea) {
|
290
|
+
handleRemoveGraceArea();
|
291
|
+
onClose();
|
292
|
+
}
|
293
|
+
};
|
294
|
+
document.addEventListener("pointermove", handleTrackPointerGrace);
|
295
|
+
return () => document.removeEventListener("pointermove", handleTrackPointerGrace);
|
296
|
+
}
|
297
|
+
}, [trigger, content, pointerGraceArea, onClose, handleRemoveGraceArea]);
|
298
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TooltipContentImpl, { ...props, ref: composedRefs });
|
299
|
+
});
|
300
|
+
var [
|
301
|
+
VisuallyHiddenContentContextProvider,
|
302
|
+
useVisuallyHiddenContentContext
|
303
|
+
] = createTooltipContext(TOOLTIP_NAME, { isInside: false });
|
304
|
+
var TooltipContentImpl = import_react2.default.forwardRef((props, forwardedRef) => {
|
305
|
+
const {
|
306
|
+
__scopeTooltip,
|
307
|
+
children,
|
308
|
+
"aria-label": ariaLabel,
|
309
|
+
onEscapeKeyDown,
|
310
|
+
onPointerDownOutside,
|
311
|
+
...contentProps
|
312
|
+
} = props;
|
313
|
+
const context = useTooltipContext(CONTENT_NAME, __scopeTooltip);
|
314
|
+
const popperScope = usePopperScope(__scopeTooltip);
|
315
|
+
const { onClose } = context;
|
316
|
+
import_react2.default.useEffect(() => {
|
317
|
+
document.addEventListener(TOOLTIP_OPEN, onClose);
|
318
|
+
return () => document.removeEventListener(TOOLTIP_OPEN, onClose);
|
319
|
+
}, [onClose]);
|
320
|
+
import_react2.default.useEffect(() => {
|
321
|
+
if (context.trigger) {
|
322
|
+
const handleScroll = (event) => {
|
323
|
+
const target = event.target;
|
324
|
+
if (target?.contains(context.trigger)) onClose();
|
325
|
+
};
|
326
|
+
window.addEventListener("scroll", handleScroll, { capture: true });
|
327
|
+
return () => window.removeEventListener("scroll", handleScroll, { capture: true });
|
328
|
+
}
|
329
|
+
}, [context.trigger, onClose]);
|
330
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
331
|
+
import_react_dismissable_layer.DismissableLayer,
|
332
|
+
{
|
333
|
+
asChild: true,
|
334
|
+
disableOutsidePointerEvents: false,
|
335
|
+
onEscapeKeyDown,
|
336
|
+
onPointerDownOutside,
|
337
|
+
onFocusOutside: (event) => event.preventDefault(),
|
338
|
+
onDismiss: onClose,
|
339
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
340
|
+
PopperPrimitive2.Content,
|
341
|
+
{
|
342
|
+
"data-state": context.stateAttribute,
|
343
|
+
...popperScope,
|
344
|
+
...contentProps,
|
345
|
+
ref: forwardedRef,
|
346
|
+
style: {
|
347
|
+
...contentProps.style,
|
348
|
+
// re-namespace exposed content custom properties
|
349
|
+
...{
|
350
|
+
"--huin-core-tooltip-content-transform-origin": "var(--huin-core-popper-transform-origin)",
|
351
|
+
"--huin-core-tooltip-content-available-width": "var(--huin-core-popper-available-width)",
|
352
|
+
"--huin-core-tooltip-content-available-height": "var(--huin-core-popper-available-height)",
|
353
|
+
"--huin-core-tooltip-trigger-width": "var(--huin-core-popper-anchor-width)",
|
354
|
+
"--huin-core-tooltip-trigger-height": "var(--huin-core-popper-anchor-height)"
|
355
|
+
}
|
356
|
+
},
|
357
|
+
children: [
|
358
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_slot.Slottable, { children }),
|
359
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
360
|
+
VisuallyHiddenContentContextProvider,
|
361
|
+
{
|
362
|
+
scope: __scopeTooltip,
|
363
|
+
isInside: true,
|
364
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(VisuallyHiddenPrimitive.Root, { id: context.contentId, role: "tooltip", children: ariaLabel || children })
|
365
|
+
}
|
366
|
+
)
|
367
|
+
]
|
368
|
+
}
|
369
|
+
)
|
370
|
+
}
|
371
|
+
);
|
372
|
+
});
|
373
|
+
TooltipContent.displayName = CONTENT_NAME;
|
374
|
+
function getExitSideFromRect(point, rect) {
|
375
|
+
const top = Math.abs(rect.top - point.y);
|
376
|
+
const bottom = Math.abs(rect.bottom - point.y);
|
377
|
+
const right = Math.abs(rect.right - point.x);
|
378
|
+
const left = Math.abs(rect.left - point.x);
|
379
|
+
switch (Math.min(top, bottom, right, left)) {
|
380
|
+
case left:
|
381
|
+
return "left";
|
382
|
+
case right:
|
383
|
+
return "right";
|
384
|
+
case top:
|
385
|
+
return "top";
|
386
|
+
case bottom:
|
387
|
+
return "bottom";
|
388
|
+
default:
|
389
|
+
throw new Error("unreachable");
|
390
|
+
}
|
391
|
+
}
|
392
|
+
function getPaddedExitPoints(exitPoint, exitSide, padding = 5) {
|
393
|
+
const paddedExitPoints = [];
|
394
|
+
switch (exitSide) {
|
395
|
+
case "top":
|
396
|
+
paddedExitPoints.push(
|
397
|
+
{ x: exitPoint.x - padding, y: exitPoint.y + padding },
|
398
|
+
{ x: exitPoint.x + padding, y: exitPoint.y + padding }
|
399
|
+
);
|
400
|
+
break;
|
401
|
+
case "bottom":
|
402
|
+
paddedExitPoints.push(
|
403
|
+
{ x: exitPoint.x - padding, y: exitPoint.y - padding },
|
404
|
+
{ x: exitPoint.x + padding, y: exitPoint.y - padding }
|
405
|
+
);
|
406
|
+
break;
|
407
|
+
case "left":
|
408
|
+
paddedExitPoints.push(
|
409
|
+
{ x: exitPoint.x + padding, y: exitPoint.y - padding },
|
410
|
+
{ x: exitPoint.x + padding, y: exitPoint.y + padding }
|
411
|
+
);
|
412
|
+
break;
|
413
|
+
case "right":
|
414
|
+
paddedExitPoints.push(
|
415
|
+
{ x: exitPoint.x - padding, y: exitPoint.y - padding },
|
416
|
+
{ x: exitPoint.x - padding, y: exitPoint.y + padding }
|
417
|
+
);
|
418
|
+
break;
|
419
|
+
}
|
420
|
+
return paddedExitPoints;
|
421
|
+
}
|
422
|
+
function getPointsFromRect(rect) {
|
423
|
+
const { top, right, bottom, left } = rect;
|
424
|
+
return [
|
425
|
+
{ x: left, y: top },
|
426
|
+
{ x: right, y: top },
|
427
|
+
{ x: right, y: bottom },
|
428
|
+
{ x: left, y: bottom }
|
429
|
+
];
|
430
|
+
}
|
431
|
+
function isPointInPolygon(point, polygon) {
|
432
|
+
const { x, y } = point;
|
433
|
+
let inside = false;
|
434
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
435
|
+
const xi = polygon[i].x;
|
436
|
+
const yi = polygon[i].y;
|
437
|
+
const xj = polygon[j].x;
|
438
|
+
const yj = polygon[j].y;
|
439
|
+
const intersect = yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
|
440
|
+
if (intersect) inside = !inside;
|
441
|
+
}
|
442
|
+
return inside;
|
443
|
+
}
|
444
|
+
function getHull(points) {
|
445
|
+
const newPoints = points.slice();
|
446
|
+
newPoints.sort((a, b) => {
|
447
|
+
if (a.x < b.x) return -1;
|
448
|
+
else if (a.x > b.x) return 1;
|
449
|
+
else if (a.y < b.y) return -1;
|
450
|
+
else if (a.y > b.y) return 1;
|
451
|
+
else return 0;
|
452
|
+
});
|
453
|
+
return getHullPresorted(newPoints);
|
454
|
+
}
|
455
|
+
function getHullPresorted(points) {
|
456
|
+
if (points.length <= 1) return points.slice();
|
457
|
+
const upperHull = [];
|
458
|
+
for (let i = 0; i < points.length; i++) {
|
459
|
+
const p = points[i];
|
460
|
+
while (upperHull.length >= 2) {
|
461
|
+
const q = upperHull[upperHull.length - 1];
|
462
|
+
const r = upperHull[upperHull.length - 2];
|
463
|
+
if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x))
|
464
|
+
upperHull.pop();
|
465
|
+
else break;
|
466
|
+
}
|
467
|
+
upperHull.push(p);
|
468
|
+
}
|
469
|
+
upperHull.pop();
|
470
|
+
const lowerHull = [];
|
471
|
+
for (let i = points.length - 1; i >= 0; i--) {
|
472
|
+
const p = points[i];
|
473
|
+
while (lowerHull.length >= 2) {
|
474
|
+
const q = lowerHull[lowerHull.length - 1];
|
475
|
+
const r = lowerHull[lowerHull.length - 2];
|
476
|
+
if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x))
|
477
|
+
lowerHull.pop();
|
478
|
+
else break;
|
479
|
+
}
|
480
|
+
lowerHull.push(p);
|
481
|
+
}
|
482
|
+
lowerHull.pop();
|
483
|
+
if (upperHull.length === 1 && lowerHull.length === 1 && upperHull[0].x === lowerHull[0].x && upperHull[0].y === lowerHull[0].y) {
|
484
|
+
return upperHull;
|
485
|
+
} else {
|
486
|
+
return upperHull.concat(lowerHull);
|
487
|
+
}
|
488
|
+
}
|
489
|
+
|
490
|
+
// packages/react/tooltip/src/TooltipTrigger.tsx
|
491
|
+
var import_react3 = __toESM(require("react"));
|
492
|
+
var import_react_primitive = require("@huin-core/react-primitive");
|
493
|
+
var PopperPrimitive3 = __toESM(require("@huin-core/react-popper"));
|
494
|
+
var import_react_compose_refs2 = require("@huin-core/react-compose-refs");
|
495
|
+
var import_primitive = require("@huin-core/primitive");
|
496
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
497
|
+
var TRIGGER_NAME = "TooltipTrigger";
|
498
|
+
var TooltipTrigger = import_react3.default.forwardRef((props, forwardedRef) => {
|
499
|
+
const { __scopeTooltip, ...triggerProps } = props;
|
500
|
+
const context = useTooltipContext(TRIGGER_NAME, __scopeTooltip);
|
501
|
+
const providerContext = useTooltipProviderContext(
|
502
|
+
TRIGGER_NAME,
|
503
|
+
__scopeTooltip
|
504
|
+
);
|
505
|
+
const popperScope = usePopperScope(__scopeTooltip);
|
506
|
+
const ref = import_react3.default.useRef(null);
|
507
|
+
const composedRefs = (0, import_react_compose_refs2.useComposedRefs)(
|
508
|
+
forwardedRef,
|
509
|
+
ref,
|
510
|
+
context.onTriggerChange
|
511
|
+
);
|
512
|
+
const isPointerDownRef = import_react3.default.useRef(false);
|
513
|
+
const hasPointerMoveOpenedRef = import_react3.default.useRef(false);
|
514
|
+
const handlePointerUp = import_react3.default.useCallback(
|
515
|
+
() => isPointerDownRef.current = false,
|
516
|
+
[]
|
517
|
+
);
|
518
|
+
import_react3.default.useEffect(() => {
|
519
|
+
return () => document.removeEventListener("pointerup", handlePointerUp);
|
520
|
+
}, [handlePointerUp]);
|
521
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PopperPrimitive3.Anchor, { asChild: true, ...popperScope, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
522
|
+
import_react_primitive.Primitive.button,
|
523
|
+
{
|
524
|
+
"aria-describedby": context.open ? context.contentId : void 0,
|
525
|
+
"data-state": context.stateAttribute,
|
526
|
+
...triggerProps,
|
527
|
+
ref: composedRefs,
|
528
|
+
onPointerMove: (0, import_primitive.composeEventHandlers)(props.onPointerMove, (event) => {
|
529
|
+
if (event.pointerType === "touch") return;
|
530
|
+
if (!hasPointerMoveOpenedRef.current && !providerContext.isPointerInTransitRef.current) {
|
531
|
+
context.onTriggerEnter();
|
532
|
+
hasPointerMoveOpenedRef.current = true;
|
533
|
+
}
|
534
|
+
}),
|
535
|
+
onPointerLeave: (0, import_primitive.composeEventHandlers)(props.onPointerLeave, () => {
|
536
|
+
context.onTriggerLeave();
|
537
|
+
hasPointerMoveOpenedRef.current = false;
|
538
|
+
}),
|
539
|
+
onPointerDown: (0, import_primitive.composeEventHandlers)(props.onPointerDown, () => {
|
540
|
+
isPointerDownRef.current = true;
|
541
|
+
document.addEventListener("pointerup", handlePointerUp, {
|
542
|
+
once: true
|
543
|
+
});
|
544
|
+
}),
|
545
|
+
onFocus: (0, import_primitive.composeEventHandlers)(props.onFocus, () => {
|
546
|
+
if (!isPointerDownRef.current) context.onOpen();
|
547
|
+
}),
|
548
|
+
onBlur: (0, import_primitive.composeEventHandlers)(props.onBlur, context.onClose),
|
549
|
+
onClick: (0, import_primitive.composeEventHandlers)(props.onClick, context.onClose)
|
550
|
+
}
|
551
|
+
) });
|
552
|
+
});
|
553
|
+
TooltipTrigger.displayName = TRIGGER_NAME;
|
554
|
+
|
555
|
+
// packages/react/tooltip/src/TooltipArrow.tsx
|
556
|
+
var PopperPrimitive4 = __toESM(require("@huin-core/react-popper"));
|
557
|
+
var import_react4 = __toESM(require("react"));
|
558
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
559
|
+
var ARROW_NAME = "TooltipArrow";
|
560
|
+
var TooltipArrow = import_react4.default.forwardRef(
|
561
|
+
(props, forwardedRef) => {
|
562
|
+
const { __scopeTooltip, ...arrowProps } = props;
|
563
|
+
const popperScope = usePopperScope(__scopeTooltip);
|
564
|
+
const visuallyHiddenContentContext = useVisuallyHiddenContentContext(
|
565
|
+
ARROW_NAME,
|
566
|
+
__scopeTooltip
|
567
|
+
);
|
568
|
+
return visuallyHiddenContentContext.isInside ? null : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
569
|
+
PopperPrimitive4.Arrow,
|
570
|
+
{
|
571
|
+
...popperScope,
|
572
|
+
...arrowProps,
|
573
|
+
ref: forwardedRef
|
574
|
+
}
|
575
|
+
);
|
576
|
+
}
|
577
|
+
);
|
578
|
+
TooltipArrow.displayName = ARROW_NAME;
|
579
|
+
//# sourceMappingURL=index.js.map
|