| 336 | } |
| 337 | |
| 338 | function detectGeometryShift(frames: SwitchFrameSample[]) { |
| 339 | const anchorIndex = frames.findIndex((frame) => frame.containsTargetMarker); |
| 340 | if (anchorIndex === -1) return []; |
| 341 | const anchor = frames[anchorIndex]; |
| 342 | const props: Array< |
| 343 | keyof Pick< |
| 344 | SwitchFrameSample, |
| 345 | "messageWindowTop" | "messageWindowHeight" | "scrollTop" | "chatInputHeight" |
| 346 | > |
| 347 | > = ["messageWindowTop", "messageWindowHeight", "scrollTop", "chatInputHeight"]; |
| 348 | const shifts = [] as Array<{ frame: number; property: string; delta: number }>; |
| 349 | for (const frame of frames.slice(anchorIndex + 1)) { |
| 350 | if (!frame.containsTargetMarker) continue; |
| 351 | for (const prop of props) { |
| 352 | const a = anchor[prop]; |
| 353 | const b = frame[prop]; |
| 354 | if (a == null || b == null) continue; |
| 355 | const delta = b - a; |
| 356 | if (Math.abs(delta) > 1) shifts.push({ frame: frame.frame, property: prop, delta }); |
| 357 | } |
| 358 | } |
| 359 | return shifts; |
| 360 | } |
| 361 | |
| 362 | async function computeDiffRatio(leftPng: Buffer, rightPng: Buffer): Promise<number> { |
| 363 | const [left, right] = await Promise.all([ |