tldraw/packages
Lu Wilson f5b95d5df2
Don't bother measuring canvas max size for small images (#2442)
This PR makes it so we don't bother measuring the max size of your
browser canvas - if you're manipulating an image that is relatively
small (ie: less than 8K resolution).

Closes #2433 

@SomeHats I reckon this has some conflicts with your PR, #2441 

## Why?

Calculating the max canvas size... takes a long time on some devices,
eg: Android Chrome.

Most of the time, you don't need such a big canvas anyway. When you're
exporting/importing a small image, we can assume that the max size will
be big enough (based on some testing
[here](https://github.com/jhildenbiddle/canvas-size?tab=readme-ov-file#test-results)).
So we don't need to bother in those cases - speeding up the operation.

If you're manipulating a larger image, we measure the max canvas size -
as before.

## Anything else?

This PR also moves the 'clamping' code to one place. Previously, it was
repeated in three places, and it was annoying having to update them all
at the same time.

## What's next?

Measuring for large images is still slow. We should look at how to make
that experience better. eg: Visual feedback that it's happening. eg: Try
not to block the main UI thread. eg: Can we do anything in parallel?

### Change Type

- [x] `patch` — Bug fix
- [ ] `minor` — New feature
- [ ] `major` — Breaking change
- [ ] `dependencies` — Changes to package dependencies[^1]
- [ ] `documentation` — Changes to the documentation only[^2]
- [ ] `tests` — Changes to any test code only[^2]
- [ ] `internal` — Any other changes that don't affect the published
package[^2]
- [ ] I don't know

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

### Test Plan

1. Draw some shapes.
2. Select them.
3. Copy/export as png.
4. Repeat with various sizes of shapes. eg: Select shapes over a large
area, so that your exported image is larger than 8K resolution.

- [ ] Unit Tests
- [ ] End to end tests

### Release Notes

- Android: Sped up exporting and importing images.
2024-01-10 17:58:18 +00:00
..
assets Update CHANGELOG.md [skip ci] 2024-01-10 12:03:59 +00:00
editor [improvement] account for coarse pointers / insets in edge scrolling (#2401) 2024-01-10 14:29:32 +00:00
state Update CHANGELOG.md [skip ci] 2024-01-10 12:03:59 +00:00
store Update CHANGELOG.md [skip ci] 2024-01-10 12:03:59 +00:00
tldraw Don't bother measuring canvas max size for small images (#2442) 2024-01-10 17:58:18 +00:00
tlschema [Minor] change Simplified Chinese label to Chinese (#2434) 2024-01-10 15:30:25 +00:00
utils faster image processing in default asset handler (#2441) 2024-01-10 14:41:18 +00:00
validate Update CHANGELOG.md [skip ci] 2024-01-10 12:03:59 +00:00