js-cloudimage-360-view 3.2.1 → 4.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/.prettierrc +9 -0
  2. package/README.md +318 -721
  3. package/dist/js-cloudimage-360-view.min.css +1 -0
  4. package/dist/js-cloudimage-360-view.min.js +2111 -0
  5. package/package.json +30 -17
  6. package/.env +0 -3
  7. package/CHANGELOG.md +0 -175
  8. package/bin/deploy-bundle.js +0 -63
  9. package/dist/ci360.service.js +0 -1270
  10. package/dist/ci360.utils.js +0 -78
  11. package/dist/constants/auto-play-behavior.js +0 -13
  12. package/dist/constants/falsy-values.js +0 -8
  13. package/dist/constants/index.js +0 -39
  14. package/dist/constants/orientations.js +0 -12
  15. package/dist/constants/props-require-reload.js +0 -33
  16. package/dist/constants/regex.js +0 -10
  17. package/dist/index.js +0 -102
  18. package/dist/static/css/hotspots.css +0 -222
  19. package/dist/static/css/style.css +0 -230
  20. package/dist/utils/auto-play/get-speed-factor.js +0 -12
  21. package/dist/utils/auto-play/is-completed-one-cycle.js +0 -27
  22. package/dist/utils/auto-play/loop.js +0 -56
  23. package/dist/utils/class-names/add-class.js +0 -15
  24. package/dist/utils/class-names/remove-class.js +0 -14
  25. package/dist/utils/container-elements/apply-styles-to-container.js +0 -14
  26. package/dist/utils/container-elements/create-360-view-circle-icon.js +0 -14
  27. package/dist/utils/container-elements/create-360-view-icon.js +0 -13
  28. package/dist/utils/container-elements/create-box-shadow.js +0 -14
  29. package/dist/utils/container-elements/create-canvas.js +0 -14
  30. package/dist/utils/container-elements/create-close-fullscreen-icon.js +0 -12
  31. package/dist/utils/container-elements/create-fullscreen-icon.js +0 -12
  32. package/dist/utils/container-elements/create-fullscreen-modal.js +0 -18
  33. package/dist/utils/container-elements/create-icons-container.js +0 -13
  34. package/dist/utils/container-elements/create-inner-box.js +0 -13
  35. package/dist/utils/container-elements/create-loader.js +0 -13
  36. package/dist/utils/container-elements/create-magnifier-icon.js +0 -12
  37. package/dist/utils/container-elements/index.js +0 -96
  38. package/dist/utils/container-elements/remove-child-from-parent.js +0 -14
  39. package/dist/utils/controls/get-item-skipped.js +0 -11
  40. package/dist/utils/controls/init-controls.js +0 -68
  41. package/dist/utils/hotspots/attach-events/hide-popup.js +0 -13
  42. package/dist/utils/hotspots/attach-events/show-popup.js +0 -12
  43. package/dist/utils/hotspots/configs-error-handler.js +0 -23
  44. package/dist/utils/hotspots/create-popper-instace.js +0 -29
  45. package/dist/utils/hotspots/elements/create-carousel-dot.js +0 -20
  46. package/dist/utils/hotspots/elements/create-carousel-image.js +0 -18
  47. package/dist/utils/hotspots/elements/create-hotspot-icon.js +0 -55
  48. package/dist/utils/hotspots/elements/create-hotspot-popup-link.js +0 -19
  49. package/dist/utils/hotspots/elements/create-hotspots.js +0 -20
  50. package/dist/utils/hotspots/elements/create-images-carousel.js +0 -23
  51. package/dist/utils/hotspots/elements/create-modal-description.js +0 -13
  52. package/dist/utils/hotspots/elements/create-modal-title.js +0 -13
  53. package/dist/utils/hotspots/elements/create-model-elements.js +0 -49
  54. package/dist/utils/hotspots/elements/create-popup-arrow.js +0 -14
  55. package/dist/utils/hotspots/elements/create-popup.js +0 -55
  56. package/dist/utils/hotspots/elements/create-read-more-btn.js +0 -15
  57. package/dist/utils/hotspots/fill-empty-coord-with-previous.js +0 -21
  58. package/dist/utils/hotspots/generate-hotspots-configs.js +0 -48
  59. package/dist/utils/hotspots/generate-popup-config.js +0 -27
  60. package/dist/utils/hotspots/get-hotspot-icon.js +0 -12
  61. package/dist/utils/hotspots/get-hotspot-orientation.js +0 -17
  62. package/dist/utils/hotspots/get-hotspot-popup-node.js +0 -12
  63. package/dist/utils/hotspots/get-popup-node.js +0 -12
  64. package/dist/utils/hotspots/hide-hotspot-icon.js +0 -11
  65. package/dist/utils/hotspots/hide-hotspots-icons.js +0 -15
  66. package/dist/utils/hotspots/is-mouse-on-hotspot.js +0 -12
  67. package/dist/utils/hotspots/prepare-hotspots-positions.js +0 -22
  68. package/dist/utils/hotspots/set-current-slide.js +0 -21
  69. package/dist/utils/hotspots/toggle-popup-events.js +0 -19
  70. package/dist/utils/hotspots/update-hotspot-icon-position.js +0 -19
  71. package/dist/utils/hotspots/update-hotspots.js +0 -40
  72. package/dist/utils/image-src/generate-images-path.js +0 -33
  73. package/dist/utils/image-src/is-props-change-require-reload.js +0 -18
  74. package/dist/utils/index.js +0 -211
  75. package/dist/utils/load-images/images-from-folder/prepare-images-from-folder.js +0 -25
  76. package/dist/utils/load-images/images-from-list/prepare-images-from-list.js +0 -21
  77. package/dist/utils/load-images/lazyload/init-lazyload.js +0 -41
  78. package/dist/utils/load-images/lazyload/prepare-first-image/prepare-first-image-from-folder.js +0 -14
  79. package/dist/utils/load-images/lazyload/prepare-first-image/prepare-first-image-from-list.js +0 -20
  80. package/dist/utils/load-images/load-image-as-promise.js +0 -16
  81. package/dist/utils/load-images/load-images-relative-to-container-size.js +0 -19
  82. package/dist/utils/load-images/load-original-images.js +0 -44
  83. package/dist/utils/load-images/pad.js +0 -12
  84. package/dist/utils/load-images/preload-images.js +0 -28
  85. package/dist/utils/load-images/preload-original-images.js +0 -28
  86. package/dist/utils/magnify/get-current-original-image.js +0 -23
  87. package/dist/utils/magnify/get-cursor-position.js +0 -22
  88. package/dist/utils/magnify/magnify.js +0 -47
  89. package/dist/utils/magnify/move-magnifier.js +0 -39
  90. package/dist/utils/responsive/contain.js +0 -9
  91. package/dist/utils/responsive/fit.js +0 -29
  92. package/dist/utils/responsive/get-image-aspect-ratio.js +0 -31
  93. package/dist/utils/responsive/get-responsive-width-of-container.js +0 -11
  94. package/dist/utils/responsive/get-size-according-to-pixel-ratio.js +0 -15
  95. package/dist/utils/responsive/get-size-limit.js +0 -12
  96. package/dist/utils/spin-y/get-moving-direction.js +0 -18
  97. package/dist/utils/zoom/generate-zoom-in-steps.js +0 -18
  98. package/dist/utils/zoom/generate-zoom-out-steps.js +0 -18
  99. package/yarn-error.log +0 -101
@@ -1,1270 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _ci = require("./ci360.utils");
12
- var _constants = require("./constants/");
13
- require("./static/css/style.css");
14
- require("./static/css/hotspots.css");
15
- var _utils = require("./utils");
16
- var _togglePopupEvents = require("./utils/hotspots/toggle-popup-events");
17
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
- var CI360Viewer = /*#__PURE__*/function () {
20
- function CI360Viewer(container, fullscreen, hotspotsConfigs) {
21
- (0, _classCallCheck2.default)(this, CI360Viewer);
22
- this.container = container;
23
- this.movementStart = {
24
- x: 0,
25
- y: 0
26
- };
27
- this.isStartSpin = false;
28
- this.movingDirection = _constants.ORIENTATIONS.CENTER;
29
- this.isClicked = false;
30
- this.loadedImagesX = 0;
31
- this.loadedImagesY = 0;
32
- this.imagesLoaded = false;
33
- this.reversed = false;
34
- this.fullscreenView = !!fullscreen;
35
- this.imagesX = [];
36
- this.imagesY = [];
37
- this.originalImagesX = [];
38
- this.originalImagesY = [];
39
- this.resizedImagesX = [];
40
- this.resizedImagesY = [];
41
- this.devicePixelRatio = Math.round(window.devicePixelRatio || 1);
42
- this.isMobile = !!('ontouchstart' in window || navigator.msMaxTouchPoints);
43
- this.id = container.id;
44
- this.hotspotsConfigs = hotspotsConfigs && (0, _utils.generateHotspotsConfigs)(hotspotsConfigs);
45
- this.isMagnifyOpen = false;
46
- this.isDragged = false;
47
- this.startPointerZoom = false;
48
- this.zoomIntensity = 0;
49
- this.mouseTracked = false;
50
- this.intialPositions = {
51
- x: 0,
52
- y: 0
53
- };
54
- this.pointerCurrentPosition = {
55
- x: 0,
56
- y: 0
57
- };
58
- this.isStartedLoadOriginalImages = false;
59
- this.init(container);
60
- }
61
- (0, _createClass2.default)(CI360Viewer, [{
62
- key: "isReady",
63
- value: function isReady() {
64
- var totalAmount = this.amountX + this.amountY;
65
- return this.imagesX.length + this.imagesY.length === totalAmount;
66
- }
67
- }, {
68
- key: "mouseDown",
69
- value: function mouseDown(event) {
70
- if (!this.imagesLoaded) return;
71
- var isMouseOnHotspotElement = (0, _utils.isMouseOnHotspot)();
72
- var pageX = event.pageX,
73
- pageY = event.pageY;
74
- this.hideInitialIcons();
75
- if (this.autoplay || this.loopTimeoutId) {
76
- this.stop();
77
- this.autoplay = false;
78
- this.isZoomReady = true;
79
- }
80
- this.intialPositions = {
81
- x: pageX,
82
- y: pageY
83
- };
84
- this.movementStart = {
85
- x: pageX,
86
- y: pageY
87
- };
88
- this.isClicked = true;
89
- this.isDragged = false;
90
- if (this.hotspotsConfigs) {
91
- (0, _togglePopupEvents.togglePopupEvents)(this.hotspotsConfigs, event, true);
92
- }
93
- if (isMouseOnHotspotElement) {
94
- this.isClicked = false;
95
- }
96
- if (this.hotspotsConfigs) {
97
- (0, _utils.updateHotspots)(this.container, this.hotspotsConfigs, this.activeImageX, this.activeImageY, this.movingDirection);
98
- }
99
- }
100
- }, {
101
- key: "mouseUp",
102
- value: function mouseUp() {
103
- var _this = this;
104
- if (!this.imagesLoaded || !this.isClicked) return;
105
- this.movementStart = {
106
- x: 0,
107
- y: 0
108
- };
109
- this.isStartSpin = false;
110
- this.isClicked = false;
111
- if (this.bottomCircle && !this.mouseTracked) {
112
- this.show360ViewCircleIcon();
113
- }
114
- if (this.hotspotsConfigs) {
115
- (0, _togglePopupEvents.togglePopupEvents)(this.hotspotsConfigs);
116
- }
117
- if (this.pointerZoom && !this.fullscreenView) {
118
- setTimeout(function () {
119
- _this.isZoomReady = true;
120
- }, 50);
121
- if (this.mouseTracked) {
122
- this.container.style.cursor = 'zoom-out';
123
- } else {
124
- this.container.style.cursor = 'zoom-in';
125
- }
126
- } else {
127
- this.container.style.cursor = 'grab';
128
- }
129
- }
130
- }, {
131
- key: "mouseClick",
132
- value: function mouseClick(event) {
133
- if (!this.pointerZoom || this.fullscreenView) return;
134
- this.setCursorPosition(event);
135
- this.hideInitialIcons();
136
- if (!this.isStartedLoadOriginalImages && !this.isDragged && this.isZoomReady) {
137
- this.prepareOriginalImages(event);
138
- }
139
- if (this.isAllOriginalImagesLoaded && !this.isDragged && this.isZoomReady) {
140
- this.togglePointerZoom(event);
141
- }
142
- ;
143
- }
144
- }, {
145
- key: "mouseMove",
146
- value: function mouseMove(event) {
147
- if (!this.imagesLoaded) return;
148
- var pageX = event.pageX,
149
- pageY = event.pageY;
150
- if (this.mouseTracked) {
151
- this.setCursorPosition(event);
152
- if (!this.isClicked) {
153
- this.update();
154
- }
155
- }
156
- if (this.isClicked) {
157
- var nextPositions = {
158
- x: pageX,
159
- y: pageY
160
- };
161
- this.container.style.cursor = 'grabbing';
162
- this.isDragged = true;
163
- this.movingDirection = (0, _utils.getMovingDirection)(this.isStartSpin, this.allowSpinY, this.intialPositions, nextPositions, this.movingDirection);
164
- this.onMoveHandler(event);
165
- }
166
- }
167
- }, {
168
- key: "mouseLeave",
169
- value: function mouseLeave() {
170
- if (!this.imagesLoaded) return;
171
- if (this.pointerZoom && this.mouseTracked) {
172
- this.togglePointerZoom();
173
- }
174
- if (this.isMagnifyOpen) {
175
- this.closeMagnifier();
176
- }
177
- }
178
- }, {
179
- key: "togglePointerZoom",
180
- value: function togglePointerZoom() {
181
- var _this2 = this;
182
- if (this.autoplay || this.loopTimeoutId) {
183
- this.stop();
184
- this.autoplay = false;
185
- }
186
- if (this.mouseTracked) {
187
- var zoomSteps = (0, _utils.generateZoomOutSteps)(this.pointerZoom);
188
- this.container.style.cursor = 'zoom-in';
189
- zoomSteps.forEach(function (step, index) {
190
- setTimeout(function () {
191
- _this2.zoomIntensity = step;
192
- _this2.update();
193
- var isReachedIntialScale = index === zoomSteps.length - 1;
194
- if (isReachedIntialScale) {
195
- _this2.mouseTracked = false;
196
- _this2.update();
197
- }
198
- ;
199
- }, (_this2.pointerZoom - step) * 200);
200
- });
201
- } else {
202
- if (this.bottomCircle) this.hide360ViewCircleIcon();
203
- var _zoomSteps = (0, _utils.generateZoomInSteps)(this.pointerZoom);
204
- if (this.hotspotsConfigs) {
205
- (0, _utils.hideHotspotsIcons)();
206
- }
207
- _zoomSteps.forEach(function (step) {
208
- setTimeout(function () {
209
- _this2.zoomIntensity = step;
210
- _this2.update();
211
- }, step * 200);
212
- });
213
- this.mouseTracked = true;
214
- this.container.style.cursor = 'zoom-out';
215
- }
216
- }
217
- }, {
218
- key: "onOriginalImageLoad",
219
- value: function onOriginalImageLoad(orientation, event, image, index) {
220
- if (orientation === _constants.ORIENTATIONS.Y) {
221
- this.originalImagesY[index] = image;
222
- } else {
223
- this.originalImagesX[index] = image;
224
- }
225
- var loadedOriginalXImages = this.originalImagesX.filter(function (image) {
226
- return image;
227
- });
228
- var loadedOriginalYImages = this.originalImagesY.filter(function (image) {
229
- return image;
230
- });
231
- var totalAmount = this.amountX + this.amountY;
232
- var totalLoadedImages = loadedOriginalXImages.length + loadedOriginalYImages.length;
233
- var isAllImagesLoaded = loadedOriginalXImages.length + loadedOriginalYImages.length === this.amountX + this.amountY;
234
- var percentage = Math.round(totalLoadedImages / totalAmount * 100);
235
- this.updatePercentageInLoader(percentage);
236
- if (isAllImagesLoaded) {
237
- this.removeLoader();
238
- this.togglePointerZoom(event);
239
- this.mouseTracked = true;
240
- this.isAllOriginalImagesLoaded = true;
241
- }
242
- }
243
- }, {
244
- key: "prepareOriginalImages",
245
- value: function prepareOriginalImages(event) {
246
- var srcX = (0, _utils.generateImagesPath)(this.srcXConfig);
247
- this.isStartedLoadOriginalImages = true;
248
- this.loader = (0, _utils.createLoader)(this.innerBox);
249
- this.container.style.cursor = 'wait';
250
- (0, _utils.preloadOriginalImages)(this.srcXConfig, srcX, this.onOriginalImageLoad.bind(this, _constants.ORIENTATIONS.X, event));
251
- if (this.allowSpinY) {
252
- var srcY = (0, _utils.generateImagesPath)(this.srcYConfig);
253
- (0, _utils.preloadOriginalImages)(this.srcYConfig, srcY, this.onOriginalImageLoad.bind(this, _constants.ORIENTATIONS.Y, event));
254
- }
255
- }
256
- }, {
257
- key: "touchStart",
258
- value: function touchStart(event) {
259
- if (!this.imagesLoaded) return;
260
- var isMouseOnHotspotElement = (0, _utils.isMouseOnHotspot)();
261
- this.hideInitialIcons();
262
- if (this.autoplay || this.loopTimeoutId) {
263
- this.stop();
264
- this.autoplay = false;
265
- }
266
- this.intialPositions = {
267
- x: event.touches[0].clientX,
268
- y: event.touches[0].clientY
269
- };
270
- this.movementStart = {
271
- x: event.touches[0].clientX,
272
- y: event.touches[0].clientY
273
- };
274
- this.isClicked = true;
275
- if (isMouseOnHotspotElement) {
276
- this.isClicked = false;
277
- }
278
- }
279
- }, {
280
- key: "touchEnd",
281
- value: function touchEnd() {
282
- if (!this.imagesLoaded) return;
283
- if (this.bottomCircle) this.show360ViewCircleIcon();
284
- this.movementStart = {
285
- x: 0,
286
- y: 0
287
- };
288
- this.isStartSpin = false;
289
- this.isClicked = false;
290
- }
291
- }, {
292
- key: "touchMove",
293
- value: function touchMove(event) {
294
- if (!this.isClicked || !this.imagesLoaded) return;
295
- if (event.cancelable && this.allowSpinY) {
296
- event.preventDefault();
297
- }
298
- var nextPositions = {
299
- x: event.touches[0].clientX,
300
- y: event.touches[0].clientY
301
- };
302
- this.movingDirection = (0, _utils.getMovingDirection)(this.isStartSpin, this.allowSpinY, this.intialPositions, nextPositions, this.movingDirection);
303
- this.onMoveHandler(event);
304
- }
305
- }, {
306
- key: "keyDownGeneral",
307
- value: function keyDownGeneral(event) {
308
- if (!this.imagesLoaded) return;
309
- if (this.glass) {
310
- this.closeMagnifier();
311
- }
312
- if (event.keyCode === 27) {
313
- //ESC
314
- if (this.mouseTracked) {
315
- this.togglePointerZoom();
316
- }
317
- }
318
- }
319
- }, {
320
- key: "hideInitialIcons",
321
- value: function hideInitialIcons() {
322
- if (this.glass) {
323
- this.closeMagnifier();
324
- }
325
- if (this.view360Icon) {
326
- this.remove360ViewIcon();
327
- }
328
- }
329
- }, {
330
- key: "setCursorPosition",
331
- value: function setCursorPosition(event) {
332
- this.mousePositions = {
333
- x: event.clientX,
334
- y: event.clientY
335
- };
336
- }
337
- }, {
338
- key: "getCursorPositionInCanvas",
339
- value: function getCursorPositionInCanvas() {
340
- var canvasRect = this.canvas.getBoundingClientRect();
341
- this.pointerCurrentPosition = {
342
- x: this.mousePositions.x - canvasRect.left,
343
- y: this.mousePositions.y - canvasRect.top
344
- };
345
- return this.pointerCurrentPosition;
346
- }
347
- }, {
348
- key: "keyDown",
349
- value: function keyDown(event) {
350
- if (!this.imagesLoaded) return;
351
- if (this.glass) {
352
- this.closeMagnifier();
353
- }
354
- if (event.keyCode === 37) {
355
- // left
356
- this.keysReverse ? this.left() : this.right();
357
- this.onSpin();
358
- }
359
- if (event.keyCode === 39) {
360
- // right
361
- this.keysReverse ? this.right() : this.left();
362
- this.onSpin();
363
- }
364
- if (this.allowSpinY) {
365
- event.preventDefault();
366
- if (event.keyCode === 38) {
367
- // up
368
- this.keysReverse ? this.top() : this.bottom();
369
- this.onSpin();
370
- }
371
- if (event.keyCode === 40) {
372
- // down
373
- this.keysReverse ? this.bottom() : this.top();
374
- this.onSpin();
375
- }
376
- }
377
- }
378
- }, {
379
- key: "onSpin",
380
- value: function onSpin() {
381
- if (this.bottomCircle) {
382
- this.hide360ViewCircleIcon();
383
- }
384
- if (this.view360Icon) {
385
- this.remove360ViewIcon();
386
- }
387
- if (this.autoplay || this.loopTimeoutId) {
388
- this.stop();
389
- this.autoplay = false;
390
- }
391
- }
392
- }, {
393
- key: "keyUp",
394
- value: function keyUp(event) {
395
- if (!this.imagesLoaded) return;
396
- if ([37, 39].indexOf(event.keyCode) !== -1) {
397
- this.onFinishSpin();
398
- }
399
- }
400
- }, {
401
- key: "onFinishSpin",
402
- value: function onFinishSpin() {
403
- if (this.bottomCircle) this.show360ViewCircleIcon();
404
- }
405
- }, {
406
- key: "moveActiveIndexUp",
407
- value: function moveActiveIndexUp(itemsSkipped) {
408
- var isReverse = this.controlReverse ? !this.spinReverse : this.spinReverse;
409
- if (this.stopAtEdges) {
410
- var isReachedTheEdge = this.activeImageX + itemsSkipped >= this.amountX;
411
- if (isReachedTheEdge) {
412
- this.activeImageX = this.amountX;
413
- if (isReverse ? this.leftElem : this.rightElem) {
414
- (0, _utils.addClass)(isReverse ? this.leftElem : this.rightElem, 'not-active');
415
- }
416
- } else {
417
- this.activeImageX += itemsSkipped;
418
- if (this.rightElem) (0, _utils.removeClass)(this.rightElem, 'not-active');
419
- if (this.leftElem) (0, _utils.removeClass)(this.leftElem, 'not-active');
420
- }
421
- } else {
422
- this.activeImageX = (this.activeImageX + itemsSkipped) % this.amountX || this.amountX;
423
- if (this.activeImageX === this.amountX && this.allowSpinY) this.spinY = true;
424
- }
425
- }
426
- }, {
427
- key: "moveActiveIndexDown",
428
- value: function moveActiveIndexDown(itemsSkipped) {
429
- var isReverse = this.controlReverse ? !this.spinReverse : this.spinReverse;
430
- if (this.stopAtEdges) {
431
- var isReachedTheEdge = this.activeImageX - itemsSkipped <= 1;
432
- if (isReachedTheEdge) {
433
- this.activeImageX = 1;
434
- if (isReverse ? this.rightElem : this.leftElem) {
435
- (0, _utils.addClass)(isReverse ? this.rightElem : this.leftElem, 'not-active');
436
- }
437
- } else {
438
- this.activeImageX -= itemsSkipped;
439
- if (this.leftElem) (0, _utils.removeClass)(this.leftElem, 'not-active');
440
- if (this.rightElem) (0, _utils.removeClass)(this.rightElem, 'not-active');
441
- }
442
- } else {
443
- if (this.activeImageX - itemsSkipped < 1) {
444
- this.activeImageX = this.amountX + (this.activeImageX - itemsSkipped);
445
- this.spinY = true;
446
- } else {
447
- this.activeImageX -= itemsSkipped;
448
- }
449
- }
450
- }
451
- }, {
452
- key: "moveActiveYIndexUp",
453
- value: function moveActiveYIndexUp(itemsSkipped) {
454
- var isReverse = this.controlReverse ? !this.spinReverse : this.spinReverse;
455
- if (this.stopAtEdges) {
456
- var isReachedTheEdge = this.activeImageY + itemsSkipped >= this.amountY;
457
- if (isReachedTheEdge) {
458
- this.activeImageY = this.amountY;
459
- if (isReverse ? this.bottomElem : this.topElem) {
460
- (0, _utils.addClass)(isReverse ? this.bottomElem : this.topElem, 'not-active');
461
- }
462
- } else {
463
- this.activeImageY += itemsSkipped;
464
- if (this.topElem) (0, _utils.removeClass)(this.topElem, 'not-active');
465
- if (this.bottomElem) (0, _utils.removeClass)(this.bottomElem, 'not-active');
466
- }
467
- } else {
468
- this.activeImageY = (this.activeImageY + itemsSkipped) % this.amountY || this.amountY;
469
- if (this.activeImageY === this.amountY) this.spinY = false;
470
- }
471
- }
472
- }, {
473
- key: "moveActiveYIndexDown",
474
- value: function moveActiveYIndexDown(itemsSkipped) {
475
- var isReverse = this.controlReverse ? !this.spinReverse : this.spinReverse;
476
- if (this.stopAtEdges) {
477
- var isReachedTheEdge = this.activeImageY - itemsSkipped <= 1;
478
- if (isReachedTheEdge) {
479
- this.activeImageY = 1;
480
- if (isReverse ? this.topElem : this.bottomElem) {
481
- (0, _utils.addClass)(isReverse ? this.topElem : this.bottomElem, 'not-active');
482
- }
483
- } else {
484
- this.activeImageY -= itemsSkipped;
485
- if (this.bottomElem) (0, _utils.removeClass)(this.bottomElem, 'not-active');
486
- if (this.topElem) (0, _utils.removeClass)(this.topElem, 'not-active');
487
- }
488
- } else {
489
- if (this.activeImageY - itemsSkipped < 1) {
490
- this.activeImageY = this.amountY + (this.activeImageY - itemsSkipped);
491
- this.spinY = false;
492
- } else {
493
- this.activeImageY -= itemsSkipped;
494
- }
495
- }
496
- }
497
- }, {
498
- key: "moveRight",
499
- value: function moveRight(currentPositionX) {
500
- var itemsSkippedRight = (0, _utils.getItemSkipped)(currentPositionX, this.movementStart.x, this.speedFactor);
501
- this.spinReverse ? this.moveActiveIndexDown(itemsSkippedRight) : this.moveActiveIndexUp(itemsSkippedRight);
502
- this.movementStart.x = currentPositionX;
503
- this.activeImageY = 1;
504
- this.update();
505
- }
506
- }, {
507
- key: "moveLeft",
508
- value: function moveLeft(currentPositionX) {
509
- var itemsSkippedLeft = (0, _utils.getItemSkipped)(this.movementStart.x, currentPositionX, this.speedFactor);
510
- this.spinReverse ? this.moveActiveIndexUp(itemsSkippedLeft) : this.moveActiveIndexDown(itemsSkippedLeft);
511
- this.activeImageY = 1;
512
- this.movementStart.x = currentPositionX;
513
- this.update();
514
- }
515
- }, {
516
- key: "moveTop",
517
- value: function moveTop(currentPositionY) {
518
- var itemsSkippedTop = (0, _utils.getItemSkipped)(this.movementStart.y, currentPositionY, this.speedFactor);
519
- this.spinReverse ? this.moveActiveYIndexUp(itemsSkippedTop) : this.moveActiveYIndexDown(itemsSkippedTop);
520
- this.activeImageX = 1;
521
- this.movementStart.y = currentPositionY;
522
- this.update();
523
- }
524
- }, {
525
- key: "moveBottom",
526
- value: function moveBottom(currentPositionY) {
527
- var itemsSkippedBottom = (0, _utils.getItemSkipped)(currentPositionY, this.movementStart.y, this.speedFactor);
528
- this.spinReverse ? this.moveActiveYIndexDown(itemsSkippedBottom) : this.moveActiveYIndexUp(itemsSkippedBottom);
529
- this.activeImageX = 1;
530
- this.movementStart.y = currentPositionY;
531
- this.update();
532
- }
533
- }, {
534
- key: "onMoveHandler",
535
- value: function onMoveHandler(event) {
536
- var currentPositionX = this.isMobile ? event.touches[0].clientX : event.pageX;
537
- var currentPositionY = this.isMobile ? event.touches[0].clientY : event.pageY;
538
- var isMoveRight = currentPositionX - this.movementStart.x >= this.speedFactor;
539
- var isMoveLeft = this.movementStart.x - currentPositionX >= this.speedFactor;
540
- var isMoveTop = this.movementStart.y - currentPositionY >= this.speedFactor;
541
- var isMoveBottom = currentPositionY - this.movementStart.y >= this.speedFactor;
542
- if (this.bottomCircle) this.hide360ViewCircleIcon();
543
- if (isMoveRight && this.movingDirection === _constants.ORIENTATIONS.X) {
544
- this.moveRight(currentPositionX);
545
- this.isStartSpin = true;
546
- } else if (isMoveLeft && this.movingDirection === _constants.ORIENTATIONS.X) {
547
- this.moveLeft(currentPositionX);
548
- this.isStartSpin = true;
549
- } else if (isMoveTop && this.movingDirection === _constants.ORIENTATIONS.Y) {
550
- this.moveTop(currentPositionY);
551
- this.isStartSpin = true;
552
- } else if (isMoveBottom && this.movingDirection === _constants.ORIENTATIONS.Y) {
553
- this.moveBottom(currentPositionY);
554
- this.isStartSpin = true;
555
- }
556
- }
557
- }, {
558
- key: "left",
559
- value: function left() {
560
- this.movingDirection = _constants.ORIENTATIONS.X;
561
- this.activeImageY = this.reversed ? this.amountY : 1;
562
- this.moveActiveIndexDown(1);
563
- this.update();
564
- }
565
- }, {
566
- key: "right",
567
- value: function right() {
568
- this.movingDirection = _constants.ORIENTATIONS.X;
569
- this.activeImageY = this.reversed ? this.amountY : 1;
570
- this.moveActiveIndexUp(1);
571
- this.update();
572
- }
573
- }, {
574
- key: "top",
575
- value: function top() {
576
- this.movingDirection = _constants.ORIENTATIONS.Y;
577
- this.activeImageX = this.reversed ? this.amountX : 1;
578
- this.moveActiveYIndexUp(1);
579
- this.update();
580
- }
581
- }, {
582
- key: "bottom",
583
- value: function bottom() {
584
- this.movingDirection = _constants.ORIENTATIONS.Y;
585
- this.activeImageX = this.reversed ? this.amountX : 1;
586
- this.moveActiveYIndexDown(1);
587
- this.update();
588
- }
589
- }, {
590
- key: "loop",
591
- value: function loop(reversed) {
592
- var loopTriggers = {
593
- left: this.left.bind(this),
594
- right: this.right.bind(this),
595
- top: this.top.bind(this),
596
- bottom: this.bottom.bind(this)
597
- };
598
- (0, _utils.loop)(this.autoplayBehavior, this.spinY, reversed, loopTriggers);
599
- }
600
- }, {
601
- key: "updateContainerAndCanvasSize",
602
- value: function updateContainerAndCanvasSize(image) {
603
- var imageAspectRatio = (0, _utils.getImageAspectRatio)(image, this.ratio);
604
- if (this.fullscreenView) {
605
- this.container.width = window.innerWidth * this.devicePixelRatio;
606
- this.container.style.width = window.innerWidth + 'px';
607
- this.container.height = window.innerHeight * this.devicePixelRatio;
608
- this.container.style.height = window.innerHeight + 'px';
609
- this.container.style.maxWidth = 'unset';
610
- this.canvas.width = window.innerWidth * this.devicePixelRatio;
611
- this.canvas.style.width = window.innerWidth + 'px';
612
- this.canvas.height = window.innerHeight * this.devicePixelRatio;
613
- this.canvas.style.height = window.innerHeight + 'px';
614
- return;
615
- }
616
- this.canvas.width = this.container.offsetWidth * this.devicePixelRatio;
617
- this.canvas.style.width = this.container.offsetWidth + 'px';
618
- this.canvas.height = this.container.offsetWidth / imageAspectRatio * this.devicePixelRatio;
619
- this.canvas.style.height = this.container.offsetWidth / imageAspectRatio + 'px';
620
- }
621
- }, {
622
- key: "onResizedImageLoad",
623
- value: function onResizedImageLoad(orientation, image, index) {
624
- if (orientation === _constants.ORIENTATIONS.Y) {
625
- this.resizedImagesY[index] = image;
626
- } else {
627
- this.resizedImagesX[index] = image;
628
- }
629
- var isAllImagesLoaded = this.resizedImagesX.length + this.resizedImagesY.length === this.amountX + this.amountY;
630
- if (isAllImagesLoaded) {
631
- this.imagesX = this.resizedImagesX;
632
- this.imagesY = this.resizedImagesY;
633
- this.update();
634
- }
635
- }
636
- }, {
637
- key: "showImageInfo",
638
- value: function showImageInfo(ctx) {
639
- ctx.font = "".concat(this.fullscreenView ? 28 : 14, "px serif");
640
- ctx.fillStyle = this.info === 'white' ? '#FFF' : '#000';
641
- var imageDimension = "image-dimension: ".concat(this.container.offsetWidth, "x").concat(this.container.offsetHeight, "px");
642
- var currentXImage = 'active-index-x: ' + this.activeImageX;
643
- var currentYImage = 'active-index-y: ' + this.activeImageY;
644
- var imageIndex = [currentXImage, currentYImage].join(' | ');
645
- ctx.fillText(imageDimension, 20, this.container.offsetHeight - 35);
646
- ctx.fillText(imageIndex, 20, this.container.offsetHeight - 10);
647
- }
648
- }, {
649
- key: "requestResizedImages",
650
- value: function requestResizedImages() {
651
- if (!this.isReady()) return;
652
- var responsive = this.ciParams.ciToken;
653
- var firstImage = this.imagesX[0];
654
- this.update();
655
- if (!responsive || !this.requestResponsiveImages || this.container.offsetWidth < firstImage.width * 1.5) return;
656
- this.speedFactor = (0, _utils.getSpeedFactor)(this.dragSpeed, this.amountX, this.container.offsetWidth);
657
- var srcX = (0, _utils.generateImagesPath)(this.srcXConfig);
658
- (0, _utils.preloadImages)(this.srcXConfig, srcX, this.onResizedImageLoad.bind(this, _constants.ORIENTATIONS.X));
659
- if (this.allowSpinY) {
660
- var srcY = (0, _utils.generateImagesPath)(this.srcYConfig);
661
- (0, _utils.preloadImages)(this.srcYConfig, srcY, this.onResizedImageLoad.bind(this, _constants.ORIENTATIONS.Y));
662
- }
663
- }
664
- }, {
665
- key: "update",
666
- value: function update() {
667
- var image = this.imagesX[this.activeImageX - 1];
668
- if (this.movingDirection === _constants.ORIENTATIONS.Y) {
669
- image = this.imagesY[this.activeImageY - 1];
670
- }
671
- if (!image) return;
672
- var ctx = this.canvas.getContext("2d");
673
- ctx.scale(this.devicePixelRatio, this.devicePixelRatio);
674
- this.updateContainerAndCanvasSize(image);
675
- if (this.fullscreenView) {
676
- var _contain = (0, _utils.contain)(this.canvas.width, this.canvas.height, image.width, image.height),
677
- width = _contain.width,
678
- height = _contain.height,
679
- offsetX = _contain.offsetX,
680
- offsetY = _contain.offsetY;
681
- ctx.drawImage(image, offsetX, offsetY, width, height);
682
- } else {
683
- if (this.mouseTracked) {
684
- this.updateImageScale(ctx);
685
- } else {
686
- if (this.hotspotsConfigs && !this.autoplay) {
687
- (0, _utils.updateHotspots)(this.container, this.hotspotsConfigs, this.activeImageX, this.activeImageY, this.movingDirection, this.isClicked);
688
- }
689
- ctx.drawImage(image, 0, 0, this.canvas.width, this.canvas.height);
690
- }
691
- }
692
- if (this.info) {
693
- this.showImageInfo(ctx);
694
- }
695
- }
696
- }, {
697
- key: "updateImageScale",
698
- value: function updateImageScale(ctx) {
699
- var image = this.originalImagesX[this.activeImageX - 1];
700
- if (this.movingDirection === _constants.ORIENTATIONS.Y) {
701
- image = this.originalImagesY[this.activeImageY - 1];
702
- }
703
- var position = this.getCursorPositionInCanvas();
704
- var imageWidth = this.canvas.width;
705
- var imageHeight = this.canvas.height;
706
- var width = this.canvas.width * this.zoomIntensity;
707
- var height = this.canvas.height * this.zoomIntensity;
708
- var pointX = 0 - position.x / imageWidth * (width - this.canvas.width);
709
- var pointY = 0 - position.y / imageHeight * (height - this.canvas.height);
710
- ctx.drawImage(image, pointX, pointY, width, height);
711
- }
712
- }, {
713
- key: "updatePercentageInLoader",
714
- value: function updatePercentageInLoader(percentage) {
715
- if (this.loader) {
716
- this.loader.style.width = percentage + '%';
717
- }
718
- if (this.view360Icon) {
719
- this.view360Icon.innerText = percentage + '%';
720
- }
721
- }
722
- }, {
723
- key: "onFirstImageLoaded",
724
- value: function onFirstImageLoaded(image) {
725
- this.add360ViewIcon();
726
- var ctx = this.canvas.getContext("2d");
727
- ctx.scale(this.devicePixelRatio, this.devicePixelRatio);
728
- this.updateContainerAndCanvasSize(image);
729
- if (this.fullscreenView) {
730
- var _contain2 = (0, _utils.contain)(this.canvas.width, this.canvas.height, image.width, image.height),
731
- offsetX = _contain2.offsetX,
732
- offsetY = _contain2.offsetY,
733
- width = _contain2.width,
734
- height = _contain2.height;
735
- this.offset = {
736
- x: offsetX,
737
- y: offsetY
738
- };
739
- this.addCloseFullscreenView();
740
- ctx.drawImage(image, offsetX, offsetY, width, height);
741
- } else {
742
- ctx.drawImage(image, 0, 0, this.canvas.width, this.canvas.height);
743
- }
744
- if (this.info) {
745
- this.showImageInfo(ctx);
746
- }
747
- if (this.magnifier) {
748
- this.addMagnifier();
749
- }
750
- if (this.boxShadow && !this.fullscreenView) {
751
- this.boxShadowEl = (0, _utils.createBoxShadow)(this.boxShadow, this.innerBox);
752
- }
753
- if (this.bottomCircle && !this.fullscreenView) {
754
- this.add360ViewCircleIcon();
755
- }
756
- if (this.fullscreen && !this.fullscreenView) {
757
- this.addFullscreenIcon();
758
- }
759
- }
760
- }, {
761
- key: "onAllImagesLoaded",
762
- value: function onAllImagesLoaded() {
763
- this.removeLoader();
764
- this.imagesLoaded = true;
765
- if (this.autoplay && this.pointerZoom) {
766
- this.container.style.cursor = 'zoom-in';
767
- } else {
768
- this.container.style.cursor = 'grab';
769
- }
770
- this.speedFactor = (0, _utils.getSpeedFactor)(this.dragSpeed, this.amountX, this.container.offsetWidth);
771
- if (this.autoplay) {
772
- this.play();
773
- }
774
- if (this.disableDrag) {
775
- this.container.style.cursor = 'default';
776
- }
777
- if (this.view360Icon) {
778
- if (this.hide360Logo) return this.remove360ViewIcon();
779
- this.view360Icon.innerText = '';
780
- //TODO [deprecated]: remove setView360Icon in the upcoming versions
781
- if (this.logoSrc) (0, _ci.setView360Icon)(this.view360Icon, this.logoSrc);
782
- }
783
- this.initControls();
784
- }
785
- }, {
786
- key: "magnify",
787
- value: function magnify(event) {
788
- var _this3 = this;
789
- event.stopPropagation();
790
- if (this.mouseTracked) this.togglePointerZoom();
791
- var currentOriginalImage = (0, _utils.getCurrentOriginalImage)(this.movingDirection, this.imagesX, this.imagesY, this.activeImageX, this.activeImageY);
792
- this.isMagnifyOpen = true;
793
- currentOriginalImage.onload = function () {
794
- if (_this3.glass) {
795
- _this3.glass.style.cursor = 'none';
796
- }
797
- };
798
- this.glass = document.createElement('div');
799
- this.container.style.overflow = 'hidden';
800
- (0, _utils.magnify)(this.container, this.offset, currentOriginalImage, this.glass, this.magnifier || 3);
801
- }
802
- }, {
803
- key: "closeMagnifier",
804
- value: function closeMagnifier() {
805
- if (!this.glass) return;
806
- this.container.style.overflow = 'visible';
807
- this.container.removeChild(this.glass);
808
- this.glass = null;
809
- this.isMagnifyOpen = false;
810
- }
811
- }, {
812
- key: "openFullscreenModal",
813
- value: function openFullscreenModal(event) {
814
- event.stopPropagation();
815
- if (this.mouseTracked) this.togglePointerZoom();
816
- var fullscreenContainer = (0, _utils.createFullscreenModal)(this.container);
817
- new CI360Viewer(fullscreenContainer, true, this.hotspotsConfigs);
818
- }
819
- }, {
820
- key: "setFullscreenEvents",
821
- value: function setFullscreenEvents(_, event) {
822
- if (event.type === 'click') return this.closeFullscreenModal(event);
823
- if (event.key === 'Escape' && this.container.parentNode.parentNode === document.body) {
824
- this.closeFullscreenModalOnEsc(event);
825
- }
826
- }
827
- }, {
828
- key: "closeFullscreenModalOnEsc",
829
- value: function closeFullscreenModalOnEsc(event) {
830
- this.closeFullscreenModal(event);
831
- }
832
- }, {
833
- key: "play",
834
- value: function play() {
835
- var _this4 = this;
836
- if (this.bottomCircle) this.hide360ViewCircleIcon();
837
- this.remove360ViewIcon();
838
- this.loopTimeoutId = window.setInterval(function () {
839
- _this4.loop(_this4.reversed);
840
- var isPlayedOnce = (0, _utils.isCompletedOneCycle)(_this4.autoplayBehavior, _this4.activeImageX, _this4.activeImageY, _this4.amountX, _this4.amountY, _this4.reversed);
841
- if (_this4.playOnce && isPlayedOnce) {
842
- window.clearTimeout(_this4.loopTimeoutId);
843
- _this4.autoplay = false;
844
- if (_this4.hotspotsConfigs) {
845
- (0, _utils.updateHotspots)(_this4.container, _this4.hotspotsConfigs, _this4.activeImageX, _this4.activeImageY, _this4.movingDirection, _this4.isClicked);
846
- }
847
- }
848
- }, this.autoplaySpeed);
849
- }
850
- }, {
851
- key: "stop",
852
- value: function stop() {
853
- if (this.bottomCircle) this.show360ViewCircleIcon();
854
- window.clearTimeout(this.loopTimeoutId);
855
- }
856
- }, {
857
- key: "updateView",
858
- value: function updateView(forceUpdate, viewers, hotspotConfigs) {
859
- var _this5 = this;
860
- var container = this.container;
861
- var imageProps = (0, _ci.get360ViewProps)(container);
862
- var srcPropsChanged = (0, _utils.isPropsChangeRequireReload)(this, imageProps);
863
- var reInitView = srcPropsChanged || forceUpdate;
864
- if (reInitView) {
865
- var oldElement = this.container;
866
- var viewIndex = viewers.findIndex(function (view) {
867
- return view.id === _this5.container.id;
868
- });
869
- container.removeChild(this.innerBox);
870
- container = container.cloneNode(true);
871
- container.className = container.className.replace(' initialized', '');
872
- oldElement.parentNode.replaceChild(container, oldElement);
873
- return viewers.splice(viewIndex, 1, new CI360Viewer(container));
874
- }
875
- container.style.position = 'relative';
876
- container.style.width = '100%';
877
- container.style.cursor = 'default';
878
- container.setAttribute('draggable', 'false');
879
- this.stop();
880
- this.init(container, true, hotspotConfigs);
881
- }
882
- }, {
883
- key: "destroy",
884
- value: function destroy() {
885
- this.stop();
886
- var oldElement = this.container;
887
- var newElement = oldElement.cloneNode(true);
888
- var innerBox = newElement.querySelector('.cloudimage-360-inner-box');
889
- newElement.className = newElement.className.replace(' initialized', '');
890
- newElement.style.position = 'relative';
891
- newElement.style.width = '100%';
892
- newElement.style.cursor = 'default';
893
- newElement.setAttribute('draggable', 'false');
894
- newElement.style.minHeight = 'auto';
895
- newElement.removeChild(innerBox);
896
- oldElement.parentNode.replaceChild(newElement, oldElement);
897
- }
898
- }, {
899
- key: "addCloseFullscreenView",
900
- value: function addCloseFullscreenView(event) {
901
- var closeFullscreenIcon = (0, _utils.createCloseFullscreenIcon)();
902
- closeFullscreenIcon.onclick = this.setFullscreenEvents.bind(this, event);
903
- window.onkeyup = this.setFullscreenEvents.bind(this, event);
904
- this.iconsContainer.appendChild(closeFullscreenIcon);
905
- }
906
- }, {
907
- key: "add360ViewIcon",
908
- value: function add360ViewIcon() {
909
- this.view360Icon = (0, _utils.create360ViewIcon)();
910
- this.innerBox.appendChild(this.view360Icon);
911
- }
912
- }, {
913
- key: "addFullscreenIcon",
914
- value: function addFullscreenIcon() {
915
- this.fullscreenIcon = (0, _utils.createFullscreenIcon)();
916
- this.fullscreenIcon.onclick = this.openFullscreenModal.bind(this);
917
- this.iconsContainer.appendChild(this.fullscreenIcon);
918
- }
919
- }, {
920
- key: "showFullscreenIcon",
921
- value: function showFullscreenIcon() {
922
- if (!this.fullscreenIcon) return;
923
- this.fullscreenIcon.style.display = 'block';
924
- this.fullscreenIcon.style.pointerEvents = 'auto';
925
- }
926
- }, {
927
- key: "hideFullscreenIcon",
928
- value: function hideFullscreenIcon() {
929
- if (!this.fullscreenIcon) return;
930
- this.fullscreenIcon.style.display = 'none';
931
- this.fullscreenIcon.style.pointerEvents = 'none';
932
- }
933
- }, {
934
- key: "addMagnifier",
935
- value: function addMagnifier() {
936
- this.magnifierIcon = (0, _utils.createMagnifierIcon)();
937
- this.magnifierIcon.onclick = this.magnify.bind(this);
938
- this.iconsContainer.appendChild(this.magnifierIcon);
939
- }
940
- }, {
941
- key: "enableMagnifierIcon",
942
- value: function enableMagnifierIcon() {
943
- if (!this.magnifierIcon) return;
944
- this.magnifierIcon.style.display = 'block';
945
- this.magnifierIcon.style.pointerEvents = 'auto';
946
- }
947
- }, {
948
- key: "disableMagnifierIcon",
949
- value: function disableMagnifierIcon() {
950
- if (!this.magnifierIcon) return;
951
- this.magnifierIcon.style.display = 'none';
952
- this.magnifierIcon.style.pointerEvents = 'none';
953
- }
954
- }, {
955
- key: "closeFullscreenModal",
956
- value: function closeFullscreenModal(event) {
957
- event.stopPropagation();
958
- document.body.removeChild(this.container.parentNode);
959
- window.document.body.style.overflow = 'visible';
960
- }
961
- }, {
962
- key: "add360ViewCircleIcon",
963
- value: function add360ViewCircleIcon() {
964
- this.view360CircleIcon = (0, _utils.create360ViewCircleIcon)(this.bottomCircleOffset);
965
- this.innerBox.appendChild(this.view360CircleIcon);
966
- }
967
- }, {
968
- key: "show360ViewCircleIcon",
969
- value: function show360ViewCircleIcon() {
970
- if (!this.view360CircleIcon) return;
971
- this.view360CircleIcon.style.opacity = '1';
972
- }
973
- }, {
974
- key: "hide360ViewCircleIcon",
975
- value: function hide360ViewCircleIcon() {
976
- if (!this.view360CircleIcon) return;
977
- this.view360CircleIcon.style.opacity = '0';
978
- }
979
- }, {
980
- key: "remove360ViewCircleIcon",
981
- value: function remove360ViewCircleIcon() {
982
- if (!this.view360CircleIcon) return;
983
- this.innerBox.removeChild(this.view360CircleIcon);
984
- this.view360CircleIcon = null;
985
- }
986
- }, {
987
- key: "removeLoader",
988
- value: function removeLoader() {
989
- if (!this.loader) return;
990
- this.innerBox.removeChild(this.loader);
991
- this.loader = null;
992
- }
993
- }, {
994
- key: "remove360ViewIcon",
995
- value: function remove360ViewIcon() {
996
- if (!this.view360Icon) return;
997
- try {
998
- this.innerBox.removeChild(this.view360Icon);
999
- this.view360Icon = null;
1000
- } catch (_unused) {}
1001
- }
1002
- }, {
1003
- key: "initControls",
1004
- value: function initControls() {
1005
- var _this6 = this;
1006
- var onLeftStart = function onLeftStart(event) {
1007
- event.stopPropagation();
1008
- _this6.onSpin();
1009
- _this6.left();
1010
- _this6.loopTimeoutId = window.setInterval(_this6.left.bind(_this6), _this6.autoplaySpeed);
1011
- };
1012
- var onRightStart = function onRightStart(event) {
1013
- event.stopPropagation();
1014
- _this6.onSpin();
1015
- _this6.right();
1016
- _this6.loopTimeoutId = window.setInterval(_this6.right.bind(_this6), _this6.autoplaySpeed);
1017
- };
1018
- var onTopStart = function onTopStart(event) {
1019
- event.stopPropagation();
1020
- _this6.onSpin();
1021
- _this6.top();
1022
- _this6.loopTimeoutId = window.setInterval(_this6.top.bind(_this6), _this6.autoplaySpeed);
1023
- };
1024
- var onBottomStart = function onBottomStart(event) {
1025
- event.stopPropagation();
1026
- _this6.onSpin();
1027
- _this6.bottom();
1028
- _this6.loopTimeoutId = window.setInterval(_this6.bottom.bind(_this6), _this6.autoplaySpeed);
1029
- };
1030
- var onEventEnd = function onEventEnd() {
1031
- _this6.onFinishSpin();
1032
- window.clearTimeout(_this6.loopTimeoutId);
1033
- };
1034
- var controlsConfig = {
1035
- container: this.container,
1036
- controlReverse: this.controlReverse,
1037
- spinReverse: this.spinReverse,
1038
- stopAtEdges: this.stopAtEdges
1039
- };
1040
- var controlsTriggers = {
1041
- onLeftStart: onLeftStart,
1042
- onRightStart: onRightStart,
1043
- onTopStart: onTopStart,
1044
- onBottomStart: onBottomStart,
1045
- onEventEnd: onEventEnd
1046
- };
1047
- var controlsElements = (0, _utils.initControls)(controlsConfig, controlsTriggers);
1048
- this.topElem = controlsElements.top;
1049
- this.bottomElem = controlsElements.bottom;
1050
- this.leftElem = controlsElements.left;
1051
- this.rightElem = controlsElements.right;
1052
- }
1053
- }, {
1054
- key: "attachEvents",
1055
- value: function attachEvents(draggable, swipeable, keys) {
1056
- window.addEventListener('resize', this.requestResizedImages.bind(this));
1057
- if (draggable && !this.disableDrag) {
1058
- this.container.addEventListener('click', this.mouseClick.bind(this));
1059
- this.container.addEventListener('mousedown', this.mouseDown.bind(this));
1060
- this.container.addEventListener('mousemove', this.mouseMove.bind(this));
1061
- this.container.addEventListener('mouseleave', this.mouseLeave.bind(this));
1062
- document.addEventListener('mouseup', this.mouseUp.bind(this));
1063
- }
1064
- if (swipeable && !this.disableDrag) {
1065
- this.container.addEventListener('touchstart', this.touchStart.bind(this), {
1066
- passive: true
1067
- });
1068
- this.container.addEventListener('touchend', this.touchEnd.bind(this));
1069
- this.container.addEventListener('touchmove', this.touchMove.bind(this));
1070
- }
1071
- if (keys) {
1072
- document.addEventListener('keydown', this.keyDown.bind(this));
1073
- document.addEventListener('keyup', this.keyUp.bind(this));
1074
- }
1075
- document.addEventListener('keydown', this.keyDownGeneral.bind(this));
1076
- }
1077
- }, {
1078
- key: "init",
1079
- value: function init(container) {
1080
- var _this7 = this;
1081
- var update = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1082
- var hotspotsConfigs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1083
- var _get360ViewProps = (0, _ci.get360ViewProps)(container),
1084
- folder = _get360ViewProps.folder,
1085
- apiVersion = _get360ViewProps.apiVersion,
1086
- filenameX = _get360ViewProps.filenameX,
1087
- filenameY = _get360ViewProps.filenameY,
1088
- imageListX = _get360ViewProps.imageListX,
1089
- imageListY = _get360ViewProps.imageListY,
1090
- indexZeroBase = _get360ViewProps.indexZeroBase,
1091
- amountX = _get360ViewProps.amountX,
1092
- amountY = _get360ViewProps.amountY,
1093
- _get360ViewProps$drag = _get360ViewProps.draggable,
1094
- draggable = _get360ViewProps$drag === void 0 ? true : _get360ViewProps$drag,
1095
- _get360ViewProps$swip = _get360ViewProps.swipeable,
1096
- swipeable = _get360ViewProps$swip === void 0 ? true : _get360ViewProps$swip,
1097
- keys = _get360ViewProps.keys,
1098
- keysReverse = _get360ViewProps.keysReverse,
1099
- bottomCircle = _get360ViewProps.bottomCircle,
1100
- bottomCircleOffset = _get360ViewProps.bottomCircleOffset,
1101
- boxShadow = _get360ViewProps.boxShadow,
1102
- autoplay = _get360ViewProps.autoplay,
1103
- autoplayBehavior = _get360ViewProps.autoplayBehavior,
1104
- playOnce = _get360ViewProps.playOnce,
1105
- speed = _get360ViewProps.speed,
1106
- autoplayReverse = _get360ViewProps.autoplayReverse,
1107
- _get360ViewProps$disa = _get360ViewProps.disableDrag,
1108
- disableDrag = _get360ViewProps$disa === void 0 ? true : _get360ViewProps$disa,
1109
- fullscreen = _get360ViewProps.fullscreen,
1110
- magnifier = _get360ViewProps.magnifier,
1111
- ciToken = _get360ViewProps.ciToken,
1112
- ciFilters = _get360ViewProps.ciFilters,
1113
- ciTransformation = _get360ViewProps.ciTransformation,
1114
- lazyload = _get360ViewProps.lazyload,
1115
- lazySelector = _get360ViewProps.lazySelector,
1116
- spinReverse = _get360ViewProps.spinReverse,
1117
- dragSpeed = _get360ViewProps.dragSpeed,
1118
- stopAtEdges = _get360ViewProps.stopAtEdges,
1119
- controlReverse = _get360ViewProps.controlReverse,
1120
- hide360Logo = _get360ViewProps.hide360Logo,
1121
- logoSrc = _get360ViewProps.logoSrc,
1122
- pointerZoom = _get360ViewProps.pointerZoom,
1123
- ratio = _get360ViewProps.ratio,
1124
- _get360ViewProps$imag = _get360ViewProps.imageInfo,
1125
- imageInfo = _get360ViewProps$imag === void 0 ? 'black' : _get360ViewProps$imag,
1126
- requestResponsiveImages = _get360ViewProps.requestResponsiveImages;
1127
- var ciParams = {
1128
- ciToken: ciToken,
1129
- ciFilters: ciFilters,
1130
- ciTransformation: ciTransformation
1131
- };
1132
- this.folder = folder;
1133
- this.apiVersion = apiVersion;
1134
- this.filenameX = filenameX;
1135
- this.filenameY = filenameY;
1136
- this.imageListX = imageListX;
1137
- this.imageListY = imageListY;
1138
- this.indexZeroBase = indexZeroBase;
1139
- this.amountX = imageListX ? JSON.parse(imageListX).length : amountX;
1140
- this.amountY = imageListY ? JSON.parse(imageListY).length : amountY;
1141
- this.allowSpinY = !!this.amountY;
1142
- this.activeImageX = autoplayReverse ? this.amountX : 1;
1143
- this.activeImageY = autoplayReverse ? this.amountY : 1;
1144
- this.spinY = autoplayBehavior === _constants.AUTOPLAY_BEHAVIOR.SPIN_YX ? true : false;
1145
- this.bottomCircle = bottomCircle;
1146
- this.bottomCircleOffset = bottomCircleOffset;
1147
- this.boxShadow = boxShadow;
1148
- this.autoplay = autoplay;
1149
- this.autoplayBehavior = autoplayBehavior;
1150
- this.playOnce = playOnce;
1151
- this.speed = speed;
1152
- this.reversed = autoplayReverse;
1153
- this.disableDrag = disableDrag;
1154
- this.fullscreen = fullscreen;
1155
- this.magnifier = !this.isMobile && magnifier > 1 ? Math.min(magnifier, 5) : 0;
1156
- this.lazySelector = lazySelector;
1157
- this.spinReverse = spinReverse;
1158
- this.controlReverse = controlReverse;
1159
- this.dragSpeed = Math.max(dragSpeed, 50);
1160
- this.autoplaySpeed = this.speed * 36 / this.amountX;
1161
- this.stopAtEdges = stopAtEdges;
1162
- this.hide360Logo = hide360Logo;
1163
- this.logoSrc = logoSrc;
1164
- this.ciParams = ciParams;
1165
- this.apiVersion = apiVersion;
1166
- this.pointerZoom = pointerZoom > 1 ? Math.min(pointerZoom, 3) : 0;
1167
- this.keysReverse = keysReverse;
1168
- this.info = imageInfo;
1169
- this.keys = keys;
1170
- this.ratio = ratio && JSON.parse(ratio);
1171
- this.requestResponsiveImages = requestResponsiveImages;
1172
- if (update) {
1173
- (0, _utils.removeChildFromParent)(this.innerBox, this.iconsContainer);
1174
- (0, _utils.removeChildFromParent)(this.innerBox, this.boxShadowEl);
1175
- (0, _utils.removeChildFromParent)(this.innerBox, this.view360Icon);
1176
- this.remove360ViewCircleIcon();
1177
- this.iconsContainer = (0, _utils.createIconsContainer)(this.innerBox);
1178
- if (!this.hide360Logo && !this.lazyload && this.logoSrc) {
1179
- this.add360ViewIcon();
1180
- (0, _ci.setView360Icon)(this.view360Icon, this.logoSrc);
1181
- }
1182
- if (this.magnifier) {
1183
- this.addMagnifier();
1184
- }
1185
- if (this.bottomCircle && !this.fullscreenView) {
1186
- this.add360ViewCircleIcon();
1187
- }
1188
- if (this.fullscreen && !this.fullscreenView) {
1189
- this.addFullscreenIcon();
1190
- }
1191
- if (this.boxShadow && !this.fullscreenView) {
1192
- this.boxShadowEl = (0, _utils.createBoxShadow)(this.boxShadow, this.innerBox);
1193
- }
1194
- if (hotspotsConfigs && !this.fullscreenView) {
1195
- this.hotspotsConfigs = (0, _utils.generateHotspotsConfigs)(hotspotsConfigs);
1196
- (0, _utils.createHotspots)(container, this.hotspotsConfigs);
1197
- }
1198
- return this.onAllImagesLoaded();
1199
- }
1200
- this.innerBox = (0, _utils.createInnerBox)(this.container);
1201
- this.iconsContainer = (0, _utils.createIconsContainer)(this.innerBox);
1202
- this.canvas = (0, _utils.createCanvas)(this.innerBox);
1203
- this.loader = (0, _utils.createLoader)(this.innerBox);
1204
- if (this.hotspotsConfigs && !this.fullscreenView) {
1205
- (0, _utils.createHotspots)(container, this.hotspotsConfigs);
1206
- }
1207
- (0, _utils.applyStylesToContainer)(this.container);
1208
- this.srcXConfig = {
1209
- folder: folder,
1210
- filename: filenameX,
1211
- imageList: imageListX,
1212
- container: container,
1213
- innerBox: this.innerBox,
1214
- apiVersion: apiVersion,
1215
- ciParams: ciParams,
1216
- lazySelector: lazySelector,
1217
- amount: this.amountX,
1218
- indexZeroBase: indexZeroBase,
1219
- fullscreen: this.fullscreenView
1220
- };
1221
- this.srcYConfig = _objectSpread(_objectSpread({}, this.srcXConfig), {}, {
1222
- filename: filenameY,
1223
- orientation: _constants.ORIENTATIONS.Y,
1224
- imageList: imageListY,
1225
- amount: this.amountY
1226
- });
1227
- var srcX = (0, _utils.generateImagesPath)(this.srcXConfig);
1228
- var onImageLoad = function onImageLoad(orientation, image, index) {
1229
- if (orientation === _constants.ORIENTATIONS.X) {
1230
- _this7.imagesX[index] = image;
1231
- } else {
1232
- _this7.imagesY[index] = image;
1233
- }
1234
- var totalAmount = _this7.amountX + _this7.amountY;
1235
- var totalLoadedImages = _this7.imagesX.length + _this7.imagesY.length;
1236
- var isFirstImageLoaded = !index && orientation !== _constants.ORIENTATIONS.Y;
1237
- var percentage = Math.round(totalLoadedImages / totalAmount * 100);
1238
- _this7.updatePercentageInLoader(percentage);
1239
- if (isFirstImageLoaded) {
1240
- _this7.onFirstImageLoaded(image);
1241
- } else if (_this7.autoplay) {
1242
- _this7.moveRight(index);
1243
- }
1244
- if (_this7.isReady()) {
1245
- _this7.onAllImagesLoaded();
1246
- }
1247
- };
1248
- var loadImages = function loadImages() {
1249
- (0, _utils.preloadImages)(_this7.srcXConfig, srcX, onImageLoad.bind(_this7, _constants.ORIENTATIONS.X));
1250
- if (_this7.allowSpinY) {
1251
- var srcY = (0, _utils.generateImagesPath)(_this7.srcYConfig);
1252
- (0, _utils.preloadImages)(_this7.srcYConfig, srcY, onImageLoad.bind(_this7, _constants.ORIENTATIONS.Y));
1253
- }
1254
- };
1255
- if (lazyload) {
1256
- var onFirstImageLoad = function onFirstImageLoad(image) {
1257
- _this7.innerBox.removeChild(image);
1258
- loadImages();
1259
- };
1260
- (0, _utils.initLazyload)(srcX, this.srcXConfig, onFirstImageLoad);
1261
- } else {
1262
- loadImages();
1263
- }
1264
- this.attachEvents(draggable, swipeable, keys);
1265
- }
1266
- }]);
1267
- return CI360Viewer;
1268
- }();
1269
- var _default = CI360Viewer;
1270
- exports.default = _default;