@nutui/nutui-react-taro 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/esm/ActionSheet.js +5 -5
  3. package/dist/esm/Address.js +11 -7
  4. package/dist/esm/Audio.js +7 -8
  5. package/dist/esm/Avatar.js +3 -3
  6. package/dist/esm/AvatarGroup.js +4 -4
  7. package/dist/esm/BackTop.js +3 -3
  8. package/dist/esm/Badge.js +3 -3
  9. package/dist/esm/Button.js +3 -3
  10. package/dist/esm/Calendar.js +8 -8
  11. package/dist/esm/CalendarItem.js +4 -4
  12. package/dist/esm/Card.js +5 -3
  13. package/dist/esm/Cascader.js +6 -7
  14. package/dist/esm/Cell.js +3 -3
  15. package/dist/esm/Checkbox.js +4 -3
  16. package/dist/esm/ConfigProvider.js +3 -3
  17. package/dist/esm/CountDown.js +4 -4
  18. package/dist/esm/DatePicker.js +9 -8
  19. package/dist/esm/Dialog.js +7 -6
  20. package/dist/esm/Elevator.js +4 -2
  21. package/dist/esm/Empty.js +4 -4
  22. package/dist/esm/FixedNav.js +6 -6
  23. package/dist/esm/Grid.js +4 -4
  24. package/dist/esm/GridItem.js +5 -5
  25. package/dist/esm/ImagePreview.js +7 -6
  26. package/dist/esm/Infiniteloading.js +5 -5
  27. package/dist/esm/Input.js +5 -5
  28. package/dist/esm/InputNumber.js +3 -3
  29. package/dist/esm/MenuItem.js +5 -5
  30. package/dist/esm/NavBar.js +3 -3
  31. package/dist/esm/NoticeBar.js +3 -3
  32. package/dist/esm/NumberKeyboard.js +7 -7
  33. package/dist/esm/Overlay.js +2 -2
  34. package/dist/esm/Pagination.js +4 -4
  35. package/dist/esm/Picker.js +8 -8
  36. package/dist/esm/Popover.js +4 -4
  37. package/dist/esm/Popup.js +4 -4
  38. package/dist/esm/Progress.js +3 -3
  39. package/dist/esm/PullToRefresh/style/index.js +2 -0
  40. package/dist/esm/PullToRefresh.js +7 -0
  41. package/dist/esm/Radio.js +4 -4
  42. package/dist/esm/RadioGroup.js +2 -2
  43. package/dist/esm/Range.js +5 -5
  44. package/dist/esm/Rate.js +3 -3
  45. package/dist/esm/SearchBar.js +5 -5
  46. package/dist/esm/ShortPassword.js +7 -7
  47. package/dist/esm/SideNavBar.js +7 -7
  48. package/dist/esm/Signature.js +6 -6
  49. package/dist/esm/Skeleton.js +4 -3
  50. package/dist/esm/Swiper.js +3 -3
  51. package/dist/esm/TabbarItem.js +3 -3
  52. package/dist/esm/Table.js +5 -5
  53. package/dist/esm/Tabs.js +3 -3
  54. package/dist/esm/Tag.js +3 -3
  55. package/dist/esm/TextArea.js +4 -4
  56. package/dist/esm/TimeDetail.js +4 -4
  57. package/dist/esm/TimePannel.js +4 -4
  58. package/dist/esm/TimeSelect.js +9 -7
  59. package/dist/esm/Toast.js +2 -3
  60. package/dist/esm/Uploader.js +4 -4
  61. package/dist/esm/VirtualList.js +4 -4
  62. package/dist/esm/{actionsheet.taro-f4d407b0.js → actionsheet.taro-1b3e7972.js} +9 -9
  63. package/dist/esm/{address.taro-4765a826.js → address.taro-f045886a.js} +48 -60
  64. package/dist/esm/{audio.taro-cd6cc93b.js → audio.taro-b34a1eb6.js} +3 -3
  65. package/dist/esm/{avatar.taro-0a0472fd.js → avatar.taro-c3a605b9.js} +1 -1
  66. package/dist/esm/{avatargroup-1ca79066.js → avatargroup-5b2584d9.js} +1 -1
  67. package/dist/esm/{backtop.taro-0e2e3946.js → backtop.taro-eb9359e8.js} +1 -1
  68. package/dist/esm/{badge.taro-eeac9de8.js → badge.taro-e6c4fe5f.js} +4 -4
  69. package/dist/esm/{button-521a516b.js → button.taro-bffc9543.js} +1 -1
  70. package/dist/esm/{calendar.taro-1abb1925.js → calendar.taro-1fc76ba0.js} +3 -3
  71. package/dist/esm/{calendaritem.taro-3c06a809.js → calendaritem.taro-11333579.js} +1 -1
  72. package/dist/esm/card.taro-2fbfbf59.js +67 -0
  73. package/dist/esm/{cascader.taro-31dbc60e.js → cascader.taro-d7e71bdf.js} +2 -2
  74. package/dist/esm/{cell.taro-3bb1b0f2.js → cell.taro-263a8927.js} +1 -1
  75. package/dist/esm/checkbox.taro-9d05ae76.js +140 -0
  76. package/dist/esm/{configprovider-9c393a29.js → configprovider-3e87d67a.js} +1 -1
  77. package/dist/esm/{configprovider.taro-1ff7f150.js → configprovider.taro-6c7b3056.js} +1 -1
  78. package/dist/esm/{countdown.taro-b00d0d46.js → countdown.taro-5d5df894.js} +1 -1
  79. package/dist/esm/{datepicker.taro-e385849d.js → datepicker.taro-318e9561.js} +22 -274
  80. package/dist/esm/{dialog.taro-c80b7b5f.js → dialog.taro-0e53ade9.js} +109 -9
  81. package/dist/esm/{elevator.taro-15b0d8c2.js → elevator.taro-8e385785.js} +39 -47
  82. package/dist/esm/{empty.taro-20b8adac.js → empty.taro-ab9c4f03.js} +1 -1
  83. package/dist/esm/{fixednav.taro-75e35339.js → fixednav.taro-6c0279ba.js} +3 -3
  84. package/dist/esm/{grid.taro-7fb43d02.js → grid.taro-5d75c0ad.js} +1 -1
  85. package/dist/esm/{griditem.taro-8020b409.js → griditem.taro-edb212e3.js} +2 -2
  86. package/dist/esm/imagepreview.taro-dae0757b.js +257 -0
  87. package/dist/esm/{infiniteloading.taro-0a86819e.js → infiniteloading.taro-067759de.js} +2 -2
  88. package/dist/esm/{input.taro-1d23861d.js → input.taro-505632ac.js} +2 -2
  89. package/dist/esm/{inputnumber.taro-75662231.js → inputnumber.taro-102203f3.js} +1 -1
  90. package/dist/esm/{menuitem.taro-56bf3205.js → menuitem.taro-0d8f50f9.js} +7 -7
  91. package/dist/esm/{navbar.taro-f2eae6a6.js → navbar.taro-2e969a0f.js} +1 -1
  92. package/dist/esm/{noticebar.taro-1890c693.js → noticebar.taro-f8bb6ae8.js} +1 -1
  93. package/dist/esm/{numberkeyboard.taro-5d685c76.js → numberkeyboard.taro-cf7d06f4.js} +2 -2
  94. package/dist/esm/nutui-react.es.js +66 -70
  95. package/dist/esm/{overlay-ed3eb37d.js → overlay.taro-be45fed5.js} +0 -0
  96. package/dist/esm/{pagination.taro-10449c4a.js → pagination.taro-62bbd23f.js} +1 -1
  97. package/dist/esm/picker.taro-62ce13e0.js +633 -0
  98. package/dist/esm/{popover.taro-9b3da0fa.js → popover.taro-0afa7cfa.js} +2 -2
  99. package/dist/esm/{popup.taro-a89dd3a1.js → popup.taro-8363fbae.js} +2 -2
  100. package/dist/esm/{progress.taro-dd93ac38.js → progress.taro-32ca3a69.js} +1 -1
  101. package/dist/esm/pulltorefresh.taro-8846f019.js +366 -0
  102. package/dist/esm/{radio.taro-32cb0172.js → radio.taro-1c63512f.js} +2 -2
  103. package/dist/esm/{radiogroup-e698d3df.js → radiogroup.taro-b5dad516.js} +0 -0
  104. package/dist/esm/{range.taro-fe08c5f4.js → range.taro-ef3b30f0.js} +2 -119
  105. package/dist/esm/{rate.taro-a0b21714.js → rate.taro-bb2e6c87.js} +1 -1
  106. package/dist/esm/{searchbar.taro-450d2f88.js → searchbar.taro-81867286.js} +2 -2
  107. package/dist/esm/{shortpassword.taro-08a05360.js → shortpassword.taro-2db97cc8.js} +3 -3
  108. package/dist/esm/{sidenavbar.taro-dd471476.js → sidenavbar.taro-e243b626.js} +2 -2
  109. package/dist/esm/{signature.taro-7cb77bab.js → signature.taro-e7369db8.js} +2 -2
  110. package/dist/esm/skeleton.taro-c19acc4e.js +109 -0
  111. package/dist/esm/{swiper.taro-7a2ef124.js → swiper.taro-448cd0ad.js} +56 -41
  112. package/dist/esm/{tabbaritem.taro-a88d3ae7.js → tabbaritem.taro-d0f2cec9.js} +1 -1
  113. package/dist/esm/{table.taro-305e0317.js → table.taro-25aeccba.js} +2 -2
  114. package/dist/esm/{tabs.taro-d1e85ea5.js → tabs.taro-d6006610.js} +1 -1
  115. package/dist/esm/{tag.taro-3bbbb557.js → tag.taro-ce9c52cd.js} +1 -1
  116. package/dist/esm/{textarea.taro-700b04c2.js → textarea.taro-388d1f90.js} +1 -1
  117. package/dist/esm/{timedetail.taro-7cc00243.js → timedetail.taro-519808cf.js} +1 -1
  118. package/dist/esm/{timepannel.taro-e24537e4.js → timepannel.taro-9904f6e6.js} +1 -1
  119. package/dist/esm/{timeselect.taro-210fd548.js → timeselect.taro-eea8d569.js} +16 -111
  120. package/dist/esm/{Notification-422905bd.js → toast.taro-d4ecd6af.js} +115 -1
  121. package/dist/esm/{uploader.taro-f7528535.js → uploader.taro-b232b2d3.js} +1 -1
  122. package/dist/esm/{virtuallist.taro-ce9619f9.js → virtuallist.taro-6858f690.js} +1 -1
  123. package/dist/esm/{zh-CN-91090ae2.js → zh-CN-14165629.js} +6 -0
  124. package/dist/locales/base.d.ts +6 -0
  125. package/dist/locales/base.js +1 -1
  126. package/dist/locales/en-US.js +7 -1
  127. package/dist/locales/id-ID.js +7 -1
  128. package/dist/locales/zh-CN.js +7 -1
  129. package/dist/locales/zh-TW.js +7 -1
  130. package/dist/nutui.react.es.js +14229 -14812
  131. package/dist/nutui.react.umd.js +14236 -14818
  132. package/dist/packages/actionsheet/actionsheet.scss +2 -0
  133. package/dist/packages/elevator/elevator.scss +1 -0
  134. package/dist/packages/pulltorefresh/pulltorefresh.scss +18 -0
  135. package/dist/style.css +1 -1
  136. package/dist/style.es.js +1 -1
  137. package/dist/styles/themes/default.scss +1 -0
  138. package/dist/types/actionsheet/actionsheet.taro.d.ts +2 -2
  139. package/dist/types/checkbox/checkbox.taro.d.ts +1 -1
  140. package/dist/types/elevator/elevator.taro.d.ts +2 -2
  141. package/dist/types/nutui.react.d.ts +3 -1
  142. package/dist/types/picker/pickerSlot.taro.d.ts +16 -0
  143. package/dist/types/popup/popup.taro.d.ts +1 -1
  144. package/dist/types/pulltorefresh/index.taro.d.ts +2 -0
  145. package/dist/types/pulltorefresh/pulltorefresh.taro.d.ts +18 -0
  146. package/dist/types/radio/radio.taro.d.ts +1 -1
  147. package/dist/types/radiogroup/index.taro.d.ts +1 -1
  148. package/dist/types/radiogroup/radiogroup.taro.d.ts +11 -0
  149. package/dist/types/timeselect/timeselect.taro.d.ts +1 -1
  150. package/package.json +2 -3
  151. package/dist/esm/button.taro-d5968f9d.js +0 -109
  152. package/dist/esm/card.taro-0861c7b3.js +0 -265
  153. package/dist/esm/checkbox.taro-6fbc4b3c.js +0 -255
  154. package/dist/esm/imagepreview.taro-a0ddd8a2.js +0 -813
  155. package/dist/esm/overlay.taro-a784329e.js +0 -94
  156. package/dist/esm/picker.taro-216cc3cb.js +0 -264
  157. package/dist/esm/pickerSlot-f8e4e542.js +0 -248
  158. package/dist/esm/popup-67173ec6.js +0 -217
  159. package/dist/esm/skeleton.taro-5934c7d7.js +0 -245
  160. package/dist/esm/toast.taro-bb181833.js +0 -122
@@ -1,813 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
- import _typeof from "@babel/runtime/helpers/typeof";
5
- var _excluded = ["children", "direction", "className", "pageContent", "onChange", "initPage", "paginationColor", "paginationVisible", "touchable", "isPreventDefault", "isStopPropagation", "autoPlay", "isCenter"];
6
-
7
- 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; }
8
-
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
-
11
- import React__default, { useRef, useState, useMemo, useEffect } from 'react';
12
- import { P as Popup } from './popup-67173ec6.js';
13
- import { V as Video } from './video-c1090c92.js';
14
- import classNames from 'classnames';
15
- import { D as DataContext } from './UserContext-b4181162.js';
16
- import { c as cn } from './bem-893ad28d.js';
17
- import { a as getRect } from './useClientRect-8b7cc406.js';
18
- import { S as SwiperItem } from './swiperitem-d00e7513.js';
19
- var defaultProps$1 = {
20
- width: (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' ? window.innerWidth : 375,
21
- height: 0,
22
- duration: 500,
23
- initPage: 0,
24
- autoPlay: 0,
25
- direction: 'horizontal',
26
- paginationColor: '#fff',
27
- paginationVisible: false,
28
- loop: true,
29
- touchable: true,
30
- isPreventDefault: true,
31
- isStopPropagation: true,
32
- isCenter: false,
33
- className: ''
34
- };
35
- var DISTANCE = 5;
36
- var Swiper = React__default.forwardRef(function (props, ref) {
37
- var _classNames, _classNames2;
38
-
39
- var propSwiper = _objectSpread(_objectSpread({}, defaultProps$1), props);
40
-
41
- var children = propSwiper.children,
42
- direction = propSwiper.direction,
43
- className = propSwiper.className,
44
- pageContent = propSwiper.pageContent,
45
- onChange = propSwiper.onChange,
46
- initPage = propSwiper.initPage,
47
- paginationColor = propSwiper.paginationColor,
48
- paginationVisible = propSwiper.paginationVisible,
49
- touchable = propSwiper.touchable,
50
- isPreventDefault = propSwiper.isPreventDefault,
51
- isStopPropagation = propSwiper.isStopPropagation,
52
- autoPlay = propSwiper.autoPlay,
53
- isCenter = propSwiper.isCenter,
54
- rest = _objectWithoutProperties(propSwiper, _excluded);
55
-
56
- var container = useRef(null);
57
- var innerRef = useRef(null);
58
-
59
- var _swiper = useRef({
60
- moving: false,
61
- autoplayTimer: null,
62
- width: 0,
63
- height: 0,
64
- offset: 0,
65
- size: 0
66
- });
67
-
68
- var isVertical = direction === 'vertical';
69
-
70
- var _useState = useState(null),
71
- _useState2 = _slicedToArray(_useState, 2),
72
- rect = _useState2[0],
73
- setRect = _useState2[1]; // eslint-disable-next-line prefer-const
74
-
75
-
76
- var _useState3 = useState(0),
77
- _useState4 = _slicedToArray(_useState3, 2),
78
- active = _useState4[0],
79
- setActive = _useState4[1];
80
-
81
- var _useState5 = useState(0),
82
- _useState6 = _slicedToArray(_useState5, 2),
83
- width = _useState6[0],
84
- setWidth = _useState6[1];
85
-
86
- var _useState7 = useState(0),
87
- _useState8 = _slicedToArray(_useState7, 2),
88
- height = _useState8[0],
89
- setHeight = _useState8[1];
90
-
91
- var _useState9 = useState(0),
92
- _useState10 = _slicedToArray(_useState9, 2),
93
- offset = _useState10[0],
94
- setOffset = _useState10[1];
95
-
96
- var _useState11 = useState([]),
97
- _useState12 = _slicedToArray(_useState11, 2),
98
- childOffset = _useState12[0],
99
- setChildOffset = _useState12[1];
100
-
101
- var _useState13 = useState(false),
102
- _useState14 = _slicedToArray(_useState13, 2),
103
- ready = _useState14[0],
104
- setReady = _useState14[1];
105
-
106
- var size = isVertical ? height : width;
107
-
108
- var _useState15 = useState({
109
- startX: 0,
110
- startY: 0,
111
- deltaX: 0,
112
- deltaY: 0,
113
- offsetX: 0,
114
- offsetY: 0,
115
- stateDirection: '',
116
- delta: 0,
117
- touchTime: 0
118
- }),
119
- _useState16 = _slicedToArray(_useState15, 2),
120
- touch = _useState16[0],
121
- setTouch = _useState16[1];
122
-
123
- var _useMemo = useMemo(function () {
124
- var childCount = 0;
125
- var childs = React__default.Children.map(props.children, function (child) {
126
- if (!React__default.isValidElement(child)) return null;
127
- childCount++;
128
- return child;
129
- });
130
- return {
131
- childs: childs,
132
- childCount: childCount
133
- };
134
- }, [props.children]),
135
- childs = _useMemo.childs,
136
- childCount = _useMemo.childCount;
137
-
138
- var trackSize = childCount * Number(size); // 父组件参数传入子组件item
139
-
140
- var parent = {
141
- propSwiper: propSwiper,
142
- size: size
143
- };
144
-
145
- var minOffset = function () {
146
- if (rect) {
147
- var base = isVertical ? rect.height : rect.width;
148
- return base - Number(size) * childCount;
149
- }
150
-
151
- return 0;
152
- }(); // 清除定时器
153
-
154
-
155
- var stopAutoPlay = function stopAutoPlay() {
156
- clearTimeout(_swiper.current.autoplayTimer);
157
- _swiper.current.autoplayTimer = null;
158
- }; // 定时轮播
159
-
160
-
161
- var autoplay = function autoplay() {
162
- if (propSwiper.autoPlay <= 0 || childCount <= 1) return;
163
- stopAutoPlay();
164
- _swiper.current.autoplayTimer = setTimeout(function () {
165
- next();
166
- autoplay();
167
- }, Number(propSwiper.autoPlay));
168
- }; // 重置首尾位置信息
169
-
170
-
171
- var resettPosition = function resettPosition() {
172
- _swiper.current.moving = true;
173
-
174
- if (active <= -1) {
175
- move({
176
- pace: childCount
177
- });
178
- }
179
-
180
- if (active >= childCount) {
181
- move({
182
- pace: -childCount
183
- });
184
- }
185
- }; // 上一页
186
-
187
-
188
- var prev = function prev() {
189
- resettPosition();
190
- touchReset();
191
- requestFrame(function () {
192
- requestFrame(function () {
193
- _swiper.current.moving = false;
194
- move({
195
- pace: -1,
196
- isEmit: true
197
- });
198
- });
199
- });
200
- }; // 下一页
201
-
202
-
203
- var next = function next() {
204
- resettPosition();
205
- touchReset();
206
- requestFrame(function () {
207
- requestFrame(function () {
208
- _swiper.current.moving = false;
209
- move({
210
- pace: 1,
211
- isEmit: true
212
- });
213
- });
214
- });
215
- }; // 前往指定页
216
-
217
-
218
- var to = function to(index) {
219
- resettPosition();
220
- touchReset();
221
- requestFrame(function () {
222
- requestFrame(function () {
223
- _swiper.current.moving = false;
224
- var targetIndex;
225
-
226
- if (props.loop && childCount === index) {
227
- targetIndex = active === 0 ? 0 : index;
228
- } else {
229
- targetIndex = index % childCount;
230
- }
231
-
232
- move({
233
- pace: targetIndex - active,
234
- isEmit: true
235
- });
236
- });
237
- });
238
- }; // 切换方法
239
-
240
-
241
- var move = function move(_ref) {
242
- var _ref$pace = _ref.pace,
243
- pace = _ref$pace === void 0 ? 0 : _ref$pace,
244
- _ref$offset = _ref.offset,
245
- offset = _ref$offset === void 0 ? 0 : _ref$offset,
246
- _ref$isEmit = _ref.isEmit,
247
- isEmit = _ref$isEmit === void 0 ? false : _ref$isEmit,
248
- _ref$movingStatus = _ref.movingStatus,
249
- movingStatus = _ref$movingStatus === void 0 ? false : _ref$movingStatus;
250
- if (childCount <= 1) return;
251
- var targetActive = getActive(pace); // 父级容器偏移量
252
-
253
- var targetOffset = getOffset(targetActive, offset); // 如果循环,调整开头结尾图片位置
254
-
255
- if (props.loop) {
256
- if (Array.isArray(children) && children[0] && targetOffset !== minOffset) {
257
- var rightBound = targetOffset < minOffset;
258
- childOffset[0] = rightBound ? trackSize : 0;
259
- }
260
-
261
- if (Array.isArray(children) && children[childCount - 1] && targetOffset !== 0) {
262
- var leftBound = targetOffset > 0;
263
- childOffset[childCount - 1] = leftBound ? -trackSize : 0;
264
- }
265
-
266
- setChildOffset(childOffset);
267
- }
268
-
269
- if (isEmit && active !== targetActive) {
270
- props.onChange && props.onChange((targetActive + childCount) % childCount);
271
- }
272
-
273
- active = targetActive;
274
- setActive(targetActive);
275
- setOffset(targetOffset);
276
- getStyle(targetOffset);
277
- }; // 确定当前active 元素
278
-
279
-
280
- var getActive = function getActive(pace) {
281
- if (pace) {
282
- var _active = active + pace;
283
-
284
- if (props.loop) {
285
- return range(_active, -1, childCount);
286
- }
287
-
288
- return range(_active, 0, childCount - 1);
289
- }
290
-
291
- return active;
292
- }; // 计算位移
293
-
294
-
295
- var getOffset = function getOffset(active) {
296
- var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
297
- var currentPosition = active * Number(size);
298
-
299
- if (!props.loop) {
300
- currentPosition = Math.min(currentPosition, -minOffset);
301
- }
302
-
303
- var targetOffset = offset - currentPosition;
304
-
305
- if (!props.loop) {
306
- targetOffset = range(targetOffset, minOffset, 0);
307
- }
308
-
309
- return targetOffset;
310
- }; // 浏览器 帧 事件
311
-
312
-
313
- var requestFrame = function requestFrame(fn) {
314
- window.requestAnimationFrame.call(window, fn);
315
- }; // 取值 方法
316
-
317
-
318
- var range = function range(num, min, max) {
319
- return Math.min(Math.max(num, min), max);
320
- };
321
-
322
- var getDirection = function getDirection(x, y) {
323
- if (x > y && x > DISTANCE) return 'horizontal';
324
- if (y > x && y > DISTANCE) return 'vertical';
325
- return '';
326
- }; // 重置 全部位移信息
327
-
328
-
329
- var touchReset = function touchReset() {
330
- touch.startX = 0;
331
- touch.startY = 0;
332
- touch.deltaX = 0;
333
- touch.deltaY = 0;
334
- touch.offsetX = 0;
335
- touch.offsetY = 0;
336
- touch.delta = 0;
337
- touch.stateDirection = '';
338
- touch.touchTime = 0;
339
- }; // 触摸事件开始
340
-
341
-
342
- var touchStart = function touchStart(e) {
343
- touchReset();
344
- touch.startX = e.touches[0].clientX;
345
- touch.startY = e.touches[0].clientY;
346
- }; // 触摸事件移动
347
-
348
-
349
- var touchMove = function touchMove(e) {
350
- touch.deltaX = e.touches[0].clientX - touch.startX;
351
- touch.deltaY = e.touches[0].clientY - touch.startY;
352
- touch.offsetX = Math.abs(touch.deltaX);
353
- touch.offsetY = Math.abs(touch.deltaY);
354
- touch.delta = isVertical ? touch.deltaY : touch.deltaX;
355
-
356
- if (!touch.stateDirection) {
357
- touch.stateDirection = getDirection(touch.offsetX, touch.offsetY);
358
- }
359
- };
360
-
361
- var b = cn('swiper');
362
- var classes = classNames(b(''));
363
- var contentClass = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(b('inner')), true), _defineProperty(_classNames, "".concat(b('vertical')), isVertical), _classNames));
364
-
365
- var getStyle = function getStyle() {
366
- var moveOffset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : offset;
367
- var target = innerRef.current;
368
- var _offset = 0;
369
-
370
- if (!isCenter) {
371
- _offset = moveOffset;
372
- } else {
373
- var _size = isVertical ? height : width;
374
-
375
- var val = isVertical ? rect.height - _size : rect.width - _size;
376
- _offset = moveOffset + (active === childCount - 1 && !props.loop ? -val / 2 : val / 2);
377
- }
378
-
379
- target.style.transform = "translate3D".concat(!isVertical ? "(".concat(_offset, "px,0,0)") : "(0,".concat(_offset, "px,0)"));
380
- target.style.transitionDuration = "".concat(_swiper.current.moving ? 0 : props.duration, "ms");
381
- target.style[isVertical ? 'height' : 'width'] = "".concat(Number(size) * childCount, "px");
382
- target.style[isVertical ? 'width' : 'height'] = "".concat(isVertical ? width : height, "px");
383
- };
384
-
385
- var onTouchStart = function onTouchStart(e) {
386
- if (props.isPreventDefault) e.preventDefault();
387
- if (props.isStopPropagation) e.stopPropagation();
388
- if (!props.touchable) return;
389
- touchStart(e);
390
- touch.touchTime = Date.now();
391
- stopAutoPlay();
392
- resettPosition();
393
- };
394
-
395
- var onTouchMove = function onTouchMove(e) {
396
- if (props.touchable && _swiper.current.moving) {
397
- touchMove(e);
398
-
399
- if (touch.stateDirection === props.direction) {
400
- move({
401
- offset: touch.delta
402
- });
403
- }
404
- }
405
- };
406
-
407
- var onTouchEnd = function onTouchEnd(e) {
408
- if (!props.touchable || !_swiper.current.moving) return;
409
- var speed = touch.delta / (Date.now() - touch.touchTime);
410
- var isShouldMove = Math.abs(speed) > 0.3 || Math.abs(touch.delta) > +(size / 2).toFixed(2);
411
- var pace = 0;
412
- _swiper.current.moving = false;
413
-
414
- if (isShouldMove && touch.stateDirection === props.direction) {
415
- var _offset2 = isVertical ? touch.offsetY : touch.offsetX;
416
-
417
- if (props.loop) {
418
- if (_offset2 > 0) {
419
- pace = touch.delta > 0 ? -1 : 1;
420
- } else {
421
- pace = 0;
422
- }
423
- } else {
424
- pace = -Math[touch.delta > 0 ? 'ceil' : 'floor'](touch.delta / size);
425
- }
426
-
427
- move({
428
- pace: pace,
429
- isEmit: true
430
- });
431
- } else if (touch.delta) {
432
- move({
433
- pace: 0
434
- });
435
- } else {
436
- getStyle();
437
- }
438
-
439
- autoplay();
440
- };
441
-
442
- useEffect(function () {
443
- _swiper.current.activePagination = (active + childCount) % childCount;
444
- }, [active]);
445
-
446
- var init = function init() {
447
- var active = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : +propSwiper.initPage;
448
- var rect = getRect(container === null || container === void 0 ? void 0 : container.current);
449
-
450
- var _active = Math.max(Math.min(childCount - 1, active), 0);
451
-
452
- var _width = propSwiper.width ? +propSwiper.width : rect.width;
453
-
454
- var _height = propSwiper.height ? +propSwiper.height : rect.height;
455
-
456
- size = isVertical ? _height : _width;
457
- trackSize = childCount * Number(size);
458
- var targetOffset = getOffset(_active);
459
- _swiper.current.moving = true;
460
-
461
- if (ready) {
462
- _swiper.current.moving = false;
463
- }
464
-
465
- setRect(rect);
466
- setActive(_active);
467
- setWidth(_width);
468
- setHeight(_height);
469
- setOffset(targetOffset);
470
- setReady(true);
471
- };
472
-
473
- useEffect(function () {
474
- if (ready) {
475
- getStyle();
476
- }
477
- }, [isVertical, width, height, offset, ready]);
478
- useEffect(function () {
479
- if (ready) {
480
- stopAutoPlay();
481
- autoplay();
482
- }
483
-
484
- return function () {
485
- setReady(false);
486
- };
487
- }, [ready]);
488
- useEffect(function () {
489
- stopAutoPlay();
490
- autoplay();
491
- }, [children]);
492
- useEffect(function () {
493
- init();
494
- }, [propSwiper.initPage]);
495
- useEffect(function () {
496
- var target = container.current;
497
- target.addEventListener('touchstart', onTouchStart, false);
498
- target.addEventListener('touchmove', onTouchMove, false);
499
- target.addEventListener('touchend', onTouchEnd, false);
500
- return function () {
501
- target.removeEventListener('touchstart', onTouchStart, false);
502
- target.removeEventListener('touchmove', onTouchMove, false);
503
- target.removeEventListener('touchend', onTouchEnd, false);
504
- };
505
- });
506
- useEffect(function () {
507
- return function () {
508
- stopAutoPlay();
509
- };
510
- }, []);
511
-
512
- var itemStyle = function itemStyle(index) {
513
- var style = {};
514
-
515
- var _direction = propSwiper.direction || direction;
516
-
517
- var _size = size;
518
-
519
- if (_size) {
520
- style[_direction === 'horizontal' ? 'width' : 'height'] = "".concat(_size, "px");
521
- }
522
-
523
- var offset = childOffset[index];
524
-
525
- if (offset) {
526
- style.transform = "translate3D".concat(_direction === 'horizontal' ? "(".concat(offset, "px,0,0)") : "(0,".concat(offset, "px,0)"));
527
- }
528
-
529
- return style;
530
- };
531
-
532
- React__default.useImperativeHandle(ref, function () {
533
- return {
534
- to: to,
535
- next: next,
536
- prev: prev
537
- };
538
- });
539
- return React__default.createElement(DataContext.Provider, {
540
- value: parent
541
- }, React__default.createElement("div", _objectSpread({
542
- className: "".concat(classes, " ").concat(className),
543
- ref: container
544
- }, rest), React__default.createElement("div", {
545
- className: contentClass,
546
- ref: innerRef
547
- }, React__default.Children.map(childs, function (child, index) {
548
- return React__default.createElement("div", {
549
- className: b('item-wrapper'),
550
- style: itemStyle(index),
551
- key: index
552
- }, child);
553
- })), propSwiper.paginationVisible && !('pageContent' in propSwiper) ? React__default.createElement("div", {
554
- className: classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(b('pagination')), true), _defineProperty(_classNames2, "".concat(b('pagination-vertical')), isVertical), _classNames2))
555
- }, React__default.Children.map(childs, function (item, index) {
556
- var _classNames3;
557
-
558
- return React__default.createElement("i", {
559
- style: (active + childCount) % childCount === index ? {
560
- backgroundColor: propSwiper.paginationColor
561
- } : undefined,
562
- className: classNames((_classNames3 = {}, _defineProperty(_classNames3, "".concat(b('pagination-item')), true), _defineProperty(_classNames3, "active", (active + childCount) % childCount === index), _classNames3)),
563
- key: index
564
- });
565
- })) : React__default.createElement("div", null, pageContent)));
566
- });
567
- Swiper.defaultProps = defaultProps$1;
568
- Swiper.displayName = 'NutSwiper';
569
- var defaultProps = {
570
- images: [],
571
- videos: [],
572
- show: false,
573
- autoplay: 3000,
574
- initNo: 1,
575
- contentClose: false,
576
- paginationVisible: false,
577
- paginationColor: '#fff',
578
- onClose: function onClose() {}
579
- };
580
-
581
- var ImagePreview = function ImagePreview(props) {
582
- var images = props.images,
583
- videos = props.videos,
584
- show = props.show,
585
- initNo = props.initNo,
586
- paginationColor = props.paginationColor,
587
- paginationVisible = props.paginationVisible,
588
- autoplay = props.autoplay,
589
- contentClose = props.contentClose,
590
- onClose = props.onClose;
591
- var nutImagePreview = useRef(null);
592
-
593
- var _useState17 = useState(false),
594
- _useState18 = _slicedToArray(_useState17, 2),
595
- showPop = _useState18[0],
596
- setShowPop = _useState18[1];
597
-
598
- var _useState19 = useState(1),
599
- _useState20 = _slicedToArray(_useState19, 2),
600
- active = _useState20[0],
601
- setActive = _useState20[1];
602
-
603
- var _useState21 = useState(1),
604
- _useState22 = _slicedToArray(_useState21, 2),
605
- maxNo = _useState22[0],
606
- setMaxNo = _useState22[1];
607
-
608
- var _useState23 = useState({
609
- scale: 1,
610
- moveable: false
611
- }),
612
- _useState24 = _slicedToArray(_useState23, 2),
613
- store = _useState24[0],
614
- setStore = _useState24[1];
615
-
616
- var _useState25 = useState(0),
617
- _useState26 = _slicedToArray(_useState25, 2),
618
- lastTouchEndTime = _useState26[0],
619
- setLastTouchEndTime = _useState26[1]; // 用来辅助监听双击
620
-
621
-
622
- var onTouchStart = function onTouchStart(event) {
623
- var touches = event.touches;
624
- var events = touches[0];
625
- var events2 = touches[1]; // 如果已经放大,双击应变回原尺寸;如果是原尺寸,双击应放大
626
-
627
- var curTouchTime = new Date().getTime();
628
-
629
- if (curTouchTime - lastTouchEndTime < 300) {
630
- var _store = store;
631
-
632
- if (_store.scale > 1) {
633
- _store.scale = 1;
634
- } else if (_store.scale === 1) {
635
- _store.scale = 2;
636
- }
637
-
638
- scaleNow();
639
- }
640
-
641
- var store1 = store;
642
- store1.moveable = true;
643
-
644
- if (events2) {
645
- // 如果开始两指操作,记录初始时刻两指间的距离
646
- store1.oriDistance = getDistance({
647
- x: events.pageX,
648
- y: events.pageY
649
- }, {
650
- x: events2.pageX,
651
- y: events2.pageY
652
- });
653
- } // 取到开始两指操作时的放大(缩小比例),store.scale 存储的是当前的放缩比(相对于标准大小 scale 为 1 的情况的放大缩小比)
654
-
655
-
656
- store1.originScale = store1.scale || 1;
657
- };
658
-
659
- var onTouchMove = function onTouchMove(event) {
660
- var touches = event.touches;
661
- var events = touches[0];
662
- var events2 = touches[1];
663
-
664
- if (!store.moveable) {
665
- return;
666
- }
667
-
668
- var store1 = store; // 双指移动
669
-
670
- if (events2) {
671
- // 获得当前两点间的距离
672
- var curDistance = getDistance({
673
- x: events.pageX,
674
- y: events.pageY
675
- }, {
676
- x: events2.pageX,
677
- y: events2.pageY
678
- });
679
- /** 此处计算倍数,距离放大(缩小) k 倍则 scale 也 扩大(缩小) k 倍。距离放大(缩小)倍数 = 结束时两点距离 除以 开始时两点距离
680
- * 注意此处的 scale 变化是基于 store.scale 的。
681
- * store.scale 是一个暂存值,比如第一次放大 2 倍,则 store.scale 为 2。
682
- * 再次两指触碰的时候,store.originScale 就为 store.scale 的值,基于此时的 store.scale 继续放大缩小。 * */
683
-
684
- var curScale = curDistance / store1.oriDistance;
685
- store1.scale = store1.originScale * curScale; // 最大放大 3 倍,缩小后松手要弹回原比例
686
-
687
- if (store1.scale > 3) {
688
- store1.scale = 3;
689
- }
690
-
691
- scaleNow();
692
- }
693
- };
694
-
695
- var onTouchEnd = function onTouchEnd() {
696
- setLastTouchEndTime(new Date().getTime());
697
- var store1 = store;
698
- store1.moveable = false;
699
-
700
- if (store1.scale < 1.1 && store1.scale > 1 || store1.scale < 1) {
701
- store1.scale = 1;
702
- scaleNow();
703
- }
704
- };
705
-
706
- var init = function init() {
707
- document.addEventListener('touchmove', onTouchMove);
708
- document.addEventListener('touchend', onTouchEnd);
709
- document.addEventListener('touchcancel', onTouchEnd);
710
- };
711
-
712
- useEffect(function () {
713
- if (show !== undefined) {
714
- setShowPop(show);
715
- init();
716
- }
717
- }, [show]);
718
- useEffect(function () {
719
- if (initNo !== undefined) {
720
- setActive(initNo);
721
- }
722
-
723
- if (show !== undefined) {
724
- setShowPop(show);
725
- }
726
-
727
- if (images && videos) {
728
- setMaxNo(images.length + videos.length);
729
- }
730
- }, []);
731
-
732
- var scaleNow = function scaleNow() {
733
- if (nutImagePreview.current) {
734
- nutImagePreview.current.style.transform = "scale(".concat(store.scale, ")");
735
- }
736
- };
737
-
738
- var onCloseInner = function onCloseInner() {
739
- setShowPop(false);
740
- setActive(1);
741
- scaleNow();
742
- onClose && onClose();
743
- setStore(_objectSpread(_objectSpread({}, store), {}, {
744
- scale: 1
745
- }));
746
- }; // 计算两个点的距离
747
-
748
-
749
- var getDistance = function getDistance(first, second) {
750
- // 计算两个点起始时刻的距离和终止时刻的距离,终止时刻距离变大了则放大,变小了则缩小
751
- // 放大 k 倍则 scale 也 扩大 k 倍
752
- return Math.hypot(Math.abs(second.x - first.x), Math.abs(second.y - first.y));
753
- };
754
-
755
- var slideChangeEnd = function slideChangeEnd(page) {
756
- setActive(page + 1);
757
- };
758
-
759
- var closeOnImg = function closeOnImg() {
760
- // 点击内容区域的图片是否可以关闭弹层(视频区域由于nut-video做了限制,无法关闭弹层)
761
- if (contentClose) {
762
- onCloseInner();
763
- }
764
- };
765
-
766
- return React__default.createElement(Popup, {
767
- visible: showPop,
768
- popClass: "custom-pop",
769
- style: {
770
- width: '100%'
771
- },
772
- onClick: onCloseInner
773
- }, React__default.createElement("div", {
774
- className: "nut-imagepreview",
775
- ref: nutImagePreview,
776
- onClick: closeOnImg,
777
- onTouchStart: onTouchStart
778
- }, React__default.createElement(Swiper, {
779
- autoPlay: autoplay,
780
- className: "nut-imagepreview-swiper",
781
- loop: true,
782
- isPreventDefault: false,
783
- style: {
784
- display: showPop ? 'block' : 'none'
785
- },
786
- direction: "horizontal",
787
- onChange: slideChangeEnd,
788
- initPage: initNo && (initNo > maxNo ? maxNo - 1 : initNo - 1),
789
- paginationColor: paginationColor,
790
- paginationVisible: paginationVisible
791
- }, videos && videos.length > 0 && videos.map(function (item, index) {
792
- return React__default.createElement(SwiperItem, {
793
- key: index
794
- }, React__default.createElement(Video, {
795
- source: item.source,
796
- options: item.options
797
- }));
798
- }), images && images.length > 0 && images.map(function (item, index) {
799
- return React__default.createElement(SwiperItem, {
800
- key: index
801
- }, React__default.createElement("img", {
802
- src: item.src,
803
- alt: "",
804
- className: "nut-imagepreview-img"
805
- }));
806
- }))), React__default.createElement("div", {
807
- className: "nut-imagepreview-index"
808
- }, active, "/", (images ? images.length : 0) + (videos ? videos.length : 0)));
809
- };
810
-
811
- ImagePreview.defaultProps = defaultProps;
812
- ImagePreview.displayName = 'NutImagePreview';
813
- export { ImagePreview as I };