A diagram drawing application which is demonstrating how we can utilize React.js and HTML <canvas/> to create an interactive drawing.
https://draw.crispyscript.com (works best in desktop)
Demo.mp4
- Line drawing tool
- Rectangle drawing tool
- Pencil drawing tool(free-hand)
- Selection tool for moving and resizing a single element
- Undo/Redo/Clear
- Text tool
- Support deleting a selected element
- Arrow drawing tool
- Pan
- Zoom
- CSS & Styling
- Mobile & Resizing friendly
- Multi-select elements
- Support uploading an image
- Duplicate elements
- Send to back/front
- Save and import diagrams, including images, as .diaglam files
- Limit max history stack to ~50 items
- Export canvas to png/jpeg
- Rotate
- Keyboard shortcut
- Setting stroke color
- Setting stroke width
- Filled rectangle
- Copy & Paste elements (upgrade "Duplicate" feature)
Use Node.js 22.12+ and pnpm.
- Run
pnpm installto install dependencies. - Run
pnpm run devto start the app athttp://localhost:3000.
Run pnpm run build to check TypeScript and create the production files in dist/.
Run pnpm run preview to serve the build locally at http://localhost:3000. Stop the development server first.
For a deployment under a subpath, use pnpm run build --base=/your-path/.
Run pnpm run typecheck to check TypeScript without a build.
Run pnpm run lint to check JavaScript, TypeScript, React, React Hooks, and Cypress code with Oxlint.
Run pnpm run lint:fix to apply available safe fixes.
Type-aware Oxlint rules need additional setup and are not enabled. pnpm run typecheck remains the TypeScript check.
.env sets the canonical URL and social metadata in index.html.
In application code, access client variables with import.meta.env.VITE_NAME.
Vite exposes variables with the VITE_ prefix to the browser. Do not put secrets in these variables.
The Cypress specs in cypress/e2e use cypress-visual-regression to compare screenshots.
Baselines are stored in cypress/snapshots/base/ (the last known good state).
Actual are stored in cypress/snapshots/actual/ (the result of the current test run).
Failed tests produce images in cypress/snapshots/diff/ (the differences between the baseline and actual).
-
Start the app with
pnpm run devand leave it running athttp://localhost:3000. -
In another terminal:
# Compare the current app against the saved baselines. pnpm visual:test -
If the test fails, review the differences in
cypress/snapshots/diff/ -
If the changes are intentional, update the baselines. Pass
--specto replace only the baselines produced by that specific.cy.jsfile:pnpm run visual:baseline --spec cypress/e2e/rectangle.cy.js
This replaces all snapshots captured by tests in
rectangle.cy.jsand leaves baselines for other spec files unchanged. If a spec contains multiple tests and you want to replace the snapshots for just one test, temporarily change that test'sit(...)toit.only(...), run the command above for its spec, then remove.onlybefore committing.
To test an app running at a different URL or test a single .cy.js file, pass --config baseUrl=<url> and/or --spec <file>:
pnpm run visual:test --config baseUrl=http://localhost:3001 --spec cypress/e2e/rectangle.cy.jsTo replace ALL baselines after reviewing an intentional change:
# WARNING: We will lose all previous baselines!!
pnpm run visual:baselineTo open Cypress for interactive debugging (defaults to regression mode):
pnpm run cypress:openNote:
- Generate and compare baselines on the same OS and Cypress version to keep the rendering consistent.
- Regression mode fails on missing baselines or visual differences and does not update baselines.
- Most of x, y value are in
scenecoordinate (i.e. canvas coord, not viewport coord). They are inconsistency in naming. For example,// All of these variable names are in `scene` coord let sceneX, x1, x2, pointerX
- However, the
viewportcoordinate is more consistency in naming.// There always be `viewport` keyword in `viewport` coord let viewportX