Skip to content

armgit / hypit

Public Imported from GitHub
0

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

refactor: record studio state and consolidate timeline attachments

kashorina010b404bc0f
diff --git a/packages/studio-adapter/src/index.ts b/packages/studio-adapter/src/index.ts
index 24068184..f0f46ca6 100644
--- a/packages/studio-adapter/src/index.ts
+++ b/packages/studio-adapter/src/index.ts
@@ -137,7 +137,6 @@ export type StudioLaneDescription = {
readonly groupId?: string;
readonly attachedTo?: string;
readonly order?: number;
- readonly expandedByDefault?: boolean;
};
export type StudioInspectorSection =
diff --git a/packages/studio-video-adapters/src/ranking.ts b/packages/studio-video-adapters/src/ranking.ts
index 2e456e03..6c5a1a8c 100644
--- a/packages/studio-video-adapters/src/ranking.ts
+++ b/packages/studio-video-adapters/src/ranking.ts
@@ -149,7 +149,6 @@ export const rankingAdapters: readonly StudioAdapter[] = [
lane: {
layout: "flat",
height: { minPx: 34, preferredPx: 40, maxPx: 56 },
- expandedByDefault: true,
},
parameters: [
{ name: "during", label: "During", writable: false },
diff --git a/packages/studio/src/style.css b/packages/studio/src/style.css
index e275109f..8d622449 100644
--- a/packages/studio/src/style.css
+++ b/packages/studio/src/style.css
@@ -50,7 +50,7 @@
--caption-rail: #ea93e8;
--visual: #6a737c;
--visual-rail: #aeb9c4;
- --timeline-label-width: 152px;
+ --timeline-label-width: 188px;
--source-width: 350px;
--workspace-width: 300px;
--timeline-height: 390px;
@@ -58,7 +58,8 @@
--timeline-selection-stroke: 1px;
--timeline-selection-edge: 3px;
--timeline-selection-radius: 3px;
- --timeline-selection-color: rgba(228, 231, 236, .68);
+ /* Original selection geometry; only the highlight is intentionally brighter. */
+ --timeline-selection-color: rgba(255, 255, 255, .92);
--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
@@ -485,7 +486,7 @@ button:focus-visible, textarea:focus-visible {
flex: 1;
min-height: 0;
display: grid;
- grid-template-columns: var(--timeline-label-width) minmax(0, 1fr);
+ grid-template-columns: var(--timeline-label-width) 8px minmax(0, 1fr);
overflow-x: hidden;
overflow-y: auto;
overscroll-behavior: contain;
@@ -519,10 +520,11 @@ button:focus-visible, textarea:focus-visible {
min-width: 0;
min-height: 0;
display: grid;
- grid-template-columns: 18px minmax(0, 1fr) 18px;
+ grid-template-columns: 18px minmax(0, 1fr);
align-items: center;
gap: 7px;
padding: 0 15px;
+ text-align: left;
border-bottom: 0;
background: transparent;
isolation: isolate;
@@ -539,14 +541,44 @@ button:focus-visible, textarea:focus-visible {
.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 { text-align: left; justify-self: stretch; }
.track-copy strong {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
+ text-align: left;
}
.track-copy strong { color: #cfd2d8; font-size: 11px; font-weight: 500; line-height: 18px; }
+.track-label-has-state { grid-template-columns: 18px minmax(0, 1fr) 18px; }
.track-state { display: grid; place-items: center; }
+.track-attachment-mark {
+ position: relative;
+ width: 18px;
+ height: 18px;
+ justify-self: center;
+}
+.track-attachment-mark::before,
+.track-attachment-mark::after {
+ content: "";
+ position: absolute;
+ pointer-events: none;
+ background: #737985;
+ border-radius: 999px;
+}
+.track-attachment-mark::before {
+ top: 1px;
+ bottom: 50%;
+ left: 7px;
+ width: 1.5px;
+}
+.track-attachment-mark::after {
+ top: 50%;
+ left: 7px;
+ width: 6px;
+ height: 1.5px;
+ transform: translateY(-50%);
+}
.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); }
@@ -717,32 +749,12 @@ button:focus-visible, textarea:focus-visible {
line-height: 17px;
}
.track-label-attached {
+ /* The branch marker occupies the same 18px prefix as a root icon;
+ attached and root labels therefore share one exact text column. */
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); }
.clip {
--track: var(--visual);
--item-head: color-mix(in srgb, var(--track) 58%, var(--lane));
diff --git a/packages/studio/src/ui/timeline.ts b/packages/studio/src/ui/timeline.ts
index 86b8e651..1132df4e 100644
--- a/packages/studio/src/ui/timeline.ts
+++ b/packages/studio/src/ui/timeline.ts
@@ -6,6 +6,7 @@ import type { StudioEditSource } from "@hypit/studio-adapter";
import { icon, setIcon } from "./icons.js";
import { mountMaterialPreview } from "./material-preview.js";
import type { State, Store } from "./selection.js";
+import { createHandle } from "./resize.js";
import { createZoom } from "./zoom.js";
import { writeSourceTransaction } from "./writeback.js";
@@ -17,8 +18,6 @@ export type Timeline = {
};
const opened = new Set<string>();
-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,
@@ -107,6 +106,7 @@ export function createTimeline(store: Store): Timeline {
<div class="timeline-zoom" data-zoom></div>`;
const labels = element.querySelector<HTMLElement>("[data-labels]")!;
+ const body = element.querySelector<HTMLElement>("[data-timeline-body]")!;
const lanes = element.querySelector<HTMLElement>("[data-lanes]")!;
const ruler = element.querySelector<HTMLElement>("[data-ruler]")!;
const rows = element.querySelector<HTMLElement>("[data-rows]")!;
@@ -118,6 +118,26 @@ export function createTimeline(store: Store): Timeline {
const zoom = createZoom();
element.querySelector<HTMLElement>("[data-zoom]")!.append(zoom.element);
+ // The label column is part of the timeline's reading surface, not a fixed
+ // application chrome width. Keep enough room for the longest built-in
+ // facet name while leaving a usable canvas, and remember the author's choice.
+ const labelHandle = createHandle({
+ axis: "column",
+ initial: 188,
+ minimum: 156,
+ // createTimeline is constructed before it is attached to the document, so
+ // clientWidth is initially zero. Keep the preferred default valid during
+ // that first pass; on a real viewport the canvas-aware ceiling applies,
+ // with 260px as the hard visual cap on a wide timeline.
+ maximum: () => Math.min(260, Math.max(188, body.clientWidth - 360)),
+ apply: (size) => { element.style.setProperty("--timeline-label-width", `${size}px`); },
+ remember: "hypit-studio.v4.timeline-label-width",
+ });
+ labelHandle.classList.add("timeline-label-handle");
+ labelHandle.setAttribute("aria-label", "Resize timeline track labels");
+ labelHandle.title = "Resize track labels";
+ body.insertBefore(labelHandle, lanes);
+
let state: State | undefined;
let built = -1;
let paintFrame = 0;
@@ -357,14 +377,19 @@ export function createTimeline(store: Store): Timeline {
detail: string,
height: number,
attached = false,
+ hasState = false,
): HTMLElement => {
const label = document.createElement("div");
- label.className = `track-label track-${kind}`;
+ label.className = `track-label track-${kind}${hasState ? " track-label-has-state" : ""}`;
if (attached) label.classList.add("track-label-attached");
label.style.height = `${height}px`;
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.innerHTML = `${attached
+ ? '<span class="track-attachment-mark" aria-hidden="true"></span>'
+ : '<span class="track-icon"></span>'}<span class="track-copy"><strong></strong></span>${hasState
+ ? '<span class="track-state"></span>'
+ : ""}`;
+ if (!attached) setIcon(label.querySelector(".track-icon")!, iconName);
label.querySelector("strong")!.textContent = name;
return label;
};
@@ -378,50 +403,6 @@ export function createTimeline(store: Store): Timeline {
&& (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) {
return;
@@ -440,10 +421,6 @@ export function createTimeline(store: Store): Timeline {
laneHeight,
);
label.classList.add("track-label-semantic");
- 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");
@@ -621,16 +598,9 @@ export function createTimeline(store: Store): Timeline {
`${displayedItems} item${displayedItems === 1 ? "" : "s"}`,
shownRows * laneHeight,
attached,
+ depth > 1,
);
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";
@@ -747,10 +717,8 @@ export function createTimeline(store: Store): Timeline {
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;
+ if (slot === 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);
}
@@ -836,9 +804,11 @@ export function createTimeline(store: Store): Timeline {
}
schedulePaint();
});
- new ResizeObserver(() => {
+ const resizeObserver = new ResizeObserver(() => {
if (state !== undefined) scheduleBuild();
- }).observe(element);
+ });
+ resizeObserver.observe(element);
+ resizeObserver.observe(lanes);
return { element, zoomIn, zoomOut, fit };
}