@enact/ui 5.4.3 → 5.5.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.
- package/AnnounceDecorator/Announce.js +9 -5
- package/AnnounceDecorator/AnnounceDecorator.js +5 -3
- package/AnnounceDecorator/tests/AnnounceDecorator-specs.js +4 -1
- package/AnnounceDecorator/tests/useAnnounce-specs.js +4 -1
- package/CHANGELOG.md +17 -0
- package/Cancelable/Cancelable.js +7 -0
- package/Cancelable/tests/Cancelable-specs.js +26 -0
- package/Changeable/Changeable.js +6 -0
- package/Changeable/tests/Changeable-specs.js +4 -1
- package/FloatingLayer/FloatingLayer.js +3 -0
- package/FloatingLayer/FloatingLayerDecorator.js +2 -0
- package/FloatingLayer/Scrim.js +3 -0
- package/Marquee/Marquee.module.css +1 -1
- package/Marquee/MarqueeDecorator.js +19 -3
- package/Marquee/tests/Marquee-specs.js +306 -1
- package/Marquee/useMarqueeController.js +6 -4
- package/Measurable/tests/Measurable-specs.js +6 -2
- package/Media/Media.js +5 -2
- package/Placeholder/tests/PlaceholderControllerDecorator-specs.js +4 -1
- package/Resizable/tests/Resizable-specs.js +4 -1
- package/Resizable/tests/useResize-specs.js +4 -1
- package/Routable/Route.js +5 -3
- package/Routable/Router.js +25 -16
- package/Routable/tests/Routable-specs.js +16 -0
- package/Scroller/Scroller.js +6 -5
- package/Scroller/ScrollerBasic.js +5 -5
- package/Skinnable/Skinnable.js +9 -7
- package/Skinnable/tests/Skinnable-specs.js +7 -2
- package/Skinnable/useSkins.js +6 -2
- package/Slider/PositionDecorator.js +20 -5
- package/Slider/Slider.d.ts +4 -0
- package/Slider/Slider.js +10 -0
- package/Slider/tests/Slider-specs.js +18 -0
- package/Slider/utils.js +9 -1
- package/Toggleable/Toggleable.js +4 -2
- package/Toggleable/tests/Toggleable-specs.js +4 -1
- package/Touchable/Touchable.js +6 -4
- package/Touchable/tests/Touchable-specs.js +4 -1
- package/Touchable/tests/useTouch-specs.js +4 -1
- package/Touchable/useTouch.js +7 -2
- package/Transition/Transition.js +2 -0
- package/ViewManager/TransitionGroup.js +3 -0
- package/ViewManager/View.js +2 -0
- package/ViewManager/ViewManager.js +7 -0
- package/VirtualList/VirtualList.js +7 -5
- package/VirtualList/VirtualListBasic.js +59 -8
- package/VirtualList/tests/VirtualList-native-specs.js +14 -0
- package/VirtualList/tests/VirtualList-specs.js +13 -0
- package/internal/IdProvider/IdProvider.js +2 -0
- package/internal/IdProvider/tests/IdProvider-specs.js +4 -1
- package/internal/Pure/tests/Pure-specs.js +7 -0
- package/package.json +12 -7
- package/resolution/ResolutionDecorator.js +21 -18
- package/resolution/index.d.ts +63 -4
- package/resolution/index.js +18 -2
- package/resolution/resolution.js +209 -29
- package/resolution/tests/ResolutionDecorator-specs.js +84 -4
- package/resolution/tests/resolution-specs.js +217 -599
- package/useControlledState/tests/useControlledState-specs.js +4 -1
- package/useControlledState/useControlledState.js +11 -7
- package/useScroll/Scrollbar.js +27 -24
- package/useScroll/ScrollbarTrack.js +5 -3
- package/useScroll/tests/useScroll-specs.js +402 -25
- package/useScroll/useScroll.js +117 -26
- package/useScroll/utilEvent.js +18 -0
package/resolution/resolution.js
CHANGED
|
@@ -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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
|
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.
|
|
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 =
|
|
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.
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
664
|
+
* @typedef {Object} ResolutionConfig
|
|
509
665
|
* @memberof ui/resolution
|
|
510
|
-
* @
|
|
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);
|
|
@@ -5,6 +5,16 @@ var _react = require("@testing-library/react");
|
|
|
5
5
|
var _ResolutionDecorator = _interopRequireDefault(require("../ResolutionDecorator"));
|
|
6
6
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
7
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
8
|
+
var changeTargetResolution = function changeTargetResolution(target, width, height) {
|
|
9
|
+
Object.defineProperty(target, 'clientWidth', {
|
|
10
|
+
configurable: true,
|
|
11
|
+
value: width
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(target, 'clientHeight', {
|
|
14
|
+
configurable: true,
|
|
15
|
+
value: height
|
|
16
|
+
});
|
|
17
|
+
};
|
|
8
18
|
describe('ResolutionDecorator Specs', function () {
|
|
9
19
|
test('should apply resolution classes to the wrapped component', function () {
|
|
10
20
|
var Component = (0, _ResolutionDecorator["default"])('div');
|
|
@@ -16,6 +26,23 @@ describe('ResolutionDecorator Specs', function () {
|
|
|
16
26
|
var actual = div.includes('enact-res-standard') && (div.includes('enact-orientation-landscape') || div.includes('enact-orientation-portrait'));
|
|
17
27
|
expect(actual).toBe(expected);
|
|
18
28
|
});
|
|
29
|
+
test('should not change resolution between renders if the screen stays the same', function () {
|
|
30
|
+
var Component = (0, _ResolutionDecorator["default"])('div');
|
|
31
|
+
var _render = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
32
|
+
"data-testid": "component"
|
|
33
|
+
})),
|
|
34
|
+
rerender = _render.rerender;
|
|
35
|
+
var expected = true;
|
|
36
|
+
var div = _react.screen.getByTestId('component').className;
|
|
37
|
+
var actual = div.includes('enact-res-standard') && (div.includes('enact-orientation-landscape') || div.includes('enact-orientation-portrait'));
|
|
38
|
+
expect(actual).toBe(expected);
|
|
39
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
40
|
+
"data-testid": "component"
|
|
41
|
+
}));
|
|
42
|
+
div = _react.screen.getByTestId('component').className;
|
|
43
|
+
actual = div.includes('enact-res-standard') && (div.includes('enact-orientation-landscape') || div.includes('enact-orientation-portrait'));
|
|
44
|
+
expect(actual).toBe(expected);
|
|
45
|
+
});
|
|
19
46
|
test('should allow custom screen types', function () {
|
|
20
47
|
var name = 'mhd';
|
|
21
48
|
var screens = [{
|
|
@@ -35,10 +62,63 @@ describe('ResolutionDecorator Specs', function () {
|
|
|
35
62
|
var div = _react.screen.getByTestId('component');
|
|
36
63
|
expect(div).toHaveClass('enact-res-mhd');
|
|
37
64
|
});
|
|
38
|
-
test
|
|
39
|
-
|
|
65
|
+
test('should update the resolution when the screen is resized', function () {
|
|
66
|
+
var screens = [{
|
|
67
|
+
name: 'hd',
|
|
68
|
+
pxPerRem: 16,
|
|
69
|
+
width: 1280,
|
|
70
|
+
height: 720,
|
|
71
|
+
aspectRatioName: 'hdtv',
|
|
72
|
+
base: true
|
|
73
|
+
}, {
|
|
74
|
+
name: 'fhd',
|
|
75
|
+
pxPerRem: 24,
|
|
76
|
+
width: 1920,
|
|
77
|
+
height: 1080,
|
|
78
|
+
aspectRatioName: 'hdtv'
|
|
79
|
+
}];
|
|
80
|
+
var Component = (0, _ResolutionDecorator["default"])({
|
|
81
|
+
screenTypes: screens
|
|
82
|
+
}, 'div');
|
|
83
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
84
|
+
"data-testid": "component"
|
|
85
|
+
}));
|
|
86
|
+
var div = _react.screen.getByTestId('component');
|
|
87
|
+
changeTargetResolution(div, 1920, 1080);
|
|
88
|
+
(0, _react.fireEvent)(window, new Event('resize'));
|
|
89
|
+
expect(div).toHaveClass('enact-res-fhd');
|
|
90
|
+
changeTargetResolution(div, 1280, 720);
|
|
91
|
+
(0, _react.fireEvent)(window, new Event('resize'));
|
|
92
|
+
expect(div).toHaveClass('enact-res-hd');
|
|
93
|
+
expect(div).not.toHaveClass('enact-res-fhd');
|
|
40
94
|
});
|
|
41
|
-
test
|
|
42
|
-
|
|
95
|
+
test('should not allow dynamic resolution updates when \'dynamic\' config option is false', function () {
|
|
96
|
+
var screens = [{
|
|
97
|
+
name: 'mhd',
|
|
98
|
+
pxPerRem: 36,
|
|
99
|
+
width: 1440,
|
|
100
|
+
height: 920,
|
|
101
|
+
aspectRatioName: 'hdtv',
|
|
102
|
+
base: true
|
|
103
|
+
}, {
|
|
104
|
+
name: 'fhd',
|
|
105
|
+
pxPerRem: 24,
|
|
106
|
+
width: 1920,
|
|
107
|
+
height: 1080,
|
|
108
|
+
aspectRatioName: 'hdtv'
|
|
109
|
+
}];
|
|
110
|
+
var Component = (0, _ResolutionDecorator["default"])({
|
|
111
|
+
dynamic: false,
|
|
112
|
+
screenTypes: screens
|
|
113
|
+
}, 'div');
|
|
114
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
115
|
+
"data-testid": "component"
|
|
116
|
+
}));
|
|
117
|
+
var div = _react.screen.getByTestId('component');
|
|
118
|
+
expect(div).toHaveClass('enact-res-mhd');
|
|
119
|
+
changeTargetResolution(div, 1920, 1080);
|
|
120
|
+
(0, _react.fireEvent)(window, new Event('resize'));
|
|
121
|
+
expect(div).toHaveClass('enact-res-mhd');
|
|
122
|
+
expect(div).not.toHaveClass('enact-res-fhd');
|
|
43
123
|
});
|
|
44
124
|
});
|