From d164d6f495227232946a63f6efb4d14ff81bf67b Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sun, 24 May 2026 19:59:52 -0400 Subject: [PATCH] export overridable config.pdfjsPath for bundled usage --- pdf.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pdf.js b/pdf.js index a27385c..6a5cd6f 100644 --- a/pdf.js +++ b/pdf.js @@ -1,20 +1,22 @@ -const pdfjsPath = (path) => +const _defaultPdfjsPath = (path) => new URL(`./vendor/pdfjs/${path}`, import.meta.url).toString(); +export const config = { + pdfjsPath: _defaultPdfjsPath, +}; + import "./vendor/pdfjs/pdf.mjs"; const pdfjsLib = globalThis.pdfjsLib; -pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsPath("pdf.worker.mjs"); +pdfjsLib.GlobalWorkerOptions.workerSrc = _defaultPdfjsPath("pdf.worker.mjs"); const fetchText = async (url) => await (await fetch(url)).text(); -// https://raw.githubusercontent.com/mozilla/pdf.js/refs/tags/v5.5.207/web/text_layer_builder.css const textLayerBuilderCSS = await fetchText( - pdfjsPath("text_layer_builder.css"), + _defaultPdfjsPath("text_layer_builder.css"), ); -// https://raw.githubusercontent.com/mozilla/pdf.js/refs/tags/v5.5.207/web/annotation_layer_builder.css const annotationLayerBuilderCSS = await fetchText( - pdfjsPath("annotation_layer_builder.css"), + _defaultPdfjsPath("annotation_layer_builder.css"), ); const render = async (page, doc, zoom) => { @@ -130,8 +132,8 @@ const makeTOCItem = (item) => ({ }); export const makePDF = async (file, options = {}) => { - const cMapUrl = options.cMapUrl ?? pdfjsPath("cmaps/"); - const standardFontDataUrl = options.standardFontDataUrl ?? pdfjsPath("standard_fonts/"); + const cMapUrl = options.cMapUrl ?? config.pdfjsPath("cmaps/"); + const standardFontDataUrl = options.standardFontDataUrl ?? config.pdfjsPath("standard_fonts/"); if (options.workerSrc) { pdfjsLib.GlobalWorkerOptions.workerSrc = options.workerSrc; }