You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: editor-packages/editor-canvas/canvas-event-target/canvas-event-target.tsx
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -140,6 +140,7 @@ export function CanvasEventTarget({
140
140
{
141
141
target: interactionEventTargetRef,
142
142
eventOptions: {
143
+
// passive to false to raise `e.preventDefault()` and `e.stopPropagation()`. - this will prevent the browser from scrolling the page, navigating with swipe gesture (safari, firefox).
* when provided, it will override the saved value or centering logic and use this transform as initial instead.
33
+
*
34
+
* Canvas automatically saves the last transform and also automatically calculates the initial transform based on the input's complexity.
35
+
*
36
+
* @default undefined
37
+
*/
31
38
initialTransform?: CanvasTransform;
32
39
}
33
40
@@ -52,7 +59,69 @@ interface HovringNode {
52
59
reason: "frame-title"|"raycast"|"external";
53
60
}
54
61
62
+
functionauto_initial_transform(
63
+
viewbound: Box,
64
+
nodes: ReflectSceneNode[]
65
+
): CanvasTransform{
66
+
const_default={
67
+
scale: INITIAL_SCALE,
68
+
xy: INITIAL_XY,
69
+
};
70
+
71
+
if(!nodes||viewbound_not_measured(viewbound)){
72
+
return_default;
73
+
}
74
+
75
+
constfit_single_node=(n: ReflectSceneNode)=>{
76
+
returncenterOf(viewbound,n);
77
+
};
78
+
79
+
if(nodes.length===0){
80
+
return_default;
81
+
}elseif(nodes.length===1){
82
+
// return center the node
83
+
constc=fit_single_node(nodes[0]);
84
+
return{
85
+
xy: c.translate,
86
+
scale: c.scale,
87
+
};
88
+
}elseif(nodes.length<20){
89
+
// fit bounds
90
+
constc=centerOf(viewbound, ...nodes);
91
+
return{
92
+
xy: c.translate,
93
+
scale: c.scale,
94
+
};
95
+
}else{
96
+
// if more than 20 nodes, just center the first one. why? -> loading all frames at once will slow down the canvas, and in most cases, we don't have to show the whole content of the canvas.
97
+
// fit first item
98
+
constc=fit_single_node(nodes[0]);
99
+
return{
100
+
xy: c.translate,
101
+
scale: c.scale,
102
+
};
103
+
}
104
+
105
+
return_default;
106
+
}
107
+
108
+
/**
109
+
* when viewbound is not measured, it means the canvas is not ready to render. and the value will be `[0,0,0,0]` (from react-use-measure)
0 commit comments