@tldraw/editor 3.16.0-next.b88d494af370 → 3.16.0-next.bd57619b0757

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 (141) hide show
  1. package/dist-cjs/index.d.ts +50 -101
  2. package/dist-cjs/index.js +1 -5
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +5 -5
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/Shape.js +7 -10
  7. package/dist-cjs/lib/components/Shape.js.map +2 -2
  8. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +4 -23
  9. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
  11. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
  12. package/dist-cjs/lib/config/TLUserPreferences.js +1 -1
  13. package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
  14. package/dist-cjs/lib/editor/Editor.js +41 -110
  15. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  16. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +1 -1
  17. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  18. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +13 -0
  19. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  20. package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
  21. package/dist-cjs/lib/exports/getSvgJsx.js +34 -14
  22. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  23. package/dist-cjs/lib/hooks/useCanvasEvents.js +7 -5
  24. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  25. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +4 -1
  26. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +2 -2
  27. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +4 -1
  28. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
  29. package/dist-cjs/lib/license/LicenseManager.js +17 -22
  30. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  31. package/dist-cjs/lib/license/LicenseProvider.js +5 -0
  32. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  33. package/dist-cjs/lib/license/Watermark.js +4 -4
  34. package/dist-cjs/lib/license/Watermark.js.map +1 -1
  35. package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
  36. package/dist-cjs/lib/primitives/Box.js +3 -0
  37. package/dist-cjs/lib/primitives/Box.js.map +2 -2
  38. package/dist-cjs/lib/primitives/Vec.js +0 -4
  39. package/dist-cjs/lib/primitives/Vec.js.map +2 -2
  40. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +26 -18
  41. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  42. package/dist-cjs/lib/primitives/geometry/Group2d.js +3 -0
  43. package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
  44. package/dist-cjs/lib/utils/reparenting.js +2 -35
  45. package/dist-cjs/lib/utils/reparenting.js.map +3 -3
  46. package/dist-cjs/version.js +3 -3
  47. package/dist-cjs/version.js.map +1 -1
  48. package/dist-esm/index.d.mts +50 -101
  49. package/dist-esm/index.mjs +1 -5
  50. package/dist-esm/index.mjs.map +2 -2
  51. package/dist-esm/lib/TldrawEditor.mjs +5 -5
  52. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  53. package/dist-esm/lib/components/Shape.mjs +7 -10
  54. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  55. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +4 -23
  56. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  57. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +1 -1
  58. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
  59. package/dist-esm/lib/config/TLUserPreferences.mjs +1 -1
  60. package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
  61. package/dist-esm/lib/editor/Editor.mjs +41 -110
  62. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  63. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +1 -1
  64. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  65. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +13 -0
  66. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  67. package/dist-esm/lib/exports/getSvgJsx.mjs +34 -14
  68. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  69. package/dist-esm/lib/hooks/useCanvasEvents.mjs +7 -5
  70. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  71. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +4 -1
  72. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +2 -2
  73. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +4 -1
  74. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
  75. package/dist-esm/lib/license/LicenseManager.mjs +17 -22
  76. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  77. package/dist-esm/lib/license/LicenseProvider.mjs +5 -0
  78. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  79. package/dist-esm/lib/license/Watermark.mjs +4 -4
  80. package/dist-esm/lib/license/Watermark.mjs.map +1 -1
  81. package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
  82. package/dist-esm/lib/primitives/Box.mjs +4 -1
  83. package/dist-esm/lib/primitives/Box.mjs.map +2 -2
  84. package/dist-esm/lib/primitives/Vec.mjs +0 -4
  85. package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
  86. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +29 -19
  87. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  88. package/dist-esm/lib/primitives/geometry/Group2d.mjs +3 -0
  89. package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
  90. package/dist-esm/lib/utils/reparenting.mjs +3 -40
  91. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  92. package/dist-esm/version.mjs +3 -3
  93. package/dist-esm/version.mjs.map +1 -1
  94. package/editor.css +8 -0
  95. package/package.json +14 -37
  96. package/src/index.ts +1 -9
  97. package/src/lib/TldrawEditor.tsx +6 -12
  98. package/src/lib/components/Shape.tsx +6 -12
  99. package/src/lib/components/default-components/DefaultCanvas.tsx +5 -22
  100. package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -1
  101. package/src/lib/config/TLUserPreferences.ts +1 -1
  102. package/src/lib/editor/Editor.test.ts +12 -11
  103. package/src/lib/editor/Editor.ts +49 -147
  104. package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +15 -14
  105. package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +16 -15
  106. package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +49 -48
  107. package/src/lib/editor/managers/FontManager/FontManager.test.ts +24 -23
  108. package/src/lib/editor/managers/HistoryManager/HistoryManager.test.ts +7 -6
  109. package/src/lib/editor/managers/ScribbleManager/ScribbleManager.test.ts +12 -11
  110. package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +57 -50
  111. package/src/lib/editor/managers/TextManager/TextManager.test.ts +51 -26
  112. package/src/lib/editor/managers/TickManager/TickManager.test.ts +14 -13
  113. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +21 -26
  114. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +1 -1
  115. package/src/lib/editor/shapes/ShapeUtil.ts +35 -0
  116. package/src/lib/editor/types/misc-types.ts +0 -6
  117. package/src/lib/exports/getSvgJsx.test.ts +868 -0
  118. package/src/lib/exports/getSvgJsx.tsx +76 -19
  119. package/src/lib/hooks/useCanvasEvents.ts +6 -6
  120. package/src/lib/hooks/usePassThroughMouseOverEvents.ts +4 -1
  121. package/src/lib/hooks/usePassThroughWheelEvents.ts +6 -1
  122. package/src/lib/license/LicenseManager.test.ts +61 -52
  123. package/src/lib/license/LicenseManager.ts +32 -24
  124. package/src/lib/license/LicenseProvider.tsx +8 -0
  125. package/src/lib/license/Watermark.test.tsx +2 -1
  126. package/src/lib/license/Watermark.tsx +4 -4
  127. package/src/lib/license/useLicenseManagerState.ts +2 -2
  128. package/src/lib/primitives/Box.test.ts +126 -0
  129. package/src/lib/primitives/Box.ts +10 -1
  130. package/src/lib/primitives/Vec.ts +0 -5
  131. package/src/lib/primitives/geometry/Geometry2d.ts +49 -19
  132. package/src/lib/primitives/geometry/Group2d.ts +4 -0
  133. package/src/lib/utils/reparenting.ts +3 -69
  134. package/src/lib/utils/sync/LocalIndexedDb.test.ts +2 -1
  135. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +15 -15
  136. package/src/version.ts +3 -3
  137. package/dist-cjs/lib/utils/nearestMultiple.js +0 -34
  138. package/dist-cjs/lib/utils/nearestMultiple.js.map +0 -7
  139. package/dist-esm/lib/utils/nearestMultiple.mjs +0 -14
  140. package/dist-esm/lib/utils/nearestMultiple.mjs.map +0 -7
  141. package/src/lib/utils/nearestMultiple.ts +0 -13
@@ -189,13 +189,6 @@ export interface TldrawEditorBaseProps {
189
189
  */
190
190
  deepLinks?: true | TLDeepLinkOptions
191
191
 
192
- /**
193
- * Predicate for whether or not a shape should be hidden.
194
- *
195
- * @deprecated Use {@link TldrawEditorBaseProps#getShapeVisibility} instead.
196
- */
197
- isShapeHidden?(shape: TLShape, editor: Editor): boolean
198
-
199
192
  /**
200
193
  * Provides a way to hide shapes.
201
194
  *
@@ -412,8 +405,6 @@ function TldrawEditorWithReadyStore({
412
405
  options,
413
406
  licenseKey,
414
407
  deepLinks: _deepLinks,
415
- // eslint-disable-next-line @typescript-eslint/no-deprecated
416
- isShapeHidden,
417
408
  getShapeVisibility,
418
409
  assetUrls,
419
410
  }: Required<
@@ -473,7 +464,6 @@ function TldrawEditorWithReadyStore({
473
464
  textOptions,
474
465
  options,
475
466
  licenseKey,
476
- isShapeHidden,
477
467
  getShapeVisibility,
478
468
  fontAssetUrls: assetUrls?.fonts,
479
469
  })
@@ -509,7 +499,6 @@ function TldrawEditorWithReadyStore({
509
499
  user,
510
500
  setEditor,
511
501
  licenseKey,
512
- isShapeHidden,
513
502
  getShapeVisibility,
514
503
  textOptions,
515
504
  assetUrls,
@@ -586,8 +575,13 @@ function TldrawEditorWithReadyStore({
586
575
  if (editor !== fontLoadingState?.editor) {
587
576
  fontLoadingState = null
588
577
  }
589
- useEffect(() => {
578
+ useLayoutEffect(() => {
590
579
  if (!editor) return
580
+ if (editor.options.maxFontsToLoadBeforeRender === 0) {
581
+ setFontLoadingState({ editor, isLoaded: true })
582
+ return
583
+ }
584
+
591
585
  let isCancelled = false
592
586
 
593
587
  setFontLoadingState({ editor, isLoaded: false })
@@ -28,7 +28,6 @@ export const Shape = memo(function Shape({
28
28
  index,
29
29
  backgroundIndex,
30
30
  opacity,
31
- dprMultiple,
32
31
  }: {
33
32
  id: TLShapeId
34
33
  shape: TLShape
@@ -36,7 +35,6 @@ export const Shape = memo(function Shape({
36
35
  index: number
37
36
  backgroundIndex: number
38
37
  opacity: number
39
- dprMultiple: number
40
38
  }) {
41
39
  const editor = useEditor()
42
40
 
@@ -91,18 +89,14 @@ export const Shape = memo(function Shape({
91
89
  }
92
90
 
93
91
  // Width / Height
94
- // We round the shape width and height up to the nearest multiple of dprMultiple
95
- // to avoid the browser making miscalculations when applying the transform.
96
- const widthRemainder = bounds.w % dprMultiple
97
- const heightRemainder = bounds.h % dprMultiple
98
- const width = widthRemainder === 0 ? bounds.w : bounds.w + (dprMultiple - widthRemainder)
99
- const height = heightRemainder === 0 ? bounds.h : bounds.h + (dprMultiple - heightRemainder)
92
+ const width = Math.max(bounds.width, 1)
93
+ const height = Math.max(bounds.height, 1)
100
94
 
101
95
  if (width !== prev.width || height !== prev.height) {
102
- setStyleProperty(containerRef.current, 'width', Math.max(width, dprMultiple) + 'px')
103
- setStyleProperty(containerRef.current, 'height', Math.max(height, dprMultiple) + 'px')
104
- setStyleProperty(bgContainerRef.current, 'width', Math.max(width, dprMultiple) + 'px')
105
- setStyleProperty(bgContainerRef.current, 'height', Math.max(height, dprMultiple) + 'px')
96
+ setStyleProperty(containerRef.current, 'width', width + 'px')
97
+ setStyleProperty(containerRef.current, 'height', height + 'px')
98
+ setStyleProperty(bgContainerRef.current, 'width', width + 'px')
99
+ setStyleProperty(bgContainerRef.current, 'height', height + 'px')
106
100
  prev.width = width
107
101
  prev.height = height
108
102
  }
@@ -22,7 +22,6 @@ import { Vec } from '../../primitives/Vec'
22
22
  import { toDomPrecision } from '../../primitives/utils'
23
23
  import { debugFlags } from '../../utils/debug-flags'
24
24
  import { setStyleProperty } from '../../utils/dom'
25
- import { nearestMultiple } from '../../utils/nearestMultiple'
26
25
  import { GeometryDebuggingView } from '../GeometryDebuggingView'
27
26
  import { LiveCollaborators } from '../LiveCollaborators'
28
27
  import { MenuClickCapture } from '../MenuClickCapture'
@@ -173,10 +172,12 @@ export function DefaultCanvas({ className }: TLCanvasComponentProps) {
173
172
  <LiveCollaborators />
174
173
  </div>
175
174
  </div>
175
+ <div className="tl-canvas__in-front">
176
+ <InFrontOfTheCanvasWrapper />
177
+ </div>
176
178
  <MovingCameraHitTestBlocker />
177
179
  </div>
178
180
  <MenuClickCapture />
179
- <InFrontOfTheCanvasWrapper />
180
181
  </>
181
182
  )
182
183
  }
@@ -390,18 +391,9 @@ function ShapesWithSVGs() {
390
391
 
391
392
  const renderingShapes = useValue('rendering shapes', () => editor.getRenderingShapes(), [editor])
392
393
 
393
- const dprMultiple = useValue(
394
- 'dpr multiple',
395
- () =>
396
- // dprMultiple is the smallest number we can multiply dpr by to get an integer
397
- // it's usually 1, 2, or 4 (for e.g. dpr of 2, 2.5 and 2.25 respectively)
398
- nearestMultiple(Math.floor(editor.getInstanceState().devicePixelRatio * 100) / 100),
399
- [editor]
400
- )
401
-
402
394
  return renderingShapes.map((result) => (
403
395
  <Fragment key={result.id + '_fragment'}>
404
- <Shape {...result} dprMultiple={dprMultiple} />
396
+ <Shape {...result} />
405
397
  <DebugSvgCopy id={result.id} mode="iframe" />
406
398
  </Fragment>
407
399
  ))
@@ -436,19 +428,10 @@ function ShapesToDisplay() {
436
428
 
437
429
  const renderingShapes = useValue('rendering shapes', () => editor.getRenderingShapes(), [editor])
438
430
 
439
- const dprMultiple = useValue(
440
- 'dpr multiple',
441
- () =>
442
- // dprMultiple is the smallest number we can multiply dpr by to get an integer
443
- // it's usually 1, 2, or 4 (for e.g. dpr of 2, 2.5 and 2.25 respectively)
444
- nearestMultiple(Math.floor(editor.getInstanceState().devicePixelRatio * 100) / 100),
445
- [editor]
446
- )
447
-
448
431
  return (
449
432
  <>
450
433
  {renderingShapes.map((result) => (
451
- <Shape key={result.id + '_shape'} {...result} dprMultiple={dprMultiple} />
434
+ <Shape key={result.id + '_shape'} {...result} />
452
435
  ))}
453
436
  {tlenv.isSafari && <ReflowIfNeeded />}
454
437
  </>
@@ -75,7 +75,7 @@ export const DefaultErrorFallback: TLErrorFallbackComponent = ({ error, editor }
75
75
 
76
76
  // if we can't find a theme class from the app or from a parent, we have
77
77
  // to fall back on using a media query:
78
- if (typeof window !== 'undefined' && 'matchMedia' in window) {
78
+ if (typeof window !== 'undefined' && window.matchMedia) {
79
79
  setIsDarkMode(window.matchMedia('(prefers-color-scheme: dark)').matches)
80
80
  }
81
81
  }, [isDarkModeFromApp])
@@ -135,7 +135,7 @@ function getRandomColor() {
135
135
 
136
136
  /** @internal */
137
137
  export function userPrefersReducedMotion() {
138
- if (typeof window !== 'undefined' && 'matchMedia' in window) {
138
+ if (typeof window !== 'undefined' && window.matchMedia) {
139
139
  return window.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches ?? false
140
140
  }
141
141
 
@@ -1,3 +1,4 @@
1
+ import { vi } from 'vitest'
1
2
  import {
2
3
  Box,
3
4
  Geometry2d,
@@ -59,8 +60,8 @@ beforeEach(() => {
59
60
  getContainer: () => document.body,
60
61
  })
61
62
  editor.setCameraOptions({ isLocked: true })
62
- editor.setCamera = jest.fn()
63
- editor.user.getAnimationSpeed = jest.fn()
63
+ editor.setCamera = vi.fn()
64
+ editor.user.getAnimationSpeed = vi.fn()
64
65
  })
65
66
 
66
67
  describe('centerOnPoint', () => {
@@ -94,13 +95,13 @@ describe('updateShape', () => {
94
95
 
95
96
  describe('zoomToFit', () => {
96
97
  it('no-op when isLocked is set', () => {
97
- editor.getCurrentPageShapeIds = jest.fn(() => new Set([createShapeId('box1')]))
98
+ editor.getCurrentPageShapeIds = vi.fn(() => new Set([createShapeId('box1')]))
98
99
  editor.zoomToFit()
99
100
  expect(editor.setCamera).not.toHaveBeenCalled()
100
101
  })
101
102
 
102
103
  it('sets camera when isLocked is set and force flag is set', () => {
103
- editor.getCurrentPageShapeIds = jest.fn(() => new Set([createShapeId('box1')]))
104
+ editor.getCurrentPageShapeIds = vi.fn(() => new Set([createShapeId('box1')]))
104
105
  editor.zoomToFit({ force: true })
105
106
  expect(editor.setCamera).toHaveBeenCalled()
106
107
  })
@@ -144,13 +145,13 @@ describe('zoomOut', () => {
144
145
 
145
146
  describe('zoomToSelection', () => {
146
147
  it('no-op when isLocked is set', () => {
147
- editor.getSelectionPageBounds = jest.fn(() => Box.From({ x: 0, y: 0, w: 100, h: 100 }))
148
+ editor.getSelectionPageBounds = vi.fn(() => Box.From({ x: 0, y: 0, w: 100, h: 100 }))
148
149
  editor.zoomToSelection()
149
150
  expect(editor.setCamera).not.toHaveBeenCalled()
150
151
  })
151
152
 
152
153
  it('sets camera when isLocked is set and force flag is set', () => {
153
- editor.getSelectionPageBounds = jest.fn(() => Box.From({ x: 0, y: 0, w: 100, h: 100 }))
154
+ editor.getSelectionPageBounds = vi.fn(() => Box.From({ x: 0, y: 0, w: 100, h: 100 }))
154
155
  editor.zoomToSelection({ force: true })
155
156
  expect(editor.setCamera).toHaveBeenCalled()
156
157
  })
@@ -286,7 +287,7 @@ describe('getShapesAtPoint', () => {
286
287
 
287
288
  it('filters out hidden shapes', () => {
288
289
  // Create a spy to mock isShapeHidden
289
- const isShapeHiddenSpy = jest.spyOn(editor, 'isShapeHidden')
290
+ const isShapeHiddenSpy = vi.spyOn(editor, 'isShapeHidden')
290
291
  isShapeHiddenSpy.mockImplementation((shape) => {
291
292
  return typeof shape === 'string' ? shape === ids.shape3 : shape.id === ids.shape3
292
293
  })
@@ -352,7 +353,7 @@ describe('getShapesAtPoint', () => {
352
353
 
353
354
  it('returns empty array when all shapes are hidden', () => {
354
355
  // Mock all shapes as hidden
355
- const isShapeHiddenSpy = jest.spyOn(editor, 'isShapeHidden')
356
+ const isShapeHiddenSpy = vi.spyOn(editor, 'isShapeHidden')
356
357
  isShapeHiddenSpy.mockReturnValue(true)
357
358
 
358
359
  const shapes = editor.getShapesAtPoint({ x: 50, y: 50 })
@@ -692,7 +693,7 @@ describe('selectAll', () => {
692
693
  const initialSelectedIds = editor.getSelectedShapeIds()
693
694
 
694
695
  // Spy on setSelectedShapes to verify it's not called
695
- const setSelectedShapesSpy = jest.spyOn(editor, 'setSelectedShapes')
696
+ const setSelectedShapesSpy = vi.spyOn(editor, 'setSelectedShapes')
696
697
 
697
698
  // Call selectAll
698
699
  editor.selectAll()
@@ -713,7 +714,7 @@ describe('selectAll', () => {
713
714
  const initialSelectedIds = editor.getSelectedShapeIds()
714
715
 
715
716
  // Spy on setSelectedShapes to verify it's not called
716
- const setSelectedShapesSpy = jest.spyOn(editor, 'setSelectedShapes')
717
+ const setSelectedShapesSpy = vi.spyOn(editor, 'setSelectedShapes')
717
718
 
718
719
  // Call selectAll
719
720
  editor.selectAll()
@@ -818,7 +819,7 @@ describe('selectAll', () => {
818
819
  const initialSelectedIds = Array.from(editor.getSelectedShapeIds())
819
820
 
820
821
  // Spy on setSelectedShapes to verify it's not called
821
- const setSelectedShapesSpy = jest.spyOn(editor, 'setSelectedShapes')
822
+ const setSelectedShapesSpy = vi.spyOn(editor, 'setSelectedShapes')
822
823
 
823
824
  // Call selectAll
824
825
  editor.selectAll()
@@ -116,7 +116,6 @@ import {
116
116
  } from '../constants'
117
117
  import { exportToSvg } from '../exports/exportToSvg'
118
118
  import { getSvgAsImage } from '../exports/getSvgAsImage'
119
- import { tlenv } from '../globals/environment'
120
119
  import { tlmenus } from '../globals/menus'
121
120
  import { tltime } from '../globals/time'
122
121
  import { TldrawOptions, defaultTldrawOptions } from '../options'
@@ -244,16 +243,6 @@ export interface TLEditorOptions {
244
243
  options?: Partial<TldrawOptions>
245
244
  licenseKey?: string
246
245
  fontAssetUrls?: { [key: string]: string | undefined }
247
- /**
248
- * A predicate that should return true if the given shape should be hidden.
249
- *
250
- * @deprecated Use {@link Editor#getShapeVisibility} instead.
251
- *
252
- * @param shape - The shape to check.
253
- * @param editor - The editor instance.
254
- */
255
- isShapeHidden?(shape: TLShape, editor: Editor): boolean
256
-
257
246
  /**
258
247
  * Provides a way to hide shapes.
259
248
  *
@@ -309,21 +298,12 @@ export class Editor extends EventEmitter<TLEventMap> {
309
298
  autoFocus,
310
299
  inferDarkMode,
311
300
  options,
312
- // eslint-disable-next-line @typescript-eslint/no-deprecated
313
- isShapeHidden,
314
301
  getShapeVisibility,
315
302
  fontAssetUrls,
316
303
  }: TLEditorOptions) {
317
304
  super()
318
- assert(
319
- !(isShapeHidden && getShapeVisibility),
320
- 'Cannot use both isShapeHidden and getShapeVisibility'
321
- )
322
305
 
323
- this._getShapeVisibility = isShapeHidden
324
- ? // eslint-disable-next-line @typescript-eslint/no-deprecated
325
- (shape: TLShape, editor: Editor) => (isShapeHidden(shape, editor) ? 'hidden' : 'inherit')
326
- : getShapeVisibility
306
+ this._getShapeVisibility = getShapeVisibility
327
307
 
328
308
  this.options = { ...defaultTldrawOptions, ...options }
329
309
 
@@ -907,14 +887,6 @@ export class Editor extends EventEmitter<TLEventMap> {
907
887
  */
908
888
  readonly fonts: FontManager
909
889
 
910
- /**
911
- * A manager for the editor's environment.
912
- *
913
- * @deprecated This is deprecated and will be removed in a future version. Use the `tlenv` global export instead.
914
- * @public
915
- */
916
- readonly environment = tlenv
917
-
918
890
  /**
919
891
  * A manager for the editor's scribbles.
920
892
  *
@@ -1119,35 +1091,6 @@ export class Editor extends EventEmitter<TLEventMap> {
1119
1091
  return this.history.getNumRedos() > 0
1120
1092
  }
1121
1093
 
1122
- /**
1123
- * Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
1124
- * any redos.
1125
- *
1126
- * @example
1127
- * ```ts
1128
- * editor.mark()
1129
- * editor.mark('flip shapes')
1130
- * ```
1131
- *
1132
- * @param markId - The mark's id, usually the reason for adding the mark.
1133
- *
1134
- * @public
1135
- * @deprecated use {@link Editor.markHistoryStoppingPoint} instead
1136
- */
1137
- mark(markId?: string): this {
1138
- if (typeof markId === 'string') {
1139
- console.warn(
1140
- `[tldraw] \`editor.history.mark("${markId}")\` is deprecated. Please use \`const myMarkId = editor.markHistoryStoppingPoint()\` instead.`
1141
- )
1142
- } else {
1143
- console.warn(
1144
- '[tldraw] `editor.mark()` is deprecated. Use `editor.markHistoryStoppingPoint()` instead.'
1145
- )
1146
- }
1147
- this.history._mark(markId ?? uniqueId())
1148
- return this
1149
- }
1150
-
1151
1094
  /**
1152
1095
  * Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
1153
1096
  * any redos. You typically want to do this just before a user interaction begins or is handled.
@@ -1272,13 +1215,6 @@ export class Editor extends EventEmitter<TLEventMap> {
1272
1215
  return this
1273
1216
  }
1274
1217
 
1275
- /**
1276
- * @deprecated Use `Editor.run` instead.
1277
- */
1278
- batch(fn: () => void, opts?: TLEditorRunOptions): this {
1279
- return this.run(fn, opts)
1280
- }
1281
-
1282
1218
  /* --------------------- Errors --------------------- */
1283
1219
 
1284
1220
  /** @internal */
@@ -1580,54 +1516,6 @@ export class Editor extends EventEmitter<TLEventMap> {
1580
1516
 
1581
1517
  menus = tlmenus.forContext(this.contextId)
1582
1518
 
1583
- /**
1584
- * @deprecated Use `editor.menus.getOpenMenus` instead.
1585
- *
1586
- * @public
1587
- */
1588
- @computed getOpenMenus(): string[] {
1589
- return this.menus.getOpenMenus()
1590
- }
1591
-
1592
- /**
1593
- * @deprecated Use `editor.menus.addOpenMenu` instead.
1594
- *
1595
- * @public
1596
- */
1597
- addOpenMenu(id: string): this {
1598
- this.menus.addOpenMenu(id)
1599
- return this
1600
- }
1601
-
1602
- /**
1603
- * @deprecated Use `editor.menus.deleteOpenMenu` instead.
1604
- *
1605
- * @public
1606
- */
1607
- deleteOpenMenu(id: string): this {
1608
- this.menus.deleteOpenMenu(id)
1609
- return this
1610
- }
1611
-
1612
- /**
1613
- * @deprecated Use `editor.menus.clearOpenMenus` instead.
1614
- *
1615
- * @public
1616
- */
1617
- clearOpenMenus(): this {
1618
- this.menus.clearOpenMenus()
1619
- return this
1620
- }
1621
-
1622
- /**
1623
- * @deprecated Use `editor.menus.hasAnyOpenMenus` instead.
1624
- *
1625
- * @public
1626
- */
1627
- @computed getIsMenuOpen(): boolean {
1628
- return this.menus.hasAnyOpenMenus()
1629
- }
1630
-
1631
1519
  /* --------------------- Cursor --------------------- */
1632
1520
 
1633
1521
  /**
@@ -4860,27 +4748,25 @@ export class Editor extends EventEmitter<TLEventMap> {
4860
4748
  return this.store.createComputedCache('pageMaskCache', (shape) => {
4861
4749
  if (isPageId(shape.parentId)) return undefined
4862
4750
 
4863
- const frameAncestors = this.getShapeAncestors(shape.id).filter((shape) =>
4864
- this.isShapeOfType<TLFrameShape>(shape, 'frame')
4865
- )
4866
-
4867
- if (frameAncestors.length === 0) return undefined
4868
-
4869
- const pageMask = frameAncestors
4870
- .map<Vec[] | undefined>((s) => {
4871
- // Apply the frame transform to the frame outline to get the frame outline in the current page space
4872
- const geometry = this.getShapeGeometry(s.id)
4873
- const pageTransform = this.getShapePageTransform(s.id)
4874
- return pageTransform.applyToPoints(geometry.vertices)
4875
- })
4876
- .reduce((acc, b) => {
4877
- if (!(b && acc)) return undefined
4878
- const intersection = intersectPolygonPolygon(acc, b)
4879
- if (intersection) {
4880
- return intersection.map(Vec.Cast)
4881
- }
4882
- return []
4883
- })
4751
+ const clipPaths: Vec[][] = []
4752
+ // Get all ancestors that can potentially clip this shape
4753
+ for (const ancestor of this.getShapeAncestors(shape.id)) {
4754
+ const util = this.getShapeUtil(ancestor)
4755
+ const clipPath = util.getClipPath?.(ancestor)
4756
+ if (!clipPath) continue
4757
+ if (util.shouldClipChild?.(shape) === false) continue
4758
+ const pageTransform = this.getShapePageTransform(ancestor.id)
4759
+ clipPaths.push(pageTransform.applyToPoints(clipPath))
4760
+ }
4761
+ if (clipPaths.length === 0) return undefined
4762
+
4763
+ const pageMask = clipPaths.reduce((acc, b) => {
4764
+ const intersection = intersectPolygonPolygon(acc, b)
4765
+ if (intersection) {
4766
+ return intersection.map(Vec.Cast)
4767
+ }
4768
+ return []
4769
+ })
4884
4770
 
4885
4771
  return pageMask
4886
4772
  })
@@ -5841,11 +5727,6 @@ export class Editor extends EventEmitter<TLEventMap> {
5841
5727
  return shapeIds
5842
5728
  }
5843
5729
 
5844
- /** @deprecated Use {@link Editor.getDraggingOverShape} instead */
5845
- getDroppingOverShape(point: Vec, droppingShapes: TLShape[]): TLShape | undefined {
5846
- return this.getDraggingOverShape(point, droppingShapes)
5847
- }
5848
-
5849
5730
  /**
5850
5731
  * Get the shape that some shapes should be dropped on at a given point.
5851
5732
  *
@@ -6333,7 +6214,17 @@ export class Editor extends EventEmitter<TLEventMap> {
6333
6214
 
6334
6215
  this.createShapes(shapesToCreate)
6335
6216
  this.createBindings(bindingsToCreate)
6336
- this.setSelectedShapes(compact(ids.map((id) => shapeIds.get(id))))
6217
+
6218
+ this.setSelectedShapes(
6219
+ compact(
6220
+ ids.map((oldId) => {
6221
+ const newId = shapeIds.get(oldId)
6222
+ if (!newId) return null
6223
+ if (!this.getShape(newId)) return null
6224
+ return newId
6225
+ })
6226
+ )
6227
+ )
6337
6228
 
6338
6229
  if (offset !== undefined) {
6339
6230
  // If we've offset the duplicated shapes, check to see whether their new bounds is entirely
@@ -9451,13 +9342,6 @@ export class Editor extends EventEmitter<TLEventMap> {
9451
9342
  }
9452
9343
  }
9453
9344
 
9454
- /** @deprecated Use {@link Editor.getSvgString} or {@link Editor.getSvgElement} instead. */
9455
- async getSvg(shapes: TLShapeId[] | TLShape[], opts: TLSvgExportOptions = {}) {
9456
- const result = await this.getSvgElement(shapes, opts)
9457
- if (!result) return undefined
9458
- return result.svg
9459
- }
9460
-
9461
9345
  /**
9462
9346
  * Get an exported image of the given shapes.
9463
9347
  *
@@ -9509,6 +9393,24 @@ export class Editor extends EventEmitter<TLEventMap> {
9509
9393
  }
9510
9394
  }
9511
9395
 
9396
+ /**
9397
+ * Get an exported image of the given shapes as a data URL.
9398
+ *
9399
+ * @param shapes - The shapes (or shape ids) to export.
9400
+ * @param opts - Options for the export.
9401
+ *
9402
+ * @returns A data URL of the image.
9403
+ * @public
9404
+ */
9405
+ async toImageDataUrl(shapes: TLShapeId[] | TLShape[], opts: TLImageExportOptions = {}) {
9406
+ const { blob, width, height } = await this.toImage(shapes, opts)
9407
+ return {
9408
+ url: await FileHelpers.blobToDataUrl(blob),
9409
+ width,
9410
+ height,
9411
+ }
9412
+ }
9413
+
9512
9414
  /* --------------------- Events --------------------- */
9513
9415
 
9514
9416
  /**
@@ -1,12 +1,13 @@
1
+ import { Mocked, vi } from 'vitest'
1
2
  import { Editor } from '../../Editor'
2
3
  import { TLClickEventInfo, TLPointerEventInfo } from '../../types/event-types'
3
4
  import { ClickManager } from './ClickManager'
4
5
 
5
6
  // Mock the Editor class
6
- jest.mock('../../Editor')
7
+ vi.mock('../../Editor')
7
8
 
8
9
  describe('ClickManager', () => {
9
- let editor: jest.Mocked<Editor>
10
+ let editor: Mocked<Editor>
10
11
  let clickManager: ClickManager
11
12
  let mockTimers: any
12
13
 
@@ -29,14 +30,14 @@ describe('ClickManager', () => {
29
30
  })
30
31
 
31
32
  beforeEach(() => {
32
- jest.useFakeTimers()
33
+ vi.useFakeTimers()
33
34
  mockTimers = {
34
- setTimeout: jest.fn((fn, delay) => setTimeout(fn, delay)),
35
+ setTimeout: vi.fn((fn, delay) => setTimeout(fn, delay)),
35
36
  }
36
37
 
37
38
  editor = {
38
39
  timers: mockTimers,
39
- dispatch: jest.fn(),
40
+ dispatch: vi.fn(),
40
41
  options: {
41
42
  doubleClickDurationMs: 300,
42
43
  multiClickDurationMs: 300,
@@ -46,7 +47,7 @@ describe('ClickManager', () => {
46
47
  inputs: {
47
48
  currentScreenPoint: { x: 0, y: 0 },
48
49
  },
49
- getInstanceState: jest.fn(() => ({
50
+ getInstanceState: vi.fn(() => ({
50
51
  isCoarsePointer: false,
51
52
  })),
52
53
  } as any
@@ -55,8 +56,8 @@ describe('ClickManager', () => {
55
56
  })
56
57
 
57
58
  afterEach(() => {
58
- jest.useRealTimers()
59
- jest.clearAllMocks()
59
+ vi.useRealTimers()
60
+ vi.clearAllMocks()
60
61
  })
61
62
 
62
63
  describe('constructor and initial state', () => {
@@ -100,7 +101,7 @@ describe('ClickManager', () => {
100
101
  clickManager.handlePointerEvent(pointerEvent)
101
102
  expect(clickManager.clickState).toBe('pendingDouble')
102
103
 
103
- jest.advanceTimersByTime(350)
104
+ vi.advanceTimersByTime(350)
104
105
 
105
106
  expect(clickManager.clickState).toBe('idle')
106
107
  })
@@ -141,7 +142,7 @@ describe('ClickManager', () => {
141
142
  clickManager.handlePointerEvent(firstDown)
142
143
  clickManager.handlePointerEvent(secondDown)
143
144
 
144
- jest.advanceTimersByTime(350)
145
+ vi.advanceTimersByTime(350)
145
146
 
146
147
  expect(editor.dispatch).toHaveBeenCalledWith(
147
148
  expect.objectContaining({
@@ -235,7 +236,7 @@ describe('ClickManager', () => {
235
236
  clickManager.handlePointerEvent(pointerDown) // second
236
237
  clickManager.handlePointerEvent(pointerDown) // third
237
238
 
238
- jest.advanceTimersByTime(350)
239
+ vi.advanceTimersByTime(350)
239
240
 
240
241
  expect(editor.dispatch).toHaveBeenCalledWith(
241
242
  expect.objectContaining({
@@ -255,7 +256,7 @@ describe('ClickManager', () => {
255
256
  clickManager.handlePointerEvent(pointerDown) // third
256
257
  clickManager.handlePointerEvent(pointerDown) // fourth
257
258
 
258
- jest.advanceTimersByTime(350)
259
+ vi.advanceTimersByTime(350)
259
260
 
260
261
  expect(editor.dispatch).toHaveBeenCalledWith(
261
262
  expect.objectContaining({
@@ -277,7 +278,7 @@ describe('ClickManager', () => {
277
278
  editor.options.doubleClickDurationMs
278
279
  )
279
280
 
280
- jest.clearAllMocks()
281
+ vi.clearAllMocks()
281
282
 
282
283
  // Second click - should use multiClickDurationMs
283
284
  clickManager.handlePointerEvent(pointerDown)
@@ -392,7 +393,7 @@ describe('ClickManager', () => {
392
393
  clickManager.cancelDoubleClickTimeout()
393
394
 
394
395
  // Advance time - should not dispatch settle event
395
- jest.advanceTimersByTime(350)
396
+ vi.advanceTimersByTime(350)
396
397
 
397
398
  expect(editor.dispatch).not.toHaveBeenCalled()
398
399
  expect(clickManager.clickState).toBe('idle')