Pindou · 拼豆豆
English · 简体中文

A browser-only fuse-bead (拼豆 / Hama / Perler) pattern editor. Place real pegboards, draw on a Canvas 2D grid, convert an image into a palette-limited bead pattern locally, and export a 1:1 vector PDF you can print and put under a clear pegboard.
Live demo: https://pindou.liangfeiyan.cn
No backend, no account, no login, no payment, no cloud sync, no upload. Projects and cached source images live in the visitor’s IndexedDB. Nothing about a project leaves the browser.

At a glance
|
|
| Code |
17.8k lines of TypeScript / TSX across 69 source files, 7 runtime dependencies |
| Core engineering |
5M-cell typed-array grid, incremental undo patches, Web Worker image pipeline, deterministic CIEDE2000 color matching, 1:1 vector print layout |
| Scale |
10 palettes (92–291 colors), 5 board sizes, patterns up to 5,000,000 cells |
| Local-first |
IndexedDB persistence, autosave, recoverable trash, versioned project format, legacy readers |
| Quality gates |
typecheck + lint + 130+ assertions + headless-Chrome end-to-end checks + CI |
| Bundle |
≈170 kB gzip entry; editor route, export stack, and the CJK print font are code-split |
Reviewing this repo for a role? Three files carry the most signal:
src/render/documentLayout.ts — physical pagination: 1:1 millimetres, 3-cell overlap bands, balanced page ranges.
src/editor/history.ts — undo as byte-budgeted patches instead of canvas snapshots.
src/conversion/match.ts — Oklab prefilter + exact CIEDE2000, no randomness anywhere.
Then run npm install && npm run check.
Architecture
flowchart TB
subgraph UI["Presentation"]
App["App.tsx · hash router"]
Pages["pages/ · Editor · BoardPicker · Library"]
Comps["components/ · canvas, panels, tool rail, overlays"]
end
subgraph State["Editing state"]
Store["editor/store.ts · the only write path"]
History["history.ts · incremental patches"]
Tools["tools · selection · keyboard"]
end
subgraph Core["Pure TypeScript core"]
Domain["domain/ · geometry, grid, palette, project schema"]
Conv["conversion/ · image to bead pipeline"]
Render["render/ · canvas, PDF, PNG, BOM"]
end
subgraph Platform["Browser platform"]
Worker["Web Worker · color matching"]
IDB["IndexedDB · projects, drafts, images"]
Canvas["Canvas 2D · viewport culling"]
end
Comps --> Store
Pages --> Store
App --> Pages
Store --> History
Store --> Tools
Store --> Domain
Store --> Conv
Store --> Render
Store --> IDB
Conv --> Domain
Conv --> Worker
Domain --> Render
Render --> Canvas
Domain --> IDB
The dependency direction is one-way: domain knows nothing about React, storage, or rendering. conversion and render are pure functions over typed arrays. storage is the only module allowed to touch IndexedDB. That is why the conversion pipeline and the print layout can be asserted from Node without a browser.
| Layer |
Owns |
Must not |
src/domain/ |
board geometry, grid rules, palette types, project schema + validation + serialization |
import React, storage, or rendering |
src/editor/ |
Zustand state, history, tools, selection transforms, keyboard |
render or persist directly |
src/conversion/ |
decode, analysis, downscale, matching, cleanup, worker protocol |
touch the DOM beyond image decoding |
src/render/ |
Canvas 2D drawing, thumbnails, paper/screen layout, PDF, PNG, BOM |
mutate editor state |
src/storage/ |
IndexedDB, autosave lifecycle, image cache |
compute layout or colors |
src/components/ |
canvas surface, panels, overlays, notices |
hold authoritative data |
src/editor/store.ts is deliberately the only place where actions live. Before changing a UI behavior, trace the action and every caller — there is no second path that writes cells.
The four hard problems
1. Image → beads is a color-science problem
Every pixel must land on one of 92–291 physical bead colors, and the result must be byte-identical when the same image is converted twice. So: header-only size probe before decoding, a hard pixel cap, a downscale in linear light (sRGB averaging darkens the image), and a deterministic matcher — Oklab prefilter to 24 candidates, then exact CIEDE2000, ties broken by first-seen order. Prefilter, dithering, palette caps, and cleanup all interact, which is why the pipeline is one explicit pass list rather than a pile of toggles.
flowchart LR
A["Image file"] --> B["Header-only size probe"]
B --> C["Decode, clamp to 4096 px / 16.7 MPx"]
C --> D["Content analysis"]
D --> E["Background sample + subject crop"]
E --> F["Downscale in linear light"]
F --> G["Bilateral filter + neutral bias"]
G --> H["Oklab prefilter to 24"]
H --> I["Exact CIEDE2000 match"]
I --> J["Palette limit + keep key colors"]
J --> K["Majority filter + merge small components"]
K --> L["Background flood fill"]
L --> M["Uint16Array bead grid"]
Steps D–L run inside a Web Worker; decoding stays on the main thread. Pixels and results cross the boundary as transferables, never as copies. → docs/conversion-pipeline.md
2. Physical scale has to survive the printer
The print export is a vector A4 document tiled at exactly 1:1 (1 cell = 2.6 mm or 5 mm), with a 3-cell overlap band for taping pages together, a 100 mm calibration ruler, per-cell color codes, and a usage list. Printer “Fit to page” silently breaks every dimension — so the document itself measures the failure: print page one, check the ruler is 100.0 mm.
flowchart LR
G["Bead grid + palette"] --> L["documentLayout<br/>mm geometry · 3-cell overlap · balanced ranges"]
L --> P["documentPaper<br/>A4 pages · guides · ruler · codes"]
P --> PDF["Vector PDF<br/>jsPDF"]
P --> PNG["Preview PNG<br/>Canvas 2D"]
G --> BOM["BOM<br/>bead + color counts"]
BOM --> CSV["usage.csv"]
PDF --> ZIP["Print kit .zip"]
CSV --> ZIP
→ docs/printing-and-export.md
3. A 5-million-cell canvas runs on the main thread
One flat Uint16Array (5M cells = 10 MB; the same canvas as objects is 500 MB+), plus a placeable mask derived from board geometry so a board gap can never hold a bead. Undo records only touched indices, under three budgets: HISTORY_DEPTH = 50, MAX_PATCH_CELLS = 2,000,000, MAX_HISTORY_BYTES = 64 MiB. Because patches mutate the buffer in place, derived state keys off commitVersion instead of object identity. Above 40,000 visible cells the renderer switches to a bitmap cache; below it, per-cell drawing with viewport culling.
4. Local-first means validation is load-bearing
There is no server-side copy, so a malformed read is lost work. Validation runs before allocation: unknown palette ids, out-of-range cell values, oversized text fields, clamped zoom/pan, recomputed placeable. Project files store the grid as zlib-compressed base64; IndexedDB stores the same grid as a structured-cloned Uint16Array. Deletion is a recoverable trash state; permanent purge sits behind explicit confirmation.
sequenceDiagram
participant U as User
participant S as Zustand store
participant H as History
participant A as Autosave
participant D as IndexedDB
U->>S: draw · convert · rename
S->>H: record touched indexes only
S->>A: commitVersion++
A->>D: debounce 2s → drafts
U->>S: explicit save
S->>D: save queue → projects
U->>S: tab hidden
A->>D: flush pending draft
→ docs/architecture.md
Engineering decisions
| Decision |
Why |
Cost accepted |
Flat Uint16Array grid + placeable mask |
5M cells in 10 MB with O(1) access |
in-place mutation, so consumers depend on commitVersion |
| Undo as index patches |
a full snapshot is 10 MB per step |
edits above 2M cells apply but are not undoable |
| Worker handles everything after decode |
decode needs DOM APIs; matching is CPU-bound |
marshalling protocol via transferables |
| Downscale in linear light |
sRGB averaging visibly darkens images |
extra gamma round-trip in the hot path |
| Oklab prefilter, then exact CIEDE2000 |
exact search over 291 colors × N pixels is too slow |
two-stage matcher to keep in sync |
| Vector PDF instead of a raster snapshot |
only vectors survive 1:1 scale and crisp color codes |
hand-written layout and pagination code |
| Two grid encodings (file vs IndexedDB) |
no compression cost in-browser, portable files on disk |
one serializer must satisfy both |
No test framework, plain node:assert |
checks run on TS directly, zero deps |
hand-rolled runner and reporting |
Features
| Area |
What it does |
| Boards |
Free placement of 2.6 mm (26/52/78/104) and 5 mm (29) boards, overlap and gap validation, physical size in mm |
| Canvas |
Pencil, bucket fill, color picker, eraser, rectangle selection, pan/zoom, color codes at high zoom, board seams and 10×10 guides |
| Conversion |
5 tuned strategies plus content-based auto selection, dither strength, color-count cap, background removal, crop to subject, image placement/scale/offset |
| Palettes |
10 Chinese and international palettes (92–291 colors), per-color exclude mask |
| Editing |
Incremental undo/redo (50 steps, 64 MiB cap), selection mirror/rotate/translate with loss preview |
| Storage |
IndexedDB projects, drafts, cached source images, lightweight list indexes, recoverable trash |
| Export |
Preview PNG, on-screen vector PDF, 1:1 A4 print PDF, ZIP bundle with usage CSV and Chinese print instructions, .pindou.json project file |
| A11y / motion |
Keyboard canvas controls, live-region notices, prefers-reduced-motion plus an in-app override |
Exported .pindou.json project files are external copies; project-file import is not exposed in the app yet, so the file format stays readable but is not a backup/restore path today.
Screenshots
| Image → beads, locally |
Export and print |
 |
 |
Local project library — IndexedDB only, with bead counts, color counts, board counts, physical size, and a recoverable trash:

Sample patterns in these screenshots were converted from illustrations generated locally, not from user data.
Tech stack
React 19 · TypeScript 6 · Zustand 5 · Vite 8 · Tailwind CSS 4 · Canvas 2D · Web Worker · IndexedDB · jsPDF · fflate · GSAP · oxlint
Seven runtime dependencies, no state library beyond Zustand, no test runner, no CSS framework beyond Tailwind. jsPDF, html2canvas, and the embedded CJK font subset load only when an export actually starts.
Repository map
src/
domain/ board geometry, grid rules, palette types, project schema + validation
editor/ Zustand store, incremental history, selection transforms, tools
conversion/ decode, analyze, downscale, preprocess, color distance, match, cleanup, worker
storage/ IndexedDB projects/drafts/image cache, autosave lifecycle
render/ Canvas 2D drawing, thumbnails, paper/screen layout, PDF, BOM
components/ canvas stage, panels, tool dock, overlays, export stage
i18n/ all user-facing Chinese copy
scripts/
check/ assert-based self-checks (Node runs the TS directly)
data/ palette build script (network, not needed to run the app)
deploy/ optional Nginx template + static deploy script
docs/ technical deep dives, English and Chinese
Run locally
Requires Node.js >= 22.18 and npm. Any current Chrome, Edge, Firefox, or Safari with Canvas 2D and IndexedDB works.
npm install
npm run dev
Open the Vite URL printed in the terminal. No environment variables, API keys, or services.
Checks
npm run typecheck
npm run lint
npm run check # Node self-check: grid/layout/export/project-input invariants
npm run check:browser # headless Chrome: persistence, conversion, canvas, exports
npm run build
npm run check is a plain node:assert script with 130+ assertions — no test framework — covering the invariants whose failure means silently losing beads: layout migration loss accounting, selection transforms into board gaps, history byte budget, board guide geometry, paper pagination/overlap/header-footer reservations, PDF content assertions through a fake sink, image dimension parsing, project validation, and pixel-art downscaling.
npm run check:browser boots Vite, drives an isolated Chrome profile through a middleware page, and asserts against real IndexedDB, real image decoding, real canvas, and real PDF output. The disposable profile is moved to the OS Trash, never into your browser profile.
CI runs typecheck, lint, self-check, and build on every push and pull request.
Technical documentation
| Document |
What it explains |
| docs/conversion-pipeline.md |
The full image → bead pipeline, color management, determinism, and the numbers behind the prefilter |
| docs/printing-and-export.md |
1:1 physical scale, A4 tiling with overlap, calibration ruler, per-cell codes, BOM, embedded CJK font |
| docs/architecture.md |
Module boundaries, the 5M-cell grid model, undo patches, IndexedDB schema, autosave, project format |
中文版:docs/zh/。
Palette data and attribution
Palette values are community screen-reference data, not manufacturer-certified measurements. For production matching, use physical swatches or a calibrated custom palette.
maxcleme/beadcolors — MIT; Perler, Hama, Artkal color fields.
HansBug/pindou-color-data — MIT; MARD 221/291, COCO 291, 漫漫 278, 盼盼 289, 咪小窝 290.
src/render/fonts/ embeds a font subset under the SIL Open Font License; see src/render/fonts/OFL.txt.
npm run build:palettes re-downloads and re-normalizes the palette tables (network required; the app itself never fetches anything).
Deployment
deploy/ contains an optional Nginx template and a host-parameterized static deploy script. Deployment is not required to use the app and is not part of CI.
Contributing
See CONTRIBUTING.md and CODE_OF_CONDUCT.md. Short version: stay browser-only, keep user-facing text in src/i18n/zh.ts, and run npm run typecheck && npm run lint && npm run check && npm run build before opening a pull request.
Security
Report vulnerabilities privately through SECURITY.md. Do not open a public issue for a vulnerability. The app has no server, no credentials, and no remote data path; the main assets are the visitor’s own local project data.
License
Application code is MIT. Third-party palette data and the embedded font keep their own licenses, listed above and in src/data/palettes.json.
评论