@tldraw/editor 4.6.0-internal.e29318c66fb0 → 4.6.0-next.0a51207761bb

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 (270) hide show
  1. package/dist-cjs/index.d.ts +850 -118
  2. package/dist-cjs/index.js +20 -6
  3. package/dist-cjs/index.js.map +3 -3
  4. package/dist-cjs/lib/TldrawEditor.js +59 -14
  5. package/dist-cjs/lib/TldrawEditor.js.map +3 -3
  6. package/dist-cjs/lib/components/MenuClickCapture.js +16 -1
  7. package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
  8. package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js +3 -3
  9. package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +1 -1
  11. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  12. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
  13. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +2 -2
  14. package/dist-cjs/lib/config/{createTLUser.js → createTLCurrentUser.js} +9 -9
  15. package/dist-cjs/lib/config/createTLCurrentUser.js.map +7 -0
  16. package/dist-cjs/lib/config/createTLStore.js +31 -1
  17. package/dist-cjs/lib/config/createTLStore.js.map +2 -2
  18. package/dist-cjs/lib/config/defaultAssets.js +36 -0
  19. package/dist-cjs/lib/config/defaultAssets.js.map +7 -0
  20. package/dist-cjs/lib/config/defaultShapes.js.map +2 -2
  21. package/dist-cjs/lib/editor/Editor.js +329 -12
  22. package/dist-cjs/lib/editor/Editor.js.map +3 -3
  23. package/dist-cjs/lib/editor/assets/AssetUtil.js +66 -0
  24. package/dist-cjs/lib/editor/assets/AssetUtil.js.map +7 -0
  25. package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js +1 -1
  26. package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +2 -2
  27. package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +2 -2
  28. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.js +80 -0
  29. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.js.map +7 -0
  30. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js +466 -0
  31. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js.map +7 -0
  32. package/dist-cjs/lib/editor/managers/PerformanceManager/perf-types.js +17 -0
  33. package/dist-cjs/lib/editor/managers/PerformanceManager/perf-types.js.map +7 -0
  34. package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js +1 -1
  35. package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +2 -2
  36. package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js.map +2 -2
  37. package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js +4 -4
  38. package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js.map +2 -2
  39. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +102 -30
  40. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
  41. package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js +106 -0
  42. package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js.map +7 -0
  43. package/dist-cjs/lib/editor/managers/ThemeManager/defaultThemes.js +586 -0
  44. package/dist-cjs/lib/editor/managers/ThemeManager/defaultThemes.js.map +7 -0
  45. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +6 -4
  46. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  47. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +21 -2
  48. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  49. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +1 -1
  50. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
  51. package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js +6 -0
  52. package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js.map +2 -2
  53. package/dist-cjs/lib/editor/tools/StateNode.js +14 -17
  54. package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
  55. package/dist-cjs/lib/editor/types/SvgExportContext.js.map +2 -2
  56. package/dist-cjs/lib/editor/types/clipboard-types.js.map +1 -1
  57. package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
  58. package/dist-cjs/lib/exports/StyleEmbedder.js +1 -1
  59. package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
  60. package/dist-cjs/lib/exports/getSvgJsx.js +12 -7
  61. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  62. package/dist-cjs/lib/globals/environment.js +18 -1
  63. package/dist-cjs/lib/globals/environment.js.map +2 -2
  64. package/dist-cjs/lib/hooks/{useIsDarkMode.js → useColorMode.js} +14 -10
  65. package/dist-cjs/lib/hooks/useColorMode.js.map +7 -0
  66. package/dist-cjs/lib/hooks/useCursor.js +3 -7
  67. package/dist-cjs/lib/hooks/useCursor.js.map +2 -2
  68. package/dist-cjs/lib/hooks/useDarkMode.js +4 -4
  69. package/dist-cjs/lib/hooks/useDarkMode.js.map +2 -2
  70. package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
  71. package/dist-cjs/lib/hooks/useGestureEvents.js +171 -127
  72. package/dist-cjs/lib/hooks/useGestureEvents.js.map +3 -3
  73. package/dist-cjs/lib/hooks/useLocalStore.js.map +2 -2
  74. package/dist-cjs/lib/options.js +3 -0
  75. package/dist-cjs/lib/options.js.map +2 -2
  76. package/dist-cjs/lib/primitives/Box.js +1 -1
  77. package/dist-cjs/lib/primitives/Box.js.map +2 -2
  78. package/dist-cjs/lib/primitives/geometry/Arc2d.js +2 -2
  79. package/dist-cjs/lib/primitives/geometry/Arc2d.js.map +2 -2
  80. package/dist-cjs/lib/primitives/geometry/Circle2d.js +2 -2
  81. package/dist-cjs/lib/primitives/geometry/Circle2d.js.map +2 -2
  82. package/dist-cjs/lib/primitives/geometry/Ellipse2d.js +2 -2
  83. package/dist-cjs/lib/primitives/geometry/Ellipse2d.js.map +2 -2
  84. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +4 -3
  85. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  86. package/dist-cjs/lib/primitives/geometry/Polyline2d.js +1 -1
  87. package/dist-cjs/lib/primitives/geometry/Polyline2d.js.map +2 -2
  88. package/dist-cjs/lib/primitives/geometry/Stadium2d.js +1 -1
  89. package/dist-cjs/lib/primitives/geometry/Stadium2d.js.map +2 -2
  90. package/dist-cjs/lib/utils/getSvgPathFromPoints.js.map +2 -2
  91. package/dist-cjs/lib/utils/reparenting.js +2 -1
  92. package/dist-cjs/lib/utils/reparenting.js.map +2 -2
  93. package/dist-cjs/lib/utils/richText.js.map +2 -2
  94. package/dist-cjs/lib/utils/runtime.js +2 -1
  95. package/dist-cjs/lib/utils/runtime.js.map +2 -2
  96. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +1 -1
  97. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
  98. package/dist-cjs/lib/utils/sync/hardReset.js +0 -8
  99. package/dist-cjs/lib/utils/sync/hardReset.js.map +2 -2
  100. package/dist-cjs/version.js +3 -3
  101. package/dist-cjs/version.js.map +1 -1
  102. package/dist-esm/index.d.mts +850 -118
  103. package/dist-esm/index.mjs +28 -10
  104. package/dist-esm/index.mjs.map +2 -2
  105. package/dist-esm/lib/TldrawEditor.mjs +62 -14
  106. package/dist-esm/lib/TldrawEditor.mjs.map +3 -3
  107. package/dist-esm/lib/components/MenuClickCapture.mjs +16 -1
  108. package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
  109. package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs +3 -3
  110. package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs.map +2 -2
  111. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +1 -1
  112. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  113. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +1 -1
  114. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +2 -2
  115. package/dist-esm/lib/config/{createTLUser.mjs → createTLCurrentUser.mjs} +6 -6
  116. package/dist-esm/lib/config/createTLCurrentUser.mjs.map +7 -0
  117. package/dist-esm/lib/config/createTLStore.mjs +37 -2
  118. package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
  119. package/dist-esm/lib/config/defaultAssets.mjs +16 -0
  120. package/dist-esm/lib/config/defaultAssets.mjs.map +7 -0
  121. package/dist-esm/lib/config/defaultShapes.mjs.map +2 -2
  122. package/dist-esm/lib/editor/Editor.mjs +332 -13
  123. package/dist-esm/lib/editor/Editor.mjs.map +3 -3
  124. package/dist-esm/lib/editor/assets/AssetUtil.mjs +46 -0
  125. package/dist-esm/lib/editor/assets/AssetUtil.mjs.map +7 -0
  126. package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs +1 -1
  127. package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +2 -2
  128. package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +2 -2
  129. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.mjs +60 -0
  130. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.mjs.map +7 -0
  131. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs +438 -0
  132. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs.map +7 -0
  133. package/dist-esm/lib/editor/managers/PerformanceManager/perf-types.mjs +1 -0
  134. package/dist-esm/lib/editor/managers/PerformanceManager/perf-types.mjs.map +7 -0
  135. package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs +1 -1
  136. package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +2 -2
  137. package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs.map +2 -2
  138. package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs +4 -4
  139. package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs.map +2 -2
  140. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +102 -30
  141. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
  142. package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs +88 -0
  143. package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs.map +7 -0
  144. package/dist-esm/lib/editor/managers/ThemeManager/defaultThemes.mjs +568 -0
  145. package/dist-esm/lib/editor/managers/ThemeManager/defaultThemes.mjs.map +7 -0
  146. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +6 -4
  147. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  148. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +21 -2
  149. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  150. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +1 -1
  151. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
  152. package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs +6 -0
  153. package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs.map +2 -2
  154. package/dist-esm/lib/editor/tools/StateNode.mjs +14 -17
  155. package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
  156. package/dist-esm/lib/editor/types/SvgExportContext.mjs.map +2 -2
  157. package/dist-esm/lib/exports/StyleEmbedder.mjs +1 -1
  158. package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
  159. package/dist-esm/lib/exports/getSvgJsx.mjs +12 -10
  160. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  161. package/dist-esm/lib/globals/environment.mjs +18 -1
  162. package/dist-esm/lib/globals/environment.mjs.map +2 -2
  163. package/dist-esm/lib/hooks/useColorMode.mjs +19 -0
  164. package/dist-esm/lib/hooks/useColorMode.mjs.map +7 -0
  165. package/dist-esm/lib/hooks/useCursor.mjs +3 -7
  166. package/dist-esm/lib/hooks/useCursor.mjs.map +2 -2
  167. package/dist-esm/lib/hooks/useDarkMode.mjs +4 -4
  168. package/dist-esm/lib/hooks/useDarkMode.mjs.map +2 -2
  169. package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
  170. package/dist-esm/lib/hooks/useGestureEvents.mjs +171 -127
  171. package/dist-esm/lib/hooks/useGestureEvents.mjs.map +3 -3
  172. package/dist-esm/lib/hooks/useLocalStore.mjs.map +2 -2
  173. package/dist-esm/lib/options.mjs +3 -0
  174. package/dist-esm/lib/options.mjs.map +2 -2
  175. package/dist-esm/lib/primitives/Box.mjs +1 -1
  176. package/dist-esm/lib/primitives/Box.mjs.map +2 -2
  177. package/dist-esm/lib/primitives/geometry/Arc2d.mjs +2 -2
  178. package/dist-esm/lib/primitives/geometry/Arc2d.mjs.map +2 -2
  179. package/dist-esm/lib/primitives/geometry/Circle2d.mjs +2 -2
  180. package/dist-esm/lib/primitives/geometry/Circle2d.mjs.map +2 -2
  181. package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs +2 -2
  182. package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs.map +2 -2
  183. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +4 -3
  184. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  185. package/dist-esm/lib/primitives/geometry/Polyline2d.mjs +1 -1
  186. package/dist-esm/lib/primitives/geometry/Polyline2d.mjs.map +2 -2
  187. package/dist-esm/lib/primitives/geometry/Stadium2d.mjs +1 -1
  188. package/dist-esm/lib/primitives/geometry/Stadium2d.mjs.map +2 -2
  189. package/dist-esm/lib/utils/getSvgPathFromPoints.mjs.map +2 -2
  190. package/dist-esm/lib/utils/reparenting.mjs +2 -1
  191. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  192. package/dist-esm/lib/utils/richText.mjs.map +2 -2
  193. package/dist-esm/lib/utils/runtime.mjs +2 -1
  194. package/dist-esm/lib/utils/runtime.mjs.map +2 -2
  195. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +1 -1
  196. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
  197. package/dist-esm/lib/utils/sync/hardReset.mjs +0 -8
  198. package/dist-esm/lib/utils/sync/hardReset.mjs.map +2 -2
  199. package/dist-esm/version.mjs +3 -3
  200. package/dist-esm/version.mjs.map +1 -1
  201. package/editor.css +13 -33
  202. package/package.json +8 -9
  203. package/src/index.ts +37 -8
  204. package/src/lib/TldrawEditor.tsx +99 -20
  205. package/src/lib/components/MenuClickCapture.tsx +20 -0
  206. package/src/lib/components/default-components/CanvasShapeIndicators.tsx +3 -3
  207. package/src/lib/components/default-components/DefaultCanvas.tsx +1 -1
  208. package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -1
  209. package/src/lib/config/TLEditorSnapshot.test.ts +1 -1
  210. package/src/lib/config/{createTLUser.ts → createTLCurrentUser.ts} +6 -6
  211. package/src/lib/config/createTLStore.ts +58 -3
  212. package/src/lib/config/defaultAssets.ts +19 -0
  213. package/src/lib/config/defaultShapes.ts +1 -1
  214. package/src/lib/editor/Editor.ts +448 -36
  215. package/src/lib/editor/assets/AssetUtil.ts +85 -0
  216. package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.ts +1 -1
  217. package/src/lib/editor/managers/FontManager/FontManager.test.ts +9 -2
  218. package/src/lib/editor/managers/FontManager/FontManager.ts +1 -67
  219. package/src/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.ts +82 -0
  220. package/src/lib/editor/managers/PerformanceManager/PerformanceManager.test.ts +522 -0
  221. package/src/lib/editor/managers/PerformanceManager/PerformanceManager.ts +583 -0
  222. package/src/lib/editor/managers/PerformanceManager/perf-types.ts +196 -0
  223. package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +1 -1
  224. package/src/lib/editor/managers/SnapManager/HandleSnaps.ts +1 -1
  225. package/src/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.ts +5 -5
  226. package/src/lib/editor/managers/TextManager/TextManager.test.ts +18 -4
  227. package/src/lib/editor/managers/TextManager/TextManager.ts +140 -34
  228. package/src/lib/editor/managers/ThemeManager/ThemeManager.ts +116 -0
  229. package/src/lib/editor/managers/ThemeManager/defaultThemes.ts +605 -0
  230. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +25 -31
  231. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +7 -5
  232. package/src/lib/editor/shapes/ShapeUtil.ts +41 -5
  233. package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +1 -1
  234. package/src/lib/editor/shapes/shared/getPerfectDashProps.ts +7 -0
  235. package/src/lib/editor/tools/StateNode.ts +16 -18
  236. package/src/lib/editor/types/SvgExportContext.tsx +5 -0
  237. package/src/lib/editor/types/clipboard-types.ts +2 -1
  238. package/src/lib/editor/types/external-content.ts +1 -0
  239. package/src/lib/exports/StyleEmbedder.ts +1 -1
  240. package/src/lib/exports/getSvgJsx.tsx +22 -16
  241. package/src/lib/globals/environment.ts +18 -0
  242. package/src/lib/hooks/{useIsDarkMode.ts → useColorMode.ts} +9 -5
  243. package/src/lib/hooks/useCursor.ts +3 -7
  244. package/src/lib/hooks/useDarkMode.ts +4 -4
  245. package/src/lib/hooks/useEditorComponents.tsx +1 -1
  246. package/src/lib/hooks/useGestureEvents.ts +240 -168
  247. package/src/lib/hooks/useLocalStore.ts +1 -1
  248. package/src/lib/options.ts +108 -0
  249. package/src/lib/primitives/Box.test.ts +30 -0
  250. package/src/lib/primitives/Box.ts +1 -1
  251. package/src/lib/primitives/geometry/Arc2d.ts +2 -2
  252. package/src/lib/primitives/geometry/Circle2d.ts +2 -2
  253. package/src/lib/primitives/geometry/Ellipse2d.ts +2 -2
  254. package/src/lib/primitives/geometry/Geometry2d.test.ts +21 -0
  255. package/src/lib/primitives/geometry/Geometry2d.ts +4 -3
  256. package/src/lib/primitives/geometry/Polyline2d.ts +1 -1
  257. package/src/lib/primitives/geometry/Stadium2d.ts +1 -1
  258. package/src/lib/utils/getSvgPathFromPoints.ts +1 -1
  259. package/src/lib/utils/reparenting.ts +6 -2
  260. package/src/lib/utils/richText.ts +1 -1
  261. package/src/lib/utils/runtime.ts +3 -1
  262. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +1 -1
  263. package/src/lib/utils/sync/TLLocalSyncClient.ts +1 -1
  264. package/src/lib/utils/sync/hardReset.ts +0 -8
  265. package/src/version.ts +3 -3
  266. package/dist-cjs/lib/config/createTLUser.js.map +0 -7
  267. package/dist-cjs/lib/hooks/useIsDarkMode.js.map +0 -7
  268. package/dist-esm/lib/config/createTLUser.mjs.map +0 -7
  269. package/dist-esm/lib/hooks/useIsDarkMode.mjs +0 -15
  270. package/dist-esm/lib/hooks/useIsDarkMode.mjs.map +0 -7
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/config/defaultAssets.ts"],
4
+ "sourcesContent": ["import { TLAssetUtilConstructor } from '../editor/assets/AssetUtil'\n\n/** @public */\nexport type TLAnyAssetUtilConstructor = TLAssetUtilConstructor<any>\n\nexport function checkAssets(customAssets: readonly TLAnyAssetUtilConstructor[]) {\n\tconst assets = [] as TLAnyAssetUtilConstructor[]\n\n\tconst addedCustomAssetTypes = new Set<string>()\n\tfor (const customAsset of customAssets) {\n\t\tif (addedCustomAssetTypes.has(customAsset.type)) {\n\t\t\tthrow new Error(`Asset type \"${customAsset.type}\" is defined more than once`)\n\t\t}\n\t\tassets.push(customAsset)\n\t\taddedCustomAssetTypes.add(customAsset.type)\n\t}\n\n\treturn assets\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,SAAS,YAAY,cAAoD;AAC/E,QAAM,SAAS,CAAC;AAEhB,QAAM,wBAAwB,oBAAI,IAAY;AAC9C,aAAW,eAAe,cAAc;AACvC,QAAI,sBAAsB,IAAI,YAAY,IAAI,GAAG;AAChD,YAAM,IAAI,MAAM,eAAe,YAAY,IAAI,6BAA6B;AAAA,IAC7E;AACA,WAAO,KAAK,WAAW;AACvB,0BAAsB,IAAI,YAAY,IAAI;AAAA,EAC3C;AAEA,SAAO;AACR;",
6
+ "names": []
7
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/config/defaultShapes.ts"],
4
- "sourcesContent": ["import { TLShapeUtilConstructor } from '../editor/shapes/ShapeUtil'\nimport { GroupShapeUtil } from '../editor/shapes/group/GroupShapeUtil'\n\n/** @public */\nexport type TLAnyShapeUtilConstructor = TLShapeUtilConstructor<any>\n\n/** @public */\nexport const coreShapes = [\n\t// created by grouping interactions, probably the corest core shape that we have\n\tGroupShapeUtil,\n] as const\n\nconst coreShapeTypes = new Set<string>(coreShapes.map((s) => s.type))\n\nexport function checkShapesAndAddCore(customShapes: readonly TLAnyShapeUtilConstructor[]) {\n\tconst shapes = [...coreShapes] as TLAnyShapeUtilConstructor[]\n\n\tconst addedCustomShapeTypes = new Set<string>()\n\tfor (const customShape of customShapes) {\n\t\tif (coreShapeTypes.has(customShape.type)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Shape type \"${customShape.type}\" is a core shapes type and cannot be overridden`\n\t\t\t)\n\t\t}\n\t\tif (addedCustomShapeTypes.has(customShape.type)) {\n\t\t\tthrow new Error(`Shape type \"${customShape.type}\" is defined more than once`)\n\t\t}\n\t\tshapes.push(customShape)\n\t\taddedCustomShapeTypes.add(customShape.type)\n\t}\n\n\treturn shapes\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,4BAA+B;AAMxB,MAAM,aAAa;AAAA;AAAA,EAEzB;AACD;AAEA,MAAM,iBAAiB,IAAI,IAAY,WAAW,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC;AAE7D,SAAS,sBAAsB,cAAoD;AACzF,QAAM,SAAS,CAAC,GAAG,UAAU;AAE7B,QAAM,wBAAwB,oBAAI,IAAY;AAC9C,aAAW,eAAe,cAAc;AACvC,QAAI,eAAe,IAAI,YAAY,IAAI,GAAG;AACzC,YAAM,IAAI;AAAA,QACT,eAAe,YAAY,IAAI;AAAA,MAChC;AAAA,IACD;AACA,QAAI,sBAAsB,IAAI,YAAY,IAAI,GAAG;AAChD,YAAM,IAAI,MAAM,eAAe,YAAY,IAAI,6BAA6B;AAAA,IAC7E;AACA,WAAO,KAAK,WAAW;AACvB,0BAAsB,IAAI,YAAY,IAAI;AAAA,EAC3C;AAEA,SAAO;AACR;",
4
+ "sourcesContent": ["import { GroupShapeUtil } from '../editor/shapes/group/GroupShapeUtil'\nimport { TLShapeUtilConstructor } from '../editor/shapes/ShapeUtil'\n\n/** @public */\nexport type TLAnyShapeUtilConstructor = TLShapeUtilConstructor<any>\n\n/** @public */\nexport const coreShapes = [\n\t// created by grouping interactions, probably the corest core shape that we have\n\tGroupShapeUtil,\n] as const\n\nconst coreShapeTypes = new Set<string>(coreShapes.map((s) => s.type))\n\nexport function checkShapesAndAddCore(customShapes: readonly TLAnyShapeUtilConstructor[]) {\n\tconst shapes = [...coreShapes] as TLAnyShapeUtilConstructor[]\n\n\tconst addedCustomShapeTypes = new Set<string>()\n\tfor (const customShape of customShapes) {\n\t\tif (coreShapeTypes.has(customShape.type)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Shape type \"${customShape.type}\" is a core shapes type and cannot be overridden`\n\t\t\t)\n\t\t}\n\t\tif (addedCustomShapeTypes.has(customShape.type)) {\n\t\t\tthrow new Error(`Shape type \"${customShape.type}\" is defined more than once`)\n\t\t}\n\t\tshapes.push(customShape)\n\t\taddedCustomShapeTypes.add(customShape.type)\n\t}\n\n\treturn shapes\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA+B;AAOxB,MAAM,aAAa;AAAA;AAAA,EAEzB;AACD;AAEA,MAAM,iBAAiB,IAAI,IAAY,WAAW,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC;AAE7D,SAAS,sBAAsB,cAAoD;AACzF,QAAM,SAAS,CAAC,GAAG,UAAU;AAE7B,QAAM,wBAAwB,oBAAI,IAAY;AAC9C,aAAW,eAAe,cAAc;AACvC,QAAI,eAAe,IAAI,YAAY,IAAI,GAAG;AACzC,YAAM,IAAI;AAAA,QACT,eAAe,YAAY,IAAI;AAAA,MAChC;AAAA,IACD;AACA,QAAI,sBAAsB,IAAI,YAAY,IAAI,GAAG;AAChD,YAAM,IAAI,MAAM,eAAe,YAAY,IAAI,6BAA6B;AAAA,IAC7E;AACA,WAAO,KAAK,WAAW;AACvB,0BAAsB,IAAI,YAAY,IAAI;AAAA,EAC3C;AAEA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -44,10 +44,11 @@ var import_store = require("@tldraw/store");
44
44
  var import_tlschema = require("@tldraw/tlschema");
45
45
  var import_utils = require("@tldraw/utils");
46
46
  var import_eventemitter3 = __toESM(require("eventemitter3"), 1);
47
- var import_TLEditorSnapshot = require("../config/TLEditorSnapshot");
48
- var import_createTLUser = require("../config/createTLUser");
47
+ var import_createTLCurrentUser = require("../config/createTLCurrentUser");
48
+ var import_defaultAssets = require("../config/defaultAssets");
49
49
  var import_defaultBindings = require("../config/defaultBindings");
50
50
  var import_defaultShapes = require("../config/defaultShapes");
51
+ var import_TLEditorSnapshot = require("../config/TLEditorSnapshot");
51
52
  var import_constants = require("../constants");
52
53
  var import_domUtils = require("../exports/domUtils");
53
54
  var import_exportToSvg = require("../exports/exportToSvg");
@@ -56,13 +57,12 @@ var import_menus = require("../globals/menus");
56
57
  var import_time = require("../globals/time");
57
58
  var import_options = require("../options");
58
59
  var import_Box = require("../primitives/Box");
59
- var import_Mat = require("../primitives/Mat");
60
- var import_Vec = require("../primitives/Vec");
61
60
  var import_easings = require("../primitives/easings");
62
61
  var import_Group2d = require("../primitives/geometry/Group2d");
63
62
  var import_intersect = require("../primitives/intersect");
63
+ var import_Mat = require("../primitives/Mat");
64
64
  var import_utils2 = require("../primitives/utils");
65
- var import_SharedStylesMap = require("../utils/SharedStylesMap");
65
+ var import_Vec = require("../primitives/Vec");
66
66
  var import_areShapesContentEqual = require("../utils/areShapesContentEqual");
67
67
  var import_assets = require("../utils/assets");
68
68
  var import_debug_flags = require("../utils/debug-flags");
@@ -71,6 +71,7 @@ var import_getIncrementedName = require("../utils/getIncrementedName");
71
71
  var import_reorderShapes = require("../utils/reorderShapes");
72
72
  var import_reparenting = require("../utils/reparenting");
73
73
  var import_rotation = require("../utils/rotation");
74
+ var import_SharedStylesMap = require("../utils/SharedStylesMap");
74
75
  var import_bindingsIndex = require("./derivations/bindingsIndex");
75
76
  var import_notVisibleShapes = require("./derivations/notVisibleShapes");
76
77
  var import_parentsToChildren = require("./derivations/parentsToChildren");
@@ -81,10 +82,12 @@ var import_FocusManager = require("./managers/FocusManager/FocusManager");
81
82
  var import_FontManager = require("./managers/FontManager/FontManager");
82
83
  var import_HistoryManager = require("./managers/HistoryManager/HistoryManager");
83
84
  var import_InputsManager = require("./managers/InputsManager/InputsManager");
85
+ var import_PerformanceManager = require("./managers/PerformanceManager/PerformanceManager");
84
86
  var import_ScribbleManager = require("./managers/ScribbleManager/ScribbleManager");
85
87
  var import_SnapManager = require("./managers/SnapManager/SnapManager");
86
88
  var import_SpatialIndexManager = require("./managers/SpatialIndexManager/SpatialIndexManager");
87
89
  var import_TextManager = require("./managers/TextManager/TextManager");
90
+ var import_ThemeManager = require("./managers/ThemeManager/ThemeManager");
88
91
  var import_TickManager = require("./managers/TickManager/TickManager");
89
92
  var import_UserPreferencesManager = require("./managers/UserPreferencesManager/UserPreferencesManager");
90
93
  var import_RootState = require("./tools/RootState");
@@ -95,6 +98,7 @@ class Editor extends import_eventemitter3.default {
95
98
  user,
96
99
  shapeUtils,
97
100
  bindingUtils,
101
+ assetUtils: assetUtilConstructors,
98
102
  tools,
99
103
  getContainer,
100
104
  // needs to be here for backwards compatibility with TldrawEditor
@@ -102,13 +106,15 @@ class Editor extends import_eventemitter3.default {
102
106
  cameraOptions,
103
107
  initialState,
104
108
  autoFocus,
105
- inferDarkMode,
106
109
  options: _options,
107
110
  // needs to be here for backwards compatibility with TldrawEditor
108
111
  // eslint-disable-next-line @typescript-eslint/no-deprecated
109
112
  textOptions: _textOptions,
110
113
  getShapeVisibility,
111
- fontAssetUrls
114
+ colorScheme,
115
+ fontAssetUrls,
116
+ themes,
117
+ initialTheme
112
118
  }) {
113
119
  super();
114
120
  this._getShapeVisibility = getShapeVisibility;
@@ -131,15 +137,27 @@ class Editor extends import_eventemitter3.default {
131
137
  ...cameraOptions,
132
138
  ...options?.camera
133
139
  });
140
+ this.getContainer = getContainer;
134
141
  this._textOptions = (0, import_state.atom)("text options", options?.text ?? null);
135
- this.user = new import_UserPreferencesManager.UserPreferencesManager(user ?? (0, import_createTLUser.createTLUser)(), inferDarkMode ?? false);
142
+ this.user = new import_UserPreferencesManager.UserPreferencesManager(user ?? (0, import_createTLCurrentUser.createTLCurrentUser)(), colorScheme ?? "light");
136
143
  this.disposables.add(() => this.user.dispose());
137
- this.getContainer = getContainer;
138
144
  this.textMeasure = new import_TextManager.TextManager(this);
139
145
  this.disposables.add(() => this.textMeasure.dispose());
140
- this.fonts = new import_FontManager.FontManager(this, fontAssetUrls);
146
+ this._themeManager = new import_ThemeManager.ThemeManager(this, {
147
+ themes: (0, import_ThemeManager.resolveThemes)(themes),
148
+ initial: initialTheme ?? "default"
149
+ });
150
+ this.disposables.add(() => this._themeManager.dispose());
141
151
  this._tickManager = new import_TickManager.TickManager(this);
152
+ this.disposables.add(() => this._tickManager.dispose());
153
+ this.disposables.add(() => {
154
+ this.off("tick", this._decayCameraStateTimeout);
155
+ this._setCameraState("idle");
156
+ });
157
+ this.fonts = new import_FontManager.FontManager(this, fontAssetUrls);
142
158
  this.inputs = new import_InputsManager.InputsManager(this);
159
+ this.performance = new import_PerformanceManager.PerformanceManager(this);
160
+ this.disposables.add(() => this.performance.dispose());
143
161
  class NewRoot extends import_RootState.RootState {
144
162
  static initial = initialState ?? "";
145
163
  }
@@ -167,6 +185,16 @@ class Editor extends import_eventemitter3.default {
167
185
  }
168
186
  this.shapeUtils = _shapeUtils;
169
187
  this.styleProps = _styleProps;
188
+ const _shapeUtilsByAssetType = {};
189
+ for (const Util of allShapeUtils) {
190
+ const assetTypes = Util.handledAssetTypes;
191
+ if (assetTypes) {
192
+ for (const assetType of assetTypes) {
193
+ _shapeUtilsByAssetType[assetType] = _shapeUtils[Util.type];
194
+ }
195
+ }
196
+ }
197
+ this._shapeUtilsByAssetType = _shapeUtilsByAssetType;
170
198
  const allBindingUtils = (0, import_defaultBindings.checkBindings)(bindingUtils);
171
199
  const _bindingUtils = {};
172
200
  for (const Util of allBindingUtils) {
@@ -174,6 +202,15 @@ class Editor extends import_eventemitter3.default {
174
202
  _bindingUtils[Util.type] = util;
175
203
  }
176
204
  this.bindingUtils = _bindingUtils;
205
+ if (assetUtilConstructors) {
206
+ const allAssetUtils = (0, import_defaultAssets.checkAssets)(assetUtilConstructors);
207
+ const _assetUtils = {};
208
+ for (const Util of allAssetUtils) {
209
+ const util = new Util(this);
210
+ _assetUtils[Util.type] = util;
211
+ }
212
+ this.assetUtils = _assetUtils;
213
+ }
177
214
  for (const Tool of [...tools]) {
178
215
  if ((0, import_utils.hasOwnProperty)(this.root.children, Tool.id)) {
179
216
  throw Error(`Can't override tool with id "${Tool.id}"`);
@@ -515,6 +552,14 @@ class Editor extends import_eventemitter3.default {
515
552
  })
516
553
  );
517
554
  }
555
+ this.disposables.add(
556
+ (0, import_state.react)("sync current user record", () => {
557
+ const user2 = this.store.props.users.currentUser.get();
558
+ if (user2) {
559
+ this._ensureUserRecord(user2);
560
+ }
561
+ })
562
+ );
518
563
  }
519
564
  _getShapeVisibility;
520
565
  getIsShapeHiddenCache() {
@@ -606,6 +651,17 @@ class Editor extends import_eventemitter3.default {
606
651
  * @public
607
652
  */
608
653
  snaps;
654
+ /**
655
+ * A manager for performance measurement hooks.
656
+ *
657
+ * @public
658
+ */
659
+ performance;
660
+ /**
661
+ * A manager for the spatial index, tracking where shapes exist on the canvas.
662
+ *
663
+ * @internal
664
+ */
609
665
  _spatialIndex;
610
666
  /**
611
667
  * A manager for the any asynchronous events and making sure they're
@@ -620,6 +676,12 @@ class Editor extends import_eventemitter3.default {
620
676
  * @public
621
677
  */
622
678
  user;
679
+ /**
680
+ * A manager for the editor's themes.
681
+ *
682
+ * @internal
683
+ */
684
+ _themeManager;
623
685
  /**
624
686
  * A helper for measuring text.
625
687
  *
@@ -691,12 +753,117 @@ class Editor extends import_eventemitter3.default {
691
753
  * @public
692
754
  */
693
755
  dispose() {
756
+ this.stopCameraAnimation();
757
+ if (this.getInstanceState().followingUserId) {
758
+ this.stopFollowingUser();
759
+ }
694
760
  this.disposables.forEach((dispose) => dispose());
695
761
  this.disposables.clear();
762
+ this.menus.clearOpenMenus();
696
763
  this.store.dispose();
697
764
  this.isDisposed = true;
698
765
  this.emit("dispose");
699
766
  }
767
+ /* ------------------ Themes (shadowing the theme manager) ------------------ */
768
+ /**
769
+ * Get the current color mode (`'light'` or `'dark'`), based on the user's dark mode preference.
770
+ *
771
+ * @public
772
+ */
773
+ getColorMode() {
774
+ return this._themeManager.getColorMode();
775
+ }
776
+ /**
777
+ * Set the color mode. Note that this is a convenience method that passes the mode to
778
+ * `user.updateUserPreferences`, which is the source of truth for the user's color mode preference.
779
+ *
780
+ * @public
781
+ */
782
+ setColorMode(mode) {
783
+ this.user.updateUserPreferences({ colorScheme: mode });
784
+ return this;
785
+ }
786
+ /**
787
+ * Get the id of the current theme.
788
+ *
789
+ * @public
790
+ */
791
+ getCurrentThemeId() {
792
+ return this._themeManager.getCurrentThemeId();
793
+ }
794
+ /**
795
+ * Get the current theme definition.
796
+ *
797
+ * @public
798
+ */
799
+ getCurrentTheme() {
800
+ return this._themeManager.getCurrentTheme();
801
+ }
802
+ /**
803
+ * Set the current theme by id.
804
+ *
805
+ * @public
806
+ */
807
+ setCurrentTheme(id) {
808
+ this._themeManager.setCurrentTheme(id);
809
+ return this;
810
+ }
811
+ /**
812
+ * Get all registered theme definitions.
813
+ *
814
+ * @public
815
+ */
816
+ getThemes() {
817
+ return this._themeManager.getThemes();
818
+ }
819
+ /**
820
+ * Get a single theme definition by id.
821
+ *
822
+ * @public
823
+ */
824
+ getTheme(id) {
825
+ return this._themeManager.getTheme(id);
826
+ }
827
+ /**
828
+ * Replace all theme definitions, or update them via a callback that receives a deep copy.
829
+ * The `'default'` theme must always be present in the result.
830
+ *
831
+ * @example
832
+ * ```ts
833
+ * // Replace all themes
834
+ * editor.updateThemes({ default: myDefaultTheme, ocean: myOceanTheme })
835
+ *
836
+ * // Update via callback
837
+ * editor.updateThemes((themes) => {
838
+ * delete themes.ocean
839
+ * return themes
840
+ * })
841
+ * ```
842
+ *
843
+ * @public
844
+ */
845
+ updateThemes(themes) {
846
+ this._themeManager.updateThemes(themes);
847
+ return this;
848
+ }
849
+ /**
850
+ * Register or update a single theme definition. The theme is keyed by its `id` property.
851
+ *
852
+ * @example
853
+ * ```ts
854
+ * // Override a property on the default theme
855
+ * editor.updateTheme({ ...editor.getTheme('default')!, fontSize: 24 })
856
+ *
857
+ * // Register a new theme
858
+ * editor.updateTheme({ id: 'ocean', ...myOceanTheme })
859
+ * ```
860
+ *
861
+ * @public
862
+ */
863
+ updateTheme(theme) {
864
+ this._themeManager.updateTheme(theme);
865
+ return this;
866
+ }
700
867
  /* ------------------- Shape Utils ------------------ */
701
868
  /**
702
869
  * A map of shape utility classes (TLShapeUtils) by shape type.
@@ -704,6 +871,8 @@ class Editor extends import_eventemitter3.default {
704
871
  * @public
705
872
  */
706
873
  shapeUtils;
874
+ /** @internal */
875
+ _shapeUtilsByAssetType = {};
707
876
  styleProps;
708
877
  getShapeUtil(arg) {
709
878
  const type = typeof arg === "string" ? arg : arg.type;
@@ -715,6 +884,17 @@ class Editor extends import_eventemitter3.default {
715
884
  const type = typeof arg === "string" ? arg : arg.type;
716
885
  return (0, import_utils.hasOwnProperty)(this.shapeUtils, type);
717
886
  }
887
+ /**
888
+ * Get the shape util that handles the given asset type.
889
+ * Returns the shape util whose {@link ShapeUtil.handledAssetTypes} includes
890
+ * the given asset type, or undefined if none matches.
891
+ *
892
+ * @param assetType - The asset type string.
893
+ * @public
894
+ */
895
+ getShapeUtilForAssetType(assetType) {
896
+ return (0, import_utils.getOwnProperty)(this._shapeUtilsByAssetType, assetType);
897
+ }
718
898
  /* ------------------- Binding Utils ------------------ */
719
899
  /**
720
900
  * A map of shape utility classes (TLShapeUtils) by shape type.
@@ -728,6 +908,42 @@ class Editor extends import_eventemitter3.default {
728
908
  (0, import_utils.assert)(bindingUtil, `No binding util found for type "${type}"`);
729
909
  return bindingUtil;
730
910
  }
911
+ /* ------------------- Asset Utils ------------------ */
912
+ /**
913
+ * A map of asset utility classes by asset type.
914
+ *
915
+ * @public
916
+ */
917
+ assetUtils = {};
918
+ getAssetUtil(arg) {
919
+ const type = typeof arg === "string" ? arg : arg.type;
920
+ const assetUtil = (0, import_utils.getOwnProperty)(this.assetUtils, type);
921
+ (0, import_utils.assert)(assetUtil, `No asset util found for type "${type}"`);
922
+ return assetUtil;
923
+ }
924
+ /**
925
+ * Returns true if the editor has an asset util for the given asset type.
926
+ *
927
+ * @public
928
+ */
929
+ hasAssetUtil(arg) {
930
+ const type = typeof arg === "string" ? arg : arg.type;
931
+ return (0, import_utils.hasOwnProperty)(this.assetUtils, type);
932
+ }
933
+ /**
934
+ * Get the asset util that accepts the given MIME type.
935
+ * Returns null if no registered asset util accepts the MIME type.
936
+ *
937
+ * @public
938
+ */
939
+ getAssetUtilForMimeType(mimeType) {
940
+ for (const util of Object.values(this.assetUtils)) {
941
+ if (util && util.acceptsMimeType(mimeType)) {
942
+ return util;
943
+ }
944
+ }
945
+ return null;
946
+ }
731
947
  /* --------------------- History -------------------- */
732
948
  /**
733
949
  * A manager for the editor's history.
@@ -749,6 +965,7 @@ class Editor extends import_eventemitter3.default {
749
965
  this._flushEventsForTick(0);
750
966
  this.complete();
751
967
  this.history.undo();
968
+ this.performance._notifyUndoRedo("undo", this.history.getNumUndos(), this.history.getNumRedos());
752
969
  return this;
753
970
  }
754
971
  canUndo() {
@@ -771,6 +988,7 @@ class Editor extends import_eventemitter3.default {
771
988
  this._flushEventsForTick(0);
772
989
  this.complete();
773
990
  this.history.redo();
991
+ this.performance._notifyUndoRedo("redo", this.history.getNumUndos(), this.history.getNumRedos());
774
992
  return this;
775
993
  }
776
994
  canRedo() {
@@ -2821,6 +3039,76 @@ class Editor extends import_eventemitter3.default {
2821
3039
  const currentPageId = this.getCurrentPageId();
2822
3040
  return this.getCollaborators().filter((c) => c.currentPageId === currentPageId);
2823
3041
  }
3042
+ // Attribution
3043
+ /**
3044
+ * Get the current user's ID for attribution purposes.
3045
+ * Also ensures a `user:` record exists in the store for the current user.
3046
+ * Returns `null` when the user store has no current user.
3047
+ *
3048
+ * @public
3049
+ */
3050
+ getAttributionUserId() {
3051
+ const user = this.store.props.users.currentUser.get();
3052
+ if (!user) return null;
3053
+ this._ensureUserRecord(user);
3054
+ return import_tlschema.UserRecordType.parseId(user.id);
3055
+ }
3056
+ /**
3057
+ * Ensure a user record exists in the store for the given user,
3058
+ * updating it if the data has changed.
3059
+ *
3060
+ * @internal
3061
+ */
3062
+ _ensureUserRecord(user) {
3063
+ const existing = this.store.get(user.id);
3064
+ if (existing && existing.name === user.name && existing.color === user.color && existing.imageUrl === user.imageUrl && existing.meta === user.meta) {
3065
+ return;
3066
+ }
3067
+ this.run(
3068
+ () => {
3069
+ this.store.put([user]);
3070
+ },
3071
+ { history: "ignore" }
3072
+ );
3073
+ }
3074
+ /**
3075
+ * Resolve a display name for a user ID. Asks the
3076
+ * {@link @tldraw/tlschema#TLUserStore} first (the app's source of truth),
3077
+ * falling back to the `user:` record in the store.
3078
+ *
3079
+ * @public
3080
+ */
3081
+ getAttributionDisplayName(userId) {
3082
+ if (!userId) return null;
3083
+ return this.store.props.users.resolve(userId).get()?.name ?? this.store.get((0, import_tlschema.createUserId)(userId))?.name ?? null;
3084
+ }
3085
+ /**
3086
+ * Resolve a user record by ID. Asks the
3087
+ * {@link @tldraw/tlschema#TLUserStore} first (the app's source of truth),
3088
+ * falling back to the `user:` record in the store.
3089
+ *
3090
+ * @public
3091
+ */
3092
+ getAttributionUser(userId) {
3093
+ if (!userId) return null;
3094
+ return this.store.props.users.resolve(userId).get() ?? this.store.get((0, import_tlschema.createUserId)(userId)) ?? null;
3095
+ }
3096
+ /**
3097
+ * Collect user IDs referenced by a set of shapes via shape-specific props
3098
+ * (e.g. `textFirstEditedBy` on notes).
3099
+ *
3100
+ * @internal
3101
+ */
3102
+ _getReferencedUserIds(shapes) {
3103
+ const userIds = /* @__PURE__ */ new Set();
3104
+ for (const shape of shapes) {
3105
+ const util = this.getShapeUtil(shape);
3106
+ for (const id of util.getReferencedUserIds(shape)) {
3107
+ userIds.add(id);
3108
+ }
3109
+ }
3110
+ return userIds;
3111
+ }
2824
3112
  // Following
2825
3113
  // When we are 'locked on' to a user, our camera is derived from their camera.
2826
3114
  _isLockedOnFollowingUser = (0, import_state.atom)("isLockedOnFollowingUser", false);
@@ -6534,12 +6822,22 @@ class Editor extends import_eventemitter3.default {
6534
6822
  if (!asset) continue;
6535
6823
  assets.push(asset);
6536
6824
  }
6825
+ const users = [];
6826
+ const seenUserIds = /* @__PURE__ */ new Set();
6827
+ for (const userId of this._getReferencedUserIds(shapes2)) {
6828
+ const recordId = (0, import_tlschema.createUserId)(userId);
6829
+ if (seenUserIds.has(recordId)) continue;
6830
+ seenUserIds.add(recordId);
6831
+ const user = this.store.get(recordId);
6832
+ if (user) users.push(user);
6833
+ }
6537
6834
  return {
6538
6835
  schema: this.store.schema.serialize(),
6539
6836
  shapes: shapes2,
6540
6837
  rootShapeIds,
6541
6838
  bindings,
6542
- assets
6839
+ assets,
6840
+ users
6543
6841
  };
6544
6842
  });
6545
6843
  }
@@ -6589,13 +6887,15 @@ class Editor extends import_eventemitter3.default {
6589
6887
  const assets = [];
6590
6888
  const shapes = [];
6591
6889
  const bindings = [];
6890
+ const users = [];
6592
6891
  const store = {
6593
6892
  store: {
6594
6893
  ...Object.fromEntries(content.assets.map((asset) => [asset.id, asset])),
6595
6894
  ...Object.fromEntries(content.shapes.map((shape) => [shape.id, shape])),
6596
6895
  ...Object.fromEntries(
6597
6896
  content.bindings?.map((bindings2) => [bindings2.id, bindings2]) ?? []
6598
- )
6897
+ ),
6898
+ ...Object.fromEntries(content.users?.map((user) => [user.id, user]) ?? [])
6599
6899
  },
6600
6900
  schema: content.schema
6601
6901
  };
@@ -6617,6 +6917,19 @@ class Editor extends import_eventemitter3.default {
6617
6917
  bindings.push(record);
6618
6918
  break;
6619
6919
  }
6920
+ case "user": {
6921
+ users.push(record);
6922
+ break;
6923
+ }
6924
+ }
6925
+ }
6926
+ if (users.length > 0) {
6927
+ const existingUserIds = new Set(
6928
+ this.store.allRecords().filter((r) => r.typeName === "user").map((r) => r.id)
6929
+ );
6930
+ const usersToCreate = users.filter((u) => !existingUserIds.has(u.id));
6931
+ if (usersToCreate.length > 0) {
6932
+ this.store.put(usersToCreate);
6620
6933
  }
6621
6934
  }
6622
6935
  const shapeIdMap = new Map(
@@ -7582,6 +7895,7 @@ class Editor extends import_eventemitter3.default {
7582
7895
  ),
7583
7896
  { immediate: true }
7584
7897
  );
7898
+ this.performance._notifyCameraOperation("zooming");
7585
7899
  this.emit("event", info);
7586
7900
  return;
7587
7901
  }
@@ -7643,6 +7957,7 @@ class Editor extends import_eventemitter3.default {
7643
7957
  immediate: true
7644
7958
  });
7645
7959
  this.maybeTrackPerformance("Zooming");
7960
+ this.performance._notifyCameraOperation("zooming");
7646
7961
  this.root.handleEvent(info);
7647
7962
  this.emit("event", info);
7648
7963
  return;
@@ -7652,6 +7967,7 @@ class Editor extends import_eventemitter3.default {
7652
7967
  immediate: true
7653
7968
  });
7654
7969
  this.maybeTrackPerformance("Panning");
7970
+ this.performance._notifyCameraOperation("panning");
7655
7971
  this.root.handleEvent(info);
7656
7972
  this.emit("event", info);
7657
7973
  return;
@@ -7717,6 +8033,7 @@ class Editor extends import_eventemitter3.default {
7717
8033
  immediate: true
7718
8034
  });
7719
8035
  this.maybeTrackPerformance("Panning");
8036
+ this.performance._notifyCameraOperation("panning");
7720
8037
  return;
7721
8038
  }
7722
8039
  if (inputs.getIsPointing() && !inputs.getIsDragging() && import_Vec.Vec.Dist2(inputs.getOriginPagePoint(), inputs.getCurrentPagePoint()) * this.getZoomLevel() > (instanceState.isCoarsePointer ? this.options.coarseDragDistanceSquared : this.options.dragDistanceSquared) / cz) {