# BinkCanvas (Component)
`Bit.Bink.BinkCanvas` - inherits `ComponentBase` - implements `IAsyncDisposable`, `IComponent`, `IHandleAfterRender`, `IHandleEvent`
A drawing surface: pointer, touch and stylus input, high-quality ink rendering, tools, undo/redo and export.
Every await in this component resumes on the renderer's dispatcher (ConfigureAwait(true)). On Blazor Server an interop call completes on a thread-pool thread, and continuing there raised BinkCanvas.Ready off the dispatcher, which takes the circuit down the moment a handler calls StateHasChanged; it also let the overlay be recorded while the dispatcher was processing pointer samples into the same tool, and let an image or a text edit change the document from a second thread. WebAssembly has one thread, which is why it never showed.
The component is a thin shell around the engine in Bit.Bink. It owns two canvases: the document surface holding committed elements, and an overlay holding the live stroke and tool previews. Pointer input never triggers a Blazor render: samples arrive from the browser once per animation frame, the active tool processes them, and only the affected canvas layer is redrawn.
A signature pad:
```
@code {
private BinkCanvas? canvas;
private void Clear() => canvas!.Clear();
private string Save() => canvas!.ExportSvg();
}
```
## Parameter
- **ActiveLayerId** : `Guid?` - The layer new elements are added to. Defaults to the top-most editable layer. While the layer named here is locked or hidden, drawing, shapes, text, pasting, dropping and importing are refused, with the reason announced.
- **AdditionalAttributes** : `IReadOnlyDictionary` - Additional attributes applied to the container element.
- **AriaLabel** : `string` = `"Drawing canvas"` - Accessible name of the canvas.
- **Brush** : `BinkBrush` - The brush used by drawing tools.
- **ChildContent** : `RenderFragment` - Content rendered above the canvas, for toolbars or overlays positioned by the application.
- **Class** : `string` - Extra CSS classes for the container.
- **DisabledShortcuts** : `IReadOnlyCollection` - Keyboard shortcuts the canvas leaves to the page, such as "Ctrl+A" or "Delete": it neither acts on them, nor lets its tools, nor stops the browser's own behaviour, so the surrounding application can give those keys a meaning of its own. Every other shortcut keeps working, unlike turning BinkCanvas.EnableKeyboardShortcuts off. To move a command to another key, list the key here, handle the other one yourself and call the canvas's method for it. Chords are written as BinkShortcut describes.
- **Document** : `BinkDocument` - The document to edit. When null the component creates and owns one, which is what a signature pad or a simple drawing field wants.
- **DocumentChanged** : `EventCallback` = `new EventCallback()` - Raised after any change to the document.
- **EnableClipboard** : `bool` = `false` - Whether Ctrl+C, Ctrl+X and Ctrl+V copy, cut and paste through the system clipboard: selected elements, and pasted images. Off by default, because a signature field that accepts a pasted image or pasted ink no longer proves anyone signed. BinkCanvas.CopySelectionAsync, BinkCanvas.PasteAsync and the other methods work regardless, so an application can offer clipboard buttons of its own.
- **EnableDrop** : `bool` = `false` - Whether image files, and saved drawings (.bink or .json), dragged onto the canvas from the desktop or another page are added where they are dropped. Off by default, for the same reason as BinkCanvas.EnableClipboard: a signature field must not accept a dropped picture of a signature.
- **EnableKeyboardShortcuts** : `bool` = `true` - Whether the built-in keyboard shortcuts (undo, redo, delete, select all, escape) are handled.
- **EnableTouchGestures** : `bool` = `false` - Whether two-finger pan and pinch zoom are handled by the canvas. When false, touch gestures scroll the page instead, which is usually what a small signature field in a form wants.
- **Focusable** : `bool` = `true` - Whether the canvas can receive keyboard focus. Required for keyboard shortcuts.
- **Grid** : `BinkGrid` - A grid drawn behind the drawing as a guide, as lines or dots; null, the default, draws none. It belongs to the view: it is never exported or saved. Set BinkSnapOptions.GridSize to the same spacing to snap to it.
- **Height** : `string` = `"300px"` - CSS height of the canvas element.
- **HistoryChanged** : `EventCallback` = `new EventCallback()` - Raised when the undo or redo stack changes.
- **HistoryLimit** : `int` = `200` - Maximum number of undo steps. Zero disables history.
- **HistoryMemoryBudget** : `long` = `0` - The most memory, in estimated bytes, undo and redo may hold; 0, the default, for no limit besides BinkCanvas.HistoryLimit. See BinkHistoryManager.MemoryBudget.
- **LowLatency** : `bool` = `false` - Whether the canvas is created with the low-latency (desynchronized) hint, which shortens the path from drawing command to pixels on browsers that honor it; BinkInputCapabilities.LowLatencyCanvas reports whether one did. Off by default, because Chromium (seen on Windows with GPU compositing) shows a desynchronized canvas whose pixels are not all opaque - the live stroke's layer always, the document's with a transparent background - as solid black once it sits inside an ancestor that clips to rounded corners (overflow: hidden with a border-radius, an ordinary card). Turn it on for a canvas with no such ancestor, such as a full-screen whiteboard. Read when the canvas attaches; changing it afterwards has no effect.
- **MaxZoom** : `float` = `64` - The largest zoom the wheel, pinch gestures, the keyboard and BinkCanvas.ZoomBy allow.
- **MinZoom** : `float` = `0.05` - The smallest zoom the wheel, pinch gestures, the keyboard and BinkCanvas.ZoomBy allow.
- **PredictInk** : `bool?` - Whether the live stroke is drawn reaching where the browser predicts the pen is going, which hides about a frame of latency on a stylus. Predictions are drawn, never stored. Defaults to on in WebAssembly and off elsewhere, where the round trip to the server is far longer than the frame a prediction covers.
- **ReadOnly** : `bool` = `false` - When true, input is ignored and the drawing is display-only.
- **Ready** : `EventCallback` = `new EventCallback()` - Raised once the canvas is attached and the device capabilities are known.
- **RejectTouchWhilePen** : `bool` = `true` - Whether a finger touch is ignored while a pen is in contact, so a resting palm does not draw.
- **SelectionChanged** : `EventCallback` = `new EventCallback()` - Raised when the selection changes.
- **ShapeStyle** : `BinkShapeStyle` - The style applied to newly created shapes and annotations.
- **Snapping** : `BinkSnapOptions` - How moving, resizing and drawing shapes snap to a grid and to other elements. Null, the default, snaps to nothing; new BinkSnapOptions() lines edges and centres up with other elements and the page.
- **StrokeCompleted** : `EventCallback` = `new EventCallback()` - Raised when a stroke is committed to the document.
- **StrokeStarted** : `EventCallback` = `new EventCallback()` - Raised when a stroke begins. Raised only for drawing tools (BinkDrawTool and subclasses other than the eraser), the same tools whose strokes BinkCanvas.StrokeCompleted reports; selecting, panning, placing a shape or editing text does not raise it.
- **Style** : `string` - Extra inline styles for the container.
- **TextPasted** : `EventCallback` = `new EventCallback()` - Raised when plain text, rather than copied Bink content or an image, is pasted onto the canvas. Without a handler the text becomes a text element in the middle of the view.
- **Tool** : `IBinkTool` - The active tool. Defaults to freehand drawing.
- **Unavailable** : `EventCallback` = `new EventCallback()` - Raised instead of BinkCanvas.Ready when the browser layer cannot start, for example because a content security policy blocks its script, with the reason. The canvas stays inert; BinkCanvas.AttachFailed holds the same reason afterwards.
- **Viewport** : `BinkViewport` = `BinkViewport.Identity` - The viewport (pan and zoom). Supports two-way binding.
- **ViewportChanged** : `EventCallback` = `new EventCallback()` - Raised when the viewport changes, for two-way binding.
- **WetInk** : `bool?` - Whether a provisional trail is drawn in the browser while a sample batch travels to the server. Ignored in WebAssembly, where the engine already runs locally. Defaults to on for interactive server rendering.
- **WheelMode** : `BinkWheelMode` = `BinkWheelMode.None` - What the mouse wheel and a trackpad do over the canvas. The default, BinkWheelMode.None, leaves the wheel to the page, which is right for a canvas embedded in a form that has to stay scrollable.
- **Width** : `string` = `"100%"` - CSS width of the canvas element, for example "100%" or "400px".
## Property
- **ActiveTool** : `IBinkTool` - The active tool.
- **AttachFailed** : `string` - The reason the browser layer could not be attached, or null when everything is working. Applications can surface this to explain why the canvas is not responding.
- **Capabilities** : `BinkInputCapabilities` = `BinkInputCapabilities.None` - What the current device and browser support. Valid once BinkCanvas.Ready has been raised.
- **CurrentDocument** : `BinkDocument` - The document being edited.
- **CurrentViewport** : `BinkViewport` = `BinkViewport.Identity` - The current viewport.
- **ElementId** : `string` - The id of the container element, useful for labelling and testing.
- **History** : `BinkHistoryManager` - Undo and redo for this canvas.
- **Selection** : `BinkSelection` - The current selection.
- **UsesFastRenderPath** : `bool` = `false` - True when the zero-copy WebAssembly rendering path is in use.
- **ViewSize** : `Vector2` = `<0, 0>` - The canvas size in CSS pixels.
## Method
- **AddImageAsync**(BinkImageSource source, Vector2? position = null, float maxWidth = 600) : `Task` - Adds an image to the document, sized to its natural dimensions.
- **AlignSelection**(BinkAlignment alignment, BinkRect? reference = null) : `bool` - Lines the selected elements up on an edge or a centre, as one undoable step. Groups move as a whole. See BinkDocument.AlignElements.
- **Announce**(string message) : `void` - Announces a message to screen readers through the canvas live region.
- **ArrangeSelection**(BinkArrangement arrangement) : `bool` - Changes the stacking order of the selected elements within their layers, as one undoable step.
- **Clear**() : `void` - Removes every element, as one undoable step.
- **CopySelectionAsync**() : `Task` - Copies the selected elements to the system clipboard, and keeps a copy for this canvas in case the browser refuses the write. Returns false when nothing is selected.
- **CutSelectionAsync**() : `Task` - Copies the selected elements to the clipboard and deletes them, as one undoable step.
- **DeleteSelection**() : `void` - Deletes the selected elements.
- **DisposeAsync**() : `ValueTask`
- **DistributeSelection**(BinkDistribution axis) : `bool` - Spaces the selected elements out with equal gaps, as one undoable step; the outermost two stay put. Needs at least three separate elements or groups. See BinkDocument.DistributeElements.
- **DuplicateSelection**(Vector2? offset = null) : `int` - Duplicates the selected elements a short distance away and selects the copies, as one undoable step.
- **ExportImageAsync**(BinkImageFormat format, BinkPngExportOptions options = null, double quality = 0.92, CancellationToken cancellationToken = null) : `Task` - Exports the drawing as a PNG, JPEG or WebP image, encoded by the browser. JPEG has no transparency, so a transparent background is exported as white.
- **ExportPdf**(BinkPdfExportOptions options = null) : `BinkPdfExportResult` - Exports the drawing as a one-page PDF and reports what could not be drawn. The work happens in .NET, like the SVG export, so it needs nothing from the browser; see BinkPdfExporter. With BinkExportRegion.Selection and no ids given, the canvas's selection is exported.
- **ExportPngAsync**(BinkPngExportOptions options = null, CancellationToken cancellationToken = null) : `Task` - Exports the drawing as a PNG. Rendering happens in the browser, so real fonts and every image format the browser supports are included.
- **ExportSvg**(BinkSvgExportOptions options = null) : `string` - Exports the drawing as SVG. This is synchronous work: SVG generation happens entirely in .NET and needs nothing from the browser.
- **ExportSvgAsync**(BinkSvgExportOptions options = null) : `Task` - Exports the drawing as SVG. Provided for symmetry with BinkCanvas.ExportPngAsync; the work itself is synchronous, so BinkCanvas.ExportSvg is equivalent and avoids a needless state machine.
- **FlipSelection**(BinkFlipDirection direction) : `bool` - Mirrors the selected elements about the centre of the selection, as one undoable step. Text moves but stays readable. See BinkDocument.FlipElements.
- **GroupSelection**() : `Guid?` - Groups the selected elements, as one undoable step, so that picking any of them picks them all. They stay selected. See BinkDocument.GroupElements.
- **ImportSvg**(string svg, Vector2? center = null, BinkSvgImportOptions options = null) : `BinkSvgImportResult` - Imports SVG as editable elements (see BinkSvgImporter) onto the active layer, grouped when there is more than one, and selects them, as one undoable step. What could not be imported is announced.
- **LoadDocument**(BinkDocument document) : `void` - Replaces the document being edited and resets history and selection.
- **LoadImageAsync**(BinkImageSource source) : `Task` - Decodes an image in the browser without adding it to the document, and returns the source with its natural size filled in. Use it before a history group or batch that places the image: the decode is a browser round trip, and a group left open across one disables undo until it closes.
- **LockSelection**() : `int` - Locks the selected elements, as one undoable step. Locked elements stay visible but cannot be selected, moved or erased, so they also leave the selection. Use BinkCanvas.UnlockAll, or BinkDocument.SetLocked for particular elements, to unlock them.
- **Paste**(string payload, Vector2? position = null) : `int` - Pastes copied elements onto the active layer and selects them, as one undoable step. A repeated paste of the same copy steps down and to the right, and a paste that would land outside the view lands in its middle.
- **PasteAsync**() : `Task` - Pastes from the system clipboard, falling back to what this canvas copied last when the browser refuses to read it. Use it for a paste button; Ctrl+V reaches the canvas without it when BinkCanvas.EnableClipboard is on.
- **PickColorAsync**(CancellationToken cancellationToken = null) : `Task` - Lets the user pick a colour from anywhere on the screen with the browser's eyedropper, for a colour picker's "pick from screen" button. Call it straight from the click: the browser only opens the eyedropper while the click's user activation lasts.
- **Redo**() : `bool` - Redoes the last undone change. Returns false when there is nothing to redo.
- **Refresh**() : `void` - Requests a redraw of the whole canvas.
- **ResetViewport**() : `void` - Resets pan and zoom.
- **SaveImageAsync**(string fileName, BinkImageFormat format, BinkPngExportOptions options = null, double quality = 0.92, CancellationToken cancellationToken = null) : `Task` - Exports the drawing as an image and offers it to the user as a file download.
- **SavePdfAsync**(string fileName = "drawing.pdf", BinkPdfExportOptions options = null) : `Task` - Exports the drawing as a PDF and offers it to the user as a file download.
- **SavePngAsync**(string fileName = "drawing.png", BinkPngExportOptions options = null, CancellationToken cancellationToken = null) : `Task` - Exports the drawing as a PNG and offers it to the user as a file download.
- **SaveSvgAsync**(string fileName = "drawing.svg", BinkSvgExportOptions options = null) : `Task` - Exports the drawing as SVG and offers it to the user as a file download.
- **SelectAll**() : `void` - Selects every element on unlocked, visible layers.
- **SetTool**(IBinkTool tool) : `void` - Replaces the active tool.
- **SetViewport**(BinkViewport viewport) : `void` - Sets the viewport, notifying BinkCanvas.ViewportChanged.
- **SupportsEyeDropperAsync**() : `Task` - Whether the browser has an eyedropper for BinkCanvas.PickColorAsync, to decide whether to offer one.
- **Undo**() : `bool` - Undoes the last change. Returns false when there is nothing to undo.
- **UngroupSelection**() : `bool` - Takes the selected groups apart one level, as one undoable step. Groups nested inside them stay intact. See BinkDocument.UngroupElements.
- **UnlockAll**() : `int` - Unlocks every locked element, as one undoable step.
- **ZoomBy**(float factor) : `void` - Zooms around the center of the view, within BinkCanvas.MinZoom and BinkCanvas.MaxZoom.
- **ZoomToFit**(float padding = 24) : `void` - Fits the drawing into the visible area.