tldraw icon indicating copy to clipboard operation
tldraw copied to clipboard

[Feature]: Expose size and aspect ratios in export APIs

Open ruiconti opened this issue 2 years ago • 0 comments

What's the feature?

Currently, useExportAs doesn't expose the possibility to define the aspect ratio nor the canvas size of the exported image, nor the Canvas' background image. If we want useExportAs to behave as "export what the user sees" (for e.g thumbnails), and offer greater flexibility for consumers (like me), then those parameters need to be exposed.

Use case

I am rendering TldrawEditor in a resizable canvas, which I am resizing solely using .tl-canvas's width and height properties. However, at exportAs time, I want the shapes to be exported relative to the canvas dimension, which I learned that they do not —editor.getSvg() will infer a bounding box from all existing shapes in the page, which is undesirable in my use case.

https://github.com/tldraw/tldraw/blob/5719cc76c12c379d700e59912edb74127ded218e/packages/editor/src/lib/editor/Editor.ts#L8094-L8119

Temporary workaround

At exportAs time, I add a rectangle GeoShape with opacity:0, that matches the size of the Canvas.

Contact Details

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

ruiconti avatar Nov 01 '23 15:11 ruiconti