@via-profit/ui-kit 0.2.1-alpha.3 → 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.
@@ -12,13 +12,12 @@ const useMasked = () => {
12
12
  caret: 0,
13
13
  };
14
14
  value
15
- .replace(/\s/, '')
15
+ .replace(/\s+/g, '')
16
16
  .split('')
17
17
  .forEach((character, charIndex) => {
18
18
  const isMatch = mask.some(pattern => {
19
19
  if (typeof pattern === 'string') {
20
- return false;
21
- // return character === pattern && character;
20
+ return character === pattern && character;
22
21
  }
23
22
  if (pattern instanceof RegExp) {
24
23
  return new RegExp(pattern).test(character);
@@ -45,7 +44,9 @@ const useMasked = () => {
45
44
  if (parsedValue === '') {
46
45
  return data;
47
46
  }
48
- for (let patternIndex = 0; patternIndex < mask.length; patternIndex++) {
47
+ let patternIndex = 0;
48
+ for (patternIndex = 0; patternIndex < mask.length; patternIndex++) {
49
+ data.isValid = false;
49
50
  if (data.charIndex >= parsedValue.length) {
50
51
  break;
51
52
  }
@@ -57,6 +58,7 @@ const useMasked = () => {
57
58
  if (pattern instanceof RegExp && new RegExp(pattern).test(char)) {
58
59
  data.text = `${data.text}${char}`;
59
60
  data.charIndex += 1;
61
+ data.isValid = true;
60
62
  }
61
63
  // If char is correct (equal with pattern string)
62
64
  // then accept char into text
@@ -79,7 +81,7 @@ const useMasked = () => {
79
81
  const result = {
80
82
  text: data.text,
81
83
  caret: data.caret,
82
- isValid: data.text.length >= mask.length,
84
+ isValid: data.isValid,
83
85
  };
84
86
  return result;
85
87
  }, []);
@@ -357,7 +357,7 @@ const MenuContainer = react_1.default.forwardRef((props, ref) => {
357
357
  }));
358
358
  }
359
359
  }, [dispatch]);
360
- return (react_1.default.createElement(ClickOutside_1.default, { onOutsideClick: onRequestClose, mouseEvent: closeOutsideClick ? 'onMouseDown' : false },
360
+ return (react_1.default.createElement(ClickOutside_1.default, { onOutsideClick: onRequestClose, mouseEvent: isOpen && closeOutsideClick ? 'onMouseDown' : false },
361
361
  react_1.default.createElement(overridesMap.Popper, { isOpen: Boolean(isOpen), ref: menuPopperRef, zIndex: zIndex, anchorPos: actualPlacement, anchorElement: anchorElement, onAnchorPosChanged: newPlacement => {
362
362
  setActualPlacement(newPlacement);
363
363
  if (typeof onAnchorPosChanged === 'function') {
@@ -2,43 +2,56 @@ import * as React from 'react';
2
2
  import { SwiperContainerProps } from './SwiperContainer';
3
3
  import { SwiperWrapperProps } from './SwiperWrapper';
4
4
  import { SwiperTrackProps } from './SwiperTrack';
5
+ import SwiperSlide, { SwiperSlideBaseProps, SwiperSlideProps } from './SwiperSlide';
6
+ export * from './SwiperSlide';
7
+ export type SwiperSlideBaseElement = React.ReactElement<SwiperSlideBaseProps, typeof SwiperSlide>;
8
+ export type SwiperSlideElement = React.ReactElement<SwiperSlideProps, typeof SwiperSlide>;
5
9
  export type SwiperRef = {
6
10
  next: () => void;
7
11
  prev: () => void;
8
12
  goToIndex: (index: number) => void;
13
+ getRealIndex: () => number;
14
+ getTotalSlides: () => number;
15
+ pause: () => void;
16
+ resume: () => void;
9
17
  };
10
18
  export interface SwiperOverrides {
11
- /**
12
- * Swiper main container
13
- */
14
19
  readonly Container?: React.ComponentType<SwiperContainerProps & React.RefAttributes<HTMLDivElement>>;
15
- /**
16
- * Swiper wrapper
17
- */
18
20
  readonly Wrapper?: React.ComponentType<SwiperWrapperProps & React.RefAttributes<HTMLDivElement>>;
19
- /**
20
- * Swiper slides track
21
- */
22
21
  readonly Track?: React.ComponentType<SwiperTrackProps & React.RefAttributes<HTMLDivElement>>;
23
22
  }
24
- export type SwiperProps = React.HTMLAttributes<HTMLDivElement> & {
23
+ export type SwiperProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> & {
25
24
  readonly dragThreshold?: number;
26
25
  readonly snap?: boolean;
27
26
  readonly draggable?: boolean;
28
27
  readonly initialIndex?: number;
29
- /**
30
- * Overridable components map
31
- */
28
+ readonly infinite?: boolean;
29
+ readonly onSlideChange?: (realIndex: number) => void;
30
+ readonly autoplay?: boolean;
31
+ readonly autoplayInterval?: number;
32
+ readonly pauseOnHover?: boolean;
33
+ readonly keyboardControl?: boolean;
34
+ readonly threshold?: number;
35
+ readonly resistance?: boolean;
36
+ readonly slidesPerView?: number;
37
+ readonly children?: readonly SwiperSlideBaseElement[];
32
38
  readonly overrides?: SwiperOverrides;
33
39
  };
34
- export declare const Swiper: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
40
+ export declare const Swiper: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLDivElement>, "children"> & {
35
41
  readonly dragThreshold?: number | undefined;
36
42
  readonly snap?: boolean | undefined;
37
43
  readonly draggable?: boolean | undefined;
38
44
  readonly initialIndex?: number | undefined;
39
- /**
40
- * Overridable components map
41
- */
45
+ readonly infinite?: boolean | undefined;
46
+ readonly onSlideChange?: ((realIndex: number) => void) | undefined;
47
+ readonly autoplay?: boolean | undefined;
48
+ readonly autoplayInterval?: number | undefined;
49
+ readonly pauseOnHover?: boolean | undefined;
50
+ readonly keyboardControl?: boolean | undefined;
51
+ readonly threshold?: number | undefined;
52
+ readonly resistance?: boolean | undefined;
53
+ readonly slidesPerView?: number | undefined;
54
+ readonly children?: readonly SwiperSlideBaseElement[] | undefined;
42
55
  readonly overrides?: SwiperOverrides | undefined;
43
56
  } & React.RefAttributes<SwiperRef>>;
44
57
  export default Swiper;
package/Swiper/Swiper.js CHANGED
@@ -22,6 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
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
+ };
25
28
  var __rest = (this && this.__rest) || function (s, e) {
26
29
  var t = {};
27
30
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -42,26 +45,185 @@ const React = __importStar(require("react"));
42
45
  const SwiperContainer_1 = __importDefault(require("./SwiperContainer"));
43
46
  const SwiperWrapper_1 = __importDefault(require("./SwiperWrapper"));
44
47
  const SwiperTrack_1 = __importDefault(require("./SwiperTrack"));
48
+ const SwiperSlidesRenderer_1 = __importDefault(require("./SwiperSlidesRenderer"));
49
+ __exportStar(require("./SwiperSlide"), exports);
45
50
  exports.Swiper = React.forwardRef((props, ref) => {
46
- const { children, dragThreshold = 120, snap = true, draggable = true, overrides, initialIndex = 0 } = props, restProps = __rest(props, ["children", "dragThreshold", "snap", "draggable", "overrides", "initialIndex"]);
47
- const slides = React.Children.toArray(children);
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]);
48
84
  const total = slides.length;
49
- const [index, setIndex] = React.useState(initialIndex);
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
+ });
50
94
  const [offset, setOffset] = React.useState(0);
51
95
  const [isDragging, setIsDragging] = React.useState(false);
96
+ const [disableAnimation, setDisableAnimation] = React.useState(false);
97
+ const [isPaused, setIsPaused] = React.useState(false);
98
+ // #region Refs
52
99
  const dragging = React.useRef(false);
53
100
  const startX = React.useRef(0);
54
101
  const lastX = React.useRef(0);
55
102
  const lastTime = React.useRef(0);
56
103
  const velocity = React.useRef(0);
57
- const width = React.useRef(0);
58
104
  const wrapperRef = React.useRef(null);
59
- const onPointerDown = React.useCallback((e) => {
60
- if (!wrapperRef.current || !draggable) {
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)
61
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; // никуда не едем — флаг не трогаем
62
184
  }
63
- width.current = wrapperRef.current.offsetWidth;
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;
64
224
  dragging.current = true;
225
+ isAnimating.current = false;
226
+ setDisableAnimation(true);
65
227
  setIsDragging(true);
66
228
  startX.current = e.clientX;
67
229
  lastX.current = e.clientX;
@@ -70,9 +232,8 @@ exports.Swiper = React.forwardRef((props, ref) => {
70
232
  e.target.setPointerCapture(e.pointerId);
71
233
  }, [draggable]);
72
234
  const onPointerMove = React.useCallback((e) => {
73
- if (!dragging.current) {
235
+ if (!dragging.current || isAnimating.current)
74
236
  return;
75
- }
76
237
  const now = performance.now();
77
238
  const dx = e.clientX - lastX.current;
78
239
  const dt = now - lastTime.current;
@@ -82,58 +243,170 @@ exports.Swiper = React.forwardRef((props, ref) => {
82
243
  lastX.current = e.clientX;
83
244
  lastTime.current = now;
84
245
  let delta = lastX.current - startX.current;
85
- if (index === 0 && delta > 0) {
86
- delta *= 0.3;
87
- }
88
- if (index === total - 1 && delta < 0) {
89
- delta *= 0.3;
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
+ }
90
253
  }
91
254
  setOffset(delta);
92
- }, [index, total]);
255
+ }, [resistance, infinite, index, maxIndex]);
93
256
  const onPointerUp = React.useCallback((e) => {
94
- if (!dragging.current) {
257
+ if (!dragging.current)
95
258
  return;
96
- }
97
259
  const delta = lastX.current - startX.current;
98
260
  const v = Math.abs(velocity.current);
99
261
  const velocityFactor = Math.min(v * 250, 0.65);
100
- const threshold = Math.max(20, Math.min(dragThreshold * (1 - velocityFactor), dragThreshold));
101
- let next = index;
102
- if (Math.abs(delta) > threshold) {
103
- next = delta < 0 ? index + 1 : index - 1;
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));
104
269
  }
105
- next = Math.max(0, Math.min(total - 1, next));
270
+ else {
271
+ nextIndex = Math.max(0, Math.min(total - 1, nextIndex));
272
+ }
273
+ setDisableAnimation(false);
106
274
  if (snap) {
107
- setIndex(next);
275
+ setIndex(nextIndex);
108
276
  setOffset(0);
109
277
  }
110
278
  else {
111
- setIndex(next);
279
+ setIndex(nextIndex);
112
280
  }
281
+ isAnimating.current = true;
113
282
  dragging.current = false;
114
283
  setIsDragging(false);
115
284
  e.target.releasePointerCapture(e.pointerId);
116
- }, [dragThreshold, index, snap, total]);
117
- const next = React.useCallback(() => {
118
- setIndex(i => Math.min(total - 1, i + 1));
119
- }, [total]);
120
- const prev = React.useCallback(() => {
121
- setIndex(i => Math.max(0, i - 1));
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
+ }
122
307
  }, []);
123
- const goToIndex = React.useCallback((i) => {
124
- setIndex(Math.max(0, Math.min(total - 1, i)));
125
- }, [total]);
126
- React.useImperativeHandle(ref, () => ({ next, prev, goToIndex }), [next, prev, goToIndex]);
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
127
388
  const overridesMap = React.useMemo(() => ({
128
389
  Container: (overrides === null || overrides === void 0 ? void 0 : overrides.Container) || SwiperContainer_1.default,
129
390
  Track: (overrides === null || overrides === void 0 ? void 0 : overrides.Track) || SwiperTrack_1.default,
130
391
  Wrapper: (overrides === null || overrides === void 0 ? void 0 : overrides.Wrapper) || SwiperWrapper_1.default,
131
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]);
132
406
  return (React.createElement(overridesMap.Container, Object.assign({}, restProps),
133
- React.createElement(overridesMap.Wrapper, { ref: wrapperRef, draggable: draggable, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: onPointerUp },
134
- React.createElement(overridesMap.Track, { dragging: isDragging, index: index, offset: offset }, slides.map((slide, i) => (
135
- // eslint-disable-next-line react/no-array-index-key
136
- React.createElement(React.Fragment, { key: i }, slide)))))));
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 })))));
137
410
  });
138
411
  exports.Swiper.displayName = 'Swiper';
139
412
  exports.default = exports.Swiper;
@@ -1,7 +1,7 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  export type SwiperContainerProps = React.HTMLAttributes<HTMLDivElement>;
3
3
  export declare const SwiperContainer: import("@emotion/styled").StyledComponent<{
4
4
  theme?: import("@emotion/react").Theme | undefined;
5
- as?: import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> | undefined;
6
- }, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
5
+ as?: React.ElementType<any, keyof React.JSX.IntrinsicElements> | undefined;
6
+ }, React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
7
7
  export default SwiperContainer;
@@ -7,6 +7,7 @@ exports.SwiperContainer = void 0;
7
7
  const styled_1 = __importDefault(require("@emotion/styled"));
8
8
  exports.SwiperContainer = styled_1.default.div `
9
9
  width: 100%;
10
+ max-width: 1200px;
10
11
  margin: 0 auto;
11
12
  overflow: hidden;
12
13
  position: relative;
@@ -1,7 +1,12 @@
1
1
  import * as React from 'react';
2
- export type SwiperSlideProps = React.HTMLAttributes<HTMLDivElement> & {
3
- readonly children: React.ReactNode | readonly React.ReactNode[];
2
+ export type SwiperSlideBaseProps = React.HTMLAttributes<HTMLDivElement> & {
3
+ readonly children: React.ReactNode;
4
4
  };
5
- export declare const SwiperSlide: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
6
- readonly children: React.ReactNode | readonly React.ReactNode[];
7
- } & React.RefAttributes<HTMLDivElement>>;
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;
@@ -41,7 +41,9 @@ exports.SwiperSlide = void 0;
41
41
  const styled_1 = __importDefault(require("@emotion/styled"));
42
42
  const React = __importStar(require("react"));
43
43
  const StyledSlide = styled_1.default.div `
44
- flex: 0 0 100%;
44
+ flex-grow: 0;
45
+ flex-shrink: 0;
46
+ flex-basis: calc(100% / ${({ $slidesPerView }) => $slidesPerView});
45
47
  height: 100%;
46
48
  display: flex;
47
49
  align-items: center;
@@ -49,7 +51,8 @@ const StyledSlide = styled_1.default.div `
49
51
  box-sizing: border-box;
50
52
  `;
51
53
  exports.SwiperSlide = React.forwardRef((props, ref) => {
52
- const { children } = props, restProps = __rest(props, ["children"]);
53
- return (React.createElement(StyledSlide, Object.assign({}, restProps, { ref: ref }), children));
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));
54
56
  });
55
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;