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

@composy/timeline-core

v0.0.1

Published

Timeline core - Canvas/SVG rendering, layout, animation, interaction

Readme

@composy/timeline-core

@composy/timeline-core 是时间轴的框架无关核心包,负责事件模型、布局计算、Canvas/SVG 渲染、缩放平移、选择、主题、导出和插件能力。

安装

pnpm add @composy/timeline-core

基础用法

import { createTimeline, type TimelineEvent } from '@composy/timeline-core'

const events: TimelineEvent[] = [
  {
    id: 'plan',
    title: '计划',
    date: '2026-01-01',
    description: '项目计划完成',
    color: 'var(--ld-primary-600)',
  },
  {
    id: 'release',
    title: '发布',
    timestamp: 1773532800000,
    color: 'var(--ld-success-600)',
  },
]

const timeline = createTimeline({
  container: document.querySelector('#timeline') as HTMLElement,
  events,
  renderType: 'canvas',
  orientation: 'horizontal',
  width: 900,
  height: 420,
})

timeline.zoomIn()
timeline.centerOn('release')
timeline.download('timeline.png', 'png')

事件数据

TimelineEvent 支持面向用户的日期别名,也兼容时间戳字段:

import type { TimelineEvent } from '@composy/timeline-core'

const event: TimelineEvent = {
  id: 'range',
  title: '范围事件',
  date: '2026-01-01',
  endDate: '2026-01-10',
  group: 'milestone',
  data: {
    owner: 'team-a',
  },
}

常用字段:

  • date / timestamp:事件开始时间,支持 Date | string | number。
  • endDate / endTime:范围事件结束时间。
  • group / groupId:事件分组。
  • color:推荐使用 var(--ld-*) 或 var(--color-*)。
  • data:业务扩展数据,类型为 Record<string, unknown>。

核心 API

  • createTimeline(config):创建时间轴实例。
  • generateTimeline(container, config):在指定容器中创建时间轴实例。
  • addEvent(event) / removeEvent(id) / updateEvent(id, event):事件增删改。
  • getEvents() / getEvent(id) / searchEvents(query):事件查询。
  • zoomIn() / zoomOut() / setZoom(level) / fit():视图缩放。
  • panTo(x, y) / centerOn(eventId):平移与定位。
  • setSelection(ids) / getSelection() / clearSelection():选择管理。
  • setTheme(name) / registerTheme(theme):主题管理。
  • toDataURL() / toSVGString() / export() / download():导出能力。
  • on(event, handler):订阅事件,返回取消订阅函数。

主题与 token

内置主题为 light、dark、minimal、colorful。默认主题值全部使用 LDesign CSS 变量:

  • 颜色使用 --ld-*,并兼容 --color-*。
  • 尺寸应由消费方容器或 Vue 适配层通过 --size-* 控制。
  • Canvas/SVG 渲染前会把 CSS 变量解析为实际颜色,避免 var(...) 直接写入 Canvas 导致绘制失败。

DOM class

core 内置 SVG 和 Canvas tooltip 只输出 ldesign-timeline 命名空间 class:

  • .ldesign-timeline__tooltip
  • .ldesign-timeline__main
  • .ldesign-timeline__grid
  • .ldesign-timeline__grid-line
  • .ldesign-timeline__scale
  • .ldesign-timeline__scale-label
  • .ldesign-timeline__today
  • .ldesign-timeline__event
  • .ldesign-timeline__event--highlighted

构建产物

pnpm -C libraries/timeline/packages/core run type-check
pnpm -C libraries/timeline/packages/core run build

构建完成后会生成:

dist/index.js
dist/index.min.js
es/index.js
esm/index.js
lib/index.cjs

License

MIT