@enact/ui 4.5.1 → 4.6.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.
Files changed (185) hide show
  1. package/AnnounceDecorator/Announce.js +1 -40
  2. package/AnnounceDecorator/AnnounceDecorator.js +3 -21
  3. package/AnnounceDecorator/tests/Announce-specs.js +2 -7
  4. package/AnnounceDecorator/tests/AnnounceDecorator-specs.js +2 -6
  5. package/AnnounceDecorator/tests/useAnnounce-specs.js +8 -19
  6. package/AnnounceDecorator/useAnnounce.js +0 -6
  7. package/BodyText/BodyText.d.ts +1 -1
  8. package/BodyText/BodyText.js +8 -28
  9. package/BodyText/tests/BodyText-specs.js +0 -19
  10. package/Button/Button.d.ts +6 -6
  11. package/Button/Button.js +33 -63
  12. package/Button/tests/Button-specs.js +0 -26
  13. package/CHANGELOG.md +36 -0
  14. package/Cancelable/Cancelable.js +8 -47
  15. package/Cancelable/cancelHandler.js +5 -12
  16. package/Cancelable/modalHandler.js +3 -11
  17. package/Cancelable/tests/Cancelable-specs.js +3 -57
  18. package/Changeable/Changeable.js +2 -34
  19. package/Changeable/tests/Changeable-specs.js +20 -66
  20. package/ComponentOverride/ComponentOverride.js +1 -13
  21. package/FloatingLayer/FloatingLayer.js +17 -73
  22. package/FloatingLayer/FloatingLayerContainer.js +0 -15
  23. package/FloatingLayer/FloatingLayerDecorator.js +4 -17
  24. package/FloatingLayer/Scrim.js +9 -53
  25. package/FloatingLayer/index.js +0 -4
  26. package/FloatingLayer/tests/FloatingLayer-specs.js +8 -22
  27. package/FloatingLayer/tests/Scrim-specs.js +0 -9
  28. package/FloatingLayer/tests/useFloatingLayerDecorator-specs.js +0 -13
  29. package/FloatingLayer/useFloatingLayer.js +3 -14
  30. package/FloatingLayer/useFloatingLayerDecorator.js +3 -11
  31. package/ForwardRef/ForwardRef.js +1 -10
  32. package/GridListImageItem/GridListImageItem.d.ts +1 -1
  33. package/GridListImageItem/GridListImageItem.js +18 -51
  34. package/Group/Group.js +5 -36
  35. package/Group/GroupItem.js +16 -33
  36. package/Group/tests/Group-specs.js +0 -32
  37. package/Heading/Heading.js +8 -36
  38. package/Heading/tests/Heading-specs.js +81 -14
  39. package/Icon/Icon.d.ts +4 -4
  40. package/Icon/Icon.js +19 -53
  41. package/Icon/tests/Icon-specs.js +0 -22
  42. package/IconButton/IconButton.d.ts +4 -4
  43. package/IconButton/IconButton.js +17 -55
  44. package/IconButton/tests/IconButton-specs.js +0 -7
  45. package/Image/Image.js +17 -46
  46. package/Image/tests/Image-specs.js +0 -14
  47. package/ImageItem/ImageItem.js +18 -47
  48. package/ImageItem/tests/ImageItem-specs.js +0 -25
  49. package/Item/Item.js +9 -33
  50. package/Item/tests/Item-specs.js +0 -24
  51. package/LabeledIcon/LabeledIcon.d.ts +2 -2
  52. package/LabeledIcon/LabeledIcon.js +22 -53
  53. package/LabeledIcon/tests/LabeledIcon-specs.js +0 -14
  54. package/Layout/Cell.js +18 -44
  55. package/Layout/Layout.d.ts +16 -16
  56. package/Layout/Layout.js +23 -46
  57. package/Layout/tests/Layout-specs.js +10 -39
  58. package/Marquee/MarqueeBase.js +31 -64
  59. package/Marquee/MarqueeController.js +11 -72
  60. package/Marquee/MarqueeDecorator.js +70 -196
  61. package/Marquee/index.js +1 -5
  62. package/Marquee/tests/Marquee-specs.js +295 -87
  63. package/Measurable/Measurable.js +12 -34
  64. package/Measurable/tests/Measurable-specs.js +115 -0
  65. package/Media/Media.js +15 -65
  66. package/Media/tests/Media-specs.js +168 -0
  67. package/Placeholder/PlaceholderControllerDecorator.js +7 -43
  68. package/Placeholder/PlaceholderDecorator.js +7 -38
  69. package/Placeholder/index.js +1 -5
  70. package/Placeholder/tests/PlaceholderControllerDecorator-specs.js +25 -0
  71. package/Placeholder/tests/PlaceholderDecorator-specs.js +28 -0
  72. package/ProgressBar/ProgressBar.js +14 -45
  73. package/ProgressBar/tests/ProgressBar-specs.js +0 -17
  74. package/RadioDecorator/RadioControllerDecorator.js +1 -29
  75. package/RadioDecorator/RadioDecorator.js +4 -42
  76. package/RadioDecorator/tests/RadioDecorator-specs.js +12 -49
  77. package/Repeater/Repeater.js +9 -33
  78. package/Repeater/tests/Repeater-specs.js +0 -38
  79. package/Resizable/Resizable.js +9 -37
  80. package/Resizable/tests/Resizable-specs.js +34 -0
  81. package/Routable/Link.js +11 -47
  82. package/Routable/Routable.d.ts +2 -2
  83. package/Routable/Routable.js +12 -35
  84. package/Routable/Route.js +0 -6
  85. package/Routable/Router.js +15 -58
  86. package/Routable/tests/Routable-specs.js +7 -33
  87. package/Routable/tests/Router-specs.js +18 -44
  88. package/Routable/useLink.js +4 -8
  89. package/Routable/util.js +18 -24
  90. package/Scrollable/ScrollAnimator.js +49 -65
  91. package/Scrollable/ScrollThumb.js +2 -13
  92. package/Scrollable/Scrollable.js +180 -387
  93. package/Scrollable/ScrollableNative.js +189 -392
  94. package/Scrollable/Scrollbar.js +30 -102
  95. package/Scroller/Scroller.js +15 -39
  96. package/Scroller/ScrollerBasic.js +34 -89
  97. package/Scroller/UiScrollerBase.js +31 -84
  98. package/Scroller/tests/Scroller-specs.js +56 -0
  99. package/Skinnable/Skinnable.js +11 -38
  100. package/Skinnable/tests/Skinnable-specs.js +3 -74
  101. package/Skinnable/tests/useSkins-specs.js +1 -13
  102. package/Skinnable/tests/util-specs.js +0 -14
  103. package/Skinnable/useSkins.js +8 -15
  104. package/Skinnable/util.js +9 -20
  105. package/Slider/Knob.js +5 -24
  106. package/Slider/PositionDecorator.js +16 -54
  107. package/Slider/Slider.d.ts +2 -2
  108. package/Slider/Slider.js +29 -67
  109. package/Slider/tests/Slider-specs.js +94 -7
  110. package/Slider/utils.js +0 -2
  111. package/SlotItem/SlotItem.d.ts +1 -1
  112. package/SlotItem/SlotItem.js +17 -43
  113. package/SlotItem/tests/SlotItem-specs.js +0 -5
  114. package/Slottable/Slottable.js +4 -12
  115. package/Slottable/tests/Slottable-specs.js +19 -46
  116. package/Slottable/tests/useSlots-specs.js +27 -65
  117. package/Slottable/useSlots.js +8 -33
  118. package/Spinner/Spinner.d.ts +1 -1
  119. package/Spinner/Spinner.js +16 -43
  120. package/Spinner/tests/Spinner-specs.js +0 -15
  121. package/ToggleIcon/ToggleIcon.js +10 -36
  122. package/ToggleIcon/tests/ToggleIcon-specs.js +0 -16
  123. package/ToggleItem/ToggleItem.d.ts +3 -3
  124. package/ToggleItem/ToggleItem.js +18 -55
  125. package/ToggleItem/tests/ToggleItem-specs.js +0 -30
  126. package/Toggleable/Toggle.js +1 -15
  127. package/Toggleable/Toggleable.js +12 -45
  128. package/Toggleable/tests/Toggleable-specs.js +28 -96
  129. package/Toggleable/useToggle.js +3 -19
  130. package/Touchable/ClickAllow.js +5 -14
  131. package/Touchable/Drag.js +16 -54
  132. package/Touchable/Flick.js +11 -42
  133. package/Touchable/Hold.js +21 -68
  134. package/Touchable/Touch.js +37 -65
  135. package/Touchable/Touchable.js +32 -71
  136. package/Touchable/config.js +8 -22
  137. package/Touchable/tests/Touchable-specs.js +270 -119
  138. package/Touchable/tests/useTouch-specs.js +6 -80
  139. package/Touchable/useTouch.js +17 -34
  140. package/Transition/Transition.js +37 -118
  141. package/Transition/tests/Transition-specs.js +20 -60
  142. package/ViewManager/Arranger.js +10 -22
  143. package/ViewManager/TransitionGroup.js +32 -107
  144. package/ViewManager/View.js +35 -91
  145. package/ViewManager/ViewManager.d.ts +1 -1
  146. package/ViewManager/ViewManager.js +20 -84
  147. package/ViewManager/tests/View-specs.js +0 -17
  148. package/ViewManager/tests/ViewManager-specs.js +236 -305
  149. package/ViewManager/tests/test-utils.js +0 -8
  150. package/VirtualList/UiVirtualListBase.js +259 -409
  151. package/VirtualList/VirtualList.d.ts +4 -4
  152. package/VirtualList/VirtualList.js +29 -69
  153. package/VirtualList/VirtualListBase.js +0 -3
  154. package/VirtualList/VirtualListBasic.js +273 -431
  155. package/VirtualList/tests/VirtualGridList-native-specs.js +161 -0
  156. package/VirtualList/tests/VirtualGridList-specs.js +614 -0
  157. package/VirtualList/tests/VirtualList-native-specs.js +152 -0
  158. package/VirtualList/tests/VirtualList-specs.js +423 -95
  159. package/internal/IdProvider/IdProvider.js +7 -21
  160. package/internal/IdProvider/Provider.js +4 -17
  161. package/internal/IdProvider/tests/IdProvider-specs.js +44 -0
  162. package/internal/IdProvider/tests/useId-specs.js +6 -20
  163. package/internal/IdProvider/useId.js +0 -6
  164. package/internal/Pure/Pure.js +3 -30
  165. package/internal/Pure/tests/Pure-specs.js +88 -0
  166. package/internal/localized-fonts/localized-fonts.js +33 -62
  167. package/internal/localized-fonts/tests/localized-fonts-specs.js +33 -0
  168. package/internal/selection/selection.js +1 -6
  169. package/internal/selection/tests/selection-specs.js +6 -4
  170. package/internal/validators/tests/validators-specs.js +80 -0
  171. package/internal/validators/validators.js +14 -34
  172. package/package.json +9 -3
  173. package/resolution/ResolutionDecorator.js +4 -40
  174. package/resolution/index.js +0 -7
  175. package/resolution/resolution.js +42 -80
  176. package/resolution/tests/ResolutionDecorator-specs.js +4 -11
  177. package/resolution/tests/resolution-specs.js +2 -2
  178. package/useControlledState/tests/useControlledState-specs.js +15 -46
  179. package/useControlledState/useControlledState.js +11 -22
  180. package/useScroll/ScrollAnimator.js +49 -65
  181. package/useScroll/Scrollbar.js +22 -58
  182. package/useScroll/ScrollbarTrack.js +3 -19
  183. package/useScroll/useScroll.js +267 -454
  184. package/useScroll/utilDOM.js +8 -14
  185. 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); // eslint-disable-next-line react/no-find-dom-node
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
  });
@@ -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
  *
@@ -18,24 +18,25 @@ exports.selectSrc = selectSrc;
18
18
  exports.unit = unit;
19
19
  exports.unitToPixelFactors = void 0;
20
20
  var baseScreen,
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;
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
- } // Loop through resolutions, last->first, largest->smallest
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
- } // Return the name of the closest fitting set of dimensions.
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; // loop through resolutions
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 () {// TODO: write a test
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 () {// TODO: write a test
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
- }); // NOTE: Currently tough to test selectSrc because it relies on a global variable for screenType
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
  });