Add a pdf.renderer.js entrypoint and gulp function to build renderer

This commit is contained in:
Ujjwal Sharma 2025-07-14 23:08:36 +02:00
parent a163821501
commit 4734888685
3 changed files with 46 additions and 3 deletions

View File

@ -589,6 +589,18 @@ function createWorkerBundle(defines) {
.pipe(webpack2Stream(workerFileConfig));
}
function createRendererWorkerBundle(defines) {
const rendererWorkerFileConfig = createWebpackConfig(defines, {
filename: defines.MINIFIED ? "pdf.renderer.min.mjs" : "pdf.renderer.mjs",
library: {
type: "module",
},
});
return gulp
.src("./src/pdf.renderer.js", { encoding: false })
.pipe(webpack2Stream(rendererWorkerFileConfig));
}
function createWebBundle(defines, options) {
const viewerFileConfig = createWebpackConfig(
defines,
@ -1103,6 +1115,7 @@ function buildGeneric(defines, dir) {
return ordered([
createMainBundle(defines).pipe(gulp.dest(dir + "build")),
createWorkerBundle(defines).pipe(gulp.dest(dir + "build")),
createRendererWorkerBundle(defines).pipe(gulp.dest(dir + "build")),
createSandboxBundle(defines).pipe(gulp.dest(dir + "build")),
createWebBundle(defines, {
defaultPreferencesDir: defines.SKIP_BABEL
@ -1294,6 +1307,7 @@ function buildMinified(defines, dir) {
return ordered([
createMainBundle(defines).pipe(gulp.dest(dir + "build")),
createWorkerBundle(defines).pipe(gulp.dest(dir + "build")),
createRendererWorkerBundle(defines).pipe(gulp.dest(dir + "build")),
createSandboxBundle(defines).pipe(gulp.dest(dir + "build")),
createImageDecodersBundle({ ...defines, IMAGE_DECODERS: true }).pipe(
gulp.dest(dir + "image_decoders")
@ -1439,6 +1453,9 @@ gulp.task(
createWorkerBundle(defines).pipe(
gulp.dest(MOZCENTRAL_CONTENT_DIR + "build")
),
createRendererWorkerBundle(defines).pipe(
gulp.dest(MOZCENTRAL_CONTENT_DIR + "build")
),
createWebBundle(defines, { defaultPreferencesDir: "mozcentral/" }).pipe(
gulp.dest(MOZCENTRAL_CONTENT_DIR + "web")
),
@ -1536,6 +1553,9 @@ gulp.task(
createWorkerBundle(defines).pipe(
gulp.dest(CHROME_BUILD_CONTENT_DIR + "build")
),
createRendererWorkerBundle(defines).pipe(
gulp.dest(CHROME_BUILD_CONTENT_DIR + "build")
),
createSandboxBundle(defines).pipe(
gulp.dest(CHROME_BUILD_CONTENT_DIR + "build")
),

View File

@ -2400,9 +2400,14 @@ class RendererWorker {
#handler;
constructor(channelPort, enableHWA) {
this.#worker = new Worker("../src/display/renderer_worker.js", {
type: "module",
});
const src =
// eslint-disable-next-line no-nested-ternary
typeof PDFJSDev === "undefined"
? "../src/pdf.worker.js"
: PDFJSDev.test("MOZCENTRAL")
? "resource://pdf.js/build/pdf.worker.mjs"
: "../build/pdf.worker.mjs";
this.#worker = new Worker(src, { type: "module" });
this.#handler = new MessageHandler("main", "renderer", this.#worker);
this.#handler.send("configure", { channelPort, enableHWA }, [channelPort]);
this.#handler.on("ready", () => {

18
src/pdf.renderer.js Normal file
View File

@ -0,0 +1,18 @@
/* Copyright 2025 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { RendererMessageHandler } from "./display/renderer_worker.js";
export { RendererMessageHandler };