fix: 修复长文档分页与滚动同步

This commit is contained in:
SkyJourney
2026-07-26 08:43:56 +08:00
parent 1d93f31f85
commit d62552384f
15 changed files with 449 additions and 61 deletions
+24
View File
@@ -0,0 +1,24 @@
import { describe, expect, it } from "vitest";
import { getNearestPageNumber } from "../src/preview-page";
const pages = [
{ top: 0, bottom: 100 },
{ top: 124, bottom: 224 },
{ top: 248, bottom: 348 }
];
describe("getNearestPageNumber", () => {
it("返回视口中心所在的页面", () => {
expect(getNearestPageNumber(180, pages)).toBe(2);
});
it("在页间空隙中返回距离最近的页面", () => {
expect(getNearestPageNumber(110, pages)).toBe(1);
expect(getNearestPageNumber(116, pages)).toBe(2);
});
it("没有页面或中心坐标无效时返回 0", () => {
expect(getNearestPageNumber(20, [])).toBe(0);
expect(getNearestPageNumber(Number.NaN, pages)).toBe(0);
});
});