Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

feat: formalize studio source operations

kashorineb1e42b6f9e2
diff --git a/packages/studio-adapter/src/index.ts b/packages/studio-adapter/src/index.ts
index bb7fcbce..e7a11734 100644
--- a/packages/studio-adapter/src/index.ts
+++ b/packages/studio-adapter/src/index.ts
@@ -55,6 +55,8 @@ export type StudioParameterLanguage = "svml" | "svs" | "svrun";
/** A real source value that an Inspector may display or edit. */
export type StudioParameter = {
readonly id: string;
+ /** Adapter vocabulary name; unlike id this is stable across source files. */
+ readonly name: string;
readonly label: string;
readonly control: StudioParameterControl;
readonly value: string;
@@ -90,11 +92,23 @@ export type StudioEditOperation =
| "duplicate"
| "canvas-transform";
+export type StudioEditCoordinate =
+ | "program-frame"
+ | "source-frame"
+ | "canvas-pixel"
+ | "normalized-progress";
+
+export type StudioSnapTarget = "frame" | "semantic-anchor" | "item-edge";
+
/** A timeline affordance is present only when its source write is explicit. */
export type StudioEditHandle = {
readonly id: string;
readonly operation: StudioEditOperation;
readonly enabled: boolean;
+ /** Coordinate space in which the central gesture resolver measures intent. */
+ readonly coordinate?: StudioEditCoordinate;
+ /** Snap policy is data, not a timeline-wide guess. */
+ readonly snapTo?: readonly StudioSnapTarget[];
readonly sources?: readonly StudioParameter["source"][];
readonly disabledReason?: string;
};
@@ -316,6 +330,8 @@ export type StudioAdapter = {
readonly lane?: StudioLaneDescription;
readonly inspector?: StudioInspectorDescription;
readonly parameters?: readonly StudioParameterDeclaration[];
+ /** Operations this adapter explicitly understands for its entities. */
+ readonly editOperations?: readonly StudioEditOperation[];
readonly project?: (context: StudioAdapterContext) => readonly StudioEntityDraft[];
};
@@ -371,6 +387,7 @@ export type StudioLaneAttachment = {
readonly interaction?: StudioInteraction;
readonly inspector?: StudioInspectorDescription;
readonly parameters?: readonly StudioParameterDeclaration[];
+ readonly editOperations?: readonly StudioEditOperation[];
};
export const readonlyInteraction: StudioInteraction = {
diff --git a/packages/studio-video-adapters/src/generic.ts b/packages/studio-video-adapters/src/generic.ts
index a8f99c72..21e128d9 100644
--- a/packages/studio-video-adapters/src/generic.ts
+++ b/packages/studio-video-adapters/src/generic.ts
@@ -115,6 +115,7 @@ export const genericAdapters: readonly StudioAdapter[] = [
{
id: "text", role: "text", output: { type: "VisualTrack", surface: "track", modules: ["@hypit/typography-track"] },
family: "text", icon: "text", interaction: readonlyInteraction,
+ editOperations: ["move", "trim-start", "trim-end"],
parameters: [
{ name: "placement", label: "Placement", writable: false },
{ name: "during", label: "During", writable: false },
@@ -130,6 +131,7 @@ export const genericAdapters: readonly StudioAdapter[] = [
{
id: "caption", role: "caption", output: { type: "VisualTrack", surface: "track", modules: ["@hypit/caption-fine"] },
family: "caption", icon: "captions", interaction: readonlyInteraction,
+ editOperations: ["move", "trim-start", "trim-end"],
parameters: [
{ name: "during", label: "During", writable: false },
{ name: "start", label: "Start", writable: true },
@@ -146,6 +148,7 @@ export const genericAdapters: readonly StudioAdapter[] = [
id: "component", role: "track",
output: { type: "VisualTrack", modules: ["@hypit/ranking", "@hypit/comment-sticker", "@hypit/screen-overlay"] },
family: "component", icon: "component", interaction: readonlyInteraction,
+ editOperations: ["move", "trim-start", "trim-end"],
parameters: [
{ name: "during", label: "During", writable: false },
{ name: "start", label: "Start", writable: true },
@@ -154,10 +157,43 @@ export const genericAdapters: readonly StudioAdapter[] = [
{ name: "for", label: "For", writable: true },
{ name: "until", label: "Until", writable: false },
{ name: "z", label: "Z", control: "number", writable: true },
+ { name: "frame", label: "Frame", writable: false },
+ { name: "appearance", label: "Appearance", writable: false },
+ { name: "motion", label: "Motion", writable: false },
+ { name: "style", label: "Style", writable: false },
+ { name: "program", label: "Program", writable: false },
+ { name: "source", label: "Source", writable: false },
+ { name: "icon", label: "Icon", writable: false },
+ { name: "label", label: "Label", writable: true },
+ { name: "rank", label: "Rank", control: "number", writable: true },
+ { name: "color", label: "Color", writable: true },
+ { name: "intensity", label: "Intensity", control: "number", writable: true },
+ { name: "opacity", label: "Opacity", control: "number", writable: true },
+ { name: "attack", label: "Attack", control: "number", writable: true, unit: "f" },
+ { name: "hold", label: "Hold", control: "number", writable: true, unit: "f" },
+ { name: "decay", label: "Decay", control: "number", writable: true, unit: "f" },
+ { name: "gain", label: "Gain", control: "number", writable: true },
+ { name: "fade-in", label: "Fade in", control: "number", writable: true, unit: "f" },
+ { name: "fade-out", label: "Fade out", control: "number", writable: true, unit: "f" },
+ { name: "center-x", label: "Center X", control: "number", writable: true },
+ { name: "center-y", label: "Center Y", control: "number", writable: true },
+ { name: "radius-x", label: "Radius X", control: "number", writable: true },
+ { name: "radius-y", label: "Radius Y", control: "number", writable: true },
+ { name: "softness", label: "Softness", control: "number", writable: true },
+ { name: "spacing", label: "Spacing", control: "number", writable: true },
+ { name: "thickness", label: "Thickness", control: "number", writable: true },
+ { name: "angle", label: "Angle", control: "number", writable: true },
+ { name: "direction", label: "Direction", writable: true },
+ { name: "seed", label: "Seed", control: "number", writable: true },
+ { name: "amount", label: "Amount", control: "number", writable: true },
+ { name: "noise-size", label: "Noise size", control: "number", writable: true },
+ { name: "scan-line-opacity", label: "Scan-line opacity", control: "number", writable: true },
+ { name: "motion-rate", label: "Motion rate", control: "number", writable: true },
],
lane: { layout: "flat", height: videoLaneHeights.component },
},
{ id: "audio-track", role: "track", output: { type: "AudioTrack" }, family: "audio", icon: "waveform", interaction: readonlyInteraction,
+ editOperations: ["move", "trim-start", "trim-end"],
parameters: [
{ name: "during", label: "During", writable: false },
{ name: "start", label: "Start", writable: true },
@@ -167,6 +203,7 @@ export const genericAdapters: readonly StudioAdapter[] = [
],
project: projectTerminalAudio, lane: { layout: "flat", height: videoLaneHeights.audio } },
{ id: "visual-track", role: "track", output: { type: "VisualTrack" }, family: "media", icon: "video", interaction: readonlyInteraction,
+ editOperations: ["move", "trim-start", "trim-end"],
parameters: [
{ name: "during", label: "During", writable: false },
{ name: "start", label: "Start", writable: true },
diff --git a/packages/studio-video-adapters/src/media.ts b/packages/studio-video-adapters/src/media.ts
index 64a32d1c..662ecb55 100644
--- a/packages/studio-video-adapters/src/media.ts
+++ b/packages/studio-video-adapters/src/media.ts
@@ -90,12 +90,22 @@ export const mediaAdapters: readonly StudioAdapter[] = [
id: "media-visual", role: "media",
output: { type: "VisualTrack", surface: "track", modules: ["@hypit/media-track"] },
family: "media", icon: "video", interaction: readonlyInteraction,
+ editOperations: ["move", "trim-start", "trim-end"],
parameters: [
{ name: "during", label: "During", writable: false },
{ name: "start", label: "Start", writable: true },
{ name: "end", label: "End", writable: true },
{ name: "at", label: "At", writable: false },
{ name: "for", label: "For", writable: true },
+ { name: "source", label: "Source", writable: false },
+ { name: "source-audio", label: "Source audio", writable: false },
+ { name: "extent", label: "Extent", writable: false },
+ { name: "fit", label: "Fit", writable: false },
+ { name: "sample-spec", label: "Sample spec", writable: false },
+ { name: "item-spec", label: "Item spec", writable: false },
+ { name: "window-spec", label: "Window spec", writable: false },
+ { name: "audio", label: "Audio", writable: true },
+ { name: "gain", label: "Gain", control: "number", writable: true },
{ name: "frame", label: "Frame", writable: false },
{ name: "appearance", label: "Appearance", writable: false },
{ name: "motion", label: "Motion", writable: false },
@@ -108,12 +118,20 @@ export const mediaAdapters: readonly StudioAdapter[] = [
id: "media-audio", role: "media",
output: { type: "AudioTrack", surface: "track", modules: ["@hypit/media-track"] },
family: "media", icon: "waveform", interaction: readonlyInteraction,
+ editOperations: ["move", "trim-start", "trim-end"],
parameters: [
{ name: "during", label: "During", writable: false },
{ name: "start", label: "Start", writable: true },
{ name: "end", label: "End", writable: true },
{ name: "at", label: "At", writable: false },
{ name: "for", label: "For", writable: true },
+ { name: "source", label: "Source", writable: false },
+ { name: "source-audio", label: "Source audio", writable: false },
+ { name: "sample-spec", label: "Sample spec", writable: false },
+ { name: "item-spec", label: "Item spec", writable: false },
+ { name: "window-spec", label: "Window spec", writable: false },
+ { name: "audio", label: "Audio", writable: true },
+ { name: "gain", label: "Gain", control: "number", writable: true },
{ name: "frame", label: "Frame", writable: false },
{ name: "appearance", label: "Appearance", writable: false },
{ name: "motion", label: "Motion", writable: false },
diff --git a/packages/studio-video-adapters/src/ranking.ts b/packages/studio-video-adapters/src/ranking.ts
index 69e2ff56..62d88265 100644
--- a/packages/studio-video-adapters/src/ranking.ts
+++ b/packages/studio-video-adapters/src/ranking.ts
@@ -114,6 +114,7 @@ export const rankingAdapters: readonly StudioAdapter[] = [
id: "ranking-column", role: "track",
output: { type: "VisualTrack", surface: "column", modules: ["@hypit/ranking"] },
family: "component", label: "Ranking", icon: "ranking", realizationPorts: ["schedule"],
+ editOperations: ["move", "trim-start", "trim-end"],
parameters: [
{ name: "style", label: "Style", writable: false },
{ name: "during", label: "During", writable: false },
diff --git a/packages/studio-video-adapters/src/speech.ts b/packages/studio-video-adapters/src/speech.ts
index 4f9c7b61..73bcbec1 100644
--- a/packages/studio-video-adapters/src/speech.ts
+++ b/packages/studio-video-adapters/src/speech.ts
@@ -41,6 +41,9 @@ export const speechAdapters: readonly StudioAdapter[] = [
{ name: "visual-frame", label: "Frame", writable: false },
{ name: "visual-appearance", label: "Appearance", writable: false },
{ name: "visual-z", label: "Z", control: "number", writable: true },
+ { name: "frame", label: "Frame", writable: false },
+ { name: "appearance", label: "Appearance", writable: false },
+ { name: "z", label: "Z", control: "number", writable: true },
],
project: projectSpeechVisual,
lane: { layout: "flat", height: videoLaneHeights.picture },
diff --git a/packages/studio/src/parameters.ts b/packages/studio/src/parameters.ts
index 32e4e171..ab79792d 100644
--- a/packages/studio/src/parameters.ts
+++ b/packages/studio/src/parameters.ts
@@ -118,6 +118,7 @@ function recipeParameters(input: {
: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/u.test(raw) ? "number" as const : "text" as const;
return {
id: `${input.draft.id}:${input.referenceName}:${property.name}`,
+ name: property.name,
label: `${input.referenceName} · ${property.name}`,
control,
value: raw,
@@ -165,6 +166,7 @@ export function parametersForDraft(input: {
const writable = declaration.writable === true && !isReference;
return [{
id: `${input.draft.id}:${name}`,
+ name,
label: declaration.label ?? name,
control: declaration.control ?? "text",
value,
@@ -207,23 +209,60 @@ const ABSOLUTE_DURATION = /^\s*\d+(?:\.\d+)?(?:f|ms|s)\s*$/u;
* source; a Selection/Moment expression cannot be moved from a downstream
* rectangle. `at + for` has one legal edge: changing `for` changes only its end.
*/
-export function timingEditHandles(parameters: readonly StudioParameter[]): readonly StudioEditHandle[] {
- const byName = new Map(parameters.map((parameter) => [parameter.id.slice(parameter.id.lastIndexOf(":") + 1), parameter]));
+export function timingEditHandles(
+ parameters: readonly StudioParameter[],
+ declared: readonly import("@hypit/studio-adapter").StudioEditOperation[] = ["move", "trim-start", "trim-end"],
+): readonly StudioEditHandle[] {
+ const byName = new Map<string, StudioParameter>();
+ for (const parameter of parameters) {
+ // Timing source attributes live in SVML. A nested Recipe may legitimately
+ // also have a property named `start`; it must never shadow the author
+ // window when a clip is being dragged.
+ if (parameter.language === "svml" && !byName.has(parameter.name)) byName.set(parameter.name, parameter);
+ }
const start = byName.get("start");
const end = byName.get("end");
const at = byName.get("at");
const duration = byName.get("for");
const absolute = (parameter: StudioParameter | undefined): parameter is StudioParameter =>
parameter !== undefined && parameter.writable && ABSOLUTE_DURATION.test(parameter.value);
+ const allowed = new Set(declared);
+ const disabled = (id: string, operation: StudioEditHandle["operation"], reason: string): StudioEditHandle => ({
+ id, operation, enabled: false, disabledReason: reason,
+ });
+ const handles: StudioEditHandle[] = [];
if (absolute(start) && absolute(end)) {
- return [
- { id: "move", operation: "move", enabled: true, sources: [start.source, end.source] },
- { id: "trim-start", operation: "trim-start", enabled: true, sources: [start.source] },
- { id: "trim-end", operation: "trim-end", enabled: true, sources: [end.source] },
- ];
- }
- if (at !== undefined && !at.writable && absolute(duration)) {
- return [{ id: "trim-end", operation: "trim-end", enabled: true, sources: [duration.source] }];
+ if (allowed.has("move")) handles.push({
+ id: "move", operation: "move", enabled: true, coordinate: "program-frame",
+ snapTo: ["frame", "semantic-anchor", "item-edge"], sources: [start.source, end.source],
+ });
+ if (allowed.has("trim-start")) handles.push({
+ id: "trim-start", operation: "trim-start", enabled: true, coordinate: "program-frame",
+ snapTo: ["frame", "semantic-anchor", "item-edge"], sources: [start.source],
+ });
+ if (allowed.has("trim-end")) handles.push({
+ id: "trim-end", operation: "trim-end", enabled: true, coordinate: "program-frame",
+ snapTo: ["frame", "semantic-anchor", "item-edge"], sources: [end.source],
+ });
+ } else if (at !== undefined && !at.writable && absolute(duration)) {
+ if (allowed.has("move")) handles.push(disabled("move", "move", "起点由 At 引用决定,不能独立移动。"));
+ if (allowed.has("trim-start")) handles.push(disabled("trim-start", "trim-start", "起点由 At 引用决定,不能独立裁剪。"));
+ if (allowed.has("trim-end")) handles.push({
+ id: "trim-end", operation: "trim-end", enabled: true, coordinate: "program-frame",
+ snapTo: ["frame", "semantic-anchor", "item-edge"], sources: [duration.source],
+ });
+ } else {
+ const reason = parameters.some((parameter) => parameter.name === "during" && !parameter.writable)
+ ? "时间窗由 Selection、Segment、Moment 或 Program 投影提供。请修改来源或投影,不拖动消费结果。"
+ : "没有可逆的绝对时间端点源码范围。";
+ if (allowed.has("move")) handles.push(disabled("move", "move", reason));
+ if (allowed.has("trim-start")) handles.push(disabled("trim-start", "trim-start", reason));
+ if (allowed.has("trim-end")) handles.push(disabled("trim-end", "trim-end", reason));
}
- return [];
+ if (allowed.has("slip")) handles.push(disabled("slip", "slip", "素材内部时间尚未声明为可回写的作者参数。"));
+ if (allowed.has("split")) handles.push(disabled("split", "split", "切分会创建新的作者实体,当前没有唯一的 SVML 写回方案。"));
+ if (allowed.has("delete")) handles.push(disabled("delete", "delete", "删除需要同时处理作者元素与全部引用,当前保持只读。"));
+ if (allowed.has("duplicate")) handles.push(disabled("duplicate", "duplicate", "复制需要生成新的作者身份和引用,当前保持只读。"));
+ if (allowed.has("canvas-transform")) handles.push(disabled("canvas-transform", "canvas-transform", "画布几何由 Frame/Point 作者值控制,当前没有唯一可写范围。"));
+ return handles;
}
diff --git a/packages/studio/src/run.ts b/packages/studio/src/run.ts
index 7102dfe0..31c35c51 100644
--- a/packages/studio/src/run.ts
+++ b/packages/studio/src/run.ts
@@ -25,6 +25,7 @@ export type RunCompilation = {
};
export type RunPlan = {
+ readonly runPath: string;
readonly authorSource: string;
/** The observed Author graph used by this exact Run compilation. */
readonly source: CompiledSource;
@@ -65,6 +66,7 @@ export async function loadStudioRun(input: {
const source = await observedCompiledSource(compiled.author, observer.observations());
const targets = compiled.run.graph.targets.map((target) => target.output);
return {
+ runPath: input.run,
authorSource: compiled.authorSource,
source,
run: compiled.run as RunCompilation,
diff --git a/packages/studio/src/server.ts b/packages/studio/src/server.ts
index 5c1e6093..5c558d2b 100644
--- a/packages/studio/src/server.ts
+++ b/packages/studio/src/server.ts
@@ -45,6 +45,10 @@ function rangeOf(error: unknown): Range | undefined {
: undefined;
}
+function conflict(error: unknown): boolean {
+ return error instanceof Error && /changed outside Studio|Source changed outside Studio/u.test(error.message);
+}
+
export function studioPlugin(options: StudioPluginOptions): Plugin {
let snapshot: StudioSnapshot | undefined;
let failure: StudioFailure | undefined;
@@ -220,7 +224,7 @@ export function studioPlugin(options: StudioPluginOptions): Plugin {
response.statusCode = 202;
response.end();
} catch (error) {
- json(response, 500, { error: error instanceof Error ? error.message : String(error) });
+ json(response, conflict(error) ? 409 : 500, { error: error instanceof Error ? error.message : String(error) });
}
})();
return;
@@ -251,7 +255,7 @@ export function studioPlugin(options: StudioPluginOptions): Plugin {
json(response, 202, { revision: body.revision });
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
- json(response, message.includes("changed outside") ? 409 : 500, { error: message });
+ json(response, conflict(error) ? 409 : 500, { error: message });
}
})();
return;
diff --git a/packages/studio/src/session.ts b/packages/studio/src/session.ts
index 46df98b3..69c96296 100644
--- a/packages/studio/src/session.ts
+++ b/packages/studio/src/session.ts
@@ -1,4 +1,5 @@
import { existsSync, readFileSync } from "node:fs";
+import { relative } from "node:path";
import type { StudioArchive } from "./archive.js";
import type { ServedFile } from "./compile.js";
@@ -76,6 +77,14 @@ export async function readStudioSession(input: {
revision: input.revision,
path: input.sourcePath ?? input.run.authorSource,
text,
+ run: {
+ path: relative(input.workspaceRoot, input.run.runPath),
+ targets: input.run.targets,
+ satisfactions: input.run.run.graph.satisfactions.map((item) => ({
+ output: item.output,
+ candidate: item.candidate,
+ })),
+ },
canvas: built.canvas,
frameRate: built.frameRate,
preview: { kind: "hyperframes", srcdoc: rendered },
diff --git a/packages/studio/src/shared.ts b/packages/studio/src/shared.ts
index 78101eaf..470a5c64 100644
--- a/packages/studio/src/shared.ts
+++ b/packages/studio/src/shared.ts
@@ -173,6 +173,12 @@ export type StudioSnapshot = {
readonly path: string;
readonly text: string;
};
+ /** Visible Run provenance; Studio never invents a second execution source. */
+ readonly run: {
+ readonly path: string;
+ readonly targets: readonly string[];
+ readonly satisfactions: readonly { readonly output: string; readonly candidate: string }[];
+ };
readonly script?: ScriptMap;
readonly space: {
readonly canvasWidth: number;
diff --git a/packages/studio/src/snapshot.ts b/packages/studio/src/snapshot.ts
index e9f2c2bd..94812f42 100644
--- a/packages/studio/src/snapshot.ts
+++ b/packages/studio/src/snapshot.ts
@@ -272,6 +272,7 @@ export function snapshot(registry: StudioAdapterRegistry, built: Preview, input:
readonly revision: number;
readonly path: string;
readonly text: string;
+ readonly run: StudioSnapshot["run"];
readonly canvas: { readonly width: number; readonly height: number; readonly clearColor: string };
readonly frameRate: { readonly numerator: number; readonly denominator: number };
readonly preview: StudioSnapshot["preview"];
@@ -346,7 +347,7 @@ export function snapshot(registry: StudioAdapterRegistry, built: Preview, input:
declarations: registry.parameterDeclarations(item, placement, draft.lane),
placements: built.source.observations.placements,
});
- const editHandles = timingEditHandles(parameters);
+ const editHandles = timingEditHandles(parameters, registry.editOperations(item, placement, draft.lane));
return parameters.length === 0 && editHandles.length === 0
? draft
: { ...draft, parameters, ...(editHandles.length === 0 ? {} : { editHandles }) };
@@ -403,6 +404,7 @@ export function snapshot(registry: StudioAdapterRegistry, built: Preview, input:
return {
revision: input.revision,
source: { path: input.path, text: input.text },
+ run: input.run,
...(script === undefined ? {} : { script }),
space: {
canvasWidth: input.canvas.width,
diff --git a/packages/studio/src/studio-registry.ts b/packages/studio/src/studio-registry.ts
index ac63995f..298bf979 100644
--- a/packages/studio/src/studio-registry.ts
+++ b/packages/studio/src/studio-registry.ts
@@ -2,6 +2,7 @@ import type {
StudioAdapter,
StudioAdapterContext,
StudioEntityDraft,
+ StudioEditOperation,
StudioLaneAttachment,
StudioProjectionRole,
StudioResolvedTrack,
@@ -199,6 +200,18 @@ export class StudioAdapterRegistry {
}
return adapter.parameters ?? [];
}
+
+ editOperations(
+ track: StudioResolvedTrack,
+ placement: Placement | undefined,
+ lane?: string,
+ ): readonly StudioEditOperation[] {
+ const adapter = this.#trackAdapter(track);
+ if (lane !== undefined) {
+ return adapter.attachments?.find((attachment) => attachment.id === lane)?.editOperations ?? [];
+ }
+ return adapter.editOperations ?? [];
+ }
}
export function sealStudioClip(
diff --git a/packages/studio/src/style.css b/packages/studio/src/style.css
index 93fe9272..eab4bc4a 100644
--- a/packages/studio/src/style.css
+++ b/packages/studio/src/style.css
@@ -441,6 +441,20 @@ button:focus-visible, textarea:focus-visible {
.parameter-readonly .parameter-value { border: 0; padding-right: 0; background: transparent; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.parameter-source { grid-column: 1 / -1; min-width: 0; overflow: hidden; color: var(--text-3); font: 9px/1 var(--font-mono); opacity: .7; text-overflow: ellipsis; white-space: nowrap; }
.parameter-right > small { flex: none; color: var(--text-3); font-size: 10px; }
+.operation-group .property-grid { display: flex; flex-direction: column; gap: 2px; }
+.operation-row {
+ min-height: 26px;
+ display: grid;
+ grid-template-columns: minmax(0, 1fr) auto;
+ align-items: center;
+ gap: 10px;
+ padding: 0 2px;
+ border-bottom: 1px solid rgba(255,255,255,.035);
+}
+.operation-row:last-child { border-bottom: 0; }
+.operation-label { color: var(--text-2); font-size: 11px; }
+.operation-state { color: var(--text-3); font-size: 10px; font-weight: 500; }
+.operation-enabled .operation-state { color: var(--text); }
.status.saving { color: var(--text-2); }
.status.saved { color: var(--ok); }
diff --git a/packages/studio/src/ui/main.ts b/packages/studio/src/ui/main.ts
index 94141a88..c18e5200 100644
--- a/packages/studio/src/ui/main.ts
+++ b/packages/studio/src/ui/main.ts
@@ -3,7 +3,7 @@ import { createCodePane } from "./code.js";
import { setIcon } from "./icons.js";
import { createHandle } from "./resize.js";
import type { Highlight } from "./code.js";
-import { intentAtOffset, intentTones, liveRanges, spanAtOffset } from "./markers.js";
+import { intentAtOffset, spanAtOffset } from "./markers.js";
import { clipAtOffset, createStore } from "./selection.js";
import { createStage } from "./stage.js";
import { writeSourceTransaction } from "./writeback.js";
@@ -190,18 +190,47 @@ function parameterGroups(parameters: readonly Clip["parameters"][number][]): rea
type StudioParameterValue = Clip["parameters"][number];
const groups = new Map<string, StudioParameterValue[]>();
for (const parameter of parameters) {
- const key = `${parameter.language}:${parameter.source.path}`;
+ const key = `${parameter.language}\u0000${parameter.source.path}`;
const held = groups.get(key) ?? [];
held.push(parameter);
groups.set(key, held);
}
return [...groups].map(([key, values]) => {
- const [language, ...path] = key.split(":");
- const title = path.length === 0 ? language!.toUpperCase() : `${language!.toUpperCase()} · ${path.join(":")}`;
+ const [language, path = ""] = key.split("\u0000");
+ const title = path.length === 0 ? language!.toUpperCase() : `${language!.toUpperCase()} · ${path}`;
return group(title, values.map(parameterControl), "parameter-group");
});
}
+const operationLabels: Readonly<Record<Clip["editHandles"][number]["operation"], string>> = {
+ move: "Move",
+ "trim-start": "Trim start",
+ "trim-end": "Trim end",
+ slip: "Slip",
+ split: "Split",
+ delete: "Delete",
+ duplicate: "Duplicate",
+ "canvas-transform": "Canvas transform",
+};
+
+function operationGroups(handles: readonly Clip["editHandles"][number][]): readonly HTMLElement[] {
+ if (handles.length === 0) return [];
+ return [group("Timeline operations", handles.map((handle) => {
+ const node = document.createElement("div");
+ node.className = `operation-row${handle.enabled ? " operation-enabled" : " operation-disabled"}`;
+ const label = document.createElement("span");
+ label.className = "operation-label";
+ label.textContent = operationLabels[handle.operation];
+ const state = document.createElement("strong");
+ state.className = "operation-state";
+ state.textContent = handle.enabled ? "Timeline" : "—";
+ node.title = handle.disabledReason
+ ?? (handle.enabled ? "按时间线把手操作,成功后会回写源文件。" : "当前实体没有可逆的 Studio 写回。" );
+ node.append(label, state);
+ return node;
+ }), "operation-group")];
+}
+
let parameterWriteState: "" | "Saving" | "Saved" | "Failed" = "";
async function writeParameter(parameter: Clip["parameters"][number], replacement: string): Promise<void> {
const state = store.current();
@@ -274,15 +303,19 @@ function renderInspector(snapshot: StudioSnapshot, clipId: string | undefined):
]),
]);
const run = track === undefined ? undefined : group("Run", [
+ property("Run", snapshot.run.path, "property-wide property-code"),
+ property("Target", snapshot.run.targets.join(", "), "property-wide property-code"),
property("Output", track.provenance.output, "property-wide property-code"),
...(track.provenance.candidateId === undefined ? [] : [
property("Candidate", track.provenance.candidateId, "property-wide property-code"),
]),
property("Status", track.provenance.status),
- property("Writeback", "Read-only"),
+ property("Writeback", "Run source · read-only"),
]);
+ const operations = operationGroups(clip.editHandles);
const parameters = parameterGroups(clip.parameters);
- inspector.replaceChildren(hero, placement, timing, ...parameters, ...(source === undefined ? [] : [source]), ...(run === undefined ? [] : [run]));
+ inspector.replaceChildren(hero, placement, timing, ...operations, ...parameters,
+ ...(source === undefined ? [] : [source]), ...(run === undefined ? [] : [run]));
}
function renderSemanticInspector(snapshot: StudioSnapshot, segmentId: string): void {
@@ -393,17 +426,10 @@ store.subscribe(({ snapshot, selection, playhead }) => {
else renderInspector(snapshot, chosen?.id);
}
- // Every Selection the playhead is inside is outlined, not only what was
- // clicked, and not only what has a clip. A Selection inside another Selection
- // is still inside it, so the enclosing pair stays outlined while the inner one
- // is — that nesting is the whole point of the authored intents.
- const tones = intentTones(snapshot);
- const live = store.clipsAt(playhead.frame);
- const highlights: Highlight[] = liveRanges(snapshot, playhead.frame).map((selection) => ({
- range: selection.range,
- tone: "binding" as const,
- depth: tones.get(selection.id) ?? 0,
- }));
+ // Source outlines are selection affordances, not a second always-on syntax
+ // layer. Keeping every live Selection outlined made the code pane fill with
+ // yellow polygons while the author was merely playing the film.
+ const highlights: Highlight[] = [];
// The element that placed what is on screen is outlined too. Knowing a cutaway
// is running is half the answer; the other half is which line put it there.
// Only what was chosen is outlined. What is merely drawn at this frame is
@@ -538,6 +564,16 @@ function applyFailure(failure: StudioFailure): void {
status.textContent = "Compile failed";
failureView.textContent = failure.error;
if (failure.range !== undefined) code.highlight([{ range: failure.range, tone: "element" }], true);
+ // A parameter control changes immediately in the browser, but the source
+ // remains the only truth. If recompilation rejects the transaction, rebuild
+ // the Inspector from the last accepted snapshot instead of leaving a false
+ // value visible in the field.
+ const current = store.current();
+ if (current === undefined) return;
+ if (current.selection.kind === "clip") renderInspector(current.snapshot, current.selection.clipId);
+ else if (current.selection.kind === "semantic-segment") renderSemanticInspector(current.snapshot, current.selection.segmentId);
+ else if (current.selection.kind === "semantic-selection") renderSemanticSelectionInspector(current.snapshot, current.selection.selectionId);
+ else if (current.selection.kind === "semantic-moment") renderSemanticMomentInspector(current.snapshot, current.selection.momentId);
}
const response = await fetch("/__studio/session");