fix(editor): connector target position NaN (#11606)

Close [BS-3086](https://linear.app/affine-design/issue/BS-3086/frame里套frame,连一下connector,拖两下,白板损坏)

### What Changes
- Fixed `bound.toRelative` may be return `NaN` when `bound.w === 0 || bound.h ===0`
- Remove type assertions from `connector-manager.ts` for more type safety
This commit is contained in:
L-Sun
2025-04-10 12:33:24 +00:00
parent d5aebc1421
commit 588659ef67
5 changed files with 109 additions and 59 deletions
@@ -341,8 +341,15 @@ export class Bound implements IBound {
return serializeXYWH(this.x, this.y, this.w, this.h);
}
/**
* Convert a point to relative coordinates.
* @param point - The point to convert.
* @returns The normalized relative coordinates of the point.
*/
toRelative([x, y]: IVec): IVec {
return [(x - this.x) / this.w, (y - this.y) / this.h];
const normalizedX = this.w === 0 ? 0 : (x - this.x) / this.w;
const normalizedY = this.h === 0 ? 0 : (y - this.y) / this.h;
return [normalizedX, normalizedY];
}
toXYWH(): XYWH {
@@ -565,6 +565,8 @@ export class Vec {
* @param n
* @param min
*/
static clampV(A: IVec, min: number, max?: number): IVec;
static clampV(A: number[], min: number): number[];
// eslint-disable-next-line @typescript-eslint/unified-signatures