Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a standard export statement in the web/pdfjs.js file #17052

Merged
merged 1 commit into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
112 changes: 66 additions & 46 deletions test/unit/pdf_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
FeatureTest,
ImageKind,
InvalidPDFException,
isNodeJS,
MissingPDFException,
normalizeUnicode,
OPS,
Expand Down Expand Up @@ -66,6 +67,53 @@ import { AnnotationLayer } from "../../src/display/annotation_layer.js";
import { GlobalWorkerOptions } from "../../src/display/worker_options.js";
import { XfaLayer } from "../../src/display/xfa_layer.js";

const expectedAPI = Object.freeze({
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,
});

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
Expand All @@ -77,51 +125,23 @@ describe("pdfjs_api", function () {

// The imported Object contains an (automatically) inserted Symbol,
// hence we copy the data to allow using a simple comparison below.
expect({ ...pdfjsAPI }).toEqual({
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,
});
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 changes: 92 additions & 3 deletions web/pdfjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,97 @@
* See the License for the specific language governing permissions and
* 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,
};