@get-set/gs-zoom 0.0.1
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 +46 -0
- package/dist/GSZoom.css +235 -0
- package/dist/actions/general.js +30 -0
- package/dist/actions/getAdjustTransform.js +43 -0
- package/dist/actions/getCurrentParams.js +42 -0
- package/dist/actions/getTranslateCoordToPoint.js +41 -0
- package/dist/actions/init.js +21 -0
- package/dist/actions/initActionEvents.js +93 -0
- package/dist/actions/initAdditionals.js +118 -0
- package/dist/actions/initAdjust.js +107 -0
- package/dist/actions/initAdjustAdditionalActive.js +33 -0
- package/dist/actions/initArrows.js +44 -0
- package/dist/actions/initAutoplay.js +81 -0
- package/dist/actions/initChange.js +73 -0
- package/dist/actions/initClose.js +28 -0
- package/dist/actions/initDraggle.js +303 -0
- package/dist/actions/initDraw.js +79 -0
- package/dist/actions/initDrawItem.js +83 -0
- package/dist/actions/initFullScreen.js +32 -0
- package/dist/actions/initLightBox.js +33 -0
- package/dist/actions/initMagnifier.js +54 -0
- package/dist/actions/initNavigateWithKeys.js +27 -0
- package/dist/actions/initWheel.js +51 -0
- package/dist/actions/setStyles.js +24 -0
- package/dist/components/GSZoom.js +115 -0
- package/dist/components/styles/GSZoom.css +235 -0
- package/dist/components/styles/GSZoom.css.map +1 -0
- package/dist/components/styles/GSZoom.scss +254 -0
- package/dist/constants/defaultParams.js +20 -0
- package/dist/constants/icons.js +23 -0
- package/dist/constants/magnifierDefaultProps.js +7 -0
- package/dist/constants/types.js +6 -0
- package/dist/helpers/uihelpers.js +9 -0
- package/index.js +3 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Get-Set Carousel
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
Advanced level React carousel plugin
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
To install this package, run:
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
npm i @get-set/gs-carousel
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```jsx
|
|
18
|
+
import GSCarousel from '@get-set/gs-carousel';
|
|
19
|
+
|
|
20
|
+
export default function Carousel() {
|
|
21
|
+
return (
|
|
22
|
+
<GSCarousel
|
|
23
|
+
slidesToShow={2}
|
|
24
|
+
slidesToScroll={1}
|
|
25
|
+
gap='2rem'
|
|
26
|
+
focusOnSelect
|
|
27
|
+
autoplay
|
|
28
|
+
>
|
|
29
|
+
<div> //GSCarousel 1-st item
|
|
30
|
+
<img src="image1.jpg" />
|
|
31
|
+
</div>
|
|
32
|
+
<p> //GSCarousel 2-nd item
|
|
33
|
+
<span>text1</span>
|
|
34
|
+
<a>link</a>
|
|
35
|
+
</p>
|
|
36
|
+
<img src="image3.jpg" /> //GSCarousel 3-rd item
|
|
37
|
+
<section> //GSCarousel 4-th item
|
|
38
|
+
<img src="image4.jpg" />
|
|
39
|
+
</section>
|
|
40
|
+
</GSCarousel>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
## Props
|
|
45
|
+
|
|
46
|
+
You can see all properties using jshint
|
package/dist/GSZoom.css
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
html.gs-zoom-opened {
|
|
2
|
+
overflow: hidden !important;
|
|
3
|
+
touch-action: pan-x pan-y;
|
|
4
|
+
}
|
|
5
|
+
html.gs-zoom-opened body {
|
|
6
|
+
touch-action: pan-x pan-y;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.gs-zoom-magnifier-instance:hover {
|
|
10
|
+
cursor: none;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.gs-zoom-magnifier {
|
|
14
|
+
pointer-events: none;
|
|
15
|
+
position: fixed;
|
|
16
|
+
z-index: 9999;
|
|
17
|
+
border: 4px solid #fff;
|
|
18
|
+
aspect-ratio: 1;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
}
|
|
21
|
+
.gs-zoom-magnifier[data-type=circle] {
|
|
22
|
+
border-radius: 50%;
|
|
23
|
+
}
|
|
24
|
+
.gs-zoom-magnifier img {
|
|
25
|
+
position: absolute;
|
|
26
|
+
transform-origin: top left;
|
|
27
|
+
max-width: unset !important;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.gs-zoom-container {
|
|
31
|
+
position: fixed;
|
|
32
|
+
z-index: 9999999999;
|
|
33
|
+
width: 100vw;
|
|
34
|
+
height: 100dvh;
|
|
35
|
+
top: 0;
|
|
36
|
+
left: 0;
|
|
37
|
+
overflow: hidden;
|
|
38
|
+
-webkit-backdrop-filter: blur(50px);
|
|
39
|
+
backdrop-filter: blur(50px);
|
|
40
|
+
}
|
|
41
|
+
.gs-zoom-container .gs-zoom-autoplayline {
|
|
42
|
+
position: fixed;
|
|
43
|
+
height: 4px;
|
|
44
|
+
top: 0;
|
|
45
|
+
left: 0;
|
|
46
|
+
z-index: 999;
|
|
47
|
+
background-color: red;
|
|
48
|
+
}
|
|
49
|
+
.gs-zoom-container button {
|
|
50
|
+
cursor: pointer;
|
|
51
|
+
outline: none !important;
|
|
52
|
+
}
|
|
53
|
+
.gs-zoom-container * {
|
|
54
|
+
-webkit-user-drag: none;
|
|
55
|
+
-moz-user-select: none;
|
|
56
|
+
-webkit-user-select: none;
|
|
57
|
+
user-select: none;
|
|
58
|
+
}
|
|
59
|
+
.gs-zoom-container .gs-zoom-header {
|
|
60
|
+
position: fixed;
|
|
61
|
+
right: 10px;
|
|
62
|
+
top: 10px;
|
|
63
|
+
display: flex;
|
|
64
|
+
justify-content: flex-end;
|
|
65
|
+
align-items: center;
|
|
66
|
+
z-index: 99;
|
|
67
|
+
}
|
|
68
|
+
.gs-zoom-container .gs-zoom-header .gs-zoom-actions {
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
}
|
|
72
|
+
.gs-zoom-container .gs-zoom-header .gs-zoom-actions .gs-zoom-action {
|
|
73
|
+
width: 40px;
|
|
74
|
+
height: 40px;
|
|
75
|
+
background-color: rgba(35, 35, 35, 0.65);
|
|
76
|
+
display: flex;
|
|
77
|
+
align-items: center;
|
|
78
|
+
justify-content: center;
|
|
79
|
+
border: none;
|
|
80
|
+
}
|
|
81
|
+
.gs-zoom-container .gs-zoom-header .gs-zoom-actions .gs-zoom-action svg {
|
|
82
|
+
fill: #fff;
|
|
83
|
+
width: 18px;
|
|
84
|
+
}
|
|
85
|
+
.gs-zoom-container .gs-zoom-img-list {
|
|
86
|
+
position: relative;
|
|
87
|
+
z-index: 2;
|
|
88
|
+
display: flex;
|
|
89
|
+
width: -moz-max-content;
|
|
90
|
+
width: max-content;
|
|
91
|
+
}
|
|
92
|
+
.gs-zoom-container .gs-zoom-img-list .gs-zoom-main-img {
|
|
93
|
+
width: 100vw;
|
|
94
|
+
height: 100dvh;
|
|
95
|
+
display: flex;
|
|
96
|
+
align-items: center;
|
|
97
|
+
justify-content: center;
|
|
98
|
+
position: relative;
|
|
99
|
+
overflow: hidden;
|
|
100
|
+
}
|
|
101
|
+
.gs-zoom-container .gs-zoom-img-list .gs-zoom-main-img .gs-zoom-img-touch {
|
|
102
|
+
position: absolute;
|
|
103
|
+
top: 0;
|
|
104
|
+
left: 0;
|
|
105
|
+
right: 0;
|
|
106
|
+
bottom: 0;
|
|
107
|
+
z-index: 2;
|
|
108
|
+
}
|
|
109
|
+
.gs-zoom-container .gs-zoom-img-list .gs-zoom-main-img .gz-zoom-loading-container {
|
|
110
|
+
display: none;
|
|
111
|
+
position: absolute;
|
|
112
|
+
top: 50%;
|
|
113
|
+
left: 50%;
|
|
114
|
+
transform: translate(-50%, -50%);
|
|
115
|
+
}
|
|
116
|
+
.gs-zoom-container .gs-zoom-img-list .gs-zoom-main-img .gs-zoom-img {
|
|
117
|
+
max-width: 100%;
|
|
118
|
+
max-height: 100%;
|
|
119
|
+
}
|
|
120
|
+
.gs-zoom-container .gs-zoom-img-list .gs-zoom-main-img .gs-zoom-img.gs-zoom-is-adjusting {
|
|
121
|
+
transition: 0.4s ease-in-out !important;
|
|
122
|
+
}
|
|
123
|
+
.gs-zoom-container .gs-zoom-img-list .gs-zoom-main-img.gz-zoom-is-loading .gz-zoom-loading-container {
|
|
124
|
+
display: block;
|
|
125
|
+
}
|
|
126
|
+
.gs-zoom-container .gs-zoom-img-list .gs-zoom-main-img.gz-zoom-is-loading .gs-zoom-img {
|
|
127
|
+
visibility: hidden;
|
|
128
|
+
}
|
|
129
|
+
.gs-zoom-container .gs-zoom-img-list .gs-zoom-main-img .gs-zoom-info-data {
|
|
130
|
+
position: absolute;
|
|
131
|
+
left: 0;
|
|
132
|
+
bottom: 0;
|
|
133
|
+
right: 0;
|
|
134
|
+
padding: 20px 20px 90px;
|
|
135
|
+
display: flex;
|
|
136
|
+
flex-direction: column;
|
|
137
|
+
align-items: center;
|
|
138
|
+
color: #fff;
|
|
139
|
+
background: linear-gradient(0deg, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0));
|
|
140
|
+
}
|
|
141
|
+
.gs-zoom-container .gs-zoom-additionals {
|
|
142
|
+
position: fixed;
|
|
143
|
+
bottom: 0;
|
|
144
|
+
left: 0;
|
|
145
|
+
width: 100%;
|
|
146
|
+
overflow-x: hidden;
|
|
147
|
+
padding: 5px 0;
|
|
148
|
+
display: flex;
|
|
149
|
+
justify-content: center;
|
|
150
|
+
background: linear-gradient(0deg, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0));
|
|
151
|
+
transform-origin: bottom;
|
|
152
|
+
}
|
|
153
|
+
.gs-zoom-container .gs-zoom-additionals .gs-add-list-container {
|
|
154
|
+
overflow-x: hidden;
|
|
155
|
+
max-width: 100%;
|
|
156
|
+
}
|
|
157
|
+
.gs-zoom-container .gs-zoom-additionals .gs-add-list-container .gs-add-list {
|
|
158
|
+
display: flex;
|
|
159
|
+
gap: 5px;
|
|
160
|
+
width: -moz-max-content;
|
|
161
|
+
width: max-content;
|
|
162
|
+
justify-content: center;
|
|
163
|
+
flex-wrap: nowrap;
|
|
164
|
+
}
|
|
165
|
+
.gs-zoom-container .gs-zoom-additionals .gs-add-list-container .gs-add-list .gs-add-item {
|
|
166
|
+
width: 80px;
|
|
167
|
+
aspect-ratio: 1;
|
|
168
|
+
display: flex;
|
|
169
|
+
align-items: center;
|
|
170
|
+
justify-content: center;
|
|
171
|
+
border: 1px solid #000;
|
|
172
|
+
opacity: 0.5;
|
|
173
|
+
transition: 0.2s ease-out;
|
|
174
|
+
transform: scale(0.8);
|
|
175
|
+
cursor: pointer;
|
|
176
|
+
}
|
|
177
|
+
.gs-zoom-container .gs-zoom-additionals .gs-add-list-container .gs-add-list .gs-add-item:hover, .gs-zoom-container .gs-zoom-additionals .gs-add-list-container .gs-add-list .gs-add-item.active {
|
|
178
|
+
transform: scale(1);
|
|
179
|
+
opacity: 1;
|
|
180
|
+
}
|
|
181
|
+
.gs-zoom-container .gs-zoom-additionals .gs-add-list-container .gs-add-list .gs-add-item img {
|
|
182
|
+
max-width: 100%;
|
|
183
|
+
max-height: 100%;
|
|
184
|
+
}
|
|
185
|
+
.gs-zoom-container .gs-zoom-additionals.gs-zoom-hidden {
|
|
186
|
+
z-index: 1;
|
|
187
|
+
opacity: 0;
|
|
188
|
+
}
|
|
189
|
+
.gs-zoom-container .gs-zoom-additionals.gs-zoom-hidden .gs-add-list {
|
|
190
|
+
transform: scale(0.9);
|
|
191
|
+
}
|
|
192
|
+
.gs-zoom-container:not(.gs-additional-isdragging) .gs-zoom-additionals .gs-add-list-container .gs-add-list {
|
|
193
|
+
transition: 0.3s transform ease-in-out;
|
|
194
|
+
}
|
|
195
|
+
.gs-zoom-container .gs-zoom-navigations button {
|
|
196
|
+
border: none;
|
|
197
|
+
position: fixed;
|
|
198
|
+
top: 50%;
|
|
199
|
+
width: 50px;
|
|
200
|
+
background-color: rgba(35, 35, 35, 0.65);
|
|
201
|
+
aspect-ratio: 1;
|
|
202
|
+
display: inline-flex;
|
|
203
|
+
align-items: center;
|
|
204
|
+
justify-content: center;
|
|
205
|
+
font-size: 28px;
|
|
206
|
+
color: #fff;
|
|
207
|
+
transform: translateY(-50%);
|
|
208
|
+
}
|
|
209
|
+
.gs-zoom-container .gs-zoom-navigations button svg {
|
|
210
|
+
fill: #fff;
|
|
211
|
+
width: 18px;
|
|
212
|
+
}
|
|
213
|
+
.gs-zoom-container .gs-zoom-navigations .gs-zoom-next {
|
|
214
|
+
right: 10px;
|
|
215
|
+
}
|
|
216
|
+
.gs-zoom-container .gs-zoom-navigations .gs-zoom-prev {
|
|
217
|
+
left: 10px;
|
|
218
|
+
}
|
|
219
|
+
.gs-zoom-container .gs-zoom-hide-inzoomed {
|
|
220
|
+
z-index: 3;
|
|
221
|
+
opacity: 1;
|
|
222
|
+
transform: scale(1);
|
|
223
|
+
transition: 0.3s ease-in-out;
|
|
224
|
+
}
|
|
225
|
+
.gs-zoom-container.gs-zoom-is-zoomed .gs-zoom-hide-inzoomed {
|
|
226
|
+
z-index: 1;
|
|
227
|
+
opacity: 0;
|
|
228
|
+
transform: scale(0.9);
|
|
229
|
+
}
|
|
230
|
+
.gs-zoom-container.gs-zoom-is-zoomed .gs-zoom-hide-inzoomed.gs-zoom-additionals {
|
|
231
|
+
transform: scale(1);
|
|
232
|
+
}
|
|
233
|
+
.gs-zoom-container.gs-zoom-is-zoomed .gs-zoom-hide-inzoomed.gs-zoom-additionals .gs-add-list {
|
|
234
|
+
transform: scale(0.9);
|
|
235
|
+
}/*# sourceMappingURL=GSZoom.css.map */
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import initClose from "./initClose";
|
|
2
|
+
|
|
3
|
+
export const getScale = (element) => {
|
|
4
|
+
// Get the computed style of the element
|
|
5
|
+
const style = window.getComputedStyle(element);
|
|
6
|
+
const transform = style.transform;
|
|
7
|
+
|
|
8
|
+
if (transform !== "none") {
|
|
9
|
+
const values = transform.match(/matrix.*\((.+)\)/)[1].split(", ");
|
|
10
|
+
return parseFloat(values[0]);
|
|
11
|
+
} else {
|
|
12
|
+
return 1;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const getTranslateCoord = (element) => {
|
|
17
|
+
const style = window.getComputedStyle(element);
|
|
18
|
+
// eslint-disable-next-line no-undef
|
|
19
|
+
const matrix = new WebKitCSSMatrix(style.transform);
|
|
20
|
+
return {
|
|
21
|
+
x: matrix.e,
|
|
22
|
+
y: matrix.f,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const fullscreenchange = () => {
|
|
27
|
+
if (!document.fullscreenElement) {
|
|
28
|
+
initClose();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const getAdjustTransform = (
|
|
2
|
+
scale,
|
|
3
|
+
translatex,
|
|
4
|
+
translatey,
|
|
5
|
+
$img,
|
|
6
|
+
$container
|
|
7
|
+
) => {
|
|
8
|
+
const actualWidth = $img.clientWidth * scale;
|
|
9
|
+
const actualHeight = $img.clientHeight * scale;
|
|
10
|
+
const containerWidth = $container.clientWidth;
|
|
11
|
+
const containerHeight = $container.clientHeight;
|
|
12
|
+
const maxTranslateXValue = (actualWidth - containerWidth) / 2;
|
|
13
|
+
const maxTranslateYValue = (actualHeight - containerHeight) / 2;
|
|
14
|
+
const minTranslateXValue = (containerWidth - actualWidth) / 2;
|
|
15
|
+
const minTranslateYValue = (containerHeight - actualHeight) / 2;
|
|
16
|
+
let newTranslateXValue = translatex / scale;
|
|
17
|
+
let newTranslateYValue = translatey / scale;
|
|
18
|
+
if (actualWidth <= containerWidth) {
|
|
19
|
+
if (translatex != 0) {
|
|
20
|
+
newTranslateXValue = 0;
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
if (translatex > maxTranslateXValue) {
|
|
24
|
+
newTranslateXValue = maxTranslateXValue / scale;
|
|
25
|
+
} else if (translatex < minTranslateXValue) {
|
|
26
|
+
newTranslateXValue = minTranslateXValue / scale;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (actualHeight <= containerHeight) {
|
|
30
|
+
if (translatex != 0) {
|
|
31
|
+
newTranslateYValue = 0;
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
if (translatey > maxTranslateYValue) {
|
|
35
|
+
newTranslateYValue = maxTranslateYValue / scale;
|
|
36
|
+
} else if (translatey < minTranslateYValue) {
|
|
37
|
+
newTranslateYValue = minTranslateYValue / scale;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return [newTranslateXValue, newTranslateYValue];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default getAdjustTransform;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import _defaultParams from '../constants/defaultParams';
|
|
2
|
+
import magnifierDefaultProps from '../constants/magnifierDefaultProps';
|
|
3
|
+
|
|
4
|
+
const getCurrentParams = (params) => {
|
|
5
|
+
const defaultParams = { ..._defaultParams };
|
|
6
|
+
let finalParams = {
|
|
7
|
+
...defaultParams,
|
|
8
|
+
...params,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
if (finalParams.responsive.length > 0) {
|
|
12
|
+
finalParams.responsive.sort((a, b) => b.windowSize - a.windowSize);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (finalParams.responsive.length > 0) {
|
|
16
|
+
const windowSize = window.innerWidth;
|
|
17
|
+
const availableResponsives = finalParams.responsive.filter(
|
|
18
|
+
(resp) => resp.windowSize >= windowSize
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
availableResponsives.map((resp) => {
|
|
22
|
+
finalParams = {
|
|
23
|
+
...finalParams,
|
|
24
|
+
...resp.params,
|
|
25
|
+
magnifier: {
|
|
26
|
+
...magnifierDefaultProps,
|
|
27
|
+
...resp.magnifier,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
return resp;
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
finalParams.magnifier = {
|
|
34
|
+
...magnifierDefaultProps,
|
|
35
|
+
...finalParams.magnifier,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return finalParams;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default getCurrentParams;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getTranslateCoord } from "./general";
|
|
2
|
+
|
|
3
|
+
const getTranslateCoordToPoint = (
|
|
4
|
+
$img,
|
|
5
|
+
$container,
|
|
6
|
+
scale,
|
|
7
|
+
newScale,
|
|
8
|
+
clientX,
|
|
9
|
+
clientY
|
|
10
|
+
) => {
|
|
11
|
+
const coords = getTranslateCoord($img);
|
|
12
|
+
const translatex = coords.x;
|
|
13
|
+
const translatey = coords.y;
|
|
14
|
+
let mouseDirectionY = 0;
|
|
15
|
+
let mouseDirectionX = 0;
|
|
16
|
+
const actualWidth = $img.clientWidth * scale;
|
|
17
|
+
const actualHeight = $img.clientHeight * scale;
|
|
18
|
+
const containerWidth = $container.clientWidth;
|
|
19
|
+
const containerHeight = $container.clientHeight;
|
|
20
|
+
|
|
21
|
+
mouseDirectionY =
|
|
22
|
+
(clientY - (containerHeight - actualHeight) / 2 - translatey) /
|
|
23
|
+
actualHeight;
|
|
24
|
+
|
|
25
|
+
mouseDirectionX =
|
|
26
|
+
(clientX - (containerWidth - actualWidth) / 2 - translatex) / actualWidth;
|
|
27
|
+
|
|
28
|
+
const newActualWidth = (actualWidth * newScale) / scale;
|
|
29
|
+
const newActualHeight = (actualHeight * newScale) / scale;
|
|
30
|
+
|
|
31
|
+
const newTranslatex =
|
|
32
|
+
(newActualWidth - containerWidth) / 2 -
|
|
33
|
+
(newActualWidth * mouseDirectionX - clientX);
|
|
34
|
+
const newTranslatey =
|
|
35
|
+
(newActualHeight - containerHeight) / 2 -
|
|
36
|
+
(newActualHeight * mouseDirectionY - clientY);
|
|
37
|
+
|
|
38
|
+
return [newTranslatex, newTranslatey];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default getTranslateCoordToPoint;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import types from "../constants/types";
|
|
2
|
+
import initLightBox from "./initLightBox";
|
|
3
|
+
import initMagnifier from "./initMagnifier";
|
|
4
|
+
|
|
5
|
+
const init = (ref) => {
|
|
6
|
+
if (typeof ref.currentParams.beforeInit === "function") {
|
|
7
|
+
ref.currentParams.beforeInit();
|
|
8
|
+
}
|
|
9
|
+
switch (ref.currentParams.type) {
|
|
10
|
+
case types.lightbox:
|
|
11
|
+
initLightBox(ref);
|
|
12
|
+
break;
|
|
13
|
+
case types.magnifier:
|
|
14
|
+
initMagnifier(ref);
|
|
15
|
+
}
|
|
16
|
+
if (typeof ref.currentParams.afterInit === "function") {
|
|
17
|
+
ref.currentParams.afterInit();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default init;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import icons from '../constants/icons';
|
|
2
|
+
import { initAutoplay, stopAutoplay } from './initAutoplay';
|
|
3
|
+
import { exitFullScreen } from './initFullScreen';
|
|
4
|
+
import setStyles from './setStyles';
|
|
5
|
+
|
|
6
|
+
const initActionEvents = (ref) => {
|
|
7
|
+
const params = ref.currentParams;
|
|
8
|
+
const $container = ref.$container;
|
|
9
|
+
const $btnAdditionals = ref.$btnAdditionals;
|
|
10
|
+
const $btnAutoplay = ref.$btnAutoplay;
|
|
11
|
+
const $btnClose = ref.$btnClose;
|
|
12
|
+
const $btnZoomIn = ref.$btnZoomIn;
|
|
13
|
+
const $btnZoomOut = ref.$btnZoomOut;
|
|
14
|
+
|
|
15
|
+
if ($btnAdditionals != null) {
|
|
16
|
+
$btnAdditionals.addEventListener('click', () => {
|
|
17
|
+
if (
|
|
18
|
+
$container
|
|
19
|
+
.querySelector('.gs-zoom-additionals')
|
|
20
|
+
.classList.contains('gs-zoom-hidden')
|
|
21
|
+
) {
|
|
22
|
+
$container
|
|
23
|
+
.querySelector('.gs-zoom-additionals')
|
|
24
|
+
.classList.remove('gs-zoom-hidden');
|
|
25
|
+
} else {
|
|
26
|
+
$container
|
|
27
|
+
.querySelector('.gs-zoom-additionals')
|
|
28
|
+
.classList.add('gs-zoom-hidden');
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if ($btnAutoplay != null) {
|
|
33
|
+
$btnAutoplay.addEventListener('click', () => {
|
|
34
|
+
if (ref.autoplay == undefined) {
|
|
35
|
+
initAutoplay(ref);
|
|
36
|
+
$btnAutoplay.innerHTML = icons.autoplayPause;
|
|
37
|
+
} else {
|
|
38
|
+
stopAutoplay(ref);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if ($btnClose != null) {
|
|
43
|
+
$btnClose.addEventListener('click', () => {
|
|
44
|
+
exitFullScreen();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if ($btnZoomIn != null) {
|
|
48
|
+
$btnZoomIn.addEventListener('click', () => {
|
|
49
|
+
const $img = ref.$img;
|
|
50
|
+
const scale =
|
|
51
|
+
$img.dataset.scale != undefined ? parseFloat($img.dataset.scale) : 1;
|
|
52
|
+
|
|
53
|
+
if (scale < params.maxZoom) {
|
|
54
|
+
clearTimeout(window.timeout);
|
|
55
|
+
const newScale = Math.min(scale + 0.4, params.maxZoom);
|
|
56
|
+
$img.dataset.scale = newScale;
|
|
57
|
+
setStyles(ref, $img, {
|
|
58
|
+
transition: '.3s ease-in-out',
|
|
59
|
+
transform: `scale(${newScale})`,
|
|
60
|
+
});
|
|
61
|
+
window.timeout = setTimeout(function () {
|
|
62
|
+
setStyles(ref, $img, {
|
|
63
|
+
transition: 'unset',
|
|
64
|
+
});
|
|
65
|
+
}, 300);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if ($btnZoomOut != null) {
|
|
70
|
+
$btnZoomOut.addEventListener('click', () => {
|
|
71
|
+
const $img = ref.$img;
|
|
72
|
+
const scale =
|
|
73
|
+
$img.dataset.scale != undefined ? parseFloat($img.dataset.scale) : 1;
|
|
74
|
+
|
|
75
|
+
if (scale > 1) {
|
|
76
|
+
clearTimeout(window.timeout);
|
|
77
|
+
const newScale = Math.max(1, scale - 0.4);
|
|
78
|
+
$img.dataset.scale = newScale;
|
|
79
|
+
setStyles(ref, $img, {
|
|
80
|
+
transition: '.3s ease-in-out',
|
|
81
|
+
transform: `scale(${newScale})`,
|
|
82
|
+
});
|
|
83
|
+
window.timeout = setTimeout(function () {
|
|
84
|
+
setStyles(ref, $img, {
|
|
85
|
+
transition: 'unset',
|
|
86
|
+
});
|
|
87
|
+
}, 300);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export default initActionEvents;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { getTranslateCoord } from "./general";
|
|
2
|
+
import initChange from "./initChange";
|
|
3
|
+
|
|
4
|
+
const initAdditionals = (ref) => {
|
|
5
|
+
const params = ref.currentParams;
|
|
6
|
+
|
|
7
|
+
if (params.showAdditionals && ref.list.length > 1) {
|
|
8
|
+
const $container = ref.$container;
|
|
9
|
+
const $mainImg = ref.$mainImg;
|
|
10
|
+
const $img = ref.$img;
|
|
11
|
+
const $addContainer = document.createElement("div");
|
|
12
|
+
const $addList = document.createElement("div");
|
|
13
|
+
const $addListContainer = document.createElement("div");
|
|
14
|
+
$addContainer.classList.add("gs-zoom-additionals");
|
|
15
|
+
$addContainer.classList.add("gs-zoom-hide-inzoomed");
|
|
16
|
+
$addContainer.classList.add("gs-zoom-hidden");
|
|
17
|
+
$addListContainer.classList.add("gs-add-list-container");
|
|
18
|
+
$addList.classList.add("gs-add-list");
|
|
19
|
+
$addList.style.transform = "translateX(0px)";
|
|
20
|
+
[...ref.list].map((el, index) => {
|
|
21
|
+
const $item = document.createElement("div");
|
|
22
|
+
$item.dataset.index = index;
|
|
23
|
+
if (index === ref.currentIndex) {
|
|
24
|
+
$item.classList.add("active");
|
|
25
|
+
}
|
|
26
|
+
const $itemImg = document.createElement("img");
|
|
27
|
+
$itemImg.src =
|
|
28
|
+
el.src.split("?")[0] + params.additionalImageQueryParameters;
|
|
29
|
+
$mainImg.classList.add("gz-zoom-is-loading");
|
|
30
|
+
$img.onload = () => {
|
|
31
|
+
$mainImg.classList.remove("gz-zoom-is-loading");
|
|
32
|
+
};
|
|
33
|
+
$item.classList.add("gs-add-item");
|
|
34
|
+
$item.append($itemImg);
|
|
35
|
+
$addList.append($item);
|
|
36
|
+
$item.addEventListener("click", () => {
|
|
37
|
+
ref.currentIndex = index;
|
|
38
|
+
initChange(ref, index);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
$addListContainer.append($addList);
|
|
42
|
+
$addContainer.append($addListContainer);
|
|
43
|
+
$container.append($addContainer);
|
|
44
|
+
|
|
45
|
+
$addList.ontouchstart = $addList.onmousedown = (e) => {
|
|
46
|
+
if ($addList.clientWidth > $container.clientWidth) {
|
|
47
|
+
window.initX =
|
|
48
|
+
e.targetTouches != null && e.targetTouches.length > 0
|
|
49
|
+
? e.targetTouches[0].clientX
|
|
50
|
+
: e.clientX;
|
|
51
|
+
window.initTranslateX = getTranslateCoord($addList).x;
|
|
52
|
+
$container.classList.add("gs-additional-isdragging");
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
$container.addEventListener("touchmove", (e) => {
|
|
56
|
+
if ($container.classList.contains("gs-additional-isdragging")) {
|
|
57
|
+
window.clientX = e.targetTouches[0].clientX;
|
|
58
|
+
const movedX = window.clientX - window.initX;
|
|
59
|
+
$addList.style.transform = `translateX(${
|
|
60
|
+
window.initTranslateX + movedX
|
|
61
|
+
}px)`;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
$container.addEventListener("mousemove", (e) => {
|
|
65
|
+
if (
|
|
66
|
+
$container.classList.contains("gs-additional-isdragging") &&
|
|
67
|
+
$addList.clientWidth > $container.clientWidth
|
|
68
|
+
) {
|
|
69
|
+
window.clientX = e.clientX;
|
|
70
|
+
const movedX = window.clientX - window.initX;
|
|
71
|
+
$addList.style.transform = `translateX(${
|
|
72
|
+
window.initTranslateX + movedX
|
|
73
|
+
}px)`;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
$container.addEventListener("mouseleave", (e) => {
|
|
77
|
+
if ($container.classList.contains("gs-additional-isdragging")) {
|
|
78
|
+
$container.classList.remove("gs-additional-isdragging");
|
|
79
|
+
const translate = getTranslateCoord($addList).x;
|
|
80
|
+
if (translate > 0) {
|
|
81
|
+
$addList.style.transform = `translateX(0px)`;
|
|
82
|
+
} else if (translate < $container.clientWidth - $addList.clientWidth) {
|
|
83
|
+
$addList.style.transform = `translateX(${
|
|
84
|
+
$container.clientWidth - $addList.clientWidth
|
|
85
|
+
}px)`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
$container.addEventListener("mouseup", (e) => {
|
|
90
|
+
if ($container.classList.contains("gs-additional-isdragging")) {
|
|
91
|
+
$container.classList.remove("gs-additional-isdragging");
|
|
92
|
+
const translate = getTranslateCoord($addList).x;
|
|
93
|
+
if (translate > 0) {
|
|
94
|
+
$addList.style.transform = `translateX(0px)`;
|
|
95
|
+
} else if (translate < $container.clientWidth - $addList.clientWidth) {
|
|
96
|
+
$addList.style.transform = `translateX(${
|
|
97
|
+
$container.clientWidth - $addList.clientWidth
|
|
98
|
+
}px)`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
$container.addEventListener("touchend", (e) => {
|
|
103
|
+
if ($container.classList.contains("gs-additional-isdragging")) {
|
|
104
|
+
$container.classList.remove("gs-additional-isdragging");
|
|
105
|
+
const translate = getTranslateCoord($addList).x;
|
|
106
|
+
if (translate > 0) {
|
|
107
|
+
$addList.style.transform = `translateX(0px)`;
|
|
108
|
+
} else if (translate < $container.clientWidth - $addList.clientWidth) {
|
|
109
|
+
$addList.style.transform = `translateX(${
|
|
110
|
+
$container.clientWidth - $addList.clientWidth
|
|
111
|
+
}px)`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export default initAdditionals;
|