tldraw / tldraw

SDK for creating whiteboards and canvas experiences on the web.
https://tldraw.dev
Other
33.9k stars 2.04k forks source link

Add component for viewing an image of a snapshot #2804

Closed TodePond closed 4 months ago

TodePond commented 4 months ago

This PR adds the TldrawImage component that displays a tldraw snapshot as an SVG image.

2024-02-15 at 12 29 52 - Coral Cod

Why

We've seen requests for this kind of thing from users. eg: GitBook, and on discord:

image

The component provides a way to do that. This PR also untangles various bits of editor state from image exporting, which makes it easier for library users to export images more agnostically. (ie: they can now export any shapes on any page in any theme. previously, they had to change the user's state to do that).

What else

Any issues?

When you toggle to editing mode in the new example, text measurements are initially wrong (until you edit the size of a text shape). Click on the text shape to see how its indicator is wrong. Not sure why this is, or if it's even related. Does it ring a bell with anyone? If not, I'll take a closer look. (fixed, see comments --steve)

Future work

Now that we've untangled image exporting from editor state, we could expose some more helpful helpers for making this easier.

Fixes tld-2122

Change Type

[^1]: publishes a patch release, for devDependencies use internal [^2]: will not publish a new version

Test Plan

  1. Open the Image snapshot example.
  2. Try editing the image, saving the image, and making sure the image updates.

Release Notes

vercel[bot] commented 4 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
examples ✅ Ready (Inspect) Visit Preview Feb 16, 2024 1:49pm
1 Ignored Deployment | Name | Status | Preview | Updated (UTC) | | :--- | :----- | :------ | :------ | | **tldraw-docs** | ⬜️ Ignored ([Inspect](https://vercel.com/tldraw/tldraw-docs/5fLxTAVyTQXabJXMDpNpcp1ctKVP)) | [Visit Preview](https://tldraw-docs-git-lu-tldraw-image-tldraw.vercel.app) | Feb 16, 2024 1:49pm |
steveruizok commented 4 months ago

viewport / page?

TodePond commented 4 months ago

viewport / page?

as props? yes that would be good. im planning to add some props for things like page, background, etc

linear[bot] commented 4 months ago

TLD-2122 TldrawImage

steveruizok commented 4 months ago

Riding in some changes here Lu:

steveruizok commented 4 months ago

There seems to be a problem with text measurement, not sure if this is particular to this project or to tldraw in general.

steveruizok commented 4 months ago

Kind of an unusual add here, but we didn't have the ability to zoom to a specific bounds without also adding an inset. I've combined the inset property with the animations object on zoomToBounds. This is pretty obscure (usually called via methods like zoomToSelection) and I think would have been considered a bug for anyone calling it directly.

steveruizok commented 4 months ago

Added format option for SVG or PNG.

steveruizok commented 4 months ago

Text measurements are wrong because the container is not getting tldraw's styles mounted to it.

steveruizok commented 4 months ago

The text issues should be fixed now. When we do text measurement, we mount the measurement div into the container, so the container needs to have our styles on it.

TodePond commented 4 months ago

nice one, thanks for the changes Steve. Looks good