Shared models and UI foundations
Shared models and UI foundations define the common language used by FreeCut's editor, renderer, media services, and project storage. They keep project data, transient editor state, visual rules, reusable controls, layout settings, branding, shortcuts, worker lifecycles, and translated text consistent across these higher-level systems.
Domain models
Project and composition model
The project model is the durable description of an editing job. It combines project identity with canvas settings and one or more timelines, so the editor and renderer can use the same data for editing, preview, and export. A composition can act as a main timeline or as a reusable nested composition with its own tracks, items, timing, controls, and markers. src/…/project.ts• L20-49 src/…/project.ts• L51-82 src/…/project.ts• L260-290
References: src/…/project.ts• L20-49 src/…/project.ts• L51-82 src/…/project.ts• L260-290
Timeline item model
The timeline model gives every editable layer a shared time and identity model. Items belong to tracks and carry a frame range, source relationship, transform, audio and visual settings, and optional links to media, captions, effects, or nested compositions. The discriminated item types let editor and render code treat video, audio, text, images, Lottie assets, shapes, adjustment layers, controllers, compositions, and subtitles as related but distinct kinds of content. src/…/timeline.ts• L57-172 src/…/timeline.ts• L191-234 src/…/timeline.ts• L347-474
References: src/…/timeline.ts• L57-172 src/…/timeline.ts• L191-234 src/…/timeline.ts• L347-474
Animation, text, and audio models
Animation, text, and audio types extend the common item model without changing the timeline's basic role. Keyframes describe values over frames with easing and optional links or expressions. Text types describe shared and per-span style. Audio types describe EQ settings that can be carried by clips, tracks, or the master bus. src/…/keyframe.ts• L53-72 src/…/keyframe.ts• L303-356 src/…/text.ts• L1-51 src/…/audio.ts• L1-48
Procedural motion uses compact, editable records instead of storing a large set of sampled values. This keeps motion adjustable while allowing the render side to evaluate it at the current frame. src/…/motion.ts• L18-57 src/…/motion.ts• L59-92
References: src/…/keyframe.ts• L53-72 src/…/keyframe.ts• L303-356 src/…/text.ts• L1-51 src/…/audio.ts• L1-48 src/…/motion.ts• L18-57 src/…/motion.ts• L59-92
Shared state
Playback and preview state
The playback state is the shared control point for the playhead and preview behavior. It separates committed playback position from temporary hover or scrub frames, records transport mode, loop and mute choices, proxy and preview quality choices, and carries the project-level audio bus settings used by preview and export. A small persisted subset restores user preferences without restoring an active play session. src/…/types.ts• L24-78 src/…/store.ts• L104-127 src/…/store.ts• L262-279
The preview frame is shared with timeline visuals so hover scrubbing can show a ghost playhead without changing normal playback. The shared scrub visual reads playback and selection state, maps frames to pixels, and updates its position when timeline geometry changes. src/…/timeline-preview-scrubber-visual.tsx• L31-74 src/…/timeline-preview-scrubber-visual.tsx• L95-163
References: src/…/types.ts• L24-78 src/…/store.ts• L104-127 src/…/store.ts• L262-279 src/…/timeline-preview-scrubber-visual.tsx• L31-74 src/…/timeline-preview-scrubber-visual.tsx• L95-163
Editor and selection state
Editor state holds transient workspace choices that shape the editing surface rather than the project itself. It coordinates open panels, active tabs, sidebar sizes, media skim previews, source patch controls, linked selection, and density choices. Workspace changes save the outgoing layout and stop preview playback before the new surface mounts, which keeps shared playback state from leaking across editor views. src/…/store.ts• L122-167 src/…/store.ts• L178-205
Selection state defines the active editing target and keeps item, track, marker, and transition selection mutually clear where needed. It also coordinates drag state, active tools, and keyframe-lane visibility so timeline gestures and property panels work from one shared selection contract. src/…/store.ts• L30-46 src/…/store.ts• L48-117 src/…/store.ts• L148-218
References: src/…/store.ts• L122-167 src/…/store.ts• L178-205 src/…/store.ts• L30-46 src/…/store.ts• L48-117 src/…/store.ts• L148-218
Project consistency rules
Project migration and normalization protect the boundary between stored data and current behavior. Version migrations reshape old data once, while normalization runs on every load to apply defaults, clamp values, repair unsafe overlaps, and report non-fatal warnings. This lets newer editor and render code consume a stable project shape while preserving compatibility with older projects. src/…/index.ts• L5-16 src/…/index.ts• L51-88 src/…/index.ts• L100-121
The same optional-field clamp rules are shared by project loading and the live timeline store. This keeps frame, crop, audio, pitch, fade, and EQ values within the same usable ranges regardless of where an edit enters the system. src/…/item-clamps.ts• L1-5 src/…/item-clamps.ts• L197-225
References: src/…/index.ts• L5-16 src/…/index.ts• L51-88 src/…/index.ts• L100-121 src/…/item-clamps.ts• L1-5 src/…/item-clamps.ts• L197-225
Graphics and timeline foundations
Shape geometry
The shared shape layer turns editable shape descriptions into reusable geometry. It supports common primitives and custom paths, then provides path transforms and fill geometry that can be consumed by different visual surfaces. This keeps shape behavior aligned between editing views and rendered output. src/…/shape-generators.ts• L14-23 src/…/shape-generators.ts• L46-75 src/…/index.ts• L1-9
Shape fills use one shared rule for solid and linear gradients. The rule resolves missing colors and converts an angle into normalized endpoints, so the same gradient meaning can be used by UI and rendering code. src/…/linear-gradient.ts• L12-37 src/…/linear-gradient.ts• L56-75
References: src/…/shape-generators.ts• L14-23 src/…/shape-generators.ts• L46-75 src/…/index.ts• L1-9 src/…/linear-gradient.ts• L12-37 src/…/linear-gradient.ts• L56-75
Timeline coordination
Shared timeline helpers define frame defaults, marker naming, time ranges, and the signals needed by linked timeline surfaces. They keep the main timeline and keyframe sheet aligned during fast scrubs without forcing a React render for every pointer event. src/…/defaults.ts• L1-8 src/…/main-timeline-scrub.ts• L1-25 src/…/main-timeline-scrub.ts• L27-53
Transition planning is also shared between timeline behavior and visual output. It resolves adjacent clips into transition windows, divides a transition around its cut, and reduces each side when a clip is under pressure from two transitions. A registry maps each transition ID to both UI metadata and a renderer boundary. src/…/transition-planner.ts• L13-23 src/…/transition-planner.ts• L48-57 src/…/transition-planner.ts• L102-217 src/…/registry.ts• L26-57
References: src/…/defaults.ts• L1-8 src/…/main-timeline-scrub.ts• L1-25 src/…/main-timeline-scrub.ts• L27-53 src/…/transition-planner.ts• L13-23 src/…/transition-planner.ts• L102-217 src/…/registry.ts• L26-57
Transform and media boundaries
Transform types separate authored values from resolved values. Optional transform fields allow defaults to depend on the canvas and source dimensions, while crop values stay source-relative. Parenting records preserve a layer's world pose when its relationship changes. src/…/transform.ts• L1-36 src/…/transform.ts• L38-63 src/…/transform.ts• L65-103
Media types describe both the asset and the derived data used around it. They cover storage provenance, technical metadata, thumbnails, attribution, transcripts, waveforms, decoded preview audio, and extracted animation frames. These records let media features share identity and derived results without changing the timeline item contract. src/…/storage.ts• L16-46 src/…/storage.ts• L38-145 src/…/storage.ts• L164-216
Shared media and time helpers bridge user-facing values with frame-based systems. Time helpers convert frames and seconds and format timecodes, while media helpers classify common animated image sources. src/…/time-utils.ts• L34-65 src/…/time-utils.ts• L93-122 src/…/media-utils.ts• L1-17
References: src/…/transform.ts• L1-36 src/…/transform.ts• L38-63 src/…/transform.ts• L65-103 src/…/storage.ts• L16-46 src/…/storage.ts• L38-145 src/…/storage.ts• L164-216 src/…/time-utils.ts• L34-65 src/…/time-utils.ts• L93-122 src/…/media-utils.ts• L1-17
Worker lifecycle
The managed worker utility gives background tasks a lazy, shared worker lifecycle. A caller creates the worker on first use, can inspect whether it exists, and can terminate it with its setup cleanup. Pending requests can be rejected and cleared when a worker stops, so callers do not remain blocked on work that cannot complete. src/…/managed-worker.ts• L1-24 src/…/managed-worker.ts• L26-67
References: src/…/managed-worker.ts• L1-24 src/…/managed-worker.ts• L26-67
Typography and UI foundations
Text style and layout
Typography helpers provide one style and geometry contract for text in the DOM preview, canvas paths, GPU text, and automatic sizing. Style resolution applies the same defaults and span-over-item cascade to every consumer. Text block layout then turns that resolved style into wrapped lines, baselines, alignment, and an optional background rectangle. src/…/text-style.ts• L1-9 src/…/text-style.ts• L15-60 src/…/text-block-layout.ts• L1-15 src/…/text-block-layout.ts• L311-405
Text presets turn a canvas size and a named visual recipe into reusable title, caption, badge, and card styles. Presets can produce templates with multiple text spans, while applying a preset to an existing item keeps its authored text. Font helpers load the required families and weights before a render needs them. src/…/text-style-presets.ts• L25-35 src/…/text-style-presets.ts• L515-551 src/…/text-style-presets.ts• L601-607 src/…/font-loader.ts• L162-210
References: src/…/text-style.ts• L1-9 src/…/text-style.ts• L15-60 src/…/text-block-layout.ts• L1-15 src/…/text-block-layout.ts• L311-405 src/…/text-style-presets.ts• L25-35 src/…/text-style-presets.ts• L515-551 src/…/font-loader.ts• L162-210
Reusable controls
The reusable UI layer supplies the common interaction language for panels and dialogs. Base controls wrap accessible primitives for buttons, dialogs, menus, tabs, inputs, overlays, and popovers. Shared property controls add editor-specific behavior such as labeled numeric editing, mixed values, keyboard steps, wheel changes, and drag scrubbing. src/…/button.tsx• L8-21 src/…/dialog.tsx• L27-60 src/…/popover.tsx• L8-36 src/…/index.ts• L1-6 src/…/number-input.tsx• L31-38
Popovers share a portaled surface with standard placement, offset, focus, border, shadow, and open/close motion. This gives menus and contextual panels a common visual and layering contract without making each caller manage the overlay boundary. src/…/popover.tsx• L12-34
Property sections give related controls a shared collapse pattern. A shift action can open or close all mounted sections, which supports dense editor panels without adding separate state coordination to each feature. src/…/property-section.tsx• L13-22 src/…/property-section.tsx• L23-76
References: src/…/button.tsx• L8-21 src/…/dialog.tsx• L27-60 src/…/popover.tsx• L8-36 src/…/index.ts• L1-6 src/…/number-input.tsx• L31-38 src/…/property-section.tsx• L13-22 src/…/property-section.tsx• L23-76
Branding and visual theme
Branding provides a single FreeCut identity for application surfaces. The logo supports icon-only and full wordmark forms with shared size choices, so navigation and landing surfaces can use the same mark without copying its geometry. src/…/freecut-logo.tsx• L3-25 src/…/freecut-logo.tsx• L38-51
The global theme establishes the dark editor surface, orange primary action color, panel layers, timeline contrast, focus tokens, spacing radius, and motion easing tokens. Tailwind names and CSS variables point to the same values, which keeps shared controls and feature-specific surfaces visually aligned. src/index.css• L15-24 src/index.css• L26-83 src/index.css• L163-203
References: src/…/freecut-logo.tsx• L3-25 src/…/freecut-logo.tsx• L38-51 src/index.css• L15-24 src/index.css• L26-83 src/index.css• L163-203
Configuration and localization
Editor configuration
Configuration separates product-level editor choices from project content. Workspace presets choose which panels and tabs are active for edit, color, and motion work, while density settings define the shared geometry and CSS values used by the shell and timeline. Persisted workspace changes are treated as user layout preferences rather than project data. src/…/editor-workspaces.ts• L1-10 src/…/editor-workspaces.ts• L31-64 src/…/editor-layout.ts• L10-62 src/…/editor-layout.ts• L64-126
The editor store uses these configuration rules to validate persisted workspace layouts and keep sidebar sizes within usable bounds. This gives user preferences a safe fallback when a saved value is old or invalid. src/…/editor-workspaces.ts• L102-124 src/…/editor-layout.ts• L154-195
Keyboard shortcuts
Keyboard configuration gives editor actions one cross-platform command map. It defines default bindings and descriptions for playback, timeline editing, tools, project actions, markers, keyframes, and source edits. The mod token means Command on macOS and Control on Windows or Linux. src/…/hotkeys.ts• L8-98 src/…/hotkeys.ts• L283-373
The same boundary supports user overrides and portable presets. Bindings are normalized across aliases and modifier order, invalid or duplicate-free overrides are filtered, conflicts can be found before use, and export/import keeps command identity with a versioned schema. Browser-hostile bindings are also identified so the app can avoid actions that the browser may capture. src/…/hotkeys.ts• L402-409 src/…/hotkeys.ts• L500-570 src/…/hotkeys.ts• L686-720 src/…/hotkeys.ts• L722-741 src/…/hotkeys.ts• L817-900
References: src/…/editor-workspaces.ts• L1-10 src/…/editor-workspaces.ts• L31-64 src/…/editor-layout.ts• L10-62 src/…/editor-layout.ts• L64-126 src/…/editor-workspaces.ts• L102-124 src/…/editor-layout.ts• L154-195 src/…/hotkeys.ts• L8-98 src/…/hotkeys.ts• L283-373 src/…/hotkeys.ts• L402-409 src/…/hotkeys.ts• L500-570 src/…/hotkeys.ts• L686-720 src/…/hotkeys.ts• L722-741 src/…/hotkeys.ts• L817-900
Localization
Localization gives the application a supported language set with a stable code, a user-facing native name, an English name for discovery, and text direction. Locale resolution maps browser or stored language values to a supported code and falls back to English when needed. src/…/languages.ts• L8-35 src/…/languages.ts• L41-54
The i18n layer merges English partial resources into the complete default tree and loads other language base files and partials when needed. It detects and persists the user's language, preloads it before the first render, and updates the document language attribute after a change. The language switcher exposes this behavior through a shared menu used by the application shell. src/…/index.ts• L14-74 src/…/index.ts• L111-150 src/…/language-switcher.tsx• L24-73
References: src/…/languages.ts• L8-35 src/…/languages.ts• L41-54 src/…/index.ts• L14-74 src/…/index.ts• L111-150 src/…/language-switcher.tsx• L24-73
Change checklist
When these files or sections are changed, remember to consider these:
- Update every consumer when a persisted project field changes. Project types, migration rules, normalization, timeline state, and composition inputs must continue to agree.
- Keep frame and second conversions aligned with the active FPS. A mismatch can shift markers, captions, transitions, or scrub previews without a type error.
- Preserve the distinction between project audio gain and per-device monitor gain. The first affects preview and export. The second affects preview only.
- When adding a text style field or default, update style resolution and the shared text block layout before changing an individual renderer.
- When changing a workspace or density value, check both persisted layout normalization and the CSS variables consumed by the editor surfaces.
- When changing a popover's placement, portal, or visual contract, check menus and contextual panels that depend on its shared overlay behavior.
- When changing a hotkey command, update its default binding, description, import aliases, conflict behavior, and export schema expectations together.
- When adding a locale or resource slice, update the supported language list and the matching base or partial resource path so detection, preload, and language switching use the same code.
- When changing worker shutdown behavior, reject pending requests before callers lose the worker that owns them.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A stored project skips or fails a needed migration | Current editor or render code receives an old data shape | migrateProject applies version steps in order and reports the source and target versions. src/…/index.ts• L51-88 |
| A new optional timeline field is clamped in only one load path | Live edits and reopened projects use different values | Register the rule in the shared optional clamp table used by both normalizers. src/…/item-clamps.ts• L1-5 |
| A clip participates in two transitions whose windows exceed its duration | Transition windows consume invalid or overlapping clip time | The transition planner solves incoming and outgoing pressure before producing windows. src/…/transition-planner.ts• L163-181 |
| Text renderers resolve defaults independently | Preview, export, and GPU text can wrap or align differently | Resolve style and block geometry through the shared typography helpers. src/…/text-style.ts• L1-9 src/…/text-block-layout.ts• L311-405 |
| A persisted workspace contains an unknown tab or invalid flag | The editor can open with a broken or unusable panel layout | Workspace layout normalization falls back per field to the active workspace preset. src/…/editor-workspaces.ts• L102-124 |
| A custom shortcut has no primary key or conflicts with another command | The shortcut is ignored or makes one of the commands unreachable | Normalize and validate overrides, then use conflict detection before applying them. src/…/hotkeys.ts• L538-570 src/…/hotkeys.ts• L707-720 |
| A requested locale has no matching resource or partial load fails | The interface can show missing text or render before the selected language is ready | Resolve to a supported code, preload the selected resources, and keep English as the fallback. src/…/index.ts• L111-148 |
| A worker terminates while requests remain pending | Callers wait forever for results from a stopped worker | Reject and clear pending requests as part of the worker shutdown path. src/…/managed-worker.ts• L12-24 |
Key files
| File | Why to read it |
|---|---|
| src/…/project.ts | Defines the durable project, timeline, composition, and canvas relationships. |
| src/…/timeline.ts | Defines the shared item and track language used by editing and rendering. |
| src/…/keyframe.ts | Defines animated properties, easing, vector lanes, and property links. |
| src/…/storage.ts | Defines media identity and the derived records shared by media workflows. |
| src/…/index.ts | Shows how stored projects become current project data. |
| src/…/normalize.ts | Shows the load-time defaults, range checks, and overlap repair rules. |
| src/…/store.ts | Shows how playhead, scrub, preview, and persisted playback preferences meet. |
| src/…/store.ts | Shows how editor-only layout and workspace state is coordinated. |
| src/…/store.ts | Shows the selection contract shared by timeline and property surfaces. |
| src/…/transition-planner.ts | Shows how clip relationships become safe transition windows. |
| src/…/shape-generators.ts | Shows the shared geometry source for native editable shapes. |
| src/…/text-style.ts | Shows the common text defaults and style cascade. |
| src/…/text-block-layout.ts | Shows the shared text wrapping and box geometry contract. |
| src/…/number-input.tsx | Shows the editor-specific number input interaction model. |
| src/…/popover.tsx | Shows the shared portaled overlay contract for contextual UI. |
| src/…/hotkeys.ts | Defines default shortcuts and the portable override format. |
| src/…/managed-worker.ts | Defines the common lazy worker and pending-request shutdown boundary. |
| src/index.css | Defines the global dark theme and the CSS tokens used by shared UI. |
| src/…/editor-workspaces.ts | Defines workspace intent and safe persisted layout values. |
| src/…/index.ts | Defines locale merge, lazy loading, detection, preload, and fallback behavior. |