@gamelearn/arcade-components 0.26.7 → 0.27.0

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.
@@ -30,6 +30,43 @@ function _iterableToArrayLimit(arr, i) { var _i = arr && (typeof Symbol !== "und
30
30
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
31
31
 
32
32
  _reactPdf.pdfjs.GlobalWorkerOptions.workerSrc = "//cdnjs.cloudflare.com/ajax/libs/pdf.js/".concat(_reactPdf.pdfjs.version, "/pdf.worker.js");
33
+ var SCALE_LIMIT = 2;
34
+ var maxValues = {
35
+ default: {
36
+ area: 268435456,
37
+ sideBig: 65535
38
+ },
39
+ firefox: {
40
+ area: 124992400,
41
+ sideBig: 32767
42
+ },
43
+ safari: {
44
+ area: 16777216,
45
+ sideBig: 4194303
46
+ }
47
+ };
48
+
49
+ var getMaxPermitted = function getMaxPermitted() {
50
+ var browser = (0, _deviceDetection.BrowserDetection)();
51
+ return maxValues[browser];
52
+ };
53
+
54
+ var formatScale = function formatScale(value) {
55
+ return value > 1 ? Math.floor(value) : Math.floor(value * 100) / 100;
56
+ };
57
+
58
+ var getMaxScaleByArea = function getMaxScaleByArea(maxArea, width, height) {
59
+ var actualArea = width * height * Math.pow(window.devicePixelRatio, 2);
60
+ var maxScale = Math.sqrt(maxArea / actualArea);
61
+ return formatScale(maxScale);
62
+ };
63
+
64
+ var getMaxScaleBySide = function getMaxScaleBySide(side, width, height) {
65
+ var max = width > height ? width : height;
66
+ var permitted = side / window.devicePixelRatio;
67
+ var maxScale = permitted / max;
68
+ return formatScale(maxScale);
69
+ };
33
70
 
34
71
  var PdfVisor = function PdfVisor(_ref) {
35
72
  var url = _ref.url,
@@ -54,12 +91,28 @@ var PdfVisor = function PdfVisor(_ref) {
54
91
  currentPage = _useState6[0],
55
92
  setCurrentPage = _useState6[1];
56
93
 
57
- var scale = (0, _deviceDetection.DeviceDetection)() ? 1 : 2;
94
+ var _useState7 = (0, _react.useState)(1),
95
+ _useState8 = _slicedToArray(_useState7, 2),
96
+ scale = _useState8[0],
97
+ setScale = _useState8[1];
58
98
 
59
99
  var _soundActions = _slicedToArray(soundActions, 1),
60
100
  play = _soundActions[0];
61
101
 
62
- var handleLoadSucess = (0, _react.useCallback)(function (pdf) {
102
+ var handleLoadSuccess = (0, _react.useCallback)(function (pdf) {
103
+ pdf.getPage(1).then(function (page) {
104
+ var viewport = page.getViewport(1);
105
+ var width = viewport.viewBox[2] - viewport.viewBox[0];
106
+ var height = viewport.viewBox[3] - viewport.viewBox[1];
107
+ var maxPermitted = getMaxPermitted(); // get max values for browser
108
+
109
+ var maxScaleByArea = getMaxScaleByArea(maxPermitted.area, width, height);
110
+ var maxScaleBySide = getMaxScaleBySide(maxPermitted.sideBig, width, height); // valid scale is the smallest scale
111
+
112
+ var validScale = maxScaleByArea < maxScaleBySide ? maxScaleByArea : maxScaleBySide;
113
+ setScale(validScale > SCALE_LIMIT ? SCALE_LIMIT : validScale);
114
+ });
115
+
63
116
  if (pdf.numPages) {
64
117
  emitNumberOfPages(pdf.numPages);
65
118
  }
@@ -85,9 +138,9 @@ var PdfVisor = function PdfVisor(_ref) {
85
138
  var documentProps = {
86
139
  file: url,
87
140
  loading: 'Loading file...',
88
- onLoadSuccess: handleLoadSucess,
141
+ onLoadSuccess: handleLoadSuccess,
89
142
  onLoadError: function onLoadError(error) {
90
- return console.log(error);
143
+ return console.error(error);
91
144
  }
92
145
  };
93
146
 
@@ -3,11 +3,22 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.DeviceDetection = void 0;
6
+ exports.BrowserDetection = exports.DeviceDetection = void 0;
7
7
 
8
8
  var DeviceDetection = function DeviceDetection() {
9
9
  return navigator.userAgent.match(/(android)/i) || ['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator.platform) || // iPad on iOS 13 detection
10
10
  navigator.userAgent.includes('Mac') && 'ontouchend' in document;
11
11
  };
12
12
 
13
- exports.DeviceDetection = DeviceDetection;
13
+ exports.DeviceDetection = DeviceDetection;
14
+
15
+ var BrowserDetection = function BrowserDetection() {
16
+ var ua = navigator.userAgent.toLowerCase();
17
+ var isFirefox = ua.indexOf('firefox') > -1;
18
+ var isSafari = ua.indexOf('safari') > -1 && ua.indexOf('chrome') <= -1;
19
+ var res = 'default';
20
+ if (isFirefox) res = 'firefox';else if (isSafari) res = 'safari';
21
+ return res;
22
+ };
23
+
24
+ exports.BrowserDetection = BrowserDetection;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gamelearn/arcade-components",
3
3
  "license": "Gamelearn",
4
- "version": "0.26.7",
4
+ "version": "0.27.0",
5
5
  "main": "dist/index.js",
6
6
  "files": [
7
7
  "dist",