@micromag/core 0.3.67 → 0.3.71
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 +11 -3
- package/es/contexts.js +14 -18
- package/es/hooks.js +13 -7
- package/es/utils.js +20 -12
- package/lib/components.js +11 -3
- package/lib/contexts.js +14 -18
- package/lib/hooks.js +13 -7
- package/lib/utils.js +20 -12
- package/package.json +2 -2
package/es/components.js
CHANGED
|
@@ -566,7 +566,9 @@ var Form = function Form(_ref) {
|
|
|
566
566
|
}
|
|
567
567
|
}, [fieldPaths, setFieldPaths]);
|
|
568
568
|
var closeFieldForm = useCallback(function () {
|
|
569
|
-
var newFields = fieldPaths
|
|
569
|
+
var newFields = _toConsumableArray(fieldPaths);
|
|
570
|
+
|
|
571
|
+
newFields.pop();
|
|
570
572
|
setFieldPaths(_toConsumableArray(newFields));
|
|
571
573
|
|
|
572
574
|
if (onCloseFieldForm !== null) {
|
|
@@ -3367,6 +3369,7 @@ var VideoLoop = function VideoLoop(_ref) {
|
|
|
3367
3369
|
|
|
3368
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"};
|
|
3369
3371
|
|
|
3372
|
+
var devicePixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
|
|
3370
3373
|
var propTypes$a = {
|
|
3371
3374
|
width: PropTypes$1.number,
|
|
3372
3375
|
height: PropTypes$1.number,
|
|
@@ -3423,6 +3426,7 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3423
3426
|
return {
|
|
3424
3427
|
width: finalContainerWidth,
|
|
3425
3428
|
height: finalContainerHeight,
|
|
3429
|
+
scale: _screenScale,
|
|
3426
3430
|
transform: "scale(".concat(_screenScale, ")")
|
|
3427
3431
|
};
|
|
3428
3432
|
}
|
|
@@ -3439,6 +3443,7 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3439
3443
|
return {
|
|
3440
3444
|
width: finalContainerWidth,
|
|
3441
3445
|
height: finalContainerHeight,
|
|
3446
|
+
scale: screenScale,
|
|
3442
3447
|
transform: "scale(".concat(screenScale, ") translate(").concat(x, "px, ").concat(y, "px)")
|
|
3443
3448
|
};
|
|
3444
3449
|
}, [screenWidth, screenHeight, width, height, fit, calculatedWidth, calculatedHeight, hasSize]),
|
|
@@ -3446,6 +3451,8 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3446
3451
|
frameWidth = _useMemo$width === void 0 ? null : _useMemo$width,
|
|
3447
3452
|
_useMemo$height = _useMemo.height,
|
|
3448
3453
|
frameHeight = _useMemo$height === void 0 ? null : _useMemo$height,
|
|
3454
|
+
_useMemo$scale = _useMemo.scale,
|
|
3455
|
+
frameScale = _useMemo$scale === void 0 ? null : _useMemo$scale,
|
|
3449
3456
|
_useMemo$transform = _useMemo.transform,
|
|
3450
3457
|
screenTransform = _useMemo$transform === void 0 ? null : _useMemo$transform;
|
|
3451
3458
|
|
|
@@ -3454,9 +3461,10 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3454
3461
|
screen: 'mobile',
|
|
3455
3462
|
screens: ['mobile'],
|
|
3456
3463
|
width: screenWidth,
|
|
3457
|
-
height: screenHeight
|
|
3464
|
+
height: screenHeight,
|
|
3465
|
+
resolution: frameScale !== null ? frameScale * devicePixelRatio : devicePixelRatio
|
|
3458
3466
|
};
|
|
3459
|
-
}, [screenWidth, screenHeight]);
|
|
3467
|
+
}, [screenWidth, screenHeight, frameScale]);
|
|
3460
3468
|
var hasFrameSize = frameWidth !== null && frameHeight !== null;
|
|
3461
3469
|
return /*#__PURE__*/React.createElement("div", {
|
|
3462
3470
|
styles: classNames([styles$8.container, _defineProperty({}, className, className !== null)]),
|
package/es/contexts.js
CHANGED
|
@@ -928,13 +928,15 @@ var useScreenDefinition = function useScreenDefinition() {
|
|
|
928
928
|
var intl = useIntl();
|
|
929
929
|
|
|
930
930
|
var _ref = useScreen() || {},
|
|
931
|
-
definition = _ref.definition
|
|
931
|
+
_ref$definition = _ref.definition,
|
|
932
|
+
definition = _ref$definition === void 0 ? null : _ref$definition;
|
|
932
933
|
|
|
933
934
|
var _ref2 = definition || {},
|
|
934
|
-
fields = _ref2.fields
|
|
935
|
+
_ref2$fields = _ref2.fields,
|
|
936
|
+
fields = _ref2$fields === void 0 ? null : _ref2$fields;
|
|
935
937
|
|
|
936
938
|
var finalFields = useMemo(function () {
|
|
937
|
-
return [].concat(_toConsumableArray(fields), [getScreenExtraField(intl)]);
|
|
939
|
+
return fields !== null ? [].concat(_toConsumableArray(fields), [getScreenExtraField(intl)]) : null;
|
|
938
940
|
}, [fields]);
|
|
939
941
|
return _objectSpread(_objectSpread({}, definition), {}, {
|
|
940
942
|
fields: finalFields
|
|
@@ -1029,11 +1031,13 @@ var ScreenProvider = function ScreenProvider(_ref6) {
|
|
|
1029
1031
|
ScreenProvider.propTypes = propTypes$5;
|
|
1030
1032
|
ScreenProvider.defaultProps = defaultProps$5;
|
|
1031
1033
|
|
|
1034
|
+
/* eslint-disable react/jsx-props-no-spreading */
|
|
1032
1035
|
var ScreenSizeContext = /*#__PURE__*/React.createContext({
|
|
1033
1036
|
screen: null,
|
|
1034
1037
|
screens: [],
|
|
1035
1038
|
width: 0,
|
|
1036
1039
|
height: 0,
|
|
1040
|
+
resolution: 1,
|
|
1037
1041
|
landscape: false
|
|
1038
1042
|
});
|
|
1039
1043
|
var useScreenSize = function useScreenSize() {
|
|
@@ -1050,21 +1054,13 @@ var defaultProps$4 = {
|
|
|
1050
1054
|
var ScreenSizeProvider = function ScreenSizeProvider(_ref) {
|
|
1051
1055
|
var size = _ref.size,
|
|
1052
1056
|
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]);
|
|
1057
|
+
var nextScreen = size.screen,
|
|
1058
|
+
nextWidth = size.width,
|
|
1059
|
+
nextHeight = size.height,
|
|
1060
|
+
nextResolution = size.resolution;
|
|
1061
|
+
var currentSize = useMemo(function () {
|
|
1062
|
+
return size;
|
|
1063
|
+
}, [nextScreen, nextWidth, nextHeight, nextResolution]);
|
|
1068
1064
|
return /*#__PURE__*/React.createElement(ScreenSizeContext.Provider, {
|
|
1069
1065
|
value: currentSize
|
|
1070
1066
|
}, 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
|
@@ -589,7 +589,9 @@ var Form = function Form(_ref) {
|
|
|
589
589
|
}
|
|
590
590
|
}, [fieldPaths, setFieldPaths]);
|
|
591
591
|
var closeFieldForm = React.useCallback(function () {
|
|
592
|
-
var newFields = fieldPaths
|
|
592
|
+
var newFields = _toConsumableArray__default["default"](fieldPaths);
|
|
593
|
+
|
|
594
|
+
newFields.pop();
|
|
593
595
|
setFieldPaths(_toConsumableArray__default["default"](newFields));
|
|
594
596
|
|
|
595
597
|
if (onCloseFieldForm !== null) {
|
|
@@ -3390,6 +3392,7 @@ var VideoLoop = function VideoLoop(_ref) {
|
|
|
3390
3392
|
|
|
3391
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"};
|
|
3392
3394
|
|
|
3395
|
+
var devicePixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
|
|
3393
3396
|
var propTypes$a = {
|
|
3394
3397
|
width: PropTypes__default["default"].number,
|
|
3395
3398
|
height: PropTypes__default["default"].number,
|
|
@@ -3446,6 +3449,7 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3446
3449
|
return {
|
|
3447
3450
|
width: finalContainerWidth,
|
|
3448
3451
|
height: finalContainerHeight,
|
|
3452
|
+
scale: _screenScale,
|
|
3449
3453
|
transform: "scale(".concat(_screenScale, ")")
|
|
3450
3454
|
};
|
|
3451
3455
|
}
|
|
@@ -3462,6 +3466,7 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3462
3466
|
return {
|
|
3463
3467
|
width: finalContainerWidth,
|
|
3464
3468
|
height: finalContainerHeight,
|
|
3469
|
+
scale: screenScale,
|
|
3465
3470
|
transform: "scale(".concat(screenScale, ") translate(").concat(x, "px, ").concat(y, "px)")
|
|
3466
3471
|
};
|
|
3467
3472
|
}, [screenWidth, screenHeight, width, height, fit, calculatedWidth, calculatedHeight, hasSize]),
|
|
@@ -3469,6 +3474,8 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3469
3474
|
frameWidth = _useMemo$width === void 0 ? null : _useMemo$width,
|
|
3470
3475
|
_useMemo$height = _useMemo.height,
|
|
3471
3476
|
frameHeight = _useMemo$height === void 0 ? null : _useMemo$height,
|
|
3477
|
+
_useMemo$scale = _useMemo.scale,
|
|
3478
|
+
frameScale = _useMemo$scale === void 0 ? null : _useMemo$scale,
|
|
3472
3479
|
_useMemo$transform = _useMemo.transform,
|
|
3473
3480
|
screenTransform = _useMemo$transform === void 0 ? null : _useMemo$transform;
|
|
3474
3481
|
|
|
@@ -3477,9 +3484,10 @@ var ScreenSizer = function ScreenSizer(_ref) {
|
|
|
3477
3484
|
screen: 'mobile',
|
|
3478
3485
|
screens: ['mobile'],
|
|
3479
3486
|
width: screenWidth,
|
|
3480
|
-
height: screenHeight
|
|
3487
|
+
height: screenHeight,
|
|
3488
|
+
resolution: frameScale !== null ? frameScale * devicePixelRatio : devicePixelRatio
|
|
3481
3489
|
};
|
|
3482
|
-
}, [screenWidth, screenHeight]);
|
|
3490
|
+
}, [screenWidth, screenHeight, frameScale]);
|
|
3483
3491
|
var hasFrameSize = frameWidth !== null && frameHeight !== null;
|
|
3484
3492
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3485
3493
|
styles: classNames__default["default"]([styles$8.container, _defineProperty__default["default"]({}, className, className !== null)]),
|
package/lib/contexts.js
CHANGED
|
@@ -963,13 +963,15 @@ var useScreenDefinition = function useScreenDefinition() {
|
|
|
963
963
|
var intl = reactIntl.useIntl();
|
|
964
964
|
|
|
965
965
|
var _ref = useScreen() || {},
|
|
966
|
-
definition = _ref.definition
|
|
966
|
+
_ref$definition = _ref.definition,
|
|
967
|
+
definition = _ref$definition === void 0 ? null : _ref$definition;
|
|
967
968
|
|
|
968
969
|
var _ref2 = definition || {},
|
|
969
|
-
fields = _ref2.fields
|
|
970
|
+
_ref2$fields = _ref2.fields,
|
|
971
|
+
fields = _ref2$fields === void 0 ? null : _ref2$fields;
|
|
970
972
|
|
|
971
973
|
var finalFields = React.useMemo(function () {
|
|
972
|
-
return [].concat(_toConsumableArray__default["default"](fields), [utils.getScreenExtraField(intl)]);
|
|
974
|
+
return fields !== null ? [].concat(_toConsumableArray__default["default"](fields), [utils.getScreenExtraField(intl)]) : null;
|
|
973
975
|
}, [fields]);
|
|
974
976
|
return _objectSpread__default["default"](_objectSpread__default["default"]({}, definition), {}, {
|
|
975
977
|
fields: finalFields
|
|
@@ -1064,11 +1066,13 @@ var ScreenProvider = function ScreenProvider(_ref6) {
|
|
|
1064
1066
|
ScreenProvider.propTypes = propTypes$5;
|
|
1065
1067
|
ScreenProvider.defaultProps = defaultProps$5;
|
|
1066
1068
|
|
|
1069
|
+
/* eslint-disable react/jsx-props-no-spreading */
|
|
1067
1070
|
var ScreenSizeContext = /*#__PURE__*/React__default["default"].createContext({
|
|
1068
1071
|
screen: null,
|
|
1069
1072
|
screens: [],
|
|
1070
1073
|
width: 0,
|
|
1071
1074
|
height: 0,
|
|
1075
|
+
resolution: 1,
|
|
1072
1076
|
landscape: false
|
|
1073
1077
|
});
|
|
1074
1078
|
var useScreenSize = function useScreenSize() {
|
|
@@ -1085,21 +1089,13 @@ var defaultProps$4 = {
|
|
|
1085
1089
|
var ScreenSizeProvider = function ScreenSizeProvider(_ref) {
|
|
1086
1090
|
var size = _ref.size,
|
|
1087
1091
|
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]);
|
|
1092
|
+
var nextScreen = size.screen,
|
|
1093
|
+
nextWidth = size.width,
|
|
1094
|
+
nextHeight = size.height,
|
|
1095
|
+
nextResolution = size.resolution;
|
|
1096
|
+
var currentSize = React.useMemo(function () {
|
|
1097
|
+
return size;
|
|
1098
|
+
}, [nextScreen, nextWidth, nextHeight, nextResolution]);
|
|
1103
1099
|
return /*#__PURE__*/React__default["default"].createElement(ScreenSizeContext.Provider, {
|
|
1104
1100
|
value: currentSize
|
|
1105
1101
|
}, 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.71",
|
|
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": "50093d0adc731dfb58656015179c4ac0b1c6765f"
|
|
136
136
|
}
|