Whiteboard
The full editor: pens, markers, highlighters, three kinds of eraser, every shape, text, pictures and SVG, selection with move, resize and rotate, grouping, locking, alignment, layers, the clipboard, pan and zoom, and a board that survives a reload. Everything here is built from the public API; each part is explained below the board.
A tool is a parameter
Every button in the first row swaps the canvas's Tool - and, for the drawing tools, its
Brush. Shapes take their stroke, fill and dashes from ShapeStyle, text its look from
the text tool's own style. Nothing about the canvas has to be told that the tool changed. Where the browser has an
eyedropper (Chromium on the desktop), Pick takes a colour from anywhere on the screen with
PickColorAsync.
switch (id) { case "marker": _brush = new BinkMarkerBrush { Width = MathF.Max(_width * 1.5f, 6f), Color = color }; _tool = new BinkDrawTool(); break; case "eraser": _tool = new BinkEraserTool { Mode = Enum.Parse<BinkEraserMode>(_eraserMode), Radius = MathF.Max(_width * 2f, 8f) }; break; case "text": _tool = new BinkTextTool { Style = BinkTextStyle.Default with { FontSize = MathF.Max(_width * 4f, 14f), Color = color, Bold = _bold } }; break; case "pan": _tool = new BinkPanTool(); // a second finger pans and pinches whatever the tool break; }
Text is typed into a real HTML textarea the canvas places over the box, so an input method, dictation
and a screen reader all work: Enter commits, Shift+Enter starts a new line, Escape cancels, and committing empty
text removes the box rather than leaving an invisible element behind. The text tool raises
EditRequested and EditFinished for an application that wants to know. A tool can also be
set from code with SetTool, which is what a shortcut of the page's own would call.
Shapes, lines and outlines
BinkShapeTool draws by dragging: a rectangle (rounded with CornerRadius), an ellipse, a
line, an arrow, a diamond, a triangle, a regular polygon (PolygonSides), a star
(StarPoints) or a highlight. Holding Shift makes a square or a circle, or keeps a line to 15 degree
steps. BinkPolylineTool places an outline point by point: each click adds a point while the next
segment follows the pointer, a double click or Enter finishes, clicking the first point again closes it,
Backspace takes the last point back and Escape abandons it. With Smooth it is a curve through the
points; with EndArrow it is an elbow connector. With a shape tool, Enter adds a shape in the middle
of the view, so shapes can be made without a drag.
_tool = new BinkShapeTool(BinkShapeKind.Star) { StarPoints = 5 }; _tool = new BinkPolylineTool { Smooth = true }; _shapeStyle = new BinkShapeStyle { StrokeColor = color, StrokeWidth = 3f, FillColor = color with { A = 48 }, Dash = [9f, 6f], LineJoin = BinkLineJoin.Miter, // sharp corners; round is the default };
Diamonds, triangles, polygons, stars and polylines are all a BinkPolygonShape, and an imported SVG
path is a BinkPathElement holding curves in any number of sub-paths; both save, paste, export and
synchronize like every other element.
Three erasers
The eraser's three modes are genuinely different, not three names for one behaviour. Every erase gesture is one undo step, however many strokes it touched, and erasing reaches only unlocked, visible layers.
| Mode | What it does | Right for |
|---|---|---|
| Whole stroke | Stroke deletes any stroke it touches. Cheap, exactly reversible, and what most people expect from a notes app. | Note taking and handwriting |
| Part of a stroke | Segment cuts out only the touched part, splitting the stroke; the first piece keeps the original id, so undo and collaborators see an edit. | Drawing and sketching |
| Pixel mask | Pixel draws an eraser stroke that masks what is below it within its layer. Nothing is deleted - the erased ink stays in the document - and it exports as an SVG mask. The only mode that erases part of a picture. | Marking up a picture |
Turning a stylus over to use its eraser end erases too, with the pixel eraser, while the pen, the marker or the
highlighter is chosen: BinkDrawTool honours the eraser button by default. The segment eraser's
geometry is public as BinkStrokeEditor.EraseSegments, for an eraser of your own.
Transforms, not rewrites
Moving, resizing, rotating and flipping only change each element's transform, so the vector data is never
rewritten and undo restores it exactly; a whole drag is one step. Scaling a stroke scales its ink with it, and
BinkStroke.Flatten() bakes the transform in when that is wanted. The wheel pans, Ctrl+wheel or a
trackpad pinch zooms, and two fingers pan and pinch on a touch screen.
<BinkCanvas WheelMode="BinkWheelMode.PanAndZoom" Snapping="new BinkSnapOptions { GridSize = 20f }" Grid="BinkGrid.DottedDefault" /> _tool = new BinkSelectTool { MarqueeShape = BinkMarqueeShape.Lasso, LassoCoverage = 0.5f };
A lasso selects a stroke when at least LassoCoverage of its points lie inside the loop, so a loose
loop around one word does not catch the lines above and below it. Snapping lines a drag up with other elements
and the page first, and falls back to the grid; ToObjects, ToPage and
GridSize turn each on or off. The grid is part of the view: it is never saved or exported, and
zoomed out it draws coarser multiples instead of a haze of dots.
The view buttons call ZoomBy, ZoomToFit and ResetViewport. The view is a
parameter as well, with two-way binding (@bind-Viewport), for a zoom field or a minimap of your own;
panning and zooming change only the view, never the document, so they are never an undo step.
The selection and the document, in code
Everything the select tool does is reachable from code. The selection is an object of its own, which drops elements by itself when they leave the document, a collaborator's deletions included. The queries behind the tools are public: hit testing is geometric, so a diagonal stroke is not picked by a marquee that only overlaps its bounding box, and clicking inside an unfilled rectangle does not select it.
BinkSelection selection = _canvas.Selection; selection.Set(id); selection.Toggle(otherId); BinkRect bounds = selection.Bounds; BinkElement? hit = BinkDocumentQuery.HitTest(_document, point, tolerance: 4f); BinkElement? locked = BinkDocumentQuery.HitTest(_document, point, includeLocked: true); // for an "Unlock" menu List<BinkElement> inside = BinkDocumentQuery.FindInRect(_document, rect, BinkRectSelectionMode.Contain); List<BinkElement> lassoed = BinkDocumentQuery.FindInPolygon(_document, loop, coverage: 0.5f); IReadOnlyList<Guid> whole = BinkDocumentQuery.ExpandToGroups(_document, ids); // widened to whole groups, as a click is string payload = BinkClipboard.Serialize(selection.Elements); // what a copy puts on the clipboard
Selection only beside the exports uses BinkExportRegion.Selection, which crops to
the selection and draws nothing else; Page, Content and Custom are the
other regions.
Grouping, locking and lining up
Group makes the selection one thing: clicking any member selects all of it, and a marquee that catches part of it takes the whole group. Groups nest, and Ungroup takes apart one level. Lock keeps elements drawn and exported but out of reach of every tool, so a template stays put while the rest of its layer is edited. Align needs two separate things, distribute three; groups take part as a whole, and flipping keeps text readable. Each command is one undo step.
Guid? group = _canvas.GroupSelection(); // Ctrl+G _canvas.UngroupSelection(); // Ctrl+Shift+G _canvas.LockSelection(); // Ctrl+Shift+L _canvas.UnlockAll(); _canvas.AlignSelection(BinkAlignment.Left); _canvas.DistributeSelection(BinkDistribution.Horizontal); _canvas.FlipSelection(BinkFlipDirection.Horizontal); // Shift+H _canvas.ArrangeSelection(BinkArrangement.BringForward); // Ctrl+]
The same commands are on BinkDocument - GroupElements, SetLocked,
AlignElements, Arrange - for an editor with no canvas.
Layers
Layers are part of the document, not separate HTML canvases, so they are saved, undone and exported exactly as
they look. The board opens with two, Drawing and Annotations; new ink goes on the one chosen in the list
(ActiveLayerId). A hidden or locked layer refuses drawing, erasing, selection, pasting and imports,
and the page says why beside the list rather than putting the ink somewhere nobody chose.
Opacity and Blend apply to the finished layer as one unit: Multiply darkens
like ink on paper, Screen lightens.
BinkLayer notes = _document.AddLayer("Notes"); _document.UpdateLayer(notes.Id, p => p with { Opacity = 0.6f, BlendMode = BinkBlendMode.Multiply }); _document.UpdateLayer(notes.Id, p => p with { IsLocked = true }); _document.ReorderLayer(notes.Id, index: 0); // 0 is the bottom BinkLayer copy = _document.DuplicateLayer(notes.Id); // directly above, with copies of its elements <BinkCanvas Document="_document" ActiveLayerId="_activeLayer" />
Clipboard, dropping and importing
With EnableClipboard on, Ctrl+C, Ctrl+X and Ctrl+V go through the system clipboard: a copy is a small
Bink document, so it pastes into another board or tab, with a PNG of the selection beside it for a chat or an
email. A pasted picture becomes an image element, and pasted plain text a text element unless the page handles
TextPasted. With EnableDrop on, pictures, saved boards and SVG files dragged onto the
canvas land where they are dropped. Both are off by default, which is what a signature field wants.
<BinkCanvas EnableClipboard="true" EnableDrop="true" /> await _canvas.CopySelectionAsync(); await _canvas.PasteAsync(); // for a button; Ctrl+V needs none await _canvas.AddImageAsync(source, position: null, maxWidth: 600f); // Insert image BinkSvgImportResult? result = _canvas.ImportSvg(svgText); // Import SVG
Import SVG turns paths, rectangles, circles, lines, polylines, polygons, text and embedded pictures into editable elements, grouped and selected in one undo step, and says what it left out (gradients, filters, masks and the like). The file is treated as untrusted: nothing is fetched, entities never expand, and scripts and event handlers are ignored.
Saving, autosave and recovery
Save writes the whole board, layers and groups included, as a file that Open
reads back with TryDeserialize, which refuses a bad file with a reason. The status line says when the
board has changed since it was last saved (IsDirty). Separately, the board is kept on this device:
BinkAutosave writes it to the browser's IndexedDB two seconds after editing pauses, and when the page
is opened again it offers the drawing back rather than restoring it unasked.
_store = new BinkBrowserDocumentStore(JS); if (await BinkAutosave.RestoreAsync(_store, "bink-demo-whiteboard") is { } saved) _recovered = saved; _autosave = new BinkAutosave(_document, _store, "bink-demo-whiteboard"); long revision = _document.Revision; await SaveToFileAsync(BinkSerializer.SerializeToUtf8Bytes(_document)); _document.MarkSaved(revision); // what changed while it was being written stays unsaved
Autosave writes two seconds after editing pauses, and at least every thirty seconds while it never does
(Delay, MaxDelay), one write at a time; SaveNowAsync saves at once,
DiscardAsync removes the copy once the application has saved for real, and a store that fails is
reported through SaveFailed and tried again. It is a recovery copy and leaves IsDirty
alone. BinkMemoryDocumentStore keeps documents in memory, and implementing
IBinkDocumentStore - three methods over bytes - keeps them in a database or behind an API.
Export SVG and Export PNG crop to the ink (BinkExportRegion.Content), the PNG at twice the
document's resolution. Every shortcut the board answers to is listed on
input and accessibility.