@remotion/animation-utils 4.0.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +7 -0
  3. package/dist/esm/index.d.ts +3 -0
  4. package/dist/esm/index.mjs +662 -0
  5. package/dist/esm/test/interpolate-styles.test.d.ts +1 -0
  6. package/dist/esm/test/make-transform.test.d.ts +1 -0
  7. package/dist/esm/transformation-helpers/interpolate-styles/constants.d.ts +3 -0
  8. package/dist/esm/transformation-helpers/interpolate-styles/index.d.ts +8 -0
  9. package/dist/esm/transformation-helpers/interpolate-styles/utils.d.ts +41 -0
  10. package/dist/esm/transformation-helpers/make-transform/index.d.ts +4 -0
  11. package/dist/esm/transformation-helpers/make-transform/is-unit-with-string.d.ts +1 -0
  12. package/dist/esm/transformation-helpers/make-transform/transform-functions.d.ts +46 -0
  13. package/dist/esm/type.d.ts +31 -0
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.js +18 -0
  16. package/dist/transformation-helpers/interpolate-styles/constants.d.ts +3 -0
  17. package/dist/transformation-helpers/interpolate-styles/constants.js +7 -0
  18. package/dist/transformation-helpers/interpolate-styles/index.d.ts +8 -0
  19. package/dist/transformation-helpers/interpolate-styles/index.js +191 -0
  20. package/dist/transformation-helpers/interpolate-styles/utils.d.ts +41 -0
  21. package/dist/transformation-helpers/interpolate-styles/utils.js +150 -0
  22. package/dist/transformation-helpers/make-transform/index.d.ts +4 -0
  23. package/dist/transformation-helpers/make-transform/index.js +29 -0
  24. package/dist/transformation-helpers/make-transform/is-unit-with-string.d.ts +1 -0
  25. package/dist/transformation-helpers/make-transform/is-unit-with-string.js +18 -0
  26. package/dist/transformation-helpers/make-transform/transform-functions.d.ts +46 -0
  27. package/dist/transformation-helpers/make-transform/transform-functions.js +302 -0
  28. package/dist/type.d.ts +31 -0
  29. package/dist/type.js +34 -0
  30. package/package.json +58 -0
@@ -0,0 +1,3 @@
1
+ declare const NUMBER = "[-+]?\\d*\\.?\\d+";
2
+ declare const PERCENTAGE: string;
3
+ export { NUMBER, PERCENTAGE };
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import type { InterpolateOptions } from 'remotion';
3
+ import type { Style } from '../../type';
4
+ /**
5
+ * @description A function that interpolates between two styles based on an input range.
6
+ * @see [Documentation](https://www.remotion.dev/docs/animation-utils/interpolate-styles)
7
+ */
8
+ export declare const interpolateStyles: (input: number, inputRange: number[], outputStylesRange: Style[], options?: InterpolateOptions) => import("react").CSSProperties;
@@ -0,0 +1,41 @@
1
+ import type { ColorMatchers, CSSPropertiesValue } from '../../type';
2
+ declare function getColorMatchers(): ColorMatchers;
3
+ declare const breakDownValueIntoUnitNumberAndFunctions: (value: CSSPropertiesValue) => ({
4
+ color: string;
5
+ function?: undefined;
6
+ number?: undefined;
7
+ unit?: undefined;
8
+ } | {
9
+ function: {
10
+ name: string;
11
+ values: ({
12
+ number: number;
13
+ unit: string;
14
+ } | {
15
+ number: number;
16
+ unit?: undefined;
17
+ } | {
18
+ unit: string;
19
+ number?: undefined;
20
+ })[];
21
+ };
22
+ color?: undefined;
23
+ number?: undefined;
24
+ unit?: undefined;
25
+ } | {
26
+ number: number;
27
+ unit: string;
28
+ color?: undefined;
29
+ function?: undefined;
30
+ } | {
31
+ number: number;
32
+ color?: undefined;
33
+ function?: undefined;
34
+ unit?: undefined;
35
+ } | {
36
+ unit: string;
37
+ color?: undefined;
38
+ function?: undefined;
39
+ number?: undefined;
40
+ })[];
41
+ export { getColorMatchers, breakDownValueIntoUnitNumberAndFunctions };
@@ -0,0 +1,4 @@
1
+ import type { TransformFunctionReturnType } from '../../type';
2
+ import { matrix, matrix3d, perspective, rotate, rotate3d, rotateX, rotateY, rotateZ, scale, scale3d, scaleX, scaleY, scaleZ, skew, skewX, skewY, translate, translate3d, translateX, translateY, translateZ } from './transform-functions';
3
+ export declare function makeTransform(transforms: TransformFunctionReturnType[]): string;
4
+ export { matrix, matrix3d, perspective, rotate, rotate3d, rotateX, rotateY, rotateZ, scale, scale3d, scaleX, scaleY, scaleZ, skew, skewX, skewY, translate, translate3d, translateX, translateY, translateZ, };
@@ -0,0 +1 @@
1
+ export declare const isUnitWithString: (input: unknown, units: readonly string[]) => boolean;
@@ -0,0 +1,46 @@
1
+ import type { AngleUnit, AngleUnitString, LengthPercentageUnit, LengthPercentageUnitString, LengthUnit, LengthUnitString } from '../../type';
2
+ declare function matrix(a: number, b: number, c: number, d: number, tx: number, ty: number): string;
3
+ declare function matrix3d(a1: number, b1: number, c1: number, d1: number, a2: number, b2: number, c2: number, d2: number, a3: number, b3: number, c3: number, d3: number, a4: number, b4: number, c4: number, d4: number): string;
4
+ declare function perspective(length: LengthPercentageUnitString): string;
5
+ declare function perspective(length: number, unit?: LengthUnit): string;
6
+ declare function rotate(angle: AngleUnitString): string;
7
+ declare function rotate(angle: number, unit?: AngleUnit): string;
8
+ declare function rotate3d(x: number, y: number, z: number, angle: number): string;
9
+ declare function rotate3d(x: number, y: number, z: number, angle: AngleUnitString): string;
10
+ declare function rotate3d(x: number, y: number, z: number, angle: number, unit?: AngleUnit): string;
11
+ declare function rotateX(angle: AngleUnitString): string;
12
+ declare function rotateX(angle: number, unit?: AngleUnit): string;
13
+ declare function rotateY(angle: AngleUnitString): string;
14
+ declare function rotateY(angle: number, unit?: AngleUnit): string;
15
+ declare function rotateZ(angle: AngleUnitString): string;
16
+ declare function rotateZ(angle: number, unit?: AngleUnit): string;
17
+ declare function scale(x: number, y?: number): string;
18
+ declare function scale3d(x: number, y: number, z: number): string;
19
+ declare function scaleX(x: number): string;
20
+ declare function scaleY(y: number): string;
21
+ declare function scaleZ(z: number): string;
22
+ declare function skew(angle: number): string;
23
+ declare function skew(angle: AngleUnitString): string;
24
+ declare function skew(angle: AngleUnitString, angle2: AngleUnitString): string;
25
+ declare function skew(angle: number, unit: AngleUnit): string;
26
+ declare function skew(angleX: number, angleY: number): string;
27
+ declare function skew(angleX: number, unitX: AngleUnit, angleY: number, unitY: AngleUnit): string;
28
+ declare function skewX(angle: AngleUnitString): string;
29
+ declare function skewX(angle: number, unit?: AngleUnit): string;
30
+ declare function skewY(angle: AngleUnitString): string;
31
+ declare function skewY(angle: number, unit?: AngleUnit): string;
32
+ declare function translate(x: LengthPercentageUnitString): string;
33
+ declare function translate(x: number): string;
34
+ declare function translate(x: number, y: number): string;
35
+ declare function translate(x: LengthPercentageUnitString, y: LengthPercentageUnitString): string;
36
+ declare function translate(translation: number, unit: LengthPercentageUnit): string;
37
+ declare function translate(x: number, unitX: LengthPercentageUnit, y: number, unitY: LengthPercentageUnit): string;
38
+ declare function translate3d(x: LengthPercentageUnitString | number, y: LengthPercentageUnitString | number, z: LengthPercentageUnitString | number): string;
39
+ declare function translate3d(x: number, unitX: LengthPercentageUnit, y: number, unitY: LengthPercentageUnit, z: number, unitZ: LengthUnit): string;
40
+ declare function translateX(x: LengthPercentageUnitString): string;
41
+ declare function translateX(x: number, unit?: LengthPercentageUnit): string;
42
+ declare function translateY(y: LengthPercentageUnitString): string;
43
+ declare function translateY(y: number, unit?: LengthPercentageUnit): string;
44
+ declare function translateZ(z: LengthUnitString): string;
45
+ declare function translateZ(z: number, unit?: LengthUnit): string;
46
+ export { matrix, matrix3d, perspective, rotate, rotate3d, rotateX, rotateY, rotateZ, scale, scale3d, scaleX, scaleY, scaleZ, skew, skewX, skewY, translate, translate3d, translateX, translateY, translateZ, };
@@ -0,0 +1,31 @@
1
+ /// <reference types="react" />
2
+ import type { breakDownValueIntoUnitNumberAndFunctions } from './transformation-helpers/interpolate-styles/utils';
3
+ import type { matrix, matrix3d, perspective, rotate, rotate3d, rotateX, rotateY, rotateZ, scale, scale3d, scaleX, scaleY, scaleZ, skew, skewX, skewY, translate, translate3d, translateX, translateY, translateZ } from './transformation-helpers/make-transform';
4
+ export declare const lengthUnits: readonly ["px", "em", "rem", "pt", "cap", "ch", "ex", "ic", "lh", "rlh", "vmax", "vmin", "vb", "vi", "cqw", "vh", "vw", "cqh", "cqi", "cqb", "cqmin", "cqmax", "cm", "mm", "Q", "in", "pc"];
5
+ export declare const angleUnits: readonly ["rad", "deg", "grad", "turn"];
6
+ export declare const lengthPercentageUnits: readonly ["%", "px", "em", "rem", "pt", "cap", "ch", "ex", "ic", "lh", "rlh", "vmax", "vmin", "vb", "vi", "cqw", "vh", "vw", "cqh", "cqi", "cqb", "cqmin", "cqmax", "cm", "mm", "Q", "in", "pc"];
7
+ type LengthUnit = (typeof lengthUnits)[number];
8
+ type AngleUnit = (typeof angleUnits)[number];
9
+ type LengthPercentageUnit = (typeof lengthPercentageUnits)[number];
10
+ export type LengthUnitString = `${number}${LengthUnit}`;
11
+ export type LengthPercentageUnitString = `${number}${LengthPercentageUnit}`;
12
+ export type AngleUnitString = `${number}${AngleUnit}`;
13
+ type TransformFunctionReturnType = ReturnType<typeof matrix | typeof matrix3d | typeof perspective | typeof rotate | typeof rotate3d | typeof rotateX | typeof rotateY | typeof rotateZ | typeof scale | typeof scale3d | typeof scaleX | typeof scaleY | typeof scaleZ | typeof skew | typeof skewX | typeof skewY | typeof translate | typeof translate3d | typeof translateX | typeof translateY | typeof translateZ>;
14
+ type MatcherType = RegExp | undefined;
15
+ type ColorMatchers = {
16
+ rgb: MatcherType;
17
+ rgba: MatcherType;
18
+ hsl: MatcherType;
19
+ hsla: MatcherType;
20
+ hex3: MatcherType;
21
+ hex4: MatcherType;
22
+ hex5: MatcherType;
23
+ hex6: MatcherType;
24
+ hex8: MatcherType;
25
+ };
26
+ type Style = React.CSSProperties;
27
+ type CSSPropertiesKey = keyof Style;
28
+ type CSSPropertiesValue = Style[CSSPropertiesKey];
29
+ type UnitNumberAndFunctions = ReturnType<typeof breakDownValueIntoUnitNumberAndFunctions>;
30
+ type UnitNumberAndFunction = UnitNumberAndFunctions[0];
31
+ export type { LengthUnit, LengthPercentageUnit, AngleUnit, TransformFunctionReturnType, ColorMatchers, Style, CSSPropertiesKey, CSSPropertiesValue, UnitNumberAndFunction, };
@@ -0,0 +1,3 @@
1
+ export * from './transformation-helpers/interpolate-styles/index.js';
2
+ export * from './transformation-helpers/make-transform';
3
+ export type { AngleUnit, LengthPercentageUnit, LengthUnit, TransformFunctionReturnType, } from './type';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./transformation-helpers/interpolate-styles/index.js"), exports);
18
+ __exportStar(require("./transformation-helpers/make-transform"), exports);
@@ -0,0 +1,3 @@
1
+ declare const NUMBER = "[-+]?\\d*\\.?\\d+";
2
+ declare const PERCENTAGE: string;
3
+ export { NUMBER, PERCENTAGE };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PERCENTAGE = exports.NUMBER = void 0;
4
+ const NUMBER = '[-+]?\\d*\\.?\\d+';
5
+ exports.NUMBER = NUMBER;
6
+ const PERCENTAGE = NUMBER + '%';
7
+ exports.PERCENTAGE = PERCENTAGE;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import type { InterpolateOptions } from 'remotion';
3
+ import type { Style } from '../../type';
4
+ /**
5
+ * @description A function that interpolates between two styles based on an input range.
6
+ * @see [Documentation](https://www.remotion.dev/docs/animation-utils/interpolate-styles)
7
+ */
8
+ export declare const interpolateStyles: (input: number, inputRange: number[], outputStylesRange: Style[], options?: InterpolateOptions) => import("react").CSSProperties;
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.interpolateStyles = void 0;
4
+ const remotion_1 = require("remotion");
5
+ const utils_1 = require("./utils");
6
+ const interpolatedPropertyPart = ({ inputValue, inputRange, initialStylePropertyPart, finalStylePropertyPart, initialStyleProperty, finalStyleProperty, options, }) => {
7
+ var _a;
8
+ if (finalStylePropertyPart === undefined) {
9
+ throw new TypeError(`The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
10
+ }
11
+ if (initialStylePropertyPart.color) {
12
+ if (!finalStylePropertyPart.color) {
13
+ throw new TypeError(`The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
14
+ }
15
+ const interpolatedColor = (0, remotion_1.interpolateColors)(inputValue, inputRange, [
16
+ initialStylePropertyPart.color,
17
+ finalStylePropertyPart.color,
18
+ ]);
19
+ return `${interpolatedColor}`;
20
+ }
21
+ if (initialStylePropertyPart.function) {
22
+ if (!(finalStylePropertyPart === null || finalStylePropertyPart === void 0 ? void 0 : finalStylePropertyPart.function) ||
23
+ initialStylePropertyPart.function.name !==
24
+ ((_a = finalStylePropertyPart.function) === null || _a === void 0 ? void 0 : _a.name)) {
25
+ throw new TypeError(`The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
26
+ }
27
+ const endValuePartFunction = finalStylePropertyPart.function;
28
+ const endValuePartFunctionArgs = endValuePartFunction.values || [];
29
+ const interpolatedFunctionArgs = initialStylePropertyPart.function.values.reduce((acc, startValuePartFunctionArg, index) => {
30
+ const endValuePartFunctionArg = endValuePartFunctionArgs[index];
31
+ const interpolatedArg = interpolatedPropertyPart({
32
+ inputValue,
33
+ inputRange,
34
+ initialStylePropertyPart: startValuePartFunctionArg,
35
+ finalStylePropertyPart: endValuePartFunctionArg,
36
+ initialStyleProperty,
37
+ finalStyleProperty,
38
+ options,
39
+ });
40
+ return `${acc}, ${interpolatedArg}`;
41
+ }, '');
42
+ return `${initialStylePropertyPart.function.name}(${interpolatedFunctionArgs.slice(2)})`;
43
+ }
44
+ if (typeof initialStylePropertyPart.number === 'undefined') {
45
+ if (initialStylePropertyPart.unit !== finalStylePropertyPart.unit) {
46
+ throw new TypeError(`Non-animatable values cannot be interpolated. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
47
+ }
48
+ return `${initialStylePropertyPart.unit}`;
49
+ }
50
+ if (initialStylePropertyPart.unit !== finalStylePropertyPart.unit &&
51
+ initialStylePropertyPart.number !== 0 &&
52
+ finalStylePropertyPart.number !== 0) {
53
+ throw new TypeError(`The units of the start and end values must match. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
54
+ }
55
+ const startNumber = initialStylePropertyPart.number;
56
+ const endNumber = finalStylePropertyPart.number || 0;
57
+ const interpolatedNumber = (0, remotion_1.interpolate)(inputValue, inputRange, [startNumber, endNumber], options);
58
+ const interpolatedUnit = initialStylePropertyPart.unit || finalStylePropertyPart.unit || '';
59
+ if (!interpolatedUnit) {
60
+ return interpolatedNumber;
61
+ }
62
+ return `${interpolatedNumber}${interpolatedUnit}`;
63
+ };
64
+ const interpolateProperty = ({ inputValue, inputRange, initialStyleProperty, finalStyleProperty, options, }) => {
65
+ if (typeof initialStyleProperty !== typeof finalStyleProperty &&
66
+ initialStyleProperty !== 0 &&
67
+ finalStyleProperty !== 0) {
68
+ throw new TypeError(`The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
69
+ }
70
+ const initialStylePropertyParts = (0, utils_1.breakDownValueIntoUnitNumberAndFunctions)(initialStyleProperty);
71
+ const finalStylePropertyParts = (0, utils_1.breakDownValueIntoUnitNumberAndFunctions)(finalStyleProperty);
72
+ if (initialStylePropertyParts.length !== finalStylePropertyParts.length) {
73
+ throw new TypeError(`The start and end values must have the same structure. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
74
+ }
75
+ const interpolatedValue = initialStylePropertyParts.reduce((acc, initialStylePropertyPart, index) => {
76
+ return `${acc} ${interpolatedPropertyPart({
77
+ inputValue,
78
+ inputRange,
79
+ initialStylePropertyPart,
80
+ finalStylePropertyPart: finalStylePropertyParts[index],
81
+ initialStyleProperty,
82
+ finalStyleProperty,
83
+ options,
84
+ })}`;
85
+ }, '');
86
+ return interpolatedValue.slice(1);
87
+ };
88
+ const interpolateStylesFunction = ({ inputValue, inputRange, initialStyle, finalStyle, options, }) => {
89
+ const [startingValue, endingValue] = inputRange;
90
+ return Object.keys(initialStyle).reduce((acc, key) => {
91
+ if (!finalStyle[key]) {
92
+ return {
93
+ ...acc,
94
+ [key]: initialStyle[key],
95
+ };
96
+ }
97
+ const finalStyleValue = interpolateProperty({
98
+ inputValue,
99
+ inputRange: [startingValue, endingValue],
100
+ initialStyleProperty: initialStyle[key],
101
+ finalStyleProperty: finalStyle[key],
102
+ options,
103
+ });
104
+ // Avoid number to be a string
105
+ if (!isNaN(Number(finalStyleValue))) {
106
+ return {
107
+ ...acc,
108
+ [key]: Number(finalStyleValue),
109
+ };
110
+ }
111
+ return {
112
+ ...acc,
113
+ [key]: finalStyleValue,
114
+ };
115
+ }, {});
116
+ };
117
+ function checkInputRange(arr) {
118
+ if (arr.length < 2) {
119
+ throw new Error('inputRange must have at least 2 elements');
120
+ }
121
+ for (let index = 0; index < arr.length; index++) {
122
+ if (typeof arr[index] !== 'number') {
123
+ throw new Error(`inputRange must contain only numbers`);
124
+ }
125
+ if (arr[index] === -Infinity || arr[index] === Infinity) {
126
+ throw new Error(`inputRange must contain only finite numbers, but got [${arr.join(',')}]`);
127
+ }
128
+ if (index > 0 && !(arr[index] > arr[index - 1])) {
129
+ throw new Error(`inputRange must be strictly monotonically non-decreasing but got [${arr.join(',')}]`);
130
+ }
131
+ }
132
+ }
133
+ function checkStylesRange(arr) {
134
+ if (arr.length < 2) {
135
+ throw new Error('outputStyles must have at least 2 elements');
136
+ }
137
+ for (const index in arr) {
138
+ if (typeof arr[index] !== 'object') {
139
+ throw new Error('outputStyles must contain only objects');
140
+ }
141
+ }
142
+ }
143
+ /**
144
+ * @description A function that interpolates between two styles based on an input range.
145
+ * @see [Documentation](https://www.remotion.dev/docs/animation-utils/interpolate-styles)
146
+ */
147
+ const interpolateStyles = (input, inputRange, outputStylesRange, options) => {
148
+ var _a, _b, _c;
149
+ if (typeof input === 'undefined') {
150
+ throw new Error('input can not be undefined');
151
+ }
152
+ if (typeof inputRange === 'undefined') {
153
+ throw new Error('inputRange can not be undefined');
154
+ }
155
+ if (typeof outputStylesRange === 'undefined') {
156
+ throw new Error('outputRange can not be undefined');
157
+ }
158
+ if (inputRange.length !== outputStylesRange.length) {
159
+ throw new Error('inputRange (' +
160
+ inputRange.length +
161
+ ') and outputStylesRange (' +
162
+ outputStylesRange.length +
163
+ ') must have the same length');
164
+ }
165
+ checkInputRange(inputRange);
166
+ checkStylesRange(outputStylesRange);
167
+ let startIndex = inputRange.findIndex((step) => input < step) - 1;
168
+ if (startIndex === -2) {
169
+ startIndex = inputRange.length - 2;
170
+ }
171
+ const endIndex = startIndex + 1;
172
+ const startingValue = inputRange[startIndex];
173
+ const endingValue = inputRange[endIndex];
174
+ const initialStyle = outputStylesRange[startIndex];
175
+ const finalStyle = outputStylesRange[endIndex];
176
+ const easing = (_a = options === null || options === void 0 ? void 0 : options.easing) !== null && _a !== void 0 ? _a : ((num) => num);
177
+ const extrapolateLeft = (_b = options === null || options === void 0 ? void 0 : options.extrapolateLeft) !== null && _b !== void 0 ? _b : 'extend';
178
+ const extrapolateRight = (_c = options === null || options === void 0 ? void 0 : options.extrapolateRight) !== null && _c !== void 0 ? _c : 'extend';
179
+ return interpolateStylesFunction({
180
+ inputValue: input,
181
+ inputRange: [startingValue, endingValue],
182
+ initialStyle,
183
+ finalStyle,
184
+ options: {
185
+ easing,
186
+ extrapolateLeft,
187
+ extrapolateRight,
188
+ },
189
+ });
190
+ };
191
+ exports.interpolateStyles = interpolateStyles;
@@ -0,0 +1,41 @@
1
+ import type { ColorMatchers, CSSPropertiesValue } from '../../type';
2
+ declare function getColorMatchers(): ColorMatchers;
3
+ declare const breakDownValueIntoUnitNumberAndFunctions: (value: CSSPropertiesValue) => ({
4
+ color: string;
5
+ function?: undefined;
6
+ number?: undefined;
7
+ unit?: undefined;
8
+ } | {
9
+ function: {
10
+ name: string;
11
+ values: ({
12
+ number: number;
13
+ unit: string;
14
+ } | {
15
+ number: number;
16
+ unit?: undefined;
17
+ } | {
18
+ unit: string;
19
+ number?: undefined;
20
+ })[];
21
+ };
22
+ color?: undefined;
23
+ number?: undefined;
24
+ unit?: undefined;
25
+ } | {
26
+ number: number;
27
+ unit: string;
28
+ color?: undefined;
29
+ function?: undefined;
30
+ } | {
31
+ number: number;
32
+ color?: undefined;
33
+ function?: undefined;
34
+ unit?: undefined;
35
+ } | {
36
+ unit: string;
37
+ color?: undefined;
38
+ function?: undefined;
39
+ number?: undefined;
40
+ })[];
41
+ export { getColorMatchers, breakDownValueIntoUnitNumberAndFunctions };
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.breakDownValueIntoUnitNumberAndFunctions = exports.getColorMatchers = void 0;
4
+ const remotion_1 = require("remotion");
5
+ const constants_1 = require("./constants");
6
+ function call(...args) {
7
+ return '\\(\\s*(' + args.join(')\\s*,\\s*(') + ')\\s*\\)';
8
+ }
9
+ function getColorMatchers() {
10
+ const cachedMatchers = {
11
+ rgb: undefined,
12
+ rgba: undefined,
13
+ hsl: undefined,
14
+ hsla: undefined,
15
+ hex3: undefined,
16
+ hex4: undefined,
17
+ hex5: undefined,
18
+ hex6: undefined,
19
+ hex8: undefined,
20
+ };
21
+ if (cachedMatchers.rgb === undefined) {
22
+ cachedMatchers.rgb = new RegExp('rgb' + call(constants_1.NUMBER, constants_1.NUMBER, constants_1.NUMBER));
23
+ cachedMatchers.rgba = new RegExp('rgba' + call(constants_1.NUMBER, constants_1.NUMBER, constants_1.NUMBER, constants_1.NUMBER));
24
+ cachedMatchers.hsl = new RegExp('hsl' + call(constants_1.NUMBER, constants_1.PERCENTAGE, constants_1.PERCENTAGE));
25
+ cachedMatchers.hsla = new RegExp('hsla' + call(constants_1.NUMBER, constants_1.PERCENTAGE, constants_1.PERCENTAGE, constants_1.NUMBER));
26
+ cachedMatchers.hex3 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
27
+ cachedMatchers.hex4 =
28
+ /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
29
+ cachedMatchers.hex6 = /^#([0-9a-fA-F]{6})$/;
30
+ cachedMatchers.hex8 = /^#([0-9a-fA-F]{8})$/;
31
+ }
32
+ return cachedMatchers;
33
+ }
34
+ exports.getColorMatchers = getColorMatchers;
35
+ const extractOrderedPartsOfValue = (value) => {
36
+ const parts = [];
37
+ let remainingValue = value;
38
+ while (remainingValue.length > 0) {
39
+ const functionMatch = remainingValue.match(/([a-zA-Z-]+)\(([^)]+)\)/);
40
+ // If there's a function, add it to the parts and remove it from the remaining value
41
+ if (functionMatch) {
42
+ const { index } = functionMatch;
43
+ const matchedFunction = functionMatch[0];
44
+ // Add any parts before the function
45
+ if ((index || 0) > 0) {
46
+ parts.push(...remainingValue.substring(0, index).trim().split(/\s+/));
47
+ }
48
+ parts.push(matchedFunction);
49
+ remainingValue = remainingValue.substring((index || 0) + matchedFunction.length);
50
+ }
51
+ else {
52
+ // If there's no function, add the remaining value to the parts
53
+ parts.push(...remainingValue.trim().split(/\s+/));
54
+ break;
55
+ }
56
+ }
57
+ return parts.filter((part) => part !== ''); // Filter out any empty strings
58
+ };
59
+ const classifyArgsOfFunction = (value) => {
60
+ let nestedLevel = 0;
61
+ const values = [];
62
+ let currentValue = '';
63
+ for (const char of value) {
64
+ if (char === '(')
65
+ nestedLevel++;
66
+ else if (char === ')')
67
+ nestedLevel--;
68
+ if (char === ',' && nestedLevel === 0) {
69
+ values.push(currentValue.trim());
70
+ currentValue = '';
71
+ }
72
+ else {
73
+ currentValue += char;
74
+ }
75
+ }
76
+ if (currentValue)
77
+ values.push(currentValue.trim());
78
+ // Classify each value
79
+ return values.map((val) => {
80
+ const numberUnitMatch = val.match(/^(\d+(?:\.\d+)?)([a-zA-Z%]*)$/);
81
+ if (numberUnitMatch) {
82
+ const number = parseFloat(numberUnitMatch[1]);
83
+ const unit = numberUnitMatch[2];
84
+ return unit ? { number, unit } : { number };
85
+ }
86
+ const numberMatch = val.match(/^(\d+(?:\.\d+)?)$/);
87
+ if (numberMatch) {
88
+ const number = parseFloat(numberMatch[1]);
89
+ return { number };
90
+ }
91
+ return { unit: val };
92
+ });
93
+ };
94
+ const isColorValue = (value) => {
95
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
96
+ if (Object.keys(remotion_1.Internals.colorNames).includes(value)) {
97
+ return true;
98
+ }
99
+ const matchers = getColorMatchers();
100
+ return (((_a = matchers.rgb) === null || _a === void 0 ? void 0 : _a.test(value)) ||
101
+ ((_b = matchers.rgba) === null || _b === void 0 ? void 0 : _b.test(value)) ||
102
+ ((_c = matchers.hsl) === null || _c === void 0 ? void 0 : _c.test(value)) ||
103
+ ((_d = matchers.hsla) === null || _d === void 0 ? void 0 : _d.test(value)) ||
104
+ ((_e = matchers.hex3) === null || _e === void 0 ? void 0 : _e.test(value)) ||
105
+ ((_f = matchers.hex4) === null || _f === void 0 ? void 0 : _f.test(value)) ||
106
+ ((_g = matchers.hex5) === null || _g === void 0 ? void 0 : _g.test(value)) ||
107
+ ((_h = matchers.hex6) === null || _h === void 0 ? void 0 : _h.test(value)) ||
108
+ ((_j = matchers.hex8) === null || _j === void 0 ? void 0 : _j.test(value)));
109
+ };
110
+ const classifyParts = (parts) => {
111
+ return parts.map((part) => {
112
+ // Check for a color value like 'red', 'rgba(0, 0, 0, 0)', '#fff', etc.
113
+ if (isColorValue(part)) {
114
+ return { color: part };
115
+ }
116
+ // Check for a function like 'translateX(10px)' or 'rotate(90deg)'
117
+ const functionMatch = part.match(/([a-zA-Z-]+)\(([^)]+)\)/);
118
+ if (functionMatch) {
119
+ const functionName = functionMatch[1];
120
+ const functionValues = classifyArgsOfFunction(functionMatch[2]);
121
+ return { function: { name: functionName, values: functionValues } };
122
+ }
123
+ // Check for a number possibly followed by a unit
124
+ const numberUnitMatch = part.match(/^(\d+(?:\.\d+)?)([a-zA-Z%]*)$/);
125
+ if (numberUnitMatch) {
126
+ const number = parseFloat(numberUnitMatch[1]);
127
+ const unit = numberUnitMatch[2];
128
+ return unit ? { number, unit } : { number };
129
+ }
130
+ // Check for a number without a unit
131
+ const numberMatch = part.match(/^(\d+(?:\.\d+)?)$/);
132
+ if (numberMatch) {
133
+ const number = parseFloat(numberMatch[1]);
134
+ return { number };
135
+ }
136
+ // If neither, treat as a unit (like 'solid', 'none', etc.)
137
+ return { unit: part };
138
+ });
139
+ };
140
+ const breakDownValueIntoUnitNumberAndFunctions = (value) => {
141
+ if (typeof value === 'number') {
142
+ return [{ number: value }];
143
+ }
144
+ if (typeof value !== 'string') {
145
+ return [];
146
+ }
147
+ const valueParts = extractOrderedPartsOfValue(value);
148
+ return classifyParts(valueParts);
149
+ };
150
+ exports.breakDownValueIntoUnitNumberAndFunctions = breakDownValueIntoUnitNumberAndFunctions;
@@ -0,0 +1,4 @@
1
+ import type { TransformFunctionReturnType } from '../../type';
2
+ import { matrix, matrix3d, perspective, rotate, rotate3d, rotateX, rotateY, rotateZ, scale, scale3d, scaleX, scaleY, scaleZ, skew, skewX, skewY, translate, translate3d, translateX, translateY, translateZ } from './transform-functions';
3
+ export declare function makeTransform(transforms: TransformFunctionReturnType[]): string;
4
+ export { matrix, matrix3d, perspective, rotate, rotate3d, rotateX, rotateY, rotateZ, scale, scale3d, scaleX, scaleY, scaleZ, skew, skewX, skewY, translate, translate3d, translateX, translateY, translateZ, };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.translateZ = exports.translateY = exports.translateX = exports.translate3d = exports.translate = exports.skewY = exports.skewX = exports.skew = exports.scaleZ = exports.scaleY = exports.scaleX = exports.scale3d = exports.scale = exports.rotateZ = exports.rotateY = exports.rotateX = exports.rotate3d = exports.rotate = exports.perspective = exports.matrix3d = exports.matrix = exports.makeTransform = void 0;
4
+ const transform_functions_1 = require("./transform-functions");
5
+ Object.defineProperty(exports, "matrix", { enumerable: true, get: function () { return transform_functions_1.matrix; } });
6
+ Object.defineProperty(exports, "matrix3d", { enumerable: true, get: function () { return transform_functions_1.matrix3d; } });
7
+ Object.defineProperty(exports, "perspective", { enumerable: true, get: function () { return transform_functions_1.perspective; } });
8
+ Object.defineProperty(exports, "rotate", { enumerable: true, get: function () { return transform_functions_1.rotate; } });
9
+ Object.defineProperty(exports, "rotate3d", { enumerable: true, get: function () { return transform_functions_1.rotate3d; } });
10
+ Object.defineProperty(exports, "rotateX", { enumerable: true, get: function () { return transform_functions_1.rotateX; } });
11
+ Object.defineProperty(exports, "rotateY", { enumerable: true, get: function () { return transform_functions_1.rotateY; } });
12
+ Object.defineProperty(exports, "rotateZ", { enumerable: true, get: function () { return transform_functions_1.rotateZ; } });
13
+ Object.defineProperty(exports, "scale", { enumerable: true, get: function () { return transform_functions_1.scale; } });
14
+ Object.defineProperty(exports, "scale3d", { enumerable: true, get: function () { return transform_functions_1.scale3d; } });
15
+ Object.defineProperty(exports, "scaleX", { enumerable: true, get: function () { return transform_functions_1.scaleX; } });
16
+ Object.defineProperty(exports, "scaleY", { enumerable: true, get: function () { return transform_functions_1.scaleY; } });
17
+ Object.defineProperty(exports, "scaleZ", { enumerable: true, get: function () { return transform_functions_1.scaleZ; } });
18
+ Object.defineProperty(exports, "skew", { enumerable: true, get: function () { return transform_functions_1.skew; } });
19
+ Object.defineProperty(exports, "skewX", { enumerable: true, get: function () { return transform_functions_1.skewX; } });
20
+ Object.defineProperty(exports, "skewY", { enumerable: true, get: function () { return transform_functions_1.skewY; } });
21
+ Object.defineProperty(exports, "translate", { enumerable: true, get: function () { return transform_functions_1.translate; } });
22
+ Object.defineProperty(exports, "translate3d", { enumerable: true, get: function () { return transform_functions_1.translate3d; } });
23
+ Object.defineProperty(exports, "translateX", { enumerable: true, get: function () { return transform_functions_1.translateX; } });
24
+ Object.defineProperty(exports, "translateY", { enumerable: true, get: function () { return transform_functions_1.translateY; } });
25
+ Object.defineProperty(exports, "translateZ", { enumerable: true, get: function () { return transform_functions_1.translateZ; } });
26
+ function makeTransform(transforms) {
27
+ return transforms.join(' ');
28
+ }
29
+ exports.makeTransform = makeTransform;
@@ -0,0 +1 @@
1
+ export declare const isUnitWithString: (input: unknown, units: readonly string[]) => boolean;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isUnitWithString = void 0;
4
+ const type_1 = require("../../type");
5
+ const isUnitWithString = (input, units) => {
6
+ if (typeof input !== 'string') {
7
+ return false;
8
+ }
9
+ if (!units.find((u) => input.endsWith(u))) {
10
+ throw new Error(`input ${input} does not end with a valid unit. Valid units are: ${units.join(', ')}`);
11
+ }
12
+ const match = input.match(/([0-9.]+)([a-z%]+)/);
13
+ if (!match) {
14
+ throw new Error(`input ${input} is not a valid transform. Must be a number or a string ending in one of the following units: ${type_1.lengthUnits.join(', ')}`);
15
+ }
16
+ return true;
17
+ };
18
+ exports.isUnitWithString = isUnitWithString;