mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Only bundle the src/display/node_utils.js
file in GENERIC-builds
This first of all simplifies the file, since we no longer need dummy-classes and can instead *directly* define the actual classes. Furthermore, and more importantly, this means that we no longer need to bundle this code in e.g. MOZCENTRAL-builds which reduces the size of *built* `pdf.js` file slightly.
This commit is contained in:
parent
da4f7dfcd0
commit
7df47c289f
2 changed files with 57 additions and 75 deletions
|
@ -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
|
||||
|
|
|
@ -19,70 +19,54 @@ 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");
|
||||
fs.readFile(url, (error, data) => {
|
||||
if (error || !data) {
|
||||
reject(new Error(error));
|
||||
return;
|
||||
}
|
||||
resolve(new Uint8Array(data));
|
||||
});
|
||||
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 {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
_createCanvas(width, height) {
|
||||
const Canvas = __non_webpack_require__("canvas");
|
||||
return Canvas.createCanvas(width, height);
|
||||
}
|
||||
};
|
||||
class NodeCanvasFactory extends BaseCanvasFactory {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
_createCanvas(width, height) {
|
||||
const Canvas = __non_webpack_require__("canvas");
|
||||
return Canvas.createCanvas(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
NodeCMapReaderFactory = class extends BaseCMapReaderFactory {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
_fetchData(url, compressionType) {
|
||||
return fetchData(url).then(data => {
|
||||
return { cMapData: data, compressionType };
|
||||
});
|
||||
}
|
||||
};
|
||||
class NodeCMapReaderFactory extends BaseCMapReaderFactory {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
_fetchData(url, compressionType) {
|
||||
return fetchData(url).then(data => {
|
||||
return { cMapData: data, compressionType };
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
NodeStandardFontDataFactory = class extends BaseStandardFontDataFactory {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
_fetchData(url) {
|
||||
return fetchData(url);
|
||||
}
|
||||
};
|
||||
class NodeStandardFontDataFactory extends BaseStandardFontDataFactory {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
_fetchData(url) {
|
||||
return fetchData(url);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue