@zag-js/tooltip 0.1.8 → 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.js CHANGED
@@ -46,22 +46,75 @@ module.exports = __toCommonJS(src_exports);
46
46
  var dataAttr = (guard) => {
47
47
  return guard ? "" : void 0;
48
48
  };
49
- var isDom = () => typeof window !== "undefined";
49
+ function getCache() {
50
+ const g = globalThis;
51
+ g.__styleCache = g.__styleCache || /* @__PURE__ */ new WeakMap();
52
+ return g.__styleCache;
53
+ }
54
+ function getComputedStyle(el) {
55
+ var _a;
56
+ if (!el)
57
+ return {};
58
+ const cache = getCache();
59
+ let style = cache.get(el);
60
+ if (!style) {
61
+ const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
62
+ style = win.getComputedStyle(el);
63
+ cache.set(el, style);
64
+ }
65
+ return style;
66
+ }
67
+ var runIfFn = (v, ...a) => {
68
+ const res = typeof v === "function" ? v(...a) : v;
69
+ return res != null ? res : void 0;
70
+ };
50
71
  var isArray = (v) => Array.isArray(v);
51
72
  var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
52
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;
79
+ }
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]";
86
+ }
87
+ function getDocument(el) {
88
+ var _a;
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 : "";
100
+ }
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
+ }
53
110
  var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
54
111
  var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
55
112
  var supportsMouseEvent = () => isDom() && window.onmousedown === null;
56
113
  var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
57
- var runIfFn = (v, ...a) => {
58
- const res = typeof v === "function" ? v(...a) : v;
59
- return res != null ? res : void 0;
60
- };
61
114
  var isRef = (v) => hasProp(v, "current");
62
- var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
115
+ var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
63
116
  function extractInfo(event, type = "page") {
64
- const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
117
+ const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback2 : event;
65
118
  return {
66
119
  point: {
67
120
  x: point[`${type}X`],
@@ -122,55 +175,6 @@ function getEventName(evt) {
122
175
  return mouseEventNames[evt];
123
176
  return evt;
124
177
  }
125
- function raf(fn) {
126
- const id = globalThis.requestAnimationFrame(fn);
127
- return function cleanup() {
128
- globalThis.cancelAnimationFrame(id);
129
- };
130
- }
131
- function getStyleCache() {
132
- ;
133
- globalThis.__styleCache__ = globalThis.__styleCache__ || /* @__PURE__ */ new WeakMap();
134
- return globalThis.__styleCache__;
135
- }
136
- function getComputedStyle(el) {
137
- var _a;
138
- if (!el)
139
- return {};
140
- const cache = getStyleCache();
141
- let style = cache.get(el);
142
- if (!style) {
143
- const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
144
- style = win.getComputedStyle(el);
145
- cache.set(el, style);
146
- }
147
- return style;
148
- }
149
- function isWindow(value) {
150
- return (value == null ? void 0 : value.toString()) === "[object Window]";
151
- }
152
- function getOwnerDocument(el) {
153
- var _a;
154
- if (isWindow(el))
155
- return el.document;
156
- return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
157
- }
158
- function getOwnerWindow(el) {
159
- var _a;
160
- return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
161
- }
162
- function getNodeName(node) {
163
- return isWindow(node) ? "" : node ? node.localName || "" : "";
164
- }
165
- function getParent(el) {
166
- const doc = getOwnerDocument(el);
167
- if (getNodeName(el) === "html")
168
- return el;
169
- return el.assignedSlot || el.parentElement || doc.documentElement;
170
- }
171
- function isHTMLElement(v) {
172
- return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
173
- }
174
178
  var visuallyHiddenStyle = {
175
179
  border: "0",
176
180
  clip: "rect(0 0 0 0)",
@@ -183,6 +187,12 @@ var visuallyHiddenStyle = {
183
187
  whiteSpace: "nowrap",
184
188
  wordWrap: "normal"
185
189
  };
190
+ function raf(fn) {
191
+ const id = globalThis.requestAnimationFrame(fn);
192
+ return function cleanup() {
193
+ globalThis.cancelAnimationFrame(id);
194
+ };
195
+ }
186
196
  function addPointerlockChangeListener(doc, fn) {
187
197
  return addDomEvent(doc, "pointerlockchange", fn, false);
188
198
  }
@@ -192,7 +202,7 @@ function isScrollParent(el) {
192
202
  }
193
203
  function getScrollParent(el) {
194
204
  if (["html", "body", "#document"].includes(getNodeName(el))) {
195
- return getOwnerDocument(el).body;
205
+ return getDocument(el).body;
196
206
  }
197
207
  if (isHTMLElement(el) && isScrollParent(el)) {
198
208
  return el;
@@ -201,8 +211,8 @@ function getScrollParent(el) {
201
211
  }
202
212
  function getScrollParents(el, list = []) {
203
213
  const scrollParent = getScrollParent(el);
204
- const isBody = scrollParent === getOwnerDocument(el).body;
205
- const win = getOwnerWindow(scrollParent);
214
+ const isBody = scrollParent === getDocument(el).body;
215
+ const win = getWindow(scrollParent);
206
216
  const target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
207
217
  const parents = list.concat(target);
208
218
  if (isBody)
@@ -213,16 +223,6 @@ function getScrollParents(el, list = []) {
213
223
  // src/tooltip.connect.ts
214
224
  var import_popper = require("@zag-js/popper");
215
225
 
216
- // ../../types/dist/index.mjs
217
- function createNormalizer(fn) {
218
- return new Proxy({}, {
219
- get() {
220
- return fn;
221
- }
222
- });
223
- }
224
- var normalizeProp = createNormalizer((v) => v);
225
-
226
226
  // src/tooltip.dom.ts
227
227
  var dom = {
228
228
  getDoc: (ctx) => {
@@ -273,7 +273,7 @@ var store = (0, import_core.proxy)({
273
273
  });
274
274
 
275
275
  // src/tooltip.connect.ts
276
- function connect(state, send, normalize = normalizeProp) {
276
+ function connect(state, send, normalize) {
277
277
  const id = state.context.id;
278
278
  const hasAriaLabel = state.context.hasAriaLabel;
279
279
  const isOpen = state.hasTag("open");
@@ -381,16 +381,6 @@ var import_core2 = require("@zag-js/core");
381
381
  var import_popper2 = require("@zag-js/popper");
382
382
 
383
383
  // ../../utilities/core/dist/index.mjs
384
- var isDom2 = () => typeof window !== "undefined";
385
- function getPlatform() {
386
- var _a;
387
- const agent = navigator.userAgentData;
388
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
389
- }
390
- var pt = (v) => isDom2() && v.test(getPlatform());
391
- var vn = (v) => isDom2() && v.test(navigator.vendor);
392
- var isSafari = () => isApple() && vn(/apple/i);
393
- var isApple = () => pt(/mac|iphone|ipad|ipod/i);
394
384
  var noop = () => {
395
385
  };
396
386
 
package/dist/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __defProp = Object.defineProperty;
3
2
  var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -23,22 +22,75 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
22
  var dataAttr = (guard) => {
24
23
  return guard ? "" : void 0;
25
24
  };
26
- var isDom = () => typeof window !== "undefined";
25
+ function getCache() {
26
+ const g = globalThis;
27
+ g.__styleCache = g.__styleCache || /* @__PURE__ */ new WeakMap();
28
+ return g.__styleCache;
29
+ }
30
+ function getComputedStyle(el) {
31
+ var _a;
32
+ if (!el)
33
+ return {};
34
+ const cache = getCache();
35
+ let style = cache.get(el);
36
+ if (!style) {
37
+ const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
38
+ style = win.getComputedStyle(el);
39
+ cache.set(el, style);
40
+ }
41
+ return style;
42
+ }
43
+ var runIfFn = (v, ...a) => {
44
+ const res = typeof v === "function" ? v(...a) : v;
45
+ return res != null ? res : void 0;
46
+ };
27
47
  var isArray = (v) => Array.isArray(v);
28
48
  var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
29
49
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
50
+ var isDom = () => typeof window !== "undefined";
51
+ function getPlatform() {
52
+ var _a;
53
+ const agent = navigator.userAgentData;
54
+ return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
55
+ }
56
+ var pt = (v) => isDom() && v.test(getPlatform());
57
+ var vn = (v) => isDom() && v.test(navigator.vendor);
58
+ var isSafari = () => isApple() && vn(/apple/i);
59
+ var isApple = () => pt(/mac|iphone|ipad|ipod/i);
60
+ function isWindow(value) {
61
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
62
+ }
63
+ function getDocument(el) {
64
+ var _a;
65
+ if (isWindow(el))
66
+ return el.document;
67
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
68
+ }
69
+ function getWindow(el) {
70
+ var _a;
71
+ return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
72
+ }
73
+ function getNodeName(node) {
74
+ var _a;
75
+ return isWindow(node) ? "" : (_a = node == null ? void 0 : node.localName) != null ? _a : "";
76
+ }
77
+ function getParent(el) {
78
+ const doc = getDocument(el);
79
+ if (getNodeName(el) === "html")
80
+ return el;
81
+ return el.assignedSlot || el.parentElement || doc.documentElement;
82
+ }
83
+ function isHTMLElement(v) {
84
+ return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
85
+ }
30
86
  var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
31
87
  var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
32
88
  var supportsMouseEvent = () => isDom() && window.onmousedown === null;
33
89
  var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
34
- var runIfFn = (v, ...a) => {
35
- const res = typeof v === "function" ? v(...a) : v;
36
- return res != null ? res : void 0;
37
- };
38
90
  var isRef = (v) => hasProp(v, "current");
39
- var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
91
+ var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
40
92
  function extractInfo(event, type = "page") {
41
- const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
93
+ const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback2 : event;
42
94
  return {
43
95
  point: {
44
96
  x: point[`${type}X`],
@@ -99,55 +151,6 @@ function getEventName(evt) {
99
151
  return mouseEventNames[evt];
100
152
  return evt;
101
153
  }
102
- function raf(fn) {
103
- const id = globalThis.requestAnimationFrame(fn);
104
- return function cleanup() {
105
- globalThis.cancelAnimationFrame(id);
106
- };
107
- }
108
- function getStyleCache() {
109
- ;
110
- globalThis.__styleCache__ = globalThis.__styleCache__ || /* @__PURE__ */ new WeakMap();
111
- return globalThis.__styleCache__;
112
- }
113
- function getComputedStyle(el) {
114
- var _a;
115
- if (!el)
116
- return {};
117
- const cache = getStyleCache();
118
- let style = cache.get(el);
119
- if (!style) {
120
- const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
121
- style = win.getComputedStyle(el);
122
- cache.set(el, style);
123
- }
124
- return style;
125
- }
126
- function isWindow(value) {
127
- return (value == null ? void 0 : value.toString()) === "[object Window]";
128
- }
129
- function getOwnerDocument(el) {
130
- var _a;
131
- if (isWindow(el))
132
- return el.document;
133
- return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
134
- }
135
- function getOwnerWindow(el) {
136
- var _a;
137
- return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
138
- }
139
- function getNodeName(node) {
140
- return isWindow(node) ? "" : node ? node.localName || "" : "";
141
- }
142
- function getParent(el) {
143
- const doc = getOwnerDocument(el);
144
- if (getNodeName(el) === "html")
145
- return el;
146
- return el.assignedSlot || el.parentElement || doc.documentElement;
147
- }
148
- function isHTMLElement(v) {
149
- return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
150
- }
151
154
  var visuallyHiddenStyle = {
152
155
  border: "0",
153
156
  clip: "rect(0 0 0 0)",
@@ -160,6 +163,12 @@ var visuallyHiddenStyle = {
160
163
  whiteSpace: "nowrap",
161
164
  wordWrap: "normal"
162
165
  };
166
+ function raf(fn) {
167
+ const id = globalThis.requestAnimationFrame(fn);
168
+ return function cleanup() {
169
+ globalThis.cancelAnimationFrame(id);
170
+ };
171
+ }
163
172
  function addPointerlockChangeListener(doc, fn) {
164
173
  return addDomEvent(doc, "pointerlockchange", fn, false);
165
174
  }
@@ -169,7 +178,7 @@ function isScrollParent(el) {
169
178
  }
170
179
  function getScrollParent(el) {
171
180
  if (["html", "body", "#document"].includes(getNodeName(el))) {
172
- return getOwnerDocument(el).body;
181
+ return getDocument(el).body;
173
182
  }
174
183
  if (isHTMLElement(el) && isScrollParent(el)) {
175
184
  return el;
@@ -178,8 +187,8 @@ function getScrollParent(el) {
178
187
  }
179
188
  function getScrollParents(el, list = []) {
180
189
  const scrollParent = getScrollParent(el);
181
- const isBody = scrollParent === getOwnerDocument(el).body;
182
- const win = getOwnerWindow(scrollParent);
190
+ const isBody = scrollParent === getDocument(el).body;
191
+ const win = getWindow(scrollParent);
183
192
  const target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
184
193
  const parents = list.concat(target);
185
194
  if (isBody)
@@ -190,16 +199,6 @@ function getScrollParents(el, list = []) {
190
199
  // src/tooltip.connect.ts
191
200
  import { getPlacementStyles } from "@zag-js/popper";
192
201
 
193
- // ../../types/dist/index.mjs
194
- function createNormalizer(fn) {
195
- return new Proxy({}, {
196
- get() {
197
- return fn;
198
- }
199
- });
200
- }
201
- var normalizeProp = createNormalizer((v) => v);
202
-
203
202
  // src/tooltip.dom.ts
204
203
  var dom = {
205
204
  getDoc: (ctx) => {
@@ -250,7 +249,7 @@ var store = proxy({
250
249
  });
251
250
 
252
251
  // src/tooltip.connect.ts
253
- function connect(state, send, normalize = normalizeProp) {
252
+ function connect(state, send, normalize) {
254
253
  const id = state.context.id;
255
254
  const hasAriaLabel = state.context.hasAriaLabel;
256
255
  const isOpen = state.hasTag("open");
@@ -358,16 +357,6 @@ import { createMachine, ref, subscribe } from "@zag-js/core";
358
357
  import { getPlacement } from "@zag-js/popper";
359
358
 
360
359
  // ../../utilities/core/dist/index.mjs
361
- var isDom2 = () => typeof window !== "undefined";
362
- function getPlatform() {
363
- var _a;
364
- const agent = navigator.userAgentData;
365
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
366
- }
367
- var pt = (v) => isDom2() && v.test(getPlatform());
368
- var vn = (v) => isDom2() && v.test(navigator.vendor);
369
- var isSafari = () => isApple() && vn(/apple/i);
370
- var isApple = () => pt(/mac|iphone|ipad|ipod/i);
371
360
  var noop = () => {
372
361
  };
373
362
 
@@ -1,6 +1,6 @@
1
- import { PropTypes, ReactPropTypes } from "@zag-js/types";
2
- import { Send, State } from "./tooltip.types";
3
- export declare function connect<T extends PropTypes = ReactPropTypes>(state: State, send: Send, normalize?: import("@zag-js/types").NormalizeProps): {
1
+ import type { NormalizeProps, PropTypes } from "@zag-js/types";
2
+ import type { Send, State } from "./tooltip.types";
3
+ export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
4
4
  isOpen: boolean;
5
5
  open(): void;
6
6
  close(): void;
@@ -1,4 +1,4 @@
1
- import { MachineContext as Ctx } from "./tooltip.types";
1
+ import type { MachineContext as Ctx } from "./tooltip.types";
2
2
  export declare const dom: {
3
3
  getDoc: (ctx: Ctx) => Document;
4
4
  getWin: (ctx: Ctx) => Window & typeof globalThis;
@@ -1,2 +1,2 @@
1
- import { UserDefinedContext, MachineContext, MachineState } from "./tooltip.types";
1
+ import type { MachineContext, MachineState, UserDefinedContext } from "./tooltip.types";
2
2
  export declare function machine(ctx?: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
@@ -1,6 +1,6 @@
1
1
  import type { StateMachine as S } from "@zag-js/core";
2
- import { Placement, PositioningOptions } from "@zag-js/popper";
3
- import { RootProperties } from "@zag-js/types";
2
+ import type { Placement, PositioningOptions } from "@zag-js/popper";
3
+ import type { RootProperties } from "@zag-js/types";
4
4
  declare type ElementIds = Partial<{
5
5
  trigger: string;
6
6
  content: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tooltip",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Core logic for the tooltip widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,10 +29,10 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/core": "0.1.6",
33
- "@zag-js/dom-utils": "0.1.5",
34
- "@zag-js/popper": "0.1.6",
35
- "@zag-js/types": "0.2.0"
32
+ "@zag-js/core": "0.1.7",
33
+ "@zag-js/dom-utils": "0.1.6",
34
+ "@zag-js/popper": "0.1.7",
35
+ "@zag-js/types": "0.2.1"
36
36
  },
37
37
  "scripts": {
38
38
  "build:fast": "zag build",