@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.
@@ -0,0 +1,308 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/tooltip.connect.ts
21
+ var tooltip_connect_exports = {};
22
+ __export(tooltip_connect_exports, {
23
+ connect: () => connect
24
+ });
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
+ var _a;
40
+ if (!el)
41
+ return {};
42
+ const cache = getCache();
43
+ let style = cache.get(el);
44
+ if (!style) {
45
+ const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
46
+ style = win.getComputedStyle(el);
47
+ cache.set(el, style);
48
+ }
49
+ return style;
50
+ }
51
+
52
+ // ../../utilities/dom/src/query.ts
53
+ function isDocument(el) {
54
+ return el.nodeType === Node.DOCUMENT_NODE;
55
+ }
56
+ function isWindow(value) {
57
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
58
+ }
59
+ function getDocument(el) {
60
+ var _a;
61
+ if (isWindow(el))
62
+ return el.document;
63
+ if (isDocument(el))
64
+ return el;
65
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
66
+ }
67
+ function getNodeName(node) {
68
+ var _a;
69
+ return isWindow(node) ? "" : (_a = node == null ? void 0 : node.localName) != null ? _a : "";
70
+ }
71
+ function getParent(el) {
72
+ const doc = getDocument(el);
73
+ if (getNodeName(el) === "html")
74
+ return el;
75
+ return el.assignedSlot || el.parentElement || doc.documentElement;
76
+ }
77
+ function defineDomHelpers(helpers) {
78
+ const dom2 = {
79
+ getRootNode: (ctx) => {
80
+ var _a, _b;
81
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
82
+ },
83
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
84
+ getWin: (ctx) => {
85
+ var _a;
86
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
87
+ },
88
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
89
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
90
+ createEmitter: (ctx, target) => {
91
+ const win = dom2.getWin(ctx);
92
+ return function emit(evt, detail, options) {
93
+ const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
94
+ const eventName = `zag:${evt}`;
95
+ const init = { bubbles, cancelable, composed, detail };
96
+ const event = new win.CustomEvent(eventName, init);
97
+ target.dispatchEvent(event);
98
+ };
99
+ },
100
+ createListener: (target) => {
101
+ return function listen(evt, handler) {
102
+ const eventName = `zag:${evt}`;
103
+ const listener = (e) => handler(e);
104
+ target.addEventListener(eventName, listener);
105
+ return () => target.removeEventListener(eventName, listener);
106
+ };
107
+ }
108
+ };
109
+ return {
110
+ ...dom2,
111
+ ...helpers
112
+ };
113
+ }
114
+ function isHTMLElement(v) {
115
+ return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
116
+ }
117
+
118
+ // ../../utilities/dom/src/scrollable.ts
119
+ function isScrollParent(el) {
120
+ const { overflow, overflowX, overflowY } = getComputedStyle(el);
121
+ return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
122
+ }
123
+ function getScrollParent(el) {
124
+ if (["html", "body", "#document"].includes(getNodeName(el))) {
125
+ return getDocument(el).body;
126
+ }
127
+ if (isHTMLElement(el) && isScrollParent(el)) {
128
+ return el;
129
+ }
130
+ return getScrollParent(getParent(el));
131
+ }
132
+
133
+ // ../../utilities/dom/src/visually-hidden.ts
134
+ var visuallyHiddenStyle = {
135
+ border: "0",
136
+ clip: "rect(0 0 0 0)",
137
+ height: "1px",
138
+ margin: "-1px",
139
+ overflow: "hidden",
140
+ padding: "0",
141
+ position: "absolute",
142
+ width: "1px",
143
+ whiteSpace: "nowrap",
144
+ wordWrap: "normal"
145
+ };
146
+
147
+ // src/tooltip.connect.ts
148
+ var import_popper = require("@zag-js/popper");
149
+
150
+ // src/tooltip.dom.ts
151
+ var dom = defineDomHelpers({
152
+ getTriggerId: (ctx) => {
153
+ var _a, _b;
154
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tooltip:${ctx.id}:trigger`;
155
+ },
156
+ getContentId: (ctx) => {
157
+ var _a, _b;
158
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tooltip:${ctx.id}:content`;
159
+ },
160
+ getArrowId: (ctx) => `tooltip:${ctx.id}:arrow`,
161
+ getPositionerId: (ctx) => `tooltip:${ctx.id}:popper`,
162
+ portalId: "tooltip-portal",
163
+ getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
164
+ getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
165
+ getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
166
+ getArrowEl: (ctx) => dom.getById(ctx, dom.getArrowId(ctx)),
167
+ getScrollParent: (ctx) => getScrollParent(dom.getTriggerEl(ctx)),
168
+ getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.portalId),
169
+ createPortalEl: (ctx) => {
170
+ const portal = dom.getDoc(ctx).createElement(dom.portalId);
171
+ portal.id = dom.portalId;
172
+ return portal;
173
+ }
174
+ });
175
+
176
+ // src/tooltip.store.ts
177
+ var import_core = require("@zag-js/core");
178
+ var store = (0, import_core.proxy)({
179
+ id: null,
180
+ prevId: null,
181
+ setId(val) {
182
+ this.prevId = this.id;
183
+ this.id = val;
184
+ }
185
+ });
186
+
187
+ // src/tooltip.anatomy.ts
188
+ var import_anatomy = require("@zag-js/anatomy");
189
+ var anatomy = (0, import_anatomy.createAnatomy)("tooltip").parts("trigger", "arrow", "arrowTip", "positioner", "content", "label");
190
+ var parts = anatomy.build();
191
+
192
+ // src/tooltip.connect.ts
193
+ function connect(state, send, normalize) {
194
+ const id = state.context.id;
195
+ const hasAriaLabel = state.context.hasAriaLabel;
196
+ const isOpen = state.hasTag("open");
197
+ const triggerId = dom.getTriggerId(state.context);
198
+ const contentId = dom.getContentId(state.context);
199
+ const isDisabled = state.context.disabled;
200
+ const popperStyles = (0, import_popper.getPlacementStyles)({
201
+ measured: !!state.context.isPlacementComplete,
202
+ placement: state.context.currentPlacement
203
+ });
204
+ return {
205
+ isOpen,
206
+ open() {
207
+ send("OPEN");
208
+ },
209
+ close() {
210
+ send("CLOSE");
211
+ },
212
+ getAnimationState() {
213
+ return {
214
+ enter: store.prevId === null && id === store.id,
215
+ exit: store.id === null
216
+ };
217
+ },
218
+ triggerProps: normalize.button({
219
+ ...parts.trigger.attrs,
220
+ id: triggerId,
221
+ "data-expanded": dataAttr(isOpen),
222
+ "aria-describedby": isOpen ? contentId : void 0,
223
+ onClick() {
224
+ send("CLICK");
225
+ },
226
+ onFocus() {
227
+ send("FOCUS");
228
+ },
229
+ onBlur() {
230
+ if (id === store.id) {
231
+ send("BLUR");
232
+ }
233
+ },
234
+ onPointerDown() {
235
+ if (isDisabled)
236
+ return;
237
+ if (id === store.id) {
238
+ send("POINTER_DOWN");
239
+ }
240
+ },
241
+ onPointerMove() {
242
+ if (isDisabled)
243
+ return;
244
+ send("POINTER_ENTER");
245
+ },
246
+ onPointerLeave() {
247
+ if (isDisabled)
248
+ return;
249
+ send("POINTER_LEAVE");
250
+ },
251
+ onPointerCancel() {
252
+ if (isDisabled)
253
+ return;
254
+ send("POINTER_LEAVE");
255
+ }
256
+ }),
257
+ arrowProps: normalize.element({
258
+ id: dom.getArrowId(state.context),
259
+ ...parts.arrow.attrs,
260
+ style: popperStyles.arrow
261
+ }),
262
+ arrowTipProps: normalize.element({
263
+ ...parts.arrowTip.attrs,
264
+ style: popperStyles.arrowTip
265
+ }),
266
+ positionerProps: normalize.element({
267
+ id: dom.getPositionerId(state.context),
268
+ ...parts.positioner.attrs,
269
+ style: popperStyles.floating
270
+ }),
271
+ contentProps: normalize.element({
272
+ ...parts.content.attrs,
273
+ hidden: !isOpen,
274
+ role: hasAriaLabel ? void 0 : "tooltip",
275
+ id: hasAriaLabel ? void 0 : contentId,
276
+ "data-placement": state.context.currentPlacement,
277
+ onPointerEnter() {
278
+ send("TOOLTIP_POINTER_ENTER");
279
+ },
280
+ onPointerLeave() {
281
+ send("TOOLTIP_POINTER_LEAVE");
282
+ },
283
+ style: {
284
+ pointerEvents: state.context.interactive ? "auto" : "none"
285
+ }
286
+ }),
287
+ labelProps: normalize.element({
288
+ ...parts.label.attrs,
289
+ id: contentId,
290
+ role: "tooltip",
291
+ style: visuallyHiddenStyle,
292
+ children: state.context["aria-label"]
293
+ }),
294
+ createPortal() {
295
+ const doc = dom.getDoc(state.context);
296
+ const exist = dom.getPortalEl(state.context);
297
+ if (exist)
298
+ return exist;
299
+ const portal = dom.createPortalEl(state.context);
300
+ doc.body.appendChild(portal);
301
+ return portal;
302
+ }
303
+ };
304
+ }
305
+ // Annotate the CommonJS export names for ESM import in node:
306
+ 0 && (module.exports = {
307
+ connect
308
+ });
@@ -0,0 +1,9 @@
1
+ import {
2
+ connect
3
+ } from "./chunk-XZ6HXWV2.mjs";
4
+ import "./chunk-RRQRIZBA.mjs";
5
+ import "./chunk-PFKIRGNP.mjs";
6
+ import "./chunk-GQYNO326.mjs";
7
+ export {
8
+ connect
9
+ };
@@ -0,0 +1,41 @@
1
+ import { MachineContext } from './tooltip.types.js';
2
+ import '@zag-js/core';
3
+ import '@zag-js/popper';
4
+ import '@zag-js/types';
5
+
6
+ declare const dom: {
7
+ getRootNode: (ctx: {
8
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
9
+ }) => Document | ShadowRoot;
10
+ getDoc: (ctx: {
11
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
12
+ }) => Document;
13
+ getWin: (ctx: {
14
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
15
+ }) => Window & typeof globalThis;
16
+ getActiveElement: (ctx: {
17
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
18
+ }) => HTMLElement | null;
19
+ getById: <T = HTMLElement>(ctx: {
20
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
21
+ }, id: string) => T | null;
22
+ createEmitter: (ctx: {
23
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
24
+ }, target: HTMLElement) => (evt: string, detail: Record<string, any>, options?: EventInit | undefined) => void;
25
+ createListener: (target: HTMLElement) => <T_1 = any>(evt: string, handler: (e: CustomEvent<T_1>) => void) => () => void;
26
+ } & {
27
+ getTriggerId: (ctx: MachineContext) => string;
28
+ getContentId: (ctx: MachineContext) => string;
29
+ getArrowId: (ctx: MachineContext) => string;
30
+ getPositionerId: (ctx: MachineContext) => string;
31
+ portalId: string;
32
+ getTriggerEl: (ctx: MachineContext) => HTMLElement | null;
33
+ getContentEl: (ctx: MachineContext) => HTMLElement | null;
34
+ getPositionerEl: (ctx: MachineContext) => HTMLElement | null;
35
+ getArrowEl: (ctx: MachineContext) => HTMLElement | null;
36
+ getScrollParent: (ctx: MachineContext) => HTMLElement;
37
+ getPortalEl: (ctx: MachineContext) => HTMLElement | null;
38
+ createPortalEl: (ctx: MachineContext) => HTMLElement;
39
+ };
40
+
41
+ export { dom };
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/tooltip.dom.ts
21
+ var tooltip_dom_exports = {};
22
+ __export(tooltip_dom_exports, {
23
+ dom: () => dom
24
+ });
25
+ module.exports = __toCommonJS(tooltip_dom_exports);
26
+
27
+ // ../../utilities/dom/src/get-computed-style.ts
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
+ var _a;
35
+ if (!el)
36
+ return {};
37
+ const cache = getCache();
38
+ let style = cache.get(el);
39
+ if (!style) {
40
+ const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
41
+ style = win.getComputedStyle(el);
42
+ cache.set(el, style);
43
+ }
44
+ return style;
45
+ }
46
+
47
+ // ../../utilities/dom/src/query.ts
48
+ function isDocument(el) {
49
+ return el.nodeType === Node.DOCUMENT_NODE;
50
+ }
51
+ function isWindow(value) {
52
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
53
+ }
54
+ function getDocument(el) {
55
+ var _a;
56
+ if (isWindow(el))
57
+ return el.document;
58
+ if (isDocument(el))
59
+ return el;
60
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
61
+ }
62
+ function getNodeName(node) {
63
+ var _a;
64
+ return isWindow(node) ? "" : (_a = node == null ? void 0 : node.localName) != null ? _a : "";
65
+ }
66
+ function getParent(el) {
67
+ const doc = getDocument(el);
68
+ if (getNodeName(el) === "html")
69
+ return el;
70
+ return el.assignedSlot || el.parentElement || doc.documentElement;
71
+ }
72
+ function defineDomHelpers(helpers) {
73
+ const dom2 = {
74
+ getRootNode: (ctx) => {
75
+ var _a, _b;
76
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
77
+ },
78
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
79
+ getWin: (ctx) => {
80
+ var _a;
81
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
82
+ },
83
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
84
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
85
+ createEmitter: (ctx, target) => {
86
+ const win = dom2.getWin(ctx);
87
+ return function emit(evt, detail, options) {
88
+ const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
89
+ const eventName = `zag:${evt}`;
90
+ const init = { bubbles, cancelable, composed, detail };
91
+ const event = new win.CustomEvent(eventName, init);
92
+ target.dispatchEvent(event);
93
+ };
94
+ },
95
+ createListener: (target) => {
96
+ return function listen(evt, handler) {
97
+ const eventName = `zag:${evt}`;
98
+ const listener = (e) => handler(e);
99
+ target.addEventListener(eventName, listener);
100
+ return () => target.removeEventListener(eventName, listener);
101
+ };
102
+ }
103
+ };
104
+ return {
105
+ ...dom2,
106
+ ...helpers
107
+ };
108
+ }
109
+ function isHTMLElement(v) {
110
+ return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
111
+ }
112
+
113
+ // ../../utilities/dom/src/scrollable.ts
114
+ function isScrollParent(el) {
115
+ const { overflow, overflowX, overflowY } = getComputedStyle(el);
116
+ return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
117
+ }
118
+ function getScrollParent(el) {
119
+ if (["html", "body", "#document"].includes(getNodeName(el))) {
120
+ return getDocument(el).body;
121
+ }
122
+ if (isHTMLElement(el) && isScrollParent(el)) {
123
+ return el;
124
+ }
125
+ return getScrollParent(getParent(el));
126
+ }
127
+
128
+ // src/tooltip.dom.ts
129
+ var dom = defineDomHelpers({
130
+ getTriggerId: (ctx) => {
131
+ var _a, _b;
132
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tooltip:${ctx.id}:trigger`;
133
+ },
134
+ getContentId: (ctx) => {
135
+ var _a, _b;
136
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tooltip:${ctx.id}:content`;
137
+ },
138
+ getArrowId: (ctx) => `tooltip:${ctx.id}:arrow`,
139
+ getPositionerId: (ctx) => `tooltip:${ctx.id}:popper`,
140
+ portalId: "tooltip-portal",
141
+ getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
142
+ getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
143
+ getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
144
+ getArrowEl: (ctx) => dom.getById(ctx, dom.getArrowId(ctx)),
145
+ getScrollParent: (ctx) => getScrollParent(dom.getTriggerEl(ctx)),
146
+ getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.portalId),
147
+ createPortalEl: (ctx) => {
148
+ const portal = dom.getDoc(ctx).createElement(dom.portalId);
149
+ portal.id = dom.portalId;
150
+ return portal;
151
+ }
152
+ });
153
+ // Annotate the CommonJS export names for ESM import in node:
154
+ 0 && (module.exports = {
155
+ dom
156
+ });
@@ -0,0 +1,6 @@
1
+ import {
2
+ dom
3
+ } from "./chunk-PFKIRGNP.mjs";
4
+ export {
5
+ dom
6
+ };
@@ -0,0 +1,8 @@
1
+ import * as _zag_js_core from '@zag-js/core';
2
+ import { UserDefinedContext, MachineContext, MachineState } from './tooltip.types.js';
3
+ import '@zag-js/popper';
4
+ import '@zag-js/types';
5
+
6
+ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
7
+
8
+ export { machine };