UNPKG

@bytedance/mona-client-web

Version:

web for mona

100 lines 2.89 kB
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; var isPxToRpx = false; var RPX = 'rpx'; var PX = 'px'; var isVendorPrefixes = { webkit: true, moz: true, ms: true, o: true, }; var unitlessNumberMap = { lineClamp: true, lineHeight: true, fontWeight: true, order: true, opacity: true, orphans: true, tabSize: true, widows: true, zIndex: true, zoom: true, columns: true, columnCount: true, gridArea: true, gridRow: true, gridRowStart: true, gridRowEnd: true, gridRowSpan: true, gridColumn: true, gridColumnStart: true, gridColumnEnd: true, gridColumnSpan: true, animationIterationCount: true, borderImageOutset: true, borderImageSlice: true, borderImageWidth: true, boxFlex: true, boxFlexGroup: true, boxOrdinalGroup: true, flex: true, flexGrow: true, flexPositive: true, flexShrink: true, flexNegative: true, flexOrder: true, fillOpacity: true, floodOpacity: true, stopOpacity: true, strokeDasharray: true, strokeDashoffset: true, strokeMiterlimit: true, strokeOpacity: true, strokeWidth: true, }; var transformReactStyleKey = function (key) { // css3变量 if (key.startsWith('--')) { return key; } var styleValue = key.replace(/\.?([A-Z]+)/g, function (_x, y) { return '-' + y.toLowerCase(); }); if (styleValue.startsWith('-')) { var firstWord = styleValue.split('-').filter(function (s) { return s; })[0]; styleValue = styleValue.replace(/^-/, ''); if (isVendorPrefixes[firstWord]) { styleValue = '-' + styleValue; } } return styleValue; }; var setPxToRpx = function (value) { if (typeof value !== 'string') { return value; } return value.replace(/\b(\d+(\.\d+)?)px\b/g, function (_match, x) { var size = Number(x); return size % 1 === 0 ? "".concat(size).concat(RPX) : "".concat(size.toFixed(2)).concat(RPX); }); }; export var plainStyle = function (style) { return Object.keys(style) .reduce(function (res, styleKey) { var value = style[styleKey]; if (!Number.isNaN(Number(value)) && !unitlessNumberMap[styleKey]) { value = "".concat(value).concat(PX); } return __spreadArray(__spreadArray([], res, true), ["".concat(transformReactStyleKey(styleKey), ":").concat(isPxToRpx ? setPxToRpx(value) : value, ";")], false); }, []) .join(''); }; //# sourceMappingURL=utils.js.map