@enact/ui 5.5.1 → 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/CHANGELOG.md +7 -0
- package/Scroller/ScrollerBasic.js +8 -2
- package/Transition/Transition.js +207 -190
- package/Transition/Transition.module.css +0 -5
- package/Transition/tests/Transition-specs.js +220 -0
- package/VirtualList/VirtualListBasic.js +8 -2
- package/package.json +6 -11
- package/resolution/ResolutionDecorator.js +2 -1
- package/resolution/index.d.ts +6 -4
- package/resolution/resolution.js +63 -35
- package/resolution/tests/resolution-specs.js +35 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
The following is a curated list of changes in the Enact ui module, newest changes on the top.
|
|
4
4
|
|
|
5
|
+
## [5.5.2] - 2026-07-08
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- `ui/Transition` to remove static `will-change` declarations, reducing persistent GPU layer promotion and memory usage on TV targets
|
|
10
|
+
- `ui/resolution` to not resize too often for some intermediate resolutions
|
|
11
|
+
|
|
5
12
|
## [5.5.1] - 2026-06-01
|
|
6
13
|
|
|
7
14
|
### Changed
|
|
@@ -193,8 +193,14 @@ var ScrollerBasic = exports.ScrollerBasic = /*#__PURE__*/function (_Component) {
|
|
|
193
193
|
}
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
|
|
197
|
+
// Clamp the step to the remaining distance so the final frame lands exactly on the target
|
|
198
|
+
// instead of overshooting by up to the minimum step (8px), which would push a focused item
|
|
199
|
+
// anchored to the start edge (e.g. `stickTo="start"`) past that edge and clip it.
|
|
200
|
+
var remainingX = Math.abs(left - node.scrollLeft);
|
|
201
|
+
var remainingY = Math.abs(top - node.scrollTop);
|
|
202
|
+
var horizontalScrollFactor = Math.min(Math.max(remainingX * 0.1, 8), remainingX);
|
|
203
|
+
var verticalScrollFactor = Math.min(Math.max(remainingY * 0.1, 8), remainingY);
|
|
198
204
|
node.scrollBy({
|
|
199
205
|
top: directionY * verticalScrollFactor,
|
|
200
206
|
left: directionX * horizontalScrollFactor,
|
package/Transition/Transition.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports.Transition = Transition;
|
|
7
|
+
exports["default"] = exports.TransitionBase = void 0;
|
|
7
8
|
var _handle = require("@enact/core/handle");
|
|
8
9
|
var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types"));
|
|
9
10
|
var _kind = _interopRequireDefault(require("@enact/core/kind"));
|
|
@@ -14,18 +15,14 @@ var _Resizable = require("../Resizable");
|
|
|
14
15
|
var _TransitionModule = _interopRequireDefault(require("./Transition.module.css"));
|
|
15
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
17
|
var _excluded = ["css", "childRef", "children", "innerStyle"],
|
|
17
|
-
_excluded2 = ["visible"];
|
|
18
|
+
_excluded2 = ["children", "direction", "duration", "noAnimation", "onHide", "onShow", "timingFunction", "type", "visible"];
|
|
18
19
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
19
|
-
function
|
|
20
|
-
function
|
|
21
|
-
function
|
|
22
|
-
function
|
|
23
|
-
function
|
|
24
|
-
function
|
|
25
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
26
|
-
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
27
|
-
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
28
|
-
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
20
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
21
|
+
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."); }
|
|
22
|
+
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; } }
|
|
23
|
+
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; }
|
|
24
|
+
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; } }
|
|
25
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
29
26
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
30
27
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
31
28
|
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; }
|
|
@@ -52,6 +49,9 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
|
|
|
52
49
|
var formatter = function formatter(duration) {
|
|
53
50
|
return typeof duration === 'number' ? duration + 'ms' : duration;
|
|
54
51
|
};
|
|
52
|
+
|
|
53
|
+
// Shared empty style object reused when no per-type tweaks are needed.
|
|
54
|
+
var EMPTY_STYLE = {};
|
|
55
55
|
/**
|
|
56
56
|
* The stateless structure of the component.
|
|
57
57
|
*
|
|
@@ -242,14 +242,18 @@ var TransitionBase = exports.TransitionBase = (0, _kind["default"])({
|
|
|
242
242
|
direction = _ref2.direction,
|
|
243
243
|
duration = _ref2.duration,
|
|
244
244
|
type = _ref2.type;
|
|
245
|
-
var style = {};
|
|
246
245
|
if (type === 'clip' && (direction === 'left' || direction === 'right')) {
|
|
247
|
-
|
|
248
|
-
|
|
246
|
+
return {
|
|
247
|
+
width: clipWidth
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
if ((type === 'fade' || type === 'slide') && duration && !css[duration]) {
|
|
249
251
|
// If it's a number, assume it's milliseconds, if not, assume it's already a CSS duration string (like "200ms" or "2s")
|
|
250
|
-
|
|
252
|
+
return {
|
|
253
|
+
transitionDuration: formatter(duration)
|
|
254
|
+
};
|
|
251
255
|
}
|
|
252
|
-
return
|
|
256
|
+
return EMPTY_STYLE;
|
|
253
257
|
},
|
|
254
258
|
style: function style(_ref3) {
|
|
255
259
|
var clipHeight = _ref3.clipHeight,
|
|
@@ -259,20 +263,21 @@ var TransitionBase = exports.TransitionBase = (0, _kind["default"])({
|
|
|
259
263
|
type = _ref3.type,
|
|
260
264
|
visible = _ref3.visible,
|
|
261
265
|
_style = _ref3.style;
|
|
262
|
-
if (type
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if (duration && !css[duration]) {
|
|
271
|
-
// If it's a number, assume it's milliseconds, if not, assume it's already a CSS duration string (like "200ms" or "2s")
|
|
272
|
-
_style.transitionDuration = formatter(duration);
|
|
273
|
-
}
|
|
266
|
+
if (type !== 'clip') return _style;
|
|
267
|
+
var merged = _style ? _objectSpread(_objectSpread({}, _style), {}, {
|
|
268
|
+
overflow: 'hidden'
|
|
269
|
+
}) : {
|
|
270
|
+
overflow: 'hidden'
|
|
271
|
+
};
|
|
272
|
+
if (visible && (direction === 'up' || direction === 'down')) {
|
|
273
|
+
merged.height = clipHeight;
|
|
274
274
|
}
|
|
275
|
-
|
|
275
|
+
// If duration isn't a known named string, assume it is a CSS duration value
|
|
276
|
+
if (duration && !css[duration]) {
|
|
277
|
+
// If it's a number, assume it's milliseconds, if not, assume it's already a CSS duration string (like "200ms" or "2s")
|
|
278
|
+
merged.transitionDuration = formatter(duration);
|
|
279
|
+
}
|
|
280
|
+
return merged;
|
|
276
281
|
}
|
|
277
282
|
},
|
|
278
283
|
render: function render(_ref4) {
|
|
@@ -311,172 +316,192 @@ var TRANSITION_STATE = {
|
|
|
311
316
|
* A stateful component that allows for applying transitions to its child items via configurable
|
|
312
317
|
* properties and events.
|
|
313
318
|
*
|
|
314
|
-
* @
|
|
319
|
+
* @function Transition
|
|
315
320
|
* @ui
|
|
316
321
|
* @memberof ui/Transition
|
|
317
322
|
* @public
|
|
318
323
|
*/
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
var initialWidth = _this.childNode.scrollWidth;
|
|
356
|
-
if (initialHeight !== _this.state.initialHeight || initialWidth !== _this.state.initialWidth) {
|
|
357
|
-
_this.setState({
|
|
358
|
-
initialHeight: initialHeight,
|
|
359
|
-
initialWidth: initialWidth,
|
|
360
|
-
renderState: TRANSITION_STATE.READY
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
_this.childRef = function (node) {
|
|
366
|
-
_this.childNode = node;
|
|
367
|
-
};
|
|
368
|
-
(0, _util.checkPropTypes)(_this, props);
|
|
369
|
-
_this.state = {
|
|
324
|
+
function Transition(_ref5) {
|
|
325
|
+
var children = _ref5.children,
|
|
326
|
+
_ref5$direction = _ref5.direction,
|
|
327
|
+
direction = _ref5$direction === void 0 ? 'up' : _ref5$direction,
|
|
328
|
+
_ref5$duration = _ref5.duration,
|
|
329
|
+
duration = _ref5$duration === void 0 ? 'medium' : _ref5$duration,
|
|
330
|
+
_ref5$noAnimation = _ref5.noAnimation,
|
|
331
|
+
noAnimation = _ref5$noAnimation === void 0 ? false : _ref5$noAnimation,
|
|
332
|
+
onHide = _ref5.onHide,
|
|
333
|
+
onShow = _ref5.onShow,
|
|
334
|
+
_ref5$timingFunction = _ref5.timingFunction,
|
|
335
|
+
timingFunction = _ref5$timingFunction === void 0 ? 'ease-in-out' : _ref5$timingFunction,
|
|
336
|
+
_ref5$type = _ref5.type,
|
|
337
|
+
type = _ref5$type === void 0 ? 'slide' : _ref5$type,
|
|
338
|
+
_ref5$visible = _ref5.visible,
|
|
339
|
+
visible = _ref5$visible === void 0 ? true : _ref5$visible,
|
|
340
|
+
rest = _objectWithoutProperties(_ref5, _excluded2);
|
|
341
|
+
var _useState = (0, _react.useState)(function () {
|
|
342
|
+
return {
|
|
343
|
+
initialHeight: null,
|
|
344
|
+
initialWidth: null,
|
|
345
|
+
renderState: visible ? TRANSITION_STATE.READY : TRANSITION_STATE.INIT
|
|
346
|
+
};
|
|
347
|
+
}),
|
|
348
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
349
|
+
state = _useState2[0],
|
|
350
|
+
setState = _useState2[1];
|
|
351
|
+
var prevVisibleRef = (0, _react.useRef)(visible);
|
|
352
|
+
|
|
353
|
+
// Adjust state during render when `visible` flips on. The functional equivalent of the
|
|
354
|
+
// class's getDerivedStateFromProps. Reading/writing the ref here is intentional.
|
|
355
|
+
// https://react.dev/reference/react/useState#storing-information-from-previous-renders
|
|
356
|
+
if (!prevVisibleRef.current && visible) {
|
|
357
|
+
// eslint-disable-line react-hooks/refs
|
|
358
|
+
prevVisibleRef.current = true;
|
|
359
|
+
setState({
|
|
370
360
|
initialHeight: null,
|
|
371
361
|
initialWidth: null,
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
};
|
|
375
|
-
_this.resizeRegistry = null;
|
|
376
|
-
return _this;
|
|
362
|
+
renderState: TRANSITION_STATE.MEASURE
|
|
363
|
+
});
|
|
377
364
|
}
|
|
378
|
-
_inherits(Transition, _Component);
|
|
379
|
-
return _createClass(Transition, [{
|
|
380
|
-
key: "componentDidMount",
|
|
381
|
-
value: function componentDidMount() {
|
|
382
|
-
if (!this.props.visible) {
|
|
383
|
-
this.measuringJob.idle();
|
|
384
|
-
} else {
|
|
385
|
-
this.measureInner();
|
|
386
|
-
}
|
|
387
|
-
if (this.context && typeof this.context === 'function') {
|
|
388
|
-
this.resizeRegistry = this.context(this.handleResize);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}, {
|
|
392
|
-
key: "shouldComponentUpdate",
|
|
393
|
-
value: function shouldComponentUpdate(nextProps, nextState) {
|
|
394
|
-
// Don't update if only updating the height and we're not visible
|
|
395
|
-
return this.state.initialHeight === nextState.initialHeight || this.props.visible || nextProps.visible;
|
|
396
|
-
}
|
|
397
|
-
}, {
|
|
398
|
-
key: "componentDidUpdate",
|
|
399
|
-
value: function componentDidUpdate(prevProps, prevState) {
|
|
400
|
-
var _this$props = this.props,
|
|
401
|
-
noAnimation = _this$props.noAnimation,
|
|
402
|
-
visible = _this$props.visible;
|
|
403
|
-
var _this$state = this.state,
|
|
404
|
-
initialHeight = _this$state.initialHeight,
|
|
405
|
-
renderState = _this$state.renderState;
|
|
406
|
-
(0, _util.checkPropTypes)(this, this.props, prevProps);
|
|
407
|
-
if (this.state.renderState === TRANSITION_STATE.MEASURE) {
|
|
408
|
-
this.measuringJob.stop();
|
|
409
|
-
}
|
|
410
365
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
366
|
+
// Latest props for handlers that fire asynchronously (transitionend, observer callbacks)
|
|
367
|
+
var currentProps = _objectSpread({
|
|
368
|
+
children: children,
|
|
369
|
+
direction: direction,
|
|
370
|
+
duration: duration,
|
|
371
|
+
noAnimation: noAnimation,
|
|
372
|
+
onHide: onHide,
|
|
373
|
+
onShow: onShow,
|
|
374
|
+
timingFunction: timingFunction,
|
|
375
|
+
type: type,
|
|
376
|
+
visible: visible
|
|
377
|
+
}, rest);
|
|
378
|
+
(0, _util.checkPropTypes)(Transition, currentProps);
|
|
379
|
+
var propsRef = (0, _react.useRef)();
|
|
380
|
+
propsRef.current = currentProps; // eslint-disable-line react-hooks/refs
|
|
381
|
+
|
|
382
|
+
var childNodeRef = (0, _react.useRef)(null);
|
|
383
|
+
var measuringJobRef = (0, _react.useRef)(null);
|
|
384
|
+
if (measuringJobRef.current == null) {
|
|
385
|
+
measuringJobRef.current = new _util.Job(function () {
|
|
386
|
+
setState(function (prev) {
|
|
387
|
+
return prev.renderState === TRANSITION_STATE.MEASURE ? prev : _objectSpread(_objectSpread({}, prev), {}, {
|
|
388
|
+
renderState: TRANSITION_STATE.MEASURE
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
var measureInner = (0, _react.useCallback)(function () {
|
|
394
|
+
var node = childNodeRef.current;
|
|
395
|
+
if (!node) return;
|
|
396
|
+
var initialHeight = node.scrollHeight;
|
|
397
|
+
var initialWidth = node.scrollWidth;
|
|
398
|
+
setState(function (prev) {
|
|
399
|
+
if (prev.initialHeight === initialHeight && prev.initialWidth === initialWidth && prev.renderState === TRANSITION_STATE.READY) {
|
|
400
|
+
return prev;
|
|
422
401
|
}
|
|
402
|
+
return {
|
|
403
|
+
initialHeight: initialHeight,
|
|
404
|
+
initialWidth: initialWidth,
|
|
405
|
+
renderState: TRANSITION_STATE.READY
|
|
406
|
+
};
|
|
407
|
+
});
|
|
408
|
+
}, []);
|
|
409
|
+
var childRef = (0, _react.useCallback)(function (node) {
|
|
410
|
+
childNodeRef.current = node;
|
|
411
|
+
}, []);
|
|
412
|
+
|
|
413
|
+
// Measurement effect — covers MEASURE → READY commits and the resize-driven
|
|
414
|
+
// re-measure path (handleResize nulls initialHeight, this re-fires).
|
|
415
|
+
(0, _react.useLayoutEffect)(function () {
|
|
416
|
+
if (state.renderState === TRANSITION_STATE.MEASURE) {
|
|
417
|
+
measuringJobRef.current.stop();
|
|
418
|
+
measureInner();
|
|
419
|
+
} else if (visible && state.initialHeight == null) {
|
|
420
|
+
// Component should be visible but doesn't have a height — measure now.
|
|
421
|
+
measureInner();
|
|
423
422
|
}
|
|
424
|
-
},
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
this.resizeRegistry.unregister();
|
|
430
|
-
}
|
|
423
|
+
}, [state.renderState, state.initialHeight, visible, measureInner]);
|
|
424
|
+
(0, _react.useEffect)(function () {
|
|
425
|
+
var job = measuringJobRef.current;
|
|
426
|
+
if (!propsRef.current.visible) {
|
|
427
|
+
job.idle();
|
|
431
428
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
visible = _this$props2.visible,
|
|
437
|
-
props = _objectWithoutProperties(_this$props2, _excluded2);
|
|
438
|
-
delete props.onHide;
|
|
439
|
-
delete props.onShow;
|
|
440
|
-
delete props.textSize;
|
|
441
|
-
switch (this.state.renderState) {
|
|
442
|
-
// If we are deferring children, don't render any
|
|
443
|
-
case TRANSITION_STATE.INIT:
|
|
444
|
-
return null;
|
|
429
|
+
return function () {
|
|
430
|
+
return job.stop();
|
|
431
|
+
};
|
|
432
|
+
}, []);
|
|
445
433
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
434
|
+
// ResizeContext registration — the context value is itself the register fn.
|
|
435
|
+
var resizeRegister = (0, _react.use)(_Resizable.ResizeContext);
|
|
436
|
+
var handleResize = (0, _react.useCallback)(function () {
|
|
437
|
+
// Null initialHeight so the next layout commit re-measures in a separate tick.
|
|
438
|
+
// the useLayoutEffect above re-runs when state.initialHeight transitions to null.
|
|
439
|
+
setState(function (prev) {
|
|
440
|
+
return prev.initialHeight == null ? prev : _objectSpread(_objectSpread({}, prev), {}, {
|
|
441
|
+
initialHeight: null
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
}, []);
|
|
445
|
+
(0, _react.useEffect)(function () {
|
|
446
|
+
if (typeof resizeRegister !== 'function') return;
|
|
447
|
+
var registry = resizeRegister(handleResize);
|
|
448
|
+
return function () {
|
|
449
|
+
if (registry) registry.unregister();
|
|
450
|
+
};
|
|
451
|
+
}, [resizeRegister, handleResize]);
|
|
452
|
+
var prevVisibleForEffectRef = (0, _react.useRef)(visible);
|
|
453
|
+
(0, _react.useEffect)(function () {
|
|
454
|
+
var prev = prevVisibleForEffectRef.current;
|
|
455
|
+
prevVisibleForEffectRef.current = visible;
|
|
456
|
+
if (!noAnimation || prev === visible) return;
|
|
457
|
+
if (!prev && visible) {
|
|
458
|
+
(0, _handle.forwardCustom)('onShow')(null, propsRef.current);
|
|
459
|
+
} else if (prev && !visible) {
|
|
460
|
+
(0, _handle.forwardCustom)('onHide')(null, propsRef.current);
|
|
463
461
|
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
return null;
|
|
462
|
+
}, [visible, noAnimation]);
|
|
463
|
+
var handleTransitionEnd = (0, _react.useCallback)(function (ev) {
|
|
464
|
+
(0, _handle.forward)('onTransitionEnd', ev, propsRef.current);
|
|
465
|
+
if (ev.target === childNodeRef.current) {
|
|
466
|
+
var eventName = propsRef.current.visible ? 'onShow' : 'onHide';
|
|
467
|
+
(0, _handle.forward)(eventName, {
|
|
468
|
+
type: eventName,
|
|
469
|
+
currentTarget: ev.currentTarget
|
|
470
|
+
}, propsRef.current);
|
|
476
471
|
}
|
|
477
|
-
}]);
|
|
478
|
-
|
|
479
|
-
|
|
472
|
+
}, []);
|
|
473
|
+
|
|
474
|
+
// If we are deferring children, don't render any.
|
|
475
|
+
if (state.renderState === TRANSITION_STATE.INIT) {
|
|
476
|
+
return null;
|
|
477
|
+
}
|
|
478
|
+
var childProps = _objectSpread(_objectSpread({}, rest), {}, {
|
|
479
|
+
children: children,
|
|
480
|
+
direction: direction,
|
|
481
|
+
duration: duration,
|
|
482
|
+
noAnimation: noAnimation,
|
|
483
|
+
timingFunction: timingFunction,
|
|
484
|
+
type: type
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
// If we're transitioning to visible but don't have a measurement yet, create
|
|
488
|
+
// the transition container with its children so we can measure. Measuring
|
|
489
|
+
// will cause a state change to trigger the animation.
|
|
490
|
+
if (state.renderState === TRANSITION_STATE.MEASURE) {
|
|
491
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(TransitionBase, _objectSpread(_objectSpread({}, childProps), {}, {
|
|
492
|
+
childRef: childRef,
|
|
493
|
+
visible: false
|
|
494
|
+
}));
|
|
495
|
+
}
|
|
496
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(TransitionBase, _objectSpread(_objectSpread({}, childProps), {}, {
|
|
497
|
+
childRef: childRef,
|
|
498
|
+
visible: visible,
|
|
499
|
+
clipHeight: state.initialHeight,
|
|
500
|
+
clipWidth: state.initialWidth,
|
|
501
|
+
onTransitionEnd: handleTransitionEnd
|
|
502
|
+
}));
|
|
503
|
+
}
|
|
504
|
+
Transition.displayName = 'Transition';
|
|
480
505
|
Transition.propTypes = /** @lends ui/Transition.Transition.prototype */{
|
|
481
506
|
/**
|
|
482
507
|
* The node to be transitioned.
|
|
@@ -578,12 +603,4 @@ Transition.propTypes = /** @lends ui/Transition.Transition.prototype */{
|
|
|
578
603
|
*/
|
|
579
604
|
visible: _propTypes2["default"].bool
|
|
580
605
|
};
|
|
581
|
-
Transition.defaultProps = {
|
|
582
|
-
direction: 'up',
|
|
583
|
-
duration: 'medium',
|
|
584
|
-
noAnimation: false,
|
|
585
|
-
timingFunction: 'ease-in-out',
|
|
586
|
-
type: 'slide',
|
|
587
|
-
visible: true
|
|
588
|
-
};
|
|
589
606
|
var _default = exports["default"] = Transition;
|
|
@@ -6,11 +6,9 @@
|
|
|
6
6
|
}
|
|
7
7
|
.transition.slide .inner {
|
|
8
8
|
transition-property: transform;
|
|
9
|
-
will-change: transform;
|
|
10
9
|
}
|
|
11
10
|
.transition.fade .inner {
|
|
12
11
|
transition-property: opacity;
|
|
13
|
-
will-change: opacity;
|
|
14
12
|
}
|
|
15
13
|
.transition.shown.slide .inner {
|
|
16
14
|
transform: translate3d(0, 0, 0);
|
|
@@ -51,12 +49,10 @@
|
|
|
51
49
|
.transition.clip.up,
|
|
52
50
|
.transition.clip.down {
|
|
53
51
|
transition-property: height;
|
|
54
|
-
will-change: height;
|
|
55
52
|
}
|
|
56
53
|
.transition.clip.right,
|
|
57
54
|
.transition.clip.left {
|
|
58
55
|
transition-property: max-width;
|
|
59
|
-
will-change: max-width;
|
|
60
56
|
}
|
|
61
57
|
.transition.clip.right .inner,
|
|
62
58
|
.transition.clip.left .inner {
|
|
@@ -67,7 +63,6 @@
|
|
|
67
63
|
}
|
|
68
64
|
.transition.clip.down .inner {
|
|
69
65
|
transition-property: transform;
|
|
70
|
-
will-change: transform;
|
|
71
66
|
}
|
|
72
67
|
.transition.clip.down.shown .inner {
|
|
73
68
|
transform: translate(0, 0);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require("@testing-library/jest-dom");
|
|
4
4
|
var _react = require("@testing-library/react");
|
|
5
|
+
var _Resizable = require("../../Resizable");
|
|
5
6
|
var _Transition = _interopRequireWildcard(require("../Transition"));
|
|
6
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
8
|
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); }
|
|
@@ -172,4 +173,223 @@ describe('Transition Specs', function () {
|
|
|
172
173
|
});
|
|
173
174
|
});
|
|
174
175
|
});
|
|
176
|
+
|
|
177
|
+
// type="clip"
|
|
178
|
+
test('should set inner width when type="clip" and direction="right"', function () {
|
|
179
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition.TransitionBase, {
|
|
180
|
+
clipWidth: 100,
|
|
181
|
+
"data-testid": "transition",
|
|
182
|
+
direction: "right",
|
|
183
|
+
type: "clip",
|
|
184
|
+
children: "Body"
|
|
185
|
+
}));
|
|
186
|
+
var expected = {
|
|
187
|
+
width: '100px'
|
|
188
|
+
};
|
|
189
|
+
var actual = _react.screen.getByText('Body');
|
|
190
|
+
expect(actual).toHaveStyle(expected);
|
|
191
|
+
});
|
|
192
|
+
test('should apply overflow hidden on root when type="clip"', function () {
|
|
193
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition.TransitionBase, {
|
|
194
|
+
clipWidth: 100,
|
|
195
|
+
"data-testid": "transition",
|
|
196
|
+
direction: "right",
|
|
197
|
+
type: "clip",
|
|
198
|
+
children: "Body"
|
|
199
|
+
}));
|
|
200
|
+
var expected = {
|
|
201
|
+
overflow: 'hidden'
|
|
202
|
+
};
|
|
203
|
+
var actual = _react.screen.getByTestId('transition');
|
|
204
|
+
expect(actual).toHaveStyle(expected);
|
|
205
|
+
});
|
|
206
|
+
test('should set height on root when type="clip", direction="up", and visible', function () {
|
|
207
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition.TransitionBase, {
|
|
208
|
+
clipHeight: 50,
|
|
209
|
+
"data-testid": "transition",
|
|
210
|
+
direction: "up",
|
|
211
|
+
type: "clip",
|
|
212
|
+
children: "Body"
|
|
213
|
+
}));
|
|
214
|
+
var expected = {
|
|
215
|
+
height: '50px'
|
|
216
|
+
};
|
|
217
|
+
var actual = _react.screen.getByTestId('transition');
|
|
218
|
+
expect(actual).toHaveStyle(expected);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// Custom duration paths.
|
|
222
|
+
test('should set transitionDuration on inner style for a custom duration', function () {
|
|
223
|
+
var actual = _Transition.TransitionBase.computed.innerStyle({
|
|
224
|
+
css: {},
|
|
225
|
+
duration: 200,
|
|
226
|
+
type: 'slide'
|
|
227
|
+
});
|
|
228
|
+
var expected = {
|
|
229
|
+
transitionDuration: '200ms'
|
|
230
|
+
};
|
|
231
|
+
expect(actual).toEqual(expected);
|
|
232
|
+
});
|
|
233
|
+
test('should set transitionDuration on style for type="clip" with a custom duration', function () {
|
|
234
|
+
var actual = _Transition.TransitionBase.computed.style({
|
|
235
|
+
clipHeight: 10,
|
|
236
|
+
css: {},
|
|
237
|
+
direction: 'up',
|
|
238
|
+
duration: '3s',
|
|
239
|
+
type: 'clip',
|
|
240
|
+
visible: true
|
|
241
|
+
});
|
|
242
|
+
var expected = {
|
|
243
|
+
height: 10,
|
|
244
|
+
overflow: 'hidden',
|
|
245
|
+
transitionDuration: '3s'
|
|
246
|
+
};
|
|
247
|
+
expect(actual).toMatchObject(expected);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// transitionend handling
|
|
251
|
+
test('should fire \'onShow\' on transitionend when visible', function () {
|
|
252
|
+
var handleShow = jest.fn();
|
|
253
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
254
|
+
onShow: handleShow,
|
|
255
|
+
visible: true,
|
|
256
|
+
children: "Body"
|
|
257
|
+
}));
|
|
258
|
+
_react.fireEvent.transitionEnd(_react.screen.getByText('Body'));
|
|
259
|
+
var expected = 1;
|
|
260
|
+
expect(handleShow).toHaveBeenCalledTimes(expected);
|
|
261
|
+
});
|
|
262
|
+
test('should fire \'onHide\' on transitionend when not visible', function () {
|
|
263
|
+
var handleHide = jest.fn();
|
|
264
|
+
var _render3 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
265
|
+
onHide: handleHide,
|
|
266
|
+
visible: true,
|
|
267
|
+
children: "Body"
|
|
268
|
+
})),
|
|
269
|
+
rerender = _render3.rerender;
|
|
270
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
271
|
+
onHide: handleHide,
|
|
272
|
+
visible: false,
|
|
273
|
+
children: "Body"
|
|
274
|
+
}));
|
|
275
|
+
_react.fireEvent.transitionEnd(_react.screen.getByText('Body'));
|
|
276
|
+
var expected = 1;
|
|
277
|
+
expect(handleHide).toHaveBeenCalledTimes(expected);
|
|
278
|
+
});
|
|
279
|
+
test('should forward \'onTransitionEnd\'', function () {
|
|
280
|
+
var handleTransitionEnd = jest.fn();
|
|
281
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
282
|
+
onTransitionEnd: handleTransitionEnd,
|
|
283
|
+
visible: true,
|
|
284
|
+
children: "Body"
|
|
285
|
+
}));
|
|
286
|
+
_react.fireEvent.transitionEnd(_react.screen.getByText('Body'));
|
|
287
|
+
var expected = 1;
|
|
288
|
+
expect(handleTransitionEnd).toHaveBeenCalledTimes(expected);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// The main accordion/header path: animated clip transition driven by `transitionend`
|
|
292
|
+
// across a full show → hide → show cycle
|
|
293
|
+
test('should fire \'onHide\' then \'onShow\' over a visible true → false → true cycle with type="clip"', function () {
|
|
294
|
+
var handleHide = jest.fn();
|
|
295
|
+
var handleShow = jest.fn();
|
|
296
|
+
var _render4 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
297
|
+
direction: "up",
|
|
298
|
+
onHide: handleHide,
|
|
299
|
+
onShow: handleShow,
|
|
300
|
+
type: "clip",
|
|
301
|
+
visible: true,
|
|
302
|
+
children: "Body"
|
|
303
|
+
})),
|
|
304
|
+
rerender = _render4.rerender;
|
|
305
|
+
|
|
306
|
+
// true → false: the hide animation runs and completes.
|
|
307
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
308
|
+
direction: "up",
|
|
309
|
+
onHide: handleHide,
|
|
310
|
+
onShow: handleShow,
|
|
311
|
+
type: "clip",
|
|
312
|
+
visible: false,
|
|
313
|
+
children: "Body"
|
|
314
|
+
}));
|
|
315
|
+
_react.fireEvent.transitionEnd(_react.screen.getByText('Body'));
|
|
316
|
+
expect(handleHide).toHaveBeenCalledTimes(1);
|
|
317
|
+
expect(handleShow).not.toHaveBeenCalled();
|
|
318
|
+
|
|
319
|
+
// false → true: the show animation runs and completes.
|
|
320
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
321
|
+
direction: "up",
|
|
322
|
+
onHide: handleHide,
|
|
323
|
+
onShow: handleShow,
|
|
324
|
+
type: "clip",
|
|
325
|
+
visible: true,
|
|
326
|
+
children: "Body"
|
|
327
|
+
}));
|
|
328
|
+
_react.fireEvent.transitionEnd(_react.screen.getByText('Body'));
|
|
329
|
+
expect(handleShow).toHaveBeenCalledTimes(1);
|
|
330
|
+
expect(handleHide).toHaveBeenCalledTimes(1);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// ResizeContext registration
|
|
334
|
+
test('should register with ResizeContext and unregister on unmount', function () {
|
|
335
|
+
var unregister = jest.fn();
|
|
336
|
+
var register = jest.fn(function () {
|
|
337
|
+
return {
|
|
338
|
+
unregister: unregister
|
|
339
|
+
};
|
|
340
|
+
});
|
|
341
|
+
var _render5 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Resizable.ResizeContext.Provider, {
|
|
342
|
+
value: register,
|
|
343
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
344
|
+
visible: true,
|
|
345
|
+
children: "Body"
|
|
346
|
+
})
|
|
347
|
+
})),
|
|
348
|
+
unmount = _render5.unmount;
|
|
349
|
+
expect(register).toHaveBeenCalled();
|
|
350
|
+
unmount();
|
|
351
|
+
expect(unregister).toHaveBeenCalled();
|
|
352
|
+
});
|
|
353
|
+
test('should re-measure when notified through ResizeContext', function () {
|
|
354
|
+
var resizeHandler;
|
|
355
|
+
var register = jest.fn(function (handler) {
|
|
356
|
+
resizeHandler = handler;
|
|
357
|
+
return {
|
|
358
|
+
unregister: jest.fn()
|
|
359
|
+
};
|
|
360
|
+
});
|
|
361
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Resizable.ResizeContext.Provider, {
|
|
362
|
+
value: register,
|
|
363
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
364
|
+
visible: true,
|
|
365
|
+
children: "Body"
|
|
366
|
+
})
|
|
367
|
+
}));
|
|
368
|
+
|
|
369
|
+
// Invoking the registered handler nulls the cached measurement and triggers a re-measure on the next layout commit.
|
|
370
|
+
(0, _react.act)(function () {
|
|
371
|
+
resizeHandler();
|
|
372
|
+
});
|
|
373
|
+
expect(register).toHaveBeenCalled();
|
|
374
|
+
});
|
|
375
|
+
test('should defer rendering then pre-measure when mounted with visible={false}', function () {
|
|
376
|
+
jest.useFakeTimers();
|
|
377
|
+
try {
|
|
378
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
379
|
+
visible: false,
|
|
380
|
+
children: "Body"
|
|
381
|
+
}));
|
|
382
|
+
|
|
383
|
+
// INIT state — children are not rendered yet.
|
|
384
|
+
expect(_react.screen.queryByText('Body')).toBeNull();
|
|
385
|
+
|
|
386
|
+
// The idle Job moves the state to MEASURE, rendering the (hidden) children so they can be measured.
|
|
387
|
+
(0, _react.act)(function () {
|
|
388
|
+
jest.runOnlyPendingTimers();
|
|
389
|
+
});
|
|
390
|
+
expect(_react.screen.getByText('Body')).toBeInTheDocument();
|
|
391
|
+
} finally {
|
|
392
|
+
jest.useRealTimers();
|
|
393
|
+
}
|
|
394
|
+
});
|
|
175
395
|
});
|
|
@@ -840,9 +840,15 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
840
840
|
// a smooth scroll if the timeout occurs first.
|
|
841
841
|
var _animateScroll = function animateScroll(currentTime) {
|
|
842
842
|
var elapsed = (currentTime - startTime) / 500;
|
|
843
|
+
|
|
844
|
+
// Clamp each step to the remaining distance so the final frame lands exactly on the target
|
|
845
|
+
// instead of overshooting by up to `scrollFactor`. Overshooting would push a focused item
|
|
846
|
+
// anchored to the start edge (e.g. `stickTo="start"`) past that edge and clip it.
|
|
847
|
+
var stepX = directionX === 0 ? 0 : directionX * Math.min(scrollFactor, Math.abs(left - node.scrollLeft));
|
|
848
|
+
var stepY = directionY === 0 ? 0 : directionY * Math.min(scrollFactor, Math.abs(top - node.scrollTop));
|
|
843
849
|
node.scrollBy({
|
|
844
|
-
top:
|
|
845
|
-
left:
|
|
850
|
+
top: stepY,
|
|
851
|
+
left: stepX,
|
|
846
852
|
behavior: 'instant'
|
|
847
853
|
});
|
|
848
854
|
_this8.scrollAnimationId = window.requestAnimationFrame(_animateScroll);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/ui",
|
|
3
|
-
"version": "5.5.
|
|
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.
|
|
36
|
-
"@enact/i18n": "^5.5.
|
|
35
|
+
"@enact/core": "^5.5.2",
|
|
36
|
+
"@enact/i18n": "^5.5.2",
|
|
37
37
|
"classnames": "^2.5.1",
|
|
38
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.
|
|
43
|
-
"react-dom": "^19.2.
|
|
44
|
-
"react-is": "^19.2.
|
|
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
|
package/resolution/index.d.ts
CHANGED
|
@@ -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.
|
|
79
|
-
|
|
80
|
-
|
|
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
|
/**
|
package/resolution/resolution.js
CHANGED
|
@@ -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
|
|
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 =
|
|
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
|
-
*
|
|
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
|
|
148
|
-
var
|
|
149
|
-
|
|
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
|
|
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
|
|
155
|
-
var
|
|
156
|
-
return
|
|
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.
|
|
298
|
-
*
|
|
299
|
-
*
|
|
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 =
|
|
361
|
+
var shouldScaleFontSize = getShouldScale(scrObj);
|
|
327
362
|
var size;
|
|
328
|
-
if (
|
|
329
|
-
size =
|
|
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
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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({},
|
|
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.
|
|
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) {
|