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
2 changes: 1 addition & 1 deletion .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Product quality
on:
pull_request:
push:
branches: [main, 'dev/**']
branches: [main]
permissions:
contents: read
concurrency:
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', '**/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'], 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', '**/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'],
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', '**/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'],
use: { ...devices['Pixel 7'], viewport: { width: 390, height: 844 }, defaultBrowserType: 'chromium', launchOptions: executablePath ? { executablePath } : {} },
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ function App() {
<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} /> : (
<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-[1.15fr_0.85fr]">
<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)]">
<div className="mb-5 text-xs font-semibold tracking-[0.2em] text-stone-500">为深度阅读,留一片空间</div>
<h1 className="text-4xl font-extrabold tracking-tight text-stone-900 sm:text-5xl" style={{ fontFamily: 'Georgia, serif' }}>页境阅读</h1>
Expand All @@ -333,7 +333,7 @@ function App() {
<li><strong className="mr-3 text-stone-800">03 对照</strong>夹住关键页,打开参考窗口并排研读</li>
</ol>
</div>
<div className="border-t border-[var(--border)] bg-[#f6f1e8] px-6 py-8 sm:px-8 md:border-t-0">
<div className="min-w-0 border-t border-[var(--border)] bg-[#f6f1e8] px-6 py-8 sm:px-8 md:border-t-0">
<div className="mb-6 flex items-baseline justify-between border-b border-[var(--border)] pb-4"><h2 className="text-xl font-semibold text-stone-900">最近打开</h2><span className="text-xs text-stone-500">{recentBooks.length} 本</span></div>
<div className="space-y-3">{recentBooks.length ? recentBooks.map((recent) => (
<button key={recent.documentId} type="button" disabled={busy} className="flex w-full items-start gap-3 border border-[var(--border)] bg-[var(--surface)] p-4 text-left transition hover:border-stone-700 disabled:opacity-50" onClick={() => { setWorkflowError(null); setDismissedError(null); closeQuickFlip(); void openRecentBook(recent.documentId); }}>
Expand Down
5 changes: 3 additions & 2 deletions src/components/reader/ReaderViewport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useBookStore } from '../../stores/bookStore';
import { useHeldStore } from '../../stores/heldStore';
import { useWindowStore } from '../../stores/windowStore';
import { useQuickFlipStore } from '../../stores/quickFlipStore';
import { pdfDecoderAssetsUrl } from '../../services/pdfDecoderAssets';
import { pdfCMapAssetsUrl, pdfDecoderAssetsUrl, pdfStandardFontAssetsUrl } from '../../services/pdfDecoderAssets';
import { useReaderGestures } from '../../hooks/useReaderGestures';
import { MousePointer2, Hand, ZoomIn, ZoomOut, ChevronLeft, ChevronRight, RotateCcw } from 'lucide-react';
import 'react-pdf/dist/Page/AnnotationLayer.css';
Expand Down Expand Up @@ -588,9 +588,10 @@ export const ReaderViewport: React.FC<Props> = ({ pageNumber, isMain = false, wi

const file = useMemo(() => documentUrl ?? null, [documentUrl]);
const options = useMemo(() => ({
cMapUrl: `https://unpkg.com/pdfjs-dist@${pdfjs.version}/cmaps/`,
cMapUrl: pdfCMapAssetsUrl(pdfjs.version),
cMapPacked: true,
wasmUrl: pdfDecoderAssetsUrl(pdfjs.version),
standardFontDataUrl: pdfStandardFontAssetsUrl(pdfjs.version),
}), []);

const modeButtonClasses = (active: boolean) =>
Expand Down
10 changes: 7 additions & 3 deletions src/services/ThumbnailService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as pdfjsLib from 'pdfjs-dist';
import { pdfDecoderAssetsUrl } from './pdfDecoderAssets';
import { pdfCMapAssetsUrl, pdfDecoderAssetsUrl, pdfStandardFontAssetsUrl } from './pdfDecoderAssets';
import { thumbnailStore } from '../stores/thumbnailStore';
import type { ThumbnailWorkerRequest, ThumbnailWorkerResponse } from './thumbnailProtocol';

Expand Down Expand Up @@ -161,7 +161,9 @@ export class ThumbnailService {
session.loading = pending;
const sourceCopy = Uint8Array.from(session.source!);
try {
worker.postMessage({ documentId: session.documentId, source: sourceCopy.buffer, wasmUrl: pdfDecoderAssetsUrl(pdfjsLib.version), type: 'load-document' } satisfies ThumbnailWorkerRequest, [sourceCopy.buffer]);
worker.postMessage({ documentId: session.documentId, source: sourceCopy.buffer,
wasmUrl: pdfDecoderAssetsUrl(pdfjsLib.version), cMapUrl: pdfCMapAssetsUrl(pdfjsLib.version),
standardFontDataUrl: pdfStandardFontAssetsUrl(pdfjsLib.version), type: 'load-document' } satisfies ThumbnailWorkerRequest, [sourceCopy.buffer]);
} catch (error) { pending.reject(error); }
return pending.promise;
}
Expand Down Expand Up @@ -245,7 +247,9 @@ export class ThumbnailService {
const session = slot.session;
if (!this.current(session)) return;
if (!slot.document) {
slot.loadingTask = pdfjsLib.getDocument({ data: Uint8Array.from(session.source!), wasmUrl: pdfDecoderAssetsUrl(pdfjsLib.version), isEvalSupported: false, useWorkerFetch: false });
slot.loadingTask = pdfjsLib.getDocument({ data: Uint8Array.from(session.source!), wasmUrl: pdfDecoderAssetsUrl(pdfjsLib.version),
cMapUrl: pdfCMapAssetsUrl(pdfjsLib.version), cMapPacked: true, standardFontDataUrl: pdfStandardFontAssetsUrl(pdfjsLib.version),
isEvalSupported: false, useWorkerFetch: false });
try { slot.document = await slot.loadingTask.promise; }
catch (error) {
try { await this.disposeFallback(slot); }
Expand Down
8 changes: 8 additions & 0 deletions src/services/pdfDecoderAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
export function pdfDecoderAssetsUrl(version: string, base = import.meta.env.BASE_URL, documentUrl = document.baseURI): string {
return new URL(`pdfjs/${version}/wasm/`, new URL(base || '/', documentUrl)).href;
}

export function pdfCMapAssetsUrl(version: string, base = import.meta.env.BASE_URL, documentUrl = document.baseURI): string {
return new URL(`pdfjs/${version}/cmaps/`, new URL(base || '/', documentUrl)).href;
}

export function pdfStandardFontAssetsUrl(version: string, base = import.meta.env.BASE_URL, documentUrl = document.baseURI): string {
return new URL(`pdfjs/${version}/standard_fonts/`, new URL(base || '/', documentUrl)).href;
}
34 changes: 34 additions & 0 deletions src/services/pdfFontSupport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { OPS, type PDFPageProxy } from 'pdfjs-dist';

/**
* PDF.js 5.4 exposes resolved display fonts through PDFPageProxy.commonObjs.
* A worker cannot safely draw system-font-dependent glyphs. Font loading errors
* may resolve as strings instead of rejecting render(), so check both cases.
* Keep this small adapter covered when upgrading PDF.js; data is deliberately
* NOT inspected because FontLoader clears embedded bytes after binding.
*/
export async function assertPdfFontSupport(page: PDFPageProxy): Promise<void> {
const operators = await page.getOperatorList(), fonts = new Set<string>(), dependencies = new Set<string>();
for (let index = 0; index < operators.fnArray.length; index++) {
const args: unknown[] = operators.argsArray[index];
// PDF.js propagates dependencies from tiling patterns and Type3 glyphs to
// this list. CanvasGraphics uses this same prefix for commonObjs; page-local
// image IDs must not be awaited there. Shared images are not font objects.
if (operators.fnArray[index] === OPS.dependency) {
for (const name of args) if (typeof name === 'string' && name.startsWith('g_')) dependencies.add(name);
}
if (operators.fnArray[index] === OPS.setFont && typeof args[0] === 'string') fonts.add(args[0]);
if (operators.fnArray[index] === OPS.setGState && Array.isArray(args[0])) {
for (const entry of args[0]) {
if (Array.isArray(entry) && entry[0] === 'Font' && Array.isArray(entry[1]) && typeof entry[1][0] === 'string') fonts.add(entry[1][0]);
}
}
}
for (const name of new Set([...fonts, ...dependencies])) {
const font: unknown = await new Promise(resolve => page.commonObjs.get(name, resolve));
if (typeof font === 'string' || (fonts.has(name) && (!font || typeof font !== 'object'))) throw new Error('PDF font could not be loaded');
if (font && typeof font === 'object' && 'missingFile' in font && font.missingFile === true) {
throw new Error('PDF font requires the main-thread font renderer');
}
}
}
2 changes: 2 additions & 0 deletions src/services/thumbnailProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export interface ThumbnailLoadDocumentRequest {
documentId: string;
source: ArrayBuffer;
wasmUrl: string;
cMapUrl: string;
standardFontDataUrl: string;
}

export interface ThumbnailRenderRequest {
Expand Down
Loading
Loading