@remotion/animation-utils 4.0.143 → 4.0.145

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