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

@sketchjs/runtime

v0.1.2

Published

Sketch 运行时核心,提供画布渲染、节点树管理与 Yoga 布局能力。适合在纯 H5 环境中直接使用,也可作为框架封装的基础。

Readme

@sketchjs/runtime

Sketch 运行时核心,提供画布渲染、节点树管理与 Yoga 布局能力。适合在纯 H5 环境中直接使用,也可作为框架封装的基础。

🎯 适用场景

  • 纯 H5 或业务自定义渲染环境
  • 希望直接控制节点树与渲染过程
  • 需要把运行时嵌入到已有框架中

✨ 功能特性

  • 节点树管理与生命周期
  • Yoga 布局计算与样式映射
  • 事件系统与渲染调度

📦 安装

npm

npm add @sketchjs/runtime

pnpm

pnpm add @sketchjs/runtime

yarn

yarn add @sketchjs/runtime

🚀 快速开始

import { SketchRoot, SketchText, SketchView, StyleSheet, SketchImage } from '@sketchjs/runtime'
import logo from './assets/logo.png'
import './styles.less'

const style = StyleSheet.create({
  root: {
    width: 500,
    height: 500,
    backgroundColor: '#ffffff'
  },
  view: {
    width: 500,
    height: 500,
    justifyContent: 'center',
    alignItems: 'center'
  },
  logo: {
    width: 200,
    height: 200
  },
  text: {
    width: 500,
    marginTop: 20,
    color: '#282c34',
    fontSize: 50,
    fontWeight: 400,
    lineHeight: 50,
    textAlign: 'center'
  }
})

(async () => {
  const app = document.getElementById('app')
  const canvasNode = document.createElement('canvas')
  const canvasCtx = canvasNode.getContext('2d')
  canvasNode.classList.add('canvas')
  if (!app || !canvasCtx) return

  const root = SketchRoot.create({ canvas: canvasNode, ctx: canvasCtx, style: style.root })
  root.addEventListener('initialized', (event) => console.log('initialized', event))
  root.addEventListener('elementUpdate', (event) => console.log('elementUpdate', event))
  await root.init()

  const view = SketchView.create({ style: style.view })
  const image = SketchImage.create({ src: logo, style: style.logo })
  const text = SketchText.create({ text: 'Hello  World!', style: style.text })

  await root.appendChild(view)
  await view.appendChild(image)
  await view.appendChild(text)

  app.appendChild(canvasNode)
  app.addEventListener('click', () => {
    const dataUrl = root.toDataURL('image/png', 1)
    console.log({ dataUrl })
  })

  return root.render()
})()

💡 核心概念

  • SketchRoot:渲染根节点,负责绑定 canvas/ctx 并驱动渲染
  • SketchView:布局容器节点
  • SketchImage:图片节点
  • SketchText:文本节点
  • StyleSheet:样式定义与布局映射工具

🧩 事件

  • initializedroot.init() 完成后触发
  • elementUpdate:节点树更新后触发

📝 使用说明

  • root.init() 需要 canvasctx
  • root.render() 执行一次渲染,通常在节点更新后调用
  • 样式中的 width/height 会影响 Canvas 像素尺寸

🧭 初始化流程

  1. 创建 canvasctx
  2. SketchRoot.create 创建根节点
  3. await root.init() 完成挂载
  4. 创建并挂载子节点
  5. 调用 root.render() 渲染

❓ 常见问题

  • 画布空白?
  • 检查 canvas/ctx 是否有效,并确保根节点样式有 width/height