@lynx-js/lynx-ui-swiper 0.0.0 → 3.130.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.
Files changed (137) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +201 -0
  3. package/README.md +51 -0
  4. package/dist/Swiper/index.d.ts +11 -0
  5. package/dist/Swiper/index.d.ts.map +1 -0
  6. package/dist/Swiper/index.jsx +261 -0
  7. package/dist/Swiper/index.jsx.map +1 -0
  8. package/dist/Swiper/styles.css +47 -0
  9. package/dist/Swiper/styles.css.map +1 -0
  10. package/dist/SwiperItem/index.d.ts +46 -0
  11. package/dist/SwiperItem/index.d.ts.map +1 -0
  12. package/dist/SwiperItem/index.jsx +86 -0
  13. package/dist/SwiperItem/index.jsx.map +1 -0
  14. package/dist/const/index.d.ts +5 -0
  15. package/dist/const/index.d.ts.map +1 -0
  16. package/dist/const/index.jsx +7 -0
  17. package/dist/const/index.jsx.map +1 -0
  18. package/dist/hooks/useAnimate.d.ts +5 -0
  19. package/dist/hooks/useAnimate.d.ts.map +1 -0
  20. package/dist/hooks/useAnimate.jsx +47 -0
  21. package/dist/hooks/useAnimate.jsx.map +1 -0
  22. package/dist/hooks/useAutoPlay.d.ts +16 -0
  23. package/dist/hooks/useAutoPlay.d.ts.map +1 -0
  24. package/dist/hooks/useAutoPlay.jsx +58 -0
  25. package/dist/hooks/useAutoPlay.jsx.map +1 -0
  26. package/dist/hooks/useAxisLock.d.ts +12 -0
  27. package/dist/hooks/useAxisLock.d.ts.map +1 -0
  28. package/dist/hooks/useAxisLock.jsx +58 -0
  29. package/dist/hooks/useAxisLock.jsx.map +1 -0
  30. package/dist/hooks/useBounceConfig.d.ts +12 -0
  31. package/dist/hooks/useBounceConfig.d.ts.map +1 -0
  32. package/dist/hooks/useBounceConfig.jsx +15 -0
  33. package/dist/hooks/useBounceConfig.jsx.map +1 -0
  34. package/dist/hooks/useBounceView.d.ts +17 -0
  35. package/dist/hooks/useBounceView.d.ts.map +1 -0
  36. package/dist/hooks/useBounceView.jsx +16 -0
  37. package/dist/hooks/useBounceView.jsx.map +1 -0
  38. package/dist/hooks/useChange.d.ts +22 -0
  39. package/dist/hooks/useChange.d.ts.map +1 -0
  40. package/dist/hooks/useChange.jsx +53 -0
  41. package/dist/hooks/useChange.jsx.map +1 -0
  42. package/dist/hooks/useDirection.d.ts +13 -0
  43. package/dist/hooks/useDirection.d.ts.map +1 -0
  44. package/dist/hooks/useDirection.jsx +37 -0
  45. package/dist/hooks/useDirection.jsx.map +1 -0
  46. package/dist/hooks/useFirstScreenStyle.d.ts +34 -0
  47. package/dist/hooks/useFirstScreenStyle.d.ts.map +1 -0
  48. package/dist/hooks/useFirstScreenStyle.jsx +63 -0
  49. package/dist/hooks/useFirstScreenStyle.jsx.map +1 -0
  50. package/dist/hooks/useModeConfig.d.ts +14 -0
  51. package/dist/hooks/useModeConfig.d.ts.map +1 -0
  52. package/dist/hooks/useModeConfig.jsx +33 -0
  53. package/dist/hooks/useModeConfig.jsx.map +1 -0
  54. package/dist/hooks/useOffset.d.ts +37 -0
  55. package/dist/hooks/useOffset.d.ts.map +1 -0
  56. package/dist/hooks/useOffset.jsx +362 -0
  57. package/dist/hooks/useOffset.jsx.map +1 -0
  58. package/dist/hooks/useOffsetLimit.d.ts +16 -0
  59. package/dist/hooks/useOffsetLimit.d.ts.map +1 -0
  60. package/dist/hooks/useOffsetLimit.jsx +51 -0
  61. package/dist/hooks/useOffsetLimit.jsx.map +1 -0
  62. package/dist/hooks/useReset.d.ts +16 -0
  63. package/dist/hooks/useReset.d.ts.map +1 -0
  64. package/dist/hooks/useReset.jsx +68 -0
  65. package/dist/hooks/useReset.jsx.map +1 -0
  66. package/dist/hooks/useSwipeCallback.d.ts +14 -0
  67. package/dist/hooks/useSwipeCallback.d.ts.map +1 -0
  68. package/dist/hooks/useSwipeCallback.jsx +40 -0
  69. package/dist/hooks/useSwipeCallback.jsx.map +1 -0
  70. package/dist/hooks/useVelocity.d.ts +14 -0
  71. package/dist/hooks/useVelocity.d.ts.map +1 -0
  72. package/dist/hooks/useVelocity.jsx +62 -0
  73. package/dist/hooks/useVelocity.jsx.map +1 -0
  74. package/dist/hooks/useVelocity_experiment.d.ts +12 -0
  75. package/dist/hooks/useVelocity_experiment.d.ts.map +1 -0
  76. package/dist/hooks/useVelocity_experiment.jsx +38 -0
  77. package/dist/hooks/useVelocity_experiment.jsx.map +1 -0
  78. package/dist/index.d.ts +5 -0
  79. package/dist/index.d.ts.map +1 -0
  80. package/dist/index.jsx +3 -0
  81. package/dist/store/index.d.ts +3 -0
  82. package/dist/store/index.d.ts.map +1 -0
  83. package/dist/store/index.jsx +18 -0
  84. package/dist/store/index.jsx.map +1 -0
  85. package/dist/types/index.d.ts +62 -0
  86. package/dist/types/index.d.ts.map +1 -0
  87. package/dist/types/index.docs.d.ts +448 -0
  88. package/dist/types/index.docs.d.ts.map +1 -0
  89. package/dist/types/index.jsx +9 -0
  90. package/dist/types/index.jsx.map +1 -0
  91. package/dist/utils/animate.d.ts +4 -0
  92. package/dist/utils/animate.d.ts.map +1 -0
  93. package/dist/utils/animate.jsx +29 -0
  94. package/dist/utils/animate.jsx.map +1 -0
  95. package/dist/utils/compareProps.d.ts +2 -0
  96. package/dist/utils/compareProps.d.ts.map +1 -0
  97. package/dist/utils/compareProps.jsx +14 -0
  98. package/dist/utils/compareProps.jsx.map +1 -0
  99. package/dist/utils/customRound.d.ts +10 -0
  100. package/dist/utils/customRound.d.ts.map +1 -0
  101. package/dist/utils/customRound.jsx +9 -0
  102. package/dist/utils/customRound.jsx.map +1 -0
  103. package/dist/utils/index.d.ts +20 -0
  104. package/dist/utils/index.d.ts.map +1 -0
  105. package/dist/utils/index.jsx +55 -0
  106. package/dist/utils/index.jsx.map +1 -0
  107. package/package.json +47 -4
  108. package/src/Swiper/index.tsx +414 -0
  109. package/src/Swiper/styles.css +44 -0
  110. package/src/SwiperItem/index.tsx +205 -0
  111. package/src/const/index.ts +11 -0
  112. package/src/hooks/useAnimate.ts +80 -0
  113. package/src/hooks/useAutoPlay.ts +95 -0
  114. package/src/hooks/useAxisLock.ts +92 -0
  115. package/src/hooks/useBounceConfig.ts +29 -0
  116. package/src/hooks/useBounceView.tsx +50 -0
  117. package/src/hooks/useChange.ts +131 -0
  118. package/src/hooks/useDirection.ts +59 -0
  119. package/src/hooks/useFirstScreenStyle.ts +200 -0
  120. package/src/hooks/useModeConfig.ts +56 -0
  121. package/src/hooks/useOffset.ts +609 -0
  122. package/src/hooks/useOffsetLimit.ts +98 -0
  123. package/src/hooks/useReset.ts +144 -0
  124. package/src/hooks/useSwipeCallback.ts +66 -0
  125. package/src/hooks/useVelocity.ts +83 -0
  126. package/src/hooks/useVelocity_experiment.ts +50 -0
  127. package/src/index.ts +8 -0
  128. package/src/store/index.ts +23 -0
  129. package/src/types/index.docs.ts +465 -0
  130. package/src/types/index.ts +105 -0
  131. package/src/utils/animate.ts +49 -0
  132. package/src/utils/compareProps.ts +54 -0
  133. package/src/utils/customRound.ts +23 -0
  134. package/src/utils/index.ts +117 -0
  135. package/tsconfig.docs.json +7 -0
  136. package/tsconfig.json +9 -0
  137. /package/{index.js → dist/types/index.docs.jsx} +0 -0
@@ -0,0 +1,37 @@
1
+ import { useMainThreadRef } from "@lynx-js/react";
2
+ import { SwipeDirection } from "../types/index.jsx";
3
+ function useDirection({ RTL }) {
4
+ const startXRef = useMainThreadRef(0);
5
+ const directionRef = useMainThreadRef(SwipeDirection.NONE);
6
+ function handleTouchStart(event) {
7
+ 'main thread';
8
+ startXRef.current = event.detail.x;
9
+ directionRef.current = SwipeDirection.NONE;
10
+ }
11
+ function handleTouchMove(event) {
12
+ 'main thread';
13
+ if (event.detail.x < startXRef.current) directionRef.current = RTL ? SwipeDirection.REVERT : SwipeDirection.NORMAL;
14
+ else if (event.detail.x > startXRef.current) directionRef.current = RTL ? SwipeDirection.NORMAL : SwipeDirection.REVERT;
15
+ else directionRef.current = SwipeDirection.NONE;
16
+ }
17
+ function handleTouchEnd(event) {
18
+ 'main thread';
19
+ if (event.detail.x < startXRef.current) directionRef.current = RTL ? SwipeDirection.REVERT : SwipeDirection.NORMAL;
20
+ else if (event.detail.x > startXRef.current) directionRef.current = RTL ? SwipeDirection.NORMAL : SwipeDirection.REVERT;
21
+ else directionRef.current = SwipeDirection.NONE;
22
+ }
23
+ function overrideDirection(direction) {
24
+ 'main thread';
25
+ directionRef.current = direction;
26
+ }
27
+ return {
28
+ handleTouchStart,
29
+ handleTouchEnd,
30
+ handleTouchMove,
31
+ overrideDirection,
32
+ directionRef
33
+ };
34
+ }
35
+ export { useDirection };
36
+
37
+ //# sourceMappingURL=useDirection.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks/useDirection.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/hooks/useDirection.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useMainThreadRef } from '@lynx-js/react'\n\nimport type { MainThread } from '@lynx-js/types'\n\nimport { SwipeDirection } from '../types'\nimport type { SwiperProps } from '../types'\n\nexport function useDirection({ RTL }: { RTL: SwiperProps<unknown>['RTL'] }) {\n const startXRef = useMainThreadRef<number>(0)\n const directionRef = useMainThreadRef<SwipeDirection>(SwipeDirection.NONE)\n\n function handleTouchStart(event: MainThread.TouchEvent) {\n 'main thread'\n\n startXRef.current = event.detail.x\n directionRef.current = SwipeDirection.NONE\n }\n\n function handleTouchMove(event: MainThread.TouchEvent) {\n 'main thread'\n\n if (event.detail.x < startXRef.current) {\n directionRef.current = RTL ? SwipeDirection.REVERT : SwipeDirection.NORMAL\n } else if (event.detail.x > startXRef.current) {\n directionRef.current = RTL ? SwipeDirection.NORMAL : SwipeDirection.REVERT\n } else {\n directionRef.current = SwipeDirection.NONE\n }\n }\n\n function handleTouchEnd(event: MainThread.TouchEvent) {\n 'main thread'\n\n if (event.detail.x < startXRef.current) {\n directionRef.current = RTL ? SwipeDirection.REVERT : SwipeDirection.NORMAL\n } else if (event.detail.x > startXRef.current) {\n directionRef.current = RTL ? SwipeDirection.NORMAL : SwipeDirection.REVERT\n } else {\n directionRef.current = SwipeDirection.NONE\n }\n }\n\n function overrideDirection(direction: SwipeDirection) {\n 'main thread'\n directionRef.current = direction\n }\n\n return {\n handleTouchStart,\n handleTouchEnd,\n handleTouchMove,\n overrideDirection,\n directionRef,\n }\n}\n"],"names":["useDirection","RTL","startXRef","useMainThreadRef","directionRef","SwipeDirection","handleTouchStart","event","handleTouchMove","handleTouchEnd","overrideDirection","direction"],"mappings":";;AAWO,SAASA,aAAa,EAAEC,GAAG,EAAwC;IACxE,MAAMC,YAAYC,iBAAyB;IAC3C,MAAMC,eAAeD,iBAAiCE,eAAe,IAAI;IAEzE,SAASC,iBAAiBC,KAA4B;QACpD;QAEAL,UAAU,OAAO,GAAGK,MAAM,MAAM,CAAC,CAAC;QAClCH,aAAa,OAAO,GAAGC,eAAe,IAAI;IAC5C;IAEA,SAASG,gBAAgBD,KAA4B;QACnD;QAEA,IAAIA,MAAM,MAAM,CAAC,CAAC,GAAGL,UAAU,OAAO,EACpCE,aAAa,OAAO,GAAGH,MAAMI,eAAe,MAAM,GAAGA,eAAe,MAAM;aACrE,IAAIE,MAAM,MAAM,CAAC,CAAC,GAAGL,UAAU,OAAO,EAC3CE,aAAa,OAAO,GAAGH,MAAMI,eAAe,MAAM,GAAGA,eAAe,MAAM;aAE1ED,aAAa,OAAO,GAAGC,eAAe,IAAI;IAE9C;IAEA,SAASI,eAAeF,KAA4B;QAClD;QAEA,IAAIA,MAAM,MAAM,CAAC,CAAC,GAAGL,UAAU,OAAO,EACpCE,aAAa,OAAO,GAAGH,MAAMI,eAAe,MAAM,GAAGA,eAAe,MAAM;aACrE,IAAIE,MAAM,MAAM,CAAC,CAAC,GAAGL,UAAU,OAAO,EAC3CE,aAAa,OAAO,GAAGH,MAAMI,eAAe,MAAM,GAAGA,eAAe,MAAM;aAE1ED,aAAa,OAAO,GAAGC,eAAe,IAAI;IAE9C;IAEA,SAASK,kBAAkBC,SAAyB;QAClD;QACAP,aAAa,OAAO,GAAGO;IACzB;IAEA,OAAO;QACLL;QACAG;QACAD;QACAE;QACAN;IACF;AACF"}
@@ -0,0 +1,34 @@
1
+ import type { CSSProperties } from '@lynx-js/types';
2
+ import type { CompoundModeConfig, OffsetLimitResult, SwiperProps } from '../types';
3
+ interface LayoutSwiperPropsType extends Pick<SwiperProps<unknown>, 'itemWidth' | 'initialIndex' | 'itemHeight' | 'trackStyle'>, Required<Pick<SwiperProps<unknown>, 'containerWidth' | 'loop' | 'loopDuplicateCount' | 'RTL' | 'swiperKey'>> {
4
+ spaceBetween: number;
5
+ dataCount: number;
6
+ modeConfig: CompoundModeConfig;
7
+ offsetLimit: OffsetLimitResult;
8
+ }
9
+ export declare function getInnerContainerWidth(props: {
10
+ itemWidth: number;
11
+ loopDuplicateCount?: number;
12
+ loop: boolean;
13
+ dataCount: number;
14
+ spaceBetween: number;
15
+ }): string;
16
+ export declare function getInnerContainerWidthMT(props: {
17
+ itemWidth: number;
18
+ loopDuplicateCount?: number;
19
+ loop: boolean;
20
+ dataCount: number;
21
+ spaceBetween: number;
22
+ }): string;
23
+ /**
24
+ * MTS does not support first screen mutation.
25
+ * We use `useMemo` hack to make firstScreen style correct.
26
+ * When MTS is not ready, we use `useMemo` to get the style, and set it to view. Since there's no
27
+ * dependency in `useMemo`, the view will only be set on firstScreen.
28
+ * After that, all the updated are handled by MTS via `setStyleProperties`
29
+ */
30
+ declare function useFirstScreenStyle(props: LayoutSwiperPropsType): {
31
+ containerStyle: CSSProperties | undefined;
32
+ };
33
+ export default useFirstScreenStyle;
34
+ //# sourceMappingURL=useFirstScreenStyle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFirstScreenStyle.d.ts","sourceRoot":"","sources":["../../src/hooks/useFirstScreenStyle.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACZ,MAAM,UAAU,CAAA;AAGjB,UAAU,qBAAsB,SAC9B,IAAI,CACF,WAAW,CAAC,OAAO,CAAC,EACpB,WAAW,GAAG,cAAc,GAAG,YAAY,GAAG,YAAY,CAC3D,EACD,QAAQ,CACN,IAAI,CACF,WAAW,CAAC,OAAO,CAAC,EAClB,gBAAgB,GAChB,MAAM,GACN,oBAAoB,GACpB,KAAK,GACL,WAAW,CACd,CACF;IAED,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,kBAAkB,CAAA;IAC9B,WAAW,EAAE,iBAAiB,CAAA;CAC/B;AAsDD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC5C,SAAS,EAAE,MAAM,CAAA;IACjB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,IAAI,EAAE,OAAO,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;CACrB,UAYA;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAC9C,SAAS,EAAE,MAAM,CAAA;IACjB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,IAAI,EAAE,OAAO,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;CACrB,UAcA;AAED;;;;;;GAMG;AACH,iBAAS,mBAAmB,CAAC,KAAK,EAAE,qBAAqB,GAAG;IAC1D,cAAc,EAAE,aAAa,GAAG,SAAS,CAAA;CAC1C,CAyDA;AAED,eAAe,mBAAmB,CAAA"}
@@ -0,0 +1,63 @@
1
+ import { useMemo } from "@lynx-js/react";
2
+ import { limiterForFirstScreen } from "../utils/index.jsx";
3
+ function getOffset(props) {
4
+ const { modeConfig, itemWidth, initialIndex = 0, loop, dataCount, containerWidth, offsetLimit, RTL, spaceBetween } = props;
5
+ let alignOffset = 0;
6
+ if ('normal' === modeConfig.mode) alignOffset = 'center' === modeConfig.align ? (containerWidth - itemWidth) / 2 : 'end' === modeConfig.align ? containerWidth - itemWidth : 0;
7
+ const finalOffset = limiterForFirstScreen(-(itemWidth + spaceBetween) * initialIndex + alignOffset, dataCount, itemWidth, spaceBetween, loop, offsetLimit, alignOffset);
8
+ return RTL ? -finalOffset : finalOffset;
9
+ }
10
+ function getInnerContainerWidth(props) {
11
+ const { itemWidth, loopDuplicateCount = 0, loop, dataCount, spaceBetween } = props;
12
+ const width = loop ? `${(dataCount + 2 * loopDuplicateCount) * (itemWidth + spaceBetween)}px` : `${dataCount * (itemWidth + spaceBetween) - spaceBetween}px`;
13
+ return width;
14
+ }
15
+ function getInnerContainerWidthMT(props) {
16
+ 'main thread';
17
+ const { itemWidth, loopDuplicateCount = 0, loop, dataCount, spaceBetween } = props;
18
+ const width = loop ? `${(dataCount + 2 * loopDuplicateCount) * (itemWidth + spaceBetween)}px` : `${dataCount * (itemWidth + spaceBetween) - spaceBetween}px`;
19
+ return width;
20
+ }
21
+ function useFirstScreenStyle(props) {
22
+ const { itemWidth, spaceBetween, containerWidth, loop, initialIndex, dataCount, itemHeight, modeConfig, offsetLimit, loopDuplicateCount, RTL, swiperKey, trackStyle } = props;
23
+ const escapeProps = {
24
+ itemWidth,
25
+ containerWidth,
26
+ itemHeight,
27
+ loop,
28
+ initialIndex,
29
+ dataCount,
30
+ modeConfig,
31
+ offsetLimit,
32
+ RTL,
33
+ spaceBetween
34
+ };
35
+ const containerStyle = useMemo(()=>{
36
+ const insetInlineStartKey = RTL ? 'inset-inline-start' : 'left';
37
+ if ('normal' === modeConfig.mode) return {
38
+ ...trackStyle,
39
+ width: getInnerContainerWidth({
40
+ itemWidth,
41
+ loopDuplicateCount,
42
+ loop,
43
+ dataCount,
44
+ spaceBetween
45
+ }),
46
+ [insetInlineStartKey]: loop ? `${-loopDuplicateCount * (itemWidth + spaceBetween)}px` : '0px',
47
+ transform: `translateX(${getOffset(escapeProps)}px)`,
48
+ height: `${itemHeight}px`
49
+ };
50
+ if ('custom' === modeConfig.mode) return {
51
+ height: `${itemHeight}px`
52
+ };
53
+ }, [
54
+ swiperKey
55
+ ]);
56
+ return {
57
+ containerStyle
58
+ };
59
+ }
60
+ const hooks_useFirstScreenStyle = useFirstScreenStyle;
61
+ export { hooks_useFirstScreenStyle as default, getInnerContainerWidth, getInnerContainerWidthMT };
62
+
63
+ //# sourceMappingURL=useFirstScreenStyle.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks/useFirstScreenStyle.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/hooks/useFirstScreenStyle.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useMemo } from '@lynx-js/react'\n\nimport type { CSSProperties } from '@lynx-js/types'\n\nimport type {\n CompoundModeConfig,\n OffsetLimitResult,\n SwiperProps,\n} from '../types'\nimport { limiterForFirstScreen } from '../utils'\n\ninterface LayoutSwiperPropsType extends\n Pick<\n SwiperProps<unknown>,\n 'itemWidth' | 'initialIndex' | 'itemHeight' | 'trackStyle'\n >,\n Required<\n Pick<\n SwiperProps<unknown>,\n | 'containerWidth'\n | 'loop'\n | 'loopDuplicateCount'\n | 'RTL'\n | 'swiperKey'\n >\n >\n{\n spaceBetween: number\n dataCount: number\n modeConfig: CompoundModeConfig\n offsetLimit: OffsetLimitResult\n}\n\ninterface EscapeProps\n extends\n Pick<SwiperProps<unknown>, 'itemWidth' | 'initialIndex'>,\n Required<\n Pick<\n SwiperProps<unknown>,\n 'containerWidth' | 'loop' | 'RTL'\n >\n >\n{\n spaceBetween: number\n dataCount: number\n modeConfig: CompoundModeConfig\n offsetLimit: OffsetLimitResult\n}\n\nfunction getOffset(props: EscapeProps) {\n const {\n modeConfig,\n itemWidth,\n initialIndex = 0,\n loop,\n dataCount,\n containerWidth,\n offsetLimit,\n RTL,\n spaceBetween,\n } = props\n let alignOffset = 0\n if (modeConfig.mode === 'normal') {\n if (modeConfig.align === 'center') {\n alignOffset = (containerWidth - itemWidth) / 2\n } else if (modeConfig.align === 'end') {\n alignOffset = containerWidth - itemWidth\n } else {\n alignOffset = 0\n }\n }\n\n const finalOffset = limiterForFirstScreen(\n -(itemWidth + spaceBetween) * initialIndex + alignOffset,\n dataCount,\n itemWidth,\n spaceBetween,\n loop,\n offsetLimit,\n alignOffset,\n )\n\n return RTL ? -finalOffset : finalOffset\n}\n\nexport function getInnerContainerWidth(props: {\n itemWidth: number\n loopDuplicateCount?: number\n loop: boolean\n dataCount: number\n spaceBetween: number\n}) {\n const {\n itemWidth,\n loopDuplicateCount = 0,\n loop,\n dataCount,\n spaceBetween,\n } = props\n const width = loop\n ? `${(dataCount + loopDuplicateCount * 2) * (itemWidth + spaceBetween)}px`\n : `${dataCount * (itemWidth + spaceBetween) - spaceBetween}px`\n return width\n}\n\nexport function getInnerContainerWidthMT(props: {\n itemWidth: number\n loopDuplicateCount?: number\n loop: boolean\n dataCount: number\n spaceBetween: number\n}) {\n 'main thread'\n const {\n itemWidth,\n loopDuplicateCount = 0,\n loop,\n dataCount,\n spaceBetween,\n } = props\n const width = loop\n ? `${(dataCount + loopDuplicateCount * 2) * (itemWidth + spaceBetween)}px`\n : `${dataCount * (itemWidth + spaceBetween) - spaceBetween}px`\n\n return width\n}\n\n/**\n * MTS does not support first screen mutation.\n * We use `useMemo` hack to make firstScreen style correct.\n * When MTS is not ready, we use `useMemo` to get the style, and set it to view. Since there's no\n * dependency in `useMemo`, the view will only be set on firstScreen.\n * After that, all the updated are handled by MTS via `setStyleProperties`\n */\nfunction useFirstScreenStyle(props: LayoutSwiperPropsType): {\n containerStyle: CSSProperties | undefined\n} {\n const {\n itemWidth,\n spaceBetween,\n containerWidth,\n loop,\n initialIndex,\n dataCount,\n itemHeight,\n modeConfig,\n offsetLimit,\n loopDuplicateCount,\n RTL,\n swiperKey,\n trackStyle,\n } = props\n const escapeProps = {\n itemWidth,\n containerWidth,\n itemHeight,\n loop,\n initialIndex,\n dataCount,\n modeConfig,\n offsetLimit,\n RTL,\n spaceBetween,\n }\n\n const containerStyle = useMemo(() => {\n const insetInlineStartKey = RTL ? 'inset-inline-start' : 'left'\n if (modeConfig.mode === 'normal') {\n return {\n ...trackStyle,\n width: getInnerContainerWidth({\n itemWidth,\n loopDuplicateCount,\n loop,\n dataCount,\n spaceBetween,\n }),\n [insetInlineStartKey]: loop\n ? `${-loopDuplicateCount * (itemWidth + spaceBetween)}px`\n : '0px',\n transform: `translateX(${getOffset(escapeProps)}px)`,\n height: `${itemHeight}px`,\n }\n } else if (modeConfig.mode === 'custom') {\n return {\n height: `${itemHeight}px`,\n }\n }\n }, [swiperKey])\n\n return {\n containerStyle,\n }\n}\n\nexport default useFirstScreenStyle\n"],"names":["getOffset","props","modeConfig","itemWidth","initialIndex","loop","dataCount","containerWidth","offsetLimit","RTL","spaceBetween","alignOffset","finalOffset","limiterForFirstScreen","getInnerContainerWidth","loopDuplicateCount","width","getInnerContainerWidthMT","useFirstScreenStyle","itemHeight","swiperKey","trackStyle","escapeProps","containerStyle","useMemo","insetInlineStartKey"],"mappings":";;AAqDA,SAASA,UAAUC,KAAkB;IACnC,MAAM,EACJC,UAAU,EACVC,SAAS,EACTC,eAAe,CAAC,EAChBC,IAAI,EACJC,SAAS,EACTC,cAAc,EACdC,WAAW,EACXC,GAAG,EACHC,YAAY,EACb,GAAGT;IACJ,IAAIU,cAAc;IAClB,IAAIT,AAAoB,aAApBA,WAAW,IAAI,EAEfS,cADET,AAAqB,aAArBA,WAAW,KAAK,GACHK,AAAAA,CAAAA,iBAAiBJ,SAAQ,IAAK,IACpCD,AAAqB,UAArBA,WAAW,KAAK,GACXK,iBAAiBJ,YAEjB;IAIlB,MAAMS,cAAcC,sBAClB,CAAEV,CAAAA,YAAYO,YAAW,IAAKN,eAAeO,aAC7CL,WACAH,WACAO,cACAL,MACAG,aACAG;IAGF,OAAOF,MAAM,CAACG,cAAcA;AAC9B;AAEO,SAASE,uBAAuBb,KAMtC;IACC,MAAM,EACJE,SAAS,EACTY,qBAAqB,CAAC,EACtBV,IAAI,EACJC,SAAS,EACTI,YAAY,EACb,GAAGT;IACJ,MAAMe,QAAQX,OACV,GAAIC,AAAAA,CAAAA,YAAYS,AAAqB,IAArBA,kBAAqB,IAAMZ,CAAAA,YAAYO,YAAW,EAAG,EAAE,CAAC,GACxE,GAAGJ,YAAaH,CAAAA,YAAYO,YAAW,IAAKA,aAAa,EAAE,CAAC;IAChE,OAAOM;AACT;AAEO,SAASC,yBAAyBhB,KAMxC;IACC;IACA,MAAM,EACJE,SAAS,EACTY,qBAAqB,CAAC,EACtBV,IAAI,EACJC,SAAS,EACTI,YAAY,EACb,GAAGT;IACJ,MAAMe,QAAQX,OACV,GAAIC,AAAAA,CAAAA,YAAYS,AAAqB,IAArBA,kBAAqB,IAAMZ,CAAAA,YAAYO,YAAW,EAAG,EAAE,CAAC,GACxE,GAAGJ,YAAaH,CAAAA,YAAYO,YAAW,IAAKA,aAAa,EAAE,CAAC;IAEhE,OAAOM;AACT;AASA,SAASE,oBAAoBjB,KAA4B;IAGvD,MAAM,EACJE,SAAS,EACTO,YAAY,EACZH,cAAc,EACdF,IAAI,EACJD,YAAY,EACZE,SAAS,EACTa,UAAU,EACVjB,UAAU,EACVM,WAAW,EACXO,kBAAkB,EAClBN,GAAG,EACHW,SAAS,EACTC,UAAU,EACX,GAAGpB;IACJ,MAAMqB,cAAc;QAClBnB;QACAI;QACAY;QACAd;QACAD;QACAE;QACAJ;QACAM;QACAC;QACAC;IACF;IAEA,MAAMa,iBAAiBC,QAAQ;QAC7B,MAAMC,sBAAsBhB,MAAM,uBAAuB;QACzD,IAAIP,AAAoB,aAApBA,WAAW,IAAI,EACjB,OAAO;YACL,GAAGmB,UAAU;YACb,OAAOP,uBAAuB;gBAC5BX;gBACAY;gBACAV;gBACAC;gBACAI;YACF;YACA,CAACe,oBAAoB,EAAEpB,OACnB,GAAG,CAACU,qBAAsBZ,CAAAA,YAAYO,YAAW,EAAG,EAAE,CAAC,GACvD;YACJ,WAAW,CAAC,WAAW,EAAEV,UAAUsB,aAAa,GAAG,CAAC;YACpD,QAAQ,GAAGH,WAAW,EAAE,CAAC;QAC3B;QACK,IAAIjB,AAAoB,aAApBA,WAAW,IAAI,EACxB,OAAO;YACL,QAAQ,GAAGiB,WAAW,EAAE,CAAC;QAC3B;IAEJ,GAAG;QAACC;KAAU;IAEd,OAAO;QACLG;IACF;AACF;AAEA,kCAAeL"}
@@ -0,0 +1,14 @@
1
+ import type { CompoundModeConfig, SwiperProps } from '../types';
2
+ /**
3
+ * Handle mode and modeConfig
4
+ * Only update reference when mode or content of modeConfig changes
5
+ * This can prevent usage like this causing reRender every time.
6
+ * ```
7
+ * <Swiper mode="normal" modeConfig={{ align: 'center' }}></Swiper>
8
+ * ```
9
+ */
10
+ export declare function useModeConfig({ mode, modeConfig, }: Pick<SwiperProps<unknown>, 'mode' | 'modeConfig'>): {
11
+ modeConfig: CompoundModeConfig;
12
+ spaceBetween: number;
13
+ };
14
+ //# sourceMappingURL=useModeConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useModeConfig.d.ts","sourceRoot":"","sources":["../../src/hooks/useModeConfig.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAEV,kBAAkB,EAElB,WAAW,EACZ,MAAM,UAAU,CAAA;AAGjB;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,EAC5B,IAAe,EACf,UAGC,GACF,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;;;EA2BnD"}
@@ -0,0 +1,33 @@
1
+ import { useMemo, useRef } from "@lynx-js/react";
2
+ import { comparePropsWithObject } from "../utils/compareProps.jsx";
3
+ function useModeConfig({ mode = 'normal', modeConfig = {
4
+ align: 'start',
5
+ spaceBetween: 0
6
+ } }) {
7
+ const prevModeConfigRef = useRef(null);
8
+ const normalizedModeConfig = useMemo(()=>{
9
+ const newConfig = 'custom' === mode ? {
10
+ mode,
11
+ ...modeConfig ?? {}
12
+ } : {
13
+ mode,
14
+ ...modeConfig ?? {
15
+ align: 'start'
16
+ }
17
+ };
18
+ if (prevModeConfigRef.current && comparePropsWithObject(prevModeConfigRef.current, newConfig)) return prevModeConfigRef.current;
19
+ prevModeConfigRef.current = newConfig;
20
+ return newConfig;
21
+ }, [
22
+ mode,
23
+ modeConfig
24
+ ]);
25
+ const spaceBetween = modeConfig.spaceBetween ?? 0;
26
+ return {
27
+ modeConfig: normalizedModeConfig,
28
+ spaceBetween
29
+ };
30
+ }
31
+ export { useModeConfig };
32
+
33
+ //# sourceMappingURL=useModeConfig.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks/useModeConfig.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/hooks/useModeConfig.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useMemo, useRef } from '@lynx-js/react'\n\nimport type {\n CompoundCustomModeConfig,\n CompoundModeConfig,\n CompoundNormalModeConfig,\n SwiperProps,\n} from '../types'\nimport { comparePropsWithObject } from '../utils/compareProps'\n\n/**\n * Handle mode and modeConfig\n * Only update reference when mode or content of modeConfig changes\n * This can prevent usage like this causing reRender every time.\n * ```\n * <Swiper mode=\"normal\" modeConfig={{ align: 'center' }}></Swiper>\n * ```\n */\nexport function useModeConfig({\n mode = 'normal',\n modeConfig = {\n align: 'start',\n spaceBetween: 0,\n },\n}: Pick<SwiperProps<unknown>, 'mode' | 'modeConfig'>) {\n const prevModeConfigRef = useRef<CompoundModeConfig | null>(null)\n\n const normalizedModeConfig = useMemo(() => {\n const newConfig: CompoundModeConfig = mode === 'custom'\n ? { mode, ...(modeConfig ?? {}) } as CompoundCustomModeConfig\n : {\n mode,\n ...(modeConfig ?? { align: 'start' }),\n } as CompoundNormalModeConfig\n\n // If previous config exists and is equal to new config, return cached version\n if (\n prevModeConfigRef.current\n && comparePropsWithObject(prevModeConfigRef.current, newConfig)\n ) {\n return prevModeConfigRef.current\n }\n\n // Update cache and return new config\n prevModeConfigRef.current = newConfig\n return newConfig\n }, [mode, modeConfig])\n\n const spaceBetween = (modeConfig.spaceBetween as number) ?? 0\n\n return { modeConfig: normalizedModeConfig, spaceBetween }\n}\n"],"names":["useModeConfig","mode","modeConfig","prevModeConfigRef","useRef","normalizedModeConfig","useMemo","newConfig","comparePropsWithObject","spaceBetween"],"mappings":";;AAsBO,SAASA,cAAc,EAC5BC,OAAO,QAAQ,EACfC,aAAa;IACX,OAAO;IACP,cAAc;AAChB,CAAC,EACiD;IAClD,MAAMC,oBAAoBC,OAAkC;IAE5D,MAAMC,uBAAuBC,QAAQ;QACnC,MAAMC,YAAgCN,AAAS,aAATA,OAClC;YAAEA;YAAM,GAAIC,cAAc,CAAC,CAAC;QAAE,IAC9B;YACAD;YACA,GAAIC,cAAc;gBAAE,OAAO;YAAQ,CAAC;QACtC;QAGF,IACEC,kBAAkB,OAAO,IACtBK,uBAAuBL,kBAAkB,OAAO,EAAEI,YAErD,OAAOJ,kBAAkB,OAAO;QAIlCA,kBAAkB,OAAO,GAAGI;QAC5B,OAAOA;IACT,GAAG;QAACN;QAAMC;KAAW;IAErB,MAAMO,eAAgBP,WAAW,YAAY,IAAe;IAE5D,OAAO;QAAE,YAAYG;QAAsBI;IAAa;AAC1D"}
@@ -0,0 +1,37 @@
1
+ import type { MainThread } from '@lynx-js/types';
2
+ import { SwipeDirection } from '../types';
3
+ import type { BounceConfig, CompoundModeConfig, OffsetLimitResult, ResetOptions, SwipeToOptions, SwiperProps } from '../types';
4
+ interface UseOffsetOpts extends Required<Pick<SwiperProps<unknown>, 'loop' | 'duration' | 'initialIndex' | 'containerWidth' | 'autoPlay' | 'autoPlayInterval' | 'consumeSlideEvent' | 'RTL'>> {
5
+ dataCount: number;
6
+ size: number;
7
+ spaceBetween: number;
8
+ easing: NonNullable<SwiperProps<unknown>['main-thread:easing']>;
9
+ modeConfig: CompoundModeConfig;
10
+ enableBounce: boolean;
11
+ startBounceItemWidth: NonNullable<BounceConfig['startBounceItemWidth']>;
12
+ endBounceItemWidth: NonNullable<BounceConfig['endBounceItemWidth']>;
13
+ onStartBounceItemBounce: BounceConfig['onStartBounceItemBounce'];
14
+ onEndBounceItemBounce: BounceConfig['onStartBounceItemBounce'];
15
+ experimentalHorizontalSwipeOnly: boolean;
16
+ onSwipeStopMT: () => void;
17
+ onSwipeStartMT: () => void;
18
+ offsetLimit: OffsetLimitResult;
19
+ }
20
+ /**
21
+ * This hook are used to maintain a virtual offset, which does not necessarily reflect the actual
22
+ * location of the swiper
23
+ */
24
+ declare function useOffset({ loop, duration, size, spaceBetween, easing, dataCount, initialIndex, autoPlay, autoPlayInterval, offsetLimit, enableBounce, startBounceItemWidth, endBounceItemWidth, onStartBounceItemBounce, onEndBounceItemBounce, experimentalHorizontalSwipeOnly, onSwipeStartMT, onSwipeStopMT, consumeSlideEvent, RTL, }: UseOffsetOpts, onOffsetUpdate: (offset: number, direction: SwipeDirection) => void): {
25
+ startAutoPlayMT: () => void;
26
+ offsetRef: import("@lynx-js/react").MainThreadRef<number>;
27
+ handleTouchStart: (event: MainThread.TouchEvent) => void;
28
+ handleTouchMove: (event: MainThread.TouchEvent) => void;
29
+ handleTouchEnd: (event: MainThread.TouchEvent) => void;
30
+ swipeTo: (index: number, options?: SwipeToOptions) => void;
31
+ swipeNext: (options?: SwipeToOptions) => void;
32
+ swipePrev: (options?: SwipeToOptions) => void;
33
+ resetOffsetMT: (resetOptions: ResetOptions) => void;
34
+ cancelAnimationJS: () => void;
35
+ };
36
+ export { useOffset };
37
+ //# sourceMappingURL=useOffset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOffset.d.ts","sourceRoot":"","sources":["../../src/hooks/useOffset.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAQhD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,WAAW,EAEZ,MAAM,UAAU,CAAA;AAGjB,UAAU,aAAc,SACtB,QAAQ,CACN,IAAI,CACF,WAAW,CAAC,OAAO,CAAC,EAClB,MAAM,GACN,UAAU,GACV,cAAc,GACd,gBAAgB,GAChB,UAAU,GACV,kBAAkB,GAClB,mBAAmB,GACnB,KAAK,CACR,CACF;IAED,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAA;IAC/D,UAAU,EAAE,kBAAkB,CAAA;IAC9B,YAAY,EAAE,OAAO,CAAA;IACrB,oBAAoB,EAAE,WAAW,CAAC,YAAY,CAAC,sBAAsB,CAAC,CAAC,CAAA;IACvE,kBAAkB,EAAE,WAAW,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC,CAAA;IACnE,uBAAuB,EAAE,YAAY,CAAC,yBAAyB,CAAC,CAAA;IAChE,qBAAqB,EAAE,YAAY,CAAC,yBAAyB,CAAC,CAAA;IAC9D,+BAA+B,EAAE,OAAO,CAAA;IACxC,aAAa,EAAE,MAAM,IAAI,CAAA;IACzB,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B,WAAW,EAAE,iBAAiB,CAAA;CAC/B;AAmCD;;;GAGG;AACH,iBAAS,SAAS,CAChB,EACE,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,+BAA+B,EAC/B,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,GAAG,GACJ,EAAE,aAAa,EAChB,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,KAAK,IAAI;;;8BAsXlC,UAAU,CAAC,UAAU;6BAgBtB,UAAU,CAAC,UAAU;4BAuBtB,UAAU,CAAC,UAAU;qBAzG5B,MAAM,YAAY,cAAc;0BAJ3B,cAAc;0BAJd,cAAc;kCA8IN,YAAY;;EA0ClD;AAED,OAAO,EAAE,SAAS,EAAE,CAAA"}
@@ -0,0 +1,362 @@
1
+ import { runOnBackground, runOnMainThread, useMainThreadRef } from "@lynx-js/react";
2
+ import { useTapLock } from "@lynx-js/react-use";
3
+ import { limiter } from "../utils/index.jsx";
4
+ import { useAnimate } from "./useAnimate.jsx";
5
+ import { useAutoplay } from "./useAutoPlay.jsx";
6
+ import { useAxisLock } from "./useAxisLock.jsx";
7
+ import { useSwipeCallback } from "./useSwipeCallback.jsx";
8
+ import { useVelocity } from "./useVelocity.jsx";
9
+ import { SwipeDirection } from "../types/index.jsx";
10
+ import { useDirection } from "./useDirection.jsx";
11
+ function customRound(num, threshold = 0.5) {
12
+ 'main thread';
13
+ const decimal = num - Math.floor(num);
14
+ if (decimal >= threshold) return Math.ceil(num);
15
+ return Math.floor(num);
16
+ }
17
+ function rubberEffect(rubberDelta, bounceWidth) {
18
+ 'main thread';
19
+ if (0 === rubberDelta || 0 === bounceWidth) return 0;
20
+ const swipeLimit = 2.0 * bounceWidth;
21
+ const scaleFactor = 1.5;
22
+ const absDelta = Math.abs(rubberDelta);
23
+ const effectiveDelta = Math.min(absDelta, swipeLimit);
24
+ const bounce = effectiveDelta / (effectiveDelta / bounceWidth + 1.0);
25
+ return Math.sign(rubberDelta) * bounce * scaleFactor;
26
+ }
27
+ function useOffset({ loop, duration, size, spaceBetween, easing, dataCount, initialIndex, autoPlay, autoPlayInterval, offsetLimit, enableBounce, startBounceItemWidth, endBounceItemWidth, onStartBounceItemBounce, onEndBounceItemBounce, experimentalHorizontalSwipeOnly, onSwipeStartMT, onSwipeStopMT, consumeSlideEvent, RTL }, onOffsetUpdate) {
28
+ const fullSize = size + spaceBetween;
29
+ function getInitialOffset() {
30
+ return limiter(-fullSize * initialIndex, dataCount, size, spaceBetween, loop, offsetLimit);
31
+ }
32
+ const touchStartRef = useMainThreadRef(0);
33
+ const touchStartCrossAxisRef = useMainThreadRef(0);
34
+ const lastScrollOffsetRef = useMainThreadRef(getInitialOffset());
35
+ const offsetRef = useMainThreadRef(getInitialOffset());
36
+ const prevIndexRef = useMainThreadRef(initialIndex);
37
+ const { velocityTouchMove, velocityTouchStart, getVelocity } = useVelocity({
38
+ RTL
39
+ });
40
+ const { cancel: cancelAnimation, animate } = useAnimate();
41
+ const reachedBounceRef = useMainThreadRef(false);
42
+ const bounceDeltaRef = useMainThreadRef(0);
43
+ const { directionRef, handleTouchStart: directionTouchStart, handleTouchMove: directionTouchMove, handleTouchEnd: directionTouchEnd, overrideDirection } = useDirection({
44
+ RTL
45
+ });
46
+ function getCurrentIndex() {
47
+ 'main thread';
48
+ if (0 === dataCount) return 0;
49
+ const totalWidth = fullSize * dataCount;
50
+ const currentIndex = (-offsetRef.current + totalWidth) % totalWidth / fullSize;
51
+ return currentIndex;
52
+ }
53
+ function setOffset(offset) {
54
+ 'main thread';
55
+ if (isNaN(offset)) throw new Error('calcBounceOffset: invalid offset');
56
+ offsetRef.current = offset;
57
+ prevIndexRef.current = getCurrentIndex();
58
+ onOffsetUpdate(offset, directionRef.current);
59
+ }
60
+ function calcLimitCompact(offset, options) {
61
+ 'main thread';
62
+ let reachingLimit = 0;
63
+ let finalOffset = offset;
64
+ if (0 === dataCount) {
65
+ if (options?.type === 'prev') return {
66
+ offset: 0,
67
+ reachingLimit: -1
68
+ };
69
+ return {
70
+ offset: 0,
71
+ reachingLimit: 1
72
+ };
73
+ }
74
+ if (!loop) {
75
+ if (offset >= -offsetLimit.startLimit) {
76
+ reachingLimit = -1;
77
+ finalOffset = -offsetLimit.startLimit;
78
+ } else if (offset <= -fullSize * (dataCount - 1) + offsetLimit.endLimit) {
79
+ reachingLimit = 1;
80
+ finalOffset = -fullSize * (dataCount - 1) + offsetLimit.endLimit;
81
+ }
82
+ }
83
+ return {
84
+ offset: finalOffset,
85
+ reachingLimit
86
+ };
87
+ }
88
+ function calcBounceOffsetAndLimit(offset) {
89
+ 'main thread';
90
+ const { offset: limitOffset, reachingLimit } = calcLimitCompact(offset);
91
+ if (enableBounce && reachingLimit) {
92
+ const bounceDelta = offset - limitOffset;
93
+ const bounceItemWidth = -1 === reachingLimit ? startBounceItemWidth : offsetLimit.isNotEnoughForScreen ? 0 : endBounceItemWidth;
94
+ reachedBounceRef.current = true;
95
+ bounceDeltaRef.current = rubberEffect(bounceDelta, bounceItemWidth);
96
+ return limitOffset + bounceDeltaRef.current;
97
+ }
98
+ return limitOffset;
99
+ }
100
+ function calcPaging(offset, rounding = 0.5) {
101
+ 'main thread';
102
+ const { offset: limitOffset, reachingLimit } = calcLimitCompact(offset);
103
+ if (reachingLimit) return limitOffset;
104
+ return customRound(-offset / fullSize, rounding) * -fullSize;
105
+ }
106
+ function calcLoop(start, end) {
107
+ 'main thread';
108
+ let startOffset = start;
109
+ let finalOffset = end;
110
+ if (0 === dataCount) return {
111
+ offset: 0,
112
+ finalOffset: 0
113
+ };
114
+ const totalWidth = fullSize * dataCount;
115
+ if (loop) {
116
+ if (finalOffset < -totalWidth + fullSize) {
117
+ finalOffset += totalWidth;
118
+ startOffset += totalWidth;
119
+ } else if (finalOffset > 0) {
120
+ finalOffset -= totalWidth;
121
+ startOffset -= totalWidth;
122
+ }
123
+ }
124
+ return {
125
+ offset: startOffset,
126
+ finalOffset
127
+ };
128
+ }
129
+ const { handleTouchMove: swipeCallbackTouchMove, handleTouchStart: swipeCallbackTouchStart, setSwipeEndMT, setSwipeStartMT } = useSwipeCallback({
130
+ onSwipeStartMT,
131
+ onSwipeStopMT
132
+ });
133
+ const { handleTouchStart: axisLockTouchStart, handleTouchMove: axisLockTouchMove, handleTouchEnd: axisLockTouchEnd, handleVelocity: axisLockVelocity } = useAxisLock({
134
+ consumeSlideEvent,
135
+ experimentalHorizontalSwipeOnly
136
+ });
137
+ const { handleTouchStart: tapLockTouchStart, handleTouchMove: tapLockTouchMove, handleTouchEnd: tapLockTouchEnd } = useTapLock();
138
+ function easingTo(start, end, onFinished) {
139
+ 'main thread';
140
+ function onProgress(progress) {
141
+ const interpolatedProgress = easing(progress / 100);
142
+ const animeOffset = (end - start) * interpolatedProgress + start;
143
+ setOffset(animeOffset);
144
+ }
145
+ animate(duration, onProgress, onFinished);
146
+ }
147
+ function hasNextMTS() {
148
+ 'main thread';
149
+ const offset = offsetRef.current;
150
+ const { reachingLimit } = calcLimitCompact(offset);
151
+ return 1 !== reachingLimit;
152
+ }
153
+ function hasPrevMTS() {
154
+ 'main thread';
155
+ const offset = offsetRef.current;
156
+ const { reachingLimit } = calcLimitCompact(offset);
157
+ return -1 !== reachingLimit;
158
+ }
159
+ function swipeToMTS(index, options) {
160
+ 'main thread';
161
+ if (0 === dataCount) return void setSwipeEndMT();
162
+ const finalIndex = Math.max(Math.min(index, dataCount - 1), 0);
163
+ const currentIndex = getCurrentIndex();
164
+ const { offset: finalOffset } = calcLimitCompact(-finalIndex * fullSize);
165
+ setSwipeStartMT();
166
+ if (finalIndex > currentIndex) overrideDirection(SwipeDirection.NORMAL);
167
+ else finalIndex < currentIndex ? overrideDirection(SwipeDirection.REVERT) : overrideDirection(SwipeDirection.NONE);
168
+ if (options?.animate) easingTo(offsetRef.current, finalOffset, ()=>{
169
+ if (options?.onFinished) options.onFinished();
170
+ setSwipeEndMT();
171
+ });
172
+ else {
173
+ setOffset(finalOffset);
174
+ setSwipeEndMT();
175
+ }
176
+ }
177
+ function swipeNextMTS(options) {
178
+ 'main thread';
179
+ if (!hasNextMTS()) return void setSwipeEndMT();
180
+ setSwipeStartMT();
181
+ let offset = offsetRef.current;
182
+ let finalOffset = calcPaging(offset - fullSize, 0.95);
183
+ if (loop) {
184
+ const result = calcLoop(offset, finalOffset);
185
+ offset = result.offset;
186
+ finalOffset = result.finalOffset;
187
+ } else {
188
+ const result = calcLimitCompact(finalOffset);
189
+ finalOffset = result.offset;
190
+ }
191
+ overrideDirection(SwipeDirection.NORMAL);
192
+ if (options?.animate === false) {
193
+ setOffset(finalOffset);
194
+ setSwipeEndMT();
195
+ } else easingTo(offset, finalOffset, ()=>{
196
+ if (options?.onFinished) options.onFinished();
197
+ setSwipeEndMT();
198
+ });
199
+ }
200
+ function swipePrevMTS(options) {
201
+ 'main thread';
202
+ if (!hasPrevMTS()) return void setSwipeEndMT();
203
+ setSwipeStartMT();
204
+ let offset = offsetRef.current;
205
+ let finalOffset = calcPaging(offset + fullSize, 0.05);
206
+ if (loop) {
207
+ const result = calcLoop(offset, finalOffset);
208
+ offset = result.offset;
209
+ finalOffset = result.finalOffset;
210
+ } else {
211
+ const result = calcLimitCompact(finalOffset);
212
+ finalOffset = result.offset;
213
+ }
214
+ overrideDirection(SwipeDirection.REVERT);
215
+ if (options?.animate === false) {
216
+ setOffset(finalOffset);
217
+ setSwipeEndMT();
218
+ } else easingTo(offset, finalOffset, ()=>{
219
+ if (options?.onFinished) options.onFinished();
220
+ setSwipeEndMT();
221
+ });
222
+ }
223
+ function swipePrev(options) {
224
+ runOnMainThread(swipePrevMTS)(options);
225
+ }
226
+ function swipeNext(options) {
227
+ runOnMainThread(swipeNextMTS)(options);
228
+ }
229
+ function swipeTo(index, options) {
230
+ runOnMainThread(swipeToMTS)(index, options);
231
+ }
232
+ function handleOnBounce(params) {
233
+ if ('start' === params.type && onStartBounceItemBounce) onStartBounceItemBounce(params);
234
+ else if ('end' === params.type && onEndBounceItemBounce) onEndBounceItemBounce(params);
235
+ }
236
+ function handleBounceCallback(offset) {
237
+ 'main thread';
238
+ if (reachedBounceRef.current) {
239
+ runOnBackground(handleOnBounce)({
240
+ type: offset > 0 ? 'start' : 'end',
241
+ offset: Math.abs(bounceDeltaRef.current)
242
+ });
243
+ reachedBounceRef.current = false;
244
+ bounceDeltaRef.current = 0;
245
+ }
246
+ }
247
+ const { pauseMT: pauseAutoPlayMT, startMT: startAutoPlayMT } = useAutoplay({
248
+ autoPlay,
249
+ autoPlayInterval,
250
+ prevMT: swipePrevMTS,
251
+ nextMT: swipeNextMTS,
252
+ duration,
253
+ dataCount
254
+ });
255
+ function handleVelocity() {
256
+ 'main thread';
257
+ const VELOCITY_THRESHOLD = 300;
258
+ if (axisLockVelocity()) return false;
259
+ const { velocity: velocityValue, direction } = getVelocity();
260
+ if (Math.abs(velocityValue) > VELOCITY_THRESHOLD) {
261
+ overrideDirection(direction);
262
+ if (direction === SwipeDirection.NORMAL && hasNextMTS()) {
263
+ swipeNextMTS({
264
+ onFinished: ()=>{
265
+ startAutoPlayMT();
266
+ }
267
+ });
268
+ return true;
269
+ }
270
+ if (direction === SwipeDirection.REVERT && hasPrevMTS()) {
271
+ swipePrevMTS({
272
+ onFinished: ()=>{
273
+ startAutoPlayMT();
274
+ }
275
+ });
276
+ return true;
277
+ }
278
+ }
279
+ return false;
280
+ }
281
+ function handleTouchStart(event) {
282
+ 'main thread';
283
+ lastScrollOffsetRef.current = offsetRef.current;
284
+ touchStartRef.current = event.detail.x;
285
+ touchStartCrossAxisRef.current = event.detail.y;
286
+ axisLockTouchStart(event);
287
+ velocityTouchStart();
288
+ tapLockTouchStart(event);
289
+ cancelAnimation();
290
+ swipeCallbackTouchStart(event);
291
+ directionTouchStart(event);
292
+ pauseAutoPlayMT();
293
+ }
294
+ function handleTouchMove(event) {
295
+ 'main thread';
296
+ if (0 === dataCount) return;
297
+ if (axisLockTouchMove(event) || tapLockTouchMove(event)) return;
298
+ const sign = RTL ? -1 : 1;
299
+ let offsetInner = sign * (event.detail.x - touchStartRef.current) + lastScrollOffsetRef.current;
300
+ offsetInner = calcBounceOffsetAndLimit(offsetInner);
301
+ setOffset(offsetInner);
302
+ velocityTouchMove(event);
303
+ swipeCallbackTouchMove(event);
304
+ directionTouchMove(event);
305
+ }
306
+ function handleTouchEnd(event) {
307
+ 'main thread';
308
+ let offset = offsetRef.current;
309
+ handleBounceCallback(offset);
310
+ if (handleVelocity()) return;
311
+ axisLockTouchEnd();
312
+ directionTouchEnd(event);
313
+ let finalOffset = calcPaging(offset);
314
+ if (loop) {
315
+ const result = calcLoop(offset, finalOffset);
316
+ offset = result.offset;
317
+ finalOffset = result.finalOffset;
318
+ } else {
319
+ const result = calcLimitCompact(finalOffset);
320
+ finalOffset = result.offset;
321
+ }
322
+ tapLockTouchEnd(event);
323
+ easingTo(offset, finalOffset, ()=>{
324
+ setSwipeEndMT();
325
+ startAutoPlayMT();
326
+ });
327
+ }
328
+ function resetOffsetMT(resetOptions) {
329
+ 'main thread';
330
+ cancelAnimation();
331
+ if (0 === dataCount) return void swipeToMTS(0);
332
+ if (resetOptions.fullReset) swipeToMTS(resetOptions.resetIndex, {
333
+ animate: false
334
+ });
335
+ else {
336
+ const currentIndex = prevIndexRef.current;
337
+ isNaN(currentIndex) ? swipeToMTS(0, {
338
+ animate: false
339
+ }) : swipeToMTS(currentIndex, {
340
+ animate: false
341
+ });
342
+ }
343
+ }
344
+ function cancelAnimationJS() {
345
+ runOnMainThread(cancelAnimation)();
346
+ }
347
+ return {
348
+ startAutoPlayMT,
349
+ offsetRef,
350
+ handleTouchStart,
351
+ handleTouchMove,
352
+ handleTouchEnd,
353
+ swipeTo,
354
+ swipeNext,
355
+ swipePrev,
356
+ resetOffsetMT,
357
+ cancelAnimationJS
358
+ };
359
+ }
360
+ export { useOffset };
361
+
362
+ //# sourceMappingURL=useOffset.jsx.map