mirror of
https://github.com/hectorqin/reader.git
synced 2026-11-11 05:20:54 +08:00
用户的三个问题在这里落地: 1. 「H5 是一个完整的客户端」——同一份构建产物既由服务端托管(`/` 直接 就是完整阅读器),也可被 Android 外壳打进 assets 复用,两种宿主只差 一个 serverUrl。 2. 「纯 H5 时 epub 等资源是否需要 iframe 或 shadow DOM」——用 shadow DOM, 但不是为了隔离出版方样式(那做不到也不该做:书必须能给自己排版)。 它挡的是反方向:客户端自身的 CSS 不会漏进书里。iframe 只在 PDF 那一处 用,因为 PDF 需要自己的浏览上下文,理由写在 render/container.ts 里。 3. 「Android 端 epub 用 H5 渲染,其他类型用原生」——按 kind 分流, capabilities() 明确声明:reflowable 走 WebView,paged/document 在 Android 交回原生。理由写进 reader-view.ts:WebView 每页一个合成层, 300MB 的画册在一台中端机上就是 OOM。 服务端同步配合的两处: - 资源流式下发 + HTTP Range - epub 按包内路径寻址、items/manifest 分窗 前端无框架:渲染热路径是命令式 DOM 操作,引框架只会把"最小覆盖 CSS" 的策略搞复杂;最终产物 35KB(gzip 10.7KB)。
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
/**
|
|
* Pagination logic tests.
|
|
*
|
|
* The DOM-dependent parts are covered by the layout itself; what is testable
|
|
* without a browser is the arithmetic, and that is where the position-drift bugs
|
|
* live. The `stride` and `blockAt` functions are pure, so they are tested
|
|
* directly rather than through a fake viewport that would only agree with itself.
|
|
*/
|
|
import { test, describe } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { pageFraction } from '../src/render/paginator.ts';
|
|
|
|
describe('page arithmetic', () => {
|
|
test('a single-page chapter is always at the start', () => {
|
|
// Returning 1/1 here would report a chapter as fully read the moment it is
|
|
// opened, and the reader's progress would jump to the next chapter's start.
|
|
assert.equal(pageFraction(0, 1), 0);
|
|
});
|
|
|
|
test('the first and last pages are the endpoints', () => {
|
|
assert.equal(pageFraction(0, 10), 0);
|
|
assert.equal(pageFraction(9, 10), 1);
|
|
});
|
|
|
|
test('progress never leaves [0, 1]', () => {
|
|
assert.equal(pageFraction(-1, 10), 0);
|
|
assert.equal(pageFraction(99, 10), 1);
|
|
});
|
|
|
|
test('a page count of zero does not divide by zero', () => {
|
|
assert.equal(pageFraction(0, 0), 0);
|
|
});
|
|
});
|