@zag-js/tooltip 0.1.6 → 0.1.9
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.d.ts +0 -1
- package/dist/index.js +83 -193
- package/dist/index.mjs +82 -193
- package/dist/tooltip.connect.d.ts +3 -4
- package/dist/tooltip.dom.d.ts +1 -2
- package/dist/tooltip.machine.d.ts +1 -2
- package/dist/tooltip.store.d.ts +0 -1
- package/dist/tooltip.types.d.ts +2 -3
- package/package.json +5 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -7
- package/dist/index.mjs.map +0 -7
- package/dist/tooltip.connect.d.ts.map +0 -1
- package/dist/tooltip.dom.d.ts.map +0 -1
- package/dist/tooltip.machine.d.ts.map +0 -1
- package/dist/tooltip.store.d.ts.map +0 -1
- package/dist/tooltip.types.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -45,16 +46,16 @@ module.exports = __toCommonJS(src_exports);
|
|
|
45
46
|
var dataAttr = (guard) => {
|
|
46
47
|
return guard ? "" : void 0;
|
|
47
48
|
};
|
|
48
|
-
function
|
|
49
|
-
;
|
|
50
|
-
|
|
51
|
-
return
|
|
49
|
+
function getCache() {
|
|
50
|
+
const g = globalThis;
|
|
51
|
+
g.__styleCache = g.__styleCache || /* @__PURE__ */ new WeakMap();
|
|
52
|
+
return g.__styleCache;
|
|
52
53
|
}
|
|
53
|
-
function
|
|
54
|
+
function getComputedStyle(el) {
|
|
54
55
|
var _a;
|
|
55
56
|
if (!el)
|
|
56
57
|
return {};
|
|
57
|
-
const cache =
|
|
58
|
+
const cache = getCache();
|
|
58
59
|
let style = cache.get(el);
|
|
59
60
|
if (!style) {
|
|
60
61
|
const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
@@ -63,83 +64,57 @@ function getComputedStyle2(el) {
|
|
|
63
64
|
}
|
|
64
65
|
return style;
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
return
|
|
69
|
-
globalThis.cancelAnimationFrame(id);
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
var noop = () => {
|
|
67
|
+
var runIfFn = (v, ...a) => {
|
|
68
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
69
|
+
return res != null ? res : void 0;
|
|
73
70
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
var isArray = (v) => Array.isArray(v);
|
|
72
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
73
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
74
|
+
var isDom = () => typeof window !== "undefined";
|
|
75
|
+
function getPlatform() {
|
|
76
|
+
var _a;
|
|
77
|
+
const agent = navigator.userAgentData;
|
|
78
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
var pt = (v) => isDom() && v.test(getPlatform());
|
|
81
|
+
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
82
|
+
var isSafari = () => isApple() && vn(/apple/i);
|
|
83
|
+
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
84
|
+
function isWindow(value) {
|
|
85
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
83
86
|
}
|
|
84
|
-
function
|
|
87
|
+
function getDocument(el) {
|
|
85
88
|
var _a;
|
|
86
|
-
if (
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
} else {
|
|
98
|
-
group == null ? void 0 : group.set(hash, /* @__PURE__ */ new Set([handler]));
|
|
99
|
-
}
|
|
100
|
-
function attach(node2) {
|
|
101
|
-
var _a2, _b;
|
|
102
|
-
function listener(event) {
|
|
103
|
-
var _a3;
|
|
104
|
-
const group2 = listenerElements.get(node2);
|
|
105
|
-
(_a3 = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _a3.forEach((fn) => fn(event));
|
|
106
|
-
}
|
|
107
|
-
if (!(listenerCache == null ? void 0 : listenerCache.has(node2))) {
|
|
108
|
-
listenerCache.set(node2, /* @__PURE__ */ new Map([[hash, listener]]));
|
|
109
|
-
node2.addEventListener(type, listener, options);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (!((_a2 = listenerCache == null ? void 0 : listenerCache.get(node2)) == null ? void 0 : _a2.has(hash))) {
|
|
113
|
-
(_b = listenerCache.get(node2)) == null ? void 0 : _b.set(hash, listener);
|
|
114
|
-
node2.addEventListener(type, listener, options);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
attach(node);
|
|
118
|
-
return function remove() {
|
|
119
|
-
var _a2, _b, _c, _d;
|
|
120
|
-
if (!listenerElements.has(node))
|
|
121
|
-
return;
|
|
122
|
-
const group2 = listenerElements.get(node);
|
|
123
|
-
(_a2 = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _a2.delete(handler);
|
|
124
|
-
if (((_b = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _b.size) === 0) {
|
|
125
|
-
const listener = (_c = listenerCache.get(node)) == null ? void 0 : _c.get(hash);
|
|
126
|
-
node.removeEventListener(type, listener, options);
|
|
127
|
-
group2 == null ? void 0 : group2.delete(hash);
|
|
128
|
-
(_d = listenerCache.get(node)) == null ? void 0 : _d.delete(hash);
|
|
129
|
-
if ((group2 == null ? void 0 : group2.size) === 0) {
|
|
130
|
-
listenerElements.delete(node);
|
|
131
|
-
listenerCache.delete(node);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
89
|
+
if (isWindow(el))
|
|
90
|
+
return el.document;
|
|
91
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
92
|
+
}
|
|
93
|
+
function getWindow(el) {
|
|
94
|
+
var _a;
|
|
95
|
+
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
96
|
+
}
|
|
97
|
+
function getNodeName(node) {
|
|
98
|
+
var _a;
|
|
99
|
+
return isWindow(node) ? "" : (_a = node == null ? void 0 : node.localName) != null ? _a : "";
|
|
135
100
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
101
|
+
function getParent(el) {
|
|
102
|
+
const doc = getDocument(el);
|
|
103
|
+
if (getNodeName(el) === "html")
|
|
104
|
+
return el;
|
|
105
|
+
return el.assignedSlot || el.parentElement || doc.documentElement;
|
|
106
|
+
}
|
|
107
|
+
function isHTMLElement(v) {
|
|
108
|
+
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
109
|
+
}
|
|
110
|
+
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
111
|
+
var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
|
|
112
|
+
var supportsMouseEvent = () => isDom() && window.onmousedown === null;
|
|
113
|
+
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
114
|
+
var isRef = (v) => hasProp(v, "current");
|
|
115
|
+
var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
|
|
141
116
|
function extractInfo(event, type = "page") {
|
|
142
|
-
const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] ||
|
|
117
|
+
const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback2 : event;
|
|
143
118
|
return {
|
|
144
119
|
point: {
|
|
145
120
|
x: point[`${type}X`],
|
|
@@ -147,9 +122,12 @@ function extractInfo(event, type = "page") {
|
|
|
147
122
|
}
|
|
148
123
|
};
|
|
149
124
|
}
|
|
150
|
-
function addDomEvent(target,
|
|
125
|
+
function addDomEvent(target, eventName, handler, options) {
|
|
151
126
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
152
|
-
|
|
127
|
+
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
128
|
+
return () => {
|
|
129
|
+
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
130
|
+
};
|
|
153
131
|
}
|
|
154
132
|
function addPointerEvent(target, event, listener, options) {
|
|
155
133
|
var _a;
|
|
@@ -172,9 +150,6 @@ function filterPrimaryPointer(fn) {
|
|
|
172
150
|
fn(event);
|
|
173
151
|
};
|
|
174
152
|
}
|
|
175
|
-
var supportsPointerEvent = () => typeof window !== "undefined" && window.onpointerdown === null;
|
|
176
|
-
var supportsTouchEvent = () => typeof window !== "undefined" && window.ontouchstart === null;
|
|
177
|
-
var supportsMouseEvent = () => typeof window !== "undefined" && window.onmousedown === null;
|
|
178
153
|
var mouseEventNames = {
|
|
179
154
|
pointerdown: "mousedown",
|
|
180
155
|
pointermove: "mousemove",
|
|
@@ -200,38 +175,34 @@ function getEventName(evt) {
|
|
|
200
175
|
return mouseEventNames[evt];
|
|
201
176
|
return evt;
|
|
202
177
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return el.assignedSlot || el.parentElement || doc.documentElement;
|
|
221
|
-
}
|
|
222
|
-
function isHTMLElement(v) {
|
|
223
|
-
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
178
|
+
var visuallyHiddenStyle = {
|
|
179
|
+
border: "0",
|
|
180
|
+
clip: "rect(0 0 0 0)",
|
|
181
|
+
height: "1px",
|
|
182
|
+
margin: "-1px",
|
|
183
|
+
overflow: "hidden",
|
|
184
|
+
padding: "0",
|
|
185
|
+
position: "absolute",
|
|
186
|
+
width: "1px",
|
|
187
|
+
whiteSpace: "nowrap",
|
|
188
|
+
wordWrap: "normal"
|
|
189
|
+
};
|
|
190
|
+
function raf(fn) {
|
|
191
|
+
const id = globalThis.requestAnimationFrame(fn);
|
|
192
|
+
return function cleanup() {
|
|
193
|
+
globalThis.cancelAnimationFrame(id);
|
|
194
|
+
};
|
|
224
195
|
}
|
|
225
|
-
function
|
|
226
|
-
return (
|
|
196
|
+
function addPointerlockChangeListener(doc, fn) {
|
|
197
|
+
return addDomEvent(doc, "pointerlockchange", fn, false);
|
|
227
198
|
}
|
|
228
199
|
function isScrollParent(el) {
|
|
229
|
-
const { overflow, overflowX, overflowY } =
|
|
200
|
+
const { overflow, overflowX, overflowY } = getComputedStyle(el);
|
|
230
201
|
return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
|
|
231
202
|
}
|
|
232
203
|
function getScrollParent(el) {
|
|
233
204
|
if (["html", "body", "#document"].includes(getNodeName(el))) {
|
|
234
|
-
return
|
|
205
|
+
return getDocument(el).body;
|
|
235
206
|
}
|
|
236
207
|
if (isHTMLElement(el) && isScrollParent(el)) {
|
|
237
208
|
return el;
|
|
@@ -240,95 +211,18 @@ function getScrollParent(el) {
|
|
|
240
211
|
}
|
|
241
212
|
function getScrollParents(el, list = []) {
|
|
242
213
|
const scrollParent = getScrollParent(el);
|
|
243
|
-
const isBody = scrollParent ===
|
|
244
|
-
const win =
|
|
214
|
+
const isBody = scrollParent === getDocument(el).body;
|
|
215
|
+
const win = getWindow(scrollParent);
|
|
245
216
|
const target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
|
|
246
217
|
const parents = list.concat(target);
|
|
247
218
|
if (isBody)
|
|
248
219
|
return parents;
|
|
249
220
|
return parents.concat(getScrollParents(getParent(target)));
|
|
250
221
|
}
|
|
251
|
-
var visuallyHiddenStyle = {
|
|
252
|
-
border: "0",
|
|
253
|
-
clip: "rect(0 0 0 0)",
|
|
254
|
-
height: "1px",
|
|
255
|
-
margin: "-1px",
|
|
256
|
-
overflow: "hidden",
|
|
257
|
-
padding: "0",
|
|
258
|
-
position: "absolute",
|
|
259
|
-
width: "1px",
|
|
260
|
-
whiteSpace: "nowrap",
|
|
261
|
-
wordWrap: "normal"
|
|
262
|
-
};
|
|
263
|
-
function itemById(v, id) {
|
|
264
|
-
return v.find((node) => node.id === id);
|
|
265
|
-
}
|
|
266
|
-
function indexOfId(v, id) {
|
|
267
|
-
const item = itemById(v, id);
|
|
268
|
-
return item ? v.indexOf(item) : -1;
|
|
269
|
-
}
|
|
270
|
-
var getValueText = (item) => {
|
|
271
|
-
var _a, _b;
|
|
272
|
-
return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
|
|
273
|
-
};
|
|
274
|
-
var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
|
|
275
|
-
var wrap = (v, idx) => {
|
|
276
|
-
return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
|
|
277
|
-
};
|
|
278
|
-
function findByText(v, text, currentId) {
|
|
279
|
-
const index = currentId ? indexOfId(v, currentId) : -1;
|
|
280
|
-
let items = currentId ? wrap(v, index) : v;
|
|
281
|
-
const isSingleKey = text.length === 1;
|
|
282
|
-
if (isSingleKey) {
|
|
283
|
-
items = items.filter((item) => item.id !== currentId);
|
|
284
|
-
}
|
|
285
|
-
return items.find((item) => match(getValueText(item), text));
|
|
286
|
-
}
|
|
287
|
-
function addPointerlockChangeListener(doc, fn) {
|
|
288
|
-
return addDomEvent(doc, "pointerlockchange", fn, false);
|
|
289
|
-
}
|
|
290
|
-
function findByTypeahead(_items, options) {
|
|
291
|
-
const { state: state2, activeId, key, timeout = 350 } = options;
|
|
292
|
-
const search = state2.keysSoFar + key;
|
|
293
|
-
const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
|
|
294
|
-
const query2 = isRepeated ? search[0] : search;
|
|
295
|
-
let items = _items.slice();
|
|
296
|
-
const next = findByText(items, query2, activeId);
|
|
297
|
-
function cleanup() {
|
|
298
|
-
clearTimeout(state2.timer);
|
|
299
|
-
state2.timer = -1;
|
|
300
|
-
}
|
|
301
|
-
function update(value) {
|
|
302
|
-
state2.keysSoFar = value;
|
|
303
|
-
cleanup();
|
|
304
|
-
if (value !== "") {
|
|
305
|
-
state2.timer = +setTimeout(() => {
|
|
306
|
-
update("");
|
|
307
|
-
cleanup();
|
|
308
|
-
}, timeout);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
update(search);
|
|
312
|
-
return next;
|
|
313
|
-
}
|
|
314
|
-
findByTypeahead.defaultOptions = {
|
|
315
|
-
keysSoFar: "",
|
|
316
|
-
timer: -1
|
|
317
|
-
};
|
|
318
222
|
|
|
319
223
|
// src/tooltip.connect.ts
|
|
320
224
|
var import_popper = require("@zag-js/popper");
|
|
321
225
|
|
|
322
|
-
// ../../types/dist/index.mjs
|
|
323
|
-
function createNormalizer(fn) {
|
|
324
|
-
return new Proxy({}, {
|
|
325
|
-
get() {
|
|
326
|
-
return fn;
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
var normalizeProp = createNormalizer((v) => v);
|
|
331
|
-
|
|
332
226
|
// src/tooltip.dom.ts
|
|
333
227
|
var dom = {
|
|
334
228
|
getDoc: (ctx) => {
|
|
@@ -379,7 +273,7 @@ var store = (0, import_core.proxy)({
|
|
|
379
273
|
});
|
|
380
274
|
|
|
381
275
|
// src/tooltip.connect.ts
|
|
382
|
-
function connect(state, send, normalize
|
|
276
|
+
function connect(state, send, normalize) {
|
|
383
277
|
const id = state.context.id;
|
|
384
278
|
const hasAriaLabel = state.context.hasAriaLabel;
|
|
385
279
|
const isOpen = state.hasTag("open");
|
|
@@ -487,11 +381,8 @@ var import_core2 = require("@zag-js/core");
|
|
|
487
381
|
var import_popper2 = require("@zag-js/popper");
|
|
488
382
|
|
|
489
383
|
// ../../utilities/core/dist/index.mjs
|
|
490
|
-
var
|
|
384
|
+
var noop = () => {
|
|
491
385
|
};
|
|
492
|
-
var ua = (v) => isDom() && v.test(navigator.userAgent);
|
|
493
|
-
var isDom = () => !!(typeof window !== "undefined");
|
|
494
|
-
var isSafari = () => ua(/^((?!chrome|android).)*safari/i);
|
|
495
386
|
|
|
496
387
|
// src/tooltip.machine.ts
|
|
497
388
|
function machine(ctx = {}) {
|
|
@@ -652,7 +543,7 @@ function machine(ctx = {}) {
|
|
|
652
543
|
},
|
|
653
544
|
trackDisabledTriggerOnSafari(ctx2, _evt, { send }) {
|
|
654
545
|
if (!isSafari())
|
|
655
|
-
return
|
|
546
|
+
return noop;
|
|
656
547
|
const doc = dom.getDoc(ctx2);
|
|
657
548
|
return addPointerEvent(doc, "pointermove", (event) => {
|
|
658
549
|
const selector = "[data-part=trigger][data-expanded]";
|
|
@@ -715,4 +606,3 @@ function machine(ctx = {}) {
|
|
|
715
606
|
}
|
|
716
607
|
});
|
|
717
608
|
}
|
|
718
|
-
//# sourceMappingURL=index.js.map
|