js-cloudimage-360-view 2.7.5 → 2.7.6

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/CHANGELOG.md CHANGED
@@ -25,7 +25,12 @@ Types of changes:
25
25
  - ...
26
26
 
27
27
  -------------
28
- ## 2.7.5 - 2022-01-08
28
+ ## 2.7.6 - 2022-02-20
29
+ ### Fixed
30
+ - drag speed
31
+ - responsive canvas width and height
32
+
33
+ ## 2.7.5 - 2022-02-08
29
34
  ### Added
30
35
  - update method to re-render or re-init the plugin
31
36
  ### Fixed
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Release](https://img.shields.io/badge/release-v2.7.5-blue.svg)](https://github.com/scaleflex/js-cloudimage-360-view/releases)
1
+ [![Release](https://img.shields.io/badge/release-v2.7.6-blue.svg)](https://github.com/scaleflex/js-cloudimage-360-view/releases)
2
2
  [![Contributions welcome](https://img.shields.io/badge/contributions-welcome-orange.svg)](#contributing)
3
3
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
4
  [![Scaleflex team](https://img.shields.io/badge/%3C%2F%3E%20with%20%E2%99%A5%20by-the%20Scaleflex%20team-6986fa.svg)](https://www.scaleflex.it/en/home)
@@ -6,16 +6,9 @@
6
6
  [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Engage%20your%20customers%20with%20a%20stunning%20360%20viewvof%20your%20products&url=https://scaleflex.github.io/js-cloudimage-360-view/&via=cloudimage&hashtags=images,cloudimage)
7
7
 
8
8
  <p align="center">
9
- <a href="https://www.cloudimage.io/#gh-light-mode-only">
10
- <img
11
- alt="The Lounge"
12
- src="https://scaleflex.cloudimg.io/v7/cloudimage.io/LOGO+WITH+SCALEFLEX-01.png?vh=f6080d&w=350">
13
- </a>
14
- <a href="https://www.cloudimage.io/#gh-dark-mode-only">
15
- <img
16
- alt="The Lounge"
17
- src="https://scaleflex.cloudimg.io/v7/cloudimage.io/cloudimage-logo-light.png?vh=b798ab&w=350">
18
- </a>
9
+ <img
10
+ alt="The Lounge"
11
+ src="https://scaleflex.cloudimg.io/v7/cloudimage.io/LOGO+WITH+SCALEFLEX-01.png?vh=f6080d&w=350">
19
12
  </p>
20
13
 
21
14
  <h1 align="center">
@@ -308,25 +301,49 @@ Open 360 spin view in full screen modal.
308
301
 
309
302
  Magnifier to zoom image.
310
303
 
311
- ### ~~data-ratio (or ratio)~~ [deprecated]
312
-
313
-
314
- ###### ~~Type: **Number** (height / width) | Default: **none** | _optional_~~
304
+ ### data-ratio (or ratio)
315
305
 
316
- ~~Prevents page from jumping.~~
317
- ### data-width (or width)
318
306
 
319
- ###### Type: **Number** | Default: **none** | _optional_
307
+ ###### Type: **Number** (width / height) or JSON object | Default: **none** | _optional_
308
+ #### `ratio`: string
320
309
 
321
- Set a responsive width for the container.
322
- It will maintain the aspect ratio in respect to width
323
- ### data-height (or height)
310
+ Setting the height relative to the container width according to the provided ratio</br>
311
+ In the following example, the height should be 0.3 the container width
324
312
 
325
- ###### Type: **Number** | Default: **none** | _optional_
313
+ ```html
314
+ <div
315
+ id="cloudimage-360-car"
316
+ class="cloudimage-360"
317
+ data-folder="https://scaleflex.airstore.io/demo/360-car/"
318
+ data-filename-x="iris-{index}.jpeg"
319
+ data-amount-x="36"
320
+ data-ratio="2"
321
+ ></div>
322
+ ```
323
+ <a href="https://codesandbox.io/s/js-cloudimage-360-view-g4wyt1?file=/index.html"><img src="https://codesandbox.io/static/img/play-codesandbox.svg" alt="edit in codesandbox"/></a>
324
+ #### `ratio`: JSON
325
+ Setting the height relative to the container width at any window size.
326
326
 
327
- Set a responsive height for the container.
328
- It will maintain the aspect ratio in respect to height
327
+ In the following example, the height should be 1.3 the container width at window size less than or equal to 567px
328
+ and 2.22 at window size less than or equal to 768px.
329
329
 
330
+ ```html
331
+ <div
332
+ id="cloudimage-360-car"
333
+ class="cloudimage-360"
334
+ data-folder="https://scaleflex.airstore.io/demo/360-car/"
335
+ data-filename-x="iris-{index}.jpeg"
336
+ data-amount-x="36"
337
+ data-ratio='{
338
+ "576": "1.3",
339
+ "768": "2.22",
340
+ "992": "2.23",
341
+ "1200": "3",
342
+ "2400": "3.2"
343
+ }'
344
+ ></div>
345
+ ```
346
+ <a href="https://codesandbox.io/s/js-cloudimage-360-view-5tssb7?file=/index.html"><img src="https://codesandbox.io/static/img/play-codesandbox.svg" alt="edit in codesandbox"/></a>
330
347
  ### data-autoplay-reverse (or autoplay-reverse)
331
348
 
332
349
  ###### Type: **Bool** | Default: **false** | _optional_
@@ -639,13 +639,9 @@ var CI360Viewer = /*#__PURE__*/function () {
639
639
  (0, _utils.loop)(this.autoplayBehavior, this.spinY, reversed, loopTriggers);
640
640
  }
641
641
  }, {
642
- key: "updateContainerSize",
643
- value: function updateContainerSize(image) {
644
- var parentEl = this.container.parentNode || {};
645
- var imageAspectRatio = image.width / image.height;
646
- var isProvidedHeightLessThanWidth = this.containerHeight < this.containerWidth;
647
- var containerWidth = (0, _utils.getContainerResponsiveWidth)(parentEl, this.containerWidth);
648
- var containerHeight = (0, _utils.getContainerResponsiveHeight)(this.container, containerWidth, this.containerHeight);
642
+ key: "updateContainerAndCanvasSize",
643
+ value: function updateContainerAndCanvasSize(image) {
644
+ var imageAspectRatio = (0, _utils.getImageAspectRatio)(image, this.ratio);
649
645
 
650
646
  if (this.fullscreenView) {
651
647
  this.container.width = window.innerWidth * this.devicePixelRatio;
@@ -656,24 +652,10 @@ var CI360Viewer = /*#__PURE__*/function () {
656
652
  return;
657
653
  }
658
654
 
659
- if (this.containerWidth && this.containerHeight) {
660
- this.container.style.width = containerWidth + 'px';
661
- this.container.style.height = containerHeight / imageAspectRatio + 'px';
662
- return;
663
- }
664
-
665
- if (!this.containerWidth && !this.containerHeight) {
666
- this.container.style.height = containerHeight / imageAspectRatio + 'px';
667
- return;
668
- }
669
-
670
- if ((isProvidedHeightLessThanWidth || !this.containerWidth) && this.containerHeight) {
671
- this.container.style.maxWidth = containerHeight * imageAspectRatio + 'px';
672
- this.container.style.height = containerHeight + 'px';
673
- } else {
674
- this.container.style.maxWidth = containerWidth + 'px';
675
- this.container.style.height = containerWidth / imageAspectRatio + 'px';
676
- }
655
+ this.canvas.width = this.container.offsetWidth * this.devicePixelRatio;
656
+ this.canvas.style.width = this.container.offsetWidth + 'px';
657
+ this.canvas.height = this.container.offsetWidth / imageAspectRatio * this.devicePixelRatio;
658
+ this.canvas.style.height = this.container.offsetWidth / imageAspectRatio + 'px';
677
659
  }
678
660
  }, {
679
661
  key: "onResizedImageLoad",
@@ -703,7 +685,7 @@ var CI360Viewer = /*#__PURE__*/function () {
703
685
  value: function requestResizedImages() {
704
686
  var responsive = this.ciParams.ciToken;
705
687
  var firstImage = this.imagesX[0];
706
- this.updateContainerSize(firstImage);
688
+ this.updateContainerAndCanvasSize(firstImage);
707
689
  this.update();
708
690
  this.speedFactor = (0, _utils.getSpeedFactor)(this.dragSpeed, this.amountX, this.container.offsetWidth);
709
691
  var srcX = (0, _utils.generateImagesPath)(this.srcXConfig);
@@ -726,10 +708,6 @@ var CI360Viewer = /*#__PURE__*/function () {
726
708
 
727
709
  var ctx = this.canvas.getContext("2d");
728
710
  ctx.scale(this.devicePixelRatio, this.devicePixelRatio);
729
- this.canvas.width = this.container.offsetWidth * this.devicePixelRatio;
730
- this.canvas.style.width = this.container.offsetWidth + 'px';
731
- this.canvas.height = this.container.offsetHeight * this.devicePixelRatio;
732
- this.canvas.style.height = this.container.offsetHeight + 'px';
733
711
 
734
712
  if (this.fullscreenView) {
735
713
  var _contain = (0, _utils.contain)(this.canvas.width, this.canvas.height, image.width, image.height),
@@ -1214,9 +1192,8 @@ var CI360Viewer = /*#__PURE__*/function () {
1214
1192
  controlReverse = _get360ViewProps.controlReverse,
1215
1193
  hide360Logo = _get360ViewProps.hide360Logo,
1216
1194
  logoSrc = _get360ViewProps.logoSrc,
1217
- containerWidth = _get360ViewProps.containerWidth,
1218
- containerHeight = _get360ViewProps.containerHeight,
1219
- pointerZoom = _get360ViewProps.pointerZoom;
1195
+ pointerZoom = _get360ViewProps.pointerZoom,
1196
+ ratio = _get360ViewProps.ratio;
1220
1197
 
1221
1198
  var ciParams = {
1222
1199
  ciToken: ciToken,
@@ -1252,17 +1229,16 @@ var CI360Viewer = /*#__PURE__*/function () {
1252
1229
  this.lazySelector = lazySelector;
1253
1230
  this.spinReverse = spinReverse;
1254
1231
  this.controlReverse = controlReverse;
1255
- this.dragSpeed = Math.max(magnifier, 50);
1232
+ this.dragSpeed = Math.max(dragSpeed, 50);
1256
1233
  this.autoplaySpeed = this.speed * 36 / this.amountX;
1257
1234
  this.stopAtEdges = stopAtEdges;
1258
1235
  this.hide360Logo = hide360Logo;
1259
1236
  this.logoSrc = logoSrc;
1260
1237
  this.ciParams = ciParams;
1261
1238
  this.apiVersion = apiVersion;
1262
- this.containerWidth = containerWidth;
1263
- this.containerHeight = containerHeight;
1264
1239
  this.pointerZoom = pointerZoom > 1 ? Math.min(pointerZoom, 3) : 0;
1265
1240
  this.keysReverse = keysReverse;
1241
+ this.ratio = ratio && JSON.parse(ratio);
1266
1242
 
1267
1243
  if (reload) {
1268
1244
  new CI360Viewer(this.container);
@@ -1347,7 +1323,7 @@ var CI360Viewer = /*#__PURE__*/function () {
1347
1323
  if (_this6.lazyloadX || _this6.lazyloadY) return initLazyload(image, orientation);
1348
1324
 
1349
1325
  if (isFirstImageLoaded) {
1350
- _this6.updateContainerSize(image);
1326
+ _this6.updateContainerAndCanvasSize(image);
1351
1327
 
1352
1328
  _this6.onFirstImageLoaded(image);
1353
1329
  }
@@ -46,8 +46,7 @@ var get360ViewProps = function get360ViewProps(image) {
46
46
  stopAtEdges: isTrue(image, 'stop-at-edges'),
47
47
  hide360Logo: isTrue(image, 'hide-360-logo'),
48
48
  logoSrc: attr(image, 'logo-src') || 'https://scaleflex.ultrafast.io/https://scaleflex.airstore.io/filerobot/js-cloudimage-360-view/360_view.svg',
49
- containerWidth: parseInt(attr(image, 'width') || attr(image, 'data-width'), 10) || 0,
50
- containerHeight: parseInt(attr(image, 'height') || attr(image, 'data-height'), 10) || 0
49
+ ratio: attr(image, 'ratio') || attr(image, 'data-ratio') || null
51
50
  };
52
51
  };
53
52
 
@@ -4,30 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
+ isSrcPropsChanged: true,
7
8
  generateImagesPath: true,
8
9
  preloadImages: true,
9
10
  preloadOriginalImages: true,
10
11
  contain: true,
12
+ getImageAspectRatio: true,
11
13
  getCurrentOriginalImage: true,
12
14
  magnify: true,
15
+ generateZoomInSteps: true,
16
+ generateZoomOutSteps: true,
17
+ loop: true,
13
18
  getSpeedFactor: true,
14
19
  isCompletedOneCycle: true,
15
- getContainerResponsiveWidth: true,
16
- getContainerResponsiveHeight: true,
17
- getMovingDirection: true,
18
- initControls: true,
19
20
  addClass: true,
20
21
  removeClass: true,
22
+ getMovingDirection: true,
21
23
  getItemSkipped: true,
22
- loop: true,
23
- generateZoomInSteps: true,
24
- generateZoomOutSteps: true,
24
+ initControls: true,
25
25
  updateHotspots: true,
26
26
  createHotspots: true,
27
27
  generateHotspotsConfigs: true,
28
28
  isMouseOnHotspot: true,
29
- hideHotspotsIcons: true,
30
- isSrcPropsChanged: true
29
+ hideHotspotsIcons: true
31
30
  };
32
31
  Object.defineProperty(exports, "addClass", {
33
32
  enumerable: true,
@@ -71,22 +70,16 @@ Object.defineProperty(exports, "generateZoomOutSteps", {
71
70
  return _generateZoomOutSteps.generateZoomOutSteps;
72
71
  }
73
72
  });
74
- Object.defineProperty(exports, "getContainerResponsiveHeight", {
75
- enumerable: true,
76
- get: function get() {
77
- return _getContainerResponsiveHeight.getContainerResponsiveHeight;
78
- }
79
- });
80
- Object.defineProperty(exports, "getContainerResponsiveWidth", {
73
+ Object.defineProperty(exports, "getCurrentOriginalImage", {
81
74
  enumerable: true,
82
75
  get: function get() {
83
- return _getContainerResponsiveWidth.getContainerResponsiveWidth;
76
+ return _getCurrentOriginalImage.getCurrentOriginalImage;
84
77
  }
85
78
  });
86
- Object.defineProperty(exports, "getCurrentOriginalImage", {
79
+ Object.defineProperty(exports, "getImageAspectRatio", {
87
80
  enumerable: true,
88
81
  get: function get() {
89
- return _getCurrentOriginalImage.getCurrentOriginalImage;
82
+ return _getImageAspectRatio.getImageAspectRatio;
90
83
  }
91
84
  });
92
85
  Object.defineProperty(exports, "getItemSkipped", {
@@ -174,6 +167,8 @@ Object.defineProperty(exports, "updateHotspots", {
174
167
  }
175
168
  });
176
169
 
170
+ var _isSrcPropsChanged = require("./image-src/is-src-props-changed");
171
+
177
172
  var _generateImagesPath = require("./image-src/generate-images-path");
178
173
 
179
174
  var _preloadImages = require("./load-images/preload-images");
@@ -182,28 +177,32 @@ var _preloadOriginalImages = require("./load-images/preload-original-images");
182
177
 
183
178
  var _contain = require("./responsive/contain");
184
179
 
180
+ var _getImageAspectRatio = require("./responsive/get-image-aspect-ratio");
181
+
185
182
  var _getCurrentOriginalImage = require("./magnify/get-current-original-image");
186
183
 
187
184
  var _magnify = require("./magnify/magnify");
188
185
 
189
- var _getSpeedFactor = require("./auto-play/get-speed-factor");
190
-
191
- var _isCompletedOneCycle = require("./auto-play/is-completed-one-cycle");
186
+ var _generateZoomInSteps = require("./zoom/generate-zoom-in-steps");
192
187
 
193
- var _getContainerResponsiveWidth = require("./responsive/get-container-responsive-width");
188
+ var _generateZoomOutSteps = require("./zoom/generate-zoom-out-steps");
194
189
 
195
- var _getContainerResponsiveHeight = require("./responsive/get-container-responsive-height");
190
+ var _loop = require("./auto-play/loop");
196
191
 
197
- var _getMovingDirection = require("./spin-y/get-moving-direction");
192
+ var _getSpeedFactor = require("./auto-play/get-speed-factor");
198
193
 
199
- var _initControls = require("./controls/init-controls");
194
+ var _isCompletedOneCycle = require("./auto-play/is-completed-one-cycle");
200
195
 
201
196
  var _addClass = require("./common/add-class");
202
197
 
203
198
  var _removeClass = require("./common/remove-class");
204
199
 
200
+ var _getMovingDirection = require("./spin-y/get-moving-direction");
201
+
205
202
  var _getItemSkipped = require("./controls/get-item-skipped");
206
203
 
204
+ var _initControls = require("./controls/init-controls");
205
+
207
206
  var _containerElements = require("./container-elements");
208
207
 
209
208
  Object.keys(_containerElements).forEach(function (key) {
@@ -218,12 +217,6 @@ Object.keys(_containerElements).forEach(function (key) {
218
217
  });
219
218
  });
220
219
 
221
- var _loop = require("./auto-play/loop");
222
-
223
- var _generateZoomInSteps = require("./zoom/generate-zoom-in-steps");
224
-
225
- var _generateZoomOutSteps = require("./zoom/generate-zoom-out-steps");
226
-
227
220
  var _updateHotspots = require("./hotspot/update-hotspots");
228
221
 
229
222
  var _createHotspots = require("./hotspot/elements/create-hotspots");
@@ -232,6 +225,4 @@ var _generateHotspotsConfigs = require("./hotspot/generate-hotspots-configs");
232
225
 
233
226
  var _isMouseOnHotspot = require("./hotspot/is-mouse-on-hotspot");
234
227
 
235
- var _hideHotspotsIcons = require("./hotspot/hide-hotspots-icons");
236
-
237
- var _isSrcPropsChanged = require("./image-src/is-src-props-changed");
228
+ var _hideHotspotsIcons = require("./hotspot/hide-hotspots-icons");
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.getImageAspectRatio = void 0;
9
+
10
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
+
12
+ var getImageAspectRatio = function getImageAspectRatio(image, providedRatio) {
13
+ try {
14
+ var imageAspectRatio = image.width / image.height;
15
+
16
+ if (typeof providedRatio === 'number') {
17
+ imageAspectRatio = providedRatio;
18
+ }
19
+
20
+ if ((0, _typeof2.default)(providedRatio) === 'object') {
21
+ var mediaQueries = Object.keys(providedRatio).sort(function (a, b) {
22
+ return a - b;
23
+ });
24
+ var activeMedia = mediaQueries.find(function (mediaQuery) {
25
+ return window.innerWidth <= parseInt(mediaQuery, 10);
26
+ });
27
+
28
+ if (activeMedia) {
29
+ imageAspectRatio = providedRatio[activeMedia];
30
+ }
31
+ }
32
+
33
+ return imageAspectRatio;
34
+ } catch (_unused) {
35
+ return 1;
36
+ }
37
+ };
38
+
39
+ exports.getImageAspectRatio = getImageAspectRatio;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-cloudimage-360-view",
3
- "version": "2.7.5",
3
+ "version": "2.7.6",
4
4
  "main": "dist/index.js",
5
5
  "description": "",
6
6
  "author": "scaleflex",
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getContainerResponsiveHeight = void 0;
7
-
8
- var getContainerResponsiveHeight = function getContainerResponsiveHeight(container, width, containerHeight) {
9
- if (containerHeight) {
10
- if (width < containerHeight) {
11
- return width;
12
- }
13
-
14
- return containerHeight;
15
- }
16
-
17
- return container.offsetWidth;
18
- };
19
-
20
- exports.getContainerResponsiveHeight = getContainerResponsiveHeight;
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getContainerResponsiveWidth = void 0;
7
-
8
- var getContainerResponsiveWidth = function getContainerResponsiveWidth(parentEl, containerWidth) {
9
- if (containerWidth) {
10
- if (parentEl.offsetWidth < containerWidth) {
11
- return parentEl.offsetWidth;
12
- }
13
-
14
- return containerWidth;
15
- }
16
-
17
- return parentEl.offsetWidth;
18
- };
19
-
20
- exports.getContainerResponsiveWidth = getContainerResponsiveWidth;