@enact/ui 5.5.0 → 5.5.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enact/ui",
3
- "version": "5.5.0",
3
+ "version": "5.5.2",
4
4
  "description": "A collection of simplified unstyled cross-platform UI components for Enact",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,21 +32,16 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "@enact/core": "^5.5.0",
36
- "@enact/i18n": "^5.5.0",
35
+ "@enact/core": "^5.5.2",
36
+ "@enact/i18n": "^5.5.2",
37
37
  "classnames": "^2.5.1",
38
- "ilib": "^14.21.3",
38
+ "ilib": "^14.22.0",
39
39
  "invariant": "^2.2.4",
40
40
  "prop-types": "^15.8.1",
41
41
  "ramda": "^0.32.0",
42
- "react": "^19.2.6",
43
- "react-dom": "^19.2.6",
44
- "react-is": "^19.2.6",
42
+ "react": "^19.2.7",
43
+ "react-dom": "^19.2.7",
44
+ "react-is": "^19.2.7",
45
45
  "warning": "^4.0.3"
46
- },
47
- "overrides": {
48
- "prop-types": {
49
- "react-is": "^19.2.6"
50
- }
51
46
  }
52
47
  }
@@ -118,7 +118,8 @@ var ResolutionDecorator = exports.ResolutionDecorator = (0, _hoc["default"])(def
118
118
  }
119
119
  };
120
120
  (0, _util.checkPropTypes)(_this, props);
121
- _resolution.config.fontSizeHandling = config.fontSizeHandling;
121
+ if (config.fontSizeHandling) _resolution.config.fontSizeHandling = config.fontSizeHandling;
122
+ if (config.orientationHandling) _resolution.config.orientationHandling = config.orientationHandling;
122
123
  if (config.linearScaling) _resolution.config.linearScaling = config.linearScaling;
123
124
  (0, _resolution.init)({
124
125
  measurementNode: typeof window !== 'undefined' && window
@@ -75,9 +75,12 @@ export function getScreenType(rez: object): string;
75
75
  * Calculate the base rem font size.
76
76
  *
77
77
  * This is how the magic happens. This accepts an optional `screenType` name. If one isn't provided,
78
- the currently detected screen type is used. This uses the config option `orientationHandling` ,
79
- which when set to "scale" and the screen is in portrait orientation (such as after screen rotation), will dynamically calculate
80
- what the base font size should be, if the width were proportionally scaled down to fit in the portrait space.
78
+ the currently detected screen type is used. When the workspace is smaller than the matched screen
79
+ type in both dimensions, the base font size is scaled proportionally based on the workspace height.
80
+ This scaling is gated by the config options `fontSizeHandling` (landscape orientation) and
81
+ `orientationHandling` (portrait orientation, such as after screen rotation); when the relevant
82
+ option is set to `'scale'` the size is calculated dynamically, otherwise the screen type's
83
+ `pxPerRem` value is used directly.
81
84
  *
82
85
  * To use, put the following in your application code:
83
86
  * ```
@@ -89,7 +92,6 @@ ri.init();
89
92
 
90
93
  * This configuration is particularly useful for applications that support screen rotation and need
91
94
  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.
93
95
  */
94
96
  export function calculateFontSize(type: string): string;
95
97
  /**
@@ -108,9 +108,31 @@ function getLinearSize() {
108
108
  return Math.max(1, Math.min(size, maxSize));
109
109
  }
110
110
 
111
+ /**
112
+ * Determines if the current workspace should be scaled based on the screen type,
113
+ * orientation, and configuration settings.
114
+ *
115
+ * @function
116
+ * @memberof ui/resolution
117
+ * @param {Object} scrObj The screen type object to compare against.
118
+ *
119
+ * @returns {boolean}
120
+ * @private
121
+ */
122
+ var getShouldScale = function getShouldScale() {
123
+ var scrObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : screenTypeObject;
124
+ if (!scrObj) return false;
125
+ var isPortrait = orientation === 'portrait';
126
+ var isLandscape = orientation === 'landscape';
127
+ var shouldScale = workspaceBounds.width < scrObj.width && workspaceBounds.height < scrObj.height;
128
+ var shouldScaleLandscape = config.fontSizeHandling === 'scale' && isLandscape && shouldScale;
129
+ var shouldScalePortrait = config.orientationHandling === 'scale' && isPortrait && shouldScale;
130
+ return shouldScaleLandscape || shouldScalePortrait;
131
+ };
132
+
111
133
  /**
112
134
  * Calculates the scale factor and determines if scaling is necessary
113
- * for the landscape workspace based on the screen type.
135
+ * for the landscape or portrait workspace based on the screen type.
114
136
  *
115
137
  * @function
116
138
  * @memberof ui/resolution
@@ -119,14 +141,14 @@ function getLinearSize() {
119
141
  * @returns {Object} Returns an object containing the scaling data.
120
142
  * @private
121
143
  */
122
- var getLandscapeScaleFactor = function getLandscapeScaleFactor() {
144
+ var getScaleFactor = function getScaleFactor() {
123
145
  var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : screenType;
124
146
  if (!type) return {
125
147
  shouldScale: false,
126
148
  factor: 1
127
149
  };
128
150
  var scrObj = getScreenTypeObject(type);
129
- var shouldScale = workspaceBounds.width < scrObj.width || workspaceBounds.height < scrObj.height;
151
+ var shouldScale = getShouldScale(scrObj);
130
152
  return {
131
153
  shouldScale: shouldScale,
132
154
  factor: workspaceBounds.height / scrObj.height
@@ -134,7 +156,11 @@ var getLandscapeScaleFactor = function getLandscapeScaleFactor() {
134
156
  };
135
157
 
136
158
  /**
137
- * Get the closest resolution type based on the `resolution`.
159
+ * Gets the closest resolution type based on the provided resolution by calculating a distance score.
160
+ *
161
+ * The score is determined by the Euclidean distance between the widths and heights of the
162
+ * resolutions, plus a weighted penalty for the difference in aspect ratios. This ensures that
163
+ * the matched resolution is not only close in size but also has a similar shape.
138
164
  *
139
165
  * @function
140
166
  * @memberOf ui/resolution
@@ -144,16 +170,23 @@ var getLandscapeScaleFactor = function getLandscapeScaleFactor() {
144
170
  * @private
145
171
  */
146
172
  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));
173
+ // Calculates a score for a candidate resolution based on proximity to the target. A lower score indicates a better match.
174
+ var getDistanceScore = function getDistanceScore(p) {
175
+ var distance = Math.sqrt(Math.pow(p.width - resolution.width, 2) + Math.pow(p.height - resolution.height, 2));
176
+ var inputRatio = resolution.width / resolution.height;
177
+ var candidateRatio = getAspectRatio(p.name);
178
+ // Apply a weighted penalty (x1000) for aspect ratio mismatch.
179
+ // This ensures that even if a resolution is close in size, it won't be chosen
180
+ // if its shape (e.g., UltraWide vs. Standard) is significantly different.
181
+ var ratioPenalty = Math.abs(inputRatio - candidateRatio) * 1000;
182
+ return distance + ratioPenalty;
150
183
  };
151
184
 
152
- // Compares the calculated distances and returns the closest resolution type name that matches current resolution
185
+ // Compares the calculated distance scores and returns the closest resolution type name that matches the current resolution.
153
186
  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;
187
+ var currScore = getDistanceScore(curr);
188
+ var prevScore = getDistanceScore(prev);
189
+ return currScore < prevScore ? curr : prev;
157
190
  }),
158
191
  name = _types$reduce.name;
159
192
  return name;
@@ -294,9 +327,12 @@ function getScreenType(rez) {
294
327
  * Calculate the base rem font size.
295
328
  *
296
329
  * This is how the magic happens. This accepts an optional `screenType` name. If one isn't provided,
297
- * the currently detected screen type is used. This uses the config option `orientationHandling`,
298
- * which when set to "scale" and the screen is in portrait orientation (such as after screen rotation), will dynamically calculate
299
- * what the base font size should be, if the width were proportionally scaled down to fit in the portrait space.
330
+ * the currently detected screen type is used. When the workspace is smaller than the matched screen
331
+ * type in both dimensions, the base font size is scaled proportionally based on the workspace height.
332
+ * This scaling is gated by the config options `fontSizeHandling` (landscape orientation) and
333
+ * `orientationHandling` (portrait orientation, such as after screen rotation); when the relevant
334
+ * option is set to `'scale'` the size is calculated dynamically, otherwise the screen type's
335
+ * `pxPerRem` value is used directly.
300
336
  *
301
337
  * To use, put the following in your application code:
302
338
  * ```
@@ -308,7 +344,6 @@ function getScreenType(rez) {
308
344
  *
309
345
  * This configuration is particularly useful for applications that support screen rotation and need
310
346
  * to maintain consistent scaling when the device orientation changes from landscape to portrait or vice versa.
311
- * This has no effect if the screen is in landscape, or if `orientationHandling` is unset.
312
347
  *
313
348
  * @function
314
349
  * @memberof ui/resolution
@@ -323,15 +358,12 @@ function calculateFontSize(type) {
323
358
  return getLinearSize() + 'px';
324
359
  }
325
360
  var scrObj = getScreenTypeObject(type);
326
- var shouldScaleFontSize = config.fontSizeHandling === 'scale' && (workspaceBounds.width < scrObj.width || workspaceBounds.height < scrObj.height);
361
+ var shouldScaleFontSize = getShouldScale(scrObj);
327
362
  var size;
328
- if (orientation === 'portrait' && config.orientationHandling === 'scale') {
329
- size = scrObj.height / scrObj.width * scrObj.pxPerRem;
363
+ if (shouldScaleFontSize) {
364
+ size = workspaceBounds.height * scrObj.pxPerRem / scrObj.height;
330
365
  } else {
331
366
  size = scrObj.pxPerRem;
332
- if (orientation === 'landscape' && shouldScaleFontSize) {
333
- size = workspaceBounds.height * scrObj.pxPerRem / scrObj.height;
334
- }
335
367
  }
336
368
  return size + 'px';
337
369
  }
@@ -404,13 +436,11 @@ function getRiRatio() {
404
436
  var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : screenType;
405
437
  if (type && baseScreen) {
406
438
  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
- }
439
+ var _getScaleFactor = getScaleFactor(type),
440
+ shouldScale = _getScaleFactor.shouldScale,
441
+ factor = _getScaleFactor.factor;
442
+ if (shouldScale) {
443
+ ratio *= factor;
414
444
  }
415
445
  if (type === screenType) {
416
446
  // cache this if it's for our current screen type.
@@ -522,13 +552,11 @@ function unit(pixels, toUnit) {
522
552
  if (!toUnit || !unitToPixelFactors[toUnit]) return;
523
553
  if (typeof pixels === 'string' && pixels.substring(-2) === 'px') pixels = parseInt(pixels.substring(0, pixels.length - 2));
524
554
  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
- }
555
+ var _getScaleFactor2 = getScaleFactor(),
556
+ shouldScale = _getScaleFactor2.shouldScale,
557
+ factor = _getScaleFactor2.factor;
558
+ if (shouldScale) {
559
+ return pixels / factor / unitToPixelFactors[toUnit] + '' + toUnit;
532
560
  }
533
561
  return pixels / unitToPixelFactors[toUnit] + '' + toUnit;
534
562
  }
@@ -6,6 +6,12 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
6
6
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
7
7
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
8
8
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
10
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
12
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
13
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
14
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
9
15
  describe('Resolution Specs', function () {
10
16
  var screenTypes = [{
11
17
  name: 'vga',
@@ -134,7 +140,7 @@ describe('Resolution Specs', function () {
134
140
  expect((0, _resolution.getScreenType)(WUHD)).toBe('wuhd');
135
141
  expect((0, _resolution.getScreenType)(UHD2)).toBe('uhd2');
136
142
  });
137
- test('should select screen type whose height and width are the closest to the screen', function () {
143
+ test('should select screen type whose height and width are the closest to the screen and have the same aspect ratio', function () {
138
144
  screenTypes.forEach(function (type) {
139
145
  expect((0, _resolution.getScreenType)({
140
146
  width: type.width,
@@ -149,9 +155,17 @@ describe('Resolution Specs', function () {
149
155
  height: type.height + 1
150
156
  })).toBe(type.name);
151
157
  });
152
- for (var i = 0; i < screenTypes.length - 1; i++) {
153
- var current = screenTypes[i];
154
- var next = screenTypes[i + 1];
158
+ screenTypes.slice(0, -1).map(function (current, i) {
159
+ return [current, screenTypes[i + 1]];
160
+ }).filter(function (_ref) {
161
+ var _ref2 = _slicedToArray(_ref, 2),
162
+ current = _ref2[0],
163
+ next = _ref2[1];
164
+ return current.aspectRatioName === next.aspectRatioName;
165
+ }).forEach(function (_ref3) {
166
+ var _ref4 = _slicedToArray(_ref3, 2),
167
+ current = _ref4[0],
168
+ next = _ref4[1];
155
169
  var midPoint = {
156
170
  width: (current.width + next.width) / 2,
157
171
  height: (current.height + next.height) / 2
@@ -166,7 +180,7 @@ describe('Resolution Specs', function () {
166
180
  };
167
181
  expect((0, _resolution.getScreenType)(justBeforeMid)).toBe(current.name);
168
182
  expect((0, _resolution.getScreenType)(justAfterMid)).toBe(next.name);
169
- }
183
+ });
170
184
  var firstScreenType = screenTypes.at(0);
171
185
  expect((0, _resolution.getScreenType)({
172
186
  width: 1,
@@ -220,7 +234,7 @@ describe('Resolution Specs', function () {
220
234
  expect(actualHD).toBe(expectedHD);
221
235
  });
222
236
  test('should convert pixels to units in landscape and fontSizeHandling is "scale"', function () {
223
- var closestResolution = _objectSpread({}, XGA);
237
+ var closestResolution = _objectSpread({}, HD);
224
238
  var wideResolution = {
225
239
  innerWidth: 1024,
226
240
  innerHeight: 480
@@ -266,7 +280,7 @@ describe('Resolution Specs', function () {
266
280
  (0, _resolution.init)({
267
281
  measurementNode: measurementNode
268
282
  });
269
- expect((0, _resolution.selectSrc)(src)).toBe(src.hd);
283
+ expect((0, _resolution.selectSrc)(src)).toBe(src.vga);
270
284
 
271
285
  // HD
272
286
  measurementNode = {
@@ -358,6 +372,20 @@ describe('Resolution Specs', function () {
358
372
  });
359
373
  expect((0, _resolution.selectSrc)(src)).toBe(src.uhd);
360
374
  });
375
+ test('should calculate font size with orientationHandling="scale" in portrait', function () {
376
+ _resolution.config.orientationHandling = 'scale';
377
+ var portraitWidth = 540;
378
+ var portraitHeight = 960;
379
+ (0, _resolution.init)({
380
+ measurementNode: {
381
+ innerWidth: portraitWidth,
382
+ innerHeight: portraitHeight
383
+ }
384
+ });
385
+ var expectedSize = portraitWidth * 16 / HD.height + 'px';
386
+ expect((0, _resolution.calculateFontSize)()).toBe(expectedSize);
387
+ _resolution.config.orientationHandling = 'normal';
388
+ });
361
389
  test('should calculate linearly scaled font size based on workspace bounds and current screen', function () {
362
390
  _resolution.config.linearScaling.active = true;
363
391
  screenTypes.forEach(function (type, index, arr) {
@@ -3,6 +3,12 @@
3
3
  require("@testing-library/jest-dom");
4
4
  var _react = require("@testing-library/react");
5
5
  var _useScroll = require("../useScroll");
6
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
7
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
9
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
10
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
11
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
6
12
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
13
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
14
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -128,6 +134,7 @@ describe('useScroll', function () {
128
134
  jest.useRealTimers();
129
135
  });
130
136
  test('should scale itemSize when ri.scale(1) changes from 1 to 2', function () {
137
+ var _scrollContentPropsCa;
131
138
  mockRiScale = jest.fn(function (val) {
132
139
  return val;
133
140
  });
@@ -136,13 +143,14 @@ describe('useScroll', function () {
136
143
  minHeight: 50
137
144
  };
138
145
  var mocks = createMockRefs();
146
+ var assignProperties = jest.fn();
139
147
  var props = _objectSpread(_objectSpread({
140
148
  itemRenderer: jest.fn(),
141
149
  itemSize: itemSize,
142
150
  direction: 'vertical',
143
151
  scrollMode: 'translate'
144
152
  }, mocks), {}, {
145
- assignProperties: jest.fn(),
153
+ assignProperties: assignProperties,
146
154
  horizontalScrollbar: 'auto',
147
155
  verticalScrollbar: 'auto'
148
156
  });
@@ -158,16 +166,30 @@ describe('useScroll', function () {
158
166
  (0, _react.fireEvent)(window, new Event('resize'));
159
167
  jest.runAllTimers();
160
168
  });
161
- expect(itemSize.minWidth).toBe(200);
162
- expect(itemSize.minHeight).toBe(100);
169
+
170
+ // Original props object must not be mutated
171
+ expect(itemSize.minWidth).toBe(100);
172
+ expect(itemSize.minHeight).toBe(50);
173
+
174
+ // The scaled values should be passed to scrollContentProps via assignProperties
175
+ var scrollContentPropsCall = assignProperties.mock.calls.findLast(function (_ref) {
176
+ var _ref2 = _slicedToArray(_ref, 1),
177
+ name = _ref2[0];
178
+ return name === 'scrollContentProps';
179
+ });
180
+ var passedItemSize = scrollContentPropsCall === null || scrollContentPropsCall === void 0 || (_scrollContentPropsCa = scrollContentPropsCall[1]) === null || _scrollContentPropsCa === void 0 ? void 0 : _scrollContentPropsCa.itemSize;
181
+ expect(passedItemSize === null || passedItemSize === void 0 ? void 0 : passedItemSize.minWidth).toBe(200);
182
+ expect(passedItemSize === null || passedItemSize === void 0 ? void 0 : passedItemSize.minHeight).toBe(100);
163
183
  });
164
184
  test('should scale itemSizes when ri.scale(1) changes from 1 to 2', function () {
185
+ var _scrollContentPropsCa2;
165
186
  mockRiScale = jest.fn(function (val) {
166
187
  return val;
167
188
  });
168
189
  var itemSize = 100;
169
190
  var itemSizes = [100, 100, 100, 100, 100];
170
191
  var mocks = createMockRefs();
192
+ var assignProperties = jest.fn();
171
193
  var props = _objectSpread(_objectSpread({
172
194
  itemRenderer: jest.fn(),
173
195
  itemSize: itemSize,
@@ -175,7 +197,7 @@ describe('useScroll', function () {
175
197
  direction: 'vertical',
176
198
  scrollMode: 'translate'
177
199
  }, mocks), {}, {
178
- assignProperties: jest.fn(),
200
+ assignProperties: assignProperties,
179
201
  horizontalScrollbar: 'auto',
180
202
  verticalScrollbar: 'auto'
181
203
  });
@@ -191,7 +213,18 @@ describe('useScroll', function () {
191
213
  (0, _react.fireEvent)(window, new Event('resize'));
192
214
  jest.runAllTimers();
193
215
  });
194
- expect(itemSizes[1]).toBe(200);
216
+
217
+ // Original props array must not be mutated
218
+ expect(itemSizes[1]).toBe(100);
219
+
220
+ // The scaled values should be passed to scrollContentProps via assignProperties
221
+ var scrollContentPropsCall = assignProperties.mock.calls.findLast(function (_ref3) {
222
+ var _ref4 = _slicedToArray(_ref3, 1),
223
+ name = _ref4[0];
224
+ return name === 'scrollContentProps';
225
+ });
226
+ var passedItemSizes = scrollContentPropsCall === null || scrollContentPropsCall === void 0 || (_scrollContentPropsCa2 = scrollContentPropsCall[1]) === null || _scrollContentPropsCa2 === void 0 ? void 0 : _scrollContentPropsCa2.itemSizes;
227
+ expect(passedItemSizes === null || passedItemSizes === void 0 ? void 0 : passedItemSizes[1]).toBe(200);
195
228
  });
196
229
  test('should NOT scale itemSize when ri.scale(1) remains unchanged', function () {
197
230
  mockRiScale = jest.fn(function (val) {
@@ -342,7 +375,7 @@ describe('useScroll', function () {
342
375
  expect(roundedTargetX).toEqual(121);
343
376
  expect(roundedTargetY).toEqual(121);
344
377
  });
345
- test('should round target position downwards when target is bi than current position', function () {
378
+ test('should round target position downwards when target is less than current position', function () {
346
379
  mockPlatform = {
347
380
  chrome: 132
348
381
  };
@@ -431,6 +464,7 @@ describe('useScroll', function () {
431
464
  scrollMode: 'native',
432
465
  rtl: true
433
466
  }, mocks), {}, {
467
+ addEventListeners: jest.fn(),
434
468
  assignProperties: jest.fn(),
435
469
  horizontalScrollbar: 'auto',
436
470
  verticalScrollbar: 'auto'
@@ -453,4 +487,139 @@ describe('useScroll', function () {
453
487
  expect(mocks.scrollContentHandle.current.didScroll).toHaveBeenCalledWith(50, 0);
454
488
  });
455
489
  });
490
+ describe('onKeyDown repeat handling (native scroll mode)', function () {
491
+ beforeEach(function () {
492
+ jest.useFakeTimers();
493
+ mockPlatform = {
494
+ chrome: 132
495
+ };
496
+ mockRiScale = jest.fn(function (val) {
497
+ return val;
498
+ });
499
+ });
500
+ afterEach(function () {
501
+ jest.runOnlyPendingTimers();
502
+ jest.useRealTimers();
503
+ });
504
+ function createNativeScrollProps(mocks) {
505
+ var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
506
+ return _objectSpread(_objectSpread({
507
+ direction: 'vertical',
508
+ scrollMode: 'native'
509
+ }, mocks), {}, {
510
+ assignProperties: jest.fn(),
511
+ horizontalScrollbar: 'auto',
512
+ verticalScrollbar: 'auto'
513
+ }, extra);
514
+ }
515
+ test('should forward onKeyDown event when key is not repeated', function () {
516
+ var mocks = createMockRefs();
517
+ var onKeyDown = jest.fn();
518
+ var props = createNativeScrollProps(mocks, {
519
+ onKeyDown: onKeyDown
520
+ });
521
+ (0, _react.renderHook)(function () {
522
+ return (0, _useScroll.useScrollBase)(props);
523
+ });
524
+
525
+ // eslint-disable-next-line testing-library/no-unnecessary-act
526
+ (0, _react.act)(function () {
527
+ _react.fireEvent.keyDown(mocks.scrollContainerRef.current, {
528
+ keyCode: 40,
529
+ repeat: false
530
+ });
531
+ });
532
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
533
+ });
534
+ test('should not forward onKeyDown event when arrowKey is repeated and lastInputType is arrowKey', function () {
535
+ var mocks = createMockRefs();
536
+ var onKeyDown = jest.fn();
537
+ var scrollContainerHandle = null;
538
+ var props = createNativeScrollProps(mocks, {
539
+ onKeyDown: onKeyDown,
540
+ setScrollContainerHandle: function setScrollContainerHandle(handle) {
541
+ scrollContainerHandle = handle;
542
+ }
543
+ });
544
+ (0, _react.renderHook)(function () {
545
+ return (0, _useScroll.useScrollBase)(props);
546
+ });
547
+
548
+ // Set lastInputType to arrowKey via the exposed themeScrollContainerHandle
549
+ (0, _react.act)(function () {
550
+ if (scrollContainerHandle) {
551
+ scrollContainerHandle.lastInputType = 'arrowKey';
552
+ }
553
+ });
554
+
555
+ // eslint-disable-next-line testing-library/no-unnecessary-act
556
+ (0, _react.act)(function () {
557
+ _react.fireEvent.keyDown(mocks.scrollContainerRef.current, {
558
+ keyCode: 40,
559
+ repeat: true
560
+ });
561
+ });
562
+ expect(onKeyDown).not.toHaveBeenCalled();
563
+ });
564
+ test('should not forward onKeyDown event when pageKey is repeated and lastInputType is pageKey', function () {
565
+ var mocks = createMockRefs();
566
+ var onKeyDown = jest.fn();
567
+ var scrollContainerHandle = null;
568
+ var props = createNativeScrollProps(mocks, {
569
+ onKeyDown: onKeyDown,
570
+ setScrollContainerHandle: function setScrollContainerHandle(handle) {
571
+ scrollContainerHandle = handle;
572
+ }
573
+ });
574
+ (0, _react.renderHook)(function () {
575
+ return (0, _useScroll.useScrollBase)(props);
576
+ });
577
+
578
+ // Set lastInputType to pageKey via the exposed themeScrollContainerHandle
579
+ (0, _react.act)(function () {
580
+ if (scrollContainerHandle) {
581
+ scrollContainerHandle.lastInputType = 'pageKey';
582
+ }
583
+ });
584
+
585
+ // eslint-disable-next-line testing-library/no-unnecessary-act
586
+ (0, _react.act)(function () {
587
+ _react.fireEvent.keyDown(mocks.scrollContainerRef.current, {
588
+ keyCode: 33,
589
+ repeat: true
590
+ });
591
+ });
592
+ expect(onKeyDown).not.toHaveBeenCalled();
593
+ });
594
+ test('should forward onKeyDown event when repeat is true but lastInputType is neither arrowKey nor pageKey', function () {
595
+ var mocks = createMockRefs();
596
+ var onKeyDown = jest.fn();
597
+ var scrollContainerHandle = null;
598
+ var props = createNativeScrollProps(mocks, {
599
+ onKeyDown: onKeyDown,
600
+ setScrollContainerHandle: function setScrollContainerHandle(handle) {
601
+ scrollContainerHandle = handle;
602
+ }
603
+ });
604
+ (0, _react.renderHook)(function () {
605
+ return (0, _useScroll.useScrollBase)(props);
606
+ });
607
+
608
+ // Set lastInputType to wheel (not arrowKey or pageKey)
609
+ (0, _react.act)(function () {
610
+ if (scrollContainerHandle) {
611
+ scrollContainerHandle.lastInputType = 'wheel';
612
+ }
613
+ });
614
+
615
+ // eslint-disable-next-line testing-library/no-unnecessary-act
616
+ (0, _react.act)(function () {
617
+ _react.fireEvent.keyDown(mocks.scrollContainerRef.current, {
618
+ keyCode: 40,
619
+ repeat: true
620
+ });
621
+ });
622
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
623
+ });
624
+ });
456
625
  });