@nutui/nutui-react-taro 1.4.4 → 1.4.5
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 +15 -0
- package/dist/esm/Address.js +5 -5
- package/dist/esm/Audio.js +5 -5
- package/dist/esm/AvatarContext-7153ad2b.js +3 -1
- package/dist/esm/AvatarGroup.js +4 -4
- package/dist/esm/Calendar.js +5 -5
- package/dist/esm/CalendarItem.js +4 -4
- package/dist/esm/Card.js +4 -3
- package/dist/esm/Cell.js +2 -2
- package/dist/esm/ConfigProvider.js +3 -3
- package/dist/esm/CountDown.js +4 -4
- package/dist/esm/DatePicker.js +5 -5
- package/dist/esm/Dialog.js +4 -4
- package/dist/esm/Ellipsis.js +4 -4
- package/dist/esm/Empty.js +4 -4
- package/dist/esm/FixedNav.js +4 -4
- package/dist/esm/Form.js +4 -4
- package/dist/esm/FormItem.js +3 -3
- package/dist/esm/Grid.js +4 -4
- package/dist/esm/GridItem.js +4 -4
- package/dist/esm/Image.js +4 -4
- package/dist/esm/Infiniteloading.js +4 -4
- package/dist/esm/Input.js +4 -4
- package/dist/esm/MenuItem.js +4 -4
- package/dist/esm/NoticeBar.js +2 -2
- package/dist/esm/NumberKeyboard.js +4 -4
- package/dist/esm/Pagination.js +4 -4
- package/dist/esm/Picker.js +4 -4
- package/dist/esm/PullToRefresh.js +4 -4
- package/dist/esm/Range.js +4 -4
- package/dist/esm/SearchBar.js +4 -4
- package/dist/esm/ShortPassword.js +4 -4
- package/dist/esm/SideNavBar.js +4 -4
- package/dist/esm/Signature.js +4 -4
- package/dist/esm/Sticky.js +4 -4
- package/dist/esm/Table.js +4 -4
- package/dist/esm/Tag.js +3 -2
- package/dist/esm/TextArea.js +4 -4
- package/dist/esm/TimeDetail.js +4 -4
- package/dist/esm/TimePannel.js +4 -4
- package/dist/esm/TimeSelect.js +6 -6
- package/dist/esm/Uploader.js +4 -4
- package/dist/esm/UserContext-68f62e66.js +3 -1
- package/dist/esm/UserContext-b4181162.js +3 -1
- package/dist/esm/UserContext-be8097d2.js +3 -1
- package/dist/esm/VirtualList.js +6 -4
- package/dist/esm/WaterMark.js +4 -4
- package/dist/esm/actionsheet.taro-a58d3d12.js +45 -83
- package/dist/esm/address.taro-79cc7c96.js +461 -0
- package/dist/esm/animate.taro-b0e83dd5.js +32 -46
- package/dist/esm/animatingnumbers.taro-6f40a2e9.js +93 -134
- package/dist/esm/audio.taro-4fadc583.js +161 -0
- package/dist/esm/avatar.taro-85ced995.js +93 -119
- package/dist/esm/avatargroup-1d900174.js +34 -0
- package/dist/esm/backtop.taro-99107c30.js +39 -62
- package/dist/esm/badge.taro-fe9171ec.js +40 -58
- package/dist/esm/barrage.taro-0e157b5e.js +61 -91
- package/dist/esm/bem-893ad28d.js +3 -6
- package/dist/esm/button.taro-4ce133b9.js +87 -98
- package/dist/esm/calendar.taro-4ed72058.js +38 -0
- package/dist/esm/calendaritem.taro-1ebe428d.js +571 -0
- package/dist/esm/card.taro-39055e82.js +32 -0
- package/dist/esm/cascader.taro-d8cb1c3e.js +397 -636
- package/dist/esm/cell.taro-9a04a92e.js +64 -0
- package/dist/esm/cellgroup.taro-e094471c.js +18 -27
- package/dist/esm/checkbox.taro-0bda9796.js +160 -232
- package/dist/esm/circleprogress.taro-47db537c.js +99 -120
- package/dist/esm/col.taro-b61c7cba.js +33 -50
- package/dist/esm/collapse.taro-af58206c.js +73 -86
- package/dist/esm/collapseitem-ce1849d2.js +75 -139
- package/dist/esm/configprovider-5eea4f5d.js +19 -0
- package/dist/esm/configprovider.taro-26882dd2.js +42 -0
- package/dist/esm/countdown.taro-9e40de9c.js +225 -0
- package/dist/esm/datepicker.taro-7220e495.js +270 -0
- package/dist/esm/dialog.taro-1c03960e.js +123 -0
- package/dist/esm/divider.taro-5236fe6a.js +27 -27
- package/dist/esm/drag.taro-82b6b27a.js +99 -138
- package/dist/esm/elevator.taro-d7d65470.js +185 -259
- package/dist/esm/ellipsis.taro-49b6db0c.js +232 -0
- package/dist/esm/empty.taro-7bd813f9.js +62 -0
- package/dist/esm/fixednav.taro-5ad15202.js +53 -0
- package/dist/esm/form.taro-71d32671.js +179 -0
- package/dist/esm/formitem.taro-3089489b.js +89 -0
- package/dist/esm/grid.taro-e6decfce.js +58 -0
- package/dist/esm/grid.taro.context-39636af9.js +4 -2
- package/dist/esm/griditem.taro-4cade72e.js +90 -0
- package/dist/esm/icon-8dc4de10.js +43 -51
- package/dist/esm/icon.taro-1d0d4fb7.js +43 -51
- package/dist/esm/image.taro-e6dc5867.js +64 -0
- package/dist/esm/imagepreview.taro-3400ea03.js +158 -205
- package/dist/esm/index.taro-a36f96fb.js +149 -210
- package/dist/esm/indicator.taro-183ea169.js +29 -43
- package/dist/esm/infiniteloading.taro-6c2a2e95.js +142 -0
- package/dist/esm/input.taro-fd566407.js +243 -0
- package/dist/esm/inputnumber.taro-dc39b853.js +129 -177
- package/dist/esm/layout.taro-358f014f.js +6 -9
- package/dist/esm/menu.taro-4abed328.js +89 -132
- package/dist/esm/menuitem.taro-6e8b27c3.js +130 -0
- package/dist/esm/navbar.taro-c931c078.js +69 -105
- package/dist/esm/noticebar.taro-69ea7673.js +450 -0
- package/dist/esm/notify.taro-308e5892.js +66 -97
- package/dist/esm/numberkeyboard.taro-194519e4.js +158 -0
- package/dist/esm/nutui-react.es.js +44 -44
- package/dist/esm/offsetContext-bfb02c25.js +3 -1
- package/dist/esm/overlay.taro-98367bc1.js +59 -74
- package/dist/esm/pagination.taro-bb490de9.js +124 -0
- package/dist/esm/picker.taro-2a8ded7c.js +420 -0
- package/dist/esm/popover.taro-46d813e8.js +132 -222
- package/dist/esm/popup.taro-cb777e09.js +125 -178
- package/dist/esm/price.taro-8801462e.js +75 -86
- package/dist/esm/progress.taro-623bc807.js +84 -118
- package/dist/esm/pulltorefresh.taro-cab7b51c.js +221 -0
- package/dist/esm/range.taro-5d6ff217.js +332 -0
- package/dist/esm/rate.taro-10197384.js +64 -111
- package/dist/esm/row.taro-37a895de.js +38 -42
- package/dist/esm/searchbar.taro-839dd622.js +148 -0
- package/dist/esm/shortpassword.taro-182d46f7.js +111 -0
- package/dist/esm/sidenavbar.taro-006cf38b.js +35 -0
- package/dist/esm/sidenavbaritem.taro-fee11d26.js +9 -22
- package/dist/esm/signature.taro-33632585.js +143 -0
- package/dist/esm/skeleton.taro-853ce460.js +51 -88
- package/dist/esm/step.taro-1c94e067.js +49 -78
- package/dist/esm/steps.taro-acf205a0.js +21 -30
- package/dist/esm/sticky.taro-d0553f48.js +13 -0
- package/dist/esm/subsidenavbar.taro-f46b4c73.js +58 -75
- package/dist/esm/swipe.taro-83bc248f.js +164 -254
- package/dist/esm/swiper.taro-852f6615.js +424 -505
- package/dist/esm/swiperitem-86a3578a.js +20 -28
- package/dist/esm/switch.taro-bae2dca0.js +43 -64
- package/dist/esm/tabbar.taro-86cece39.js +47 -57
- package/dist/esm/tabbaritem.taro-8dfb8055.js +51 -79
- package/dist/esm/table.taro-cb4dd2c3.js +92 -0
- package/dist/esm/tabpane.taro-91cd6cf4.js +17 -22
- package/dist/esm/tabs.taro-e71875fa.js +121 -165
- package/dist/esm/tag.taro-00fe554d.js +89 -0
- package/dist/esm/textarea.taro-42600f8c.js +74 -0
- package/dist/esm/timedetail.taro-c5f564fd.js +44 -0
- package/dist/esm/timepannel.taro-29f9dd86.js +22 -0
- package/dist/esm/timeselect.taro-3ecce65d.js +133 -0
- package/dist/esm/toast.taro-0804b6b4.js +99 -137
- package/dist/esm/trendarrow.taro-5a7153e4.js +63 -90
- package/dist/esm/types/src/packages/cell/cell.taro.d.ts +0 -1
- package/dist/esm/types/src/packages/noticebar/noticebar.d.ts +5 -4
- package/dist/esm/types/src/packages/noticebar/noticebar.taro.d.ts +5 -4
- package/dist/esm/types/src/packages/uploader/uploader.d.ts +1 -1
- package/dist/esm/types/src/packages/virtuallist/virtuallist.taro.d.ts +13 -2
- package/dist/esm/typings-1c5f2628.js +7 -6
- package/dist/esm/uploader.taro-f80d76d9.js +392 -0
- package/dist/esm/useClientRect-bf69d7b3.js +5 -25
- package/dist/esm/useTouch-a2ea68c6.js +63 -93
- package/dist/esm/video-8a3518c5.js +59 -83
- package/dist/esm/virtuallist.taro-e3345ced.js +215 -0
- package/dist/esm/watermark.taro-cd9db98a.js +114 -0
- package/dist/esm/zh-CN-dfc384d0.js +128 -133
- package/dist/locales/base.js +1 -1
- package/dist/locales/en-US.js +1 -1
- package/dist/locales/id-ID.js +1 -1
- package/dist/locales/zh-CN.js +1 -1
- package/dist/locales/zh-TW.js +1 -1
- package/dist/locales/zh-UG.js +1 -1
- package/dist/nutui.react.es.js +634 -5664
- package/dist/nutui.react.umd.js +634 -5664
- package/dist/packages/noticebar/noticebar.scss +17 -0
- package/dist/packages/radio/radio.scss +3 -1
- package/dist/packages/row/row.scss +2 -0
- package/dist/packages/searchbar/searchbar.scss +1 -1
- package/dist/packages/tag/tag.scss +13 -5
- package/dist/packages/virtuallist/virtuallist.scss +24 -0
- package/dist/style.css +1 -1
- package/dist/style.es.js +1 -1
- package/dist/styles/temp.scss +2340 -0
- package/dist/styles/theme-dark.scss +7 -0
- package/dist/styles/theme-default.scss +11 -0
- package/dist/styles/variables.scss +1945 -710
- package/dist/types/index.d.ts +16 -23
- package/package.json +9 -4
- package/dist/esm/address.taro-1e2aea24.js +0 -615
- package/dist/esm/audio.taro-fddcdfc0.js +0 -228
- package/dist/esm/avatargroup-f7f600ff.js +0 -42
- package/dist/esm/calendar.taro-72974415.js +0 -83
- package/dist/esm/calendaritem.taro-84e889eb.js +0 -580
- package/dist/esm/card.taro-a530dfb3.js +0 -61
- package/dist/esm/cell.taro-cf50c4f2.js +0 -109
- package/dist/esm/configprovider-c7d60e20.js +0 -18
- package/dist/esm/configprovider.taro-8bdb3a28.js +0 -50
- package/dist/esm/countdown.taro-d7dc8681.js +0 -246
- package/dist/esm/datepicker.taro-7199f521.js +0 -304
- package/dist/esm/dialog.taro-f54cfbf0.js +0 -187
- package/dist/esm/ellipsis.taro-c0de6ff4.js +0 -309
- package/dist/esm/empty.taro-dbc66496.js +0 -81
- package/dist/esm/fixednav.taro-9e759320.js +0 -97
- package/dist/esm/form.taro-880014b1.js +0 -181
- package/dist/esm/formitem.taro-3695f4a7.js +0 -136
- package/dist/esm/grid.taro-c2cc12d6.js +0 -81
- package/dist/esm/griditem.taro-892153cd.js +0 -122
- package/dist/esm/image.taro-c30973d5.js +0 -105
- package/dist/esm/infiniteloading.taro-b5ddf3cc.js +0 -188
- package/dist/esm/input.taro-104130c1.js +0 -361
- package/dist/esm/menuitem.taro-216e9f7d.js +0 -193
- package/dist/esm/noticebar.taro-94002898.js +0 -368
- package/dist/esm/numberkeyboard.taro-5e8f0ddf.js +0 -245
- package/dist/esm/pagination.taro-9925ffab.js +0 -169
- package/dist/esm/picker.taro-3b5cc054.js +0 -540
- package/dist/esm/pulltorefresh.taro-f26a20dd.js +0 -302
- package/dist/esm/range.taro-c41e9b90.js +0 -469
- package/dist/esm/searchbar.taro-01ed4ea4.js +0 -236
- package/dist/esm/shortpassword.taro-3a3bf412.js +0 -190
- package/dist/esm/sidenavbar.taro-06026f31.js +0 -66
- package/dist/esm/signature.taro-17648cac.js +0 -192
- package/dist/esm/sticky.taro-36013e97.js +0 -16
- package/dist/esm/table.taro-adda6622.js +0 -139
- package/dist/esm/tag.taro-bd900990.js +0 -104
- package/dist/esm/textarea.taro-83d5fe73.js +0 -102
- package/dist/esm/timedetail.taro-105f5380.js +0 -68
- package/dist/esm/timepannel.taro-c66c63dd.js +0 -30
- package/dist/esm/timeselect.taro-fc7ec6ee.js +0 -172
- package/dist/esm/uploader.taro-a1edf38f.js +0 -529
- package/dist/esm/virtuallist.taro-4add61c3.js +0 -315
- package/dist/esm/watermark.taro-323d1cf3.js +0 -132
|
@@ -1,528 +1,447 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
-
import _typeof from "@babel/runtime/helpers/typeof";
|
|
6
|
-
var _excluded = ["children", "direction", "className", "pageContent", "onChange", "initPage", "paginationColor", "paginationVisible", "touchable", "isPreventDefault", "isStopPropagation", "autoPlay", "isCenter"];
|
|
7
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
8
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
1
|
import React__default, { useRef, useState, useMemo, useEffect } from 'react';
|
|
11
2
|
import classNames from 'classnames';
|
|
12
3
|
import { nextTick, useReady, createSelectorQuery } from '@tarojs/taro';
|
|
13
4
|
import { D as DataContext } from './UserContext-b4181162.js';
|
|
14
5
|
import { c as cn } from './bem-893ad28d.js';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
duration: 500,
|
|
19
|
-
initPage: 0,
|
|
20
|
-
autoPlay: 0,
|
|
21
|
-
direction: 'horizontal',
|
|
22
|
-
paginationColor: '#fff',
|
|
23
|
-
paginationBgColor: '#ddd',
|
|
24
|
-
paginationVisible: false,
|
|
25
|
-
loop: true,
|
|
26
|
-
touchable: true,
|
|
27
|
-
isPreventDefault: true,
|
|
28
|
-
isStopPropagation: true,
|
|
29
|
-
isCenter: false,
|
|
30
|
-
className: ''
|
|
31
|
-
};
|
|
32
|
-
var DISTANCE = 5;
|
|
33
|
-
var Swiper = React__default.forwardRef(function (props, ref) {
|
|
34
|
-
var _classNames, _classNames2;
|
|
35
|
-
var propSwiper = _objectSpread(_objectSpread({}, defaultProps), props);
|
|
36
|
-
var children = propSwiper.children,
|
|
37
|
-
direction = propSwiper.direction,
|
|
38
|
-
className = propSwiper.className,
|
|
39
|
-
pageContent = propSwiper.pageContent,
|
|
40
|
-
onChange = propSwiper.onChange,
|
|
41
|
-
initPage = propSwiper.initPage,
|
|
42
|
-
paginationColor = propSwiper.paginationColor,
|
|
43
|
-
paginationVisible = propSwiper.paginationVisible,
|
|
44
|
-
touchable = propSwiper.touchable,
|
|
45
|
-
isPreventDefault = propSwiper.isPreventDefault,
|
|
46
|
-
isStopPropagation = propSwiper.isStopPropagation,
|
|
47
|
-
autoPlay = propSwiper.autoPlay,
|
|
48
|
-
isCenter = propSwiper.isCenter,
|
|
49
|
-
rest = _objectWithoutProperties(propSwiper, _excluded);
|
|
50
|
-
var container = useRef(null);
|
|
51
|
-
var innerRef = useRef(null);
|
|
52
|
-
var _swiper = useRef({
|
|
53
|
-
moving: false,
|
|
54
|
-
autoplayTimer: null,
|
|
55
|
-
width: 0,
|
|
6
|
+
|
|
7
|
+
const defaultProps = {
|
|
8
|
+
width: typeof window === 'object' ? window.innerWidth : 375,
|
|
56
9
|
height: 0,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
setOffset = _useState12[1];
|
|
85
|
-
var _useState13 = useState([]),
|
|
86
|
-
_useState14 = _slicedToArray(_useState13, 2),
|
|
87
|
-
childOffset = _useState14[0],
|
|
88
|
-
setChildOffset = _useState14[1];
|
|
89
|
-
var _useState15 = useState(false),
|
|
90
|
-
_useState16 = _slicedToArray(_useState15, 2),
|
|
91
|
-
ready = _useState16[0],
|
|
92
|
-
setReady = _useState16[1];
|
|
93
|
-
var size = isVertical ? height : width;
|
|
94
|
-
var _useState17 = useState({
|
|
95
|
-
startX: 0,
|
|
96
|
-
startY: 0,
|
|
97
|
-
deltaX: 0,
|
|
98
|
-
deltaY: 0,
|
|
99
|
-
offsetX: 0,
|
|
100
|
-
offsetY: 0,
|
|
101
|
-
stateDirection: '',
|
|
102
|
-
delta: 0,
|
|
103
|
-
touchTime: 0
|
|
104
|
-
}),
|
|
105
|
-
_useState18 = _slicedToArray(_useState17, 2),
|
|
106
|
-
touch = _useState18[0],
|
|
107
|
-
setTouch = _useState18[1];
|
|
108
|
-
var _useMemo = useMemo(function () {
|
|
109
|
-
var childCount = 0;
|
|
110
|
-
var childs = React__default.Children.map(props.children, function (child) {
|
|
111
|
-
if (!React__default.isValidElement(child)) return null;
|
|
112
|
-
childCount++;
|
|
113
|
-
return child;
|
|
114
|
-
});
|
|
115
|
-
return {
|
|
116
|
-
childs: childs,
|
|
117
|
-
childCount: childCount
|
|
118
|
-
};
|
|
119
|
-
}, [props.children]),
|
|
120
|
-
childs = _useMemo.childs,
|
|
121
|
-
childCount = _useMemo.childCount;
|
|
122
|
-
var trackSize = childCount * Number(size);
|
|
123
|
-
// 父组件参数传入子组件item
|
|
124
|
-
var parent = {
|
|
125
|
-
propSwiper: propSwiper,
|
|
126
|
-
size: size
|
|
127
|
-
};
|
|
128
|
-
var minOffset = function () {
|
|
129
|
-
if (rect) {
|
|
130
|
-
var base = isVertical ? rect === null || rect === void 0 ? void 0 : rect.height : rect === null || rect === void 0 ? void 0 : rect.width;
|
|
131
|
-
return base - Number(size) * childCount;
|
|
132
|
-
}
|
|
133
|
-
return 0;
|
|
134
|
-
}();
|
|
135
|
-
// 清除定时器
|
|
136
|
-
var stopAutoPlay = function stopAutoPlay() {
|
|
137
|
-
clearTimeout(_swiper.current.autoplayTimer);
|
|
138
|
-
_swiper.current.autoplayTimer = null;
|
|
139
|
-
};
|
|
140
|
-
// 定时轮播
|
|
141
|
-
var autoplay = function autoplay() {
|
|
142
|
-
if (propSwiper.autoPlay <= 0 || childCount <= 1) return;
|
|
143
|
-
stopAutoPlay();
|
|
144
|
-
_swiper.current.autoplayTimer = setTimeout(function () {
|
|
145
|
-
next();
|
|
146
|
-
autoplay();
|
|
147
|
-
}, Number(propSwiper.autoPlay));
|
|
148
|
-
};
|
|
149
|
-
// 重置首尾位置信息
|
|
150
|
-
var resettPosition = function resettPosition() {
|
|
151
|
-
_swiper.current.moving = true;
|
|
152
|
-
if (active <= -1) {
|
|
153
|
-
move({
|
|
154
|
-
pace: childCount
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
if (active >= childCount) {
|
|
158
|
-
move({
|
|
159
|
-
pace: -childCount
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
// 上一页
|
|
164
|
-
var prev = function prev() {
|
|
165
|
-
resettPosition();
|
|
166
|
-
touchReset();
|
|
167
|
-
requestFrame(function () {
|
|
168
|
-
requestFrame(function () {
|
|
169
|
-
_swiper.current.moving = false;
|
|
170
|
-
move({
|
|
171
|
-
pace: -1,
|
|
172
|
-
isEmit: true
|
|
173
|
-
});
|
|
174
|
-
});
|
|
10
|
+
duration: 500,
|
|
11
|
+
initPage: 0,
|
|
12
|
+
autoPlay: 0,
|
|
13
|
+
direction: 'horizontal',
|
|
14
|
+
paginationColor: '#fff',
|
|
15
|
+
paginationBgColor: '#ddd',
|
|
16
|
+
paginationVisible: false,
|
|
17
|
+
loop: true,
|
|
18
|
+
touchable: true,
|
|
19
|
+
isPreventDefault: true,
|
|
20
|
+
isStopPropagation: true,
|
|
21
|
+
isCenter: false,
|
|
22
|
+
className: '',
|
|
23
|
+
};
|
|
24
|
+
const DISTANCE = 5;
|
|
25
|
+
const Swiper = React__default.forwardRef((props, ref) => {
|
|
26
|
+
const propSwiper = { ...defaultProps, ...props };
|
|
27
|
+
const { children, direction, className, pageContent, onChange, initPage, paginationColor, paginationVisible, touchable, isPreventDefault, isStopPropagation, autoPlay, isCenter, ...rest } = propSwiper;
|
|
28
|
+
const container = useRef(null);
|
|
29
|
+
const innerRef = useRef(null);
|
|
30
|
+
const _swiper = useRef({
|
|
31
|
+
moving: false,
|
|
32
|
+
autoplayTimer: null,
|
|
33
|
+
width: 0,
|
|
34
|
+
height: 0,
|
|
35
|
+
offset: 0,
|
|
36
|
+
size: 0,
|
|
175
37
|
});
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
38
|
+
const [refRandomId] = useState(Math.random().toString(36).slice(-8));
|
|
39
|
+
const isVertical = direction === 'vertical';
|
|
40
|
+
const [rect, setRect] = useState(null);
|
|
41
|
+
// eslint-disable-next-line prefer-const
|
|
42
|
+
let [active, setActive] = useState(0);
|
|
43
|
+
const [width, setWidth] = useState(0);
|
|
44
|
+
const [height, setHeight] = useState(0);
|
|
45
|
+
const [offset, setOffset] = useState(0);
|
|
46
|
+
const [childOffset, setChildOffset] = useState([]);
|
|
47
|
+
const [ready, setReady] = useState(false);
|
|
48
|
+
let size = isVertical ? height : width;
|
|
49
|
+
const [touch, setTouch] = useState({
|
|
50
|
+
startX: 0,
|
|
51
|
+
startY: 0,
|
|
52
|
+
deltaX: 0,
|
|
53
|
+
deltaY: 0,
|
|
54
|
+
offsetX: 0,
|
|
55
|
+
offsetY: 0,
|
|
56
|
+
stateDirection: '',
|
|
57
|
+
delta: 0,
|
|
58
|
+
touchTime: 0,
|
|
189
59
|
});
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
60
|
+
const { childs, childCount } = useMemo(() => {
|
|
61
|
+
let childCount = 0;
|
|
62
|
+
const childs = React__default.Children.map(props.children, (child) => {
|
|
63
|
+
if (!React__default.isValidElement(child))
|
|
64
|
+
return null;
|
|
65
|
+
childCount++;
|
|
66
|
+
return child;
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
childs,
|
|
70
|
+
childCount,
|
|
71
|
+
};
|
|
72
|
+
}, [props.children]);
|
|
73
|
+
let trackSize = childCount * Number(size);
|
|
74
|
+
// 父组件参数传入子组件item
|
|
75
|
+
const parent = {
|
|
76
|
+
propSwiper,
|
|
77
|
+
size,
|
|
78
|
+
};
|
|
79
|
+
const minOffset = (() => {
|
|
80
|
+
if (rect) {
|
|
81
|
+
const base = isVertical ? rect?.height : rect?.width;
|
|
82
|
+
return base - Number(size) * childCount;
|
|
83
|
+
}
|
|
84
|
+
return 0;
|
|
85
|
+
})();
|
|
86
|
+
// 清除定时器
|
|
87
|
+
const stopAutoPlay = () => {
|
|
88
|
+
clearTimeout(_swiper.current.autoplayTimer);
|
|
89
|
+
_swiper.current.autoplayTimer = null;
|
|
90
|
+
};
|
|
91
|
+
// 定时轮播
|
|
92
|
+
const autoplay = () => {
|
|
93
|
+
if (propSwiper.autoPlay <= 0 || childCount <= 1)
|
|
94
|
+
return;
|
|
95
|
+
stopAutoPlay();
|
|
96
|
+
_swiper.current.autoplayTimer = setTimeout(() => {
|
|
97
|
+
next();
|
|
98
|
+
autoplay();
|
|
99
|
+
}, Number(propSwiper.autoPlay));
|
|
100
|
+
};
|
|
101
|
+
// 重置首尾位置信息
|
|
102
|
+
const resettPosition = () => {
|
|
103
|
+
_swiper.current.moving = true;
|
|
104
|
+
if (active <= -1) {
|
|
105
|
+
move({ pace: childCount });
|
|
203
106
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
107
|
+
if (active >= childCount) {
|
|
108
|
+
move({ pace: -childCount });
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
// 上一页
|
|
112
|
+
const prev = () => {
|
|
113
|
+
resettPosition();
|
|
114
|
+
touchReset();
|
|
115
|
+
requestFrame(() => {
|
|
116
|
+
requestFrame(() => {
|
|
117
|
+
_swiper.current.moving = false;
|
|
118
|
+
move({
|
|
119
|
+
pace: -1,
|
|
120
|
+
isEmit: true,
|
|
121
|
+
});
|
|
122
|
+
});
|
|
207
123
|
});
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (childCount <= 1) return;
|
|
222
|
-
var targetActive = getActive(pace);
|
|
223
|
-
// 父级容器偏移量
|
|
224
|
-
var targetOffset = getOffset(targetActive, offset);
|
|
225
|
-
// 如果循环,调整开头结尾图片位置
|
|
226
|
-
if (props.loop) {
|
|
227
|
-
if (Array.isArray(children) && children[0] && targetOffset !== minOffset) {
|
|
228
|
-
var rightBound = targetOffset < minOffset;
|
|
229
|
-
childOffset[0] = rightBound ? trackSize : 0;
|
|
230
|
-
}
|
|
231
|
-
if (Array.isArray(children) && children[childCount - 1] && targetOffset !== 0) {
|
|
232
|
-
var leftBound = targetOffset > 0;
|
|
233
|
-
childOffset[childCount - 1] = leftBound ? -trackSize : 0;
|
|
234
|
-
}
|
|
235
|
-
setChildOffset(childOffset);
|
|
236
|
-
}
|
|
237
|
-
if (isEmit && active !== targetActive) {
|
|
238
|
-
props.onChange && props.onChange((targetActive + childCount) % childCount);
|
|
239
|
-
}
|
|
240
|
-
active = targetActive;
|
|
241
|
-
setActive(targetActive);
|
|
242
|
-
setOffset(targetOffset);
|
|
243
|
-
getStyle(targetOffset);
|
|
244
|
-
};
|
|
245
|
-
// 确定当前active 元素
|
|
246
|
-
var getActive = function getActive(pace) {
|
|
247
|
-
if (pace) {
|
|
248
|
-
var _active = active + pace;
|
|
249
|
-
if (props.loop) {
|
|
250
|
-
return range(_active, -1, childCount);
|
|
251
|
-
}
|
|
252
|
-
return range(_active, 0, childCount - 1);
|
|
253
|
-
}
|
|
254
|
-
return active;
|
|
255
|
-
};
|
|
256
|
-
// 计算位移
|
|
257
|
-
var getOffset = function getOffset(active) {
|
|
258
|
-
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
259
|
-
var currentPosition = active * Number(size);
|
|
260
|
-
if (!props.loop) {
|
|
261
|
-
currentPosition = Math.min(currentPosition, -minOffset);
|
|
262
|
-
}
|
|
263
|
-
var targetOffset = offset - currentPosition;
|
|
264
|
-
if (!props.loop) {
|
|
265
|
-
targetOffset = range(targetOffset, minOffset, 0);
|
|
266
|
-
}
|
|
267
|
-
return targetOffset;
|
|
268
|
-
};
|
|
269
|
-
// 浏览器 帧 事件
|
|
270
|
-
var requestFrame = function requestFrame(fn) {
|
|
271
|
-
window.requestAnimationFrame.call(window, fn);
|
|
272
|
-
};
|
|
273
|
-
// 取值 方法
|
|
274
|
-
var range = function range(num, min, max) {
|
|
275
|
-
return Math.min(Math.max(num, min), max);
|
|
276
|
-
};
|
|
277
|
-
var getDirection = function getDirection(x, y) {
|
|
278
|
-
if (x > y && x > DISTANCE) return 'horizontal';
|
|
279
|
-
if (y > x && y > DISTANCE) return 'vertical';
|
|
280
|
-
return '';
|
|
281
|
-
};
|
|
282
|
-
// 重置 全部位移信息
|
|
283
|
-
var touchReset = function touchReset() {
|
|
284
|
-
touch.startX = 0;
|
|
285
|
-
touch.startY = 0;
|
|
286
|
-
touch.deltaX = 0;
|
|
287
|
-
touch.deltaY = 0;
|
|
288
|
-
touch.offsetX = 0;
|
|
289
|
-
touch.offsetY = 0;
|
|
290
|
-
touch.delta = 0;
|
|
291
|
-
touch.stateDirection = '';
|
|
292
|
-
touch.touchTime = 0;
|
|
293
|
-
};
|
|
294
|
-
// 触摸事件开始
|
|
295
|
-
var touchStart = function touchStart(e) {
|
|
296
|
-
touchReset();
|
|
297
|
-
touch.startX = e.touches[0].clientX;
|
|
298
|
-
touch.startY = e.touches[0].clientY;
|
|
299
|
-
};
|
|
300
|
-
// 触摸事件移动
|
|
301
|
-
var touchMove = function touchMove(e) {
|
|
302
|
-
touch.deltaX = e.touches[0].clientX - touch.startX;
|
|
303
|
-
touch.deltaY = e.touches[0].clientY - touch.startY;
|
|
304
|
-
touch.offsetX = Math.abs(touch.deltaX);
|
|
305
|
-
touch.offsetY = Math.abs(touch.deltaY);
|
|
306
|
-
touch.delta = isVertical ? touch.deltaY : touch.deltaX;
|
|
307
|
-
if (!touch.stateDirection) {
|
|
308
|
-
touch.stateDirection = getDirection(touch.offsetX, touch.offsetY);
|
|
309
|
-
}
|
|
310
|
-
};
|
|
311
|
-
var b = cn('swiper');
|
|
312
|
-
var classes = classNames(b(''));
|
|
313
|
-
var contentClass = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(b('inner')), true), _defineProperty(_classNames, "".concat(b('vertical')), isVertical), _classNames));
|
|
314
|
-
var getStyle = function getStyle() {
|
|
315
|
-
var moveOffset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : offset;
|
|
316
|
-
var target = innerRef.current;
|
|
317
|
-
var _offset = 0;
|
|
318
|
-
if (!isCenter) {
|
|
319
|
-
_offset = moveOffset;
|
|
320
|
-
} else {
|
|
321
|
-
var _size = isVertical ? height : width;
|
|
322
|
-
var val = isVertical ? (rect === null || rect === void 0 ? void 0 : rect.height) - _size : (rect === null || rect === void 0 ? void 0 : rect.width) - _size;
|
|
323
|
-
_offset = moveOffset + (active === childCount - 1 && !props.loop ? -val / 2 : val / 2);
|
|
324
|
-
}
|
|
325
|
-
target.style.transitionDuration = "".concat(_swiper.current.moving ? 0 : props.duration, "ms");
|
|
326
|
-
target.style[isVertical ? 'height' : 'width'] = "".concat(Number(size) * childCount, "px");
|
|
327
|
-
target.style[isVertical ? 'width' : 'height'] = "".concat(isVertical ? width : height, "px");
|
|
328
|
-
target.style.transform = "translate3D".concat(!isVertical ? "(".concat(_offset, "px,0,0)") : "(0,".concat(_offset, "px,0)"));
|
|
329
|
-
};
|
|
330
|
-
var onTouchStart = function onTouchStart(e) {
|
|
331
|
-
if (props.isPreventDefault) e.preventDefault();
|
|
332
|
-
if (props.isStopPropagation) e.stopPropagation();
|
|
333
|
-
if (!props.touchable) return;
|
|
334
|
-
touchStart(e);
|
|
335
|
-
touch.touchTime = Date.now();
|
|
336
|
-
stopAutoPlay();
|
|
337
|
-
resettPosition();
|
|
338
|
-
};
|
|
339
|
-
var onTouchMove = function onTouchMove(e) {
|
|
340
|
-
if (props.touchable && _swiper.current.moving) {
|
|
341
|
-
touchMove(e);
|
|
342
|
-
if (touch.stateDirection === props.direction) {
|
|
343
|
-
move({
|
|
344
|
-
offset: touch.delta
|
|
124
|
+
};
|
|
125
|
+
// 下一页
|
|
126
|
+
const next = () => {
|
|
127
|
+
resettPosition();
|
|
128
|
+
touchReset();
|
|
129
|
+
requestFrame(() => {
|
|
130
|
+
requestFrame(() => {
|
|
131
|
+
_swiper.current.moving = false;
|
|
132
|
+
move({
|
|
133
|
+
pace: 1,
|
|
134
|
+
isEmit: true,
|
|
135
|
+
});
|
|
136
|
+
});
|
|
345
137
|
});
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
var pace = 0;
|
|
354
|
-
_swiper.current.moving = false;
|
|
355
|
-
if (isShouldMove && touch.stateDirection === props.direction) {
|
|
356
|
-
var _offset2 = isVertical ? touch.offsetY : touch.offsetX;
|
|
357
|
-
if (props.loop) {
|
|
358
|
-
if (_offset2 > 0) {
|
|
359
|
-
pace = touch.delta > 0 ? -1 : 1;
|
|
360
|
-
} else {
|
|
361
|
-
pace = 0;
|
|
362
|
-
}
|
|
363
|
-
} else {
|
|
364
|
-
pace = -Math[touch.delta > 0 ? 'ceil' : 'floor'](touch.delta / size);
|
|
365
|
-
}
|
|
366
|
-
move({
|
|
367
|
-
pace: pace,
|
|
368
|
-
isEmit: true
|
|
369
|
-
});
|
|
370
|
-
} else if (touch.delta) {
|
|
371
|
-
move({
|
|
372
|
-
pace: 0
|
|
373
|
-
});
|
|
374
|
-
} else {
|
|
375
|
-
getStyle();
|
|
376
|
-
}
|
|
377
|
-
autoplay();
|
|
378
|
-
};
|
|
379
|
-
useEffect(function () {
|
|
380
|
-
_swiper.current.activePagination = (active + childCount) % childCount;
|
|
381
|
-
}, [active]);
|
|
382
|
-
var queryRect = function queryRect(element) {
|
|
383
|
-
return new Promise(function (resolve) {
|
|
384
|
-
var query = createSelectorQuery();
|
|
385
|
-
query.select("#".concat(element.id)) && query.select("#".concat(element.id)).boundingClientRect();
|
|
386
|
-
query.exec(function (res) {
|
|
387
|
-
resolve(res[0]);
|
|
388
|
-
});
|
|
389
|
-
});
|
|
390
|
-
};
|
|
391
|
-
var init = /*#__PURE__*/function () {
|
|
392
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
393
|
-
var active,
|
|
394
|
-
rect,
|
|
395
|
-
_active,
|
|
396
|
-
_width,
|
|
397
|
-
_height,
|
|
398
|
-
targetOffset,
|
|
399
|
-
_args = arguments;
|
|
400
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
401
|
-
while (1) {
|
|
402
|
-
switch (_context.prev = _context.next) {
|
|
403
|
-
case 0:
|
|
404
|
-
active = _args.length > 0 && _args[0] !== undefined ? _args[0] : +propSwiper.initPage;
|
|
405
|
-
_context.next = 3;
|
|
406
|
-
return queryRect(container.current);
|
|
407
|
-
case 3:
|
|
408
|
-
rect = _context.sent;
|
|
409
|
-
_active = Math.max(Math.min(childCount - 1, active), 0);
|
|
410
|
-
_width = propSwiper.width ? +propSwiper.width : rect === null || rect === void 0 ? void 0 : rect.width;
|
|
411
|
-
_height = propSwiper.height ? +propSwiper.height : rect === null || rect === void 0 ? void 0 : rect.height;
|
|
412
|
-
size = isVertical ? _height : _width;
|
|
413
|
-
trackSize = childCount * Number(size);
|
|
414
|
-
targetOffset = getOffset(_active);
|
|
415
|
-
_swiper.current.moving = true;
|
|
416
|
-
if (ready) {
|
|
138
|
+
};
|
|
139
|
+
// 前往指定页
|
|
140
|
+
const to = (index) => {
|
|
141
|
+
resettPosition();
|
|
142
|
+
touchReset();
|
|
143
|
+
requestFrame(() => {
|
|
144
|
+
requestFrame(() => {
|
|
417
145
|
_swiper.current.moving = false;
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
146
|
+
let targetIndex;
|
|
147
|
+
if (props.loop && childCount === index) {
|
|
148
|
+
targetIndex = active === 0 ? 0 : index;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
targetIndex = index % childCount;
|
|
152
|
+
}
|
|
153
|
+
move({
|
|
154
|
+
pace: targetIndex - active,
|
|
155
|
+
isEmit: true,
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
// 切换方法
|
|
161
|
+
const move = ({ pace = 0, offset = 0, isEmit = false, movingStatus = false, }) => {
|
|
162
|
+
if (childCount <= 1)
|
|
163
|
+
return;
|
|
164
|
+
const targetActive = getActive(pace);
|
|
165
|
+
// 父级容器偏移量
|
|
166
|
+
const targetOffset = getOffset(targetActive, offset);
|
|
167
|
+
// 如果循环,调整开头结尾图片位置
|
|
168
|
+
if (props.loop) {
|
|
169
|
+
if (Array.isArray(children) &&
|
|
170
|
+
children[0] &&
|
|
171
|
+
targetOffset !== minOffset) {
|
|
172
|
+
const rightBound = targetOffset < minOffset;
|
|
173
|
+
childOffset[0] = rightBound ? trackSize : 0;
|
|
174
|
+
}
|
|
175
|
+
if (Array.isArray(children) &&
|
|
176
|
+
children[childCount - 1] &&
|
|
177
|
+
targetOffset !== 0) {
|
|
178
|
+
const leftBound = targetOffset > 0;
|
|
179
|
+
childOffset[childCount - 1] = leftBound ? -trackSize : 0;
|
|
180
|
+
}
|
|
181
|
+
setChildOffset(childOffset);
|
|
429
182
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
183
|
+
if (isEmit && active !== targetActive) {
|
|
184
|
+
props.onChange && props.onChange((targetActive + childCount) % childCount);
|
|
185
|
+
}
|
|
186
|
+
active = targetActive;
|
|
187
|
+
setActive(targetActive);
|
|
188
|
+
setOffset(targetOffset);
|
|
189
|
+
getStyle(targetOffset);
|
|
434
190
|
};
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
}
|
|
446
|
-
return function () {
|
|
447
|
-
setReady(false);
|
|
191
|
+
// 确定当前active 元素
|
|
192
|
+
const getActive = (pace) => {
|
|
193
|
+
if (pace) {
|
|
194
|
+
const _active = active + pace;
|
|
195
|
+
if (props.loop) {
|
|
196
|
+
return range(_active, -1, childCount);
|
|
197
|
+
}
|
|
198
|
+
return range(_active, 0, childCount - 1);
|
|
199
|
+
}
|
|
200
|
+
return active;
|
|
448
201
|
};
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
return function () {
|
|
461
|
-
stopAutoPlay();
|
|
202
|
+
// 计算位移
|
|
203
|
+
const getOffset = (active, offset = 0) => {
|
|
204
|
+
let currentPosition = active * Number(size);
|
|
205
|
+
if (!props.loop) {
|
|
206
|
+
currentPosition = Math.min(currentPosition, -minOffset);
|
|
207
|
+
}
|
|
208
|
+
let targetOffset = offset - currentPosition;
|
|
209
|
+
if (!props.loop) {
|
|
210
|
+
targetOffset = range(targetOffset, minOffset, 0);
|
|
211
|
+
}
|
|
212
|
+
return targetOffset;
|
|
462
213
|
};
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
214
|
+
// 浏览器 帧 事件
|
|
215
|
+
const requestFrame = (fn) => {
|
|
216
|
+
window.requestAnimationFrame.call(window, fn);
|
|
217
|
+
};
|
|
218
|
+
// 取值 方法
|
|
219
|
+
const range = (num, min, max) => {
|
|
220
|
+
return Math.min(Math.max(num, min), max);
|
|
221
|
+
};
|
|
222
|
+
const getDirection = (x, y) => {
|
|
223
|
+
if (x > y && x > DISTANCE)
|
|
224
|
+
return 'horizontal';
|
|
225
|
+
if (y > x && y > DISTANCE)
|
|
226
|
+
return 'vertical';
|
|
227
|
+
return '';
|
|
228
|
+
};
|
|
229
|
+
// 重置 全部位移信息
|
|
230
|
+
const touchReset = () => {
|
|
231
|
+
touch.startX = 0;
|
|
232
|
+
touch.startY = 0;
|
|
233
|
+
touch.deltaX = 0;
|
|
234
|
+
touch.deltaY = 0;
|
|
235
|
+
touch.offsetX = 0;
|
|
236
|
+
touch.offsetY = 0;
|
|
237
|
+
touch.delta = 0;
|
|
238
|
+
touch.stateDirection = '';
|
|
239
|
+
touch.touchTime = 0;
|
|
240
|
+
};
|
|
241
|
+
// 触摸事件开始
|
|
242
|
+
const touchStart = (e) => {
|
|
243
|
+
touchReset();
|
|
244
|
+
touch.startX = e.touches[0].clientX;
|
|
245
|
+
touch.startY = e.touches[0].clientY;
|
|
246
|
+
};
|
|
247
|
+
// 触摸事件移动
|
|
248
|
+
const touchMove = (e) => {
|
|
249
|
+
touch.deltaX = e.touches[0].clientX - touch.startX;
|
|
250
|
+
touch.deltaY = e.touches[0].clientY - touch.startY;
|
|
251
|
+
touch.offsetX = Math.abs(touch.deltaX);
|
|
252
|
+
touch.offsetY = Math.abs(touch.deltaY);
|
|
253
|
+
touch.delta = isVertical ? touch.deltaY : touch.deltaX;
|
|
254
|
+
if (!touch.stateDirection) {
|
|
255
|
+
touch.stateDirection = getDirection(touch.offsetX, touch.offsetY);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
const b = cn('swiper');
|
|
259
|
+
const classes = classNames(b(''));
|
|
260
|
+
const contentClass = classNames({
|
|
261
|
+
[`${b('inner')}`]: true,
|
|
262
|
+
[`${b('vertical')}`]: isVertical,
|
|
467
263
|
});
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
264
|
+
const getStyle = (moveOffset = offset) => {
|
|
265
|
+
const target = innerRef.current;
|
|
266
|
+
let _offset = 0;
|
|
267
|
+
if (!isCenter) {
|
|
268
|
+
_offset = moveOffset;
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
const _size = isVertical ? height : width;
|
|
272
|
+
const val = isVertical
|
|
273
|
+
? rect?.height - _size
|
|
274
|
+
: rect?.width - _size;
|
|
275
|
+
_offset =
|
|
276
|
+
moveOffset +
|
|
277
|
+
(active === childCount - 1 && !props.loop ? -val / 2 : val / 2);
|
|
278
|
+
}
|
|
279
|
+
target.style.transitionDuration = `${_swiper.current.moving ? 0 : props.duration}ms`;
|
|
280
|
+
target.style[isVertical ? 'height' : 'width'] = `${Number(size) * childCount}px`;
|
|
281
|
+
target.style[isVertical ? 'width' : 'height'] = `${isVertical ? width : height}px`;
|
|
282
|
+
target.style.transform = `translate3D${!isVertical ? `(${_offset}px,0,0)` : `(0,${_offset}px,0)`}`;
|
|
283
|
+
};
|
|
284
|
+
const onTouchStart = (e) => {
|
|
285
|
+
if (props.isPreventDefault)
|
|
286
|
+
e.preventDefault();
|
|
287
|
+
if (props.isStopPropagation)
|
|
288
|
+
e.stopPropagation();
|
|
289
|
+
if (!props.touchable)
|
|
290
|
+
return;
|
|
291
|
+
touchStart(e);
|
|
292
|
+
touch.touchTime = Date.now();
|
|
293
|
+
stopAutoPlay();
|
|
294
|
+
resettPosition();
|
|
295
|
+
};
|
|
296
|
+
const onTouchMove = (e) => {
|
|
297
|
+
if (props.touchable && _swiper.current.moving) {
|
|
298
|
+
touchMove(e);
|
|
299
|
+
if (touch.stateDirection === props.direction) {
|
|
300
|
+
move({
|
|
301
|
+
offset: touch.delta,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
487
305
|
};
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
306
|
+
const onTouchEnd = (e) => {
|
|
307
|
+
if (!props.touchable || !_swiper.current.moving)
|
|
308
|
+
return;
|
|
309
|
+
const speed = touch.delta / (Date.now() - touch.touchTime);
|
|
310
|
+
const isShouldMove = Math.abs(speed) > 0.3 || Math.abs(touch.delta) > +(size / 2).toFixed(2);
|
|
311
|
+
let pace = 0;
|
|
312
|
+
_swiper.current.moving = false;
|
|
313
|
+
if (isShouldMove && touch.stateDirection === props.direction) {
|
|
314
|
+
const offset = isVertical ? touch.offsetY : touch.offsetX;
|
|
315
|
+
if (props.loop) {
|
|
316
|
+
if (offset > 0) {
|
|
317
|
+
pace = touch.delta > 0 ? -1 : 1;
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
pace = 0;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
pace = -Math[touch.delta > 0 ? 'ceil' : 'floor'](touch.delta / size);
|
|
325
|
+
}
|
|
326
|
+
move({
|
|
327
|
+
pace,
|
|
328
|
+
isEmit: true,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
else if (touch.delta) {
|
|
332
|
+
move({ pace: 0 });
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
getStyle();
|
|
336
|
+
}
|
|
337
|
+
autoplay();
|
|
338
|
+
};
|
|
339
|
+
useEffect(() => {
|
|
340
|
+
_swiper.current.activePagination = (active + childCount) % childCount;
|
|
341
|
+
}, [active]);
|
|
342
|
+
const queryRect = (element) => {
|
|
343
|
+
return new Promise((resolve) => {
|
|
344
|
+
const query = createSelectorQuery();
|
|
345
|
+
query.select(`#${element.id}`) &&
|
|
346
|
+
query.select(`#${element.id}`).boundingClientRect();
|
|
347
|
+
query.exec((res) => {
|
|
348
|
+
resolve(res[0]);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
};
|
|
352
|
+
const init = async (active = +propSwiper.initPage) => {
|
|
353
|
+
const rect = await queryRect(container.current);
|
|
354
|
+
const _active = Math.max(Math.min(childCount - 1, active), 0);
|
|
355
|
+
const _width = propSwiper.width ? +propSwiper.width : rect?.width;
|
|
356
|
+
const _height = propSwiper.height ? +propSwiper.height : rect?.height;
|
|
357
|
+
size = isVertical ? _height : _width;
|
|
358
|
+
trackSize = childCount * Number(size);
|
|
359
|
+
const targetOffset = getOffset(_active);
|
|
360
|
+
_swiper.current.moving = true;
|
|
361
|
+
if (ready) {
|
|
362
|
+
_swiper.current.moving = false;
|
|
363
|
+
}
|
|
364
|
+
setRect(rect);
|
|
365
|
+
setActive(_active);
|
|
366
|
+
setWidth(_width);
|
|
367
|
+
setHeight(_height);
|
|
368
|
+
setOffset(targetOffset);
|
|
369
|
+
setReady(true);
|
|
370
|
+
};
|
|
371
|
+
useEffect(() => {
|
|
372
|
+
if (ready) {
|
|
373
|
+
getStyle();
|
|
374
|
+
}
|
|
375
|
+
}, [isVertical, width, height, offset, ready]);
|
|
376
|
+
useEffect(() => {
|
|
377
|
+
if (ready) {
|
|
378
|
+
stopAutoPlay();
|
|
379
|
+
autoplay();
|
|
380
|
+
}
|
|
381
|
+
return () => {
|
|
382
|
+
setReady(false);
|
|
383
|
+
};
|
|
384
|
+
}, [ready]);
|
|
385
|
+
useEffect(() => {
|
|
386
|
+
stopAutoPlay();
|
|
387
|
+
autoplay();
|
|
388
|
+
}, [children]);
|
|
389
|
+
useEffect(() => {
|
|
390
|
+
nextTick(() => {
|
|
391
|
+
init();
|
|
392
|
+
});
|
|
393
|
+
}, [propSwiper.initPage]);
|
|
394
|
+
useEffect(() => {
|
|
395
|
+
return () => {
|
|
396
|
+
stopAutoPlay();
|
|
397
|
+
};
|
|
398
|
+
}, []);
|
|
399
|
+
useReady(() => {
|
|
400
|
+
nextTick(() => {
|
|
401
|
+
init();
|
|
402
|
+
});
|
|
523
403
|
});
|
|
524
|
-
|
|
404
|
+
const itemStyle = (index) => {
|
|
405
|
+
const style = {};
|
|
406
|
+
const _direction = propSwiper.direction || direction;
|
|
407
|
+
const _size = size;
|
|
408
|
+
if (_size) {
|
|
409
|
+
style[_direction === 'horizontal' ? 'width' : 'height'] = `${_size}px`;
|
|
410
|
+
}
|
|
411
|
+
const offset = childOffset[index];
|
|
412
|
+
if (offset) {
|
|
413
|
+
style.transform = `translate3D${_direction === 'horizontal' ? `(${offset}px,0,0)` : `(0,${offset}px,0)`}`;
|
|
414
|
+
}
|
|
415
|
+
return style;
|
|
416
|
+
};
|
|
417
|
+
React__default.useImperativeHandle(ref, () => ({
|
|
418
|
+
to,
|
|
419
|
+
next,
|
|
420
|
+
prev,
|
|
421
|
+
}));
|
|
422
|
+
return (React__default.createElement(DataContext.Provider, { value: parent },
|
|
423
|
+
React__default.createElement("div", { className: `${classes} ${className}`, ref: container, ...rest, id: `container-${refRandomId}`, onTouchStart: onTouchStart, onTouchMove: onTouchMove, onTouchEnd: onTouchEnd,
|
|
424
|
+
// @ts-ignore
|
|
425
|
+
catchMove: isVertical },
|
|
426
|
+
React__default.createElement("div", { className: contentClass, ref: innerRef }, React__default.Children.map(childs, (child, index) => {
|
|
427
|
+
return (React__default.createElement("div", { className: b('item-wrapper'), style: itemStyle(index), key: index }, child));
|
|
428
|
+
})),
|
|
429
|
+
propSwiper.paginationVisible && !('pageContent' in propSwiper) ? (React__default.createElement("div", { className: classNames({
|
|
430
|
+
[`${b('pagination')}`]: true,
|
|
431
|
+
[`${b('pagination-vertical')}`]: isVertical,
|
|
432
|
+
}) }, React__default.Children.map(childs, (item, index) => {
|
|
433
|
+
return (React__default.createElement("i", { style: (active + childCount) % childCount === index
|
|
434
|
+
? {
|
|
435
|
+
backgroundColor: propSwiper.paginationColor,
|
|
436
|
+
}
|
|
437
|
+
: {
|
|
438
|
+
backgroundColor: propSwiper.paginationBgColor,
|
|
439
|
+
}, className: classNames({
|
|
440
|
+
active: (active + childCount) % childCount === index,
|
|
441
|
+
}), key: index }));
|
|
442
|
+
}))) : (React__default.createElement("div", null, pageContent)))));
|
|
525
443
|
});
|
|
526
444
|
Swiper.defaultProps = defaultProps;
|
|
527
445
|
Swiper.displayName = 'NutSwiper';
|
|
446
|
+
|
|
528
447
|
export { Swiper as S };
|