How leaferjs/leaferjs works
Project Type and Purpose
• LeaferJS is an open‑source, frontend Canvas rendering engine and interactive UI library.
• The monorepo uses pnpm workspaces, Rollup for bundling, Vite for development, and shell scripts for build automation.
File Structure
• Top‑level config and scripts:
• rollup.config.js, vite.config.ts – build tool configs
• scripts/*.sh – tasks: all.sh (all builds), clear.sh (clean), dts.sh (generate TypeScript defs), update.sh
• pnpm-workspace.yaml, package.json, tsconfig.json – monorepo, package, and TS config
• public/ – static assets for dev server
• index.ts – entry point for demo or custom code
• src/
• README.md – submodule overview
Key README Insights
• Requires cloning with --recurse‑submodules to populate src/* from external repos.
• Scripts to install, start a local dev server (Vite on port 10101), and to build “core,” “web,” or “all” bundles via npm run commands.
• MIT‑licensed, targeted at front‑end developers needing high‑performance Canvas and UI building blocks.
Main Components
a. Core Engine (“leafer”)
b. Sub‑packages:
• UI layer (leafer-ui)
• Input handling (leafer-in)
• Game abstractions (leafer-game)
• Editor features (leafer-editor)
c. Build Toolchain:
• Rollup bundler
• Vite dev server
• Shell scripts (build, clean, generate typings)
d. Consumer Code:
• index.ts demo or user application
• public assets served by Vite
e. External Interfaces:
• Browser Canvas API
• DOM / Event system
Relationships and Interactions
• The Consumer Code (index.ts) imports modules from the sub‑packages.
• Input events flow from the browser through leafer-in to the core engine, then to UI components.
• The UI and editor modules sit atop the core drawing engine. Game logic uses both drawing and input modules.
• During development, Vite serves public/ and index.ts, hot‑reloads code.
• Rollup consumes sub‑packages, outputs bundles (core, web, all) and generates .d.ts files via scripts.
Architectural Patterns and Design Principles
• Monorepo with modular sub‑packages (plugin‑style extensibility).
• Clear separation: Core engine vs. UI vs. Input vs. Extensions (game, editor).
• Build‑time bundling vs. runtime dev server.
• Convention over configuration: standardized folder layout, scripts, and configs.
Detail Level
• Sub‑package as its own node.
• Shared dependencies (e.g., TypeScript types, shared utils).
• Shell scripts as automation blocks tied to the Rollup configuration.
• Do not over‑complicate: illustrate major components and their interactions clearly.