mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 03:01:12 +00:00
fix: enforce positive rounded size in normalizeSize
This commit is contained in:
parent
cf4894b7c3
commit
ff53e1fac3
14
electron/lib/utils.js
vendored
14
electron/lib/utils.js
vendored
@ -109,14 +109,22 @@ const utils = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 兜底处理尺寸类数值,确保传入的是有限数字
|
* 兜底处理尺寸类数值,返回四舍五入后的正整数
|
||||||
* @param value
|
* @param value
|
||||||
* @param fallback
|
* @param fallback
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
normalizeSize(value, fallback) {
|
normalizeSize(value, fallback) {
|
||||||
const parsed = Number(value);
|
const toPositiveNumber = (candidate) => {
|
||||||
return Number.isFinite(parsed) ? parsed : fallback;
|
const num = Number(candidate);
|
||||||
|
return Number.isFinite(num) && num > 0 ? num : null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const primary = toPositiveNumber(value);
|
||||||
|
const secondary = toPositiveNumber(fallback);
|
||||||
|
const safeValue = primary ?? secondary ?? 1;
|
||||||
|
|
||||||
|
return Math.max(1, Math.round(safeValue));
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user