PDF Web Viewer
    Preparing search index...

    Interface IRecentsConfig

    Persistence for the recent-documents history — the only part of it the host owns.

    The viewer keeps the list itself: it records each open, orders and de-duplicates the entries, caps their number and empties them on "Clear all". Without this config all of that still works, but only until the page is reloaded. Implement getRecents + setRecents and the history survives, in whatever storage you like.

    The "Recents" tab appears whenever at least one readable source is configured, independently of this config; hide it with layoutConfig.chooseFile.recents: false.

    recentsConfig: {
    getRecents: () => JSON.parse(localStorage.getItem('recents') ?? '[]'),
    setRecents: (entries) => {
    localStorage.setItem('recents', JSON.stringify(entries));
    // Previews outlive their entries unless the same write prunes them.
    const live = new Set(entries.map((entry) => `thumb:${entry.key}`));
    Object.keys(localStorage)
    .filter((stored) => stored.startsWith('thumb:') && !live.has(stored))
    .forEach((orphan) => localStorage.removeItem(orphan));
    },
    }
    interface IRecentsConfig {
        getRecents?: () => IRecentEntry[] | Promise<IRecentEntry[]>;
        getRecentThumbnail?: (key: string) => Promise<string | Blob>;
        maxRecents?: number;
        setRecents?: (entries: IRecentEntry[]) => void | Promise<void>;
        setRecentThumbnail?: (key: string, thumbnail: Blob) => void | Promise<void>;
    }
    Index

    Properties

    getRecents?: () => IRecentEntry[] | Promise<IRecentEntry[]>

    Restores the stored history. Called once, when the viewer starts.

    getRecentThumbnail?: (key: string) => Promise<string | Blob>

    Restores a stored page-one preview, as an image Blob, a URL / data-URL string, or null when there is none. key is the opaque id the viewer passed to IRecentsConfig.setRecentThumbnail.

    Kept apart from the list on purpose: the list is small metadata rewritten on every open, a preview is a one-off blob better kept out of it (and out of localStorage). Omit both callbacks and previews simply last for the session.

    maxRecents?: number

    How many entries to keep. Defaults to 20.

    setRecents?: (entries: IRecentEntry[]) => void | Promise<void>

    Stores the history, newest first — called after every change (open, save elsewhere, clear).

    setRecentThumbnail?: (key: string, thumbnail: Blob) => void | Promise<void>

    Stores the page-one preview the viewer rendered for an entry, under that entry's IRecentEntry.key.

    Deleting them is yours as well, because only you know where they went — and it needs no extra callback: every IRecentsConfig.setRecents call carries the whole list, so dropping every stored preview whose key is not in it prunes the entries that were removed, cleared or pushed off the end of the list. Doing it there also collects anything orphaned by an earlier crash, which a "preview removed" notification never would.