react-pic-gallery 1.3.9 → 1.5.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/README.md +26 -21
- package/dist/react-pic-gallery.es.js +2012 -0
- package/dist/react-pic-gallery.umd.js +67 -0
- package/package.json +41 -47
- package/dist/CircularLoading.d.ts +0 -1
- package/dist/ImgLazyLoading.d.ts +0 -7
- package/dist/ImgLightbox.d.ts +0 -10
- package/dist/example/src/setupTests.d.ts +0 -1
- package/dist/index.d.ts +0 -29
- package/dist/index.modern.js +0 -342
- package/dist/index.modern.js.map +0 -1
- package/dist/src/index.d.ts +0 -26
- package/dist/styles.d.ts +0 -74
|
@@ -0,0 +1,2012 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import React, { useState, useImperativeHandle, Component, useContext, useRef, useEffect, useCallback } from "react";
|
|
21
|
+
var jsxRuntime = { exports: {} };
|
|
22
|
+
var reactJsxRuntime_production_min = {};
|
|
23
|
+
/*
|
|
24
|
+
object-assign
|
|
25
|
+
(c) Sindre Sorhus
|
|
26
|
+
@license MIT
|
|
27
|
+
*/
|
|
28
|
+
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
|
29
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
30
|
+
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
|
31
|
+
function toObject(val) {
|
|
32
|
+
if (val === null || val === void 0) {
|
|
33
|
+
throw new TypeError("Object.assign cannot be called with null or undefined");
|
|
34
|
+
}
|
|
35
|
+
return Object(val);
|
|
36
|
+
}
|
|
37
|
+
function shouldUseNative() {
|
|
38
|
+
try {
|
|
39
|
+
if (!Object.assign) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
var test1 = new String("abc");
|
|
43
|
+
test1[5] = "de";
|
|
44
|
+
if (Object.getOwnPropertyNames(test1)[0] === "5") {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
var test2 = {};
|
|
48
|
+
for (var i = 0; i < 10; i++) {
|
|
49
|
+
test2["_" + String.fromCharCode(i)] = i;
|
|
50
|
+
}
|
|
51
|
+
var order2 = Object.getOwnPropertyNames(test2).map(function(n2) {
|
|
52
|
+
return test2[n2];
|
|
53
|
+
});
|
|
54
|
+
if (order2.join("") !== "0123456789") {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
var test3 = {};
|
|
58
|
+
"abcdefghijklmnopqrst".split("").forEach(function(letter) {
|
|
59
|
+
test3[letter] = letter;
|
|
60
|
+
});
|
|
61
|
+
if (Object.keys(Object.assign({}, test3)).join("") !== "abcdefghijklmnopqrst") {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
} catch (err) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
shouldUseNative() ? Object.assign : function(target, source) {
|
|
70
|
+
var from;
|
|
71
|
+
var to = toObject(target);
|
|
72
|
+
var symbols;
|
|
73
|
+
for (var s = 1; s < arguments.length; s++) {
|
|
74
|
+
from = Object(arguments[s]);
|
|
75
|
+
for (var key in from) {
|
|
76
|
+
if (hasOwnProperty.call(from, key)) {
|
|
77
|
+
to[key] = from[key];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (getOwnPropertySymbols) {
|
|
81
|
+
symbols = getOwnPropertySymbols(from);
|
|
82
|
+
for (var i = 0; i < symbols.length; i++) {
|
|
83
|
+
if (propIsEnumerable.call(from, symbols[i])) {
|
|
84
|
+
to[symbols[i]] = from[symbols[i]];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return to;
|
|
90
|
+
};
|
|
91
|
+
/** @license React v17.0.2
|
|
92
|
+
* react-jsx-runtime.production.min.js
|
|
93
|
+
*
|
|
94
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
95
|
+
*
|
|
96
|
+
* This source code is licensed under the MIT license found in the
|
|
97
|
+
* LICENSE file in the root directory of this source tree.
|
|
98
|
+
*/
|
|
99
|
+
var f = React, g = 60103;
|
|
100
|
+
reactJsxRuntime_production_min.Fragment = 60107;
|
|
101
|
+
if (typeof Symbol === "function" && Symbol.for) {
|
|
102
|
+
var h = Symbol.for;
|
|
103
|
+
g = h("react.element");
|
|
104
|
+
reactJsxRuntime_production_min.Fragment = h("react.fragment");
|
|
105
|
+
}
|
|
106
|
+
var m = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, n = Object.prototype.hasOwnProperty, p = { key: true, ref: true, __self: true, __source: true };
|
|
107
|
+
function q(c, a, k) {
|
|
108
|
+
var b, d = {}, e = null, l = null;
|
|
109
|
+
k !== void 0 && (e = "" + k);
|
|
110
|
+
a.key !== void 0 && (e = "" + a.key);
|
|
111
|
+
a.ref !== void 0 && (l = a.ref);
|
|
112
|
+
for (b in a)
|
|
113
|
+
n.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
|
|
114
|
+
if (c && c.defaultProps)
|
|
115
|
+
for (b in a = c.defaultProps, a)
|
|
116
|
+
d[b] === void 0 && (d[b] = a[b]);
|
|
117
|
+
return { $$typeof: g, type: c, key: e, ref: l, props: d, _owner: m.current };
|
|
118
|
+
}
|
|
119
|
+
reactJsxRuntime_production_min.jsx = q;
|
|
120
|
+
reactJsxRuntime_production_min.jsxs = q;
|
|
121
|
+
{
|
|
122
|
+
jsxRuntime.exports = reactJsxRuntime_production_min;
|
|
123
|
+
}
|
|
124
|
+
const jsx = jsxRuntime.exports.jsx;
|
|
125
|
+
const jsxs = jsxRuntime.exports.jsxs;
|
|
126
|
+
var extendStatics = function(d, b) {
|
|
127
|
+
extendStatics = Object.setPrototypeOf || {
|
|
128
|
+
__proto__: []
|
|
129
|
+
} instanceof Array && function(d2, b2) {
|
|
130
|
+
d2.__proto__ = b2;
|
|
131
|
+
} || function(d2, b2) {
|
|
132
|
+
for (var p2 in b2)
|
|
133
|
+
if (Object.prototype.hasOwnProperty.call(b2, p2))
|
|
134
|
+
d2[p2] = b2[p2];
|
|
135
|
+
};
|
|
136
|
+
return extendStatics(d, b);
|
|
137
|
+
};
|
|
138
|
+
function __extends(d, b) {
|
|
139
|
+
if (typeof b !== "function" && b !== null)
|
|
140
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
141
|
+
extendStatics(d, b);
|
|
142
|
+
function __() {
|
|
143
|
+
this.constructor = d;
|
|
144
|
+
}
|
|
145
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
146
|
+
}
|
|
147
|
+
var __assign = function() {
|
|
148
|
+
__assign = Object.assign || function __assign2(t) {
|
|
149
|
+
for (var s, i = 1, n2 = arguments.length; i < n2; i++) {
|
|
150
|
+
s = arguments[i];
|
|
151
|
+
for (var p2 in s)
|
|
152
|
+
if (Object.prototype.hasOwnProperty.call(s, p2))
|
|
153
|
+
t[p2] = s[p2];
|
|
154
|
+
}
|
|
155
|
+
return t;
|
|
156
|
+
};
|
|
157
|
+
return __assign.apply(this, arguments);
|
|
158
|
+
};
|
|
159
|
+
function __spreadArray(to, from, pack) {
|
|
160
|
+
if (pack || arguments.length === 2)
|
|
161
|
+
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
162
|
+
if (ar || !(i in from)) {
|
|
163
|
+
if (!ar)
|
|
164
|
+
ar = Array.prototype.slice.call(from, 0, i);
|
|
165
|
+
ar[i] = from[i];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return to.concat(ar || from);
|
|
169
|
+
}
|
|
170
|
+
var roundNumber = function(num, decimal) {
|
|
171
|
+
return Number(num.toFixed(decimal));
|
|
172
|
+
};
|
|
173
|
+
var checkIsNumber = function(num, defaultValue) {
|
|
174
|
+
return typeof num === "number" ? num : defaultValue;
|
|
175
|
+
};
|
|
176
|
+
var handleCallback = function(context, event, callback) {
|
|
177
|
+
if (callback && typeof callback === "function") {
|
|
178
|
+
callback(context, event);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
var easeOut = function(t) {
|
|
182
|
+
return -Math.cos(t * Math.PI) / 2 + 0.5;
|
|
183
|
+
};
|
|
184
|
+
var linear = function(t) {
|
|
185
|
+
return t;
|
|
186
|
+
};
|
|
187
|
+
var easeInQuad = function(t) {
|
|
188
|
+
return t * t;
|
|
189
|
+
};
|
|
190
|
+
var easeOutQuad = function(t) {
|
|
191
|
+
return t * (2 - t);
|
|
192
|
+
};
|
|
193
|
+
var easeInOutQuad = function(t) {
|
|
194
|
+
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
|
195
|
+
};
|
|
196
|
+
var easeInCubic = function(t) {
|
|
197
|
+
return t * t * t;
|
|
198
|
+
};
|
|
199
|
+
var easeOutCubic = function(t) {
|
|
200
|
+
return --t * t * t + 1;
|
|
201
|
+
};
|
|
202
|
+
var easeInOutCubic = function(t) {
|
|
203
|
+
return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
|
|
204
|
+
};
|
|
205
|
+
var easeInQuart = function(t) {
|
|
206
|
+
return t * t * t * t;
|
|
207
|
+
};
|
|
208
|
+
var easeOutQuart = function(t) {
|
|
209
|
+
return 1 - --t * t * t * t;
|
|
210
|
+
};
|
|
211
|
+
var easeInOutQuart = function(t) {
|
|
212
|
+
return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t;
|
|
213
|
+
};
|
|
214
|
+
var easeInQuint = function(t) {
|
|
215
|
+
return t * t * t * t * t;
|
|
216
|
+
};
|
|
217
|
+
var easeOutQuint = function(t) {
|
|
218
|
+
return 1 + --t * t * t * t * t;
|
|
219
|
+
};
|
|
220
|
+
var easeInOutQuint = function(t) {
|
|
221
|
+
return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t;
|
|
222
|
+
};
|
|
223
|
+
var animations = {
|
|
224
|
+
easeOut,
|
|
225
|
+
linear,
|
|
226
|
+
easeInQuad,
|
|
227
|
+
easeOutQuad,
|
|
228
|
+
easeInOutQuad,
|
|
229
|
+
easeInCubic,
|
|
230
|
+
easeOutCubic,
|
|
231
|
+
easeInOutCubic,
|
|
232
|
+
easeInQuart,
|
|
233
|
+
easeOutQuart,
|
|
234
|
+
easeInOutQuart,
|
|
235
|
+
easeInQuint,
|
|
236
|
+
easeOutQuint,
|
|
237
|
+
easeInOutQuint
|
|
238
|
+
};
|
|
239
|
+
var handleCancelAnimationFrame = function(animation) {
|
|
240
|
+
if (typeof animation === "number") {
|
|
241
|
+
cancelAnimationFrame(animation);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
var handleCancelAnimation = function(contextInstance) {
|
|
245
|
+
if (!contextInstance.mounted)
|
|
246
|
+
return;
|
|
247
|
+
handleCancelAnimationFrame(contextInstance.animation);
|
|
248
|
+
contextInstance.animate = false;
|
|
249
|
+
contextInstance.animation = null;
|
|
250
|
+
contextInstance.velocity = null;
|
|
251
|
+
};
|
|
252
|
+
function handleSetupAnimation(contextInstance, animationName, animationTime, callback) {
|
|
253
|
+
if (!contextInstance.mounted)
|
|
254
|
+
return;
|
|
255
|
+
var startTime = new Date().getTime();
|
|
256
|
+
var lastStep = 1;
|
|
257
|
+
handleCancelAnimation(contextInstance);
|
|
258
|
+
contextInstance.animation = function() {
|
|
259
|
+
if (!contextInstance.mounted) {
|
|
260
|
+
return handleCancelAnimationFrame(contextInstance.animation);
|
|
261
|
+
}
|
|
262
|
+
var frameTime = new Date().getTime() - startTime;
|
|
263
|
+
var animationProgress = frameTime / animationTime;
|
|
264
|
+
var animationType = animations[animationName];
|
|
265
|
+
var step = animationType(animationProgress);
|
|
266
|
+
if (frameTime >= animationTime) {
|
|
267
|
+
callback(lastStep);
|
|
268
|
+
contextInstance.animation = null;
|
|
269
|
+
} else if (contextInstance.animation) {
|
|
270
|
+
callback(step);
|
|
271
|
+
requestAnimationFrame(contextInstance.animation);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
requestAnimationFrame(contextInstance.animation);
|
|
275
|
+
}
|
|
276
|
+
function animate(contextInstance, targetState, animationTime, animationName) {
|
|
277
|
+
var isValid = isValidTargetState(targetState);
|
|
278
|
+
if (!contextInstance.mounted || !isValid)
|
|
279
|
+
return;
|
|
280
|
+
var setTransformState = contextInstance.setTransformState;
|
|
281
|
+
var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
282
|
+
var scaleDiff = targetState.scale - scale;
|
|
283
|
+
var positionXDiff = targetState.positionX - positionX;
|
|
284
|
+
var positionYDiff = targetState.positionY - positionY;
|
|
285
|
+
if (animationTime === 0) {
|
|
286
|
+
setTransformState(targetState.scale, targetState.positionX, targetState.positionY);
|
|
287
|
+
} else {
|
|
288
|
+
handleSetupAnimation(contextInstance, animationName, animationTime, function(step) {
|
|
289
|
+
var newScale = scale + scaleDiff * step;
|
|
290
|
+
var newPositionX = positionX + positionXDiff * step;
|
|
291
|
+
var newPositionY = positionY + positionYDiff * step;
|
|
292
|
+
setTransformState(newScale, newPositionX, newPositionY);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function isValidTargetState(targetState) {
|
|
297
|
+
var scale = targetState.scale, positionX = targetState.positionX, positionY = targetState.positionY;
|
|
298
|
+
if (isNaN(scale) || isNaN(positionX) || isNaN(positionY)) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
function getComponentsSizes(wrapperComponent, contentComponent, newScale) {
|
|
304
|
+
var wrapperWidth = wrapperComponent.offsetWidth;
|
|
305
|
+
var wrapperHeight = wrapperComponent.offsetHeight;
|
|
306
|
+
var contentWidth = contentComponent.offsetWidth;
|
|
307
|
+
var contentHeight = contentComponent.offsetHeight;
|
|
308
|
+
var newContentWidth = contentWidth * newScale;
|
|
309
|
+
var newContentHeight = contentHeight * newScale;
|
|
310
|
+
var newDiffWidth = wrapperWidth - newContentWidth;
|
|
311
|
+
var newDiffHeight = wrapperHeight - newContentHeight;
|
|
312
|
+
return {
|
|
313
|
+
wrapperWidth,
|
|
314
|
+
wrapperHeight,
|
|
315
|
+
newContentWidth,
|
|
316
|
+
newDiffWidth,
|
|
317
|
+
newContentHeight,
|
|
318
|
+
newDiffHeight
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
var getBounds = function(wrapperWidth, newContentWidth, diffWidth, wrapperHeight, newContentHeight, diffHeight, centerZoomedOut) {
|
|
322
|
+
var scaleWidthFactor = wrapperWidth > newContentWidth ? diffWidth * (centerZoomedOut ? 1 : 0.5) : 0;
|
|
323
|
+
var scaleHeightFactor = wrapperHeight > newContentHeight ? diffHeight * (centerZoomedOut ? 1 : 0.5) : 0;
|
|
324
|
+
var minPositionX = wrapperWidth - newContentWidth - scaleWidthFactor;
|
|
325
|
+
var maxPositionX = scaleWidthFactor;
|
|
326
|
+
var minPositionY = wrapperHeight - newContentHeight - scaleHeightFactor;
|
|
327
|
+
var maxPositionY = scaleHeightFactor;
|
|
328
|
+
return {
|
|
329
|
+
minPositionX,
|
|
330
|
+
maxPositionX,
|
|
331
|
+
minPositionY,
|
|
332
|
+
maxPositionY
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
var calculateBounds = function(contextInstance, newScale) {
|
|
336
|
+
var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
337
|
+
var centerZoomedOut = contextInstance.setup.centerZoomedOut;
|
|
338
|
+
if (!wrapperComponent || !contentComponent) {
|
|
339
|
+
throw new Error("Components are not mounted");
|
|
340
|
+
}
|
|
341
|
+
var _a = getComponentsSizes(wrapperComponent, contentComponent, newScale), wrapperWidth = _a.wrapperWidth, wrapperHeight = _a.wrapperHeight, newContentWidth = _a.newContentWidth, newDiffWidth = _a.newDiffWidth, newContentHeight = _a.newContentHeight, newDiffHeight = _a.newDiffHeight;
|
|
342
|
+
var bounds = getBounds(wrapperWidth, newContentWidth, newDiffWidth, wrapperHeight, newContentHeight, newDiffHeight, Boolean(centerZoomedOut));
|
|
343
|
+
return bounds;
|
|
344
|
+
};
|
|
345
|
+
var handleCalculateBounds = function(contextInstance, newScale) {
|
|
346
|
+
var bounds = calculateBounds(contextInstance, newScale);
|
|
347
|
+
contextInstance.bounds = bounds;
|
|
348
|
+
return bounds;
|
|
349
|
+
};
|
|
350
|
+
function getMouseBoundedPosition(positionX, positionY, bounds, limitToBounds, paddingValueX, paddingValueY, wrapperComponent) {
|
|
351
|
+
var minPositionX = bounds.minPositionX, minPositionY = bounds.minPositionY, maxPositionX = bounds.maxPositionX, maxPositionY = bounds.maxPositionY;
|
|
352
|
+
var paddingX = 0;
|
|
353
|
+
var paddingY = 0;
|
|
354
|
+
if (wrapperComponent) {
|
|
355
|
+
paddingX = paddingValueX;
|
|
356
|
+
paddingY = paddingValueY;
|
|
357
|
+
}
|
|
358
|
+
var x = boundLimiter(positionX, minPositionX - paddingX, maxPositionX + paddingX, limitToBounds);
|
|
359
|
+
var y = boundLimiter(positionY, minPositionY - paddingY, maxPositionY + paddingY, limitToBounds);
|
|
360
|
+
return {
|
|
361
|
+
x,
|
|
362
|
+
y
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
var boundLimiter = function(value, minBound, maxBound, isActive) {
|
|
366
|
+
if (!isActive)
|
|
367
|
+
return roundNumber(value, 2);
|
|
368
|
+
if (value < minBound)
|
|
369
|
+
return roundNumber(minBound, 2);
|
|
370
|
+
if (value > maxBound)
|
|
371
|
+
return roundNumber(maxBound, 2);
|
|
372
|
+
return roundNumber(value, 2);
|
|
373
|
+
};
|
|
374
|
+
function handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale, bounds, limitToBounds) {
|
|
375
|
+
var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
376
|
+
var scaleDifference = newScale - scale;
|
|
377
|
+
if (typeof mouseX !== "number" || typeof mouseY !== "number") {
|
|
378
|
+
console.error("Mouse X and Y position were not provided!");
|
|
379
|
+
return {
|
|
380
|
+
x: positionX,
|
|
381
|
+
y: positionY
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
var calculatedPositionX = positionX - mouseX * scaleDifference;
|
|
385
|
+
var calculatedPositionY = positionY - mouseY * scaleDifference;
|
|
386
|
+
var newPositions = getMouseBoundedPosition(calculatedPositionX, calculatedPositionY, bounds, limitToBounds, 0, 0, null);
|
|
387
|
+
return newPositions;
|
|
388
|
+
}
|
|
389
|
+
function checkZoomBounds(zoom, minScale, maxScale, zoomPadding, enablePadding) {
|
|
390
|
+
var scalePadding = enablePadding ? zoomPadding : 0;
|
|
391
|
+
var minScaleWithPadding = minScale - scalePadding;
|
|
392
|
+
if (!isNaN(maxScale) && zoom >= maxScale)
|
|
393
|
+
return maxScale;
|
|
394
|
+
if (!isNaN(minScale) && zoom <= minScaleWithPadding)
|
|
395
|
+
return minScaleWithPadding;
|
|
396
|
+
return zoom;
|
|
397
|
+
}
|
|
398
|
+
var isPanningStartAllowed = function(contextInstance, event) {
|
|
399
|
+
var excluded = contextInstance.setup.panning.excluded;
|
|
400
|
+
var isInitialized = contextInstance.isInitialized, wrapperComponent = contextInstance.wrapperComponent;
|
|
401
|
+
var target = event.target;
|
|
402
|
+
var isWrapperChild = wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.contains(target);
|
|
403
|
+
var isAllowed = isInitialized && target && isWrapperChild;
|
|
404
|
+
if (!isAllowed)
|
|
405
|
+
return false;
|
|
406
|
+
var isExcluded = isExcludedNode(target, excluded);
|
|
407
|
+
if (isExcluded)
|
|
408
|
+
return false;
|
|
409
|
+
return true;
|
|
410
|
+
};
|
|
411
|
+
var isPanningAllowed = function(contextInstance) {
|
|
412
|
+
var isInitialized = contextInstance.isInitialized, isPanning = contextInstance.isPanning, setup = contextInstance.setup;
|
|
413
|
+
var disabled = setup.panning.disabled;
|
|
414
|
+
var isAllowed = isInitialized && isPanning && !disabled;
|
|
415
|
+
if (!isAllowed)
|
|
416
|
+
return false;
|
|
417
|
+
return true;
|
|
418
|
+
};
|
|
419
|
+
var handlePanningSetup = function(contextInstance, event) {
|
|
420
|
+
var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY;
|
|
421
|
+
contextInstance.isPanning = true;
|
|
422
|
+
var x = event.clientX;
|
|
423
|
+
var y = event.clientY;
|
|
424
|
+
contextInstance.startCoords = {
|
|
425
|
+
x: x - positionX,
|
|
426
|
+
y: y - positionY
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
var handleTouchPanningSetup = function(contextInstance, event) {
|
|
430
|
+
var touches = event.touches;
|
|
431
|
+
var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY;
|
|
432
|
+
contextInstance.isPanning = true;
|
|
433
|
+
var oneFingerTouch = touches.length === 1;
|
|
434
|
+
if (oneFingerTouch) {
|
|
435
|
+
var x = touches[0].clientX;
|
|
436
|
+
var y = touches[0].clientY;
|
|
437
|
+
contextInstance.startCoords = {
|
|
438
|
+
x: x - positionX,
|
|
439
|
+
y: y - positionY
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
function handlePanToBounds(contextInstance) {
|
|
444
|
+
var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale;
|
|
445
|
+
var _b = contextInstance.setup, disabled = _b.disabled, limitToBounds = _b.limitToBounds, centerZoomedOut = _b.centerZoomedOut;
|
|
446
|
+
var wrapperComponent = contextInstance.wrapperComponent;
|
|
447
|
+
if (disabled || !wrapperComponent || !contextInstance.bounds)
|
|
448
|
+
return;
|
|
449
|
+
var _c = contextInstance.bounds, maxPositionX = _c.maxPositionX, minPositionX = _c.minPositionX, maxPositionY = _c.maxPositionY, minPositionY = _c.minPositionY;
|
|
450
|
+
var xChanged = positionX > maxPositionX || positionX < minPositionX;
|
|
451
|
+
var yChanged = positionY > maxPositionY || positionY < minPositionY;
|
|
452
|
+
var mousePosX = positionX > maxPositionX ? wrapperComponent.offsetWidth : contextInstance.setup.minPositionX || 0;
|
|
453
|
+
var mousePosY = positionY > maxPositionY ? wrapperComponent.offsetHeight : contextInstance.setup.minPositionY || 0;
|
|
454
|
+
var _d = handleCalculateZoomPositions(contextInstance, mousePosX, mousePosY, scale, contextInstance.bounds, limitToBounds || centerZoomedOut), x = _d.x, y = _d.y;
|
|
455
|
+
return {
|
|
456
|
+
scale,
|
|
457
|
+
positionX: xChanged ? x : positionX,
|
|
458
|
+
positionY: yChanged ? y : positionY
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
function handleNewPosition(contextInstance, newPositionX, newPositionY, paddingValueX, paddingValueY) {
|
|
462
|
+
var limitToBounds = contextInstance.setup.limitToBounds;
|
|
463
|
+
var wrapperComponent = contextInstance.wrapperComponent, bounds = contextInstance.bounds;
|
|
464
|
+
var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
465
|
+
var hasPositionXChanged = newPositionX !== positionX;
|
|
466
|
+
var hasPositionYChanged = newPositionY !== positionY;
|
|
467
|
+
var hasNewPosition = !hasPositionXChanged || !hasPositionYChanged;
|
|
468
|
+
if (!wrapperComponent || hasNewPosition || !bounds) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
var _b = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, paddingValueX, paddingValueY, wrapperComponent), x = _b.x, y = _b.y;
|
|
472
|
+
contextInstance.setTransformState(scale, x, y);
|
|
473
|
+
}
|
|
474
|
+
var getPanningClientPosition = function(contextInstance, clientX, clientY) {
|
|
475
|
+
var startCoords = contextInstance.startCoords, transformState = contextInstance.transformState;
|
|
476
|
+
var panning = contextInstance.setup.panning;
|
|
477
|
+
var lockAxisX = panning.lockAxisX, lockAxisY = panning.lockAxisY;
|
|
478
|
+
var positionX = transformState.positionX, positionY = transformState.positionY;
|
|
479
|
+
if (!startCoords) {
|
|
480
|
+
return {
|
|
481
|
+
x: positionX,
|
|
482
|
+
y: positionY
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
var mouseX = clientX - startCoords.x;
|
|
486
|
+
var mouseY = clientY - startCoords.y;
|
|
487
|
+
var newPositionX = lockAxisX ? positionX : mouseX;
|
|
488
|
+
var newPositionY = lockAxisY ? positionY : mouseY;
|
|
489
|
+
return {
|
|
490
|
+
x: newPositionX,
|
|
491
|
+
y: newPositionY
|
|
492
|
+
};
|
|
493
|
+
};
|
|
494
|
+
var getPaddingValue = function(contextInstance, size) {
|
|
495
|
+
var setup = contextInstance.setup, transformState = contextInstance.transformState;
|
|
496
|
+
var scale = transformState.scale;
|
|
497
|
+
var minScale = setup.minScale;
|
|
498
|
+
if (size > 0 && scale >= minScale) {
|
|
499
|
+
return size;
|
|
500
|
+
}
|
|
501
|
+
return 0;
|
|
502
|
+
};
|
|
503
|
+
var isVelocityCalculationAllowed = function(contextInstance) {
|
|
504
|
+
var mounted = contextInstance.mounted;
|
|
505
|
+
var _a = contextInstance.setup, disabled = _a.disabled, velocityAnimation = _a.velocityAnimation;
|
|
506
|
+
var scale = contextInstance.transformState.scale;
|
|
507
|
+
var disabledVelocity = velocityAnimation.disabled;
|
|
508
|
+
var isAllowed = !disabledVelocity || scale > 1 || !disabled || mounted;
|
|
509
|
+
if (!isAllowed)
|
|
510
|
+
return false;
|
|
511
|
+
return true;
|
|
512
|
+
};
|
|
513
|
+
var isVelocityAllowed = function(contextInstance) {
|
|
514
|
+
var mounted = contextInstance.mounted, velocity = contextInstance.velocity, bounds = contextInstance.bounds;
|
|
515
|
+
var _a = contextInstance.setup, disabled = _a.disabled, velocityAnimation = _a.velocityAnimation;
|
|
516
|
+
var scale = contextInstance.transformState.scale;
|
|
517
|
+
var disabledVelocity = velocityAnimation.disabled;
|
|
518
|
+
var isAllowed = !disabledVelocity || scale > 1 || !disabled || mounted;
|
|
519
|
+
if (!isAllowed)
|
|
520
|
+
return false;
|
|
521
|
+
if (!velocity || !bounds)
|
|
522
|
+
return false;
|
|
523
|
+
return true;
|
|
524
|
+
};
|
|
525
|
+
function getVelocityMoveTime(contextInstance, velocity) {
|
|
526
|
+
var velocityAnimation = contextInstance.setup.velocityAnimation;
|
|
527
|
+
var equalToMove = velocityAnimation.equalToMove, animationTime = velocityAnimation.animationTime, sensitivity = velocityAnimation.sensitivity;
|
|
528
|
+
if (equalToMove) {
|
|
529
|
+
return animationTime * velocity * sensitivity;
|
|
530
|
+
}
|
|
531
|
+
return animationTime;
|
|
532
|
+
}
|
|
533
|
+
function getVelocityPosition(newPosition, startPosition, currentPosition, isLocked, limitToBounds, minPosition, maxPosition, minTarget, maxTarget, step) {
|
|
534
|
+
if (limitToBounds) {
|
|
535
|
+
if (startPosition > maxPosition && currentPosition > maxPosition) {
|
|
536
|
+
var calculatedPosition = maxPosition + (newPosition - maxPosition) * step;
|
|
537
|
+
if (calculatedPosition > maxTarget)
|
|
538
|
+
return maxTarget;
|
|
539
|
+
if (calculatedPosition < maxPosition)
|
|
540
|
+
return maxPosition;
|
|
541
|
+
return calculatedPosition;
|
|
542
|
+
}
|
|
543
|
+
if (startPosition < minPosition && currentPosition < minPosition) {
|
|
544
|
+
var calculatedPosition = minPosition + (newPosition - minPosition) * step;
|
|
545
|
+
if (calculatedPosition < minTarget)
|
|
546
|
+
return minTarget;
|
|
547
|
+
if (calculatedPosition > minPosition)
|
|
548
|
+
return minPosition;
|
|
549
|
+
return calculatedPosition;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if (isLocked)
|
|
553
|
+
return startPosition;
|
|
554
|
+
return boundLimiter(newPosition, minPosition, maxPosition, limitToBounds);
|
|
555
|
+
}
|
|
556
|
+
function getSizeMultiplier(wrapperComponent, equalToMove) {
|
|
557
|
+
var defaultMultiplier = 1;
|
|
558
|
+
if (equalToMove) {
|
|
559
|
+
return Math.min(defaultMultiplier, wrapperComponent.offsetWidth / window.innerWidth);
|
|
560
|
+
}
|
|
561
|
+
return defaultMultiplier;
|
|
562
|
+
}
|
|
563
|
+
function handleCalculateVelocity(contextInstance, position) {
|
|
564
|
+
var isAllowed = isVelocityCalculationAllowed(contextInstance);
|
|
565
|
+
if (!isAllowed) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
var lastMousePosition = contextInstance.lastMousePosition, velocityTime = contextInstance.velocityTime, setup = contextInstance.setup;
|
|
569
|
+
var wrapperComponent = contextInstance.wrapperComponent;
|
|
570
|
+
var equalToMove = setup.velocityAnimation.equalToMove;
|
|
571
|
+
var now = Date.now();
|
|
572
|
+
if (lastMousePosition && velocityTime && wrapperComponent) {
|
|
573
|
+
var sizeMultiplier = getSizeMultiplier(wrapperComponent, equalToMove);
|
|
574
|
+
var distanceX = position.x - lastMousePosition.x;
|
|
575
|
+
var distanceY = position.y - lastMousePosition.y;
|
|
576
|
+
var velocityX = distanceX / sizeMultiplier;
|
|
577
|
+
var velocityY = distanceY / sizeMultiplier;
|
|
578
|
+
var interval = now - velocityTime;
|
|
579
|
+
var speed = distanceX * distanceX + distanceY * distanceY;
|
|
580
|
+
var velocity = Math.sqrt(speed) / interval;
|
|
581
|
+
contextInstance.velocity = {
|
|
582
|
+
velocityX,
|
|
583
|
+
velocityY,
|
|
584
|
+
total: velocity
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
contextInstance.lastMousePosition = position;
|
|
588
|
+
contextInstance.velocityTime = now;
|
|
589
|
+
}
|
|
590
|
+
function handleVelocityPanning(contextInstance) {
|
|
591
|
+
var velocity = contextInstance.velocity, bounds = contextInstance.bounds, setup = contextInstance.setup, wrapperComponent = contextInstance.wrapperComponent;
|
|
592
|
+
var isAllowed = isVelocityAllowed(contextInstance);
|
|
593
|
+
if (!isAllowed || !velocity || !bounds || !wrapperComponent) {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
var velocityX = velocity.velocityX, velocityY = velocity.velocityY, total = velocity.total;
|
|
597
|
+
var maxPositionX = bounds.maxPositionX, minPositionX = bounds.minPositionX, maxPositionY = bounds.maxPositionY, minPositionY = bounds.minPositionY;
|
|
598
|
+
var limitToBounds = setup.limitToBounds, alignmentAnimation = setup.alignmentAnimation;
|
|
599
|
+
var zoomAnimation = setup.zoomAnimation, panning = setup.panning;
|
|
600
|
+
var lockAxisY = panning.lockAxisY, lockAxisX = panning.lockAxisX;
|
|
601
|
+
var animationType = zoomAnimation.animationType;
|
|
602
|
+
var sizeX = alignmentAnimation.sizeX, sizeY = alignmentAnimation.sizeY, velocityAlignmentTime = alignmentAnimation.velocityAlignmentTime;
|
|
603
|
+
var alignAnimationTime = velocityAlignmentTime;
|
|
604
|
+
var moveAnimationTime = getVelocityMoveTime(contextInstance, total);
|
|
605
|
+
var finalAnimationTime = Math.max(moveAnimationTime, alignAnimationTime);
|
|
606
|
+
var paddingValueX = getPaddingValue(contextInstance, sizeX);
|
|
607
|
+
var paddingValueY = getPaddingValue(contextInstance, sizeY);
|
|
608
|
+
var paddingX = paddingValueX * wrapperComponent.offsetWidth / 100;
|
|
609
|
+
var paddingY = paddingValueY * wrapperComponent.offsetHeight / 100;
|
|
610
|
+
var maxTargetX = maxPositionX + paddingX;
|
|
611
|
+
var minTargetX = minPositionX - paddingX;
|
|
612
|
+
var maxTargetY = maxPositionY + paddingY;
|
|
613
|
+
var minTargetY = minPositionY - paddingY;
|
|
614
|
+
var startState = contextInstance.transformState;
|
|
615
|
+
var startTime = new Date().getTime();
|
|
616
|
+
handleSetupAnimation(contextInstance, animationType, finalAnimationTime, function(step) {
|
|
617
|
+
var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
618
|
+
var frameTime = new Date().getTime() - startTime;
|
|
619
|
+
var animationProgress = frameTime / alignAnimationTime;
|
|
620
|
+
var alignAnimation = animations[alignmentAnimation.animationType];
|
|
621
|
+
var alignStep = 1 - alignAnimation(Math.min(1, animationProgress));
|
|
622
|
+
var customStep = 1 - step;
|
|
623
|
+
var newPositionX = positionX + velocityX * customStep;
|
|
624
|
+
var newPositionY = positionY + velocityY * customStep;
|
|
625
|
+
var currentPositionX = getVelocityPosition(newPositionX, startState.positionX, positionX, lockAxisX, limitToBounds, minPositionX, maxPositionX, minTargetX, maxTargetX, alignStep);
|
|
626
|
+
var currentPositionY = getVelocityPosition(newPositionY, startState.positionY, positionY, lockAxisY, limitToBounds, minPositionY, maxPositionY, minTargetY, maxTargetY, alignStep);
|
|
627
|
+
if (positionX !== newPositionX || positionY !== newPositionY) {
|
|
628
|
+
contextInstance.setTransformState(scale, currentPositionX, currentPositionY);
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
function handlePanningStart(contextInstance, event) {
|
|
633
|
+
var scale = contextInstance.transformState.scale;
|
|
634
|
+
handleCancelAnimation(contextInstance);
|
|
635
|
+
handleCalculateBounds(contextInstance, scale);
|
|
636
|
+
if (event.touches) {
|
|
637
|
+
handleTouchPanningSetup(contextInstance, event);
|
|
638
|
+
} else {
|
|
639
|
+
handlePanningSetup(contextInstance, event);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
function handlePanning(contextInstance, clientX, clientY) {
|
|
643
|
+
var startCoords = contextInstance.startCoords, setup = contextInstance.setup;
|
|
644
|
+
var _a = setup.alignmentAnimation, sizeX = _a.sizeX, sizeY = _a.sizeY;
|
|
645
|
+
if (!startCoords)
|
|
646
|
+
return;
|
|
647
|
+
var _b = getPanningClientPosition(contextInstance, clientX, clientY), x = _b.x, y = _b.y;
|
|
648
|
+
var paddingValueX = getPaddingValue(contextInstance, sizeX);
|
|
649
|
+
var paddingValueY = getPaddingValue(contextInstance, sizeY);
|
|
650
|
+
handleCalculateVelocity(contextInstance, {
|
|
651
|
+
x,
|
|
652
|
+
y
|
|
653
|
+
});
|
|
654
|
+
handleNewPosition(contextInstance, x, y, paddingValueX, paddingValueY);
|
|
655
|
+
}
|
|
656
|
+
function handlePanningEnd(contextInstance) {
|
|
657
|
+
if (contextInstance.isPanning) {
|
|
658
|
+
var velocityDisabled = contextInstance.setup.panning.velocityDisabled;
|
|
659
|
+
var velocity = contextInstance.velocity, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
660
|
+
contextInstance.isPanning = false;
|
|
661
|
+
contextInstance.animate = false;
|
|
662
|
+
contextInstance.animation = null;
|
|
663
|
+
var wrapperRect = wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.getBoundingClientRect();
|
|
664
|
+
var contentRect = contentComponent === null || contentComponent === void 0 ? void 0 : contentComponent.getBoundingClientRect();
|
|
665
|
+
var wrapperWidth = (wrapperRect === null || wrapperRect === void 0 ? void 0 : wrapperRect.width) || 0;
|
|
666
|
+
var wrapperHeight = (wrapperRect === null || wrapperRect === void 0 ? void 0 : wrapperRect.height) || 0;
|
|
667
|
+
var contentWidth = (contentRect === null || contentRect === void 0 ? void 0 : contentRect.width) || 0;
|
|
668
|
+
var contentHeight = (contentRect === null || contentRect === void 0 ? void 0 : contentRect.height) || 0;
|
|
669
|
+
var isZoomed = wrapperWidth < contentWidth || wrapperHeight < contentHeight;
|
|
670
|
+
var shouldAnimate = !velocityDisabled && velocity && (velocity === null || velocity === void 0 ? void 0 : velocity.total) > 0.1 && isZoomed;
|
|
671
|
+
if (shouldAnimate) {
|
|
672
|
+
handleVelocityPanning(contextInstance);
|
|
673
|
+
} else {
|
|
674
|
+
handleAlignToBounds(contextInstance);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function handleAlignToBounds(contextInstance) {
|
|
679
|
+
var scale = contextInstance.transformState.scale;
|
|
680
|
+
var _a = contextInstance.setup, minScale = _a.minScale, alignmentAnimation = _a.alignmentAnimation;
|
|
681
|
+
var disabled = alignmentAnimation.disabled, sizeX = alignmentAnimation.sizeX, sizeY = alignmentAnimation.sizeY, animationTime = alignmentAnimation.animationTime, animationType = alignmentAnimation.animationType;
|
|
682
|
+
var isDisabled = disabled || scale < minScale || !sizeX && !sizeY;
|
|
683
|
+
if (isDisabled)
|
|
684
|
+
return;
|
|
685
|
+
var targetState = handlePanToBounds(contextInstance);
|
|
686
|
+
if (targetState) {
|
|
687
|
+
animate(contextInstance, targetState, animationTime, animationType);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
function handleAlignToScaleBounds(contextInstance, mousePositionX, mousePositionY) {
|
|
691
|
+
var scale = contextInstance.transformState.scale;
|
|
692
|
+
var wrapperComponent = contextInstance.wrapperComponent;
|
|
693
|
+
var _a = contextInstance.setup, minScale = _a.minScale, limitToBounds = _a.limitToBounds, zoomAnimation = _a.zoomAnimation;
|
|
694
|
+
var disabled = zoomAnimation.disabled, animationTime = zoomAnimation.animationTime, animationType = zoomAnimation.animationType;
|
|
695
|
+
var isDisabled = disabled || scale >= minScale;
|
|
696
|
+
if (scale >= 1 || limitToBounds) {
|
|
697
|
+
handleAlignToBounds(contextInstance);
|
|
698
|
+
}
|
|
699
|
+
if (isDisabled || !wrapperComponent || !contextInstance.mounted)
|
|
700
|
+
return;
|
|
701
|
+
var mouseX = mousePositionX || wrapperComponent.offsetWidth / 2;
|
|
702
|
+
var mouseY = mousePositionY || wrapperComponent.offsetHeight / 2;
|
|
703
|
+
var targetState = handleZoomToPoint(contextInstance, minScale, mouseX, mouseY);
|
|
704
|
+
if (targetState) {
|
|
705
|
+
animate(contextInstance, targetState, animationTime, animationType);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
function handleZoomToPoint(contextInstance, scale, mouseX, mouseY) {
|
|
709
|
+
var _a = contextInstance.setup, minScale = _a.minScale, maxScale = _a.maxScale, limitToBounds = _a.limitToBounds;
|
|
710
|
+
var newScale = checkZoomBounds(roundNumber(scale, 2), minScale, maxScale, 0, false);
|
|
711
|
+
var bounds = handleCalculateBounds(contextInstance, newScale);
|
|
712
|
+
var _b = handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale, bounds, limitToBounds), x = _b.x, y = _b.y;
|
|
713
|
+
return {
|
|
714
|
+
scale: newScale,
|
|
715
|
+
positionX: x,
|
|
716
|
+
positionY: y
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
var initialState = {
|
|
720
|
+
previousScale: 1,
|
|
721
|
+
scale: 1,
|
|
722
|
+
positionX: 0,
|
|
723
|
+
positionY: 0
|
|
724
|
+
};
|
|
725
|
+
var contextInitialState = __assign(__assign({}, initialState), {
|
|
726
|
+
setComponents: function() {
|
|
727
|
+
return void 0;
|
|
728
|
+
},
|
|
729
|
+
contextInstance: null
|
|
730
|
+
});
|
|
731
|
+
var initialSetup = {
|
|
732
|
+
disabled: false,
|
|
733
|
+
minPositionX: null,
|
|
734
|
+
maxPositionX: null,
|
|
735
|
+
minPositionY: null,
|
|
736
|
+
maxPositionY: null,
|
|
737
|
+
minScale: 1,
|
|
738
|
+
maxScale: 8,
|
|
739
|
+
limitToBounds: true,
|
|
740
|
+
centerZoomedOut: false,
|
|
741
|
+
centerOnInit: false,
|
|
742
|
+
wheel: {
|
|
743
|
+
step: 0.2,
|
|
744
|
+
disabled: false,
|
|
745
|
+
wheelDisabled: false,
|
|
746
|
+
touchPadDisabled: false,
|
|
747
|
+
activationKeys: [],
|
|
748
|
+
excluded: []
|
|
749
|
+
},
|
|
750
|
+
panning: {
|
|
751
|
+
disabled: false,
|
|
752
|
+
velocityDisabled: false,
|
|
753
|
+
lockAxisX: false,
|
|
754
|
+
lockAxisY: false,
|
|
755
|
+
activationKeys: [],
|
|
756
|
+
excluded: []
|
|
757
|
+
},
|
|
758
|
+
pinch: {
|
|
759
|
+
step: 5,
|
|
760
|
+
disabled: false,
|
|
761
|
+
excluded: []
|
|
762
|
+
},
|
|
763
|
+
doubleClick: {
|
|
764
|
+
disabled: false,
|
|
765
|
+
step: 0.7,
|
|
766
|
+
mode: "zoomIn",
|
|
767
|
+
animationType: "easeOut",
|
|
768
|
+
animationTime: 200,
|
|
769
|
+
excluded: []
|
|
770
|
+
},
|
|
771
|
+
zoomAnimation: {
|
|
772
|
+
disabled: false,
|
|
773
|
+
size: 0.4,
|
|
774
|
+
animationTime: 200,
|
|
775
|
+
animationType: "easeOut"
|
|
776
|
+
},
|
|
777
|
+
alignmentAnimation: {
|
|
778
|
+
disabled: false,
|
|
779
|
+
sizeX: 100,
|
|
780
|
+
sizeY: 100,
|
|
781
|
+
animationTime: 200,
|
|
782
|
+
velocityAlignmentTime: 400,
|
|
783
|
+
animationType: "easeOut"
|
|
784
|
+
},
|
|
785
|
+
velocityAnimation: {
|
|
786
|
+
disabled: false,
|
|
787
|
+
sensitivity: 1,
|
|
788
|
+
animationTime: 400,
|
|
789
|
+
animationType: "easeOut",
|
|
790
|
+
equalToMove: true
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
var createState = function(props) {
|
|
794
|
+
var _a, _b, _c, _d;
|
|
795
|
+
return {
|
|
796
|
+
previousScale: (_a = props.initialScale) !== null && _a !== void 0 ? _a : initialState.scale,
|
|
797
|
+
scale: (_b = props.initialScale) !== null && _b !== void 0 ? _b : initialState.scale,
|
|
798
|
+
positionX: (_c = props.initialPositionX) !== null && _c !== void 0 ? _c : initialState.positionX,
|
|
799
|
+
positionY: (_d = props.initialPositionY) !== null && _d !== void 0 ? _d : initialState.positionY
|
|
800
|
+
};
|
|
801
|
+
};
|
|
802
|
+
var createSetup = function(props) {
|
|
803
|
+
var newSetup = __assign({}, initialSetup);
|
|
804
|
+
Object.keys(props).forEach(function(key) {
|
|
805
|
+
var validValue = typeof props[key] !== "undefined";
|
|
806
|
+
var validParameter = typeof initialSetup[key] !== "undefined";
|
|
807
|
+
if (validParameter && validValue) {
|
|
808
|
+
var dataType = Object.prototype.toString.call(initialSetup[key]);
|
|
809
|
+
var isObject = dataType === "[object Object]";
|
|
810
|
+
var isArray = dataType === "[object Array]";
|
|
811
|
+
if (isObject) {
|
|
812
|
+
newSetup[key] = __assign(__assign({}, initialSetup[key]), props[key]);
|
|
813
|
+
} else if (isArray) {
|
|
814
|
+
newSetup[key] = __spreadArray(__spreadArray([], initialSetup[key]), props[key]);
|
|
815
|
+
} else {
|
|
816
|
+
newSetup[key] = props[key];
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
return newSetup;
|
|
821
|
+
};
|
|
822
|
+
var handleCalculateButtonZoom = function(contextInstance, delta, step) {
|
|
823
|
+
var scale = contextInstance.transformState.scale;
|
|
824
|
+
var wrapperComponent = contextInstance.wrapperComponent, setup = contextInstance.setup;
|
|
825
|
+
var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation;
|
|
826
|
+
var size = zoomAnimation.size;
|
|
827
|
+
if (!wrapperComponent) {
|
|
828
|
+
throw new Error("Wrapper is not mounted");
|
|
829
|
+
}
|
|
830
|
+
var targetScale = scale * Math.exp(delta * step);
|
|
831
|
+
var newScale = checkZoomBounds(roundNumber(targetScale, 3), minScale, maxScale, size, false);
|
|
832
|
+
return newScale;
|
|
833
|
+
};
|
|
834
|
+
function handleZoomToViewCenter(contextInstance, delta, step, animationTime, animationType) {
|
|
835
|
+
var wrapperComponent = contextInstance.wrapperComponent;
|
|
836
|
+
var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
837
|
+
if (!wrapperComponent)
|
|
838
|
+
return console.error("No WrapperComponent found");
|
|
839
|
+
var wrapperWidth = wrapperComponent.offsetWidth;
|
|
840
|
+
var wrapperHeight = wrapperComponent.offsetHeight;
|
|
841
|
+
var mouseX = (wrapperWidth / 2 - positionX) / scale;
|
|
842
|
+
var mouseY = (wrapperHeight / 2 - positionY) / scale;
|
|
843
|
+
var newScale = handleCalculateButtonZoom(contextInstance, delta, step);
|
|
844
|
+
var targetState = handleZoomToPoint(contextInstance, newScale, mouseX, mouseY);
|
|
845
|
+
if (!targetState) {
|
|
846
|
+
return console.error("Error during zoom event. New transformation state was not calculated.");
|
|
847
|
+
}
|
|
848
|
+
animate(contextInstance, targetState, animationTime, animationType);
|
|
849
|
+
}
|
|
850
|
+
function resetTransformations(contextInstance, animationTime, animationType) {
|
|
851
|
+
var setup = contextInstance.setup, wrapperComponent = contextInstance.wrapperComponent;
|
|
852
|
+
var limitToBounds = setup.limitToBounds;
|
|
853
|
+
var initialTransformation = createState(contextInstance.props);
|
|
854
|
+
var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
855
|
+
if (!wrapperComponent)
|
|
856
|
+
return;
|
|
857
|
+
var newBounds = calculateBounds(contextInstance, initialTransformation.scale);
|
|
858
|
+
var boundedPositions = getMouseBoundedPosition(initialTransformation.positionX, initialTransformation.positionY, newBounds, limitToBounds, 0, 0, wrapperComponent);
|
|
859
|
+
var newState = {
|
|
860
|
+
scale: initialTransformation.scale,
|
|
861
|
+
positionX: boundedPositions.x,
|
|
862
|
+
positionY: boundedPositions.y
|
|
863
|
+
};
|
|
864
|
+
if (scale === initialTransformation.scale && positionX === initialTransformation.positionX && positionY === initialTransformation.positionY) {
|
|
865
|
+
return;
|
|
866
|
+
}
|
|
867
|
+
animate(contextInstance, newState, animationTime, animationType);
|
|
868
|
+
}
|
|
869
|
+
function calculateZoomToNode(contextInstance, node, customZoom) {
|
|
870
|
+
var wrapperComponent = contextInstance.wrapperComponent;
|
|
871
|
+
var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, minScale = _a.minScale, maxScale = _a.maxScale;
|
|
872
|
+
if (!wrapperComponent)
|
|
873
|
+
return initialState;
|
|
874
|
+
var wrapperRect = wrapperComponent.getBoundingClientRect();
|
|
875
|
+
var nodeRect = getOffset(node);
|
|
876
|
+
var nodeLeft = nodeRect.x;
|
|
877
|
+
var nodeTop = nodeRect.y;
|
|
878
|
+
var nodeWidth = node.offsetWidth;
|
|
879
|
+
var nodeHeight = node.offsetHeight;
|
|
880
|
+
var scaleX = wrapperComponent.offsetWidth / nodeWidth;
|
|
881
|
+
var scaleY = wrapperComponent.offsetHeight / nodeHeight;
|
|
882
|
+
var newScale = checkZoomBounds(customZoom || Math.min(scaleX, scaleY), minScale, maxScale, 0, false);
|
|
883
|
+
var offsetX = (wrapperRect.width - nodeWidth * newScale) / 2;
|
|
884
|
+
var offsetY = (wrapperRect.height - nodeHeight * newScale) / 2;
|
|
885
|
+
var newPositionX = (wrapperRect.left - nodeLeft) * newScale + offsetX;
|
|
886
|
+
var newPositionY = (wrapperRect.top - nodeTop) * newScale + offsetY;
|
|
887
|
+
var bounds = calculateBounds(contextInstance, newScale);
|
|
888
|
+
var _b = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, 0, 0, wrapperComponent), x = _b.x, y = _b.y;
|
|
889
|
+
return {
|
|
890
|
+
positionX: x,
|
|
891
|
+
positionY: y,
|
|
892
|
+
scale: newScale
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
function getOffset(element) {
|
|
896
|
+
var el = element;
|
|
897
|
+
var offsetLeft = 0;
|
|
898
|
+
var offsetTop = 0;
|
|
899
|
+
while (el) {
|
|
900
|
+
offsetLeft += el.offsetLeft;
|
|
901
|
+
offsetTop += el.offsetTop;
|
|
902
|
+
el = el.offsetParent;
|
|
903
|
+
}
|
|
904
|
+
return {
|
|
905
|
+
x: offsetLeft,
|
|
906
|
+
y: offsetTop
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
function isValidZoomNode(node) {
|
|
910
|
+
if (!node) {
|
|
911
|
+
console.error("Zoom node not found");
|
|
912
|
+
return false;
|
|
913
|
+
} else if ((node === null || node === void 0 ? void 0 : node.offsetWidth) === void 0 || (node === null || node === void 0 ? void 0 : node.offsetHeight) === void 0) {
|
|
914
|
+
console.error("Zoom node is not valid - it must contain offsetWidth and offsetHeight");
|
|
915
|
+
return false;
|
|
916
|
+
}
|
|
917
|
+
return true;
|
|
918
|
+
}
|
|
919
|
+
var zoomIn = function(contextInstance) {
|
|
920
|
+
return function(step, animationTime, animationType) {
|
|
921
|
+
if (step === void 0) {
|
|
922
|
+
step = 0.5;
|
|
923
|
+
}
|
|
924
|
+
if (animationTime === void 0) {
|
|
925
|
+
animationTime = 300;
|
|
926
|
+
}
|
|
927
|
+
if (animationType === void 0) {
|
|
928
|
+
animationType = "easeOut";
|
|
929
|
+
}
|
|
930
|
+
handleZoomToViewCenter(contextInstance, 1, step, animationTime, animationType);
|
|
931
|
+
};
|
|
932
|
+
};
|
|
933
|
+
var zoomOut = function(contextInstance) {
|
|
934
|
+
return function(step, animationTime, animationType) {
|
|
935
|
+
if (step === void 0) {
|
|
936
|
+
step = 0.5;
|
|
937
|
+
}
|
|
938
|
+
if (animationTime === void 0) {
|
|
939
|
+
animationTime = 300;
|
|
940
|
+
}
|
|
941
|
+
if (animationType === void 0) {
|
|
942
|
+
animationType = "easeOut";
|
|
943
|
+
}
|
|
944
|
+
handleZoomToViewCenter(contextInstance, -1, step, animationTime, animationType);
|
|
945
|
+
};
|
|
946
|
+
};
|
|
947
|
+
var setTransform = function(contextInstance) {
|
|
948
|
+
return function(newPositionX, newPositionY, newScale, animationTime, animationType) {
|
|
949
|
+
if (animationTime === void 0) {
|
|
950
|
+
animationTime = 300;
|
|
951
|
+
}
|
|
952
|
+
if (animationType === void 0) {
|
|
953
|
+
animationType = "easeOut";
|
|
954
|
+
}
|
|
955
|
+
var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale;
|
|
956
|
+
var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
957
|
+
var disabled = contextInstance.setup.disabled;
|
|
958
|
+
if (disabled || !wrapperComponent || !contentComponent)
|
|
959
|
+
return;
|
|
960
|
+
var targetState = {
|
|
961
|
+
positionX: isNaN(newPositionX) ? positionX : newPositionX,
|
|
962
|
+
positionY: isNaN(newPositionY) ? positionY : newPositionY,
|
|
963
|
+
scale: isNaN(newScale) ? scale : newScale
|
|
964
|
+
};
|
|
965
|
+
animate(contextInstance, targetState, animationTime, animationType);
|
|
966
|
+
};
|
|
967
|
+
};
|
|
968
|
+
var resetTransform = function(contextInstance) {
|
|
969
|
+
return function(animationTime, animationType) {
|
|
970
|
+
if (animationTime === void 0) {
|
|
971
|
+
animationTime = 200;
|
|
972
|
+
}
|
|
973
|
+
if (animationType === void 0) {
|
|
974
|
+
animationType = "easeOut";
|
|
975
|
+
}
|
|
976
|
+
resetTransformations(contextInstance, animationTime, animationType);
|
|
977
|
+
};
|
|
978
|
+
};
|
|
979
|
+
var centerView = function(contextInstance) {
|
|
980
|
+
return function(scale, animationTime, animationType) {
|
|
981
|
+
if (animationTime === void 0) {
|
|
982
|
+
animationTime = 200;
|
|
983
|
+
}
|
|
984
|
+
if (animationType === void 0) {
|
|
985
|
+
animationType = "easeOut";
|
|
986
|
+
}
|
|
987
|
+
var transformState = contextInstance.transformState, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
988
|
+
if (wrapperComponent && contentComponent) {
|
|
989
|
+
var targetState = getCenterPosition(scale || transformState.scale, wrapperComponent, contentComponent);
|
|
990
|
+
animate(contextInstance, targetState, animationTime, animationType);
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
};
|
|
994
|
+
var zoomToElement = function(contextInstance) {
|
|
995
|
+
return function(node, scale, animationTime, animationType) {
|
|
996
|
+
if (animationTime === void 0) {
|
|
997
|
+
animationTime = 600;
|
|
998
|
+
}
|
|
999
|
+
if (animationType === void 0) {
|
|
1000
|
+
animationType = "easeOut";
|
|
1001
|
+
}
|
|
1002
|
+
handleCancelAnimation(contextInstance);
|
|
1003
|
+
var wrapperComponent = contextInstance.wrapperComponent;
|
|
1004
|
+
var target = typeof node === "string" ? document.getElementById(node) : node;
|
|
1005
|
+
if (wrapperComponent && isValidZoomNode(target) && target && wrapperComponent.contains(target)) {
|
|
1006
|
+
var targetState = calculateZoomToNode(contextInstance, target, scale);
|
|
1007
|
+
animate(contextInstance, targetState, animationTime, animationType);
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
};
|
|
1011
|
+
var getContext = function(contextInstance) {
|
|
1012
|
+
return {
|
|
1013
|
+
instance: contextInstance,
|
|
1014
|
+
state: contextInstance.transformState,
|
|
1015
|
+
zoomIn: zoomIn(contextInstance),
|
|
1016
|
+
zoomOut: zoomOut(contextInstance),
|
|
1017
|
+
setTransform: setTransform(contextInstance),
|
|
1018
|
+
resetTransform: resetTransform(contextInstance),
|
|
1019
|
+
centerView: centerView(contextInstance),
|
|
1020
|
+
zoomToElement: zoomToElement(contextInstance)
|
|
1021
|
+
};
|
|
1022
|
+
};
|
|
1023
|
+
var passiveSupported = false;
|
|
1024
|
+
function makePassiveEventOption() {
|
|
1025
|
+
try {
|
|
1026
|
+
var options = {
|
|
1027
|
+
get passive() {
|
|
1028
|
+
passiveSupported = true;
|
|
1029
|
+
return false;
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
return options;
|
|
1033
|
+
} catch (err) {
|
|
1034
|
+
passiveSupported = false;
|
|
1035
|
+
return passiveSupported;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
var isExcludedNode = function(node, excluded) {
|
|
1039
|
+
var targetTagName = node.tagName.toUpperCase();
|
|
1040
|
+
var isExcludedTag = excluded.find(function(tag) {
|
|
1041
|
+
return tag.toUpperCase() === targetTagName;
|
|
1042
|
+
});
|
|
1043
|
+
if (isExcludedTag)
|
|
1044
|
+
return true;
|
|
1045
|
+
var isExcludedClassName = excluded.find(function(className) {
|
|
1046
|
+
return node.classList.contains(className);
|
|
1047
|
+
});
|
|
1048
|
+
if (isExcludedClassName)
|
|
1049
|
+
return true;
|
|
1050
|
+
return false;
|
|
1051
|
+
};
|
|
1052
|
+
var cancelTimeout = function(timeout) {
|
|
1053
|
+
if (timeout) {
|
|
1054
|
+
clearTimeout(timeout);
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
var getTransformStyles = function(x, y, scale) {
|
|
1058
|
+
return "translate3d(" + x + "px, " + y + "px, 0) scale(" + scale + ")";
|
|
1059
|
+
};
|
|
1060
|
+
var getCenterPosition = function(scale, wrapperComponent, contentComponent) {
|
|
1061
|
+
var contentWidth = contentComponent.offsetWidth * scale;
|
|
1062
|
+
var contentHeight = contentComponent.offsetHeight * scale;
|
|
1063
|
+
var centerPositionX = (wrapperComponent.offsetWidth - contentWidth) / 2;
|
|
1064
|
+
var centerPositionY = (wrapperComponent.offsetHeight - contentHeight) / 2;
|
|
1065
|
+
return {
|
|
1066
|
+
scale,
|
|
1067
|
+
positionX: centerPositionX,
|
|
1068
|
+
positionY: centerPositionY
|
|
1069
|
+
};
|
|
1070
|
+
};
|
|
1071
|
+
var isWheelAllowed = function(contextInstance, event) {
|
|
1072
|
+
var _a = contextInstance.setup.wheel, disabled = _a.disabled, wheelDisabled = _a.wheelDisabled, touchPadDisabled = _a.touchPadDisabled, excluded = _a.excluded;
|
|
1073
|
+
var isInitialized = contextInstance.isInitialized, isPanning = contextInstance.isPanning;
|
|
1074
|
+
var target = event.target;
|
|
1075
|
+
var isAllowed = isInitialized && !isPanning && !disabled && target;
|
|
1076
|
+
if (!isAllowed)
|
|
1077
|
+
return false;
|
|
1078
|
+
if (wheelDisabled && !event.ctrlKey)
|
|
1079
|
+
return false;
|
|
1080
|
+
if (touchPadDisabled && event.ctrlKey)
|
|
1081
|
+
return false;
|
|
1082
|
+
var isExcluded = isExcludedNode(target, excluded);
|
|
1083
|
+
if (isExcluded)
|
|
1084
|
+
return false;
|
|
1085
|
+
return true;
|
|
1086
|
+
};
|
|
1087
|
+
function getDelta(event, customDelta) {
|
|
1088
|
+
var deltaY = event ? event.deltaY < 0 ? 1 : -1 : 0;
|
|
1089
|
+
var delta = checkIsNumber(customDelta, deltaY);
|
|
1090
|
+
return delta;
|
|
1091
|
+
}
|
|
1092
|
+
function getMousePosition(event, contentComponent, scale) {
|
|
1093
|
+
var contentRect = contentComponent.getBoundingClientRect();
|
|
1094
|
+
var mouseX = 0;
|
|
1095
|
+
var mouseY = 0;
|
|
1096
|
+
if ("clientX" in event) {
|
|
1097
|
+
mouseX = (event.clientX - contentRect.left) / scale;
|
|
1098
|
+
mouseY = (event.clientY - contentRect.top) / scale;
|
|
1099
|
+
} else {
|
|
1100
|
+
var touch = event.touches[0];
|
|
1101
|
+
mouseX = (touch.clientX - contentRect.left) / scale;
|
|
1102
|
+
mouseY = (touch.clientY - contentRect.top) / scale;
|
|
1103
|
+
}
|
|
1104
|
+
if (isNaN(mouseX) || isNaN(mouseY))
|
|
1105
|
+
console.error("No mouse or touch offset found");
|
|
1106
|
+
return {
|
|
1107
|
+
x: mouseX,
|
|
1108
|
+
y: mouseY
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
var handleCalculateWheelZoom = function(contextInstance, delta, step, disablePadding, getTarget) {
|
|
1112
|
+
var scale = contextInstance.transformState.scale;
|
|
1113
|
+
var wrapperComponent = contextInstance.wrapperComponent, setup = contextInstance.setup;
|
|
1114
|
+
var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation;
|
|
1115
|
+
var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
|
|
1116
|
+
if (!wrapperComponent) {
|
|
1117
|
+
throw new Error("Wrapper is not mounted");
|
|
1118
|
+
}
|
|
1119
|
+
var targetScale = scale + delta * (scale - scale * step) * step;
|
|
1120
|
+
if (getTarget)
|
|
1121
|
+
return targetScale;
|
|
1122
|
+
var paddingEnabled = disablePadding ? false : !disabled;
|
|
1123
|
+
var newScale = checkZoomBounds(roundNumber(targetScale, 3), minScale, maxScale, size, paddingEnabled);
|
|
1124
|
+
return newScale;
|
|
1125
|
+
};
|
|
1126
|
+
var handleWheelZoomStop = function(contextInstance, event) {
|
|
1127
|
+
var previousWheelEvent = contextInstance.previousWheelEvent;
|
|
1128
|
+
var scale = contextInstance.transformState.scale;
|
|
1129
|
+
var _a = contextInstance.setup, maxScale = _a.maxScale, minScale = _a.minScale;
|
|
1130
|
+
if (!previousWheelEvent)
|
|
1131
|
+
return false;
|
|
1132
|
+
if (scale < maxScale || scale > minScale)
|
|
1133
|
+
return true;
|
|
1134
|
+
if (Math.sign(previousWheelEvent.deltaY) !== Math.sign(event.deltaY))
|
|
1135
|
+
return true;
|
|
1136
|
+
if (previousWheelEvent.deltaY > 0 && previousWheelEvent.deltaY < event.deltaY)
|
|
1137
|
+
return true;
|
|
1138
|
+
if (previousWheelEvent.deltaY < 0 && previousWheelEvent.deltaY > event.deltaY)
|
|
1139
|
+
return true;
|
|
1140
|
+
if (Math.sign(previousWheelEvent.deltaY) !== Math.sign(event.deltaY))
|
|
1141
|
+
return true;
|
|
1142
|
+
return false;
|
|
1143
|
+
};
|
|
1144
|
+
var isPinchStartAllowed = function(contextInstance, event) {
|
|
1145
|
+
var _a = contextInstance.setup.pinch, disabled = _a.disabled, excluded = _a.excluded;
|
|
1146
|
+
var isInitialized = contextInstance.isInitialized;
|
|
1147
|
+
var target = event.target;
|
|
1148
|
+
var isAllowed = isInitialized && !disabled && target;
|
|
1149
|
+
if (!isAllowed)
|
|
1150
|
+
return false;
|
|
1151
|
+
var isExcluded = isExcludedNode(target, excluded);
|
|
1152
|
+
if (isExcluded)
|
|
1153
|
+
return false;
|
|
1154
|
+
return true;
|
|
1155
|
+
};
|
|
1156
|
+
var isPinchAllowed = function(contextInstance) {
|
|
1157
|
+
var disabled = contextInstance.setup.pinch.disabled;
|
|
1158
|
+
var isInitialized = contextInstance.isInitialized, pinchStartDistance = contextInstance.pinchStartDistance;
|
|
1159
|
+
var isAllowed = isInitialized && !disabled && pinchStartDistance;
|
|
1160
|
+
if (!isAllowed)
|
|
1161
|
+
return false;
|
|
1162
|
+
return true;
|
|
1163
|
+
};
|
|
1164
|
+
var calculateTouchMidPoint = function(event, scale, contentComponent) {
|
|
1165
|
+
var contentRect = contentComponent.getBoundingClientRect();
|
|
1166
|
+
var touches = event.touches;
|
|
1167
|
+
var firstPointX = roundNumber(touches[0].clientX - contentRect.left, 5);
|
|
1168
|
+
var firstPointY = roundNumber(touches[0].clientY - contentRect.top, 5);
|
|
1169
|
+
var secondPointX = roundNumber(touches[1].clientX - contentRect.left, 5);
|
|
1170
|
+
var secondPointY = roundNumber(touches[1].clientY - contentRect.top, 5);
|
|
1171
|
+
return {
|
|
1172
|
+
x: (firstPointX + secondPointX) / 2 / scale,
|
|
1173
|
+
y: (firstPointY + secondPointY) / 2 / scale
|
|
1174
|
+
};
|
|
1175
|
+
};
|
|
1176
|
+
var getTouchDistance = function(event) {
|
|
1177
|
+
return Math.sqrt(Math.pow(event.touches[0].pageX - event.touches[1].pageX, 2) + Math.pow(event.touches[0].pageY - event.touches[1].pageY, 2));
|
|
1178
|
+
};
|
|
1179
|
+
var calculatePinchZoom = function(contextInstance, currentDistance) {
|
|
1180
|
+
var pinchStartScale = contextInstance.pinchStartScale, pinchStartDistance = contextInstance.pinchStartDistance, setup = contextInstance.setup;
|
|
1181
|
+
var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation;
|
|
1182
|
+
var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
|
|
1183
|
+
if (!pinchStartScale || pinchStartDistance === null || !currentDistance) {
|
|
1184
|
+
throw new Error("Pinch touches distance was not provided");
|
|
1185
|
+
}
|
|
1186
|
+
if (currentDistance < 0) {
|
|
1187
|
+
return contextInstance.transformState.scale;
|
|
1188
|
+
}
|
|
1189
|
+
var touchProportion = currentDistance / pinchStartDistance;
|
|
1190
|
+
var scaleDifference = touchProportion * pinchStartScale;
|
|
1191
|
+
return checkZoomBounds(roundNumber(scaleDifference, 2), minScale, maxScale, size, !disabled);
|
|
1192
|
+
};
|
|
1193
|
+
var wheelStopEventTime = 160;
|
|
1194
|
+
var wheelAnimationTime = 100;
|
|
1195
|
+
var handleWheelStart = function(contextInstance, event) {
|
|
1196
|
+
var _a = contextInstance.props, onWheelStart = _a.onWheelStart, onZoomStart = _a.onZoomStart;
|
|
1197
|
+
if (!contextInstance.wheelStopEventTimer) {
|
|
1198
|
+
handleCancelAnimation(contextInstance);
|
|
1199
|
+
handleCallback(getContext(contextInstance), event, onWheelStart);
|
|
1200
|
+
handleCallback(getContext(contextInstance), event, onZoomStart);
|
|
1201
|
+
}
|
|
1202
|
+
};
|
|
1203
|
+
var handleWheelZoom = function(contextInstance, event) {
|
|
1204
|
+
var _a = contextInstance.props, onWheel = _a.onWheel, onZoom = _a.onZoom;
|
|
1205
|
+
var contentComponent = contextInstance.contentComponent, setup = contextInstance.setup, transformState = contextInstance.transformState;
|
|
1206
|
+
var scale = transformState.scale;
|
|
1207
|
+
var limitToBounds = setup.limitToBounds, centerZoomedOut = setup.centerZoomedOut, zoomAnimation = setup.zoomAnimation, wheel = setup.wheel;
|
|
1208
|
+
var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
|
|
1209
|
+
var step = wheel.step;
|
|
1210
|
+
if (!contentComponent) {
|
|
1211
|
+
throw new Error("Component not mounted");
|
|
1212
|
+
}
|
|
1213
|
+
event.preventDefault();
|
|
1214
|
+
event.stopPropagation();
|
|
1215
|
+
var delta = getDelta(event, null);
|
|
1216
|
+
var newScale = handleCalculateWheelZoom(contextInstance, delta, step, !event.ctrlKey);
|
|
1217
|
+
if (scale === newScale)
|
|
1218
|
+
return;
|
|
1219
|
+
var bounds = handleCalculateBounds(contextInstance, newScale);
|
|
1220
|
+
var mousePosition = getMousePosition(event, contentComponent, scale);
|
|
1221
|
+
var isPaddingDisabled = disabled || size === 0 || centerZoomedOut;
|
|
1222
|
+
var isLimitedToBounds = limitToBounds && isPaddingDisabled;
|
|
1223
|
+
var _b = handleCalculateZoomPositions(contextInstance, mousePosition.x, mousePosition.y, newScale, bounds, isLimitedToBounds), x = _b.x, y = _b.y;
|
|
1224
|
+
contextInstance.previousWheelEvent = event;
|
|
1225
|
+
contextInstance.setTransformState(newScale, x, y);
|
|
1226
|
+
handleCallback(getContext(contextInstance), event, onWheel);
|
|
1227
|
+
handleCallback(getContext(contextInstance), event, onZoom);
|
|
1228
|
+
};
|
|
1229
|
+
var handleWheelStop = function(contextInstance, event) {
|
|
1230
|
+
var _a = contextInstance.props, onWheelStop = _a.onWheelStop, onZoomStop = _a.onZoomStop;
|
|
1231
|
+
cancelTimeout(contextInstance.wheelAnimationTimer);
|
|
1232
|
+
contextInstance.wheelAnimationTimer = setTimeout(function() {
|
|
1233
|
+
if (!contextInstance.mounted)
|
|
1234
|
+
return;
|
|
1235
|
+
handleAlignToScaleBounds(contextInstance, event.x, event.y);
|
|
1236
|
+
contextInstance.wheelAnimationTimer = null;
|
|
1237
|
+
}, wheelAnimationTime);
|
|
1238
|
+
var hasStoppedZooming = handleWheelZoomStop(contextInstance, event);
|
|
1239
|
+
if (hasStoppedZooming) {
|
|
1240
|
+
cancelTimeout(contextInstance.wheelStopEventTimer);
|
|
1241
|
+
contextInstance.wheelStopEventTimer = setTimeout(function() {
|
|
1242
|
+
if (!contextInstance.mounted)
|
|
1243
|
+
return;
|
|
1244
|
+
contextInstance.wheelStopEventTimer = null;
|
|
1245
|
+
handleCallback(getContext(contextInstance), event, onWheelStop);
|
|
1246
|
+
handleCallback(getContext(contextInstance), event, onZoomStop);
|
|
1247
|
+
}, wheelStopEventTime);
|
|
1248
|
+
}
|
|
1249
|
+
};
|
|
1250
|
+
var handlePinchStart = function(contextInstance, event) {
|
|
1251
|
+
var distance = getTouchDistance(event);
|
|
1252
|
+
contextInstance.pinchStartDistance = distance;
|
|
1253
|
+
contextInstance.lastDistance = distance;
|
|
1254
|
+
contextInstance.pinchStartScale = contextInstance.transformState.scale;
|
|
1255
|
+
contextInstance.isPanning = false;
|
|
1256
|
+
handleCancelAnimation(contextInstance);
|
|
1257
|
+
};
|
|
1258
|
+
var handlePinchZoom = function(contextInstance, event) {
|
|
1259
|
+
var contentComponent = contextInstance.contentComponent, pinchStartDistance = contextInstance.pinchStartDistance;
|
|
1260
|
+
var scale = contextInstance.transformState.scale;
|
|
1261
|
+
var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, centerZoomedOut = _a.centerZoomedOut, zoomAnimation = _a.zoomAnimation;
|
|
1262
|
+
var disabled = zoomAnimation.disabled, size = zoomAnimation.size;
|
|
1263
|
+
if (pinchStartDistance === null || !contentComponent)
|
|
1264
|
+
return;
|
|
1265
|
+
var midPoint = calculateTouchMidPoint(event, scale, contentComponent);
|
|
1266
|
+
if (!isFinite(midPoint.x) || !isFinite(midPoint.y))
|
|
1267
|
+
return;
|
|
1268
|
+
var currentDistance = getTouchDistance(event);
|
|
1269
|
+
var newScale = calculatePinchZoom(contextInstance, currentDistance);
|
|
1270
|
+
if (newScale === scale)
|
|
1271
|
+
return;
|
|
1272
|
+
var bounds = handleCalculateBounds(contextInstance, newScale);
|
|
1273
|
+
var isPaddingDisabled = disabled || size === 0 || centerZoomedOut;
|
|
1274
|
+
var isLimitedToBounds = limitToBounds && isPaddingDisabled;
|
|
1275
|
+
var _b = handleCalculateZoomPositions(contextInstance, midPoint.x, midPoint.y, newScale, bounds, isLimitedToBounds), x = _b.x, y = _b.y;
|
|
1276
|
+
contextInstance.pinchMidpoint = midPoint;
|
|
1277
|
+
contextInstance.lastDistance = currentDistance;
|
|
1278
|
+
contextInstance.setTransformState(newScale, x, y);
|
|
1279
|
+
};
|
|
1280
|
+
var handlePinchStop = function(contextInstance) {
|
|
1281
|
+
var pinchMidpoint = contextInstance.pinchMidpoint;
|
|
1282
|
+
contextInstance.velocity = null;
|
|
1283
|
+
contextInstance.lastDistance = null;
|
|
1284
|
+
contextInstance.pinchMidpoint = null;
|
|
1285
|
+
contextInstance.pinchStartScale = null;
|
|
1286
|
+
contextInstance.pinchStartDistance = null;
|
|
1287
|
+
handleAlignToScaleBounds(contextInstance, pinchMidpoint === null || pinchMidpoint === void 0 ? void 0 : pinchMidpoint.x, pinchMidpoint === null || pinchMidpoint === void 0 ? void 0 : pinchMidpoint.y);
|
|
1288
|
+
};
|
|
1289
|
+
function handleDoubleClick(contextInstance, event) {
|
|
1290
|
+
var _a = contextInstance.setup.doubleClick, disabled = _a.disabled, mode = _a.mode, step = _a.step, animationTime = _a.animationTime, animationType = _a.animationType;
|
|
1291
|
+
if (disabled)
|
|
1292
|
+
return;
|
|
1293
|
+
if (mode === "reset") {
|
|
1294
|
+
return resetTransformations(contextInstance, animationTime, animationType);
|
|
1295
|
+
}
|
|
1296
|
+
var scale = contextInstance.transformState.scale;
|
|
1297
|
+
var contentComponent = contextInstance.contentComponent;
|
|
1298
|
+
if (!contentComponent)
|
|
1299
|
+
return console.error("No ContentComponent found");
|
|
1300
|
+
var delta = mode === "zoomOut" ? -1 : 1;
|
|
1301
|
+
var newScale = handleCalculateButtonZoom(contextInstance, delta, step);
|
|
1302
|
+
var mousePosition = getMousePosition(event, contentComponent, scale);
|
|
1303
|
+
var targetState = handleZoomToPoint(contextInstance, newScale, mousePosition.x, mousePosition.y);
|
|
1304
|
+
if (!targetState) {
|
|
1305
|
+
return console.error("Error during zoom event. New transformation state was not calculated.");
|
|
1306
|
+
}
|
|
1307
|
+
animate(contextInstance, targetState, animationTime, animationType);
|
|
1308
|
+
}
|
|
1309
|
+
var isDoubleClickAllowed = function(contextInstance, event) {
|
|
1310
|
+
var isInitialized = contextInstance.isInitialized, setup = contextInstance.setup, wrapperComponent = contextInstance.wrapperComponent;
|
|
1311
|
+
var _a = setup.doubleClick, disabled = _a.disabled, excluded = _a.excluded;
|
|
1312
|
+
var target = event.target;
|
|
1313
|
+
var isWrapperChild = wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.contains(target);
|
|
1314
|
+
var isAllowed = isInitialized && target && isWrapperChild && !disabled;
|
|
1315
|
+
if (!isAllowed)
|
|
1316
|
+
return false;
|
|
1317
|
+
var isExcluded = isExcludedNode(target, excluded);
|
|
1318
|
+
if (isExcluded)
|
|
1319
|
+
return false;
|
|
1320
|
+
if (!isAllowed)
|
|
1321
|
+
return false;
|
|
1322
|
+
return true;
|
|
1323
|
+
};
|
|
1324
|
+
var Context = React.createContext(contextInitialState);
|
|
1325
|
+
var TransformContext = function(_super) {
|
|
1326
|
+
__extends(TransformContext2, _super);
|
|
1327
|
+
function TransformContext2() {
|
|
1328
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1329
|
+
_this.mounted = true;
|
|
1330
|
+
_this.transformState = createState(_this.props);
|
|
1331
|
+
_this.setup = createSetup(_this.props);
|
|
1332
|
+
_this.wrapperComponent = null;
|
|
1333
|
+
_this.contentComponent = null;
|
|
1334
|
+
_this.isInitialized = false;
|
|
1335
|
+
_this.bounds = null;
|
|
1336
|
+
_this.previousWheelEvent = null;
|
|
1337
|
+
_this.wheelStopEventTimer = null;
|
|
1338
|
+
_this.wheelAnimationTimer = null;
|
|
1339
|
+
_this.isPanning = false;
|
|
1340
|
+
_this.startCoords = null;
|
|
1341
|
+
_this.lastTouch = null;
|
|
1342
|
+
_this.distance = null;
|
|
1343
|
+
_this.lastDistance = null;
|
|
1344
|
+
_this.pinchStartDistance = null;
|
|
1345
|
+
_this.pinchStartScale = null;
|
|
1346
|
+
_this.pinchMidpoint = null;
|
|
1347
|
+
_this.velocity = null;
|
|
1348
|
+
_this.velocityTime = null;
|
|
1349
|
+
_this.lastMousePosition = null;
|
|
1350
|
+
_this.animate = false;
|
|
1351
|
+
_this.animation = null;
|
|
1352
|
+
_this.maxBounds = null;
|
|
1353
|
+
_this.pressedKeys = {};
|
|
1354
|
+
_this.handleInitializeWrapperEvents = function(wrapper) {
|
|
1355
|
+
var passive = makePassiveEventOption();
|
|
1356
|
+
wrapper.addEventListener("wheel", _this.onWheelZoom, passive);
|
|
1357
|
+
wrapper.addEventListener("dblclick", _this.onDoubleClick, passive);
|
|
1358
|
+
wrapper.addEventListener("touchstart", _this.onTouchPanningStart, passive);
|
|
1359
|
+
wrapper.addEventListener("touchmove", _this.onTouchPanning, passive);
|
|
1360
|
+
wrapper.addEventListener("touchend", _this.onTouchPanningStop, passive);
|
|
1361
|
+
};
|
|
1362
|
+
_this.handleInitialize = function() {
|
|
1363
|
+
var centerOnInit = _this.setup.centerOnInit;
|
|
1364
|
+
_this.applyTransformation();
|
|
1365
|
+
_this.forceUpdate();
|
|
1366
|
+
if (centerOnInit) {
|
|
1367
|
+
setTimeout(function() {
|
|
1368
|
+
if (_this.mounted) {
|
|
1369
|
+
_this.setCenter();
|
|
1370
|
+
}
|
|
1371
|
+
}, 50);
|
|
1372
|
+
setTimeout(function() {
|
|
1373
|
+
if (_this.mounted) {
|
|
1374
|
+
_this.setCenter();
|
|
1375
|
+
}
|
|
1376
|
+
}, 100);
|
|
1377
|
+
setTimeout(function() {
|
|
1378
|
+
if (_this.mounted) {
|
|
1379
|
+
_this.setCenter();
|
|
1380
|
+
}
|
|
1381
|
+
}, 200);
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
_this.onWheelZoom = function(event) {
|
|
1385
|
+
var disabled = _this.setup.disabled;
|
|
1386
|
+
if (disabled)
|
|
1387
|
+
return;
|
|
1388
|
+
var isAllowed = isWheelAllowed(_this, event);
|
|
1389
|
+
if (!isAllowed)
|
|
1390
|
+
return;
|
|
1391
|
+
var keysPressed = _this.isPressingKeys(_this.setup.wheel.activationKeys);
|
|
1392
|
+
if (!keysPressed)
|
|
1393
|
+
return;
|
|
1394
|
+
handleWheelStart(_this, event);
|
|
1395
|
+
handleWheelZoom(_this, event);
|
|
1396
|
+
handleWheelStop(_this, event);
|
|
1397
|
+
};
|
|
1398
|
+
_this.onPanningStart = function(event) {
|
|
1399
|
+
var disabled = _this.setup.disabled;
|
|
1400
|
+
var onPanningStart = _this.props.onPanningStart;
|
|
1401
|
+
if (disabled)
|
|
1402
|
+
return;
|
|
1403
|
+
var isAllowed = isPanningStartAllowed(_this, event);
|
|
1404
|
+
if (!isAllowed)
|
|
1405
|
+
return;
|
|
1406
|
+
var keysPressed = _this.isPressingKeys(_this.setup.panning.activationKeys);
|
|
1407
|
+
if (!keysPressed)
|
|
1408
|
+
return;
|
|
1409
|
+
event.preventDefault();
|
|
1410
|
+
event.stopPropagation();
|
|
1411
|
+
handleCancelAnimation(_this);
|
|
1412
|
+
handlePanningStart(_this, event);
|
|
1413
|
+
handleCallback(getContext(_this), event, onPanningStart);
|
|
1414
|
+
};
|
|
1415
|
+
_this.onPanning = function(event) {
|
|
1416
|
+
var disabled = _this.setup.disabled;
|
|
1417
|
+
var onPanning = _this.props.onPanning;
|
|
1418
|
+
if (disabled)
|
|
1419
|
+
return;
|
|
1420
|
+
var isAllowed = isPanningAllowed(_this);
|
|
1421
|
+
if (!isAllowed)
|
|
1422
|
+
return;
|
|
1423
|
+
var keysPressed = _this.isPressingKeys(_this.setup.panning.activationKeys);
|
|
1424
|
+
if (!keysPressed)
|
|
1425
|
+
return;
|
|
1426
|
+
event.preventDefault();
|
|
1427
|
+
event.stopPropagation();
|
|
1428
|
+
handlePanning(_this, event.clientX, event.clientY);
|
|
1429
|
+
handleCallback(getContext(_this), event, onPanning);
|
|
1430
|
+
};
|
|
1431
|
+
_this.onPanningStop = function(event) {
|
|
1432
|
+
var onPanningStop = _this.props.onPanningStop;
|
|
1433
|
+
if (_this.isPanning) {
|
|
1434
|
+
handlePanningEnd(_this);
|
|
1435
|
+
handleCallback(getContext(_this), event, onPanningStop);
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1438
|
+
_this.onPinchStart = function(event) {
|
|
1439
|
+
var disabled = _this.setup.disabled;
|
|
1440
|
+
var _a = _this.props, onPinchingStart = _a.onPinchingStart, onZoomStart = _a.onZoomStart;
|
|
1441
|
+
if (disabled)
|
|
1442
|
+
return;
|
|
1443
|
+
var isAllowed = isPinchStartAllowed(_this, event);
|
|
1444
|
+
if (!isAllowed)
|
|
1445
|
+
return;
|
|
1446
|
+
handlePinchStart(_this, event);
|
|
1447
|
+
handleCancelAnimation(_this);
|
|
1448
|
+
handleCallback(getContext(_this), event, onPinchingStart);
|
|
1449
|
+
handleCallback(getContext(_this), event, onZoomStart);
|
|
1450
|
+
};
|
|
1451
|
+
_this.onPinch = function(event) {
|
|
1452
|
+
var disabled = _this.setup.disabled;
|
|
1453
|
+
var _a = _this.props, onPinching = _a.onPinching, onZoom = _a.onZoom;
|
|
1454
|
+
if (disabled)
|
|
1455
|
+
return;
|
|
1456
|
+
var isAllowed = isPinchAllowed(_this);
|
|
1457
|
+
if (!isAllowed)
|
|
1458
|
+
return;
|
|
1459
|
+
event.preventDefault();
|
|
1460
|
+
event.stopPropagation();
|
|
1461
|
+
handlePinchZoom(_this, event);
|
|
1462
|
+
handleCallback(getContext(_this), event, onPinching);
|
|
1463
|
+
handleCallback(getContext(_this), event, onZoom);
|
|
1464
|
+
};
|
|
1465
|
+
_this.onPinchStop = function(event) {
|
|
1466
|
+
var _a = _this.props, onPinchingStop = _a.onPinchingStop, onZoomStop = _a.onZoomStop;
|
|
1467
|
+
if (_this.pinchStartScale) {
|
|
1468
|
+
handlePinchStop(_this);
|
|
1469
|
+
handleCallback(getContext(_this), event, onPinchingStop);
|
|
1470
|
+
handleCallback(getContext(_this), event, onZoomStop);
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1473
|
+
_this.onTouchPanningStart = function(event) {
|
|
1474
|
+
var disabled = _this.setup.disabled;
|
|
1475
|
+
var onPanningStart = _this.props.onPanningStart;
|
|
1476
|
+
if (disabled)
|
|
1477
|
+
return;
|
|
1478
|
+
var isAllowed = isPanningStartAllowed(_this, event);
|
|
1479
|
+
if (!isAllowed)
|
|
1480
|
+
return;
|
|
1481
|
+
var isDoubleTap = _this.lastTouch && +new Date() - _this.lastTouch < 200;
|
|
1482
|
+
if (isDoubleTap && event.touches.length === 1) {
|
|
1483
|
+
_this.onDoubleClick(event);
|
|
1484
|
+
} else {
|
|
1485
|
+
_this.lastTouch = +new Date();
|
|
1486
|
+
handleCancelAnimation(_this);
|
|
1487
|
+
var touches = event.touches;
|
|
1488
|
+
var isPanningAction = touches.length === 1;
|
|
1489
|
+
var isPinchAction = touches.length === 2;
|
|
1490
|
+
if (isPanningAction) {
|
|
1491
|
+
handleCancelAnimation(_this);
|
|
1492
|
+
handlePanningStart(_this, event);
|
|
1493
|
+
handleCallback(getContext(_this), event, onPanningStart);
|
|
1494
|
+
}
|
|
1495
|
+
if (isPinchAction) {
|
|
1496
|
+
_this.onPinchStart(event);
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
};
|
|
1500
|
+
_this.onTouchPanning = function(event) {
|
|
1501
|
+
var disabled = _this.setup.disabled;
|
|
1502
|
+
var onPanning = _this.props.onPanning;
|
|
1503
|
+
if (_this.isPanning && event.touches.length === 1) {
|
|
1504
|
+
if (disabled)
|
|
1505
|
+
return;
|
|
1506
|
+
var isAllowed = isPanningAllowed(_this);
|
|
1507
|
+
if (!isAllowed)
|
|
1508
|
+
return;
|
|
1509
|
+
event.preventDefault();
|
|
1510
|
+
event.stopPropagation();
|
|
1511
|
+
var touch = event.touches[0];
|
|
1512
|
+
handlePanning(_this, touch.clientX, touch.clientY);
|
|
1513
|
+
handleCallback(getContext(_this), event, onPanning);
|
|
1514
|
+
} else if (event.touches.length > 1) {
|
|
1515
|
+
_this.onPinch(event);
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
_this.onTouchPanningStop = function(event) {
|
|
1519
|
+
_this.onPanningStop(event);
|
|
1520
|
+
_this.onPinchStop(event);
|
|
1521
|
+
};
|
|
1522
|
+
_this.onDoubleClick = function(event) {
|
|
1523
|
+
var disabled = _this.setup.disabled;
|
|
1524
|
+
if (disabled)
|
|
1525
|
+
return;
|
|
1526
|
+
var isAllowed = isDoubleClickAllowed(_this, event);
|
|
1527
|
+
if (!isAllowed)
|
|
1528
|
+
return;
|
|
1529
|
+
handleDoubleClick(_this, event);
|
|
1530
|
+
};
|
|
1531
|
+
_this.clearPanning = function(event) {
|
|
1532
|
+
if (_this.isPanning) {
|
|
1533
|
+
_this.onPanningStop(event);
|
|
1534
|
+
}
|
|
1535
|
+
};
|
|
1536
|
+
_this.setKeyPressed = function(e) {
|
|
1537
|
+
_this.pressedKeys[e.key] = true;
|
|
1538
|
+
};
|
|
1539
|
+
_this.setKeyUnPressed = function(e) {
|
|
1540
|
+
_this.pressedKeys[e.key] = false;
|
|
1541
|
+
};
|
|
1542
|
+
_this.isPressingKeys = function(keys) {
|
|
1543
|
+
if (!keys.length) {
|
|
1544
|
+
return true;
|
|
1545
|
+
}
|
|
1546
|
+
return Boolean(keys.find(function(key) {
|
|
1547
|
+
return _this.pressedKeys[key];
|
|
1548
|
+
}));
|
|
1549
|
+
};
|
|
1550
|
+
_this.setComponents = function(wrapperComponent, contentComponent) {
|
|
1551
|
+
_this.wrapperComponent = wrapperComponent;
|
|
1552
|
+
_this.contentComponent = contentComponent;
|
|
1553
|
+
handleCalculateBounds(_this, _this.transformState.scale);
|
|
1554
|
+
_this.handleInitializeWrapperEvents(wrapperComponent);
|
|
1555
|
+
_this.handleInitialize();
|
|
1556
|
+
_this.handleRef();
|
|
1557
|
+
_this.isInitialized = true;
|
|
1558
|
+
handleCallback(getContext(_this), void 0, _this.props.onInit);
|
|
1559
|
+
};
|
|
1560
|
+
_this.setTransformState = function(scale, positionX, positionY) {
|
|
1561
|
+
if (!isNaN(scale) && !isNaN(positionX) && !isNaN(positionY)) {
|
|
1562
|
+
if (scale !== _this.transformState.scale) {
|
|
1563
|
+
_this.transformState.previousScale = _this.transformState.scale;
|
|
1564
|
+
_this.transformState.scale = scale;
|
|
1565
|
+
}
|
|
1566
|
+
_this.transformState.positionX = positionX;
|
|
1567
|
+
_this.transformState.positionY = positionY;
|
|
1568
|
+
_this.applyTransformation();
|
|
1569
|
+
} else {
|
|
1570
|
+
console.error("Detected NaN set state values");
|
|
1571
|
+
}
|
|
1572
|
+
};
|
|
1573
|
+
_this.setCenter = function() {
|
|
1574
|
+
if (_this.wrapperComponent && _this.contentComponent) {
|
|
1575
|
+
var targetState = getCenterPosition(_this.transformState.scale, _this.wrapperComponent, _this.contentComponent);
|
|
1576
|
+
_this.setTransformState(targetState.scale, targetState.positionX, targetState.positionY);
|
|
1577
|
+
}
|
|
1578
|
+
};
|
|
1579
|
+
_this.applyTransformation = function() {
|
|
1580
|
+
if (!_this.mounted || !_this.contentComponent)
|
|
1581
|
+
return;
|
|
1582
|
+
var _a = _this.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
1583
|
+
var transform = getTransformStyles(positionX, positionY, scale);
|
|
1584
|
+
_this.contentComponent.style.transform = transform;
|
|
1585
|
+
_this.handleRef();
|
|
1586
|
+
};
|
|
1587
|
+
_this.handleRef = function() {
|
|
1588
|
+
_this.props.setRef(getContext(_this));
|
|
1589
|
+
};
|
|
1590
|
+
return _this;
|
|
1591
|
+
}
|
|
1592
|
+
TransformContext2.prototype.componentDidMount = function() {
|
|
1593
|
+
var passive = makePassiveEventOption();
|
|
1594
|
+
window.addEventListener("mousedown", this.onPanningStart, passive);
|
|
1595
|
+
window.addEventListener("mousemove", this.onPanning, passive);
|
|
1596
|
+
window.addEventListener("mouseup", this.onPanningStop, passive);
|
|
1597
|
+
document.addEventListener("mouseleave", this.clearPanning, passive);
|
|
1598
|
+
window.addEventListener("keyup", this.setKeyUnPressed, passive);
|
|
1599
|
+
window.addEventListener("keydown", this.setKeyPressed, passive);
|
|
1600
|
+
this.handleRef();
|
|
1601
|
+
};
|
|
1602
|
+
TransformContext2.prototype.componentWillUnmount = function() {
|
|
1603
|
+
var passive = makePassiveEventOption();
|
|
1604
|
+
window.removeEventListener("mousedown", this.onPanningStart, passive);
|
|
1605
|
+
window.removeEventListener("mousemove", this.onPanning, passive);
|
|
1606
|
+
window.removeEventListener("mouseup", this.onPanningStop, passive);
|
|
1607
|
+
window.removeEventListener("keyup", this.setKeyUnPressed, passive);
|
|
1608
|
+
window.removeEventListener("keydown", this.setKeyPressed, passive);
|
|
1609
|
+
handleCancelAnimation(this);
|
|
1610
|
+
};
|
|
1611
|
+
TransformContext2.prototype.componentDidUpdate = function(oldProps) {
|
|
1612
|
+
if (oldProps !== this.props) {
|
|
1613
|
+
handleCalculateBounds(this, this.transformState.scale);
|
|
1614
|
+
this.setup = createSetup(this.props);
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
TransformContext2.prototype.render = function() {
|
|
1618
|
+
var value = getContext(this);
|
|
1619
|
+
var children = this.props.children;
|
|
1620
|
+
var content = typeof children === "function" ? children(value) : children;
|
|
1621
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
1622
|
+
value: __assign(__assign({}, this.transformState), {
|
|
1623
|
+
setComponents: this.setComponents,
|
|
1624
|
+
contextInstance: this
|
|
1625
|
+
}),
|
|
1626
|
+
children: content
|
|
1627
|
+
});
|
|
1628
|
+
};
|
|
1629
|
+
return TransformContext2;
|
|
1630
|
+
}(Component);
|
|
1631
|
+
var TransformWrapper = React.forwardRef(function(props, ref) {
|
|
1632
|
+
var _a = useState(null), innerRef = _a[0], setRef = _a[1];
|
|
1633
|
+
useImperativeHandle(ref, function() {
|
|
1634
|
+
return innerRef;
|
|
1635
|
+
}, [innerRef]);
|
|
1636
|
+
return /* @__PURE__ */ jsx(TransformContext, __spreadValues({}, __assign({}, props, {
|
|
1637
|
+
setRef
|
|
1638
|
+
})));
|
|
1639
|
+
});
|
|
1640
|
+
function styleInject(css, ref) {
|
|
1641
|
+
if (ref === void 0)
|
|
1642
|
+
ref = {};
|
|
1643
|
+
var insertAt = ref.insertAt;
|
|
1644
|
+
if (!css || typeof document === "undefined") {
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1647
|
+
var head = document.head || document.getElementsByTagName("head")[0];
|
|
1648
|
+
var style = document.createElement("style");
|
|
1649
|
+
style.type = "text/css";
|
|
1650
|
+
if (insertAt === "top") {
|
|
1651
|
+
if (head.firstChild) {
|
|
1652
|
+
head.insertBefore(style, head.firstChild);
|
|
1653
|
+
} else {
|
|
1654
|
+
head.appendChild(style);
|
|
1655
|
+
}
|
|
1656
|
+
} else {
|
|
1657
|
+
head.appendChild(style);
|
|
1658
|
+
}
|
|
1659
|
+
if (style.styleSheet) {
|
|
1660
|
+
style.styleSheet.cssText = css;
|
|
1661
|
+
} else {
|
|
1662
|
+
style.appendChild(document.createTextNode(css));
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
var css_248z = ".transform-component-module_wrapper__1_Fgj {\n position: relative;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: fit-content;\n overflow: hidden;\n -webkit-touch-callout: none; /* iOS Safari */\n -webkit-user-select: none; /* Safari */\n -khtml-user-select: none; /* Konqueror HTML */\n -moz-user-select: none; /* Firefox */\n -ms-user-select: none; /* Internet Explorer/Edge */\n user-select: none;\n margin: 0;\n padding: 0;\n}\n.transform-component-module_content__2jYgh {\n display: flex;\n flex-wrap: wrap;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: fit-content;\n margin: 0;\n padding: 0;\n transform-origin: 0% 0%;\n}\n.transform-component-module_content__2jYgh img {\n pointer-events: none;\n}\n";
|
|
1666
|
+
var styles$1 = {
|
|
1667
|
+
"wrapper": "transform-component-module_wrapper__1_Fgj",
|
|
1668
|
+
"content": "transform-component-module_content__2jYgh"
|
|
1669
|
+
};
|
|
1670
|
+
styleInject(css_248z);
|
|
1671
|
+
var TransformComponent = function(_a) {
|
|
1672
|
+
var children = _a.children, _b = _a.wrapperClass, wrapperClass = _b === void 0 ? "" : _b, _c = _a.contentClass, contentClass = _c === void 0 ? "" : _c, wrapperStyle = _a.wrapperStyle, contentStyle = _a.contentStyle;
|
|
1673
|
+
var setComponents = useContext(Context).setComponents;
|
|
1674
|
+
var wrapperRef = useRef(null);
|
|
1675
|
+
var contentRef = useRef(null);
|
|
1676
|
+
useEffect(function() {
|
|
1677
|
+
var wrapper = wrapperRef.current;
|
|
1678
|
+
var content = contentRef.current;
|
|
1679
|
+
if (wrapper !== null && content !== null && setComponents) {
|
|
1680
|
+
setComponents(wrapper, content);
|
|
1681
|
+
}
|
|
1682
|
+
}, []);
|
|
1683
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1684
|
+
ref: wrapperRef,
|
|
1685
|
+
className: "react-transform-wrapper " + styles$1.wrapper + " " + wrapperClass,
|
|
1686
|
+
style: wrapperStyle,
|
|
1687
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1688
|
+
ref: contentRef,
|
|
1689
|
+
className: "react-transform-component " + styles$1.content + " " + contentClass,
|
|
1690
|
+
style: contentStyle,
|
|
1691
|
+
children
|
|
1692
|
+
})
|
|
1693
|
+
});
|
|
1694
|
+
};
|
|
1695
|
+
const extraStyle = `
|
|
1696
|
+
.lds-dual-ring {
|
|
1697
|
+
display: inline-block;
|
|
1698
|
+
width: 40px;
|
|
1699
|
+
height: 40px;
|
|
1700
|
+
}
|
|
1701
|
+
.lds-dual-ring:after {
|
|
1702
|
+
content: " ";
|
|
1703
|
+
display: block;
|
|
1704
|
+
width: 32px;
|
|
1705
|
+
height: 32px;
|
|
1706
|
+
margin: 8px;
|
|
1707
|
+
border-radius: 50%;
|
|
1708
|
+
border: 3px solid rgba(185, 185, 185, 0.466);
|
|
1709
|
+
border-color: rgba(185, 185, 185, 0.466) transparent rgba(185, 185, 185, 0.466) transparent;
|
|
1710
|
+
animation: lds-dual-ring 1.2s linear infinite;
|
|
1711
|
+
}
|
|
1712
|
+
@keyframes lds-dual-ring {
|
|
1713
|
+
0% {
|
|
1714
|
+
transform: rotate(0deg);
|
|
1715
|
+
}
|
|
1716
|
+
100% {
|
|
1717
|
+
transform: rotate(360deg);
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
`;
|
|
1721
|
+
function CircularLoading() {
|
|
1722
|
+
const styleTag = document.querySelector("#react-pic-style");
|
|
1723
|
+
if (!styleTag) {
|
|
1724
|
+
const sheet = document.createElement("style");
|
|
1725
|
+
sheet.id = "react-pic-style";
|
|
1726
|
+
sheet.innerHTML = extraStyle;
|
|
1727
|
+
document.body.appendChild(sheet);
|
|
1728
|
+
} else {
|
|
1729
|
+
styleTag.innerHTML = styleTag.innerHTML + extraStyle;
|
|
1730
|
+
}
|
|
1731
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1732
|
+
className: "lds-dual-ring"
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1735
|
+
let styles = {};
|
|
1736
|
+
styles.lightbox = {
|
|
1737
|
+
position: "fixed",
|
|
1738
|
+
top: 0,
|
|
1739
|
+
left: 0,
|
|
1740
|
+
width: "100%",
|
|
1741
|
+
height: "100%",
|
|
1742
|
+
background: `rgba(0, 0, 0, 0.454)`,
|
|
1743
|
+
backdropFilter: "blur(6px)",
|
|
1744
|
+
zIndex: 9999999,
|
|
1745
|
+
display: "grid",
|
|
1746
|
+
gridTemplateRows: "60px | auto | 300px",
|
|
1747
|
+
justifyContent: "center",
|
|
1748
|
+
alignContent: "center"
|
|
1749
|
+
};
|
|
1750
|
+
styles.topCustomContent = {
|
|
1751
|
+
position: "absolute",
|
|
1752
|
+
top: 0
|
|
1753
|
+
};
|
|
1754
|
+
styles.bottomCustomContent = {
|
|
1755
|
+
position: "absolute",
|
|
1756
|
+
bottom: 0
|
|
1757
|
+
};
|
|
1758
|
+
styles.LbButton = {
|
|
1759
|
+
float: "right",
|
|
1760
|
+
textDecoration: "none",
|
|
1761
|
+
color: "white",
|
|
1762
|
+
padding: "5px",
|
|
1763
|
+
border: "1px solid white",
|
|
1764
|
+
borderRadius: "5px"
|
|
1765
|
+
};
|
|
1766
|
+
styles.ABtn = {
|
|
1767
|
+
float: "right",
|
|
1768
|
+
textDecoration: "none",
|
|
1769
|
+
color: "white"
|
|
1770
|
+
};
|
|
1771
|
+
styles.DescriptionDiv = {
|
|
1772
|
+
background: "white",
|
|
1773
|
+
padding: "10px",
|
|
1774
|
+
color: "#666",
|
|
1775
|
+
textAlign: "center",
|
|
1776
|
+
position: "relative",
|
|
1777
|
+
zIndex: -1
|
|
1778
|
+
};
|
|
1779
|
+
styles.Wrapper = {
|
|
1780
|
+
display: "flex",
|
|
1781
|
+
width: "100%",
|
|
1782
|
+
minWidth: 200,
|
|
1783
|
+
height: "100%"
|
|
1784
|
+
};
|
|
1785
|
+
styles.Grid = {
|
|
1786
|
+
display: "grid",
|
|
1787
|
+
gridTemplateRows: "1fr",
|
|
1788
|
+
gap: "2px",
|
|
1789
|
+
width: "100%",
|
|
1790
|
+
height: "auto"
|
|
1791
|
+
};
|
|
1792
|
+
const ImgLightbox = (props) => {
|
|
1793
|
+
var _a, _b, _c, _d, _e;
|
|
1794
|
+
const [imgSrcUrl, setImgSrcUrl] = React.useState("");
|
|
1795
|
+
const Loading = ((_a = props.options) == null ? void 0 : _a.customLoadComponent) !== void 0 ? props.options.customLoadComponent : CircularLoading;
|
|
1796
|
+
React.useEffect(() => {
|
|
1797
|
+
var _a2, _b2;
|
|
1798
|
+
const imgSrc = ((_a2 = props.imgObj) == null ? void 0 : _a2.fullSrc) ? props.imgObj.fullSrc : ((_b2 = props.imgObj) == null ? void 0 : _b2.thumbnailSrc) ? props.imgObj.thumbnailSrc : null;
|
|
1799
|
+
if (imgSrc) {
|
|
1800
|
+
fetch(imgSrc).then((response) => response.blob()).then((blob) => {
|
|
1801
|
+
setImgSrcUrl(URL.createObjectURL(blob));
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
document.body.style.overflow = "hidden";
|
|
1805
|
+
}, [props.imgObj]);
|
|
1806
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1807
|
+
className: "reactPic-lightbox",
|
|
1808
|
+
style: styles.lightbox,
|
|
1809
|
+
onClick: (event) => {
|
|
1810
|
+
document.body.style.overflow = "";
|
|
1811
|
+
const target = event.target;
|
|
1812
|
+
if (target.className === "reactPic-lightbox") {
|
|
1813
|
+
props.onClose();
|
|
1814
|
+
}
|
|
1815
|
+
},
|
|
1816
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
1817
|
+
style: styles.topCustomContent,
|
|
1818
|
+
className: "reactPic-topCustomContent",
|
|
1819
|
+
children: (_b = props.topCustomContent) == null ? void 0 : _b.call(props, {
|
|
1820
|
+
closeLightbox: props.onClose,
|
|
1821
|
+
imgObject: props.imgObj
|
|
1822
|
+
})
|
|
1823
|
+
}), imgSrcUrl === "" ? /* @__PURE__ */ jsx("div", {
|
|
1824
|
+
style: {
|
|
1825
|
+
display: "block",
|
|
1826
|
+
margin: "auto"
|
|
1827
|
+
},
|
|
1828
|
+
children: /* @__PURE__ */ jsx(Loading, {})
|
|
1829
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
1830
|
+
children: [/* @__PURE__ */ jsx(TransformWrapper, {
|
|
1831
|
+
children: /* @__PURE__ */ jsx(TransformComponent, {
|
|
1832
|
+
children: /* @__PURE__ */ jsx("img", {
|
|
1833
|
+
src: imgSrcUrl,
|
|
1834
|
+
alt: "",
|
|
1835
|
+
id: "lightboxImg",
|
|
1836
|
+
style: {
|
|
1837
|
+
maxWidth: "80vw",
|
|
1838
|
+
maxHeight: "calc(80vh - 20px)",
|
|
1839
|
+
margin: "auto",
|
|
1840
|
+
zIndex: 99999999999
|
|
1841
|
+
}
|
|
1842
|
+
})
|
|
1843
|
+
})
|
|
1844
|
+
}), props.onClickPrevious && /* @__PURE__ */ jsx("div", {
|
|
1845
|
+
className: "react-lightbox-prevBtn",
|
|
1846
|
+
style: {
|
|
1847
|
+
position: "absolute",
|
|
1848
|
+
left: 20,
|
|
1849
|
+
top: "50%",
|
|
1850
|
+
fontSize: 50,
|
|
1851
|
+
cursor: "pointer",
|
|
1852
|
+
color: "white",
|
|
1853
|
+
display: ((_c = props.options) == null ? void 0 : _c.hidePagination) ? "none" : "inherit"
|
|
1854
|
+
},
|
|
1855
|
+
onClick: props.onClickPrevious,
|
|
1856
|
+
children: "\u2039"
|
|
1857
|
+
}), props.onClickNext && /* @__PURE__ */ jsx("div", {
|
|
1858
|
+
className: "react-lightbox-nextBtn",
|
|
1859
|
+
style: {
|
|
1860
|
+
position: "absolute",
|
|
1861
|
+
right: 20,
|
|
1862
|
+
top: "50%",
|
|
1863
|
+
fontSize: 50,
|
|
1864
|
+
cursor: "pointer",
|
|
1865
|
+
color: "white",
|
|
1866
|
+
display: ((_d = props.options) == null ? void 0 : _d.hidePagination) ? "none" : "inherit"
|
|
1867
|
+
},
|
|
1868
|
+
onClick: props.onClickNext,
|
|
1869
|
+
children: "\u203A"
|
|
1870
|
+
})]
|
|
1871
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1872
|
+
style: styles.bottomCustomContent,
|
|
1873
|
+
className: "reactPic-bottomCustomContent",
|
|
1874
|
+
children: (_e = props.bottomCustomContent) == null ? void 0 : _e.call(props, {
|
|
1875
|
+
closeLightbox: props.onClose,
|
|
1876
|
+
imgObject: props.imgObj
|
|
1877
|
+
})
|
|
1878
|
+
})]
|
|
1879
|
+
});
|
|
1880
|
+
};
|
|
1881
|
+
const ImgLazyLoading = (props) => {
|
|
1882
|
+
var _a;
|
|
1883
|
+
const [imgSrcUrl, setImgSrcUrl] = React.useState("");
|
|
1884
|
+
const Loading = ((_a = props.options) == null ? void 0 : _a.customLoadComponent) !== void 0 ? props.options.customLoadComponent : CircularLoading;
|
|
1885
|
+
React.useEffect(() => {
|
|
1886
|
+
const ac = new AbortController();
|
|
1887
|
+
if (props.imgSrc) {
|
|
1888
|
+
fetch(props.imgSrc).then((response) => response.blob()).then((blob) => {
|
|
1889
|
+
setImgSrcUrl(URL.createObjectURL(blob));
|
|
1890
|
+
});
|
|
1891
|
+
}
|
|
1892
|
+
return () => {
|
|
1893
|
+
ac.abort();
|
|
1894
|
+
};
|
|
1895
|
+
}, [props.imgSrc]);
|
|
1896
|
+
if (imgSrcUrl) {
|
|
1897
|
+
return /* @__PURE__ */ jsx("img", {
|
|
1898
|
+
src: imgSrcUrl,
|
|
1899
|
+
alt: "",
|
|
1900
|
+
style: __spreadValues({}, props.style),
|
|
1901
|
+
onClick: () => {
|
|
1902
|
+
props.onClick();
|
|
1903
|
+
}
|
|
1904
|
+
});
|
|
1905
|
+
} else {
|
|
1906
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1907
|
+
style: {
|
|
1908
|
+
height: "100%",
|
|
1909
|
+
width: "100%",
|
|
1910
|
+
display: "flex",
|
|
1911
|
+
alignItems: "center",
|
|
1912
|
+
alignContent: "center",
|
|
1913
|
+
justifyContent: "center",
|
|
1914
|
+
background: "rgba(0, 0, 0, 0.157)",
|
|
1915
|
+
border: "1px solid rgba(0, 0, 0,0.3)"
|
|
1916
|
+
},
|
|
1917
|
+
children: /* @__PURE__ */ jsx(Loading, {})
|
|
1918
|
+
});
|
|
1919
|
+
}
|
|
1920
|
+
};
|
|
1921
|
+
function ImgGallery(props) {
|
|
1922
|
+
var _a;
|
|
1923
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1924
|
+
className: "reactPic-grid",
|
|
1925
|
+
style: __spreadProps(__spreadValues({}, styles.Grid), {
|
|
1926
|
+
gridTemplateColumns: `repeat(${((_a = props.options) == null ? void 0 : _a.picsPerRow) ? props.options.picsPerRow : "3"}, 1fr)`
|
|
1927
|
+
}),
|
|
1928
|
+
children: props.imgList.map((element, index) => {
|
|
1929
|
+
var _a2;
|
|
1930
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1931
|
+
className: "reactPic-imgDiv",
|
|
1932
|
+
style: {
|
|
1933
|
+
overflow: "hidden",
|
|
1934
|
+
width: "100%",
|
|
1935
|
+
height: "100%",
|
|
1936
|
+
minHeight: "150px"
|
|
1937
|
+
},
|
|
1938
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1939
|
+
className: "reactPic-innerImgDiv",
|
|
1940
|
+
style: {
|
|
1941
|
+
display: "flex",
|
|
1942
|
+
justifyContent: "center",
|
|
1943
|
+
alignItems: "center",
|
|
1944
|
+
overflow: "hidden !important",
|
|
1945
|
+
width: "100%",
|
|
1946
|
+
height: ((_a2 = props.options) == null ? void 0 : _a2.rowHeight) ? props.options.rowHeight : "150px",
|
|
1947
|
+
cursor: "pointer"
|
|
1948
|
+
},
|
|
1949
|
+
children: /* @__PURE__ */ jsx(ImgLazyLoading, {
|
|
1950
|
+
options: props.options,
|
|
1951
|
+
imgSrc: element.thumbnailSrc ? element.thumbnailSrc : element.fullSrc,
|
|
1952
|
+
style: {
|
|
1953
|
+
flexShrink: 0,
|
|
1954
|
+
minWidth: "100%",
|
|
1955
|
+
minHeight: "100%"
|
|
1956
|
+
},
|
|
1957
|
+
onClick: () => props.onOpen(index)
|
|
1958
|
+
})
|
|
1959
|
+
})
|
|
1960
|
+
}, element.thumbnailSrc ? element.thumbnailSrc : element.fullSrc);
|
|
1961
|
+
})
|
|
1962
|
+
});
|
|
1963
|
+
}
|
|
1964
|
+
var ImgGallery$1 = React.memo(ImgGallery);
|
|
1965
|
+
const defaultOptions = {
|
|
1966
|
+
downloadBtnDisplay: true,
|
|
1967
|
+
descriptionBoxDisplay: true,
|
|
1968
|
+
navigation: true
|
|
1969
|
+
};
|
|
1970
|
+
function PicGallery(props) {
|
|
1971
|
+
var _a;
|
|
1972
|
+
const [open, setOpen] = useState(false);
|
|
1973
|
+
const [modalImgIndex, setModalImgIndex] = useState(0);
|
|
1974
|
+
const options = __spreadValues(__spreadValues({}, defaultOptions), props.options);
|
|
1975
|
+
useEffect(() => {
|
|
1976
|
+
if (typeof props.setExtLightboxChildren == "function") {
|
|
1977
|
+
if (open) {
|
|
1978
|
+
props.setExtLightboxChildren(/* @__PURE__ */ jsx(ImgLightbox, {
|
|
1979
|
+
imgObj: props.imgList[modalImgIndex],
|
|
1980
|
+
options,
|
|
1981
|
+
onClose: () => {
|
|
1982
|
+
setOpen(false);
|
|
1983
|
+
}
|
|
1984
|
+
}));
|
|
1985
|
+
} else {
|
|
1986
|
+
props.setExtLightboxChildren(void 0);
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
}, [open]);
|
|
1990
|
+
const onOpen = useCallback((count) => {
|
|
1991
|
+
setModalImgIndex(count);
|
|
1992
|
+
setOpen(true);
|
|
1993
|
+
}, []);
|
|
1994
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1995
|
+
className: "reactPic-wrapper",
|
|
1996
|
+
style: styles.Wrapper,
|
|
1997
|
+
children: [open && !((_a = props.options) == null ? void 0 : _a.externalLightbox) ? /* @__PURE__ */ jsx(ImgLightbox, {
|
|
1998
|
+
imgObj: props.imgList[modalImgIndex],
|
|
1999
|
+
topCustomContent: props.topCustomContent,
|
|
2000
|
+
bottomCustomContent: props.bottomCustomContent,
|
|
2001
|
+
options,
|
|
2002
|
+
onClose: () => setOpen(false),
|
|
2003
|
+
onClickPrevious: modalImgIndex - 1 >= 0 ? () => setModalImgIndex(modalImgIndex - 1) : void 0,
|
|
2004
|
+
onClickNext: modalImgIndex + 1 < props.imgList.length ? () => setModalImgIndex(modalImgIndex + 1) : void 0
|
|
2005
|
+
}) : null, /* @__PURE__ */ jsx(ImgGallery$1, {
|
|
2006
|
+
options: props.options,
|
|
2007
|
+
imgList: props.imgList,
|
|
2008
|
+
onOpen
|
|
2009
|
+
})]
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
2012
|
+
export { PicGallery as default };
|