@tldraw/editor 4.6.0-canary.d388dc133c68 → 4.6.0-canary.d56815af4e9e

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 (96) hide show
  1. package/dist-cjs/index.d.ts +430 -4
  2. package/dist-cjs/index.js +7 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +7 -0
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  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/config/createTLStore.js +2 -0
  9. package/dist-cjs/lib/config/createTLStore.js.map +2 -2
  10. package/dist-cjs/lib/config/defaultAssets.js +36 -0
  11. package/dist-cjs/lib/config/defaultAssets.js.map +7 -0
  12. package/dist-cjs/lib/editor/Editor.js +85 -0
  13. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  14. package/dist-cjs/lib/editor/assets/AssetUtil.js +66 -0
  15. package/dist-cjs/lib/editor/assets/AssetUtil.js.map +7 -0
  16. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.js +80 -0
  17. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.js.map +7 -0
  18. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js +466 -0
  19. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js.map +7 -0
  20. package/dist-cjs/lib/editor/managers/PerformanceManager/perf-types.js +17 -0
  21. package/dist-cjs/lib/editor/managers/PerformanceManager/perf-types.js.map +7 -0
  22. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +11 -2
  23. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  24. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +1 -1
  25. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
  26. package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js +6 -0
  27. package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js.map +2 -2
  28. package/dist-cjs/lib/editor/tools/StateNode.js +14 -17
  29. package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
  30. package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
  31. package/dist-cjs/lib/utils/reparenting.js +2 -1
  32. package/dist-cjs/lib/utils/reparenting.js.map +2 -2
  33. package/dist-cjs/lib/utils/runtime.js +2 -1
  34. package/dist-cjs/lib/utils/runtime.js.map +2 -2
  35. package/dist-cjs/lib/utils/sync/hardReset.js +0 -8
  36. package/dist-cjs/lib/utils/sync/hardReset.js.map +2 -2
  37. package/dist-cjs/version.js +3 -3
  38. package/dist-cjs/version.js.map +1 -1
  39. package/dist-esm/index.d.mts +430 -4
  40. package/dist-esm/index.mjs +7 -1
  41. package/dist-esm/index.mjs.map +2 -2
  42. package/dist-esm/lib/TldrawEditor.mjs +7 -0
  43. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  44. package/dist-esm/lib/components/MenuClickCapture.mjs +16 -1
  45. package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
  46. package/dist-esm/lib/config/createTLStore.mjs +2 -0
  47. package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
  48. package/dist-esm/lib/config/defaultAssets.mjs +16 -0
  49. package/dist-esm/lib/config/defaultAssets.mjs.map +7 -0
  50. package/dist-esm/lib/editor/Editor.mjs +85 -0
  51. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  52. package/dist-esm/lib/editor/assets/AssetUtil.mjs +46 -0
  53. package/dist-esm/lib/editor/assets/AssetUtil.mjs.map +7 -0
  54. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.mjs +60 -0
  55. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.mjs.map +7 -0
  56. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs +438 -0
  57. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs.map +7 -0
  58. package/dist-esm/lib/editor/managers/PerformanceManager/perf-types.mjs +1 -0
  59. package/dist-esm/lib/editor/managers/PerformanceManager/perf-types.mjs.map +7 -0
  60. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +11 -2
  61. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  62. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +1 -1
  63. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
  64. package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs +6 -0
  65. package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs.map +2 -2
  66. package/dist-esm/lib/editor/tools/StateNode.mjs +14 -17
  67. package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
  68. package/dist-esm/lib/utils/reparenting.mjs +2 -1
  69. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  70. package/dist-esm/lib/utils/runtime.mjs +2 -1
  71. package/dist-esm/lib/utils/runtime.mjs.map +2 -2
  72. package/dist-esm/lib/utils/sync/hardReset.mjs +0 -8
  73. package/dist-esm/lib/utils/sync/hardReset.mjs.map +2 -2
  74. package/dist-esm/version.mjs +3 -3
  75. package/dist-esm/version.mjs.map +1 -1
  76. package/package.json +7 -7
  77. package/src/index.ts +17 -0
  78. package/src/lib/TldrawEditor.tsx +16 -3
  79. package/src/lib/components/MenuClickCapture.tsx +20 -0
  80. package/src/lib/config/createTLStore.ts +7 -1
  81. package/src/lib/config/defaultAssets.ts +19 -0
  82. package/src/lib/editor/Editor.ts +110 -0
  83. package/src/lib/editor/assets/AssetUtil.ts +85 -0
  84. package/src/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.ts +82 -0
  85. package/src/lib/editor/managers/PerformanceManager/PerformanceManager.test.ts +522 -0
  86. package/src/lib/editor/managers/PerformanceManager/PerformanceManager.ts +583 -0
  87. package/src/lib/editor/managers/PerformanceManager/perf-types.ts +196 -0
  88. package/src/lib/editor/shapes/ShapeUtil.ts +27 -2
  89. package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +1 -1
  90. package/src/lib/editor/shapes/shared/getPerfectDashProps.ts +7 -0
  91. package/src/lib/editor/tools/StateNode.ts +16 -18
  92. package/src/lib/editor/types/external-content.ts +1 -0
  93. package/src/lib/utils/reparenting.ts +6 -2
  94. package/src/lib/utils/runtime.ts +3 -1
  95. package/src/lib/utils/sync/hardReset.ts +0 -8
  96. package/src/version.ts +3 -3
@@ -88,6 +88,7 @@ import { TLTheme } from '@tldraw/tlschema';
88
88
  import { TLThemeColors } from '@tldraw/tlschema';
89
89
  import { TLThemeId } from '@tldraw/tlschema';
90
90
  import { TLThemes } from '@tldraw/tlschema';
91
+ import { TLUnknownAsset } from '@tldraw/tlschema';
91
92
  import { TLUnknownBinding } from '@tldraw/tlschema';
92
93
  import { TLUnknownShape } from '@tldraw/tlschema';
93
94
  import { TLUser } from '@tldraw/tlschema';
@@ -154,6 +155,51 @@ export declare class Arc2d extends Geometry2d {
154
155
  */
155
156
  export declare function areAnglesCompatible(a: number, b: number): boolean;
156
157
 
158
+ /**
159
+ * Abstract base class for defining asset-type-specific behavior.
160
+ *
161
+ * Each asset type (image, video, bookmark, etc.) has a corresponding AssetUtil that handles
162
+ * type-specific operations like determining supported MIME types and creating assets from files.
163
+ *
164
+ * @public
165
+ */
166
+ export declare abstract class AssetUtil<Asset extends TLAsset = TLAsset> {
167
+ editor: Editor;
168
+ /** Configure this asset util's {@link AssetUtil.options | `options`}. */
169
+ static configure<T extends TLAssetUtilConstructor<any, any>>(this: T, options: T extends new (...args: any[]) => {
170
+ options: infer Options;
171
+ } ? Partial<Options> : never): T;
172
+ constructor(editor: Editor);
173
+ /**
174
+ * Options for this asset util. Override this to provide customization options for your asset.
175
+ * Use {@link AssetUtil.configure} to customize existing asset utils.
176
+ */
177
+ options: {};
178
+ static props?: RecordProps<TLUnknownAsset>;
179
+ static migrations?: LegacyMigrations | MigrationSequence | TLPropsMigrations;
180
+ /**
181
+ * The type of the asset util, which should match the asset's type.
182
+ */
183
+ static type: string;
184
+ /**
185
+ * Get the default props for an asset of this type.
186
+ */
187
+ abstract getDefaultProps(): Asset['props'];
188
+ /**
189
+ * Get the MIME types that this asset type supports.
190
+ * Return an empty array if this asset type doesn't support files (e.g. bookmarks).
191
+ */
192
+ getSupportedMimeTypes(): readonly string[];
193
+ /**
194
+ * Check whether this asset type accepts a given MIME type.
195
+ */
196
+ acceptsMimeType(mimeType: string): boolean;
197
+ /**
198
+ * Create an asset from a file. Return null if this asset type can't handle the file.
199
+ */
200
+ getAssetFromFile(_file: File, _assetId: TLAssetId): Promise<Asset | null>;
201
+ }
202
+
157
203
  /** @public */
158
204
  export declare function average(A: VecLike, B: VecLike): string;
159
205
 
@@ -1057,7 +1103,7 @@ export declare class EdgeScrollManager {
1057
1103
  /** @public */
1058
1104
  export declare class Editor extends EventEmitter<TLEventMap> {
1059
1105
  readonly id: string;
1060
- constructor({ store, user, shapeUtils, bindingUtils, tools, getContainer, cameraOptions, initialState, autoFocus, options: _options, textOptions: _textOptions, getShapeVisibility, colorScheme, fontAssetUrls, themes, initialTheme }: TLEditorOptions);
1106
+ constructor({ store, user, shapeUtils, bindingUtils, assetUtils: assetUtilConstructors, tools, getContainer, cameraOptions, initialState, autoFocus, options: _options, textOptions: _textOptions, getShapeVisibility, colorScheme, fontAssetUrls, themes, initialTheme }: TLEditorOptions);
1061
1107
  private readonly _getShapeVisibility?;
1062
1108
  private getIsShapeHiddenCache;
1063
1109
  isShapeHidden(shapeOrId: TLShape | TLShapeId): boolean;
@@ -1120,6 +1166,12 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1120
1166
  * @public
1121
1167
  */
1122
1168
  readonly snaps: SnapManager;
1169
+ /**
1170
+ * A manager for performance measurement hooks.
1171
+ *
1172
+ * @public
1173
+ */
1174
+ readonly performance: PerformanceManager;
1123
1175
  /* Excluded from this release type: _spatialIndex */
1124
1176
  /**
1125
1177
  * A manager for the any asynchronous events and making sure they're
@@ -1275,6 +1327,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1275
1327
  shapeUtils: {
1276
1328
  readonly [K in string]?: ShapeUtil<TLShape>;
1277
1329
  };
1330
+ /* Excluded from this release type: _shapeUtilsByAssetType */
1278
1331
  styleProps: {
1279
1332
  [key: string]: Map<StyleProp<any>, string>;
1280
1333
  };
@@ -1306,6 +1359,15 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1306
1359
  hasShapeUtil(shape: TLShape | TLShapePartial<TLShape>): boolean;
1307
1360
  hasShapeUtil(type: TLShape['type']): boolean;
1308
1361
  hasShapeUtil<T extends ShapeUtil>(type: T extends ShapeUtil<infer R> ? R['type'] : string): boolean;
1362
+ /**
1363
+ * Get the shape util that handles the given asset type.
1364
+ * Returns the shape util whose {@link ShapeUtil.handledAssetTypes} includes
1365
+ * the given asset type, or undefined if none matches.
1366
+ *
1367
+ * @param assetType - The asset type string.
1368
+ * @public
1369
+ */
1370
+ getShapeUtilForAssetType(assetType: string): ShapeUtil | undefined;
1309
1371
  /**
1310
1372
  * A map of shape utility classes (TLShapeUtils) by shape type.
1311
1373
  *
@@ -1336,6 +1398,40 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1336
1398
  type: S['type'];
1337
1399
  } | S): BindingUtil<S>;
1338
1400
  getBindingUtil<T extends BindingUtil>(type: T extends BindingUtil<infer R> ? R['type'] : string): T;
1401
+ /**
1402
+ * A map of asset utility classes by asset type.
1403
+ *
1404
+ * @public
1405
+ */
1406
+ assetUtils: {
1407
+ readonly [K in string]?: AssetUtil<TLAsset>;
1408
+ };
1409
+ /**
1410
+ * Get an asset util from an asset or asset type.
1411
+ *
1412
+ * @param arg - An asset, asset type string, or object with type.
1413
+ *
1414
+ * @public
1415
+ */
1416
+ getAssetUtil<S extends TLAsset>(asset: {
1417
+ type: S['type'];
1418
+ } | S): AssetUtil<S>;
1419
+ getAssetUtil(type: string): AssetUtil;
1420
+ /**
1421
+ * Returns true if the editor has an asset util for the given asset type.
1422
+ *
1423
+ * @public
1424
+ */
1425
+ hasAssetUtil(arg: {
1426
+ type: string;
1427
+ } | string): boolean;
1428
+ /**
1429
+ * Get the asset util that accepts the given MIME type.
1430
+ * Returns null if no registered asset util accepts the MIME type.
1431
+ *
1432
+ * @public
1433
+ */
1434
+ getAssetUtilForMimeType(mimeType: string): AssetUtil | null;
1339
1435
  /**
1340
1436
  * A manager for the editor's history.
1341
1437
  *
@@ -4685,7 +4781,7 @@ export declare class GroupShapeUtil extends ShapeUtil<TLGroupShape> {
4685
4781
  static type: "group";
4686
4782
  static props: RecordProps<TLGroupShape>;
4687
4783
  static migrations: TLPropsMigrations;
4688
- hideSelectionBoundsFg(): boolean;
4784
+ hideSelectionBoundsFg(shape: TLGroupShape): boolean;
4689
4785
  canBind(): boolean;
4690
4786
  canResize(): boolean;
4691
4787
  canResizeChildren(): boolean;
@@ -5327,6 +5423,94 @@ export declare function parseDeepLinkString(deepLinkString: string): TLDeepLink;
5327
5423
  /** @public */
5328
5424
  export declare type PerfectDashTerminal = 'none' | 'outset' | 'skip';
5329
5425
 
5426
+ /**
5427
+ * Optional adapter that pipes PerformanceManager events into browser
5428
+ * `performance.mark()` / `performance.measure()` for DevTools integration.
5429
+ *
5430
+ * Tree-shakeable — only included if imported.
5431
+ *
5432
+ * @example
5433
+ * ```ts
5434
+ * const adapter = new PerformanceApiAdapter(editor.performance)
5435
+ * // ... later
5436
+ * adapter.dispose()
5437
+ * ```
5438
+ *
5439
+ * @public
5440
+ */
5441
+ export declare class PerformanceApiAdapter {
5442
+ private cleanups;
5443
+ constructor(perfManager: PerformanceManager);
5444
+ /** Remove all listeners and stop piping events. @public */
5445
+ dispose(): void;
5446
+ }
5447
+
5448
+ /**
5449
+ * Manages performance event subscriptions for the editor. Available as `editor.performance`.
5450
+ *
5451
+ * Listeners are lazy — internal editor hooks (frame, shape events) are only attached while
5452
+ * at least one subscriber exists, so there is zero overhead when unused.
5453
+ *
5454
+ * @example
5455
+ * ```ts
5456
+ * const unsub = editor.performance.on('interaction-end', (event) => {
5457
+ * console.log(`${event.name}: ${event.fps.toFixed(1)} fps, p95=${event.p95FrameTime.toFixed(1)}ms`)
5458
+ * })
5459
+ * ```
5460
+ *
5461
+ * @public
5462
+ */
5463
+ export declare class PerformanceManager {
5464
+ /* Excluded from this release type: emitter */
5465
+ private editor;
5466
+ private activeInteraction;
5467
+ private activeCamera;
5468
+ private frameCleanup;
5469
+ private shapeCreatedCleanup;
5470
+ private shapeEditedCleanup;
5471
+ private shapeDeletedCleanup;
5472
+ private loafObserver;
5473
+ constructor(editor: Editor);
5474
+ /**
5475
+ * Subscribe to a performance event. Returns an unsubscribe function.
5476
+ *
5477
+ * @example
5478
+ * ```ts
5479
+ * const unsub = editor.performance.on('interaction-end', (event) => {
5480
+ * sendToAnalytics({ name: event.name, fps: event.fps, p95: event.p95FrameTime })
5481
+ * })
5482
+ * // later: unsub()
5483
+ * ```
5484
+ *
5485
+ * @public
5486
+ */
5487
+ on<K extends keyof TLPerfEventMap>(event: K, fn: (...args: TLPerfEventMap[K]) => void): () => void;
5488
+ /**
5489
+ * Subscribe to a performance event once. The listener is removed after the first invocation.
5490
+ * Returns an unsubscribe function for early removal.
5491
+ *
5492
+ * @public
5493
+ */
5494
+ once<K extends keyof TLPerfEventMap>(event: K, fn: (...args: TLPerfEventMap[K]) => void): () => void;
5495
+ /* Excluded from this release type: dispose */
5496
+ /* Excluded from this release type: _notifyInteractionStart */
5497
+ /* Excluded from this release type: _notifyInteractionEnd */
5498
+ /* Excluded from this release type: _notifyCameraOperation */
5499
+ /* Excluded from this release type: _notifyUndoRedo */
5500
+ private _startCameraSession;
5501
+ private _endCameraSession;
5502
+ private _onFrame;
5503
+ private _onShapesCreated;
5504
+ private _onShapesEdited;
5505
+ private _onShapesDeleted;
5506
+ private _startLoafObserver;
5507
+ private _stopLoafObserver;
5508
+ private _needsFrameListener;
5509
+ private _needsLoafObserver;
5510
+ private _maybeAttachLazyListeners;
5511
+ private _maybeDetachLazyListeners;
5512
+ }
5513
+
5330
5514
  /**
5331
5515
  * Find the approximate perimeter of an ellipse.
5332
5516
  *
@@ -5812,12 +5996,32 @@ export declare abstract class ShapeUtil<Shape extends TLShape = TLShape> {
5812
5996
  * @public
5813
5997
  */
5814
5998
  static type: string;
5999
+ /**
6000
+ * The asset types that this shape can be created from.
6001
+ * When a file is dropped on the canvas, the editor finds the shape util
6002
+ * whose `handledAssetTypes` includes the asset's type and calls
6003
+ * {@link ShapeUtil.createShapeForAsset} to produce the shape.
6004
+ *
6005
+ * @public
6006
+ */
6007
+ static handledAssetTypes?: readonly string[];
5815
6008
  /**
5816
6009
  * Get the default props for a shape.
5817
6010
  *
5818
6011
  * @public
5819
6012
  */
5820
6013
  abstract getDefaultProps(): Shape['props'];
6014
+ /**
6015
+ * Create a shape partial for placing an asset on the canvas.
6016
+ * Only called for shapes whose constructor declares matching
6017
+ * {@link ShapeUtil.handledAssetTypes | `handledAssetTypes`}.
6018
+ *
6019
+ * @param asset - The asset to create a shape for.
6020
+ * @param position - Where to place the shape.
6021
+ * @returns A shape partial, or null if this shape can't be created for the asset.
6022
+ * @public
6023
+ */
6024
+ createShapeForAsset?(asset: TLAsset, position: VecModel): null | TLShapePartial;
5821
6025
  /**
5822
6026
  * Get the shape's geometry.
5823
6027
  *
@@ -5898,7 +6102,7 @@ export declare abstract class ShapeUtil<Shape extends TLShape = TLShape> {
5898
6102
  *
5899
6103
  * @public
5900
6104
  */
5901
- canBind(_opts: TLShapeUtilCanBindOpts): boolean;
6105
+ canBind(opts: TLShapeUtilCanBindOpts): boolean;
5902
6106
  /**
5903
6107
  * Whether the shape can be double clicked to edit.
5904
6108
  *
@@ -6079,7 +6283,7 @@ export declare abstract class ShapeUtil<Shape extends TLShape = TLShape> {
6079
6283
  * @param type - The shape type.
6080
6284
  * @public
6081
6285
  */
6082
- canReceiveNewChildrenOfType(shape: Shape, _type: TLShape['type']): boolean;
6286
+ canReceiveNewChildrenOfType(shape: Shape, type: TLShape['type']): boolean;
6083
6287
  /**
6084
6288
  * Get the shape as an SVG object.
6085
6289
  *
@@ -6522,6 +6726,8 @@ export declare abstract class StateNode implements Partial<TLEventHandlers> {
6522
6726
  static children?: () => TLStateNodeConstructor[];
6523
6727
  static isLockable: boolean;
6524
6728
  static useCoalescedEvents: boolean;
6729
+ /** Set to `true` in subclasses to emit interaction-start/end performance events when this state is entered/exited. */
6730
+ static trackPerformance: boolean;
6525
6731
  id: string;
6526
6732
  type: 'branch' | 'leaf' | 'root';
6527
6733
  shapeType?: string;
@@ -6789,12 +6995,23 @@ export declare type TiptapNode = Node_2;
6789
6995
  /** @public */
6790
6996
  export declare type TLAdjacentDirection = 'down' | 'left' | 'next' | 'prev' | 'right' | 'up';
6791
6997
 
6998
+ /** @public */
6999
+ export declare type TLAnyAssetUtilConstructor = TLAssetUtilConstructor<any>;
7000
+
6792
7001
  /** @public */
6793
7002
  export declare type TLAnyBindingUtilConstructor = TLBindingUtilConstructor<any>;
6794
7003
 
6795
7004
  /** @public */
6796
7005
  export declare type TLAnyShapeUtilConstructor = TLShapeUtilConstructor<any>;
6797
7006
 
7007
+ /** @public */
7008
+ export declare interface TLAssetUtilConstructor<T extends TLAsset = TLAsset, U extends AssetUtil<T> = AssetUtil<T>> {
7009
+ new (editor: Editor): U;
7010
+ type: T['type'];
7011
+ props?: RecordProps<T>;
7012
+ migrations?: LegacyMigrations | MigrationSequence | TLPropsMigrations;
7013
+ }
7014
+
6798
7015
  /** @public */
6799
7016
  export declare type TLBaseBoxShape = ExtractShapeByProps<{
6800
7017
  h: number;
@@ -6884,6 +7101,29 @@ export declare interface TLCameraConstraints {
6884
7101
  };
6885
7102
  }
6886
7103
 
7104
+ /**
7105
+ * Emitted when a camera operation ends (after a 50ms debounce), with aggregated frame time stats.
7106
+ * @public
7107
+ */
7108
+ export declare interface TLCameraEndPerfEvent extends TLPerfFrameTimeStats {
7109
+ /** Whether this was a pan or zoom operation. */
7110
+ type: 'panning' | 'zooming';
7111
+ /** Total shapes on the current page. */
7112
+ shapeCount: number;
7113
+ /** Number of shapes visible (not culled) in the viewport. */
7114
+ visibleShapeCount: number;
7115
+ /** Number of shapes culled (off-screen) from rendering. */
7116
+ culledShapeCount: number;
7117
+ /** Viewport width in screen pixels. */
7118
+ viewportWidth: number;
7119
+ /** Viewport height in screen pixels. */
7120
+ viewportHeight: number;
7121
+ /** Camera zoom level (`camera.z`) at session end. */
7122
+ zoomLevel: number;
7123
+ /** `performance.now()` when the camera session ended. */
7124
+ timestamp: number;
7125
+ }
7126
+
6887
7127
  /** @public */
6888
7128
  export declare interface TLCameraMoveOptions {
6889
7129
  /** Whether to move the camera immediately, rather than on the next tick. */
@@ -6922,6 +7162,17 @@ export declare interface TLCameraOptions {
6922
7162
  constraints?: TLCameraConstraints;
6923
7163
  }
6924
7164
 
7165
+ /**
7166
+ * Emitted when a camera operation (pan or zoom) begins.
7167
+ * @public
7168
+ */
7169
+ export declare interface TLCameraStartPerfEvent {
7170
+ /** Whether this is a pan or zoom operation. */
7171
+ type: 'panning' | 'zooming';
7172
+ /** `performance.now()` when the camera session started. */
7173
+ timestamp: number;
7174
+ }
7175
+
6925
7176
  /** @public */
6926
7177
  export declare type TLCancelEvent = (info: TLCancelEventInfo) => void;
6927
7178
 
@@ -7144,6 +7395,10 @@ export declare interface TldrawEditorBaseProps {
7144
7395
  * An array of binding utils to use in the editor.
7145
7396
  */
7146
7397
  bindingUtils?: readonly TLAnyBindingUtilConstructor[];
7398
+ /**
7399
+ * An array of asset utils to use in the editor.
7400
+ */
7401
+ assetUtils?: readonly TLAnyAssetUtilConstructor[];
7147
7402
  /**
7148
7403
  * An array of tools to add to the editor's state chart.
7149
7404
  */
@@ -7579,6 +7834,10 @@ export declare interface TLEditorOptions {
7579
7834
  * An array of bindings to use in the editor. These will be used to create and manage bindings in the editor.
7580
7835
  */
7581
7836
  bindingUtils: readonly TLAnyBindingUtilConstructor[];
7837
+ /**
7838
+ * An array of asset utils to use in the editor. These will be used to handle asset-type-specific behavior.
7839
+ */
7840
+ assetUtils?: readonly TLAnyAssetUtilConstructor[];
7582
7841
  /**
7583
7842
  * An array of tools to use in the editor. These will be used to handle events and manage user interactions in the editor.
7584
7843
  */
@@ -7841,6 +8100,7 @@ export declare interface TLFileReplaceExternalContent extends TLBaseExternalCont
7841
8100
  type: 'file-replace';
7842
8101
  file: File;
7843
8102
  shapeId: TLShapeId;
8103
+ /** @deprecated This field is no longer used by the default handler. It may be removed in a future version. */
7844
8104
  isImage: boolean;
7845
8105
  }
7846
8106
 
@@ -7851,6 +8111,21 @@ export declare interface TLFilesExternalContent extends TLBaseExternalContent {
7851
8111
  ignoreParent?: boolean;
7852
8112
  }
7853
8113
 
8114
+ /**
8115
+ * Emitted every animation frame when at least one `'frame'` listener is registered.
8116
+ * @public
8117
+ */
8118
+ export declare interface TLFramePerfEvent {
8119
+ /** Time since the last frame in ms. */
8120
+ elapsed: number;
8121
+ /** Total shapes on the current page. */
8122
+ shapeCount: number;
8123
+ /** Number of shapes culled (off-screen) from rendering. */
8124
+ culledShapeCount: number;
8125
+ /** Number of shapes visible (not culled) in the viewport. */
8126
+ visibleShapeCount: number;
8127
+ }
8128
+
7854
8129
  /** Additional options for the {@link ShapeUtil.getGeometry} method.
7855
8130
  *
7856
8131
  * @public
@@ -7993,6 +8268,38 @@ export declare type TLIndicatorPath = {
7993
8268
  path: Path2D;
7994
8269
  } | Path2D;
7995
8270
 
8271
+ /**
8272
+ * Emitted when an interaction state is exited, with aggregated frame time stats.
8273
+ * @public
8274
+ */
8275
+ export declare interface TLInteractionEndPerfEvent extends TLPerfFrameTimeStats {
8276
+ /** The state node id (e.g. `'translating'`). */
8277
+ name: string;
8278
+ /** Full tool path (e.g. `'select.translating'`). */
8279
+ path: string;
8280
+ /** Total shapes on the current page. */
8281
+ shapeCount: number;
8282
+ /** Breakdown of selected shape types at interaction start (e.g. `{ geo: 2, draw: 1 }`). */
8283
+ selectedShapeTypes: Record<string, number>;
8284
+ /** Camera zoom level (`camera.z`) at interaction end. */
8285
+ zoomLevel: number;
8286
+ /** `performance.now()` when the interaction ended. */
8287
+ timestamp: number;
8288
+ }
8289
+
8290
+ /**
8291
+ * Emitted when an interaction state (e.g. translating, resizing) is entered.
8292
+ * @public
8293
+ */
8294
+ export declare interface TLInteractionStartPerfEvent {
8295
+ /** The state node id (e.g. `'translating'`). */
8296
+ name: string;
8297
+ /** Full tool path (e.g. `'select.translating'`). */
8298
+ path: string;
8299
+ /** `performance.now()` when the interaction started. */
8300
+ timestamp: number;
8301
+ }
8302
+
7996
8303
  /** @public */
7997
8304
  export declare type TLInterruptEvent = (info: TLInterruptEventInfo) => void;
7998
8305
 
@@ -8240,6 +8547,94 @@ export declare const tlmenus: {
8240
8547
  */
8241
8548
  export declare type TLOnMountHandler = (editor: Editor) => (() => undefined | void) | undefined | void;
8242
8549
 
8550
+ /**
8551
+ * Map of all performance event names to their payload types.
8552
+ * Used with {@link PerformanceManager.on} and {@link PerformanceManager.once}.
8553
+ * @public
8554
+ */
8555
+ export declare interface TLPerfEventMap {
8556
+ /** An interaction state was entered. */
8557
+ 'interaction-start': [TLInteractionStartPerfEvent];
8558
+ /** An interaction state was exited, with aggregated frame time stats. */
8559
+ 'interaction-end': [TLInteractionEndPerfEvent];
8560
+ /** A camera operation (pan/zoom) began. */
8561
+ 'camera-start': [TLCameraStartPerfEvent];
8562
+ /** A camera operation ended (after debounce), with aggregated frame time stats. */
8563
+ 'camera-end': [TLCameraEndPerfEvent];
8564
+ /** Shapes were created. */
8565
+ 'shapes-created': [TLShapeOperationPerfEvent];
8566
+ /** Shapes were updated. */
8567
+ 'shapes-updated': [TLShapeOperationPerfEvent];
8568
+ /** Shapes were deleted. */
8569
+ 'shapes-deleted': [TLShapeOperationPerfEvent];
8570
+ /** An animation frame was rendered. Only fires when listeners are registered. */
8571
+ frame: [TLFramePerfEvent];
8572
+ /** An undo operation was performed. */
8573
+ undo: [TLUndoRedoPerfEvent];
8574
+ /** A redo operation was performed. */
8575
+ redo: [TLUndoRedoPerfEvent];
8576
+ }
8577
+
8578
+ /**
8579
+ * Common frame time statistics shared by interaction and camera end events.
8580
+ * @public
8581
+ */
8582
+ export declare interface TLPerfFrameTimeStats {
8583
+ /** Total duration of the session in ms. */
8584
+ duration: number;
8585
+ /** Average frames per second during the session. */
8586
+ fps: number;
8587
+ /** Total number of frames recorded. */
8588
+ frameCount: number;
8589
+ /** Mean frame duration in ms. */
8590
+ avgFrameTime: number;
8591
+ /** Median (p50) frame duration in ms. */
8592
+ medianFrameTime: number;
8593
+ /** 95th percentile frame duration in ms. */
8594
+ p95FrameTime: number;
8595
+ /** 99th percentile frame duration in ms. */
8596
+ p99FrameTime: number;
8597
+ /** Shortest frame duration in ms. */
8598
+ minFrameTime: number;
8599
+ /** Longest frame duration in ms. */
8600
+ maxFrameTime: number;
8601
+ /** Raw frame durations for local analysis. Exclude when sending to analytics. */
8602
+ frameTimes: number[];
8603
+ /**
8604
+ * Long animation frames observed during this period (Chromium 123+).
8605
+ * Only present when the browser supports the Long Animation Frames API and
8606
+ * at least one long frame was observed.
8607
+ * Exclude when sending to analytics — entries are large and contain script URLs.
8608
+ */
8609
+ longAnimationFrames?: TLPerfLongAnimationFrame[];
8610
+ }
8611
+
8612
+ /**
8613
+ * A long animation frame observed by the browser during an interaction.
8614
+ * Available only in browsers that support the Long Animation Frames API (Chromium 123+).
8615
+ * @public
8616
+ */
8617
+ export declare interface TLPerfLongAnimationFrame {
8618
+ /** Frame start time (relative to timeOrigin). */
8619
+ startTime: number;
8620
+ /** Total frame duration in ms. */
8621
+ duration: number;
8622
+ /** Time the main thread was blocked in ms. */
8623
+ blockingDuration: number;
8624
+ /** Scripts that contributed to the long frame. */
8625
+ scripts: TLPerfLongAnimationFrameScript[];
8626
+ }
8627
+
8628
+ /** A script attribution entry from a long animation frame. @public */
8629
+ export declare interface TLPerfLongAnimationFrameScript {
8630
+ /** The script source URL (may be empty for inline scripts). */
8631
+ sourceURL: string;
8632
+ /** The function name or invoker description. */
8633
+ invoker: string;
8634
+ /** Time spent in this script in ms. */
8635
+ duration: number;
8636
+ }
8637
+
8243
8638
  /** @public */
8244
8639
  export declare type TLPinchEvent = (info: TLPinchEventInfo) => void;
8245
8640
 
@@ -8427,6 +8822,21 @@ export declare interface TLShapeIndicatorsProps {
8427
8822
  showAll?: boolean;
8428
8823
  }
8429
8824
 
8825
+ /**
8826
+ * Emitted when shapes are created, updated, or deleted.
8827
+ * @public
8828
+ */
8829
+ export declare interface TLShapeOperationPerfEvent {
8830
+ /** The operation type. */
8831
+ operation: 'create' | 'delete' | 'update';
8832
+ /** Number of shapes affected. */
8833
+ count: number;
8834
+ /** Breakdown by shape type (e.g. `{ geo: 2, draw: 1 }`). */
8835
+ shapeTypes: Record<string, number>;
8836
+ /** `performance.now()` when the operation occurred. */
8837
+ timestamp: number;
8838
+ }
8839
+
8430
8840
  /**
8431
8841
  * Options passed to {@link ShapeUtil.canBeLaidOut}.
8432
8842
  *
@@ -8484,6 +8894,7 @@ export declare interface TLShapeUtilConstructor<T extends TLShape, U extends Sha
8484
8894
  type: T['type'];
8485
8895
  props?: RecordProps<T>;
8486
8896
  migrations?: LegacyMigrations | MigrationSequence | TLPropsMigrations;
8897
+ handledAssetTypes?: readonly string[];
8487
8898
  }
8488
8899
 
8489
8900
  /** @public */
@@ -8511,6 +8922,7 @@ export declare interface TLStateNodeConstructor {
8511
8922
  children?(): TLStateNodeConstructor[];
8512
8923
  isLockable: boolean;
8513
8924
  useCoalescedEvents: boolean;
8925
+ trackPerformance: boolean;
8514
8926
  }
8515
8927
 
8516
8928
  /** @public */
@@ -8550,6 +8962,7 @@ export declare type TLStoreOptions = TLStoreBaseOptions & {
8550
8962
 
8551
8963
  /** @public */
8552
8964
  export declare type TLStoreSchemaOptions = {
8965
+ assetUtils?: readonly TLAnyAssetUtilConstructor[];
8553
8966
  bindingUtils?: readonly TLAnyBindingUtilConstructor[];
8554
8967
  migrations?: readonly MigrationSequence[];
8555
8968
  records?: Record<string, CustomRecordInfo>;
@@ -8687,6 +9100,19 @@ export declare interface TLTldrawExternalContentSource {
8687
9100
  data: TLContent;
8688
9101
  }
8689
9102
 
9103
+ /**
9104
+ * Emitted after an undo or redo operation.
9105
+ * @public
9106
+ */
9107
+ export declare interface TLUndoRedoPerfEvent {
9108
+ /** Whether this was an undo or redo. */
9109
+ type: 'redo' | 'undo';
9110
+ /** Number of undo steps remaining. */
9111
+ undoDepth: number;
9112
+ /** Number of redo steps remaining. */
9113
+ redoDepth: number;
9114
+ }
9115
+
8690
9116
  /** @public */
8691
9117
  export declare interface TLUpdatePointerOptions {
8692
9118
  /** Whether to update the pointer immediately, rather than on the next tick. */
package/dist-cjs/index.js CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  var index_exports = {};
21
21
  __export(index_exports, {
22
22
  Arc2d: () => import_Arc2d.Arc2d,
23
+ AssetUtil: () => import_AssetUtil.AssetUtil,
23
24
  BaseBoxShapeTool: () => import_BaseBoxShapeTool.BaseBoxShapeTool,
24
25
  BaseBoxShapeUtil: () => import_BaseBoxShapeUtil.BaseBoxShapeUtil,
25
26
  BindingUtil: () => import_BindingUtil.BindingUtil,
@@ -81,6 +82,8 @@ __export(index_exports, {
81
82
  OptionalErrorBoundary: () => import_ErrorBoundary.OptionalErrorBoundary,
82
83
  PI: () => import_utils2.PI,
83
84
  PI2: () => import_utils2.PI2,
85
+ PerformanceApiAdapter: () => import_PerformanceApiAdapter.PerformanceApiAdapter,
86
+ PerformanceManager: () => import_PerformanceManager.PerformanceManager,
84
87
  Point2d: () => import_Point2d.Point2d,
85
88
  Polygon2d: () => import_Polygon2d.Polygon2d,
86
89
  Polyline2d: () => import_Polyline2d.Polyline2d,
@@ -283,6 +286,7 @@ var import_TLEditorSnapshot = require("./lib/config/TLEditorSnapshot");
283
286
  var import_TLSessionStateSnapshot = require("./lib/config/TLSessionStateSnapshot");
284
287
  var import_TLUserPreferences = require("./lib/config/TLUserPreferences");
285
288
  var import_constants = require("./lib/constants");
289
+ var import_AssetUtil = require("./lib/editor/assets/AssetUtil");
286
290
  var import_BindingUtil = require("./lib/editor/bindings/BindingUtil");
287
291
  var import_Editor = require("./lib/editor/Editor");
288
292
  var import_ClickManager = require("./lib/editor/managers/ClickManager/ClickManager");
@@ -299,6 +303,8 @@ var import_TextManager = require("./lib/editor/managers/TextManager/TextManager"
299
303
  var import_defaultThemes = require("./lib/editor/managers/ThemeManager/defaultThemes");
300
304
  var import_ThemeManager = require("./lib/editor/managers/ThemeManager/ThemeManager");
301
305
  var import_TickManager = require("./lib/editor/managers/TickManager/TickManager");
306
+ var import_PerformanceApiAdapter = require("./lib/editor/managers/PerformanceManager/PerformanceApiAdapter");
307
+ var import_PerformanceManager = require("./lib/editor/managers/PerformanceManager/PerformanceManager");
302
308
  var import_UserPreferencesManager = require("./lib/editor/managers/UserPreferencesManager/UserPreferencesManager");
303
309
  var import_BaseBoxShapeUtil = require("./lib/editor/shapes/BaseBoxShapeUtil");
304
310
  var import_GroupShapeUtil = require("./lib/editor/shapes/group/GroupShapeUtil");
@@ -383,7 +389,7 @@ var import_uniq = require("./lib/utils/uniq");
383
389
  var import_defaultThemes2 = require("./lib/editor/managers/ThemeManager/defaultThemes");
384
390
  (0, import_utils.registerTldrawLibraryVersion)(
385
391
  "@tldraw/editor",
386
- "4.6.0-canary.d388dc133c68",
392
+ "4.6.0-canary.d56815af4e9e",
387
393
  "cjs"
388
394
  );
389
395
  //# sourceMappingURL=index.js.map