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

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.
Files changed (68) hide show
  1. package/README.md +15 -7
  2. package/dist/browser/NodeCanvasFactory-ONRE5YYL.js +58 -0
  3. package/dist/browser/chunk-5IWODJWD.js +801 -0
  4. package/dist/browser/chunk-ELOUEWKT.js +1142 -0
  5. package/dist/browser/chunk-NJUB3B5A.js +1207 -0
  6. package/dist/browser/index.js +2641 -3053
  7. package/dist/browser/openjpeg-K2XBCFFN.js +9 -0
  8. package/dist/browser/qcms_bg-Q7BRLLZG.js +9 -0
  9. package/dist/browser/worker.js +7307 -6457
  10. package/dist/index.d.ts +3 -0
  11. package/dist/lib/AnnotationData.d.ts +8 -8
  12. package/dist/lib/AnnotationOperatorsList.d.ts +21 -0
  13. package/dist/lib/CanvasGraphics.d.ts +1 -0
  14. package/dist/lib/NodeCanvasFactory.d.ts +9 -0
  15. package/dist/lib/NodeFilterFactory.d.ts +10 -0
  16. package/dist/lib/Path2D.d.ts +1 -1
  17. package/dist/lib/StandardFontDataFactory.d.ts +2 -2
  18. package/dist/lib/Svg.d.ts +143 -0
  19. package/dist/lib/SvgCanvasContext.d.ts +31 -22
  20. package/dist/lib/TextLayer.d.ts +12 -5
  21. package/dist/lib/WasmFactory.d.ts +5 -0
  22. package/dist/lib/utils.d.ts +29 -3
  23. package/dist/node/NodeCanvasFactory-YRBSQ5MH.js +8 -0
  24. package/dist/node/chunk-3XZOTLLE.js +1439 -0
  25. package/dist/node/chunk-XMKSLA4K.js +1207 -0
  26. package/dist/node/chunk-ZKUTXCS2.js +801 -0
  27. package/dist/node/index.js +2659 -3102
  28. package/dist/node/openjpeg-B2WN24QZ.js +9 -0
  29. package/dist/node/qcms_bg-T4RSHPOQ.js +9 -0
  30. package/dist/node/worker.js +7307 -6457
  31. package/dist/pdf.js/src/display/annotation_layer.d.ts +1 -2
  32. package/dist/pdf.js/src/display/annotation_storage.d.ts +1 -8
  33. package/dist/pdf.js/src/display/api.d.ts +38 -72
  34. package/dist/pdf.js/src/display/api_utils.d.ts +13 -0
  35. package/dist/pdf.js/src/display/canvas.d.ts +21 -29
  36. package/dist/pdf.js/src/display/display_utils.d.ts +12 -1
  37. package/dist/pdf.js/src/display/draw_layer.d.ts +2 -2
  38. package/dist/pdf.js/src/display/editor/alt_text.d.ts +1 -1
  39. package/dist/pdf.js/src/display/editor/annotation_editor_layer.d.ts +5 -5
  40. package/dist/pdf.js/src/display/editor/color_picker.d.ts +1 -1
  41. package/dist/pdf.js/src/display/editor/draw.d.ts +7 -7
  42. package/dist/pdf.js/src/display/editor/drawers/freedraw.d.ts +3 -3
  43. package/dist/pdf.js/src/display/editor/drawers/signaturedraw.d.ts +13 -13
  44. package/dist/pdf.js/src/display/editor/editor.d.ts +30 -6
  45. package/dist/pdf.js/src/display/editor/freetext.d.ts +4 -7
  46. package/dist/pdf.js/src/display/editor/highlight.d.ts +6 -3
  47. package/dist/pdf.js/src/display/editor/ink.d.ts +1 -0
  48. package/dist/pdf.js/src/display/editor/signature.d.ts +3 -0
  49. package/dist/pdf.js/src/display/editor/stamp.d.ts +4 -3
  50. package/dist/pdf.js/src/display/editor/toolbar.d.ts +4 -2
  51. package/dist/pdf.js/src/display/editor/tools.d.ts +7 -9
  52. package/dist/pdf.js/src/display/metadata.d.ts +1 -2
  53. package/dist/pdf.js/src/display/optional_content_config.d.ts +1 -1
  54. package/dist/pdf.js/src/display/pattern_helper.d.ts +4 -2
  55. package/dist/pdf.js/src/display/pdf_objects.d.ts +40 -0
  56. package/dist/pdf.js/src/display/text_layer.d.ts +9 -9
  57. package/dist/pdf.js/src/display/touch_manager.d.ts +5 -1
  58. package/dist/pdf.js/src/display/worker_options.d.ts +2 -2
  59. package/dist/pdf.js/src/pdf.d.ts +4 -1
  60. package/dist/pdf.js/src/shared/scripting_utils.d.ts +2 -0
  61. package/dist/pdf.js/src/shared/util.d.ts +123 -100
  62. package/dist/pdf.js/web/text_accessibility.d.ts +1 -1
  63. package/package.json +7 -4
  64. package/dist/browser/chunk-DYHYQ33L.js +0 -1775
  65. package/dist/node/chunk-KTTVPO2G.js +0 -1775
  66. package/dist/pdf.js/src/display/cmap_reader_factory.d.ts +0 -25
  67. package/dist/pdf.js/src/display/node_utils.d.ts +0 -32
  68. package/dist/pdf.js/src/display/wasm_factory.d.ts +0 -20
@@ -1,1775 +0,0 @@
1
- import {
2
- __privateAdd,
3
- __privateGet,
4
- __privateMethod,
5
- __privateSet
6
- } from "./chunk-7MW5RQZ5.js";
7
-
8
- // src/lib/polyfills.ts
9
- if (!Array.prototype.at) {
10
- Object.defineProperty(Array.prototype, "at", {
11
- value: function at(index) {
12
- return this[index >= 0 ? index : this.length + index];
13
- },
14
- enumerable: false
15
- });
16
- }
17
- if (!Promise.withResolvers) {
18
- Promise.withResolvers = function withResolvers() {
19
- let resolve;
20
- let reject;
21
- const promise = new this((res, rej) => {
22
- resolve = res;
23
- reject = rej;
24
- });
25
- return {
26
- resolve,
27
- reject,
28
- promise
29
- };
30
- };
31
- }
32
- if (!("try" in Promise)) {
33
- Object.defineProperty(Promise, "try", {
34
- value: function tryFn(fn, ...args) {
35
- return new this(
36
- (resolve, reject) => {
37
- try {
38
- resolve(fn(...args));
39
- } catch (error) {
40
- reject(error);
41
- }
42
- }
43
- );
44
- },
45
- enumerable: false
46
- });
47
- }
48
-
49
- // src/pdf.js/src/shared/util.js
50
- var isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
51
- var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
52
- var FONT_IDENTITY_MATRIX = [1e-3, 0, 0, 1e-3, 0, 0];
53
- var LINE_FACTOR = 1.35;
54
- var LINE_DESCENT_FACTOR = 0.35;
55
- var BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
56
- var RenderingIntentFlag = {
57
- ANY: 1,
58
- DISPLAY: 2,
59
- PRINT: 4,
60
- SAVE: 8,
61
- ANNOTATIONS_FORMS: 16,
62
- ANNOTATIONS_STORAGE: 32,
63
- ANNOTATIONS_DISABLE: 64,
64
- IS_EDITING: 128,
65
- OPLIST: 256
66
- };
67
- var AnnotationMode = {
68
- DISABLE: 0,
69
- ENABLE: 1,
70
- ENABLE_FORMS: 2,
71
- ENABLE_STORAGE: 3
72
- };
73
- var AnnotationEditorPrefix = "pdfjs_internal_editor_";
74
- var AnnotationEditorType = {
75
- DISABLE: -1,
76
- NONE: 0,
77
- FREETEXT: 3,
78
- HIGHLIGHT: 9,
79
- STAMP: 13,
80
- INK: 15,
81
- SIGNATURE: 101
82
- };
83
- var AnnotationEditorParamsType = {
84
- RESIZE: 1,
85
- CREATE: 2,
86
- FREETEXT_SIZE: 11,
87
- FREETEXT_COLOR: 12,
88
- FREETEXT_OPACITY: 13,
89
- INK_COLOR: 21,
90
- INK_THICKNESS: 22,
91
- INK_OPACITY: 23,
92
- HIGHLIGHT_COLOR: 31,
93
- HIGHLIGHT_DEFAULT_COLOR: 32,
94
- HIGHLIGHT_THICKNESS: 33,
95
- HIGHLIGHT_FREE: 34,
96
- HIGHLIGHT_SHOW_ALL: 35,
97
- DRAW_STEP: 41
98
- };
99
- var PermissionFlag = {
100
- PRINT: 4,
101
- MODIFY_CONTENTS: 8,
102
- COPY: 16,
103
- MODIFY_ANNOTATIONS: 32,
104
- FILL_INTERACTIVE_FORMS: 256,
105
- COPY_FOR_ACCESSIBILITY: 512,
106
- ASSEMBLE: 1024,
107
- PRINT_HIGH_QUALITY: 2048
108
- };
109
- var TextRenderingMode = {
110
- FILL: 0,
111
- STROKE: 1,
112
- FILL_STROKE: 2,
113
- INVISIBLE: 3,
114
- FILL_ADD_TO_PATH: 4,
115
- STROKE_ADD_TO_PATH: 5,
116
- FILL_STROKE_ADD_TO_PATH: 6,
117
- ADD_TO_PATH: 7,
118
- FILL_STROKE_MASK: 3,
119
- ADD_TO_PATH_FLAG: 4
120
- };
121
- var ImageKind = {
122
- GRAYSCALE_1BPP: 1,
123
- RGB_24BPP: 2,
124
- RGBA_32BPP: 3
125
- };
126
- var AnnotationType = {
127
- TEXT: 1,
128
- LINK: 2,
129
- FREETEXT: 3,
130
- LINE: 4,
131
- SQUARE: 5,
132
- CIRCLE: 6,
133
- POLYGON: 7,
134
- POLYLINE: 8,
135
- HIGHLIGHT: 9,
136
- UNDERLINE: 10,
137
- SQUIGGLY: 11,
138
- STRIKEOUT: 12,
139
- STAMP: 13,
140
- CARET: 14,
141
- INK: 15,
142
- POPUP: 16,
143
- FILEATTACHMENT: 17,
144
- SOUND: 18,
145
- MOVIE: 19,
146
- WIDGET: 20,
147
- SCREEN: 21,
148
- PRINTERMARK: 22,
149
- TRAPNET: 23,
150
- WATERMARK: 24,
151
- THREED: 25,
152
- REDACT: 26
153
- };
154
- var AnnotationReplyType = {
155
- GROUP: "Group",
156
- REPLY: "R"
157
- };
158
- var AnnotationFlag = {
159
- INVISIBLE: 1,
160
- HIDDEN: 2,
161
- PRINT: 4,
162
- NOZOOM: 8,
163
- NOROTATE: 16,
164
- NOVIEW: 32,
165
- READONLY: 64,
166
- LOCKED: 128,
167
- TOGGLENOVIEW: 256,
168
- LOCKEDCONTENTS: 512
169
- };
170
- var AnnotationFieldFlag = {
171
- READONLY: 1,
172
- REQUIRED: 2,
173
- NOEXPORT: 4,
174
- MULTILINE: 4096,
175
- PASSWORD: 8192,
176
- NOTOGGLETOOFF: 16384,
177
- RADIO: 32768,
178
- PUSHBUTTON: 65536,
179
- COMBO: 131072,
180
- EDIT: 262144,
181
- SORT: 524288,
182
- FILESELECT: 1048576,
183
- MULTISELECT: 2097152,
184
- DONOTSPELLCHECK: 4194304,
185
- DONOTSCROLL: 8388608,
186
- COMB: 16777216,
187
- RICHTEXT: 33554432,
188
- RADIOSINUNISON: 33554432,
189
- COMMITONSELCHANGE: 67108864
190
- };
191
- var AnnotationBorderStyleType = {
192
- SOLID: 1,
193
- DASHED: 2,
194
- BEVELED: 3,
195
- INSET: 4,
196
- UNDERLINE: 5
197
- };
198
- var AnnotationActionEventType = {
199
- E: "Mouse Enter",
200
- X: "Mouse Exit",
201
- D: "Mouse Down",
202
- U: "Mouse Up",
203
- Fo: "Focus",
204
- Bl: "Blur",
205
- PO: "PageOpen",
206
- PC: "PageClose",
207
- PV: "PageVisible",
208
- PI: "PageInvisible",
209
- K: "Keystroke",
210
- F: "Format",
211
- V: "Validate",
212
- C: "Calculate"
213
- };
214
- var DocumentActionEventType = {
215
- WC: "WillClose",
216
- WS: "WillSave",
217
- DS: "DidSave",
218
- WP: "WillPrint",
219
- DP: "DidPrint"
220
- };
221
- var PageActionEventType = {
222
- O: "PageOpen",
223
- C: "PageClose"
224
- };
225
- var VerbosityLevel = {
226
- ERRORS: 0,
227
- WARNINGS: 1,
228
- INFOS: 5
229
- };
230
- var OPS = {
231
- // Intentionally start from 1 so it is easy to spot bad operators that will be
232
- // 0's.
233
- // PLEASE NOTE: We purposely keep any removed operators commented out, since
234
- // re-numbering the list would risk breaking third-party users.
235
- dependency: 1,
236
- setLineWidth: 2,
237
- setLineCap: 3,
238
- setLineJoin: 4,
239
- setMiterLimit: 5,
240
- setDash: 6,
241
- setRenderingIntent: 7,
242
- setFlatness: 8,
243
- setGState: 9,
244
- save: 10,
245
- restore: 11,
246
- transform: 12,
247
- moveTo: 13,
248
- lineTo: 14,
249
- curveTo: 15,
250
- curveTo2: 16,
251
- curveTo3: 17,
252
- closePath: 18,
253
- rectangle: 19,
254
- stroke: 20,
255
- closeStroke: 21,
256
- fill: 22,
257
- eoFill: 23,
258
- fillStroke: 24,
259
- eoFillStroke: 25,
260
- closeFillStroke: 26,
261
- closeEOFillStroke: 27,
262
- endPath: 28,
263
- clip: 29,
264
- eoClip: 30,
265
- beginText: 31,
266
- endText: 32,
267
- setCharSpacing: 33,
268
- setWordSpacing: 34,
269
- setHScale: 35,
270
- setLeading: 36,
271
- setFont: 37,
272
- setTextRenderingMode: 38,
273
- setTextRise: 39,
274
- moveText: 40,
275
- setLeadingMoveText: 41,
276
- setTextMatrix: 42,
277
- nextLine: 43,
278
- showText: 44,
279
- showSpacedText: 45,
280
- nextLineShowText: 46,
281
- nextLineSetSpacingShowText: 47,
282
- setCharWidth: 48,
283
- setCharWidthAndBounds: 49,
284
- setStrokeColorSpace: 50,
285
- setFillColorSpace: 51,
286
- setStrokeColor: 52,
287
- setStrokeColorN: 53,
288
- setFillColor: 54,
289
- setFillColorN: 55,
290
- setStrokeGray: 56,
291
- setFillGray: 57,
292
- setStrokeRGBColor: 58,
293
- setFillRGBColor: 59,
294
- setStrokeCMYKColor: 60,
295
- setFillCMYKColor: 61,
296
- shadingFill: 62,
297
- beginInlineImage: 63,
298
- beginImageData: 64,
299
- endInlineImage: 65,
300
- paintXObject: 66,
301
- markPoint: 67,
302
- markPointProps: 68,
303
- beginMarkedContent: 69,
304
- beginMarkedContentProps: 70,
305
- endMarkedContent: 71,
306
- beginCompat: 72,
307
- endCompat: 73,
308
- paintFormXObjectBegin: 74,
309
- paintFormXObjectEnd: 75,
310
- beginGroup: 76,
311
- endGroup: 77,
312
- // beginAnnotations: 78,
313
- // endAnnotations: 79,
314
- beginAnnotation: 80,
315
- endAnnotation: 81,
316
- // paintJpegXObject: 82,
317
- paintImageMaskXObject: 83,
318
- paintImageMaskXObjectGroup: 84,
319
- paintImageXObject: 85,
320
- paintInlineImageXObject: 86,
321
- paintInlineImageXObjectGroup: 87,
322
- paintImageXObjectRepeat: 88,
323
- paintImageMaskXObjectRepeat: 89,
324
- paintSolidColorImageMask: 90,
325
- constructPath: 91,
326
- setStrokeTransparent: 92,
327
- setFillTransparent: 93
328
- };
329
- var PasswordResponses = {
330
- NEED_PASSWORD: 1,
331
- INCORRECT_PASSWORD: 2
332
- };
333
- var verbosity = VerbosityLevel.WARNINGS;
334
- function setVerbosityLevel(level) {
335
- if (Number.isInteger(level)) {
336
- verbosity = level;
337
- }
338
- }
339
- function getVerbosityLevel() {
340
- return verbosity;
341
- }
342
- function info(msg) {
343
- if (verbosity >= VerbosityLevel.INFOS) {
344
- console.log(`Info: ${msg}`);
345
- }
346
- }
347
- function warn(msg) {
348
- if (verbosity >= VerbosityLevel.WARNINGS) {
349
- console.log(`Warning: ${msg}`);
350
- }
351
- }
352
- function unreachable(msg) {
353
- throw new Error(msg);
354
- }
355
- function assert(cond, msg) {
356
- if (!cond) {
357
- unreachable(msg);
358
- }
359
- }
360
- function _isValidProtocol(url) {
361
- switch (url?.protocol) {
362
- case "http:":
363
- case "https:":
364
- case "ftp:":
365
- case "mailto:":
366
- case "tel:":
367
- return true;
368
- default:
369
- return false;
370
- }
371
- }
372
- function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
373
- if (!url) {
374
- return null;
375
- }
376
- if (options && typeof url === "string") {
377
- if (options.addDefaultProtocol && url.startsWith("www.")) {
378
- const dots = url.match(/\./g);
379
- if (dots?.length >= 2) {
380
- url = `http://${url}`;
381
- }
382
- }
383
- if (options.tryConvertEncoding) {
384
- try {
385
- url = stringToUTF8String(url);
386
- } catch {
387
- }
388
- }
389
- }
390
- const absoluteUrl = baseUrl ? URL.parse(url, baseUrl) : URL.parse(url);
391
- return _isValidProtocol(absoluteUrl) ? absoluteUrl : null;
392
- }
393
- function shadow(obj, prop, value, nonSerializable = false) {
394
- if (false) {
395
- assert(
396
- prop in obj,
397
- `shadow: Property "${prop && prop.toString()}" not found in object.`
398
- );
399
- }
400
- Object.defineProperty(obj, prop, {
401
- value,
402
- enumerable: !nonSerializable,
403
- configurable: true,
404
- writable: false
405
- });
406
- return value;
407
- }
408
- var BaseException = function BaseExceptionClosure() {
409
- function BaseException2(message, name) {
410
- if (false) {
411
- unreachable("Cannot initialize BaseException.");
412
- }
413
- this.message = message;
414
- this.name = name;
415
- }
416
- BaseException2.prototype = new Error();
417
- BaseException2.constructor = BaseException2;
418
- return BaseException2;
419
- }();
420
- var PasswordException = class extends BaseException {
421
- constructor(msg, code) {
422
- super(msg, "PasswordException");
423
- this.code = code;
424
- }
425
- };
426
- var UnknownErrorException = class extends BaseException {
427
- constructor(msg, details) {
428
- super(msg, "UnknownErrorException");
429
- this.details = details;
430
- }
431
- };
432
- var InvalidPDFException = class extends BaseException {
433
- constructor(msg) {
434
- super(msg, "InvalidPDFException");
435
- }
436
- };
437
- var ResponseException = class extends BaseException {
438
- constructor(msg, status, missing) {
439
- super(msg, "ResponseException");
440
- this.status = status;
441
- this.missing = missing;
442
- }
443
- };
444
- var FormatError = class extends BaseException {
445
- constructor(msg) {
446
- super(msg, "FormatError");
447
- }
448
- };
449
- var AbortException = class extends BaseException {
450
- constructor(msg) {
451
- super(msg, "AbortException");
452
- }
453
- };
454
- function bytesToString(bytes) {
455
- if (typeof bytes !== "object" || bytes?.length === void 0) {
456
- unreachable("Invalid argument for bytesToString");
457
- }
458
- const length = bytes.length;
459
- const MAX_ARGUMENT_COUNT = 8192;
460
- if (length < MAX_ARGUMENT_COUNT) {
461
- return String.fromCharCode.apply(null, bytes);
462
- }
463
- const strBuf = [];
464
- for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
465
- const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
466
- const chunk = bytes.subarray(i, chunkEnd);
467
- strBuf.push(String.fromCharCode.apply(null, chunk));
468
- }
469
- return strBuf.join("");
470
- }
471
- function stringToBytes(str) {
472
- if (typeof str !== "string") {
473
- unreachable("Invalid argument for stringToBytes");
474
- }
475
- const length = str.length;
476
- const bytes = new Uint8Array(length);
477
- for (let i = 0; i < length; ++i) {
478
- bytes[i] = str.charCodeAt(i) & 255;
479
- }
480
- return bytes;
481
- }
482
- function string32(value) {
483
- if (false) {
484
- assert(
485
- typeof value === "number" && Math.abs(value) < 2 ** 32,
486
- `string32: Unexpected input "${value}".`
487
- );
488
- }
489
- return String.fromCharCode(
490
- value >> 24 & 255,
491
- value >> 16 & 255,
492
- value >> 8 & 255,
493
- value & 255
494
- );
495
- }
496
- function objectSize(obj) {
497
- return Object.keys(obj).length;
498
- }
499
- function objectFromMap(map) {
500
- const obj = /* @__PURE__ */ Object.create(null);
501
- for (const [key, value] of map) {
502
- obj[key] = value;
503
- }
504
- return obj;
505
- }
506
- function isLittleEndian() {
507
- const buffer8 = new Uint8Array(4);
508
- buffer8[0] = 1;
509
- const view32 = new Uint32Array(buffer8.buffer, 0, 1);
510
- return view32[0] === 1;
511
- }
512
- function isEvalSupported() {
513
- try {
514
- new Function("");
515
- return true;
516
- } catch {
517
- return false;
518
- }
519
- }
520
- var FeatureTest = class {
521
- static get isLittleEndian() {
522
- return shadow(this, "isLittleEndian", isLittleEndian());
523
- }
524
- static get isEvalSupported() {
525
- return shadow(this, "isEvalSupported", isEvalSupported());
526
- }
527
- static get isOffscreenCanvasSupported() {
528
- return shadow(
529
- this,
530
- "isOffscreenCanvasSupported",
531
- typeof OffscreenCanvas !== "undefined"
532
- );
533
- }
534
- static get isImageDecoderSupported() {
535
- return shadow(
536
- this,
537
- "isImageDecoderSupported",
538
- typeof ImageDecoder !== "undefined"
539
- );
540
- }
541
- static get platform() {
542
- if (typeof navigator !== "undefined" && typeof navigator?.platform === "string" && typeof navigator?.userAgent === "string") {
543
- const { platform, userAgent } = navigator;
544
- return shadow(this, "platform", {
545
- isAndroid: userAgent.includes("Android"),
546
- isLinux: platform.includes("Linux"),
547
- isMac: platform.includes("Mac"),
548
- isWindows: platform.includes("Win"),
549
- isFirefox: userAgent.includes("Firefox")
550
- });
551
- }
552
- return shadow(this, "platform", {
553
- isAndroid: false,
554
- isLinux: false,
555
- isMac: false,
556
- isWindows: false,
557
- isFirefox: false
558
- });
559
- }
560
- static get isCSSRoundSupported() {
561
- return shadow(
562
- this,
563
- "isCSSRoundSupported",
564
- globalThis.CSS?.supports?.("width: round(1.5px, 1px)")
565
- );
566
- }
567
- };
568
- var hexNumbers = Array.from(
569
- Array(256).keys(),
570
- (n) => n.toString(16).padStart(2, "0")
571
- );
572
- var _Util_static, getExtremumOnCurve_fn, getExtremum_fn;
573
- var Util = class {
574
- static makeHexColor(r, g, b) {
575
- return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
576
- }
577
- // Apply a scaling matrix to some min/max values.
578
- // If a scaling factor is negative then min and max must be
579
- // swapped.
580
- static scaleMinMax(transform, minMax) {
581
- let temp;
582
- if (transform[0]) {
583
- if (transform[0] < 0) {
584
- temp = minMax[0];
585
- minMax[0] = minMax[2];
586
- minMax[2] = temp;
587
- }
588
- minMax[0] *= transform[0];
589
- minMax[2] *= transform[0];
590
- if (transform[3] < 0) {
591
- temp = minMax[1];
592
- minMax[1] = minMax[3];
593
- minMax[3] = temp;
594
- }
595
- minMax[1] *= transform[3];
596
- minMax[3] *= transform[3];
597
- } else {
598
- temp = minMax[0];
599
- minMax[0] = minMax[1];
600
- minMax[1] = temp;
601
- temp = minMax[2];
602
- minMax[2] = minMax[3];
603
- minMax[3] = temp;
604
- if (transform[1] < 0) {
605
- temp = minMax[1];
606
- minMax[1] = minMax[3];
607
- minMax[3] = temp;
608
- }
609
- minMax[1] *= transform[1];
610
- minMax[3] *= transform[1];
611
- if (transform[2] < 0) {
612
- temp = minMax[0];
613
- minMax[0] = minMax[2];
614
- minMax[2] = temp;
615
- }
616
- minMax[0] *= transform[2];
617
- minMax[2] *= transform[2];
618
- }
619
- minMax[0] += transform[4];
620
- minMax[1] += transform[5];
621
- minMax[2] += transform[4];
622
- minMax[3] += transform[5];
623
- }
624
- // Concatenates two transformation matrices together and returns the result.
625
- static transform(m1, m2) {
626
- return [
627
- m1[0] * m2[0] + m1[2] * m2[1],
628
- m1[1] * m2[0] + m1[3] * m2[1],
629
- m1[0] * m2[2] + m1[2] * m2[3],
630
- m1[1] * m2[2] + m1[3] * m2[3],
631
- m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
632
- m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
633
- ];
634
- }
635
- // For 2d affine transforms
636
- static applyTransform(p, m) {
637
- const xt = p[0] * m[0] + p[1] * m[2] + m[4];
638
- const yt = p[0] * m[1] + p[1] * m[3] + m[5];
639
- return [xt, yt];
640
- }
641
- static applyInverseTransform(p, m) {
642
- const d = m[0] * m[3] - m[1] * m[2];
643
- const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
644
- const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
645
- return [xt, yt];
646
- }
647
- // Applies the transform to the rectangle and finds the minimum axially
648
- // aligned bounding box.
649
- static getAxialAlignedBoundingBox(r, m) {
650
- const p1 = this.applyTransform(r, m);
651
- const p2 = this.applyTransform(r.slice(2, 4), m);
652
- const p3 = this.applyTransform([r[0], r[3]], m);
653
- const p4 = this.applyTransform([r[2], r[1]], m);
654
- return [
655
- Math.min(p1[0], p2[0], p3[0], p4[0]),
656
- Math.min(p1[1], p2[1], p3[1], p4[1]),
657
- Math.max(p1[0], p2[0], p3[0], p4[0]),
658
- Math.max(p1[1], p2[1], p3[1], p4[1])
659
- ];
660
- }
661
- static inverseTransform(m) {
662
- const d = m[0] * m[3] - m[1] * m[2];
663
- return [
664
- m[3] / d,
665
- -m[1] / d,
666
- -m[2] / d,
667
- m[0] / d,
668
- (m[2] * m[5] - m[4] * m[3]) / d,
669
- (m[4] * m[1] - m[5] * m[0]) / d
670
- ];
671
- }
672
- // This calculation uses Singular Value Decomposition.
673
- // The SVD can be represented with formula A = USV. We are interested in the
674
- // matrix S here because it represents the scale values.
675
- static singularValueDecompose2dScale(m) {
676
- const transpose = [m[0], m[2], m[1], m[3]];
677
- const a = m[0] * transpose[0] + m[1] * transpose[2];
678
- const b = m[0] * transpose[1] + m[1] * transpose[3];
679
- const c = m[2] * transpose[0] + m[3] * transpose[2];
680
- const d = m[2] * transpose[1] + m[3] * transpose[3];
681
- const first = (a + d) / 2;
682
- const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
683
- const sx = first + second || 1;
684
- const sy = first - second || 1;
685
- return [Math.sqrt(sx), Math.sqrt(sy)];
686
- }
687
- // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
688
- // For coordinate systems whose origin lies in the bottom-left, this
689
- // means normalization to (BL,TR) ordering. For systems with origin in the
690
- // top-left, this means (TL,BR) ordering.
691
- static normalizeRect(rect) {
692
- const r = rect.slice(0);
693
- if (rect[0] > rect[2]) {
694
- r[0] = rect[2];
695
- r[2] = rect[0];
696
- }
697
- if (rect[1] > rect[3]) {
698
- r[1] = rect[3];
699
- r[3] = rect[1];
700
- }
701
- return r;
702
- }
703
- // Returns a rectangle [x1, y1, x2, y2] corresponding to the
704
- // intersection of rect1 and rect2. If no intersection, returns 'null'
705
- // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
706
- static intersect(rect1, rect2) {
707
- const xLow = Math.max(
708
- Math.min(rect1[0], rect1[2]),
709
- Math.min(rect2[0], rect2[2])
710
- );
711
- const xHigh = Math.min(
712
- Math.max(rect1[0], rect1[2]),
713
- Math.max(rect2[0], rect2[2])
714
- );
715
- if (xLow > xHigh) {
716
- return null;
717
- }
718
- const yLow = Math.max(
719
- Math.min(rect1[1], rect1[3]),
720
- Math.min(rect2[1], rect2[3])
721
- );
722
- const yHigh = Math.min(
723
- Math.max(rect1[1], rect1[3]),
724
- Math.max(rect2[1], rect2[3])
725
- );
726
- if (yLow > yHigh) {
727
- return null;
728
- }
729
- return [xLow, yLow, xHigh, yHigh];
730
- }
731
- // From https://github.com/adobe-webplatform/Snap.svg/blob/b365287722a72526000ac4bfcf0ce4cac2faa015/src/path.js#L852
732
- static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
733
- if (minMax) {
734
- minMax[0] = Math.min(minMax[0], x0, x3);
735
- minMax[1] = Math.min(minMax[1], y0, y3);
736
- minMax[2] = Math.max(minMax[2], x0, x3);
737
- minMax[3] = Math.max(minMax[3], y0, y3);
738
- } else {
739
- minMax = [
740
- Math.min(x0, x3),
741
- Math.min(y0, y3),
742
- Math.max(x0, x3),
743
- Math.max(y0, y3)
744
- ];
745
- }
746
- __privateMethod(this, _Util_static, getExtremum_fn).call(this, x0, x1, x2, x3, y0, y1, y2, y3, 3 * (-x0 + 3 * (x1 - x2) + x3), 6 * (x0 - 2 * x1 + x2), 3 * (x1 - x0), minMax);
747
- __privateMethod(this, _Util_static, getExtremum_fn).call(this, x0, x1, x2, x3, y0, y1, y2, y3, 3 * (-y0 + 3 * (y1 - y2) + y3), 6 * (y0 - 2 * y1 + y2), 3 * (y1 - y0), minMax);
748
- return minMax;
749
- }
750
- };
751
- _Util_static = new WeakSet();
752
- getExtremumOnCurve_fn = function(x0, x1, x2, x3, y0, y1, y2, y3, t, minMax) {
753
- if (t <= 0 || t >= 1) {
754
- return;
755
- }
756
- const mt = 1 - t;
757
- const tt = t * t;
758
- const ttt = tt * t;
759
- const x = mt * (mt * (mt * x0 + 3 * t * x1) + 3 * tt * x2) + ttt * x3;
760
- const y = mt * (mt * (mt * y0 + 3 * t * y1) + 3 * tt * y2) + ttt * y3;
761
- minMax[0] = Math.min(minMax[0], x);
762
- minMax[1] = Math.min(minMax[1], y);
763
- minMax[2] = Math.max(minMax[2], x);
764
- minMax[3] = Math.max(minMax[3], y);
765
- };
766
- getExtremum_fn = function(x0, x1, x2, x3, y0, y1, y2, y3, a, b, c, minMax) {
767
- if (Math.abs(a) < 1e-12) {
768
- if (Math.abs(b) >= 1e-12) {
769
- __privateMethod(this, _Util_static, getExtremumOnCurve_fn).call(this, x0, x1, x2, x3, y0, y1, y2, y3, -c / b, minMax);
770
- }
771
- return;
772
- }
773
- const delta = b ** 2 - 4 * c * a;
774
- if (delta < 0) {
775
- return;
776
- }
777
- const sqrtDelta = Math.sqrt(delta);
778
- const a2 = 2 * a;
779
- __privateMethod(this, _Util_static, getExtremumOnCurve_fn).call(this, x0, x1, x2, x3, y0, y1, y2, y3, (-b + sqrtDelta) / a2, minMax);
780
- __privateMethod(this, _Util_static, getExtremumOnCurve_fn).call(this, x0, x1, x2, x3, y0, y1, y2, y3, (-b - sqrtDelta) / a2, minMax);
781
- };
782
- __privateAdd(Util, _Util_static);
783
- var PDFStringTranslateTable = [
784
- 0,
785
- 0,
786
- 0,
787
- 0,
788
- 0,
789
- 0,
790
- 0,
791
- 0,
792
- 0,
793
- 0,
794
- 0,
795
- 0,
796
- 0,
797
- 0,
798
- 0,
799
- 0,
800
- 0,
801
- 0,
802
- 0,
803
- 0,
804
- 0,
805
- 0,
806
- 0,
807
- 0,
808
- 728,
809
- 711,
810
- 710,
811
- 729,
812
- 733,
813
- 731,
814
- 730,
815
- 732,
816
- 0,
817
- 0,
818
- 0,
819
- 0,
820
- 0,
821
- 0,
822
- 0,
823
- 0,
824
- 0,
825
- 0,
826
- 0,
827
- 0,
828
- 0,
829
- 0,
830
- 0,
831
- 0,
832
- 0,
833
- 0,
834
- 0,
835
- 0,
836
- 0,
837
- 0,
838
- 0,
839
- 0,
840
- 0,
841
- 0,
842
- 0,
843
- 0,
844
- 0,
845
- 0,
846
- 0,
847
- 0,
848
- 0,
849
- 0,
850
- 0,
851
- 0,
852
- 0,
853
- 0,
854
- 0,
855
- 0,
856
- 0,
857
- 0,
858
- 0,
859
- 0,
860
- 0,
861
- 0,
862
- 0,
863
- 0,
864
- 0,
865
- 0,
866
- 0,
867
- 0,
868
- 0,
869
- 0,
870
- 0,
871
- 0,
872
- 0,
873
- 0,
874
- 0,
875
- 0,
876
- 0,
877
- 0,
878
- 0,
879
- 0,
880
- 0,
881
- 0,
882
- 0,
883
- 0,
884
- 0,
885
- 0,
886
- 0,
887
- 0,
888
- 0,
889
- 0,
890
- 0,
891
- 0,
892
- 0,
893
- 0,
894
- 0,
895
- 0,
896
- 0,
897
- 0,
898
- 0,
899
- 0,
900
- 0,
901
- 0,
902
- 0,
903
- 0,
904
- 0,
905
- 0,
906
- 0,
907
- 0,
908
- 0,
909
- 0,
910
- 0,
911
- 0,
912
- 8226,
913
- 8224,
914
- 8225,
915
- 8230,
916
- 8212,
917
- 8211,
918
- 402,
919
- 8260,
920
- 8249,
921
- 8250,
922
- 8722,
923
- 8240,
924
- 8222,
925
- 8220,
926
- 8221,
927
- 8216,
928
- 8217,
929
- 8218,
930
- 8482,
931
- 64257,
932
- 64258,
933
- 321,
934
- 338,
935
- 352,
936
- 376,
937
- 381,
938
- 305,
939
- 322,
940
- 339,
941
- 353,
942
- 382,
943
- 0,
944
- 8364
945
- ];
946
- function stringToPDFString(str) {
947
- if (str[0] >= "\xEF") {
948
- let encoding;
949
- if (str[0] === "\xFE" && str[1] === "\xFF") {
950
- encoding = "utf-16be";
951
- if (str.length % 2 === 1) {
952
- str = str.slice(0, -1);
953
- }
954
- } else if (str[0] === "\xFF" && str[1] === "\xFE") {
955
- encoding = "utf-16le";
956
- if (str.length % 2 === 1) {
957
- str = str.slice(0, -1);
958
- }
959
- } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
960
- encoding = "utf-8";
961
- }
962
- if (encoding) {
963
- try {
964
- const decoder = new TextDecoder(encoding, { fatal: true });
965
- const buffer = stringToBytes(str);
966
- const decoded = decoder.decode(buffer);
967
- if (!decoded.includes("\x1B")) {
968
- return decoded;
969
- }
970
- return decoded.replaceAll(/\x1b[^\x1b]*(?:\x1b|$)/g, "");
971
- } catch (ex) {
972
- warn(`stringToPDFString: "${ex}".`);
973
- }
974
- }
975
- }
976
- const strBuf = [];
977
- for (let i = 0, ii = str.length; i < ii; i++) {
978
- const charCode = str.charCodeAt(i);
979
- if (charCode === 27) {
980
- while (++i < ii && str.charCodeAt(i) !== 27) {
981
- }
982
- continue;
983
- }
984
- const code = PDFStringTranslateTable[charCode];
985
- strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
986
- }
987
- return strBuf.join("");
988
- }
989
- function stringToUTF8String(str) {
990
- return decodeURIComponent(escape(str));
991
- }
992
- function utf8StringToString(str) {
993
- return unescape(encodeURIComponent(str));
994
- }
995
- function isArrayEqual(arr1, arr2) {
996
- if (arr1.length !== arr2.length) {
997
- return false;
998
- }
999
- for (let i = 0, ii = arr1.length; i < ii; i++) {
1000
- if (arr1[i] !== arr2[i]) {
1001
- return false;
1002
- }
1003
- }
1004
- return true;
1005
- }
1006
- function getModificationDate(date = /* @__PURE__ */ new Date()) {
1007
- const buffer = [
1008
- date.getUTCFullYear().toString(),
1009
- (date.getUTCMonth() + 1).toString().padStart(2, "0"),
1010
- date.getUTCDate().toString().padStart(2, "0"),
1011
- date.getUTCHours().toString().padStart(2, "0"),
1012
- date.getUTCMinutes().toString().padStart(2, "0"),
1013
- date.getUTCSeconds().toString().padStart(2, "0")
1014
- ];
1015
- return buffer.join("");
1016
- }
1017
- var NormalizeRegex = null;
1018
- var NormalizationMap = null;
1019
- function normalizeUnicode(str) {
1020
- if (!NormalizeRegex) {
1021
- NormalizeRegex = /([\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;
1022
- NormalizationMap = /* @__PURE__ */ new Map([["\uFB05", "\u017Ft"]]);
1023
- }
1024
- return str.replaceAll(
1025
- NormalizeRegex,
1026
- (_, p1, p2) => p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2)
1027
- );
1028
- }
1029
- function getUuid() {
1030
- if (typeof crypto.randomUUID === "function") {
1031
- return crypto.randomUUID();
1032
- }
1033
- const buf = new Uint8Array(32);
1034
- crypto.getRandomValues(buf);
1035
- return bytesToString(buf);
1036
- }
1037
- var AnnotationPrefix = "pdfjs_internal_id_";
1038
- function toHexUtil(arr) {
1039
- if (Uint8Array.prototype.toHex) {
1040
- return arr.toHex();
1041
- }
1042
- return Array.from(arr, (num) => hexNumbers[num]).join("");
1043
- }
1044
- function toBase64Util(arr) {
1045
- if (Uint8Array.prototype.toBase64) {
1046
- return arr.toBase64();
1047
- }
1048
- return btoa(bytesToString(arr));
1049
- }
1050
- function fromBase64Util(str) {
1051
- if (Uint8Array.fromBase64) {
1052
- return Uint8Array.fromBase64(str);
1053
- }
1054
- return stringToBytes(atob(str));
1055
- }
1056
- if (false) {
1057
- Promise.try = function(fn, ...args) {
1058
- return new Promise((resolve) => {
1059
- resolve(fn(...args));
1060
- });
1061
- };
1062
- }
1063
-
1064
- // src/pdf.js/src/shared/message_handler.js
1065
- var CallbackKind = {
1066
- DATA: 1,
1067
- ERROR: 2
1068
- };
1069
- var StreamKind = {
1070
- CANCEL: 1,
1071
- CANCEL_COMPLETE: 2,
1072
- CLOSE: 3,
1073
- ENQUEUE: 4,
1074
- ERROR: 5,
1075
- PULL: 6,
1076
- PULL_COMPLETE: 7,
1077
- START_COMPLETE: 8
1078
- };
1079
- function onFn() {
1080
- }
1081
- function wrapReason(ex) {
1082
- if (ex instanceof AbortException || ex instanceof InvalidPDFException || ex instanceof PasswordException || ex instanceof ResponseException || ex instanceof UnknownErrorException) {
1083
- return ex;
1084
- }
1085
- if (!(ex instanceof Error || typeof ex === "object" && ex !== null)) {
1086
- unreachable(
1087
- 'wrapReason: Expected "reason" to be a (possibly cloned) Error.'
1088
- );
1089
- }
1090
- switch (ex.name) {
1091
- case "AbortException":
1092
- return new AbortException(ex.message);
1093
- case "InvalidPDFException":
1094
- return new InvalidPDFException(ex.message);
1095
- case "PasswordException":
1096
- return new PasswordException(ex.message, ex.code);
1097
- case "ResponseException":
1098
- return new ResponseException(ex.message, ex.status, ex.missing);
1099
- case "UnknownErrorException":
1100
- return new UnknownErrorException(ex.message, ex.details);
1101
- }
1102
- return new UnknownErrorException(ex.message, ex.toString());
1103
- }
1104
- var _messageAC, _MessageHandler_instances, onMessage_fn, createStreamSink_fn, processStreamMessage_fn, deleteStreamController_fn;
1105
- var MessageHandler = class {
1106
- constructor(sourceName, targetName, comObj) {
1107
- __privateAdd(this, _MessageHandler_instances);
1108
- __privateAdd(this, _messageAC, new AbortController());
1109
- this.sourceName = sourceName;
1110
- this.targetName = targetName;
1111
- this.comObj = comObj;
1112
- this.callbackId = 1;
1113
- this.streamId = 1;
1114
- this.streamSinks = /* @__PURE__ */ Object.create(null);
1115
- this.streamControllers = /* @__PURE__ */ Object.create(null);
1116
- this.callbackCapabilities = /* @__PURE__ */ Object.create(null);
1117
- this.actionHandler = /* @__PURE__ */ Object.create(null);
1118
- comObj.addEventListener("message", __privateMethod(this, _MessageHandler_instances, onMessage_fn).bind(this), {
1119
- signal: __privateGet(this, _messageAC).signal
1120
- });
1121
- }
1122
- on(actionName, handler) {
1123
- if (false) {
1124
- assert(
1125
- typeof handler === "function",
1126
- 'MessageHandler.on: Expected "handler" to be a function.'
1127
- );
1128
- }
1129
- const ah = this.actionHandler;
1130
- if (ah[actionName]) {
1131
- throw new Error(`There is already an actionName called "${actionName}"`);
1132
- }
1133
- ah[actionName] = handler;
1134
- }
1135
- /**
1136
- * Sends a message to the comObj to invoke the action with the supplied data.
1137
- * @param {string} actionName - Action to call.
1138
- * @param {JSON} data - JSON data to send.
1139
- * @param {Array} [transfers] - List of transfers/ArrayBuffers.
1140
- */
1141
- send(actionName, data, transfers) {
1142
- this.comObj.postMessage(
1143
- {
1144
- sourceName: this.sourceName,
1145
- targetName: this.targetName,
1146
- action: actionName,
1147
- data
1148
- },
1149
- transfers
1150
- );
1151
- }
1152
- /**
1153
- * Sends a message to the comObj to invoke the action with the supplied data.
1154
- * Expects that the other side will callback with the response.
1155
- * @param {string} actionName - Action to call.
1156
- * @param {JSON} data - JSON data to send.
1157
- * @param {Array} [transfers] - List of transfers/ArrayBuffers.
1158
- * @returns {Promise} Promise to be resolved with response data.
1159
- */
1160
- sendWithPromise(actionName, data, transfers) {
1161
- const callbackId = this.callbackId++;
1162
- const capability = Promise.withResolvers();
1163
- this.callbackCapabilities[callbackId] = capability;
1164
- try {
1165
- this.comObj.postMessage(
1166
- {
1167
- sourceName: this.sourceName,
1168
- targetName: this.targetName,
1169
- action: actionName,
1170
- callbackId,
1171
- data
1172
- },
1173
- transfers
1174
- );
1175
- } catch (ex) {
1176
- capability.reject(ex);
1177
- }
1178
- return capability.promise;
1179
- }
1180
- /**
1181
- * Sends a message to the comObj to invoke the action with the supplied data.
1182
- * Expect that the other side will callback to signal 'start_complete'.
1183
- * @param {string} actionName - Action to call.
1184
- * @param {JSON} data - JSON data to send.
1185
- * @param {Object} queueingStrategy - Strategy to signal backpressure based on
1186
- * internal queue.
1187
- * @param {Array} [transfers] - List of transfers/ArrayBuffers.
1188
- * @returns {ReadableStream} ReadableStream to read data in chunks.
1189
- */
1190
- sendWithStream(actionName, data, queueingStrategy, transfers) {
1191
- const streamId = this.streamId++, sourceName = this.sourceName, targetName = this.targetName, comObj = this.comObj;
1192
- return new ReadableStream(
1193
- {
1194
- start: (controller) => {
1195
- const startCapability = Promise.withResolvers();
1196
- this.streamControllers[streamId] = {
1197
- controller,
1198
- startCall: startCapability,
1199
- pullCall: null,
1200
- cancelCall: null,
1201
- isClosed: false
1202
- };
1203
- comObj.postMessage(
1204
- {
1205
- sourceName,
1206
- targetName,
1207
- action: actionName,
1208
- streamId,
1209
- data,
1210
- desiredSize: controller.desiredSize
1211
- },
1212
- transfers
1213
- );
1214
- return startCapability.promise;
1215
- },
1216
- pull: (controller) => {
1217
- const pullCapability = Promise.withResolvers();
1218
- this.streamControllers[streamId].pullCall = pullCapability;
1219
- comObj.postMessage({
1220
- sourceName,
1221
- targetName,
1222
- stream: StreamKind.PULL,
1223
- streamId,
1224
- desiredSize: controller.desiredSize
1225
- });
1226
- return pullCapability.promise;
1227
- },
1228
- cancel: (reason) => {
1229
- assert(reason instanceof Error, "cancel must have a valid reason");
1230
- const cancelCapability = Promise.withResolvers();
1231
- this.streamControllers[streamId].cancelCall = cancelCapability;
1232
- this.streamControllers[streamId].isClosed = true;
1233
- comObj.postMessage({
1234
- sourceName,
1235
- targetName,
1236
- stream: StreamKind.CANCEL,
1237
- streamId,
1238
- reason: wrapReason(reason)
1239
- });
1240
- return cancelCapability.promise;
1241
- }
1242
- },
1243
- queueingStrategy
1244
- );
1245
- }
1246
- destroy() {
1247
- __privateGet(this, _messageAC)?.abort();
1248
- __privateSet(this, _messageAC, null);
1249
- }
1250
- };
1251
- _messageAC = new WeakMap();
1252
- _MessageHandler_instances = new WeakSet();
1253
- onMessage_fn = function({ data }) {
1254
- if (data.targetName !== this.sourceName) {
1255
- return;
1256
- }
1257
- if (data.stream) {
1258
- __privateMethod(this, _MessageHandler_instances, processStreamMessage_fn).call(this, data);
1259
- return;
1260
- }
1261
- if (data.callback) {
1262
- const callbackId = data.callbackId;
1263
- const capability = this.callbackCapabilities[callbackId];
1264
- if (!capability) {
1265
- throw new Error(`Cannot resolve callback ${callbackId}`);
1266
- }
1267
- delete this.callbackCapabilities[callbackId];
1268
- if (data.callback === CallbackKind.DATA) {
1269
- capability.resolve(data.data);
1270
- } else if (data.callback === CallbackKind.ERROR) {
1271
- capability.reject(wrapReason(data.reason));
1272
- } else {
1273
- throw new Error("Unexpected callback case");
1274
- }
1275
- return;
1276
- }
1277
- const action = this.actionHandler[data.action];
1278
- if (!action) {
1279
- throw new Error(`Unknown action from worker: ${data.action}`);
1280
- }
1281
- if (data.callbackId) {
1282
- const sourceName = this.sourceName, targetName = data.sourceName, comObj = this.comObj;
1283
- Promise.try(action, data.data).then(
1284
- function(result) {
1285
- comObj.postMessage({
1286
- sourceName,
1287
- targetName,
1288
- callback: CallbackKind.DATA,
1289
- callbackId: data.callbackId,
1290
- data: result
1291
- });
1292
- },
1293
- function(reason) {
1294
- comObj.postMessage({
1295
- sourceName,
1296
- targetName,
1297
- callback: CallbackKind.ERROR,
1298
- callbackId: data.callbackId,
1299
- reason: wrapReason(reason)
1300
- });
1301
- }
1302
- );
1303
- return;
1304
- }
1305
- if (data.streamId) {
1306
- __privateMethod(this, _MessageHandler_instances, createStreamSink_fn).call(this, data);
1307
- return;
1308
- }
1309
- action(data.data);
1310
- };
1311
- createStreamSink_fn = function(data) {
1312
- const streamId = data.streamId, sourceName = this.sourceName, targetName = data.sourceName, comObj = this.comObj;
1313
- const self = this, action = this.actionHandler[data.action];
1314
- const streamSink = {
1315
- enqueue(chunk, size = 1, transfers) {
1316
- if (this.isCancelled) {
1317
- return;
1318
- }
1319
- const lastDesiredSize = this.desiredSize;
1320
- this.desiredSize -= size;
1321
- if (lastDesiredSize > 0 && this.desiredSize <= 0) {
1322
- this.sinkCapability = Promise.withResolvers();
1323
- this.ready = this.sinkCapability.promise;
1324
- }
1325
- comObj.postMessage(
1326
- {
1327
- sourceName,
1328
- targetName,
1329
- stream: StreamKind.ENQUEUE,
1330
- streamId,
1331
- chunk
1332
- },
1333
- transfers
1334
- );
1335
- },
1336
- close() {
1337
- if (this.isCancelled) {
1338
- return;
1339
- }
1340
- this.isCancelled = true;
1341
- comObj.postMessage({
1342
- sourceName,
1343
- targetName,
1344
- stream: StreamKind.CLOSE,
1345
- streamId
1346
- });
1347
- delete self.streamSinks[streamId];
1348
- },
1349
- error(reason) {
1350
- assert(reason instanceof Error, "error must have a valid reason");
1351
- if (this.isCancelled) {
1352
- return;
1353
- }
1354
- this.isCancelled = true;
1355
- comObj.postMessage({
1356
- sourceName,
1357
- targetName,
1358
- stream: StreamKind.ERROR,
1359
- streamId,
1360
- reason: wrapReason(reason)
1361
- });
1362
- },
1363
- sinkCapability: Promise.withResolvers(),
1364
- onPull: null,
1365
- onCancel: null,
1366
- isCancelled: false,
1367
- desiredSize: data.desiredSize,
1368
- ready: null
1369
- };
1370
- streamSink.sinkCapability.resolve();
1371
- streamSink.ready = streamSink.sinkCapability.promise;
1372
- this.streamSinks[streamId] = streamSink;
1373
- Promise.try(action, data.data, streamSink).then(
1374
- function() {
1375
- comObj.postMessage({
1376
- sourceName,
1377
- targetName,
1378
- stream: StreamKind.START_COMPLETE,
1379
- streamId,
1380
- success: true
1381
- });
1382
- },
1383
- function(reason) {
1384
- comObj.postMessage({
1385
- sourceName,
1386
- targetName,
1387
- stream: StreamKind.START_COMPLETE,
1388
- streamId,
1389
- reason: wrapReason(reason)
1390
- });
1391
- }
1392
- );
1393
- };
1394
- processStreamMessage_fn = function(data) {
1395
- const streamId = data.streamId, sourceName = this.sourceName, targetName = data.sourceName, comObj = this.comObj;
1396
- const streamController = this.streamControllers[streamId], streamSink = this.streamSinks[streamId];
1397
- switch (data.stream) {
1398
- case StreamKind.START_COMPLETE:
1399
- if (data.success) {
1400
- streamController.startCall.resolve();
1401
- } else {
1402
- streamController.startCall.reject(wrapReason(data.reason));
1403
- }
1404
- break;
1405
- case StreamKind.PULL_COMPLETE:
1406
- if (data.success) {
1407
- streamController.pullCall.resolve();
1408
- } else {
1409
- streamController.pullCall.reject(wrapReason(data.reason));
1410
- }
1411
- break;
1412
- case StreamKind.PULL:
1413
- if (!streamSink) {
1414
- comObj.postMessage({
1415
- sourceName,
1416
- targetName,
1417
- stream: StreamKind.PULL_COMPLETE,
1418
- streamId,
1419
- success: true
1420
- });
1421
- break;
1422
- }
1423
- if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
1424
- streamSink.sinkCapability.resolve();
1425
- }
1426
- streamSink.desiredSize = data.desiredSize;
1427
- Promise.try(streamSink.onPull || onFn).then(
1428
- function() {
1429
- comObj.postMessage({
1430
- sourceName,
1431
- targetName,
1432
- stream: StreamKind.PULL_COMPLETE,
1433
- streamId,
1434
- success: true
1435
- });
1436
- },
1437
- function(reason) {
1438
- comObj.postMessage({
1439
- sourceName,
1440
- targetName,
1441
- stream: StreamKind.PULL_COMPLETE,
1442
- streamId,
1443
- reason: wrapReason(reason)
1444
- });
1445
- }
1446
- );
1447
- break;
1448
- case StreamKind.ENQUEUE:
1449
- assert(streamController, "enqueue should have stream controller");
1450
- if (streamController.isClosed) {
1451
- break;
1452
- }
1453
- streamController.controller.enqueue(data.chunk);
1454
- break;
1455
- case StreamKind.CLOSE:
1456
- assert(streamController, "close should have stream controller");
1457
- if (streamController.isClosed) {
1458
- break;
1459
- }
1460
- streamController.isClosed = true;
1461
- streamController.controller.close();
1462
- __privateMethod(this, _MessageHandler_instances, deleteStreamController_fn).call(this, streamController, streamId);
1463
- break;
1464
- case StreamKind.ERROR:
1465
- assert(streamController, "error should have stream controller");
1466
- streamController.controller.error(wrapReason(data.reason));
1467
- __privateMethod(this, _MessageHandler_instances, deleteStreamController_fn).call(this, streamController, streamId);
1468
- break;
1469
- case StreamKind.CANCEL_COMPLETE:
1470
- if (data.success) {
1471
- streamController.cancelCall.resolve();
1472
- } else {
1473
- streamController.cancelCall.reject(wrapReason(data.reason));
1474
- }
1475
- __privateMethod(this, _MessageHandler_instances, deleteStreamController_fn).call(this, streamController, streamId);
1476
- break;
1477
- case StreamKind.CANCEL:
1478
- if (!streamSink) {
1479
- break;
1480
- }
1481
- const dataReason = wrapReason(data.reason);
1482
- Promise.try(streamSink.onCancel || onFn, dataReason).then(
1483
- function() {
1484
- comObj.postMessage({
1485
- sourceName,
1486
- targetName,
1487
- stream: StreamKind.CANCEL_COMPLETE,
1488
- streamId,
1489
- success: true
1490
- });
1491
- },
1492
- function(reason) {
1493
- comObj.postMessage({
1494
- sourceName,
1495
- targetName,
1496
- stream: StreamKind.CANCEL_COMPLETE,
1497
- streamId,
1498
- reason: wrapReason(reason)
1499
- });
1500
- }
1501
- );
1502
- streamSink.sinkCapability.reject(dataReason);
1503
- streamSink.isCancelled = true;
1504
- delete this.streamSinks[streamId];
1505
- break;
1506
- default:
1507
- throw new Error("Unexpected stream case");
1508
- }
1509
- };
1510
- deleteStreamController_fn = async function(streamController, streamId) {
1511
- await Promise.allSettled([
1512
- streamController.startCall?.promise,
1513
- streamController.pullCall?.promise,
1514
- streamController.cancelCall?.promise
1515
- ]);
1516
- delete this.streamControllers[streamId];
1517
- };
1518
-
1519
- // src/pdf.js/src/shared/murmurhash3.js
1520
- var SEED = 3285377520;
1521
- var MASK_HIGH = 4294901760;
1522
- var MASK_LOW = 65535;
1523
- var MurmurHash3_64 = class {
1524
- constructor(seed) {
1525
- this.h1 = seed ? seed & 4294967295 : SEED;
1526
- this.h2 = seed ? seed & 4294967295 : SEED;
1527
- }
1528
- update(input) {
1529
- let data, length;
1530
- if (typeof input === "string") {
1531
- data = new Uint8Array(input.length * 2);
1532
- length = 0;
1533
- for (let i = 0, ii = input.length; i < ii; i++) {
1534
- const code = input.charCodeAt(i);
1535
- if (code <= 255) {
1536
- data[length++] = code;
1537
- } else {
1538
- data[length++] = code >>> 8;
1539
- data[length++] = code & 255;
1540
- }
1541
- }
1542
- } else if (ArrayBuffer.isView(input)) {
1543
- data = input.slice();
1544
- length = data.byteLength;
1545
- } else {
1546
- throw new Error("Invalid data format, must be a string or TypedArray.");
1547
- }
1548
- const blockCounts = length >> 2;
1549
- const tailLength = length - blockCounts * 4;
1550
- const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
1551
- let k1 = 0, k2 = 0;
1552
- let h1 = this.h1, h2 = this.h2;
1553
- const C1 = 3432918353, C2 = 461845907;
1554
- const C1_LOW = C1 & MASK_LOW, C2_LOW = C2 & MASK_LOW;
1555
- for (let i = 0; i < blockCounts; i++) {
1556
- if (i & 1) {
1557
- k1 = dataUint32[i];
1558
- k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
1559
- k1 = k1 << 15 | k1 >>> 17;
1560
- k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
1561
- h1 ^= k1;
1562
- h1 = h1 << 13 | h1 >>> 19;
1563
- h1 = h1 * 5 + 3864292196;
1564
- } else {
1565
- k2 = dataUint32[i];
1566
- k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
1567
- k2 = k2 << 15 | k2 >>> 17;
1568
- k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
1569
- h2 ^= k2;
1570
- h2 = h2 << 13 | h2 >>> 19;
1571
- h2 = h2 * 5 + 3864292196;
1572
- }
1573
- }
1574
- k1 = 0;
1575
- switch (tailLength) {
1576
- case 3:
1577
- k1 ^= data[blockCounts * 4 + 2] << 16;
1578
- /* falls through */
1579
- case 2:
1580
- k1 ^= data[blockCounts * 4 + 1] << 8;
1581
- /* falls through */
1582
- case 1:
1583
- k1 ^= data[blockCounts * 4];
1584
- k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
1585
- k1 = k1 << 15 | k1 >>> 17;
1586
- k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
1587
- if (blockCounts & 1) {
1588
- h1 ^= k1;
1589
- } else {
1590
- h2 ^= k1;
1591
- }
1592
- }
1593
- this.h1 = h1;
1594
- this.h2 = h2;
1595
- }
1596
- hexdigest() {
1597
- let h1 = this.h1, h2 = this.h2;
1598
- h1 ^= h2 >>> 1;
1599
- h1 = h1 * 3981806797 & MASK_HIGH | h1 * 36045 & MASK_LOW;
1600
- h2 = h2 * 4283543511 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 2950163797 & MASK_HIGH) >>> 16;
1601
- h1 ^= h2 >>> 1;
1602
- h1 = h1 * 444984403 & MASK_HIGH | h1 * 60499 & MASK_LOW;
1603
- h2 = h2 * 3301882366 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 3120437893 & MASK_HIGH) >>> 16;
1604
- h1 ^= h2 >>> 1;
1605
- return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
1606
- }
1607
- };
1608
-
1609
- // src/pdf.js/src/shared/image_utils.js
1610
- function convertToRGBA(params) {
1611
- switch (params.kind) {
1612
- case ImageKind.GRAYSCALE_1BPP:
1613
- return convertBlackAndWhiteToRGBA(params);
1614
- case ImageKind.RGB_24BPP:
1615
- return convertRGBToRGBA(params);
1616
- }
1617
- return null;
1618
- }
1619
- function convertBlackAndWhiteToRGBA({
1620
- src,
1621
- srcPos = 0,
1622
- dest,
1623
- width,
1624
- height,
1625
- nonBlackColor = 4294967295,
1626
- inverseDecode = false
1627
- }) {
1628
- const black = FeatureTest.isLittleEndian ? 4278190080 : 255;
1629
- const [zeroMapping, oneMapping] = inverseDecode ? [nonBlackColor, black] : [black, nonBlackColor];
1630
- const widthInSource = width >> 3;
1631
- const widthRemainder = width & 7;
1632
- const srcLength = src.length;
1633
- dest = new Uint32Array(dest.buffer);
1634
- let destPos = 0;
1635
- for (let i = 0; i < height; i++) {
1636
- for (const max = srcPos + widthInSource; srcPos < max; srcPos++) {
1637
- const elem2 = srcPos < srcLength ? src[srcPos] : 255;
1638
- dest[destPos++] = elem2 & 128 ? oneMapping : zeroMapping;
1639
- dest[destPos++] = elem2 & 64 ? oneMapping : zeroMapping;
1640
- dest[destPos++] = elem2 & 32 ? oneMapping : zeroMapping;
1641
- dest[destPos++] = elem2 & 16 ? oneMapping : zeroMapping;
1642
- dest[destPos++] = elem2 & 8 ? oneMapping : zeroMapping;
1643
- dest[destPos++] = elem2 & 4 ? oneMapping : zeroMapping;
1644
- dest[destPos++] = elem2 & 2 ? oneMapping : zeroMapping;
1645
- dest[destPos++] = elem2 & 1 ? oneMapping : zeroMapping;
1646
- }
1647
- if (widthRemainder === 0) {
1648
- continue;
1649
- }
1650
- const elem = srcPos < srcLength ? src[srcPos++] : 255;
1651
- for (let j = 0; j < widthRemainder; j++) {
1652
- dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
1653
- }
1654
- }
1655
- return { srcPos, destPos };
1656
- }
1657
- function convertRGBToRGBA({
1658
- src,
1659
- srcPos = 0,
1660
- dest,
1661
- destPos = 0,
1662
- width,
1663
- height
1664
- }) {
1665
- let i = 0;
1666
- const len = width * height * 3;
1667
- const len32 = len >> 2;
1668
- const src32 = new Uint32Array(src.buffer, srcPos, len32);
1669
- if (FeatureTest.isLittleEndian) {
1670
- for (; i < len32 - 2; i += 3, destPos += 4) {
1671
- const s1 = src32[i];
1672
- const s2 = src32[i + 1];
1673
- const s3 = src32[i + 2];
1674
- dest[destPos] = s1 | 4278190080;
1675
- dest[destPos + 1] = s1 >>> 24 | s2 << 8 | 4278190080;
1676
- dest[destPos + 2] = s2 >>> 16 | s3 << 16 | 4278190080;
1677
- dest[destPos + 3] = s3 >>> 8 | 4278190080;
1678
- }
1679
- for (let j = i * 4, jj = srcPos + len; j < jj; j += 3) {
1680
- dest[destPos++] = src[j] | src[j + 1] << 8 | src[j + 2] << 16 | 4278190080;
1681
- }
1682
- } else {
1683
- for (; i < len32 - 2; i += 3, destPos += 4) {
1684
- const s1 = src32[i];
1685
- const s2 = src32[i + 1];
1686
- const s3 = src32[i + 2];
1687
- dest[destPos] = s1 | 255;
1688
- dest[destPos + 1] = s1 << 24 | s2 >>> 8 | 255;
1689
- dest[destPos + 2] = s2 << 16 | s3 >>> 16 | 255;
1690
- dest[destPos + 3] = s3 << 8 | 255;
1691
- }
1692
- for (let j = i * 4, jj = srcPos + len; j < jj; j += 3) {
1693
- dest[destPos++] = src[j] << 24 | src[j + 1] << 16 | src[j + 2] << 8 | 255;
1694
- }
1695
- }
1696
- return { srcPos: srcPos + len, destPos };
1697
- }
1698
- function grayToRGBA(src, dest) {
1699
- if (FeatureTest.isLittleEndian) {
1700
- for (let i = 0, ii = src.length; i < ii; i++) {
1701
- dest[i] = src[i] * 65793 | 4278190080;
1702
- }
1703
- } else {
1704
- for (let i = 0, ii = src.length; i < ii; i++) {
1705
- dest[i] = src[i] * 16843008 | 255;
1706
- }
1707
- }
1708
- }
1709
-
1710
- export {
1711
- isNodeJS,
1712
- IDENTITY_MATRIX,
1713
- FONT_IDENTITY_MATRIX,
1714
- LINE_FACTOR,
1715
- LINE_DESCENT_FACTOR,
1716
- BASELINE_FACTOR,
1717
- RenderingIntentFlag,
1718
- AnnotationMode,
1719
- AnnotationEditorPrefix,
1720
- AnnotationEditorType,
1721
- AnnotationEditorParamsType,
1722
- PermissionFlag,
1723
- TextRenderingMode,
1724
- ImageKind,
1725
- AnnotationType,
1726
- AnnotationReplyType,
1727
- AnnotationFlag,
1728
- AnnotationFieldFlag,
1729
- AnnotationBorderStyleType,
1730
- AnnotationActionEventType,
1731
- DocumentActionEventType,
1732
- PageActionEventType,
1733
- VerbosityLevel,
1734
- OPS,
1735
- PasswordResponses,
1736
- setVerbosityLevel,
1737
- getVerbosityLevel,
1738
- info,
1739
- warn,
1740
- unreachable,
1741
- assert,
1742
- createValidAbsoluteUrl,
1743
- shadow,
1744
- BaseException,
1745
- PasswordException,
1746
- InvalidPDFException,
1747
- ResponseException,
1748
- FormatError,
1749
- AbortException,
1750
- bytesToString,
1751
- stringToBytes,
1752
- string32,
1753
- objectSize,
1754
- objectFromMap,
1755
- FeatureTest,
1756
- hexNumbers,
1757
- Util,
1758
- stringToPDFString,
1759
- stringToUTF8String,
1760
- utf8StringToString,
1761
- isArrayEqual,
1762
- getModificationDate,
1763
- normalizeUnicode,
1764
- getUuid,
1765
- AnnotationPrefix,
1766
- toHexUtil,
1767
- toBase64Util,
1768
- fromBase64Util,
1769
- MurmurHash3_64,
1770
- wrapReason,
1771
- MessageHandler,
1772
- convertToRGBA,
1773
- convertBlackAndWhiteToRGBA,
1774
- grayToRGBA
1775
- };