@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.
Files changed (35) hide show
  1. package/README.md +46 -0
  2. package/dist/GSZoom.css +235 -0
  3. package/dist/actions/general.js +30 -0
  4. package/dist/actions/getAdjustTransform.js +43 -0
  5. package/dist/actions/getCurrentParams.js +42 -0
  6. package/dist/actions/getTranslateCoordToPoint.js +41 -0
  7. package/dist/actions/init.js +21 -0
  8. package/dist/actions/initActionEvents.js +93 -0
  9. package/dist/actions/initAdditionals.js +118 -0
  10. package/dist/actions/initAdjust.js +107 -0
  11. package/dist/actions/initAdjustAdditionalActive.js +33 -0
  12. package/dist/actions/initArrows.js +44 -0
  13. package/dist/actions/initAutoplay.js +81 -0
  14. package/dist/actions/initChange.js +73 -0
  15. package/dist/actions/initClose.js +28 -0
  16. package/dist/actions/initDraggle.js +303 -0
  17. package/dist/actions/initDraw.js +79 -0
  18. package/dist/actions/initDrawItem.js +83 -0
  19. package/dist/actions/initFullScreen.js +32 -0
  20. package/dist/actions/initLightBox.js +33 -0
  21. package/dist/actions/initMagnifier.js +54 -0
  22. package/dist/actions/initNavigateWithKeys.js +27 -0
  23. package/dist/actions/initWheel.js +51 -0
  24. package/dist/actions/setStyles.js +24 -0
  25. package/dist/components/GSZoom.js +115 -0
  26. package/dist/components/styles/GSZoom.css +235 -0
  27. package/dist/components/styles/GSZoom.css.map +1 -0
  28. package/dist/components/styles/GSZoom.scss +254 -0
  29. package/dist/constants/defaultParams.js +20 -0
  30. package/dist/constants/icons.js +23 -0
  31. package/dist/constants/magnifierDefaultProps.js +7 -0
  32. package/dist/constants/types.js +6 -0
  33. package/dist/helpers/uihelpers.js +9 -0
  34. package/index.js +3 -0
  35. package/package.json +43 -0
@@ -0,0 +1,107 @@
1
+ import { getTranslateCoord } from './general';
2
+ import getAdjustTransform from './getAdjustTransform';
3
+ import getTranslateCoordToPoint from './getTranslateCoordToPoint';
4
+ import setStyles from './setStyles';
5
+
6
+ const initAdjust = (ref, $container, $img, withAnimation = true) => {
7
+ if ($img.classList.contains('gs-zoom-isdragging') || !withAnimation) {
8
+ const params = ref.currentParams;
9
+ let needAdjust = false;
10
+ if (withAnimation) {
11
+ $img.classList.remove('gs-zoom-isdragging');
12
+ }
13
+
14
+ let scale = $img.dataset.scale != null ? parseFloat($img.dataset.scale) : 1;
15
+ let isOverzoomed = false;
16
+ const oldScale = scale;
17
+
18
+ if (scale < 1) {
19
+ scale = 1;
20
+ needAdjust = true;
21
+ } else if (scale > params.maxZoom) {
22
+ isOverzoomed = true;
23
+ scale = params.maxZoom;
24
+ needAdjust = true;
25
+ }
26
+ $img.dataset.scale = scale;
27
+ const actualWidth = $img.clientWidth * scale;
28
+ const actualHeight = $img.clientHeight * scale;
29
+ const containerWidth = $container.clientWidth;
30
+ const containerHeight = $container.clientHeight;
31
+ const coords = getTranslateCoord($img);
32
+ const translatex = coords.x;
33
+ const translatey = coords.y;
34
+ const maxTranslateXValue = (actualWidth - containerWidth) / 2;
35
+ const maxTranslateYValue = (actualHeight - containerHeight) / 2;
36
+ const minTranslateXValue = (containerWidth - actualWidth) / 2;
37
+ const minTranslateYValue = (containerHeight - actualHeight) / 2;
38
+ let newTranslateXValue = translatex / scale;
39
+ let newTranslateYValue = translatey / scale;
40
+ if (actualWidth <= containerWidth) {
41
+ if (translatex != 0) {
42
+ needAdjust = true;
43
+ newTranslateXValue = 0;
44
+ }
45
+ } else {
46
+ if (translatex > maxTranslateXValue) {
47
+ needAdjust = true;
48
+ newTranslateXValue = maxTranslateXValue / scale;
49
+ } else if (translatex < minTranslateXValue) {
50
+ needAdjust = true;
51
+ newTranslateXValue = minTranslateXValue / scale;
52
+ }
53
+ }
54
+ if (actualHeight <= containerHeight) {
55
+ if (translatex != 0) {
56
+ needAdjust = true;
57
+ newTranslateYValue = 0;
58
+ }
59
+ } else {
60
+ if (translatey > maxTranslateYValue) {
61
+ needAdjust = true;
62
+ newTranslateYValue = maxTranslateYValue / scale;
63
+ } else if (translatey < minTranslateYValue) {
64
+ needAdjust = true;
65
+ newTranslateYValue = minTranslateYValue / scale;
66
+ }
67
+ }
68
+ if (isOverzoomed) {
69
+ const clientCenterX = (window.clientX + window.clientX2) / 2;
70
+ const clientCenterY = (window.clientY + window.clientY2) / 2;
71
+ let [newTranslatex, newTranslatey] = getTranslateCoordToPoint(
72
+ $img,
73
+ $container,
74
+ oldScale,
75
+ scale,
76
+ clientCenterX,
77
+ clientCenterY
78
+ );
79
+ [newTranslatex, newTranslatey] = getAdjustTransform(
80
+ scale,
81
+ newTranslatex,
82
+ newTranslatey,
83
+ $img,
84
+ $container
85
+ );
86
+ newTranslateXValue = newTranslatex;
87
+ newTranslateYValue = newTranslatey;
88
+ }
89
+ if (needAdjust) {
90
+ if (withAnimation) {
91
+ $img.classList.add('gs-zoom-is-adjusting');
92
+ }
93
+ setStyles(ref, $img, {
94
+ transform: `scale(${scale}) translate(${newTranslateXValue}px, ${newTranslateYValue}px)`,
95
+ });
96
+ $img.dataset.translatex = newTranslateXValue * scale;
97
+ $img.dataset.translatey = newTranslateYValue * scale;
98
+ if (withAnimation) {
99
+ setTimeout(function () {
100
+ $img.classList.remove('gs-zoom-is-adjusting');
101
+ }, 400);
102
+ }
103
+ }
104
+ }
105
+ };
106
+
107
+ export default initAdjust;
@@ -0,0 +1,33 @@
1
+ import { getTranslateCoord } from "./general";
2
+
3
+ const initAdjustAdditionalActive = (ref) => {
4
+ if (ref.currentParams.showAdditionals && ref.list.length > 1) {
5
+ const $container = ref.$container;
6
+ const $active = $container.querySelector(
7
+ `.gs-add-list .gs-add-item.active`
8
+ );
9
+ if ($active != null) {
10
+ const $list = $container.querySelector(".gs-add-list");
11
+ const tranlateLeft = getTranslateCoord($list).x;
12
+ const offsetLeft = $active.offsetLeft;
13
+ const containerWidth = $container.clientWidth;
14
+ const itemWidth = $active.clientWidth;
15
+ const listWidth = $list.clientWidth;
16
+ const offsetContainer = offsetLeft + tranlateLeft;
17
+ const gap = parseFloat(getComputedStyle($list).columnGap);
18
+ if (offsetContainer < itemWidth + gap) {
19
+ $list.style.transform = `translateX(${Math.min(
20
+ itemWidth + gap - offsetLeft,
21
+ 0
22
+ )}px)`;
23
+ } else if (offsetContainer > containerWidth - (2 * itemWidth + gap)) {
24
+ $list.style.transform = `translateX(${Math.max(
25
+ containerWidth - offsetLeft - 2 * itemWidth - gap,
26
+ containerWidth - listWidth
27
+ )}px)`;
28
+ }
29
+ }
30
+ }
31
+ };
32
+
33
+ export default initAdjustAdditionalActive;
@@ -0,0 +1,44 @@
1
+ import icons from "../constants/icons";
2
+ import initChange from "./initChange";
3
+
4
+ const initArrows = (ref) => {
5
+ const params = ref.currentParams;
6
+ const $container = ref.$container;
7
+
8
+ if (params.arrows && ref.list.length > 1) {
9
+ const $btnNavigations = document.createElement("div");
10
+ const $btnNext = document.createElement("button");
11
+ const $btnPrev = document.createElement("button");
12
+ $btnPrev.innerHTML = icons.arrPrev;
13
+ $btnNext.innerHTML = icons.arrNext;
14
+ $btnNavigations.classList.add("gs-zoom-navigations");
15
+ $btnNext.classList.add("gs-zoom-next");
16
+ $btnNext.classList.add("gs-zoom-hide-inzoomed");
17
+ $btnPrev.classList.add("gs-zoom-prev");
18
+ $btnPrev.classList.add("gs-zoom-hide-inzoomed");
19
+ $btnNavigations.append($btnPrev);
20
+ $btnNavigations.append($btnNext);
21
+ $container.append($btnNavigations);
22
+
23
+ $btnNext.addEventListener("click", () => {
24
+ let newIndex = 0;
25
+ if (ref.currentIndex < ref.list.length - 1) {
26
+ newIndex = ref.currentIndex + 1;
27
+ } else {
28
+ newIndex = 0;
29
+ }
30
+ initChange(ref, newIndex);
31
+ });
32
+ $btnPrev.addEventListener("click", () => {
33
+ let newIndex = 0;
34
+ if (ref.currentIndex == 0) {
35
+ newIndex = ref.list.length - 1;
36
+ } else {
37
+ newIndex = ref.currentIndex - 1;
38
+ }
39
+ initChange(ref, newIndex);
40
+ });
41
+ }
42
+ };
43
+
44
+ export default initArrows;
@@ -0,0 +1,81 @@
1
+ import icons from "../constants/icons";
2
+ import initChange from "./initChange";
3
+
4
+ export const initAutoplay = (ref) => {
5
+ const $container = ref.$container;
6
+ const params = ref.currentParams;
7
+ const $autoplayLine = document.createElement("div");
8
+ if ($container.querySelector(".gs-zoom-autoplayline") != null) {
9
+ $container.querySelector(".gs-zoom-autoplayline").remove();
10
+ }
11
+ setTimeout(() => {
12
+ $autoplayLine.classList.add("gs-zoom-autoplayline");
13
+ $container.prepend($autoplayLine);
14
+ $autoplayLine.style.width = "0px";
15
+ setTimeout(() => {
16
+ $autoplayLine.style.transition = `${params.autoplaySpeed}ms all linear`;
17
+ $autoplayLine.style.width = "100vw";
18
+ clearTimeout(ref.autoplay);
19
+ ref.autoplay = setTimeout(() => {
20
+ if ($container.querySelector(".gs-zoom-autoplayline") != null) {
21
+ $container.querySelector(".gs-zoom-autoplayline").remove();
22
+ }
23
+ if (ref.currentIndex == [...ref.list].length - 1) {
24
+ initChange(ref, 0, true);
25
+ } else {
26
+ initChange(ref, ref.currentIndex + 1, true);
27
+ }
28
+ }, params.autoplaySpeed - 100);
29
+ }, 100);
30
+ }, 0);
31
+ };
32
+
33
+ export const pauseAutoplay = (ref) => {
34
+ if (ref.autoplay != undefined) {
35
+ const $container = ref.$container;
36
+ const $loader = $container.querySelector(".gs-zoom-autoplayline");
37
+ const loaded = $loader.clientWidth;
38
+ const all = $container.clientWidth;
39
+ const loadedPercent = loaded / all;
40
+ $loader.transition = "unset";
41
+ $loader.style.width = loaded + "px";
42
+ $loader.dataset.loaded = loadedPercent;
43
+ clearTimeout(ref.autoplay);
44
+ ref.autoplay = undefined;
45
+ ref.autoplayStoped = true;
46
+ }
47
+ };
48
+
49
+ export const resumeAutoplay = (ref) => {
50
+ if (ref.autoplayStoped) {
51
+ ref.autoplayStoped = false;
52
+ const params = ref.currentParams;
53
+ const $container = ref.$container;
54
+ const $loader = $container.querySelector(".gs-zoom-autoplayline");
55
+ if ($loader != null) {
56
+ const loaded = +$loader.dataset.loaded;
57
+ const timeLeft = params.autoplaySpeed * (1 - loaded);
58
+ $loader.style.transition = `${timeLeft}ms all linear`;
59
+ $loader.style.width = "100vw";
60
+ clearTimeout(ref.autoplay);
61
+ ref.autoplay = setTimeout(() => {
62
+ if (ref.currentIndex == [...ref.list].length - 1) {
63
+ initChange(ref, 0, true);
64
+ } else {
65
+ initChange(ref, ref.currentIndex + 1, true);
66
+ }
67
+ }, timeLeft);
68
+ }
69
+ }
70
+ };
71
+
72
+ export const stopAutoplay = (ref) => {
73
+ const $container = ref.$container;
74
+ $container.querySelector(".gs-zoom-btn-autoplay").innerHTML = icons.autoplay;
75
+ if ($container.querySelector(".gs-zoom-autoplayline") != null) {
76
+ $container.querySelector(".gs-zoom-autoplayline").remove();
77
+ clearTimeout(ref.autoplay);
78
+ ref.autoplay = undefined;
79
+ ref.autoplayStoped = false;
80
+ }
81
+ };
@@ -0,0 +1,73 @@
1
+ import initAdjustAdditionalActive from "./initAdjustAdditionalActive";
2
+ import { initAutoplay, stopAutoplay } from "./initAutoplay";
3
+ import initDraggle from "./initDraggle";
4
+ import initDrawItem from "./initDrawItem";
5
+ import initWheel from "./initWheel";
6
+ import setStyles from "./setStyles";
7
+
8
+ const initChange = (ref, index, isAutoplay = false) => {
9
+ if (!ref.inProcess) {
10
+ ref.inProcess = true;
11
+ const params = ref.currentParams;
12
+ const $img = ref.$img;
13
+ const $container = ref.$container;
14
+ const $imgList = ref.$imgList;
15
+ $img.dataset.scale = 1;
16
+ $img.dataset.translatex = 0;
17
+ $img.dataset.translatey = 0;
18
+
19
+ $container.classList.remove("gs-zoom-is-zoomed");
20
+ $imgList.style.transition = ".3s ease-in-out";
21
+ $imgList.style.transform = `translateX(-${
22
+ $container.clientWidth * index
23
+ }px)`;
24
+
25
+ if (params.showAdditionals && ref.list.length > 1) {
26
+ const $active = $container.querySelector(
27
+ ".gs-zoom-additionals .gs-add-list .gs-add-item.active"
28
+ );
29
+ if ($active != null) {
30
+ $active.classList.remove("active");
31
+ }
32
+ $container
33
+ .querySelector(
34
+ `.gs-zoom-additionals .gs-add-list .gs-add-item[data-index='${index}']`
35
+ )
36
+ .classList.add("active");
37
+ }
38
+ initAdjustAdditionalActive(ref);
39
+ setTimeout(() => {
40
+ ref.isZoomed = false;
41
+ $imgList.style.transition = "unset";
42
+ setStyles(ref, $img, {
43
+ transform: "scale(1) translate(0, 0)",
44
+ });
45
+ ref.$mainImg = [...$imgList.querySelectorAll(".gs-zoom-main-img")][index];
46
+ ref.$imgTouch = ref.$mainImg.querySelector(".gs-zoom-img-touch");
47
+ ref.$img = ref.$mainImg.querySelector(".gs-zoom-img");
48
+ ref.currentIndex = index;
49
+ [...$imgList.querySelectorAll(".gs-zoom-main-img")].map((item, i) => {
50
+ if (i <= index + 1 && i >= index - 1) {
51
+ initDrawItem(ref, i);
52
+ } else {
53
+ item.innerHTML = "";
54
+ }
55
+ });
56
+ ref.inProcess = false;
57
+ if (typeof params.afterChange === "function") {
58
+ params.afterChange();
59
+ }
60
+
61
+ initDraggle(ref, index);
62
+ }, 300);
63
+ $imgList.classList.remove("gs-zoom-listisdragging");
64
+
65
+ if (isAutoplay) {
66
+ initAutoplay(ref);
67
+ } else {
68
+ stopAutoplay(ref);
69
+ }
70
+ }
71
+ };
72
+
73
+ export default initChange;
@@ -0,0 +1,28 @@
1
+ import { stopAutoplay } from "./initAutoplay";
2
+
3
+ const initClose = () => {
4
+ const ref =
5
+ window.GSZoomConfigue.openedZoom !== undefined
6
+ ? window.GSZoomConfigue.references.find(
7
+ (x) => x.key === window.GSZoomConfigue.openedZoom
8
+ ).ref
9
+ : null;
10
+ if (ref != null) {
11
+ if (typeof ref.currentParams.beforeLightBoxClose === "function") {
12
+ ref.currentParams.beforeLightBoxClose();
13
+ }
14
+ document.onkeyup = null;
15
+ ref.$container.remove();
16
+ if (ref.autoplay != undefined) {
17
+ clearTimeout(ref.autoplay);
18
+ stopAutoplay(ref);
19
+ }
20
+ document.querySelector("html").classList.remove("gs-zoom-opened");
21
+ if (typeof ref.currentParams.afterLightBoxClose === "function") {
22
+ ref.currentParams.afterLightBoxClose();
23
+ }
24
+ window.GSZoomConfigue.openedZoom = undefined;
25
+ }
26
+ };
27
+
28
+ export default initClose;
@@ -0,0 +1,303 @@
1
+ import { getTranslateCoord } from "./general";
2
+ import getAdjustTransform from "./getAdjustTransform";
3
+ import getTranslateCoordToPoint from "./getTranslateCoordToPoint";
4
+ import initAdjust from "./initAdjust";
5
+ import { pauseAutoplay, resumeAutoplay } from "./initAutoplay";
6
+ import initChange from "./initChange";
7
+ import setStyles from "./setStyles";
8
+
9
+ const initDraggle = (ref, index) => {
10
+ const params = ref.currentParams;
11
+ const $container = ref.$container;
12
+ const $imgList = ref.$imgList;
13
+
14
+ [
15
+ ...ref.$imgList.querySelectorAll(
16
+ `.gs-zoom-main-img:not([data-index='${index}']) .gs-zoom-img-touch`
17
+ ),
18
+ ].map(($touch) => {
19
+ $touch.onclick = null;
20
+ $touch.ontouchstart = null;
21
+ $touch.onmousedown = null;
22
+ $touch.ontouchmove = null;
23
+ $touch.onmousemove = null;
24
+ $touch.onmouseleave = null;
25
+ $touch.onmouseup = null;
26
+ $touch.ontouchend = null;
27
+ });
28
+ const item = ref.$imgList.querySelector(
29
+ `.gs-zoom-main-img[data-index='${index}']`
30
+ );
31
+ if (item != null) {
32
+ const $imgTouch = item.querySelector(".gs-zoom-img-touch");
33
+ const $img = item.querySelector(".gs-zoom-img");
34
+
35
+ $imgTouch.onclick = (e) => {
36
+ const timeNow = new Date().getTime();
37
+ const timeDifference = timeNow - window.lastClickTime;
38
+ if (timeDifference < 300) {
39
+ const scale =
40
+ $img.dataset.scale != undefined ? parseFloat($img.dataset.scale) : 1;
41
+ let newScale = 1;
42
+ if (scale < params.maxZoom) {
43
+ newScale = params.maxZoom;
44
+ }
45
+ const clientX =
46
+ e.targetTouches !== null &&
47
+ typeof e.targetTouches !== "undefined" &&
48
+ e.targetTouches.length > 0
49
+ ? e.targetTouches[0].clientX
50
+ : e.clientX;
51
+ const clientY =
52
+ e.targetTouches !== null &&
53
+ typeof e.targetTouches !== "undefined" &&
54
+ e.targetTouches.length > 0
55
+ ? e.targetTouches[0].clientY
56
+ : e.clientY;
57
+
58
+ let [newTranslatex, newTranslatey] = getTranslateCoordToPoint(
59
+ $img,
60
+ $container,
61
+ scale,
62
+ newScale,
63
+ clientX,
64
+ clientY
65
+ );
66
+ [newTranslatex, newTranslatey] = getAdjustTransform(
67
+ newScale,
68
+ newTranslatex,
69
+ newTranslatey,
70
+ $img,
71
+ $container
72
+ );
73
+ const transform = `scale(${newScale}) translate(${newTranslatex}px, ${newTranslatey}px)`;
74
+ $img.dataset.scale = newScale;
75
+ setStyles(ref, $img, {
76
+ transition: "4s ease-in-out",
77
+ transform: transform,
78
+ });
79
+ $img.classList.add("gs-zoom-is-adjusting");
80
+ setTimeout(() => {
81
+ $img.classList.remove("gs-zoom-is-adjusting");
82
+ setStyles(ref, $img, {
83
+ transition: "unset",
84
+ });
85
+ }, 400);
86
+ }
87
+ window.lastClickTime = timeNow;
88
+ };
89
+ $imgTouch.ontouchstart = (e) => {
90
+ pauseAutoplay(ref);
91
+ if (e.targetTouches.length > 1) {
92
+ document
93
+ .querySelector("html")
94
+ .classList.add("gs-disable-apple-touchzoom");
95
+ }
96
+ if (!ref.isZoomed && e.targetTouches.length == 1) {
97
+ const coords = getTranslateCoord($imgList);
98
+ window.initListX = e.targetTouches[0].clientX;
99
+ window.initListY = e.targetTouches[0].clientY;
100
+ window.initListTranslateX = parseFloat(coords.x);
101
+ window.initListTranslateY = parseFloat(coords.y);
102
+ $imgList.classList.add("gs-zoom-listisdragging");
103
+ } else {
104
+ if (!$img.classList.contains("gs-zoom-is-adjusting")) {
105
+ const coords = getTranslateCoord($img);
106
+ $img.dataset.translatex = coords.x;
107
+ $img.dataset.translatey = coords.y;
108
+ window.initX = e.targetTouches[0].clientX;
109
+ window.initY = e.targetTouches[0].clientY;
110
+ if (e.targetTouches.length > 1) {
111
+ window.initX2 = e.targetTouches[1].clientX;
112
+ window.initY2 = e.targetTouches[1].clientY;
113
+ window.touchDistance = Math.sqrt(
114
+ Math.pow(window.initX2 - window.initX, 2) +
115
+ Math.pow(window.initY2 - window.initY, 2)
116
+ );
117
+ window.initCenterX = (window.initX2 + window.initX) / 2;
118
+ window.initCenterY = (window.initY2 + window.initY) / 2;
119
+ }
120
+ window.initTranslateX = parseFloat($img.dataset.translatex);
121
+ window.initTranslateY = parseFloat($img.dataset.translatey);
122
+ $img.classList.add("gs-zoom-isdragging");
123
+ }
124
+ }
125
+ };
126
+ $imgTouch.onmousedown = (e) => {
127
+ pauseAutoplay(ref);
128
+ if (!ref.isZoomed) {
129
+ const coords = getTranslateCoord($imgList);
130
+ window.initListX = e.clientX;
131
+ window.initListTranslateX = parseFloat(coords.x);
132
+ window.initListY = e.clientY;
133
+ window.initListTranslateY = parseFloat(coords.y);
134
+ $imgList.classList.add("gs-zoom-listisdragging");
135
+ } else {
136
+ if (!$img.classList.contains("gs-zoom-is-adjusting")) {
137
+ const coords = getTranslateCoord($img);
138
+ $img.dataset.translatex = coords.x;
139
+ $img.dataset.translatey = coords.y;
140
+ window.initX = e.clientX;
141
+ window.initTranslateX = parseFloat($img.dataset.translatex);
142
+ window.initY = e.clientY;
143
+ window.initTranslateY = parseFloat($img.dataset.translatey);
144
+ $img.classList.add("gs-zoom-isdragging");
145
+ }
146
+ }
147
+ };
148
+ $imgTouch.ontouchmove = (e) => {
149
+ const towTouchPoints = e.targetTouches.length > 1;
150
+ window.clientX = e.targetTouches[0].clientX;
151
+ window.clientY = e.targetTouches[0].clientY;
152
+ if (towTouchPoints) {
153
+ window.clientX2 = e.targetTouches[1].clientX;
154
+ window.clientY2 = e.targetTouches[1].clientY;
155
+ }
156
+ if (!ref.isZoomed && !towTouchPoints) {
157
+ ref.listMoved = true;
158
+ if ($imgList.classList.contains("gs-zoom-listisdragging")) {
159
+ const movedX = window.clientX - window.initListX;
160
+ const newTranslateX = window.initListTranslateX + movedX;
161
+ $imgList.style.transform = `translateX(${newTranslateX}px)`;
162
+ $imgList.dataset.moved = movedX;
163
+ }
164
+ } else if (
165
+ $imgList.dataset.moved === undefined ||
166
+ $imgList.dataset.moved == 0
167
+ ) {
168
+ if ($img.classList.contains("gs-zoom-isdragging")) {
169
+ if (towTouchPoints) {
170
+ const clientCenterX = (window.clientX + window.clientX2) / 2;
171
+ const clientCenterY = (window.clientY + window.clientY2) / 2;
172
+ let scale =
173
+ $img.dataset.scale != undefined
174
+ ? parseFloat($img.dataset.scale)
175
+ : 1;
176
+ let oldScale =
177
+ $img.dataset.tempscale != undefined
178
+ ? parseFloat($img.dataset.tempscale)
179
+ : scale;
180
+ const currentDistance = Math.sqrt(
181
+ Math.pow(window.clientX - window.clientX2, 2) +
182
+ Math.pow(window.clientY - window.clientY2, 2)
183
+ );
184
+ scale = (scale * currentDistance) / window.touchDistance;
185
+
186
+ if (scale < 1) {
187
+ scale = 1;
188
+ }
189
+ $img.dataset.tempscale = scale;
190
+
191
+ let [newTranslatex, newTranslatey] = getTranslateCoordToPoint(
192
+ $img,
193
+ $container,
194
+ oldScale,
195
+ scale,
196
+ window.initCenterX,
197
+ window.initCenterY
198
+ );
199
+ const movedX = clientCenterX - window.initCenterX;
200
+ const movedY = clientCenterY - window.initCenterY;
201
+ window.initCenterX = clientCenterX;
202
+ window.initCenterY = clientCenterY;
203
+ $img.dataset.translatex = newTranslatex + movedX;
204
+ $img.dataset.translatey = newTranslatey + movedY;
205
+ const transform = `scale(${scale}) translate(${
206
+ (newTranslatex + movedX) / scale
207
+ }px, ${(newTranslatey + movedY) / scale}px)`;
208
+ setStyles(ref, $img, {
209
+ transform: transform,
210
+ });
211
+ } else {
212
+ const movedY = window.clientY - window.initY;
213
+ const movedX = window.clientX - window.initX;
214
+ $img.dataset.translatex = window.initTranslateX + movedX;
215
+ $img.dataset.translatey = window.initTranslateY + movedY;
216
+ let scale =
217
+ $img.dataset.scale != undefined
218
+ ? parseFloat($img.dataset.scale)
219
+ : 1;
220
+
221
+ const transform = `scale(${scale}) translate(${
222
+ (window.initTranslateX + movedX) / scale
223
+ }px, ${(window.initTranslateY + movedY) / scale}px)`;
224
+ setStyles(ref, $img, {
225
+ transform: transform,
226
+ });
227
+ }
228
+ }
229
+ }
230
+ };
231
+ $imgTouch.onmousemove = (e) => {
232
+ window.clientX = e.clientX;
233
+ window.clientY = e.clientY;
234
+ if (!ref.isZoomed) {
235
+ ref.listMoved = true;
236
+ if ($imgList.classList.contains("gs-zoom-listisdragging")) {
237
+ const movedX = window.clientX - window.initListX;
238
+ const newTranslateX = window.initListTranslateX + movedX;
239
+ $imgList.style.transform = `translateX(${newTranslateX}px)`;
240
+ $imgList.dataset.moved = movedX;
241
+ }
242
+ } else if (
243
+ $imgList.dataset.moved === undefined ||
244
+ $imgList.dataset.moved == 0
245
+ ) {
246
+ if ($img.classList.contains("gs-zoom-isdragging")) {
247
+ const movedY = clientY - window.initY;
248
+ const movedX = clientX - window.initX;
249
+ $img.dataset.translatex = window.initTranslateX + movedX;
250
+ $img.dataset.translatey = window.initTranslateY + movedY;
251
+ let scale =
252
+ $img.dataset.scale != undefined
253
+ ? parseFloat($img.dataset.scale)
254
+ : 1;
255
+
256
+ const transform = `scale(${scale}) translate(${
257
+ (initTranslateX + movedX) / scale
258
+ }px, ${(initTranslateY + movedY) / scale}px)`;
259
+ setStyles(ref, $img, {
260
+ transform: transform,
261
+ });
262
+ }
263
+ }
264
+ };
265
+ $imgTouch.onmouseleave =
266
+ $imgTouch.onmouseup =
267
+ $imgTouch.ontouchend =
268
+ () => {
269
+ if (
270
+ $img.classList.contains("gs-zoom-isdragging") &&
271
+ ($imgList.dataset.moved === undefined ||
272
+ $imgList.dataset.moved == 0)
273
+ ) {
274
+ if ($img.dataset.tempscale != undefined) {
275
+ $img.dataset.scale = $img.dataset.tempscale;
276
+ $img.removeAttribute("data-tempscale");
277
+ }
278
+
279
+ initAdjust(ref, $container, $img);
280
+ resumeAutoplay(ref);
281
+ $imgList.classList.remove("gs-zoom-listisdragging");
282
+ } else if ($imgList.classList.contains("gs-zoom-listisdragging")) {
283
+ $imgList.classList.remove("gs-zoom-listisdragging");
284
+ if (+$imgList.dataset.moved < 0) {
285
+ initChange(
286
+ ref,
287
+ Math.min(ref.currentIndex + 1, ref.list.length - 1)
288
+ );
289
+ } else if (+$imgList.dataset.moved > 0) {
290
+ initChange(ref, Math.max(ref.currentIndex - 1, 0));
291
+ } else {
292
+ resumeAutoplay(ref);
293
+ }
294
+ $imgList.dataset.moved = 0;
295
+ }
296
+ document
297
+ .querySelector("html")
298
+ .classList.remove("gs-disable-apple-touchzoom");
299
+ };
300
+ }
301
+ };
302
+
303
+ export default initDraggle;