babel-plugin-styled-components-px2vw
Version:
Babel plugin for convert px to vw units of styled-components
7 lines (6 loc) • 958 B
TypeScript
import { Identifier, Statement } from '@babel/types';
import { IConfiguration } from './configuration';
export declare const source = "\nfunction %%px2vw%%(%%input%%, ...args) {\n if (typeof %%input%% === 'function') return %%px2vw%%(%%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%%) {\n return `${pixels}px`;\n }\n var unit = %%viewportUnit%%;\n var mul = Math.pow(10, %%unitPrecision%% + 1);\n return `${Math.round(Math.floor(pixels * 100 / %%viewportWidth%% * mul) / 10) * 10 / mul }${unit}`;\n}\n";
export declare type IPx2vwOptions = Pick<IConfiguration, 'viewportWidth' | 'unitPrecision' | 'viewportUnit' | 'minPixelValue'>;
declare const _default: (_px2vw: Identifier, config: IPx2vwOptions) => Statement;
export default _default;