npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

svelte-interactive-timeline

v0.1.0

Published

A canvas-based interactive timeline component for Svelte 5 with zoom, pan, and pluggable rendering layers

Readme

svelte-interactive-timeline

A reusable timeline component library for Svelte 5 with canvas rendering.

Features

  • Canvas-based rendering for smooth performance
  • Svelte 5 runes for modern reactivity
  • Customizable colors, layout, and layers
  • Interactive - click to seek, drag to scrub, drag to zoom, scroll to pan
  • DaisyUI compatible styling
  • TypeScript support

Installation

npm install svelte-interactive-timeline

Quick Start

<script lang="ts">
  import { Timeline, createTimelineStore } from 'svelte-interactive-timeline';

  const store = createTimelineStore();
</script>

<Timeline
  {store}
  endTime={120}
  height={80}
  onTimeChange={(time) => console.log('Time:', time)}
/>

Components

Timeline

The main container component with canvas and controls.

<Timeline
  {store}
  endTime={120}
  startTime={0}
  height={80}
  showControls={true}
  showZoomControls={true}
  showTimeDisplay={true}
  timeFormat="hms"
  embedded={false}
  colors={customColors}
  layout={customLayout}
  layers={customLayers}
  onTimeChange={(time) => {}}
  onViewChange={(start, end) => {}}
  onPlayheadDragStart={() => {}}
  onPlayheadDragEnd={() => {}}
/>

TimelineCanvas

Just the canvas for custom layouts.

<TimelineCanvas
  {store}
  colors={customColors}
  layout={customLayout}
  layers={customLayers}
  onTimeChange={(time) => {}}
  onViewChange={(start, end) => {}}
/>

TimelineControls

Just the controls bar for custom layouts.

<TimelineControls
  {store}
  showZoomControls={true}
  showTimeDisplay={true}
  timeFormat="hms"
  onZoom={() => {}}
/>

Store

Create a timeline store to manage state:

import { createTimelineStore } from 'svelte-interactive-timeline';

const store = createTimelineStore({
  minZoomDuration: 1, // Minimum 1 second when zoomed in
  minZoomSelectionThreshold: 0.5 // Minimum selection to apply zoom
});

// Initialize with duration
store.initialize(120); // 120 seconds

// Programmatic control
store.setCurrentTime(30);
store.zoom(0.5); // Zoom in
store.zoom(2); // Zoom out
store.zoomToFit(); // Reset zoom
store.pan(10); // Pan by 10 seconds
store.setView(10, 60); // Set view window

// Read state (reactive)
console.log(store.currentTime);
console.log(store.viewStart, store.viewEnd);
console.log(store.isZoomed);
console.log(store.zoomLevel);

Customization

Custom Colors

import { createColorScheme } from 'svelte-interactive-timeline';

const customColors = createColorScheme({
  accent: '#3b82f6', // Blue playhead
  accentLight: '#60a5fa',
  accentGlow: 'rgba(59, 130, 246, 0.4)',
  zoomFill: 'rgba(16, 185, 129, 0.15)',
  zoomStroke: 'rgba(16, 185, 129, 0.6)'
});

Custom Layout

import { createLayoutConfig } from 'svelte-interactive-timeline';

const customLayout = createLayoutConfig({
  playheadHeadHeight: 18,
  playheadHeadWidth: 16,
  playheadLineWidth: 3,
  labelFontSize: 11,
  playheadHitTolerance: 12
});

Custom Layers

Add custom rendering layers:

import type { RenderLayer, RenderContext } from 'svelte-interactive-timeline';
import {
  BackgroundLayer,
  PlayheadLayer,
  HoverLayer,
  ZoomSelectionLayer
} from 'svelte-interactive-timeline';

class MarkersLayer implements RenderLayer {
  name = 'markers';
  visible = true;
  markers: number[] = [];

  constructor(markers: number[]) {
    this.markers = markers;
  }

  render(ctx: RenderContext): void {
    const { ctx: c, height, timeToX } = ctx;

    for (const marker of this.markers) {
      const x = timeToX(marker);
      if (x < 0 || x > ctx.width) continue;

      c.fillStyle = '#10b981';
      c.beginPath();
      c.arc(x, 6, 4, 0, Math.PI * 2);
      c.fill();
    }
  }
}

const customLayers = [
  new BackgroundLayer(),
  new MarkersLayer([10, 30, 60]),
  new PlayheadLayer(),
  new ZoomSelectionLayer(),
  new HoverLayer()
];

Interactions

| Interaction | Action | |-------------|--------| | Click | Seek to time | | Drag playhead | Scrub through time | | Drag on track | Zoom to selection | | Scroll (horizontal) | Pan view | | Ctrl/Cmd + Scroll | Zoom at cursor | | Alt + Drag | Pan view | | Middle click + Drag | Pan view |

API Reference

Types

type DragTarget = 'playhead' | 'pan' | 'zoom-region' | null;
type HitTarget = 'playhead' | 'track' | 'empty';

interface TimelineState {
  dataStart: number;
  dataEnd: number;
  viewStart: number;
  viewEnd: number;
  currentTime: number;
  leftX: number;
  rightX: number;
  hoveredTime: number | null;
  isDragging: DragTarget;
  zoomSelectionStart: number | null;
  zoomSelectionEnd: number | null;
}

interface RenderContext {
  ctx: CanvasRenderingContext2D;
  state: TimelineState;
  width: number;
  height: number;
  dpr: number;
  timeToX: (time: number) => number;
  xToTime: (x: number) => number;
}

interface RenderLayer {
  name: string;
  visible: boolean;
  render(ctx: RenderContext): void;
}

Utilities

import {
  clamp,
  mapRange,
  formatTime,
  calculateGridInterval,
  generateGridLines,
  zoomAtPoint,
  panView,
  getDevicePixelRatio
} from 'svelte-interactive-timeline';

License

MIT