: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
case FontRenderOps.RESTORE:
commands.push(ctx => ctx.restore());
commands.push(ctx => ctx.save());
case FontRenderOps.SCALE:
assert(commands.length === 2, "Scale command is only valid at the third position.");
case FontRenderOps.TRANSFORM:
const [a, b, c, d, e, f] = cmds.slice(i, i + 6);
commands.push(ctx => ctx.transform(a, b, c, d, e, f));
case FontRenderOps.TRANSLATE:
const [a, b] = cmds.slice(i, i + 2);
commands.push(ctx => ctx.translate(a, b));
return this.compiledGlyphs[character] = function glyphDrawer(ctx, size) {
for (let i = 2, ii = commands.length; i < ii; i++) {
;// CONCATENATED MODULE: ./src/display/node_utils.js
var packageCapability = Promise.withResolvers();
const loadPackages = async () => {
const fs = await import( /*webpackIgnore: true*/"fs"),
http = await import( /*webpackIgnore: true*/"http"),
https = await import( /*webpackIgnore: true*/"https"),
url = await import( /*webpackIgnore: true*/"url");
canvas = await import( /*webpackIgnore: true*/"canvas");
path2d = await import( /*webpackIgnore: true*/"path2d");
return new Map(Object.entries({
loadPackages().then(map => {
packageCapability.resolve();
if (!globalThis.DOMMatrix) {
const DOMMatrix = map.get("canvas")?.DOMMatrix;
globalThis.DOMMatrix = DOMMatrix;
warn("Cannot polyfill `DOMMatrix`, rendering may be broken.");
if (!globalThis.Path2D) {
const CanvasRenderingContext2D = map.get("canvas")?.CanvasRenderingContext2D;
const applyPath2DToCanvasRenderingContext = map.get("path2d")?.applyPath2DToCanvasRenderingContext;
const Path2D = map.get("path2d")?.Path2D;
if (CanvasRenderingContext2D && applyPath2DToCanvasRenderingContext && Path2D) {
applyPath2DToCanvasRenderingContext(CanvasRenderingContext2D);
globalThis.Path2D = Path2D;
warn("Cannot polyfill `Path2D`, rendering may be broken.");
warn(`loadPackages: ${reason}`);
packageCapability.resolve();
return packageCapability.promise;
return packageMap?.get(name);
const node_utils_fetchData = function (url) {
const fs = NodePackages.get("fs");
return fs.promises.readFile(url).then(data => new Uint8Array(data));
class NodeFilterFactory extends BaseFilterFactory {}
class NodeCanvasFactory extends BaseCanvasFactory {
_createCanvas(width, height) {
const canvas = NodePackages.get("canvas");
return canvas.createCanvas(width, height);
class NodeCMapReaderFactory extends BaseCMapReaderFactory {
_fetchData(url, compressionType) {
return node_utils_fetchData(url).then(data => ({
class NodeStandardFontDataFactory extends BaseStandardFontDataFactory {
return node_utils_fetchData(url);
;// CONCATENATED MODULE: ./src/display/pattern_helper.js
function applyBoundingBox(ctx, bbox) {
const width = bbox[2] - bbox[0];
const height = bbox[3] - bbox[1];
const region = new Path2D();
region.rect(bbox[0], bbox[1], width, height);
class BaseShadingPattern {
if (this.constructor === BaseShadingPattern) {
unreachable("Cannot initialize BaseShadingPattern.");
unreachable("Abstract method `getPattern` called.");
class RadialAxialShadingPattern extends BaseShadingPattern {
this._colorStops = IR[3];
if (this._type === "axial") {
grad = ctx.createLinearGradient(this._p0[0], this._p0[1], this._p1[0], this._p1[1]);
} else if (this._type === "radial") {
grad = ctx.createRadialGradient(this._p0[0], this._p0[1], this._r0, this._p1[0], this._p1[1], this._r1);
for (const colorStop of this._colorStops) {
grad.addColorStop(colorStop[0], colorStop[1]);
getPattern(ctx, owner, inverse, pathType) {
if (pathType === PathType.STROKE || pathType === PathType.FILL) {
const ownerBBox = owner.current.getClippedPathBoundingBox(pathType, getCurrentTransform(ctx)) || [0, 0, 0, 0];
const width = Math.ceil(ownerBBox[2] - ownerBBox[0]) || 1;
const height = Math.ceil(ownerBBox[3] - ownerBBox[1]) || 1;
const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", width, height, true);
const tmpCtx = tmpCanvas.context;
tmpCtx.clearRect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
tmpCtx.rect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
tmpCtx.translate(-ownerBBox[0], -ownerBBox[1]);
inverse = Util.transform(inverse, [1, 0, 0, 1, ownerBBox[0], ownerBBox[1]]);
tmpCtx.transform(...owner.baseTransform);
tmpCtx.transform(...this.matrix);
applyBoundingBox(tmpCtx, this._bbox);
tmpCtx.fillStyle = this._createGradient(tmpCtx);
pattern = ctx.createPattern(tmpCanvas.canvas, "no-repeat");
const domMatrix = new DOMMatrix(inverse);
pattern.setTransform(domMatrix);
applyBoundingBox(ctx, this._bbox);
pattern = this._createGradient(ctx);
function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
const coords = context.coords,
rowSize = data.width * 4;
if (coords[p1 + 1] > coords[p2 + 1]) {
if (coords[p2 + 1] > coords[p3 + 1]) {
if (coords[p1 + 1] > coords[p2 + 1]) {
const x1 = (coords[p1] + context.offsetX) * context.scaleX;
const y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
const x2 = (coords[p2] + context.offsetX) * context.scaleX;
const y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
const x3 = (coords[p3] + context.offsetX) * context.scaleX;
const y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
const minY = Math.round(y1),
for (let y = minY; y <= maxY; y++) {
const k = y < y1 ? 0 : (y1 - y) / (y1 - y2);
car = c1r - (c1r - c2r) * k;
cag = c1g - (c1g - c2g) * k;
cab = c1b - (c1b - c2b) * k;
k = (y2 - y) / (y2 - y3);
car = c2r - (c2r - c3r) * k;
cag = c2g - (c2g - c3g) * k;
cab = c2b - (c2b - c3b) * k;
k = (y1 - y) / (y1 - y3);
cbr = c1r - (c1r - c3r) * k;
cbg = c1g - (c1g - c3g) * k;
cbb = c1b - (c1b - c3b) * k;
const x1_ = Math.round(Math.min(xa, xb));
const x2_ = Math.round(Math.max(xa, xb));
let j = rowSize * y + x1_ * 4;
for (let x = x1_; x <= x2_; x++) {
k = (xa - x) / (xa - xb);
bytes[j++] = car - (car - cbr) * k | 0;
bytes[j++] = cag - (cag - cbg) * k | 0;
bytes[j++] = cab - (cab - cbb) * k | 0;
function drawFigure(data, figure, context) {
const ps = figure.coords;
const cs = figure.colors;
const verticesPerRow = figure.verticesPerRow;
const rows = Math.floor(ps.length / verticesPerRow) - 1;
const cols = verticesPerRow - 1;
for (i = 0; i < rows; i++) {
let q = i * verticesPerRow;
for (let j = 0; j < cols; j++, q++) {
drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
for (i = 0, ii = ps.length; i < ii; i += 3) {
drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
throw new Error("illegal figure");
class MeshShadingPattern extends BaseShadingPattern {
this._background = IR[8];
_createMeshCanvas(combinedScale, backgroundColor, cachedCanvases) {
const EXPECTED_SCALE = 1.1;
const MAX_PATTERN_SIZE = 3000;
const offsetX = Math.floor(this._bounds[0]);
const offsetY = Math.floor(this._bounds[1]);
const boundsWidth = Math.ceil(this._bounds[2]) - offsetX;
const boundsHeight = Math.ceil(this._bounds[3]) - offsetY;
const width = Math.min(Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
const height = Math.min(Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
const scaleX = boundsWidth / width;
const scaleY = boundsHeight / height;
const paddedWidth = width + BORDER_SIZE * 2;
const paddedHeight = height + BORDER_SIZE * 2;
const tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
const tmpCtx = tmpCanvas.context;
const data = tmpCtx.createImageData(width, height);
for (let i = 0, ii = bytes.length; i < ii; i += 4) {
bytes[i] = backgroundColor[0];
bytes[i + 1] = backgroundColor[1];
bytes[i + 2] = backgroundColor[2];
for (const figure of this._figures) {
drawFigure(data, figure, context);
tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
const canvas = tmpCanvas.canvas;
offsetX: offsetX - BORDER_SIZE * scaleX,
offsetY: offsetY - BORDER_SIZE * scaleY,
getPattern(ctx, owner, inverse, pathType) {
applyBoundingBox(ctx, this._bbox);
if (pathType === PathType.SHADING) {
scale = Util.singularValueDecompose2dScale(getCurrentTransform(ctx));
scale = Util.singularValueDecompose2dScale(owner.baseTransform);
const matrixScale = Util.singularValueDecompose2dScale(this.matrix);
scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
const temporaryPatternCanvas = this._createMeshCanvas(scale, pathType === PathType.SHADING ? null : this._background, owner.cachedCanvases);
if (pathType !== PathType.SHADING) {
ctx.setTransform(...owner.baseTransform);
ctx.transform(...this.matrix);
ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
class DummyShadingPattern extends BaseShadingPattern {
function getShadingPattern(IR) {
return new RadialAxialShadingPattern(IR);
return new MeshShadingPattern(IR);
return new DummyShadingPattern();
throw new Error(`Unknown IR type: ${IR[0]}`);
static MAX_PATTERN_SIZE = 3000;
constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
this.operatorList = IR[2];
this.canvasGraphicsFactory = canvasGraphicsFactory;
this.baseTransform = baseTransform;
createPatternCanvas(owner) {
const operatorList = this.operatorList;
const xstep = this.xstep;
const ystep = this.ystep;
const paintType = this.paintType;
const tilingType = this.tilingType;
const color = this.color;
const canvasGraphicsFactory = this.canvasGraphicsFactory;
info("TilingType: " + tilingType);
const matrixScale = Util.singularValueDecompose2dScale(this.matrix);
const curMatrixScale = Util.singularValueDecompose2dScale(this.baseTransform);
const combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
const dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
const dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
const tmpCtx = tmpCanvas.context;
const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
graphics.groupLevel = owner.groupLevel;
this.setFillAndStrokeStyleToContext(graphics, paintType, color);
adjustedX1 += Math.abs(x0);
adjustedY1 += Math.abs(y0);
tmpCtx.translate(-(dimx.scale * adjustedX0), -(dimy.scale * adjustedY0));
graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
this.clipBbox(graphics, adjustedX0, adjustedY0, adjustedX1, adjustedY1);
graphics.baseTransform = getCurrentTransform(graphics.ctx);
graphics.executeOperatorList(operatorList);