Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.{json,yml,yaml,md,html}]
indent_size = 2
5 changes: 5 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Formatting-only commits, skipped by `git blame` (GitHub reads this file automatically;
# locally: git config blame.ignoreRevsFile .git-blame-ignore-revs).

# style: reformat with Prettier (2-space indentation)
9d50b8e4a1142ca0d771d83288ab501732602e85
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ jobs:
node-version: 24
cache: pnpm
- run: pnpm install --frozen-lockfile
# Merging a version bump publishes it (release.yml), with notes from CHANGELOG.md.
- name: CHANGELOG.md has a section for the version
run: |
version="$(node -p "require('./package.json').version")"
grep -Eq "^## ${version//./\\.}( |$)" CHANGELOG.md || { echo "Add a '## $version' section to CHANGELOG.md" >&2; exit 1; }
- run: pnpm format:check
- run: pnpm lint
- run: pnpm typecheck
- run: pnpm test
Expand Down
96 changes: 78 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
name: Publish to npm
name: Release

# Push a tag like v1.0.0 to publish.
# The version in package.json is the switch: merging a pull request that bumps it publishes that
# version. Pushes that leave the version alone (already on npm) do nothing.
#
# On a new version this tests and builds, publishes to npm with provenance (a version with a
# pre-release suffix such as 1.2.0-beta.1 goes to the `next` dist-tag), tags the commit vX.Y.Z and
# creates a GitHub release from the version's section in CHANGELOG.md.
#
# Authentication, in order of preference:
# 1. npm Trusted Publishing (OIDC) — no secret needed. Configure it on npmjs.com under
# the package's Settings → Trusted Publisher (repo Inchill/react-whiteboard, workflow release.yml).
# 2. An NPM_TOKEN repository secret — only needed for the very first publish, because npm
# requires the package to exist before Trusted Publishing can be configured.
# Use a short-lived granular token and delete it once Trusted Publishing works.
# 2. An NPM_TOKEN repository secret — use a short-lived granular token and delete it once
# Trusted Publishing works.
on:
push:
tags: ['v*']
branches: [main]
workflow_dispatch:

permissions:
contents: read
id-token: write # required for Trusted Publishing and provenance
contents: write # push the tag and create the release
id-token: write # Trusted Publishing and provenance

# Never run two releases at once, and never cancel one halfway through publishing.
concurrency:
group: release
cancel-in-progress: false

jobs:
publish:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -27,18 +37,68 @@ jobs:
node-version: 24
cache: pnpm
registry-url: https://registry.npmjs.org
# Trusted Publishing needs npm CLI 11.5.1 or later.
- run: npm install -g npm@11
- run: pnpm install --frozen-lockfile
- run: pnpm test
- name: Check the tag matches package.json

- name: Is this version new?
id: version
run: |
name="$(node -p "require('./package.json').name")"
version="$(node -p "require('./package.json').version")"
if [ "v$version" != "$GITHUB_REF_NAME" ]; then
echo "Tag $GITHUB_REF_NAME does not match package.json version $version" >&2
echo "version=$version" >> "$GITHUB_OUTPUT"
if npm view "$name@$version" version > /dev/null 2>&1; then
echo "$name@$version is already on npm; nothing to release."
echo "new=false" >> "$GITHUB_OUTPUT"
else
echo "Releasing $name@$version."
echo "new=true" >> "$GITHUB_OUTPUT"
fi

# Trusted Publishing needs npm CLI 11.5.1 or later.
- if: steps.version.outputs.new == 'true'
run: npm install -g npm@11
- if: steps.version.outputs.new == 'true'
run: pnpm install --frozen-lockfile
- if: steps.version.outputs.new == 'true'
run: |
pnpm lint
pnpm typecheck
pnpm test

- name: Release notes from CHANGELOG.md
if: steps.version.outputs.new == 'true'
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
# The lines under "## <version>" up to the next "## " heading.
awk -v v="$VERSION" '
index($0, "## " v " ") == 1 || $0 == "## " v { found = 1; next }
found && /^## / { exit }
found { print }
' CHANGELOG.md > release-notes.md
if ! grep -q '[^[:space:]]' release-notes.md; then
echo "CHANGELOG.md has no section for $VERSION" >&2
exit 1
fi
- run: npm publish --provenance --access public

- name: Publish to npm
if: steps.version.outputs.new == 'true'
env:
VERSION: ${{ steps.version.outputs.version }}
# Empty once the secret is deleted; npm then uses Trusted Publishing.
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
case "$VERSION" in
*-*) dist_tag=next ;;
*) dist_tag=latest ;;
esac
# prepublishOnly builds the library.
npm publish --provenance --access public --tag "$dist_tag"

- name: Tag and create the GitHub release
if: steps.version.outputs.new == 'true'
env:
VERSION: ${{ steps.version.outputs.version }}
GH_TOKEN: ${{ github.token }}
run: |
prerelease=""
case "$VERSION" in *-*) prerelease="--prerelease" ;; esac
gh release create "v$VERSION" --target "$GITHUB_SHA" --title "v$VERSION" --notes-file release-notes.md $prerelease
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist
coverage
pnpm-lock.yaml
public
# Prose is wrapped and aligned by hand.
*.md
11 changes: 11 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"tabWidth": 2,
"useTabs": false,
"printWidth": 140,
"singleQuote": true,
"semi": true,
"trailingComma": "all",
"arrowParens": "always",
"endOfLine": "lf"
}
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint", "editorconfig.editorconfig"]
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "editorconfig.editorconfig"]
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 1.1.0 — 2026-10-13

### Added
- Elbow and curved lines and arrows. The style panel's new *Shape* option sets a line or arrow to straight, elbow (right-angled turns, like a flowchart connector) or curve (a smooth curve that follows your drag). It also changes the shape of selected lines.
- `LinearShape` gains optional `via` (points the line passes through) and `curved`. Lines without them are straight, as before, so existing documents are unchanged; older versions of the library draw new elbow and curved lines as straight lines.
- `LineRoute` type export and a `lineRoute` field in `StyleState`.

## 1.0.0 — 2026-10-08

A rewrite of the original canvas drawing prototype.
Expand Down
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ Node.js 24+ and pnpm 10+ are required (`.nvmrc` pins 24; installs fail on older
## Before opening a pull request

```bash
pnpm format # Prettier: 2-space indentation, single quotes, semicolons
pnpm lint
pnpm typecheck
pnpm test
```

Code style is set by `.prettierrc.json` and `.editorconfig`; editors with the Prettier and EditorConfig extensions apply it on save. CI runs `pnpm format:check`.

- Keep the library (`src/whiteboard`) free of runtime dependencies other than React.
- Add or update tests in `tests/` for behaviour changes (`tests/<module>.test.ts`). Pure logic lives in `geometry.ts`, `shapes.ts`, `history.ts` and `export.ts`, which are easy to unit test.
- New UI strings go into **both** locales in `src/whiteboard/i18n.ts`.
Expand All @@ -34,6 +37,7 @@ pnpm test
| `src/whiteboard/types.ts` | Shape and state types |
| `src/whiteboard/geometry.ts` | Bounds, hit-testing, camera math, path smoothing |
| `src/whiteboard/shapes.ts` | Creating / updating / styling shapes |
| `src/whiteboard/linear.ts` | Elbow and curved lines: points, curves, simplifying a drawn curve |
| `src/whiteboard/render.ts` | Canvas renderer |
| `src/whiteboard/export.ts` | SVG / PNG / JSON import & export |
| `src/whiteboard/history.ts` | Undo/redo reducer |
Expand All @@ -47,6 +51,10 @@ pnpm test
2. Handle it in `getBounds`, `hitTest`, `translateShape` (`geometry.ts`), `createShape` / `updateDraft` / `finalizeShape` (`shapes.ts`), `drawShape` (`render.ts`), `shapeToSvg` and `isValidShape` (`export.ts`).
3. Add a tool entry in `constants.ts`, an icon in `icons.tsx` and labels in `i18n.ts`.

## Releasing

The version in `package.json` is the release switch. To release, bump it in your pull request (semver: `fix` → patch, `feat` → minor, breaking → major) and add a `## X.Y.Z — date` section at the top of `CHANGELOG.md`; CI fails without it. Once the pull request is merged into `main`, the release workflow publishes to npm, tags `vX.Y.Z` and creates a GitHub release from that section. A version with a pre-release suffix (`1.2.0-beta.1`) is published under the `next` dist-tag.

## Commit messages

Conventional Commits are preferred: `feat: …`, `fix: …`, `docs: …`, `chore: …`.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Infinite canvas, shapes, text, selection, undo and PNG / SVG export — about 23
- **Export** — PNG, SVG, copy PNG to clipboard, save/open `.json` (also by drag-and-drop)
- **Keyboard first** — single-key tool shortcuts, Shift to constrain angles and squares, arrow keys to nudge, `?` for the cheat sheet
- **Feels like a pen** — strokes follow Apple Pencil / tablet pressure (or drawing speed with a mouse or finger) and taper at both ends
- **Elbow and curved arrows** — lines and arrows can be straight, turn at right angles like a flowchart connector, or follow your drag as a smooth curve
- **Rub-out eraser** — erase just the part of a stroke you rub over, or switch to removing whole shapes
- **Touch & stylus** — Pointer Events with coalesced samples, two-finger pinch zoom
- **Autosave** to `localStorage`, **dark mode**, **English / 中文 UI**
Expand Down Expand Up @@ -201,7 +202,7 @@ src/
tests/ Vitest unit and component tests
```

The website deploys to GitHub Pages from `main` (see `.github/workflows/deploy.yml`). Pushing a `v*` tag publishes the package to npm (needs an `NPM_TOKEN` secret).
The website deploys to GitHub Pages from `main` (see `.github/workflows/deploy.yml`). Merging a version bump into `main` publishes it to npm: bump `version` in `package.json` and add a matching section to `CHANGELOG.md` in the pull request, and `.github/workflows/release.yml` publishes it, tags `vX.Y.Z` and creates a GitHub release from that section. Changes that keep the version publish nothing.

## Contributing

Expand Down
3 changes: 2 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- **导出**:PNG、SVG、复制 PNG 到剪贴板,保存 / 打开 `.json`(支持拖拽文件进画布)
- **键盘优先**:单键切换工具,Shift 锁定角度 / 正方形,方向键微调,按 `?` 查看全部快捷键
- **像真笔一样**:线条粗细跟随 Apple Pencil / 数位板的压力变化(用鼠标或手指时随书写速度变化),起笔收笔自然变尖
- **折线和曲线箭头**:直线和箭头可以是直的,可以像流程图连线一样直角拐弯,也可以顺着拖动的轨迹画成平滑曲线
- **局部擦除**:只擦掉划过的那一段笔画,也可以切换成整笔删除
- **触屏与手写笔**:基于 Pointer Events 并读取合并采样点,支持双指缩放
- **自动保存**到 `localStorage`,**深色模式**,**中英文界面**
Expand Down Expand Up @@ -156,7 +157,7 @@ pnpm build:lib # 组件库 → dist/lib
- `src/app/`:`/board/` 全屏白板
- `tests/`:Vitest 单元测试和组件测试

推送到 `main` 会自动部署官网到 GitHub Pages;推送 `v*` 标签会发布到 npm(需要配置 `NPM_TOKEN` secret)。
推送到 `main` 会自动部署官网到 GitHub Pages;版本号就是发布开关:在 PR 里把 `package.json` 的 `version` 升级,并在 `CHANGELOG.md` 里加上对应版本的一节,合入 `main` 后 `.github/workflows/release.yml` 会发布到 npm、打上 `vX.Y.Z` 标签,并用这一节创建 GitHub Release;不改版本号的合入不会发布。

## 参与贡献

Expand Down
16 changes: 13 additions & 3 deletions board/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)" />
<meta name="theme-color" content="#16171d" media="(prefers-color-scheme: dark)" />
<meta name="description" content="A free, open-source online whiteboard. Draw, sketch and diagram in your browser — no sign-up, saved locally." />
<meta
name="description"
content="A free, open-source online whiteboard. Draw, sketch and diagram in your browser — no sign-up, saved locally."
/>
<link rel="icon" type="image/svg+xml" href="../favicon.svg" />
<link rel="manifest" href="../manifest.webmanifest" />
<title>Whiteboard · react-whiteboard</title>
<style>
html, body, #root { height: 100%; margin: 0; }
body { overscroll-behavior: none; }
html,
body,
#root {
height: 100%;
margin: 0;
}
body {
overscroll-behavior: none;
}
</style>
</head>
<body>
Expand Down
Binary file modified docs/screenshot-en-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshot-en-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshot-zh-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshot-zh-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 18 additions & 21 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,23 @@ import reactRefresh from 'eslint-plugin-react-refresh';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{ ignores: ['dist', 'coverage'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2022,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
quotes: ['error', 'single', { avoidEscape: true }],
semi: ['error', 'always'],
'eol-last': ['error', 'always'],
indent: ['error', 4, { SwitchCase: 1 }],
'no-console': 'warn',
},
{ ignores: ['dist', 'coverage'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2022,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
// Formatting (indentation, quotes, semicolons) is Prettier's job: `pnpm format`.
'no-console': 'warn',
},
},
);
9 changes: 7 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>react-whiteboard — an open-source whiteboard for React</title>
<meta name="description" content="An open-source, zero-dependency infinite-canvas whiteboard component for React: shapes, text, selection, undo, dark mode, PNG/SVG export." />
<meta
name="description"
content="An open-source, zero-dependency infinite-canvas whiteboard component for React: shapes, text, selection, undo, dark mode, PNG/SVG export."
/>
<meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)" />
<meta name="theme-color" content="#0f1115" media="(prefers-color-scheme: dark)" />
<link rel="icon" type="image/svg+xml" href="./favicon.svg" />
Expand All @@ -23,7 +26,9 @@
</script>
</head>
<body>
<noscript>This page needs JavaScript for the live demo. The full source is on GitHub: https://github.com/Inchill/react-whiteboard</noscript>
<noscript
>This page needs JavaScript for the live demo. The full source is on GitHub: https://github.com/Inchill/react-whiteboard</noscript
>
<div id="root"></div>
<script type="module" src="/src/site/main.tsx"></script>
</body>
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@inchill/react-whiteboard",
"version": "1.0.0",
"version": "1.1.0",
"description": "A lightweight, zero-dependency infinite-canvas whiteboard component for React.",
"keywords": [
"react",
Expand Down Expand Up @@ -48,6 +48,8 @@
"build:lib": "vite build -c vite.lib.config.ts && tsc -p tsconfig.lib.json",
"preview": "vite preview",
"lint": "eslint .",
"format": "prettier --write .",
"format:check": "prettier --check .",
"typecheck": "tsc -b",
"test": "vitest run",
"test:watch": "vitest",
Expand Down Expand Up @@ -75,6 +77,7 @@
"eslint-plugin-react-refresh": "^0.5.7",
"globals": "^17.13.0",
"jsdom": "^26.1.0",
"prettier": "^3.9.10",
"react": "^19.3.0",
"react-dom": "^19.3.0",
"typescript": "~5.9",
Expand Down
Loading
Loading