UNPKG

tdesign-mobile-vue

Version:
128 lines (124 loc) 5.35 kB
/** * tdesign v1.7.0 * (c) 2024 TDesign Group * @license MIT */ import { isBrowser } from '../util.js'; import '@babel/runtime/helpers/slicedToArray'; import 'lodash/isNumber'; import '../../config.js'; var TimeDataUnit = { DD: "\u5929", HH: "\u65F6", mm: "\u5206", ss: "\u79D2", SSS: "\u6BEB\u79D2" }; var getRemainTimes = function getRemainTimes(time) { if (!time) { return { days: 0, hours: 0, minutes: 0, seconds: 0, milliseconds: 0 }; } var stime = Math.floor(time / 1e3); return { days: Math.floor(stime / 3600 / 24), hours: Math.floor(stime / 3600 % 24), minutes: Math.floor(stime / 60 % 60), seconds: stime % 60, milliseconds: time % 1e3 }; }; var fillZero = function fillZero(num) { var isMillieconds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; if (isMillieconds) { if (num >= 100) { return num; } return num >= 10 ? "0".concat(num) : "00".concat(num); } return num >= 10 ? num : "0".concat(num); }; var getMark = function getMark(format, type) { var _format$split, _format$split$split; return format === null || format === void 0 || (_format$split = format.split) === null || _format$split === void 0 || (_format$split = _format$split.call(format, type)) === null || _format$split === void 0 || (_format$split = _format$split[1]) === null || _format$split === void 0 || (_format$split$split = _format$split.split) === null || _format$split$split === void 0 || (_format$split$split = _format$split$split.call(_format$split, "")) === null || _format$split$split === void 0 ? void 0 : _format$split$split[0]; }; var getShowTimes = function getShowTimes(times, format) { var _ref, _ref$toUpperCase, _format, _format2, _format3, _format4, _format5; var millisecond = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; var splitWithUnit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; format = (_ref = format || "DD:HH:mm:ss") === null || _ref === void 0 || (_ref$toUpperCase = _ref.toUpperCase) === null || _ref$toUpperCase === void 0 ? void 0 : _ref$toUpperCase.call(_ref); millisecond && !format.includes(":SSS") && (format = format.concat(":SSS")); var showTimes = []; if (((_format = format) === null || _format === void 0 ? void 0 : _format.indexOf("DD")) > -1) { showTimes === null || showTimes === void 0 || showTimes.push({ mark: getMark(format, "DD"), value: fillZero(times === null || times === void 0 ? void 0 : times.days) }); } if (((_format2 = format) === null || _format2 === void 0 ? void 0 : _format2.indexOf("HH")) > -1) { showTimes === null || showTimes === void 0 || showTimes.push({ mark: splitWithUnit ? TimeDataUnit.HH : getMark(format, "HH"), value: fillZero(times === null || times === void 0 ? void 0 : times.hours) }); } if (((_format3 = format) === null || _format3 === void 0 ? void 0 : _format3.indexOf("MM")) > -1) { showTimes === null || showTimes === void 0 || showTimes.push({ mark: splitWithUnit ? TimeDataUnit.mm : getMark(format, "MM"), value: fillZero(times === null || times === void 0 ? void 0 : times.minutes) }); } if (((_format4 = format) === null || _format4 === void 0 ? void 0 : _format4.indexOf("SS")) > -1) { showTimes === null || showTimes === void 0 || showTimes.push({ mark: splitWithUnit ? TimeDataUnit.ss : getMark(format, "SS"), value: fillZero(times === null || times === void 0 ? void 0 : times.seconds) }); } if (((_format5 = format) === null || _format5 === void 0 ? void 0 : _format5.indexOf("SSS")) > -1 || millisecond) { showTimes === null || showTimes === void 0 || showTimes.push({ mark: splitWithUnit ? TimeDataUnit.SSS : getMark(format, "SSS"), value: fillZero(times === null || times === void 0 ? void 0 : times.milliseconds, true) }); } return showTimes; }; var getScreenFps = function (_ref2, _ref2$find) { if (!isBrowser) return; var _window = window, requestAnimationFrame = _window.requestAnimationFrame, mozRequestAnimationFrame = _window.mozRequestAnimationFrame, webkitRequestAnimationFrame = _window.webkitRequestAnimationFrame; var nextFrame = (_ref2 = [requestAnimationFrame, mozRequestAnimationFrame, webkitRequestAnimationFrame]) === null || _ref2 === void 0 || (_ref2$find = _ref2.find) === null || _ref2$find === void 0 ? void 0 : _ref2$find.call(_ref2, function (fn) { return fn; }); if (!nextFrame) { console.error("requestAnimationFrame is not supported!"); return; } return function () { var targetCount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 50; if (targetCount < 1) { return; } var count = 0; var beginDate = Date.now(); return new Promise(function (resolve) { (function log() { nextFrame === null || nextFrame === void 0 || nextFrame(function () { if (++count >= targetCount) { var diffDate = Date.now() - beginDate; var fps = count / diffDate * 1e3; return resolve(fps); } log(); }); })(); }); }; }(); export { TimeDataUnit, fillZero, getMark, getRemainTimes, getScreenFps, getShowTimes }; //# sourceMappingURL=utils.js.map