@remotion/studio-server 4.0.526 → 4.0.528
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.
- package/dist/codemods/apply-codemod-to-file.d.ts +2 -1
- package/dist/codemods/apply-codemod-to-file.js +142 -8
- package/dist/codemods/{delete-jsx-node.d.ts → delete-jsx-nodes.d.ts} +1 -10
- package/dist/codemods/delete-jsx-nodes.js +10 -0
- package/dist/codemods/paste-effects.d.ts +15 -1
- package/dist/codemods/paste-effects.js +3 -2
- package/dist/codemods/split-jsx-sequence.d.ts +14 -0
- package/dist/codemods/split-jsx-sequence.js +10 -3
- package/dist/codemods/update-effect-props/update-effect-props.d.ts +11 -3
- package/dist/codemods/update-effect-props/update-effect-props.js +17 -10
- package/dist/codemods/update-keyframes/update-keyframes.d.ts +31 -10
- package/dist/codemods/update-keyframes/update-keyframes.js +24 -7
- package/dist/codemods/update-sequence-props/update-sequence-props.d.ts +3 -6
- package/dist/codemods/update-sequence-props/update-sequence-props.js +16 -9
- package/dist/helpers/open-file-for-writing-without-symlinks.d.ts +6 -1
- package/dist/helpers/open-file-for-writing-without-symlinks.js +9 -6
- package/dist/helpers/resolve-composition-component.d.ts +1 -1
- package/dist/helpers/resolve-composition-component.js +5 -4
- package/dist/index.d.ts +0 -19
- package/dist/index.js +0 -6
- package/dist/preview-server/api-routes.js +8 -2
- package/dist/preview-server/hot-middleware/index.js +13 -46
- package/dist/preview-server/routes/add-effect.js +17 -8
- package/dist/preview-server/routes/apply-codemod.d.ts +0 -19
- package/dist/preview-server/routes/apply-codemod.js +24 -26
- package/dist/preview-server/routes/apply-visual-control-change.js +13 -65
- package/dist/preview-server/routes/can-update-default-props.d.ts +1 -1
- package/dist/preview-server/routes/can-update-default-props.js +3 -4
- package/dist/preview-server/routes/can-update-sequence-props.d.ts +0 -10
- package/dist/preview-server/routes/can-update-sequence-props.js +62 -495
- package/dist/preview-server/routes/delete-effect.js +15 -13
- package/dist/preview-server/routes/delete-jsx-nodes.d.ts +3 -0
- package/dist/preview-server/routes/{delete-jsx-node.js → delete-jsx-nodes.js} +23 -12
- package/dist/preview-server/routes/download-remote-asset.d.ts +5 -0
- package/dist/preview-server/routes/download-remote-asset.js +25 -20
- package/dist/preview-server/routes/duplicate-effect.js +12 -4
- package/dist/preview-server/routes/duplicate-jsx-node.js +15 -4
- package/dist/preview-server/routes/element-install-plan.d.ts +1 -1
- package/dist/preview-server/routes/find-in-file.d.ts +9 -1
- package/dist/preview-server/routes/find-in-file.js +3 -4
- package/dist/preview-server/routes/insert-basic-captions.d.ts +3 -0
- package/dist/preview-server/routes/insert-basic-captions.js +119 -0
- package/dist/preview-server/routes/insert-element.js +399 -280
- package/dist/preview-server/routes/install-dependency.js +14 -4
- package/dist/preview-server/routes/prepare-element-install.js +3 -0
- package/dist/preview-server/routes/reorder-effect.js +12 -5
- package/dist/preview-server/routes/reorder-sequence.js +10 -5
- package/dist/preview-server/routes/replace-video-source.d.ts +3 -0
- package/dist/preview-server/routes/replace-video-source.js +81 -0
- package/dist/preview-server/routes/save-sequence-props.js +8 -28
- package/dist/preview-server/routes/split-jsx-sequence.js +82 -42
- package/dist/preview-server/routes/split-video-from-audio.js +9 -4
- package/dist/preview-server/routes/subscribe-to-sequence-props.js +6 -10
- package/dist/preview-server/routes/update-config.js +38 -2
- package/dist/preview-server/routes/update-default-props.js +12 -8
- package/dist/preview-server/routes/wrap-jsx-node.d.ts +3 -0
- package/dist/preview-server/routes/wrap-jsx-node.js +97 -0
- package/dist/preview-server/studio-protocol/handle-discovery.js +1 -1
- package/dist/preview-server/studio-protocol/handle-element-library.js +3 -3
- package/dist/preview-server/undo-stack.d.ts +2 -1
- package/dist/preview-server/undo-stack.js +19 -0
- package/dist/routes.js +2 -0
- package/package.json +8 -8
- package/dist/canvas-capture/generate-canvas-capture-composition.d.ts +0 -14
- package/dist/canvas-capture/generate-canvas-capture-composition.js +0 -239
- package/dist/codemods/add-effect.d.ts +0 -1
- package/dist/codemods/add-effect.js +0 -8
- package/dist/codemods/apply-visual-control.d.ts +0 -8
- package/dist/codemods/apply-visual-control.js +0 -89
- package/dist/codemods/delete-effect.d.ts +0 -1
- package/dist/codemods/delete-effect.js +0 -6
- package/dist/codemods/delete-jsx-node.js +0 -17
- package/dist/codemods/duplicate-composition.d.ts +0 -2
- package/dist/codemods/duplicate-composition.js +0 -64
- package/dist/codemods/duplicate-effect.d.ts +0 -1
- package/dist/codemods/duplicate-effect.js +0 -6
- package/dist/codemods/duplicate-jsx-node.d.ts +0 -25
- package/dist/codemods/duplicate-jsx-node.js +0 -26
- package/dist/codemods/format-file-content.d.ts +0 -7
- package/dist/codemods/format-file-content.js +0 -80
- package/dist/codemods/format-inline-content.d.ts +0 -18
- package/dist/codemods/format-inline-content.js +0 -78
- package/dist/codemods/recast-mods.d.ts +0 -13
- package/dist/codemods/recast-mods.js +0 -902
- package/dist/codemods/reorder-effect.d.ts +0 -1
- package/dist/codemods/reorder-effect.js +0 -5
- package/dist/codemods/reorder-sequence.d.ts +0 -1
- package/dist/codemods/reorder-sequence.js +0 -5
- package/dist/codemods/simple-diff.d.ts +0 -5
- package/dist/codemods/simple-diff.js +0 -39
- package/dist/codemods/split-video-from-audio.d.ts +0 -1
- package/dist/codemods/split-video-from-audio.js +0 -5
- package/dist/codemods/update-default-props.d.ts +0 -1
- package/dist/codemods/update-default-props.js +0 -6
- package/dist/codemods/update-inline-caption-patches.d.ts +0 -1
- package/dist/codemods/update-inline-caption-patches.js +0 -5
- package/dist/codemods/update-keyframes/ensure-imports-and-frame-hook.d.ts +0 -1
- package/dist/codemods/update-keyframes/ensure-imports-and-frame-hook.js +0 -7
- package/dist/preview-server/routes/delete-jsx-node.d.ts +0 -3
- package/dist/preview-server/routes/update-public-license.d.ts +0 -11
- package/dist/preview-server/routes/update-public-license.js +0 -97
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.deleteJsxNodesHandler = void 0;
|
|
4
4
|
const node_fs_1 = require("node:fs");
|
|
5
|
+
const codemods_1 = require("@remotion/codemods");
|
|
5
6
|
const renderer_1 = require("@remotion/renderer");
|
|
6
|
-
const delete_jsx_node_1 = require("../../codemods/delete-jsx-node");
|
|
7
7
|
const file_watcher_1 = require("../../file-watcher");
|
|
8
8
|
const resolve_file_inside_project_1 = require("../../helpers/resolve-file-inside-project");
|
|
9
9
|
const format_log_file_location_1 = require("../format-log-file-location");
|
|
@@ -17,19 +17,19 @@ const getDeletedNodeDescription = (nodeLabels) => {
|
|
|
17
17
|
}
|
|
18
18
|
return `${nodeLabels.length} JSX nodes`;
|
|
19
19
|
};
|
|
20
|
-
const
|
|
20
|
+
const deleteJsxNodesHandler = ({ input: { nodes }, remotionRoot, logLevel }) => {
|
|
21
21
|
return (0, source_file_write_queue_1.withSourceFileWriteQueue)(async () => {
|
|
22
22
|
var _a;
|
|
23
23
|
try {
|
|
24
24
|
(0, hmr_timing_1.logHmrTiming)({
|
|
25
25
|
detail: null,
|
|
26
26
|
logLevel,
|
|
27
|
-
stage: 'delete-jsx-
|
|
27
|
+
stage: 'delete-jsx-nodes-request-start',
|
|
28
28
|
});
|
|
29
29
|
if (nodes.length === 0) {
|
|
30
30
|
throw new Error('No JSX nodes were specified for deletion');
|
|
31
31
|
}
|
|
32
|
-
renderer_1.RenderInternals.Log.trace({ indent: false, logLevel }, `[delete-jsx-
|
|
32
|
+
renderer_1.RenderInternals.Log.trace({ indent: false, logLevel }, `[delete-jsx-nodes] Received request to delete ${nodes.length} JSX node${nodes.length === 1 ? '' : 's'}`);
|
|
33
33
|
const itemsByFileName = new Map();
|
|
34
34
|
for (const item of nodes) {
|
|
35
35
|
const fileItems = (_a = itemsByFileName.get(item.fileName)) !== null && _a !== void 0 ? _a : [];
|
|
@@ -37,16 +37,27 @@ const deleteJsxNodeHandler = ({ input: { nodes }, remotionRoot, logLevel }) => {
|
|
|
37
37
|
itemsByFileName.set(item.fileName, fileItems);
|
|
38
38
|
}
|
|
39
39
|
const updates = await Promise.all([...itemsByFileName.entries()].map(async ([fileName, fileItems]) => {
|
|
40
|
+
var _a;
|
|
41
|
+
var _b;
|
|
40
42
|
const { absolutePath, fileRelativeToRoot } = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
|
|
41
43
|
remotionRoot,
|
|
42
44
|
fileName,
|
|
43
45
|
action: 'modify',
|
|
44
46
|
});
|
|
45
47
|
const fileContents = (0, node_fs_1.readFileSync)(absolutePath, 'utf-8');
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
const result = await (0, codemods_1.deleteJsxNodes)({
|
|
49
|
+
project: {
|
|
50
|
+
files: { [absolutePath]: fileContents },
|
|
51
|
+
rootDir: remotionRoot,
|
|
52
|
+
},
|
|
53
|
+
nodes: fileItems.map((item) => ({
|
|
54
|
+
filePath: absolutePath,
|
|
55
|
+
nodePath: item.nodePath,
|
|
56
|
+
})),
|
|
49
57
|
});
|
|
58
|
+
const output = (_b = (_a = result.changes[0]) === null || _a === void 0 ? void 0 : _a.nextContents) !== null && _b !== void 0 ? _b : fileContents;
|
|
59
|
+
const { nodeLabels, logLines } = result.editDetails[0];
|
|
60
|
+
const nodePathRemappings = result.nodePathRemappings.map(({ oldNodePath, newNodePath }) => ({ oldNodePath, newNodePath }));
|
|
50
61
|
return {
|
|
51
62
|
absolutePath,
|
|
52
63
|
fileRelativeToRoot,
|
|
@@ -60,7 +71,7 @@ const deleteJsxNodeHandler = ({ input: { nodes }, remotionRoot, logLevel }) => {
|
|
|
60
71
|
(0, hmr_timing_1.logHmrTiming)({
|
|
61
72
|
detail: `files=${updates.length}`,
|
|
62
73
|
logLevel,
|
|
63
|
-
stage: 'delete-jsx-
|
|
74
|
+
stage: 'delete-jsx-nodes-codemod-complete',
|
|
64
75
|
});
|
|
65
76
|
const nodePathMutation = (0, sequence_node_path_mutation_1.broadcastSequenceNodePathMutation)(updates.map((update) => ({
|
|
66
77
|
absolutePath: update.absolutePath,
|
|
@@ -79,7 +90,7 @@ const deleteJsxNodeHandler = ({ input: { nodes }, remotionRoot, logLevel }) => {
|
|
|
79
90
|
undoMessage: `↩️ Deletion of ${deletedNodeDescription}`,
|
|
80
91
|
redoMessage: `↪️ Deletion of ${deletedNodeDescription}`,
|
|
81
92
|
},
|
|
82
|
-
entryType: 'delete-jsx-
|
|
93
|
+
entryType: 'delete-jsx-nodes',
|
|
83
94
|
suppressHmrOnFileRestore: false,
|
|
84
95
|
nodePathRemappings: update.nodePathRemappings,
|
|
85
96
|
});
|
|
@@ -106,7 +117,7 @@ const deleteJsxNodeHandler = ({ input: { nodes }, remotionRoot, logLevel }) => {
|
|
|
106
117
|
line: update.logLine,
|
|
107
118
|
});
|
|
108
119
|
renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${(0, source_file_write_queue_1.getCodemodTimingPrefix)(logLevel)}${renderer_1.RenderInternals.chalk.blueBright(`${locationLabel}`)} Deleted ${deletedNodeDescription}`);
|
|
109
|
-
renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, `[delete-jsx-
|
|
120
|
+
renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, `[delete-jsx-nodes] Wrote ${update.fileRelativeToRoot}`);
|
|
110
121
|
}
|
|
111
122
|
(0, undo_stack_1.printUndoHint)(logLevel);
|
|
112
123
|
return {
|
|
@@ -123,4 +134,4 @@ const deleteJsxNodeHandler = ({ input: { nodes }, remotionRoot, logLevel }) => {
|
|
|
123
134
|
}
|
|
124
135
|
});
|
|
125
136
|
};
|
|
126
|
-
exports.
|
|
137
|
+
exports.deleteJsxNodesHandler = deleteJsxNodesHandler;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { getRemoteAssetFilename, type DownloadRemoteAssetRequest, type DownloadRemoteAssetResponse } from '@remotion/studio-shared';
|
|
2
2
|
import type { ApiHandler } from '../api-types';
|
|
3
3
|
export { getRemoteAssetFilename };
|
|
4
|
+
export declare const downloadRemoteAssetBytes: ({ acceptHeader, maxSize, url, }: {
|
|
5
|
+
acceptHeader: string | null;
|
|
6
|
+
maxSize: number;
|
|
7
|
+
url: URL;
|
|
8
|
+
}) => Promise<Uint8Array<ArrayBuffer>>;
|
|
4
9
|
export declare const downloadRemoteAssetHandler: ApiHandler<DownloadRemoteAssetRequest, DownloadRemoteAssetResponse>;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.downloadRemoteAssetHandler = exports.getRemoteAssetFilename = void 0;
|
|
6
|
+
exports.downloadRemoteAssetHandler = exports.downloadRemoteAssetBytes = exports.getRemoteAssetFilename = void 0;
|
|
7
7
|
const promises_1 = require("node:dns/promises");
|
|
8
8
|
const node_fs_1 = require("node:fs");
|
|
9
9
|
const node_net_1 = require("node:net");
|
|
@@ -75,15 +75,13 @@ const ensureRemoteUrlIsAllowed = async (url) => {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
|
-
const fetchRemoteAsset = async ({ signal, url, }) => {
|
|
78
|
+
const fetchRemoteAsset = async ({ acceptHeader, signal, url, }) => {
|
|
79
79
|
var _a;
|
|
80
80
|
let currentUrl = url;
|
|
81
81
|
for (let redirects = 0; redirects <= maxRemoteAssetRedirects; redirects++) {
|
|
82
82
|
await ensureRemoteUrlIsAllowed(currentUrl);
|
|
83
83
|
const response = await fetch(currentUrl, {
|
|
84
|
-
headers: {
|
|
85
|
-
accept: studio_shared_1.remoteAssetAcceptHeader,
|
|
86
|
-
},
|
|
84
|
+
headers: acceptHeader === null ? undefined : { accept: acceptHeader },
|
|
87
85
|
redirect: 'manual',
|
|
88
86
|
signal,
|
|
89
87
|
});
|
|
@@ -102,15 +100,15 @@ const fetchRemoteAsset = async ({ signal, url, }) => {
|
|
|
102
100
|
}
|
|
103
101
|
throw new Error('Remote asset redirected too many times');
|
|
104
102
|
};
|
|
105
|
-
const readRemoteAsset = async ({ response, abort, }) => {
|
|
103
|
+
const readRemoteAsset = async ({ response, abort, maxSize, }) => {
|
|
106
104
|
const contentLength = response.headers.get('content-length');
|
|
107
|
-
if (contentLength !== null && Number(contentLength) >
|
|
105
|
+
if (contentLength !== null && Number(contentLength) > maxSize) {
|
|
108
106
|
abort();
|
|
109
107
|
throw new Error('Remote asset exceeds the 50MB size limit');
|
|
110
108
|
}
|
|
111
109
|
if (!response.body) {
|
|
112
110
|
const buffer = await response.arrayBuffer();
|
|
113
|
-
if (buffer.byteLength >
|
|
111
|
+
if (buffer.byteLength > maxSize) {
|
|
114
112
|
throw new Error('Remote asset exceeds the 50MB size limit');
|
|
115
113
|
}
|
|
116
114
|
return new Uint8Array(buffer);
|
|
@@ -127,7 +125,7 @@ const readRemoteAsset = async ({ response, abort, }) => {
|
|
|
127
125
|
continue;
|
|
128
126
|
}
|
|
129
127
|
size += value.byteLength;
|
|
130
|
-
if (size >
|
|
128
|
+
if (size > maxSize) {
|
|
131
129
|
abort();
|
|
132
130
|
await reader.cancel();
|
|
133
131
|
throw new Error('Remote asset exceeds the 50MB size limit');
|
|
@@ -142,31 +140,25 @@ const readRemoteAsset = async ({ response, abort, }) => {
|
|
|
142
140
|
}
|
|
143
141
|
return result;
|
|
144
142
|
};
|
|
145
|
-
const
|
|
146
|
-
(0, validate_same_origin_1.validateSameOrigin)(request);
|
|
147
|
-
if (typeof input.url !== 'string') {
|
|
148
|
-
throw new Error('No `url` provided');
|
|
149
|
-
}
|
|
143
|
+
const downloadRemoteAssetBytes = async ({ acceptHeader, maxSize, url, }) => {
|
|
150
144
|
if (typeof fetch !== 'function') {
|
|
151
145
|
throw new Error('Downloading remote assets requires Node.js 18 or newer. Drag a local file instead.');
|
|
152
146
|
}
|
|
153
|
-
const url = new URL(input.url);
|
|
154
147
|
const controller = new AbortController();
|
|
155
|
-
const timeout = setTimeout(() =>
|
|
156
|
-
controller.abort();
|
|
157
|
-
}, studio_shared_1.remoteAssetDownloadTimeout);
|
|
158
|
-
let contents;
|
|
148
|
+
const timeout = setTimeout(() => controller.abort(), studio_shared_1.remoteAssetDownloadTimeout);
|
|
159
149
|
try {
|
|
160
150
|
const response = await fetchRemoteAsset({
|
|
151
|
+
acceptHeader,
|
|
161
152
|
signal: controller.signal,
|
|
162
153
|
url,
|
|
163
154
|
});
|
|
164
155
|
if (!response.ok) {
|
|
165
156
|
throw new Error(`Could not download remote asset: ${response.status}`);
|
|
166
157
|
}
|
|
167
|
-
|
|
158
|
+
return await readRemoteAsset({
|
|
168
159
|
response,
|
|
169
160
|
abort: () => controller.abort(),
|
|
161
|
+
maxSize,
|
|
170
162
|
});
|
|
171
163
|
}
|
|
172
164
|
catch (err) {
|
|
@@ -178,6 +170,19 @@ const downloadRemoteAssetHandler = async ({ input, publicDir, request }) => {
|
|
|
178
170
|
finally {
|
|
179
171
|
clearTimeout(timeout);
|
|
180
172
|
}
|
|
173
|
+
};
|
|
174
|
+
exports.downloadRemoteAssetBytes = downloadRemoteAssetBytes;
|
|
175
|
+
const downloadRemoteAssetHandler = async ({ input, publicDir, request }) => {
|
|
176
|
+
(0, validate_same_origin_1.validateSameOrigin)(request);
|
|
177
|
+
if (typeof input.url !== 'string') {
|
|
178
|
+
throw new Error('No `url` provided');
|
|
179
|
+
}
|
|
180
|
+
const url = new URL(input.url);
|
|
181
|
+
const contents = await (0, exports.downloadRemoteAssetBytes)({
|
|
182
|
+
acceptHeader: studio_shared_1.remoteAssetAcceptHeader,
|
|
183
|
+
maxSize: studio_shared_1.maxRemoteAssetSize,
|
|
184
|
+
url,
|
|
185
|
+
});
|
|
181
186
|
const fileType = (0, studio_shared_1.detectFileType)(contents);
|
|
182
187
|
if (!(0, studio_shared_1.isImageFileType)(fileType)) {
|
|
183
188
|
throw new Error('Remote asset is not a supported image');
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.duplicateEffectHandler = void 0;
|
|
4
4
|
const node_fs_1 = require("node:fs");
|
|
5
|
+
const codemods_1 = require("@remotion/codemods");
|
|
5
6
|
const renderer_1 = require("@remotion/renderer");
|
|
6
|
-
const duplicate_effect_1 = require("../../codemods/duplicate-effect");
|
|
7
7
|
const file_watcher_1 = require("../../file-watcher");
|
|
8
8
|
const resolve_file_inside_project_1 = require("../../helpers/resolve-file-inside-project");
|
|
9
9
|
const format_log_file_location_1 = require("../format-log-file-location");
|
|
@@ -32,19 +32,27 @@ const duplicateEffectHandler = ({ input: effects, remotionRoot, logLevel }) => {
|
|
|
32
32
|
itemsByFileName.set(item.fileName, fileItems);
|
|
33
33
|
}
|
|
34
34
|
const updates = await Promise.all([...itemsByFileName.entries()].map(async ([fileName, fileItems]) => {
|
|
35
|
+
var _a;
|
|
36
|
+
var _b;
|
|
35
37
|
const { absolutePath, fileRelativeToRoot } = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
|
|
36
38
|
remotionRoot,
|
|
37
39
|
fileName,
|
|
38
40
|
action: 'modify',
|
|
39
41
|
});
|
|
40
42
|
const fileContents = (0, node_fs_1.readFileSync)(absolutePath, 'utf-8');
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
+
const result = await (0, codemods_1.duplicateEffects)({
|
|
44
|
+
project: {
|
|
45
|
+
files: { [absolutePath]: fileContents },
|
|
46
|
+
rootDir: remotionRoot,
|
|
47
|
+
},
|
|
43
48
|
effects: fileItems.map((item) => ({
|
|
44
|
-
|
|
49
|
+
filePath: absolutePath,
|
|
50
|
+
nodePath: item.sequenceNodePath.nodePath,
|
|
45
51
|
effectIndex: item.effectIndex,
|
|
46
52
|
})),
|
|
47
53
|
});
|
|
54
|
+
const output = (_b = (_a = result.changes[0]) === null || _a === void 0 ? void 0 : _a.nextContents) !== null && _b !== void 0 ? _b : fileContents;
|
|
55
|
+
const { formatted, effectLabels, logLines } = result.editDetails[0];
|
|
48
56
|
return {
|
|
49
57
|
absolutePath,
|
|
50
58
|
fileRelativeToRoot,
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.duplicateJsxNodeHandler = void 0;
|
|
4
4
|
const node_fs_1 = require("node:fs");
|
|
5
|
+
const codemods_1 = require("@remotion/codemods");
|
|
5
6
|
const renderer_1 = require("@remotion/renderer");
|
|
6
|
-
const studio_codemods_1 = require("@remotion/studio-codemods");
|
|
7
7
|
const file_watcher_1 = require("../../file-watcher");
|
|
8
8
|
const resolve_file_inside_project_1 = require("../../helpers/resolve-file-inside-project");
|
|
9
9
|
const format_log_file_location_1 = require("../format-log-file-location");
|
|
@@ -25,16 +25,27 @@ const duplicateJsxNodeHandler = ({ input: { nodes }, remotionRoot, logLevel }) =
|
|
|
25
25
|
itemsByFileName.set(item.fileName, fileItems);
|
|
26
26
|
}
|
|
27
27
|
const updates = await Promise.all([...itemsByFileName.entries()].map(async ([fileName, fileItems]) => {
|
|
28
|
+
var _a;
|
|
29
|
+
var _b;
|
|
28
30
|
const { absolutePath, fileRelativeToRoot } = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
|
|
29
31
|
remotionRoot,
|
|
30
32
|
fileName,
|
|
31
33
|
action: 'modify',
|
|
32
34
|
});
|
|
33
35
|
const fileContents = (0, node_fs_1.readFileSync)(absolutePath, 'utf-8');
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
const result = await (0, codemods_1.duplicateJsxNodes)({
|
|
37
|
+
project: {
|
|
38
|
+
files: { [absolutePath]: fileContents },
|
|
39
|
+
rootDir: remotionRoot,
|
|
40
|
+
},
|
|
41
|
+
nodes: fileItems.map((item) => ({
|
|
42
|
+
filePath: absolutePath,
|
|
43
|
+
nodePath: item.nodePath,
|
|
44
|
+
})),
|
|
37
45
|
});
|
|
46
|
+
const output = (_b = (_a = result.changes[0]) === null || _a === void 0 ? void 0 : _a.nextContents) !== null && _b !== void 0 ? _b : fileContents;
|
|
47
|
+
const { nodeLabels, logLines } = result.editDetails[0];
|
|
48
|
+
const nodePathRemappings = result.nodePathRemappings.map(({ oldNodePath, newNodePath }) => ({ oldNodePath, newNodePath }));
|
|
38
49
|
return {
|
|
39
50
|
absolutePath,
|
|
40
51
|
fileRelativeToRoot,
|
|
@@ -18,7 +18,7 @@ export declare const getElementInstallPlan: ({ destination, element, installatio
|
|
|
18
18
|
expectedFileState: ElementInstallExpectedFileState;
|
|
19
19
|
filePath: string;
|
|
20
20
|
importPath: string;
|
|
21
|
-
location: import("@remotion/
|
|
21
|
+
location: import("@remotion/codemods").ResolvedCompositionComponentWithFile | null;
|
|
22
22
|
safePaths: {
|
|
23
23
|
compositionFileName: string;
|
|
24
24
|
elementFileName: string;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import type { FindInFileRequest, FindInFileResponse } from '@remotion/studio-shared';
|
|
2
2
|
import type { ApiHandler } from '../api-types';
|
|
3
|
-
export
|
|
3
|
+
export declare const findSearchPosition: ({ contents, lineNumber, columnNumber, search, }: {
|
|
4
|
+
contents: string;
|
|
5
|
+
lineNumber: number;
|
|
6
|
+
columnNumber: number;
|
|
7
|
+
search: string;
|
|
8
|
+
}) => {
|
|
9
|
+
lineNumber: number;
|
|
10
|
+
columnNumber: number;
|
|
11
|
+
};
|
|
4
12
|
export declare const findInFileHandler: ApiHandler<FindInFileRequest, FindInFileResponse>;
|
|
@@ -6,13 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.findInFileHandler = exports.findSearchPosition = void 0;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
Object.defineProperty(exports, "findSearchPosition", { enumerable: true, get: function () { return studio_codemods_2.findSearchPosition; } });
|
|
9
|
+
const codemods_1 = require("@remotion/codemods");
|
|
10
|
+
({ findSearchPosition: exports.findSearchPosition } = codemods_1.CodemodsInternals);
|
|
12
11
|
const findInFileHandler = async ({ input, remotionRoot }) => {
|
|
13
12
|
const { fileName, lineNumber, columnNumber, search } = input;
|
|
14
13
|
const contents = await node_fs_1.default.promises.readFile(node_path_1.default.resolve(remotionRoot, fileName), 'utf-8');
|
|
15
|
-
return (0,
|
|
14
|
+
return (0, exports.findSearchPosition)({
|
|
16
15
|
contents,
|
|
17
16
|
lineNumber,
|
|
18
17
|
columnNumber,
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.insertBasicCaptionsHandler = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const codemods_1 = require("@remotion/codemods");
|
|
6
|
+
const renderer_1 = require("@remotion/renderer");
|
|
7
|
+
const file_watcher_1 = require("../../file-watcher");
|
|
8
|
+
const resolve_file_inside_project_1 = require("../../helpers/resolve-file-inside-project");
|
|
9
|
+
const format_log_file_location_1 = require("../format-log-file-location");
|
|
10
|
+
const sequence_node_path_mutation_1 = require("../sequence-node-path-mutation");
|
|
11
|
+
const undo_stack_1 = require("../undo-stack");
|
|
12
|
+
const source_file_write_queue_1 = require("./source-file-write-queue");
|
|
13
|
+
const { basicCaptionsElementSource, getBasicCaptionsElementFile, insertBasicCaptions, } = codemods_1.CodemodsInternals;
|
|
14
|
+
const insertBasicCaptionsHandler = ({ input: { fileName, nodePath, captions, durationInFrames }, remotionRoot, logLevel, }) => (0, source_file_write_queue_1.withSourceFileWriteQueue)(() => {
|
|
15
|
+
var _a;
|
|
16
|
+
try {
|
|
17
|
+
const { absolutePath } = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
|
|
18
|
+
remotionRoot,
|
|
19
|
+
fileName,
|
|
20
|
+
action: 'modify',
|
|
21
|
+
});
|
|
22
|
+
const fileContents = (0, node_fs_1.readFileSync)(absolutePath, 'utf-8');
|
|
23
|
+
const elementFile = getBasicCaptionsElementFile({
|
|
24
|
+
fileName: absolutePath,
|
|
25
|
+
readFileContents: (candidate) => {
|
|
26
|
+
const { absolutePath: elementPath } = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
|
|
27
|
+
remotionRoot,
|
|
28
|
+
fileName: candidate,
|
|
29
|
+
action: 'create',
|
|
30
|
+
});
|
|
31
|
+
let stat;
|
|
32
|
+
try {
|
|
33
|
+
stat = (0, node_fs_1.lstatSync)(elementPath);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error.code === 'ENOENT') {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
if (!stat.isFile()) {
|
|
42
|
+
throw new Error(`Cannot use ${elementPath} for Basic captions`);
|
|
43
|
+
}
|
|
44
|
+
return (0, node_fs_1.readFileSync)(elementPath, 'utf-8');
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
const { output, logLine, nodePathRemappings } = insertBasicCaptions({
|
|
48
|
+
input: fileContents,
|
|
49
|
+
nodePath,
|
|
50
|
+
captions,
|
|
51
|
+
durationInFrames,
|
|
52
|
+
importPath: elementFile.importPath,
|
|
53
|
+
});
|
|
54
|
+
const nodePathMutation = (0, sequence_node_path_mutation_1.broadcastSequenceNodePathMutation)([{ absolutePath, remappings: nodePathRemappings }], null);
|
|
55
|
+
(0, undo_stack_1.pushTransactionToUndoStack)({
|
|
56
|
+
snapshots: [
|
|
57
|
+
...(elementFile.shouldWrite
|
|
58
|
+
? [
|
|
59
|
+
{
|
|
60
|
+
filePath: elementFile.fileName,
|
|
61
|
+
oldContents: null,
|
|
62
|
+
newContents: basicCaptionsElementSource,
|
|
63
|
+
logLine: 1,
|
|
64
|
+
nodePathRemappings: null,
|
|
65
|
+
},
|
|
66
|
+
]
|
|
67
|
+
: []),
|
|
68
|
+
{
|
|
69
|
+
filePath: absolutePath,
|
|
70
|
+
oldContents: fileContents,
|
|
71
|
+
newContents: output,
|
|
72
|
+
logLine,
|
|
73
|
+
nodePathRemappings,
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
logLevel,
|
|
77
|
+
remotionRoot,
|
|
78
|
+
description: {
|
|
79
|
+
undoMessage: '↩️ Insertion of Basic captions',
|
|
80
|
+
redoMessage: '↪️ Insertion of Basic captions',
|
|
81
|
+
},
|
|
82
|
+
entryType: 'insert-basic-captions',
|
|
83
|
+
suppressHmrOnFileRestore: false,
|
|
84
|
+
undoRedoNavigation: null,
|
|
85
|
+
});
|
|
86
|
+
if (elementFile.shouldWrite) {
|
|
87
|
+
(0, undo_stack_1.suppressUndoStackInvalidation)(elementFile.fileName);
|
|
88
|
+
(0, file_watcher_1.writeFileAndNotifyFileWatchers)({
|
|
89
|
+
file: elementFile.fileName,
|
|
90
|
+
content: basicCaptionsElementSource,
|
|
91
|
+
originatorClientId: undefined,
|
|
92
|
+
metadata: null,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
(0, undo_stack_1.suppressUndoStackInvalidation)(absolutePath);
|
|
96
|
+
(0, file_watcher_1.writeFileAndNotifyFileWatchers)({
|
|
97
|
+
file: absolutePath,
|
|
98
|
+
content: output,
|
|
99
|
+
originatorClientId: undefined,
|
|
100
|
+
metadata: { skipSequencePropsUpdate: true },
|
|
101
|
+
});
|
|
102
|
+
const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
|
|
103
|
+
remotionRoot,
|
|
104
|
+
absolutePath,
|
|
105
|
+
line: logLine,
|
|
106
|
+
});
|
|
107
|
+
renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${(0, source_file_write_queue_1.getCodemodTimingPrefix)(logLevel)}${renderer_1.RenderInternals.chalk.blueBright(locationLabel)} Inserted Basic captions`);
|
|
108
|
+
(0, undo_stack_1.printUndoHint)(logLevel);
|
|
109
|
+
return Promise.resolve({ success: true, nodePathMutation });
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
return Promise.resolve({
|
|
113
|
+
success: false,
|
|
114
|
+
reason: error.message,
|
|
115
|
+
stack: (_a = error.stack) !== null && _a !== void 0 ? _a : '',
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
exports.insertBasicCaptionsHandler = insertBasicCaptionsHandler;
|