Skip to content

feat: add the bucket fill tool - #214

Open
tbolis wants to merge 4 commits into
release/1.2.0from
feature/bucket-fill
Open

tbolis wants to merge 4 commits into
release/1.2.0from
feature/bucket-fill

Conversation

@tbolis

@tbolis tbolis commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Summary

Adds the bucket fill tool: a click fills the area which is closed around it with fillColor (lineColor while fillColor is transparent).

  • Lines, rectangles, circles, polygons, strokes of the pencil, texts and the overlay image close an area. The background color and the background image do not, and nor does a dashed line.
  • The area has to be closed within the canvas as it is shown. When the color would get out, a click fills nothing.
  • The fill is a vector path (BucketFill): one undo step, saved by toJSON(), loaded by value, defaultValue and fromJSON(), scaled with the canvas. It is under the lines which close the area, a pixel under their edge, and over the object the area is in.
  • The logic is in the new private package @react-sketch/bucket, which react-sketch bundles like eraser and laserpointer.
  • The showcase has a Bucket fill button (key F), with the fill color only in its properties.

Behavior change

Undo of a removal puts the object back where it was among the objects, and not on top. Redo of an addition does the same for an object added under the others (the fill). Without it, a fill removed and brought back would cover its lines. One existing test (removes the selected object, and undo brings it back) asserted the old order and is updated. It is listed under Changed in the CHANGELOG.

Testing

  • yarn format:check, yarn lint, yarn typecheck, yarn build pass.
  • yarn test passes (533 tests), also with REACT=18.
  • The tests with real pixels (bucketFill.spec.ts) run in the node environment of Jest with the node build of fabric, as the canvas mock of jsdom has no pixels.
  • Run in Chrome (device pixel ratio 2) with the built showcase: draw a rectangle, fill it, click where the area is open, undo, redo (the line stays over the fill), and cut the fill with the eraser.

Notes

  • Shapes drawn by hand with a gap, however small, let the color out and are not filled.
  • The CHANGELOG has a new 1.2.0 heading, without a date.

@react-sketch/bucket renders the objects of a canvas, finds the area of the
pixels connected to a point, grows it under the lines around it, and makes
its outline a path (a FillPath, saved and loaded as a BucketFill). The area
has to be closed within the canvas, and the fill goes over the object the
area is in and under the ones which close it.

The package is private and built with the other two by build:packages.
tool="bucket-fill" (Tools.BucketFill, Types.Tool.BUCKET_FILL) fills the area
which is closed around a click with fillColor, or lineColor while fillColor
is transparent. A click where the area is not closed does nothing.

The fill goes under the lines which close the area, so the history keeps the
place of an object which is not on top: undo of a removal and redo of an
addition put it back where it was, and not over the lines.
The bucket fill button (key F) fills with the fill color, whether the shapes
are filled or not, and its properties show the fill color only.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant