@enact/ui 4.5.2 → 4.5.3
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/AnnounceDecorator/Announce.js +1 -40
- package/AnnounceDecorator/AnnounceDecorator.js +3 -21
- package/AnnounceDecorator/tests/Announce-specs.js +2 -7
- package/AnnounceDecorator/tests/AnnounceDecorator-specs.js +2 -6
- package/AnnounceDecorator/tests/useAnnounce-specs.js +8 -19
- package/AnnounceDecorator/useAnnounce.js +0 -6
- package/BodyText/BodyText.js +6 -26
- package/BodyText/tests/BodyText-specs.js +0 -19
- package/Button/Button.js +26 -56
- package/Button/tests/Button-specs.js +0 -26
- package/CHANGELOG.md +4 -0
- package/Cancelable/Cancelable.js +8 -47
- package/Cancelable/cancelHandler.js +5 -12
- package/Cancelable/modalHandler.js +3 -11
- package/Cancelable/tests/Cancelable-specs.js +3 -57
- package/Changeable/Changeable.js +2 -34
- package/Changeable/tests/Changeable-specs.js +20 -66
- package/ComponentOverride/ComponentOverride.js +1 -13
- package/FloatingLayer/FloatingLayer.js +17 -73
- package/FloatingLayer/FloatingLayerContainer.js +0 -15
- package/FloatingLayer/FloatingLayerDecorator.js +4 -17
- package/FloatingLayer/Scrim.js +9 -53
- package/FloatingLayer/index.js +0 -4
- package/FloatingLayer/tests/FloatingLayer-specs.js +8 -22
- package/FloatingLayer/tests/Scrim-specs.js +0 -9
- package/FloatingLayer/tests/useFloatingLayerDecorator-specs.js +0 -13
- package/FloatingLayer/useFloatingLayer.js +3 -14
- package/FloatingLayer/useFloatingLayerDecorator.js +3 -11
- package/ForwardRef/ForwardRef.js +1 -10
- package/GridListImageItem/GridListImageItem.js +17 -50
- package/Group/Group.js +4 -35
- package/Group/GroupItem.js +15 -32
- package/Group/tests/Group-specs.js +0 -32
- package/Heading/Heading.js +7 -35
- package/Heading/tests/Heading-specs.js +81 -14
- package/Icon/Icon.js +14 -48
- package/Icon/tests/Icon-specs.js +0 -22
- package/IconButton/IconButton.js +12 -50
- package/IconButton/tests/IconButton-specs.js +0 -7
- package/Image/Image.js +16 -45
- package/Image/tests/Image-specs.js +0 -14
- package/ImageItem/ImageItem.js +17 -46
- package/ImageItem/tests/ImageItem-specs.js +0 -25
- package/Item/Item.js +8 -32
- package/Item/tests/Item-specs.js +0 -24
- package/LabeledIcon/LabeledIcon.js +19 -50
- package/LabeledIcon/tests/LabeledIcon-specs.js +0 -14
- package/Layout/Cell.js +11 -37
- package/Layout/Layout.js +14 -37
- package/Layout/tests/Layout-specs.js +10 -39
- package/Marquee/MarqueeBase.js +29 -63
- package/Marquee/MarqueeController.js +11 -72
- package/Marquee/MarqueeDecorator.js +62 -196
- package/Marquee/index.js +1 -5
- package/Marquee/tests/Marquee-specs.js +258 -87
- package/Measurable/Measurable.js +12 -34
- package/Measurable/tests/Measurable-specs.js +115 -0
- package/Media/Media.js +15 -65
- package/Media/tests/Media-specs.js +168 -0
- package/Placeholder/PlaceholderControllerDecorator.js +7 -43
- package/Placeholder/PlaceholderDecorator.js +7 -38
- package/Placeholder/index.js +0 -4
- package/Placeholder/tests/PlaceholderControllerDecorator-specs.js +25 -0
- package/Placeholder/tests/PlaceholderDecorator-specs.js +28 -0
- package/ProgressBar/ProgressBar.js +13 -44
- package/ProgressBar/tests/ProgressBar-specs.js +0 -17
- package/RadioDecorator/RadioControllerDecorator.js +1 -29
- package/RadioDecorator/RadioDecorator.js +4 -42
- package/RadioDecorator/tests/RadioDecorator-specs.js +12 -49
- package/Repeater/Repeater.js +9 -33
- package/Repeater/tests/Repeater-specs.js +0 -38
- package/Resizable/Resizable.js +7 -35
- package/Resizable/tests/Resizable-specs.js +34 -0
- package/Routable/Link.js +8 -44
- package/Routable/Routable.js +10 -33
- package/Routable/Route.js +0 -6
- package/Routable/Router.js +13 -56
- package/Routable/tests/Routable-specs.js +7 -33
- package/Routable/tests/Router-specs.js +18 -44
- package/Routable/useLink.js +4 -8
- package/Routable/util.js +18 -24
- package/Scrollable/ScrollAnimator.js +49 -65
- package/Scrollable/ScrollThumb.js +2 -13
- package/Scrollable/Scrollable.js +179 -386
- package/Scrollable/ScrollableNative.js +188 -391
- package/Scrollable/Scrollbar.js +28 -100
- package/Scroller/Scroller.js +15 -39
- package/Scroller/ScrollerBasic.js +34 -89
- package/Scroller/UiScrollerBase.js +31 -84
- package/Skinnable/Skinnable.js +11 -38
- package/Skinnable/tests/Skinnable-specs.js +3 -74
- package/Skinnable/tests/useSkins-specs.js +1 -13
- package/Skinnable/tests/util-specs.js +0 -14
- package/Skinnable/useSkins.js +8 -15
- package/Skinnable/util.js +9 -20
- package/Slider/Knob.js +5 -24
- package/Slider/PositionDecorator.js +16 -54
- package/Slider/Slider.js +26 -64
- package/Slider/tests/Slider-specs.js +94 -7
- package/Slider/utils.js +0 -2
- package/SlotItem/SlotItem.js +15 -41
- package/SlotItem/tests/SlotItem-specs.js +0 -5
- package/Slottable/Slottable.js +4 -12
- package/Slottable/tests/Slottable-specs.js +19 -46
- package/Slottable/tests/useSlots-specs.js +27 -65
- package/Slottable/useSlots.js +8 -33
- package/Spinner/Spinner.js +15 -42
- package/Spinner/tests/Spinner-specs.js +0 -15
- package/ToggleIcon/ToggleIcon.js +10 -36
- package/ToggleIcon/tests/ToggleIcon-specs.js +0 -16
- package/ToggleItem/ToggleItem.js +15 -52
- package/ToggleItem/tests/ToggleItem-specs.js +0 -30
- package/Toggleable/Toggle.js +1 -15
- package/Toggleable/Toggleable.js +12 -45
- package/Toggleable/tests/Toggleable-specs.js +28 -96
- package/Toggleable/useToggle.js +3 -19
- package/Touchable/ClickAllow.js +5 -14
- package/Touchable/Drag.js +16 -54
- package/Touchable/Flick.js +11 -42
- package/Touchable/Hold.js +21 -68
- package/Touchable/Touch.js +37 -65
- package/Touchable/Touchable.js +32 -71
- package/Touchable/config.js +8 -22
- package/Touchable/tests/Touchable-specs.js +270 -119
- package/Touchable/tests/useTouch-specs.js +6 -80
- package/Touchable/useTouch.js +17 -34
- package/Transition/Transition.js +37 -118
- package/Transition/tests/Transition-specs.js +20 -60
- package/ViewManager/Arranger.js +10 -22
- package/ViewManager/TransitionGroup.js +31 -106
- package/ViewManager/View.js +35 -91
- package/ViewManager/ViewManager.js +19 -83
- package/ViewManager/tests/View-specs.js +0 -17
- package/ViewManager/tests/ViewManager-specs.js +236 -305
- package/ViewManager/tests/test-utils.js +0 -8
- package/VirtualList/UiVirtualListBase.js +256 -406
- package/VirtualList/VirtualList.js +29 -69
- package/VirtualList/VirtualListBase.js +0 -3
- package/VirtualList/VirtualListBasic.js +270 -428
- package/VirtualList/tests/VirtualList-specs.js +9 -37
- package/internal/IdProvider/IdProvider.js +7 -21
- package/internal/IdProvider/Provider.js +4 -17
- package/internal/IdProvider/tests/IdProvider-specs.js +44 -0
- package/internal/IdProvider/tests/useId-specs.js +7 -22
- package/internal/IdProvider/useId.js +0 -6
- package/internal/Pure/Pure.js +3 -30
- package/internal/Pure/tests/Pure-specs.js +88 -0
- package/internal/localized-fonts/localized-fonts.js +33 -62
- package/internal/localized-fonts/tests/localized-fonts-specs.js +33 -0
- package/internal/selection/selection.js +1 -6
- package/internal/selection/tests/selection-specs.js +6 -4
- package/internal/validators/tests/validators-specs.js +80 -0
- package/internal/validators/validators.js +14 -34
- package/package.json +8 -2
- package/resolution/ResolutionDecorator.js +4 -40
- package/resolution/index.js +0 -7
- package/resolution/resolution.js +42 -80
- package/resolution/tests/ResolutionDecorator-specs.js +4 -11
- package/resolution/tests/resolution-specs.js +2 -2
- package/useControlledState/tests/useControlledState-specs.js +15 -46
- package/useControlledState/useControlledState.js +11 -22
- package/useScroll/ScrollAnimator.js +49 -65
- package/useScroll/Scrollbar.js +22 -58
- package/useScroll/ScrollbarTrack.js +3 -19
- package/useScroll/useScroll.js +267 -454
- package/useScroll/utilDOM.js +8 -14
- package/useScroll/utilEvent.js +0 -4
|
@@ -4,47 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = exports.ResolutionDecorator = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
11
|
-
|
|
12
9
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
-
|
|
14
10
|
var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
|
|
15
|
-
|
|
16
11
|
var _resolution = require("./resolution");
|
|
17
|
-
|
|
18
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
21
|
-
|
|
22
14
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
-
|
|
24
15
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
25
|
-
|
|
26
16
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
-
|
|
28
17
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
29
|
-
|
|
30
18
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
31
|
-
|
|
32
19
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
33
|
-
|
|
34
20
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
35
|
-
|
|
36
21
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
37
|
-
|
|
38
22
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
39
|
-
|
|
40
23
|
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
41
|
-
|
|
42
24
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
43
|
-
|
|
44
25
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
45
|
-
|
|
46
26
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
47
|
-
|
|
48
27
|
/**
|
|
49
28
|
* Default config for `ResolutionDecorator`.
|
|
50
29
|
*
|
|
@@ -61,7 +40,6 @@ var defaultConfig = {
|
|
|
61
40
|
* @memberof ui/resolution.ResolutionDecorator.defaultConfig
|
|
62
41
|
*/
|
|
63
42
|
dynamic: true,
|
|
64
|
-
|
|
65
43
|
/**
|
|
66
44
|
* An array of objects containing declarations for screen types to add to the list of known
|
|
67
45
|
* screen types.
|
|
@@ -73,6 +51,7 @@ var defaultConfig = {
|
|
|
73
51
|
*/
|
|
74
52
|
screenTypes: null
|
|
75
53
|
};
|
|
54
|
+
|
|
76
55
|
/**
|
|
77
56
|
* A higher-order component that configures resolution support for its wrapped component tree.
|
|
78
57
|
*
|
|
@@ -95,36 +74,26 @@ var defaultConfig = {
|
|
|
95
74
|
* @hoc
|
|
96
75
|
* @public
|
|
97
76
|
*/
|
|
98
|
-
|
|
99
77
|
var ResolutionDecorator = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
|
|
100
78
|
var _class;
|
|
101
|
-
|
|
102
79
|
if (config.screenTypes) {
|
|
103
80
|
(0, _resolution.defineScreenTypes)(config.screenTypes);
|
|
104
81
|
}
|
|
105
|
-
|
|
106
82
|
return _class = /*#__PURE__*/function (_Component) {
|
|
107
83
|
_inherits(_class, _Component);
|
|
108
|
-
|
|
109
84
|
var _super = _createSuper(_class);
|
|
110
|
-
|
|
111
85
|
function _class(props) {
|
|
112
86
|
var _this;
|
|
113
|
-
|
|
114
87
|
_classCallCheck(this, _class);
|
|
115
|
-
|
|
116
88
|
_this = _super.call(this, props);
|
|
117
|
-
|
|
118
89
|
_this.handleResize = function () {
|
|
119
90
|
var classNames = _this.didClassesChange();
|
|
120
|
-
|
|
121
91
|
if (classNames) {
|
|
122
92
|
_this.setState({
|
|
123
93
|
resolutionClasses: classNames
|
|
124
94
|
});
|
|
125
95
|
}
|
|
126
96
|
};
|
|
127
|
-
|
|
128
97
|
(0, _resolution.init)({
|
|
129
98
|
measurementNode: typeof window !== 'undefined' && window
|
|
130
99
|
});
|
|
@@ -133,12 +102,11 @@ var ResolutionDecorator = (0, _hoc["default"])(defaultConfig, function (config,
|
|
|
133
102
|
};
|
|
134
103
|
return _this;
|
|
135
104
|
}
|
|
136
|
-
|
|
137
105
|
_createClass(_class, [{
|
|
138
106
|
key: "componentDidMount",
|
|
139
107
|
value: function componentDidMount() {
|
|
140
|
-
if (config.dynamic) window.addEventListener('resize', this.handleResize);
|
|
141
|
-
|
|
108
|
+
if (config.dynamic) window.addEventListener('resize', this.handleResize);
|
|
109
|
+
// eslint-disable-next-line react/no-find-dom-node
|
|
142
110
|
this.rootNode = _reactDom["default"].findDOMNode(this);
|
|
143
111
|
}
|
|
144
112
|
}, {
|
|
@@ -162,7 +130,6 @@ var ResolutionDecorator = (0, _hoc["default"])(defaultConfig, function (config,
|
|
|
162
130
|
measurementNode: this.rootNode
|
|
163
131
|
});
|
|
164
132
|
var classNames = (0, _resolution.getResolutionClasses)();
|
|
165
|
-
|
|
166
133
|
if (prevClassNames !== classNames) {
|
|
167
134
|
return classNames;
|
|
168
135
|
}
|
|
@@ -178,11 +145,8 @@ var ResolutionDecorator = (0, _hoc["default"])(defaultConfig, function (config,
|
|
|
178
145
|
}));
|
|
179
146
|
}
|
|
180
147
|
}]);
|
|
181
|
-
|
|
182
148
|
return _class;
|
|
183
|
-
}(_react.Component), _class.displayName = 'ResolutionDecorator', _class.propTypes =
|
|
184
|
-
/** @lends ui/resolution.ResolutionDecorator.prototype */
|
|
185
|
-
{
|
|
149
|
+
}(_react.Component), _class.displayName = 'ResolutionDecorator', _class.propTypes = /** @lends ui/resolution.ResolutionDecorator.prototype */{
|
|
186
150
|
className: _propTypes["default"].string
|
|
187
151
|
}, _class;
|
|
188
152
|
});
|
package/resolution/index.js
CHANGED
|
@@ -13,9 +13,7 @@ Object.defineProperty(exports, "ResolutionDecorator", {
|
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
15
|
exports["default"] = void 0;
|
|
16
|
-
|
|
17
16
|
var ri = _interopRequireWildcard(require("./resolution"));
|
|
18
|
-
|
|
19
17
|
Object.keys(ri).forEach(function (key) {
|
|
20
18
|
if (key === "default" || key === "__esModule") return;
|
|
21
19
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -27,15 +25,10 @@ Object.keys(ri).forEach(function (key) {
|
|
|
27
25
|
}
|
|
28
26
|
});
|
|
29
27
|
});
|
|
30
|
-
|
|
31
28
|
var _ResolutionDecorator = _interopRequireDefault(require("./ResolutionDecorator"));
|
|
32
|
-
|
|
33
29
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
34
|
-
|
|
35
30
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
36
|
-
|
|
37
31
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
38
|
-
|
|
39
32
|
/**
|
|
40
33
|
* Exports a number of useful methods for resolution independence.
|
|
41
34
|
*
|
package/resolution/resolution.js
CHANGED
|
@@ -18,24 +18,25 @@ exports.selectSrc = selectSrc;
|
|
|
18
18
|
exports.unit = unit;
|
|
19
19
|
exports.unitToPixelFactors = void 0;
|
|
20
20
|
var baseScreen,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}],
|
|
36
|
-
|
|
37
|
-
screenTypeObject,
|
|
38
|
-
|
|
21
|
+
orientation,
|
|
22
|
+
riRatio,
|
|
23
|
+
screenType,
|
|
24
|
+
workspaceBounds = {
|
|
25
|
+
width: typeof window === 'object' ? window.innerWidth : 1920,
|
|
26
|
+
height: typeof window === 'object' ? window.innerHeight : 1080
|
|
27
|
+
},
|
|
28
|
+
screenTypes = [{
|
|
29
|
+
name: 'standard',
|
|
30
|
+
pxPerRem: 16,
|
|
31
|
+
width: workspaceBounds.width,
|
|
32
|
+
height: workspaceBounds.height,
|
|
33
|
+
aspectRatioName: 'standard',
|
|
34
|
+
base: true
|
|
35
|
+
}],
|
|
36
|
+
// Assign one sane type in case defineScreenTypes is never run.
|
|
37
|
+
screenTypeObject,
|
|
38
|
+
config;
|
|
39
|
+
|
|
39
40
|
/**
|
|
40
41
|
* Object that stores all of the pixel conversion factors to each keyed unit.
|
|
41
42
|
*
|
|
@@ -43,7 +44,6 @@ screenTypeObject,
|
|
|
43
44
|
* @memberof ui/resolution
|
|
44
45
|
* @public
|
|
45
46
|
*/
|
|
46
|
-
|
|
47
47
|
exports.config = config;
|
|
48
48
|
var unitToPixelFactors = {
|
|
49
49
|
'rem': 12,
|
|
@@ -53,6 +53,7 @@ exports.unitToPixelFactors = unitToPixelFactors;
|
|
|
53
53
|
var configDefaults = {
|
|
54
54
|
orientationHandling: 'normal'
|
|
55
55
|
};
|
|
56
|
+
|
|
56
57
|
/**
|
|
57
58
|
* Update the common measured boundary object.
|
|
58
59
|
*
|
|
@@ -66,7 +67,6 @@ var configDefaults = {
|
|
|
66
67
|
* @returns {undefined}
|
|
67
68
|
* @private
|
|
68
69
|
*/
|
|
69
|
-
|
|
70
70
|
var updateWorkspaceBounds = function updateWorkspaceBounds(measurementNode) {
|
|
71
71
|
if (measurementNode && (measurementNode.clientHeight || measurementNode.clientWidth)) {
|
|
72
72
|
workspaceBounds = {
|
|
@@ -81,6 +81,7 @@ var updateWorkspaceBounds = function updateWorkspaceBounds(measurementNode) {
|
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
|
+
|
|
84
85
|
/**
|
|
85
86
|
* Fetch the screenType object
|
|
86
87
|
*
|
|
@@ -92,19 +93,16 @@ var updateWorkspaceBounds = function updateWorkspaceBounds(measurementNode) {
|
|
|
92
93
|
* @returns {Object} screenTypeObject
|
|
93
94
|
* @private
|
|
94
95
|
*/
|
|
95
|
-
|
|
96
|
-
|
|
97
96
|
function getScreenTypeObject(type) {
|
|
98
97
|
type = type || screenType;
|
|
99
|
-
|
|
100
98
|
if (screenTypeObject && screenTypeObject.name === type) {
|
|
101
99
|
return screenTypeObject;
|
|
102
100
|
}
|
|
103
|
-
|
|
104
101
|
return screenTypes.filter(function (elem) {
|
|
105
102
|
return type === elem.name;
|
|
106
103
|
})[0];
|
|
107
104
|
}
|
|
105
|
+
|
|
108
106
|
/**
|
|
109
107
|
* Sets up screen resolution scaling capabilities by defining an array of all the screens
|
|
110
108
|
* being used.
|
|
@@ -139,17 +137,14 @@ function getScreenTypeObject(type) {
|
|
|
139
137
|
* @returns {undefined}
|
|
140
138
|
* @public
|
|
141
139
|
*/
|
|
142
|
-
|
|
143
|
-
|
|
144
140
|
function defineScreenTypes(types) {
|
|
145
141
|
if (types) screenTypes = types;
|
|
146
|
-
|
|
147
142
|
for (var i = 0; i < screenTypes.length; i++) {
|
|
148
143
|
if (screenTypes[i]['base']) baseScreen = screenTypes[i];
|
|
149
144
|
}
|
|
150
|
-
|
|
151
145
|
init();
|
|
152
146
|
}
|
|
147
|
+
|
|
153
148
|
/**
|
|
154
149
|
* Fetches the name of the screen type that best matches the current screen size.
|
|
155
150
|
*
|
|
@@ -162,33 +157,30 @@ function defineScreenTypes(types) {
|
|
|
162
157
|
* @returns {String} Screen type (e.g., `'fhd'`, `'uhd'`, etc.)
|
|
163
158
|
* @public
|
|
164
159
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
167
160
|
function getScreenType(rez) {
|
|
168
161
|
rez = rez || workspaceBounds;
|
|
169
162
|
var types = screenTypes;
|
|
170
163
|
var bestMatch = types[types.length - 1].name; // Blindly set the first screen type, in case no matches are found later.
|
|
171
164
|
|
|
172
165
|
orientation = 'landscape';
|
|
173
|
-
|
|
174
166
|
if (rez.height > rez.width) {
|
|
175
167
|
orientation = 'portrait';
|
|
176
168
|
var swap = rez.width;
|
|
177
169
|
rez.width = rez.height;
|
|
178
170
|
rez.height = swap;
|
|
179
|
-
}
|
|
180
|
-
|
|
171
|
+
}
|
|
181
172
|
|
|
173
|
+
// Loop through resolutions, last->first, largest->smallest
|
|
182
174
|
for (var i = types.length - 1; i >= 0; i--) {
|
|
183
175
|
// Does the current resolution fit inside this screenType definition? If so, save it as the current best match.
|
|
184
176
|
if (rez.height <= types[i].height && rez.width <= types[i].width) {
|
|
185
177
|
bestMatch = types[i].name;
|
|
186
178
|
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
179
|
+
}
|
|
180
|
+
// Return the name of the closest fitting set of dimensions.
|
|
190
181
|
return bestMatch;
|
|
191
182
|
}
|
|
183
|
+
|
|
192
184
|
/**
|
|
193
185
|
* Calculate the base rem font size.
|
|
194
186
|
*
|
|
@@ -214,20 +206,17 @@ function getScreenType(rez) {
|
|
|
214
206
|
* @returns {String} The calculated pixel size (with unit suffix. Ex: "24px").
|
|
215
207
|
* @public
|
|
216
208
|
*/
|
|
217
|
-
|
|
218
|
-
|
|
219
209
|
function calculateFontSize(type) {
|
|
220
210
|
var scrObj = getScreenTypeObject(type);
|
|
221
211
|
var size;
|
|
222
|
-
|
|
223
212
|
if (orientation === 'portrait' && config.orientationHandling === 'scale') {
|
|
224
213
|
size = scrObj.height / scrObj.width * scrObj.pxPerRem;
|
|
225
214
|
} else {
|
|
226
215
|
size = scrObj.pxPerRem;
|
|
227
216
|
}
|
|
228
|
-
|
|
229
217
|
return size + 'px';
|
|
230
218
|
}
|
|
219
|
+
|
|
231
220
|
/**
|
|
232
221
|
* @function
|
|
233
222
|
* @memberof ui/resolution
|
|
@@ -235,13 +224,12 @@ function calculateFontSize(type) {
|
|
|
235
224
|
* @private
|
|
236
225
|
* @returns {undefined}
|
|
237
226
|
*/
|
|
238
|
-
|
|
239
|
-
|
|
240
227
|
function updateBaseFontSize(size) {
|
|
241
228
|
if (typeof window === 'object') {
|
|
242
229
|
document.documentElement.style.fontSize = size;
|
|
243
230
|
}
|
|
244
231
|
}
|
|
232
|
+
|
|
245
233
|
/**
|
|
246
234
|
* Returns the CSS classes for the given `type`.
|
|
247
235
|
*
|
|
@@ -251,27 +239,22 @@ function updateBaseFontSize(size) {
|
|
|
251
239
|
* @returns {String} CSS class names
|
|
252
240
|
* @public
|
|
253
241
|
*/
|
|
254
|
-
|
|
255
|
-
|
|
256
242
|
function getResolutionClasses() {
|
|
257
243
|
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : screenType;
|
|
258
244
|
var classes = [];
|
|
259
|
-
|
|
260
245
|
if (orientation) {
|
|
261
246
|
classes.push('enact-orientation-' + orientation);
|
|
262
247
|
}
|
|
263
|
-
|
|
264
248
|
if (type) {
|
|
265
249
|
classes.push('enact-res-' + type.toLowerCase());
|
|
266
250
|
var scrObj = getScreenTypeObject(type);
|
|
267
|
-
|
|
268
251
|
if (scrObj.aspectRatioName) {
|
|
269
252
|
classes.push('enact-aspect-ratio-' + scrObj.aspectRatioName.toLowerCase());
|
|
270
253
|
}
|
|
271
254
|
}
|
|
272
|
-
|
|
273
255
|
return classes.join(' ');
|
|
274
256
|
}
|
|
257
|
+
|
|
275
258
|
/**
|
|
276
259
|
* Returns the ratio of pixels per rem for the given `type` to the pixels per rem for the base type.
|
|
277
260
|
*
|
|
@@ -281,24 +264,19 @@ function getResolutionClasses() {
|
|
|
281
264
|
*
|
|
282
265
|
* @returns {Number} ratio
|
|
283
266
|
*/
|
|
284
|
-
|
|
285
|
-
|
|
286
267
|
function getRiRatio() {
|
|
287
268
|
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : screenType;
|
|
288
|
-
|
|
289
269
|
if (type && baseScreen) {
|
|
290
270
|
var ratio = getUnitToPixelFactors(type) / getUnitToPixelFactors(baseScreen.name);
|
|
291
|
-
|
|
292
271
|
if (type === screenType) {
|
|
293
272
|
// cache this if it's for our current screen type.
|
|
294
273
|
riRatio = ratio;
|
|
295
274
|
}
|
|
296
|
-
|
|
297
275
|
return ratio;
|
|
298
276
|
}
|
|
299
|
-
|
|
300
277
|
return 1;
|
|
301
278
|
}
|
|
279
|
+
|
|
302
280
|
/**
|
|
303
281
|
* Returns the pixels per rem for the given `type`.
|
|
304
282
|
*
|
|
@@ -307,17 +285,14 @@ function getRiRatio() {
|
|
|
307
285
|
*
|
|
308
286
|
* @returns {Number} pixels per rem
|
|
309
287
|
*/
|
|
310
|
-
|
|
311
|
-
|
|
312
288
|
function getUnitToPixelFactors() {
|
|
313
289
|
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : screenType;
|
|
314
|
-
|
|
315
290
|
if (type) {
|
|
316
291
|
return getScreenTypeObject(type).pxPerRem;
|
|
317
292
|
}
|
|
318
|
-
|
|
319
293
|
return 1;
|
|
320
294
|
}
|
|
295
|
+
|
|
321
296
|
/**
|
|
322
297
|
* Calculates the aspect ratio of the specified screen type.
|
|
323
298
|
*
|
|
@@ -330,17 +305,14 @@ function getUnitToPixelFactors() {
|
|
|
330
305
|
* @returns {Number} The calculated screen ratio (e.g., `1.333`, `1.777`, `2.333`, etc.)
|
|
331
306
|
* @public
|
|
332
307
|
*/
|
|
333
|
-
|
|
334
|
-
|
|
335
308
|
function getAspectRatio(type) {
|
|
336
309
|
var scrObj = getScreenTypeObject(type);
|
|
337
|
-
|
|
338
310
|
if (scrObj.width && scrObj.height) {
|
|
339
311
|
return scrObj.width / scrObj.height;
|
|
340
312
|
}
|
|
341
|
-
|
|
342
313
|
return 1;
|
|
343
314
|
}
|
|
315
|
+
|
|
344
316
|
/**
|
|
345
317
|
* Returns the name of the aspect ratio for a specified screen type, or for the default
|
|
346
318
|
* screen type if none is provided.
|
|
@@ -352,12 +324,11 @@ function getAspectRatio(type) {
|
|
|
352
324
|
* @returns {String} The name of the screen type's aspect ratio
|
|
353
325
|
* @public
|
|
354
326
|
*/
|
|
355
|
-
|
|
356
|
-
|
|
357
327
|
function getAspectRatioName(type) {
|
|
358
328
|
var scrObj = getScreenTypeObject(type);
|
|
359
329
|
return scrObj.aspectRatioName || 'standard';
|
|
360
330
|
}
|
|
331
|
+
|
|
361
332
|
/**
|
|
362
333
|
* Takes a provided pixel value and performs a scaling operation based on the current
|
|
363
334
|
* screen type.
|
|
@@ -369,11 +340,10 @@ function getAspectRatioName(type) {
|
|
|
369
340
|
* @returns {Number} The scaled value based on the current screen scaling factor
|
|
370
341
|
* @public
|
|
371
342
|
*/
|
|
372
|
-
|
|
373
|
-
|
|
374
343
|
function scale(px) {
|
|
375
344
|
return (riRatio || getRiRatio()) * px;
|
|
376
345
|
}
|
|
346
|
+
|
|
377
347
|
/**
|
|
378
348
|
* Convert to various unit formats.
|
|
379
349
|
*
|
|
@@ -400,14 +370,13 @@ function scale(px) {
|
|
|
400
370
|
* @returns {String|undefined} Resulting conversion in CSS safe format, in case of malformed input, `undefined`
|
|
401
371
|
* @public
|
|
402
372
|
*/
|
|
403
|
-
|
|
404
|
-
|
|
405
373
|
function unit(pixels, toUnit) {
|
|
406
374
|
if (!toUnit || !unitToPixelFactors[toUnit]) return;
|
|
407
375
|
if (typeof pixels === 'string' && pixels.substr(-2) === 'px') pixels = parseInt(pixels.substr(0, pixels.length - 2));
|
|
408
376
|
if (typeof pixels !== 'number') return;
|
|
409
377
|
return pixels / unitToPixelFactors[toUnit] + '' + toUnit;
|
|
410
378
|
}
|
|
379
|
+
|
|
411
380
|
/**
|
|
412
381
|
* Shorthand for when you know you need to scale some pixel value and have it converted to "rem" for
|
|
413
382
|
* proper scaling.
|
|
@@ -421,11 +390,10 @@ function unit(pixels, toUnit) {
|
|
|
421
390
|
* @returns {String|undefined} Resulting conversion or, in case of malformed input, `undefined`
|
|
422
391
|
* @public
|
|
423
392
|
*/
|
|
424
|
-
|
|
425
|
-
|
|
426
393
|
var scaleToRem = function scaleToRem(pixels) {
|
|
427
394
|
return unit(scale(pixels), 'rem');
|
|
428
395
|
};
|
|
396
|
+
|
|
429
397
|
/**
|
|
430
398
|
* The default configurable options for {@link ui/resolution.selectSrc}. Additional resolutions
|
|
431
399
|
* may be added.
|
|
@@ -476,25 +444,22 @@ var scaleToRem = function scaleToRem(pixels) {
|
|
|
476
444
|
* or hash provided
|
|
477
445
|
* @public
|
|
478
446
|
*/
|
|
479
|
-
|
|
480
|
-
|
|
481
447
|
exports.scaleToRem = scaleToRem;
|
|
482
|
-
|
|
483
448
|
function selectSrc(src) {
|
|
484
449
|
if (typeof src != 'string' && src) {
|
|
485
450
|
var newSrc = src.fhd || src.uhd || src.hd;
|
|
486
|
-
var types = screenTypes;
|
|
451
|
+
var types = screenTypes;
|
|
487
452
|
|
|
453
|
+
// loop through resolutions
|
|
488
454
|
for (var i = types.length - 1; i >= 0; i--) {
|
|
489
455
|
var t = types[i].name;
|
|
490
456
|
if (screenType === t && src[t]) newSrc = src[t];
|
|
491
457
|
}
|
|
492
|
-
|
|
493
458
|
src = newSrc;
|
|
494
459
|
}
|
|
495
|
-
|
|
496
460
|
return src;
|
|
497
461
|
}
|
|
462
|
+
|
|
498
463
|
/**
|
|
499
464
|
* This will need to be re-run any time the screen size changes, so all the values can be re-cached.
|
|
500
465
|
*
|
|
@@ -507,8 +472,6 @@ function selectSrc(src) {
|
|
|
507
472
|
* @returns {undefined}
|
|
508
473
|
* @public
|
|
509
474
|
*/
|
|
510
|
-
|
|
511
|
-
|
|
512
475
|
function init() {
|
|
513
476
|
var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
514
477
|
var measurementNode = args.measurementNode;
|
|
@@ -519,6 +482,7 @@ function init() {
|
|
|
519
482
|
riRatio = getRiRatio();
|
|
520
483
|
updateBaseFontSize(calculateFontSize());
|
|
521
484
|
}
|
|
485
|
+
|
|
522
486
|
/**
|
|
523
487
|
* The current configuration
|
|
524
488
|
*
|
|
@@ -526,6 +490,4 @@ function init() {
|
|
|
526
490
|
* @memberof ui/resolution
|
|
527
491
|
* @private
|
|
528
492
|
*/
|
|
529
|
-
|
|
530
|
-
|
|
531
493
|
exports.config = config = Object.assign({}, configDefaults);
|
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
require("@testing-library/jest-dom");
|
|
4
|
-
|
|
5
4
|
var _react = require("@testing-library/react");
|
|
6
|
-
|
|
7
5
|
var _ResolutionDecorator = _interopRequireDefault(require("../ResolutionDecorator"));
|
|
8
|
-
|
|
9
6
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
-
|
|
11
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
|
-
|
|
13
8
|
describe('ResolutionDecorator Specs', function () {
|
|
14
9
|
test('should apply resolution classes to the wrapped component', function () {
|
|
15
10
|
var Component = (0, _ResolutionDecorator["default"])('div');
|
|
16
11
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
17
12
|
"data-testid": "component"
|
|
18
13
|
}));
|
|
19
|
-
|
|
20
14
|
var div = _react.screen.getByTestId('component').className;
|
|
21
|
-
|
|
22
15
|
var expected = true;
|
|
23
16
|
var actual = div.includes('enact-res-standard') && (div.includes('enact-orientation-landscape') || div.includes('enact-orientation-portrait'));
|
|
24
17
|
expect(actual).toBe(expected);
|
|
@@ -39,13 +32,13 @@ describe('ResolutionDecorator Specs', function () {
|
|
|
39
32
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
40
33
|
"data-testid": "component"
|
|
41
34
|
}));
|
|
42
|
-
|
|
43
35
|
var div = _react.screen.getByTestId('component');
|
|
44
|
-
|
|
45
36
|
expect(div).toHaveClass('enact-res-mhd');
|
|
46
37
|
});
|
|
47
|
-
test.skip('should update the resolution when the screen is resized', function () {
|
|
38
|
+
test.skip('should update the resolution when the screen is resized', function () {
|
|
39
|
+
// TODO: write a test
|
|
48
40
|
});
|
|
49
|
-
test.skip('should not allow dynamic resolution updates when \'dynamic\' config option is false', function () {
|
|
41
|
+
test.skip('should not allow dynamic resolution updates when \'dynamic\' config option is false', function () {
|
|
42
|
+
// TODO: write a test
|
|
50
43
|
});
|
|
51
44
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _resolution = require("../resolution.js");
|
|
4
|
-
|
|
5
4
|
describe('Resolution Specs', function () {
|
|
6
5
|
var screenTypes = [{
|
|
7
6
|
name: 'vga',
|
|
@@ -84,7 +83,8 @@ describe('Resolution Specs', function () {
|
|
|
84
83
|
var actualHD = (0, _resolution.unit)(16, 'rem');
|
|
85
84
|
expect(actualFHD).toBe(expectedFHD);
|
|
86
85
|
expect(actualHD).toBe(expectedHD);
|
|
87
|
-
});
|
|
86
|
+
});
|
|
88
87
|
|
|
88
|
+
// NOTE: Currently tough to test selectSrc because it relies on a global variable for screenType
|
|
89
89
|
test.skip('should select source for the current screen type', function () {});
|
|
90
90
|
});
|