@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.
- package/CHANGELOG.md +16 -0
- package/LICENSE +201 -0
- package/README.md +51 -0
- package/dist/Swiper/index.d.ts +11 -0
- package/dist/Swiper/index.d.ts.map +1 -0
- package/dist/Swiper/index.jsx +261 -0
- package/dist/Swiper/index.jsx.map +1 -0
- package/dist/Swiper/styles.css +47 -0
- package/dist/Swiper/styles.css.map +1 -0
- package/dist/SwiperItem/index.d.ts +46 -0
- package/dist/SwiperItem/index.d.ts.map +1 -0
- package/dist/SwiperItem/index.jsx +86 -0
- package/dist/SwiperItem/index.jsx.map +1 -0
- package/dist/const/index.d.ts +5 -0
- package/dist/const/index.d.ts.map +1 -0
- package/dist/const/index.jsx +7 -0
- package/dist/const/index.jsx.map +1 -0
- package/dist/hooks/useAnimate.d.ts +5 -0
- package/dist/hooks/useAnimate.d.ts.map +1 -0
- package/dist/hooks/useAnimate.jsx +47 -0
- package/dist/hooks/useAnimate.jsx.map +1 -0
- package/dist/hooks/useAutoPlay.d.ts +16 -0
- package/dist/hooks/useAutoPlay.d.ts.map +1 -0
- package/dist/hooks/useAutoPlay.jsx +58 -0
- package/dist/hooks/useAutoPlay.jsx.map +1 -0
- package/dist/hooks/useAxisLock.d.ts +12 -0
- package/dist/hooks/useAxisLock.d.ts.map +1 -0
- package/dist/hooks/useAxisLock.jsx +58 -0
- package/dist/hooks/useAxisLock.jsx.map +1 -0
- package/dist/hooks/useBounceConfig.d.ts +12 -0
- package/dist/hooks/useBounceConfig.d.ts.map +1 -0
- package/dist/hooks/useBounceConfig.jsx +15 -0
- package/dist/hooks/useBounceConfig.jsx.map +1 -0
- package/dist/hooks/useBounceView.d.ts +17 -0
- package/dist/hooks/useBounceView.d.ts.map +1 -0
- package/dist/hooks/useBounceView.jsx +16 -0
- package/dist/hooks/useBounceView.jsx.map +1 -0
- package/dist/hooks/useChange.d.ts +22 -0
- package/dist/hooks/useChange.d.ts.map +1 -0
- package/dist/hooks/useChange.jsx +53 -0
- package/dist/hooks/useChange.jsx.map +1 -0
- package/dist/hooks/useDirection.d.ts +13 -0
- package/dist/hooks/useDirection.d.ts.map +1 -0
- package/dist/hooks/useDirection.jsx +37 -0
- package/dist/hooks/useDirection.jsx.map +1 -0
- package/dist/hooks/useFirstScreenStyle.d.ts +34 -0
- package/dist/hooks/useFirstScreenStyle.d.ts.map +1 -0
- package/dist/hooks/useFirstScreenStyle.jsx +63 -0
- package/dist/hooks/useFirstScreenStyle.jsx.map +1 -0
- package/dist/hooks/useModeConfig.d.ts +14 -0
- package/dist/hooks/useModeConfig.d.ts.map +1 -0
- package/dist/hooks/useModeConfig.jsx +33 -0
- package/dist/hooks/useModeConfig.jsx.map +1 -0
- package/dist/hooks/useOffset.d.ts +37 -0
- package/dist/hooks/useOffset.d.ts.map +1 -0
- package/dist/hooks/useOffset.jsx +362 -0
- package/dist/hooks/useOffset.jsx.map +1 -0
- package/dist/hooks/useOffsetLimit.d.ts +16 -0
- package/dist/hooks/useOffsetLimit.d.ts.map +1 -0
- package/dist/hooks/useOffsetLimit.jsx +51 -0
- package/dist/hooks/useOffsetLimit.jsx.map +1 -0
- package/dist/hooks/useReset.d.ts +16 -0
- package/dist/hooks/useReset.d.ts.map +1 -0
- package/dist/hooks/useReset.jsx +68 -0
- package/dist/hooks/useReset.jsx.map +1 -0
- package/dist/hooks/useSwipeCallback.d.ts +14 -0
- package/dist/hooks/useSwipeCallback.d.ts.map +1 -0
- package/dist/hooks/useSwipeCallback.jsx +40 -0
- package/dist/hooks/useSwipeCallback.jsx.map +1 -0
- package/dist/hooks/useVelocity.d.ts +14 -0
- package/dist/hooks/useVelocity.d.ts.map +1 -0
- package/dist/hooks/useVelocity.jsx +62 -0
- package/dist/hooks/useVelocity.jsx.map +1 -0
- package/dist/hooks/useVelocity_experiment.d.ts +12 -0
- package/dist/hooks/useVelocity_experiment.d.ts.map +1 -0
- package/dist/hooks/useVelocity_experiment.jsx +38 -0
- package/dist/hooks/useVelocity_experiment.jsx.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.jsx +3 -0
- package/dist/store/index.d.ts +3 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.jsx +18 -0
- package/dist/store/index.jsx.map +1 -0
- package/dist/types/index.d.ts +62 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.docs.d.ts +448 -0
- package/dist/types/index.docs.d.ts.map +1 -0
- package/dist/types/index.jsx +9 -0
- package/dist/types/index.jsx.map +1 -0
- package/dist/utils/animate.d.ts +4 -0
- package/dist/utils/animate.d.ts.map +1 -0
- package/dist/utils/animate.jsx +29 -0
- package/dist/utils/animate.jsx.map +1 -0
- package/dist/utils/compareProps.d.ts +2 -0
- package/dist/utils/compareProps.d.ts.map +1 -0
- package/dist/utils/compareProps.jsx +14 -0
- package/dist/utils/compareProps.jsx.map +1 -0
- package/dist/utils/customRound.d.ts +10 -0
- package/dist/utils/customRound.d.ts.map +1 -0
- package/dist/utils/customRound.jsx +9 -0
- package/dist/utils/customRound.jsx.map +1 -0
- package/dist/utils/index.d.ts +20 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.jsx +55 -0
- package/dist/utils/index.jsx.map +1 -0
- package/package.json +47 -4
- package/src/Swiper/index.tsx +414 -0
- package/src/Swiper/styles.css +44 -0
- package/src/SwiperItem/index.tsx +205 -0
- package/src/const/index.ts +11 -0
- package/src/hooks/useAnimate.ts +80 -0
- package/src/hooks/useAutoPlay.ts +95 -0
- package/src/hooks/useAxisLock.ts +92 -0
- package/src/hooks/useBounceConfig.ts +29 -0
- package/src/hooks/useBounceView.tsx +50 -0
- package/src/hooks/useChange.ts +131 -0
- package/src/hooks/useDirection.ts +59 -0
- package/src/hooks/useFirstScreenStyle.ts +200 -0
- package/src/hooks/useModeConfig.ts +56 -0
- package/src/hooks/useOffset.ts +609 -0
- package/src/hooks/useOffsetLimit.ts +98 -0
- package/src/hooks/useReset.ts +144 -0
- package/src/hooks/useSwipeCallback.ts +66 -0
- package/src/hooks/useVelocity.ts +83 -0
- package/src/hooks/useVelocity_experiment.ts +50 -0
- package/src/index.ts +8 -0
- package/src/store/index.ts +23 -0
- package/src/types/index.docs.ts +465 -0
- package/src/types/index.ts +105 -0
- package/src/utils/animate.ts +49 -0
- package/src/utils/compareProps.ts +54 -0
- package/src/utils/customRound.ts +23 -0
- package/src/utils/index.ts +117 -0
- package/tsconfig.docs.json +7 -0
- package/tsconfig.json +9 -0
- /package/{index.js → dist/types/index.docs.jsx} +0 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ReactElement } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
export interface SwiperItemProps {
|
|
4
|
+
/**
|
|
5
|
+
* Index of current SwiperItem, out of Swiper's data.
|
|
6
|
+
* @Android
|
|
7
|
+
* @iOS
|
|
8
|
+
* @Harmony
|
|
9
|
+
*/
|
|
10
|
+
index: number;
|
|
11
|
+
/**
|
|
12
|
+
* Children of SwiperItem
|
|
13
|
+
* @Android
|
|
14
|
+
* @iOS
|
|
15
|
+
* @Harmony
|
|
16
|
+
*/
|
|
17
|
+
children: ReactElement | ReactElement[];
|
|
18
|
+
/**
|
|
19
|
+
* Style of SwiperItem
|
|
20
|
+
* @Android
|
|
21
|
+
* @iOS
|
|
22
|
+
* @Harmony
|
|
23
|
+
*/
|
|
24
|
+
style?: CSSProperties;
|
|
25
|
+
/**
|
|
26
|
+
* Real index of current SwiperItem, out of Swiper's data.
|
|
27
|
+
* Same with `index`, but will be different from `index` when in loop mode.
|
|
28
|
+
* @Android
|
|
29
|
+
* @iOS
|
|
30
|
+
* @Harmony
|
|
31
|
+
*/
|
|
32
|
+
realIndex?: number;
|
|
33
|
+
/**
|
|
34
|
+
* `overlap` attribute passed to SwiperItem's direct child.
|
|
35
|
+
* This property is used only when opacity has issues.
|
|
36
|
+
* Refer to {@link https://lynxjs.org/en/api/css/properties/opacity#opacity}
|
|
37
|
+
* @Android
|
|
38
|
+
* @iOS
|
|
39
|
+
* @Harmony
|
|
40
|
+
*/
|
|
41
|
+
overlap?: boolean;
|
|
42
|
+
}
|
|
43
|
+
declare const SwiperItem: ({ index, realIndex, children, overlap }: SwiperItemProps) => import("react").JSX.Element;
|
|
44
|
+
declare const MemoSwiperItem: typeof SwiperItem;
|
|
45
|
+
export { MemoSwiperItem as SwiperItem };
|
|
46
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/SwiperItem/index.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,YAAY,EAAa,MAAM,gBAAgB,CAAA;AAE7D,OAAO,KAAK,EAAE,aAAa,EAAc,MAAM,gBAAgB,CAAA;AAK/D,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;;OAKG;IACH,QAAQ,EAAE,YAAY,GAAG,YAAY,EAAE,CAAA;IACvC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAmGD,QAAA,MAAM,UAAU,GACd,yCAAiD,eAAe,gCA0CjE,CAAA;AAED,QAAA,MAAM,cAAc,EAAuB,OAAO,UAAU,CAAA;AAE5D,OAAO,EAAE,cAAc,IAAI,UAAU,EAAE,CAAA"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { memo, runOnMainThread, useContext, useEffect, useMainThreadRef, useMemo } from "@lynx-js/react";
|
|
2
|
+
import { SwiperContext } from "../store/index.jsx";
|
|
3
|
+
function useFirstScreenStyle(props) {
|
|
4
|
+
const { itemWidth, spaceBetween, itemHeight, itemRef, customAnimationFirstScreen, realIndex, modeConfig, initialIndex, RTL } = props;
|
|
5
|
+
const containerStyle = useMemo(()=>{
|
|
6
|
+
if ('normal' === modeConfig.mode) {
|
|
7
|
+
let style = {
|
|
8
|
+
width: `${itemWidth}px`,
|
|
9
|
+
height: `${itemHeight}px`,
|
|
10
|
+
[true === RTL ? 'marginLeft' : 'marginRight']: `${spaceBetween}px`
|
|
11
|
+
};
|
|
12
|
+
if (customAnimationFirstScreen) {
|
|
13
|
+
const customStyle = customAnimationFirstScreen(-initialIndex + realIndex, realIndex);
|
|
14
|
+
style = {
|
|
15
|
+
...style,
|
|
16
|
+
...customStyle
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return style;
|
|
20
|
+
}
|
|
21
|
+
if ('custom' === modeConfig.mode) {
|
|
22
|
+
let style = {
|
|
23
|
+
width: `${itemWidth}px`,
|
|
24
|
+
height: `${itemHeight}px`,
|
|
25
|
+
position: 'absolute'
|
|
26
|
+
};
|
|
27
|
+
if (customAnimationFirstScreen) {
|
|
28
|
+
const customStyle = customAnimationFirstScreen(-initialIndex + realIndex, realIndex);
|
|
29
|
+
style = {
|
|
30
|
+
...style,
|
|
31
|
+
...customStyle
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return style;
|
|
35
|
+
}
|
|
36
|
+
}, []);
|
|
37
|
+
function updateMainThreadR(propsFromJS) {
|
|
38
|
+
'main thread';
|
|
39
|
+
if (itemRef.current) itemRef.current.setStyleProperties({
|
|
40
|
+
width: `${propsFromJS.itemWidth}px`,
|
|
41
|
+
height: `${propsFromJS.itemHeight}px`,
|
|
42
|
+
marginInlineEnd: `${propsFromJS.spaceBetween}px`
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
useEffect(()=>{
|
|
46
|
+
runOnMainThread(updateMainThreadR)({
|
|
47
|
+
itemWidth,
|
|
48
|
+
itemHeight,
|
|
49
|
+
spaceBetween
|
|
50
|
+
});
|
|
51
|
+
}, [
|
|
52
|
+
itemWidth,
|
|
53
|
+
itemHeight,
|
|
54
|
+
spaceBetween
|
|
55
|
+
]);
|
|
56
|
+
return {
|
|
57
|
+
containerStyle
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const SwiperItem = ({ index, realIndex = index, children, overlap })=>{
|
|
61
|
+
const { itemWidth, itemHeight, setChildrenRef, modeConfig, customAnimationFirstScreen, initialIndex = 0, spaceBetween, RTL } = useContext(SwiperContext);
|
|
62
|
+
const swiperItemRef = useMainThreadRef();
|
|
63
|
+
const { containerStyle } = useFirstScreenStyle({
|
|
64
|
+
itemWidth,
|
|
65
|
+
itemHeight,
|
|
66
|
+
spaceBetween,
|
|
67
|
+
itemRef: swiperItemRef,
|
|
68
|
+
modeConfig,
|
|
69
|
+
realIndex,
|
|
70
|
+
initialIndex,
|
|
71
|
+
customAnimationFirstScreen,
|
|
72
|
+
RTL
|
|
73
|
+
});
|
|
74
|
+
function setRef(ref) {
|
|
75
|
+
'main thread';
|
|
76
|
+
swiperItemRef.current = ref;
|
|
77
|
+
setChildrenRef(ref, realIndex ?? index);
|
|
78
|
+
}
|
|
79
|
+
return <view class='swiper-item' style={containerStyle} main-thread:ref={setRef} overlap={overlap}>
|
|
80
|
+
{children}
|
|
81
|
+
</view>;
|
|
82
|
+
};
|
|
83
|
+
const MemoSwiperItem = memo(SwiperItem);
|
|
84
|
+
export { MemoSwiperItem as SwiperItem };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=index.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwiperItem/index.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/SwiperItem/index.tsx"],"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 {\n memo,\n runOnMainThread,\n useContext,\n useEffect,\n useMainThreadRef,\n useMemo,\n} from '@lynx-js/react'\nimport type { ReactElement, RefObject } from '@lynx-js/react'\n\nimport type { CSSProperties, MainThread } from '@lynx-js/types'\n\nimport { SwiperContext } from '../store'\nimport type { CompoundModeConfig, SwiperContextProps } from '../types'\n\nexport interface SwiperItemProps {\n /**\n * Index of current SwiperItem, out of Swiper's data.\n * @Android\n * @iOS\n * @Harmony\n */\n index: number\n /**\n * Children of SwiperItem\n * @Android\n * @iOS\n * @Harmony\n */\n children: ReactElement | ReactElement[]\n /**\n * Style of SwiperItem\n * @Android\n * @iOS\n * @Harmony\n */\n style?: CSSProperties\n /**\n * Real index of current SwiperItem, out of Swiper's data.\n * Same with `index`, but will be different from `index` when in loop mode.\n * @Android\n * @iOS\n * @Harmony\n */\n realIndex?: number\n /**\n * `overlap` attribute passed to SwiperItem's direct child.\n * This property is used only when opacity has issues.\n * Refer to {@link https://lynxjs.org/en/api/css/properties/opacity#opacity}\n * @Android\n * @iOS\n * @Harmony\n */\n overlap?: boolean\n}\n\ninterface IFirstScreenStyle extends\n Pick<\n SwiperContextProps,\n | 'itemWidth'\n | 'itemHeight'\n | 'initialIndex'\n | 'customAnimationFirstScreen'\n | 'RTL'\n >\n{\n itemRef: RefObject<MainThread.Element | undefined>\n spaceBetween: number\n realIndex: number\n modeConfig: CompoundModeConfig\n}\n\nfunction useFirstScreenStyle(props: IFirstScreenStyle) {\n const {\n itemWidth,\n spaceBetween,\n itemHeight,\n itemRef,\n customAnimationFirstScreen,\n realIndex,\n modeConfig,\n initialIndex,\n RTL,\n } = props\n\n const containerStyle = useMemo(() => {\n if (modeConfig.mode === 'normal') {\n let style: CSSProperties = {\n width: `${itemWidth}px`,\n height: `${itemHeight}px`,\n [RTL === true ? 'marginLeft' : 'marginRight']: `${spaceBetween}px`,\n }\n if (customAnimationFirstScreen) {\n const customStyle = customAnimationFirstScreen(\n -initialIndex + realIndex,\n realIndex,\n )\n style = {\n ...style,\n ...customStyle,\n }\n }\n\n return style\n } else if (modeConfig.mode === 'custom') {\n let style: CSSProperties = {\n width: `${itemWidth}px`,\n height: `${itemHeight}px`,\n position: 'absolute',\n }\n if (customAnimationFirstScreen) {\n const customStyle = customAnimationFirstScreen(\n -initialIndex + realIndex,\n realIndex,\n )\n style = {\n ...style,\n ...customStyle,\n }\n }\n\n return style\n }\n }, [])\n\n function updateMainThreadR(propsFromJS: {\n itemWidth: number\n itemHeight: SwiperContextProps['itemHeight']\n spaceBetween: number\n }) {\n 'main thread'\n if (itemRef.current) {\n itemRef.current.setStyleProperties({\n width: `${propsFromJS.itemWidth}px`,\n height: `${propsFromJS.itemHeight}px`,\n marginInlineEnd: `${propsFromJS.spaceBetween}px`,\n })\n }\n }\n\n useEffect(() => {\n runOnMainThread(updateMainThreadR)({\n itemWidth,\n itemHeight,\n spaceBetween,\n })\n }, [itemWidth, itemHeight, spaceBetween])\n\n return {\n containerStyle,\n }\n}\n\nconst SwiperItem = (\n { index, realIndex = index, children, overlap }: SwiperItemProps,\n) => {\n const {\n itemWidth,\n itemHeight,\n setChildrenRef,\n modeConfig,\n customAnimationFirstScreen,\n initialIndex = 0,\n spaceBetween,\n RTL,\n } = useContext(SwiperContext)\n const swiperItemRef = useMainThreadRef<MainThread.Element>()\n\n const { containerStyle } = useFirstScreenStyle({\n itemWidth,\n itemHeight,\n spaceBetween,\n itemRef: swiperItemRef,\n modeConfig,\n realIndex,\n initialIndex,\n customAnimationFirstScreen,\n RTL,\n })\n\n function setRef(ref: MainThread.Element) {\n 'main thread'\n swiperItemRef.current = ref\n setChildrenRef(ref, realIndex ?? index)\n }\n\n return (\n <view\n class='swiper-item'\n style={containerStyle}\n main-thread:ref={setRef}\n overlap={overlap}\n >\n {children}\n </view>\n )\n}\n\nconst MemoSwiperItem = memo(SwiperItem) as typeof SwiperItem\n\nexport { MemoSwiperItem as SwiperItem }\n"],"names":["useFirstScreenStyle","props","itemWidth","spaceBetween","itemHeight","itemRef","customAnimationFirstScreen","realIndex","modeConfig","initialIndex","RTL","containerStyle","useMemo","style","customStyle","updateMainThreadR","propsFromJS","useEffect","runOnMainThread","SwiperItem","index","children","overlap","setChildrenRef","useContext","SwiperContext","swiperItemRef","useMainThreadRef","setRef","ref","view","MemoSwiperItem","memo"],"mappings":";;AA4EA,SAASA,oBAAoBC,KAAwB;IACnD,MAAM,EACJC,SAAS,EACTC,YAAY,EACZC,UAAU,EACVC,OAAO,EACPC,0BAA0B,EAC1BC,SAAS,EACTC,UAAU,EACVC,YAAY,EACZC,GAAG,EACJ,GAAGT;IAEJ,MAAMU,iBAAiBC,QAAQ;QAC7B,IAAIJ,AAAoB,aAApBA,WAAW,IAAI,EAAe;YAChC,IAAIK,QAAuB;gBACzB,OAAO,GAAGX,UAAU,EAAE,CAAC;gBACvB,QAAQ,GAAGE,WAAW,EAAE,CAAC;gBACzB,CAACM,AAAQ,SAARA,MAAe,eAAe,cAAc,EAAE,GAAGP,aAAa,EAAE,CAAC;YACpE;YACA,IAAIG,4BAA4B;gBAC9B,MAAMQ,cAAcR,2BAClB,CAACG,eAAeF,WAChBA;gBAEFM,QAAQ;oBACN,GAAGA,KAAK;oBACR,GAAGC,WAAW;gBAChB;YACF;YAEA,OAAOD;QACT;QAAO,IAAIL,AAAoB,aAApBA,WAAW,IAAI,EAAe;YACvC,IAAIK,QAAuB;gBACzB,OAAO,GAAGX,UAAU,EAAE,CAAC;gBACvB,QAAQ,GAAGE,WAAW,EAAE,CAAC;gBACzB,UAAU;YACZ;YACA,IAAIE,4BAA4B;gBAC9B,MAAMQ,cAAcR,2BAClB,CAACG,eAAeF,WAChBA;gBAEFM,QAAQ;oBACN,GAAGA,KAAK;oBACR,GAAGC,WAAW;gBAChB;YACF;YAEA,OAAOD;QACT;IACF,GAAG,EAAE;IAEL,SAASE,kBAAkBC,WAI1B;QACC;QACA,IAAIX,QAAQ,OAAO,EACjBA,QAAQ,OAAO,CAAC,kBAAkB,CAAC;YACjC,OAAO,GAAGW,YAAY,SAAS,CAAC,EAAE,CAAC;YACnC,QAAQ,GAAGA,YAAY,UAAU,CAAC,EAAE,CAAC;YACrC,iBAAiB,GAAGA,YAAY,YAAY,CAAC,EAAE,CAAC;QAClD;IAEJ;IAEAC,UAAU;QACRC,gBAAgBH,mBAAmB;YACjCb;YACAE;YACAD;QACF;IACF,GAAG;QAACD;QAAWE;QAAYD;KAAa;IAExC,OAAO;QACLQ;IACF;AACF;AAEA,MAAMQ,aAAa,CACjB,EAAEC,KAAK,EAAEb,YAAYa,KAAK,EAAEC,QAAQ,EAAEC,OAAO,EAAmB;IAEhE,MAAM,EACJpB,SAAS,EACTE,UAAU,EACVmB,cAAc,EACdf,UAAU,EACVF,0BAA0B,EAC1BG,eAAe,CAAC,EAChBN,YAAY,EACZO,GAAG,EACJ,GAAGc,WAAWC;IACf,MAAMC,gBAAgBC;IAEtB,MAAM,EAAEhB,cAAc,EAAE,GAAGX,oBAAoB;QAC7CE;QACAE;QACAD;QACA,SAASuB;QACTlB;QACAD;QACAE;QACAH;QACAI;IACF;IAEA,SAASkB,OAAOC,GAAuB;QACrC;QACAH,cAAc,OAAO,GAAGG;QACxBN,eAAeM,KAAKtB,aAAaa;IACnC;IAEA,QACGU,KACC,MAAM,cACN,OAAOnB,gBACP,YAAY,KAAKiB,QACjB,SAASN,SACV;MACC,CAACD,SAAS;IACZ,EAAES;AAEN;AAEA,MAAMC,iBAAiBC,KAAKb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/const/index.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,IAAI,CAAA;AAE3B,eAAO,MAAM,aAAa,IAAI,CAAA;AAE9B,eAAO,MAAM,oBAAoB,KAAK,CAAA;AAEtC,eAAO,MAAM,iBAAiB,IAAI,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const/index.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/const/index.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\nexport const LOOP_COUNT = 2\n\nexport const TAP_THRESHOLD = 8\n\nexport const CROSS_AXIS_THRESHOLD = 20\n\nexport const GESTURE_THRESHOLD = 8 // Slop area in pixels\n"],"names":["LOOP_COUNT","TAP_THRESHOLD","CROSS_AXIS_THRESHOLD","GESTURE_THRESHOLD"],"mappings":"AAIO,MAAMA,aAAa;AAEnB,MAAMC,gBAAgB;AAEtB,MAAMC,uBAAuB;AAE7B,MAAMC,oBAAoB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAnimate.d.ts","sourceRoot":"","sources":["../../src/hooks/useAnimate.ts"],"names":[],"mappings":"AAoDA,wBAAgB,UAAU;;wBASZ,MAAM,YACN,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,eACvB,MAAM,IAAI;EAgB1B"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useMainThreadRef } from "@lynx-js/react";
|
|
2
|
+
function animateInner(duration, onUpdate, onFinished) {
|
|
3
|
+
'main thread';
|
|
4
|
+
let startTs = 0;
|
|
5
|
+
let rafId = 0;
|
|
6
|
+
function tick(ts) {
|
|
7
|
+
const progress = Math.max(Math.min((ts - startTs) * 100 / duration, 100), 0);
|
|
8
|
+
onUpdate(progress);
|
|
9
|
+
}
|
|
10
|
+
function updateRafId(id) {
|
|
11
|
+
rafId = id;
|
|
12
|
+
}
|
|
13
|
+
function step(ts) {
|
|
14
|
+
if (!startTs) startTs = Number(ts);
|
|
15
|
+
if (ts - startTs <= duration + 100) {
|
|
16
|
+
tick(ts);
|
|
17
|
+
updateRafId(requestAnimationFrame(step));
|
|
18
|
+
} else onFinished?.();
|
|
19
|
+
}
|
|
20
|
+
updateRafId(requestAnimationFrame(step));
|
|
21
|
+
function cancel() {
|
|
22
|
+
cancelAnimationFrame(rafId);
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
cancel
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function useAnimate() {
|
|
29
|
+
const lastCancelRef = useMainThreadRef();
|
|
30
|
+
function cancel() {
|
|
31
|
+
'main thread';
|
|
32
|
+
lastCancelRef.current?.();
|
|
33
|
+
}
|
|
34
|
+
function animate(duration, onUpdate, onFinished) {
|
|
35
|
+
'main thread';
|
|
36
|
+
cancel();
|
|
37
|
+
const { cancel: innerCancel } = animateInner(duration, onUpdate, onFinished);
|
|
38
|
+
lastCancelRef.current = innerCancel;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
cancel,
|
|
42
|
+
animate
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export { useAnimate };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=useAnimate.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks/useAnimate.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/hooks/useAnimate.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\nfunction animateInner(\n duration: number,\n onUpdate: (progress: number) => void,\n onFinished?: () => void,\n) {\n 'main thread'\n let startTs = 0\n let rafId = 0\n\n function tick(ts: number) {\n const progress = Math.max(\n Math.min(((ts - startTs) * 100) / duration, 100),\n 0,\n )\n\n onUpdate(progress)\n }\n\n function updateRafId(id: number) {\n rafId = id\n }\n\n function step(ts: number) {\n if (!startTs) {\n startTs = Number(ts)\n }\n // make sure progress can reach 100%\n if (ts - startTs <= duration + 100) {\n tick(ts)\n updateRafId(requestAnimationFrame(step))\n } else {\n onFinished?.()\n }\n }\n\n updateRafId(requestAnimationFrame(step))\n\n function cancel() {\n cancelAnimationFrame(rafId)\n }\n\n return {\n cancel,\n }\n}\n\nexport function useAnimate() {\n const lastCancelRef = useMainThreadRef<() => void>()\n\n function cancel() {\n 'main thread'\n lastCancelRef.current?.()\n }\n\n function animate(\n duration: number,\n onUpdate: (progress: number) => void,\n onFinished?: () => void,\n ) {\n 'main thread'\n cancel()\n const { cancel: innerCancel } = animateInner(\n duration,\n onUpdate,\n onFinished,\n )\n lastCancelRef.current = innerCancel\n }\n\n return {\n cancel,\n animate,\n }\n}\n"],"names":["animateInner","duration","onUpdate","onFinished","startTs","rafId","tick","ts","progress","Math","updateRafId","id","step","Number","requestAnimationFrame","cancel","cancelAnimationFrame","useAnimate","lastCancelRef","useMainThreadRef","animate","innerCancel"],"mappings":";AAMA,SAASA,aACPC,QAAgB,EAChBC,QAAoC,EACpCC,UAAuB;IAEvB;IACA,IAAIC,UAAU;IACd,IAAIC,QAAQ;IAEZ,SAASC,KAAKC,EAAU;QACtB,MAAMC,WAAWC,KAAK,GAAG,CACvBA,KAAK,GAAG,CAAGF,AAAAA,CAAAA,KAAKH,OAAM,IAAK,MAAOH,UAAU,MAC5C;QAGFC,SAASM;IACX;IAEA,SAASE,YAAYC,EAAU;QAC7BN,QAAQM;IACV;IAEA,SAASC,KAAKL,EAAU;QACtB,IAAI,CAACH,SACHA,UAAUS,OAAON;QAGnB,IAAIA,KAAKH,WAAWH,WAAW,KAAK;YAClCK,KAAKC;YACLG,YAAYI,sBAAsBF;QACpC,OACET;IAEJ;IAEAO,YAAYI,sBAAsBF;IAElC,SAASG;QACPC,qBAAqBX;IACvB;IAEA,OAAO;QACLU;IACF;AACF;AAEO,SAASE;IACd,MAAMC,gBAAgBC;IAEtB,SAASJ;QACP;QACAG,cAAc,OAAO;IACvB;IAEA,SAASE,QACPnB,QAAgB,EAChBC,QAAoC,EACpCC,UAAuB;QAEvB;QACAY;QACA,MAAM,EAAE,QAAQM,WAAW,EAAE,GAAGrB,aAC9BC,UACAC,UACAC;QAEFe,cAAc,OAAO,GAAGG;IAC1B;IAEA,OAAO;QACLN;QACAK;IACF;AACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface IAutoPlay {
|
|
2
|
+
autoPlay: boolean;
|
|
3
|
+
duration: number;
|
|
4
|
+
dataCount: number;
|
|
5
|
+
autoPlayInterval: number;
|
|
6
|
+
prevMT: () => void;
|
|
7
|
+
nextMT: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function useAutoplay({ autoPlay, autoPlayInterval, nextMT, duration, }: IAutoPlay): {
|
|
10
|
+
pause: () => void;
|
|
11
|
+
start: () => void;
|
|
12
|
+
pauseMT: () => void;
|
|
13
|
+
startMT: () => void;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=useAutoPlay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAutoPlay.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoPlay.ts"],"names":[],"mappings":"AAaA,UAAU,SAAS;IACjB,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE,MAAM,CAAA;IACxB,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB;AAED,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,gBAAgB,EAChB,MAAM,EACN,QAAQ,GACT,EAAE,SAAS;;;;;EAmEX"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { runOnMainThread, useEffect, useMainThreadRef, useRef } from "@lynx-js/react";
|
|
2
|
+
import { useMemoizedFn } from "@lynx-js/lynx-ui-common";
|
|
3
|
+
function useAutoplay({ autoPlay, autoPlayInterval, nextMT, duration }) {
|
|
4
|
+
const stoppedRef = useRef(false);
|
|
5
|
+
const timerMTRef = useMainThreadRef(0);
|
|
6
|
+
const stoppedMTRef = useMainThreadRef(false);
|
|
7
|
+
const autoPlayMTRef = useMainThreadRef(autoPlay);
|
|
8
|
+
function playMT() {
|
|
9
|
+
'main thread';
|
|
10
|
+
if (stoppedRef.current || !autoPlayMTRef.current) return;
|
|
11
|
+
timerMTRef.current && clearTimeout(timerMTRef.current);
|
|
12
|
+
timerMTRef.current = setTimeout(()=>{
|
|
13
|
+
nextMT();
|
|
14
|
+
playMT();
|
|
15
|
+
}, autoPlayInterval + duration);
|
|
16
|
+
}
|
|
17
|
+
function pauseMT() {
|
|
18
|
+
'main thread';
|
|
19
|
+
if (!autoPlayMTRef.current) return;
|
|
20
|
+
timerMTRef.current && clearTimeout(timerMTRef.current);
|
|
21
|
+
stoppedMTRef.current = true;
|
|
22
|
+
}
|
|
23
|
+
function startMT() {
|
|
24
|
+
'main thread';
|
|
25
|
+
if (!autoPlayMTRef.current) return;
|
|
26
|
+
stoppedMTRef.current = false;
|
|
27
|
+
playMT();
|
|
28
|
+
}
|
|
29
|
+
function setAutoPlayRef(autoPlayValue) {
|
|
30
|
+
'main thread';
|
|
31
|
+
autoPlayMTRef.current = autoPlayValue;
|
|
32
|
+
}
|
|
33
|
+
const start = useMemoizedFn(()=>{
|
|
34
|
+
runOnMainThread(startMT)();
|
|
35
|
+
});
|
|
36
|
+
const pause = useMemoizedFn(()=>{
|
|
37
|
+
runOnMainThread(pauseMT)();
|
|
38
|
+
});
|
|
39
|
+
useEffect(()=>{
|
|
40
|
+
runOnMainThread(setAutoPlayRef)(autoPlay);
|
|
41
|
+
if (autoPlay) start();
|
|
42
|
+
else pause();
|
|
43
|
+
return pause;
|
|
44
|
+
}, [
|
|
45
|
+
start,
|
|
46
|
+
pause,
|
|
47
|
+
autoPlay
|
|
48
|
+
]);
|
|
49
|
+
return {
|
|
50
|
+
pause,
|
|
51
|
+
start,
|
|
52
|
+
pauseMT,
|
|
53
|
+
startMT
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export { useAutoplay };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=useAutoPlay.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks/useAutoPlay.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/hooks/useAutoPlay.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 {\n runOnMainThread,\n useEffect,\n useMainThreadRef,\n useRef,\n} from '@lynx-js/react'\n\nimport { useMemoizedFn } from '@lynx-js/lynx-ui-common'\n\ninterface IAutoPlay {\n autoPlay: boolean\n duration: number\n dataCount: number\n autoPlayInterval: number\n prevMT: () => void\n nextMT: () => void\n}\n\nexport function useAutoplay({\n autoPlay,\n autoPlayInterval,\n nextMT,\n duration,\n}: IAutoPlay) {\n const stoppedRef = useRef<boolean>(false)\n const timerMTRef = useMainThreadRef<number>(0)\n const stoppedMTRef = useMainThreadRef<boolean>(false)\n const autoPlayMTRef = useMainThreadRef<boolean>(autoPlay)\n\n function playMT() {\n 'main thread'\n if (stoppedRef.current || !autoPlayMTRef.current) {\n return\n }\n\n timerMTRef.current && clearTimeout(timerMTRef.current)\n timerMTRef.current = setTimeout(() => {\n nextMT()\n playMT()\n }, autoPlayInterval + duration) as unknown as number\n }\n\n function pauseMT() {\n 'main thread'\n if (!autoPlayMTRef.current) {\n return\n }\n timerMTRef.current && clearTimeout(timerMTRef.current)\n stoppedMTRef.current = true\n }\n\n function startMT() {\n 'main thread'\n if (!autoPlayMTRef.current) {\n return\n }\n stoppedMTRef.current = false\n playMT()\n }\n\n function setAutoPlayRef(autoPlayValue: boolean) {\n 'main thread'\n autoPlayMTRef.current = autoPlayValue\n }\n\n const start = useMemoizedFn(() => {\n runOnMainThread(startMT)()\n })\n\n const pause = useMemoizedFn(() => {\n runOnMainThread(pauseMT)()\n })\n\n useEffect(() => {\n runOnMainThread(setAutoPlayRef)(autoPlay)\n if (autoPlay) {\n start()\n } else {\n pause()\n }\n\n return pause\n }, [start, pause, autoPlay])\n\n return {\n pause,\n start,\n pauseMT,\n startMT,\n }\n}\n"],"names":["useAutoplay","autoPlay","autoPlayInterval","nextMT","duration","stoppedRef","useRef","timerMTRef","useMainThreadRef","stoppedMTRef","autoPlayMTRef","playMT","clearTimeout","setTimeout","pauseMT","startMT","setAutoPlayRef","autoPlayValue","start","useMemoizedFn","runOnMainThread","pause","useEffect"],"mappings":";;AAsBO,SAASA,YAAY,EAC1BC,QAAQ,EACRC,gBAAgB,EAChBC,MAAM,EACNC,QAAQ,EACE;IACV,MAAMC,aAAaC,OAAgB;IACnC,MAAMC,aAAaC,iBAAyB;IAC5C,MAAMC,eAAeD,iBAA0B;IAC/C,MAAME,gBAAgBF,iBAA0BP;IAEhD,SAASU;QACP;QACA,IAAIN,WAAW,OAAO,IAAI,CAACK,cAAc,OAAO,EAC9C;QAGFH,WAAW,OAAO,IAAIK,aAAaL,WAAW,OAAO;QACrDA,WAAW,OAAO,GAAGM,WAAW;YAC9BV;YACAQ;QACF,GAAGT,mBAAmBE;IACxB;IAEA,SAASU;QACP;QACA,IAAI,CAACJ,cAAc,OAAO,EACxB;QAEFH,WAAW,OAAO,IAAIK,aAAaL,WAAW,OAAO;QACrDE,aAAa,OAAO,GAAG;IACzB;IAEA,SAASM;QACP;QACA,IAAI,CAACL,cAAc,OAAO,EACxB;QAEFD,aAAa,OAAO,GAAG;QACvBE;IACF;IAEA,SAASK,eAAeC,aAAsB;QAC5C;QACAP,cAAc,OAAO,GAAGO;IAC1B;IAEA,MAAMC,QAAQC,cAAc;QAC1BC,gBAAgBL;IAClB;IAEA,MAAMM,QAAQF,cAAc;QAC1BC,gBAAgBN;IAClB;IAEAQ,UAAU;QACRF,gBAAgBJ,gBAAgBf;QAChC,IAAIA,UACFiB;aAEAG;QAGF,OAAOA;IACT,GAAG;QAACH;QAAOG;QAAOpB;KAAS;IAE3B,OAAO;QACLoB;QACAH;QACAJ;QACAC;IACF;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MainThread } from '@lynx-js/types';
|
|
2
|
+
import type { SwiperProps } from '../types';
|
|
3
|
+
export declare function useAxisLock({ consumeSlideEvent, experimentalHorizontalSwipeOnly, }: {
|
|
4
|
+
consumeSlideEvent: NonNullable<SwiperProps<unknown>['consumeSlideEvent']>;
|
|
5
|
+
experimentalHorizontalSwipeOnly: boolean;
|
|
6
|
+
}): {
|
|
7
|
+
handleTouchStart: (event: MainThread.TouchEvent) => void;
|
|
8
|
+
handleTouchMove: (event: MainThread.TouchEvent) => boolean;
|
|
9
|
+
handleTouchEnd: () => void;
|
|
10
|
+
handleVelocity: () => boolean;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=useAxisLock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAxisLock.d.ts","sourceRoot":"","sources":["../../src/hooks/useAxisLock.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAGhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAa3C,wBAAgB,WAAW,CAAC,EAC1B,iBAAiB,EACjB,+BAA+B,GAChC,EAAE;IACD,iBAAiB,EAAE,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAA;IACzE,+BAA+B,EAAE,OAAO,CAAA;CACzC;8BAMkC,UAAU,CAAC,UAAU;6BAWtB,UAAU,CAAC,UAAU;;;EA8CtD"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useMainThreadRef } from "@lynx-js/react";
|
|
2
|
+
import { GESTURE_THRESHOLD } from "../const/index.jsx";
|
|
3
|
+
function isAngleInRanges(angle, ranges) {
|
|
4
|
+
'main thread';
|
|
5
|
+
return ranges.some(([start, end])=>{
|
|
6
|
+
if (start <= end) return angle >= start && angle <= end;
|
|
7
|
+
return angle >= start || angle <= end;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function useAxisLock({ consumeSlideEvent, experimentalHorizontalSwipeOnly }) {
|
|
11
|
+
const gestureLockedRef = useMainThreadRef(false);
|
|
12
|
+
const isMainAxisLockedRef = useMainThreadRef(false);
|
|
13
|
+
const touchStartRef = useMainThreadRef(0);
|
|
14
|
+
const touchStartCrossAxisRef = useMainThreadRef(0);
|
|
15
|
+
function handleTouchStart(event) {
|
|
16
|
+
'main thread';
|
|
17
|
+
touchStartRef.current = event.detail.x;
|
|
18
|
+
touchStartCrossAxisRef.current = event.detail.y;
|
|
19
|
+
gestureLockedRef.current = false;
|
|
20
|
+
isMainAxisLockedRef.current = false;
|
|
21
|
+
}
|
|
22
|
+
function handleTouchMove(event) {
|
|
23
|
+
'main thread';
|
|
24
|
+
if (!experimentalHorizontalSwipeOnly) return false;
|
|
25
|
+
const deltaX = event.detail.x - touchStartRef.current;
|
|
26
|
+
const deltaY = event.detail.y - touchStartCrossAxisRef.current;
|
|
27
|
+
const displacement = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
28
|
+
if (!gestureLockedRef.current && displacement > GESTURE_THRESHOLD) {
|
|
29
|
+
const angle = 180 * Math.atan2(deltaY, deltaX) / Math.PI;
|
|
30
|
+
if (isAngleInRanges(angle, consumeSlideEvent)) {
|
|
31
|
+
gestureLockedRef.current = true;
|
|
32
|
+
isMainAxisLockedRef.current = false;
|
|
33
|
+
} else {
|
|
34
|
+
gestureLockedRef.current = true;
|
|
35
|
+
isMainAxisLockedRef.current = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return isMainAxisLockedRef.current;
|
|
39
|
+
}
|
|
40
|
+
function handleVelocity() {
|
|
41
|
+
'main thread';
|
|
42
|
+
return isMainAxisLockedRef.current;
|
|
43
|
+
}
|
|
44
|
+
function handleTouchEnd() {
|
|
45
|
+
'main thread';
|
|
46
|
+
gestureLockedRef.current = false;
|
|
47
|
+
isMainAxisLockedRef.current = false;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
handleTouchStart,
|
|
51
|
+
handleTouchMove,
|
|
52
|
+
handleTouchEnd,
|
|
53
|
+
handleVelocity
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export { useAxisLock };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=useAxisLock.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks/useAxisLock.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/hooks/useAxisLock.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 { GESTURE_THRESHOLD } from '../const'\nimport type { SwiperProps } from '../types'\n\nfunction isAngleInRanges(angle: number, ranges: [number, number][]) {\n 'main thread'\n return ranges.some(([start, end]) => {\n if (start <= end) {\n return angle >= start && angle <= end\n } else {\n return angle >= start || angle <= end // Handles wrap-around cases like [-180, -135] or [135, 180]\n }\n })\n}\n\nexport function useAxisLock({\n consumeSlideEvent,\n experimentalHorizontalSwipeOnly,\n}: {\n consumeSlideEvent: NonNullable<SwiperProps<unknown>['consumeSlideEvent']>\n experimentalHorizontalSwipeOnly: boolean\n}) {\n const gestureLockedRef = useMainThreadRef<boolean>(false)\n const isMainAxisLockedRef = useMainThreadRef<boolean>(false)\n const touchStartRef = useMainThreadRef<number>(0)\n const touchStartCrossAxisRef = useMainThreadRef<number>(0)\n\n function handleTouchStart(event: MainThread.TouchEvent) {\n 'main thread'\n\n touchStartRef.current = event.detail.x\n\n touchStartCrossAxisRef.current = event.detail.y\n\n gestureLockedRef.current = false\n isMainAxisLockedRef.current = false\n }\n\n function handleTouchMove(event: MainThread.TouchEvent) {\n 'main thread'\n\n if (!experimentalHorizontalSwipeOnly) {\n return false\n }\n\n const deltaX = event.detail.x - touchStartRef.current\n\n const deltaY = event.detail.y - touchStartCrossAxisRef.current\n\n // Calculate total displacement (distance)\n const displacement = Math.sqrt(deltaX * deltaX + deltaY * deltaY)\n\n if (!gestureLockedRef.current && displacement > GESTURE_THRESHOLD) {\n const angle = Math.atan2(deltaY, deltaX) * 180 / Math.PI\n\n if (isAngleInRanges(angle, consumeSlideEvent)) {\n gestureLockedRef.current = true\n isMainAxisLockedRef.current = false\n } else {\n gestureLockedRef.current = true\n isMainAxisLockedRef.current = true\n }\n }\n\n return isMainAxisLockedRef.current\n }\n\n function handleVelocity() {\n 'main thread'\n return isMainAxisLockedRef.current\n }\n\n function handleTouchEnd() {\n 'main thread'\n gestureLockedRef.current = false\n isMainAxisLockedRef.current = false\n }\n\n return {\n handleTouchStart,\n handleTouchMove,\n handleTouchEnd,\n handleVelocity,\n }\n}\n"],"names":["isAngleInRanges","angle","ranges","start","end","useAxisLock","consumeSlideEvent","experimentalHorizontalSwipeOnly","gestureLockedRef","useMainThreadRef","isMainAxisLockedRef","touchStartRef","touchStartCrossAxisRef","handleTouchStart","event","handleTouchMove","deltaX","deltaY","displacement","Math","GESTURE_THRESHOLD","handleVelocity","handleTouchEnd"],"mappings":";;AAWA,SAASA,gBAAgBC,KAAa,EAAEC,MAA0B;IAChE;IACA,OAAOA,OAAO,IAAI,CAAC,CAAC,CAACC,OAAOC,IAAI;QAC9B,IAAID,SAASC,KACX,OAAOH,SAASE,SAASF,SAASG;QAElC,OAAOH,SAASE,SAASF,SAASG;IAEtC;AACF;AAEO,SAASC,YAAY,EAC1BC,iBAAiB,EACjBC,+BAA+B,EAIhC;IACC,MAAMC,mBAAmBC,iBAA0B;IACnD,MAAMC,sBAAsBD,iBAA0B;IACtD,MAAME,gBAAgBF,iBAAyB;IAC/C,MAAMG,yBAAyBH,iBAAyB;IAExD,SAASI,iBAAiBC,KAA4B;QACpD;QAEAH,cAAc,OAAO,GAAGG,MAAM,MAAM,CAAC,CAAC;QAEtCF,uBAAuB,OAAO,GAAGE,MAAM,MAAM,CAAC,CAAC;QAE/CN,iBAAiB,OAAO,GAAG;QAC3BE,oBAAoB,OAAO,GAAG;IAChC;IAEA,SAASK,gBAAgBD,KAA4B;QACnD;QAEA,IAAI,CAACP,iCACH,OAAO;QAGT,MAAMS,SAASF,MAAM,MAAM,CAAC,CAAC,GAAGH,cAAc,OAAO;QAErD,MAAMM,SAASH,MAAM,MAAM,CAAC,CAAC,GAAGF,uBAAuB,OAAO;QAG9D,MAAMM,eAAeC,KAAK,IAAI,CAACH,SAASA,SAASC,SAASA;QAE1D,IAAI,CAACT,iBAAiB,OAAO,IAAIU,eAAeE,mBAAmB;YACjE,MAAMnB,QAAQkB,AAA6B,MAA7BA,KAAK,KAAK,CAACF,QAAQD,UAAgBG,KAAK,EAAE;YAExD,IAAInB,gBAAgBC,OAAOK,oBAAoB;gBAC7CE,iBAAiB,OAAO,GAAG;gBAC3BE,oBAAoB,OAAO,GAAG;YAChC,OAAO;gBACLF,iBAAiB,OAAO,GAAG;gBAC3BE,oBAAoB,OAAO,GAAG;YAChC;QACF;QAEA,OAAOA,oBAAoB,OAAO;IACpC;IAEA,SAASW;QACP;QACA,OAAOX,oBAAoB,OAAO;IACpC;IAEA,SAASY;QACP;QACAd,iBAAiB,OAAO,GAAG;QAC3BE,oBAAoB,OAAO,GAAG;IAChC;IAEA,OAAO;QACLG;QACAE;QACAO;QACAD;IACF;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BounceConfig } from '../types';
|
|
2
|
+
declare function useBounceConfig(bounceConfig?: BounceConfig): {
|
|
3
|
+
enableBounce: boolean;
|
|
4
|
+
startBounceItem: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | undefined;
|
|
5
|
+
endBounceItem: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | undefined;
|
|
6
|
+
startBounceItemWidth: number;
|
|
7
|
+
endBounceItemWidth: number;
|
|
8
|
+
onStartBounceItemBounce: ((bounceParams: import("../types").onBounceParams) => void) | undefined;
|
|
9
|
+
onEndBounceItemBounce: ((bounceParams: import("../types").onBounceParams) => void) | undefined;
|
|
10
|
+
};
|
|
11
|
+
export { useBounceConfig };
|
|
12
|
+
//# sourceMappingURL=useBounceConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBounceConfig.d.ts","sourceRoot":"","sources":["../../src/hooks/useBounceConfig.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAE5C,iBAAS,eAAe,CAAC,YAAY,CAAC,EAAE,YAAY;;;;;;;;EAoBnD;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function useBounceConfig(bounceConfig) {
|
|
2
|
+
const { startBounceItem, endBounceItem, enable = false, startBounceItemWidth = 50, endBounceItemWidth = 50, onStartBounceItemBounce, onEndBounceItemBounce } = bounceConfig ?? {};
|
|
3
|
+
return {
|
|
4
|
+
enableBounce: enable,
|
|
5
|
+
startBounceItem,
|
|
6
|
+
endBounceItem,
|
|
7
|
+
startBounceItemWidth,
|
|
8
|
+
endBounceItemWidth,
|
|
9
|
+
onStartBounceItemBounce,
|
|
10
|
+
onEndBounceItemBounce
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export { useBounceConfig };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=useBounceConfig.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks/useBounceConfig.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/hooks/useBounceConfig.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 type { BounceConfig } from '../types'\n\nfunction useBounceConfig(bounceConfig?: BounceConfig) {\n const {\n startBounceItem,\n endBounceItem,\n enable = false,\n startBounceItemWidth = 50,\n endBounceItemWidth = 50,\n onStartBounceItemBounce,\n onEndBounceItemBounce,\n } = bounceConfig ?? {}\n\n return {\n enableBounce: enable,\n startBounceItem,\n endBounceItem,\n startBounceItemWidth,\n endBounceItemWidth,\n onStartBounceItemBounce,\n onEndBounceItemBounce,\n }\n}\n\nexport { useBounceConfig }\n"],"names":["useBounceConfig","bounceConfig","startBounceItem","endBounceItem","enable","startBounceItemWidth","endBounceItemWidth","onStartBounceItemBounce","onEndBounceItemBounce"],"mappings":"AAMA,SAASA,gBAAgBC,YAA2B;IAClD,MAAM,EACJC,eAAe,EACfC,aAAa,EACbC,SAAS,KAAK,EACdC,uBAAuB,EAAE,EACzBC,qBAAqB,EAAE,EACvBC,uBAAuB,EACvBC,qBAAqB,EACtB,GAAGP,gBAAgB,CAAC;IAErB,OAAO;QACL,cAAcG;QACdF;QACAC;QACAE;QACAC;QACAC;QACAC;IACF;AACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactElement } from '@lynx-js/react';
|
|
2
|
+
import type { CompoundModeConfig, SwiperProps } from '../types';
|
|
3
|
+
declare function useBounceView({ startBounceItem, endBounceItem, RTL, itemWidth, count, containerWidth, mode, loop, }: {
|
|
4
|
+
startBounceItem?: ReactElement;
|
|
5
|
+
endBounceItem?: ReactElement;
|
|
6
|
+
RTL: SwiperProps<unknown>['RTL'];
|
|
7
|
+
itemWidth: number;
|
|
8
|
+
containerWidth: number;
|
|
9
|
+
count: number;
|
|
10
|
+
mode: CompoundModeConfig['mode'];
|
|
11
|
+
loop: boolean;
|
|
12
|
+
}): {
|
|
13
|
+
bounceStartView: import("react").JSX.Element | null;
|
|
14
|
+
bounceEndView: import("react").JSX.Element | null;
|
|
15
|
+
};
|
|
16
|
+
export { useBounceView };
|
|
17
|
+
//# sourceMappingURL=useBounceView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBounceView.d.ts","sourceRoot":"","sources":["../../src/hooks/useBounceView.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAE/D,iBAAS,aAAa,CAAC,EACrB,eAAe,EACf,aAAa,EACb,GAAG,EACH,SAAS,EACT,KAAK,EACL,cAAc,EACd,IAAI,EACJ,IAAI,GACL,EAAE;IACD,eAAe,CAAC,EAAE,YAAY,CAAA;IAC9B,aAAa,CAAC,EAAE,YAAY,CAAA;IAC5B,GAAG,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAA;IAChC,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAA;IAChC,IAAI,EAAE,OAAO,CAAA;CACd;;;EAqBA;AAED,OAAO,EAAE,aAAa,EAAE,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function useBounceView({ startBounceItem, endBounceItem, RTL, itemWidth, count, containerWidth, mode, loop }) {
|
|
2
|
+
const bounceStartView = startBounceItem ? <view class={RTL ? 'bounce-start-item-RTL' : 'bounce-start-item'}>
|
|
3
|
+
{startBounceItem}
|
|
4
|
+
</view> : null;
|
|
5
|
+
const shouldShowEndBounce = 'normal' === mode && false === loop && count * itemWidth >= containerWidth;
|
|
6
|
+
const bounceEndView = endBounceItem && shouldShowEndBounce ? <view class={RTL ? 'bounce-end-item-RTL' : 'bounce-end-item'}>
|
|
7
|
+
{endBounceItem}
|
|
8
|
+
</view> : null;
|
|
9
|
+
return {
|
|
10
|
+
bounceStartView,
|
|
11
|
+
bounceEndView
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export { useBounceView };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=useBounceView.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks/useBounceView.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/hooks/useBounceView.tsx"],"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 type { ReactElement } from '@lynx-js/react'\n\nimport type { CompoundModeConfig, SwiperProps } from '../types'\n\nfunction useBounceView({\n startBounceItem,\n endBounceItem,\n RTL,\n itemWidth,\n count,\n containerWidth,\n mode,\n loop,\n}: {\n startBounceItem?: ReactElement\n endBounceItem?: ReactElement\n RTL: SwiperProps<unknown>['RTL']\n itemWidth: number\n containerWidth: number\n count: number\n mode: CompoundModeConfig['mode']\n loop: boolean\n}) {\n const bounceStartView = startBounceItem\n ? (\n <view class={RTL ? 'bounce-start-item-RTL' : 'bounce-start-item'}>\n {startBounceItem}\n </view>\n )\n : null\n\n const shouldShowEndBounce = mode === 'normal' && loop === false\n && count * itemWidth >= containerWidth\n\n const bounceEndView = endBounceItem && shouldShowEndBounce\n ? (\n <view class={RTL ? 'bounce-end-item-RTL' : 'bounce-end-item'}>\n {endBounceItem}\n </view>\n )\n : null\n\n return { bounceStartView, bounceEndView }\n}\n\nexport { useBounceView }\n"],"names":["useBounceView","startBounceItem","endBounceItem","RTL","itemWidth","count","containerWidth","mode","loop","bounceStartView","view","shouldShowEndBounce","bounceEndView"],"mappings":"AAQA,SAASA,cAAc,EACrBC,eAAe,EACfC,aAAa,EACbC,GAAG,EACHC,SAAS,EACTC,KAAK,EACLC,cAAc,EACdC,IAAI,EACJC,IAAI,EAUL;IACC,MAAMC,kBAAkBR,mBAEnBS,KAAK,OAAOP,MAAM,0BAA0B,qBAAqB;QAChE,CAACF,gBAAgB;MACnB,EAAES,QAEF;IAEJ,MAAMC,sBAAsBJ,AAAS,aAATA,QAAqBC,AAAS,UAATA,QAC5CH,QAAQD,aAAaE;IAE1B,MAAMM,gBAAgBV,iBAAiBS,uBAElCD,KAAK,OAAOP,MAAM,wBAAwB,mBAAmB;QAC5D,CAACD,cAAc;MACjB,EAAEQ,QAEF;IAEJ,OAAO;QAAED;QAAiBG;IAAc;AAC1C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SwipeDirection } from '../types';
|
|
2
|
+
import type { CompoundModeConfig, OffsetLimitResult, SwiperProps } from '../types';
|
|
3
|
+
interface UseChangeOpts extends Pick<SwiperProps<unknown>, 'containerWidth' | 'onSwipeStart' | 'onSwipeStop'> {
|
|
4
|
+
onChange?: (offset: number) => void;
|
|
5
|
+
size: number;
|
|
6
|
+
spaceBetween: number;
|
|
7
|
+
dataCount: number;
|
|
8
|
+
offsetLimit: OffsetLimitResult;
|
|
9
|
+
'main-thread:onOffsetChange'?: (offset: number) => void;
|
|
10
|
+
modeConfig: CompoundModeConfig;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* This hook handles change related things
|
|
14
|
+
* Including `onChange` and `main-thread:onOffsetChange`
|
|
15
|
+
*/
|
|
16
|
+
export declare function useChange({ onChange, size: _size, spaceBetween, dataCount, onSwipeStart, onSwipeStop, offsetLimit, 'main-thread:onOffsetChange': onOffsetChange, }: UseChangeOpts): {
|
|
17
|
+
setChangeOffset: (offset: number, direction: SwipeDirection) => void;
|
|
18
|
+
setChangeSwipeStartMT: () => void;
|
|
19
|
+
setChangeSwipeStopMT: () => void;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=useChange.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChange.d.ts","sourceRoot":"","sources":["../../src/hooks/useChange.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACZ,MAAM,UAAU,CAAA;AAGjB,UAAU,aAAc,SACtB,IAAI,CACF,WAAW,CAAC,OAAO,CAAC,EACpB,gBAAgB,GAAG,cAAc,GAAG,aAAa,CAClD;IAED,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IACnC,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,iBAAiB,CAAA;IAC9B,4BAA4B,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IACvD,UAAU,EAAE,kBAAkB,CAAA;CAC/B;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,IAAI,EAAE,KAAK,EACX,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,WAAW,EACX,WAAW,EACX,4BAA4B,EAAE,cAAc,GAC7C,EAAE,aAAa;8BAkCmB,MAAM,aAAa,cAAc;;;EAsDnE"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { runOnBackground, useMainThreadRef } from "@lynx-js/react";
|
|
2
|
+
import { SwipeDirection } from "../types/index.jsx";
|
|
3
|
+
import { eqOrGtMT, eqOrLtMT, fixPrecisionMT, safeEqualMT } from "../utils/index.jsx";
|
|
4
|
+
function useChange({ onChange, size: _size, spaceBetween, dataCount, onSwipeStart, onSwipeStop, offsetLimit, 'main-thread:onOffsetChange': onOffsetChange }) {
|
|
5
|
+
const prevIndexMTRef = useMainThreadRef(0);
|
|
6
|
+
const prevOffsetMTRef = useMainThreadRef(0);
|
|
7
|
+
const currentIndexMTRef = useMainThreadRef(0);
|
|
8
|
+
const size = _size + spaceBetween;
|
|
9
|
+
function callOnChange(currentIndex) {
|
|
10
|
+
if (onChange) onChange(currentIndex);
|
|
11
|
+
}
|
|
12
|
+
function callOnSwipeStart(currentIndex) {
|
|
13
|
+
if (onSwipeStart) onSwipeStart(currentIndex);
|
|
14
|
+
}
|
|
15
|
+
function callOnSwipeStop(currentIndex) {
|
|
16
|
+
if (onSwipeStop) onSwipeStop(currentIndex);
|
|
17
|
+
}
|
|
18
|
+
function setChangeSwipeStopMT() {
|
|
19
|
+
'main thread';
|
|
20
|
+
runOnBackground(callOnSwipeStop)(currentIndexMTRef.current);
|
|
21
|
+
}
|
|
22
|
+
function setChangeSwipeStartMT() {
|
|
23
|
+
'main thread';
|
|
24
|
+
runOnBackground(callOnSwipeStart)(currentIndexMTRef.current);
|
|
25
|
+
}
|
|
26
|
+
function setChangeOffset(offset, direction) {
|
|
27
|
+
'main thread';
|
|
28
|
+
function mod(n, m) {
|
|
29
|
+
return (n % m + m) % m;
|
|
30
|
+
}
|
|
31
|
+
const rawIndex = fixPrecisionMT(-offset / size);
|
|
32
|
+
let currentIndex;
|
|
33
|
+
currentIndex = direction === SwipeDirection.NORMAL ? Math.floor(rawIndex) : direction === SwipeDirection.REVERT ? Math.ceil(rawIndex) : currentIndexMTRef.current;
|
|
34
|
+
currentIndex = mod(currentIndex, dataCount || Number.MAX_SAFE_INTEGER);
|
|
35
|
+
if (!safeEqualMT(offsetLimit.startLimit, 0) && eqOrGtMT(offset, -offsetLimit.startLimit)) currentIndex = 0;
|
|
36
|
+
else if (!safeEqualMT(offsetLimit.endLimit, 0) && eqOrLtMT(offset, -size * (dataCount - 1) + offsetLimit.endLimit)) currentIndex = dataCount - 1;
|
|
37
|
+
currentIndexMTRef.current = currentIndex;
|
|
38
|
+
if (onOffsetChange && !safeEqualMT(offset, prevOffsetMTRef.current)) onOffsetChange(offset);
|
|
39
|
+
if (!safeEqualMT(prevIndexMTRef.current, currentIndex)) {
|
|
40
|
+
runOnBackground(callOnChange)(currentIndex);
|
|
41
|
+
prevIndexMTRef.current = currentIndex;
|
|
42
|
+
}
|
|
43
|
+
prevOffsetMTRef.current = offset;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
setChangeOffset,
|
|
47
|
+
setChangeSwipeStartMT,
|
|
48
|
+
setChangeSwipeStopMT
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export { useChange };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=useChange.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks/useChange.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/hooks/useChange.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 { runOnBackground, useMainThreadRef } from '@lynx-js/react'\n\nimport { SwipeDirection } from '../types'\nimport type {\n CompoundModeConfig,\n OffsetLimitResult,\n SwiperProps,\n} from '../types'\nimport { eqOrGtMT, eqOrLtMT, fixPrecisionMT, safeEqualMT } from '../utils'\n\ninterface UseChangeOpts extends\n Pick<\n SwiperProps<unknown>,\n 'containerWidth' | 'onSwipeStart' | 'onSwipeStop'\n >\n{\n onChange?: (offset: number) => void\n size: number\n spaceBetween: number\n dataCount: number\n offsetLimit: OffsetLimitResult\n 'main-thread:onOffsetChange'?: (offset: number) => void\n modeConfig: CompoundModeConfig\n}\n\n/**\n * This hook handles change related things\n * Including `onChange` and `main-thread:onOffsetChange`\n */\nexport function useChange({\n onChange,\n size: _size,\n spaceBetween,\n dataCount,\n onSwipeStart,\n onSwipeStop,\n offsetLimit,\n 'main-thread:onOffsetChange': onOffsetChange,\n}: UseChangeOpts) {\n const prevIndexMTRef = useMainThreadRef<number>(0)\n const prevOffsetMTRef = useMainThreadRef<number>(0)\n const currentIndexMTRef = useMainThreadRef<number>(0)\n\n const size = _size + spaceBetween\n\n function callOnChange(currentIndex: number) {\n if (onChange) {\n onChange(currentIndex)\n }\n }\n\n function callOnSwipeStart(currentIndex: number) {\n if (onSwipeStart) {\n onSwipeStart(currentIndex)\n }\n }\n function callOnSwipeStop(currentIndex: number) {\n if (onSwipeStop) {\n onSwipeStop(currentIndex)\n }\n }\n\n function setChangeSwipeStopMT() {\n 'main thread'\n runOnBackground(callOnSwipeStop)(currentIndexMTRef.current)\n }\n\n function setChangeSwipeStartMT() {\n 'main thread'\n runOnBackground(callOnSwipeStart)(currentIndexMTRef.current)\n }\n\n function setChangeOffset(offset: number, direction: SwipeDirection) {\n 'main thread'\n\n function mod(n: number, m: number) {\n return ((n % m) + m) % m\n }\n\n // Calculate raw index with proper sign handling\n const rawIndex = fixPrecisionMT(-offset / size)\n let currentIndex: number\n\n if (direction === SwipeDirection.NORMAL) {\n currentIndex = Math.floor(rawIndex)\n } else if (direction === SwipeDirection.REVERT) {\n currentIndex = Math.ceil(rawIndex)\n } else {\n currentIndex = currentIndexMTRef.current\n }\n\n currentIndex = mod(currentIndex, dataCount || Number.MAX_SAFE_INTEGER)\n\n // If offsetLimit is applied, swiper could not scroll to the end.\n // In this case, when it can no longer scroll, set index to 0 or max\n // offsetLimit is always 0 in loop mode, so code below will only work when loop is false\n if (\n !safeEqualMT(offsetLimit.startLimit, 0)\n && eqOrGtMT(offset, -offsetLimit.startLimit)\n ) {\n currentIndex = 0\n } else if (\n !safeEqualMT(offsetLimit.endLimit, 0)\n && eqOrLtMT(offset, -size * (dataCount - 1) + offsetLimit.endLimit)\n ) {\n currentIndex = dataCount - 1\n }\n\n currentIndexMTRef.current = currentIndex\n if (onOffsetChange && !safeEqualMT(offset, prevOffsetMTRef.current)) {\n onOffsetChange(offset)\n }\n\n if (!safeEqualMT(prevIndexMTRef.current, currentIndex)) {\n runOnBackground(callOnChange)(currentIndex)\n prevIndexMTRef.current = currentIndex\n }\n\n prevOffsetMTRef.current = offset\n }\n\n return {\n setChangeOffset,\n setChangeSwipeStartMT,\n setChangeSwipeStopMT,\n }\n}\n"],"names":["useChange","onChange","_size","spaceBetween","dataCount","onSwipeStart","onSwipeStop","offsetLimit","onOffsetChange","prevIndexMTRef","useMainThreadRef","prevOffsetMTRef","currentIndexMTRef","size","callOnChange","currentIndex","callOnSwipeStart","callOnSwipeStop","setChangeSwipeStopMT","runOnBackground","setChangeSwipeStartMT","setChangeOffset","offset","direction","mod","n","m","rawIndex","fixPrecisionMT","SwipeDirection","Math","Number","safeEqualMT","eqOrGtMT","eqOrLtMT"],"mappings":";;;AAiCO,SAASA,UAAU,EACxBC,QAAQ,EACR,MAAMC,KAAK,EACXC,YAAY,EACZC,SAAS,EACTC,YAAY,EACZC,WAAW,EACXC,WAAW,EACX,8BAA8BC,cAAc,EAC9B;IACd,MAAMC,iBAAiBC,iBAAyB;IAChD,MAAMC,kBAAkBD,iBAAyB;IACjD,MAAME,oBAAoBF,iBAAyB;IAEnD,MAAMG,OAAOX,QAAQC;IAErB,SAASW,aAAaC,YAAoB;QACxC,IAAId,UACFA,SAASc;IAEb;IAEA,SAASC,iBAAiBD,YAAoB;QAC5C,IAAIV,cACFA,aAAaU;IAEjB;IACA,SAASE,gBAAgBF,YAAoB;QAC3C,IAAIT,aACFA,YAAYS;IAEhB;IAEA,SAASG;QACP;QACAC,gBAAgBF,iBAAiBL,kBAAkB,OAAO;IAC5D;IAEA,SAASQ;QACP;QACAD,gBAAgBH,kBAAkBJ,kBAAkB,OAAO;IAC7D;IAEA,SAASS,gBAAgBC,MAAc,EAAEC,SAAyB;QAChE;QAEA,SAASC,IAAIC,CAAS,EAAEC,CAAS;YAC/B,OAAQ,AAACD,CAAAA,IAAIC,IAAKA,CAAAA,IAAKA;QACzB;QAGA,MAAMC,WAAWC,eAAe,CAACN,SAAST;QAC1C,IAAIE;QAGFA,eADEQ,cAAcM,eAAe,MAAM,GACtBC,KAAK,KAAK,CAACH,YACjBJ,cAAcM,eAAe,MAAM,GAC7BC,KAAK,IAAI,CAACH,YAEVf,kBAAkB,OAAO;QAG1CG,eAAeS,IAAIT,cAAcX,aAAa2B,OAAO,gBAAgB;QAKrE,IACE,CAACC,YAAYzB,YAAY,UAAU,EAAE,MAClC0B,SAASX,QAAQ,CAACf,YAAY,UAAU,GAE3CQ,eAAe;aACV,IACL,CAACiB,YAAYzB,YAAY,QAAQ,EAAE,MAChC2B,SAASZ,QAAQ,CAACT,OAAQT,CAAAA,YAAY,KAAKG,YAAY,QAAQ,GAElEQ,eAAeX,YAAY;QAG7BQ,kBAAkB,OAAO,GAAGG;QAC5B,IAAIP,kBAAkB,CAACwB,YAAYV,QAAQX,gBAAgB,OAAO,GAChEH,eAAec;QAGjB,IAAI,CAACU,YAAYvB,eAAe,OAAO,EAAEM,eAAe;YACtDI,gBAAgBL,cAAcC;YAC9BN,eAAe,OAAO,GAAGM;QAC3B;QAEAJ,gBAAgB,OAAO,GAAGW;IAC5B;IAEA,OAAO;QACLD;QACAD;QACAF;IACF;AACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MainThread } from '@lynx-js/types';
|
|
2
|
+
import { SwipeDirection } from '../types';
|
|
3
|
+
import type { SwiperProps } from '../types';
|
|
4
|
+
export declare function useDirection({ RTL }: {
|
|
5
|
+
RTL: SwiperProps<unknown>['RTL'];
|
|
6
|
+
}): {
|
|
7
|
+
handleTouchStart: (event: MainThread.TouchEvent) => void;
|
|
8
|
+
handleTouchEnd: (event: MainThread.TouchEvent) => void;
|
|
9
|
+
handleTouchMove: (event: MainThread.TouchEvent) => void;
|
|
10
|
+
overrideDirection: (direction: SwipeDirection) => void;
|
|
11
|
+
directionRef: import("@lynx-js/react").MainThreadRef<SwipeDirection>;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=useDirection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDirection.d.ts","sourceRoot":"","sources":["../../src/hooks/useDirection.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAE3C,wBAAgB,YAAY,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAA;CAAE;8BAIvC,UAAU,CAAC,UAAU;4BAmBvB,UAAU,CAAC,UAAU;6BAZpB,UAAU,CAAC,UAAU;mCAwBf,cAAc;;EAYrD"}
|