@kolserdav/swiper 1.0.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.
- package/README.md +30 -0
- package/dist/index.css +47 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +490 -0
- package/dist/index.js.map +1 -0
- package/dist/index.modern.js +487 -0
- package/dist/index.modern.js.map +1 -0
- package/dist/index.test.d.ts +1 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# swiper
|
|
2
|
+
|
|
3
|
+
> Simple and powerfull react swiper component
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/swiper) [](https://standardjs.com)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install --save swiper
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import React, { Component } from 'react'
|
|
17
|
+
|
|
18
|
+
import MyComponent from 'swiper'
|
|
19
|
+
import 'swiper/dist/index.css'
|
|
20
|
+
|
|
21
|
+
class Example extends Component {
|
|
22
|
+
render() {
|
|
23
|
+
return <MyComponent />
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
MIT © [kolserdav](https://github.com/kolserdav)
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
._p6aGD {
|
|
2
|
+
position: relative;
|
|
3
|
+
overflow: hidden;
|
|
4
|
+
min-width: 320px;
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: 100%;
|
|
7
|
+
min-height: 80vh;
|
|
8
|
+
max-width: 100vw;
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
._3_Zua {
|
|
15
|
+
background-color: white;
|
|
16
|
+
border-radius: 1rem;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
._7l_j0 {
|
|
20
|
+
position: absolute;
|
|
21
|
+
max-width: inherit;
|
|
22
|
+
top: 0;
|
|
23
|
+
left: 0;
|
|
24
|
+
display: flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
justify-content: center;
|
|
27
|
+
}
|
|
28
|
+
._2S9j_ {
|
|
29
|
+
left: -100%;
|
|
30
|
+
}
|
|
31
|
+
._2T1oW {
|
|
32
|
+
left: 100%;
|
|
33
|
+
}
|
|
34
|
+
._uQNyq {
|
|
35
|
+
transition: left 0.4sease-in 0s;
|
|
36
|
+
}
|
|
37
|
+
._8240d {
|
|
38
|
+
transition: left 0.4s ease-out 0s;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
._1EOHv {
|
|
42
|
+
border-radius: 2px;
|
|
43
|
+
position: relative;
|
|
44
|
+
width: calc(100% - 48px);
|
|
45
|
+
height: calc(100% - 48px);
|
|
46
|
+
box-shadow: 0px 0px 5px 1px rgba(34, 60, 80, 0.14);
|
|
47
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React, { RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* One of swipe card
|
|
4
|
+
*/
|
|
5
|
+
export interface Swipe {
|
|
6
|
+
id: number;
|
|
7
|
+
children: React.ReactElement | React.ReactElement[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Callback for get next or previous card content
|
|
11
|
+
*/
|
|
12
|
+
export declare type GetSwipeHandler = (oldId: number) => Swipe | Promise<Swipe>;
|
|
13
|
+
/**
|
|
14
|
+
* Props of Swiper component
|
|
15
|
+
*/
|
|
16
|
+
interface SwiperProps {
|
|
17
|
+
/**
|
|
18
|
+
* Current card content
|
|
19
|
+
*/
|
|
20
|
+
current: Swipe;
|
|
21
|
+
/**
|
|
22
|
+
* Next card content
|
|
23
|
+
*/
|
|
24
|
+
next: Swipe;
|
|
25
|
+
/**
|
|
26
|
+
* Previous card content
|
|
27
|
+
*/
|
|
28
|
+
prev: Swipe;
|
|
29
|
+
/**
|
|
30
|
+
* Get next card handler
|
|
31
|
+
*/
|
|
32
|
+
getNext: GetSwipeHandler;
|
|
33
|
+
/**
|
|
34
|
+
* Get previous card handler
|
|
35
|
+
*/
|
|
36
|
+
getPrev: GetSwipeHandler;
|
|
37
|
+
/**
|
|
38
|
+
* Class name for content block
|
|
39
|
+
*/
|
|
40
|
+
className?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Button for swipe to next
|
|
43
|
+
*/
|
|
44
|
+
nextButtonRef?: RefObject<HTMLButtonElement | undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* Button for swipe to previous
|
|
47
|
+
*/
|
|
48
|
+
prevButtonRef?: RefObject<HTMLButtonElement | undefined>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Swiper component
|
|
52
|
+
*/
|
|
53
|
+
declare const Swiper: {
|
|
54
|
+
(props: SwiperProps): JSX.Element;
|
|
55
|
+
defaultProps: {
|
|
56
|
+
className: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export default Swiper;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var React__default = _interopDefault(React);
|
|
5
|
+
var clsx = _interopDefault(require('clsx'));
|
|
6
|
+
|
|
7
|
+
function _extends() {
|
|
8
|
+
_extends = Object.assign || function (target) {
|
|
9
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
10
|
+
var source = arguments[i];
|
|
11
|
+
|
|
12
|
+
for (var key in source) {
|
|
13
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
14
|
+
target[key] = source[key];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return _extends.apply(this, arguments);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// A type of promise-like that resolves synchronously and supports only one observer
|
|
26
|
+
const _Pact = /*#__PURE__*/(function() {
|
|
27
|
+
function _Pact() {}
|
|
28
|
+
_Pact.prototype.then = function(onFulfilled, onRejected) {
|
|
29
|
+
const result = new _Pact();
|
|
30
|
+
const state = this.s;
|
|
31
|
+
if (state) {
|
|
32
|
+
const callback = state & 1 ? onFulfilled : onRejected;
|
|
33
|
+
if (callback) {
|
|
34
|
+
try {
|
|
35
|
+
_settle(result, 1, callback(this.v));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
_settle(result, 2, e);
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
} else {
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
this.o = function(_this) {
|
|
45
|
+
try {
|
|
46
|
+
const value = _this.v;
|
|
47
|
+
if (_this.s & 1) {
|
|
48
|
+
_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
49
|
+
} else if (onRejected) {
|
|
50
|
+
_settle(result, 1, onRejected(value));
|
|
51
|
+
} else {
|
|
52
|
+
_settle(result, 2, value);
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {
|
|
55
|
+
_settle(result, 2, e);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
return _Pact;
|
|
61
|
+
})();
|
|
62
|
+
|
|
63
|
+
// Settles a pact synchronously
|
|
64
|
+
function _settle(pact, state, value) {
|
|
65
|
+
if (!pact.s) {
|
|
66
|
+
if (value instanceof _Pact) {
|
|
67
|
+
if (value.s) {
|
|
68
|
+
if (state & 1) {
|
|
69
|
+
state = value.s;
|
|
70
|
+
}
|
|
71
|
+
value = value.v;
|
|
72
|
+
} else {
|
|
73
|
+
value.o = _settle.bind(null, pact, state);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (value && value.then) {
|
|
78
|
+
value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
pact.s = state;
|
|
82
|
+
pact.v = value;
|
|
83
|
+
const observer = pact.o;
|
|
84
|
+
if (observer) {
|
|
85
|
+
observer(pact);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
|
|
91
|
+
|
|
92
|
+
const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
|
|
93
|
+
|
|
94
|
+
// Asynchronously implement a switch statement
|
|
95
|
+
function _switch(discriminant, cases) {
|
|
96
|
+
var dispatchIndex = -1;
|
|
97
|
+
var awaitBody;
|
|
98
|
+
outer: {
|
|
99
|
+
for (var i = 0; i < cases.length; i++) {
|
|
100
|
+
var test = cases[i][0];
|
|
101
|
+
if (test) {
|
|
102
|
+
var testValue = test();
|
|
103
|
+
if (testValue && testValue.then) {
|
|
104
|
+
break outer;
|
|
105
|
+
}
|
|
106
|
+
if (testValue === discriminant) {
|
|
107
|
+
dispatchIndex = i;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
// Found the default case, set it as the pending dispatch case
|
|
112
|
+
dispatchIndex = i;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (dispatchIndex !== -1) {
|
|
116
|
+
do {
|
|
117
|
+
var body = cases[dispatchIndex][1];
|
|
118
|
+
while (!body) {
|
|
119
|
+
dispatchIndex++;
|
|
120
|
+
body = cases[dispatchIndex][1];
|
|
121
|
+
}
|
|
122
|
+
var result = body();
|
|
123
|
+
if (result && result.then) {
|
|
124
|
+
awaitBody = true;
|
|
125
|
+
break outer;
|
|
126
|
+
}
|
|
127
|
+
var fallthroughCheck = cases[dispatchIndex][2];
|
|
128
|
+
dispatchIndex++;
|
|
129
|
+
} while (fallthroughCheck && !fallthroughCheck());
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const pact = new _Pact();
|
|
134
|
+
const reject = _settle.bind(null, pact, 2);
|
|
135
|
+
(awaitBody ? result.then(_resumeAfterBody) : testValue.then(_resumeAfterTest)).then(void 0, reject);
|
|
136
|
+
return pact;
|
|
137
|
+
function _resumeAfterTest(value) {
|
|
138
|
+
for (;;) {
|
|
139
|
+
if (value === discriminant) {
|
|
140
|
+
dispatchIndex = i;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
if (++i === cases.length) {
|
|
144
|
+
if (dispatchIndex !== -1) {
|
|
145
|
+
break;
|
|
146
|
+
} else {
|
|
147
|
+
_settle(pact, 1, result);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
test = cases[i][0];
|
|
152
|
+
if (test) {
|
|
153
|
+
value = test();
|
|
154
|
+
if (value && value.then) {
|
|
155
|
+
value.then(_resumeAfterTest).then(void 0, reject);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
dispatchIndex = i;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
do {
|
|
163
|
+
var body = cases[dispatchIndex][1];
|
|
164
|
+
while (!body) {
|
|
165
|
+
dispatchIndex++;
|
|
166
|
+
body = cases[dispatchIndex][1];
|
|
167
|
+
}
|
|
168
|
+
var result = body();
|
|
169
|
+
if (result && result.then) {
|
|
170
|
+
result.then(_resumeAfterBody).then(void 0, reject);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
var fallthroughCheck = cases[dispatchIndex][2];
|
|
174
|
+
dispatchIndex++;
|
|
175
|
+
} while (fallthroughCheck && !fallthroughCheck());
|
|
176
|
+
_settle(pact, 1, result);
|
|
177
|
+
}
|
|
178
|
+
function _resumeAfterBody(result) {
|
|
179
|
+
for (;;) {
|
|
180
|
+
var fallthroughCheck = cases[dispatchIndex][2];
|
|
181
|
+
if (!fallthroughCheck || fallthroughCheck()) {
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
dispatchIndex++;
|
|
185
|
+
var body = cases[dispatchIndex][1];
|
|
186
|
+
while (!body) {
|
|
187
|
+
dispatchIndex++;
|
|
188
|
+
body = cases[dispatchIndex][1];
|
|
189
|
+
}
|
|
190
|
+
result = body();
|
|
191
|
+
if (result && result.then) {
|
|
192
|
+
result.then(_resumeAfterBody).then(void 0, reject);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
_settle(pact, 1, result);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
var styles = {"container":"_p6aGD","paper":"_3_Zua","card":"_7l_j0","prev":"_2S9j_","next":"_2T1oW","back":"_uQNyq","go":"_8240d","content":"_1EOHv"};
|
|
201
|
+
|
|
202
|
+
var ANIMATION_TIMEOUT = 400;
|
|
203
|
+
|
|
204
|
+
var getSwipes = function getSwipes(__prev, __current, __next) {
|
|
205
|
+
var result = [1, 2, 3].map(function (id) {
|
|
206
|
+
var item = id === 1 ? _extends({}, __prev) : id === 2 ? _extends({}, __current) : _extends({}, __next);
|
|
207
|
+
item.type = id === 1 ? 'prev' : id === 2 ? 'current' : 'next';
|
|
208
|
+
return item;
|
|
209
|
+
});
|
|
210
|
+
return result;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
var refs = {};
|
|
214
|
+
var startClientX;
|
|
215
|
+
var lastLeft;
|
|
216
|
+
|
|
217
|
+
var Swiper = function Swiper(props) {
|
|
218
|
+
var current = props.current,
|
|
219
|
+
next = props.next,
|
|
220
|
+
prev = props.prev,
|
|
221
|
+
getNext = props.getNext,
|
|
222
|
+
getPrev = props.getPrev,
|
|
223
|
+
className = props.className,
|
|
224
|
+
prevButtonRef = props.prevButtonRef,
|
|
225
|
+
nextButtonRef = props.nextButtonRef;
|
|
226
|
+
|
|
227
|
+
var _useState = React.useState(),
|
|
228
|
+
_current = _useState[0],
|
|
229
|
+
setCurrent = _useState[1];
|
|
230
|
+
|
|
231
|
+
var _useState2 = React.useState(),
|
|
232
|
+
_prev = _useState2[0],
|
|
233
|
+
setPrev = _useState2[1];
|
|
234
|
+
|
|
235
|
+
var _useState3 = React.useState(),
|
|
236
|
+
_next = _useState3[0],
|
|
237
|
+
setNext = _useState3[1];
|
|
238
|
+
|
|
239
|
+
var _useState4 = React.useState(0),
|
|
240
|
+
windowWidth = _useState4[0],
|
|
241
|
+
setWindowWidth = _useState4[1];
|
|
242
|
+
|
|
243
|
+
var _useState5 = React.useState(0),
|
|
244
|
+
height = _useState5[0],
|
|
245
|
+
setHeight = _useState5[1];
|
|
246
|
+
|
|
247
|
+
var _useState6 = React.useState(0),
|
|
248
|
+
width = _useState6[0],
|
|
249
|
+
setWidth = _useState6[1];
|
|
250
|
+
|
|
251
|
+
var _useState7 = React.useState(0),
|
|
252
|
+
_left = _useState7[0],
|
|
253
|
+
_setLeft = _useState7[1];
|
|
254
|
+
|
|
255
|
+
var _useState8 = React.useState(0),
|
|
256
|
+
left = _useState8[0],
|
|
257
|
+
setLeft = _useState8[1];
|
|
258
|
+
|
|
259
|
+
var containerRef = React.createRef();
|
|
260
|
+
var swipes = React.useMemo(function () {
|
|
261
|
+
return getSwipes(_prev || prev, _current || current, _next || next);
|
|
262
|
+
}, [_next]);
|
|
263
|
+
|
|
264
|
+
var getRef = function getRef(id) {
|
|
265
|
+
refs[id] = refs[id] ? refs[id] : React.createRef();
|
|
266
|
+
return refs[id];
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
var setGoClass = function setGoClass() {
|
|
270
|
+
var _getRef$current, _getRef$current2, _getRef$current3;
|
|
271
|
+
|
|
272
|
+
(_getRef$current = getRef((_next === null || _next === void 0 ? void 0 : _next.id) || 0).current) === null || _getRef$current === void 0 ? void 0 : _getRef$current.classList.add(styles.go);
|
|
273
|
+
(_getRef$current2 = getRef((_prev === null || _prev === void 0 ? void 0 : _prev.id) || 0).current) === null || _getRef$current2 === void 0 ? void 0 : _getRef$current2.classList.add(styles.go);
|
|
274
|
+
(_getRef$current3 = getRef((_current === null || _current === void 0 ? void 0 : _current.id) || 0).current) === null || _getRef$current3 === void 0 ? void 0 : _getRef$current3.classList.add(styles.go);
|
|
275
|
+
setTimeout(function () {
|
|
276
|
+
var _getRef$current4, _getRef$current5, _getRef$current6;
|
|
277
|
+
|
|
278
|
+
(_getRef$current4 = getRef((_next === null || _next === void 0 ? void 0 : _next.id) || 0).current) === null || _getRef$current4 === void 0 ? void 0 : _getRef$current4.classList.remove(styles.go);
|
|
279
|
+
(_getRef$current5 = getRef((_prev === null || _prev === void 0 ? void 0 : _prev.id) || 0).current) === null || _getRef$current5 === void 0 ? void 0 : _getRef$current5.classList.remove(styles.go);
|
|
280
|
+
(_getRef$current6 = getRef((_current === null || _current === void 0 ? void 0 : _current.id) || 0).current) === null || _getRef$current6 === void 0 ? void 0 : _getRef$current6.classList.remove(styles.go);
|
|
281
|
+
}, ANIMATION_TIMEOUT);
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
var setBackClass = function setBackClass() {
|
|
285
|
+
var _getRef$current7, _getRef$current8, _getRef$current9;
|
|
286
|
+
|
|
287
|
+
(_getRef$current7 = getRef((_next === null || _next === void 0 ? void 0 : _next.id) || 0).current) === null || _getRef$current7 === void 0 ? void 0 : _getRef$current7.classList.add(styles.back);
|
|
288
|
+
(_getRef$current8 = getRef((_prev === null || _prev === void 0 ? void 0 : _prev.id) || 0).current) === null || _getRef$current8 === void 0 ? void 0 : _getRef$current8.classList.add(styles.back);
|
|
289
|
+
(_getRef$current9 = getRef((_current === null || _current === void 0 ? void 0 : _current.id) || 0).current) === null || _getRef$current9 === void 0 ? void 0 : _getRef$current9.classList.add(styles.back);
|
|
290
|
+
setLeft(0);
|
|
291
|
+
setTimeout(function () {
|
|
292
|
+
var _getRef$current10, _getRef$current11, _getRef$current12;
|
|
293
|
+
|
|
294
|
+
(_getRef$current10 = getRef((_next === null || _next === void 0 ? void 0 : _next.id) || 0).current) === null || _getRef$current10 === void 0 ? void 0 : _getRef$current10.classList.remove(styles.back);
|
|
295
|
+
(_getRef$current11 = getRef((_prev === null || _prev === void 0 ? void 0 : _prev.id) || 0).current) === null || _getRef$current11 === void 0 ? void 0 : _getRef$current11.classList.remove(styles.back);
|
|
296
|
+
(_getRef$current12 = getRef((_current === null || _current === void 0 ? void 0 : _current.id) || 0).current) === null || _getRef$current12 === void 0 ? void 0 : _getRef$current12.classList.remove(styles.back);
|
|
297
|
+
}, ANIMATION_TIMEOUT);
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
var swipe = function swipe(_lastLeft) {
|
|
301
|
+
try {
|
|
302
|
+
var _temp4 = function () {
|
|
303
|
+
if (Math.abs(_lastLeft) > width / 3) {
|
|
304
|
+
var _temp5 = function _temp5() {
|
|
305
|
+
setGoClass();
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
setLeft(0);
|
|
309
|
+
|
|
310
|
+
var _temp6 = function () {
|
|
311
|
+
if (_lastLeft < 0) {
|
|
312
|
+
setPrev(_current);
|
|
313
|
+
setCurrent(_next);
|
|
314
|
+
return Promise.resolve(getNext((_next === null || _next === void 0 ? void 0 : _next.id) || 0)).then(function (_getNext) {
|
|
315
|
+
setNext(_getNext);
|
|
316
|
+
});
|
|
317
|
+
} else {
|
|
318
|
+
return Promise.resolve(getPrev((_prev === null || _prev === void 0 ? void 0 : _prev.id) || 0)).then(function (_getPrev) {
|
|
319
|
+
setPrev(_getPrev);
|
|
320
|
+
setCurrent(_prev);
|
|
321
|
+
setNext(_current);
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}();
|
|
325
|
+
|
|
326
|
+
return _temp6 && _temp6.then ? _temp6.then(_temp5) : _temp5(_temp6);
|
|
327
|
+
} else {
|
|
328
|
+
setBackClass();
|
|
329
|
+
}
|
|
330
|
+
}();
|
|
331
|
+
|
|
332
|
+
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(function () {}) : void 0);
|
|
333
|
+
} catch (e) {
|
|
334
|
+
return Promise.reject(e);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
var onTouchHandler = function onTouchHandler(name, e) {
|
|
339
|
+
try {
|
|
340
|
+
var _touches$;
|
|
341
|
+
|
|
342
|
+
var _interrupt2 = false;
|
|
343
|
+
var touches = e.touches;
|
|
344
|
+
var clientX = (_touches$ = touches[0]) === null || _touches$ === void 0 ? void 0 : _touches$.clientX;
|
|
345
|
+
startClientX = startClientX || 0;
|
|
346
|
+
|
|
347
|
+
var _temp8 = _switch(name, [[function () {
|
|
348
|
+
return 'onTouchStart';
|
|
349
|
+
}, function () {
|
|
350
|
+
startClientX = clientX;
|
|
351
|
+
_interrupt2 = true;
|
|
352
|
+
}], [function () {
|
|
353
|
+
return 'onTouchMove';
|
|
354
|
+
}, function () {
|
|
355
|
+
lastLeft = _left - (startClientX - clientX);
|
|
356
|
+
setLeft(lastLeft);
|
|
357
|
+
_interrupt2 = true;
|
|
358
|
+
}], [function () {
|
|
359
|
+
return 'onTouchEnd';
|
|
360
|
+
}, function () {
|
|
361
|
+
return Promise.resolve(swipe(lastLeft)).then(function () {
|
|
362
|
+
_interrupt2 = true;
|
|
363
|
+
});
|
|
364
|
+
}], []]);
|
|
365
|
+
|
|
366
|
+
return Promise.resolve(_temp8 && _temp8.then ? _temp8.then(function () {}) : void 0);
|
|
367
|
+
} catch (e) {
|
|
368
|
+
return Promise.reject(e);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
var wait = function wait(miliseconds) {
|
|
373
|
+
try {
|
|
374
|
+
return Promise.resolve(new Promise(function (resolve) {
|
|
375
|
+
setTimeout(function () {
|
|
376
|
+
resolve(0);
|
|
377
|
+
}, miliseconds);
|
|
378
|
+
})).then(function () {});
|
|
379
|
+
} catch (e) {
|
|
380
|
+
return Promise.reject(e);
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
var onTouchWrapper = function onTouchWrapper(name) {
|
|
385
|
+
return function (e) {
|
|
386
|
+
onTouchHandler(name, e);
|
|
387
|
+
};
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
var clickHandler = function clickHandler(origin) {
|
|
391
|
+
var isNext = origin === 'next';
|
|
392
|
+
return function () {
|
|
393
|
+
try {
|
|
394
|
+
var coeff = isNext ? -1 : 1;
|
|
395
|
+
var leftVal = width * coeff;
|
|
396
|
+
|
|
397
|
+
if (isNext) {
|
|
398
|
+
setGoClass();
|
|
399
|
+
} else {
|
|
400
|
+
setBackClass();
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
setLeft(leftVal);
|
|
404
|
+
return Promise.resolve(wait(ANIMATION_TIMEOUT / 2)).then(function () {
|
|
405
|
+
return Promise.resolve(swipe(leftVal)).then(function () {});
|
|
406
|
+
});
|
|
407
|
+
} catch (e) {
|
|
408
|
+
return Promise.reject(e);
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
var clickNextHandler = clickHandler('next');
|
|
414
|
+
var clickPrevHandler = clickHandler('prev');
|
|
415
|
+
React.useEffect(function () {
|
|
416
|
+
var _containerRef$current, _containerRef$current2, _containerRef$current3, _containerRef$current4, _containerRef$current5, _containerRef$current6, _containerRef$current7, _containerRef$current8, _containerRef$current9;
|
|
417
|
+
|
|
418
|
+
var _width = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : (_containerRef$current2 = _containerRef$current.parentElement) === null || _containerRef$current2 === void 0 ? void 0 : (_containerRef$current3 = _containerRef$current2.getBoundingClientRect()) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.width;
|
|
419
|
+
|
|
420
|
+
var _height = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current4 = containerRef.current) === null || _containerRef$current4 === void 0 ? void 0 : (_containerRef$current5 = _containerRef$current4.parentElement) === null || _containerRef$current5 === void 0 ? void 0 : (_containerRef$current6 = _containerRef$current5.getBoundingClientRect()) === null || _containerRef$current6 === void 0 ? void 0 : _containerRef$current6.height;
|
|
421
|
+
|
|
422
|
+
var __left = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current7 = containerRef.current) === null || _containerRef$current7 === void 0 ? void 0 : (_containerRef$current8 = _containerRef$current7.parentElement) === null || _containerRef$current8 === void 0 ? void 0 : (_containerRef$current9 = _containerRef$current8.getBoundingClientRect()) === null || _containerRef$current9 === void 0 ? void 0 : _containerRef$current9.left;
|
|
423
|
+
|
|
424
|
+
var prevButton = prevButtonRef === null || prevButtonRef === void 0 ? void 0 : prevButtonRef.current;
|
|
425
|
+
var nextButton = nextButtonRef === null || nextButtonRef === void 0 ? void 0 : nextButtonRef.current;
|
|
426
|
+
var _windowWidth = document.body.clientWidth;
|
|
427
|
+
|
|
428
|
+
if (_width && !width && _height && !height) {
|
|
429
|
+
setWidth(_width);
|
|
430
|
+
setHeight(_height);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (__left && !left) {
|
|
434
|
+
_setLeft(__left);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (!windowWidth && _windowWidth) {
|
|
438
|
+
setWindowWidth(_windowWidth);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (!_current || !_prev || !_next) {
|
|
442
|
+
setCurrent(current);
|
|
443
|
+
setNext(next);
|
|
444
|
+
setPrev(prev);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
prevButton === null || prevButton === void 0 ? void 0 : prevButton.addEventListener('click', clickPrevHandler);
|
|
448
|
+
nextButton === null || nextButton === void 0 ? void 0 : nextButton.addEventListener('click', clickNextHandler);
|
|
449
|
+
return function () {
|
|
450
|
+
prevButton === null || prevButton === void 0 ? void 0 : prevButton.removeEventListener('click', clickPrevHandler);
|
|
451
|
+
nextButton === null || nextButton === void 0 ? void 0 : nextButton.removeEventListener('click', clickNextHandler);
|
|
452
|
+
};
|
|
453
|
+
}, [_next]);
|
|
454
|
+
return React__default.createElement("div", {
|
|
455
|
+
className: styles.container,
|
|
456
|
+
ref: containerRef
|
|
457
|
+
}, swipes.map(function (item) {
|
|
458
|
+
return React__default.createElement("div", {
|
|
459
|
+
onTouchMove: onTouchWrapper('onTouchMove'),
|
|
460
|
+
onTouchStart: onTouchWrapper('onTouchStart'),
|
|
461
|
+
onTouchEnd: onTouchWrapper('onTouchEnd'),
|
|
462
|
+
key: item.id,
|
|
463
|
+
id: item.id.toString(),
|
|
464
|
+
style: item.type === 'current' ? {
|
|
465
|
+
width: width,
|
|
466
|
+
height: height,
|
|
467
|
+
left: left
|
|
468
|
+
} : item.type === 'prev' ? {
|
|
469
|
+
width: width,
|
|
470
|
+
height: height,
|
|
471
|
+
left: left - windowWidth
|
|
472
|
+
} : {
|
|
473
|
+
width: width,
|
|
474
|
+
height: height,
|
|
475
|
+
left: left + windowWidth
|
|
476
|
+
},
|
|
477
|
+
className: clsx(styles.card, item.type === 'prev' ? styles.prev : item.type === 'next' ? styles.next : ''),
|
|
478
|
+
ref: getRef(item.id)
|
|
479
|
+
}, React__default.createElement("div", {
|
|
480
|
+
className: clsx(styles.content, className)
|
|
481
|
+
}, item.children));
|
|
482
|
+
}));
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
Swiper.defaultProps = {
|
|
486
|
+
className: ''
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
module.exports = Swiper;
|
|
490
|
+
//# sourceMappingURL=index.js.map
|