import { Comment, Input, Result, Root } from "postcss"; //#region src/types.d.ts /** * Supported transformation method types. * * @example * const methods: PxTransformMethod[] = ['platform', 'size'] */ type PxTransformMethod = 'platform' | 'size'; /** * Supported target platforms. * * @example * const platform: PxTransformPlatform = 'weapp' */ type PxTransformPlatform = 'weapp' | 'h5' | 'rn' | 'quickapp' | 'harmony'; /** * Target unit after conversion. * * @example * const unit: PxTransformTargetUnit = 'rpx' */ type PxTransformTargetUnit = 'rpx' | 'rem' | 'px' | 'vw' | 'vmin'; /** * Design width can be a number or per-file resolver. * * @default 750 * @example * const designWidth: DesignWidth = (input) => * input.file?.includes('tablet') ? 1024 : 750 */ type DesignWidth = number | ((input: Input) => number); /** * Device ratio mapping for different design widths. * * @example * const deviceRatio: PxTransformDeviceRatio = { 750: 1, 375: 2 } */ interface PxTransformDeviceRatio { [designWidth: number]: number; } /** * Options for postcss-pxtrans. * * Defaults: * - platform: 'weapp' * - designWidth: 750 * - deviceRatio: { 375: 2, 640: 1.17, 750: 1, 828: 0.905 } * - methods: ['platform', 'size'] * - rootValue: computed from platform + designWidth * - targetUnit: 'rpx' (weapp), 'rem' (h5) * - unitPrecision: 5 * - selectorBlackList: [] * - propList: ['*'] * - replace: true * - mediaQuery: false * - minPixelValue: 0 * - onePxTransform: true * * @example * const options: PxTransformOptions = { * platform: 'h5', * designWidth: 375, * targetUnit: 'vw', * propList: ['*'], * } */ interface PxTransformOptions { /** * Target platform. * * @default 'weapp' */ platform?: PxTransformPlatform; /** * Design width in pixels. * * @default 750 */ designWidth?: DesignWidth; /** * Target unit after conversion. * * @default 'rpx' (weapp), 'rem' (h5) */ targetUnit?: PxTransformTargetUnit; /** * Device ratio map. * * @default { 375: 2, 640: 1.17, 750: 1, 828: 0.905 } */ deviceRatio?: PxTransformDeviceRatio; /** * Custom root value resolver. * * @default computed from platform + designWidth */ rootValue?: number | ((input: Input, m: string, value: string) => number); /** * Base font size for rem conversion. * * @default 20 (or minRootSize when >= 1) */ baseFontSize?: number; /** * Minimum base font size. * * @default 0 */ minRootSize?: number; /** * Enabled methods. * * @default ['platform', 'size'] */ methods?: readonly PxTransformMethod[]; /** * Decimal precision for generated values. * * @default 5 */ unitPrecision?: number; /** * Selectors to ignore. * * @default [] */ selectorBlackList?: readonly (string | RegExp)[]; /** * Properties to transform. * Supports negated glob patterns like `!padding*` or `!--wot-*-font-size`. * * @default ['*'] */ propList?: readonly string[]; /** * Replace the original declaration value. * * @default true */ replace?: boolean; /** * Enable unit conversion inside @media params. * * @default false */ mediaQuery?: boolean; /** * Minimum px value to convert. * * @default 0 */ minPixelValue?: number; /** * Convert 1px values. * * @default true */ onePxTransform?: boolean; /** * Exclude files by path. * * @default undefined */ exclude?: (filePath?: string) => boolean; } //#endregion //#region src/directives.d.ts /** * Create a PostCSS plugin that handles pxtrans directives such as * `#ifdef`, `#ifndef`, and `postcss-pxtrans rn eject`. * * Defaults: * - platform: 'weapp' * - methods: ['platform', 'size'] * * @example * import postcss from 'postcss' * import pxtrans, { createDirectivePlugin } from 'postcss-pxtrans' * * const result = await postcss([ * createDirectivePlugin({ platform: 'rn' }), * pxtrans({ platform: 'rn' }), * ]).process('/* #ifdef rn *\\/\\n.a{width:16px}\\n/* #endif *\\/', { from: undefined }) */ declare function createDirectivePlugin(options?: PxTransformOptions): { postcssPlugin: string; prepare(result: Result): { Comment(comment: Comment): void; OnceExit(): void; }; }; //#endregion //#region src/index.d.ts /** * Convert px (and rpx) to target units based on platform rules. * * Defaults: * - platform: 'weapp' * - designWidth: 750 * - deviceRatio: { 375: 2, 640: 1.17, 750: 1, 828: 0.905 } * - methods: ['platform', 'size'] * - targetUnit: 'rpx' (weapp), 'rem' (h5) * - unitPrecision: 5 * - propList: ['*'] * - replace: true * - mediaQuery: false * - minPixelValue: 0 * - onePxTransform: true * * @example * import postcss from 'postcss' * import pxtrans from 'postcss-pxtrans' * * const result = await postcss([pxtrans({ * platform: 'h5', * designWidth: 375, * targetUnit: 'vw', * })]).process('.a{padding:16px}', { from: undefined }) */ declare function plugin(userOptions?: PxTransformOptions): { postcssPlugin: string; prepare?: never; } | { postcssPlugin: string; prepare(result: Result): { Once(css: Root): void; }; }; declare namespace plugin { var postcss: boolean; } //#endregion //#region src/index-require.d.cts declare const requireEntry: typeof plugin & { default: typeof plugin; createDirectivePlugin: typeof createDirectivePlugin; }; export = requireEntry;