tldraw 4.3.0-canary.ef0248947f13 → 4.3.0-canary.ef709265bb13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/dist-cjs/index.js +1 -1
  2. package/dist-cjs/lib/canvas/TldrawSelectionForeground.js +2 -2
  3. package/dist-cjs/lib/canvas/TldrawSelectionForeground.js.map +2 -2
  4. package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js +5 -10
  5. package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js.map +2 -2
  6. package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js +3 -3
  7. package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js.map +2 -2
  8. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js +1 -1
  9. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js.map +2 -2
  10. package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js +3 -4
  11. package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js.map +2 -2
  12. package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js +1 -1
  13. package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js.map +2 -2
  14. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js +4 -5
  15. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js.map +2 -2
  16. package/dist-cjs/lib/shapes/shared/HyperlinkButton.js +2 -1
  17. package/dist-cjs/lib/shapes/shared/HyperlinkButton.js.map +2 -2
  18. package/dist-cjs/lib/shapes/shared/ShapeFill.js +2 -2
  19. package/dist-cjs/lib/shapes/shared/ShapeFill.js.map +2 -2
  20. package/dist-cjs/lib/shapes/shared/{useForceSolid.js → useEfficientZoomThreshold.js} +10 -7
  21. package/dist-cjs/lib/shapes/shared/useEfficientZoomThreshold.js.map +7 -0
  22. package/dist-cjs/lib/shapes/shared/useImageOrVideoAsset.js +1 -1
  23. package/dist-cjs/lib/shapes/shared/useImageOrVideoAsset.js.map +2 -2
  24. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js +1 -1
  25. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js.map +2 -2
  26. package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenuContent.js +3 -9
  27. package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenuContent.js.map +2 -2
  28. package/dist-cjs/lib/ui/components/ZoomMenu/DefaultZoomMenu.js +1 -1
  29. package/dist-cjs/lib/ui/components/ZoomMenu/DefaultZoomMenu.js.map +2 -2
  30. package/dist-cjs/lib/ui/components/menu-items.js +3 -1
  31. package/dist-cjs/lib/ui/components/menu-items.js.map +2 -2
  32. package/dist-cjs/lib/ui/version.js +3 -3
  33. package/dist-cjs/lib/ui/version.js.map +1 -1
  34. package/dist-esm/index.mjs +1 -1
  35. package/dist-esm/lib/canvas/TldrawSelectionForeground.mjs +2 -2
  36. package/dist-esm/lib/canvas/TldrawSelectionForeground.mjs.map +2 -2
  37. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs +6 -12
  38. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
  39. package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs +3 -3
  40. package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs.map +2 -2
  41. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs +1 -1
  42. package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs.map +2 -2
  43. package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs +3 -4
  44. package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs.map +2 -2
  45. package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs +1 -1
  46. package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs.map +2 -2
  47. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs +4 -5
  48. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs.map +2 -2
  49. package/dist-esm/lib/shapes/shared/HyperlinkButton.mjs +3 -2
  50. package/dist-esm/lib/shapes/shared/HyperlinkButton.mjs.map +2 -2
  51. package/dist-esm/lib/shapes/shared/ShapeFill.mjs +2 -2
  52. package/dist-esm/lib/shapes/shared/ShapeFill.mjs.map +2 -2
  53. package/dist-esm/lib/shapes/shared/useEfficientZoomThreshold.mjs +12 -0
  54. package/dist-esm/lib/shapes/shared/useEfficientZoomThreshold.mjs.map +7 -0
  55. package/dist-esm/lib/shapes/shared/useImageOrVideoAsset.mjs +1 -1
  56. package/dist-esm/lib/shapes/shared/useImageOrVideoAsset.mjs.map +2 -2
  57. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs +1 -1
  58. package/dist-esm/lib/shapes/video/VideoShapeUtil.mjs.map +2 -2
  59. package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenuContent.mjs +2 -8
  60. package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenuContent.mjs.map +2 -2
  61. package/dist-esm/lib/ui/components/ZoomMenu/DefaultZoomMenu.mjs +1 -1
  62. package/dist-esm/lib/ui/components/ZoomMenu/DefaultZoomMenu.mjs.map +2 -2
  63. package/dist-esm/lib/ui/components/menu-items.mjs +3 -1
  64. package/dist-esm/lib/ui/components/menu-items.mjs.map +2 -2
  65. package/dist-esm/lib/ui/version.mjs +3 -3
  66. package/dist-esm/lib/ui/version.mjs.map +1 -1
  67. package/package.json +3 -3
  68. package/src/lib/canvas/TldrawSelectionForeground.tsx +2 -2
  69. package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +6 -11
  70. package/src/lib/shapes/draw/DrawShapeUtil.tsx +3 -3
  71. package/src/lib/shapes/frame/FrameShapeUtil.tsx +1 -1
  72. package/src/lib/shapes/geo/GeoShapeUtil.tsx +3 -4
  73. package/src/lib/shapes/highlight/HighlightShapeUtil.tsx +1 -1
  74. package/src/lib/shapes/note/NoteShapeUtil.tsx +6 -8
  75. package/src/lib/shapes/shared/HyperlinkButton.tsx +3 -2
  76. package/src/lib/shapes/shared/ShapeFill.tsx +2 -2
  77. package/src/lib/shapes/shared/useEfficientZoomThreshold.ts +10 -0
  78. package/src/lib/shapes/shared/useImageOrVideoAsset.ts +1 -1
  79. package/src/lib/shapes/video/VideoShapeUtil.tsx +2 -1
  80. package/src/lib/ui/components/ActionsMenu/DefaultActionsMenuContent.tsx +1 -9
  81. package/src/lib/ui/components/ZoomMenu/DefaultZoomMenu.tsx +1 -1
  82. package/src/lib/ui/components/menu-items.tsx +3 -1
  83. package/src/lib/ui/version.ts +3 -3
  84. package/src/test/commands/cameraState.test.ts +299 -0
  85. package/dist-cjs/lib/shapes/shared/useForceSolid.js.map +0 -7
  86. package/dist-esm/lib/shapes/shared/useForceSolid.mjs +0 -9
  87. package/dist-esm/lib/shapes/shared/useForceSolid.mjs.map +0 -7
  88. package/src/lib/shapes/shared/useForceSolid.ts +0 -6
@@ -1,13 +1,14 @@
1
- import { useEditor, useValue } from '@tldraw/editor'
1
+ import { useEditor } from '@tldraw/editor'
2
2
  import classNames from 'classnames'
3
3
  import { PointerEventHandler, useCallback } from 'react'
4
+ import { useEfficientZoomThreshold } from './useEfficientZoomThreshold'
4
5
 
5
6
  const LINK_ICON =
6
7
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' fill='none'%3E%3Cpath stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M13 5H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6M19 5h6m0 0v6m0-6L13 17'/%3E%3C/svg%3E"
7
8
 
8
9
  export function HyperlinkButton({ url }: { url: string }) {
9
10
  const editor = useEditor()
10
- const hideButton = useValue('zoomLevel', () => editor.getZoomLevel() < 0.32, [editor])
11
+ const hideButton = useEfficientZoomThreshold()
11
12
  const markAsHandledOnShiftKey = useCallback<PointerEventHandler>(
12
13
  (e) => {
13
14
  if (!editor.inputs.shiftKey) editor.markEventAsHandled(e)
@@ -50,10 +50,10 @@ export const ShapeFill = React.memo(function ShapeFill({
50
50
  export function PatternFill({ d, color, theme }: ShapeFillProps) {
51
51
  const editor = useEditor()
52
52
  const svgExport = useSvgExportContext()
53
- const zoomLevel = useValue('zoomLevel', () => editor.getZoomLevel(), [editor])
53
+ const zoomLevel = useValue('zoomLevel', () => editor.getEfficientZoomLevel(), [editor])
54
54
  const getHashPatternZoomName = useGetHashPatternZoomName()
55
55
 
56
- const teenyTiny = editor.getZoomLevel() <= 0.18
56
+ const teenyTiny = zoomLevel <= 0.18
57
57
 
58
58
  return (
59
59
  <>
@@ -0,0 +1,10 @@
1
+ import { useEditor, useValue } from '@tldraw/editor'
2
+
3
+ /** Returns true when zoomed out far enough that shapes should render in a simplified "solid" style. */
4
+ export function useEfficientZoomThreshold(threshold = 0.25) {
5
+ const editor = useEditor()
6
+ return useValue('efficient zoom threshold', () => editor.getEfficientZoomLevel() < threshold, [
7
+ editor,
8
+ threshold,
9
+ ])
10
+ }
@@ -96,7 +96,7 @@ export function useImageOrVideoAsset({ shapeId, assetId, width }: UseImageOrVide
96
96
 
97
97
  const screenScale = exportInfo
98
98
  ? exportInfo.scale * (width / asset.props.w)
99
- : editor.getZoomLevel() * (width / asset.props.w)
99
+ : editor.getEfficientZoomLevel() * (width / asset.props.w)
100
100
 
101
101
  function resolve(asset: TLImageAsset | TLVideoAsset, url: string | null) {
102
102
  if (isCancelled) return // don't update if the hook has remounted
@@ -95,7 +95,8 @@ export class VideoShapeUtil extends BaseBoxShapeUtil<TLVideoShape> {
95
95
 
96
96
  const VideoShape = memo(function VideoShape({ shape }: { shape: TLVideoShape }) {
97
97
  const editor = useEditor()
98
- const showControls = editor.getShapeGeometry(shape).bounds.w * editor.getZoomLevel() >= 110
98
+ const showControls =
99
+ editor.getShapeGeometry(shape).bounds.w * editor.getEfficientZoomLevel() >= 110
99
100
  const isEditing = useIsEditing(shape.id)
100
101
  const prefersReducedMotion = usePrefersReducedMotion()
101
102
  const { Spinner } = useEditorComponents()
@@ -1,4 +1,3 @@
1
- import { useEditor, useValue } from '@tldraw/editor'
2
1
  import { PORTRAIT_BREAKPOINT } from '../../constants'
3
2
  import { useBreakpoint } from '../../context/breakpoints'
4
3
  import {
@@ -9,6 +8,7 @@ import {
9
8
  useThreeStackableItems,
10
9
  useUnlockedSelectedShapesCount,
11
10
  } from '../../hooks/menu-hooks'
11
+ import { ZoomTo100MenuItem } from '../menu-items'
12
12
  import { TldrawUiMenuActionItem } from '../primitives/menus/TldrawUiMenuActionItem'
13
13
 
14
14
  /** @public @react */
@@ -99,14 +99,6 @@ export function ZoomOrRotateMenuItem() {
99
99
  }
100
100
  /** @public @react */
101
101
 
102
- export function ZoomTo100MenuItem() {
103
- const editor = useEditor()
104
- const isZoomedTo100 = useValue('zoom is 1', () => editor.getZoomLevel() === 1, [editor])
105
-
106
- return <TldrawUiMenuActionItem actionId="zoom-to-100" disabled={isZoomedTo100} />
107
- }
108
- /** @public @react */
109
-
110
102
  export function RotateCCWMenuItem() {
111
103
  const oneSelected = useUnlockedSelectedShapesCount(1)
112
104
  const isInSelectState = useIsInSelectState()
@@ -48,7 +48,7 @@ export const DefaultZoomMenu = memo(function DefaultZoomMenu({ children }: TLUiZ
48
48
  const ZoomTriggerButton = () => {
49
49
  const editor = useEditor()
50
50
  const breakpoint = useBreakpoint()
51
- const zoom = useValue('zoom', () => editor.getZoomLevel(), [editor])
51
+ const zoom = useValue('zoom', () => editor.getEfficientZoomLevel(), [editor])
52
52
  const msg = useTranslation()
53
53
 
54
54
  const handleDoubleClick = useCallback(() => {
@@ -182,7 +182,9 @@ export function UnlockAllMenuItem() {
182
182
  /** @public @react */
183
183
  export function ZoomTo100MenuItem() {
184
184
  const editor = useEditor()
185
- const isZoomedTo100 = useValue('zoomed to 100', () => editor.getZoomLevel() === 1, [editor])
185
+ const isZoomedTo100 = useValue('zoomed to 100', () => editor.getEfficientZoomLevel() === 1, [
186
+ editor,
187
+ ])
186
188
 
187
189
  return <TldrawUiMenuActionItem actionId="zoom-to-100" noClose disabled={isZoomedTo100} />
188
190
  }
@@ -1,9 +1,9 @@
1
1
  // This file is automatically generated by internal/scripts/refresh-assets.ts.
2
2
  // Do not edit manually. Or do, I'm a comment, not a cop.
3
3
 
4
- export const version = '4.3.0-canary.ef0248947f13'
4
+ export const version = '4.3.0-canary.ef709265bb13'
5
5
  export const publishDates = {
6
6
  major: '2025-09-18T14:39:22.803Z',
7
- minor: '2025-12-05T17:44:11.680Z',
8
- patch: '2025-12-05T17:44:11.680Z',
7
+ minor: '2025-12-06T09:01:14.443Z',
8
+ patch: '2025-12-06T09:01:14.443Z',
9
9
  }
@@ -0,0 +1,299 @@
1
+ import { Box } from '@tldraw/editor'
2
+ import { TestEditor } from '../TestEditor'
3
+
4
+ let editor: TestEditor
5
+
6
+ beforeEach(() => {
7
+ editor = new TestEditor()
8
+ editor.updateViewportScreenBounds(new Box(0, 0, 1600, 900))
9
+ })
10
+
11
+ describe('getCameraState', () => {
12
+ it('starts as idle', () => {
13
+ expect(editor.getCameraState()).toBe('idle')
14
+ })
15
+
16
+ it('becomes moving when the camera changes via setCamera', () => {
17
+ expect(editor.getCameraState()).toBe('idle')
18
+ editor.setCamera({ x: 100, y: 100, z: 1 })
19
+ expect(editor.getCameraState()).toBe('moving')
20
+ })
21
+
22
+ it('becomes moving when the camera changes via pan', () => {
23
+ expect(editor.getCameraState()).toBe('idle')
24
+ editor.pan({ x: 100, y: 100 })
25
+ expect(editor.getCameraState()).toBe('moving')
26
+ })
27
+
28
+ it('becomes moving when the camera changes via zoomIn', () => {
29
+ expect(editor.getCameraState()).toBe('idle')
30
+ editor.zoomIn(undefined, { immediate: true })
31
+ expect(editor.getCameraState()).toBe('moving')
32
+ })
33
+
34
+ it('returns to idle after the timeout elapses', () => {
35
+ expect(editor.getCameraState()).toBe('idle')
36
+ editor.setCamera({ x: 100, y: 100, z: 1 })
37
+ expect(editor.getCameraState()).toBe('moving')
38
+
39
+ // The default timeout is 64ms (options.cameraMovingTimeoutMs)
40
+ // Each tick is 16ms, so we need ~4 ticks to elapse
41
+ editor.forceTick(5)
42
+ expect(editor.getCameraState()).toBe('idle')
43
+ })
44
+
45
+ it('stays moving while camera continues to change', () => {
46
+ expect(editor.getCameraState()).toBe('idle')
47
+ editor.setCamera({ x: 100, y: 100, z: 1 })
48
+ expect(editor.getCameraState()).toBe('moving')
49
+
50
+ // Move again before timeout elapses
51
+ editor.forceTick(2)
52
+ editor.setCamera({ x: 200, y: 200, z: 1 })
53
+ expect(editor.getCameraState()).toBe('moving')
54
+
55
+ // Move again
56
+ editor.forceTick(2)
57
+ editor.setCamera({ x: 300, y: 300, z: 1 })
58
+ expect(editor.getCameraState()).toBe('moving')
59
+
60
+ // Now let it settle
61
+ editor.forceTick(5)
62
+ expect(editor.getCameraState()).toBe('idle')
63
+ })
64
+
65
+ it('stays idle when camera position does not actually change', () => {
66
+ expect(editor.getCameraState()).toBe('idle')
67
+
68
+ // Setting the same camera position should not trigger moving state
69
+ const currentCamera = editor.getCamera()
70
+ editor.setCamera({ x: currentCamera.x, y: currentCamera.y, z: currentCamera.z })
71
+ expect(editor.getCameraState()).toBe('idle')
72
+ })
73
+
74
+ it('does not add multiple tick listeners when camera changes rapidly', () => {
75
+ // This test verifies the fix: we should not have redundant listeners
76
+ expect(editor.getCameraState()).toBe('idle')
77
+
78
+ // Change camera multiple times rapidly
79
+ editor.setCamera({ x: 100, y: 100, z: 1 })
80
+ editor.setCamera({ x: 200, y: 200, z: 1 })
81
+ editor.setCamera({ x: 300, y: 300, z: 1 })
82
+
83
+ expect(editor.getCameraState()).toBe('moving')
84
+
85
+ // After timeout, should return to idle exactly once
86
+ // If there were multiple listeners, the state might behave unexpectedly
87
+ editor.forceTick(5)
88
+ expect(editor.getCameraState()).toBe('idle')
89
+ })
90
+
91
+ it('resets timeout when camera changes while already moving', () => {
92
+ expect(editor.getCameraState()).toBe('idle')
93
+ editor.setCamera({ x: 100, y: 100, z: 1 })
94
+ expect(editor.getCameraState()).toBe('moving')
95
+
96
+ // Wait almost until timeout
97
+ editor.forceTick(3)
98
+ expect(editor.getCameraState()).toBe('moving')
99
+
100
+ // Change camera again - should reset timeout
101
+ editor.setCamera({ x: 200, y: 200, z: 1 })
102
+ expect(editor.getCameraState()).toBe('moving')
103
+
104
+ // Wait 3 more ticks - would have been idle if timeout wasn't reset
105
+ editor.forceTick(3)
106
+ expect(editor.getCameraState()).toBe('moving')
107
+
108
+ // Now let it fully settle
109
+ editor.forceTick(3)
110
+ expect(editor.getCameraState()).toBe('idle')
111
+ })
112
+ })
113
+
114
+ describe('camera state with zoom', () => {
115
+ it('becomes moving on zoomOut', () => {
116
+ expect(editor.getCameraState()).toBe('idle')
117
+ editor.zoomOut(undefined, { immediate: true })
118
+ expect(editor.getCameraState()).toBe('moving')
119
+ })
120
+
121
+ it('becomes moving on centerOnPoint', () => {
122
+ expect(editor.getCameraState()).toBe('idle')
123
+ editor.centerOnPoint({ x: 500, y: 500 })
124
+ expect(editor.getCameraState()).toBe('moving')
125
+ })
126
+
127
+ it('becomes moving on zoomToFit', () => {
128
+ // Create a shape so zoomToFit has something to fit
129
+ editor.createShape({ type: 'geo', x: 100, y: 100, props: { w: 200, h: 200 } })
130
+ expect(editor.getCameraState()).toBe('idle')
131
+ editor.zoomToFit({ immediate: true })
132
+ expect(editor.getCameraState()).toBe('moving')
133
+ })
134
+ })
135
+
136
+ describe('getDebouncedZoomLevel', () => {
137
+ it('returns the current zoom level when camera is idle', () => {
138
+ expect(editor.getCameraState()).toBe('idle')
139
+ expect(editor.getDebouncedZoomLevel()).toBe(editor.getZoomLevel())
140
+
141
+ // Change zoom and let it settle
142
+ editor.zoomIn(undefined, { immediate: true })
143
+ editor.forceTick(5)
144
+ expect(editor.getCameraState()).toBe('idle')
145
+ expect(editor.getDebouncedZoomLevel()).toBe(editor.getZoomLevel())
146
+ })
147
+
148
+ it('captures zoom when camera starts moving', () => {
149
+ expect(editor.getCameraState()).toBe('idle')
150
+
151
+ // Start zooming - the debounced zoom is captured when movement starts
152
+ editor.zoomIn(undefined, { immediate: true })
153
+ expect(editor.getCameraState()).toBe('moving')
154
+
155
+ // The debounced zoom is captured at the moment movement starts (after first change)
156
+ const capturedZoom = editor.getDebouncedZoomLevel()
157
+ expect(capturedZoom).toBe(editor.getZoomLevel())
158
+ })
159
+
160
+ it('keeps captured zoom during continued camera movement', () => {
161
+ // Start zooming
162
+ editor.zoomIn(undefined, { immediate: true })
163
+ const capturedZoom = editor.getDebouncedZoomLevel()
164
+ expect(editor.getCameraState()).toBe('moving')
165
+
166
+ // Zoom again while still moving - debounced value should stay the same
167
+ editor.zoomIn(undefined, { immediate: true })
168
+ expect(editor.getCameraState()).toBe('moving')
169
+ expect(editor.getDebouncedZoomLevel()).toBe(capturedZoom)
170
+
171
+ // But current zoom should have changed
172
+ expect(editor.getZoomLevel()).not.toBe(capturedZoom)
173
+ })
174
+
175
+ it('updates debounced zoom when camera becomes idle again', () => {
176
+ // Start zooming
177
+ editor.zoomIn(undefined, { immediate: true })
178
+ const capturedZoom = editor.getDebouncedZoomLevel()
179
+
180
+ // Zoom again while moving to change the current zoom
181
+ editor.zoomIn(undefined, { immediate: true })
182
+ expect(editor.getDebouncedZoomLevel()).toBe(capturedZoom)
183
+
184
+ // Let camera settle
185
+ editor.forceTick(5)
186
+ expect(editor.getCameraState()).toBe('idle')
187
+
188
+ // Debounced zoom should now match current zoom
189
+ expect(editor.getDebouncedZoomLevel()).toBe(editor.getZoomLevel())
190
+ })
191
+
192
+ it('captures new zoom at the start of each new movement', () => {
193
+ // First zoom and settle
194
+ editor.zoomIn(undefined, { immediate: true })
195
+ const firstCapturedZoom = editor.getDebouncedZoomLevel()
196
+ editor.forceTick(5)
197
+ expect(editor.getCameraState()).toBe('idle')
198
+
199
+ // Second zoom - should capture new zoom level
200
+ editor.zoomIn(undefined, { immediate: true })
201
+ expect(editor.getCameraState()).toBe('moving')
202
+ // The captured zoom should be different from the first capture
203
+ expect(editor.getDebouncedZoomLevel()).not.toBe(firstCapturedZoom)
204
+ // And it should match the current zoom (since we just started moving)
205
+ expect(editor.getDebouncedZoomLevel()).toBe(editor.getZoomLevel())
206
+ })
207
+
208
+ describe('with debouncedZoom option disabled', () => {
209
+ let editorWithoutDebouncedZoom: TestEditor
210
+
211
+ beforeEach(() => {
212
+ editorWithoutDebouncedZoom = new TestEditor({
213
+ options: { debouncedZoom: false },
214
+ })
215
+ editorWithoutDebouncedZoom.updateViewportScreenBounds(new Box(0, 0, 1600, 900))
216
+ })
217
+
218
+ it('always returns the current zoom level even when camera is moving', () => {
219
+ const initialZoom = editorWithoutDebouncedZoom.getZoomLevel()
220
+
221
+ editorWithoutDebouncedZoom.zoomIn(undefined, { immediate: true })
222
+ expect(editorWithoutDebouncedZoom.getCameraState()).toBe('moving')
223
+
224
+ // Should return the current zoom, not the captured one
225
+ expect(editorWithoutDebouncedZoom.getDebouncedZoomLevel()).toBe(
226
+ editorWithoutDebouncedZoom.getZoomLevel()
227
+ )
228
+ expect(editorWithoutDebouncedZoom.getDebouncedZoomLevel()).not.toBe(initialZoom)
229
+ })
230
+ })
231
+ })
232
+
233
+ describe('getEfficientZoomLevel', () => {
234
+ it('returns current zoom level when below shape threshold', () => {
235
+ // Default threshold is 500 shapes, we have 0
236
+ expect(editor.getZoomLevel()).toBe(editor.getEfficientZoomLevel())
237
+
238
+ // Add a few shapes - still below threshold
239
+ for (let i = 0; i < 10; i++) {
240
+ editor.createShape({ type: 'geo', x: i * 100, y: 0, props: { w: 50, h: 50 } })
241
+ }
242
+ expect(editor.getCurrentPageShapeIds().size).toBe(10)
243
+
244
+ // Start zooming
245
+ editor.zoomIn(undefined, { immediate: true })
246
+ expect(editor.getCameraState()).toBe('moving')
247
+
248
+ // Should still return current zoom because we're below threshold
249
+ expect(editor.getEfficientZoomLevel()).toBe(editor.getZoomLevel())
250
+ })
251
+
252
+ describe('with many shapes above threshold', () => {
253
+ let editorWithManyShapes: TestEditor
254
+
255
+ beforeEach(() => {
256
+ // Use a lower threshold for testing
257
+ editorWithManyShapes = new TestEditor({
258
+ options: { debouncedZoomThreshold: 5 },
259
+ })
260
+ editorWithManyShapes.updateViewportScreenBounds(new Box(0, 0, 1600, 900))
261
+
262
+ // Add shapes above the threshold
263
+ for (let i = 0; i < 10; i++) {
264
+ editorWithManyShapes.createShape({
265
+ type: 'geo',
266
+ x: i * 100,
267
+ y: 0,
268
+ props: { w: 50, h: 50 },
269
+ })
270
+ }
271
+ })
272
+
273
+ it('returns debounced zoom level when above shape threshold and camera is moving', () => {
274
+ // First zoom to capture a debounced value
275
+ editorWithManyShapes.zoomIn(undefined, { immediate: true })
276
+ const capturedZoom = editorWithManyShapes.getEfficientZoomLevel()
277
+ expect(editorWithManyShapes.getCameraState()).toBe('moving')
278
+
279
+ // Zoom again while still moving
280
+ editorWithManyShapes.zoomIn(undefined, { immediate: true })
281
+ expect(editorWithManyShapes.getCameraState()).toBe('moving')
282
+
283
+ // Should return the captured zoom, not the current zoom
284
+ expect(editorWithManyShapes.getEfficientZoomLevel()).toBe(capturedZoom)
285
+ expect(editorWithManyShapes.getEfficientZoomLevel()).not.toBe(
286
+ editorWithManyShapes.getZoomLevel()
287
+ )
288
+ })
289
+
290
+ it('returns current zoom level when above threshold but camera is idle', () => {
291
+ editorWithManyShapes.zoomIn(undefined, { immediate: true })
292
+ editorWithManyShapes.forceTick(5)
293
+ expect(editorWithManyShapes.getCameraState()).toBe('idle')
294
+
295
+ // Should return current zoom because camera is idle
296
+ expect(editorWithManyShapes.getEfficientZoomLevel()).toBe(editorWithManyShapes.getZoomLevel())
297
+ })
298
+ })
299
+ })
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/lib/shapes/shared/useForceSolid.ts"],
4
- "sourcesContent": ["import { useEditor, useValue } from '@tldraw/editor'\n\nexport function useForceSolid() {\n\tconst editor = useEditor()\n\treturn useValue('zoom', () => editor.getZoomLevel() < 0.35, [editor])\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AAE7B,SAAS,gBAAgB;AAC/B,QAAM,aAAS,yBAAU;AACzB,aAAO,wBAAS,QAAQ,MAAM,OAAO,aAAa,IAAI,MAAM,CAAC,MAAM,CAAC;AACrE;",
6
- "names": []
7
- }
@@ -1,9 +0,0 @@
1
- import { useEditor, useValue } from "@tldraw/editor";
2
- function useForceSolid() {
3
- const editor = useEditor();
4
- return useValue("zoom", () => editor.getZoomLevel() < 0.35, [editor]);
5
- }
6
- export {
7
- useForceSolid
8
- };
9
- //# sourceMappingURL=useForceSolid.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/lib/shapes/shared/useForceSolid.ts"],
4
- "sourcesContent": ["import { useEditor, useValue } from '@tldraw/editor'\n\nexport function useForceSolid() {\n\tconst editor = useEditor()\n\treturn useValue('zoom', () => editor.getZoomLevel() < 0.35, [editor])\n}\n"],
5
- "mappings": "AAAA,SAAS,WAAW,gBAAgB;AAE7B,SAAS,gBAAgB;AAC/B,QAAM,SAAS,UAAU;AACzB,SAAO,SAAS,QAAQ,MAAM,OAAO,aAAa,IAAI,MAAM,CAAC,MAAM,CAAC;AACrE;",
6
- "names": []
7
- }
@@ -1,6 +0,0 @@
1
- import { useEditor, useValue } from '@tldraw/editor'
2
-
3
- export function useForceSolid() {
4
- const editor = useEditor()
5
- return useValue('zoom', () => editor.getZoomLevel() < 0.35, [editor])
6
- }