feat(stammbaum): convert pointer pixel delta to SVG units (#692)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -61,3 +61,23 @@ export function parsePanZoomParams(raw: {
|
||||
export function serializePanZoomParams(state: PanZoomState): { cx: string; cy: string; z: string } {
|
||||
return { cx: String(state.x), cy: String(state.y), z: String(state.z) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a pointer delta in CSS pixels into SVG user units, using the current
|
||||
* viewBox-to-element ratio per axis. This is the distance the pointer traversed
|
||||
* expressed in the tree's coordinate space; the gesture handler subtracts it
|
||||
* from the pan offset so the canvas follows the finger (US-PAN-001).
|
||||
*/
|
||||
export function screenDeltaToSvg(
|
||||
dxPx: number,
|
||||
dyPx: number,
|
||||
viewBoxW: number,
|
||||
viewBoxH: number,
|
||||
elPxW: number,
|
||||
elPxH: number
|
||||
): { dx: number; dy: number } {
|
||||
return {
|
||||
dx: elPxW > 0 ? dxPx * (viewBoxW / elPxW) : 0,
|
||||
dy: elPxH > 0 ? dyPx * (viewBoxH / elPxH) : 0
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user