@smakss/react-scroll-direction 3.0.1 → 3.1.0-beta.0

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/Readme.md CHANGED
@@ -72,3 +72,11 @@ const scrollDir = useDetectScroll({ axis: "x" });
72
72
 
73
73
  // Returns: "left", "right", or "still"
74
74
  ```
75
+
76
+ ## Contributing
77
+
78
+ Interested in making contributions to this project? Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines and details.
79
+
80
+ ## Code of Conduct
81
+
82
+ We value and prioritize the well-being of all our contributors and users. To ensure that this project remains a welcoming space for everyone, please refer to our [Code of Conduct](./CODE_OF_CONDUCT.md).
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { useState, useEffect, useCallback } from \"react\";\n/** Enumeration for axis values */\nexport var Axis;\n(function (Axis) {\n Axis[\"X\"] = \"x\";\n Axis[\"Y\"] = \"y\";\n})(Axis || (Axis = {}));\n/** Enumeration for direction values */\nexport var Direction;\n(function (Direction) {\n Direction[\"Up\"] = \"up\";\n Direction[\"Down\"] = \"down\";\n Direction[\"Left\"] = \"left\";\n Direction[\"Right\"] = \"right\";\n Direction[\"Still\"] = \"still\";\n})(Direction || (Direction = {}));\n/**\n * useDetectScroll hook.\n *\n * This hook provides a mechanism to detect the scroll direction.\n * It will return the scroll direction as a string (up, down, left, right, or still) based on user scrolling.\n *\n * @example\n *\n * import useDetectScroll, { Axis, Direction } from '@smakss/react-scroll-direction';\n *\n * function App() {\n * const scrollDirection = useDetectScroll({\n * thr: 100,\n * axis: Axis.Y,\n * scrollUp: Direction.Up,\n * scrollDown: Direction.Down,\n * still: Direction.Still\n * });\n *\n * return (\n * <div>\n * <p>Current scroll direction: {scrollDirection}</p>\n * </div>\n * );\n * }\n *\n * @param {ScrollProps} props - The properties related to scrolling.\n * @property {number} props.thr - The threshold value which the scroll difference must exceed to update scroll direction.\n * @property {Axis} props.axis - The axis along which to detect scroll. Can be 'x' or 'y'.\n * @property {Direction} props.scrollUp - The direction to set when scrolling up or left. By default, 'up' for y-axis and 'left' for x-axis.\n * @property {Direction} props.scrollDown - The direction to set when scrolling down or right. By default, 'down' for y-axis and 'right' for x-axis.\n * @property {Direction} props.still - The direction to set when there is no scrolling. By default, 'still'.\n *\n * @returns {Direction} - The current direction of scrolling.\n */\nfunction useDetectScroll(props = {}) {\n const { thr = 0, axis = Axis.Y, scrollUp = axis === Axis.Y ? Direction.Up : Direction.Left, scrollDown = axis === Axis.Y ? Direction.Down : Direction.Right, still = Direction.Still, } = props;\n const [scrollDir, setScrollDir] = useState(still);\n const threshold = Math.max(0, thr);\n let ticking = false;\n let lastScroll = 0;\n /** Function to update scroll direction */\n const updateScrollDir = useCallback(() => {\n const scroll = axis === Axis.Y ? window.scrollY : window.scrollX;\n if (Math.abs(scroll - lastScroll) >= threshold) {\n setScrollDir(scroll > lastScroll ? scrollDown : scrollUp);\n lastScroll = Math.max(0, scroll);\n }\n ticking = false;\n }, [axis, threshold, scrollDown, scrollUp]);\n useEffect(() => {\n lastScroll = axis === Axis.Y ? window.scrollY : window.scrollX;\n /** Function to handle onScroll event */\n const onScroll = () => {\n if (!ticking) {\n window.requestAnimationFrame(updateScrollDir);\n ticking = true;\n }\n };\n window.addEventListener(\"scroll\", onScroll);\n return () => window.removeEventListener(\"scroll\", onScroll);\n }, [updateScrollDir]);\n return scrollDir;\n}\nexport default useDetectScroll;\n//# sourceMappingURL=index.js.map"],"names":["Axis","Direction","useState","useCallback","useEffect"],"mappings":";;;;;;AACA;AACWA,sBAAK;AAChB,CAAC,UAAU,IAAI,EAAE;AACjB,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AACpB,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AACpB,CAAC,EAAEA,YAAI,KAAKA,YAAI,GAAG,EAAE,CAAC,CAAC,CAAC;AACxB;AACWC,2BAAU;AACrB,CAAC,UA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AM;AAC9C,QAAQ,MAAM,MAAM,GAAG,IAAI,KAAKH,YAAI,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;AACzE,QAAQ,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,UAAU,CAAC,IAAI,SAAS,EAAE;AACxD,YAAY,YAAY,CAAC,MAAM,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,CAAC,CAAC;AACtE,YAAY,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAC7C,SAAS;AACT,QAAQ,OAAO,GAAG,KAAK,CAAC;AACxB,KAAK,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;AAChD,IAAII,eAAS,CAAC,MAAM;AACpB,QAAQ,UAAU,GAAG,IAAI,KAAKJ,YAAI,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;AACvE;AACA,QAAQ,MAAM,QAAQ,GAAG,MAAM;AAC/B,YAAY,IAAI,CAAC,OAAO,EAAE;AAC1B,gBAAgB,MAAM,CAAC,qBAAqB,CAAC,eAAe,CAAC,CAAC;AAC9D,gBAAgB,OAAO,GAAG,IAAI,CAAC;AAC/B,aAAa;AACb,SAAS,CAAC;AACV,QAAQ,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACpD,QAAQ,OAAO,MAAM,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACpE,KAAK,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;AAC1B,IAAI,OAAO,SAAS,CAAC;AACrB;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { useState, useEffect, useCallback } from \"react\";\n\n/** Enumeration for axis values */\nexport enum Axis {\n X = \"x\",\n Y = \"y\",\n}\n\n/** Enumeration for direction values */\nexport enum Direction {\n Up = \"up\",\n Down = \"down\",\n Left = \"left\",\n Right = \"right\",\n Still = \"still\",\n}\n\n/** Type declaration for scroll properties */\ntype ScrollProps = {\n thr?: number;\n axis?: Axis;\n scrollUp?: Direction;\n scrollDown?: Direction;\n still?: Direction;\n};\n\n/**\n * useDetectScroll hook.\n *\n * This hook provides a mechanism to detect the scroll direction.\n * It will return the scroll direction as a string (up, down, left, right, or still) based on user scrolling.\n *\n * @example\n *\n * import useDetectScroll, { Axis, Direction } from '@smakss/react-scroll-direction';\n *\n * function App() {\n * const scrollDirection = useDetectScroll({\n * thr: 100,\n * axis: Axis.Y,\n * scrollUp: Direction.Up,\n * scrollDown: Direction.Down,\n * still: Direction.Still\n * });\n *\n * return (\n * <div>\n * <p>Current scroll direction: {scrollDirection}</p>\n * </div>\n * );\n * }\n *\n * @param {ScrollProps} props - The properties related to scrolling.\n * @property {number} props.thr - The threshold value which the scroll difference must exceed to update scroll direction.\n * @property {Axis} props.axis - The axis along which to detect scroll. Can be 'x' or 'y'.\n * @property {Direction} props.scrollUp - The direction to set when scrolling up or left. By default, 'up' for y-axis and 'left' for x-axis.\n * @property {Direction} props.scrollDown - The direction to set when scrolling down or right. By default, 'down' for y-axis and 'right' for x-axis.\n * @property {Direction} props.still - The direction to set when there is no scrolling. By default, 'still'.\n *\n * @returns {Direction} - The current direction of scrolling.\n */\nfunction useDetectScroll(props: ScrollProps = {}): Direction {\n const {\n thr = 0,\n axis = Axis.Y,\n scrollUp = axis === Axis.Y ? Direction.Up : Direction.Left,\n scrollDown = axis === Axis.Y ? Direction.Down : Direction.Right,\n still = Direction.Still,\n } = props;\n\n const [scrollDir, setScrollDir] = useState<Direction>(still);\n\n const threshold = Math.max(0, thr);\n let ticking = false;\n let lastScroll = 0;\n\n /** Function to update scroll direction */\n const updateScrollDir = useCallback(() => {\n const scroll = axis === Axis.Y ? window.scrollY : window.scrollX;\n\n if (Math.abs(scroll - lastScroll) >= threshold) {\n setScrollDir(scroll > lastScroll ? scrollDown : scrollUp);\n lastScroll = Math.max(0, scroll);\n }\n ticking = false;\n }, [axis, threshold, scrollDown, scrollUp]);\n\n useEffect(() => {\n lastScroll = axis === Axis.Y ? window.scrollY : window.scrollX;\n\n /** Function to handle onScroll event */\n const onScroll = () => {\n if (!ticking) {\n window.requestAnimationFrame(updateScrollDir);\n ticking = true;\n }\n };\n\n window.addEventListener(\"scroll\", onScroll);\n\n return () => window.removeEventListener(\"scroll\", onScroll);\n }, [updateScrollDir]);\n\n return scrollDir;\n}\n\nexport default useDetectScroll;\n"],"names":["Axis","Direction","useState","useCallback","useEffect"],"mappings":";;;;;;AAEA;AACYA,sBAGX;AAHD,CAAA,UAAY,IAAI,EAAA;AACd,IAAA,IAAA,CAAA,GAAA,CAAA,GAAA,GAAO,CAAA;AACP,IAAA,IAAA,CAAA,GAAA,CAAA,GAAA,GAAO,CAAA;AACT,CAAC,EAHWA,YAAI,KAAJA,YAAI,GAGf,EAAA,CAAA,CAAA,CAAA;AAED;AACYC,2BAMX;AAND,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,IAAA,CAAA,GAAA,IAAS,CAAA;AACT,IAAA,SAAA,CAAA,MAAA,CAAA,GAAA,MAAa,CAAA;AACb,IAAA,SAAA,CAAA,MAAA,CAAA,GAAA,MAAa,CAAA;AACb,IAAA,SAAA,CAAA,OAAA,CAAA,GAAA,OAAe,CAAA;AACf,IAAA,SAAA,CAAA,OAAA,CAAA,GAAA,OAAe,CAAA;AACjB,CAAC,EANWA,iBAAS,KAATA,iBAAS,GAMpB,EAAA,CAAA,CAAA,CAAA;AAWD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCG;AACH,SAAS,eAAe,CAAC,KAAA,GAAqB,EAAE,EAAA;IAC9C,MAAM,EACJ,GAAG,GAAG,CAAC,EACP,IAAI,GAAGD,YAAI,CAAC,CAAC,EACb,QAAQ,GAAG,IAAI,KAAKA,YAAI,CA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AC,CAAC;gBAC9C,OAAO,GAAG,IAAI,CAAC;AAChB,aAAA;AACH,SAAC,CAAC;AAEF,QAAA,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAE5C,OAAO,MAAM,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC9D,KAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;AAEtB,IAAA,OAAO,SAAS,CAAC;AACnB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { useState, useEffect, useCallback } from \"react\";\n/** Enumeration for axis values */\nexport var Axis;\n(function (Axis) {\n Axis[\"X\"] = \"x\";\n Axis[\"Y\"] = \"y\";\n})(Axis || (Axis = {}));\n/** Enumeration for direction values */\nexport var Direction;\n(function (Direction) {\n Direction[\"Up\"] = \"up\";\n Direction[\"Down\"] = \"down\";\n Direction[\"Left\"] = \"left\";\n Direction[\"Right\"] = \"right\";\n Direction[\"Still\"] = \"still\";\n})(Direction || (Direction = {}));\n/**\n * useDetectScroll hook.\n *\n * This hook provides a mechanism to detect the scroll direction.\n * It will return the scroll direction as a string (up, down, left, right, or still) based on user scrolling.\n *\n * @example\n *\n * import useDetectScroll, { Axis, Direction } from '@smakss/react-scroll-direction';\n *\n * function App() {\n * const scrollDirection = useDetectScroll({\n * thr: 100,\n * axis: Axis.Y,\n * scrollUp: Direction.Up,\n * scrollDown: Direction.Down,\n * still: Direction.Still\n * });\n *\n * return (\n * <div>\n * <p>Current scroll direction: {scrollDirection}</p>\n * </div>\n * );\n * }\n *\n * @param {ScrollProps} props - The properties related to scrolling.\n * @property {number} props.thr - The threshold value which the scroll difference must exceed to update scroll direction.\n * @property {Axis} props.axis - The axis along which to detect scroll. Can be 'x' or 'y'.\n * @property {Direction} props.scrollUp - The direction to set when scrolling up or left. By default, 'up' for y-axis and 'left' for x-axis.\n * @property {Direction} props.scrollDown - The direction to set when scrolling down or right. By default, 'down' for y-axis and 'right' for x-axis.\n * @property {Direction} props.still - The direction to set when there is no scrolling. By default, 'still'.\n *\n * @returns {Direction} - The current direction of scrolling.\n */\nfunction useDetectScroll(props = {}) {\n const { thr = 0, axis = Axis.Y, scrollUp = axis === Axis.Y ? Direction.Up : Direction.Left, scrollDown = axis === Axis.Y ? Direction.Down : Direction.Right, still = Direction.Still, } = props;\n const [scrollDir, setScrollDir] = useState(still);\n const threshold = Math.max(0, thr);\n let ticking = false;\n let lastScroll = 0;\n /** Function to update scroll direction */\n const updateScrollDir = useCallback(() => {\n const scroll = axis === Axis.Y ? window.scrollY : window.scrollX;\n if (Math.abs(scroll - lastScroll) >= threshold) {\n setScrollDir(scroll > lastScroll ? scrollDown : scrollUp);\n lastScroll = Math.max(0, scroll);\n }\n ticking = false;\n }, [axis, threshold, scrollDown, scrollUp]);\n useEffect(() => {\n lastScroll = axis === Axis.Y ? window.scrollY : window.scrollX;\n /** Function to handle onScroll event */\n const onScroll = () => {\n if (!ticking) {\n window.requestAnimationFrame(updateScrollDir);\n ticking = true;\n }\n };\n window.addEventListener(\"scroll\", onScroll);\n return () => window.removeEventListener(\"scroll\", onScroll);\n }, [updateScrollDir]);\n return scrollDir;\n}\nexport default useDetectScroll;\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;AACA;AACU,IAAC,KAAK;AAChB,CAAC,UAAU,IAAI,EAAE;AACjB,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AACpB,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AACpB,CAAC,EAAE,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC;AACxB;AACU,IAAC,UAAU;AACrB,CAAC,UAAU,SAAS,EAAE;AACtB,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAC3B,IAAI,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AAC/B,IAAI,SAAS,C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GAAG,UAAU,CAAC,IAAI,SAAS,EAAE;AACxD,YAAY,YAAY,CAAC,MAAM,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,CAAC,CAAC;AACtE,YAAY,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAC7C,SAAS;AACT,QAAQ,OAAO,GAAG,KAAK,CAAC;AACxB,KAAK,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;AAChD,IAAI,SAAS,CAAC,MAAM;AACpB,QAAQ,UAAU,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;AACvE;AACA,QAAQ,MAAM,QAAQ,GAAG,MAAM;AAC/B,YAAY,IAAI,CAAC,OAAO,EAAE;AAC1B,gBAAgB,MAAM,CAAC,qBAAqB,CAAC,eAAe,CAAC,CAAC;AAC9D,gBAAgB,OAAO,GAAG,IAAI,CAAC;AAC/B,aAAa;AACb,SAAS,CAAC;AACV,QAAQ,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACpD,QAAQ,OAAO,MAAM,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACpE,KAAK,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;AAC1B,IAAI,OAAO,SAAS,CAAC;AACrB;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { useState, useEffect, useCallback } from \"react\";\n\n/** Enumeration for axis values */\nexport enum Axis {\n X = \"x\",\n Y = \"y\",\n}\n\n/** Enumeration for direction values */\nexport enum Direction {\n Up = \"up\",\n Down = \"down\",\n Left = \"left\",\n Right = \"right\",\n Still = \"still\",\n}\n\n/** Type declaration for scroll properties */\ntype ScrollProps = {\n thr?: number;\n axis?: Axis;\n scrollUp?: Direction;\n scrollDown?: Direction;\n still?: Direction;\n};\n\n/**\n * useDetectScroll hook.\n *\n * This hook provides a mechanism to detect the scroll direction.\n * It will return the scroll direction as a string (up, down, left, right, or still) based on user scrolling.\n *\n * @example\n *\n * import useDetectScroll, { Axis, Direction } from '@smakss/react-scroll-direction';\n *\n * function App() {\n * const scrollDirection = useDetectScroll({\n * thr: 100,\n * axis: Axis.Y,\n * scrollUp: Direction.Up,\n * scrollDown: Direction.Down,\n * still: Direction.Still\n * });\n *\n * return (\n * <div>\n * <p>Current scroll direction: {scrollDirection}</p>\n * </div>\n * );\n * }\n *\n * @param {ScrollProps} props - The properties related to scrolling.\n * @property {number} props.thr - The threshold value which the scroll difference must exceed to update scroll direction.\n * @property {Axis} props.axis - The axis along which to detect scroll. Can be 'x' or 'y'.\n * @property {Direction} props.scrollUp - The direction to set when scrolling up or left. By default, 'up' for y-axis and 'left' for x-axis.\n * @property {Direction} props.scrollDown - The direction to set when scrolling down or right. By default, 'down' for y-axis and 'right' for x-axis.\n * @property {Direction} props.still - The direction to set when there is no scrolling. By default, 'still'.\n *\n * @returns {Direction} - The current direction of scrolling.\n */\nfunction useDetectScroll(props: ScrollProps = {}): Direction {\n const {\n thr = 0,\n axis = Axis.Y,\n scrollUp = axis === Axis.Y ? Direction.Up : Direction.Left,\n scrollDown = axis === Axis.Y ? Direction.Down : Direction.Right,\n still = Direction.Still,\n } = props;\n\n const [scrollDir, setScrollDir] = useState<Direction>(still);\n\n const threshold = Math.max(0, thr);\n let ticking = false;\n let lastScroll = 0;\n\n /** Function to update scroll direction */\n const updateScrollDir = useCallback(() => {\n const scroll = axis === Axis.Y ? window.scrollY : window.scrollX;\n\n if (Math.abs(scroll - lastScroll) >= threshold) {\n setScrollDir(scroll > lastScroll ? scrollDown : scrollUp);\n lastScroll = Math.max(0, scroll);\n }\n ticking = false;\n }, [axis, threshold, scrollDown, scrollUp]);\n\n useEffect(() => {\n lastScroll = axis === Axis.Y ? window.scrollY : window.scrollX;\n\n /** Function to handle onScroll event */\n const onScroll = () => {\n if (!ticking) {\n window.requestAnimationFrame(updateScrollDir);\n ticking = true;\n }\n };\n\n window.addEventListener(\"scroll\", onScroll);\n\n return () => window.removeEventListener(\"scroll\", onScroll);\n }, [updateScrollDir]);\n\n return scrollDir;\n}\n\nexport default useDetectScroll;\n"],"names":[],"mappings":";;AAEA;IACY,KAGX;AAHD,CAAA,UAAY,IAAI,EAAA;AACd,IAAA,IAAA,CAAA,GAAA,CAAA,GAAA,GAAO,CAAA;AACP,IAAA,IAAA,CAAA,GAAA,CAAA,GAAA,GAAO,CAAA;AACT,CAAC,EAHW,IAAI,KAAJ,IAAI,GAGf,EAAA,CAAA,CAAA,CAAA;AAED;IACY,UAMX;AAND,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,IAAA,CAAA,GAAA,IAAS,CAAA;AACT,IAAA,SAAA,CAAA,MAAA,CAAA,GAAA,MAAa,CAAA;AACb,IAAA,SAAA,CAAA,MAAA,CAAA,GAAA,MAAa,CAAA;AACb,IAAA,SAAA,CAAA,OAAA,CAAA,GAAA,OAAe,CAAA;AACf,IAAA,SAAA,CAAA,OAAA,CAAA,GAAA,OAAe,CAAA;AACjB,CAAC,EANW,SAAS,KAAT,SAAS,GAMpB,EAAA,CAAA,CAAA,CAAA;AAWD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCG;AACH,SAAS,eAAe,CAAC,KAAA,GAAqB,EAAE,EAAA;IAC9C,MAAM,EACJ,GAAG,GAAG,CAAC,EACP,IAAI,GAAG,IAAI,CAAC,CAAC,EACb,QAAQ,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC,IAAI,EAC1D,UAAU,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC,IAAI,GAAG,SAAS,CAAC,KAAK,EAC/D,KAAK,GAAG,SAAS,CAAC,KAAK,GACxB,GAAG,KAAK,CAAC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E,CAAC,eAAe,CAAC,CAAC,CAAC;AAEtB,IAAA,OAAO,SAAS,CAAC;AACnB;;;;"}
package/package.json CHANGED
@@ -5,8 +5,8 @@
5
5
  },
6
6
  "description": "Detect scroll direction in react applications.",
7
7
  "devDependencies": {
8
- "@commitlint/cli": "^17.7.1",
9
- "@commitlint/config-conventional": "^17.7.0",
8
+ "@commitlint/cli": "^18.2.0",
9
+ "@commitlint/config-conventional": "^18.1.0",
10
10
  "@rollup/plugin-commonjs": "^25.0.0",
11
11
  "@rollup/plugin-node-resolve": "^15.0.1",
12
12
  "@rollup/plugin-typescript": "^11.1.1",
@@ -14,12 +14,12 @@
14
14
  "@typescript-eslint/eslint-plugin": "^5.59.6",
15
15
  "@typescript-eslint/parser": "^5.59.6",
16
16
  "eslint": "^8.41.0",
17
- "eslint-config-prettier": "8.8.0",
17
+ "eslint-config-prettier": "9.0.0",
18
18
  "eslint-plugin-prettier": "^4.2.1",
19
19
  "husky": "^8.0.3",
20
- "lint-staged": "^14.0.1",
20
+ "lint-staged": "^15.0.2",
21
21
  "prettier": "^2.8.8",
22
- "rollup": "^3.2.3",
22
+ "rollup": "^4.2.0",
23
23
  "typescript": "^5.0.4"
24
24
  },
25
25
  "exports": {
@@ -64,9 +64,9 @@
64
64
  "generate": "rollup -c",
65
65
  "lint": "eslint --cache --cache-location ./node_modules/.cache/.eslintcache --ext js,jsx,ts,tsx --max-warnings=0 .",
66
66
  "lint:fix": "eslint src/**/*.ts --fix",
67
- "postinstall": "husky install",
67
+ "setup": "yarn && husky install",
68
68
  "typecheck": "tsc -b ."
69
69
  },
70
70
  "type": "module",
71
- "version": "3.0.1"
71
+ "version": "3.1.0-beta.0"
72
72
  }