@tldraw/editor 4.6.0-next.5a871ec02ff3 → 4.6.0-next.6594d48ace27

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 (448) hide show
  1. package/dist-cjs/index.d.ts +1316 -285
  2. package/dist-cjs/index.js +31 -26
  3. package/dist-cjs/index.js.map +3 -3
  4. package/dist-cjs/lib/TldrawEditor.js +62 -14
  5. package/dist-cjs/lib/TldrawEditor.js.map +3 -3
  6. package/dist-cjs/lib/components/MenuClickCapture.js +99 -38
  7. package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
  8. package/dist-cjs/lib/components/default-components/CanvasOverlays.js +180 -0
  9. package/dist-cjs/lib/components/default-components/CanvasOverlays.js.map +7 -0
  10. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +33 -236
  11. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +3 -3
  12. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
  13. package/dist-cjs/lib/config/{createTLUser.js → createTLCurrentUser.js} +9 -9
  14. package/dist-cjs/lib/config/createTLCurrentUser.js.map +7 -0
  15. package/dist-cjs/lib/config/createTLStore.js +31 -1
  16. package/dist-cjs/lib/config/createTLStore.js.map +2 -2
  17. package/dist-cjs/lib/{components/default-components/DefaultShapeIndicatorErrorFallback.js → config/defaultAssets.js} +17 -9
  18. package/dist-cjs/lib/config/defaultAssets.js.map +7 -0
  19. package/dist-cjs/lib/config/defaultShapes.js.map +2 -2
  20. package/dist-cjs/lib/editor/Editor.js +921 -386
  21. package/dist-cjs/lib/editor/Editor.js.map +3 -3
  22. package/dist-cjs/lib/editor/assets/AssetUtil.js +67 -0
  23. package/dist-cjs/lib/editor/assets/AssetUtil.js.map +7 -0
  24. package/dist-cjs/lib/editor/bindings/BindingUtil.js +1 -0
  25. package/dist-cjs/lib/editor/bindings/BindingUtil.js.map +1 -1
  26. package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js +26 -64
  27. package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +2 -2
  28. package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js +98 -0
  29. package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js.map +7 -0
  30. package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js +2 -1
  31. package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +2 -2
  32. package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js +15 -53
  33. package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js.map +1 -1
  34. package/dist-cjs/lib/editor/managers/FontManager/FontManager.js +2 -0
  35. package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +2 -2
  36. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +2 -0
  37. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +1 -1
  38. package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js +83 -112
  39. package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js.map +2 -2
  40. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.js +80 -0
  41. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.js.map +7 -0
  42. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js +466 -0
  43. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js.map +7 -0
  44. package/dist-cjs/lib/{components/default-components/DefaultHandles.js → editor/managers/PerformanceManager/perf-types.js} +3 -14
  45. package/dist-cjs/lib/editor/managers/PerformanceManager/perf-types.js.map +7 -0
  46. package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js +1 -0
  47. package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +1 -1
  48. package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js +22 -56
  49. package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +2 -2
  50. package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js +12 -52
  51. package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js.map +2 -2
  52. package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js +21 -57
  53. package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js.map +2 -2
  54. package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js +5 -4
  55. package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js.map +2 -2
  56. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +103 -30
  57. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
  58. package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js +107 -0
  59. package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js.map +7 -0
  60. package/dist-cjs/lib/editor/managers/ThemeManager/defaultThemes.js +600 -0
  61. package/dist-cjs/lib/editor/managers/ThemeManager/defaultThemes.js.map +7 -0
  62. package/dist-cjs/lib/editor/managers/TickManager/TickManager.js +17 -55
  63. package/dist-cjs/lib/editor/managers/TickManager/TickManager.js.map +1 -1
  64. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +65 -72
  65. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  66. package/dist-cjs/lib/editor/overlays/OverlayManager.js +154 -0
  67. package/dist-cjs/lib/editor/overlays/OverlayManager.js.map +7 -0
  68. package/dist-cjs/lib/editor/overlays/OverlayUtil.js +92 -0
  69. package/dist-cjs/lib/editor/overlays/OverlayUtil.js.map +7 -0
  70. package/dist-cjs/lib/editor/overlays/ShapeIndicatorOverlayUtil.js +161 -0
  71. package/dist-cjs/lib/editor/overlays/ShapeIndicatorOverlayUtil.js.map +7 -0
  72. package/dist-cjs/lib/editor/shapes/BaseFrameLikeShapeUtil.js +76 -0
  73. package/dist-cjs/lib/editor/shapes/BaseFrameLikeShapeUtil.js.map +7 -0
  74. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +35 -20
  75. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  76. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +33 -3
  77. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
  78. package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js +6 -0
  79. package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js.map +2 -2
  80. package/dist-cjs/lib/editor/tools/StateNode.js +15 -17
  81. package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
  82. package/dist-cjs/lib/editor/types/SvgExportContext.js.map +2 -2
  83. package/dist-cjs/lib/editor/types/clipboard-types.js.map +1 -1
  84. package/dist-cjs/lib/editor/types/event-types.js.map +2 -2
  85. package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
  86. package/dist-cjs/lib/exports/ExportDelay.js +13 -53
  87. package/dist-cjs/lib/exports/ExportDelay.js.map +1 -1
  88. package/dist-cjs/lib/exports/FontEmbedder.js +14 -57
  89. package/dist-cjs/lib/exports/FontEmbedder.js.map +1 -1
  90. package/dist-cjs/lib/exports/StyleEmbedder.js +2 -1
  91. package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
  92. package/dist-cjs/lib/exports/fetchCache.js +1 -1
  93. package/dist-cjs/lib/exports/fetchCache.js.map +2 -2
  94. package/dist-cjs/lib/exports/getSvgJsx.js +14 -8
  95. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  96. package/dist-cjs/lib/globals/environment.js +18 -1
  97. package/dist-cjs/lib/globals/environment.js.map +2 -2
  98. package/dist-cjs/lib/hooks/EditorComponentsContext.js.map +2 -2
  99. package/dist-cjs/lib/hooks/useCanvasEvents.js +25 -4
  100. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  101. package/dist-cjs/lib/hooks/{useIsDarkMode.js → useColorMode.js} +14 -10
  102. package/dist-cjs/lib/hooks/useColorMode.js.map +7 -0
  103. package/dist-cjs/lib/hooks/useCursor.js +3 -7
  104. package/dist-cjs/lib/hooks/useCursor.js.map +2 -2
  105. package/dist-cjs/lib/hooks/useDarkMode.js +4 -4
  106. package/dist-cjs/lib/hooks/useDarkMode.js.map +2 -2
  107. package/dist-cjs/lib/hooks/useEditorComponents.js +0 -28
  108. package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
  109. package/dist-cjs/lib/hooks/useGestureEvents.js +171 -127
  110. package/dist-cjs/lib/hooks/useGestureEvents.js.map +3 -3
  111. package/dist-cjs/lib/hooks/useLocalStore.js.map +2 -2
  112. package/dist-cjs/lib/hooks/usePeerIds.js +1 -36
  113. package/dist-cjs/lib/hooks/usePeerIds.js.map +2 -2
  114. package/dist-cjs/lib/hooks/useShapeCulling.js +2 -1
  115. package/dist-cjs/lib/hooks/useShapeCulling.js.map +2 -2
  116. package/dist-cjs/lib/options.js +4 -0
  117. package/dist-cjs/lib/options.js.map +2 -2
  118. package/dist-cjs/lib/primitives/Box.js +26 -26
  119. package/dist-cjs/lib/primitives/Box.js.map +2 -2
  120. package/dist-cjs/lib/primitives/Vec.js +4 -1
  121. package/dist-cjs/lib/primitives/Vec.js.map +2 -2
  122. package/dist-cjs/lib/primitives/geometry/Arc2d.js +2 -2
  123. package/dist-cjs/lib/primitives/geometry/Arc2d.js.map +2 -2
  124. package/dist-cjs/lib/primitives/geometry/Circle2d.js +3 -2
  125. package/dist-cjs/lib/primitives/geometry/Circle2d.js.map +2 -2
  126. package/dist-cjs/lib/primitives/geometry/CubicSpline2d.js +1 -1
  127. package/dist-cjs/lib/primitives/geometry/CubicSpline2d.js.map +1 -1
  128. package/dist-cjs/lib/primitives/geometry/Ellipse2d.js +4 -3
  129. package/dist-cjs/lib/primitives/geometry/Ellipse2d.js.map +2 -2
  130. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +12 -9
  131. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  132. package/dist-cjs/lib/primitives/geometry/Polyline2d.js +2 -2
  133. package/dist-cjs/lib/primitives/geometry/Polyline2d.js.map +2 -2
  134. package/dist-cjs/lib/primitives/geometry/Stadium2d.js +2 -1
  135. package/dist-cjs/lib/primitives/geometry/Stadium2d.js.map +2 -2
  136. package/dist-cjs/lib/utils/EditorAtom.js +2 -0
  137. package/dist-cjs/lib/utils/EditorAtom.js.map +1 -1
  138. package/dist-cjs/lib/utils/SharedStylesMap.js +1 -1
  139. package/dist-cjs/lib/utils/SharedStylesMap.js.map +1 -1
  140. package/dist-cjs/lib/utils/getSvgPathFromPoints.js.map +2 -2
  141. package/dist-cjs/lib/utils/reparenting.js +2 -1
  142. package/dist-cjs/lib/utils/reparenting.js.map +2 -2
  143. package/dist-cjs/lib/utils/richText.js.map +2 -2
  144. package/dist-cjs/lib/utils/runtime.js +2 -1
  145. package/dist-cjs/lib/utils/runtime.js.map +2 -2
  146. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +8 -2
  147. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
  148. package/dist-cjs/lib/utils/sync/hardReset.js +0 -8
  149. package/dist-cjs/lib/utils/sync/hardReset.js.map +2 -2
  150. package/dist-cjs/version.js +3 -3
  151. package/dist-cjs/version.js.map +1 -1
  152. package/dist-esm/index.d.mts +1316 -285
  153. package/dist-esm/index.mjs +44 -48
  154. package/dist-esm/index.mjs.map +2 -2
  155. package/dist-esm/lib/TldrawEditor.mjs +65 -14
  156. package/dist-esm/lib/TldrawEditor.mjs.map +3 -3
  157. package/dist-esm/lib/components/MenuClickCapture.mjs +100 -39
  158. package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
  159. package/dist-esm/lib/components/default-components/CanvasOverlays.mjs +160 -0
  160. package/dist-esm/lib/components/default-components/CanvasOverlays.mjs.map +7 -0
  161. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +34 -237
  162. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +3 -3
  163. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
  164. package/dist-esm/lib/config/{createTLUser.mjs → createTLCurrentUser.mjs} +6 -6
  165. package/dist-esm/lib/config/createTLCurrentUser.mjs.map +7 -0
  166. package/dist-esm/lib/config/createTLStore.mjs +37 -2
  167. package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
  168. package/dist-esm/lib/config/defaultAssets.mjs +16 -0
  169. package/dist-esm/lib/config/defaultAssets.mjs.map +7 -0
  170. package/dist-esm/lib/config/defaultShapes.mjs.map +2 -2
  171. package/dist-esm/lib/editor/Editor.mjs +924 -389
  172. package/dist-esm/lib/editor/Editor.mjs.map +3 -3
  173. package/dist-esm/lib/editor/assets/AssetUtil.mjs +47 -0
  174. package/dist-esm/lib/editor/assets/AssetUtil.mjs.map +7 -0
  175. package/dist-esm/lib/editor/bindings/BindingUtil.mjs +1 -0
  176. package/dist-esm/lib/editor/bindings/BindingUtil.mjs.map +1 -1
  177. package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs +26 -64
  178. package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +2 -2
  179. package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs +83 -0
  180. package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs.map +7 -0
  181. package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs +2 -1
  182. package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +2 -2
  183. package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs +15 -53
  184. package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs.map +1 -1
  185. package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs +2 -0
  186. package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +2 -2
  187. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +2 -0
  188. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +1 -1
  189. package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs +83 -112
  190. package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs.map +2 -2
  191. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.mjs +60 -0
  192. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.mjs.map +7 -0
  193. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs +438 -0
  194. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs.map +7 -0
  195. package/dist-esm/lib/editor/managers/PerformanceManager/perf-types.mjs +1 -0
  196. package/dist-esm/lib/editor/managers/PerformanceManager/perf-types.mjs.map +7 -0
  197. package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs +1 -0
  198. package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +1 -1
  199. package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs +22 -56
  200. package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +2 -2
  201. package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs +12 -52
  202. package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs.map +2 -2
  203. package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs +21 -57
  204. package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs.map +2 -2
  205. package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs +5 -4
  206. package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs.map +2 -2
  207. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +103 -30
  208. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
  209. package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs +89 -0
  210. package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs.map +7 -0
  211. package/dist-esm/lib/editor/managers/ThemeManager/defaultThemes.mjs +582 -0
  212. package/dist-esm/lib/editor/managers/ThemeManager/defaultThemes.mjs.map +7 -0
  213. package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs +17 -55
  214. package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs.map +1 -1
  215. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +65 -72
  216. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  217. package/dist-esm/lib/editor/overlays/OverlayManager.mjs +136 -0
  218. package/dist-esm/lib/editor/overlays/OverlayManager.mjs.map +7 -0
  219. package/dist-esm/lib/editor/overlays/OverlayUtil.mjs +72 -0
  220. package/dist-esm/lib/editor/overlays/OverlayUtil.mjs.map +7 -0
  221. package/dist-esm/lib/editor/overlays/ShapeIndicatorOverlayUtil.mjs +141 -0
  222. package/dist-esm/lib/editor/overlays/ShapeIndicatorOverlayUtil.mjs.map +7 -0
  223. package/dist-esm/lib/editor/shapes/BaseFrameLikeShapeUtil.mjs +56 -0
  224. package/dist-esm/lib/editor/shapes/BaseFrameLikeShapeUtil.mjs.map +7 -0
  225. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +35 -20
  226. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  227. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +33 -3
  228. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
  229. package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs +6 -0
  230. package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs.map +2 -2
  231. package/dist-esm/lib/editor/tools/StateNode.mjs +15 -17
  232. package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
  233. package/dist-esm/lib/editor/types/SvgExportContext.mjs.map +2 -2
  234. package/dist-esm/lib/editor/types/event-types.mjs.map +2 -2
  235. package/dist-esm/lib/exports/ExportDelay.mjs +13 -53
  236. package/dist-esm/lib/exports/ExportDelay.mjs.map +1 -1
  237. package/dist-esm/lib/exports/FontEmbedder.mjs +14 -57
  238. package/dist-esm/lib/exports/FontEmbedder.mjs.map +1 -1
  239. package/dist-esm/lib/exports/StyleEmbedder.mjs +2 -1
  240. package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
  241. package/dist-esm/lib/exports/fetchCache.mjs +2 -2
  242. package/dist-esm/lib/exports/fetchCache.mjs.map +2 -2
  243. package/dist-esm/lib/exports/getSvgJsx.mjs +14 -11
  244. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  245. package/dist-esm/lib/globals/environment.mjs +18 -1
  246. package/dist-esm/lib/globals/environment.mjs.map +2 -2
  247. package/dist-esm/lib/hooks/EditorComponentsContext.mjs.map +2 -2
  248. package/dist-esm/lib/hooks/useCanvasEvents.mjs +25 -4
  249. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  250. package/dist-esm/lib/hooks/useColorMode.mjs +19 -0
  251. package/dist-esm/lib/hooks/useColorMode.mjs.map +7 -0
  252. package/dist-esm/lib/hooks/useCursor.mjs +3 -7
  253. package/dist-esm/lib/hooks/useCursor.mjs.map +2 -2
  254. package/dist-esm/lib/hooks/useDarkMode.mjs +4 -4
  255. package/dist-esm/lib/hooks/useDarkMode.mjs.map +2 -2
  256. package/dist-esm/lib/hooks/useEditorComponents.mjs +0 -28
  257. package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
  258. package/dist-esm/lib/hooks/useGestureEvents.mjs +171 -127
  259. package/dist-esm/lib/hooks/useGestureEvents.mjs.map +3 -3
  260. package/dist-esm/lib/hooks/useLocalStore.mjs.map +2 -2
  261. package/dist-esm/lib/hooks/usePeerIds.mjs +2 -40
  262. package/dist-esm/lib/hooks/usePeerIds.mjs.map +2 -2
  263. package/dist-esm/lib/hooks/useShapeCulling.mjs +2 -1
  264. package/dist-esm/lib/hooks/useShapeCulling.mjs.map +2 -2
  265. package/dist-esm/lib/options.mjs +4 -0
  266. package/dist-esm/lib/options.mjs.map +2 -2
  267. package/dist-esm/lib/primitives/Box.mjs +26 -26
  268. package/dist-esm/lib/primitives/Box.mjs.map +2 -2
  269. package/dist-esm/lib/primitives/Vec.mjs +4 -1
  270. package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
  271. package/dist-esm/lib/primitives/geometry/Arc2d.mjs +2 -2
  272. package/dist-esm/lib/primitives/geometry/Arc2d.mjs.map +2 -2
  273. package/dist-esm/lib/primitives/geometry/Circle2d.mjs +3 -2
  274. package/dist-esm/lib/primitives/geometry/Circle2d.mjs.map +2 -2
  275. package/dist-esm/lib/primitives/geometry/CubicSpline2d.mjs +1 -1
  276. package/dist-esm/lib/primitives/geometry/CubicSpline2d.mjs.map +1 -1
  277. package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs +4 -3
  278. package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs.map +2 -2
  279. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +12 -9
  280. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  281. package/dist-esm/lib/primitives/geometry/Polyline2d.mjs +2 -2
  282. package/dist-esm/lib/primitives/geometry/Polyline2d.mjs.map +2 -2
  283. package/dist-esm/lib/primitives/geometry/Stadium2d.mjs +2 -1
  284. package/dist-esm/lib/primitives/geometry/Stadium2d.mjs.map +2 -2
  285. package/dist-esm/lib/utils/EditorAtom.mjs +2 -0
  286. package/dist-esm/lib/utils/EditorAtom.mjs.map +1 -1
  287. package/dist-esm/lib/utils/SharedStylesMap.mjs +1 -1
  288. package/dist-esm/lib/utils/SharedStylesMap.mjs.map +1 -1
  289. package/dist-esm/lib/utils/getSvgPathFromPoints.mjs.map +2 -2
  290. package/dist-esm/lib/utils/reparenting.mjs +2 -1
  291. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  292. package/dist-esm/lib/utils/richText.mjs.map +2 -2
  293. package/dist-esm/lib/utils/runtime.mjs +2 -1
  294. package/dist-esm/lib/utils/runtime.mjs.map +2 -2
  295. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +8 -2
  296. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
  297. package/dist-esm/lib/utils/sync/hardReset.mjs +0 -8
  298. package/dist-esm/lib/utils/sync/hardReset.mjs.map +2 -2
  299. package/dist-esm/version.mjs +3 -3
  300. package/dist-esm/version.mjs.map +1 -1
  301. package/editor.css +16 -256
  302. package/package.json +7 -8
  303. package/src/index.ts +58 -52
  304. package/src/lib/TldrawEditor.tsx +108 -20
  305. package/src/lib/components/MenuClickCapture.tsx +129 -49
  306. package/src/lib/components/default-components/CanvasOverlays.tsx +208 -0
  307. package/src/lib/components/default-components/DefaultCanvas.tsx +38 -310
  308. package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -0
  309. package/src/lib/config/TLEditorSnapshot.test.ts +1 -1
  310. package/src/lib/config/{createTLUser.ts → createTLCurrentUser.ts} +9 -9
  311. package/src/lib/config/createTLStore.ts +58 -3
  312. package/src/lib/config/defaultAssets.ts +19 -0
  313. package/src/lib/config/defaultShapes.ts +1 -1
  314. package/src/lib/editor/Editor.test.ts +3 -1
  315. package/src/lib/editor/Editor.ts +610 -69
  316. package/src/lib/editor/assets/AssetUtil.ts +85 -0
  317. package/src/lib/editor/managers/ClickManager/ClickManager.ts +1 -1
  318. package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.ts +98 -0
  319. package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.ts +1 -1
  320. package/src/lib/editor/managers/FontManager/FontManager.test.ts +9 -2
  321. package/src/lib/editor/managers/FontManager/FontManager.ts +1 -67
  322. package/src/lib/editor/managers/InputsManager/InputsManager.ts +42 -30
  323. package/src/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.ts +82 -0
  324. package/src/lib/editor/managers/PerformanceManager/PerformanceManager.test.ts +522 -0
  325. package/src/lib/editor/managers/PerformanceManager/PerformanceManager.ts +583 -0
  326. package/src/lib/editor/managers/PerformanceManager/perf-types.ts +196 -0
  327. package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +1 -1
  328. package/src/lib/editor/managers/SnapManager/HandleSnaps.ts +1 -1
  329. package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +13 -2
  330. package/src/lib/editor/managers/SnapManager/SnapManager.ts +1 -1
  331. package/src/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.ts +5 -5
  332. package/src/lib/editor/managers/TextManager/TextManager.test.ts +18 -4
  333. package/src/lib/editor/managers/TextManager/TextManager.ts +140 -34
  334. package/src/lib/editor/managers/ThemeManager/ThemeManager.ts +116 -0
  335. package/src/lib/editor/managers/ThemeManager/defaultThemes.ts +619 -0
  336. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +25 -31
  337. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +7 -5
  338. package/src/lib/editor/overlays/OverlayManager.ts +183 -0
  339. package/src/lib/editor/overlays/OverlayUtil.ts +143 -0
  340. package/src/lib/editor/overlays/ShapeIndicatorOverlayUtil.ts +216 -0
  341. package/src/lib/editor/shapes/BaseFrameLikeShapeUtil.tsx +123 -0
  342. package/src/lib/editor/shapes/ShapeUtil.ts +67 -30
  343. package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +41 -4
  344. package/src/lib/editor/shapes/shared/getPerfectDashProps.ts +7 -0
  345. package/src/lib/editor/tools/StateNode.ts +16 -18
  346. package/src/lib/editor/types/SvgExportContext.tsx +5 -0
  347. package/src/lib/editor/types/clipboard-types.ts +2 -1
  348. package/src/lib/editor/types/event-types.ts +2 -0
  349. package/src/lib/editor/types/external-content.ts +1 -0
  350. package/src/lib/exports/StyleEmbedder.ts +1 -1
  351. package/src/lib/exports/fetchCache.ts +2 -4
  352. package/src/lib/exports/getSvgJsx.test.ts +3 -1
  353. package/src/lib/exports/getSvgJsx.tsx +24 -17
  354. package/src/lib/globals/environment.ts +18 -0
  355. package/src/lib/hooks/EditorComponentsContext.tsx +0 -27
  356. package/src/lib/hooks/useCanvasEvents.ts +40 -3
  357. package/src/lib/hooks/{useIsDarkMode.ts → useColorMode.ts} +9 -5
  358. package/src/lib/hooks/useCursor.ts +3 -7
  359. package/src/lib/hooks/useDarkMode.ts +4 -4
  360. package/src/lib/hooks/useEditorComponents.tsx +1 -29
  361. package/src/lib/hooks/useGestureEvents.ts +240 -168
  362. package/src/lib/hooks/useLocalStore.ts +1 -1
  363. package/src/lib/hooks/usePeerIds.ts +6 -55
  364. package/src/lib/hooks/useShapeCulling.tsx +3 -1
  365. package/src/lib/options.ts +115 -0
  366. package/src/lib/primitives/Box.test.ts +30 -0
  367. package/src/lib/primitives/Box.ts +26 -26
  368. package/src/lib/primitives/Vec.ts +1 -1
  369. package/src/lib/primitives/geometry/Arc2d.ts +2 -2
  370. package/src/lib/primitives/geometry/Circle2d.ts +2 -2
  371. package/src/lib/primitives/geometry/CubicSpline2d.ts +1 -1
  372. package/src/lib/primitives/geometry/Ellipse2d.ts +3 -3
  373. package/src/lib/primitives/geometry/Geometry2d.test.ts +21 -0
  374. package/src/lib/primitives/geometry/Geometry2d.ts +10 -9
  375. package/src/lib/primitives/geometry/Polyline2d.ts +2 -2
  376. package/src/lib/primitives/geometry/Stadium2d.ts +1 -1
  377. package/src/lib/utils/SharedStylesMap.ts +1 -1
  378. package/src/lib/utils/getSvgPathFromPoints.ts +1 -1
  379. package/src/lib/utils/reparenting.ts +6 -2
  380. package/src/lib/utils/richText.ts +1 -1
  381. package/src/lib/utils/runtime.ts +3 -1
  382. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +1 -1
  383. package/src/lib/utils/sync/TLLocalSyncClient.ts +5 -1
  384. package/src/lib/utils/sync/hardReset.ts +0 -8
  385. package/src/version.ts +3 -3
  386. package/dist-cjs/lib/components/LiveCollaborators.js +0 -151
  387. package/dist-cjs/lib/components/LiveCollaborators.js.map +0 -7
  388. package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js +0 -227
  389. package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js.map +0 -7
  390. package/dist-cjs/lib/components/default-components/DefaultBrush.js +0 -38
  391. package/dist-cjs/lib/components/default-components/DefaultBrush.js.map +0 -7
  392. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +0 -71
  393. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +0 -7
  394. package/dist-cjs/lib/components/default-components/DefaultHandle.js +0 -56
  395. package/dist-cjs/lib/components/default-components/DefaultHandle.js.map +0 -7
  396. package/dist-cjs/lib/components/default-components/DefaultHandles.js.map +0 -7
  397. package/dist-cjs/lib/components/default-components/DefaultScribble.js +0 -51
  398. package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +0 -7
  399. package/dist-cjs/lib/components/default-components/DefaultSelectionForeground.js +0 -69
  400. package/dist-cjs/lib/components/default-components/DefaultSelectionForeground.js.map +0 -7
  401. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +0 -107
  402. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +0 -7
  403. package/dist-cjs/lib/components/default-components/DefaultShapeIndicatorErrorFallback.js.map +0 -7
  404. package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js +0 -101
  405. package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js.map +0 -7
  406. package/dist-cjs/lib/components/default-components/DefaultSnapIndictor.js +0 -170
  407. package/dist-cjs/lib/components/default-components/DefaultSnapIndictor.js.map +0 -7
  408. package/dist-cjs/lib/config/createTLUser.js.map +0 -7
  409. package/dist-cjs/lib/hooks/useIsDarkMode.js.map +0 -7
  410. package/dist-esm/lib/components/LiveCollaborators.mjs +0 -134
  411. package/dist-esm/lib/components/LiveCollaborators.mjs.map +0 -7
  412. package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs +0 -207
  413. package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs.map +0 -7
  414. package/dist-esm/lib/components/default-components/DefaultBrush.mjs +0 -18
  415. package/dist-esm/lib/components/default-components/DefaultBrush.mjs.map +0 -7
  416. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +0 -41
  417. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +0 -7
  418. package/dist-esm/lib/components/default-components/DefaultHandle.mjs +0 -26
  419. package/dist-esm/lib/components/default-components/DefaultHandle.mjs.map +0 -7
  420. package/dist-esm/lib/components/default-components/DefaultHandles.mjs +0 -8
  421. package/dist-esm/lib/components/default-components/DefaultHandles.mjs.map +0 -7
  422. package/dist-esm/lib/components/default-components/DefaultScribble.mjs +0 -21
  423. package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +0 -7
  424. package/dist-esm/lib/components/default-components/DefaultSelectionForeground.mjs +0 -39
  425. package/dist-esm/lib/components/default-components/DefaultSelectionForeground.mjs.map +0 -7
  426. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +0 -77
  427. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +0 -7
  428. package/dist-esm/lib/components/default-components/DefaultShapeIndicatorErrorFallback.mjs +0 -8
  429. package/dist-esm/lib/components/default-components/DefaultShapeIndicatorErrorFallback.mjs.map +0 -7
  430. package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs +0 -81
  431. package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs.map +0 -7
  432. package/dist-esm/lib/components/default-components/DefaultSnapIndictor.mjs +0 -142
  433. package/dist-esm/lib/components/default-components/DefaultSnapIndictor.mjs.map +0 -7
  434. package/dist-esm/lib/config/createTLUser.mjs.map +0 -7
  435. package/dist-esm/lib/hooks/useIsDarkMode.mjs +0 -15
  436. package/dist-esm/lib/hooks/useIsDarkMode.mjs.map +0 -7
  437. package/src/lib/components/LiveCollaborators.tsx +0 -174
  438. package/src/lib/components/default-components/CanvasShapeIndicators.tsx +0 -289
  439. package/src/lib/components/default-components/DefaultBrush.tsx +0 -35
  440. package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +0 -52
  441. package/src/lib/components/default-components/DefaultHandle.tsx +0 -42
  442. package/src/lib/components/default-components/DefaultHandles.tsx +0 -15
  443. package/src/lib/components/default-components/DefaultScribble.tsx +0 -31
  444. package/src/lib/components/default-components/DefaultSelectionForeground.tsx +0 -50
  445. package/src/lib/components/default-components/DefaultShapeIndicator.tsx +0 -104
  446. package/src/lib/components/default-components/DefaultShapeIndicatorErrorFallback.tsx +0 -9
  447. package/src/lib/components/default-components/DefaultShapeIndicators.tsx +0 -116
  448. package/src/lib/components/default-components/DefaultSnapIndictor.tsx +0 -174
@@ -50,9 +50,16 @@ import {
50
50
  TLShapePartial,
51
51
  TLStore,
52
52
  TLStoreSnapshot,
53
+ TLTheme,
54
+ TLThemeId,
55
+ TLThemes,
56
+ TLUser,
57
+ TLUserId,
53
58
  TLVideoAsset,
59
+ UserRecordType,
54
60
  createBindingId,
55
61
  createShapeId,
62
+ createUserId,
56
63
  getShapePropKeysByStyle,
57
64
  isPageId,
58
65
  isShapeId,
@@ -82,7 +89,6 @@ import {
82
89
  hasOwnProperty,
83
90
  last,
84
91
  lerp,
85
- maxBy,
86
92
  minBy,
87
93
  sortById,
88
94
  sortByIndex,
@@ -90,15 +96,16 @@ import {
90
96
  uniqueId,
91
97
  } from '@tldraw/utils'
92
98
  import EventEmitter from 'eventemitter3'
99
+ import { TLCurrentUser, createTLCurrentUser } from '../config/createTLCurrentUser'
100
+ import { TLAnyAssetUtilConstructor, checkAssets } from '../config/defaultAssets'
101
+ import { TLAnyBindingUtilConstructor, checkBindings } from '../config/defaultBindings'
102
+ import { TLAnyShapeUtilConstructor, checkShapesAndAddCore } from '../config/defaultShapes'
93
103
  import {
94
104
  TLEditorSnapshot,
95
105
  TLLoadSnapshotOptions,
96
106
  getSnapshot,
97
107
  loadSnapshot,
98
108
  } from '../config/TLEditorSnapshot'
99
- import { TLUser, createTLUser } from '../config/createTLUser'
100
- import { TLAnyBindingUtilConstructor, checkBindings } from '../config/defaultBindings'
101
- import { TLAnyShapeUtilConstructor, checkShapesAndAddCore } from '../config/defaultShapes'
102
109
  import {
103
110
  DEFAULT_ANIMATION_OPTIONS,
104
111
  DEFAULT_CAMERA_OPTIONS,
@@ -115,14 +122,13 @@ import { tlmenus } from '../globals/menus'
115
122
  import { tltime } from '../globals/time'
116
123
  import { TldrawOptions, defaultTldrawOptions } from '../options'
117
124
  import { Box, BoxLike } from '../primitives/Box'
118
- import { Mat, MatLike } from '../primitives/Mat'
119
- import { Vec, VecLike } from '../primitives/Vec'
120
125
  import { EASINGS } from '../primitives/easings'
121
126
  import { Geometry2d } from '../primitives/geometry/Geometry2d'
122
127
  import { Group2d } from '../primitives/geometry/Group2d'
123
128
  import { intersectPolygonPolygon } from '../primitives/intersect'
129
+ import { Mat, MatLike } from '../primitives/Mat'
124
130
  import { PI, approximately, areAnglesCompatible, clamp, pointInPolygon } from '../primitives/utils'
125
- import { ReadonlySharedStyleMap, SharedStyle, SharedStyleMap } from '../utils/SharedStylesMap'
131
+ import { Vec, VecLike } from '../primitives/Vec'
126
132
  import { areShapesContentEqual } from '../utils/areShapesContentEqual'
127
133
  import { dataUrlToFile } from '../utils/assets'
128
134
  import { debugFlags } from '../utils/debug-flags'
@@ -137,23 +143,30 @@ import { getReorderingShapesChanges } from '../utils/reorderShapes'
137
143
  import { getDroppedShapesToNewParents, kickoutOccludedShapes } from '../utils/reparenting'
138
144
  import { TLTextOptions, TiptapEditor } from '../utils/richText'
139
145
  import { applyRotationToSnapshotShapes, getRotationSnapshot } from '../utils/rotation'
146
+ import { ReadonlySharedStyleMap, SharedStyle, SharedStyleMap } from '../utils/SharedStylesMap'
147
+ import { AssetUtil } from './assets/AssetUtil'
140
148
  import { BindingOnDeleteOptions, BindingUtil } from './bindings/BindingUtil'
141
149
  import { bindingsIndex } from './derivations/bindingsIndex'
142
150
  import { notVisibleShapes } from './derivations/notVisibleShapes'
143
151
  import { parentsToChildren } from './derivations/parentsToChildren'
144
152
  import { deriveShapeIdsInCurrentPage } from './derivations/shapeIdsInCurrentPage'
145
153
  import { ClickManager } from './managers/ClickManager/ClickManager'
154
+ import { CollaboratorsManager } from './managers/CollaboratorsManager/CollaboratorsManager'
146
155
  import { EdgeScrollManager } from './managers/EdgeScrollManager/EdgeScrollManager'
147
156
  import { FocusManager } from './managers/FocusManager/FocusManager'
148
157
  import { FontManager } from './managers/FontManager/FontManager'
149
158
  import { HistoryManager } from './managers/HistoryManager/HistoryManager'
150
159
  import { InputsManager } from './managers/InputsManager/InputsManager'
160
+ import { PerformanceManager } from './managers/PerformanceManager/PerformanceManager'
151
161
  import { ScribbleManager } from './managers/ScribbleManager/ScribbleManager'
152
162
  import { SnapManager } from './managers/SnapManager/SnapManager'
153
163
  import { SpatialIndexManager } from './managers/SpatialIndexManager/SpatialIndexManager'
154
164
  import { TextManager } from './managers/TextManager/TextManager'
165
+ import { ThemeManager, resolveThemes } from './managers/ThemeManager/ThemeManager'
155
166
  import { TickManager } from './managers/TickManager/TickManager'
156
167
  import { UserPreferencesManager } from './managers/UserPreferencesManager/UserPreferencesManager'
168
+ import { OverlayManager } from './overlays/OverlayManager'
169
+ import { TLAnyOverlayUtilConstructor } from './overlays/OverlayUtil'
157
170
  import {
158
171
  ShapeUtil,
159
172
  TLEditStartInfo,
@@ -210,18 +223,22 @@ export interface TLEditorOptions {
210
223
  */
211
224
  bindingUtils: readonly TLAnyBindingUtilConstructor[]
212
225
  /**
213
- * An array of tools to use in the editor. These will be used to handle events and manage user interactions in the editor.
226
+ * An array of asset utils to use in the editor. These will be used to handle asset-type-specific behavior.
214
227
  */
215
- tools: readonly TLStateNodeConstructor[]
228
+ assetUtils?: readonly TLAnyAssetUtilConstructor[]
216
229
  /**
217
- * Should return a containing html element which has all the styles applied to the editor. If not
218
- * given, the body element will be used.
230
+ * An array of overlay utils to use in the editor. These define canvas overlay UI elements
231
+ * like selection handles, rotation corners, shape handles, etc.
219
232
  */
220
- getContainer(): HTMLElement
233
+ overlayUtils?: readonly TLAnyOverlayUtilConstructor[]
234
+ /**
235
+ * An array of tools to use in the editor. These will be used to handle events and manage user interactions in the editor.
236
+ */
237
+ tools: readonly TLStateNodeConstructor[]
221
238
  /**
222
239
  * A user defined externally to replace the default user.
223
240
  */
224
- user?: TLUser
241
+ user?: TLCurrentUser
225
242
  /**
226
243
  * The editor's initial active tool (or other state node id).
227
244
  */
@@ -230,25 +247,13 @@ export interface TLEditorOptions {
230
247
  * Whether to automatically focus the editor when it mounts.
231
248
  */
232
249
  autoFocus?: boolean
233
- /**
234
- * Whether to infer dark mode from the user's system preferences. Defaults to false.
235
- */
236
- inferDarkMode?: boolean
237
- /**
238
- * Options for the editor's camera.
239
- *
240
- * @deprecated Use `options.cameraOptions` instead. This will be removed in a future release.
241
- */
242
- cameraOptions?: Partial<TLCameraOptions>
243
- options?: Partial<TldrawOptions>
244
- /**
245
- * Text options for the editor.
246
- *
247
- * @deprecated Use `options.text` instead. This prop will be removed in a future release.
248
- */
249
- textOptions?: TLTextOptions
250
250
  licenseKey?: string
251
251
  fontAssetUrls?: { [key: string]: string | undefined }
252
+ /**
253
+ * Should return a containing html element which has all the styles applied to the editor. If not
254
+ * given, the body element will be used.
255
+ */
256
+ getContainer(): HTMLElement
252
257
  /**
253
258
  * Provides a way to hide shapes.
254
259
  *
@@ -268,6 +273,41 @@ export interface TLEditorOptions {
268
273
  shape: TLShape,
269
274
  editor: Editor
270
275
  ): 'visible' | 'hidden' | 'inherit' | null | undefined
276
+ /**
277
+ * Named theme definitions for the editor. Each theme contains shared
278
+ * properties (font size, line height, stroke width) and color palettes
279
+ * for both light and dark modes.
280
+ */
281
+ themes?: Partial<TLThemes>
282
+ /**
283
+ * The id of the initially active theme. Defaults to `'default'`.
284
+ */
285
+ initialTheme?: TLThemeId
286
+ /**
287
+ * The editor's color scheme preference, controls the default color mode. Defaults to `'light'`.
288
+ *
289
+ * - `'light'` - Always use light mode.
290
+ * - `'dark'` - Always use dark mode.
291
+ * - `'system'` - Follow the OS color scheme preference.
292
+ */
293
+ colorScheme?: 'light' | 'dark' | 'system'
294
+ /**
295
+ * Additional configuration options for the tldraw editor.
296
+ */
297
+ options?: Partial<TldrawOptions>
298
+ // --- Deprecated ----
299
+ /**
300
+ * Options for the editor's camera.
301
+ *
302
+ * @deprecated Use `options.cameraOptions` instead. This will be removed in a future release.
303
+ */
304
+ cameraOptions?: Partial<TLCameraOptions>
305
+ /**
306
+ * Text options for the editor.
307
+ *
308
+ * @deprecated Use `options.text` instead. This prop will be removed in a future release.
309
+ */
310
+ textOptions?: TLTextOptions
271
311
  }
272
312
 
273
313
  /**
@@ -296,6 +336,8 @@ export class Editor extends EventEmitter<TLEventMap> {
296
336
  user,
297
337
  shapeUtils,
298
338
  bindingUtils,
339
+ assetUtils: assetUtilConstructors,
340
+ overlayUtils: overlayUtilConstructors,
299
341
  tools,
300
342
  getContainer,
301
343
  // needs to be here for backwards compatibility with TldrawEditor
@@ -303,13 +345,15 @@ export class Editor extends EventEmitter<TLEventMap> {
303
345
  cameraOptions,
304
346
  initialState,
305
347
  autoFocus,
306
- inferDarkMode,
307
348
  options: _options,
308
349
  // needs to be here for backwards compatibility with TldrawEditor
309
350
  // eslint-disable-next-line @typescript-eslint/no-deprecated
310
351
  textOptions: _textOptions,
311
352
  getShapeVisibility,
353
+ colorScheme,
312
354
  fontAssetUrls,
355
+ themes,
356
+ initialTheme,
313
357
  }: TLEditorOptions) {
314
358
  super()
315
359
 
@@ -344,21 +388,37 @@ export class Editor extends EventEmitter<TLEventMap> {
344
388
  ...options?.camera,
345
389
  })
346
390
 
391
+ this.getContainer = getContainer
392
+
347
393
  this._textOptions = atom('text options', options?.text ?? null)
348
394
 
349
- this.user = new UserPreferencesManager(user ?? createTLUser(), inferDarkMode ?? false)
395
+ this.user = new UserPreferencesManager(user ?? createTLCurrentUser(), colorScheme ?? 'light')
350
396
  this.disposables.add(() => this.user.dispose())
351
397
 
352
- this.getContainer = getContainer
353
-
354
398
  this.textMeasure = new TextManager(this)
355
399
  this.disposables.add(() => this.textMeasure.dispose())
356
400
 
357
- this.fonts = new FontManager(this, fontAssetUrls)
401
+ this._themeManager = new ThemeManager(this, {
402
+ themes: resolveThemes(themes),
403
+ initial: initialTheme ?? 'default',
404
+ })
405
+ this.disposables.add(() => this._themeManager.dispose())
358
406
 
359
407
  this._tickManager = new TickManager(this)
408
+ this.disposables.add(() => this._tickManager.dispose())
409
+ this.disposables.add(() => {
410
+ // Reset camera state to 'idle' so the store isn't left stuck at 'moving'
411
+ // when tick events stop (e.g. React strict mode disposes while camera is moving)
412
+ this.off('tick', this._decayCameraStateTimeout)
413
+ this._setCameraState('idle')
414
+ })
415
+
416
+ this.fonts = new FontManager(this, fontAssetUrls)
360
417
 
361
418
  this.inputs = new InputsManager(this)
419
+ this.performance = new PerformanceManager(this)
420
+ this.disposables.add(() => this.performance.dispose())
421
+ this.collaborators = new CollaboratorsManager(this)
362
422
 
363
423
  class NewRoot extends RootState {
364
424
  static override initial = initialState ?? ''
@@ -396,6 +456,17 @@ export class Editor extends EventEmitter<TLEventMap> {
396
456
  this.shapeUtils = _shapeUtils
397
457
  this.styleProps = _styleProps
398
458
 
459
+ const _shapeUtilsByAssetType = {} as Record<string, ShapeUtil<any>>
460
+ for (const Util of allShapeUtils) {
461
+ const assetTypes = Util.handledAssetTypes
462
+ if (assetTypes) {
463
+ for (const assetType of assetTypes) {
464
+ _shapeUtilsByAssetType[assetType] = _shapeUtils[Util.type]
465
+ }
466
+ }
467
+ }
468
+ this._shapeUtilsByAssetType = _shapeUtilsByAssetType
469
+
399
470
  const allBindingUtils = checkBindings(bindingUtils)
400
471
  const _bindingUtils = {} as Record<string, BindingUtil<any>>
401
472
  for (const Util of allBindingUtils) {
@@ -404,6 +475,17 @@ export class Editor extends EventEmitter<TLEventMap> {
404
475
  }
405
476
  this.bindingUtils = _bindingUtils
406
477
 
478
+ // Asset utils
479
+ if (assetUtilConstructors) {
480
+ const allAssetUtils = checkAssets(assetUtilConstructors)
481
+ const _assetUtils = {} as Record<string, AssetUtil<any>>
482
+ for (const Util of allAssetUtils) {
483
+ const util = new Util(this)
484
+ _assetUtils[Util.type] = util
485
+ }
486
+ this.assetUtils = _assetUtils
487
+ }
488
+
407
489
  // Tools.
408
490
  // Accept tools from constructor parameters which may not conflict with the root note's default or
409
491
  // "baked in" tools, select and zoom.
@@ -416,6 +498,15 @@ export class Editor extends EventEmitter<TLEventMap> {
416
498
 
417
499
  this.scribbles = new ScribbleManager(this)
418
500
 
501
+ // Overlay utils
502
+ this.overlays = new OverlayManager(this)
503
+ if (overlayUtilConstructors) {
504
+ for (const Util of overlayUtilConstructors) {
505
+ const util = new Util(this)
506
+ this.overlays.registerUtil(util)
507
+ }
508
+ }
509
+
419
510
  // Cleanup
420
511
 
421
512
  const cleanupInstancePageState = (
@@ -820,6 +911,15 @@ export class Editor extends EventEmitter<TLEventMap> {
820
911
  })
821
912
  )
822
913
  }
914
+
915
+ this.disposables.add(
916
+ react('sync current user record', () => {
917
+ const user = this.store.props.users.currentUser.get()
918
+ if (user) {
919
+ this._ensureUserRecord(user)
920
+ }
921
+ })
922
+ )
823
923
  }
824
924
 
825
925
  private readonly _getShapeVisibility?: TLEditorOptions['getShapeVisibility']
@@ -929,6 +1029,18 @@ export class Editor extends EventEmitter<TLEventMap> {
929
1029
  */
930
1030
  readonly snaps: SnapManager
931
1031
 
1032
+ /**
1033
+ * A manager for performance measurement hooks.
1034
+ *
1035
+ * @public
1036
+ */
1037
+ readonly performance: PerformanceManager
1038
+
1039
+ /**
1040
+ * A manager for the spatial index, tracking where shapes exist on the canvas.
1041
+ *
1042
+ * @internal
1043
+ */
932
1044
  private readonly _spatialIndex: SpatialIndexManager
933
1045
 
934
1046
  /**
@@ -939,6 +1051,13 @@ export class Editor extends EventEmitter<TLEventMap> {
939
1051
  */
940
1052
  readonly timers = tltime.forContext(this.contextId)
941
1053
 
1054
+ /**
1055
+ * A manager for remote peer collaborators connected to this editor.
1056
+ *
1057
+ * @public
1058
+ */
1059
+ readonly collaborators: CollaboratorsManager
1060
+
942
1061
  /**
943
1062
  * A manager for the user and their preferences.
944
1063
  *
@@ -946,6 +1065,13 @@ export class Editor extends EventEmitter<TLEventMap> {
946
1065
  */
947
1066
  readonly user: UserPreferencesManager
948
1067
 
1068
+ /**
1069
+ * A manager for the editor's themes.
1070
+ *
1071
+ * @internal
1072
+ */
1073
+ private readonly _themeManager: ThemeManager
1074
+
949
1075
  /**
950
1076
  * A helper for measuring text.
951
1077
  *
@@ -967,6 +1093,13 @@ export class Editor extends EventEmitter<TLEventMap> {
967
1093
  */
968
1094
  readonly scribbles: ScribbleManager
969
1095
 
1096
+ /**
1097
+ * A manager for canvas overlay UI elements (selection handles, shape handles, etc.).
1098
+ *
1099
+ * @public
1100
+ */
1101
+ readonly overlays: OverlayManager
1102
+
970
1103
  /**
971
1104
  * A manager for side effects and correct state enforcement. See {@link @tldraw/store#StoreSideEffects} for details.
972
1105
  *
@@ -1026,13 +1159,134 @@ export class Editor extends EventEmitter<TLEventMap> {
1026
1159
  * @public
1027
1160
  */
1028
1161
  dispose() {
1162
+ // Stop any in-progress camera animations and following before
1163
+ // running disposables, so their cleanup listeners fire first
1164
+ this.stopCameraAnimation()
1165
+ if (this.getInstanceState().followingUserId) {
1166
+ this.stopFollowingUser()
1167
+ }
1168
+
1029
1169
  this.disposables.forEach((dispose) => dispose())
1030
1170
  this.disposables.clear()
1171
+
1172
+ // Clear any open menus for this editor's context
1173
+ this.menus.clearOpenMenus()
1174
+
1031
1175
  this.store.dispose()
1032
1176
  this.isDisposed = true
1033
1177
  this.emit('dispose')
1034
1178
  }
1035
1179
 
1180
+ /* ------------------ Themes (shadowing the theme manager) ------------------ */
1181
+
1182
+ /**
1183
+ * Get the current color mode (`'light'` or `'dark'`), based on the user's dark mode preference.
1184
+ *
1185
+ * @public
1186
+ */
1187
+ getColorMode(): 'light' | 'dark' {
1188
+ return this._themeManager.getColorMode()
1189
+ }
1190
+
1191
+ /**
1192
+ * Set the color mode. Note that this is a convenience method that passes the mode to
1193
+ * `user.updateUserPreferences`, which is the source of truth for the user's color mode preference.
1194
+ *
1195
+ * @public
1196
+ */
1197
+ setColorMode(mode: 'light' | 'dark') {
1198
+ this.user.updateUserPreferences({ colorScheme: mode })
1199
+ return this
1200
+ }
1201
+
1202
+ /**
1203
+ * Get the id of the current theme.
1204
+ *
1205
+ * @public
1206
+ */
1207
+ getCurrentThemeId(): TLThemeId {
1208
+ return this._themeManager.getCurrentThemeId()
1209
+ }
1210
+
1211
+ /**
1212
+ * Get the current theme definition.
1213
+ *
1214
+ * @public
1215
+ */
1216
+ getCurrentTheme(): TLTheme {
1217
+ return this._themeManager.getCurrentTheme()
1218
+ }
1219
+
1220
+ /**
1221
+ * Set the current theme by id.
1222
+ *
1223
+ * @public
1224
+ */
1225
+ setCurrentTheme(id: TLThemeId) {
1226
+ this._themeManager.setCurrentTheme(id)
1227
+ return this
1228
+ }
1229
+
1230
+ /**
1231
+ * Get all registered theme definitions.
1232
+ *
1233
+ * @public
1234
+ */
1235
+ getThemes(): TLThemes {
1236
+ return this._themeManager.getThemes()
1237
+ }
1238
+
1239
+ /**
1240
+ * Get a single theme definition by id.
1241
+ *
1242
+ * @public
1243
+ */
1244
+ getTheme(id: TLThemeId): TLTheme | undefined {
1245
+ return this._themeManager.getTheme(id)
1246
+ }
1247
+
1248
+ /**
1249
+ * Replace all theme definitions, or update them via a callback that receives a deep copy.
1250
+ * The `'default'` theme must always be present in the result.
1251
+ *
1252
+ * @example
1253
+ * ```ts
1254
+ * // Replace all themes
1255
+ * editor.updateThemes({ default: myDefaultTheme, ocean: myOceanTheme })
1256
+ *
1257
+ * // Update via callback
1258
+ * editor.updateThemes((themes) => {
1259
+ * delete themes.ocean
1260
+ * return themes
1261
+ * })
1262
+ * ```
1263
+ *
1264
+ * @public
1265
+ */
1266
+ updateThemes(themes: TLThemes | ((themes: TLThemes) => TLThemes)) {
1267
+ this._themeManager.updateThemes(themes)
1268
+ return this
1269
+ }
1270
+
1271
+ /**
1272
+ * Register or update a single theme definition. The theme is keyed by its `id` property.
1273
+ *
1274
+ * @example
1275
+ * ```ts
1276
+ * // Override a property on the default theme
1277
+ * editor.updateTheme({ ...editor.getTheme('default')!, fontSize: 24 })
1278
+ *
1279
+ * // Register a new theme
1280
+ * editor.updateTheme({ id: 'ocean', ...myOceanTheme })
1281
+ * ```
1282
+ *
1283
+ * @public
1284
+ */
1285
+ updateTheme(theme: TLTheme) {
1286
+ this._themeManager.updateTheme(theme)
1287
+ return this
1288
+ }
1289
+
1036
1290
  /* ------------------- Shape Utils ------------------ */
1037
1291
 
1038
1292
  /**
@@ -1042,6 +1296,9 @@ export class Editor extends EventEmitter<TLEventMap> {
1042
1296
  */
1043
1297
  shapeUtils: { readonly [K in string]?: ShapeUtil<TLShape> }
1044
1298
 
1299
+ /** @internal */
1300
+ private _shapeUtilsByAssetType: { readonly [K in string]?: ShapeUtil<TLShape> } = {}
1301
+
1045
1302
  styleProps: { [key: string]: Map<StyleProp<any>, string> }
1046
1303
 
1047
1304
  /**
@@ -1084,6 +1341,18 @@ export class Editor extends EventEmitter<TLEventMap> {
1084
1341
  return hasOwnProperty(this.shapeUtils, type)
1085
1342
  }
1086
1343
 
1344
+ /**
1345
+ * Get the shape util that handles the given asset type.
1346
+ * Returns the shape util whose {@link ShapeUtil.handledAssetTypes} includes
1347
+ * the given asset type, or undefined if none matches.
1348
+ *
1349
+ * @param assetType - The asset type string.
1350
+ * @public
1351
+ */
1352
+ getShapeUtilForAssetType(assetType: string): ShapeUtil | undefined {
1353
+ return getOwnProperty(this._shapeUtilsByAssetType, assetType)
1354
+ }
1355
+
1087
1356
  /* ------------------- Binding Utils ------------------ */
1088
1357
  /**
1089
1358
  * A map of shape utility classes (TLShapeUtils) by shape type.
@@ -1119,6 +1388,56 @@ export class Editor extends EventEmitter<TLEventMap> {
1119
1388
  return bindingUtil
1120
1389
  }
1121
1390
 
1391
+ /* ------------------- Asset Utils ------------------ */
1392
+
1393
+ /**
1394
+ * A map of asset utility classes by asset type.
1395
+ *
1396
+ * @public
1397
+ */
1398
+ assetUtils: { readonly [K in string]?: AssetUtil<TLAsset> } = {}
1399
+
1400
+ /**
1401
+ * Get an asset util from an asset or asset type.
1402
+ *
1403
+ * @param arg - An asset, asset type string, or object with type.
1404
+ *
1405
+ * @public
1406
+ */
1407
+ getAssetUtil<S extends TLAsset>(asset: S | { type: S['type'] }): AssetUtil<S>
1408
+ getAssetUtil(type: string): AssetUtil
1409
+ getAssetUtil(arg: string | { type: string }) {
1410
+ const type = typeof arg === 'string' ? arg : arg.type
1411
+ const assetUtil = getOwnProperty(this.assetUtils, type)
1412
+ assert(assetUtil, `No asset util found for type "${type}"`)
1413
+ return assetUtil
1414
+ }
1415
+
1416
+ /**
1417
+ * Returns true if the editor has an asset util for the given asset type.
1418
+ *
1419
+ * @public
1420
+ */
1421
+ hasAssetUtil(arg: string | { type: string }): boolean {
1422
+ const type = typeof arg === 'string' ? arg : arg.type
1423
+ return hasOwnProperty(this.assetUtils, type)
1424
+ }
1425
+
1426
+ /**
1427
+ * Get the asset util that accepts the given MIME type.
1428
+ * Returns null if no registered asset util accepts the MIME type.
1429
+ *
1430
+ * @public
1431
+ */
1432
+ getAssetUtilForMimeType(mimeType: string): AssetUtil | null {
1433
+ for (const util of Object.values(this.assetUtils)) {
1434
+ if (util && util.acceptsMimeType(mimeType)) {
1435
+ return util
1436
+ }
1437
+ }
1438
+ return null
1439
+ }
1440
+
1122
1441
  /* --------------------- History -------------------- */
1123
1442
 
1124
1443
  /**
@@ -1142,6 +1461,7 @@ export class Editor extends EventEmitter<TLEventMap> {
1142
1461
  this._flushEventsForTick(0)
1143
1462
  this.complete()
1144
1463
  this.history.undo()
1464
+ this.performance._notifyUndoRedo('undo', this.history.getNumUndos(), this.history.getNumRedos())
1145
1465
  return this
1146
1466
  }
1147
1467
 
@@ -1172,6 +1492,7 @@ export class Editor extends EventEmitter<TLEventMap> {
1172
1492
  this._flushEventsForTick(0)
1173
1493
  this.complete()
1174
1494
  this.history.redo()
1495
+ this.performance._notifyUndoRedo('redo', this.history.getNumUndos(), this.history.getNumRedos())
1175
1496
  return this
1176
1497
  }
1177
1498
 
@@ -1623,11 +1944,23 @@ export class Editor extends EventEmitter<TLEventMap> {
1623
1944
  /**
1624
1945
  * Set the cursor.
1625
1946
  *
1947
+ * No-op when the partial wouldn't change the current cursor — `setCursor`
1948
+ * is called from pointer-move hot paths (see `updateHoveredOverlayId`,
1949
+ * various tool states) and skipping redundant writes avoids needlessly
1950
+ * dirtying instance state.
1951
+ *
1626
1952
  * @param cursor - The cursor to set.
1627
1953
  * @public
1628
1954
  */
1629
1955
  setCursor(cursor: Partial<TLCursor>) {
1630
- this.updateInstanceState({ cursor: { ...this.getInstanceState().cursor, ...cursor } })
1956
+ const current = this.getInstanceState().cursor
1957
+ if (
1958
+ (cursor.type === undefined || cursor.type === current.type) &&
1959
+ (cursor.rotation === undefined || cursor.rotation === current.rotation)
1960
+ ) {
1961
+ return this
1962
+ }
1963
+ this.updateInstanceState({ cursor: { ...current, ...cursor } })
1631
1964
  return this
1632
1965
  }
1633
1966
 
@@ -3933,43 +4266,143 @@ export class Editor extends EventEmitter<TLEventMap> {
3933
4266
  }
3934
4267
  // Collaborators
3935
4268
 
3936
- @computed
3937
- private _getCollaboratorsQuery() {
3938
- return this.store.query.records('instance_presence', () => ({
3939
- userId: { neq: this.user.getId() },
3940
- }))
3941
- }
3942
-
3943
4269
  /**
3944
4270
  * Returns a list of presence records for all peer collaborators.
3945
4271
  * This will return the latest presence record for each connected user.
3946
4272
  *
4273
+ * Convenience wrapper for {@link CollaboratorsManager.getCollaborators}.
4274
+ *
3947
4275
  * @public
3948
4276
  */
3949
- @computed
3950
4277
  getCollaborators() {
3951
- const allPresenceRecords = this._getCollaboratorsQuery().get()
3952
- if (!allPresenceRecords.length) return EMPTY_ARRAY
3953
- const userIds = [...new Set(allPresenceRecords.map((c) => c.userId))].sort()
3954
- return userIds.map((id) => {
3955
- const latestPresence = maxBy(
3956
- allPresenceRecords.filter((c) => c.userId === id),
3957
- (p) => p.lastActivityTimestamp ?? 0
3958
- )
3959
- return latestPresence!
3960
- })
4278
+ return this.collaborators.getCollaborators()
3961
4279
  }
3962
4280
 
3963
4281
  /**
3964
4282
  * Returns a list of presence records for all peer collaborators on the current page.
3965
4283
  * This will return the latest presence record for each connected user.
3966
4284
  *
4285
+ * Convenience wrapper for {@link CollaboratorsManager.getCollaboratorsOnCurrentPage}.
4286
+ *
3967
4287
  * @public
3968
4288
  */
3969
- @computed
3970
4289
  getCollaboratorsOnCurrentPage() {
3971
- const currentPageId = this.getCurrentPageId()
3972
- return this.getCollaborators().filter((c) => c.currentPageId === currentPageId)
4290
+ return this.collaborators.getCollaboratorsOnCurrentPage()
4291
+ }
4292
+
4293
+ /**
4294
+ * Returns a list of presence records for peer collaborators who should currently be
4295
+ * shown in the UI. Filters {@link Editor.getCollaborators} by activity state
4296
+ * (active / idle / inactive) and visibility rules such as following and highlighted
4297
+ * users. Re-evaluates on the collaborator visibility clock, so callers don't need to
4298
+ * drive their own activity timer.
4299
+ *
4300
+ * Convenience wrapper for {@link CollaboratorsManager.getVisibleCollaborators}.
4301
+ *
4302
+ * @public
4303
+ */
4304
+ getVisibleCollaborators() {
4305
+ return this.collaborators.getVisibleCollaborators()
4306
+ }
4307
+
4308
+ /**
4309
+ * Returns a list of presence records for peer collaborators who should currently be
4310
+ * shown in the UI, filtered to those on the current page.
4311
+ *
4312
+ * Convenience wrapper for {@link CollaboratorsManager.getVisibleCollaboratorsOnCurrentPage}.
4313
+ *
4314
+ * @public
4315
+ */
4316
+ getVisibleCollaboratorsOnCurrentPage() {
4317
+ return this.collaborators.getVisibleCollaboratorsOnCurrentPage()
4318
+ }
4319
+
4320
+ // Attribution
4321
+
4322
+ /**
4323
+ * Get the current user's ID for attribution purposes.
4324
+ * Also ensures a `user:` record exists in the store for the current user.
4325
+ * Returns `null` when the user store has no current user.
4326
+ *
4327
+ * @public
4328
+ */
4329
+ getAttributionUserId(): string | null {
4330
+ const user = this.store.props.users.currentUser.get()
4331
+ if (!user) return null
4332
+ this._ensureUserRecord(user)
4333
+ return UserRecordType.parseId(user.id)
4334
+ }
4335
+
4336
+ /**
4337
+ * Ensure a user record exists in the store for the given user,
4338
+ * updating it if the data has changed.
4339
+ *
4340
+ * @internal
4341
+ */
4342
+ _ensureUserRecord(user: TLUser): void {
4343
+ const existing = this.store.get(user.id)
4344
+ if (
4345
+ existing &&
4346
+ existing.name === user.name &&
4347
+ existing.color === user.color &&
4348
+ existing.imageUrl === user.imageUrl &&
4349
+ existing.meta === user.meta
4350
+ ) {
4351
+ return
4352
+ }
4353
+ this.run(
4354
+ () => {
4355
+ this.store.put([user])
4356
+ },
4357
+ { history: 'ignore' }
4358
+ )
4359
+ }
4360
+
4361
+ /**
4362
+ * Resolve a display name for a user ID. Asks the
4363
+ * {@link @tldraw/tlschema#TLUserStore} first (the app's source of truth),
4364
+ * falling back to the `user:` record in the store.
4365
+ *
4366
+ * @public
4367
+ */
4368
+ getAttributionDisplayName(userId: string | null): string | null {
4369
+ if (!userId) return null
4370
+ return (
4371
+ this.store.props.users.resolve(userId).get()?.name ??
4372
+ this.store.get(createUserId(userId))?.name ??
4373
+ null
4374
+ )
4375
+ }
4376
+
4377
+ /**
4378
+ * Resolve a user record by ID. Asks the
4379
+ * {@link @tldraw/tlschema#TLUserStore} first (the app's source of truth),
4380
+ * falling back to the `user:` record in the store.
4381
+ *
4382
+ * @public
4383
+ */
4384
+ getAttributionUser(userId: string | null): TLUser | null {
4385
+ if (!userId) return null
4386
+ return (
4387
+ this.store.props.users.resolve(userId).get() ?? this.store.get(createUserId(userId)) ?? null
4388
+ )
4389
+ }
4390
+
4391
+ /**
4392
+ * Collect user IDs referenced by a set of shapes via shape-specific props
4393
+ * (e.g. `textFirstEditedBy` on notes).
4394
+ *
4395
+ * @internal
4396
+ */
4397
+ _getReferencedUserIds(shapes: TLShape[]): Set<string> {
4398
+ const userIds = new Set<string>()
4399
+ for (const shape of shapes) {
4400
+ const util = this.getShapeUtil(shape)
4401
+ for (const id of util.getReferencedUserIds(shape)) {
4402
+ userIds.add(id)
4403
+ }
4404
+ }
4405
+ return userIds
3973
4406
  }
3974
4407
 
3975
4408
  // Following
@@ -4735,7 +5168,7 @@ export class Editor extends EventEmitter<TLEventMap> {
4735
5168
  const zoomStepFunction = (zoom: number) => Math.pow(2, Math.ceil(Math.log2(zoom)))
4736
5169
  const steppedScreenScale = zoomStepFunction(screenScale)
4737
5170
  const networkEffectiveType: string | null =
4738
- 'connection' in navigator ? (navigator as any).connection.effectiveType : null
5171
+ 'connection' in navigator ? ((navigator as any).connection?.effectiveType ?? null) : null
4739
5172
 
4740
5173
  return await this.store.props.assets.resolve(asset, {
4741
5174
  screenScale: screenScale || 1,
@@ -5326,8 +5759,8 @@ export class Editor extends EventEmitter<TLEventMap> {
5326
5759
  ? this.getCurrentPageRenderingShapesSorted()
5327
5760
  : this.getCurrentPageShapesSorted()
5328
5761
  ).filter((shape) => {
5329
- // Frames have labels positioned above the shape (outside bounds), so always include them
5330
- if (!candidateIds.has(shape.id) && !this.isShapeOfType(shape, 'frame')) return false
5762
+ // Frame-like shapes have labels positioned above the shape (outside bounds), so always include them
5763
+ if (!candidateIds.has(shape.id) && !this.isShapeFrameLike(shape)) return false
5331
5764
 
5332
5765
  if (
5333
5766
  (shape.isLocked && !hitLocked) ||
@@ -5349,12 +5782,14 @@ export class Editor extends EventEmitter<TLEventMap> {
5349
5782
  const pointInShapeSpace = this.getPointInShapeSpace(shape, point)
5350
5783
 
5351
5784
  // Check labels first
5785
+ const shapeUtil = this.getShapeUtil(shape)
5786
+ const isShapeFrameLike = this.isShapeFrameLike(shape)
5352
5787
  if (
5353
- this.isShapeOfType(shape, 'frame') ||
5788
+ isShapeFrameLike ||
5354
5789
  ((this.isShapeOfType(shape, 'note') ||
5355
5790
  this.isShapeOfType(shape, 'arrow') ||
5356
5791
  (this.isShapeOfType(shape, 'geo') && shape.props.fill === 'none')) &&
5357
- this.getShapeUtil(shape).getText(shape)?.trim())
5792
+ shapeUtil.getText(shape)?.trim())
5358
5793
  ) {
5359
5794
  for (const childGeometry of (geometry as Group2d).children) {
5360
5795
  if (childGeometry.isLabel && childGeometry.isPointInBounds(pointInShapeSpace)) {
@@ -5363,8 +5798,8 @@ export class Editor extends EventEmitter<TLEventMap> {
5363
5798
  }
5364
5799
  }
5365
5800
 
5366
- if (this.isShapeOfType(shape, 'frame')) {
5367
- // On the rare case that we've hit a frame (not its label), test again hitInside to be forced true;
5801
+ if (isShapeFrameLike) {
5802
+ // On the rare case that we've hit a frame-like shape (not its label), test again hitInside to be forced true;
5368
5803
  // this prevents clicks from passing through the body of a frame to shapes behind it.
5369
5804
 
5370
5805
  // If the hit is within the frame's outer margin, then select the frame
@@ -5523,11 +5958,11 @@ export class Editor extends EventEmitter<TLEventMap> {
5523
5958
  const candidateIds = this._spatialIndex.getShapeIdsAtPoint(point, margin)
5524
5959
 
5525
5960
  // Get all page shapes in z-index order and filter to candidates that pass isPointInShape
5526
- // Frames are always checked because their labels can be outside their bounds
5961
+ // Frame-like shapes are always checked because their labels can be outside their bounds
5527
5962
  return this.getCurrentPageShapesSorted()
5528
5963
  .filter((shape) => {
5529
5964
  if (this.isShapeHidden(shape)) return false
5530
- if (!candidateIds.has(shape.id) && !this.isShapeOfType(shape, 'frame')) return false
5965
+ if (!candidateIds.has(shape.id) && !this.isShapeFrameLike(shape)) return false
5531
5966
  return this.isPointInShape(shape, point, opts)
5532
5967
  })
5533
5968
  .reverse()
@@ -5702,6 +6137,25 @@ export class Editor extends EventEmitter<TLEventMap> {
5702
6137
  return shape.type === type
5703
6138
  }
5704
6139
 
6140
+ /**
6141
+ * Get whether a shape behaves like a frame — a container that has child
6142
+ * shapes, requires full-brush selection, blocks erasure from inside, etc.
6143
+ *
6144
+ * @example
6145
+ * ```ts
6146
+ * const isFrameLike = editor.isShapeFrameLike(someShape)
6147
+ * ```
6148
+ *
6149
+ * @param shape - The shape (or shape id) to test.
6150
+ *
6151
+ * @public
6152
+ */
6153
+ isShapeFrameLike(shape: TLShape | TLShapeId): boolean {
6154
+ const _shape = typeof shape === 'string' ? this.getShape(shape) : shape
6155
+ if (!_shape) return false
6156
+ return this.getShapeUtil(_shape).isFrameLike(_shape)
6157
+ }
6158
+
5705
6159
  /**
5706
6160
  * Get a shape by its id.
5707
6161
  *
@@ -9071,6 +9525,7 @@ export class Editor extends EventEmitter<TLEventMap> {
9071
9525
  opts = {} as { force?: boolean }
9072
9526
  ): Promise<void> {
9073
9527
  if (!opts.force && this.getIsReadonly()) return
9528
+
9074
9529
  return this.externalContentHandlers[info.type]?.(info as any)
9075
9530
  }
9076
9531
 
@@ -9156,12 +9611,23 @@ export class Editor extends EventEmitter<TLEventMap> {
9156
9611
  assets.push(asset)
9157
9612
  }
9158
9613
 
9614
+ const users: TLUser[] = []
9615
+ const seenUserIds = new Set<TLUserId>()
9616
+ for (const userId of this._getReferencedUserIds(shapes)) {
9617
+ const recordId = createUserId(userId)
9618
+ if (seenUserIds.has(recordId)) continue
9619
+ seenUserIds.add(recordId)
9620
+ const user = this.store.get(recordId)
9621
+ if (user) users.push(user)
9622
+ }
9623
+
9159
9624
  return {
9160
9625
  schema: this.store.schema.serialize(),
9161
9626
  shapes,
9162
9627
  rootShapeIds,
9163
9628
  bindings,
9164
9629
  assets,
9630
+ users,
9165
9631
  }
9166
9632
  })
9167
9633
  }
@@ -9237,6 +9703,7 @@ export class Editor extends EventEmitter<TLEventMap> {
9237
9703
  const assets: TLAsset[] = []
9238
9704
  const shapes: TLShape[] = []
9239
9705
  const bindings: TLBinding[] = []
9706
+ const users: TLUser[] = []
9240
9707
 
9241
9708
  // Let's treat the content as a store, and then migrate that store.
9242
9709
  const store: StoreSnapshot<TLRecord> = {
@@ -9246,6 +9713,7 @@ export class Editor extends EventEmitter<TLEventMap> {
9246
9713
  ...Object.fromEntries(
9247
9714
  content.bindings?.map((bindings) => [bindings.id, bindings] as const) ?? []
9248
9715
  ),
9716
+ ...Object.fromEntries(content.users?.map((user) => [user.id, user] as const) ?? []),
9249
9717
  },
9250
9718
  schema: content.schema,
9251
9719
  }
@@ -9267,6 +9735,23 @@ export class Editor extends EventEmitter<TLEventMap> {
9267
9735
  bindings.push(record)
9268
9736
  break
9269
9737
  }
9738
+ case 'user': {
9739
+ users.push(record)
9740
+ break
9741
+ }
9742
+ }
9743
+ }
9744
+
9745
+ if (users.length > 0) {
9746
+ const existingUserIds = new Set(
9747
+ this.store
9748
+ .allRecords()
9749
+ .filter((r): r is TLUser => r.typeName === 'user')
9750
+ .map((r) => r.id)
9751
+ )
9752
+ const usersToCreate = users.filter((u) => !existingUserIds.has(u.id))
9753
+ if (usersToCreate.length > 0) {
9754
+ this.store.put(usersToCreate)
9270
9755
  }
9271
9756
  }
9272
9757
 
@@ -10457,6 +10942,7 @@ export class Editor extends EventEmitter<TLEventMap> {
10457
10942
  { immediate: true }
10458
10943
  )
10459
10944
 
10945
+ this.performance._notifyCameraOperation('zooming')
10460
10946
  this.emit('event', info)
10461
10947
  return // Stop here!
10462
10948
  }
@@ -10549,6 +11035,7 @@ export class Editor extends EventEmitter<TLEventMap> {
10549
11035
  immediate: true,
10550
11036
  })
10551
11037
  this.maybeTrackPerformance('Zooming')
11038
+ this.performance._notifyCameraOperation('zooming')
10552
11039
  this.root.handleEvent(info)
10553
11040
  this.emit('event', info)
10554
11041
  return
@@ -10559,6 +11046,7 @@ export class Editor extends EventEmitter<TLEventMap> {
10559
11046
  immediate: true,
10560
11047
  })
10561
11048
  this.maybeTrackPerformance('Panning')
11049
+ this.performance._notifyCameraOperation('panning')
10562
11050
  this.root.handleEvent(info)
10563
11051
  this.emit('event', info)
10564
11052
  return
@@ -10625,6 +11113,10 @@ export class Editor extends EventEmitter<TLEventMap> {
10625
11113
  }
10626
11114
  this.inputs.setIsPanning(true)
10627
11115
  clearTimeout(this._longPressTimeout)
11116
+ } else if (info.button === RIGHT_MOUSE_BUTTON && this.options.rightClickPanning) {
11117
+ this.inputs.setIsRightPointing(true)
11118
+ clearTimeout(this._longPressTimeout)
11119
+ return this
10628
11120
  }
10629
11121
 
10630
11122
  // We might be panning because we did a middle mouse click, or because we're holding spacebar and started a regular click
@@ -10643,9 +11135,31 @@ export class Editor extends EventEmitter<TLEventMap> {
10643
11135
 
10644
11136
  const { x: cx, y: cy, z: cz } = unsafe__withoutCapture(() => this.getCamera())
10645
11137
 
11138
+ // Right-click pointing: waiting to see if this becomes a drag
11139
+ if (this.inputs.getIsRightPointing() && !this.inputs.getIsPanning()) {
11140
+ const currentScreenPoint = this.inputs.getCurrentScreenPoint()
11141
+ const originScreenPoint = this.inputs.getOriginScreenPoint()
11142
+ if (
11143
+ Vec.Dist2(originScreenPoint, currentScreenPoint) > this.options.dragDistanceSquared
11144
+ ) {
11145
+ // Passed the drag threshold—transition to panning
11146
+ this._prevCursor = this.getInstanceState().cursor.type
11147
+ this.inputs.setIsPanning(true)
11148
+ this.setCursor({ type: 'grabbing', rotation: 0 })
11149
+ this.stopCameraAnimation()
11150
+ // Apply the initial delta from the pointer down origin
11151
+ const offset = Vec.Sub(currentScreenPoint, originScreenPoint)
11152
+ this.setCamera(new Vec(cx + offset.x / cz, cy + offset.y / cz, cz), {
11153
+ immediate: true,
11154
+ })
11155
+ this.maybeTrackPerformance('Panning')
11156
+ }
11157
+ return
11158
+ }
11159
+
10646
11160
  // If we've started panning, then clear any long press timeout
10647
11161
  if (this.inputs.getIsPanning() && this.inputs.getIsPointing()) {
10648
- // Handle spacebar / middle mouse button panning
11162
+ // Handle spacebar / middle mouse button / right-click panning
10649
11163
  const currentScreenPoint = this.inputs.getCurrentScreenPoint()
10650
11164
  const previousScreenPoint = this.inputs.getPreviousScreenPoint()
10651
11165
  const offset = Vec.Sub(currentScreenPoint, previousScreenPoint)
@@ -10653,6 +11167,7 @@ export class Editor extends EventEmitter<TLEventMap> {
10653
11167
  immediate: true,
10654
11168
  })
10655
11169
  this.maybeTrackPerformance('Panning')
11170
+ this.performance._notifyCameraOperation('panning')
10656
11171
  return
10657
11172
  }
10658
11173
 
@@ -10677,13 +11192,24 @@ export class Editor extends EventEmitter<TLEventMap> {
10677
11192
  inputs.setIsDragging(false)
10678
11193
  inputs.setIsPointing(false)
10679
11194
  clearTimeout(this._longPressTimeout)
10680
-
10681
11195
  // Remove the button from the buttons set
10682
11196
  inputs.buttons.delete(info.button)
10683
11197
 
10684
11198
  // If we're in pen mode and we're not using a pen, stop here
10685
11199
  if (instanceState.isPenMode && !isPen) return
10686
11200
 
11201
+ // Right-click pointing ended without dragging—this is a static
11202
+ // right-click, so let it through to the state chart as right_click.
11203
+ // Check isPanning first: if we transitioned to panning, isRightPointing
11204
+ // is still true but we want the panning cleanup path instead.
11205
+ if (this.inputs.getIsRightPointing() && !this.inputs.getIsPanning()) {
11206
+ this.inputs.setIsRightPointing(false)
11207
+ this._selectedShapeIdsAtPointerDown = []
11208
+ break // fall through to state chart dispatch as right_click
11209
+ }
11210
+
11211
+ this.inputs.setIsRightPointing(false)
11212
+
10687
11213
  // Firefox bug fix...
10688
11214
  // If it's the same pointer that we stored earlier...
10689
11215
  // ... then it's probably still a left-mouse-click!
@@ -10706,11 +11232,26 @@ export class Editor extends EventEmitter<TLEventMap> {
10706
11232
  break
10707
11233
  }
10708
11234
  case MIDDLE_MOUSE_BUTTON: {
10709
- if (this.inputs.keys.has(' ')) {
11235
+ if (this.inputs.keys.has('Space')) {
11236
+ this.setCursor({ type: 'grab', rotation: 0 })
11237
+ } else {
11238
+ this.setCursor({ type: this._prevCursor, rotation: 0 })
11239
+ }
11240
+ break
11241
+ }
11242
+ case RIGHT_MOUSE_BUTTON: {
11243
+ if (this.inputs.keys.has('Space')) {
10710
11244
  this.setCursor({ type: 'grab', rotation: 0 })
10711
11245
  } else {
10712
11246
  this.setCursor({ type: this._prevCursor, rotation: 0 })
10713
11247
  }
11248
+ // Don't pass right-click panning events to the state chart
11249
+ // as it causes unintended shape selection on release
11250
+ if (slideSpeed > 0) {
11251
+ this.slideCamera({ speed: slideSpeed, direction: slideDirection })
11252
+ }
11253
+ this._selectedShapeIdsAtPointerDown = []
11254
+ return this
10714
11255
  }
10715
11256
  }
10716
11257