@zag-js/tooltip 0.2.5 → 0.2.6
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/chunk-GQYNO326.mjs +14 -0
- package/dist/chunk-JWVFZJC7.mjs +359 -0
- package/dist/chunk-PFKIRGNP.mjs +146 -0
- package/dist/chunk-RRQRIZBA.mjs +9 -0
- package/dist/chunk-XZ6HXWV2.mjs +147 -0
- package/dist/index.d.ts +8 -946
- package/dist/index.js +36 -18
- package/dist/index.mjs +11 -619
- package/dist/tooltip.anatomy.d.ts +6 -0
- package/dist/tooltip.anatomy.js +34 -0
- package/dist/tooltip.anatomy.mjs +8 -0
- package/dist/tooltip.connect.d.ts +23 -0
- package/dist/tooltip.connect.js +308 -0
- package/dist/tooltip.connect.mjs +9 -0
- package/dist/tooltip.dom.d.ts +41 -0
- package/dist/tooltip.dom.js +156 -0
- package/dist/tooltip.dom.mjs +6 -0
- package/dist/tooltip.machine.d.ts +8 -0
- package/dist/tooltip.machine.js +528 -0
- package/dist/tooltip.machine.mjs +8 -0
- package/dist/tooltip.store.d.ts +9 -0
- package/dist/tooltip.store.js +38 -0
- package/dist/tooltip.store.mjs +6 -0
- package/dist/tooltip.types.d.ts +77 -0
- package/dist/tooltip.types.js +18 -0
- package/dist/tooltip.types.mjs +0 -0
- package/package.json +22 -12
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dom,
|
|
3
|
+
getScrollParents,
|
|
4
|
+
isHTMLElement
|
|
5
|
+
} from "./chunk-PFKIRGNP.mjs";
|
|
6
|
+
import {
|
|
7
|
+
store
|
|
8
|
+
} from "./chunk-GQYNO326.mjs";
|
|
9
|
+
|
|
10
|
+
// src/tooltip.machine.ts
|
|
11
|
+
import { createMachine, subscribe } from "@zag-js/core";
|
|
12
|
+
|
|
13
|
+
// ../../utilities/core/src/functions.ts
|
|
14
|
+
var runIfFn = (v, ...a) => {
|
|
15
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
16
|
+
return res != null ? res : void 0;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// ../../utilities/core/src/guard.ts
|
|
20
|
+
var isArray = (v) => Array.isArray(v);
|
|
21
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
22
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
23
|
+
|
|
24
|
+
// ../../utilities/core/src/object.ts
|
|
25
|
+
function compact(obj) {
|
|
26
|
+
if (obj === void 0)
|
|
27
|
+
return obj;
|
|
28
|
+
return Object.fromEntries(
|
|
29
|
+
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ../../utilities/dom/src/platform.ts
|
|
34
|
+
var isDom = () => typeof window !== "undefined";
|
|
35
|
+
function getPlatform() {
|
|
36
|
+
var _a;
|
|
37
|
+
const agent = navigator.userAgentData;
|
|
38
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
39
|
+
}
|
|
40
|
+
var pt = (v) => isDom() && v.test(getPlatform());
|
|
41
|
+
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
42
|
+
var isSafari = () => isApple() && vn(/apple/i);
|
|
43
|
+
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
44
|
+
|
|
45
|
+
// ../../utilities/dom/src/event.ts
|
|
46
|
+
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
47
|
+
var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
|
|
48
|
+
var supportsMouseEvent = () => isDom() && window.onmousedown === null;
|
|
49
|
+
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
50
|
+
|
|
51
|
+
// ../../utilities/dom/src/listener.ts
|
|
52
|
+
var isRef = (v) => hasProp(v, "current");
|
|
53
|
+
var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
|
|
54
|
+
function extractInfo(event, type = "page") {
|
|
55
|
+
const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
|
|
56
|
+
return {
|
|
57
|
+
point: {
|
|
58
|
+
x: point[`${type}X`],
|
|
59
|
+
y: point[`${type}Y`]
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function addDomEvent(target, eventName, handler, options) {
|
|
64
|
+
const node = isRef(target) ? target.current : runIfFn(target);
|
|
65
|
+
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
66
|
+
return () => {
|
|
67
|
+
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function addPointerEvent(target, event, listener, options) {
|
|
71
|
+
var _a;
|
|
72
|
+
const type = (_a = getEventName(event)) != null ? _a : event;
|
|
73
|
+
return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
|
|
74
|
+
}
|
|
75
|
+
function wrapHandler(fn, filter = false) {
|
|
76
|
+
const listener = (event) => {
|
|
77
|
+
fn(event, extractInfo(event));
|
|
78
|
+
};
|
|
79
|
+
return filter ? filterPrimaryPointer(listener) : listener;
|
|
80
|
+
}
|
|
81
|
+
function filterPrimaryPointer(fn) {
|
|
82
|
+
return (event) => {
|
|
83
|
+
var _a;
|
|
84
|
+
const win = (_a = event.view) != null ? _a : window;
|
|
85
|
+
const isMouseEvent = event instanceof win.MouseEvent;
|
|
86
|
+
const isPrimary = !isMouseEvent || isMouseEvent && event.button === 0;
|
|
87
|
+
if (isPrimary)
|
|
88
|
+
fn(event);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
var mouseEventNames = {
|
|
92
|
+
pointerdown: "mousedown",
|
|
93
|
+
pointermove: "mousemove",
|
|
94
|
+
pointerup: "mouseup",
|
|
95
|
+
pointercancel: "mousecancel",
|
|
96
|
+
pointerover: "mouseover",
|
|
97
|
+
pointerout: "mouseout",
|
|
98
|
+
pointerenter: "mouseenter",
|
|
99
|
+
pointerleave: "mouseleave"
|
|
100
|
+
};
|
|
101
|
+
var touchEventNames = {
|
|
102
|
+
pointerdown: "touchstart",
|
|
103
|
+
pointermove: "touchmove",
|
|
104
|
+
pointerup: "touchend",
|
|
105
|
+
pointercancel: "touchcancel"
|
|
106
|
+
};
|
|
107
|
+
function getEventName(evt) {
|
|
108
|
+
if (supportsPointerEvent())
|
|
109
|
+
return evt;
|
|
110
|
+
if (supportsTouchEvent())
|
|
111
|
+
return touchEventNames[evt];
|
|
112
|
+
if (supportsMouseEvent())
|
|
113
|
+
return mouseEventNames[evt];
|
|
114
|
+
return evt;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ../../utilities/dom/src/next-tick.ts
|
|
118
|
+
function raf(fn) {
|
|
119
|
+
const id = globalThis.requestAnimationFrame(fn);
|
|
120
|
+
return function cleanup() {
|
|
121
|
+
globalThis.cancelAnimationFrame(id);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ../../utilities/dom/src/pointerlock.ts
|
|
126
|
+
function addPointerlockChangeListener(doc, fn) {
|
|
127
|
+
return addDomEvent(doc, "pointerlockchange", fn, false);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/tooltip.machine.ts
|
|
131
|
+
import { getPlacement } from "@zag-js/popper";
|
|
132
|
+
function machine(userContext) {
|
|
133
|
+
const ctx = compact(userContext);
|
|
134
|
+
return createMachine(
|
|
135
|
+
{
|
|
136
|
+
id: "tooltip",
|
|
137
|
+
initial: "unknown",
|
|
138
|
+
context: {
|
|
139
|
+
openDelay: 1e3,
|
|
140
|
+
closeDelay: 500,
|
|
141
|
+
closeOnPointerDown: true,
|
|
142
|
+
closeOnEsc: true,
|
|
143
|
+
interactive: true,
|
|
144
|
+
currentPlacement: void 0,
|
|
145
|
+
...ctx,
|
|
146
|
+
positioning: {
|
|
147
|
+
placement: "bottom",
|
|
148
|
+
...ctx.positioning
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
computed: {
|
|
152
|
+
hasAriaLabel: (ctx2) => !!ctx2["aria-label"]
|
|
153
|
+
},
|
|
154
|
+
watch: {
|
|
155
|
+
disabled: ["closeIfDisabled"]
|
|
156
|
+
},
|
|
157
|
+
on: {
|
|
158
|
+
OPEN: "open",
|
|
159
|
+
CLOSE: "closed"
|
|
160
|
+
},
|
|
161
|
+
states: {
|
|
162
|
+
unknown: {
|
|
163
|
+
on: {
|
|
164
|
+
SETUP: "closed"
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
closed: {
|
|
168
|
+
tags: ["closed"],
|
|
169
|
+
entry: ["clearGlobalId", "invokeOnClose"],
|
|
170
|
+
on: {
|
|
171
|
+
FOCUS: "open",
|
|
172
|
+
POINTER_ENTER: [
|
|
173
|
+
{
|
|
174
|
+
guard: "noVisibleTooltip",
|
|
175
|
+
target: "opening"
|
|
176
|
+
},
|
|
177
|
+
{ target: "open" }
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
opening: {
|
|
182
|
+
tags: ["closed"],
|
|
183
|
+
activities: ["trackScroll", "trackPointerlockChange"],
|
|
184
|
+
after: {
|
|
185
|
+
OPEN_DELAY: "open"
|
|
186
|
+
},
|
|
187
|
+
on: {
|
|
188
|
+
POINTER_LEAVE: "closed",
|
|
189
|
+
BLUR: "closed",
|
|
190
|
+
SCROLL: "closed",
|
|
191
|
+
POINTER_LOCK_CHANGE: "closed",
|
|
192
|
+
POINTER_DOWN: {
|
|
193
|
+
guard: "closeOnPointerDown",
|
|
194
|
+
target: "closed"
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
open: {
|
|
199
|
+
tags: ["open"],
|
|
200
|
+
activities: [
|
|
201
|
+
"trackEscapeKey",
|
|
202
|
+
"trackDisabledTriggerOnSafari",
|
|
203
|
+
"trackScroll",
|
|
204
|
+
"trackPointerlockChange",
|
|
205
|
+
"computePlacement"
|
|
206
|
+
],
|
|
207
|
+
entry: ["setGlobalId", "invokeOnOpen"],
|
|
208
|
+
on: {
|
|
209
|
+
POINTER_LEAVE: [
|
|
210
|
+
{
|
|
211
|
+
guard: "isVisible",
|
|
212
|
+
target: "closing"
|
|
213
|
+
},
|
|
214
|
+
{ target: "closed" }
|
|
215
|
+
],
|
|
216
|
+
BLUR: "closed",
|
|
217
|
+
ESCAPE: "closed",
|
|
218
|
+
SCROLL: "closed",
|
|
219
|
+
POINTER_LOCK_CHANGE: "closed",
|
|
220
|
+
TOOLTIP_POINTER_LEAVE: {
|
|
221
|
+
guard: "isInteractive",
|
|
222
|
+
target: "closing"
|
|
223
|
+
},
|
|
224
|
+
POINTER_DOWN: {
|
|
225
|
+
guard: "closeOnPointerDown",
|
|
226
|
+
target: "closed"
|
|
227
|
+
},
|
|
228
|
+
CLICK: "closed"
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
closing: {
|
|
232
|
+
tags: ["open"],
|
|
233
|
+
activities: ["trackStore", "computePlacement"],
|
|
234
|
+
after: {
|
|
235
|
+
CLOSE_DELAY: "closed"
|
|
236
|
+
},
|
|
237
|
+
on: {
|
|
238
|
+
FORCE_CLOSE: "closed",
|
|
239
|
+
POINTER_ENTER: "open",
|
|
240
|
+
TOOLTIP_POINTER_ENTER: {
|
|
241
|
+
guard: "isInteractive",
|
|
242
|
+
target: "open"
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
activities: {
|
|
250
|
+
computePlacement(ctx2) {
|
|
251
|
+
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
252
|
+
let cleanup;
|
|
253
|
+
raf(() => {
|
|
254
|
+
cleanup = getPlacement(dom.getTriggerEl(ctx2), dom.getPositionerEl(ctx2), {
|
|
255
|
+
...ctx2.positioning,
|
|
256
|
+
onComplete(data) {
|
|
257
|
+
ctx2.currentPlacement = data.placement;
|
|
258
|
+
ctx2.isPlacementComplete = true;
|
|
259
|
+
},
|
|
260
|
+
onCleanup() {
|
|
261
|
+
ctx2.currentPlacement = void 0;
|
|
262
|
+
ctx2.isPlacementComplete = false;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
return cleanup;
|
|
267
|
+
},
|
|
268
|
+
trackPointerlockChange(ctx2, _evt, { send }) {
|
|
269
|
+
return addPointerlockChangeListener(dom.getDoc(ctx2), () => {
|
|
270
|
+
send("POINTER_LOCK_CHANGE");
|
|
271
|
+
});
|
|
272
|
+
},
|
|
273
|
+
trackScroll(ctx2, _evt, { send }) {
|
|
274
|
+
const trigger = dom.getTriggerEl(ctx2);
|
|
275
|
+
if (!trigger)
|
|
276
|
+
return;
|
|
277
|
+
const cleanups = getScrollParents(trigger).map((el) => {
|
|
278
|
+
const opts = { passive: true, capture: true };
|
|
279
|
+
return addDomEvent(el, "scroll", () => send("SCROLL"), opts);
|
|
280
|
+
});
|
|
281
|
+
return () => {
|
|
282
|
+
cleanups.forEach((fn) => fn == null ? void 0 : fn());
|
|
283
|
+
};
|
|
284
|
+
},
|
|
285
|
+
trackStore(ctx2, _evt, { send }) {
|
|
286
|
+
return subscribe(store, () => {
|
|
287
|
+
if (store.id !== ctx2.id) {
|
|
288
|
+
send("FORCE_CLOSE");
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
},
|
|
292
|
+
trackDisabledTriggerOnSafari(ctx2, _evt, { send }) {
|
|
293
|
+
if (!isSafari())
|
|
294
|
+
return;
|
|
295
|
+
const doc = dom.getDoc(ctx2);
|
|
296
|
+
return addPointerEvent(doc, "pointermove", (event) => {
|
|
297
|
+
const selector = "[data-part=trigger][data-expanded]";
|
|
298
|
+
if (isHTMLElement(event.target) && event.target.closest(selector))
|
|
299
|
+
return;
|
|
300
|
+
send("POINTER_LEAVE");
|
|
301
|
+
});
|
|
302
|
+
},
|
|
303
|
+
trackEscapeKey(ctx2, _evt, { send }) {
|
|
304
|
+
if (!ctx2.closeOnEsc)
|
|
305
|
+
return;
|
|
306
|
+
const doc = dom.getDoc(ctx2);
|
|
307
|
+
return addDomEvent(doc, "keydown", (event) => {
|
|
308
|
+
if (event.key === "Escape") {
|
|
309
|
+
send("ESCAPE");
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
actions: {
|
|
315
|
+
setGlobalId(ctx2) {
|
|
316
|
+
store.setId(ctx2.id);
|
|
317
|
+
},
|
|
318
|
+
clearGlobalId(ctx2) {
|
|
319
|
+
if (ctx2.id === store.id) {
|
|
320
|
+
store.setId(null);
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
invokeOnOpen(ctx2, evt) {
|
|
324
|
+
var _a;
|
|
325
|
+
const omit = ["TOOLTIP_POINTER_ENTER", "POINTER_ENTER"];
|
|
326
|
+
if (!omit.includes(evt.type)) {
|
|
327
|
+
(_a = ctx2.onOpen) == null ? void 0 : _a.call(ctx2);
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
invokeOnClose(ctx2, evt) {
|
|
331
|
+
var _a;
|
|
332
|
+
const omit = ["SETUP"];
|
|
333
|
+
if (!omit.includes(evt.type)) {
|
|
334
|
+
(_a = ctx2.onClose) == null ? void 0 : _a.call(ctx2);
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
closeIfDisabled(ctx2, _evt, { send }) {
|
|
338
|
+
if (ctx2.disabled) {
|
|
339
|
+
send("CLOSE");
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
guards: {
|
|
344
|
+
closeOnPointerDown: (ctx2) => ctx2.closeOnPointerDown,
|
|
345
|
+
noVisibleTooltip: () => store.id === null,
|
|
346
|
+
isVisible: (ctx2) => ctx2.id === store.id,
|
|
347
|
+
isInteractive: (ctx2) => ctx2.interactive
|
|
348
|
+
},
|
|
349
|
+
delays: {
|
|
350
|
+
OPEN_DELAY: (ctx2) => ctx2.openDelay,
|
|
351
|
+
CLOSE_DELAY: (ctx2) => ctx2.closeDelay
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export {
|
|
358
|
+
machine
|
|
359
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// ../../utilities/dom/src/get-computed-style.ts
|
|
2
|
+
function getCache() {
|
|
3
|
+
const g = globalThis;
|
|
4
|
+
g.__styleCache = g.__styleCache || /* @__PURE__ */ new WeakMap();
|
|
5
|
+
return g.__styleCache;
|
|
6
|
+
}
|
|
7
|
+
function getComputedStyle(el) {
|
|
8
|
+
var _a;
|
|
9
|
+
if (!el)
|
|
10
|
+
return {};
|
|
11
|
+
const cache = getCache();
|
|
12
|
+
let style = cache.get(el);
|
|
13
|
+
if (!style) {
|
|
14
|
+
const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
15
|
+
style = win.getComputedStyle(el);
|
|
16
|
+
cache.set(el, style);
|
|
17
|
+
}
|
|
18
|
+
return style;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// ../../utilities/dom/src/query.ts
|
|
22
|
+
function isDocument(el) {
|
|
23
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
24
|
+
}
|
|
25
|
+
function isWindow(value) {
|
|
26
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
27
|
+
}
|
|
28
|
+
function getDocument(el) {
|
|
29
|
+
var _a;
|
|
30
|
+
if (isWindow(el))
|
|
31
|
+
return el.document;
|
|
32
|
+
if (isDocument(el))
|
|
33
|
+
return el;
|
|
34
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
35
|
+
}
|
|
36
|
+
function getWindow(el) {
|
|
37
|
+
var _a;
|
|
38
|
+
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
39
|
+
}
|
|
40
|
+
function getNodeName(node) {
|
|
41
|
+
var _a;
|
|
42
|
+
return isWindow(node) ? "" : (_a = node == null ? void 0 : node.localName) != null ? _a : "";
|
|
43
|
+
}
|
|
44
|
+
function getParent(el) {
|
|
45
|
+
const doc = getDocument(el);
|
|
46
|
+
if (getNodeName(el) === "html")
|
|
47
|
+
return el;
|
|
48
|
+
return el.assignedSlot || el.parentElement || doc.documentElement;
|
|
49
|
+
}
|
|
50
|
+
function defineDomHelpers(helpers) {
|
|
51
|
+
const dom2 = {
|
|
52
|
+
getRootNode: (ctx) => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
55
|
+
},
|
|
56
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
57
|
+
getWin: (ctx) => {
|
|
58
|
+
var _a;
|
|
59
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
60
|
+
},
|
|
61
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
62
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
63
|
+
createEmitter: (ctx, target) => {
|
|
64
|
+
const win = dom2.getWin(ctx);
|
|
65
|
+
return function emit(evt, detail, options) {
|
|
66
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
67
|
+
const eventName = `zag:${evt}`;
|
|
68
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
69
|
+
const event = new win.CustomEvent(eventName, init);
|
|
70
|
+
target.dispatchEvent(event);
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
createListener: (target) => {
|
|
74
|
+
return function listen(evt, handler) {
|
|
75
|
+
const eventName = `zag:${evt}`;
|
|
76
|
+
const listener = (e) => handler(e);
|
|
77
|
+
target.addEventListener(eventName, listener);
|
|
78
|
+
return () => target.removeEventListener(eventName, listener);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
...dom2,
|
|
84
|
+
...helpers
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function isHTMLElement(v) {
|
|
88
|
+
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ../../utilities/dom/src/scrollable.ts
|
|
92
|
+
function isScrollParent(el) {
|
|
93
|
+
const { overflow, overflowX, overflowY } = getComputedStyle(el);
|
|
94
|
+
return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
|
|
95
|
+
}
|
|
96
|
+
function getScrollParent(el) {
|
|
97
|
+
if (["html", "body", "#document"].includes(getNodeName(el))) {
|
|
98
|
+
return getDocument(el).body;
|
|
99
|
+
}
|
|
100
|
+
if (isHTMLElement(el) && isScrollParent(el)) {
|
|
101
|
+
return el;
|
|
102
|
+
}
|
|
103
|
+
return getScrollParent(getParent(el));
|
|
104
|
+
}
|
|
105
|
+
function getScrollParents(el, list = []) {
|
|
106
|
+
const scrollParent = getScrollParent(el);
|
|
107
|
+
const isBody = scrollParent === getDocument(el).body;
|
|
108
|
+
const win = getWindow(scrollParent);
|
|
109
|
+
const target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
|
|
110
|
+
const parents = list.concat(target);
|
|
111
|
+
if (isBody)
|
|
112
|
+
return parents;
|
|
113
|
+
return parents.concat(getScrollParents(getParent(target)));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/tooltip.dom.ts
|
|
117
|
+
var dom = defineDomHelpers({
|
|
118
|
+
getTriggerId: (ctx) => {
|
|
119
|
+
var _a, _b;
|
|
120
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tooltip:${ctx.id}:trigger`;
|
|
121
|
+
},
|
|
122
|
+
getContentId: (ctx) => {
|
|
123
|
+
var _a, _b;
|
|
124
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tooltip:${ctx.id}:content`;
|
|
125
|
+
},
|
|
126
|
+
getArrowId: (ctx) => `tooltip:${ctx.id}:arrow`,
|
|
127
|
+
getPositionerId: (ctx) => `tooltip:${ctx.id}:popper`,
|
|
128
|
+
portalId: "tooltip-portal",
|
|
129
|
+
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
|
130
|
+
getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
|
|
131
|
+
getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
|
|
132
|
+
getArrowEl: (ctx) => dom.getById(ctx, dom.getArrowId(ctx)),
|
|
133
|
+
getScrollParent: (ctx) => getScrollParent(dom.getTriggerEl(ctx)),
|
|
134
|
+
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.portalId),
|
|
135
|
+
createPortalEl: (ctx) => {
|
|
136
|
+
const portal = dom.getDoc(ctx).createElement(dom.portalId);
|
|
137
|
+
portal.id = dom.portalId;
|
|
138
|
+
return portal;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
export {
|
|
143
|
+
isHTMLElement,
|
|
144
|
+
getScrollParents,
|
|
145
|
+
dom
|
|
146
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parts
|
|
3
|
+
} from "./chunk-RRQRIZBA.mjs";
|
|
4
|
+
import {
|
|
5
|
+
dom
|
|
6
|
+
} from "./chunk-PFKIRGNP.mjs";
|
|
7
|
+
import {
|
|
8
|
+
store
|
|
9
|
+
} from "./chunk-GQYNO326.mjs";
|
|
10
|
+
|
|
11
|
+
// ../../utilities/dom/src/attrs.ts
|
|
12
|
+
var dataAttr = (guard) => {
|
|
13
|
+
return guard ? "" : void 0;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// ../../utilities/dom/src/visually-hidden.ts
|
|
17
|
+
var visuallyHiddenStyle = {
|
|
18
|
+
border: "0",
|
|
19
|
+
clip: "rect(0 0 0 0)",
|
|
20
|
+
height: "1px",
|
|
21
|
+
margin: "-1px",
|
|
22
|
+
overflow: "hidden",
|
|
23
|
+
padding: "0",
|
|
24
|
+
position: "absolute",
|
|
25
|
+
width: "1px",
|
|
26
|
+
whiteSpace: "nowrap",
|
|
27
|
+
wordWrap: "normal"
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// src/tooltip.connect.ts
|
|
31
|
+
import { getPlacementStyles } from "@zag-js/popper";
|
|
32
|
+
function connect(state, send, normalize) {
|
|
33
|
+
const id = state.context.id;
|
|
34
|
+
const hasAriaLabel = state.context.hasAriaLabel;
|
|
35
|
+
const isOpen = state.hasTag("open");
|
|
36
|
+
const triggerId = dom.getTriggerId(state.context);
|
|
37
|
+
const contentId = dom.getContentId(state.context);
|
|
38
|
+
const isDisabled = state.context.disabled;
|
|
39
|
+
const popperStyles = getPlacementStyles({
|
|
40
|
+
measured: !!state.context.isPlacementComplete,
|
|
41
|
+
placement: state.context.currentPlacement
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
isOpen,
|
|
45
|
+
open() {
|
|
46
|
+
send("OPEN");
|
|
47
|
+
},
|
|
48
|
+
close() {
|
|
49
|
+
send("CLOSE");
|
|
50
|
+
},
|
|
51
|
+
getAnimationState() {
|
|
52
|
+
return {
|
|
53
|
+
enter: store.prevId === null && id === store.id,
|
|
54
|
+
exit: store.id === null
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
triggerProps: normalize.button({
|
|
58
|
+
...parts.trigger.attrs,
|
|
59
|
+
id: triggerId,
|
|
60
|
+
"data-expanded": dataAttr(isOpen),
|
|
61
|
+
"aria-describedby": isOpen ? contentId : void 0,
|
|
62
|
+
onClick() {
|
|
63
|
+
send("CLICK");
|
|
64
|
+
},
|
|
65
|
+
onFocus() {
|
|
66
|
+
send("FOCUS");
|
|
67
|
+
},
|
|
68
|
+
onBlur() {
|
|
69
|
+
if (id === store.id) {
|
|
70
|
+
send("BLUR");
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
onPointerDown() {
|
|
74
|
+
if (isDisabled)
|
|
75
|
+
return;
|
|
76
|
+
if (id === store.id) {
|
|
77
|
+
send("POINTER_DOWN");
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
onPointerMove() {
|
|
81
|
+
if (isDisabled)
|
|
82
|
+
return;
|
|
83
|
+
send("POINTER_ENTER");
|
|
84
|
+
},
|
|
85
|
+
onPointerLeave() {
|
|
86
|
+
if (isDisabled)
|
|
87
|
+
return;
|
|
88
|
+
send("POINTER_LEAVE");
|
|
89
|
+
},
|
|
90
|
+
onPointerCancel() {
|
|
91
|
+
if (isDisabled)
|
|
92
|
+
return;
|
|
93
|
+
send("POINTER_LEAVE");
|
|
94
|
+
}
|
|
95
|
+
}),
|
|
96
|
+
arrowProps: normalize.element({
|
|
97
|
+
id: dom.getArrowId(state.context),
|
|
98
|
+
...parts.arrow.attrs,
|
|
99
|
+
style: popperStyles.arrow
|
|
100
|
+
}),
|
|
101
|
+
arrowTipProps: normalize.element({
|
|
102
|
+
...parts.arrowTip.attrs,
|
|
103
|
+
style: popperStyles.arrowTip
|
|
104
|
+
}),
|
|
105
|
+
positionerProps: normalize.element({
|
|
106
|
+
id: dom.getPositionerId(state.context),
|
|
107
|
+
...parts.positioner.attrs,
|
|
108
|
+
style: popperStyles.floating
|
|
109
|
+
}),
|
|
110
|
+
contentProps: normalize.element({
|
|
111
|
+
...parts.content.attrs,
|
|
112
|
+
hidden: !isOpen,
|
|
113
|
+
role: hasAriaLabel ? void 0 : "tooltip",
|
|
114
|
+
id: hasAriaLabel ? void 0 : contentId,
|
|
115
|
+
"data-placement": state.context.currentPlacement,
|
|
116
|
+
onPointerEnter() {
|
|
117
|
+
send("TOOLTIP_POINTER_ENTER");
|
|
118
|
+
},
|
|
119
|
+
onPointerLeave() {
|
|
120
|
+
send("TOOLTIP_POINTER_LEAVE");
|
|
121
|
+
},
|
|
122
|
+
style: {
|
|
123
|
+
pointerEvents: state.context.interactive ? "auto" : "none"
|
|
124
|
+
}
|
|
125
|
+
}),
|
|
126
|
+
labelProps: normalize.element({
|
|
127
|
+
...parts.label.attrs,
|
|
128
|
+
id: contentId,
|
|
129
|
+
role: "tooltip",
|
|
130
|
+
style: visuallyHiddenStyle,
|
|
131
|
+
children: state.context["aria-label"]
|
|
132
|
+
}),
|
|
133
|
+
createPortal() {
|
|
134
|
+
const doc = dom.getDoc(state.context);
|
|
135
|
+
const exist = dom.getPortalEl(state.context);
|
|
136
|
+
if (exist)
|
|
137
|
+
return exist;
|
|
138
|
+
const portal = dom.createPortalEl(state.context);
|
|
139
|
+
doc.body.appendChild(portal);
|
|
140
|
+
return portal;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export {
|
|
146
|
+
connect
|
|
147
|
+
};
|