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.
TypeScript agentic-aiaiai-agentsai-videocompilerdslffmpeggenerative-aillmmarkup-languagemonorepoplugin-systemprogramming-languagetext-to-videotypescriptvideovideo-automationvideo-clonevideo-editingvideo-generation
feat(studio): establish traceable semantic timeline UI
kashorinc4eee0cbf6d5
diff --git a/packages/ranking/preview/Column.svg b/packages/ranking/preview/Column.svgnew file mode 100644index 00000000..c98620d4--- /dev/null+++ b/packages/ranking/preview/Column.svg@@ -0,0 +1,29 @@+<svg xmlns="http://www.w3.org/2000/svg" width="274" height="392" viewBox="0 0 274 392" fill="none">+ <!-- A lightweight SVG approximation of three settled Column rows.+ Geometry follows the real Column recipe: 112px cells, 18px column gap,+ 12px row gap, 16px outer padding, 8px rank radius and 18px icon radius. -->+ <g transform="translate(16 16)">+ <rect width="112" height="112" rx="8" fill="#FF3F56"/>+ <path d="M125 0L125 618L226 522L5 522L5 700L361 700L361 0Z" fill="#FFFFFF" transform="translate(44.714 74.9) scale(.054 -.054)"/>+ <rect x="130" width="112" height="112" rx="18" fill="#5B65C9"/>+ <circle cx="186" cy="56" r="27" fill="none" stroke="#FFFFFF" stroke-width="10"/>+ <circle cx="186" cy="56" r="7" fill="#FFFFFF"/>+ <circle cx="215" cy="28" r="7" fill="#FFFFFF"/>+ </g>++ <g transform="translate(16 140)">+ <rect width="112" height="112" rx="8" fill="#FFA72D"/>+ <path d="M28 0L28 145L281 379Q305 402 316.5 419Q328 436 332 449.5Q336 463 336 475Q336 501 319 515.5Q302 530 268 530Q237 530 209 513.5Q181 497 165 465L-13 554Q25 626 101 671Q177 716 290 716Q373 716 437 689Q501 662 537 613Q573 564 573 497Q573 463 564.5 429Q556 395 530 357.5Q504 320 453 274L263 101L226 183L589 183L589 0Z" fill="#FFFFFF" transform="translate(39.584 75.332) scale(.054 -.054)"/>+ <rect x="130" width="112" height="112" rx="18" fill="#279CA8"/>+ <path d="M160 36h52v12h-52zM160 53h38v12h-38zM160 70h52v12h-52z" fill="#FFFFFF"/>+ <path d="m202 53 17 6-17 6V53Z" fill="#FFFFFF"/>+ </g>++ <g transform="translate(16 264)">+ <rect width="112" height="112" rx="8" fill="#EADC2A"/>+ <path d="M270 -16Q198 -16 124 0Q50 16 -6 47L74 221Q119 195 168.5 182.5Q218 170 262 170Q302 170 327.5 183.5Q353 197 353 224Q353 247 334 259.5Q315 272 270 272L177 272L177 417L358 601L379 522L30 522L30 700L552 700L552 555L371 371L258 435L320 435Q452 435 521 376Q590 317 590 224Q590 164 556.5 109Q523 54 452.5 19Q382 -16 270 -16Z" fill="#FFFFFF" transform="translate(39.422 74.9) scale(.054 -.054)"/>+ <rect x="130" width="112" height="112" rx="18" fill="#C96254"/>+ <circle cx="174" cy="56" r="22" fill="none" stroke="#FFFFFF" stroke-width="10"/>+ <circle cx="202" cy="56" r="22" fill="none" stroke="#FFFFFF" stroke-width="10"/>+ </g>+</svg>diff --git a/packages/ranking/src/manifest.ts b/packages/ranking/src/manifest.tsindex f45da6a4..42f1d564 100644--- a/packages/ranking/src/manifest.ts+++ b/packages/ranking/src/manifest.ts@@ -11,8 +11,8 @@ import { svsRecipeType } from "@hypit/svs";import { temporalDependency } from "@hypit/temporal";import { textDependency, textTypes } from "@hypit/text";-const previewImage = (file: string) => ({- mediaType: "image/png",+const previewImage = (file: string, mediaType = "image/png") => ({+ mediaType,path: `preview/${file}`,open: async () => Uint8Array.from(await readFile(new URL(`../preview/${file}`, import.meta.url))),});@@ -487,7 +487,7 @@ export const rankingMarkupSurfaces = [summary: "Places rows by explicit rank, reveals each non-preset row in its own Selection, and publishes the board and the Tracks it renders to.",appearance:"A narrow vertical rank rail occupies its Frame while a large reveal stage is positioned independently in Canvas space. Preset rows are settled from the first frame. Each other row rises into the stage during its own projected Selection, then shrinks and moves into the content slot beside its numbered rank. Rank, child order and reveal time are independent.",- preview: previewImage("Column.png"),+ preview: previewImage("Column.svg", "image/svg+xml"),attributes: [{ name: "id", kind: "identifier", required: true,summary: "Names this board so its Schedule, Program and Tracks can be referenced elsewhere in the Source." },diff --git a/packages/studio/src/adapters/audio.ts b/packages/studio/src/adapters/audio.tsindex f5af302d..5acf9167 100644--- a/packages/studio/src/adapters/audio.ts+++ b/packages/studio/src/adapters/audio.ts@@ -1,17 +1,26 @@import type { StudioAdapter, StudioAdapterContext, StudioEntityDraft } from "./types.js";-import { childEntities, readonlyInteraction, sameSurfaceValue } from "./types.js";+import { childEntities, laneHeights, readonlyInteraction, sameSurfaceValue } from "./types.js";type AudioTrackProgramValue = {- readonly items?: readonly { readonly id: string; readonly window: { readonly startFrame: number; readonly endFrameExclusive: number } }[];+ readonly items?: readonly {+ readonly id: string;+ readonly window: { readonly startFrame: number; readonly endFrameExclusive: number };+ readonly source: { readonly artifact: { readonly digest: string } };+ }[];};function projectAudio(context: StudioAdapterContext): readonly StudioEntityDraft[] {const program = sameSurfaceValue(context, "program") as AudioTrackProgramValue | undefined;if (program?.items === undefined) return context.generic();- return childEntities(context, program.items.map((item) => ({+ const items = program.items.map((item) => ({id: item.id, startFrame: item.window.startFrame, endFrameExclusive: item.window.endFrameExclusive,stackOrder: Number.MIN_SAFE_INTEGER,- })), "audio-clip", "waveform");+ preview: { kind: "audio" as const, url: `/__studio/material/${item.source.artifact.digest}` },+ }));+ return childEntities(context, items, "audio-clip", "waveform").map((entity, index) => ({+ ...entity,+ preview: items[index]!.preview,+ }));}export const audioAdapters: readonly StudioAdapter[] = [@@ -20,5 +29,6 @@ export const audioAdapters: readonly StudioAdapter[] = [id: "audio", role: "track", output: { type: "AudioTrack", surface: "track", modules: ["@hypit/audio-track"] },family: "audio", icon: "waveform", interaction: readonlyInteraction,realizationPorts: ["program"], project: projectAudio,+ lane: { layout: "flat", height: laneHeights.audio },},];diff --git a/packages/studio/src/adapters/deck.ts b/packages/studio/src/adapters/deck.tsindex 100cd937..a1b02a2d 100644--- a/packages/studio/src/adapters/deck.ts+++ b/packages/studio/src/adapters/deck.ts@@ -1,5 +1,5 @@import type { StudioAdapter, StudioAdapterContext, StudioEntityDraft } from "./types.js";-import { readonlyInteraction, sameSurfaceValue } from "./types.js";+import { laneHeights, readonlyInteraction, sameSurfaceValue } from "./types.js";type DepthStackProgram = {readonly terminalFrame: number;@@ -53,5 +53,6 @@ export const deckAdapters: readonly StudioAdapter[] = [output: { type: "VisualTrack", surface: "track", modules: ["@hypit/deck-track"] },family: "component", icon: "layers", realizationPorts: ["program"],interaction: readonlyInteraction, project: projectDeck,+ lane: { layout: "flat", height: laneHeights.component },},];diff --git a/packages/studio/src/adapters/generic.ts b/packages/studio/src/adapters/generic.tsindex dceae13e..40c17965 100644--- a/packages/studio/src/adapters/generic.ts+++ b/packages/studio/src/adapters/generic.ts@@ -1,5 +1,5 @@import type { StudioAdapter, StudioAdapterContext, StudioEntityDraft } from "./types.js";-import { childEntities, readonlyInteraction, sameSurfaceValue } from "./types.js";+import { childEntities, laneHeights, readonlyInteraction, sameSurfaceValue } from "./types.js";import { itemTemporalLineage } from "./temporal.js";type TypographyTrackProgram = {@@ -35,6 +35,60 @@ type CaptionDisplayValue = {readonly words?: readonly { readonly id: string; readonly text: string }[];};+type TerminalVisualTrack = {+ readonly presents?: readonly {+ readonly id: string;+ readonly elements?: readonly {+ readonly kind?: string;+ readonly artifact?: { readonly digest?: string };+ }[];+ }[];+};++type TerminalAudioTrack = {+ readonly clips?: readonly {+ readonly id: string;+ readonly artifact?: { readonly digest?: string };+ }[];+};++/** Terminal media has one Studio treatment regardless of which package authored it. */+function projectTerminalVisual(context: StudioAdapterContext): readonly StudioEntityDraft[] {+ const presents = new Map(((context.track.track as TerminalVisualTrack).presents ?? [])+ .map((present) => [present.id, present] as const));+ return context.generic().map((entity) => {+ const present = entity.presentId === undefined ? undefined : presents.get(entity.presentId);+ const material = present?.elements?.find((element) =>+ (element.kind === "image" || element.kind === "video") && element.artifact?.digest !== undefined);+ const digest = material?.artifact?.digest;+ return {+ ...entity,+ presentation: { entity: "media-item", shape: "picture", depth: 0 },+ ...(digest === undefined ? {} : {+ preview: {+ kind: material?.kind === "image" ? "image" as const : "video" as const,+ url: `/__studio/material/${digest}`,+ },+ }),+ };+ });+}++function projectTerminalAudio(context: StudioAdapterContext): readonly StudioEntityDraft[] {+ const clips = new Map(((context.track.track as TerminalAudioTrack).clips ?? [])+ .map((clip) => [clip.id, clip] as const));+ return context.generic().map((entity, index) => {+ const digest = clips.get(context.spans[index]?.id ?? "")?.artifact?.digest;+ return {+ ...entity,+ presentation: { entity: "audio-clip", shape: "waveform", depth: 0 },+ ...(digest === undefined ? {} : {+ preview: { kind: "audio" as const, url: `/__studio/material/${digest}` },+ }),+ };+ });+}+function projectText(context: StudioAdapterContext): readonly StudioEntityDraft[] {const program = sameSurfaceValue(context, "program") as TypographyTrackProgram | undefined;if (program?.items === undefined) return context.generic();@@ -96,17 +150,22 @@ export const genericAdapters: readonly StudioAdapter[] = [id: "text", role: "text", output: { type: "VisualTrack", surface: "track", modules: ["@hypit/typography-track"] },family: "text", icon: "text", interaction: readonlyInteraction,realizationPorts: ["program"], project: projectText,+ lane: { layout: "flat", height: laneHeights.text },},{id: "caption", role: "caption", output: { type: "VisualTrack", surface: "track", modules: ["@hypit/caption-fine"] },family: "caption", icon: "captions", interaction: readonlyInteraction,dependencies: [{ type: "CaptionPlan", role: "caption-plan" }], project: projectCaption,+ lane: { layout: "flat", height: laneHeights.text },},{id: "component", role: "track",output: { type: "VisualTrack", modules: ["@hypit/ranking", "@hypit/comment-sticker", "@hypit/screen-overlay"] },family: "component", icon: "component", interaction: readonlyInteraction,+ lane: { layout: "flat", height: laneHeights.component },},- { id: "audio-fallback", role: "track", output: { type: "AudioTrack" }, family: "audio", icon: "waveform", interaction: readonlyInteraction },- { id: "visual-fallback", role: "track", output: { type: "VisualTrack" }, family: "visual", icon: "layers", interaction: readonlyInteraction },+ { id: "audio-track", role: "track", output: { type: "AudioTrack" }, family: "audio", icon: "waveform", interaction: readonlyInteraction,+ project: projectTerminalAudio, lane: { layout: "flat", height: laneHeights.audio } },+ { id: "visual-track", role: "track", output: { type: "VisualTrack" }, family: "media", icon: "video", interaction: readonlyInteraction,+ project: projectTerminalVisual, lane: { layout: "flat", height: laneHeights.picture } },];diff --git a/packages/studio/src/adapters/media.ts b/packages/studio/src/adapters/media.tsindex 8f63ff01..546adf72 100644--- a/packages/studio/src/adapters/media.ts+++ b/packages/studio/src/adapters/media.ts@@ -1,5 +1,5 @@import type { StudioAdapter, StudioAdapterContext, StudioEntityDraft } from "./types.js";-import { childEntities, readonlyInteraction, sameSurfaceValue } from "./types.js";+import { childEntities, laneHeights, readonlyInteraction, sameSurfaceValue } from "./types.js";import { itemTemporalLineage } from "./temporal.js";type MediaTrackProgramValue = {@@ -8,43 +8,63 @@ type MediaTrackProgramValue = {readonly span: { readonly startFrame: number; readonly endFrameExclusive: number };readonly stacking: { readonly order: number };readonly layers?: readonly MediaLayerValue[];+ readonly sourceAudio?: { readonly fromLayer: string };}[];readonly sequences?: readonly {readonly id: string;readonly span: { readonly startFrame: number; readonly endFrameExclusive: number };readonly stacking: { readonly order: number };- readonly members?: readonly { readonly layers?: readonly MediaLayerValue[] }[];+ readonly members?: readonly {+ readonly layers?: readonly MediaLayerValue[];+ readonly sourceAudio?: { readonly fromLayer: string };+ }[];}[];};type MediaLayerValue = {+ readonly id?: string;readonly kind?: string;readonly source?: {readonly kind?: string;readonly artifact?: { readonly digest?: string; readonly mediaType?: string };+ readonly audio?: { readonly artifact?: { readonly digest?: string; readonly mediaType?: string } };};};-function imagePreview(layers: readonly MediaLayerValue[] | undefined): StudioEntityDraft["preview"] {- const source = layers?.find((layer) => layer.kind === "sample")?.source;- const artifact = source?.artifact;- if (source?.kind !== "still" || artifact?.digest === undefined || artifact.mediaType?.startsWith("image/") !== true) {- return undefined;+function materialPreview(+ layers: readonly MediaLayerValue[] | undefined,+ facet: "visual" | "audio",+ audioFromLayer?: string,+): StudioEntityDraft["preview"] {+ const layer = layers?.find((candidate) => candidate.kind === "sample"+ && (facet === "visual" || audioFromLayer === undefined || candidate.id === audioFromLayer));+ const source = layer?.source;+ if (facet === "audio") {+ const artifact = source?.audio?.artifact;+ return artifact?.digest === undefined+ ? undefined+ : { kind: "audio", url: `/__studio/material/${artifact.digest}` };}- return { kind: "image", url: `/__studio/material/${artifact.digest}` };+ const artifact = source?.artifact;+ if (artifact?.digest === undefined) return undefined;+ if (source?.kind === "still") return { kind: "image", url: `/__studio/material/${artifact.digest}` };+ if (source?.kind === "timed") return { kind: "video", url: `/__studio/material/${artifact.digest}` };+ return undefined;}function projectMedia(context: StudioAdapterContext): readonly StudioEntityDraft[] {const program = sameSurfaceValue(context, "program") as MediaTrackProgramValue | undefined;if (program === undefined) return context.generic();+ const facet = context.track.type === "AudioTrack" ? "audio" : "visual";const items = [...(program.items ?? []).map((item) => ({id: item.id, startFrame: item.span.startFrame, endFrameExclusive: item.span.endFrameExclusive,- stackOrder: item.stacking.order, preview: imagePreview(item.layers),+ stackOrder: item.stacking.order, preview: materialPreview(item.layers, facet, item.sourceAudio?.fromLayer),})),...(program.sequences ?? []).map((item) => ({id: item.id, startFrame: item.span.startFrame, endFrameExclusive: item.span.endFrameExclusive,- stackOrder: item.stacking.order, preview: imagePreview(item.members?.[0]?.layers),+ stackOrder: item.stacking.order,+ preview: materialPreview(item.members?.[0]?.layers, facet, item.members?.[0]?.sourceAudio?.fromLayer),})),];return childEntities(context, items, "media-item",@@ -57,7 +77,7 @@ function projectMedia(context: StudioAdapterContext): readonly StudioEntityDraft});return {...entity,- ...(item.preview === undefined || context.track.type === "AudioTrack" ? {} : { preview: item.preview }),+ ...(item.preview === undefined ? {} : { preview: item.preview }),...(temporal === undefined ? {} : { temporal }),};});@@ -70,11 +90,13 @@ export const mediaAdapters: readonly StudioAdapter[] = [output: { type: "VisualTrack", surface: "track", modules: ["@hypit/media-track"] },family: "media", icon: "video", interaction: readonlyInteraction,realizationPorts: ["program"], project: projectMedia,+ lane: { layout: "flat", height: laneHeights.picture },},{id: "media-audio", role: "media",output: { type: "AudioTrack", surface: "track", modules: ["@hypit/media-track"] },family: "media", icon: "waveform", interaction: readonlyInteraction,realizationPorts: ["program"], project: projectMedia,+ lane: { layout: "flat", height: laneHeights.audio },},];diff --git a/packages/studio/src/adapters/ranking.ts b/packages/studio/src/adapters/ranking.tsindex 1121fab2..1ef2dfe7 100644--- a/packages/studio/src/adapters/ranking.ts+++ b/packages/studio/src/adapters/ranking.ts@@ -15,6 +15,31 @@ type RankingSchedule = {type Span = { readonly startFrame: number; readonly endFrameExclusive: number };+type RankingVisualElement = {+ readonly kind?: string;+ readonly artifact?: { readonly digest?: string; readonly mediaType?: string };+};++type RankingVisualTrack = {+ readonly presents?: readonly {+ readonly id: string;+ readonly elements?: readonly RankingVisualElement[];+ }[];+};++function itemPreview(+ context: StudioAdapterContext,+ itemId: string,+): StudioEntityDraft["preview"] | undefined {+ const track = context.track.track as RankingVisualTrack;+ const present = track.presents?.find((candidate) => candidate.id.includes(`:item:${itemId}:`));+ const artifact = present?.elements?.find((element) => element.kind === "image")?.artifact;+ if (artifact?.digest === undefined) return undefined;+ return artifact.mediaType?.startsWith("video/") === true+ ? { kind: "video", url: `/__studio/material/${artifact.digest}` }+ : { kind: "image", url: `/__studio/material/${artifact.digest}` };+}+/** Column entities come from the public resolved Schedule, never renderer id conventions. */function projectRanking(context: StudioAdapterContext): readonly StudioEntityDraft[] {const placement = context.placement;@@ -51,41 +76,36 @@ function projectRanking(context: StudioAdapterContext): readonly StudioEntityDra};const children = new Map(placement.children.flatMap((child) =>child.id === undefined ? [] : [[child.id, child] as const]));- const entries = (schedule.entries ?? []).map((entry): StudioEntityDraft => {+ const reveals = (schedule.entries ?? []).flatMap((entry): readonly StudioEntityDraft[] => {+ if (entry.mode !== "reveal") return [];const child = children.get(entry.itemId);const markerId = child?.referenceAttributes.during?.split(".").at(-1);- const span = entry.mode === "preset"- ? entry.settled- : { startFrame: entry.active.startFrame, endFrameExclusive: entry.settled.endFrameExclusive };- return {+ const preview = itemPreview(context, entry.itemId);+ return [{id: `${context.track.outputRef}:entity:${entry.itemId}`,authoredId: entry.itemId,...(markerId === undefined ? {} : { markerId }),label: child?.attributes.label ?? entry.itemId,- startFrame: span.startFrame,- endFrameExclusive: span.endFrameExclusive,+ startFrame: entry.active.startFrame,+ endFrameExclusive: entry.active.endFrameExclusive,stackOrder: group.stackOrder + 1,...(child === undefined ? {} : { elementRange: child.range }),- presentation: { entity: "ranking-item", shape: "window", parentId: parent, depth: 1 },- temporal: entry.mode === "preset" ? {- source: { kind: "parent-schedule" },- phases: [{ id: `${entry.itemId}:settled`, label: "Settled", role: "settled", ...entry.settled }],- } : {+ ...(preview === undefined ? {} : { preview }),+ lane: "reveal",+ presentation: { entity: "ranking-reveal", shape: "picture", depth: 0 },+ temporal: {source: { kind: "selection", ...(markerId === undefined ? {} : { id: markerId }) },projection: {startExpression: "selection.start",endExpression: "selection.end",...entry.preferred,},- phases: [- { id: `${entry.itemId}:active`, label: "Reveal", role: "active", ...entry.active },- { id: `${entry.itemId}:settled`, label: "Settled", role: "settled", ...entry.settled },- ],+ phases: [],},interaction: readonlyInteraction,- };- });- return [group, ...entries];+ }];+ }).sort((left, right) => left.startFrame - right.startFrame || left.id.localeCompare(right.id));+ return [group, ...reveals];}export const rankingAdapters: readonly StudioAdapter[] = [@@ -93,8 +113,25 @@ export const rankingAdapters: readonly StudioAdapter[] = [{id: "ranking-column", role: "track",output: { type: "VisualTrack", surface: "column", modules: ["@hypit/ranking"] },- family: "component", icon: "ranking", realizationPorts: ["schedule"],- lane: { layout: "nested", boundFacets: false },+ family: "component", label: "Ranking", icon: "ranking", realizationPorts: ["schedule"],+ poster: { source: "surface-preview" },+ lane: {+ layout: "flat",+ height: { minPx: 64, preferredPx: 80, maxPx: 112 },+ groupId: "ranking-reveals",+ },+ attachments: [{+ id: "reveal",+ family: "ranking-reveal",+ label: "Reveals",+ icon: "ranking",+ facet: "visual",+ lane: {+ layout: "flat",+ height: { minPx: 34, preferredPx: 40, maxPx: 56 },+ expandedByDefault: true,+ },+ }],interaction: readonlyInteraction, project: projectRanking,},];diff --git a/packages/studio/src/adapters/speech.ts b/packages/studio/src/adapters/speech.tsindex cc543515..376eeb54 100644--- a/packages/studio/src/adapters/speech.ts+++ b/packages/studio/src/adapters/speech.ts@@ -1,41 +1,11 @@-import type { StudioAdapter, StudioAdapterContext, StudioEntityDraft } from "./types.js";-import { childEntities, readonlyInteraction, sameSurfaceValue } from "./types.js";--type SemanticTrackValue = {- readonly items?: readonly {- readonly take: { readonly segment: { readonly segmentId: string; readonly startFrame: number; readonly endFrameExclusive: number } };- }[];-};--function projectSpeech(context: StudioAdapterContext): readonly StudioEntityDraft[] {- const semantic = sameSurfaceValue(context, "semantic") as SemanticTrackValue | undefined;- if (semantic?.items === undefined) return context.generic();- let cursor = 0;- const items = semantic.items.map(({ take }) => {- const count = take.segment.endFrameExclusive - take.segment.startFrame;- const item = { id: take.segment.segmentId, startFrame: cursor, endFrameExclusive: cursor + count, stackOrder: 0 };- cursor += count;- return item;- });- return childEntities(context, items, "semantic-take",- context.track.type === "AudioTrack" ? "waveform" : "picture");-}+import type { StudioAdapter } from "./types.js";+import { laneHeights } from "./types.js";export const speechAdapters: readonly StudioAdapter[] = [{ id: "semantic-take", role: "semantic-take", output: { type: "SemanticTake" } },- { id: "semantic-track", role: "semantic-track", output: { type: "SemanticTrack" } },- {- id: "speech-visual", role: "speech-visual",- output: { type: "VisualTrack", surface: "track", modules: ["@hypit/speech-track"], siblingType: "SemanticTrack" },- family: "speech", icon: "speech", interaction: readonlyInteraction,- realizationPorts: ["semantic"], project: projectSpeech,- lane: { layout: "flat", boundFacets: true },- },{- id: "speech-audio", role: "speech-audio",- output: { type: "AudioTrack", surface: "track", modules: ["@hypit/speech-track"], siblingType: "SemanticTrack" },- family: "speech", icon: "waveform", interaction: readonlyInteraction,- realizationPorts: ["semantic"], project: projectSpeech,- lane: { layout: "flat", boundFacets: true },+ id: "semantic-track", role: "semantic-track", output: { type: "SemanticTrack" },+ family: "speech", label: "Speech", icon: "speech",+ lane: { layout: "flat", height: laneHeights.semantic },},];diff --git a/packages/studio/src/adapters/types.ts b/packages/studio/src/adapters/types.tsindex 6799b0c2..c46da281 100644--- a/packages/studio/src/adapters/types.ts+++ b/packages/studio/src/adapters/types.ts@@ -17,8 +17,6 @@ export type StudioProjectionRole =| "semantic-track"| "caption-plan"| "realization"- | "speech-visual"- | "speech-audio"| "media"| "text"| "caption"@@ -46,11 +44,15 @@ export type StudioEntityDraft = {readonly interaction?: StudioInteraction;readonly temporal?: StudioTemporalLineage;readonly preview?: StudioMaterialPreview;+ /** Studio-local lane partition; omitted means the root lane. */+ readonly lane?: string;};export type StudioAdapterContext = {readonly track: BuiltTrack;readonly placement?: Placement;+ /** Package-owned Surface preview resolved by Studio from the selected domain. */+ readonly surfacePreview?: StudioMaterialPreview;readonly spans: readonly StudioSpan[];readonly values: ReadonlyMap<string, unknown>;readonly semantic: SemanticTimeline;@@ -67,7 +69,11 @@ export type StudioAdapter = {readonly siblingType?: string;};readonly family?: StudioTrackFamily;+ readonly label?: string;readonly icon?: string;+ /** Opts root timeline entities into the component's package-owned Surface preview. */+ readonly poster?: { readonly source: "surface-preview" };+ readonly attachments?: readonly StudioLaneAttachment[];readonly realizationPorts?: readonly string[];readonly dependencies?: readonly {readonly type: string;@@ -79,6 +85,17 @@ export type StudioAdapter = {readonly project?: (context: StudioAdapterContext) => readonly StudioEntityDraft[];};+export type StudioLaneAttachment = {+ readonly id: string;+ readonly family: StudioTrackFamily;+ readonly label?: string;+ readonly icon: string;+ readonly facet: "visual" | "audio";+ readonly lane: StudioLaneDescription;+ readonly interaction?: StudioInteraction;+ readonly inspector?: StudioInspectorDescription;+};+export const readonlyInteraction: StudioInteraction = {select: true,seek: "pointer",@@ -89,7 +106,22 @@ export const readonlyInteraction: StudioInteraction = {writeback: "none",};-export const flatLane: StudioLaneDescription = { layout: "flat", boundFacets: false };+export const laneHeights = {+ // Speech is a compact two-row item: a short name bar and a full-height+ // semantic content row. The row itself, not outer padding, carries the+ // word timing blocks.+ semantic: { minPx: 44, preferredPx: 48, maxPx: 72 },+ picture: { minPx: 60, preferredPx: 76, maxPx: 128 },+ audio: { minPx: 40, preferredPx: 48, maxPx: 88 },+ text: { minPx: 42, preferredPx: 48, maxPx: 72 },+ component: { minPx: 44, preferredPx: 52, maxPx: 96 },+ fallback: { minPx: 44, preferredPx: 52, maxPx: 96 },+} as const;++export const flatLane: StudioLaneDescription = {+ layout: "flat",+ height: laneHeights.fallback,+};export const standardInspector: StudioInspectorDescription = {sections: ["authoring", "resolved", "composition", "identity", "run"],diff --git a/packages/studio/src/preview/render.ts b/packages/studio/src/preview/render.tsindex ae72599f..38b1ddd0 100644--- a/packages/studio/src/preview/render.ts+++ b/packages/studio/src/preview/render.ts@@ -1,4 +1,4 @@-import type { Composition } from "@hypit/composition";+import type { AudioTrack, Composition } from "@hypit/composition";import { compileHyperframesDocument, materializeHyperframesHtml } from "@hypit/hyperframes";import type { ProgramSpace } from "@hypit/program-space";@@ -9,8 +9,6 @@ export type RenderInput = {readonly space: ProgramSpace;/** Digests Studio can serve for material selected by the Run. */readonly served?: ReadonlySet<string>;- /** The Track whose material carries the programme's speech. */- readonly audibleTrack?: string;};/**@@ -31,5 +29,23 @@ export function renderPreview(input: RenderInput): string {}return `/__studio/material/${artifact.digest}`;});- return injectRuntimeShim(html, input.audibleTrack);+ const audio = input.composition.tracks+ .filter((track): track is AudioTrack => track.kind === "audio")+ .flatMap((track) => track.clips)+ .map((clip) => {+ if (input.served?.has(clip.artifact.digest) !== true) {+ throw new Error(`Preview audio references Artifact ${clip.artifact.digest}, which it cannot serve.`);+ }+ return `<audio class="hypit-studio-audio" preload="auto"+ src="/__studio/material/${clip.artifact.digest}"+ data-start="${clip.target.startSample / 48_000}"+ data-duration="${(clip.target.endSampleExclusive - clip.target.startSample) / 48_000}"+ data-media-start="${clip.source.startSample / 48_000}"+ data-media-end="${clip.source.endSampleExclusive / 48_000}"+ data-loop="${clip.source.loop}"+ data-phase="${clip.source.phaseSample / 48_000}"+ data-playback-rate="${clip.playbackRate}"+ data-gain="${clip.gain}"></audio>`;+ }).join("");+ return injectRuntimeShim(html, audio);}diff --git a/packages/studio/src/preview/runtime-shim.ts b/packages/studio/src/preview/runtime-shim.tsindex 68b4b62a..31f31372 100644--- a/packages/studio/src/preview/runtime-shim.ts+++ b/packages/studio/src/preview/runtime-shim.ts@@ -5,11 +5,10 @@* an absolute Program frame, places every timed Present/material at that* instant, and waits until a discrete media seek is actually decoded.*/-function shim(audibleTrack: string | undefined): string {+function shim(): string {return String.raw`<script>(function () {- var audible = ${JSON.stringify(audibleTrack ?? null)};var muted = false;var root = document.querySelector('[data-composition-id]');var fpsAttr = (root && root.getAttribute('data-fps')) || '30';@@ -46,8 +45,21 @@ function shim(audibleTrack: string | undefined): string {start: parseFloat(ownStart || (present && present.getAttribute('data-start')) || '0') || 0,duration: parseFloat(ownDuration || (present && present.getAttribute('data-duration')) || '0') || 0,mediaStart: parseFloat(element.getAttribute('data-media-start') || '0') || 0,+ rate: parseFloat(element.getAttribute('data-playback-rate') || '1') || 1+ });+ }+ var programmeAudio = [];+ for (var element of document.querySelectorAll('.hypit-studio-audio')) {+ programmeAudio.push({+ element: element,+ start: parseFloat(element.getAttribute('data-start') || '0') || 0,+ duration: parseFloat(element.getAttribute('data-duration') || '0') || 0,+ mediaStart: parseFloat(element.getAttribute('data-media-start') || '0') || 0,+ mediaEnd: parseFloat(element.getAttribute('data-media-end') || '0') || 0,+ loop: element.getAttribute('data-loop') === 'true',+ phase: parseFloat(element.getAttribute('data-phase') || '0') || 0,rate: parseFloat(element.getAttribute('data-playback-rate') || '1') || 1,- track: present && present.getAttribute('data-hypit-track-id')+ gain: parseFloat(element.getAttribute('data-gain') || '1') || 1});}@@ -96,7 +108,9 @@ function shim(audibleTrack: string | undefined): string {var inside = local >= 0 && local < record.duration;var element = record.element;element.style.visibility = inside ? 'visible' : 'hidden';- element.muted = muted || scrubbing || audible === null || record.track !== audible;+ // Normalized picture Artifacts are deliberately silent. Programme sound+ // comes from the exact AudioTrack below rather than from a video sidecar.+ element.muted = true;if (!inside) { element.pause(); continue; }var target = record.mediaStart + (local + frameSeconds / 2) * record.rate;if (Number.isFinite(element.duration) && element.duration > 0) {@@ -117,6 +131,30 @@ function shim(audibleTrack: string | undefined): string {}}}+ for (var record of programmeAudio) {+ var local = currentSeconds - record.start;+ var inside = local >= 0 && local < record.duration;+ var element = record.element;+ element.muted = muted || scrubbing;+ if (!inside) { element.pause(); continue; }+ var interval = Math.max(0, record.mediaEnd - record.mediaStart);+ var advanced = (local + frameSeconds / 2) * record.rate;+ var target = record.mediaStart + advanced;+ if (record.loop && interval > 0) target = record.mediaStart + ((record.phase + advanced) % interval);+ else target = Math.min(target, Math.max(record.mediaStart, record.mediaEnd - 0.000001));+ if (scrubbing || local >= record.duration - frameSeconds - 0.000001) {+ element.pause();+ waits.push(seekDecoded(element, target));+ } else {+ if (Math.abs(element.currentTime - target) > 0.08) element.currentTime = target;+ element.playbackRate = record.rate;+ element.volume = Math.max(0, Math.min(1, record.gain));+ if (element.paused) {+ var started = element.play();+ if (started) started.catch(function () {});+ }+ }+ }waits.push(placeHyperframes(currentSeconds));return Promise.all(waits).then(function () { return revision === seekRevision; });}@@ -139,8 +177,8 @@ function shim(audibleTrack: string | undefined): string {</script>`;}-export function injectRuntimeShim(html: string, audibleTrack?: string): string {- const script = shim(audibleTrack);+export function injectRuntimeShim(html: string, audio = ""): string {+ const script = audio + shim();const at = html.lastIndexOf("</body>");return at < 0 ? html + script : html.slice(0, at) + script + html.slice(at);}diff --git a/packages/studio/src/programme.ts b/packages/studio/src/programme.tsindex b4b314d4..8a7c289a 100644--- a/packages/studio/src/programme.ts+++ b/packages/studio/src/programme.ts@@ -14,6 +14,7 @@ import { executeDeterministic, MemoryArtifactStore } from "./execute.js";import type { RunPlan } from "./run.js";import type { StudioProjection } from "./studio-preflight.js";import type { StudioProjectionRole } from "./studio-registry.js";+import { studioSurfacePreview } from "./surface-preview.js";const PLAYABLE = new Set(["VisualTrack", "AudioTrack"]);const TIMING = "SemanticTrack";@@ -26,6 +27,7 @@ export type BuiltTrack = {readonly candidateOrigin: "run" | "source" | "none";readonly role: StudioProjectionRole;readonly trace: StudioProjection["trace"];+ readonly surfacePreview?: import("./shared.js").StudioMaterialPreview;readonly track: unknown;};@@ -112,7 +114,11 @@ export async function preview(input: {readonly projections: readonly StudioProjection[];readonly archive?: StudioArchive;}): Promise<Preview> {- const targets = input.source.exports.filter((item) => input.outputRefs.includes(item.ref));+ const exportsByRef = new Map(input.source.exports.map((item) => [item.ref, item] as const));+ const targets = input.outputRefs.flatMap((ref) => {+ const found = exportsByRef.get(ref);+ return found === undefined ? [] : [found];+ });const store = new MemoryArtifactStore();const served = new Map(input.source.served);for (const attachment of input.run.attachments) {@@ -190,6 +196,9 @@ export async function preview(input: {if (projection === undefined) {throw new Error(`Studio projection ${target.name} has no Studio trace.`);}+ const surfacePreview = projection.trace.module === undefined || projection.trace.surface === undefined+ ? undefined+ : studioSurfacePreview(input.domain, projection.trace.module, projection.trace.surface);return [{name: target.name,type: target.type,@@ -198,6 +207,7 @@ export async function preview(input: {candidateOrigin: candidateId === undefined ? "source" as const : "run" as const,role: projection.role,trace: projection.trace,+ ...(surfacePreview === undefined ? {} : { surfacePreview }),track: stored.value,}];});diff --git a/packages/studio/src/server.ts b/packages/studio/src/server.tsindex 188b6882..b00eea8e 100644--- a/packages/studio/src/server.ts+++ b/packages/studio/src/server.ts@@ -11,6 +11,9 @@ import type { StudioDomain } from "./domain.js";import { loadStudioRun } from "./run.js";import { readStudioSession } from "./session.js";import type { Range, StudioFailure, StudioSnapshot } from "./shared.js";+import { createStudioStoryboard } from "./storyboard.js";+import type { StudioStoryboard } from "./storyboard.js";+import { findSurfacePreview } from "./surface-preview.js";export type StudioPluginOptions = {readonly source: string;@@ -49,6 +52,7 @@ export function studioPlugin(options: StudioPluginOptions): Plugin {let requestedRevision = 0;let currentSource = options.source;const watched = new Map<string, FSWatcher>();+ const storyboards = new Map<string, Promise<StudioStoryboard>>();const watchSource = (path: string): void => {if (watched.has(path)) return;@@ -160,6 +164,64 @@ export function studioPlugin(options: StudioPluginOptions): Plugin {})();return;}+ if (url.pathname === "/__studio/surface-preview") {+ void (async () => {+ const module = url.searchParams.get("module");+ const version = url.searchParams.get("version");+ const surface = url.searchParams.get("surface");+ const preview = module === null || version === null || surface === null+ ? undefined+ : findSurfacePreview(options.domain, { name: module, version }, surface);+ if (preview === undefined) {+ response.statusCode = 404;+ response.end();+ return;+ }+ const bytes = await preview.open();+ response.statusCode = 200;+ response.setHeader("content-type", preview.mediaType);+ response.setHeader("cache-control", "no-store");+ if (request.method === "HEAD") response.end();+ else response.end(Buffer.from(bytes));+ })().catch((error) => {+ json(response, 500, { error: error instanceof Error ? error.message : String(error) });+ });+ return;+ }+ const storyboardDigest = /^\/__studio\/storyboard\/(sha256:[a-f0-9]{64})$/u.exec(url.pathname)?.[1];+ if (storyboardDigest !== undefined) {+ void (async () => {+ const file = material.get(storyboardDigest);+ if (file === undefined || !file.mediaType.startsWith("video/")) {+ response.statusCode = 404;+ response.end();+ return;+ }+ try {+ let pending = storyboards.get(storyboardDigest);+ if (pending === undefined) {+ pending = createStudioStoryboard(file);+ storyboards.set(storyboardDigest, pending);+ }+ const storyboard = await pending;+ response.statusCode = 200;+ response.setHeader("content-type", "image/png");+ response.setHeader("cache-control", "public, max-age=31536000, immutable");+ response.setHeader("x-hypit-storyboard-count", String(storyboard.count));+ response.setHeader("x-hypit-storyboard-columns", String(storyboard.columns));+ response.setHeader("x-hypit-storyboard-rows", String(storyboard.rows));+ response.setHeader("x-hypit-storyboard-tile-width", String(storyboard.tileWidth));+ response.setHeader("x-hypit-storyboard-tile-height", String(storyboard.tileHeight));+ response.setHeader("x-hypit-storyboard-sample-fps", String(storyboard.sampleFps));+ if (request.method === "HEAD") response.end();+ else response.end(Buffer.from(storyboard.bytes));+ } catch (error) {+ storyboards.delete(storyboardDigest);+ json(response, 500, { error: error instanceof Error ? error.message : String(error) });+ }+ })();+ return;+ }const digest = /^\/__studio\/material\/(sha256:[a-f0-9]{64})$/u.exec(url.pathname)?.[1];if (digest !== undefined) {const file = material.get(digest);diff --git a/packages/studio/src/session.ts b/packages/studio/src/session.tsindex a0620d9a..f8fbb44b 100644--- a/packages/studio/src/session.ts+++ b/packages/studio/src/session.ts@@ -45,7 +45,6 @@ export async function readStudioSession(input: {composition: built.composition,space: built.space as never,served: new Set(built.served.keys()),- ...(audible(built) === undefined ? {} : { audibleTrack: audible(built)! }),});const text = readFileSync(input.run.authorSource, "utf8");return {@@ -62,8 +61,3 @@ export async function readStudioSession(input: {projections: inspection.projections,};}--function audible(built: Awaited<ReturnType<typeof preview>>): string | undefined {- const found = built.tracks.find((track) => track.type === "AudioTrack" && track.track !== undefined);- return found === undefined ? undefined : (found.track as { readonly id?: string }).id;-}diff --git a/packages/studio/src/shared.ts b/packages/studio/src/shared.tsindex fd57ce3b..a8f3bcb8 100644--- a/packages/studio/src/shared.ts+++ b/packages/studio/src/shared.ts@@ -13,10 +13,10 @@ export type CandidateStatus = "resolved" | "unresolved";export type StudioTrackFamily = string;export type StudioTimelinePresentation = {- /** What one selectable box means, never how the renderer happened to split it. */+ /** What one selectable box means, never CSS such as radius, hover or selection chrome. */readonly entity: string;+ /** Content grammar selected by the adapter; Studio owns the visual treatment of each shape. */readonly shape: string;- readonly parentId?: string;readonly depth: number;};@@ -66,14 +66,25 @@ export type StudioInteraction = {};/** Material Studio can show without inventing a proxy or rerunning a Provider. */-export type StudioMaterialPreview = {- readonly kind: "image";- readonly url: string;-};+export type StudioMaterialPreview =+ | { readonly kind: "image"; readonly url: string }+ | { readonly kind: "video"; readonly url: string }+ | { readonly kind: "audio"; readonly url: string };export type StudioLaneDescription = {- readonly layout: "flat" | "nested";- readonly boundFacets: boolean;+ /** Structural lane composition. Visual chrome remains a Studio-wide concern. */+ readonly layout: "flat";+ /** The adapter selects a supported range; Studio owns the current height within it. */+ readonly height: {+ readonly minPx: number;+ readonly preferredPx: number;+ readonly maxPx: number;+ };+ /** Optional local attachment group. Attached lanes render beside their root lane. */+ readonly groupId?: string;+ readonly attachedTo?: string;+ readonly order?: number;+ readonly expandedByDefault?: boolean;};export type StudioInspectorSection =@@ -91,12 +102,16 @@ export type StudioInspectorDescription = {/** Studio-owned interpretation of a terminal projection. */export type StudioTrackBinding = {readonly family: StudioTrackFamily;+ /** Studio-local lane name. This is presentation, not an authored identity. */+ readonly label?: string;readonly facet: "visual" | "audio";/** Visual/audio facets from one authored element share this identity. */readonly groupId: string;readonly icon: string;/** Stable Studio-local adapter id; fallback adapters remain explicit too. */readonly adapter: string;+ /** Studio-local partition key for an attached projection. */+ readonly attachmentId?: string;readonly lane: StudioLaneDescription;readonly inspector: StudioInspectorDescription;readonly authoredTag?: string;@@ -225,6 +240,13 @@ export type SemanticToken = {/** The semantic timebase projected from the compiled Narrative and its anchors. */export type SemanticTimeline = {+ /** Studio-only presentation owned by the SemanticTrack adapter. */+ readonly presentation: {+ readonly family: StudioTrackFamily;+ readonly label?: string;+ readonly icon: string;+ readonly lane: StudioLaneDescription;+ };readonly anchors: readonly SemanticAnchor[];readonly segments: readonly SemanticSegment[];readonly tokens: readonly SemanticToken[];diff --git a/packages/studio/src/snapshot.ts b/packages/studio/src/snapshot.tsindex c70b44d1..f36f7d99 100644--- a/packages/studio/src/snapshot.ts+++ b/packages/studio/src/snapshot.ts@@ -21,6 +21,8 @@ import {bindStudioTrack,projectStudioTrack,sealStudioClip,+ semanticTimelinePresentation,+ studioTrackAttachments,} from "./studio-registry.js";import type { StudioEntityDraft } from "./studio-registry.js";@@ -252,7 +254,12 @@ function semanticTimeline(built: Preview, script: ScriptMap | undefined): Semantstatus: "resolved",errors: [],};+ const semanticPlacement = built.source.observations.placements.find((placement) =>+ built.timingOutput !== undefined+ && (placement.outputs.includes(built.timingOutput.ref)+ || placement.outputs.includes(built.timingOutput.name)));return {+ presentation: semanticTimelinePresentation(semanticPlacement?.id),anchors: anchors.sort((left, right) => left.frame - right.frame || left.id.localeCompare(right.id)),segments: segments.sort((left, right) => left.startFrame - right.startFrame || left.id.localeCompare(right.id)),tokens: tokens.sort((left, right) => left.startFrame - right.startFrame || left.id.localeCompare(right.id)),@@ -338,14 +345,18 @@ export function snapshot(built: Preview, input: {stackOrder: span.stackOrder,};});- const clips: Clip[] = projectStudioTrack({+ const drafts = projectStudioTrack({track: item,...(placement === undefined ? {} : { placement }),+ ...(item.surfacePreview === undefined ? {} : { surfacePreview: item.surfacePreview }),spans: projectedSpans,values: built.values,semantic,generic,- }).map((draft) => sealStudioClip(item.outputRef, draft, binding));+ });+ const clips: Clip[] = drafts+ .filter((draft) => draft.lane === undefined)+ .map((draft) => sealStudioClip(item.outputRef, draft, binding));const provenance: CandidateProvenance = {output: item.name,outputRef: item.outputRef,@@ -362,13 +373,24 @@ export function snapshot(built: Preview, input: {binding,provenance,});+ for (const attachment of studioTrackAttachments(item)) {+ const attachedDrafts = drafts.filter((draft) => draft.lane === attachment.attachmentId);+ if (attachedDrafts.length === 0) continue;+ tracks.push({+ id: `${item.outputRef}::studio::${attachment.attachmentId}`,+ label: attachment.label ?? attachment.attachmentId ?? item.name,+ row: 0,+ clips: attachedDrafts.map((draft) => sealStudioClip(item.outputRef, draft, attachment)),+ binding: attachment,+ provenance,+ });+ }}- // The lowest Present sits at the bottom of the timeline, as it does in the- // picture. A Track nobody could build keeps its place rather than vanishing.- const depth = (track: Track): number =>- track.clips.length === 0 ? Number.MAX_SAFE_INTEGER : Math.min(...track.clips.map((clip) => clip.stackOrder));- const ordered = [...tracks].sort((left, right) => depth(right) - depth(left));- const rows = ordered.map((track, row) => ({ ...track, row }));+ // Root lanes retain Film's authored organizational order. A Present's z is+ // local compositing data and cannot define the order of a Track containing+ // independently stacked items. Studio-only detail lanes stay beside the+ // root that produced them in this list.+ const rows = tracks.map((track, row) => ({ ...track, row }));const declared = (built.space as { durationSec?: number; frameRate?: { numerator: number; denominator: number } })?.durationSec;diff --git a/packages/studio/src/storyboard.ts b/packages/studio/src/storyboard.tsnew file mode 100644index 00000000..ed475868--- /dev/null+++ b/packages/studio/src/storyboard.ts@@ -0,0 +1,133 @@+import { spawn } from "node:child_process";++import type { ServedFile } from "./compile.js";++export type StudioStoryboard = {+ readonly bytes: Uint8Array;+ readonly count: number;+ readonly columns: number;+ readonly rows: number;+ readonly tileWidth: number;+ readonly tileHeight: number;+ readonly sampleFps: number;+};++type VideoFacts = {+ readonly duration: number;+ readonly fps: number;+ readonly width: number;+ readonly height: number;+};++function run(+ executable: string,+ args: readonly string[],+ input: Uint8Array,+ maxOutputBytes: number,+): Promise<Buffer> {+ return new Promise((resolve, reject) => {+ const child = spawn(executable, [...args], {+ shell: false,+ windowsHide: true,+ stdio: ["pipe", "pipe", "pipe"],+ });+ const stdout: Buffer[] = [];+ let outputBytes = 0;+ let stderr = "";+ let settled = false;+ const finish = (error?: Error): void => {+ if (settled) return;+ settled = true;+ if (error === undefined) resolve(Buffer.concat(stdout));+ else reject(error);+ };+ child.stdout.on("data", (chunk: Buffer) => {+ outputBytes += chunk.byteLength;+ if (outputBytes > maxOutputBytes) {+ child.kill("SIGKILL");+ finish(new Error(`${executable} storyboard output is too large.`));+ return;+ }+ stdout.push(chunk);+ });+ child.stderr.on("data", (chunk: Buffer) => {+ stderr = `${stderr}${chunk.toString("utf8")}`.slice(-64 * 1024);+ });+ child.on("error", (error) => finish(error));+ child.on("close", (code) => {+ if (code === 0) finish();+ else finish(new Error(`${executable} exited ${String(code)}: ${stderr.trim()}`));+ });+ child.stdin.on("error", () => { /* a failed child reports through close */ });+ child.stdin.end(Buffer.from(input));+ });+}++function rational(value: string | undefined): number | undefined {+ if (value === undefined) return undefined;+ const [numerator, denominator] = value.split("/").map(Number);+ if (numerator === undefined || denominator === undefined || denominator === 0) return undefined;+ const result = numerator / denominator;+ return Number.isFinite(result) && result > 0 ? result : undefined;+}++async function videoFacts(file: ServedFile): Promise<VideoFacts> {+ const output = await run("ffprobe", [+ "-v", "error",+ "-select_streams", "v:0",+ "-show_entries", "stream=avg_frame_rate,duration,width,height:format=duration",+ "-of", "json",+ "pipe:0",+ ], file.bytes, 1024 * 1024);+ const value = JSON.parse(output.toString("utf8")) as {+ readonly streams?: readonly {+ readonly avg_frame_rate?: string;+ readonly duration?: string;+ readonly width?: number;+ readonly height?: number;+ }[];+ readonly format?: { readonly duration?: string };+ };+ const stream = value.streams?.[0];+ const duration = Number(stream?.duration ?? value.format?.duration);+ const fps = rational(stream?.avg_frame_rate);+ const width = stream?.width;+ const height = stream?.height;+ if (!(Number.isFinite(duration) && duration > 0 && fps !== undefined+ && width !== undefined && width > 0 && height !== undefined && height > 0)) {+ throw new Error("Video duration, frame rate or extent is unavailable for its Studio storyboard.");+ }+ return { duration, fps, width, height };+}++/** Build one immutable filmstrip atlas for an already selected video Artifact. */+export async function createStudioStoryboard(file: ServedFile): Promise<StudioStoryboard> {+ if (!file.mediaType.startsWith("video/")) throw new Error("Studio storyboards require a video Artifact.");+ const facts = await videoFacts(file);+ // Timeline content is roughly 40 CSS px high. An 80 px atlas tile remains+ // crisp on a 2x display while still being a small presentation derivative.+ const tileHeight = 80;+ const tileWidth = Math.max(1, Math.round(tileHeight * facts.width / facts.height));+ // Short-form material gets a tile for every source frame. Longer material+ // gradually reduces sampling density to keep the presentation atlas bounded.+ const sampleFps = Math.max(1, Math.min(facts.fps, 360 / facts.duration));+ const count = Math.max(1, Math.floor(facts.duration * sampleFps));+ const columns = Math.min(32, count);+ const rows = Math.ceil(count / columns);+ const filter = [+ `fps=${sampleFps.toFixed(6)}`,+ `scale=${tileWidth}:${tileHeight}:force_original_aspect_ratio=decrease`,+ `pad=${tileWidth}:${tileHeight}:(ow-iw)/2:(oh-ih)/2:black`,+ `tile=layout=${columns}x${rows}:nb_frames=${count}:padding=0:margin=0`,+ ].join(",");+ const bytes = await run("ffmpeg", [+ "-hide_banner", "-loglevel", "error",+ "-i", "pipe:0",+ "-vf", filter,+ "-frames:v", "1",+ "-f", "image2pipe",+ "-vcodec", "png",+ "pipe:1",+ ], file.bytes, 64 * 1024 * 1024);+ return { bytes, count, columns, rows, tileWidth, tileHeight, sampleFps };+}diff --git a/packages/studio/src/studio-preflight.ts b/packages/studio/src/studio-preflight.tsindex 238c1af9..dc3421ed 100644--- a/packages/studio/src/studio-preflight.ts+++ b/packages/studio/src/studio-preflight.ts@@ -108,34 +108,30 @@ export function inspectStudioRun(source: CompiledSource, base: RunPlan): StudioI}}- const filmTrackRefs = unique([- ...chosen.placement.references,- ...chosen.placement.children.flatMap((child) => child.references),- ]).flatMap((ref) => {+ // Only authored <film:Track source={...}/> children define Film membership+ // and Studio lane order. Film's canvas, semantic and appearance references+ // are not Tracks, and sibling outputs of those references are not implied.+ const filmTrackRefs = unique(chosen.placement.children.flatMap((child) => {+ const source = child.referenceAttributes.source;+ return source === undefined ? [] : [source];+ })).flatMap((ref) => {const output = outputFor(source, ref);return output !== undefined && (output.type === "VisualTrack" || output.type === "AudioTrack")? [output.ref]: [];});- const speechTracks = source.observations.placements.filter((placement) =>- placement.outputs.some((ref) => outputFor(source, ref)?.type === "SemanticTrack")- && placement.outputs.some((ref) => {- const output = outputFor(source, ref);- return output !== undefined && filmTrackRefs.includes(output.ref);- })- );- const semanticTakeRefs = unique(speechTracks.flatMap((placement) => [- ...placement.references,- ...placement.children.flatMap((child) => child.references),- ])).flatMap((ref) => outputFor(source, ref)?.type === "SemanticTake"+ const semanticOutput = outputFor(source, chosen.placement.referenceAttributes.semantic ?? "");+ if (semanticOutput?.type !== "SemanticTrack") {+ issues.push("Film has no traceable SemanticTrack reference");+ }+ const semanticPlacement = semanticOutput === undefined+ ? undefined+ : placementFor(source, semanticOutput.ref);+ const semanticTakeRefs = unique(semanticPlacement === undefined ? [] : [+ ...semanticPlacement.references,+ ...semanticPlacement.children.flatMap((child) => child.references),+ ]).flatMap((ref) => outputFor(source, ref)?.type === "SemanticTake"? [outputFor(source, ref)!.ref] : []);- const speechProjectionRefs = unique(speechTracks.flatMap((placement) => placement.outputs))- .flatMap((ref) => {- const output = outputFor(source, ref);- return output !== undefined- && (output.type === "SemanticTrack" || output.type === "VisualTrack" || output.type === "AudioTrack")- ? [output.ref] : [];- });if (semanticTakeRefs.length === 0) issues.push("Film has no traceable SemanticTake / Speech Track chain");const captionPlanRefs = unique(filmTrackRefs.flatMap((ref) =>@@ -146,7 +142,7 @@ export function inspectStudioRun(source: CompiledSource, base: RunPlan): StudioIconst projectionRefs = unique([...filmTrackRefs,- ...speechProjectionRefs,+ ...(semanticOutput?.type === "SemanticTrack" ? [semanticOutput.ref] : []),...semanticTakeRefs,...captionPlanRefs,...adapterRealizationRefs,diff --git a/packages/studio/src/studio-registry.ts b/packages/studio/src/studio-registry.tsindex e2a3d4ea..7ece6977 100644--- a/packages/studio/src/studio-registry.ts+++ b/packages/studio/src/studio-registry.ts@@ -4,7 +4,7 @@ import { genericAdapters } from "./adapters/generic.js";import { mediaAdapters } from "./adapters/media.js";import { rankingAdapters } from "./adapters/ranking.js";import { speechAdapters } from "./adapters/speech.js";-import type { StudioAdapter, StudioEntityDraft, StudioProjectionRole, StudioSpan } from "./adapters/types.js";+import type { StudioAdapter, StudioEntityDraft, StudioLaneAttachment, StudioProjectionRole, StudioSpan } from "./adapters/types.js";import { flatLane, readonlyInteraction, standardInspector } from "./adapters/types.js";import type { Placement } from "./observe.js";import type { BuiltTrack } from "./programme.js";@@ -86,6 +86,24 @@ export function studioRealizationPorts(return adapterFor(type, placement, siblingTypes)?.realizationPorts ?? [];}+/** Presentation for the special semantic timebase lane, still owned by its Studio adapter. */+export function semanticTimelinePresentation(authoredLabel?: string): {+ readonly family: StudioTrackBinding["family"];+ readonly label?: string;+ readonly icon: string;+ readonly lane: StudioTrackBinding["lane"];+} {+ const adapter = adapterFor("SemanticTrack", undefined, []);+ return {+ family: adapter?.family ?? "speech",+ ...(authoredLabel === undefined+ ? (adapter?.label === undefined ? {} : { label: adapter.label })+ : { label: authoredLabel }),+ icon: adapter?.icon ?? "speech",+ lane: adapter?.lane ?? flatLane,+ };+}+function trackAdapter(track: BuiltTrack): StudioAdapter & { readonly family: StudioTrackBinding["family"] } {const placement = track.trace.surface === undefined || track.trace.module === undefined? undefined@@ -102,10 +120,33 @@ function trackAdapter(track: BuiltTrack): StudioAdapter & { readonly family: Stureturn { ...adapter, family };}+export function studioTrackAttachments(track: BuiltTrack): readonly StudioTrackBinding[] {+ const root = bindStudioTrack(track);+ const adapter = trackAdapter(track);+ return (adapter.attachments ?? []).map((attachment: StudioLaneAttachment) => ({+ family: attachment.family,+ ...(attachment.label === undefined ? {} : { label: attachment.label }),+ facet: attachment.facet,+ groupId: root.groupId,+ icon: attachment.icon,+ adapter: `${adapter.id}:${attachment.id}`,+ attachmentId: attachment.id,+ lane: {+ ...attachment.lane,+ attachedTo: attachment.lane.attachedTo ?? root.lane.groupId ?? root.groupId,+ },+ inspector: attachment.inspector ?? adapter.inspector ?? standardInspector,+ references: root.references,+ interaction: attachment.interaction ?? adapter.interaction ?? readonlyInteraction,+ }));+}+export function bindStudioTrack(track: BuiltTrack): StudioTrackBinding {const adapter = trackAdapter(track);+ const label = track.trace.authoredId ?? adapter.label;return {family: adapter.family,+ ...(label === undefined ? {} : { label }),facet: track.type === "AudioTrack" ? "audio" : "visual",groupId: track.trace.authoredId ?? track.outputRef,icon: adapter.icon ?? (track.type === "AudioTrack" ? "waveform" : "layers"),@@ -121,12 +162,19 @@ export function bindStudioTrack(track: BuiltTrack): StudioTrackBinding {export function projectStudioTrack(input: {readonly track: BuiltTrack;readonly placement?: Placement;+ readonly surfacePreview?: import("./shared.js").StudioMaterialPreview;readonly spans: readonly StudioSpan[];readonly values: ReadonlyMap<string, unknown>;readonly semantic: import("./shared.js").SemanticTimeline;readonly generic: () => readonly StudioEntityDraft[];}): readonly StudioEntityDraft[] {- return trackAdapter(input.track).project?.(input) ?? input.generic();+ const adapter = trackAdapter(input.track);+ const drafts = adapter.project?.(input) ?? input.generic();+ const preview = input.surfacePreview;+ if (adapter.poster?.source !== "surface-preview" || preview === undefined) return drafts;+ return drafts.map((draft) => draft.lane !== undefined || draft.preview !== undefined+ ? draft+ : { ...draft, preview });}export function sealStudioClip(diff --git a/packages/studio/src/style.css b/packages/studio/src/style.cssindex cb3ab65b..3ed5ac85 100644--- a/packages/studio/src/style.css+++ b/packages/studio/src/style.css@@ -11,27 +11,51 @@--text: #e7e8eb;--text-2: #a4a7ae;--text-3: #6f737c;- --cyan: #00c8d7;- --cyan-soft: rgba(0, 200, 215, .16);- --danger: #ff646b;- --speech: #008768;- --speech-rail: #00d0a6;- --media: #3672b7;- --media-rail: #66b4ff;- --audio: #328344;- --audio-rail: #63cb76;- --text-track: #5a68b8;- --text-rail: #93a8ff;- --caption: #805bab;- --caption-rail: #c796ff;- --component: #a55a0f;- --component-rail: #f9953d;- --visual: #647280;- --visual-rail: #9eb4ca;+ /* Replace this ramp as one unit when Hypit's interaction identity changes. */+ --brand-200: #f8b6c4;+ --brand-400: #ee647c;+ --brand-500: #e83f5f;+ --brand-600: #c92d4c;+ --brand-soft: color-mix(in srgb, var(--brand-500) 14%, transparent);+ --brand-foreground: var(--text);+ --interaction-accent: var(--brand-500);+ --interaction-pressed: var(--brand-600);+ --danger: #d33944;+ /* Track family is data encoding, deliberately separated from the brand hue. */+ --component: #ae5528;+ --component-rail: #ff9661;+ /* Ranking reveal windows are component structure, not imported media. */+ --ranking-reveal: #874721;+ --ranking-reveal-rail: #e7834c;+ --audio: #38853e;+ --audio-rail: #75d079;+ --speech: #008882;+ --speech-rail: #00d5cd;+ --media: #007bb2;+ --media-rail: #38c5ff;+ --text-track: #5c69bc;+ --text-rail: #9caeff;+ --caption: #8e57a5;+ --caption-rail: #db98f9;+ --visual: #69737d;+ --visual-rail: #adb9c5;+ --timeline-label-width: 152px;--source-width: 350px;--workspace-width: 300px;--timeline-height: 390px;- font: 12px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;+ --timeline-item-radius: 2px;+ --timeline-selection-stroke: 1px;+ --timeline-selection-edge: 3px;+ --timeline-selection-radius: 3px;+ --timeline-selection-color: rgba(228, 231, 236, .68);+ --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", "PingFang SC", "Microsoft YaHei", "微软雅黑", "Noto Sans CJK SC", sans-serif;+ /* Keep the monospace family before CJK fallbacks so Latin timing/code glyphs+ cannot be claimed by PingFang or Microsoft YaHei. Missing CJK glyphs then+ fall through to the explicit sans-serif CJK faces. */+ --font-mono: "SF Mono", "SFMono-Regular", ui-monospace, Menlo, Monaco, "Cascadia Mono", "Cascadia Code", "Segoe UI Mono", Consolas, "PingFang SC", "Microsoft YaHei", "微软雅黑", "Noto Sans Mono CJK SC", monospace;+ font: 500 12px/1.45 var(--font-ui);+ font-variant-numeric: tabular-nums;+ font-optical-sizing: auto;}* { box-sizing: border-box; }@@ -48,10 +72,10 @@ body { cursor: default; }button, [role="button"] { font: inherit; }button { cursor: pointer; }button:focus-visible, textarea:focus-visible {- outline: 1px solid var(--cyan);+ outline: 1px solid var(--interaction-accent);outline-offset: -1px;}-::selection { background: rgba(0, 200, 215, .27); color: #fff; }+::selection { background: color-mix(in srgb, var(--interaction-accent) 27%, transparent); color: #fff; }*::-webkit-scrollbar { width: 9px; height: 9px; }*::-webkit-scrollbar-track { background: transparent; }*::-webkit-scrollbar-thumb {@@ -61,6 +85,7 @@ button:focus-visible, textarea:focus-visible {background-clip: padding-box;}*::-webkit-scrollbar-thumb:hover { background-color: rgba(255, 255, 255, .26); }+*::-webkit-scrollbar-corner, *::-webkit-resizer { background: transparent; }.icon, .pane-icon { display: block; width: 16px; height: 16px; flex: none; }#app { position: relative; display: flex; flex-direction: column; }@@ -77,10 +102,11 @@ button:focus-visible, textarea:focus-visible {background: #151619;user-select: none;}-.brand { display: flex; align-items: center; gap: 7px; min-width: 0; }-.brand-mark { width: 21px; height: 21px; display: grid; place-items: center; }-.brand-mark svg { width: 21px; height: 21px; fill: var(--text); }-.brand strong { font-size: 12px; font-weight: 600; letter-spacing: -.01em; }+.brand { display: flex; align-items: center; min-width: 0; }+.brand-mark { height: 22px; display: flex; align-items: center; gap: 8px; overflow: visible; }+.brand-mark svg { display: block; flex: none; overflow: visible; }+.brand-symbol { width: 22px; height: 20px; color: var(--brand-foreground); }+.brand-wordmark { width: 43px; height: 20px; color: var(--brand-foreground); }.project-title {min-width: 0;justify-self: center;@@ -94,10 +120,11 @@ button:focus-visible, textarea:focus-visible {.topbar-right { justify-self: end; display: flex; align-items: center; min-width: 0; }.meta {color: var(--text-3);- font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;+ font: 500 11px/1 var(--font-ui);font-variant-numeric: tabular-nums;white-space: nowrap;}+.meta:empty { display: none; }.status { color: var(--text-3); font-size: 11px; }.status.error { margin-left: 10px; color: var(--danger); }@@ -165,7 +192,7 @@ button:focus-visible, textarea:focus-visible {bottom: 0;left: 0;height: 2px;- background: var(--cyan);+ background: var(--interaction-accent);}.icon-button, .tool-button {width: 28px;@@ -174,12 +201,13 @@ button:focus-visible, textarea:focus-visible {place-items: center;padding: 0;border: 0;- border-radius: 4px;+ border-radius: var(--timeline-item-radius);background: transparent;color: var(--text-3);}.icon-button:hover, .tool-button:hover { background: var(--hover); color: var(--text); }-.tool-button.active { background: var(--cyan-soft); color: var(--cyan); }+.tool-button.active { background: var(--brand-soft); color: var(--interaction-accent); }+.tool-button.active:active { color: var(--interaction-pressed); }/* Source */.code { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }@@ -203,7 +231,7 @@ button:focus-visible, textarea:focus-visible {overflow: auto;padding: 10px 10px 42px 0;background: #141518;- font: 11px/19px ui-monospace, SFMono-Regular, Menlo, monospace;+ font: 11px/19px var(--font-mono);user-select: text;cursor: text;}@@ -219,9 +247,9 @@ button:focus-visible, textarea:focus-visible {outline: none;background: #141518;color: #b5b8bf;- font: 11px/19px ui-monospace, SFMono-Regular, Menlo, monospace;+ font: 11px/19px var(--font-mono);tab-size: 2;- caret-color: var(--cyan);+ caret-color: var(--interaction-accent);user-select: text;cursor: text;white-space: pre;@@ -269,13 +297,12 @@ button:focus-visible, textarea:focus-visible {background: transparent;}.range-canvas { position: absolute; inset: 0; z-index: 0; pointer-events: none; }-.spoken { position: absolute; z-index: 0; border-radius: 2px; background: rgba(0, 200, 215, .12); pointer-events: none; }+.spoken { position: absolute; z-index: 0; border-radius: 2px; background: color-mix(in srgb, var(--speech) 18%, transparent); pointer-events: none; }.range-element { fill: rgba(255, 255, 255, .035); stroke: rgba(255, 255, 255, .64); stroke-width: 1; }-.range-binding { fill: transparent; stroke: var(--tone, var(--cyan)); stroke-width: 1; }+.range-binding { fill: transparent; stroke: var(--tone, var(--interaction-accent)); stroke-width: 1; }/* Preview */.stage { height: 100%; min-height: 0; display: flex; flex-direction: column; background: var(--panel); }-.stage-canvas { color: var(--text-3); font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }.stage-viewport {flex: 1;min-height: 0;@@ -297,11 +324,11 @@ button:focus-visible, textarea:focus-visible {}.stage-overlay { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }.box { --tone: #fff; }-.box-content { fill: transparent; stroke: var(--cyan); stroke-width: 2; }-.box-content-guide { fill: none; stroke: rgba(0, 200, 215, .55); stroke-width: 1; stroke-dasharray: 3 4; }+.box-content { fill: transparent; stroke: rgba(228, 231, 236, .72); stroke-width: 1.5; }+.box-content-guide { fill: none; stroke: rgba(255, 255, 255, .55); stroke-width: 1; stroke-dasharray: 3 4; }.box-label {fill: #fff;- font: 500 23px -apple-system, BlinkMacSystemFont, sans-serif;+ font: 500 23px var(--font-ui);paint-order: stroke;stroke: rgba(0, 0, 0, .85);stroke-width: 5px;@@ -320,7 +347,7 @@ button:focus-visible, textarea:focus-visible {}.stage-bar button {width: 28px;- height: 28px;+ height: 22px;display: grid;place-items: center;padding: 0;@@ -331,13 +358,6 @@ button:focus-visible, textarea:focus-visible {}.stage-bar button:hover { background: var(--hover); color: #fff; }.stage-bar button[data-play] { width: 30px; height: 30px; color: #f0f1f3; }-.stage-time {- position: absolute;- left: 12px;- color: #c8cbd1;- font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;- font-variant-numeric: tabular-nums;-}.stage-mute { margin-left: 5px; }/* Inspector */@@ -388,13 +408,14 @@ button:focus-visible, textarea:focus-visible {overflow: hidden;color: var(--text-2);font-size: 11px;- font-weight: 400;+ font-weight: 500;text-align: right;text-overflow: ellipsis;white-space: nowrap;font-variant-numeric: tabular-nums;}-.property-code > strong { font: 11px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; }+.property-code > strong { font: 11px/1.3 var(--font-mono); }+.property-number > strong { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }/* Timeline */.timeline { height: 100%; min-height: 0; display: flex; flex-direction: column; background: #0f1013; }@@ -410,9 +431,10 @@ button:focus-visible, textarea:focus-visible {}.timeline-tools, .timeline-view-actions { min-width: 0; display: flex; align-items: center; gap: 3px; }.timeline-view-actions { justify-content: flex-end; }+.meta { font-variant-numeric: tabular-nums; }.timeline-time {- color: var(--cyan);- font: 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;+ color: var(--text);+ font: 500 14px/1 var(--font-mono);font-variant-numeric: tabular-nums;letter-spacing: .01em;}@@ -420,60 +442,73 @@ button:focus-visible, textarea:focus-visible {flex: 1;min-height: 0;display: grid;- grid-template-columns: 176px minmax(0, 1fr);+ grid-template-columns: var(--timeline-label-width) minmax(0, 1fr);overflow-x: hidden;overflow-y: auto;overscroll-behavior: contain;+ scrollbar-width: none;background: var(--lane);}+.timeline-body::-webkit-scrollbar { width: 0; }.timeline-labels {position: sticky;left: 0;z-index: 5;border-right: 1px solid var(--line-strong);- background: var(--panel);+ background: #111216;}.label-corner {position: sticky;top: 0;- z-index: 7;- height: 28px;+ z-index: 10;+ height: 22px;display: flex;align-items: center;justify-content: flex-end;padding-right: 8px;- border-bottom: 1px solid var(--line);- background: var(--panel);+ border-bottom: 1px solid #191b1f;+ background: #111216;color: var(--text-3);- font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;+ font: 500 11px/1 var(--font-mono);}.track-label {+ position: relative;min-width: 0;- min-height: 44px;+ min-height: 0;display: grid;- grid-template-columns: 20px minmax(0, 1fr) 18px;+ grid-template-columns: 18px minmax(0, 1fr) 18px;align-items: center;- gap: 5px;- padding: 0 7px;- border-bottom: 1px solid var(--line);- background: var(--panel);+ gap: 7px;+ padding: 0 15px;+ border-bottom: 0;+ background: transparent;+ isolation: isolate;}-.track-icon { width: 20px; height: 20px; display: grid; place-items: center; color: var(--rail, var(--track)); }-.track-icon .icon { width: 15px; height: 15px; }+.track-label::before {+ content: "";+ position: absolute;+ z-index: -1;+ inset: var(--timeline-item-inset-y) 6px;+ border-radius: var(--timeline-item-radius);+ background: #181a1f;+}+.track-label > * { position: relative; z-index: 1; }+.track-icon { width: 18px; height: 18px; display: grid; place-items: center; align-self: center; color: #858a93; }+.track-icon .icon { display: block; width: 14px; height: 14px; }.track-copy { min-width: 0; }-.track-copy strong, .track-copy small {+.track-copy strong {display: block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}-.track-copy strong { color: #c8cad0; font-size: 11px; font-weight: 500; }-.track-copy small { margin-top: 1px; color: #62666e; font-size: 11px; }+.track-copy strong { color: #cfd2d8; font-size: 11px; font-weight: 500; line-height: 18px; }.track-state { display: grid; place-items: center; }.track-media { --track: var(--media); --rail: var(--media-rail); }.track-speech { --track: var(--speech); --rail: var(--speech-rail); }.track-caption { --track: var(--caption); --rail: var(--caption-rail); }.track-component { --track: var(--component); --rail: var(--component-rail); }+.track-ranking-reveal { --track: var(--ranking-reveal); --rail: var(--ranking-reveal-rail); }.track-audio { --track: var(--audio); --rail: var(--audio-rail); }.track-text { --track: var(--text-track); --rail: var(--text-rail); }.track-visual { --track: var(--visual); --rail: var(--visual-rail); }@@ -481,90 +516,154 @@ button:focus-visible, textarea:focus-visible {.ruler {position: sticky;top: 0;- z-index: 6;- height: 28px;+ z-index: 9;+ height: 22px;overflow: hidden;border-bottom: 1px solid var(--line);background: #111216;- cursor: ew-resize;+ cursor: pointer;}.tick {position: absolute;top: 0;- height: 14px;+ height: 8px;padding-left: 4px;- border-left: 1px solid #3c3f45;- color: #8b8f98;- font: 11px/14px ui-monospace, SFMono-Regular, Menlo, monospace;+ border-left: 1px solid #35383e;+ color: transparent;+ font: 500 10px/14px var(--font-mono);white-space: nowrap;}-.tick-last { padding-right: 4px; padding-left: 0; border-right: 1px solid #45484e; border-left: 0; transform: translateX(-100%); }-.ruler-segment {+.tick-major { height: 16px; border-left-color: #686d76; color: #9da2ac; }+.tick-minor { top: 8px; height: 6px; border-left-color: #2a2d32; }+.tick-second.tick-minor { top: 6px; height: 10px; border-left-color: #3a3d43; }+.tick-subdivision { top: 10px; height: 6px; padding: 0; border-left-color: #292c31; }+.tick-frame { top: 11px; height: 5px; border-left-color: #24272c; }+.ruler-context {position: absolute;- top: 15px;- height: 13px;- overflow: hidden;+ z-index: 2;+ top: 0;+ left: 0;+ height: 16px;+ min-width: 48px;padding-left: 4px;- border-left: 1px solid rgba(0, 208, 166, .45);- background: rgba(0, 208, 166, .09);- color: #7fdcc4;- font-size: 11px;- line-height: 13px;+ background: linear-gradient(90deg, #111216 76%, rgba(17, 18, 22, 0));+ color: #a9aeb7;+ font: 500 10px/14px var(--font-mono);white-space: nowrap;+ pointer-events: none;}-.lanes { min-height: 100%; }-.lane { position: relative; min-height: 44px; overflow: hidden; border-bottom: 1px solid #191b1f; background: var(--lane); }-.semantic-lane { min-height: 52px; background: #091210; }+.tick-frame-label {+ position: absolute;+ z-index: 1;+ top: 0;+ padding-left: 3px;+ color: #858b95;+ font: 500 10px/14px var(--font-mono);+ white-space: nowrap;+ pointer-events: none;+}+.tick-last { padding-right: 4px; padding-left: 0; border-right: 1px solid #45484e; border-left: 0; transform: translateX(-100%); }+.lanes { min-height: 0; cursor: default; }+.lane { position: relative; min-height: 0; overflow: hidden; border-bottom: 1px solid #191b1f; background: var(--lane); }+.semantic-lane { min-height: 0; background: #0a0c0e; }+.lane-attached {+ border-left: 0;+ background: var(--lane);+}+.timeline-labels > .track-label:last-child,+.lanes > .lane:last-child { border-bottom: 0; }.semantic-segment {+ /* The header names the take; the second row carries its actual time cells.+ They must not collapse into one flat colour. */+ --item-head: color-mix(in srgb, var(--track) 22%, var(--lane));+ --item-body: color-mix(in srgb, var(--track) 10%, var(--lane));+ --item-cell: color-mix(in srgb, var(--track) 46%, var(--lane));position: absolute;- top: 4px;- bottom: 4px;+ top: var(--timeline-item-inset-y);+ bottom: var(--timeline-item-inset-y);min-width: 2px;overflow: hidden;border: 0;- border-radius: 4px;- background: var(--speech);- box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14);- color: #e4fbf4;+ border-radius: var(--timeline-item-radius);+ background: var(--item-body);+ box-shadow: none;+ color: var(--text);text-align: left;- cursor: pointer;+ cursor: default;}-.semantic-segment:hover { background: color-mix(in srgb, var(--speech) 88%, white); }-.semantic-segment.live { box-shadow: inset 0 0 0 1px rgba(0, 208, 166, .8), inset 0 1px 0 rgba(255, 255, 255, .14); }+.semantic-segment.selected { z-index: 4; overflow: visible; }+.semantic-segment.selected > .clip-selection { display: block; }+.semantic-segment.live { box-shadow: none; }.semantic-segment-label {- position: absolute;- top: 3px;- left: 5px;- right: 5px;+ flex: 1 1 auto;+ min-width: 0;overflow: hidden;- color: #c6f5e7;+ text-overflow: ellipsis;+ padding-left: 5px;+ color: #eef0f3;font-size: 11px;font-weight: 500;white-space: nowrap;}-.semantic-words { position: absolute; right: 0; bottom: 3px; left: 0; height: 22px; }-.semantic-word {+.semantic-segment-head {position: absolute;top: 0;+ right: 0;+ left: 0;+ height: var(--timeline-item-header-height);+ display: flex;+ align-items: center;+ gap: 6px;+ overflow: hidden;+ background: var(--item-head);+ border-bottom: 1px solid rgba(255, 255, 255, .13);+ border-radius: var(--timeline-item-radius) var(--timeline-item-radius) 0 0;+}+.semantic-segment-duration {+ flex: 0 0 auto;+ padding-right: 5px;+ color: rgba(255, 255, 255, .75);+ font: 500 11px/1 var(--font-mono);+ font-variant-numeric: tabular-nums;+}+.semantic-segment:not(.semantic-wide) .semantic-segment-duration { display: none; }+.semantic-words {+ position: absolute;+ top: var(--timeline-item-header-height);+ right: 0;bottom: 0;+ left: 0;+ overflow: hidden;+ background: var(--item-body);+ border-radius: 0 0 var(--timeline-item-radius) var(--timeline-item-radius);+}+.semantic-word {+ position: absolute;+ top: 50%;+ height: var(--timeline-content-cell-height);+ transform: translateY(-50%);min-width: 1px;overflow: hidden;+ display: flex;+ align-items: center;padding: 0 3px;border: 0;- border-left: 1px solid rgba(255, 255, 255, .16);- background: transparent;- color: #e4fbf4;+ background: var(--item-cell);+ box-shadow: none;+ color: #eef0f3;text-align: left;- cursor: pointer;-}-.semantic-word:hover { background: rgba(255, 255, 255, .10); color: #fff; }-.semantic-word.current { background: var(--cyan); color: #071214; }-.semantic-word-label { display: block; overflow: hidden; font-size: 11px; line-height: 22px; white-space: nowrap; }-.semantic-anchor { position: absolute; bottom: 3px; width: 1px; height: 7px; background: rgba(255, 255, 255, .22); pointer-events: none; }-.semantic-anchor-segment-start, .semantic-anchor-segment-end { top: 0; bottom: 0; height: auto; background: rgba(255, 255, 255, .45); }-.label-hidden .semantic-word-label, .label-hidden.semantic-segment > .semantic-segment-label { display: none; }-.semantic-coarse .semantic-words,-.semantic-coarse .semantic-anchor:not(.semantic-anchor-segment-start):not(.semantic-anchor-segment-end) { display: none; }+ cursor: default;+}+.semantic-word.current { background: var(--speech); color: #fff; }+.semantic-word-label { display: block; overflow: hidden; font-size: 11px; font-weight: 500; line-height: 1; white-space: nowrap; }+/* At overview scale keep the semantic content row visible. Only its labels+ disappear; the coloured cells still communicate the timing structure. */+.semantic-coarse .semantic-words { display: block; }+.semantic-coarse .semantic-segment-head {+ height: var(--timeline-item-header-height);+ border-bottom: 1px solid rgba(255, 255, 255, .13);+}+.label-hidden .semantic-word-label, .label-hidden .semantic-segment-label { display: none; }.track-fold {min-width: 17px;height: 17px;@@ -577,62 +676,162 @@ button:focus-visible, textarea:focus-visible {line-height: 17px;}.track-fold:hover { background: #303238; color: #fff; }+.track-label-attached {+ padding: 0 15px;+ background: transparent;+}+.track-label-attached::before { inset: var(--timeline-item-inset-y) 6px; background: #181a1f; }+.attachment-fold {+ position: relative;+ width: 17px;+ min-width: 17px;+ height: 17px;+ padding: 0;+ border: 0;+ background: transparent;+}+.attachment-fold::before {+ content: "";+ position: absolute;+ top: 5px;+ left: 5px;+ width: 5px;+ height: 5px;+ border-right: 1px solid #81858d;+ border-bottom: 1px solid #81858d;+ transform: rotate(-45deg);+ transition: transform 100ms ease;+}+.attachment-fold.expanded::before { transform: rotate(45deg) translate(-1px, -1px); }+.attachment-fold:hover { background: transparent; }.clip {--track: var(--visual);+ --item-head: color-mix(in srgb, var(--track) 58%, var(--lane));+ --item-body: color-mix(in srgb, var(--track) 20%, var(--lane));+ --item-cell: color-mix(in srgb, var(--track) 66%, var(--lane));position: absolute;top: 0;- height: calc(var(--lane-height, 52px) - 12px);+ height: calc(var(--lane-height, 52px) - 2 * var(--timeline-item-inset-y));min-width: 2px;- margin-top: 6px;+ margin-top: var(--timeline-item-inset-y);overflow: hidden;- display: flex;- align-items: center;- padding: 0 8px;+ display: block;+ padding: 0;border: 0;- border-radius: 4px;- background: var(--track);- box-shadow: inset 0 1px 0 rgba(255, 255, 255, .13);+ border-radius: var(--timeline-item-radius);+ background: var(--item-body);+ box-shadow: none;color: #fff;text-align: left;- cursor: pointer;+ cursor: default;}-.clip:hover { filter: brightness(1.12); }.clip.selected {z-index: 4;- box-shadow: inset 0 0 0 2px var(--cyan), inset 0 1px 0 rgba(255, 255, 255, .13);+ overflow: visible;+ box-shadow: none;color: #fff;}-.clip.live:not(.selected) { filter: brightness(1.06); }-.clip-copy { position: relative; z-index: 2; min-width: 0; display: block; }-.clip-material { position: absolute; z-index: 0; inset: 0; pointer-events: none; }-.clip-material-image {- background-repeat: no-repeat;+.clip:focus-visible { outline: 0; }+.clip-selection {+ position: absolute;+ z-index: 6;+ inset: calc(-1 * var(--timeline-selection-stroke));+ display: none;+ border: var(--timeline-selection-stroke) solid var(--timeline-selection-color);+ border-radius: var(--timeline-selection-radius);+ pointer-events: none;+}+.clip-selection::before, .clip-selection::after {+ content: "";+ position: absolute;+ top: -1px;+ bottom: -1px;+ width: var(--timeline-selection-edge);+ background: var(--timeline-selection-color);+}+.clip-selection::before {+ left: calc(-1 * var(--timeline-selection-stroke));+ border-radius: var(--timeline-selection-radius) 0 0 var(--timeline-selection-radius);+}+.clip-selection::after {+ right: calc(-1 * var(--timeline-selection-stroke));+ border-radius: 0 var(--timeline-selection-radius) var(--timeline-selection-radius) 0;+}+.clip.selected > .clip-selection { display: block; }+.clip-head {+ position: absolute;+ z-index: 3;+ top: 0;+ right: 0;+ left: 0;+ height: var(--timeline-item-header-height);+ display: flex;+ align-items: center;+ gap: 6px;+ overflow: hidden;+ padding: 0 5px;+ border-bottom: 1px solid rgba(255, 255, 255, .13);+ background: var(--item-head);+ border-radius: var(--timeline-item-radius) var(--timeline-item-radius) 0 0;+}+.clip-body {+ position: absolute;+ top: var(--timeline-item-header-height);+ right: 0;+ bottom: 0;+ left: 0;+ overflow: hidden;+ background: var(--item-body);+ border-radius: 0 0 var(--timeline-item-radius) var(--timeline-item-radius);+}+.clip-material { position: absolute; z-index: 1; inset: 0; overflow: hidden; pointer-events: none; }+.clip-material-image, .clip-material-video {background-position: left center;background-size: auto 100%;opacity: 1;- -webkit-mask-image: linear-gradient(90deg, #000 0, #000 38px, transparent 94px);- mask-image: linear-gradient(90deg, #000 0, #000 38px, transparent 94px);}-.clip-material-image::after {- content: "";+.clip-material-image { background-repeat: repeat-x; }+.clip-material-video { background: none; }+.clip-video-frame {position: absolute;- inset: 0;- background: linear-gradient(180deg, rgba(4, 6, 8, .52), rgba(4, 6, 8, 0) 78%);+ top: 0;+ bottom: 0;+ background-repeat: no-repeat;+}+.clip-material-audio {+ inset: 2px 5px;+ background-repeat: no-repeat;+ background-position: center;+ background-size: 100% 100%;+ opacity: .9;}-.clip-has-material:not(.clip-preview-wide) .clip-material { display: none; }-.clip-preview-wide .clip-copy { margin-left: 54px; }-.clip-phases { position: absolute; z-index: 1; inset: 0; overflow: hidden; pointer-events: none; }+.clip-material { display: block; }+.clip-content { position: absolute; z-index: 2; inset: 0; min-width: 0; overflow: hidden; }+.clip-content-text {+ display: none;+ height: 100%;+ align-items: center;+ overflow: hidden;+ padding: 0 5px;+ color: #e7e8eb;+ font-size: 11px;+ font-weight: 500;+ line-height: 1;+ text-overflow: clip;+ white-space: nowrap;+}+.clip-phases { position: absolute; z-index: 3; inset: 0; overflow: hidden; pointer-events: none; }.clip-phase { position: absolute; bottom: 0; height: 3px; border-left: 1px solid rgba(255, 255, 255, .17); }.clip-phase-active, .clip-phase-enter, .clip-phase-exit { background: rgba(255, 255, 255, .24); }.clip-phase-settled, .clip-phase-body { background: rgba(255, 255, 255, .10); }.clip-phase-preferred { border-top: 1px dashed rgba(255, 255, 255, .48); background: transparent; }-.clip-name, .clip-meta { display: block; overflow: hidden; text-overflow: clip; white-space: nowrap; }-.clip-name { color: #fff; font-size: 11px; font-weight: 500; text-shadow: 0 1px 2px rgba(0, 0, 0, .5); }+.clip-name, .clip-meta { display: block; min-width: 0; overflow: hidden; text-overflow: clip; white-space: nowrap; }+.clip-name { flex: 1 1 auto; color: #eef0f3; font-size: 11px; font-weight: 500; }.clip-meta {+ flex: 0 0 auto;display: none;- margin-top: 2px;color: rgba(255, 255, 255, .75);- font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;+ font: 500 11px/1 var(--font-mono);font-variant-numeric: tabular-nums;}.clip-wide .clip-meta { display: block; }@@ -642,89 +841,121 @@ button:focus-visible, textarea:focus-visible {.clip-text { --track: var(--text-track); }.clip-caption { --track: var(--caption); }.clip-component { --track: var(--component); }+.clip-ranking-reveal { --track: var(--ranking-reveal); }.clip-visual { --track: var(--visual); }-.clip-facet-audio::after {- content: "";- position: absolute;- z-index: 1;- right: 7px;- left: 7px;- top: 50%;- height: 1px;- background: color-mix(in srgb, var(--track) 74%, white);- opacity: .46;- pointer-events: none;-}-.clip-facet-audio .clip-copy { transform: translateY(-9px); }+.clip-shape-waveform.clip-has-material .clip-content { display: none; }+.clip-shape-text .clip-content-text { display: flex; }.clip-shape-group {border: 0;- background: rgba(255, 255, 255, .05);- box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--track) 55%, transparent);+ background: var(--item-body);+ box-shadow: none;}-.clip-shape-group > .clip-copy { align-self: flex-start; margin-top: 4px; }-.clip-shape-group > .clip-copy .clip-meta { display: none; }-.clip-shape-window { height: 22px; margin-top: 15px; border: 0; border-radius: 3px; background: var(--track); }-.clip-nested-child {- z-index: 2;- min-height: 3px;- margin-top: 0;- padding: 0;- border: 0;- border-radius: 2px;- background: color-mix(in srgb, var(--track) 80%, #000);- box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14);-}-.clip-nested-child .clip-copy { display: none; }-.clip-nested-child .clip-phase { height: 100%; opacity: .7; }-.projection-overlay {+.clip-shape-group > .clip-body { background: var(--item-body); }+.clip-shape-group .clip-meta { display: none; }+.timeline-hover {position: absolute;top: 0;+ bottom: 0;left: 0;- z-index: 3;- overflow: visible;+ z-index: 7;+ display: none;+ width: 1px;+ background: rgba(255, 255, 255, .28);pointer-events: none;+ will-change: transform;}-.projection-path {- fill: none;- stroke: rgba(0, 200, 215, .9);- stroke-width: 1;- stroke-dasharray: 4 4;- vector-effect: non-scaling-stroke;+.timeline-hover.visible { display: block; }+.timeline-hover > span {+ position: absolute;+ top: 3px;+ left: 5px;+ padding: 2px 4px;+ border-radius: 3px;+ background: #e9ebef;+ color: #111318;+ font: 500 10px/1.2 var(--font-mono);+ font-variant-numeric: tabular-nums;+ white-space: nowrap;}-.projection-point { fill: var(--lane); stroke: var(--cyan); stroke-width: 1.25; vector-effect: non-scaling-stroke; }.playhead {position: absolute;top: 0;bottom: 0;left: 0;- z-index: 8;+ z-index: 11;width: 2px;background: #fff;pointer-events: none;will-change: transform;}-.playhead.outside { display: none; }-.playhead-grip { position: absolute; top: 0; left: -5px; width: 11px; height: 9px; border-radius: 2px 2px 0 0; background: #fff; }+.playhead.outside, .playhead-grip.outside { display: none; }+.playhead-grip {+ position: absolute;+ z-index: 12;+ top: 0;+ left: 0;+ width: 11px;+ height: 9px;+ border-radius: 2px 2px 0 0;+ background: #fff;+ pointer-events: none;+ will-change: transform;+}.timeline-zoom {- height: 20px;+ height: 18px;flex: none;display: flex;align-items: center;- padding: 0 8px 0 184px;- border-top: 1px solid var(--line);- background: #17181b;-}-.zoom { position: relative; width: 100%; height: 4px; border-radius: 2px; background: #0f1012; cursor: pointer; }-.zoom-window { position: absolute; top: -1px; height: 6px; min-width: 8px; border-radius: 3px; background: #4a4d54; cursor: grab; }-.zoom-window:active { cursor: grabbing; }-.zoom-grip { position: absolute; top: -3px; width: 7px; height: 12px; cursor: ew-resize; }-.zoom-grip-start { left: -2px; }-.zoom-grip-end { right: -2px; }+ padding: 0 8px 0 var(--timeline-label-width);+ border-top: 1px solid #202227;+ background: #141519;+}+.zoom {+ position: relative;+ width: 100%;+ height: 14px;+ background: transparent;+ cursor: pointer;+}+.zoom::before {+ content: "";+ position: absolute;+ top: 6px;+ right: 0;+ left: 0;+ height: 2px;+ border-radius: 1px;+ background: #23262c;+}+.zoom-window {+ position: absolute;+ top: 5px;+ height: 4px;+ min-width: 14px;+ border-radius: 2px;+ background: #3a3e46;+ cursor: grab;+ transition: background 80ms ease;+}+/* The control remains easy to acquire without making its visible rail fat. */+.zoom-window::before { content: ""; position: absolute; inset: -5px 0; }+.zoom-window:hover { background: #464b54; }+.zoom-window:active { background: #505660; cursor: grabbing; }+.zoom-grip {+ position: absolute;+ z-index: 1;+ top: -5px;+ width: 12px;+ height: 14px;+ cursor: ew-resize;+}+.zoom-grip-start { left: -5px; }+.zoom-grip-end { right: -5px; }/* Resizers and errors */.handle { position: relative; z-index: 20; background: #0c0d0f; touch-action: none; }.handle::after { content: ""; position: absolute; background: transparent; }-.handle:hover::after, .handle:focus-visible::after { background: var(--cyan); }+.handle:hover::after, .handle:focus-visible::after { background: var(--interaction-accent); }.handle-column { width: 8px; cursor: col-resize; }.handle-column::after { top: 0; bottom: 0; left: 3px; width: 1px; }.handle-row { height: 8px; cursor: row-resize; }@@ -741,7 +972,7 @@ button:focus-visible, textarea:focus-visible {border-radius: 4px;background: #2a181a;color: #ffc1c4;- font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;+ font: 11px/1.5 var(--font-mono);white-space: pre-wrap;pointer-events: none;}diff --git a/packages/studio/src/surface-preview.ts b/packages/studio/src/surface-preview.tsnew file mode 100644index 00000000..87308113--- /dev/null+++ b/packages/studio/src/surface-preview.ts@@ -0,0 +1,35 @@+import type { SurfacePreview } from "@hypit/markup";++import type { StudioDomain } from "./domain.js";+import type { StudioMaterialPreview } from "./shared.js";++function kindOf(mediaType: string): StudioMaterialPreview["kind"] | undefined {+ if (mediaType.startsWith("image/")) return "image";+ if (mediaType.startsWith("video/")) return "video";+ if (mediaType.startsWith("audio/")) return "audio";+ return undefined;+}++export function findSurfacePreview(+ domain: StudioDomain,+ module: { readonly name: string; readonly version: string },+ surface: string,+): SurfacePreview | undefined {+ return domain.surfaces.resolve(module, surface)?.vocabulary?.preview;+}++/** A URL for a selected package resource, not a generated Build artifact. */+export function studioSurfacePreview(+ domain: StudioDomain,+ moduleName: string,+ surface: string,+): StudioMaterialPreview | undefined {+ const module = domain.resolveModule(moduleName);+ if (module === undefined) return undefined;+ const preview = findSurfacePreview(domain, module, surface);+ if (preview === undefined) return undefined;+ const kind = kindOf(preview.mediaType);+ if (kind === undefined) return undefined;+ const query = new URLSearchParams({ module: module.name, version: module.version, surface });+ return { kind, url: `/__studio/surface-preview?${query.toString()}` };+}diff --git a/packages/studio/src/ui/icons.ts b/packages/studio/src/ui/icons.tsindex 1292bf54..c9c8a652 100644--- a/packages/studio/src/ui/icons.ts+++ b/packages/studio/src/ui/icons.ts@@ -15,7 +15,10 @@ const paths: Readonly<Record<string, string>> = {pause: '<path d="M8 5v14M16 5v14"/>',volume: '<path d="M4 10v4h4l5 4V6l-5 4H4Z"/><path d="M16 9c1.5 1.7 1.5 4.3 0 6M19 6.5c3 3 3 8 0 11"/>',muted: '<path d="M4 10v4h4l5 4V6l-5 4H4ZM17 10l4 4M21 10l-4 4"/>',- speech: '<path d="M7 17H5a3 3 0 0 1-3-3V7a3 3 0 0 1 3-3h10a3 3 0 0 1 3 3v7a3 3 0 0 1-3 3h-4l-4 3v-3Z"/><path d="M7 9h6M7 12h4"/>',+ // The speech bubble's geometric path is left-heavy because of its tail.+ // Shift it two view-box units so its optical centre shares the same column+ // as the symmetric video, waveform, text and caption glyphs.+ speech: '<g transform="translate(2 0)"><path d="M7 17H5a3 3 0 0 1-3-3V7a3 3 0 0 1 3-3h10a3 3 0 0 1 3 3v7a3 3 0 0 1-3 3h-4l-4 3v-3Z"/><path d="M7 9h6M7 12h4"/></g>',waveform: '<path d="M3 12h2l1.5-6 3 12 3-14 3 16 2-8H21"/>',video: '<rect x="3" y="5" width="14" height="14" rx="2"/><path d="m17 10 4-2v8l-4-2v-4Z"/>',text: '<path d="M5 5h14M12 5v14M8 19h8"/>',diff --git a/packages/studio/src/ui/main.ts b/packages/studio/src/ui/main.tsindex c3d9e5a6..5ef30a46 100644--- a/packages/studio/src/ui/main.ts+++ b/packages/studio/src/ui/main.ts@@ -12,11 +12,22 @@ import "../style.css";const app = document.querySelector<HTMLElement>("#app")!;app.innerHTML = `<header class="topbar">- <div class="brand">+ <div class="brand" aria-label="Hypit"><span class="brand-mark" aria-hidden="true">- <svg viewBox="0 0 32 32"><path d="M7.6 3.8H14.6L12.6 7.2H5.6L7.6 3.8ZM4.1 10.4H16.6L18.7 7H30.4L27.9 11.1H16.1L14.1 14.2H1.8L4.1 10.4ZM19.1 14.1H23.1L19.3 20.7H15.4L19.1 14.1Z"/></svg>+ <svg class="brand-symbol" viewBox="50 180 262 234" preserveAspectRatio="xMidYMid meet">+ <path fill="currentColor" d="M303.78,277.82c-5.98-8.63-15.83-13.77-26.32-13.77h-93.41c-12.28,0-24.92,7.44-29.6,18.8l-28.26,75.82c-4.6,11.25-4.54,24.05,2.22,34.16,6.79,10.15,19.36,16.15,31.57,16.15h85.98c14.12,0,26.9-8.88,31.84-22.1l29.69-79.57c3.67-9.84,2.29-20.86-3.69-29.48v-.02h-.02ZM252.02,377.25c-.94,2.52-3.39,4.22-6.08,4.22h-83.45c-4.34,0-6.68-2.8-7.49-3.99s-2.5-4.43-.84-8.44l23.85-66.24c2.29-6.35,8.08-10.87,14.82-11.22.33-.02.67-.02,1.02-.02h75.41s12.51,1.42,9.29,14.61l-26.53,71.09h0ZM106.85,361.73s-22.36-11.59-17.66-32.66l29.67-82.23c4.78-13.25,17.36-22.09,31.45-22.09h95.02c6.25,0,12.1,3.03,15.71,8.14l13.89,19.68h-112.97c-8.7,0-16.49,5.41-19.52,13.57l-35.59,95.6h0ZM73.3,323.27s-22.37-11.59-17.66-32.66l29.67-82.23c4.79-13.25,17.37-22.09,31.45-22.09h89.91c6.25,0,12.1,3.03,15.71,8.14l13.89,19.68h-107.84c-8.7,0-16.49,5.41-19.52,13.57l-35.59,95.6h-.02Z"/>+ </svg>+ <svg class="brand-wordmark" viewBox="370 228 422 180" preserveAspectRatio="xMinYMid meet">+ <g fill="currentColor">+ <rect x="692.47" y="276.19" width="19.22" height="90.09" rx="4.12" ry="4.12"/>+ <path d="M462.31,293.32c-4.51-11.11-12.93-15.68-28.26-17.66-15.52-2-31.17,1.58-36.41,2.96v-38.42c0-2.22-1.8-4.02-4.02-4.02h-11.19c-2.22,0-4.02,1.8-4.02,4.02v123.26c0,2.22,1.8,4.02,4.02,4.02h11.19c2.22,0,4.02-1.8,4.02-4.02v-66.25c3.68-1.46,16.84-6.13,30.89-4.57,12.12,1.35,15.81,10.13,16.92,14.75.32,1.33.47,2.68.47,4.03v53.36c0,1.49,1.2,2.68,2.68,2.68h13.65c1.49,0,2.68-1.2,2.68-2.68v-57.38c0-4.82-.82-9.63-2.63-14.09h.01Z"/>+ <path d="M568.55,346.34v-67.42c0-1.57-1.27-2.85-2.85-2.85h-14.66c-1.57,0-2.85,1.27-2.85,2.85v64.51c0,.58-.19,1.16-.58,1.6-1.62,1.88-7.33,6.23-25.19,5.92-2.22.05-6.37-.58-8.51-1.13-14.03-3.61-12.62-17.41-12.62-33.16v-37.73c0-1.57-1.27-2.85-2.85-2.85h-13.68c-1.57,0-2.85,1.27-2.85,2.85v57.63s-2.72,24.49,25.91,30.92c0,0,3.11.67,7.45,1.01h-.02s.13,0,.38.03c.07,0,.15,0,.23.02.19.02.42.02.69.04.25.02.51.02.77.04,2.94.14,8.59.25,14.08-.44h-.05c6.97-.77,13.42-2.51,17.37-5.02,0,0-1.77,20.45-18.82,23.73-9.86,1.13-24.24-.46-31.62-1.65-2.22-.36-4.33,1.06-4.84,3.24l-2.55,10.92c-.49,2.08.99,4.09,3.1,4.28,7.44.63,23.6,1.84,34.54,1.37,14.62-.61,26.8-6.24,34.06-21.17,7.26-14.93,5.93-37.54,5.93-37.54h.03Z"/>+ <path d="M674.19,297.63c-8.46-21.2-28.09-21.76-37.64-22.58-7.78-.66-37.08.93-47.69,1.54-2.17.13-3.86,1.92-3.86,4.1v119.88c0,1.74,1.41,3.14,3.14,3.14h14.17c1.74,0,3.14-1.41,3.14-3.14v-34.16c45.01,4.23,52.91-1.5,60.82-8.86,8.8-8.2,15.13-37.91,7.91-59.92h.01ZM656.46,330.82c-.27,4.64-1.91,18-19.5,19.22-17.59,1.23-31.5-2.32-31.5-2.32v-54.21c4.62-.18,16.65-.61,25.09-.61,10.64,0,15.27,1.5,21.82,8.32s4.37,24.96,4.09,29.59h0Z"/>+ <path d="M784.34,292.92c1.41,0,2.56-1.15,2.56-2.56v-11.6c0-1.41-1.15-2.56-2.56-2.56h-27.3v-19.11c0-1.32-1.07-2.38-2.38-2.38h-14.87c-1.32,0-2.38,1.07-2.38,2.38v19.11h-10.74c-1.41,0-2.56,1.15-2.56,2.56v11.6c0,1.41,1.15,2.56,2.56,2.56h10.74v48.61c0,14.46,11.72,26.19,26.19,26.19h19.46c2.13,0,3.86-1.73,3.86-3.86v-9.69c0-2.13-1.73-3.86-3.86-3.86h-13.53c-6.9,0-12.48-5.59-12.48-12.48v-44.92h27.3-.01Z"/>+ </g>+ <circle fill="#e83f5f" cx="703.1" cy="250.37" r="14.18"/>+ </svg></span>- <div><strong>Hypit</strong></div></div><div class="project-title" data-project></div><div class="topbar-right">@@ -89,14 +100,11 @@ const failureView = app.querySelector<HTMLElement>("[data-failure]")!;// Program-level facts never change while a Source is being read, so they live in// the header rather than taking a panel that would have to sit over something.function renderMeta(snapshot: StudioSnapshot): void {- const { space } = snapshot;project.textContent = snapshot.source.path.split("/").at(-1) ?? snapshot.source.path;project.title = snapshot.source.path;- meta.textContent = [- `${space.canvasWidth}x${space.canvasHeight}`,- `${space.frameRate.numerator}/${space.frameRate.denominator}fps`,- `${space.durationSec.toFixed(2)}s`,- ].join(" · ");+ // Sequence facts belong to the project/inspector, not the application chrome.+ // The timeline transport is the single persistent time readout.+ meta.textContent = "";}function property(label: string, value: string, tone?: string): HTMLElement {@@ -151,10 +159,10 @@ function renderInspector(snapshot: StudioSnapshot, clipId: string | undefined):hero.querySelector("small")!.textContent = track?.label ?? "Visual track";const timing = group("Timing", [- property("Start", `${clip.startFrame}f`),- property("End", `${clip.endFrameExclusive}f`),- property("Duration", `${durationFrames}f`),- property("Seconds", `${(durationFrames / fps).toFixed(2)}s`),+ property("Start", `${clip.startFrame}f`, "property-number"),+ property("End", `${clip.endFrameExclusive}f`, "property-number"),+ property("Duration", `${durationFrames}f`, "property-number"),+ property("Seconds", `${(durationFrames / fps).toFixed(2)}s`, "property-number"),]);const placement = group("Placement", [property("Track", track?.label ?? "—", "property-wide"),@@ -171,6 +179,28 @@ function renderInspector(snapshot: StudioSnapshot, clipId: string | undefined):inspector.replaceChildren(hero, placement, timing, ...(source === undefined ? [] : [source]));}+function renderSemanticInspector(snapshot: StudioSnapshot, segmentId: string): void {+ const segment = snapshot.semantic.segments.find((item) => item.id === segmentId);+ if (segment === undefined) { inspector.replaceChildren(); return; }+ const fps = snapshot.space.frameRate.numerator / snapshot.space.frameRate.denominator;+ const durationFrames = segment.endFrameExclusive - segment.startFrame;+ const hero = document.createElement("div");+ hero.className = "selection-hero";+ hero.innerHTML = `+ <span class="selection-icon" data-selection-icon></span>+ <div class="selection-title"><strong></strong><small></small></div>+ <span class="selection-kind">Speech</span>`;+ setIcon(hero.querySelector("[data-selection-icon]")!, snapshot.semantic.presentation.icon);+ hero.querySelector("strong")!.textContent = segment.id;+ hero.querySelector("small")!.textContent = "Semantic take";+ inspector.replaceChildren(hero, group("Timing", [+ property("Start", `${segment.startFrame}f`, "property-number"),+ property("End", `${segment.endFrameExclusive}f`, "property-number"),+ property("Duration", `${durationFrames}f`, "property-number"),+ property("Seconds", `${(durationFrames / fps).toFixed(2)}s`, "property-number"),+ ]));+}+// The word being spoken at the playhead, which is the point of carrying token// timings at all: it ties the Script text to the frame on screen.store.subscribe(({ snapshot, playhead }) => {@@ -183,13 +213,17 @@ let described = "";let scrolledTo = "";store.subscribe(({ snapshot, selection, playhead }) => {- const origin = selection.kind === "clip" ? selection.origin : undefined;+ const origin = selection.kind === "none" ? undefined : selection.origin;const chosen = selection.kind === "clip" ? store.clip(selection.clipId) : undefined;+ const chosenSegment = selection.kind === "semantic-segment"+ ? snapshot.semantic.segments.find((item) => item.id === selection.segmentId)+ : undefined;// Rebuilding this every frame of playback would be DOM churn for no change.- const describes = `${snapshot.revision}:${chosen?.id ?? ""}`;+ const describes = `${snapshot.revision}:${chosen?.id ?? chosenSegment?.id ?? ""}`;if (describes !== described) {described = describes;- renderInspector(snapshot, chosen?.id);+ if (chosenSegment !== undefined) renderSemanticInspector(snapshot, chosenSegment.id);+ else renderInspector(snapshot, chosen?.id);}// Every Selection the playhead is inside is outlined, not only what was@@ -211,11 +245,16 @@ store.subscribe(({ snapshot, selection, playhead }) => {if (chosen?.elementRange !== undefined) {highlights.push({ range: chosen.elementRange, tone: "element" });}+ if (chosenSegment?.range !== undefined) {+ highlights.push({ range: chosenSegment.range, tone: "element" });+ }// Scroll only when the selection actually moved, and never toward the pane// the author is pointing at: following the playhead every frame would drag// the source out from under whoever is reading it.- const focused = chosen === undefined ? "" : `${snapshot.revision}:${chosen.id}`;+ const focused = chosen === undefined && chosenSegment === undefined+ ? ""+ : `${snapshot.revision}:${chosen?.id ?? chosenSegment?.id}`;const moved = focused.length > 0 && focused !== scrolledTo;scrolledTo = focused;code.highlight(highlights, moved && origin !== "code");@@ -266,15 +305,31 @@ window.addEventListener("keydown", (event) => {const state = store.current();if (state === undefined || event.metaKey || event.ctrlKey || event.altKey) return;// Space is the transport everywhere else; typing in a field is not transport.- const editing = (event.target as HTMLElement | null)?.closest("input, textarea, select") !== null;+ const target = event.target instanceof Element ? event.target : undefined;+ const editing = target?.closest("input, textarea, select") !== null && target !== undefined;if (event.key === " " && !editing) {stage.toggle();event.preventDefault();return;}+ if (!editing && (event.key === "-" || event.key === "_")) {+ timeline.zoomOut();+ event.preventDefault();+ return;+ }+ if (!editing && (event.key === "=" || event.key === "+")) {+ timeline.zoomIn();+ event.preventDefault();+ return;+ }+ if (!editing && (event.key === "\\" || event.key.toLowerCase() === "f")) {+ timeline.fit();+ event.preventDefault();+ return;+ }const step = event.shiftKey ? 10 : 1;- if (event.key === "ArrowLeft") store.seek(state.playhead.frame - step, "timeline");- else if (event.key === "ArrowRight") store.seek(state.playhead.frame + step, "timeline");+ if (event.key === "ArrowLeft" || event.key === ",") store.seek(state.playhead.frame - step, "timeline");+ else if (event.key === "ArrowRight" || event.key === ".") store.seek(state.playhead.frame + step, "timeline");else if (event.key === "Home") store.seek(0, "timeline");else if (event.key === "End") store.seek(state.snapshot.space.frameCount - 1, "timeline");else if (event.key === "Escape") store.clearSelection();diff --git a/packages/studio/src/ui/material-preview.ts b/packages/studio/src/ui/material-preview.tsnew file mode 100644index 00000000..3ddbf433--- /dev/null+++ b/packages/studio/src/ui/material-preview.ts@@ -0,0 +1,165 @@+import type { StudioMaterialPreview } from "../shared.js";++type Storyboard = {+ readonly imageUrl: string;+ readonly count: number;+ readonly columns: number;+ readonly rows: number;+ readonly tileWidth: number;+ readonly tileHeight: number;+};++const generatedAudio = new Map<string, Promise<string | undefined>>();+const resolvedAudio = new Map<string, string | undefined>();+const storyboards = new Map<string, Promise<Storyboard | undefined>>();+const resolvedStoryboards = new Map<string, Storyboard | undefined>();++function positiveHeader(response: Response, name: string): number | undefined {+ const value = Number(response.headers.get(name));+ return Number.isFinite(value) && value > 0 ? value : undefined;+}++async function loadStoryboard(materialUrl: string): Promise<Storyboard | undefined> {+ const storyboardUrl = materialUrl.replace("/__studio/material/", "/__studio/storyboard/");+ if (storyboardUrl === materialUrl) return undefined;+ const response = await fetch(storyboardUrl);+ if (!response.ok) return undefined;+ const count = positiveHeader(response, "x-hypit-storyboard-count");+ const columns = positiveHeader(response, "x-hypit-storyboard-columns");+ const rows = positiveHeader(response, "x-hypit-storyboard-rows");+ const tileWidth = positiveHeader(response, "x-hypit-storyboard-tile-width");+ const tileHeight = positiveHeader(response, "x-hypit-storyboard-tile-height");+ if (count === undefined || columns === undefined || rows === undefined+ || tileWidth === undefined || tileHeight === undefined) return undefined;+ return {+ imageUrl: URL.createObjectURL(await response.blob()),+ count: Math.floor(count),+ columns: Math.floor(columns),+ rows: Math.floor(rows),+ tileWidth: Math.floor(tileWidth),+ tileHeight: Math.floor(tileHeight),+ };+}++function storyboardFor(url: string): Promise<Storyboard | undefined> {+ const held = storyboards.get(url);+ if (held !== undefined) return held;+ const pending = loadStoryboard(url).catch(() => undefined).then((storyboard) => {+ resolvedStoryboards.set(url, storyboard);+ return storyboard;+ });+ storyboards.set(url, pending);+ return pending;+}++function renderStoryboard(target: HTMLElement, storyboard: Storyboard): void {+ if (!target.isConnected) return;+ const lane = target.closest<HTMLElement>(".lane");+ if (lane === null) return;+ const targetBox = target.getBoundingClientRect();+ const laneBox = lane.getBoundingClientRect();+ const visibleLeft = Math.max(targetBox.left, laneBox.left);+ const visibleRight = Math.min(targetBox.right, laneBox.right);+ if (visibleRight <= visibleLeft || targetBox.width < 1 || targetBox.height < 1) return;++ const slotWidth = Math.max(1, targetBox.height * storyboard.tileWidth / storyboard.tileHeight);+ const firstSlot = Math.floor((visibleLeft - targetBox.left) / slotWidth);+ const lastSlot = Math.ceil((visibleRight - targetBox.left) / slotWidth);+ const frames: HTMLElement[] = [];+ for (let slot = firstSlot; slot < lastSlot; slot += 1) {+ const left = slot * slotWidth;+ const progress = Math.max(0, Math.min(1, (left + slotWidth / 2) / targetBox.width));+ const index = Math.min(storyboard.count - 1, Math.floor(progress * storyboard.count));+ const column = index % storyboard.columns;+ const row = Math.floor(index / storyboard.columns);+ const frame = document.createElement("span");+ frame.className = "clip-video-frame";+ frame.style.left = `${left}px`;+ // Adjacent frames share the same fractional boundary. Adding a full CSS+ // pixel here lets the next frame overpaint roughly 3% of a 9:16 thumbnail,+ // which reads as a horizontal crop even though the atlas itself is exact.+ frame.style.width = `${slotWidth}px`;+ frame.style.backgroundImage = `url(${JSON.stringify(storyboard.imageUrl)})`;+ frame.style.backgroundSize = `${storyboard.columns * slotWidth}px ${storyboard.rows * targetBox.height}px`;+ frame.style.backgroundPosition = `${-column * slotWidth}px ${-row * targetBox.height}px`;+ frames.push(frame);+ }+ target.replaceChildren(...frames);+ target.classList.add("ready");+}++async function audioWaveform(url: string): Promise<string | undefined> {+ const response = await fetch(url);+ if (!response.ok) return undefined;+ const audioContext = new AudioContext();+ try {+ const buffer = await audioContext.decodeAudioData(await response.arrayBuffer());+ const width = 2048;+ const height = 56;+ const channels = Array.from({ length: buffer.numberOfChannels }, (_, index) => buffer.getChannelData(index));+ const samplesPerColumn = Math.max(1, Math.floor(buffer.length / width));+ const segments: string[] = [];+ for (let x = 0; x < width; x += 1) {+ const from = x * samplesPerColumn;+ const to = Math.min(buffer.length, from + samplesPerColumn);+ let peak = 0;+ for (const channel of channels) {+ for (let sample = from; sample < to; sample += 1) {+ peak = Math.max(peak, Math.abs(channel[sample] ?? 0));+ }+ }+ const amplitude = Math.max(1, peak * (height - 4));+ const top = (height - amplitude) / 2;+ segments.push(`M${x} ${top.toFixed(2)}V${(top + amplitude).toFixed(2)}`);+ }+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" preserveAspectRatio="none"><path d="${segments.join("")}" fill="none" stroke="rgba(255,255,255,.76)" stroke-width="1" vector-effect="non-scaling-stroke"/></svg>`;+ return `data:image/svg+xml,${encodeURIComponent(svg)}`;+ } finally {+ await audioContext.close();+ }+}++function audioPreview(url: string): Promise<string | undefined> {+ const held = generatedAudio.get(url);+ if (held !== undefined) return held;+ const pending = audioWaveform(url).catch(() => undefined).then((waveform) => {+ resolvedAudio.set(url, waveform);+ return waveform;+ });+ generatedAudio.set(url, pending);+ return pending;+}++/** Mount only a real selected artifact; failed decoding deliberately leaves the item plain. */+export function mountMaterialPreview(target: HTMLElement, preview: StudioMaterialPreview): void {+ target.classList.add(`clip-material-${preview.kind}`);+ if (preview.kind === "video") {+ if (resolvedStoryboards.has(preview.url)) {+ const storyboard = resolvedStoryboards.get(preview.url);+ if (storyboard !== undefined) renderStoryboard(target, storyboard);+ return;+ }+ void storyboardFor(preview.url).then((storyboard) => {+ if (storyboard !== undefined) renderStoryboard(target, storyboard);+ });+ return;+ }+ if (preview.kind === "image") {+ target.style.backgroundImage = `url(${JSON.stringify(preview.url)})`;+ target.classList.add("ready");+ return;+ }+ if (resolvedAudio.has(preview.url)) {+ const url = resolvedAudio.get(preview.url);+ if (url !== undefined) {+ target.style.backgroundImage = `url(${JSON.stringify(url)})`;+ target.classList.add("ready");+ }+ return;+ }+ void audioPreview(preview.url).then((url) => {+ if (url === undefined || !target.isConnected) return;+ target.style.backgroundImage = `url(${JSON.stringify(url)})`;+ target.classList.add("ready");+ });+}diff --git a/packages/studio/src/ui/selection.ts b/packages/studio/src/ui/selection.tsindex d16f6e33..11d868e0 100644--- a/packages/studio/src/ui/selection.ts+++ b/packages/studio/src/ui/selection.ts@@ -9,7 +9,8 @@ export type Origin = "timeline" | "code" | "video";export type Selection =| { readonly kind: "none" }- | { readonly kind: "clip"; readonly clipId: string; readonly origin: Origin };+ | { readonly kind: "clip"; readonly clipId: string; readonly origin: Origin }+ | { readonly kind: "semantic-segment"; readonly segmentId: string; readonly origin: Origin };export type Playhead = { readonly frame: number; readonly origin: Origin | "play" };@@ -26,6 +27,11 @@ export type Store = {/** Clips covering a frame, topmost track first. */clipsAt(frame: number): readonly Clip[];load(snapshot: StudioSnapshot): void;+ /** Select without moving the playhead; timeline inspection must not destroy position. */+ select(clipId: string, origin: Origin): void;+ /** Select one authored SemanticTake without moving the playhead. */+ selectSemanticSegment(segmentId: string, origin: Origin): void;+ /** Select and seek to the clip start, used by source navigation. */selectClip(clipId: string, origin: Origin): void;/*** Look at one instant, optionally selecting a clip there. Used when the thing@@ -98,15 +104,28 @@ export function createStore(): Store {if (held.kind === "clip" && !clips().some((clip) => clip.id === held.clipId)) {selection = { kind: "none" };}+ if (held.kind === "semantic-segment"+ && !snapshot.semantic.segments.some((segment) => segment.id === held.segmentId)) {+ selection = { kind: "none" };+ }playhead = { frame: clamp(playhead.frame), origin: playhead.origin };emit();},+ select(clipId, origin) {+ const clip = clips().find((item) => item.id === clipId);+ if (clip === undefined) return;+ selection = { kind: "clip", clipId, origin };+ emit();+ },+ selectSemanticSegment(segmentId, origin) {+ if (snapshot?.semantic.segments.some((segment) => segment.id === segmentId) !== true) return;+ selection = { kind: "semantic-segment", segmentId, origin };+ emit();+ },selectClip(clipId, origin) {const clip = clips().find((item) => item.id === clipId);if (clip === undefined) return;selection = { kind: "clip", clipId, origin };- // Selecting is also a seek: "show me this B-roll" means showing the frame- // it starts on, not wherever the playhead happened to be.playhead = { frame: clamp(clip.startFrame), origin };emit();},diff --git a/packages/studio/src/ui/stage.ts b/packages/studio/src/ui/stage.tsindex 4372a49c..0962d458 100644--- a/packages/studio/src/ui/stage.ts+++ b/packages/studio/src/ui/stage.ts@@ -23,7 +23,6 @@ export function createStage(store: Store): Stage {element.innerHTML = `<div class="stage-heading"><div class="stage-title">${icon("preview")}<strong>Preview</strong></div>- <span class="stage-canvas" data-canvas></span></div><div class="stage-viewport"><div class="stage-scaler">@@ -31,7 +30,6 @@ export function createStage(store: Store): Stage {</div></div><div class="stage-bar">- <span class="stage-time" data-time>00:00:00</span><button type="button" data-previous aria-label="Previous frame" title="Previous frame">${icon("previous")}</button>@@ -81,7 +79,7 @@ export function createStage(store: Store): Stage {// the third way into the same selection.scaler.addEventListener("click", (event) => {const clip = overlay.hitTest(event.clientX, event.clientY);- if (clip !== undefined) store.selectClip(clip.id, "video");+ if (clip !== undefined) store.select(clip.id, "video");else store.clearSelection();});// The room around the picture is empty in the plainest sense.@@ -94,8 +92,6 @@ export function createStage(store: Store): Stage {const playIcon = element.querySelector<HTMLElement>("[data-icon]")!;const mute = element.querySelector<HTMLButtonElement>("[data-mute]")!;const muteIcon = element.querySelector<HTMLElement>("[data-mute-icon]")!;- const time = element.querySelector<HTMLElement>("[data-time]")!;- const canvas = element.querySelector<HTMLElement>("[data-canvas]")!;type SeekWindow = Window & {__hypitSeekFrame?: (frame: number) => Promise<boolean>;@@ -202,11 +198,6 @@ export function createStage(store: Store): Stage {store.subscribe((value) => {const first = state === undefined;state = value;- const frameRate = fps(value.snapshot);- const seconds = value.playhead.frame / frameRate;- const whole = Math.floor(seconds);- time.textContent = `${String(Math.floor(whole / 60)).padStart(2, "0")}:${String(whole % 60).padStart(2, "0")}:${String(value.playhead.frame % Math.round(frameRate)).padStart(2, "0")}`;- canvas.textContent = `${value.snapshot.space.canvasWidth} × ${value.snapshot.space.canvasHeight}`;if (value.snapshot.revision !== mounted) {mounted = value.snapshot.revision;stop();diff --git a/packages/studio/src/ui/timeline.ts b/packages/studio/src/ui/timeline.tsindex e2958659..7524b1eb 100644--- a/packages/studio/src/ui/timeline.ts+++ b/packages/studio/src/ui/timeline.ts@@ -1,36 +1,60 @@import type {- SemanticAnchor,SemanticToken,StudioSnapshot,- StudioTemporalLineage,} from "../shared.js";import { icon, setIcon } from "./icons.js";+import { mountMaterialPreview } from "./material-preview.js";import type { State, Store } from "./selection.js";import { createZoom } from "./zoom.js";-export type Timeline = { readonly element: HTMLElement };+export type Timeline = {+ readonly element: HTMLElement;+ readonly zoomIn: () => void;+ readonly zoomOut: () => void;+ readonly fit: () => void;+};-const SEMANTIC_LANE_HEIGHT = 52;const opened = new Set<string>();-let speechExpanded = false;+const expandedAttachmentGroups = new Set<string>();+const collapsedAttachmentGroups = new Set<string>();+const itemMetrics = {+ // Ordinary items fill their rows. Only the semantic lane owns compact word cells.+ insetYPx: 1,+ headerPx: 15,+ contentCellPx: 18,+ gapPx: 1,+} as const;++const measuredText = (() => {+ const context = document.createElement("canvas").getContext("2d");+ const cache = new Map<string, number>();+ return (value: string, font: string): number => {+ const key = `${font}\u0000${value}`;+ const existing = cache.get(key);+ if (existing !== undefined) return existing;+ if (context === null) return value.length * 7;+ context.font = font;+ const width = context.measureText(value).width;+ cache.set(key, width);+ return width;+ };+})();-function trackLaneHeight(track: StudioSnapshot["tracks"][number]): number {- if (track.binding.facet === "audio") return 44;- if (track.binding.family === "media" || track.binding.family === "speech") return 56;- if (track.binding.family === "caption") return 46;- return 48;+function timecode(seconds: number): string {+ const whole = Math.floor(seconds);+ return `${String(Math.floor(whole / 60)).padStart(2, "0")}:${String(whole % 60).padStart(2, "0")}`;}-function tickSeconds(durationSec: number, widthPx: number): number {- for (const step of [1, 2, 5, 10, 15, 30, 60]) {- if (durationSec / step <= Math.max(2, widthPx / 72)) return step;- }- return 120;+function frameTickLabel(frame: number): string {+ return `${frame}f`;}-function timecode(seconds: number): string {- const whole = Math.floor(seconds);- return `${String(Math.floor(whole / 60)).padStart(2, "0")}:${String(whole % 60).padStart(2, "0")}`;+function frameSteps(frameRate: number): readonly number[] {+ const result: number[] = [];+ for (let candidate = 1; candidate <= frameRate; candidate += 1) {+ if (frameRate % candidate === 0) result.push(candidate);+ }+ return result;}function place(frame: number, frameCount: number, shown: { start: number; end: number }): number {@@ -39,45 +63,24 @@ function place(frame: number, frameCount: number, shown: { start: number; end: n}function displayTrackName(track: StudioSnapshot["tracks"][number]): string {- if (track.binding.family === "speech") return track.binding.facet === "audio" ? "Voice" : "Picture";- const base = track.label.replace(/\.(?:track|visual|audio)$/u, "");- return base.length === 0 ? track.label : base;+ if (track.binding.label !== undefined) return track.binding.label;+ return track.label;}-function sourceWindow(- snapshot: StudioSnapshot,- source: StudioTemporalLineage["source"],-): { readonly start: number; readonly end: number } | undefined {- if (source.kind === "selection") {- const match = snapshot.semantic.selections.find((item) => item.id === source.id- && (source.occurrenceId === undefined || source.occurrenceId === item.occurrenceId));- return match === undefined ? undefined : { start: match.startFrame, end: match.endFrameExclusive };- }- if (source.kind === "moment") {- const match = snapshot.semantic.moments.find((item) => item.id === source.id- && (source.occurrenceId === undefined || source.occurrenceId === item.occurrenceId));- return match === undefined ? undefined : { start: match.frame, end: match.frame };- }- if (source.kind === "segment") {- const match = snapshot.semantic.segments.find((item) => item.id === source.id);- return match === undefined ? undefined : { start: match.startFrame, end: match.endFrameExclusive };- }- return undefined;+function clipHeaderLabel(clip: StudioSnapshot["tracks"][number]["clips"][number]): string {+ return clip.presentation.shape === "text" ? clip.authoredId : clip.label;}-function sourceFrame(- snapshot: StudioSnapshot,- source: StudioTemporalLineage["source"],- endpoint: "start" | "end",-): number | undefined {- const window = sourceWindow(snapshot, source);- if (window === undefined) return undefined;- return endpoint === "start" ? window.start : window.end;+function clipBodyLabel(clip: StudioSnapshot["tracks"][number]["clips"][number]): string {+ return clip.presentation.shape === "text" ? clip.label : "";}export function createTimeline(store: Store): Timeline {const element = document.createElement("section");element.className = "timeline";+ element.style.setProperty("--timeline-item-inset-y", `${itemMetrics.insetYPx}px`);+ element.style.setProperty("--timeline-item-header-height", `${itemMetrics.headerPx}px`);+ element.style.setProperty("--timeline-content-cell-height", `${itemMetrics.contentCellPx}px`);element.innerHTML = `<div class="timeline-toolbar"><div class="timeline-tools">@@ -93,10 +96,10 @@ export function createTimeline(store: Store): Timeline {<div class="timeline-body" data-timeline-body><div class="timeline-labels" data-labels></div><div class="timeline-lanes" data-lanes>- <div class="ruler" data-ruler></div>+ <div class="ruler" data-ruler><div class="playhead-grip" data-playhead-grip></div></div><div class="lanes" data-rows></div>- <svg class="projection-overlay" data-projection aria-hidden="true"></svg>- <div class="playhead" data-playhead><div class="playhead-grip"></div></div>+ <div class="timeline-hover" data-hover aria-hidden="true"><span data-hover-time></span></div>+ <div class="playhead" data-playhead></div></div></div><div class="timeline-zoom" data-zoom></div>`;@@ -105,23 +108,18 @@ export function createTimeline(store: Store): Timeline {const lanes = element.querySelector<HTMLElement>("[data-lanes]")!;const ruler = element.querySelector<HTMLElement>("[data-ruler]")!;const rows = element.querySelector<HTMLElement>("[data-rows]")!;- const projectionOverlay = element.querySelector<SVGSVGElement>("[data-projection]")!;+ const hover = element.querySelector<HTMLElement>("[data-hover]")!;+ const hoverTime = element.querySelector<HTMLElement>("[data-hover-time]")!;const playhead = element.querySelector<HTMLElement>("[data-playhead]")!;+ const playheadGrip = element.querySelector<HTMLElement>("[data-playhead-grip]")!;const timelineTime = element.querySelector<HTMLElement>("[data-timeline-time]")!;const zoom = createZoom();element.querySelector<HTMLElement>("[data-zoom]")!.append(zoom.element);- element.querySelector<HTMLButtonElement>("[data-zoom-out]")!- .addEventListener("click", () => zoom.pinch(0.5, 1.45));- element.querySelector<HTMLButtonElement>("[data-zoom-in]")!- .addEventListener("click", () => zoom.pinch(0.5, 0.68));- element.querySelector<HTMLButtonElement>("[data-zoom-fit]")!- .addEventListener("click", () => zoom.fit());let state: State | undefined;let built = -1;let paintFrame = 0;let rebuildFrame = 0;- let projectionKey = "";let semanticLane: HTMLElement | undefined;let clipNodes: readonly {readonly node: HTMLElement;@@ -131,59 +129,167 @@ export function createTimeline(store: Store): Timeline {}[] = [];let semanticNodes: readonly {readonly node: HTMLElement;+ readonly id: string;readonly start: number;readonly end: number;readonly kind: "segment" | "word";}[] = [];+ const playheadFraction = (): number => {+ if (state === undefined) return 0.5;+ const shown = zoom.window();+ const at = state.playhead.frame / Math.max(1, state.snapshot.space.frameCount);+ return Math.max(0, Math.min(1, (at - shown.start) / Math.max(1e-6, shown.end - shown.start)));+ };+ const zoomOut = (): void => zoom.pinch(playheadFraction(), 1.25);+ const zoomIn = (): void => zoom.pinch(playheadFraction(), 0.8);+ const fit = (): void => zoom.fit();+ element.querySelector<HTMLButtonElement>("[data-zoom-out]")!.addEventListener("click", zoomOut);+ element.querySelector<HTMLButtonElement>("[data-zoom-in]")!.addEventListener("click", zoomIn);+ element.querySelector<HTMLButtonElement>("[data-zoom-fit]")!.addEventListener("click", fit);+const fps = (snapshot: StudioSnapshot): number =>snapshot.space.frameRate.numerator / snapshot.space.frameRate.denominator;+ const snapFrame = (frame: number): number => {+ if (state === undefined || lanes.clientWidth <= 0) return frame;+ const shown = zoom.window();+ const threshold = Math.max(1, Math.ceil(+ (shown.end - shown.start) * state.snapshot.space.frameCount / lanes.clientWidth * 6,+ ));+ let nearest = frame;+ let distance = threshold + 1;+ const consider = (candidate: number): void => {+ const next = Math.abs(candidate - frame);+ if (next < distance) { nearest = candidate; distance = next; }+ };+ for (const anchor of state.snapshot.semantic.anchors) consider(anchor.frame);+ for (const clip of state.snapshot.tracks.flatMap((track) => track.clips)) {+ consider(clip.startFrame);+ consider(clip.endFrameExclusive);+ }+ return distance <= threshold ? nearest : frame;+ };+const frameAt = (clientX: number): number => {const box = lanes.getBoundingClientRect();if (box.width === 0 || state === undefined) return 0;const across = Math.max(0, Math.min(1, (clientX - box.left) / box.width));const shown = zoom.window();- return Math.floor((shown.start + across * (shown.end - shown.start)) * state.snapshot.space.frameCount);+ return snapFrame(Math.floor(+ (shown.start + across * (shown.end - shown.start)) * state.snapshot.space.frameCount,+ ));};- const scrub = (event: PointerEvent): void => {- try { lanes.setPointerCapture(event.pointerId); } catch { /* pointer remains local */ }- store.seek(frameAt(event.clientX), "timeline");+ const frameTimecode = (snapshot: StudioSnapshot, frame: number): string => {+ const rate = Math.max(1, Math.round(fps(snapshot)));+ const seconds = Math.floor(frame / fps(snapshot));+ return `${String(Math.floor(seconds / 60)).padStart(2, "0")}:${String(seconds % 60).padStart(2, "0")}:${String(frame % rate).padStart(2, "0")}`;};+ let pointerArmed = false;+ let pointerDownX = 0;+ let pointerDownOnItem = false;lanes.addEventListener("pointerdown", (event) => {- if ((event.target as HTMLElement).closest(".clip, .semantic-segment, .semantic-word") !== null) return;- store.clearSelection();- scrub(event);+ pointerDownOnItem = (event.target as HTMLElement).closest(".clip, .semantic-segment, .semantic-word") !== null;+ pointerDownX = event.clientX;+ pointerArmed = true;+ try { lanes.setPointerCapture(event.pointerId); } catch { /* pointer remains local */ }+ if (!pointerDownOnItem) {+ store.clearSelection();+ store.seek(frameAt(event.clientX), "timeline");+ }});lanes.addEventListener("pointermove", (event) => {- if (event.buttons === 1 && lanes.hasPointerCapture(event.pointerId)) scrub(event);+ const frame = frameAt(event.clientX);+ const at = place(frame, state?.snapshot.space.frameCount ?? 1, zoom.window()) * lanes.clientWidth;+ hover.style.transform = `translate3d(${at}px,0,0)`;+ hoverTime.textContent = state === undefined ? "" : frameTimecode(state.snapshot, frame);+ hover.classList.add("visible");+ if (!pointerArmed || event.buttons !== 1) return;+ if (pointerDownOnItem && Math.abs(event.clientX - pointerDownX) < 3) return;+ store.seek(frame, "timeline");+ });+ const finishPointer = (event: PointerEvent): void => {+ pointerArmed = false;+ try { lanes.releasePointerCapture(event.pointerId); } catch { /* already released */ }+ };+ lanes.addEventListener("pointerup", finishPointer);+ lanes.addEventListener("pointercancel", finishPointer);+ lanes.addEventListener("pointerleave", () => {+ if (!pointerArmed) hover.classList.remove("visible");});const drawRuler = (snapshot: StudioSnapshot): void => {ruler.replaceChildren();- const step = tickSeconds(snapshot.space.durationSec, lanes.clientWidth);- for (let seconds = 0; seconds <= snapshot.space.durationSec; seconds += step) {- const at = place(seconds * fps(snapshot), snapshot.space.frameCount, zoom.window());+ const frameCount = Math.max(1, snapshot.space.frameCount);+ const shown = zoom.window();+ const visibleFrames = Math.max(1, (shown.end - shown.start) * frameCount);+ const widthPx = Math.max(1, lanes.clientWidth);+ const exactRate = Math.max(1, fps(snapshot));+ const rate = Math.max(1, Math.round(exactRate));+ const pxPerFrame = widthPx / visibleFrames;+ const pxPerSecond = pxPerFrame * exactRate;+ const startFrame = shown.start * frameCount;+ const endFrame = shown.end * frameCount;+ const startSecond = startFrame / exactRate;+ const endSecond = endFrame / exactRate;++ const context = document.createElement("span");+ context.className = "ruler-context";+ context.textContent = timecode(startSecond);+ ruler.append(context);++ const secondCandidates = [1, 2, 5, 10, 15, 30, 60, 120];+ const majorSeconds = secondCandidates.find((candidate) => candidate * pxPerSecond >= 112)+ ?? secondCandidates.at(-1)!;+ const firstSecond = Math.max(0, Math.ceil(startSecond - 1e-6));+ const lastSecond = Math.min(Math.floor(snapshot.space.durationSec), Math.floor(endSecond + 1e-6));+ for (let seconds = firstSecond; seconds <= lastSecond; seconds += 1) {+ const frame = Math.min(frameCount, Math.round(seconds * exactRate));+ const at = place(frame, frameCount, shown);if (at < 0 || at > 1) continue;+ const major = Math.abs(seconds / majorSeconds - Math.round(seconds / majorSeconds)) < 1e-6;const tick = document.createElement("span");- tick.className = `tick${at > 0.94 ? " tick-last" : ""}`;+ tick.className = `tick tick-second ${major ? "tick-major" : "tick-minor"}${at > 0.94 ? " tick-last" : ""}`;tick.style.left = `${at * 100}%`;- tick.textContent = timecode(seconds);+ tick.textContent = major && at * widthPx >= 52 ? timecode(seconds) : "";ruler.append(tick);}- for (const segment of snapshot.semantic.segments) {- const from = place(segment.startFrame, snapshot.space.frameCount, zoom.window());- const to = place(segment.endFrameExclusive, snapshot.space.frameCount, zoom.window());- if (to <= 0 || from >= 1) continue;- const marker = document.createElement("span");- marker.className = "ruler-segment";- marker.style.left = `${Math.max(0, from) * 100}%`;- marker.style.width = `${Math.max(0, Math.min(1, to) - Math.max(0, from)) * 100}%`;- marker.textContent = segment.id;- ruler.append(marker);++ const steps = frameSteps(rate);+ // A full-project ruler stays quiet. Once a second occupies enough screen+ // space, minor frame marks enter before their labels. Both densities are+ // selected from the same frame lattice, only with different pixel budgets.+ const tickStep = pxPerSecond < 120+ ? rate+ : steps.find((candidate) => candidate * pxPerFrame >= 18) ?? rate;+ const labelStep = steps.find((candidate) => candidate * pxPerFrame >= 68) ?? rate;+ const firstFrame = Math.max(0, Math.ceil(startFrame));+ const lastFrame = Math.min(frameCount, Math.floor(endFrame));+ for (let frame = firstFrame; frame <= lastFrame; frame += 1) {+ const withinSecond = ((frame % rate) + rate) % rate;+ if (withinSecond === 0) continue;+ const at = place(frame, frameCount, shown);+ if (at < 0 || at > 1) continue;+ if (withinSecond % tickStep === 0) {+ const tick = document.createElement("span");+ tick.className = `tick tick-subdivision${tickStep === 1 ? " tick-frame" : ""}`;+ tick.style.left = `${at * 100}%`;+ ruler.append(tick);+ }+ if (labelStep < rate && withinSecond % labelStep === 0 && at * widthPx >= 52) {+ const label = document.createElement("span");+ label.className = "tick-frame-label";+ label.style.left = `${at * 100}%`;+ label.textContent = frameTickLabel(withinSecond);+ ruler.append(label);+ }}+ // The ruler is sticky while tracks scroll. Keeping the grip inside it makes+ // the current-time marker remain attached to the scale instead of leaving+ // its head behind at the top of the scrolled track stack.+ ruler.append(playheadGrip);};const createTrackLabel = (@@ -191,65 +297,107 @@ export function createTimeline(store: Store): Timeline {kind: string,iconName: string,detail: string,- height = SEMANTIC_LANE_HEIGHT,+ height: number,+ attached = false,): HTMLElement => {const label = document.createElement("div");label.className = `track-label track-${kind}`;+ if (attached) label.classList.add("track-label-attached");label.style.height = `${height}px`;- label.innerHTML = `<span class="track-icon"></span><span class="track-copy"><strong></strong><small></small></span><span class="track-state"></span>`;+ label.title = `${name} · ${detail}`;+ label.innerHTML = `<span class="track-icon"></span><span class="track-copy"><strong></strong></span><span class="track-state"></span>`;setIcon(label.querySelector(".track-icon")!, iconName);label.querySelector("strong")!.textContent = name;- label.querySelector("small")!.textContent = detail;return label;};+ const attachedTracks = (+ snapshot: StudioSnapshot,+ slot: string,+ groupId?: string,+ ): readonly StudioSnapshot["tracks"][number][] => snapshot.tracks+ .filter((track) => track.binding.lane.attachedTo === slot+ && (groupId === undefined || track.binding.groupId === groupId))+ .sort((left, right) => (left.binding.lane.order ?? 0) - (right.binding.lane.order ?? 0));++ const attachmentExpanded = (+ key: string,+ attachments: readonly StudioSnapshot["tracks"][number][],+ ): boolean => !collapsedAttachmentGroups.has(key)+ && (expandedAttachmentGroups.has(key)+ || attachments.some((track) => track.binding.lane.expandedByDefault === true));++ const addAttachmentToggle = (+ label: HTMLElement,+ key: string,+ count: number,+ snapshot: StudioSnapshot,+ ): void => {+ if (count === 0) return;+ const fold = document.createElement("button");+ fold.type = "button";+ fold.className = "track-fold attachment-fold";+ const expanded = !collapsedAttachmentGroups.has(key)+ && (expandedAttachmentGroups.has(key)+ || snapshot.tracks.some((track) => {+ const slot = track.binding.lane.attachedTo;+ return slot !== undefined+ && `track:${track.binding.groupId}:${slot}` === key+ && track.binding.lane.expandedByDefault === true;+ }));+ fold.classList.toggle("expanded", expanded);+ fold.textContent = "";+ fold.title = expanded ? "Hide attached facets" : "Show attached facets";+ fold.setAttribute("aria-expanded", String(expanded));+ fold.addEventListener("click", (event) => {+ event.stopPropagation();+ if (expanded) {+ collapsedAttachmentGroups.add(key);+ expandedAttachmentGroups.delete(key);+ } else {+ collapsedAttachmentGroups.delete(key);+ expandedAttachmentGroups.add(key);+ }+ build(snapshot);+ paint();+ });+ label.querySelector(".track-state")!.append(fold);+ };+const buildSemanticLane = (snapshot: StudioSnapshot): void => {if (snapshot.semantic.segments.length === 0) {semanticLane = undefined;return;}+ const presentation = snapshot.semantic.presentation;+ const laneHeight = presentation.lane.height.preferredPx;const label = createTrackLabel(- "Speech",- "speech",- "speech",+ presentation.label ?? "Speech",+ presentation.family,+ presentation.icon,`${snapshot.semantic.segments.length} take${snapshot.semantic.segments.length === 1 ? "" : "s"}`,+ laneHeight,);- const facets = snapshot.tracks.filter((track) => track.binding.family === "speech").length;- if (facets > 0) {- const fold = document.createElement("button");- fold.type = "button";- fold.className = "track-fold speech-fold";- fold.textContent = speechExpanded ? "−" : "+";- fold.title = speechExpanded ? "Hide picture and voice facets" : "Show picture and voice facets";- fold.setAttribute("aria-expanded", String(speechExpanded));- fold.addEventListener("click", (event) => {- event.stopPropagation();- speechExpanded = !speechExpanded;- build(snapshot);- paint();- });- label.querySelector(".track-state")!.append(fold);- }+ const groupId = presentation.lane.groupId;+ const attachmentKey = groupId === undefined ? undefined : `semantic:${groupId}`;+ const facets = groupId === undefined ? [] : attachedTracks(snapshot, groupId);+ if (attachmentKey !== undefined) addAttachmentToggle(label, attachmentKey, facets.length, snapshot);labels.append(label);const lane = document.createElement("div");- lane.className = "lane semantic-lane track-speech";- lane.style.height = `${SEMANTIC_LANE_HEIGHT}px`;+ lane.className = `lane semantic-lane track-${presentation.family}`;+ lane.style.height = `${laneHeight}px`;+ lane.style.setProperty("--lane-min-height", `${presentation.lane.height.minPx}px`);+ lane.style.setProperty("--lane-max-height", `${presentation.lane.height.maxPx}px`);semanticLane = lane;+ const laneWidth = lanes.clientWidth;const tokensBySegment = new Map<string, SemanticToken[]>();for (const token of snapshot.semantic.tokens) {const held = tokensBySegment.get(token.segmentId);if (held === undefined) tokensBySegment.set(token.segmentId, [token]);else held.push(token);}- const anchorsBySegment = new Map<string, SemanticAnchor[]>();- for (const anchor of snapshot.semantic.anchors) {- const held = anchorsBySegment.get(anchor.segmentId);- if (held === undefined) anchorsBySegment.set(anchor.segmentId, [anchor]);- else held.push(anchor);- }- const nextSemanticNodes: { node: HTMLElement; start: number; end: number; kind: "segment" | "word" }[] = [];- const measured: { node: HTMLElement; label: HTMLElement; segment: boolean }[] = [];+ const nextSemanticNodes: { node: HTMLElement; id: string; start: number; end: number; kind: "segment" | "word" }[] = [];for (const segment of snapshot.semantic.segments) {const from = place(segment.startFrame, snapshot.space.frameCount, zoom.window());@@ -263,16 +411,27 @@ export function createTimeline(store: Store): Timeline {node.setAttribute("role", "button");node.dataset.semanticSegment = segment.id;node.style.left = `${visibleFrom * 100}%`;- node.style.width = `${Math.max(0, visibleTo - visibleFrom) * 100}%`;+ const segmentWidth = Math.max(0, visibleTo - visibleFrom) * 100;+ node.style.width = `max(2px, calc(${segmentWidth}% - ${itemMetrics.gapPx}px))`;node.title = `${segment.id} · ${segment.startFrame}-${segment.endFrameExclusive}f`;const segmentLabel = document.createElement("span");segmentLabel.className = "semantic-segment-label";segmentLabel.textContent = segment.id;- node.append(segmentLabel);- measured.push({ node, label: segmentLabel, segment: true });+ const visibleWidthPx = Math.max(0, visibleTo - visibleFrom) * laneWidth;+ node.classList.toggle("semantic-coarse", visibleWidthPx < 92);+ node.classList.toggle("semantic-wide", visibleWidthPx >= 140);+ node.classList.toggle("label-hidden",+ measuredText(segment.id, "500 11px -apple-system, system-ui, Segoe UI, sans-serif") + 18 > visibleWidthPx);+ const head = document.createElement("div");+ head.className = "semantic-segment-head";+ const segmentDuration = document.createElement("span");+ segmentDuration.className = "semantic-segment-duration";+ segmentDuration.textContent = `${segment.endFrameExclusive - segment.startFrame}f`;+ head.append(segmentLabel, segmentDuration);+ node.append(head);node.addEventListener("pointerdown", (event) => {- event.stopPropagation();- store.seek(segment.startFrame, "timeline");+ if ((event.target as Element).closest(".semantic-word") !== null) return;+ store.selectSemanticSegment(segment.id, "timeline");});node.addEventListener("dblclick", (event) => {event.stopPropagation();@@ -284,9 +443,9 @@ export function createTimeline(store: Store): Timeline {node.addEventListener("keydown", (event) => {if (event.key !== "Enter" && event.key !== " ") return;event.preventDefault();- store.seek(segment.startFrame, "timeline");+ store.selectSemanticSegment(segment.id, "timeline");});- nextSemanticNodes.push({ node, start: segment.startFrame, end: segment.endFrameExclusive, kind: "segment" });+ nextSemanticNodes.push({ node, id: segment.id, start: segment.startFrame, end: segment.endFrameExclusive, kind: "segment" });const words = document.createElement("div");words.className = "semantic-words";@@ -302,80 +461,70 @@ export function createTimeline(store: Store): Timeline {const clippedFrom = Math.max(visibleFrom, wordFrom);const clippedTo = Math.min(visibleTo, wordTo);word.style.left = `${Math.max(0, clippedFrom - visibleFrom) / span * 100}%`;- word.style.width = `${Math.max(0, clippedTo - clippedFrom) / span * 100}%`;+ word.style.width = `max(1px, calc(${Math.max(0, clippedTo - clippedFrom) / span * 100}% - 1px))`;word.title = `${token.text} · ${token.startFrame}-${token.endFrameExclusive}f`;const text = document.createElement("span");text.className = "semantic-word-label";text.textContent = token.text;word.append(text);- measured.push({ node: word, label: text, segment: false });- word.addEventListener("pointerdown", (event) => {- event.stopPropagation();+ const widthPx = Math.max(0, clippedTo - clippedFrom) / span * visibleWidthPx;+ word.classList.toggle("label-hidden",+ measuredText(token.text, "500 11px -apple-system, system-ui, Segoe UI, sans-serif") + 18 > widthPx);+ word.addEventListener("pointerdown", () => {+ store.selectSemanticSegment(segment.id, "timeline");store.seek(token.startFrame, "timeline");});- nextSemanticNodes.push({ node: word, start: token.startFrame, end: token.endFrameExclusive, kind: "word" });+ nextSemanticNodes.push({ node: word, id: segment.id, start: token.startFrame, end: token.endFrameExclusive, kind: "word" });words.append(word);}node.append(words);-- for (const anchor of anchorsBySegment.get(segment.id) ?? []) {- const at = place(anchor.frame, snapshot.space.frameCount, zoom.window());- if (at < from || at > to) continue;- const tick = document.createElement("span");- tick.className = `semantic-anchor semantic-anchor-${anchor.kind}`;- tick.style.left = `${(at - from) / Math.max(1e-6, to - from) * 100}%`;- node.append(tick);- }+ const selection = document.createElement("span");+ selection.className = "clip-selection";+ selection.setAttribute("aria-hidden", "true");+ node.append(selection);lane.append(node);}rows.append(lane);semanticNodes = nextSemanticNodes;- requestAnimationFrame(() => {- for (const item of measured) {- item.node.classList.toggle("label-hidden", item.label.scrollWidth + 6 > item.label.clientWidth);- if (item.segment) item.node.classList.toggle("semantic-coarse", item.node.clientWidth < 92);- }- });};const buildTrack = (snapshot: StudioSnapshot,track: StudioSnapshot["tracks"][number],nextClipNodes: { node: HTMLElement; start: number; end: number; id: string }[],+ attached = false,): void => {const kind = track.binding.family;const freeFrom: number[] = [];const rowOf = new Map<string, number>();- const roots = track.clips.filter((clip) => clip.presentation.parentId === undefined);- const childrenByParent = new Map<string, typeof track.clips>();- for (const clip of track.clips) {- const parentId = clip.presentation.parentId;- if (parentId !== undefined) childrenByParent.set(parentId, [...(childrenByParent.get(parentId) ?? []), clip]);- }- for (const clip of [...roots].sort((a, b) => b.stackOrder - a.stackOrder || a.startFrame - b.startFrame)) {+ for (const clip of [...track.clips].sort((a, b) => b.stackOrder - a.stackOrder || a.startFrame - b.startFrame)) {let row = freeFrom.findIndex((free) => free <= clip.startFrame);if (row < 0) { row = freeFrom.length; freeFrom.push(0); }freeFrom[row] = clip.endFrameExclusive;rowOf.set(clip.id, row);}- for (const clip of track.clips) {- const parentId = clip.presentation.parentId;- if (parentId !== undefined) rowOf.set(clip.id, rowOf.get(parentId) ?? 0);- }const depth = Math.max(1, freeFrom.length);const folded = depth > 1 && !opened.has(track.id);const shownRows = folded ? 1 : depth;- const laneHeight = trackLaneHeight(track);- const nestedItems = track.clips.filter((clip) => clip.presentation.parentId !== undefined).length;- const displayedItems = nestedItems > 0 ? nestedItems : track.clips.length;+ const laneHeight = track.binding.lane.height.preferredPx;+ const displayedItems = track.clips.length;const label = createTrackLabel(displayTrackName(track),kind,track.binding.icon,`${displayedItems} item${displayedItems === 1 ? "" : "s"}`,shownRows * laneHeight,+ attached,);label.classList.add(`track-facet-${track.binding.facet}`);+ const attachmentSlot = track.binding.lane.groupId;+ const attachmentKey = attachmentSlot === undefined+ ? undefined+ : `track:${track.binding.groupId}:${attachmentSlot}`;+ const attachments = attachmentSlot === undefined+ ? []+ : attachedTracks(snapshot, attachmentSlot, track.binding.groupId);+ if (attachmentKey !== undefined) addAttachmentToggle(label, attachmentKey, attachments.length, snapshot);if (depth > 1) {const fold = document.createElement("button");fold.type = "button";@@ -395,41 +544,38 @@ export function createTimeline(store: Store): Timeline {labels.append(label);const lane = document.createElement("div");- lane.className = `lane track-${kind} track-facet-${track.binding.facet}`;+ lane.className = `lane track-${kind} track-facet-${track.binding.facet}${attached ? " lane-attached" : ""}`;lane.style.height = `${shownRows * laneHeight}px`;lane.style.setProperty("--lane-height", `${laneHeight}px`);+ lane.style.setProperty("--lane-min-height", `${track.binding.lane.height.minPx}px`);+ lane.style.setProperty("--lane-max-height", `${track.binding.lane.height.maxPx}px`);+ const laneWidth = lanes.clientWidth;+ const materialMounts: {+ readonly target: HTMLElement;+ readonly preview: NonNullable<StudioSnapshot["tracks"][number]["clips"][number]["preview"]>;+ }[] = [];for (const clip of track.clips) {const from = place(clip.startFrame, snapshot.space.frameCount, zoom.window());const to = place(clip.endFrameExclusive, snapshot.space.frameCount, zoom.window());if (to <= 0 || from >= 1) continue;const row = rowOf.get(clip.id) ?? 0;if (folded && row > 0) continue;- const visibleFrom = Math.max(0, from);- const visibleTo = Math.min(1, to);const node = document.createElement("button");node.type = "button";node.className = `clip clip-${kind} clip-facet-${track.binding.facet} clip-shape-${clip.presentation.shape}`;node.dataset.clip = clip.id;- node.style.left = `${visibleFrom * 100}%`;- node.style.width = `max(2px, calc(${Math.max(0, visibleTo - visibleFrom) * 100}% - 2px))`;- const parentId = clip.presentation.parentId;- if (parentId === undefined) {- node.style.top = `${row * laneHeight}px`;- } else {- const siblings = childrenByParent.get(parentId) ?? [];- const index = Math.max(0, siblings.findIndex((candidate) => candidate.id === clip.id));- const slot = (laneHeight - 18) / Math.max(1, siblings.length);- node.classList.add("clip-nested-child");- node.style.top = `${row * laneHeight + 9 + index * slot}px`;- node.style.height = `${Math.max(3, slot - 2)}px`;- }+ node.style.left = `${from * 100}%`;+ node.style.width = `max(2px, calc(${Math.max(0, to - from) * 100}% - ${itemMetrics.gapPx}px))`;+ const widthPx = Math.max(0, to - from) * laneWidth;+ node.classList.toggle("clip-wide", widthPx >= 110);+ node.classList.toggle("clip-preview-wide", widthPx >= 92);+ node.style.top = `${row * laneHeight}px`;node.title = `${clip.label} · ${clip.startFrame}-${clip.endFrameExclusive}f`;- node.innerHTML = `<span class="clip-material" aria-hidden="true"></span><span class="clip-phases"></span><span class="clip-copy"><span class="clip-name"></span><span class="clip-meta"></span></span>`;+ node.innerHTML = `<span class="clip-head"><span class="clip-name"></span><span class="clip-meta"></span></span><span class="clip-body"><span class="clip-material" aria-hidden="true"></span><span class="clip-content"><span class="clip-content-text"></span></span><span class="clip-phases"></span></span><span class="clip-selection" aria-hidden="true"></span>`;const material = node.querySelector<HTMLElement>(".clip-material")!;- if (clip.preview?.kind === "image") {+ if (clip.preview !== undefined) {node.classList.add("clip-has-material");- material.classList.add("clip-material-image");- material.style.backgroundImage = `url(${JSON.stringify(clip.preview.url)})`;+ materialMounts.push({ target: material, preview: clip.preview });}const phaseLayer = node.querySelector<HTMLElement>(".clip-phases")!;for (const phase of clip.temporal?.phases ?? []) {@@ -440,107 +586,60 @@ export function createTimeline(store: Store): Timeline {phaseNode.style.width = `${(phase.endFrameExclusive - phase.startFrame) / Math.max(1, clip.endFrameExclusive - clip.startFrame) * 100}%`;phaseLayer.append(phaseNode);}- node.querySelector(".clip-name")!.textContent = clip.label;+ node.querySelector(".clip-name")!.textContent = clipHeaderLabel(clip);node.querySelector(".clip-meta")!.textContent = `${((clip.endFrameExclusive - clip.startFrame) / fps(snapshot)).toFixed(2)}s`;- node.addEventListener("pointerdown", (event) => {- event.stopPropagation();- if (clip.interaction.select) store.focus(frameAt(event.clientX), clip.id, "timeline");+ node.querySelector(".clip-content-text")!.textContent = clipBodyLabel(clip);+ node.addEventListener("pointerdown", () => {+ if (clip.interaction.select) store.select(clip.id, "timeline");});+ node.addEventListener("dblclick", () => store.seek(clip.startFrame, "timeline"));nextClipNodes.push({ node, start: clip.startFrame, end: clip.endFrameExclusive, id: clip.id });lane.append(node);- requestAnimationFrame(() => {- node.classList.toggle("clip-wide", node.clientWidth >= 110);- node.classList.toggle("clip-preview-wide", node.clientWidth >= 92);- });}rows.append(lane);+ for (const item of materialMounts) mountMaterialPreview(item.target, item.preview);};const build = (snapshot: StudioSnapshot): void => {labels.replaceChildren();rows.replaceChildren();- projectionOverlay.replaceChildren();- projectionKey = "";semanticNodes = [];const corner = document.createElement("div");corner.className = "label-corner";- corner.textContent = `${snapshot.space.frameCount}f`;+ corner.textContent = "";labels.append(corner);buildSemanticLane(snapshot);const nextClipNodes: { node: HTMLElement; start: number; end: number; id: string }[] = [];for (const track of snapshot.tracks) {- if (track.binding.family === "speech" && !speechExpanded) continue;+ const attachedTo = track.binding.lane.attachedTo;+ if (attachedTo !== undefined) continue;buildTrack(snapshot, track, nextClipNodes);+ const slot = track.binding.lane.groupId;+ const key = slot === undefined ? undefined : `track:${track.binding.groupId}:${slot}`;+ if (slot === undefined || key === undefined) continue;+ const attachments = attachedTracks(snapshot, slot, track.binding.groupId);+ if (!attachmentExpanded(key, attachments)) continue;+ for (const attachment of attachments) {+ buildTrack(snapshot, attachment, nextClipNodes, true);+ }}clipNodes = nextClipNodes;drawRuler(snapshot);};- const drawProjection = (current: State): void => {- const nextKey = current.selection.kind === "clip"- ? `${current.snapshot.revision}:${current.selection.clipId}:${zoom.window().start}:${zoom.window().end}:${lanes.clientWidth}:${lanes.scrollHeight}`- : `${current.snapshot.revision}:none`;- if (nextKey === projectionKey) return;- projectionKey = nextKey;- projectionOverlay.replaceChildren();- if (current.selection.kind !== "clip" || semanticLane === undefined) return;- const clip = store.clip(current.selection.clipId);- const source = clip?.temporal === undefined ? undefined : sourceWindow(current.snapshot, clip.temporal.source);- const target = clipNodes.find((item) => item.id === clip?.id)?.node;- if (source === undefined || target === undefined) return;- const width = lanes.clientWidth;- const height = Math.max(lanes.scrollHeight, lanes.clientHeight);- if (width <= 0 || height <= 0) return;- projectionOverlay.setAttribute("viewBox", `0 0 ${width} ${height}`);- projectionOverlay.setAttribute("width", String(width));- projectionOverlay.setAttribute("height", String(height));- const lanesBox = lanes.getBoundingClientRect();- const semanticBox = semanticLane.getBoundingClientRect();- const targetBox = target.getBoundingClientRect();- const sourceY = semanticBox.bottom - lanesBox.top - 5;- const targetY = targetBox.top - lanesBox.top + 4;- if (sourceY < 0 || sourceY > height || targetY < 0 || targetY > height) return;- const targetWindow = clip?.temporal?.projection ?? {- startFrame: clip?.startFrame ?? 0,- endFrameExclusive: clip?.endFrameExclusive ?? 0,- };- const endpoints = clip?.temporal?.projection === undefined ? undefined : {- start: sourceFrame(current.snapshot, clip.temporal.source, "start"),- end: sourceFrame(current.snapshot, clip.temporal.source, "end"),- };- const pairs: readonly (readonly [number, number])[] = source.start === source.end- ? [[endpoints?.start ?? source.start, targetWindow.startFrame]]- : [- [endpoints?.start ?? source.start, targetWindow.startFrame],- [endpoints?.end ?? source.end, targetWindow.endFrameExclusive],- ];- for (const [fromFrame, toFrame] of pairs) {- const fromX = place(fromFrame, current.snapshot.space.frameCount, zoom.window()) * width;- const toX = place(toFrame, current.snapshot.space.frameCount, zoom.window()) * width;- if ((fromX < 0 && toX < 0) || (fromX > width && toX > width)) continue;- const middle = sourceY + (targetY - sourceY) * 0.48;- const path = document.createElementNS("http://www.w3.org/2000/svg", "path");- path.setAttribute("class", "projection-path");- path.setAttribute("d", `M ${fromX} ${sourceY} C ${fromX} ${middle}, ${toX} ${middle}, ${toX} ${targetY}`);- projectionOverlay.append(path);- const sourcePoint = document.createElementNS("http://www.w3.org/2000/svg", "circle");- sourcePoint.setAttribute("class", "projection-point");- sourcePoint.setAttribute("cx", String(fromX));- sourcePoint.setAttribute("cy", String(sourceY));- sourcePoint.setAttribute("r", "2.5");- projectionOverlay.append(sourcePoint);- }- };-const paint = (): void => {if (state === undefined) return;const { snapshot, selection, playhead: head } = state;const position = place(head.frame, snapshot.space.frameCount, zoom.window()) * lanes.clientWidth;+ if (head.origin === "play" && position > lanes.clientWidth * 0.88 && zoom.window().end < 0.9999) {+ zoom.slide(Math.max(0.25, position / Math.max(1, lanes.clientWidth) - 0.18));+ return;+ }playhead.style.transform = `translate3d(${position}px,0,0)`;+ playheadGrip.style.transform = `translate3d(${position - 5}px,0,0)`;playhead.classList.toggle("outside", position < 0 || position > lanes.clientWidth);- const rate = Math.max(1, Math.round(fps(snapshot)));- const seconds = Math.floor(head.frame / fps(snapshot));- timelineTime.textContent = `${String(Math.floor(seconds / 60)).padStart(2, "0")}:${String(seconds % 60).padStart(2, "0")}:${String(head.frame % rate).padStart(2, "0")}`;+ playheadGrip.classList.toggle("outside", position < 0 || position > lanes.clientWidth);+ timelineTime.textContent = frameTimecode(snapshot, head.frame);for (const item of clipNodes) {const selected = selection.kind === "clip" && selection.clipId === item.id;item.node.classList.toggle("selected", selected);@@ -550,8 +649,9 @@ export function createTimeline(store: Store): Timeline {for (const item of semanticNodes) {item.node.classList.toggle("live", item.kind === "segment" && head.frame >= item.start && head.frame < item.end);item.node.classList.toggle("current", item.kind === "word" && head.frame >= item.start && head.frame < item.end);+ item.node.classList.toggle("selected", item.kind === "segment"+ && selection.kind === "semantic-segment" && selection.segmentId === item.id);}- drawProjection(state);};const schedulePaint = (): void => {@@ -573,16 +673,18 @@ export function createTimeline(store: Store): Timeline {};lanes.addEventListener("wheel", (event) => {- if (event.ctrlKey) {+ if (event.ctrlKey || event.metaKey || event.altKey) {event.preventDefault();const box = lanes.getBoundingClientRect();const at = box.width === 0 ? 0.5 : (event.clientX - box.left) / box.width;- zoom.pinch(at, Math.exp(event.deltaY * 0.01));+ zoom.pinch(at, Math.exp(event.deltaY * 0.004));return;}- if (Math.abs(event.deltaX) <= Math.abs(event.deltaY)) return;- event.preventDefault();- zoom.slide(event.deltaX / Math.max(1, lanes.clientWidth));+ if (event.shiftKey || Math.abs(event.deltaX) > Math.abs(event.deltaY)) {+ event.preventDefault();+ const delta = event.shiftKey ? event.deltaY : event.deltaX;+ zoom.slide(delta / Math.max(1, lanes.clientWidth));+ }}, { passive: false });zoom.subscribe(scheduleBuild);@@ -595,11 +697,8 @@ export function createTimeline(store: Store): Timeline {schedulePaint();});new ResizeObserver(() => {- if (state !== undefined) {- drawRuler(state.snapshot);- schedulePaint();- }- }).observe(lanes);+ if (state !== undefined) scheduleBuild();+ }).observe(element);- return { element };+ return { element, zoomIn, zoomOut, fit };}diff --git a/packages/studio/src/ui/zoom.ts b/packages/studio/src/ui/zoom.tsindex 089f002f..11a15cf4 100644--- a/packages/studio/src/ui/zoom.ts+++ b/packages/studio/src/ui/zoom.ts@@ -26,7 +26,11 @@ export type Zoom = {};/** Nothing smaller than this is readable, and nothing larger than all of it exists. */-const NARROWEST = 0.01;+// Keep a small amount of surrounding context even at maximum magnification.+// For the short-form projects Studio targets this is roughly a few hundred+// milliseconds, enough to read individual frames without turning the ruler+// into an unbounded microscope.+const NARROWEST = 0.02;export function createZoom(): Zoom {const element = document.createElement("div");diff --git a/packages/studio/start.ts b/packages/studio/start.tsindex b96f9762..fc34490d 100644--- a/packages/studio/start.ts+++ b/packages/studio/start.ts@@ -80,7 +80,11 @@ const server = await createServer({root: here,server: {port,- fs: { allow: [workspaceRoot, here] },+ // Vite resolves package assets through pnpm's real paths. The package root+ // must therefore be readable for self-hosted fonts and other declared+ // Studio dependencies, while the author workspace remains separately+ // available for Source and material previews.+ fs: { allow: [workspaceRoot, packageRoot, here] },},plugins: [studioPlugin({source,