@remotion/studio-server 4.0.523 → 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 (52) hide show
  1. package/dist/canvas-capture/generate-canvas-capture-composition.d.ts +1 -1
  2. package/dist/canvas-capture/generate-canvas-capture-composition.js +77 -12
  3. package/dist/codemods/add-effect.d.ts +1 -26
  4. package/dist/codemods/add-effect.js +6 -191
  5. package/dist/codemods/apply-codemod-to-file.js +8 -1
  6. package/dist/codemods/delete-effect.d.ts +1 -30
  7. package/dist/codemods/delete-effect.js +4 -126
  8. package/dist/codemods/duplicate-effect.d.ts +1 -26
  9. package/dist/codemods/duplicate-effect.js +4 -90
  10. package/dist/codemods/paste-effects.d.ts +9 -14
  11. package/dist/codemods/paste-effects.js +2 -170
  12. package/dist/codemods/reorder-effect.d.ts +1 -13
  13. package/dist/codemods/reorder-effect.js +2 -58
  14. package/dist/codemods/update-effect-props/update-effect-props.d.ts +2 -67
  15. package/dist/codemods/update-effect-props/update-effect-props.js +8 -312
  16. package/dist/codemods/update-keyframes/update-keyframes.js +2 -7
  17. package/dist/codemods/update-sequence-props/update-sequence-props.js +20 -58
  18. package/dist/helpers/resolve-composition-component.d.ts +2 -1
  19. package/dist/helpers/resolve-composition-component.js +13 -7
  20. package/dist/preview-server/api-routes.js +5 -0
  21. package/dist/preview-server/routes/add-keyframes.js +1 -0
  22. package/dist/preview-server/routes/apply-codemod.d.ts +19 -0
  23. package/dist/preview-server/routes/apply-codemod.js +17 -56
  24. package/dist/preview-server/routes/batch-update-keyframe-settings.js +1 -0
  25. package/dist/preview-server/routes/delete-keyframes.js +1 -0
  26. package/dist/preview-server/routes/duplicate-jsx-node.js +1 -0
  27. package/dist/preview-server/routes/insert-element.js +150 -29
  28. package/dist/preview-server/routes/insert-jsx-element.js +1 -0
  29. package/dist/preview-server/routes/install-remotion-skill.d.ts +4 -0
  30. package/dist/preview-server/routes/install-remotion-skill.js +108 -0
  31. package/dist/preview-server/routes/invalidate-bundle.d.ts +3 -0
  32. package/dist/preview-server/routes/invalidate-bundle.js +11 -0
  33. package/dist/preview-server/routes/move-keyframes.js +1 -0
  34. package/dist/preview-server/routes/save-multiple-effect-props.js +1 -0
  35. package/dist/preview-server/routes/save-sequence-props.js +1 -0
  36. package/dist/preview-server/studio-protocol/handle-discovery.js +1 -1
  37. package/dist/preview-server/studio-protocol/handle-element-library.js +1 -1
  38. package/dist/preview-server/studio-protocol/handle-install.js +4 -3
  39. package/dist/preview-server/studio-protocol/handle-license-key.js +1 -1
  40. package/dist/preview-server/studio-protocol/origin-policy.d.ts +1 -1
  41. package/dist/preview-server/studio-protocol/origin-policy.js +13 -6
  42. package/dist/preview-server/undo-stack.d.ts +4 -2
  43. package/dist/preview-server/undo-stack.js +22 -4
  44. package/dist/preview-server/watch-ignore-next-change.d.ts +1 -0
  45. package/dist/preview-server/watch-ignore-next-change.js +20 -12
  46. package/package.json +8 -8
  47. package/dist/preview-server/routes/delete-effect-keyframe.d.ts +0 -3
  48. package/dist/preview-server/routes/delete-effect-keyframe.js +0 -89
  49. package/dist/preview-server/routes/delete-sequence-keyframe.d.ts +0 -3
  50. package/dist/preview-server/routes/delete-sequence-keyframe.js +0 -82
  51. package/dist/preview-server/routes/save-props-mutex.d.ts +0 -1
  52. package/dist/preview-server/routes/save-props-mutex.js +0 -11
@@ -11,4 +11,4 @@ export declare const generateCanvasCaptureComposition: ({ componentName, composi
11
11
  readonly videoHeight: number;
12
12
  readonly videoWidth: number;
13
13
  readonly width: number;
14
- }) => Promise<string>;
14
+ }) => string;
@@ -1,7 +1,40 @@
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
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.generateCanvasCaptureComposition = void 0;
4
- const duplicate_composition_1 = require("../codemods/duplicate-composition");
37
+ const recast = __importStar(require("recast"));
5
38
  const customCursorRegex = /^\s*url\(/;
6
39
  const collapseMouseMovementsByFrame = ({ data, keyframeFps, }) => {
7
40
  const movements = [];
@@ -30,7 +63,39 @@ const getCursorName = (cursor) => {
30
63
  }
31
64
  return ((_a = cursor.split(',').at(-1)) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase()) || 'default';
32
65
  };
33
- const serialize = (value) => JSON.stringify(value);
66
+ const serialize = (value) => {
67
+ if (typeof value === 'string') {
68
+ return recast.prettyPrint(recast.types.builders.stringLiteral(value), {
69
+ quote: 'single',
70
+ }).code;
71
+ }
72
+ return JSON.stringify(value);
73
+ };
74
+ const serializeArray = (values, indentation) => {
75
+ const items = values.map(serialize);
76
+ const inline = `[${items.join(', ')}]`;
77
+ if (indentation * 2 + inline.length + 1 <= 80) {
78
+ return inline;
79
+ }
80
+ const lines = [];
81
+ const numeric = values.every((value) => typeof value === 'number');
82
+ for (const item of items) {
83
+ const previous = lines.at(-1);
84
+ if (numeric &&
85
+ previous &&
86
+ (indentation + 1) * 2 + previous.length + item.length + 2 <= 80) {
87
+ lines[lines.length - 1] = `${previous} ${item},`;
88
+ }
89
+ else {
90
+ lines.push(`${item},`);
91
+ }
92
+ }
93
+ return [
94
+ '[',
95
+ ...lines.map((line) => `${'\t'.repeat(indentation + 1)}${line}`),
96
+ `${'\t'.repeat(indentation)}]`,
97
+ ].join('\n');
98
+ };
34
99
  const generateCanvasCaptureComposition = ({ componentName, compositionId, data, durationInFrames, fps, height, keyframeFps, videoFileName, videoHeight, videoWidth, width, }) => {
35
100
  var _a;
36
101
  const movements = collapseMouseMovementsByFrame({ data, keyframeFps });
@@ -79,11 +144,11 @@ const generateCanvasCaptureComposition = ({ componentName, compositionId, data,
79
144
  }, []);
80
145
  const customCursor = (_a = movements.find((movement) => customCursorRegex.test(movement.cursor))) === null || _a === void 0 ? void 0 : _a.cursor;
81
146
  const cursorProp = cursorKeyframes.length === 1
82
- ? `cursor=${serialize(cursorKeyframes[0].value)}`
147
+ ? `cursor={${serialize(cursorKeyframes[0].value)}}`
83
148
  : `cursor={interpolate(
84
149
  frame,
85
- ${serialize(cursorKeyframes.map((keyframe) => keyframe.frame))},
86
- ${serialize(cursorKeyframes.map((keyframe) => keyframe.value))},
150
+ ${serializeArray(cursorKeyframes.map((keyframe) => keyframe.frame), 5)},
151
+ ${serializeArray(cursorKeyframes.map((keyframe) => keyframe.value), 5)},
87
152
  {
88
153
  easing: Easing.step1,
89
154
  extrapolateLeft: 'clamp',
@@ -94,8 +159,8 @@ const generateCanvasCaptureComposition = ({ componentName, compositionId, data,
94
159
  ? serialize(scaleKeyframes[0].value)
95
160
  : `interpolate(
96
161
  frame,
97
- ${serialize(scaleKeyframes.map((keyframe) => keyframe.frame))},
98
- ${serialize(scaleKeyframes.map((keyframe) => keyframe.value))},
162
+ ${serializeArray(scaleKeyframes.map((keyframe) => keyframe.frame), 6)},
163
+ ${serializeArray(scaleKeyframes.map((keyframe) => keyframe.value), 6)},
99
164
  {
100
165
  easing: Easing.step1,
101
166
  extrapolateLeft: 'clamp',
@@ -106,8 +171,8 @@ const generateCanvasCaptureComposition = ({ componentName, compositionId, data,
106
171
  ? serialize(positionKeyframes[0].value)
107
172
  : `interpolate(
108
173
  frame,
109
- ${serialize(positionKeyframes.map((keyframe) => keyframe.frame))},
110
- ${serialize(positionKeyframes.map((keyframe) => keyframe.value))},
174
+ ${serializeArray(positionKeyframes.map((keyframe) => keyframe.frame), 6)},
175
+ ${serializeArray(positionKeyframes.map((keyframe) => keyframe.value), 6)},
111
176
  {
112
177
  extrapolateLeft: 'clamp',
113
178
  extrapolateRight: 'clamp',
@@ -116,7 +181,7 @@ const generateCanvasCaptureComposition = ({ componentName, compositionId, data,
116
181
  const previewComponentName = componentName.endsWith('Composition')
117
182
  ? `${componentName.slice(0, -'Composition'.length)}Preview`
118
183
  : `${componentName}Preview`;
119
- return (0, duplicate_composition_1.formatOutput)(`import {MacOSCursor} from '@remotion/mac-cursors';
184
+ return `import {MacOSCursor} from '@remotion/mac-cursors';
120
185
  import {Video} from '@remotion/media';
121
186
  import {
122
187
  AbsoluteFill,
@@ -160,7 +225,7 @@ ${customCursor === undefined ? '' : `\t\t\t\tcustomCursor={${serialize(customCur
160
225
  export const ${componentName} = () => {
161
226
  return (
162
227
  <Composition
163
- id=${serialize(compositionId)}
228
+ id={${serialize(compositionId)}}
164
229
  component={${previewComponentName}}
165
230
  width={${width}}
166
231
  height={${height}}
@@ -169,6 +234,6 @@ export const ${componentName} = () => {
169
234
  />
170
235
  );
171
236
  };
172
- `);
237
+ `;
173
238
  };
174
239
  exports.generateCanvasCaptureComposition = generateCanvasCaptureComposition;
@@ -1,26 +1 @@
1
- import type { File, ObjectExpression } from '@babel/types';
2
- import type { SequenceNodePath } from 'remotion';
3
- export declare const assertValidEffect: ({ effectName, effectImportPath, }: {
4
- effectName: string;
5
- effectImportPath: string;
6
- }) => void;
7
- export declare const ensureEffectImport: ({ ast, effectName, effectImportPath, }: {
8
- ast: File;
9
- effectName: string;
10
- effectImportPath: string;
11
- }) => string;
12
- export declare const makeConfigObjectExpression: (config: Record<string, unknown>) => ObjectExpression;
13
- export declare const addEffect: ({ input, sequenceNodePath, effectName, effectImportPath, effectConfig, prettierConfigOverride, }: {
14
- input: string;
15
- sequenceNodePath: SequenceNodePath;
16
- effectName: string;
17
- effectImportPath: string;
18
- effectConfig: Record<string, unknown>;
19
- prettierConfigOverride?: Record<string, unknown> | null | undefined;
20
- }) => Promise<{
21
- output: string;
22
- formatted: boolean;
23
- effectLabel: string;
24
- nodeLabel: string;
25
- logLine: number;
26
- }>;
1
+ export { addEffect, assertValidEffect, ensureEffectImport, makeConfigObjectExpression, } from '@remotion/studio-codemods';
@@ -1,193 +1,8 @@
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.addEffect = exports.makeConfigObjectExpression = exports.ensureEffectImport = exports.assertValidEffect = void 0;
37
- const studio_shared_1 = require("@remotion/studio-shared");
38
- const recast = __importStar(require("recast"));
39
- const imports_1 = require("../helpers/imports");
40
- const can_update_sequence_props_1 = require("../preview-server/routes/can-update-sequence-props");
41
- const format_file_content_1 = require("./format-file-content");
42
- const parse_ast_1 = require("./parse-ast");
43
- const update_effect_props_1 = require("./update-effect-props/update-effect-props");
44
- const b = recast.types.builders;
45
- const identifierRegex = /^[A-Za-z_$][0-9A-Za-z_$]*$/;
46
- const assertValidEffect = ({ effectName, effectImportPath, }) => {
47
- if (!identifierRegex.test(effectName)) {
48
- throw new Error(`Invalid effect name "${effectName}"`);
49
- }
50
- const allowedImport = effectImportPath.startsWith('@remotion/effects/') ||
51
- effectImportPath === '@remotion/light-leaks' ||
52
- effectImportPath === '@remotion/starburst';
53
- if (!allowedImport) {
54
- throw new Error(`Unsupported effect import "${effectImportPath}"`);
55
- }
56
- };
57
- exports.assertValidEffect = assertValidEffect;
58
- const parseValueExpression = (value) => {
59
- const code = `a = ${(0, studio_shared_1.stringifyDefaultProps)({ props: value, enumPaths: [] })}`;
60
- const ast = (0, parse_ast_1.parseAst)(code);
61
- const stmt = ast.program.body[0];
62
- if (stmt.type !== 'ExpressionStatement' ||
63
- stmt.expression.type !== 'AssignmentExpression') {
64
- throw new Error('Failed to parse effect config value');
65
- }
66
- return stmt.expression.right;
67
- };
68
- const declarationBindsName = (declaration, name) => {
69
- var _a, _b;
70
- if (declaration.type === 'ClassDeclaration') {
71
- return ((_a = declaration.id) === null || _a === void 0 ? void 0 : _a.name) === name;
72
- }
73
- if (declaration.type === 'FunctionDeclaration') {
74
- return ((_b = declaration.id) === null || _b === void 0 ? void 0 : _b.name) === name;
75
- }
76
- return declaration.declarations.some((variableDeclaration) => {
77
- return (variableDeclaration.id.type === 'Identifier' &&
78
- variableDeclaration.id.name === name);
79
- });
80
- };
81
- const hasTopLevelBinding = ({ ast, name }) => {
82
- return ast.program.body.some((node) => {
83
- var _a;
84
- if (node.type === 'FunctionDeclaration' ||
85
- node.type === 'ClassDeclaration' ||
86
- node.type === 'VariableDeclaration') {
87
- return declarationBindsName(node, name);
88
- }
89
- if (node.type === 'ExportNamedDeclaration' &&
90
- node.declaration &&
91
- (node.declaration.type === 'FunctionDeclaration' ||
92
- node.declaration.type === 'ClassDeclaration' ||
93
- node.declaration.type === 'VariableDeclaration')) {
94
- return declarationBindsName(node.declaration, name);
95
- }
96
- if (node.type !== 'ImportDeclaration') {
97
- return false;
98
- }
99
- return (_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.some((specifier) => {
100
- var _a;
101
- return ((_a = specifier.local) === null || _a === void 0 ? void 0 : _a.name) === name;
102
- });
103
- });
104
- };
105
- const getAvailableLocalName = ({ ast, effectName, }) => {
106
- if (!hasTopLevelBinding({ ast, name: effectName })) {
107
- return effectName;
108
- }
109
- const base = `${effectName}Effect`;
110
- if (!hasTopLevelBinding({ ast, name: base })) {
111
- return base;
112
- }
113
- for (let i = 2; i < 100; i++) {
114
- const candidate = `${base}${i}`;
115
- if (!hasTopLevelBinding({ ast, name: candidate })) {
116
- return candidate;
117
- }
118
- }
119
- throw new Error(`Cannot find a local name for ${effectName}`);
120
- };
121
- const ensureEffectImport = ({ ast, effectName, effectImportPath, }) => {
122
- const localName = getAvailableLocalName({ ast, effectName });
123
- return (0, imports_1.ensureNamedImport)({
124
- ast,
125
- importedName: effectName,
126
- sourcePath: effectImportPath,
127
- localName,
128
- });
129
- };
130
- exports.ensureEffectImport = ensureEffectImport;
131
- const getEffectsArray = (attr) => {
132
- if (!attr.value || attr.value.type !== 'JSXExpressionContainer') {
133
- throw new Error('Cannot add effect: effects prop is not an array');
134
- }
135
- const expr = attr.value.expression;
136
- if (expr.type !== 'ArrayExpression') {
137
- throw new Error('Cannot add effect: effects prop is not an array');
138
- }
139
- return expr;
140
- };
141
- const makeEffectsAttr = (array) => {
142
- return b.jsxAttribute(b.jsxIdentifier('effects'), b.jsxExpressionContainer(array));
143
- };
144
- const makeConfigObjectExpression = (config) => {
145
- return b.objectExpression(Object.entries(config).map(([key, value]) => {
146
- const keyNode = identifierRegex.test(key)
147
- ? b.identifier(key)
148
- : b.stringLiteral(key);
149
- return b.objectProperty(keyNode, parseValueExpression(value));
150
- }));
151
- };
152
- exports.makeConfigObjectExpression = makeConfigObjectExpression;
153
- const getJsxTagLabel = (name) => {
154
- if (name.type === 'JSXIdentifier') {
155
- return `<${name.name}>`;
156
- }
157
- return 'element';
158
- };
159
- const addEffect = async ({ input, sequenceNodePath, effectName, effectImportPath, effectConfig, prettierConfigOverride, }) => {
160
- var _a;
161
- var _b, _c;
162
- (0, exports.assertValidEffect)({ effectName, effectImportPath });
163
- const ast = (0, parse_ast_1.parseAst)(input);
164
- const jsx = (0, can_update_sequence_props_1.findJsxElementAtNodePath)(ast, sequenceNodePath);
165
- if (!jsx) {
166
- throw new Error('Could not find a JSX element at the specified location to add effect');
167
- }
168
- const localName = (0, exports.ensureEffectImport)({ ast, effectName, effectImportPath });
169
- const effectCall = b.callExpression(b.identifier(localName), [
170
- (0, exports.makeConfigObjectExpression)(effectConfig),
171
- ]);
172
- const attr = (0, update_effect_props_1.findEffectsAttr)((_b = jsx.attributes) !== null && _b !== void 0 ? _b : []);
173
- if (attr) {
174
- getEffectsArray(attr).elements.push(effectCall);
175
- }
176
- else {
177
- const effectsArray = b.arrayExpression([effectCall]);
178
- jsx.attributes.push(makeEffectsAttr(effectsArray));
179
- }
180
- const finalFile = (0, parse_ast_1.serializeAst)(ast);
181
- const { output, formatted } = await (0, format_file_content_1.formatFileContent)({
182
- input: finalFile,
183
- prettierConfigOverride,
184
- });
185
- return {
186
- output,
187
- formatted,
188
- effectLabel: `${effectName}()`,
189
- nodeLabel: getJsxTagLabel(jsx.name),
190
- logLine: (_c = (_a = jsx.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _c !== void 0 ? _c : 1,
191
- };
192
- };
193
- exports.addEffect = addEffect;
3
+ exports.makeConfigObjectExpression = exports.ensureEffectImport = exports.assertValidEffect = exports.addEffect = void 0;
4
+ const studio_codemods_1 = require("@remotion/studio-codemods");
5
+ Object.defineProperty(exports, "addEffect", { enumerable: true, get: function () { return studio_codemods_1.addEffect; } });
6
+ Object.defineProperty(exports, "assertValidEffect", { enumerable: true, get: function () { return studio_codemods_1.assertValidEffect; } });
7
+ Object.defineProperty(exports, "ensureEffectImport", { enumerable: true, get: function () { return studio_codemods_1.ensureEffectImport; } });
8
+ Object.defineProperty(exports, "makeConfigObjectExpression", { enumerable: true, get: function () { return studio_codemods_1.makeConfigObjectExpression; } });
@@ -27,6 +27,13 @@ const applyCodemodToFile = async ({ filePath, codeMod, }) => {
27
27
  codeMod,
28
28
  input,
29
29
  });
30
- return (0, duplicate_composition_1.formatOutput)(newContents);
30
+ if (codeMod.type === 'new-composition' ||
31
+ codeMod.type === 'duplicate-composition' ||
32
+ codeMod.type === 'rename-composition' ||
33
+ codeMod.type === 'delete-composition') {
34
+ return newContents;
35
+ }
36
+ const formatted = await (0, duplicate_composition_1.formatOutput)(newContents);
37
+ return formatted;
31
38
  };
32
39
  exports.applyCodemodToFile = applyCodemodToFile;
@@ -1,30 +1 @@
1
- import type { SequenceNodePath } from 'remotion';
2
- export type EffectDeletionTarget = {
3
- sequenceNodePath: SequenceNodePath;
4
- } & ({
5
- type: 'single-effect';
6
- effectIndex: number;
7
- } | {
8
- type: 'all-effects';
9
- });
10
- export declare const deleteEffects: ({ input, effects, prettierConfigOverride, }: {
11
- input: string;
12
- effects: EffectDeletionTarget[];
13
- prettierConfigOverride?: Record<string, unknown> | null | undefined;
14
- }) => Promise<{
15
- output: string;
16
- formatted: boolean;
17
- effectLabels: string[];
18
- logLines: number[];
19
- }>;
20
- export declare const deleteEffect: ({ input, sequenceNodePath, effectIndex, prettierConfigOverride, }: {
21
- input: string;
22
- sequenceNodePath: SequenceNodePath;
23
- effectIndex: number;
24
- prettierConfigOverride?: Record<string, unknown> | null | undefined;
25
- }) => Promise<{
26
- output: string;
27
- formatted: boolean;
28
- effectLabel: string;
29
- logLine: number;
30
- }>;
1
+ export { deleteEffect, deleteEffects, type EffectDeletionTarget, } from '@remotion/studio-codemods';
@@ -1,128 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deleteEffect = exports.deleteEffects = 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 delete effect: effects prop is not an array');
11
- }
12
- const expr = attr.value.expression;
13
- if (expr.type !== 'ArrayExpression') {
14
- throw new Error('Cannot delete effect: effects prop is not an array');
15
- }
16
- return expr;
17
- };
18
- const getAllEffectLabels = (effectsArray, attr) => {
19
- if (effectsArray.elements.length === 0) {
20
- throw new Error('Cannot delete effect: no effects found');
21
- }
22
- const elements = (0, update_effect_props_1.enumerateEffectArrayElements)(effectsArray);
23
- return {
24
- effectLabels: elements.map((effect) => effect.kind === 'call' ? `${effect.callee}()` : 'effect'),
25
- logLines: elements.map((effect) => {
26
- var _a, _b, _c;
27
- var _d, _e, _f;
28
- return effect.kind === 'call'
29
- ? ((_e = (_d = (_a = effect.node.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _d !== void 0 ? _d : (_b = attr.loc) === null || _b === void 0 ? void 0 : _b.start.line) !== null && _e !== void 0 ? _e : 1)
30
- : ((_f = (_c = attr.loc) === null || _c === void 0 ? void 0 : _c.start.line) !== null && _f !== void 0 ? _f : 1);
31
- }),
32
- };
33
- };
34
- const deleteEffects = async ({ input, effects, prettierConfigOverride, }) => {
35
- var _a, _b;
36
- var _c, _d, _e;
37
- if (effects.length === 0) {
38
- throw new Error('No effects were specified for deletion');
39
- }
40
- const ast = (0, parse_ast_1.parseAst)(input);
41
- const deletionsByAttr = new Map();
42
- for (const effect of effects) {
43
- const { sequenceNodePath } = effect;
44
- const jsx = (0, can_update_sequence_props_1.findJsxElementAtNodePath)(ast, sequenceNodePath);
45
- if (!jsx) {
46
- throw new Error('Could not find a JSX element at the specified location to delete effect');
47
- }
48
- const attr = (0, update_effect_props_1.findEffectsAttr)((_c = jsx.attributes) !== null && _c !== void 0 ? _c : []);
49
- if (!attr) {
50
- throw new Error('Could not find effects on the target JSX element');
51
- }
52
- const effectsArray = getEffectsArray(attr);
53
- const existingDeletion = deletionsByAttr.get(attr);
54
- const deletion = existingDeletion !== null && existingDeletion !== void 0 ? existingDeletion : {
55
- jsxAttributes: jsx.attributes,
56
- attr,
57
- effectsArray,
58
- allEffects: false,
59
- effectIndices: new Set(),
60
- effectLabels: [],
61
- logLines: [],
62
- };
63
- deletionsByAttr.set(attr, deletion);
64
- if (effect.type === 'all-effects') {
65
- const { effectLabels, logLines } = getAllEffectLabels(effectsArray, attr);
66
- deletion.allEffects = true;
67
- deletion.effectIndices.clear();
68
- deletion.effectLabels = effectLabels;
69
- deletion.logLines = logLines;
70
- continue;
71
- }
72
- const { effectIndex } = effect;
73
- if (deletion.allEffects || deletion.effectIndices.has(effectIndex)) {
74
- continue;
75
- }
76
- const found = (0, update_effect_props_1.findEffectCallExpression)({ attr, effectIndex });
77
- if (found.kind === 'error') {
78
- throw new Error(`Cannot delete effect: ${found.reason}`);
79
- }
80
- deletion.effectIndices.add(effectIndex);
81
- deletion.effectLabels.push(`${found.callee}()`);
82
- deletion.logLines.push((_e = (_d = (_a = found.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);
83
- }
84
- for (const deletion of deletionsByAttr.values()) {
85
- if (deletion.allEffects) {
86
- const attrIndex = deletion.jsxAttributes.indexOf(deletion.attr);
87
- if (attrIndex !== -1) {
88
- deletion.jsxAttributes.splice(attrIndex, 1);
89
- }
90
- continue;
91
- }
92
- for (const effectIndex of [...deletion.effectIndices].sort((a, b) => b - a)) {
93
- deletion.effectsArray.elements.splice(effectIndex, 1);
94
- }
95
- if (deletion.effectsArray.elements.length === 0) {
96
- const attrIndex = deletion.jsxAttributes.indexOf(deletion.attr);
97
- if (attrIndex !== -1) {
98
- deletion.jsxAttributes.splice(attrIndex, 1);
99
- }
100
- }
101
- }
102
- const finalFile = (0, parse_ast_1.serializeAst)(ast);
103
- const { output, formatted } = await (0, format_file_content_1.formatFileContent)({
104
- input: finalFile,
105
- prettierConfigOverride,
106
- });
107
- return {
108
- output,
109
- formatted,
110
- effectLabels: [...deletionsByAttr.values()].flatMap((deletion) => deletion.effectLabels),
111
- logLines: [...deletionsByAttr.values()].flatMap((deletion) => deletion.logLines),
112
- };
113
- };
114
- exports.deleteEffects = deleteEffects;
115
- const deleteEffect = async ({ input, sequenceNodePath, effectIndex, prettierConfigOverride, }) => {
116
- const { output, formatted, effectLabels, logLines } = await (0, exports.deleteEffects)({
117
- input,
118
- effects: [{ type: 'single-effect', sequenceNodePath, effectIndex }],
119
- prettierConfigOverride,
120
- });
121
- return {
122
- output,
123
- formatted,
124
- effectLabel: effectLabels[0],
125
- logLine: logLines[0],
126
- };
127
- };
128
- exports.deleteEffect = deleteEffect;
3
+ exports.deleteEffects = exports.deleteEffect = void 0;
4
+ const studio_codemods_1 = require("@remotion/studio-codemods");
5
+ Object.defineProperty(exports, "deleteEffect", { enumerable: true, get: function () { return studio_codemods_1.deleteEffect; } });
6
+ Object.defineProperty(exports, "deleteEffects", { enumerable: true, get: function () { return studio_codemods_1.deleteEffects; } });
@@ -1,26 +1 @@
1
- import type { SequenceNodePath } from 'remotion';
2
- export type EffectDuplicationTarget = {
3
- sequenceNodePath: SequenceNodePath;
4
- effectIndex: number;
5
- };
6
- export declare const duplicateEffects: ({ input, effects, prettierConfigOverride, }: {
7
- input: string;
8
- effects: EffectDuplicationTarget[];
9
- prettierConfigOverride?: Record<string, unknown> | null | undefined;
10
- }) => Promise<{
11
- output: string;
12
- formatted: boolean;
13
- effectLabels: string[];
14
- logLines: number[];
15
- }>;
16
- export declare const duplicateEffect: ({ input, sequenceNodePath, effectIndex, prettierConfigOverride, }: {
17
- input: string;
18
- sequenceNodePath: SequenceNodePath;
19
- effectIndex: number;
20
- prettierConfigOverride?: Record<string, unknown> | null | undefined;
21
- }) => Promise<{
22
- output: string;
23
- formatted: boolean;
24
- effectLabel: string;
25
- logLine: number;
26
- }>;
1
+ export { duplicateEffect, duplicateEffects, type EffectTarget as EffectDuplicationTarget, } from '@remotion/studio-codemods';