: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
constructor(stream, start, end) {
let path = decodeURIComponent(this._url.path);
if (fileUriRegex.test(this._url.href)) {
path = path.replace(/^\//, "");
const fs = NodePackages.get("fs");
this._setReadableStream(fs.createReadStream(path, {
;// CONCATENATED MODULE: ./src/display/text_layer.js
const MAX_TEXT_DIVS_TO_RENDER = 100000;
const DEFAULT_FONT_SIZE = 30;
const DEFAULT_FONT_ASCENT = 0.8;
#capability = Promise.withResolvers();
#disableProcessItems = false;
#fontInspectorEnabled = !!globalThis.FontInspector?.enabled;
#layoutTextParams = null;
#styleCache = Object.create(null);
#textContentItemsStr = [];
#textContentSource = null;
#textDivProperties = new WeakMap();
static #ascentCache = new Map();
static #canvasContexts = new Map();
static #pendingTextLayers = new Set();
if (textContentSource instanceof ReadableStream) {
this.#textContentSource = textContentSource;
} else if (typeof textContentSource === "object") {
this.#textContentSource = new ReadableStream({
controller.enqueue(textContentSource);
throw new Error('No "textContentSource" parameter specified.');
this.#container = this.#rootContainer = container;
this.#scale = viewport.scale * (globalThis.devicePixelRatio || 1);
this.#rotation = viewport.rotation;
this.#layoutTextParams = {
this.#transform = [1, 0, 0, -1, -pageX, pageY + pageHeight];
this.#pageWidth = pageWidth;
this.#pageHeight = pageHeight;
setLayerDimensions(container, viewport);
this.#capability.promise.catch(() => {}).then(() => {
TextLayer.#pendingTextLayers.delete(this);
this.#layoutTextParams = null;
this.#reader.read().then(({
this.#capability.resolve();
this.#lang ??= value.lang;
Object.assign(this.#styleCache, value.styles);
this.#processItems(value.items);
}, this.#capability.reject);
this.#reader = this.#textContentSource.getReader();
TextLayer.#pendingTextLayers.add(this);
return this.#capability.promise;
const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
const rotation = viewport.rotation;
if (rotation !== this.#rotation) {
this.#rotation = rotation;
setLayerDimensions(this.#rootContainer, {
if (scale !== this.#scale) {
ctx: TextLayer.#getCtx(this.#lang)
for (const div of this.#textDivs) {
params.properties = this.#textDivProperties.get(div);
const abortEx = new AbortException("TextLayer task cancelled.");
this.#reader?.cancel(abortEx).catch(() => {});
this.#capability.reject(abortEx);
get textContentItemsStr() {
return this.#textContentItemsStr;
if (this.#disableProcessItems) {
this.#layoutTextParams.ctx ||= TextLayer.#getCtx(this.#lang);
const textDivs = this.#textDivs,
textContentItemsStr = this.#textContentItemsStr;
for (const item of items) {
if (textDivs.length > MAX_TEXT_DIVS_TO_RENDER) {
warn("Ignoring additional textDivs for performance reasons.");
this.#disableProcessItems = true;
if (item.str === undefined) {
if (item.type === "beginMarkedContentProps" || item.type === "beginMarkedContent") {
const parent = this.#container;
this.#container = document.createElement("span");
this.#container.classList.add("markedContent");
this.#container.setAttribute("id", `${item.id}`);
parent.append(this.#container);
} else if (item.type === "endMarkedContent") {
this.#container = this.#container.parentNode;
textContentItemsStr.push(item.str);
const textDiv = document.createElement("span");
const textDivProperties = {
hasText: geom.str !== "",
this.#textDivs.push(textDiv);
const tx = Util.transform(this.#transform, geom.transform);
let angle = Math.atan2(tx[1], tx[0]);
const style = this.#styleCache[geom.fontName];
const fontFamily = this.#fontInspectorEnabled && style.fontSubstitution || style.fontFamily;
const fontHeight = Math.hypot(tx[2], tx[3]);
const fontAscent = fontHeight * TextLayer.#getAscent(fontFamily, this.#lang);
top = tx[5] - fontAscent;
left = tx[4] + fontAscent * Math.sin(angle);
top = tx[5] - fontAscent * Math.cos(angle);
const scaleFactorStr = "calc(var(--scale-factor)*";
const divStyle = textDiv.style;
if (this.#container === this.#rootContainer) {
divStyle.left = `${(100 * left / this.#pageWidth).toFixed(2)}%`;
divStyle.top = `${(100 * top / this.#pageHeight).toFixed(2)}%`;
divStyle.left = `${scaleFactorStr}${left.toFixed(2)}px)`;
divStyle.top = `${scaleFactorStr}${top.toFixed(2)}px)`;
divStyle.fontSize = `${scaleFactorStr}${fontHeight.toFixed(2)}px)`;
divStyle.fontFamily = fontFamily;
textDivProperties.fontSize = fontHeight;
textDiv.setAttribute("role", "presentation");
textDiv.textContent = geom.str;
if (this.#fontInspectorEnabled) {
textDiv.dataset.fontName = style.fontSubstitutionLoadedName || geom.fontName;
textDivProperties.angle = angle * (180 / Math.PI);
let shouldScaleText = false;
if (geom.str.length > 1) {
} else if (geom.str !== " " && geom.transform[0] !== geom.transform[3]) {
const absScaleX = Math.abs(geom.transform[0]),
absScaleY = Math.abs(geom.transform[3]);
if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
textDivProperties.canvasWidth = style.vertical ? geom.height : geom.width;
this.#textDivProperties.set(textDiv, textDivProperties);
this.#layoutTextParams.div = textDiv;
this.#layoutTextParams.properties = textDivProperties;
this.#layout(this.#layoutTextParams);
if (textDivProperties.hasText) {
this.#container.append(textDiv);
if (textDivProperties.hasEOL) {
const br = document.createElement("br");
br.setAttribute("role", "presentation");
this.#container.append(br);
if (properties.canvasWidth !== 0 && properties.hasText) {
if (prevFontSize !== fontSize || prevFontFamily !== fontFamily) {
ctx.font = `${fontSize * this.#scale}px ${fontFamily}`;
params.prevFontSize = fontSize;
params.prevFontFamily = fontFamily;
} = ctx.measureText(div.textContent);
transform = `scaleX(${canvasWidth * this.#scale / width})`;
if (properties.angle !== 0) {
transform = `rotate(${properties.angle}deg) ${transform}`;
if (transform.length > 0) {
style.transform = transform;
if (this.#pendingTextLayers.size > 0) {
this.#ascentCache.clear();
} of this.#canvasContexts.values()) {
this.#canvasContexts.clear();
static #getCtx(lang = null) {
let canvasContext = this.#canvasContexts.get(lang ||= "");
const canvas = document.createElement("canvas");
canvas.className = "hiddenCanvasElement";
document.body.append(canvas);
canvasContext = canvas.getContext("2d", {
this.#canvasContexts.set(lang, canvasContext);
static #getAscent(fontFamily, lang) {
const cachedAscent = this.#ascentCache.get(fontFamily);
const ctx = this.#getCtx(lang);
const savedFont = ctx.font;
ctx.canvas.width = ctx.canvas.height = DEFAULT_FONT_SIZE;
ctx.font = `${DEFAULT_FONT_SIZE}px ${fontFamily}`;
const metrics = ctx.measureText("");
let ascent = metrics.fontBoundingBoxAscent;
let descent = Math.abs(metrics.fontBoundingBoxDescent);
const ratio = ascent / (ascent + descent);
this.#ascentCache.set(fontFamily, ratio);
ctx.canvas.width = ctx.canvas.height = 0;
ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
ctx.strokeText("g", 0, 0);
let pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
for (let i = pixels.length - 1 - 3; i >= 0; i -= 4) {
descent = Math.ceil(i / 4 / DEFAULT_FONT_SIZE);
ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
ctx.strokeText("A", 0, DEFAULT_FONT_SIZE);
pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
for (let i = 0, ii = pixels.length; i < ii; i += 4) {
ascent = DEFAULT_FONT_SIZE - Math.floor(i / 4 / DEFAULT_FONT_SIZE);
ctx.canvas.width = ctx.canvas.height = 0;
const ratio = ascent ? ascent / (ascent + descent) : DEFAULT_FONT_ASCENT;
this.#ascentCache.set(fontFamily, ratio);
function renderTextLayer() {
deprecated("`renderTextLayer`, please use `TextLayer` instead.");
const restKeys = Object.keys(rest);
if (restKeys.length > 0) {
warn("Ignoring `renderTextLayer` parameters: " + restKeys.join(", "));
const textLayer = new TextLayer({
const promise = textLayer.render();
function updateTextLayer() {
deprecated("`updateTextLayer`, please use `TextLayer` instead.");
;// CONCATENATED MODULE: ./src/display/xfa_text.js
static textContent(xfa) {
styles: Object.create(null)
} else if (!XfaText.shouldBuildText(name)) {
} else if (node?.attributes?.textContent) {
str = node.attributes.textContent;
for (const child of node.children) {
static shouldBuildText(name) {
return !(name === "textarea" || name === "input" || name === "option" || name === "select");
;// CONCATENATED MODULE: ./src/display/api.js
const DEFAULT_RANGE_CHUNK_SIZE = 65536;
const RENDERING_CANCELLED_TIMEOUT = 100;
const DELAYED_CLEANUP_TIMEOUT = 5000;
const DefaultCanvasFactory = isNodeJS ? NodeCanvasFactory : DOMCanvasFactory;
const DefaultCMapReaderFactory = isNodeJS ? NodeCMapReaderFactory : DOMCMapReaderFactory;
const DefaultFilterFactory = isNodeJS ? NodeFilterFactory : DOMFilterFactory;
const DefaultStandardFontDataFactory = isNodeJS ? NodeStandardFontDataFactory : DOMStandardFontDataFactory;
function getDocument(src) {
if (typeof src === "string" || src instanceof URL) {
} else if (src instanceof ArrayBuffer || ArrayBuffer.isView(src)) {