@zag-js/remove-scroll 0.1.0 → 0.1.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Chakra UI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # @zag-js/remove-scroll
2
2
 
3
-
4
-
5
3
  ## Installation
6
4
 
7
5
  ```sh
@@ -12,11 +10,8 @@ npm i @zag-js/remove-scroll
12
10
 
13
11
  ## Contribution
14
12
 
15
- Yes please! See the
16
- [contributing guidelines](https://github.com/chakra-ui/zag/blob/main/CONTRIBUTING.md)
17
- for details.
13
+ Yes please! See the [contributing guidelines](https://github.com/chakra-ui/zag/blob/main/CONTRIBUTING.md) for details.
18
14
 
19
15
  ## Licence
20
16
 
21
- This project is licensed under the terms of the
22
- [MIT license](https://github.com/chakra-ui/zag/blob/main/LICENSE).
17
+ This project is licensed under the terms of the [MIT license](https://github.com/chakra-ui/zag/blob/main/LICENSE).
package/dist/index.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- interface BodyScrollOptions {
2
- disabled?: boolean;
3
- document?: Document;
4
- }
5
- export declare function preventBodyScroll(options?: BodyScrollOptions): () => void;
6
- export {};
7
- //# sourceMappingURL=index.d.ts.map
1
+ declare function preventBodyScroll(_document?: Document): (() => void) | undefined;
2
+
3
+ export { preventBodyScroll };
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -23,21 +24,20 @@ __export(src_exports, {
23
24
  });
24
25
  module.exports = __toCommonJS(src_exports);
25
26
 
26
- // ../core/dist/index.mjs
27
+ // ../dom/dist/index.mjs
27
28
  var isDom = () => typeof window !== "undefined";
28
29
  function getPlatform() {
29
- var _a;
30
30
  const agent = navigator.userAgentData;
31
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
31
+ return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
32
32
  }
33
33
  var pt = (v) => isDom() && v.test(getPlatform());
34
- var isTouchDevice = isDom() && !!navigator.maxTouchPoints;
34
+ var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
35
35
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
36
36
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
37
37
  var isIos = () => isApple() && !isMac();
38
38
 
39
39
  // src/index.ts
40
- var identifier = "data-scroll-lock";
40
+ var LOCK_CLASSNAME = "data-scroll-lock";
41
41
  function assignStyle(el, style) {
42
42
  if (!el)
43
43
  return () => {
@@ -67,18 +67,14 @@ function getPaddingProperty(documentElement) {
67
67
  const scrollbarX = Math.round(documentLeft) + documentElement.scrollLeft;
68
68
  return scrollbarX ? "paddingLeft" : "paddingRight";
69
69
  }
70
- function preventBodyScroll(options = {}) {
71
- var _a;
72
- const { document: docProp, disabled } = options;
73
- if (disabled)
74
- return;
75
- const doc = docProp != null ? docProp : document;
76
- const win = (_a = doc == null ? void 0 : doc.defaultView) != null ? _a : window;
70
+ function preventBodyScroll(_document) {
71
+ const doc = _document ?? document;
72
+ const win = doc.defaultView ?? window;
77
73
  const { documentElement, body } = doc;
78
- const locked = body.hasAttribute(identifier);
74
+ const locked = body.hasAttribute(LOCK_CLASSNAME);
79
75
  if (locked)
80
76
  return;
81
- body.setAttribute(identifier, "");
77
+ body.setAttribute(LOCK_CLASSNAME, "");
82
78
  const scrollbarWidth = win.innerWidth - documentElement.clientWidth;
83
79
  const setScrollbarWidthProperty = () => setCSSProperty(documentElement, "--scrollbar-width", `${scrollbarWidth}px`);
84
80
  const paddingProperty = getPaddingProperty(documentElement);
@@ -87,10 +83,9 @@ function preventBodyScroll(options = {}) {
87
83
  [paddingProperty]: `${scrollbarWidth}px`
88
84
  });
89
85
  const setIOSStyle = () => {
90
- var _a2, _b;
91
86
  const { scrollX, scrollY, visualViewport } = win;
92
- const offsetLeft = (_a2 = visualViewport == null ? void 0 : visualViewport.offsetLeft) != null ? _a2 : 0;
93
- const offsetTop = (_b = visualViewport == null ? void 0 : visualViewport.offsetTop) != null ? _b : 0;
87
+ const offsetLeft = (visualViewport == null ? void 0 : visualViewport.offsetLeft) ?? 0;
88
+ const offsetTop = (visualViewport == null ? void 0 : visualViewport.offsetTop) ?? 0;
94
89
  const restoreStyle = assignStyle(body, {
95
90
  position: "fixed",
96
91
  overflow: "hidden",
@@ -107,7 +102,10 @@ function preventBodyScroll(options = {}) {
107
102
  const cleanups = [setScrollbarWidthProperty(), isIos() ? setIOSStyle() : setStyle()];
108
103
  return () => {
109
104
  cleanups.forEach((cleanup) => cleanup());
110
- body.removeAttribute(identifier);
105
+ body.removeAttribute(LOCK_CLASSNAME);
111
106
  };
112
107
  }
113
- //# sourceMappingURL=index.js.map
108
+ // Annotate the CommonJS export names for ESM import in node:
109
+ 0 && (module.exports = {
110
+ preventBodyScroll
111
+ });
package/dist/index.mjs CHANGED
@@ -1,18 +1,17 @@
1
- // ../core/dist/index.mjs
1
+ // ../dom/dist/index.mjs
2
2
  var isDom = () => typeof window !== "undefined";
3
3
  function getPlatform() {
4
- var _a;
5
4
  const agent = navigator.userAgentData;
6
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
5
+ return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
7
6
  }
8
7
  var pt = (v) => isDom() && v.test(getPlatform());
9
- var isTouchDevice = isDom() && !!navigator.maxTouchPoints;
8
+ var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
10
9
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
11
10
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
12
11
  var isIos = () => isApple() && !isMac();
13
12
 
14
13
  // src/index.ts
15
- var identifier = "data-scroll-lock";
14
+ var LOCK_CLASSNAME = "data-scroll-lock";
16
15
  function assignStyle(el, style) {
17
16
  if (!el)
18
17
  return () => {
@@ -42,18 +41,14 @@ function getPaddingProperty(documentElement) {
42
41
  const scrollbarX = Math.round(documentLeft) + documentElement.scrollLeft;
43
42
  return scrollbarX ? "paddingLeft" : "paddingRight";
44
43
  }
45
- function preventBodyScroll(options = {}) {
46
- var _a;
47
- const { document: docProp, disabled } = options;
48
- if (disabled)
49
- return;
50
- const doc = docProp != null ? docProp : document;
51
- const win = (_a = doc == null ? void 0 : doc.defaultView) != null ? _a : window;
44
+ function preventBodyScroll(_document) {
45
+ const doc = _document ?? document;
46
+ const win = doc.defaultView ?? window;
52
47
  const { documentElement, body } = doc;
53
- const locked = body.hasAttribute(identifier);
48
+ const locked = body.hasAttribute(LOCK_CLASSNAME);
54
49
  if (locked)
55
50
  return;
56
- body.setAttribute(identifier, "");
51
+ body.setAttribute(LOCK_CLASSNAME, "");
57
52
  const scrollbarWidth = win.innerWidth - documentElement.clientWidth;
58
53
  const setScrollbarWidthProperty = () => setCSSProperty(documentElement, "--scrollbar-width", `${scrollbarWidth}px`);
59
54
  const paddingProperty = getPaddingProperty(documentElement);
@@ -62,10 +57,9 @@ function preventBodyScroll(options = {}) {
62
57
  [paddingProperty]: `${scrollbarWidth}px`
63
58
  });
64
59
  const setIOSStyle = () => {
65
- var _a2, _b;
66
60
  const { scrollX, scrollY, visualViewport } = win;
67
- const offsetLeft = (_a2 = visualViewport == null ? void 0 : visualViewport.offsetLeft) != null ? _a2 : 0;
68
- const offsetTop = (_b = visualViewport == null ? void 0 : visualViewport.offsetTop) != null ? _b : 0;
61
+ const offsetLeft = (visualViewport == null ? void 0 : visualViewport.offsetLeft) ?? 0;
62
+ const offsetTop = (visualViewport == null ? void 0 : visualViewport.offsetTop) ?? 0;
69
63
  const restoreStyle = assignStyle(body, {
70
64
  position: "fixed",
71
65
  overflow: "hidden",
@@ -82,10 +76,9 @@ function preventBodyScroll(options = {}) {
82
76
  const cleanups = [setScrollbarWidthProperty(), isIos() ? setIOSStyle() : setStyle()];
83
77
  return () => {
84
78
  cleanups.forEach((cleanup) => cleanup());
85
- body.removeAttribute(identifier);
79
+ body.removeAttribute(LOCK_CLASSNAME);
86
80
  };
87
81
  }
88
82
  export {
89
83
  preventBodyScroll
90
84
  };
91
- //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/remove-scroll",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "JavaScript utility to remove scroll on body",
5
5
  "keywords": [
6
6
  "js",
@@ -18,22 +18,22 @@
18
18
  "files": [
19
19
  "dist/**/*"
20
20
  ],
21
- "scripts": {
22
- "build:fast": "yarn zag build",
23
- "start": "yarn zag build --watch",
24
- "build": "yarn zag build --prod",
25
- "test": "jest --config ../../../jest.config.js --rootDir tests",
26
- "lint": "eslint src --ext .ts,.tsx",
27
- "test:ci": "yarn test --ci --runInBand --updateSnapshot",
28
- "test:watch": "yarn test --watchAll"
29
- },
30
21
  "publishConfig": {
31
22
  "access": "public"
32
23
  },
33
- "dependencies": {
34
- "@zag-js/utils": "0.1.2"
24
+ "devDependencies": {
25
+ "@zag-js/dom-utils": "0.1.8"
35
26
  },
36
27
  "bugs": {
37
28
  "url": "https://github.com/chakra-ui/zag/issues"
29
+ },
30
+ "scripts": {
31
+ "build-fast": "tsup src/index.ts --format=esm,cjs",
32
+ "start": "pnpm build --watch",
33
+ "build": "tsup src/index.ts --format=esm,cjs --dts",
34
+ "test": "jest --config ../../../jest.config.js --rootDir tests",
35
+ "lint": "eslint src --ext .ts,.tsx",
36
+ "test-ci": "pnpm test --ci --runInBand -u",
37
+ "test-watch": "pnpm test --watchAll"
38
38
  }
39
- }
39
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiCA,UAAU,iBAAiB;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,iBAAsB,cAqDhE"}
package/dist/index.js.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/index.ts", "../../core/src/array.ts", "../../core/src/guard.ts", "../../core/src/platform.ts", "../../core/src/events.ts", "../../core/src/functions.ts", "../../core/src/warning.ts"],
4
- "sourcesContent": ["import { isIos } from \"@zag-js/utils\"\n\nconst identifier = \"data-scroll-lock\"\n\nfunction assignStyle(el: HTMLElement | null | undefined, style: Partial<CSSStyleDeclaration>) {\n if (!el) return () => {}\n const previousStyle = el.style.cssText\n Object.assign(el.style, style)\n return () => {\n el.style.cssText = previousStyle\n }\n}\n\nfunction setCSSProperty(el: HTMLElement | null | undefined, property: string, value: string) {\n if (!el) return () => {}\n const previousValue = el.style.getPropertyValue(property)\n el.style.setProperty(property, value)\n return () => {\n if (previousValue) {\n el.style.setProperty(property, previousValue)\n } else {\n el.style.removeProperty(property)\n }\n }\n}\n\nfunction getPaddingProperty(documentElement: HTMLElement) {\n // RTL <body> scrollbar\n const documentLeft = documentElement.getBoundingClientRect().left\n const scrollbarX = Math.round(documentLeft) + documentElement.scrollLeft\n return scrollbarX ? \"paddingLeft\" : \"paddingRight\"\n}\n\ninterface BodyScrollOptions {\n disabled?: boolean\n document?: Document\n}\n\nexport function preventBodyScroll(options: BodyScrollOptions = {}) {\n const { document: docProp, disabled } = options\n\n if (disabled) return\n\n const doc = docProp ?? document\n const win = doc?.defaultView ?? window\n const { documentElement, body } = doc\n\n const locked = body.hasAttribute(identifier)\n if (locked) return\n\n body.setAttribute(identifier, \"\")\n\n const scrollbarWidth = win.innerWidth - documentElement.clientWidth\n const setScrollbarWidthProperty = () => setCSSProperty(documentElement, \"--scrollbar-width\", `${scrollbarWidth}px`)\n const paddingProperty = getPaddingProperty(documentElement)\n\n const setStyle = () =>\n assignStyle(body, {\n overflow: \"hidden\",\n [paddingProperty]: `${scrollbarWidth}px`,\n })\n\n // Only iOS doesn't respect `overflow: hidden` on document.body\n const setIOSStyle = () => {\n const { scrollX, scrollY, visualViewport } = win\n\n // iOS 12 does not support `visuaViewport`.\n const offsetLeft = visualViewport?.offsetLeft ?? 0\n const offsetTop = visualViewport?.offsetTop ?? 0\n\n const restoreStyle = assignStyle(body, {\n position: \"fixed\",\n overflow: \"hidden\",\n top: `${-(scrollY - Math.floor(offsetTop))}px`,\n left: `${-(scrollX - Math.floor(offsetLeft))}px`,\n right: \"0\",\n [paddingProperty]: `${scrollbarWidth}px`,\n })\n\n return () => {\n restoreStyle()\n win.scrollTo(scrollX, scrollY)\n }\n }\n\n const cleanups = [setScrollbarWidthProperty(), isIos() ? setIOSStyle() : setStyle()]\n\n return () => {\n cleanups.forEach((cleanup) => cleanup())\n body.removeAttribute(identifier)\n }\n}\n", "export function toArray<T>(v: T | T[] | undefined | null): T[] {\n if (!v) return []\n return Array.isArray(v) ? v : [v]\n}\n\nexport const fromLength = (length: number) => Array.from(Array(length).keys())\n\nexport const first = <T>(v: T[]): T | undefined => v[0]\n\nexport const last = <T>(v: T[]): T | undefined => v[v.length - 1]\n\nexport const isEmpty = <T>(v: T[]): boolean => v.length === 0\n\nexport const has = <T>(v: T[], t: any): boolean => v.indexOf(t) !== -1\n\nexport const add = <T>(v: T[], ...items: T[]): T[] => v.concat(items)\n\nexport const remove = <T>(v: T[], item: T): T[] => removeAt(v, v.indexOf(item))\n\nexport const removeAt = <T>(v: T[], i: number): T[] => {\n if (i > -1) v.splice(i, 1)\n return v\n}\n\nexport function clear<T>(v: T[]): T[] {\n while (v.length > 0) v.pop()\n return v\n}\n\nexport type IndexOptions = {\n step?: number\n loop?: boolean\n}\n\nexport function nextIndex<T>(v: T[], idx: number, opts: IndexOptions = {}): number {\n const { step = 1, loop = true } = opts\n const next = idx + step\n const len = v.length\n const last = len - 1\n if (idx === -1) return step > 0 ? 0 : last\n if (next < 0) return loop ? last : 0\n if (next >= len) return loop ? 0 : idx > len ? len : idx\n return next\n}\n\nexport function next<T>(v: T[], idx: number, opts: IndexOptions = {}): T | undefined {\n return v[nextIndex(v, idx, opts)]\n}\n\nexport function prevIndex<T>(v: T[], idx: number, opts: IndexOptions = {}): number {\n const { step = 1, loop = true } = opts\n return nextIndex(v, idx, { step: -step, loop })\n}\n\nexport function prev<T>(v: T[], index: number, opts: IndexOptions = {}): T | undefined {\n return v[prevIndex(v, index, opts)]\n}\n\nexport const chunk = <T>(v: T[], size: number): T[][] => {\n const res: T[][] = []\n return v.reduce((rows, value, index) => {\n if (index % size === 0) rows.push([value])\n else last(rows)?.push(value)\n return rows\n }, res)\n}\n", "export const isDev = () => process.env.NODE_ENV !== \"production\"\nexport const isDom = () => typeof window !== \"undefined\"\n\nexport const isArray = (v: any): v is any[] => Array.isArray(v)\nexport const isBoolean = (v: any): v is boolean => v === true || v === false\nexport const isObject = (v: any): v is Record<string, any> => !(v == null || typeof v !== \"object\" || isArray(v))\nexport const isNumber = (v: any): v is number => typeof v === \"number\" && !Number.isNaN(v)\nexport const isString = (v: any): v is string => typeof v === \"string\"\nexport const isFunction = (v: any): v is Function => typeof v === \"function\"\n\nexport const hasProp = <T extends string>(obj: any, prop: T): obj is Record<T, any> =>\n Object.prototype.hasOwnProperty.call(obj, prop)\n", "import { isDom } from \"./guard\"\n\nexport function getPlatform() {\n const agent = (navigator as any).userAgentData\n return agent?.platform ?? navigator.platform\n}\n\nconst pt = (v: RegExp) => isDom() && v.test(getPlatform())\nconst ua = (v: RegExp) => isDom() && v.test(navigator.userAgent)\nconst vn = (v: RegExp) => isDom() && v.test(navigator.vendor)\n\nexport const isTouchDevice = isDom() && !!navigator.maxTouchPoints\nexport const isMac = () => pt(/^Mac/) && !isTouchDevice\nexport const isIPhone = () => pt(/^iPhone/)\nexport const isSafari = () => isApple() && vn(/apple/i)\nexport const isFirefox = () => ua(/firefox\\//i)\nexport const isApple = () => pt(/mac|iphone|ipad|ipod/i)\nexport const isIos = () => isApple() && !isMac()\n", "import { hasProp, isDom, isObject } from \"./guard\"\nimport { isMac } from \"./platform\"\n\nexport const supportsPointerEvent = () => isDom() && window.onpointerdown === null\nexport const supportsTouchEvent = () => isDom() && window.ontouchstart === null\nexport const supportsMouseEvent = () => isDom() && window.onmousedown === null\n\nexport const isMouseEvent = (v: any): v is MouseEvent => isObject(v) && hasProp(v, \"button\")\nexport const isTouchEvent = (v: any): v is TouchEvent => isObject(v) && hasProp(v, \"touches\")\nexport const isLeftClick = (v: { button: number }) => v.button === 0\nexport const isRightClick = (v: { button: number }) => v.button === 2\nexport const isModifiedEvent = (v: Pick<KeyboardEvent, \"ctrlKey\" | \"metaKey\" | \"altKey\">) =>\n v.ctrlKey || v.altKey || v.metaKey\n\nexport const isCtrlKey = (v: Pick<KeyboardEvent, \"ctrlKey\" | \"metaKey\">) =>\n isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey\n", "export const runIfFn = <T>(\n v: T | undefined,\n ...a: T extends (...a: any[]) => void ? Parameters<T> : never\n): T extends (...a: any[]) => void ? NonNullable<ReturnType<T>> : NonNullable<T> => {\n const res = typeof v === \"function\" ? v(...a) : v\n return res ?? undefined\n}\n\nexport const cast = <T>(v: unknown): T => v as T\n\nexport const noop = () => {}\n\nexport const pipe =\n <T>(...fns: Array<(a: T) => T>) =>\n (v: T) =>\n fns.reduce((a, b) => b(a), v)\n\nexport const callAll =\n <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) =>\n (...a: Parameters<T>) => {\n fns.forEach(function (fn) {\n fn?.(...a)\n })\n }\n\nexport const uuid = /*#__PURE__*/ (() => {\n let id = 0\n return () => {\n id++\n return id.toString(36)\n }\n})()\n\nexport function merge<T, U>(origin: T, patch: U): T & U {\n if (!(typeof patch === \"object\")) return patch as any\n const result = !(typeof origin === \"object\") ? {} : Object.assign({}, origin)\n for (const key of Object.keys(patch)) {\n const value = patch[key]\n const src = result[key]\n if (value === null) delete result[key]\n else if (Array.isArray(value) || Array.isArray(src)) result[key] = (src || []).concat(value || [])\n else result[key] = merge(src, value)\n }\n return result as any\n}\n", "export function warn(m: string): void\nexport function warn(c: boolean, m: string): void\nexport function warn(...a: any[]): void {\n const m = a.length === 1 ? a[0] : a[1]\n const c = a.length === 2 ? a[0] : true\n if (c && process.env.NODE_ENV !== \"production\") {\n console.warn(m)\n }\n}\n\nexport function invariant(m: string): void\nexport function invariant(c: boolean, m: string): void\nexport function invariant(...a: any[]): void {\n const m = a.length === 1 ? a[0] : a[1]\n const c = a.length === 2 ? a[0] : true\n if (c && process.env.NODE_ENV !== \"production\") {\n throw new Error(m)\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AECO,IAAM,QAAQ,MAAM,OAAO,WAAW;ACCtC,uBAAuB;AAF9B,MAAA;AAGE,QAAM,QAAS,UAAkB;AACjC,SAAO,MAAA,SAAA,OAAA,SAAA,MAAO,a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;AAEZ,OAAK,aAAa,YAAY,EAAE;AAEhC,QAAM,iBAAiB,IAAI,aAAa,gBAAgB;AACxD,QAAM,4BAA4B,MAAM,eAAe,iBAAiB,qBAAqB,GAAG,kBAAkB;AAClH,QAAM,kBAAkB,mBAAmB,eAAe;AAE1D,QAAM,WAAW,MACf,YAAY,MAAM;AAAA,IAChB,UAAU;AAAA,KACT,kBAAkB,GAAG;AAAA,EACxB,CAAC;AAGH,QAAM,cAAc,MAAM;AA/D5B;AAgEI,UAAM,EAAE,SAAS,SAAS,mBAAmB;AAG7C,UAAM,aAAa,wDAAgB,eAAhB,aAA8B;AACjD,UAAM,YAAY,uDAAgB,cAAhB,YAA6B;AAE/C,UAAM,eAAe,YAAY,MAAM;AAAA,MACrC,UAAU;AAAA,MACV,UAAU;AAAA,MACV,KAAK,GAAG,CAAE,WAAU,KAAK,MAAM,SAAS;AAAA,MACxC,MAAM,GAAG,CAAE,WAAU,KAAK,MAAM,UAAU;AAAA,MAC1C,OAAO;AAAA,OACN,kBAAkB,GAAG;AAAA,IACxB,CAAC;AAED,WAAO,MAAM;AACX,mBAAa;AACb,UAAI,SAAS,SAAS,OAAO;AAAA,IAC/B;AAAA,EACF;AAEA,QAAM,WAAW,CAAC,0BAA0B,GAAG,MAAM,IAAI,YAAY,IAAI,SAAS,CAAC;AAEnF,SAAO,MAAM;AACX,aAAS,QAAQ,CAAC,YAAY,QAAQ,CAAC;AACvC,SAAK,gBAAgB,UAAU;AAAA,EACjC;AACF;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../core/src/array.ts", "../../core/src/guard.ts", "../../core/src/platform.ts", "../../core/src/events.ts", "../../core/src/functions.ts", "../../core/src/warning.ts", "../src/index.ts"],
4
- "sourcesContent": ["export function toArray<T>(v: T | T[] | undefined | null): T[] {\n if (!v) return []\n return Array.isArray(v) ? v : [v]\n}\n\nexport const fromLength = (length: number) => Array.from(Array(length).keys())\n\nexport const first = <T>(v: T[]): T | undefined => v[0]\n\nexport const last = <T>(v: T[]): T | undefined => v[v.length - 1]\n\nexport const isEmpty = <T>(v: T[]): boolean => v.length === 0\n\nexport const has = <T>(v: T[], t: any): boolean => v.indexOf(t) !== -1\n\nexport const add = <T>(v: T[], ...items: T[]): T[] => v.concat(items)\n\nexport const remove = <T>(v: T[], item: T): T[] => removeAt(v, v.indexOf(item))\n\nexport const removeAt = <T>(v: T[], i: number): T[] => {\n if (i > -1) v.splice(i, 1)\n return v\n}\n\nexport function clear<T>(v: T[]): T[] {\n while (v.length > 0) v.pop()\n return v\n}\n\nexport type IndexOptions = {\n step?: number\n loop?: boolean\n}\n\nexport function nextIndex<T>(v: T[], idx: number, opts: IndexOptions = {}): number {\n const { step = 1, loop = true } = opts\n const next = idx + step\n const len = v.length\n const last = len - 1\n if (idx === -1) return step > 0 ? 0 : last\n if (next < 0) return loop ? last : 0\n if (next >= len) return loop ? 0 : idx > len ? len : idx\n return next\n}\n\nexport function next<T>(v: T[], idx: number, opts: IndexOptions = {}): T | undefined {\n return v[nextIndex(v, idx, opts)]\n}\n\nexport function prevIndex<T>(v: T[], idx: number, opts: IndexOptions = {}): number {\n const { step = 1, loop = true } = opts\n return nextIndex(v, idx, { step: -step, loop })\n}\n\nexport function prev<T>(v: T[], index: number, opts: IndexOptions = {}): T | undefined {\n return v[prevIndex(v, index, opts)]\n}\n\nexport const chunk = <T>(v: T[], size: number): T[][] => {\n const res: T[][] = []\n return v.reduce((rows, value, index) => {\n if (index % size === 0) rows.push([value])\n else last(rows)?.push(value)\n return rows\n }, res)\n}\n", "export const isDev = () => process.env.NODE_ENV !== \"production\"\nexport const isDom = () => typeof window !== \"undefined\"\n\nexport const isArray = (v: any): v is any[] => Array.isArray(v)\nexport const isBoolean = (v: any): v is boolean => v === true || v === false\nexport const isObject = (v: any): v is Record<string, any> => !(v == null || typeof v !== \"object\" || isArray(v))\nexport const isNumber = (v: any): v is number => typeof v === \"number\" && !Number.isNaN(v)\nexport const isString = (v: any): v is string => typeof v === \"string\"\nexport const isFunction = (v: any): v is Function => typeof v === \"function\"\n\nexport const hasProp = <T extends string>(obj: any, prop: T): obj is Record<T, any> =>\n Object.prototype.hasOwnProperty.call(obj, prop)\n", "import { isDom } from \"./guard\"\n\nexport function getPlatform() {\n const agent = (navigator as any).userAgentData\n return agent?.platform ?? navigator.platform\n}\n\nconst pt = (v: RegExp) => isDom() && v.test(getPlatform())\nconst ua = (v: RegExp) => isDom() && v.test(navigator.userAgent)\nconst vn = (v: RegExp) => isDom() && v.test(navigator.vendor)\n\nexport const isTouchDevice = isDom() && !!navigator.maxTouchPoints\nexport const isMac = () => pt(/^Mac/) && !isTouchDevice\nexport const isIPhone = () => pt(/^iPhone/)\nexport const isSafari = () => isApple() && vn(/apple/i)\nexport const isFirefox = () => ua(/firefox\\//i)\nexport const isApple = () => pt(/mac|iphone|ipad|ipod/i)\nexport const isIos = () => isApple() && !isMac()\n", "import { hasProp, isDom, isObject } from \"./guard\"\nimport { isMac } from \"./platform\"\n\nexport const supportsPointerEvent = () => isDom() && window.onpointerdown === null\nexport const supportsTouchEvent = () => isDom() && window.ontouchstart === null\nexport const supportsMouseEvent = () => isDom() && window.onmousedown === null\n\nexport const isMouseEvent = (v: any): v is MouseEvent => isObject(v) && hasProp(v, \"button\")\nexport const isTouchEvent = (v: any): v is TouchEvent => isObject(v) && hasProp(v, \"touches\")\nexport const isLeftClick = (v: { button: number }) => v.button === 0\nexport const isRightClick = (v: { button: number }) => v.button === 2\nexport const isModifiedEvent = (v: Pick<KeyboardEvent, \"ctrlKey\" | \"metaKey\" | \"altKey\">) =>\n v.ctrlKey || v.altKey || v.metaKey\n\nexport const isCtrlKey = (v: Pick<KeyboardEvent, \"ctrlKey\" | \"metaKey\">) =>\n isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey\n", "export const runIfFn = <T>(\n v: T | undefined,\n ...a: T extends (...a: any[]) => void ? Parameters<T> : never\n): T extends (...a: any[]) => void ? NonNullable<ReturnType<T>> : NonNullable<T> => {\n const res = typeof v === \"function\" ? v(...a) : v\n return res ?? undefined\n}\n\nexport const cast = <T>(v: unknown): T => v as T\n\nexport const noop = () => {}\n\nexport const pipe =\n <T>(...fns: Array<(a: T) => T>) =>\n (v: T) =>\n fns.reduce((a, b) => b(a), v)\n\nexport const callAll =\n <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) =>\n (...a: Parameters<T>) => {\n fns.forEach(function (fn) {\n fn?.(...a)\n })\n }\n\nexport const uuid = /*#__PURE__*/ (() => {\n let id = 0\n return () => {\n id++\n return id.toString(36)\n }\n})()\n\nexport function merge<T, U>(origin: T, patch: U): T & U {\n if (!(typeof patch === \"object\")) return patch as any\n const result = !(typeof origin === \"object\") ? {} : Object.assign({}, origin)\n for (const key of Object.keys(patch)) {\n const value = patch[key]\n const src = result[key]\n if (value === null) delete result[key]\n else if (Array.isArray(value) || Array.isArray(src)) result[key] = (src || []).concat(value || [])\n else result[key] = merge(src, value)\n }\n return result as any\n}\n", "export function warn(m: string): void\nexport function warn(c: boolean, m: string): void\nexport function warn(...a: any[]): void {\n const m = a.length === 1 ? a[0] : a[1]\n const c = a.length === 2 ? a[0] : true\n if (c && process.env.NODE_ENV !== \"production\") {\n console.warn(m)\n }\n}\n\nexport function invariant(m: string): void\nexport function invariant(c: boolean, m: string): void\nexport function invariant(...a: any[]): void {\n const m = a.length === 1 ? a[0] : a[1]\n const c = a.length === 2 ? a[0] : true\n if (c && process.env.NODE_ENV !== \"production\") {\n throw new Error(m)\n }\n}\n", "import { isIos } from \"@zag-js/utils\"\n\nconst identifier = \"data-scroll-lock\"\n\nfunction assignStyle(el: HTMLElement | null | undefined, style: Partial<CSSStyleDeclaration>) {\n if (!el) return () => {}\n const previousStyle = el.style.cssText\n Object.assign(el.style, style)\n return () => {\n el.style.cssText = previousStyle\n }\n}\n\nfunction setCSSProperty(el: HTMLElement | null | undefined, property: string, value: string) {\n if (!el) return () => {}\n const previousValue = el.style.getPropertyValue(property)\n el.style.setProperty(property, value)\n return () => {\n if (previousValue) {\n el.style.setProperty(property, previousValue)\n } else {\n el.style.removeProperty(property)\n }\n }\n}\n\nfunction getPaddingProperty(documentElement: HTMLElement) {\n // RTL <body> scrollbar\n const documentLeft = documentElement.getBoundingClientRect().left\n const scrollbarX = Math.round(documentLeft) + documentElement.scrollLeft\n return scrollbarX ? \"paddingLeft\" : \"paddingRight\"\n}\n\ninterface BodyScrollOptions {\n disabled?: boolean\n document?: Document\n}\n\nexport function preventBodyScroll(options: BodyScrollOptions = {}) {\n const { document: docProp, disabled } = options\n\n if (disabled) return\n\n const doc = docProp ?? document\n const win = doc?.defaultView ?? window\n const { documentElement, body } = doc\n\n const locked = body.hasAttribute(identifier)\n if (locked) return\n\n body.setAttribute(identifier, \"\")\n\n const scrollbarWidth = win.innerWidth - documentElement.clientWidth\n const setScrollbarWidthProperty = () => setCSSProperty(documentElement, \"--scrollbar-width\", `${scrollbarWidth}px`)\n const paddingProperty = getPaddingProperty(documentElement)\n\n const setStyle = () =>\n assignStyle(body, {\n overflow: \"hidden\",\n [paddingProperty]: `${scrollbarWidth}px`,\n })\n\n // Only iOS doesn't respect `overflow: hidden` on document.body\n const setIOSStyle = () => {\n const { scrollX, scrollY, visualViewport } = win\n\n // iOS 12 does not support `visuaViewport`.\n const offsetLeft = visualViewport?.offsetLeft ?? 0\n const offsetTop = visualViewport?.offsetTop ?? 0\n\n const restoreStyle = assignStyle(body, {\n position: \"fixed\",\n overflow: \"hidden\",\n top: `${-(scrollY - Math.floor(offsetTop))}px`,\n left: `${-(scrollX - Math.floor(offsetLeft))}px`,\n right: \"0\",\n [paddingProperty]: `${scrollbarWidth}px`,\n })\n\n return () => {\n restoreStyle()\n win.scrollTo(scrollX, scrollY)\n }\n }\n\n const cleanups = [setScrollbarWidthProperty(), isIos() ? setIOSStyle() : setStyle()]\n\n return () => {\n cleanups.forEach((cleanup) => cleanup())\n body.removeAttribute(identifier)\n }\n}\n"],
5
- "mappings": ";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