Use a standard export
statement in the web/pdfjs.js
file
This removes the only remaining old and non-standard handling of exports in the `web/`-folder, since some initial attempts at outputting JavaScript modules in the builds have identified this file as a potential problem. While this uses a hard-coded list, for overall simplicity, I don't believe that that's a big problem since: - Generating this file automatically would require a bunch more parsing *every single time* that the library is built. - The official API-surface doesn't change often enough for this to really impede development in any significant way. - The added unit-test helps ensure that this list cannot accidentally become outdated.
This commit is contained in:
parent
3ca63c68ea
commit
9624505f0f
@ -23,6 +23,7 @@ import {
|
|||||||
FeatureTest,
|
FeatureTest,
|
||||||
ImageKind,
|
ImageKind,
|
||||||
InvalidPDFException,
|
InvalidPDFException,
|
||||||
|
isNodeJS,
|
||||||
MissingPDFException,
|
MissingPDFException,
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
OPS,
|
OPS,
|
||||||
@ -66,18 +67,7 @@ import { AnnotationLayer } from "../../src/display/annotation_layer.js";
|
|||||||
import { GlobalWorkerOptions } from "../../src/display/worker_options.js";
|
import { GlobalWorkerOptions } from "../../src/display/worker_options.js";
|
||||||
import { XfaLayer } from "../../src/display/xfa_layer.js";
|
import { XfaLayer } from "../../src/display/xfa_layer.js";
|
||||||
|
|
||||||
describe("pdfjs_api", function () {
|
const expectedAPI = Object.freeze({
|
||||||
it("checks that the *official* PDF.js API exposes the expected functionality", async function () {
|
|
||||||
// eslint-disable-next-line no-unsanitized/method
|
|
||||||
const pdfjsAPI = await import(
|
|
||||||
typeof PDFJSDev !== "undefined" && PDFJSDev.test("LIB")
|
|
||||||
? "../../pdf.js"
|
|
||||||
: "../../src/pdf.js"
|
|
||||||
);
|
|
||||||
|
|
||||||
// The imported Object contains an (automatically) inserted Symbol,
|
|
||||||
// hence we copy the data to allow using a simple comparison below.
|
|
||||||
expect({ ...pdfjsAPI }).toEqual({
|
|
||||||
AbortException,
|
AbortException,
|
||||||
AnnotationEditorLayer,
|
AnnotationEditorLayer,
|
||||||
AnnotationEditorParamsType,
|
AnnotationEditorParamsType,
|
||||||
@ -123,5 +113,35 @@ describe("pdfjs_api", function () {
|
|||||||
version,
|
version,
|
||||||
XfaLayer,
|
XfaLayer,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("pdfjs_api", function () {
|
||||||
|
it("checks that the *official* PDF.js API exposes the expected functionality", async function () {
|
||||||
|
// eslint-disable-next-line no-unsanitized/method
|
||||||
|
const pdfjsAPI = await import(
|
||||||
|
typeof PDFJSDev !== "undefined" && PDFJSDev.test("LIB")
|
||||||
|
? "../../pdf.js"
|
||||||
|
: "../../src/pdf.js"
|
||||||
|
);
|
||||||
|
|
||||||
|
// The imported Object contains an (automatically) inserted Symbol,
|
||||||
|
// hence we copy the data to allow using a simple comparison below.
|
||||||
|
expect({ ...pdfjsAPI }).toEqual(expectedAPI);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("web_pdfjsLib", function () {
|
||||||
|
it("checks that the viewer re-exports the expected API functionality", async function () {
|
||||||
|
if (isNodeJS) {
|
||||||
|
pending("loadScript is not supported in Node.js.");
|
||||||
|
}
|
||||||
|
await loadScript(
|
||||||
|
"../../build/generic/build/pdf.js",
|
||||||
|
/* removeScriptElement = */ true
|
||||||
|
);
|
||||||
|
const webPdfjsLib = await import("../../web/pdfjs.js");
|
||||||
|
|
||||||
|
expect(Object.keys(webPdfjsLib).sort()).toEqual(
|
||||||
|
Object.keys(expectedAPI).sort()
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
95
web/pdfjs.js
95
web/pdfjs.js
@ -12,8 +12,97 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals module */
|
|
||||||
|
|
||||||
"use strict";
|
const {
|
||||||
|
AbortException,
|
||||||
|
AnnotationEditorLayer,
|
||||||
|
AnnotationEditorParamsType,
|
||||||
|
AnnotationEditorType,
|
||||||
|
AnnotationEditorUIManager,
|
||||||
|
AnnotationLayer,
|
||||||
|
AnnotationMode,
|
||||||
|
build,
|
||||||
|
CMapCompressionType,
|
||||||
|
createValidAbsoluteUrl,
|
||||||
|
DOMSVGFactory,
|
||||||
|
FeatureTest,
|
||||||
|
getDocument,
|
||||||
|
getFilenameFromUrl,
|
||||||
|
getPdfFilenameFromUrl,
|
||||||
|
getXfaPageViewport,
|
||||||
|
GlobalWorkerOptions,
|
||||||
|
ImageKind,
|
||||||
|
InvalidPDFException,
|
||||||
|
isDataScheme,
|
||||||
|
isPdfFile,
|
||||||
|
loadScript,
|
||||||
|
MissingPDFException,
|
||||||
|
noContextMenu,
|
||||||
|
normalizeUnicode,
|
||||||
|
OPS,
|
||||||
|
PasswordResponses,
|
||||||
|
PDFDataRangeTransport,
|
||||||
|
PDFDateString,
|
||||||
|
PDFWorker,
|
||||||
|
PermissionFlag,
|
||||||
|
PixelsPerInch,
|
||||||
|
PromiseCapability,
|
||||||
|
RenderingCancelledException,
|
||||||
|
renderTextLayer,
|
||||||
|
setLayerDimensions,
|
||||||
|
shadow,
|
||||||
|
SVGGraphics,
|
||||||
|
UnexpectedResponseException,
|
||||||
|
updateTextLayer,
|
||||||
|
Util,
|
||||||
|
VerbosityLevel,
|
||||||
|
version,
|
||||||
|
XfaLayer,
|
||||||
|
} = globalThis.pdfjsLib;
|
||||||
|
|
||||||
module.exports = globalThis.pdfjsLib;
|
export {
|
||||||
|
AbortException,
|
||||||
|
AnnotationEditorLayer,
|
||||||
|
AnnotationEditorParamsType,
|
||||||
|
AnnotationEditorType,
|
||||||
|
AnnotationEditorUIManager,
|
||||||
|
AnnotationLayer,
|
||||||
|
AnnotationMode,
|
||||||
|
build,
|
||||||
|
CMapCompressionType,
|
||||||
|
createValidAbsoluteUrl,
|
||||||
|
DOMSVGFactory,
|
||||||
|
FeatureTest,
|
||||||
|
getDocument,
|
||||||
|
getFilenameFromUrl,
|
||||||
|
getPdfFilenameFromUrl,
|
||||||
|
getXfaPageViewport,
|
||||||
|
GlobalWorkerOptions,
|
||||||
|
ImageKind,
|
||||||
|
InvalidPDFException,
|
||||||
|
isDataScheme,
|
||||||
|
isPdfFile,
|
||||||
|
loadScript,
|
||||||
|
MissingPDFException,
|
||||||
|
noContextMenu,
|
||||||
|
normalizeUnicode,
|
||||||
|
OPS,
|
||||||
|
PasswordResponses,
|
||||||
|
PDFDataRangeTransport,
|
||||||
|
PDFDateString,
|
||||||
|
PDFWorker,
|
||||||
|
PermissionFlag,
|
||||||
|
PixelsPerInch,
|
||||||
|
PromiseCapability,
|
||||||
|
RenderingCancelledException,
|
||||||
|
renderTextLayer,
|
||||||
|
setLayerDimensions,
|
||||||
|
shadow,
|
||||||
|
SVGGraphics,
|
||||||
|
UnexpectedResponseException,
|
||||||
|
updateTextLayer,
|
||||||
|
Util,
|
||||||
|
VerbosityLevel,
|
||||||
|
version,
|
||||||
|
XfaLayer,
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user