@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.
Files changed (219) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/esm/Address.js +5 -5
  3. package/dist/esm/Audio.js +5 -5
  4. package/dist/esm/AvatarContext-7153ad2b.js +3 -1
  5. package/dist/esm/AvatarGroup.js +4 -4
  6. package/dist/esm/Calendar.js +5 -5
  7. package/dist/esm/CalendarItem.js +4 -4
  8. package/dist/esm/Card.js +4 -3
  9. package/dist/esm/Cell.js +2 -2
  10. package/dist/esm/ConfigProvider.js +3 -3
  11. package/dist/esm/CountDown.js +4 -4
  12. package/dist/esm/DatePicker.js +5 -5
  13. package/dist/esm/Dialog.js +4 -4
  14. package/dist/esm/Ellipsis.js +4 -4
  15. package/dist/esm/Empty.js +4 -4
  16. package/dist/esm/FixedNav.js +4 -4
  17. package/dist/esm/Form.js +4 -4
  18. package/dist/esm/FormItem.js +3 -3
  19. package/dist/esm/Grid.js +4 -4
  20. package/dist/esm/GridItem.js +4 -4
  21. package/dist/esm/Image.js +4 -4
  22. package/dist/esm/Infiniteloading.js +4 -4
  23. package/dist/esm/Input.js +4 -4
  24. package/dist/esm/MenuItem.js +4 -4
  25. package/dist/esm/NoticeBar.js +2 -2
  26. package/dist/esm/NumberKeyboard.js +4 -4
  27. package/dist/esm/Pagination.js +4 -4
  28. package/dist/esm/Picker.js +4 -4
  29. package/dist/esm/PullToRefresh.js +4 -4
  30. package/dist/esm/Range.js +4 -4
  31. package/dist/esm/SearchBar.js +4 -4
  32. package/dist/esm/ShortPassword.js +4 -4
  33. package/dist/esm/SideNavBar.js +4 -4
  34. package/dist/esm/Signature.js +4 -4
  35. package/dist/esm/Sticky.js +4 -4
  36. package/dist/esm/Table.js +4 -4
  37. package/dist/esm/Tag.js +3 -2
  38. package/dist/esm/TextArea.js +4 -4
  39. package/dist/esm/TimeDetail.js +4 -4
  40. package/dist/esm/TimePannel.js +4 -4
  41. package/dist/esm/TimeSelect.js +6 -6
  42. package/dist/esm/Uploader.js +4 -4
  43. package/dist/esm/UserContext-68f62e66.js +3 -1
  44. package/dist/esm/UserContext-b4181162.js +3 -1
  45. package/dist/esm/UserContext-be8097d2.js +3 -1
  46. package/dist/esm/VirtualList.js +6 -4
  47. package/dist/esm/WaterMark.js +4 -4
  48. package/dist/esm/actionsheet.taro-a58d3d12.js +45 -83
  49. package/dist/esm/address.taro-79cc7c96.js +461 -0
  50. package/dist/esm/animate.taro-b0e83dd5.js +32 -46
  51. package/dist/esm/animatingnumbers.taro-6f40a2e9.js +93 -134
  52. package/dist/esm/audio.taro-4fadc583.js +161 -0
  53. package/dist/esm/avatar.taro-85ced995.js +93 -119
  54. package/dist/esm/avatargroup-1d900174.js +34 -0
  55. package/dist/esm/backtop.taro-99107c30.js +39 -62
  56. package/dist/esm/badge.taro-fe9171ec.js +40 -58
  57. package/dist/esm/barrage.taro-0e157b5e.js +61 -91
  58. package/dist/esm/bem-893ad28d.js +3 -6
  59. package/dist/esm/button.taro-4ce133b9.js +87 -98
  60. package/dist/esm/calendar.taro-4ed72058.js +38 -0
  61. package/dist/esm/calendaritem.taro-1ebe428d.js +571 -0
  62. package/dist/esm/card.taro-39055e82.js +32 -0
  63. package/dist/esm/cascader.taro-d8cb1c3e.js +397 -636
  64. package/dist/esm/cell.taro-9a04a92e.js +64 -0
  65. package/dist/esm/cellgroup.taro-e094471c.js +18 -27
  66. package/dist/esm/checkbox.taro-0bda9796.js +160 -232
  67. package/dist/esm/circleprogress.taro-47db537c.js +99 -120
  68. package/dist/esm/col.taro-b61c7cba.js +33 -50
  69. package/dist/esm/collapse.taro-af58206c.js +73 -86
  70. package/dist/esm/collapseitem-ce1849d2.js +75 -139
  71. package/dist/esm/configprovider-5eea4f5d.js +19 -0
  72. package/dist/esm/configprovider.taro-26882dd2.js +42 -0
  73. package/dist/esm/countdown.taro-9e40de9c.js +225 -0
  74. package/dist/esm/datepicker.taro-7220e495.js +270 -0
  75. package/dist/esm/dialog.taro-1c03960e.js +123 -0
  76. package/dist/esm/divider.taro-5236fe6a.js +27 -27
  77. package/dist/esm/drag.taro-82b6b27a.js +99 -138
  78. package/dist/esm/elevator.taro-d7d65470.js +185 -259
  79. package/dist/esm/ellipsis.taro-49b6db0c.js +232 -0
  80. package/dist/esm/empty.taro-7bd813f9.js +62 -0
  81. package/dist/esm/fixednav.taro-5ad15202.js +53 -0
  82. package/dist/esm/form.taro-71d32671.js +179 -0
  83. package/dist/esm/formitem.taro-3089489b.js +89 -0
  84. package/dist/esm/grid.taro-e6decfce.js +58 -0
  85. package/dist/esm/grid.taro.context-39636af9.js +4 -2
  86. package/dist/esm/griditem.taro-4cade72e.js +90 -0
  87. package/dist/esm/icon-8dc4de10.js +43 -51
  88. package/dist/esm/icon.taro-1d0d4fb7.js +43 -51
  89. package/dist/esm/image.taro-e6dc5867.js +64 -0
  90. package/dist/esm/imagepreview.taro-3400ea03.js +158 -205
  91. package/dist/esm/index.taro-a36f96fb.js +149 -210
  92. package/dist/esm/indicator.taro-183ea169.js +29 -43
  93. package/dist/esm/infiniteloading.taro-6c2a2e95.js +142 -0
  94. package/dist/esm/input.taro-fd566407.js +243 -0
  95. package/dist/esm/inputnumber.taro-dc39b853.js +129 -177
  96. package/dist/esm/layout.taro-358f014f.js +6 -9
  97. package/dist/esm/menu.taro-4abed328.js +89 -132
  98. package/dist/esm/menuitem.taro-6e8b27c3.js +130 -0
  99. package/dist/esm/navbar.taro-c931c078.js +69 -105
  100. package/dist/esm/noticebar.taro-69ea7673.js +450 -0
  101. package/dist/esm/notify.taro-308e5892.js +66 -97
  102. package/dist/esm/numberkeyboard.taro-194519e4.js +158 -0
  103. package/dist/esm/nutui-react.es.js +44 -44
  104. package/dist/esm/offsetContext-bfb02c25.js +3 -1
  105. package/dist/esm/overlay.taro-98367bc1.js +59 -74
  106. package/dist/esm/pagination.taro-bb490de9.js +124 -0
  107. package/dist/esm/picker.taro-2a8ded7c.js +420 -0
  108. package/dist/esm/popover.taro-46d813e8.js +132 -222
  109. package/dist/esm/popup.taro-cb777e09.js +125 -178
  110. package/dist/esm/price.taro-8801462e.js +75 -86
  111. package/dist/esm/progress.taro-623bc807.js +84 -118
  112. package/dist/esm/pulltorefresh.taro-cab7b51c.js +221 -0
  113. package/dist/esm/range.taro-5d6ff217.js +332 -0
  114. package/dist/esm/rate.taro-10197384.js +64 -111
  115. package/dist/esm/row.taro-37a895de.js +38 -42
  116. package/dist/esm/searchbar.taro-839dd622.js +148 -0
  117. package/dist/esm/shortpassword.taro-182d46f7.js +111 -0
  118. package/dist/esm/sidenavbar.taro-006cf38b.js +35 -0
  119. package/dist/esm/sidenavbaritem.taro-fee11d26.js +9 -22
  120. package/dist/esm/signature.taro-33632585.js +143 -0
  121. package/dist/esm/skeleton.taro-853ce460.js +51 -88
  122. package/dist/esm/step.taro-1c94e067.js +49 -78
  123. package/dist/esm/steps.taro-acf205a0.js +21 -30
  124. package/dist/esm/sticky.taro-d0553f48.js +13 -0
  125. package/dist/esm/subsidenavbar.taro-f46b4c73.js +58 -75
  126. package/dist/esm/swipe.taro-83bc248f.js +164 -254
  127. package/dist/esm/swiper.taro-852f6615.js +424 -505
  128. package/dist/esm/swiperitem-86a3578a.js +20 -28
  129. package/dist/esm/switch.taro-bae2dca0.js +43 -64
  130. package/dist/esm/tabbar.taro-86cece39.js +47 -57
  131. package/dist/esm/tabbaritem.taro-8dfb8055.js +51 -79
  132. package/dist/esm/table.taro-cb4dd2c3.js +92 -0
  133. package/dist/esm/tabpane.taro-91cd6cf4.js +17 -22
  134. package/dist/esm/tabs.taro-e71875fa.js +121 -165
  135. package/dist/esm/tag.taro-00fe554d.js +89 -0
  136. package/dist/esm/textarea.taro-42600f8c.js +74 -0
  137. package/dist/esm/timedetail.taro-c5f564fd.js +44 -0
  138. package/dist/esm/timepannel.taro-29f9dd86.js +22 -0
  139. package/dist/esm/timeselect.taro-3ecce65d.js +133 -0
  140. package/dist/esm/toast.taro-0804b6b4.js +99 -137
  141. package/dist/esm/trendarrow.taro-5a7153e4.js +63 -90
  142. package/dist/esm/types/src/packages/cell/cell.taro.d.ts +0 -1
  143. package/dist/esm/types/src/packages/noticebar/noticebar.d.ts +5 -4
  144. package/dist/esm/types/src/packages/noticebar/noticebar.taro.d.ts +5 -4
  145. package/dist/esm/types/src/packages/uploader/uploader.d.ts +1 -1
  146. package/dist/esm/types/src/packages/virtuallist/virtuallist.taro.d.ts +13 -2
  147. package/dist/esm/typings-1c5f2628.js +7 -6
  148. package/dist/esm/uploader.taro-f80d76d9.js +392 -0
  149. package/dist/esm/useClientRect-bf69d7b3.js +5 -25
  150. package/dist/esm/useTouch-a2ea68c6.js +63 -93
  151. package/dist/esm/video-8a3518c5.js +59 -83
  152. package/dist/esm/virtuallist.taro-e3345ced.js +215 -0
  153. package/dist/esm/watermark.taro-cd9db98a.js +114 -0
  154. package/dist/esm/zh-CN-dfc384d0.js +128 -133
  155. package/dist/locales/base.js +1 -1
  156. package/dist/locales/en-US.js +1 -1
  157. package/dist/locales/id-ID.js +1 -1
  158. package/dist/locales/zh-CN.js +1 -1
  159. package/dist/locales/zh-TW.js +1 -1
  160. package/dist/locales/zh-UG.js +1 -1
  161. package/dist/nutui.react.es.js +634 -5664
  162. package/dist/nutui.react.umd.js +634 -5664
  163. package/dist/packages/noticebar/noticebar.scss +17 -0
  164. package/dist/packages/radio/radio.scss +3 -1
  165. package/dist/packages/row/row.scss +2 -0
  166. package/dist/packages/searchbar/searchbar.scss +1 -1
  167. package/dist/packages/tag/tag.scss +13 -5
  168. package/dist/packages/virtuallist/virtuallist.scss +24 -0
  169. package/dist/style.css +1 -1
  170. package/dist/style.es.js +1 -1
  171. package/dist/styles/temp.scss +2340 -0
  172. package/dist/styles/theme-dark.scss +7 -0
  173. package/dist/styles/theme-default.scss +11 -0
  174. package/dist/styles/variables.scss +1945 -710
  175. package/dist/types/index.d.ts +16 -23
  176. package/package.json +9 -4
  177. package/dist/esm/address.taro-1e2aea24.js +0 -615
  178. package/dist/esm/audio.taro-fddcdfc0.js +0 -228
  179. package/dist/esm/avatargroup-f7f600ff.js +0 -42
  180. package/dist/esm/calendar.taro-72974415.js +0 -83
  181. package/dist/esm/calendaritem.taro-84e889eb.js +0 -580
  182. package/dist/esm/card.taro-a530dfb3.js +0 -61
  183. package/dist/esm/cell.taro-cf50c4f2.js +0 -109
  184. package/dist/esm/configprovider-c7d60e20.js +0 -18
  185. package/dist/esm/configprovider.taro-8bdb3a28.js +0 -50
  186. package/dist/esm/countdown.taro-d7dc8681.js +0 -246
  187. package/dist/esm/datepicker.taro-7199f521.js +0 -304
  188. package/dist/esm/dialog.taro-f54cfbf0.js +0 -187
  189. package/dist/esm/ellipsis.taro-c0de6ff4.js +0 -309
  190. package/dist/esm/empty.taro-dbc66496.js +0 -81
  191. package/dist/esm/fixednav.taro-9e759320.js +0 -97
  192. package/dist/esm/form.taro-880014b1.js +0 -181
  193. package/dist/esm/formitem.taro-3695f4a7.js +0 -136
  194. package/dist/esm/grid.taro-c2cc12d6.js +0 -81
  195. package/dist/esm/griditem.taro-892153cd.js +0 -122
  196. package/dist/esm/image.taro-c30973d5.js +0 -105
  197. package/dist/esm/infiniteloading.taro-b5ddf3cc.js +0 -188
  198. package/dist/esm/input.taro-104130c1.js +0 -361
  199. package/dist/esm/menuitem.taro-216e9f7d.js +0 -193
  200. package/dist/esm/noticebar.taro-94002898.js +0 -368
  201. package/dist/esm/numberkeyboard.taro-5e8f0ddf.js +0 -245
  202. package/dist/esm/pagination.taro-9925ffab.js +0 -169
  203. package/dist/esm/picker.taro-3b5cc054.js +0 -540
  204. package/dist/esm/pulltorefresh.taro-f26a20dd.js +0 -302
  205. package/dist/esm/range.taro-c41e9b90.js +0 -469
  206. package/dist/esm/searchbar.taro-01ed4ea4.js +0 -236
  207. package/dist/esm/shortpassword.taro-3a3bf412.js +0 -190
  208. package/dist/esm/sidenavbar.taro-06026f31.js +0 -66
  209. package/dist/esm/signature.taro-17648cac.js +0 -192
  210. package/dist/esm/sticky.taro-36013e97.js +0 -16
  211. package/dist/esm/table.taro-adda6622.js +0 -139
  212. package/dist/esm/tag.taro-bd900990.js +0 -104
  213. package/dist/esm/textarea.taro-83d5fe73.js +0 -102
  214. package/dist/esm/timedetail.taro-105f5380.js +0 -68
  215. package/dist/esm/timepannel.taro-c66c63dd.js +0 -30
  216. package/dist/esm/timeselect.taro-fc7ec6ee.js +0 -172
  217. package/dist/esm/uploader.taro-a1edf38f.js +0 -529
  218. package/dist/esm/virtuallist.taro-4add61c3.js +0 -315
  219. package/dist/esm/watermark.taro-323d1cf3.js +0 -132
@@ -1,91 +1,67 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["children", "source", "options", "className", "play", "pause", "playend", "onPlayFuc", "onPauseFuc", "onPlayend"];
4
- 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; }
5
- 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; }
6
1
  import React__default, { useRef, useEffect } from 'react';
7
2
  import classNames from 'classnames';
8
3
  import { c as cn } from './bem-893ad28d.js';
9
- var defaultProps = {
10
- source: {
11
- type: {},
12
- src: ''
13
- },
14
- options: {
15
- controls: true,
16
- muted: false,
17
- autoplay: false,
18
- poster: '',
19
- playsinline: false,
20
- loop: false
21
- }
4
+
5
+ const defaultProps = {
6
+ source: {
7
+ type: {},
8
+ src: '',
9
+ },
10
+ options: {
11
+ controls: true,
12
+ muted: false,
13
+ autoplay: false,
14
+ poster: '',
15
+ playsinline: false,
16
+ loop: false,
17
+ },
22
18
  };
23
- var Video = function Video(props) {
24
- var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props),
25
- children = _defaultProps$props.children,
26
- source = _defaultProps$props.source,
27
- options = _defaultProps$props.options,
28
- className = _defaultProps$props.className,
29
- play = _defaultProps$props.play,
30
- pause = _defaultProps$props.pause,
31
- playend = _defaultProps$props.playend,
32
- onPlayFuc = _defaultProps$props.onPlayFuc,
33
- onPauseFuc = _defaultProps$props.onPauseFuc,
34
- onPlayend = _defaultProps$props.onPlayend,
35
- restProps = _objectWithoutProperties(_defaultProps$props, _excluded);
36
- var rootRef = useRef(null);
37
- var b = cn('video');
38
- var classes = classNames(className, b(''));
39
- useEffect(function () {
40
- init();
41
- }, []);
42
- var init = function init() {
43
- if (rootRef.current) {
44
- var videoRef = rootRef.current;
45
- if (options.autoplay) {
46
- setTimeout(function () {
47
- videoRef.play();
48
- }, 200);
49
- }
50
- if (options.playsinline) {
51
- videoRef.setAttribute('playsinline', String(options.playsinline));
52
- videoRef.setAttribute('webkit-playsinline', String(options.playsinline));
53
- videoRef.setAttribute('x5-video-player-type', 'h5-page');
54
- videoRef.setAttribute('x5-video-player-fullscreen', 'false');
55
- }
56
- videoRef.addEventListener('play', function () {
57
- onPlayFuc && onPlayFuc(videoRef);
58
- play && play(videoRef);
59
- });
60
- videoRef.addEventListener('pause', function () {
61
- onPauseFuc && onPauseFuc(videoRef);
62
- pause && pause(videoRef);
63
- });
64
- videoRef.addEventListener('ended', function () {
65
- videoRef.currentTime = 0;
66
- onPlayend && onPlayend(videoRef);
67
- playend && playend(videoRef);
68
- });
69
- }
70
- };
71
- return React__default.createElement("div", _objectSpread({
72
- className: classes
73
- }, restProps), React__default.createElement("video", {
74
- className: "nut-video-player",
75
- muted: options.muted,
76
- autoPlay: options.autoplay,
77
- loop: options.loop,
78
- poster: options.poster,
79
- controls: options.controls,
80
- ref: rootRef,
81
- src: source.src
82
- }, React__default.createElement("source", {
83
- src: source.src,
84
- type: source.type
85
- }), React__default.createElement("track", {
86
- kind: "captions"
87
- })));
19
+ const Video = (props) => {
20
+ const { children, source, options, className, play, pause, playend, onPlayFuc, onPauseFuc, onPlayend, ...restProps } = {
21
+ ...defaultProps,
22
+ ...props,
23
+ };
24
+ const rootRef = useRef(null);
25
+ const b = cn('video');
26
+ const classes = classNames(className, b(''));
27
+ useEffect(() => {
28
+ init();
29
+ }, []);
30
+ const init = () => {
31
+ if (rootRef.current) {
32
+ const videoRef = rootRef.current;
33
+ if (options.autoplay) {
34
+ setTimeout(() => {
35
+ videoRef.play();
36
+ }, 200);
37
+ }
38
+ if (options.playsinline) {
39
+ videoRef.setAttribute('playsinline', String(options.playsinline));
40
+ videoRef.setAttribute('webkit-playsinline', String(options.playsinline));
41
+ videoRef.setAttribute('x5-video-player-type', 'h5-page');
42
+ videoRef.setAttribute('x5-video-player-fullscreen', 'false');
43
+ }
44
+ videoRef.addEventListener('play', () => {
45
+ onPlayFuc && onPlayFuc(videoRef);
46
+ play && play(videoRef);
47
+ });
48
+ videoRef.addEventListener('pause', () => {
49
+ onPauseFuc && onPauseFuc(videoRef);
50
+ pause && pause(videoRef);
51
+ });
52
+ videoRef.addEventListener('ended', () => {
53
+ videoRef.currentTime = 0;
54
+ onPlayend && onPlayend(videoRef);
55
+ playend && playend(videoRef);
56
+ });
57
+ }
58
+ };
59
+ return (React__default.createElement("div", { className: classes, ...restProps },
60
+ React__default.createElement("video", { className: "nut-video-player", muted: options.muted, autoPlay: options.autoplay, loop: options.loop, poster: options.poster, controls: options.controls, ref: rootRef, src: source.src },
61
+ React__default.createElement("source", { src: source.src, type: source.type }),
62
+ React__default.createElement("track", { kind: "captions" }))));
88
63
  };
89
64
  Video.defaultProps = defaultProps;
90
65
  Video.displayName = 'NutVideo';
66
+
91
67
  export { Video as V };
@@ -0,0 +1,215 @@
1
+ import React__default, { useState, useRef, useEffect, useCallback } from 'react';
2
+ import { ScrollView } from '@tarojs/components';
3
+ import Taro from '@tarojs/taro';
4
+ import { u as useConfig } from './configprovider.taro-26882dd2.js';
5
+
6
+ // 缓存列表初始化信息
7
+ const initPositinoCache = (reaItemSize, length = 0) => {
8
+ let index = 0;
9
+ const positions = Array(length);
10
+ while (index < length) {
11
+ positions[index] = {
12
+ index,
13
+ height: reaItemSize,
14
+ width: reaItemSize,
15
+ top: index * reaItemSize,
16
+ bottom: (index + 1) * reaItemSize,
17
+ left: index * reaItemSize,
18
+ right: (index + 1) * reaItemSize,
19
+ };
20
+ index++;
21
+ }
22
+ return positions;
23
+ };
24
+ // 通过二分法找到 scrollOffset 对应的值
25
+ const binarySearch = (positionsList, value = 0, horizontal) => {
26
+ let start = 0;
27
+ let end = positionsList.length - 1;
28
+ let tempIndex = null;
29
+ const key = horizontal ? 'right' : 'bottom';
30
+ while (start <= end) {
31
+ const midIndex = Math.floor((start + end) / 2);
32
+ const midValue = positionsList[midIndex][key];
33
+ // 相等则直接返回(因为是bottom, 因此startIndex应该是下一个节点)
34
+ if (midValue === value) {
35
+ return midIndex + 1;
36
+ }
37
+ // 中间值 < 传入值,则说明 value对应的节点 大于 start, start往后移动一位
38
+ if (midValue < value) {
39
+ start = midIndex + 1;
40
+ }
41
+ // 中间值 > 传入值,则说明 value 在 中间值之前,end 节点移动到 mid - 1
42
+ else if (midValue > value) {
43
+ // tempIndex存放最靠近值为value的所有
44
+ if (tempIndex === null || tempIndex > midIndex) {
45
+ tempIndex = midIndex;
46
+ }
47
+ end = midIndex - 1;
48
+ }
49
+ }
50
+ tempIndex = tempIndex || 0;
51
+ return tempIndex;
52
+ };
53
+ // 更新Item大小
54
+ const updateItemSize = (positions, items, sizeKey) => {
55
+ const newPos = positions.concat();
56
+ Array.from(items).forEach((item) => {
57
+ const index = Number(item.getAttribute('data-index'));
58
+ const styleVal = item.getAttribute('style');
59
+ if (styleVal && styleVal.includes('none'))
60
+ return;
61
+ const nowSize = item.getBoundingClientRect()[sizeKey];
62
+ const oldSize = positions[index][sizeKey];
63
+ // 存在差值, 更新该节点以后所有的节点
64
+ const dValue = oldSize - nowSize;
65
+ if (dValue) {
66
+ if (sizeKey === 'width') {
67
+ newPos[index].right -= dValue;
68
+ newPos[index][sizeKey] = nowSize;
69
+ for (let k = index + 1; k < positions.length; k++) {
70
+ newPos[k].left = positions[k - 1].right;
71
+ newPos[k].right -= dValue;
72
+ }
73
+ }
74
+ else if (sizeKey === 'height') {
75
+ newPos[index].bottom -= dValue;
76
+ newPos[index][sizeKey] = nowSize;
77
+ for (let k = index + 1; k < positions.length; k++) {
78
+ newPos[k].top = positions[k - 1].bottom;
79
+ newPos[k].bottom -= dValue;
80
+ }
81
+ }
82
+ }
83
+ });
84
+ };
85
+
86
+ const defaultProps = {
87
+ sourceData: [],
88
+ itemSize: 66,
89
+ itemEqualSize: true,
90
+ overscan: 2,
91
+ };
92
+ const clientHeight = Taro.getSystemInfoSync().windowHeight - 5 || 667;
93
+ Taro.getSystemInfoSync().windowWidth || 375;
94
+ const VirtualList = (props) => {
95
+ const { sourceData = [], ItemRender, itemSize = 66, itemEqualSize = true, overscan = 2, key, onScroll, className, containerSize = clientHeight, ...rest } = props;
96
+ // const sizeKey = horizontal ? 'width' : 'height'
97
+ // const scrollKey = horizontal ? 'scrollLeft' : 'scrollTop'
98
+ // const offsetKey = horizontal ? 'left' : 'top'
99
+ const [startOffset, setStartOffset] = useState(0);
100
+ const [start, setStart] = useState(0);
101
+ const [list, setList] = useState(sourceData.slice());
102
+ useConfig();
103
+ // 虚拟列表容器ref
104
+ const scrollRef = useRef(null);
105
+ // 虚拟列表显示区域ref
106
+ const itemsRef = useRef(null);
107
+ const firstItemRef = useRef(null);
108
+ // 列表位置信息
109
+ const [positions, setPositions] = useState([
110
+ {
111
+ index: 0,
112
+ left: 0,
113
+ top: 0,
114
+ bottom: 0,
115
+ width: 0,
116
+ height: 0,
117
+ right: 0,
118
+ },
119
+ ]);
120
+ const [offSetSize, setOffSetSize] = useState(containerSize || 0);
121
+ const [options, setOptions] = useState({
122
+ startOffset: 0,
123
+ startIndex: 0,
124
+ overStart: 0,
125
+ endIndex: 10, // 可视区域结束索引
126
+ });
127
+ useEffect(() => {
128
+ if (sourceData.length) {
129
+ setList(sourceData.slice());
130
+ }
131
+ }, [sourceData]);
132
+ // 初始计算可视区域展示数量
133
+ useEffect(() => {
134
+ setPositions((options) => {
135
+ return { ...options, endIndex: visibleCount() };
136
+ });
137
+ }, [itemSize, overscan, offSetSize]);
138
+ useEffect(() => {
139
+ if (containerSize)
140
+ return;
141
+ setOffSetSize(getContainerHeight());
142
+ }, [containerSize]);
143
+ useEffect(() => {
144
+ const pos = initPositinoCache(itemSize, sourceData.length);
145
+ setPositions(pos);
146
+ }, [itemSize, sourceData]);
147
+ // 可视区域总高度
148
+ const getContainerHeight = () => {
149
+ //初始首页列表高度
150
+ const initH = itemSize * sourceData.length;
151
+ //未设置containerSize高度,判断首页高度小于设备高度时,滚动容器高度为首页数据高度,减5为分页触发的偏移量
152
+ let containerH = initH < clientHeight
153
+ ? initH + overscan * itemSize - 5
154
+ : Math.min(containerSize, clientHeight);
155
+ return containerH; // Math.min(containerSize, clientHeight)
156
+ };
157
+ // 可视区域条数
158
+ const visibleCount = () => {
159
+ return Math.ceil(getContainerHeight() / itemSize) + overscan;
160
+ };
161
+ const end = () => {
162
+ return start + visibleCount();
163
+ };
164
+ const listHeight = () => {
165
+ return list.length * itemSize;
166
+ };
167
+ const visibleData = () => {
168
+ return list.slice(start, Math.min(end(), list.length));
169
+ };
170
+ const updateTotalSize = useCallback(() => {
171
+ if (!itemsRef.current)
172
+ return;
173
+ const items = itemsRef.current.children;
174
+ if (!items.length)
175
+ return;
176
+ // 更新缓存
177
+ updateItemSize(positions, items, 'height');
178
+ }, [positions]);
179
+ // 滚动监听
180
+ const listScroll = (e) => {
181
+ const scrollTop = e.detail ? e.detail.scrollTop : e.target.scrollTop;
182
+ const scrollSize = Math.floor(scrollTop);
183
+ const startIndex = binarySearch(positions, scrollSize, false);
184
+ const overStart = startIndex - overscan > -1 ? startIndex - overscan : 0;
185
+ const endIndex = end();
186
+ if (!itemEqualSize) {
187
+ updateTotalSize();
188
+ }
189
+ setStart(Math.floor(scrollTop / itemSize));
190
+ setOptions({ startOffset, startIndex, overStart, endIndex });
191
+ if (end() > list.length - 1) {
192
+ onScroll && onScroll();
193
+ }
194
+ setStartOffset(scrollTop - (scrollTop % itemSize));
195
+ };
196
+ return (React__default.createElement("div", { className: className ? `${className} nut-virtualList-box` : 'nut-virtualList-box', ...rest, style: {
197
+ height: containerSize ? `${offSetSize}px` : '',
198
+ } },
199
+ React__default.createElement(ScrollView, { scrollTop: 0, scrollY: true, ref: scrollRef, className: "nut-virtuallist", style: {
200
+ height: `${getContainerHeight()}px`,
201
+ }, onScroll: listScroll },
202
+ React__default.createElement("div", { className: "nut-virtuallist-phantom", style: { height: `${listHeight()}px` } }),
203
+ React__default.createElement("div", { className: "nut-virtuallist-container", ref: itemsRef, style: { transform: `translate3d(0, ${startOffset}px, 0)` } }, visibleData().map((data, index) => {
204
+ const { overStart } = options;
205
+ const dataIndex = overStart + index;
206
+ key && data[key] ? data[key] : dataIndex;
207
+ return (React__default.createElement("div", { ref: dataIndex === 0 ? firstItemRef : null, "data-index": `${dataIndex}`, className: "nut-virtuallist-item", key: `${data}`, style: {
208
+ height: `${itemEqualSize ? `${itemSize}px` : 'auto'}`,
209
+ } }, ItemRender ? (React__default.createElement(ItemRender, { data: data, index: `${index}` })) : (data)));
210
+ })))));
211
+ };
212
+ VirtualList.defaultProps = defaultProps;
213
+ VirtualList.displayName = 'NutVirtualList';
214
+
215
+ export { VirtualList as V };
@@ -0,0 +1,114 @@
1
+ import React__default, { useState, useEffect } from 'react';
2
+ import { u as useConfig } from './configprovider-5eea4f5d.js';
3
+ import Taro from '@tarojs/taro';
4
+ import classNames from 'classnames';
5
+ import { c as cn } from './bem-893ad28d.js';
6
+
7
+ const defaultProps = {
8
+ content: '',
9
+ fullPage: true,
10
+ zIndex: 2000,
11
+ gapX: 24,
12
+ gapY: 48,
13
+ width: 120,
14
+ height: 64,
15
+ image: '',
16
+ imageWidth: 120,
17
+ imageHeight: 64,
18
+ rotate: -22,
19
+ fontColor: 'rgba(0,0,0,.15)',
20
+ fontStyle: 'normal',
21
+ fontFamily: 'PingFang SC',
22
+ fontWeight: 'normal',
23
+ fontSize: 14,
24
+ };
25
+ const WaterMark = (props) => {
26
+ const { locale } = useConfig();
27
+ const { content, fullPage, zIndex, className, gapX, gapY, width, height, image, imageWidth, imageHeight, rotate, fontColor, fontStyle, fontFamily, fontWeight, fontSize, style, children, } = {
28
+ ...defaultProps,
29
+ ...props,
30
+ };
31
+ const [base64Url, setBase64Url] = useState('');
32
+ const b = cn('watermark');
33
+ const classes = classNames({
34
+ [`${b('')}`]: true,
35
+ [`${b('')}-full-page`]: fullPage,
36
+ });
37
+ const cls = classNames(classes, className);
38
+ useEffect(() => {
39
+ init();
40
+ }, []);
41
+ const init = () => {
42
+ let ratio = 1;
43
+ Taro.getSystemInfo().then((res) => {
44
+ ratio = res.pixelRatio;
45
+ const canvasWidth = `${(gapX + width) * ratio}px`;
46
+ const canvasHeight = `${(gapY + height) * ratio}px`;
47
+ const markWidth = width * ratio;
48
+ const markHeight = height * ratio;
49
+ let ctx;
50
+ let canvas;
51
+ if (process.env.TARO_ENV === 'h5') {
52
+ canvas = document.createElement('canvas');
53
+ ctx = canvas.getContext('2d');
54
+ canvas.setAttribute('width', canvasWidth);
55
+ canvas.setAttribute('height', canvasHeight);
56
+ }
57
+ else {
58
+ canvas = Taro.createOffscreenCanvas({
59
+ type: '2d',
60
+ width: Number(canvasWidth),
61
+ height: Number(canvasHeight),
62
+ });
63
+ ctx = canvas.getContext('2d');
64
+ }
65
+ if (ctx) {
66
+ if (image) {
67
+ ctx.translate(markWidth / 2, markHeight / 2);
68
+ ctx.rotate((Math.PI / 180) * Number(rotate));
69
+ let img;
70
+ if (process.env.TARO_ENV === 'h5') {
71
+ img = new Image();
72
+ }
73
+ else {
74
+ img = canvas.createImage();
75
+ }
76
+ img.crossOrigin = 'anonymous';
77
+ img.referrerPolicy = 'no-referrer';
78
+ img.src = image;
79
+ img.onload = () => {
80
+ ctx.drawImage(img, (-imageWidth * ratio) / 2, (-imageHeight * ratio) / 2, imageWidth * ratio, imageHeight * ratio);
81
+ ctx.restore();
82
+ setBase64Url(canvas.toDataURL());
83
+ };
84
+ }
85
+ else if (content) {
86
+ ctx.textBaseline = 'middle'; // 设置或返回在绘制文本时使用的当前文本基线。(正中)
87
+ ctx.textAlign = 'center'; // 设置或返回文本内容的当前对齐方式。
88
+ // 文字绕中间旋转
89
+ ctx.translate(markWidth / 2, markHeight / 2);
90
+ ctx.rotate((Math.PI / 180) * Number(rotate));
91
+ const markSize = Number(fontSize) * ratio;
92
+ ctx.font = `${fontStyle} normal ${fontWeight} ${markSize}px/${markHeight}px ${fontFamily}`;
93
+ ctx.fillStyle = fontColor;
94
+ ctx.fillText(content, 0, 0); // 在画布上绘制"被填充的"文本。
95
+ ctx.restore(); // 返回之前保存过的路径状态和属性。
96
+ setBase64Url(canvas.toDataURL());
97
+ }
98
+ }
99
+ else {
100
+ throw new Error(locale.watermark.errorCanvasTips);
101
+ }
102
+ });
103
+ };
104
+ return (React__default.createElement("div", { className: cls, style: {
105
+ zIndex,
106
+ backgroundSize: `${gapX + width}px`,
107
+ backgroundImage: `url('${base64Url}')`,
108
+ ...style,
109
+ } }));
110
+ };
111
+ WaterMark.defaultProps = defaultProps;
112
+ WaterMark.displayName = 'NutWaterMark';
113
+
114
+ export { WaterMark as W };