@prom-ui/core 1.7.0-alpha.2 → 1.7.0-alpha.3
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/Avatar/package.json +1 -1
- package/Backdrop/package.json +1 -1
- package/Body/package.json +1 -1
- package/BodyContext/package.json +1 -1
- package/BodyProvider/cjs/index.development.js +18 -0
- package/BodyProvider/cjs/index.development.v2.js +18 -0
- package/BodyProvider/cjs/index.production.js +1 -1
- package/BodyProvider/cjs/index.production.v2.js +1 -1
- package/BodyProvider/package.json +1 -1
- package/Box/package.json +1 -1
- package/Button/package.json +1 -1
- package/ButtonPageUp/package.json +1 -1
- package/Checkbox/package.json +1 -1
- package/Flex/package.json +1 -1
- package/Grid/package.json +1 -1
- package/Icon/package.json +1 -1
- package/Image/package.json +1 -1
- package/ImageEmoji/package.json +1 -1
- package/Input/package.json +1 -1
- package/InputField/package.json +1 -1
- package/KeyPress/package.json +1 -1
- package/Line/package.json +1 -1
- package/Link/package.json +1 -1
- package/List/package.json +1 -1
- package/Media/package.json +1 -1
- package/OutsideClick/package.json +1 -1
- package/Overlay/cjs/index.development.js +35 -4
- package/Overlay/cjs/index.development.v2.js +35 -4
- package/Overlay/cjs/index.production.js +1 -1
- package/Overlay/cjs/index.production.v2.js +1 -1
- package/Overlay/components/TouchScrollable.d.ts +8 -0
- package/Overlay/package.json +2 -1
- package/PhotoGallery/cjs/index.development.js +1361 -0
- package/PhotoGallery/cjs/index.development.v2.js +1361 -0
- package/PhotoGallery/cjs/index.production.js +1 -0
- package/PhotoGallery/cjs/index.production.v2.js +1 -0
- package/PhotoGallery/cjs/style.development.css +1 -0
- package/PhotoGallery/cjs/style.development.v2.css +1 -0
- package/PhotoGallery/cjs/style.production.css +1 -0
- package/PhotoGallery/cjs/style.production.v2.css +1 -0
- package/PhotoGallery/components/Header.d.ts +9 -0
- package/PhotoGallery/components/MainPhotos.d.ts +10 -0
- package/PhotoGallery/components/MainPhotosImage.d.ts +10 -0
- package/PhotoGallery/components/PinchZoom.d.ts +30 -0
- package/PhotoGallery/components/PreviewPhotos.d.ts +11 -0
- package/PhotoGallery/components/TouchScrollable.d.ts +9 -0
- package/PhotoGallery/index.d.ts +19 -0
- package/PhotoGallery/package.json +13 -0
- package/PhotoGallery/utils.d.ts +3 -0
- package/Picture/package.json +1 -1
- package/Portal/package.json +1 -1
- package/QRCode/package.json +1 -1
- package/Rating/package.json +1 -1
- package/RatingSelect/package.json +1 -1
- package/SafeQuery/package.json +1 -1
- package/Scroll/package.json +1 -1
- package/ScrollControls/cjs/index.development.js +8 -5
- package/ScrollControls/cjs/index.development.v2.js +8 -5
- package/ScrollControls/cjs/index.production.js +1 -1
- package/ScrollControls/cjs/index.production.v2.js +1 -1
- package/ScrollControls/index.d.ts +1 -1
- package/ScrollControls/package.json +1 -1
- package/SimpleSlider/cjs/index.development.js +1 -0
- package/SimpleSlider/cjs/index.development.v2.js +1 -0
- package/SimpleSlider/cjs/index.production.js +1 -1
- package/SimpleSlider/cjs/index.production.v2.js +1 -1
- package/SimpleSlider/index.d.ts +1 -0
- package/SimpleSlider/package.json +2 -1
- package/Skeleton/package.json +1 -1
- package/Spinner/package.json +1 -1
- package/Text/package.json +1 -1
- package/TextEmoji/package.json +1 -1
- package/Tooltip/package.json +1 -1
- package/Tumbler/package.json +1 -1
- package/package.json +4 -2
- package/useBodyTTag/package.json +1 -1
- package/useDebounce/package.json +1 -1
- package/{BodyScrollLock → useForwardRef}/cjs/index.development.js +18 -9
- package/{BodyScrollLock → useForwardRef}/cjs/index.development.v2.js +18 -9
- package/useForwardRef/cjs/index.production.js +1 -0
- package/useForwardRef/cjs/index.production.v2.js +1 -0
- package/useForwardRef/index.d.ts +5 -0
- package/{BodyScrollLock → useForwardRef}/package.json +2 -2
- package/useId/package.json +1 -1
- package/useIsMounted/package.json +1 -1
- package/useKeyPress/package.json +1 -1
- package/useMedia/package.json +1 -1
- package/useOutsideClick/package.json +1 -1
- package/usePortal/package.json +1 -1
- package/useScrollPosition/package.json +1 -1
- package/BodyScrollLock/cjs/index.production.js +0 -1
- package/BodyScrollLock/cjs/index.production.v2.js +0 -1
- package/BodyScrollLock/index.d.ts +0 -5
- package/useBodyScrollLock/cjs/index.development.js +0 -163
- package/useBodyScrollLock/cjs/index.development.v2.js +0 -163
- package/useBodyScrollLock/cjs/index.production.js +0 -1
- package/useBodyScrollLock/cjs/index.production.v2.js +0 -1
- package/useBodyScrollLock/index.d.ts +0 -5
- package/useBodyScrollLock/package.json +0 -9
- package/useBodyScrollLock/preventScrollMobileSafari.d.ts +0 -1
- package/useBodyScrollLock/preventScrollStandard.d.ts +0 -1
- package/useBodyScrollLock/utils.d.ts +0 -16
- /package/{BodyScrollLock → PhotoGallery}/index.js +0 -0
- /package/{BodyScrollLock → PhotoGallery}/index.v2.js +0 -0
- /package/{useBodyScrollLock → useForwardRef}/index.js +0 -0
- /package/{useBodyScrollLock → useForwardRef}/index.v2.js +0 -0
|
@@ -0,0 +1,1361 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var ScrollLock = require('react-scrolllock');
|
|
7
|
+
var reactTransitionGroup = require('react-transition-group');
|
|
8
|
+
var Backdrop = require('@prom-ui/core/Backdrop');
|
|
9
|
+
var KeyPress = require('@prom-ui/core/KeyPress');
|
|
10
|
+
var Portal = require('@prom-ui/core/Portal');
|
|
11
|
+
var ScrollControls = require('@prom-ui/core/ScrollControls');
|
|
12
|
+
var utils = require('react-scrolllock/dist/utils');
|
|
13
|
+
var Icon = require('@prom-ui/core/Icon');
|
|
14
|
+
var Play = require('@prom-ui/icons/Play');
|
|
15
|
+
var Button = require('@prom-ui/core/Button');
|
|
16
|
+
var useBodyTTag = require('@prom-ui/core/useBodyTTag');
|
|
17
|
+
var Close = require('@prom-ui/icons/Close');
|
|
18
|
+
|
|
19
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
20
|
+
|
|
21
|
+
function _interopNamespaceCompat(e) {
|
|
22
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
23
|
+
var n = Object.create(null);
|
|
24
|
+
if (e) {
|
|
25
|
+
Object.keys(e).forEach(function (k) {
|
|
26
|
+
if (k !== 'default') {
|
|
27
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
28
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return e[k]; }
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
n.default = e;
|
|
36
|
+
return Object.freeze(n);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceCompat(React);
|
|
40
|
+
var ScrollLock__default = /*#__PURE__*/_interopDefaultCompat(ScrollLock);
|
|
41
|
+
|
|
42
|
+
function _iterableToArrayLimit(arr, i) {
|
|
43
|
+
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
|
|
44
|
+
if (null != _i) {
|
|
45
|
+
var _s,
|
|
46
|
+
_e,
|
|
47
|
+
_x,
|
|
48
|
+
_r,
|
|
49
|
+
_arr = [],
|
|
50
|
+
_n = !0,
|
|
51
|
+
_d = !1;
|
|
52
|
+
try {
|
|
53
|
+
if (_x = (_i = _i.call(arr)).next, 0 === i) {
|
|
54
|
+
if (Object(_i) !== _i) return;
|
|
55
|
+
_n = !1;
|
|
56
|
+
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
_d = !0, _e = err;
|
|
59
|
+
} finally {
|
|
60
|
+
try {
|
|
61
|
+
if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
|
|
62
|
+
} finally {
|
|
63
|
+
if (_d) throw _e;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return _arr;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function _taggedTemplateLiteral(strings, raw) {
|
|
70
|
+
if (!raw) {
|
|
71
|
+
raw = strings.slice(0);
|
|
72
|
+
}
|
|
73
|
+
return Object.freeze(Object.defineProperties(strings, {
|
|
74
|
+
raw: {
|
|
75
|
+
value: Object.freeze(raw)
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
function _slicedToArray(arr, i) {
|
|
80
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
81
|
+
}
|
|
82
|
+
function _arrayWithHoles(arr) {
|
|
83
|
+
if (Array.isArray(arr)) return arr;
|
|
84
|
+
}
|
|
85
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
86
|
+
if (!o) return;
|
|
87
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
88
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
89
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
90
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
91
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
92
|
+
}
|
|
93
|
+
function _arrayLikeToArray(arr, len) {
|
|
94
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
95
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
96
|
+
return arr2;
|
|
97
|
+
}
|
|
98
|
+
function _nonIterableRest() {
|
|
99
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// FORK FROM https://github.com/jossmac/react-scrolllock/blob/master/src/TouchScrollable.js
|
|
103
|
+
|
|
104
|
+
function allowTouchMove(e) {
|
|
105
|
+
var target = e.currentTarget;
|
|
106
|
+
if (target.scrollHeight > target.clientHeight || target.scrollWidth > target.clientWidth) {
|
|
107
|
+
e.stopPropagation();
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
114
|
+
|
|
115
|
+
/* @ts-ignore */
|
|
116
|
+
var canUseEventListeners = canUseDOM && !!(window.addEventListener || window.attachEvent);
|
|
117
|
+
var TouchScrollable = function TouchScrollable(_ref) {
|
|
118
|
+
var _ref$isActive = _ref.isActive,
|
|
119
|
+
isActive = _ref$isActive === void 0 ? false : _ref$isActive,
|
|
120
|
+
scrollRef = _ref.scrollRef,
|
|
121
|
+
children = _ref.children;
|
|
122
|
+
React__namespace.useEffect(function () {
|
|
123
|
+
if (!isActive || !canUseEventListeners || !(scrollRef !== null && scrollRef !== void 0 && scrollRef.current)) return;
|
|
124
|
+
scrollRef.current.addEventListener('touchstart', utils.preventInertiaScroll, utils.listenerOptions);
|
|
125
|
+
scrollRef.current.addEventListener('touchmove', allowTouchMove, utils.listenerOptions);
|
|
126
|
+
return function () {
|
|
127
|
+
if (!isActive || !canUseEventListeners || !(scrollRef !== null && scrollRef !== void 0 && scrollRef.current)) return;
|
|
128
|
+
scrollRef.current.removeEventListener('touchstart', utils.preventInertiaScroll, utils.listenerOptions);
|
|
129
|
+
scrollRef.current.removeEventListener('touchmove', allowTouchMove, utils.listenerOptions);
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, children);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
var reqMap = new Map();
|
|
136
|
+
var scrollInToViewElement = function scrollInToViewElement(target, parent) {
|
|
137
|
+
var isAnimate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
138
|
+
if (reqMap.has(parent)) {
|
|
139
|
+
cancelAnimationFrame(reqMap.get(parent));
|
|
140
|
+
reqMap["delete"](parent);
|
|
141
|
+
}
|
|
142
|
+
var reqId = requestAnimationFrame(function () {
|
|
143
|
+
var parentRect = parent.getBoundingClientRect();
|
|
144
|
+
var targetRect = target.getBoundingClientRect();
|
|
145
|
+
var scrollTop = targetRect.top + parent.scrollTop - parentRect.top - parentRect.height / 2 + targetRect.height / 2;
|
|
146
|
+
var scrollLeft = targetRect.left + parent.scrollLeft - parentRect.left - parentRect.width / 2 + targetRect.width / 2;
|
|
147
|
+
if (scrollLeft < 0) {
|
|
148
|
+
scrollLeft = 0;
|
|
149
|
+
}
|
|
150
|
+
if (scrollTop < 0) {
|
|
151
|
+
scrollTop = 0;
|
|
152
|
+
}
|
|
153
|
+
parent.scrollTo({
|
|
154
|
+
behavior: isAnimate ? 'smooth' : 'instant',
|
|
155
|
+
top: scrollTop,
|
|
156
|
+
left: scrollLeft
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
reqMap.set(parent, reqId);
|
|
160
|
+
};
|
|
161
|
+
var getIndexFromScroll = function getIndexFromScroll(target, size) {
|
|
162
|
+
var scrollLeft = target.scrollLeft;
|
|
163
|
+
var scrollWidth = target.scrollWidth;
|
|
164
|
+
var scrollIndex = scrollLeft / scrollWidth * size;
|
|
165
|
+
return Math.round(scrollIndex);
|
|
166
|
+
};
|
|
167
|
+
var prepareVideoUrl = function prepareVideoUrl(videoSrc) {
|
|
168
|
+
var url = new URL(videoSrc);
|
|
169
|
+
url.searchParams["delete"]('autoplay');
|
|
170
|
+
url.searchParams.append('enablejsapi', '1');
|
|
171
|
+
url.searchParams.append('rel', '0');
|
|
172
|
+
return url.href;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// fork rfom https://github.com/manuelstofer/pinchzoom
|
|
176
|
+
// @ts-nocheck
|
|
177
|
+
|
|
178
|
+
// utils
|
|
179
|
+
var buildElement = function buildElement(str) {
|
|
180
|
+
// empty string as title argument required by IE and Edge
|
|
181
|
+
var tmp = document.implementation.createHTMLDocument('');
|
|
182
|
+
tmp.body.innerHTML = str;
|
|
183
|
+
return Array.from(tmp.body.children)[0];
|
|
184
|
+
};
|
|
185
|
+
var definePinchZoom = function definePinchZoom() {
|
|
186
|
+
/**
|
|
187
|
+
* Pinch zoom
|
|
188
|
+
* @param el
|
|
189
|
+
* @param options
|
|
190
|
+
* @constructor
|
|
191
|
+
*/
|
|
192
|
+
var PinchZoom = function PinchZoom(el, options) {
|
|
193
|
+
this.el = el;
|
|
194
|
+
this.zoomFactor = 1;
|
|
195
|
+
this.lastScale = 1;
|
|
196
|
+
this.offset = {
|
|
197
|
+
x: 0,
|
|
198
|
+
y: 0
|
|
199
|
+
};
|
|
200
|
+
this.initialOffset = {
|
|
201
|
+
x: 0,
|
|
202
|
+
y: 0
|
|
203
|
+
};
|
|
204
|
+
this.options = Object.assign({}, this.defaults, options);
|
|
205
|
+
this.setupMarkup();
|
|
206
|
+
this.bindEvents();
|
|
207
|
+
this.update();
|
|
208
|
+
|
|
209
|
+
// The image may already be loaded when PinchZoom is initialized,
|
|
210
|
+
// and then the load event (which trigger update) will never fire.
|
|
211
|
+
if (this.isImageLoaded(this.el)) {
|
|
212
|
+
this.updateAspectRatio();
|
|
213
|
+
this.setupOffsets();
|
|
214
|
+
}
|
|
215
|
+
this.enable();
|
|
216
|
+
},
|
|
217
|
+
sum = function sum(a, b) {
|
|
218
|
+
return a + b;
|
|
219
|
+
},
|
|
220
|
+
isCloseTo = function isCloseTo(value, expected) {
|
|
221
|
+
return value > expected - 0.01 && value < expected + 0.01;
|
|
222
|
+
};
|
|
223
|
+
PinchZoom.prototype = {
|
|
224
|
+
defaults: {
|
|
225
|
+
tapZoomFactor: 2,
|
|
226
|
+
zoomOutFactor: 1.3,
|
|
227
|
+
animationDuration: 300,
|
|
228
|
+
maxZoom: 4,
|
|
229
|
+
minZoom: 0.5,
|
|
230
|
+
draggableUnzoomed: true,
|
|
231
|
+
lockDragAxis: false,
|
|
232
|
+
setOffsetsOnce: false,
|
|
233
|
+
use2d: true,
|
|
234
|
+
useMouseWheel: false,
|
|
235
|
+
verticalPadding: 0,
|
|
236
|
+
horizontalPadding: 0,
|
|
237
|
+
onZoomStart: null,
|
|
238
|
+
onZoomEnd: null,
|
|
239
|
+
onZoomUpdate: null,
|
|
240
|
+
onDragStart: null,
|
|
241
|
+
onDragEnd: null,
|
|
242
|
+
onDragUpdate: null,
|
|
243
|
+
onDoubleTap: null,
|
|
244
|
+
onMouseWheel: null
|
|
245
|
+
},
|
|
246
|
+
/**
|
|
247
|
+
* Event handler for 'dragstart'
|
|
248
|
+
* @param event
|
|
249
|
+
*/
|
|
250
|
+
handleDragStart: function handleDragStart(event) {
|
|
251
|
+
if (typeof this.options.onDragStart == 'function') {
|
|
252
|
+
this.options.onDragStart(this, event);
|
|
253
|
+
}
|
|
254
|
+
this.stopAnimation();
|
|
255
|
+
this.lastDragPosition = false;
|
|
256
|
+
this.hasInteraction = true;
|
|
257
|
+
this.handleDrag(event);
|
|
258
|
+
},
|
|
259
|
+
/**
|
|
260
|
+
* Event handler for 'drag'
|
|
261
|
+
* @param event
|
|
262
|
+
*/
|
|
263
|
+
handleDrag: function handleDrag(event) {
|
|
264
|
+
var touch = event.type === 'touchmove' ? this.getTouches(event)[0] : this.getPointer(event);
|
|
265
|
+
this.drag(touch, this.lastDragPosition);
|
|
266
|
+
this.offset = this.sanitizeOffset(this.offset);
|
|
267
|
+
this.lastDragPosition = touch;
|
|
268
|
+
},
|
|
269
|
+
handleDragEnd: function handleDragEnd() {
|
|
270
|
+
if (typeof this.options.onDragEnd == 'function') {
|
|
271
|
+
this.options.onDragEnd(this, event);
|
|
272
|
+
}
|
|
273
|
+
this.end();
|
|
274
|
+
},
|
|
275
|
+
/**
|
|
276
|
+
* Event handler for 'zoomstart'
|
|
277
|
+
* @param event
|
|
278
|
+
*/
|
|
279
|
+
handleZoomStart: function handleZoomStart(event) {
|
|
280
|
+
if (typeof this.options.onZoomStart == 'function') {
|
|
281
|
+
this.options.onZoomStart(this, event);
|
|
282
|
+
}
|
|
283
|
+
this.stopAnimation();
|
|
284
|
+
this.lastScale = 1;
|
|
285
|
+
this.nthZoom = 0;
|
|
286
|
+
this.lastZoomCenter = false;
|
|
287
|
+
this.hasInteraction = true;
|
|
288
|
+
},
|
|
289
|
+
/**
|
|
290
|
+
* Event handler for 'zoom'
|
|
291
|
+
* @param event
|
|
292
|
+
*/
|
|
293
|
+
handleZoom: function handleZoom(event, newScale) {
|
|
294
|
+
// a relative scale factor is used
|
|
295
|
+
var touchCenter = this.getTouchCenter(this.getTouches(event)),
|
|
296
|
+
scale = newScale / this.lastScale;
|
|
297
|
+
this.lastScale = newScale;
|
|
298
|
+
|
|
299
|
+
// the first touch events are thrown away since they are not precise
|
|
300
|
+
this.nthZoom += 1;
|
|
301
|
+
if (this.nthZoom > 3) {
|
|
302
|
+
this.scale(scale, touchCenter);
|
|
303
|
+
this.drag(touchCenter, this.lastZoomCenter);
|
|
304
|
+
}
|
|
305
|
+
this.lastZoomCenter = touchCenter;
|
|
306
|
+
},
|
|
307
|
+
handleZoomEnd: function handleZoomEnd() {
|
|
308
|
+
if (typeof this.options.onZoomEnd == 'function') {
|
|
309
|
+
this.options.onZoomEnd(this, event);
|
|
310
|
+
}
|
|
311
|
+
this.end();
|
|
312
|
+
},
|
|
313
|
+
/**
|
|
314
|
+
* Event handler for 'doubletap'
|
|
315
|
+
* @param event
|
|
316
|
+
*/
|
|
317
|
+
handleDoubleTap: function handleDoubleTap(event) {
|
|
318
|
+
var center = this.getTouches(event)[0],
|
|
319
|
+
zoomFactor = this.zoomFactor > 1 ? 1 : this.options.tapZoomFactor,
|
|
320
|
+
startZoomFactor = this.zoomFactor,
|
|
321
|
+
updateProgress = function (progress) {
|
|
322
|
+
this.scaleTo(startZoomFactor + progress * (zoomFactor - startZoomFactor), center);
|
|
323
|
+
}.bind(this);
|
|
324
|
+
if (this.hasInteraction) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
this.isDoubleTap = true;
|
|
328
|
+
if (startZoomFactor > zoomFactor) {
|
|
329
|
+
center = this.getCurrentZoomCenter();
|
|
330
|
+
}
|
|
331
|
+
this.animate(this.options.animationDuration, updateProgress, this.swing);
|
|
332
|
+
if (typeof this.options.onDoubleTap == 'function') {
|
|
333
|
+
this.options.onDoubleTap(this, event);
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
/**
|
|
337
|
+
* Event handler for 'mousewheel'
|
|
338
|
+
* @param event
|
|
339
|
+
*/
|
|
340
|
+
handleMouseWheel: function handleMouseWheel(event) {
|
|
341
|
+
var center = this.getPointer(event),
|
|
342
|
+
newScale = Math.min(Math.max(this.options.minZoom, this.lastScale + event.deltaY * -0.01), this.options.maxZoom),
|
|
343
|
+
scale = newScale / this.lastScale;
|
|
344
|
+
this.scale(scale, center);
|
|
345
|
+
this.lastScale = newScale;
|
|
346
|
+
this.update();
|
|
347
|
+
if (typeof this.options.onMouseWheel == 'function') {
|
|
348
|
+
this.options.onMouseWheel(this, event);
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
/**
|
|
352
|
+
* Compute the initial offset
|
|
353
|
+
*
|
|
354
|
+
* the element should be centered in the container upon initialization
|
|
355
|
+
*/
|
|
356
|
+
computeInitialOffset: function computeInitialOffset() {
|
|
357
|
+
this.initialOffset = {
|
|
358
|
+
x: -Math.abs(this.el.offsetWidth * this.getInitialZoomFactor() - this.container.offsetWidth) / 2,
|
|
359
|
+
y: -Math.abs(this.el.offsetHeight * this.getInitialZoomFactor() - this.container.offsetHeight) / 2
|
|
360
|
+
};
|
|
361
|
+
},
|
|
362
|
+
/**
|
|
363
|
+
* Reset current image offset to that of the initial offset
|
|
364
|
+
*/
|
|
365
|
+
resetOffset: function resetOffset() {
|
|
366
|
+
this.offset.x = this.initialOffset.x;
|
|
367
|
+
this.offset.y = this.initialOffset.y;
|
|
368
|
+
},
|
|
369
|
+
/**
|
|
370
|
+
* Determine if image is loaded
|
|
371
|
+
*/
|
|
372
|
+
isImageLoaded: function isImageLoaded(el) {
|
|
373
|
+
if (el.nodeName === 'IMG') {
|
|
374
|
+
return el.complete && el.naturalHeight !== 0;
|
|
375
|
+
} else {
|
|
376
|
+
return Array.from(el.querySelectorAll('img')).every(this.isImageLoaded);
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
setupOffsets: function setupOffsets() {
|
|
380
|
+
if (this.options.setOffsetsOnce && this._isOffsetsSet) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
this._isOffsetsSet = true;
|
|
384
|
+
this.computeInitialOffset();
|
|
385
|
+
this.resetOffset();
|
|
386
|
+
},
|
|
387
|
+
/**
|
|
388
|
+
* Max / min values for the offset
|
|
389
|
+
* @param offset
|
|
390
|
+
* @return {Object} the sanitized offset
|
|
391
|
+
*/
|
|
392
|
+
sanitizeOffset: function sanitizeOffset(offset) {
|
|
393
|
+
var elWidth = this.el.offsetWidth * this.getInitialZoomFactor() * this.zoomFactor;
|
|
394
|
+
var elHeight = this.el.offsetHeight * this.getInitialZoomFactor() * this.zoomFactor;
|
|
395
|
+
var maxX = elWidth - this.getContainerX() + this.options.horizontalPadding,
|
|
396
|
+
maxY = elHeight - this.getContainerY() + this.options.verticalPadding,
|
|
397
|
+
maxOffsetX = Math.max(maxX, 0),
|
|
398
|
+
maxOffsetY = Math.max(maxY, 0),
|
|
399
|
+
minOffsetX = Math.min(maxX, 0) - this.options.horizontalPadding,
|
|
400
|
+
minOffsetY = Math.min(maxY, 0) - this.options.verticalPadding;
|
|
401
|
+
return {
|
|
402
|
+
x: Math.min(Math.max(offset.x, minOffsetX), maxOffsetX),
|
|
403
|
+
y: Math.min(Math.max(offset.y, minOffsetY), maxOffsetY)
|
|
404
|
+
};
|
|
405
|
+
},
|
|
406
|
+
/**
|
|
407
|
+
* Scale to a specific zoom factor (not relative)
|
|
408
|
+
* @param zoomFactor
|
|
409
|
+
* @param center
|
|
410
|
+
*/
|
|
411
|
+
scaleTo: function scaleTo(zoomFactor, center) {
|
|
412
|
+
this.scale(zoomFactor / this.zoomFactor, center);
|
|
413
|
+
},
|
|
414
|
+
/**
|
|
415
|
+
* Scales the element from specified center
|
|
416
|
+
* @param scale
|
|
417
|
+
* @param center
|
|
418
|
+
*/
|
|
419
|
+
scale: function scale(_scale, center) {
|
|
420
|
+
_scale = this.scaleZoomFactor(_scale);
|
|
421
|
+
this.addOffset({
|
|
422
|
+
x: (_scale - 1) * (center.x + this.offset.x),
|
|
423
|
+
y: (_scale - 1) * (center.y + this.offset.y)
|
|
424
|
+
});
|
|
425
|
+
if (typeof this.options.onZoomUpdate == 'function') {
|
|
426
|
+
this.options.onZoomUpdate(this, event);
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
/**
|
|
430
|
+
* Scales the zoom factor relative to current state
|
|
431
|
+
* @param scale
|
|
432
|
+
* @return the actual scale (can differ because of max min zoom factor)
|
|
433
|
+
*/
|
|
434
|
+
scaleZoomFactor: function scaleZoomFactor(scale) {
|
|
435
|
+
var originalZoomFactor = this.zoomFactor;
|
|
436
|
+
this.zoomFactor *= scale;
|
|
437
|
+
this.zoomFactor = Math.min(this.options.maxZoom, Math.max(this.zoomFactor, this.options.minZoom));
|
|
438
|
+
return this.zoomFactor / originalZoomFactor;
|
|
439
|
+
},
|
|
440
|
+
/**
|
|
441
|
+
* Determine if the image is in a draggable state
|
|
442
|
+
*
|
|
443
|
+
* When the image can be dragged, the drag event is acted upon and cancelled.
|
|
444
|
+
* When not draggable, the drag event bubbles through this component.
|
|
445
|
+
*
|
|
446
|
+
* @return {Boolean}
|
|
447
|
+
*/
|
|
448
|
+
canDrag: function canDrag() {
|
|
449
|
+
return this.options.draggableUnzoomed || !isCloseTo(this.zoomFactor, 1);
|
|
450
|
+
},
|
|
451
|
+
/**
|
|
452
|
+
* Drags the element
|
|
453
|
+
* @param center
|
|
454
|
+
* @param lastCenter
|
|
455
|
+
*/
|
|
456
|
+
drag: function drag(center, lastCenter) {
|
|
457
|
+
if (lastCenter) {
|
|
458
|
+
if (this.options.lockDragAxis) {
|
|
459
|
+
// lock scroll to position that was changed the most
|
|
460
|
+
if (Math.abs(center.x - lastCenter.x) > Math.abs(center.y - lastCenter.y)) {
|
|
461
|
+
this.addOffset({
|
|
462
|
+
x: -(center.x - lastCenter.x),
|
|
463
|
+
y: 0
|
|
464
|
+
});
|
|
465
|
+
} else {
|
|
466
|
+
this.addOffset({
|
|
467
|
+
y: -(center.y - lastCenter.y),
|
|
468
|
+
x: 0
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
} else {
|
|
472
|
+
this.addOffset({
|
|
473
|
+
y: -(center.y - lastCenter.y),
|
|
474
|
+
x: -(center.x - lastCenter.x)
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
if (typeof this.options.onDragUpdate == 'function') {
|
|
478
|
+
this.options.onDragUpdate(this, event);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
/**
|
|
483
|
+
* Calculates the touch center of multiple touches
|
|
484
|
+
* @param touches
|
|
485
|
+
* @return {Object}
|
|
486
|
+
*/
|
|
487
|
+
getTouchCenter: function getTouchCenter(touches) {
|
|
488
|
+
return this.getVectorAvg(touches);
|
|
489
|
+
},
|
|
490
|
+
/**
|
|
491
|
+
* Calculates the average of multiple vectors (x, y values)
|
|
492
|
+
*/
|
|
493
|
+
getVectorAvg: function getVectorAvg(vectors) {
|
|
494
|
+
return {
|
|
495
|
+
x: vectors.map(function (v) {
|
|
496
|
+
return v.x;
|
|
497
|
+
}).reduce(sum) / vectors.length,
|
|
498
|
+
y: vectors.map(function (v) {
|
|
499
|
+
return v.y;
|
|
500
|
+
}).reduce(sum) / vectors.length
|
|
501
|
+
};
|
|
502
|
+
},
|
|
503
|
+
/**
|
|
504
|
+
* Adds an offset
|
|
505
|
+
* @param offset the offset to add
|
|
506
|
+
* @return return true when the offset change was accepted
|
|
507
|
+
*/
|
|
508
|
+
addOffset: function addOffset(offset) {
|
|
509
|
+
this.offset = {
|
|
510
|
+
x: this.offset.x + offset.x,
|
|
511
|
+
y: this.offset.y + offset.y
|
|
512
|
+
};
|
|
513
|
+
},
|
|
514
|
+
sanitize: function sanitize() {
|
|
515
|
+
if (this.zoomFactor < this.options.zoomOutFactor) {
|
|
516
|
+
this.zoomOutAnimation();
|
|
517
|
+
} else if (this.isInsaneOffset(this.offset)) {
|
|
518
|
+
this.sanitizeOffsetAnimation();
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
/**
|
|
522
|
+
* Checks if the offset is ok with the current zoom factor
|
|
523
|
+
* @param offset
|
|
524
|
+
* @return {Boolean}
|
|
525
|
+
*/
|
|
526
|
+
isInsaneOffset: function isInsaneOffset(offset) {
|
|
527
|
+
var sanitizedOffset = this.sanitizeOffset(offset);
|
|
528
|
+
return sanitizedOffset.x !== offset.x || sanitizedOffset.y !== offset.y;
|
|
529
|
+
},
|
|
530
|
+
/**
|
|
531
|
+
* Creates an animation moving to a sane offset
|
|
532
|
+
*/
|
|
533
|
+
sanitizeOffsetAnimation: function sanitizeOffsetAnimation() {
|
|
534
|
+
var targetOffset = this.sanitizeOffset(this.offset),
|
|
535
|
+
startOffset = {
|
|
536
|
+
x: this.offset.x,
|
|
537
|
+
y: this.offset.y
|
|
538
|
+
},
|
|
539
|
+
updateProgress = function (progress) {
|
|
540
|
+
this.offset.x = startOffset.x + progress * (targetOffset.x - startOffset.x);
|
|
541
|
+
this.offset.y = startOffset.y + progress * (targetOffset.y - startOffset.y);
|
|
542
|
+
this.update();
|
|
543
|
+
}.bind(this);
|
|
544
|
+
this.animate(this.options.animationDuration, updateProgress, this.swing);
|
|
545
|
+
},
|
|
546
|
+
/**
|
|
547
|
+
* Zooms back to the original position,
|
|
548
|
+
* (no offset and zoom factor 1)
|
|
549
|
+
*/
|
|
550
|
+
zoomOutAnimation: function zoomOutAnimation() {
|
|
551
|
+
if (this.zoomFactor === 1) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
var startZoomFactor = this.zoomFactor,
|
|
555
|
+
zoomFactor = 1,
|
|
556
|
+
center = this.getCurrentZoomCenter(),
|
|
557
|
+
updateProgress = function (progress) {
|
|
558
|
+
this.scaleTo(startZoomFactor + progress * (zoomFactor - startZoomFactor), center);
|
|
559
|
+
}.bind(this);
|
|
560
|
+
this.animate(this.options.animationDuration, updateProgress, this.swing);
|
|
561
|
+
},
|
|
562
|
+
/**
|
|
563
|
+
* Updates the container aspect ratio
|
|
564
|
+
*
|
|
565
|
+
* Any previous container height must be cleared before re-measuring the
|
|
566
|
+
* parent height, since it depends implicitly on the height of any of its children
|
|
567
|
+
*/
|
|
568
|
+
updateAspectRatio: function updateAspectRatio() {
|
|
569
|
+
this.unsetContainerY();
|
|
570
|
+
this.setContainerY(this.container.parentElement.offsetHeight);
|
|
571
|
+
},
|
|
572
|
+
/**
|
|
573
|
+
* Calculates the initial zoom factor (for the element to fit into the container)
|
|
574
|
+
* @return {number} the initial zoom factor
|
|
575
|
+
*/
|
|
576
|
+
getInitialZoomFactor: function getInitialZoomFactor() {
|
|
577
|
+
var xZoomFactor = this.container.offsetWidth / this.el.offsetWidth;
|
|
578
|
+
var yZoomFactor = this.container.offsetHeight / this.el.offsetHeight;
|
|
579
|
+
return Math.min(xZoomFactor, yZoomFactor);
|
|
580
|
+
},
|
|
581
|
+
/**
|
|
582
|
+
* Calculates the aspect ratio of the element
|
|
583
|
+
* @return the aspect ratio
|
|
584
|
+
*/
|
|
585
|
+
getAspectRatio: function getAspectRatio() {
|
|
586
|
+
return this.el.offsetWidth / this.el.offsetHeight;
|
|
587
|
+
},
|
|
588
|
+
/**
|
|
589
|
+
* Calculates the virtual zoom center for the current offset and zoom factor
|
|
590
|
+
* (used for reverse zoom)
|
|
591
|
+
* @return {Object} the current zoom center
|
|
592
|
+
*/
|
|
593
|
+
getCurrentZoomCenter: function getCurrentZoomCenter() {
|
|
594
|
+
var offsetLeft = this.offset.x - this.initialOffset.x;
|
|
595
|
+
var centerX = -1 * this.offset.x - offsetLeft / (1 / this.zoomFactor - 1);
|
|
596
|
+
var offsetTop = this.offset.y - this.initialOffset.y;
|
|
597
|
+
var centerY = -1 * this.offset.y - offsetTop / (1 / this.zoomFactor - 1);
|
|
598
|
+
return {
|
|
599
|
+
x: centerX,
|
|
600
|
+
y: centerY
|
|
601
|
+
};
|
|
602
|
+
},
|
|
603
|
+
/**
|
|
604
|
+
* Returns the touches of an event relative to the container offset
|
|
605
|
+
* @param event
|
|
606
|
+
* @return array touches
|
|
607
|
+
*/
|
|
608
|
+
getTouches: function getTouches(event) {
|
|
609
|
+
var rect = this.container.getBoundingClientRect();
|
|
610
|
+
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
|
|
611
|
+
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
|
|
612
|
+
var posTop = rect.top + scrollTop;
|
|
613
|
+
var posLeft = rect.left + scrollLeft;
|
|
614
|
+
return Array.prototype.slice.call(event.touches).map(function (touch) {
|
|
615
|
+
return {
|
|
616
|
+
x: touch.pageX - posLeft,
|
|
617
|
+
y: touch.pageY - posTop
|
|
618
|
+
};
|
|
619
|
+
});
|
|
620
|
+
},
|
|
621
|
+
/**
|
|
622
|
+
* Returns the pointer of an event relative to the container offset
|
|
623
|
+
* @param event
|
|
624
|
+
* @return pointer
|
|
625
|
+
*/
|
|
626
|
+
getPointer: function getPointer(event) {
|
|
627
|
+
var rect = this.container.getBoundingClientRect();
|
|
628
|
+
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
|
|
629
|
+
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
|
|
630
|
+
var posTop = rect.top + scrollTop;
|
|
631
|
+
var posLeft = rect.left + scrollLeft;
|
|
632
|
+
return {
|
|
633
|
+
x: event.pageX - posLeft,
|
|
634
|
+
y: event.pageY - posTop
|
|
635
|
+
};
|
|
636
|
+
},
|
|
637
|
+
/**
|
|
638
|
+
* Animation loop
|
|
639
|
+
* does not support simultaneous animations
|
|
640
|
+
* @param duration
|
|
641
|
+
* @param framefn
|
|
642
|
+
* @param timefn
|
|
643
|
+
* @param callback
|
|
644
|
+
*/
|
|
645
|
+
animate: function animate(duration, framefn, timefn, callback) {
|
|
646
|
+
var startTime = new Date().getTime(),
|
|
647
|
+
renderFrame = function () {
|
|
648
|
+
if (!this.inAnimation) {
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
var frameTime = new Date().getTime() - startTime,
|
|
652
|
+
progress = frameTime / duration;
|
|
653
|
+
if (frameTime >= duration) {
|
|
654
|
+
framefn(1);
|
|
655
|
+
if (callback) {
|
|
656
|
+
callback();
|
|
657
|
+
}
|
|
658
|
+
this.update();
|
|
659
|
+
this.stopAnimation();
|
|
660
|
+
this.update();
|
|
661
|
+
} else {
|
|
662
|
+
if (timefn) {
|
|
663
|
+
progress = timefn(progress);
|
|
664
|
+
}
|
|
665
|
+
framefn(progress);
|
|
666
|
+
this.update();
|
|
667
|
+
requestAnimationFrame(renderFrame);
|
|
668
|
+
}
|
|
669
|
+
}.bind(this);
|
|
670
|
+
this.inAnimation = true;
|
|
671
|
+
requestAnimationFrame(renderFrame);
|
|
672
|
+
},
|
|
673
|
+
/**
|
|
674
|
+
* Stops the animation
|
|
675
|
+
*/
|
|
676
|
+
stopAnimation: function stopAnimation() {
|
|
677
|
+
this.inAnimation = false;
|
|
678
|
+
},
|
|
679
|
+
/**
|
|
680
|
+
* Swing timing function for animations
|
|
681
|
+
* @param p
|
|
682
|
+
* @return {Number}
|
|
683
|
+
*/
|
|
684
|
+
swing: function swing(p) {
|
|
685
|
+
return -Math.cos(p * Math.PI) / 2 + 0.5;
|
|
686
|
+
},
|
|
687
|
+
getContainerX: function getContainerX() {
|
|
688
|
+
return this.container.offsetWidth;
|
|
689
|
+
},
|
|
690
|
+
getContainerY: function getContainerY() {
|
|
691
|
+
return this.container.offsetHeight;
|
|
692
|
+
},
|
|
693
|
+
setContainerY: function setContainerY(y) {
|
|
694
|
+
return this.container.style.height = y + 'px';
|
|
695
|
+
},
|
|
696
|
+
unsetContainerY: function unsetContainerY() {
|
|
697
|
+
this.container.style.height = null;
|
|
698
|
+
},
|
|
699
|
+
/**
|
|
700
|
+
* Creates the expected html structure
|
|
701
|
+
*/
|
|
702
|
+
setupMarkup: function setupMarkup() {
|
|
703
|
+
this.container = buildElement('<div class="pinch-zoom-container"></div>');
|
|
704
|
+
this.el.parentNode.insertBefore(this.container, this.el);
|
|
705
|
+
this.container.appendChild(this.el);
|
|
706
|
+
this.container.style.overflow = 'hidden';
|
|
707
|
+
this.container.style.position = 'relative';
|
|
708
|
+
this.el.style.webkitTransformOrigin = '0% 0%';
|
|
709
|
+
this.el.style.mozTransformOrigin = '0% 0%';
|
|
710
|
+
this.el.style.msTransformOrigin = '0% 0%';
|
|
711
|
+
this.el.style.oTransformOrigin = '0% 0%';
|
|
712
|
+
this.el.style.transformOrigin = '0% 0%';
|
|
713
|
+
this.el.style.position = 'absolute';
|
|
714
|
+
this.el.style.backfaceVisibility = 'hidden';
|
|
715
|
+
this.el.style.willChange = 'transform';
|
|
716
|
+
},
|
|
717
|
+
end: function end() {
|
|
718
|
+
this.hasInteraction = false;
|
|
719
|
+
this.sanitize();
|
|
720
|
+
this.update();
|
|
721
|
+
},
|
|
722
|
+
/**
|
|
723
|
+
* Binds all required event listeners
|
|
724
|
+
*/
|
|
725
|
+
bindEvents: function bindEvents() {
|
|
726
|
+
var self = this;
|
|
727
|
+
detectGestures(this.container, this);
|
|
728
|
+
this.resizeHandler = this.update.bind(this);
|
|
729
|
+
window.addEventListener('resize', this.resizeHandler);
|
|
730
|
+
Array.from(this.el.querySelectorAll('img')).forEach(function (imgEl) {
|
|
731
|
+
imgEl.addEventListener('load', self.update.bind(self));
|
|
732
|
+
});
|
|
733
|
+
if (this.el.nodeName === 'IMG') {
|
|
734
|
+
this.el.addEventListener('load', this.update.bind(this));
|
|
735
|
+
}
|
|
736
|
+
},
|
|
737
|
+
/**
|
|
738
|
+
* Updates the css values according to the current zoom factor and offset
|
|
739
|
+
*/
|
|
740
|
+
update: function update(event) {
|
|
741
|
+
if (event && event.type === 'resize') {
|
|
742
|
+
this.updateAspectRatio();
|
|
743
|
+
this.setupOffsets();
|
|
744
|
+
}
|
|
745
|
+
if (event && event.type === 'load') {
|
|
746
|
+
this.updateAspectRatio();
|
|
747
|
+
this.setupOffsets();
|
|
748
|
+
}
|
|
749
|
+
if (this.updatePlanned) {
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
this.updatePlanned = true;
|
|
753
|
+
window.setTimeout(function () {
|
|
754
|
+
this.updatePlanned = false;
|
|
755
|
+
var zoomFactor = this.getInitialZoomFactor() * this.zoomFactor,
|
|
756
|
+
offsetX = -this.offset.x / zoomFactor,
|
|
757
|
+
offsetY = -this.offset.y / zoomFactor,
|
|
758
|
+
transform3d = 'scale3d(' + zoomFactor + ', ' + zoomFactor + ',1) ' + 'translate3d(' + offsetX + 'px,' + offsetY + 'px,0px)',
|
|
759
|
+
transform2d = 'scale(' + zoomFactor + ', ' + zoomFactor + ') ' + 'translate(' + offsetX + 'px,' + offsetY + 'px)',
|
|
760
|
+
removeClone = function () {
|
|
761
|
+
if (this.clone) {
|
|
762
|
+
this.clone.parentNode.removeChild(this.clone);
|
|
763
|
+
delete this.clone;
|
|
764
|
+
}
|
|
765
|
+
}.bind(this);
|
|
766
|
+
|
|
767
|
+
// Scale 3d and translate3d are faster (at least on ios)
|
|
768
|
+
// but they also reduce the quality.
|
|
769
|
+
// PinchZoom uses the 3d transformations during interactions
|
|
770
|
+
// after interactions it falls back to 2d transformations
|
|
771
|
+
if (!this.options.use2d || this.hasInteraction || this.inAnimation) {
|
|
772
|
+
this.is3d = true;
|
|
773
|
+
removeClone();
|
|
774
|
+
this.el.style.webkitTransform = transform3d;
|
|
775
|
+
this.el.style.mozTransform = transform2d;
|
|
776
|
+
this.el.style.msTransform = transform2d;
|
|
777
|
+
this.el.style.oTransform = transform2d;
|
|
778
|
+
this.el.style.transform = transform3d;
|
|
779
|
+
} else {
|
|
780
|
+
// When changing from 3d to 2d transform webkit has some glitches.
|
|
781
|
+
// To avoid this, a copy of the 3d transformed element is displayed in the
|
|
782
|
+
// foreground while the element is converted from 3d to 2d transform
|
|
783
|
+
if (this.is3d) {
|
|
784
|
+
this.clone = this.el.cloneNode(true);
|
|
785
|
+
this.clone.style.pointerEvents = 'none';
|
|
786
|
+
this.container.appendChild(this.clone);
|
|
787
|
+
window.setTimeout(removeClone, 200);
|
|
788
|
+
}
|
|
789
|
+
this.el.style.webkitTransform = transform2d;
|
|
790
|
+
this.el.style.mozTransform = transform2d;
|
|
791
|
+
this.el.style.msTransform = transform2d;
|
|
792
|
+
this.el.style.oTransform = transform2d;
|
|
793
|
+
this.el.style.transform = transform2d;
|
|
794
|
+
this.is3d = false;
|
|
795
|
+
}
|
|
796
|
+
}.bind(this), 0);
|
|
797
|
+
},
|
|
798
|
+
/**
|
|
799
|
+
* Enables event handling for gestures
|
|
800
|
+
*/
|
|
801
|
+
enable: function enable() {
|
|
802
|
+
this.enabled = true;
|
|
803
|
+
},
|
|
804
|
+
/**
|
|
805
|
+
* Disables event handling for gestures
|
|
806
|
+
*/
|
|
807
|
+
disable: function disable() {
|
|
808
|
+
this.enabled = false;
|
|
809
|
+
},
|
|
810
|
+
/**
|
|
811
|
+
* Unmounts the zooming container and global event listeners
|
|
812
|
+
*/
|
|
813
|
+
destroy: function destroy() {
|
|
814
|
+
window.removeEventListener('resize', this.resizeHandler);
|
|
815
|
+
if (this.container) {
|
|
816
|
+
this.container.remove();
|
|
817
|
+
this.container = null;
|
|
818
|
+
}
|
|
819
|
+
},
|
|
820
|
+
reset: function reset() {
|
|
821
|
+
this.zoomOutAnimation();
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
var detectGestures = function detectGestures(el, target) {
|
|
825
|
+
var interaction = null,
|
|
826
|
+
fingers = 0,
|
|
827
|
+
lastTouchStart = null,
|
|
828
|
+
startTouches = null,
|
|
829
|
+
setInteraction = function setInteraction(newInteraction, event) {
|
|
830
|
+
if (interaction !== newInteraction) {
|
|
831
|
+
if (interaction && !newInteraction) {
|
|
832
|
+
switch (interaction) {
|
|
833
|
+
case 'zoom':
|
|
834
|
+
target.handleZoomEnd(event);
|
|
835
|
+
break;
|
|
836
|
+
case 'drag':
|
|
837
|
+
target.handleDragEnd(event);
|
|
838
|
+
break;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
switch (newInteraction) {
|
|
842
|
+
case 'zoom':
|
|
843
|
+
target.handleZoomStart(event);
|
|
844
|
+
break;
|
|
845
|
+
case 'drag':
|
|
846
|
+
target.handleDragStart(event);
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
interaction = newInteraction;
|
|
851
|
+
},
|
|
852
|
+
updateInteraction = function updateInteraction(event) {
|
|
853
|
+
if (fingers === 2) {
|
|
854
|
+
setInteraction('zoom');
|
|
855
|
+
} else if (fingers === 1 && target.canDrag()) {
|
|
856
|
+
setInteraction('drag', event);
|
|
857
|
+
} else {
|
|
858
|
+
setInteraction(null, event);
|
|
859
|
+
}
|
|
860
|
+
},
|
|
861
|
+
targetTouches = function targetTouches(touches) {
|
|
862
|
+
return Array.from(touches).map(function (touch) {
|
|
863
|
+
return {
|
|
864
|
+
x: touch.pageX,
|
|
865
|
+
y: touch.pageY
|
|
866
|
+
};
|
|
867
|
+
});
|
|
868
|
+
},
|
|
869
|
+
getDistance = function getDistance(a, b) {
|
|
870
|
+
var x, y;
|
|
871
|
+
x = a.x - b.x;
|
|
872
|
+
y = a.y - b.y;
|
|
873
|
+
return Math.sqrt(x * x + y * y);
|
|
874
|
+
},
|
|
875
|
+
calculateScale = function calculateScale(startTouches, endTouches) {
|
|
876
|
+
var startDistance = getDistance(startTouches[0], startTouches[1]),
|
|
877
|
+
endDistance = getDistance(endTouches[0], endTouches[1]);
|
|
878
|
+
return endDistance / startDistance;
|
|
879
|
+
},
|
|
880
|
+
cancelEvent = function cancelEvent(event) {
|
|
881
|
+
event.stopPropagation();
|
|
882
|
+
event.preventDefault();
|
|
883
|
+
},
|
|
884
|
+
detectDoubleTap = function detectDoubleTap(event) {
|
|
885
|
+
var time = new Date().getTime();
|
|
886
|
+
if (fingers > 1) {
|
|
887
|
+
lastTouchStart = null;
|
|
888
|
+
}
|
|
889
|
+
if (time - lastTouchStart < 300) {
|
|
890
|
+
cancelEvent(event);
|
|
891
|
+
target.handleDoubleTap(event);
|
|
892
|
+
switch (interaction) {
|
|
893
|
+
case 'zoom':
|
|
894
|
+
target.handleZoomEnd(event);
|
|
895
|
+
break;
|
|
896
|
+
case 'drag':
|
|
897
|
+
target.handleDragEnd(event);
|
|
898
|
+
break;
|
|
899
|
+
}
|
|
900
|
+
} else {
|
|
901
|
+
target.isDoubleTap = false;
|
|
902
|
+
}
|
|
903
|
+
if (fingers === 1) {
|
|
904
|
+
lastTouchStart = time;
|
|
905
|
+
}
|
|
906
|
+
},
|
|
907
|
+
firstMove = true;
|
|
908
|
+
el.addEventListener('touchstart', function (event) {
|
|
909
|
+
if (target.enabled) {
|
|
910
|
+
firstMove = true;
|
|
911
|
+
fingers = event.touches.length;
|
|
912
|
+
detectDoubleTap(event);
|
|
913
|
+
}
|
|
914
|
+
}, {
|
|
915
|
+
passive: false
|
|
916
|
+
});
|
|
917
|
+
el.addEventListener('touchmove', function (event) {
|
|
918
|
+
if (target.enabled && !target.isDoubleTap) {
|
|
919
|
+
if (firstMove) {
|
|
920
|
+
updateInteraction(event);
|
|
921
|
+
if (interaction) {
|
|
922
|
+
cancelEvent(event);
|
|
923
|
+
}
|
|
924
|
+
startTouches = targetTouches(event.touches);
|
|
925
|
+
} else {
|
|
926
|
+
switch (interaction) {
|
|
927
|
+
case 'zoom':
|
|
928
|
+
if (startTouches.length == 2 && event.touches.length == 2) {
|
|
929
|
+
target.handleZoom(event, calculateScale(startTouches, targetTouches(event.touches)));
|
|
930
|
+
}
|
|
931
|
+
break;
|
|
932
|
+
case 'drag':
|
|
933
|
+
target.handleDrag(event);
|
|
934
|
+
break;
|
|
935
|
+
}
|
|
936
|
+
if (interaction) {
|
|
937
|
+
cancelEvent(event);
|
|
938
|
+
target.update();
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
firstMove = false;
|
|
942
|
+
}
|
|
943
|
+
}, {
|
|
944
|
+
passive: false
|
|
945
|
+
});
|
|
946
|
+
el.addEventListener('touchend', function (event) {
|
|
947
|
+
if (target.enabled) {
|
|
948
|
+
fingers = event.touches.length;
|
|
949
|
+
updateInteraction(event);
|
|
950
|
+
}
|
|
951
|
+
});
|
|
952
|
+
if (target.options.useMouseWheel) {
|
|
953
|
+
el.addEventListener('mousewheel', function (event) {
|
|
954
|
+
if (target.enabled) {
|
|
955
|
+
cancelEvent(event);
|
|
956
|
+
target.handleMouseWheel(event);
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
el.addEventListener('mousedown', function (event) {
|
|
960
|
+
if (target.enabled) {
|
|
961
|
+
firstMove = true;
|
|
962
|
+
fingers = 1;
|
|
963
|
+
}
|
|
964
|
+
}, {
|
|
965
|
+
passive: true
|
|
966
|
+
});
|
|
967
|
+
el.addEventListener('mousemove', function (event) {
|
|
968
|
+
if (target.enabled) {
|
|
969
|
+
if (firstMove) {
|
|
970
|
+
updateInteraction(event);
|
|
971
|
+
if (interaction) {
|
|
972
|
+
cancelEvent(event);
|
|
973
|
+
}
|
|
974
|
+
} else {
|
|
975
|
+
if (interaction === 'drag') {
|
|
976
|
+
target.handleDrag(event);
|
|
977
|
+
}
|
|
978
|
+
if (interaction) {
|
|
979
|
+
cancelEvent(event);
|
|
980
|
+
target.update();
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
firstMove = false;
|
|
984
|
+
}
|
|
985
|
+
}, {
|
|
986
|
+
passive: false
|
|
987
|
+
});
|
|
988
|
+
el.addEventListener('mouseup', function (event) {
|
|
989
|
+
if (target.enabled) {
|
|
990
|
+
fingers = 0;
|
|
991
|
+
updateInteraction(event);
|
|
992
|
+
}
|
|
993
|
+
}, {
|
|
994
|
+
passive: true
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
return PinchZoom;
|
|
999
|
+
};
|
|
1000
|
+
var PinchZoom = definePinchZoom();
|
|
1001
|
+
|
|
1002
|
+
var css = {"scrolling":"PhotoGallery__scrolling___q1DKc","root":"PhotoGallery__root___KiBKq","layout":"PhotoGallery__layout___JBDok","layoutHeader":"PhotoGallery__layoutHeader___tVG4b","layoutContent":"PhotoGallery__layoutContent___O43ff","layoutSection":"PhotoGallery__layoutSection___CvZb6","layoutAside":"PhotoGallery__layoutAside___fdKgJ","header":"PhotoGallery__header___xfAad","headerTitle":"PhotoGallery__headerTitle___QiOEy","headerClose":"PhotoGallery__headerClose___qdl3x","mainPhotoScrollControls":"PhotoGallery__mainPhotoScrollControls___PeY3Y","mainPhoto":"PhotoGallery__mainPhoto___QIMHy PhotoGallery__scrolling___q1DKc","mainPhotoItem":"PhotoGallery__mainPhotoItem___aZCyk","mainPhotoImage":"PhotoGallery__mainPhotoImage___2aEr5","mainPhotoIframe":"PhotoGallery__mainPhotoIframe___kThdT","preview":"PhotoGallery__preview___F-k0z PhotoGallery__scrolling___q1DKc","previewItem":"PhotoGallery__previewItem___jf683","previewButton":"PhotoGallery__previewButton___VAXOP","previewImage":"PhotoGallery__previewImage___Mx2Y-","videoPlayLabel":"PhotoGallery__videoPlayLabel___jQiDN","videoPlayLabelIcon":"PhotoGallery__videoPlayLabelIcon___wSdjd","enter":"PhotoGallery__enter___Lnosr","exit":"PhotoGallery__exit___NW-xY","enterActive":"PhotoGallery__enterActive___LrirU","exitActive":"PhotoGallery__exitActive___L6st-"};
|
|
1003
|
+
|
|
1004
|
+
var MainPhotosImage = /*#__PURE__*/React__namespace.forwardRef(function (_ref, ref) {
|
|
1005
|
+
var src = _ref.src,
|
|
1006
|
+
video = _ref.video;
|
|
1007
|
+
var videoIframeRef = React__namespace.useRef(null);
|
|
1008
|
+
var pinchZoomRef = React__namespace.useRef(null);
|
|
1009
|
+
var imgRef = React__namespace.useRef(null);
|
|
1010
|
+
var isVideo = !!video;
|
|
1011
|
+
var reset = function reset() {
|
|
1012
|
+
var _pinchZoomRef$current, _videoIframeRef$curre;
|
|
1013
|
+
(_pinchZoomRef$current = pinchZoomRef.current) === null || _pinchZoomRef$current === void 0 ? void 0 : _pinchZoomRef$current.reset();
|
|
1014
|
+
(_videoIframeRef$curre = videoIframeRef.current) === null || _videoIframeRef$curre === void 0 || (_videoIframeRef$curre = _videoIframeRef$curre.contentWindow) === null || _videoIframeRef$curre === void 0 ? void 0 : _videoIframeRef$curre.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
|
|
1015
|
+
};
|
|
1016
|
+
React__namespace.useEffect(function () {
|
|
1017
|
+
requestAnimationFrame(function () {
|
|
1018
|
+
if (imgRef.current && !isVideo) {
|
|
1019
|
+
pinchZoomRef.current = new PinchZoom(imgRef.current, {
|
|
1020
|
+
draggableUnzoomed: false,
|
|
1021
|
+
animationDuration: 200
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
return function () {
|
|
1026
|
+
var _pinchZoomRef$current2;
|
|
1027
|
+
(_pinchZoomRef$current2 = pinchZoomRef.current) === null || _pinchZoomRef$current2 === void 0 ? void 0 : _pinchZoomRef$current2.destroy();
|
|
1028
|
+
};
|
|
1029
|
+
}, [video]);
|
|
1030
|
+
React__namespace.useImperativeHandle(ref, function () {
|
|
1031
|
+
return {
|
|
1032
|
+
reset: reset
|
|
1033
|
+
};
|
|
1034
|
+
}, []);
|
|
1035
|
+
if (isVideo) {
|
|
1036
|
+
return /*#__PURE__*/React__namespace.createElement("iframe", {
|
|
1037
|
+
ref: videoIframeRef,
|
|
1038
|
+
className: css.mainPhotoIframe,
|
|
1039
|
+
src: prepareVideoUrl(video),
|
|
1040
|
+
width: "100%",
|
|
1041
|
+
height: "100%",
|
|
1042
|
+
allowFullScreen: true,
|
|
1043
|
+
title: "",
|
|
1044
|
+
loading: "lazy",
|
|
1045
|
+
"data-qaid": "photo_gallery_main_video",
|
|
1046
|
+
"data-testid": "photo_gallery_main_video"
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
return /*#__PURE__*/React__namespace.createElement("img", {
|
|
1050
|
+
ref: imgRef,
|
|
1051
|
+
className: css.mainPhotoImage,
|
|
1052
|
+
src: src,
|
|
1053
|
+
width: "100%",
|
|
1054
|
+
height: "100%",
|
|
1055
|
+
alt: "",
|
|
1056
|
+
decoding: "async",
|
|
1057
|
+
loading: "lazy",
|
|
1058
|
+
"data-qaid": "photo_gallery_main_image",
|
|
1059
|
+
"data-testid": "photo_gallery_main_image"
|
|
1060
|
+
});
|
|
1061
|
+
});
|
|
1062
|
+
|
|
1063
|
+
var MainPhotos = /*#__PURE__*/React__namespace.forwardRef(function (_ref, ref) {
|
|
1064
|
+
var items = _ref.items,
|
|
1065
|
+
onChange = _ref.onChange;
|
|
1066
|
+
var mainPhotoRefs = React__namespace.useRef([]);
|
|
1067
|
+
var scrollIndex = React__namespace.useRef(0);
|
|
1068
|
+
var localScrollRef = React__namespace.useRef(null);
|
|
1069
|
+
var destroyMainPhoto = function destroyMainPhoto() {
|
|
1070
|
+
mainPhotoRefs.current.forEach(function (currentRef) {
|
|
1071
|
+
currentRef === null || currentRef === void 0 ? void 0 : currentRef.reset();
|
|
1072
|
+
});
|
|
1073
|
+
};
|
|
1074
|
+
var scrollToIndex = function scrollToIndex(index) {
|
|
1075
|
+
var _localScrollRef$curre;
|
|
1076
|
+
var isAnimate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1077
|
+
var childNode = (_localScrollRef$curre = localScrollRef.current) === null || _localScrollRef$curre === void 0 ? void 0 : _localScrollRef$curre.children[index];
|
|
1078
|
+
destroyMainPhoto();
|
|
1079
|
+
if (childNode) {
|
|
1080
|
+
scrollInToViewElement(childNode, localScrollRef.current, isAnimate);
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
React__namespace.useImperativeHandle(ref, function () {
|
|
1084
|
+
return {
|
|
1085
|
+
scrollToIndex: scrollToIndex
|
|
1086
|
+
};
|
|
1087
|
+
}, []);
|
|
1088
|
+
var onScroll = function onScroll() {
|
|
1089
|
+
if (!localScrollRef.current) return;
|
|
1090
|
+
var indexFromScroll = getIndexFromScroll(localScrollRef.current, items.length);
|
|
1091
|
+
if (scrollIndex.current !== indexFromScroll) {
|
|
1092
|
+
scrollIndex.current = indexFromScroll;
|
|
1093
|
+
onChange(indexFromScroll);
|
|
1094
|
+
destroyMainPhoto();
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
return /*#__PURE__*/React__namespace.createElement(ScrollControls.ScrollControls, {
|
|
1098
|
+
ref: localScrollRef,
|
|
1099
|
+
className: css.mainPhotoScrollControls,
|
|
1100
|
+
showOnHover: true,
|
|
1101
|
+
hideOnDisabled: true
|
|
1102
|
+
}, function (scrollRef) {
|
|
1103
|
+
return /*#__PURE__*/React__namespace.createElement(TouchScrollable, {
|
|
1104
|
+
scrollRef: scrollRef,
|
|
1105
|
+
isActive: true
|
|
1106
|
+
}, /*#__PURE__*/React__namespace.createElement("div", {
|
|
1107
|
+
ref: scrollRef,
|
|
1108
|
+
className: css.mainPhoto,
|
|
1109
|
+
onScroll: onScroll
|
|
1110
|
+
}, items.map(function (_ref2, index) {
|
|
1111
|
+
var src = _ref2.src,
|
|
1112
|
+
video = _ref2.video;
|
|
1113
|
+
return /*#__PURE__*/React__namespace.createElement("div", {
|
|
1114
|
+
key: index,
|
|
1115
|
+
className: css.mainPhotoItem,
|
|
1116
|
+
"data-qaid": "photo_gallery_main_item",
|
|
1117
|
+
"data-testid": "photo_gallery_main_item"
|
|
1118
|
+
}, /*#__PURE__*/React__namespace.createElement(MainPhotosImage, {
|
|
1119
|
+
ref: function ref(el) {
|
|
1120
|
+
return mainPhotoRefs.current[index] = el;
|
|
1121
|
+
},
|
|
1122
|
+
src: src,
|
|
1123
|
+
video: video
|
|
1124
|
+
}));
|
|
1125
|
+
})));
|
|
1126
|
+
});
|
|
1127
|
+
});
|
|
1128
|
+
|
|
1129
|
+
var PreviewPhotos = /*#__PURE__*/React__namespace.forwardRef(function (_ref, ref) {
|
|
1130
|
+
var items = _ref.items,
|
|
1131
|
+
selectedIndex = _ref.selectedIndex,
|
|
1132
|
+
onChange = _ref.onChange;
|
|
1133
|
+
var localScrollRef = React__namespace.useRef(null);
|
|
1134
|
+
var scrollToIndex = function scrollToIndex(index) {
|
|
1135
|
+
var _localScrollRef$curre;
|
|
1136
|
+
var isAnimate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1137
|
+
var childNode = (_localScrollRef$curre = localScrollRef.current) === null || _localScrollRef$curre === void 0 ? void 0 : _localScrollRef$curre.children[index];
|
|
1138
|
+
if (childNode) {
|
|
1139
|
+
scrollInToViewElement(childNode, localScrollRef.current, isAnimate);
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
React__namespace.useImperativeHandle(ref, function () {
|
|
1143
|
+
return {
|
|
1144
|
+
scrollToIndex: scrollToIndex
|
|
1145
|
+
};
|
|
1146
|
+
}, []);
|
|
1147
|
+
var _onClick = function onClick(index) {
|
|
1148
|
+
onChange(index);
|
|
1149
|
+
};
|
|
1150
|
+
return /*#__PURE__*/React__namespace.createElement(TouchScrollable, {
|
|
1151
|
+
scrollRef: localScrollRef,
|
|
1152
|
+
isActive: true
|
|
1153
|
+
}, /*#__PURE__*/React__namespace.createElement("div", {
|
|
1154
|
+
ref: localScrollRef,
|
|
1155
|
+
className: css.preview
|
|
1156
|
+
}, items.map(function (_ref2, index) {
|
|
1157
|
+
var src = _ref2.src,
|
|
1158
|
+
video = _ref2.video;
|
|
1159
|
+
return /*#__PURE__*/React__namespace.createElement("div", {
|
|
1160
|
+
key: index,
|
|
1161
|
+
className: css.previewItem,
|
|
1162
|
+
"data-qaid": "photo_gallery_preview_item",
|
|
1163
|
+
"data-testid": "photo_gallery_preview_item"
|
|
1164
|
+
}, /*#__PURE__*/React__namespace.createElement("button", {
|
|
1165
|
+
className: css.previewButton,
|
|
1166
|
+
type: "button",
|
|
1167
|
+
onClick: function onClick() {
|
|
1168
|
+
return _onClick(index);
|
|
1169
|
+
},
|
|
1170
|
+
disabled: selectedIndex === index,
|
|
1171
|
+
"data-qaid": "photo_gallery_preview_button",
|
|
1172
|
+
"data-testid": "photo_gallery_preview_button"
|
|
1173
|
+
}, /*#__PURE__*/React__namespace.createElement("img", {
|
|
1174
|
+
className: css.previewImage,
|
|
1175
|
+
src: src,
|
|
1176
|
+
width: 58,
|
|
1177
|
+
height: 58,
|
|
1178
|
+
alt: "",
|
|
1179
|
+
decoding: "async",
|
|
1180
|
+
loading: "lazy",
|
|
1181
|
+
"data-qaid": "photo_gallery_preview_image",
|
|
1182
|
+
"data-testid": "photo_gallery_preview_image"
|
|
1183
|
+
}), !!video && /*#__PURE__*/React__namespace.createElement("div", {
|
|
1184
|
+
className: css.videoPlayLabel,
|
|
1185
|
+
"data-qaid": "photo_gallery_preview_play",
|
|
1186
|
+
"data-testid": "photo_gallery_preview_play"
|
|
1187
|
+
}, /*#__PURE__*/React__namespace.createElement(Icon.Icon, {
|
|
1188
|
+
className: css.videoPlayLabelIcon,
|
|
1189
|
+
"icon-as": Play.SvgPlay
|
|
1190
|
+
}))));
|
|
1191
|
+
})));
|
|
1192
|
+
});
|
|
1193
|
+
|
|
1194
|
+
var _templateObject;
|
|
1195
|
+
var Header = function Header(_ref) {
|
|
1196
|
+
var title = _ref.title,
|
|
1197
|
+
onClose = _ref.onClose,
|
|
1198
|
+
selectedIndex = _ref.selectedIndex,
|
|
1199
|
+
itemsLength = _ref.itemsLength;
|
|
1200
|
+
var _useBodyTTag = useBodyTTag.useBodyTTag(),
|
|
1201
|
+
t = _useBodyTTag.t;
|
|
1202
|
+
var visibleSelectedIndex = selectedIndex + 1;
|
|
1203
|
+
var visibleTitle = t(_templateObject || (_templateObject = _taggedTemplateLiteral(["\u0424\u043E\u0442\u043E ", " \u0438\u0437 ", ""])), visibleSelectedIndex, itemsLength);
|
|
1204
|
+
return /*#__PURE__*/React__namespace.createElement("div", {
|
|
1205
|
+
className: css.header
|
|
1206
|
+
}, /*#__PURE__*/React__namespace.createElement("div", {
|
|
1207
|
+
className: css.headerTitle,
|
|
1208
|
+
"data-qaid": "photo_gallery_title",
|
|
1209
|
+
"data-testid": "photo_gallery_title"
|
|
1210
|
+
}, title || visibleTitle), /*#__PURE__*/React__namespace.createElement("div", {
|
|
1211
|
+
className: css.headerClose
|
|
1212
|
+
}, /*#__PURE__*/React__namespace.createElement(Button.Button, {
|
|
1213
|
+
"button-padding": "xxs",
|
|
1214
|
+
"button-theme": "black-inherit",
|
|
1215
|
+
type: "button",
|
|
1216
|
+
onClick: onClose,
|
|
1217
|
+
"data-qaid": "photo_gallery_close_button",
|
|
1218
|
+
"data-testid": "photo_gallery_close_button"
|
|
1219
|
+
}, /*#__PURE__*/React__namespace.createElement(Icon.Icon, {
|
|
1220
|
+
"icon-as": Close.SvgClose,
|
|
1221
|
+
style: {
|
|
1222
|
+
width: 24,
|
|
1223
|
+
height: 24
|
|
1224
|
+
}
|
|
1225
|
+
}))));
|
|
1226
|
+
};
|
|
1227
|
+
|
|
1228
|
+
var PhotoGallery = function PhotoGallery(_ref) {
|
|
1229
|
+
var isOpen = _ref.isOpen,
|
|
1230
|
+
title = _ref.title,
|
|
1231
|
+
_ref$visibleIndex = _ref.visibleIndex,
|
|
1232
|
+
visibleIndex = _ref$visibleIndex === void 0 ? 0 : _ref$visibleIndex,
|
|
1233
|
+
items = _ref.items,
|
|
1234
|
+
onClose = _ref.onClose,
|
|
1235
|
+
onChange = _ref.onChange;
|
|
1236
|
+
var refIsAllowChangePreviewPhoto = React__namespace.useRef(true);
|
|
1237
|
+
var refMainPhotos = React__namespace.useRef(null);
|
|
1238
|
+
var refPreviewPhotos = React__namespace.useRef(null);
|
|
1239
|
+
var _React$useState = React__namespace.useState(visibleIndex),
|
|
1240
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
1241
|
+
selectedIndex = _React$useState2[0],
|
|
1242
|
+
setSelectedIndex = _React$useState2[1];
|
|
1243
|
+
React__namespace.useEffect(function () {
|
|
1244
|
+
if (isOpen && typeof onChange === 'function') {
|
|
1245
|
+
onChange(selectedIndex);
|
|
1246
|
+
}
|
|
1247
|
+
}, [selectedIndex]);
|
|
1248
|
+
React__namespace.useEffect(function () {
|
|
1249
|
+
if (isOpen) {
|
|
1250
|
+
var _refPreviewPhotos$cur, _refMainPhotos$curren;
|
|
1251
|
+
setSelectedIndex(visibleIndex);
|
|
1252
|
+
(_refPreviewPhotos$cur = refPreviewPhotos.current) === null || _refPreviewPhotos$cur === void 0 ? void 0 : _refPreviewPhotos$cur.scrollToIndex(visibleIndex, false);
|
|
1253
|
+
(_refMainPhotos$curren = refMainPhotos.current) === null || _refMainPhotos$curren === void 0 ? void 0 : _refMainPhotos$curren.scrollToIndex(visibleIndex, false);
|
|
1254
|
+
}
|
|
1255
|
+
}, [isOpen]);
|
|
1256
|
+
React__namespace.useEffect(function () {
|
|
1257
|
+
if (!isOpen) return function () {};
|
|
1258
|
+
var timer = null;
|
|
1259
|
+
var clearTimeoutHandle = function clearTimeoutHandle() {
|
|
1260
|
+
if (timer) {
|
|
1261
|
+
clearTimeout(timer);
|
|
1262
|
+
}
|
|
1263
|
+
};
|
|
1264
|
+
var resizeHandle = function resizeHandle() {
|
|
1265
|
+
clearTimeoutHandle();
|
|
1266
|
+
timer = setTimeout(function () {
|
|
1267
|
+
var _refPreviewPhotos$cur2, _refMainPhotos$curren2;
|
|
1268
|
+
(_refPreviewPhotos$cur2 = refPreviewPhotos.current) === null || _refPreviewPhotos$cur2 === void 0 ? void 0 : _refPreviewPhotos$cur2.scrollToIndex(selectedIndex, false);
|
|
1269
|
+
(_refMainPhotos$curren2 = refMainPhotos.current) === null || _refMainPhotos$curren2 === void 0 ? void 0 : _refMainPhotos$curren2.scrollToIndex(selectedIndex, false);
|
|
1270
|
+
}, 100);
|
|
1271
|
+
};
|
|
1272
|
+
window.addEventListener('resize', resizeHandle);
|
|
1273
|
+
window.matchMedia('(orientation: portrait)').addEventListener('change', resizeHandle);
|
|
1274
|
+
return function () {
|
|
1275
|
+
clearTimeoutHandle();
|
|
1276
|
+
window.removeEventListener('resize', resizeHandle);
|
|
1277
|
+
window.matchMedia('(orientation: portrait)').removeEventListener('change', resizeHandle);
|
|
1278
|
+
};
|
|
1279
|
+
}, [isOpen, selectedIndex]);
|
|
1280
|
+
var onChangePreviewPhoto = function onChangePreviewPhoto(index) {
|
|
1281
|
+
var _refPreviewPhotos$cur3, _refMainPhotos$curren3;
|
|
1282
|
+
refIsAllowChangePreviewPhoto.current = false;
|
|
1283
|
+
setSelectedIndex(index);
|
|
1284
|
+
(_refPreviewPhotos$cur3 = refPreviewPhotos.current) === null || _refPreviewPhotos$cur3 === void 0 ? void 0 : _refPreviewPhotos$cur3.scrollToIndex(index);
|
|
1285
|
+
(_refMainPhotos$curren3 = refMainPhotos.current) === null || _refMainPhotos$curren3 === void 0 ? void 0 : _refMainPhotos$curren3.scrollToIndex(index);
|
|
1286
|
+
};
|
|
1287
|
+
var onChangeMainPhoto = function onChangeMainPhoto(index) {
|
|
1288
|
+
if (refIsAllowChangePreviewPhoto.current) {
|
|
1289
|
+
var _refPreviewPhotos$cur4;
|
|
1290
|
+
setSelectedIndex(index);
|
|
1291
|
+
(_refPreviewPhotos$cur4 = refPreviewPhotos.current) === null || _refPreviewPhotos$cur4 === void 0 ? void 0 : _refPreviewPhotos$cur4.scrollToIndex(index);
|
|
1292
|
+
}
|
|
1293
|
+
if (!refIsAllowChangePreviewPhoto.current && selectedIndex === index) {
|
|
1294
|
+
refIsAllowChangePreviewPhoto.current = true;
|
|
1295
|
+
}
|
|
1296
|
+
};
|
|
1297
|
+
var onPrevPhoto = function onPrevPhoto() {
|
|
1298
|
+
if (selectedIndex === 0) return;
|
|
1299
|
+
onChangePreviewPhoto(selectedIndex - 1);
|
|
1300
|
+
};
|
|
1301
|
+
var onNextPhoto = function onNextPhoto() {
|
|
1302
|
+
if (selectedIndex === items.length - 1) return;
|
|
1303
|
+
onChangePreviewPhoto(selectedIndex + 1);
|
|
1304
|
+
};
|
|
1305
|
+
var onCloseHandle = function onCloseHandle() {
|
|
1306
|
+
onClose(selectedIndex);
|
|
1307
|
+
};
|
|
1308
|
+
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(Backdrop.Backdrop, {
|
|
1309
|
+
isOpen: isOpen,
|
|
1310
|
+
onClick: onCloseHandle
|
|
1311
|
+
}), /*#__PURE__*/React__namespace.createElement(reactTransitionGroup.CSSTransition, {
|
|
1312
|
+
"in": isOpen,
|
|
1313
|
+
timeout: 240,
|
|
1314
|
+
classNames: css,
|
|
1315
|
+
unmountOnExit: true
|
|
1316
|
+
// onEnter={onOpen}
|
|
1317
|
+
// onEntered={onOpened}
|
|
1318
|
+
// onExited={onClosed}
|
|
1319
|
+
}, /*#__PURE__*/React__namespace.createElement(Portal.Portal, null, /*#__PURE__*/React__namespace.createElement("div", {
|
|
1320
|
+
className: css.root,
|
|
1321
|
+
"data-qaid": "photo_gallery",
|
|
1322
|
+
"data-testid": "photo_gallery"
|
|
1323
|
+
}, /*#__PURE__*/React__namespace.createElement(ScrollLock__default.default, null), /*#__PURE__*/React__namespace.createElement(KeyPress.KeyPress, {
|
|
1324
|
+
code: "Escape",
|
|
1325
|
+
onKeyUp: onCloseHandle
|
|
1326
|
+
}), /*#__PURE__*/React__namespace.createElement(KeyPress.KeyPress, {
|
|
1327
|
+
code: "ArrowLeft",
|
|
1328
|
+
onKeyUp: onPrevPhoto
|
|
1329
|
+
}), /*#__PURE__*/React__namespace.createElement(KeyPress.KeyPress, {
|
|
1330
|
+
code: "ArrowRight",
|
|
1331
|
+
onKeyUp: onNextPhoto
|
|
1332
|
+
}), /*#__PURE__*/React__namespace.createElement("div", {
|
|
1333
|
+
className: css.layout
|
|
1334
|
+
}, /*#__PURE__*/React__namespace.createElement("header", {
|
|
1335
|
+
className: css.layoutHeader
|
|
1336
|
+
}, /*#__PURE__*/React__namespace.createElement(Header, {
|
|
1337
|
+
title: title,
|
|
1338
|
+
selectedIndex: selectedIndex,
|
|
1339
|
+
itemsLength: items.length,
|
|
1340
|
+
onClose: onCloseHandle
|
|
1341
|
+
})), /*#__PURE__*/React__namespace.createElement("div", {
|
|
1342
|
+
className: css.layoutContent
|
|
1343
|
+
}, /*#__PURE__*/React__namespace.createElement("section", {
|
|
1344
|
+
className: css.layoutSection
|
|
1345
|
+
}, /*#__PURE__*/React__namespace.createElement(MainPhotos, {
|
|
1346
|
+
ref: refMainPhotos,
|
|
1347
|
+
items: items,
|
|
1348
|
+
onChange: onChangeMainPhoto
|
|
1349
|
+
})), /*#__PURE__*/React__namespace.createElement("aside", {
|
|
1350
|
+
className: css.layoutAside
|
|
1351
|
+
}, /*#__PURE__*/React__namespace.createElement(PreviewPhotos, {
|
|
1352
|
+
ref: refPreviewPhotos,
|
|
1353
|
+
items: items,
|
|
1354
|
+
selectedIndex: selectedIndex,
|
|
1355
|
+
onChange: onChangePreviewPhoto
|
|
1356
|
+
}))))))));
|
|
1357
|
+
};
|
|
1358
|
+
|
|
1359
|
+
exports.PhotoGallery = PhotoGallery;
|
|
1360
|
+
|
|
1361
|
+
require('./style.development.v2.css');
|