@jumio/websdk
Version:
Jumio WebSDK is a powerful, flexible software development kit that simplifies the integration of Jumio's services into your web applications.
15,468 lines • 519 kB
JavaScript
var qp = Object.defineProperty;
var du = (d) => {
throw TypeError(d);
};
var Xp = (d, t, e) => t in d ? qp(d, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : d[t] = e;
var R = (d, t, e) => Xp(d, typeof t != "symbol" ? t + "" : t, e), vc = (d, t, e) => t.has(d) || du("Cannot " + e);
var n = (d, t, e) => (vc(d, t, "read from private field"), e ? e.call(d) : t.get(d)), m = (d, t, e) => t.has(d) ? du("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(d) : t.set(d, e), f = (d, t, e, s) => (vc(d, t, "write to private field"), s ? s.call(d, e) : t.set(d, e), e), b = (d, t, e) => (vc(d, t, "access private method"), e);
var Zt = (d, t, e, s) => ({
set _(i) {
f(d, t, i, e);
},
get _() {
return n(d, t, s);
}
});
const re = typeof process == "object" && process + "" == "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser"), Ic = [1e-3, 0, 0, 1e-3, 0, 0], _c = 1.35, Me = {
ANY: 1,
DISPLAY: 2,
PRINT: 4,
ANNOTATIONS_FORMS: 16,
ANNOTATIONS_STORAGE: 32,
ANNOTATIONS_DISABLE: 64,
IS_EDITING: 128,
OPLIST: 256
}, vi = {
DISABLE: 0,
ENABLE: 1,
ENABLE_FORMS: 2,
ENABLE_STORAGE: 3
}, Du = "pdfjs_internal_editor_", z = {
DISABLE: -1,
NONE: 0,
FREETEXT: 3,
HIGHLIGHT: 9,
STAMP: 13,
INK: 15,
SIGNATURE: 101
}, Y = {
RESIZE: 1,
CREATE: 2,
FREETEXT_SIZE: 11,
FREETEXT_COLOR: 12,
FREETEXT_OPACITY: 13,
INK_COLOR: 21,
INK_THICKNESS: 22,
INK_OPACITY: 23,
HIGHLIGHT_COLOR: 31,
HIGHLIGHT_DEFAULT_COLOR: 32,
HIGHLIGHT_THICKNESS: 33,
HIGHLIGHT_FREE: 34,
HIGHLIGHT_SHOW_ALL: 35,
DRAW_STEP: 41
}, Yp = {
PRINT: 4,
MODIFY_CONTENTS: 8,
COPY: 16,
MODIFY_ANNOTATIONS: 32,
FILL_INTERACTIVE_FORMS: 256,
COPY_FOR_ACCESSIBILITY: 512,
ASSEMBLE: 1024,
PRINT_HIGH_QUALITY: 2048
}, qt = {
FILL: 0,
STROKE: 1,
FILL_STROKE: 2,
INVISIBLE: 3,
FILL_STROKE_MASK: 3,
ADD_TO_PATH_FLAG: 4
}, lh = {
GRAYSCALE_1BPP: 1,
RGB_24BPP: 2,
RGBA_32BPP: 3
}, _t = {
TEXT: 1,
LINK: 2,
FREETEXT: 3,
LINE: 4,
SQUARE: 5,
CIRCLE: 6,
POLYGON: 7,
POLYLINE: 8,
HIGHLIGHT: 9,
UNDERLINE: 10,
SQUIGGLY: 11,
STRIKEOUT: 12,
STAMP: 13,
CARET: 14,
INK: 15,
POPUP: 16,
FILEATTACHMENT: 17,
SOUND: 18,
MOVIE: 19,
WIDGET: 20,
SCREEN: 21,
PRINTERMARK: 22,
TRAPNET: 23,
WATERMARK: 24,
THREED: 25,
REDACT: 26
}, Mr = {
SOLID: 1,
DASHED: 2,
BEVELED: 3,
INSET: 4,
UNDERLINE: 5
}, fc = {
ERRORS: 0,
WARNINGS: 1,
INFOS: 5
}, Hh = {
dependency: 1,
setLineWidth: 2,
setLineCap: 3,
setLineJoin: 4,
setMiterLimit: 5,
setDash: 6,
setRenderingIntent: 7,
setFlatness: 8,
setGState: 9,
save: 10,
restore: 11,
transform: 12,
moveTo: 13,
lineTo: 14,
curveTo: 15,
curveTo2: 16,
curveTo3: 17,
closePath: 18,
rectangle: 19,
stroke: 20,
closeStroke: 21,
fill: 22,
eoFill: 23,
fillStroke: 24,
eoFillStroke: 25,
closeFillStroke: 26,
closeEOFillStroke: 27,
endPath: 28,
clip: 29,
eoClip: 30,
beginText: 31,
endText: 32,
setCharSpacing: 33,
setWordSpacing: 34,
setHScale: 35,
setLeading: 36,
setFont: 37,
setTextRenderingMode: 38,
setTextRise: 39,
moveText: 40,
setLeadingMoveText: 41,
setTextMatrix: 42,
nextLine: 43,
showText: 44,
showSpacedText: 45,
nextLineShowText: 46,
nextLineSetSpacingShowText: 47,
setCharWidth: 48,
setCharWidthAndBounds: 49,
setStrokeColorSpace: 50,
setFillColorSpace: 51,
setStrokeColor: 52,
setStrokeColorN: 53,
setFillColor: 54,
setFillColorN: 55,
setStrokeGray: 56,
setFillGray: 57,
setStrokeRGBColor: 58,
setFillRGBColor: 59,
setStrokeCMYKColor: 60,
setFillCMYKColor: 61,
shadingFill: 62,
beginInlineImage: 63,
beginImageData: 64,
endInlineImage: 65,
paintXObject: 66,
markPoint: 67,
markPointProps: 68,
beginMarkedContent: 69,
beginMarkedContentProps: 70,
endMarkedContent: 71,
beginCompat: 72,
endCompat: 73,
paintFormXObjectBegin: 74,
paintFormXObjectEnd: 75,
beginGroup: 76,
endGroup: 77,
beginAnnotation: 80,
endAnnotation: 81,
paintImageMaskXObject: 83,
paintImageMaskXObjectGroup: 84,
paintImageXObject: 85,
paintInlineImageXObject: 86,
paintInlineImageXObjectGroup: 87,
paintImageXObjectRepeat: 88,
paintImageMaskXObjectRepeat: 89,
paintSolidColorImageMask: 90,
constructPath: 91,
setStrokeTransparent: 92,
setFillTransparent: 93,
rawFillPath: 94
}, eh = {
moveTo: 0,
lineTo: 1,
curveTo: 2,
closePath: 3
}, Kp = {
NEED_PASSWORD: 1,
INCORRECT_PASSWORD: 2
};
let pc = fc.WARNINGS;
function Qp(d) {
Number.isInteger(d) && (pc = d);
}
function Jp() {
return pc;
}
function gc(d) {
pc >= fc.INFOS && console.log(`Info: ${d}`);
}
function U(d) {
pc >= fc.WARNINGS && console.log(`Warning: ${d}`);
}
function rt(d) {
throw new Error(d);
}
function Et(d, t) {
d || rt(t);
}
function Zp(d) {
switch (d == null ? void 0 : d.protocol) {
case "http:":
case "https:":
case "ftp:":
case "mailto:":
case "tel:":
return !0;
default:
return !1;
}
}
function Fu(d, t = null, e = null) {
if (!d)
return null;
if (e && typeof d == "string") {
if (e.addDefaultProtocol && d.startsWith("www.")) {
const i = d.match(/\./g);
(i == null ? void 0 : i.length) >= 2 && (d = `http://${d}`);
}
if (e.tryConvertEncoding)
try {
d = ng(d);
} catch {
}
}
const s = t ? URL.parse(d, t) : URL.parse(d);
return Zp(s) ? s : null;
}
function Nu(d, t, e = !1) {
const s = URL.parse(d);
return s ? (s.hash = t, s.href) : e && Fu(d, "http://example.com") ? d.split("#", 1)[0] + `${t ? `#${t}` : ""}` : "";
}
function X(d, t, e, s = !1) {
return Object.defineProperty(d, t, {
value: e,
enumerable: !s,
configurable: !0,
writable: !1
}), e;
}
const Rr = function() {
function t(e, s) {
this.message = e, this.name = s;
}
return t.prototype = new Error(), t.constructor = t, t;
}();
class uu extends Rr {
constructor(t, e) {
super(t, "PasswordException"), this.code = e;
}
}
class Sc extends Rr {
constructor(t, e) {
super(t, "UnknownErrorException"), this.details = e;
}
}
class Mc extends Rr {
constructor(t) {
super(t, "InvalidPDFException");
}
}
class $h extends Rr {
constructor(t, e, s) {
super(t, "ResponseException"), this.status = e, this.missing = s;
}
}
class tg extends Rr {
constructor(t) {
super(t, "FormatError");
}
}
class an extends Rr {
constructor(t) {
super(t, "AbortException");
}
}
function Ou(d) {
(typeof d != "object" || (d == null ? void 0 : d.length) === void 0) && rt("Invalid argument for bytesToString");
const t = d.length, e = 8192;
if (t < e)
return String.fromCharCode.apply(null, d);
const s = [];
for (let i = 0; i < t; i += e) {
const r = Math.min(i + e, t), a = d.subarray(i, r);
s.push(String.fromCharCode.apply(null, a));
}
return s.join("");
}
function Yl(d) {
typeof d != "string" && rt("Invalid argument for stringToBytes");
const t = d.length, e = new Uint8Array(t);
for (let s = 0; s < t; ++s)
e[s] = d.charCodeAt(s) & 255;
return e;
}
function eg(d) {
return String.fromCharCode(d >> 24 & 255, d >> 16 & 255, d >> 8 & 255, d & 255);
}
function sg() {
const d = new Uint8Array(4);
return d[0] = 1, new Uint32Array(d.buffer, 0, 1)[0] === 1;
}
function ig() {
try {
return new Function(""), !0;
} catch {
return !1;
}
}
class Wt {
static get isLittleEndian() {
return X(this, "isLittleEndian", sg());
}
static get isEvalSupported() {
return X(this, "isEvalSupported", ig());
}
static get isOffscreenCanvasSupported() {
return X(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas < "u");
}
static get isImageDecoderSupported() {
return X(this, "isImageDecoderSupported", typeof ImageDecoder < "u");
}
static get platform() {
const {
platform: t,
userAgent: e
} = navigator;
return X(this, "platform", {
isAndroid: e.includes("Android"),
isLinux: t.includes("Linux"),
isMac: t.includes("Mac"),
isWindows: t.includes("Win"),
isFirefox: e.includes("Firefox")
});
}
static get isCSSRoundSupported() {
var t, e;
return X(this, "isCSSRoundSupported", (e = (t = globalThis.CSS) == null ? void 0 : t.supports) == null ? void 0 : e.call(t, "width: round(1.5px, 1px)"));
}
}
const Ec = Array.from(Array(256).keys(), (d) => d.toString(16).padStart(2, "0"));
var gi, hh, kc;
class $ {
static makeHexColor(t, e, s) {
return `#${Ec[t]}${Ec[e]}${Ec[s]}`;
}
static scaleMinMax(t, e) {
let s;
t[0] ? (t[0] < 0 && (s = e[0], e[0] = e[2], e[2] = s), e[0] *= t[0], e[2] *= t[0], t[3] < 0 && (s = e[1], e[1] = e[3], e[3] = s), e[1] *= t[3], e[3] *= t[3]) : (s = e[0], e[0] = e[1], e[1] = s, s = e[2], e[2] = e[3], e[3] = s, t[1] < 0 && (s = e[1], e[1] = e[3], e[3] = s), e[1] *= t[1], e[3] *= t[1], t[2] < 0 && (s = e[0], e[0] = e[2], e[2] = s), e[0] *= t[2], e[2] *= t[2]), e[0] += t[4], e[1] += t[5], e[2] += t[4], e[3] += t[5];
}
static transform(t, e) {
return [t[0] * e[0] + t[2] * e[1], t[1] * e[0] + t[3] * e[1], t[0] * e[2] + t[2] * e[3], t[1] * e[2] + t[3] * e[3], t[0] * e[4] + t[2] * e[5] + t[4], t[1] * e[4] + t[3] * e[5] + t[5]];
}
static applyTransform(t, e, s = 0) {
const i = t[s], r = t[s + 1];
t[s] = i * e[0] + r * e[2] + e[4], t[s + 1] = i * e[1] + r * e[3] + e[5];
}
static applyTransformToBezier(t, e, s = 0) {
const i = e[0], r = e[1], a = e[2], o = e[3], l = e[4], h = e[5];
for (let c = 0; c < 6; c += 2) {
const u = t[s + c], p = t[s + c + 1];
t[s + c] = u * i + p * a + l, t[s + c + 1] = u * r + p * o + h;
}
}
static applyInverseTransform(t, e) {
const s = t[0], i = t[1], r = e[0] * e[3] - e[1] * e[2];
t[0] = (s * e[3] - i * e[2] + e[2] * e[5] - e[4] * e[3]) / r, t[1] = (-s * e[1] + i * e[0] + e[4] * e[1] - e[5] * e[0]) / r;
}
static axialAlignedBoundingBox(t, e, s) {
const i = e[0], r = e[1], a = e[2], o = e[3], l = e[4], h = e[5], c = t[0], u = t[1], p = t[2], g = t[3];
let A = i * c + l, y = A, w = i * p + l, v = w, S = o * u + h, _ = S, E = o * g + h, C = E;
if (r !== 0 || a !== 0) {
const x = r * c, T = r * p, P = a * u, M = a * g;
A += P, v += P, w += M, y += M, S += x, C += x, E += T, _ += T;
}
s[0] = Math.min(s[0], A, w, y, v), s[1] = Math.min(s[1], S, E, _, C), s[2] = Math.max(s[2], A, w, y, v), s[3] = Math.max(s[3], S, E, _, C);
}
static inverseTransform(t) {
const e = t[0] * t[3] - t[1] * t[2];
return [t[3] / e, -t[1] / e, -t[2] / e, t[0] / e, (t[2] * t[5] - t[4] * t[3]) / e, (t[4] * t[1] - t[5] * t[0]) / e];
}
static singularValueDecompose2dScale(t, e) {
const s = t[0], i = t[1], r = t[2], a = t[3], o = s ** 2 + i ** 2, l = s * r + i * a, h = r ** 2 + a ** 2, c = (o + h) / 2, u = Math.sqrt(c ** 2 - (o * h - l ** 2));
e[0] = Math.sqrt(c + u || 1), e[1] = Math.sqrt(c - u || 1);
}
static normalizeRect(t) {
const e = t.slice(0);
return t[0] > t[2] && (e[0] = t[2], e[2] = t[0]), t[1] > t[3] && (e[1] = t[3], e[3] = t[1]), e;
}
static intersect(t, e) {
const s = Math.max(Math.min(t[0], t[2]), Math.min(e[0], e[2])), i = Math.min(Math.max(t[0], t[2]), Math.max(e[0], e[2]));
if (s > i)
return null;
const r = Math.max(Math.min(t[1], t[3]), Math.min(e[1], e[3])), a = Math.min(Math.max(t[1], t[3]), Math.max(e[1], e[3]));
return r > a ? null : [s, r, i, a];
}
static pointBoundingBox(t, e, s) {
s[0] = Math.min(s[0], t), s[1] = Math.min(s[1], e), s[2] = Math.max(s[2], t), s[3] = Math.max(s[3], e);
}
static rectBoundingBox(t, e, s, i, r) {
r[0] = Math.min(r[0], t, s), r[1] = Math.min(r[1], e, i), r[2] = Math.max(r[2], t, s), r[3] = Math.max(r[3], e, i);
}
static bezierBoundingBox(t, e, s, i, r, a, o, l, h) {
h[0] = Math.min(h[0], t, o), h[1] = Math.min(h[1], e, l), h[2] = Math.max(h[2], t, o), h[3] = Math.max(h[3], e, l), b(this, gi, kc).call(this, t, s, r, o, e, i, a, l, 3 * (-t + 3 * (s - r) + o), 6 * (t - 2 * s + r), 3 * (s - t), h), b(this, gi, kc).call(this, t, s, r, o, e, i, a, l, 3 * (-e + 3 * (i - a) + l), 6 * (e - 2 * i + a), 3 * (i - e), h);
}
}
gi = new WeakSet(), hh = function(t, e, s, i, r, a, o, l, h, c) {
if (h <= 0 || h >= 1)
return;
const u = 1 - h, p = h * h, g = p * h, A = u * (u * (u * t + 3 * h * e) + 3 * p * s) + g * i, y = u * (u * (u * r + 3 * h * a) + 3 * p * o) + g * l;
c[0] = Math.min(c[0], A), c[1] = Math.min(c[1], y), c[2] = Math.max(c[2], A), c[3] = Math.max(c[3], y);
}, kc = function(t, e, s, i, r, a, o, l, h, c, u, p) {
if (Math.abs(h) < 1e-12) {
Math.abs(c) >= 1e-12 && b(this, gi, hh).call(this, t, e, s, i, r, a, o, l, -u / c, p);
return;
}
const g = c ** 2 - 4 * u * h;
if (g < 0)
return;
const A = Math.sqrt(g), y = 2 * h;
b(this, gi, hh).call(this, t, e, s, i, r, a, o, l, (-c + A) / y, p), b(this, gi, hh).call(this, t, e, s, i, r, a, o, l, (-c - A) / y, p);
}, m($, gi);
function ng(d) {
return decodeURIComponent(escape(d));
}
let Cc = null, fu = null;
function rg(d) {
return Cc || (Cc = /([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu, fu = /* @__PURE__ */ new Map([["ſt", "ſt"]])), d.replaceAll(Cc, (t, e, s) => e ? e.normalize("NFKC") : fu.get(s));
}
function Bu() {
if (typeof crypto.randomUUID == "function")
return crypto.randomUUID();
const d = new Uint8Array(32);
return crypto.getRandomValues(d), Ou(d);
}
const Xd = "pdfjs_internal_id_";
function ag(d, t, e) {
if (!Array.isArray(e) || e.length < 2)
return !1;
const [s, i, ...r] = e;
if (!d(s) && !Number.isInteger(s) || !t(i))
return !1;
const a = r.length;
let o = !0;
switch (i.name) {
case "XYZ":
if (a < 2 || a > 3)
return !1;
break;
case "Fit":
case "FitB":
return a === 0;
case "FitH":
case "FitBH":
case "FitV":
case "FitBV":
if (a > 1)
return !1;
break;
case "FitR":
if (a !== 4)
return !1;
o = !1;
break;
default:
return !1;
}
for (const l of r)
if (!(typeof l == "number" || o && l === null))
return !1;
return !0;
}
function ae(d, t, e) {
return Math.min(Math.max(d, t), e);
}
function Hu(d) {
return Uint8Array.prototype.toBase64 ? d.toBase64() : btoa(Ou(d));
}
function og(d) {
return Uint8Array.fromBase64 ? Uint8Array.fromBase64(d) : Yl(atob(d));
}
typeof Promise.try != "function" && (Promise.try = function(d, ...t) {
return new Promise((e) => {
e(d(...t));
});
});
typeof Math.sumPrecise != "function" && (Math.sumPrecise = function(d) {
return d.reduce((t, e) => t + e, 0);
});
const ks = "http://www.w3.org/2000/svg", gn = class gn {
};
R(gn, "CSS", 96), R(gn, "PDF", 72), R(gn, "PDF_TO_CSS_UNITS", gn.CSS / gn.PDF);
let on = gn;
async function Kl(d, t = "text") {
if (Ja(d, document.baseURI)) {
const e = await fetch(d);
if (!e.ok)
throw new Error(e.statusText);
switch (t) {
case "arraybuffer":
return e.arrayBuffer();
case "blob":
return e.blob();
case "json":
return e.json();
}
return e.text();
}
return new Promise((e, s) => {
const i = new XMLHttpRequest();
i.open("GET", d, !0), i.responseType = t, i.onreadystatechange = () => {
if (i.readyState === XMLHttpRequest.DONE) {
if (i.status === 200 || i.status === 0) {
switch (t) {
case "arraybuffer":
case "blob":
case "json":
e(i.response);
return;
}
e(i.responseText);
return;
}
s(new Error(i.statusText));
}
}, i.send(null);
});
}
class Ql {
constructor({
viewBox: t,
userUnit: e,
scale: s,
rotation: i,
offsetX: r = 0,
offsetY: a = 0,
dontFlip: o = !1
}) {
this.viewBox = t, this.userUnit = e, this.scale = s, this.rotation = i, this.offsetX = r, this.offsetY = a, s *= e;
const l = (t[2] + t[0]) / 2, h = (t[3] + t[1]) / 2;
let c, u, p, g;
switch (i %= 360, i < 0 && (i += 360), i) {
case 180:
c = -1, u = 0, p = 0, g = 1;
break;
case 90:
c = 0, u = 1, p = 1, g = 0;
break;
case 270:
c = 0, u = -1, p = -1, g = 0;
break;
case 0:
c = 1, u = 0, p = 0, g = -1;
break;
default:
throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
}
o && (p = -p, g = -g);
let A, y, w, v;
c === 0 ? (A = Math.abs(h - t[1]) * s + r, y = Math.abs(l - t[0]) * s + a, w = (t[3] - t[1]) * s, v = (t[2] - t[0]) * s) : (A = Math.abs(l - t[0]) * s + r, y = Math.abs(h - t[1]) * s + a, w = (t[2] - t[0]) * s, v = (t[3] - t[1]) * s), this.transform = [c * s, u * s, p * s, g * s, A - c * s * l - p * s * h, y - u * s * l - g * s * h], this.width = w, this.height = v;
}
get rawDims() {
const t = this.viewBox;
return X(this, "rawDims", {
pageWidth: t[2] - t[0],
pageHeight: t[3] - t[1],
pageX: t[0],
pageY: t[1]
});
}
clone({
scale: t = this.scale,
rotation: e = this.rotation,
offsetX: s = this.offsetX,
offsetY: i = this.offsetY,
dontFlip: r = !1
} = {}) {
return new Ql({
viewBox: this.viewBox.slice(),
userUnit: this.userUnit,
scale: t,
rotation: e,
offsetX: s,
offsetY: i,
dontFlip: r
});
}
convertToViewportPoint(t, e) {
const s = [t, e];
return $.applyTransform(s, this.transform), s;
}
convertToViewportRectangle(t) {
const e = [t[0], t[1]];
$.applyTransform(e, this.transform);
const s = [t[2], t[3]];
return $.applyTransform(s, this.transform), [e[0], e[1], s[0], s[1]];
}
convertToPdfPoint(t, e) {
const s = [t, e];
return $.applyInverseTransform(s, this.transform), s;
}
}
class Yd extends Rr {
constructor(t, e = 0) {
super(t, "RenderingCancelledException"), this.extraDelay = e;
}
}
function mc(d) {
const t = d.length;
let e = 0;
for (; e < t && d[e].trim() === ""; )
e++;
return d.substring(e, e + 5).toLowerCase() === "data:";
}
function Kd(d) {
return typeof d == "string" && /\.pdf$/i.test(d);
}
function lg(d) {
return [d] = d.split(/[#?]/, 1), d.substring(d.lastIndexOf("/") + 1);
}
function hg(d, t = "document.pdf") {
if (typeof d != "string")
return t;
if (mc(d))
return U('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'), t;
const s = ((o) => {
try {
return new URL(o);
} catch {
try {
return new URL(decodeURIComponent(o));
} catch {
try {
return new URL(o, "https://foo.bar");
} catch {
try {
return new URL(decodeURIComponent(o), "https://foo.bar");
} catch {
return null;
}
}
}
}
})(d);
if (!s)
return t;
const i = (o) => {
try {
let l = decodeURIComponent(o);
return l.includes("/") ? (l = l.split("/").at(-1), l.test(/^\.pdf$/i) ? l : o) : l;
} catch {
return o;
}
}, r = /\.pdf$/i, a = s.pathname.split("/").at(-1);
if (r.test(a))
return i(a);
if (s.searchParams.size > 0) {
const o = Array.from(s.searchParams.values()).reverse();
for (const h of o)
if (r.test(h))
return i(h);
const l = Array.from(s.searchParams.keys()).reverse();
for (const h of l)
if (r.test(h))
return i(h);
}
if (s.hash) {
const l = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i.exec(s.hash);
if (l)
return i(l[0]);
}
return t;
}
class pu {
constructor() {
R(this, "started", /* @__PURE__ */ Object.create(null));
R(this, "times", []);
}
time(t) {
t in this.started && U(`Timer is already running for ${t}`), this.started[t] = Date.now();
}
timeEnd(t) {
t in this.started || U(`Timer has not been started for ${t}`), this.times.push({
name: t,
start: this.started[t],
end: Date.now()
}), delete this.started[t];
}
toString() {
const t = [];
let e = 0;
for (const {
name: s
} of this.times)
e = Math.max(s.length, e);
for (const {
name: s,
start: i,
end: r
} of this.times)
t.push(`${s.padEnd(e)} ${r - i}ms
`);
return t.join("");
}
}
function Ja(d, t) {
const e = t ? URL.parse(d, t) : URL.parse(d);
return (e == null ? void 0 : e.protocol) === "http:" || (e == null ? void 0 : e.protocol) === "https:";
}
function as(d) {
d.preventDefault();
}
function St(d) {
d.preventDefault(), d.stopPropagation();
}
function cg(d) {
console.log("Deprecated API usage: " + d);
}
var vo;
class Qd {
static toDateObject(t) {
if (!t || typeof t != "string")
return null;
n(this, vo) || f(this, vo, new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));
const e = n(this, vo).exec(t);
if (!e)
return null;
const s = parseInt(e[1], 10);
let i = parseInt(e[2], 10);
i = i >= 1 && i <= 12 ? i - 1 : 0;
let r = parseInt(e[3], 10);
r = r >= 1 && r <= 31 ? r : 1;
let a = parseInt(e[4], 10);
a = a >= 0 && a <= 23 ? a : 0;
let o = parseInt(e[5], 10);
o = o >= 0 && o <= 59 ? o : 0;
let l = parseInt(e[6], 10);
l = l >= 0 && l <= 59 ? l : 0;
const h = e[7] || "Z";
let c = parseInt(e[8], 10);
c = c >= 0 && c <= 23 ? c : 0;
let u = parseInt(e[9], 10) || 0;
return u = u >= 0 && u <= 59 ? u : 0, h === "-" ? (a += c, o += u) : h === "+" && (a -= c, o -= u), new Date(Date.UTC(s, i, r, a, o, l));
}
}
vo = new WeakMap(), m(Qd, vo);
function dg(d, {
scale: t = 1,
rotation: e = 0
}) {
const {
width: s,
height: i
} = d.attributes.style, r = [0, 0, parseInt(s), parseInt(i)];
return new Ql({
viewBox: r,
userUnit: 1,
scale: t,
rotation: e
});
}
function Jd(d) {
if (d.startsWith("#")) {
const t = parseInt(d.slice(1), 16);
return [(t & 16711680) >> 16, (t & 65280) >> 8, t & 255];
}
return d.startsWith("rgb(") ? d.slice(4, -1).split(",").map((t) => parseInt(t)) : d.startsWith("rgba(") ? d.slice(5, -1).split(",").map((t) => parseInt(t)).slice(0, 3) : (U(`Not a valid color format: "${d}"`), [0, 0, 0]);
}
function ug(d) {
const t = document.createElement("span");
t.style.visibility = "hidden", t.style.colorScheme = "only light", document.body.append(t);
for (const e of d.keys()) {
t.style.color = e;
const s = window.getComputedStyle(t).color;
d.set(e, Jd(s));
}
t.remove();
}
function pt(d) {
const {
a: t,
b: e,
c: s,
d: i,
e: r,
f: a
} = d.getTransform();
return [t, e, s, i, r, a];
}
function ls(d) {
const {
a: t,
b: e,
c: s,
d: i,
e: r,
f: a
} = d.getTransform().invertSelf();
return [t, e, s, i, r, a];
}
function Cr(d, t, e = !1, s = !0) {
if (t instanceof Ql) {
const {
pageWidth: i,
pageHeight: r
} = t.rawDims, {
style: a
} = d, o = Wt.isCSSRoundSupported, l = `var(--total-scale-factor) * ${i}px`, h = `var(--total-scale-factor) * ${r}px`, c = o ? `round(down, ${l}, var(--scale-round-x))` : `calc(${l})`, u = o ? `round(down, ${h}, var(--scale-round-y))` : `calc(${h})`;
!e || t.rotation % 180 === 0 ? (a.width = c, a.height = u) : (a.width = u, a.height = c);
}
s && d.setAttribute("data-main-rotation", t.rotation);
}
class Rs {
constructor() {
const {
pixelRatio: t
} = Rs;
this.sx = t, this.sy = t;
}
get scaled() {
return this.sx !== 1 || this.sy !== 1;
}
get symmetric() {
return this.sx === this.sy;
}
limitCanvas(t, e, s, i, r = -1) {
let a = 1 / 0, o = 1 / 0, l = 1 / 0;
s = Rs.capPixels(s, r), s > 0 && (a = Math.sqrt(s / (t * e))), i !== -1 && (o = i / t, l = i / e);
const h = Math.min(a, o, l);
return this.sx > h || this.sy > h ? (this.sx = h, this.sy = h, !0) : !1;
}
static get pixelRatio() {
return globalThis.devicePixelRatio || 1;
}
static capPixels(t, e) {
if (e >= 0) {
const s = Math.ceil(window.screen.availWidth * window.screen.availHeight * this.pixelRatio ** 2 * (1 + e / 100));
return t > 0 ? Math.min(t, s) : s;
}
return t;
}
}
const Lc = ["image/apng", "image/avif", "image/bmp", "image/gif", "image/jpeg", "image/png", "image/svg+xml", "image/webp", "image/x-icon"];
var _i, bn, Oe, Si, _o, zr, So, Xh, $u, oe, Gu, zu, Za, ch;
const Fs = class Fs {
constructor(t) {
m(this, oe);
m(this, _i, null);
m(this, bn, null);
m(this, Oe);
m(this, Si, null);
m(this, _o, null);
m(this, zr, null);
f(this, Oe, t), n(Fs, So) || f(Fs, So, Object.freeze({
freetext: "pdfjs-editor-remove-freetext-button",
highlight: "pdfjs-editor-remove-highlight-button",
ink: "pdfjs-editor-remove-ink-button",
stamp: "pdfjs-editor-remove-stamp-button",
signature: "pdfjs-editor-remove-signature-button"
}));
}
render() {
const t = f(this, _i, document.createElement("div"));
t.classList.add("editToolbar", "hidden"), t.setAttribute("role", "toolbar");
const e = n(this, Oe)._uiManager._signal;
t.addEventListener("contextmenu", as, {
signal: e
}), t.addEventListener("pointerdown", b(Fs, Xh, $u), {
signal: e
});
const s = f(this, Si, document.createElement("div"));
s.className = "buttons", t.append(s);
const i = n(this, Oe).toolbarPosition;
if (i) {
const {
style: r
} = t, a = n(this, Oe)._uiManager.direction === "ltr" ? 1 - i[0] : i[0];
r.insetInlineEnd = `${100 * a}%`, r.top = `calc(${100 * i[1]}% + var(--editor-toolbar-vert-offset))`;
}
return t;
}
get div() {
return n(this, _i);
}
hide() {
var t;
n(this, _i).classList.add("hidden"), (t = n(this, bn)) == null || t.hideDropdown();
}
show() {
var t;
n(this, _i).classList.remove("hidden"), (t = n(this, _o)) == null || t.shown();
}
addDeleteButton() {
const {
editorType: t,
_uiManager: e
} = n(this, Oe), s = document.createElement("button");
s.className = "delete", s.tabIndex = 0, s.setAttribute("data-l10n-id", n(Fs, So)[t]), b(this, oe, Za).call(this, s), s.addEventListener("click", (i) => {
e.delete();
}, {
signal: e._signal
}), n(this, Si).append(s);
}
async addAltText(t) {
const e = await t.render();
b(this, oe, Za).call(this, e), n(this, Si).append(e, n(this, oe, ch)), f(this, _o, t);
}
addColorPicker(t) {
f(this, bn, t);
const e = t.renderButton();
b(this, oe, Za).call(this, e), n(this, Si).append(e, n(this, oe, ch));
}
async addEditSignatureButton(t) {
const e = f(this, zr, await t.renderEditButton(n(this, Oe)));
b(this, oe, Za).call(this, e), n(this, Si).append(e, n(this, oe, ch));
}
async addButton(t, e) {
switch (t) {
case "colorPicker":
this.addColorPicker(e);
break;
case "altText":
await this.addAltText(e);
break;
case "editSignature":
await this.addEditSignatureButton(e);
break;
case "delete":
this.addDeleteButton();
break;
}
}
updateEditSignatureButton(t) {
n(this, zr) && (n(this, zr).title = t);
}
remove() {
var t;
n(this, _i).remove(), (t = n(this, bn)) == null || t.destroy(), f(this, bn, null);
}
};
_i = new WeakMap(), bn = new WeakMap(), Oe = new WeakMap(), Si = new WeakMap(), _o = new WeakMap(), zr = new WeakMap(), So = new WeakMap(), Xh = new WeakSet(), $u = function(t) {
t.stopPropagation();
}, oe = new WeakSet(), Gu = function(t) {
n(this, Oe)._focusEventsAllowed = !1, St(t);
}, zu = function(t) {
n(this, Oe)._focusEventsAllowed = !0, St(t);
}, Za = function(t) {
const e = n(this, Oe)._uiManager._signal;
t.addEventListener("focusin", b(this, oe, Gu).bind(this), {
capture: !0,
signal: e
}), t.addEventListener("focusout", b(this, oe, zu).bind(this), {
capture: !0,
signal: e
}), t.addEventListener("contextmenu", as, {
signal: e
});
}, ch = function() {
const t = document.createElement("div");
return t.className = "divider", t;
}, m(Fs, Xh), m(Fs, So, null);
let Dc = Fs;
var Eo, An, yn, ln, Uu, ju, Vu;
class fg {
constructor(t) {
m(this, ln);
m(this, Eo, null);
m(this, An, null);
m(this, yn);
f(this, yn, t);
}
show(t, e, s) {
const [i, r] = b(this, ln, ju).call(this, e, s), {
style: a
} = n(this, An) || f(this, An, b(this, ln, Uu).call(this));
t.append(n(this, An)), a.insetInlineEnd = `${100 * i}%`, a.top = `calc(${100 * r}% + var(--editor-toolbar-vert-offset))`;
}
hide() {
n(this, An).remove();
}
}
Eo = new WeakMap(), An = new WeakMap(), yn = new WeakMap(), ln = new WeakSet(), Uu = function() {
const t = f(this, An, document.createElement("div"));
t.className = "editToolbar", t.setAttribute("role", "toolbar"), t.addEventListener("contextmenu", as, {
signal: n(this, yn)._signal
});
const e = f(this, Eo, document.createElement("div"));
return e.className = "buttons", t.append(e), b(this, ln, Vu).call(this), t;
}, ju = function(t, e) {
let s = 0, i = 0;
for (const r of t) {
const a = r.y + r.height;
if (a < s)
continue;
const o = r.x + (e ? r.width : 0);
if (a > s) {
i = o, s = a;
continue;
}
e ? o > i && (i = o) : o < i && (i = o);
}
return [e ? 1 - i : i, s];
}, Vu = function() {
const t = document.createElement("button");
t.className = "highlightButton", t.tabIndex = 0, t.setAttribute("data-l10n-id", "pdfjs-highlight-floating-button1");
const e = document.createElement("span");
t.append(e), e.className = "visuallyHidden", e.setAttribute("data-l10n-id", "pdfjs-highlight-floating-button-label");
const s = n(this, yn)._signal;
t.addEventListener("contextmenu", as, {
signal: s
}), t.addEventListener("click", () => {
n(this, yn).highlightSelection("floating_button");
}, {
signal: s
}), n(this, Eo).append(t);
};
function Wu(d, t, e) {
for (const s of e)
t.addEventListener(s, d[s].bind(d));
}
var Yh;
class pg {
constructor() {
m(this, Yh, 0);
}
get id() {
return `${Du}${Zt(this, Yh)._++}`;
}
}
Yh = new WeakMap();
var Ur, Co, Yt, jr, dh;
const ru = class ru {
constructor() {
m(this, jr);
m(this, Ur, Bu());
m(this, Co, 0);
m(this, Yt, null);
}
static get _isSVGFittingCanvas() {
const t = 'data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" style="fill:red;"/></svg>', s = new OffscreenCanvas(1, 3).getContext("2d", {
willReadFrequently: !0
}), i = new Image();
i.src = t;
const r = i.decode().then(() => (s.drawImage(i, 0, 0, 1, 1, 0, 0, 1, 3), new Uint32Array(s.getImageData(0, 0, 1, 1).data.buffer)[0] === 0));
return X(this, "_isSVGFittingCanvas", r);
}
async getFromFile(t) {
const {
lastModified: e,
name: s,
size: i,
type: r
} = t;
return b(this, jr, dh).call(this, `${e}_${s}_${i}_${r}`, t);
}
async getFromUrl(t) {
return b(this, jr, dh).call(this, t, t);
}
async getFromBlob(t, e) {
const s = await e;
return b(this, jr, dh).call(this, t, s);
}
async getFromId(t) {
n(this, Yt) || f(this, Yt, /* @__PURE__ */ new Map());
const e = n(this, Yt).get(t);
if (!e)
return null;
if (e.bitmap)
return e.refCounter += 1, e;
if (e.file)
return this.getFromFile(e.file);
if (e.blobPromise) {
const {
blobPromise: s
} = e;
return delete e.blobPromise, this.getFromBlob(e.id, s);
}
return this.getFromUrl(e.url);
}
getFromCanvas(t, e) {
n(this, Yt) || f(this, Yt, /* @__PURE__ */ new Map());
let s = n(this, Yt).get(t);
if (s != null && s.bitmap)
return s.refCounter += 1, s;
const i = new OffscreenCanvas(e.width, e.height);
return i.getContext("2d").drawImage(e, 0, 0), s = {
bitmap: i.transferToImageBitmap(),
id: `image_${n(this, Ur)}_${Zt(this, Co)._++}`,
refCounter: 1,
isSvg: !1
}, n(this, Yt).set(t, s), n(this, Yt).set(s.id, s), s;
}
getSvgUrl(t) {
const e = n(this, Yt).get(t);
return e != null && e.isSvg ? e.svgUrl : null;
}
deleteId(t) {
var i;
n(this, Yt) || f(this, Yt, /* @__PURE__ */ new Map());
const e = n(this, Yt).get(t);
if (!e || (e.refCounter -= 1, e.refCounter !== 0))
return;
const {
bitmap: s
} = e;
if (!e.url && !e.file) {
const r = new OffscreenCanvas(s.width, s.height);
r.getContext("bitmaprenderer").transferFromImageBitmap(s), e.blobPromise = r.convertToBlob();
}
(i = s.close) == null || i.call(s), e.bitmap = null;
}
isValidId(t) {
return t.startsWith(`image_${n(this, Ur)}_`);
}
};
Ur = new WeakMap(), Co = new WeakMap(), Yt = new WeakMap(), jr = new WeakSet(), dh = async function(t, e) {
n(this, Yt) || f(this, Yt, /* @__PURE__ */ new Map());
let s = n(this, Yt).get(t);
if (s === null)
return null;
if (s != null && s.bitmap)
return s.refCounter += 1, s;
try {
s || (s = {
bitmap: null,
id: `image_${n(this, Ur)}_${Zt(this, Co)._++}`,
refCounter: 0,
isSvg: !1
});
let i;
if (typeof e == "string" ? (s.url = e, i = await Kl(e, "blob")) : e instanceof File ? i = s.file = e : e instanceof Blob && (i = e), i.type === "image/svg+xml") {
const r = ru._isSVGFittingCanvas, a = new FileReader(), o = new Image(), l = new Promise((h, c) => {
o.onload = () => {
s.bitmap = o, s.isSvg = !0, h();
}, a.onload = async () => {
const u = s.svgUrl = a.result;
o.src = await r ? `${u}#svgView(preserveAspectRatio(none))` : u;
}, o.onerror = a.onerror = c;
});
a.readAsDataURL(i), await l;
} else
s.bitmap = await createImageBitmap(i);
s.refCounter = 1;
} catch (i) {
U(i), s = null;
}
return n(this, Yt).set(t, s), s && n(this, Yt).set(s.id, s), s;
};
let Fc = ru;
var At, Ei, xo, ft;
class gg {
constructor(t = 128) {
m(this, At, []);
m(this, Ei, !1);
m(this, xo);
m(this, ft, -1);
f(this, xo, t);
}
add({
cmd: t,
undo: e,
post: s,
mustExec: i,
type: r = NaN,
overwriteIfSameType: a = !1,
keepUndo: o = !1
}) {
if (i && t(), n(this, Ei))
return;
const l = {
cmd: t,
undo: e,
post: s,
type: r
};
if (n(this, ft) === -1) {
n(this, At).length > 0 && (n(this, At).length = 0), f(this, ft, 0), n(this, At).push(l);
return;
}
if (a && n(this, At)[n(this, ft)].type === r) {
o && (l.undo = n(this, At)[n(this, ft)].undo), n(this, At)[n(this, ft)] = l;
return;
}
const h = n(this, ft) + 1;
h === n(this, xo) ? n(this, At).splice(0, 1) : (f(this, ft, h), h < n(this, At).length && n(this, At).splice(h)), n(this, At).push(l);
}
undo() {
if (n(this, ft) === -1)
return;
f(this, Ei, !0);
const {
undo: t,
post: e
} = n(this, At)[n(this, ft)];
t(), e == null || e(), f(this, Ei, !1), f(this, ft, n(this, ft) - 1);
}
redo() {
if (n(this, ft) < n(this, At).length - 1) {
f(this, ft, n(this, ft) + 1), f(this, Ei, !0);
const {
cmd: t,
post: e
} = n(this, At)[n(this, ft)];
t(), e == null || e(), f(this, Ei, !1);
}
}
hasSomethingToUndo() {
return n(this, ft) !== -1;
}
hasSomethingToRedo() {
return n(this, ft) < n(this, At).length - 1;
}
cleanType(t) {
if (n(this, ft) !== -1) {
for (let e = n(this, ft); e >= 0; e--)
if (n(this, At)[e].type !== t) {
n(this, At).splice(e + 1, n(this, ft) - e), f(this, ft, e);
return;
}
n(this, At).length = 0, f(this, ft, -1);
}
}
destroy() {
f(this, At, null);
}
}
At = new WeakMap(), Ei = new WeakMap(), xo = new WeakMap(), ft = new WeakMap();
var Kh, qu;
class Jl {
constructor(t) {
m(this, Kh);
this.buffer = [], this.callbacks = /* @__PURE__ */ new Map(), this.allKeys = /* @__PURE__ */ new Set();
const {
isMac: e
} = Wt.platform;
for (const [s, i, r = {}] of t)
for (const a of s) {
const o = a.startsWith("mac+");
e && o ? (this.callbacks.set(a.slice(4), {
callback: i,
options: r
}), this.allKeys.add(a.split("+").at(-1))) : !e && !o && (this.callbacks.set(a, {
callback: i,
options: r
}), this.allKeys.add(a.split("+").at(-1)));
}
}
exec(t, e) {
if (!this.allKeys.has(e.key))
return;
const s = this.callbacks.get(b(this, Kh, qu).call(this, e));
if (!s)
return;
const {
callback: i,
options: {
bubbles: r = !1,
args: a = [],
checker: o = null
}
} = s;
o && !o(t, e) || (i.bind(t, ...a, e)(), r || St(e));
}
}
Kh = new WeakSet(), qu = function(t) {
t.altKey && this.buffer.push("alt"), t.ctrlKey && this.buffer.push("ctrl"), t.metaKey && this.buffer.push("meta"), t.shiftKey && this.buffer.push("shift"), this.buffer.push(t.key);
const e = this.buffer.join("+");
return this.buffer.length = 0, e;
};
const Qh = class Qh {
get _colors() {
const t = /* @__PURE__ */ new Map([["CanvasText", null], ["Canvas", null]]);
return ug(t), X(this, "_colors", t);
}
convert(t) {
const e = Jd(t);
if (!window.matchMedia("(forced-colors: active)").matches)
return e;
for (const [s, i] of this._colors)
if (i.every((r, a) => r === e[a]))
return Qh._colorsMapping.get(s);
return e;
}
getHexCode(t) {
const e = this._colors.get(t);
return e ? $.makeHexColor(...e) : t;
}
};
R(Qh, "_colorsMapping", /* @__PURE__ */ new Map([["CanvasText", [0, 0, 0]], ["Canvas", [255, 255, 255]]]));
let Nc = Qh;
var Vr, be, Rt, Ht, Wr, Os, qr, Be, Ci, xi, Xr, wn, ds, qe, vn, To, Ro, Yr, Po, us, Ti, Kr, Ri, fs, Jh, Pi, Io, Ii, _n, Sn, Mi, Mo, kt, et, Bs, ki, En, ko, Lo, Li, ps, Hs, Do, Fo, He, I, uh, Oc, Xu, Yu, fh, Ku, Qu, Ju, Bc, Zu, Hc, $c, tf, te, Ls, ef, sf, Gc, nf, to, zc;
const Hr = class Hr {
constructor(t, e, s, i, r, a, o, l, h, c, u, p, g, A, y) {
m(this, I);
m(this, Vr, new AbortController());
m(this, be, null);
m(this, Rt, /* @__PURE__ */ new Map());
m(this, Ht, /* @__PURE__ */ new Map());
m(this, Wr, null);
m(this, Os, null);
m(this, qr, null);
m(this, Be, new gg());
m(this, Ci, null);
m(this, xi, null);
m(this, Xr, 0);
m(this, wn, /* @__PURE__ */ new Set());
m(this, ds, null);
m(this, qe, null);
m(this, vn, /* @__PURE__ */ new Set());
R(this, "_editorUndoBar", null);
m(this, To, !1);
m(this, Ro, !1);
m(this, Yr, !1);
m(this, Po, null);
m(this, us, null);
m(this, Ti, null);
m(this, Kr, null);
m(this, Ri, !1);
m(this, fs, null);
m(this, Jh, new pg());
m(this, Pi, !1);
m(this, Io, !1);
m(this, Ii, null);
m(this, _n, null);
m(this, Sn, null);
m(this, Mi, null);
m(this, Mo, null);
m(this, kt, z.NONE);
m(this, et, /* @__PURE__ */ new Set());
m(this, Bs, null);
m(this, ki, null);
m(this, En, null);
m(this, ko, null);
m(this, Lo, {
isEditing: !1,
isEmpty: !0,
hasSomethingToUndo: !1,
hasSomethingToRedo: !1,
hasSelectedEditor: !1,
hasSelectedText: !1
});
m(this, Li, [0, 0]);
m(this, ps, null);
m(this, Hs, null);
m(this, Do, null);
m(this, Fo, null);
m(this, He, null);
const w = this._signal = n(this, Vr).signal;
f(this, Hs, t), f(this, Do, e), f(this, Fo, s), f(this, Wr, i), f(this, ki, r), this._eventBus = a, a._on("editingaction", this.onEditingAction.bind(this), {
signal: w
}), a._on("pagechanging", this.onPageChanging.bind(this), {
signal: w
}), a._on("scalechanging", this.onScaleChanging.bind(this), {
signal: w
}), a._on("rotationchanging", this.onRotationChanging.bind(this), {
signal: w
}), a._on("setpreference", this.onSetPreference.bind(this), {
signal: w
}), a._on("switchannotationeditorparams", (v) => this.updateParams(v.type, v.value), {
signal: w
}), b(this, I, Ku).call(this), b(this, I, tf).call(this), b(this, I, Bc).call(this), f(this, Os, o.annotationStorage), f(this, Po, o.filterFactory), f(this, En, l), f(this, Kr, h || null), f(this, To, c), f(this, Ro, u), f(this, Yr, p), f(this, Mo, g || null), this.viewParameters = {
realScale: on.PDF_TO_CSS_UNITS,
rotation: 0
}, this.isShiftKeyDown = !1, this._editorUndoBar = A || null, this._supportsPinchToZoom = y !== !1;
}
static get _keyboardManager() {
const t = Hr.prototype, e = (a) => n(a, Hs).contains(document.activeElement) && document.activeElement.tagName !== "BUTTON" && a.hasSomethingToControl(), s = (a, {
target: o
}) => {
if (o instanceof HTMLInputElement) {
const {
type: l
} = o;
return l !== "text" && l !== "number";
}
return !0;
}, i = this.TRANSLATE_SMALL, r = this.TRANSLATE_BIG;
return X(this, "_keyboardManager", new Jl([[["ctrl+a", "mac+meta+a"], t.selectAll, {
checker: s
}], [["ctrl+z", "mac+meta+z"], t.undo, {
checker: s
}], [["ctrl+y", "ctrl+shift+z", "mac+meta+shift+z", "ctrl+shift+Z", "mac+meta+shift+Z"], t.redo, {
checker: s
}], [["Backspace", "alt+Backspace", "ctrl+Backspace", "shift+Backspace", "mac+Backspace", "mac+alt+Backspace", "mac+ctrl+Backspace", "Delete", "ctrl+Delete", "shift+Delete", "mac+Delete"], t.delete, {
checker: s
}], [["Enter", "mac+Enter"], t.addNewEditorFromKeyboard, {
checker: (a, {
target: o
}) => !(o instanceof HTMLButtonElement) && n(a, Hs).contains(o) && !a.isEnterHandled
}], [[" ", "mac+ "], t.addNewEditorFromKeyboard, {
checker: (a, {
target: o
}) => !(o instanceof HTMLButtonElement) && n(a, Hs).contains(document.activeElement)
}], [["Escape", "mac+Escape"], t.unselectAll], [["ArrowLeft", "mac+ArrowLeft"], t.translateSelectedEditors, {
args: [-i, 0],
checker: e
}], [["ctrl+ArrowLeft", "mac+shift+ArrowLeft"], t.translateSelectedEditors, {
args: [-r, 0],
checker: e
}], [["ArrowRight", "mac+ArrowRight"], t.translateSelectedEditors, {
args: [i, 0],
checker: e
}], [["ctrl+ArrowRight", "mac+shift+ArrowRight"], t.translateSelectedEditors, {
args: [r, 0],
checker: e
}], [["ArrowUp", "mac+ArrowUp"], t.translateSelectedEditors, {
args: [0, -i],
checker: e
}], [["ctrl+ArrowUp", "mac+shift+ArrowUp"], t.translateSelectedEditors, {
args: [0, -r],
checker: e
}], [["ArrowDown", "mac+ArrowDown"], t.translateSelectedEditors, {
args: [0, i],
checker: e
}], [["ctrl+ArrowDown", "mac+shift+ArrowDown"], t.translateSelectedEditors, {
args: [0, r],
checker: e
}]]));
}
destroy() {
var t, e, s, i, r, a, o, l;
(t = n(this, He)) == null || t.resolve(), f(this, He, null), (e = n(this, Vr)) == null || e.abort(), f(this, Vr, null), this._signal = null;
for (const h of n(this, Ht).values())
h.destroy();
n(this, Ht).clear(), n(this, Rt).clear(), n(this, vn).clear(), (s = n(this, Mi)) == null || s.clear(), f(this, be, null), n(this, et).clear(), n(this, Be).destroy(), (i = n(this, Wr)) == null || i.destroy(), (r = n(this, ki)) == null || r.destroy(), (a = n(this, fs)) == null || a.hide(), f(this, fs, null), (o = n(this, Sn)) == null || o.destroy(), f(this, Sn, null), n(this, us) && (clearTimeout(n(this, us)), f(this, us, null)), n(this, ps) && (clearTimeout(n(this, ps)), f(this, ps, null)), (l = this._editorUndoBar) == null || l.destroy();
}
combinedSignal(t) {
return AbortSignal.any([this._signal, t.signal]);
}
get mlManager() {
return n(this, Mo);
}
get useNewAltTextFlow() {
return n(this, Ro);
}
get useNewAltTextWhenAddingImage() {
return n(this, Yr);
}
get hcmFilter() {
return X(this, "hcmFilter", n(this, En) ? n(this, Po).addHCMFilter(n(this, En).foreground, n(this, En).background) : "none");
}
get direction() {
return X(this, "direction", getComputedStyle(n(this, Hs)).direction);
}
get highlightColors() {
return X(this, "highlightColors", n(this, Kr) ? new Map(n(this, Kr).split(",").map((t) => (t = t.split("=").map((e) => e.trim()), t[1] = t[1].toUpperCase(), t))) : null);
}
get highlightColorNames() {
return X(this, "highlightColorNames", this.highlightColors ? new Map(Array.from(this.highlightColors, (t) => t.reverse())) : null);
}
setCurrentDrawingSession(t) {
t ? (this.unselectAll(), this.disableUserSelect(!0)) : this.disableUserSelect(!1), f(this, xi, t);
}
setMainHighlightColorPicker(t) {
f(this, Sn, t);
}
editAltText(t, e = !1) {
var s;
(s = n(this, Wr)) == null || s.editAltText(this, t, e);
}
getSignature(t) {
var e;
(e = n(this, ki)) == null || e.getSignature({
uiManager: this,
editor: t
});
}
get signatureManager() {
return n(this, ki);
}
switchToMode(t, e) {
this._eventBus.on("annotationeditormodechanged", e, {
once: !0,
signal: this._signal
}), this._eventBus.dispatch("showannotationeditorui", {
source: this,
mode: t
});
}
setPreference(t, e) {
this._eventBus.dispatch("setpreference", {
source: this,
name: t,
value: e
});
}
onSetPreference({
name: t,
value: e
}) {
switch (t) {
case "enableNewAltTextWhenAddingImage":
f(this, Yr, e);
break;
}
}
onPageChanging({
pageNumber: t
}) {
f(this, Xr, t - 1);
}
focusMainContainer() {
n(this, Hs).focus();
}
findParent(t, e) {
for (const s of n(this, Ht).values()) {
const {
x: i,
y: r,
width: a,
height: o
} = s.div.getBoundingClientRect();
if (t >= i && t <= i + a && e >= r && e <= r + o)
return s;
}
return null;
}
disableUserSelect(t = !1) {
n(this, Do).classList.toggle("noUserSelect", t);
}
addShouldRescale(t) {
n(this, vn).add(t);
}
removeShouldRescale(t) {
n(this, vn).delete(t);
}
onScaleChanging({
scale: t
}) {
var e;
this.commitOrRemove(), this.viewParameters.realScale = t * on.PDF_TO_CSS_UNITS;
for (const s of n(this, vn))
s.onScaleChanging();
(e = n(this, xi)) == null || e.onScaleChanging();
}
onRotationChanging({
pagesRotation: t
}) {
this.commitOrRemove(), this.viewParameters.rotation = t;
}
highlightSelection(t = "") {
const e = document.getSelection();
if (!e || e.isCollapsed)
return;
const {
anchorNode: s,
anchorOffset: i,
focusNode: r,
focusOffset: a
} = e, o = e.toString(), h = b(this, I, uh).call(this, e).closest(".textLayer"), c = this.getSelectionBoxes(h);
if (!c)
return;
e.empty();
const u = b(this, I, Oc).call(this, h), p = n(this, kt) === z.NONE, g = () => {
u == null || u.createAndAddNewEditor({
x: 0,
y: 0
}, !1, {
methodOfCreation: t,
boxes: c,
anchorNode: s,
anchorOffset: i,
focusNode: r,
focusOffset: a,
text: o
}), p && this.showAllEditors("highlight", !0, !0);
};
if (p) {
this.switchToMode(z.HIGHLIGHT, g);
return;
}
g();
}
addToAnnotationStorage(t) {
!t.isEmpty() && n(this, Os) && !n(this, Os).has(t.id) && n(this, Os).setValue(t.id, t);
}
a11yAlert(t, e = null) {
const s = n(this, Fo);
s && (s.setAttribute("data-l10n-id", t), e ? s.setAttribute("data-l10n-args", JSON.stringify(e)) : s.removeAttribute("data-l10n-args"));
}
blur() {
if (this.isShiftKeyDown = !1, n(this, Ri) && (f(this, Ri, !1), b(this, I, fh).call(this, "main_toolbar")), !this.hasSelection)
return;
const {
activeElement: t
} = document;
for (const e of n(this, et))
if (e.div.contains(t)) {
f(this, _n, [e, t]), e._focusEventsAllowed = !1;
break;
}
}
focus() {
if (!n(this, _n))
return;
const [t, e] = n(this, _n);
f(this, _n, null), e.addEventListener("focusin", () => {
t._focusEventsAllowed = !0;
}, {
once: !0,
signal: this._signal
}), e.focus();
}
addEditListeners() {
b(this, I, Bc).call(this), b(this, I, Hc).call(this);
}
removeEditListeners() {
b(this, I, Zu).call(this), b(this, I, $c).call(this);
}
dragOver(t) {
for (const {
type: e
} of t.dataTransfer.items)
for (const s of n(this, qe))
if (s.isHandlingMimeForPasting(e)) {
t.dataTransfer.dropEffect = "copy", t.preventDefault();
return;
}
}
drop(t) {
for (const e of t.dataTransfer.items)
for (const s of n(this, qe))
if (s.isHandlingMimeForPasting(e.type)) {
s.paste(e, this.currentLayer), t.preventDefault();
return;
}
}
copy(t) {
var s;
if (t.preventDefault(), (s = n(this, be)) == null || s.commitOrRemove(), !this.hasSelection)
return;
const e = [];
for (const i of n(this, et)) {
const r = i.serialize(!0);
r && e.push(r);
}
e.length !== 0 && t.clipboardData.setData("application/pdfjs", JSON.stringify(e));
}
cut(t) {
this.copy(t), this.delete();
}
async paste(t) {
t.preventDefault();
const {
clipboardData: e
} = t;
for (const r of e.items)
for (const a of n(this, qe))
if (a.isHandlingMimeForPasting(r.type)) {
a.paste(r, this.currentLayer);
return;
}
let s = e.getData("application/pdfjs");
if (!s)
return;
try {
s = JSON.parse(s);
} catch (r) {
U(`paste: "${r.message}".`);
return;
}
if (!Array.isArray(s))
return;
this.unselectAll();
const i = this.currentLayer;
try {
const r = [];
for (const l of s) {
const h = await i.deserialize(l);
if (!h)
return;
r.push(h);
}
const a = () => {
for (const l of r)
b(this, I, Gc).call(this, l);
b(this, I, zc).call(this, r);
}, o = () => {
for (const l of r)
l.remove();
};
this.addCommands({
cmd: a,
undo: o,
mustExec: !0
});
} catch (r) {
U(`paste: "${r.message}".`);
}
}
keydown(t) {
!this.isShiftKeyDown && t.key === "Shift" && (this.isShiftKeyDown = !0), n(this, kt) !== z.NONE && !this.isEditorHandlingKeyboard && Hr._keyboardManager.exec(this, t);
}
keyup(t) {
this.isShiftKeyDown && t.key === "Shift" && (this.isShiftKeyDown = !1, n(this, Ri) && (f(this, Ri, !1), b(this, I, fh).call(this, "main_toolbar")));
}
onEditingAction({
name: t
}) {
switch (t) {
case "undo":
case "redo":
case "delete":
case "selectAll":
this[t]();
break;
case "highlightSelection":
this.highlightSelection("context_menu");
break;
}
}
setEditingState(t) {
t ? (b(this, I, Qu).call(this), b(this, I, Hc).call(this), b(this, I, te).call(this, {
isEditing: n(this, kt) !== z.NONE,
isEmpty: b(this, I, to).call(this),
hasSomethingToUndo: n(this, Be).hasSomethingToUndo(),
hasSomethingToRedo: n(this, Be).hasSomethingToRedo(),
hasSelectedEditor: !1
})) : (b(this, I, Ju).call(this), b(this, I, $c).call(this), b(this, I, te).call(this, {
isEditing: !1
}), this.disableUserSelect(!1));
}
registerEditorTypes(t) {
if (!n(this, qe)) {
f(this, qe, t);
for (const e of n(this, qe))
b(this, I, Ls).call(this, e.defaultPropertiesToUpdate);
}
}
getId() {
return n(this, Jh).id;
}
get currentLayer() {
return n(this, Ht).get(n(this, Xr));
}
getLayer(t) {
return n(this, Ht).get(t);
}
get currentPageIndex() {
return n(this, Xr);
}
addLayer(t) {
n(this, Ht).set(t.pageIndex, t), n(this, Pi) ? t.enable() : t.disable();
}
removeLayer(t) {
n(this, Ht).delete(t.pageIndex);
}
async updateMode(t, e = null, s = !1, i = !1) {
var r, a, o;
if (n(this, kt) !== t && !(n(this, He) && (await n(this, He).promise, !n(this, He)))) {
if (f(this, He, Promise.withResolvers()), (r = n(this, xi)) == null || r.commitOrRemove(), f(this, kt, t), t === z.NONE) {
this.setEditingState(!1), b(this, I, sf).call(this), (a = this._editorUndoBar) == null || a.hide(), n(this, He).resolve();
return;
}
t === z.SIGNATURE && await ((o = n(this, ki)) == null ? void 0 : o.loadSignatures()), this.setEditingState(!0), await b(this, I, ef).call(this), this.unselectAll();
for (const l of n(this, Ht).values())
l.updateMode(t);
if (!e) {
s && this.addNewEditorFromKeyboard(), n(this, He).resolve();
return;
}
for (const l of n(this, Rt).values())
l.annotationElementId === e || l.id === e ? (this.setSelected(l), i && l.enterInEditMode()) : l.unselect();
n(this, He).resolve();
}
}
addNewEditorFromKeyboard() {
this.currentLayer.canCreateNewEmptyEditor() && this.currentLayer.addNewEditor();
}
updateToolbar(t) {
t.mode !== n(this, kt) && this._eventBus.dispatch("switchannotationeditormode", {
source: this,
...t
});
}
updateParams(t, e) {
var s;
if (n(this, qe)) {
switch (t) {
case Y.CREATE:
this.currentLayer.addNewEditor(e);
return;
case Y.HIGHLIGHT_DEFAULT_COLOR:
(s = n(this, Sn)) == null || s.updateColor(e);
break;
case Y.HIGHLIGHT_SHOW_ALL:
this._eventBus.dispatch("reporttelemetry", {
source: this,
details: {
type: "editing",
data: {
type: "highlight",
action: "toggle_visibility"
}
}
}), (n(this, ko) || f(this, ko, /* @__PURE__ */ new Map())).set(t, e), this.showAllEditors("highlight", e);
break;
}
for (const i of n(this, et))
i.updateParams(t, e);
for (const i of n(this, qe))
i.updateDefaultParams(t, e);
}
}
showAllEditors(t, e, s = !1) {
var r;
for (const a of n(this, Rt).values())
a.editorType === t && a.show(e);
(((r = n(this, ko)) == null ? void 0 : r.get(Y.HIGHLIGHT_SHOW_ALL)) ?? !0) !== e && b(this, I, Ls).call(this, [[Y.HIGHLIGHT_SHOW_ALL, e]]);
}
enableWaiting(t = !1) {
if (n(this, Io) !== t) {
f(this, Io, t);
for (const e of n(this, Ht).values())
t ? e.disableClick() : e.enableClick(), e.div.classList.toggle("waiting", t);
}
}
getEditors(t) {
const e = [];
for (const s of n(this, Rt).values())
s.pageIndex === t && e.push(s);
return e;
}
getEditor(t) {
return n(this, Rt).get(t);
}
addEditor(t) {
n(this, Rt).set(t.id, t);
}
removeEditor(t) {
var e, s;
t.div.contains(document.activeElement) && (n(this, us) && clearTimeout(n(this, us)), f(this, us, setTimeout(() => {
this.focusMainContainer(), f(this, us, null);
}, 0))), n(this, Rt).delete(t.id), t.annotationElementId && ((e = n(this, Mi)) == null || e.delete(t.annotationElementId)), this.unselect(t), (!t.annotationElementId || !n(this, wn).has(t.annotationElementId)) && ((s = n(this, Os)) == null || s.remove(t.id));
}
addDeletedAnnotationElement(t) {
n(this, wn).add(t.annotationElementId), this.addChangedExistingAnnotation(t), t.deleted = !0;
}
isDeletedAnnotationElement(t) {
return n(this, wn).has(t);
}
removeDeletedAnnotationElement(t) {
n(this, wn).delete(t.annotationElementId), this.removeChangedExistingAnnotation(t), t.deleted = !1;
}
setActiveEditor(t) {
n(this, be) !== t && (f(this, be, t), t && b(this, I, Ls).call(this, t.propertiesToUpdate));
}
updateUI(t) {
n(this, I, nf) === t && b(this, I, Ls).call(this, t.propertiesToUpdate);
}
updateUIForDefaultProperties(t) {
b(this, I, Ls).call(this, t.defaultPropertiesToUpdate);
}
toggleSelected(t) {
if (n(this, et).has(t)) {
n(this, et).delete(t), t.unselect(), b(this, I, te).call(this, {
hasSelectedEditor: this.hasSelection
});
return;
}
n(this, et).add(t), t.select(), b(this, I, Ls).call(this, t.propertiesToUpdate), b(this, I, te).call(this, {
hasSelectedEditor: !0
});
}
setSelected(t) {
var e;
this.updateToolbar({
mode: t.mode,
editId: t.id
}), (e = n(this, xi)) == null || e.commitOrRemove();
for (const s of n(this, et))
s !== t && s.unselect();
n(this, et).clear(), n(this, et).add(t), t.select(), b(this, I, Ls).call(this, t.propertiesToUpdate), b(this, I, te).call(this, {
hasSelectedEditor: !0
});
}
isSelected(t) {
return n(this, et).has(t);
}
get firstSelectedEditor() {
return n(this, et).values().next().value;
}
unselect(t) {
t.unselect(), n(this, et).delete(t), b(this, I, te).call(this, {
hasSelectedEditor: this.hasSelection
});
}
get hasSelection() {
return n(this, et).size !== 0;
}
get isEnterHandled() {
return n(this, et).size === 1 && this.firstSelectedEditor.isEnterHandled;
}
undo() {
var t;
n(this, Be).undo(), b(this, I, te).call(this, {
hasSomethingToUndo: n(this, Be).hasSomethingToUndo(),
hasSomethingToRedo: !0,
isEmpty: b(this, I, to).call(this)
}), (t = this._editorUndoBar) == null || t.hide();
}
redo() {
n(this, Be).redo(), b(this, I, te).call(this, {
hasSomethingToUndo: !0,
hasSomethingToRedo: n(this, Be).hasSomethingToRedo(),
isEmpty: b(this, I, to).call(this)
});
}
addCommands(t) {
n(this, Be).add(t), b(this, I, te).call(this, {
hasSomethingToUndo: !0,
hasSomethingToRedo: !1,
isEmpty: b(this, I, to).call(this)
});
}
cleanUndoStack(t) {
n(this, Be).cleanType(t);
}
delete() {
var r;
this.commitOrRemove();
const t = (r = this.currentLayer) == null ? void 0 : r.endDrawingSession(!0);
if (!this.hasSelection && !t)
return;
const e = t ? [t] : [...n(this, et)], s = () => {
var a;
(a = this._editorUndoBar) == null || a.show(i, e.length === 1 ? e[0].editorType : e.length);
for (const o of e)
o.remove();
}, i = () => {
for (const a of e)
b(this, I, Gc).call(this, a);
};
this.addCommands({
cmd: s,
undo: i,
mustExec: !0
});
}
commitOrRemove() {
var t;
(t = n(this, be)) == null || t.commitOrRemove();
}
hasSomethingToControl() {
return n(this, be) || this.hasSelection;
}
selectAll() {
for (const t of n(this, et))
t.commit();
b(this, I, zc).call(this, n(this, Rt).values());
}
unselectAll() {
var t;
if (!(n(this, be) && (n(this, be).commitOrRemove(), n(this, kt) !== z.NONE)) && !((t = n(this, xi)) != null && t.commitOrRemove()) && this.hasSelection) {
for (const e of n(this, et))
e.unselect();
n(this, et).clear(), b(this, I, te).call(this, {
hasSelectedEditor: !1
});
}
}
translateSelectedEditors(t, e, s = !1) {
if (s || this.commitOrRemove(), !this.hasSelection)
return;
n(this, Li)[0] += t, n(this, Li)[1] += e;
const [i, r] = n(this, Li), a = [...n(this, et)], o = 1e3;
n(this, ps) && clearTimeout(n(this, ps)), f(this, ps, setTimeout(() => {
f(this, ps, null), n(this, Li)[0] = n(this, Li)[1] = 0, this.addCommands({
cmd: () => {
for (const l of a)
n(this, Rt).has(l.id) && (l.translateInPage(i, r), l.translationDone());
},
undo: () => {
for (const l of a)
n(this, Rt).has(l.id) && (l.translateInPage(-i, -r), l.translationDone());
},
mustExec: !1
});
}, o));
for (const l of a)
l.translateInPage(t, e), l.translationDone();
}
setUpDragSession() {
if (this.hasSelection) {
this.disableUserSelect(!0), f(this, ds, /* @__PURE__ */ new Map());
for (const t of n(this, et))
n(this, ds).set(t, {
savedX: t.x,
savedY: t.y,
savedPageIndex: t.pageIndex,
newX: 0,
newY: 0,
newPageIndex: -1
});
}
}
endDragSession() {
if (!n(this, ds))
return !1;
this.disableUserSelect(!1);
const t = n(this, ds);
f(this, ds, null);
let e = !1;
for (const [{
x: i,
y: r,
pageIndex: a
}, o] of t)
o.newX = i, o.newY = r, o.newPageIndex = a, e || (e = i !== o.savedX || r !== o.savedY || a !== o.savedPageIndex);
if (!e)
return !1;
const s = (i, r, a, o) => {
if (n(this, Rt).has(i.id)) {
const l = n(this, Ht).get(o);
l ? i._setParentAndPosition(l, r, a) : (i.pageIndex = o, i.x = r, i.y = a);
}
};
return this.addCommands({
cmd: () => {
for (const [i, {
newX: r,
newY: a,
newPageIndex: o
}] of t)
s(i, r, a, o);
},
undo: () => {
for (const [i, {
savedX: r,
savedY: a,
savedPageIndex: o
}] of t)
s(i, r, a, o);
},
mustExec: !0
}), !0;
}
dragSelectedEditors(t, e) {
if (n(this, ds))
for (const s of n(this, ds).keys())
s.drag(t, e);
}
rebuild(t) {
if (t.parent === null) {
const e = this.getLayer(t.pageIndex);
e ? (e.changeParent(t), e.addOrRebuild(t)) : (this.addEditor(t), this.addToAnnotationStorage(t), t.rebuild());
} else
t.parent.addOrRebuild(t);
}
get isEditorHandlingKeyboard() {
var t;
return ((t = this.getActive()) == null ? void 0 : t.shouldGetKeyboardEvents()) || n(this, et).size === 1 && this.firstSelectedEditor.shouldGetKeyboardEvents();
}
isActive(t) {
return n(this, be) === t;
}
getActive() {
return n(this, be);
}
getMode() {
return n(this, kt);
}
get imageManager() {
return X(this, "imageManager", new Fc());
}
getSelectionBoxes(t) {
if (!t)
return null;
const e = document.getSelection();
for (let h = 0, c = e.rangeCount; h < c; h++)
if (!t.contains(e.getRangeAt(h).commonAncestorContainer))
return null;
const {
x: s,
y: i,
width: r,
height: a
} = t.getBoundingClientRect();
let o;
switch (t.getAttribute("data-main-rotation")) {
case "90":
o = (h, c, u, p) => ({
x: (c - i) / a,
y: 1 - (h + u - s) / r,
width: p / a,
height: u / r
});
break;
case "180":
o = (h, c, u, p) => ({
x: 1 - (h + u - s) / r,
y: 1 - (c + p - i) / a,
width: u / r,
height: p / a
});
break;
case "270":
o = (h, c, u, p) => ({
x: 1 - (c + p - i) / a,
y: (h - s) / r,
width: p / a,
height: u / r
});
break;
default:
o = (h, c, u, p) => ({
x: (h - s) / r,
y: (c - i) / a,
width: u / r,
height: p / a
});
break;
}
const l = [];
for (let h = 0, c = e.rangeCount; h < c; h++) {
const u = e.getRangeAt(h);
if (!u.collapsed)
for (const {
x: p,
y: g,
width: A,
height: y
} of u.getClientRects())
A === 0 || y === 0 || l.push(o(p, g, A, y));
}
return l.length === 0 ? null : l;
}
addChangedExistingAnnotation({
annotationElementId: t,
id: e
}) {
(n(this, qr) || f(this, qr, /* @__PURE__ */ new Map())).set(t, e);
}
removeChangedExistingAnnotation({
annotationElementId: t
}) {
var e;
(e = n(this, qr)) == null || e.delete(t);
}
renderAnnotationElement(t) {
var i;
const e = (i = n(this, qr)) == null ? void 0 : i.get(t.data.id);
if (!e)
return;
const s = n(this, Os).getRawValue(e);
s && (n(this, kt) === z.NONE && !s.hasBeenModified || s.renderAnnotationElement(t));
}
setMissingCanvas(t, e, s) {
var r;
const i = (r = n(this, Mi)) == null ? void 0 : r.get(t);
i && (i.setCanvas(e, s), n(this, Mi).delete(t));
}
addMissingCanvas(t, e) {
(n(this, Mi) || f(this, Mi, /* @__PURE__ */ new Map())).set(t, e);
}
};
Vr = new WeakMap(), be = new WeakMap(), Rt = new WeakMap(), Ht = new WeakMap(), Wr = new WeakMap(), Os = new WeakMap(), qr = new WeakMap(), Be = new WeakMap(), Ci = new WeakMap(), xi = new WeakMap(), Xr = new WeakMap(), wn = new WeakMap(), ds = new WeakMap(), qe = new WeakMap(), vn = new WeakMap(), To = new WeakMap(), Ro = new WeakMap(), Yr = new WeakMap(), Po = new WeakMap(), us = new WeakMap(), Ti = new WeakMap(), Kr = new WeakMap(), Ri = new WeakMap(), fs = new WeakMap(), Jh = new WeakMap(), Pi = new WeakMap(), Io = new WeakMap(), Ii = new WeakMap(), _n = new WeakMap(), Sn = new WeakMap(), Mi = new WeakMap(), Mo = new WeakMap(), kt = new WeakMap(), et = new WeakMap(), Bs = new WeakMap(), ki = new WeakMap(), En = new WeakMap(), ko = new WeakMap(), Lo = new WeakMap(), Li = new WeakMap(), ps = new WeakMap(), Hs = new WeakMap(), Do = new WeakMap(), Fo = new WeakMap(), He = new WeakMap(), I = new WeakSet(), uh = function({
anchorNode: t
}) {
return t.nodeType === Node.TEXT_NODE ? t.parentElement : t;
}, Oc = function(t) {
const {
currentLayer: e
} = this;
if (e.hasTextLayer(t))
return e;
for (const s of n(this, Ht).values())
if (s.hasTextLayer(t))
return s;
return null;
}, Xu = function() {
const t = document.getSelection();
if (!t || t.isCollapsed)
return;
const s = b(this, I, uh).call(this, t).closest(".textLayer"), i = this.getSelectionBoxes(s);
i && (n(this, fs) || f(this, fs, new fg(this)), n(this, fs).show(s, i, this.direction === "ltr"));
}, Yu = function() {
var r, a, o;
const t = document.getSelection();
if (!t || t.isCollapsed) {
n(this, Bs) && ((r = n(this, fs)) == null || r.hide(), f(this, Bs, null), b(this, I, te).call(this, {
hasSelectedText: !1
}));
return;
}
const {
anchorNode: e
} = t;
if (e === n(this, Bs))
return;
const i = b(this, I, uh).call(this, t).closest(".textLayer");
if (!i) {
n(this, Bs) && ((a = n(this, fs)) == null || a.hide(), f(this, Bs, null), b(this, I, te).call(this, {
hasSelectedText: !1
}));
return;
}
if ((o = n(this, fs)) == null || o.hide(), f(this, Bs, e), b(this, I, te).call(this, {
hasSelectedText: !0
}), !(n(this, kt) !== z.HIGHLIGHT && n(this, kt) !== z.NONE) && (n(this, kt) === z.HIGHLIGHT && this.showAllEditors("highlight", !0, !0), f(this, Ri, this.isShiftKeyDown), !this.isShiftKeyDown)) {
const l = n(this, kt) === z.HIGHLIGHT ? b(this, I, Oc).call(this, i) : null;
l == null || l.toggleDrawing();
const h = new AbortController(), c = this.combinedSignal(h), u = (p) => {
p.type === "pointerup" && p.button !== 0 || (h.abort(), l == null || l.toggleDrawing(!0), p.type === "pointerup" && b(this, I, fh).call(this, "main_toolbar"));
};
window.addEventListener("pointerup", u, {
signal: c
}), window.addEventListener("blur", u, {
signal: c
});
}
}, fh = function(t = "") {
n(this, kt) === z.HIGHLIGHT ? this.highlightSelection(t) : n(this, To) && b(this, I, Xu).call(this);
}, Ku = function() {
document.addEventListener("selectionchange", b(this, I, Yu).bind(this), {
signal: this._signal
});
}, Qu = function() {
if (n(this, Ti))
return;
f(this, Ti, new AbortController());
const t = this.combinedSignal(n(this, Ti));
window.addEventListener("focus", this.focus.bind(this), {
signal: t
}), window.addEventListener("blur", this.blur.bind(this), {
signal: t
});
}, Ju = function() {
var t;
(t = n(this, Ti)) == null || t.abort(), f(this, Ti, null);
}, Bc = function() {
if (n(this, Ii))
return;
f(this, Ii, new AbortController());
const t = this.combinedSignal(n(this, Ii));
window.addEventListener("keydown", this.keydown.bind(this), {
signal: t
}), window.addEventListener("keyup", this.keyup.bind(this), {
signal: t
});
}, Zu = function() {
var t;
(t = n(this, Ii)) == null || t.abort(), f(this, Ii, null);
}, Hc = function() {
if (n(this, Ci))
return;
f(this, Ci, new AbortController());
const t = this.combinedSignal(n(this, Ci));
document.addEventListener("copy", this.copy.bind(this), {
signal: t
}), document.addEventListener("cut", this.cut.bind(this), {
signal: t
}), document.addEventListener("paste", this.paste.bind(this), {
signal: t
});
}, $c = function() {
var t;
(t = n(this, Ci)) == null || t.abort(), f(this, Ci, null);
}, tf = function() {
const t = this._signal;
document.addEventListener("dragover", this.dragOver.bind(this), {
signal: t
}), document.addEventListener("drop", this.drop.bind(this), {
signal: t
});
}, te = function(t) {
Object.entries(t).some(([s, i]) => n(this, Lo)[s] !== i) && (this._eventBus.dispatch("annotationeditorstateschanged", {
source: this,
details: Object.assign(n(this, Lo), t)
}), n(this, kt) === z.HIGHLIGHT && t.hasSelectedEditor === !1 && b(this, I, Ls).call(this, [[Y.HIGHLIGHT_FREE, !0]]));
}, Ls = function(t) {
this._eventBus.dispatch("annotationeditorparamschanged", {
source: this,
details: t
});
}, ef = async function() {
if (!n(this, Pi)) {
f(this, Pi, !0);
const t = [];
for (const e of n(this, Ht).values())
t.push(e.enable());
await Promise.all(t);
for (const e of n(this, Rt).values())
e.enable();
}
}, sf = function() {
if (this.unselectAll(), n(this, Pi)) {
f(this, Pi, !1);
for (const t of n(this, Ht).values())
t.disable();
for (const t of n(this, Rt).values())
t.disable();
}
}, Gc = function(t) {
const e = n(this, Ht).get(t.pageIndex);
e ? e.addOrRebuild(t) : (this.addEditor(t), this.addToAnnotationStorage(t));
}, nf = function() {
let t = null;
for (t of n(this, et))
;
return t;
}, to = function() {
if (n(this, Rt).size === 0)
return !0;
if (n(this, Rt).size === 1)
for (const t of n(this, Rt).values())
return t.isEmpty();
return !1;
}, zc = function(t) {
for (const e of n(this, et))
e.unselect();
n(this, et).clear();
for (const e of t)
e.isEmpty() || (n(this, et).add(e), e.select());
b(this, I, te).call(this, {
hasSelectedEditor: this.hasSelection
});
}, R(Hr, "TRANSLATE_SMALL", 1), R(Hr, "TRANSLATE_BIG", 10);
let xr = Hr;
var Lt, gs, Xe, Qr, ms, Ae, Jr, bs, ue, $s, Cn, As, Di, rs, eo, ph;
const ee = class ee {
constructor(t) {
m(this, rs);
m(this, Lt, null);
m(this, gs, !1);
m(this, Xe, null);
m(this, Qr, null);
m(this, ms, null);
m(this, Ae, null);
m(this, Jr, !1);
m(this, bs, null);
m(this, ue, null);
m(this, $s, null);
m(this, Cn, null);
m(this, As, !1);
f(this, ue, t), f(this, As, t._uiManager.useNewAltTextFlow), n(ee, Di) || f(ee, Di, Object.freeze({
added: "pdfjs-editor-new-alt-text-added-button",
"added-label": "pdfjs-editor-new-alt-text-added-button-label",
missing: "pdfjs-editor-new-alt-text-missing-button",
"missing-label": "pdfjs-editor-new-alt-text-missing-button-label",
review: "pdfjs-editor-new-alt-text-to-review-button",
"review-label": "pdfjs-editor-new-alt-text-to-review-button-label"
}));
}
static initialize(t) {
ee._l10n ?? (ee._l10n = t);
}
async render() {
const t = f(this, Xe, document.createElement("button"));
t.className = "altText", t.tabIndex = "0";
const e = f(this, Qr, document.createElement("span"));
t.append(e), n(this, As) ? (t.classList.add("new"), t.setAttribute("data-l10n-id", n(ee, Di).missing), e.setAttribute("data-l10n-id", n(ee, Di)["missing-label"])) : (t.setAttribute("data-l10n-id", "pdfjs-editor-alt-text-button"), e.setAttribute("data-l10n-id", "pdfjs-editor-alt-text-button-label"));
const s = n(this, ue)._uiManager._signal;
t.addEventListener("contextmenu", as, {
signal: s
}), t.addEventListener("pointerdown", (r) => r.stopPropagation(), {
signal: s
});
const i = (r) => {
r.preventDefault(), n(this, ue)._uiManager.editAltText(n(this, ue)), n(this, As) && n(this, ue)._reportTelemetry({
action: "pdfjs.image.alt_text.image_status_label_clicked",
data: {
label: n(this, rs, eo)
}
});
};
return t.addEventListener("click", i, {
capture: !0,
signal: s
}), t.addEventListener("keydown", (r) => {
r.target === t && r.key === "Enter" && (f(this, Jr, !0), i(r));
}, {
signal: s
}), await b(this, rs, ph).call(this), t;
}
finish() {
n(this, Xe) && (n(this, Xe).focus({
focusVisible: n(this, Jr)
}), f(this, Jr, !1));
}
isEmpty() {
return n(this, As) ? n(this, Lt) === null : !n(this, Lt) && !n(this, gs);
}
hasData() {
return n(this, As) ? n(this, Lt) !== null || !!n(this, $s) : this.isEmpty();
}
get guessedText() {
return n(this, $s);
}
async setGuessedText(t) {
n(this, Lt) === null && (f(this, $s, t), f(this, Cn, await ee._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer", {
generatedAltText: t
})), b(this, rs, ph).call(this));
}
toggleAltTextBadge(t = !1) {
var e;
if (!n(this, As) || n(this, Lt)) {
(e = n(this, bs)) == null || e.remove(), f(this, bs, null);
return;
}
if (!n(this, bs)) {
const s = f(this, bs, document.createElement("div"));
s.className = "noAltTextBadge", n(this, ue).div.append(s);
}
n(this, bs).classList.toggle("hidden", !t);
}
serialize(t) {
let e = n(this, Lt);
return !t && n(this, $s) === e && (e = n(this, Cn)), {
altText: e,
decorative: n(this, gs),
guessedText: n(this, $s),
textWithDisclaimer: n(this, Cn)
};
}
get data() {
return {
altText: n(this, Lt),
decorative: n(this, gs)
};
}
set data({
altText: t,
decorative: e,
guessedText: s,
textWithDisclaimer: i,
cancel: r = !1
}) {
s && (f(this, $s, s), f(this, Cn, i)), !(n(this, Lt) === t && n(this, gs) === e) && (r || (f(this, Lt, t), f(this, gs, e)), b(this, rs, ph).call(this));
}
toggle(t = !1) {
n(this, Xe) && (!t && n(this, Ae) && (clearTimeout(n(this, Ae)), f(this, Ae, null)), n(this, Xe).disabled = !t);
}
shown() {
n(this, ue)._reportTelemetry({
action: "pdfjs.image.alt_text.image_status_label_displayed",
data: {
label: n(this, rs, eo)
}
});
}
destroy() {
var t, e;
(t = n(this, Xe)) == null || t.remove(), f(this, Xe, null), f(this, Qr, null), f(this, ms, null), (e = n(this, bs)) == null || e.remove(), f(this, bs, null);
}
};
Lt = new WeakMap(), gs = new WeakMap(), Xe = new WeakMap(), Qr = new WeakMap(), ms = new WeakMap(), Ae = new WeakMap(), Jr = new WeakMap(), bs = new WeakMap(), ue = new WeakMap(), $s = new WeakMap(), Cn = new WeakMap(), As = new WeakMap(), Di = new WeakMap(), rs = new WeakSet(), eo = function() {
return n(this, Lt) && "added" || n(this, Lt) === null && this.guessedText && "review" || "missing";
}, ph = async function() {
var i, r, a;
const t = n(this, Xe);
if (!t)
return;
if (n(this, As)) {
if (t.classList.toggle("done", !!n(this, Lt)), t.setAttribute("data-l10n-id", n(ee, Di)[n(this, rs, eo)]), (i = n(this, Qr)) == null || i.setAttribute("data-l10n-id", n(ee, Di)[`${n(this, rs, eo)}-label`]), !n(this, Lt)) {
(r = n(this, ms)) == null || r.remove();
return;
}
} else {
if (!n(this, Lt) && !n(this, gs)) {
t.classList.remove("done"), (a = n(this, ms)) == null || a.remove();
return;
}
t.classList.add("done"), t.setAttribute("data-l10n-id", "pdfjs-editor-alt-text-edit-button");
}
let e = n(this, ms);
if (!e) {
f(this, ms, e = document.createElement("span")), e.className = "tooltip", e.setAttribute("role", "tooltip"), e.id = `alt-text-tooltip-${n(this, ue).id}`;
const o = 100, l = n(this, ue)._uiManager._signal;
l.addEventListener("abort", () => {
clearTimeout(n(this, Ae)), f(this, Ae, null);
}, {
once: !0
}), t.addEventListener("mouseenter", () => {
f(this, Ae, setTimeout(() => {
f(this, Ae, null), n(this, ms).classList.add("show"), n(this, ue)._reportTelemetry({
action: "alt_text_tooltip"
});
}, o));
}, {
signal: l
}), t.addEventListener("mouseleave", () => {
var h;
n(this, Ae) && (clearTimeout(n(this, Ae)), f(this, Ae, null)), (h = n(this, ms)) == null || h.classList.remove("show");
}, {
signal: l
});
}
n(this, gs) ? e.setAttribute("data-l10n-id", "pdfjs-editor-alt-text-decorative-tooltip") : (e.removeAttribute("data-l10n-id"), e.textContent = n(this, Lt)), e.parentNode || t.append(e);
const s = n(this, ue).getElementForAltText();
s == null || s.setAttribute("aria-describedby", e.id);
}, m(ee, Di, null), R(ee, "_l10n", null);
let Gh = ee;
var Zr, xn, No, Oo, Bo, Ho, $o, Gs, Tn, zs, Rn, Us, hn, rf, af, of;
const au = class au {
constructor({
container: t,
isPinchingDisabled: e = null,
isPinchingStopped: s = null,
onPinchStart: i = null,
onPinching: r = null,
onPinchEnd: a = null,
signal: o
}) {
m(this, hn);
m(this, Zr);
m(this, xn, !1);
m(this, No, null);
m(this, Oo);
m(this, Bo);
m(this, Ho);
m(this, $o);
m(this, Gs, null);
m(this, Tn);
m(this, zs, null);
m(this, Rn);
m(this, Us, null);
f(this, Zr, t), f(this, No, s), f(this, Oo, e), f(this, Bo, i), f(this, Ho, r), f(this, $o, a), f(this, Rn, new AbortController()), f(this, Tn, AbortSignal.any([o, n(this, Rn).signal])), t.addEventListener("touchstart", b(this, hn, rf).bind(this), {
passive: !1,
signal: n(this, Tn)
});
}
get MIN_TOUCH_DISTANCE_TO_PINCH() {
return 35 / Rs.pixelRatio;
}
destroy() {
var t, e;
(t = n(this, Rn)) == null || t.abort(), f(this, Rn, null), (e = n(this, Gs)) == null || e.abort(), f(this, Gs, null);
}
};
Zr = new WeakMap(), xn = new WeakMap(), No = new WeakMap(), Oo = new WeakMap(), Bo = new WeakMap(), Ho = new WeakMap(), $o = new WeakMap(), Gs = new WeakMap(), Tn = new WeakMap(), zs = new WeakMap(), Rn = new WeakMap(), Us = new WeakMap(), hn = new WeakSet(), rf = function(t) {
var i, r, a;
if ((i = n(this, Oo)) != null && i.call(this))
return;
if (t.touches.length === 1) {
if (n(this, Gs))
return;
const o = f(this, Gs, new AbortController()), l = AbortSignal.any([n(this, Tn), o.signal]), h = n(this, Zr), c = {
capture: !0,
signal: l,
passive: !1
}, u = (p) => {
var g;
p.pointerType === "touch" && ((g = n(this, Gs)) == null || g.abort(), f(this, Gs, null));
};
h.addEventListener("pointerdown", (p) => {
p.pointerType === "touch" && (St(p), u(p));
}, c), h.addEventListener("pointerup", u, c), h.addEventListener("pointercancel", u, c);
return;
}
if (!n(this, Us)) {
f(this, Us, new AbortController());
const o = AbortSignal.any([n(this, Tn), n(this, Us).signal]), l = n(this, Zr), h = {
signal: o,
capture: !1,
passive: !1
};
l.addEventListener("touchmove", b(this, hn, af).bind(this), h);
const c = b(this, hn, of).bind(this);
l.addEventListener("touchend", c, h), l.addEventListener("touchcancel", c, h), h.capture = !0, l.addEventListener("pointerdown", St, h), l.addEventListener("pointermove", St, h), l.addEventListener("pointercancel", St, h), l.addEventListener("pointerup", St, h), (r = n(this, Bo)) == null || r.call(this);
}
if (St(t), t.touches.length !== 2 || (a = n(this, No)) != null && a.call(this)) {
f(this, zs, null);
return;
}
let [e, s] = t.touches;
e.identifier > s.identifier && ([e, s] = [s, e]), f(this, zs, {
touch0X: e.screenX,
touch0Y: e.screenY,
touch1X: s.screenX,
touch1Y: s.screenY
});
}, af = function(t) {
var E;
if (!n(this, zs) || t.touches.length !== 2)
return;
St(t);
let [e, s] = t.touches;
e.identifier > s.identifier && ([e, s] = [s, e]);
const {
screenX: i,
screenY: r
} = e, {
screenX: a,
screenY: o
} = s, l = n(this, zs), {
touch0X: h,
touch0Y: c,
touch1X: u,
touch1Y: p
} = l, g = u - h, A = p - c, y = a - i, w = o - r, v = Math.hypot(y, w) || 1, S = Math.hypot(g, A) || 1;
if (!n(this, xn) && Math.abs(S - v) <= au.MIN_TOUCH_DISTANCE_TO_PINCH)
return;
if (l.touch0X = i, l.touch0Y = r, l.touch1X = a, l.touch1Y = o, !n(this, xn)) {
f(this, xn, !0);
return;
}
const _ = [(i + a) / 2, (r + o) / 2];
(E = n(this, Ho)) == null || E.call(this, _, S, v);
}, of = function(t) {
var e;
t.touches.length >= 2 || (n(this, Us) && (n(this, Us).abort(), f(this, Us, null), (e = n(this, $o)) == null || e.call(this)), n(this, zs) && (St(t), f(this, zs, null), f(this, xn, !1)));
};
let zh = au;
var Pn, Ye, ct, ta, Fi, Go, In, $t, Mn, js, Ni, zo, kn, ye, Uo, Ln, Vs, ys, ea, sa, $e, Dn, jo, Zh, G, Uc, Vo, jc, gh, lf, hf, Vc, mh, Wc, cf, df, uf, qc, ff, Xc, pf, gf, mf, Yc, so;
const V = class V {
constructor(t) {
m(this, G);
m(this, Pn, null);
m(this, Ye, null);
m(this, ct, null);
m(this, ta, !1);
m(this, Fi, null);
m(this, Go, "");
m(this, In, !1);
m(this, $t, null);
m(this, Mn, null);
m(this, js, null);
m(this, Ni, null);
m(this, zo, "");
m(this, kn, !1);
m(this, ye, null);
m(this, Uo, !1);
m(this, Ln, !1);
m(this, Vs, !1);
m(this, ys, null);
m(this, ea, 0);
m(this, sa, 0);
m(this, $e, null);
m(this, Dn, null);
R(this, "isSelected", !1);
R(this, "_isCopy", !1);
R(this, "_editToolbar", null);
R(this, "_initialOptions", /* @__PURE__ */ Object.create(null));
R(this, "_initialData", null);
R(this, "_isVisible", !0);
R(this, "_uiManager", null);
R(this, "_focusEventsAllowed", !0);
m(this, jo, !1);
m(this, Zh, V._zIndex++);
this.parent = t.parent, this.id = t.id, this.width = this.height = null, this.pageIndex = t.parent.pageIndex, this.name = t.name, this.div = null, this._uiManager = t.uiManager, this.annotationElementId = null, this._willKeepAspectRatio = !1, this._initialOptions.isCentered = t.isCentered, this._structTreeParentId = null, this.annotationElementId = t.annotationElementId || null;
const {
rotation: e,
rawDims: {
pageWidth: s,
pageHeight: i,
pageX: r,
pageY: a
}
} = this.parent.viewport;
this.rotation = e, this.pageRotation = (360 + e - this._uiManager.viewParameters.rotation) % 360, this.pageDimensions = [s, i], this.pageTranslation = [r, a];
const [o, l] = this.parentDimensions;
this.x = t.x / o, this.y = t.y / l, this.isAttachedToDOM = !1, this.deleted = !1;
}
static get _resizerKeyboardManager() {
const t = V.prototype._resizeWithKeyboard, e = xr.TRANSLATE_SMALL, s = xr.TRANSLATE_BIG;
return X(this, "_resizerKeyboardManager", new Jl([[["ArrowLeft", "mac+ArrowLeft"], t, {
args: [-e, 0]
}], [["ctrl+ArrowLeft", "mac+shift+ArrowLeft"], t, {
args: [-s, 0]
}], [["ArrowRight", "mac+ArrowRight"], t, {
args: [e, 0]
}], [["ctrl+ArrowRight", "mac+shift+ArrowRight"], t, {
args: [s, 0]
}], [["ArrowUp", "mac+ArrowUp"], t, {
args: [0, -e]
}], [["ctrl+ArrowUp", "mac+shift+ArrowUp"], t, {
args: [0, -s]
}], [["ArrowDown", "mac+ArrowDown"], t, {
args: [0, e]
}], [["ctrl+ArrowDown", "mac+shift+ArrowDown"], t, {
args: [0, s]
}], [["Escape", "mac+Escape"], V.prototype._stopResizingWithKeyboard]]));
}
get editorType() {
return Object.getPrototypeOf(this).constructor._type;
}
get mode() {
return Object.getPrototypeOf(this).constructor._editorType;
}
static get isDrawer() {
return !1;
}
static get _defaultLineColor() {
return X(this, "_defaultLineColor", this._colorManager.getHexCode("CanvasText"));
}
static deleteAnnotationElement(t) {
const e = new mg({
id: t.parent.getNextId(),
parent: t.parent,
uiManager: t._uiManager
});
e.annotationElementId = t.annotationElementId, e.deleted = !0, e._uiManager.addToAnnotationStorage(e);
}
static initialize(t, e) {
if (V._l10n ?? (V._l10n = t), V._l10nResizer || (V._l10nResizer = Object.freeze({
topLeft: "pdfjs-editor-resizer-top-left",
topMiddle: "pdfjs-editor-resizer-top-middle",
topRight: "pdfjs-editor-resizer-top-right",
middleRight: "pdfjs-editor-resizer-middle-right",
bottomRight: "pdfjs-editor-resizer-bottom-right",
bottomMiddle: "pdfjs-editor-resizer-bottom-middle",
bottomLeft: "pdfjs-editor-resizer-bottom-left",
middleLeft: "pdfjs-editor-resizer-middle-left"
})), V._borderLineWidth !== -1)
return;
const s = getComputedStyle(document.documentElement);
V._borderLineWidth = parseFloat(s.getPropertyValue("--outline-width")) || 0;
}
static updateDefaultParams(t, e) {
}
static get defaultPropertiesToUpdate() {
return [];
}
static isHandlingMimeForPasting(t) {
return !1;
}
static paste(t, e) {
rt("Not implemented");
}
get propertiesToUpdate() {
return [];
}
get _isDraggable() {
return n(this, jo);
}
set _isDraggable(t) {
var e;
f(this, jo, t), (e = this.div) == null || e.classList.toggle("draggable", t);
}
get isEnterHandled() {
return !0;
}
center() {
const [t, e] = this.pageDimensions;
switch (this.parentRotation) {
case 90:
this.x -= this.height * e / (t * 2), this.y += this.width * t / (e * 2);
break;
case 180:
this.x += this.width / 2, this.y += this.height / 2;
break;
case 270:
this.x += this.height * e / (t * 2), this.y -= this.width * t / (e * 2);
break;
default:
this.x -= this.width / 2, this.y -= this.height / 2;
break;
}
this.fixAndSetPosition();
}
addCommands(t) {
this._uiManager.addCommands(t);
}
get currentLayer() {
return this._uiManager.currentLayer;
}
setInBackground() {
this.div.style.zIndex = 0;
}
setInForeground() {
this.div.style.zIndex = n(this, Zh);
}
setParent(t) {
t !== null ? (this.pageIndex = t.pageIndex, this.pageDimensions = t.pageDimensions) : b(this, G, so).call(this), this.parent = t;
}
focusin(t) {
this._focusEventsAllowed && (n(this, kn) ? f(this, kn, !1) : this.parent.setSelected(this));
}
focusout(t) {
var s;
if (!this._focusEventsAllowed || !this.isAttachedToDOM)
return;
const e = t.relatedTarget;
e != null && e.closest(`#${this.id}`) || (t.preventDefault(), (s = this.parent) != null && s.isMultipleSelection || this.commitOrRemove());
}
commitOrRemove() {
this.isEmpty() ? this.remove() : this.commit();
}
commit() {
this.isInEditMode() && this.addToAnnotationStorage();
}
addToAnnotationStorage() {
this._uiManager.addToAnnotationStorage(this);
}
setAt(t, e, s, i) {
const [r, a] = this.parentDimensions;
[s, i] = this.screenToPageTranslation(s, i), this.x = (t + s) / r, this.y = (e + i) / a, this.fixAndSetPosition();
}
_moveAfterPaste(t, e) {
const [s, i] = this.parentDimensions;
this.setAt(t * s, e * i, this.width * s, this.height * i), this._onTranslated();
}
translate(t, e) {
b(this, G, Uc).call(this, this.parentDimensions, t, e);
}
translateInPage(t, e) {
n(this, ye) || f(this, ye, [this.x, this.y, this.width, this.height]), b(this, G, Uc).call(this, this.pageDimensions, t, e), this.div.scrollIntoView({
block: "nearest"
});
}
translationDone() {
this._onTranslated(this.x, this.y);
}
drag(t, e) {
n(this, ye) || f(this, ye, [this.x, this.y, this.width, this.height]);
const {
div: s,
parentDimensions: [i, r]
} = this;
if (this.x += t / i, this.y += e / r, this.parent && (this.x < 0 || this.x > 1 || this.y < 0 || this.y > 1)) {
const {
x: u,
y: p
} = this.div.getBoundingClientRect();
this.parent.findNewParent(this, u, p) && (this.x -= Math.floor(this.x), this.y -= Math.floor(this.y));
}
let {
x: a,
y: o
} = this;
const [l, h] = this.getBaseTranslation();
a += l, o += h;
const {
style: c
} = s;
c.left = `${(100 * a).toFixed(2)}%`, c.top = `${(100 * o).toFixed(2)}%`, this._onTranslating(a, o), s.scrollIntoView({
block: "nearest"
});
}
_onTranslating(t, e) {
}
_onTranslated(t, e) {
}
get _hasBeenMoved() {
return !!n(this, ye) && (n(this, ye)[0] !== this.x || n(this, ye)[1] !== this.y);
}
get _hasBeenResized() {
return !!n(this, ye) && (n(this, ye)[2] !== this.width || n(this, ye)[3] !== this.height);
}
getBaseTranslation() {
const [t, e] = this.parentDimensions, {
_borderLineWidth: s
} = V, i = s / t, r = s / e;
switch (this.rotation) {
case 90:
return [-i, r];
case 180:
return [i, r];
case 270:
return [i, -r];
default:
return [-i, -r];
}
}
get _mustFixPosition() {
return !0;
}
fixAndSetPosition(t = this.rotation) {
const {
div: {
style: e
},
pageDimensions: [s, i]
} = this;
let {
x: r,
y: a,
width: o,
height: l
} = this;
if (o *= s, l *= i, r *= s, a *= i, this._mustFixPosition)
switch (t) {
case 0:
r = ae(r, 0, s - o), a = ae(a, 0, i - l);
break;
case 90:
r = ae(r, 0, s - l), a = ae(a, o, i);
break;
case 180:
r = ae(r, o, s), a = ae(a, l, i);
break;
case 270:
r = ae(r, l, s), a = ae(a, 0, i - o);
break;
}
this.x = r /= s, this.y = a /= i;
const [h, c] = this.getBaseTranslation();
r += h, a += c, e.left = `${(100 * r).toFixed(2)}%`, e.top = `${(100 * a).toFixed(2)}%`, this.moveInDOM();
}
screenToPageTranslation(t, e) {
var s;
return b(s = V, Vo, jc).call(s, t, e, this.parentRotation);
}
pageTranslationToScreen(t, e) {
var s;
return b(s = V, Vo, jc).call(s, t, e, 360 - this.parentRotation);
}
get parentScale() {
return this._uiManager.viewParameters.realScale;
}
get parentRotation() {
return (this._uiManager.viewParameters.rotation + this.pageRotation) % 360;
}
get parentDimensions() {
const {
parentScale: t,
pageDimensions: [e, s]
} = this;
return [e * t, s * t];
}
setDims(t, e) {
const [s, i] = this.parentDimensions, {
style: r
} = this.div;
r.width = `${(100 * t / s).toFixed(2)}%`, n(this, In) || (r.height = `${(100 * e / i).toFixed(2)}%`);
}
fixDims() {
const {
style: t
} = this.div, {
height: e,
width: s
} = t, i = s.endsWith("%"), r = !n(this, In) && e.endsWith("%");
if (i && r)
return;
const [a, o] = this.parentDimensions;
i || (t.width = `${(100 * parseFloat(s) / a).toFixed(2)}%`), !n(this, In) && !r && (t.height = `${(100 * parseFloat(e) / o).toFixed(2)}%`);
}
getInitialTranslation() {
return [0, 0];
}
_onResized() {
}
static _round(t) {
return Math.round(t * 1e4) / 1e4;
}
_onResizing() {
}
altTextFinish() {
var t;
(t = n(this, ct)) == null || t.finish();
}
get toolbarButtons() {
return null;
}
async addEditToolbar() {
if (this._editToolbar || n(this, Ln))
return this._editToolbar;
this._editToolbar = new Dc(this), this.div.append(this._editToolbar.render());
const {
toolbarButtons: t
} = this;
if (t)
for (const [e, s] of t)
await this._editToolbar.addButton(e, s);
return this._editToolbar.addButton("delete"), this._editToolbar;
}
removeEditToolbar() {
var t;
this._editToolbar && (this._editToolbar.remove(), this._editToolbar = null, (t = n(this, ct)) == null || t.destroy());
}
addContainer(t) {
var s;
const e = (s = this._editToolbar) == null ? void 0 : s.div;
e ? e.before(t) : this.div.append(t);
}
getClientDimensions() {
return this.div.getBoundingClientRect();
}
createAltText() {
return n(this, ct) || (Gh.initialize(V._l10n), f(this, ct, new Gh(this)), n(this, Pn) && (n(this, ct).data = n(this, Pn), f(this, Pn, null))), n(this, ct);
}
get altTextData() {
var t;
return (t = n(this, ct)) == null ? void 0 : t.data;
}
set altTextData(t) {
n(this, ct) && (n(this, ct).data = t);
}
get guessedAltText() {
var t;
return (t = n(this, ct)) == null ? void 0 : t.guessedText;
}
async setGuessedAltText(t) {
var e;
await ((e = n(this, ct)) == null ? void 0 : e.setGuessedText(t));
}
serializeAltText(t) {
var e;
return (e = n(this, ct)) == null ? void 0 : e.serialize(t);
}
hasAltText() {
return !!n(this, ct) && !n(this, ct).isEmpty();
}
hasAltTextData() {
var t;
return ((t = n(this, ct)) == null ? void 0 : t.hasData()) ?? !1;
}
render() {
var a;
const t = this.div = document.createElement("div");
t.setAttribute("data-editor-rotation", (360 - this.rotation) % 360), t.className = this.name, t.setAttribute("id", this.id), t.tabIndex = n(this, ta) ? -1 : 0, t.setAttribute("role", "application"), this.defaultL10nId && t.setAttribute("data-l10n-id", this.defaultL10nId), this._isVisible || t.classList.add("hidden"), this.setInForeground(), b(this, G, Xc).call(this);
const [e, s] = this.parentDimensions;
this.parentRotation % 180 !== 0 && (t.style.maxWidth = `${(100 * s / e).toFixed(2)}%`, t.style.maxHeight = `${(100 * e / s).toFixed(2)}%`);
const [i, r] = this.getInitialTranslation();
return this.translate(i, r), Wu(this, t, ["keydown", "pointerdown", "dblclick"]), this.isResizable && this._uiManager._supportsPinchToZoom && (n(this, Dn) || f(this, Dn, new zh({
container: t,
isPinchingDisabled: () => !this.isSelected,
onPinchStart: b(this, G, cf).bind(this),
onPinching: b(this, G, df).bind(this),
onPinchEnd: b(this, G, uf).bind(this),
signal: this._uiManager._signal
}))), (a = this._uiManager._editorUndoBar) == null || a.hide(), t;
}
pointerdown(t) {
const {
isMac: e
} = Wt.platform;
if (t.button !== 0 || t.ctrlKey && e) {
t.preventDefault();
return;
}
if (f(this, kn, !0), this._isDraggable) {
b(this, G, ff).call(this, t);
return;
}
b(this, G, qc).call(this, t);
}
_onStartDragging() {
}
_onStopDragging() {
}
moveInDOM() {
n(this, ys) && clearTimeout(n(this, ys)), f(this, ys, setTimeout(() => {
var t;
f(this, ys, null), (t = this.parent) == null || t.moveEditorInDOM(this);
}, 0));
}
_setParentAndPosition(t, e, s) {
t.changeParent(this), this.x = e, this.y = s, this.fixAndSetPosition(), this._onTranslated();
}
getRect(t, e, s = this.rotation) {
const i = this.parentScale, [r, a] = this.pageDimensions, [o, l] = this.pageTranslation, h = t / i, c = e / i, u = this.x * r, p = this.y * a, g = this.width * r, A = this.height * a;
switch (s) {
case 0:
return [u + h + o, a - p - c - A + l, u + h + g + o, a - p - c + l];
case 90:
return [u + c + o, a - p + h + l, u + c + A + o, a - p + h + g + l];
case 180:
return [u - h - g + o, a - p + c + l, u - h + o, a - p + c + A + l];
case 270:
return [u - c - A + o, a - p - h - g + l, u - c + o, a - p - h + l];
default:
throw new Error("Invalid rotation");
}
}
getRectInCurrentCoords(t, e) {
const [s, i, r, a] = t, o = r - s, l = a - i;
switch (this.rotation) {
case 0:
return [s, e - a, o, l];
case 90:
return [s, e - i, l, o];
case 180:
return [r, e - i, o, l];
case 270:
return [r, e - a, l, o];
default:
throw new Error("Invalid rotation");
}
}
onceAdded(t) {
}
isEmpty() {
return !1;
}
enableEditMode() {
return this.isInEditMode() ? !1 : (this.parent.setEditingState(!1), f(this, Ln, !0), !0);
}
disableEditMode() {
return this.isInEditMode() ? (this.parent.setEditingState(!0), f(this, Ln, !1), !0) : !1;
}
isInEditMode() {
return n(this, Ln);
}
shouldGetKeyboardEvents() {
return n(this, Vs);
}
needsToBeRebuilt() {
return this.div && !this.isAttachedToDOM;
}
get isOnScreen() {
const {
top: t,
left: e,
bottom: s,
right: i
} = this.getClientDimensions(), {
innerHeight: r,
innerWidth: a
} = window;
return e < a && i > 0 && t < r && s > 0;
}
rebuild() {
b(this, G, Xc).call(this);
}
rotate(t) {
}
resize() {
}
serializeDeleted() {
var t;
return {
id: this.annotationElementId,
deleted: !0,
pageIndex: this.pageIndex,
popupRef: ((t = this._initialData) == null ? void 0 : t.popupRef) || ""
};
}
serialize(t = !1, e = null) {
rt("An editor must be serializable");
}
static async deserialize(t, e, s) {
const i = new this.prototype.constructor({
parent: e,
id: e.getNextId(),
uiManager: s,
annotationElementId: t.annotationElementId
});
i.rotation = t.rotation, f(i, Pn, t.accessibilityData), i._isCopy = t.isCopy || !1;
const [r, a] = i.pageDimensions, [o, l, h, c] = i.getRectInCurrentCoords(t.rect, a);
return i.x = o / r, i.y = l / a, i.width = h / r, i.height = c / a, i;
}
get hasBeenModified() {
return !!this.annotationElementId && (this.deleted || this.serialize() !== null);
}
remove() {
var t, e;
if ((t = n(this, Ni)) == null || t.abort(), f(this, Ni, null), this.isEmpty() || this.commit(), this.parent ? this.parent.remove(this) : this._uiManager.removeEditor(this), n(this, ys) && (clearTimeout(n(this, ys)), f(this, ys, null)), b(this, G, so).call(this), this.removeEditToolbar(), n(this, $e)) {
for (const s of n(this, $e).values())
clearTimeout(s);
f(this, $e, null);
}
this.parent = null, (e = n(this, Dn)) == null || e.destroy(), f(this, Dn, null);
}
get isResizable() {
return !1;
}
makeResizable() {
this.isResizable && (b(this, G, lf).call(this), n(this, $t).classList.remove("hidden"));
}
get toolbarPosition() {
return null;
}
keydown(t) {
if (!this.isResizable || t.target !== this.div || t.key !== "Enter")
return;
this._uiManager.setSelected(this), f(this, js, {
savedX: this.x,
savedY: this.y,
savedWidth: this.width,
savedHeight: this.height
});
const e = n(this, $t).children;
if (!n(this, Ye)) {
f(this, Ye, Array.from(e));
const a = b(this, G, pf).bind(this), o = b(this, G, gf).bind(this), l = this._uiManager._signal;
for (const h of n(this, Ye)) {
const c = h.getAttribute("data-resizer-name");
h.setAttribute("role", "spinbutton"), h.addEventListener("keydown", a, {
signal: l
}), h.addEventListener("blur", o, {
signal: l
}), h.addEventListener("focus", b(this, G, mf).bind(this, c), {
signal: l
}), h.setAttribute("data-l10n-id", V._l10nResizer[c]);
}
}
const s = n(this, Ye)[0];
let i = 0;
for (const a of e) {
if (a === s)
break;
i++;
}
const r = (360 - this.rotation + this.parentRotation) % 360 / 90 * (n(this, Ye).length / 4);
if (r !== i) {
if (r < i)
for (let o = 0; o < i - r; o++)
n(this, $t).append(n(this, $t).firstChild);
else if (r > i)
for (let o = 0; o < r - i; o++)
n(this, $t).firstChild.before(n(this, $t).lastChild);
let a = 0;
for (const o of e) {
const h = n(this, Ye)[a++].getAttribute("data-resizer-name");
o.setAttribute("data-l10n-id", V._l10nResizer[h]);
}
}
b(this, G, Yc).call(this, 0), f(this, Vs, !0), n(this, $t).firstChild.focus({
focusVisible: !0
}), t.preventDefault(), t.stopImmediatePropagation();
}
_resizeWithKeyboard(t, e) {
n(this, Vs) && b(this, G, Wc).call(this, n(this, zo), {
deltaX: t,
deltaY: e,
fromKeyboard: !0
});
}
_stopResizingWithKeyboard() {
b(this, G, so).call(this), this.div.focus();
}
select() {
var t, e, s;
if (!(this.isSelected && this._editToolbar)) {
if (this.isSelected = !0, this.makeResizable(), (t = this.div) == null || t.classList.add("selectedEditor"), !this._editToolbar) {
this.addEditToolbar().then(() => {
var i, r;
(i = this.div) != null && i.classList.contains("selectedEditor") && ((r = this._editToolbar) == null || r.show());
});
return;
}
(e = this._editToolbar) == null || e.show(), (s = n(this, ct)) == null || s.toggleAltTextBadge(!1);
}
}
unselect() {
var t, e, s, i, r;
this.isSelected && (this.isSelected = !1, (t = n(this, $t)) == null || t.classList.add("hidden"), (e = this.div) == null || e.classList.remove("selectedEditor"), (s = this.div) != null && s.contains(document.activeElement) && this._uiManager.currentLayer.div.focus({
preventScroll: !0
}), (i = this._editToolbar) == null || i.hide(), (r = n(this, ct)) == null || r.toggleAltTextBadge(!0));
}
updateParams(t, e) {
}
disableEditing() {
}
enableEditing() {
}
get canChangeContent() {
return !1;
}
enterInEditMode() {
this.canChangeContent && (this.enableEditMode(), this.div.focus());
}
dblclick(t) {
this.enterInEditMode(), this.parent.updateToolbar({
mode: this.constructor._editorType,
editId: this.id
});
}
getElementForAltText() {
return this.div;
}
get contentDiv() {
return this.div;
}
get isEditing() {
return n(this, Uo);
}
set isEditing(t) {
f(this, Uo, t), this.parent && (t ? (this.parent.setSelected(this), this.parent.setActiveEditor(this)) : this.parent.setActiveEditor(null));
}
setAspectRatio(t, e) {
f(this, In, !0);
const s = t / e, {
style: i
} = this.div;
i.aspectRatio = s, i.height = "auto";
}
static get MIN_SIZE() {
return 16;
}
static canCreateNewEmptyEditor() {
return !0;
}
get telemetryInitialData() {
return {
action: "added"
};
}
get telemetryFinalData() {
return null;
}
_reportTelemetry(t, e = !1) {
if (e) {
n(this, $e) || f(this, $e, /* @__PURE__ */ new Map());
const {
action: s
} = t;
let i = n(this, $e).get(s);
i && clearTimeout(i), i = setTimeout(() => {
this._reportTelemetry(t), n(this, $e).delete(s), n(this, $e).size === 0 && f(this, $e, null);
}, V._telemetryTimeout), n(this, $e).set(s, i);
return;
}
t.type || (t.type = this.editorType), this._uiManager._eventBus.dispatch("reporttelemetry", {
source: this,
details: {
type: "editing",
data: t
}
});
}
show(t = this._isVisible) {
this.div.classList.toggle("hidden", !t), this._isVisible = t;
}
enable() {
this.div && (this.div.tabIndex = 0), f(this, ta, !1);
}
disable() {
this.div && (this.div.tabIndex = -1), f(this, ta, !0);
}
renderAnnotationElement(t) {
let e = t.container.querySelector(".annotationContent");
if (!e)
e = document.createElement("div"), e.classList.add("annotationContent", this.editorType), t.container.prepend(e);
else if (e.nodeName === "CANVAS") {
const s = e;
e = document.createElement("div"), e.classList.add("annotationContent", this.editorType), s.before(e);
}
return e;
}
resetAnnotationElement(t) {
const {
firstChild: e
} = t.container;
(e == null ? void 0 : e.nodeName) === "DIV" && e.classList.contains("annotationContent") && e.remove();
}
};
Pn = new WeakMap(), Ye = new WeakMap(), ct = new WeakMap(), ta = new WeakMap(), Fi = new WeakMap(), Go = new WeakMap(), In = new WeakMap(), $t = new WeakMap(), Mn = new WeakMap(), js = new WeakMap(), Ni = new WeakMap(), zo = new WeakMap(), kn = new WeakMap(), ye = new WeakMap(), Uo = new WeakMap(), Ln = new WeakMap(), Vs = new WeakMap(), ys = new WeakMap(), ea = new WeakMap(), sa = new WeakMap(), $e = new WeakMap(), Dn = new WeakMap(), jo = new WeakMap(), Zh = new WeakMap(), G = new WeakSet(), Uc = function([t, e], s, i) {
[s, i] = this.screenToPageTranslation(s, i), this.x += s / t, this.y += i / e, this._onTranslating(this.x, this.y), this.fixAndSetPosition();
}, Vo = new WeakSet(), jc = function(t, e, s) {
switch (s) {
case 90:
return [e, -t];
case 180:
return [-t, -e];
case 270:
return [-e, t];
default:
return [t, e];
}
}, gh = function(t) {
switch (t) {
case 90: {
const [e, s] = this.pageDimensions;
return [0, -e / s, s / e, 0];
}
case 180:
return [-1, 0, 0, -1];
case 270: {
const [e, s] = this.pageDimensions;
return [0, e / s, -s / e, 0];
}
default:
return [1, 0, 0, 1];
}
}, lf = function() {
if (n(this, $t))
return;
f(this, $t, document.createElement("div")), n(this, $t).classList.add("resizers");
const t = this._willKeepAspectRatio ? ["topLeft", "topRight", "bottomRight", "bottomLeft"] : ["topLeft", "topMiddle", "topRight", "middleRight", "bottomRight", "bottomMiddle", "bottomLeft", "middleLeft"], e = this._uiManager._signal;
for (const s of t) {
const i = document.createElement("div");
n(this, $t).append(i), i.classList.add("resizer", s), i.setAttribute("data-resizer-name", s), i.addEventListener("pointerdown", b(this, G, hf).bind(this, s), {
signal: e
}), i.addEventListener("contextmenu", as, {
signal: e
}), i.tabIndex = -1;
}
this.div.prepend(n(this, $t));
}, hf = function(t, e) {
var c;
e.preventDefault();
const {
isMac: s
} = Wt.platform;
if (e.button !== 0 || e.ctrlKey && s)
return;
(c = n(this, ct)) == null || c.toggle(!1);
const i = this._isDraggable;
this._isDraggable = !1, f(this, Mn, [e.screenX, e.screenY]);
const r = new AbortController(), a = this._uiManager.combinedSignal(r);
this.parent.togglePointerEvents(!1), window.addEventListener("pointermove", b(this, G, Wc).bind(this, t), {
passive: !0,
capture: !0,
signal: a
}), window.addEventListener("touchmove", St, {
passive: !1,
signal: a
}), window.addEventListener("contextmenu", as, {
signal: a
}), f(this, js, {
savedX: this.x,
savedY: this.y,
savedWidth: this.width,
savedHeight: this.height
});
const o = this.parent.div.style.cursor, l = this.div.style.cursor;
this.div.style.cursor = this.parent.div.style.cursor = window.getComputedStyle(e.target).cursor;
const h = () => {
var u;
r.abort(), this.parent.togglePointerEvents(!0), (u = n(this, ct)) == null || u.toggle(!0), this._isDraggable = i, this.parent.div.style.cursor = o, this.div.style.cursor = l, b(this, G, mh).call(this);
};
window.addEventListener("pointerup", h, {
signal: a
}), window.addEventListener("blur", h, {
signal: a
});
}, Vc = function(t, e, s, i) {
this.width = s, this.height = i, this.x = t, this.y = e;
const [r, a] = this.parentDimensions;
this.setDims(r * s, a * i), this.fixAndSetPosition(), this._onResized();
}, mh = function() {
if (!n(this, js))
return;
const {
savedX: t,
savedY: e,
savedWidth: s,
savedHeight: i
} = n(this, js);
f(this, js, null);
const r = this.x, a = this.y, o = this.width, l = this.height;
r === t && a === e && o === s && l === i || this.addCommands({
cmd: b(this, G, Vc).bind(this, r, a, o, l),
undo: b(this, G, Vc).bind(this, t, e, s, i),
mustExec: !0
});
}, Wc = function(t, e) {
const [s, i] = this.parentDimensions, r = this.x, a = this.y, o = this.width, l = this.height, h = V.MIN_SIZE / s, c = V.MIN_SIZE / i, u = b(this, G, gh).call(this, this.rotation), p = (N, H) => [u[0] * N + u[2] * H, u[1] * N + u[3] * H], g = b(this, G, gh).call(this, 360 - this.rotation), A = (N, H) => [g[0] * N + g[2] * H, g[1] * N + g[3] * H];
let y, w, v = !1, S = !1;
switch (t) {
case "topLeft":
v = !0, y = (N, H) => [0, 0], w = (N, H) => [N, H];
break;
case "topMiddle":
y = (N, H) => [N / 2, 0], w = (N, H) => [N / 2, H];
break;
case "topRight":
v = !0, y = (N, H) => [N, 0], w = (N, H) => [0, H];
break;
case "middleRight":
S = !0, y = (N, H) => [N, H / 2], w = (N, H) => [0, H / 2];
break;
case "bottomRight":
v = !0, y = (N, H) => [N, H], w = (N, H) => [0, 0];
break;
case "bottomMiddle":
y = (N, H) => [N / 2, H], w = (N, H) => [N / 2, 0];
break;
case "bottomLeft":
v = !0, y = (N, H) => [0, H], w = (N, H) => [N, 0];
break;
case "middleLeft":
S = !0, y = (N, H) => [0, H / 2], w = (N, H) => [N, H / 2];
break;
}
const _ = y(o, l), E = w(o, l);
let C = p(...E);
const x = V._round(r + C[0]), T = V._round(a + C[1]);
let P = 1, M = 1, O, D;
if (e.fromKeyboard)
({
deltaX: O,
deltaY: D
} = e);
else {
const {
screenX: N,
screenY: H
} = e, [Fe, Is] = n(this, Mn);
[O, D] = this.screenToPageTranslation(N - Fe, H - Is), n(this, Mn)[0] = N, n(this, Mn)[1] = H;
}
if ([O, D] = A(O / s, D / i), v) {
const N = Math.hypot(o, l);
P = M = Math.max(Math.min(Math.hypot(E[0] - _[0] - O, E[1] - _[1] - D) / N, 1 / o, 1 / l), h / o, c / l);
} else S ? P = ae(Math.abs(E[0] - _[0] - O), h, 1) / o : M = ae(Math.abs(E[1] - _[1] - D), c, 1) / l;
const tt = V._round(o * P), st = V._round(l * M);
C = p(...w(tt, st));
const q = x - C[0], Jt = T - C[1];
n(this, ye) || f(this, ye, [this.x, this.y, this.width, this.height]), this.width = tt, this.height = st, this.x = q, this.y = Jt, this.setDims(s * tt, i * st), this.fixAndSetPosition(), this._onResizing();
}, cf = function() {
var t;
f(this, js, {
savedX: this.x,
savedY: this.y,
savedWidth: this.width,
savedHeight: this.height
}), (t = n(this, ct)) == null || t.toggle(!1), this.parent.togglePointerEvents(!1);
}, df = function(t, e, s) {
let r = 0.7 * (s / e) + 1 - 0.7;
if (r === 1)
return;
const a = b(this, G, gh).call(this, this.rotation), o = (x, T) => [a[0] * x + a[2] * T, a[1] * x + a[3] * T], [l, h] = this.parentDimensions, c = this.x, u = this.y, p = this.width, g = this.height, A = V.MIN_SIZE / l, y = V.MIN_SIZE / h;
r = Math.max(Math.min(r, 1 / p, 1 / g), A / p, y / g);
const w = V._round(p * r), v = V._round(g * r);
if (w === p && v === g)
return;
n(this, ye) || f(this, ye, [c, u, p, g]);
const S = o(p / 2, g / 2), _ = V._round(c + S[0]), E = V._round(u + S[1]), C = o(w / 2, v / 2);
this.x = _ - C[0], this.y = E - C[1], this.width = w, this.height = v, this.setDims(l * w, h * v), this.fixAndSetPosition(), this._onResizing();
}, uf = function() {
var t;
(t = n(this, ct)) == null || t.toggle(!0), this.parent.togglePointerEvents(!0), b(this, G, mh).call(this);
}, qc = function(t) {
const {
isMac: e
} = Wt.platform;
t.ctrlKey && !e || t.shiftKey || t.metaKey && e ? this.parent.toggleSelected(this) : this.parent.setSelected(this);
}, ff = function(t) {
const {
isSelected: e
} = this;
this._uiManager.setUpDragSession();
let s = !1;
const i = new AbortController(), r = this._uiManager.combinedSignal(i), a = {
capture: !0,
passive: !1,
signal: r
}, o = (h) => {
i.abort(), f(this, Fi, null), f(this, kn, !1), this._uiManager.endDragSession() || b(this, G, qc).call(this, h), s && this._onStopDragging();
};
e && (f(this, ea, t.clientX), f(this, sa, t.clientY), f(this, Fi, t.pointerId), f(this, Go, t.pointerType), window.addEventListener("pointermove", (h) => {
s || (s = !0, this._onStartDragging());
const {
clientX: c,
clientY: u,
pointerId: p
} = h;
if (p !== n(this, Fi)) {
St(h);
return;
}
const [g, A] = this.screenToPageTranslation(c - n(this, ea), u - n(this, sa));
f(this, ea, c), f(this, sa, u), this._uiManager.dragSelectedEditors(g, A);
}, a), window.addEventListener("touchmove", St, a), window.addEventListener("pointerdown", (h) => {
h.pointerType === n(this, Go) && (n(this, Dn) || h.isPrimary) && o(h), St(h);
}, a));
const l = (h) => {
if (!n(this, Fi) || n(this, Fi) === h.pointerId) {
o(h);
return;
}
St(h);
};
window.addEventListener("pointerup", l, {
signal: r
}), window.addEventListener("blur", l, {
signal: r
});
}, Xc = function() {
if (n(this, Ni) || !this.div)
return;
f(this, Ni, new AbortController());
const t = this._uiManager.combinedSignal(n(this, Ni));
this.div.addEventListener("focusin", this.focusin.bind(this), {
signal: t
}), this.div.addEventListener("focusout", this.focusout.bind(this), {
signal: t
});
}, pf = function(t) {
V._resizerKeyboardManager.exec(this, t);
}, gf = function(t) {
var e;
n(this, Vs) && ((e = t.relatedTarget) == null ? void 0 : e.parentNode) !== n(this, $t) && b(this, G, so).call(this);
}, mf = function(t) {
f(this, zo, n(this, Vs) ? t : "");
}, Yc = function(t) {
if (n(this, Ye))
for (const e of n(this, Ye))
e.tabIndex = t;
}, so = function() {
f(this, Vs, !1), b(this, G, Yc).call(this, -1), b(this, G, mh).call(this);
}, m(V, Vo), R(V, "_l10n", null), R(V, "_l10nResizer", null), R(V, "_borderLineWidth", -1), R(V, "_colorManager", new Nc()), R(V, "_zIndex", 1), R(V, "_telemetryTimeout", 1e3);
let lt = V;
class mg extends lt {
constructor(t) {
super(t), this.annotationElementId = t.annotationElementId, this.deleted = !0;
}
serialize() {
return this.serializeDeleted();
}
}
const gu = 3285377520, Ne = 4294901760, hs = 65535;
class bf {
constructor(t) {
this.h1 = t ? t & 4294967295 : gu, this.h2 = t ? t & 4294967295 : gu;
}
update(t) {
let e, s;
if (typeof t == "string") {
e = new Uint8Array(t.length * 2), s = 0;
for (let y = 0, w = t.length; y < w; y++) {
const v = t.charCodeAt(y);
v <= 255 ? e[s++] = v : (e[s++] = v >>> 8, e[s++] = v & 255);
}
} else if (ArrayBuffer.isView(t))
e = t.slice(), s = e.byteLength;
else
throw new Error("Invalid data format, must be a string or TypedArray.");
const i = s >> 2, r = s - i * 4, a = new Uint32Array(e.buffer, 0, i);
let o = 0, l = 0, h = this.h1, c = this.h2;
const u = 3432918353, p = 461845907, g = u & hs, A = p & hs;
for (let y = 0; y < i; y++)
y & 1 ? (o = a[y], o = o * u & Ne | o * g & hs, o = o << 15 | o >>> 17, o = o * p & Ne | o * A & hs, h ^= o, h = h << 13 | h >>> 19, h = h * 5 + 3864292196) : (l = a[y], l = l * u & Ne | l * g & hs, l = l << 15 | l >>> 17, l = l * p & Ne | l * A & hs, c ^= l, c = c << 13 | c >>> 19, c = c * 5 + 3864292196);
switch (o = 0, r) {
case 3:
o ^= e[i * 4 + 2] << 16;
case 2:
o ^= e[i * 4 + 1] << 8;
case 1:
o ^= e[i * 4], o = o * u & Ne | o * g & hs, o = o << 15 | o >>> 17, o = o * p & Ne | o * A & hs, i & 1 ? h ^= o : c ^= o;
}
this.h1 = h, this.h2 = c;
}
hexdigest() {
let t = this.h1, e = this.h2;
return t ^= e >>> 1, t = t * 3981806797 & Ne | t * 36045 & hs, e = e * 4283543511 & Ne | ((e << 16 | t >>> 16) * 2950163797 & Ne) >>> 16, t ^= e >>> 1, t = t * 444984403 & Ne | t * 60499 & hs, e = e * 3301882366 & Ne | ((e << 16 | t >>> 16) * 3120437893 & Ne) >>> 16, t ^= e >>> 1, (t >>> 0).toString(16).padStart(8, "0") + (e >>> 0).toString(16).padStart(8, "0");
}
}
const Kc = Object.freeze({
map: null,
hash: "",
transfer: void 0
});
var Fn, Nn, Gt, tc, Af;
class Zd {
constructor() {
m(this, tc);
m(this, Fn, !1);
m(this, Nn, null);
m(this, Gt, /* @__PURE__ */ new Map());
this.onSetModified = null, this.onResetModified = null, this.onAnnotationEditor = null;
}
getValue(t, e) {
const s = n(this, Gt).get(t);
return s === void 0 ? e : Object.assign(e, s);
}
getRawValue(t) {
return n(this, Gt).get(t);
}
remove(t) {
if (n(this, Gt).delete(t), n(this, Gt).size === 0 && this.resetModified(), typeof this.onAnnotationEditor == "function") {
for (const e of n(this, Gt).values())
if (e instanceof lt)
return;
this.onAnnotationEditor(null);
}
}
setValue(t, e) {
const s = n(this, Gt).get(t);
let i = !1;
if (s !== void 0)
for (const [r, a] of Object.entries(e))
s[r] !== a && (i = !0, s[r] = a);
else
i = !0, n(this, Gt).set(t, e);
i && b(this, tc, Af).call(this), e instanceof lt && typeof this.onAnnotationEditor == "function" && this.onAnnotationEditor(e.constructor._type);
}
has(t) {
return n(this, Gt).has(t);
}
get size() {
return n(this, Gt).size;
}
resetModified() {
n(this, Fn) && (f(this, Fn, !1), typeof this.onResetModified == "function" && this.onResetModified());
}
get print() {
return new yf(this);
}
get serializable() {
if (n(this, Gt).size === 0)
return Kc;
const t = /* @__PURE__ */ new Map(), e = new bf(), s = [], i = /* @__PURE__ */ Object.create(null);
let r = !1;
for (const [a, o] of n(this, Gt)) {
const l = o instanceof lt ? o.serialize(!1, i) : o;
l && (t.set(a, l), e.update(`${a}:${JSON.stringify(l)}`), r || (r = !!l.bitmap));
}
if (r)
for (const a of t.values())
a.bitmap && s.push(a.bitmap);
return t.size > 0 ? {
map: t,
hash: e.hexdigest(),
transfer: s
} : Kc;
}
get editorStats() {
let t = null;
const e = /* @__PURE__ */ new Map();
for (const s of n(this, Gt).values()) {
if (!(s instanceof lt))
continue;
const i = s.telemetryFinalData;
if (!i)
continue;
const {
type: r
} = i;
e.has(r) || e.set(r, Object.getPrototypeOf(s).constructor), t || (t = /* @__PURE__ */ Object.create(null));
const a = t[r] || (t[r] = /* @__PURE__ */ new Map());
for (const [o, l] of Object.entries(i)) {
if (o === "type")
continue;
let h = a.get(o);
h || (h = /* @__PURE__ */ new Map(), a.set(o, h));
const c = h.get(l) ?? 0;
h.set(l, c + 1);
}
}
for (const [s, i] of e)
t[s] = i.computeTelemetryFinalData(t[s]);
return t;
}
resetModifiedIds() {
f(this, Nn, null);
}
get modifiedIds() {
if (n(this, Nn))
return n(this, Nn);
const t = [];
for (const e of n(this, Gt).values())
!(e instanceof lt) || !e.annotationElementId || !e.serialize() || t.push(e.annotationElementId);
return f(this, Nn, {
ids: new Set(t),
hash: t.join(",")
});
}
[Symbol.iterator]() {
return n(this, Gt).entries();
}
}
Fn = new WeakMap(), Nn = new WeakMap(), Gt = new WeakMap(), tc = new WeakSet(), Af = function() {
n(this, Fn) || (f(this, Fn, !0), typeof this.onSetModified == "function" && this.onSetModified());
};
var Wo;
class yf extends Zd {
constructor(e) {
super();
m(this, Wo);
const {
map: s,
hash: i,
transfer: r
} = e.serializable, a = structuredClone(s, r ? {
transfer: r
} : null);
f(this, Wo, {
map: a,
hash: i,
transfer: r
});
}
get print() {
rt("Should not call PrintAnnotationStorage.print");
}
get serializable() {
return n(this, Wo);
}
get modifiedIds() {
return X(this, "modifiedIds", {
ids: /* @__PURE__ */ new Set(),
hash: ""
});
}
}
Wo = new WeakMap();
var ia;
class bg {
constructor({
ownerDocument: t = globalThis.document,
styleElement: e = null
}) {
m(this, ia, /* @__PURE__ */ new Set());
this._document = t, this.nativeFontFaces = /* @__PURE__ */ new Set(), this.styleElement = null, this.loadingRequests = [], this.loadTestFontId = 0;
}
addNativeFontFace(t) {
this.nativeFontFaces.add(t), this._document.fonts.add(t);
}
removeNativeFontFace(t) {
this.nativeFontFaces.delete(t), this._document.fonts.delete(t);
}
insertRule(t) {
this.styleElement || (this.styleElement = this._document.createElement("style"), this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement));
const e = this.styleElement.sheet;
e.insertRule(t, e.cssRules.length);
}
clear() {
for (const t of this.nativeFontFaces)
this._document.fonts.delete(t);
this.nativeFontFaces.clear(), n(this, ia).clear(), this.styleElement && (this.styleElement.remove(), this.styleElement = null);
}
async loadSystemFont({
systemFontInfo: t,
disableFontFace: e,
_inspectFont: s
}) {
if (!(!t || n(this, ia).has(t.loadedName))) {
if (Et(!e, "loadSystemFont shouldn't be called when `disableFontFace` is set."), this.isFontLoadingAPISupported) {
const {
loadedName: i,
src: r,
style: a
} = t, o = new FontFace(i, r, a);
this.addNativeFontFace(o);
try {
await o.load(), n(this, ia).add(i), s == null || s(t);
} catch {
U(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`), this.removeNativeFontFace(o);
}
return;
}
rt("Not implemented: loadSystemFont without the Font Loading API.");
}
}
async bind(t) {
if (t.attached || t.missingFile && !t.systemFontInfo)
return;
if (t.attached = !0, t.systemFontInfo) {
await this.loadSystemFont(t);
return;
}
if (this.isFontLoadingAPISupported) {
const s = t.createNativeFontFace();
if (s) {
this.addNativeFontFace(s);
try {
await s.loaded;
} catch (i) {
throw U(`Failed to load font '${s.family}': '${i}'.`), t.disableFontFace = !0, i;
}
}
return;
}
const e = t.createFontFaceRule();
if (e) {
if (this.insertRule(e), this.isSyncFontLoadingSupported)
return;
await new Promise((s) => {
const i = this._queueLoadingCallback(s);
this._prepareFontLoadEvent(t, i);
});
}
}
get isFontLoadingAPISupported() {
var e;
const t = !!((e = this._document) != null && e.fonts);
return X(this, "isFontLoadingAPISupported", t);
}
get isSyncFontLoadingSupported() {
return X(this, "isSyncFontLoadingSupported", re || Wt.platform.isFirefox);
}
_queueLoadingCallback(t) {
function e() {
for (Et(!i.done, "completeRequest() cannot be called twice."), i.done = !0; s.length > 0 && s[0].done; ) {
const r = s.shift();
setTimeout(r.callback, 0);
}
}
const {
loadingRequests: s
} = this, i = {
done: !1,
complete: e,
callback: t
};
return s.push(i), i;
}
get _loadTestFont() {
const t = atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");
return X(this, "_loadTestFont", t);
}
_prepareFontLoadEvent(t, e) {
function s(E, C) {
return E.charCodeAt(C) << 24 | E.charCodeAt(C + 1) << 16 | E.charCodeAt(C + 2) << 8 | E.charCodeAt(C + 3) & 255;
}
function i(E, C, x, T) {
const P = E.substring(0, C), M = E.substring(C + x);
return P + T + M;
}
let r, a;
const o = this._document.createElement("canvas");
o.width = 1, o.height = 1;
const l = o.getContext("2d");
let h = 0;
function c(E, C) {
if (++h > 30) {
U("Load test font never loaded."), C();
return;
}
if (l.font = "30px " + E, l.fillText(".", 0, 20), l.getImageData(0, 0, 1, 1).data[3] > 0) {
C();
return;
}
setTimeout(c.bind(null, E, C));
}
const u = `lt${Date.now()}${this.loadTestFontId++}`;
let p = this._loadTestFont;
p = i(p, 976, u.length, u);
const A = 16, y = 1482184792;
let w = s(p, A);
for (r = 0, a = u.length - 3; r < a; r += 4)
w = w - y + s(u, r) | 0;
r < u.length && (w = w - y + s(u + "XXX", r) | 0), p = i(p, A, 4, eg(w));
const v = `url(data:font/opentype;base64,${btoa(p)});`, S = `@font-face {font-family:"${u}";src:${v}}`;
this.insertRule(S);
const _ = this._document.createElement("div");
_.style.visibility = "hidden", _.style.width = _.style.height = "10px", _.style.position = "absolute", _.style.top = _.style.left = "0px";
for (const E of [t.loadedName, u]) {
const C = this._document.createElement("span");
C.textContent = "Hi", C.style.fontFamily = E, _.append(C);
}
this._document.body.append(_), c(u, () => {
_.remove(), e.complete();
});
}
}
ia = new WeakMap();
class Ag {
constructor(t, e = null) {
this.compiledGlyphs = /* @__PURE__ */ Object.create(null);
for (const s in t)
this[s] = t[s];
this._inspectFont = e;
}
createNativeFontFace() {
var e;
if (!this.data || this.disableFontFace)
return null;
let t;
if (!this.cssFontInfo)
t = new FontFace(this.loadedName, this.data, {});
else {
const s = {
weight: this.cssFontInfo.fontWeight
};
this.cssFontInfo.italicAngle && (s.style = `oblique ${this.cssFontInfo.italicAngle}deg`), t = new FontFace(this.cssFontInfo.fontFamily, this.data, s);
}
return (e = this._inspectFont) == null || e.call(this, this), t;
}
createFontFaceRule() {
var s;
if (!this.data || this.disableFontFace)
return null;
const t = `url(data:${this.mimetype};base64,${Hu(this.data)});`;
let e;
if (!this.cssFontInfo)
e = `@font-face {font-family:"${this.loadedName}";src:${t}}`;
else {
let i = `font-weight: ${this.cssFontInfo.fontWeight};`;
this.cssFontInfo.italicAngle && (i += `font-style: oblique ${this.cssFontInfo.italicAngle}deg;`), e = `@font-face {font-family:"${this.cssFontInfo.fontFamily}";${i}src:${t}}`;
}
return (s = this._inspectFont) == null || s.call(this, this, t), e;
}
getPathGenerator(t, e) {
if (this.compiledGlyphs[e] !== void 0)
return this.compiledGlyphs[e];
const s = this.loadedName + "_path_" + e;
let i;
try {
i = t.get(s);
} catch (a) {
U(`getPathGenerator - ignoring character: "${a}".`);
}
const r = new Path2D(i || "");
return this.fontExtraProperties || t.delete(s), this.compiledGlyphs[e] = r;
}
}
function yg(d) {
if (d instanceof URL)
return d.href;
if (typeof d == "string") {
if (re)
return d;
const t = URL.parse(d, window.location);
if (t)
return t.href;
}
throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.");
}
function wg(d) {
if (re && typeof Buffer < "u" && d instanceof Buffer)
throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");
if (d instanceof Uint8Array && d.byteLength === d.buffer.byteLength)
return d;
if (typeof d == "string")
return Yl(d);
if (d instanceof ArrayBuffer || ArrayBuffer.isView(d) || typeof d == "object" && !isNaN(d == null ? void 0 : d.length))
return new Uint8Array(d);
throw new Error("Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.");
}
function sh(d) {
if (typeof d != "string")
return null;
if (d.endsWith("/"))
return d;
throw new Error(`Invalid factory url: "${d}" must include trailing slash.`);
}
const Qc = (d) => typeof d == "object" && Number.isInteger(d == null ? void 0 : d.num) && d.num >= 0 && Number.isInteger(d == null ? void 0 : d.gen) && d.gen >= 0, vg = (d) => typeof d == "object" && typeof (d == null ? void 0 : d.name) == "string", _g = ag.bind(null, Qc, vg);
var Ws, ec;
class Sg {
constructor() {
m(this, Ws, /* @__PURE__ */ new Map());
m(this, ec, Promise.resolve());
}
postMessage(t, e) {
const s = {
data: structuredClone(t, e ? {
transfer: e
} : null)
};
n(this, ec).then(() => {
for (const [i] of n(this, Ws))
i.call(this, s);
});
}
addEventListener(t, e, s = null) {
let i = null;
if ((s == null ? void 0 : s.signal) instanceof AbortSignal) {
const {
signal: r
} = s;
if (r.aborted) {
U("LoopbackPort - cannot use an `aborted` signal.");
return;
}
const a = () => this.removeEventListener(t, e);
i = () => r.removeEventListener("abort", a), r.addEventListener("abort", a);
}
n(this, Ws).set(e, i);
}
removeEventListener(t, e) {
const s = n(this, Ws).get(e);
s == null || s(), n(this, Ws).delete(e);
}
terminate() {
for (const [, t] of n(this, Ws))
t == null || t();
n(this, Ws).clear();
}
}
Ws = new WeakMap(), ec = new WeakMap();
const ih = {
DATA: 1,
ERROR: 2
}, vt = {
CANCEL: 1,
CANCEL_COMPLETE: 2,
CLOSE: 3,
ENQUEUE: 4,
ERROR: 5,
PULL: 6,
PULL_COMPLETE: 7,
START_COMPLETE: 8
};
function mu() {
}
function ce(d) {
if (d instanceof an || d instanceof Mc || d instanceof uu || d instanceof $h || d instanceof Sc)
return d;
switch (d instanceof Error || typeof d == "object" && d !== null || rt('wrapReason: Expected "reason" to be a (possibly cloned) Error.'), d.name) {
case "AbortException":
return new an(d.message);
case "InvalidPDFException":
return new Mc(d.message);
case "PasswordException":
return new uu(d.message, d.code);
case "ResponseException":
return new $h(d.message, d.status, d.missing);
case "UnknownErrorException":
return new Sc(d.message, d.details);
}
return new Sc(d.message, d.toString());
}
var na, Ve, wf, vf, _f, bh;
class io {
constructor(t, e, s) {
m(this, Ve);
m(this, na, new AbortController());
this.sourceName = t, this.targetName = e, this.comObj = s, this.callbackId = 1, this.streamId = 1, this.streamSinks = /* @__PURE__ */ Object.create(null), this.streamControllers = /* @__PURE__ */ Object.create(null), this.callbackCapabilities = /* @__PURE__ */ Object.create(null), this.actionHandler = /* @__PURE__ */ Object.create(null), s.addEventListener("message", b(this, Ve, wf).bind(this), {
signal: n(this, na).signal
});
}
on(t, e) {
const s = this.actionHandler;
if (s[t])
throw new Error(`There is already an actionName called "${t}"`);
s[t] = e;
}
send(t, e, s) {
this.comObj.postMessage({
sourceName: this.sourceName,
targetName: this.targetName,
action: t,
data: e
}, s);
}
sendWithPromise(t, e, s) {
const i = this.callbackId++, r = Promise.withResolvers();
this.callbackCapabilities[i] = r;
try {
this.comObj.postMessage({
sourceName: this.sourceName,
targetName: this.targetName,
action: t,
callbackId: i,
data: e
}, s);
} catch (a) {
r.reject(a);
}
return r.promise;
}
sendWithStream(t, e, s, i) {
const r = this.streamId++, a = this.sourceName, o = this.targetName, l = this.comObj;
return new ReadableStream({
start: (h) => {
const c = Promise.withResolvers();
return this.streamControllers[r] = {
controller: h,
startCall: c,
pullCall: null,
cancelCall: null,
isClosed: !1
}, l.postMessage({
sourceName: a,
targetName: o,
action: t,
streamId: r,
data: e,
desiredSize: h.desiredSize
}, i), c.promise;
},
pull: (h) => {
const c = Promise.withResolvers();
return this.streamControllers[r].pullCall = c, l.postMessage({
sourceName: a,
targetName: o,
stream: vt.PULL,
streamId: r,
desiredSize: h.desiredSize
}), c.promise;
},
cancel: (h) => {
Et(h instanceof Error, "cancel must have a valid reason");
const c = Promise.withResolvers();
return this.streamControllers[r].cancelCall = c, this.streamControllers[r].isClosed = !0, l.postMessage({
sourceName: a,
targetName: o,
stream: vt.CANCEL,
streamId: r,
reason: ce(h)
}), c.promise;
}
}, s);
}
destroy() {
var t;
(t = n(this, na)) == null || t.abort(), f(this, na, null);
}
}
na = new WeakMap(), Ve = new WeakSet(), wf = function({
data: t
}) {
if (t.targetName !== this.sourceName)
return;
if (t.stream) {
b(this, Ve, _f).call(this, t);
return;
}
if (t.callback) {
const s = t.callbackId, i = this.callbackCapabilities[s];
if (!i)
throw new Error(`Cannot resolve callback ${s}`);
if (delete this.callbackCapabilities[s], t.callback === ih.DATA)
i.resolve(t.data);
else if (t.callback === ih.ERROR)
i.reject(ce(t.reason));
else
throw new Error("Unexpected callback case");
return;
}
const e = this.actionHandler[t.action];
if (!e)
throw new Error(`Unknown action from worker: ${t.action}`);
if (t.callbackId) {
const s = this.sourceName, i = t.sourceName, r = this.comObj;
Promise.try(e, t.data).then(function(a) {
r.postMessage({
sourceName: s,
targetName: i,
callback: ih.DATA,
callbackId: t.callbackId,
data: a
});
}, function(a) {
r.postMessage({
sourceName: s,
targetName: i,
callback: ih.ERROR,
callbackId: t.callbackId,
reason: ce(a)
});
});
return;
}
if (t.streamId) {
b(this, Ve, vf).call(this, t);
return;
}
e(t.data);
}, vf = function(t) {
const e = t.streamId, s = this.sourceName, i = t.sourceName, r = this.comObj, a = this, o = this.actionHandler[t.action], l = {
enqueue(h, c = 1, u) {
if (this.isCancelled)
return;
const p = this.desiredSize;
this.desiredSize -= c, p > 0 && this.desiredSize <= 0 && (this.sinkCapability = Promise.withResolvers(), this.ready = this.sinkCapability.promise), r.postMessage({
sourceName: s,
targetName: i,
stream: vt.ENQUEUE,
streamId: e,
chunk: h
}, u);
},
close() {
this.isCancelled || (this.isCancelled = !0, r.postMessage({
sourceName: s,
targetName: i,
stream: vt.CLOSE,
streamId: e
}), delete a.streamSinks[e]);
},
error(h) {
Et(h instanceof Error, "error must have a valid reason"), !this.isCancelled && (this.isCancelled = !0, r.postMessage({
sourceName: s,
targetName: i,
stream: vt.ERROR,
streamId: e,
reason: ce(h)
}));
},
sinkCapability: Promise.withResolvers(),
onPull: null,
onCancel: null,
isCancelled: !1,
desiredSize: t.desiredSize,
ready: null
};
l.sinkCapability.resolve(), l.ready = l.sinkCapability.promise, this.streamSinks[e] = l, Promise.try(o, t.data, l).then(function() {
r.postMessage({
sourceName: s,
targetName: i,
stream: vt.START_COMPLETE,
streamId: e,
success: !0
});
}, function(h) {
r.postMessage({
sourceName: s,
targetName: i,
stream: vt.START_COMPLETE,
streamId: e,
reason: ce(h)
});
});
}, _f = function(t) {
const e = t.streamId, s = this.sourceName, i = t.sourceName, r = this.comObj, a = this.streamControllers[e], o = this.streamSinks[e];
switch (t.stream) {
case vt.START_COMPLETE:
t.success ? a.startCall.resolve() : a.startCall.reject(ce(t.reason));
break;
case vt.PULL_COMPLETE:
t.success ? a.pullCall.resolve() : a.pullCall.reject(ce(t.reason));
break;
case vt.PULL:
if (!o) {
r.postMessage({
sourceName: s,
targetName: i,
stream: vt.PULL_COMPLETE,
streamId: e,
success: !0
});
break;
}
o.desiredSize <= 0 && t.desiredSize > 0 && o.sinkCapability.resolve(), o.desiredSize = t.desiredSize, Promise.try(o.onPull || mu).then(function() {
r.postMessage({
sourceName: s,
targetName: i,
stream: vt.PULL_COMPLETE,
streamId: e,
success: !0
});
}, function(h) {
r.postMessage({
sourceName: s,
targetName: i,
stream: vt.PULL_COMPLETE,
streamId: e,
reason: ce(h)
});
});
break;
case vt.ENQUEUE:
if (Et(a, "enqueue should have stream controller"), a.isClosed)
break;
a.controller.enqueue(t.chunk);
break;
case vt.CLOSE:
if (Et(a, "close should have stream controller"), a.isClosed)
break;
a.isClosed = !0, a.controller.close(), b(this, Ve, bh).call(this, a, e);
break;
case vt.ERROR:
Et(a, "error should have stream controller"), a.controller.error(ce(t.reason)), b(this, Ve, bh).call(this, a, e);
break;
case vt.CANCEL_COMPLETE:
t.success ? a.cancelCall.resolve() : a.cancelCall.reject(ce(t.reason)), b(this, Ve, bh).call(this, a, e);
break;
case vt.CANCEL:
if (!o)
break;
const l = ce(t.reason);
Promise.try(o.onCancel || mu, l).then(function() {
r.postMessage({
sourceName: s,
targetName: i,
stream: vt.CANCEL_COMPLETE,
streamId: e,
success: !0
});
}, function(h) {
r.postMessage({
sourceName: s,
targetName: i,
stream: vt.CANCEL_COMPLETE,
streamId: e,
reason: ce(h)
});
}), o.sinkCapability.reject(l), o.isCancelled = !0, delete this.streamSinks[e];
break;
default:
throw new Error("Unexpected stream case");
}
}, bh = async function(t, e) {
var s, i, r;
await Promise.allSettled([(s = t.startCall) == null ? void 0 : s.promise, (i = t.pullCall) == null ? void 0 : i.promise, (r = t.cancelCall) == null ? void 0 : r.promise]), delete this.streamControllers[e];
};
var qo;
class Sf {
constructor({
enableHWA: t = !1
}) {
m(this, qo, !1);
f(this, qo, t);
}
create(t, e) {
if (t <= 0 || e <= 0)
throw new Error("Invalid canvas size");
const s = this._createCanvas(t, e);
return {
canvas: s,
context: s.getContext("2d", {
willReadFrequently: !n(this, qo)
})
};
}
reset(t, e, s) {
if (!t.canvas)
throw new Error("Canvas is not specified");
if (e <= 0 || s <= 0)
throw new Error("Invalid canvas size");
t.canvas.width = e, t.canvas.height = s;
}
destroy(t) {
if (!t.canvas)
throw new Error("Canvas is not specified");
t.canvas.width = 0, t.canvas.height = 0, t.canvas = null, t.context = null;
}
_createCanvas(t, e) {
rt("Abstract method `_createCanvas` called.");
}
}
qo = new WeakMap();
class Eg extends Sf {
constructor({
ownerDocument: t = globalThis.document,
enableHWA: e = !1
}) {
super({
enableHWA: e
}), this._document = t;
}
_createCanvas(t, e) {
const s = this._document.createElement("canvas");
return s.width = t, s.height = e, s;
}
}
class Ef {
constructor({
baseUrl: t = null,
isCompressed: e = !0
}) {
this.baseUrl = t, this.isCompressed = e;
}
async fetch({
name: t
}) {
if (!this.baseUrl)
throw new Error("Ensure that the `cMapUrl` and `cMapPacked` API parameters are provided.");
if (!t)
throw new Error("CMap name must be specified.");
const e = this.baseUrl + t + (this.isCompressed ? ".bcmap" : "");
return this._fetch(e).then((s) => ({
cMapData: s,
isCompressed: this.isCompressed
})).catch((s) => {
throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${e}`);
});
}
async _fetch(t) {
rt("Abstract method `_fetch` called.");
}
}
class bu extends Ef {
async _fetch(t) {
const e = await Kl(t, this.isCompressed ? "arraybuffer" : "text");
return e instanceof ArrayBuffer ? new Uint8Array(e) : Yl(e);
}
}
class Cf {
addFilter(t) {
return "none";
}
addHCMFilter(t, e) {
return "none";
}
addAlphaFilter(t) {
return "none";
}
addLuminosityFilter(t) {
return "none";
}
addHighlightHCMFilter(t, e, s, i, r) {
return "none";
}
destroy(t = !1) {
}
}
var On, ra, qs, Xs, Kt, Bn, Hn, k, Xt, no, kr, Ah, Lr, xf, Jc, Dr, ro, ao, Zc, oo;
class Cg extends Cf {
constructor({
docId: e,
ownerDocument: s = globalThis.document
}) {
super();
m(this, k);
m(this, On);
m(this, ra);
m(this, qs);
m(this, Xs);
m(this, Kt);
m(this, Bn);
m(this, Hn, 0);
f(this, Xs, e), f(this, Kt, s);
}
addFilter(e) {
if (!e)
return "none";
let s = n(this, k, Xt).get(e);
if (s)
return s;
const [i, r, a] = b(this, k, Ah).call(this, e), o = e.length === 1 ? i : `${i}${r}${a}`;
if (s = n(this, k, Xt).get(o), s)
return n(this, k, Xt).set(e, s), s;
const l = `g_${n(this, Xs)}_transfer_map_${Zt(this, Hn)._++}`, h = b(this, k, Lr).call(this, l);
n(this, k, Xt).set(e, h), n(this, k, Xt).set(o, h);
const c = b(this, k, Dr).call(this, l);
return b(this, k, ao).call(this, i, r, a, c), h;
}
addHCMFilter(e, s) {
var A;
const i = `${e}-${s}`, r = "base";
let a = n(this, k, no).get(r);
if ((a == null ? void 0 : a.key) === i || (a ? ((A = a.filter) == null || A.remove(), a.key = i, a.url = "none", a.filter = null) : (a = {
key: i,
url: "none",
filter: null
}, n(this, k, no).set(r, a)), !e || !s))
return a.url;
const o = b(this, k, oo).call(this, e);
e = $.makeHexColor(...o);
const l = b(this, k, oo).call(this, s);
if (s = $.makeHexColor(...l), n(this, k, kr).style.color = "", e === "#000000" && s === "#ffffff" || e === s)
return a.url;
const h = new Array(256);
for (let y = 0; y <= 255; y++) {
const w = y / 255;
h[y] = w <= 0.03928 ? w / 12.92 : ((w + 0.055) / 1.055) ** 2.4;
}
const c = h.join(","), u = `g_${n(this, Xs)}_hcm_filter`, p = a.filter = b(this, k, Dr).call(this, u);
b(this, k, ao).call(this, c, c, c, p), b(this, k, Jc).call(this, p);
const g = (y, w) => {
const v = o[y] / 255, S = l[y] / 255, _ = new Array(w + 1);
for (let E = 0; E <= w; E++)
_[E] = v + E / w * (S - v);
return _.join(",");
};
return b(this, k, ao).call(this, g(0, 5), g(1, 5), g(2, 5), p), a.url = b(this, k, Lr).call(this, u), a.url;
}
addAlphaFilter(e) {
let s = n(this, k, Xt).get(e);
if (s)
return s;
const [i] = b(this, k, Ah).call(this, [e]), r = `alpha_${i}`;
if (s = n(this, k, Xt).get(r), s)
return n(this, k, Xt).set(e, s), s;
const a = `g_${n(this, Xs)}_alpha_map_${Zt(this, Hn)._++}`, o = b(this, k, Lr).call(this, a);
n(this, k, Xt).set(e, o), n(this, k, Xt).set(r, o);
const l = b(this, k, Dr).call(this, a);
return b(this, k, Zc).call(this, i, l), o;
}
addLuminosityFilter(e) {
let s = n(this, k, Xt).get(e || "luminosity");
if (s)
return s;
let i, r;
if (e ? ([i] = b(this, k, Ah).call(this, [e]), r = `luminosity_${i}`) : r = "luminosity", s = n(this, k, Xt).get(r), s)
return n(this, k, Xt).set(e, s), s;
const a = `g_${n(this, Xs)}_luminosity_map_${Zt(this, Hn)._++}`, o = b(this, k, Lr).call(this, a);
n(this, k, Xt).set(e, o), n(this, k, Xt).set(r, o);
const l = b(this, k, Dr).call(this, a);
return b(this, k, xf).call(this, l), e && b(this, k, Zc).call(this, i, l), o;
}
addHighlightHCMFilter(e, s, i, r, a) {
var S;
const o = `${s}-${i}-${r}-${a}`;
let l = n(this, k, no).get(e);
if ((l == null ? void 0 : l.key) === o || (l ? ((S = l.filter) == null || S.remove(), l.key = o, l.url = "none", l.filter = null) : (l = {
key: o,
url: "none",
filter: null
}, n(this, k, no).set(e, l)), !s || !i))
return l.url;
const [h, c] = [s, i].map(b(this, k, oo).bind(this));
let u = Math.round(0.2126 * h[0] + 0.7152 * h[1] + 0.0722 * h[2]), p = Math.round(0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2]), [g, A] = [r, a].map(b(this, k, oo).bind(this));
p < u && ([u, p, g, A] = [p, u, A, g]), n(this, k, kr).style.color = "";
const y = (_, E, C) => {
const x = new Array(256), T = (p - u) / C, P = _ / 255, M = (E - _) / (255 * C);
let O = 0;
for (let D = 0; D <= C; D++) {
const tt = Math.round(u + D * T), st = P + D * M;
for (let q = O; q <= tt; q++)
x[q] = st;
O = tt + 1;
}
for (let D = O; D < 256; D++)
x[D] = x[O - 1];
return x.join(",");
}, w = `g_${n(this, Xs)}_hcm_${e}_filter`, v = l.filter = b(this, k, Dr).call(this, w);
return b(this, k, Jc).call(this, v), b(this, k, ao).call(this, y(g[0], A[0], 5), y(g[1], A[1], 5), y(g[2], A[2], 5), v), l.url = b(this, k, Lr).call(this, w), l.url;
}
destroy(e = !1) {
var s, i, r, a;
e && ((s = n(this, Bn)) != null && s.size) || ((i = n(this, qs)) == null || i.parentNode.parentNode.remove(), f(this, qs, null), (r = n(this, ra)) == null || r.clear(), f(this, ra, null), (a = n(this, Bn)) == null || a.clear(), f(this, Bn, null), f(this, Hn, 0));
}
}
On = new WeakMap(), ra = new WeakMap(), qs = new WeakMap(), Xs = new WeakMap(), Kt = new WeakMap(), Bn = new WeakMap(), Hn = new WeakMap(), k = new WeakSet(), Xt = function() {
return n(this, ra) || f(this, ra, /* @__PURE__ */ new Map());
}, no = function() {
return n(this, Bn) || f(this, Bn, /* @__PURE__ */ new Map());
}, kr = function() {
if (!n(this, qs)) {
const e = n(this, Kt).createElement("div"), {
style: s
} = e;
s.visibility = "hidden", s.contain = "strict", s.width = s.height = 0, s.position = "absolute", s.top = s.left = 0, s.zIndex = -1;
const i = n(this, Kt).createElementNS(ks, "svg");
i.setAttribute("width", 0), i.setAttribute("height", 0), f(this, qs, n(this, Kt).createElementNS(ks, "defs")), e.append(i), i.append(n(this, qs)), n(this, Kt).body.append(e);
}
return n(this, qs);
}, Ah = function(e) {
if (e.length === 1) {
const h = e[0], c = new Array(256);
for (let p = 0; p < 256; p++)
c[p] = h[p] / 255;
const u = c.join(",");
return [u, u, u];
}
const [s, i, r] = e, a = new Array(256), o = new Array(256), l = new Array(256);
for (let h = 0; h < 256; h++)
a[h] = s[h] / 255, o[h] = i[h] / 255, l[h] = r[h] / 255;
return [a.join(","), o.join(","), l.join(",")];
}, Lr = function(e) {
if (n(this, On) === void 0) {
f(this, On, "");
const s = n(this, Kt).URL;
s !== n(this, Kt).baseURI && (mc(s) ? U('#createUrl: ignore "data:"-URL for performance reasons.') : f(this, On, Nu(s, "")));
}
return `url(${n(this, On)}#${e})`;
}, xf = function(e) {
const s = n(this, Kt).createElementNS(ks, "feColorMatrix");
s.setAttribute("type", "matrix"), s.setAttribute("values", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0"), e.append(s);
}, Jc = function(e) {
const s = n(this, Kt).createElementNS(ks, "feColorMatrix");
s.setAttribute("type", "matrix"), s.setAttribute("values", "0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0"), e.append(s);
}, Dr = function(e) {
const s = n(this, Kt).createElementNS(ks, "filter");
return s.setAttribute("color-interpolation-filters", "sRGB"), s.setAttribute("id", e), n(this, k, kr).append(s), s;
}, ro = function(e, s, i) {
const r = n(this, Kt).createElementNS(ks, s);
r.setAttribute("type", "discrete"), r.setAttribute("tableValues", i), e.append(r);
}, ao = function(e, s, i, r) {
const a = n(this, Kt).createElementNS(ks, "feComponentTransfer");
r.append(a), b(this, k, ro).call(this, a, "feFuncR", e), b(this, k, ro).call(this, a, "feFuncG", s), b(this, k, ro).call(this, a, "feFuncB", i);
}, Zc = function(e, s) {
const i = n(this, Kt).createElementNS(ks, "feComponentTransfer");
s.append(i), b(this, k, ro).call(this, i, "feFuncA", e);
}, oo = function(e) {
return n(this, k, kr).style.color = e, Jd(getComputedStyle(n(this, k, kr)).getPropertyValue("color"));
};
class Tf {
constructor({
baseUrl: t = null
}) {
this.baseUrl = t;
}
async fetch({
filename: t
}) {
if (!this.baseUrl)
throw new Error("Ensure that the `standardFontDataUrl` API parameter is provided.");
if (!t)
throw new Error("Font filename must be specified.");
const e = `${this.baseUrl}${t}`;
return this._fetch(e).catch((s) => {
throw new Error(`Unable to load font data at: ${e}`);
});
}
async _fetch(t) {
rt("Abstract method `_fetch` called.");
}
}
class Au extends Tf {
async _fetch(t) {
const e = await Kl(t, "arraybuffer");
return new Uint8Array(e);
}
}
class Rf {
constructor({
baseUrl: t = null
}) {
this.baseUrl = t;
}
async fetch({
filename: t
}) {
if (!this.baseUrl)
throw new Error("Ensure that the `wasmUrl` API parameter is provided.");
if (!t)
throw new Error("Wasm filename must be specified.");
const e = `${this.baseUrl}${t}`;
return this._fetch(e).catch((s) => {
throw new Error(`Unable to load wasm data at: ${e}`);
});
}
async _fetch(t) {
rt("Abstract method `_fetch` called.");
}
}
class yu extends Rf {
async _fetch(t) {
const e = await Kl(t, "arraybuffer");
return new Uint8Array(e);
}
}
re && U("Please use the `legacy` build in Node.js environments.");
async function tu(d) {
const e = await process.getBuiltinModule("fs").promises.readFile(d);
return new Uint8Array(e);
}
class xg extends Cf {
}
class Tg extends Sf {
_createCanvas(t, e) {
return process.getBuiltinModule("module").createRequire(import.meta.url)("@napi-rs/canvas").createCanvas(t, e);
}
}
class Rg extends Ef {
async _fetch(t) {
return tu(t);
}
}
class Pg extends Tf {
async _fetch(t) {
return tu(t);
}
}
class Ig extends Rf {
async _fetch(t) {
return tu(t);
}
}
const jt = {
FILL: "Fill",
STROKE: "Stroke",
SHADING: "Shading"
};
function td(d, t) {
if (!t)
return;
const e = t[2] - t[0], s = t[3] - t[1], i = new Path2D();
i.rect(t[0], t[1], e, s), d.clip(i);
}
class eu {
isModifyingCurrentTransform() {
return !1;
}
getPattern() {
rt("Abstract method `getPattern` called.");
}
}
class Mg extends eu {
constructor(t) {
super(), this._type = t[1], this._bbox = t[2], this._colorStops = t[3], this._p0 = t[4], this._p1 = t[5], this._r0 = t[6], this._r1 = t[7], this.matrix = null;
}
_createGradient(t) {
let e;
this._type === "axial" ? e = t.createLinearGradient(this._p0[0], this._p0[1], this._p1[0], this._p1[1]) : this._type === "radial" && (e = t.createRadialGradient(this._p0[0], this._p0[1], this._r0, this._p1[0], this._p1[1], this._r1));
for (const s of this._colorStops)
e.addColorStop(s[0], s[1]);
return e;
}
getPattern(t, e, s, i) {
let r;
if (i === jt.STROKE || i === jt.FILL) {
const a = e.current.getClippedPathBoundingBox(i, pt(t)) || [0, 0, 0, 0], o = Math.ceil(a[2] - a[0]) || 1, l = Math.ceil(a[3] - a[1]) || 1, h = e.cachedCanvases.getCanvas("pattern", o, l), c = h.context;
c.clearRect(0, 0, c.canvas.width, c.canvas.height), c.beginPath(), c.rect(0, 0, c.canvas.width, c.canvas.height), c.translate(-a[0], -a[1]), s = $.transform(s, [1, 0, 0, 1, a[0], a[1]]), c.transform(...e.baseTransform), this.matrix && c.transform(...this.matrix), td(c, this._bbox), c.fillStyle = this._createGradient(c), c.fill(), r = t.createPattern(h.canvas, "no-repeat");
const u = new DOMMatrix(s);
r.setTransform(u);
} else
td(t, this._bbox), r = this._createGradient(t);
return r;
}
}
function xc(d, t, e, s, i, r, a, o) {
const l = t.coords, h = t.colors, c = d.data, u = d.width * 4;
let p;
l[e + 1] > l[s + 1] && (p = e, e = s, s = p, p = r, r = a, a = p), l[s + 1] > l[i + 1] && (p = s, s = i, i = p, p = a, a = o, o = p), l[e + 1] > l[s + 1] && (p = e, e = s, s = p, p = r, r = a, a = p);
const g = (l[e] + t.offsetX) * t.scaleX, A = (l[e + 1] + t.offsetY) * t.scaleY, y = (l[s] + t.offsetX) * t.scaleX, w = (l[s + 1] + t.offsetY) * t.scaleY, v = (l[i] + t.offsetX) * t.scaleX, S = (l[i + 1] + t.offsetY) * t.scaleY;
if (A >= S)
return;
const _ = h[r], E = h[r + 1], C = h[r + 2], x = h[a], T = h[a + 1], P = h[a + 2], M = h[o], O = h[o + 1], D = h[o + 2], tt = Math.round(A), st = Math.round(S);
let q, Jt, N, H, Fe, Is, dn, Ms;
for (let Mt = tt; Mt <= st; Mt++) {
if (Mt < w) {
const gt = Mt < A ? 0 : (A - Mt) / (A - w);
q = g - (g - y) * gt, Jt = _ - (_ - x) * gt, N = E - (E - T) * gt, H = C - (C - P) * gt;
} else {
let gt;
Mt > S ? gt = 1 : w === S ? gt = 0 : gt = (w - Mt) / (w - S), q = y - (y - v) * gt, Jt = x - (x - M) * gt, N = T - (T - O) * gt, H = P - (P - D) * gt;
}
let bt;
Mt < A ? bt = 0 : Mt > S ? bt = 1 : bt = (A - Mt) / (A - S), Fe = g - (g - v) * bt, Is = _ - (_ - M) * bt, dn = E - (E - O) * bt, Ms = C - (C - D) * bt;
const Ir = Math.round(Math.min(q, Fe)), Ai = Math.round(Math.max(q, Fe));
let yi = u * Mt + Ir * 4;
for (let gt = Ir; gt <= Ai; gt++)
bt = (q - gt) / (q - Fe), bt < 0 ? bt = 0 : bt > 1 && (bt = 1), c[yi++] = Jt - (Jt - Is) * bt | 0, c[yi++] = N - (N - dn) * bt | 0, c[yi++] = H - (H - Ms) * bt | 0, c[yi++] = 255;
}
}
function kg(d, t, e) {
const s = t.coords, i = t.colors;
let r, a;
switch (t.type) {
case "lattice":
const o = t.verticesPerRow, l = Math.floor(s.length / o) - 1, h = o - 1;
for (r = 0; r < l; r++) {
let c = r * o;
for (let u = 0; u < h; u++, c++)
xc(d, e, s[c], s[c + 1], s[c + o], i[c], i[c + 1], i[c + o]), xc(d, e, s[c + o + 1], s[c + 1], s[c + o], i[c + o + 1], i[c + 1], i[c + o]);
}
break;
case "triangles":
for (r = 0, a = s.length; r < a; r += 3)
xc(d, e, s[r], s[r + 1], s[r + 2], i[r], i[r + 1], i[r + 2]);
break;
default:
throw new Error("illegal figure");
}
}
class Lg extends eu {
constructor(t) {
super(), this._coords = t[2], this._colors = t[3], this._figures = t[4], this._bounds = t[5], this._bbox = t[6], this._background = t[7], this.matrix = null;
}
_createMeshCanvas(t, e, s) {
const o = Math.floor(this._bounds[0]), l = Math.floor(this._bounds[1]), h = Math.ceil(this._bounds[2]) - o, c = Math.ceil(this._bounds[3]) - l, u = Math.min(Math.ceil(Math.abs(h * t[0] * 1.1)), 3e3), p = Math.min(Math.ceil(Math.abs(c * t[1] * 1.1)), 3e3), g = h / u, A = c / p, y = {
coords: this._coords,
colors: this._colors,
offsetX: -o,
offsetY: -l,
scaleX: 1 / g,
scaleY: 1 / A
}, w = u + 2 * 2, v = p + 2 * 2, S = s.getCanvas("mesh", w, v), _ = S.context, E = _.createImageData(u, p);
if (e) {
const x = E.data;
for (let T = 0, P = x.length; T < P; T += 4)
x[T] = e[0], x[T + 1] = e[1], x[T + 2] = e[2], x[T + 3] = 255;
}
for (const x of this._figures)
kg(E, x, y);
return _.putImageData(E, 2, 2), {
canvas: S.canvas,
offsetX: o - 2 * g,
offsetY: l - 2 * A,
scaleX: g,
scaleY: A
};
}
isModifyingCurrentTransform() {
return !0;
}
getPattern(t, e, s, i) {
td(t, this._bbox);
const r = new Float32Array(2);
if (i === jt.SHADING)
$.singularValueDecompose2dScale(pt(t), r);
else if (this.matrix) {
$.singularValueDecompose2dScale(this.matrix, r);
const [o, l] = r;
$.singularValueDecompose2dScale(e.baseTransform, r), r[0] *= o, r[1] *= l;
} else
$.singularValueDecompose2dScale(e.baseTransform, r);
const a = this._createMeshCanvas(r, i === jt.SHADING ? null : this._background, e.cachedCanvases);
return i !== jt.SHADING && (t.setTransform(...e.baseTransform), this.matrix && t.transform(...this.matrix)), t.translate(a.offsetX, a.offsetY), t.scale(a.scaleX, a.scaleY), t.createPattern(a.canvas, "no-repeat");
}
}
class Dg extends eu {
getPattern() {
return "hotpink";
}
}
function Fg(d) {
switch (d[0]) {
case "RadialAxial":
return new Mg(d);
case "Mesh":
return new Lg(d);
case "Dummy":
return new Dg();
}
throw new Error(`Unknown IR type: ${d[0]}`);
}
const wu = {
COLORED: 1,
UNCOLORED: 2
}, sc = class sc {
constructor(t, e, s, i) {
this.color = t[1], this.operatorList = t[2], this.matrix = t[3], this.bbox = t[4], this.xstep = t[5], this.ystep = t[6], this.paintType = t[7], this.tilingType = t[8], this.ctx = e, this.canvasGraphicsFactory = s, this.baseTransform = i;
}
createPatternCanvas(t) {
const {
bbox: e,
operatorList: s,
paintType: i,
tilingType: r,
color: a,
canvasGraphicsFactory: o
} = this;
let {
xstep: l,
ystep: h
} = this;
l = Math.abs(l), h = Math.abs(h), gc("TilingType: " + r);
const c = e[0], u = e[1], p = e[2], g = e[3], A = p - c, y = g - u, w = new Float32Array(2);
$.singularValueDecompose2dScale(this.matrix, w);
const [v, S] = w;
$.singularValueDecompose2dScale(this.baseTransform, w);
const _ = v * w[0], E = S * w[1];
let C = A, x = y, T = !1, P = !1;
const M = Math.ceil(l * _), O = Math.ceil(h * E), D = Math.ceil(A * _), tt = Math.ceil(y * E);
M >= D ? C = l : T = !0, O >= tt ? x = h : P = !0;
const st = this.getSizeAndScale(C, this.ctx.canvas.width, _), q = this.getSizeAndScale(x, this.ctx.canvas.height, E), Jt = t.cachedCanvases.getCanvas("pattern", st.size, q.size), N = Jt.context, H = o.createCanvasGraphics(N);
if (H.groupLevel = t.groupLevel, this.setFillAndStrokeStyleToContext(H, i, a), N.translate(-st.scale * c, -q.scale * u), H.transform(st.scale, 0, 0, q.scale, 0, 0), N.save(), this.clipBbox(H, c, u, p, g), H.baseTransform = pt(H.ctx), H.executeOperatorList(s), H.endDrawing(), N.restore(), T || P) {
const Fe = Jt.canvas;
T && (C = l), P && (x = h);
const Is = this.getSizeAndScale(C, this.ctx.canvas.width, _), dn = this.getSizeAndScale(x, this.ctx.canvas.height, E), Ms = Is.size, Mt = dn.size, bt = t.cachedCanvases.getCanvas("pattern-workaround", Ms, Mt), Ir = bt.context, Ai = T ? Math.floor(A / l) : 0, yi = P ? Math.floor(y / h) : 0;
for (let gt = 0; gt <= Ai; gt++)
for (let qa = 0; qa <= yi; qa++)
Ir.drawImage(Fe, Ms * gt, Mt * qa, Ms, Mt, 0, 0, Ms, Mt);
return {
canvas: bt.canvas,
scaleX: Is.scale,
scaleY: dn.scale,
offsetX: c,
offsetY: u
};
}
return {
canvas: Jt.canvas,
scaleX: st.scale,
scaleY: q.scale,
offsetX: c,
offsetY: u
};
}
getSizeAndScale(t, e, s) {
const i = Math.max(sc.MAX_PATTERN_SIZE, e);
let r = Math.ceil(t * s);
return r >= i ? r = i : s = r / t, {
scale: s,
size: r
};
}
clipBbox(t, e, s, i, r) {
const a = i - e, o = r - s;
t.ctx.rect(e, s, a, o), $.axialAlignedBoundingBox([e, s, i, r], pt(t.ctx), t.current.minMax), t.clip(), t.endPath();
}
setFillAndStrokeStyleToContext(t, e, s) {
const i = t.ctx, r = t.current;
switch (e) {
case wu.COLORED:
const {
fillStyle: a,
strokeStyle: o
} = this.ctx;
i.fillStyle = r.fillColor = a, i.strokeStyle = r.strokeColor = o;
break;
case wu.UNCOLORED:
i.fillStyle = i.strokeStyle = s, r.fillColor = r.strokeColor = s;
break;
default:
throw new tg(`Unsupported paint type: ${e}`);
}
}
isModifyingCurrentTransform() {
return !1;
}
getPattern(t, e, s, i) {
let r = s;
i !== jt.SHADING && (r = $.transform(r, e.baseTransform), this.matrix && (r = $.transform(r, this.matrix)));
const a = this.createPatternCanvas(e);
let o = new DOMMatrix(r);
o = o.translate(a.offsetX, a.offsetY), o = o.scale(1 / a.scaleX, 1 / a.scaleY);
const l = t.createPattern(a.canvas, "repeat");
return l.setTransform(o), l;
}
};
R(sc, "MAX_PATTERN_SIZE", 3e3);
let ed = sc;
function Ng({
src: d,
srcPos: t = 0,
dest: e,
width: s,
height: i,
nonBlackColor: r = 4294967295,
inverseDecode: a = !1
}) {
const o = Wt.isLittleEndian ? 4278190080 : 255, [l, h] = a ? [r, o] : [o, r], c = s >> 3, u = s & 7, p = d.length;
e = new Uint32Array(e.buffer);
let g = 0;
for (let A = 0; A < i; A++) {
for (const w = t + c; t < w; t++) {
const v = t < p ? d[t] : 255;
e[g++] = v & 128 ? h : l, e[g++] = v & 64 ? h : l, e[g++] = v & 32 ? h : l, e[g++] = v & 16 ? h : l, e[g++] = v & 8 ? h : l, e[g++] = v & 4 ? h : l, e[g++] = v & 2 ? h : l, e[g++] = v & 1 ? h : l;
}
if (u === 0)
continue;
const y = t < p ? d[t++] : 255;
for (let w = 0; w < u; w++)
e[g++] = y & 1 << 7 - w ? h : l;
}
return {
srcPos: t,
destPos: g
};
}
const vu = 16, _u = 100, Og = 15, Su = 10, ge = 16, Tc = new DOMMatrix(), ke = new Float32Array(2), Br = new Float32Array([1 / 0, 1 / 0, -1 / 0, -1 / 0]);
function Bg(d, t) {
if (d._removeMirroring)
throw new Error("Context is already forwarding operations.");
d.__originalSave = d.save, d.__originalRestore = d.restore, d.__originalRotate = d.rotate, d.__originalScale = d.scale, d.__originalTranslate = d.translate, d.__originalTransform = d.transform, d.__originalSetTransform = d.setTransform, d.__originalResetTransform = d.resetTransform, d.__originalClip = d.clip, d.__originalMoveTo = d.moveTo, d.__originalLineTo = d.lineTo, d.__originalBezierCurveTo = d.bezierCurveTo, d.__originalRect = d.rect, d.__originalClosePath = d.closePath, d.__originalBeginPath = d.beginPath, d._removeMirroring = () => {
d.save = d.__originalSave, d.restore = d.__originalRestore, d.rotate = d.__originalRotate, d.scale = d.__originalScale, d.translate = d.__originalTranslate, d.transform = d.__originalTransform, d.setTransform = d.__originalSetTransform, d.resetTransform = d.__originalResetTransform, d.clip = d.__originalClip, d.moveTo = d.__originalMoveTo, d.lineTo = d.__originalLineTo, d.bezierCurveTo = d.__originalBezierCurveTo, d.rect = d.__originalRect, d.closePath = d.__originalClosePath, d.beginPath = d.__originalBeginPath, delete d._removeMirroring;
}, d.save = function() {
t.save(), this.__originalSave();
}, d.restore = function() {
t.restore(), this.__originalRestore();
}, d.translate = function(e, s) {
t.translate(e, s), this.__originalTranslate(e, s);
}, d.scale = function(e, s) {
t.scale(e, s), this.__originalScale(e, s);
}, d.transform = function(e, s, i, r, a, o) {
t.transform(e, s, i, r, a, o), this.__originalTransform(e, s, i, r, a, o);
}, d.setTransform = function(e, s, i, r, a, o) {
t.setTransform(e, s, i, r, a, o), this.__originalSetTransform(e, s, i, r, a, o);
}, d.resetTransform = function() {
t.resetTransform(), this.__originalResetTransform();
}, d.rotate = function(e) {
t.rotate(e), this.__originalRotate(e);
}, d.clip = function(e) {
t.clip(e), this.__originalClip(e);
}, d.moveTo = function(e, s) {
t.moveTo(e, s), this.__originalMoveTo(e, s);
}, d.lineTo = function(e, s) {
t.lineTo(e, s), this.__originalLineTo(e, s);
}, d.bezierCurveTo = function(e, s, i, r, a, o) {
t.bezierCurveTo(e, s, i, r, a, o), this.__originalBezierCurveTo(e, s, i, r, a, o);
}, d.rect = function(e, s, i, r) {
t.rect(e, s, i, r), this.__originalRect(e, s, i, r);
}, d.closePath = function() {
t.closePath(), this.__originalClosePath();
}, d.beginPath = function() {
t.beginPath(), this.__originalBeginPath();
};
}
class Hg {
constructor(t) {
this.canvasFactory = t, this.cache = /* @__PURE__ */ Object.create(null);
}
getCanvas(t, e, s) {
let i;
return this.cache[t] !== void 0 ? (i = this.cache[t], this.canvasFactory.reset(i, e, s)) : (i = this.canvasFactory.create(e, s), this.cache[t] = i), i;
}
delete(t) {
delete this.cache[t];
}
clear() {
for (const t in this.cache) {
const e = this.cache[t];
this.canvasFactory.destroy(e), delete this.cache[t];
}
}
}
function nh(d, t, e, s, i, r, a, o, l, h) {
const [c, u, p, g, A, y] = pt(d);
if (u === 0 && p === 0) {
const S = a * c + A, _ = Math.round(S), E = o * g + y, C = Math.round(E), x = (a + l) * c + A, T = Math.abs(Math.round(x) - _) || 1, P = (o + h) * g + y, M = Math.abs(Math.round(P) - C) || 1;
return d.setTransform(Math.sign(c), 0, 0, Math.sign(g), _, C), d.drawImage(t, e, s, i, r, 0, 0, T, M), d.setTransform(c, u, p, g, A, y), [T, M];
}
if (c === 0 && g === 0) {
const S = o * p + A, _ = Math.round(S), E = a * u + y, C = Math.round(E), x = (o + h) * p + A, T = Math.abs(Math.round(x) - _) || 1, P = (a + l) * u + y, M = Math.abs(Math.round(P) - C) || 1;
return d.setTransform(0, Math.sign(u), Math.sign(p), 0, _, C), d.drawImage(t, e, s, i, r, 0, 0, M, T), d.setTransform(c, u, p, g, A, y), [M, T];
}
d.drawImage(t, e, s, i, r, a, o, l, h);
const w = Math.hypot(c, u), v = Math.hypot(p, g);
return [w * l, v * h];
}
class Eu {
constructor(t, e) {
R(this, "alphaIsShape", !1);
R(this, "fontSize", 0);
R(this, "fontSizeScale", 1);
R(this, "textMatrix", null);
R(this, "textMatrixScale", 1);
R(this, "fontMatrix", Ic);
R(this, "leading", 0);
R(this, "x", 0);
R(this, "y", 0);
R(this, "lineX", 0);
R(this, "lineY", 0);
R(this, "charSpacing", 0);
R(this, "wordSpacing", 0);
R(this, "textHScale", 1);
R(this, "textRenderingMode", qt.FILL);
R(this, "textRise", 0);
R(this, "fillColor", "#000000");
R(this, "strokeColor", "#000000");
R(this, "patternFill", !1);
R(this, "patternStroke", !1);
R(this, "fillAlpha", 1);
R(this, "strokeAlpha", 1);
R(this, "lineWidth", 1);
R(this, "activeSMask", null);
R(this, "transferMaps", "none");
this.clipBox = new Float32Array([0, 0, t, e]), this.minMax = Br.slice();
}
clone() {
const t = Object.create(this);
return t.clipBox = this.clipBox.slice(), t.minMax = this.minMax.slice(), t;
}
getPathBoundingBox(t = jt.FILL, e = null) {
const s = this.minMax.slice();
if (t === jt.STROKE) {
e || rt("Stroke bounding box must include transform."), $.singularValueDecompose2dScale(e, ke);
const i = ke[0] * this.lineWidth / 2, r = ke[1] * this.lineWidth / 2;
s[0] -= i, s[1] -= r, s[2] += i, s[3] += r;
}
return s;
}
updateClipFromPath() {
const t = $.intersect(this.clipBox, this.getPathBoundingBox());
this.startNewPathAndClipBox(t || [0, 0, 0, 0]);
}
isEmptyClip() {
return this.minMax[0] === 1 / 0;
}
startNewPathAndClipBox(t) {
this.clipBox.set(t, 0), this.minMax.set(Br, 0);
}
getClippedPathBoundingBox(t = jt.FILL, e = null) {
return $.intersect(this.clipBox, this.getPathBoundingBox(t, e));
}
}
function Cu(d, t) {
if (t instanceof ImageData) {
d.putImageData(t, 0, 0);
return;
}
const e = t.height, s = t.width, i = e % ge, r = (e - i) / ge, a = i === 0 ? r : r + 1, o = d.createImageData(s, ge);
let l = 0, h;
const c = t.data, u = o.data;
let p, g, A, y;
if (t.kind === lh.GRAYSCALE_1BPP) {
const w = c.byteLength, v = new Uint32Array(u.buffer, 0, u.byteLength >> 2), S = v.length, _ = s + 7 >> 3, E = 4294967295, C = Wt.isLittleEndian ? 4278190080 : 255;
for (p = 0; p < a; p++) {
for (A = p < r ? ge : i, h = 0, g = 0; g < A; g++) {
const x = w - l;
let T = 0;
const P = x > _ ? s : x * 8 - 7, M = P & -8;
let O = 0, D = 0;
for (; T < M; T += 8)
D = c[l++], v[h++] = D & 128 ? E : C, v[h++] = D & 64 ? E : C, v[h++] = D & 32 ? E : C, v[h++] = D & 16 ? E : C, v[h++] = D & 8 ? E : C, v[h++] = D & 4 ? E : C, v[h++] = D & 2 ? E : C, v[h++] = D & 1 ? E : C;
for (; T < P; T++)
O === 0 && (D = c[l++], O = 128), v[h++] = D & O ? E : C, O >>= 1;
}
for (; h < S; )
v[h++] = 0;
d.putImageData(o, 0, p * ge);
}
} else if (t.kind === lh.RGBA_32BPP) {
for (g = 0, y = s * ge * 4, p = 0; p < r; p++)
u.set(c.subarray(l, l + y)), l += y, d.putImageData(o, 0, g), g += ge;
p < a && (y = s * i * 4, u.set(c.subarray(l, l + y)), d.putImageData(o, 0, g));
} else if (t.kind === lh.RGB_24BPP)
for (A = ge, y = s * A, p = 0; p < a; p++) {
for (p >= r && (A = i, y = s * A), h = 0, g = y; g--; )
u[h++] = c[l++], u[h++] = c[l++], u[h++] = c[l++], u[h++] = 255;
d.putImageData(o, 0, p * ge);
}
else
throw new Error(`bad image kind: ${t.kind}`);
}
function xu(d, t) {
if (t.bitmap) {
d.drawImage(t.bitmap, 0, 0);
return;
}
const e = t.height, s = t.width, i = e % ge, r = (e - i) / ge, a = i === 0 ? r : r + 1, o = d.createImageData(s, ge);
let l = 0;
const h = t.data, c = o.data;
for (let u = 0; u < a; u++) {
const p = u < r ? ge : i;
({
srcPos: l
} = Ng({
src: h,
srcPos: l,
dest: c,
width: s,
height: p,
nonBlackColor: 0
})), d.putImageData(o, 0, u * ge);
}
}
function Xa(d, t) {
const e = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font", "filter"];
for (const s of e)
d[s] !== void 0 && (t[s] = d[s]);
d.setLineDash !== void 0 && (t.setLineDash(d.getLineDash()), t.lineDashOffset = d.lineDashOffset);
}
function rh(d) {
d.strokeStyle = d.fillStyle = "#000000", d.fillRule = "nonzero", d.globalAlpha = 1, d.lineWidth = 1, d.lineCap = "butt", d.lineJoin = "miter", d.miterLimit = 10, d.globalCompositeOperation = "source-over", d.font = "10px sans-serif", d.setLineDash !== void 0 && (d.setLineDash([]), d.lineDashOffset = 0);
const {
filter: t
} = d;
t !== "none" && t !== "" && (d.filter = "none");
}
function Tu(d, t) {
if (t)
return !0;
$.singularValueDecompose2dScale(d, ke);
const e = Math.fround(Rs.pixelRatio * on.PDF_TO_CSS_UNITS);
return ke[0] <= e && ke[1] <= e;
}
const $g = ["butt", "round", "square"], Gg = ["miter", "round", "bevel"], zg = {}, Ru = {};
var os, sd, id, nd;
const ou = class ou {
constructor(t, e, s, i, r, {
optionalContentConfig: a,
markedContentStack: o = null
}, l, h) {
m(this, os);
this.ctx = t, this.current = new Eu(this.ctx.canvas.width, this.ctx.canvas.height), this.stateStack = [], this.pendingClip = null, this.pendingEOFill = !1, this.res = null, this.xobjs = null, this.commonObjs = e, this.objs = s, this.canvasFactory = i, this.filterFactory = r, this.groupStack = [], this.baseTransform = null, this.baseTransformStack = [], this.groupLevel = 0, this.smaskStack = [], this.smaskCounter = 0, this.tempSMask = null, this.suspendedCtx = null, this.contentVisible = !0, this.markedContentStack = o || [], this.optionalContentConfig = a, this.cachedCanvases = new Hg(this.canvasFactory), this.cachedPatterns = /* @__PURE__ */ new Map(), this.annotationCanvasMap = l, this.viewportScale = 1, this.outputScaleX = 1, this.outputScaleY = 1, this.pageColors = h, this._cachedScaleForStroking = [-1, 0], this._cachedGetSinglePixelWidth = null, this._cachedBitmapsMap = /* @__PURE__ */ new Map();
}
getObject(t, e = null) {
return typeof t == "string" ? t.startsWith("g_") ? this.commonObjs.get(t) : this.objs.get(t) : e;
}
beginDrawing({
transform: t,
viewport: e,
transparency: s = !1,
background: i = null
}) {
const r = this.ctx.canvas.width, a = this.ctx.canvas.height, o = this.ctx.fillStyle;
if (this.ctx.fillStyle = i || "#ffffff", this.ctx.fillRect(0, 0, r, a), this.ctx.fillStyle = o, s) {
const l = this.cachedCanvases.getCanvas("transparent", r, a);
this.compositeCtx = this.ctx, this.transparentCanvas = l.canvas, this.ctx = l.context, this.ctx.save(), this.ctx.transform(...pt(this.compositeCtx));
}
this.ctx.save(), rh(this.ctx), t && (this.ctx.transform(...t), this.outputScaleX = t[0], this.outputScaleY = t[0]), this.ctx.transform(...e.transform), this.viewportScale = e.scale, this.baseTransform = pt(this.ctx);
}
executeOperatorList(t, e, s, i) {
const r = t.argsArray, a = t.fnArray;
let o = e || 0;
const l = r.length;
if (l === o)
return o;
const h = l - o > Su && typeof s == "function", c = h ? Date.now() + Og : 0;
let u = 0;
const p = this.commonObjs, g = this.objs;
let A;
for (; ; ) {
if (i !== void 0 && o === i.nextBreakPoint)
return i.breakIt(o, s), o;
if (A = a[o], A !== Hh.dependency)
this[A].apply(this, r[o]);
else
for (const y of r[o]) {
const w = y.startsWith("g_") ? p : g;
if (!w.has(y))
return w.get(y, s), o;
}
if (o++, o === l)
return o;
if (h && ++u > Su) {
if (Date.now() > c)
return s(), o;
u = 0;
}
}
}
endDrawing() {
b(this, os, sd).call(this), this.cachedCanvases.clear(), this.cachedPatterns.clear();
for (const t of this._cachedBitmapsMap.values()) {
for (const e of t.values())
typeof HTMLCanvasElement < "u" && e instanceof HTMLCanvasElement && (e.width = e.height = 0);
t.clear();
}
this._cachedBitmapsMap.clear(), b(this, os, id).call(this);
}
_scaleImage(t, e) {
const s = t.width ?? t.displayWidth, i = t.height ?? t.displayHeight;
let r = Math.max(Math.hypot(e[0], e[1]), 1), a = Math.max(Math.hypot(e[2], e[3]), 1), o = s, l = i, h = "prescale1", c, u;
for (; r > 2 && o > 1 || a > 2 && l > 1; ) {
let p = o, g = l;
r > 2 && o > 1 && (p = o >= 16384 ? Math.floor(o / 2) - 1 || 1 : Math.ceil(o / 2), r /= o / p), a > 2 && l > 1 && (g = l >= 16384 ? Math.floor(l / 2) - 1 || 1 : Math.ceil(l) / 2, a /= l / g), c = this.cachedCanvases.getCanvas(h, p, g), u = c.context, u.clearRect(0, 0, p, g), u.drawImage(t, 0, 0, o, l, 0, 0, p, g), t = c.canvas, o = p, l = g, h = h === "prescale1" ? "prescale2" : "prescale1";
}
return {
img: t,
paintWidth: o,
paintHeight: l
};
}
_createMaskCanvas(t) {
const e = this.ctx, {
width: s,
height: i
} = t, r = this.current.fillColor, a = this.current.patternFill, o = pt(e);
let l, h, c, u;
if ((t.bitmap || t.data) && t.count > 1) {
const M = t.bitmap || t.data.buffer;
h = JSON.stringify(a ? o : [o.slice(0, 4), r]), l = this._cachedBitmapsMap.get(M), l || (l = /* @__PURE__ */ new Map(), this._cachedBitmapsMap.set(M, l));
const O = l.get(h);
if (O && !a) {
const D = Math.round(Math.min(o[0], o[2]) + o[4]), tt = Math.round(Math.min(o[1], o[3]) + o[5]);
return {
canvas: O,
offsetX: D,
offsetY: tt
};
}
c = O;
}
c || (u = this.cachedCanvases.getCanvas("maskCanvas", s, i), xu(u.context, t));
let p = $.transform(o, [1 / s, 0, 0, -1 / i, 0, 0]);
p = $.transform(p, [1, 0, 0, 1, 0, -i]);
const g = Br.slice();
$.axialAlignedBoundingBox([0, 0, s, i], p, g);
const [A, y, w, v] = g, S = Math.round(w - A) || 1, _ = Math.round(v - y) || 1, E = this.cachedCanvases.getCanvas("fillCanvas", S, _), C = E.context, x = A, T = y;
C.translate(-x, -T), C.transform(...p), c || (c = this._scaleImage(u.canvas, ls(C)), c = c.img, l && a && l.set(h, c)), C.imageSmoothingEnabled = Tu(pt(C), t.interpolate), nh(C, c, 0, 0, c.width, c.height, 0, 0, s, i), C.globalCompositeOperation = "source-in";
const P = $.transform(ls(C), [1, 0, 0, 1, -x, -T]);
return C.fillStyle = a ? r.getPattern(e, this, P, jt.FILL) : r, C.fillRect(0, 0, s, i), l && !a && (this.cachedCanvases.delete("fillCanvas"), l.set(h, E.canvas)), {
canvas: E.canvas,
offsetX: Math.round(x),
offsetY: Math.round(T)
};
}
setLineWidth(t) {
t !== this.current.lineWidth && (this._cachedScaleForStroking[0] = -1), this.current.lineWidth = t, this.ctx.lineWidth = t;
}
setLineCap(t) {
this.ctx.lineCap = $g[t];
}
setLineJoin(t) {
this.ctx.lineJoin = Gg[t];
}
setMiterLimit(t) {
this.ctx.miterLimit = t;
}
setDash(t, e) {
const s = this.ctx;
s.setLineDash !== void 0 && (s.setLineDash(t), s.lineDashOffset = e);
}
setRenderingIntent(t) {
}
setFlatness(t) {
}
setGState(t) {
for (const [e, s] of t)
switch (e) {
case "LW":
this.setLineWidth(s);
break;
case "LC":
this.setLineCap(s);
break;
case "LJ":
this.setLineJoin(s);
break;
case "ML":
this.setMiterLimit(s);
break;
case "D":
this.setDash(s[0], s[1]);
break;
case "RI":
this.setRenderingIntent(s);
break;
case "FL":
this.setFlatness(s);
break;
case "Font":
this.setFont(s[0], s[1]);
break;
case "CA":
this.current.strokeAlpha = s;
break;
case "ca":
this.ctx.globalAlpha = this.current.fillAlpha = s;
break;
case "BM":
this.ctx.globalCompositeOperation = s;
break;
case "SMask":
this.current.activeSMask = s ? this.tempSMask : null, this.tempSMask = null, this.checkSMaskState();
break;
case "TR":
this.ctx.filter = this.current.transferMaps = this.filterFactory.addFilter(s);
break;
}
}
get inSMaskMode() {
return !!this.suspendedCtx;
}
checkSMaskState() {
const t = this.inSMaskMode;
this.current.activeSMask && !t ? this.beginSMaskMode() : !this.current.activeSMask && t && this.endSMaskMode();
}
beginSMaskMode() {
if (this.inSMaskMode)
throw new Error("beginSMaskMode called while already in smask mode");
const t = this.ctx.canvas.width, e = this.ctx.canvas.height, s = "smaskGroupAt" + this.groupLevel, i = this.cachedCanvases.getCanvas(s, t, e);
this.suspendedCtx = this.ctx;
const r = this.ctx = i.context;
r.setTransform(this.suspendedCtx.getTransform()), Xa(this.suspendedCtx, r), Bg(r, this.suspendedCtx), this.setGState([["BM", "source-over"]]);
}
endSMaskMode() {
if (!this.inSMaskMode)
throw new Error("endSMaskMode called while not in smask mode");
this.ctx._removeMirroring(), Xa(this.ctx, this.suspendedCtx), this.ctx = this.suspendedCtx, this.suspendedCtx = null;
}
compose(t) {
if (!this.current.activeSMask)
return;
t ? (t[0] = Math.floor(t[0]), t[1] = Math.floor(t[1]), t[2] = Math.ceil(t[2]), t[3] = Math.ceil(t[3])) : t = [0, 0, this.ctx.canvas.width, this.ctx.canvas.height];
const e = this.current.activeSMask, s = this.suspendedCtx;
this.composeSMask(s, e, this.ctx, t), this.ctx.save(), this.ctx.setTransform(1, 0, 0, 1, 0, 0), this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height), this.ctx.restore();
}
composeSMask(t, e, s, i) {
const r = i[0], a = i[1], o = i[2] - r, l = i[3] - a;
o === 0 || l === 0 || (this.genericComposeSMask(e.context, s, o, l, e.subtype, e.backdrop, e.transferMap, r, a, e.offsetX, e.offsetY), t.save(), t.globalAlpha = 1, t.globalCompositeOperation = "source-over", t.setTransform(1, 0, 0, 1, 0, 0), t.drawImage(s.canvas, 0, 0), t.restore());
}
genericComposeSMask(t, e, s, i, r, a, o, l, h, c, u) {
let p = t.canvas, g = l - c, A = h - u;
if (a)
if (g < 0 || A < 0 || g + s > p.width || A + i > p.height) {
const w = this.cachedCanvases.getCanvas("maskExtension", s, i), v = w.context;
v.drawImage(p, -g, -A), v.globalCompositeOperation = "destination-atop", v.fillStyle = a, v.fillRect(0, 0, s, i), v.globalCompositeOperation = "source-over", p = w.canvas, g = A = 0;
} else {
t.save(), t.globalAlpha = 1, t.setTransform(1, 0, 0, 1, 0, 0);
const w = new Path2D();
w.rect(g, A, s, i), t.clip(w), t.globalCompositeOperation = "destination-atop", t.fillStyle = a, t.fillRect(g, A, s, i), t.restore();
}
e.save(), e.globalAlpha = 1, e.setTransform(1, 0, 0, 1, 0, 0), r === "Alpha" && o ? e.filter = this.filterFactory.addAlphaFilter(o) : r === "Luminosity" && (e.filter = this.filterFactory.addLuminosityFilter(o));
const y = new Path2D();
y.rect(l, h, s, i), e.clip(y), e.globalCompositeOperation = "destination-in", e.drawImage(p, g, A, s, i, l, h, s, i), e.restore();
}
save() {
this.inSMaskMode && Xa(this.ctx, this.suspendedCtx), this.ctx.save();
const t = this.current;
this.stateStack.push(t), this.current = t.clone();
}
restore() {
if (this.stateStack.length === 0) {
this.inSMaskMode && this.endSMaskMode();
return;
}
this.current = this.stateStack.pop(), this.ctx.restore(), this.inSMaskMode && Xa(this.suspendedCtx, this.ctx), this.checkSMaskState(), this.pendingClip = null, this._cachedScaleForStroking[0] = -1, this._cachedGetSinglePixelWidth = null;
}
transform(t, e, s, i, r, a) {
this.ctx.transform(t, e, s, i, r, a), this._cachedScaleForStroking[0] = -1, this._cachedGetSinglePixelWidth = null;
}
constructPath(t, e, s) {
let [i] = e;
if (!s) {
i || (i = e[0] = new Path2D()), this[t](i);
return;
}
if (!(i instanceof Path2D)) {
const r = e[0] = new Path2D();
for (let a = 0, o = i.length; a < o; )
switch (i[a++]) {
case eh.moveTo:
r.moveTo(i[a++], i[a++]);
break;
case eh.lineTo:
r.lineTo(i[a++], i[a++]);
break;
case eh.curveTo:
r.bezierCurveTo(i[a++], i[a++], i[a++], i[a++], i[a++], i[a++]);
break;
case eh.closePath:
r.closePath();
break;
default:
U(`Unrecognized drawing path operator: ${i[a - 1]}`);
break;
}
i = r;
}
$.axialAlignedBoundingBox(s, pt(this.ctx), this.current.minMax), this[t](i);
}
closePath() {
this.ctx.closePath();
}
stroke(t, e = !0) {
const s = this.ctx, i = this.current.strokeColor;
if (s.globalAlpha = this.current.strokeAlpha, this.contentVisible)
if (typeof i == "object" && (i != null && i.getPattern)) {
const r = i.isModifyingCurrentTransform() ? s.getTransform() : null;
if (s.save(), s.strokeStyle = i.getPattern(s, this, ls(s), jt.STROKE), r) {
const a = new Path2D();
a.addPath(t, s.getTransform().invertSelf().multiplySelf(r)), t = a;
}
this.rescaleAndStroke(t, !1), s.restore();
} else
this.rescaleAndStroke(t, !0);
e && this.consumePath(t, this.current.getClippedPathBoundingBox(jt.STROKE, pt(this.ctx))), s.globalAlpha = this.current.fillAlpha;
}
closeStroke(t) {
this.stroke(t);
}
fill(t, e = !0) {
const s = this.ctx, i = this.current.fillColor, r = this.current.patternFill;
let a = !1;
if (r) {
const l = i.isModifyingCurrentTransform() ? s.getTransform() : null;
if (s.save(), s.fillStyle = i.getPattern(s, this, ls(s), jt.FILL), l) {
const h = new Path2D();
h.addPath(t, s.getTransform().invertSelf().multiplySelf(l)), t = h;
}
a = !0;
}
const o = this.current.getClippedPathBoundingBox();
this.contentVisible && o !== null && (this.pendingEOFill ? (s.fill(t, "evenodd"), this.pendingEOFill = !1) : s.fill(t)), a && s.restore(), e && this.consumePath(t, o);
}
eoFill(t) {
this.pendingEOFill = !0, this.fill(t);
}
fillStroke(t) {
this.fill(t, !1), this.stroke(t, !1), this.consumePath(t);
}
eoFillStroke(t) {
this.pendingEOFill = !0, this.fillStroke(t);
}
closeFillStroke(t) {
this.fillStroke(t);
}
closeEOFillStroke(t) {
this.pendingEOFill = !0, this.fillStroke(t);
}
endPath(t) {
this.consumePath(t);
}
rawFillPath(t) {
this.ctx.fill(t);
}
clip() {
this.pendingClip = zg;
}
eoClip() {
this.pendingClip = Ru;
}
beginText() {
this.current.textMatrix = null, this.current.textMatrixScale = 1, this.current.x = this.current.lineX = 0, this.current.y = this.current.lineY = 0;
}
endText() {
const t = this.pendingTextPaths, e = this.ctx;
if (t === void 0)
return;
const s = new Path2D(), i = e.getTransform().invertSelf();
for (const {
transform: r,
x: a,
y: o,
fontSize: l,
path: h
} of t)
s.addPath(h, new DOMMatrix(r).preMultiplySelf(i).translate(a, o).scale(l, -l));
e.clip(s), delete this.pendingTextPaths;
}
setCharSpacing(t) {
this.current.charSpacing = t;
}
setWordSpacing(t) {
this.current.wordSpacing = t;
}
setHScale(t) {
this.current.textHScale = t / 100;
}
setLeading(t) {
this.current.leading = -t;
}
setFont(t, e) {
var c;
const s = this.commonObjs.get(t), i = this.current;
if (!s)
throw new Error(`Can't find font for ${t}`);
if (i.fontMatrix = s.fontMatrix || Ic, (i.fontMatrix[0] === 0 || i.fontMatrix[3] === 0) && U("Invalid font matrix for font " + t), e < 0 ? (e = -e, i.fontDirection = -1) : i.fontDirection = 1, this.current.font = s, this.current.fontSize = e, s.isType3Font)
return;
const r = s.loadedName || "sans-serif", a = ((c = s.systemFontInfo) == null ? void 0 : c.css) || `"${r}", ${s.fallbackName}`;
let o = "normal";
s.black ? o = "900" : s.bold && (o = "bold");
const l = s.italic ? "italic" : "normal";
let h = e;
e < vu ? h = vu : e > _u && (h = _u), this.current.fontSizeScale = e / h, this.ctx.font = `${l} ${o} ${h}px ${a}`;
}
setTextRenderingMode(t) {
this.current.textRenderingMode = t;
}
setTextRise(t) {
this.current.textRise = t;
}
moveText(t, e) {
this.current.x = this.current.lineX += t, this.current.y = this.current.lineY += e;
}
setLeadingMoveText(t, e) {
this.setLeading(-e), this.moveText(t, e);
}
setTextMatrix(t) {
const {
current: e
} = this;
e.textMatrix = t, e.textMatrixScale = Math.hypot(t[0], t[1]), e.x = e.lineX = 0, e.y = e.lineY = 0;
}
nextLine() {
this.moveText(0, this.current.leading);
}
paintChar(t, e, s, i, r) {
const a = this.ctx, o = this.current, l = o.font, h = o.textRenderingMode, c = o.fontSize / o.fontSizeScale, u = h & qt.FILL_STROKE_MASK, p = !!(h & qt.ADD_TO_PATH_FLAG), g = o.patternFill && !l.missingFile, A = o.patternStroke && !l.missingFile;
let y;
if ((l.disableFontFace || p || g || A) && (y = l.getPathGenerator(this.commonObjs, t)), l.disableFontFace || g || A) {
a.save(), a.translate(e, s), a.scale(c, -c);
let w;
if ((u === qt.FILL || u === qt.FILL_STROKE) && (i ? (w = a.getTransform(), a.setTransform(...i), a.fill(b(this, os, nd).call(this, y, w, i))) : a.fill(y)), u === qt.STROKE || u === qt.FILL_STROKE)
if (r) {
w || (w = a.getTransform()), a.setTransform(...r);
const {
a: v,
b: S,
c: _,
d: E
} = w, C = $.inverseTransform(r), x = $.transform([v, S, _, E, 0, 0], C);
$.singularValueDecompose2dScale(x, ke), a.lineWidth *= Math.max(ke[0], ke[1]) / c, a.stroke(b(this, os, nd).call(this, y, w, r));
} else
a.lineWidth /= c, a.stroke(y);
a.restore();
} else
(u === qt.FILL || u === qt.FILL_STROKE) && a.fillText(t, e, s), (u === qt.STROKE || u === qt.FILL_STROKE) && a.strokeText(t, e, s);
p && (this.pendingTextPaths || (this.pendingTextPaths = [])).push({
transform: pt(a),
x: e,
y: s,
fontSize: c,
path: y
});
}
get isFontSubpixelAAEnabled() {
const {
context: t
} = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
t.scale(1.5, 1), t.fillText("I", 0, 10);
const e = t.getImageData(0, 0, 10, 10).data;
let s = !1;
for (let i = 3; i < e.length; i += 4)
if (e[i] > 0 && e[i] < 255) {
s = !0;
break;
}
return X(this, "isFontSubpixelAAEnabled", s);
}
showText(t) {
const e = this.current, s = e.font;
if (s.isType3Font)
return this.showType3Text(t);
const i = e.fontSize;
if (i === 0)
return;
const r = this.ctx, a = e.fontSizeScale, o = e.charSpacing, l = e.wordSpacing, h = e.fontDirection, c = e.textHScale * h, u = t.length, p = s.vertical, g = p ? 1 : -1, A = s.defaultVMetrics, y = i * e.fontMatrix[0], w = e.textRenderingMode === qt.FILL && !s.disableFontFace && !e.patternFill;
r.save(), e.textMatrix && r.transform(...e.textMatrix), r.translate(e.x, e.y + e.textRise), h > 0 ? r.scale(c, -1) : r.scale(c, 1);
let v, S;
if (e.patternFill) {
r.save();
const T = e.fillColor.getPattern(r, this, ls(r), jt.FILL);
v = pt(r), r.restore(), r.fillStyle = T;
}
if (e.patternStroke) {
r.save();
const T = e.strokeColor.getPattern(r, this, ls(r), jt.STROKE);
S = pt(r), r.restore(), r.strokeStyle = T;
}
let _ = e.lineWidth;
const E = e.textMatrixScale;
if (E === 0 || _ === 0) {
const T = e.textRenderingMode & qt.FILL_STROKE_MASK;
(T === qt.STROKE || T === qt.FILL_STROKE) && (_ = this.getSinglePixelWidth());
} else
_ /= E;
if (a !== 1 && (r.scale(a, a), _ /= a), r.lineWidth = _, s.isInvalidPDFjsFont) {
const T = [];
let P = 0;
for (const M of t)
T.push(M.unicode), P += M.width;
r.fillText(T.join(""), 0, 0), e.x += P * y * c, r.restore(), this.compose();
return;
}
let C = 0, x;
for (x = 0; x < u; ++x) {
const T = t[x];
if (typeof T == "number") {
C += g * T * i / 1e3;
continue;
}
let P = !1;
const M = (T.isSpace ? l : 0) + o, O = T.fontChar, D = T.accent;
let tt, st, q = T.width;
if (p) {
const N = T.vmetric || A, H = -(T.vmetric ? N[1] : q * 0.5) * y, Fe = N[2] * y;
q = N ? -N[0] : q, tt = H / a, st = (C + Fe) / a;
} else
tt = C / a, st = 0;
if (s.remeasure && q > 0) {
const N = r.measureText(O).width * 1e3 / i * a;
if (q < N && this.isFontSubpixelAAEnabled) {
const H = q / N;
P = !0, r.save(), r.scale(H, 1), tt /= H;
} else q !== N && (tt += (q - N) / 2e3 * i / a);
}
if (this.contentVisible && (T.isInFont || s.missingFile)) {
if (w && !D)
r.fillText(O, tt, st);
else if (this.paintChar(O, tt, st, v, S), D) {
const N = tt + i * D.offset.x / a, H = st - i * D.offset.y / a;
this.paintChar(D.fontChar, N, H, v, S);
}
}
const Jt = p ? q * y - M * h : q * y + M * h;
C += Jt, P && r.restore();
}
p ? e.y -= C : e.x += C * c, r.restore(), this.compose();
}
showType3Text(t) {
const e = this.ctx, s = this.current, i = s.font, r = s.fontSize, a = s.fontDirection, o = i.vertical ? 1 : -1, l = s.charSpacing, h = s.wordSpacing, c = s.textHScale * a, u = s.fontMatrix || Ic, p = t.length, g = s.textRenderingMode === qt.INVISIBLE;
let A, y, w, v;
if (!(g || r === 0)) {
for (this._cachedScaleForStroking[0] = -1, this._cachedGetSinglePixelWidth = null, e.save(), s.textMatrix && e.transform(...s.textMatrix), e.translate(s.x, s.y + s.textRise), e.scale(c, a), A = 0; A < p; ++A) {
if (y = t[A], typeof y == "number") {
v = o * y * r / 1e3, this.ctx.translate(v, 0), s.x += v * c;
continue;
}
const S = (y.isSpace ? h : 0) + l, _ = i.charProcOperatorList[y.operatorListId];
_ ? this.contentVisible && (this.save(), e.scale(r, r), e.transform(...u), this.executeOperatorList(_), this.restore()) : U(`Type3 character "${y.operatorListId}" is not available.`);
const E = [y.width, 0];
$.applyTransform(E, u), w = E[0] * r + S, e.translate(w, 0), s.x += w * c;
}
e.restore();
}
}
setCharWidth(t, e) {
}
setCharWidthAndBounds(t, e, s, i, r, a) {
const o = new Path2D();
o.rect(s, i, r - s, a - i), this.ctx.clip(o), this.endPath();
}
getColorN_Pattern(t) {
let e;
if (t[0] === "TilingPattern") {
const s = this.baseTransform || pt(this.ctx), i = {
createCanvasGraphics: (r) => new ou(r, this.commonObjs, this.objs, this.canvasFactory, this.filterFactory, {
optionalContentConfig: this.optionalContentConfig,
markedContentStack: this.markedContentStack
})
};
e = new ed(t, this.ctx, i, s);
} else
e = this._getPattern(t[1], t[2]);
return e;
}
setStrokeColorN() {
this.current.strokeColor = this.getColorN_Pattern(arguments), this.current.patternStroke = !0;
}
setFillColorN() {
this.current.fillColor = this.getColorN_Pattern(arguments), this.current.patternFill = !0;
}
setStrokeRGBColor(t) {
this.ctx.strokeStyle = this.current.strokeColor = t, this.current.patternStroke = !1;
}
setStrokeTransparent() {
this.ctx.strokeStyle = this.current.strokeColor = "transparent", this.current.patternStroke = !1;
}
setFillRGBColor(t) {
this.ctx.fillStyle = this.current.fillColor = t, this.current.patternFill = !1;
}
setFillTransparent() {
this.ctx.fillStyle = this.current.fillColor = "transparent", this.current.patternFill = !1;
}
_getPattern(t, e = null) {
let s;
return this.cachedPatterns.has(t) ? s = this.cachedPatterns.get(t) : (s = Fg(this.getObject(t)), this.cachedPatterns.set(t, s)), e && (s.matrix = e), s;
}
shadingFill(t) {
if (!this.contentVisible)
return;
const e = this.ctx;
this.save();
const s = this._getPattern(t);
e.fillStyle = s.getPattern(e, this, ls(e), jt.SHADING);
const i = ls(e);
if (i) {
const {
width: r,
height: a
} = e.canvas, o = Br.slice();
$.axialAlignedBoundingBox([0, 0, r, a], i, o);
const [l, h, c, u] = o;
this.ctx.fillRect(l, h, c - l, u - h);
} else
this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
this.compose(this.current.getClippedPathBoundingBox()), this.restore();
}
beginInlineImage() {
rt("Should not call beginInlineImage");
}
beginImageData() {
rt("Should not call beginImageData");
}
paintFormXObjectBegin(t, e) {
if (this.contentVisible && (this.save(), this.baseTransformStack.push(this.baseTransform), t && this.transform(...t), this.baseTransform = pt(this.ctx), e)) {
$.axialAlignedBoundingBox(e, this.baseTransform, this.current.minMax);
const [s, i, r, a] = e, o = new Path2D();
o.rect(s, i, r - s, a - i), this.ctx.clip(o), this.endPath();
}
}
paintFormXObjectEnd() {
this.contentVisible && (this.restore(), this.baseTransform = this.baseTransformStack.pop());
}
beginGroup(t) {
if (!this.contentVisible)
return;
this.save(), this.inSMaskMode && (this.endSMaskMode(), this.current.activeSMask = null);
const e = this.ctx;
t.isolated || gc("TODO: Support non-isolated groups."), t.knockout && U("Knockout groups not supported.");
const s = pt(e);
if (t.matrix && e.transform(...t.matrix), !t.bbox)
throw new Error("Bounding box is required.");
let i = Br.slice();
$.axialAlignedBoundingBox(t.bbox, pt(e), i);
const r = [0, 0, e.canvas.width, e.canvas.height];
i = $.intersect(i, r) || [0, 0, 0, 0];
const a = Math.floor(i[0]), o = Math.floor(i[1]), l = Math.max(Math.ceil(i[2]) - a, 1), h = Math.max(Math.ceil(i[3]) - o, 1);
this.current.startNewPathAndClipBox([0, 0, l, h]);
let c = "groupAt" + this.groupLevel;
t.smask && (c += "_smask_" + this.smaskCounter++ % 2);
const u = this.cachedCanvases.getCanvas(c, l, h), p = u.context;
p.translate(-a, -o), p.transform(...s);
let g = new Path2D();
const [A, y, w, v] = t.bbox;
if (g.rect(A, y, w - A, v - y), t.matrix) {
const S = new Path2D();
S.addPath(g, new DOMMatrix(t.matrix)), g = S;
}
p.clip(g), t.smask ? this.smaskStack.push({
canvas: u.canvas,
context: p,
offsetX: a,
offsetY: o,
subtype: t.smask.subtype,
backdrop: t.smask.backdrop,
transferMap: t.smask.transferMap || null,
startTransformInverse: null
}) : (e.setTransform(1, 0, 0, 1, 0, 0), e.translate(a, o), e.save()), Xa(e, p), this.ctx = p, this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]), this.groupStack.push(e), this.groupLevel++;
}
endGroup(t) {
if (!this.contentVisible)
return;
this.groupLevel--;
const e = this.ctx, s = this.groupStack.pop();
if (this.ctx = s, this.ctx.imageSmoothingEnabled = !1, t.smask)
this.tempSMask = this.smaskStack.pop(), this.restore();
else {
this.ctx.restore();
const i = pt(this.ctx);
this.restore(), this.ctx.save(), this.ctx.setTransform(...i);
const r = Br.slice();
$.axialAlignedBoundingBox([0, 0, e.canvas.width, e.canvas.height], i, r), this.ctx.drawImage(e.canvas, 0, 0), this.ctx.restore(), this.compose(r);
}
}
beginAnnotation(t, e, s, i, r) {
if (b(this, os, sd).call(this), rh(this.ctx), this.ctx.save(), this.save(), this.baseTransform && this.ctx.setTransform(...this.baseTransform), e) {
const a = e[2] - e[0], o = e[3] - e[1];
if (r && this.annotationCanvasMap) {
s = s.slice(), s[4] -= e[0], s[5] -= e[1], e = e.slice(), e[0] = e[1] = 0, e[2] = a, e[3] = o, $.singularValueDecompose2dScale(pt(this.ctx), ke);
const {
viewportScale: l
} = this, h = Math.ceil(a * this.outputScaleX * l), c = Math.ceil(o * this.outputScaleY * l);
this.annotationCanvas = this.canvasFactory.create(h, c);
const {
canvas: u,
context: p
} = this.annotationCanvas;
this.annotationCanvasMap.set(t, u), this.annotationCanvas.savedCtx = this.ctx, this.ctx = p, this.ctx.save(), this.ctx.setTransform(ke[0], 0, 0, -ke[1], 0, o * ke[1]), rh(this.ctx);
} else {
rh(this.ctx), this.endPath();
const l = new Path2D();
l.rect(e[0], e[1], a, o), this.ctx.clip(l);
}
}
this.current = new Eu(this.ctx.canvas.width, this.ctx.canvas.height), this.transform(...s), this.transform(...i);
}
endAnnotation() {
this.annotationCanvas && (this.ctx.restore(), b(this, os, id).call(this), this.ctx = this.annotationCanvas.savedCtx, delete this.annotationCanvas.savedCtx, delete this.annotationCanvas);
}
paintImageMaskXObject(t) {
if (!this.contentVisible)
return;
const e = t.count;
t = this.getObject(t.data, t), t.count = e;
const s = this.ctx, i = this._createMaskCanvas(t), r = i.canvas;
s.save(), s.setTransform(1, 0, 0, 1, 0, 0), s.drawImage(r, i.offsetX, i.offsetY), s.restore(), this.compose();
}
paintImageMaskXObjectRepeat(t, e, s = 0, i = 0, r, a) {
if (!this.contentVisible)
return;
t = this.getObject(t.data, t);
const o = this.ctx;
o.save();
const l = pt(o);
o.transform(e, s, i, r, 0, 0);
const h = this._createMaskCanvas(t);
o.setTransform(1, 0, 0, 1, h.offsetX - l[4], h.offsetY - l[5]);
for (let c = 0, u = a.length; c < u; c += 2) {
const p = $.transform(l, [e, s, i, r, a[c], a[c + 1]]);
o.drawImage(h.canvas, p[4], p[5]);
}
o.restore(), this.compose();
}
paintImageMaskXObjectGroup(t) {
if (!this.contentVisible)
return;
const e = this.ctx, s = this.current.fillColor, i = this.current.patternFill;
for (const r of t) {
const {
data: a,
width: o,
height: l,
transform: h
} = r, c = this.cachedCanvases.getCanvas("maskCanvas", o, l), u = c.context;
u.save();
const p = this.getObject(a, r);
xu(u, p), u.globalCompositeOperation = "source-in", u.fillStyle = i ? s.getPattern(u, this, ls(e), jt.FILL) : s, u.fillRect(0, 0, o, l), u.restore(), e.save(), e.transform(...h), e.scale(1, -1), nh(e, c.canvas, 0, 0, o, l, 0, -1, 1, 1), e.restore();
}
this.compose();
}
paintImageXObject(t) {
if (!this.contentVisible)
return;
const e = this.getObject(t);
if (!e) {
U("Dependent image isn't ready yet");
return;
}
this.paintInlineImageXObject(e);
}
paintImageXObjectRepeat(t, e, s, i) {
if (!this.contentVisible)
return;
const r = this.getObject(t);
if (!r) {
U("Dependent image isn't ready yet");
return;
}
const a = r.width, o = r.height, l = [];
for (let h = 0, c = i.length; h < c; h += 2)
l.push({
transform: [e, 0, 0, s, i[h], i[h + 1]],
x: 0,
y: 0,
w: a,
h: o
});
this.paintInlineImageXObjectGroup(r, l);
}
applyTransferMapsToCanvas(t) {
return this.current.transferMaps !== "none" && (t.filter = this.current.transferMaps, t.drawImage(t.canvas, 0, 0), t.filter = "none"), t.canvas;
}
applyTransferMapsToBitmap(t) {
if (this.current.transferMaps === "none")
return t.bitmap;
const {
bitmap: e,
width: s,
height: i
} = t, r = this.cachedCanvases.getCanvas("inlineImage", s, i), a = r.context;
return a.filter = this.current.transferMaps, a.drawImage(e, 0, 0), a.filter = "none", r.canvas;
}
paintInlineImageXObject(t) {
if (!this.contentVisible)
return;
const e = t.width, s = t.height, i = this.ctx;
this.save();
const {
filter: r
} = i;
r !== "none" && r !== "" && (i.filter = "none"), i.scale(1 / e, -1 / s);
let a;
if (t.bitmap)
a = this.applyTransferMapsToBitmap(t);
else if (typeof HTMLElement == "function" && t instanceof HTMLElement || !t.data)
a = t;
else {
const h = this.cachedCanvases.getCanvas("inlineImage", e, s).context;
Cu(h, t), a = this.applyTransferMapsToCanvas(h);
}
const o = this._scaleImage(a, ls(i));
i.imageSmoothingEnabled = Tu(pt(i), t.interpolate), nh(i, o.img, 0, 0, o.paintWidth, o.paintHeight, 0, -s, e, s), this.compose(), this.restore();
}
paintInlineImageXObjectGroup(t, e) {
if (!this.contentVisible)
return;
const s = this.ctx;
let i;
if (t.bitmap)
i = t.bitmap;
else {
const r = t.width, a = t.height, l = this.cachedCanvases.getCanvas("inlineImage", r, a).context;
Cu(l, t), i = this.applyTransferMapsToCanvas(l);
}
for (const r of e)
s.save(), s.transform(...r.transform), s.scale(1, -1), nh(s, i, r.x, r.y, r.w, r.h, 0, -1, 1, 1), s.restore();
this.compose();
}
paintSolidColorImageMask() {
this.contentVisible && (this.ctx.fillRect(0, 0, 1, 1), this.compose());
}
markPoint(t) {
}
markPointProps(t, e) {
}
beginMarkedContent(t) {
this.markedContentStack.push({
visible: !0
});
}
beginMarkedContentProps(t, e) {
t === "OC" ? this.markedContentStack.push({
visible: this.optionalContentConfig.isVisible(e)
}) : this.markedContentStack.push({
visible: !0
}), this.contentVisible = this.isContentVisible();
}
endMarkedContent() {
this.markedContentStack.pop(), this.contentVisible = this.isContentVisible();
}
beginCompat() {
}
endCompat() {
}
consumePath(t, e) {
const s = this.current.isEmptyClip();
this.pendingClip && this.current.updateClipFromPath(), this.pendingClip || this.compose(e);
const i = this.ctx;
this.pendingClip && (s || (this.pendingClip === Ru ? i.clip(t, "evenodd") : i.clip(t)), this.pendingClip = null), this.current.startNewPathAndClipBox(this.current.clipBox);
}
getSinglePixelWidth() {
if (!this._cachedGetSinglePixelWidth) {
const t = pt(this.ctx);
if (t[1] === 0 && t[2] === 0)
this._cachedGetSinglePixelWidth = 1 / Math.min(Math.abs(t[0]), Math.abs(t[3]));
else {
const e = Math.abs(t[0] * t[3] - t[2] * t[1]), s = Math.hypot(t[0], t[2]), i = Math.hypot(t[1], t[3]);
this._cachedGetSinglePixelWidth = Math.max(s, i) / e;
}
}
return this._cachedGetSinglePixelWidth;
}
getScaleForStroking() {
if (this._cachedScaleForStroking[0] === -1) {
const {
lineWidth: t
} = this.current, {
a: e,
b: s,
c: i,
d: r
} = this.ctx.getTransform();
let a, o;
if (s === 0 && i === 0) {
const l = Math.abs(e), h = Math.abs(r);
if (l === h)
if (t === 0)
a = o = 1 / l;
else {
const c = l * t;
a = o = c < 1 ? 1 / c : 1;
}
else if (t === 0)
a = 1 / l, o = 1 / h;
else {
const c = l * t, u = h * t;
a = c < 1 ? 1 / c : 1, o = u < 1 ? 1 / u : 1;
}
} else {
const l = Math.abs(e * r - s * i), h = Math.hypot(e, s), c = Math.hypot(i, r);
if (t === 0)
a = c / l, o = h / l;
else {
const u = t * l;
a = c > u ? c / u : 1, o = h > u ? h / u : 1;
}
}
this._cachedScaleForStroking[0] = a, this._cachedScaleForStroking[1] = o;
}
return this._cachedScaleForStroking;
}
rescaleAndStroke(t, e) {
const {
ctx: s,
current: {
lineWidth: i
}
} = this, [r, a] = this.getScaleForStroking();
if (r === a) {
s.lineWidth = (i || 1) * r, s.stroke(t);
return;
}
const o = s.getLineDash();
e && s.save(), s.scale(r, a), Tc.a = 1 / r, Tc.d = 1 / a;
const l = new Path2D();
if (l.addPath(t, Tc), o.length > 0) {
const h = Math.max(r, a);
s.setLineDash(o.map((c) => c / h)), s.lineDashOffset /= h;
}
s.lineWidth = i || 1, s.stroke(l), e && s.restore();
}
isContentVisible() {
for (let t = this.markedContentStack.length - 1; t >= 0; t--)
if (!this.markedContentStack[t].visible)
return !1;
return !0;
}
};
os = new WeakSet(), sd = function() {
for (; this.stateStack.length || this.inSMaskMode; )
this.restore();
this.current.activeSMask = null, this.ctx.restore(), this.transparentCanvas && (this.ctx = this.compositeCtx, this.ctx.save(), this.ctx.setTransform(1, 0, 0, 1, 0, 0), this.ctx.drawImage(this.transparentCanvas, 0, 0), this.ctx.restore(), this.transparentCanvas = null);
}, id = function() {
if (this.pageColors) {
const t = this.filterFactory.addHCMFilter(this.pageColors.foreground, this.pageColors.background);
if (t !== "none") {
const e = this.ctx.filter;
this.ctx.filter = t, this.ctx.drawImage(this.ctx.canvas, 0, 0), this.ctx.filter = e;
}
}
}, nd = function(t, e, s) {
const i = new Path2D();
return i.addPath(t, new DOMMatrix(s).invertSelf().multiplySelf(e)), i;
};
let Gr = ou;
for (const d in Hh)
Gr.prototype[d] !== void 0 && (Gr.prototype[Hh[d]] = Gr.prototype[d]);
var Xo, Yo;
class fi {
static get workerPort() {
return n(this, Xo);
}
static set workerPort(t) {
if (!(typeof Worker < "u" && t instanceof Worker) && t !== null)
throw new Error("Invalid `workerPort` type.");
f(this, Xo, t);
}
static get workerSrc() {
return n(this, Yo);
}
static set workerSrc(t) {
if (typeof t != "string")
throw new Error("Invalid `workerSrc` type.");
f(this, Yo, t);
}
}
Xo = new WeakMap(), Yo = new WeakMap(), m(fi, Xo, null), m(fi, Yo, "");
var aa, Ko;
class Ug {
constructor({
parsedData: t,
rawData: e
}) {
m(this, aa);
m(this, Ko);
f(this, aa, t), f(this, Ko, e);
}
getRaw() {
return n(this, Ko);
}
get(t) {
return n(this, aa).get(t) ?? null;
}
[Symbol.iterator]() {
return n(this, aa).entries();
}
}
aa = new WeakMap(), Ko = new WeakMap();
const Fr = Symbol("INTERNAL");
var Qo, Jo, Zo, oa;
class jg {
constructor(t, {
name: e,
intent: s,
usage: i,
rbGroups: r
}) {
m(this, Qo, !1);
m(this, Jo, !1);
m(this, Zo, !1);
m(this, oa, !0);
f(this, Qo, !!(t & Me.DISPLAY)), f(this, Jo, !!(t & Me.PRINT)), this.name = e, this.intent = s, this.usage = i, this.rbGroups = r;
}
get visible() {
if (n(this, Zo))
return n(this, oa);
if (!n(this, oa))
return !1;
const {
print: t,
view: e
} = this.usage;
return n(this, Qo) ? (e == null ? void 0 : e.viewState) !== "OFF" : n(this, Jo) ? (t == null ? void 0 : t.printState) !== "OFF" : !0;
}
_setVisible(t, e, s = !1) {
t !== Fr && rt("Internal method `_setVisible` called."), f(this, Zo, s), f(this, oa, e);
}
}
Qo = new WeakMap(), Jo = new WeakMap(), Zo = new WeakMap(), oa = new WeakMap();
var Oi, it, la, ha, tl, rd;
class Vg {
constructor(t, e = Me.DISPLAY) {
m(this, tl);
m(this, Oi, null);
m(this, it, /* @__PURE__ */ new Map());
m(this, la, null);
m(this, ha, null);
if (this.renderingIntent = e, this.name = null, this.creator = null, t !== null) {
this.name = t.name, this.creator = t.creator, f(this, ha, t.order);
for (const s of t.groups)
n(this, it).set(s.id, new jg(e, s));
if (t.baseState === "OFF")
for (const s of n(this, it).values())
s._setVisible(Fr, !1);
for (const s of t.on)
n(this, it).get(s)._setVisible(Fr, !0);
for (const s of t.off)
n(this, it).get(s)._setVisible(Fr, !1);
f(this, la, this.getHash());
}
}
isVisible(t) {
if (n(this, it).size === 0)
return !0;
if (!t)
return gc("Optional content group not defined."), !0;
if (t.type === "OCG")
return n(this, it).has(t.id) ? n(this, it).get(t.id).visible : (U(`Optional content group not found: ${t.id}`), !0);
if (t.type === "OCMD") {
if (t.expression)
return b(this, tl, rd).call(this, t.expression);
if (!t.policy || t.policy === "AnyOn") {
for (const e of t.ids) {
if (!n(this, it).has(e))
return U(`Optional content group not found: ${e}`), !0;
if (n(this, it).get(e).visible)
return !0;
}
return !1;
} else if (t.policy === "AllOn") {
for (const e of t.ids) {
if (!n(this, it).has(e))
return U(`Optional content group not found: ${e}`), !0;
if (!n(this, it).get(e).visible)
return !1;
}
return !0;
} else if (t.policy === "AnyOff") {
for (const e of t.ids) {
if (!n(this, it).has(e))
return U(`Optional content group not found: ${e}`), !0;
if (!n(this, it).get(e).visible)
return !0;
}
return !1;
} else if (t.policy === "AllOff") {
for (const e of t.ids) {
if (!n(this, it).has(e))
return U(`Optional content group not found: ${e}`), !0;
if (n(this, it).get(e).visible)
return !1;
}
return !0;
}
return U(`Unknown optional content policy ${t.policy}.`), !0;
}
return U(`Unknown group type ${t.type}.`), !0;
}
setVisibility(t, e = !0, s = !0) {
var r;
const i = n(this, it).get(t);
if (!i) {
U(`Optional content group not found: ${t}`);
return;
}
if (s && e && i.rbGroups.length)
for (const a of i.rbGroups)
for (const o of a)
o !== t && ((r = n(this, it).get(o)) == null || r._setVisible(Fr, !1, !0));
i._setVisible(Fr, !!e, !0), f(this, Oi, null);
}
setOCGState({
state: t,
preserveRB: e
}) {
let s;
for (const i of t) {
switch (i) {
case "ON":
case "OFF":
case "Toggle":
s = i;
continue;
}
const r = n(this, it).get(i);
if (r)
switch (s) {
case "ON":
this.setVisibility(i, !0, e);
break;
case "OFF":
this.setVisibility(i, !1, e);
break;
case "Toggle":
this.setVisibility(i, !r.visible, e);
break;
}
}
f(this, Oi, null);
}
get hasInitialVisibility() {
return n(this, la) === null || this.getHash() === n(this, la);
}
getOrder() {
return n(this, it).size ? n(this, ha) ? n(this, ha).slice() : [...n(this, it).keys()] : null;
}
getGroup(t) {
return n(this, it).get(t) || null;
}
getHash() {
if (n(this, Oi) !== null)
return n(this, Oi);
const t = new bf();
for (const [e, s] of n(this, it))
t.update(`${e}:${s.visible}`);
return f(this, Oi, t.hexdigest());
}
[Symbol.iterator]() {
return n(this, it).entries();
}
}
Oi = new WeakMap(), it = new WeakMap(), la = new WeakMap(), ha = new WeakMap(), tl = new WeakSet(), rd = function(t) {
const e = t.length;
if (e < 2)
return !0;
const s = t[0];
for (let i = 1; i < e; i++) {
const r = t[i];
let a;
if (Array.isArray(r))
a = b(this, tl, rd).call(this, r);
else if (n(this, it).has(r))
a = n(this, it).get(r).visible;
else
return U(`Optional content group not found: ${r}`), !0;
switch (s) {
case "And":
if (!a)
return !1;
break;
case "Or":
if (a)
return !0;
break;
case "Not":
return !a;
default:
return !0;
}
}
return s === "And";
};
class Wg {
constructor(t, {
disableRange: e = !1,
disableStream: s = !1
}) {
Et(t, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
const {
length: i,
initialData: r,
progressiveDone: a,
contentDispositionFilename: o
} = t;
if (this._queuedChunks = [], this._progressiveDone = a, this._contentDispositionFilename = o, (r == null ? void 0 : r.length) > 0) {
const l = r instanceof Uint8Array && r.byteLength === r.buffer.byteLength ? r.buffer : new Uint8Array(r).buffer;
this._queuedChunks.push(l);
}
this._pdfDataRangeTransport = t, this._isStreamingSupported = !s, this._isRangeSupported = !e, this._contentLength = i, this._fullRequestReader = null, this._rangeReaders = [], t.addRangeListener((l, h) => {
this._onReceiveData({
begin: l,
chunk: h
});
}), t.addProgressListener((l, h) => {
this._onProgress({
loaded: l,
total: h
});
}), t.addProgressiveReadListener((l) => {
this._onReceiveData({
chunk: l
});
}), t.addProgressiveDoneListener(() => {
this._onProgressiveDone();
}), t.transportReady();
}
_onReceiveData({
begin: t,
chunk: e
}) {
const s = e instanceof Uint8Array && e.byteLength === e.buffer.byteLength ? e.buffer : new Uint8Array(e).buffer;
if (t === void 0)
this._fullRequestReader ? this._fullRequestReader._enqueue(s) : this._queuedChunks.push(s);
else {
const i = this._rangeReaders.some(function(r) {
return r._begin !== t ? !1 : (r._enqueue(s), !0);
});
Et(i, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
}
}
get _progressiveDataLength() {
var t;
return ((t = this._fullRequestReader) == null ? void 0 : t._loaded) ?? 0;
}
_onProgress(t) {
var e, s, i, r;
t.total === void 0 ? (s = (e = this._rangeReaders[0]) == null ? void 0 : e.onProgress) == null || s.call(e, {
loaded: t.loaded
}) : (r = (i = this._fullRequestReader) == null ? void 0 : i.onProgress) == null || r.call(i, {
loaded: t.loaded,
total: t.total
});
}
_onProgressiveDone() {
var t;
(t = this._fullRequestReader) == null || t.progressiveDone(), this._progressiveDone = !0;
}
_removeRangeReader(t) {
const e = this._rangeReaders.indexOf(t);
e >= 0 && this._rangeReaders.splice(e, 1);
}
getFullReader() {
Et(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
const t = this._queuedChunks;
return this._queuedChunks = null, new qg(this, t, this._progressiveDone, this._contentDispositionFilename);
}
getRangeReader(t, e) {
if (e <= this._progressiveDataLength)
return null;
const s = new Xg(this, t, e);
return this._pdfDataRangeTransport.requestDataRange(t, e), this._rangeReaders.push(s), s;
}
cancelAllRequests(t) {
var e;
(e = this._fullRequestReader) == null || e.cancel(t);
for (const s of this._rangeReaders.slice(0))
s.cancel(t);
this._pdfDataRangeTransport.abort();
}
}
class qg {
constructor(t, e, s = !1, i = null) {
this._stream = t, this._done = s || !1, this._filename = Kd(i) ? i : null, this._queuedChunks = e || [], this._loaded = 0;
for (const r of this._queuedChunks)
this._loaded += r.byteLength;
this._requests = [], this._headersReady = Promise.resolve(), t._fullRequestReader = this, this.onProgress = null;
}
_enqueue(t) {
this._done || (this._requests.length > 0 ? this._requests.shift().resolve({
value: t,
done: !1
}) : this._queuedChunks.push(t), this._loaded += t.byteLength);
}
get headersReady() {
return this._headersReady;
}
get filename() {
return this._filename;
}
get isRangeSupported() {
return this._stream._isRangeSupported;
}
get isStreamingSupported() {
return this._stream._isStreamingSupported;
}
get contentLength() {
return this._stream._contentLength;
}
async read() {
if (this._queuedChunks.length > 0)
return {
value: this._queuedChunks.shift(),
done: !1
};
if (this._done)
return {
value: void 0,
done: !0
};
const t = Promise.withResolvers();
return this._requests.push(t), t.promise;
}
cancel(t) {
this._done = !0;
for (const e of this._requests)
e.resolve({
value: void 0,
done: !0
});
this._requests.length = 0;
}
progressiveDone() {
this._done || (this._done = !0);
}
}
class Xg {
constructor(t, e, s) {
this._stream = t, this._begin = e, this._end = s, this._queuedChunk = null, this._requests = [], this._done = !1, this.onProgress = null;
}
_enqueue(t) {
if (!this._done) {
if (this._requests.length === 0)
this._queuedChunk = t;
else {
this._requests.shift().resolve({
value: t,
done: !1
});
for (const s of this._requests)
s.resolve({
value: void 0,
done: !0
});
this._requests.length = 0;
}
this._done = !0, this._stream._removeRangeReader(this);
}
}
get isStreamingSupported() {
return !1;
}
async read() {
if (this._queuedChunk) {
const e = this._queuedChunk;
return this._queuedChunk = null, {
value: e,
done: !1
};
}
if (this._done)
return {
value: void 0,
done: !0
};
const t = Promise.withResolvers();
return this._requests.push(t), t.promise;
}
cancel(t) {
this._done = !0;
for (const e of this._requests)
e.resolve({
value: void 0,
done: !0
});
this._requests.length = 0, this._stream._removeRangeReader(this);
}
}
function Yg(d) {
let t = !0, e = s("filename\\*", "i").exec(d);
if (e) {
e = e[1];
let c = o(e);
return c = unescape(c), c = l(c), c = h(c), r(c);
}
if (e = a(d), e) {
const c = h(e);
return r(c);
}
if (e = s("filename", "i").exec(d), e) {
e = e[1];
let c = o(e);
return c = h(c), r(c);
}
function s(c, u) {
return new RegExp("(?:^|;)\\s*" + c + '\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)', u);
}
function i(c, u) {
if (c) {
if (!/^[\x00-\xFF]+$/.test(u))
return u;
try {
const p = new TextDecoder(c, {
fatal: !0
}), g = Yl(u);
u = p.decode(g), t = !1;
} catch {
}
}
return u;
}
function r(c) {
return t && /[\x80-\xff]/.test(c) && (c = i("utf-8", c), t && (c = i("iso-8859-1", c))), c;
}
function a(c) {
const u = [];
let p;
const g = s("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
for (; (p = g.exec(c)) !== null; ) {
let [, y, w, v] = p;
if (y = parseInt(y, 10), y in u) {
if (y === 0)
break;
continue;
}
u[y] = [w, v];
}
const A = [];
for (let y = 0; y < u.length && y in u; ++y) {
let [w, v] = u[y];
v = o(v), w && (v = unescape(v), y === 0 && (v = l(v))), A.push(v);
}
return A.join("");
}
function o(c) {
if (c.startsWith('"')) {
const u = c.slice(1).split('\\"');
for (let p = 0; p < u.length; ++p) {
const g = u[p].indexOf('"');
g !== -1 && (u[p] = u[p].slice(0, g), u.length = p + 1), u[p] = u[p].replaceAll(/\\(.)/g, "$1");
}
c = u.join('"');
}
return c;
}
function l(c) {
const u = c.indexOf("'");
if (u === -1)
return c;
const p = c.slice(0, u), A = c.slice(u + 1).replace(/^[^']*'/, "");
return i(p, A);
}
function h(c) {
return !c.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(c) ? c : c.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function(u, p, g, A) {
if (g === "q" || g === "Q")
return A = A.replaceAll("_", " "), A = A.replaceAll(/=([0-9a-fA-F]{2})/g, function(y, w) {
return String.fromCharCode(parseInt(w, 16));
}), i(p, A);
try {
A = atob(A);
} catch {
}
return i(p, A);
});
}
return "";
}
function Pf(d, t) {
const e = new Headers();
if (!d || !t || typeof t != "object")
return e;
for (const s in t) {
const i = t[s];
i !== void 0 && e.append(s, i);
}
return e;
}
function bc(d) {
var t;
return ((t = URL.parse(d)) == null ? void 0 : t.origin) ?? null;
}
function If({
responseHeaders: d,
isHttp: t,
rangeChunkSize: e,
disableRange: s
}) {
const i = {
allowRangeRequests: !1,
suggestedLength: void 0
}, r = parseInt(d.get("Content-Length"), 10);
return !Number.isInteger(r) || (i.suggestedLength = r, r <= 2 * e) || s || !t || d.get("Accept-Ranges") !== "bytes" || (d.get("Content-Encoding") || "identity") !== "identity" || (i.allowRangeRequests = !0), i;
}
function Mf(d) {
const t = d.get("Content-Disposition");
if (t) {
let e = Yg(t);
if (e.includes("%"))
try {
e = decodeURIComponent(e);
} catch {
}
if (Kd(e))
return e;
}
return null;
}
function Zl(d, t) {
return new $h(`Unexpected server response (${d}) while retrieving PDF "${t}".`, d, d === 404 || d === 0 && t.startsWith("file:"));
}
function kf(d) {
return d === 200 || d === 206;
}
function Lf(d, t, e) {
return {
method: "GET",
headers: d,
signal: e.signal,
mode: "cors",
credentials: t ? "include" : "same-origin",
redirect: "follow"
};
}
function Df(d) {
return d instanceof Uint8Array ? d.buffer : d instanceof ArrayBuffer ? d : (U(`getArrayBuffer - unexpected data format: ${d}`), new Uint8Array(d).buffer);
}
class Kg {
constructor(t) {
R(this, "_responseOrigin", null);
this.source = t, this.isHttp = /^https?:/i.test(t.url), this.headers = Pf(this.isHttp, t.httpHeaders), this._fullRequestReader = null, this._rangeRequestReaders = [];
}
get _progressiveDataLength() {
var t;
return ((t = this._fullRequestReader) == null ? void 0 : t._loaded) ?? 0;
}
getFullReader() {
return Et(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once."), this._fullRequestReader = new Qg(this), this._fullRequestReader;
}
getRangeReader(t, e) {
if (e <= this._progressiveDataLength)
return null;
const s = new Jg(this, t, e);
return this._rangeRequestReaders.push(s), s;
}
cancelAllRequests(t) {
var e;
(e = this._fullRequestReader) == null || e.cancel(t);
for (const s of this._rangeRequestReaders.slice(0))
s.cancel(t);
}
}
class Qg {
constructor(t) {
this._stream = t, this._reader = null, this._loaded = 0, this._filename = null;
const e = t.source;
this._withCredentials = e.withCredentials || !1, this._contentLength = e.length, this._headersCapability = Promise.withResolvers(), this._disableRange = e.disableRange || !1, this._rangeChunkSize = e.rangeChunkSize, !this._rangeChunkSize && !this._disableRange && (this._disableRange = !0), this._abortController = new AbortController(), this._isStreamingSupported = !e.disableStream, this._isRangeSupported = !e.disableRange;
const s = new Headers(t.headers), i = e.url;
fetch(i, Lf(s, this._withCredentials, this._abortController)).then((r) => {
if (t._responseOrigin = bc(r.url), !kf(r.status))
throw Zl(r.status, i);
this._reader = r.body.getReader(), this._headersCapability.resolve();
const a = r.headers, {
allowRangeRequests: o,
suggestedLength: l
} = If({
responseHeaders: a,
isHttp: t.isHttp,
rangeChunkSize: this._rangeChunkSize,
disableRange: this._disableRange
});
this._isRangeSupported = o, this._contentLength = l || this._contentLength, this._filename = Mf(a), !this._isStreamingSupported && this._isRangeSupported && this.cancel(new an("Streaming is disabled."));
}).catch(this._headersCapability.reject), this.onProgress = null;
}
get headersReady() {
return this._headersCapability.promise;
}
get filename() {
return this._filename;
}
get contentLength() {
return this._contentLength;
}
get isRangeSupported() {
return this._isRangeSupported;
}
get isStreamingSupported() {
return this._isStreamingSupported;
}
async read() {
var s;
await this._headersCapability.promise;
const {
value: t,
done: e
} = await this._reader.read();
return e ? {
value: t,
done: e
} : (this._loaded += t.byteLength, (s = this.onProgress) == null || s.call(this, {
loaded: this._loaded,
total: this._contentLength
}), {
value: Df(t),
done: !1
});
}
cancel(t) {
var e;
(e = this._reader) == null || e.cancel(t), this._abortController.abort();
}
}
class Jg {
constructor(t, e, s) {
this._stream = t, this._reader = null, this._loaded = 0;
const i = t.source;
this._withCredentials = i.withCredentials || !1, this._readCapability = Promise.withResolvers(), this._isStreamingSupported = !i.disableStream, this._abortController = new AbortController();
const r = new Headers(t.headers);
r.append("Range", `bytes=${e}-${s - 1}`);
const a = i.url;
fetch(a, Lf(r, this._withCredentials, this._abortController)).then((o) => {
const l = bc(o.url);
if (l !== t._responseOrigin)
throw new Error(`Expected range response-origin "${l}" to match "${t._responseOrigin}".`);
if (!kf(o.status))
throw Zl(o.status, a);
this._readCapability.resolve(), this._reader = o.body.getReader();
}).catch(this._readCapability.reject), this.onProgress = null;
}
get isStreamingSupported() {
return this._isStreamingSupported;
}
async read() {
var s;
await this._readCapability.promise;
const {
value: t,
done: e
} = await this._reader.read();
return e ? {
value: t,
done: e
} : (this._loaded += t.byteLength, (s = this.onProgress) == null || s.call(this, {
loaded: this._loaded
}), {
value: Df(t),
done: !1
});
}
cancel(t) {
var e;
(e = this._reader) == null || e.cancel(t), this._abortController.abort();
}
}
const Rc = 200, Pc = 206;
function Zg(d) {
const t = d.response;
return typeof t != "string" ? t : Yl(t).buffer;
}
class tm {
constructor({
url: t,
httpHeaders: e,
withCredentials: s
}) {
R(this, "_responseOrigin", null);
this.url = t, this.isHttp = /^https?:/i.test(t), this.headers = Pf(this.isHttp, e), this.withCredentials = s || !1, this.currXhrId = 0, this.pendingRequests = /* @__PURE__ */ Object.create(null);
}
request(t) {
const e = new XMLHttpRequest(), s = this.currXhrId++, i = this.pendingRequests[s] = {
xhr: e
};
e.open("GET", this.url), e.withCredentials = this.withCredentials;
for (const [r, a] of this.headers)
e.setRequestHeader(r, a);
return this.isHttp && "begin" in t && "end" in t ? (e.setRequestHeader("Range", `bytes=${t.begin}-${t.end - 1}`), i.expectedStatus = Pc) : i.expectedStatus = Rc, e.responseType = "arraybuffer", Et(t.onError, "Expected `onError` callback to be provided."), e.onerror = () => {
t.onError(e.status);
}, e.onreadystatechange = this.onStateChange.bind(this, s), e.onprogress = this.onProgress.bind(this, s), i.onHeadersReceived = t.onHeadersReceived, i.onDone = t.onDone, i.onError = t.onError, i.onProgress = t.onProgress, e.send(null), s;
}
onProgress(t, e) {
var i;
const s = this.pendingRequests[t];
s && ((i = s.onProgress) == null || i.call(s, e));
}
onStateChange(t, e) {
const s = this.pendingRequests[t];
if (!s)
return;
const i = s.xhr;
if (i.readyState >= 2 && s.onHeadersReceived && (s.onHeadersReceived(), delete s.onHeadersReceived), i.readyState !== 4 || !(t in this.pendingRequests))
return;
if (delete this.pendingRequests[t], i.status === 0 && this.isHttp) {
s.onError(i.status);
return;
}
const r = i.status || Rc;
if (!(r === Rc && s.expectedStatus === Pc) && r !== s.expectedStatus) {
s.onError(i.status);
return;
}
const o = Zg(i);
if (r === Pc) {
const l = i.getResponseHeader("Content-Range"), h = /bytes (\d+)-(\d+)\/(\d+)/.exec(l);
h ? s.onDone({
begin: parseInt(h[1], 10),
chunk: o
}) : (U('Missing or invalid "Content-Range" header.'), s.onError(0));
} else o ? s.onDone({
begin: 0,
chunk: o
}) : s.onError(i.status);
}
getRequestXhr(t) {
return this.pendingRequests[t].xhr;
}
isPendingRequest(t) {
return t in this.pendingRequests;
}
abortRequest(t) {
const e = this.pendingRequests[t].xhr;
delete this.pendingRequests[t], e.abort();
}
}
class em {
constructor(t) {
this._source = t, this._manager = new tm(t), this._rangeChunkSize = t.rangeChunkSize, this._fullRequestReader = null, this._rangeRequestReaders = [];
}
_onRangeRequestReaderClosed(t) {
const e = this._rangeRequestReaders.indexOf(t);
e >= 0 && this._rangeRequestReaders.splice(e, 1);
}
getFullReader() {
return Et(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once."), this._fullRequestReader = new sm(this._manager, this._source), this._fullRequestReader;
}
getRangeReader(t, e) {
const s = new im(this._manager, t, e);
return s.onClosed = this._onRangeRequestReaderClosed.bind(this), this._rangeRequestReaders.push(s), s;
}
cancelAllRequests(t) {
var e;
(e = this._fullRequestReader) == null || e.cancel(t);
for (const s of this._rangeRequestReaders.slice(0))
s.cancel(t);
}
}
class sm {
constructor(t, e) {
this._manager = t, this._url = e.url, this._fullRequestId = t.request({
onHeadersReceived: this._onHeadersReceived.bind(this),
onDone: this._onDone.bind(this),
onError: this._onError.bind(this),
onProgress: this._onProgress.bind(this)
}), this._headersCapability = Promise.withResolvers(), this._disableRange = e.disableRange || !1, this._contentLength = e.length, this._rangeChunkSize = e.rangeChunkSize, !this._rangeChunkSize && !this._disableRange && (this._disableRange = !0), this._isStreamingSupported = !1, this._isRangeSupported = !1, this._cachedChunks = [], this._requests = [], this._done = !1, this._storedError = void 0, this._filename = null, this.onProgress = null;
}
_onHeadersReceived() {
const t = this._fullRequestId, e = this._manager.getRequestXhr(t);
this._manager._responseOrigin = bc(e.responseURL);
const s = e.getAllResponseHeaders(), i = new Headers(s ? s.trimStart().replace(/[^\S ]+$/, "").split(/[\r\n]+/).map((o) => {
const [l, ...h] = o.split(": ");
return [l, h.join(": ")];
}) : []), {
allowRangeRequests: r,
suggestedLength: a
} = If({
responseHeaders: i,
isHttp: this._manager.isHttp,
rangeChunkSize: this._rangeChunkSize,
disableRange: this._disableRange
});
r && (this._isRangeSupported = !0), this._contentLength = a || this._contentLength, this._filename = Mf(i), this._isRangeSupported && this._manager.abortRequest(t), this._headersCapability.resolve();
}
_onDone(t) {
if (t && (this._requests.length > 0 ? this._requests.shift().resolve({
value: t.chunk,
done: !1
}) : this._cachedChunks.push(t.chunk)), this._done = !0, !(this._cachedChunks.length > 0)) {
for (const e of this._requests)
e.resolve({
value: void 0,
done: !0
});
this._requests.length = 0;
}
}
_onError(t) {
this._storedError = Zl(t, this._url), this._headersCapability.reject(this._storedError);
for (const e of this._requests)
e.reject(this._storedError);
this._requests.length = 0, this._cachedChunks.length = 0;
}
_onProgress(t) {
var e;
(e = this.onProgress) == null || e.call(this, {
loaded: t.loaded,
total: t.lengthComputable ? t.total : this._contentLength
});
}
get filename() {
return this._filename;
}
get isRangeSupported() {
return this._isRangeSupported;
}
get isStreamingSupported() {
return this._isStreamingSupported;
}
get contentLength() {
return this._contentLength;
}
get headersReady() {
return this._headersCapability.promise;
}
async read() {
if (await this._headersCapability.promise, this._storedError)
throw this._storedError;
if (this._cachedChunks.length > 0)
return {
value: this._cachedChunks.shift(),
done: !1
};
if (this._done)
return {
value: void 0,
done: !0
};
const t = Promise.withResolvers();
return this._requests.push(t), t.promise;
}
cancel(t) {
this._done = !0, this._headersCapability.reject(t);
for (const e of this._requests)
e.resolve({
value: void 0,
done: !0
});
this._requests.length = 0, this._manager.isPendingRequest(this._fullRequestId) && this._manager.abortRequest(this._fullRequestId), this._fullRequestReader = null;
}
}
class im {
constructor(t, e, s) {
this._manager = t, this._url = t.url, this._requestId = t.request({
begin: e,
end: s,
onHeadersReceived: this._onHeadersReceived.bind(this),
onDone: this._onDone.bind(this),
onError: this._onError.bind(this),
onProgress: this._onProgress.bind(this)
}), this._requests = [], this._queuedChunk = null, this._done = !1, this._storedError = void 0, this.onProgress = null, this.onClosed = null;
}
_onHeadersReceived() {
var e;
const t = bc((e = this._manager.getRequestXhr(this._requestId)) == null ? void 0 : e.responseURL);
t !== this._manager._responseOrigin && (this._storedError = new Error(`Expected range response-origin "${t}" to match "${this._manager._responseOrigin}".`), this._onError(0));
}
_close() {
var t;
(t = this.onClosed) == null || t.call(this, this);
}
_onDone(t) {
const e = t.chunk;
this._requests.length > 0 ? this._requests.shift().resolve({
value: e,
done: !1
}) : this._queuedChunk = e, this._done = !0;
for (const s of this._requests)
s.resolve({
value: void 0,
done: !0
});
this._requests.length = 0, this._close();
}
_onError(t) {
this._storedError ?? (this._storedError = Zl(t, this._url));
for (const e of this._requests)
e.reject(this._storedError);
this._requests.length = 0, this._queuedChunk = null;
}
_onProgress(t) {
var e;
this.isStreamingSupported || (e = this.onProgress) == null || e.call(this, {
loaded: t.loaded
});
}
get isStreamingSupported() {
return !1;
}
async read() {
if (this._storedError)
throw this._storedError;
if (this._queuedChunk !== null) {
const e = this._queuedChunk;
return this._queuedChunk = null, {
value: e,
done: !1
};
}
if (this._done)
return {
value: void 0,
done: !0
};
const t = Promise.withResolvers();
return this._requests.push(t), t.promise;
}
cancel(t) {
this._done = !0;
for (const e of this._requests)
e.resolve({
value: void 0,
done: !0
});
this._requests.length = 0, this._manager.isPendingRequest(this._requestId) && this._manager.abortRequest(this._requestId), this._close();
}
}
const nm = /^[a-z][a-z0-9\-+.]+:/i;
function rm(d) {
if (nm.test(d))
return new URL(d);
const t = process.getBuiltinModule("url");
return new URL(t.pathToFileURL(d));
}
class am {
constructor(t) {
this.source = t, this.url = rm(t.url), Et(this.url.protocol === "file:", "PDFNodeStream only supports file:// URLs."), this._fullRequestReader = null, this._rangeRequestReaders = [];
}
get _progressiveDataLength() {
var t;
return ((t = this._fullRequestReader) == null ? void 0 : t._loaded) ?? 0;
}
getFullReader() {
return Et(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once."), this._fullRequestReader = new om(this), this._fullRequestReader;
}
getRangeReader(t, e) {
if (e <= this._progressiveDataLength)
return null;
const s = new lm(this, t, e);
return this._rangeRequestReaders.push(s), s;
}
cancelAllRequests(t) {
var e;
(e = this._fullRequestReader) == null || e.cancel(t);
for (const s of this._rangeRequestReaders.slice(0))
s.cancel(t);
}
}
class om {
constructor(t) {
this._url = t.url, this._done = !1, this._storedError = null, this.onProgress = null;
const e = t.source;
this._contentLength = e.length, this._loaded = 0, this._filename = null, this._disableRange = e.disableRange || !1, this._rangeChunkSize = e.rangeChunkSize, !this._rangeChunkSize && !this._disableRange && (this._disableRange = !0), this._isStreamingSupported = !e.disableStream, this._isRangeSupported = !e.disableRange, this._readableStream = null, this._readCapability = Promise.withResolvers(), this._headersCapability = Promise.withResolvers();
const s = process.getBuiltinModule("fs");
s.promises.lstat(this._url).then((i) => {
this._contentLength = i.size, this._setReadableStream(s.createReadStream(this._url)), this._headersCapability.resolve();
}, (i) => {
i.code === "ENOENT" && (i = Zl(0, this._url.href)), this._storedError = i, this._headersCapability.reject(i);
});
}
get headersReady() {
return this._headersCapability.promise;
}
get filename() {
return this._filename;
}
get contentLength() {
return this._contentLength;
}
get isRangeSupported() {
return this._isRangeSupported;
}
get isStreamingSupported() {
return this._isStreamingSupported;
}
async read() {
var s;
if (await this._readCapability.promise, this._done)
return {
value: void 0,
done: !0
};
if (this._storedError)
throw this._storedError;
const t = this._readableStream.read();
return t === null ? (this._readCapability = Promise.withResolvers(), this.read()) : (this._loaded += t.length, (s = this.onProgress) == null || s.call(this, {
loaded: this._loaded,
total: this._contentLength
}), {
value: new Uint8Array(t).buffer,
done: !1
});
}
cancel(t) {
if (!this._readableStream) {
this._error(t);
return;
}
this._readableStream.destroy(t);
}
_error(t) {
this._storedError = t, this._readCapability.resolve();
}
_setReadableStream(t) {
this._readableStream = t, t.on("readable", () => {
this._readCapability.resolve();
}), t.on("end", () => {
t.destroy(), this._done = !0, this._readCapability.resolve();
}), t.on("error", (e) => {
this._error(e);
}), !this._isStreamingSupported && this._isRangeSupported && this._error(new an("streaming is disabled")), this._storedError && this._readableStream.destroy(this._storedError);
}
}
class lm {
constructor(t, e, s) {
this._url = t.url, this._done = !1, this._storedError = null, this.onProgress = null, this._loaded = 0, this._readableStream = null, this._readCapability = Promise.withResolvers();
const i = t.source;
this._isStreamingSupported = !i.disableStream;
const r = process.getBuiltinModule("fs");
this._setReadableStream(r.createReadStream(this._url, {
start: e,
end: s - 1
}));
}
get isStreamingSupported() {
return this._isStreamingSupported;
}
async read() {
var s;
if (await this._readCapability.promise, this._done)
return {
value: void 0,
done: !0
};
if (this._storedError)
throw this._storedError;
const t = this._readableStream.read();
return t === null ? (this._readCapability = Promise.withResolvers(), this.read()) : (this._loaded += t.length, (s = this.onProgress) == null || s.call(this, {
loaded: this._loaded
}), {
value: new Uint8Array(t).buffer,
done: !1
});
}
cancel(t) {
if (!this._readableStream) {
this._error(t);
return;
}
this._readableStream.destroy(t);
}
_error(t) {
this._storedError = t, this._readCapability.resolve();
}
_setReadableStream(t) {
this._readableStream = t, t.on("readable", () => {
this._readCapability.resolve();
}), t.on("end", () => {
t.destroy(), this._done = !0, this._readCapability.resolve();
}), t.on("error", (e) => {
this._error(e);
}), this._storedError && this._readableStream.destroy(this._storedError);
}
}
const Ya = Symbol("INITIAL_DATA");
var we, el, ad;
class Ff {
constructor() {
m(this, el);
m(this, we, /* @__PURE__ */ Object.create(null));
}
get(t, e = null) {
if (e) {
const i = b(this, el, ad).call(this, t);
return i.promise.then(() => e(i.data)), null;
}
const s = n(this, we)[t];
if (!s || s.data === Ya)
throw new Error(`Requesting object that isn't resolved yet ${t}.`);
return s.data;
}
has(t) {
const e = n(this, we)[t];
return !!e && e.data !== Ya;
}
delete(t) {
const e = n(this, we)[t];
return !e || e.data === Ya ? !1 : (delete n(this, we)[t], !0);
}
resolve(t, e = null) {
const s = b(this, el, ad).call(this, t);
s.data = e, s.resolve();
}
clear() {
var t;
for (const e in n(this, we)) {
const {
data: s
} = n(this, we)[e];
(t = s == null ? void 0 : s.bitmap) == null || t.close();
}
f(this, we, /* @__PURE__ */ Object.create(null));
}
*[Symbol.iterator]() {
for (const t in n(this, we)) {
const {
data: e
} = n(this, we)[t];
e !== Ya && (yield [t, e]);
}
}
}
we = new WeakMap(), el = new WeakSet(), ad = function(t) {
var e;
return (e = n(this, we))[t] || (e[t] = {
...Promise.withResolvers(),
data: Ya
});
};
const hm = 1e5, Pu = 30;
var Lu, Bi, fe, sl, il, $n, Ys, nl, rl, Gn, ca, da, Hi, ua, al, fa, zn, ol, ll, pa, Un, hl, $i, ga, bi, Nf, Of, od, De, yh, ld, Bf, Hf;
const xt = class xt {
constructor({
textContentSource: t,
container: e,
viewport: s
}) {
m(this, bi);
m(this, Bi, Promise.withResolvers());
m(this, fe, null);
m(this, sl, !1);
m(this, il, !!((Lu = globalThis.FontInspector) != null && Lu.enabled));
m(this, $n, null);
m(this, Ys, null);
m(this, nl, 0);
m(this, rl, 0);
m(this, Gn, null);
m(this, ca, null);
m(this, da, 0);
m(this, Hi, 0);
m(this, ua, /* @__PURE__ */ Object.create(null));
m(this, al, []);
m(this, fa, null);
m(this, zn, []);
m(this, ol, /* @__PURE__ */ new WeakMap());
m(this, ll, null);
var l;
if (t instanceof ReadableStream)
f(this, fa, t);
else if (typeof t == "object")
f(this, fa, new ReadableStream({
start(h) {
h.enqueue(t), h.close();
}
}));
else
throw new Error('No "textContentSource" parameter specified.');
f(this, fe, f(this, ca, e)), f(this, Hi, s.scale * Rs.pixelRatio), f(this, da, s.rotation), f(this, Ys, {
div: null,
properties: null,
ctx: null
});
const {
pageWidth: i,
pageHeight: r,
pageX: a,
pageY: o
} = s.rawDims;
f(this, ll, [1, 0, 0, -1, -a, o + r]), f(this, rl, i), f(this, nl, r), b(l = xt, De, Bf).call(l), Cr(e, s), n(this, Bi).promise.finally(() => {
n(xt, ga).delete(this), f(this, Ys, null), f(this, ua, null);
}).catch(() => {
});
}
static get fontFamilyMap() {
const {
isWindows: t,
isFirefox: e
} = Wt.platform;
return X(this, "fontFamilyMap", /* @__PURE__ */ new Map([["sans-serif", `${t && e ? "Calibri, " : ""}sans-serif`], ["monospace", `${t && e ? "Lucida Console, " : ""}monospace`]]));
}
render() {
const t = () => {
n(this, Gn).read().then(({
value: e,
done: s
}) => {
if (s) {
n(this, Bi).resolve();
return;
}
n(this, $n) ?? f(this, $n, e.lang), Object.assign(n(this, ua), e.styles), b(this, bi, Nf).call(this, e.items), t();
}, n(this, Bi).reject);
};
return f(this, Gn, n(this, fa).getReader()), n(xt, ga).add(this), t(), n(this, Bi).promise;
}
update({
viewport: t,
onBefore: e = null
}) {
var r;
const s = t.scale * Rs.pixelRatio, i = t.rotation;
if (i !== n(this, da) && (e == null || e(), f(this, da, i), Cr(n(this, ca), {
rotation: i
})), s !== n(this, Hi)) {
e == null || e(), f(this, Hi, s);
const a = {
div: null,
properties: null,
ctx: b(r = xt, De, yh).call(r, n(this, $n))
};
for (const o of n(this, zn))
a.properties = n(this, ol).get(o), a.div = o, b(this, bi, od).call(this, a);
}
}
cancel() {
var e;
const t = new an("TextLayer task cancelled.");
(e = n(this, Gn)) == null || e.cancel(t).catch(() => {
}), f(this, Gn, null), n(this, Bi).reject(t);
}
get textDivs() {
return n(this, zn);
}
get textContentItemsStr() {
return n(this, al);
}
static cleanup() {
if (!(n(this, ga).size > 0)) {
n(this, pa).clear();
for (const {
canvas: t
} of n(this, Un).values())
t.remove();
n(this, Un).clear();
}
}
};
Bi = new WeakMap(), fe = new WeakMap(), sl = new WeakMap(), il = new WeakMap(), $n = new WeakMap(), Ys = new WeakMap(), nl = new WeakMap(), rl = new WeakMap(), Gn = new WeakMap(), ca = new WeakMap(), da = new WeakMap(), Hi = new WeakMap(), ua = new WeakMap(), al = new WeakMap(), fa = new WeakMap(), zn = new WeakMap(), ol = new WeakMap(), ll = new WeakMap(), pa = new WeakMap(), Un = new WeakMap(), hl = new WeakMap(), $i = new WeakMap(), ga = new WeakMap(), bi = new WeakSet(), Nf = function(t) {
var i, r;
if (n(this, sl))
return;
(r = n(this, Ys)).ctx ?? (r.ctx = b(i = xt, De, yh).call(i, n(this, $n)));
const e = n(this, zn), s = n(this, al);
for (const a of t) {
if (e.length > hm) {
U("Ignoring additional textDivs for performance reasons."), f(this, sl, !0);
return;
}
if (a.str === void 0) {
if (a.type === "beginMarkedContentProps" || a.type === "beginMarkedContent") {
const o = n(this, fe);
f(this, fe, document.createElement("span")), n(this, fe).classList.add("markedContent"), a.id !== null && n(this, fe).setAttribute("id", `${a.id}`), o.append(n(this, fe));
} else a.type === "endMarkedContent" && f(this, fe, n(this, fe).parentNode);
continue;
}
s.push(a.str), b(this, bi, Of).call(this, a);
}
}, Of = function(t) {
var y;
const e = document.createElement("span"), s = {
angle: 0,
canvasWidth: 0,
hasText: t.str !== "",
hasEOL: t.hasEOL,
fontSize: 0
};
n(this, zn).push(e);
const i = $.transform(n(this, ll), t.transform);
let r = Math.atan2(i[1], i[0]);
const a = n(this, ua)[t.fontName];
a.vertical && (r += Math.PI / 2);
let o = n(this, il) && a.fontSubstitution || a.fontFamily;
o = xt.fontFamilyMap.get(o) || o;
const l = Math.hypot(i[2], i[3]), h = l * b(y = xt, De, Hf).call(y, o, a, n(this, $n));
let c, u;
r === 0 ? (c = i[4], u = i[5] - h) : (c = i[4] + h * Math.sin(r), u = i[5] - h * Math.cos(r));
const p = "calc(var(--total-scale-factor) *", g = e.style;
n(this, fe) === n(this, ca) ? (g.left = `${(100 * c / n(this, rl)).toFixed(2)}%`, g.top = `${(100 * u / n(this, nl)).toFixed(2)}%`) : (g.left = `${p}${c.toFixed(2)}px)`, g.top = `${p}${u.toFixed(2)}px)`), g.fontSize = `${p}${(n(xt, $i) * l).toFixed(2)}px)`, g.fontFamily = o, s.fontSize = l, e.setAttribute("role", "presentation"), e.textContent = t.str, e.dir = t.dir, n(this, il) && (e.dataset.fontName = a.fontSubstitutionLoadedName || t.fontName), r !== 0 && (s.angle = r * (180 / Math.PI));
let A = !1;
if (t.str.length > 1)
A = !0;
else if (t.str !== " " && t.transform[0] !== t.transform[3]) {
const w = Math.abs(t.transform[0]), v = Math.abs(t.transform[3]);
w !== v && Math.max(w, v) / Math.min(w, v) > 1.5 && (A = !0);
}
if (A && (s.canvasWidth = a.vertical ? t.height : t.width), n(this, ol).set(e, s), n(this, Ys).div = e, n(this, Ys).properties = s, b(this, bi, od).call(this, n(this, Ys)), s.hasText && n(this, fe).append(e), s.hasEOL) {
const w = document.createElement("br");
w.setAttribute("role", "presentation"), n(this, fe).append(w);
}
}, od = function(t) {
var o;
const {
div: e,
properties: s,
ctx: i
} = t, {
style: r
} = e;
let a = "";
if (n(xt, $i) > 1 && (a = `scale(${1 / n(xt, $i)})`), s.canvasWidth !== 0 && s.hasText) {
const {
fontFamily: l
} = r, {
canvasWidth: h,
fontSize: c
} = s;
b(o = xt, De, ld).call(o, i, c * n(this, Hi), l);
const {
width: u
} = i.measureText(e.textContent);
u > 0 && (a = `scaleX(${h * n(this, Hi) / u}) ${a}`);
}
s.angle !== 0 && (a = `rotate(${s.angle}deg) ${a}`), a.length > 0 && (r.transform = a);
}, De = new WeakSet(), yh = function(t = null) {
let e = n(this, Un).get(t || (t = ""));
if (!e) {
const s = document.createElement("canvas");
s.className = "hiddenCanvasElement", s.lang = t, document.body.append(s), e = s.getContext("2d", {
alpha: !1,
willReadFrequently: !0
}), n(this, Un).set(t, e), n(this, hl).set(e, {
size: 0,
family: ""
});
}
return e;
}, ld = function(t, e, s) {
const i = n(this, hl).get(t);
e === i.size && s === i.family || (t.font = `${e}px ${s}`, i.size = e, i.family = s);
}, Bf = function() {
if (n(this, $i) !== null)
return;
const t = document.createElement("div");
t.style.opacity = 0, t.style.lineHeight = 1, t.style.fontSize = "1px", t.style.position = "absolute", t.textContent = "X", document.body.append(t), f(this, $i, t.getBoundingClientRect().height), t.remove();
}, Hf = function(t, e, s) {
const i = n(this, pa).get(t);
if (i)
return i;
const r = b(this, De, yh).call(this, s);
r.canvas.width = r.canvas.height = Pu, b(this, De, ld).call(this, r, Pu, t);
const a = r.measureText(""), o = a.fontBoundingBoxAscent, l = Math.abs(a.fontBoundingBoxDescent);
r.canvas.width = r.canvas.height = 0;
let h = 0.8;
return o ? h = o / (o + l) : (Wt.platform.isFirefox && U("Enable the `dom.textMetrics.fontBoundingBox.enabled` preference in `about:config` to improve TextLayer rendering."), e.ascent ? h = e.ascent : e.descent && (h = 1 + e.descent)), n(this, pa).set(t, h), h;
}, m(xt, De), m(xt, pa, /* @__PURE__ */ new Map()), m(xt, Un, /* @__PURE__ */ new Map()), m(xt, hl, /* @__PURE__ */ new WeakMap()), m(xt, $i, null), m(xt, ga, /* @__PURE__ */ new Set());
let Ao = xt;
class yo {
static textContent(t) {
const e = [], s = {
items: e,
styles: /* @__PURE__ */ Object.create(null)
};
function i(r) {
var l;
if (!r)
return;
let a = null;
const o = r.name;
if (o === "#text")
a = r.value;
else if (yo.shouldBuildText(o))
(l = r == null ? void 0 : r.attributes) != null && l.textContent ? a = r.attributes.textContent : r.value && (a = r.value);
else return;
if (a !== null && e.push({
str: a
}), !!r.children)
for (const h of r.children)
i(h);
}
return i(t), s;
}
static shouldBuildText(t) {
return !(t === "textarea" || t === "input" || t === "option" || t === "select");
}
}
const cm = 100;
function dm(d = {}) {
typeof d == "string" || d instanceof URL ? d = {
url: d
} : (d instanceof ArrayBuffer || ArrayBuffer.isView(d)) && (d = {
data: d
});
const t = new hd(), {
docId: e
} = t, s = d.url ? yg(d.url) : null, i = d.data ? wg(d.data) : null, r = d.httpHeaders || null, a = d.withCredentials === !0, o = d.password ?? null, l = d.range instanceof $f ? d.range : null, h = Number.isInteger(d.rangeChunkSize) && d.rangeChunkSize > 0 ? d.rangeChunkSize : 2 ** 16;
let c = d.worker instanceof wo ? d.worker : null;
const u = d.verbosity, p = typeof d.docBaseUrl == "string" && !mc(d.docBaseUrl) ? d.docBaseUrl : null, g = sh(d.cMapUrl), A = d.cMapPacked !== !1, y = d.CMapReaderFactory || (re ? Rg : bu), w = sh(d.iccUrl), v = sh(d.standardFontDataUrl), S = d.StandardFontDataFactory || (re ? Pg : Au), _ = sh(d.wasmUrl), E = d.WasmFactory || (re ? Ig : yu), C = d.stopAtErrors !== !0, x = Number.isInteger(d.maxImageSize) && d.maxImageSize > -1 ? d.maxImageSize : -1, T = d.isEvalSupported !== !1, P = typeof d.isOffscreenCanvasSupported == "boolean" ? d.isOffscreenCanvasSupported : !re, M = typeof d.isImageDecoderSupported == "boolean" ? d.isImageDecoderSupported : !re && (Wt.platform.isFirefox || !globalThis.chrome), O = Number.isInteger(d.canvasMaxAreaInBytes) ? d.canvasMaxAreaInBytes : -1, D = typeof d.disableFontFace == "boolean" ? d.disableFontFace : re, tt = d.fontExtraProperties === !0, st = d.enableXfa === !0, q = d.ownerDocument || globalThis.document, Jt = d.disableRange === !0, N = d.disableStream === !0, H = d.disableAutoFetch === !0, Fe = d.pdfBug === !0, Is = d.CanvasFactory || (re ? Tg : Eg), dn = d.FilterFactory || (re ? xg : Cg), Ms = d.enableHWA === !0, Mt = d.useWasm !== !1, bt = l ? l.length : d.length ?? NaN, Ir = typeof d.useSystemFonts == "boolean" ? d.useSystemFonts : !re && !D, Ai = typeof d.useWorkerFetch == "boolean" ? d.useWorkerFetch : !!(y === bu && S === Au && E === yu && g && v && _ && Ja(g, document.baseURI) && Ja(v, document.baseURI) && Ja(_, document.baseURI)), yi = null;
Qp(u);
const gt = {
canvasFactory: new Is({
ownerDocument: q,
enableHWA: Ms
}),
filterFactory: new dn({
docId: e,
ownerDocument: q
}),
cMapReaderFactory: Ai ? null : new y({
baseUrl: g,
isCompressed: A
}),
standardFontDataFactory: Ai ? null : new S({
baseUrl: v
}),
wasmFactory: Ai ? null : new E({
baseUrl: _
})
};
c || (c = wo.create({
verbosity: u,
port: fi.workerPort
}), t._worker = c);
const qa = {
docId: e,
apiVersion: "5.3.93",
data: i,
password: o,
disableAutoFetch: H,
rangeChunkSize: h,
length: bt,
docBaseUrl: p,
enableXfa: st,
evaluatorOptions: {
maxImageSize: x,
disableFontFace: D,
ignoreErrors: C,
isEvalSupported: T,
isOffscreenCanvasSupported: P,
isImageDecoderSupported: M,
canvasMaxAreaInBytes: O,
fontExtraProperties: tt,
useSystemFonts: Ir,
useWasm: Mt,
useWorkerFetch: Ai,
cMapUrl: g,
iccUrl: w,
standardFontDataUrl: v,
wasmUrl: _
}
}, jp = {
ownerDocument: q,
pdfBug: Fe,
styleElement: yi,
loadingParams: {
disableAutoFetch: H,
enableXfa: st
}
};
return c.promise.then(function() {
if (t.destroyed)
throw new Error("Loading aborted");
if (c.destroyed)
throw new Error("Worker was destroyed");
const Vp = c.messageHandler.sendWithPromise("GetDocRequest", qa, i ? [i.buffer] : null);
let yc;
if (l)
yc = new Wg(l, {
disableRange: Jt,
disableStream: N
});
else if (!i) {
if (!s)
throw new Error("getDocument - no `url` parameter provided.");
const wc = Ja(s) ? Kg : re ? am : em;
yc = new wc({
url: s,
length: bt,
httpHeaders: r,
withCredentials: a,
rangeChunkSize: h,
disableRange: Jt,
disableStream: N
});
}
return Vp.then((wc) => {
if (t.destroyed)
throw new Error("Loading aborted");
if (c.destroyed)
throw new Error("Worker was destroyed");
const cu = new io(e, wc, c.port), Wp = new pm(cu, t, yc, jp, gt);
t._transport = Wp, cu.send("Ready", null);
});
}).catch(t._capability.reject), t;
}
var ic;
const nc = class nc {
constructor() {
R(this, "_capability", Promise.withResolvers());
R(this, "_transport", null);
R(this, "_worker", null);
R(this, "docId", `d${Zt(nc, ic)._++}`);
R(this, "destroyed", !1);
R(this, "onPassword", null);
R(this, "onProgress", null);
}
get promise() {
return this._capability.promise;
}
async destroy() {
var t, e, s, i;
this.destroyed = !0;
try {
(t = this._worker) != null && t.port && (this._worker._pendingDestroy = !0), await ((e = this._transport) == null ? void 0 : e.destroy());
} catch (r) {
throw (s = this._worker) != null && s.port && delete this._worker._pendingDestroy, r;
}
this._transport = null, (i = this._worker) == null || i.destroy(), this._worker = null;
}
async getData() {
return this._transport.getData();
}
};
ic = new WeakMap(), m(nc, ic, 0);
let hd = nc;
var jn, cl, dl, ul, fl;
class $f {
constructor(t, e, s = !1, i = null) {
m(this, jn, Promise.withResolvers());
m(this, cl, []);
m(this, dl, []);
m(this, ul, []);
m(this, fl, []);
this.length = t, this.initialData = e, this.progressiveDone = s, this.contentDispositionFilename = i;
}
addRangeListener(t) {
n(this, fl).push(t);
}
addProgressListener(t) {
n(this, ul).push(t);
}
addProgressiveReadListener(t) {
n(this, dl).push(t);
}
addProgressiveDoneListener(t) {
n(this, cl).push(t);
}
onDataRange(t, e) {
for (const s of n(this, fl))
s(t, e);
}
onDataProgress(t, e) {
n(this, jn).promise.then(() => {
for (const s of n(this, ul))
s(t, e);
});
}
onDataProgressiveRead(t) {
n(this, jn).promise.then(() => {
for (const e of n(this, dl))
e(t);
});
}
onDataProgressiveDone() {
n(this, jn).promise.then(() => {
for (const t of n(this, cl))
t();
});
}
transportReady() {
n(this, jn).resolve();
}
requestDataRange(t, e) {
rt("Abstract method PDFDataRangeTransport.requestDataRange");
}
abort() {
}
}
jn = new WeakMap(), cl = new WeakMap(), dl = new WeakMap(), ul = new WeakMap(), fl = new WeakMap();
class um {
constructor(t, e) {
this._pdfInfo = t, this._transport = e;
}
get annotationStorage() {
return this._transport.annotationStorage;
}
get canvasFactory() {
return this._transport.canvasFactory;
}
get filterFactory() {
return this._transport.filterFactory;
}
get numPages() {
return this._pdfInfo.numPages;
}
get fingerprints() {
return this._pdfInfo.fingerprints;
}
get isPureXfa() {
return X(this, "isPureXfa", !!this._transport._htmlForXfa);
}
get allXfaHtml() {
return this._transport._htmlForXfa;
}
getPage(t) {
return this._transport.getPage(t);
}
getPageIndex(t) {
return this._transport.getPageIndex(t);
}
getDestinations() {
return this._transport.getDestinations();
}
getDestination(t) {
return this._transport.getDestination(t);
}
getPageLabels() {
return this._transport.getPageLabels();
}
getPageLayout() {
return this._transport.getPageLayout();
}
getPageMode() {
return this._transport.getPageMode();
}
getViewerPreferences() {
return this._transport.getViewerPreferences();
}
getOpenAction() {
return this._transport.getOpenAction();
}
getAttachments() {
return this._transport.getAttachments();
}
getJSActions() {
return this._transport.getDocJSActions();
}
getOutline() {
return this._transport.getOutline();
}
getOptionalContentConfig({
intent: t = "display"
} = {}) {
const {
renderingIntent: e
} = this._transport.getRenderingIntent(t);
return this._transport.getOptionalContentConfig(e);
}
getPermissions() {
return this._transport.getPermissions();
}
getMetadata() {
return this._transport.getMetadata();
}
getMarkInfo() {
return this._transport.getMarkInfo();
}
getData() {
return this._transport.getData();
}
saveDocument() {
return this._transport.saveDocument();
}
getDownloadInfo() {
return this._transport.downloadInfoCapability.promise;
}
cleanup(t = !1) {
return this._transport.startCleanup(t || this.isPureXfa);
}
destroy() {
return this.loadingTask.destroy();
}
cachedPageNumber(t) {
return this._transport.cachedPageNumber(t);
}
get loadingParams() {
return this._transport.loadingParams;
}
get loadingTask() {
return this._transport.loadingTask;
}
getFieldObjects() {
return this._transport.getFieldObjects();
}
hasJSActions() {
return this._transport.hasJSActions();
}
getCalculationOrderIds() {
return this._transport.getCalculationOrderIds();
}
}
var Ks, Vn, lo;
class fm {
constructor(t, e, s, i = !1) {
m(this, Vn);
m(this, Ks, !1);
this._pageIndex = t, this._pageInfo = e, this._transport = s, this._stats = i ? new pu() : null, this._pdfBug = i, this.commonObjs = s.commonObjs, this.objs = new Ff(), this._intentStates = /* @__PURE__ */ new Map(), this.destroyed = !1;
}
get pageNumber() {
return this._pageIndex + 1;
}
get rotate() {
return this._pageInfo.rotate;
}
get ref() {
return this._pageInfo.ref;
}
get userUnit() {
return this._pageInfo.userUnit;
}
get view() {
return this._pageInfo.view;
}
getViewport({
scale: t,
rotation: e = this.rotate,
offsetX: s = 0,
offsetY: i = 0,
dontFlip: r = !1
} = {}) {
return new Ql({
viewBox: this.view,
userUnit: this.userUnit,
scale: t,
rotation: e,
offsetX: s,
offsetY: i,
dontFlip: r
});
}
getAnnotations({
intent: t = "display"
} = {}) {
const {
renderingIntent: e
} = this._transport.getRenderingIntent(t);
return this._transport.getAnnotations(this._pageIndex, e);
}
getJSActions() {
return this._transport.getPageJSActions(this._pageIndex);
}
get filterFactory() {
return this._transport.filterFactory;
}
get isPureXfa() {
return X(this, "isPureXfa", !!this._transport._htmlForXfa);
}
async getXfa() {
var t;
return ((t = this._transport._htmlForXfa) == null ? void 0 : t.children[this._pageIndex]) || null;
}
render({
canvasContext: t,
viewport: e,
intent: s = "display",
annotationMode: i = vi.ENABLE,
transform: r = null,
background: a = null,
optionalContentConfigPromise: o = null,
annotationCanvasMap: l = null,
pageColors: h = null,
printAnnotationStorage: c = null,
isEditing: u = !1
}) {
var E, C;
(E = this._stats) == null || E.time("Overall");
const p = this._transport.getRenderingIntent(s, i, c, u), {
renderingIntent: g,
cacheKey: A
} = p;
f(this, Ks, !1), o || (o = this._transport.getOptionalContentConfig(g));
let y = this._intentStates.get(A);
y || (y = /* @__PURE__ */ Object.create(null), this._intentStates.set(A, y)), y.streamReaderCancelTimeout && (clearTimeout(y.streamReaderCancelTimeout), y.streamReaderCancelTimeout = null);
const w = !!(g & Me.PRINT);
y.displayReadyCapability || (y.displayReadyCapability = Promise.withResolvers(), y.operatorList = {
fnArray: [],
argsArray: [],
lastChunk: !1,
separateAnnots: null
}, (C = this._stats) == null || C.time("Page Request"), this._pumpOperatorList(p));
const v = (x) => {
var T;
y.renderTasks.delete(S), w && f(this, Ks, !0), b(this, Vn, lo).call(this), x ? (S.capability.reject(x), this._abortOperatorList({
intentState: y,
reason: x instanceof Error ? x : new Error(x)
})) : S.capability.resolve(), this._stats && (this._stats.timeEnd("Rendering"), this._stats.timeEnd("Overall"), (T = globalThis.Stats) != null && T.enabled && globalThis.Stats.add(this.pageNumber, this._stats));
}, S = new cd({
callback: v,
params: {
canvasContext: t,
viewport: e,
transform: r,
background: a
},
objs: this.objs,
commonObjs: this.commonObjs,
annotationCanvasMap: l,
operatorList: y.operatorList,
pageIndex: this._pageIndex,
canvasFactory: this._transport.canvasFactory,
filterFactory: this._transport.filterFactory,
useRequestAnimationFrame: !w,
pdfBug: this._pdfBug,
pageColors: h
});
(y.renderTasks || (y.renderTasks = /* @__PURE__ */ new Set())).add(S);
const _ = S.task;
return Promise.all([y.displayReadyCapability.promise, o]).then(([x, T]) => {
var P;
if (this.destroyed) {
v();
return;
}
if ((P = this._stats) == null || P.time("Rendering"), !(T.renderingIntent & g))
throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");
S.initializeGraphics({
transparency: x,
optionalContentConfig: T
}), S.operatorListChanged();
}).catch(v), _;
}
getOperatorList({
intent: t = "display",
annotationMode: e = vi.ENABLE,
printAnnotationStorage: s = null,
isEditing: i = !1
} = {}) {
var h;
function r() {
o.operatorList.lastChunk && (o.opListReadCapability.resolve(o.operatorList), o.renderTasks.delete(l));
}
const a = this._transport.getRenderingIntent(t, e, s, i, !0);
let o = this._intentStates.get(a.cacheKey);
o || (o = /* @__PURE__ */ Object.create(null), this._intentStates.set(a.cacheKey, o));
let l;
return o.opListReadCapability || (l = /* @__PURE__ */ Object.create(null), l.operatorListChanged = r, o.opListReadCapability = Promise.withResolvers(), (o.renderTasks || (o.renderTasks = /* @__PURE__ */ new Set())).add(l), o.operatorList = {
fnArray: [],
argsArray: [],
lastChunk: !1,
separateAnnots: null
}, (h = this._stats) == null || h.time("Page Request"), this._pumpOperatorList(a)), o.opListReadCapability.promise;
}
streamTextContent({
includeMarkedContent: t = !1,
disableNormalization: e = !1
} = {}) {
return this._transport.messageHandler.sendWithStream("GetTextContent", {
pageIndex: this._pageIndex,
includeMarkedContent: t === !0,
disableNormalization: e === !0
}, {
highWaterMark: 100,
size(i) {
return i.items.length;
}
});
}
getTextContent(t = {}) {
if (this._transport._htmlForXfa)
return this.getXfa().then((s) => yo.textContent(s));
const e = this.streamTextContent(t);
return new Promise(function(s, i) {
function r() {
a.read().then(function({
value: l,
done: h
}) {
if (h) {
s(o);
return;
}
o.lang ?? (o.lang = l.lang), Object.assign(o.styles, l.styles), o.items.push(...l.items), r();
}, i);
}
const a = e.getReader(), o = {
items: [],
styles: /* @__PURE__ */ Object.create(null),
lang: null
};
r();
});
}
getStructTree() {
return this._transport.getStructTree(this._pageIndex);
}
_destroy() {
this.destroyed = !0;
const t = [];
for (const e of this._intentStates.values())
if (this._abortOperatorList({
intentState: e,
reason: new Error("Page was destroyed."),
force: !0
}), !e.opListReadCapability)
for (const s of e.renderTasks)
t.push(s.completed), s.cancel();
return this.objs.clear(), f(this, Ks, !1), Promise.all(t);
}
cleanup(t = !1) {
f(this, Ks, !0);
const e = b(this, Vn, lo).call(this);
return t && e && this._stats && (this._stats = new pu()), e;
}
_startRenderPage(t, e) {
var i, r;
const s = this._intentStates.get(e);
s && ((i = this._stats) == null || i.timeEnd("Page Request"), (r = s.displayReadyCapability) == null || r.resolve(t));
}
_renderPageChunk(t, e) {
for (let s = 0, i = t.length; s < i; s++)
e.operatorList.fnArray.push(t.fnArray[s]), e.operatorList.argsArray.push(t.argsArray[s]);
e.operatorList.lastChunk = t.lastChunk, e.operatorList.separateAnnots = t.separateAnnots;
for (const s of e.renderTasks)
s.operatorListChanged();
t.lastChunk && b(this, Vn, lo).call(this);
}
_pumpOperatorList({
renderingIntent: t,
cacheKey: e,
annotationStorageSerializable: s,
modifiedIds: i
}) {
const {
map: r,
transfer: a
} = s, l = this._transport.messageHandler.sendWithStream("GetOperatorList", {
pageIndex: this._pageIndex,
intent: t,
cacheKey: e,
annotationStorage: r,
modifiedIds: i
}, a).getReader(), h = this._intentStates.get(e);
h.streamReader = l;
const c = () => {
l.read().then(({
value: u,
done: p
}) => {
if (p) {
h.streamReader = null;
return;
}
this._transport.destroyed || (this._renderPageChunk(u, h), c());
}, (u) => {
if (h.streamReader = null, !this._transport.destroyed) {
if (h.operatorList) {
h.operatorList.lastChunk = !0;
for (const p of h.renderTasks)
p.operatorListChanged();
b(this, Vn, lo).call(this);
}
if (h.displayReadyCapability)
h.displayReadyCapability.reject(u);
else if (h.opListReadCapability)
h.opListReadCapability.reject(u);
else
throw u;
}
});
};
c();
}
_abortOperatorList({
intentState: t,
reason: e,
force: s = !1
}) {
if (t.streamReader) {
if (t.streamReaderCancelTimeout && (clearTimeout(t.streamReaderCancelTimeout), t.streamReaderCancelTimeout = null), !s) {
if (t.renderTasks.size > 0)
return;
if (e instanceof Yd) {
let i = cm;
e.extraDelay > 0 && e.extraDelay < 1e3 && (i += e.extraDelay), t.streamReaderCancelTimeout = setTimeout(() => {
t.streamReaderCancelTimeout = null, this._abortOperatorList({
intentState: t,
reason: e,
force: !0
});
}, i);
return;
}
}
if (t.streamReader.cancel(new an(e.message)).catch(() => {
}), t.streamReader = null, !this._transport.destroyed) {
for (const [i, r] of this._intentStates)
if (r === t) {
this._intentStates.delete(i);
break;
}
this.cleanup();
}
}
}
get stats() {
return this._stats;
}
}
Ks = new WeakMap(), Vn = new WeakSet(), lo = function() {
if (!n(this, Ks) || this.destroyed)
return !1;
for (const {
renderTasks: t,
operatorList: e
} of this._intentStates.values())
if (t.size > 0 || !e.lastChunk)
return !1;
return this._intentStates.clear(), this.objs.clear(), f(this, Ks, !1), !0;
};
var Gi, Ke, Qs, Wn, rc, qn, Xn, le, wh, Gf, zf, ho, ma, vh;
const ht = class ht {
constructor({
name: t = null,
port: e = null,
verbosity: s = Jp()
} = {}) {
m(this, le);
m(this, Gi, Promise.withResolvers());
m(this, Ke, null);
m(this, Qs, null);
m(this, Wn, null);
if (this.name = t, this.destroyed = !1, this.verbosity = s, e) {
if (n(ht, Xn).has(e))
throw new Error("Cannot use more than one PDFWorker per port.");
n(ht, Xn).set(e, this), b(this, le, Gf).call(this, e);
} else
b(this, le, zf).call(this);
}
get promise() {
return n(this, Gi).promise;
}
get port() {
return n(this, Qs);
}
get messageHandler() {
return n(this, Ke);
}
destroy() {
var t, e;
this.destroyed = !0, (t = n(this, Wn)) == null || t.terminate(), f(this, Wn, null), n(ht, Xn).delete(n(this, Qs)), f(this, Qs, null), (e = n(this, Ke)) == null || e.destroy(), f(this, Ke, null);
}
static create(t) {
const e = n(this, Xn).get(t == null ? void 0 : t.port);
if (e) {
if (e._pendingDestroy)
throw new Error("PDFWorker.create - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");
return e;
}
return new ht(t);
}
static get workerSrc() {
if (fi.workerSrc)
return fi.workerSrc;
throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
}
static get _setupFakeWorkerGlobal() {
return X(this, "_setupFakeWorkerGlobal", (async () => n(this, ma, vh) ? n(this, ma, vh) : (await import(
/*webpackIgnore: true*/
/*@vite-ignore*/
this.workerSrc
)).WorkerMessageHandler)());
}
};
Gi = new WeakMap(), Ke = new WeakMap(), Qs = new WeakMap(), Wn = new WeakMap(), rc = new WeakMap(), qn = new WeakMap(), Xn = new WeakMap(), le = new WeakSet(), wh = function() {
n(this, Gi).resolve(), n(this, Ke).send("configure", {
verbosity: this.verbosity
});
}, Gf = function(t) {
f(this, Qs, t), f(this, Ke, new io("main", "worker", t)), n(this, Ke).on("ready", () => {
}), b(this, le, wh).call(this);
}, zf = function() {
if (n(ht, qn) || n(ht, ma, vh)) {
b(this, le, ho).call(this);
return;
}
let {
workerSrc: t
} = ht;
try {
ht._isSameOrigin(window.location, t) || (t = ht._createCDNWrapper(new URL(t, window.location).href));
const e = new Worker(t, {
type: "module"
}), s = new io("main", "worker", e), i = () => {
r.abort(), s.destroy(), e.terminate(), this.destroyed ? n(this, Gi).reject(new Error("Worker was destroyed")) : b(this, le, ho).call(this);
}, r = new AbortController();
e.addEventListener("error", () => {
n(this, Wn) || i();
}, {
signal: r.signal
}), s.on("test", (o) => {
if (r.abort(), this.destroyed || !o) {
i();
return;
}
f(this, Ke, s), f(this, Qs, e), f(this, Wn, e), b(this, le, wh).call(this);
}), s.on("ready", (o) => {
if (r.abort(), this.destroyed) {
i();
return;
}
try {
a();
} catch {
b(this, le, ho).call(this);
}
});
const a = () => {
const o = new Uint8Array();
s.send("test", o, [o.buffer]);
};
a();
return;
} catch {
gc("The worker has been disabled.");
}
b(this, le, ho).call(this);
}, ho = function() {
n(ht, qn) || (U("Setting up fake worker."), f(ht, qn, !0)), ht._setupFakeWorkerGlobal.then((t) => {
if (this.destroyed) {
n(this, Gi).reject(new Error("Worker was destroyed"));
return;
}
const e = new Sg();
f(this, Qs, e);
const s = `fake${Zt(ht, rc)._++}`, i = new io(s + "_worker", s, e);
t.setup(i, e), f(this, Ke, new io(s, s + "_worker", e)), b(this, le, wh).call(this);
}).catch((t) => {
n(this, Gi).reject(new Error(`Setting up fake worker failed: "${t.message}".`));
});
}, ma = new WeakSet(), vh = function() {
var t;
try {
return ((t = globalThis.pdfjsWorker) == null ? void 0 : t.WorkerMessageHandler) || null;
} catch {
return null;
}
}, m(ht, ma), m(ht, rc, 0), m(ht, qn, !1), m(ht, Xn, /* @__PURE__ */ new WeakMap()), re && (f(ht, qn, !0), fi.workerSrc || (fi.workerSrc = "./pdf.worker.mjs")), ht._isSameOrigin = (t, e) => {
const s = URL.parse(t);
if (!(s != null && s.origin) || s.origin === "null")
return !1;
const i = new URL(e, s);
return s.origin === i.origin;
}, ht._createCDNWrapper = (t) => {
const e = `await import("${t}");`;
return URL.createObjectURL(new Blob([e], {
type: "text/javascript"
}));
}, ht.fromPort = (t) => {
if (cg("`PDFWorker.fromPort` - please use `PDFWorker.create` instead."), !(t != null && t.port))
throw new Error("PDFWorker.fromPort - invalid method signature.");
return ht.create(t);
};
let wo = ht;
var Js, ws, ba, Aa, Zs, Yn, co;
class pm {
constructor(t, e, s, i, r) {
m(this, Yn);
m(this, Js, /* @__PURE__ */ new Map());
m(this, ws, /* @__PURE__ */ new Map());
m(this, ba, /* @__PURE__ */ new Map());
m(this, Aa, /* @__PURE__ */ new Map());
m(this, Zs, null);
this.messageHandler = t, this.loadingTask = e, this.commonObjs = new Ff(), this.fontLoader = new bg({
ownerDocument: i.ownerDocument,
styleElement: i.styleElement
}), this.loadingParams = i.loadingParams, this._params = i, this.canvasFactory = r.canvasFactory, this.filterFactory = r.filterFactory, this.cMapReaderFactory = r.cMapReaderFactory, this.standardFontDataFactory = r.standardFontDataFactory, this.wasmFactory = r.wasmFactory, this.destroyed = !1, this.destroyCapability = null, this._networkStream = s, this._fullReader = null, this._lastProgress = null, this.downloadInfoCapability = Promise.withResolvers(), this.setupMessageHandler();
}
get annotationStorage() {
return X(this, "annotationStorage", new Zd());
}
getRenderingIntent(t, e = vi.ENABLE, s = null, i = !1, r = !1) {
let a = Me.DISPLAY, o = Kc;
switch (t) {
case "any":
a = Me.ANY;
break;
case "display":
break;
case "print":
a = Me.PRINT;
break;
default:
U(`getRenderingIntent - invalid intent: ${t}`);
}
const l = a & Me.PRINT && s instanceof yf ? s : this.annotationStorage;
switch (e) {
case vi.DISABLE:
a += Me.ANNOTATIONS_DISABLE;
break;
case vi.ENABLE:
break;
case vi.ENABLE_FORMS:
a += Me.ANNOTATIONS_FORMS;
break;
case vi.ENABLE_STORAGE:
a += Me.ANNOTATIONS_STORAGE, o = l.serializable;
break;
default:
U(`getRenderingIntent - invalid annotationMode: ${e}`);
}
i && (a += Me.IS_EDITING), r && (a += Me.OPLIST);
const {
ids: h,
hash: c
} = l.modifiedIds, u = [a, o.hash, c];
return {
renderingIntent: a,
cacheKey: u.join("_"),
annotationStorageSerializable: o,
modifiedIds: h
};
}
destroy() {
var s;
if (this.destroyCapability)
return this.destroyCapability.promise;
this.destroyed = !0, this.destroyCapability = Promise.withResolvers(), (s = n(this, Zs)) == null || s.reject(new Error("Worker was destroyed during onPassword callback"));
const t = [];
for (const i of n(this, ws).values())
t.push(i._destroy());
n(this, ws).clear(), n(this, ba).clear(), n(this, Aa).clear(), this.hasOwnProperty("annotationStorage") && this.annotationStorage.resetModified();
const e = this.messageHandler.sendWithPromise("Terminate", null);
return t.push(e), Promise.all(t).then(() => {
var i, r;
this.commonObjs.clear(), this.fontLoader.clear(), n(this, Js).clear(), this.filterFactory.destroy(), Ao.cleanup(), (i = this._networkStream) == null || i.cancelAllRequests(new an("Worker was terminated.")), (r = this.messageHandler) == null || r.destroy(), this.messageHandler = null, this.destroyCapability.resolve();
}, this.destroyCapability.reject), this.destroyCapability.promise;
}
setupMessageHandler() {
const {
messageHandler: t,
loadingTask: e
} = this;
t.on("GetReader", (s, i) => {
Et(this._networkStream, "GetReader - no `IPDFStream` instance available."), this._fullReader = this._networkStream.getFullReader(), this._fullReader.onProgress = (r) => {
this._lastProgress = {
loaded: r.loaded,
total: r.total
};
}, i.onPull = () => {
this._fullReader.read().then(function({
value: r,
done: a
}) {
if (a) {
i.close();
return;
}
Et(r instanceof ArrayBuffer, "GetReader - expected an ArrayBuffer."), i.enqueue(new Uint8Array(r), 1, [r]);
}).catch((r) => {
i.error(r);
});
}, i.onCancel = (r) => {
this._fullReader.cancel(r), i.ready.catch((a) => {
if (!this.destroyed)
throw a;
});
};
}), t.on("ReaderHeadersReady", async (s) => {
var o;
await this._fullReader.headersReady;
const {
isStreamingSupported: i,
isRangeSupported: r,
contentLength: a
} = this._fullReader;
return (!i || !r) && (this._lastProgress && ((o = e.onProgress) == null || o.call(e, this._lastProgress)), this._fullReader.onProgress = (l) => {
var h;
(h = e.onProgress) == null || h.call(e, {
loaded: l.loaded,
total: l.total
});
}), {
isStreamingSupported: i,
isRangeSupported: r,
contentLength: a
};
}), t.on("GetRangeReader", (s, i) => {
Et(this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
const r = this._networkStream.getRangeReader(s.begin, s.end);
if (!r) {
i.close();
return;
}
i.onPull = () => {
r.read().then(function({
value: a,
done: o
}) {
if (o) {
i.close();
return;
}
Et(a instanceof ArrayBuffer, "GetRangeReader - expected an ArrayBuffer."), i.enqueue(new Uint8Array(a), 1, [a]);
}).catch((a) => {
i.error(a);
});
}, i.onCancel = (a) => {
r.cancel(a), i.ready.catch((o) => {
if (!this.destroyed)
throw o;
});
};
}), t.on("GetDoc", ({
pdfInfo: s
}) => {
this._numPages = s.numPages, this._htmlForXfa = s.htmlForXfa, delete s.htmlForXfa, e._capability.resolve(new um(s, this));
}), t.on("DocException", (s) => {
e._capability.reject(ce(s));
}), t.on("PasswordRequest", (s) => {
f(this, Zs, Promise.withResolvers());
try {
if (!e.onPassword)
throw ce(s);
const i = (r) => {
r instanceof Error ? n(this, Zs).reject(r) : n(this, Zs).resolve({
password: r
});
};
e.onPassword(i, s.code);
} catch (i) {
n(this, Zs).reject(i);
}
return n(this, Zs).promise;
}), t.on("DataLoaded", (s) => {
var i;
(i = e.onProgress) == null || i.call(e, {
loaded: s.length,
total: s.length
}), this.downloadInfoCapability.resolve(s);
}), t.on("StartRenderPage", (s) => {
if (this.destroyed)
return;
n(this, ws).get(s.pageIndex)._startRenderPage(s.transparency, s.cacheKey);
}), t.on("commonobj", ([s, i, r]) => {
var a;
if (this.destroyed || this.commonObjs.has(s))
return null;
switch (i) {
case "Font":
if ("error" in r) {
const c = r.error;
U(`Error during font loading: ${c}`), this.commonObjs.resolve(s, c);
break;
}
const o = this._params.pdfBug && ((a = globalThis.FontInspector) != null && a.enabled) ? (c, u) => globalThis.FontInspector.fontAdded(c, u) : null, l = new Ag(r, o);
this.fontLoader.bind(l).catch(() => t.sendWithPromise("FontFallback", {
id: s
})).finally(() => {
!l.fontExtraProperties && l.data && (l.data = null), this.commonObjs.resolve(s, l);
});
break;
case "CopyLocalImage":
const {
imageRef: h
} = r;
Et(h, "The imageRef must be defined.");
for (const c of n(this, ws).values())
for (const [, u] of c.objs)
if ((u == null ? void 0 : u.ref) === h)
return u.dataLen ? (this.commonObjs.resolve(s, structuredClone(u)), u.dataLen) : null;
break;
case "FontPath":
case "Image":
case "Pattern":
this.commonObjs.resolve(s, r);
break;
default:
throw new Error(`Got unknown common object type ${i}`);
}
return null;
}), t.on("obj", ([s, i, r, a]) => {
var l;
if (this.destroyed)
return;
const o = n(this, ws).get(i);
if (!o.objs.has(s)) {
if (o._intentStates.size === 0) {
(l = a == null ? void 0 : a.bitmap) == null || l.close();
return;
}
switch (r) {
case "Image":
case "Pattern":
o.objs.resolve(s, a);
break;
default:
throw new Error(`Got unknown object type ${r}`);
}
}
}), t.on("DocProgress", (s) => {
var i;
this.destroyed || (i = e.onProgress) == null || i.call(e, {
loaded: s.loaded,
total: s.total
});
}), t.on("FetchBinaryData", async (s) => {
if (this.destroyed)
throw new Error("Worker was destroyed.");
const i = this[s.type];
if (!i)
throw new Error(`${s.type} not initialized, see the \`useWorkerFetch\` parameter.`);
return i.fetch(s);
});
}
getData() {
return this.messageHandler.sendWithPromise("GetData", null);
}
saveDocument() {
var s;
this.annotationStorage.size <= 0 && U("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");
const {
map: t,
transfer: e
} = this.annotationStorage.serializable;
return this.messageHandler.sendWithPromise("SaveDocument", {
isPureXfa: !!this._htmlForXfa,
numPages: this._numPages,
annotationStorage: t,
filename: ((s = this._fullReader) == null ? void 0 : s.filename) ?? null
}, e).finally(() => {
this.annotationStorage.resetModified();
});
}
getPage(t) {
if (!Number.isInteger(t) || t <= 0 || t > this._numPages)
return Promise.reject(new Error("Invalid page request."));
const e = t - 1, s = n(this, ba).get(e);
if (s)
return s;
const i = this.messageHandler.sendWithPromise("GetPage", {
pageIndex: e
}).then((r) => {
if (this.destroyed)
throw new Error("Transport destroyed");
r.refStr && n(this, Aa).set(r.refStr, t);
const a = new fm(e, r, this, this._params.pdfBug);
return n(this, ws).set(e, a), a;
});
return n(this, ba).set(e, i), i;
}
getPageIndex(t) {
return Qc(t) ? this.messageHandler.sendWithPromise("GetPageIndex", {
num: t.num,
gen: t.gen
}) : Promise.reject(new Error("Invalid pageIndex request."));
}
getAnnotations(t, e) {
return this.messageHandler.sendWithPromise("GetAnnotations", {
pageIndex: t,
intent: e
});
}
getFieldObjects() {
return b(this, Yn, co).call(this, "GetFieldObjects");
}
hasJSActions() {
return b(this, Yn, co).call(this, "HasJSActions");
}
getCalculationOrderIds() {
return this.messageHandler.sendWithPromise("GetCalculationOrderIds", null);
}
getDestinations() {
return this.messageHandler.sendWithPromise("GetDestinations", null);
}
getDestination(t) {
return typeof t != "string" ? Promise.reject(new Error("Invalid destination request.")) : this.messageHandler.sendWithPromise("GetDestination", {
id: t
});
}
getPageLabels() {
return this.messageHandler.sendWithPromise("GetPageLabels", null);
}
getPageLayout() {
return this.messageHandler.sendWithPromise("GetPageLayout", null);
}
getPageMode() {
return this.messageHandler.sendWithPromise("GetPageMode", null);
}
getViewerPreferences() {
return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
}
getOpenAction() {
return this.messageHandler.sendWithPromise("GetOpenAction", null);
}
getAttachments() {
return this.messageHandler.sendWithPromise("GetAttachments", null);
}
getDocJSActions() {
return b(this, Yn, co).call(this, "GetDocJSActions");
}
getPageJSActions(t) {
return this.messageHandler.sendWithPromise("GetPageJSActions", {
pageIndex: t
});
}
getStructTree(t) {
return this.messageHandler.sendWithPromise("GetStructTree", {
pageIndex: t
});
}
getOutline() {
return this.messageHandler.sendWithPromise("GetOutline", null);
}
getOptionalContentConfig(t) {
return b(this, Yn, co).call(this, "GetOptionalContentConfig").then((e) => new Vg(e, t));
}
getPermissions() {
return this.messageHandler.sendWithPromise("GetPermissions", null);
}
getMetadata() {
const t = "GetMetadata", e = n(this, Js).get(t);
if (e)
return e;
const s = this.messageHandler.sendWithPromise(t, null).then((i) => {
var r, a;
return {
info: i[0],
metadata: i[1] ? new Ug(i[1]) : null,
contentDispositionFilename: ((r = this._fullReader) == null ? void 0 : r.filename) ?? null,
contentLength: ((a = this._fullReader) == null ? void 0 : a.contentLength) ?? null
};
});
return n(this, Js).set(t, s), s;
}
getMarkInfo() {
return this.messageHandler.sendWithPromise("GetMarkInfo", null);
}
async startCleanup(t = !1) {
if (!this.destroyed) {
await this.messageHandler.sendWithPromise("Cleanup", null);
for (const e of n(this, ws).values())
if (!e.cleanup())
throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);
this.commonObjs.clear(), t || this.fontLoader.clear(), n(this, Js).clear(), this.filterFactory.destroy(!0), Ao.cleanup();
}
}
cachedPageNumber(t) {
if (!Qc(t))
return null;
const e = t.gen === 0 ? `${t.num}R` : `${t.num}R${t.gen}`;
return n(this, Aa).get(e) ?? null;
}
}
Js = new WeakMap(), ws = new WeakMap(), ba = new WeakMap(), Aa = new WeakMap(), Zs = new WeakMap(), Yn = new WeakSet(), co = function(t, e = null) {
const s = n(this, Js).get(t);
if (s)
return s;
const i = this.messageHandler.sendWithPromise(t, e);
return n(this, Js).set(t, i), i;
};
var zi;
class gm {
constructor(t) {
m(this, zi, null);
R(this, "onContinue", null);
R(this, "onError", null);
f(this, zi, t);
}
get promise() {
return n(this, zi).capability.promise;
}
cancel(t = 0) {
n(this, zi).cancel(null, t);
}
get separateAnnots() {
const {
separateAnnots: t
} = n(this, zi).operatorList;
if (!t)
return !1;
const {
annotationCanvasMap: e
} = n(this, zi);
return t.form || t.canvas && (e == null ? void 0 : e.size) > 0;
}
}
zi = new WeakMap();
var Ui, Kn;
const mn = class mn {
constructor({
callback: t,
params: e,
objs: s,
commonObjs: i,
annotationCanvasMap: r,
operatorList: a,
pageIndex: o,
canvasFactory: l,
filterFactory: h,
useRequestAnimationFrame: c = !1,
pdfBug: u = !1,
pageColors: p = null
}) {
m(this, Ui, null);
this.callback = t, this.params = e, this.objs = s, this.commonObjs = i, this.annotationCanvasMap = r, this.operatorListIdx = null, this.operatorList = a, this._pageIndex = o, this.canvasFactory = l, this.filterFactory = h, this._pdfBug = u, this.pageColors = p, this.running = !1, this.graphicsReadyCallback = null, this.graphicsReady = !1, this._useRequestAnimationFrame = c === !0 && typeof window < "u", this.cancelled = !1, this.capability = Promise.withResolvers(), this.task = new gm(this), this._cancelBound = this.cancel.bind(this), this._continueBound = this._continue.bind(this), this._scheduleNextBound = this._scheduleNext.bind(this), this._nextBound = this._next.bind(this), this._canvas = e.canvasContext.canvas;
}
get completed() {
return this.capability.promise.catch(function() {
});
}
initializeGraphics({
transparency: t = !1,
optionalContentConfig: e
}) {
var o, l;
if (this.cancelled)
return;
if (this._canvas) {
if (n(mn, Kn).has(this._canvas))
throw new Error("Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed.");
n(mn, Kn).add(this._canvas);
}
this._pdfBug && ((o = globalThis.StepperManager) != null && o.enabled) && (this.stepper = globalThis.StepperManager.create(this._pageIndex), this.stepper.init(this.operatorList), this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint());
const {
canvasContext: s,
viewport: i,
transform: r,
background: a
} = this.params;
this.gfx = new Gr(s, this.commonObjs, this.objs, this.canvasFactory, this.filterFactory, {
optionalContentConfig: e
}, this.annotationCanvasMap, this.pageColors), this.gfx.beginDrawing({
transform: r,
viewport: i,
transparency: t,
background: a
}), this.operatorListIdx = 0, this.graphicsReady = !0, (l = this.graphicsReadyCallback) == null || l.call(this);
}
cancel(t = null, e = 0) {
var s, i, r;
this.running = !1, this.cancelled = !0, (s = this.gfx) == null || s.endDrawing(), n(this, Ui) && (window.cancelAnimationFrame(n(this, Ui)), f(this, Ui, null)), n(mn, Kn).delete(this._canvas), t || (t = new Yd(`Rendering cancelled, page ${this._pageIndex + 1}`, e)), this.callback(t), (r = (i = this.task).onError) == null || r.call(i, t);
}
operatorListChanged() {
var t;
if (!this.graphicsReady) {
this.graphicsReadyCallback || (this.graphicsReadyCallback = this._continueBound);
return;
}
(t = this.stepper) == null || t.updateOperatorList(this.operatorList), !this.running && this._continue();
}
_continue() {
this.running = !0, !this.cancelled && (this.task.onContinue ? this.task.onContinue(this._scheduleNextBound) : this._scheduleNext());
}
_scheduleNext() {
this._useRequestAnimationFrame ? f(this, Ui, window.requestAnimationFrame(() => {
f(this, Ui, null), this._nextBound().catch(this._cancelBound);
})) : Promise.resolve().then(this._nextBound).catch(this._cancelBound);
}
async _next() {
this.cancelled || (this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper), this.operatorListIdx === this.operatorList.argsArray.length && (this.running = !1, this.operatorList.lastChunk && (this.gfx.endDrawing(), n(mn, Kn).delete(this._canvas), this.callback())));
}
};
Ui = new WeakMap(), Kn = new WeakMap(), m(mn, Kn, /* @__PURE__ */ new WeakSet());
let cd = mn;
const mm = "5.3.93", bm = "cbeef3233";
function Iu(d) {
return Math.floor(Math.max(0, Math.min(1, d)) * 255).toString(16).padStart(2, "0");
}
function Ka(d) {
return Math.max(0, Math.min(255, 255 * d));
}
class Mu {
static CMYK_G([t, e, s, i]) {
return ["G", 1 - Math.min(1, 0.3 * t + 0.59 * s + 0.11 * e + i)];
}
static G_CMYK([t]) {
return ["CMYK", 0, 0, 0, 1 - t];
}
static G_RGB([t]) {
return ["RGB", t, t, t];
}
static G_rgb([t]) {
return t = Ka(t), [t, t, t];
}
static G_HTML([t]) {
const e = Iu(t);
return `#${e}${e}${e}`;
}
static RGB_G([t, e, s]) {
return ["G", 0.3 * t + 0.59 * e + 0.11 * s];
}
static RGB_rgb(t) {
return t.map(Ka);
}
static RGB_HTML(t) {
return `#${t.map(Iu).join("")}`;
}
static T_HTML() {
return "#00000000";
}
static T_rgb() {
return [null];
}
static CMYK_RGB([t, e, s, i]) {
return ["RGB", 1 - Math.min(1, t + i), 1 - Math.min(1, s + i), 1 - Math.min(1, e + i)];
}
static CMYK_rgb([t, e, s, i]) {
return [Ka(1 - Math.min(1, t + i)), Ka(1 - Math.min(1, s + i)), Ka(1 - Math.min(1, e + i))];
}
static CMYK_HTML(t) {
const e = this.CMYK_RGB(t).slice(1);
return this.RGB_HTML(e);
}
static RGB_CMYK([t, e, s]) {
const i = 1 - t, r = 1 - e, a = 1 - s, o = Math.min(i, r, a);
return ["CMYK", i, r, a, o];
}
}
class Am {
create(t, e, s = !1) {
if (t <= 0 || e <= 0)
throw new Error("Invalid SVG dimensions");
const i = this._createSVG("svg:svg");
return i.setAttribute("version", "1.1"), s || (i.setAttribute("width", `${t}px`), i.setAttribute("height", `${e}px`)), i.setAttribute("preserveAspectRatio", "none"), i.setAttribute("viewBox", `0 0 ${t} ${e}`), i;
}
createElement(t) {
if (typeof t != "string")
throw new Error("Invalid SVG element type");
return this._createSVG(t);
}
_createSVG(t) {
rt("Abstract method `_createSVG` called.");
}
}
class Uh extends Am {
_createSVG(t) {
return document.createElementNS(ks, t);
}
}
class Uf {
static setupStorage(t, e, s, i, r) {
const a = i.getValue(e, {
value: null
});
switch (s.name) {
case "textarea":
if (a.value !== null && (t.textContent = a.value), r === "print")
break;
t.addEventListener("input", (o) => {
i.setValue(e, {
value: o.target.value
});
});
break;
case "input":
if (s.attributes.type === "radio" || s.attributes.type === "checkbox") {
if (a.value === s.attributes.xfaOn ? t.setAttribute("checked", !0) : a.value === s.attributes.xfaOff && t.removeAttribute("checked"), r === "print")
break;
t.addEventListener("change", (o) => {
i.setValue(e, {
value: o.target.checked ? o.target.getAttribute("xfaOn") : o.target.getAttribute("xfaOff")
});
});
} else {
if (a.value !== null && t.setAttribute("value", a.value), r === "print")
break;
t.addEventListener("input", (o) => {
i.setValue(e, {
value: o.target.value
});
});
}
break;
case "select":
if (a.value !== null) {
t.setAttribute("value", a.value);
for (const o of s.children)
o.attributes.value === a.value ? o.attributes.selected = !0 : o.attributes.hasOwnProperty("selected") && delete o.attributes.selected;
}
t.addEventListener("input", (o) => {
const l = o.target.options, h = l.selectedIndex === -1 ? "" : l[l.selectedIndex].value;
i.setValue(e, {
value: h
});
});
break;
}
}
static setAttributes({
html: t,
element: e,
storage: s = null,
intent: i,
linkService: r
}) {
const {
attributes: a
} = e, o = t instanceof HTMLAnchorElement;
a.type === "radio" && (a.name = `${a.name}-${i}`);
for (const [l, h] of Object.entries(a))
if (h != null)
switch (l) {
case "class":
h.length && t.setAttribute(l, h.join(" "));
break;
case "dataId":
break;
case "id":
t.setAttribute("data-element-id", h);
break;
case "style":
Object.assign(t.style, h);
break;
case "textContent":
t.textContent = h;
break;
default:
(!o || l !== "href" && l !== "newWindow") && t.setAttribute(l, h);
}
o && r.addLinkAttributes(t, a.href, a.newWindow), s && a.dataId && this.setupStorage(t, a.dataId, e, s);
}
static render(t) {
var u, p;
const e = t.annotationStorage, s = t.linkService, i = t.xfaHtml, r = t.intent || "display", a = document.createElement(i.name);
i.attributes && this.setAttributes({
html: a,
element: i,
intent: r,
linkService: s
});
const o = r !== "richText", l = t.div;
if (l.append(a), t.viewport) {
const g = `matrix(${t.viewport.transform.join(",")})`;
l.style.transform = g;
}
o && l.setAttribute("class", "xfaLayer xfaFont");
const h = [];
if (i.children.length === 0) {
if (i.value) {
const g = document.createTextNode(i.value);
a.append(g), o && yo.shouldBuildText(i.name) && h.push(g);
}
return {
textDivs: h
};
}
const c = [[i, -1, a]];
for (; c.length > 0; ) {
const [g, A, y] = c.at(-1);
if (A + 1 === g.children.length) {
c.pop();
continue;
}
const w = g.children[++c.at(-1)[1]];
if (w === null)
continue;
const {
name: v
} = w;
if (v === "#text") {
const _ = document.createTextNode(w.value);
h.push(_), y.append(_);
continue;
}
const S = (u = w == null ? void 0 : w.attributes) != null && u.xmlns ? document.createElementNS(w.attributes.xmlns, v) : document.createElement(v);
if (y.append(S), w.attributes && this.setAttributes({
html: S,
element: w,
storage: e,
intent: r,
linkService: s
}), ((p = w.children) == null ? void 0 : p.length) > 0)
c.push([w, -1, S]);
else if (w.value) {
const _ = document.createTextNode(w.value);
o && yo.shouldBuildText(v) && h.push(_), S.append(_);
}
}
for (const g of l.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))
g.setAttribute("readOnly", !0);
return {
textDivs: h
};
}
static update(t) {
const e = `matrix(${t.viewport.transform.join(",")})`;
t.div.style.transform = e, t.div.hidden = !1;
}
}
const ym = 9, Tr = /* @__PURE__ */ new WeakSet();
class ku {
static create(t) {
switch (t.data.annotationType) {
case _t.LINK:
return new jf(t);
case _t.TEXT:
return new wm(t);
case _t.WIDGET:
switch (t.data.fieldType) {
case "Tx":
return new vm(t);
case "Btn":
return t.data.radioButton ? new qf(t) : t.data.checkBox ? new Sm(t) : new Em(t);
case "Ch":
return new Cm(t);
case "Sig":
return new _m(t);
}
return new Pr(t);
case _t.POPUP:
return new ud(t);
case _t.FREETEXT:
return new Jf(t);
case _t.LINE:
return new Tm(t);
case _t.SQUARE:
return new Rm(t);
case _t.CIRCLE:
return new Pm(t);
case _t.POLYLINE:
return new Zf(t);
case _t.CARET:
return new Mm(t);
case _t.INK:
return new su(t);
case _t.POLYGON:
return new Im(t);
case _t.HIGHLIGHT:
return new tp(t);
case _t.UNDERLINE:
return new km(t);
case _t.SQUIGGLY:
return new Lm(t);
case _t.STRIKEOUT:
return new Dm(t);
case _t.STAMP:
return new ep(t);
case _t.FILEATTACHMENT:
return new Fm(t);
default:
return new wt(t);
}
}
}
var Qn, ya, wa, pl, dd;
const lu = class lu {
constructor(t, {
isRenderable: e = !1,
ignoreBorder: s = !1,
createQuadrilaterals: i = !1
} = {}) {
m(this, pl);
m(this, Qn, null);
m(this, ya, !1);
m(this, wa, null);
this.isRenderable = e, this.data = t.data, this.layer = t.layer, this.linkService = t.linkService, this.downloadManager = t.downloadManager, this.imageResourcesPath = t.imageResourcesPath, this.renderForms = t.renderForms, this.svgFactory = t.svgFactory, this.annotationStorage = t.annotationStorage, this.enableScripting = t.enableScripting, this.hasJSActions = t.hasJSActions, this._fieldObjects = t.fieldObjects, this.parent = t.parent, e && (this.container = this._createContainer(s)), i && this._createQuadrilaterals();
}
static _hasPopupData({
contentsObj: t,
richText: e
}) {
return !!(t != null && t.str || e != null && e.str);
}
get _isEditable() {
return this.data.isEditable;
}
get hasPopupData() {
return lu._hasPopupData(this.data);
}
updateEdited(t) {
var s;
if (!this.container)
return;
n(this, Qn) || f(this, Qn, {
rect: this.data.rect.slice(0)
});
const {
rect: e
} = t;
e && b(this, pl, dd).call(this, e), (s = n(this, wa)) == null || s.popup.updateEdited(t);
}
resetEdited() {
var t;
n(this, Qn) && (b(this, pl, dd).call(this, n(this, Qn).rect), (t = n(this, wa)) == null || t.popup.resetEdited(), f(this, Qn, null));
}
_createContainer(t) {
const {
data: e,
parent: {
page: s,
viewport: i
}
} = this, r = document.createElement("section");
r.setAttribute("data-annotation-id", e.id), this instanceof Pr || (r.tabIndex = 0);
const {
style: a
} = r;
if (a.zIndex = this.parent.zIndex++, e.alternativeText && (r.title = e.alternativeText), e.noRotate && r.classList.add("norotate"), !e.rect || this instanceof ud) {
const {
rotation: y
} = e;
return !e.hasOwnCanvas && y !== 0 && this.setRotation(y, r), r;
}
const {
width: o,
height: l
} = this;
if (!t && e.borderStyle.width > 0) {
a.borderWidth = `${e.borderStyle.width}px`;
const y = e.borderStyle.horizontalCornerRadius, w = e.borderStyle.verticalCornerRadius;
if (y > 0 || w > 0) {
const S = `calc(${y}px * var(--total-scale-factor)) / calc(${w}px * var(--total-scale-factor))`;
a.borderRadius = S;
} else if (this instanceof qf) {
const S = `calc(${o}px * var(--total-scale-factor)) / calc(${l}px * var(--total-scale-factor))`;
a.borderRadius = S;
}
switch (e.borderStyle.style) {
case Mr.SOLID:
a.borderStyle = "solid";
break;
case Mr.DASHED:
a.borderStyle = "dashed";
break;
case Mr.BEVELED:
U("Unimplemented border style: beveled");
break;
case Mr.INSET:
U("Unimplemented border style: inset");
break;
case Mr.UNDERLINE:
a.borderBottomStyle = "solid";
break;
}
const v = e.borderColor || null;
v ? (f(this, ya, !0), a.borderColor = $.makeHexColor(v[0] | 0, v[1] | 0, v[2] | 0)) : a.borderWidth = 0;
}
const h = $.normalizeRect([e.rect[0], s.view[3] - e.rect[1] + s.view[1], e.rect[2], s.view[3] - e.rect[3] + s.view[1]]), {
pageWidth: c,
pageHeight: u,
pageX: p,
pageY: g
} = i.rawDims;
a.left = `${100 * (h[0] - p) / c}%`, a.top = `${100 * (h[1] - g) / u}%`;
const {
rotation: A
} = e;
return e.hasOwnCanvas || A === 0 ? (a.width = `${100 * o / c}%`, a.height = `${100 * l / u}%`) : this.setRotation(A, r), r;
}
setRotation(t, e = this.container) {
if (!this.data.rect)
return;
const {
pageWidth: s,
pageHeight: i
} = this.parent.viewport.rawDims;
let {
width: r,
height: a
} = this;
t % 180 !== 0 && ([r, a] = [a, r]), e.style.width = `${100 * r / s}%`, e.style.height = `${100 * a / i}%`, e.setAttribute("data-main-rotation", (360 - t) % 360);
}
get _commonActions() {
const t = (e, s, i) => {
const r = i.detail[e], a = r[0], o = r.slice(1);
i.target.style[s] = Mu[`${a}_HTML`](o), this.annotationStorage.setValue(this.data.id, {
[s]: Mu[`${a}_rgb`](o)
});
};
return X(this, "_commonActions", {
display: (e) => {
const {
display: s
} = e.detail, i = s % 2 === 1;
this.container.style.visibility = i ? "hidden" : "visible", this.annotationStorage.setValue(this.data.id, {
noView: i,
noPrint: s === 1 || s === 2
});
},
print: (e) => {
this.annotationStorage.setValue(this.data.id, {
noPrint: !e.detail.print
});
},
hidden: (e) => {
const {
hidden: s
} = e.detail;
this.container.style.visibility = s ? "hidden" : "visible", this.annotationStorage.setValue(this.data.id, {
noPrint: s,
noView: s
});
},
focus: (e) => {
setTimeout(() => e.target.focus({
preventScroll: !1
}), 0);
},
userName: (e) => {
e.target.title = e.detail.userName;
},
readonly: (e) => {
e.target.disabled = e.detail.readonly;
},
required: (e) => {
this._setRequired(e.target, e.detail.required);
},
bgColor: (e) => {
t("bgColor", "backgroundColor", e);
},
fillColor: (e) => {
t("fillColor", "backgroundColor", e);
},
fgColor: (e) => {
t("fgColor", "color", e);
},
textColor: (e) => {
t("textColor", "color", e);
},
borderColor: (e) => {
t("borderColor", "borderColor", e);
},
strokeColor: (e) => {
t("strokeColor", "borderColor", e);
},
rotation: (e) => {
const s = e.detail.rotation;
this.setRotation(s), this.annotationStorage.setValue(this.data.id, {
rotation: s
});
}
});
}
_dispatchEventFromSandbox(t, e) {
const s = this._commonActions;
for (const i of Object.keys(e.detail)) {
const r = t[i] || s[i];
r == null || r(e);
}
}
_setDefaultPropertiesFromJS(t) {
if (!this.enableScripting)
return;
const e = this.annotationStorage.getRawValue(this.data.id);
if (!e)
return;
const s = this._commonActions;
for (const [i, r] of Object.entries(e)) {
const a = s[i];
if (a) {
const o = {
detail: {
[i]: r
},
target: t
};
a(o), delete e[i];
}
}
}
_createQuadrilaterals() {
if (!this.container)
return;
const {
quadPoints: t
} = this.data;
if (!t)
return;
const [e, s, i, r] = this.data.rect.map((y) => Math.fround(y));
if (t.length === 8) {
const [y, w, v, S] = t.subarray(2, 6);
if (i === y && r === w && e === v && s === S)
return;
}
const {
style: a
} = this.container;
let o;
if (n(this, ya)) {
const {
borderColor: y,
borderWidth: w
} = a;
a.borderWidth = 0, o = ["url('data:image/svg+xml;utf8,", '<svg xmlns="http://www.w3.org/2000/svg"', ' preserveAspectRatio="none" viewBox="0 0 1 1">', `<g fill="transparent" stroke="${y}" stroke-width="${w}">`], this.container.classList.add("hasBorder");
}
const l = i - e, h = r - s, {
svgFactory: c
} = this, u = c.createElement("svg");
u.classList.add("quadrilateralsContainer"), u.setAttribute("width", 0), u.setAttribute("height", 0), u.role = "none";
const p = c.createElement("defs");
u.append(p);
const g = c.createElement("clipPath"), A = `clippath_${this.data.id}`;
g.setAttribute("id", A), g.setAttribute("clipPathUnits", "objectBoundingBox"), p.append(g);
for (let y = 2, w = t.length; y < w; y += 8) {
const v = t[y], S = t[y + 1], _ = t[y + 2], E = t[y + 3], C = c.createElement("rect"), x = (_ - e) / l, T = (r - S) / h, P = (v - _) / l, M = (S - E) / h;
C.setAttribute("x", x), C.setAttribute("y", T), C.setAttribute("width", P), C.setAttribute("height", M), g.append(C), o == null || o.push(`<rect vector-effect="non-scaling-stroke" x="${x}" y="${T}" width="${P}" height="${M}"/>`);
}
n(this, ya) && (o.push("</g></svg>')"), a.backgroundImage = o.join("")), this.container.append(u), this.container.style.clipPath = `url(#${A})`;
}
_createPopup() {
const {
data: t
} = this, e = f(this, wa, new ud({
data: {
color: t.color,
titleObj: t.titleObj,
modificationDate: t.modificationDate,
contentsObj: t.contentsObj,
richText: t.richText,
parentRect: t.rect,
borderStyle: 0,
id: `popup_${t.id}`,
rotation: t.rotation,
noRotate: !0
},
parent: this.parent,
elements: [this]
}));
this.parent.div.append(e.render());
}
render() {
rt("Abstract method `AnnotationElement.render` called");
}
_getElementsByName(t, e = null) {
const s = [];
if (this._fieldObjects) {
const i = this._fieldObjects[t];
if (i)
for (const {
page: r,
id: a,
exportValues: o
} of i) {
if (r === -1 || a === e)
continue;
const l = typeof o == "string" ? o : null, h = document.querySelector(`[data-element-id="${a}"]`);
if (h && !Tr.has(h)) {
U(`_getElementsByName - element not allowed: ${a}`);
continue;
}
s.push({
id: a,
exportValue: l,
domElement: h
});
}
return s;
}
for (const i of document.getElementsByName(t)) {
const {
exportValue: r
} = i, a = i.getAttribute("data-element-id");
a !== e && Tr.has(i) && s.push({
id: a,
exportValue: r,
domElement: i
});
}
return s;
}
show() {
var t;
this.container && (this.container.hidden = !1), (t = this.popup) == null || t.maybeShow();
}
hide() {
var t;
this.container && (this.container.hidden = !0), (t = this.popup) == null || t.forceHide();
}
getElementsToTriggerPopup() {
return this.container;
}
addHighlightArea() {
const t = this.getElementsToTriggerPopup();
if (Array.isArray(t))
for (const e of t)
e.classList.add("highlightArea");
else
t.classList.add("highlightArea");
}
_editOnDoubleClick() {
if (!this._isEditable)
return;
const {
annotationEditorType: t,
data: {
id: e
}
} = this;
this.container.addEventListener("dblclick", () => {
var s;
(s = this.linkService.eventBus) == null || s.dispatch("switchannotationeditormode", {
source: this,
mode: t,
editId: e,
mustEnterInEditMode: !0
});
});
}
get width() {
return this.data.rect[2] - this.data.rect[0];
}
get height() {
return this.data.rect[3] - this.data.rect[1];
}
};
Qn = new WeakMap(), ya = new WeakMap(), wa = new WeakMap(), pl = new WeakSet(), dd = function(t) {
const {
container: {
style: e
},
data: {
rect: s,
rotation: i
},
parent: {
viewport: {
rawDims: {
pageWidth: r,
pageHeight: a,
pageX: o,
pageY: l
}
}
}
} = this;
s == null || s.splice(0, 4, ...t), e.left = `${100 * (t[0] - o) / r}%`, e.top = `${100 * (a - t[3] + l) / a}%`, i === 0 ? (e.width = `${100 * (t[2] - t[0]) / r}%`, e.height = `${100 * (t[3] - t[1]) / a}%`) : this.setRotation(i);
};
let wt = lu;
var Le, un, Vf, Wf;
class jf extends wt {
constructor(e, s = null) {
super(e, {
isRenderable: !0,
ignoreBorder: !!(s != null && s.ignoreBorder),
createQuadrilaterals: !0
});
m(this, Le);
this.isTooltipOnly = e.data.isTooltipOnly;
}
render() {
const {
data: e,
linkService: s
} = this, i = document.createElement("a");
i.setAttribute("data-element-id", e.id);
let r = !1;
return e.url ? (s.addLinkAttributes(i, e.url, e.newWindow), r = !0) : e.action ? (this._bindNamedAction(i, e.action), r = !0) : e.attachment ? (b(this, Le, Vf).call(this, i, e.attachment, e.attachmentDest), r = !0) : e.setOCGState ? (b(this, Le, Wf).call(this, i, e.setOCGState), r = !0) : e.dest ? (this._bindLink(i, e.dest), r = !0) : (e.actions && (e.actions.Action || e.actions["Mouse Up"] || e.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions && (this._bindJSAction(i, e), r = !0), e.resetForm ? (this._bindResetFormAction(i, e.resetForm), r = !0) : this.isTooltipOnly && !r && (this._bindLink(i, ""), r = !0)), this.container.classList.add("linkAnnotation"), r && this.container.append(i), this.container;
}
_bindLink(e, s) {
e.href = this.linkService.getDestinationHash(s), e.onclick = () => (s && this.linkService.goToDestination(s), !1), (s || s === "") && b(this, Le, un).call(this);
}
_bindNamedAction(e, s) {
e.href = this.linkService.getAnchorUrl(""), e.onclick = () => (this.linkService.executeNamedAction(s), !1), b(this, Le, un).call(this);
}
_bindJSAction(e, s) {
e.href = this.linkService.getAnchorUrl("");
const i = /* @__PURE__ */ new Map([["Action", "onclick"], ["Mouse Up", "onmouseup"], ["Mouse Down", "onmousedown"]]);
for (const r of Object.keys(s.actions)) {
const a = i.get(r);
a && (e[a] = () => {
var o;
return (o = this.linkService.eventBus) == null || o.dispatch("dispatcheventinsandbox", {
source: this,
detail: {
id: s.id,
name: r
}
}), !1;
});
}
e.onclick || (e.onclick = () => !1), b(this, Le, un).call(this);
}
_bindResetFormAction(e, s) {
const i = e.onclick;
if (i || (e.href = this.linkService.getAnchorUrl("")), b(this, Le, un).call(this), !this._fieldObjects) {
U('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'), i || (e.onclick = () => !1);
return;
}
e.onclick = () => {
var u;
i == null || i();
const {
fields: r,
refs: a,
include: o
} = s, l = [];
if (r.length !== 0 || a.length !== 0) {
const p = new Set(a);
for (const g of r) {
const A = this._fieldObjects[g] || [];
for (const {
id: y
} of A)
p.add(y);
}
for (const g of Object.values(this._fieldObjects))
for (const A of g)
p.has(A.id) === o && l.push(A);
} else
for (const p of Object.values(this._fieldObjects))
l.push(...p);
const h = this.annotationStorage, c = [];
for (const p of l) {
const {
id: g
} = p;
switch (c.push(g), p.type) {
case "text": {
const y = p.defaultValue || "";
h.setValue(g, {
value: y
});
break;
}
case "checkbox":
case "radiobutton": {
const y = p.defaultValue === p.exportValues;
h.setValue(g, {
value: y
});
break;
}
case "combobox":
case "listbox": {
const y = p.defaultValue || "";
h.setValue(g, {
value: y
});
break;
}
default:
continue;
}
const A = document.querySelector(`[data-element-id="${g}"]`);
if (A) {
if (!Tr.has(A)) {
U(`_bindResetFormAction - element not allowed: ${g}`);
continue;
}
} else continue;
A.dispatchEvent(new Event("resetform"));
}
return this.enableScripting && ((u = this.linkService.eventBus) == null || u.dispatch("dispatcheventinsandbox", {
source: this,
detail: {
id: "app",
ids: c,
name: "ResetForm"
}
})), !1;
};
}
}
Le = new WeakSet(), un = function() {
this.container.setAttribute("data-internal-link", "");
}, Vf = function(e, s, i = null) {
e.href = this.linkService.getAnchorUrl(""), s.description && (e.title = s.description), e.onclick = () => {
var r;
return (r = this.downloadManager) == null || r.openOrDownloadData(s.content, s.filename, i), !1;
}, b(this, Le, un).call(this);
}, Wf = function(e, s) {
e.href = this.linkService.getAnchorUrl(""), e.onclick = () => (this.linkService.executeSetOCGState(s), !1), b(this, Le, un).call(this);
};
class wm extends wt {
constructor(t) {
super(t, {
isRenderable: !0
});
}
render() {
this.container.classList.add("textAnnotation");
const t = document.createElement("img");
return t.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg", t.setAttribute("data-l10n-id", "pdfjs-text-annotation-type"), t.setAttribute("data-l10n-args", JSON.stringify({
type: this.data.name
})), !this.data.popupRef && this.hasPopupData && this._createPopup(), this.container.append(t), this.container;
}
}
class Pr extends wt {
render() {
return this.container;
}
showElementAndHideCanvas(t) {
var e;
this.data.hasOwnCanvas && (((e = t.previousSibling) == null ? void 0 : e.nodeName) === "CANVAS" && (t.previousSibling.hidden = !0), t.hidden = !1);
}
_getKeyModifier(t) {
return Wt.platform.isMac ? t.metaKey : t.ctrlKey;
}
_setEventListener(t, e, s, i, r) {
s.includes("mouse") ? t.addEventListener(s, (a) => {
var o;
(o = this.linkService.eventBus) == null || o.dispatch("dispatcheventinsandbox", {
source: this,
detail: {
id: this.data.id,
name: i,
value: r(a),
shift: a.shiftKey,
modifier: this._getKeyModifier(a)
}
});
}) : t.addEventListener(s, (a) => {
var o;
if (s === "blur") {
if (!e.focused || !a.relatedTarget)
return;
e.focused = !1;
} else if (s === "focus") {
if (e.focused)
return;
e.focused = !0;
}
r && ((o = this.linkService.eventBus) == null || o.dispatch("dispatcheventinsandbox", {
source: this,
detail: {
id: this.data.id,
name: i,
value: r(a)
}
}));
});
}
_setEventListeners(t, e, s, i) {
var r, a, o;
for (const [l, h] of s)
(h === "Action" || (r = this.data.actions) != null && r[h]) && ((h === "Focus" || h === "Blur") && (e || (e = {
focused: !1
})), this._setEventListener(t, e, l, h, i), h === "Focus" && !((a = this.data.actions) != null && a.Blur) ? this._setEventListener(t, e, "blur", "Blur", null) : h === "Blur" && !((o = this.data.actions) != null && o.Focus) && this._setEventListener(t, e, "focus", "Focus", null));
}
_setBackgroundColor(t) {
const e = this.data.backgroundColor || null;
t.style.backgroundColor = e === null ? "transparent" : $.makeHexColor(e[0], e[1], e[2]);
}
_setTextStyle(t) {
const e = ["left", "center", "right"], {
fontColor: s
} = this.data.defaultAppearanceData, i = this.data.defaultAppearanceData.fontSize || ym, r = t.style;
let a;
const o = 2, l = (h) => Math.round(10 * h) / 10;
if (this.data.multiLine) {
const h = Math.abs(this.data.rect[3] - this.data.rect[1] - o), c = Math.round(h / (_c * i)) || 1, u = h / c;
a = Math.min(i, l(u / _c));
} else {
const h = Math.abs(this.data.rect[3] - this.data.rect[1] - o);
a = Math.min(i, l(h / _c));
}
r.fontSize = `calc(${a}px * var(--total-scale-factor))`, r.color = $.makeHexColor(s[0], s[1], s[2]), this.data.textAlignment !== null && (r.textAlign = e[this.data.textAlignment]);
}
_setRequired(t, e) {
e ? t.setAttribute("required", !0) : t.removeAttribute("required"), t.setAttribute("aria-required", e);
}
}
class vm extends Pr {
constructor(t) {
const e = t.renderForms || t.data.hasOwnCanvas || !t.data.hasAppearance && !!t.data.fieldValue;
super(t, {
isRenderable: e
});
}
setPropertyOnSiblings(t, e, s, i) {
const r = this.annotationStorage;
for (const a of this._getElementsByName(t.name, t.id))
a.domElement && (a.domElement[e] = s), r.setValue(a.id, {
[i]: s
});
}
render() {
var i, r;
const t = this.annotationStorage, e = this.data.id;
this.container.classList.add("textWidgetAnnotation");
let s = null;
if (this.renderForms) {
const a = t.getValue(e, {
value: this.data.fieldValue
});
let o = a.value || "";
const l = t.getValue(e, {
charLimit: this.data.maxLen
}).charLimit;
l && o.length > l && (o = o.slice(0, l));
let h = a.formattedValue || ((i = this.data.textContent) == null ? void 0 : i.join(`
`)) || null;
h && this.data.comb && (h = h.replaceAll(/\s+/g, ""));
const c = {
userValue: o,
formattedValue: h,
lastCommittedValue: null,
commitKey: 1,
focused: !1
};
this.data.multiLine ? (s = document.createElement("textarea"), s.textContent = h ?? o, this.data.doNotScroll && (s.style.overflowY = "hidden")) : (s = document.createElement("input"), s.type = this.data.password ? "password" : "text", s.setAttribute("value", h ?? o), this.data.doNotScroll && (s.style.overflowX = "hidden")), this.data.hasOwnCanvas && (s.hidden = !0), Tr.add(s), s.setAttribute("data-element-id", e), s.disabled = this.data.readOnly, s.name = this.data.fieldName, s.tabIndex = 0;
const u = this.data.dateFormat || this.data.timeFormat;
u && (s.title = u), this._setRequired(s, this.data.required), l && (s.maxLength = l), s.addEventListener("input", (g) => {
t.setValue(e, {
value: g.target.value
}), this.setPropertyOnSiblings(s, "value", g.target.value, "value"), c.formattedValue = null;
}), s.addEventListener("resetform", (g) => {
const A = this.data.defaultFieldValue ?? "";
s.value = c.userValue = A, c.formattedValue = null;
});
let p = (g) => {
const {
formattedValue: A
} = c;
A != null && (g.target.value = A), g.target.scrollLeft = 0;
};
if (this.enableScripting && this.hasJSActions) {
s.addEventListener("focus", (A) => {
var w;
if (c.focused)
return;
const {
target: y
} = A;
c.userValue && (y.value = c.userValue), c.lastCommittedValue = y.value, c.commitKey = 1, (w = this.data.actions) != null && w.Focus || (c.focused = !0);
}), s.addEventListener("updatefromsandbox", (A) => {
this.showElementAndHideCanvas(A.target);
const y = {
value(w) {
c.userValue = w.detail.value ?? "", t.setValue(e, {
value: c.userValue.toString()
}), w.target.value = c.userValue;
},
formattedValue(w) {
const {
formattedValue: v
} = w.detail;
c.formattedValue = v, v != null && w.target !== document.activeElement && (w.target.value = v), t.setValue(e, {
formattedValue: v
});
},
selRange(w) {
w.target.setSelectionRange(...w.detail.selRange);
},
charLimit: (w) => {
var E;
const {
charLimit: v
} = w.detail, {
target: S
} = w;
if (v === 0) {
S.removeAttribute("maxLength");
return;
}
S.setAttribute("maxLength", v);
let _ = c.userValue;
!_ || _.length <= v || (_ = _.slice(0, v), S.value = c.userValue = _, t.setValue(e, {
value: _
}), (E = this.linkService.eventBus) == null || E.dispatch("dispatcheventinsandbox", {
source: this,
detail: {
id: e,
name: "Keystroke",
value: _,
willCommit: !0,
commitKey: 1,
selStart: S.selectionStart,
selEnd: S.selectionEnd
}
}));
}
};
this._dispatchEventFromSandbox(y, A);
}), s.addEventListener("keydown", (A) => {
var v;
c.commitKey = 1;
let y = -1;
if (A.key === "Escape" ? y = 0 : A.key === "Enter" && !this.data.multiLine ? y = 2 : A.key === "Tab" && (c.commitKey = 3), y === -1)
return;
const {
value: w
} = A.target;
c.lastCommittedValue !== w && (c.lastCommittedValue = w, c.userValue = w, (v = this.linkService.eventBus) == null || v.dispatch("dispatcheventinsandbox", {
source: this,
detail: {
id: e,
name: "Keystroke",
value: w,
willCommit: !0,
commitKey: y,
selStart: A.target.selectionStart,
selEnd: A.target.selectionEnd
}
}));
});
const g = p;
p = null, s.addEventListener("blur", (A) => {
var w, v;
if (!c.focused || !A.relatedTarget)
return;
(w = this.data.actions) != null && w.Blur || (c.focused = !1);
const {
value: y
} = A.target;
c.userValue = y, c.lastCommittedValue !== y && ((v = this.linkService.eventBus) == null || v.dispatch("dispatcheventinsandbox", {
source: this,
detail: {
id: e,
name: "Keystroke",
value: y,
willCommit: !0,
commitKey: c.commitKey,
selStart: A.target.selectionStart,
selEnd: A.target.selectionEnd
}
})), g(A);
}), (r = this.data.actions) != null && r.Keystroke && s.addEventListener("beforeinput", (A) => {
var x;
c.lastCommittedValue = null;
const {
data: y,
target: w
} = A, {
value: v,
selectionStart: S,
selectionEnd: _
} = w;
let E = S, C = _;
switch (A.inputType) {
case "deleteWordBackward": {
const T = v.substring(0, S).match(/\w*[^\w]*$/);
T && (E -= T[0].length);
break;
}
case "deleteWordForward": {
const T = v.substring(S).match(/^[^\w]*\w*/);
T && (C += T[0].length);
break;
}
case "deleteContentBackward":
S === _ && (E -= 1);
break;
case "deleteContentForward":
S === _ && (C += 1);
break;
}
A.preventDefault(), (x = this.linkService.eventBus) == null || x.dispatch("dispatcheventinsandbox", {
source: this,
detail: {
id: e,
name: "Keystroke",
value: v,
change: y || "",
willCommit: !1,
selStart: E,
selEnd: C
}
});
}), this._setEventListeners(s, c, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], (A) => A.target.value);
}
if (p && s.addEventListener("blur", p), this.data.comb) {
const A = (this.data.rect[2] - this.data.rect[0]) / l;
s.classList.add("comb"), s.style.letterSpacing = `calc(${A}px * var(--total-scale-factor) - 1ch)`;
}
} else
s = document.createElement("div"), s.textContent = this.data.fieldValue, s.style.verticalAlign = "middle", s.style.display = "table-cell", this.data.hasOwnCanvas && (s.hidden = !0);
return this._setTextStyle(s), this._setBackgroundColor(s), this._setDefaultPropertiesFromJS(s), this.container.append(s), this.container;
}
}
class _m extends Pr {
constructor(t) {
super(t, {
isRenderable: !!t.data.hasOwnCanvas
});
}
}
class Sm extends Pr {
constructor(t) {
super(t, {
isRenderable: t.renderForms
});
}
render() {
const t = this.annotationStorage, e = this.data, s = e.id;
let i = t.getValue(s, {
value: e.exportValue === e.fieldValue
}).value;
typeof i == "string" && (i = i !== "Off", t.setValue(s, {
value: i
})), this.container.classList.add("buttonWidgetAnnotation", "checkBox");
const r = document.createElement("input");
return Tr.add(r), r.setAttribute("data-element-id", s), r.disabled = e.readOnly, this._setRequired(r, this.data.required), r.type = "checkbox", r.name = e.fieldName, i && r.setAttribute("checked", !0), r.setAttribute("exportValue", e.exportValue), r.tabIndex = 0, r.addEventListener("change", (a) => {
const {
name: o,
checked: l
} = a.target;
for (const h of this._getElementsByName(o, s)) {
const c = l && h.exportValue === e.exportValue;
h.domElement && (h.domElement.checked = c), t.setValue(h.id, {
value: c
});
}
t.setValue(s, {
value: l
});
}), r.addEventListener("resetform", (a) => {
const o = e.defaultFieldValue || "Off";
a.target.checked = o === e.exportValue;
}), this.enableScripting && this.hasJSActions && (r.addEventListener("updatefromsandbox", (a) => {
const o = {
value(l) {
l.target.checked = l.detail.value !== "Off", t.setValue(s, {
value: l.target.checked
});
}
};
this._dispatchEventFromSandbox(o, a);
}), this._setEventListeners(r, null, [["change", "Validate"], ["change", "Action"], ["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], (a) => a.target.checked)), this._setBackgroundColor(r), this._setDefaultPropertiesFromJS(r), this.container.append(r), this.container;
}
}
class qf extends Pr {
constructor(t) {
super(t, {
isRenderable: t.renderForms
});
}
render() {
this.container.classList.add("buttonWidgetAnnotation", "radioButton");
const t = this.annotationStorage, e = this.data, s = e.id;
let i = t.getValue(s, {
value: e.fieldValue === e.buttonValue
}).value;
if (typeof i == "string" && (i = i !== e.buttonValue, t.setValue(s, {
value: i
})), i)
for (const a of this._getElementsByName(e.fieldName, s))
t.setValue(a.id, {
value: !1
});
const r = document.createElement("input");
if (Tr.add(r), r.setAttribute("data-element-id", s), r.disabled = e.readOnly, this._setRequired(r, this.data.required), r.type = "radio", r.name = e.fieldName, i && r.setAttribute("checked", !0), r.tabIndex = 0, r.addEventListener("change", (a) => {
const {
name: o,
checked: l
} = a.target;
for (const h of this._getElementsByName(o, s))
t.setValue(h.id, {
value: !1
});
t.setValue(s, {
value: l
});
}), r.addEventListener("resetform", (a) => {
const o = e.defaultFieldValue;
a.target.checked = o != null && o === e.buttonValue;
}), this.enableScripting && this.hasJSActions) {
const a = e.buttonValue;
r.addEventListener("updatefromsandbox", (o) => {
const l = {
value: (h) => {
const c = a === h.detail.value;
for (const u of this._getElementsByName(h.target.name)) {
const p = c && u.id === s;
u.domElement && (u.domElement.checked = p), t.setValue(u.id, {
value: p
});
}
}
};
this._dispatchEventFromSandbox(l, o);
}), this._setEventListeners(r, null, [["change", "Validate"], ["change", "Action"], ["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], (o) => o.target.checked);
}
return this._setBackgroundColor(r), this._setDefaultPropertiesFromJS(r), this.container.append(r), this.container;
}
}
class Em extends jf {
constructor(t) {
super(t, {
ignoreBorder: t.data.hasAppearance
});
}
render() {
const t = super.render();
t.classList.add("buttonWidgetAnnotation", "pushButton");
const e = t.lastChild;
return this.enableScripting && this.hasJSActions && e && (this._setDefaultPropertiesFromJS(e), e.addEventListener("updatefromsandbox", (s) => {
this._dispatchEventFromSandbox({}, s);
})), t;
}
}
class Cm extends Pr {
constructor(t) {
super(t, {
isRenderable: t.renderForms
});
}
render() {
this.container.classList.add("choiceWidgetAnnotation");
const t = this.annotationStorage, e = this.data.id, s = t.getValue(e, {
value: this.data.fieldValue
}), i = document.createElement("select");
Tr.add(i), i.setAttribute("data-element-id", e), i.disabled = this.data.readOnly, this._setRequired(i, this.data.required), i.name = this.data.fieldName, i.tabIndex = 0;
let r = this.data.combo && this.data.options.length > 0;
this.data.combo || (i.size = this.data.options.length, this.data.multiSelect && (i.multiple = !0)), i.addEventListener("resetform", (c) => {
const u = this.data.defaultFieldValue;
for (const p of i.options)
p.selected = p.value === u;
});
for (const c of this.data.options) {
const u = document.createElement("option");
u.textContent = c.displayValue, u.value = c.exportValue, s.value.includes(c.exportValue) && (u.setAttribute("selected", !0), r = !1), i.append(u);
}
let a = null;
if (r) {
const c = document.createElement("option");
c.value = " ", c.setAttribute("hidden", !0), c.setAttribute("selected", !0), i.prepend(c), a = () => {
c.remove(), i.removeEventListener("input", a), a = null;
}, i.addEventListener("input", a);
}
const o = (c) => {
const u = c ? "value" : "textContent", {
options: p,
multiple: g
} = i;
return g ? Array.prototype.filter.call(p, (A) => A.selected).map((A) => A[u]) : p.selectedIndex === -1 ? null : p[p.selectedIndex][u];
};
let l = o(!1);
const h = (c) => {
const u = c.target.options;
return Array.prototype.map.call(u, (p) => ({
displayValue: p.textContent,
exportValue: p.value
}));
};
return this.enableScripting && this.hasJSActions ? (i.addEventListener("updatefromsandbox", (c) => {
const u = {
value(p) {
a == null || a();
const g = p.detail.value, A = new Set(Array.isArray(g) ? g : [g]);
for (const y of i.options)
y.selected = A.has(y.value);
t.setValue(e, {
value: o(!0)
}), l = o(!1);
},
multipleSelection(p) {
i.multiple = !0;
},
remove(p) {
const g = i.options, A = p.detail.remove;
g[A].selected = !1, i.remove(A), g.length > 0 && Array.prototype.findIndex.call(g, (w) => w.selected) === -1 && (g[0].selected = !0), t.setValue(e, {
value: o(!0),
items: h(p)
}), l = o(!1);
},
clear(p) {
for (; i.length !== 0; )
i.remove(0);
t.setValue(e, {
value: null,
items: []
}), l = o(!1);
},
insert(p) {
const {
index: g,
displayValue: A,
exportValue: y
} = p.detail.insert, w = i.children[g], v = document.createElement("option");
v.textContent = A, v.value = y, w ? w.before(v) : i.append(v), t.setValue(e, {
value: o(!0),
items: h(p)
}), l = o(!1);
},
items(p) {
const {
items: g
} = p.detail;
for (; i.length !== 0; )
i.remove(0);
for (const A of g) {
const {
displayValue: y,
exportValue: w
} = A, v = document.createElement("option");
v.textContent = y, v.value = w, i.append(v);
}
i.options.length > 0 && (i.options[0].selected = !0), t.setValue(e, {
value: o(!0),
items: h(p)
}), l = o(!1);
},
indices(p) {
const g = new Set(p.detail.indices);
for (const A of p.target.options)
A.selected = g.has(A.index);
t.setValue(e, {
value: o(!0)
}), l = o(!1);
},
editable(p) {
p.target.disabled = !p.detail.editable;
}
};
this._dispatchEventFromSandbox(u, c);
}), i.addEventListener("input", (c) => {
var g;
const u = o(!0), p = o(!1);
t.setValue(e, {
value: u
}), c.preventDefault(), (g = this.linkService.eventBus) == null || g.dispatch("dispatcheventinsandbox", {
source: this,
detail: {
id: e,
name: "Keystroke",
value: l,
change: p,
changeEx: u,
willCommit: !1,
commitKey: 1,
keyDown: !1
}
});
}), this._setEventListeners(i, null, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"], ["input", "Action"], ["input", "Validate"]], (c) => c.target.value)) : i.addEventListener("input", function(c) {
t.setValue(e, {
value: o(!0)
});
}), this.data.combo && this._setTextStyle(i), this._setBackgroundColor(i), this._setDefaultPropertiesFromJS(i), this.container.append(i), this.container;
}
}
class ud extends wt {
constructor(t) {
const {
data: e,
elements: s
} = t;
super(t, {
isRenderable: wt._hasPopupData(e)
}), this.elements = s, this.popup = null;
}
render() {
const {
container: t
} = this;
t.classList.add("popupAnnotation"), t.role = "comment";
const e = this.popup = new xm({
container: this.container,
color: this.data.color,
titleObj: this.data.titleObj,
modificationDate: this.data.modificationDate,
contentsObj: this.data.contentsObj,
richText: this.data.richText,
rect: this.data.rect,
parentRect: this.data.parentRect || null,
parent: this.parent,
elements: this.elements,
open: this.data.open
}), s = [];
for (const i of this.elements)
i.popup = e, i.container.ariaHasPopup = "dialog", s.push(i.data.id), i.addHighlightArea();
return this.container.setAttribute("aria-controls", s.map((i) => `${Xd}${i}`).join(",")), this.container;
}
}
var va, ac, oc, _a, Sa, mt, ti, Jn, gl, ml, Ea, ei, Qe, si, bl, ii, Al, Zn, tr, at, _h, fd, Xf, Yf, Kf, Qf, Sh, Eh, pd;
class xm {
constructor({
container: t,
color: e,
elements: s,
titleObj: i,
modificationDate: r,
contentsObj: a,
richText: o,
parent: l,
rect: h,
parentRect: c,
open: u
}) {
m(this, at);
m(this, va, b(this, at, Kf).bind(this));
m(this, ac, b(this, at, pd).bind(this));
m(this, oc, b(this, at, Eh).bind(this));
m(this, _a, b(this, at, Sh).bind(this));
m(this, Sa, null);
m(this, mt, null);
m(this, ti, null);
m(this, Jn, null);
m(this, gl, null);
m(this, ml, null);
m(this, Ea, null);
m(this, ei, !1);
m(this, Qe, null);
m(this, si, null);
m(this, bl, null);
m(this, ii, null);
m(this, Al, null);
m(this, Zn, null);
m(this, tr, !1);
var p;
f(this, mt, t), f(this, Al, i), f(this, ti, a), f(this, ii, o), f(this, ml, l), f(this, Sa, e), f(this, bl, h), f(this, Ea, c), f(this, gl, s), f(this, Jn, Qd.toDateObject(r)), this.trigger = s.flatMap((g) => g.getElementsToTriggerPopup());
for (const g of this.trigger)
g.addEventListener("click", n(this, _a)), g.addEventListener("mouseenter", n(this, oc)), g.addEventListener("mouseleave", n(this, ac)), g.classList.add("popupTriggerArea");
for (const g of s)
(p = g.container) == null || p.addEventListener("keydown", n(this, va));
n(this, mt).hidden = !0, u && b(this, at, Sh).call(this);
}
render() {
if (n(this, Qe))
return;
const t = f(this, Qe, document.createElement("div"));
if (t.className = "popup", n(this, Sa)) {
const r = t.style.outlineColor = $.makeHexColor(...n(this, Sa));
t.style.backgroundColor = `color-mix(in srgb, ${r} 30%, white)`;
}
const e = document.createElement("span");
e.className = "header";
const s = document.createElement("h1");
if (e.append(s), {
dir: s.dir,
str: s.textContent
} = n(this, Al), t.append(e), n(this, Jn)) {
const r = document.createElement("time");
r.classList.add("popupDate"), r.setAttribute("data-l10n-id", "pdfjs-annotation-date-time-string"), r.setAttribute("data-l10n-args", JSON.stringify({
dateObj: n(this, Jn).valueOf()
})), r.dateTime = n(this, Jn).toISOString(), e.append(r);
}
const i = n(this, at, _h);
if (i)
Uf.render({
xfaHtml: i,
intent: "richText",
div: t
}), t.lastChild.classList.add("richText", "popupContent");
else {
const r = this._formatContents(n(this, ti));
t.append(r);
}
n(this, mt).append(t);
}
_formatContents({
str: t,
dir: e
}) {
const s = document.createElement("p");
s.classList.add("popupContent"), s.dir = e;
const i = t.split(/(?:\r\n?|\n)/);
for (let r = 0, a = i.length; r < a; ++r) {
const o = i[r];
s.append(document.createTextNode(o)), r < a - 1 && s.append(document.createElement("br"));
}
return s;
}
updateEdited({
rect: t,
popupContent: e
}) {
var s;
n(this, Zn) || f(this, Zn, {
contentsObj: n(this, ti),
richText: n(this, ii)
}), t && f(this, si, null), e && (f(this, ii, b(this, at, Yf).call(this, e)), f(this, ti, null)), (s = n(this, Qe)) == null || s.remove(), f(this, Qe, null);
}
resetEdited() {
var t;
n(this, Zn) && ({
contentsObj: Zt(this, ti)._,
richText: Zt(this, ii)._
} = n(this, Zn), f(this, Zn, null), (t = n(this, Qe)) == null || t.remove(), f(this, Qe, null), f(this, si, null));
}
forceHide() {
f(this, tr, this.isVisible), n(this, tr) && (n(this, mt).hidden = !0);
}
maybeShow() {
n(this, tr) && (n(this, Qe) || b(this, at, Eh).call(this), f(this, tr, !1), n(this, mt).hidden = !1);
}
get isVisible() {
return n(this, mt).hidden === !1;
}
}
va = new WeakMap(), ac = new WeakMap(), oc = new WeakMap(), _a = new WeakMap(), Sa = new WeakMap(), mt = new WeakMap(), ti = new WeakMap(), Jn = new WeakMap(), gl = new WeakMap(), ml = new WeakMap(), Ea = new WeakMap(), ei = new WeakMap(), Qe = new WeakMap(), si = new WeakMap(), bl = new WeakMap(), ii = new WeakMap(), Al = new WeakMap(), Zn = new WeakMap(), tr = new WeakMap(), at = new WeakSet(), _h = function() {
const t = n(this, ii), e = n(this, ti);
return t != null && t.str && (!(e != null && e.str) || e.str === t.str) && n(this, ii).html || null;
}, fd = function() {
var t, e, s;
return ((s = (e = (t = n(this, at, _h)) == null ? void 0 : t.attributes) == null ? void 0 : e.style) == null ? void 0 : s.fontSize) || 0;
}, Xf = function() {
var t, e, s;
return ((s = (e = (t = n(this, at, _h)) == null ? void 0 : t.attributes) == null ? void 0 : e.style) == null ? void 0 : s.color) || null;
}, Yf = function(t) {
const e = [], s = {
str: t,
html: {
name: "div",
attributes: {
dir: "auto"
},
children: [{
name: "p",
children: e
}]
}
}, i = {
style: {
color: n(this, at, Xf),
fontSize: n(this, at, fd) ? `calc(${n(this, at, fd)}px * var(--total-scale-factor))` : ""
}
};
for (const r of t.split(`
`))
e.push({
name: "span",
value: r,
attributes: i
});
return s;
}, Kf = function(t) {
t.altKey || t.shiftKey || t.ctrlKey || t.metaKey || (t.key === "Enter" || t.key === "Escape" && n(this, ei)) && b(this, at, Sh).call(this);
}, Qf = function() {
if (n(this, si) !== null)
return;
const {
page: {
view: t
},
viewport: {
rawDims: {
pageWidth: e,
pageHeight: s,
pageX: i,
pageY: r
}
}
} = n(this, ml);
let a = !!n(this, Ea), o = a ? n(this, Ea) : n(this, bl);
for (const A of n(this, gl))
if (!o || $.intersect(A.data.rect, o) !== null) {
o = A.data.rect, a = !0;
break;
}
const l = $.normalizeRect([o[0], t[3] - o[1] + t[1], o[2], t[3] - o[3] + t[1]]), c = a ? o[2] - o[0] + 5 : 0, u = l[0] + c, p = l[1];
f(this, si, [100 * (u - i) / e, 100 * (p - r) / s]);
const {
style: g
} = n(this, mt);
g.left = `${n(this, si)[0]}%`, g.top = `${n(this, si)[1]}%`;
}, Sh = function() {
f(this, ei, !n(this, ei)), n(this, ei) ? (b(this, at, Eh).call(this), n(this, mt).addEventListener("click", n(this, _a)), n(this, mt).addEventListener("keydown", n(this, va))) : (b(this, at, pd).call(this), n(this, mt).removeEventListener("click", n(this, _a)), n(this, mt).removeEventListener("keydown", n(this, va)));
}, Eh = function() {
n(this, Qe) || this.render(), this.isVisible ? n(this, ei) && n(this, mt).classList.add("focused") : (b(this, at, Qf).call(this), n(this, mt).hidden = !1, n(this, mt).style.zIndex = parseInt(n(this, mt).style.zIndex) + 1e3);
}, pd = function() {
n(this, mt).classList.remove("focused"), !(n(this, ei) || !this.isVisible) && (n(this, mt).hidden = !0, n(this, mt).style.zIndex = parseInt(n(this, mt).style.zIndex) - 1e3);
};
class Jf extends wt {
constructor(t) {
super(t, {
isRenderable: !0,
ignoreBorder: !0
}), this.textContent = t.data.textContent, this.textPosition = t.data.textPosition, this.annotationEditorType = z.FREETEXT;
}
render() {
if (this.container.classList.add("freeTextAnnotation"), this.textContent) {
const t = document.createElement("div");
t.classList.add("annotationTextContent"), t.setAttribute("role", "comment");
for (const e of this.textContent) {
const s = document.createElement("span");
s.textContent = e, t.append(s);
}
this.container.append(t);
}
return !this.data.popupRef && this.hasPopupData && this._createPopup(), this._editOnDoubleClick(), this.container;
}
}
var yl;
class Tm extends wt {
constructor(e) {
super(e, {
isRenderable: !0,
ignoreBorder: !0
});
m(this, yl, null);
}
render() {
this.container.classList.add("lineAnnotation");
const {
data: e,
width: s,
height: i
} = this, r = this.svgFactory.create(s, i, !0), a = f(this, yl, this.svgFactory.createElement("svg:line"));
return a.setAttribute("x1", e.rect[2] - e.lineCoordinates[0]), a.setAttribute("y1", e.rect[3] - e.lineCoordinates[1]), a.setAttribute("x2", e.rect[2] - e.lineCoordinates[2]), a.setAttribute("y2", e.rect[3] - e.lineCoordinates[3]), a.setAttribute("stroke-width", e.borderStyle.width || 1), a.setAttribute("stroke", "transparent"), a.setAttribute("fill", "transparent"), r.append(a), this.container.append(r), !e.popupRef && this.hasPopupData && this._createPopup(), this.container;
}
getElementsToTriggerPopup() {
return n(this, yl);
}
addHighlightArea() {
this.container.classList.add("highlightArea");
}
}
yl = new WeakMap();
var wl;
class Rm extends wt {
constructor(e) {
super(e, {
isRenderable: !0,
ignoreBorder: !0
});
m(this, wl, null);
}
render() {
this.container.classList.add("squareAnnotation");
const {
data: e,
width: s,
height: i
} = this, r = this.svgFactory.create(s, i, !0), a = e.borderStyle.width, o = f(this, wl, this.svgFactory.createElement("svg:rect"));
return o.setAttribute("x", a / 2), o.setAttribute("y", a / 2), o.setAttribute("width", s - a), o.setAttribute("height", i - a), o.setAttribute("stroke-width", a || 1), o.setAttribute("stroke", "transparent"), o.setAttribute("fill", "transparent"), r.append(o), this.container.append(r), !e.popupRef && this.hasPopupData && this._createPopup(), this.container;
}
getElementsToTriggerPopup() {
return n(this, wl);
}
addHighlightArea() {
this.container.classList.add("highlightArea");
}
}
wl = new WeakMap();
var vl;
class Pm extends wt {
constructor(e) {
super(e, {
isRenderable: !0,
ignoreBorder: !0
});
m(this, vl, null);
}
render() {
this.container.classList.add("circleAnnotation");
const {
data: e,
width: s,
height: i
} = this, r = this.svgFactory.create(s, i, !0), a = e.borderStyle.width, o = f(this, vl, this.svgFactory.createElement("svg:ellipse"));
return o.setAttribute("cx", s / 2), o.setAttribute("cy", i / 2), o.setAttribute("rx", s / 2 - a / 2), o.setAttribute("ry", i / 2 - a / 2), o.setAttribute("stroke-width", a || 1), o.setAttribute("stroke", "transparent"), o.setAttribute("fill", "transparent"), r.append(o), this.container.append(r), !e.popupRef && this.hasPopupData && this._createPopup(), this.container;
}
getElementsToTriggerPopup() {
return n(this, vl);
}
addHighlightArea() {
this.container.classList.add("highlightArea");
}
}
vl = new WeakMap();
var _l;
class Zf extends wt {
constructor(e) {
super(e, {
isRenderable: !0,
ignoreBorder: !0
});
m(this, _l, null);
this.containerClassName = "polylineAnnotation", this.svgElementName = "svg:polyline";
}
render() {
this.container.classList.add(this.containerClassName);
const {
data: {
rect: e,
vertices: s,
borderStyle: i,
popupRef: r
},
width: a,
height: o
} = this;
if (!s)
return this.container;
const l = this.svgFactory.create(a, o, !0);
let h = [];
for (let u = 0, p = s.length; u < p; u += 2) {
const g = s[u] - e[0], A = e[3] - s[u + 1];
h.push(`${g},${A}`);
}
h = h.join(" ");
const c = f(this, _l, this.svgFactory.createElement(this.svgElementName));
return c.setAttribute("points", h), c.setAttribute("stroke-width", i.width || 1), c.setAttribute("stroke", "transparent"), c.setAttribute("fill", "transparent"), l.append(c), this.container.append(l), !r && this.hasPopupData && this._createPopup(), this.container;
}
getElementsToTriggerPopup() {
return n(this, _l);
}
addHighlightArea() {
this.container.classList.add("highlightArea");
}
}
_l = new WeakMap();
class Im extends Zf {
constructor(t) {
super(t), this.containerClassName = "polygonAnnotation", this.svgElementName = "svg:polygon";
}
}
class Mm extends wt {
constructor(t) {
super(t, {
isRenderable: !0,
ignoreBorder: !0
});
}
render() {
return this.container.classList.add("caretAnnotation"), !this.data.popupRef && this.hasPopupData && this._createPopup(), this.container;
}
}
var Sl, er, El, gd;
class su extends wt {
constructor(e) {
super(e, {
isRenderable: !0,
ignoreBorder: !0
});
m(this, El);
m(this, Sl, null);
m(this, er, []);
this.containerClassName = "inkAnnotation", this.svgElementName = "svg:polyline", this.annotationEditorType = this.data.it === "InkHighlight" ? z.HIGHLIGHT : z.INK;
}
render() {
this.container.classList.add(this.containerClassName);
const {
data: {
rect: e,
rotation: s,
inkLists: i,
borderStyle: r,
popupRef: a
}
} = this, {
transform: o,
width: l,
height: h
} = b(this, El, gd).call(this, s, e), c = this.svgFactory.create(l, h, !0), u = f(this, Sl, this.svgFactory.createElement("svg:g"));
c.append(u), u.setAttribute("stroke-width", r.width || 1), u.setAttribute("stroke-linecap", "round"), u.setAttribute("stroke-linejoin", "round"), u.setAttribute("stroke-miterlimit", 10), u.setAttribute("stroke", "transparent"), u.setAttribute("fill", "transparent"), u.setAttribute("transform", o);
for (let p = 0, g = i.length; p < g; p++) {
const A = this.svgFactory.createElement(this.svgElementName);
n(this, er).push(A), A.setAttribute("points", i[p].join(",")), u.append(A);
}
return !a && this.hasPopupData && this._createPopup(), this.container.append(c), this._editOnDoubleClick(), this.container;
}
updateEdited(e) {
super.updateEdited(e);
const {
thickness: s,
points: i,
rect: r
} = e, a = n(this, Sl);
if (s >= 0 && a.setAttribute("stroke-width", s || 1), i)
for (let o = 0, l = n(this, er).length; o < l; o++)
n(this, er)[o].setAttribute("points", i[o].join(","));
if (r) {
const {
transform: o,
width: l,
height: h
} = b(this, El, gd).call(this, this.data.rotation, r);
a.parentElement.setAttribute("viewBox", `0 0 ${l} ${h}`), a.setAttribute("transform", o);
}
}
getElementsToTriggerPopup() {
return n(this, er);
}
addHighlightArea() {
this.container.classList.add("highlightArea");
}
}
Sl = new WeakMap(), er = new WeakMap(), El = new WeakSet(), gd = function(e, s) {
switch (e) {
case 90:
return {
transform: `rotate(90) translate(${-s[0]},${s[1]}) scale(1,-1)`,
width: s[3] - s[1],
height: s[2] - s[0]
};
case 180:
return {
transform: `rotate(180) translate(${-s[2]},${s[1]}) scale(1,-1)`,
width: s[2] - s[0],
height: s[3] - s[1]
};
case 270:
return {
transform: `rotate(270) translate(${-s[2]},${s[3]}) scale(1,-1)`,
width: s[3] - s[1],
height: s[2] - s[0]
};
default:
return {
transform: `translate(${-s[0]},${s[3]}) scale(1,-1)`,
width: s[2] - s[0],
height: s[3] - s[1]
};
}
};
class tp extends wt {
constructor(t) {
super(t, {
isRenderable: !0,
ignoreBorder: !0,
createQuadrilaterals: !0
}), this.annotationEditorType = z.HIGHLIGHT;
}
render() {
const {
data: {
overlaidText: t,
popupRef: e
}
} = this;
if (!e && this.hasPopupData && this._createPopup(), this.container.classList.add("highlightAnnotation"), this._editOnDoubleClick(), t) {
const s = document.createElement("mark");
s.classList.add("overlaidText"), s.textContent = t, this.container.append(s);
}
return this.container;
}
}
class km extends wt {
constructor(t) {
super(t, {
isRenderable: !0,
ignoreBorder: !0,
createQuadrilaterals: !0
});
}
render() {
const {
data: {
overlaidText: t,
popupRef: e
}
} = this;
if (!e && this.hasPopupData && this._createPopup(), this.container.classList.add("underlineAnnotation"), t) {
const s = document.createElement("u");
s.classList.add("overlaidText"), s.textContent = t, this.container.append(s);
}
return this.container;
}
}
class Lm extends wt {
constructor(t) {
super(t, {
isRenderable: !0,
ignoreBorder: !0,
createQuadrilaterals: !0
});
}
render() {
const {
data: {
overlaidText: t,
popupRef: e
}
} = this;
if (!e && this.hasPopupData && this._createPopup(), this.container.classList.add("squigglyAnnotation"), t) {
const s = document.createElement("u");
s.classList.add("overlaidText"), s.textContent = t, this.container.append(s);
}
return this.container;
}
}
class Dm extends wt {
constructor(t) {
super(t, {
isRenderable: !0,
ignoreBorder: !0,
createQuadrilaterals: !0
});
}
render() {
const {
data: {
overlaidText: t,
popupRef: e
}
} = this;
if (!e && this.hasPopupData && this._createPopup(), this.container.classList.add("strikeoutAnnotation"), t) {
const s = document.createElement("s");
s.classList.add("overlaidText"), s.textContent = t, this.container.append(s);
}
return this.container;
}
}
class ep extends wt {
constructor(t) {
super(t, {
isRenderable: !0,
ignoreBorder: !0
}), this.annotationEditorType = z.STAMP;
}
render() {
return this.container.classList.add("stampAnnotation"), this.container.setAttribute("role", "img"), !this.data.popupRef && this.hasPopupData && this._createPopup(), this._editOnDoubleClick(), this.container;
}
}
var Cl, xl, md;
class Fm extends wt {
constructor(e) {
var i;
super(e, {
isRenderable: !0
});
m(this, xl);
m(this, Cl, null);
const {
file: s
} = this.data;
this.filename = s.filename, this.content = s.content, (i = this.linkService.eventBus) == null || i.dispatch("fileattachmentannotation", {
source: this,
...s
});
}
render() {
this.container.classList.add("fileAttachmentAnnotation");
const {
container: e,
data: s
} = this;
let i;
s.hasAppearance || s.fillAlpha === 0 ? i = document.createElement("div") : (i = document.createElement("img"), i.src = `${this.imageResourcesPath}annotation-${/paperclip/i.test(s.name) ? "paperclip" : "pushpin"}.svg`, s.fillAlpha && s.fillAlpha < 1 && (i.style = `filter: opacity(${Math.round(s.fillAlpha * 100)}%);`)), i.addEventListener("dblclick", b(this, xl, md).bind(this)), f(this, Cl, i);
const {
isMac: r
} = Wt.platform;
return e.addEventListener("keydown", (a) => {
a.key === "Enter" && (r ? a.metaKey : a.ctrlKey) && b(this, xl, md).call(this);
}), !s.popupRef && this.hasPopupData ? this._createPopup() : i.classList.add("popupTriggerArea"), e.append(i), e;
}
getElementsToTriggerPopup() {
return n(this, Cl);
}
addHighlightArea() {
this.container.classList.add("highlightArea");
}
}
Cl = new WeakMap(), xl = new WeakSet(), md = function() {
var e;
(e = this.downloadManager) == null || e.openOrDownloadData(this.content, this.filename);
};
var Tl, sr, ji, Rl, cn, Ad, yd;
const hu = class hu {
constructor({
div: t,
accessibilityManager: e,
annotationCanvasMap: s,
annotationEditorUIManager: i,
page: r,
viewport: a,
structTreeLayer: o
}) {
m(this, cn);
m(this, Tl, null);
m(this, sr, null);
m(this, ji, /* @__PURE__ */ new Map());
m(this, Rl, null);
this.div = t, f(this, Tl, e), f(this, sr, s), f(this, Rl, o || null), this.page = r, this.viewport = a, this.zIndex = 0, this._annotationEditorUIManager = i;
}
hasEditableAnnotations() {
return n(this, ji).size > 0;
}
async render(t) {
var a;
const {
annotations: e
} = t, s = this.div;
Cr(s, this.viewport);
const i = /* @__PURE__ */ new Map(), r = {
data: null,
layer: s,
linkService: t.linkService,
downloadManager: t.downloadManager,
imageResourcesPath: t.imageResourcesPath || "",
renderForms: t.renderForms !== !1,
svgFactory: new Uh(),
annotationStorage: t.annotationStorage || new Zd(),
enableScripting: t.enableScripting === !0,
hasJSActions: t.hasJSActions,
fieldObjects: t.fieldObjects,
parent: this,
elements: null
};
for (const o of e) {
if (o.noHTML)
continue;
const l = o.annotationType === _t.POPUP;
if (l) {
const u = i.get(o.id);
if (!u)
continue;
r.elements = u;
} else if (o.rect[2] === o.rect[0] || o.rect[3] === o.rect[1])
continue;
r.data = o;
const h = ku.create(r);
if (!h.isRenderable)
continue;
if (!l && o.popupRef) {
const u = i.get(o.popupRef);
u ? u.push(h) : i.set(o.popupRef, [h]);
}
const c = h.render();
o.hidden && (c.style.visibility = "hidden"), await b(this, cn, Ad).call(this, c, o.id, r.elements), h._isEditable && (n(this, ji).set(h.data.id, h), (a = this._annotationEditorUIManager) == null || a.renderAnnotationElement(h));
}
b(this, cn, yd).call(this);
}
async addLinkAnnotations(t, e) {
const s = {
data: null,
layer: this.div,
linkService: e,
svgFactory: new Uh(),
parent: this
};
for (const i of t) {
i.borderStyle || (i.borderStyle = hu._defaultBorderStyle), s.data = i;
const r = ku.create(s);
if (!r.isRenderable)
continue;
const a = r.render();
await b(this, cn, Ad).call(this, a, i.id, null);
}
}
update({
viewport: t
}) {
const e = this.div;
this.viewport = t, Cr(e, {
rotation: t.rotation
}), b(this, cn, yd).call(this), e.hidden = !1;
}
getEditableAnnotations() {
return Array.from(n(this, ji).values());
}
getEditableAnnotation(t) {
return n(this, ji).get(t);
}
static get _defaultBorderStyle() {
return X(this, "_defaultBorderStyle", Object.freeze({
width: 1,
rawWidth: 1,
style: Mr.SOLID,
dashArray: [3],
horizontalCornerRadius: 0,
verticalCornerRadius: 0
}));
}
};
Tl = new WeakMap(), sr = new WeakMap(), ji = new WeakMap(), Rl = new WeakMap(), cn = new WeakSet(), Ad = async function(t, e, s) {
var o, l;
const i = t.firstChild || t, r = i.id = `${Xd}${e}`, a = await ((o = n(this, Rl)) == null ? void 0 : o.getAriaAttributes(r));
if (a)
for (const [h, c] of a)
i.setAttribute(h, c);
s ? s.at(-1).container.after(t) : (this.div.append(t), (l = n(this, Tl)) == null || l.moveElementInDOM(this.div, t, i, !1));
}, yd = function() {
var e;
if (!n(this, sr))
return;
const t = this.div;
for (const [s, i] of n(this, sr)) {
const r = t.querySelector(`[data-annotation-id="${s}"]`);
if (!r)
continue;
i.className = "annotationContent";
const {
firstChild: a
} = r;
a ? a.nodeName === "CANVAS" ? a.replaceWith(i) : a.classList.contains("annotationContent") ? a.after(i) : a.before(i) : r.append(i);
const o = n(this, ji).get(s);
o && (o._hasNoCanvas ? ((e = this._annotationEditorUIManager) == null || e.setMissingCanvas(s, r.id, i), o._hasNoCanvas = !1) : o.canvas = i);
}
n(this, sr).clear();
};
let bd = hu;
const ah = /\r\n?|\n/g;
var Je, ve, Pl, ir, _e, Ct, sp, ip, np, Ch, mi, xh, Th, rp, vd, ap;
const ot = class ot extends lt {
constructor(e) {
super({
...e,
name: "freeTextEditor"
});
m(this, Ct);
m(this, Je);
m(this, ve, "");
m(this, Pl, `${this.id}-editor`);
m(this, ir, null);
m(this, _e);
f(this, Je, e.color || ot._defaultColor || lt._defaultLineColor), f(this, _e, e.fontSize || ot._defaultFontSize), this.annotationElementId || this._uiManager.a11yAlert("pdfjs-editor-freetext-added-alert");
}
static get _keyboardManager() {
const e = ot.prototype, s = (a) => a.isEmpty(), i = xr.TRANSLATE_SMALL, r = xr.TRANSLATE_BIG;
return X(this, "_keyboardManager", new Jl([[["ctrl+s", "mac+meta+s", "ctrl+p", "mac+meta+p"], e.commitOrRemove, {
bubbles: !0
}], [["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"], e.commitOrRemove], [["ArrowLeft", "mac+ArrowLeft"], e._translateEmpty, {
args: [-i, 0],
checker: s
}], [["ctrl+ArrowLeft", "mac+shift+ArrowLeft"], e._translateEmpty, {
args: [-r, 0],
checker: s
}], [["ArrowRight", "mac+ArrowRight"], e._translateEmpty, {
args: [i, 0],
checker: s
}], [["ctrl+ArrowRight", "mac+shift+ArrowRight"], e._translateEmpty, {
args: [r, 0],
checker: s
}], [["ArrowUp", "mac+ArrowUp"], e._translateEmpty, {
args: [0, -i],
checker: s
}], [["ctrl+ArrowUp", "mac+shift+ArrowUp"], e._translateEmpty, {
args: [0, -r],
checker: s
}], [["ArrowDown", "mac+ArrowDown"], e._translateEmpty, {
args: [0, i],
checker: s
}], [["ctrl+ArrowDown", "mac+shift+ArrowDown"], e._translateEmpty, {
args: [0, r],
checker: s
}]]));
}
static initialize(e, s) {
lt.initialize(e, s);
const i = getComputedStyle(document.documentElement);
this._internalPadding = parseFloat(i.getPropertyValue("--freetext-padding"));
}
static updateDefaultParams(e, s) {
switch (e) {
case Y.FREETEXT_SIZE:
ot._defaultFontSize = s;
break;
case Y.FREETEXT_COLOR:
ot._defaultColor = s;
break;
}
}
updateParams(e, s) {
switch (e) {
case Y.FREETEXT_SIZE:
b(this, Ct, sp).call(this, s);
break;
case Y.FREETEXT_COLOR:
b(this, Ct, ip).call(this, s);
break;
}
}
static get defaultPropertiesToUpdate() {
return [[Y.FREETEXT_SIZE, ot._defaultFontSize], [Y.FREETEXT_COLOR, ot._defaultColor || lt._defaultLineColor]];
}
get propertiesToUpdate() {
return [[Y.FREETEXT_SIZE, n(this, _e)], [Y.FREETEXT_COLOR, n(this, Je)]];
}
_translateEmpty(e, s) {
this._uiManager.translateSelectedEditors(e, s, !0);
}
getInitialTranslation() {
const e = this.parentScale;
return [-ot._internalPadding * e, -(ot._internalPadding + n(this, _e)) * e];
}
rebuild() {
this.parent && (super.rebuild(), this.div !== null && (this.isAttachedToDOM || this.parent.add(this)));
}
enableEditMode() {
if (!super.enableEditMode())
return !1;
this.overlayDiv.classList.remove("enabled"), this.editorDiv.contentEditable = !0, this._isDraggable = !1, this.div.removeAttribute("aria-activedescendant"), f(this, ir, new AbortController());
const e = this._uiManager.combinedSignal(n(this, ir));
return this.editorDiv.addEventListener("keydown", this.editorDivKeydown.bind(this), {
signal: e
}), this.editorDiv.addEventListener("focus", this.editorDivFocus.bind(this), {
signal: e
}), this.editorDiv.addEventListener("blur", this.editorDivBlur.bind(this), {
signal: e
}), this.editorDiv.addEventListener("input", this.editorDivInput.bind(this), {
signal: e
}), this.editorDiv.addEventListener("paste", this.editorDivPaste.bind(this), {
signal: e
}), !0;
}
disableEditMode() {
var e;
return super.disableEditMode() ? (this.overlayDiv.classList.add("enabled"), this.editorDiv.contentEditable = !1, this.div.setAttribute("aria-activedescendant", n(this, Pl)), this._isDraggable = !0, (e = n(this, ir)) == null || e.abort(), f(this, ir, null), this.div.focus({
preventScroll: !0
}), this.isEditing = !1, this.parent.div.classList.add("freetextEditing"), !0) : !1;
}
focusin(e) {
this._focusEventsAllowed && (super.focusin(e), e.target !== this.editorDiv && this.editorDiv.focus());
}
onceAdded(e) {
var s;
this.width || (this.enableEditMode(), e && this.editorDiv.focus(), (s = this._initialOptions) != null && s.isCentered && this.center(), this._initialOptions = null);
}
isEmpty() {
return !this.editorDiv || this.editorDiv.innerText.trim() === "";
}
remove() {
this.isEditing = !1, this.parent && (this.parent.setEditingState(!0), this.parent.div.classList.add("freetextEditing")), super.remove();
}
commit() {
if (!this.isInEditMode())
return;
super.commit(), this.disableEditMode();
const e = n(this, ve), s = f(this, ve, b(this, Ct, np).call(this).trimEnd());
if (e === s)
return;
const i = (r) => {
if (f(this, ve, r), !r) {
this.remove();
return;
}
b(this, Ct, Th).call(this), this._uiManager.rebuild(this), b(this, Ct, Ch).call(this);
};
this.addCommands({
cmd: () => {
i(s);
},
undo: () => {
i(e);
},
mustExec: !1
}), b(this, Ct, Ch).call(this);
}
shouldGetKeyboardEvents() {
return this.isInEditMode();
}
enterInEditMode() {
this.enableEditMode(), this.editorDiv.focus();
}
keydown(e) {
e.target === this.div && e.key === "Enter" && (this.enterInEditMode(), e.preventDefault());
}
editorDivKeydown(e) {
ot._keyboardManager.exec(this, e);
}
editorDivFocus(e) {
this.isEditing = !0;
}
editorDivBlur(e) {
this.isEditing = !1;
}
editorDivInput(e) {
this.parent.div.classList.toggle("freetextEditing", this.isEmpty());
}
disableEditing() {
this.editorDiv.setAttribute("role", "comment"), this.editorDiv.removeAttribute("aria-multiline");
}
enableEditing() {
this.editorDiv.setAttribute("role", "textbox"), this.editorDiv.setAttribute("aria-multiline", !0);
}
get canChangeContent() {
return !0;
}
render() {
if (this.div)
return this.div;
let e, s;
(this._isCopy || this.annotationElementId) && (e = this.x, s = this.y), super.render(), this.editorDiv = document.createElement("div"), this.editorDiv.className = "internal", this.editorDiv.setAttribute("id", n(this, Pl)), this.editorDiv.setAttribute("data-l10n-id", "pdfjs-free-text2"), this.editorDiv.setAttribute("data-l10n-attrs", "default-content"), this.enableEditing(), this.editorDiv.contentEditable = !0;
const {
style: i
} = this.editorDiv;
if (i.fontSize = `calc(${n(this, _e)}px * var(--total-scale-factor))`, i.color = n(this, Je), this.div.append(this.editorDiv), this.overlayDiv = document.createElement("div"), this.overlayDiv.classList.add("overlay", "enabled"), this.div.append(this.overlayDiv), this._isCopy || this.annotationElementId) {
const [r, a] = this.parentDimensions;
if (this.annotationElementId) {
const {
position: o
} = this._initialData;
let [l, h] = this.getInitialTranslation();
[l, h] = this.pageTranslationToScreen(l, h);
const [c, u] = this.pageDimensions, [p, g] = this.pageTranslation;
let A, y;
switch (this.rotation) {
case 0:
A = e + (o[0] - p) / c, y = s + this.height - (o[1] - g) / u;
break;
case 90:
A = e + (o[0] - p) / c, y = s - (o[1] - g) / u, [l, h] = [h, -l];
break;
case 180:
A = e - this.width + (o[0] - p) / c, y = s - (o[1] - g) / u, [l, h] = [-l, -h];
break;
case 270:
A = e + (o[0] - p - this.height * u) / c, y = s + (o[1] - g - this.width * c) / u, [l, h] = [-h, l];
break;
}
this.setAt(A * r, y * a, l, h);
} else
this._moveAfterPaste(e, s);
b(this, Ct, Th).call(this), this._isDraggable = !0, this.editorDiv.contentEditable = !1;
} else
this._isDraggable = !1, this.editorDiv.contentEditable = !0;
return this.div;
}
editorDivPaste(e) {
var A, y, w;
const s = e.clipboardData || window.clipboardData, {
types: i
} = s;
if (i.length === 1 && i[0] === "text/plain")
return;
e.preventDefault();
const r = b(A = ot, mi, vd).call(A, s.getData("text") || "").replaceAll(ah, `
`);
if (!r)
return;
const a = window.getSelection();
if (!a.rangeCount)
return;
this.editorDiv.normalize(), a.deleteFromDocument();
const o = a.getRangeAt(0);
if (!r.includes(`
`)) {
o.insertNode(document.createTextNode(r)), this.editorDiv.normalize(), a.collapseToStart();
return;
}
const {
startContainer: l,
startOffset: h
} = o, c = [], u = [];
if (l.nodeType === Node.TEXT_NODE) {
const v = l.parentElement;
if (u.push(l.nodeValue.slice(h).replaceAll(ah, "")), v !== this.editorDiv) {
let S = c;
for (const _ of this.editorDiv.childNodes) {
if (_ === v) {
S = u;
continue;
}
S.push(b(y = ot, mi, xh).call(y, _));
}
}
c.push(l.nodeValue.slice(0, h).replaceAll(ah, ""));
} else if (l === this.editorDiv) {
let v = c, S = 0;
for (const _ of this.editorDiv.childNodes)
S++ === h && (v = u), v.push(b(w = ot, mi, xh).call(w, _));
}
f(this, ve, `${c.join(`
`)}${r}${u.join(`
`)}`), b(this, Ct, Th).call(this);
const p = new Range();
let g = Math.sumPrecise(c.map((v) => v.length));
for (const {
firstChild: v
} of this.editorDiv.childNodes)
if (v.nodeType === Node.TEXT_NODE) {
const S = v.nodeValue.length;
if (g <= S) {
p.setStart(v, g), p.setEnd(v, g);
break;
}
g -= S;
}
a.removeAllRanges(), a.addRange(p);
}
get contentDiv() {
return this.editorDiv;
}
static async deserialize(e, s, i) {
var o;
let r = null;
if (e instanceof Jf) {
const {
data: {
defaultAppearanceData: {
fontSize: l,
fontColor: h
},
rect: c,
rotation: u,
id: p,
popupRef: g
},
textContent: A,
textPosition: y,
parent: {
page: {
pageNumber: w
}
}
} = e;
if (!A || A.length === 0)
return null;
r = e = {
annotationType: z.FREETEXT,
color: Array.from(h),
fontSize: l,
value: A.join(`
`),
position: y,
pageIndex: w - 1,
rect: c.slice(0),
rotation: u,
annotationElementId: p,
id: p,
deleted: !1,
popupRef: g
};
}
const a = await super.deserialize(e, s, i);
return f(a, _e, e.fontSize), f(a, Je, $.makeHexColor(...e.color)), f(a, ve, b(o = ot, mi, vd).call(o, e.value)), a._initialData = r, a;
}
serialize(e = !1) {
if (this.isEmpty())
return null;
if (this.deleted)
return this.serializeDeleted();
const s = ot._internalPadding * this.parentScale, i = this.getRect(s, s), r = lt._colorManager.convert(this.isAttachedToDOM ? getComputedStyle(this.editorDiv).color : n(this, Je)), a = {
annotationType: z.FREETEXT,
color: r,
fontSize: n(this, _e),
value: b(this, Ct, rp).call(this),
pageIndex: this.pageIndex,
rect: i,
rotation: this.rotation,
structTreeParentId: this._structTreeParentId
};
return e ? (a.isCopy = !0, a) : this.annotationElementId && !b(this, Ct, ap).call(this, a) ? null : (a.id = this.annotationElementId, a);
}
renderAnnotationElement(e) {
const s = super.renderAnnotationElement(e);
if (this.deleted)
return s;
const {
style: i
} = s;
i.fontSize = `calc(${n(this, _e)}px * var(--total-scale-factor))`, i.color = n(this, Je), s.replaceChildren();
for (const a of n(this, ve).split(`
`)) {
const o = document.createElement("div");
o.append(a ? document.createTextNode(a) : document.createElement("br")), s.append(o);
}
const r = ot._internalPadding * this.parentScale;
return e.updateEdited({
rect: this.getRect(r, r),
popupContent: n(this, ve)
}), s;
}
resetAnnotationElement(e) {
super.resetAnnotationElement(e), e.resetEdited();
}
};
Je = new WeakMap(), ve = new WeakMap(), Pl = new WeakMap(), ir = new WeakMap(), _e = new WeakMap(), Ct = new WeakSet(), sp = function(e) {
const s = (r) => {
this.editorDiv.style.fontSize = `calc(${r}px * var(--total-scale-factor))`, this.translate(0, -(r - n(this, _e)) * this.parentScale), f(this, _e, r), b(this, Ct, Ch).call(this);
}, i = n(this, _e);
this.addCommands({
cmd: s.bind(this, e),
undo: s.bind(this, i),
post: this._uiManager.updateUI.bind(this._uiManager, this),
mustExec: !0,
type: Y.FREETEXT_SIZE,
overwriteIfSameType: !0,
keepUndo: !0
});
}, ip = function(e) {
const s = (r) => {
f(this, Je, this.editorDiv.style.color = r);
}, i = n(this, Je);
this.addCommands({
cmd: s.bind(this, e),
undo: s.bind(this, i),
post: this._uiManager.updateUI.bind(this._uiManager, this),
mustExec: !0,
type: Y.FREETEXT_COLOR,
overwriteIfSameType: !0,
keepUndo: !0
});
}, np = function() {
var i;
const e = [];
this.editorDiv.normalize();
let s = null;
for (const r of this.editorDiv.childNodes)
(s == null ? void 0 : s.nodeType) === Node.TEXT_NODE && r.nodeName === "BR" || (e.push(b(i = ot, mi, xh).call(i, r)), s = r);
return e.join(`
`);
}, Ch = function() {
const [e, s] = this.parentDimensions;
let i;
if (this.isAttachedToDOM)
i = this.div.getBoundingClientRect();
else {
const {
currentLayer: r,
div: a
} = this, o = a.style.display, l = a.classList.contains("hidden");
a.classList.remove("hidden"), a.style.display = "hidden", r.div.append(this.div), i = a.getBoundingClientRect(), a.remove(), a.style.display = o, a.classList.toggle("hidden", l);
}
this.rotation % 180 === this.parentRotation % 180 ? (this.width = i.width / e, this.height = i.height / s) : (this.width = i.height / e, this.height = i.width / s), this.fixAndSetPosition();
}, mi = new WeakSet(), xh = function(e) {
return (e.nodeType === Node.TEXT_NODE ? e.nodeValue : e.innerText).replaceAll(ah, "");
}, Th = function() {
if (this.editorDiv.replaceChildren(), !!n(this, ve))
for (const e of n(this, ve).split(`
`)) {
const s = document.createElement("div");
s.append(e ? document.createTextNode(e) : document.createElement("br")), this.editorDiv.append(s);
}
}, rp = function() {
return n(this, ve).replaceAll(" ", " ");
}, vd = function(e) {
return e.replaceAll(" ", " ");
}, ap = function(e) {
const {
value: s,
fontSize: i,
color: r,
pageIndex: a
} = this._initialData;
return this._hasBeenMoved || e.value !== s || e.fontSize !== i || e.color.some((o, l) => o !== r[l]) || e.pageIndex !== a;
}, m(ot, mi), R(ot, "_freeTextDefaultContent", ""), R(ot, "_internalPadding", 0), R(ot, "_defaultColor", null), R(ot, "_defaultFontSize", 10), R(ot, "_type", "freetext"), R(ot, "_editorType", z.FREETEXT);
let wd = ot;
class L {
toSVGPath() {
rt("Abstract method `toSVGPath` must be implemented.");
}
get box() {
rt("Abstract getter `box` must be implemented.");
}
serialize(t, e) {
rt("Abstract method `serialize` must be implemented.");
}
static _rescale(t, e, s, i, r, a) {
a || (a = new Float32Array(t.length));
for (let o = 0, l = t.length; o < l; o += 2)
a[o] = e + t[o] * i, a[o + 1] = s + t[o + 1] * r;
return a;
}
static _rescaleAndSwap(t, e, s, i, r, a) {
a || (a = new Float32Array(t.length));
for (let o = 0, l = t.length; o < l; o += 2)
a[o] = e + t[o + 1] * i, a[o + 1] = s + t[o] * r;
return a;
}
static _translate(t, e, s, i) {
i || (i = new Float32Array(t.length));
for (let r = 0, a = t.length; r < a; r += 2)
i[r] = e + t[r], i[r + 1] = s + t[r + 1];
return i;
}
static svgRound(t) {
return Math.round(t * 1e4);
}
static _normalizePoint(t, e, s, i, r) {
switch (r) {
case 90:
return [1 - e / s, t / i];
case 180:
return [1 - t / s, 1 - e / i];
case 270:
return [e / s, 1 - t / i];
default:
return [t / s, e / i];
}
}
static _normalizePagePoint(t, e, s) {
switch (s) {
case 90:
return [1 - e, t];
case 180:
return [1 - t, 1 - e];
case 270:
return [e, 1 - t];
default:
return [t, e];
}
}
static createBezierPoints(t, e, s, i, r, a) {
return [(t + 5 * s) / 6, (e + 5 * i) / 6, (5 * s + r) / 6, (5 * i + a) / 6, (s + r) / 2, (i + a) / 2];
}
}
R(L, "PRECISION", 1e-4);
var Se, Ze, Ca, xa, vs, W, nr, rr, Il, Ml, Ta, Ra, Vi, kl, lc, hc, It, uo, op, lp, hp, cp, dp, up;
const Ns = class Ns {
constructor({
x: t,
y: e
}, s, i, r, a, o = 0) {
m(this, It);
m(this, Se);
m(this, Ze, []);
m(this, Ca);
m(this, xa);
m(this, vs, []);
m(this, W, new Float32Array(18));
m(this, nr);
m(this, rr);
m(this, Il);
m(this, Ml);
m(this, Ta);
m(this, Ra);
m(this, Vi, []);
f(this, Se, s), f(this, Ra, r * i), f(this, xa, a), n(this, W).set([NaN, NaN, NaN, NaN, t, e], 6), f(this, Ca, o), f(this, Ml, n(Ns, kl) * i), f(this, Il, n(Ns, hc) * i), f(this, Ta, i), n(this, Vi).push(t, e);
}
isEmpty() {
return isNaN(n(this, W)[8]);
}
add({
x: t,
y: e
}) {
var M;
f(this, nr, t), f(this, rr, e);
const [s, i, r, a] = n(this, Se);
let [o, l, h, c] = n(this, W).subarray(8, 12);
const u = t - h, p = e - c, g = Math.hypot(u, p);
if (g < n(this, Il))
return !1;
const A = g - n(this, Ml), y = A / g, w = y * u, v = y * p;
let S = o, _ = l;
o = h, l = c, h += w, c += v, (M = n(this, Vi)) == null || M.push(t, e);
const E = -v / A, C = w / A, x = E * n(this, Ra), T = C * n(this, Ra);
return n(this, W).set(n(this, W).subarray(2, 8), 0), n(this, W).set([h + x, c + T], 4), n(this, W).set(n(this, W).subarray(14, 18), 12), n(this, W).set([h - x, c - T], 16), isNaN(n(this, W)[6]) ? (n(this, vs).length === 0 && (n(this, W).set([o + x, l + T], 2), n(this, vs).push(NaN, NaN, NaN, NaN, (o + x - s) / r, (l + T - i) / a), n(this, W).set([o - x, l - T], 14), n(this, Ze).push(NaN, NaN, NaN, NaN, (o - x - s) / r, (l - T - i) / a)), n(this, W).set([S, _, o, l, h, c], 6), !this.isEmpty()) : (n(this, W).set([S, _, o, l, h, c], 6), Math.abs(Math.atan2(_ - l, S - o) - Math.atan2(v, w)) < Math.PI / 2 ? ([o, l, h, c] = n(this, W).subarray(2, 6), n(this, vs).push(NaN, NaN, NaN, NaN, ((o + h) / 2 - s) / r, ((l + c) / 2 - i) / a), [o, l, S, _] = n(this, W).subarray(14, 18), n(this, Ze).push(NaN, NaN, NaN, NaN, ((S + o) / 2 - s) / r, ((_ + l) / 2 - i) / a), !0) : ([S, _, o, l, h, c] = n(this, W).subarray(0, 6), n(this, vs).push(((S + 5 * o) / 6 - s) / r, ((_ + 5 * l) / 6 - i) / a, ((5 * o + h) / 6 - s) / r, ((5 * l + c) / 6 - i) / a, ((o + h) / 2 - s) / r, ((l + c) / 2 - i) / a), [h, c, o, l, S, _] = n(this, W).subarray(12, 18), n(this, Ze).push(((S + 5 * o) / 6 - s) / r, ((_ + 5 * l) / 6 - i) / a, ((5 * o + h) / 6 - s) / r, ((5 * l + c) / 6 - i) / a, ((o + h) / 2 - s) / r, ((l + c) / 2 - i) / a), !0));
}
toSVGPath() {
if (this.isEmpty())
return "";
const t = n(this, vs), e = n(this, Ze);
if (isNaN(n(this, W)[6]) && !this.isEmpty())
return b(this, It, op).call(this);
const s = [];
s.push(`M${t[4]} ${t[5]}`);
for (let i = 6; i < t.length; i += 6)
isNaN(t[i]) ? s.push(`L${t[i + 4]} ${t[i + 5]}`) : s.push(`C${t[i]} ${t[i + 1]} ${t[i + 2]} ${t[i + 3]} ${t[i + 4]} ${t[i + 5]}`);
b(this, It, hp).call(this, s);
for (let i = e.length - 6; i >= 6; i -= 6)
isNaN(e[i]) ? s.push(`L${e[i + 4]} ${e[i + 5]}`) : s.push(`C${e[i]} ${e[i + 1]} ${e[i + 2]} ${e[i + 3]} ${e[i + 4]} ${e[i + 5]}`);
return b(this, It, lp).call(this, s), s.join(" ");
}
newFreeDrawOutline(t, e, s, i, r, a) {
return new fp(t, e, s, i, r, a);
}
getOutlines() {
var u;
const t = n(this, vs), e = n(this, Ze), s = n(this, W), [i, r, a, o] = n(this, Se), l = new Float32Array((((u = n(this, Vi)) == null ? void 0 : u.length) ?? 0) + 2);
for (let p = 0, g = l.length - 2; p < g; p += 2)
l[p] = (n(this, Vi)[p] - i) / a, l[p + 1] = (n(this, Vi)[p + 1] - r) / o;
if (l[l.length - 2] = (n(this, nr) - i) / a, l[l.length - 1] = (n(this, rr) - r) / o, isNaN(s[6]) && !this.isEmpty())
return b(this, It, cp).call(this, l);
const h = new Float32Array(n(this, vs).length + 24 + n(this, Ze).length);
let c = t.length;
for (let p = 0; p < c; p += 2) {
if (isNaN(t[p])) {
h[p] = h[p + 1] = NaN;
continue;
}
h[p] = t[p], h[p + 1] = t[p + 1];
}
c = b(this, It, up).call(this, h, c);
for (let p = e.length - 6; p >= 6; p -= 6)
for (let g = 0; g < 6; g += 2) {
if (isNaN(e[p + g])) {
h[c] = h[c + 1] = NaN, c += 2;
continue;
}
h[c] = e[p + g], h[c + 1] = e[p + g + 1], c += 2;
}
return b(this, It, dp).call(this, h, c), this.newFreeDrawOutline(h, l, n(this, Se), n(this, Ta), n(this, Ca), n(this, xa));
}
};
Se = new WeakMap(), Ze = new WeakMap(), Ca = new WeakMap(), xa = new WeakMap(), vs = new WeakMap(), W = new WeakMap(), nr = new WeakMap(), rr = new WeakMap(), Il = new WeakMap(), Ml = new WeakMap(), Ta = new WeakMap(), Ra = new WeakMap(), Vi = new WeakMap(), kl = new WeakMap(), lc = new WeakMap(), hc = new WeakMap(), It = new WeakSet(), uo = function() {
const t = n(this, W).subarray(4, 6), e = n(this, W).subarray(16, 18), [s, i, r, a] = n(this, Se);
return [(n(this, nr) + (t[0] - e[0]) / 2 - s) / r, (n(this, rr) + (t[1] - e[1]) / 2 - i) / a, (n(this, nr) + (e[0] - t[0]) / 2 - s) / r, (n(this, rr) + (e[1] - t[1]) / 2 - i) / a];
}, op = function() {
const [t, e, s, i] = n(this, Se), [r, a, o, l] = b(this, It, uo).call(this);
return `M${(n(this, W)[2] - t) / s} ${(n(this, W)[3] - e) / i} L${(n(this, W)[4] - t) / s} ${(n(this, W)[5] - e) / i} L${r} ${a} L${o} ${l} L${(n(this, W)[16] - t) / s} ${(n(this, W)[17] - e) / i} L${(n(this, W)[14] - t) / s} ${(n(this, W)[15] - e) / i} Z`;
}, lp = function(t) {
const e = n(this, Ze);
t.push(`L${e[4]} ${e[5]} Z`);
}, hp = function(t) {
const [e, s, i, r] = n(this, Se), a = n(this, W).subarray(4, 6), o = n(this, W).subarray(16, 18), [l, h, c, u] = b(this, It, uo).call(this);
t.push(`L${(a[0] - e) / i} ${(a[1] - s) / r} L${l} ${h} L${c} ${u} L${(o[0] - e) / i} ${(o[1] - s) / r}`);
}, cp = function(t) {
const e = n(this, W), [s, i, r, a] = n(this, Se), [o, l, h, c] = b(this, It, uo).call(this), u = new Float32Array(36);
return u.set([NaN, NaN, NaN, NaN, (e[2] - s) / r, (e[3] - i) / a, NaN, NaN, NaN, NaN, (e[4] - s) / r, (e[5] - i) / a, NaN, NaN, NaN, NaN, o, l, NaN, NaN, NaN, NaN, h, c, NaN, NaN, NaN, NaN, (e[16] - s) / r, (e[17] - i) / a, NaN, NaN, NaN, NaN, (e[14] - s) / r, (e[15] - i) / a], 0), this.newFreeDrawOutline(u, t, n(this, Se), n(this, Ta), n(this, Ca), n(this, xa));
}, dp = function(t, e) {
const s = n(this, Ze);
return t.set([NaN, NaN, NaN, NaN, s[4], s[5]], e), e += 6;
}, up = function(t, e) {
const s = n(this, W).subarray(4, 6), i = n(this, W).subarray(16, 18), [r, a, o, l] = n(this, Se), [h, c, u, p] = b(this, It, uo).call(this);
return t.set([NaN, NaN, NaN, NaN, (s[0] - r) / o, (s[1] - a) / l, NaN, NaN, NaN, NaN, h, c, NaN, NaN, NaN, NaN, u, p, NaN, NaN, NaN, NaN, (i[0] - r) / o, (i[1] - a) / l], e), e += 24;
}, m(Ns, kl, 8), m(Ns, lc, 2), m(Ns, hc, n(Ns, kl) + n(Ns, lc));
let jh = Ns;
var Pa, ar, ni, Ll, Ee, Dl, yt, cc, pp;
class fp extends L {
constructor(e, s, i, r, a, o) {
super();
m(this, cc);
m(this, Pa);
m(this, ar, new Float32Array(4));
m(this, ni);
m(this, Ll);
m(this, Ee);
m(this, Dl);
m(this, yt);
f(this, yt, e), f(this, Ee, s), f(this, Pa, i), f(this, Dl, r), f(this, ni, a), f(this, Ll, o), this.lastPoint = [NaN, NaN], b(this, cc, pp).call(this, o);
const [l, h, c, u] = n(this, ar);
for (let p = 0, g = e.length; p < g; p += 2)
e[p] = (e[p] - l) / c, e[p + 1] = (e[p + 1] - h) / u;
for (let p = 0, g = s.length; p < g; p += 2)
s[p] = (s[p] - l) / c, s[p + 1] = (s[p + 1] - h) / u;
}
toSVGPath() {
const e = [`M${n(this, yt)[4]} ${n(this, yt)[5]}`];
for (let s = 6, i = n(this, yt).length; s < i; s += 6) {
if (isNaN(n(this, yt)[s])) {
e.push(`L${n(this, yt)[s + 4]} ${n(this, yt)[s + 5]}`);
continue;
}
e.push(`C${n(this, yt)[s]} ${n(this, yt)[s + 1]} ${n(this, yt)[s + 2]} ${n(this, yt)[s + 3]} ${n(this, yt)[s + 4]} ${n(this, yt)[s + 5]}`);
}
return e.push("Z"), e.join(" ");
}
serialize([e, s, i, r], a) {
const o = i - e, l = r - s;
let h, c;
switch (a) {
case 0:
h = L._rescale(n(this, yt), e, r, o, -l), c = L._rescale(n(this, Ee), e, r, o, -l);
break;
case 90:
h = L._rescaleAndSwap(n(this, yt), e, s, o, l), c = L._rescaleAndSwap(n(this, Ee), e, s, o, l);
break;
case 180:
h = L._rescale(n(this, yt), i, s, -o, l), c = L._rescale(n(this, Ee), i, s, -o, l);
break;
case 270:
h = L._rescaleAndSwap(n(this, yt), i, r, -o, -l), c = L._rescaleAndSwap(n(this, Ee), i, r, -o, -l);
break;
}
return {
outline: Array.from(h),
points: [Array.from(c)]
};
}
get box() {
return n(this, ar);
}
newOutliner(e, s, i, r, a, o = 0) {
return new jh(e, s, i, r, a, o);
}
getNewOutline(e, s) {
const [i, r, a, o] = n(this, ar), [l, h, c, u] = n(this, Pa), p = a * c, g = o * u, A = i * c + l, y = r * u + h, w = this.newOutliner({
x: n(this, Ee)[0] * p + A,
y: n(this, Ee)[1] * g + y
}, n(this, Pa), n(this, Dl), e, n(this, Ll), s ?? n(this, ni));
for (let v = 2; v < n(this, Ee).length; v += 2)
w.add({
x: n(this, Ee)[v] * p + A,
y: n(this, Ee)[v + 1] * g + y
});
return w.getOutlines();
}
}
Pa = new WeakMap(), ar = new WeakMap(), ni = new WeakMap(), Ll = new WeakMap(), Ee = new WeakMap(), Dl = new WeakMap(), yt = new WeakMap(), cc = new WeakSet(), pp = function(e) {
const s = n(this, yt);
let i = s[4], r = s[5];
const a = [i, r, i, r];
let o = i, l = r;
const h = e ? Math.max : Math.min;
for (let u = 6, p = s.length; u < p; u += 6) {
const g = s[u + 4], A = s[u + 5];
if (isNaN(s[u]))
$.pointBoundingBox(g, A, a), l < A ? (o = g, l = A) : l === A && (o = h(o, g));
else {
const y = [1 / 0, 1 / 0, -1 / 0, -1 / 0];
$.bezierBoundingBox(i, r, ...s.slice(u, u + 6), y), $.rectBoundingBox(...y, a), l < y[3] ? (o = y[2], l = y[3]) : l === y[3] && (o = h(o, y[2]));
}
i = g, r = A;
}
const c = n(this, ar);
c[0] = a[0] - n(this, ni), c[1] = a[1] - n(this, ni), c[2] = a[2] - a[0] + 2 * n(this, ni), c[3] = a[3] - a[1] + 2 * n(this, ni), this.lastPoint = [o, l];
};
var Fl, Nl, Wi, ts, he, gp, Rh, mp, bp, Sd;
class _d {
constructor(t, e = 0, s = 0, i = !0) {
m(this, he);
m(this, Fl);
m(this, Nl);
m(this, Wi, []);
m(this, ts, []);
const r = [1 / 0, 1 / 0, -1 / 0, -1 / 0], a = 10 ** -4;
for (const {
x: g,
y: A,
width: y,
height: w
} of t) {
const v = Math.floor((g - e) / a) * a, S = Math.ceil((g + y + e) / a) * a, _ = Math.floor((A - e) / a) * a, E = Math.ceil((A + w + e) / a) * a, C = [v, _, E, !0], x = [S, _, E, !1];
n(this, Wi).push(C, x), $.rectBoundingBox(v, _, S, E, r);
}
const o = r[2] - r[0] + 2 * s, l = r[3] - r[1] + 2 * s, h = r[0] - s, c = r[1] - s, u = n(this, Wi).at(i ? -1 : -2), p = [u[0], u[2]];
for (const g of n(this, Wi)) {
const [A, y, w] = g;
g[0] = (A - h) / o, g[1] = (y - c) / l, g[2] = (w - c) / l;
}
f(this, Fl, new Float32Array([h, c, o, l])), f(this, Nl, p);
}
getOutlines() {
n(this, Wi).sort((e, s) => e[0] - s[0] || e[1] - s[1] || e[2] - s[2]);
const t = [];
for (const e of n(this, Wi))
e[3] ? (t.push(...b(this, he, Sd).call(this, e)), b(this, he, mp).call(this, e)) : (b(this, he, bp).call(this, e), t.push(...b(this, he, Sd).call(this, e)));
return b(this, he, gp).call(this, t);
}
}
Fl = new WeakMap(), Nl = new WeakMap(), Wi = new WeakMap(), ts = new WeakMap(), he = new WeakSet(), gp = function(t) {
const e = [], s = /* @__PURE__ */ new Set();
for (const a of t) {
const [o, l, h] = a;
e.push([o, l, a], [o, h, a]);
}
e.sort((a, o) => a[1] - o[1] || a[0] - o[0]);
for (let a = 0, o = e.length; a < o; a += 2) {
const l = e[a][2], h = e[a + 1][2];
l.push(h), h.push(l), s.add(l), s.add(h);
}
const i = [];
let r;
for (; s.size > 0; ) {
const a = s.values().next().value;
let [o, l, h, c, u] = a;
s.delete(a);
let p = o, g = l;
for (r = [o, h], i.push(r); ; ) {
let A;
if (s.has(c))
A = c;
else if (s.has(u))
A = u;
else
break;
s.delete(A), [o, l, h, c, u] = A, p !== o && (r.push(p, g, o, g === l ? l : h), p = o), g = g === l ? h : l;
}
r.push(p, g);
}
return new Nm(i, n(this, Fl), n(this, Nl));
}, Rh = function(t) {
const e = n(this, ts);
let s = 0, i = e.length - 1;
for (; s <= i; ) {
const r = s + i >> 1, a = e[r][0];
if (a === t)
return r;
a < t ? s = r + 1 : i = r - 1;
}
return i + 1;
}, mp = function([, t, e]) {
const s = b(this, he, Rh).call(this, t);
n(this, ts).splice(s, 0, [t, e]);
}, bp = function([, t, e]) {
const s = b(this, he, Rh).call(this, t);
for (let i = s; i < n(this, ts).length; i++) {
const [r, a] = n(this, ts)[i];
if (r !== t)
break;
if (r === t && a === e) {
n(this, ts).splice(i, 1);
return;
}
}
for (let i = s - 1; i >= 0; i--) {
const [r, a] = n(this, ts)[i];
if (r !== t)
break;
if (r === t && a === e) {
n(this, ts).splice(i, 1);
return;
}
}
}, Sd = function(t) {
const [e, s, i] = t, r = [[e, s, i]], a = b(this, he, Rh).call(this, i);
for (let o = 0; o < a; o++) {
const [l, h] = n(this, ts)[o];
for (let c = 0, u = r.length; c < u; c++) {
const [, p, g] = r[c];
if (!(h <= p || g <= l)) {
if (p >= l) {
if (g > h)
r[c][1] = h;
else {
if (u === 1)
return [];
r.splice(c, 1), c--, u--;
}
continue;
}
r[c][2] = l, g > h && r.push([e, h, g]);
}
}
}
return r;
};
var Ol, Ia;
class Nm extends L {
constructor(e, s, i) {
super();
m(this, Ol);
m(this, Ia);
f(this, Ia, e), f(this, Ol, s), this.lastPoint = i;
}
toSVGPath() {
const e = [];
for (const s of n(this, Ia)) {
let [i, r] = s;
e.push(`M${i} ${r}`);
for (let a = 2; a < s.length; a += 2) {
const o = s[a], l = s[a + 1];
o === i ? (e.push(`V${l}`), r = l) : l === r && (e.push(`H${o}`), i = o);
}
e.push("Z");
}
return e.join(" ");
}
serialize([e, s, i, r], a) {
const o = [], l = i - e, h = r - s;
for (const c of n(this, Ia)) {
const u = new Array(c.length);
for (let p = 0; p < c.length; p += 2)
u[p] = e + c[p] * l, u[p + 1] = r - c[p + 1] * h;
o.push(u);
}
return o;
}
get box() {
return n(this, Ol);
}
get classNamesForOutlining() {
return ["highlightOutline"];
}
}
Ol = new WeakMap(), Ia = new WeakMap();
class Ed extends jh {
newFreeDrawOutline(t, e, s, i, r, a) {
return new Om(t, e, s, i, r, a);
}
}
class Om extends fp {
newOutliner(t, e, s, i, r, a = 0) {
return new Ed(t, e, s, i, r, a);
}
}
var Ce, or, Ma, Pt, Bl, ka, ri, Hl, qi, es, La, $l, nt, Cd, xd, Td, fn, Ap, wi;
const de = class de {
constructor({
editor: t = null,
uiManager: e = null
}) {
m(this, nt);
m(this, Ce, null);
m(this, or, null);
m(this, Ma);
m(this, Pt, null);
m(this, Bl, !1);
m(this, ka, !1);
m(this, ri, null);
m(this, Hl);
m(this, qi, null);
m(this, es, null);
m(this, La);
var s, i;
t ? (f(this, ka, !1), f(this, La, Y.HIGHLIGHT_COLOR), f(this, ri, t)) : (f(this, ka, !0), f(this, La, Y.HIGHLIGHT_DEFAULT_COLOR)), f(this, es, (t == null ? void 0 : t._uiManager) || e), f(this, Hl, n(this, es)._eventBus), f(this, Ma, ((s = t == null ? void 0 : t.color) == null ? void 0 : s.toUpperCase()) || ((i = n(this, es)) == null ? void 0 : i.highlightColors.values().next().value) || "#FFFF98"), n(de, $l) || f(de, $l, Object.freeze({
blue: "pdfjs-editor-colorpicker-blue",
green: "pdfjs-editor-colorpicker-green",
pink: "pdfjs-editor-colorpicker-pink",
red: "pdfjs-editor-colorpicker-red",
yellow: "pdfjs-editor-colorpicker-yellow"
}));
}
static get _keyboardManager() {
return X(this, "_keyboardManager", new Jl([[["Escape", "mac+Escape"], de.prototype._hideDropdownFromKeyboard], [[" ", "mac+ "], de.prototype._colorSelectFromKeyboard], [["ArrowDown", "ArrowRight", "mac+ArrowDown", "mac+ArrowRight"], de.prototype._moveToNext], [["ArrowUp", "ArrowLeft", "mac+ArrowUp", "mac+ArrowLeft"], de.prototype._moveToPrevious], [["Home", "mac+Home"], de.prototype._moveToBeginning], [["End", "mac+End"], de.prototype._moveToEnd]]));
}
renderButton() {
const t = f(this, Ce, document.createElement("button"));
t.className = "colorPicker", t.tabIndex = "0", t.setAttribute("data-l10n-id", "pdfjs-editor-colorpicker-button"), t.ariaHasPopup = "true", n(this, ri) && (t.ariaControls = `${n(this, ri).id}_colorpicker_dropdown`);
const e = n(this, es)._signal;
t.addEventListener("click", b(this, nt, fn).bind(this), {
signal: e
}), t.addEventListener("keydown", b(this, nt, Td).bind(this), {
signal: e
});
const s = f(this, or, document.createElement("span"));
return s.className = "swatch", s.ariaHidden = "true", s.style.backgroundColor = n(this, Ma), t.append(s), t;
}
renderMainDropdown() {
const t = f(this, Pt, b(this, nt, Cd).call(this));
return t.ariaOrientation = "horizontal", t.ariaLabelledBy = "highlightColorPickerLabel", t;
}
_colorSelectFromKeyboard(t) {
if (t.target === n(this, Ce)) {
b(this, nt, fn).call(this, t);
return;
}
const e = t.target.getAttribute("data-color");
e && b(this, nt, xd).call(this, e, t);
}
_moveToNext(t) {
var e, s;
if (!n(this, nt, wi)) {
b(this, nt, fn).call(this, t);
return;
}
if (t.target === n(this, Ce)) {
(e = n(this, Pt).firstChild) == null || e.focus();
return;
}
(s = t.target.nextSibling) == null || s.focus();
}
_moveToPrevious(t) {
var e, s;
if (t.target === ((e = n(this, Pt)) == null ? void 0 : e.firstChild) || t.target === n(this, Ce)) {
n(this, nt, wi) && this._hideDropdownFromKeyboard();
return;
}
n(this, nt, wi) || b(this, nt, fn).call(this, t), (s = t.target.previousSibling) == null || s.focus();
}
_moveToBeginning(t) {
var e;
if (!n(this, nt, wi)) {
b(this, nt, fn).call(this, t);
return;
}
(e = n(this, Pt).firstChild) == null || e.focus();
}
_moveToEnd(t) {
var e;
if (!n(this, nt, wi)) {
b(this, nt, fn).call(this, t);
return;
}
(e = n(this, Pt).lastChild) == null || e.focus();
}
hideDropdown() {
var t, e;
(t = n(this, Pt)) == null || t.classList.add("hidden"), n(this, Ce).ariaExpanded = "false", (e = n(this, qi)) == null || e.abort(), f(this, qi, null);
}
_hideDropdownFromKeyboard() {
var t;
if (!n(this, ka)) {
if (!n(this, nt, wi)) {
(t = n(this, ri)) == null || t.unselect();
return;
}
this.hideDropdown(), n(this, Ce).focus({
preventScroll: !0,
focusVisible: n(this, Bl)
});
}
}
updateColor(t) {
if (n(this, or) && (n(this, or).style.backgroundColor = t), !n(this, Pt))
return;
const e = n(this, es).highlightColors.values();
for (const s of n(this, Pt).children)
s.ariaSelected = e.next().value === t.toUpperCase();
}
destroy() {
var t, e;
(t = n(this, Ce)) == null || t.remove(), f(this, Ce, null), f(this, or, null), (e = n(this, Pt)) == null || e.remove(), f(this, Pt, null);
}
};
Ce = new WeakMap(), or = new WeakMap(), Ma = new WeakMap(), Pt = new WeakMap(), Bl = new WeakMap(), ka = new WeakMap(), ri = new WeakMap(), Hl = new WeakMap(), qi = new WeakMap(), es = new WeakMap(), La = new WeakMap(), $l = new WeakMap(), nt = new WeakSet(), Cd = function() {
const t = document.createElement("div"), e = n(this, es)._signal;
t.addEventListener("contextmenu", as, {
signal: e
}), t.className = "dropdown", t.role = "listbox", t.ariaMultiSelectable = "false", t.ariaOrientation = "vertical", t.setAttribute("data-l10n-id", "pdfjs-editor-colorpicker-dropdown"), n(this, ri) && (t.id = `${n(this, ri).id}_colorpicker_dropdown`);
for (const [s, i] of n(this, es).highlightColors) {
const r = document.createElement("button");
r.tabIndex = "0", r.role = "option", r.setAttribute("data-color", i), r.title = s, r.setAttribute("data-l10n-id", n(de, $l)[s]);
const a = document.createElement("span");
r.append(a), a.className = "swatch", a.style.backgroundColor = i, r.ariaSelected = i === n(this, Ma), r.addEventListener("click", b(this, nt, xd).bind(this, i), {
signal: e
}), t.append(r);
}
return t.addEventListener("keydown", b(this, nt, Td).bind(this), {
signal: e
}), t;
}, xd = function(t, e) {
e.stopPropagation(), n(this, Hl).dispatch("switchannotationeditorparams", {
source: this,
type: n(this, La),
value: t
});
}, Td = function(t) {
de._keyboardManager.exec(this, t);
}, fn = function(t) {
if (n(this, nt, wi)) {
this.hideDropdown();
return;
}
if (f(this, Bl, t.detail === 0), n(this, qi) || (f(this, qi, new AbortController()), window.addEventListener("pointerdown", b(this, nt, Ap).bind(this), {
signal: n(this, es).combinedSignal(n(this, qi))
})), n(this, Ce).ariaExpanded = "true", n(this, Pt)) {
n(this, Pt).classList.remove("hidden");
return;
}
const e = f(this, Pt, b(this, nt, Cd).call(this));
n(this, Ce).append(e);
}, Ap = function(t) {
var e;
(e = n(this, Pt)) != null && e.contains(t.target) || this.hideDropdown();
}, wi = function() {
return n(this, Pt) && !n(this, Pt).classList.contains("hidden");
}, m(de, $l, null);
let Vh = de;
var Da, Gl, ai, lr, zl, pe, Ul, jl, hr, Ge, xe, zt, Fa, oi, Qt, Na, ze, Vl, j, Rd, Ph, yp, wp, vp, Pd, pn, je, Nr, _p, Ih, fo, Sp, Ep, Cp, xp, Tp;
const J = class J extends lt {
constructor(e) {
super({
...e,
name: "highlightEditor"
});
m(this, j);
m(this, Da, null);
m(this, Gl, 0);
m(this, ai);
m(this, lr, null);
m(this, zl, null);
m(this, pe, null);
m(this, Ul, null);
m(this, jl, 0);
m(this, hr, null);
m(this, Ge, null);
m(this, xe, null);
m(this, zt, !1);
m(this, Fa, null);
m(this, oi);
m(this, Qt, null);
m(this, Na, "");
m(this, ze);
m(this, Vl, "");
this.color = e.color || J._defaultColor, f(this, ze, e.thickness || J._defaultThickness), f(this, oi, e.opacity || J._defaultOpacity), f(this, ai, e.boxes || null), f(this, Vl, e.methodOfCreation || ""), f(this, Na, e.text || ""), this._isDraggable = !1, this.defaultL10nId = "pdfjs-editor-highlight-editor", e.highlightId > -1 ? (f(this, zt, !0), b(this, j, Ph).call(this, e), b(this, j, pn).call(this)) : n(this, ai) && (f(this, Da, e.anchorNode), f(this, Gl, e.anchorOffset), f(this, Ul, e.focusNode), f(this, jl, e.focusOffset), b(this, j, Rd).call(this), b(this, j, pn).call(this), this.rotate(this.rotation)), this.annotationElementId || this._uiManager.a11yAlert("pdfjs-editor-highlight-added-alert");
}
static get _keyboardManager() {
const e = J.prototype;
return X(this, "_keyboardManager", new Jl([[["ArrowLeft", "mac+ArrowLeft"], e._moveCaret, {
args: [0]
}], [["ArrowRight", "mac+ArrowRight"], e._moveCaret, {
args: [1]
}], [["ArrowUp", "mac+ArrowUp"], e._moveCaret, {
args: [2]
}], [["ArrowDown", "mac+ArrowDown"], e._moveCaret, {
args: [3]
}]]));
}
get telemetryInitialData() {
return {
action: "added",
type: n(this, zt) ? "free_highlight" : "highlight",
color: this._uiManager.highlightColorNames.get(this.color),
thickness: n(this, ze),
methodOfCreation: n(this, Vl)
};
}
get telemetryFinalData() {
return {
type: "highlight",
color: this._uiManager.highlightColorNames.get(this.color)
};
}
static computeTelemetryFinalData(e) {
return {
numberOfColors: e.get("color").size
};
}
static initialize(e, s) {
var i;
lt.initialize(e, s), J._defaultColor || (J._defaultColor = ((i = s.highlightColors) == null ? void 0 : i.values().next().value) || "#fff066");
}
static updateDefaultParams(e, s) {
switch (e) {
case Y.HIGHLIGHT_DEFAULT_COLOR:
J._defaultColor = s;
break;
case Y.HIGHLIGHT_THICKNESS:
J._defaultThickness = s;
break;
}
}
translateInPage(e, s) {
}
get toolbarPosition() {
return n(this, Fa);
}
updateParams(e, s) {
switch (e) {
case Y.HIGHLIGHT_COLOR:
b(this, j, yp).call(this, s);
break;
case Y.HIGHLIGHT_THICKNESS:
b(this, j, wp).call(this, s);
break;
}
}
static get defaultPropertiesToUpdate() {
return [[Y.HIGHLIGHT_DEFAULT_COLOR, J._defaultColor], [Y.HIGHLIGHT_THICKNESS, J._defaultThickness]];
}
get propertiesToUpdate() {
return [[Y.HIGHLIGHT_COLOR, this.color || J._defaultColor], [Y.HIGHLIGHT_THICKNESS, n(this, ze) || J._defaultThickness], [Y.HIGHLIGHT_FREE, n(this, zt)]];
}
get toolbarButtons() {
return this._uiManager.highlightColors ? [["colorPicker", f(this, zl, new Vh({
editor: this
}))]] : super.toolbarButtons;
}
disableEditing() {
super.disableEditing(), this.div.classList.toggle("disabled", !0);
}
enableEditing() {
super.enableEditing(), this.div.classList.toggle("disabled", !1);
}
fixAndSetPosition() {
return super.fixAndSetPosition(b(this, j, fo).call(this));
}
getBaseTranslation() {
return [0, 0];
}
getRect(e, s) {
return super.getRect(e, s, b(this, j, fo).call(this));
}
onceAdded(e) {
this.annotationElementId || this.parent.addUndoableEditor(this), e && this.div.focus();
}
remove() {
b(this, j, Pd).call(this), this._reportTelemetry({
action: "deleted"
}), super.remove();
}
rebuild() {
this.parent && (super.rebuild(), this.div !== null && (b(this, j, pn).call(this), this.isAttachedToDOM || this.parent.add(this)));
}
setParent(e) {
var i;
let s = !1;
this.parent && !e ? b(this, j, Pd).call(this) : e && (b(this, j, pn).call(this, e), s = !this.parent && ((i = this.div) == null ? void 0 : i.classList.contains("selectedEditor"))), super.setParent(e), this.show(this._isVisible), s && this.select();
}
rotate(e) {
var r, a, o;
const {
drawLayer: s
} = this.parent;
let i;
n(this, zt) ? (e = (e - this.rotation + 360) % 360, i = b(r = J, je, Nr).call(r, n(this, Ge).box, e)) : i = b(a = J, je, Nr).call(a, [this.x, this.y, this.width, this.height], e), s.updateProperties(n(this, xe), {
bbox: i,
root: {
"data-main-rotation": e
}
}), s.updateProperties(n(this, Qt), {
bbox: b(o = J, je, Nr).call(o, n(this, pe).box, e),
root: {
"data-main-rotation": e
}
});
}
render() {
if (this.div)
return this.div;
const e = super.render();
n(this, Na) && (e.setAttribute("aria-label", n(this, Na)), e.setAttribute("role", "mark")), n(this, zt) ? e.classList.add("free") : this.div.addEventListener("keydown", b(this, j, _p).bind(this), {
signal: this._uiManager._signal
});
const s = f(this, hr, document.createElement("div"));
e.append(s), s.setAttribute("aria-hidden", "true"), s.className = "internal", s.style.clipPath = n(this, lr);
const [i, r] = this.parentDimensions;
return this.setDims(this.width * i, this.height * r), Wu(this, n(this, hr), ["pointerover", "pointerleave"]), this.enableEditing(), e;
}
pointerover() {
var e;
this.isSelected || (e = this.parent) == null || e.drawLayer.updateProperties(n(this, Qt), {
rootClass: {
hovered: !0
}
});
}
pointerleave() {
var e;
this.isSelected || (e = this.parent) == null || e.drawLayer.updateProperties(n(this, Qt), {
rootClass: {
hovered: !1
}
});
}
_moveCaret(e) {
switch (this.parent.unselect(this), e) {
case 0:
case 2:
b(this, j, Ih).call(this, !0);
break;
case 1:
case 3:
b(this, j, Ih).call(this, !1);
break;
}
}
select() {
var e;
super.select(), n(this, Qt) && ((e = this.parent) == null || e.drawLayer.updateProperties(n(this, Qt), {
rootClass: {
hovered: !1,
selected: !0
}
}));
}
unselect() {
var e;
super.unselect(), n(this, Qt) && ((e = this.parent) == null || e.drawLayer.updateProperties(n(this, Qt), {
rootClass: {
selected: !1
}
}), n(this, zt) || b(this, j, Ih).call(this, !1));
}
get _mustFixPosition() {
return !n(this, zt);
}
show(e = this._isVisible) {
super.show(e), this.parent && (this.parent.drawLayer.updateProperties(n(this, xe), {
rootClass: {
hidden: !e
}
}), this.parent.drawLayer.updateProperties(n(this, Qt), {
rootClass: {
hidden: !e
}
}));
}
static startHighlighting(e, s, {
target: i,
x: r,
y: a
}) {
const {
x: o,
y: l,
width: h,
height: c
} = i.getBoundingClientRect(), u = new AbortController(), p = e.combinedSignal(u), g = (A) => {
u.abort(), b(this, je, xp).call(this, e, A);
};
window.addEventListener("blur", g, {
signal: p
}), window.addEventListener("pointerup", g, {
signal: p
}), window.addEventListener("pointerdown", St, {
capture: !0,
passive: !1,
signal: p
}), window.addEventListener("contextmenu", as, {
signal: p
}), i.addEventListener("pointermove", b(this, je, Cp).bind(this, e), {
signal: p
}), this._freeHighlight = new Ed({
x: r,
y: a
}, [o, l, h, c], e.scale, this._defaultThickness / 2, s, 1e-3), {
id: this._freeHighlightId,
clipPathId: this._freeHighlightClipId
} = e.drawLayer.draw({
bbox: [0, 0, 1, 1],
root: {
viewBox: "0 0 1 1",
fill: this._defaultColor,
"fill-opacity": this._defaultOpacity
},
rootClass: {
highlight: !0,
free: !0
},
path: {
d: this._freeHighlight.toSVGPath()
}
}, !0, !0);
}
static async deserialize(e, s, i) {
var y, w, v, S;
let r = null;
if (e instanceof tp) {
const {
data: {
quadPoints: _,
rect: E,
rotation: C,
id: x,
color: T,
opacity: P,
popupRef: M
},
parent: {
page: {
pageNumber: O
}
}
} = e;
r = e = {
annotationType: z.HIGHLIGHT,
color: Array.from(T),
opacity: P,
quadPoints: _,
boxes: null,
pageIndex: O - 1,
rect: E.slice(0),
rotation: C,
annotationElementId: x,
id: x,
deleted: !1,
popupRef: M
};
} else if (e instanceof su) {
const {
data: {
inkLists: _,
rect: E,
rotation: C,
id: x,
color: T,
borderStyle: {
rawWidth: P
},
popupRef: M
},
parent: {
page: {
pageNumber: O
}
}
} = e;
r = e = {
annotationType: z.HIGHLIGHT,
color: Array.from(T),
thickness: P,
inkLists: _,
boxes: null,
pageIndex: O - 1,
rect: E.slice(0),
rotation: C,
annotationElementId: x,
id: x,
deleted: !1,
popupRef: M
};
}
const {
color: a,
quadPoints: o,
inkLists: l,
opacity: h
} = e, c = await super.deserialize(e, s, i);
c.color = $.makeHexColor(...a), f(c, oi, h || 1), l && f(c, ze, e.thickness), c._initialData = r;
const [u, p] = c.pageDimensions, [g, A] = c.pageTranslation;
if (o) {
const _ = f(c, ai, []);
for (let E = 0; E < o.length; E += 8)
_.push({
x: (o[E] - g) / u,
y: 1 - (o[E + 1] - A) / p,
width: (o[E + 2] - o[E]) / u,
height: (o[E + 1] - o[E + 5]) / p
});
b(y = c, j, Rd).call(y), b(w = c, j, pn).call(w), c.rotate(c.rotation);
} else if (l) {
f(c, zt, !0);
const _ = l[0], E = {
x: _[0] - g,
y: p - (_[1] - A)
}, C = new Ed(E, [0, 0, u, p], 1, n(c, ze) / 2, !0, 1e-3);
for (let P = 0, M = _.length; P < M; P += 2)
E.x = _[P] - g, E.y = p - (_[P + 1] - A), C.add(E);
const {
id: x,
clipPathId: T
} = s.drawLayer.draw({
bbox: [0, 0, 1, 1],
root: {
viewBox: "0 0 1 1",
fill: c.color,
"fill-opacity": c._defaultOpacity
},
rootClass: {
highlight: !0,
free: !0
},
path: {
d: C.toSVGPath()
}
}, !0, !0);
b(v = c, j, Ph).call(v, {
highlightOutlines: C.getOutlines(),
highlightId: x,
clipPathId: T
}), b(S = c, j, pn).call(S), c.rotate(c.parentRotation);
}
return c;
}
serialize(e = !1) {
if (this.isEmpty() || e)
return null;
if (this.deleted)
return this.serializeDeleted();
const s = this.getRect(0, 0), i = lt._colorManager.convert(this.color), r = {
annotationType: z.HIGHLIGHT,
color: i,
opacity: n(this, oi),
thickness: n(this, ze),
quadPoints: b(this, j, Sp).call(this),
outlines: b(this, j, Ep).call(this, s),
pageIndex: this.pageIndex,
rect: s,
rotation: b(this, j, fo).call(this),
structTreeParentId: this._structTreeParentId
};
return this.annotationElementId && !b(this, j, Tp).call(this, r) ? null : (r.id = this.annotationElementId, r);
}
renderAnnotationElement(e) {
return e.updateEdited({
rect: this.getRect(0, 0)
}), null;
}
static canCreateNewEmptyEditor() {
return !1;
}
};
Da = new WeakMap(), Gl = new WeakMap(), ai = new WeakMap(), lr = new WeakMap(), zl = new WeakMap(), pe = new WeakMap(), Ul = new WeakMap(), jl = new WeakMap(), hr = new WeakMap(), Ge = new WeakMap(), xe = new WeakMap(), zt = new WeakMap(), Fa = new WeakMap(), oi = new WeakMap(), Qt = new WeakMap(), Na = new WeakMap(), ze = new WeakMap(), Vl = new WeakMap(), j = new WeakSet(), Rd = function() {
const e = new _d(n(this, ai), 1e-3);
f(this, Ge, e.getOutlines()), [this.x, this.y, this.width, this.height] = n(this, Ge).box;
const s = new _d(n(this, ai), 25e-4, 1e-3, this._uiManager.direction === "ltr");
f(this, pe, s.getOutlines());
const {
lastPoint: i
} = n(this, pe);
f(this, Fa, [(i[0] - this.x) / this.width, (i[1] - this.y) / this.height]);
}, Ph = function({
highlightOutlines: e,
highlightId: s,
clipPathId: i
}) {
var u, p;
if (f(this, Ge, e), f(this, pe, e.getNewOutline(n(this, ze) / 2 + 1.5, 25e-4)), s >= 0)
f(this, xe, s), f(this, lr, i), this.parent.drawLayer.finalizeDraw(s, {
bbox: e.box,
path: {
d: e.toSVGPath()
}
}), f(this, Qt, this.parent.drawLayer.drawOutline({
rootClass: {
highlightOutline: !0,
free: !0
},
bbox: n(this, pe).box,
path: {
d: n(this, pe).toSVGPath()
}
}, !0));
else if (this.parent) {
const g = this.parent.viewport.rotation;
this.parent.drawLayer.updateProperties(n(this, xe), {
bbox: b(u = J, je, Nr).call(u, n(this, Ge).box, (g - this.rotation + 360) % 360),
path: {
d: e.toSVGPath()
}
}), this.parent.drawLayer.updateProperties(n(this, Qt), {
bbox: b(p = J, je, Nr).call(p, n(this, pe).box, g),
path: {
d: n(this, pe).toSVGPath()
}
});
}
const [a, o, l, h] = e.box;
switch (this.rotation) {
case 0:
this.x = a, this.y = o, this.width = l, this.height = h;
break;
case 90: {
const [g, A] = this.parentDimensions;
this.x = o, this.y = 1 - a, this.width = l * A / g, this.height = h * g / A;
break;
}
case 180:
this.x = 1 - a, this.y = 1 - o, this.width = l, this.height = h;
break;
case 270: {
const [g, A] = this.parentDimensions;
this.x = 1 - o, this.y = a, this.width = l * A / g, this.height = h * g / A;
break;
}
}
const {
lastPoint: c
} = n(this, pe);
f(this, Fa, [(c[0] - a) / l, (c[1] - o) / h]);
}, yp = function(e) {
const s = (a, o) => {
var l, h;
this.color = a, f(this, oi, o), (l = this.parent) == null || l.drawLayer.updateProperties(n(this, xe), {
root: {
fill: a,
"fill-opacity": o
}
}), (h = n(this, zl)) == null || h.updateColor(a);
}, i = this.color, r = n(this, oi);
this.addCommands({
cmd: s.bind(this, e, J._defaultOpacity),
undo: s.bind(this, i, r),
post: this._uiManager.updateUI.bind(this._uiManager, this),
mustExec: !0,
type: Y.HIGHLIGHT_COLOR,
overwriteIfSameType: !0,
keepUndo: !0
}), this._reportTelemetry({
action: "color_changed",
color: this._uiManager.highlightColorNames.get(e)
}, !0);
}, wp = function(e) {
const s = n(this, ze), i = (r) => {
f(this, ze, r), b(this, j, vp).call(this, r);
};
this.addCommands({
cmd: i.bind(this, e),
undo: i.bind(this, s),
post: this._uiManager.updateUI.bind(this._uiManager, this),
mustExec: !0,
type: Y.INK_THICKNESS,
overwriteIfSameType: !0,
keepUndo: !0
}), this._reportTelemetry({
action: "thickness_changed",
thickness: e
}, !0);
}, vp = function(e) {
if (!n(this, zt))
return;
b(this, j, Ph).call(this, {
highlightOutlines: n(this, Ge).getNewOutline(e / 2)
}), this.fixAndSetPosition();
const [s, i] = this.parentDimensions;
this.setDims(this.width * s, this.height * i);
}, Pd = function() {
n(this, xe) === null || !this.parent || (this.parent.drawLayer.remove(n(this, xe)), f(this, xe, null), this.parent.drawLayer.remove(n(this, Qt)), f(this, Qt, null));
}, pn = function(e = this.parent) {
n(this, xe) === null && ({
id: Zt(this, xe)._,
clipPathId: Zt(this, lr)._
} = e.drawLayer.draw({
bbox: n(this, Ge).box,
root: {
viewBox: "0 0 1 1",
fill: this.color,
"fill-opacity": n(this, oi)
},
rootClass: {
highlight: !0,
free: n(this, zt)
},
path: {
d: n(this, Ge).toSVGPath()
}
}, !1, !0), f(this, Qt, e.drawLayer.drawOutline({
rootClass: {
highlightOutline: !0,
free: n(this, zt)
},
bbox: n(this, pe).box,
path: {
d: n(this, pe).toSVGPath()
}
}, n(this, zt))), n(this, hr) && (n(this, hr).style.clipPath = n(this, lr)));
}, je = new WeakSet(), Nr = function([e, s, i, r], a) {
switch (a) {
case 90:
return [1 - s - r, e, r, i];
case 180:
return [1 - e - i, 1 - s - r, i, r];
case 270:
return [s, 1 - e - i, r, i];
}
return [e, s, i, r];
}, _p = function(e) {
J._keyboardManager.exec(this, e);
}, Ih = function(e) {
if (!n(this, Da))
return;
const s = window.getSelection();
e ? s.setPosition(n(this, Da), n(this, Gl)) : s.setPosition(n(this, Ul), n(this, jl));
}, fo = function() {
return n(this, zt) ? this.rotation : 0;
}, Sp = function() {
if (n(this, zt))
return null;
const [e, s] = this.pageDimensions, [i, r] = this.pageTranslation, a = n(this, ai), o = new Float32Array(a.length * 8);
let l = 0;
for (const {
x: h,
y: c,
width: u,
height: p
} of a) {
const g = h * e + i, A = (1 - c) * s + r;
o[l] = o[l + 4] = g, o[l + 1] = o[l + 3] = A, o[l + 2] = o[l + 6] = g + u * e, o[l + 5] = o[l + 7] = A - p * s, l += 8;
}
return o;
}, Ep = function(e) {
return n(this, Ge).serialize(e, b(this, j, fo).call(this));
}, Cp = function(e, s) {
this._freeHighlight.add(s) && e.drawLayer.updateProperties(this._freeHighlightId, {
path: {
d: this._freeHighlight.toSVGPath()
}
});
}, xp = function(e, s) {
this._freeHighlight.isEmpty() ? e.drawLayer.remove(this._freeHighlightId) : e.createAndAddNewEditor(s, !1, {
highlightId: this._freeHighlightId,
highlightOutlines: this._freeHighlight.getOutlines(),
clipPathId: this._freeHighlightClipId,
methodOfCreation: "main_toolbar"
}), this._freeHighlightId = -1, this._freeHighlight = null, this._freeHighlightClipId = "";
}, Tp = function(e) {
const {
color: s
} = this._initialData;
return e.color.some((i, r) => i !== s[r]);
}, m(J, je), R(J, "_defaultColor", null), R(J, "_defaultOpacity", 1), R(J, "_defaultThickness", 12), R(J, "_type", "highlight"), R(J, "_editorType", z.HIGHLIGHT), R(J, "_freeHighlightId", -1), R(J, "_freeHighlight", null), R(J, "_freeHighlightClipId", "");
let Wh = J;
var cr;
class Rp {
constructor() {
m(this, cr, /* @__PURE__ */ Object.create(null));
}
updateProperty(t, e) {
this[t] = e, this.updateSVGProperty(t, e);
}
updateProperties(t) {
if (t)
for (const [e, s] of Object.entries(t))
e.startsWith("_") || this.updateProperty(e, s);
}
updateSVGProperty(t, e) {
n(this, cr)[t] = e;
}
toSVGProperties() {
const t = n(this, cr);
return f(this, cr, /* @__PURE__ */ Object.create(null)), {
root: t
};
}
reset() {
f(this, cr, /* @__PURE__ */ Object.create(null));
}
updateAll(t = this) {
this.updateProperties(t);
}
clone() {
rt("Not implemented");
}
}
cr = new WeakMap();
var Te, Oa, Dt, dr, ur, Xi, Yi, Ki, fr, K, Id, Md, kd, po, Pp, Mh, go, Or;
const F = class F extends lt {
constructor(e) {
super(e);
m(this, K);
m(this, Te, null);
m(this, Oa);
R(this, "_drawId", null);
f(this, Oa, e.mustBeCommitted || !1), this._addOutlines(e);
}
_addOutlines(e) {
e.drawOutlines && (b(this, K, Id).call(this, e), b(this, K, po).call(this));
}
static _mergeSVGProperties(e, s) {
const i = new Set(Object.keys(e));
for (const [r, a] of Object.entries(s))
i.has(r) ? Object.assign(e[r], a) : e[r] = a;
return e;
}
static getDefaultDrawingOptions(e) {
rt("Not implemented");
}
static get typesMap() {
rt("Not implemented");
}
static get isDrawer() {
return !0;
}
static get supportMultipleDrawings() {
return !1;
}
static updateDefaultParams(e, s) {
const i = this.typesMap.get(e);
i && this._defaultDrawingOptions.updateProperty(i, s), this._currentParent && (n(F, Dt).updateProperty(i, s), this._currentParent.drawLayer.updateProperties(this._currentDrawId, this._defaultDrawingOptions.toSVGProperties()));
}
updateParams(e, s) {
const i = this.constructor.typesMap.get(e);
i && this._updateProperty(e, i, s);
}
static get defaultPropertiesToUpdate() {
const e = [], s = this._defaultDrawingOptions;
for (const [i, r] of this.typesMap)
e.push([i, s[r]]);
return e;
}
get propertiesToUpdate() {
const e = [], {
_drawingOptions: s
} = this;
for (const [i, r] of this.constructor.typesMap)
e.push([i, s[r]]);
return e;
}
_updateProperty(e, s, i) {
const r = this._drawingOptions, a = r[s], o = (l) => {
var c;
r.updateProperty(s, l);
const h = n(this, Te).updateProperty(s, l);
h && b(this, K, go).call(this, h), (c = this.parent) == null || c.drawLayer.updateProperties(this._drawId, r.toSVGProperties());
};
this.addCommands({
cmd: o.bind(this, i),
undo: o.bind(this, a),
post: this._uiManager.updateUI.bind(this._uiManager, this),
mustExec: !0,
type: e,
overwriteIfSameType: !0,
keepUndo: !0
});
}
_onResizing() {
var e;
(e = this.parent) == null || e.drawLayer.updateProperties(this._drawId, F._mergeSVGProperties(n(this, Te).getPathResizingSVGProperties(b(this, K, Mh).call(this)), {
bbox: b(this, K, Or).call(this)
}));
}
_onResized() {
var e;
(e = this.parent) == null || e.drawLayer.updateProperties(this._drawId, F._mergeSVGProperties(n(this, Te).getPathResizedSVGProperties(b(this, K, Mh).call(this)), {
bbox: b(this, K, Or).call(this)
}));
}
_onTranslating(e, s) {
var i;
(i = this.parent) == null || i.drawLayer.updateProperties(this._drawId, {
bbox: b(this, K, Or).call(this)
});
}
_onTranslated() {
var e;
(e = this.parent) == null || e.drawLayer.updateProperties(this._drawId, F._mergeSVGProperties(n(this, Te).getPathTranslatedSVGProperties(b(this, K, Mh).call(this), this.parentDimensions), {
bbox: b(this, K, Or).call(this)
}));
}
_onStartDragging() {
var e;
(e = this.parent) == null || e.drawLayer.updateProperties(this._drawId, {
rootClass: {
moving: !0
}
});
}
_onStopDragging() {
var e;
(e = this.parent) == null || e.drawLayer.updateProperties(this._drawId, {
rootClass: {
moving: !1
}
});
}
commit() {
super.commit(), this.disableEditMode(), this.disableEditing();
}
disableEditing() {
super.disableEditing(), this.div.classList.toggle("disabled", !0);
}
enableEditing() {
super.enableEditing(), this.div.classList.toggle("disabled", !1);
}
getBaseTranslation() {
return [0, 0];
}
get isResizable() {
return !0;
}
onceAdded(e) {
this.annotationElementId || this.parent.addUndoableEditor(this), this._isDraggable = !0, n(this, Oa) && (f(this, Oa, !1), this.commit(), this.parent.setSelected(this), e && this.isOnScreen && this.div.focus());
}
remove() {
b(this, K, kd).call(this), super.remove();
}
rebuild() {
this.parent && (super.rebuild(), this.div !== null && (b(this, K, po).call(this), b(this, K, go).call(this, n(this, Te).box), this.isAttachedToDOM || this.parent.add(this)));
}
setParent(e) {
var i;
let s = !1;
this.parent && !e ? (this._uiManager.removeShouldRescale(this), b(this, K, kd).call(this)) : e && (this._uiManager.addShouldRescale(this), b(this, K, po).call(this, e), s = !this.parent && ((i = this.div) == null ? void 0 : i.classList.contains("selectedEditor"))), super.setParent(e), s && this.select();
}
rotate() {
this.parent && this.parent.drawLayer.updateProperties(this._drawId, F._mergeSVGProperties({
bbox: b(this, K, Or).call(this)
}, n(this, Te).updateRotation((this.parentRotation - this.rotation + 360) % 360)));
}
onScaleChanging() {
this.parent && b(this, K, go).call(this, n(this, Te).updateParentDimensions(this.parentDimensions, this.parent.scale));
}
static onScaleChangingWhenDrawing() {
}
render() {
if (this.div)
return this.div;
let e, s;
this._isCopy && (e = this.x, s = this.y);
const i = super.render();
i.classList.add("draw");
const r = document.createElement("div");
i.append(r), r.setAttribute("aria-hidden", "true"), r.className = "internal";
const [a, o] = this.parentDimensions;
return this.setDims(this.width * a, this.height * o), this._uiManager.addShouldRescale(this), this.disableEditing(), this._isCopy && this._moveAfterPaste(e, s), i;
}
static createDrawerInstance(e, s, i, r, a) {
rt("Not implemented");
}
static startDrawing(e, s, i, r) {
var w;
const {
target: a,
offsetX: o,
offsetY: l,
pointerId: h,
pointerType: c
} = r;
if (n(F, Yi) && n(F, Yi) !== c)
return;
const {
viewport: {
rotation: u
}
} = e, {
width: p,
height: g
} = a.getBoundingClientRect(), A = f(F, dr, new AbortController()), y = e.combinedSignal(A);
if (n(F, Xi) || f(F, Xi, h), n(F, Yi) ?? f(F, Yi, c), window.addEventListener("pointerup", (v) => {
var S;
n(F, Xi) === v.pointerId ? this._endDraw(v) : (S = n(F, Ki)) == null || S.delete(v.pointerId);
}, {
signal: y
}), window.addEventListener("pointercancel", (v) => {
var S;
n(F, Xi) === v.pointerId ? this._currentParent.endDrawingSession() : (S = n(F, Ki)) == null || S.delete(v.pointerId);
}, {
signal: y
}), window.addEventListener("pointerdown", (v) => {
n(F, Yi) === v.pointerType && ((n(F, Ki) || f(F, Ki, /* @__PURE__ */ new Set())).add(v.pointerId), n(F, Dt).isCancellable() && (n(F, Dt).removeLastElement(), n(F, Dt).isEmpty() ? this._currentParent.endDrawingSession(!0) : this._endDraw(null)));
}, {
capture: !0,
passive: !1,
signal: y
}), window.addEventListener("contextmenu", as, {
signal: y
}), a.addEventListener("pointermove", this._drawMove.bind(this), {
signal: y
}), a.addEventListener("touchmove", (v) => {
v.timeStamp === n(F, fr) && St(v);
}, {
signal: y
}), e.toggleDrawing(), (w = s._editorUndoBar) == null || w.hide(), n(F, Dt)) {
e.drawLayer.updateProperties(this._currentDrawId, n(F, Dt).startNew(o, l, p, g, u));
return;
}
s.updateUIForDefaultProperties(this), f(F, Dt, this.createDrawerInstance(o, l, p, g, u)), f(F, ur, this.getDefaultDrawingOptions()), this._currentParent = e, {
id: this._currentDrawId
} = e.drawLayer.draw(this._mergeSVGProperties(n(F, ur).toSVGProperties(), n(F, Dt).defaultSVGProperties), !0, !1);
}
static _drawMove(e) {
var a;
if (f(F, fr, -1), !n(F, Dt))
return;
const {
offsetX: s,
offsetY: i,
pointerId: r
} = e;
if (n(F, Xi) === r) {
if (((a = n(F, Ki)) == null ? void 0 : a.size) >= 1) {
this._endDraw(e);
return;
}
this._currentParent.drawLayer.updateProperties(this._currentDrawId, n(F, Dt).add(s, i)), f(F, fr, e.timeStamp), St(e);
}
}
static _cleanup(e) {
e && (this._currentDrawId = -1, this._currentParent = null, f(F, Dt, null), f(F, ur, null), f(F, Yi, null), f(F, fr, NaN)), n(F, dr) && (n(F, dr).abort(), f(F, dr, null), f(F, Xi, NaN), f(F, Ki, null));
}
static _endDraw(e) {
const s = this._currentParent;
if (s) {
if (s.toggleDrawing(!0), this._cleanup(!1), (e == null ? void 0 : e.target) === s.div && s.drawLayer.updateProperties(this._currentDrawId, n(F, Dt).end(e.offsetX, e.offsetY)), this.supportMultipleDrawings) {
const i = n(F, Dt), r = this._currentDrawId, a = i.getLastElement();
s.addCommands({
cmd: () => {
s.drawLayer.updateProperties(r, i.setLastElement(a));
},
undo: () => {
s.drawLayer.updateProperties(r, i.removeLastElement());
},
mustExec: !1,
type: Y.DRAW_STEP
});
return;
}
this.endDrawing(!1);
}
}
static endDrawing(e) {
const s = this._currentParent;
if (!s)
return null;
if (s.toggleDrawing(!0), s.cleanUndoStack(Y.DRAW_STEP), !n(F, Dt).isEmpty()) {
const {
pageDimensions: [i, r],
scale: a
} = s, o = s.createAndAddNewEditor({
offsetX: 0,
offsetY: 0
}, !1, {
drawId: this._currentDrawId,
drawOutlines: n(F, Dt).getOutlines(i * a, r * a, a, this._INNER_MARGIN),
drawingOptions: n(F, ur),
mustBeCommitted: !e
});
return this._cleanup(!0), o;
}
return s.drawLayer.remove(this._currentDrawId), this._cleanup(!0), null;
}
createDrawingOptions(e) {
}
static deserializeDraw(e, s, i, r, a, o) {
rt("Not implemented");
}
static async deserialize(e, s, i) {
var u, p;
const {
rawDims: {
pageWidth: r,
pageHeight: a,
pageX: o,
pageY: l
}
} = s.viewport, h = this.deserializeDraw(o, l, r, a, this._INNER_MARGIN, e), c = await super.deserialize(e, s, i);
return c.createDrawingOptions(e), b(u = c, K, Id).call(u, {
drawOutlines: h
}), b(p = c, K, po).call(p), c.onScaleChanging(), c.rotate(), c;
}
serializeDraw(e) {
const [s, i] = this.pageTranslation, [r, a] = this.pageDimensions;
return n(this, Te).serialize([s, i, r, a], e);
}
renderAnnotationElement(e) {
return e.updateEdited({
rect: this.getRect(0, 0)
}), null;
}
static canCreateNewEmptyEditor() {
return !1;
}
};
Te = new WeakMap(), Oa = new WeakMap(), Dt = new WeakMap(), dr = new WeakMap(), ur = new WeakMap(), Xi = new WeakMap(), Yi = new WeakMap(), Ki = new WeakMap(), fr = new WeakMap(), K = new WeakSet(), Id = function({
drawOutlines: e,
drawId: s,
drawingOptions: i
}) {
f(this, Te, e), this._drawingOptions || (this._drawingOptions = i), this.annotationElementId || this._uiManager.a11yAlert(`pdfjs-editor-${this.editorType}-added-alert`), s >= 0 ? (this._drawId = s, this.parent.drawLayer.finalizeDraw(s, e.defaultProperties)) : this._drawId = b(this, K, Md).call(this, e, this.parent), b(this, K, go).call(this, e.box);
}, Md = function(e, s) {
const {
id: i
} = s.drawLayer.draw(F._mergeSVGProperties(this._drawingOptions.toSVGProperties(), e.defaultSVGProperties), !1, !1);
return i;
}, kd = function() {
this._drawId === null || !this.parent || (this.parent.drawLayer.remove(this._drawId), this._drawId = null, this._drawingOptions.reset());
}, po = function(e = this.parent) {
if (!(this._drawId !== null && this.parent === e)) {
if (this._drawId !== null) {
this.parent.drawLayer.updateParent(this._drawId, e.drawLayer);
return;
}
this._drawingOptions.updateAll(), this._drawId = b(this, K, Md).call(this, n(this, Te), e);
}
}, Pp = function([e, s, i, r]) {
const {
parentDimensions: [a, o],
rotation: l
} = this;
switch (l) {
case 90:
return [s, 1 - e, i * (o / a), r * (a / o)];
case 180:
return [1 - e, 1 - s, i, r];
case 270:
return [1 - s, e, i * (o / a), r * (a / o)];
default:
return [e, s, i, r];
}
}, Mh = function() {
const {
x: e,
y: s,
width: i,
height: r,
parentDimensions: [a, o],
rotation: l
} = this;
switch (l) {
case 90:
return [1 - s, e, i * (a / o), r * (o / a)];
case 180:
return [1 - e, 1 - s, i, r];
case 270:
return [s, 1 - e, i * (a / o), r * (o / a)];
default:
return [e, s, i, r];
}
}, go = function(e) {
if ([this.x, this.y, this.width, this.height] = b(this, K, Pp).call(this, e), this.div) {
this.fixAndSetPosition();
const [s, i] = this.parentDimensions;
this.setDims(this.width * s, this.height * i);
}
this._onResized();
}, Or = function() {
const {
x: e,
y: s,
width: i,
height: r,
rotation: a,
parentRotation: o,
parentDimensions: [l, h]
} = this;
switch ((a * 4 + o) / 90) {
case 1:
return [1 - s - r, e, r, i];
case 2:
return [1 - e - i, 1 - s - r, i, r];
case 3:
return [s, 1 - e - i, r, i];
case 4:
return [e, s - i * (l / h), r * (h / l), i * (l / h)];
case 5:
return [1 - s, e, i * (l / h), r * (h / l)];
case 6:
return [1 - e - r * (h / l), 1 - s, r * (h / l), i * (l / h)];
case 7:
return [s - i * (l / h), 1 - e - r * (h / l), i * (l / h), r * (h / l)];
case 8:
return [e - i, s - r, i, r];
case 9:
return [1 - s, e - i, r, i];
case 10:
return [1 - e, 1 - s, i, r];
case 11:
return [s - r, 1 - e, r, i];
case 12:
return [e - r * (h / l), s, r * (h / l), i * (l / h)];
case 13:
return [1 - s - i * (l / h), e - r * (h / l), i * (l / h), r * (h / l)];
case 14:
return [1 - e, 1 - s - i * (l / h), r * (h / l), i * (l / h)];
case 15:
return [s, 1 - e, i * (l / h), r * (h / l)];
default:
return [e, s, i, r];
}
}, R(F, "_currentDrawId", -1), R(F, "_currentParent", null), m(F, Dt, null), m(F, dr, null), m(F, ur, null), m(F, Xi, NaN), m(F, Yi, null), m(F, Ki, null), m(F, fr, NaN), R(F, "_INNER_MARGIN", 3);
let qh = F;
var _s, Ft, Nt, pr, Ba, se, Ut, Ue, gr, mr, br, Ha, kh;
class Bm {
constructor(t, e, s, i, r, a) {
m(this, Ha);
m(this, _s, new Float64Array(6));
m(this, Ft);
m(this, Nt);
m(this, pr);
m(this, Ba);
m(this, se);
m(this, Ut, "");
m(this, Ue, 0);
m(this, gr, new th());
m(this, mr);
m(this, br);
f(this, mr, s), f(this, br, i), f(this, pr, r), f(this, Ba, a), [t, e] = b(this, Ha, kh).call(this, t, e);
const o = f(this, Ft, [NaN, NaN, NaN, NaN, t, e]);
f(this, se, [t, e]), f(this, Nt, [{
line: o,
points: n(this, se)
}]), n(this, _s).set(o, 0);
}
updateProperty(t, e) {
t === "stroke-width" && f(this, Ba, e);
}
isEmpty() {
return !n(this, Nt) || n(this, Nt).length === 0;
}
isCancellable() {
return n(this, se).length <= 10;
}
add(t, e) {
[t, e] = b(this, Ha, kh).call(this, t, e);
const [s, i, r, a] = n(this, _s).subarray(2, 6), o = t - r, l = e - a;
return Math.hypot(n(this, mr) * o, n(this, br) * l) <= 2 ? null : (n(this, se).push(t, e), isNaN(s) ? (n(this, _s).set([r, a, t, e], 2), n(this, Ft).push(NaN, NaN, NaN, NaN, t, e), {
path: {
d: this.toSVGPath()
}
}) : (isNaN(n(this, _s)[0]) && n(this, Ft).splice(6, 6), n(this, _s).set([s, i, r, a, t, e], 0), n(this, Ft).push(...L.createBezierPoints(s, i, r, a, t, e)), {
path: {
d: this.toSVGPath()
}
}));
}
end(t, e) {
const s = this.add(t, e);
return s || (n(this, se).length === 2 ? {
path: {
d: this.toSVGPath()
}
} : null);
}
startNew(t, e, s, i, r) {
f(this, mr, s), f(this, br, i), f(this, pr, r), [t, e] = b(this, Ha, kh).call(this, t, e);
const a = f(this, Ft, [NaN, NaN, NaN, NaN, t, e]);
f(this, se, [t, e]);
const o = n(this, Nt).at(-1);
return o && (o.line = new Float32Array(o.line), o.points = new Float32Array(o.points)), n(this, Nt).push({
line: a,
points: n(this, se)
}), n(this, _s).set(a, 0), f(this, Ue, 0), this.toSVGPath(), null;
}
getLastElement() {
return n(this, Nt).at(-1);
}
setLastElement(t) {
return n(this, Nt) ? (n(this, Nt).push(t), f(this, Ft, t.line), f(this, se, t.points), f(this, Ue, 0), {
path: {
d: this.toSVGPath()
}
}) : n(this, gr).setLastElement(t);
}
removeLastElement() {
if (!n(this, Nt))
return n(this, gr).removeLastElement();
n(this, Nt).pop(), f(this, Ut, "");
for (let t = 0, e = n(this, Nt).length; t < e; t++) {
const {
line: s,
points: i
} = n(this, Nt)[t];
f(this, Ft, s), f(this, se, i), f(this, Ue, 0), this.toSVGPath();
}
return {
path: {
d: n(this, Ut)
}
};
}
toSVGPath() {
const t = L.svgRound(n(this, Ft)[4]), e = L.svgRound(n(this, Ft)[5]);
if (n(this, se).length === 2)
return f(this, Ut, `${n(this, Ut)} M ${t} ${e} Z`), n(this, Ut);
if (n(this, se).length <= 6) {
const i = n(this, Ut).lastIndexOf("M");
f(this, Ut, `${n(this, Ut).slice(0, i)} M ${t} ${e}`), f(this, Ue, 6);
}
if (n(this, se).length === 4) {
const i = L.svgRound(n(this, Ft)[10]), r = L.svgRound(n(this, Ft)[11]);
return f(this, Ut, `${n(this, Ut)} L ${i} ${r}`), f(this, Ue, 12), n(this, Ut);
}
const s = [];
n(this, Ue) === 0 && (s.push(`M ${t} ${e}`), f(this, Ue, 6));
for (let i = n(this, Ue), r = n(this, Ft).length; i < r; i += 6) {
const [a, o, l, h, c, u] = n(this, Ft).slice(i, i + 6).map(L.svgRound);
s.push(`C${a} ${o} ${l} ${h} ${c} ${u}`);
}
return f(this, Ut, n(this, Ut) + s.join(" ")), f(this, Ue, n(this, Ft).length), n(this, Ut);
}
getOutlines(t, e, s, i) {
const r = n(this, Nt).at(-1);
return r.line = new Float32Array(r.line), r.points = new Float32Array(r.points), n(this, gr).build(n(this, Nt), t, e, s, n(this, pr), n(this, Ba), i), f(this, _s, null), f(this, Ft, null), f(this, Nt, null), f(this, Ut, null), n(this, gr);
}
get defaultSVGProperties() {
return {
root: {
viewBox: "0 0 10000 10000"
},
rootClass: {
draw: !0
},
bbox: [0, 0, 1, 1]
};
}
}
_s = new WeakMap(), Ft = new WeakMap(), Nt = new WeakMap(), pr = new WeakMap(), Ba = new WeakMap(), se = new WeakMap(), Ut = new WeakMap(), Ue = new WeakMap(), gr = new WeakMap(), mr = new WeakMap(), br = new WeakMap(), Ha = new WeakSet(), kh = function(t, e) {
return L._normalizePoint(t, e, n(this, mr), n(this, br), n(this, pr));
};
var ie, Wl, ql, Re, Ss, Es, $a, Ga, Ar, Vt, Ds, Ip, Mp, kp;
class th extends L {
constructor() {
super(...arguments);
m(this, Vt);
m(this, ie);
m(this, Wl, 0);
m(this, ql);
m(this, Re);
m(this, Ss);
m(this, Es);
m(this, $a);
m(this, Ga);
m(this, Ar);
}
build(e, s, i, r, a, o, l) {
f(this, Ss, s), f(this, Es, i), f(this, $a, r), f(this, Ga, a), f(this, Ar, o), f(this, ql, l ?? 0), f(this, Re, e), b(this, Vt, Mp).call(this);
}
get thickness() {
return n(this, Ar);
}
setLastElement(e) {
return n(this, Re).push(e), {
path: {
d: this.toSVGPath()
}
};
}
removeLastElement() {
return n(this, Re).pop(), {
path: {
d: this.toSVGPath()
}
};
}
toSVGPath() {
const e = [];
for (const {
line: s
} of n(this, Re)) {
if (e.push(`M${L.svgRound(s[4])} ${L.svgRound(s[5])}`), s.length === 6) {
e.push("Z");
continue;
}
if (s.length === 12 && isNaN(s[6])) {
e.push(`L${L.svgRound(s[10])} ${L.svgRound(s[11])}`);
continue;
}
for (let i = 6, r = s.length; i < r; i += 6) {
const [a, o, l, h, c, u] = s.subarray(i, i + 6).map(L.svgRound);
e.push(`C${a} ${o} ${l} ${h} ${c} ${u}`);
}
}
return e.join("");
}
serialize([e, s, i, r], a) {
const o = [], l = [], [h, c, u, p] = b(this, Vt, Ip).call(this);
let g, A, y, w, v, S, _, E, C;
switch (n(this, Ga)) {
case 0:
C = L._rescale, g = e, A = s + r, y = i, w = -r, v = e + h * i, S = s + (1 - c - p) * r, _ = e + (h + u) * i, E = s + (1 - c) * r;
break;
case 90:
C = L._rescaleAndSwap, g = e, A = s, y = i, w = r, v = e + c * i, S = s + h * r, _ = e + (c + p) * i, E = s + (h + u) * r;
break;
case 180:
C = L._rescale, g = e + i, A = s, y = -i, w = r, v = e + (1 - h - u) * i, S = s + c * r, _ = e + (1 - h) * i, E = s + (c + p) * r;
break;
case 270:
C = L._rescaleAndSwap, g = e + i, A = s + r, y = -i, w = -r, v = e + (1 - c - p) * i, S = s + (1 - h - u) * r, _ = e + (1 - c) * i, E = s + (1 - h) * r;
break;
}
for (const {
line: x,
points: T
} of n(this, Re))
o.push(C(x, g, A, y, w, a ? new Array(x.length) : null)), l.push(C(T, g, A, y, w, a ? new Array(T.length) : null));
return {
lines: o,
points: l,
rect: [v, S, _, E]
};
}
static deserialize(e, s, i, r, a, {
paths: {
lines: o,
points: l
},
rotation: h,
thickness: c
}) {
const u = [];
let p, g, A, y, w;
switch (h) {
case 0:
w = L._rescale, p = -e / i, g = s / r + 1, A = 1 / i, y = -1 / r;
break;
case 90:
w = L._rescaleAndSwap, p = -s / r, g = -e / i, A = 1 / r, y = 1 / i;
break;
case 180:
w = L._rescale, p = e / i + 1, g = -s / r, A = -1 / i, y = 1 / r;
break;
case 270:
w = L._rescaleAndSwap, p = s / r + 1, g = e / i + 1, A = -1 / r, y = -1 / i;
break;
}
if (!o) {
o = [];
for (const S of l) {
const _ = S.length;
if (_ === 2) {
o.push(new Float32Array([NaN, NaN, NaN, NaN, S[0], S[1]]));
continue;
}
if (_ === 4) {
o.push(new Float32Array([NaN, NaN, NaN, NaN, S[0], S[1], NaN, NaN, NaN, NaN, S[2], S[3]]));
continue;
}
const E = new Float32Array(3 * (_ - 2));
o.push(E);
let [C, x, T, P] = S.subarray(0, 4);
E.set([NaN, NaN, NaN, NaN, C, x], 0);
for (let M = 4; M < _; M += 2) {
const O = S[M], D = S[M + 1];
E.set(L.createBezierPoints(C, x, T, P, O, D), (M - 2) * 3), [C, x, T, P] = [T, P, O, D];
}
}
}
for (let S = 0, _ = o.length; S < _; S++)
u.push({
line: w(o[S].map((E) => E ?? NaN), p, g, A, y),
points: w(l[S].map((E) => E ?? NaN), p, g, A, y)
});
const v = new this.prototype.constructor();
return v.build(u, i, r, 1, h, c, a), v;
}
get box() {
return n(this, ie);
}
updateProperty(e, s) {
return e === "stroke-width" ? b(this, Vt, kp).call(this, s) : null;
}
updateParentDimensions([e, s], i) {
const [r, a] = b(this, Vt, Ds).call(this);
f(this, Ss, e), f(this, Es, s), f(this, $a, i);
const [o, l] = b(this, Vt, Ds).call(this), h = o - r, c = l - a, u = n(this, ie);
return u[0] -= h, u[1] -= c, u[2] += 2 * h, u[3] += 2 * c, u;
}
updateRotation(e) {
return f(this, Wl, e), {
path: {
transform: this.rotationTransform
}
};
}
get viewBox() {
return n(this, ie).map(L.svgRound).join(" ");
}
get defaultProperties() {
const [e, s] = n(this, ie);
return {
root: {
viewBox: this.viewBox
},
path: {
"transform-origin": `${L.svgRound(e)} ${L.svgRound(s)}`
}
};
}
get rotationTransform() {
const [, , e, s] = n(this, ie);
let i = 0, r = 0, a = 0, o = 0, l = 0, h = 0;
switch (n(this, Wl)) {
case 90:
r = s / e, a = -e / s, l = e;
break;
case 180:
i = -1, o = -1, l = e, h = s;
break;
case 270:
r = -s / e, a = e / s, h = s;
break;
default:
return "";
}
return `matrix(${i} ${r} ${a} ${o} ${L.svgRound(l)} ${L.svgRound(h)})`;
}
getPathResizingSVGProperties([e, s, i, r]) {
const [a, o] = b(this, Vt, Ds).call(this), [l, h, c, u] = n(this, ie);
if (Math.abs(c - a) <= L.PRECISION || Math.abs(u - o) <= L.PRECISION) {
const w = e + i / 2 - (l + c / 2), v = s + r / 2 - (h + u / 2);
return {
path: {
"transform-origin": `${L.svgRound(e)} ${L.svgRound(s)}`,
transform: `${this.rotationTransform} translate(${w} ${v})`
}
};
}
const p = (i - 2 * a) / (c - 2 * a), g = (r - 2 * o) / (u - 2 * o), A = c / i, y = u / r;
return {
path: {
"transform-origin": `${L.svgRound(l)} ${L.svgRound(h)}`,
transform: `${this.rotationTransform} scale(${A} ${y}) translate(${L.svgRound(a)} ${L.svgRound(o)}) scale(${p} ${g}) translate(${L.svgRound(-a)} ${L.svgRound(-o)})`
}
};
}
getPathResizedSVGProperties([e, s, i, r]) {
const [a, o] = b(this, Vt, Ds).call(this), l = n(this, ie), [h, c, u, p] = l;
if (l[0] = e, l[1] = s, l[2] = i, l[3] = r, Math.abs(u - a) <= L.PRECISION || Math.abs(p - o) <= L.PRECISION) {
const v = e + i / 2 - (h + u / 2), S = s + r / 2 - (c + p / 2);
for (const {
line: _,
points: E
} of n(this, Re))
L._translate(_, v, S, _), L._translate(E, v, S, E);
return {
root: {
viewBox: this.viewBox
},
path: {
"transform-origin": `${L.svgRound(e)} ${L.svgRound(s)}`,
transform: this.rotationTransform || null,
d: this.toSVGPath()
}
};
}
const g = (i - 2 * a) / (u - 2 * a), A = (r - 2 * o) / (p - 2 * o), y = -g * (h + a) + e + a, w = -A * (c + o) + s + o;
if (g !== 1 || A !== 1 || y !== 0 || w !== 0)
for (const {
line: v,
points: S
} of n(this, Re))
L._rescale(v, y, w, g, A, v), L._rescale(S, y, w, g, A, S);
return {
root: {
viewBox: this.viewBox
},
path: {
"transform-origin": `${L.svgRound(e)} ${L.svgRound(s)}`,
transform: this.rotationTransform || null,
d: this.toSVGPath()
}
};
}
getPathTranslatedSVGProperties([e, s], i) {
const [r, a] = i, o = n(this, ie), l = e - o[0], h = s - o[1];
if (n(this, Ss) === r && n(this, Es) === a)
for (const {
line: c,
points: u
} of n(this, Re))
L._translate(c, l, h, c), L._translate(u, l, h, u);
else {
const c = n(this, Ss) / r, u = n(this, Es) / a;
f(this, Ss, r), f(this, Es, a);
for (const {
line: p,
points: g
} of n(this, Re))
L._rescale(p, l, h, c, u, p), L._rescale(g, l, h, c, u, g);
o[2] *= c, o[3] *= u;
}
return o[0] = e, o[1] = s, {
root: {
viewBox: this.viewBox
},
path: {
d: this.toSVGPath(),
"transform-origin": `${L.svgRound(e)} ${L.svgRound(s)}`
}
};
}
get defaultSVGProperties() {
const e = n(this, ie);
return {
root: {
viewBox: this.viewBox
},
rootClass: {
draw: !0
},
path: {
d: this.toSVGPath(),
"transform-origin": `${L.svgRound(e[0])} ${L.svgRound(e[1])}`,
transform: this.rotationTransform || null
},
bbox: e
};
}
}
ie = new WeakMap(), Wl = new WeakMap(), ql = new WeakMap(), Re = new WeakMap(), Ss = new WeakMap(), Es = new WeakMap(), $a = new WeakMap(), Ga = new WeakMap(), Ar = new WeakMap(), Vt = new WeakSet(), Ds = function(e = n(this, Ar)) {
const s = n(this, ql) + e / 2 * n(this, $a);
return n(this, Ga) % 180 === 0 ? [s / n(this, Ss), s / n(this, Es)] : [s / n(this, Es), s / n(this, Ss)];
}, Ip = function() {
const [e, s, i, r] = n(this, ie), [a, o] = b(this, Vt, Ds).call(this, 0);
return [e + a, s + o, i - 2 * a, r - 2 * o];
}, Mp = function() {
const e = f(this, ie, new Float32Array([1 / 0, 1 / 0, -1 / 0, -1 / 0]));
for (const {
line: r
} of n(this, Re)) {
if (r.length <= 12) {
for (let l = 4, h = r.length; l < h; l += 6)
$.pointBoundingBox(r[l], r[l + 1], e);
continue;
}
let a = r[4], o = r[5];
for (let l = 6, h = r.length; l < h; l += 6) {
const [c, u, p, g, A, y] = r.subarray(l, l + 6);
$.bezierBoundingBox(a, o, c, u, p, g, A, y, e), a = A, o = y;
}
}
const [s, i] = b(this, Vt, Ds).call(this);
e[0] = ae(e[0] - s, 0, 1), e[1] = ae(e[1] - i, 0, 1), e[2] = ae(e[2] + s, 0, 1), e[3] = ae(e[3] + i, 0, 1), e[2] -= e[0], e[3] -= e[1];
}, kp = function(e) {
const [s, i] = b(this, Vt, Ds).call(this);
f(this, Ar, e);
const [r, a] = b(this, Vt, Ds).call(this), [o, l] = [r - s, a - i], h = n(this, ie);
return h[0] -= o, h[1] -= l, h[2] += 2 * o, h[3] += 2 * l, h;
};
class Ac extends Rp {
constructor(t) {
super(), this._viewParameters = t, super.updateProperties({
fill: "none",
stroke: lt._defaultLineColor,
"stroke-opacity": 1,
"stroke-width": 1,
"stroke-linecap": "round",
"stroke-linejoin": "round",
"stroke-miterlimit": 10
});
}
updateSVGProperty(t, e) {
t === "stroke-width" && (e ?? (e = this["stroke-width"]), e *= this._viewParameters.realScale), super.updateSVGProperty(t, e);
}
clone() {
const t = new Ac(this._viewParameters);
return t.updateAll(this), t;
}
}
var dc, Lp;
const $r = class $r extends qh {
constructor(e) {
super({
...e,
name: "inkEditor"
});
m(this, dc);
this._willKeepAspectRatio = !0, this.defaultL10nId = "pdfjs-editor-ink-editor";
}
static initialize(e, s) {
lt.initialize(e, s), this._defaultDrawingOptions = new Ac(s.viewParameters);
}
static getDefaultDrawingOptions(e) {
const s = this._defaultDrawingOptions.clone();
return s.updateProperties(e), s;
}
static get supportMultipleDrawings() {
return !0;
}
static get typesMap() {
return X(this, "typesMap", /* @__PURE__ */ new Map([[Y.INK_THICKNESS, "stroke-width"], [Y.INK_COLOR, "stroke"], [Y.INK_OPACITY, "stroke-opacity"]]));
}
static createDrawerInstance(e, s, i, r, a) {
return new Bm(e, s, i, r, a, this._defaultDrawingOptions["stroke-width"]);
}
static deserializeDraw(e, s, i, r, a, o) {
return th.deserialize(e, s, i, r, a, o);
}
static async deserialize(e, s, i) {
let r = null;
if (e instanceof su) {
const {
data: {
inkLists: o,
rect: l,
rotation: h,
id: c,
color: u,
opacity: p,
borderStyle: {
rawWidth: g
},
popupRef: A
},
parent: {
page: {
pageNumber: y
}
}
} = e;
r = e = {
annotationType: z.INK,
color: Array.from(u),
thickness: g,
opacity: p,
paths: {
points: o
},
boxes: null,
pageIndex: y - 1,
rect: l.slice(0),
rotation: h,
annotationElementId: c,
id: c,
deleted: !1,
popupRef: A
};
}
const a = await super.deserialize(e, s, i);
return a._initialData = r, a;
}
onScaleChanging() {
if (!this.parent)
return;
super.onScaleChanging();
const {
_drawId: e,
_drawingOptions: s,
parent: i
} = this;
s.updateSVGProperty("stroke-width"), i.drawLayer.updateProperties(e, s.toSVGProperties());
}
static onScaleChangingWhenDrawing() {
const e = this._currentParent;
e && (super.onScaleChangingWhenDrawing(), this._defaultDrawingOptions.updateSVGProperty("stroke-width"), e.drawLayer.updateProperties(this._currentDrawId, this._defaultDrawingOptions.toSVGProperties()));
}
createDrawingOptions({
color: e,
thickness: s,
opacity: i
}) {
this._drawingOptions = $r.getDefaultDrawingOptions({
stroke: $.makeHexColor(...e),
"stroke-width": s,
"stroke-opacity": i
});
}
serialize(e = !1) {
if (this.isEmpty())
return null;
if (this.deleted)
return this.serializeDeleted();
const {
lines: s,
points: i,
rect: r
} = this.serializeDraw(e), {
_drawingOptions: {
stroke: a,
"stroke-opacity": o,
"stroke-width": l
}
} = this, h = {
annotationType: z.INK,
color: lt._colorManager.convert(a),
opacity: o,
thickness: l,
paths: {
lines: s,
points: i
},
pageIndex: this.pageIndex,
rect: r,
rotation: this.rotation,
structTreeParentId: this._structTreeParentId
};
return e ? (h.isCopy = !0, h) : this.annotationElementId && !b(this, dc, Lp).call(this, h) ? null : (h.id = this.annotationElementId, h);
}
renderAnnotationElement(e) {
const {
points: s,
rect: i
} = this.serializeDraw(!1);
return e.updateEdited({
rect: i,
thickness: this._drawingOptions["stroke-width"],
points: s
}), null;
}
};
dc = new WeakSet(), Lp = function(e) {
const {
color: s,
thickness: i,
opacity: r,
pageIndex: a
} = this._initialData;
return this._hasBeenMoved || this._hasBeenResized || e.color.some((o, l) => o !== s[l]) || e.thickness !== i || e.opacity !== r || e.pageIndex !== a;
}, R($r, "_type", "ink"), R($r, "_editorType", z.INK), R($r, "_defaultDrawingOptions", null);
let Ld = $r;
class Dd extends th {
toSVGPath() {
let t = super.toSVGPath();
return t.endsWith("Z") || (t += "Z"), t;
}
}
const oh = 8, Qa = 3;
var yr, Z, Fd, ss, Dp, Fp, Nd, Lh, Np, Op, Bp, Od, Bd, Hp;
class pi {
static extractContoursFromText(t, {
fontFamily: e,
fontStyle: s,
fontWeight: i
}, r, a, o, l) {
let h = new OffscreenCanvas(1, 1), c = h.getContext("2d", {
alpha: !1
});
const u = 200, p = c.font = `${s} ${i} ${u}px ${e}`, {
actualBoundingBoxLeft: g,
actualBoundingBoxRight: A,
actualBoundingBoxAscent: y,
actualBoundingBoxDescent: w,
fontBoundingBoxAscent: v,
fontBoundingBoxDescent: S,
width: _
} = c.measureText(t), E = 1.5, C = Math.ceil(Math.max(Math.abs(g) + Math.abs(A) || 0, _) * E), x = Math.ceil(Math.max(Math.abs(y) + Math.abs(w) || u, Math.abs(v) + Math.abs(S) || u) * E);
h = new OffscreenCanvas(C, x), c = h.getContext("2d", {
alpha: !0,
willReadFrequently: !0
}), c.font = p, c.filter = "grayscale(1)", c.fillStyle = "white", c.fillRect(0, 0, C, x), c.fillStyle = "black", c.fillText(t, C * (E - 1) / 2, x * (3 - E) / 2);
const T = b(this, Z, Od).call(this, c.getImageData(0, 0, C, x).data), P = b(this, Z, Bp).call(this, T), M = b(this, Z, Bd).call(this, P), O = b(this, Z, Nd).call(this, T, C, x, M);
return this.processDrawnLines({
lines: {
curves: O,
width: C,
height: x
},
pageWidth: r,
pageHeight: a,
rotation: o,
innerMargin: l,
mustSmooth: !0,
areContours: !0
});
}
static process(t, e, s, i, r) {
const [a, o, l] = b(this, Z, Hp).call(this, t), [h, c] = b(this, Z, Op).call(this, a, o, l, Math.hypot(o, l) * n(this, yr).sigmaSFactor, n(this, yr).sigmaR, n(this, yr).kernelSize), u = b(this, Z, Bd).call(this, c), p = b(this, Z, Nd).call(this, h, o, l, u);
return this.processDrawnLines({
lines: {
curves: p,
width: o,
height: l
},
pageWidth: e,
pageHeight: s,
rotation: i,
innerMargin: r,
mustSmooth: !0,
areContours: !0
});
}
static processDrawnLines({
lines: t,
pageWidth: e,
pageHeight: s,
rotation: i,
innerMargin: r,
mustSmooth: a,
areContours: o
}) {
i % 180 !== 0 && ([e, s] = [s, e]);
const {
curves: l,
width: h,
height: c
} = t, u = t.thickness ?? 0, p = [], g = Math.min(e / h, s / c), A = g / e, y = g / s, w = [];
for (const {
points: S
} of l) {
const _ = a ? b(this, Z, Np).call(this, S) : S;
if (!_)
continue;
w.push(_);
const E = _.length, C = new Float32Array(E), x = new Float32Array(3 * (E === 2 ? 2 : E - 2));
if (p.push({
line: x,
points: C
}), E === 2) {
C[0] = _[0] * A, C[1] = _[1] * y, x.set([NaN, NaN, NaN, NaN, C[0], C[1]], 0);
continue;
}
let [T, P, M, O] = _;
T *= A, P *= y, M *= A, O *= y, C.set([T, P, M, O], 0), x.set([NaN, NaN, NaN, NaN, T, P], 0);
for (let D = 4; D < E; D += 2) {
const tt = C[D] = _[D] * A, st = C[D + 1] = _[D + 1] * y;
x.set(L.createBezierPoints(T, P, M, O, tt, st), (D - 2) * 3), [T, P, M, O] = [M, O, tt, st];
}
}
if (p.length === 0)
return null;
const v = o ? new Dd() : new th();
return v.build(p, e, s, 1, i, o ? 0 : u, r), {
outline: v,
newCurves: w,
areContours: o,
thickness: u,
width: h,
height: c
};
}
static async compressSignature({
outlines: t,
areContours: e,
thickness: s,
width: i,
height: r
}) {
let a = 1 / 0, o = -1 / 0, l = 0;
for (const _ of t) {
l += _.length;
for (let E = 2, C = _.length; E < C; E++) {
const x = _[E] - _[E - 2];
a = Math.min(a, x), o = Math.max(o, x);
}
}
let h;
a >= -128 && o <= 127 ? h = Int8Array : a >= -32768 && o <= 32767 ? h = Int16Array : h = Int32Array;
const c = t.length, u = oh + Qa * c, p = new Uint32Array(u);
let g = 0;
p[g++] = u * Uint32Array.BYTES_PER_ELEMENT + (l - 2 * c) * h.BYTES_PER_ELEMENT, p[g++] = 0, p[g++] = i, p[g++] = r, p[g++] = e ? 0 : 1, p[g++] = Math.max(0, Math.floor(s ?? 0)), p[g++] = c, p[g++] = h.BYTES_PER_ELEMENT;
for (const _ of t)
p[g++] = _.length - 2, p[g++] = _[0], p[g++] = _[1];
const A = new CompressionStream("deflate-raw"), y = A.writable.getWriter();
await y.ready, y.write(p);
const w = h.prototype.constructor;
for (const _ of t) {
const E = new w(_.length - 2);
for (let C = 2, x = _.length; C < x; C++)
E[C - 2] = _[C] - _[C - 2];
y.write(E);
}
y.close();
const v = await new Response(A.readable).arrayBuffer(), S = new Uint8Array(v);
return Hu(S);
}
static async decompressSignature(t) {
try {
const e = og(t), {
readable: s,
writable: i
} = new DecompressionStream("deflate-raw"), r = i.getWriter();
await r.ready, r.write(e).then(async () => {
await r.ready, await r.close();
}).catch(() => {
});
let a = null, o = 0;
for await (const _ of s)
a || (a = new Uint8Array(new Uint32Array(_.buffer, 0, 4)[0])), a.set(_, o), o += _.length;
const l = new Uint32Array(a.buffer, 0, a.length >> 2), h = l[1];
if (h !== 0)
throw new Error(`Invalid version: ${h}`);
const c = l[2], u = l[3], p = l[4] === 0, g = l[5], A = l[6], y = l[7], w = [], v = (oh + Qa * A) * Uint32Array.BYTES_PER_ELEMENT;
let S;
switch (y) {
case Int8Array.BYTES_PER_ELEMENT:
S = new Int8Array(a.buffer, v);
break;
case Int16Array.BYTES_PER_ELEMENT:
S = new Int16Array(a.buffer, v);
break;
case Int32Array.BYTES_PER_ELEMENT:
S = new Int32Array(a.buffer, v);
break;
}
o = 0;
for (let _ = 0; _ < A; _++) {
const E = l[Qa * _ + oh], C = new Float32Array(E + 2);
w.push(C);
for (let x = 0; x < Qa - 1; x++)
C[x] = l[Qa * _ + oh + x + 1];
for (let x = 0; x < E; x++)
C[x + 2] = C[x] + S[o++];
}
return {
areContours: p,
thickness: g,
outlines: w,
width: c,
height: u
};
} catch (e) {
return U(`decompressSignature: ${e}`), null;
}
}
}
yr = new WeakMap(), Z = new WeakSet(), Fd = function(t, e, s, i) {
return s -= t, i -= e, s === 0 ? i > 0 ? 0 : 4 : s === 1 ? i + 6 : 2 - i;
}, ss = new WeakMap(), Dp = function(t, e, s, i, r, a, o) {
const l = b(this, Z, Fd).call(this, s, i, r, a);
for (let h = 0; h < 8; h++) {
const c = (-h + l - o + 16) % 8, u = n(this, ss)[2 * c], p = n(this, ss)[2 * c + 1];
if (t[(s + u) * e + (i + p)] !== 0)
return c;
}
return -1;
}, Fp = function(t, e, s, i, r, a, o) {
const l = b(this, Z, Fd).call(this, s, i, r, a);
for (let h = 0; h < 8; h++) {
const c = (h + l + o + 16) % 8, u = n(this, ss)[2 * c], p = n(this, ss)[2 * c + 1];
if (t[(s + u) * e + (i + p)] !== 0)
return c;
}
return -1;
}, Nd = function(t, e, s, i) {
const r = t.length, a = new Int32Array(r);
for (let c = 0; c < r; c++)
a[c] = t[c] <= i ? 1 : 0;
for (let c = 1; c < s - 1; c++)
a[c * e] = a[c * e + e - 1] = 0;
for (let c = 0; c < e; c++)
a[c] = a[e * s - 1 - c] = 0;
let o = 1, l;
const h = [];
for (let c = 1; c < s - 1; c++) {
l = 1;
for (let u = 1; u < e - 1; u++) {
const p = c * e + u, g = a[p];
if (g === 0)
continue;
let A = c, y = u;
if (g === 1 && a[p - 1] === 0)
o += 1, y -= 1;
else if (g >= 1 && a[p + 1] === 0)
o += 1, y += 1, g > 1 && (l = g);
else {
g !== 1 && (l = Math.abs(g));
continue;
}
const w = [u, c], v = y === u + 1, S = {
isHole: v,
points: w,
id: o,
parent: 0
};
h.push(S);
let _;
for (const D of h)
if (D.id === l) {
_ = D;
break;
}
_ ? _.isHole ? S.parent = v ? _.parent : l : S.parent = v ? l : _.parent : S.parent = v ? l : 0;
const E = b(this, Z, Dp).call(this, a, e, c, u, A, y, 0);
if (E === -1) {
a[p] = -o, a[p] !== 1 && (l = Math.abs(a[p]));
continue;
}
let C = n(this, ss)[2 * E], x = n(this, ss)[2 * E + 1];
const T = c + C, P = u + x;
A = T, y = P;
let M = c, O = u;
for (; ; ) {
const D = b(this, Z, Fp).call(this, a, e, M, O, A, y, 1);
C = n(this, ss)[2 * D], x = n(this, ss)[2 * D + 1];
const tt = M + C, st = O + x;
w.push(st, tt);
const q = M * e + O;
if (a[q + 1] === 0 ? a[q] = -o : a[q] === 1 && (a[q] = o), tt === c && st === u && M === T && O === P) {
a[p] !== 1 && (l = Math.abs(a[p]));
break;
} else
A = M, y = O, M = tt, O = st;
}
}
}
return h;
}, Lh = function(t, e, s, i) {
if (s - e <= 4) {
for (let T = e; T < s - 2; T += 2)
i.push(t[T], t[T + 1]);
return;
}
const r = t[e], a = t[e + 1], o = t[s - 4] - r, l = t[s - 3] - a, h = Math.hypot(o, l), c = o / h, u = l / h, p = c * a - u * r, g = l / o, A = 1 / h, y = Math.atan(g), w = Math.cos(y), v = Math.sin(y), S = A * (Math.abs(w) + Math.abs(v)), _ = A * (1 - S + S ** 2), E = Math.max(Math.atan(Math.abs(v + w) * _), Math.atan(Math.abs(v - w) * _));
let C = 0, x = e;
for (let T = e + 2; T < s - 2; T += 2) {
const P = Math.abs(p - c * t[T + 1] + u * t[T]);
P > C && (x = T, C = P);
}
C > (h * E) ** 2 ? (b(this, Z, Lh).call(this, t, e, x + 2, i), b(this, Z, Lh).call(this, t, x, s, i)) : i.push(r, a);
}, Np = function(t) {
const e = [], s = t.length;
return b(this, Z, Lh).call(this, t, 0, s, e), e.push(t[s - 2], t[s - 1]), e.length <= 4 ? null : e;
}, Op = function(t, e, s, i, r, a) {
const o = new Float32Array(a ** 2), l = -2 * i ** 2, h = a >> 1;
for (let y = 0; y < a; y++) {
const w = (y - h) ** 2;
for (let v = 0; v < a; v++)
o[y * a + v] = Math.exp((w + (v - h) ** 2) / l);
}
const c = new Float32Array(256), u = -2 * r ** 2;
for (let y = 0; y < 256; y++)
c[y] = Math.exp(y ** 2 / u);
const p = t.length, g = new Uint8Array(p), A = new Uint32Array(256);
for (let y = 0; y < s; y++)
for (let w = 0; w < e; w++) {
const v = y * e + w, S = t[v];
let _ = 0, E = 0;
for (let x = 0; x < a; x++) {
const T = y + x - h;
if (!(T < 0 || T >= s))
for (let P = 0; P < a; P++) {
const M = w + P - h;
if (M < 0 || M >= e)
continue;
const O = t[T * e + M], D = o[x * a + P] * c[Math.abs(O - S)];
_ += O * D, E += D;
}
}
const C = g[v] = Math.round(_ / E);
A[C]++;
}
return [g, A];
}, Bp = function(t) {
const e = new Uint32Array(256);
for (const s of t)
e[s]++;
return e;
}, Od = function(t) {
const e = t.length, s = new Uint8ClampedArray(e >> 2);
let i = -1 / 0, r = 1 / 0;
for (let o = 0, l = s.length; o < l; o++) {
if (t[(o << 2) + 3] === 0) {
i = s[o] = 255;
continue;
}
const c = s[o] = t[o << 2];
c > i && (i = c), c < r && (r = c);
}
const a = 255 / (i - r);
for (let o = 0; o < e; o++)
s[o] = (s[o] - r) * a;
return s;
}, Bd = function(t) {
let e, s = -1 / 0, i = -1 / 0;
const r = t.findIndex((l) => l !== 0);
let a = r, o = r;
for (e = r; e < 256; e++) {
const l = t[e];
l > s && (e - a > i && (i = e - a, o = e - 1), s = l, a = e);
}
for (e = o - 1; e >= 0 && !(t[e] > t[e + 1]); e--)
;
return e;
}, Hp = function(t) {
const e = t, {
width: s,
height: i
} = t, {
maxDim: r
} = n(this, yr);
let a = s, o = i;
if (s > r || i > r) {
let p = s, g = i, A = Math.log2(Math.max(s, i) / r);
const y = Math.floor(A);
A = A === y ? y - 1 : y;
for (let v = 0; v < A; v++) {
a = Math.ceil(p / 2), o = Math.ceil(g / 2);
const S = new OffscreenCanvas(a, o);
S.getContext("2d").drawImage(t, 0, 0, p, g, 0, 0, a, o), p = a, g = o, t !== e && t.close(), t = S.transferToImageBitmap();
}
const w = Math.min(r / a, r / o);
a = Math.round(a * w), o = Math.round(o * w);
}
const h = new OffscreenCanvas(a, o).getContext("2d", {
willReadFrequently: !0
});
h.filter = "grayscale(1)", h.drawImage(t, 0, 0, t.width, t.height, 0, 0, a, o);
const c = h.getImageData(0, 0, a, o).data;
return [b(this, Z, Od).call(this, c), a, o];
}, m(pi, Z), m(pi, yr, {
maxDim: 512,
sigmaSFactor: 0.02,
sigmaR: 25,
kernelSize: 16
}), m(pi, ss, new Int32Array([0, 1, -1, 1, -1, 0, -1, -1, 0, -1, 1, -1, 1, 0, 1, 1]));
class iu extends Rp {
constructor() {
super(), super.updateProperties({
fill: lt._defaultLineColor,
"stroke-width": 0
});
}
clone() {
const t = new iu();
return t.updateAll(this), t;
}
}
class nu extends Ac {
constructor(t) {
super(t), super.updateProperties({
stroke: lt._defaultLineColor,
"stroke-width": 1
});
}
clone() {
const t = new nu(this._viewParameters);
return t.updateAll(this), t;
}
}
var Qi, Cs, Ji, wr;
const me = class me extends qh {
constructor(e) {
super({
...e,
mustBeCommitted: !0,
name: "signatureEditor"
});
m(this, Qi, !1);
m(this, Cs, null);
m(this, Ji, null);
m(this, wr, null);
this._willKeepAspectRatio = !0, f(this, Ji, e.signatureData || null), f(this, Cs, null), this.defaultL10nId = "pdfjs-editor-signature-editor1";
}
static initialize(e, s) {
lt.initialize(e, s), this._defaultDrawingOptions = new iu(), this._defaultDrawnSignatureOptions = new nu(s.viewParameters);
}
static getDefaultDrawingOptions(e) {
const s = this._defaultDrawingOptions.clone();
return s.updateProperties(e), s;
}
static get supportMultipleDrawings() {
return !1;
}
static get typesMap() {
return X(this, "typesMap", /* @__PURE__ */ new Map());
}
static get isDrawer() {
return !1;
}
get telemetryFinalData() {
return {
type: "signature",
hasDescription: !!n(this, Cs)
};
}
static computeTelemetryFinalData(e) {
const s = e.get("hasDescription");
return {
hasAltText: s.get(!0) ?? 0,
hasNoAltText: s.get(!1) ?? 0
};
}
get isResizable() {
return !0;
}
onScaleChanging() {
this._drawId !== null && super.onScaleChanging();
}
render() {
if (this.div)
return this.div;
let e, s;
const {
_isCopy: i
} = this;
if (i && (this._isCopy = !1, e = this.x, s = this.y), super.render(), this._drawId === null)
if (n(this, Ji)) {
const {
lines: r,
mustSmooth: a,
areContours: o,
description: l,
uuid: h,
heightInPage: c
} = n(this, Ji), {
rawDims: {
pageWidth: u,
pageHeight: p
},
rotation: g
} = this.parent.viewport, A = pi.processDrawnLines({
lines: r,
pageWidth: u,
pageHeight: p,
rotation: g,
innerMargin: me._INNER_MARGIN,
mustSmooth: a,
areContours: o
});
this.addSignature(A, c, l, h);
} else
this.div.setAttribute("data-l10n-args", JSON.stringify({
description: ""
})), this.div.hidden = !0, this._uiManager.getSignature(this);
return i && (this._isCopy = !0, this._moveAfterPaste(e, s)), this.div;
}
setUuid(e) {
f(this, wr, e), this.addEditToolbar();
}
getUuid() {
return n(this, wr);
}
get description() {
return n(this, Cs);
}
set description(e) {
f(this, Cs, e), super.addEditToolbar().then((s) => {
s == null || s.updateEditSignatureButton(e);
});
}
getSignaturePreview() {
const {
newCurves: e,
areContours: s,
thickness: i,
width: r,
height: a
} = n(this, Ji), o = Math.max(r, a), l = pi.processDrawnLines({
lines: {
curves: e.map((h) => ({
points: h
})),
thickness: i,
width: r,
height: a
},
pageWidth: o,
pageHeight: o,
rotation: 0,
innerMargin: 0,
mustSmooth: !1,
areContours: s
});
return {
areContours: s,
outline: l.outline
};
}
get toolbarButtons() {
return this._uiManager.signatureManager ? [["editSignature", this._uiManager.signatureManager]] : super.toolbarButtons;
}
addSignature(e, s, i, r) {
const {
x: a,
y: o
} = this, {
outline: l
} = f(this, Ji, e);
f(this, Qi, l instanceof Dd), this.description = i, this.div.setAttribute("data-l10n-args", JSON.stringify({
description: i
}));
let h;
n(this, Qi) ? h = me.getDefaultDrawingOptions() : (h = me._defaultDrawnSignatureOptions.clone(), h.updateProperties({
"stroke-width": l.thickness
})), this._addOutlines({
drawOutlines: l,
drawingOptions: h
});
const [c, u] = this.parentDimensions, [, p] = this.pageDimensions;
let g = s / p;
g = g >= 1 ? 0.5 : g, this.width *= g / this.height, this.width >= 1 && (g *= 0.9 / this.width, this.width = 0.9), this.height = g, this.setDims(c * this.width, u * this.height), this.x = a, this.y = o, this.center(), this._onResized(), this.onScaleChanging(), this.rotate(), this._uiManager.addToAnnotationStorage(this), this.setUuid(r), this._reportTelemetry({
action: "pdfjs.signature.inserted",
data: {
hasBeenSaved: !!r,
hasDescription: !!i
}
}), this.div.hidden = !1;
}
getFromImage(e) {
const {
rawDims: {
pageWidth: s,
pageHeight: i
},
rotation: r
} = this.parent.viewport;
return pi.process(e, s, i, r, me._INNER_MARGIN);
}
getFromText(e, s) {
const {
rawDims: {
pageWidth: i,
pageHeight: r
},
rotation: a
} = this.parent.viewport;
return pi.extractContoursFromText(e, s, i, r, a, me._INNER_MARGIN);
}
getDrawnSignature(e) {
const {
rawDims: {
pageWidth: s,
pageHeight: i
},
rotation: r
} = this.parent.viewport;
return pi.processDrawnLines({
lines: e,
pageWidth: s,
pageHeight: i,
rotation: r,
innerMargin: me._INNER_MARGIN,
mustSmooth: !1,
areContours: !1
});
}
createDrawingOptions({
areContours: e,
thickness: s
}) {
e ? this._drawingOptions = me.getDefaultDrawingOptions() : (this._drawingOptions = me._defaultDrawnSignatureOptions.clone(), this._drawingOptions.updateProperties({
"stroke-width": s
}));
}
serialize(e = !1) {
if (this.isEmpty())
return null;
const {
lines: s,
points: i,
rect: r
} = this.serializeDraw(e), {
_drawingOptions: {
"stroke-width": a
}
} = this, o = {
annotationType: z.SIGNATURE,
isSignature: !0,
areContours: n(this, Qi),
color: [0, 0, 0],
thickness: n(this, Qi) ? 0 : a,
pageIndex: this.pageIndex,
rect: r,
rotation: this.rotation,
structTreeParentId: this._structTreeParentId
};
return e ? (o.paths = {
lines: s,
points: i
}, o.uuid = n(this, wr), o.isCopy = !0) : o.lines = s, n(this, Cs) && (o.accessibilityData = {
type: "Figure",
alt: n(this, Cs)
}), o;
}
static deserializeDraw(e, s, i, r, a, o) {
return o.areContours ? Dd.deserialize(e, s, i, r, a, o) : th.deserialize(e, s, i, r, a, o);
}
static async deserialize(e, s, i) {
var a;
const r = await super.deserialize(e, s, i);
return f(r, Qi, e.areContours), f(r, Cs, ((a = e.accessibilityData) == null ? void 0 : a.alt) || ""), f(r, wr, e.uuid), r;
}
};
Qi = new WeakMap(), Cs = new WeakMap(), Ji = new WeakMap(), wr = new WeakMap(), R(me, "_type", "signature"), R(me, "_editorType", z.SIGNATURE), R(me, "_defaultDrawingOptions", null);
let Hd = me;
var dt, Ot, Zi, li, tn, za, hi, vr, xs, Pe, Ua, Q, mo, bo, Dh, Fh, Nh, Gd, Oh, $p;
class $d extends lt {
constructor(e) {
super({
...e,
name: "stampEditor"
});
m(this, Q);
m(this, dt, null);
m(this, Ot, null);
m(this, Zi, null);
m(this, li, null);
m(this, tn, null);
m(this, za, "");
m(this, hi, null);
m(this, vr, !1);
m(this, xs, null);
m(this, Pe, !1);
m(this, Ua, !1);
f(this, li, e.bitmapUrl), f(this, tn, e.bitmapFile), this.defaultL10nId = "pdfjs-editor-stamp-editor";
}
static initialize(e, s) {
lt.initialize(e, s);
}
static isHandlingMimeForPasting(e) {
return Lc.includes(e);
}
static paste(e, s) {
s.pasteEditor({
mode: z.STAMP
}, {
bitmapFile: e.getAsFile()
});
}
altTextFinish() {
this._uiManager.useNewAltTextFlow && (this.div.hidden = !1), super.altTextFinish();
}
get telemetryFinalData() {
var e;
return {
type: "stamp",
hasAltText: !!((e = this.altTextData) != null && e.altText)
};
}
static computeTelemetryFinalData(e) {
const s = e.get("hasAltText");
return {
hasAltText: s.get(!0) ?? 0,
hasNoAltText: s.get(!1) ?? 0
};
}
async mlGuessAltText(e = null, s = !0) {
if (this.hasAltTextData())
return null;
const {
mlManager: i
} = this._uiManager;
if (!i)
throw new Error("No ML.");
if (!await i.isEnabledFor("altText"))
throw new Error("ML isn't enabled for alt text.");
const {
data: r,
width: a,
height: o
} = e || this.copyCanvas(null, null, !0).imageData, l = await i.guess({
name: "altText",
request: {
data: r,
width: a,
height: o,
channels: r.length / (a * o)
}
});
if (!l)
throw new Error("No response from the AI service.");
if (l.error)
throw new Error("Error from the AI service.");
if (l.cancel)
return null;
if (!l.output)
throw new Error("No valid response from the AI service.");
const h = l.output;
return await this.setGuessedAltText(h), s && !this.hasAltTextData() && (this.altTextData = {
alt: h,
decorative: !1
}), h;
}
remove() {
var e;
n(this, Ot) && (f(this, dt, null), this._uiManager.imageManager.deleteId(n(this, Ot)), (e = n(this, hi)) == null || e.remove(), f(this, hi, null), n(this, xs) && (clearTimeout(n(this, xs)), f(this, xs, null))), super.remove();
}
rebuild() {
if (!this.parent) {
n(this, Ot) && b(this, Q, Dh).call(this);
return;
}
super.rebuild(), this.div !== null && (n(this, Ot) && n(this, hi) === null && b(this, Q, Dh).call(this), this.isAttachedToDOM || this.parent.add(this));
}
onceAdded(e) {
this._isDraggable = !0, e && this.div.focus();
}
isEmpty() {
return !(n(this, Zi) || n(this, dt) || n(this, li) || n(this, tn) || n(this, Ot) || n(this, vr));
}
get toolbarButtons() {
return [["altText", this.createAltText()]];
}
get isResizable() {
return !0;
}
render() {
if (this.div)
return this.div;
let e, s;
return this._isCopy && (e = this.x, s = this.y), super.render(), this.div.hidden = !0, this.createAltText(), n(this, vr) || (n(this, dt) ? b(this, Q, Fh).call(this) : b(this, Q, Dh).call(this)), this._isCopy && this._moveAfterPaste(e, s), this._uiManager.addShouldRescale(this), this.div;
}
setCanvas(e, s) {
const {
id: i,
bitmap: r
} = this._uiManager.imageManager.getFromCanvas(e, s);
s.remove(), i && this._uiManager.imageManager.isValidId(i) && (f(this, Ot, i), r && f(this, dt, r), f(this, vr, !1), b(this, Q, Fh).call(this));
}
_onResized() {
this.onScaleChanging();
}
onScaleChanging() {
if (!this.parent)
return;
n(this, xs) !== null && clearTimeout(n(this, xs)), f(this, xs, setTimeout(() => {
f(this, xs, null), b(this, Q, Gd).call(this);
}, 200));
}
copyCanvas(e, s, i = !1) {
var g;
e || (e = 224);
const {
width: r,
height: a
} = n(this, dt), o = new Rs();
let l = n(this, dt), h = r, c = a, u = null;
if (s) {
if (r > s || a > s) {
const P = Math.min(s / r, s / a);
h = Math.floor(r * P), c = Math.floor(a * P);
}
u = document.createElement("canvas");
const A = u.width = Math.ceil(h * o.sx), y = u.height = Math.ceil(c * o.sy);
n(this, Pe) || (l = b(this, Q, Nh).call(this, A, y));
const w = u.getContext("2d");
w.filter = this._uiManager.hcmFilter;
let v = "white", S = "#cfcfd8";
this._uiManager.hcmFilter !== "none" ? S = "black" : (g = window.matchMedia) != null && g.call(window, "(prefers-color-scheme: dark)").matches && (v = "#8f8f9d", S = "#42414d");
const _ = 15, E = _ * o.sx, C = _ * o.sy, x = new OffscreenCanvas(E * 2, C * 2), T = x.getContext("2d");
T.fillStyle = v, T.fillRect(0, 0, E * 2, C * 2), T.fillStyle = S, T.fillRect(0, 0, E, C), T.fillRect(E, C, E, C), w.fillStyle = w.createPattern(x, "repeat"), w.fillRect(0, 0, A, y), w.drawImage(l, 0, 0, l.width, l.height, 0, 0, A, y);
}
let p = null;
if (i) {
let A, y;
if (o.symmetric && l.width < e && l.height < e)
A = l.width, y = l.height;
else if (l = n(this, dt), r > e || a > e) {
const S = Math.min(e / r, e / a);
A = Math.floor(r * S), y = Math.floor(a * S), n(this, Pe) || (l = b(this, Q, Nh).call(this, A, y));
}
const v = new OffscreenCanvas(A, y).getContext("2d", {
willReadFrequently: !0
});
v.drawImage(l, 0, 0, l.width, l.height, 0, 0, A, y), p = {
width: A,
height: y,
data: v.getImageData(0, 0, A, y).data
};
}
return {
canvas: u,
width: h,
height: c,
imageData: p
};
}
static async deserialize(e, s, i) {
var w;
let r = null, a = !1;
if (e instanceof ep) {
const {
data: {
rect: v,
rotation: S,
id: _,
structParent: E,
popupRef: C
},
container: x,
parent: {
page: {
pageNumber: T
}
},
canvas: P
} = e;
let M, O;
P ? (delete e.canvas, {
id: M,
bitmap: O
} = i.imageManager.getFromCanvas(x.id, P), P.remove()) : (a = !0, e._hasNoCanvas = !0);
const D = ((w = await s._structTree.getAriaAttributes(`${Xd}${_}`)) == null ? void 0 : w.get("aria-label")) || "";
r = e = {
annotationType: z.STAMP,
bitmapId: M,
bitmap: O,
pageIndex: T - 1,
rect: v.slice(0),
rotation: S,
annotationElementId: _,
id: _,
deleted: !1,
accessibilityData: {
decorative: !1,
altText: D
},
isSvg: !1,
structParent: E,
popupRef: C
};
}
const o = await super.deserialize(e, s, i), {
rect: l,
bitmap: h,
bitmapUrl: c,
bitmapId: u,
isSvg: p,
accessibilityData: g
} = e;
a ? (i.addMissingCanvas(e.id, o), f(o, vr, !0)) : u && i.imageManager.isValidId(u) ? (f(o, Ot, u), h && f(o, dt, h)) : f(o, li, c), f(o, Pe, p);
const [A, y] = o.pageDimensions;
return o.width = (l[2] - l[0]) / A, o.height = (l[3] - l[1]) / y, g && (o.altTextData = g), o._initialData = r, f(o, Ua, !!r), o;
}
serialize(e = !1, s = null) {
if (this.isEmpty())
return null;
if (this.deleted)
return this.serializeDeleted();
const i = {
annotationType: z.STAMP,
bitmapId: n(this, Ot),
pageIndex: this.pageIndex,
rect: this.getRect(0, 0),
rotation: this.rotation,
isSvg: n(this, Pe),
structTreeParentId: this._structTreeParentId
};
if (e)
return i.bitmapUrl = b(this, Q, Oh).call(this, !0), i.accessibilityData = this.serializeAltText(!0), i.isCopy = !0, i;
const {
decorative: r,
altText: a
} = this.serializeAltText(!1);
if (!r && a && (i.accessibilityData = {
type: "Figure",
alt: a
}), this.annotationElementId) {
const l = b(this, Q, $p).call(this, i);
if (l.isSame)
return null;
l.isSameAltText ? delete i.accessibilityData : i.accessibilityData.structParent = this._initialData.structParent ?? -1;
}
if (i.id = this.annotationElementId, s === null)
return i;
s.stamps || (s.stamps = /* @__PURE__ */ new Map());
const o = n(this, Pe) ? (i.rect[2] - i.rect[0]) * (i.rect[3] - i.rect[1]) : null;
if (!s.stamps.has(n(this, Ot)))
s.stamps.set(n(this, Ot), {
area: o,
serialized: i
}), i.bitmap = b(this, Q, Oh).call(this, !1);
else if (n(this, Pe)) {
const l = s.stamps.get(n(this, Ot));
o > l.area && (l.area = o, l.serialized.bitmap.close(), l.serialized.bitmap = b(this, Q, Oh).call(this, !1));
}
return i;
}
renderAnnotationElement(e) {
return e.updateEdited({
rect: this.getRect(0, 0)
}), null;
}
}
dt = new WeakMap(), Ot = new WeakMap(), Zi = new WeakMap(), li = new WeakMap(), tn = new WeakMap(), za = new WeakMap(), hi = new WeakMap(), vr = new WeakMap(), xs = new WeakMap(), Pe = new WeakMap(), Ua = new WeakMap(), Q = new WeakSet(), mo = function(e, s = !1) {
if (!e) {
this.remove();
return;
}
f(this, dt, e.bitmap), s || (f(this, Ot, e.id), f(this, Pe, e.isSvg)), e.file && f(this, za, e.file.name), b(this, Q, Fh).call(this);
}, bo = function() {
if (f(this, Zi, null), this._uiManager.enableWaiting(!1), !!n(this, hi)) {
if (this._uiManager.useNewAltTextWhenAddingImage && this._uiManager.useNewAltTextFlow && n(this, dt)) {
this.addEditToolbar().then(() => {
this._editToolbar.hide(), this._uiManager.editAltText(this, !0);
});
return;
}
if (!this._uiManager.useNewAltTextWhenAddingImage && this._uiManager.useNewAltTextFlow && n(this, dt)) {
this._reportTelemetry({
action: "pdfjs.image.image_added",
data: {
alt_text_modal: !1,
alt_text_type: "empty"
}
});
try {
this.mlGuessAltText();
} catch {
}
}
this.div.focus();
}
}, Dh = function() {
if (n(this, Ot)) {
this._uiManager.enableWaiting(!0), this._uiManager.imageManager.getFromId(n(this, Ot)).then((i) => b(this, Q, mo).call(this, i, !0)).finally(() => b(this, Q, bo).call(this));
return;
}
if (n(this, li)) {
const i = n(this, li);
f(this, li, null), this._uiManager.enableWaiting(!0), f(this, Zi, this._uiManager.imageManager.getFromUrl(i).then((r) => b(this, Q, mo).call(this, r)).finally(() => b(this, Q, bo).call(this)));
return;
}
if (n(this, tn)) {
const i = n(this, tn);
f(this, tn, null), this._uiManager.enableWaiting(!0), f(this, Zi, this._uiManager.imageManager.getFromFile(i).then((r) => b(this, Q, mo).call(this, r)).finally(() => b(this, Q, bo).call(this)));
return;
}
const e = document.createElement("input");
e.type = "file", e.accept = Lc.join(",");
const s = this._uiManager._signal;
f(this, Zi, new Promise((i) => {
e.addEventListener("change", async () => {
if (!e.files || e.files.length === 0)
this.remove();
else {
this._uiManager.enableWaiting(!0);
const r = await this._uiManager.imageManager.getFromFile(e.files[0]);
this._reportTelemetry({
action: "pdfjs.image.image_selected",
data: {
alt_text_modal: this._uiManager.useNewAltTextFlow
}
}), b(this, Q, mo).call(this, r);
}
i();
}, {
signal: s
}), e.addEventListener("cancel", () => {
this.remove(), i();
}, {
signal: s
});
}).finally(() => b(this, Q, bo).call(this))), e.click();
}, Fh = function() {
var u;
const {
div: e
} = this;
let {
width: s,
height: i
} = n(this, dt);
const [r, a] = this.pageDimensions, o = 0.75;
if (this.width)
s = this.width * r, i = this.height * a;
else if (s > o * r || i > o * a) {
const p = Math.min(o * r / s, o * a / i);
s *= p, i *= p;
}
const [l, h] = this.parentDimensions;
this.setDims(s * l / r, i * h / a), this._uiManager.enableWaiting(!1);
const c = f(this, hi, document.createElement("canvas"));
c.setAttribute("role", "img"), this.addContainer(c), this.width = s / r, this.height = i / a, (u = this._initialOptions) != null && u.isCentered ? this.center() : this.fixAndSetPosition(), this._initialOptions = null, (!this._uiManager.useNewAltTextWhenAddingImage || !this._uiManager.useNewAltTextFlow || this.annotationElementId) && (e.hidden = !1), b(this, Q, Gd).call(this), n(this, Ua) || (this.parent.addUndoableEditor(this), f(this, Ua, !0)), this._reportTelemetry({
action: "inserted_image"
}), n(this, za) && this.div.setAttribute("aria-description", n(this, za)), this.annotationElementId || this._uiManager.a11yAlert("pdfjs-editor-stamp-added-alert");
}, Nh = function(e, s) {
const {
width: i,
height: r
} = n(this, dt);
let a = i, o = r, l = n(this, dt);
for (; a > 2 * e || o > 2 * s; ) {
const h = a, c = o;
a > 2 * e && (a = a >= 16384 ? Math.floor(a / 2) - 1 : Math.ceil(a / 2)), o > 2 * s && (o = o >= 16384 ? Math.floor(o / 2) - 1 : Math.ceil(o / 2));
const u = new OffscreenCanvas(a, o);
u.getContext("2d").drawImage(l, 0, 0, h, c, 0, 0, a, o), l = u.transferToImageBitmap();
}
return l;
}, Gd = function() {
const [e, s] = this.parentDimensions, {
width: i,
height: r
} = this, a = new Rs(), o = Math.ceil(i * e * a.sx), l = Math.ceil(r * s * a.sy), h = n(this, hi);
if (!h || h.width === o && h.height === l)
return;
h.width = o, h.height = l;
const c = n(this, Pe) ? n(this, dt) : b(this, Q, Nh).call(this, o, l), u = h.getContext("2d");
u.filter = this._uiManager.hcmFilter, u.drawImage(c, 0, 0, c.width, c.height, 0, 0, o, l);
}, Oh = function(e) {
if (e) {
if (n(this, Pe)) {
const r = this._uiManager.imageManager.getSvgUrl(n(this, Ot));
if (r)
return r;
}
const s = document.createElement("canvas");
return {
width: s.width,
height: s.height
} = n(this, dt), s.getContext("2d").drawImage(n(this, dt), 0, 0), s.toDataURL();
}
if (n(this, Pe)) {
const [s, i] = this.pageDimensions, r = Math.round(this.width * s * on.PDF_TO_CSS_UNITS), a = Math.round(this.height * i * on.PDF_TO_CSS_UNITS), o = new OffscreenCanvas(r, a);
return o.getContext("2d").drawImage(n(this, dt), 0, 0, n(this, dt).width, n(this, dt).height, 0, 0, r, a), o.transferToImageBitmap();
}
return structuredClone(n(this, dt));
}, $p = function(e) {
var o;
const {
pageIndex: s,
accessibilityData: {
altText: i
}
} = this._initialData, r = e.pageIndex === s, a = (((o = e.accessibilityData) == null ? void 0 : o.alt) || "") === i;
return {
isSame: !this._hasBeenMoved && !this._hasBeenResized && r && a,
isSameAltText: a
};
}, R($d, "_type", "stamp"), R($d, "_editorType", z.STAMP);
var _r, ja, Ts, en, ci, Ie, sn, Va, Sr, is, di, Bt, ui, nn, Wa, B, rn, ut, Gp, cs, Ud, jd, Bh;
const We = class We {
constructor({
uiManager: t,
pageIndex: e,
div: s,
structTreeLayer: i,
accessibilityManager: r,
annotationLayer: a,
drawLayer: o,
textLayer: l,
viewport: h,
l10n: c
}) {
m(this, ut);
m(this, _r);
m(this, ja, !1);
m(this, Ts, null);
m(this, en, null);
m(this, ci, null);
m(this, Ie, /* @__PURE__ */ new Map());
m(this, sn, !1);
m(this, Va, !1);
m(this, Sr, !1);
m(this, is, null);
m(this, di, null);
m(this, Bt, null);
m(this, ui, null);
m(this, nn, null);
m(this, Wa, -1);
m(this, B);
const u = [...n(We, rn).values()];
if (!We._initialized) {
We._initialized = !0;
for (const p of u)
p.initialize(c, t);
}
t.registerEditorTypes(u), f(this, B, t), this.pageIndex = e, this.div = s, f(this, _r, r), f(this, Ts, a), this.viewport = h, f(this, Bt, l), this.drawLayer = o, this._structTree = i, n(this, B).addLayer(this);
}
get isEmpty() {
return n(this, Ie).size === 0;
}
get isInvisible() {
return this.isEmpty && n(this, B).getMode() === z.NONE;
}
updateToolbar(t) {
n(this, B).updateToolbar(t);
}
updateMode(t = n(this, B).getMode()) {
switch (b(this, ut, Bh).call(this), t) {
case z.NONE:
this.disableTextSelection(), this.togglePointerEvents(!1), this.toggleAnnotationLayerPointerEvents(!0), this.disableClick();
return;
case z.INK:
this.disableTextSelection(), this.togglePointerEvents(!0), this.enableClick();
break;
case z.HIGHLIGHT:
this.enableTextSelection(), this.togglePointerEvents(!1), this.disableClick();
break;
default:
this.disableTextSelection(), this.togglePointerEvents(!0), this.enableClick();
}
this.toggleAnnotationLayerPointerEvents(!1);
const {
classList: e
} = this.div;
for (const s of n(We, rn).values())
e.toggle(`${s._type}Editing`, t === s._editorType);
this.div.hidden = !1;
}
hasTextLayer(t) {
var e;
return t === ((e = n(this, Bt)) == null ? void 0 : e.div);
}
setEditingState(t) {
n(this, B).setEditingState(t);
}
addCommands(t) {
n(this, B).addCommands(t);
}
cleanUndoStack(t) {
n(this, B).cleanUndoStack(t);
}
toggleDrawing(t = !1) {
this.div.classList.toggle("drawing", !t);
}
togglePointerEvents(t = !1) {
this.div.classList.toggle("disabled", !t);
}
toggleAnnotationLayerPointerEvents(t = !1) {
var e;
(e = n(this, Ts)) == null || e.div.classList.toggle("disabled", !t);
}
async enable() {
var s;
f(this, Sr, !0), this.div.tabIndex = 0, this.togglePointerEvents(!0), (s = n(this, nn)) == null || s.abort(), f(this, nn, null);
const t = /* @__PURE__ */ new Set();
for (const i of n(this, Ie).values())
i.enableEditing(), i.show(!0), i.annotationElementId && (n(this, B).removeChangedExistingAnnotation(i), t.add(i.annotationElementId));
if (!n(this, Ts)) {
f(this, Sr, !1);
return;
}
const e = n(this, Ts).getEditableAnnotations();
for (const i of e) {
if (i.hide(), n(this, B).isDeletedAnnotationElement(i.data.id) || t.has(i.data.id))
continue;
const r = await this.deserialize(i);
r && (this.addOrRebuild(r), r.enableEditing());
}
f(this, Sr, !1);
}
disable() {
var i;
if (f(this, Va, !0), this.div.tabIndex = -1, this.togglePointerEvents(!1), n(this, Bt) && !n(this, nn)) {
f(this, nn, new AbortController());
const r = n(this, B).combinedSignal(n(this, nn));
n(this, Bt).div.addEventListener("pointerdown", (a) => {
const {
clientX: l,
clientY: h,
timeStamp: c
} = a, u = n(this, Wa);
if (c - u > 500) {
f(this, Wa, c);
return;
}
f(this, Wa, -1);
const {
classList: p
} = this.div;
p.toggle("getElements", !0);
const g = document.elementsFromPoint(l, h);
if (p.toggle("getElements", !1), !this.div.contains(g[0]))
return;
let A;
const y = new RegExp(`^${Du}[0-9]+$`);
for (const v of g)
if (y.test(v.id)) {
A = v.id;
break;
}
if (!A)
return;
const w = n(this, Ie).get(A);
(w == null ? void 0 : w.annotationElementId) === null && (a.stopPropagation(), a.preventDefault(), w.dblclick());
}, {
signal: r,
capture: !0
});
}
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map();
for (const r of n(this, Ie).values())
if (r.disableEditing(), !!r.annotationElementId) {
if (r.serialize() !== null) {
t.set(r.annotationElementId, r);
continue;
} else
e.set(r.annotationElementId, r);
(i = this.getEditableAnnotation(r.annotationElementId)) == null || i.show(), r.remove();
}
if (n(this, Ts)) {
const r = n(this, Ts).getEditableAnnotations();
for (const a of r) {
const {
id: o
} = a.data;
if (n(this, B).isDeletedAnnotationElement(o))
continue;
let l = e.get(o);
if (l) {
l.resetAnnotationElement(a), l.show(!1), a.show();
continue;
}
l = t.get(o), l && (n(this, B).addChangedExistingAnnotation(l), l.renderAnnotationElement(a) && l.show(!1)), a.show();
}
}
b(this, ut, Bh).call(this), this.isEmpty && (this.div.hidden = !0);
const {
classList: s
} = this.div;
for (const r of n(We, rn).values())
s.remove(`${r._type}Editing`);
this.disableTextSelection(), this.toggleAnnotationLayerPointerEvents(!0), f(this, Va, !1);
}
getEditableAnnotation(t) {
var e;
return ((e = n(this, Ts)) == null ? void 0 : e.getEditableAnnotation(t)) || null;
}
setActiveEditor(t) {
n(this, B).getActive() !== t && n(this, B).setActiveEditor(t);
}
enableTextSelection() {
var t;
if (this.div.tabIndex = -1, (t = n(this, Bt)) != null && t.div && !n(this, ui)) {
f(this, ui, new AbortController());
const e = n(this, B).combinedSignal(n(this, ui));
n(this, Bt).div.addEventListener("pointerdown", b(this, ut, Gp).bind(this), {
signal: e
}), n(this, Bt).div.classList.add("highlighting");
}
}
disableTextSelection() {
var t;
this.div.tabIndex = 0, (t = n(this, Bt)) != null && t.div && n(this, ui) && (n(this, ui).abort(), f(this, ui, null), n(this, Bt).div.classList.remove("highlighting"));
}
enableClick() {
if (n(this, en))
return;
f(this, en, new AbortController());
const t = n(this, B).combinedSignal(n(this, en));
this.div.addEventListener("pointerdown", this.pointerdown.bind(this), {
signal: t
});
const e = this.pointerup.bind(this);
this.div.addEventListener("pointerup", e, {
signal: t
}), this.div.addEventListener("pointercancel", e, {
signal: t
});
}
disableClick() {
var t;
(t = n(this, en)) == null || t.abort(), f(this, en, null);
}
attach(t) {
n(this, Ie).set(t.id, t);
const {
annotationElementId: e
} = t;
e && n(this, B).isDeletedAnnotationElement(e) && n(this, B).removeDeletedAnnotationElement(t);
}
detach(t) {
var e;
n(this, Ie).delete(t.id), (e = n(this, _r)) == null || e.removePointerInTextLayer(t.contentDiv), !n(this, Va) && t.annotationElementId && n(this, B).addDeletedAnnotationElement(t);
}
remove(t) {
this.detach(t), n(this, B).removeEditor(t), t.div.remove(), t.isAttachedToDOM = !1;
}
changeParent(t) {
var e;
t.parent !== this && (t.parent && t.annotationElementId && (n(this, B).addDeletedAnnotationElement(t.annotationElementId), lt.deleteAnnotationElement(t), t.annotationElementId = null), this.attach(t), (e = t.parent) == null || e.detach(t), t.setParent(this), t.div && t.isAttachedToDOM && (t.div.remove(), this.div.append(t.div)));
}
add(t) {
if (!(t.parent === this && t.isAttachedToDOM)) {
if (this.changeParent(t), n(this, B).addEditor(t), this.attach(t), !t.isAttachedToDOM) {
const e = t.render();
this.div.append(e), t.isAttachedToDOM = !0;
}
t.fixAndSetPosition(), t.onceAdded(!n(this, Sr)), n(this, B).addToAnnotationStorage(t), t._reportTelemetry(t.telemetryInitialData);
}
}
moveEditorInDOM(t) {
var s;
if (!t.isAttachedToDOM)
return;
const {
activeElement: e
} = document;
t.div.contains(e) && !n(this, ci) && (t._focusEventsAllowed = !1, f(this, ci, setTimeout(() => {
f(this, ci, null), t.div.contains(document.activeElement) ? t._focusEventsAllowed = !0 : (t.div.addEventListener("focusin", () => {
t._focusEventsAllowed = !0;
}, {
once: !0,
signal: n(this, B)._signal
}), e.focus());
}, 0))), t._structTreeParentId = (s = n(this, _r)) == null ? void 0 : s.moveElementInDOM(this.div, t.div, t.contentDiv, !0);
}
addOrRebuild(t) {
t.needsToBeRebuilt() ? (t.parent || (t.parent = this), t.rebuild(), t.show()) : this.add(t);
}
addUndoableEditor(t) {
const e = () => t._uiManager.rebuild(t), s = () => {
t.remove();
};
this.addCommands({
cmd: e,
undo: s,
mustExec: !1
});
}
getNextId() {
return n(this, B).getId();
}
combinedSignal(t) {
return n(this, B).combinedSignal(t);
}
canCreateNewEmptyEditor() {
var t;
return (t = n(this, ut, cs)) == null ? void 0 : t.canCreateNewEmptyEditor();
}
async pasteEditor(t, e) {
this.updateToolbar(t), await n(this, B).updateMode(t.mode);
const {
offsetX: s,
offsetY: i
} = b(this, ut, jd).call(this), r = this.getNextId(), a = b(this, ut, Ud).call(this, {
parent: this,
id: r,
x: s,
y: i,
uiManager: n(this, B),
isCentered: !0,
...e
});
a && this.add(a);
}
async deserialize(t) {
var e;
return await ((e = n(We, rn).get(t.annotationType ?? t.annotationEditorType)) == null ? void 0 : e.deserialize(t, this, n(this, B))) || null;
}
createAndAddNewEditor(t, e, s = {}) {
const i = this.getNextId(), r = b(this, ut, Ud).call(this, {
parent: this,
id: i,
x: t.offsetX,
y: t.offsetY,
uiManager: n(this, B),
isCentered: e,
...s
});
return r && this.add(r), r;
}
addNewEditor(t = {}) {
this.createAndAddNewEditor(b(this, ut, jd).call(this), !0, t);
}
setSelected(t) {
n(this, B).setSelected(t);
}
toggleSelected(t) {
n(this, B).toggleSelected(t);
}
unselect(t) {
n(this, B).unselect(t);
}
pointerup(t) {
var i;
const {
isMac: e
} = Wt.platform;
if (t.button !== 0 || t.ctrlKey && e || t.target !== this.div || !n(this, sn) || (f(this, sn, !1), (i = n(this, ut, cs)) != null && i.isDrawer && n(this, ut, cs).supportMultipleDrawings))
return;
if (!n(this, ja)) {
f(this, ja, !0);
return;
}
const s = n(this, B).getMode();
if (s === z.STAMP || s === z.SIGNATURE) {
n(this, B).unselectAll();
return;
}
this.createAndAddNewEditor(t, !1);
}
pointerdown(t) {
var i;
if (n(this, B).getMode() === z.HIGHLIGHT && this.enableTextSelection(), n(this, sn)) {
f(this, sn, !1);
return;
}
const {
isMac: e
} = Wt.platform;
if (t.button !== 0 || t.ctrlKey && e || t.target !== this.div)
return;
if (f(this, sn, !0), (i = n(this, ut, cs)) != null && i.isDrawer) {
this.startDrawingSession(t);
return;
}
const s = n(this, B).getActive();
f(this, ja, !s || s.isEmpty());
}
startDrawingSession(t) {
if (this.div.focus({
preventScroll: !0
}), n(this, is)) {
n(this, ut, cs).startDrawing(this, n(this, B), !1, t);
return;
}
n(this, B).setCurrentDrawingSession(this), f(this, is, new AbortController());
const e = n(this, B).combinedSignal(n(this, is));
this.div.addEventListener("blur", ({
relatedTarget: s
}) => {
s && !this.div.contains(s) && (f(this, di, null), this.commitOrRemove());
}, {
signal: e
}), n(this, ut, cs).startDrawing(this, n(this, B), !1, t);
}
pause(t) {
if (t) {
const {
activeElement: e
} = document;
this.div.contains(e) && f(this, di, e);
return;
}
n(this, di) && setTimeout(() => {
var e;
(e = n(this, di)) == null || e.focus(), f(this, di, null);
}, 0);
}
endDrawingSession(t = !1) {
return n(this, is) ? (n(this, B).setCurrentDrawingSession(null), n(this, is).abort(), f(this, is, null), f(this, di, null), n(this, ut, cs).endDrawing(t)) : null;
}
findNewParent(t, e, s) {
const i = n(this, B).findParent(e, s);
return i === null || i === this ? !1 : (i.changeParent(t), !0);
}
commitOrRemove() {
return n(this, is) ? (this.endDrawingSession(), !0) : !1;
}
onScaleChanging() {
n(this, is) && n(this, ut, cs).onScaleChangingWhenDrawing(this);
}
destroy() {
var t, e;
this.commitOrRemove(), ((t = n(this, B).getActive()) == null ? void 0 : t.parent) === this && (n(this, B).commitOrRemove(), n(this, B).setActiveEditor(null)), n(this, ci) && (clearTimeout(n(this, ci)), f(this, ci, null));
for (const s of n(this, Ie).values())
(e = n(this, _r)) == null || e.removePointerInTextLayer(s.contentDiv), s.setParent(null), s.isAttachedToDOM = !1, s.div.remove();
this.div = null, n(this, Ie).clear(), n(this, B).removeLayer(this);
}
render({
viewport: t
}) {
this.viewport = t, Cr(this.div, t);
for (const e of n(this, B).getEditors(this.pageIndex))
this.add(e), e.rebuild();
this.updateMode();
}
update({
viewport: t
}) {
n(this, B).commitOrRemove(), b(this, ut, Bh).call(this);
const e = this.viewport.rotation, s = t.rotation;
if (this.viewport = t, Cr(this.div, {
rotation: s
}), e !== s)
for (const i of n(this, Ie).values())
i.rotate(s);
}
get pageDimensions() {
const {
pageWidth: t,
pageHeight: e
} = this.viewport.rawDims;
return [t, e];
}
get scale() {
return n(this, B).viewParameters.realScale;
}
};
_r = new WeakMap(), ja = new WeakMap(), Ts = new WeakMap(), en = new WeakMap(), ci = new WeakMap(), Ie = new WeakMap(), sn = new WeakMap(), Va = new WeakMap(), Sr = new WeakMap(), is = new WeakMap(), di = new WeakMap(), Bt = new WeakMap(), ui = new WeakMap(), nn = new WeakMap(), Wa = new WeakMap(), B = new WeakMap(), rn = new WeakMap(), ut = new WeakSet(), Gp = function(t) {
n(this, B).unselectAll();
const {
target: e
} = t;
if (e === n(this, Bt).div || (e.getAttribute("role") === "img" || e.classList.contains("endOfContent")) && n(this, Bt).div.contains(e)) {
const {
isMac: s
} = Wt.platform;
if (t.button !== 0 || t.ctrlKey && s)
return;
n(this, B).showAllEditors("highlight", !0, !0), n(this, Bt).div.classList.add("free"), this.toggleDrawing(), Wh.startHighlighting(this, n(this, B).direction === "ltr", {
target: n(this, Bt).div,
x: t.x,
y: t.y
}), n(this, Bt).div.addEventListener("pointerup", () => {
n(this, Bt).div.classList.remove("free"), this.toggleDrawing(!0);
}, {
once: !0,
signal: n(this, B)._signal
}), t.preventDefault();
}
}, cs = function() {
return n(We, rn).get(n(this, B).getMode());
}, Ud = function(t) {
const e = n(this, ut, cs);
return e ? new e.prototype.constructor(t) : null;
}, jd = function() {
const {
x: t,
y: e,
width: s,
height: i
} = this.div.getBoundingClientRect(), r = Math.max(0, t), a = Math.max(0, e), o = Math.min(window.innerWidth, t + s), l = Math.min(window.innerHeight, e + i), h = (r + o) / 2 - t, c = (a + l) / 2 - e, [u, p] = this.viewport.rotation % 180 === 0 ? [h, c] : [c, h];
return {
offsetX: u,
offsetY: p
};
}, Bh = function() {
for (const t of n(this, Ie).values())
t.isEmpty() && t.remove();
}, R(We, "_initialized", !1), m(We, rn, new Map([wd, Ld, $d, Wh, Hd].map((t) => [t._editorType, t])));
let zd = We;
var ns, ne, Er, Xl, uc, zp, Ps, Wd, Up, qd;
const Tt = class Tt {
constructor({
pageIndex: t
}) {
m(this, Ps);
m(this, ns, null);
m(this, ne, /* @__PURE__ */ new Map());
m(this, Er, /* @__PURE__ */ new Map());
this.pageIndex = t;
}
setParent(t) {
if (!n(this, ns)) {
f(this, ns, t);
return;
}
if (n(this, ns) !== t) {
if (n(this, ne).size > 0)
for (const e of n(this, ne).values())
e.remove(), t.append(e);
f(this, ns, t);
}
}
static get _svgFactory() {
return X(this, "_svgFactory", new Uh());
}
draw(t, e = !1, s = !1) {
const i = Zt(Tt, Xl)._++, r = b(this, Ps, Wd).call(this), a = Tt._svgFactory.createElement("defs");
r.append(a);
const o = Tt._svgFactory.createElement("path");
a.append(o);
const l = `path_p${this.pageIndex}_${i}`;
o.setAttribute("id", l), o.setAttribute("vector-effect", "non-scaling-stroke"), e && n(this, Er).set(i, o);
const h = s ? b(this, Ps, Up).call(this, a, l) : null, c = Tt._svgFactory.createElement("use");
return r.append(c), c.setAttribute("href", `#${l}`), this.updateProperties(r, t), n(this, ne).set(i, r), {
id: i,
clipPathId: `url(#${h})`
};
}
drawOutline(t, e) {
const s = Zt(Tt, Xl)._++, i = b(this, Ps, Wd).call(this), r = Tt._svgFactory.createElement("defs");
i.append(r);
const a = Tt._svgFactory.createElement("path");
r.append(a);
const o = `path_p${this.pageIndex}_${s}`;
a.setAttribute("id", o), a.setAttribute("vector-effect", "non-scaling-stroke");
let l;
if (e) {
const u = Tt._svgFactory.createElement("mask");
r.append(u), l = `mask_p${this.pageIndex}_${s}`, u.setAttribute("id", l), u.setAttribute("maskUnits", "objectBoundingBox");
const p = Tt._svgFactory.createElement("rect");
u.append(p), p.setAttribute("width", "1"), p.setAttribute("height", "1"), p.setAttribute("fill", "white");
const g = Tt._svgFactory.createElement("use");
u.append(g), g.setAttribute("href", `#${o}`), g.setAttribute("stroke", "none"), g.setAttribute("fill", "black"), g.setAttribute("fill-rule", "nonzero"), g.classList.add("mask");
}
const h = Tt._svgFactory.createElement("use");
i.append(h), h.setAttribute("href", `#${o}`), l && h.setAttribute("mask", `url(#${l})`);
const c = h.cloneNode();
return i.append(c), h.classList.add("mainOutline"), c.classList.add("secondaryOutline"), this.updateProperties(i, t), n(this, ne).set(s, i), s;
}
finalizeDraw(t, e) {
n(this, Er).delete(t), this.updateProperties(t, e);
}
updateProperties(t, e) {
var l;
if (!e)
return;
const {
root: s,
bbox: i,
rootClass: r,
path: a
} = e, o = typeof t == "number" ? n(this, ne).get(t) : t;
if (o) {
if (s && b(this, Ps, qd).call(this, o, s), i && b(l = Tt, uc, zp).call(l, o, i), r) {
const {
classList: h
} = o;
for (const [c, u] of Object.entries(r))
h.toggle(c, u);
}
if (a) {
const c = o.firstChild.firstChild;
b(this, Ps, qd).call(this, c, a);
}
}
}
updateParent(t, e) {
if (e === this)
return;
const s = n(this, ne).get(t);
s && (n(e, ns).append(s), n(this, ne).delete(t), n(e, ne).set(t, s));
}
remove(t) {
n(this, Er).delete(t), n(this, ns) !== null && (n(this, ne).get(t).remove(), n(this, ne).delete(t));
}
destroy() {
f(this, ns, null);
for (const t of n(this, ne).values())
t.remove();
n(this, ne).clear(), n(this, Er).clear();
}
};
ns = new WeakMap(), ne = new WeakMap(), Er = new WeakMap(), Xl = new WeakMap(), uc = new WeakSet(), zp = function(t, [e, s, i, r]) {
const {
style: a
} = t;
a.top = `${100 * s}%`, a.left = `${100 * e}%`, a.width = `${100 * i}%`, a.height = `${100 * r}%`;
}, Ps = new WeakSet(), Wd = function() {
const t = Tt._svgFactory.create(1, 1, !0);
return n(this, ns).append(t), t.setAttribute("aria-hidden", !0), t;
}, Up = function(t, e) {
const s = Tt._svgFactory.createElement("clipPath");
t.append(s);
const i = `clip_${e}`;
s.setAttribute("id", i), s.setAttribute("clipPathUnits", "objectBoundingBox");
const r = Tt._svgFactory.createElement("use");
return s.append(r), r.setAttribute("href", `#${e}`), r.classList.add("clip"), i;
}, qd = function(t, e) {
for (const [s, i] of Object.entries(e))
i === null ? t.removeAttribute(s) : t.setAttribute(s, i);
}, m(Tt, uc), m(Tt, Xl, 0);
let Vd = Tt;
globalThis._pdfjsTestingUtils = {
HighlightOutliner: _d
};
globalThis.pdfjsLib = {
AbortException: an,
AnnotationEditorLayer: zd,
AnnotationEditorParamsType: Y,
AnnotationEditorType: z,
AnnotationEditorUIManager: xr,
AnnotationLayer: bd,
AnnotationMode: vi,
AnnotationType: _t,
build: bm,
ColorPicker: Vh,
createValidAbsoluteUrl: Fu,
DOMSVGFactory: Uh,
DrawLayer: Vd,
FeatureTest: Wt,
fetchData: Kl,
getDocument: dm,
getFilenameFromUrl: lg,
getPdfFilenameFromUrl: hg,
getUuid: Bu,
getXfaPageViewport: dg,
GlobalWorkerOptions: fi,
ImageKind: lh,
InvalidPDFException: Mc,
isDataScheme: mc,
isPdfFile: Kd,
isValidExplicitDest: _g,
MathClamp: ae,
noContextMenu: as,
normalizeUnicode: rg,
OPS: Hh,
OutputScale: Rs,
PasswordResponses: Kp,
PDFDataRangeTransport: $f,
PDFDateString: Qd,
PDFWorker: wo,
PermissionFlag: Yp,
PixelsPerInch: on,
RenderingCancelledException: Yd,
ResponseException: $h,
setLayerDimensions: Cr,
shadow: X,
SignatureExtractor: pi,
stopEvent: St,
SupportedImageMimeTypes: Lc,
TextLayer: Ao,
TouchManager: zh,
updateUrlHash: Nu,
Util: $,
VerbosityLevel: fc,
version: mm,
XfaLayer: Uf
};
export {
an as AbortException,
zd as AnnotationEditorLayer,
Y as AnnotationEditorParamsType,
z as AnnotationEditorType,
xr as AnnotationEditorUIManager,
bd as AnnotationLayer,
vi as AnnotationMode,
_t as AnnotationType,
Vh as ColorPicker,
Uh as DOMSVGFactory,
Vd as DrawLayer,
Wt as FeatureTest,
fi as GlobalWorkerOptions,
lh as ImageKind,
Mc as InvalidPDFException,
ae as MathClamp,
Hh as OPS,
Rs as OutputScale,
$f as PDFDataRangeTransport,
Qd as PDFDateString,
wo as PDFWorker,
Kp as PasswordResponses,
Yp as PermissionFlag,
on as PixelsPerInch,
Yd as RenderingCancelledException,
$h as ResponseException,
pi as SignatureExtractor,
Lc as SupportedImageMimeTypes,
Ao as TextLayer,
zh as TouchManager,
$ as Util,
fc as VerbosityLevel,
Uf as XfaLayer,
bm as build,
Fu as createValidAbsoluteUrl,
Kl as fetchData,
dm as getDocument,
lg as getFilenameFromUrl,
hg as getPdfFilenameFromUrl,
Bu as getUuid,
dg as getXfaPageViewport,
mc as isDataScheme,
Kd as isPdfFile,
_g as isValidExplicitDest,
as as noContextMenu,
rg as normalizeUnicode,
Cr as setLayerDimensions,
X as shadow,
St as stopEvent,
Nu as updateUrlHash,
mm as version
};
//# sourceMappingURL=pdf-BappGl9h.js.map