@micromag/core 0.3.68 → 0.3.69
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/es/components.js +8 -2
- package/es/contexts.js +9 -15
- package/es/hooks.js +13 -7
- package/es/utils.js +20 -12
- package/lib/components.js +8 -2
- package/lib/contexts.js +9 -15
- package/lib/hooks.js +13 -7
- package/lib/utils.js +20 -12
- package/package.json +2 -2
package/es/components.js
CHANGED
|
@@ -3369,6 +3369,7 @@ var VideoLoop = function VideoLoop(_ref) {
|
|
|
3369
3369
|
|
|
3370
3370
|
var styles$8 = {"container":"micromag-core-screens-screen-sizer-container","frame":"micromag-core-screens-screen-sizer-frame","screen":"micromag-core-screens-screen-sizer-screen"};
|
|
3371
3371
|
|
|
3372
|
+
var devicePixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
|
|
3372
3373
|
var propTypes$a = {
|
|
3373
3374
|
width: PropTypes$1.number,
|
|
3374
3375
|
height: PropTypes$1.number,
|
|
@@ -3425,6 +3426,7 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3425
3426
|
return {
|
|
3426
3427
|
width: finalContainerWidth,
|
|
3427
3428
|
height: finalContainerHeight,
|
|
3429
|
+
scale: _screenScale,
|
|
3428
3430
|
transform: "scale(".concat(_screenScale, ")")
|
|
3429
3431
|
};
|
|
3430
3432
|
}
|
|
@@ -3441,6 +3443,7 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3441
3443
|
return {
|
|
3442
3444
|
width: finalContainerWidth,
|
|
3443
3445
|
height: finalContainerHeight,
|
|
3446
|
+
scale: screenScale,
|
|
3444
3447
|
transform: "scale(".concat(screenScale, ") translate(").concat(x, "px, ").concat(y, "px)")
|
|
3445
3448
|
};
|
|
3446
3449
|
}, [screenWidth, screenHeight, width, height, fit, calculatedWidth, calculatedHeight, hasSize]),
|
|
@@ -3448,6 +3451,8 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3448
3451
|
frameWidth = _useMemo$width === void 0 ? null : _useMemo$width,
|
|
3449
3452
|
_useMemo$height = _useMemo.height,
|
|
3450
3453
|
frameHeight = _useMemo$height === void 0 ? null : _useMemo$height,
|
|
3454
|
+
_useMemo$scale = _useMemo.scale,
|
|
3455
|
+
frameScale = _useMemo$scale === void 0 ? null : _useMemo$scale,
|
|
3451
3456
|
_useMemo$transform = _useMemo.transform,
|
|
3452
3457
|
screenTransform = _useMemo$transform === void 0 ? null : _useMemo$transform;
|
|
3453
3458
|
|
|
@@ -3456,9 +3461,10 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3456
3461
|
screen: 'mobile',
|
|
3457
3462
|
screens: ['mobile'],
|
|
3458
3463
|
width: screenWidth,
|
|
3459
|
-
height: screenHeight
|
|
3464
|
+
height: screenHeight,
|
|
3465
|
+
resolution: frameScale !== null ? frameScale * devicePixelRatio : devicePixelRatio
|
|
3460
3466
|
};
|
|
3461
|
-
}, [screenWidth, screenHeight]);
|
|
3467
|
+
}, [screenWidth, screenHeight, frameScale]);
|
|
3462
3468
|
var hasFrameSize = frameWidth !== null && frameHeight !== null;
|
|
3463
3469
|
return /*#__PURE__*/React.createElement("div", {
|
|
3464
3470
|
styles: classNames([styles$8.container, _defineProperty({}, className, className !== null)]),
|
package/es/contexts.js
CHANGED
|
@@ -1029,11 +1029,13 @@ var ScreenProvider = function ScreenProvider(_ref6) {
|
|
|
1029
1029
|
ScreenProvider.propTypes = propTypes$5;
|
|
1030
1030
|
ScreenProvider.defaultProps = defaultProps$5;
|
|
1031
1031
|
|
|
1032
|
+
/* eslint-disable react/jsx-props-no-spreading */
|
|
1032
1033
|
var ScreenSizeContext = /*#__PURE__*/React.createContext({
|
|
1033
1034
|
screen: null,
|
|
1034
1035
|
screens: [],
|
|
1035
1036
|
width: 0,
|
|
1036
1037
|
height: 0,
|
|
1038
|
+
resolution: 1,
|
|
1037
1039
|
landscape: false
|
|
1038
1040
|
});
|
|
1039
1041
|
var useScreenSize = function useScreenSize() {
|
|
@@ -1050,21 +1052,13 @@ var defaultProps$4 = {
|
|
|
1050
1052
|
var ScreenSizeProvider = function ScreenSizeProvider(_ref) {
|
|
1051
1053
|
var size = _ref.size,
|
|
1052
1054
|
children = _ref.children;
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
prevHeight = currentSize.height;
|
|
1061
|
-
var nextWidth = size.width,
|
|
1062
|
-
nextHeight = size.height;
|
|
1063
|
-
useEffect(function () {
|
|
1064
|
-
if (prevWidth !== nextWidth || prevHeight !== nextHeight) {
|
|
1065
|
-
setSize(size);
|
|
1066
|
-
}
|
|
1067
|
-
}, [setSize, nextWidth, nextHeight, prevWidth, prevHeight, size]);
|
|
1055
|
+
var nextScreen = size.screen,
|
|
1056
|
+
nextWidth = size.width,
|
|
1057
|
+
nextHeight = size.height,
|
|
1058
|
+
nextResolution = size.resolution;
|
|
1059
|
+
var currentSize = useMemo(function () {
|
|
1060
|
+
return size;
|
|
1061
|
+
}, [nextScreen, nextWidth, nextHeight, nextResolution]);
|
|
1068
1062
|
return /*#__PURE__*/React.createElement(ScreenSizeContext.Provider, {
|
|
1069
1063
|
value: currentSize
|
|
1070
1064
|
}, children);
|
package/es/hooks.js
CHANGED
|
@@ -1059,6 +1059,7 @@ var useParsedStory = function useParsedStory(story) {
|
|
|
1059
1059
|
};
|
|
1060
1060
|
|
|
1061
1061
|
var _excluded = ["width", "height"];
|
|
1062
|
+
var devicePixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
|
|
1062
1063
|
|
|
1063
1064
|
var useScreenSize = function useScreenSize(_ref) {
|
|
1064
1065
|
var _ref$width = _ref.width,
|
|
@@ -1074,7 +1075,9 @@ var useScreenSize = function useScreenSize(_ref) {
|
|
|
1074
1075
|
_ref$mediaType = _ref.mediaType,
|
|
1075
1076
|
mediaType = _ref$mediaType === void 0 ? 'screen' : _ref$mediaType,
|
|
1076
1077
|
_ref$media = _ref.media,
|
|
1077
|
-
providedMedia = _ref$media === void 0 ? null : _ref$media
|
|
1078
|
+
providedMedia = _ref$media === void 0 ? null : _ref$media,
|
|
1079
|
+
_ref$scale = _ref.scale,
|
|
1080
|
+
scale = _ref$scale === void 0 ? null : _ref$scale;
|
|
1078
1081
|
var screenSize = useMemo(function () {
|
|
1079
1082
|
var media = providedMedia !== null ? providedMedia : {
|
|
1080
1083
|
type: mediaType,
|
|
@@ -1097,7 +1100,8 @@ var useScreenSize = function useScreenSize(_ref) {
|
|
|
1097
1100
|
width: width,
|
|
1098
1101
|
height: height,
|
|
1099
1102
|
landscape: landscape,
|
|
1100
|
-
menuOverScreen: menuOverScreen
|
|
1103
|
+
menuOverScreen: menuOverScreen,
|
|
1104
|
+
resolution: scale !== null ? scale * devicePixelRatio : devicePixelRatio
|
|
1101
1105
|
};
|
|
1102
1106
|
}, [screens, providedMedia, mediaType, width, height, landscape, menuOverScreen]);
|
|
1103
1107
|
return screenSize;
|
|
@@ -1166,17 +1170,19 @@ var useScreenSizeFromElement = function useScreenSizeFromElement() {
|
|
|
1166
1170
|
finalHeight -= 1;
|
|
1167
1171
|
}
|
|
1168
1172
|
|
|
1169
|
-
var scale = finalWidth / screenWidth;
|
|
1173
|
+
var scale = finalWidth > 0 ? finalWidth / screenWidth : null;
|
|
1170
1174
|
var screenSize = useScreenSize(_objectSpread({
|
|
1171
|
-
width: withoutScale ? finalWidth : screenWidth,
|
|
1172
|
-
height: withoutScale ? finalHeight : finalHeight / scale,
|
|
1175
|
+
width: withoutScale || scale === null ? finalWidth : screenWidth,
|
|
1176
|
+
height: withoutScale || scale === null ? finalHeight : finalHeight / scale,
|
|
1173
1177
|
landscape: landscape,
|
|
1174
|
-
menuOverScreen: menuOverScreen
|
|
1178
|
+
menuOverScreen: menuOverScreen,
|
|
1179
|
+
scale: !withoutScale ? scale : null
|
|
1175
1180
|
}, opts));
|
|
1176
1181
|
return {
|
|
1177
1182
|
ref: ref,
|
|
1178
1183
|
screenSize: screenSize,
|
|
1179
|
-
scale: !withoutScale ? scale : null
|
|
1184
|
+
scale: !withoutScale ? scale : null,
|
|
1185
|
+
resolution: !withoutScale ? scale * devicePixelRatio : devicePixelRatio
|
|
1180
1186
|
};
|
|
1181
1187
|
};
|
|
1182
1188
|
|
package/es/utils.js
CHANGED
|
@@ -291,18 +291,23 @@ var getOptimalImageUrl = function getOptimalImageUrl() {
|
|
|
291
291
|
var media = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
292
292
|
var containerWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
293
293
|
var containerHeight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
294
|
-
var maxDiff = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 800;
|
|
295
294
|
|
|
296
|
-
var _ref =
|
|
297
|
-
_ref$
|
|
298
|
-
|
|
299
|
-
_ref$
|
|
300
|
-
|
|
301
|
-
_ref$metadata = _ref.metadata;
|
|
295
|
+
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
296
|
+
_ref$resolution = _ref.resolution,
|
|
297
|
+
resolution = _ref$resolution === void 0 ? 1 : _ref$resolution,
|
|
298
|
+
_ref$maxDiff = _ref.maxDiff,
|
|
299
|
+
maxDiff = _ref$maxDiff === void 0 ? 800 : _ref$maxDiff;
|
|
302
300
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
301
|
+
var _ref2 = media || {},
|
|
302
|
+
_ref2$sizes = _ref2.sizes,
|
|
303
|
+
sizes = _ref2$sizes === void 0 ? null : _ref2$sizes,
|
|
304
|
+
_ref2$url = _ref2.url,
|
|
305
|
+
defaultUrl = _ref2$url === void 0 ? null : _ref2$url,
|
|
306
|
+
_ref2$metadata = _ref2.metadata;
|
|
307
|
+
|
|
308
|
+
_ref2$metadata = _ref2$metadata === void 0 ? {} : _ref2$metadata;
|
|
309
|
+
var imgWidth = _ref2$metadata.width,
|
|
310
|
+
imgHeight = _ref2$metadata.height;
|
|
306
311
|
|
|
307
312
|
if (sizes === null || containerWidth === null && containerHeight === null) {
|
|
308
313
|
return defaultUrl;
|
|
@@ -316,6 +321,9 @@ var getOptimalImageUrl = function getOptimalImageUrl() {
|
|
|
316
321
|
}
|
|
317
322
|
}, sizes);
|
|
318
323
|
|
|
324
|
+
var finalContainerWidth = containerWidth !== null && resolution !== null ? containerWidth * resolution : containerWidth;
|
|
325
|
+
var finalContainerHeight = containerHeight !== null && resolution !== null ? containerHeight * resolution : containerHeight;
|
|
326
|
+
|
|
319
327
|
var _Object$keys$reduce = Object.keys(finalSizes).reduce(function (acc, key) {
|
|
320
328
|
var currentDiff = acc.diff,
|
|
321
329
|
currentIsLarger = acc.isLarger,
|
|
@@ -326,8 +334,8 @@ var getOptimalImageUrl = function getOptimalImageUrl() {
|
|
|
326
334
|
width = _finalSizes$key$width === void 0 ? null : _finalSizes$key$width,
|
|
327
335
|
_finalSizes$key$heigh = _finalSizes$key.height,
|
|
328
336
|
height = _finalSizes$key$heigh === void 0 ? null : _finalSizes$key$heigh;
|
|
329
|
-
var diffWidth = width !== null &&
|
|
330
|
-
var diffHeight = height !== null &&
|
|
337
|
+
var diffWidth = width !== null && finalContainerWidth !== null ? width - finalContainerWidth : null;
|
|
338
|
+
var diffHeight = height !== null && finalContainerHeight !== null ? height - finalContainerHeight : null;
|
|
331
339
|
var isLarger = (diffWidth === null || diffWidth >= 0) && (diffHeight === null || diffHeight >= 0);
|
|
332
340
|
var diff = [diffWidth, diffHeight].reduce(function (total, value) {
|
|
333
341
|
return value !== null ? (total || 0) + Math.abs(value) : total;
|
package/lib/components.js
CHANGED
|
@@ -3392,6 +3392,7 @@ var VideoLoop = function VideoLoop(_ref) {
|
|
|
3392
3392
|
|
|
3393
3393
|
var styles$8 = {"container":"micromag-core-screens-screen-sizer-container","frame":"micromag-core-screens-screen-sizer-frame","screen":"micromag-core-screens-screen-sizer-screen"};
|
|
3394
3394
|
|
|
3395
|
+
var devicePixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
|
|
3395
3396
|
var propTypes$a = {
|
|
3396
3397
|
width: PropTypes__default["default"].number,
|
|
3397
3398
|
height: PropTypes__default["default"].number,
|
|
@@ -3448,6 +3449,7 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3448
3449
|
return {
|
|
3449
3450
|
width: finalContainerWidth,
|
|
3450
3451
|
height: finalContainerHeight,
|
|
3452
|
+
scale: _screenScale,
|
|
3451
3453
|
transform: "scale(".concat(_screenScale, ")")
|
|
3452
3454
|
};
|
|
3453
3455
|
}
|
|
@@ -3464,6 +3466,7 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3464
3466
|
return {
|
|
3465
3467
|
width: finalContainerWidth,
|
|
3466
3468
|
height: finalContainerHeight,
|
|
3469
|
+
scale: screenScale,
|
|
3467
3470
|
transform: "scale(".concat(screenScale, ") translate(").concat(x, "px, ").concat(y, "px)")
|
|
3468
3471
|
};
|
|
3469
3472
|
}, [screenWidth, screenHeight, width, height, fit, calculatedWidth, calculatedHeight, hasSize]),
|
|
@@ -3471,6 +3474,8 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3471
3474
|
frameWidth = _useMemo$width === void 0 ? null : _useMemo$width,
|
|
3472
3475
|
_useMemo$height = _useMemo.height,
|
|
3473
3476
|
frameHeight = _useMemo$height === void 0 ? null : _useMemo$height,
|
|
3477
|
+
_useMemo$scale = _useMemo.scale,
|
|
3478
|
+
frameScale = _useMemo$scale === void 0 ? null : _useMemo$scale,
|
|
3474
3479
|
_useMemo$transform = _useMemo.transform,
|
|
3475
3480
|
screenTransform = _useMemo$transform === void 0 ? null : _useMemo$transform;
|
|
3476
3481
|
|
|
@@ -3479,9 +3484,10 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3479
3484
|
screen: 'mobile',
|
|
3480
3485
|
screens: ['mobile'],
|
|
3481
3486
|
width: screenWidth,
|
|
3482
|
-
height: screenHeight
|
|
3487
|
+
height: screenHeight,
|
|
3488
|
+
resolution: frameScale !== null ? frameScale * devicePixelRatio : devicePixelRatio
|
|
3483
3489
|
};
|
|
3484
|
-
}, [screenWidth, screenHeight]);
|
|
3490
|
+
}, [screenWidth, screenHeight, frameScale]);
|
|
3485
3491
|
var hasFrameSize = frameWidth !== null && frameHeight !== null;
|
|
3486
3492
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3487
3493
|
styles: classNames__default["default"]([styles$8.container, _defineProperty__default["default"]({}, className, className !== null)]),
|
package/lib/contexts.js
CHANGED
|
@@ -1064,11 +1064,13 @@ var ScreenProvider = function ScreenProvider(_ref6) {
|
|
|
1064
1064
|
ScreenProvider.propTypes = propTypes$5;
|
|
1065
1065
|
ScreenProvider.defaultProps = defaultProps$5;
|
|
1066
1066
|
|
|
1067
|
+
/* eslint-disable react/jsx-props-no-spreading */
|
|
1067
1068
|
var ScreenSizeContext = /*#__PURE__*/React__default["default"].createContext({
|
|
1068
1069
|
screen: null,
|
|
1069
1070
|
screens: [],
|
|
1070
1071
|
width: 0,
|
|
1071
1072
|
height: 0,
|
|
1073
|
+
resolution: 1,
|
|
1072
1074
|
landscape: false
|
|
1073
1075
|
});
|
|
1074
1076
|
var useScreenSize = function useScreenSize() {
|
|
@@ -1085,21 +1087,13 @@ var defaultProps$4 = {
|
|
|
1085
1087
|
var ScreenSizeProvider = function ScreenSizeProvider(_ref) {
|
|
1086
1088
|
var size = _ref.size,
|
|
1087
1089
|
children = _ref.children;
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
prevHeight = currentSize.height;
|
|
1096
|
-
var nextWidth = size.width,
|
|
1097
|
-
nextHeight = size.height;
|
|
1098
|
-
React.useEffect(function () {
|
|
1099
|
-
if (prevWidth !== nextWidth || prevHeight !== nextHeight) {
|
|
1100
|
-
setSize(size);
|
|
1101
|
-
}
|
|
1102
|
-
}, [setSize, nextWidth, nextHeight, prevWidth, prevHeight, size]);
|
|
1090
|
+
var nextScreen = size.screen,
|
|
1091
|
+
nextWidth = size.width,
|
|
1092
|
+
nextHeight = size.height,
|
|
1093
|
+
nextResolution = size.resolution;
|
|
1094
|
+
var currentSize = React.useMemo(function () {
|
|
1095
|
+
return size;
|
|
1096
|
+
}, [nextScreen, nextWidth, nextHeight, nextResolution]);
|
|
1103
1097
|
return /*#__PURE__*/React__default["default"].createElement(ScreenSizeContext.Provider, {
|
|
1104
1098
|
value: currentSize
|
|
1105
1099
|
}, children);
|
package/lib/hooks.js
CHANGED
|
@@ -1095,6 +1095,7 @@ var useParsedStory = function useParsedStory(story) {
|
|
|
1095
1095
|
};
|
|
1096
1096
|
|
|
1097
1097
|
var _excluded = ["width", "height"];
|
|
1098
|
+
var devicePixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
|
|
1098
1099
|
|
|
1099
1100
|
var useScreenSize = function useScreenSize(_ref) {
|
|
1100
1101
|
var _ref$width = _ref.width,
|
|
@@ -1110,7 +1111,9 @@ var useScreenSize = function useScreenSize(_ref) {
|
|
|
1110
1111
|
_ref$mediaType = _ref.mediaType,
|
|
1111
1112
|
mediaType = _ref$mediaType === void 0 ? 'screen' : _ref$mediaType,
|
|
1112
1113
|
_ref$media = _ref.media,
|
|
1113
|
-
providedMedia = _ref$media === void 0 ? null : _ref$media
|
|
1114
|
+
providedMedia = _ref$media === void 0 ? null : _ref$media,
|
|
1115
|
+
_ref$scale = _ref.scale,
|
|
1116
|
+
scale = _ref$scale === void 0 ? null : _ref$scale;
|
|
1114
1117
|
var screenSize = react.useMemo(function () {
|
|
1115
1118
|
var media = providedMedia !== null ? providedMedia : {
|
|
1116
1119
|
type: mediaType,
|
|
@@ -1133,7 +1136,8 @@ var useScreenSize = function useScreenSize(_ref) {
|
|
|
1133
1136
|
width: width,
|
|
1134
1137
|
height: height,
|
|
1135
1138
|
landscape: landscape,
|
|
1136
|
-
menuOverScreen: menuOverScreen
|
|
1139
|
+
menuOverScreen: menuOverScreen,
|
|
1140
|
+
resolution: scale !== null ? scale * devicePixelRatio : devicePixelRatio
|
|
1137
1141
|
};
|
|
1138
1142
|
}, [screens, providedMedia, mediaType, width, height, landscape, menuOverScreen]);
|
|
1139
1143
|
return screenSize;
|
|
@@ -1202,17 +1206,19 @@ var useScreenSizeFromElement = function useScreenSizeFromElement() {
|
|
|
1202
1206
|
finalHeight -= 1;
|
|
1203
1207
|
}
|
|
1204
1208
|
|
|
1205
|
-
var scale = finalWidth / screenWidth;
|
|
1209
|
+
var scale = finalWidth > 0 ? finalWidth / screenWidth : null;
|
|
1206
1210
|
var screenSize = useScreenSize(_objectSpread__default["default"]({
|
|
1207
|
-
width: withoutScale ? finalWidth : screenWidth,
|
|
1208
|
-
height: withoutScale ? finalHeight : finalHeight / scale,
|
|
1211
|
+
width: withoutScale || scale === null ? finalWidth : screenWidth,
|
|
1212
|
+
height: withoutScale || scale === null ? finalHeight : finalHeight / scale,
|
|
1209
1213
|
landscape: landscape,
|
|
1210
|
-
menuOverScreen: menuOverScreen
|
|
1214
|
+
menuOverScreen: menuOverScreen,
|
|
1215
|
+
scale: !withoutScale ? scale : null
|
|
1211
1216
|
}, opts));
|
|
1212
1217
|
return {
|
|
1213
1218
|
ref: ref,
|
|
1214
1219
|
screenSize: screenSize,
|
|
1215
|
-
scale: !withoutScale ? scale : null
|
|
1220
|
+
scale: !withoutScale ? scale : null,
|
|
1221
|
+
resolution: !withoutScale ? scale * devicePixelRatio : devicePixelRatio
|
|
1216
1222
|
};
|
|
1217
1223
|
};
|
|
1218
1224
|
|
package/lib/utils.js
CHANGED
|
@@ -308,18 +308,23 @@ var getOptimalImageUrl = function getOptimalImageUrl() {
|
|
|
308
308
|
var media = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
309
309
|
var containerWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
310
310
|
var containerHeight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
311
|
-
var maxDiff = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 800;
|
|
312
311
|
|
|
313
|
-
var _ref =
|
|
314
|
-
_ref$
|
|
315
|
-
|
|
316
|
-
_ref$
|
|
317
|
-
|
|
318
|
-
_ref$metadata = _ref.metadata;
|
|
312
|
+
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
313
|
+
_ref$resolution = _ref.resolution,
|
|
314
|
+
resolution = _ref$resolution === void 0 ? 1 : _ref$resolution,
|
|
315
|
+
_ref$maxDiff = _ref.maxDiff,
|
|
316
|
+
maxDiff = _ref$maxDiff === void 0 ? 800 : _ref$maxDiff;
|
|
319
317
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
318
|
+
var _ref2 = media || {},
|
|
319
|
+
_ref2$sizes = _ref2.sizes,
|
|
320
|
+
sizes = _ref2$sizes === void 0 ? null : _ref2$sizes,
|
|
321
|
+
_ref2$url = _ref2.url,
|
|
322
|
+
defaultUrl = _ref2$url === void 0 ? null : _ref2$url,
|
|
323
|
+
_ref2$metadata = _ref2.metadata;
|
|
324
|
+
|
|
325
|
+
_ref2$metadata = _ref2$metadata === void 0 ? {} : _ref2$metadata;
|
|
326
|
+
var imgWidth = _ref2$metadata.width,
|
|
327
|
+
imgHeight = _ref2$metadata.height;
|
|
323
328
|
|
|
324
329
|
if (sizes === null || containerWidth === null && containerHeight === null) {
|
|
325
330
|
return defaultUrl;
|
|
@@ -333,6 +338,9 @@ var getOptimalImageUrl = function getOptimalImageUrl() {
|
|
|
333
338
|
}
|
|
334
339
|
}, sizes);
|
|
335
340
|
|
|
341
|
+
var finalContainerWidth = containerWidth !== null && resolution !== null ? containerWidth * resolution : containerWidth;
|
|
342
|
+
var finalContainerHeight = containerHeight !== null && resolution !== null ? containerHeight * resolution : containerHeight;
|
|
343
|
+
|
|
336
344
|
var _Object$keys$reduce = Object.keys(finalSizes).reduce(function (acc, key) {
|
|
337
345
|
var currentDiff = acc.diff,
|
|
338
346
|
currentIsLarger = acc.isLarger,
|
|
@@ -343,8 +351,8 @@ var getOptimalImageUrl = function getOptimalImageUrl() {
|
|
|
343
351
|
width = _finalSizes$key$width === void 0 ? null : _finalSizes$key$width,
|
|
344
352
|
_finalSizes$key$heigh = _finalSizes$key.height,
|
|
345
353
|
height = _finalSizes$key$heigh === void 0 ? null : _finalSizes$key$heigh;
|
|
346
|
-
var diffWidth = width !== null &&
|
|
347
|
-
var diffHeight = height !== null &&
|
|
354
|
+
var diffWidth = width !== null && finalContainerWidth !== null ? width - finalContainerWidth : null;
|
|
355
|
+
var diffHeight = height !== null && finalContainerHeight !== null ? height - finalContainerHeight : null;
|
|
348
356
|
var isLarger = (diffWidth === null || diffWidth >= 0) && (diffHeight === null || diffHeight >= 0);
|
|
349
357
|
var diff = [diffWidth, diffHeight].reduce(function (total, value) {
|
|
350
358
|
return value !== null ? (total || 0) + Math.abs(value) : total;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.69",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -132,5 +132,5 @@
|
|
|
132
132
|
"publishConfig": {
|
|
133
133
|
"access": "public"
|
|
134
134
|
},
|
|
135
|
-
"gitHead": "
|
|
135
|
+
"gitHead": "c69c85dbe321ddcd2d57f5d972b456ab76b5da3e"
|
|
136
136
|
}
|