@remotion/studio-server 4.0.524 → 4.0.525

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 (43) hide show
  1. package/dist/codemods/add-effect.d.ts +1 -26
  2. package/dist/codemods/add-effect.js +6 -191
  3. package/dist/codemods/delete-effect.d.ts +1 -30
  4. package/dist/codemods/delete-effect.js +4 -126
  5. package/dist/codemods/duplicate-effect.d.ts +1 -26
  6. package/dist/codemods/duplicate-effect.js +4 -90
  7. package/dist/codemods/paste-effects.d.ts +9 -14
  8. package/dist/codemods/paste-effects.js +2 -170
  9. package/dist/codemods/reorder-effect.d.ts +1 -13
  10. package/dist/codemods/reorder-effect.js +2 -58
  11. package/dist/codemods/update-effect-props/update-effect-props.d.ts +2 -67
  12. package/dist/codemods/update-effect-props/update-effect-props.js +8 -312
  13. package/dist/codemods/update-keyframes/update-keyframes.js +2 -7
  14. package/dist/codemods/update-sequence-props/update-sequence-props.js +20 -58
  15. package/dist/helpers/resolve-composition-component.d.ts +2 -1
  16. package/dist/helpers/resolve-composition-component.js +13 -7
  17. package/dist/preview-server/api-routes.js +5 -0
  18. package/dist/preview-server/routes/add-keyframes.js +1 -0
  19. package/dist/preview-server/routes/apply-codemod.d.ts +19 -0
  20. package/dist/preview-server/routes/apply-codemod.js +17 -55
  21. package/dist/preview-server/routes/batch-update-keyframe-settings.js +1 -0
  22. package/dist/preview-server/routes/delete-keyframes.js +1 -0
  23. package/dist/preview-server/routes/duplicate-jsx-node.js +1 -0
  24. package/dist/preview-server/routes/insert-element.js +122 -19
  25. package/dist/preview-server/routes/insert-jsx-element.js +1 -0
  26. package/dist/preview-server/routes/install-remotion-skill.d.ts +4 -0
  27. package/dist/preview-server/routes/install-remotion-skill.js +108 -0
  28. package/dist/preview-server/routes/invalidate-bundle.d.ts +3 -0
  29. package/dist/preview-server/routes/invalidate-bundle.js +11 -0
  30. package/dist/preview-server/routes/move-keyframes.js +1 -0
  31. package/dist/preview-server/routes/save-multiple-effect-props.js +1 -0
  32. package/dist/preview-server/routes/save-sequence-props.js +1 -0
  33. package/dist/preview-server/undo-stack.d.ts +4 -2
  34. package/dist/preview-server/undo-stack.js +22 -4
  35. package/dist/preview-server/watch-ignore-next-change.d.ts +1 -0
  36. package/dist/preview-server/watch-ignore-next-change.js +20 -12
  37. package/package.json +8 -8
  38. package/dist/preview-server/routes/delete-effect-keyframe.d.ts +0 -3
  39. package/dist/preview-server/routes/delete-effect-keyframe.js +0 -89
  40. package/dist/preview-server/routes/delete-sequence-keyframe.d.ts +0 -3
  41. package/dist/preview-server/routes/delete-sequence-keyframe.js +0 -82
  42. package/dist/preview-server/routes/save-props-mutex.d.ts +0 -1
  43. package/dist/preview-server/routes/save-props-mutex.js +0 -11
@@ -1,174 +1,6 @@
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
3
  exports.pasteEffects = void 0;
37
- const recast = __importStar(require("recast"));
38
- const get_ast_node_path_1 = require("../helpers/get-ast-node-path");
39
- const can_update_sequence_props_1 = require("../preview-server/routes/can-update-sequence-props");
40
- const add_effect_1 = require("./add-effect");
41
- const effect_param_expression_1 = require("./effect-param-expression");
42
- const format_file_content_1 = require("./format-file-content");
43
- const parse_ast_1 = require("./parse-ast");
44
- const update_effect_props_1 = require("./update-effect-props/update-effect-props");
45
- const ensure_imports_and_frame_hook_1 = require("./update-keyframes/ensure-imports-and-frame-hook");
46
- const b = recast.types.builders;
47
- const identifierRegex = /^[A-Za-z_$][0-9A-Za-z_$]*$/;
48
- const getEffectsArray = (attr) => {
49
- if (!attr.value || attr.value.type !== 'JSXExpressionContainer') {
50
- throw new Error('Cannot append effects: effects prop is not an array');
51
- }
52
- const expr = attr.value.expression;
53
- if (expr.type !== 'ArrayExpression') {
54
- throw new Error('Cannot append effects: effects prop is not an array');
55
- }
56
- return expr;
57
- };
58
- const makeEffectsAttr = (array) => {
59
- return b.jsxAttribute(b.jsxIdentifier('effects'), b.jsxExpressionContainer(array));
60
- };
61
- const makeEffectsArray = (calls) => {
62
- return b.arrayExpression(calls);
63
- };
64
- const makeParamsObjectExpression = ({ params, remotionLocalNames, }) => {
65
- return b.objectExpression(Object.entries(params).map(([key, param]) => {
66
- const keyNode = identifierRegex.test(key)
67
- ? b.identifier(key)
68
- : b.stringLiteral(key);
69
- return b.objectProperty(keyNode, (0, effect_param_expression_1.makeParamExpression)({ param, remotionLocalNames }));
70
- }));
71
- };
72
- const makeEffectCall = ({ ast, effect, remotionLocalNames, }) => {
73
- (0, add_effect_1.assertValidEffect)({
74
- effectName: effect.callee,
75
- effectImportPath: effect.importPath,
76
- });
77
- const localName = (0, add_effect_1.ensureEffectImport)({
78
- ast,
79
- effectName: effect.callee,
80
- effectImportPath: effect.importPath,
81
- });
82
- return b.callExpression(b.identifier(localName), [
83
- makeParamsObjectExpression({
84
- params: effect.params,
85
- remotionLocalNames,
86
- }),
87
- ]);
88
- };
89
- const removeEffectsAttr = (attributes, attr) => {
90
- const index = attributes.indexOf(attr);
91
- if (index !== -1) {
92
- attributes.splice(index, 1);
93
- }
94
- };
95
- const pasteEffects = async ({ input, targetSequenceNodePath, type, effects, insertAtIndices, prettierConfigOverride, }) => {
96
- var _a;
97
- var _b, _c, _d;
98
- const ast = (0, parse_ast_1.parseAst)(input);
99
- const targetJsxPath = (0, get_ast_node_path_1.getAstNodePath)(ast, targetSequenceNodePath);
100
- const targetJsx = (0, can_update_sequence_props_1.findJsxElementAtNodePath)(ast, targetSequenceNodePath);
101
- if (!targetJsx || !targetJsxPath) {
102
- throw new Error('Could not find a JSX element at the specified location to paste effects');
103
- }
104
- const requiredRemotionImports = (0, effect_param_expression_1.getRequiredRemotionImports)(effects);
105
- const remotionLocalNames = (0, effect_param_expression_1.ensureRemotionImportLocalNames)({
106
- ast,
107
- requiredImports: requiredRemotionImports,
108
- });
109
- if (requiredRemotionImports.has('useCurrentFrame')) {
110
- const fnPath = (0, ensure_imports_and_frame_hook_1.findEnclosingFunctionPath)(targetJsxPath);
111
- if (fnPath) {
112
- (0, ensure_imports_and_frame_hook_1.ensureUseCurrentFrameHook)(fnPath, (_b = remotionLocalNames.useCurrentFrame) !== null && _b !== void 0 ? _b : 'useCurrentFrame');
113
- }
114
- }
115
- const effectCalls = effects.map((effect) => makeEffectCall({ ast, effect, remotionLocalNames }));
116
- const effectLabels = effects.map((effect) => `${effect.callee}()`);
117
- const existingAttr = (0, update_effect_props_1.findEffectsAttr)((_c = targetJsx.attributes) !== null && _c !== void 0 ? _c : []);
118
- if (insertAtIndices !== null) {
119
- if (type !== 'effects-additive' ||
120
- insertAtIndices.length !== effectCalls.length ||
121
- new Set(insertAtIndices).size !== insertAtIndices.length ||
122
- insertAtIndices.some((index) => !Number.isInteger(index) || index < 0)) {
123
- throw new Error('Cannot paste effects: invalid insertion indices');
124
- }
125
- }
126
- if (type === 'effects-replacing') {
127
- if (existingAttr) {
128
- removeEffectsAttr(targetJsx.attributes, existingAttr);
129
- }
130
- if (effectCalls.length > 0) {
131
- targetJsx.attributes.push(makeEffectsAttr(makeEffectsArray(effectCalls)));
132
- }
133
- }
134
- else if (effectCalls.length === 0) {
135
- throw new Error('Cannot paste effects: no effects were copied');
136
- }
137
- else if (insertAtIndices === null) {
138
- if (existingAttr) {
139
- getEffectsArray(existingAttr).elements.push(...effectCalls);
140
- }
141
- else {
142
- targetJsx.attributes.push(makeEffectsAttr(makeEffectsArray(effectCalls)));
143
- }
144
- }
145
- else {
146
- const elements = existingAttr
147
- ? getEffectsArray(existingAttr).elements
148
- : [];
149
- const indexedCalls = effectCalls
150
- .map((effect, index) => ({
151
- effect,
152
- index: insertAtIndices[index],
153
- }))
154
- .sort((left, right) => left.index - right.index);
155
- for (const indexedCall of indexedCalls) {
156
- elements.splice(Math.min(indexedCall.index, elements.length), 0, indexedCall.effect);
157
- }
158
- if (!existingAttr) {
159
- targetJsx.attributes.push(makeEffectsAttr(b.arrayExpression(elements)));
160
- }
161
- }
162
- const finalFile = (0, parse_ast_1.serializeAst)(ast);
163
- const { output, formatted } = await (0, format_file_content_1.formatFileContent)({
164
- input: finalFile,
165
- prettierConfigOverride,
166
- });
167
- return {
168
- output,
169
- formatted,
170
- effectLabels,
171
- logLine: (_d = (_a = targetJsx.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _d !== void 0 ? _d : 1,
172
- };
173
- };
4
+ const studio_codemods_1 = require("@remotion/studio-codemods");
5
+ const pasteEffects = (input) => (0, studio_codemods_1.pasteEffects)(input);
174
6
  exports.pasteEffects = pasteEffects;
@@ -1,13 +1 @@
1
- import type { SequenceNodePath } from 'remotion';
2
- export declare const reorderEffect: ({ input, sequenceNodePath, fromIndex, toIndex, prettierConfigOverride, }: {
3
- input: string;
4
- sequenceNodePath: SequenceNodePath;
5
- fromIndex: number;
6
- toIndex: number;
7
- prettierConfigOverride?: Record<string, unknown> | null | undefined;
8
- }) => Promise<{
9
- output: string;
10
- formatted: boolean;
11
- effectLabel: string;
12
- logLine: number;
13
- }>;
1
+ export { reorderEffect } from '@remotion/studio-codemods';
@@ -1,61 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.reorderEffect = void 0;
4
- const can_update_sequence_props_1 = require("../preview-server/routes/can-update-sequence-props");
5
- const format_file_content_1 = require("./format-file-content");
6
- const parse_ast_1 = require("./parse-ast");
7
- const update_effect_props_1 = require("./update-effect-props/update-effect-props");
8
- const getEffectsArray = (attr) => {
9
- if (!attr.value || attr.value.type !== 'JSXExpressionContainer') {
10
- throw new Error('Cannot reorder effect: effects prop is not an array');
11
- }
12
- const expr = attr.value.expression;
13
- if (expr.type !== 'ArrayExpression') {
14
- throw new Error('Cannot reorder effect: effects prop is not an array');
15
- }
16
- return expr;
17
- };
18
- const reorderEffect = async ({ input, sequenceNodePath, fromIndex, toIndex, prettierConfigOverride, }) => {
19
- var _a, _b;
20
- var _c, _d, _e;
21
- const ast = (0, parse_ast_1.parseAst)(input);
22
- const jsx = (0, can_update_sequence_props_1.findJsxElementAtNodePath)(ast, sequenceNodePath);
23
- if (!jsx) {
24
- throw new Error('Could not find a JSX element at the specified location to reorder effect');
25
- }
26
- const attr = (0, update_effect_props_1.findEffectsAttr)((_c = jsx.attributes) !== null && _c !== void 0 ? _c : []);
27
- if (!attr) {
28
- throw new Error('Could not find effects on the target JSX element');
29
- }
30
- const effectsArray = getEffectsArray(attr);
31
- const elements = (0, update_effect_props_1.enumerateEffectArrayElements)(effectsArray);
32
- if (fromIndex < 0 || fromIndex >= elements.length) {
33
- throw new Error('Cannot reorder effect: source index not-found');
34
- }
35
- if (toIndex < 0 || toIndex >= elements.length) {
36
- throw new Error('Cannot reorder effect: target index not-found');
37
- }
38
- const target = elements[fromIndex];
39
- if (target.kind !== 'call') {
40
- throw new Error('Cannot reorder effect: source effect is not-call-expression');
41
- }
42
- if (fromIndex !== toIndex) {
43
- const [moved] = effectsArray.elements.splice(fromIndex, 1);
44
- if (!moved) {
45
- throw new Error('Cannot reorder effect: source effect is not-call-expression');
46
- }
47
- effectsArray.elements.splice(toIndex, 0, moved);
48
- }
49
- const finalFile = (0, parse_ast_1.serializeAst)(ast);
50
- const { output, formatted } = await (0, format_file_content_1.formatFileContent)({
51
- input: finalFile,
52
- prettierConfigOverride,
53
- });
54
- return {
55
- output,
56
- formatted,
57
- effectLabel: `${target.callee}()`,
58
- logLine: (_e = (_d = (_a = target.node.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,
59
- };
60
- };
61
- exports.reorderEffect = reorderEffect;
4
+ const studio_codemods_1 = require("@remotion/studio-codemods");
5
+ Object.defineProperty(exports, "reorderEffect", { enumerable: true, get: function () { return studio_codemods_1.reorderEffect; } });
@@ -1,68 +1,3 @@
1
- import type { ArrayExpression, CallExpression, JSXAttribute } from '@babel/types';
2
- import type { EffectClipboardParam } from '@remotion/studio-shared';
3
- import type { SequenceNodePath, InteractivitySchema } from 'remotion';
4
- export type EffectPropUpdate = {
5
- key: string;
6
- value: unknown;
7
- defaultValue: unknown | null;
8
- } | {
9
- key: string;
10
- effectParam: EffectClipboardParam;
11
- defaultValue: unknown | null;
12
- };
13
- export type UpdateEffectPropsResult = {
14
- output: string;
15
- formatted: boolean;
16
- oldValueString: string;
17
- newValueString: string;
18
- logLine: number;
19
- effectCallee: string;
20
- removedProps: PropDelta[];
21
- };
22
- export type PropDelta = {
23
- key: string;
24
- valueString: string;
25
- };
1
+ import type { JSXAttribute } from '@babel/types';
2
+ export { enumerateEffectArrayElements, findEffectCallExpression, type EffectArrayElement, type EffectPropUpdate, type PropDelta, type UpdateEffectPropsResult, updateEffectProps, updateEffectPropsAst, } from '@remotion/studio-codemods';
26
3
  export declare const findEffectsAttr: (attrs: readonly unknown[]) => JSXAttribute | null;
27
- export type EffectArrayElement = {
28
- kind: 'call';
29
- callee: string;
30
- node: CallExpression;
31
- } | {
32
- kind: 'unsupported';
33
- reason: 'not-call-expression' | 'spread';
34
- };
35
- export declare const enumerateEffectArrayElements: (arr: ArrayExpression) => EffectArrayElement[];
36
- export declare const findEffectCallExpression: ({ attr, effectIndex, }: {
37
- attr: JSXAttribute;
38
- effectIndex: number;
39
- }) => {
40
- kind: "ok";
41
- call: CallExpression;
42
- callee: string;
43
- } | {
44
- kind: "error";
45
- reason: "not-call-expression" | "not-found";
46
- };
47
- export declare const updateEffectPropsAst: ({ input, sequenceNodePath, effectIndex, update, schema, }: {
48
- input: string;
49
- sequenceNodePath: SequenceNodePath;
50
- effectIndex: number;
51
- update: EffectPropUpdate;
52
- schema: InteractivitySchema;
53
- }) => {
54
- serialized: string;
55
- oldValueString: string;
56
- newValueString: string;
57
- logLine: number;
58
- effectCallee: string;
59
- removedProps: PropDelta[];
60
- };
61
- export declare const updateEffectProps: ({ input, sequenceNodePath, effectIndex, update, schema, prettierConfigOverride, }: {
62
- input: string;
63
- sequenceNodePath: SequenceNodePath;
64
- effectIndex: number;
65
- update: EffectPropUpdate;
66
- schema: InteractivitySchema;
67
- prettierConfigOverride?: Record<string, unknown> | null | undefined;
68
- }) => Promise<UpdateEffectPropsResult>;
@@ -1,317 +1,13 @@
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.updateEffectProps = exports.updateEffectPropsAst = exports.findEffectCallExpression = exports.enumerateEffectArrayElements = exports.findEffectsAttr = void 0;
37
- const recast = __importStar(require("recast"));
38
- const no_react_1 = require("remotion/no-react");
39
- const get_ast_node_path_1 = require("../../helpers/get-ast-node-path");
40
- const can_update_sequence_props_1 = require("../../preview-server/routes/can-update-sequence-props");
41
- const effect_param_expression_1 = require("../effect-param-expression");
42
- const format_file_content_1 = require("../format-file-content");
43
- const parse_ast_1 = require("../parse-ast");
44
- const ensure_imports_and_frame_hook_1 = require("../update-keyframes/ensure-imports-and-frame-hook");
45
- const update_nested_prop_1 = require("../update-nested-prop");
46
- const b = recast.types.builders;
3
+ exports.findEffectsAttr = exports.updateEffectPropsAst = exports.updateEffectProps = exports.findEffectCallExpression = exports.enumerateEffectArrayElements = void 0;
4
+ const studio_codemods_1 = require("@remotion/studio-codemods");
5
+ const studio_codemods_2 = require("@remotion/studio-codemods");
6
+ Object.defineProperty(exports, "enumerateEffectArrayElements", { enumerable: true, get: function () { return studio_codemods_2.enumerateEffectArrayElements; } });
7
+ Object.defineProperty(exports, "findEffectCallExpression", { enumerable: true, get: function () { return studio_codemods_2.findEffectCallExpression; } });
8
+ Object.defineProperty(exports, "updateEffectProps", { enumerable: true, get: function () { return studio_codemods_2.updateEffectProps; } });
9
+ Object.defineProperty(exports, "updateEffectPropsAst", { enumerable: true, get: function () { return studio_codemods_2.updateEffectPropsAst; } });
47
10
  const findEffectsAttr = (attrs) => {
48
- for (const attr of attrs) {
49
- if (attr.type !== 'JSXAttribute') {
50
- continue;
51
- }
52
- const a = attr;
53
- if (a.name.type === 'JSXIdentifier' && a.name.name === 'effects') {
54
- return a;
55
- }
56
- }
57
- return null;
11
+ return (0, studio_codemods_1.findEffectsAttr)(attrs);
58
12
  };
59
13
  exports.findEffectsAttr = findEffectsAttr;
60
- const getCalleeName = (call) => {
61
- const { callee } = call;
62
- if (callee.type === 'Identifier') {
63
- return callee.name;
64
- }
65
- if (callee.type === 'MemberExpression' &&
66
- !callee.computed &&
67
- callee.property.type === 'Identifier') {
68
- return callee.property.name;
69
- }
70
- return null;
71
- };
72
- const enumerateEffectArrayElements = (arr) => {
73
- const out = [];
74
- for (const el of arr.elements) {
75
- if (el === null) {
76
- out.push({ kind: 'unsupported', reason: 'not-call-expression' });
77
- continue;
78
- }
79
- if (el.type === 'SpreadElement') {
80
- out.push({ kind: 'unsupported', reason: 'spread' });
81
- continue;
82
- }
83
- if (el.type !== 'CallExpression') {
84
- out.push({ kind: 'unsupported', reason: 'not-call-expression' });
85
- continue;
86
- }
87
- const call = el;
88
- const callee = getCalleeName(call);
89
- if (callee === null) {
90
- out.push({ kind: 'unsupported', reason: 'not-call-expression' });
91
- continue;
92
- }
93
- out.push({ kind: 'call', callee, node: call });
94
- }
95
- return out;
96
- };
97
- exports.enumerateEffectArrayElements = enumerateEffectArrayElements;
98
- const findEffectCallExpression = ({ attr, effectIndex, }) => {
99
- if (!attr.value || attr.value.type !== 'JSXExpressionContainer') {
100
- return { kind: 'error', reason: 'not-call-expression' };
101
- }
102
- const expr = attr.value.expression;
103
- if (expr.type !== 'ArrayExpression') {
104
- return { kind: 'error', reason: 'not-call-expression' };
105
- }
106
- const elements = (0, exports.enumerateEffectArrayElements)(expr);
107
- if (effectIndex < 0 || effectIndex >= elements.length) {
108
- return { kind: 'error', reason: 'not-found' };
109
- }
110
- const target = elements[effectIndex];
111
- if (target.kind !== 'call') {
112
- return { kind: 'error', reason: 'not-call-expression' };
113
- }
114
- return { kind: 'ok', call: target.node, callee: target.callee };
115
- };
116
- exports.findEffectCallExpression = findEffectCallExpression;
117
- const findObjectProperty = (objExpr, propertyName) => {
118
- const propIndex = objExpr.properties.findIndex((p) => p.type === 'ObjectProperty' &&
119
- ((p.key.type === 'Identifier' && p.key.name === propertyName) ||
120
- (p.key.type === 'StringLiteral' &&
121
- p.key.value === propertyName)));
122
- return {
123
- propIndex,
124
- prop: propIndex !== -1
125
- ? objExpr.properties[propIndex]
126
- : undefined,
127
- };
128
- };
129
- const printObjectPropertyValue = (prop) => recast
130
- .print(prop.value)
131
- .code.replace(/[\n\r\t]+/g, ' ')
132
- .replace(/,(\s*[}\]])/g, '$1')
133
- .trim();
134
- const updateHasEffectParam = (update) => 'effectParam' in update;
135
- const getStaticUpdateValue = (update) => {
136
- if (updateHasEffectParam(update)) {
137
- return update.effectParam.type === 'static'
138
- ? update.effectParam.value
139
- : null;
140
- }
141
- return update.value;
142
- };
143
- const ensureClipboardParamImports = ({ ast, sequenceNodePath, param, }) => {
144
- var _a;
145
- const requiredImports = (0, effect_param_expression_1.getRequiredRemotionImportsForEffectParams)([param]);
146
- const remotionLocalNames = (0, effect_param_expression_1.ensureRemotionImportLocalNames)({
147
- ast,
148
- requiredImports,
149
- });
150
- if (requiredImports.has('useCurrentFrame')) {
151
- const targetJsxPath = (0, get_ast_node_path_1.getAstNodePath)(ast, sequenceNodePath);
152
- if (targetJsxPath) {
153
- const fnPath = (0, ensure_imports_and_frame_hook_1.findEnclosingFunctionPath)(targetJsxPath);
154
- if (fnPath) {
155
- (0, ensure_imports_and_frame_hook_1.ensureUseCurrentFrameHook)(fnPath, (_a = remotionLocalNames.useCurrentFrame) !== null && _a !== void 0 ? _a : 'useCurrentFrame');
156
- }
157
- }
158
- }
159
- return remotionLocalNames;
160
- };
161
- const makeUpdateValueExpression = ({ ast, sequenceNodePath, update, }) => {
162
- if (!updateHasEffectParam(update)) {
163
- return (0, update_nested_prop_1.parseValueExpression)(update.value);
164
- }
165
- const remotionLocalNames = ensureClipboardParamImports({
166
- ast,
167
- sequenceNodePath,
168
- param: update.effectParam,
169
- });
170
- return (0, effect_param_expression_1.makeParamExpression)({
171
- param: update.effectParam,
172
- remotionLocalNames,
173
- });
174
- };
175
- const removeObjectProperty = ({ objExpr, propertyName, }) => {
176
- const { propIndex, prop } = findObjectProperty(objExpr, propertyName);
177
- if (!prop || propIndex === -1) {
178
- return null;
179
- }
180
- const valueString = printObjectPropertyValue(prop);
181
- objExpr.properties.splice(propIndex, 1);
182
- return {
183
- key: propertyName,
184
- valueString,
185
- };
186
- };
187
- const updateEffectPropsAst = ({ input, sequenceNodePath, effectIndex, update, schema, }) => {
188
- var _a, _b, _c, _d;
189
- var _e, _f, _g, _h, _j;
190
- const ast = (0, parse_ast_1.parseAst)(input);
191
- const jsx = (0, can_update_sequence_props_1.findJsxElementAtNodePath)(ast, sequenceNodePath);
192
- if (!jsx) {
193
- throw new Error('Could not find a JSX element at the specified location to update effects');
194
- }
195
- const attr = (0, exports.findEffectsAttr)((_e = jsx.attributes) !== null && _e !== void 0 ? _e : []);
196
- if (!attr) {
197
- throw new Error('Could not find effects on the target JSX element');
198
- }
199
- const found = (0, exports.findEffectCallExpression)({
200
- attr,
201
- effectIndex,
202
- });
203
- if (found.kind === 'error') {
204
- throw new Error(`Cannot update effect prop: ${found.reason}`);
205
- }
206
- const { call, callee: effectCallee } = found;
207
- const isDefault = !updateHasEffectParam(update) &&
208
- update.defaultValue !== null &&
209
- JSON.stringify(update.value) === JSON.stringify(update.defaultValue);
210
- let objExpr;
211
- if (call.arguments.length === 0) {
212
- if (isDefault) {
213
- return {
214
- serialized: (0, parse_ast_1.serializeAst)(ast),
215
- oldValueString: '',
216
- newValueString: JSON.stringify(update.defaultValue),
217
- logLine: (_g = (_f = (_a = call.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _f !== void 0 ? _f : (_b = jsx.loc) === null || _b === void 0 ? void 0 : _b.start.line) !== null && _g !== void 0 ? _g : 1,
218
- effectCallee,
219
- removedProps: [],
220
- };
221
- }
222
- objExpr = b.objectExpression([]);
223
- call.arguments.push(objExpr);
224
- }
225
- else if (call.arguments[0].type !== 'ObjectExpression') {
226
- throw new Error('Cannot update effect prop: computed');
227
- }
228
- else {
229
- objExpr = call.arguments[0];
230
- }
231
- const { prop } = findObjectProperty(objExpr, update.key);
232
- const removedProps = [];
233
- let oldValueString = '';
234
- if (prop) {
235
- oldValueString = recast.print(prop.value).code;
236
- }
237
- else if (update.defaultValue !== null) {
238
- oldValueString = JSON.stringify(update.defaultValue);
239
- }
240
- let newValueString = '';
241
- if (isDefault) {
242
- newValueString = JSON.stringify(update.defaultValue);
243
- if (prop) {
244
- const idx = objExpr.properties.indexOf(prop);
245
- if (idx !== -1) {
246
- objExpr.properties.splice(idx, 1);
247
- }
248
- }
249
- }
250
- else {
251
- const newValueExpr = makeUpdateValueExpression({
252
- ast,
253
- sequenceNodePath,
254
- update,
255
- });
256
- newValueString = recast.print(newValueExpr).code;
257
- if (prop) {
258
- prop.value = newValueExpr;
259
- }
260
- else {
261
- objExpr.properties.push(b.objectProperty(b.identifier(update.key), newValueExpr));
262
- }
263
- }
264
- const fieldSchema = schema[update.key];
265
- const staticUpdateValue = getStaticUpdateValue(update);
266
- if (fieldSchema &&
267
- fieldSchema.type === 'enum' &&
268
- staticUpdateValue !== null) {
269
- const propsToDelete = no_react_1.NoReactInternals.findPropsToDelete({
270
- schema,
271
- key: update.key,
272
- value: staticUpdateValue,
273
- });
274
- for (const propToDelete of propsToDelete) {
275
- const removed = removeObjectProperty({
276
- objExpr,
277
- propertyName: propToDelete,
278
- });
279
- if (removed) {
280
- removedProps.push(removed);
281
- }
282
- }
283
- }
284
- const logLine = (_j = (_h = (_c = call.loc) === null || _c === void 0 ? void 0 : _c.start.line) !== null && _h !== void 0 ? _h : (_d = jsx.loc) === null || _d === void 0 ? void 0 : _d.start.line) !== null && _j !== void 0 ? _j : 1;
285
- return {
286
- serialized: (0, parse_ast_1.serializeAst)(ast),
287
- oldValueString,
288
- newValueString,
289
- logLine,
290
- effectCallee,
291
- removedProps,
292
- };
293
- };
294
- exports.updateEffectPropsAst = updateEffectPropsAst;
295
- const updateEffectProps = async ({ input, sequenceNodePath, effectIndex, update, schema, prettierConfigOverride, }) => {
296
- const { serialized, oldValueString, newValueString, logLine, effectCallee, removedProps, } = (0, exports.updateEffectPropsAst)({
297
- input,
298
- sequenceNodePath,
299
- effectIndex,
300
- update,
301
- schema,
302
- });
303
- const { output, formatted } = await (0, format_file_content_1.formatFileContent)({
304
- input: serialized,
305
- prettierConfigOverride,
306
- });
307
- return {
308
- output,
309
- oldValueString,
310
- newValueString,
311
- formatted,
312
- logLine,
313
- effectCallee,
314
- removedProps,
315
- };
316
- };
317
- exports.updateEffectProps = updateEffectProps;
@@ -2,15 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateEffectKeyframes = exports.updateSequenceKeyframes = exports.updateSequenceKeyframesAst = exports.updateEffectKeyframesAst = void 0;
4
4
  const studio_codemods_1 = require("@remotion/studio-codemods");
5
- const format_file_content_1 = require("../format-file-content");
6
5
  const studio_codemods_2 = require("@remotion/studio-codemods");
7
6
  Object.defineProperty(exports, "updateEffectKeyframesAst", { enumerable: true, get: function () { return studio_codemods_2.updateEffectKeyframesAst; } });
8
7
  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 });
8
+ const updateSequenceKeyframes = (input) => (0, studio_codemods_1.updateSequenceKeyframes)(input);
14
9
  exports.updateSequenceKeyframes = updateSequenceKeyframes;
15
- const updateEffectKeyframes = (input) => (0, studio_codemods_1.updateEffectKeyframes)({ ...input, formatFile: formatKeyframesFile });
10
+ const updateEffectKeyframes = (input) => (0, studio_codemods_1.updateEffectKeyframes)(input);
16
11
  exports.updateEffectKeyframes = updateEffectKeyframes;