UNPKG

babel-plugin-styled-components-px2rem

Version:
20 lines 1.39 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var types_1 = require("@babel/types"); var template_1 = __importDefault(require("@babel/template")); var source = "function %%px2rem%%(%%input%%, ...args) {\n if (typeof %%input%% === 'function') return %%px2rem%%(%%input%%(...args), ...args);\n var value = typeof %%input%% === 'string' ? parseFloat(%%input%%) : typeof %%input%% === 'number' ? %%input%% : 0;\n var pixels = (Number.isNaN(value) ? 0 : value);\n if (Math.abs(pixels) < %%minPixelValue%%) return pixels + 'px';\n var mul = Math.pow(10, %%unitPrecision%% + 1);\n return ((Math.round(Math.floor(((pixels * %%multiplier%%) / %%rootValue%%) * mul) / 10) * 10) / mul) + 'rem';\n}"; exports.default = (function (_px2rem, config) { var template = template_1.default.statement(source); return template({ input: types_1.identifier('input'), px2rem: _px2rem, rootValue: types_1.numericLiteral(config.rootValue), unitPrecision: types_1.numericLiteral(config.unitPrecision), multiplier: types_1.numericLiteral(config.multiplier), minPixelValue: types_1.numericLiteral(config.minPixelValue), }); }); //# sourceMappingURL=createPx2rem.js.map