@tldraw/editor 4.6.0-next.e0f85e824397 → 4.6.0-next.e390fde97eab
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.
- package/dist-cjs/index.d.ts +297 -3
- package/dist-cjs/index.js +5 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/components/MenuClickCapture.js +16 -1
- package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +15 -0
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.js +80 -0
- package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.js.map +7 -0
- package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js +466 -0
- package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/PerformanceManager/perf-types.js +17 -0
- package/dist-cjs/lib/editor/managers/PerformanceManager/perf-types.js.map +7 -0
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +1 -1
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js +6 -0
- package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js.map +2 -2
- package/dist-cjs/lib/editor/tools/StateNode.js +14 -17
- package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
- package/dist-cjs/lib/utils/runtime.js +2 -1
- package/dist-cjs/lib/utils/runtime.js.map +2 -2
- package/dist-cjs/lib/utils/sync/hardReset.js +0 -8
- package/dist-cjs/lib/utils/sync/hardReset.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +297 -3
- package/dist-esm/index.mjs +5 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/components/MenuClickCapture.mjs +16 -1
- package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +15 -0
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.mjs +60 -0
- package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs +438 -0
- package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/PerformanceManager/perf-types.mjs +1 -0
- package/dist-esm/lib/editor/managers/PerformanceManager/perf-types.mjs.map +7 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +1 -1
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs +6 -0
- package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/StateNode.mjs +14 -17
- package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
- package/dist-esm/lib/utils/runtime.mjs +2 -1
- package/dist-esm/lib/utils/runtime.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/hardReset.mjs +0 -8
- package/dist-esm/lib/utils/sync/hardReset.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +15 -0
- package/src/lib/components/MenuClickCapture.tsx +20 -0
- package/src/lib/editor/Editor.ts +16 -0
- package/src/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.ts +82 -0
- package/src/lib/editor/managers/PerformanceManager/PerformanceManager.test.ts +522 -0
- package/src/lib/editor/managers/PerformanceManager/PerformanceManager.ts +583 -0
- package/src/lib/editor/managers/PerformanceManager/perf-types.ts +196 -0
- package/src/lib/editor/shapes/ShapeUtil.ts +2 -2
- package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +1 -1
- package/src/lib/editor/shapes/shared/getPerfectDashProps.ts +7 -0
- package/src/lib/editor/tools/StateNode.ts +16 -18
- package/src/lib/utils/runtime.ts +3 -1
- package/src/lib/utils/sync/hardReset.ts +0 -8
- package/src/version.ts +3 -3
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common frame time statistics shared by interaction and camera end events.
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export interface TLPerfFrameTimeStats {
|
|
6
|
+
/** Total duration of the session in ms. */
|
|
7
|
+
duration: number
|
|
8
|
+
/** Average frames per second during the session. */
|
|
9
|
+
fps: number
|
|
10
|
+
/** Total number of frames recorded. */
|
|
11
|
+
frameCount: number
|
|
12
|
+
/** Mean frame duration in ms. */
|
|
13
|
+
avgFrameTime: number
|
|
14
|
+
/** Median (p50) frame duration in ms. */
|
|
15
|
+
medianFrameTime: number
|
|
16
|
+
/** 95th percentile frame duration in ms. */
|
|
17
|
+
p95FrameTime: number
|
|
18
|
+
/** 99th percentile frame duration in ms. */
|
|
19
|
+
p99FrameTime: number
|
|
20
|
+
/** Shortest frame duration in ms. */
|
|
21
|
+
minFrameTime: number
|
|
22
|
+
/** Longest frame duration in ms. */
|
|
23
|
+
maxFrameTime: number
|
|
24
|
+
/** Raw frame durations for local analysis. Exclude when sending to analytics. */
|
|
25
|
+
frameTimes: number[]
|
|
26
|
+
/**
|
|
27
|
+
* Long animation frames observed during this period (Chromium 123+).
|
|
28
|
+
* Only present when the browser supports the Long Animation Frames API and
|
|
29
|
+
* at least one long frame was observed.
|
|
30
|
+
* Exclude when sending to analytics — entries are large and contain script URLs.
|
|
31
|
+
*/
|
|
32
|
+
longAnimationFrames?: TLPerfLongAnimationFrame[]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Emitted when an interaction state (e.g. translating, resizing) is entered.
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export interface TLInteractionStartPerfEvent {
|
|
40
|
+
/** The state node id (e.g. `'translating'`). */
|
|
41
|
+
name: string
|
|
42
|
+
/** Full tool path (e.g. `'select.translating'`). */
|
|
43
|
+
path: string
|
|
44
|
+
/** `performance.now()` when the interaction started. */
|
|
45
|
+
timestamp: number
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Emitted when an interaction state is exited, with aggregated frame time stats.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export interface TLInteractionEndPerfEvent extends TLPerfFrameTimeStats {
|
|
53
|
+
/** The state node id (e.g. `'translating'`). */
|
|
54
|
+
name: string
|
|
55
|
+
/** Full tool path (e.g. `'select.translating'`). */
|
|
56
|
+
path: string
|
|
57
|
+
/** Total shapes on the current page. */
|
|
58
|
+
shapeCount: number
|
|
59
|
+
/** Breakdown of selected shape types at interaction start (e.g. `{ geo: 2, draw: 1 }`). */
|
|
60
|
+
selectedShapeTypes: Record<string, number>
|
|
61
|
+
/** Camera zoom level (`camera.z`) at interaction end. */
|
|
62
|
+
zoomLevel: number
|
|
63
|
+
/** `performance.now()` when the interaction ended. */
|
|
64
|
+
timestamp: number
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Emitted when a camera operation (pan or zoom) begins.
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export interface TLCameraStartPerfEvent {
|
|
72
|
+
/** Whether this is a pan or zoom operation. */
|
|
73
|
+
type: 'panning' | 'zooming'
|
|
74
|
+
/** `performance.now()` when the camera session started. */
|
|
75
|
+
timestamp: number
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Emitted when a camera operation ends (after a 50ms debounce), with aggregated frame time stats.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export interface TLCameraEndPerfEvent extends TLPerfFrameTimeStats {
|
|
83
|
+
/** Whether this was a pan or zoom operation. */
|
|
84
|
+
type: 'panning' | 'zooming'
|
|
85
|
+
/** Total shapes on the current page. */
|
|
86
|
+
shapeCount: number
|
|
87
|
+
/** Number of shapes visible (not culled) in the viewport. */
|
|
88
|
+
visibleShapeCount: number
|
|
89
|
+
/** Number of shapes culled (off-screen) from rendering. */
|
|
90
|
+
culledShapeCount: number
|
|
91
|
+
/** Viewport width in screen pixels. */
|
|
92
|
+
viewportWidth: number
|
|
93
|
+
/** Viewport height in screen pixels. */
|
|
94
|
+
viewportHeight: number
|
|
95
|
+
/** Camera zoom level (`camera.z`) at session end. */
|
|
96
|
+
zoomLevel: number
|
|
97
|
+
/** `performance.now()` when the camera session ended. */
|
|
98
|
+
timestamp: number
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Emitted when shapes are created, updated, or deleted.
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
export interface TLShapeOperationPerfEvent {
|
|
106
|
+
/** The operation type. */
|
|
107
|
+
operation: 'create' | 'update' | 'delete'
|
|
108
|
+
/** Number of shapes affected. */
|
|
109
|
+
count: number
|
|
110
|
+
/** Breakdown by shape type (e.g. `{ geo: 2, draw: 1 }`). */
|
|
111
|
+
shapeTypes: Record<string, number>
|
|
112
|
+
/** `performance.now()` when the operation occurred. */
|
|
113
|
+
timestamp: number
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Emitted every animation frame when at least one `'frame'` listener is registered.
|
|
118
|
+
* @public
|
|
119
|
+
*/
|
|
120
|
+
export interface TLFramePerfEvent {
|
|
121
|
+
/** Time since the last frame in ms. */
|
|
122
|
+
elapsed: number
|
|
123
|
+
/** Total shapes on the current page. */
|
|
124
|
+
shapeCount: number
|
|
125
|
+
/** Number of shapes culled (off-screen) from rendering. */
|
|
126
|
+
culledShapeCount: number
|
|
127
|
+
/** Number of shapes visible (not culled) in the viewport. */
|
|
128
|
+
visibleShapeCount: number
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Emitted after an undo or redo operation.
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
export interface TLUndoRedoPerfEvent {
|
|
136
|
+
/** Whether this was an undo or redo. */
|
|
137
|
+
type: 'undo' | 'redo'
|
|
138
|
+
/** Number of undo steps remaining. */
|
|
139
|
+
undoDepth: number
|
|
140
|
+
/** Number of redo steps remaining. */
|
|
141
|
+
redoDepth: number
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* A long animation frame observed by the browser during an interaction.
|
|
146
|
+
* Available only in browsers that support the Long Animation Frames API (Chromium 123+).
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
export interface TLPerfLongAnimationFrame {
|
|
150
|
+
/** Frame start time (relative to timeOrigin). */
|
|
151
|
+
startTime: number
|
|
152
|
+
/** Total frame duration in ms. */
|
|
153
|
+
duration: number
|
|
154
|
+
/** Time the main thread was blocked in ms. */
|
|
155
|
+
blockingDuration: number
|
|
156
|
+
/** Scripts that contributed to the long frame. */
|
|
157
|
+
scripts: TLPerfLongAnimationFrameScript[]
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** A script attribution entry from a long animation frame. @public */
|
|
161
|
+
export interface TLPerfLongAnimationFrameScript {
|
|
162
|
+
/** The script source URL (may be empty for inline scripts). */
|
|
163
|
+
sourceURL: string
|
|
164
|
+
/** The function name or invoker description. */
|
|
165
|
+
invoker: string
|
|
166
|
+
/** Time spent in this script in ms. */
|
|
167
|
+
duration: number
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Map of all performance event names to their payload types.
|
|
172
|
+
* Used with {@link PerformanceManager.on} and {@link PerformanceManager.once}.
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
export interface TLPerfEventMap {
|
|
176
|
+
/** An interaction state was entered. */
|
|
177
|
+
'interaction-start': [TLInteractionStartPerfEvent]
|
|
178
|
+
/** An interaction state was exited, with aggregated frame time stats. */
|
|
179
|
+
'interaction-end': [TLInteractionEndPerfEvent]
|
|
180
|
+
/** A camera operation (pan/zoom) began. */
|
|
181
|
+
'camera-start': [TLCameraStartPerfEvent]
|
|
182
|
+
/** A camera operation ended (after debounce), with aggregated frame time stats. */
|
|
183
|
+
'camera-end': [TLCameraEndPerfEvent]
|
|
184
|
+
/** Shapes were created. */
|
|
185
|
+
'shapes-created': [TLShapeOperationPerfEvent]
|
|
186
|
+
/** Shapes were updated. */
|
|
187
|
+
'shapes-updated': [TLShapeOperationPerfEvent]
|
|
188
|
+
/** Shapes were deleted. */
|
|
189
|
+
'shapes-deleted': [TLShapeOperationPerfEvent]
|
|
190
|
+
/** An animation frame was rendered. Only fires when listeners are registered. */
|
|
191
|
+
frame: [TLFramePerfEvent]
|
|
192
|
+
/** An undo operation was performed. */
|
|
193
|
+
undo: [TLUndoRedoPerfEvent]
|
|
194
|
+
/** A redo operation was performed. */
|
|
195
|
+
redo: [TLUndoRedoPerfEvent]
|
|
196
|
+
}
|
|
@@ -301,7 +301,7 @@ export abstract class ShapeUtil<Shape extends TLShape = TLShape> {
|
|
|
301
301
|
*
|
|
302
302
|
* @public
|
|
303
303
|
*/
|
|
304
|
-
canBind(
|
|
304
|
+
canBind(opts: TLShapeUtilCanBindOpts): boolean {
|
|
305
305
|
return true
|
|
306
306
|
}
|
|
307
307
|
|
|
@@ -551,7 +551,7 @@ export abstract class ShapeUtil<Shape extends TLShape = TLShape> {
|
|
|
551
551
|
* @param type - The shape type.
|
|
552
552
|
* @public
|
|
553
553
|
*/
|
|
554
|
-
canReceiveNewChildrenOfType(shape: Shape,
|
|
554
|
+
canReceiveNewChildrenOfType(shape: Shape, type: TLShape['type']) {
|
|
555
555
|
return false
|
|
556
556
|
}
|
|
557
557
|
|
|
@@ -12,7 +12,7 @@ export class GroupShapeUtil extends ShapeUtil<TLGroupShape> {
|
|
|
12
12
|
static override props = groupShapeProps
|
|
13
13
|
static override migrations = groupShapeMigrations
|
|
14
14
|
|
|
15
|
-
override hideSelectionBoundsFg() {
|
|
15
|
+
override hideSelectionBoundsFg(shape: TLGroupShape) {
|
|
16
16
|
return true
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -17,20 +17,6 @@ import {
|
|
|
17
17
|
TLWheelEventInfo,
|
|
18
18
|
} from '../types/event-types'
|
|
19
19
|
|
|
20
|
-
const STATE_NODES_TO_MEASURE = [
|
|
21
|
-
'brushing',
|
|
22
|
-
'cropping',
|
|
23
|
-
'dragging',
|
|
24
|
-
'dragging_handle',
|
|
25
|
-
'drawing',
|
|
26
|
-
'erasing',
|
|
27
|
-
'lasering',
|
|
28
|
-
'resizing',
|
|
29
|
-
'rotating',
|
|
30
|
-
'scribble_brushing',
|
|
31
|
-
'translating',
|
|
32
|
-
]
|
|
33
|
-
|
|
34
20
|
/** @public */
|
|
35
21
|
export interface TLStateNodeConstructor {
|
|
36
22
|
new (editor: Editor, parent?: StateNode): StateNode
|
|
@@ -39,6 +25,7 @@ export interface TLStateNodeConstructor {
|
|
|
39
25
|
children?(): TLStateNodeConstructor[]
|
|
40
26
|
isLockable: boolean
|
|
41
27
|
useCoalescedEvents: boolean
|
|
28
|
+
trackPerformance: boolean
|
|
42
29
|
}
|
|
43
30
|
|
|
44
31
|
/** @public */
|
|
@@ -94,6 +81,8 @@ export abstract class StateNode implements Partial<TLEventHandlers> {
|
|
|
94
81
|
static children?: () => TLStateNodeConstructor[]
|
|
95
82
|
static isLockable = true
|
|
96
83
|
static useCoalescedEvents = false
|
|
84
|
+
/** Set to `true` in subclasses to emit interaction-start/end performance events when this state is entered/exited. */
|
|
85
|
+
static trackPerformance = false
|
|
97
86
|
|
|
98
87
|
id: string
|
|
99
88
|
type: 'branch' | 'leaf' | 'root'
|
|
@@ -191,8 +180,12 @@ export abstract class StateNode implements Partial<TLEventHandlers> {
|
|
|
191
180
|
|
|
192
181
|
// todo: move this logic into transition
|
|
193
182
|
enter(info: any, from: string) {
|
|
194
|
-
|
|
195
|
-
|
|
183
|
+
const track = (this.constructor as TLStateNodeConstructor).trackPerformance
|
|
184
|
+
if (track) {
|
|
185
|
+
if (debugFlags.measurePerformance.get()) {
|
|
186
|
+
this.performanceTracker.start(this.id)
|
|
187
|
+
}
|
|
188
|
+
this.editor.performance._notifyInteractionStart(this.id, this.getPath())
|
|
196
189
|
}
|
|
197
190
|
|
|
198
191
|
this._isActive.set(true)
|
|
@@ -207,9 +200,14 @@ export abstract class StateNode implements Partial<TLEventHandlers> {
|
|
|
207
200
|
|
|
208
201
|
// todo: move this logic into transition
|
|
209
202
|
exit(info: any, to: string) {
|
|
210
|
-
|
|
211
|
-
|
|
203
|
+
const track = (this.constructor as TLStateNodeConstructor).trackPerformance
|
|
204
|
+
if (track) {
|
|
205
|
+
if (debugFlags.measurePerformance.get() && this.performanceTracker.isStarted()) {
|
|
206
|
+
this.performanceTracker.stop()
|
|
207
|
+
}
|
|
208
|
+
this.editor.performance._notifyInteractionEnd()
|
|
212
209
|
}
|
|
210
|
+
|
|
213
211
|
this._isActive.set(false)
|
|
214
212
|
this.onExit?.(info, to)
|
|
215
213
|
|
package/src/lib/utils/runtime.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { hardReset } from './sync/hardReset'
|
|
2
|
+
|
|
1
3
|
/** @public */
|
|
2
4
|
export const runtime: {
|
|
3
5
|
openWindow(url: string, target: string, allowReferrer?: boolean): void
|
|
@@ -11,7 +13,7 @@ export const runtime: {
|
|
|
11
13
|
window.location.reload()
|
|
12
14
|
},
|
|
13
15
|
async hardReset() {
|
|
14
|
-
return await (
|
|
16
|
+
return await hardReset({ shouldReload: true })
|
|
15
17
|
},
|
|
16
18
|
}
|
|
17
19
|
|
|
@@ -19,11 +19,3 @@ export async function hardReset({ shouldReload = true } = {}) {
|
|
|
19
19
|
window.location.reload()
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
if (typeof window !== 'undefined') {
|
|
24
|
-
if (process.env.NODE_ENV === 'development') {
|
|
25
|
-
;(window as any).hardReset = hardReset
|
|
26
|
-
}
|
|
27
|
-
// window.__tldraw__hardReset is used to inject the logic into the tldraw library
|
|
28
|
-
;(window as any).__tldraw__hardReset = hardReset
|
|
29
|
-
}
|
package/src/version.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// This file is automatically generated by internal/scripts/refresh-assets.ts.
|
|
2
2
|
// Do not edit manually. Or do, I'm a comment, not a cop.
|
|
3
3
|
|
|
4
|
-
export const version = '4.6.0-next.
|
|
4
|
+
export const version = '4.6.0-next.e390fde97eab'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2025-09-18T14:39:22.803Z',
|
|
7
|
-
minor: '2026-04-
|
|
8
|
-
patch: '2026-04-
|
|
7
|
+
minor: '2026-04-15T14:45:51.334Z',
|
|
8
|
+
patch: '2026-04-15T14:45:51.334Z',
|
|
9
9
|
}
|