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,
|
StatTimer,
|
||||||
} from "./display_utils.js";
|
} from "./display_utils.js";
|
||||||
import { FontFaceObject, FontLoader } from "./font_loader.js";
|
import { FontFaceObject, FontLoader } from "./font_loader.js";
|
||||||
import {
|
|
||||||
NodeCanvasFactory,
|
|
||||||
NodeCMapReaderFactory,
|
|
||||||
NodeStandardFontDataFactory,
|
|
||||||
} from "./node_utils.js";
|
|
||||||
import { AnnotationStorage } from "./annotation_storage.js";
|
import { AnnotationStorage } from "./annotation_storage.js";
|
||||||
import { CanvasGraphics } from "./canvas.js";
|
import { CanvasGraphics } from "./canvas.js";
|
||||||
import { GlobalWorkerOptions } from "./worker_options.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 DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
|
||||||
const RENDERING_CANCELLED_TIMEOUT = 100; // ms
|
const RENDERING_CANCELLED_TIMEOUT = 100; // ms
|
||||||
|
|
||||||
const DefaultCanvasFactory =
|
let DefaultCanvasFactory = DOMCanvasFactory;
|
||||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS
|
let DefaultCMapReaderFactory = DOMCMapReaderFactory;
|
||||||
? NodeCanvasFactory
|
let DefaultStandardFontDataFactory = DOMStandardFontDataFactory;
|
||||||
: DOMCanvasFactory;
|
|
||||||
const DefaultCMapReaderFactory =
|
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS) {
|
||||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS
|
const {
|
||||||
? NodeCMapReaderFactory
|
NodeCanvasFactory,
|
||||||
: DOMCMapReaderFactory;
|
NodeCMapReaderFactory,
|
||||||
const DefaultStandardFontDataFactory =
|
NodeStandardFontDataFactory,
|
||||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS
|
} = require("./node_utils.js");
|
||||||
? NodeStandardFontDataFactory
|
|
||||||
: DOMStandardFontDataFactory;
|
DefaultCanvasFactory = NodeCanvasFactory;
|
||||||
|
DefaultCMapReaderFactory = NodeCMapReaderFactory;
|
||||||
|
DefaultStandardFontDataFactory = NodeStandardFontDataFactory;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {function} IPDFStreamFactory
|
* @typedef {function} IPDFStreamFactory
|
||||||
@ -355,15 +353,10 @@ function getDocument(src) {
|
|||||||
params.isEvalSupported = true;
|
params.isEvalSupported = true;
|
||||||
}
|
}
|
||||||
if (typeof params.disableFontFace !== "boolean") {
|
if (typeof params.disableFontFace !== "boolean") {
|
||||||
params.disableFontFace =
|
params.disableFontFace = isNodeJS;
|
||||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS;
|
|
||||||
}
|
}
|
||||||
if (typeof params.useSystemFonts !== "boolean") {
|
if (typeof params.useSystemFonts !== "boolean") {
|
||||||
params.useSystemFonts =
|
params.useSystemFonts = !isNodeJS && !params.disableFontFace;
|
||||||
!(
|
|
||||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
|
|
||||||
isNodeJS
|
|
||||||
) && !params.disableFontFace;
|
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
typeof params.ownerDocument !== "object" ||
|
typeof params.ownerDocument !== "object" ||
|
||||||
|
@ -19,70 +19,54 @@ import {
|
|||||||
BaseCMapReaderFactory,
|
BaseCMapReaderFactory,
|
||||||
BaseStandardFontDataFactory,
|
BaseStandardFontDataFactory,
|
||||||
} from "./base_factory.js";
|
} from "./base_factory.js";
|
||||||
import { isNodeJS } from "../shared/is_node.js";
|
|
||||||
import { unreachable } from "../shared/util.js";
|
|
||||||
|
|
||||||
let NodeCanvasFactory = class {
|
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
||||||
constructor() {
|
throw new Error(
|
||||||
unreachable("Not implemented: NodeCanvasFactory");
|
'Module "./node_utils.js" shall not be used with MOZCENTRAL builds.'
|
||||||
}
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
let NodeCMapReaderFactory = class {
|
const fetchData = function (url) {
|
||||||
constructor() {
|
return new Promise((resolve, reject) => {
|
||||||
unreachable("Not implemented: NodeCMapReaderFactory");
|
const fs = __non_webpack_require__("fs");
|
||||||
}
|
fs.readFile(url, (error, data) => {
|
||||||
};
|
if (error || !data) {
|
||||||
|
reject(new Error(error));
|
||||||
let NodeStandardFontDataFactory = class {
|
return;
|
||||||
constructor() {
|
}
|
||||||
unreachable("Not implemented: NodeStandardFontDataFactory");
|
resolve(new Uint8Array(data));
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS) {
|
|
||||||
const fetchData = function (url) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const fs = __non_webpack_require__("fs");
|
|
||||||
fs.readFile(url, (error, data) => {
|
|
||||||
if (error || !data) {
|
|
||||||
reject(new Error(error));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve(new Uint8Array(data));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
};
|
||||||
|
|
||||||
NodeCanvasFactory = class extends BaseCanvasFactory {
|
class NodeCanvasFactory extends BaseCanvasFactory {
|
||||||
/**
|
/**
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
_createCanvas(width, height) {
|
_createCanvas(width, height) {
|
||||||
const Canvas = __non_webpack_require__("canvas");
|
const Canvas = __non_webpack_require__("canvas");
|
||||||
return Canvas.createCanvas(width, height);
|
return Canvas.createCanvas(width, height);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
NodeCMapReaderFactory = class extends BaseCMapReaderFactory {
|
class NodeCMapReaderFactory extends BaseCMapReaderFactory {
|
||||||
/**
|
/**
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
_fetchData(url, compressionType) {
|
_fetchData(url, compressionType) {
|
||||||
return fetchData(url).then(data => {
|
return fetchData(url).then(data => {
|
||||||
return { cMapData: data, compressionType };
|
return { cMapData: data, compressionType };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
NodeStandardFontDataFactory = class extends BaseStandardFontDataFactory {
|
class NodeStandardFontDataFactory extends BaseStandardFontDataFactory {
|
||||||
/**
|
/**
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
_fetchData(url) {
|
_fetchData(url) {
|
||||||
return fetchData(url);
|
return fetchData(url);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user