@@ -14,11 +14,7 @@ import {
1414 OnPointerMoveHandler ,
1515 OnPointerDownHandler ,
1616} from "../canvas-event-target" ;
17- import {
18- transform_by_zoom_delta ,
19- get_hovering_target ,
20- centerOf ,
21- } from "../math" ;
17+ import { get_hovering_target , centerOf } from "../math" ;
2218import { utils } from "@design-sdk/core" ;
2319import { LazyFrame } from "@code-editor/canvas/lazy-frame" ;
2420import { HudCustomRenderers , HudSurface } from "./hud-surface" ;
@@ -29,7 +25,7 @@ const designq = utils.query;
2925const INITIAL_SCALE = 1 ;
3026const INITIAL_XY : XY = [ 0 , 0 ] ;
3127const LAYER_HOVER_HIT_MARGIN = 3.5 ;
32- const MIN_ZOOM = 0.05 ;
28+ const MIN_ZOOM = 0.02 ;
3329
3430type CanvasTransform = {
3531 scale : number ;
@@ -84,7 +80,8 @@ export function Canvas({
8480
8581 const [ zoom , setZoom ] = useState ( _initial_scale ) ;
8682 const [ isZooming , setIsZooming ] = useState ( false ) ;
87- const [ xy , setXY ] = useState < [ number , number ] > ( _inicial_xy ) ;
83+ const [ offset , setOffset ] = useState < [ number , number ] > ( _inicial_xy ) ;
84+ const nonscaled_offset : XY = [ offset [ 0 ] / zoom , offset [ 1 ] / zoom ] ; // offset;
8885 const [ isPanning , setIsPanning ] = useState ( false ) ;
8986
9087 const node = ( id ) => designq . find_node_by_id_under_inpage_nodes ( id , nodes ) ;
@@ -109,7 +106,7 @@ export function Canvas({
109106 point : state . xy ,
110107 tree : nodes ,
111108 zoom : zoom ,
112- offset : xy ,
109+ offset : nonscaled_offset ,
113110 margin : LAYER_HOVER_HIT_MARGIN ,
114111 } ) ;
115112
@@ -150,8 +147,9 @@ export function Canvas({
150147 wheeling,
151148 } = s ;
152149
153- setXY ( [ xy [ 0 ] - x / zoom , xy [ 1 ] - y / zoom ] ) ;
150+ setOffset ( [ offset [ 0 ] - x , offset [ 1 ] - y ] ) ;
154151 } ;
152+
155153 const onZooming : OnZoomingHandler = ( state ) => {
156154 const zoomdelta = state . delta [ 0 ] ;
157155 const zoompoint : XY = [
@@ -163,18 +161,15 @@ export function Canvas({
163161
164162 const newzoom = Math . max ( zoom + zoomdelta , MIN_ZOOM ) ;
165163 setZoom ( newzoom ) ;
166-
167- const delta = transform_by_zoom_delta ( zoomdelta , zoompoint ) ;
168- setXY ( [ xy [ 0 ] + delta [ 0 ] , xy [ 1 ] + delta [ 1 ] ] ) ;
164+ // TODO: transform offset
165+ // setOffset([offset[0], offset[1]]);
169166 } ;
170167
171168 const is_canvas_transforming = isPanning || isZooming ;
172169 const selected_nodes = selectedNodes
173170 ?. map ( ( id ) => designq . find_node_by_id_under_inpage_nodes ( id , nodes ) )
174171 . filter ( Boolean ) ;
175172
176- // console.log("selected_nodes", selected_nodes);
177-
178173 return (
179174 < >
180175 < CanvasEventTarget
@@ -198,7 +193,7 @@ export function Canvas({
198193 onPointerDown = { onPointerDown }
199194 >
200195 < HudSurface
201- offset = { xy }
196+ offset = { nonscaled_offset }
202197 zoom = { zoom }
203198 hide = { is_canvas_transforming }
204199 readonly = { readonly }
@@ -224,7 +219,7 @@ export function Canvas({
224219 renderFrameTitle = { props . renderFrameTitle }
225220 />
226221 </ CanvasEventTarget >
227- < CanvasTransformRoot scale = { zoom } xy = { xy } >
222+ < CanvasTransformRoot scale = { zoom } xy = { nonscaled_offset } >
228223 < DisableBackdropFilter >
229224 { nodes ?. map ( ( node ) => {
230225 return (
0 commit comments