@remotion/animation-utils 4.0.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +7 -0
  3. package/dist/esm/index.d.ts +3 -0
  4. package/dist/esm/index.mjs +662 -0
  5. package/dist/esm/test/interpolate-styles.test.d.ts +1 -0
  6. package/dist/esm/test/make-transform.test.d.ts +1 -0
  7. package/dist/esm/transformation-helpers/interpolate-styles/constants.d.ts +3 -0
  8. package/dist/esm/transformation-helpers/interpolate-styles/index.d.ts +8 -0
  9. package/dist/esm/transformation-helpers/interpolate-styles/utils.d.ts +41 -0
  10. package/dist/esm/transformation-helpers/make-transform/index.d.ts +4 -0
  11. package/dist/esm/transformation-helpers/make-transform/is-unit-with-string.d.ts +1 -0
  12. package/dist/esm/transformation-helpers/make-transform/transform-functions.d.ts +46 -0
  13. package/dist/esm/type.d.ts +31 -0
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.js +18 -0
  16. package/dist/transformation-helpers/interpolate-styles/constants.d.ts +3 -0
  17. package/dist/transformation-helpers/interpolate-styles/constants.js +7 -0
  18. package/dist/transformation-helpers/interpolate-styles/index.d.ts +8 -0
  19. package/dist/transformation-helpers/interpolate-styles/index.js +191 -0
  20. package/dist/transformation-helpers/interpolate-styles/utils.d.ts +41 -0
  21. package/dist/transformation-helpers/interpolate-styles/utils.js +150 -0
  22. package/dist/transformation-helpers/make-transform/index.d.ts +4 -0
  23. package/dist/transformation-helpers/make-transform/index.js +29 -0
  24. package/dist/transformation-helpers/make-transform/is-unit-with-string.d.ts +1 -0
  25. package/dist/transformation-helpers/make-transform/is-unit-with-string.js +18 -0
  26. package/dist/transformation-helpers/make-transform/transform-functions.d.ts +46 -0
  27. package/dist/transformation-helpers/make-transform/transform-functions.js +302 -0
  28. package/dist/type.d.ts +31 -0
  29. package/dist/type.js +34 -0
  30. package/package.json +58 -0
package/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2023 Chetan Karwa
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # `@remotion/animation-utils`
2
+
3
+ Docs: https://remotion.dev/docs/animation-utils
4
+
5
+ ## License
6
+
7
+ MIT
@@ -0,0 +1,3 @@
1
+ export * from './transformation-helpers/interpolate-styles/index.js';
2
+ export * from './transformation-helpers/make-transform';
3
+ export type { AngleUnit, LengthPercentageUnit, LengthUnit, TransformFunctionReturnType, } from './type';
@@ -0,0 +1,662 @@
1
+ import { Internals, interpolateColors, interpolate } from 'remotion';
2
+
3
+ const NUMBER = '[-+]?\\d*\\.?\\d+';
4
+ const PERCENTAGE = NUMBER + '%';
5
+
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
+ });
92
+ };
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
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
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
+ });
138
+ };
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);
148
+ };
149
+
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}`;
207
+ };
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
+ if (!finalStyle[key]) {
236
+ return {
237
+ ...acc,
238
+ [key]: initialStyle[key],
239
+ };
240
+ }
241
+ const finalStyleValue = interpolateProperty({
242
+ inputValue,
243
+ inputRange: [startingValue, endingValue],
244
+ initialStyleProperty: initialStyle[key],
245
+ finalStyleProperty: finalStyle[key],
246
+ options,
247
+ });
248
+ // Avoid number to be a string
249
+ if (!isNaN(Number(finalStyleValue))) {
250
+ return {
251
+ ...acc,
252
+ [key]: Number(finalStyleValue),
253
+ };
254
+ }
255
+ return {
256
+ ...acc,
257
+ [key]: finalStyleValue,
258
+ };
259
+ }, {});
260
+ };
261
+ function checkInputRange(arr) {
262
+ if (arr.length < 2) {
263
+ throw new Error('inputRange must have at least 2 elements');
264
+ }
265
+ for (let index = 0; index < arr.length; index++) {
266
+ if (typeof arr[index] !== 'number') {
267
+ throw new Error(`inputRange must contain only numbers`);
268
+ }
269
+ if (arr[index] === -Infinity || arr[index] === Infinity) {
270
+ throw new Error(`inputRange must contain only finite numbers, but got [${arr.join(',')}]`);
271
+ }
272
+ if (index > 0 && !(arr[index] > arr[index - 1])) {
273
+ throw new Error(`inputRange must be strictly monotonically non-decreasing but got [${arr.join(',')}]`);
274
+ }
275
+ }
276
+ }
277
+ function checkStylesRange(arr) {
278
+ if (arr.length < 2) {
279
+ throw new Error('outputStyles must have at least 2 elements');
280
+ }
281
+ for (const index in arr) {
282
+ if (typeof arr[index] !== 'object') {
283
+ throw new Error('outputStyles must contain only objects');
284
+ }
285
+ }
286
+ }
287
+ /**
288
+ * @description A function that interpolates between two styles based on an input range.
289
+ * @see [Documentation](https://www.remotion.dev/docs/animation-utils/interpolate-styles)
290
+ */
291
+ const interpolateStyles = (input, inputRange, outputStylesRange, options) => {
292
+ var _a, _b, _c;
293
+ if (typeof input === 'undefined') {
294
+ throw new Error('input can not be undefined');
295
+ }
296
+ if (typeof inputRange === 'undefined') {
297
+ throw new Error('inputRange can not be undefined');
298
+ }
299
+ if (typeof outputStylesRange === 'undefined') {
300
+ throw new Error('outputRange can not be undefined');
301
+ }
302
+ if (inputRange.length !== outputStylesRange.length) {
303
+ throw new Error('inputRange (' +
304
+ inputRange.length +
305
+ ') and outputStylesRange (' +
306
+ outputStylesRange.length +
307
+ ') must have the same length');
308
+ }
309
+ checkInputRange(inputRange);
310
+ checkStylesRange(outputStylesRange);
311
+ let startIndex = inputRange.findIndex((step) => input < step) - 1;
312
+ if (startIndex === -2) {
313
+ startIndex = inputRange.length - 2;
314
+ }
315
+ const endIndex = startIndex + 1;
316
+ const startingValue = inputRange[startIndex];
317
+ const endingValue = inputRange[endIndex];
318
+ const initialStyle = outputStylesRange[startIndex];
319
+ const finalStyle = outputStylesRange[endIndex];
320
+ const easing = (_a = options === null || options === void 0 ? void 0 : options.easing) !== null && _a !== void 0 ? _a : ((num) => num);
321
+ const extrapolateLeft = (_b = options === null || options === void 0 ? void 0 : options.extrapolateLeft) !== null && _b !== void 0 ? _b : 'extend';
322
+ const extrapolateRight = (_c = options === null || options === void 0 ? void 0 : options.extrapolateRight) !== null && _c !== void 0 ? _c : 'extend';
323
+ return interpolateStylesFunction({
324
+ inputValue: input,
325
+ inputRange: [startingValue, endingValue],
326
+ initialStyle,
327
+ finalStyle,
328
+ options: {
329
+ easing,
330
+ extrapolateLeft,
331
+ extrapolateRight,
332
+ },
333
+ });
334
+ };
335
+
336
+ const lengthUnits = [
337
+ 'px',
338
+ 'em',
339
+ 'rem',
340
+ 'pt',
341
+ 'cap',
342
+ 'ch',
343
+ 'ex',
344
+ 'ic',
345
+ 'lh',
346
+ 'rlh',
347
+ 'vmax',
348
+ 'vmin',
349
+ 'vb',
350
+ 'vi',
351
+ 'cqw',
352
+ 'vh',
353
+ 'vw',
354
+ 'cqh',
355
+ 'cqi',
356
+ 'cqb',
357
+ 'cqmin',
358
+ 'cqmax',
359
+ 'cm',
360
+ 'mm',
361
+ 'Q',
362
+ 'in',
363
+ 'pc',
364
+ ];
365
+ const angleUnits = ['rad', 'deg', 'grad', 'turn'];
366
+ const lengthPercentageUnits = ['%', ...lengthUnits];
367
+
368
+ const isUnitWithString = (input, units) => {
369
+ if (typeof input !== 'string') {
370
+ return false;
371
+ }
372
+ if (!units.find((u) => input.endsWith(u))) {
373
+ throw new Error(`input ${input} does not end with a valid unit. Valid units are: ${units.join(', ')}`);
374
+ }
375
+ const match = input.match(/([0-9.]+)([a-z%]+)/);
376
+ if (!match) {
377
+ 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(', ')}`);
378
+ }
379
+ return true;
380
+ };
381
+
382
+ /* eslint-disable no-redeclare */
383
+ /* Matrix transformation */
384
+ const checkNumber = ({ num, param, api, }) => {
385
+ if (typeof num === 'undefined') {
386
+ throw new TypeError(`Argument passed to "${api}" for param "${param}" is undefined`);
387
+ }
388
+ if (typeof num !== 'number') {
389
+ throw new TypeError(`Argument passed to "${api}" for param "${param}" is ${JSON.stringify(num)}`);
390
+ }
391
+ if (!Number.isFinite(num)) {
392
+ throw new TypeError(`Argument passed to "${api}" for param "${param}" is ${JSON.stringify(num)} (must be finite)`);
393
+ }
394
+ };
395
+ function matrix(a, b, c, d, tx, ty) {
396
+ checkNumber({ num: a, param: 'a', api: 'matrix' });
397
+ checkNumber({ num: b, param: 'b', api: 'matrix' });
398
+ checkNumber({ num: c, param: 'c', api: 'matrix' });
399
+ checkNumber({ num: d, param: 'd', api: 'matrix' });
400
+ checkNumber({ num: tx, param: 'tx', api: 'matrix' });
401
+ checkNumber({ num: ty, param: 'ty', api: 'matrix' });
402
+ return `matrix(${a}, ${b}, ${c}, ${d}, ${tx}, ${ty})`;
403
+ }
404
+ function matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
405
+ checkNumber({ num: a1, param: 'a1', api: 'matrix3d' });
406
+ checkNumber({ num: b1, param: 'b1', api: 'matrix3d' });
407
+ checkNumber({ num: c1, param: 'c1', api: 'matrix3d' });
408
+ checkNumber({ num: d1, param: 'd1', api: 'matrix3d' });
409
+ checkNumber({ num: a2, param: 'a2', api: 'matrix3d' });
410
+ checkNumber({ num: b2, param: 'b2', api: 'matrix3d' });
411
+ checkNumber({ num: c2, param: 'c2', api: 'matrix3d' });
412
+ checkNumber({ num: d2, param: 'd2', api: 'matrix3d' });
413
+ checkNumber({ num: a3, param: 'a3', api: 'matrix3d' });
414
+ checkNumber({ num: b3, param: 'b3', api: 'matrix3d' });
415
+ checkNumber({ num: c3, param: 'c3', api: 'matrix3d' });
416
+ checkNumber({ num: d3, param: 'd3', api: 'matrix3d' });
417
+ checkNumber({ num: a4, param: 'a4', api: 'matrix3d' });
418
+ checkNumber({ num: b4, param: 'b4', api: 'matrix3d' });
419
+ checkNumber({ num: c4, param: 'c4', api: 'matrix3d' });
420
+ checkNumber({ num: d4, param: 'd4', api: 'matrix3d' });
421
+ return `matrix3d(${a1}, ${b1}, ${c1}, ${d1}, ${a2}, ${b2}, ${c2}, ${d2}, ${a3}, ${b3}, ${c3}, ${d3}, ${a4}, ${b4}, ${c4}, ${d4})`;
422
+ }
423
+ function perspective(length, unit = 'px') {
424
+ if (isUnitWithString(length, lengthUnits)) {
425
+ return `perspective(${length})`;
426
+ }
427
+ checkNumber({ num: length, param: 'length', api: 'perspective' });
428
+ return `perspective(${length}${unit})`;
429
+ }
430
+ function rotate(angle, unit = 'deg') {
431
+ if (isUnitWithString(angle, angleUnits)) {
432
+ return `rotate(${angle})`;
433
+ }
434
+ checkNumber({ num: angle, param: 'angle', api: 'rotate' });
435
+ return `rotate(${angle}${unit})`;
436
+ }
437
+ function rotate3d(x, y, z, angle, unit = 'deg') {
438
+ checkNumber({ num: x, param: 'x', api: 'rotate3d' });
439
+ checkNumber({ num: y, param: 'y', api: 'rotate3d' });
440
+ checkNumber({ num: z, param: 'z', api: 'rotate3d' });
441
+ if (isUnitWithString(angle, angleUnits)) {
442
+ return `rotate3d(${x}, ${y}, ${z}, ${angle})`;
443
+ }
444
+ checkNumber({ num: angle, param: 'angle', api: 'rotate3d' });
445
+ return `rotate3d(${x}, ${y}, ${z}, ${angle}${unit})`;
446
+ }
447
+ function rotateX(angle, unit = 'deg') {
448
+ if (isUnitWithString(angle, angleUnits)) {
449
+ return `rotateX(${angle})`;
450
+ }
451
+ checkNumber({ num: angle, param: 'angle', api: 'rotateX' });
452
+ return `rotateX(${angle}${unit})`;
453
+ }
454
+ function rotateY(angle, unit = 'deg') {
455
+ if (isUnitWithString(angle, angleUnits)) {
456
+ return `rotateY(${angle})`;
457
+ }
458
+ checkNumber({ num: angle, param: 'angle', api: 'rotateY' });
459
+ return `rotateY(${angle}${unit})`;
460
+ }
461
+ function rotateZ(angle, unit = 'deg') {
462
+ if (isUnitWithString(angle, angleUnits)) {
463
+ return `rotateZ(${angle})`;
464
+ }
465
+ checkNumber({ num: angle, param: 'angle', api: 'rotateZ' });
466
+ return `rotateZ(${angle}${unit})`;
467
+ }
468
+ /* Scale */
469
+ function scale(x, y = x) {
470
+ checkNumber({ num: x, param: 'x', api: 'scale' });
471
+ return `scale(${x}, ${y})`;
472
+ }
473
+ function scale3d(x, y, z) {
474
+ checkNumber({ num: x, param: 'x', api: 'scale3d' });
475
+ checkNumber({ num: y, param: 'y', api: 'scale3d' });
476
+ checkNumber({ num: z, param: 'z', api: 'scale3d' });
477
+ return `scale3d(${x}, ${y}, ${z})`;
478
+ }
479
+ function scaleX(x) {
480
+ checkNumber({ num: x, param: 'x', api: 'scaleX' });
481
+ return `scaleX(${x})`;
482
+ }
483
+ function scaleY(y) {
484
+ checkNumber({ num: y, param: 'y', api: 'scaleY' });
485
+ return `scaleY(${y})`;
486
+ }
487
+ function scaleZ(z) {
488
+ checkNumber({ num: z, param: 'z', api: 'scaleZ' });
489
+ return `scaleZ(${z})`;
490
+ }
491
+ function skew(...args) {
492
+ const [arg1, arg2, arg3, arg4] = args;
493
+ if (arguments.length === 1) {
494
+ // Case A
495
+ if (isUnitWithString(arg1, angleUnits)) {
496
+ return `skew(${arg1}, ${arg1})`;
497
+ }
498
+ // Case Z
499
+ checkNumber({ num: arg1, param: 'angle', api: 'skew' });
500
+ return `skew(${arg1}deg, ${arg1}deg)`;
501
+ }
502
+ if (arguments.length === 2) {
503
+ // Case B
504
+ if (isUnitWithString(arg1, angleUnits) &&
505
+ isUnitWithString(arg2, angleUnits)) {
506
+ return `skew(${arg1}, ${arg2})`;
507
+ }
508
+ // Case C
509
+ if (typeof arg1 === 'number' && typeof arg2 !== 'number') {
510
+ checkNumber({ num: arg1, param: 'angle', api: 'skew' });
511
+ return `skew(${arg1}${arg2}, ${arg1}${arg2})`;
512
+ }
513
+ // Case D
514
+ if (typeof arg1 === 'number' && typeof arg2 === 'number') {
515
+ checkNumber({ num: arg1, param: 'angle', api: 'skew' });
516
+ checkNumber({ num: arg2, param: 'angle', api: 'skew' });
517
+ return `skew(${arg1}deg, ${arg2}deg)`;
518
+ }
519
+ }
520
+ if (arguments.length === 4) {
521
+ // Case E
522
+ if (typeof arg1 === 'number' &&
523
+ isUnitWithString(arg2, angleUnits) &&
524
+ typeof arg3 === 'number' &&
525
+ isUnitWithString(arg4, angleUnits)) {
526
+ checkNumber({ num: arg1, param: 'angle', api: 'skew' });
527
+ checkNumber({ num: arg3, param: 'angle', api: 'skew' });
528
+ return `skew(${arg1}${arg2}, ${arg3}${arg4})`;
529
+ }
530
+ }
531
+ throw new TypeError([
532
+ 'skew() supports only the following signatures:',
533
+ 'skew(angle: AngleUnitString): string;',
534
+ 'skew(angle: AngleUnitString, angle2: AngleUnitString): string;',
535
+ 'skew(angle: number, unit: AngleUnit): string;',
536
+ 'skew(angleX: number, angleY: number): string;',
537
+ 'skew(angleX: number, unitX: AngleUnit, angleY: number, unitY: AngleUnit): string;',
538
+ ].join('\n'));
539
+ }
540
+ function skewX(angle, unit = 'deg') {
541
+ if (isUnitWithString(angle, angleUnits)) {
542
+ return `skewX(${angle})`;
543
+ }
544
+ checkNumber({ num: angle, param: 'angle', api: 'skewX' });
545
+ return `skewX(${angle}${unit})`;
546
+ }
547
+ function skewY(angle, unit = 'deg') {
548
+ if (isUnitWithString(angle, angleUnits)) {
549
+ return `skewY(${angle})`;
550
+ }
551
+ checkNumber({ num: angle, param: 'angle', api: 'skewY' });
552
+ return `skewY(${angle}${unit})`;
553
+ }
554
+ function translate(...args) {
555
+ const [arg1, arg2, arg3, arg4] = args;
556
+ if (arguments.length === 1) {
557
+ // Case A
558
+ if (isUnitWithString(arg1, lengthPercentageUnits)) {
559
+ return `translate(${arg1})`;
560
+ }
561
+ // Case B
562
+ checkNumber({ num: arg1, param: 'x', api: 'translate' });
563
+ return `translate(${arg1}px)`;
564
+ }
565
+ if (arguments.length === 2) {
566
+ // Case C
567
+ if (typeof arg1 === 'number' && typeof arg2 === 'number') {
568
+ checkNumber({ num: arg1, param: 'x', api: 'translate' });
569
+ checkNumber({ num: arg2, param: 'y', api: 'translate' });
570
+ return `translate(${arg1}px, ${arg2}px)`;
571
+ }
572
+ // Case C.1
573
+ if (isUnitWithString(arg1, lengthPercentageUnits) &&
574
+ isUnitWithString(arg2, lengthPercentageUnits)) {
575
+ return `translate(${arg1}, ${arg2})`;
576
+ }
577
+ // Case D
578
+ if (typeof arg1 === 'number' && typeof arg2 !== 'number') {
579
+ checkNumber({ num: arg1, param: 'x', api: 'translate' });
580
+ return `translate(${arg1}${arg2})`;
581
+ }
582
+ }
583
+ if (arguments.length === 4) {
584
+ // Case E
585
+ if (typeof arg1 === 'number' && typeof arg3 === 'number') {
586
+ checkNumber({ num: arg1, param: 'x', api: 'translate' });
587
+ checkNumber({ num: arg3, param: 'y', api: 'translate' });
588
+ return `translate(${arg1}${arg2}, ${arg3}${arg4})`;
589
+ }
590
+ }
591
+ throw new TypeError([
592
+ `translate() supports only the following signatures:`,
593
+ `translate(x: LengthPercentageUnitString)`,
594
+ `translate(x: number)`,
595
+ `translate(x: number, y: number)`,
596
+ `translate(translation: number, unit: LengthPercentageUnit)`,
597
+ `translate(x: number, unitX: LengthPercentageUnit, y: number, unitY: LengthPercentageUnit): string;`,
598
+ ].join('\n'));
599
+ }
600
+ function translate3d(...args) {
601
+ if (arguments.length === 3) {
602
+ const [x, y, z] = args;
603
+ const vars = [x, y, z].map((arg, i) => {
604
+ if (isUnitWithString(arg, lengthPercentageUnits)) {
605
+ return arg;
606
+ }
607
+ checkNumber({
608
+ num: arg,
609
+ param: i === 0 ? 'x' : i === 1 ? 'y' : 'z',
610
+ api: 'translate3d',
611
+ });
612
+ if (typeof arg === 'number') {
613
+ return `${arg}px`;
614
+ }
615
+ return arg;
616
+ });
617
+ return `translate3d(${vars.join(', ')})`;
618
+ }
619
+ if (arguments.length === 6) {
620
+ const [x, unitX, y, unitY, z, unitZ] = args;
621
+ if (typeof x === 'number' &&
622
+ typeof y === 'number' &&
623
+ typeof z === 'number') {
624
+ checkNumber({ num: x, param: 'x', api: 'translate3d' });
625
+ checkNumber({ num: y, param: 'y', api: 'translate3d' });
626
+ checkNumber({ num: z, param: 'z', api: 'translate3d' });
627
+ return `translate3d(${x}${unitX}, ${y}${unitY}, ${z}${unitZ})`;
628
+ }
629
+ }
630
+ throw new TypeError([
631
+ `translate3d() supports only the following signatures:`,
632
+ `translate3d(x: LengthPercentageUnitString, y: LengthPercentageUnitString, z: LengthPercentageUnitString)`,
633
+ `translate3d(x: number, unitX: LengthPercentageUnit, y: number, unitY: LengthPercentageUnit, z: number, unitZ: LengthUnit)`,
634
+ ].join('\n'));
635
+ }
636
+ function translateX(x, unit = 'px') {
637
+ if (isUnitWithString(x, lengthPercentageUnits)) {
638
+ return `translateX(${x})`;
639
+ }
640
+ checkNumber({ num: x, param: 'x', api: 'translateX' });
641
+ return `translateX(${x}${unit})`;
642
+ }
643
+ function translateY(y, unit = 'px') {
644
+ if (isUnitWithString(y, lengthPercentageUnits)) {
645
+ return `translateY(${y})`;
646
+ }
647
+ checkNumber({ num: y, param: 'y', api: 'translateY' });
648
+ return `translateY(${y}${unit})`;
649
+ }
650
+ function translateZ(z, unit = 'px') {
651
+ if (isUnitWithString(z, lengthUnits)) {
652
+ return `translateZ(${z})`;
653
+ }
654
+ checkNumber({ num: z, param: 'z', api: 'translateZ' });
655
+ return `translateZ(${z}${unit})`;
656
+ }
657
+
658
+ function makeTransform(transforms) {
659
+ return transforms.join(' ');
660
+ }
661
+
662
+ export { interpolateStyles, makeTransform, matrix, matrix3d, perspective, rotate, rotate3d, rotateX, rotateY, rotateZ, scale, scale3d, scaleX, scaleY, scaleZ, skew, skewX, skewY, translate, translate3d, translateX, translateY, translateZ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};