Files
openmotion/packages/edit-core/project-inputs.ts
open-design-crew[bot] 8ef74470c5 Keep Studio edits responsive through one ordered local working copy (#1041)
* Prepare versioned project edits locally and skip recursive preview mounts

* Preserve validation details on locally prepared composition drops

* Prepare Studio edits from one ordered local working copy

* Chain editable media references to their preceding Studio writes

---------

Co-authored-by: lefarcen <935902669@qq.com>
2026-11-25 10:24:21 +08:00

31 lines
1.5 KiB
TypeScript

import { locateEdit, type EditRequest } from './commands.ts';
import { contentDependencies, isContentCommand } from './content-schema.ts';
import { hasRelativeLutSource } from './color-grading.ts';
export type EditInputKind = 'text' | 'optional-text' | 'asset';
/** The inputs a caller must observe to run this command, including direct read-only dependencies. */
export function projectEditInputs(edit: EditRequest) {
const commands = (edit.kind === 'batch' ? edit.commands : [edit]).map(locateEdit);
const targets = new Set<string>();
const requested = new Map<string, EditInputKind>();
function requireInput(path: string, kind: EditInputKind) {
const previous = requested.get(path);
requested.set(path, previous && previous !== kind ? 'text' : kind);
}
for (const command of commands) {
const path = command.compositionPath;
if (command.kind !== 'setBeatGrid' && !/\.html?$/i.test(path)) throw new Error('A composition must be an HTML file');
targets.add(path);
requireInput(path, command.kind === 'setBeatGrid' ? 'optional-text' : 'text');
if (command.kind === 'setBeatGrid') requireInput(command.assetPath, 'asset');
if (isContentCommand(command)) {
for (const input of contentDependencies(command)) requireInput(input.path, input.type);
}
}
if (targets.size > 1 && commands.some(command => command.kind === 'gradeMedia' && hasRelativeLutSource(command.value))) {
throw new Error('Use an absolute LUT source when grading multiple compositions');
}
return { commands, targets, requested };
}