@via-profit/ui-kit 0.2.1-alpha.1 → 0.2.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 (143) hide show
  1. package/Autocomplete/AutocompleteContainer.d.ts +33 -6
  2. package/Autocomplete/AutocompleteContainer.js +48 -36
  3. package/Autocomplete/AutocompleteItem.d.ts +1 -1
  4. package/Autocomplete/AutocompleteTextField.d.ts +3 -0
  5. package/Autocomplete/AutocompleteTextField.js +63 -1
  6. package/Autocomplete/OverrideMenuList.d.ts +4 -0
  7. package/Autocomplete/OverrideMenuList.js +39 -0
  8. package/Autocomplete/context.d.ts +9 -1
  9. package/Autocomplete/context.js +15 -1
  10. package/Autocomplete/index.js +9 -10
  11. package/Autocomplete2/Autocomplete2.d.ts +12 -0
  12. package/Autocomplete2/Autocomplete2.js +83 -0
  13. package/Autocomplete2/Autocomplete2TextField.d.ts +7 -0
  14. package/Autocomplete2/Autocomplete2TextField.js +39 -0
  15. package/Autocomplete2/index.d.ts +2 -0
  16. package/Autocomplete2/index.js +7 -0
  17. package/Avatar/index.js +1 -1
  18. package/Badge/BadgeDeleteButton.js +6 -6
  19. package/Badge/BadgeOutlined.js +2 -2
  20. package/Badge/BadgeStandard.js +1 -1
  21. package/Button/ButtonOutlined.js +1 -1
  22. package/Button/ButtonPlain.js +1 -1
  23. package/Button/ButtonStandard.js +4 -11
  24. package/Calendar/CalendarCell.js +6 -2
  25. package/Calendar/CalendarComponent.d.ts +226 -0
  26. package/Calendar/CalendarComponent.js +572 -0
  27. package/Calendar/CalendarControlButton.js +16 -9
  28. package/Calendar/CalendarDayBadge.js +1 -1
  29. package/Calendar/CalendarEmptyCell.d.ts +2 -2
  30. package/Calendar/CalendarEmptyCell.js +8 -3
  31. package/Calendar/CalendarHeading.js +2 -1
  32. package/Calendar/CalendarSubheading.js +3 -2
  33. package/Calendar/CalendarWeekDayCell.d.ts +10 -0
  34. package/Calendar/CalendarWeekDayCell.js +32 -0
  35. package/Calendar/CalendarWeekDayWeekNumber.d.ts +7 -0
  36. package/Calendar/CalendarWeekDayWeekNumber.js +38 -0
  37. package/Calendar/CalendarWeekRow.d.ts +2 -2
  38. package/Calendar/CalendarWeekRow.js +2 -1
  39. package/Calendar/CalendarWeekRowButton.d.ts +13 -0
  40. package/Calendar/CalendarWeekRowButton.js +31 -0
  41. package/Calendar/CalendarYearsSelector.d.ts +39 -1
  42. package/Calendar/CalendarYearsSelector.js +52 -16
  43. package/Calendar/IconChevronDown.d.ts +3 -0
  44. package/Calendar/IconChevronDown.js +31 -0
  45. package/Calendar/index.d.ts +7 -224
  46. package/Calendar/index.js +19 -281
  47. package/Calendar/use-calendar.d.ts +1 -1
  48. package/Color/Color.d.ts +138 -0
  49. package/Color/Color.js +324 -0
  50. package/Color/ColorGenerator.d.ts +29 -0
  51. package/Color/ColorGenerator.js +141 -0
  52. package/Color/ColorParser.d.ts +20 -0
  53. package/Color/ColorParser.js +284 -0
  54. package/Color/index.d.ts +4 -122
  55. package/Color/index.js +18 -473
  56. package/CountryFlags/SwiperOverview.d.ts +257 -0
  57. package/CountryFlags/SwiperOverview.js +524 -0
  58. package/DatePicker/index.d.ts +2 -17
  59. package/DatePicker/index.js +47 -61
  60. package/DatePicker/useDatePickerFormat.js +5 -5
  61. package/ErrorBoundary/Fallback.d.ts +3 -0
  62. package/ErrorBoundary/Fallback.js +51 -0
  63. package/ErrorBoundary/RenderError.d.ts +6 -0
  64. package/ErrorBoundary/RenderError.js +80 -0
  65. package/ErrorBoundary/index.d.ts +7 -11
  66. package/ErrorBoundary/index.js +4 -51
  67. package/LoadingIndicator/Spinner.d.ts +5 -3
  68. package/LoadingIndicator/Spinner.js +61 -32
  69. package/LoadingIndicator/index.d.ts +3 -3
  70. package/LoadingIndicator/index.js +15 -2
  71. package/MaskedField/index.d.ts +2 -1
  72. package/MaskedField/index.js +52 -43
  73. package/MaskedField/useMasked.js +7 -5
  74. package/Menu/AutoHeightWrapper.d.ts +6 -0
  75. package/Menu/AutoHeightWrapper.js +43 -0
  76. package/Menu/MeasuredItem.d.ts +10 -0
  77. package/Menu/MeasuredItem.js +51 -0
  78. package/Menu/MenuContainer.d.ts +51 -18
  79. package/Menu/MenuContainer.js +19 -12
  80. package/Menu/MenuItem.d.ts +24 -7
  81. package/Menu/MenuItem.js +13 -6
  82. package/Menu/MenuList.d.ts +4 -2
  83. package/Menu/MenuList.js +26 -6
  84. package/Menu/VirtualizedItem.d.ts +22 -0
  85. package/Menu/VirtualizedItem.js +69 -0
  86. package/Menu/VirtualizedList.d.ts +18 -0
  87. package/Menu/VirtualizedList.js +28 -0
  88. package/Menu/VirtualizedListComponent.d.ts +20 -0
  89. package/Menu/VirtualizedListComponent.js +305 -0
  90. package/Menu/index.d.ts +3 -1
  91. package/Menu/index.js +2 -0
  92. package/Popper/Popper.d.ts +7 -80
  93. package/Popper/Popper.js +26 -12
  94. package/Popper/PopperContainer.js +1 -1
  95. package/Popper/usePopprer.d.ts +88 -3
  96. package/Popper/usePopprer.js +240 -65
  97. package/Selectbox/SelectboxButton.d.ts +5 -0
  98. package/Selectbox/SelectboxButton.js +48 -8
  99. package/Selectbox/SelectboxButtonWrapper.d.ts +2 -0
  100. package/Selectbox/SelectboxButtonWrapper.js +1 -17
  101. package/Selectbox/SelectboxMenu.d.ts +12 -0
  102. package/Selectbox/SelectboxMenu.js +50 -0
  103. package/Selectbox/index.d.ts +5 -5
  104. package/Selectbox/index.js +115 -97
  105. package/Surface/index.js +1 -1
  106. package/Swiper/Swiper.d.ts +57 -0
  107. package/Swiper/Swiper.js +412 -0
  108. package/Swiper/SwiperContainer.d.ts +7 -0
  109. package/Swiper/SwiperContainer.js +15 -0
  110. package/Swiper/SwiperSlide.d.ts +12 -0
  111. package/Swiper/SwiperSlide.js +58 -0
  112. package/Swiper/SwiperSlidesRenderer.d.ts +11 -0
  113. package/Swiper/SwiperSlidesRenderer.js +74 -0
  114. package/Swiper/SwiperTrack.d.ts +18 -0
  115. package/Swiper/SwiperTrack.js +55 -0
  116. package/Swiper/SwiperWrapper.d.ts +16 -0
  117. package/Swiper/SwiperWrapper.js +60 -0
  118. package/Swiper/index.d.ts +7 -0
  119. package/Swiper/index.js +26 -0
  120. package/Switch/SwitchDot.js +1 -1
  121. package/Switch/SwitchTrack.js +1 -1
  122. package/TextField/TextFieldContainer.d.ts +2 -2
  123. package/TextField/TextFieldContainer.js +5 -3
  124. package/TextField/TextFieldErrorText.d.ts +2 -2
  125. package/TextField/TextFieldErrorText.js +5 -4
  126. package/TextField/TextFieldIconWrapper.d.ts +3 -3
  127. package/TextField/TextFieldIconWrapper.js +5 -3
  128. package/TextField/TextFieldInput.d.ts +2 -2
  129. package/TextField/TextFieldInput.js +6 -4
  130. package/TextField/TextFieldInputWrapper.d.ts +2 -2
  131. package/TextField/TextFieldInputWrapper.js +5 -3
  132. package/TextField/TextFieldLabel.d.ts +2 -2
  133. package/TextField/TextFieldLabel.js +5 -3
  134. package/TextField/TextFieldLabelAsterisk.d.ts +2 -2
  135. package/TextField/TextFieldLabelAsterisk.js +5 -3
  136. package/TextField/index.d.ts +8 -1
  137. package/TextField/index.js +49 -22
  138. package/ThemeProvider/createTheme.js +2 -2
  139. package/package.json +1 -1
  140. package/Calendar/reducer.d.ts +0 -17
  141. package/Calendar/reducer.js +0 -50
  142. /package/Calendar/{IconChevronRight.d.ts → CalendarIconNext.d.ts} +0 -0
  143. /package/Calendar/{IconChevronRight.js → CalendarIconNext.js} +0 -0
@@ -0,0 +1,412 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ var __rest = (this && this.__rest) || function (s, e) {
29
+ var t = {};
30
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
31
+ t[p] = s[p];
32
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
33
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
34
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
35
+ t[p[i]] = s[p[i]];
36
+ }
37
+ return t;
38
+ };
39
+ var __importDefault = (this && this.__importDefault) || function (mod) {
40
+ return (mod && mod.__esModule) ? mod : { "default": mod };
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.Swiper = void 0;
44
+ const React = __importStar(require("react"));
45
+ const SwiperContainer_1 = __importDefault(require("./SwiperContainer"));
46
+ const SwiperWrapper_1 = __importDefault(require("./SwiperWrapper"));
47
+ const SwiperTrack_1 = __importDefault(require("./SwiperTrack"));
48
+ const SwiperSlidesRenderer_1 = __importDefault(require("./SwiperSlidesRenderer"));
49
+ __exportStar(require("./SwiperSlide"), exports);
50
+ exports.Swiper = React.forwardRef((props, ref) => {
51
+ const { children, dragThreshold = 240, snap = true, draggable = true, overrides, initialIndex = 0, infinite = false, onSlideChange, autoplay = false, autoplayInterval = 3000, pauseOnHover = true, keyboardControl = true, threshold = 20, resistance = true, slidesPerView = 1 } = props, restProps = __rest(props, ["children", "dragThreshold", "snap", "draggable", "overrides", "initialIndex", "infinite", "onSlideChange", "autoplay", "autoplayInterval", "pauseOnHover", "keyboardControl", "threshold", "resistance", "slidesPerView"]);
52
+ // #region Slides
53
+ const slides = React.useMemo(() => {
54
+ const childrenSlides = Array.isArray(children)
55
+ ? children
56
+ : [children];
57
+ if (infinite) {
58
+ if (childrenSlides.length < 2) {
59
+ console.error('To infinite loop counts of the slides must be greater than 2');
60
+ return childrenSlides;
61
+ }
62
+ if (childrenSlides.length < slidesPerView + 1) {
63
+ console.error(`For infinite loop with slidesPerView=${slidesPerView}, need at least ${slidesPerView + 1} slides`);
64
+ return childrenSlides;
65
+ }
66
+ // Используем стабильные ключи без Date.now()
67
+ const headClones = childrenSlides.slice(-slidesPerView).map((slide, i) => React.cloneElement(slide, {
68
+ key: `clone-head-${i}`,
69
+ 'data-clone': 'head',
70
+ }));
71
+ const tailClones = childrenSlides.slice(0, slidesPerView).map((slide, i) => React.cloneElement(slide, {
72
+ key: `clone-tail-${i}`,
73
+ 'data-clone': 'tail',
74
+ }));
75
+ const mainSlides = childrenSlides.map((slide, idx) => React.cloneElement(slide, {
76
+ key: `slide-${idx}`,
77
+ }));
78
+ return [...headClones, ...mainSlides, ...tailClones];
79
+ }
80
+ return childrenSlides.map((slide, idx) => React.cloneElement(slide, {
81
+ key: `slide-${idx}`,
82
+ }));
83
+ }, [children, infinite, slidesPerView]);
84
+ const total = slides.length;
85
+ const realSlidesCount = infinite ? total - 2 * slidesPerView : total;
86
+ const maxIndex = Math.max(0, total - slidesPerView);
87
+ // #region States
88
+ const [index, setIndex] = React.useState(() => {
89
+ if (!infinite) {
90
+ return Math.max(0, Math.min(initialIndex, maxIndex));
91
+ }
92
+ return initialIndex + slidesPerView;
93
+ });
94
+ const [offset, setOffset] = React.useState(0);
95
+ const [isDragging, setIsDragging] = React.useState(false);
96
+ const [disableAnimation, setDisableAnimation] = React.useState(false);
97
+ const [isPaused, setIsPaused] = React.useState(false);
98
+ // #region Refs
99
+ const dragging = React.useRef(false);
100
+ const startX = React.useRef(0);
101
+ const lastX = React.useRef(0);
102
+ const lastTime = React.useRef(0);
103
+ const velocity = React.useRef(0);
104
+ const wrapperRef = React.useRef(null);
105
+ const trackRef = React.useRef(null);
106
+ const isAnimating = React.useRef(false);
107
+ const autoplayTimer = React.useRef();
108
+ const mounted = React.useRef(true);
109
+ const normalizeTimeout = React.useRef();
110
+ // #region Real Index
111
+ const realIndex = React.useMemo(() => {
112
+ if (!infinite) {
113
+ return index;
114
+ }
115
+ const realIndex = index - slidesPerView;
116
+ if (realIndex < 0) {
117
+ return realSlidesCount + realIndex;
118
+ }
119
+ if (realIndex >= realSlidesCount) {
120
+ return realIndex - realSlidesCount;
121
+ }
122
+ return Math.min(realIndex, realSlidesCount - slidesPerView);
123
+ }, [index, infinite, slidesPerView, realSlidesCount]);
124
+ const prevRealIndex = React.useRef(realIndex);
125
+ // #region Effects
126
+ React.useEffect(() => {
127
+ if (realIndex !== prevRealIndex.current && mounted.current) {
128
+ onSlideChange === null || onSlideChange === void 0 ? void 0 : onSlideChange(realIndex);
129
+ prevRealIndex.current = realIndex;
130
+ }
131
+ }, [realIndex, onSlideChange]);
132
+ React.useEffect(() => {
133
+ if (!mounted.current)
134
+ return;
135
+ const newTotal = slides.length;
136
+ if (index >= newTotal) {
137
+ setIndex(Math.max(0, newTotal - 1));
138
+ }
139
+ }, [slides.length, index]);
140
+ // #region Normalization
141
+ const normalizeIndex = React.useCallback(() => {
142
+ if (!infinite || !mounted.current)
143
+ return;
144
+ const firstRealIndex = slidesPerView;
145
+ const lastRealIndex = total - slidesPerView - 1;
146
+ if (index < firstRealIndex || index > lastRealIndex) {
147
+ const target = index < firstRealIndex ? lastRealIndex : firstRealIndex;
148
+ setDisableAnimation(true);
149
+ requestAnimationFrame(() => {
150
+ var _a;
151
+ if (!mounted.current)
152
+ return;
153
+ (_a = trackRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
154
+ setIndex(target);
155
+ setOffset(0);
156
+ requestAnimationFrame(() => {
157
+ if (mounted.current) {
158
+ setDisableAnimation(false);
159
+ }
160
+ });
161
+ });
162
+ }
163
+ }, [index, infinite, slidesPerView, total]);
164
+ // #region Navigation API
165
+ const indexRef = React.useRef(index);
166
+ React.useEffect(() => {
167
+ indexRef.current = index;
168
+ }, [index]);
169
+ const goToIndex = React.useCallback((i) => {
170
+ if (isAnimating.current)
171
+ return;
172
+ let targetIndex = i;
173
+ if (infinite) {
174
+ targetIndex = i + slidesPerView;
175
+ const minIndex = slidesPerView;
176
+ const maxIndex = slidesPerView + realSlidesCount - 1;
177
+ targetIndex = Math.max(minIndex, Math.min(maxIndex, targetIndex));
178
+ }
179
+ else {
180
+ targetIndex = Math.max(0, Math.min(maxIndex, i));
181
+ }
182
+ if (targetIndex === indexRef.current) {
183
+ return; // никуда не едем — флаг не трогаем
184
+ }
185
+ setDisableAnimation(false);
186
+ setIndex(targetIndex);
187
+ isAnimating.current = true;
188
+ }, [infinite, slidesPerView, realSlidesCount, maxIndex]);
189
+ const next = React.useCallback(() => {
190
+ // if (isAnimating.current) return;
191
+ setDisableAnimation(false);
192
+ setIndex(prev => {
193
+ let nextIndex;
194
+ if (infinite) {
195
+ nextIndex = Math.min(prev + 1, total - 1);
196
+ }
197
+ else {
198
+ nextIndex = Math.min(prev + 1, maxIndex);
199
+ }
200
+ // если индекс не меняется — не ставим флаг анимации
201
+ if (nextIndex === prev) {
202
+ return prev;
203
+ }
204
+ isAnimating.current = true;
205
+ return nextIndex;
206
+ });
207
+ }, [infinite, maxIndex, total]);
208
+ const prev = React.useCallback(() => {
209
+ // if (isAnimating.current) return;
210
+ setDisableAnimation(false);
211
+ setIndex(prev => {
212
+ const nextIndex = Math.max(prev - 1, 0);
213
+ if (nextIndex === prev) {
214
+ return prev;
215
+ }
216
+ isAnimating.current = true;
217
+ return nextIndex;
218
+ });
219
+ }, []);
220
+ // #region Pointer Events
221
+ const onPointerDown = React.useCallback((e) => {
222
+ if (!wrapperRef.current || !draggable)
223
+ return;
224
+ dragging.current = true;
225
+ isAnimating.current = false;
226
+ setDisableAnimation(true);
227
+ setIsDragging(true);
228
+ startX.current = e.clientX;
229
+ lastX.current = e.clientX;
230
+ lastTime.current = performance.now();
231
+ velocity.current = 0;
232
+ e.target.setPointerCapture(e.pointerId);
233
+ }, [draggable]);
234
+ const onPointerMove = React.useCallback((e) => {
235
+ if (!dragging.current || isAnimating.current)
236
+ return;
237
+ const now = performance.now();
238
+ const dx = e.clientX - lastX.current;
239
+ const dt = now - lastTime.current;
240
+ if (dt > 0) {
241
+ velocity.current = dx / dt;
242
+ }
243
+ lastX.current = e.clientX;
244
+ lastTime.current = now;
245
+ let delta = lastX.current - startX.current;
246
+ if (resistance && !infinite) {
247
+ if (index === 0 && delta > 0) {
248
+ delta *= 0.3;
249
+ }
250
+ if (index === maxIndex && delta < 0) {
251
+ delta *= 0.3;
252
+ }
253
+ }
254
+ setOffset(delta);
255
+ }, [resistance, infinite, index, maxIndex]);
256
+ const onPointerUp = React.useCallback((e) => {
257
+ if (!dragging.current)
258
+ return;
259
+ const delta = lastX.current - startX.current;
260
+ const v = Math.abs(velocity.current);
261
+ const velocityFactor = Math.min(v * 250, 0.65);
262
+ const dynamicThreshold = Math.max(threshold, Math.min(dragThreshold * (1 - velocityFactor), dragThreshold));
263
+ let nextIndex = index;
264
+ if (Math.abs(delta) > dynamicThreshold) {
265
+ nextIndex = delta < 0 ? index + 1 : index - 1;
266
+ }
267
+ if (!infinite) {
268
+ nextIndex = Math.max(0, Math.min(maxIndex, nextIndex));
269
+ }
270
+ else {
271
+ nextIndex = Math.max(0, Math.min(total - 1, nextIndex));
272
+ }
273
+ setDisableAnimation(false);
274
+ if (snap) {
275
+ setIndex(nextIndex);
276
+ setOffset(0);
277
+ }
278
+ else {
279
+ setIndex(nextIndex);
280
+ }
281
+ isAnimating.current = true;
282
+ dragging.current = false;
283
+ setIsDragging(false);
284
+ e.target.releasePointerCapture(e.pointerId);
285
+ }, [threshold, dragThreshold, index, maxIndex, snap, infinite, total]);
286
+ const onLostPointerCapture = React.useCallback((e) => {
287
+ if (dragging.current) {
288
+ onPointerUp(e);
289
+ }
290
+ }, [onPointerUp]);
291
+ // #region Autoplay
292
+ const startAutoplay = React.useCallback(() => {
293
+ if (!autoplay || isPaused)
294
+ return;
295
+ autoplayTimer.current = setInterval(() => {
296
+ if (!isDragging && !isAnimating.current && mounted.current) {
297
+ next();
298
+ }
299
+ }, autoplayInterval);
300
+ }, [autoplay, autoplayInterval, isDragging, isPaused, next]);
301
+ const pause = React.useCallback(() => {
302
+ setIsPaused(true);
303
+ if (autoplayTimer.current) {
304
+ clearInterval(autoplayTimer.current);
305
+ autoplayTimer.current = undefined;
306
+ }
307
+ }, []);
308
+ const resume = React.useCallback(() => {
309
+ setIsPaused(false);
310
+ }, []);
311
+ // #region Keyboard
312
+ React.useEffect(() => {
313
+ if (!keyboardControl)
314
+ return;
315
+ const handleKeyDown = (e) => {
316
+ if (e.key === 'ArrowLeft') {
317
+ e.preventDefault();
318
+ prev();
319
+ }
320
+ else if (e.key === 'ArrowRight') {
321
+ e.preventDefault();
322
+ next();
323
+ }
324
+ };
325
+ window.addEventListener('keydown', handleKeyDown);
326
+ return () => window.removeEventListener('keydown', handleKeyDown);
327
+ }, [keyboardControl, prev, next]);
328
+ // #region Hover
329
+ React.useEffect(() => {
330
+ if (!autoplay || !pauseOnHover)
331
+ return;
332
+ const wrapper = wrapperRef.current;
333
+ if (!wrapper)
334
+ return;
335
+ const handleMouseEnter = () => pause();
336
+ const handleMouseLeave = () => resume();
337
+ wrapper.addEventListener('mouseenter', handleMouseEnter);
338
+ wrapper.addEventListener('mouseleave', handleMouseLeave);
339
+ return () => {
340
+ wrapper.removeEventListener('mouseenter', handleMouseEnter);
341
+ wrapper.removeEventListener('mouseleave', handleMouseLeave);
342
+ };
343
+ }, [autoplay, pauseOnHover, pause, resume]);
344
+ // #region Autoplay Effect
345
+ React.useEffect(() => {
346
+ if (autoplay) {
347
+ startAutoplay();
348
+ }
349
+ return () => {
350
+ if (autoplayTimer.current) {
351
+ clearInterval(autoplayTimer.current);
352
+ autoplayTimer.current = undefined;
353
+ }
354
+ };
355
+ }, [autoplay, startAutoplay, isPaused]);
356
+ // #region Transition End
357
+ React.useEffect(() => {
358
+ const track = trackRef.current;
359
+ if (!track)
360
+ return;
361
+ const handleTransitionEnd = (e) => {
362
+ if (e.propertyName !== 'transform')
363
+ return;
364
+ isAnimating.current = false;
365
+ normalizeIndex(); // <-- вот здесь
366
+ };
367
+ track.addEventListener('transitionend', handleTransitionEnd);
368
+ return () => track.removeEventListener('transitionend', handleTransitionEnd);
369
+ }, [normalizeIndex]);
370
+ // #region Mount
371
+ React.useEffect(() => {
372
+ mounted.current = true;
373
+ return () => {
374
+ mounted.current = false;
375
+ };
376
+ }, []);
377
+ // #region Imperative Handle
378
+ React.useImperativeHandle(ref, () => ({
379
+ next,
380
+ prev,
381
+ goToIndex,
382
+ getRealIndex: () => realIndex,
383
+ getTotalSlides: () => realSlidesCount,
384
+ pause,
385
+ resume,
386
+ }), [next, prev, goToIndex, realIndex, realSlidesCount, pause, resume]);
387
+ // #region Overrides
388
+ const overridesMap = React.useMemo(() => ({
389
+ Container: (overrides === null || overrides === void 0 ? void 0 : overrides.Container) || SwiperContainer_1.default,
390
+ Track: (overrides === null || overrides === void 0 ? void 0 : overrides.Track) || SwiperTrack_1.default,
391
+ Wrapper: (overrides === null || overrides === void 0 ? void 0 : overrides.Wrapper) || SwiperWrapper_1.default,
392
+ }), [overrides]);
393
+ const getSlideRealIndex = React.useCallback((domIndex) => {
394
+ if (!infinite) {
395
+ return domIndex;
396
+ }
397
+ const totalSlides = realSlidesCount;
398
+ if (domIndex < slidesPerView) {
399
+ return totalSlides - slidesPerView + domIndex;
400
+ }
401
+ if (domIndex >= total - slidesPerView) {
402
+ return domIndex - (total - slidesPerView);
403
+ }
404
+ return domIndex - slidesPerView;
405
+ }, [infinite, realSlidesCount, slidesPerView, total]);
406
+ return (React.createElement(overridesMap.Container, Object.assign({}, restProps),
407
+ React.createElement(overridesMap.Wrapper, { ref: wrapperRef, draggable: draggable, slidesPerView: slidesPerView, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: onPointerUp, onLostPointerCapture: onLostPointerCapture },
408
+ React.createElement(overridesMap.Track, { ref: trackRef, dragging: isDragging, index: index, offset: offset, disableAnimation: disableAnimation, slidesPerView: slidesPerView },
409
+ React.createElement(SwiperSlidesRenderer_1.default, { slides: slides, slidesPerView: slidesPerView, realIndex: realIndex, realSlidesCount: realSlidesCount, getSlideRealIndex: getSlideRealIndex })))));
410
+ });
411
+ exports.Swiper.displayName = 'Swiper';
412
+ exports.default = exports.Swiper;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ export type SwiperContainerProps = React.HTMLAttributes<HTMLDivElement>;
3
+ export declare const SwiperContainer: import("@emotion/styled").StyledComponent<{
4
+ theme?: import("@emotion/react").Theme | undefined;
5
+ as?: React.ElementType<any, keyof React.JSX.IntrinsicElements> | undefined;
6
+ }, React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
7
+ export default SwiperContainer;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SwiperContainer = void 0;
7
+ const styled_1 = __importDefault(require("@emotion/styled"));
8
+ exports.SwiperContainer = styled_1.default.div `
9
+ width: 100%;
10
+ max-width: 1200px;
11
+ margin: 0 auto;
12
+ overflow: hidden;
13
+ position: relative;
14
+ `;
15
+ exports.default = exports.SwiperContainer;
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ export type SwiperSlideBaseProps = React.HTMLAttributes<HTMLDivElement> & {
3
+ readonly children: React.ReactNode;
4
+ };
5
+ export type SwiperSlideProps = SwiperSlideBaseProps & {
6
+ readonly isVisible: boolean;
7
+ readonly isNearby: boolean;
8
+ readonly slidesPerView: number;
9
+ readonly key: string;
10
+ };
11
+ export declare const SwiperSlide: React.ForwardRefExoticComponent<(SwiperSlideBaseProps | SwiperSlideProps) & React.RefAttributes<HTMLDivElement>>;
12
+ export default SwiperSlide;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __rest = (this && this.__rest) || function (s, e) {
26
+ var t = {};
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
+ t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
+ t[p[i]] = s[p[i]];
33
+ }
34
+ return t;
35
+ };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.SwiperSlide = void 0;
41
+ const styled_1 = __importDefault(require("@emotion/styled"));
42
+ const React = __importStar(require("react"));
43
+ const StyledSlide = styled_1.default.div `
44
+ flex-grow: 0;
45
+ flex-shrink: 0;
46
+ flex-basis: calc(100% / ${({ $slidesPerView }) => $slidesPerView});
47
+ height: 100%;
48
+ display: flex;
49
+ align-items: center;
50
+ justify-content: center;
51
+ box-sizing: border-box;
52
+ `;
53
+ exports.SwiperSlide = React.forwardRef((props, ref) => {
54
+ const _a = props, { children, isVisible = true, slidesPerView = 1, isNearby = true } = _a, restProps = __rest(_a, ["children", "isVisible", "slidesPerView", "isNearby"]);
55
+ return (React.createElement(StyledSlide, Object.assign({ "data-is-visible": isVisible, "data-is-nearby": isNearby }, restProps, { "$slidesPerView": slidesPerView, ref: ref }), isVisible || isNearby ? children : null));
56
+ });
57
+ exports.SwiperSlide.displayName = 'SwiperSlide';
58
+ exports.default = exports.SwiperSlide;
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ import { SwiperSlideElement } from './Swiper';
3
+ export type SwiperSlidesRendererProps = {
4
+ readonly slides: readonly SwiperSlideElement[];
5
+ readonly slidesPerView: number;
6
+ readonly realIndex: number;
7
+ readonly realSlidesCount: number;
8
+ readonly getSlideRealIndex: (index: number) => number;
9
+ };
10
+ declare const _default: React.NamedExoticComponent<SwiperSlidesRendererProps>;
11
+ export default _default;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const React = __importStar(require("react"));
27
+ const SwiperSlidesRenderer = props => {
28
+ const { slides, slidesPerView, realIndex, realSlidesCount, getSlideRealIndex } = props;
29
+ // Мемоизируем вычисления видимости
30
+ const visibilityMap = React.useMemo(() => {
31
+ const map = new Map();
32
+ if (realSlidesCount <= slidesPerView) {
33
+ slides.forEach((_, i) => {
34
+ map.set(i, { isVisible: true, isNearby: false });
35
+ });
36
+ }
37
+ else {
38
+ const visibleIndices = [];
39
+ for (let j = 0; j < slidesPerView; j++) {
40
+ visibleIndices.push((realIndex + j) % realSlidesCount);
41
+ }
42
+ const prevIndex = (realIndex - 1 + realSlidesCount) % realSlidesCount;
43
+ const nextIndex = (realIndex + slidesPerView) % realSlidesCount;
44
+ slides.forEach((_, i) => {
45
+ const slideRealIndex = getSlideRealIndex(i);
46
+ const isVisible = visibleIndices.includes(slideRealIndex);
47
+ const isNearby = !isVisible && (slideRealIndex === prevIndex || slideRealIndex === nextIndex);
48
+ map.set(i, { isVisible, isNearby });
49
+ });
50
+ }
51
+ return map;
52
+ }, [slides, slidesPerView, realIndex, realSlidesCount, getSlideRealIndex]);
53
+ return (React.createElement(React.Fragment, null, slides.map((slide, i) => {
54
+ const { isVisible, isNearby } = visibilityMap.get(i) || {
55
+ isVisible: false,
56
+ isNearby: false,
57
+ };
58
+ const slideRealIndex = getSlideRealIndex(i);
59
+ // Не клонируем заново, если пропсы не изменились
60
+ if (slide.props.slidesPerView === slidesPerView &&
61
+ slide.props.isVisible === isVisible &&
62
+ slide.props.isNearby === isNearby) {
63
+ return slide;
64
+ }
65
+ return React.cloneElement(slide, {
66
+ slidesPerView,
67
+ isVisible,
68
+ isNearby,
69
+ 'data-index': i,
70
+ 'data-real-index': slideRealIndex,
71
+ });
72
+ })));
73
+ };
74
+ exports.default = React.memo(SwiperSlidesRenderer);
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+ export type SwiperTrackProps = React.HTMLAttributes<HTMLDivElement> & {
3
+ readonly children: React.ReactNode;
4
+ readonly index: number;
5
+ readonly offset: number;
6
+ readonly dragging: boolean;
7
+ readonly disableAnimation?: boolean;
8
+ readonly slidesPerView: number;
9
+ };
10
+ export declare const SwiperTrack: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
11
+ readonly children: React.ReactNode;
12
+ readonly index: number;
13
+ readonly offset: number;
14
+ readonly dragging: boolean;
15
+ readonly disableAnimation?: boolean | undefined;
16
+ readonly slidesPerView: number;
17
+ } & React.RefAttributes<HTMLDivElement>>;
18
+ export default SwiperTrack;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __rest = (this && this.__rest) || function (s, e) {
26
+ var t = {};
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
+ t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
+ t[p[i]] = s[p[i]];
33
+ }
34
+ return t;
35
+ };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.SwiperTrack = void 0;
41
+ const React = __importStar(require("react"));
42
+ const styled_1 = __importDefault(require("@emotion/styled"));
43
+ const StyledTrack = styled_1.default.div `
44
+ display: flex;
45
+ height: 100%;
46
+ transition: ${({ $dragging, $disableAnimation }) => $dragging || $disableAnimation ? 'none' : 'transform 0.3s ease'};
47
+ will-change: transform;
48
+ transform: ${({ $index, $offset, $slidesPerView }) => `translateX(calc(${-(($index * 100) / $slidesPerView)}% + ${$offset}px))`};
49
+ `;
50
+ exports.SwiperTrack = React.forwardRef((props, ref) => {
51
+ const { children, index, offset, dragging, disableAnimation, slidesPerView } = props, restProps = __rest(props, ["children", "index", "offset", "dragging", "disableAnimation", "slidesPerView"]);
52
+ return (React.createElement(StyledTrack, Object.assign({ "$dragging": dragging, "$index": index, "$offset": offset, "$disableAnimation": disableAnimation, "$slidesPerView": slidesPerView }, restProps, { ref: ref }), children));
53
+ });
54
+ exports.SwiperTrack.displayName = 'SwiperTrack';
55
+ exports.default = exports.SwiperTrack;