@enact/ui 5.4.4 → 5.5.1

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 (65) hide show
  1. package/AnnounceDecorator/Announce.js +9 -5
  2. package/AnnounceDecorator/AnnounceDecorator.js +5 -3
  3. package/AnnounceDecorator/tests/AnnounceDecorator-specs.js +4 -1
  4. package/AnnounceDecorator/tests/useAnnounce-specs.js +4 -1
  5. package/CHANGELOG.md +30 -0
  6. package/Cancelable/Cancelable.js +7 -0
  7. package/Cancelable/tests/Cancelable-specs.js +26 -0
  8. package/Changeable/Changeable.js +6 -0
  9. package/Changeable/tests/Changeable-specs.js +4 -1
  10. package/FloatingLayer/FloatingLayer.js +3 -0
  11. package/FloatingLayer/FloatingLayerDecorator.js +2 -0
  12. package/FloatingLayer/Scrim.js +3 -0
  13. package/Marquee/Marquee.module.css +1 -1
  14. package/Marquee/MarqueeDecorator.js +19 -3
  15. package/Marquee/tests/Marquee-specs.js +306 -1
  16. package/Marquee/useMarqueeController.js +6 -4
  17. package/Measurable/tests/Measurable-specs.js +6 -2
  18. package/Media/Media.js +5 -2
  19. package/Placeholder/tests/PlaceholderControllerDecorator-specs.js +4 -1
  20. package/Resizable/tests/Resizable-specs.js +4 -1
  21. package/Resizable/tests/useResize-specs.js +4 -1
  22. package/Routable/Route.js +5 -3
  23. package/Routable/Router.js +25 -16
  24. package/Routable/tests/Routable-specs.js +16 -0
  25. package/Scroller/Scroller.js +6 -5
  26. package/Scroller/ScrollerBasic.js +5 -5
  27. package/Skinnable/Skinnable.js +9 -7
  28. package/Skinnable/tests/Skinnable-specs.js +7 -2
  29. package/Skinnable/useSkins.js +6 -2
  30. package/Slider/PositionDecorator.js +20 -5
  31. package/Slider/Slider.d.ts +4 -0
  32. package/Slider/Slider.js +10 -0
  33. package/Slider/tests/Slider-specs.js +18 -0
  34. package/Slider/utils.js +9 -1
  35. package/Toggleable/Toggleable.js +4 -2
  36. package/Toggleable/tests/Toggleable-specs.js +4 -1
  37. package/Touchable/Touchable.js +6 -4
  38. package/Touchable/tests/Touchable-specs.js +4 -1
  39. package/Touchable/tests/useTouch-specs.js +4 -1
  40. package/Touchable/useTouch.js +7 -2
  41. package/Transition/Transition.js +2 -0
  42. package/ViewManager/TransitionGroup.js +3 -0
  43. package/ViewManager/View.js +2 -0
  44. package/ViewManager/ViewManager.js +7 -0
  45. package/VirtualList/VirtualList.js +7 -5
  46. package/VirtualList/VirtualListBasic.js +170 -32
  47. package/VirtualList/tests/VirtualList-native-specs.js +233 -3
  48. package/VirtualList/tests/VirtualList-specs.js +13 -0
  49. package/internal/IdProvider/IdProvider.js +2 -0
  50. package/internal/IdProvider/tests/IdProvider-specs.js +4 -1
  51. package/internal/Pure/tests/Pure-specs.js +7 -0
  52. package/package.json +8 -3
  53. package/resolution/ResolutionDecorator.js +21 -18
  54. package/resolution/index.d.ts +63 -4
  55. package/resolution/index.js +18 -2
  56. package/resolution/resolution.js +209 -29
  57. package/resolution/tests/ResolutionDecorator-specs.js +84 -4
  58. package/resolution/tests/resolution-specs.js +217 -599
  59. package/useControlledState/tests/useControlledState-specs.js +4 -1
  60. package/useControlledState/useControlledState.js +11 -7
  61. package/useScroll/Scrollbar.js +27 -24
  62. package/useScroll/ScrollbarTrack.js +5 -3
  63. package/useScroll/tests/useScroll-specs.js +408 -42
  64. package/useScroll/useScroll.js +132 -27
  65. package/useScroll/utilEvent.js +18 -0
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ var _util = require("@enact/core/util");
3
4
  require("@testing-library/jest-dom");
4
5
  var _react = require("@testing-library/react");
5
6
  var _react2 = require("react");
@@ -35,11 +36,17 @@ var Base = /*#__PURE__*/function (_Component) {
35
36
  var _this;
36
37
  _classCallCheck(this, Base);
37
38
  _this = _callSuper(this, Base, [props]);
39
+ (0, _util.checkPropTypes)(_this, props);
38
40
  _this.countRenders = 0;
39
41
  return _this;
40
42
  }
41
43
  _inherits(Base, _Component);
42
44
  return _createClass(Base, [{
45
+ key: "componentDidUpdate",
46
+ value: function componentDidUpdate(prevProps) {
47
+ (0, _util.checkPropTypes)(this, this.props, prevProps);
48
+ }
49
+ }, {
43
50
  key: "render",
44
51
  value: function render() {
45
52
  data = this.props;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enact/ui",
3
- "version": "5.4.4",
3
+ "version": "5.5.1",
4
4
  "description": "A collection of simplified unstyled cross-platform UI components for Enact",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,8 +32,8 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "@enact/core": "^5.4.4",
36
- "@enact/i18n": "^5.4.4",
35
+ "@enact/core": "^5.5.1",
36
+ "@enact/i18n": "^5.5.1",
37
37
  "classnames": "^2.5.1",
38
38
  "ilib": "^14.22.0",
39
39
  "invariant": "^2.2.4",
@@ -43,5 +43,10 @@
43
43
  "react-dom": "^19.2.6",
44
44
  "react-is": "^19.2.6",
45
45
  "warning": "^4.0.3"
46
+ },
47
+ "overrides": {
48
+ "prop-types": {
49
+ "react-is": "^19.2.6"
50
+ }
46
51
  }
47
52
  }
@@ -7,6 +7,7 @@ exports["default"] = exports.ResolutionDecorator = void 0;
7
7
  var _react = require("react");
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
10
+ var _util = require("@enact/core/util");
10
11
  var _resolution = require("./resolution");
11
12
  var _jsxRuntime = require("react/jsx-runtime");
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
@@ -38,6 +39,10 @@ var defaultConfig = {
38
39
  /**
39
40
  * Attaches an event listener to the window to listen for resize events.
40
41
  *
42
+ * When enabled, the resolution classes will be automatically updated when the window
43
+ * is resized or when screen rotation occurs (such as when a device changes from
44
+ * landscape to portrait orientation).
45
+ *
41
46
  * @type {Boolean}
42
47
  * @default true
43
48
  * @public
@@ -51,23 +56,11 @@ var defaultConfig = {
51
56
  * When set to `normal`, the font-size will be the pxPerRem value of the best match screen type.
52
57
  *
53
58
  * @type {('normal'|'scale')}
54
- * @default 'normal'
55
- * @private
56
- * @memberof ui/resolution.ResolutionDecorator.defaultConfig
57
- */
58
- intermediateScreenHandling: 'normal',
59
- /**
60
- * Determines how to get the best match screen type of current resolution.
61
- * When set to `true`, the matched screen type will be the one that is smaller and
62
- * the closest to the screen resolution.
63
- * When set to `false`, the matched screen type will be the one that is greater and
64
- * the closest to the screen resolution.
65
- *
66
- * @type {Boolean}
59
+ * @default 'scale'
67
60
  * @private
68
61
  * @memberof ui/resolution.ResolutionDecorator.defaultConfig
69
62
  */
70
- matchSmallerScreenType: false,
63
+ fontSizeHandling: 'scale',
71
64
  /**
72
65
  * An array of objects containing declarations for screen types to add to the list of known
73
66
  * screen types.
@@ -83,13 +76,17 @@ var defaultConfig = {
83
76
  /**
84
77
  * A higher-order component that configures resolution support for its wrapped component tree.
85
78
  *
79
+ * This decorator automatically applies resolution-specific CSS classes to the wrapped component,
80
+ * enabling responsive layouts that adapt to different screen sizes, orientations, and aspect ratios.
81
+ * It also supports dynamic updates when the window is resized or when the screen rotates.
82
+ *
86
83
  * Configuration options:
87
- * * `dynamic: true` - when `true`, updates the resolution classes when the window resizes
84
+ * * `dynamic: true` - when `true`, updates the resolution classes when the window resizes or the screen rotates
88
85
  * * `screenTypes: null` - defines a set of screen types to support
89
86
  *
90
87
  * Example:
91
88
  * ```
92
- * // Will have the resolution classes and will be updated when the window resizes
89
+ * // Will have the resolution classes and will be updated when the window resizes or the screen rotates
93
90
  * const AppWithResolution = ResolutionDecorator(App);
94
91
  * // Will have the resolution classes for the screen at the time of render only
95
92
  * const AppWithStaticResolution = ResolutionDecorator({dynamic: false}, App);
@@ -120,8 +117,9 @@ var ResolutionDecorator = exports.ResolutionDecorator = (0, _hoc["default"])(def
120
117
  });
121
118
  }
122
119
  };
123
- _resolution.config.intermediateScreenHandling = config.intermediateScreenHandling;
124
- _resolution.config.matchSmallerScreenType = config.matchSmallerScreenType;
120
+ (0, _util.checkPropTypes)(_this, props);
121
+ _resolution.config.fontSizeHandling = config.fontSizeHandling;
122
+ if (config.linearScaling) _resolution.config.linearScaling = config.linearScaling;
125
123
  (0, _resolution.init)({
126
124
  measurementNode: typeof window !== 'undefined' && window
127
125
  });
@@ -138,6 +136,11 @@ var ResolutionDecorator = exports.ResolutionDecorator = (0, _hoc["default"])(def
138
136
  if (config.dynamic) window.addEventListener('resize', this.handleResize);
139
137
  this.rootNode = ((_document$getElements = document.getElementsByClassName((0, _resolution.getResolutionClasses)())) === null || _document$getElements === void 0 ? void 0 : _document$getElements[0]) || null;
140
138
  }
139
+ }, {
140
+ key: "componentDidUpdate",
141
+ value: function componentDidUpdate(prevProps) {
142
+ (0, _util.checkPropTypes)(this, this.props, prevProps);
143
+ }
141
144
  }, {
142
145
  key: "componentWillUnmount",
143
146
  value: function componentWillUnmount() {
@@ -5,8 +5,12 @@ type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
5
5
 
6
6
  export interface ResolutionDecoratorConfig extends Object {
7
7
  /**
8
- * Attaches an event listener to the window to listen for resize events.
9
- */
8
+ * Attaches an event listener to the window to listen for resize events.
9
+ *
10
+ * When enabled, the resolution classes will be automatically updated when the window
11
+ is resized or when screen rotation occurs (such as when a device changes from
12
+ landscape to portrait orientation).
13
+ */
10
14
  dynamic?: boolean;
11
15
  /**
12
16
  * An array of objects containing declarations for screen types to add to the list of known
@@ -72,7 +76,7 @@ export function getScreenType(rez: object): string;
72
76
  *
73
77
  * This is how the magic happens. This accepts an optional `screenType` name. If one isn't provided,
74
78
  the currently detected screen type is used. This uses the config option `orientationHandling` ,
75
- which when set to "scale" and the screen is in portrait orientation, will dynamically calculate
79
+ which when set to "scale" and the screen is in portrait orientation (such as after screen rotation), will dynamically calculate
76
80
  what the base font size should be, if the width were proportionally scaled down to fit in the portrait space.
77
81
  *
78
82
  * To use, put the following in your application code:
@@ -83,11 +87,30 @@ ri.config.orientationHandling = 'scale';
83
87
  ri.init();
84
88
  ```
85
89
 
86
- * This has no effect if the screen is in landscape, or if `orientationHandling` is unset.
90
+ * This configuration is particularly useful for applications that support screen rotation and need
91
+ to maintain consistent scaling when the device orientation changes from landscape to portrait or vice versa.
92
+ This has no effect if the screen is in landscape, or if `orientationHandling` is unset.
87
93
  */
88
94
  export function calculateFontSize(type: string): string;
89
95
  /**
90
96
  * Returns the CSS classes for the given `type` .
97
+ *
98
+ * This function generates CSS class names that can be used to style components based on
99
+ the current screen resolution, orientation, and aspect ratio. The returned classes are
100
+ particularly useful for responsive layouts and handling screen rotation scenarios.
101
+ *
102
+ * The following CSS classes are returned:
103
+ * * Orientation class : `enact-orientation-landscape` or `enact-orientation-portrait`
104
+ * * Applied based on the current screen orientation
105
+ * * Updates automatically when device rotation occurs (if dynamic mode is enabled)
106
+ * * Resolution class : `enact-res-{screentype}`
107
+ * * Examples: `enact-res-fhd` , `enact-res-uhd` , `enact-res-hd` , `enact-res-qhd`
108
+ * * Applied based on the matched screen type
109
+ * * Aspect ratio class : `enact-aspect-ratio-{aspectRatioName}`
110
+ * * Examples: `enact-aspect-ratio-hdtv` , `enact-aspect-ratio-cinema` , `enact-aspect-ratio-standard`
111
+ * * Applied based on the screen type's aspect ratio name
112
+ *
113
+ * Example return value: `'enact-orientation-landscape enact-res-fhd enact-aspect-ratio-hdtv'`
91
114
  */
92
115
  export function getResolutionClasses(type: string): string;
93
116
  /**
@@ -187,3 +210,39 @@ export function selectSrc(
187
210
  * This will need to be re-run any time the screen size changes, so all the values can be re-cached.
188
211
  */
189
212
  export function init(args: object): void;
213
+ export interface LinearScalingConfig {
214
+ /**
215
+ * Enables linear scaling calculation for
216
+ font sizes and unit conversions. Default: `true` .
217
+ */
218
+ active: boolean; /**
219
+ * Determines the
220
+ reference screen used for linear scaling calculation.
221
+ Default: `linearScalingType.currentScreen` .
222
+ */
223
+ type: ui_resolution_linearScalingType;
224
+ }
225
+ /**
226
+ * Configuration options for resolution independence behavior.
227
+ */
228
+ export interface ResolutionConfig {
229
+ /**
230
+ * Determines how to calculate
231
+ font-size. When set to `'scale'` and the screen is in landscape orientation,
232
+ calculates font-size linearly based on screen resolution. When set to `'normal'` ,
233
+ the font-size will be the pxPerRem value of the best match screen type.
234
+ Default: `'scale'`
235
+ */
236
+ fontSizeHandling: "normal" | "scale"; /**
237
+ * Determines how to handle screen
238
+ orientation and rotation. When set to `'scale'` and the screen is in portrait
239
+ orientation (due to screen rotation), dynamically calculates the base font size
240
+ based on proportional scaling. When set to `'normal'` , uses the standard pxPerRem
241
+ value. This is particularly useful for supporting device rotation scenarios.
242
+ Default: `'normal'`
243
+ */
244
+ orientationHandling: "normal" | "scale"; /**
245
+ * Configuration for linear scaling mode.
246
+ */
247
+ linearScaling: LinearScalingConfig;
248
+ }
@@ -29,9 +29,25 @@ var _ResolutionDecorator = _interopRequireDefault(require("./ResolutionDecorator
29
29
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
30
30
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
31
31
  /**
32
- * Exports a number of useful methods for resolution independence.
32
+ * Provides resolution independence utilities for responsive applications.
33
33
  *
34
- * The default export is an object containing the resolution independence methods.
34
+ * This module enables applications to adapt to different screen resolutions, orientations, and aspect ratios.
35
+ * It includes support for screen rotation scenarios, allowing applications
36
+ * to dynamically adjust their layout and scaling when device orientation changes.
37
+ *
38
+ * Key features:
39
+ * - Automatic detection of a screen type based on resolution
40
+ * - Dynamic font-size calculation for different resolutions
41
+ * - Support for screen rotation and orientation changes
42
+ * - Configurable behavior via {@link ui/resolution.config}
43
+ * - CSS class generation for resolution-specific styling via {@link ui/resolution.getResolutionClasses}
44
+ * - The default export is an object containing the resolution independence methods.
45
+ *
46
+ * Key exports include:
47
+ * - {@link ui/resolution.config} - Configuration object for controlling resolution behavior, screen rotation handling, and more
48
+ * - {@link ui/resolution.getResolutionClasses} - Returns CSS classes for resolution, orientation, and aspect ratio
49
+ * - {@link ui/resolution.ResolutionDecorator} - HOC for wrapping components with resolution support
50
+ * - Other utility functions for scaling, unit conversion, and screen type detection
35
51
  *
36
52
  * @module ui/resolution
37
53
  * @exports ResolutionDecorator
@@ -12,6 +12,7 @@ exports.getResolutionClasses = getResolutionClasses;
12
12
  exports.getScreenType = getScreenType;
13
13
  exports.getScreenTypeObject = getScreenTypeObject;
14
14
  exports.init = init;
15
+ exports.linearScalingType = void 0;
15
16
  exports.scale = scale;
16
17
  exports.scaleToRem = void 0;
17
18
  exports.selectSrc = selectSrc;
@@ -48,10 +49,114 @@ var unitToPixelFactors = exports.unitToPixelFactors = {
48
49
  'rem': 12,
49
50
  'in': 96
50
51
  };
52
+
53
+ /**
54
+ * Enumerates the available reporting types for linear scaling.
55
+ *
56
+ * @enum {String}
57
+ * @memberof ui/resolution
58
+ * @public
59
+ */
60
+ var linearScalingType = exports.linearScalingType = {
61
+ baseScreen: 'baseScreen',
62
+ currentScreen: 'currentScreen'
63
+ };
64
+
65
+ /**
66
+ * Default configuration values.
67
+ *
68
+ * See {@link ui/resolution.config} for full documentation.
69
+ *
70
+ * @type {Object}
71
+ * @memberof ui/resolution
72
+ * @private
73
+ */
51
74
  var configDefaults = {
52
- intermediateScreenHandling: 'normal',
53
- matchSmallerScreenType: false,
54
- orientationHandling: 'normal'
75
+ fontSizeHandling: 'scale',
76
+ orientationHandling: 'normal',
77
+ linearScaling: {
78
+ active: false,
79
+ type: linearScalingType.currentScreen
80
+ }
81
+ };
82
+
83
+ /**
84
+ * Calculates a linearly scaled size for 1rem based on the current workspace dimensions.
85
+ *
86
+ * The calculation determines a scaling factor using the geometric mean of horizontal
87
+ * and vertical scale factors relative to a reference screen (either the `baseScreen`
88
+ * or the currently matched `screenTypeObject`).
89
+ *
90
+ * The resulting size is rounded to one decimal place and constrained to a minimum
91
+ * of 1px and a maximum of the `pxPerRem` value defined for the largest screen type
92
+ * (the last element in `screenTypes`).
93
+ *
94
+ * @function
95
+ * @memberof ui/resolution
96
+ * @returns {Number} The calculated pixel size for 1rem, clamped between 1 and the
97
+ * maximum defined pxPerRem.
98
+ * @private
99
+ */
100
+ function getLinearSize() {
101
+ var isCurrentScreen = config.linearScaling.type === linearScalingType.currentScreen;
102
+ var reportScreen = isCurrentScreen ? screenTypeObject : baseScreen;
103
+ var maxSize = screenTypes.at(-1).pxPerRem;
104
+ var scaleX = workspaceBounds.width / reportScreen.width;
105
+ var scaleY = workspaceBounds.height / reportScreen.height;
106
+ var ratio = Math.sqrt(scaleX * scaleY);
107
+ var size = Math.round(reportScreen.pxPerRem * ratio * 10) / 10;
108
+ return Math.max(1, Math.min(size, maxSize));
109
+ }
110
+
111
+ /**
112
+ * Calculates the scale factor and determines if scaling is necessary
113
+ * for the landscape workspace based on the screen type.
114
+ *
115
+ * @function
116
+ * @memberof ui/resolution
117
+ * @param {String} [type=screenType] The screen type identifier used to retrieve dimensions. Defaults to the global
118
+ * or scoped `screenType`.
119
+ * @returns {Object} Returns an object containing the scaling data.
120
+ * @private
121
+ */
122
+ var getLandscapeScaleFactor = function getLandscapeScaleFactor() {
123
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : screenType;
124
+ if (!type) return {
125
+ shouldScale: false,
126
+ factor: 1
127
+ };
128
+ var scrObj = getScreenTypeObject(type);
129
+ var shouldScale = workspaceBounds.width < scrObj.width || workspaceBounds.height < scrObj.height;
130
+ return {
131
+ shouldScale: shouldScale,
132
+ factor: workspaceBounds.height / scrObj.height
133
+ };
134
+ };
135
+
136
+ /**
137
+ * Get the closest resolution type based on the `resolution`.
138
+ *
139
+ * @function
140
+ * @memberOf ui/resolution
141
+ * @param {Object} resolution The resolution object (must include `height` and `width` properties).
142
+ * @param {Object[]} types The resolution types object (must include `name`, `width`, `height`, and `aspectRatioName` properties).
143
+ * @returns {String} Screen type (e.g., `'fhd'`, `'uhd'`, etc.).
144
+ * @private
145
+ */
146
+ var getClosestResolutionType = function getClosestResolutionType(resolution, types) {
147
+ // Calculates the distance between two resolutions using their width and height as coordinates (x, y)
148
+ var getDistance = function getDistance(p1, p2) {
149
+ return Math.sqrt(Math.pow(p2.width - p1.width, 2) + Math.pow(p2.height - p1.height, 2));
150
+ };
151
+
152
+ // Compares the calculated distances and returns the closest resolution type name that matches current resolution
153
+ var _types$reduce = types.reduce(function (prev, curr) {
154
+ var distCurr = getDistance(curr, resolution);
155
+ var distPrev = getDistance(prev, resolution);
156
+ return distCurr < distPrev ? curr : prev;
157
+ }),
158
+ name = _types$reduce.name;
159
+ return name;
55
160
  };
56
161
 
57
162
  /**
@@ -166,8 +271,6 @@ function defineScreenTypes(types) {
166
271
  function getScreenType(rez) {
167
272
  rez = rez || workspaceBounds;
168
273
  var types = screenTypes;
169
- var bestMatch = config.matchSmallerScreenType ? types[0].name : types[types.length - 1].name; // Blindly set the first screen type, in case no matches are found later.
170
-
171
274
  orientation = 'landscape';
172
275
  if (rez.height > rez.width) {
173
276
  orientation = 'portrait';
@@ -175,26 +278,16 @@ function getScreenType(rez) {
175
278
  rez.width = rez.height;
176
279
  rez.height = swap;
177
280
  }
178
- if (config.matchSmallerScreenType) {
179
- // Loop through resolutions, first->last, smallest->largest
180
- for (var i = 0; i <= types.length - 1; i++) {
181
- // Does this screenType definition fit inside the current resolution? If so, save it as the current best match.
182
- if (rez.height >= types[i].height && rez.width >= types[i].width) {
183
- bestMatch = types[i].name;
184
- }
185
- }
186
- } else {
187
- // Loop through resolutions, last->first, largest->smallest
188
- for (var _i = types.length - 1; _i >= 0; _i--) {
189
- // Does the current resolution fit inside this screenType definition? If so, save it as the current best match.
190
- if (rez.height <= types[_i].height && rez.width <= types[_i].width) {
191
- bestMatch = types[_i].name;
192
- }
281
+
282
+ // Loop through resolutions, last->first, largest->smallest and return in case of exact match.
283
+ for (var i = types.length - 1; i >= 0; i--) {
284
+ if (rez.height === types[i].height && rez.width === types[i].width) {
285
+ return types[i].name;
193
286
  }
194
287
  }
195
288
 
196
289
  // Return the name of the closest fitting set of dimensions.
197
- return bestMatch;
290
+ return getClosestResolutionType(rez, types);
198
291
  }
199
292
 
200
293
  /**
@@ -202,7 +295,7 @@ function getScreenType(rez) {
202
295
  *
203
296
  * This is how the magic happens. This accepts an optional `screenType` name. If one isn't provided,
204
297
  * the currently detected screen type is used. This uses the config option `orientationHandling`,
205
- * which when set to "scale" and the screen is in portrait orientation, will dynamically calculate
298
+ * which when set to "scale" and the screen is in portrait orientation (such as after screen rotation), will dynamically calculate
206
299
  * what the base font size should be, if the width were proportionally scaled down to fit in the portrait space.
207
300
  *
208
301
  * To use, put the following in your application code:
@@ -213,6 +306,8 @@ function getScreenType(rez) {
213
306
  * ri.init();
214
307
  * ```
215
308
  *
309
+ * This configuration is particularly useful for applications that support screen rotation and need
310
+ * to maintain consistent scaling when the device orientation changes from landscape to portrait or vice versa.
216
311
  * This has no effect if the screen is in landscape, or if `orientationHandling` is unset.
217
312
  *
218
313
  * @function
@@ -223,15 +318,19 @@ function getScreenType(rez) {
223
318
  * @public
224
319
  */
225
320
  function calculateFontSize(type) {
321
+ // If linear scaling is enabled, bypass standard screen-type-based calculation and use the dynamic linear size
322
+ if (config.linearScaling.active && !type) {
323
+ return getLinearSize() + 'px';
324
+ }
226
325
  var scrObj = getScreenTypeObject(type);
227
- var shouldScaleFontSize = config.intermediateScreenHandling === 'scale' && (config.matchSmallerScreenType ? workspaceBounds.width > scrObj.width && workspaceBounds.height > scrObj.height : workspaceBounds.width < scrObj.width && workspaceBounds.height < scrObj.height);
326
+ var shouldScaleFontSize = config.fontSizeHandling === 'scale' && (workspaceBounds.width < scrObj.width || workspaceBounds.height < scrObj.height);
228
327
  var size;
229
328
  if (orientation === 'portrait' && config.orientationHandling === 'scale') {
230
329
  size = scrObj.height / scrObj.width * scrObj.pxPerRem;
231
330
  } else {
232
331
  size = scrObj.pxPerRem;
233
332
  if (orientation === 'landscape' && shouldScaleFontSize) {
234
- size = parseInt(workspaceBounds.height * scrObj.pxPerRem / scrObj.height);
333
+ size = workspaceBounds.height * scrObj.pxPerRem / scrObj.height;
235
334
  }
236
335
  }
237
336
  return size + 'px';
@@ -253,6 +352,23 @@ function updateBaseFontSize(size) {
253
352
  /**
254
353
  * Returns the CSS classes for the given `type`.
255
354
  *
355
+ * This function generates CSS class names that can be used to style components based on
356
+ * the current screen resolution, orientation, and aspect ratio. The returned classes are
357
+ * particularly useful for responsive layouts and handling screen rotation scenarios.
358
+ *
359
+ * The following CSS classes are returned:
360
+ * - **Orientation class**: `enact-orientation-landscape` or `enact-orientation-portrait`
361
+ * - Applied based on the current screen orientation
362
+ * - Updates automatically when device rotation occurs (if dynamic mode is enabled)
363
+ * - **Resolution class**: `enact-res-{screentype}`
364
+ * - Examples: `enact-res-fhd`, `enact-res-uhd`, `enact-res-hd`, `enact-res-qhd`
365
+ * - Applied based on the matched screen type
366
+ * - **Aspect ratio class**: `enact-aspect-ratio-{aspectRatioName}`
367
+ * - Examples: `enact-aspect-ratio-hdtv`, `enact-aspect-ratio-cinema`, `enact-aspect-ratio-standard`
368
+ * - Applied based on the screen type's aspect ratio name
369
+ *
370
+ * Example return value: `'enact-orientation-landscape enact-res-fhd enact-aspect-ratio-hdtv'`
371
+ *
256
372
  * @function
257
373
  * @memberof ui/resolution
258
374
  * @param {String} type Screen type
@@ -288,6 +404,14 @@ function getRiRatio() {
288
404
  var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : screenType;
289
405
  if (type && baseScreen) {
290
406
  var ratio = getUnitToPixelFactors(type) / getUnitToPixelFactors(baseScreen.name);
407
+ if (orientation === 'landscape' && config.fontSizeHandling === 'scale') {
408
+ var _getLandscapeScaleFac = getLandscapeScaleFactor(type),
409
+ shouldScale = _getLandscapeScaleFac.shouldScale,
410
+ factor = _getLandscapeScaleFac.factor;
411
+ if (shouldScale) {
412
+ ratio *= factor;
413
+ }
414
+ }
291
415
  if (type === screenType) {
292
416
  // cache this if it's for our current screen type.
293
417
  riRatio = ratio;
@@ -307,6 +431,10 @@ function getRiRatio() {
307
431
  */
308
432
  function getUnitToPixelFactors() {
309
433
  var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : screenType;
434
+ // Use linear scaling for the current screen type if active.
435
+ if (config.linearScaling.active && (!type || type === screenType)) {
436
+ return getLinearSize();
437
+ }
310
438
  if (type) {
311
439
  return getScreenTypeObject(type).pxPerRem;
312
440
  }
@@ -392,8 +520,16 @@ function scale(px) {
392
520
  */
393
521
  function unit(pixels, toUnit) {
394
522
  if (!toUnit || !unitToPixelFactors[toUnit]) return;
395
- if (typeof pixels === 'string' && pixels.substr(-2) === 'px') pixels = parseInt(pixels.substr(0, pixels.length - 2));
523
+ if (typeof pixels === 'string' && pixels.substring(-2) === 'px') pixels = parseInt(pixels.substring(0, pixels.length - 2));
396
524
  if (typeof pixels !== 'number') return;
525
+ if (screenType && orientation === 'landscape' && config.fontSizeHandling === 'scale') {
526
+ var _getLandscapeScaleFac2 = getLandscapeScaleFactor(),
527
+ shouldScale = _getLandscapeScaleFac2.shouldScale,
528
+ factor = _getLandscapeScaleFac2.factor;
529
+ if (shouldScale) {
530
+ return pixels / factor / unitToPixelFactors[toUnit] + '' + toUnit;
531
+ }
532
+ }
397
533
  return pixels / unitToPixelFactors[toUnit] + '' + toUnit;
398
534
  }
399
535
 
@@ -472,7 +608,17 @@ function selectSrc(src) {
472
608
  // loop through resolutions
473
609
  for (var i = types.length - 1; i >= 0; i--) {
474
610
  var t = types[i].name;
475
- if (screenType === t && src[t]) newSrc = src[t];
611
+
612
+ // return exact match
613
+ if (screenType === t && src[t]) return src[t];
614
+ }
615
+ var srcResolutions = types.filter(function (type) {
616
+ return type.name in src;
617
+ });
618
+ var currentScreenTypeResolution = getScreenTypeObject();
619
+ if (srcResolutions.length && currentScreenTypeResolution) {
620
+ var closestType = getClosestResolutionType(currentScreenTypeResolution, srcResolutions);
621
+ newSrc = src[closestType];
476
622
  }
477
623
  src = newSrc;
478
624
  }
@@ -503,10 +649,44 @@ function init() {
503
649
  }
504
650
 
505
651
  /**
506
- * The current configuration
652
+ * @typedef {Object} LinearScalingConfig
653
+ * @memberof ui/resolution
654
+ * @property {Boolean} active - Enables linear scaling calculation for
655
+ * font sizes and unit conversions. Default: `true`.
656
+ * @property {ui/resolution.linearScalingType} type - Determines the
657
+ * reference screen used for linear scaling calculation.
658
+ * Default: `linearScalingType.currentScreen`.
659
+ */
660
+
661
+ /**
662
+ * Configuration options for resolution independence behavior.
507
663
  *
508
- * @type {Object}
664
+ * @typedef {Object} ResolutionConfig
509
665
  * @memberof ui/resolution
510
- * @private
666
+ * @property {('normal'|'scale')} fontSizeHandling - Determines how to calculate
667
+ * font-size. When set to `'scale'` and the screen is in landscape orientation,
668
+ * calculates font-size linearly based on screen resolution. When set to `'normal'`,
669
+ * the font-size will be the pxPerRem value of the best match screen type.
670
+ * Default: `'scale'`
671
+ * @property {('normal'|'scale')} orientationHandling - Determines how to handle screen
672
+ * orientation and rotation. When set to `'scale'` and the screen is in portrait
673
+ * orientation (due to screen rotation), dynamically calculates the base font size
674
+ * based on proportional scaling. When set to `'normal'`, uses the standard pxPerRem
675
+ * value. This is particularly useful for supporting device rotation scenarios.
676
+ * Default: `'normal'`
677
+ * @property {LinearScalingConfig} linearScaling - Configuration for linear scaling mode.
678
+ * @public
679
+ */
680
+
681
+ /**
682
+ * Configuration object for resolution independence behavior.
683
+ *
684
+ * This object controls how the resolution independence system handles different screen sizes,
685
+ * orientations, and screen rotation scenarios.
686
+ * See the details in {@link ui/resolution.ResolutionConfig|ResolutionConfig}
687
+ *
688
+ * @type {ui/resolution.ResolutionConfig}
689
+ * @memberof ui/resolution
690
+ * @public
511
691
  */
512
692
  exports.config = config = Object.assign({}, configDefaults);