@remotion/studio-server 4.0.513 → 4.0.514

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 (56) hide show
  1. package/dist/codemods/delete-jsx-node.d.ts +2 -5
  2. package/dist/codemods/delete-jsx-node.js +23 -341
  3. package/dist/codemods/duplicate-composition.d.ts +1 -9
  4. package/dist/codemods/duplicate-composition.js +3 -49
  5. package/dist/codemods/format-inline-content.d.ts +0 -4
  6. package/dist/codemods/format-inline-content.js +7 -46
  7. package/dist/codemods/recast-mods.js +0 -18
  8. package/dist/codemods/reorder-sequence.d.ts +2 -2
  9. package/dist/codemods/reorder-sequence.js +12 -112
  10. package/dist/codemods/split-jsx-sequence.d.ts +1 -2
  11. package/dist/codemods/split-jsx-sequence.js +11 -298
  12. package/dist/codemods/split-video-from-audio.d.ts +15 -0
  13. package/dist/codemods/split-video-from-audio.js +15 -0
  14. package/dist/codemods/update-default-props.d.ts +2 -6
  15. package/dist/codemods/update-default-props.js +12 -220
  16. package/dist/codemods/update-keyframes/ensure-imports-and-frame-hook.d.ts +1 -4
  17. package/dist/codemods/update-keyframes/ensure-imports-and-frame-hook.js +5 -102
  18. package/dist/codemods/update-keyframes/update-keyframes.d.ts +8 -93
  19. package/dist/codemods/update-keyframes/update-keyframes.js +11 -1302
  20. package/dist/detect-outdated-remotion-skills.d.ts +7 -0
  21. package/dist/detect-outdated-remotion-skills.js +11 -5
  22. package/dist/helpers/resolve-composition-component.d.ts +3 -11
  23. package/dist/helpers/resolve-composition-component.js +38 -1495
  24. package/dist/index.d.ts +3 -2
  25. package/dist/index.js +1 -0
  26. package/dist/max-timeline-tracks.d.ts +2 -1
  27. package/dist/max-timeline-tracks.js +10 -4
  28. package/dist/preview-server/api-routes.js +4 -0
  29. package/dist/preview-server/routes/add-effect.js +1 -1
  30. package/dist/preview-server/routes/apply-codemod.js +3 -3
  31. package/dist/preview-server/routes/apply-visual-control-change.js +3 -3
  32. package/dist/preview-server/routes/can-update-sequence-props.js +107 -24
  33. package/dist/preview-server/routes/delete-effect.js +1 -1
  34. package/dist/preview-server/routes/delete-jsx-node.js +1 -1
  35. package/dist/preview-server/routes/duplicate-effect.js +1 -1
  36. package/dist/preview-server/routes/duplicate-jsx-node.js +1 -1
  37. package/dist/preview-server/routes/element-install-plan.d.ts +1 -1
  38. package/dist/preview-server/routes/insert-element.js +2 -2
  39. package/dist/preview-server/routes/insert-jsx-element.js +1 -1
  40. package/dist/preview-server/routes/log-updates/log-effect-update.js +2 -1
  41. package/dist/preview-server/routes/log-updates/log-update.js +2 -1
  42. package/dist/preview-server/routes/paste-effects.js +1 -1
  43. package/dist/preview-server/routes/remotion-skills-info.d.ts +7 -0
  44. package/dist/preview-server/routes/remotion-skills-info.js +24 -0
  45. package/dist/preview-server/routes/reorder-effect.js +1 -1
  46. package/dist/preview-server/routes/reorder-sequence.js +1 -1
  47. package/dist/preview-server/routes/source-file-write-queue.d.ts +1 -0
  48. package/dist/preview-server/routes/source-file-write-queue.js +11 -2
  49. package/dist/preview-server/routes/split-jsx-sequence.js +1 -1
  50. package/dist/preview-server/routes/split-video-from-audio.d.ts +3 -0
  51. package/dist/preview-server/routes/split-video-from-audio.js +80 -0
  52. package/dist/preview-server/routes/update-default-props.js +1 -1
  53. package/dist/preview-server/start-server.js +188 -140
  54. package/dist/preview-server/undo-stack.d.ts +3 -52
  55. package/dist/preview-server/update-available.js +4 -4
  56. package/package.json +8 -8
@@ -1,1307 +1,16 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.updateEffectKeyframes = exports.updateEffectKeyframesAst = exports.updateSequenceKeyframes = exports.updateSequenceKeyframesAst = void 0;
37
- const studio_shared_1 = require("@remotion/studio-shared");
38
- const recast = __importStar(require("recast"));
39
- const get_ast_node_path_1 = require("../../helpers/get-ast-node-path");
40
- const parse_keyframe_easing_expression_1 = require("../../helpers/parse-keyframe-easing-expression");
41
- const video_config_numeric_expression_1 = require("../../helpers/video-config-numeric-expression");
42
- const video_config_values_1 = require("../../helpers/video-config-values");
43
- const can_update_sequence_props_1 = require("../../preview-server/routes/can-update-sequence-props");
3
+ exports.updateEffectKeyframes = exports.updateSequenceKeyframes = exports.updateSequenceKeyframesAst = exports.updateEffectKeyframesAst = void 0;
4
+ const studio_codemods_1 = require("@remotion/studio-codemods");
44
5
  const format_file_content_1 = require("../format-file-content");
45
- const parse_ast_1 = require("../parse-ast");
46
- const update_effect_props_1 = require("../update-effect-props/update-effect-props");
47
- const update_nested_prop_1 = require("../update-nested-prop");
48
- const ensure_imports_and_frame_hook_1 = require("./ensure-imports-and-frame-hook");
49
- const b = recast.types.builders;
50
- const getObjectPropertyNameFromUpdateKey = (key) => {
51
- const dotIndex = key.indexOf('.');
52
- return dotIndex === -1 ? key : key.slice(dotIndex + 1);
53
- };
54
- const lineStartsWithPropertyName = ({ line, propertyName, }) => {
55
- const trimmed = line.trimStart();
56
- return (trimmed.startsWith(`${propertyName}:`) ||
57
- trimmed.startsWith(`'${propertyName}':`) ||
58
- trimmed.startsWith(`"${propertyName}":`));
59
- };
60
- const getIndent = (line) => {
61
- var _a;
62
- var _b;
63
- return (_b = (_a = line.match(/^[ \t]*/)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '';
64
- };
65
- const removeBlankLinesFromObjectsWithProperties = ({ input, propertyNames, }) => {
66
- if (propertyNames.length === 0) {
67
- return input;
68
- }
69
- const lines = input.split('\n');
70
- const linesToRemove = new Set();
71
- for (let i = 0; i < lines.length; i++) {
72
- const propertyName = propertyNames.find((name) => lineStartsWithPropertyName({ line: lines[i], propertyName: name }));
73
- if (!propertyName) {
74
- continue;
75
- }
76
- const propertyIndentLength = getIndent(lines[i]).length;
77
- let objectStart = i;
78
- for (let j = i - 1; j >= 0; j--) {
79
- const trimmed = lines[j].trim();
80
- if (trimmed.endsWith('{') &&
81
- getIndent(lines[j]).length < propertyIndentLength) {
82
- objectStart = j;
83
- break;
84
- }
85
- }
86
- let objectEnd = i;
87
- for (let j = i + 1; j < lines.length; j++) {
88
- const trimmed = lines[j].trim();
89
- if (trimmed.startsWith('}') &&
90
- getIndent(lines[j]).length < propertyIndentLength) {
91
- objectEnd = j;
92
- break;
93
- }
94
- }
95
- for (let j = objectStart + 1; j < objectEnd; j++) {
96
- if (lines[j].trim() === '') {
97
- linesToRemove.add(j);
98
- }
99
- }
100
- }
101
- if (linesToRemove.size === 0) {
102
- return input;
103
- }
104
- return lines.filter((_, index) => !linesToRemove.has(index)).join('\n');
105
- };
106
- const getSupportedCallArgument = (arg) => {
107
- if (arg === undefined ||
108
- arg.type === 'ArgumentPlaceholder' ||
109
- arg.type === 'JSXNamespacedName') {
110
- return null;
111
- }
112
- return arg;
113
- };
114
- const getInterpolationExpression = (node, videoConfigValues) => {
115
- if (node.type === 'TSAsExpression') {
116
- return getInterpolationExpression(node.expression, videoConfigValues);
117
- }
118
- if (node.type !== 'CallExpression' ||
119
- node.callee.type !== 'Identifier' ||
120
- !(0, studio_shared_1.isKeyframeInterpolationFunction)(node.callee.name)) {
121
- return null;
122
- }
123
- const frameArg = getSupportedCallArgument(node.arguments[0]);
124
- const inputArg = node.arguments[1];
125
- const outputArg = node.arguments[2];
126
- if (!frameArg ||
127
- !inputArg ||
128
- !outputArg ||
129
- inputArg.type !== 'ArrayExpression' ||
130
- outputArg.type !== 'ArrayExpression' ||
131
- inputArg.elements.length !== outputArg.elements.length) {
132
- return null;
133
- }
134
- const keyframes = [];
135
- for (let i = 0; i < inputArg.elements.length; i++) {
136
- const inputElement = inputArg.elements[i];
137
- const outputElement = outputArg.elements[i];
138
- if (!inputElement ||
139
- !outputElement ||
140
- inputElement.type === 'SpreadElement' ||
141
- outputElement.type === 'SpreadElement') {
142
- return null;
143
- }
144
- const frameExpression = (0, video_config_numeric_expression_1.parseVideoConfigNumericExpression)({
145
- node: inputElement,
146
- videoConfigValues,
147
- });
148
- if (frameExpression === null || !(0, can_update_sequence_props_1.isStaticValue)(outputElement)) {
149
- return null;
150
- }
151
- keyframes.push({
152
- frame: frameExpression.value,
153
- frameExpression: inputElement,
154
- frameNumericExpression: frameExpression,
155
- originalFrame: frameExpression.value,
156
- output: outputElement,
157
- value: (0, can_update_sequence_props_1.extractStaticValue)(outputElement),
158
- });
159
- }
160
- if (keyframes.length === 0) {
161
- return null;
162
- }
163
- const extraArgs = [];
164
- for (const arg of node.arguments.slice(3)) {
165
- const supportedArg = getSupportedCallArgument(arg);
166
- if (!supportedArg) {
167
- return null;
168
- }
169
- extraArgs.push(supportedArg);
170
- }
171
- return {
172
- callee: node.callee,
173
- input: frameArg,
174
- extraArgs,
175
- keyframes,
176
- };
177
- };
178
- const getInterpolationCalleeForValues = ({ schema, key, staticValue, newValue, }) => {
179
- return b.identifier((0, studio_shared_1.getKeyframeInterpolationFunction)({
180
- schema,
181
- key,
182
- staticValue,
183
- newValue,
184
- }));
185
- };
186
- const createFrameExpression = (frame) => {
187
- return (0, update_nested_prop_1.parseValueExpression)(frame);
188
- };
189
- const createClampOptionsExpression = ({ defaultOutput, }) => {
190
- const properties = [
191
- b.objectProperty(b.identifier('extrapolateLeft'), b.stringLiteral('clamp')),
192
- b.objectProperty(b.identifier('extrapolateRight'), b.stringLiteral('clamp')),
193
- ];
194
- if (defaultOutput !== null && defaultOutput !== 'linear') {
195
- properties.push(b.objectProperty(b.identifier('output'), b.stringLiteral(defaultOutput)));
196
- }
197
- return b.objectExpression(properties);
198
- };
199
- const createEmptyOptionsExpression = () => b.objectExpression([]);
200
- const findObjectOptionProperty = (options, propertyName) => {
201
- const propIndex = options.properties.findIndex((prop) => prop.type === 'ObjectProperty' &&
202
- !prop.computed &&
203
- ((prop.key.type === 'Identifier' && prop.key.name === propertyName) ||
204
- (prop.key.type === 'StringLiteral' && prop.key.value === propertyName)));
205
- return {
206
- propIndex,
207
- prop: propIndex === -1
208
- ? undefined
209
- : options.properties[propIndex],
210
- };
211
- };
212
- const setOptionsProperty = ({ options, propertyName, value, }) => {
213
- const { propIndex, prop } = findObjectOptionProperty(options, propertyName);
214
- if (value === null) {
215
- if (propIndex !== -1) {
216
- options.properties.splice(propIndex, 1);
217
- }
218
- return;
219
- }
220
- if (prop) {
221
- prop.value = value;
222
- return;
223
- }
224
- options.properties.push(b.objectProperty(b.identifier(propertyName), value));
225
- };
226
- const isLinearEasing = (easing) => easing.type === 'linear';
227
- const getKeyframeEasing = (node) => (0, parse_keyframe_easing_expression_1.parseKeyframeEasingExpression)(node);
228
- const getKeyframeEasingArray = ({ easingNode, segmentCount, }) => {
229
- if (segmentCount === 0) {
230
- return [];
231
- }
232
- if (easingNode.type === 'TSAsExpression') {
233
- return getKeyframeEasingArray({
234
- easingNode: easingNode.expression,
235
- segmentCount,
236
- });
237
- }
238
- if (easingNode.type === 'ArrayExpression') {
239
- if (easingNode.elements.length > segmentCount) {
240
- return null;
241
- }
242
- const parsed = easingNode.elements.map((element) => {
243
- if (!element || element.type === 'SpreadElement') {
244
- return null;
245
- }
246
- return getKeyframeEasing(element);
247
- });
248
- if (parsed.some((value) => value === null)) {
249
- return null;
250
- }
251
- const easingArray = parsed;
252
- while (easingArray.length < segmentCount) {
253
- easingArray.push(studio_shared_1.LINEAR_KEYFRAME_EASING);
254
- }
255
- return easingArray;
256
- }
257
- const easing = getKeyframeEasing(easingNode);
258
- if (!easing) {
259
- return null;
260
- }
261
- return new Array(segmentCount).fill(easing);
262
- };
263
- const getExistingEasingArray = ({ options, segmentCount, }) => {
264
- const { prop } = findObjectOptionProperty(options, 'easing');
265
- if (!prop) {
266
- return Array.from({ length: segmentCount }, () => ({ type: 'linear' }));
267
- }
268
- const easing = getKeyframeEasingArray({
269
- easingNode: prop.value,
270
- segmentCount,
271
- });
272
- if (!easing) {
273
- throw new Error('Cannot update easing: easing must be inline');
274
- }
275
- return easing;
276
- };
277
- const getExistingEasingArrayOrNull = ({ options, segmentCount, }) => {
278
- const { prop } = findObjectOptionProperty(options, 'easing');
279
- if (!prop) {
280
- return null;
281
- }
282
- return getExistingEasingArray({ options, segmentCount });
283
- };
284
- const createEasingExpression = (easing) => {
285
- switch (easing.type) {
286
- case 'linear':
287
- return b.memberExpression(b.identifier('Easing'), b.identifier('linear'));
288
- case 'step1':
289
- return b.memberExpression(b.identifier('Easing'), b.identifier('step1'));
290
- case 'spring':
291
- return b.callExpression(b.memberExpression(b.identifier('Easing'), b.identifier('spring')), [
292
- b.objectExpression([
293
- b.objectProperty(b.identifier('damping'), (0, update_nested_prop_1.parseValueExpression)(easing.damping)),
294
- b.objectProperty(b.identifier('mass'), (0, update_nested_prop_1.parseValueExpression)(easing.mass)),
295
- b.objectProperty(b.identifier('stiffness'), (0, update_nested_prop_1.parseValueExpression)(easing.stiffness)),
296
- ...(easing.allowTail === null
297
- ? []
298
- : [
299
- b.objectProperty(b.identifier('allowTail'), b.booleanLiteral(easing.allowTail)),
300
- ]),
301
- ...(easing.durationRestThreshold === null
302
- ? []
303
- : [
304
- b.objectProperty(b.identifier('durationRestThreshold'), (0, update_nested_prop_1.parseValueExpression)(easing.durationRestThreshold)),
305
- ]),
306
- b.objectProperty(b.identifier('overshootClamping'), b.booleanLiteral(easing.overshootClamping)),
307
- ]),
308
- ]);
309
- case 'bezier':
310
- return b.callExpression(b.memberExpression(b.identifier('Easing'), b.identifier('bezier')), [easing.x1, easing.y1, easing.x2, easing.y2].map((value) => (0, update_nested_prop_1.parseValueExpression)(value)));
311
- default:
312
- throw new Error(`Unsupported easing: ${JSON.stringify(easing)}`);
313
- }
314
- };
315
- const createEasingArrayExpression = (easing) => b.arrayExpression(easing.map((easingValue) => createEasingExpression(easingValue)));
316
- const setEasingOption = ({ options, easing, }) => {
317
- const hasNonLinearEasing = easing.some((easingValue) => !isLinearEasing(easingValue));
318
- setOptionsProperty({
319
- options,
320
- propertyName: 'easing',
321
- value: hasNonLinearEasing ? createEasingArrayExpression(easing) : null,
322
- });
323
- return hasNonLinearEasing;
324
- };
325
- const getExtraArgsWithOptions = ({ extraArgs, options, }) => {
326
- return options.properties.length === 0
327
- ? extraArgs.slice(1)
328
- : [options, ...extraArgs.slice(1)];
329
- };
330
- const getInlineOptionsFromExtraArgs = (extraArgs) => {
331
- const existingOptions = extraArgs[0];
332
- if (!existingOptions || existingOptions.type !== 'ObjectExpression') {
333
- return null;
334
- }
335
- return existingOptions;
336
- };
337
- const normalizeEasingAfterAddingKeyframe = ({ extraArgs, previousSegmentCount, nextSegmentCount, insertedKeyframeIndex, nextKeyframeCount, defaultEasing, }) => {
338
- var _a, _b;
339
- const options = (_a = getInlineOptionsFromExtraArgs(extraArgs)) !== null && _a !== void 0 ? _a : (extraArgs.length === 0 ? createEmptyOptionsExpression() : null);
340
- if (!options) {
341
- return { extraArgs, needsEasingImport: false };
342
- }
343
- const easing = (_b = getExistingEasingArrayOrNull({
344
- options,
345
- segmentCount: previousSegmentCount,
346
- })) !== null && _b !== void 0 ? _b : Array.from({ length: previousSegmentCount }, () => defaultEasing);
347
- if (easing.length < nextSegmentCount) {
348
- const isSplittingExistingSegment = insertedKeyframeIndex > 0 &&
349
- insertedKeyframeIndex < nextKeyframeCount - 1;
350
- const easingIndexToDuplicate = isSplittingExistingSegment && easing.length > 0
351
- ? Math.min(insertedKeyframeIndex - 1, easing.length - 1)
352
- : null;
353
- easing.splice(insertedKeyframeIndex, 0, easingIndexToDuplicate === null
354
- ? defaultEasing
355
- : easing[easingIndexToDuplicate]);
356
- }
357
- while (easing.length < nextSegmentCount) {
358
- easing.push(defaultEasing);
359
- }
360
- const needsEasingImport = setEasingOption({ options, easing });
361
- return {
362
- extraArgs: getExtraArgsWithOptions({ extraArgs, options }),
363
- needsEasingImport,
364
- };
365
- };
366
- const getEasingIndexToRemove = ({ removedKeyframeIndex, keyframeCountBeforeRemoval, }) => {
367
- if (removedKeyframeIndex === 0) {
368
- return 0;
369
- }
370
- if (removedKeyframeIndex === keyframeCountBeforeRemoval - 1) {
371
- return removedKeyframeIndex - 1;
372
- }
373
- return removedKeyframeIndex;
374
- };
375
- const normalizeEasingAfterRemovingKeyframe = ({ extraArgs, previousSegmentCount, nextSegmentCount, removedKeyframeIndex, }) => {
376
- const options = getInlineOptionsFromExtraArgs(extraArgs);
377
- if (!options) {
378
- return { extraArgs, needsEasingImport: false };
379
- }
380
- const easing = getExistingEasingArrayOrNull({
381
- options,
382
- segmentCount: previousSegmentCount,
383
- });
384
- if (easing === null) {
385
- return { extraArgs, needsEasingImport: false };
386
- }
387
- if (easing.length > 0) {
388
- const easingIndexToRemove = getEasingIndexToRemove({
389
- removedKeyframeIndex,
390
- keyframeCountBeforeRemoval: previousSegmentCount + 1,
391
- });
392
- easing.splice(easingIndexToRemove, 1);
393
- }
394
- while (easing.length > nextSegmentCount) {
395
- easing.pop();
396
- }
397
- while (easing.length < nextSegmentCount) {
398
- easing.push(studio_shared_1.LINEAR_KEYFRAME_EASING);
399
- }
400
- return {
401
- extraArgs: getExtraArgsWithOptions({ extraArgs, options }),
402
- needsEasingImport: setEasingOption({ options, easing }),
403
- };
404
- };
405
- const normalizeEasingAfterRemovingKeyframes = ({ extraArgs, previousSegmentCount, nextSegmentCount, removedKeyframeIndexes, }) => {
406
- const options = getInlineOptionsFromExtraArgs(extraArgs);
407
- if (!options) {
408
- return { extraArgs, needsEasingImport: false };
409
- }
410
- const easing = getExistingEasingArrayOrNull({
411
- options,
412
- segmentCount: previousSegmentCount,
413
- });
414
- if (easing === null) {
415
- return { extraArgs, needsEasingImport: false };
416
- }
417
- for (const { removedKeyframeIndex, keyframeCountBeforeRemoval } of [
418
- ...removedKeyframeIndexes,
419
- ]
420
- .sort((first, second) => second - first)
421
- .map((keyframeIndex, index) => ({
422
- removedKeyframeIndex: keyframeIndex,
423
- keyframeCountBeforeRemoval: previousSegmentCount + 1 - index,
424
- }))) {
425
- if (easing.length === 0) {
426
- break;
427
- }
428
- const easingIndexToRemove = getEasingIndexToRemove({
429
- removedKeyframeIndex,
430
- keyframeCountBeforeRemoval,
431
- });
432
- easing.splice(easingIndexToRemove, 1);
433
- }
434
- while (easing.length > nextSegmentCount) {
435
- easing.pop();
436
- }
437
- while (easing.length < nextSegmentCount) {
438
- easing.push(studio_shared_1.LINEAR_KEYFRAME_EASING);
439
- }
440
- return {
441
- extraArgs: getExtraArgsWithOptions({ extraArgs, options }),
442
- needsEasingImport: setEasingOption({ options, easing }),
443
- };
444
- };
445
- const validatePosterize = (posterize) => {
446
- if (posterize === undefined) {
447
- return;
448
- }
449
- if (!Number.isFinite(posterize) || posterize <= 0) {
450
- throw new Error('Cannot update keyframe settings: posterize must be > 0');
451
- }
452
- };
453
- const validateOutput = (output) => {
454
- if (output === undefined ||
455
- output === 'linear' ||
456
- output === 'perceptual-scale') {
457
- return;
458
- }
459
- throw new Error('Cannot update keyframe settings: output must be "linear" or "perceptual-scale"');
460
- };
461
- const updateKeyframeSettings = ({ expression, clamping, posterize, output, videoConfigValues, }) => {
462
- validatePosterize(posterize);
463
- validateOutput(output);
464
- const existing = getInterpolationExpression(expression, videoConfigValues);
465
- if (!existing) {
466
- throw new Error('Cannot update keyframe settings on non-keyframed value');
467
- }
468
- const calleeName = existing.callee.type === 'Identifier' ? existing.callee.name : null;
469
- const isColorInterpolation = calleeName === 'interpolateColors';
470
- const extraArgs = [...existing.extraArgs];
471
- const existingOptions = extraArgs[0];
472
- if (existingOptions && existingOptions.type !== 'ObjectExpression') {
473
- throw new Error('Cannot update keyframe settings: options must be inline');
474
- }
475
- const options = (existingOptions === null || existingOptions === void 0 ? void 0 : existingOptions.type) === 'ObjectExpression'
476
- ? existingOptions
477
- : createEmptyOptionsExpression();
478
- if (isColorInterpolation) {
479
- setOptionsProperty({ options, propertyName: 'extrapolateLeft', value: null });
480
- setOptionsProperty({
481
- options,
482
- propertyName: 'extrapolateRight',
483
- value: null,
484
- });
485
- setOptionsProperty({ options, propertyName: 'output', value: null });
486
- }
487
- else if (clamping) {
488
- setOptionsProperty({
489
- options,
490
- propertyName: 'extrapolateLeft',
491
- value: b.stringLiteral(clamping.left),
492
- });
493
- setOptionsProperty({
494
- options,
495
- propertyName: 'extrapolateRight',
496
- value: b.stringLiteral(clamping.right),
497
- });
498
- }
499
- if (!isColorInterpolation && output !== undefined) {
500
- setOptionsProperty({
501
- options,
502
- propertyName: 'output',
503
- value: output === 'linear' ? null : b.stringLiteral(output),
504
- });
505
- }
506
- setOptionsProperty({
507
- options,
508
- propertyName: 'posterize',
509
- value: posterize === undefined ? null : b.numericLiteral(posterize),
510
- });
511
- const nextExtraArgs = options.properties.length === 0
512
- ? extraArgs.slice(1)
513
- : [options, ...extraArgs.slice(1)];
514
- return createInterpolateExpression({
515
- callee: existing.callee,
516
- input: existing.input,
517
- extraArgs: nextExtraArgs,
518
- keyframes: existing.keyframes,
519
- });
520
- };
521
- const updateKeyframeEasing = ({ expression, segmentIndex, easing, videoConfigValues, }) => {
522
- const existing = getInterpolationExpression(expression, videoConfigValues);
523
- if (!existing) {
524
- throw new Error('Cannot update easing on non-keyframed value');
525
- }
526
- const segmentCount = Math.max(0, existing.keyframes.length - 1);
527
- if (!Number.isInteger(segmentIndex) ||
528
- segmentIndex < 0 ||
529
- segmentIndex >= segmentCount) {
530
- throw new Error('Cannot update easing: segment index out of range');
531
- }
532
- const extraArgs = [...existing.extraArgs];
533
- const existingOptions = extraArgs[0];
534
- if (existingOptions && existingOptions.type !== 'ObjectExpression') {
535
- throw new Error('Cannot update easing: options must be inline');
536
- }
537
- const options = (existingOptions === null || existingOptions === void 0 ? void 0 : existingOptions.type) === 'ObjectExpression'
538
- ? existingOptions
539
- : createEmptyOptionsExpression();
540
- const nextEasing = getExistingEasingArray({ options, segmentCount });
541
- nextEasing[segmentIndex] = easing;
542
- const hasNonLinearEasing = nextEasing.some((easingValue) => !isLinearEasing(easingValue));
543
- setOptionsProperty({
544
- options,
545
- propertyName: 'easing',
546
- value: hasNonLinearEasing ? createEasingArrayExpression(nextEasing) : null,
547
- });
548
- const nextExtraArgs = options.properties.length === 0
549
- ? extraArgs.slice(1)
550
- : [options, ...extraArgs.slice(1)];
551
- return {
552
- expression: createInterpolateExpression({
553
- callee: existing.callee,
554
- input: existing.input,
555
- extraArgs: nextExtraArgs,
556
- keyframes: existing.keyframes,
557
- }),
558
- needsEasingImport: hasNonLinearEasing,
559
- };
560
- };
561
- const createInterpolateExpression = ({ callee, input, extraArgs, keyframes, }) => {
562
- const sortedKeyframes = [...keyframes].sort((first, second) => first.frame - second.frame);
563
- return b.callExpression(callee, [
564
- input,
565
- b.arrayExpression(sortedKeyframes.map((keyframe) => keyframe.frame === keyframe.originalFrame
566
- ? keyframe.frameExpression
567
- : (0, video_config_numeric_expression_1.updateVideoConfigNumericExpression)({
568
- expression: keyframe.frameNumericExpression,
569
- value: keyframe.frame,
570
- }))),
571
- b.arrayExpression(sortedKeyframes.map((keyframe) => keyframe.output)),
572
- ...extraArgs,
573
- ]);
574
- };
575
- const noIntroducedIdentifiers = {
576
- calleeName: null,
577
- needsFrameHook: false,
578
- needsEasingImport: false,
579
- };
580
- const addKeyframe = ({ expression, key, frame, value, schema, videoConfigValues, }) => {
581
- var _a;
582
- if (!(0, studio_shared_1.isSchemaFieldKeyframable)({ schema, key })) {
583
- throw new Error(`Cannot add keyframe: "${key}" is not keyframable`);
584
- }
585
- const existing = getInterpolationExpression(expression, videoConfigValues);
586
- const newOutput = (0, update_nested_prop_1.parseValueExpression)(value);
587
- if (existing) {
588
- const defaultEasing = (0, studio_shared_1.isSchemaFieldHoldOnly)({ schema, key })
589
- ? studio_shared_1.HOLD_KEYFRAME_EASING
590
- : studio_shared_1.LINEAR_KEYFRAME_EASING;
591
- const existingCalleeName = existing.callee.type === 'Identifier'
592
- ? existing.callee.name
593
- : 'interpolate';
594
- const schemaCalleeName = (0, studio_shared_1.getKeyframeInterpolationFunctionForSchemaField)({
595
- schema,
596
- key,
597
- });
598
- const nextCalleeName = schemaCalleeName !== null && schemaCalleeName !== void 0 ? schemaCalleeName : existingCalleeName;
599
- const existingIndex = existing.keyframes.findIndex((keyframe) => keyframe.frame === frame);
600
- const nextKeyframes = existingIndex === -1
601
- ? [
602
- ...existing.keyframes,
603
- {
604
- frame,
605
- frameExpression: createFrameExpression(frame),
606
- frameNumericExpression: { type: 'literal', value: frame },
607
- originalFrame: frame,
608
- output: newOutput,
609
- value,
610
- },
611
- ]
612
- : existing.keyframes.map((keyframe, index) => index === existingIndex
613
- ? { ...keyframe, output: newOutput, value }
614
- : keyframe);
615
- const normalizedEasing = existingIndex === -1
616
- ? normalizeEasingAfterAddingKeyframe({
617
- extraArgs: existing.extraArgs,
618
- previousSegmentCount: Math.max(existing.keyframes.length - 1, 0),
619
- nextSegmentCount: Math.max(nextKeyframes.length - 1, 0),
620
- insertedKeyframeIndex: [...nextKeyframes]
621
- .sort((first, second) => first.frame - second.frame)
622
- .findIndex((keyframe) => keyframe.frame === frame),
623
- nextKeyframeCount: nextKeyframes.length,
624
- defaultEasing,
625
- })
626
- : { extraArgs: existing.extraArgs, needsEasingImport: false };
627
- return {
628
- expression: createInterpolateExpression({
629
- callee: b.identifier(nextCalleeName),
630
- input: existing.input,
631
- extraArgs: normalizedEasing.extraArgs,
632
- keyframes: nextKeyframes,
633
- }),
634
- introduced: {
635
- calleeName: schemaCalleeName && schemaCalleeName !== existingCalleeName
636
- ? schemaCalleeName
637
- : null,
638
- needsFrameHook: false,
639
- needsEasingImport: normalizedEasing.needsEasingImport,
640
- },
641
- };
642
- }
643
- const staticNumericExpression = (0, video_config_numeric_expression_1.parseVideoConfigNumericExpression)({
644
- node: expression,
645
- videoConfigValues,
646
- });
647
- if (!(0, can_update_sequence_props_1.isStaticValue)(expression) && staticNumericExpression === null) {
648
- throw new Error('Cannot add keyframe to computed expression');
649
- }
650
- const staticValue = (_a = staticNumericExpression === null || staticNumericExpression === void 0 ? void 0 : staticNumericExpression.value) !== null && _a !== void 0 ? _a : (0, can_update_sequence_props_1.extractStaticValue)(expression);
651
- const keyframes = [
652
- {
653
- frame,
654
- frameExpression: createFrameExpression(frame),
655
- frameNumericExpression: { type: 'literal', value: frame },
656
- originalFrame: frame,
657
- output: newOutput,
658
- value,
659
- },
660
- ];
661
- const callee = getInterpolationCalleeForValues({
662
- schema,
663
- key,
664
- staticValue,
665
- newValue: value,
666
- });
667
- const extraArgs = callee.type === 'Identifier' && callee.name === 'interpolateColors'
668
- ? []
669
- : [
670
- createClampOptionsExpression({
671
- defaultOutput: getDefaultKeyframeOutput({ schema, key }),
672
- }),
673
- ];
674
- return {
675
- expression: createInterpolateExpression({
676
- callee,
677
- input: b.identifier('frame'),
678
- extraArgs,
679
- keyframes,
680
- }),
681
- introduced: {
682
- calleeName: callee.type === 'Identifier'
683
- ? callee.name
684
- : null,
685
- needsFrameHook: true,
686
- needsEasingImport: false,
687
- },
688
- };
689
- };
690
- const removeKeyframe = ({ expression, frame, videoConfigValues, valueWhenLastKeyframeDeleted, }) => {
691
- const existing = getInterpolationExpression(expression, videoConfigValues);
692
- if (!existing) {
693
- throw new Error('Cannot remove keyframe from non-interpolated expression');
694
- }
695
- const keyframeIndex = existing.keyframes.findIndex((keyframe) => keyframe.frame === frame);
696
- if (keyframeIndex === -1) {
697
- throw new Error(`Cannot remove keyframe at frame ${frame}: not found`);
698
- }
699
- const nextKeyframes = existing.keyframes.filter((_keyframe, index) => index !== keyframeIndex);
700
- if (nextKeyframes.length === 0) {
701
- return {
702
- expression: valueWhenLastKeyframeDeleted === null
703
- ? existing.keyframes[keyframeIndex].output
704
- : (0, update_nested_prop_1.parseValueExpression)(valueWhenLastKeyframeDeleted),
705
- introduced: noIntroducedIdentifiers,
706
- };
707
- }
708
- const normalizedEasing = normalizeEasingAfterRemovingKeyframe({
709
- extraArgs: existing.extraArgs,
710
- previousSegmentCount: Math.max(existing.keyframes.length - 1, 0),
711
- nextSegmentCount: Math.max(nextKeyframes.length - 1, 0),
712
- removedKeyframeIndex: keyframeIndex,
713
- });
714
- return {
715
- expression: createInterpolateExpression({
716
- callee: existing.callee,
717
- input: existing.input,
718
- extraArgs: normalizedEasing.extraArgs,
719
- keyframes: nextKeyframes,
720
- }),
721
- introduced: {
722
- ...noIntroducedIdentifiers,
723
- needsEasingImport: normalizedEasing.needsEasingImport,
724
- },
725
- };
726
- };
727
- const moveKeyframes = ({ expression, moves, videoConfigValues, }) => {
728
- const existing = getInterpolationExpression(expression, videoConfigValues);
729
- if (!existing) {
730
- throw new Error('Cannot move keyframe in non-interpolated expression');
731
- }
732
- const moveMap = new Map();
733
- for (const move of moves) {
734
- if (move.fromFrame === move.toFrame) {
735
- continue;
736
- }
737
- if (moveMap.has(move.fromFrame)) {
738
- throw new Error(`Cannot move keyframe at frame ${move.fromFrame} twice`);
739
- }
740
- moveMap.set(move.fromFrame, move.toFrame);
741
- }
742
- if (moveMap.size === 0) {
743
- return expression;
744
- }
745
- const frames = new Set(existing.keyframes.map((keyframe) => keyframe.frame));
746
- for (const fromFrame of moveMap.keys()) {
747
- if (!frames.has(fromFrame)) {
748
- throw new Error(`Cannot move keyframe at frame ${fromFrame}: not found`);
749
- }
750
- }
751
- const movedFromFrames = new Set(moveMap.keys());
752
- const movedToFrames = new Set(moveMap.values());
753
- const removedKeyframeIndexes = [];
754
- const nextKeyframes = existing.keyframes.flatMap((keyframe, index) => {
755
- const movedFrame = moveMap.get(keyframe.frame);
756
- if (movedFrame !== undefined) {
757
- return [{ ...keyframe, frame: movedFrame }];
758
- }
759
- if (movedToFrames.has(keyframe.frame) &&
760
- !movedFromFrames.has(keyframe.frame)) {
761
- removedKeyframeIndexes.push(index);
762
- return [];
763
- }
764
- return [keyframe];
765
- });
766
- const nextFrames = new Set();
767
- for (const keyframe of nextKeyframes) {
768
- if (nextFrames.has(keyframe.frame)) {
769
- throw new Error(`Cannot move keyframe to frame ${keyframe.frame}: frame already exists`);
770
- }
771
- nextFrames.add(keyframe.frame);
772
- }
773
- const normalizedEasing = normalizeEasingAfterRemovingKeyframes({
774
- extraArgs: existing.extraArgs,
775
- previousSegmentCount: Math.max(existing.keyframes.length - 1, 0),
776
- nextSegmentCount: Math.max(nextKeyframes.length - 1, 0),
777
- removedKeyframeIndexes,
778
- });
779
- return createInterpolateExpression({
780
- callee: existing.callee,
781
- input: existing.input,
782
- extraArgs: normalizedEasing.extraArgs,
783
- keyframes: nextKeyframes,
784
- });
785
- };
786
- const applyKeyframeOperation = ({ expression, key, operation, schema, videoConfigValues, }) => {
787
- if (operation.type === 'add') {
788
- return addKeyframe({
789
- expression,
790
- key,
791
- frame: operation.frame,
792
- value: operation.value,
793
- schema,
794
- videoConfigValues,
795
- });
796
- }
797
- if (operation.type === 'settings') {
798
- return {
799
- expression: updateKeyframeSettings({
800
- expression,
801
- clamping: operation.clamping,
802
- posterize: operation.posterize,
803
- output: operation.output,
804
- videoConfigValues,
805
- }),
806
- introduced: noIntroducedIdentifiers,
807
- };
808
- }
809
- if (operation.type === 'easing') {
810
- if ((0, studio_shared_1.isSchemaFieldHoldOnly)({ schema, key }) &&
811
- operation.easing.type !== 'step1') {
812
- throw new Error(`Cannot update easing: "${key}" only supports Easing.step1`);
813
- }
814
- const updated = updateKeyframeEasing({
815
- expression,
816
- segmentIndex: operation.segmentIndex,
817
- easing: operation.easing,
818
- videoConfigValues,
819
- });
820
- return {
821
- expression: updated.expression,
822
- introduced: {
823
- ...noIntroducedIdentifiers,
824
- needsEasingImport: updated.needsEasingImport,
825
- },
826
- };
827
- }
828
- if (operation.type === 'move') {
829
- return {
830
- expression: moveKeyframes({
831
- expression,
832
- moves: operation.moves,
833
- videoConfigValues,
834
- }),
835
- introduced: noIntroducedIdentifiers,
836
- };
837
- }
838
- return removeKeyframe({
839
- expression,
840
- frame: operation.frame,
841
- videoConfigValues,
842
- valueWhenLastKeyframeDeleted: operation.valueWhenLastKeyframeDeleted,
843
- });
844
- };
845
- const getExpressionFromJsxAttribute = (attr) => {
846
- if (!attr.value) {
847
- return b.booleanLiteral(true);
848
- }
849
- if (attr.value.type === 'StringLiteral') {
850
- return attr.value;
851
- }
852
- if (attr.value.type !== 'JSXExpressionContainer') {
853
- return null;
854
- }
855
- const { expression } = attr.value;
856
- if (expression.type === 'JSXEmptyExpression') {
857
- return null;
858
- }
859
- return expression;
860
- };
861
- const findJsxAttribute = (attributes, name) => {
862
- const attrIndex = attributes.findIndex((candidate) => {
863
- if (candidate.type === 'JSXSpreadAttribute') {
864
- return false;
865
- }
866
- if (candidate.name.type === 'JSXNamespacedName') {
867
- return false;
868
- }
869
- return candidate.name.name === name;
870
- });
871
- const foundAttr = attrIndex === -1 ? undefined : attributes[attrIndex];
872
- return {
873
- attrIndex,
874
- attr: foundAttr && foundAttr.type === 'JSXAttribute'
875
- ? foundAttr
876
- : undefined,
877
- };
878
- };
879
- const findObjectProperty = (objExpr, propertyName) => {
880
- const propIndex = objExpr.properties.findIndex((prop) => prop.type === 'ObjectProperty' &&
881
- ((prop.key.type === 'Identifier' && prop.key.name === propertyName) ||
882
- (prop.key.type === 'StringLiteral' && prop.key.value === propertyName)));
883
- return {
884
- propIndex,
885
- prop: propIndex === -1
886
- ? undefined
887
- : objExpr.properties[propIndex],
888
- };
889
- };
890
- const findFieldInSchema = (schema, key) => {
891
- if (key in schema) {
892
- return schema[key];
893
- }
894
- for (const field of Object.values(schema)) {
895
- if (field.type !== 'enum') {
896
- continue;
897
- }
898
- for (const variant of Object.values(field.variants)) {
899
- const found = findFieldInSchema(variant, key);
900
- if (found) {
901
- return found;
902
- }
903
- }
904
- }
905
- return undefined;
906
- };
907
- const getDefaultKeyframeOutput = ({ schema, key, }) => {
908
- const field = schema ? findFieldInSchema(schema, key) : undefined;
909
- if (((field === null || field === void 0 ? void 0 : field.type) === 'number' || (field === null || field === void 0 ? void 0 : field.type) === 'scale') &&
910
- field.defaultKeyframeOutput !== undefined) {
911
- return field.defaultKeyframeOutput;
912
- }
913
- return key === 'style.scale' ? 'perceptual-scale' : null;
914
- };
915
- const getInitialValueForMissingProp = ({ schema, key, newValue, }) => {
916
- const field = schema ? findFieldInSchema(schema, key) : undefined;
917
- if (field && field.type !== 'hidden' && field.default !== undefined) {
918
- return field.default;
919
- }
920
- return newValue;
921
- };
922
- const shouldRemovePropAfterKeyframeOperation = ({ expression, key, operation, schema, videoConfigValues, }) => {
923
- if (operation.type !== 'remove' || !schema) {
924
- return false;
925
- }
926
- const existing = getInterpolationExpression(expression, videoConfigValues);
927
- if (!existing || existing.keyframes.length !== 1) {
928
- return false;
929
- }
930
- const field = findFieldInSchema(schema, key);
931
- if (!field || field.type === 'hidden' || field.default === undefined) {
932
- return false;
933
- }
934
- const valueAfterRemoval = operation.valueWhenLastKeyframeDeleted === null
935
- ? existing.keyframes[0].value
936
- : operation.valueWhenLastKeyframeDeleted;
937
- return JSON.stringify(valueAfterRemoval) === JSON.stringify(field.default);
938
- };
939
- const getObjectExpression = (attr) => {
940
- if (!attr.value || attr.value.type !== 'JSXExpressionContainer') {
941
- return null;
942
- }
943
- if (attr.value.expression.type !== 'ObjectExpression') {
944
- return null;
945
- }
946
- return attr.value.expression;
947
- };
948
- const createJsxExpressionAttribute = (key, expression) => {
949
- return b.jsxAttribute(b.jsxIdentifier(key), b.jsxExpressionContainer(expression));
950
- };
951
- const createObjectProperty = (key, value) => b.objectProperty(b.identifier(key), value);
952
- const createObjectExpressionAttribute = ({ parentKey, childKey, expression, }) => {
953
- return createJsxExpressionAttribute(parentKey, b.objectExpression([
954
- createObjectProperty(childKey, expression),
955
- ]));
956
- };
957
- const createMissingPropExpression = (missingPropInitialValue) => {
958
- return (0, update_nested_prop_1.parseValueExpression)(missingPropInitialValue.value);
959
- };
960
- const getSequenceWritableProp = ({ attributes, key, missingPropInitialValue, }) => {
961
- const dotIndex = key.indexOf('.');
962
- if (dotIndex === -1) {
963
- const { attrIndex, attr: topLevelAttr } = findJsxAttribute(attributes, key);
964
- if (!topLevelAttr) {
965
- if (missingPropInitialValue) {
966
- return {
967
- expression: createMissingPropExpression(missingPropInitialValue),
968
- setExpression: (nextExpression) => {
969
- attributes.push(createJsxExpressionAttribute(key, nextExpression));
970
- },
971
- remove: () => undefined,
972
- };
973
- }
974
- throw new Error(`Cannot update keyframes: "${key}" is not set`);
975
- }
976
- const expression = getExpressionFromJsxAttribute(topLevelAttr);
977
- if (!expression) {
978
- throw new Error(`Cannot update keyframes: "${key}" is computed`);
979
- }
980
- return {
981
- expression,
982
- setExpression: (nextExpression) => {
983
- topLevelAttr.value = b.jsxExpressionContainer(nextExpression);
984
- },
985
- remove: () => {
986
- attributes.splice(attrIndex, 1);
987
- },
988
- };
989
- }
990
- const parentKey = key.slice(0, dotIndex);
991
- const childKey = key.slice(dotIndex + 1);
992
- const { attrIndex: parentAttrIndex, attr: parentAttr } = findJsxAttribute(attributes, parentKey);
993
- if (!parentAttr) {
994
- if (missingPropInitialValue) {
995
- return {
996
- expression: createMissingPropExpression(missingPropInitialValue),
997
- setExpression: (nextExpression) => {
998
- attributes.push(createObjectExpressionAttribute({
999
- parentKey,
1000
- childKey,
1001
- expression: nextExpression,
1002
- }));
1003
- },
1004
- remove: () => undefined,
1005
- };
1006
- }
1007
- throw new Error(`Cannot update keyframes: "${parentKey}" is not set`);
1008
- }
1009
- const objExpr = getObjectExpression(parentAttr);
1010
- if (!objExpr) {
1011
- throw new Error(`Cannot update keyframes: "${parentKey}" is computed`);
1012
- }
1013
- const { propIndex, prop } = findObjectProperty(objExpr, childKey);
1014
- if (!prop) {
1015
- if (missingPropInitialValue) {
1016
- return {
1017
- expression: createMissingPropExpression(missingPropInitialValue),
1018
- setExpression: (nextExpression) => {
1019
- objExpr.properties.push(createObjectProperty(childKey, nextExpression));
1020
- },
1021
- remove: () => undefined,
1022
- };
1023
- }
1024
- throw new Error(`Cannot update keyframes: "${key}" is not set`);
1025
- }
1026
- return {
1027
- expression: prop.value,
1028
- setExpression: (nextExpression) => {
1029
- prop.value = nextExpression;
1030
- },
1031
- remove: () => {
1032
- objExpr.properties.splice(propIndex, 1);
1033
- if (objExpr.properties.length === 0) {
1034
- attributes.splice(parentAttrIndex, 1);
1035
- }
1036
- },
1037
- };
1038
- };
1039
- const getEffectWritableProp = ({ objExpr, key, missingPropInitialValue, }) => {
1040
- const { propIndex, prop } = findObjectProperty(objExpr, key);
1041
- if (!prop) {
1042
- if (missingPropInitialValue) {
1043
- return {
1044
- expression: createMissingPropExpression(missingPropInitialValue),
1045
- setExpression: (nextExpression) => {
1046
- objExpr.properties.push(createObjectProperty(key, nextExpression));
1047
- },
1048
- remove: () => undefined,
1049
- };
1050
- }
1051
- throw new Error(`Cannot update keyframes: "${key}" is not set`);
1052
- }
1053
- return {
1054
- expression: prop.value,
1055
- setExpression: (nextExpression) => {
1056
- prop.value = nextExpression;
1057
- },
1058
- remove: () => {
1059
- objExpr.properties.splice(propIndex, 1);
1060
- },
1061
- };
1062
- };
1063
- const getEffectPropsObjectExpression = (call) => {
1064
- if (call.arguments.length === 0) {
1065
- const objExpr = b.objectExpression([]);
1066
- call.arguments.push(objExpr);
1067
- return objExpr;
1068
- }
1069
- if (call.arguments[0].type !== 'ObjectExpression') {
1070
- throw new Error('Cannot update effect keyframe: computed');
1071
- }
1072
- return call.arguments[0];
1073
- };
1074
- const updateSequenceKeyframesAst = ({ input, nodePath, updates, schema, videoConfigValues, }) => {
1075
- var _a;
1076
- var _b;
1077
- const ast = (0, parse_ast_1.parseAst)(input);
1078
- const videoConfigIdentifierValues = (0, video_config_values_1.getVideoConfigIdentifierValues)({
1079
- ast,
1080
- videoConfigValues,
1081
- });
1082
- const jsxPath = (0, get_ast_node_path_1.getAstNodePath)(ast, nodePath);
1083
- const node = (0, can_update_sequence_props_1.findJsxElementAtNodePath)(ast, nodePath);
1084
- if (!node || !jsxPath) {
1085
- throw new Error('Could not find a JSX element at the specified location to update keyframes');
1086
- }
1087
- if (!node.attributes) {
1088
- node.attributes = [];
1089
- }
1090
- const requiredImports = new Set();
1091
- let needsFrameHook = false;
1092
- const oldValueStrings = [];
1093
- const newValueStrings = [];
1094
- for (const update of updates) {
1095
- const prop = getSequenceWritableProp({
1096
- attributes: node.attributes,
1097
- key: update.key,
1098
- missingPropInitialValue: update.operation.type === 'add'
1099
- ? {
1100
- value: getInitialValueForMissingProp({
1101
- schema: schema !== null && schema !== void 0 ? schema : null,
1102
- key: update.key,
1103
- newValue: update.operation.value,
1104
- }),
1105
- }
1106
- : null,
1107
- });
1108
- oldValueStrings.push(recast.print(prop.expression).code);
1109
- const { expression: nextExpression, introduced } = applyKeyframeOperation({
1110
- expression: prop.expression,
1111
- key: update.key,
1112
- operation: update.operation,
1113
- schema: schema !== null && schema !== void 0 ? schema : null,
1114
- videoConfigValues: videoConfigIdentifierValues,
1115
- });
1116
- newValueStrings.push(recast.print(nextExpression).code);
1117
- if (shouldRemovePropAfterKeyframeOperation({
1118
- expression: prop.expression,
1119
- key: update.key,
1120
- operation: update.operation,
1121
- schema: schema !== null && schema !== void 0 ? schema : null,
1122
- videoConfigValues: videoConfigIdentifierValues,
1123
- })) {
1124
- prop.remove();
1125
- }
1126
- else {
1127
- prop.setExpression(nextExpression);
1128
- }
1129
- if (introduced.calleeName) {
1130
- requiredImports.add(introduced.calleeName);
1131
- }
1132
- if (introduced.needsFrameHook) {
1133
- requiredImports.add('useCurrentFrame');
1134
- needsFrameHook = true;
1135
- }
1136
- if (introduced.needsEasingImport) {
1137
- requiredImports.add('Easing');
1138
- }
1139
- }
1140
- if (needsFrameHook) {
1141
- const fnPath = (0, ensure_imports_and_frame_hook_1.findEnclosingFunctionPath)(jsxPath);
1142
- if (fnPath) {
1143
- (0, ensure_imports_and_frame_hook_1.ensureUseCurrentFrameHook)(fnPath);
1144
- }
1145
- }
1146
- (0, ensure_imports_and_frame_hook_1.ensureRemotionImports)(ast, requiredImports);
1147
- const updatedNodePath = (0, can_update_sequence_props_1.findNodePathForJsxElement)(ast, node);
1148
- if (!updatedNodePath) {
1149
- throw new Error('Could not find updated JSX element location after updating keyframes');
1150
- }
1151
- return {
1152
- serialized: (0, parse_ast_1.serializeAst)(ast),
1153
- oldValueStrings,
1154
- newValueStrings,
1155
- logLine: (_b = (_a = node.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1,
1156
- updatedNodePath,
1157
- };
1158
- };
1159
- exports.updateSequenceKeyframesAst = updateSequenceKeyframesAst;
1160
- const updateSequenceKeyframes = async ({ input, nodePath, updates, schema, prettierConfigOverride, videoConfigValues, }) => {
1161
- const { serialized, oldValueStrings, newValueStrings, logLine, updatedNodePath, } = (0, exports.updateSequenceKeyframesAst)({
1162
- input,
1163
- nodePath,
1164
- updates,
1165
- schema,
1166
- videoConfigValues,
1167
- });
1168
- const { output, formatted } = await (0, format_file_content_1.formatFileContent)({
1169
- input: serialized,
1170
- prettierConfigOverride,
1171
- });
1172
- const outputWithoutInsertedBlankLines = removeBlankLinesFromObjectsWithProperties({
1173
- input: output,
1174
- propertyNames: updates.map((update) => getObjectPropertyNameFromUpdateKey(update.key)),
1175
- });
1176
- return {
1177
- output: outputWithoutInsertedBlankLines,
1178
- formatted,
1179
- oldValueStrings,
1180
- newValueStrings,
1181
- logLine,
1182
- updatedNodePath,
1183
- };
1184
- };
6
+ const studio_codemods_2 = require("@remotion/studio-codemods");
7
+ Object.defineProperty(exports, "updateEffectKeyframesAst", { enumerable: true, get: function () { return studio_codemods_2.updateEffectKeyframesAst; } });
8
+ Object.defineProperty(exports, "updateSequenceKeyframesAst", { enumerable: true, get: function () { return studio_codemods_2.updateSequenceKeyframesAst; } });
9
+ const formatKeyframesFile = ({ contents, prettierConfigOverride, }) => (0, format_file_content_1.formatFileContent)({
10
+ input: contents,
11
+ prettierConfigOverride,
12
+ });
13
+ const updateSequenceKeyframes = (input) => (0, studio_codemods_1.updateSequenceKeyframes)({ ...input, formatFile: formatKeyframesFile });
1185
14
  exports.updateSequenceKeyframes = updateSequenceKeyframes;
1186
- const updateEffectKeyframesAst = ({ input, sequenceNodePath, effectIndex, updates, schema, videoConfigValues, }) => {
1187
- var _a, _b;
1188
- var _c, _d, _e;
1189
- const ast = (0, parse_ast_1.parseAst)(input);
1190
- const videoConfigIdentifierValues = (0, video_config_values_1.getVideoConfigIdentifierValues)({
1191
- ast,
1192
- videoConfigValues,
1193
- });
1194
- const jsxPath = (0, get_ast_node_path_1.getAstNodePath)(ast, sequenceNodePath);
1195
- const jsx = (0, can_update_sequence_props_1.findJsxElementAtNodePath)(ast, sequenceNodePath);
1196
- if (!jsx || !jsxPath) {
1197
- throw new Error('Could not find a JSX element at the specified location to update effect keyframes');
1198
- }
1199
- const attr = (0, update_effect_props_1.findEffectsAttr)((_c = jsx.attributes) !== null && _c !== void 0 ? _c : []);
1200
- if (!attr) {
1201
- throw new Error('Could not find effects on the target JSX element');
1202
- }
1203
- const found = (0, update_effect_props_1.findEffectCallExpression)({ attr, effectIndex });
1204
- if (found.kind === 'error') {
1205
- throw new Error(`Cannot update effect keyframe: ${found.reason}`);
1206
- }
1207
- const { call, callee: effectCallee } = found;
1208
- const objExpr = getEffectPropsObjectExpression(call);
1209
- const oldValueStrings = [];
1210
- const newValueStrings = [];
1211
- const requiredImports = new Set();
1212
- let needsFrameHook = false;
1213
- for (const update of updates) {
1214
- const prop = getEffectWritableProp({
1215
- objExpr,
1216
- key: update.key,
1217
- missingPropInitialValue: update.operation.type === 'add'
1218
- ? {
1219
- value: getInitialValueForMissingProp({
1220
- schema: schema !== null && schema !== void 0 ? schema : null,
1221
- key: update.key,
1222
- newValue: update.operation.value,
1223
- }),
1224
- }
1225
- : null,
1226
- });
1227
- oldValueStrings.push(recast.print(prop.expression).code);
1228
- const { expression: nextExpression, introduced } = applyKeyframeOperation({
1229
- expression: prop.expression,
1230
- key: update.key,
1231
- operation: update.operation,
1232
- schema: schema !== null && schema !== void 0 ? schema : null,
1233
- videoConfigValues: videoConfigIdentifierValues,
1234
- });
1235
- newValueStrings.push(recast.print(nextExpression).code);
1236
- if (shouldRemovePropAfterKeyframeOperation({
1237
- expression: prop.expression,
1238
- key: update.key,
1239
- operation: update.operation,
1240
- schema: schema !== null && schema !== void 0 ? schema : null,
1241
- videoConfigValues: videoConfigIdentifierValues,
1242
- })) {
1243
- prop.remove();
1244
- }
1245
- else {
1246
- prop.setExpression(nextExpression);
1247
- }
1248
- if (introduced.calleeName) {
1249
- requiredImports.add(introduced.calleeName);
1250
- }
1251
- if (introduced.needsFrameHook) {
1252
- requiredImports.add('useCurrentFrame');
1253
- needsFrameHook = true;
1254
- }
1255
- if (introduced.needsEasingImport) {
1256
- requiredImports.add('Easing');
1257
- }
1258
- }
1259
- if (needsFrameHook) {
1260
- const fnPath = (0, ensure_imports_and_frame_hook_1.findEnclosingFunctionPath)(jsxPath);
1261
- if (fnPath) {
1262
- (0, ensure_imports_and_frame_hook_1.ensureUseCurrentFrameHook)(fnPath);
1263
- }
1264
- }
1265
- (0, ensure_imports_and_frame_hook_1.ensureRemotionImports)(ast, requiredImports);
1266
- const updatedSequenceNodePath = (0, can_update_sequence_props_1.findNodePathForJsxElement)(ast, jsx);
1267
- if (!updatedSequenceNodePath) {
1268
- throw new Error('Could not find updated JSX element location after updating effect keyframes');
1269
- }
1270
- return {
1271
- serialized: (0, parse_ast_1.serializeAst)(ast),
1272
- oldValueStrings,
1273
- newValueStrings,
1274
- logLine: (_e = (_d = (_a = call.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _d !== void 0 ? _d : (_b = jsx.loc) === null || _b === void 0 ? void 0 : _b.start.line) !== null && _e !== void 0 ? _e : 1,
1275
- effectCallee,
1276
- updatedSequenceNodePath,
1277
- };
1278
- };
1279
- exports.updateEffectKeyframesAst = updateEffectKeyframesAst;
1280
- const updateEffectKeyframes = async ({ input, sequenceNodePath, effectIndex, updates, schema, prettierConfigOverride, videoConfigValues, }) => {
1281
- const { serialized, oldValueStrings, newValueStrings, logLine, effectCallee, updatedSequenceNodePath, } = (0, exports.updateEffectKeyframesAst)({
1282
- input,
1283
- sequenceNodePath,
1284
- effectIndex,
1285
- updates,
1286
- schema,
1287
- videoConfigValues,
1288
- });
1289
- const { output, formatted } = await (0, format_file_content_1.formatFileContent)({
1290
- input: serialized,
1291
- prettierConfigOverride,
1292
- });
1293
- const outputWithoutInsertedBlankLines = removeBlankLinesFromObjectsWithProperties({
1294
- input: output,
1295
- propertyNames: updates.map((update) => update.key),
1296
- });
1297
- return {
1298
- output: outputWithoutInsertedBlankLines,
1299
- formatted,
1300
- oldValueStrings,
1301
- newValueStrings,
1302
- logLine,
1303
- effectCallee,
1304
- updatedSequenceNodePath,
1305
- };
1306
- };
15
+ const updateEffectKeyframes = (input) => (0, studio_codemods_1.updateEffectKeyframes)({ ...input, formatFile: formatKeyframesFile });
1307
16
  exports.updateEffectKeyframes = updateEffectKeyframes;