heartbeat-monitor/node_modules/motion-dom/dist/es/utils/transform.mjs.map

1 line
4.7 KiB
Plaintext

{"version":3,"file":"transform.mjs","sources":["../../../src/utils/transform.ts"],"sourcesContent":["import { EasingFunction } from \"motion-utils\"\nimport { interpolate } from \"./interpolate\"\n\n/**\n * @public\n */\nexport interface TransformOptions<T> {\n /**\n * Clamp values to within the given range. Defaults to `true`\n *\n * @public\n */\n clamp?: boolean\n\n /**\n * Easing functions to use on the interpolations between each value in the input and output ranges.\n *\n * If provided as an array, the array must be one item shorter than the input and output ranges, as the easings apply to the transition **between** each.\n *\n * @public\n */\n ease?: EasingFunction | EasingFunction[]\n\n /**\n * Provide a function that can interpolate between any two values in the provided range.\n *\n * @public\n */\n mixer?: (from: T, to: T) => (v: number) => any\n}\n\n/**\n * Transforms numbers into other values by mapping them from an input range to an output range.\n * Returns the type of the input provided.\n *\n * @remarks\n *\n * Given an input range of `[0, 200]` and an output range of\n * `[0, 1]`, this function will return a value between `0` and `1`.\n * The input range must be a linear series of numbers. The output range\n * can be any supported value type, such as numbers, colors, shadows, arrays, objects and more.\n * Every value in the output range must be of the same type and in the same format.\n *\n * ```jsx\n * export function MyComponent() {\n * const inputRange = [0, 200]\n * const outputRange = [0, 1]\n * const output = transform(100, inputRange, outputRange)\n *\n * // Returns 0.5\n * return <div>{output}</div>\n * }\n * ```\n *\n * @param inputValue - A number to transform between the input and output ranges.\n * @param inputRange - A linear series of numbers (either all increasing or decreasing).\n * @param outputRange - A series of numbers, colors, strings, or arrays/objects of those. Must be the same length as `inputRange`.\n * @param options - Clamp: Clamp values to within the given range. Defaults to `true`.\n *\n * @public\n */\nexport function transform<T>(\n inputValue: number,\n inputRange: number[],\n outputRange: T[],\n options?: TransformOptions<T>\n): T\n/**\n *\n * Transforms numbers into other values by mapping them from an input range to an output range.\n *\n * Given an input range of `[0, 200]` and an output range of\n * `[0, 1]`, this function will return a value between `0` and `1`.\n * The input range must be a linear series of numbers. The output range\n * can be any supported value type, such as numbers, colors, shadows, arrays, objects and more.\n * Every value in the output range must be of the same type and in the same format.\n *\n * ```jsx\n * export function MyComponent() {\n * const inputRange = [-200, -100, 100, 200]\n * const outputRange = [0, 1, 1, 0]\n * const convertRange = transform(inputRange, outputRange)\n * const output = convertRange(-150)\n *\n * // Returns 0.5\n * return <div>{output}</div>\n * }\n *\n * ```\n *\n * @param inputRange - A linear series of numbers (either all increasing or decreasing).\n * @param outputRange - A series of numbers, colors or strings. Must be the same length as `inputRange`.\n * @param options - Clamp: clamp values to within the given range. Defaults to `true`.\n *\n * @public\n */\nexport function transform<T>(\n inputRange: number[],\n outputRange: T[],\n options?: TransformOptions<T>\n): (inputValue: number) => T\nexport function transform<T>(\n ...args:\n | [number, number[], T[], TransformOptions<T>?]\n | [number[], T[], TransformOptions<T>?]\n) {\n const useImmediate = !Array.isArray(args[0])\n const argOffset = useImmediate ? 0 : -1\n const inputValue = args[0 + argOffset] as number\n const inputRange = args[1 + argOffset] as number[]\n const outputRange = args[2 + argOffset] as T[]\n const options = args[3 + argOffset] as TransformOptions<T>\n\n const interpolator = interpolate(inputRange, outputRange, options)\n\n return useImmediate ? interpolator(inputValue) : interpolator\n}\n"],"names":[],"mappings":";;AAqGgB,SAAA,SAAS,CACrB,GAAG,IAEwC,EAAA;AAE3C,IAAA,MAAM,YAAY,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AAC5C,IAAA,MAAM,SAAS,GAAG,YAAY,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IACvC,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,GAAG,SAAS,CAAW,CAAA;IAChD,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,GAAG,SAAS,CAAa,CAAA;IAClD,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,GAAG,SAAS,CAAQ,CAAA;IAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,GAAG,SAAS,CAAwB,CAAA;IAE1D,MAAM,YAAY,GAAG,WAAW,CAAC,UAAU,EAAE,WAAW,EAAE,OAAO,CAAC,CAAA;AAElE,IAAA,OAAO,YAAY,GAAG,YAAY,CAAC,UAAU,CAAC,GAAG,YAAY,CAAA;AACjE;;;;"}