UNPKG

@ccos/webos-vue

Version:

A Web-Ui Framework for Skyworth/Coocaa TV

45 lines (44 loc) 873 B
const gapValue = 48; let virtualWidth = 1920; function getVirtualWidth() { return virtualWidth; } function px2vw(width) { return 100 / virtualWidth * width; } function vw2px(vw) { return vw * virtualWidth / 100; } function getNumber(str1) { const str = str1.trim(); let i = 0; for (; i < str.length; i++) { const code = str.charCodeAt(i); if (code == 46 || code >= 48 && code <= 57) { continue; } break; } if (i == 0) { return 0; } return Number(str.substring(0, i)); } function css2px(cssStr) { const css = cssStr.toLowerCase().trim(); const numberValue = getNumber(css); if (css.endsWith("px") || css.endsWith("px;")) { return numberValue; } if (css.endsWith("vw") || css.endsWith("vw;")) { return vw2px(numberValue); } } export { css2px, gapValue, getNumber, getVirtualWidth, px2vw, vw2px };