@molecule/app-feature-track-lane-svelte

Feature · track-lane · App (browser) · v1.2.1 · Apache-2.0

Horizontal track lane primitive for music-DAW, video-editor, animation-tool — a single row in a multi-track timeline rendering draggable/resizable clips on a time-base axis

npm install @molecule/app-feature-track-lane-svelte

npm · Source on GitHub

How it works

@molecule/app-feature-track-lane-svelte is a ready-made track-lane feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

<script lang="ts">
  import { TrackLane, type Clip } from '@molecule/app-feature-track-lane-svelte'

  let selected = $state<string>()
  const clips: Clip[] = [
    { id: 'a', startTime: 0, duration: 2, color: '#0af', label: 'Kick' },
    { id: 'b', startTime: 4, duration: 1.5, label: 'Snare' },
  ]
</script>

<TrackLane
  name="Drums"
  {clips}
  pixelsPerSecond={20}
  selectedClipId={selected}
  onClipClick={(clipId) => (selected = clipId)}
/>

Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte

Reference

Svelte horizontal track-lane primitive for multi-track timelines (music DAW, video editor, animation tool). Renders one lane row of draggable + resizable clip blocks on a pixelsPerSecond time axis.

Svelte counterpart of @molecule/app-feature-track-lane-react: the same props (React names), the same DOM for the same input, and the same callback calls, so an app switches framework by changing only the package name it imports.

Exports <TrackLane> and the Clip type, plus the pure-function helpers clipToPixels, pixelsToTime and clampClipMove that back the pointer-event drag/resize math.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

<script lang="ts">
  import { TrackLane, type Clip } from '@molecule/app-feature-track-lane-svelte'

  let selected = $state<string>()
  const clips: Clip[] = [
    { id: 'a', startTime: 0, duration: 2, color: '#0af', label: 'Kick' },
    { id: 'b', startTime: 4, duration: 1.5, label: 'Snare' },
  ]
</script>

<TrackLane
  name="Drums"
  {clips}
  pixelsPerSecond={20}
  selectedClipId={selected}
  onClipClick={(clipId) => (selected = clipId)}
/>

Type

feature

Installation

npm install @molecule/app-feature-track-lane-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte

API

Interfaces

Clip

A single clip block on a track lane. startTime and duration are both in seconds; pixelsPerSecond on the lane converts them to the on-screen geometry. id is a stable identifier used as the row key and as the argument passed back to all event handlers. color accents the body fill (defaults to a neutral surface) and label is rendered inside the clip when given.

interface Clip {
  /** Stable identifier for the clip (used as the row key + handler arg). */
  id: string
  /** Clip start time on the lane in seconds. */
  startTime: number
  /** Clip duration in seconds. Always positive — minimum is enforced. */
  duration: number
  /** Optional accent color for the clip body (any valid CSS color). */
  color?: string
  /** Optional inline label rendered on top of the clip body (a snippet or text). */
  label?: string | number | Snippet
}

TrackLaneProps

Props accepted by the TrackLane component — the same props React's TrackLane accepts. A node-valued prop is a snippet (or plain text).

interface TrackLaneProps {
  /** Optional lane name shown in the leading lane header. */
  name?: string | number | Snippet
  /** Clips on this lane. Order is preserved as-is. */
  clips: Clip[]
  /** Horizontal time scale, defaults to 20. */
  pixelsPerSecond?: number
  /**
   * Optional opaque lane identifier. Forwarded to handlers and emitted as
   * `data-lane` so multi-lane parents can tell lanes apart.
   */
  lane?: string
  /** Lane row height in pixels. Defaults to 44. */
  height?: number
  /** Called when a clip is dragged horizontally. */
  onClipMove?: (clipId: string, startTime: number, lane?: string) => void
  /** Called when a clip's right edge handle is dragged. */
  onClipResize?: (clipId: string, duration: number, lane?: string) => void
  /** Called when a clip body is clicked (no drag). */
  onClipClick?: (clipId: string, lane?: string) => void
  /** Currently-selected clip id (renders the selection ring on that clip). */
  selectedClipId?: string
  /** Extra classes merged onto the root element. */
  className?: string
}

Functions

clipToPixels(clip, pixelsPerSecond)

Convert a clip to its on-lane pixel geometry.

function clipToPixels(
  clip: { startTime: number; duration: number },
  pixelsPerSecond: number,
): { left: number; width: number }
  • clip — The clip to project (startTime + duration in seconds).
  • pixelsPerSecond — Horizontal scale; zero or negative falls back to 1.

Returns: { left, width } in pixels.

pixelsToTime(pixels, pixelsPerSecond)

Convert a pixel offset back to a time value, clamped to >= 0.

function pixelsToTime(pixels: number, pixelsPerSecond: number): number
  • pixels — Offset in pixels.
  • pixelsPerSecond — Horizontal scale; zero or negative falls back to 1.

Returns: Time in seconds (never negative).

clampClipMove(proposedStartTime)

Clamp the proposed new startTime for a clip move so the clip stays non-negative. (No upper bound — the parent decides whether to clip to a song length.)

function clampClipMove(proposedStartTime: number): number
  • proposedStartTime — The candidate start time in seconds.

Returns: The clamped start time.

Constants

TrackLane

const TrackLane: LegacyComponentType

MIN_CLIP_DURATION_SECONDS

Minimum clip duration in seconds — clips can't be resized below this.

const MIN_CLIP_DURATION_SECONDS: 0.05

DRAG_DISTANCE_THRESHOLD_PX

Pointer-distance threshold (px) before a press becomes a drag.

const DRAG_DISTANCE_THRESHOLD_PX: 3

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-svelte ^3.5.0 || ^4.0.0
  • @molecule/app-ui ^1.9.0
  • @molecule/app-ui-svelte ^1.5.0
  • svelte ^5.0.0

Runtime Dependencies

  • @molecule/app-svelte

  • @molecule/app-ui

  • @molecule/app-ui-svelte

  • svelte

  • Requires a bonded ClassMap (cm.flex, cm.cn, …) — rendering throws otherwise. No router dependency.

  • Every visible string comes from useTranslation() (trackLane.aria.* and trackLane.header), so a locale switch re-renders it.

  • Node-valued props (name, a clip's label) are snippets (or plain text).

Translations

Translation strings are provided by @molecule/app-locales-feature-track-lane.