Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ jobs:
- run: npm run test:ui
browser-tests:
runs-on: ubuntu-latest
timeout-minutes: 20
# The single-worker WebKit matrix includes mobile and stability repeats.
# Keep every check and per-test deadline while allowing normal runner variance.
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ npm run test:e2e
- 浮窗拖动、缩放和分栏调整在失焦、切换标签页或松开鼠标时结束;拖动中按 Esc 只取消本次拖动,不关闭窗口
- 最多新建 4 个参考窗口。可选择并排或平铺 2–5 页;手机通过「打开的页面」切换主视角与参考页
- 速翻、目录、底部时间轴和页码输入跟随当前活动窗口。页码输入按 Enter 确认,Esc 取消
- PDF 内部页码链接在点击所在的阅读窗口跳转;较慢的链接解析不会覆盖之后的翻页、同页选择或速翻操作。无法解析的链接会在原窗口提示,按 Esc 可关闭提示
- PDF 内部链接在原阅读窗口打开目标页,保留其他窗口的位置和缩放;用 Enter 跳到其他页后,可继续用方向键翻页。链接解析期间若已把焦点移到工具栏或其他窗口,不会把焦点抢回
- 最多新增到 12 张夹页,可通过上下移动按钮调整顺序;移除正在对照的夹页时可选择是否保留窗口
- 点击左上角 LeafSpace 回到书库。切换书籍、回到书库前,会先保存当前现场
- 页码、缩放、夹页与窗口布局在操作停止后自动保存;切到后台时会尽早尝试保存待存更改。只有真正保存完成才显示「已保存到本机」。存储失败或上次现场未恢复时仍需明确重试,后台保存不能保证在系统结束进程前完成
Expand Down
6 changes: 3 additions & 3 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export default defineConfig({
},
{ name: 'firefox', testIgnore: '**/native-touch.test.ts', use: { ...devices['Desktop Firefox'], viewport: { width: 1440, height: 900 } } },
{ name: 'webkit', testIgnore: '**/native-touch.test.ts', use: { ...devices['Desktop Safari'], viewport: { width: 1440, height: 900 } } },
{ name: 'mobile-webkit', testMatch: ['**/gesture-contract.test.ts', '**/site-icons.test.ts', '**/storage-recovery.test.ts', '**/held-read-intent.test.ts', '**/thumbnail-actions.test.ts', '**/fit-width.test.ts', '**/password-recovery.test.ts', '**/hidden-save.test.ts', '**/recovery-access.test.ts', '**/reader-activation.test.ts', '**/mixed-pages.test.ts', '**/pdf-decoders.test.ts', '**/pdf-fonts.test.ts', '**/render-recovery.test.ts'], use: { ...devices['iPhone 13'] } },
{ name: 'mobile-webkit', testMatch: ['**/gesture-contract.test.ts', '**/site-icons.test.ts', '**/storage-recovery.test.ts', '**/held-read-intent.test.ts', '**/thumbnail-actions.test.ts', '**/fit-width.test.ts', '**/password-recovery.test.ts', '**/hidden-save.test.ts', '**/recovery-access.test.ts', '**/reader-activation.test.ts', '**/mixed-pages.test.ts', '**/pdf-decoders.test.ts', '**/pdf-fonts.test.ts', '**/render-recovery.test.ts', '**/pdf-links.test.ts'], use: { ...devices['iPhone 13'] } },
{
name: 'tablet',
testMatch: ['**/responsive.test.ts', '**/native-touch.test.ts', '**/gesture-contract.test.ts', '**/site-icons.test.ts', '**/storage-recovery.test.ts', '**/held-read-intent.test.ts', '**/thumbnail-actions.test.ts', '**/fit-width.test.ts', '**/password-recovery.test.ts', '**/hidden-save.test.ts', '**/recovery-access.test.ts', '**/reader-activation.test.ts', '**/mixed-pages.test.ts', '**/pdf-decoders.test.ts', '**/pdf-fonts.test.ts', '**/render-recovery.test.ts'],
testMatch: ['**/responsive.test.ts', '**/native-touch.test.ts', '**/gesture-contract.test.ts', '**/site-icons.test.ts', '**/storage-recovery.test.ts', '**/held-read-intent.test.ts', '**/thumbnail-actions.test.ts', '**/fit-width.test.ts', '**/password-recovery.test.ts', '**/hidden-save.test.ts', '**/recovery-access.test.ts', '**/reader-activation.test.ts', '**/mixed-pages.test.ts', '**/pdf-decoders.test.ts', '**/pdf-fonts.test.ts', '**/render-recovery.test.ts', '**/pdf-links.test.ts'],
use: { ...devices['Desktop Chrome'], viewport: { width: 768, height: 1024 }, hasTouch: true, launchOptions: executablePath ? { executablePath } : {} },
},
{
name: 'mobile',
testMatch: ['**/responsive.test.ts', '**/native-touch.test.ts', '**/gesture-contract.test.ts', '**/site-icons.test.ts', '**/storage-recovery.test.ts', '**/held-read-intent.test.ts', '**/thumbnail-actions.test.ts', '**/fit-width.test.ts', '**/password-recovery.test.ts', '**/hidden-save.test.ts', '**/recovery-access.test.ts', '**/reader-activation.test.ts', '**/mixed-pages.test.ts', '**/pdf-decoders.test.ts', '**/pdf-fonts.test.ts', '**/render-recovery.test.ts'],
testMatch: ['**/responsive.test.ts', '**/native-touch.test.ts', '**/gesture-contract.test.ts', '**/site-icons.test.ts', '**/storage-recovery.test.ts', '**/held-read-intent.test.ts', '**/thumbnail-actions.test.ts', '**/fit-width.test.ts', '**/password-recovery.test.ts', '**/hidden-save.test.ts', '**/recovery-access.test.ts', '**/reader-activation.test.ts', '**/mixed-pages.test.ts', '**/pdf-decoders.test.ts', '**/pdf-fonts.test.ts', '**/render-recovery.test.ts', '**/pdf-links.test.ts'],
use: { ...devices['Pixel 7'], viewport: { width: 390, height: 844 }, defaultBrowserType: 'chromium', launchOptions: executablePath ? { executablePath } : {} },
},
],
Expand Down
19 changes: 15 additions & 4 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useUnsavedExitGuard } from '../hooks/useUnsavedExitGuard';
import { useWorkspaceAutoSave } from '../hooks/useWorkspaceAutoSave';
import { PDFPasswordRequiredError } from '../services/PDFService';
import { prepareHeldRead } from '../services/HeldReadTransaction';
import { notifyReaderNavigation } from '../services/readerNavigationIntent';
import { useThumbnailActions } from '../hooks/useThumbnailActions';
import { ThumbnailActionDialog } from '../components/thumbnails/ThumbnailActionDialog';

Expand All @@ -25,8 +26,10 @@ function isCurrentWorkspaceSaved(documentId: string | null) {
&& JSON.stringify(snapshot.windows) === JSON.stringify(windows);
}

const solidButton = 'inline-flex min-h-10 items-center justify-center gap-2 border border-stone-900 bg-stone-900 px-4 py-2 text-sm font-semibold text-white transition hover:bg-stone-700 disabled:cursor-not-allowed disabled:opacity-50';
const outlineButton = 'inline-flex min-h-10 items-center justify-center gap-2 border border-[var(--border)] px-3 py-2 text-sm font-medium text-stone-700 transition hover:border-stone-700 hover:bg-stone-100 disabled:cursor-not-allowed disabled:opacity-50';
// Disabled controls may be muted, but re-enabled text must regain its full
// contrast immediately instead of fading through a readable-but-low-contrast state.
const solidButton = 'inline-flex min-h-10 items-center justify-center gap-2 border border-stone-900 bg-stone-900 px-4 py-2 text-sm font-semibold text-white transition-colors hover:bg-stone-700 disabled:cursor-not-allowed disabled:opacity-50';
const outlineButton = 'inline-flex min-h-10 items-center justify-center gap-2 border border-[var(--border)] px-3 py-2 text-sm font-medium text-stone-700 transition-colors hover:border-stone-700 hover:bg-stone-100 disabled:cursor-not-allowed disabled:opacity-50';

function App() {
const book = useBookStore();
Expand Down Expand Up @@ -318,7 +321,15 @@ function App() {
{(windowNotice || heldNotice) && <div role="status" className="flex shrink-0 items-center justify-between gap-3 border-b border-amber-200 bg-amber-50 px-4 py-2 text-sm text-amber-950"><span>{windowNotice || heldNotice}</span><button aria-label="关闭操作提示" className="p-2" onClick={() => { clearWindowNotice(); useHeldStore.getState().clearNotice(); }}><X size={16} /></button></div>}
<main inert={busy} className="relative flex min-h-0 min-w-0 flex-1 overflow-hidden">
<section inert={showHeldPages} className="flex min-h-0 min-w-0 flex-1 flex-col bg-[#edece9]">
{documentId ? <WorkspaceCanvas subscribeInterruption={thumbnailActions.controller.onInterrupt} windows={windows} onWindowUpdate={(win) => { updateWindow(win.id, win); if (win.isActive) setActiveWindow(win.id); }} onWindowClose={closeReferenceWindow} /> : (
{documentId ? <WorkspaceCanvas subscribeInterruption={thumbnailActions.controller.onInterrupt} windows={windows} onWindowUpdate={(win) => {
// Canvas callbacks carry the full window for layout operations.
// Do not turn a raise/drag/resize into a new page choice or replay
// a stale paper viewport while applying that geometry.
updateWindow(win.id, { x: win.x, y: win.y, width: win.width, height: win.height,
type: win.type, dockMode: win.dockMode, splitRatio: win.splitRatio,
zIndex: win.zIndex, isActive: win.isActive });
if (win.isActive) setActiveWindow(win.id);
}} onWindowClose={closeReferenceWindow} /> : (
<div className="flex min-h-0 flex-1 overflow-y-auto bg-[var(--surface)] p-4 sm:p-8 lg:items-center lg:justify-center">
<div className="m-auto grid w-full max-w-[1080px] grid-cols-1 border border-[var(--border)] bg-[var(--surface)] shadow-[0_24px_70px_rgba(28,25,23,0.05)] md:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]">
<div className="px-6 py-9 sm:px-10 sm:py-12 md:border-r md:border-[var(--border)]">
Expand Down Expand Up @@ -363,7 +374,7 @@ function App() {
}} onPageClick={(page) => { openInNewWindow(page.pageNumber); closeHeldPanel(); }} onRemovePage={(id, closeReferences) => { const page = heldPages.find((candidate) => candidate.id === id); if (page) { if (closeReferences) useWindowStore.getState().closeWindowsForPage(page.pageNumber); unholdPage(page.pageNumber); } }} />
</aside>}
</main>
{documentId && <footer inert={busy} className="h-16 shrink-0 border-t border-[var(--border)]"><TimelineBar key={`${documentId}:${activeWindowId}:${isQuickFlipVisible}:${showHeldPages}:${busy}:${thumbnailActions.isOpen}`} currentPage={activePage} chapters={book.toc} totalPages={totalPages} onPageClick={jumpToPage} markers={heldPages.map((page) => page.pageNumber)} /></footer>}
{documentId && <footer inert={busy} className="h-16 shrink-0 border-t border-[var(--border)]"><TimelineBar key={`${documentId}:${activeWindowId}:${isQuickFlipVisible}:${showHeldPages}:${busy}:${thumbnailActions.isOpen}`} currentPage={activePage} chapters={book.toc} totalPages={totalPages} onPageClick={jumpToPage} onPreviewStart={() => notifyReaderNavigation(useWindowStore.getState().activeWindowId ?? 'main')} markers={heldPages.map((page) => page.pageNumber)} /></footer>}
</div>
{isQuickFlipVisible && ready && <QuickFlipOverlay thumbnailActions={thumbnailActions.controller} interactionSuspended={thumbnailActions.isOpen} isVisible restoreFocusOnClose={false} onClose={dismissQuickFlip} currentPage={quickFlipOrigin.current.page} totalPages={totalPages} onPageChange={page => { updateWindow(quickFlipOrigin.current.windowId, { pageNumber: page }); setActiveWindow(quickFlipOrigin.current.windowId); }} />}
{thumbnailActions.request && <ThumbnailActionDialog controller={thumbnailActions.controller} request={thumbnailActions.request} awaitingRelease={thumbnailActions.awaitingRelease} />}
Expand Down
32 changes: 29 additions & 3 deletions src/components/reader/ReaderViewport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useWindowStore } from '../../stores/windowStore';
import { useQuickFlipStore } from '../../stores/quickFlipStore';
import { pdfCMapAssetsUrl, pdfDecoderAssetsUrl, pdfStandardFontAssetsUrl } from '../../services/pdfDecoderAssets';
import { useReaderGestures } from '../../hooks/useReaderGestures';
import { usePdfLinkNavigation } from '../../hooks/usePdfLinkNavigation';
import { MousePointer2, Hand, ZoomIn, ZoomOut, ChevronLeft, ChevronRight, RotateCcw } from 'lucide-react';
import 'react-pdf/dist/Page/AnnotationLayer.css';
import 'react-pdf/dist/Page/TextLayer.css';
Expand Down Expand Up @@ -71,6 +72,7 @@ export const ReaderViewport: React.FC<Props> = ({ pageNumber, isMain = false, wi

const containerRef = useRef<HTMLDivElement>(null);
const contentFrameRef = useRef<HTMLDivElement>(null);
const pageElementRef = useRef<HTMLDivElement>(null);
const [isPanning, setIsPanning] = useState(false);
const panGestureActive = useRef(false);
const [shouldCenterHorizontally, setShouldCenterHorizontally] = useState(true);
Expand All @@ -93,6 +95,9 @@ export const ReaderViewport: React.FC<Props> = ({ pageNumber, isMain = false, wi
renderGeneration.current += 1;
};
}, []);
const pdfLinks = usePdfLinkNavigation({ sessionId, documentUrl, windowId: windowId ?? 'main',
pageNumber: activePage, attempt: retryAttempt, containerRef, pageRef: pageElementRef });
const cancelPdfLinks = pdfLinks.cancel;
const [renderFeedback, setRenderFeedback] = useState<RenderFeedback>(null);
const showRenderFailure = renderFeedback?.kind === 'failed' && renderFeedback.token === renderToken;
const showRenderRetry = renderFeedback?.kind === 'retrying' && renderFeedback.context === renderContext && renderFeedback.attempt === retryAttempt;
Expand Down Expand Up @@ -381,13 +386,14 @@ export const ReaderViewport: React.FC<Props> = ({ pageNumber, isMain = false, wi
if (zoomCorrectionFrame.current !== null) window.cancelAnimationFrame(zoomCorrectionFrame.current);
zoomCorrectionFrame.current = null;
renderReady.current = false;
cancelPdfLinks();
const attempt = ++requestedAttempt.current;
// Supersede old callbacks now, not only after React commits the new Page.
currentRenderToken.current = null;
containerRef.current?.focus({ preventScroll: true });
setRenderFeedback({ kind: 'retrying', context: renderContext, attempt });
setRetryAttempt(attempt);
}, [cancelPanning, cancelZoom, captureScrollIntent, renderContext, renderFeedback]);
}, [cancelPanning, cancelPdfLinks, cancelZoom, captureScrollIntent, renderContext, renderFeedback]);

useEffect(() => {
const container = containerRef.current;
Expand Down Expand Up @@ -618,7 +624,7 @@ export const ReaderViewport: React.FC<Props> = ({ pageNumber, isMain = false, wi
if (quickFlipVisible || activeWindowId !== (windowId ?? 'main')) cancelZoom();
}, [activeWindowId, cancelZoom, quickFlipVisible, windowId]);

useReaderGestures({
const readerGestures = useReaderGestures({
containerRef, frameRef: contentFrameRef, scale, canSwipe: mode === 'grab', isActive: activeWindowId === (windowId ?? 'main'),
contextKey: `${sessionId}:${windowId}:${documentUrl}:${activePage}:${retryAttempt}:${quickFlipVisible}:${scale}:${mode}`,
onActivate: () => { cancelZoom(); handleViewportFocus(); },
Expand Down Expand Up @@ -672,7 +678,12 @@ export const ReaderViewport: React.FC<Props> = ({ pageNumber, isMain = false, wi
}, [activePage, holdPage, totalPages, updateActivePage]);

return (
<div data-reader-shell className="flex h-full min-h-0 min-w-0 flex-col overflow-hidden bg-[var(--surface)]" onFocusCapture={handleViewportFocus} onPointerDownCapture={handleViewportFocus}>
<div data-reader-shell className="flex h-full min-h-0 min-w-0 flex-col overflow-hidden bg-[var(--surface)]" onFocusCapture={handleViewportFocus} onPointerDownCapture={handleViewportFocus}
onKeyDown={event => {
if (event.key !== 'Escape' || event.defaultPrevented || !pdfLinks.notice || showRenderFailure || showRenderRetry) return;
event.preventDefault(); event.stopPropagation();
pdfLinks.cancel(); containerRef.current?.focus({ preventScroll: true });
}}>
<div className="flex min-h-11 shrink-0 flex-wrap items-center justify-between gap-2 border-b border-[var(--border)] bg-[var(--surface)] px-2 py-1 sm:px-4">
<div className="flex items-center gap-3">
<div className="flex bg-[#f0ede9] p-[2px]">
Expand Down Expand Up @@ -706,6 +717,7 @@ export const ReaderViewport: React.FC<Props> = ({ pageNumber, isMain = false, wi
role="region"
aria-label={isMain ? '主阅读区' : `参考阅读区,第 ${activePage} 页`}
className={`flex min-h-0 min-w-0 flex-1 overflow-auto bg-[#edece9] ${mode === 'grab' ? 'select-none' : 'select-text'}`}
onClickCapture={event => { if (!readerGestures.suppressClick(event)) pdfLinks.onClickCapture(event); }}
onMouseDown={handleMouseDown}
onMouseMove={handleMouseMove}
onMouseUp={stopPanning}
Expand All @@ -723,20 +735,24 @@ export const ReaderViewport: React.FC<Props> = ({ pageNumber, isMain = false, wi
style={paperRatio ? { width: Math.floor(pageWidth * scale) + 2, height: Math.floor(pageWidth * scale * paperRatio) + 2 } : undefined}>
{file ? (
<Document
key={pdfLinks.documentKey}
file={file}
options={options}
onLoadSuccess={pdfLinks.onDocumentLoad}
error={<div role="alert" className="max-w-xs p-6 text-sm text-red-800">页面暂时无法显示,请重新导入这本 PDF。</div>}
loading={<div role="status" className="mt-24 text-sm italic text-stone-500" style={{ fontFamily: 'Georgia, Times New Roman, serif' }}>正在渲染...</div>}
>
<Page
key={`${sessionId}:${windowId ?? 'main'}:${retryAttempt}`}
inputRef={pageElementRef}
canvasRef={initializeCanvas}
pageNumber={activePage}
width={pageWidth}
scale={scale}
className="border border-[#e0ddd5] bg-white shadow-[0_1px_4px_rgba(0,0,0,0.05),0_30px_100px_rgba(0,0,0,0.1)]"
renderTextLayer={true}
onLoadSuccess={handlePageLoad}
onGetAnnotationsSuccess={pdfLinks.onAnnotations}
onRenderSuccess={handleRenderSuccess}
onRenderError={handleRenderError}
loading={<div role="status" className="p-6 text-sm text-stone-500">正在渲染页面…</div>}
Expand All @@ -749,6 +765,16 @@ export const ReaderViewport: React.FC<Props> = ({ pageNumber, isMain = false, wi
</div>
</div>
</div>
{pdfLinks.notice && !showRenderFailure && !showRenderRetry && (
<div className="pointer-events-none absolute inset-x-3 bottom-3 z-10 flex justify-center">
<div role="alert" className="pointer-events-auto flex max-w-md items-center gap-3 border border-[var(--border)] bg-[var(--surface)] p-3 text-sm text-stone-800 shadow-sm">
<p>无法打开此链接。可尝试目录或页码导航。</p>
<button type="button" aria-label="关闭链接提示" className="min-h-10 shrink-0 px-2 text-stone-700 hover:bg-stone-100" onClick={() => {
containerRef.current?.focus({ preventScroll: true }); pdfLinks.cancel();
}}>关闭</button>
</div>
</div>
)}
{(showRenderFailure || showRenderRetry) && (
<div className="pointer-events-none absolute inset-0 z-10 flex items-center justify-center p-3">
<div role={showRenderFailure ? 'alert' : 'status'} className="pointer-events-auto max-h-full min-h-0 w-full max-w-sm overflow-auto border border-[var(--border)] bg-[var(--surface)] p-4 text-sm text-stone-800 shadow-sm">
Expand Down
Loading
Loading