react-magic-card 1.1.2 → 2.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 +40 -40
- package/dist/CircleRotation/index.d.ts +3 -0
- package/dist/{MagicCircle → CircleRotation}/index.js +54 -54
- package/dist/StraightInfinity/index.d.ts +3 -0
- package/dist/{MagicStraight → StraightInfinity}/index.js +144 -75
- package/dist/common/DetailImage/index.d.ts +3 -0
- package/dist/common/{PickImage → DetailImage}/index.js +11 -10
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -5
- package/dist/types.d.ts +23 -29
- package/package.json +4 -2
- package/dist/MagicCircle/index.d.ts +0 -3
- package/dist/MagicCircle/styles.module.css +0 -14
- package/dist/MagicStraight/index.d.ts +0 -3
- package/dist/MagicStraight/styles.module.css +0 -6
- package/dist/common/PickImage/index.d.ts +0 -4
- package/dist/common/PickImage/styles.module.css +0 -14
package/README.md
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
# react-magic-card
|
|
2
|
-
|
|
3
1
|
[](https://github.com/su-pull/react-magic-card/releases/latest)
|
|
4
2
|
[](https://bundlephobia.com/package/react-magic-card)
|
|
5
3
|
[](https://opensource.org/licenses/MIT)
|
|
6
4
|
|
|
7
|
-
This is the framer motion components, that support images gallery.
|
|
5
|
+
This is the framer motion animation components, that support images gallery.
|
|
8
6
|
|
|
9
7
|
## Installation
|
|
10
8
|
|
|
@@ -15,27 +13,33 @@ npm install react-magic-card framer-motion
|
|
|
15
13
|
## Usage Guide
|
|
16
14
|
|
|
17
15
|
```tsx
|
|
18
|
-
import {
|
|
16
|
+
import { StraightInfinity } from "react-magic-card";
|
|
19
17
|
|
|
20
18
|
function MyComponent() {
|
|
21
19
|
const images = [
|
|
22
20
|
{
|
|
23
|
-
src:
|
|
24
|
-
alt:
|
|
25
|
-
}
|
|
26
|
-
|
|
21
|
+
src: "/cat.jpeg",
|
|
22
|
+
alt: "alt",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
src: "/dog.jpeg",
|
|
26
|
+
alt: "alt",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
src: "/bird.jpeg",
|
|
30
|
+
alt: "alt",
|
|
31
|
+
},
|
|
32
|
+
];
|
|
27
33
|
|
|
28
34
|
return (
|
|
29
|
-
<
|
|
35
|
+
<StraightInfinity
|
|
30
36
|
images={images}
|
|
31
37
|
width={100}
|
|
32
38
|
height={100}
|
|
33
|
-
radius={100}
|
|
34
39
|
controller={100}
|
|
35
|
-
start={
|
|
36
|
-
delay={100}
|
|
40
|
+
start={Math.ceil(images.length / 2)}
|
|
37
41
|
/>
|
|
38
|
-
)
|
|
42
|
+
);
|
|
39
43
|
}
|
|
40
44
|
```
|
|
41
45
|
|
|
@@ -48,12 +52,8 @@ function MyComponent() {
|
|
|
48
52
|
| width (required) | width of the single image |
|
|
49
53
|
| height (required) | height of the single image |
|
|
50
54
|
| controller (required) | controller size is add to the size of the component |
|
|
51
|
-
| delay | delay of the animation firing interval |
|
|
52
55
|
| offsetIndex | add an offset to the index of the components and images |
|
|
53
56
|
| reverseIndex | order the change the overlap of zindex default true |
|
|
54
|
-
| loading | loading attribute of img element in html |
|
|
55
|
-
| initialFadeRange | range of fade animation after page loaded |
|
|
56
|
-
| initialTransTime | transition time of fade animation after page loaded |
|
|
57
57
|
| className | className of the component |
|
|
58
58
|
| classImages | className of the images |
|
|
59
59
|
| classImageSelect | className of the select image |
|
|
@@ -61,24 +61,24 @@ function MyComponent() {
|
|
|
61
61
|
| animate | object in the animation property |
|
|
62
62
|
| initial | object in the animation property |
|
|
63
63
|
| transition | object in the transition property |
|
|
64
|
-
|
|
|
65
|
-
|
|
|
64
|
+
| detailTransition | object in the transition property |
|
|
65
|
+
| detailProperty | object in the detail property |
|
|
66
|
+
| loading | loading attribute of img element in html |
|
|
67
|
+
| initialFadeRange | range of fade animation after page loaded |
|
|
68
|
+
| initialTransTime | transition time of fade animation after page loaded |
|
|
66
69
|
|
|
67
|
-
##
|
|
70
|
+
## CircleRotation Properties
|
|
68
71
|
|
|
69
|
-
| Property | Meaning
|
|
70
|
-
| ----------------- |
|
|
71
|
-
| radius (required) | radius of the circle
|
|
72
|
-
| dynamic | dynamic or static for rotation the default true |
|
|
72
|
+
| Property | Meaning |
|
|
73
|
+
| ----------------- | -------------------- |
|
|
74
|
+
| radius (required) | radius of the circle |
|
|
73
75
|
|
|
74
|
-
##
|
|
76
|
+
## StraightInfinity Properties
|
|
75
77
|
|
|
76
|
-
| Property
|
|
77
|
-
|
|
|
78
|
-
| vertical
|
|
79
|
-
| margin
|
|
80
|
-
| selectOffsetX | X-axis position |
|
|
81
|
-
| selectOffsetY | Y-axis position |
|
|
78
|
+
| Property | Meaning |
|
|
79
|
+
| -------- | --------------------------------------- |
|
|
80
|
+
| vertical | vertical or horizontal the default true |
|
|
81
|
+
| margin | spacing of the between images |
|
|
82
82
|
|
|
83
83
|
## Animation Object
|
|
84
84
|
|
|
@@ -99,16 +99,16 @@ function MyComponent() {
|
|
|
99
99
|
|
|
100
100
|
It is Inherits framer motion transition object other than intera.
|
|
101
101
|
|
|
102
|
-
##
|
|
102
|
+
## detailProperty Object
|
|
103
103
|
|
|
104
|
-
| Property
|
|
105
|
-
|
|
|
106
|
-
|
|
|
107
|
-
| white
|
|
108
|
-
| alpha
|
|
109
|
-
| blur
|
|
110
|
-
| scale
|
|
111
|
-
| offset
|
|
104
|
+
| Property | Meaning |
|
|
105
|
+
| ----------- | --------------------------------------------------------- |
|
|
106
|
+
| classDetail | className of the detail image |
|
|
107
|
+
| white | white or black for background the default true |
|
|
108
|
+
| alpha | background transparency of a number between 0 ~ 1 |
|
|
109
|
+
| blur | blur intensity of a number between 1 ~ 20 a preferred |
|
|
110
|
+
| scale | scale of the detail image |
|
|
111
|
+
| offset | offset of an appearance position from the center position |
|
|
112
112
|
|
|
113
113
|
## License
|
|
114
114
|
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { CircleRotationProps } from '../types';
|
|
3
|
+
export declare const CircleRotation: ({ images, start, height, width, radius, controller, offsetIndex, reverseIndex, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, detail, detailProperty, detailTransition, loading, initialFadeRange, initialFadeTime }: CircleRotationProps) => React.JSX.Element;
|
|
@@ -26,12 +26,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.CircleRotation = void 0;
|
|
30
30
|
const react_1 = __importStar(require("react"));
|
|
31
31
|
const framer_motion_1 = require("framer-motion");
|
|
32
32
|
const styles_module_css_1 = __importDefault(require("./styles.module.css"));
|
|
33
|
-
const
|
|
34
|
-
const
|
|
33
|
+
const DetailImage_1 = require("../common/DetailImage");
|
|
34
|
+
const CircleRotation = ({ images, start, height, width, radius, controller, offsetIndex = 0, reverseIndex = true, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, detail = true, detailProperty, detailTransition, loading = 'lazy', initialFadeRange = 1, initialFadeTime = 0.2 }) => {
|
|
35
35
|
// array out of range adjusting.
|
|
36
36
|
start = Math.max(0, start);
|
|
37
37
|
start = Math.min(start, images.length - 1);
|
|
@@ -42,38 +42,33 @@ const MagicCircle = ({ images, start, height, width, dynamic = true, scrollDirec
|
|
|
42
42
|
const [initialY, setInitialY] = (0, react_1.useState)(0);
|
|
43
43
|
const [isDragging, setIsDragging] = (0, react_1.useState)(false);
|
|
44
44
|
const [hasMove, setHasMove] = (0, react_1.useState)(false);
|
|
45
|
-
const [hasShift, setHasShift] = (0, react_1.useState)(false);
|
|
46
45
|
const [hasDelayed, setHasDelayed] = (0, react_1.useState)(true);
|
|
47
46
|
const [select, setSelect] = (0, react_1.useState)(start);
|
|
48
|
-
const [
|
|
47
|
+
const [hasDetail, setHasDetail] = (0, react_1.useState)(false);
|
|
49
48
|
const refOuter = (0, react_1.useRef)(null);
|
|
50
|
-
const
|
|
49
|
+
const refDetail = (0, react_1.useRef)(null);
|
|
51
50
|
const centralAngle = ((2 * Math.PI) / images.length) * (180 / Math.PI);
|
|
52
51
|
// Functions of the rotation and select and delay.
|
|
53
52
|
// turn left
|
|
54
53
|
const shiftLeft = (0, react_1.useCallback)(() => {
|
|
55
54
|
setSelect(select == 0 ? images.length - 1 : select - 1);
|
|
56
|
-
setHasShift(false);
|
|
57
55
|
setHasDelayed(false);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}, [centralAngle, count, dynamic, images.length, select]);
|
|
56
|
+
setCount(count + centralAngle);
|
|
57
|
+
}, [centralAngle, count, images.length, select]);
|
|
61
58
|
// turn right
|
|
62
59
|
const shiftRight = (0, react_1.useCallback)(() => {
|
|
63
60
|
setSelect(select == images.length - 1 ? 0 : select + 1);
|
|
64
|
-
setHasShift(true);
|
|
65
61
|
setHasDelayed(false);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}, [centralAngle, count, dynamic, images.length, select]);
|
|
62
|
+
setCount(count - centralAngle);
|
|
63
|
+
}, [centralAngle, count, images.length, select]);
|
|
69
64
|
// Function of the desktop.
|
|
70
65
|
const handleScroll = (0, react_1.useCallback)((e) => {
|
|
71
66
|
const delta = e.deltaY;
|
|
72
67
|
if (delta < 0)
|
|
73
|
-
|
|
68
|
+
shiftLeft();
|
|
74
69
|
if (delta > 0)
|
|
75
|
-
|
|
76
|
-
}, [
|
|
70
|
+
shiftRight();
|
|
71
|
+
}, [shiftLeft, shiftRight]);
|
|
77
72
|
// Get a start y and x position in touchStart Y and X.
|
|
78
73
|
const handleTouchStart = (e) => {
|
|
79
74
|
const touch = e.touches[0];
|
|
@@ -123,12 +118,12 @@ const MagicCircle = ({ images, start, height, width, dynamic = true, scrollDirec
|
|
|
123
118
|
setTouchStartY(deltaY);
|
|
124
119
|
}, [shiftLeft, shiftRight, touchStartX, touchStartY]);
|
|
125
120
|
const handleMouseDown = (0, react_1.useCallback)((e) => {
|
|
126
|
-
if (
|
|
121
|
+
if (hasDetail)
|
|
127
122
|
return;
|
|
128
123
|
setIsDragging(true);
|
|
129
124
|
setInitialX(e.clientX);
|
|
130
125
|
setInitialY(e.clientY);
|
|
131
|
-
}, [
|
|
126
|
+
}, [hasDetail]);
|
|
132
127
|
const handleMouseMove = (0, react_1.useCallback)((e) => {
|
|
133
128
|
if (isDragging) {
|
|
134
129
|
const outer = refOuter.current;
|
|
@@ -179,45 +174,45 @@ const MagicCircle = ({ images, start, height, width, dynamic = true, scrollDirec
|
|
|
179
174
|
// Main functional, exit function if ref and hasDelayed does not exist.
|
|
180
175
|
(0, react_1.useEffect)(() => {
|
|
181
176
|
const outer = refOuter.current;
|
|
182
|
-
const
|
|
177
|
+
const detail = refDetail.current;
|
|
183
178
|
const timeId = setTimeout(() => {
|
|
184
179
|
setHasDelayed(true);
|
|
185
|
-
},
|
|
180
|
+
}, ((transition === null || transition === void 0 ? void 0 : transition.duration) / 2) * 1000);
|
|
186
181
|
// Add handle event when component mount and deps update.
|
|
187
182
|
document.addEventListener('mouseup', handleMouseUp);
|
|
188
183
|
if (!hasDelayed)
|
|
189
184
|
return;
|
|
190
|
-
|
|
185
|
+
detail.addEventListener('mousedown', handleMouseDown);
|
|
191
186
|
outer.addEventListener('mousedown', handleMouseDown);
|
|
192
187
|
document.addEventListener('mousemove', handleMouseMove);
|
|
193
188
|
outer.addEventListener('wheel', handleScroll);
|
|
194
189
|
outer.addEventListener('touchstart', handleTouchStart);
|
|
195
190
|
outer.addEventListener('touchmove', handleTouchMove);
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
191
|
+
detail.addEventListener('wheel', handleScroll);
|
|
192
|
+
detail.addEventListener('touchstart', handleTouchStart);
|
|
193
|
+
detail.addEventListener('touchmove', handleTouchMove);
|
|
199
194
|
// Clean up event and timeId when component is unmount.
|
|
200
195
|
return () => {
|
|
201
196
|
clearTimeout(timeId);
|
|
202
197
|
document.removeEventListener('mouseup', handleMouseUp);
|
|
203
|
-
|
|
198
|
+
detail.removeEventListener('mousedown', handleMouseDown);
|
|
204
199
|
outer.removeEventListener('mousedown', handleMouseDown);
|
|
205
200
|
document.removeEventListener('mousemove', handleMouseMove);
|
|
206
201
|
outer.removeEventListener('wheel', handleScroll);
|
|
207
202
|
outer.removeEventListener('touchstart', handleTouchStart);
|
|
208
203
|
outer.removeEventListener('touchmove', handleTouchMove);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
204
|
+
detail.removeEventListener('wheel', handleScroll);
|
|
205
|
+
detail.removeEventListener('touchstart', handleTouchStart);
|
|
206
|
+
detail.removeEventListener('touchmove', handleTouchMove);
|
|
212
207
|
};
|
|
213
208
|
}, [
|
|
214
|
-
delay,
|
|
215
209
|
handleMouseDown,
|
|
216
210
|
handleMouseMove,
|
|
217
211
|
handleMouseUp,
|
|
218
212
|
handleTouchMove,
|
|
219
213
|
handleScroll,
|
|
220
|
-
hasDelayed
|
|
214
|
+
hasDelayed,
|
|
215
|
+
transition === null || transition === void 0 ? void 0 : transition.duration
|
|
221
216
|
]);
|
|
222
217
|
// The controll start or end.
|
|
223
218
|
// Added event when component is mounted.
|
|
@@ -230,26 +225,26 @@ const MagicCircle = ({ images, start, height, width, dynamic = true, scrollDirec
|
|
|
230
225
|
document.body.style.overflow = 'auto';
|
|
231
226
|
};
|
|
232
227
|
const outer = refOuter.current;
|
|
233
|
-
const
|
|
228
|
+
const detail = refDetail.current;
|
|
234
229
|
// Add event.
|
|
235
230
|
outer.addEventListener('mouseover', enterControl, { passive: false });
|
|
236
231
|
outer.addEventListener('mouseout', leaveControl);
|
|
237
232
|
outer.addEventListener('touchmove', enterControl, { passive: false });
|
|
238
233
|
outer.addEventListener('touchend', leaveControl);
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
234
|
+
detail.addEventListener('mouseover', enterControl, { passive: false });
|
|
235
|
+
detail.addEventListener('mouseout', leaveControl);
|
|
236
|
+
detail.addEventListener('touchmove', enterControl, { passive: false });
|
|
237
|
+
detail.addEventListener('touchend', leaveControl);
|
|
243
238
|
// Clean up event when component is unmount.
|
|
244
239
|
return () => {
|
|
245
240
|
outer.removeEventListener('mouseover', enterControl);
|
|
246
241
|
outer.removeEventListener('mouseout', leaveControl);
|
|
247
242
|
outer.removeEventListener('touchmove', enterControl);
|
|
248
243
|
outer.removeEventListener('touchend', leaveControl);
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
244
|
+
detail.removeEventListener('mouseover', enterControl);
|
|
245
|
+
detail.removeEventListener('mouseout', leaveControl);
|
|
246
|
+
detail.removeEventListener('touchmove', enterControl);
|
|
247
|
+
detail.removeEventListener('touchend', leaveControl);
|
|
253
248
|
// page unmount with leave control.
|
|
254
249
|
leaveControl();
|
|
255
250
|
};
|
|
@@ -264,11 +259,14 @@ const MagicCircle = ({ images, start, height, width, dynamic = true, scrollDirec
|
|
|
264
259
|
e.key === 'ArrowRight' && shiftLeft();
|
|
265
260
|
e.key === 'ArrowDown' && shiftRight();
|
|
266
261
|
e.key === 'ArrowLeft' && shiftRight();
|
|
267
|
-
e.key === 'Enter' &&
|
|
268
|
-
e.key === 'Escape' &&
|
|
262
|
+
e.key === 'Enter' && setHasDetail(true);
|
|
263
|
+
e.key === 'Escape' && setHasDetail(false);
|
|
269
264
|
};
|
|
270
265
|
// has after Lazy loading fade transition.
|
|
271
266
|
const [isLoaded, setIsLoaded] = (0, react_1.useState)(false);
|
|
267
|
+
(0, react_1.useEffect)(() => {
|
|
268
|
+
setIsLoaded(true);
|
|
269
|
+
}, []);
|
|
272
270
|
return (react_1.default.createElement(framer_motion_1.LazyMotion, { features: framer_motion_1.domAnimation },
|
|
273
271
|
react_1.default.createElement("div", { className: className },
|
|
274
272
|
react_1.default.createElement(framer_motion_1.m.div, { className: styles_module_css_1.default.outer, ref: refOuter, tabIndex: offsetIndex <= 0 ? 0 : offsetIndex - 1, onKeyDown: handleKeyPress, style: {
|
|
@@ -286,8 +284,8 @@ const MagicCircle = ({ images, start, height, width, dynamic = true, scrollDirec
|
|
|
286
284
|
(hasSelect && classImageSelect) +
|
|
287
285
|
' ' +
|
|
288
286
|
classImageUnique +
|
|
289
|
-
zIndex, role: 'button', src: image.src, alt: image.alt, draggable: false, loading: loading,
|
|
290
|
-
rotate: -count,
|
|
287
|
+
zIndex, role: 'button', "aria-label": "click and scale image", src: image.src, alt: image.alt, draggable: false, loading: loading, animate: {
|
|
288
|
+
rotate: -count - ((animate === null || animate === void 0 ? void 0 : animate.rotate) ? animate === null || animate === void 0 ? void 0 : animate.rotate : 0),
|
|
291
289
|
scale: hasSelect ? animate === null || animate === void 0 ? void 0 : animate.selectScale : animate === null || animate === void 0 ? void 0 : animate.scale,
|
|
292
290
|
rotateY: hasSelect
|
|
293
291
|
? animate === null || animate === void 0 ? void 0 : animate.selectRotateY
|
|
@@ -299,12 +297,12 @@ const MagicCircle = ({ images, start, height, width, dynamic = true, scrollDirec
|
|
|
299
297
|
? animate === null || animate === void 0 ? void 0 : animate.selectRotateZ
|
|
300
298
|
: animate === null || animate === void 0 ? void 0 : animate.rotateZ,
|
|
301
299
|
opacity: hasSelect
|
|
302
|
-
?
|
|
300
|
+
? hasDetail
|
|
303
301
|
? 0
|
|
304
302
|
: animate === null || animate === void 0 ? void 0 : animate.selectOpacity
|
|
305
303
|
: animate === null || animate === void 0 ? void 0 : animate.opacity
|
|
306
304
|
}, initial: {
|
|
307
|
-
rotate: -count,
|
|
305
|
+
rotate: -count - ((initial === null || initial === void 0 ? void 0 : initial.rotate) ? initial === null || initial === void 0 ? void 0 : initial.rotate : 0),
|
|
308
306
|
scale: hasSelect ? initial === null || initial === void 0 ? void 0 : initial.selectScale : initial === null || initial === void 0 ? void 0 : initial.scale,
|
|
309
307
|
rotateY: hasSelect
|
|
310
308
|
? initial === null || initial === void 0 ? void 0 : initial.selectRotateY
|
|
@@ -318,7 +316,7 @@ const MagicCircle = ({ images, start, height, width, dynamic = true, scrollDirec
|
|
|
318
316
|
opacity: hasSelect
|
|
319
317
|
? initial === null || initial === void 0 ? void 0 : initial.selectOpacity
|
|
320
318
|
: initial === null || initial === void 0 ? void 0 : initial.opacity
|
|
321
|
-
}, transition: transition, onPointerDown: () => setSelect(index), onClick: () => hasSelect &&
|
|
319
|
+
}, transition: transition, onPointerDown: () => setSelect(index), onClick: () => hasSelect && detail && !hasMove && setHasDetail(true), style: {
|
|
322
320
|
zIndex: hasSelect ? frontImage : zIndex,
|
|
323
321
|
width: width + 'px',
|
|
324
322
|
height: height + 'px',
|
|
@@ -330,14 +328,16 @@ const MagicCircle = ({ images, start, height, width, dynamic = true, scrollDirec
|
|
|
330
328
|
radius -
|
|
331
329
|
height / 2 +
|
|
332
330
|
'px',
|
|
333
|
-
filter: isLoaded
|
|
334
|
-
? '
|
|
331
|
+
filter: initialFadeRange && isLoaded
|
|
332
|
+
? ''
|
|
335
333
|
: `blur(${initialFadeRange}px)`,
|
|
336
|
-
transition:
|
|
334
|
+
transition: initialFadeTime
|
|
335
|
+
? `filter ${initialFadeTime}s ease-in-out`
|
|
336
|
+
: ''
|
|
337
337
|
} }));
|
|
338
338
|
}))),
|
|
339
|
-
react_1.default.createElement(
|
|
340
|
-
|
|
341
|
-
},
|
|
339
|
+
react_1.default.createElement(DetailImage_1.DetailImage, { detailRef: refDetail, detailKey: select, hasDetail: hasDetail, onClick: () => {
|
|
340
|
+
setHasDetail(false);
|
|
341
|
+
}, classDetail: detailProperty === null || detailProperty === void 0 ? void 0 : detailProperty.classDetail, src: images[select].src, alt: images[select].alt, width: width, height: height, white: detailProperty === null || detailProperty === void 0 ? void 0 : detailProperty.white, alpha: detailProperty === null || detailProperty === void 0 ? void 0 : detailProperty.alpha, blur: detailProperty === null || detailProperty === void 0 ? void 0 : detailProperty.blur, scale: detailProperty === null || detailProperty === void 0 ? void 0 : detailProperty.scale, transition: detailTransition, zIndex: frontImage }))));
|
|
342
342
|
};
|
|
343
|
-
exports.
|
|
343
|
+
exports.CircleRotation = CircleRotation;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { StraightInfinityProps } from '../types';
|
|
3
|
+
export declare const StraightInfinity: ({ images, start, height, width, vertical, margin, controller, offsetIndex, reverseIndex, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, detail, detailProperty, detailTransition, loading, initialFadeRange, initialFadeTime }: StraightInfinityProps) => React.JSX.Element;
|
|
@@ -22,16 +22,25 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
25
34
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
36
|
};
|
|
28
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
38
|
+
exports.StraightInfinity = void 0;
|
|
30
39
|
const react_1 = __importStar(require("react"));
|
|
31
40
|
const framer_motion_1 = require("framer-motion");
|
|
32
41
|
const styles_module_css_1 = __importDefault(require("./styles.module.css"));
|
|
33
|
-
const
|
|
34
|
-
const
|
|
42
|
+
const DetailImage_1 = require("../common/DetailImage");
|
|
43
|
+
const StraightInfinity = ({ images, start, height, width, vertical = false, margin = 0, controller = 0, offsetIndex = 0, reverseIndex = true, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, detail = true, detailProperty, detailTransition, loading = 'lazy', initialFadeRange = 1, initialFadeTime = 0.2 }) => {
|
|
35
44
|
// array out of range adjusting.
|
|
36
45
|
start = Math.max(0, start);
|
|
37
46
|
start = Math.min(start, images.length - 1);
|
|
@@ -44,30 +53,38 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
|
|
|
44
53
|
const [hasShift, setHasShift] = (0, react_1.useState)(false);
|
|
45
54
|
const [hasDelayed, setHasDelayed] = (0, react_1.useState)(true);
|
|
46
55
|
const [select, setSelect] = (0, react_1.useState)(start);
|
|
47
|
-
const [
|
|
56
|
+
const [edge, setEdge] = (0, react_1.useState)(images.length);
|
|
57
|
+
const [hasDetail, setHasDetail] = (0, react_1.useState)(false);
|
|
48
58
|
const refOuter = (0, react_1.useRef)(null);
|
|
49
|
-
const
|
|
59
|
+
const refDetail = (0, react_1.useRef)(null);
|
|
60
|
+
const [count, setCount] = (0, react_1.useState)(0);
|
|
50
61
|
// Functions of the swipe and wheel a shifting.
|
|
51
62
|
// turn left
|
|
52
|
-
const shiftLeft = (0, react_1.useCallback)(() => {
|
|
53
|
-
setSelect(select
|
|
63
|
+
const shiftLeft = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
edge !== 0 && setSelect(select === 0 ? images.length - 1 : select - 1);
|
|
65
|
+
setEdge(edge === 0 ? images.length : edge - 1);
|
|
54
66
|
setHasShift(false);
|
|
55
67
|
setHasDelayed(false);
|
|
56
|
-
|
|
68
|
+
setCount(edge === 0 ? 5 : count + width + margin * 2);
|
|
69
|
+
return;
|
|
70
|
+
}), [count, images.length, margin, select, edge, width]);
|
|
57
71
|
// turn right
|
|
58
|
-
const shiftRight = (0, react_1.useCallback)(() => {
|
|
59
|
-
setSelect(select
|
|
72
|
+
const shiftRight = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
edge !== 5 && setSelect(select === images.length - 1 ? 0 : select + 1);
|
|
74
|
+
setEdge(edge === images.length ? 0 : edge + 1);
|
|
60
75
|
setHasShift(true);
|
|
61
76
|
setHasDelayed(false);
|
|
62
|
-
|
|
77
|
+
setCount(edge === 5 ? 0 : count - (width + margin * 2));
|
|
78
|
+
return;
|
|
79
|
+
}), [count, images.length, margin, select, edge, width]);
|
|
63
80
|
// Wheel function of the desktop.
|
|
64
|
-
const handleScroll = (0, react_1.useCallback)((e) => {
|
|
81
|
+
const handleScroll = (0, react_1.useCallback)((e) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
82
|
const delta = e.deltaY;
|
|
66
83
|
if (delta < 0)
|
|
67
84
|
shiftLeft();
|
|
68
85
|
if (delta > 0)
|
|
69
86
|
shiftRight();
|
|
70
|
-
}, [shiftLeft, shiftRight]);
|
|
87
|
+
}), [shiftLeft, shiftRight]);
|
|
71
88
|
// Get a start y and x position in touchStart Y and X.
|
|
72
89
|
const handleTouchStart = (e) => {
|
|
73
90
|
const touch = e.touches[0];
|
|
@@ -77,29 +94,29 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
|
|
|
77
94
|
// Swipe Function of the mobile.
|
|
78
95
|
const handleTouchMove = (0, react_1.useCallback)((e) => {
|
|
79
96
|
const touch = e.touches[0];
|
|
80
|
-
const delta =
|
|
97
|
+
const delta = hasDetail
|
|
81
98
|
? touch.clientX
|
|
82
99
|
: !vertical
|
|
83
100
|
? touch.clientX
|
|
84
101
|
: touch.clientY;
|
|
85
|
-
if (
|
|
102
|
+
if (hasDetail
|
|
86
103
|
? delta < touchStartX
|
|
87
104
|
: !vertical
|
|
88
105
|
? delta < touchStartX
|
|
89
106
|
: delta < touchStartY)
|
|
90
107
|
shiftLeft();
|
|
91
|
-
if (
|
|
108
|
+
if (hasDetail
|
|
92
109
|
? delta > touchStartX
|
|
93
110
|
: !vertical
|
|
94
111
|
? delta > touchStartX
|
|
95
112
|
: delta > touchStartY)
|
|
96
113
|
shiftRight();
|
|
97
|
-
|
|
114
|
+
hasDetail
|
|
98
115
|
? setTouchStartX(delta)
|
|
99
116
|
: !vertical
|
|
100
117
|
? setTouchStartX(delta)
|
|
101
118
|
: setTouchStartY(delta);
|
|
102
|
-
}, [
|
|
119
|
+
}, [hasDetail, shiftLeft, shiftRight, touchStartX, touchStartY, vertical]);
|
|
103
120
|
const handleMouseDown = (0, react_1.useCallback)((e) => {
|
|
104
121
|
setIsDragging(true);
|
|
105
122
|
setInitialX(e.clientX);
|
|
@@ -124,23 +141,23 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
|
|
|
124
141
|
// Main functional, exit function if ref and hasDelayed does not exist.
|
|
125
142
|
(0, react_1.useEffect)(() => {
|
|
126
143
|
const outer = refOuter.current;
|
|
127
|
-
const
|
|
144
|
+
const detail = refDetail.current;
|
|
128
145
|
const timeId = setTimeout(() => {
|
|
129
146
|
setHasDelayed(true);
|
|
130
|
-
},
|
|
147
|
+
}, ((transition === null || transition === void 0 ? void 0 : transition.duration) / 2) * 1000);
|
|
131
148
|
// Add handle event when component mount and deps update.
|
|
132
149
|
document.addEventListener('mouseup', handleMouseUp);
|
|
133
150
|
if (!hasDelayed)
|
|
134
151
|
return;
|
|
135
|
-
|
|
152
|
+
detail.addEventListener('mousedown', handleMouseDown);
|
|
136
153
|
outer.addEventListener('mousedown', handleMouseDown);
|
|
137
154
|
document.addEventListener('mousemove', handleMouseMove);
|
|
138
155
|
outer.addEventListener('wheel', handleScroll);
|
|
139
156
|
outer.addEventListener('touchstart', handleTouchStart);
|
|
140
157
|
outer.addEventListener('touchmove', handleTouchMove);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
158
|
+
detail.addEventListener('wheel', handleScroll);
|
|
159
|
+
detail.addEventListener('touchstart', handleTouchStart);
|
|
160
|
+
detail.addEventListener('touchmove', handleTouchMove);
|
|
144
161
|
// Clean up event and timeId when component is unmount.
|
|
145
162
|
return () => {
|
|
146
163
|
clearTimeout(timeId);
|
|
@@ -148,20 +165,20 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
|
|
|
148
165
|
outer.removeEventListener('touchstart', handleTouchStart);
|
|
149
166
|
outer.removeEventListener('touchmove', handleTouchMove);
|
|
150
167
|
document.removeEventListener('mouseup', handleMouseUp);
|
|
151
|
-
|
|
168
|
+
detail.removeEventListener('mousedown', handleMouseDown);
|
|
152
169
|
outer.removeEventListener('mousedown', handleMouseDown);
|
|
153
170
|
document.removeEventListener('mousemove', handleMouseMove);
|
|
154
|
-
|
|
155
|
-
|
|
171
|
+
detail.removeEventListener('touchstart', handleTouchStart);
|
|
172
|
+
detail.removeEventListener('touchmove', handleTouchMove);
|
|
156
173
|
};
|
|
157
174
|
}, [
|
|
158
|
-
delay,
|
|
159
175
|
handleMouseDown,
|
|
160
176
|
handleMouseMove,
|
|
161
177
|
handleMouseUp,
|
|
162
178
|
handleTouchMove,
|
|
163
179
|
handleScroll,
|
|
164
|
-
hasDelayed
|
|
180
|
+
hasDelayed,
|
|
181
|
+
transition === null || transition === void 0 ? void 0 : transition.duration
|
|
165
182
|
]);
|
|
166
183
|
// The controll start or end.
|
|
167
184
|
// Added event when component is mounted.
|
|
@@ -174,35 +191,30 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
|
|
|
174
191
|
document.body.style.overflow = 'auto';
|
|
175
192
|
};
|
|
176
193
|
const outer = refOuter.current;
|
|
177
|
-
const
|
|
194
|
+
const detail = refDetail.current;
|
|
178
195
|
// Add event.
|
|
179
196
|
outer.addEventListener('mouseover', enterControl, { passive: false });
|
|
180
197
|
outer.addEventListener('mouseout', leaveControl);
|
|
181
198
|
outer.addEventListener('touchmove', enterControl, { passive: false });
|
|
182
199
|
outer.addEventListener('touchend', leaveControl);
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
200
|
+
detail.addEventListener('mouseover', enterControl, { passive: false });
|
|
201
|
+
detail.addEventListener('mouseout', leaveControl);
|
|
202
|
+
detail.addEventListener('touchmove', enterControl, { passive: false });
|
|
203
|
+
detail.addEventListener('touchend', leaveControl);
|
|
187
204
|
// Clean up event when component is unmount.
|
|
188
205
|
return () => {
|
|
189
206
|
outer.removeEventListener('mouseover', enterControl);
|
|
190
207
|
outer.removeEventListener('mouseout', leaveControl);
|
|
191
208
|
outer.removeEventListener('touchmove', enterControl);
|
|
192
209
|
outer.removeEventListener('touchend', leaveControl);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
210
|
+
detail.removeEventListener('mouseover', enterControl);
|
|
211
|
+
detail.removeEventListener('mouseout', leaveControl);
|
|
212
|
+
detail.removeEventListener('touchmove', enterControl);
|
|
213
|
+
detail.removeEventListener('touchend', leaveControl);
|
|
197
214
|
// page unmount with leave control.
|
|
198
215
|
leaveControl();
|
|
199
216
|
};
|
|
200
217
|
}, []);
|
|
201
|
-
// average calculation.
|
|
202
|
-
let total = 0;
|
|
203
|
-
for (let i = 1; i < images.length; i++)
|
|
204
|
-
total += i;
|
|
205
|
-
const average = total / images.length;
|
|
206
218
|
// selected image.
|
|
207
219
|
const frontImage = offsetIndex + images.length + 1;
|
|
208
220
|
// keyboard control.
|
|
@@ -211,24 +223,71 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
|
|
|
211
223
|
e.key === 'ArrowUp' && shiftLeft();
|
|
212
224
|
e.key === 'ArrowRight' && shiftRight();
|
|
213
225
|
e.key === 'ArrowDown' && shiftRight();
|
|
214
|
-
e.key === 'Enter' &&
|
|
215
|
-
e.key === 'Escape' &&
|
|
226
|
+
e.key === 'Enter' && setHasDetail(true);
|
|
227
|
+
e.key === 'Escape' && setHasDetail(false);
|
|
216
228
|
};
|
|
217
229
|
// has after Lazy loading fade transition.
|
|
218
230
|
const [isLoaded, setIsLoaded] = (0, react_1.useState)(false);
|
|
231
|
+
(0, react_1.useEffect)(() => {
|
|
232
|
+
setIsLoaded(true);
|
|
233
|
+
}, []);
|
|
234
|
+
const [offsetWide, setOffsetWide] = (0, react_1.useState)(0);
|
|
235
|
+
const [offsetHeight, setOffsetHeight] = (0, react_1.useState)(0);
|
|
236
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
237
|
+
if (edge === 0 && hasShift == true) {
|
|
238
|
+
if (!vertical)
|
|
239
|
+
setOffsetWide(images.length * width + images.length * (margin * 2));
|
|
240
|
+
if (vertical)
|
|
241
|
+
setOffsetHeight(images.length * height + images.length * (margin * 2));
|
|
242
|
+
}
|
|
243
|
+
if (edge === 5 && hasShift == false) {
|
|
244
|
+
if (!vertical)
|
|
245
|
+
setOffsetWide(0);
|
|
246
|
+
if (vertical)
|
|
247
|
+
setOffsetHeight(0);
|
|
248
|
+
}
|
|
249
|
+
}, [
|
|
250
|
+
hasDelayed,
|
|
251
|
+
hasShift,
|
|
252
|
+
height,
|
|
253
|
+
images.length,
|
|
254
|
+
margin,
|
|
255
|
+
edge,
|
|
256
|
+
vertical,
|
|
257
|
+
width
|
|
258
|
+
]);
|
|
259
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
260
|
+
if (edge === 0 && hasShift == false) {
|
|
261
|
+
shiftLeft();
|
|
262
|
+
}
|
|
263
|
+
if (edge === 0 && hasShift == true) {
|
|
264
|
+
shiftRight();
|
|
265
|
+
}
|
|
266
|
+
}, [hasDelayed, hasShift, shiftLeft, shiftRight, edge]);
|
|
219
267
|
return (react_1.default.createElement(framer_motion_1.LazyMotion, { features: framer_motion_1.domAnimation },
|
|
220
268
|
react_1.default.createElement("div", { className: className },
|
|
221
|
-
react_1.default.createElement(
|
|
269
|
+
react_1.default.createElement(framer_motion_1.m.div, { className: styles_module_css_1.default.outer, ref: refOuter, tabIndex: offsetIndex <= 0 ? 0 : offsetIndex - 1, onKeyDown: handleKeyPress, style: {
|
|
222
270
|
zIndex: offsetIndex - 1,
|
|
223
271
|
width: !vertical
|
|
224
|
-
? images.length * (width + margin * 2) + controller + 'px'
|
|
272
|
+
? images.length * (width + margin * 2) * 6 + controller + 'px'
|
|
225
273
|
: width + controller,
|
|
226
274
|
height: vertical
|
|
227
|
-
? images.length * (height + margin * 2) + controller + 'px'
|
|
275
|
+
? images.length * (height + margin * 2) * 6 + controller + 'px'
|
|
228
276
|
: height + controller,
|
|
229
277
|
flexDirection: vertical ? 'column' : 'row'
|
|
230
|
-
}
|
|
278
|
+
}, animate: {
|
|
279
|
+
x: !vertical ? count + offsetWide : 0,
|
|
280
|
+
y: vertical ? count + offsetHeight : 0
|
|
281
|
+
}, transition: transition }, images.map((image, index) => {
|
|
231
282
|
const hasSelect = images[select] == images[index];
|
|
283
|
+
const hasEdge = () => {
|
|
284
|
+
for (let i = edge; i <= images.length - 1; i++) {
|
|
285
|
+
if (images[i] === images[index]) {
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return false;
|
|
290
|
+
};
|
|
232
291
|
const zIndex = reverseIndex
|
|
233
292
|
? offsetIndex + images.length - 1 - index
|
|
234
293
|
: offsetIndex + index;
|
|
@@ -237,22 +296,15 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
|
|
|
237
296
|
(hasSelect && classImageSelect) +
|
|
238
297
|
' ' +
|
|
239
298
|
classImageUnique +
|
|
240
|
-
index, src: image.src, alt: image.alt, role: 'button', draggable: false, loading: loading,
|
|
241
|
-
|
|
242
|
-
?
|
|
243
|
-
? (average - index) * height +
|
|
244
|
-
(average - index) * (margin * 2) +
|
|
245
|
-
selectOffsetY
|
|
246
|
-
: selectOffsetY
|
|
299
|
+
index, src: image.src, alt: image.alt, role: 'button', "aria-label": "click and scale image", draggable: false, loading: loading, animate: {
|
|
300
|
+
x: !vertical && hasEdge()
|
|
301
|
+
? -(images.length * width + images.length * (margin * 2))
|
|
247
302
|
: 0,
|
|
248
|
-
|
|
249
|
-
?
|
|
250
|
-
? (average - index) * width +
|
|
251
|
-
(average - index) * (margin * 2) +
|
|
252
|
-
selectOffsetX
|
|
253
|
-
: selectOffsetX
|
|
303
|
+
y: vertical && hasEdge()
|
|
304
|
+
? -(images.length * height + images.length * (margin * 2))
|
|
254
305
|
: 0,
|
|
255
306
|
scale: hasSelect ? animate === null || animate === void 0 ? void 0 : animate.selectScale : animate === null || animate === void 0 ? void 0 : animate.scale,
|
|
307
|
+
rotate: hasSelect ? animate === null || animate === void 0 ? void 0 : animate.selectRotate : animate === null || animate === void 0 ? void 0 : animate.rotate,
|
|
256
308
|
rotateY: hasSelect
|
|
257
309
|
? animate === null || animate === void 0 ? void 0 : animate.selectRotateY
|
|
258
310
|
: animate === null || animate === void 0 ? void 0 : animate.rotateY,
|
|
@@ -262,13 +314,16 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
|
|
|
262
314
|
rotateZ: hasSelect
|
|
263
315
|
? animate === null || animate === void 0 ? void 0 : animate.selectRotateZ
|
|
264
316
|
: animate === null || animate === void 0 ? void 0 : animate.rotateZ,
|
|
265
|
-
opacity:
|
|
266
|
-
?
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
317
|
+
opacity: images[images[edge] === images[images.length] ? 0 : edge] === images[index] || images[edge - 1] === images[index]
|
|
318
|
+
? 0
|
|
319
|
+
: hasSelect
|
|
320
|
+
? hasDetail
|
|
321
|
+
? 0
|
|
322
|
+
: animate === null || animate === void 0 ? void 0 : animate.selectOpacity
|
|
323
|
+
: animate === null || animate === void 0 ? void 0 : animate.opacity
|
|
270
324
|
}, initial: {
|
|
271
325
|
scale: hasSelect ? initial === null || initial === void 0 ? void 0 : initial.selectScale : initial === null || initial === void 0 ? void 0 : initial.scale,
|
|
326
|
+
rotate: hasSelect ? animate === null || animate === void 0 ? void 0 : animate.selectRotate : animate === null || animate === void 0 ? void 0 : animate.rotate,
|
|
272
327
|
rotateY: hasSelect
|
|
273
328
|
? initial === null || initial === void 0 ? void 0 : initial.selectRotateY
|
|
274
329
|
: initial === null || initial === void 0 ? void 0 : initial.rotateY,
|
|
@@ -280,8 +335,17 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
|
|
|
280
335
|
: initial === null || initial === void 0 ? void 0 : initial.rotateZ,
|
|
281
336
|
opacity: hasSelect ? initial === null || initial === void 0 ? void 0 : initial.selectOpacity : initial === null || initial === void 0 ? void 0 : initial.opacity
|
|
282
337
|
}, transition: transition, onClick: () => {
|
|
283
|
-
|
|
284
|
-
|
|
338
|
+
hasSelect && detail && !hasMove && setHasDetail(true);
|
|
339
|
+
if (!hasDelayed)
|
|
340
|
+
return;
|
|
341
|
+
images[select - 1] === images[index] ||
|
|
342
|
+
(select === 0 && images[images.length - 1] === images[index])
|
|
343
|
+
? shiftLeft()
|
|
344
|
+
: images[select + 1] === images[index] ||
|
|
345
|
+
(select === images.length - 1 &&
|
|
346
|
+
images[0] === images[index])
|
|
347
|
+
? shiftRight()
|
|
348
|
+
: null;
|
|
285
349
|
}, style: {
|
|
286
350
|
zIndex: hasSelect ? frontImage : zIndex,
|
|
287
351
|
width: width + 'px',
|
|
@@ -289,12 +353,17 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
|
|
|
289
353
|
margin: vertical
|
|
290
354
|
? margin + 'px' + ' 0'
|
|
291
355
|
: '0 ' + margin + 'px',
|
|
292
|
-
filter:
|
|
293
|
-
|
|
356
|
+
filter: initialFadeRange && isLoaded
|
|
357
|
+
? ''
|
|
358
|
+
: `blur(${initialFadeRange}px)`,
|
|
359
|
+
transition: initialFadeTime
|
|
360
|
+
? `filter ${initialFadeTime}s ease-in-out`
|
|
361
|
+
: ''
|
|
294
362
|
} }));
|
|
295
363
|
})),
|
|
296
|
-
react_1.default.createElement(
|
|
297
|
-
|
|
298
|
-
},
|
|
364
|
+
react_1.default.createElement(DetailImage_1.DetailImage, { detailRef: refDetail, detailKey: select, hasDetail: hasDetail, onClick: () => {
|
|
365
|
+
setHasDetail(false);
|
|
366
|
+
}, classDetail: detailProperty === null || detailProperty === void 0 ? void 0 : detailProperty.classDetail, src: images[select].src, alt: images[select].alt, width: width, height: height, white: detailProperty === null || detailProperty === void 0 ? void 0 : detailProperty.white, alpha: detailProperty === null || detailProperty === void 0 ? void 0 : detailProperty.alpha, blur: detailProperty === null || detailProperty === void 0 ? void 0 : detailProperty.blur, scale: detailProperty === null || detailProperty === void 0 ? void 0 : detailProperty.scale, transition: detailTransition, zIndex: frontImage }),
|
|
367
|
+
react_1.default.createElement(react_1.default.Fragment, null, select))));
|
|
299
368
|
};
|
|
300
|
-
exports.
|
|
369
|
+
exports.StraightInfinity = StraightInfinity;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { DetailImageProps } from '../../types';
|
|
3
|
+
export declare const DetailImage: ({ onClick, classDetail, hasDetail, detailRef, detailKey, src, alt, width, height, zIndex, white, alpha, blur, scale, transition }: DetailImageProps) => React.JSX.Element;
|
|
@@ -3,26 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DetailImage = void 0;
|
|
6
7
|
const react_1 = __importDefault(require("react"));
|
|
7
8
|
const framer_motion_1 = require("framer-motion");
|
|
8
9
|
const styles_module_css_1 = __importDefault(require("./styles.module.css"));
|
|
9
|
-
const
|
|
10
|
-
const backdropFilter =
|
|
11
|
-
const background =
|
|
10
|
+
const DetailImage = ({ onClick, classDetail, hasDetail, detailRef, detailKey, src, alt, width, height, zIndex, white = true, alpha = 0.3, blur = 3, scale = 2.5, transition }) => {
|
|
11
|
+
const backdropFilter = hasDetail ? `blur(${blur}px)` : undefined;
|
|
12
|
+
const background = hasDetail
|
|
12
13
|
? white
|
|
13
14
|
? `rgba(255, 255, 255, ${alpha})`
|
|
14
15
|
: `rgba(0, 0, 0, ${alpha})`
|
|
15
16
|
: undefined;
|
|
16
|
-
return (react_1.default.createElement(framer_motion_1.m.div, { role: "button", onClick: onClick, ref:
|
|
17
|
+
return (react_1.default.createElement(framer_motion_1.m.div, { role: "button", onClick: onClick, ref: detailRef, className: styles_module_css_1.default.full_size, animate: {
|
|
17
18
|
zIndex: zIndex,
|
|
18
|
-
opacity:
|
|
19
|
-
pointerEvents:
|
|
19
|
+
opacity: hasDetail ? 1 : 0,
|
|
20
|
+
pointerEvents: hasDetail ? 'auto' : 'none'
|
|
20
21
|
}, style: { backdropFilter: backdropFilter, background: background }, transition: transition },
|
|
21
|
-
react_1.default.createElement(framer_motion_1.m.img, { key:
|
|
22
|
+
react_1.default.createElement(framer_motion_1.m.img, { key: detailKey, className: classDetail + ' ' + styles_module_css_1.default.no_select, src: src, alt: alt, width: width, height: height, draggable: false, animate: {
|
|
22
23
|
zIndex: zIndex + 1,
|
|
23
24
|
scale: scale,
|
|
24
|
-
opacity:
|
|
25
|
+
opacity: hasDetail ? 1 : 0,
|
|
25
26
|
x: 0
|
|
26
|
-
}, initial: { scale: 1, opacity: 0
|
|
27
|
+
}, initial: { scale: 1, opacity: 0 }, transition: transition })));
|
|
27
28
|
};
|
|
28
|
-
exports.
|
|
29
|
+
exports.DetailImage = DetailImage;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
import { CircleRotation } from './CircleRotation';
|
|
2
|
+
import { StraightInfinity } from './StraightInfinity';
|
|
3
|
+
export { CircleRotation };
|
|
4
|
+
export { StraightInfinity };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
const
|
|
7
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.StraightInfinity = exports.CircleRotation = void 0;
|
|
4
|
+
const CircleRotation_1 = require("./CircleRotation");
|
|
5
|
+
Object.defineProperty(exports, "CircleRotation", { enumerable: true, get: function () { return CircleRotation_1.CircleRotation; } });
|
|
6
|
+
const StraightInfinity_1 = require("./StraightInfinity");
|
|
7
|
+
Object.defineProperty(exports, "StraightInfinity", { enumerable: true, get: function () { return StraightInfinity_1.StraightInfinity; } });
|
package/dist/types.d.ts
CHANGED
|
@@ -5,11 +5,13 @@ type ImageProperty = {
|
|
|
5
5
|
};
|
|
6
6
|
type AnimationProperty = {
|
|
7
7
|
scale?: number;
|
|
8
|
+
rotate?: number;
|
|
8
9
|
rotateY?: number;
|
|
9
10
|
rotateX?: number;
|
|
10
11
|
rotateZ?: number;
|
|
11
12
|
opacity?: number;
|
|
12
13
|
selectScale?: number;
|
|
14
|
+
selectRotate?: number;
|
|
13
15
|
selectRotateY?: number;
|
|
14
16
|
selectRotateX?: number;
|
|
15
17
|
selectRotateZ?: number;
|
|
@@ -26,12 +28,9 @@ type TransitionProperty = {
|
|
|
26
28
|
damping?: number;
|
|
27
29
|
mass?: number;
|
|
28
30
|
stiffness?: number;
|
|
29
|
-
velocity?: number;
|
|
30
|
-
restSpeed?: number;
|
|
31
|
-
restDelta?: number;
|
|
32
31
|
};
|
|
33
|
-
type
|
|
34
|
-
|
|
32
|
+
type DetailProperty = {
|
|
33
|
+
classDetail?: string;
|
|
35
34
|
white?: boolean;
|
|
36
35
|
alpha?: number;
|
|
37
36
|
blur?: number;
|
|
@@ -41,15 +40,11 @@ type PickProperty = {
|
|
|
41
40
|
type CommonProperty = {
|
|
42
41
|
images: ImageProperty[];
|
|
43
42
|
start: number;
|
|
44
|
-
loading?: 'eager' | 'lazy';
|
|
45
43
|
height: number;
|
|
46
44
|
width: number;
|
|
47
45
|
controller: number;
|
|
48
|
-
delay: number;
|
|
49
46
|
offsetIndex?: number;
|
|
50
47
|
reverseIndex?: boolean;
|
|
51
|
-
initialFadeRange: number;
|
|
52
|
-
initialTransTime: number;
|
|
53
48
|
className?: string;
|
|
54
49
|
classImages?: string;
|
|
55
50
|
classImageSelect?: string;
|
|
@@ -57,36 +52,36 @@ type CommonProperty = {
|
|
|
57
52
|
animate?: AnimationProperty;
|
|
58
53
|
initial?: AnimationProperty;
|
|
59
54
|
transition?: TransitionProperty;
|
|
55
|
+
loading?: 'eager' | 'lazy';
|
|
56
|
+
initialFadeRange?: number;
|
|
57
|
+
initialFadeTime?: number;
|
|
60
58
|
};
|
|
61
|
-
type
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
type DetailOn = {
|
|
60
|
+
detail?: true;
|
|
61
|
+
detailProperty: DetailProperty;
|
|
62
|
+
detailTransition: TransitionProperty;
|
|
65
63
|
};
|
|
66
|
-
type
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
type DetailOff = {
|
|
65
|
+
detail?: false;
|
|
66
|
+
detailProperty?: undefined;
|
|
67
|
+
detailTransition?: undefined;
|
|
70
68
|
};
|
|
71
|
-
type MagicProperty = CommonProperty & (
|
|
72
|
-
export type
|
|
69
|
+
type MagicProperty = CommonProperty & (DetailOn | DetailOff);
|
|
70
|
+
export type CircleRotationProps = MagicProperty & {
|
|
73
71
|
radius: number;
|
|
74
|
-
dynamic?: boolean;
|
|
75
|
-
scrollDirection?: boolean;
|
|
76
72
|
};
|
|
77
|
-
export type
|
|
73
|
+
export type StraightInfinityProps = MagicProperty & {
|
|
78
74
|
vertical?: boolean;
|
|
79
75
|
margin?: number;
|
|
80
76
|
selectOffsetX?: number;
|
|
81
77
|
selectOffsetY?: number;
|
|
82
78
|
};
|
|
83
|
-
export type
|
|
79
|
+
export type DetailImageProps = {
|
|
84
80
|
onClick: MouseEventHandler<HTMLDivElement>;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
argKey: number;
|
|
81
|
+
classDetail?: string;
|
|
82
|
+
hasDetail: boolean;
|
|
83
|
+
detailRef: Ref<HTMLDivElement>;
|
|
84
|
+
detailKey: number;
|
|
90
85
|
src: string;
|
|
91
86
|
alt: string;
|
|
92
87
|
width: number;
|
|
@@ -96,7 +91,6 @@ export type PickImageProps = {
|
|
|
96
91
|
alpha?: number;
|
|
97
92
|
blur?: number;
|
|
98
93
|
scale?: number;
|
|
99
|
-
offset?: number;
|
|
100
94
|
transition?: TransitionProperty;
|
|
101
95
|
};
|
|
102
96
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-magic-card",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "React Component library for images gallery using the framer motion animation.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
"component",
|
|
24
24
|
"animation",
|
|
25
25
|
"images",
|
|
26
|
-
"gallery"
|
|
26
|
+
"gallery",
|
|
27
|
+
"circle",
|
|
28
|
+
"infinity"
|
|
27
29
|
],
|
|
28
30
|
"license": "MIT",
|
|
29
31
|
"dependencies": {
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { MagicCircleProps } from '../types';
|
|
3
|
-
export declare const MagicCircle: ({ images, start, height, width, dynamic, scrollDirection, radius, delay, controller, offsetIndex, reverseIndex, loading, initialFadeRange, initialTransTime, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, pickScale, pickProperty, pickTransition }: MagicCircleProps) => React.JSX.Element;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { MagicStraightProps } from '../types';
|
|
3
|
-
export declare const MagicStraight: ({ images, start, height, width, vertical, margin, selectOffsetX, selectOffsetY, controller, delay, offsetIndex, reverseIndex, loading, initialFadeRange, initialTransTime, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, pickScale, pickProperty, pickTransition }: MagicStraightProps) => React.JSX.Element;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { PickImageProps } from '../../types';
|
|
3
|
-
declare const PickImage: ({ onClick, classPick, hasPick, hasShift, argRef, argKey, src, alt, width, height, zIndex, white, alpha, blur, scale, offset, transition }: PickImageProps) => React.JSX.Element;
|
|
4
|
-
export default PickImage;
|