@remotion/animation-utils 4.0.142 → 4.0.144

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.
@@ -1,663 +1,660 @@
1
- import { Internals, interpolateColors, interpolate } from 'remotion';
1
+ // src/transformation-helpers/interpolate-styles/index.tsx
2
+ import {interpolate, interpolateColors} from "remotion";
2
3
 
3
- const NUMBER = '[-+]?\\d*\\.?\\d+';
4
- const PERCENTAGE = NUMBER + '%';
4
+ // src/transformation-helpers/interpolate-styles/utils.ts
5
+ import {NoReactInternals} from "remotion/no-react";
5
6
 
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(NUMBER, NUMBER, NUMBER));
23
- cachedMatchers.rgba = new RegExp('rgba' + call(NUMBER, NUMBER, NUMBER, NUMBER));
24
- cachedMatchers.hsl = new RegExp('hsl' + call(NUMBER, PERCENTAGE, PERCENTAGE));
25
- cachedMatchers.hsla = new RegExp('hsla' + call(NUMBER, PERCENTAGE, PERCENTAGE, 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
- const extractOrderedPartsOfValue = (value) => {
35
- const parts = [];
36
- let remainingValue = value;
37
- while (remainingValue.length > 0) {
38
- const functionMatch = remainingValue.match(/([a-zA-Z-]+)\(([^)]+)\)/);
39
- // If there's a function, add it to the parts and remove it from the remaining value
40
- if (functionMatch) {
41
- const { index } = functionMatch;
42
- const matchedFunction = functionMatch[0];
43
- // Add any parts before the function
44
- if ((index || 0) > 0) {
45
- parts.push(...remainingValue.substring(0, index).trim().split(/\s+/));
46
- }
47
- parts.push(matchedFunction);
48
- remainingValue = remainingValue.substring((index || 0) + matchedFunction.length);
49
- }
50
- else {
51
- // If there's no function, add the remaining value to the parts
52
- parts.push(...remainingValue.trim().split(/\s+/));
53
- break;
54
- }
55
- }
56
- return parts.filter((part) => part !== ''); // Filter out any empty strings
57
- };
58
- const classifyArgsOfFunction = (value) => {
59
- let nestedLevel = 0;
60
- const values = [];
61
- let currentValue = '';
62
- for (const char of value) {
63
- if (char === '(')
64
- nestedLevel++;
65
- else if (char === ')')
66
- nestedLevel--;
67
- if (char === ',' && nestedLevel === 0) {
68
- values.push(currentValue.trim());
69
- currentValue = '';
70
- }
71
- else {
72
- currentValue += char;
73
- }
74
- }
75
- if (currentValue)
76
- values.push(currentValue.trim());
77
- // Classify each value
78
- return values.map((val) => {
79
- const numberUnitMatch = val.match(/^(-?\d+(?:\.\d+)?)([a-zA-Z%]*)$/);
80
- if (numberUnitMatch) {
81
- const number = parseFloat(numberUnitMatch[1]);
82
- const unit = numberUnitMatch[2];
83
- return unit ? { number, unit } : { number };
84
- }
85
- const numberMatch = val.match(/^(\d+(?:\.\d+)?)$/);
86
- if (numberMatch) {
87
- const number = parseFloat(numberMatch[1]);
88
- return { number };
89
- }
90
- return { unit: val };
91
- });
7
+ // src/transformation-helpers/interpolate-styles/constants.ts
8
+ var NUMBER = "[-+]?\\d*\\.?\\d+";
9
+ var PERCENTAGE = NUMBER + "%";
10
+
11
+ // src/transformation-helpers/interpolate-styles/utils.ts
12
+ var call = function(...args) {
13
+ return "\\(\\s*(" + args.join(")\\s*,\\s*(") + ")\\s*\\)";
92
14
  };
93
- const isColorValue = (value) => {
94
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
95
- if (Object.keys(Internals.colorNames).includes(value)) {
96
- return true;
97
- }
98
- const matchers = getColorMatchers();
99
- return (((_a = matchers.rgb) === null || _a === void 0 ? void 0 : _a.test(value)) ||
100
- ((_b = matchers.rgba) === null || _b === void 0 ? void 0 : _b.test(value)) ||
101
- ((_c = matchers.hsl) === null || _c === void 0 ? void 0 : _c.test(value)) ||
102
- ((_d = matchers.hsla) === null || _d === void 0 ? void 0 : _d.test(value)) ||
103
- ((_e = matchers.hex3) === null || _e === void 0 ? void 0 : _e.test(value)) ||
104
- ((_f = matchers.hex4) === null || _f === void 0 ? void 0 : _f.test(value)) ||
105
- ((_g = matchers.hex5) === null || _g === void 0 ? void 0 : _g.test(value)) ||
106
- ((_h = matchers.hex6) === null || _h === void 0 ? void 0 : _h.test(value)) ||
107
- ((_j = matchers.hex8) === null || _j === void 0 ? void 0 : _j.test(value)));
108
- };
109
- const classifyParts = (parts) => {
110
- return parts.map((part) => {
111
- // Check for a color value like 'red', 'rgba(0, 0, 0, 0)', '#fff', etc.
112
- if (isColorValue(part)) {
113
- return { color: part };
114
- }
115
- // Check for a function like 'translateX(10px)' or 'rotate(90deg)'
116
- const functionMatch = part.match(/([a-zA-Z-]+)\(([^)]+)\)/);
117
- if (functionMatch) {
118
- const functionName = functionMatch[1];
119
- const functionValues = classifyArgsOfFunction(functionMatch[2]);
120
- return { function: { name: functionName, values: functionValues } };
121
- }
122
- // Check for a number possibly followed by a unit like '10px' or '10' or '-10px'
123
- const numberUnitMatch = part.match(/^(-?\d+(?:\.\d+)?)([a-zA-Z%]*)$/);
124
- if (numberUnitMatch) {
125
- const number = parseFloat(numberUnitMatch[1]);
126
- const unit = numberUnitMatch[2];
127
- return unit ? { number, unit } : { number };
128
- }
129
- // Check for a number without a unit like '10' or '-10'
130
- const numberMatch = part.match(/^(-?\d+(?:\.\d+)?)$/);
131
- if (numberMatch) {
132
- const number = parseFloat(numberMatch[1]);
133
- return { number };
134
- }
135
- // If neither, treat as a unit (like 'solid', 'none', etc.)
136
- return { unit: part };
137
- });
15
+ var getColorMatchers = function() {
16
+ const cachedMatchers = {
17
+ rgb: undefined,
18
+ rgba: undefined,
19
+ hsl: undefined,
20
+ hsla: undefined,
21
+ hex3: undefined,
22
+ hex4: undefined,
23
+ hex5: undefined,
24
+ hex6: undefined,
25
+ hex8: undefined
26
+ };
27
+ if (cachedMatchers.rgb === undefined) {
28
+ cachedMatchers.rgb = new RegExp("rgb" + call(NUMBER, NUMBER, NUMBER));
29
+ cachedMatchers.rgba = new RegExp("rgba" + call(NUMBER, NUMBER, NUMBER, NUMBER));
30
+ cachedMatchers.hsl = new RegExp("hsl" + call(NUMBER, PERCENTAGE, PERCENTAGE));
31
+ cachedMatchers.hsla = new RegExp("hsla" + call(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER));
32
+ cachedMatchers.hex3 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
33
+ cachedMatchers.hex4 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
34
+ cachedMatchers.hex6 = /^#([0-9a-fA-F]{6})$/;
35
+ cachedMatchers.hex8 = /^#([0-9a-fA-F]{8})$/;
36
+ }
37
+ return cachedMatchers;
138
38
  };
139
- const breakDownValueIntoUnitNumberAndFunctions = (value) => {
140
- if (typeof value === 'number') {
141
- return [{ number: value }];
142
- }
143
- if (typeof value !== 'string') {
144
- return [];
145
- }
146
- const valueParts = extractOrderedPartsOfValue(value);
147
- return classifyParts(valueParts);
39
+ var extractOrderedPartsOfValue = (value) => {
40
+ const parts = [];
41
+ let remainingValue = value;
42
+ while (remainingValue.length > 0) {
43
+ const functionMatch = remainingValue.match(/([a-zA-Z-]+)\(([^)]+)\)/);
44
+ if (functionMatch) {
45
+ const { index } = functionMatch;
46
+ const matchedFunction = functionMatch[0];
47
+ if ((index || 0) > 0) {
48
+ parts.push(...remainingValue.substring(0, index).trim().split(/\s+/));
49
+ }
50
+ parts.push(matchedFunction);
51
+ remainingValue = remainingValue.substring((index || 0) + matchedFunction.length);
52
+ } else {
53
+ parts.push(...remainingValue.trim().split(/\s+/));
54
+ break;
55
+ }
56
+ }
57
+ return parts.filter((part) => part !== "");
58
+ };
59
+ var 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
+ } else {
72
+ currentValue += char;
73
+ }
74
+ }
75
+ if (currentValue)
76
+ values.push(currentValue.trim());
77
+ return values.map((val) => {
78
+ const numberUnitMatch = val.match(/^(-?\d+(?:\.\d+)?)([a-zA-Z%]*)$/);
79
+ if (numberUnitMatch) {
80
+ const number = parseFloat(numberUnitMatch[1]);
81
+ const unit = numberUnitMatch[2];
82
+ return unit ? { number, unit } : { number };
83
+ }
84
+ const numberMatch = val.match(/^(\d+(?:\.\d+)?)$/);
85
+ if (numberMatch) {
86
+ const number = parseFloat(numberMatch[1]);
87
+ return { number };
88
+ }
89
+ return { unit: val };
90
+ });
91
+ };
92
+ var isColorValue = (value) => {
93
+ if (Object.keys(NoReactInternals.colorNames).includes(value)) {
94
+ return true;
95
+ }
96
+ const matchers = getColorMatchers();
97
+ return matchers.rgb?.test(value) || matchers.rgba?.test(value) || matchers.hsl?.test(value) || matchers.hsla?.test(value) || matchers.hex3?.test(value) || matchers.hex4?.test(value) || matchers.hex5?.test(value) || matchers.hex6?.test(value) || matchers.hex8?.test(value);
98
+ };
99
+ var classifyParts = (parts) => {
100
+ return parts.map((part) => {
101
+ if (isColorValue(part)) {
102
+ return { color: part };
103
+ }
104
+ const functionMatch = part.match(/([a-zA-Z-]+)\(([^)]+)\)/);
105
+ if (functionMatch) {
106
+ const functionName = functionMatch[1];
107
+ const functionValues = classifyArgsOfFunction(functionMatch[2]);
108
+ return { function: { name: functionName, values: functionValues } };
109
+ }
110
+ const numberUnitMatch = part.match(/^(-?\d+(?:\.\d+)?)([a-zA-Z%]*)$/);
111
+ if (numberUnitMatch) {
112
+ const number = parseFloat(numberUnitMatch[1]);
113
+ const unit = numberUnitMatch[2];
114
+ return unit ? { number, unit } : { number };
115
+ }
116
+ const numberMatch = part.match(/^(-?\d+(?:\.\d+)?)$/);
117
+ if (numberMatch) {
118
+ const number = parseFloat(numberMatch[1]);
119
+ return { number };
120
+ }
121
+ return { unit: part };
122
+ });
123
+ };
124
+ var breakDownValueIntoUnitNumberAndFunctions = (value) => {
125
+ if (typeof value === "number") {
126
+ return [{ number: value }];
127
+ }
128
+ if (typeof value !== "string") {
129
+ return [];
130
+ }
131
+ const valueParts = extractOrderedPartsOfValue(value);
132
+ return classifyParts(valueParts);
148
133
  };
149
134
 
150
- const interpolatedPropertyPart = ({ inputValue, inputRange, initialStylePropertyPart, finalStylePropertyPart, initialStyleProperty, finalStyleProperty, options, }) => {
151
- var _a;
152
- if (finalStylePropertyPart === undefined) {
153
- throw new TypeError(`The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
154
- }
155
- if (initialStylePropertyPart.color) {
156
- if (!finalStylePropertyPart.color) {
157
- throw new TypeError(`The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
158
- }
159
- const interpolatedColor = interpolateColors(inputValue, inputRange, [
160
- initialStylePropertyPart.color,
161
- finalStylePropertyPart.color,
162
- ]);
163
- return `${interpolatedColor}`;
164
- }
165
- if (initialStylePropertyPart.function) {
166
- if (!(finalStylePropertyPart === null || finalStylePropertyPart === void 0 ? void 0 : finalStylePropertyPart.function) ||
167
- initialStylePropertyPart.function.name !==
168
- ((_a = finalStylePropertyPart.function) === null || _a === void 0 ? void 0 : _a.name)) {
169
- throw new TypeError(`The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
170
- }
171
- const endValuePartFunction = finalStylePropertyPart.function;
172
- const endValuePartFunctionArgs = endValuePartFunction.values || [];
173
- const interpolatedFunctionArgs = initialStylePropertyPart.function.values.reduce((acc, startValuePartFunctionArg, index) => {
174
- const endValuePartFunctionArg = endValuePartFunctionArgs[index];
175
- const interpolatedArg = interpolatedPropertyPart({
176
- inputValue,
177
- inputRange,
178
- initialStylePropertyPart: startValuePartFunctionArg,
179
- finalStylePropertyPart: endValuePartFunctionArg,
180
- initialStyleProperty,
181
- finalStyleProperty,
182
- options,
183
- });
184
- return `${acc}, ${interpolatedArg}`;
185
- }, '');
186
- return `${initialStylePropertyPart.function.name}(${interpolatedFunctionArgs.slice(2)})`;
187
- }
188
- if (typeof initialStylePropertyPart.number === 'undefined') {
189
- if (initialStylePropertyPart.unit !== finalStylePropertyPart.unit) {
190
- throw new TypeError(`Non-animatable values cannot be interpolated. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
191
- }
192
- return `${initialStylePropertyPart.unit}`;
193
- }
194
- if (initialStylePropertyPart.unit !== finalStylePropertyPart.unit &&
195
- initialStylePropertyPart.number !== 0 &&
196
- finalStylePropertyPart.number !== 0) {
197
- throw new TypeError(`The units of the start and end values must match. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
198
- }
199
- const startNumber = initialStylePropertyPart.number;
200
- const endNumber = finalStylePropertyPart.number || 0;
201
- const interpolatedNumber = interpolate(inputValue, inputRange, [startNumber, endNumber], options);
202
- const interpolatedUnit = initialStylePropertyPart.unit || finalStylePropertyPart.unit || '';
203
- if (!interpolatedUnit) {
204
- return interpolatedNumber;
205
- }
206
- return `${interpolatedNumber}${interpolatedUnit}`;
135
+ // src/transformation-helpers/interpolate-styles/index.tsx
136
+ var checkInputRange = function(arr) {
137
+ if (arr.length < 2) {
138
+ throw new Error("inputRange must have at least 2 elements");
139
+ }
140
+ for (let index = 0;index < arr.length; index++) {
141
+ if (typeof arr[index] !== "number") {
142
+ throw new Error(`inputRange must contain only numbers`);
143
+ }
144
+ if (arr[index] === (-Infinity) || arr[index] === Infinity) {
145
+ throw new Error(`inputRange must contain only finite numbers, but got [${arr.join(",")}]`);
146
+ }
147
+ if (index > 0 && !(arr[index] > arr[index - 1])) {
148
+ throw new Error(`inputRange must be strictly monotonically non-decreasing but got [${arr.join(",")}]`);
149
+ }
150
+ }
207
151
  };
208
- const interpolateProperty = ({ inputValue, inputRange, initialStyleProperty, finalStyleProperty, options, }) => {
209
- if (typeof initialStyleProperty !== typeof finalStyleProperty &&
210
- initialStyleProperty !== 0 &&
211
- finalStyleProperty !== 0) {
212
- throw new TypeError(`The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
213
- }
214
- const initialStylePropertyParts = breakDownValueIntoUnitNumberAndFunctions(initialStyleProperty);
215
- const finalStylePropertyParts = breakDownValueIntoUnitNumberAndFunctions(finalStyleProperty);
216
- if (initialStylePropertyParts.length !== finalStylePropertyParts.length) {
217
- throw new TypeError(`The start and end values must have the same structure. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
218
- }
219
- const interpolatedValue = initialStylePropertyParts.reduce((acc, initialStylePropertyPart, index) => {
220
- return `${acc} ${interpolatedPropertyPart({
221
- inputValue,
222
- inputRange,
223
- initialStylePropertyPart,
224
- finalStylePropertyPart: finalStylePropertyParts[index],
225
- initialStyleProperty,
226
- finalStyleProperty,
227
- options,
228
- })}`;
229
- }, '');
230
- return interpolatedValue.slice(1);
231
- };
232
- const interpolateStylesFunction = ({ inputValue, inputRange, initialStyle, finalStyle, options, }) => {
233
- const [startingValue, endingValue] = inputRange;
234
- return Object.keys(initialStyle).reduce((acc, key) => {
235
- const value = finalStyle[key];
236
- if (value === undefined || value === null) {
237
- return {
238
- ...acc,
239
- [key]: initialStyle[key],
240
- };
241
- }
242
- const finalStyleValue = interpolateProperty({
243
- inputValue,
244
- inputRange: [startingValue, endingValue],
245
- initialStyleProperty: initialStyle[key],
246
- finalStyleProperty: finalStyle[key],
247
- options,
248
- });
249
- // Avoid number to be a string
250
- if (!isNaN(Number(finalStyleValue))) {
251
- return {
252
- ...acc,
253
- [key]: Number(finalStyleValue),
254
- };
255
- }
256
- return {
257
- ...acc,
258
- [key]: finalStyleValue,
259
- };
260
- }, {});
261
- };
262
- function checkInputRange(arr) {
263
- if (arr.length < 2) {
264
- throw new Error('inputRange must have at least 2 elements');
265
- }
266
- for (let index = 0; index < arr.length; index++) {
267
- if (typeof arr[index] !== 'number') {
268
- throw new Error(`inputRange must contain only numbers`);
269
- }
270
- if (arr[index] === -Infinity || arr[index] === Infinity) {
271
- throw new Error(`inputRange must contain only finite numbers, but got [${arr.join(',')}]`);
272
- }
273
- if (index > 0 && !(arr[index] > arr[index - 1])) {
274
- throw new Error(`inputRange must be strictly monotonically non-decreasing but got [${arr.join(',')}]`);
275
- }
276
- }
277
- }
278
- function checkStylesRange(arr) {
279
- if (arr.length < 2) {
280
- throw new Error('outputStyles must have at least 2 elements');
281
- }
282
- for (const index in arr) {
283
- if (typeof arr[index] !== 'object') {
284
- throw new Error('outputStyles must contain only objects');
285
- }
286
- }
287
- }
288
- /**
289
- * @description A function that interpolates between two styles based on an input range.
290
- * @see [Documentation](https://www.remotion.dev/docs/animation-utils/interpolate-styles)
291
- */
292
- const interpolateStyles = (input, inputRange, outputStylesRange, options) => {
293
- var _a, _b, _c;
294
- if (typeof input === 'undefined') {
295
- throw new Error('input can not be undefined');
296
- }
297
- if (typeof inputRange === 'undefined') {
298
- throw new Error('inputRange can not be undefined');
299
- }
300
- if (typeof outputStylesRange === 'undefined') {
301
- throw new Error('outputRange can not be undefined');
302
- }
303
- if (inputRange.length !== outputStylesRange.length) {
304
- throw new Error('inputRange (' +
305
- inputRange.length +
306
- ') and outputStylesRange (' +
307
- outputStylesRange.length +
308
- ') must have the same length');
309
- }
310
- checkInputRange(inputRange);
311
- checkStylesRange(outputStylesRange);
312
- let startIndex = inputRange.findIndex((step) => input < step) - 1;
313
- if (startIndex === -2) {
314
- startIndex = inputRange.length - 2;
315
- }
316
- const endIndex = startIndex + 1;
317
- const startingValue = inputRange[startIndex];
318
- const endingValue = inputRange[endIndex];
319
- const initialStyle = outputStylesRange[startIndex];
320
- const finalStyle = outputStylesRange[endIndex];
321
- const easing = (_a = options === null || options === void 0 ? void 0 : options.easing) !== null && _a !== void 0 ? _a : ((num) => num);
322
- const extrapolateLeft = (_b = options === null || options === void 0 ? void 0 : options.extrapolateLeft) !== null && _b !== void 0 ? _b : 'extend';
323
- const extrapolateRight = (_c = options === null || options === void 0 ? void 0 : options.extrapolateRight) !== null && _c !== void 0 ? _c : 'extend';
324
- return interpolateStylesFunction({
325
- inputValue: input,
326
- inputRange: [startingValue, endingValue],
327
- initialStyle,
328
- finalStyle,
329
- options: {
330
- easing,
331
- extrapolateLeft,
332
- extrapolateRight,
333
- },
152
+ var checkStylesRange = function(arr) {
153
+ if (arr.length < 2) {
154
+ throw new Error("outputStyles must have at least 2 elements");
155
+ }
156
+ for (const index in arr) {
157
+ if (typeof arr[index] !== "object") {
158
+ throw new Error("outputStyles must contain only objects");
159
+ }
160
+ }
161
+ };
162
+ var interpolatedPropertyPart = ({
163
+ inputValue,
164
+ inputRange,
165
+ initialStylePropertyPart,
166
+ finalStylePropertyPart,
167
+ initialStyleProperty,
168
+ finalStyleProperty,
169
+ options
170
+ }) => {
171
+ if (finalStylePropertyPart === undefined) {
172
+ throw new TypeError(`The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
173
+ }
174
+ if (initialStylePropertyPart.color) {
175
+ if (!finalStylePropertyPart.color) {
176
+ throw new TypeError(`The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
177
+ }
178
+ const interpolatedColor = interpolateColors(inputValue, inputRange, [
179
+ initialStylePropertyPart.color,
180
+ finalStylePropertyPart.color
181
+ ]);
182
+ return `${interpolatedColor}`;
183
+ }
184
+ if (initialStylePropertyPart.function) {
185
+ if (!finalStylePropertyPart?.function || initialStylePropertyPart.function.name !== finalStylePropertyPart.function?.name) {
186
+ throw new TypeError(`The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
187
+ }
188
+ const endValuePartFunction = finalStylePropertyPart.function;
189
+ const endValuePartFunctionArgs = endValuePartFunction.values || [];
190
+ const interpolatedFunctionArgs = initialStylePropertyPart.function.values.reduce((acc, startValuePartFunctionArg, index) => {
191
+ const endValuePartFunctionArg = endValuePartFunctionArgs[index];
192
+ const interpolatedArg = interpolatedPropertyPart({
193
+ inputValue,
194
+ inputRange,
195
+ initialStylePropertyPart: startValuePartFunctionArg,
196
+ finalStylePropertyPart: endValuePartFunctionArg,
197
+ initialStyleProperty,
198
+ finalStyleProperty,
199
+ options
200
+ });
201
+ return `${acc}, ${interpolatedArg}`;
202
+ }, "");
203
+ return `${initialStylePropertyPart.function.name}(${interpolatedFunctionArgs.slice(2)})`;
204
+ }
205
+ if (typeof initialStylePropertyPart.number === "undefined") {
206
+ if (initialStylePropertyPart.unit !== finalStylePropertyPart.unit) {
207
+ throw new TypeError(`Non-animatable values cannot be interpolated. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
208
+ }
209
+ return `${initialStylePropertyPart.unit}`;
210
+ }
211
+ if (initialStylePropertyPart.unit !== finalStylePropertyPart.unit && initialStylePropertyPart.number !== 0 && finalStylePropertyPart.number !== 0) {
212
+ throw new TypeError(`The units of the start and end values must match. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
213
+ }
214
+ const startNumber = initialStylePropertyPart.number;
215
+ const endNumber = finalStylePropertyPart.number || 0;
216
+ const interpolatedNumber = interpolate(inputValue, inputRange, [startNumber, endNumber], options);
217
+ const interpolatedUnit = initialStylePropertyPart.unit || finalStylePropertyPart.unit || "";
218
+ if (!interpolatedUnit) {
219
+ return interpolatedNumber;
220
+ }
221
+ return `${interpolatedNumber}${interpolatedUnit}`;
222
+ };
223
+ var interpolateProperty = ({
224
+ inputValue,
225
+ inputRange,
226
+ initialStyleProperty,
227
+ finalStyleProperty,
228
+ options
229
+ }) => {
230
+ if (typeof initialStyleProperty !== typeof finalStyleProperty && initialStyleProperty !== 0 && finalStyleProperty !== 0) {
231
+ throw new TypeError(`The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
232
+ }
233
+ const initialStylePropertyParts = breakDownValueIntoUnitNumberAndFunctions(initialStyleProperty);
234
+ const finalStylePropertyParts = breakDownValueIntoUnitNumberAndFunctions(finalStyleProperty);
235
+ if (initialStylePropertyParts.length !== finalStylePropertyParts.length) {
236
+ throw new TypeError(`The start and end values must have the same structure. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`);
237
+ }
238
+ const interpolatedValue = initialStylePropertyParts.reduce((acc, initialStylePropertyPart, index) => {
239
+ return `${acc} ${interpolatedPropertyPart({
240
+ inputValue,
241
+ inputRange,
242
+ initialStylePropertyPart,
243
+ finalStylePropertyPart: finalStylePropertyParts[index],
244
+ initialStyleProperty,
245
+ finalStyleProperty,
246
+ options
247
+ })}`;
248
+ }, "");
249
+ return interpolatedValue.slice(1);
250
+ };
251
+ var interpolateStylesFunction = ({
252
+ inputValue,
253
+ inputRange,
254
+ initialStyle,
255
+ finalStyle,
256
+ options
257
+ }) => {
258
+ const [startingValue, endingValue] = inputRange;
259
+ return Object.keys(initialStyle).reduce((acc, key) => {
260
+ const value = finalStyle[key];
261
+ if (value === undefined || value === null) {
262
+ return {
263
+ ...acc,
264
+ [key]: initialStyle[key]
265
+ };
266
+ }
267
+ const finalStyleValue = interpolateProperty({
268
+ inputValue,
269
+ inputRange: [startingValue, endingValue],
270
+ initialStyleProperty: initialStyle[key],
271
+ finalStyleProperty: finalStyle[key],
272
+ options
334
273
  });
274
+ if (!isNaN(Number(finalStyleValue))) {
275
+ return {
276
+ ...acc,
277
+ [key]: Number(finalStyleValue)
278
+ };
279
+ }
280
+ return {
281
+ ...acc,
282
+ [key]: finalStyleValue
283
+ };
284
+ }, {});
335
285
  };
336
-
337
- const lengthUnits = [
338
- 'px',
339
- 'em',
340
- 'rem',
341
- 'pt',
342
- 'cap',
343
- 'ch',
344
- 'ex',
345
- 'ic',
346
- 'lh',
347
- 'rlh',
348
- 'vmax',
349
- 'vmin',
350
- 'vb',
351
- 'vi',
352
- 'cqw',
353
- 'vh',
354
- 'vw',
355
- 'cqh',
356
- 'cqi',
357
- 'cqb',
358
- 'cqmin',
359
- 'cqmax',
360
- 'cm',
361
- 'mm',
362
- 'Q',
363
- 'in',
364
- 'pc',
286
+ var interpolateStyles = (input, inputRange, outputStylesRange, options) => {
287
+ if (typeof input === "undefined") {
288
+ throw new Error("input can not be undefined");
289
+ }
290
+ if (typeof inputRange === "undefined") {
291
+ throw new Error("inputRange can not be undefined");
292
+ }
293
+ if (typeof outputStylesRange === "undefined") {
294
+ throw new Error("outputRange can not be undefined");
295
+ }
296
+ if (inputRange.length !== outputStylesRange.length) {
297
+ throw new Error("inputRange (" + inputRange.length + ") and outputStylesRange (" + outputStylesRange.length + ") must have the same length");
298
+ }
299
+ checkInputRange(inputRange);
300
+ checkStylesRange(outputStylesRange);
301
+ let startIndex = inputRange.findIndex((step) => input < step) - 1;
302
+ if (startIndex === -2) {
303
+ startIndex = inputRange.length - 2;
304
+ }
305
+ const endIndex = startIndex + 1;
306
+ const startingValue = inputRange[startIndex];
307
+ const endingValue = inputRange[endIndex];
308
+ const initialStyle = outputStylesRange[startIndex];
309
+ const finalStyle = outputStylesRange[endIndex];
310
+ const easing = options?.easing ?? ((num) => num);
311
+ const extrapolateLeft = options?.extrapolateLeft ?? "extend";
312
+ const extrapolateRight = options?.extrapolateRight ?? "extend";
313
+ return interpolateStylesFunction({
314
+ inputValue: input,
315
+ inputRange: [startingValue, endingValue],
316
+ initialStyle,
317
+ finalStyle,
318
+ options: {
319
+ easing,
320
+ extrapolateLeft,
321
+ extrapolateRight
322
+ }
323
+ });
324
+ };
325
+ // src/type.ts
326
+ var lengthUnits = [
327
+ "px",
328
+ "em",
329
+ "rem",
330
+ "pt",
331
+ "cap",
332
+ "ch",
333
+ "ex",
334
+ "ic",
335
+ "lh",
336
+ "rlh",
337
+ "vmax",
338
+ "vmin",
339
+ "vb",
340
+ "vi",
341
+ "cqw",
342
+ "vh",
343
+ "vw",
344
+ "cqh",
345
+ "cqi",
346
+ "cqb",
347
+ "cqmin",
348
+ "cqmax",
349
+ "cm",
350
+ "mm",
351
+ "Q",
352
+ "in",
353
+ "pc"
365
354
  ];
366
- const angleUnits = ['rad', 'deg', 'grad', 'turn'];
367
- const lengthPercentageUnits = ['%', ...lengthUnits];
355
+ var angleUnits = ["rad", "deg", "grad", "turn"];
356
+ var lengthPercentageUnits = ["%", ...lengthUnits];
368
357
 
369
- const isUnitWithString = (input, units) => {
370
- if (typeof input !== 'string') {
371
- return false;
372
- }
373
- if (!units.find((u) => input.endsWith(u))) {
374
- throw new Error(`input ${input} does not end with a valid unit. Valid units are: ${units.join(', ')}`);
375
- }
376
- const match = input.match(/([0-9.]+)([a-z%]+)/);
377
- if (!match) {
378
- throw new Error(`input ${input} is not a valid transform. Must be a number or a string ending in one of the following units: ${lengthUnits.join(', ')}`);
379
- }
380
- return true;
358
+ // src/transformation-helpers/make-transform/is-unit-with-string.ts
359
+ var isUnitWithString = (input, units) => {
360
+ if (typeof input !== "string") {
361
+ return false;
362
+ }
363
+ if (!units.find((u) => input.endsWith(u))) {
364
+ throw new Error(`input ${input} does not end with a valid unit. Valid units are: ${units.join(", ")}`);
365
+ }
366
+ const match = input.match(/([0-9.]+)([a-z%]+)/);
367
+ if (!match) {
368
+ throw new Error(`input ${input} is not a valid transform. Must be a number or a string ending in one of the following units: ${lengthUnits.join(", ")}`);
369
+ }
370
+ return true;
381
371
  };
382
372
 
383
- /* eslint-disable no-redeclare */
384
- /* Matrix transformation */
385
- const checkNumber = ({ num, param, api, }) => {
386
- if (typeof num === 'undefined') {
387
- throw new TypeError(`Argument passed to "${api}" for param "${param}" is undefined`);
388
- }
389
- if (typeof num !== 'number') {
390
- throw new TypeError(`Argument passed to "${api}" for param "${param}" is ${JSON.stringify(num)}`);
391
- }
392
- if (!Number.isFinite(num)) {
393
- throw new TypeError(`Argument passed to "${api}" for param "${param}" is ${JSON.stringify(num)} (must be finite)`);
394
- }
373
+ // src/transformation-helpers/make-transform/transform-functions.ts
374
+ var matrix = function(a, b, c, d, tx, ty) {
375
+ checkNumber({ num: a, param: "a", api: "matrix" });
376
+ checkNumber({ num: b, param: "b", api: "matrix" });
377
+ checkNumber({ num: c, param: "c", api: "matrix" });
378
+ checkNumber({ num: d, param: "d", api: "matrix" });
379
+ checkNumber({ num: tx, param: "tx", api: "matrix" });
380
+ checkNumber({ num: ty, param: "ty", api: "matrix" });
381
+ return `matrix(${a}, ${b}, ${c}, ${d}, ${tx}, ${ty})`;
382
+ };
383
+ var matrix3d = function(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
384
+ checkNumber({ num: a1, param: "a1", api: "matrix3d" });
385
+ checkNumber({ num: b1, param: "b1", api: "matrix3d" });
386
+ checkNumber({ num: c1, param: "c1", api: "matrix3d" });
387
+ checkNumber({ num: d1, param: "d1", api: "matrix3d" });
388
+ checkNumber({ num: a2, param: "a2", api: "matrix3d" });
389
+ checkNumber({ num: b2, param: "b2", api: "matrix3d" });
390
+ checkNumber({ num: c2, param: "c2", api: "matrix3d" });
391
+ checkNumber({ num: d2, param: "d2", api: "matrix3d" });
392
+ checkNumber({ num: a3, param: "a3", api: "matrix3d" });
393
+ checkNumber({ num: b3, param: "b3", api: "matrix3d" });
394
+ checkNumber({ num: c3, param: "c3", api: "matrix3d" });
395
+ checkNumber({ num: d3, param: "d3", api: "matrix3d" });
396
+ checkNumber({ num: a4, param: "a4", api: "matrix3d" });
397
+ checkNumber({ num: b4, param: "b4", api: "matrix3d" });
398
+ checkNumber({ num: c4, param: "c4", api: "matrix3d" });
399
+ checkNumber({ num: d4, param: "d4", api: "matrix3d" });
400
+ return `matrix3d(${a1}, ${b1}, ${c1}, ${d1}, ${a2}, ${b2}, ${c2}, ${d2}, ${a3}, ${b3}, ${c3}, ${d3}, ${a4}, ${b4}, ${c4}, ${d4})`;
401
+ };
402
+ var perspective = function(length, unit = "px") {
403
+ if (isUnitWithString(length, lengthUnits)) {
404
+ return `perspective(${length})`;
405
+ }
406
+ checkNumber({ num: length, param: "length", api: "perspective" });
407
+ return `perspective(${length}${unit})`;
408
+ };
409
+ var rotate = function(angle, unit = "deg") {
410
+ if (isUnitWithString(angle, angleUnits)) {
411
+ return `rotate(${angle})`;
412
+ }
413
+ checkNumber({ num: angle, param: "angle", api: "rotate" });
414
+ return `rotate(${angle}${unit})`;
415
+ };
416
+ var rotate3d = function(x, y, z, angle, unit = "deg") {
417
+ checkNumber({ num: x, param: "x", api: "rotate3d" });
418
+ checkNumber({ num: y, param: "y", api: "rotate3d" });
419
+ checkNumber({ num: z, param: "z", api: "rotate3d" });
420
+ if (isUnitWithString(angle, angleUnits)) {
421
+ return `rotate3d(${x}, ${y}, ${z}, ${angle})`;
422
+ }
423
+ checkNumber({ num: angle, param: "angle", api: "rotate3d" });
424
+ return `rotate3d(${x}, ${y}, ${z}, ${angle}${unit})`;
425
+ };
426
+ var rotateX = function(angle, unit = "deg") {
427
+ if (isUnitWithString(angle, angleUnits)) {
428
+ return `rotateX(${angle})`;
429
+ }
430
+ checkNumber({ num: angle, param: "angle", api: "rotateX" });
431
+ return `rotateX(${angle}${unit})`;
432
+ };
433
+ var rotateY = function(angle, unit = "deg") {
434
+ if (isUnitWithString(angle, angleUnits)) {
435
+ return `rotateY(${angle})`;
436
+ }
437
+ checkNumber({ num: angle, param: "angle", api: "rotateY" });
438
+ return `rotateY(${angle}${unit})`;
439
+ };
440
+ var rotateZ = function(angle, unit = "deg") {
441
+ if (isUnitWithString(angle, angleUnits)) {
442
+ return `rotateZ(${angle})`;
443
+ }
444
+ checkNumber({ num: angle, param: "angle", api: "rotateZ" });
445
+ return `rotateZ(${angle}${unit})`;
446
+ };
447
+ var scale = function(x, y = x) {
448
+ checkNumber({ num: x, param: "x", api: "scale" });
449
+ return `scale(${x}, ${y})`;
450
+ };
451
+ var scale3d = function(x, y, z) {
452
+ checkNumber({ num: x, param: "x", api: "scale3d" });
453
+ checkNumber({ num: y, param: "y", api: "scale3d" });
454
+ checkNumber({ num: z, param: "z", api: "scale3d" });
455
+ return `scale3d(${x}, ${y}, ${z})`;
456
+ };
457
+ var scaleX = function(x) {
458
+ checkNumber({ num: x, param: "x", api: "scaleX" });
459
+ return `scaleX(${x})`;
460
+ };
461
+ var scaleY = function(y) {
462
+ checkNumber({ num: y, param: "y", api: "scaleY" });
463
+ return `scaleY(${y})`;
464
+ };
465
+ var scaleZ = function(z) {
466
+ checkNumber({ num: z, param: "z", api: "scaleZ" });
467
+ return `scaleZ(${z})`;
468
+ };
469
+ var skew = function(...args) {
470
+ const [arg1, arg2, arg3, arg4] = args;
471
+ if (arguments.length === 1) {
472
+ if (isUnitWithString(arg1, angleUnits)) {
473
+ return `skew(${arg1}, ${arg1})`;
474
+ }
475
+ checkNumber({ num: arg1, param: "angle", api: "skew" });
476
+ return `skew(${arg1}deg, ${arg1}deg)`;
477
+ }
478
+ if (arguments.length === 2) {
479
+ if (isUnitWithString(arg1, angleUnits) && isUnitWithString(arg2, angleUnits)) {
480
+ return `skew(${arg1}, ${arg2})`;
481
+ }
482
+ if (typeof arg1 === "number" && typeof arg2 !== "number") {
483
+ checkNumber({ num: arg1, param: "angle", api: "skew" });
484
+ return `skew(${arg1}${arg2}, ${arg1}${arg2})`;
485
+ }
486
+ if (typeof arg1 === "number" && typeof arg2 === "number") {
487
+ checkNumber({ num: arg1, param: "angle", api: "skew" });
488
+ checkNumber({ num: arg2, param: "angle", api: "skew" });
489
+ return `skew(${arg1}deg, ${arg2}deg)`;
490
+ }
491
+ }
492
+ if (arguments.length === 4) {
493
+ if (typeof arg1 === "number" && isUnitWithString(arg2, angleUnits) && typeof arg3 === "number" && isUnitWithString(arg4, angleUnits)) {
494
+ checkNumber({ num: arg1, param: "angle", api: "skew" });
495
+ checkNumber({ num: arg3, param: "angle", api: "skew" });
496
+ return `skew(${arg1}${arg2}, ${arg3}${arg4})`;
497
+ }
498
+ }
499
+ throw new TypeError([
500
+ "skew() supports only the following signatures:",
501
+ "skew(angle: AngleUnitString): string;",
502
+ "skew(angle: AngleUnitString, angle2: AngleUnitString): string;",
503
+ "skew(angle: number, unit: AngleUnit): string;",
504
+ "skew(angleX: number, angleY: number): string;",
505
+ "skew(angleX: number, unitX: AngleUnit, angleY: number, unitY: AngleUnit): string;"
506
+ ].join("\n"));
507
+ };
508
+ var skewX = function(angle, unit = "deg") {
509
+ if (isUnitWithString(angle, angleUnits)) {
510
+ return `skewX(${angle})`;
511
+ }
512
+ checkNumber({ num: angle, param: "angle", api: "skewX" });
513
+ return `skewX(${angle}${unit})`;
514
+ };
515
+ var skewY = function(angle, unit = "deg") {
516
+ if (isUnitWithString(angle, angleUnits)) {
517
+ return `skewY(${angle})`;
518
+ }
519
+ checkNumber({ num: angle, param: "angle", api: "skewY" });
520
+ return `skewY(${angle}${unit})`;
521
+ };
522
+ var translate = function(...args) {
523
+ const [arg1, arg2, arg3, arg4] = args;
524
+ if (arguments.length === 1) {
525
+ if (isUnitWithString(arg1, lengthPercentageUnits)) {
526
+ return `translate(${arg1})`;
527
+ }
528
+ checkNumber({ num: arg1, param: "x", api: "translate" });
529
+ return `translate(${arg1}px)`;
530
+ }
531
+ if (arguments.length === 2) {
532
+ if (typeof arg1 === "number" && typeof arg2 === "number") {
533
+ checkNumber({ num: arg1, param: "x", api: "translate" });
534
+ checkNumber({ num: arg2, param: "y", api: "translate" });
535
+ return `translate(${arg1}px, ${arg2}px)`;
536
+ }
537
+ if (isUnitWithString(arg1, lengthPercentageUnits) && isUnitWithString(arg2, lengthPercentageUnits)) {
538
+ return `translate(${arg1}, ${arg2})`;
539
+ }
540
+ if (typeof arg1 === "number" && typeof arg2 !== "number") {
541
+ checkNumber({ num: arg1, param: "x", api: "translate" });
542
+ return `translate(${arg1}${arg2})`;
543
+ }
544
+ }
545
+ if (arguments.length === 4) {
546
+ if (typeof arg1 === "number" && typeof arg3 === "number") {
547
+ checkNumber({ num: arg1, param: "x", api: "translate" });
548
+ checkNumber({ num: arg3, param: "y", api: "translate" });
549
+ return `translate(${arg1}${arg2}, ${arg3}${arg4})`;
550
+ }
551
+ }
552
+ throw new TypeError([
553
+ `translate() supports only the following signatures:`,
554
+ `translate(x: LengthPercentageUnitString)`,
555
+ `translate(x: number)`,
556
+ `translate(x: number, y: number)`,
557
+ `translate(translation: number, unit: LengthPercentageUnit)`,
558
+ `translate(x: number, unitX: LengthPercentageUnit, y: number, unitY: LengthPercentageUnit): string;`
559
+ ].join("\n"));
560
+ };
561
+ var translate3d = function(...args) {
562
+ if (arguments.length === 3) {
563
+ const [x, y, z] = args;
564
+ const vars = [x, y, z].map((arg, i) => {
565
+ if (isUnitWithString(arg, lengthPercentageUnits)) {
566
+ return arg;
567
+ }
568
+ checkNumber({
569
+ num: arg,
570
+ param: i === 0 ? "x" : i === 1 ? "y" : "z",
571
+ api: "translate3d"
572
+ });
573
+ if (typeof arg === "number") {
574
+ return `${arg}px`;
575
+ }
576
+ return arg;
577
+ });
578
+ return `translate3d(${vars.join(", ")})`;
579
+ }
580
+ if (arguments.length === 6) {
581
+ const [x, unitX, y, unitY, z, unitZ] = args;
582
+ if (typeof x === "number" && typeof y === "number" && typeof z === "number") {
583
+ checkNumber({ num: x, param: "x", api: "translate3d" });
584
+ checkNumber({ num: y, param: "y", api: "translate3d" });
585
+ checkNumber({ num: z, param: "z", api: "translate3d" });
586
+ return `translate3d(${x}${unitX}, ${y}${unitY}, ${z}${unitZ})`;
587
+ }
588
+ }
589
+ throw new TypeError([
590
+ `translate3d() supports only the following signatures:`,
591
+ `translate3d(x: LengthPercentageUnitString, y: LengthPercentageUnitString, z: LengthPercentageUnitString)`,
592
+ `translate3d(x: number, unitX: LengthPercentageUnit, y: number, unitY: LengthPercentageUnit, z: number, unitZ: LengthUnit)`
593
+ ].join("\n"));
594
+ };
595
+ var translateX = function(x, unit = "px") {
596
+ if (isUnitWithString(x, lengthPercentageUnits)) {
597
+ return `translateX(${x})`;
598
+ }
599
+ checkNumber({ num: x, param: "x", api: "translateX" });
600
+ return `translateX(${x}${unit})`;
601
+ };
602
+ var translateY = function(y, unit = "px") {
603
+ if (isUnitWithString(y, lengthPercentageUnits)) {
604
+ return `translateY(${y})`;
605
+ }
606
+ checkNumber({ num: y, param: "y", api: "translateY" });
607
+ return `translateY(${y}${unit})`;
608
+ };
609
+ var translateZ = function(z, unit = "px") {
610
+ if (isUnitWithString(z, lengthUnits)) {
611
+ return `translateZ(${z})`;
612
+ }
613
+ checkNumber({ num: z, param: "z", api: "translateZ" });
614
+ return `translateZ(${z}${unit})`;
615
+ };
616
+ var checkNumber = ({
617
+ num,
618
+ param,
619
+ api
620
+ }) => {
621
+ if (typeof num === "undefined") {
622
+ throw new TypeError(`Argument passed to "${api}" for param "${param}" is undefined`);
623
+ }
624
+ if (typeof num !== "number") {
625
+ throw new TypeError(`Argument passed to "${api}" for param "${param}" is ${JSON.stringify(num)}`);
626
+ }
627
+ if (!Number.isFinite(num)) {
628
+ throw new TypeError(`Argument passed to "${api}" for param "${param}" is ${JSON.stringify(num)} (must be finite)`);
629
+ }
395
630
  };
396
- function matrix(a, b, c, d, tx, ty) {
397
- checkNumber({ num: a, param: 'a', api: 'matrix' });
398
- checkNumber({ num: b, param: 'b', api: 'matrix' });
399
- checkNumber({ num: c, param: 'c', api: 'matrix' });
400
- checkNumber({ num: d, param: 'd', api: 'matrix' });
401
- checkNumber({ num: tx, param: 'tx', api: 'matrix' });
402
- checkNumber({ num: ty, param: 'ty', api: 'matrix' });
403
- return `matrix(${a}, ${b}, ${c}, ${d}, ${tx}, ${ty})`;
404
- }
405
- function matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
406
- checkNumber({ num: a1, param: 'a1', api: 'matrix3d' });
407
- checkNumber({ num: b1, param: 'b1', api: 'matrix3d' });
408
- checkNumber({ num: c1, param: 'c1', api: 'matrix3d' });
409
- checkNumber({ num: d1, param: 'd1', api: 'matrix3d' });
410
- checkNumber({ num: a2, param: 'a2', api: 'matrix3d' });
411
- checkNumber({ num: b2, param: 'b2', api: 'matrix3d' });
412
- checkNumber({ num: c2, param: 'c2', api: 'matrix3d' });
413
- checkNumber({ num: d2, param: 'd2', api: 'matrix3d' });
414
- checkNumber({ num: a3, param: 'a3', api: 'matrix3d' });
415
- checkNumber({ num: b3, param: 'b3', api: 'matrix3d' });
416
- checkNumber({ num: c3, param: 'c3', api: 'matrix3d' });
417
- checkNumber({ num: d3, param: 'd3', api: 'matrix3d' });
418
- checkNumber({ num: a4, param: 'a4', api: 'matrix3d' });
419
- checkNumber({ num: b4, param: 'b4', api: 'matrix3d' });
420
- checkNumber({ num: c4, param: 'c4', api: 'matrix3d' });
421
- checkNumber({ num: d4, param: 'd4', api: 'matrix3d' });
422
- return `matrix3d(${a1}, ${b1}, ${c1}, ${d1}, ${a2}, ${b2}, ${c2}, ${d2}, ${a3}, ${b3}, ${c3}, ${d3}, ${a4}, ${b4}, ${c4}, ${d4})`;
423
- }
424
- function perspective(length, unit = 'px') {
425
- if (isUnitWithString(length, lengthUnits)) {
426
- return `perspective(${length})`;
427
- }
428
- checkNumber({ num: length, param: 'length', api: 'perspective' });
429
- return `perspective(${length}${unit})`;
430
- }
431
- function rotate(angle, unit = 'deg') {
432
- if (isUnitWithString(angle, angleUnits)) {
433
- return `rotate(${angle})`;
434
- }
435
- checkNumber({ num: angle, param: 'angle', api: 'rotate' });
436
- return `rotate(${angle}${unit})`;
437
- }
438
- function rotate3d(x, y, z, angle, unit = 'deg') {
439
- checkNumber({ num: x, param: 'x', api: 'rotate3d' });
440
- checkNumber({ num: y, param: 'y', api: 'rotate3d' });
441
- checkNumber({ num: z, param: 'z', api: 'rotate3d' });
442
- if (isUnitWithString(angle, angleUnits)) {
443
- return `rotate3d(${x}, ${y}, ${z}, ${angle})`;
444
- }
445
- checkNumber({ num: angle, param: 'angle', api: 'rotate3d' });
446
- return `rotate3d(${x}, ${y}, ${z}, ${angle}${unit})`;
447
- }
448
- function rotateX(angle, unit = 'deg') {
449
- if (isUnitWithString(angle, angleUnits)) {
450
- return `rotateX(${angle})`;
451
- }
452
- checkNumber({ num: angle, param: 'angle', api: 'rotateX' });
453
- return `rotateX(${angle}${unit})`;
454
- }
455
- function rotateY(angle, unit = 'deg') {
456
- if (isUnitWithString(angle, angleUnits)) {
457
- return `rotateY(${angle})`;
458
- }
459
- checkNumber({ num: angle, param: 'angle', api: 'rotateY' });
460
- return `rotateY(${angle}${unit})`;
461
- }
462
- function rotateZ(angle, unit = 'deg') {
463
- if (isUnitWithString(angle, angleUnits)) {
464
- return `rotateZ(${angle})`;
465
- }
466
- checkNumber({ num: angle, param: 'angle', api: 'rotateZ' });
467
- return `rotateZ(${angle}${unit})`;
468
- }
469
- /* Scale */
470
- function scale(x, y = x) {
471
- checkNumber({ num: x, param: 'x', api: 'scale' });
472
- return `scale(${x}, ${y})`;
473
- }
474
- function scale3d(x, y, z) {
475
- checkNumber({ num: x, param: 'x', api: 'scale3d' });
476
- checkNumber({ num: y, param: 'y', api: 'scale3d' });
477
- checkNumber({ num: z, param: 'z', api: 'scale3d' });
478
- return `scale3d(${x}, ${y}, ${z})`;
479
- }
480
- function scaleX(x) {
481
- checkNumber({ num: x, param: 'x', api: 'scaleX' });
482
- return `scaleX(${x})`;
483
- }
484
- function scaleY(y) {
485
- checkNumber({ num: y, param: 'y', api: 'scaleY' });
486
- return `scaleY(${y})`;
487
- }
488
- function scaleZ(z) {
489
- checkNumber({ num: z, param: 'z', api: 'scaleZ' });
490
- return `scaleZ(${z})`;
491
- }
492
- function skew(...args) {
493
- const [arg1, arg2, arg3, arg4] = args;
494
- if (arguments.length === 1) {
495
- // Case A
496
- if (isUnitWithString(arg1, angleUnits)) {
497
- return `skew(${arg1}, ${arg1})`;
498
- }
499
- // Case Z
500
- checkNumber({ num: arg1, param: 'angle', api: 'skew' });
501
- return `skew(${arg1}deg, ${arg1}deg)`;
502
- }
503
- if (arguments.length === 2) {
504
- // Case B
505
- if (isUnitWithString(arg1, angleUnits) &&
506
- isUnitWithString(arg2, angleUnits)) {
507
- return `skew(${arg1}, ${arg2})`;
508
- }
509
- // Case C
510
- if (typeof arg1 === 'number' && typeof arg2 !== 'number') {
511
- checkNumber({ num: arg1, param: 'angle', api: 'skew' });
512
- return `skew(${arg1}${arg2}, ${arg1}${arg2})`;
513
- }
514
- // Case D
515
- if (typeof arg1 === 'number' && typeof arg2 === 'number') {
516
- checkNumber({ num: arg1, param: 'angle', api: 'skew' });
517
- checkNumber({ num: arg2, param: 'angle', api: 'skew' });
518
- return `skew(${arg1}deg, ${arg2}deg)`;
519
- }
520
- }
521
- if (arguments.length === 4) {
522
- // Case E
523
- if (typeof arg1 === 'number' &&
524
- isUnitWithString(arg2, angleUnits) &&
525
- typeof arg3 === 'number' &&
526
- isUnitWithString(arg4, angleUnits)) {
527
- checkNumber({ num: arg1, param: 'angle', api: 'skew' });
528
- checkNumber({ num: arg3, param: 'angle', api: 'skew' });
529
- return `skew(${arg1}${arg2}, ${arg3}${arg4})`;
530
- }
531
- }
532
- throw new TypeError([
533
- 'skew() supports only the following signatures:',
534
- 'skew(angle: AngleUnitString): string;',
535
- 'skew(angle: AngleUnitString, angle2: AngleUnitString): string;',
536
- 'skew(angle: number, unit: AngleUnit): string;',
537
- 'skew(angleX: number, angleY: number): string;',
538
- 'skew(angleX: number, unitX: AngleUnit, angleY: number, unitY: AngleUnit): string;',
539
- ].join('\n'));
540
- }
541
- function skewX(angle, unit = 'deg') {
542
- if (isUnitWithString(angle, angleUnits)) {
543
- return `skewX(${angle})`;
544
- }
545
- checkNumber({ num: angle, param: 'angle', api: 'skewX' });
546
- return `skewX(${angle}${unit})`;
547
- }
548
- function skewY(angle, unit = 'deg') {
549
- if (isUnitWithString(angle, angleUnits)) {
550
- return `skewY(${angle})`;
551
- }
552
- checkNumber({ num: angle, param: 'angle', api: 'skewY' });
553
- return `skewY(${angle}${unit})`;
554
- }
555
- function translate(...args) {
556
- const [arg1, arg2, arg3, arg4] = args;
557
- if (arguments.length === 1) {
558
- // Case A
559
- if (isUnitWithString(arg1, lengthPercentageUnits)) {
560
- return `translate(${arg1})`;
561
- }
562
- // Case B
563
- checkNumber({ num: arg1, param: 'x', api: 'translate' });
564
- return `translate(${arg1}px)`;
565
- }
566
- if (arguments.length === 2) {
567
- // Case C
568
- if (typeof arg1 === 'number' && typeof arg2 === 'number') {
569
- checkNumber({ num: arg1, param: 'x', api: 'translate' });
570
- checkNumber({ num: arg2, param: 'y', api: 'translate' });
571
- return `translate(${arg1}px, ${arg2}px)`;
572
- }
573
- // Case C.1
574
- if (isUnitWithString(arg1, lengthPercentageUnits) &&
575
- isUnitWithString(arg2, lengthPercentageUnits)) {
576
- return `translate(${arg1}, ${arg2})`;
577
- }
578
- // Case D
579
- if (typeof arg1 === 'number' && typeof arg2 !== 'number') {
580
- checkNumber({ num: arg1, param: 'x', api: 'translate' });
581
- return `translate(${arg1}${arg2})`;
582
- }
583
- }
584
- if (arguments.length === 4) {
585
- // Case E
586
- if (typeof arg1 === 'number' && typeof arg3 === 'number') {
587
- checkNumber({ num: arg1, param: 'x', api: 'translate' });
588
- checkNumber({ num: arg3, param: 'y', api: 'translate' });
589
- return `translate(${arg1}${arg2}, ${arg3}${arg4})`;
590
- }
591
- }
592
- throw new TypeError([
593
- `translate() supports only the following signatures:`,
594
- `translate(x: LengthPercentageUnitString)`,
595
- `translate(x: number)`,
596
- `translate(x: number, y: number)`,
597
- `translate(translation: number, unit: LengthPercentageUnit)`,
598
- `translate(x: number, unitX: LengthPercentageUnit, y: number, unitY: LengthPercentageUnit): string;`,
599
- ].join('\n'));
600
- }
601
- function translate3d(...args) {
602
- if (arguments.length === 3) {
603
- const [x, y, z] = args;
604
- const vars = [x, y, z].map((arg, i) => {
605
- if (isUnitWithString(arg, lengthPercentageUnits)) {
606
- return arg;
607
- }
608
- checkNumber({
609
- num: arg,
610
- param: i === 0 ? 'x' : i === 1 ? 'y' : 'z',
611
- api: 'translate3d',
612
- });
613
- if (typeof arg === 'number') {
614
- return `${arg}px`;
615
- }
616
- return arg;
617
- });
618
- return `translate3d(${vars.join(', ')})`;
619
- }
620
- if (arguments.length === 6) {
621
- const [x, unitX, y, unitY, z, unitZ] = args;
622
- if (typeof x === 'number' &&
623
- typeof y === 'number' &&
624
- typeof z === 'number') {
625
- checkNumber({ num: x, param: 'x', api: 'translate3d' });
626
- checkNumber({ num: y, param: 'y', api: 'translate3d' });
627
- checkNumber({ num: z, param: 'z', api: 'translate3d' });
628
- return `translate3d(${x}${unitX}, ${y}${unitY}, ${z}${unitZ})`;
629
- }
630
- }
631
- throw new TypeError([
632
- `translate3d() supports only the following signatures:`,
633
- `translate3d(x: LengthPercentageUnitString, y: LengthPercentageUnitString, z: LengthPercentageUnitString)`,
634
- `translate3d(x: number, unitX: LengthPercentageUnit, y: number, unitY: LengthPercentageUnit, z: number, unitZ: LengthUnit)`,
635
- ].join('\n'));
636
- }
637
- function translateX(x, unit = 'px') {
638
- if (isUnitWithString(x, lengthPercentageUnits)) {
639
- return `translateX(${x})`;
640
- }
641
- checkNumber({ num: x, param: 'x', api: 'translateX' });
642
- return `translateX(${x}${unit})`;
643
- }
644
- function translateY(y, unit = 'px') {
645
- if (isUnitWithString(y, lengthPercentageUnits)) {
646
- return `translateY(${y})`;
647
- }
648
- checkNumber({ num: y, param: 'y', api: 'translateY' });
649
- return `translateY(${y}${unit})`;
650
- }
651
- function translateZ(z, unit = 'px') {
652
- if (isUnitWithString(z, lengthUnits)) {
653
- return `translateZ(${z})`;
654
- }
655
- checkNumber({ num: z, param: 'z', api: 'translateZ' });
656
- return `translateZ(${z}${unit})`;
657
- }
658
631
 
632
+ // src/transformation-helpers/make-transform/index.ts
659
633
  function makeTransform(transforms) {
660
- return transforms.join(' ');
634
+ return transforms.join(" ");
661
635
  }
662
-
663
- export { interpolateStyles, makeTransform, matrix, matrix3d, perspective, rotate, rotate3d, rotateX, rotateY, rotateZ, scale, scale3d, scaleX, scaleY, scaleZ, skew, skewX, skewY, translate, translate3d, translateX, translateY, translateZ };
636
+ export {
637
+ translateZ,
638
+ translateY,
639
+ translateX,
640
+ translate3d,
641
+ translate,
642
+ skewY,
643
+ skewX,
644
+ skew,
645
+ scaleZ,
646
+ scaleY,
647
+ scaleX,
648
+ scale3d,
649
+ scale,
650
+ rotateZ,
651
+ rotateY,
652
+ rotateX,
653
+ rotate3d,
654
+ rotate,
655
+ perspective,
656
+ matrix3d,
657
+ matrix,
658
+ makeTransform,
659
+ interpolateStyles
660
+ };