@chialab/pdfjs-lib 1.0.0-alpha.20 → 1.0.0-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,43 +1,3 @@
1
- import {
2
- ColorConverters,
3
- MessageHandler,
4
- MurmurHash3_64,
5
- convertBlackAndWhiteToRGBA,
6
- wrapReason
7
- } from "./chunk-5IWODJWD.js";
8
- import {
9
- DOMCanvasFactory,
10
- DOMFilterFactory,
11
- OutputScale,
12
- PDFDateString,
13
- PageViewport,
14
- PixelsPerInch,
15
- RenderingCancelledException,
16
- SVG_NS,
17
- StatTimer,
18
- SupportedImageMimeTypes,
19
- canvasToData,
20
- colorToRgb,
21
- deprecated,
22
- fetchData,
23
- getColorValues,
24
- getCurrentTransform,
25
- getCurrentTransformInverse,
26
- getFilenameFromUrl,
27
- getPdfFilenameFromUrl,
28
- getRGB,
29
- getXfaPageViewport,
30
- isDataScheme,
31
- isPdfFile,
32
- isValidFetchUrl,
33
- makeSerializable,
34
- noContextMenu,
35
- parseRgbaColor,
36
- rgbToHex,
37
- setLayerDimensions,
38
- stopEvent,
39
- toDataUrl
40
- } from "./chunk-ELOUEWKT.js";
41
1
  import {
42
2
  AbortException,
43
3
  AnnotationBorderStyleType,
@@ -47,6 +7,8 @@ import {
47
7
  AnnotationMode,
48
8
  AnnotationPrefix,
49
9
  AnnotationType,
10
+ BaseException,
11
+ ColorConverters,
50
12
  DrawOPS,
51
13
  FONT_IDENTITY_MATRIX,
52
14
  FeatureTest,
@@ -55,6 +17,8 @@ import {
55
17
  InvalidPDFException,
56
18
  LINE_FACTOR,
57
19
  MathClamp,
20
+ MessageHandler,
21
+ MurmurHash3_64,
58
22
  OPS,
59
23
  PasswordResponses,
60
24
  PermissionFlag,
@@ -65,6 +29,7 @@ import {
65
29
  VerbosityLevel,
66
30
  _isValidExplicitDest,
67
31
  assert,
32
+ convertBlackAndWhiteToRGBA,
68
33
  createValidAbsoluteUrl,
69
34
  fromBase64Util,
70
35
  getUuid,
@@ -79,8 +44,16 @@ import {
79
44
  toBase64Util,
80
45
  unreachable,
81
46
  updateUrlHash,
82
- warn
83
- } from "./chunk-NJUB3B5A.js";
47
+ warn,
48
+ wrapReason
49
+ } from "./chunk-W3YEFTNG.js";
50
+ import {
51
+ NodeCMapReaderFactory,
52
+ NodeCanvasFactory,
53
+ NodeFilterFactory,
54
+ NodeStandardFontDataFactory,
55
+ NodeWasmFactory
56
+ } from "./chunk-3ZTAZS2X.js";
84
57
  import {
85
58
  __privateAdd,
86
59
  __privateGet,
@@ -90,6 +63,569 @@ import {
90
63
  __publicField
91
64
  } from "./chunk-O4UKW7AD.js";
92
65
 
66
+ // src/pdf.js/src/display/display_utils.js
67
+ var SVG_NS = "http://www.w3.org/2000/svg";
68
+ var _PixelsPerInch = class _PixelsPerInch {
69
+ };
70
+ __publicField(_PixelsPerInch, "CSS", 96);
71
+ __publicField(_PixelsPerInch, "PDF", 72);
72
+ __publicField(_PixelsPerInch, "PDF_TO_CSS_UNITS", _PixelsPerInch.CSS / _PixelsPerInch.PDF);
73
+ var PixelsPerInch = _PixelsPerInch;
74
+ async function fetchData(url, type = "text") {
75
+ if (isValidFetchUrl(url, document.baseURI)) {
76
+ const response = await fetch(url);
77
+ if (!response.ok) {
78
+ throw new Error(response.statusText);
79
+ }
80
+ switch (type) {
81
+ case "arraybuffer":
82
+ return response.arrayBuffer();
83
+ case "blob":
84
+ return response.blob();
85
+ case "json":
86
+ return response.json();
87
+ }
88
+ return response.text();
89
+ }
90
+ return new Promise((resolve, reject) => {
91
+ const request = new XMLHttpRequest();
92
+ request.open(
93
+ "GET",
94
+ url,
95
+ /* async = */
96
+ true
97
+ );
98
+ request.responseType = type;
99
+ request.onreadystatechange = () => {
100
+ if (request.readyState !== XMLHttpRequest.DONE) {
101
+ return;
102
+ }
103
+ if (request.status === 200 || request.status === 0) {
104
+ switch (type) {
105
+ case "arraybuffer":
106
+ case "blob":
107
+ case "json":
108
+ resolve(request.response);
109
+ return;
110
+ }
111
+ resolve(request.responseText);
112
+ return;
113
+ }
114
+ reject(new Error(request.statusText));
115
+ };
116
+ request.send(null);
117
+ });
118
+ }
119
+ var PageViewport = class _PageViewport {
120
+ /**
121
+ * @param {PageViewportParameters}
122
+ */
123
+ constructor({
124
+ viewBox,
125
+ userUnit,
126
+ scale,
127
+ rotation,
128
+ offsetX = 0,
129
+ offsetY = 0,
130
+ dontFlip = false
131
+ }) {
132
+ this.viewBox = viewBox;
133
+ this.userUnit = userUnit;
134
+ this.scale = scale;
135
+ this.rotation = rotation;
136
+ this.offsetX = offsetX;
137
+ this.offsetY = offsetY;
138
+ scale *= userUnit;
139
+ const centerX = (viewBox[2] + viewBox[0]) / 2;
140
+ const centerY = (viewBox[3] + viewBox[1]) / 2;
141
+ let rotateA, rotateB, rotateC, rotateD;
142
+ rotation %= 360;
143
+ if (rotation < 0) {
144
+ rotation += 360;
145
+ }
146
+ switch (rotation) {
147
+ case 180:
148
+ rotateA = -1;
149
+ rotateB = 0;
150
+ rotateC = 0;
151
+ rotateD = 1;
152
+ break;
153
+ case 90:
154
+ rotateA = 0;
155
+ rotateB = 1;
156
+ rotateC = 1;
157
+ rotateD = 0;
158
+ break;
159
+ case 270:
160
+ rotateA = 0;
161
+ rotateB = -1;
162
+ rotateC = -1;
163
+ rotateD = 0;
164
+ break;
165
+ case 0:
166
+ rotateA = 1;
167
+ rotateB = 0;
168
+ rotateC = 0;
169
+ rotateD = -1;
170
+ break;
171
+ default:
172
+ throw new Error(
173
+ "PageViewport: Invalid rotation, must be a multiple of 90 degrees."
174
+ );
175
+ }
176
+ if (dontFlip) {
177
+ rotateC = -rotateC;
178
+ rotateD = -rotateD;
179
+ }
180
+ let offsetCanvasX, offsetCanvasY;
181
+ let width, height;
182
+ if (rotateA === 0) {
183
+ offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
184
+ offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
185
+ width = (viewBox[3] - viewBox[1]) * scale;
186
+ height = (viewBox[2] - viewBox[0]) * scale;
187
+ } else {
188
+ offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
189
+ offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
190
+ width = (viewBox[2] - viewBox[0]) * scale;
191
+ height = (viewBox[3] - viewBox[1]) * scale;
192
+ }
193
+ this.transform = [
194
+ rotateA * scale,
195
+ rotateB * scale,
196
+ rotateC * scale,
197
+ rotateD * scale,
198
+ offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
199
+ offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
200
+ ];
201
+ this.width = width;
202
+ this.height = height;
203
+ }
204
+ /**
205
+ * The original, un-scaled, viewport dimensions.
206
+ * @type {Object}
207
+ */
208
+ get rawDims() {
209
+ const dims = this.viewBox;
210
+ return shadow(this, "rawDims", {
211
+ pageWidth: dims[2] - dims[0],
212
+ pageHeight: dims[3] - dims[1],
213
+ pageX: dims[0],
214
+ pageY: dims[1]
215
+ });
216
+ }
217
+ /**
218
+ * Clones viewport, with optional additional properties.
219
+ * @param {PageViewportCloneParameters} [params]
220
+ * @returns {PageViewport} Cloned viewport.
221
+ */
222
+ clone({
223
+ scale = this.scale,
224
+ rotation = this.rotation,
225
+ offsetX = this.offsetX,
226
+ offsetY = this.offsetY,
227
+ dontFlip = false
228
+ } = {}) {
229
+ return new _PageViewport({
230
+ viewBox: this.viewBox.slice(),
231
+ userUnit: this.userUnit,
232
+ scale,
233
+ rotation,
234
+ offsetX,
235
+ offsetY,
236
+ dontFlip
237
+ });
238
+ }
239
+ /**
240
+ * Converts PDF point to the viewport coordinates. For examples, useful for
241
+ * converting PDF location into canvas pixel coordinates.
242
+ * @param {number} x - The x-coordinate.
243
+ * @param {number} y - The y-coordinate.
244
+ * @returns {Array} Array containing `x`- and `y`-coordinates of the
245
+ * point in the viewport coordinate space.
246
+ * @see {@link convertToPdfPoint}
247
+ * @see {@link convertToViewportRectangle}
248
+ */
249
+ convertToViewportPoint(x, y) {
250
+ const p = [x, y];
251
+ Util.applyTransform(p, this.transform);
252
+ return p;
253
+ }
254
+ /**
255
+ * Converts PDF rectangle to the viewport coordinates.
256
+ * @param {Array} rect - The xMin, yMin, xMax and yMax coordinates.
257
+ * @returns {Array} Array containing corresponding coordinates of the
258
+ * rectangle in the viewport coordinate space.
259
+ * @see {@link convertToViewportPoint}
260
+ */
261
+ convertToViewportRectangle(rect) {
262
+ const topLeft = [rect[0], rect[1]];
263
+ Util.applyTransform(topLeft, this.transform);
264
+ const bottomRight = [rect[2], rect[3]];
265
+ Util.applyTransform(bottomRight, this.transform);
266
+ return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
267
+ }
268
+ /**
269
+ * Converts viewport coordinates to the PDF location. For examples, useful
270
+ * for converting canvas pixel location into PDF one.
271
+ * @param {number} x - The x-coordinate.
272
+ * @param {number} y - The y-coordinate.
273
+ * @returns {Array} Array containing `x`- and `y`-coordinates of the
274
+ * point in the PDF coordinate space.
275
+ * @see {@link convertToViewportPoint}
276
+ */
277
+ convertToPdfPoint(x, y) {
278
+ const p = [x, y];
279
+ Util.applyInverseTransform(p, this.transform);
280
+ return p;
281
+ }
282
+ };
283
+ var RenderingCancelledException = class extends BaseException {
284
+ constructor(msg, extraDelay = 0) {
285
+ super(msg, "RenderingCancelledException");
286
+ this.extraDelay = extraDelay;
287
+ }
288
+ };
289
+ function isDataScheme(url) {
290
+ const ii = url.length;
291
+ let i = 0;
292
+ while (i < ii && url[i].trim() === "") {
293
+ i++;
294
+ }
295
+ return url.substring(i, i + 5).toLowerCase() === "data:";
296
+ }
297
+ function isPdfFile(filename) {
298
+ return typeof filename === "string" && /\.pdf$/i.test(filename);
299
+ }
300
+ function getFilenameFromUrl(url) {
301
+ [url] = url.split(/[#?]/, 1);
302
+ return url.substring(url.lastIndexOf("/") + 1);
303
+ }
304
+ function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
305
+ if (typeof url !== "string") {
306
+ return defaultFilename;
307
+ }
308
+ if (isDataScheme(url)) {
309
+ warn('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
310
+ return defaultFilename;
311
+ }
312
+ const getURL = (urlString) => {
313
+ try {
314
+ return new URL(urlString);
315
+ } catch {
316
+ try {
317
+ return new URL(decodeURIComponent(urlString));
318
+ } catch {
319
+ try {
320
+ return new URL(urlString, "https://foo.bar");
321
+ } catch {
322
+ try {
323
+ return new URL(decodeURIComponent(urlString), "https://foo.bar");
324
+ } catch {
325
+ return null;
326
+ }
327
+ }
328
+ }
329
+ }
330
+ };
331
+ const newURL = getURL(url);
332
+ if (!newURL) {
333
+ return defaultFilename;
334
+ }
335
+ const decode = (name) => {
336
+ try {
337
+ let decoded = decodeURIComponent(name);
338
+ if (decoded.includes("/")) {
339
+ decoded = decoded.split("/").at(-1);
340
+ if (decoded.test(/^\.pdf$/i)) {
341
+ return decoded;
342
+ }
343
+ return name;
344
+ }
345
+ return decoded;
346
+ } catch {
347
+ return name;
348
+ }
349
+ };
350
+ const pdfRegex = /\.pdf$/i;
351
+ const filename = newURL.pathname.split("/").at(-1);
352
+ if (pdfRegex.test(filename)) {
353
+ return decode(filename);
354
+ }
355
+ if (newURL.searchParams.size > 0) {
356
+ const values = Array.from(newURL.searchParams.values()).reverse();
357
+ for (const value of values) {
358
+ if (pdfRegex.test(value)) {
359
+ return decode(value);
360
+ }
361
+ }
362
+ const keys = Array.from(newURL.searchParams.keys()).reverse();
363
+ for (const key of keys) {
364
+ if (pdfRegex.test(key)) {
365
+ return decode(key);
366
+ }
367
+ }
368
+ }
369
+ if (newURL.hash) {
370
+ const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
371
+ const hashFilename = reFilename.exec(newURL.hash);
372
+ if (hashFilename) {
373
+ return decode(hashFilename[0]);
374
+ }
375
+ }
376
+ return defaultFilename;
377
+ }
378
+ var StatTimer = class {
379
+ constructor() {
380
+ __publicField(this, "started", /* @__PURE__ */ Object.create(null));
381
+ __publicField(this, "times", []);
382
+ }
383
+ time(name) {
384
+ if (name in this.started) {
385
+ warn(`Timer is already running for ${name}`);
386
+ }
387
+ this.started[name] = Date.now();
388
+ }
389
+ timeEnd(name) {
390
+ if (!(name in this.started)) {
391
+ warn(`Timer has not been started for ${name}`);
392
+ }
393
+ this.times.push({
394
+ name,
395
+ start: this.started[name],
396
+ end: Date.now()
397
+ });
398
+ delete this.started[name];
399
+ }
400
+ toString() {
401
+ const outBuf = [];
402
+ let longest = 0;
403
+ for (const { name } of this.times) {
404
+ longest = Math.max(name.length, longest);
405
+ }
406
+ for (const { name, start, end } of this.times) {
407
+ outBuf.push(`${name.padEnd(longest)} ${end - start}ms
408
+ `);
409
+ }
410
+ return outBuf.join("");
411
+ }
412
+ };
413
+ function isValidFetchUrl(url, baseUrl) {
414
+ if (false) {
415
+ throw new Error("Not implemented: isValidFetchUrl");
416
+ }
417
+ const res = baseUrl ? URL.parse(url, baseUrl) : URL.parse(url);
418
+ return res?.protocol === "http:" || res?.protocol === "https:";
419
+ }
420
+ function noContextMenu(e) {
421
+ e.preventDefault();
422
+ }
423
+ function stopEvent(e) {
424
+ e.preventDefault();
425
+ e.stopPropagation();
426
+ }
427
+ function deprecated(details) {
428
+ console.log("Deprecated API usage: " + details);
429
+ }
430
+ var _regex;
431
+ var PDFDateString = class {
432
+ /**
433
+ * Convert a PDF date string to a JavaScript `Date` object.
434
+ *
435
+ * The PDF date string format is described in section 7.9.4 of the official
436
+ * PDF 32000-1:2008 specification. However, in the PDF 1.7 reference (sixth
437
+ * edition) Adobe describes the same format including a trailing apostrophe.
438
+ * This syntax in incorrect, but Adobe Acrobat creates PDF files that contain
439
+ * them. We ignore all apostrophes as they are not necessary for date parsing.
440
+ *
441
+ * Moreover, Adobe Acrobat doesn't handle changing the date to universal time
442
+ * and doesn't use the user's time zone (effectively ignoring the HH' and mm'
443
+ * parts of the date string).
444
+ *
445
+ * @param {string} input
446
+ * @returns {Date|null}
447
+ */
448
+ static toDateObject(input) {
449
+ if (!input || typeof input !== "string") {
450
+ return null;
451
+ }
452
+ __privateGet(this, _regex) || __privateSet(this, _regex, new RegExp(
453
+ "^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"
454
+ // Trailing apostrophe (optional)
455
+ ));
456
+ const matches = __privateGet(this, _regex).exec(input);
457
+ if (!matches) {
458
+ return null;
459
+ }
460
+ const year = parseInt(matches[1], 10);
461
+ let month = parseInt(matches[2], 10);
462
+ month = month >= 1 && month <= 12 ? month - 1 : 0;
463
+ let day = parseInt(matches[3], 10);
464
+ day = day >= 1 && day <= 31 ? day : 1;
465
+ let hour = parseInt(matches[4], 10);
466
+ hour = hour >= 0 && hour <= 23 ? hour : 0;
467
+ let minute = parseInt(matches[5], 10);
468
+ minute = minute >= 0 && minute <= 59 ? minute : 0;
469
+ let second = parseInt(matches[6], 10);
470
+ second = second >= 0 && second <= 59 ? second : 0;
471
+ const universalTimeRelation = matches[7] || "Z";
472
+ let offsetHour = parseInt(matches[8], 10);
473
+ offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
474
+ let offsetMinute = parseInt(matches[9], 10) || 0;
475
+ offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
476
+ if (universalTimeRelation === "-") {
477
+ hour += offsetHour;
478
+ minute += offsetMinute;
479
+ } else if (universalTimeRelation === "+") {
480
+ hour -= offsetHour;
481
+ minute -= offsetMinute;
482
+ }
483
+ return new Date(Date.UTC(year, month, day, hour, minute, second));
484
+ }
485
+ };
486
+ _regex = new WeakMap();
487
+ __privateAdd(PDFDateString, _regex);
488
+ function getXfaPageViewport(xfaPage, { scale = 1, rotation = 0 }) {
489
+ const { width, height } = xfaPage.attributes.style;
490
+ const viewBox = [0, 0, parseInt(width), parseInt(height)];
491
+ return new PageViewport({
492
+ viewBox,
493
+ userUnit: 1,
494
+ scale,
495
+ rotation
496
+ });
497
+ }
498
+ function getRGB(color) {
499
+ if (color.startsWith("#")) {
500
+ const colorRGB = parseInt(color.slice(1), 16);
501
+ return [
502
+ (colorRGB & 16711680) >> 16,
503
+ (colorRGB & 65280) >> 8,
504
+ colorRGB & 255
505
+ ];
506
+ }
507
+ if (color.startsWith("rgb(")) {
508
+ return color.slice(
509
+ /* "rgb(".length */
510
+ 4,
511
+ -1
512
+ ).split(",").map((x) => parseInt(x));
513
+ }
514
+ if (color.startsWith("rgba(")) {
515
+ return color.slice(
516
+ /* "rgba(".length */
517
+ 5,
518
+ -1
519
+ ).split(",").map((x) => parseInt(x)).slice(0, 3);
520
+ }
521
+ warn(`Not a valid color format: "${color}"`);
522
+ return [0, 0, 0];
523
+ }
524
+ function getColorValues(colors) {
525
+ const span = document.createElement("span");
526
+ span.style.visibility = "hidden";
527
+ span.style.colorScheme = "only light";
528
+ document.body.append(span);
529
+ for (const name of colors.keys()) {
530
+ span.style.color = name;
531
+ const computedColor = window.getComputedStyle(span).color;
532
+ colors.set(name, getRGB(computedColor));
533
+ }
534
+ span.remove();
535
+ }
536
+ function getCurrentTransform(ctx) {
537
+ const { a, b, c, d, e, f } = ctx.getTransform();
538
+ return [a, b, c, d, e, f];
539
+ }
540
+ function getCurrentTransformInverse(ctx) {
541
+ const { a, b, c, d, e, f } = ctx.getTransform().invertSelf();
542
+ return [a, b, c, d, e, f];
543
+ }
544
+ function setLayerDimensions(div, viewport, mustFlip = false, mustRotate = true) {
545
+ if (viewport instanceof PageViewport) {
546
+ const { pageWidth, pageHeight } = viewport.rawDims;
547
+ const { style } = div;
548
+ const useRound = FeatureTest.isCSSRoundSupported;
549
+ const w = `var(--total-scale-factor) * ${pageWidth}px`, h = `var(--total-scale-factor) * ${pageHeight}px`;
550
+ const widthStr = useRound ? `round(down, ${w}, var(--scale-round-x))` : `calc(${w})`, heightStr = useRound ? `round(down, ${h}, var(--scale-round-y))` : `calc(${h})`;
551
+ if (!mustFlip || viewport.rotation % 180 === 0) {
552
+ style.width = widthStr;
553
+ style.height = heightStr;
554
+ } else {
555
+ style.width = heightStr;
556
+ style.height = widthStr;
557
+ }
558
+ }
559
+ if (mustRotate) {
560
+ div.setAttribute("data-main-rotation", viewport.rotation);
561
+ }
562
+ }
563
+ var OutputScale = class _OutputScale {
564
+ constructor() {
565
+ const { pixelRatio } = _OutputScale;
566
+ this.sx = pixelRatio;
567
+ this.sy = pixelRatio;
568
+ }
569
+ /**
570
+ * @type {boolean} Returns `true` when scaling is required, `false` otherwise.
571
+ */
572
+ get scaled() {
573
+ return this.sx !== 1 || this.sy !== 1;
574
+ }
575
+ /**
576
+ * @type {boolean} Returns `true` when scaling is symmetric,
577
+ * `false` otherwise.
578
+ */
579
+ get symmetric() {
580
+ return this.sx === this.sy;
581
+ }
582
+ /**
583
+ * @returns {boolean} Returns `true` if scaling was limited,
584
+ * `false` otherwise.
585
+ */
586
+ limitCanvas(width, height, maxPixels, maxDim, capAreaFactor = -1) {
587
+ let maxAreaScale = Infinity, maxWidthScale = Infinity, maxHeightScale = Infinity;
588
+ maxPixels = _OutputScale.capPixels(maxPixels, capAreaFactor);
589
+ if (maxPixels > 0) {
590
+ maxAreaScale = Math.sqrt(maxPixels / (width * height));
591
+ }
592
+ if (maxDim !== -1) {
593
+ maxWidthScale = maxDim / width;
594
+ maxHeightScale = maxDim / height;
595
+ }
596
+ const maxScale = Math.min(maxAreaScale, maxWidthScale, maxHeightScale);
597
+ if (this.sx > maxScale || this.sy > maxScale) {
598
+ this.sx = maxScale;
599
+ this.sy = maxScale;
600
+ return true;
601
+ }
602
+ return false;
603
+ }
604
+ static get pixelRatio() {
605
+ return globalThis.devicePixelRatio || 1;
606
+ }
607
+ static capPixels(maxPixels, capAreaFactor) {
608
+ if (capAreaFactor >= 0) {
609
+ const winPixels = Math.ceil(
610
+ (false ? window.innerWidth * window.innerHeight : window.screen.availWidth * window.screen.availHeight) * this.pixelRatio ** 2 * (1 + capAreaFactor / 100)
611
+ );
612
+ return maxPixels > 0 ? Math.min(maxPixels, winPixels) : winPixels;
613
+ }
614
+ return maxPixels;
615
+ }
616
+ };
617
+ var SupportedImageMimeTypes = [
618
+ "image/apng",
619
+ "image/avif",
620
+ "image/bmp",
621
+ "image/gif",
622
+ "image/jpeg",
623
+ "image/png",
624
+ "image/svg+xml",
625
+ "image/webp",
626
+ "image/x-icon"
627
+ ];
628
+
93
629
  // src/pdf.js/src/display/editor/toolbar.js
94
630
  var _toolbar, _colorPicker, _editor, _buttons, _altText, _signatureDescriptionButton, _l10nRemove, _EditorToolbar_static, pointerDown_fn, _EditorToolbar_instances, focusIn_fn, focusOut_fn, addListenersToElement_fn, divider_get;
95
631
  var _EditorToolbar = class _EditorToolbar {
@@ -5790,18 +6326,6 @@ var LoopbackPort = class {
5790
6326
  _listeners = new WeakMap();
5791
6327
  _deferred = new WeakMap();
5792
6328
 
5793
- // src/lib/NodeUtilsStabs.ts
5794
- var NodeCanvasFactory = class {
5795
- };
5796
- var NodeCMapReaderFactory = class {
5797
- };
5798
- var NodeStandardFontDataFactory = class {
5799
- };
5800
- var NodeFilterFactory = class {
5801
- };
5802
- var NodeWasmFactory = class {
5803
- };
5804
-
5805
6329
  // src/pdf.js/src/display/pattern_helper.js
5806
6330
  var PathType = {
5807
6331
  FILL: "Fill",
@@ -8702,6 +9226,71 @@ for (const op in OPS) {
8702
9226
  }
8703
9227
  }
8704
9228
 
9229
+ // src/pdf.js/src/display/canvas_factory.js
9230
+ var _enableHWA;
9231
+ var BaseCanvasFactory = class {
9232
+ constructor({ enableHWA = false }) {
9233
+ __privateAdd(this, _enableHWA, false);
9234
+ if (false) {
9235
+ unreachable("Cannot initialize BaseCanvasFactory.");
9236
+ }
9237
+ __privateSet(this, _enableHWA, enableHWA);
9238
+ }
9239
+ create(width, height) {
9240
+ if (width <= 0 || height <= 0) {
9241
+ throw new Error("Invalid canvas size");
9242
+ }
9243
+ const canvas = this._createCanvas(width, height);
9244
+ return {
9245
+ canvas,
9246
+ context: canvas.getContext("2d", {
9247
+ willReadFrequently: !__privateGet(this, _enableHWA)
9248
+ })
9249
+ };
9250
+ }
9251
+ reset(canvasAndContext, width, height) {
9252
+ if (!canvasAndContext.canvas) {
9253
+ throw new Error("Canvas is not specified");
9254
+ }
9255
+ if (width <= 0 || height <= 0) {
9256
+ throw new Error("Invalid canvas size");
9257
+ }
9258
+ canvasAndContext.canvas.width = width;
9259
+ canvasAndContext.canvas.height = height;
9260
+ }
9261
+ destroy(canvasAndContext) {
9262
+ if (!canvasAndContext.canvas) {
9263
+ throw new Error("Canvas is not specified");
9264
+ }
9265
+ canvasAndContext.canvas.width = 0;
9266
+ canvasAndContext.canvas.height = 0;
9267
+ canvasAndContext.canvas = null;
9268
+ canvasAndContext.context = null;
9269
+ }
9270
+ /**
9271
+ * @ignore
9272
+ */
9273
+ _createCanvas(width, height) {
9274
+ unreachable("Abstract method `_createCanvas` called.");
9275
+ }
9276
+ };
9277
+ _enableHWA = new WeakMap();
9278
+ var DOMCanvasFactory = class extends BaseCanvasFactory {
9279
+ constructor({ ownerDocument = globalThis.document, enableHWA = false }) {
9280
+ super({ enableHWA });
9281
+ this._document = ownerDocument;
9282
+ }
9283
+ /**
9284
+ * @ignore
9285
+ */
9286
+ _createCanvas(width, height) {
9287
+ const canvas = this._document.createElement("canvas");
9288
+ canvas.width = width;
9289
+ canvas.height = height;
9290
+ return canvas;
9291
+ }
9292
+ };
9293
+
8705
9294
  // src/pdf.js/src/display/cmap_reader_factory.js
8706
9295
  var BaseCMapReaderFactory = class {
8707
9296
  constructor({ baseUrl = null, isCompressed = true }) {
@@ -8749,6 +9338,380 @@ var DOMCMapReaderFactory = class extends BaseCMapReaderFactory {
8749
9338
  }
8750
9339
  };
8751
9340
 
9341
+ // src/pdf.js/src/display/filter_factory.js
9342
+ var BaseFilterFactory = class {
9343
+ constructor() {
9344
+ if (false) {
9345
+ unreachable("Cannot initialize BaseFilterFactory.");
9346
+ }
9347
+ }
9348
+ addFilter(maps) {
9349
+ return "none";
9350
+ }
9351
+ addHCMFilter(fgColor, bgColor) {
9352
+ return "none";
9353
+ }
9354
+ addAlphaFilter(map) {
9355
+ return "none";
9356
+ }
9357
+ addLuminosityFilter(map) {
9358
+ return "none";
9359
+ }
9360
+ addHighlightHCMFilter(filterName, fgColor, bgColor, newFgColor, newBgColor) {
9361
+ return "none";
9362
+ }
9363
+ destroy(keepHCM = false) {
9364
+ }
9365
+ };
9366
+ var _baseUrl, __cache, __defs, _docId, _document, __hcmCache, _id3, _DOMFilterFactory_instances, cache_get, hcmCache_get, defs_get, createTables_fn, createUrl_fn, addLuminosityConversion_fn, addGrayConversion_fn, createFilter_fn, appendFeFunc_fn, addTransferMapConversion_fn, addTransferMapAlphaConversion_fn, getRGB_fn;
9367
+ var DOMFilterFactory = class extends BaseFilterFactory {
9368
+ constructor({ docId, ownerDocument = globalThis.document }) {
9369
+ super();
9370
+ __privateAdd(this, _DOMFilterFactory_instances);
9371
+ __privateAdd(this, _baseUrl);
9372
+ __privateAdd(this, __cache);
9373
+ __privateAdd(this, __defs);
9374
+ __privateAdd(this, _docId);
9375
+ __privateAdd(this, _document);
9376
+ __privateAdd(this, __hcmCache);
9377
+ __privateAdd(this, _id3, 0);
9378
+ __privateSet(this, _docId, docId);
9379
+ __privateSet(this, _document, ownerDocument);
9380
+ }
9381
+ addFilter(maps) {
9382
+ if (!maps) {
9383
+ return "none";
9384
+ }
9385
+ let value = __privateGet(this, _DOMFilterFactory_instances, cache_get).get(maps);
9386
+ if (value) {
9387
+ return value;
9388
+ }
9389
+ const [tableR, tableG, tableB] = __privateMethod(this, _DOMFilterFactory_instances, createTables_fn).call(this, maps);
9390
+ const key = maps.length === 1 ? tableR : `${tableR}${tableG}${tableB}`;
9391
+ value = __privateGet(this, _DOMFilterFactory_instances, cache_get).get(key);
9392
+ if (value) {
9393
+ __privateGet(this, _DOMFilterFactory_instances, cache_get).set(maps, value);
9394
+ return value;
9395
+ }
9396
+ const id2 = `g_${__privateGet(this, _docId)}_transfer_map_${__privateWrapper(this, _id3)._++}`;
9397
+ const url = __privateMethod(this, _DOMFilterFactory_instances, createUrl_fn).call(this, id2);
9398
+ __privateGet(this, _DOMFilterFactory_instances, cache_get).set(maps, url);
9399
+ __privateGet(this, _DOMFilterFactory_instances, cache_get).set(key, url);
9400
+ const filter = __privateMethod(this, _DOMFilterFactory_instances, createFilter_fn).call(this, id2);
9401
+ __privateMethod(this, _DOMFilterFactory_instances, addTransferMapConversion_fn).call(this, tableR, tableG, tableB, filter);
9402
+ return url;
9403
+ }
9404
+ addHCMFilter(fgColor, bgColor) {
9405
+ const key = `${fgColor}-${bgColor}`;
9406
+ const filterName = "base";
9407
+ let info2 = __privateGet(this, _DOMFilterFactory_instances, hcmCache_get).get(filterName);
9408
+ if (info2?.key === key) {
9409
+ return info2.url;
9410
+ }
9411
+ if (info2) {
9412
+ info2.filter?.remove();
9413
+ info2.key = key;
9414
+ info2.url = "none";
9415
+ info2.filter = null;
9416
+ } else {
9417
+ info2 = {
9418
+ key,
9419
+ url: "none",
9420
+ filter: null
9421
+ };
9422
+ __privateGet(this, _DOMFilterFactory_instances, hcmCache_get).set(filterName, info2);
9423
+ }
9424
+ if (!fgColor || !bgColor) {
9425
+ return info2.url;
9426
+ }
9427
+ const fgRGB = __privateMethod(this, _DOMFilterFactory_instances, getRGB_fn).call(this, fgColor);
9428
+ fgColor = Util.makeHexColor(...fgRGB);
9429
+ const bgRGB = __privateMethod(this, _DOMFilterFactory_instances, getRGB_fn).call(this, bgColor);
9430
+ bgColor = Util.makeHexColor(...bgRGB);
9431
+ __privateGet(this, _DOMFilterFactory_instances, defs_get).style.color = "";
9432
+ if (fgColor === "#000000" && bgColor === "#ffffff" || fgColor === bgColor) {
9433
+ return info2.url;
9434
+ }
9435
+ const map = new Array(256);
9436
+ for (let i = 0; i <= 255; i++) {
9437
+ const x = i / 255;
9438
+ map[i] = x <= 0.03928 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
9439
+ }
9440
+ const table = map.join(",");
9441
+ const id2 = `g_${__privateGet(this, _docId)}_hcm_filter`;
9442
+ const filter = info2.filter = __privateMethod(this, _DOMFilterFactory_instances, createFilter_fn).call(this, id2);
9443
+ __privateMethod(this, _DOMFilterFactory_instances, addTransferMapConversion_fn).call(this, table, table, table, filter);
9444
+ __privateMethod(this, _DOMFilterFactory_instances, addGrayConversion_fn).call(this, filter);
9445
+ const getSteps = (c, n) => {
9446
+ const start = fgRGB[c] / 255;
9447
+ const end = bgRGB[c] / 255;
9448
+ const arr = new Array(n + 1);
9449
+ for (let i = 0; i <= n; i++) {
9450
+ arr[i] = start + i / n * (end - start);
9451
+ }
9452
+ return arr.join(",");
9453
+ };
9454
+ __privateMethod(this, _DOMFilterFactory_instances, addTransferMapConversion_fn).call(this, getSteps(0, 5), getSteps(1, 5), getSteps(2, 5), filter);
9455
+ info2.url = __privateMethod(this, _DOMFilterFactory_instances, createUrl_fn).call(this, id2);
9456
+ return info2.url;
9457
+ }
9458
+ addAlphaFilter(map) {
9459
+ let value = __privateGet(this, _DOMFilterFactory_instances, cache_get).get(map);
9460
+ if (value) {
9461
+ return value;
9462
+ }
9463
+ const [tableA] = __privateMethod(this, _DOMFilterFactory_instances, createTables_fn).call(this, [map]);
9464
+ const key = `alpha_${tableA}`;
9465
+ value = __privateGet(this, _DOMFilterFactory_instances, cache_get).get(key);
9466
+ if (value) {
9467
+ __privateGet(this, _DOMFilterFactory_instances, cache_get).set(map, value);
9468
+ return value;
9469
+ }
9470
+ const id2 = `g_${__privateGet(this, _docId)}_alpha_map_${__privateWrapper(this, _id3)._++}`;
9471
+ const url = __privateMethod(this, _DOMFilterFactory_instances, createUrl_fn).call(this, id2);
9472
+ __privateGet(this, _DOMFilterFactory_instances, cache_get).set(map, url);
9473
+ __privateGet(this, _DOMFilterFactory_instances, cache_get).set(key, url);
9474
+ const filter = __privateMethod(this, _DOMFilterFactory_instances, createFilter_fn).call(this, id2);
9475
+ __privateMethod(this, _DOMFilterFactory_instances, addTransferMapAlphaConversion_fn).call(this, tableA, filter);
9476
+ return url;
9477
+ }
9478
+ addLuminosityFilter(map) {
9479
+ let value = __privateGet(this, _DOMFilterFactory_instances, cache_get).get(map || "luminosity");
9480
+ if (value) {
9481
+ return value;
9482
+ }
9483
+ let tableA, key;
9484
+ if (map) {
9485
+ [tableA] = __privateMethod(this, _DOMFilterFactory_instances, createTables_fn).call(this, [map]);
9486
+ key = `luminosity_${tableA}`;
9487
+ } else {
9488
+ key = "luminosity";
9489
+ }
9490
+ value = __privateGet(this, _DOMFilterFactory_instances, cache_get).get(key);
9491
+ if (value) {
9492
+ __privateGet(this, _DOMFilterFactory_instances, cache_get).set(map, value);
9493
+ return value;
9494
+ }
9495
+ const id2 = `g_${__privateGet(this, _docId)}_luminosity_map_${__privateWrapper(this, _id3)._++}`;
9496
+ const url = __privateMethod(this, _DOMFilterFactory_instances, createUrl_fn).call(this, id2);
9497
+ __privateGet(this, _DOMFilterFactory_instances, cache_get).set(map, url);
9498
+ __privateGet(this, _DOMFilterFactory_instances, cache_get).set(key, url);
9499
+ const filter = __privateMethod(this, _DOMFilterFactory_instances, createFilter_fn).call(this, id2);
9500
+ __privateMethod(this, _DOMFilterFactory_instances, addLuminosityConversion_fn).call(this, filter);
9501
+ if (map) {
9502
+ __privateMethod(this, _DOMFilterFactory_instances, addTransferMapAlphaConversion_fn).call(this, tableA, filter);
9503
+ }
9504
+ return url;
9505
+ }
9506
+ addHighlightHCMFilter(filterName, fgColor, bgColor, newFgColor, newBgColor) {
9507
+ const key = `${fgColor}-${bgColor}-${newFgColor}-${newBgColor}`;
9508
+ let info2 = __privateGet(this, _DOMFilterFactory_instances, hcmCache_get).get(filterName);
9509
+ if (info2?.key === key) {
9510
+ return info2.url;
9511
+ }
9512
+ if (info2) {
9513
+ info2.filter?.remove();
9514
+ info2.key = key;
9515
+ info2.url = "none";
9516
+ info2.filter = null;
9517
+ } else {
9518
+ info2 = {
9519
+ key,
9520
+ url: "none",
9521
+ filter: null
9522
+ };
9523
+ __privateGet(this, _DOMFilterFactory_instances, hcmCache_get).set(filterName, info2);
9524
+ }
9525
+ if (!fgColor || !bgColor) {
9526
+ return info2.url;
9527
+ }
9528
+ const [fgRGB, bgRGB] = [fgColor, bgColor].map(__privateMethod(this, _DOMFilterFactory_instances, getRGB_fn).bind(this));
9529
+ let fgGray = Math.round(
9530
+ 0.2126 * fgRGB[0] + 0.7152 * fgRGB[1] + 0.0722 * fgRGB[2]
9531
+ );
9532
+ let bgGray = Math.round(
9533
+ 0.2126 * bgRGB[0] + 0.7152 * bgRGB[1] + 0.0722 * bgRGB[2]
9534
+ );
9535
+ let [newFgRGB, newBgRGB] = [newFgColor, newBgColor].map(
9536
+ __privateMethod(this, _DOMFilterFactory_instances, getRGB_fn).bind(this)
9537
+ );
9538
+ if (bgGray < fgGray) {
9539
+ [fgGray, bgGray, newFgRGB, newBgRGB] = [
9540
+ bgGray,
9541
+ fgGray,
9542
+ newBgRGB,
9543
+ newFgRGB
9544
+ ];
9545
+ }
9546
+ __privateGet(this, _DOMFilterFactory_instances, defs_get).style.color = "";
9547
+ const getSteps = (fg, bg, n) => {
9548
+ const arr = new Array(256);
9549
+ const step = (bgGray - fgGray) / n;
9550
+ const newStart = fg / 255;
9551
+ const newStep = (bg - fg) / (255 * n);
9552
+ let prev = 0;
9553
+ for (let i = 0; i <= n; i++) {
9554
+ const k = Math.round(fgGray + i * step);
9555
+ const value = newStart + i * newStep;
9556
+ for (let j = prev; j <= k; j++) {
9557
+ arr[j] = value;
9558
+ }
9559
+ prev = k + 1;
9560
+ }
9561
+ for (let i = prev; i < 256; i++) {
9562
+ arr[i] = arr[prev - 1];
9563
+ }
9564
+ return arr.join(",");
9565
+ };
9566
+ const id2 = `g_${__privateGet(this, _docId)}_hcm_${filterName}_filter`;
9567
+ const filter = info2.filter = __privateMethod(this, _DOMFilterFactory_instances, createFilter_fn).call(this, id2);
9568
+ __privateMethod(this, _DOMFilterFactory_instances, addGrayConversion_fn).call(this, filter);
9569
+ __privateMethod(this, _DOMFilterFactory_instances, addTransferMapConversion_fn).call(this, getSteps(newFgRGB[0], newBgRGB[0], 5), getSteps(newFgRGB[1], newBgRGB[1], 5), getSteps(newFgRGB[2], newBgRGB[2], 5), filter);
9570
+ info2.url = __privateMethod(this, _DOMFilterFactory_instances, createUrl_fn).call(this, id2);
9571
+ return info2.url;
9572
+ }
9573
+ destroy(keepHCM = false) {
9574
+ if (keepHCM && __privateGet(this, __hcmCache)?.size) {
9575
+ return;
9576
+ }
9577
+ __privateGet(this, __defs)?.parentNode.parentNode.remove();
9578
+ __privateSet(this, __defs, null);
9579
+ __privateGet(this, __cache)?.clear();
9580
+ __privateSet(this, __cache, null);
9581
+ __privateGet(this, __hcmCache)?.clear();
9582
+ __privateSet(this, __hcmCache, null);
9583
+ __privateSet(this, _id3, 0);
9584
+ }
9585
+ };
9586
+ _baseUrl = new WeakMap();
9587
+ __cache = new WeakMap();
9588
+ __defs = new WeakMap();
9589
+ _docId = new WeakMap();
9590
+ _document = new WeakMap();
9591
+ __hcmCache = new WeakMap();
9592
+ _id3 = new WeakMap();
9593
+ _DOMFilterFactory_instances = new WeakSet();
9594
+ cache_get = function() {
9595
+ return __privateGet(this, __cache) || __privateSet(this, __cache, /* @__PURE__ */ new Map());
9596
+ };
9597
+ hcmCache_get = function() {
9598
+ return __privateGet(this, __hcmCache) || __privateSet(this, __hcmCache, /* @__PURE__ */ new Map());
9599
+ };
9600
+ defs_get = function() {
9601
+ if (!__privateGet(this, __defs)) {
9602
+ const div = __privateGet(this, _document).createElement("div");
9603
+ const { style } = div;
9604
+ style.visibility = "hidden";
9605
+ style.contain = "strict";
9606
+ style.width = style.height = 0;
9607
+ style.position = "absolute";
9608
+ style.top = style.left = 0;
9609
+ style.zIndex = -1;
9610
+ const svg = __privateGet(this, _document).createElementNS(SVG_NS, "svg");
9611
+ svg.setAttribute("width", 0);
9612
+ svg.setAttribute("height", 0);
9613
+ __privateSet(this, __defs, __privateGet(this, _document).createElementNS(SVG_NS, "defs"));
9614
+ div.append(svg);
9615
+ svg.append(__privateGet(this, __defs));
9616
+ __privateGet(this, _document).body.append(div);
9617
+ }
9618
+ return __privateGet(this, __defs);
9619
+ };
9620
+ createTables_fn = function(maps) {
9621
+ if (maps.length === 1) {
9622
+ const mapR2 = maps[0];
9623
+ const buffer = new Array(256);
9624
+ for (let i = 0; i < 256; i++) {
9625
+ buffer[i] = mapR2[i] / 255;
9626
+ }
9627
+ const table = buffer.join(",");
9628
+ return [table, table, table];
9629
+ }
9630
+ const [mapR, mapG, mapB] = maps;
9631
+ const bufferR = new Array(256);
9632
+ const bufferG = new Array(256);
9633
+ const bufferB = new Array(256);
9634
+ for (let i = 0; i < 256; i++) {
9635
+ bufferR[i] = mapR[i] / 255;
9636
+ bufferG[i] = mapG[i] / 255;
9637
+ bufferB[i] = mapB[i] / 255;
9638
+ }
9639
+ return [bufferR.join(","), bufferG.join(","), bufferB.join(",")];
9640
+ };
9641
+ createUrl_fn = function(id2) {
9642
+ if (__privateGet(this, _baseUrl) === void 0) {
9643
+ __privateSet(this, _baseUrl, "");
9644
+ const url = __privateGet(this, _document).URL;
9645
+ if (url !== __privateGet(this, _document).baseURI) {
9646
+ if (isDataScheme(url)) {
9647
+ warn('#createUrl: ignore "data:"-URL for performance reasons.');
9648
+ } else {
9649
+ __privateSet(this, _baseUrl, updateUrlHash(url, ""));
9650
+ }
9651
+ }
9652
+ }
9653
+ return `url(${__privateGet(this, _baseUrl)}#${id2})`;
9654
+ };
9655
+ addLuminosityConversion_fn = function(filter) {
9656
+ const feColorMatrix = __privateGet(this, _document).createElementNS(
9657
+ SVG_NS,
9658
+ "feColorMatrix"
9659
+ );
9660
+ feColorMatrix.setAttribute("type", "matrix");
9661
+ feColorMatrix.setAttribute(
9662
+ "values",
9663
+ "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0"
9664
+ );
9665
+ filter.append(feColorMatrix);
9666
+ };
9667
+ addGrayConversion_fn = function(filter) {
9668
+ const feColorMatrix = __privateGet(this, _document).createElementNS(
9669
+ SVG_NS,
9670
+ "feColorMatrix"
9671
+ );
9672
+ feColorMatrix.setAttribute("type", "matrix");
9673
+ feColorMatrix.setAttribute(
9674
+ "values",
9675
+ "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"
9676
+ );
9677
+ filter.append(feColorMatrix);
9678
+ };
9679
+ createFilter_fn = function(id2) {
9680
+ const filter = __privateGet(this, _document).createElementNS(SVG_NS, "filter");
9681
+ filter.setAttribute("color-interpolation-filters", "sRGB");
9682
+ filter.setAttribute("id", id2);
9683
+ __privateGet(this, _DOMFilterFactory_instances, defs_get).append(filter);
9684
+ return filter;
9685
+ };
9686
+ appendFeFunc_fn = function(feComponentTransfer, func, table) {
9687
+ const feFunc = __privateGet(this, _document).createElementNS(SVG_NS, func);
9688
+ feFunc.setAttribute("type", "discrete");
9689
+ feFunc.setAttribute("tableValues", table);
9690
+ feComponentTransfer.append(feFunc);
9691
+ };
9692
+ addTransferMapConversion_fn = function(rTable, gTable, bTable, filter) {
9693
+ const feComponentTransfer = __privateGet(this, _document).createElementNS(
9694
+ SVG_NS,
9695
+ "feComponentTransfer"
9696
+ );
9697
+ filter.append(feComponentTransfer);
9698
+ __privateMethod(this, _DOMFilterFactory_instances, appendFeFunc_fn).call(this, feComponentTransfer, "feFuncR", rTable);
9699
+ __privateMethod(this, _DOMFilterFactory_instances, appendFeFunc_fn).call(this, feComponentTransfer, "feFuncG", gTable);
9700
+ __privateMethod(this, _DOMFilterFactory_instances, appendFeFunc_fn).call(this, feComponentTransfer, "feFuncB", bTable);
9701
+ };
9702
+ addTransferMapAlphaConversion_fn = function(aTable, filter) {
9703
+ const feComponentTransfer = __privateGet(this, _document).createElementNS(
9704
+ SVG_NS,
9705
+ "feComponentTransfer"
9706
+ );
9707
+ filter.append(feComponentTransfer);
9708
+ __privateMethod(this, _DOMFilterFactory_instances, appendFeFunc_fn).call(this, feComponentTransfer, "feFuncA", aTable);
9709
+ };
9710
+ getRGB_fn = function(color) {
9711
+ __privateGet(this, _DOMFilterFactory_instances, defs_get).style.color = color;
9712
+ return getRGB(getComputedStyle(__privateGet(this, _DOMFilterFactory_instances, defs_get)).getPropertyValue("color"));
9713
+ };
9714
+
8752
9715
  // src/pdf.js/src/display/standard_fontdata_factory.js
8753
9716
  var BaseStandardFontDataFactory = class {
8754
9717
  constructor({ baseUrl = null }) {
@@ -10947,7 +11910,7 @@ function getDocument(src = {}) {
10947
11910
  }).catch(task._capability.reject);
10948
11911
  return task;
10949
11912
  }
10950
- var _docId;
11913
+ var _docId2;
10951
11914
  var _PDFDocumentLoadingTask = class _PDFDocumentLoadingTask {
10952
11915
  constructor() {
10953
11916
  /**
@@ -10966,7 +11929,7 @@ var _PDFDocumentLoadingTask = class _PDFDocumentLoadingTask {
10966
11929
  * Unique identifier for the document loading task.
10967
11930
  * @type {string}
10968
11931
  */
10969
- __publicField(this, "docId", `d${__privateWrapper(_PDFDocumentLoadingTask, _docId)._++}`);
11932
+ __publicField(this, "docId", `d${__privateWrapper(_PDFDocumentLoadingTask, _docId2)._++}`);
10970
11933
  /**
10971
11934
  * Whether the loading task is destroyed or not.
10972
11935
  * @type {boolean}
@@ -11026,8 +11989,8 @@ var _PDFDocumentLoadingTask = class _PDFDocumentLoadingTask {
11026
11989
  return this._transport.getData();
11027
11990
  }
11028
11991
  };
11029
- _docId = new WeakMap();
11030
- __privateAdd(_PDFDocumentLoadingTask, _docId, 0);
11992
+ _docId2 = new WeakMap();
11993
+ __privateAdd(_PDFDocumentLoadingTask, _docId2, 0);
11031
11994
  var PDFDocumentLoadingTask = _PDFDocumentLoadingTask;
11032
11995
  var _capability2, _progressiveDoneListeners, _progressiveReadListeners, _progressListeners, _rangeListeners;
11033
11996
  var PDFDataRangeTransport = class {
@@ -18055,7 +19018,7 @@ __privateAdd(_ColorPicker, _l10nColor, null);
18055
19018
  var ColorPicker = _ColorPicker;
18056
19019
 
18057
19020
  // src/pdf.js/src/display/editor/highlight.js
18058
- var _anchorNode, _anchorOffset, _boxes, _clipPathId, _colorPicker2, _focusOutlines, _focusNode, _focusOffset, _highlightDiv, _highlightOutlines, _id3, _isFreeHighlight, _lastPoint2, _opacity, _outlineId, _text, _thickness2, _methodOfCreation, _HighlightEditor_instances, createOutlines_fn, createFreeOutlines_fn, updateColor_fn2, updateThickness_fn, changeThickness_fn, cleanDrawLayer_fn, addToDrawLayer_fn, _HighlightEditor_static, rotateBbox_fn, keydown_fn, setCaret_fn, getRotation_fn, serializeBoxes_fn, serializeOutlines_fn, highlightMove_fn, endHighlight_fn, hasElementChanged_fn2;
19021
+ var _anchorNode, _anchorOffset, _boxes, _clipPathId, _colorPicker2, _focusOutlines, _focusNode, _focusOffset, _highlightDiv, _highlightOutlines, _id4, _isFreeHighlight, _lastPoint2, _opacity, _outlineId, _text, _thickness2, _methodOfCreation, _HighlightEditor_instances, createOutlines_fn, createFreeOutlines_fn, updateColor_fn2, updateThickness_fn, changeThickness_fn, cleanDrawLayer_fn, addToDrawLayer_fn, _HighlightEditor_static, rotateBbox_fn, keydown_fn, setCaret_fn, getRotation_fn, serializeBoxes_fn, serializeOutlines_fn, highlightMove_fn, endHighlight_fn, hasElementChanged_fn2;
18059
19022
  var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
18060
19023
  constructor(params) {
18061
19024
  super({ ...params, name: "highlightEditor" });
@@ -18070,7 +19033,7 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
18070
19033
  __privateAdd(this, _focusOffset, 0);
18071
19034
  __privateAdd(this, _highlightDiv, null);
18072
19035
  __privateAdd(this, _highlightOutlines, null);
18073
- __privateAdd(this, _id3, null);
19036
+ __privateAdd(this, _id4, null);
18074
19037
  __privateAdd(this, _isFreeHighlight, false);
18075
19038
  __privateAdd(this, _lastPoint2, null);
18076
19039
  __privateAdd(this, _opacity);
@@ -18284,7 +19247,7 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
18284
19247
  } else {
18285
19248
  box = __privateMethod(_b = _HighlightEditor, _HighlightEditor_static, rotateBbox_fn).call(_b, [this.x, this.y, this.width, this.height], angle);
18286
19249
  }
18287
- drawLayer.updateProperties(__privateGet(this, _id3), {
19250
+ drawLayer.updateProperties(__privateGet(this, _id4), {
18288
19251
  bbox: box,
18289
19252
  root: {
18290
19253
  "data-main-rotation": angle
@@ -18404,7 +19367,7 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
18404
19367
  show(visible = this._isVisible) {
18405
19368
  super.show(visible);
18406
19369
  if (this.parent) {
18407
- this.parent.drawLayer.updateProperties(__privateGet(this, _id3), {
19370
+ this.parent.drawLayer.updateProperties(__privateGet(this, _id4), {
18408
19371
  rootClass: {
18409
19372
  hidden: !visible
18410
19373
  }
@@ -18655,7 +19618,7 @@ _focusNode = new WeakMap();
18655
19618
  _focusOffset = new WeakMap();
18656
19619
  _highlightDiv = new WeakMap();
18657
19620
  _highlightOutlines = new WeakMap();
18658
- _id3 = new WeakMap();
19621
+ _id4 = new WeakMap();
18659
19622
  _isFreeHighlight = new WeakMap();
18660
19623
  _lastPoint2 = new WeakMap();
18661
19624
  _opacity = new WeakMap();
@@ -18699,7 +19662,7 @@ createFreeOutlines_fn = function({ highlightOutlines, highlightId, clipPathId })
18699
19662
  25e-4
18700
19663
  ));
18701
19664
  if (highlightId >= 0) {
18702
- __privateSet(this, _id3, highlightId);
19665
+ __privateSet(this, _id4, highlightId);
18703
19666
  __privateSet(this, _clipPathId, clipPathId);
18704
19667
  this.parent.drawLayer.finalizeDraw(highlightId, {
18705
19668
  bbox: highlightOutlines.box,
@@ -18723,7 +19686,7 @@ createFreeOutlines_fn = function({ highlightOutlines, highlightId, clipPathId })
18723
19686
  ));
18724
19687
  } else if (this.parent) {
18725
19688
  const angle = this.parent.viewport.rotation;
18726
- this.parent.drawLayer.updateProperties(__privateGet(this, _id3), {
19689
+ this.parent.drawLayer.updateProperties(__privateGet(this, _id4), {
18727
19690
  bbox: __privateMethod(_a2 = _HighlightEditor, _HighlightEditor_static, rotateBbox_fn).call(_a2, __privateGet(this, _highlightOutlines).box, (angle - this.rotation + 360) % 360),
18728
19691
  path: {
18729
19692
  d: highlightOutlines.toSVGPath()
@@ -18778,7 +19741,7 @@ updateColor_fn2 = function(color) {
18778
19741
  const setColorAndOpacity = (col, opa) => {
18779
19742
  this.color = col;
18780
19743
  __privateSet(this, _opacity, opa);
18781
- this.parent?.drawLayer.updateProperties(__privateGet(this, _id3), {
19744
+ this.parent?.drawLayer.updateProperties(__privateGet(this, _id4), {
18782
19745
  root: {
18783
19746
  fill: col,
18784
19747
  "fill-opacity": opa
@@ -18847,19 +19810,19 @@ changeThickness_fn = function(thickness) {
18847
19810
  this.setDims(this.width * parentWidth, this.height * parentHeight);
18848
19811
  };
18849
19812
  cleanDrawLayer_fn = function() {
18850
- if (__privateGet(this, _id3) === null || !this.parent) {
19813
+ if (__privateGet(this, _id4) === null || !this.parent) {
18851
19814
  return;
18852
19815
  }
18853
- this.parent.drawLayer.remove(__privateGet(this, _id3));
18854
- __privateSet(this, _id3, null);
19816
+ this.parent.drawLayer.remove(__privateGet(this, _id4));
19817
+ __privateSet(this, _id4, null);
18855
19818
  this.parent.drawLayer.remove(__privateGet(this, _outlineId));
18856
19819
  __privateSet(this, _outlineId, null);
18857
19820
  };
18858
19821
  addToDrawLayer_fn = function(parent = this.parent) {
18859
- if (__privateGet(this, _id3) !== null) {
19822
+ if (__privateGet(this, _id4) !== null) {
18860
19823
  return;
18861
19824
  }
18862
- ({ id: __privateWrapper(this, _id3)._, clipPathId: __privateWrapper(this, _clipPathId)._ } = parent.drawLayer.draw(
19825
+ ({ id: __privateWrapper(this, _id4)._, clipPathId: __privateWrapper(this, _clipPathId)._ } = parent.drawLayer.draw(
18863
19826
  {
18864
19827
  bbox: __privateGet(this, _highlightOutlines).box,
18865
19828
  root: {
@@ -23380,7 +24343,7 @@ __privateAdd(_AnnotationEditorLayer, _editorTypes2, new Map(
23380
24343
  var AnnotationEditorLayer = _AnnotationEditorLayer;
23381
24344
 
23382
24345
  // src/pdf.js/src/display/draw_layer.js
23383
- var _parent2, _mapping, _toUpdate, _id4, _DrawLayer_static, setBox_fn, _DrawLayer_instances, createSVG_fn, createClipPath_fn, updateProperties_fn;
24346
+ var _parent2, _mapping, _toUpdate, _id5, _DrawLayer_static, setBox_fn, _DrawLayer_instances, createSVG_fn, createClipPath_fn, updateProperties_fn;
23384
24347
  var _DrawLayer = class _DrawLayer {
23385
24348
  constructor({ pageIndex }) {
23386
24349
  __privateAdd(this, _DrawLayer_instances);
@@ -23408,7 +24371,7 @@ var _DrawLayer = class _DrawLayer {
23408
24371
  return shadow(this, "_svgFactory", new DOMSVGFactory());
23409
24372
  }
23410
24373
  draw(properties, isPathUpdatable = false, hasClip = false) {
23411
- const id2 = __privateWrapper(_DrawLayer, _id4)._++;
24374
+ const id2 = __privateWrapper(_DrawLayer, _id5)._++;
23412
24375
  const root = __privateMethod(this, _DrawLayer_instances, createSVG_fn).call(this);
23413
24376
  const defs = _DrawLayer._svgFactory.createElement("defs");
23414
24377
  root.append(defs);
@@ -23429,7 +24392,7 @@ var _DrawLayer = class _DrawLayer {
23429
24392
  return { id: id2, clipPathId: `url(#${clipPathId})` };
23430
24393
  }
23431
24394
  drawOutline(properties, mustRemoveSelfIntersections) {
23432
- const id2 = __privateWrapper(_DrawLayer, _id4)._++;
24395
+ const id2 = __privateWrapper(_DrawLayer, _id5)._++;
23433
24396
  const root = __privateMethod(this, _DrawLayer_instances, createSVG_fn).call(this);
23434
24397
  const defs = _DrawLayer._svgFactory.createElement("defs");
23435
24398
  root.append(defs);
@@ -23536,7 +24499,7 @@ var _DrawLayer = class _DrawLayer {
23536
24499
  _parent2 = new WeakMap();
23537
24500
  _mapping = new WeakMap();
23538
24501
  _toUpdate = new WeakMap();
23539
- _id4 = new WeakMap();
24502
+ _id5 = new WeakMap();
23540
24503
  _DrawLayer_static = new WeakSet();
23541
24504
  setBox_fn = function(element, [x, y, width, height]) {
23542
24505
  const { style } = element;
@@ -23579,7 +24542,7 @@ updateProperties_fn = function(element, properties) {
23579
24542
  }
23580
24543
  };
23581
24544
  __privateAdd(_DrawLayer, _DrawLayer_static);
23582
- __privateAdd(_DrawLayer, _id4, 0);
24545
+ __privateAdd(_DrawLayer, _id5, 0);
23583
24546
  var DrawLayer = _DrawLayer;
23584
24547
 
23585
24548
  // src/pdf.js/src/pdf.js
@@ -24006,6 +24969,94 @@ function renderSvgNode(node) {
24006
24969
  return `<${node.tag}${renderAttributes(node.attrs)} />`;
24007
24970
  }
24008
24971
 
24972
+ // src/lib/utils.ts
24973
+ async function canvasToData(canvas) {
24974
+ if ("toBlob" in canvas) {
24975
+ const blob = await new Promise(
24976
+ (resolve) => canvas.toBlob((data) => resolve(data))
24977
+ );
24978
+ if (!blob) {
24979
+ throw new Error("Failed to generate graphics");
24980
+ }
24981
+ return new Uint8Array(await blob.arrayBuffer());
24982
+ }
24983
+ const buffer = await canvas.toBuffer("png");
24984
+ return new Uint8Array(buffer);
24985
+ }
24986
+ async function toDataUrl(data, type = "image/png") {
24987
+ if (typeof FileReader !== "undefined") {
24988
+ return new Promise((resolve) => {
24989
+ const reader = new FileReader();
24990
+ reader.onload = () => {
24991
+ resolve(reader.result);
24992
+ };
24993
+ reader.readAsDataURL(new Blob([data], { type }));
24994
+ });
24995
+ }
24996
+ return `data:${type};base64,${Buffer.from(data).toString("base64")}`;
24997
+ }
24998
+ function makeSerializable(object) {
24999
+ if (typeof object !== "object" || object === null) {
25000
+ return object;
25001
+ }
25002
+ if (object instanceof Int8Array || object instanceof Uint8Array || object instanceof Uint8ClampedArray || object instanceof Int16Array || object instanceof Uint16Array || object instanceof Int32Array || object instanceof Uint32Array || object instanceof Float32Array || object instanceof Float64Array) {
25003
+ return makeSerializable(Array.from(object));
25004
+ }
25005
+ if (object instanceof BigInt64Array || object instanceof BigUint64Array) {
25006
+ return makeSerializable(Array.from(object));
25007
+ }
25008
+ if (Array.isArray(object)) {
25009
+ return object.map(makeSerializable);
25010
+ }
25011
+ return Object.fromEntries(
25012
+ Object.entries(object).map(([key, value]) => [
25013
+ key,
25014
+ makeSerializable(value)
25015
+ ])
25016
+ );
25017
+ }
25018
+ function colorToRgb(color) {
25019
+ if (color.startsWith("#")) {
25020
+ const hex = color.slice(1);
25021
+ if (hex.length === 3) {
25022
+ return [
25023
+ Number.parseInt(hex[0] + hex[0], 16),
25024
+ Number.parseInt(hex[1] + hex[1], 16),
25025
+ Number.parseInt(hex[2] + hex[2], 16)
25026
+ ];
25027
+ }
25028
+ if (hex.length === 6) {
25029
+ return [
25030
+ Number.parseInt(hex.slice(0, 2), 16),
25031
+ Number.parseInt(hex.slice(2, 4), 16),
25032
+ Number.parseInt(hex.slice(4, 6), 16)
25033
+ ];
25034
+ }
25035
+ }
25036
+ throw new Error(`Invalid color format: ${color}`);
25037
+ }
25038
+ function rgbToHex(r, g, b) {
25039
+ const toHex = (value) => value.toString(16).padStart(2, "0");
25040
+ if (Array.isArray(r)) {
25041
+ return `#${toHex(r[0])}${toHex(r[1])}${toHex(r[2])}`;
25042
+ }
25043
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
25044
+ }
25045
+ function parseRgbaColor(color) {
25046
+ const match = color.match(
25047
+ /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)$/
25048
+ );
25049
+ if (!match) {
25050
+ return { r: 0, g: 0, b: 0, a: 1 };
25051
+ }
25052
+ return {
25053
+ r: Number.parseInt(match[1], 10),
25054
+ g: Number.parseInt(match[2], 10),
25055
+ b: Number.parseInt(match[3], 10),
25056
+ a: match[4] ? Number.parseFloat(match[4]) : 1
25057
+ };
25058
+ }
25059
+
24009
25060
  // src/lib/SvgCanvasContext.ts
24010
25061
  function isCanvas(img) {
24011
25062
  return "toDataURL" in img;
@@ -24972,7 +26023,7 @@ async function toSvgString(ctx) {
24972
26023
 
24973
26024
  // src/lib/PDFPageProxy.ts
24974
26025
  async function loadNodeCanvasFactory() {
24975
- const { NodeCanvasFactory: NodeCanvasFactory2 } = await import("./NodeCanvasFactory-ONRE5YYL.js");
26026
+ const { NodeCanvasFactory: NodeCanvasFactory2 } = await import("./NodeUtilsStabs-MUAXKISB.js");
24976
26027
  return new NodeCanvasFactory2({});
24977
26028
  }
24978
26029
  var getAnnotations = PDFPageProxy.prototype.getAnnotations;