Open-source project
leaferjs/leafer-ui avatar
leaferjs/leafer-ui

leafer-ui: a canvas scene graph that ships ten pinned packages

Canvas AI An easy-to-use Canvas engine for effortless graphic interaction and editing, an infinite canvas engine for the AI era.

4,510 stars199 forksTypeScriptMIT

At a glance

What is it?
leafer-ui is the presentation layer of the LeaferJS canvas engine, aimed at editors and infinite canvas tools that need a large scene graph and hit testing. Its own install instructions recommend installing three packages instead of one when you use plugins, which is the first thing to understand.
Who is it for?
Adopt leafer-ui if you are building a canvas editor and want a scene tree, native hit testing and Flex layout without writing them yourself. Do not adopt it if you only render static output, or if ten exact-pinned sibling packages in your lockfile is a risk your build pipeline cannot carry, and remember that rotate, scale and multi-select come from the Editor plugin.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 2 days ago.
What is it written in?
Mainly TypeScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • leaferjs/leafer-ui4,510 ★ · +215
Star history
Repository2026-07-282026-11-15
leaferjs/leafer-ui4.3k4.5k

215 Stars in the last 110 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The version-synchronisation warning inside the install snippet

leafer-ui publishes as an umbrella of ten sibling packages, all pinned to one exact version rather than to a range. package.json names leafer-ui at 2.3.3 and depends on @leafer/core, @leafer/partner, @leafer/interface, @leafer-in/interface, @leafer-ui/draw, @leafer-ui/core, @leafer-ui/web, @leafer-ui/interaction-web, @leafer-ui/partner and @leafer-ui/interface, every one of them fixed at 2.3.3 rather than a caret range. That is not incidental. The install snippet carries a Chinese comment telling you to install the cross-platform core packages alongside leafer-ui precisely to avoid a version mismatch between packages. In practice the mismatch is not something you can dodge by installing less: the umbrella package itself already drags those ten in, so the recommended second command is about making the versions explicit and discoverable rather than about pulling in extra code. If you adopt this engine, your dependency review has to cover the whole LeaferJS family, not one entry. The package is ESM first: "type" is "module", the import entry is ./dist/web.esm.min.js, the CommonJS entry is ./dist/web.min.cjs, and types come from ./types/index.d.ts.

What the million-rectangle table actually measures

Nobody has to accept the performance table on faith. It compares one million interactive rectangles and reports first-paint creation at 1.28 seconds against roughly 9 to 15 seconds for a traditional canvas library, memory at 320 MB against about 2 to 4 GB, and single-element drag at 60 FPS against a range of 0 to 4 FPS. The stated improvement for drag is about 15 times, computed against the top of the baseline range rather than its average, so read that row as the best case for the comparison rather than a typical result. The README also says outright that the figures are for reference only and that real performance depends on hardware, and it names the test environment as a 2K-screen laptop on Chrome V143.0. No file in the repository documents a per-object hit-test cost or an offscreen culling threshold, which means there is no documented way to predict where your own scene size falls off the edge of these numbers. The 320 MB figure for a million live rectangles is also the number to plan memory against, and it is the one that moves first on a lower-memory target.

Installing and drawing a draggable rect in nine lines

Installation is a plain npm install, and the second command in the snippet exists to keep the family versions aligned rather than to add plugins. Run this in a TypeScript or JavaScript project:

sh
npm install leafer-ui

# 需使用插件时,推荐同时安装跨平台核心包,防止出现更新版本不同步问题
npm install leafer-ui @leafer-ui/core @leafer-ui/draw

One line is enough to render. The second repeats leafer-ui and adds @leafer-ui/core and @leafer-ui/draw explicitly, which the comment ties to preventing out-of-sync versions when you later pull in plugins. Then a first scene is four statements: construct a Leafer bound to window, construct a Rect with draggable set, add it to the tree.

ts
import { Leafer, Rect } from 'leafer-ui'

const leafer = new Leafer({ view: window })

const rect = new Rect({
  x: 100,
  y: 100,
  width: 200,
  height: 200,
  fill: '#32cd79',
  draggable: true,
})

leafer.add(rect)

An object literal goes to the constructor rather than a chain of calls, and draggable is a property on that literal, so interaction is declared where the geometry is. Passing window to view is what makes the canvas resize with the window; there is no separate sizing call in the example.

The Editor plugin is opt-in, and the README treats it as the point

Rotation, scaling, moving and multi-select are described as a built-in Editor plugin rather than behaviour of leafer-ui itself, and no import line for it appears in the quick start. Everything in the short example above stops at dragging one rectangle. If your product needs a Figma-style frame, the transform handles and multi-selection arrive only once you install and register a plugin, which changes your evaluation: you are assessing two things, the scene graph and the plugin. The same split explains why the install comment mentions plugins at all. The engine's own scene of use leans heavily on editing rather than drawing: a structured scene tree is described as something an AI system can manipulate the way it manipates the DOM, which only pays off if nodes carry addresses and attributes rather than pixels. For a tool that mostly renders static output, the plugin layer is the part you may never touch, and for a tool that is an editor it is most of the product.

Flex layout inside a canvas, with no DOM underneath

Flex layout computed by the engine is what separates LeaferJS from most canvas drawing libraries. The README calls that support rare in this class of tool and compares the authoring experience to writing HTML. That comparison is about authoring, not about output: there is no DOM underneath and no browser reflow doing the work, because the scene tree computes the layout itself. If your interface is built from panels, toolbars and resizable regions, this removes the step where you hand-roll container measurement, and it removes it in the same coordinate space the renderer uses. The cost is that you are inside the engine's own layout model, so you cannot fall back to CSS for the awkward case, and the README does not document the properties it honours or the gaps. Hit testing is the other half of the interaction story and is described as native, in milliseconds, with drag, scale and multi-touch. Both are the features to test in a prototype, since neither has a documented configuration surface in this repository.

One bundle for web, Node.js, mini programs and mobile H5

A single codebase runs on web, Node.js, mini programs and mobile H5, with server-side frame rendering for short video and batch image generation named as a use case. That is plausible from the repository layout rather than from prose: the package exposes a single web entry at ./dist/web.esm.min.js, and the surrounding @leafer-ui/web and @leafer-ui/interaction-web packages in the dependency list point to the web renderer being one target among several, not the whole product. For Node.js work this matters more than the marketing word cross-platform, because rendering frames without a browser removes a headless-Chromium dependency from a pipeline. The README does not document a separate Node entry point or any server-specific setup, so treat the Node.js path as something to confirm against the official documentation site before planning a build pipeline around it.

The licence is MIT and the core engine and its base plugins stay open source, with commercial plugins sold separately by PxGrow for professional editor suites, complex geometry algorithms and performance work. The last push to this repository was on 2026-10-30.

Where Konva's approach ends and this one starts

Konva is the common comparison point, because both are scene-graph canvas libraries with draggable nodes, and Konva is the option most teams reach for first. Functionality sits in different places in the two. Konva gives you a canvas stage, layers and shapes with event handling, and leaves layout, containers and transform tooling to the application or to separate libraries. LeaferJS folds more of that into the engine: Flex layout is computed by the engine, hit testing is native, and the Editor plugin supplies scaling, rotation and multi-select as a package from the same vendor on the same schedule. That concentration is the trade. Fewer libraries to assemble and one version train to track, against a dependency family that must move in lockstep and an editor feature set that is partly commercial. If you only need a handful of shapes with click and drag, the added machinery buys you nothing. If you are assembling an editor today, the practical question is whether shipping ten exact-pinned packages is cheaper than assembling layout and transform tooling yourself.

Editorial conclusion

Adopt leafer-ui if you are building a canvas editor and want a scene tree, native hit testing and Flex layout without writing them yourself. Do not adopt it if you only render static output, or if ten exact-pinned sibling packages in your lockfile is a risk your build pipeline cannot carry, and remember that rotate, scale and multi-select come from the Editor plugin. Verify first, on your own hardware, that a scene of the density you actually need still responds to drag, since the published figures come from a 2K-screen laptop running Chrome V143.0 and the README itself says real performance depends on hardware. Check the lockfile after that install: if @leafer/core, @leafer-ui/draw and the rest are not all on the same exact version, stop there.

Frequently asked questions

How do I install leafer-ui and start a draggable rectangle?

Run npm install leafer-ui, then create a Leafer bound to window and add a Rect with draggable set to true in its options object. The quick start also recommends installing @leafer-ui/core and @leafer-ui/draw alongside it to avoid version mismatch between packages.

Does leafer-ui support layout inside the canvas without HTML?

Yes. Flex layout is natively supported inside the canvas engine, so containers are computed by the engine rather than by browser reflow. The README does not list the supported Flex properties.

Is the editor behaviour (rotate, scale, multi-select) included in the leafer-ui package?

That behaviour comes from the Editor plugin, which is opt-in rather than part of the quick start import. Plugins are installed separately and the quick start warns that installing the cross-platform core packages alongside helps avoid version mismatch.

Official sources

  1. Official documentation
  2. Official README
  3. Project repository
  4. Release notes
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/leaferjs-leafer-ui.svg)](https://hysenlabs.com/projects/leaferjs-leafer-ui)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/leaferjs-leafer-ui.svg)](https://hysenlabs.com/projects/leaferjs-leafer-ui)

Was this useful?