redhotmagma-visualization 1.56.4 → 1.57.2
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/Utils/imagePreloader.js +15 -11
- package/package.json +2 -2
- package/src/Utils/imagePreloader.js +5 -6
package/Utils/imagePreloader.js
CHANGED
|
@@ -13,8 +13,10 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
|
|
|
13
13
|
import once from "lodash/once";
|
|
14
14
|
export var createImagePreloader = function createImagePreloader(srcArr) {
|
|
15
15
|
var ready = false;
|
|
16
|
-
|
|
16
|
+
/** @type {Map<string, HTMLImageElement>|undefined} */
|
|
17
|
+
var imagesBySrc;
|
|
17
18
|
var loadAll = once( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
19
|
+
var images;
|
|
18
20
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
19
21
|
while (1) switch (_context.prev = _context.next) {
|
|
20
22
|
case 0:
|
|
@@ -35,19 +37,24 @@ export var createImagePreloader = function createImagePreloader(srcArr) {
|
|
|
35
37
|
}));
|
|
36
38
|
case 3:
|
|
37
39
|
images = _context.sent;
|
|
40
|
+
imagesBySrc = new Map(images.map(function (_ref2) {
|
|
41
|
+
var src = _ref2.src,
|
|
42
|
+
img = _ref2.img;
|
|
43
|
+
return [src, img];
|
|
44
|
+
}));
|
|
38
45
|
ready = true;
|
|
39
|
-
_context.next =
|
|
46
|
+
_context.next = 11;
|
|
40
47
|
break;
|
|
41
|
-
case
|
|
42
|
-
_context.prev =
|
|
48
|
+
case 8:
|
|
49
|
+
_context.prev = 8;
|
|
43
50
|
_context.t0 = _context["catch"](0);
|
|
44
51
|
// eslint-disable-next-line no-console
|
|
45
52
|
console.error("Error while loading resource!", _context.t0);
|
|
46
|
-
case
|
|
53
|
+
case 11:
|
|
47
54
|
case "end":
|
|
48
55
|
return _context.stop();
|
|
49
56
|
}
|
|
50
|
-
}, _callee, null, [[0,
|
|
57
|
+
}, _callee, null, [[0, 8]]);
|
|
51
58
|
})));
|
|
52
59
|
return {
|
|
53
60
|
loadAll: loadAll,
|
|
@@ -55,11 +62,8 @@ export var createImagePreloader = function createImagePreloader(srcArr) {
|
|
|
55
62
|
return ready;
|
|
56
63
|
},
|
|
57
64
|
get: function get(searchSrc) {
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
return src === searchSrc;
|
|
61
|
-
}).pop();
|
|
62
|
-
return item && item.img;
|
|
65
|
+
var _imagesBySrc;
|
|
66
|
+
return (_imagesBySrc = imagesBySrc) === null || _imagesBySrc === void 0 ? void 0 : _imagesBySrc.get(searchSrc);
|
|
63
67
|
}
|
|
64
68
|
};
|
|
65
69
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redhotmagma-visualization",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.57.2",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./index.js",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@babel/polyfill": "^7.12.1",
|
|
9
|
-
"@configuratorware/scripts": "1.
|
|
9
|
+
"@configuratorware/scripts": "1.57.2",
|
|
10
10
|
"@tweenjs/tween.js": "^17.6.0",
|
|
11
11
|
"console-polyfill": "^0.3.0",
|
|
12
12
|
"css-element-queries": "^1.2.3",
|
|
@@ -2,11 +2,12 @@ import once from "lodash/once";
|
|
|
2
2
|
|
|
3
3
|
export const createImagePreloader = srcArr => {
|
|
4
4
|
let ready = false;
|
|
5
|
-
|
|
5
|
+
/** @type {Map<string, HTMLImageElement>|undefined} */
|
|
6
|
+
let imagesBySrc;
|
|
6
7
|
|
|
7
8
|
const loadAll = once(async () => {
|
|
8
9
|
try {
|
|
9
|
-
images = await Promise.all(
|
|
10
|
+
const images = await Promise.all(
|
|
10
11
|
srcArr.map(
|
|
11
12
|
src =>
|
|
12
13
|
new Promise((resolve, reject) => {
|
|
@@ -17,6 +18,7 @@ export const createImagePreloader = srcArr => {
|
|
|
17
18
|
})
|
|
18
19
|
)
|
|
19
20
|
);
|
|
21
|
+
imagesBySrc = new Map(images.map(({ src, img }) => [src, img]));
|
|
20
22
|
ready = true;
|
|
21
23
|
} catch (e) {
|
|
22
24
|
// eslint-disable-next-line no-console
|
|
@@ -27,9 +29,6 @@ export const createImagePreloader = srcArr => {
|
|
|
27
29
|
return {
|
|
28
30
|
loadAll,
|
|
29
31
|
isReady: () => ready,
|
|
30
|
-
get: searchSrc =>
|
|
31
|
-
const item = images && images.filter(({ src }) => src === searchSrc).pop();
|
|
32
|
-
return item && item.img;
|
|
33
|
-
},
|
|
32
|
+
get: searchSrc => imagesBySrc?.get(searchSrc),
|
|
34
33
|
};
|
|
35
34
|
};
|