fix(editor): loupe copy without ids, two fingers counted in the pinch
Minor 1: the loupe's copy of the drawing drops every id (the equine drawing has 142); its url(#…) and href="#…" resolve to the originals. Minor 2: useFraming's onPinch marks the two-finger flag at the pinch move itself; the passive effect that read the live press phase and the press hook's multi() are removed.
This commit is contained in:
1 parent
181f81789a
commit
dd3f245bca
5 files changed
+59
-33
No files matched your search
@@ -35,6 +35,8 @@ export interface FramingOptions {
|
||||
* follows the fingers' spread since the pinch began (a clamp at the fit never ratchets).
|
||||
*/
|
||||
twoPointerPan?: boolean
|
||||
/** A two-pointer move changed the framing: told at the move itself, never later. */
|
||||
onPinch?: () => void
|
||||
}
|
||||
|
||||
/** Where a pinch began: its spread and the scale then. */
|
||||
@@ -59,6 +61,9 @@ function distance(a: Point, b: Point): number {
|
||||
return Math.hypot(a.x - b.x, a.y - b.y)
|
||||
}
|
||||
|
||||
const sameFraming = (a: Framing, b: Framing) =>
|
||||
a.scale === b.scale && a.x === b.x && a.y === b.y
|
||||
|
||||
const midpoint = (a: Point, b: Point, box: { left: number; top: number }) => ({
|
||||
x: (a.x + b.x) / 2 - box.left,
|
||||
y: (a.y + b.y) / 2 - box.top,
|
||||
@@ -131,6 +136,11 @@ export function useFraming(
|
||||
const twoPointerPan = useRef(options.twoPointerPan ?? false)
|
||||
twoPointerPan.current = options.twoPointerPan ?? false
|
||||
const pinch = useRef<PinchStart | null>(null)
|
||||
const onPinch = useRef(options.onPinch)
|
||||
onPinch.current = options.onPinch
|
||||
// The framing as last rendered: a pinch move compares its result with it.
|
||||
const shown = useRef(framing)
|
||||
shown.current = framing
|
||||
|
||||
useEffect(() => setFraming(FIT), [resetKey])
|
||||
useEffect(() => {
|
||||
@@ -186,6 +196,8 @@ export function useFraming(
|
||||
const box = boxOf(viewport.current)
|
||||
const start = pinch.current
|
||||
if (twoPointerPan.current && start) {
|
||||
const next = pinchPan(shown.current, start, fingers, box)
|
||||
if (!sameFraming(next, shown.current)) onPinch.current?.()
|
||||
setFraming((f) => pinchPan(f, start, fingers, box))
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user