@salutejs/plasma-core 1.226.1-next-sbcom.0 → 1.227.0-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/__helpers/IconPlaceholder.js +6 -9
  2. package/__helpers/index.js +1 -1
  3. package/collectPackageInfo.js +4 -4
  4. package/components/Badge/Badge.js +30 -103
  5. package/components/Badge/index.js +1 -1
  6. package/components/Basebox/Basebox.js +33 -42
  7. package/components/Basebox/index.js +1 -1
  8. package/components/Button/Button.js +28 -67
  9. package/components/Button/Button.mixins.js +22 -76
  10. package/components/Button/Button.props.js +5 -5
  11. package/components/Button/createButton.js +14 -145
  12. package/components/Button/index.js +4 -4
  13. package/components/Card/Card.js +34 -162
  14. package/components/Card/CardBody.js +4 -4
  15. package/components/Card/CardContent.js +14 -23
  16. package/components/Card/CardMedia.js +20 -91
  17. package/components/Card/CardPrice.js +18 -60
  18. package/components/Card/CardTypography.js +43 -52
  19. package/components/Card/index.js +5 -5
  20. package/components/Carousel/Carousel.js +46 -64
  21. package/components/Carousel/CarouselItem.js +21 -93
  22. package/components/Carousel/hooks.js +62 -121
  23. package/components/Carousel/index.js +3 -3
  24. package/components/Carousel/utils.js +59 -73
  25. package/components/Fade/Fade.js +6 -9
  26. package/components/Fade/index.js +1 -1
  27. package/components/Field/Field.js +48 -63
  28. package/components/Field/Field.statuses.js +3 -3
  29. package/components/Field/index.js +2 -2
  30. package/components/Image/Image.js +34 -115
  31. package/components/Image/index.js +1 -1
  32. package/components/Input/Input.js +7 -7
  33. package/components/Input/Input.mixins.js +9 -12
  34. package/components/Input/index.js +1 -1
  35. package/components/ModalBase/ModalBase.js +22 -100
  36. package/components/ModalBase/ModalBaseContext.js +6 -9
  37. package/components/ModalBase/ModalOverlay.js +28 -111
  38. package/components/ModalBase/hooks.js +15 -43
  39. package/components/ModalBase/index.js +2 -2
  40. package/components/PaginationDots/PaginationDot.js +11 -17
  41. package/components/PaginationDots/PaginationDots.js +4 -7
  42. package/components/PaginationDots/index.js +3 -3
  43. package/components/PaginationDots/usePaginationDots.js +10 -11
  44. package/components/Popup/Popup.js +52 -205
  45. package/components/Popup/index.js +1 -1
  46. package/components/PopupBase/PopupBase.js +35 -169
  47. package/components/PopupBase/PopupBaseContext.js +26 -86
  48. package/components/PopupBase/PopupBaseRoot.js +31 -169
  49. package/components/PopupBase/hooks.js +23 -97
  50. package/components/PopupBase/index.js +3 -3
  51. package/components/PopupBase/utils.js +32 -78
  52. package/components/Price/Price.js +15 -90
  53. package/components/Price/index.js +1 -1
  54. package/components/RadioGroup/RadioGroup.js +6 -127
  55. package/components/RadioGroup/index.js +1 -1
  56. package/components/SSRProvider/SSRProvider.js +4 -5
  57. package/components/SSRProvider/index.js +1 -1
  58. package/components/Skeleton/LineSkeleton.js +23 -95
  59. package/components/Skeleton/RectSkeleton.js +20 -93
  60. package/components/Skeleton/Skeleton.js +2 -2
  61. package/components/Skeleton/TextSkeleton.js +11 -55
  62. package/components/Skeleton/index.js +3 -3
  63. package/components/Slider/Double.js +52 -203
  64. package/components/Slider/Handle.js +28 -158
  65. package/components/Slider/Single.js +29 -177
  66. package/components/Slider/Slider.js +5 -7
  67. package/components/Slider/SliderBase.js +39 -48
  68. package/components/Slider/ThumbBase.js +19 -95
  69. package/components/Slider/index.js +3 -3
  70. package/components/Slider/utils.js +2 -2
  71. package/components/Spinner/Spinner.js +28 -100
  72. package/components/Spinner/SpinnerSvg.js +9 -78
  73. package/components/Spinner/index.js +1 -1
  74. package/components/Switch/Switch.js +49 -220
  75. package/components/Switch/index.js +1 -1
  76. package/components/Tabs/TabItem.js +33 -168
  77. package/components/Tabs/Tabs.js +32 -170
  78. package/components/Tabs/TabsContext.js +12 -42
  79. package/components/Tabs/createTabsController.js +33 -168
  80. package/components/Tabs/index.js +4 -4
  81. package/components/TextArea/TextArea.js +20 -30
  82. package/components/TextArea/index.js +1 -1
  83. package/components/TextField/index.js +3 -3
  84. package/components/Toast/Toast.js +15 -16
  85. package/components/Toast/ToastContext.js +4 -8
  86. package/components/Toast/ToastController.js +44 -101
  87. package/components/Toast/ToastProvider.js +37 -142
  88. package/components/Toast/index.js +3 -3
  89. package/components/Toast/useToast.js +6 -6
  90. package/components/Typography/Body.js +18 -18
  91. package/components/Typography/Button.js +13 -13
  92. package/components/Typography/Caption.js +8 -8
  93. package/components/Typography/Display.js +18 -18
  94. package/components/Typography/Footnote.js +13 -13
  95. package/components/Typography/Headline.js +43 -43
  96. package/components/Typography/Paragraph.js +24 -24
  97. package/components/Typography/Underline.js +8 -8
  98. package/es/__helpers/IconPlaceholder.js +5 -8
  99. package/es/collectPackageInfo.js +3 -3
  100. package/es/components/Badge/Badge.js +27 -100
  101. package/es/components/Basebox/Basebox.js +28 -37
  102. package/es/components/Button/Button.js +24 -63
  103. package/es/components/Button/Button.mixins.js +19 -73
  104. package/es/components/Button/Button.props.js +3 -3
  105. package/es/components/Button/createButton.js +12 -143
  106. package/es/components/Card/Card.js +29 -157
  107. package/es/components/Card/CardBody.js +2 -2
  108. package/es/components/Card/CardContent.js +12 -21
  109. package/es/components/Card/CardMedia.js +17 -88
  110. package/es/components/Card/CardPrice.js +13 -55
  111. package/es/components/Card/CardTypography.js +43 -52
  112. package/es/components/Carousel/Carousel.js +45 -63
  113. package/es/components/Carousel/CarouselItem.js +18 -90
  114. package/es/components/Carousel/hooks.js +58 -117
  115. package/es/components/Carousel/utils.js +58 -72
  116. package/es/components/Fade/Fade.js +5 -8
  117. package/es/components/Field/Field.js +44 -59
  118. package/es/components/Field/Field.statuses.js +4 -4
  119. package/es/components/Image/Image.js +31 -112
  120. package/es/components/Input/Input.js +4 -4
  121. package/es/components/Input/Input.mixins.js +6 -9
  122. package/es/components/ModalBase/ModalBase.js +16 -94
  123. package/es/components/ModalBase/ModalBaseContext.js +6 -9
  124. package/es/components/ModalBase/ModalOverlay.js +23 -106
  125. package/es/components/ModalBase/hooks.js +12 -40
  126. package/es/components/PaginationDots/PaginationDot.js +9 -15
  127. package/es/components/PaginationDots/PaginationDots.js +3 -6
  128. package/es/components/PaginationDots/usePaginationDots.js +9 -10
  129. package/es/components/Popup/Popup.js +48 -201
  130. package/es/components/PopupBase/PopupBase.js +27 -161
  131. package/es/components/PopupBase/PopupBaseContext.js +25 -85
  132. package/es/components/PopupBase/PopupBaseRoot.js +26 -164
  133. package/es/components/PopupBase/hooks.js +21 -95
  134. package/es/components/PopupBase/utils.js +31 -77
  135. package/es/components/Price/Price.js +12 -87
  136. package/es/components/RadioGroup/RadioGroup.js +5 -126
  137. package/es/components/SSRProvider/SSRProvider.js +3 -4
  138. package/es/components/Skeleton/LineSkeleton.js +18 -90
  139. package/es/components/Skeleton/RectSkeleton.js +16 -89
  140. package/es/components/Skeleton/Skeleton.js +2 -2
  141. package/es/components/Skeleton/TextSkeleton.js +7 -51
  142. package/es/components/Slider/Double.js +49 -200
  143. package/es/components/Slider/Handle.js +23 -153
  144. package/es/components/Slider/Single.js +26 -174
  145. package/es/components/Slider/Slider.js +2 -4
  146. package/es/components/Slider/SliderBase.js +36 -45
  147. package/es/components/Slider/ThumbBase.js +16 -92
  148. package/es/components/Slider/index.js +1 -1
  149. package/es/components/Slider/utils.js +2 -2
  150. package/es/components/Spinner/Spinner.js +23 -95
  151. package/es/components/Spinner/SpinnerSvg.js +8 -77
  152. package/es/components/Switch/Switch.js +45 -216
  153. package/es/components/Tabs/TabItem.js +28 -163
  154. package/es/components/Tabs/Tabs.js +28 -166
  155. package/es/components/Tabs/TabsContext.js +11 -41
  156. package/es/components/Tabs/createTabsController.js +28 -163
  157. package/es/components/TextArea/TextArea.js +18 -28
  158. package/es/components/Toast/Toast.js +10 -11
  159. package/es/components/Toast/ToastContext.js +3 -7
  160. package/es/components/Toast/ToastController.js +38 -95
  161. package/es/components/Toast/ToastProvider.js +34 -139
  162. package/es/components/Toast/useToast.js +4 -4
  163. package/es/components/Typography/Body.js +15 -15
  164. package/es/components/Typography/Button.js +10 -10
  165. package/es/components/Typography/Caption.js +5 -5
  166. package/es/components/Typography/Display.js +15 -15
  167. package/es/components/Typography/Footnote.js +10 -10
  168. package/es/components/Typography/Headline.js +40 -40
  169. package/es/components/Typography/Paragraph.js +21 -21
  170. package/es/components/Typography/Underline.js +5 -5
  171. package/es/hocs/withAutoFocus.js +8 -78
  172. package/es/hocs/withSkeleton.js +5 -10
  173. package/es/hooks/useDebouncedFunction.js +4 -36
  174. package/es/hooks/useFocusTrap.js +18 -21
  175. package/es/hooks/useForkRef.js +3 -3
  176. package/es/hooks/useIsomorphicLayoutEffect.js +1 -1
  177. package/es/hooks/useResizeObserver.js +8 -8
  178. package/es/hooks/useUniqId.js +6 -52
  179. package/es/mixins/addFocus.js +17 -22
  180. package/es/mixins/applyDisabled.js +6 -9
  181. package/es/mixins/applyEllipsis.js +2 -4
  182. package/es/mixins/applyMaxLines.js +3 -6
  183. package/es/mixins/applyNoSelect.js +2 -4
  184. package/es/mixins/applyOutline.js +2 -4
  185. package/es/mixins/applyRoundness.js +4 -7
  186. package/es/mixins/applyScrollSnap.js +4 -7
  187. package/es/mixins/applySkeletonGradient.js +6 -9
  188. package/es/mixins/applyView.js +2 -5
  189. package/es/mixins/blur.js +2 -5
  190. package/es/mixins/shadows.js +1 -1
  191. package/es/tokens/colors.js +48 -48
  192. package/es/tokens/typography.js +18 -18
  193. package/es/utils/__tests__/formatters.test.js +2 -2
  194. package/es/utils/animatedScrollTo.js +24 -34
  195. package/es/utils/canUseDOM.js +1 -1
  196. package/es/utils/extractTextFrom.js +3 -7
  197. package/es/utils/focusManager.js +40 -47
  198. package/es/utils/formatCurrency.js +4 -4
  199. package/es/utils/formatters.js +6 -14
  200. package/es/utils/react.js +4 -4
  201. package/es/utils/roundness.js +2 -4
  202. package/es/utils/scopeTab.js +5 -5
  203. package/es/utils/setRef.js +1 -1
  204. package/es/utils/tabbable.js +16 -25
  205. package/es/utils/toCssSize.js +1 -3
  206. package/es/utils/transformStyles.js +5 -60
  207. package/hocs/index.js +2 -2
  208. package/hocs/withAutoFocus.js +9 -79
  209. package/hocs/withSkeleton.js +8 -13
  210. package/hooks/index.js +6 -6
  211. package/hooks/useDebouncedFunction.js +5 -37
  212. package/hooks/useFocusTrap.js +22 -25
  213. package/hooks/useForkRef.js +5 -5
  214. package/hooks/useIsomorphicLayoutEffect.js +3 -3
  215. package/hooks/useResizeObserver.js +9 -9
  216. package/hooks/useUniqId.js +8 -54
  217. package/mixins/addFocus.js +19 -24
  218. package/mixins/applyDisabled.js +7 -10
  219. package/mixins/applyEllipsis.js +3 -5
  220. package/mixins/applyMaxLines.js +4 -7
  221. package/mixins/applyNoSelect.js +3 -5
  222. package/mixins/applyOutline.js +3 -5
  223. package/mixins/applyRoundness.js +5 -8
  224. package/mixins/applyScrollSnap.js +5 -8
  225. package/mixins/applySkeletonGradient.js +8 -11
  226. package/mixins/applyView.js +3 -6
  227. package/mixins/blur.js +2 -5
  228. package/mixins/index.js +11 -11
  229. package/mixins/shadows.js +1 -1
  230. package/package.json +13 -18
  231. package/tokens/colors.js +48 -48
  232. package/tokens/typography.js +18 -18
  233. package/utils/__tests__/formatters.test.js +3 -3
  234. package/utils/animatedScrollTo.js +24 -34
  235. package/utils/canUseDOM.js +1 -1
  236. package/utils/extractTextFrom.js +4 -8
  237. package/utils/focusManager.js +41 -48
  238. package/utils/formatCurrency.js +4 -4
  239. package/utils/formatters.js +6 -14
  240. package/utils/index.js +10 -10
  241. package/utils/react.js +7 -7
  242. package/utils/roundness.js +2 -4
  243. package/utils/scopeTab.js +6 -6
  244. package/utils/setRef.js +1 -1
  245. package/utils/tabbable.js +16 -25
  246. package/utils/toCssSize.js +1 -3
  247. package/utils/transformStyles.js +5 -60
@@ -1,109 +1,59 @@
1
- function _array_like_to_array(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _array_with_holes(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
- function _iterable_to_array_limit(arr, i) {
10
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
11
- if (_i == null) return;
12
- var _arr = [];
13
- var _n = true;
14
- var _d = false;
15
- var _s, _e;
16
- try {
17
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
18
- _arr.push(_s.value);
19
- if (i && _arr.length === i) break;
20
- }
21
- } catch (err) {
22
- _d = true;
23
- _e = err;
24
- } finally{
25
- try {
26
- if (!_n && _i["return"] != null) _i["return"]();
27
- } finally{
28
- if (_d) throw _e;
29
- }
30
- }
31
- return _arr;
32
- }
33
- function _non_iterable_rest() {
34
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
- }
36
- function _sliced_to_array(arr, i) {
37
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
38
- }
39
- function _unsupported_iterable_to_array(o, minLen) {
40
- if (!o) return;
41
- if (typeof o === "string") return _array_like_to_array(o, minLen);
42
- var n = Object.prototype.toString.call(o).slice(8, -1);
43
- if (n === "Object" && o.constructor) n = o.constructor.name;
44
- if (n === "Map" || n === "Set") return Array.from(n);
45
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
46
- }
47
1
  /* eslint-disable no-continue */ import throttle from 'lodash.throttle';
48
2
  import { useRef, useEffect, useCallback, useMemo, useLayoutEffect, useState } from 'react';
49
3
  import { useDebouncedFunction } from '../../hooks';
50
4
  import { scrollToPos, getCalculatedPos, getCalculatedOffset, getItemSlot, getCarouselItems, translateToIndex } from './utils';
51
- var THROTTLE_DEFAULT_MS = 100;
52
- var DEBOUNCE_DEFAULT_MS = 150;
53
- export var useCarousel = function useCarousel(param) {
54
- var index = param.index, axis = param.axis, _param_detectActive = param.detectActive, detectActive = _param_detectActive === void 0 ? false : _param_detectActive, _param_detectThreshold = param.detectThreshold, detectThreshold = _param_detectThreshold === void 0 ? 0.5 : _param_detectThreshold, _param_scrollAlign = param.scrollAlign, scrollAlign = _param_scrollAlign === void 0 ? 'center' : _param_scrollAlign, scaleCallback = param.scaleCallback, scaleResetCallback = param.scaleResetCallback, onIndexChange = param.onIndexChange, onDetectActiveItem = param.onDetectActiveItem, _param_animatedScrollByIndex = param.animatedScrollByIndex, animatedScrollByIndex = _param_animatedScrollByIndex === void 0 ? false : _param_animatedScrollByIndex, _param_throttleMs = param.throttleMs, throttleMs = _param_throttleMs === void 0 ? THROTTLE_DEFAULT_MS : _param_throttleMs, _param_debounceMs = param.debounceMs, debounceMs = _param_debounceMs === void 0 ? DEBOUNCE_DEFAULT_MS : _param_debounceMs;
55
- var prevIndex = useRef(null);
56
- var direction = useRef(null);
57
- var offset = useRef(0);
58
- var scrollRef = useRef(null);
59
- var trackRef = useRef(null);
5
+ const THROTTLE_DEFAULT_MS = 100;
6
+ const DEBOUNCE_DEFAULT_MS = 150;
7
+ export const useCarousel = ({ index, axis, detectActive = false, detectThreshold = 0.5, scrollAlign = 'center', scaleCallback, scaleResetCallback, onIndexChange, onDetectActiveItem, animatedScrollByIndex = false, throttleMs = THROTTLE_DEFAULT_MS, debounceMs = DEBOUNCE_DEFAULT_MS })=>{
8
+ const prevIndex = useRef(null);
9
+ const direction = useRef(null);
10
+ const offset = useRef(0);
11
+ const scrollRef = useRef(null);
12
+ const trackRef = useRef(null);
60
13
  /**
61
14
  * Для того, чтобы не спамить изменениями индекса.
62
15
  * Задержка дебаунса слегка больше, чем у тротлинга.
63
16
  * Таким образом, событие срабатывает при завершении скролла.
64
- */ var debouncedOnIndexChange = useDebouncedFunction(function(i) {
65
- return onIndexChange === null || onIndexChange === void 0 ? void 0 : onIndexChange(i);
66
- }, debounceMs);
17
+ */ const debouncedOnIndexChange = useDebouncedFunction((i)=>onIndexChange?.(i), debounceMs);
67
18
  /**
68
19
  * Вычисление центрального элемента.
69
20
  * Подсчет: от 0 до 1, какое количество ширины/высоты
70
21
  * каждого элемента находится по центру скролла.
71
- */ var throttledDetectActiveItem = useMemo(function() {
72
- return throttle(function() {
22
+ */ const throttledDetectActiveItem = useMemo(()=>{
23
+ return throttle(()=>{
73
24
  if (!detectActive || scrollRef.current === null || trackRef.current === null) {
74
25
  return;
75
26
  }
76
27
  /**
77
28
  * Правая (или нижняя для Оу) граница элемента.
78
- */ var itemEdge = offset.current;
29
+ */ let itemEdge = offset.current;
79
30
  /**
80
31
  * Смещение (отрицательный или положительный отступ)
81
32
  * и размер карусели (для Ox - ширина, для Oy - высота).
82
- */ var scrollPos = scrollRef.current[axis === 'x' ? 'scrollLeft' : 'scrollTop'];
83
- var scrollSize = scrollRef.current[axis === 'x' ? 'offsetWidth' : 'offsetHeight'];
33
+ */ const scrollPos = scrollRef.current[axis === 'x' ? 'scrollLeft' : 'scrollTop'];
34
+ const scrollSize = scrollRef.current[axis === 'x' ? 'offsetWidth' : 'offsetHeight'];
84
35
  /**
85
36
  * Граница скролла (видимой части).
86
37
  * Смещение + размер.
87
- */ var scrollEdge = scrollPos + scrollSize;
38
+ */ const scrollEdge = scrollPos + scrollSize;
88
39
  /**
89
40
  * Элементы перед, после и в видимой части.
90
41
  * перед [ ВИДИМЫЕ ] после
91
- */ var prevItems = [];
92
- var nextItems = [];
93
- var count = 0;
94
- var items = getCarouselItems(trackRef.current);
42
+ */ const prevItems = [];
43
+ const nextItems = [];
44
+ let count = 0;
45
+ const items = getCarouselItems(trackRef.current);
95
46
  /**
96
47
  * Проходим по всему списку, суммируя ширины элементов,
97
48
  * пока не найдем один элемент, чей центр будет в центре карусели.
98
- */ for(var itemIndex = 0; itemIndex < items.length; itemIndex++){
99
- var _prevIndex_current;
100
- var item = items.item(itemIndex);
49
+ */ for(let itemIndex = 0; itemIndex < items.length; itemIndex++){
50
+ const item = items.item(itemIndex);
101
51
  if (item === null) {
102
52
  continue;
103
53
  }
104
54
  /**
105
55
  * Для Ox - ширина, для Oy - высота.
106
- */ var itemSize = item[axis === 'x' ? 'offsetWidth' : 'offsetHeight'];
56
+ */ const itemSize = item[axis === 'x' ? 'offsetWidth' : 'offsetHeight'];
107
57
  /**
108
58
  * Все элементы правее вьюпорта выпадают из процедуры.
109
59
  * Сравниваем по предыдущему элементу.
@@ -125,11 +75,11 @@ export var useCarousel = function useCarousel(param) {
125
75
  }
126
76
  continue;
127
77
  }
128
- var itemSlot = getItemSlot(itemIndex, itemEdge, itemSize, scrollPos, scrollSize, scrollAlign, (_prevIndex_current = prevIndex.current) !== null && _prevIndex_current !== void 0 ? _prevIndex_current : 0, offset.current);
78
+ const itemSlot = getItemSlot(itemIndex, itemEdge, itemSize, scrollPos, scrollSize, scrollAlign, prevIndex.current ?? 0, offset.current);
129
79
  if (itemSlot !== null) {
130
80
  if (detectThreshold && Math.abs(itemSlot) <= detectThreshold) {
131
- onDetectActiveItem === null || onDetectActiveItem === void 0 ? void 0 : onDetectActiveItem(itemIndex);
132
- debouncedOnIndexChange === null || debouncedOnIndexChange === void 0 ? void 0 : debouncedOnIndexChange(itemIndex);
81
+ onDetectActiveItem?.(itemIndex);
82
+ debouncedOnIndexChange?.(itemIndex);
133
83
  }
134
84
  if (scaleCallback) {
135
85
  scaleCallback(item, itemSlot);
@@ -140,27 +90,19 @@ export var useCarousel = function useCarousel(param) {
140
90
  }
141
91
  }
142
92
  if (scaleCallback && scaleResetCallback) {
143
- window.requestAnimationFrame(function() {
93
+ window.requestAnimationFrame(()=>{
144
94
  if (direction.current) {
145
95
  if (nextItems.length) {
146
- nextItems.splice(0, count).forEach(function(elem) {
147
- return scaleCallback(elem, count);
148
- });
96
+ nextItems.splice(0, count).forEach((elem)=>scaleCallback(elem, count));
149
97
  if (nextItems.length) {
150
- nextItems.splice(0, count).forEach(function(elem) {
151
- return scaleResetCallback(elem);
152
- });
98
+ nextItems.splice(0, count).forEach((elem)=>scaleResetCallback(elem));
153
99
  }
154
100
  }
155
101
  } else if (prevItems.length) {
156
- var prItemsRev = prevItems.reverse();
157
- prItemsRev.splice(0, count).forEach(function(elem) {
158
- return scaleCallback(elem, count * -1);
159
- });
102
+ const prItemsRev = prevItems.reverse();
103
+ prItemsRev.splice(0, count).forEach((elem)=>scaleCallback(elem, count * -1));
160
104
  if (prItemsRev.length) {
161
- prItemsRev.splice(0, count).forEach(function(elem) {
162
- return scaleResetCallback(elem);
163
- });
105
+ prItemsRev.splice(0, count).forEach((elem)=>scaleResetCallback(elem));
164
106
  }
165
107
  }
166
108
  });
@@ -179,21 +121,21 @@ export var useCarousel = function useCarousel(param) {
179
121
  ]);
180
122
  /**
181
123
  * Прокрутка до нужной позиции индекса.
182
- */ var toIndex = useCallback(function(i) {
183
- var scrollEl = scrollRef.current;
184
- var items = trackRef.current ? getCarouselItems(trackRef.current) : null;
124
+ */ const toIndex = useCallback((i)=>{
125
+ const scrollEl = scrollRef.current;
126
+ const items = trackRef.current ? getCarouselItems(trackRef.current) : null;
185
127
  if (scrollEl && items && items.length > 0 && i >= 0) {
186
128
  scrollToPos({
187
- scrollEl: scrollEl,
129
+ scrollEl,
188
130
  pos: getCalculatedPos({
189
- scrollEl: scrollEl,
190
- items: items,
191
- axis: axis,
131
+ scrollEl,
132
+ items,
133
+ axis,
192
134
  index: i,
193
135
  offset: offset.current,
194
- scrollAlign: scrollAlign
136
+ scrollAlign
195
137
  }),
196
- axis: axis,
138
+ axis,
197
139
  /**
198
140
  * Без анимации при переходе на другой конец списка
199
141
  */ animated: animatedScrollByIndex && (prevIndex.current === null || Math.abs(i - prevIndex.current) !== items.length - 1)
@@ -205,7 +147,7 @@ export var useCarousel = function useCarousel(param) {
205
147
  axis,
206
148
  scrollAlign
207
149
  ]);
208
- useEffect(function() {
150
+ useEffect(()=>{
209
151
  if (scrollRef.current && trackRef.current) {
210
152
  offset.current = getCalculatedOffset(scrollRef.current, trackRef.current, axis);
211
153
  }
@@ -215,12 +157,12 @@ export var useCarousel = function useCarousel(param) {
215
157
  /**
216
158
  * Операции на маунте/анмаунте компонента.
217
159
  * Создать слушатели событи и т.п.
218
- */ useEffect(function() {
219
- var carouselElement = scrollRef.current;
160
+ */ useEffect(()=>{
161
+ const carouselElement = scrollRef.current;
220
162
  if (carouselElement) {
221
163
  carouselElement.addEventListener('scroll', throttledDetectActiveItem);
222
164
  }
223
- return function() {
165
+ return ()=>{
224
166
  if (carouselElement) {
225
167
  carouselElement.removeEventListener('scroll', throttledDetectActiveItem);
226
168
  }
@@ -230,8 +172,8 @@ export var useCarousel = function useCarousel(param) {
230
172
  ]);
231
173
  /**
232
174
  * Нужно вызвать только при первом рендере
233
- */ useEffect(function() {
234
- requestAnimationFrame(function() {
175
+ */ useEffect(()=>{
176
+ requestAnimationFrame(()=>{
235
177
  /**
236
178
  * Прокрутка до начального индекса.
237
179
  */ toIndex(index);
@@ -245,7 +187,7 @@ export var useCarousel = function useCarousel(param) {
245
187
  }, []);
246
188
  /**
247
189
  * Прокрутка до нужной позиции индекса, если индекс изменился.
248
- */ useEffect(function() {
190
+ */ useEffect(()=>{
249
191
  if (index !== prevIndex.current) {
250
192
  toIndex(index);
251
193
  }
@@ -254,29 +196,28 @@ export var useCarousel = function useCarousel(param) {
254
196
  toIndex
255
197
  ]);
256
198
  return {
257
- scrollRef: scrollRef,
258
- trackRef: trackRef
199
+ scrollRef,
200
+ trackRef
259
201
  };
260
202
  };
261
- export function useCarouselLite(param) {
262
- var index = param.index, axis = param.axis, _param_scrollAlign = param.scrollAlign, scrollAlign = _param_scrollAlign === void 0 ? 'center' : _param_scrollAlign, _param_scrollMode = param.scrollMode, scrollMode = _param_scrollMode === void 0 ? 'translate' : _param_scrollMode;
263
- var _useState = _sliced_to_array(useState(index), 2), prevIndex = _useState[0], setPrevIndex = _useState[1];
264
- var carouselRef = useRef(null);
265
- var trackRef = useRef(null);
266
- var needTranslateToInitialIndex = useRef(true);
203
+ export function useCarouselLite({ index, axis, scrollAlign = 'center', scrollMode = 'translate' }) {
204
+ const [prevIndex, setPrevIndex] = useState(index);
205
+ const carouselRef = useRef(null);
206
+ const trackRef = useRef(null);
207
+ const needTranslateToInitialIndex = useRef(true);
267
208
  // Первый раз нужно проскролить к индексу, после первого рендера
268
- useLayoutEffect(function() {
209
+ useLayoutEffect(()=>{
269
210
  if (needTranslateToInitialIndex.current === false) {
270
211
  return;
271
212
  }
272
213
  /**
273
214
  * Вызываем через requestAnimationFrame, так как при использовании динамических CarouselCol
274
215
  * ширины элементов высчитываются неверно внутри translateToIndex при синхронном вызове
275
- */ var rafId = requestAnimationFrame(function() {
216
+ */ const rafId = requestAnimationFrame(()=>{
276
217
  translateToIndex(index, index, axis, scrollAlign, trackRef.current, carouselRef.current, true, scrollMode);
277
218
  needTranslateToInitialIndex.current = false;
278
219
  });
279
- return function() {
220
+ return ()=>{
280
221
  cancelAnimationFrame(rafId);
281
222
  };
282
223
  }, [
@@ -293,6 +234,6 @@ export function useCarouselLite(param) {
293
234
  }
294
235
  return {
295
236
  scrollRef: carouselRef,
296
- trackRef: trackRef
237
+ trackRef
297
238
  };
298
239
  }
@@ -1,9 +1,8 @@
1
1
  import { animatedScrollToX, animatedScrollToY } from '../../utils';
2
- var positionModByScrollAlign = function positionModByScrollAlign(param) {
3
- var scrollAlign = param.scrollAlign, position = param.position, carouselSize = param.carouselSize, itemSize = param.itemSize, offset = param.offset, scrollStart = param.scrollStart, axis = param.axis;
2
+ const positionModByScrollAlign = ({ scrollAlign, position, carouselSize, itemSize, offset, scrollStart, axis })=>{
4
3
  if (scrollAlign === 'start') {
5
- var inaccuracy = 1;
6
- var paddingOffset = axis === 'y' ? offset - itemSize / 2 + inaccuracy : 0;
4
+ const inaccuracy = 1;
5
+ const paddingOffset = axis === 'y' ? offset - itemSize / 2 + inaccuracy : 0;
7
6
  return position + paddingOffset;
8
7
  }
9
8
  if (scrollAlign === 'center') {
@@ -24,59 +23,49 @@ var positionModByScrollAlign = function positionModByScrollAlign(param) {
24
23
  };
25
24
  /**
26
25
  * Подсчет скролла до переданного индекса.
27
- */ export var getCalculatedPos = function getCalculatedPos(param) {
28
- var scrollEl = param.scrollEl, items = param.items, axis = param.axis, index = param.index, offset = param.offset, scrollAlign = param.scrollAlign;
29
- var position = scrollAlign === 'center' ? offset : 0;
30
- var carouselSize;
31
- var itemSize;
32
- var scrollStart;
26
+ */ export const getCalculatedPos = ({ scrollEl, items, axis, index, offset, scrollAlign })=>{
27
+ let position = scrollAlign === 'center' ? offset : 0;
28
+ let carouselSize;
29
+ let itemSize;
30
+ let scrollStart;
33
31
  if (items.item(index) === null) {
34
32
  return position;
35
33
  }
36
- for(var i = 0; i < index; i++){
34
+ for(let i = 0; i < index; i++){
37
35
  if (axis === 'x') {
38
- var _ref;
39
- var _items_item;
40
- position += (_ref = (_items_item = items.item(i)) === null || _items_item === void 0 ? void 0 : _items_item.offsetWidth) !== null && _ref !== void 0 ? _ref : 0;
36
+ position += items.item(i)?.offsetWidth ?? 0;
41
37
  } else {
42
- var _ref1;
43
- var _items_item1;
44
- position += (_ref1 = (_items_item1 = items.item(i)) === null || _items_item1 === void 0 ? void 0 : _items_item1.offsetHeight) !== null && _ref1 !== void 0 ? _ref1 : 0;
38
+ position += items.item(i)?.offsetHeight ?? 0;
45
39
  }
46
40
  }
47
41
  if (axis === 'x') {
48
- var _ref2;
49
- var _items_item2;
50
42
  carouselSize = scrollEl.offsetWidth;
51
- itemSize = (_ref2 = (_items_item2 = items.item(index)) === null || _items_item2 === void 0 ? void 0 : _items_item2.offsetWidth) !== null && _ref2 !== void 0 ? _ref2 : 0;
43
+ itemSize = items.item(index)?.offsetWidth ?? 0;
52
44
  scrollStart = scrollEl.scrollLeft;
53
45
  } else {
54
- var _ref3;
55
- var _items_item3;
56
46
  carouselSize = scrollEl.offsetHeight;
57
- itemSize = (_ref3 = (_items_item3 = items.item(index)) === null || _items_item3 === void 0 ? void 0 : _items_item3.offsetHeight) !== null && _ref3 !== void 0 ? _ref3 : 0;
47
+ itemSize = items.item(index)?.offsetHeight ?? 0;
58
48
  scrollStart = scrollEl.scrollTop;
59
49
  }
60
50
  return positionModByScrollAlign({
61
- scrollAlign: scrollAlign,
62
- position: position,
63
- carouselSize: carouselSize,
64
- itemSize: itemSize,
65
- offset: offset,
66
- scrollStart: scrollStart,
67
- axis: axis
51
+ scrollAlign,
52
+ position,
53
+ carouselSize,
54
+ itemSize,
55
+ offset,
56
+ scrollStart,
57
+ axis
68
58
  });
69
59
  };
70
60
  /**
71
61
  * Подсчет смещения из-за паддингов.
72
- */ export var getCalculatedOffset = function getCalculatedOffset(scrollEl, trackEl, axis) {
73
- var paddingProp = axis === 'x' ? 'paddingLeft' : 'paddingTop';
62
+ */ export const getCalculatedOffset = (scrollEl, trackEl, axis)=>{
63
+ const paddingProp = axis === 'x' ? 'paddingLeft' : 'paddingTop';
74
64
  return parseInt(getComputedStyle(scrollEl)[paddingProp], 10) + parseInt(getComputedStyle(trackEl)[paddingProp], 10);
75
65
  };
76
66
  /**
77
67
  * Прокрутка к указанной позиции с анимацией или без.
78
- */ export var scrollToPos = function scrollToPos(param) {
79
- var scrollEl = param.scrollEl, pos = param.pos, axis = param.axis, animated = param.animated, duration = param.duration, timingFunction = param.timingFunction;
68
+ */ export const scrollToPos = ({ scrollEl, pos, axis, animated, duration, timingFunction })=>{
80
69
  if (axis === 'x' && Math.abs(pos - scrollEl.scrollLeft) > 1) {
81
70
  if (animated) {
82
71
  animatedScrollToX(scrollEl, pos, duration, timingFunction);
@@ -96,20 +85,17 @@ var positionModByScrollAlign = function positionModByScrollAlign(param) {
96
85
  }
97
86
  }
98
87
  };
99
- var round = function round(n) {
100
- return Math.round(n * 100) / 100;
101
- };
88
+ const round = (n)=>Math.round(n * 100) / 100;
102
89
  /**
103
90
  * Получить позицию (слот) айтема в каруселе.
104
91
  * Каждый айтем имеет свой слот относительно вьюпорта карусели.
105
- */ export var getItemSlot = function getItemSlot(itemIndex, itemEnd, itemSize, scrollStart, scrollSize, scrollAlign) {
106
- var prevIndex = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : 0, offset = arguments.length > 7 && arguments[7] !== void 0 ? arguments[7] : 0;
92
+ */ export const getItemSlot = (itemIndex, itemEnd, itemSize, scrollStart, scrollSize, scrollAlign, prevIndex = 0, offset = 0)=>{
107
93
  /**
108
94
  * Граница и центр скролла (видимой части).
109
95
  * Смещение + размер.
110
- */ var scrollEnd = scrollStart + scrollSize;
111
- var scrollCenter = scrollStart + scrollSize / 2;
112
- var itemCenter = itemEnd - itemSize / 2;
96
+ */ const scrollEnd = scrollStart + scrollSize;
97
+ const scrollCenter = scrollStart + scrollSize / 2;
98
+ const itemCenter = itemEnd - itemSize / 2;
113
99
  if (scrollAlign === 'center') {
114
100
  return round((itemCenter - scrollCenter) / itemSize);
115
101
  }
@@ -120,9 +106,9 @@ var round = function round(n) {
120
106
  return round((itemEnd - (scrollSize + scrollStart)) / itemSize);
121
107
  }
122
108
  if (scrollAlign === 'activeDirection') {
123
- var prevStart = offset + itemSize * prevIndex;
124
- var prevEnd = prevStart + itemSize;
125
- var prevVisible = prevEnd > scrollStart && prevStart < scrollEnd;
109
+ const prevStart = offset + itemSize * prevIndex;
110
+ const prevEnd = prevStart + itemSize;
111
+ const prevVisible = prevEnd > scrollStart && prevStart < scrollEnd;
126
112
  if (!prevVisible) {
127
113
  if (prevIndex < itemIndex) {
128
114
  return round((itemEnd - (scrollSize + scrollStart)) / itemSize);
@@ -135,28 +121,28 @@ var round = function round(n) {
135
121
  export function getCarouselItems(track) {
136
122
  return track.children;
137
123
  }
138
- var axisToTranslateMap = {
139
- x: function x(position) {
140
- return "translateX(".concat(-position, "px)");
124
+ const axisToTranslateMap = {
125
+ x (position) {
126
+ return `translateX(${-position}px)`;
141
127
  },
142
- y: function y(position) {
143
- return "translateY(".concat(-position, "px)");
128
+ y (position) {
129
+ return `translateY(${-position}px)`;
144
130
  }
145
131
  };
146
- var axisToOffsetKeyMap = {
132
+ const axisToOffsetKeyMap = {
147
133
  x: 'offsetLeft',
148
134
  y: 'offsetTop'
149
135
  };
150
- var axisToSizeKeyMap = {
136
+ const axisToSizeKeyMap = {
151
137
  x: 'offsetWidth',
152
138
  y: 'offsetHeight'
153
139
  };
154
- var axisToScrollKeyMap = {
140
+ const axisToScrollKeyMap = {
155
141
  x: 'scrollLeft',
156
142
  y: 'scrollTop'
157
143
  };
158
144
  function getCenterPosition(itemSize, itemStart, carouselSize, trackOffset) {
159
- var relativeMiddle = itemStart + trackOffset + itemSize / 2;
145
+ const relativeMiddle = itemStart + trackOffset + itemSize / 2;
160
146
  return relativeMiddle - carouselSize / 2;
161
147
  }
162
148
  function getEndPosition(itemSize, itemStart, carouselSize, trackOffset) {
@@ -184,12 +170,12 @@ function boundPosition(position, trackSize, carouselSize, trackOffset) {
184
170
  }
185
171
  // если все элементы помещаются в ширину карусели, то считаем trackEnd по-другому
186
172
  if (trackSize < carouselSize) {
187
- var trackEnd = Math.abs(carouselSize - trackSize - trackOffset);
173
+ const trackEnd = Math.abs(carouselSize - trackSize - trackOffset);
188
174
  return position < trackEnd ? position : trackEnd;
189
175
  }
190
- var trackEnd1 = trackSize - carouselSize + trackOffset;
191
- if (position > trackEnd1) {
192
- return trackEnd1;
176
+ const trackEnd = trackSize - carouselSize + trackOffset;
177
+ if (position > trackEnd) {
178
+ return trackEnd;
193
179
  }
194
180
  return position;
195
181
  }
@@ -217,10 +203,10 @@ function setTimingFunction(element, timingFunction) {
217
203
  }
218
204
  }
219
205
  function translateToPosition(element, axis, position) {
220
- var translate = axisToTranslateMap[axis];
206
+ const translate = axisToTranslateMap[axis];
221
207
  element.style.transform = translate(position);
222
208
  }
223
- var scrollOptions = {
209
+ const scrollOptions = {
224
210
  behavior: 'auto',
225
211
  left: 0,
226
212
  top: 0
@@ -244,24 +230,24 @@ var scrollOptions = {
244
230
  if (track === null || carousel === null) {
245
231
  return;
246
232
  }
247
- var scrollKey = axisToScrollKeyMap[axis];
233
+ const scrollKey = axisToScrollKeyMap[axis];
248
234
  if (disableAnimation === false && scrollMode === 'translate' && carousel[scrollKey] !== 0) {
249
235
  carousel.scrollTo(scrollOptions);
250
236
  }
251
- var itemToTranslateTo = track.children.item(index);
237
+ const itemToTranslateTo = track.children.item(index);
252
238
  if (itemToTranslateTo === null) {
253
239
  return;
254
240
  }
255
- var numberOfItems = track.children.length;
256
- var offsetKey = axisToOffsetKeyMap[axis];
257
- var sizeKey = axisToSizeKeyMap[axis];
258
- var carouselSize = carousel[sizeKey];
259
- var trackSize = track[sizeKey];
260
- var trackOffset = track[offsetKey];
261
- var itemSize = itemToTranslateTo[sizeKey];
262
- var itemStart = itemToTranslateTo[offsetKey];
263
- var translatePosition = getTranslatePosition(itemSize, itemStart, carouselSize, trackOffset, align);
264
- var position = boundPosition(translatePosition, trackSize, carouselSize, trackOffset);
241
+ const numberOfItems = track.children.length;
242
+ const offsetKey = axisToOffsetKeyMap[axis];
243
+ const sizeKey = axisToSizeKeyMap[axis];
244
+ const carouselSize = carousel[sizeKey];
245
+ const trackSize = track[sizeKey];
246
+ const trackOffset = track[offsetKey];
247
+ const itemSize = itemToTranslateTo[sizeKey];
248
+ const itemStart = itemToTranslateTo[offsetKey];
249
+ const translatePosition = getTranslatePosition(itemSize, itemStart, carouselSize, trackOffset, align);
250
+ const position = boundPosition(translatePosition, trackSize, carouselSize, trackOffset);
265
251
  if (scrollMode === 'scroll') {
266
252
  carousel.scrollTo({
267
253
  behavior: disableAnimation ? 'auto' : 'smooth',
@@ -1,15 +1,12 @@
1
1
  import styled from 'styled-components';
2
- var gradients = {
2
+ const gradients = {
3
3
  top: 'radial-gradient(200% 200% at 50% -100%, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0) 100%)',
4
4
  bottom: 'radial-gradient(200% 200% at 50% 200%, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0) 100%)'
5
5
  };
6
- export var Fade = styled.div.withConfig({
6
+ export const Fade = styled.div.withConfig({
7
7
  displayName: "Fade",
8
8
  componentId: "sc-1f25e4f8-0"
9
9
  })([
10
- "position:fixed;top:0;left:0;right:0;bottom:0;z-index:999;background:",
11
- ";"
12
- ], function(param) {
13
- var _param_placement = param.placement, placement = _param_placement === void 0 ? 'bottom' : _param_placement;
14
- return gradients[placement];
15
- });
10
+ `position:fixed;top:0;left:0;right:0;bottom:0;z-index:999;background:`,
11
+ `;`
12
+ ], ({ placement = 'bottom' })=>gradients[placement]);