@zag-js/tooltip 0.0.0-dev-20230221113221 → 0.0.0-dev-20230222181847
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-3LXHM7BW.mjs +17 -0
- package/dist/{chunk-YCQQKYLH.mjs → chunk-463EFHFN.mjs} +8 -124
- package/dist/{chunk-VTDFWXSY.mjs → chunk-W3OSVXCZ.mjs} +15 -20
- package/dist/index.js +32 -241
- package/dist/index.mjs +3 -3
- package/dist/tooltip.connect.d.ts +12 -0
- package/dist/tooltip.connect.js +19 -105
- package/dist/tooltip.connect.mjs +2 -2
- package/dist/tooltip.dom.d.ts +2 -2
- package/dist/tooltip.dom.js +3 -84
- package/dist/tooltip.dom.mjs +1 -1
- package/dist/tooltip.machine.js +16 -222
- package/dist/tooltip.machine.mjs +2 -2
- package/package.json +8 -6
- package/dist/chunk-DYQY5P2O.mjs +0 -111
package/dist/tooltip.connect.js
CHANGED
|
@@ -23,108 +23,9 @@ __export(tooltip_connect_exports, {
|
|
|
23
23
|
connect: () => connect
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(tooltip_connect_exports);
|
|
26
|
-
|
|
27
|
-
// ../../utilities/dom/src/attrs.ts
|
|
28
|
-
var dataAttr = (guard) => {
|
|
29
|
-
return guard ? "" : void 0;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// ../../utilities/dom/src/get-computed-style.ts
|
|
33
|
-
function getCache() {
|
|
34
|
-
const g = globalThis;
|
|
35
|
-
g.__styleCache = g.__styleCache || /* @__PURE__ */ new WeakMap();
|
|
36
|
-
return g.__styleCache;
|
|
37
|
-
}
|
|
38
|
-
function getComputedStyle(el) {
|
|
39
|
-
if (!el)
|
|
40
|
-
return {};
|
|
41
|
-
const cache = getCache();
|
|
42
|
-
let style = cache.get(el);
|
|
43
|
-
if (!style) {
|
|
44
|
-
const win = el?.ownerDocument.defaultView ?? window;
|
|
45
|
-
style = win.getComputedStyle(el);
|
|
46
|
-
cache.set(el, style);
|
|
47
|
-
}
|
|
48
|
-
return style;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// ../../utilities/dom/src/query.ts
|
|
52
|
-
function isDocument(el) {
|
|
53
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
54
|
-
}
|
|
55
|
-
function isWindow(value) {
|
|
56
|
-
return value?.toString() === "[object Window]";
|
|
57
|
-
}
|
|
58
|
-
function getDocument(el) {
|
|
59
|
-
if (isWindow(el))
|
|
60
|
-
return el.document;
|
|
61
|
-
if (isDocument(el))
|
|
62
|
-
return el;
|
|
63
|
-
return el?.ownerDocument ?? document;
|
|
64
|
-
}
|
|
65
|
-
function getNodeName(node) {
|
|
66
|
-
return isWindow(node) ? "" : node?.localName ?? "";
|
|
67
|
-
}
|
|
68
|
-
function getParent(el) {
|
|
69
|
-
const doc = getDocument(el);
|
|
70
|
-
if (getNodeName(el) === "html")
|
|
71
|
-
return el;
|
|
72
|
-
return el.assignedSlot || el.parentElement || doc.documentElement;
|
|
73
|
-
}
|
|
74
|
-
function defineDomHelpers(helpers) {
|
|
75
|
-
const dom2 = {
|
|
76
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
77
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
78
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
79
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
80
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
81
|
-
queryById: (ctx, id) => {
|
|
82
|
-
const el = dom2.getById(ctx, id);
|
|
83
|
-
if (!el)
|
|
84
|
-
throw new Error(`Element with id "${id}" not found.`);
|
|
85
|
-
return el;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
return {
|
|
89
|
-
...dom2,
|
|
90
|
-
...helpers
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
function isHTMLElement(v) {
|
|
94
|
-
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// ../../utilities/dom/src/scrollable.ts
|
|
98
|
-
function isScrollParent(el) {
|
|
99
|
-
const { overflow, overflowX, overflowY } = getComputedStyle(el);
|
|
100
|
-
return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
|
|
101
|
-
}
|
|
102
|
-
function getScrollParent(el) {
|
|
103
|
-
if (["html", "body", "#document"].includes(getNodeName(el))) {
|
|
104
|
-
return getDocument(el).body;
|
|
105
|
-
}
|
|
106
|
-
if (isHTMLElement(el) && isScrollParent(el)) {
|
|
107
|
-
return el;
|
|
108
|
-
}
|
|
109
|
-
return getScrollParent(getParent(el));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ../../utilities/dom/src/visually-hidden.ts
|
|
113
|
-
var visuallyHiddenStyle = {
|
|
114
|
-
border: "0",
|
|
115
|
-
clip: "rect(0 0 0 0)",
|
|
116
|
-
height: "1px",
|
|
117
|
-
margin: "-1px",
|
|
118
|
-
overflow: "hidden",
|
|
119
|
-
padding: "0",
|
|
120
|
-
position: "absolute",
|
|
121
|
-
width: "1px",
|
|
122
|
-
whiteSpace: "nowrap",
|
|
123
|
-
wordWrap: "normal"
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
// src/tooltip.connect.ts
|
|
26
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
127
27
|
var import_popper = require("@zag-js/popper");
|
|
28
|
+
var import_visually_hidden = require("@zag-js/visually-hidden");
|
|
128
29
|
|
|
129
30
|
// src/tooltip.anatomy.ts
|
|
130
31
|
var import_anatomy = require("@zag-js/anatomy");
|
|
@@ -132,7 +33,8 @@ var anatomy = (0, import_anatomy.createAnatomy)("tooltip").parts("trigger", "arr
|
|
|
132
33
|
var parts = anatomy.build();
|
|
133
34
|
|
|
134
35
|
// src/tooltip.dom.ts
|
|
135
|
-
var
|
|
36
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
37
|
+
var dom = (0, import_dom_query.createScope)({
|
|
136
38
|
getTriggerId: (ctx) => ctx.ids?.trigger ?? `tooltip:${ctx.id}:trigger`,
|
|
137
39
|
getContentId: (ctx) => ctx.ids?.content ?? `tooltip:${ctx.id}:content`,
|
|
138
40
|
getArrowId: (ctx) => `tooltip:${ctx.id}:arrow`,
|
|
@@ -141,7 +43,7 @@ var dom = defineDomHelpers({
|
|
|
141
43
|
getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
|
|
142
44
|
getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
|
|
143
45
|
getArrowEl: (ctx) => dom.getById(ctx, dom.getArrowId(ctx)),
|
|
144
|
-
getScrollParent: (ctx) => getScrollParent(dom.getTriggerEl(ctx))
|
|
46
|
+
getScrollParent: (ctx) => (0, import_dom_query.getScrollParent)(dom.getTriggerEl(ctx))
|
|
145
47
|
});
|
|
146
48
|
|
|
147
49
|
// src/tooltip.store.ts
|
|
@@ -168,13 +70,25 @@ function connect(state, send, normalize) {
|
|
|
168
70
|
placement: state.context.currentPlacement
|
|
169
71
|
});
|
|
170
72
|
return {
|
|
73
|
+
/**
|
|
74
|
+
* Whether the tooltip is open.
|
|
75
|
+
*/
|
|
171
76
|
isOpen,
|
|
77
|
+
/**
|
|
78
|
+
* Function to open the tooltip.
|
|
79
|
+
*/
|
|
172
80
|
open() {
|
|
173
81
|
send("OPEN");
|
|
174
82
|
},
|
|
83
|
+
/**
|
|
84
|
+
* Function to close the tooltip.
|
|
85
|
+
*/
|
|
175
86
|
close() {
|
|
176
87
|
send("CLOSE");
|
|
177
88
|
},
|
|
89
|
+
/**
|
|
90
|
+
* Returns the animation state of the tooltip.
|
|
91
|
+
*/
|
|
178
92
|
getAnimationState() {
|
|
179
93
|
return {
|
|
180
94
|
enter: store.prevId === null && id === store.id,
|
|
@@ -184,7 +98,7 @@ function connect(state, send, normalize) {
|
|
|
184
98
|
triggerProps: normalize.button({
|
|
185
99
|
...parts.trigger.attrs,
|
|
186
100
|
id: triggerId,
|
|
187
|
-
"data-expanded": dataAttr(isOpen),
|
|
101
|
+
"data-expanded": (0, import_dom_query2.dataAttr)(isOpen),
|
|
188
102
|
"aria-describedby": isOpen ? contentId : void 0,
|
|
189
103
|
onClick() {
|
|
190
104
|
send("CLICK");
|
|
@@ -254,7 +168,7 @@ function connect(state, send, normalize) {
|
|
|
254
168
|
...parts.label.attrs,
|
|
255
169
|
id: contentId,
|
|
256
170
|
role: "tooltip",
|
|
257
|
-
style: visuallyHiddenStyle,
|
|
171
|
+
style: import_visually_hidden.visuallyHiddenStyle,
|
|
258
172
|
children: state.context["aria-label"]
|
|
259
173
|
})
|
|
260
174
|
};
|
package/dist/tooltip.connect.mjs
CHANGED
package/dist/tooltip.dom.d.ts
CHANGED
|
@@ -16,10 +16,10 @@ declare const dom: {
|
|
|
16
16
|
getActiveElement: (ctx: {
|
|
17
17
|
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
18
18
|
}) => HTMLElement | null;
|
|
19
|
-
getById: <T = HTMLElement>(ctx: {
|
|
19
|
+
getById: <T extends HTMLElement = HTMLElement>(ctx: {
|
|
20
20
|
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
21
21
|
}, id: string) => T | null;
|
|
22
|
-
queryById: <T_1 = HTMLElement>(ctx: {
|
|
22
|
+
queryById: <T_1 extends HTMLElement = HTMLElement>(ctx: {
|
|
23
23
|
getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
|
|
24
24
|
}, id: string) => T_1;
|
|
25
25
|
} & {
|
package/dist/tooltip.dom.js
CHANGED
|
@@ -23,89 +23,8 @@ __export(tooltip_dom_exports, {
|
|
|
23
23
|
dom: () => dom
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(tooltip_dom_exports);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function getCache() {
|
|
29
|
-
const g = globalThis;
|
|
30
|
-
g.__styleCache = g.__styleCache || /* @__PURE__ */ new WeakMap();
|
|
31
|
-
return g.__styleCache;
|
|
32
|
-
}
|
|
33
|
-
function getComputedStyle(el) {
|
|
34
|
-
if (!el)
|
|
35
|
-
return {};
|
|
36
|
-
const cache = getCache();
|
|
37
|
-
let style = cache.get(el);
|
|
38
|
-
if (!style) {
|
|
39
|
-
const win = el?.ownerDocument.defaultView ?? window;
|
|
40
|
-
style = win.getComputedStyle(el);
|
|
41
|
-
cache.set(el, style);
|
|
42
|
-
}
|
|
43
|
-
return style;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// ../../utilities/dom/src/query.ts
|
|
47
|
-
function isDocument(el) {
|
|
48
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
49
|
-
}
|
|
50
|
-
function isWindow(value) {
|
|
51
|
-
return value?.toString() === "[object Window]";
|
|
52
|
-
}
|
|
53
|
-
function getDocument(el) {
|
|
54
|
-
if (isWindow(el))
|
|
55
|
-
return el.document;
|
|
56
|
-
if (isDocument(el))
|
|
57
|
-
return el;
|
|
58
|
-
return el?.ownerDocument ?? document;
|
|
59
|
-
}
|
|
60
|
-
function getNodeName(node) {
|
|
61
|
-
return isWindow(node) ? "" : node?.localName ?? "";
|
|
62
|
-
}
|
|
63
|
-
function getParent(el) {
|
|
64
|
-
const doc = getDocument(el);
|
|
65
|
-
if (getNodeName(el) === "html")
|
|
66
|
-
return el;
|
|
67
|
-
return el.assignedSlot || el.parentElement || doc.documentElement;
|
|
68
|
-
}
|
|
69
|
-
function defineDomHelpers(helpers) {
|
|
70
|
-
const dom2 = {
|
|
71
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
72
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
73
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
74
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
75
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
76
|
-
queryById: (ctx, id) => {
|
|
77
|
-
const el = dom2.getById(ctx, id);
|
|
78
|
-
if (!el)
|
|
79
|
-
throw new Error(`Element with id "${id}" not found.`);
|
|
80
|
-
return el;
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
return {
|
|
84
|
-
...dom2,
|
|
85
|
-
...helpers
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
function isHTMLElement(v) {
|
|
89
|
-
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// ../../utilities/dom/src/scrollable.ts
|
|
93
|
-
function isScrollParent(el) {
|
|
94
|
-
const { overflow, overflowX, overflowY } = getComputedStyle(el);
|
|
95
|
-
return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
|
|
96
|
-
}
|
|
97
|
-
function getScrollParent(el) {
|
|
98
|
-
if (["html", "body", "#document"].includes(getNodeName(el))) {
|
|
99
|
-
return getDocument(el).body;
|
|
100
|
-
}
|
|
101
|
-
if (isHTMLElement(el) && isScrollParent(el)) {
|
|
102
|
-
return el;
|
|
103
|
-
}
|
|
104
|
-
return getScrollParent(getParent(el));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// src/tooltip.dom.ts
|
|
108
|
-
var dom = defineDomHelpers({
|
|
26
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
27
|
+
var dom = (0, import_dom_query.createScope)({
|
|
109
28
|
getTriggerId: (ctx) => ctx.ids?.trigger ?? `tooltip:${ctx.id}:trigger`,
|
|
110
29
|
getContentId: (ctx) => ctx.ids?.content ?? `tooltip:${ctx.id}:content`,
|
|
111
30
|
getArrowId: (ctx) => `tooltip:${ctx.id}:arrow`,
|
|
@@ -114,7 +33,7 @@ var dom = defineDomHelpers({
|
|
|
114
33
|
getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
|
|
115
34
|
getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
|
|
116
35
|
getArrowEl: (ctx) => dom.getById(ctx, dom.getArrowId(ctx)),
|
|
117
|
-
getScrollParent: (ctx) => getScrollParent(dom.getTriggerEl(ctx))
|
|
36
|
+
getScrollParent: (ctx) => (0, import_dom_query.getScrollParent)(dom.getTriggerEl(ctx))
|
|
118
37
|
});
|
|
119
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
120
39
|
0 && (module.exports = {
|
package/dist/tooltip.dom.mjs
CHANGED
package/dist/tooltip.machine.js
CHANGED
|
@@ -24,219 +24,14 @@ __export(tooltip_machine_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(tooltip_machine_exports);
|
|
26
26
|
var import_core2 = require("@zag-js/core");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
function getCache() {
|
|
30
|
-
const g = globalThis;
|
|
31
|
-
g.__styleCache = g.__styleCache || /* @__PURE__ */ new WeakMap();
|
|
32
|
-
return g.__styleCache;
|
|
33
|
-
}
|
|
34
|
-
function getComputedStyle(el) {
|
|
35
|
-
if (!el)
|
|
36
|
-
return {};
|
|
37
|
-
const cache = getCache();
|
|
38
|
-
let style = cache.get(el);
|
|
39
|
-
if (!style) {
|
|
40
|
-
const win = el?.ownerDocument.defaultView ?? window;
|
|
41
|
-
style = win.getComputedStyle(el);
|
|
42
|
-
cache.set(el, style);
|
|
43
|
-
}
|
|
44
|
-
return style;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// ../../utilities/core/src/functions.ts
|
|
48
|
-
var runIfFn = (v, ...a) => {
|
|
49
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
50
|
-
return res ?? void 0;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// ../../utilities/core/src/guard.ts
|
|
54
|
-
var isArray = (v) => Array.isArray(v);
|
|
55
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
56
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
57
|
-
|
|
58
|
-
// ../../utilities/core/src/object.ts
|
|
59
|
-
function compact(obj) {
|
|
60
|
-
if (obj === void 0)
|
|
61
|
-
return obj;
|
|
62
|
-
return Object.fromEntries(
|
|
63
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// ../../utilities/dom/src/platform.ts
|
|
68
|
-
var isDom = () => typeof window !== "undefined";
|
|
69
|
-
function getPlatform() {
|
|
70
|
-
const agent = navigator.userAgentData;
|
|
71
|
-
return agent?.platform ?? navigator.platform;
|
|
72
|
-
}
|
|
73
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
74
|
-
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
75
|
-
var isSafari = () => isApple() && vn(/apple/i);
|
|
76
|
-
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
77
|
-
|
|
78
|
-
// ../../utilities/dom/src/query.ts
|
|
79
|
-
function isDocument(el) {
|
|
80
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
81
|
-
}
|
|
82
|
-
function isWindow(value) {
|
|
83
|
-
return value?.toString() === "[object Window]";
|
|
84
|
-
}
|
|
85
|
-
function getDocument(el) {
|
|
86
|
-
if (isWindow(el))
|
|
87
|
-
return el.document;
|
|
88
|
-
if (isDocument(el))
|
|
89
|
-
return el;
|
|
90
|
-
return el?.ownerDocument ?? document;
|
|
91
|
-
}
|
|
92
|
-
function getWindow(el) {
|
|
93
|
-
return el?.ownerDocument.defaultView ?? window;
|
|
94
|
-
}
|
|
95
|
-
function getNodeName(node) {
|
|
96
|
-
return isWindow(node) ? "" : node?.localName ?? "";
|
|
97
|
-
}
|
|
98
|
-
function getParent(el) {
|
|
99
|
-
const doc = getDocument(el);
|
|
100
|
-
if (getNodeName(el) === "html")
|
|
101
|
-
return el;
|
|
102
|
-
return el.assignedSlot || el.parentElement || doc.documentElement;
|
|
103
|
-
}
|
|
104
|
-
function defineDomHelpers(helpers) {
|
|
105
|
-
const dom2 = {
|
|
106
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
107
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
108
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
109
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
110
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
111
|
-
queryById: (ctx, id) => {
|
|
112
|
-
const el = dom2.getById(ctx, id);
|
|
113
|
-
if (!el)
|
|
114
|
-
throw new Error(`Element with id "${id}" not found.`);
|
|
115
|
-
return el;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
return {
|
|
119
|
-
...dom2,
|
|
120
|
-
...helpers
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
function isHTMLElement(v) {
|
|
124
|
-
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// ../../utilities/dom/src/event.ts
|
|
128
|
-
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
129
|
-
var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
|
|
130
|
-
var supportsMouseEvent = () => isDom() && window.onmousedown === null;
|
|
131
|
-
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
132
|
-
|
|
133
|
-
// ../../utilities/dom/src/listener.ts
|
|
134
|
-
var isRef = (v) => hasProp(v, "current");
|
|
135
|
-
var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
|
|
136
|
-
function extractInfo(event, type = "page") {
|
|
137
|
-
const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
|
|
138
|
-
return {
|
|
139
|
-
point: {
|
|
140
|
-
x: point[`${type}X`],
|
|
141
|
-
y: point[`${type}Y`]
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
146
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
147
|
-
node?.addEventListener(eventName, handler, options);
|
|
148
|
-
return () => {
|
|
149
|
-
node?.removeEventListener(eventName, handler, options);
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
function addPointerEvent(target, event, listener, options) {
|
|
153
|
-
const type = getEventName(event) ?? event;
|
|
154
|
-
return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
|
|
155
|
-
}
|
|
156
|
-
function wrapHandler(fn, filter = false) {
|
|
157
|
-
const listener = (event) => {
|
|
158
|
-
fn(event, extractInfo(event));
|
|
159
|
-
};
|
|
160
|
-
return filter ? filterPrimaryPointer(listener) : listener;
|
|
161
|
-
}
|
|
162
|
-
function filterPrimaryPointer(fn) {
|
|
163
|
-
return (event) => {
|
|
164
|
-
const win = event.view ?? window;
|
|
165
|
-
const isMouseEvent = event instanceof win.MouseEvent;
|
|
166
|
-
const isPrimary = !isMouseEvent || isMouseEvent && event.button === 0;
|
|
167
|
-
if (isPrimary)
|
|
168
|
-
fn(event);
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
var mouseEventNames = {
|
|
172
|
-
pointerdown: "mousedown",
|
|
173
|
-
pointermove: "mousemove",
|
|
174
|
-
pointerup: "mouseup",
|
|
175
|
-
pointercancel: "mousecancel",
|
|
176
|
-
pointerover: "mouseover",
|
|
177
|
-
pointerout: "mouseout",
|
|
178
|
-
pointerenter: "mouseenter",
|
|
179
|
-
pointerleave: "mouseleave"
|
|
180
|
-
};
|
|
181
|
-
var touchEventNames = {
|
|
182
|
-
pointerdown: "touchstart",
|
|
183
|
-
pointermove: "touchmove",
|
|
184
|
-
pointerup: "touchend",
|
|
185
|
-
pointercancel: "touchcancel"
|
|
186
|
-
};
|
|
187
|
-
function getEventName(evt) {
|
|
188
|
-
if (supportsPointerEvent())
|
|
189
|
-
return evt;
|
|
190
|
-
if (supportsTouchEvent())
|
|
191
|
-
return touchEventNames[evt];
|
|
192
|
-
if (supportsMouseEvent())
|
|
193
|
-
return mouseEventNames[evt];
|
|
194
|
-
return evt;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// ../../utilities/dom/src/next-tick.ts
|
|
198
|
-
function raf(fn) {
|
|
199
|
-
const id = globalThis.requestAnimationFrame(fn);
|
|
200
|
-
return function cleanup() {
|
|
201
|
-
globalThis.cancelAnimationFrame(id);
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// ../../utilities/dom/src/pointerlock.ts
|
|
206
|
-
function addPointerlockChangeListener(doc, fn) {
|
|
207
|
-
return addDomEvent(doc, "pointerlockchange", fn, false);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// ../../utilities/dom/src/scrollable.ts
|
|
211
|
-
function isScrollParent(el) {
|
|
212
|
-
const { overflow, overflowX, overflowY } = getComputedStyle(el);
|
|
213
|
-
return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
|
|
214
|
-
}
|
|
215
|
-
function getScrollParent(el) {
|
|
216
|
-
if (["html", "body", "#document"].includes(getNodeName(el))) {
|
|
217
|
-
return getDocument(el).body;
|
|
218
|
-
}
|
|
219
|
-
if (isHTMLElement(el) && isScrollParent(el)) {
|
|
220
|
-
return el;
|
|
221
|
-
}
|
|
222
|
-
return getScrollParent(getParent(el));
|
|
223
|
-
}
|
|
224
|
-
function getScrollParents(el, list = []) {
|
|
225
|
-
const scrollParent = getScrollParent(el);
|
|
226
|
-
const isBody = scrollParent === getDocument(el).body;
|
|
227
|
-
const win = getWindow(scrollParent);
|
|
228
|
-
const target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
|
|
229
|
-
const parents = list.concat(target);
|
|
230
|
-
if (isBody)
|
|
231
|
-
return parents;
|
|
232
|
-
return parents.concat(getScrollParents(getParent(target)));
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// src/tooltip.machine.ts
|
|
27
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
28
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
236
29
|
var import_popper = require("@zag-js/popper");
|
|
30
|
+
var import_utils = require("@zag-js/utils");
|
|
237
31
|
|
|
238
32
|
// src/tooltip.dom.ts
|
|
239
|
-
var
|
|
33
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
34
|
+
var dom = (0, import_dom_query.createScope)({
|
|
240
35
|
getTriggerId: (ctx) => ctx.ids?.trigger ?? `tooltip:${ctx.id}:trigger`,
|
|
241
36
|
getContentId: (ctx) => ctx.ids?.content ?? `tooltip:${ctx.id}:content`,
|
|
242
37
|
getArrowId: (ctx) => `tooltip:${ctx.id}:arrow`,
|
|
@@ -245,7 +40,7 @@ var dom = defineDomHelpers({
|
|
|
245
40
|
getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
|
|
246
41
|
getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
|
|
247
42
|
getArrowEl: (ctx) => dom.getById(ctx, dom.getArrowId(ctx)),
|
|
248
|
-
getScrollParent: (ctx) => getScrollParent(dom.getTriggerEl(ctx))
|
|
43
|
+
getScrollParent: (ctx) => (0, import_dom_query.getScrollParent)(dom.getTriggerEl(ctx))
|
|
249
44
|
});
|
|
250
45
|
|
|
251
46
|
// src/tooltip.store.ts
|
|
@@ -261,7 +56,7 @@ var store = (0, import_core.proxy)({
|
|
|
261
56
|
|
|
262
57
|
// src/tooltip.machine.ts
|
|
263
58
|
function machine(userContext) {
|
|
264
|
-
const ctx = compact(userContext);
|
|
59
|
+
const ctx = (0, import_utils.compact)(userContext);
|
|
265
60
|
return (0, import_core2.createMachine)(
|
|
266
61
|
{
|
|
267
62
|
id: "tooltip",
|
|
@@ -376,7 +171,7 @@ function machine(userContext) {
|
|
|
376
171
|
computePlacement(ctx2) {
|
|
377
172
|
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
378
173
|
let cleanup;
|
|
379
|
-
raf(() => {
|
|
174
|
+
(0, import_dom_query2.raf)(() => {
|
|
380
175
|
cleanup = (0, import_popper.getPlacement)(dom.getTriggerEl(ctx2), dom.getPositionerEl(ctx2), {
|
|
381
176
|
...ctx2.positioning,
|
|
382
177
|
onComplete(data) {
|
|
@@ -392,17 +187,16 @@ function machine(userContext) {
|
|
|
392
187
|
return cleanup;
|
|
393
188
|
},
|
|
394
189
|
trackPointerlockChange(ctx2, _evt, { send }) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
});
|
|
190
|
+
const onChange = () => send("POINTER_LOCK_CHANGE");
|
|
191
|
+
return (0, import_dom_event.addDomEvent)(dom.getDoc(ctx2), "pointerlockchange", onChange, false);
|
|
398
192
|
},
|
|
399
193
|
trackScroll(ctx2, _evt, { send }) {
|
|
400
194
|
const trigger = dom.getTriggerEl(ctx2);
|
|
401
195
|
if (!trigger)
|
|
402
196
|
return;
|
|
403
|
-
const cleanups = getScrollParents(trigger).map((el) => {
|
|
197
|
+
const cleanups = (0, import_dom_query2.getScrollParents)(trigger).map((el) => {
|
|
404
198
|
const opts = { passive: true, capture: true };
|
|
405
|
-
return addDomEvent(el, "scroll", () => send("SCROLL"), opts);
|
|
199
|
+
return (0, import_dom_event.addDomEvent)(el, "scroll", () => send("SCROLL"), opts);
|
|
406
200
|
});
|
|
407
201
|
return () => {
|
|
408
202
|
cleanups.forEach((fn) => fn?.());
|
|
@@ -416,12 +210,12 @@ function machine(userContext) {
|
|
|
416
210
|
});
|
|
417
211
|
},
|
|
418
212
|
trackDisabledTriggerOnSafari(ctx2, _evt, { send }) {
|
|
419
|
-
if (!isSafari())
|
|
213
|
+
if (!(0, import_dom_query2.isSafari)())
|
|
420
214
|
return;
|
|
421
215
|
const doc = dom.getDoc(ctx2);
|
|
422
|
-
return
|
|
216
|
+
return (0, import_dom_event.addDomEvent)(doc, "pointermove", (event) => {
|
|
423
217
|
const selector = "[data-part=trigger][data-expanded]";
|
|
424
|
-
if (isHTMLElement(event.target) && event.target.closest(selector))
|
|
218
|
+
if ((0, import_dom_query2.isHTMLElement)(event.target) && event.target.closest(selector))
|
|
425
219
|
return;
|
|
426
220
|
send("POINTER_LEAVE");
|
|
427
221
|
});
|
|
@@ -430,7 +224,7 @@ function machine(userContext) {
|
|
|
430
224
|
if (!ctx2.closeOnEsc)
|
|
431
225
|
return;
|
|
432
226
|
const doc = dom.getDoc(ctx2);
|
|
433
|
-
return addDomEvent(doc, "keydown", (event) => {
|
|
227
|
+
return (0, import_dom_event.addDomEvent)(doc, "keydown", (event) => {
|
|
434
228
|
if (event.key === "Escape") {
|
|
435
229
|
send("ESCAPE");
|
|
436
230
|
}
|
package/dist/tooltip.machine.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/tooltip",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20230222181847",
|
|
4
4
|
"description": "Core logic for the tooltip widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,14 +27,16 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@zag-js/anatomy": "0.1.4",
|
|
30
|
-
"@zag-js/core": "0.0.0-dev-
|
|
31
|
-
"@zag-js/popper": "0.0.0-dev-
|
|
30
|
+
"@zag-js/core": "0.0.0-dev-20230222181847",
|
|
31
|
+
"@zag-js/popper": "0.0.0-dev-20230222181847",
|
|
32
|
+
"@zag-js/dom-query": "0.0.0-dev-20230222181847",
|
|
33
|
+
"@zag-js/dom-event": "0.0.0-dev-20230222181847",
|
|
34
|
+
"@zag-js/utils": "0.3.3",
|
|
35
|
+
"@zag-js/visually-hidden": "0.0.0-dev-20230222181847",
|
|
32
36
|
"@zag-js/types": "0.3.4"
|
|
33
37
|
},
|
|
34
38
|
"devDependencies": {
|
|
35
|
-
"clean-package": "2.2.0"
|
|
36
|
-
"@zag-js/dom-utils": "0.2.4",
|
|
37
|
-
"@zag-js/utils": "0.3.3"
|
|
39
|
+
"clean-package": "2.2.0"
|
|
38
40
|
},
|
|
39
41
|
"clean-package": "../../../clean-package.config.json",
|
|
40
42
|
"main": "dist/index.js",
|