Merge pull request #14870 from Snuffleupagus/isNodeJS-cleanup
Only bundle the `src/display/node_utils.js` file in GENERIC-builds
This commit is contained in:
commit
899e4d58d6
@ -49,11 +49,6 @@ import {
|
||||
StatTimer,
|
||||
} from "./display_utils.js";
|
||||
import { FontFaceObject, FontLoader } from "./font_loader.js";
|
||||
import {
|
||||
NodeCanvasFactory,
|
||||
NodeCMapReaderFactory,
|
||||
NodeStandardFontDataFactory,
|
||||
} from "./node_utils.js";
|
||||
import { AnnotationStorage } from "./annotation_storage.js";
|
||||
import { CanvasGraphics } from "./canvas.js";
|
||||
import { GlobalWorkerOptions } from "./worker_options.js";
|
||||
@ -67,18 +62,21 @@ import { XfaText } from "./xfa_text.js";
|
||||
const DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
|
||||
const RENDERING_CANCELLED_TIMEOUT = 100; // ms
|
||||
|
||||
const DefaultCanvasFactory =
|
||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS
|
||||
? NodeCanvasFactory
|
||||
: DOMCanvasFactory;
|
||||
const DefaultCMapReaderFactory =
|
||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS
|
||||
? NodeCMapReaderFactory
|
||||
: DOMCMapReaderFactory;
|
||||
const DefaultStandardFontDataFactory =
|
||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS
|
||||
? NodeStandardFontDataFactory
|
||||
: DOMStandardFontDataFactory;
|
||||
let DefaultCanvasFactory = DOMCanvasFactory;
|
||||
let DefaultCMapReaderFactory = DOMCMapReaderFactory;
|
||||
let DefaultStandardFontDataFactory = DOMStandardFontDataFactory;
|
||||
|
||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS) {
|
||||
const {
|
||||
NodeCanvasFactory,
|
||||
NodeCMapReaderFactory,
|
||||
NodeStandardFontDataFactory,
|
||||
} = require("./node_utils.js");
|
||||
|
||||
DefaultCanvasFactory = NodeCanvasFactory;
|
||||
DefaultCMapReaderFactory = NodeCMapReaderFactory;
|
||||
DefaultStandardFontDataFactory = NodeStandardFontDataFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {function} IPDFStreamFactory
|
||||
@ -355,15 +353,10 @@ function getDocument(src) {
|
||||
params.isEvalSupported = true;
|
||||
}
|
||||
if (typeof params.disableFontFace !== "boolean") {
|
||||
params.disableFontFace =
|
||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS;
|
||||
params.disableFontFace = isNodeJS;
|
||||
}
|
||||
if (typeof params.useSystemFonts !== "boolean") {
|
||||
params.useSystemFonts =
|
||||
!(
|
||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
|
||||
isNodeJS
|
||||
) && !params.disableFontFace;
|
||||
params.useSystemFonts = !isNodeJS && !params.disableFontFace;
|
||||
}
|
||||
if (
|
||||
typeof params.ownerDocument !== "object" ||
|
||||
|
@ -19,28 +19,13 @@ import {
|
||||
BaseCMapReaderFactory,
|
||||
BaseStandardFontDataFactory,
|
||||
} from "./base_factory.js";
|
||||
import { isNodeJS } from "../shared/is_node.js";
|
||||
import { unreachable } from "../shared/util.js";
|
||||
|
||||
let NodeCanvasFactory = class {
|
||||
constructor() {
|
||||
unreachable("Not implemented: NodeCanvasFactory");
|
||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
||||
throw new Error(
|
||||
'Module "./node_utils.js" shall not be used with MOZCENTRAL builds.'
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
let NodeCMapReaderFactory = class {
|
||||
constructor() {
|
||||
unreachable("Not implemented: NodeCMapReaderFactory");
|
||||
}
|
||||
};
|
||||
|
||||
let NodeStandardFontDataFactory = class {
|
||||
constructor() {
|
||||
unreachable("Not implemented: NodeStandardFontDataFactory");
|
||||
}
|
||||
};
|
||||
|
||||
if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS) {
|
||||
const fetchData = function (url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const fs = __non_webpack_require__("fs");
|
||||
@ -54,7 +39,7 @@ if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS) {
|
||||
});
|
||||
};
|
||||
|
||||
NodeCanvasFactory = class extends BaseCanvasFactory {
|
||||
class NodeCanvasFactory extends BaseCanvasFactory {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
@ -62,9 +47,9 @@ if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS) {
|
||||
const Canvas = __non_webpack_require__("canvas");
|
||||
return Canvas.createCanvas(width, height);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
NodeCMapReaderFactory = class extends BaseCMapReaderFactory {
|
||||
class NodeCMapReaderFactory extends BaseCMapReaderFactory {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
@ -73,16 +58,15 @@ if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS) {
|
||||
return { cMapData: data, compressionType };
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
NodeStandardFontDataFactory = class extends BaseStandardFontDataFactory {
|
||||
class NodeStandardFontDataFactory extends BaseStandardFontDataFactory {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
_fetchData(url) {
|
||||
return fetchData(url);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
|
Loading…
x
Reference in New Issue
Block a user