@zag-js/popover 0.0.0-dev-20220604091726 → 0.0.0-dev-20220604123738

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.mjs CHANGED
@@ -18,115 +18,6 @@ var __spreadValues = (a, b) => {
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
 
21
- // ../../../node_modules/compute-scroll-into-view/dist/index.module.js
22
- function t(t2) {
23
- return typeof t2 == "object" && t2 != null && t2.nodeType === 1;
24
- }
25
- function e(t2, e2) {
26
- return (!e2 || t2 !== "hidden") && t2 !== "visible" && t2 !== "clip";
27
- }
28
- function n(t2, n2) {
29
- if (t2.clientHeight < t2.scrollHeight || t2.clientWidth < t2.scrollWidth) {
30
- var r2 = getComputedStyle(t2, null);
31
- return e(r2.overflowY, n2) || e(r2.overflowX, n2) || function(t3) {
32
- var e2 = function(t4) {
33
- if (!t4.ownerDocument || !t4.ownerDocument.defaultView)
34
- return null;
35
- try {
36
- return t4.ownerDocument.defaultView.frameElement;
37
- } catch (t5) {
38
- return null;
39
- }
40
- }(t3);
41
- return !!e2 && (e2.clientHeight < t3.scrollHeight || e2.clientWidth < t3.scrollWidth);
42
- }(t2);
43
- }
44
- return false;
45
- }
46
- function r(t2, e2, n2, r2, i, o, l, d) {
47
- return o < t2 && l > e2 || o > t2 && l < e2 ? 0 : o <= t2 && d <= n2 || l >= e2 && d >= n2 ? o - t2 - r2 : l > e2 && d < n2 || o < t2 && d > n2 ? l - e2 + i : 0;
48
- }
49
- function index_module_default(e2, i) {
50
- var o = window, l = i.scrollMode, d = i.block, u = i.inline, h = i.boundary, a = i.skipOverflowHiddenElements, c = typeof h == "function" ? h : function(t2) {
51
- return t2 !== h;
52
- };
53
- if (!t(e2))
54
- throw new TypeError("Invalid target");
55
- for (var f = document.scrollingElement || document.documentElement, s = [], p = e2; t(p) && c(p); ) {
56
- if ((p = p.parentElement) === f) {
57
- s.push(p);
58
- break;
59
- }
60
- p != null && p === document.body && n(p) && !n(document.documentElement) || p != null && n(p, a) && s.push(p);
61
- }
62
- for (var m = o.visualViewport ? o.visualViewport.width : innerWidth, g = o.visualViewport ? o.visualViewport.height : innerHeight, w = window.scrollX || pageXOffset, v = window.scrollY || pageYOffset, W = e2.getBoundingClientRect(), b = W.height, H = W.width, y = W.top, E = W.right, M = W.bottom, V = W.left, x = d === "start" || d === "nearest" ? y : d === "end" ? M : y + b / 2, I = u === "center" ? V + H / 2 : u === "end" ? E : V, C = [], T = 0; T < s.length; T++) {
63
- var k = s[T], B = k.getBoundingClientRect(), D = B.height, O = B.width, R = B.top, X = B.right, Y = B.bottom, L = B.left;
64
- if (l === "if-needed" && y >= 0 && V >= 0 && M <= g && E <= m && y >= R && M <= Y && V >= L && E <= X)
65
- return C;
66
- var S = getComputedStyle(k), j = parseInt(S.borderLeftWidth, 10), q = parseInt(S.borderTopWidth, 10), z = parseInt(S.borderRightWidth, 10), A = parseInt(S.borderBottomWidth, 10), F = 0, G = 0, J = "offsetWidth" in k ? k.offsetWidth - k.clientWidth - j - z : 0, K = "offsetHeight" in k ? k.offsetHeight - k.clientHeight - q - A : 0;
67
- if (f === k)
68
- F = d === "start" ? x : d === "end" ? x - g : d === "nearest" ? r(v, v + g, g, q, A, v + x, v + x + b, b) : x - g / 2, G = u === "start" ? I : u === "center" ? I - m / 2 : u === "end" ? I - m : r(w, w + m, m, j, z, w + I, w + I + H, H), F = Math.max(0, F + v), G = Math.max(0, G + w);
69
- else {
70
- F = d === "start" ? x - R - q : d === "end" ? x - Y + A + K : d === "nearest" ? r(R, Y, D, q, A + K, x, x + b, b) : x - (R + D / 2) + K / 2, G = u === "start" ? I - L - j : u === "center" ? I - (L + O / 2) + J / 2 : u === "end" ? I - X + z + J : r(L, X, O, j, z + J, I, I + H, H);
71
- var N = k.scrollLeft, P = k.scrollTop;
72
- x += P - (F = Math.max(0, Math.min(P + F, k.scrollHeight - D + K))), I += N - (G = Math.max(0, Math.min(N + G, k.scrollWidth - O + J)));
73
- }
74
- C.push({ el: k, top: F, left: G });
75
- }
76
- return C;
77
- }
78
-
79
- // ../../utilities/dom/node_modules/scroll-into-view-if-needed/es/index.js
80
- function isOptionsObject(options) {
81
- return options === Object(options) && Object.keys(options).length !== 0;
82
- }
83
- function defaultBehavior(actions, behavior) {
84
- if (behavior === void 0) {
85
- behavior = "auto";
86
- }
87
- var canSmoothScroll = "scrollBehavior" in document.body.style;
88
- actions.forEach(function(_ref) {
89
- var el = _ref.el, top = _ref.top, left = _ref.left;
90
- if (el.scroll && canSmoothScroll) {
91
- el.scroll({
92
- top,
93
- left,
94
- behavior
95
- });
96
- } else {
97
- el.scrollTop = top;
98
- el.scrollLeft = left;
99
- }
100
- });
101
- }
102
- function getOptions(options) {
103
- if (options === false) {
104
- return {
105
- block: "end",
106
- inline: "nearest"
107
- };
108
- }
109
- if (isOptionsObject(options)) {
110
- return options;
111
- }
112
- return {
113
- block: "start",
114
- inline: "nearest"
115
- };
116
- }
117
- function scrollIntoView(target, options) {
118
- var isTargetAttached = target.isConnected || target.ownerDocument.documentElement.contains(target);
119
- if (isOptionsObject(options) && typeof options.behavior === "function") {
120
- return options.behavior(isTargetAttached ? index_module_default(target, options) : []);
121
- }
122
- if (!isTargetAttached) {
123
- return;
124
- }
125
- var computeOptions = getOptions(options);
126
- return defaultBehavior(index_module_default(target, computeOptions), computeOptions.behavior);
127
- }
128
- var es_default = scrollIntoView;
129
-
130
21
  // ../../utilities/dom/dist/index.mjs
131
22
  var dataAttr = (guard) => {
132
23
  return guard ? "" : void 0;
@@ -168,6 +59,10 @@ function raf(fn) {
168
59
  globalThis.cancelAnimationFrame(id);
169
60
  };
170
61
  }
62
+ var isDom = () => typeof window !== "undefined";
63
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
64
+ var isTouchDevice = isDom() && !!navigator.maxTouchPoints;
65
+ var isLeftClick = (v) => v.button === 0;
171
66
  var runIfFn = (v, ...a) => {
172
67
  const res = typeof v === "function" ? v(...a) : v;
173
68
  return res != null ? res : void 0;
@@ -175,14 +70,6 @@ var runIfFn = (v, ...a) => {
175
70
  var noop = () => {
176
71
  };
177
72
  var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
178
- var platform = (v) => isDom() && v.test(navigator.platform);
179
- var isDom = () => typeof window !== "undefined";
180
- var isMac = () => platform(/^Mac/);
181
- var isIPhone = () => platform(/^iPhone/);
182
- var isIPad = () => platform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
183
- var isIos = () => isIPhone() || isIPad();
184
- var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
185
- var isLeftClick = (v) => v.button === 0;
186
73
  function getListenerElements() {
187
74
  ;
188
75
  globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map();
@@ -308,21 +195,6 @@ function preventBodyPointerEvents(el, opts = {}) {
308
195
  cleanups.forEach((cleanup) => cleanup == null ? void 0 : cleanup());
309
196
  };
310
197
  }
311
- function getOwnerDocument(el) {
312
- var _a;
313
- if (isWindow(el))
314
- return el.document;
315
- return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
316
- }
317
- function getNodeName(node) {
318
- return isWindow(node) ? "" : node ? node.localName || "" : "";
319
- }
320
- function getParent(el) {
321
- const doc = getOwnerDocument(el);
322
- if (getNodeName(el) === "html")
323
- return el;
324
- return el.assignedSlot || el.parentElement || doc.documentElement;
325
- }
326
198
  function contains(parent, child) {
327
199
  if (!parent)
328
200
  return false;
@@ -331,124 +203,9 @@ function contains(parent, child) {
331
203
  function isHTMLElement(v) {
332
204
  return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
333
205
  }
334
- function isWindow(value) {
335
- return (value == null ? void 0 : value.toString()) === "[object Window]";
336
- }
337
206
  var isDisabled = (el) => {
338
207
  return (el == null ? void 0 : el.getAttribute("disabled")) != null || !!(el == null ? void 0 : el.getAttribute("aria-disabled")) === true;
339
208
  };
340
- function isScrollParent(el) {
341
- const { overflow, overflowX, overflowY } = getComputedStyle2(el);
342
- return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
343
- }
344
- function getScrollParent(el) {
345
- if (["html", "body", "#document"].includes(getNodeName(el))) {
346
- return getOwnerDocument(el).body;
347
- }
348
- if (isHTMLElement(el) && isScrollParent(el)) {
349
- return el;
350
- }
351
- return getScrollParent(getParent(el));
352
- }
353
- var nonTextInputTypes = /* @__PURE__ */ new Set(["checkbox", "radio", "range", "color", "file", "image", "button", "submit", "reset"]);
354
- function preventBodyScroll(opts) {
355
- var _a;
356
- const { document: docProp, disabled = false, allowPinchZoom } = opts != null ? opts : {};
357
- const doc = docProp != null ? docProp : document;
358
- const win = (_a = doc == null ? void 0 : doc.defaultView) != null ? _a : window;
359
- const viewport = isDom() ? win.visualViewport : null;
360
- const docEl = doc.documentElement;
361
- function preventScrollStandard() {
362
- if (docEl.hasAttribute("scroll-lock"))
363
- return;
364
- const fn = pipe(setStyle(docEl, "paddingRight", `${win.innerWidth - docEl.clientWidth}px`), setStyle(docEl, "overflow", "hidden"), () => docEl.setAttribute("scroll-lock", "true"));
365
- return pipe(fn, () => docEl.removeAttribute("scroll-lock"));
366
- }
367
- function preventScrollMobileSafari() {
368
- if (docEl.hasAttribute("scroll-lock"))
369
- return;
370
- let scrollable;
371
- let lastY = 0;
372
- let onTouchStart = (e2) => {
373
- scrollable = getScrollParent(e2.target);
374
- if (scrollable === docEl && scrollable === doc.body) {
375
- return;
376
- }
377
- lastY = e2.changedTouches[0].pageY;
378
- };
379
- let onTouchMove = (e2) => {
380
- if (e2.touches.length === 2 && allowPinchZoom)
381
- return;
382
- if (!scrollable || scrollable === docEl || scrollable === doc.body) {
383
- e2.preventDefault();
384
- return;
385
- }
386
- let y = e2.changedTouches[0].pageY;
387
- let scrollTop = scrollable.scrollTop;
388
- let bottom = scrollable.scrollHeight - scrollable.clientHeight;
389
- if (scrollTop <= 0 && y > lastY || scrollTop >= bottom && y < lastY) {
390
- e2.preventDefault();
391
- }
392
- lastY = y;
393
- };
394
- let onTouchEnd = (e2) => {
395
- let target = e2.target;
396
- if (target instanceof win.HTMLInputElement && !nonTextInputTypes.has(target.type)) {
397
- e2.preventDefault();
398
- target.style.transform = "translateY(-2000px)";
399
- target.focus();
400
- win.requestAnimationFrame(() => {
401
- target.style.transform = "";
402
- });
403
- }
404
- };
405
- let onFocus = (e2) => {
406
- let target = e2.target;
407
- if (target instanceof win.HTMLInputElement && !nonTextInputTypes.has(target.type)) {
408
- target.style.transform = "translateY(-2000px)";
409
- win.requestAnimationFrame(() => {
410
- target.style.transform = "";
411
- if (!viewport)
412
- return;
413
- if (viewport.height < win.innerHeight) {
414
- win.requestAnimationFrame(function() {
415
- es_default(target, { scrollMode: "if-needed" });
416
- });
417
- } else {
418
- const onResize = () => {
419
- es_default(target, { scrollMode: "if-needed" });
420
- };
421
- addDomEvent(viewport, "resize", onResize, { once: true });
422
- }
423
- });
424
- }
425
- };
426
- let onWindowScroll = () => {
427
- win.scrollTo(0, 0);
428
- };
429
- let scrollX = win.scrollX;
430
- let scrollY = win.scrollY;
431
- let restoreStyles = pipe(setStyle(docEl, "paddingRight", `${win.innerWidth - docEl.clientWidth}px`), setStyle(docEl, "overflow", "hidden"), setStyle(doc.body, "marginTop", `-${scrollY}px`));
432
- win.scrollTo(0, 0);
433
- let removeEvents = pipe(addDomEvent(doc, "touchstart", onTouchStart, { passive: false, capture: true }), addDomEvent(doc, "touchmove", onTouchMove, { passive: false, capture: true }), addDomEvent(doc, "touchend", onTouchEnd, { passive: false, capture: true }), addDomEvent(doc, "focus", onFocus, true), addDomEvent(win, "scroll", onWindowScroll), () => docEl.setAttribute("scroll-lock", "true"));
434
- return () => {
435
- restoreStyles();
436
- removeEvents();
437
- win.scrollTo(scrollX, scrollY);
438
- docEl.removeAttribute("scroll-lock");
439
- };
440
- }
441
- if (disabled)
442
- return noop;
443
- return isIos() ? preventScrollMobileSafari() : preventScrollStandard();
444
- }
445
- function setStyle(el, key, value) {
446
- let cur = el.style[key];
447
- el.style[key] = value;
448
- return () => {
449
- el.style[key] = cur;
450
- };
451
- }
452
209
  function validateBlur(event, opts) {
453
210
  var _a;
454
211
  const exclude = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
@@ -603,6 +360,8 @@ function nextIndex(v, idx, opts = {}) {
603
360
  function next(v, idx, opts = {}) {
604
361
  return v[nextIndex(v, idx, opts)];
605
362
  }
363
+ var isDom2 = () => typeof window !== "undefined";
364
+ var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
606
365
  var runIfFn2 = (v, ...a) => {
607
366
  const res = typeof v === "function" ? v(...a) : v;
608
367
  return res != null ? res : void 0;
@@ -782,6 +541,7 @@ function connect(state, send, normalize = normalizeProp) {
782
541
  import { ariaHidden } from "@zag-js/aria-hidden";
783
542
  import { createMachine, guards, ref } from "@zag-js/core";
784
543
  import { getPlacement } from "@zag-js/popper";
544
+ import { preventBodyScroll } from "@zag-js/remove-scroll";
785
545
  import { createFocusTrap } from "focus-trap";
786
546
  var { and, or } = guards;
787
547
  function machine(ctx = {}) {
@@ -812,7 +572,7 @@ function machine(ctx = {}) {
812
572
  unknown: {
813
573
  on: {
814
574
  SETUP: {
815
- target: "closed",
575
+ target: ctx.open ? "open" : "closed",
816
576
  actions: ["setupDocument", "checkRenderedElements"]
817
577
  }
818
578
  }
@@ -911,7 +671,6 @@ function machine(ctx = {}) {
911
671
  },
912
672
  preventScroll(ctx2) {
913
673
  return preventBodyScroll({
914
- allowPinchZoom: true,
915
674
  disabled: !ctx2.modal,
916
675
  document: dom.getDoc(ctx2)
917
676
  });
@@ -934,7 +693,7 @@ function machine(ctx = {}) {
934
693
  });
935
694
  try {
936
695
  trap.activate();
937
- } catch (e2) {
696
+ } catch (e) {
938
697
  }
939
698
  });
940
699
  return () => trap == null ? void 0 : trap.deactivate();