1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | (function webpackUniversalModuleDefinition(root, factory) {
|
24 | if(typeof exports === 'object' && typeof module === 'object')
|
25 | module.exports = factory();
|
26 | else if(typeof define === 'function' && define.amd)
|
27 | define("pdfjs-dist/build/pdf", [], factory);
|
28 | else if(typeof exports === 'object')
|
29 | exports["pdfjs-dist/build/pdf"] = factory();
|
30 | else
|
31 | root["pdfjs-dist/build/pdf"] = root.pdfjsLib = factory();
|
32 | })(globalThis, () => {
|
33 | return (() => {
|
34 | "use strict";
|
35 | var __webpack_modules__ = ([
|
36 | ,
|
37 |
|
38 | ((__unused_webpack_module, exports) => {
|
39 |
|
40 |
|
41 |
|
42 | Object.defineProperty(exports, "__esModule", ({
|
43 | value: true
|
44 | }));
|
45 | exports.VerbosityLevel = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.RenderingIntentFlag = exports.PromiseCapability = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.MAX_IMAGE_SIZE_TO_CACHE = exports.LINE_FACTOR = exports.LINE_DESCENT_FACTOR = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FeatureTest = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.CMapCompressionType = exports.BaseException = exports.BASELINE_FACTOR = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMode = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationEditorType = exports.AnnotationEditorPrefix = exports.AnnotationEditorParamsType = exports.AnnotationBorderStyleType = exports.AnnotationActionEventType = exports.AbortException = void 0;
|
46 | exports.assert = assert;
|
47 | exports.bytesToString = bytesToString;
|
48 | exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
|
49 | exports.getModificationDate = getModificationDate;
|
50 | exports.getVerbosityLevel = getVerbosityLevel;
|
51 | exports.info = info;
|
52 | exports.isArrayBuffer = isArrayBuffer;
|
53 | exports.isArrayEqual = isArrayEqual;
|
54 | exports.normalizeUnicode = normalizeUnicode;
|
55 | exports.objectFromMap = objectFromMap;
|
56 | exports.objectSize = objectSize;
|
57 | exports.setVerbosityLevel = setVerbosityLevel;
|
58 | exports.shadow = shadow;
|
59 | exports.string32 = string32;
|
60 | exports.stringToBytes = stringToBytes;
|
61 | exports.stringToPDFString = stringToPDFString;
|
62 | exports.stringToUTF8String = stringToUTF8String;
|
63 | exports.unreachable = unreachable;
|
64 | exports.utf8StringToString = utf8StringToString;
|
65 | exports.warn = warn;
|
66 | ;
|
67 | const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
|
68 | exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
|
69 | const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
|
70 | exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
|
71 | const MAX_IMAGE_SIZE_TO_CACHE = 10e6;
|
72 | exports.MAX_IMAGE_SIZE_TO_CACHE = MAX_IMAGE_SIZE_TO_CACHE;
|
73 | const LINE_FACTOR = 1.35;
|
74 | exports.LINE_FACTOR = LINE_FACTOR;
|
75 | const LINE_DESCENT_FACTOR = 0.35;
|
76 | exports.LINE_DESCENT_FACTOR = LINE_DESCENT_FACTOR;
|
77 | const BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
|
78 | exports.BASELINE_FACTOR = BASELINE_FACTOR;
|
79 | const RenderingIntentFlag = {
|
80 | ANY: 0x01,
|
81 | DISPLAY: 0x02,
|
82 | PRINT: 0x04,
|
83 | SAVE: 0x08,
|
84 | ANNOTATIONS_FORMS: 0x10,
|
85 | ANNOTATIONS_STORAGE: 0x20,
|
86 | ANNOTATIONS_DISABLE: 0x40,
|
87 | OPLIST: 0x100
|
88 | };
|
89 | exports.RenderingIntentFlag = RenderingIntentFlag;
|
90 | const AnnotationMode = {
|
91 | DISABLE: 0,
|
92 | ENABLE: 1,
|
93 | ENABLE_FORMS: 2,
|
94 | ENABLE_STORAGE: 3
|
95 | };
|
96 | exports.AnnotationMode = AnnotationMode;
|
97 | const AnnotationEditorPrefix = "pdfjs_internal_editor_";
|
98 | exports.AnnotationEditorPrefix = AnnotationEditorPrefix;
|
99 | const AnnotationEditorType = {
|
100 | DISABLE: -1,
|
101 | NONE: 0,
|
102 | FREETEXT: 3,
|
103 | INK: 15
|
104 | };
|
105 | exports.AnnotationEditorType = AnnotationEditorType;
|
106 | const AnnotationEditorParamsType = {
|
107 | FREETEXT_SIZE: 1,
|
108 | FREETEXT_COLOR: 2,
|
109 | FREETEXT_OPACITY: 3,
|
110 | INK_COLOR: 11,
|
111 | INK_THICKNESS: 12,
|
112 | INK_OPACITY: 13
|
113 | };
|
114 | exports.AnnotationEditorParamsType = AnnotationEditorParamsType;
|
115 | const PermissionFlag = {
|
116 | PRINT: 0x04,
|
117 | MODIFY_CONTENTS: 0x08,
|
118 | COPY: 0x10,
|
119 | MODIFY_ANNOTATIONS: 0x20,
|
120 | FILL_INTERACTIVE_FORMS: 0x100,
|
121 | COPY_FOR_ACCESSIBILITY: 0x200,
|
122 | ASSEMBLE: 0x400,
|
123 | PRINT_HIGH_QUALITY: 0x800
|
124 | };
|
125 | exports.PermissionFlag = PermissionFlag;
|
126 | const TextRenderingMode = {
|
127 | FILL: 0,
|
128 | STROKE: 1,
|
129 | FILL_STROKE: 2,
|
130 | INVISIBLE: 3,
|
131 | FILL_ADD_TO_PATH: 4,
|
132 | STROKE_ADD_TO_PATH: 5,
|
133 | FILL_STROKE_ADD_TO_PATH: 6,
|
134 | ADD_TO_PATH: 7,
|
135 | FILL_STROKE_MASK: 3,
|
136 | ADD_TO_PATH_FLAG: 4
|
137 | };
|
138 | exports.TextRenderingMode = TextRenderingMode;
|
139 | const ImageKind = {
|
140 | GRAYSCALE_1BPP: 1,
|
141 | RGB_24BPP: 2,
|
142 | RGBA_32BPP: 3
|
143 | };
|
144 | exports.ImageKind = ImageKind;
|
145 | const AnnotationType = {
|
146 | TEXT: 1,
|
147 | LINK: 2,
|
148 | FREETEXT: 3,
|
149 | LINE: 4,
|
150 | SQUARE: 5,
|
151 | CIRCLE: 6,
|
152 | POLYGON: 7,
|
153 | POLYLINE: 8,
|
154 | HIGHLIGHT: 9,
|
155 | UNDERLINE: 10,
|
156 | SQUIGGLY: 11,
|
157 | STRIKEOUT: 12,
|
158 | STAMP: 13,
|
159 | CARET: 14,
|
160 | INK: 15,
|
161 | POPUP: 16,
|
162 | FILEATTACHMENT: 17,
|
163 | SOUND: 18,
|
164 | MOVIE: 19,
|
165 | WIDGET: 20,
|
166 | SCREEN: 21,
|
167 | PRINTERMARK: 22,
|
168 | TRAPNET: 23,
|
169 | WATERMARK: 24,
|
170 | THREED: 25,
|
171 | REDACT: 26
|
172 | };
|
173 | exports.AnnotationType = AnnotationType;
|
174 | const AnnotationStateModelType = {
|
175 | MARKED: "Marked",
|
176 | REVIEW: "Review"
|
177 | };
|
178 | exports.AnnotationStateModelType = AnnotationStateModelType;
|
179 | const AnnotationMarkedState = {
|
180 | MARKED: "Marked",
|
181 | UNMARKED: "Unmarked"
|
182 | };
|
183 | exports.AnnotationMarkedState = AnnotationMarkedState;
|
184 | const AnnotationReviewState = {
|
185 | ACCEPTED: "Accepted",
|
186 | REJECTED: "Rejected",
|
187 | CANCELLED: "Cancelled",
|
188 | COMPLETED: "Completed",
|
189 | NONE: "None"
|
190 | };
|
191 | exports.AnnotationReviewState = AnnotationReviewState;
|
192 | const AnnotationReplyType = {
|
193 | GROUP: "Group",
|
194 | REPLY: "R"
|
195 | };
|
196 | exports.AnnotationReplyType = AnnotationReplyType;
|
197 | const AnnotationFlag = {
|
198 | INVISIBLE: 0x01,
|
199 | HIDDEN: 0x02,
|
200 | PRINT: 0x04,
|
201 | NOZOOM: 0x08,
|
202 | NOROTATE: 0x10,
|
203 | NOVIEW: 0x20,
|
204 | READONLY: 0x40,
|
205 | LOCKED: 0x80,
|
206 | TOGGLENOVIEW: 0x100,
|
207 | LOCKEDCONTENTS: 0x200
|
208 | };
|
209 | exports.AnnotationFlag = AnnotationFlag;
|
210 | const AnnotationFieldFlag = {
|
211 | READONLY: 0x0000001,
|
212 | REQUIRED: 0x0000002,
|
213 | NOEXPORT: 0x0000004,
|
214 | MULTILINE: 0x0001000,
|
215 | PASSWORD: 0x0002000,
|
216 | NOTOGGLETOOFF: 0x0004000,
|
217 | RADIO: 0x0008000,
|
218 | PUSHBUTTON: 0x0010000,
|
219 | COMBO: 0x0020000,
|
220 | EDIT: 0x0040000,
|
221 | SORT: 0x0080000,
|
222 | FILESELECT: 0x0100000,
|
223 | MULTISELECT: 0x0200000,
|
224 | DONOTSPELLCHECK: 0x0400000,
|
225 | DONOTSCROLL: 0x0800000,
|
226 | COMB: 0x1000000,
|
227 | RICHTEXT: 0x2000000,
|
228 | RADIOSINUNISON: 0x2000000,
|
229 | COMMITONSELCHANGE: 0x4000000
|
230 | };
|
231 | exports.AnnotationFieldFlag = AnnotationFieldFlag;
|
232 | const AnnotationBorderStyleType = {
|
233 | SOLID: 1,
|
234 | DASHED: 2,
|
235 | BEVELED: 3,
|
236 | INSET: 4,
|
237 | UNDERLINE: 5
|
238 | };
|
239 | exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
|
240 | const AnnotationActionEventType = {
|
241 | E: "Mouse Enter",
|
242 | X: "Mouse Exit",
|
243 | D: "Mouse Down",
|
244 | U: "Mouse Up",
|
245 | Fo: "Focus",
|
246 | Bl: "Blur",
|
247 | PO: "PageOpen",
|
248 | PC: "PageClose",
|
249 | PV: "PageVisible",
|
250 | PI: "PageInvisible",
|
251 | K: "Keystroke",
|
252 | F: "Format",
|
253 | V: "Validate",
|
254 | C: "Calculate"
|
255 | };
|
256 | exports.AnnotationActionEventType = AnnotationActionEventType;
|
257 | const DocumentActionEventType = {
|
258 | WC: "WillClose",
|
259 | WS: "WillSave",
|
260 | DS: "DidSave",
|
261 | WP: "WillPrint",
|
262 | DP: "DidPrint"
|
263 | };
|
264 | exports.DocumentActionEventType = DocumentActionEventType;
|
265 | const PageActionEventType = {
|
266 | O: "PageOpen",
|
267 | C: "PageClose"
|
268 | };
|
269 | exports.PageActionEventType = PageActionEventType;
|
270 | const VerbosityLevel = {
|
271 | ERRORS: 0,
|
272 | WARNINGS: 1,
|
273 | INFOS: 5
|
274 | };
|
275 | exports.VerbosityLevel = VerbosityLevel;
|
276 | const CMapCompressionType = {
|
277 | NONE: 0,
|
278 | BINARY: 1
|
279 | };
|
280 | exports.CMapCompressionType = CMapCompressionType;
|
281 | const OPS = {
|
282 | dependency: 1,
|
283 | setLineWidth: 2,
|
284 | setLineCap: 3,
|
285 | setLineJoin: 4,
|
286 | setMiterLimit: 5,
|
287 | setDash: 6,
|
288 | setRenderingIntent: 7,
|
289 | setFlatness: 8,
|
290 | setGState: 9,
|
291 | save: 10,
|
292 | restore: 11,
|
293 | transform: 12,
|
294 | moveTo: 13,
|
295 | lineTo: 14,
|
296 | curveTo: 15,
|
297 | curveTo2: 16,
|
298 | curveTo3: 17,
|
299 | closePath: 18,
|
300 | rectangle: 19,
|
301 | stroke: 20,
|
302 | closeStroke: 21,
|
303 | fill: 22,
|
304 | eoFill: 23,
|
305 | fillStroke: 24,
|
306 | eoFillStroke: 25,
|
307 | closeFillStroke: 26,
|
308 | closeEOFillStroke: 27,
|
309 | endPath: 28,
|
310 | clip: 29,
|
311 | eoClip: 30,
|
312 | beginText: 31,
|
313 | endText: 32,
|
314 | setCharSpacing: 33,
|
315 | setWordSpacing: 34,
|
316 | setHScale: 35,
|
317 | setLeading: 36,
|
318 | setFont: 37,
|
319 | setTextRenderingMode: 38,
|
320 | setTextRise: 39,
|
321 | moveText: 40,
|
322 | setLeadingMoveText: 41,
|
323 | setTextMatrix: 42,
|
324 | nextLine: 43,
|
325 | showText: 44,
|
326 | showSpacedText: 45,
|
327 | nextLineShowText: 46,
|
328 | nextLineSetSpacingShowText: 47,
|
329 | setCharWidth: 48,
|
330 | setCharWidthAndBounds: 49,
|
331 | setStrokeColorSpace: 50,
|
332 | setFillColorSpace: 51,
|
333 | setStrokeColor: 52,
|
334 | setStrokeColorN: 53,
|
335 | setFillColor: 54,
|
336 | setFillColorN: 55,
|
337 | setStrokeGray: 56,
|
338 | setFillGray: 57,
|
339 | setStrokeRGBColor: 58,
|
340 | setFillRGBColor: 59,
|
341 | setStrokeCMYKColor: 60,
|
342 | setFillCMYKColor: 61,
|
343 | shadingFill: 62,
|
344 | beginInlineImage: 63,
|
345 | beginImageData: 64,
|
346 | endInlineImage: 65,
|
347 | paintXObject: 66,
|
348 | markPoint: 67,
|
349 | markPointProps: 68,
|
350 | beginMarkedContent: 69,
|
351 | beginMarkedContentProps: 70,
|
352 | endMarkedContent: 71,
|
353 | beginCompat: 72,
|
354 | endCompat: 73,
|
355 | paintFormXObjectBegin: 74,
|
356 | paintFormXObjectEnd: 75,
|
357 | beginGroup: 76,
|
358 | endGroup: 77,
|
359 | beginAnnotation: 80,
|
360 | endAnnotation: 81,
|
361 | paintImageMaskXObject: 83,
|
362 | paintImageMaskXObjectGroup: 84,
|
363 | paintImageXObject: 85,
|
364 | paintInlineImageXObject: 86,
|
365 | paintInlineImageXObjectGroup: 87,
|
366 | paintImageXObjectRepeat: 88,
|
367 | paintImageMaskXObjectRepeat: 89,
|
368 | paintSolidColorImageMask: 90,
|
369 | constructPath: 91
|
370 | };
|
371 | exports.OPS = OPS;
|
372 | const PasswordResponses = {
|
373 | NEED_PASSWORD: 1,
|
374 | INCORRECT_PASSWORD: 2
|
375 | };
|
376 | exports.PasswordResponses = PasswordResponses;
|
377 | let verbosity = VerbosityLevel.WARNINGS;
|
378 | function setVerbosityLevel(level) {
|
379 | if (Number.isInteger(level)) {
|
380 | verbosity = level;
|
381 | }
|
382 | }
|
383 | function getVerbosityLevel() {
|
384 | return verbosity;
|
385 | }
|
386 | function info(msg) {
|
387 | if (verbosity >= VerbosityLevel.INFOS) {
|
388 | console.log(`Info: ${msg}`);
|
389 | }
|
390 | }
|
391 | function warn(msg) {
|
392 | if (verbosity >= VerbosityLevel.WARNINGS) {
|
393 | console.log(`Warning: ${msg}`);
|
394 | }
|
395 | }
|
396 | function unreachable(msg) {
|
397 | throw new Error(msg);
|
398 | }
|
399 | function assert(cond, msg) {
|
400 | if (!cond) {
|
401 | unreachable(msg);
|
402 | }
|
403 | }
|
404 | function _isValidProtocol(url) {
|
405 | switch (url?.protocol) {
|
406 | case "http:":
|
407 | case "https:":
|
408 | case "ftp:":
|
409 | case "mailto:":
|
410 | case "tel:":
|
411 | return true;
|
412 | default:
|
413 | return false;
|
414 | }
|
415 | }
|
416 | function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
|
417 | if (!url) {
|
418 | return null;
|
419 | }
|
420 | try {
|
421 | if (options && typeof url === "string") {
|
422 | if (options.addDefaultProtocol && url.startsWith("www.")) {
|
423 | const dots = url.match(/\./g);
|
424 | if (dots?.length >= 2) {
|
425 | url = `http://${url}`;
|
426 | }
|
427 | }
|
428 | if (options.tryConvertEncoding) {
|
429 | try {
|
430 | url = stringToUTF8String(url);
|
431 | } catch (ex) {}
|
432 | }
|
433 | }
|
434 | const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
|
435 | if (_isValidProtocol(absoluteUrl)) {
|
436 | return absoluteUrl;
|
437 | }
|
438 | } catch (ex) {}
|
439 | return null;
|
440 | }
|
441 | function shadow(obj, prop, value, nonSerializable = false) {
|
442 | Object.defineProperty(obj, prop, {
|
443 | value,
|
444 | enumerable: !nonSerializable,
|
445 | configurable: true,
|
446 | writable: false
|
447 | });
|
448 | return value;
|
449 | }
|
450 | const BaseException = function BaseExceptionClosure() {
|
451 | function BaseException(message, name) {
|
452 | if (this.constructor === BaseException) {
|
453 | unreachable("Cannot initialize BaseException.");
|
454 | }
|
455 | this.message = message;
|
456 | this.name = name;
|
457 | }
|
458 | BaseException.prototype = new Error();
|
459 | BaseException.constructor = BaseException;
|
460 | return BaseException;
|
461 | }();
|
462 | exports.BaseException = BaseException;
|
463 | class PasswordException extends BaseException {
|
464 | constructor(msg, code) {
|
465 | super(msg, "PasswordException");
|
466 | this.code = code;
|
467 | }
|
468 | }
|
469 | exports.PasswordException = PasswordException;
|
470 | class UnknownErrorException extends BaseException {
|
471 | constructor(msg, details) {
|
472 | super(msg, "UnknownErrorException");
|
473 | this.details = details;
|
474 | }
|
475 | }
|
476 | exports.UnknownErrorException = UnknownErrorException;
|
477 | class InvalidPDFException extends BaseException {
|
478 | constructor(msg) {
|
479 | super(msg, "InvalidPDFException");
|
480 | }
|
481 | }
|
482 | exports.InvalidPDFException = InvalidPDFException;
|
483 | class MissingPDFException extends BaseException {
|
484 | constructor(msg) {
|
485 | super(msg, "MissingPDFException");
|
486 | }
|
487 | }
|
488 | exports.MissingPDFException = MissingPDFException;
|
489 | class UnexpectedResponseException extends BaseException {
|
490 | constructor(msg, status) {
|
491 | super(msg, "UnexpectedResponseException");
|
492 | this.status = status;
|
493 | }
|
494 | }
|
495 | exports.UnexpectedResponseException = UnexpectedResponseException;
|
496 | class FormatError extends BaseException {
|
497 | constructor(msg) {
|
498 | super(msg, "FormatError");
|
499 | }
|
500 | }
|
501 | exports.FormatError = FormatError;
|
502 | class AbortException extends BaseException {
|
503 | constructor(msg) {
|
504 | super(msg, "AbortException");
|
505 | }
|
506 | }
|
507 | exports.AbortException = AbortException;
|
508 | function bytesToString(bytes) {
|
509 | if (typeof bytes !== "object" || bytes?.length === undefined) {
|
510 | unreachable("Invalid argument for bytesToString");
|
511 | }
|
512 | const length = bytes.length;
|
513 | const MAX_ARGUMENT_COUNT = 8192;
|
514 | if (length < MAX_ARGUMENT_COUNT) {
|
515 | return String.fromCharCode.apply(null, bytes);
|
516 | }
|
517 | const strBuf = [];
|
518 | for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
|
519 | const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
|
520 | const chunk = bytes.subarray(i, chunkEnd);
|
521 | strBuf.push(String.fromCharCode.apply(null, chunk));
|
522 | }
|
523 | return strBuf.join("");
|
524 | }
|
525 | function stringToBytes(str) {
|
526 | if (typeof str !== "string") {
|
527 | unreachable("Invalid argument for stringToBytes");
|
528 | }
|
529 | const length = str.length;
|
530 | const bytes = new Uint8Array(length);
|
531 | for (let i = 0; i < length; ++i) {
|
532 | bytes[i] = str.charCodeAt(i) & 0xff;
|
533 | }
|
534 | return bytes;
|
535 | }
|
536 | function string32(value) {
|
537 | return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
|
538 | }
|
539 | function objectSize(obj) {
|
540 | return Object.keys(obj).length;
|
541 | }
|
542 | function objectFromMap(map) {
|
543 | const obj = Object.create(null);
|
544 | for (const [key, value] of map) {
|
545 | obj[key] = value;
|
546 | }
|
547 | return obj;
|
548 | }
|
549 | function isLittleEndian() {
|
550 | const buffer8 = new Uint8Array(4);
|
551 | buffer8[0] = 1;
|
552 | const view32 = new Uint32Array(buffer8.buffer, 0, 1);
|
553 | return view32[0] === 1;
|
554 | }
|
555 | function isEvalSupported() {
|
556 | try {
|
557 | new Function("");
|
558 | return true;
|
559 | } catch (e) {
|
560 | return false;
|
561 | }
|
562 | }
|
563 | class FeatureTest {
|
564 | static get isLittleEndian() {
|
565 | return shadow(this, "isLittleEndian", isLittleEndian());
|
566 | }
|
567 | static get isEvalSupported() {
|
568 | return shadow(this, "isEvalSupported", isEvalSupported());
|
569 | }
|
570 | static get isOffscreenCanvasSupported() {
|
571 | return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
|
572 | }
|
573 | static get platform() {
|
574 | if (typeof navigator === "undefined") {
|
575 | return shadow(this, "platform", {
|
576 | isWin: false,
|
577 | isMac: false
|
578 | });
|
579 | }
|
580 | return shadow(this, "platform", {
|
581 | isWin: navigator.platform.includes("Win"),
|
582 | isMac: navigator.platform.includes("Mac")
|
583 | });
|
584 | }
|
585 | }
|
586 | exports.FeatureTest = FeatureTest;
|
587 | const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
|
588 | class Util {
|
589 | static makeHexColor(r, g, b) {
|
590 | return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
|
591 | }
|
592 | static scaleMinMax(transform, minMax) {
|
593 | let temp;
|
594 | if (transform[0]) {
|
595 | if (transform[0] < 0) {
|
596 | temp = minMax[0];
|
597 | minMax[0] = minMax[1];
|
598 | minMax[1] = temp;
|
599 | }
|
600 | minMax[0] *= transform[0];
|
601 | minMax[1] *= transform[0];
|
602 | if (transform[3] < 0) {
|
603 | temp = minMax[2];
|
604 | minMax[2] = minMax[3];
|
605 | minMax[3] = temp;
|
606 | }
|
607 | minMax[2] *= transform[3];
|
608 | minMax[3] *= transform[3];
|
609 | } else {
|
610 | temp = minMax[0];
|
611 | minMax[0] = minMax[2];
|
612 | minMax[2] = temp;
|
613 | temp = minMax[1];
|
614 | minMax[1] = minMax[3];
|
615 | minMax[3] = temp;
|
616 | if (transform[1] < 0) {
|
617 | temp = minMax[2];
|
618 | minMax[2] = minMax[3];
|
619 | minMax[3] = temp;
|
620 | }
|
621 | minMax[2] *= transform[1];
|
622 | minMax[3] *= transform[1];
|
623 | if (transform[2] < 0) {
|
624 | temp = minMax[0];
|
625 | minMax[0] = minMax[1];
|
626 | minMax[1] = temp;
|
627 | }
|
628 | minMax[0] *= transform[2];
|
629 | minMax[1] *= transform[2];
|
630 | }
|
631 | minMax[0] += transform[4];
|
632 | minMax[1] += transform[4];
|
633 | minMax[2] += transform[5];
|
634 | minMax[3] += transform[5];
|
635 | }
|
636 | static transform(m1, m2) {
|
637 | return [m1[0] * m2[0] + m1[2] * m2[1], m1[1] * m2[0] + m1[3] * m2[1], m1[0] * m2[2] + m1[2] * m2[3], m1[1] * m2[2] + m1[3] * m2[3], m1[0] * m2[4] + m1[2] * m2[5] + m1[4], m1[1] * m2[4] + m1[3] * m2[5] + m1[5]];
|
638 | }
|
639 | static applyTransform(p, m) {
|
640 | const xt = p[0] * m[0] + p[1] * m[2] + m[4];
|
641 | const yt = p[0] * m[1] + p[1] * m[3] + m[5];
|
642 | return [xt, yt];
|
643 | }
|
644 | static applyInverseTransform(p, m) {
|
645 | const d = m[0] * m[3] - m[1] * m[2];
|
646 | const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
|
647 | const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
|
648 | return [xt, yt];
|
649 | }
|
650 | static getAxialAlignedBoundingBox(r, m) {
|
651 | const p1 = Util.applyTransform(r, m);
|
652 | const p2 = Util.applyTransform(r.slice(2, 4), m);
|
653 | const p3 = Util.applyTransform([r[0], r[3]], m);
|
654 | const p4 = Util.applyTransform([r[2], r[1]], m);
|
655 | return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])];
|
656 | }
|
657 | static inverseTransform(m) {
|
658 | const d = m[0] * m[3] - m[1] * m[2];
|
659 | return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d, (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
|
660 | }
|
661 | static singularValueDecompose2dScale(m) {
|
662 | const transpose = [m[0], m[2], m[1], m[3]];
|
663 | const a = m[0] * transpose[0] + m[1] * transpose[2];
|
664 | const b = m[0] * transpose[1] + m[1] * transpose[3];
|
665 | const c = m[2] * transpose[0] + m[3] * transpose[2];
|
666 | const d = m[2] * transpose[1] + m[3] * transpose[3];
|
667 | const first = (a + d) / 2;
|
668 | const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
|
669 | const sx = first + second || 1;
|
670 | const sy = first - second || 1;
|
671 | return [Math.sqrt(sx), Math.sqrt(sy)];
|
672 | }
|
673 | static normalizeRect(rect) {
|
674 | const r = rect.slice(0);
|
675 | if (rect[0] > rect[2]) {
|
676 | r[0] = rect[2];
|
677 | r[2] = rect[0];
|
678 | }
|
679 | if (rect[1] > rect[3]) {
|
680 | r[1] = rect[3];
|
681 | r[3] = rect[1];
|
682 | }
|
683 | return r;
|
684 | }
|
685 | static intersect(rect1, rect2) {
|
686 | const xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
|
687 | const xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
|
688 | if (xLow > xHigh) {
|
689 | return null;
|
690 | }
|
691 | const yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
|
692 | const yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
|
693 | if (yLow > yHigh) {
|
694 | return null;
|
695 | }
|
696 | return [xLow, yLow, xHigh, yHigh];
|
697 | }
|
698 | static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3) {
|
699 | const tvalues = [],
|
700 | bounds = [[], []];
|
701 | let a, b, c, t, t1, t2, b2ac, sqrtb2ac;
|
702 | for (let i = 0; i < 2; ++i) {
|
703 | if (i === 0) {
|
704 | b = 6 * x0 - 12 * x1 + 6 * x2;
|
705 | a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
|
706 | c = 3 * x1 - 3 * x0;
|
707 | } else {
|
708 | b = 6 * y0 - 12 * y1 + 6 * y2;
|
709 | a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
|
710 | c = 3 * y1 - 3 * y0;
|
711 | }
|
712 | if (Math.abs(a) < 1e-12) {
|
713 | if (Math.abs(b) < 1e-12) {
|
714 | continue;
|
715 | }
|
716 | t = -c / b;
|
717 | if (0 < t && t < 1) {
|
718 | tvalues.push(t);
|
719 | }
|
720 | continue;
|
721 | }
|
722 | b2ac = b * b - 4 * c * a;
|
723 | sqrtb2ac = Math.sqrt(b2ac);
|
724 | if (b2ac < 0) {
|
725 | continue;
|
726 | }
|
727 | t1 = (-b + sqrtb2ac) / (2 * a);
|
728 | if (0 < t1 && t1 < 1) {
|
729 | tvalues.push(t1);
|
730 | }
|
731 | t2 = (-b - sqrtb2ac) / (2 * a);
|
732 | if (0 < t2 && t2 < 1) {
|
733 | tvalues.push(t2);
|
734 | }
|
735 | }
|
736 | let j = tvalues.length,
|
737 | mt;
|
738 | const jlen = j;
|
739 | while (j--) {
|
740 | t = tvalues[j];
|
741 | mt = 1 - t;
|
742 | bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
|
743 | bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
|
744 | }
|
745 | bounds[0][jlen] = x0;
|
746 | bounds[1][jlen] = y0;
|
747 | bounds[0][jlen + 1] = x3;
|
748 | bounds[1][jlen + 1] = y3;
|
749 | bounds[0].length = bounds[1].length = jlen + 2;
|
750 | return [Math.min(...bounds[0]), Math.min(...bounds[1]), Math.max(...bounds[0]), Math.max(...bounds[1])];
|
751 | }
|
752 | }
|
753 | exports.Util = Util;
|
754 | const PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2d8, 0x2c7, 0x2c6, 0x2d9, 0x2dd, 0x2db, 0x2da, 0x2dc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203a, 0x2212, 0x2030, 0x201e, 0x201c, 0x201d, 0x2018, 0x2019, 0x201a, 0x2122, 0xfb01, 0xfb02, 0x141, 0x152, 0x160, 0x178, 0x17d, 0x131, 0x142, 0x153, 0x161, 0x17e, 0, 0x20ac];
|
755 | function stringToPDFString(str) {
|
756 | if (str[0] >= "\xEF") {
|
757 | let encoding;
|
758 | if (str[0] === "\xFE" && str[1] === "\xFF") {
|
759 | encoding = "utf-16be";
|
760 | } else if (str[0] === "\xFF" && str[1] === "\xFE") {
|
761 | encoding = "utf-16le";
|
762 | } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
|
763 | encoding = "utf-8";
|
764 | }
|
765 | if (encoding) {
|
766 | try {
|
767 | const decoder = new TextDecoder(encoding, {
|
768 | fatal: true
|
769 | });
|
770 | const buffer = stringToBytes(str);
|
771 | return decoder.decode(buffer);
|
772 | } catch (ex) {
|
773 | warn(`stringToPDFString: "${ex}".`);
|
774 | }
|
775 | }
|
776 | }
|
777 | const strBuf = [];
|
778 | for (let i = 0, ii = str.length; i < ii; i++) {
|
779 | const code = PDFStringTranslateTable[str.charCodeAt(i)];
|
780 | strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
|
781 | }
|
782 | return strBuf.join("");
|
783 | }
|
784 | function stringToUTF8String(str) {
|
785 | return decodeURIComponent(escape(str));
|
786 | }
|
787 | function utf8StringToString(str) {
|
788 | return unescape(encodeURIComponent(str));
|
789 | }
|
790 | function isArrayBuffer(v) {
|
791 | return typeof v === "object" && v?.byteLength !== undefined;
|
792 | }
|
793 | function isArrayEqual(arr1, arr2) {
|
794 | if (arr1.length !== arr2.length) {
|
795 | return false;
|
796 | }
|
797 | for (let i = 0, ii = arr1.length; i < ii; i++) {
|
798 | if (arr1[i] !== arr2[i]) {
|
799 | return false;
|
800 | }
|
801 | }
|
802 | return true;
|
803 | }
|
804 | function getModificationDate(date = new Date()) {
|
805 | const buffer = [date.getUTCFullYear().toString(), (date.getUTCMonth() + 1).toString().padStart(2, "0"), date.getUTCDate().toString().padStart(2, "0"), date.getUTCHours().toString().padStart(2, "0"), date.getUTCMinutes().toString().padStart(2, "0"), date.getUTCSeconds().toString().padStart(2, "0")];
|
806 | return buffer.join("");
|
807 | }
|
808 | class PromiseCapability {
|
809 | #settled = false;
|
810 | constructor() {
|
811 | this.promise = new Promise((resolve, reject) => {
|
812 | this.resolve = data => {
|
813 | this.#settled = true;
|
814 | resolve(data);
|
815 | };
|
816 | this.reject = reason => {
|
817 | this.#settled = true;
|
818 | reject(reason);
|
819 | };
|
820 | });
|
821 | }
|
822 | get settled() {
|
823 | return this.#settled;
|
824 | }
|
825 | }
|
826 | exports.PromiseCapability = PromiseCapability;
|
827 | let NormalizeRegex = null;
|
828 | let NormalizationMap = null;
|
829 | function normalizeUnicode(str) {
|
830 | if (!NormalizeRegex) {
|
831 | 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;
|
832 | NormalizationMap = new Map([["ſt", "ſt"]]);
|
833 | }
|
834 | return str.replaceAll(NormalizeRegex, (_, p1, p2) => {
|
835 | return p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2);
|
836 | });
|
837 | }
|
838 |
|
839 | }),
|
840 |
|
841 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
842 |
|
843 |
|
844 |
|
845 | Object.defineProperty(exports, "__esModule", ({
|
846 | value: true
|
847 | }));
|
848 | exports.build = exports.RenderTask = exports.PDFWorkerUtil = exports.PDFWorker = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFDocumentLoadingTask = exports.PDFDataRangeTransport = exports.LoopbackPort = exports.DefaultStandardFontDataFactory = exports.DefaultFilterFactory = exports.DefaultCanvasFactory = exports.DefaultCMapReaderFactory = void 0;
|
849 | exports.getDocument = getDocument;
|
850 | exports.version = void 0;
|
851 | var _util = __w_pdfjs_require__(1);
|
852 | var _annotation_storage = __w_pdfjs_require__(3);
|
853 | var _display_utils = __w_pdfjs_require__(6);
|
854 | var _font_loader = __w_pdfjs_require__(9);
|
855 | var _canvas = __w_pdfjs_require__(11);
|
856 | var _worker_options = __w_pdfjs_require__(14);
|
857 | var _is_node = __w_pdfjs_require__(10);
|
858 | var _message_handler = __w_pdfjs_require__(15);
|
859 | var _metadata = __w_pdfjs_require__(16);
|
860 | var _optional_content_config = __w_pdfjs_require__(17);
|
861 | var _transport_stream = __w_pdfjs_require__(18);
|
862 | var _xfa_text = __w_pdfjs_require__(19);
|
863 | const DEFAULT_RANGE_CHUNK_SIZE = 65536;
|
864 | const RENDERING_CANCELLED_TIMEOUT = 100;
|
865 | const DELAYED_CLEANUP_TIMEOUT = 5000;
|
866 | let DefaultCanvasFactory = _display_utils.DOMCanvasFactory;
|
867 | exports.DefaultCanvasFactory = DefaultCanvasFactory;
|
868 | let DefaultCMapReaderFactory = _display_utils.DOMCMapReaderFactory;
|
869 | exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory;
|
870 | let DefaultFilterFactory = _display_utils.DOMFilterFactory;
|
871 | exports.DefaultFilterFactory = DefaultFilterFactory;
|
872 | let DefaultStandardFontDataFactory = _display_utils.DOMStandardFontDataFactory;
|
873 | exports.DefaultStandardFontDataFactory = DefaultStandardFontDataFactory;
|
874 | if (_is_node.isNodeJS) {
|
875 | const {
|
876 | NodeCanvasFactory,
|
877 | NodeCMapReaderFactory,
|
878 | NodeFilterFactory,
|
879 | NodeStandardFontDataFactory
|
880 | } = __w_pdfjs_require__(20);
|
881 | exports.DefaultCanvasFactory = DefaultCanvasFactory = NodeCanvasFactory;
|
882 | exports.DefaultCMapReaderFactory = DefaultCMapReaderFactory = NodeCMapReaderFactory;
|
883 | exports.DefaultFilterFactory = DefaultFilterFactory = NodeFilterFactory;
|
884 | exports.DefaultStandardFontDataFactory = DefaultStandardFontDataFactory = NodeStandardFontDataFactory;
|
885 | }
|
886 | let createPDFNetworkStream;
|
887 | {
|
888 | if (_is_node.isNodeJS) {
|
889 | const {
|
890 | PDFNodeStream
|
891 | } = __w_pdfjs_require__(21);
|
892 | createPDFNetworkStream = params => {
|
893 | return new PDFNodeStream(params);
|
894 | };
|
895 | } else {
|
896 | const {
|
897 | PDFNetworkStream
|
898 | } = __w_pdfjs_require__(24);
|
899 | const {
|
900 | PDFFetchStream
|
901 | } = __w_pdfjs_require__(25);
|
902 | createPDFNetworkStream = params => {
|
903 | return (0, _display_utils.isValidFetchUrl)(params.url) ? new PDFFetchStream(params) : new PDFNetworkStream(params);
|
904 | };
|
905 | }
|
906 | }
|
907 | function getDocument(src) {
|
908 | if (typeof src === "string" || src instanceof URL) {
|
909 | src = {
|
910 | url: src
|
911 | };
|
912 | } else if ((0, _util.isArrayBuffer)(src)) {
|
913 | src = {
|
914 | data: src
|
915 | };
|
916 | }
|
917 | if (typeof src !== "object") {
|
918 | throw new Error("Invalid parameter in getDocument, need parameter object.");
|
919 | }
|
920 | if (!src.url && !src.data && !src.range) {
|
921 | throw new Error("Invalid parameter object: need either .data, .range or .url");
|
922 | }
|
923 | const task = new PDFDocumentLoadingTask();
|
924 | const {
|
925 | docId
|
926 | } = task;
|
927 | const url = src.url ? getUrlProp(src.url) : null;
|
928 | const data = src.data ? getDataProp(src.data) : null;
|
929 | const httpHeaders = src.httpHeaders || null;
|
930 | const withCredentials = src.withCredentials === true;
|
931 | const password = src.password ?? null;
|
932 | const rangeTransport = src.range instanceof PDFDataRangeTransport ? src.range : null;
|
933 | const rangeChunkSize = Number.isInteger(src.rangeChunkSize) && src.rangeChunkSize > 0 ? src.rangeChunkSize : DEFAULT_RANGE_CHUNK_SIZE;
|
934 | let worker = src.worker instanceof PDFWorker ? src.worker : null;
|
935 | const verbosity = src.verbosity;
|
936 | const docBaseUrl = typeof src.docBaseUrl === "string" && !(0, _display_utils.isDataScheme)(src.docBaseUrl) ? src.docBaseUrl : null;
|
937 | const cMapUrl = typeof src.cMapUrl === "string" ? src.cMapUrl : null;
|
938 | const cMapPacked = src.cMapPacked !== false;
|
939 | const CMapReaderFactory = src.CMapReaderFactory || DefaultCMapReaderFactory;
|
940 | const standardFontDataUrl = typeof src.standardFontDataUrl === "string" ? src.standardFontDataUrl : null;
|
941 | const StandardFontDataFactory = src.StandardFontDataFactory || DefaultStandardFontDataFactory;
|
942 | const ignoreErrors = src.stopAtErrors !== true;
|
943 | const maxImageSize = Number.isInteger(src.maxImageSize) && src.maxImageSize > -1 ? src.maxImageSize : -1;
|
944 | const isEvalSupported = src.isEvalSupported !== false;
|
945 | const isOffscreenCanvasSupported = typeof src.isOffscreenCanvasSupported === "boolean" ? src.isOffscreenCanvasSupported : !_is_node.isNodeJS;
|
946 | const canvasMaxAreaInBytes = Number.isInteger(src.canvasMaxAreaInBytes) ? src.canvasMaxAreaInBytes : -1;
|
947 | const disableFontFace = typeof src.disableFontFace === "boolean" ? src.disableFontFace : _is_node.isNodeJS;
|
948 | const fontExtraProperties = src.fontExtraProperties === true;
|
949 | const enableXfa = src.enableXfa === true;
|
950 | const ownerDocument = src.ownerDocument || globalThis.document;
|
951 | const disableRange = src.disableRange === true;
|
952 | const disableStream = src.disableStream === true;
|
953 | const disableAutoFetch = src.disableAutoFetch === true;
|
954 | const pdfBug = src.pdfBug === true;
|
955 | const length = rangeTransport ? rangeTransport.length : src.length ?? NaN;
|
956 | const useSystemFonts = typeof src.useSystemFonts === "boolean" ? src.useSystemFonts : !_is_node.isNodeJS && !disableFontFace;
|
957 | const useWorkerFetch = typeof src.useWorkerFetch === "boolean" ? src.useWorkerFetch : CMapReaderFactory === _display_utils.DOMCMapReaderFactory && StandardFontDataFactory === _display_utils.DOMStandardFontDataFactory && (0, _display_utils.isValidFetchUrl)(cMapUrl, document.baseURI) && (0, _display_utils.isValidFetchUrl)(standardFontDataUrl, document.baseURI);
|
958 | const canvasFactory = src.canvasFactory || new DefaultCanvasFactory({
|
959 | ownerDocument
|
960 | });
|
961 | const filterFactory = src.filterFactory || new DefaultFilterFactory({
|
962 | docId,
|
963 | ownerDocument
|
964 | });
|
965 | const styleElement = null;
|
966 | (0, _util.setVerbosityLevel)(verbosity);
|
967 | const transportFactory = {
|
968 | canvasFactory,
|
969 | filterFactory
|
970 | };
|
971 | if (!useWorkerFetch) {
|
972 | transportFactory.cMapReaderFactory = new CMapReaderFactory({
|
973 | baseUrl: cMapUrl,
|
974 | isCompressed: cMapPacked
|
975 | });
|
976 | transportFactory.standardFontDataFactory = new StandardFontDataFactory({
|
977 | baseUrl: standardFontDataUrl
|
978 | });
|
979 | }
|
980 | if (!worker) {
|
981 | const workerParams = {
|
982 | verbosity,
|
983 | port: _worker_options.GlobalWorkerOptions.workerPort
|
984 | };
|
985 | worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
|
986 | task._worker = worker;
|
987 | }
|
988 | const fetchDocParams = {
|
989 | docId,
|
990 | apiVersion: '3.7.107',
|
991 | data,
|
992 | password,
|
993 | disableAutoFetch,
|
994 | rangeChunkSize,
|
995 | length,
|
996 | docBaseUrl,
|
997 | enableXfa,
|
998 | evaluatorOptions: {
|
999 | maxImageSize,
|
1000 | disableFontFace,
|
1001 | ignoreErrors,
|
1002 | isEvalSupported,
|
1003 | isOffscreenCanvasSupported,
|
1004 | canvasMaxAreaInBytes,
|
1005 | fontExtraProperties,
|
1006 | useSystemFonts,
|
1007 | cMapUrl: useWorkerFetch ? cMapUrl : null,
|
1008 | standardFontDataUrl: useWorkerFetch ? standardFontDataUrl : null
|
1009 | }
|
1010 | };
|
1011 | const transportParams = {
|
1012 | ignoreErrors,
|
1013 | isEvalSupported,
|
1014 | disableFontFace,
|
1015 | fontExtraProperties,
|
1016 | enableXfa,
|
1017 | ownerDocument,
|
1018 | disableAutoFetch,
|
1019 | pdfBug,
|
1020 | styleElement
|
1021 | };
|
1022 | worker.promise.then(function () {
|
1023 | if (task.destroyed) {
|
1024 | throw new Error("Loading aborted");
|
1025 | }
|
1026 | const workerIdPromise = _fetchDocument(worker, fetchDocParams);
|
1027 | const networkStreamPromise = new Promise(function (resolve) {
|
1028 | let networkStream;
|
1029 | if (rangeTransport) {
|
1030 | networkStream = new _transport_stream.PDFDataTransportStream({
|
1031 | length,
|
1032 | initialData: rangeTransport.initialData,
|
1033 | progressiveDone: rangeTransport.progressiveDone,
|
1034 | contentDispositionFilename: rangeTransport.contentDispositionFilename,
|
1035 | disableRange,
|
1036 | disableStream
|
1037 | }, rangeTransport);
|
1038 | } else if (!data) {
|
1039 | networkStream = createPDFNetworkStream({
|
1040 | url,
|
1041 | length,
|
1042 | httpHeaders,
|
1043 | withCredentials,
|
1044 | rangeChunkSize,
|
1045 | disableRange,
|
1046 | disableStream
|
1047 | });
|
1048 | }
|
1049 | resolve(networkStream);
|
1050 | });
|
1051 | return Promise.all([workerIdPromise, networkStreamPromise]).then(function ([workerId, networkStream]) {
|
1052 | if (task.destroyed) {
|
1053 | throw new Error("Loading aborted");
|
1054 | }
|
1055 | const messageHandler = new _message_handler.MessageHandler(docId, workerId, worker.port);
|
1056 | const transport = new WorkerTransport(messageHandler, task, networkStream, transportParams, transportFactory);
|
1057 | task._transport = transport;
|
1058 | messageHandler.send("Ready", null);
|
1059 | });
|
1060 | }).catch(task._capability.reject);
|
1061 | return task;
|
1062 | }
|
1063 | async function _fetchDocument(worker, source) {
|
1064 | if (worker.destroyed) {
|
1065 | throw new Error("Worker was destroyed");
|
1066 | }
|
1067 | const workerId = await worker.messageHandler.sendWithPromise("GetDocRequest", source, source.data ? [source.data.buffer] : null);
|
1068 | if (worker.destroyed) {
|
1069 | throw new Error("Worker was destroyed");
|
1070 | }
|
1071 | return workerId;
|
1072 | }
|
1073 | function getUrlProp(val) {
|
1074 | if (val instanceof URL) {
|
1075 | return val.href;
|
1076 | }
|
1077 | try {
|
1078 | return new URL(val, window.location).href;
|
1079 | } catch (ex) {
|
1080 | if (_is_node.isNodeJS && typeof val === "string") {
|
1081 | return val;
|
1082 | }
|
1083 | }
|
1084 | throw new Error("Invalid PDF url data: " + "either string or URL-object is expected in the url property.");
|
1085 | }
|
1086 | function getDataProp(val) {
|
1087 | if (_is_node.isNodeJS && typeof Buffer !== "undefined" && val instanceof Buffer) {
|
1088 | (0, _display_utils.deprecated)("Please provide binary data as `Uint8Array`, rather than `Buffer`.");
|
1089 | return new Uint8Array(val);
|
1090 | }
|
1091 | if (val instanceof Uint8Array && val.byteLength === val.buffer.byteLength) {
|
1092 | return val;
|
1093 | }
|
1094 | if (typeof val === "string") {
|
1095 | return (0, _util.stringToBytes)(val);
|
1096 | }
|
1097 | if (typeof val === "object" && !isNaN(val?.length) || (0, _util.isArrayBuffer)(val)) {
|
1098 | return new Uint8Array(val);
|
1099 | }
|
1100 | throw new Error("Invalid PDF binary data: either TypedArray, " + "string, or array-like object is expected in the data property.");
|
1101 | }
|
1102 | class PDFDocumentLoadingTask {
|
1103 | static #docId = 0;
|
1104 | constructor() {
|
1105 | this._capability = new _util.PromiseCapability();
|
1106 | this._transport = null;
|
1107 | this._worker = null;
|
1108 | this.docId = `d${PDFDocumentLoadingTask.#docId++}`;
|
1109 | this.destroyed = false;
|
1110 | this.onPassword = null;
|
1111 | this.onProgress = null;
|
1112 | }
|
1113 | get promise() {
|
1114 | return this._capability.promise;
|
1115 | }
|
1116 | async destroy() {
|
1117 | this.destroyed = true;
|
1118 | await this._transport?.destroy();
|
1119 | this._transport = null;
|
1120 | if (this._worker) {
|
1121 | this._worker.destroy();
|
1122 | this._worker = null;
|
1123 | }
|
1124 | }
|
1125 | }
|
1126 | exports.PDFDocumentLoadingTask = PDFDocumentLoadingTask;
|
1127 | class PDFDataRangeTransport {
|
1128 | constructor(length, initialData, progressiveDone = false, contentDispositionFilename = null) {
|
1129 | this.length = length;
|
1130 | this.initialData = initialData;
|
1131 | this.progressiveDone = progressiveDone;
|
1132 | this.contentDispositionFilename = contentDispositionFilename;
|
1133 | this._rangeListeners = [];
|
1134 | this._progressListeners = [];
|
1135 | this._progressiveReadListeners = [];
|
1136 | this._progressiveDoneListeners = [];
|
1137 | this._readyCapability = new _util.PromiseCapability();
|
1138 | }
|
1139 | addRangeListener(listener) {
|
1140 | this._rangeListeners.push(listener);
|
1141 | }
|
1142 | addProgressListener(listener) {
|
1143 | this._progressListeners.push(listener);
|
1144 | }
|
1145 | addProgressiveReadListener(listener) {
|
1146 | this._progressiveReadListeners.push(listener);
|
1147 | }
|
1148 | addProgressiveDoneListener(listener) {
|
1149 | this._progressiveDoneListeners.push(listener);
|
1150 | }
|
1151 | onDataRange(begin, chunk) {
|
1152 | for (const listener of this._rangeListeners) {
|
1153 | listener(begin, chunk);
|
1154 | }
|
1155 | }
|
1156 | onDataProgress(loaded, total) {
|
1157 | this._readyCapability.promise.then(() => {
|
1158 | for (const listener of this._progressListeners) {
|
1159 | listener(loaded, total);
|
1160 | }
|
1161 | });
|
1162 | }
|
1163 | onDataProgressiveRead(chunk) {
|
1164 | this._readyCapability.promise.then(() => {
|
1165 | for (const listener of this._progressiveReadListeners) {
|
1166 | listener(chunk);
|
1167 | }
|
1168 | });
|
1169 | }
|
1170 | onDataProgressiveDone() {
|
1171 | this._readyCapability.promise.then(() => {
|
1172 | for (const listener of this._progressiveDoneListeners) {
|
1173 | listener();
|
1174 | }
|
1175 | });
|
1176 | }
|
1177 | transportReady() {
|
1178 | this._readyCapability.resolve();
|
1179 | }
|
1180 | requestDataRange(begin, end) {
|
1181 | (0, _util.unreachable)("Abstract method PDFDataRangeTransport.requestDataRange");
|
1182 | }
|
1183 | abort() {}
|
1184 | }
|
1185 | exports.PDFDataRangeTransport = PDFDataRangeTransport;
|
1186 | class PDFDocumentProxy {
|
1187 | constructor(pdfInfo, transport) {
|
1188 | this._pdfInfo = pdfInfo;
|
1189 | this._transport = transport;
|
1190 | }
|
1191 | get annotationStorage() {
|
1192 | return this._transport.annotationStorage;
|
1193 | }
|
1194 | get filterFactory() {
|
1195 | return this._transport.filterFactory;
|
1196 | }
|
1197 | get numPages() {
|
1198 | return this._pdfInfo.numPages;
|
1199 | }
|
1200 | get fingerprints() {
|
1201 | return this._pdfInfo.fingerprints;
|
1202 | }
|
1203 | get isPureXfa() {
|
1204 | return (0, _util.shadow)(this, "isPureXfa", !!this._transport._htmlForXfa);
|
1205 | }
|
1206 | get allXfaHtml() {
|
1207 | return this._transport._htmlForXfa;
|
1208 | }
|
1209 | getPage(pageNumber) {
|
1210 | return this._transport.getPage(pageNumber);
|
1211 | }
|
1212 | getPageIndex(ref) {
|
1213 | return this._transport.getPageIndex(ref);
|
1214 | }
|
1215 | getDestinations() {
|
1216 | return this._transport.getDestinations();
|
1217 | }
|
1218 | getDestination(id) {
|
1219 | return this._transport.getDestination(id);
|
1220 | }
|
1221 | getPageLabels() {
|
1222 | return this._transport.getPageLabels();
|
1223 | }
|
1224 | getPageLayout() {
|
1225 | return this._transport.getPageLayout();
|
1226 | }
|
1227 | getPageMode() {
|
1228 | return this._transport.getPageMode();
|
1229 | }
|
1230 | getViewerPreferences() {
|
1231 | return this._transport.getViewerPreferences();
|
1232 | }
|
1233 | getOpenAction() {
|
1234 | return this._transport.getOpenAction();
|
1235 | }
|
1236 | getAttachments() {
|
1237 | return this._transport.getAttachments();
|
1238 | }
|
1239 | getJavaScript() {
|
1240 | return this._transport.getJavaScript();
|
1241 | }
|
1242 | getJSActions() {
|
1243 | return this._transport.getDocJSActions();
|
1244 | }
|
1245 | getOutline() {
|
1246 | return this._transport.getOutline();
|
1247 | }
|
1248 | getOptionalContentConfig() {
|
1249 | return this._transport.getOptionalContentConfig();
|
1250 | }
|
1251 | getPermissions() {
|
1252 | return this._transport.getPermissions();
|
1253 | }
|
1254 | getMetadata() {
|
1255 | return this._transport.getMetadata();
|
1256 | }
|
1257 | getMarkInfo() {
|
1258 | return this._transport.getMarkInfo();
|
1259 | }
|
1260 | getData() {
|
1261 | return this._transport.getData();
|
1262 | }
|
1263 | saveDocument() {
|
1264 | return this._transport.saveDocument();
|
1265 | }
|
1266 | getDownloadInfo() {
|
1267 | return this._transport.downloadInfoCapability.promise;
|
1268 | }
|
1269 | cleanup(keepLoadedFonts = false) {
|
1270 | return this._transport.startCleanup(keepLoadedFonts || this.isPureXfa);
|
1271 | }
|
1272 | destroy() {
|
1273 | return this.loadingTask.destroy();
|
1274 | }
|
1275 | get loadingParams() {
|
1276 | return this._transport.loadingParams;
|
1277 | }
|
1278 | get loadingTask() {
|
1279 | return this._transport.loadingTask;
|
1280 | }
|
1281 | getFieldObjects() {
|
1282 | return this._transport.getFieldObjects();
|
1283 | }
|
1284 | hasJSActions() {
|
1285 | return this._transport.hasJSActions();
|
1286 | }
|
1287 | getCalculationOrderIds() {
|
1288 | return this._transport.getCalculationOrderIds();
|
1289 | }
|
1290 | }
|
1291 | exports.PDFDocumentProxy = PDFDocumentProxy;
|
1292 | class PDFPageProxy {
|
1293 | #delayedCleanupTimeout = null;
|
1294 | #pendingCleanup = false;
|
1295 | constructor(pageIndex, pageInfo, transport, pdfBug = false) {
|
1296 | this._pageIndex = pageIndex;
|
1297 | this._pageInfo = pageInfo;
|
1298 | this._transport = transport;
|
1299 | this._stats = pdfBug ? new _display_utils.StatTimer() : null;
|
1300 | this._pdfBug = pdfBug;
|
1301 | this.commonObjs = transport.commonObjs;
|
1302 | this.objs = new PDFObjects();
|
1303 | this._maybeCleanupAfterRender = false;
|
1304 | this._intentStates = new Map();
|
1305 | this.destroyed = false;
|
1306 | }
|
1307 | get pageNumber() {
|
1308 | return this._pageIndex + 1;
|
1309 | }
|
1310 | get rotate() {
|
1311 | return this._pageInfo.rotate;
|
1312 | }
|
1313 | get ref() {
|
1314 | return this._pageInfo.ref;
|
1315 | }
|
1316 | get userUnit() {
|
1317 | return this._pageInfo.userUnit;
|
1318 | }
|
1319 | get view() {
|
1320 | return this._pageInfo.view;
|
1321 | }
|
1322 | getViewport({
|
1323 | scale,
|
1324 | rotation = this.rotate,
|
1325 | offsetX = 0,
|
1326 | offsetY = 0,
|
1327 | dontFlip = false
|
1328 | } = {}) {
|
1329 | return new _display_utils.PageViewport({
|
1330 | viewBox: this.view,
|
1331 | scale,
|
1332 | rotation,
|
1333 | offsetX,
|
1334 | offsetY,
|
1335 | dontFlip
|
1336 | });
|
1337 | }
|
1338 | getAnnotations({
|
1339 | intent = "display"
|
1340 | } = {}) {
|
1341 | const intentArgs = this._transport.getRenderingIntent(intent);
|
1342 | return this._transport.getAnnotations(this._pageIndex, intentArgs.renderingIntent);
|
1343 | }
|
1344 | getJSActions() {
|
1345 | return this._transport.getPageJSActions(this._pageIndex);
|
1346 | }
|
1347 | get isPureXfa() {
|
1348 | return (0, _util.shadow)(this, "isPureXfa", !!this._transport._htmlForXfa);
|
1349 | }
|
1350 | async getXfa() {
|
1351 | return this._transport._htmlForXfa?.children[this._pageIndex] || null;
|
1352 | }
|
1353 | render({
|
1354 | canvasContext,
|
1355 | viewport,
|
1356 | intent = "display",
|
1357 | annotationMode = _util.AnnotationMode.ENABLE,
|
1358 | transform = null,
|
1359 | background = null,
|
1360 | optionalContentConfigPromise = null,
|
1361 | annotationCanvasMap = null,
|
1362 | pageColors = null,
|
1363 | printAnnotationStorage = null
|
1364 | }) {
|
1365 | if (arguments[0]?.canvasFactory) {
|
1366 | throw new Error("render no longer accepts the `canvasFactory`-option, " + "please pass it to the `getDocument`-function instead.");
|
1367 | }
|
1368 | this._stats?.time("Overall");
|
1369 | const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage);
|
1370 | this.#pendingCleanup = false;
|
1371 | this.#abortDelayedCleanup();
|
1372 | if (!optionalContentConfigPromise) {
|
1373 | optionalContentConfigPromise = this._transport.getOptionalContentConfig();
|
1374 | }
|
1375 | let intentState = this._intentStates.get(intentArgs.cacheKey);
|
1376 | if (!intentState) {
|
1377 | intentState = Object.create(null);
|
1378 | this._intentStates.set(intentArgs.cacheKey, intentState);
|
1379 | }
|
1380 | if (intentState.streamReaderCancelTimeout) {
|
1381 | clearTimeout(intentState.streamReaderCancelTimeout);
|
1382 | intentState.streamReaderCancelTimeout = null;
|
1383 | }
|
1384 | const intentPrint = !!(intentArgs.renderingIntent & _util.RenderingIntentFlag.PRINT);
|
1385 | if (!intentState.displayReadyCapability) {
|
1386 | intentState.displayReadyCapability = new _util.PromiseCapability();
|
1387 | intentState.operatorList = {
|
1388 | fnArray: [],
|
1389 | argsArray: [],
|
1390 | lastChunk: false,
|
1391 | separateAnnots: null
|
1392 | };
|
1393 | this._stats?.time("Page Request");
|
1394 | this._pumpOperatorList(intentArgs);
|
1395 | }
|
1396 | const complete = error => {
|
1397 | intentState.renderTasks.delete(internalRenderTask);
|
1398 | if (this._maybeCleanupAfterRender || intentPrint) {
|
1399 | this.#pendingCleanup = true;
|
1400 | }
|
1401 | this.#tryCleanup(!intentPrint);
|
1402 | if (error) {
|
1403 | internalRenderTask.capability.reject(error);
|
1404 | this._abortOperatorList({
|
1405 | intentState,
|
1406 | reason: error instanceof Error ? error : new Error(error)
|
1407 | });
|
1408 | } else {
|
1409 | internalRenderTask.capability.resolve();
|
1410 | }
|
1411 | this._stats?.timeEnd("Rendering");
|
1412 | this._stats?.timeEnd("Overall");
|
1413 | };
|
1414 | const internalRenderTask = new InternalRenderTask({
|
1415 | callback: complete,
|
1416 | params: {
|
1417 | canvasContext,
|
1418 | viewport,
|
1419 | transform,
|
1420 | background
|
1421 | },
|
1422 | objs: this.objs,
|
1423 | commonObjs: this.commonObjs,
|
1424 | annotationCanvasMap,
|
1425 | operatorList: intentState.operatorList,
|
1426 | pageIndex: this._pageIndex,
|
1427 | canvasFactory: this._transport.canvasFactory,
|
1428 | filterFactory: this._transport.filterFactory,
|
1429 | useRequestAnimationFrame: !intentPrint,
|
1430 | pdfBug: this._pdfBug,
|
1431 | pageColors
|
1432 | });
|
1433 | (intentState.renderTasks ||= new Set()).add(internalRenderTask);
|
1434 | const renderTask = internalRenderTask.task;
|
1435 | Promise.all([intentState.displayReadyCapability.promise, optionalContentConfigPromise]).then(([transparency, optionalContentConfig]) => {
|
1436 | if (this.#pendingCleanup) {
|
1437 | complete();
|
1438 | return;
|
1439 | }
|
1440 | this._stats?.time("Rendering");
|
1441 | internalRenderTask.initializeGraphics({
|
1442 | transparency,
|
1443 | optionalContentConfig
|
1444 | });
|
1445 | internalRenderTask.operatorListChanged();
|
1446 | }).catch(complete);
|
1447 | return renderTask;
|
1448 | }
|
1449 | getOperatorList({
|
1450 | intent = "display",
|
1451 | annotationMode = _util.AnnotationMode.ENABLE,
|
1452 | printAnnotationStorage = null
|
1453 | } = {}) {
|
1454 | function operatorListChanged() {
|
1455 | if (intentState.operatorList.lastChunk) {
|
1456 | intentState.opListReadCapability.resolve(intentState.operatorList);
|
1457 | intentState.renderTasks.delete(opListTask);
|
1458 | }
|
1459 | }
|
1460 | const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage, true);
|
1461 | let intentState = this._intentStates.get(intentArgs.cacheKey);
|
1462 | if (!intentState) {
|
1463 | intentState = Object.create(null);
|
1464 | this._intentStates.set(intentArgs.cacheKey, intentState);
|
1465 | }
|
1466 | let opListTask;
|
1467 | if (!intentState.opListReadCapability) {
|
1468 | opListTask = Object.create(null);
|
1469 | opListTask.operatorListChanged = operatorListChanged;
|
1470 | intentState.opListReadCapability = new _util.PromiseCapability();
|
1471 | (intentState.renderTasks ||= new Set()).add(opListTask);
|
1472 | intentState.operatorList = {
|
1473 | fnArray: [],
|
1474 | argsArray: [],
|
1475 | lastChunk: false,
|
1476 | separateAnnots: null
|
1477 | };
|
1478 | this._stats?.time("Page Request");
|
1479 | this._pumpOperatorList(intentArgs);
|
1480 | }
|
1481 | return intentState.opListReadCapability.promise;
|
1482 | }
|
1483 | streamTextContent({
|
1484 | includeMarkedContent = false,
|
1485 | disableNormalization = false
|
1486 | } = {}) {
|
1487 | const TEXT_CONTENT_CHUNK_SIZE = 100;
|
1488 | return this._transport.messageHandler.sendWithStream("GetTextContent", {
|
1489 | pageIndex: this._pageIndex,
|
1490 | includeMarkedContent: includeMarkedContent === true,
|
1491 | disableNormalization: disableNormalization === true
|
1492 | }, {
|
1493 | highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
|
1494 | size(textContent) {
|
1495 | return textContent.items.length;
|
1496 | }
|
1497 | });
|
1498 | }
|
1499 | getTextContent(params = {}) {
|
1500 | if (this._transport._htmlForXfa) {
|
1501 | return this.getXfa().then(xfa => {
|
1502 | return _xfa_text.XfaText.textContent(xfa);
|
1503 | });
|
1504 | }
|
1505 | const readableStream = this.streamTextContent(params);
|
1506 | return new Promise(function (resolve, reject) {
|
1507 | function pump() {
|
1508 | reader.read().then(function ({
|
1509 | value,
|
1510 | done
|
1511 | }) {
|
1512 | if (done) {
|
1513 | resolve(textContent);
|
1514 | return;
|
1515 | }
|
1516 | Object.assign(textContent.styles, value.styles);
|
1517 | textContent.items.push(...value.items);
|
1518 | pump();
|
1519 | }, reject);
|
1520 | }
|
1521 | const reader = readableStream.getReader();
|
1522 | const textContent = {
|
1523 | items: [],
|
1524 | styles: Object.create(null)
|
1525 | };
|
1526 | pump();
|
1527 | });
|
1528 | }
|
1529 | getStructTree() {
|
1530 | return this._transport.getStructTree(this._pageIndex);
|
1531 | }
|
1532 | _destroy() {
|
1533 | this.destroyed = true;
|
1534 | const waitOn = [];
|
1535 | for (const intentState of this._intentStates.values()) {
|
1536 | this._abortOperatorList({
|
1537 | intentState,
|
1538 | reason: new Error("Page was destroyed."),
|
1539 | force: true
|
1540 | });
|
1541 | if (intentState.opListReadCapability) {
|
1542 | continue;
|
1543 | }
|
1544 | for (const internalRenderTask of intentState.renderTasks) {
|
1545 | waitOn.push(internalRenderTask.completed);
|
1546 | internalRenderTask.cancel();
|
1547 | }
|
1548 | }
|
1549 | this.objs.clear();
|
1550 | this.#pendingCleanup = false;
|
1551 | this.#abortDelayedCleanup();
|
1552 | return Promise.all(waitOn);
|
1553 | }
|
1554 | cleanup(resetStats = false) {
|
1555 | this.#pendingCleanup = true;
|
1556 | const success = this.#tryCleanup(false);
|
1557 | if (resetStats && success) {
|
1558 | this._stats &&= new _display_utils.StatTimer();
|
1559 | }
|
1560 | return success;
|
1561 | }
|
1562 | #tryCleanup(delayed = false) {
|
1563 | this.#abortDelayedCleanup();
|
1564 | if (!this.#pendingCleanup) {
|
1565 | return false;
|
1566 | }
|
1567 | if (delayed) {
|
1568 | this.#delayedCleanupTimeout = setTimeout(() => {
|
1569 | this.#delayedCleanupTimeout = null;
|
1570 | this.#tryCleanup(false);
|
1571 | }, DELAYED_CLEANUP_TIMEOUT);
|
1572 | return false;
|
1573 | }
|
1574 | for (const {
|
1575 | renderTasks,
|
1576 | operatorList
|
1577 | } of this._intentStates.values()) {
|
1578 | if (renderTasks.size > 0 || !operatorList.lastChunk) {
|
1579 | return false;
|
1580 | }
|
1581 | }
|
1582 | this._intentStates.clear();
|
1583 | this.objs.clear();
|
1584 | this.#pendingCleanup = false;
|
1585 | return true;
|
1586 | }
|
1587 | #abortDelayedCleanup() {
|
1588 | if (this.#delayedCleanupTimeout) {
|
1589 | clearTimeout(this.#delayedCleanupTimeout);
|
1590 | this.#delayedCleanupTimeout = null;
|
1591 | }
|
1592 | }
|
1593 | _startRenderPage(transparency, cacheKey) {
|
1594 | const intentState = this._intentStates.get(cacheKey);
|
1595 | if (!intentState) {
|
1596 | return;
|
1597 | }
|
1598 | this._stats?.timeEnd("Page Request");
|
1599 | intentState.displayReadyCapability?.resolve(transparency);
|
1600 | }
|
1601 | _renderPageChunk(operatorListChunk, intentState) {
|
1602 | for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
|
1603 | intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
|
1604 | intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
|
1605 | }
|
1606 | intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
|
1607 | intentState.operatorList.separateAnnots = operatorListChunk.separateAnnots;
|
1608 | for (const internalRenderTask of intentState.renderTasks) {
|
1609 | internalRenderTask.operatorListChanged();
|
1610 | }
|
1611 | if (operatorListChunk.lastChunk) {
|
1612 | this.#tryCleanup(true);
|
1613 | }
|
1614 | }
|
1615 | _pumpOperatorList({
|
1616 | renderingIntent,
|
1617 | cacheKey,
|
1618 | annotationStorageMap
|
1619 | }) {
|
1620 | const readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", {
|
1621 | pageIndex: this._pageIndex,
|
1622 | intent: renderingIntent,
|
1623 | cacheKey,
|
1624 | annotationStorage: annotationStorageMap
|
1625 | });
|
1626 | const reader = readableStream.getReader();
|
1627 | const intentState = this._intentStates.get(cacheKey);
|
1628 | intentState.streamReader = reader;
|
1629 | const pump = () => {
|
1630 | reader.read().then(({
|
1631 | value,
|
1632 | done
|
1633 | }) => {
|
1634 | if (done) {
|
1635 | intentState.streamReader = null;
|
1636 | return;
|
1637 | }
|
1638 | if (this._transport.destroyed) {
|
1639 | return;
|
1640 | }
|
1641 | this._renderPageChunk(value, intentState);
|
1642 | pump();
|
1643 | }, reason => {
|
1644 | intentState.streamReader = null;
|
1645 | if (this._transport.destroyed) {
|
1646 | return;
|
1647 | }
|
1648 | if (intentState.operatorList) {
|
1649 | intentState.operatorList.lastChunk = true;
|
1650 | for (const internalRenderTask of intentState.renderTasks) {
|
1651 | internalRenderTask.operatorListChanged();
|
1652 | }
|
1653 | this.#tryCleanup(true);
|
1654 | }
|
1655 | if (intentState.displayReadyCapability) {
|
1656 | intentState.displayReadyCapability.reject(reason);
|
1657 | } else if (intentState.opListReadCapability) {
|
1658 | intentState.opListReadCapability.reject(reason);
|
1659 | } else {
|
1660 | throw reason;
|
1661 | }
|
1662 | });
|
1663 | };
|
1664 | pump();
|
1665 | }
|
1666 | _abortOperatorList({
|
1667 | intentState,
|
1668 | reason,
|
1669 | force = false
|
1670 | }) {
|
1671 | if (!intentState.streamReader) {
|
1672 | return;
|
1673 | }
|
1674 | if (intentState.streamReaderCancelTimeout) {
|
1675 | clearTimeout(intentState.streamReaderCancelTimeout);
|
1676 | intentState.streamReaderCancelTimeout = null;
|
1677 | }
|
1678 | if (!force) {
|
1679 | if (intentState.renderTasks.size > 0) {
|
1680 | return;
|
1681 | }
|
1682 | if (reason instanceof _display_utils.RenderingCancelledException) {
|
1683 | let delay = RENDERING_CANCELLED_TIMEOUT;
|
1684 | if (reason.extraDelay > 0 && reason.extraDelay < 1000) {
|
1685 | delay += reason.extraDelay;
|
1686 | }
|
1687 | intentState.streamReaderCancelTimeout = setTimeout(() => {
|
1688 | intentState.streamReaderCancelTimeout = null;
|
1689 | this._abortOperatorList({
|
1690 | intentState,
|
1691 | reason,
|
1692 | force: true
|
1693 | });
|
1694 | }, delay);
|
1695 | return;
|
1696 | }
|
1697 | }
|
1698 | intentState.streamReader.cancel(new _util.AbortException(reason.message)).catch(() => {});
|
1699 | intentState.streamReader = null;
|
1700 | if (this._transport.destroyed) {
|
1701 | return;
|
1702 | }
|
1703 | for (const [curCacheKey, curIntentState] of this._intentStates) {
|
1704 | if (curIntentState === intentState) {
|
1705 | this._intentStates.delete(curCacheKey);
|
1706 | break;
|
1707 | }
|
1708 | }
|
1709 | this.cleanup();
|
1710 | }
|
1711 | get stats() {
|
1712 | return this._stats;
|
1713 | }
|
1714 | }
|
1715 | exports.PDFPageProxy = PDFPageProxy;
|
1716 | class LoopbackPort {
|
1717 | #listeners = new Set();
|
1718 | #deferred = Promise.resolve();
|
1719 | postMessage(obj, transfer) {
|
1720 | const event = {
|
1721 | data: structuredClone(obj, transfer ? {
|
1722 | transfer
|
1723 | } : null)
|
1724 | };
|
1725 | this.#deferred.then(() => {
|
1726 | for (const listener of this.#listeners) {
|
1727 | listener.call(this, event);
|
1728 | }
|
1729 | });
|
1730 | }
|
1731 | addEventListener(name, listener) {
|
1732 | this.#listeners.add(listener);
|
1733 | }
|
1734 | removeEventListener(name, listener) {
|
1735 | this.#listeners.delete(listener);
|
1736 | }
|
1737 | terminate() {
|
1738 | this.#listeners.clear();
|
1739 | }
|
1740 | }
|
1741 | exports.LoopbackPort = LoopbackPort;
|
1742 | const PDFWorkerUtil = {
|
1743 | isWorkerDisabled: false,
|
1744 | fallbackWorkerSrc: null,
|
1745 | fakeWorkerId: 0
|
1746 | };
|
1747 | exports.PDFWorkerUtil = PDFWorkerUtil;
|
1748 | {
|
1749 | if (_is_node.isNodeJS && typeof require === "function") {
|
1750 | PDFWorkerUtil.isWorkerDisabled = true;
|
1751 | PDFWorkerUtil.fallbackWorkerSrc = "./pdf.worker.js";
|
1752 | } else if (typeof document === "object") {
|
1753 | const pdfjsFilePath = document?.currentScript?.src;
|
1754 | if (pdfjsFilePath) {
|
1755 | PDFWorkerUtil.fallbackWorkerSrc = pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, ".worker$1$2");
|
1756 | }
|
1757 | }
|
1758 | PDFWorkerUtil.isSameOrigin = function (baseUrl, otherUrl) {
|
1759 | let base;
|
1760 | try {
|
1761 | base = new URL(baseUrl);
|
1762 | if (!base.origin || base.origin === "null") {
|
1763 | return false;
|
1764 | }
|
1765 | } catch (e) {
|
1766 | return false;
|
1767 | }
|
1768 | const other = new URL(otherUrl, base);
|
1769 | return base.origin === other.origin;
|
1770 | };
|
1771 | PDFWorkerUtil.createCDNWrapper = function (url) {
|
1772 | const wrapper = `importScripts("${url}");`;
|
1773 | return URL.createObjectURL(new Blob([wrapper]));
|
1774 | };
|
1775 | }
|
1776 | class PDFWorker {
|
1777 | static #workerPorts = new WeakMap();
|
1778 | constructor({
|
1779 | name = null,
|
1780 | port = null,
|
1781 | verbosity = (0, _util.getVerbosityLevel)()
|
1782 | } = {}) {
|
1783 | if (port && PDFWorker.#workerPorts.has(port)) {
|
1784 | throw new Error("Cannot use more than one PDFWorker per port.");
|
1785 | }
|
1786 | this.name = name;
|
1787 | this.destroyed = false;
|
1788 | this.verbosity = verbosity;
|
1789 | this._readyCapability = new _util.PromiseCapability();
|
1790 | this._port = null;
|
1791 | this._webWorker = null;
|
1792 | this._messageHandler = null;
|
1793 | if (port) {
|
1794 | PDFWorker.#workerPorts.set(port, this);
|
1795 | this._initializeFromPort(port);
|
1796 | return;
|
1797 | }
|
1798 | this._initialize();
|
1799 | }
|
1800 | get promise() {
|
1801 | return this._readyCapability.promise;
|
1802 | }
|
1803 | get port() {
|
1804 | return this._port;
|
1805 | }
|
1806 | get messageHandler() {
|
1807 | return this._messageHandler;
|
1808 | }
|
1809 | _initializeFromPort(port) {
|
1810 | this._port = port;
|
1811 | this._messageHandler = new _message_handler.MessageHandler("main", "worker", port);
|
1812 | this._messageHandler.on("ready", function () {});
|
1813 | this._readyCapability.resolve();
|
1814 | this._messageHandler.send("configure", {
|
1815 | verbosity: this.verbosity
|
1816 | });
|
1817 | }
|
1818 | _initialize() {
|
1819 | if (!PDFWorkerUtil.isWorkerDisabled && !PDFWorker._mainThreadWorkerMessageHandler) {
|
1820 | let {
|
1821 | workerSrc
|
1822 | } = PDFWorker;
|
1823 | try {
|
1824 | if (!PDFWorkerUtil.isSameOrigin(window.location.href, workerSrc)) {
|
1825 | workerSrc = PDFWorkerUtil.createCDNWrapper(new URL(workerSrc, window.location).href);
|
1826 | }
|
1827 | const worker = new Worker(workerSrc);
|
1828 | const messageHandler = new _message_handler.MessageHandler("main", "worker", worker);
|
1829 | const terminateEarly = () => {
|
1830 | worker.removeEventListener("error", onWorkerError);
|
1831 | messageHandler.destroy();
|
1832 | worker.terminate();
|
1833 | if (this.destroyed) {
|
1834 | this._readyCapability.reject(new Error("Worker was destroyed"));
|
1835 | } else {
|
1836 | this._setupFakeWorker();
|
1837 | }
|
1838 | };
|
1839 | const onWorkerError = () => {
|
1840 | if (!this._webWorker) {
|
1841 | terminateEarly();
|
1842 | }
|
1843 | };
|
1844 | worker.addEventListener("error", onWorkerError);
|
1845 | messageHandler.on("test", data => {
|
1846 | worker.removeEventListener("error", onWorkerError);
|
1847 | if (this.destroyed) {
|
1848 | terminateEarly();
|
1849 | return;
|
1850 | }
|
1851 | if (data) {
|
1852 | this._messageHandler = messageHandler;
|
1853 | this._port = worker;
|
1854 | this._webWorker = worker;
|
1855 | this._readyCapability.resolve();
|
1856 | messageHandler.send("configure", {
|
1857 | verbosity: this.verbosity
|
1858 | });
|
1859 | } else {
|
1860 | this._setupFakeWorker();
|
1861 | messageHandler.destroy();
|
1862 | worker.terminate();
|
1863 | }
|
1864 | });
|
1865 | messageHandler.on("ready", data => {
|
1866 | worker.removeEventListener("error", onWorkerError);
|
1867 | if (this.destroyed) {
|
1868 | terminateEarly();
|
1869 | return;
|
1870 | }
|
1871 | try {
|
1872 | sendTest();
|
1873 | } catch (e) {
|
1874 | this._setupFakeWorker();
|
1875 | }
|
1876 | });
|
1877 | const sendTest = () => {
|
1878 | const testObj = new Uint8Array();
|
1879 | messageHandler.send("test", testObj, [testObj.buffer]);
|
1880 | };
|
1881 | sendTest();
|
1882 | return;
|
1883 | } catch (e) {
|
1884 | (0, _util.info)("The worker has been disabled.");
|
1885 | }
|
1886 | }
|
1887 | this._setupFakeWorker();
|
1888 | }
|
1889 | _setupFakeWorker() {
|
1890 | if (!PDFWorkerUtil.isWorkerDisabled) {
|
1891 | (0, _util.warn)("Setting up fake worker.");
|
1892 | PDFWorkerUtil.isWorkerDisabled = true;
|
1893 | }
|
1894 | PDFWorker._setupFakeWorkerGlobal.then(WorkerMessageHandler => {
|
1895 | if (this.destroyed) {
|
1896 | this._readyCapability.reject(new Error("Worker was destroyed"));
|
1897 | return;
|
1898 | }
|
1899 | const port = new LoopbackPort();
|
1900 | this._port = port;
|
1901 | const id = `fake${PDFWorkerUtil.fakeWorkerId++}`;
|
1902 | const workerHandler = new _message_handler.MessageHandler(id + "_worker", id, port);
|
1903 | WorkerMessageHandler.setup(workerHandler, port);
|
1904 | const messageHandler = new _message_handler.MessageHandler(id, id + "_worker", port);
|
1905 | this._messageHandler = messageHandler;
|
1906 | this._readyCapability.resolve();
|
1907 | messageHandler.send("configure", {
|
1908 | verbosity: this.verbosity
|
1909 | });
|
1910 | }).catch(reason => {
|
1911 | this._readyCapability.reject(new Error(`Setting up fake worker failed: "${reason.message}".`));
|
1912 | });
|
1913 | }
|
1914 | destroy() {
|
1915 | this.destroyed = true;
|
1916 | if (this._webWorker) {
|
1917 | this._webWorker.terminate();
|
1918 | this._webWorker = null;
|
1919 | }
|
1920 | PDFWorker.#workerPorts.delete(this._port);
|
1921 | this._port = null;
|
1922 | if (this._messageHandler) {
|
1923 | this._messageHandler.destroy();
|
1924 | this._messageHandler = null;
|
1925 | }
|
1926 | }
|
1927 | static fromPort(params) {
|
1928 | if (!params?.port) {
|
1929 | throw new Error("PDFWorker.fromPort - invalid method signature.");
|
1930 | }
|
1931 | if (this.#workerPorts.has(params.port)) {
|
1932 | return this.#workerPorts.get(params.port);
|
1933 | }
|
1934 | return new PDFWorker(params);
|
1935 | }
|
1936 | static get workerSrc() {
|
1937 | if (_worker_options.GlobalWorkerOptions.workerSrc) {
|
1938 | return _worker_options.GlobalWorkerOptions.workerSrc;
|
1939 | }
|
1940 | if (PDFWorkerUtil.fallbackWorkerSrc !== null) {
|
1941 | if (!_is_node.isNodeJS) {
|
1942 | (0, _display_utils.deprecated)('No "GlobalWorkerOptions.workerSrc" specified.');
|
1943 | }
|
1944 | return PDFWorkerUtil.fallbackWorkerSrc;
|
1945 | }
|
1946 | throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
|
1947 | }
|
1948 | static get _mainThreadWorkerMessageHandler() {
|
1949 | try {
|
1950 | return globalThis.pdfjsWorker?.WorkerMessageHandler || null;
|
1951 | } catch (ex) {
|
1952 | return null;
|
1953 | }
|
1954 | }
|
1955 | static get _setupFakeWorkerGlobal() {
|
1956 | const loader = async () => {
|
1957 | const mainWorkerMessageHandler = this._mainThreadWorkerMessageHandler;
|
1958 | if (mainWorkerMessageHandler) {
|
1959 | return mainWorkerMessageHandler;
|
1960 | }
|
1961 | if (_is_node.isNodeJS && typeof require === "function") {
|
1962 | const worker = eval("require")(this.workerSrc);
|
1963 | return worker.WorkerMessageHandler;
|
1964 | }
|
1965 | await (0, _display_utils.loadScript)(this.workerSrc);
|
1966 | return window.pdfjsWorker.WorkerMessageHandler;
|
1967 | };
|
1968 | return (0, _util.shadow)(this, "_setupFakeWorkerGlobal", loader());
|
1969 | }
|
1970 | }
|
1971 | exports.PDFWorker = PDFWorker;
|
1972 | class WorkerTransport {
|
1973 | #methodPromises = new Map();
|
1974 | #pageCache = new Map();
|
1975 | #pagePromises = new Map();
|
1976 | constructor(messageHandler, loadingTask, networkStream, params, factory) {
|
1977 | this.messageHandler = messageHandler;
|
1978 | this.loadingTask = loadingTask;
|
1979 | this.commonObjs = new PDFObjects();
|
1980 | this.fontLoader = new _font_loader.FontLoader({
|
1981 | ownerDocument: params.ownerDocument,
|
1982 | styleElement: params.styleElement
|
1983 | });
|
1984 | this._params = params;
|
1985 | this.canvasFactory = factory.canvasFactory;
|
1986 | this.filterFactory = factory.filterFactory;
|
1987 | this.cMapReaderFactory = factory.cMapReaderFactory;
|
1988 | this.standardFontDataFactory = factory.standardFontDataFactory;
|
1989 | this.destroyed = false;
|
1990 | this.destroyCapability = null;
|
1991 | this._passwordCapability = null;
|
1992 | this._networkStream = networkStream;
|
1993 | this._fullReader = null;
|
1994 | this._lastProgress = null;
|
1995 | this.downloadInfoCapability = new _util.PromiseCapability();
|
1996 | this.setupMessageHandler();
|
1997 | }
|
1998 | #cacheSimpleMethod(name, data = null) {
|
1999 | const cachedPromise = this.#methodPromises.get(name);
|
2000 | if (cachedPromise) {
|
2001 | return cachedPromise;
|
2002 | }
|
2003 | const promise = this.messageHandler.sendWithPromise(name, data);
|
2004 | this.#methodPromises.set(name, promise);
|
2005 | return promise;
|
2006 | }
|
2007 | get annotationStorage() {
|
2008 | return (0, _util.shadow)(this, "annotationStorage", new _annotation_storage.AnnotationStorage());
|
2009 | }
|
2010 | getRenderingIntent(intent, annotationMode = _util.AnnotationMode.ENABLE, printAnnotationStorage = null, isOpList = false) {
|
2011 | let renderingIntent = _util.RenderingIntentFlag.DISPLAY;
|
2012 | let annotationMap = null;
|
2013 | switch (intent) {
|
2014 | case "any":
|
2015 | renderingIntent = _util.RenderingIntentFlag.ANY;
|
2016 | break;
|
2017 | case "display":
|
2018 | break;
|
2019 | case "print":
|
2020 | renderingIntent = _util.RenderingIntentFlag.PRINT;
|
2021 | break;
|
2022 | default:
|
2023 | (0, _util.warn)(`getRenderingIntent - invalid intent: ${intent}`);
|
2024 | }
|
2025 | switch (annotationMode) {
|
2026 | case _util.AnnotationMode.DISABLE:
|
2027 | renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_DISABLE;
|
2028 | break;
|
2029 | case _util.AnnotationMode.ENABLE:
|
2030 | break;
|
2031 | case _util.AnnotationMode.ENABLE_FORMS:
|
2032 | renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_FORMS;
|
2033 | break;
|
2034 | case _util.AnnotationMode.ENABLE_STORAGE:
|
2035 | renderingIntent += _util.RenderingIntentFlag.ANNOTATIONS_STORAGE;
|
2036 | const annotationStorage = renderingIntent & _util.RenderingIntentFlag.PRINT && printAnnotationStorage instanceof _annotation_storage.PrintAnnotationStorage ? printAnnotationStorage : this.annotationStorage;
|
2037 | annotationMap = annotationStorage.serializable;
|
2038 | break;
|
2039 | default:
|
2040 | (0, _util.warn)(`getRenderingIntent - invalid annotationMode: ${annotationMode}`);
|
2041 | }
|
2042 | if (isOpList) {
|
2043 | renderingIntent += _util.RenderingIntentFlag.OPLIST;
|
2044 | }
|
2045 | return {
|
2046 | renderingIntent,
|
2047 | cacheKey: `${renderingIntent}_${_annotation_storage.AnnotationStorage.getHash(annotationMap)}`,
|
2048 | annotationStorageMap: annotationMap
|
2049 | };
|
2050 | }
|
2051 | destroy() {
|
2052 | if (this.destroyCapability) {
|
2053 | return this.destroyCapability.promise;
|
2054 | }
|
2055 | this.destroyed = true;
|
2056 | this.destroyCapability = new _util.PromiseCapability();
|
2057 | if (this._passwordCapability) {
|
2058 | this._passwordCapability.reject(new Error("Worker was destroyed during onPassword callback"));
|
2059 | }
|
2060 | const waitOn = [];
|
2061 | for (const page of this.#pageCache.values()) {
|
2062 | waitOn.push(page._destroy());
|
2063 | }
|
2064 | this.#pageCache.clear();
|
2065 | this.#pagePromises.clear();
|
2066 | if (this.hasOwnProperty("annotationStorage")) {
|
2067 | this.annotationStorage.resetModified();
|
2068 | }
|
2069 | const terminated = this.messageHandler.sendWithPromise("Terminate", null);
|
2070 | waitOn.push(terminated);
|
2071 | Promise.all(waitOn).then(() => {
|
2072 | this.commonObjs.clear();
|
2073 | this.fontLoader.clear();
|
2074 | this.#methodPromises.clear();
|
2075 | this.filterFactory.destroy();
|
2076 | if (this._networkStream) {
|
2077 | this._networkStream.cancelAllRequests(new _util.AbortException("Worker was terminated."));
|
2078 | }
|
2079 | if (this.messageHandler) {
|
2080 | this.messageHandler.destroy();
|
2081 | this.messageHandler = null;
|
2082 | }
|
2083 | this.destroyCapability.resolve();
|
2084 | }, this.destroyCapability.reject);
|
2085 | return this.destroyCapability.promise;
|
2086 | }
|
2087 | setupMessageHandler() {
|
2088 | const {
|
2089 | messageHandler,
|
2090 | loadingTask
|
2091 | } = this;
|
2092 | messageHandler.on("GetReader", (data, sink) => {
|
2093 | (0, _util.assert)(this._networkStream, "GetReader - no `IPDFStream` instance available.");
|
2094 | this._fullReader = this._networkStream.getFullReader();
|
2095 | this._fullReader.onProgress = evt => {
|
2096 | this._lastProgress = {
|
2097 | loaded: evt.loaded,
|
2098 | total: evt.total
|
2099 | };
|
2100 | };
|
2101 | sink.onPull = () => {
|
2102 | this._fullReader.read().then(function ({
|
2103 | value,
|
2104 | done
|
2105 | }) {
|
2106 | if (done) {
|
2107 | sink.close();
|
2108 | return;
|
2109 | }
|
2110 | (0, _util.assert)(value instanceof ArrayBuffer, "GetReader - expected an ArrayBuffer.");
|
2111 | sink.enqueue(new Uint8Array(value), 1, [value]);
|
2112 | }).catch(reason => {
|
2113 | sink.error(reason);
|
2114 | });
|
2115 | };
|
2116 | sink.onCancel = reason => {
|
2117 | this._fullReader.cancel(reason);
|
2118 | sink.ready.catch(readyReason => {
|
2119 | if (this.destroyed) {
|
2120 | return;
|
2121 | }
|
2122 | throw readyReason;
|
2123 | });
|
2124 | };
|
2125 | });
|
2126 | messageHandler.on("ReaderHeadersReady", data => {
|
2127 | const headersCapability = new _util.PromiseCapability();
|
2128 | const fullReader = this._fullReader;
|
2129 | fullReader.headersReady.then(() => {
|
2130 | if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
|
2131 | if (this._lastProgress) {
|
2132 | loadingTask.onProgress?.(this._lastProgress);
|
2133 | }
|
2134 | fullReader.onProgress = evt => {
|
2135 | loadingTask.onProgress?.({
|
2136 | loaded: evt.loaded,
|
2137 | total: evt.total
|
2138 | });
|
2139 | };
|
2140 | }
|
2141 | headersCapability.resolve({
|
2142 | isStreamingSupported: fullReader.isStreamingSupported,
|
2143 | isRangeSupported: fullReader.isRangeSupported,
|
2144 | contentLength: fullReader.contentLength
|
2145 | });
|
2146 | }, headersCapability.reject);
|
2147 | return headersCapability.promise;
|
2148 | });
|
2149 | messageHandler.on("GetRangeReader", (data, sink) => {
|
2150 | (0, _util.assert)(this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
|
2151 | const rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
|
2152 | if (!rangeReader) {
|
2153 | sink.close();
|
2154 | return;
|
2155 | }
|
2156 | sink.onPull = () => {
|
2157 | rangeReader.read().then(function ({
|
2158 | value,
|
2159 | done
|
2160 | }) {
|
2161 | if (done) {
|
2162 | sink.close();
|
2163 | return;
|
2164 | }
|
2165 | (0, _util.assert)(value instanceof ArrayBuffer, "GetRangeReader - expected an ArrayBuffer.");
|
2166 | sink.enqueue(new Uint8Array(value), 1, [value]);
|
2167 | }).catch(reason => {
|
2168 | sink.error(reason);
|
2169 | });
|
2170 | };
|
2171 | sink.onCancel = reason => {
|
2172 | rangeReader.cancel(reason);
|
2173 | sink.ready.catch(readyReason => {
|
2174 | if (this.destroyed) {
|
2175 | return;
|
2176 | }
|
2177 | throw readyReason;
|
2178 | });
|
2179 | };
|
2180 | });
|
2181 | messageHandler.on("GetDoc", ({
|
2182 | pdfInfo
|
2183 | }) => {
|
2184 | this._numPages = pdfInfo.numPages;
|
2185 | this._htmlForXfa = pdfInfo.htmlForXfa;
|
2186 | delete pdfInfo.htmlForXfa;
|
2187 | loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
|
2188 | });
|
2189 | messageHandler.on("DocException", function (ex) {
|
2190 | let reason;
|
2191 | switch (ex.name) {
|
2192 | case "PasswordException":
|
2193 | reason = new _util.PasswordException(ex.message, ex.code);
|
2194 | break;
|
2195 | case "InvalidPDFException":
|
2196 | reason = new _util.InvalidPDFException(ex.message);
|
2197 | break;
|
2198 | case "MissingPDFException":
|
2199 | reason = new _util.MissingPDFException(ex.message);
|
2200 | break;
|
2201 | case "UnexpectedResponseException":
|
2202 | reason = new _util.UnexpectedResponseException(ex.message, ex.status);
|
2203 | break;
|
2204 | case "UnknownErrorException":
|
2205 | reason = new _util.UnknownErrorException(ex.message, ex.details);
|
2206 | break;
|
2207 | default:
|
2208 | (0, _util.unreachable)("DocException - expected a valid Error.");
|
2209 | }
|
2210 | loadingTask._capability.reject(reason);
|
2211 | });
|
2212 | messageHandler.on("PasswordRequest", exception => {
|
2213 | this._passwordCapability = new _util.PromiseCapability();
|
2214 | if (loadingTask.onPassword) {
|
2215 | const updatePassword = password => {
|
2216 | if (password instanceof Error) {
|
2217 | this._passwordCapability.reject(password);
|
2218 | } else {
|
2219 | this._passwordCapability.resolve({
|
2220 | password
|
2221 | });
|
2222 | }
|
2223 | };
|
2224 | try {
|
2225 | loadingTask.onPassword(updatePassword, exception.code);
|
2226 | } catch (ex) {
|
2227 | this._passwordCapability.reject(ex);
|
2228 | }
|
2229 | } else {
|
2230 | this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code));
|
2231 | }
|
2232 | return this._passwordCapability.promise;
|
2233 | });
|
2234 | messageHandler.on("DataLoaded", data => {
|
2235 | loadingTask.onProgress?.({
|
2236 | loaded: data.length,
|
2237 | total: data.length
|
2238 | });
|
2239 | this.downloadInfoCapability.resolve(data);
|
2240 | });
|
2241 | messageHandler.on("StartRenderPage", data => {
|
2242 | if (this.destroyed) {
|
2243 | return;
|
2244 | }
|
2245 | const page = this.#pageCache.get(data.pageIndex);
|
2246 | page._startRenderPage(data.transparency, data.cacheKey);
|
2247 | });
|
2248 | messageHandler.on("commonobj", ([id, type, exportedData]) => {
|
2249 | if (this.destroyed) {
|
2250 | return;
|
2251 | }
|
2252 | if (this.commonObjs.has(id)) {
|
2253 | return;
|
2254 | }
|
2255 | switch (type) {
|
2256 | case "Font":
|
2257 | const params = this._params;
|
2258 | if ("error" in exportedData) {
|
2259 | const exportedError = exportedData.error;
|
2260 | (0, _util.warn)(`Error during font loading: ${exportedError}`);
|
2261 | this.commonObjs.resolve(id, exportedError);
|
2262 | break;
|
2263 | }
|
2264 | const inspectFont = params.pdfBug && globalThis.FontInspector?.enabled ? (font, url) => globalThis.FontInspector.fontAdded(font, url) : null;
|
2265 | const font = new _font_loader.FontFaceObject(exportedData, {
|
2266 | isEvalSupported: params.isEvalSupported,
|
2267 | disableFontFace: params.disableFontFace,
|
2268 | ignoreErrors: params.ignoreErrors,
|
2269 | inspectFont
|
2270 | });
|
2271 | this.fontLoader.bind(font).catch(reason => {
|
2272 | return messageHandler.sendWithPromise("FontFallback", {
|
2273 | id
|
2274 | });
|
2275 | }).finally(() => {
|
2276 | if (!params.fontExtraProperties && font.data) {
|
2277 | font.data = null;
|
2278 | }
|
2279 | this.commonObjs.resolve(id, font);
|
2280 | });
|
2281 | break;
|
2282 | case "FontPath":
|
2283 | case "Image":
|
2284 | case "Pattern":
|
2285 | this.commonObjs.resolve(id, exportedData);
|
2286 | break;
|
2287 | default:
|
2288 | throw new Error(`Got unknown common object type ${type}`);
|
2289 | }
|
2290 | });
|
2291 | messageHandler.on("obj", ([id, pageIndex, type, imageData]) => {
|
2292 | if (this.destroyed) {
|
2293 | return;
|
2294 | }
|
2295 | const pageProxy = this.#pageCache.get(pageIndex);
|
2296 | if (pageProxy.objs.has(id)) {
|
2297 | return;
|
2298 | }
|
2299 | switch (type) {
|
2300 | case "Image":
|
2301 | pageProxy.objs.resolve(id, imageData);
|
2302 | if (imageData) {
|
2303 | let length;
|
2304 | if (imageData.bitmap) {
|
2305 | const {
|
2306 | width,
|
2307 | height
|
2308 | } = imageData;
|
2309 | length = width * height * 4;
|
2310 | } else {
|
2311 | length = imageData.data?.length || 0;
|
2312 | }
|
2313 | if (length > _util.MAX_IMAGE_SIZE_TO_CACHE) {
|
2314 | pageProxy._maybeCleanupAfterRender = true;
|
2315 | }
|
2316 | }
|
2317 | break;
|
2318 | case "Pattern":
|
2319 | pageProxy.objs.resolve(id, imageData);
|
2320 | break;
|
2321 | default:
|
2322 | throw new Error(`Got unknown object type ${type}`);
|
2323 | }
|
2324 | });
|
2325 | messageHandler.on("DocProgress", data => {
|
2326 | if (this.destroyed) {
|
2327 | return;
|
2328 | }
|
2329 | loadingTask.onProgress?.({
|
2330 | loaded: data.loaded,
|
2331 | total: data.total
|
2332 | });
|
2333 | });
|
2334 | messageHandler.on("FetchBuiltInCMap", data => {
|
2335 | if (this.destroyed) {
|
2336 | return Promise.reject(new Error("Worker was destroyed."));
|
2337 | }
|
2338 | if (!this.cMapReaderFactory) {
|
2339 | return Promise.reject(new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter."));
|
2340 | }
|
2341 | return this.cMapReaderFactory.fetch(data);
|
2342 | });
|
2343 | messageHandler.on("FetchStandardFontData", data => {
|
2344 | if (this.destroyed) {
|
2345 | return Promise.reject(new Error("Worker was destroyed."));
|
2346 | }
|
2347 | if (!this.standardFontDataFactory) {
|
2348 | return Promise.reject(new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter."));
|
2349 | }
|
2350 | return this.standardFontDataFactory.fetch(data);
|
2351 | });
|
2352 | }
|
2353 | getData() {
|
2354 | return this.messageHandler.sendWithPromise("GetData", null);
|
2355 | }
|
2356 | saveDocument() {
|
2357 | if (this.annotationStorage.size <= 0) {
|
2358 | (0, _util.warn)("saveDocument called while `annotationStorage` is empty, " + "please use the getData-method instead.");
|
2359 | }
|
2360 | return this.messageHandler.sendWithPromise("SaveDocument", {
|
2361 | isPureXfa: !!this._htmlForXfa,
|
2362 | numPages: this._numPages,
|
2363 | annotationStorage: this.annotationStorage.serializable,
|
2364 | filename: this._fullReader?.filename ?? null
|
2365 | }).finally(() => {
|
2366 | this.annotationStorage.resetModified();
|
2367 | });
|
2368 | }
|
2369 | getPage(pageNumber) {
|
2370 | if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
|
2371 | return Promise.reject(new Error("Invalid page request."));
|
2372 | }
|
2373 | const pageIndex = pageNumber - 1,
|
2374 | cachedPromise = this.#pagePromises.get(pageIndex);
|
2375 | if (cachedPromise) {
|
2376 | return cachedPromise;
|
2377 | }
|
2378 | const promise = this.messageHandler.sendWithPromise("GetPage", {
|
2379 | pageIndex
|
2380 | }).then(pageInfo => {
|
2381 | if (this.destroyed) {
|
2382 | throw new Error("Transport destroyed");
|
2383 | }
|
2384 | const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.pdfBug);
|
2385 | this.#pageCache.set(pageIndex, page);
|
2386 | return page;
|
2387 | });
|
2388 | this.#pagePromises.set(pageIndex, promise);
|
2389 | return promise;
|
2390 | }
|
2391 | getPageIndex(ref) {
|
2392 | if (typeof ref !== "object" || ref === null || !Number.isInteger(ref.num) || ref.num < 0 || !Number.isInteger(ref.gen) || ref.gen < 0) {
|
2393 | return Promise.reject(new Error("Invalid pageIndex request."));
|
2394 | }
|
2395 | return this.messageHandler.sendWithPromise("GetPageIndex", {
|
2396 | num: ref.num,
|
2397 | gen: ref.gen
|
2398 | });
|
2399 | }
|
2400 | getAnnotations(pageIndex, intent) {
|
2401 | return this.messageHandler.sendWithPromise("GetAnnotations", {
|
2402 | pageIndex,
|
2403 | intent
|
2404 | });
|
2405 | }
|
2406 | getFieldObjects() {
|
2407 | return this.#cacheSimpleMethod("GetFieldObjects");
|
2408 | }
|
2409 | hasJSActions() {
|
2410 | return this.#cacheSimpleMethod("HasJSActions");
|
2411 | }
|
2412 | getCalculationOrderIds() {
|
2413 | return this.messageHandler.sendWithPromise("GetCalculationOrderIds", null);
|
2414 | }
|
2415 | getDestinations() {
|
2416 | return this.messageHandler.sendWithPromise("GetDestinations", null);
|
2417 | }
|
2418 | getDestination(id) {
|
2419 | if (typeof id !== "string") {
|
2420 | return Promise.reject(new Error("Invalid destination request."));
|
2421 | }
|
2422 | return this.messageHandler.sendWithPromise("GetDestination", {
|
2423 | id
|
2424 | });
|
2425 | }
|
2426 | getPageLabels() {
|
2427 | return this.messageHandler.sendWithPromise("GetPageLabels", null);
|
2428 | }
|
2429 | getPageLayout() {
|
2430 | return this.messageHandler.sendWithPromise("GetPageLayout", null);
|
2431 | }
|
2432 | getPageMode() {
|
2433 | return this.messageHandler.sendWithPromise("GetPageMode", null);
|
2434 | }
|
2435 | getViewerPreferences() {
|
2436 | return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
|
2437 | }
|
2438 | getOpenAction() {
|
2439 | return this.messageHandler.sendWithPromise("GetOpenAction", null);
|
2440 | }
|
2441 | getAttachments() {
|
2442 | return this.messageHandler.sendWithPromise("GetAttachments", null);
|
2443 | }
|
2444 | getJavaScript() {
|
2445 | return this.messageHandler.sendWithPromise("GetJavaScript", null);
|
2446 | }
|
2447 | getDocJSActions() {
|
2448 | return this.messageHandler.sendWithPromise("GetDocJSActions", null);
|
2449 | }
|
2450 | getPageJSActions(pageIndex) {
|
2451 | return this.messageHandler.sendWithPromise("GetPageJSActions", {
|
2452 | pageIndex
|
2453 | });
|
2454 | }
|
2455 | getStructTree(pageIndex) {
|
2456 | return this.messageHandler.sendWithPromise("GetStructTree", {
|
2457 | pageIndex
|
2458 | });
|
2459 | }
|
2460 | getOutline() {
|
2461 | return this.messageHandler.sendWithPromise("GetOutline", null);
|
2462 | }
|
2463 | getOptionalContentConfig() {
|
2464 | return this.messageHandler.sendWithPromise("GetOptionalContentConfig", null).then(results => {
|
2465 | return new _optional_content_config.OptionalContentConfig(results);
|
2466 | });
|
2467 | }
|
2468 | getPermissions() {
|
2469 | return this.messageHandler.sendWithPromise("GetPermissions", null);
|
2470 | }
|
2471 | getMetadata() {
|
2472 | const name = "GetMetadata",
|
2473 | cachedPromise = this.#methodPromises.get(name);
|
2474 | if (cachedPromise) {
|
2475 | return cachedPromise;
|
2476 | }
|
2477 | const promise = this.messageHandler.sendWithPromise(name, null).then(results => {
|
2478 | return {
|
2479 | info: results[0],
|
2480 | metadata: results[1] ? new _metadata.Metadata(results[1]) : null,
|
2481 | contentDispositionFilename: this._fullReader?.filename ?? null,
|
2482 | contentLength: this._fullReader?.contentLength ?? null
|
2483 | };
|
2484 | });
|
2485 | this.#methodPromises.set(name, promise);
|
2486 | return promise;
|
2487 | }
|
2488 | getMarkInfo() {
|
2489 | return this.messageHandler.sendWithPromise("GetMarkInfo", null);
|
2490 | }
|
2491 | async startCleanup(keepLoadedFonts = false) {
|
2492 | if (this.destroyed) {
|
2493 | return;
|
2494 | }
|
2495 | await this.messageHandler.sendWithPromise("Cleanup", null);
|
2496 | for (const page of this.#pageCache.values()) {
|
2497 | const cleanupSuccessful = page.cleanup();
|
2498 | if (!cleanupSuccessful) {
|
2499 | throw new Error(`startCleanup: Page ${page.pageNumber} is currently rendering.`);
|
2500 | }
|
2501 | }
|
2502 | this.commonObjs.clear();
|
2503 | if (!keepLoadedFonts) {
|
2504 | this.fontLoader.clear();
|
2505 | }
|
2506 | this.#methodPromises.clear();
|
2507 | this.filterFactory.destroy(true);
|
2508 | }
|
2509 | get loadingParams() {
|
2510 | const {
|
2511 | disableAutoFetch,
|
2512 | enableXfa
|
2513 | } = this._params;
|
2514 | return (0, _util.shadow)(this, "loadingParams", {
|
2515 | disableAutoFetch,
|
2516 | enableXfa
|
2517 | });
|
2518 | }
|
2519 | }
|
2520 | class PDFObjects {
|
2521 | #objs = Object.create(null);
|
2522 | #ensureObj(objId) {
|
2523 | const obj = this.#objs[objId];
|
2524 | if (obj) {
|
2525 | return obj;
|
2526 | }
|
2527 | return this.#objs[objId] = {
|
2528 | capability: new _util.PromiseCapability(),
|
2529 | data: null
|
2530 | };
|
2531 | }
|
2532 | get(objId, callback = null) {
|
2533 | if (callback) {
|
2534 | const obj = this.#ensureObj(objId);
|
2535 | obj.capability.promise.then(() => callback(obj.data));
|
2536 | return null;
|
2537 | }
|
2538 | const obj = this.#objs[objId];
|
2539 | if (!obj?.capability.settled) {
|
2540 | throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
|
2541 | }
|
2542 | return obj.data;
|
2543 | }
|
2544 | has(objId) {
|
2545 | const obj = this.#objs[objId];
|
2546 | return obj?.capability.settled || false;
|
2547 | }
|
2548 | resolve(objId, data = null) {
|
2549 | const obj = this.#ensureObj(objId);
|
2550 | obj.data = data;
|
2551 | obj.capability.resolve();
|
2552 | }
|
2553 | clear() {
|
2554 | for (const objId in this.#objs) {
|
2555 | const {
|
2556 | data
|
2557 | } = this.#objs[objId];
|
2558 | data?.bitmap?.close();
|
2559 | }
|
2560 | this.#objs = Object.create(null);
|
2561 | }
|
2562 | }
|
2563 | class RenderTask {
|
2564 | #internalRenderTask = null;
|
2565 | constructor(internalRenderTask) {
|
2566 | this.#internalRenderTask = internalRenderTask;
|
2567 | this.onContinue = null;
|
2568 | }
|
2569 | get promise() {
|
2570 | return this.#internalRenderTask.capability.promise;
|
2571 | }
|
2572 | cancel(extraDelay = 0) {
|
2573 | this.#internalRenderTask.cancel(null, extraDelay);
|
2574 | }
|
2575 | get separateAnnots() {
|
2576 | const {
|
2577 | separateAnnots
|
2578 | } = this.#internalRenderTask.operatorList;
|
2579 | if (!separateAnnots) {
|
2580 | return false;
|
2581 | }
|
2582 | const {
|
2583 | annotationCanvasMap
|
2584 | } = this.#internalRenderTask;
|
2585 | return separateAnnots.form || separateAnnots.canvas && annotationCanvasMap?.size > 0;
|
2586 | }
|
2587 | }
|
2588 | exports.RenderTask = RenderTask;
|
2589 | class InternalRenderTask {
|
2590 | static #canvasInUse = new WeakSet();
|
2591 | constructor({
|
2592 | callback,
|
2593 | params,
|
2594 | objs,
|
2595 | commonObjs,
|
2596 | annotationCanvasMap,
|
2597 | operatorList,
|
2598 | pageIndex,
|
2599 | canvasFactory,
|
2600 | filterFactory,
|
2601 | useRequestAnimationFrame = false,
|
2602 | pdfBug = false,
|
2603 | pageColors = null
|
2604 | }) {
|
2605 | this.callback = callback;
|
2606 | this.params = params;
|
2607 | this.objs = objs;
|
2608 | this.commonObjs = commonObjs;
|
2609 | this.annotationCanvasMap = annotationCanvasMap;
|
2610 | this.operatorListIdx = null;
|
2611 | this.operatorList = operatorList;
|
2612 | this._pageIndex = pageIndex;
|
2613 | this.canvasFactory = canvasFactory;
|
2614 | this.filterFactory = filterFactory;
|
2615 | this._pdfBug = pdfBug;
|
2616 | this.pageColors = pageColors;
|
2617 | this.running = false;
|
2618 | this.graphicsReadyCallback = null;
|
2619 | this.graphicsReady = false;
|
2620 | this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
|
2621 | this.cancelled = false;
|
2622 | this.capability = new _util.PromiseCapability();
|
2623 | this.task = new RenderTask(this);
|
2624 | this._cancelBound = this.cancel.bind(this);
|
2625 | this._continueBound = this._continue.bind(this);
|
2626 | this._scheduleNextBound = this._scheduleNext.bind(this);
|
2627 | this._nextBound = this._next.bind(this);
|
2628 | this._canvas = params.canvasContext.canvas;
|
2629 | }
|
2630 | get completed() {
|
2631 | return this.capability.promise.catch(function () {});
|
2632 | }
|
2633 | initializeGraphics({
|
2634 | transparency = false,
|
2635 | optionalContentConfig
|
2636 | }) {
|
2637 | if (this.cancelled) {
|
2638 | return;
|
2639 | }
|
2640 | if (this._canvas) {
|
2641 | if (InternalRenderTask.#canvasInUse.has(this._canvas)) {
|
2642 | throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
|
2643 | }
|
2644 | InternalRenderTask.#canvasInUse.add(this._canvas);
|
2645 | }
|
2646 | if (this._pdfBug && globalThis.StepperManager?.enabled) {
|
2647 | this.stepper = globalThis.StepperManager.create(this._pageIndex);
|
2648 | this.stepper.init(this.operatorList);
|
2649 | this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
|
2650 | }
|
2651 | const {
|
2652 | canvasContext,
|
2653 | viewport,
|
2654 | transform,
|
2655 | background
|
2656 | } = this.params;
|
2657 | this.gfx = new _canvas.CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, this.filterFactory, {
|
2658 | optionalContentConfig
|
2659 | }, this.annotationCanvasMap, this.pageColors);
|
2660 | this.gfx.beginDrawing({
|
2661 | transform,
|
2662 | viewport,
|
2663 | transparency,
|
2664 | background
|
2665 | });
|
2666 | this.operatorListIdx = 0;
|
2667 | this.graphicsReady = true;
|
2668 | this.graphicsReadyCallback?.();
|
2669 | }
|
2670 | cancel(error = null, extraDelay = 0) {
|
2671 | this.running = false;
|
2672 | this.cancelled = true;
|
2673 | this.gfx?.endDrawing();
|
2674 | if (this._canvas) {
|
2675 | InternalRenderTask.#canvasInUse.delete(this._canvas);
|
2676 | }
|
2677 | this.callback(error || new _display_utils.RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, "canvas", extraDelay));
|
2678 | }
|
2679 | operatorListChanged() {
|
2680 | if (!this.graphicsReady) {
|
2681 | this.graphicsReadyCallback ||= this._continueBound;
|
2682 | return;
|
2683 | }
|
2684 | this.stepper?.updateOperatorList(this.operatorList);
|
2685 | if (this.running) {
|
2686 | return;
|
2687 | }
|
2688 | this._continue();
|
2689 | }
|
2690 | _continue() {
|
2691 | this.running = true;
|
2692 | if (this.cancelled) {
|
2693 | return;
|
2694 | }
|
2695 | if (this.task.onContinue) {
|
2696 | this.task.onContinue(this._scheduleNextBound);
|
2697 | } else {
|
2698 | this._scheduleNext();
|
2699 | }
|
2700 | }
|
2701 | _scheduleNext() {
|
2702 | if (this._useRequestAnimationFrame) {
|
2703 | window.requestAnimationFrame(() => {
|
2704 | this._nextBound().catch(this._cancelBound);
|
2705 | });
|
2706 | } else {
|
2707 | Promise.resolve().then(this._nextBound).catch(this._cancelBound);
|
2708 | }
|
2709 | }
|
2710 | async _next() {
|
2711 | if (this.cancelled) {
|
2712 | return;
|
2713 | }
|
2714 | this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
|
2715 | if (this.operatorListIdx === this.operatorList.argsArray.length) {
|
2716 | this.running = false;
|
2717 | if (this.operatorList.lastChunk) {
|
2718 | this.gfx.endDrawing(this.pageColors);
|
2719 | if (this._canvas) {
|
2720 | InternalRenderTask.#canvasInUse.delete(this._canvas);
|
2721 | }
|
2722 | this.callback();
|
2723 | }
|
2724 | }
|
2725 | }
|
2726 | }
|
2727 | const version = '3.7.107';
|
2728 | exports.version = version;
|
2729 | const build = '036f855dc';
|
2730 | exports.build = build;
|
2731 |
|
2732 | }),
|
2733 |
|
2734 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
2735 |
|
2736 |
|
2737 |
|
2738 | Object.defineProperty(exports, "__esModule", ({
|
2739 | value: true
|
2740 | }));
|
2741 | exports.PrintAnnotationStorage = exports.AnnotationStorage = void 0;
|
2742 | var _util = __w_pdfjs_require__(1);
|
2743 | var _editor = __w_pdfjs_require__(4);
|
2744 | var _murmurhash = __w_pdfjs_require__(8);
|
2745 | class AnnotationStorage {
|
2746 | #modified = false;
|
2747 | #storage = new Map();
|
2748 | constructor() {
|
2749 | this.onSetModified = null;
|
2750 | this.onResetModified = null;
|
2751 | this.onAnnotationEditor = null;
|
2752 | }
|
2753 | getValue(key, defaultValue) {
|
2754 | const value = this.#storage.get(key);
|
2755 | if (value === undefined) {
|
2756 | return defaultValue;
|
2757 | }
|
2758 | return Object.assign(defaultValue, value);
|
2759 | }
|
2760 | getRawValue(key) {
|
2761 | return this.#storage.get(key);
|
2762 | }
|
2763 | remove(key) {
|
2764 | this.#storage.delete(key);
|
2765 | if (this.#storage.size === 0) {
|
2766 | this.resetModified();
|
2767 | }
|
2768 | if (typeof this.onAnnotationEditor === "function") {
|
2769 | for (const value of this.#storage.values()) {
|
2770 | if (value instanceof _editor.AnnotationEditor) {
|
2771 | return;
|
2772 | }
|
2773 | }
|
2774 | this.onAnnotationEditor(null);
|
2775 | }
|
2776 | }
|
2777 | setValue(key, value) {
|
2778 | const obj = this.#storage.get(key);
|
2779 | let modified = false;
|
2780 | if (obj !== undefined) {
|
2781 | for (const [entry, val] of Object.entries(value)) {
|
2782 | if (obj[entry] !== val) {
|
2783 | modified = true;
|
2784 | obj[entry] = val;
|
2785 | }
|
2786 | }
|
2787 | } else {
|
2788 | modified = true;
|
2789 | this.#storage.set(key, value);
|
2790 | }
|
2791 | if (modified) {
|
2792 | this.#setModified();
|
2793 | }
|
2794 | if (value instanceof _editor.AnnotationEditor && typeof this.onAnnotationEditor === "function") {
|
2795 | this.onAnnotationEditor(value.constructor._type);
|
2796 | }
|
2797 | }
|
2798 | has(key) {
|
2799 | return this.#storage.has(key);
|
2800 | }
|
2801 | getAll() {
|
2802 | return this.#storage.size > 0 ? (0, _util.objectFromMap)(this.#storage) : null;
|
2803 | }
|
2804 | setAll(obj) {
|
2805 | for (const [key, val] of Object.entries(obj)) {
|
2806 | this.setValue(key, val);
|
2807 | }
|
2808 | }
|
2809 | get size() {
|
2810 | return this.#storage.size;
|
2811 | }
|
2812 | #setModified() {
|
2813 | if (!this.#modified) {
|
2814 | this.#modified = true;
|
2815 | if (typeof this.onSetModified === "function") {
|
2816 | this.onSetModified();
|
2817 | }
|
2818 | }
|
2819 | }
|
2820 | resetModified() {
|
2821 | if (this.#modified) {
|
2822 | this.#modified = false;
|
2823 | if (typeof this.onResetModified === "function") {
|
2824 | this.onResetModified();
|
2825 | }
|
2826 | }
|
2827 | }
|
2828 | get print() {
|
2829 | return new PrintAnnotationStorage(this);
|
2830 | }
|
2831 | get serializable() {
|
2832 | if (this.#storage.size === 0) {
|
2833 | return null;
|
2834 | }
|
2835 | const clone = new Map();
|
2836 | for (const [key, val] of this.#storage) {
|
2837 | const serialized = val instanceof _editor.AnnotationEditor ? val.serialize() : val;
|
2838 | if (serialized) {
|
2839 | clone.set(key, serialized);
|
2840 | }
|
2841 | }
|
2842 | return clone;
|
2843 | }
|
2844 | static getHash(map) {
|
2845 | if (!map) {
|
2846 | return "";
|
2847 | }
|
2848 | const hash = new _murmurhash.MurmurHash3_64();
|
2849 | for (const [key, val] of map) {
|
2850 | hash.update(`${key}:${JSON.stringify(val)}`);
|
2851 | }
|
2852 | return hash.hexdigest();
|
2853 | }
|
2854 | }
|
2855 | exports.AnnotationStorage = AnnotationStorage;
|
2856 | class PrintAnnotationStorage extends AnnotationStorage {
|
2857 | #serializable = null;
|
2858 | constructor(parent) {
|
2859 | super();
|
2860 | this.#serializable = structuredClone(parent.serializable);
|
2861 | }
|
2862 | get print() {
|
2863 | (0, _util.unreachable)("Should not call PrintAnnotationStorage.print");
|
2864 | }
|
2865 | get serializable() {
|
2866 | return this.#serializable;
|
2867 | }
|
2868 | }
|
2869 | exports.PrintAnnotationStorage = PrintAnnotationStorage;
|
2870 |
|
2871 | }),
|
2872 |
|
2873 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
2874 |
|
2875 |
|
2876 |
|
2877 | Object.defineProperty(exports, "__esModule", ({
|
2878 | value: true
|
2879 | }));
|
2880 | exports.AnnotationEditor = void 0;
|
2881 | var _tools = __w_pdfjs_require__(5);
|
2882 | var _util = __w_pdfjs_require__(1);
|
2883 | class AnnotationEditor {
|
2884 | #boundFocusin = this.focusin.bind(this);
|
2885 | #boundFocusout = this.focusout.bind(this);
|
2886 | #hasBeenSelected = false;
|
2887 | #isEditing = false;
|
2888 | #isInEditMode = false;
|
2889 | _uiManager = null;
|
2890 | #zIndex = AnnotationEditor._zIndex++;
|
2891 | static _colorManager = new _tools.ColorManager();
|
2892 | static _zIndex = 1;
|
2893 | constructor(parameters) {
|
2894 | if (this.constructor === AnnotationEditor) {
|
2895 | (0, _util.unreachable)("Cannot initialize AnnotationEditor.");
|
2896 | }
|
2897 | this.parent = parameters.parent;
|
2898 | this.id = parameters.id;
|
2899 | this.width = this.height = null;
|
2900 | this.pageIndex = parameters.parent.pageIndex;
|
2901 | this.name = parameters.name;
|
2902 | this.div = null;
|
2903 | this._uiManager = parameters.uiManager;
|
2904 | const {
|
2905 | rotation,
|
2906 | rawDims: {
|
2907 | pageWidth,
|
2908 | pageHeight,
|
2909 | pageX,
|
2910 | pageY
|
2911 | }
|
2912 | } = this.parent.viewport;
|
2913 | this.rotation = rotation;
|
2914 | this.pageRotation = (360 + rotation - this._uiManager.viewParameters.rotation) % 360;
|
2915 | this.pageDimensions = [pageWidth, pageHeight];
|
2916 | this.pageTranslation = [pageX, pageY];
|
2917 | const [width, height] = this.parentDimensions;
|
2918 | this.x = parameters.x / width;
|
2919 | this.y = parameters.y / height;
|
2920 | this.isAttachedToDOM = false;
|
2921 | }
|
2922 | static get _defaultLineColor() {
|
2923 | return (0, _util.shadow)(this, "_defaultLineColor", this._colorManager.getHexCode("CanvasText"));
|
2924 | }
|
2925 | addCommands(params) {
|
2926 | this._uiManager.addCommands(params);
|
2927 | }
|
2928 | get currentLayer() {
|
2929 | return this._uiManager.currentLayer;
|
2930 | }
|
2931 | setInBackground() {
|
2932 | this.div.style.zIndex = 0;
|
2933 | }
|
2934 | setInForeground() {
|
2935 | this.div.style.zIndex = this.#zIndex;
|
2936 | }
|
2937 | setParent(parent) {
|
2938 | if (parent !== null) {
|
2939 | this.pageIndex = parent.pageIndex;
|
2940 | this.pageDimensions = parent.pageDimensions;
|
2941 | }
|
2942 | this.parent = parent;
|
2943 | }
|
2944 | focusin(event) {
|
2945 | if (!this.#hasBeenSelected) {
|
2946 | this.parent.setSelected(this);
|
2947 | } else {
|
2948 | this.#hasBeenSelected = false;
|
2949 | }
|
2950 | }
|
2951 | focusout(event) {
|
2952 | if (!this.isAttachedToDOM) {
|
2953 | return;
|
2954 | }
|
2955 | const target = event.relatedTarget;
|
2956 | if (target?.closest(`#${this.id}`)) {
|
2957 | return;
|
2958 | }
|
2959 | event.preventDefault();
|
2960 | if (!this.parent?.isMultipleSelection) {
|
2961 | this.commitOrRemove();
|
2962 | }
|
2963 | }
|
2964 | commitOrRemove() {
|
2965 | if (this.isEmpty()) {
|
2966 | this.remove();
|
2967 | } else {
|
2968 | this.commit();
|
2969 | }
|
2970 | }
|
2971 | commit() {
|
2972 | this.addToAnnotationStorage();
|
2973 | }
|
2974 | addToAnnotationStorage() {
|
2975 | this._uiManager.addToAnnotationStorage(this);
|
2976 | }
|
2977 | dragstart(event) {
|
2978 | const rect = this.parent.div.getBoundingClientRect();
|
2979 | this.startX = event.clientX - rect.x;
|
2980 | this.startY = event.clientY - rect.y;
|
2981 | event.dataTransfer.setData("text/plain", this.id);
|
2982 | event.dataTransfer.effectAllowed = "move";
|
2983 | }
|
2984 | setAt(x, y, tx, ty) {
|
2985 | const [width, height] = this.parentDimensions;
|
2986 | [tx, ty] = this.screenToPageTranslation(tx, ty);
|
2987 | this.x = (x + tx) / width;
|
2988 | this.y = (y + ty) / height;
|
2989 | this.div.style.left = `${100 * this.x}%`;
|
2990 | this.div.style.top = `${100 * this.y}%`;
|
2991 | }
|
2992 | translate(x, y) {
|
2993 | const [width, height] = this.parentDimensions;
|
2994 | [x, y] = this.screenToPageTranslation(x, y);
|
2995 | this.x += x / width;
|
2996 | this.y += y / height;
|
2997 | this.div.style.left = `${100 * this.x}%`;
|
2998 | this.div.style.top = `${100 * this.y}%`;
|
2999 | }
|
3000 | screenToPageTranslation(x, y) {
|
3001 | switch (this.parentRotation) {
|
3002 | case 90:
|
3003 | return [y, -x];
|
3004 | case 180:
|
3005 | return [-x, -y];
|
3006 | case 270:
|
3007 | return [-y, x];
|
3008 | default:
|
3009 | return [x, y];
|
3010 | }
|
3011 | }
|
3012 | get parentScale() {
|
3013 | return this._uiManager.viewParameters.realScale;
|
3014 | }
|
3015 | get parentRotation() {
|
3016 | return (this._uiManager.viewParameters.rotation + this.pageRotation) % 360;
|
3017 | }
|
3018 | get parentDimensions() {
|
3019 | const {
|
3020 | realScale
|
3021 | } = this._uiManager.viewParameters;
|
3022 | const [pageWidth, pageHeight] = this.pageDimensions;
|
3023 | return [pageWidth * realScale, pageHeight * realScale];
|
3024 | }
|
3025 | setDims(width, height) {
|
3026 | const [parentWidth, parentHeight] = this.parentDimensions;
|
3027 | this.div.style.width = `${100 * width / parentWidth}%`;
|
3028 | this.div.style.height = `${100 * height / parentHeight}%`;
|
3029 | }
|
3030 | fixDims() {
|
3031 | const {
|
3032 | style
|
3033 | } = this.div;
|
3034 | const {
|
3035 | height,
|
3036 | width
|
3037 | } = style;
|
3038 | const widthPercent = width.endsWith("%");
|
3039 | const heightPercent = height.endsWith("%");
|
3040 | if (widthPercent && heightPercent) {
|
3041 | return;
|
3042 | }
|
3043 | const [parentWidth, parentHeight] = this.parentDimensions;
|
3044 | if (!widthPercent) {
|
3045 | style.width = `${100 * parseFloat(width) / parentWidth}%`;
|
3046 | }
|
3047 | if (!heightPercent) {
|
3048 | style.height = `${100 * parseFloat(height) / parentHeight}%`;
|
3049 | }
|
3050 | }
|
3051 | getInitialTranslation() {
|
3052 | return [0, 0];
|
3053 | }
|
3054 | render() {
|
3055 | this.div = document.createElement("div");
|
3056 | this.div.setAttribute("data-editor-rotation", (360 - this.rotation) % 360);
|
3057 | this.div.className = this.name;
|
3058 | this.div.setAttribute("id", this.id);
|
3059 | this.div.setAttribute("tabIndex", 0);
|
3060 | this.setInForeground();
|
3061 | this.div.addEventListener("focusin", this.#boundFocusin);
|
3062 | this.div.addEventListener("focusout", this.#boundFocusout);
|
3063 | const [tx, ty] = this.getInitialTranslation();
|
3064 | this.translate(tx, ty);
|
3065 | (0, _tools.bindEvents)(this, this.div, ["dragstart", "pointerdown"]);
|
3066 | return this.div;
|
3067 | }
|
3068 | pointerdown(event) {
|
3069 | const {
|
3070 | isMac
|
3071 | } = _util.FeatureTest.platform;
|
3072 | if (event.button !== 0 || event.ctrlKey && isMac) {
|
3073 | event.preventDefault();
|
3074 | return;
|
3075 | }
|
3076 | if (event.ctrlKey && !isMac || event.shiftKey || event.metaKey && isMac) {
|
3077 | this.parent.toggleSelected(this);
|
3078 | } else {
|
3079 | this.parent.setSelected(this);
|
3080 | }
|
3081 | this.#hasBeenSelected = true;
|
3082 | }
|
3083 | getRect(tx, ty) {
|
3084 | const scale = this.parentScale;
|
3085 | const [pageWidth, pageHeight] = this.pageDimensions;
|
3086 | const [pageX, pageY] = this.pageTranslation;
|
3087 | const shiftX = tx / scale;
|
3088 | const shiftY = ty / scale;
|
3089 | const x = this.x * pageWidth;
|
3090 | const y = this.y * pageHeight;
|
3091 | const width = this.width * pageWidth;
|
3092 | const height = this.height * pageHeight;
|
3093 | switch (this.rotation) {
|
3094 | case 0:
|
3095 | return [x + shiftX + pageX, pageHeight - y - shiftY - height + pageY, x + shiftX + width + pageX, pageHeight - y - shiftY + pageY];
|
3096 | case 90:
|
3097 | return [x + shiftY + pageX, pageHeight - y + shiftX + pageY, x + shiftY + height + pageX, pageHeight - y + shiftX + width + pageY];
|
3098 | case 180:
|
3099 | return [x - shiftX - width + pageX, pageHeight - y + shiftY + pageY, x - shiftX + pageX, pageHeight - y + shiftY + height + pageY];
|
3100 | case 270:
|
3101 | return [x - shiftY - height + pageX, pageHeight - y - shiftX - width + pageY, x - shiftY + pageX, pageHeight - y - shiftX + pageY];
|
3102 | default:
|
3103 | throw new Error("Invalid rotation");
|
3104 | }
|
3105 | }
|
3106 | getRectInCurrentCoords(rect, pageHeight) {
|
3107 | const [x1, y1, x2, y2] = rect;
|
3108 | const width = x2 - x1;
|
3109 | const height = y2 - y1;
|
3110 | switch (this.rotation) {
|
3111 | case 0:
|
3112 | return [x1, pageHeight - y2, width, height];
|
3113 | case 90:
|
3114 | return [x1, pageHeight - y1, height, width];
|
3115 | case 180:
|
3116 | return [x2, pageHeight - y1, width, height];
|
3117 | case 270:
|
3118 | return [x2, pageHeight - y2, height, width];
|
3119 | default:
|
3120 | throw new Error("Invalid rotation");
|
3121 | }
|
3122 | }
|
3123 | onceAdded() {}
|
3124 | isEmpty() {
|
3125 | return false;
|
3126 | }
|
3127 | enableEditMode() {
|
3128 | this.#isInEditMode = true;
|
3129 | }
|
3130 | disableEditMode() {
|
3131 | this.#isInEditMode = false;
|
3132 | }
|
3133 | isInEditMode() {
|
3134 | return this.#isInEditMode;
|
3135 | }
|
3136 | shouldGetKeyboardEvents() {
|
3137 | return false;
|
3138 | }
|
3139 | needsToBeRebuilt() {
|
3140 | return this.div && !this.isAttachedToDOM;
|
3141 | }
|
3142 | rebuild() {
|
3143 | this.div?.addEventListener("focusin", this.#boundFocusin);
|
3144 | }
|
3145 | serialize() {
|
3146 | (0, _util.unreachable)("An editor must be serializable");
|
3147 | }
|
3148 | static deserialize(data, parent, uiManager) {
|
3149 | const editor = new this.prototype.constructor({
|
3150 | parent,
|
3151 | id: parent.getNextId(),
|
3152 | uiManager
|
3153 | });
|
3154 | editor.rotation = data.rotation;
|
3155 | const [pageWidth, pageHeight] = editor.pageDimensions;
|
3156 | const [x, y, width, height] = editor.getRectInCurrentCoords(data.rect, pageHeight);
|
3157 | editor.x = x / pageWidth;
|
3158 | editor.y = y / pageHeight;
|
3159 | editor.width = width / pageWidth;
|
3160 | editor.height = height / pageHeight;
|
3161 | return editor;
|
3162 | }
|
3163 | remove() {
|
3164 | this.div.removeEventListener("focusin", this.#boundFocusin);
|
3165 | this.div.removeEventListener("focusout", this.#boundFocusout);
|
3166 | if (!this.isEmpty()) {
|
3167 | this.commit();
|
3168 | }
|
3169 | this.parent.remove(this);
|
3170 | }
|
3171 | select() {
|
3172 | this.div?.classList.add("selectedEditor");
|
3173 | }
|
3174 | unselect() {
|
3175 | this.div?.classList.remove("selectedEditor");
|
3176 | }
|
3177 | updateParams(type, value) {}
|
3178 | disableEditing() {}
|
3179 | enableEditing() {}
|
3180 | get propertiesToUpdate() {
|
3181 | return {};
|
3182 | }
|
3183 | get contentDiv() {
|
3184 | return this.div;
|
3185 | }
|
3186 | get isEditing() {
|
3187 | return this.#isEditing;
|
3188 | }
|
3189 | set isEditing(value) {
|
3190 | this.#isEditing = value;
|
3191 | if (value) {
|
3192 | this.parent.setSelected(this);
|
3193 | this.parent.setActiveEditor(this);
|
3194 | } else {
|
3195 | this.parent.setActiveEditor(null);
|
3196 | }
|
3197 | }
|
3198 | }
|
3199 | exports.AnnotationEditor = AnnotationEditor;
|
3200 |
|
3201 | }),
|
3202 |
|
3203 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
3204 |
|
3205 |
|
3206 |
|
3207 | Object.defineProperty(exports, "__esModule", ({
|
3208 | value: true
|
3209 | }));
|
3210 | exports.KeyboardManager = exports.CommandManager = exports.ColorManager = exports.AnnotationEditorUIManager = void 0;
|
3211 | exports.bindEvents = bindEvents;
|
3212 | exports.opacityToHex = opacityToHex;
|
3213 | var _util = __w_pdfjs_require__(1);
|
3214 | var _display_utils = __w_pdfjs_require__(6);
|
3215 | function bindEvents(obj, element, names) {
|
3216 | for (const name of names) {
|
3217 | element.addEventListener(name, obj[name].bind(obj));
|
3218 | }
|
3219 | }
|
3220 | function opacityToHex(opacity) {
|
3221 | return Math.round(Math.min(255, Math.max(1, 255 * opacity))).toString(16).padStart(2, "0");
|
3222 | }
|
3223 | class IdManager {
|
3224 | #id = 0;
|
3225 | getId() {
|
3226 | return `${_util.AnnotationEditorPrefix}${this.#id++}`;
|
3227 | }
|
3228 | }
|
3229 | class CommandManager {
|
3230 | #commands = [];
|
3231 | #locked = false;
|
3232 | #maxSize;
|
3233 | #position = -1;
|
3234 | constructor(maxSize = 128) {
|
3235 | this.#maxSize = maxSize;
|
3236 | }
|
3237 | add({
|
3238 | cmd,
|
3239 | undo,
|
3240 | mustExec,
|
3241 | type = NaN,
|
3242 | overwriteIfSameType = false,
|
3243 | keepUndo = false
|
3244 | }) {
|
3245 | if (mustExec) {
|
3246 | cmd();
|
3247 | }
|
3248 | if (this.#locked) {
|
3249 | return;
|
3250 | }
|
3251 | const save = {
|
3252 | cmd,
|
3253 | undo,
|
3254 | type
|
3255 | };
|
3256 | if (this.#position === -1) {
|
3257 | if (this.#commands.length > 0) {
|
3258 | this.#commands.length = 0;
|
3259 | }
|
3260 | this.#position = 0;
|
3261 | this.#commands.push(save);
|
3262 | return;
|
3263 | }
|
3264 | if (overwriteIfSameType && this.#commands[this.#position].type === type) {
|
3265 | if (keepUndo) {
|
3266 | save.undo = this.#commands[this.#position].undo;
|
3267 | }
|
3268 | this.#commands[this.#position] = save;
|
3269 | return;
|
3270 | }
|
3271 | const next = this.#position + 1;
|
3272 | if (next === this.#maxSize) {
|
3273 | this.#commands.splice(0, 1);
|
3274 | } else {
|
3275 | this.#position = next;
|
3276 | if (next < this.#commands.length) {
|
3277 | this.#commands.splice(next);
|
3278 | }
|
3279 | }
|
3280 | this.#commands.push(save);
|
3281 | }
|
3282 | undo() {
|
3283 | if (this.#position === -1) {
|
3284 | return;
|
3285 | }
|
3286 | this.#locked = true;
|
3287 | this.#commands[this.#position].undo();
|
3288 | this.#locked = false;
|
3289 | this.#position -= 1;
|
3290 | }
|
3291 | redo() {
|
3292 | if (this.#position < this.#commands.length - 1) {
|
3293 | this.#position += 1;
|
3294 | this.#locked = true;
|
3295 | this.#commands[this.#position].cmd();
|
3296 | this.#locked = false;
|
3297 | }
|
3298 | }
|
3299 | hasSomethingToUndo() {
|
3300 | return this.#position !== -1;
|
3301 | }
|
3302 | hasSomethingToRedo() {
|
3303 | return this.#position < this.#commands.length - 1;
|
3304 | }
|
3305 | destroy() {
|
3306 | this.#commands = null;
|
3307 | }
|
3308 | }
|
3309 | exports.CommandManager = CommandManager;
|
3310 | class KeyboardManager {
|
3311 | constructor(callbacks) {
|
3312 | this.buffer = [];
|
3313 | this.callbacks = new Map();
|
3314 | this.allKeys = new Set();
|
3315 | const {
|
3316 | isMac
|
3317 | } = _util.FeatureTest.platform;
|
3318 | for (const [keys, callback] of callbacks) {
|
3319 | for (const key of keys) {
|
3320 | const isMacKey = key.startsWith("mac+");
|
3321 | if (isMac && isMacKey) {
|
3322 | this.callbacks.set(key.slice(4), callback);
|
3323 | this.allKeys.add(key.split("+").at(-1));
|
3324 | } else if (!isMac && !isMacKey) {
|
3325 | this.callbacks.set(key, callback);
|
3326 | this.allKeys.add(key.split("+").at(-1));
|
3327 | }
|
3328 | }
|
3329 | }
|
3330 | }
|
3331 | #serialize(event) {
|
3332 | if (event.altKey) {
|
3333 | this.buffer.push("alt");
|
3334 | }
|
3335 | if (event.ctrlKey) {
|
3336 | this.buffer.push("ctrl");
|
3337 | }
|
3338 | if (event.metaKey) {
|
3339 | this.buffer.push("meta");
|
3340 | }
|
3341 | if (event.shiftKey) {
|
3342 | this.buffer.push("shift");
|
3343 | }
|
3344 | this.buffer.push(event.key);
|
3345 | const str = this.buffer.join("+");
|
3346 | this.buffer.length = 0;
|
3347 | return str;
|
3348 | }
|
3349 | exec(self, event) {
|
3350 | if (!this.allKeys.has(event.key)) {
|
3351 | return;
|
3352 | }
|
3353 | const callback = this.callbacks.get(this.#serialize(event));
|
3354 | if (!callback) {
|
3355 | return;
|
3356 | }
|
3357 | callback.bind(self)();
|
3358 | event.stopPropagation();
|
3359 | event.preventDefault();
|
3360 | }
|
3361 | }
|
3362 | exports.KeyboardManager = KeyboardManager;
|
3363 | class ColorManager {
|
3364 | static _colorsMapping = new Map([["CanvasText", [0, 0, 0]], ["Canvas", [255, 255, 255]]]);
|
3365 | get _colors() {
|
3366 | const colors = new Map([["CanvasText", null], ["Canvas", null]]);
|
3367 | (0, _display_utils.getColorValues)(colors);
|
3368 | return (0, _util.shadow)(this, "_colors", colors);
|
3369 | }
|
3370 | convert(color) {
|
3371 | const rgb = (0, _display_utils.getRGB)(color);
|
3372 | if (!window.matchMedia("(forced-colors: active)").matches) {
|
3373 | return rgb;
|
3374 | }
|
3375 | for (const [name, RGB] of this._colors) {
|
3376 | if (RGB.every((x, i) => x === rgb[i])) {
|
3377 | return ColorManager._colorsMapping.get(name);
|
3378 | }
|
3379 | }
|
3380 | return rgb;
|
3381 | }
|
3382 | getHexCode(name) {
|
3383 | const rgb = this._colors.get(name);
|
3384 | if (!rgb) {
|
3385 | return name;
|
3386 | }
|
3387 | return _util.Util.makeHexColor(...rgb);
|
3388 | }
|
3389 | }
|
3390 | exports.ColorManager = ColorManager;
|
3391 | class AnnotationEditorUIManager {
|
3392 | #activeEditor = null;
|
3393 | #allEditors = new Map();
|
3394 | #allLayers = new Map();
|
3395 | #annotationStorage = null;
|
3396 | #commandManager = new CommandManager();
|
3397 | #currentPageIndex = 0;
|
3398 | #editorTypes = null;
|
3399 | #editorsToRescale = new Set();
|
3400 | #eventBus = null;
|
3401 | #idManager = new IdManager();
|
3402 | #isEnabled = false;
|
3403 | #mode = _util.AnnotationEditorType.NONE;
|
3404 | #selectedEditors = new Set();
|
3405 | #boundCopy = this.copy.bind(this);
|
3406 | #boundCut = this.cut.bind(this);
|
3407 | #boundPaste = this.paste.bind(this);
|
3408 | #boundKeydown = this.keydown.bind(this);
|
3409 | #boundOnEditingAction = this.onEditingAction.bind(this);
|
3410 | #boundOnPageChanging = this.onPageChanging.bind(this);
|
3411 | #boundOnScaleChanging = this.onScaleChanging.bind(this);
|
3412 | #boundOnRotationChanging = this.onRotationChanging.bind(this);
|
3413 | #previousStates = {
|
3414 | isEditing: false,
|
3415 | isEmpty: true,
|
3416 | hasSomethingToUndo: false,
|
3417 | hasSomethingToRedo: false,
|
3418 | hasSelectedEditor: false
|
3419 | };
|
3420 | #container = null;
|
3421 | static _keyboardManager = new KeyboardManager([[["ctrl+a", "mac+meta+a"], AnnotationEditorUIManager.prototype.selectAll], [["ctrl+z", "mac+meta+z"], AnnotationEditorUIManager.prototype.undo], [["ctrl+y", "ctrl+shift+Z", "mac+meta+shift+Z"], AnnotationEditorUIManager.prototype.redo], [["Backspace", "alt+Backspace", "ctrl+Backspace", "shift+Backspace", "mac+Backspace", "mac+alt+Backspace", "mac+ctrl+Backspace", "Delete", "ctrl+Delete", "shift+Delete"], AnnotationEditorUIManager.prototype.delete], [["Escape", "mac+Escape"], AnnotationEditorUIManager.prototype.unselectAll]]);
|
3422 | constructor(container, eventBus, annotationStorage) {
|
3423 | this.#container = container;
|
3424 | this.#eventBus = eventBus;
|
3425 | this.#eventBus._on("editingaction", this.#boundOnEditingAction);
|
3426 | this.#eventBus._on("pagechanging", this.#boundOnPageChanging);
|
3427 | this.#eventBus._on("scalechanging", this.#boundOnScaleChanging);
|
3428 | this.#eventBus._on("rotationchanging", this.#boundOnRotationChanging);
|
3429 | this.#annotationStorage = annotationStorage;
|
3430 | this.viewParameters = {
|
3431 | realScale: _display_utils.PixelsPerInch.PDF_TO_CSS_UNITS,
|
3432 | rotation: 0
|
3433 | };
|
3434 | }
|
3435 | destroy() {
|
3436 | this.#removeKeyboardManager();
|
3437 | this.#eventBus._off("editingaction", this.#boundOnEditingAction);
|
3438 | this.#eventBus._off("pagechanging", this.#boundOnPageChanging);
|
3439 | this.#eventBus._off("scalechanging", this.#boundOnScaleChanging);
|
3440 | this.#eventBus._off("rotationchanging", this.#boundOnRotationChanging);
|
3441 | for (const layer of this.#allLayers.values()) {
|
3442 | layer.destroy();
|
3443 | }
|
3444 | this.#allLayers.clear();
|
3445 | this.#allEditors.clear();
|
3446 | this.#editorsToRescale.clear();
|
3447 | this.#activeEditor = null;
|
3448 | this.#selectedEditors.clear();
|
3449 | this.#commandManager.destroy();
|
3450 | }
|
3451 | onPageChanging({
|
3452 | pageNumber
|
3453 | }) {
|
3454 | this.#currentPageIndex = pageNumber - 1;
|
3455 | }
|
3456 | focusMainContainer() {
|
3457 | this.#container.focus();
|
3458 | }
|
3459 | addShouldRescale(editor) {
|
3460 | this.#editorsToRescale.add(editor);
|
3461 | }
|
3462 | removeShouldRescale(editor) {
|
3463 | this.#editorsToRescale.delete(editor);
|
3464 | }
|
3465 | onScaleChanging({
|
3466 | scale
|
3467 | }) {
|
3468 | this.commitOrRemove();
|
3469 | this.viewParameters.realScale = scale * _display_utils.PixelsPerInch.PDF_TO_CSS_UNITS;
|
3470 | for (const editor of this.#editorsToRescale) {
|
3471 | editor.onScaleChanging();
|
3472 | }
|
3473 | }
|
3474 | onRotationChanging({
|
3475 | pagesRotation
|
3476 | }) {
|
3477 | this.commitOrRemove();
|
3478 | this.viewParameters.rotation = pagesRotation;
|
3479 | }
|
3480 | addToAnnotationStorage(editor) {
|
3481 | if (!editor.isEmpty() && this.#annotationStorage && !this.#annotationStorage.has(editor.id)) {
|
3482 | this.#annotationStorage.setValue(editor.id, editor);
|
3483 | }
|
3484 | }
|
3485 | #addKeyboardManager() {
|
3486 | this.#container.addEventListener("keydown", this.#boundKeydown);
|
3487 | }
|
3488 | #removeKeyboardManager() {
|
3489 | this.#container.removeEventListener("keydown", this.#boundKeydown);
|
3490 | }
|
3491 | #addCopyPasteListeners() {
|
3492 | document.addEventListener("copy", this.#boundCopy);
|
3493 | document.addEventListener("cut", this.#boundCut);
|
3494 | document.addEventListener("paste", this.#boundPaste);
|
3495 | }
|
3496 | #removeCopyPasteListeners() {
|
3497 | document.removeEventListener("copy", this.#boundCopy);
|
3498 | document.removeEventListener("cut", this.#boundCut);
|
3499 | document.removeEventListener("paste", this.#boundPaste);
|
3500 | }
|
3501 | copy(event) {
|
3502 | event.preventDefault();
|
3503 | if (this.#activeEditor) {
|
3504 | this.#activeEditor.commitOrRemove();
|
3505 | }
|
3506 | if (!this.hasSelection) {
|
3507 | return;
|
3508 | }
|
3509 | const editors = [];
|
3510 | for (const editor of this.#selectedEditors) {
|
3511 | if (!editor.isEmpty()) {
|
3512 | editors.push(editor.serialize());
|
3513 | }
|
3514 | }
|
3515 | if (editors.length === 0) {
|
3516 | return;
|
3517 | }
|
3518 | event.clipboardData.setData("application/pdfjs", JSON.stringify(editors));
|
3519 | }
|
3520 | cut(event) {
|
3521 | this.copy(event);
|
3522 | this.delete();
|
3523 | }
|
3524 | paste(event) {
|
3525 | event.preventDefault();
|
3526 | let data = event.clipboardData.getData("application/pdfjs");
|
3527 | if (!data) {
|
3528 | return;
|
3529 | }
|
3530 | try {
|
3531 | data = JSON.parse(data);
|
3532 | } catch (ex) {
|
3533 | (0, _util.warn)(`paste: "${ex.message}".`);
|
3534 | return;
|
3535 | }
|
3536 | if (!Array.isArray(data)) {
|
3537 | return;
|
3538 | }
|
3539 | this.unselectAll();
|
3540 | const layer = this.#allLayers.get(this.#currentPageIndex);
|
3541 | try {
|
3542 | const newEditors = [];
|
3543 | for (const editor of data) {
|
3544 | const deserializedEditor = layer.deserialize(editor);
|
3545 | if (!deserializedEditor) {
|
3546 | return;
|
3547 | }
|
3548 | newEditors.push(deserializedEditor);
|
3549 | }
|
3550 | const cmd = () => {
|
3551 | for (const editor of newEditors) {
|
3552 | this.#addEditorToLayer(editor);
|
3553 | }
|
3554 | this.#selectEditors(newEditors);
|
3555 | };
|
3556 | const undo = () => {
|
3557 | for (const editor of newEditors) {
|
3558 | editor.remove();
|
3559 | }
|
3560 | };
|
3561 | this.addCommands({
|
3562 | cmd,
|
3563 | undo,
|
3564 | mustExec: true
|
3565 | });
|
3566 | } catch (ex) {
|
3567 | (0, _util.warn)(`paste: "${ex.message}".`);
|
3568 | }
|
3569 | }
|
3570 | keydown(event) {
|
3571 | if (!this.getActive()?.shouldGetKeyboardEvents()) {
|
3572 | AnnotationEditorUIManager._keyboardManager.exec(this, event);
|
3573 | }
|
3574 | }
|
3575 | onEditingAction(details) {
|
3576 | if (["undo", "redo", "delete", "selectAll"].includes(details.name)) {
|
3577 | this[details.name]();
|
3578 | }
|
3579 | }
|
3580 | #dispatchUpdateStates(details) {
|
3581 | const hasChanged = Object.entries(details).some(([key, value]) => this.#previousStates[key] !== value);
|
3582 | if (hasChanged) {
|
3583 | this.#eventBus.dispatch("annotationeditorstateschanged", {
|
3584 | source: this,
|
3585 | details: Object.assign(this.#previousStates, details)
|
3586 | });
|
3587 | }
|
3588 | }
|
3589 | #dispatchUpdateUI(details) {
|
3590 | this.#eventBus.dispatch("annotationeditorparamschanged", {
|
3591 | source: this,
|
3592 | details
|
3593 | });
|
3594 | }
|
3595 | setEditingState(isEditing) {
|
3596 | if (isEditing) {
|
3597 | this.#addKeyboardManager();
|
3598 | this.#addCopyPasteListeners();
|
3599 | this.#dispatchUpdateStates({
|
3600 | isEditing: this.#mode !== _util.AnnotationEditorType.NONE,
|
3601 | isEmpty: this.#isEmpty(),
|
3602 | hasSomethingToUndo: this.#commandManager.hasSomethingToUndo(),
|
3603 | hasSomethingToRedo: this.#commandManager.hasSomethingToRedo(),
|
3604 | hasSelectedEditor: false
|
3605 | });
|
3606 | } else {
|
3607 | this.#removeKeyboardManager();
|
3608 | this.#removeCopyPasteListeners();
|
3609 | this.#dispatchUpdateStates({
|
3610 | isEditing: false
|
3611 | });
|
3612 | }
|
3613 | }
|
3614 | registerEditorTypes(types) {
|
3615 | if (this.#editorTypes) {
|
3616 | return;
|
3617 | }
|
3618 | this.#editorTypes = types;
|
3619 | for (const editorType of this.#editorTypes) {
|
3620 | this.#dispatchUpdateUI(editorType.defaultPropertiesToUpdate);
|
3621 | }
|
3622 | }
|
3623 | getId() {
|
3624 | return this.#idManager.getId();
|
3625 | }
|
3626 | get currentLayer() {
|
3627 | return this.#allLayers.get(this.#currentPageIndex);
|
3628 | }
|
3629 | get currentPageIndex() {
|
3630 | return this.#currentPageIndex;
|
3631 | }
|
3632 | addLayer(layer) {
|
3633 | this.#allLayers.set(layer.pageIndex, layer);
|
3634 | if (this.#isEnabled) {
|
3635 | layer.enable();
|
3636 | } else {
|
3637 | layer.disable();
|
3638 | }
|
3639 | }
|
3640 | removeLayer(layer) {
|
3641 | this.#allLayers.delete(layer.pageIndex);
|
3642 | }
|
3643 | updateMode(mode) {
|
3644 | this.#mode = mode;
|
3645 | if (mode === _util.AnnotationEditorType.NONE) {
|
3646 | this.setEditingState(false);
|
3647 | this.#disableAll();
|
3648 | } else {
|
3649 | this.setEditingState(true);
|
3650 | this.#enableAll();
|
3651 | for (const layer of this.#allLayers.values()) {
|
3652 | layer.updateMode(mode);
|
3653 | }
|
3654 | }
|
3655 | }
|
3656 | updateToolbar(mode) {
|
3657 | if (mode === this.#mode) {
|
3658 | return;
|
3659 | }
|
3660 | this.#eventBus.dispatch("switchannotationeditormode", {
|
3661 | source: this,
|
3662 | mode
|
3663 | });
|
3664 | }
|
3665 | updateParams(type, value) {
|
3666 | if (!this.#editorTypes) {
|
3667 | return;
|
3668 | }
|
3669 | for (const editor of this.#selectedEditors) {
|
3670 | editor.updateParams(type, value);
|
3671 | }
|
3672 | for (const editorType of this.#editorTypes) {
|
3673 | editorType.updateDefaultParams(type, value);
|
3674 | }
|
3675 | }
|
3676 | #enableAll() {
|
3677 | if (!this.#isEnabled) {
|
3678 | this.#isEnabled = true;
|
3679 | for (const layer of this.#allLayers.values()) {
|
3680 | layer.enable();
|
3681 | }
|
3682 | }
|
3683 | }
|
3684 | #disableAll() {
|
3685 | this.unselectAll();
|
3686 | if (this.#isEnabled) {
|
3687 | this.#isEnabled = false;
|
3688 | for (const layer of this.#allLayers.values()) {
|
3689 | layer.disable();
|
3690 | }
|
3691 | }
|
3692 | }
|
3693 | getEditors(pageIndex) {
|
3694 | const editors = [];
|
3695 | for (const editor of this.#allEditors.values()) {
|
3696 | if (editor.pageIndex === pageIndex) {
|
3697 | editors.push(editor);
|
3698 | }
|
3699 | }
|
3700 | return editors;
|
3701 | }
|
3702 | getEditor(id) {
|
3703 | return this.#allEditors.get(id);
|
3704 | }
|
3705 | addEditor(editor) {
|
3706 | this.#allEditors.set(editor.id, editor);
|
3707 | }
|
3708 | removeEditor(editor) {
|
3709 | this.#allEditors.delete(editor.id);
|
3710 | this.unselect(editor);
|
3711 | this.#annotationStorage?.remove(editor.id);
|
3712 | }
|
3713 | #addEditorToLayer(editor) {
|
3714 | const layer = this.#allLayers.get(editor.pageIndex);
|
3715 | if (layer) {
|
3716 | layer.addOrRebuild(editor);
|
3717 | } else {
|
3718 | this.addEditor(editor);
|
3719 | }
|
3720 | }
|
3721 | setActiveEditor(editor) {
|
3722 | if (this.#activeEditor === editor) {
|
3723 | return;
|
3724 | }
|
3725 | this.#activeEditor = editor;
|
3726 | if (editor) {
|
3727 | this.#dispatchUpdateUI(editor.propertiesToUpdate);
|
3728 | }
|
3729 | }
|
3730 | toggleSelected(editor) {
|
3731 | if (this.#selectedEditors.has(editor)) {
|
3732 | this.#selectedEditors.delete(editor);
|
3733 | editor.unselect();
|
3734 | this.#dispatchUpdateStates({
|
3735 | hasSelectedEditor: this.hasSelection
|
3736 | });
|
3737 | return;
|
3738 | }
|
3739 | this.#selectedEditors.add(editor);
|
3740 | editor.select();
|
3741 | this.#dispatchUpdateUI(editor.propertiesToUpdate);
|
3742 | this.#dispatchUpdateStates({
|
3743 | hasSelectedEditor: true
|
3744 | });
|
3745 | }
|
3746 | setSelected(editor) {
|
3747 | for (const ed of this.#selectedEditors) {
|
3748 | if (ed !== editor) {
|
3749 | ed.unselect();
|
3750 | }
|
3751 | }
|
3752 | this.#selectedEditors.clear();
|
3753 | this.#selectedEditors.add(editor);
|
3754 | editor.select();
|
3755 | this.#dispatchUpdateUI(editor.propertiesToUpdate);
|
3756 | this.#dispatchUpdateStates({
|
3757 | hasSelectedEditor: true
|
3758 | });
|
3759 | }
|
3760 | isSelected(editor) {
|
3761 | return this.#selectedEditors.has(editor);
|
3762 | }
|
3763 | unselect(editor) {
|
3764 | editor.unselect();
|
3765 | this.#selectedEditors.delete(editor);
|
3766 | this.#dispatchUpdateStates({
|
3767 | hasSelectedEditor: this.hasSelection
|
3768 | });
|
3769 | }
|
3770 | get hasSelection() {
|
3771 | return this.#selectedEditors.size !== 0;
|
3772 | }
|
3773 | undo() {
|
3774 | this.#commandManager.undo();
|
3775 | this.#dispatchUpdateStates({
|
3776 | hasSomethingToUndo: this.#commandManager.hasSomethingToUndo(),
|
3777 | hasSomethingToRedo: true,
|
3778 | isEmpty: this.#isEmpty()
|
3779 | });
|
3780 | }
|
3781 | redo() {
|
3782 | this.#commandManager.redo();
|
3783 | this.#dispatchUpdateStates({
|
3784 | hasSomethingToUndo: true,
|
3785 | hasSomethingToRedo: this.#commandManager.hasSomethingToRedo(),
|
3786 | isEmpty: this.#isEmpty()
|
3787 | });
|
3788 | }
|
3789 | addCommands(params) {
|
3790 | this.#commandManager.add(params);
|
3791 | this.#dispatchUpdateStates({
|
3792 | hasSomethingToUndo: true,
|
3793 | hasSomethingToRedo: false,
|
3794 | isEmpty: this.#isEmpty()
|
3795 | });
|
3796 | }
|
3797 | #isEmpty() {
|
3798 | if (this.#allEditors.size === 0) {
|
3799 | return true;
|
3800 | }
|
3801 | if (this.#allEditors.size === 1) {
|
3802 | for (const editor of this.#allEditors.values()) {
|
3803 | return editor.isEmpty();
|
3804 | }
|
3805 | }
|
3806 | return false;
|
3807 | }
|
3808 | delete() {
|
3809 | this.commitOrRemove();
|
3810 | if (!this.hasSelection) {
|
3811 | return;
|
3812 | }
|
3813 | const editors = [...this.#selectedEditors];
|
3814 | const cmd = () => {
|
3815 | for (const editor of editors) {
|
3816 | editor.remove();
|
3817 | }
|
3818 | };
|
3819 | const undo = () => {
|
3820 | for (const editor of editors) {
|
3821 | this.#addEditorToLayer(editor);
|
3822 | }
|
3823 | };
|
3824 | this.addCommands({
|
3825 | cmd,
|
3826 | undo,
|
3827 | mustExec: true
|
3828 | });
|
3829 | }
|
3830 | commitOrRemove() {
|
3831 | this.#activeEditor?.commitOrRemove();
|
3832 | }
|
3833 | #selectEditors(editors) {
|
3834 | this.#selectedEditors.clear();
|
3835 | for (const editor of editors) {
|
3836 | if (editor.isEmpty()) {
|
3837 | continue;
|
3838 | }
|
3839 | this.#selectedEditors.add(editor);
|
3840 | editor.select();
|
3841 | }
|
3842 | this.#dispatchUpdateStates({
|
3843 | hasSelectedEditor: true
|
3844 | });
|
3845 | }
|
3846 | selectAll() {
|
3847 | for (const editor of this.#selectedEditors) {
|
3848 | editor.commit();
|
3849 | }
|
3850 | this.#selectEditors(this.#allEditors.values());
|
3851 | }
|
3852 | unselectAll() {
|
3853 | if (this.#activeEditor) {
|
3854 | this.#activeEditor.commitOrRemove();
|
3855 | return;
|
3856 | }
|
3857 | if (this.#selectedEditors.size === 0) {
|
3858 | return;
|
3859 | }
|
3860 | for (const editor of this.#selectedEditors) {
|
3861 | editor.unselect();
|
3862 | }
|
3863 | this.#selectedEditors.clear();
|
3864 | this.#dispatchUpdateStates({
|
3865 | hasSelectedEditor: false
|
3866 | });
|
3867 | }
|
3868 | isActive(editor) {
|
3869 | return this.#activeEditor === editor;
|
3870 | }
|
3871 | getActive() {
|
3872 | return this.#activeEditor;
|
3873 | }
|
3874 | getMode() {
|
3875 | return this.#mode;
|
3876 | }
|
3877 | }
|
3878 | exports.AnnotationEditorUIManager = AnnotationEditorUIManager;
|
3879 |
|
3880 | }),
|
3881 |
|
3882 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
3883 |
|
3884 |
|
3885 |
|
3886 | Object.defineProperty(exports, "__esModule", ({
|
3887 | value: true
|
3888 | }));
|
3889 | exports.StatTimer = exports.RenderingCancelledException = exports.PixelsPerInch = exports.PageViewport = exports.PDFDateString = exports.DOMStandardFontDataFactory = exports.DOMSVGFactory = exports.DOMFilterFactory = exports.DOMCanvasFactory = exports.DOMCMapReaderFactory = exports.AnnotationPrefix = void 0;
|
3890 | exports.deprecated = deprecated;
|
3891 | exports.getColorValues = getColorValues;
|
3892 | exports.getCurrentTransform = getCurrentTransform;
|
3893 | exports.getCurrentTransformInverse = getCurrentTransformInverse;
|
3894 | exports.getFilenameFromUrl = getFilenameFromUrl;
|
3895 | exports.getPdfFilenameFromUrl = getPdfFilenameFromUrl;
|
3896 | exports.getRGB = getRGB;
|
3897 | exports.getXfaPageViewport = getXfaPageViewport;
|
3898 | exports.isDataScheme = isDataScheme;
|
3899 | exports.isPdfFile = isPdfFile;
|
3900 | exports.isValidFetchUrl = isValidFetchUrl;
|
3901 | exports.loadScript = loadScript;
|
3902 | exports.setLayerDimensions = setLayerDimensions;
|
3903 | var _base_factory = __w_pdfjs_require__(7);
|
3904 | var _util = __w_pdfjs_require__(1);
|
3905 | const SVG_NS = "http://www.w3.org/2000/svg";
|
3906 | const AnnotationPrefix = "pdfjs_internal_id_";
|
3907 | exports.AnnotationPrefix = AnnotationPrefix;
|
3908 | class PixelsPerInch {
|
3909 | static CSS = 96.0;
|
3910 | static PDF = 72.0;
|
3911 | static PDF_TO_CSS_UNITS = this.CSS / this.PDF;
|
3912 | }
|
3913 | exports.PixelsPerInch = PixelsPerInch;
|
3914 | class DOMFilterFactory extends _base_factory.BaseFilterFactory {
|
3915 | #_cache;
|
3916 | #_defs;
|
3917 | #docId;
|
3918 | #document;
|
3919 | #hcmFilter;
|
3920 | #hcmKey;
|
3921 | #hcmUrl;
|
3922 | #id = 0;
|
3923 | constructor({
|
3924 | docId,
|
3925 | ownerDocument = globalThis.document
|
3926 | } = {}) {
|
3927 | super();
|
3928 | this.#docId = docId;
|
3929 | this.#document = ownerDocument;
|
3930 | }
|
3931 | get #cache() {
|
3932 | return this.#_cache ||= new Map();
|
3933 | }
|
3934 | get #defs() {
|
3935 | if (!this.#_defs) {
|
3936 | const div = this.#document.createElement("div");
|
3937 | const {
|
3938 | style
|
3939 | } = div;
|
3940 | style.visibility = "hidden";
|
3941 | style.contain = "strict";
|
3942 | style.width = style.height = 0;
|
3943 | style.position = "absolute";
|
3944 | style.top = style.left = 0;
|
3945 | style.zIndex = -1;
|
3946 | const svg = this.#document.createElementNS(SVG_NS, "svg");
|
3947 | svg.setAttribute("width", 0);
|
3948 | svg.setAttribute("height", 0);
|
3949 | this.#_defs = this.#document.createElementNS(SVG_NS, "defs");
|
3950 | div.append(svg);
|
3951 | svg.append(this.#_defs);
|
3952 | this.#document.body.append(div);
|
3953 | }
|
3954 | return this.#_defs;
|
3955 | }
|
3956 | #appendFeFunc(feComponentTransfer, func, table) {
|
3957 | const feFunc = this.#document.createElementNS(SVG_NS, func);
|
3958 | feFunc.setAttribute("type", "discrete");
|
3959 | feFunc.setAttribute("tableValues", table);
|
3960 | feComponentTransfer.append(feFunc);
|
3961 | }
|
3962 | addFilter(maps) {
|
3963 | if (!maps) {
|
3964 | return "none";
|
3965 | }
|
3966 | let value = this.#cache.get(maps);
|
3967 | if (value) {
|
3968 | return value;
|
3969 | }
|
3970 | let tableR, tableG, tableB, key;
|
3971 | if (maps.length === 1) {
|
3972 | const mapR = maps[0];
|
3973 | const buffer = new Array(256);
|
3974 | for (let i = 0; i < 256; i++) {
|
3975 | buffer[i] = mapR[i] / 255;
|
3976 | }
|
3977 | key = tableR = tableG = tableB = buffer.join(",");
|
3978 | } else {
|
3979 | const [mapR, mapG, mapB] = maps;
|
3980 | const bufferR = new Array(256);
|
3981 | const bufferG = new Array(256);
|
3982 | const bufferB = new Array(256);
|
3983 | for (let i = 0; i < 256; i++) {
|
3984 | bufferR[i] = mapR[i] / 255;
|
3985 | bufferG[i] = mapG[i] / 255;
|
3986 | bufferB[i] = mapB[i] / 255;
|
3987 | }
|
3988 | tableR = bufferR.join(",");
|
3989 | tableG = bufferG.join(",");
|
3990 | tableB = bufferB.join(",");
|
3991 | key = `${tableR}${tableG}${tableB}`;
|
3992 | }
|
3993 | value = this.#cache.get(key);
|
3994 | if (value) {
|
3995 | this.#cache.set(maps, value);
|
3996 | return value;
|
3997 | }
|
3998 | const id = `g_${this.#docId}_transfer_map_${this.#id++}`;
|
3999 | const url = `url(#${id})`;
|
4000 | this.#cache.set(maps, url);
|
4001 | this.#cache.set(key, url);
|
4002 | const filter = this.#document.createElementNS(SVG_NS, "filter", SVG_NS);
|
4003 | filter.setAttribute("id", id);
|
4004 | filter.setAttribute("color-interpolation-filters", "sRGB");
|
4005 | const feComponentTransfer = this.#document.createElementNS(SVG_NS, "feComponentTransfer");
|
4006 | filter.append(feComponentTransfer);
|
4007 | this.#appendFeFunc(feComponentTransfer, "feFuncR", tableR);
|
4008 | this.#appendFeFunc(feComponentTransfer, "feFuncG", tableG);
|
4009 | this.#appendFeFunc(feComponentTransfer, "feFuncB", tableB);
|
4010 | this.#defs.append(filter);
|
4011 | return url;
|
4012 | }
|
4013 | addHCMFilter(fgColor, bgColor) {
|
4014 | const key = `${fgColor}-${bgColor}`;
|
4015 | if (this.#hcmKey === key) {
|
4016 | return this.#hcmUrl;
|
4017 | }
|
4018 | this.#hcmKey = key;
|
4019 | this.#hcmUrl = "none";
|
4020 | this.#hcmFilter?.remove();
|
4021 | if (!fgColor || !bgColor) {
|
4022 | return this.#hcmUrl;
|
4023 | }
|
4024 | this.#defs.style.color = fgColor;
|
4025 | fgColor = getComputedStyle(this.#defs).getPropertyValue("color");
|
4026 | const fgRGB = getRGB(fgColor);
|
4027 | fgColor = _util.Util.makeHexColor(...fgRGB);
|
4028 | this.#defs.style.color = bgColor;
|
4029 | bgColor = getComputedStyle(this.#defs).getPropertyValue("color");
|
4030 | const bgRGB = getRGB(bgColor);
|
4031 | bgColor = _util.Util.makeHexColor(...bgRGB);
|
4032 | this.#defs.style.color = "";
|
4033 | if (fgColor === "#000000" && bgColor === "#ffffff" || fgColor === bgColor) {
|
4034 | return this.#hcmUrl;
|
4035 | }
|
4036 | const map = new Array(256);
|
4037 | for (let i = 0; i <= 255; i++) {
|
4038 | const x = i / 255;
|
4039 | map[i] = x <= 0.03928 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
|
4040 | }
|
4041 | const table = map.join(",");
|
4042 | const id = `g_${this.#docId}_hcm_filter`;
|
4043 | const filter = this.#hcmFilter = this.#document.createElementNS(SVG_NS, "filter", SVG_NS);
|
4044 | filter.setAttribute("id", id);
|
4045 | filter.setAttribute("color-interpolation-filters", "sRGB");
|
4046 | let feComponentTransfer = this.#document.createElementNS(SVG_NS, "feComponentTransfer");
|
4047 | filter.append(feComponentTransfer);
|
4048 | this.#appendFeFunc(feComponentTransfer, "feFuncR", table);
|
4049 | this.#appendFeFunc(feComponentTransfer, "feFuncG", table);
|
4050 | this.#appendFeFunc(feComponentTransfer, "feFuncB", table);
|
4051 | const feColorMatrix = this.#document.createElementNS(SVG_NS, "feColorMatrix");
|
4052 | feColorMatrix.setAttribute("type", "matrix");
|
4053 | feColorMatrix.setAttribute("values", "0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0");
|
4054 | filter.append(feColorMatrix);
|
4055 | feComponentTransfer = this.#document.createElementNS(SVG_NS, "feComponentTransfer");
|
4056 | filter.append(feComponentTransfer);
|
4057 | const getSteps = (c, n) => {
|
4058 | const start = fgRGB[c] / 255;
|
4059 | const end = bgRGB[c] / 255;
|
4060 | const arr = new Array(n + 1);
|
4061 | for (let i = 0; i <= n; i++) {
|
4062 | arr[i] = start + i / n * (end - start);
|
4063 | }
|
4064 | return arr.join(",");
|
4065 | };
|
4066 | this.#appendFeFunc(feComponentTransfer, "feFuncR", getSteps(0, 5));
|
4067 | this.#appendFeFunc(feComponentTransfer, "feFuncG", getSteps(1, 5));
|
4068 | this.#appendFeFunc(feComponentTransfer, "feFuncB", getSteps(2, 5));
|
4069 | this.#defs.append(filter);
|
4070 | this.#hcmUrl = `url(#${id})`;
|
4071 | return this.#hcmUrl;
|
4072 | }
|
4073 | destroy(keepHCM = false) {
|
4074 | if (keepHCM && this.#hcmUrl) {
|
4075 | return;
|
4076 | }
|
4077 | if (this.#_defs) {
|
4078 | this.#_defs.parentNode.parentNode.remove();
|
4079 | this.#_defs = null;
|
4080 | }
|
4081 | if (this.#_cache) {
|
4082 | this.#_cache.clear();
|
4083 | this.#_cache = null;
|
4084 | }
|
4085 | this.#id = 0;
|
4086 | }
|
4087 | }
|
4088 | exports.DOMFilterFactory = DOMFilterFactory;
|
4089 | class DOMCanvasFactory extends _base_factory.BaseCanvasFactory {
|
4090 | constructor({
|
4091 | ownerDocument = globalThis.document
|
4092 | } = {}) {
|
4093 | super();
|
4094 | this._document = ownerDocument;
|
4095 | }
|
4096 | _createCanvas(width, height) {
|
4097 | const canvas = this._document.createElement("canvas");
|
4098 | canvas.width = width;
|
4099 | canvas.height = height;
|
4100 | return canvas;
|
4101 | }
|
4102 | }
|
4103 | exports.DOMCanvasFactory = DOMCanvasFactory;
|
4104 | async function fetchData(url, asTypedArray = false) {
|
4105 | if (isValidFetchUrl(url, document.baseURI)) {
|
4106 | const response = await fetch(url);
|
4107 | if (!response.ok) {
|
4108 | throw new Error(response.statusText);
|
4109 | }
|
4110 | return asTypedArray ? new Uint8Array(await response.arrayBuffer()) : (0, _util.stringToBytes)(await response.text());
|
4111 | }
|
4112 | return new Promise((resolve, reject) => {
|
4113 | const request = new XMLHttpRequest();
|
4114 | request.open("GET", url, true);
|
4115 | if (asTypedArray) {
|
4116 | request.responseType = "arraybuffer";
|
4117 | }
|
4118 | request.onreadystatechange = () => {
|
4119 | if (request.readyState !== XMLHttpRequest.DONE) {
|
4120 | return;
|
4121 | }
|
4122 | if (request.status === 200 || request.status === 0) {
|
4123 | let data;
|
4124 | if (asTypedArray && request.response) {
|
4125 | data = new Uint8Array(request.response);
|
4126 | } else if (!asTypedArray && request.responseText) {
|
4127 | data = (0, _util.stringToBytes)(request.responseText);
|
4128 | }
|
4129 | if (data) {
|
4130 | resolve(data);
|
4131 | return;
|
4132 | }
|
4133 | }
|
4134 | reject(new Error(request.statusText));
|
4135 | };
|
4136 | request.send(null);
|
4137 | });
|
4138 | }
|
4139 | class DOMCMapReaderFactory extends _base_factory.BaseCMapReaderFactory {
|
4140 | _fetchData(url, compressionType) {
|
4141 | return fetchData(url, this.isCompressed).then(data => {
|
4142 | return {
|
4143 | cMapData: data,
|
4144 | compressionType
|
4145 | };
|
4146 | });
|
4147 | }
|
4148 | }
|
4149 | exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
|
4150 | class DOMStandardFontDataFactory extends _base_factory.BaseStandardFontDataFactory {
|
4151 | _fetchData(url) {
|
4152 | return fetchData(url, true);
|
4153 | }
|
4154 | }
|
4155 | exports.DOMStandardFontDataFactory = DOMStandardFontDataFactory;
|
4156 | class DOMSVGFactory extends _base_factory.BaseSVGFactory {
|
4157 | _createSVG(type) {
|
4158 | return document.createElementNS(SVG_NS, type);
|
4159 | }
|
4160 | }
|
4161 | exports.DOMSVGFactory = DOMSVGFactory;
|
4162 | class PageViewport {
|
4163 | constructor({
|
4164 | viewBox,
|
4165 | scale,
|
4166 | rotation,
|
4167 | offsetX = 0,
|
4168 | offsetY = 0,
|
4169 | dontFlip = false
|
4170 | }) {
|
4171 | this.viewBox = viewBox;
|
4172 | this.scale = scale;
|
4173 | this.rotation = rotation;
|
4174 | this.offsetX = offsetX;
|
4175 | this.offsetY = offsetY;
|
4176 | const centerX = (viewBox[2] + viewBox[0]) / 2;
|
4177 | const centerY = (viewBox[3] + viewBox[1]) / 2;
|
4178 | let rotateA, rotateB, rotateC, rotateD;
|
4179 | rotation %= 360;
|
4180 | if (rotation < 0) {
|
4181 | rotation += 360;
|
4182 | }
|
4183 | switch (rotation) {
|
4184 | case 180:
|
4185 | rotateA = -1;
|
4186 | rotateB = 0;
|
4187 | rotateC = 0;
|
4188 | rotateD = 1;
|
4189 | break;
|
4190 | case 90:
|
4191 | rotateA = 0;
|
4192 | rotateB = 1;
|
4193 | rotateC = 1;
|
4194 | rotateD = 0;
|
4195 | break;
|
4196 | case 270:
|
4197 | rotateA = 0;
|
4198 | rotateB = -1;
|
4199 | rotateC = -1;
|
4200 | rotateD = 0;
|
4201 | break;
|
4202 | case 0:
|
4203 | rotateA = 1;
|
4204 | rotateB = 0;
|
4205 | rotateC = 0;
|
4206 | rotateD = -1;
|
4207 | break;
|
4208 | default:
|
4209 | throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
|
4210 | }
|
4211 | if (dontFlip) {
|
4212 | rotateC = -rotateC;
|
4213 | rotateD = -rotateD;
|
4214 | }
|
4215 | let offsetCanvasX, offsetCanvasY;
|
4216 | let width, height;
|
4217 | if (rotateA === 0) {
|
4218 | offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
|
4219 | offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
|
4220 | width = (viewBox[3] - viewBox[1]) * scale;
|
4221 | height = (viewBox[2] - viewBox[0]) * scale;
|
4222 | } else {
|
4223 | offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
|
4224 | offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
|
4225 | width = (viewBox[2] - viewBox[0]) * scale;
|
4226 | height = (viewBox[3] - viewBox[1]) * scale;
|
4227 | }
|
4228 | this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
|
4229 | this.width = width;
|
4230 | this.height = height;
|
4231 | }
|
4232 | get rawDims() {
|
4233 | const {
|
4234 | viewBox
|
4235 | } = this;
|
4236 | return (0, _util.shadow)(this, "rawDims", {
|
4237 | pageWidth: viewBox[2] - viewBox[0],
|
4238 | pageHeight: viewBox[3] - viewBox[1],
|
4239 | pageX: viewBox[0],
|
4240 | pageY: viewBox[1]
|
4241 | });
|
4242 | }
|
4243 | clone({
|
4244 | scale = this.scale,
|
4245 | rotation = this.rotation,
|
4246 | offsetX = this.offsetX,
|
4247 | offsetY = this.offsetY,
|
4248 | dontFlip = false
|
4249 | } = {}) {
|
4250 | return new PageViewport({
|
4251 | viewBox: this.viewBox.slice(),
|
4252 | scale,
|
4253 | rotation,
|
4254 | offsetX,
|
4255 | offsetY,
|
4256 | dontFlip
|
4257 | });
|
4258 | }
|
4259 | convertToViewportPoint(x, y) {
|
4260 | return _util.Util.applyTransform([x, y], this.transform);
|
4261 | }
|
4262 | convertToViewportRectangle(rect) {
|
4263 | const topLeft = _util.Util.applyTransform([rect[0], rect[1]], this.transform);
|
4264 | const bottomRight = _util.Util.applyTransform([rect[2], rect[3]], this.transform);
|
4265 | return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
|
4266 | }
|
4267 | convertToPdfPoint(x, y) {
|
4268 | return _util.Util.applyInverseTransform([x, y], this.transform);
|
4269 | }
|
4270 | }
|
4271 | exports.PageViewport = PageViewport;
|
4272 | class RenderingCancelledException extends _util.BaseException {
|
4273 | constructor(msg, type, extraDelay = 0) {
|
4274 | super(msg, "RenderingCancelledException");
|
4275 | this.type = type;
|
4276 | this.extraDelay = extraDelay;
|
4277 | }
|
4278 | }
|
4279 | exports.RenderingCancelledException = RenderingCancelledException;
|
4280 | function isDataScheme(url) {
|
4281 | const ii = url.length;
|
4282 | let i = 0;
|
4283 | while (i < ii && url[i].trim() === "") {
|
4284 | i++;
|
4285 | }
|
4286 | return url.substring(i, i + 5).toLowerCase() === "data:";
|
4287 | }
|
4288 | function isPdfFile(filename) {
|
4289 | return typeof filename === "string" && /\.pdf$/i.test(filename);
|
4290 | }
|
4291 | function getFilenameFromUrl(url, onlyStripPath = false) {
|
4292 | if (!onlyStripPath) {
|
4293 | [url] = url.split(/[#?]/, 1);
|
4294 | }
|
4295 | return url.substring(url.lastIndexOf("/") + 1);
|
4296 | }
|
4297 | function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
|
4298 | if (typeof url !== "string") {
|
4299 | return defaultFilename;
|
4300 | }
|
4301 | if (isDataScheme(url)) {
|
4302 | (0, _util.warn)('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
|
4303 | return defaultFilename;
|
4304 | }
|
4305 | const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
|
4306 | const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
|
4307 | const splitURI = reURI.exec(url);
|
4308 | let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
|
4309 | if (suggestedFilename) {
|
4310 | suggestedFilename = suggestedFilename[0];
|
4311 | if (suggestedFilename.includes("%")) {
|
4312 | try {
|
4313 | suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
|
4314 | } catch (ex) {}
|
4315 | }
|
4316 | }
|
4317 | return suggestedFilename || defaultFilename;
|
4318 | }
|
4319 | class StatTimer {
|
4320 | started = Object.create(null);
|
4321 | times = [];
|
4322 | time(name) {
|
4323 | if (name in this.started) {
|
4324 | (0, _util.warn)(`Timer is already running for ${name}`);
|
4325 | }
|
4326 | this.started[name] = Date.now();
|
4327 | }
|
4328 | timeEnd(name) {
|
4329 | if (!(name in this.started)) {
|
4330 | (0, _util.warn)(`Timer has not been started for ${name}`);
|
4331 | }
|
4332 | this.times.push({
|
4333 | name,
|
4334 | start: this.started[name],
|
4335 | end: Date.now()
|
4336 | });
|
4337 | delete this.started[name];
|
4338 | }
|
4339 | toString() {
|
4340 | const outBuf = [];
|
4341 | let longest = 0;
|
4342 | for (const {
|
4343 | name
|
4344 | } of this.times) {
|
4345 | longest = Math.max(name.length, longest);
|
4346 | }
|
4347 | for (const {
|
4348 | name,
|
4349 | start,
|
4350 | end
|
4351 | } of this.times) {
|
4352 | outBuf.push(`${name.padEnd(longest)} ${end - start}ms\n`);
|
4353 | }
|
4354 | return outBuf.join("");
|
4355 | }
|
4356 | }
|
4357 | exports.StatTimer = StatTimer;
|
4358 | function isValidFetchUrl(url, baseUrl) {
|
4359 | try {
|
4360 | const {
|
4361 | protocol
|
4362 | } = baseUrl ? new URL(url, baseUrl) : new URL(url);
|
4363 | return protocol === "http:" || protocol === "https:";
|
4364 | } catch (ex) {
|
4365 | return false;
|
4366 | }
|
4367 | }
|
4368 | function loadScript(src, removeScriptElement = false) {
|
4369 | return new Promise((resolve, reject) => {
|
4370 | const script = document.createElement("script");
|
4371 | script.src = src;
|
4372 | script.onload = function (evt) {
|
4373 | if (removeScriptElement) {
|
4374 | script.remove();
|
4375 | }
|
4376 | resolve(evt);
|
4377 | };
|
4378 | script.onerror = function () {
|
4379 | reject(new Error(`Cannot load script at: ${script.src}`));
|
4380 | };
|
4381 | (document.head || document.documentElement).append(script);
|
4382 | });
|
4383 | }
|
4384 | function deprecated(details) {
|
4385 | console.log("Deprecated API usage: " + details);
|
4386 | }
|
4387 | let pdfDateStringRegex;
|
4388 | class PDFDateString {
|
4389 | static toDateObject(input) {
|
4390 | if (!input || typeof input !== "string") {
|
4391 | return null;
|
4392 | }
|
4393 | pdfDateStringRegex ||= new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?");
|
4394 | const matches = pdfDateStringRegex.exec(input);
|
4395 | if (!matches) {
|
4396 | return null;
|
4397 | }
|
4398 | const year = parseInt(matches[1], 10);
|
4399 | let month = parseInt(matches[2], 10);
|
4400 | month = month >= 1 && month <= 12 ? month - 1 : 0;
|
4401 | let day = parseInt(matches[3], 10);
|
4402 | day = day >= 1 && day <= 31 ? day : 1;
|
4403 | let hour = parseInt(matches[4], 10);
|
4404 | hour = hour >= 0 && hour <= 23 ? hour : 0;
|
4405 | let minute = parseInt(matches[5], 10);
|
4406 | minute = minute >= 0 && minute <= 59 ? minute : 0;
|
4407 | let second = parseInt(matches[6], 10);
|
4408 | second = second >= 0 && second <= 59 ? second : 0;
|
4409 | const universalTimeRelation = matches[7] || "Z";
|
4410 | let offsetHour = parseInt(matches[8], 10);
|
4411 | offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
|
4412 | let offsetMinute = parseInt(matches[9], 10) || 0;
|
4413 | offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
|
4414 | if (universalTimeRelation === "-") {
|
4415 | hour += offsetHour;
|
4416 | minute += offsetMinute;
|
4417 | } else if (universalTimeRelation === "+") {
|
4418 | hour -= offsetHour;
|
4419 | minute -= offsetMinute;
|
4420 | }
|
4421 | return new Date(Date.UTC(year, month, day, hour, minute, second));
|
4422 | }
|
4423 | }
|
4424 | exports.PDFDateString = PDFDateString;
|
4425 | function getXfaPageViewport(xfaPage, {
|
4426 | scale = 1,
|
4427 | rotation = 0
|
4428 | }) {
|
4429 | const {
|
4430 | width,
|
4431 | height
|
4432 | } = xfaPage.attributes.style;
|
4433 | const viewBox = [0, 0, parseInt(width), parseInt(height)];
|
4434 | return new PageViewport({
|
4435 | viewBox,
|
4436 | scale,
|
4437 | rotation
|
4438 | });
|
4439 | }
|
4440 | function getRGB(color) {
|
4441 | if (color.startsWith("#")) {
|
4442 | const colorRGB = parseInt(color.slice(1), 16);
|
4443 | return [(colorRGB & 0xff0000) >> 16, (colorRGB & 0x00ff00) >> 8, colorRGB & 0x0000ff];
|
4444 | }
|
4445 | if (color.startsWith("rgb(")) {
|
4446 | return color.slice(4, -1).split(",").map(x => parseInt(x));
|
4447 | }
|
4448 | if (color.startsWith("rgba(")) {
|
4449 | return color.slice(5, -1).split(",").map(x => parseInt(x)).slice(0, 3);
|
4450 | }
|
4451 | (0, _util.warn)(`Not a valid color format: "${color}"`);
|
4452 | return [0, 0, 0];
|
4453 | }
|
4454 | function getColorValues(colors) {
|
4455 | const span = document.createElement("span");
|
4456 | span.style.visibility = "hidden";
|
4457 | document.body.append(span);
|
4458 | for (const name of colors.keys()) {
|
4459 | span.style.color = name;
|
4460 | const computedColor = window.getComputedStyle(span).color;
|
4461 | colors.set(name, getRGB(computedColor));
|
4462 | }
|
4463 | span.remove();
|
4464 | }
|
4465 | function getCurrentTransform(ctx) {
|
4466 | const {
|
4467 | a,
|
4468 | b,
|
4469 | c,
|
4470 | d,
|
4471 | e,
|
4472 | f
|
4473 | } = ctx.getTransform();
|
4474 | return [a, b, c, d, e, f];
|
4475 | }
|
4476 | function getCurrentTransformInverse(ctx) {
|
4477 | const {
|
4478 | a,
|
4479 | b,
|
4480 | c,
|
4481 | d,
|
4482 | e,
|
4483 | f
|
4484 | } = ctx.getTransform().invertSelf();
|
4485 | return [a, b, c, d, e, f];
|
4486 | }
|
4487 | function setLayerDimensions(div, viewport, mustFlip = false, mustRotate = true) {
|
4488 | if (viewport instanceof PageViewport) {
|
4489 | const {
|
4490 | pageWidth,
|
4491 | pageHeight
|
4492 | } = viewport.rawDims;
|
4493 | const {
|
4494 | style
|
4495 | } = div;
|
4496 | const widthStr = `calc(var(--scale-factor) * ${pageWidth}px)`;
|
4497 | const heightStr = `calc(var(--scale-factor) * ${pageHeight}px)`;
|
4498 | if (!mustFlip || viewport.rotation % 180 === 0) {
|
4499 | style.width = widthStr;
|
4500 | style.height = heightStr;
|
4501 | } else {
|
4502 | style.width = heightStr;
|
4503 | style.height = widthStr;
|
4504 | }
|
4505 | }
|
4506 | if (mustRotate) {
|
4507 | div.setAttribute("data-main-rotation", viewport.rotation);
|
4508 | }
|
4509 | }
|
4510 |
|
4511 | }),
|
4512 |
|
4513 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
4514 |
|
4515 |
|
4516 |
|
4517 | Object.defineProperty(exports, "__esModule", ({
|
4518 | value: true
|
4519 | }));
|
4520 | exports.BaseStandardFontDataFactory = exports.BaseSVGFactory = exports.BaseFilterFactory = exports.BaseCanvasFactory = exports.BaseCMapReaderFactory = void 0;
|
4521 | var _util = __w_pdfjs_require__(1);
|
4522 | class BaseFilterFactory {
|
4523 | constructor() {
|
4524 | if (this.constructor === BaseFilterFactory) {
|
4525 | (0, _util.unreachable)("Cannot initialize BaseFilterFactory.");
|
4526 | }
|
4527 | }
|
4528 | addFilter(maps) {
|
4529 | return "none";
|
4530 | }
|
4531 | addHCMFilter(fgColor, bgColor) {
|
4532 | return "none";
|
4533 | }
|
4534 | destroy(keepHCM = false) {}
|
4535 | }
|
4536 | exports.BaseFilterFactory = BaseFilterFactory;
|
4537 | class BaseCanvasFactory {
|
4538 | constructor() {
|
4539 | if (this.constructor === BaseCanvasFactory) {
|
4540 | (0, _util.unreachable)("Cannot initialize BaseCanvasFactory.");
|
4541 | }
|
4542 | }
|
4543 | create(width, height) {
|
4544 | if (width <= 0 || height <= 0) {
|
4545 | throw new Error("Invalid canvas size");
|
4546 | }
|
4547 | const canvas = this._createCanvas(width, height);
|
4548 | return {
|
4549 | canvas,
|
4550 | context: canvas.getContext("2d")
|
4551 | };
|
4552 | }
|
4553 | reset(canvasAndContext, width, height) {
|
4554 | if (!canvasAndContext.canvas) {
|
4555 | throw new Error("Canvas is not specified");
|
4556 | }
|
4557 | if (width <= 0 || height <= 0) {
|
4558 | throw new Error("Invalid canvas size");
|
4559 | }
|
4560 | canvasAndContext.canvas.width = width;
|
4561 | canvasAndContext.canvas.height = height;
|
4562 | }
|
4563 | destroy(canvasAndContext) {
|
4564 | if (!canvasAndContext.canvas) {
|
4565 | throw new Error("Canvas is not specified");
|
4566 | }
|
4567 | canvasAndContext.canvas.width = 0;
|
4568 | canvasAndContext.canvas.height = 0;
|
4569 | canvasAndContext.canvas = null;
|
4570 | canvasAndContext.context = null;
|
4571 | }
|
4572 | _createCanvas(width, height) {
|
4573 | (0, _util.unreachable)("Abstract method `_createCanvas` called.");
|
4574 | }
|
4575 | }
|
4576 | exports.BaseCanvasFactory = BaseCanvasFactory;
|
4577 | class BaseCMapReaderFactory {
|
4578 | constructor({
|
4579 | baseUrl = null,
|
4580 | isCompressed = true
|
4581 | }) {
|
4582 | if (this.constructor === BaseCMapReaderFactory) {
|
4583 | (0, _util.unreachable)("Cannot initialize BaseCMapReaderFactory.");
|
4584 | }
|
4585 | this.baseUrl = baseUrl;
|
4586 | this.isCompressed = isCompressed;
|
4587 | }
|
4588 | async fetch({
|
4589 | name
|
4590 | }) {
|
4591 | if (!this.baseUrl) {
|
4592 | throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
|
4593 | }
|
4594 | if (!name) {
|
4595 | throw new Error("CMap name must be specified.");
|
4596 | }
|
4597 | const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
|
4598 | const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE;
|
4599 | return this._fetchData(url, compressionType).catch(reason => {
|
4600 | throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`);
|
4601 | });
|
4602 | }
|
4603 | _fetchData(url, compressionType) {
|
4604 | (0, _util.unreachable)("Abstract method `_fetchData` called.");
|
4605 | }
|
4606 | }
|
4607 | exports.BaseCMapReaderFactory = BaseCMapReaderFactory;
|
4608 | class BaseStandardFontDataFactory {
|
4609 | constructor({
|
4610 | baseUrl = null
|
4611 | }) {
|
4612 | if (this.constructor === BaseStandardFontDataFactory) {
|
4613 | (0, _util.unreachable)("Cannot initialize BaseStandardFontDataFactory.");
|
4614 | }
|
4615 | this.baseUrl = baseUrl;
|
4616 | }
|
4617 | async fetch({
|
4618 | filename
|
4619 | }) {
|
4620 | if (!this.baseUrl) {
|
4621 | throw new Error('The standard font "baseUrl" parameter must be specified, ensure that ' + 'the "standardFontDataUrl" API parameter is provided.');
|
4622 | }
|
4623 | if (!filename) {
|
4624 | throw new Error("Font filename must be specified.");
|
4625 | }
|
4626 | const url = `${this.baseUrl}${filename}`;
|
4627 | return this._fetchData(url).catch(reason => {
|
4628 | throw new Error(`Unable to load font data at: ${url}`);
|
4629 | });
|
4630 | }
|
4631 | _fetchData(url) {
|
4632 | (0, _util.unreachable)("Abstract method `_fetchData` called.");
|
4633 | }
|
4634 | }
|
4635 | exports.BaseStandardFontDataFactory = BaseStandardFontDataFactory;
|
4636 | class BaseSVGFactory {
|
4637 | constructor() {
|
4638 | if (this.constructor === BaseSVGFactory) {
|
4639 | (0, _util.unreachable)("Cannot initialize BaseSVGFactory.");
|
4640 | }
|
4641 | }
|
4642 | create(width, height, skipDimensions = false) {
|
4643 | if (width <= 0 || height <= 0) {
|
4644 | throw new Error("Invalid SVG dimensions");
|
4645 | }
|
4646 | const svg = this._createSVG("svg:svg");
|
4647 | svg.setAttribute("version", "1.1");
|
4648 | if (!skipDimensions) {
|
4649 | svg.setAttribute("width", `${width}px`);
|
4650 | svg.setAttribute("height", `${height}px`);
|
4651 | }
|
4652 | svg.setAttribute("preserveAspectRatio", "none");
|
4653 | svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
|
4654 | return svg;
|
4655 | }
|
4656 | createElement(type) {
|
4657 | if (typeof type !== "string") {
|
4658 | throw new Error("Invalid SVG element type");
|
4659 | }
|
4660 | return this._createSVG(type);
|
4661 | }
|
4662 | _createSVG(type) {
|
4663 | (0, _util.unreachable)("Abstract method `_createSVG` called.");
|
4664 | }
|
4665 | }
|
4666 | exports.BaseSVGFactory = BaseSVGFactory;
|
4667 |
|
4668 | }),
|
4669 |
|
4670 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
4671 |
|
4672 |
|
4673 |
|
4674 | Object.defineProperty(exports, "__esModule", ({
|
4675 | value: true
|
4676 | }));
|
4677 | exports.MurmurHash3_64 = void 0;
|
4678 | var _util = __w_pdfjs_require__(1);
|
4679 | const SEED = 0xc3d2e1f0;
|
4680 | const MASK_HIGH = 0xffff0000;
|
4681 | const MASK_LOW = 0xffff;
|
4682 | class MurmurHash3_64 {
|
4683 | constructor(seed) {
|
4684 | this.h1 = seed ? seed & 0xffffffff : SEED;
|
4685 | this.h2 = seed ? seed & 0xffffffff : SEED;
|
4686 | }
|
4687 | update(input) {
|
4688 | let data, length;
|
4689 | if (typeof input === "string") {
|
4690 | data = new Uint8Array(input.length * 2);
|
4691 | length = 0;
|
4692 | for (let i = 0, ii = input.length; i < ii; i++) {
|
4693 | const code = input.charCodeAt(i);
|
4694 | if (code <= 0xff) {
|
4695 | data[length++] = code;
|
4696 | } else {
|
4697 | data[length++] = code >>> 8;
|
4698 | data[length++] = code & 0xff;
|
4699 | }
|
4700 | }
|
4701 | } else if ((0, _util.isArrayBuffer)(input)) {
|
4702 | data = input.slice();
|
4703 | length = data.byteLength;
|
4704 | } else {
|
4705 | throw new Error("Wrong data format in MurmurHash3_64_update. " + "Input must be a string or array.");
|
4706 | }
|
4707 | const blockCounts = length >> 2;
|
4708 | const tailLength = length - blockCounts * 4;
|
4709 | const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
|
4710 | let k1 = 0,
|
4711 | k2 = 0;
|
4712 | let h1 = this.h1,
|
4713 | h2 = this.h2;
|
4714 | const C1 = 0xcc9e2d51,
|
4715 | C2 = 0x1b873593;
|
4716 | const C1_LOW = C1 & MASK_LOW,
|
4717 | C2_LOW = C2 & MASK_LOW;
|
4718 | for (let i = 0; i < blockCounts; i++) {
|
4719 | if (i & 1) {
|
4720 | k1 = dataUint32[i];
|
4721 | k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
|
4722 | k1 = k1 << 15 | k1 >>> 17;
|
4723 | k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
|
4724 | h1 ^= k1;
|
4725 | h1 = h1 << 13 | h1 >>> 19;
|
4726 | h1 = h1 * 5 + 0xe6546b64;
|
4727 | } else {
|
4728 | k2 = dataUint32[i];
|
4729 | k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
|
4730 | k2 = k2 << 15 | k2 >>> 17;
|
4731 | k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
|
4732 | h2 ^= k2;
|
4733 | h2 = h2 << 13 | h2 >>> 19;
|
4734 | h2 = h2 * 5 + 0xe6546b64;
|
4735 | }
|
4736 | }
|
4737 | k1 = 0;
|
4738 | switch (tailLength) {
|
4739 | case 3:
|
4740 | k1 ^= data[blockCounts * 4 + 2] << 16;
|
4741 | case 2:
|
4742 | k1 ^= data[blockCounts * 4 + 1] << 8;
|
4743 | case 1:
|
4744 | k1 ^= data[blockCounts * 4];
|
4745 | k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
|
4746 | k1 = k1 << 15 | k1 >>> 17;
|
4747 | k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
|
4748 | if (blockCounts & 1) {
|
4749 | h1 ^= k1;
|
4750 | } else {
|
4751 | h2 ^= k1;
|
4752 | }
|
4753 | }
|
4754 | this.h1 = h1;
|
4755 | this.h2 = h2;
|
4756 | }
|
4757 | hexdigest() {
|
4758 | let h1 = this.h1,
|
4759 | h2 = this.h2;
|
4760 | h1 ^= h2 >>> 1;
|
4761 | h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
|
4762 | h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
|
4763 | h1 ^= h2 >>> 1;
|
4764 | h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
|
4765 | h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
|
4766 | h1 ^= h2 >>> 1;
|
4767 | return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
|
4768 | }
|
4769 | }
|
4770 | exports.MurmurHash3_64 = MurmurHash3_64;
|
4771 |
|
4772 | }),
|
4773 |
|
4774 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
4775 |
|
4776 |
|
4777 |
|
4778 | Object.defineProperty(exports, "__esModule", ({
|
4779 | value: true
|
4780 | }));
|
4781 | exports.FontLoader = exports.FontFaceObject = void 0;
|
4782 | var _util = __w_pdfjs_require__(1);
|
4783 | var _is_node = __w_pdfjs_require__(10);
|
4784 | class FontLoader {
|
4785 | #systemFonts = new Set();
|
4786 | constructor({
|
4787 | ownerDocument = globalThis.document,
|
4788 | styleElement = null
|
4789 | }) {
|
4790 | this._document = ownerDocument;
|
4791 | this.nativeFontFaces = new Set();
|
4792 | this.styleElement = null;
|
4793 | this.loadingRequests = [];
|
4794 | this.loadTestFontId = 0;
|
4795 | }
|
4796 | addNativeFontFace(nativeFontFace) {
|
4797 | this.nativeFontFaces.add(nativeFontFace);
|
4798 | this._document.fonts.add(nativeFontFace);
|
4799 | }
|
4800 | removeNativeFontFace(nativeFontFace) {
|
4801 | this.nativeFontFaces.delete(nativeFontFace);
|
4802 | this._document.fonts.delete(nativeFontFace);
|
4803 | }
|
4804 | insertRule(rule) {
|
4805 | if (!this.styleElement) {
|
4806 | this.styleElement = this._document.createElement("style");
|
4807 | this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement);
|
4808 | }
|
4809 | const styleSheet = this.styleElement.sheet;
|
4810 | styleSheet.insertRule(rule, styleSheet.cssRules.length);
|
4811 | }
|
4812 | clear() {
|
4813 | for (const nativeFontFace of this.nativeFontFaces) {
|
4814 | this._document.fonts.delete(nativeFontFace);
|
4815 | }
|
4816 | this.nativeFontFaces.clear();
|
4817 | this.#systemFonts.clear();
|
4818 | if (this.styleElement) {
|
4819 | this.styleElement.remove();
|
4820 | this.styleElement = null;
|
4821 | }
|
4822 | }
|
4823 | async loadSystemFont(info) {
|
4824 | if (!info || this.#systemFonts.has(info.loadedName)) {
|
4825 | return;
|
4826 | }
|
4827 | (0, _util.assert)(!this.disableFontFace, "loadSystemFont shouldn't be called when `disableFontFace` is set.");
|
4828 | if (this.isFontLoadingAPISupported) {
|
4829 | const {
|
4830 | loadedName,
|
4831 | src,
|
4832 | style
|
4833 | } = info;
|
4834 | const fontFace = new FontFace(loadedName, src, style);
|
4835 | this.addNativeFontFace(fontFace);
|
4836 | try {
|
4837 | await fontFace.load();
|
4838 | this.#systemFonts.add(loadedName);
|
4839 | } catch {
|
4840 | (0, _util.warn)(`Cannot load system font: ${info.baseFontName}, installing it could help to improve PDF rendering.`);
|
4841 | this.removeNativeFontFace(fontFace);
|
4842 | }
|
4843 | return;
|
4844 | }
|
4845 | (0, _util.unreachable)("Not implemented: loadSystemFont without the Font Loading API.");
|
4846 | }
|
4847 | async bind(font) {
|
4848 | if (font.attached || font.missingFile && !font.systemFontInfo) {
|
4849 | return;
|
4850 | }
|
4851 | font.attached = true;
|
4852 | if (font.systemFontInfo) {
|
4853 | await this.loadSystemFont(font.systemFontInfo);
|
4854 | return;
|
4855 | }
|
4856 | if (this.isFontLoadingAPISupported) {
|
4857 | const nativeFontFace = font.createNativeFontFace();
|
4858 | if (nativeFontFace) {
|
4859 | this.addNativeFontFace(nativeFontFace);
|
4860 | try {
|
4861 | await nativeFontFace.loaded;
|
4862 | } catch (ex) {
|
4863 | (0, _util.warn)(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
|
4864 | font.disableFontFace = true;
|
4865 | throw ex;
|
4866 | }
|
4867 | }
|
4868 | return;
|
4869 | }
|
4870 | const rule = font.createFontFaceRule();
|
4871 | if (rule) {
|
4872 | this.insertRule(rule);
|
4873 | if (this.isSyncFontLoadingSupported) {
|
4874 | return;
|
4875 | }
|
4876 | await new Promise(resolve => {
|
4877 | const request = this._queueLoadingCallback(resolve);
|
4878 | this._prepareFontLoadEvent(font, request);
|
4879 | });
|
4880 | }
|
4881 | }
|
4882 | get isFontLoadingAPISupported() {
|
4883 | const hasFonts = !!this._document?.fonts;
|
4884 | return (0, _util.shadow)(this, "isFontLoadingAPISupported", hasFonts);
|
4885 | }
|
4886 | get isSyncFontLoadingSupported() {
|
4887 | let supported = false;
|
4888 | if (_is_node.isNodeJS) {
|
4889 | supported = true;
|
4890 | } else if (typeof navigator !== "undefined" && /Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent)) {
|
4891 | supported = true;
|
4892 | }
|
4893 | return (0, _util.shadow)(this, "isSyncFontLoadingSupported", supported);
|
4894 | }
|
4895 | _queueLoadingCallback(callback) {
|
4896 | function completeRequest() {
|
4897 | (0, _util.assert)(!request.done, "completeRequest() cannot be called twice.");
|
4898 | request.done = true;
|
4899 | while (loadingRequests.length > 0 && loadingRequests[0].done) {
|
4900 | const otherRequest = loadingRequests.shift();
|
4901 | setTimeout(otherRequest.callback, 0);
|
4902 | }
|
4903 | }
|
4904 | const {
|
4905 | loadingRequests
|
4906 | } = this;
|
4907 | const request = {
|
4908 | done: false,
|
4909 | complete: completeRequest,
|
4910 | callback
|
4911 | };
|
4912 | loadingRequests.push(request);
|
4913 | return request;
|
4914 | }
|
4915 | get _loadTestFont() {
|
4916 | const testFont = atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQA" + "FQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAA" + "ALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgA" + "AAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1" + "AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD" + "6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACM" + "AooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4D" + "IP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAA" + "AAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUA" + "AQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgAB" + "AAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABY" + "AAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAA" + "AC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAA" + "AAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQAC" + "AQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3" + "Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTj" + "FQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");
|
4917 | return (0, _util.shadow)(this, "_loadTestFont", testFont);
|
4918 | }
|
4919 | _prepareFontLoadEvent(font, request) {
|
4920 | function int32(data, offset) {
|
4921 | return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
|
4922 | }
|
4923 | function spliceString(s, offset, remove, insert) {
|
4924 | const chunk1 = s.substring(0, offset);
|
4925 | const chunk2 = s.substring(offset + remove);
|
4926 | return chunk1 + insert + chunk2;
|
4927 | }
|
4928 | let i, ii;
|
4929 | const canvas = this._document.createElement("canvas");
|
4930 | canvas.width = 1;
|
4931 | canvas.height = 1;
|
4932 | const ctx = canvas.getContext("2d");
|
4933 | let called = 0;
|
4934 | function isFontReady(name, callback) {
|
4935 | if (++called > 30) {
|
4936 | (0, _util.warn)("Load test font never loaded.");
|
4937 | callback();
|
4938 | return;
|
4939 | }
|
4940 | ctx.font = "30px " + name;
|
4941 | ctx.fillText(".", 0, 20);
|
4942 | const imageData = ctx.getImageData(0, 0, 1, 1);
|
4943 | if (imageData.data[3] > 0) {
|
4944 | callback();
|
4945 | return;
|
4946 | }
|
4947 | setTimeout(isFontReady.bind(null, name, callback));
|
4948 | }
|
4949 | const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
|
4950 | let data = this._loadTestFont;
|
4951 | const COMMENT_OFFSET = 976;
|
4952 | data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
|
4953 | const CFF_CHECKSUM_OFFSET = 16;
|
4954 | const XXXX_VALUE = 0x58585858;
|
4955 | let checksum = int32(data, CFF_CHECKSUM_OFFSET);
|
4956 | for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
|
4957 | checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
|
4958 | }
|
4959 | if (i < loadTestFontId.length) {
|
4960 | checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
|
4961 | }
|
4962 | data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum));
|
4963 | const url = `url(data:font/opentype;base64,${btoa(data)});`;
|
4964 | const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
|
4965 | this.insertRule(rule);
|
4966 | const div = this._document.createElement("div");
|
4967 | div.style.visibility = "hidden";
|
4968 | div.style.width = div.style.height = "10px";
|
4969 | div.style.position = "absolute";
|
4970 | div.style.top = div.style.left = "0px";
|
4971 | for (const name of [font.loadedName, loadTestFontId]) {
|
4972 | const span = this._document.createElement("span");
|
4973 | span.textContent = "Hi";
|
4974 | span.style.fontFamily = name;
|
4975 | div.append(span);
|
4976 | }
|
4977 | this._document.body.append(div);
|
4978 | isFontReady(loadTestFontId, () => {
|
4979 | div.remove();
|
4980 | request.complete();
|
4981 | });
|
4982 | }
|
4983 | }
|
4984 | exports.FontLoader = FontLoader;
|
4985 | class FontFaceObject {
|
4986 | constructor(translatedData, {
|
4987 | isEvalSupported = true,
|
4988 | disableFontFace = false,
|
4989 | ignoreErrors = false,
|
4990 | inspectFont = null
|
4991 | }) {
|
4992 | this.compiledGlyphs = Object.create(null);
|
4993 | for (const i in translatedData) {
|
4994 | this[i] = translatedData[i];
|
4995 | }
|
4996 | this.isEvalSupported = isEvalSupported !== false;
|
4997 | this.disableFontFace = disableFontFace === true;
|
4998 | this.ignoreErrors = ignoreErrors === true;
|
4999 | this._inspectFont = inspectFont;
|
5000 | }
|
5001 | createNativeFontFace() {
|
5002 | if (!this.data || this.disableFontFace) {
|
5003 | return null;
|
5004 | }
|
5005 | let nativeFontFace;
|
5006 | if (!this.cssFontInfo) {
|
5007 | nativeFontFace = new FontFace(this.loadedName, this.data, {});
|
5008 | } else {
|
5009 | const css = {
|
5010 | weight: this.cssFontInfo.fontWeight
|
5011 | };
|
5012 | if (this.cssFontInfo.italicAngle) {
|
5013 | css.style = `oblique ${this.cssFontInfo.italicAngle}deg`;
|
5014 | }
|
5015 | nativeFontFace = new FontFace(this.cssFontInfo.fontFamily, this.data, css);
|
5016 | }
|
5017 | this._inspectFont?.(this);
|
5018 | return nativeFontFace;
|
5019 | }
|
5020 | createFontFaceRule() {
|
5021 | if (!this.data || this.disableFontFace) {
|
5022 | return null;
|
5023 | }
|
5024 | const data = (0, _util.bytesToString)(this.data);
|
5025 | const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
|
5026 | let rule;
|
5027 | if (!this.cssFontInfo) {
|
5028 | rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
|
5029 | } else {
|
5030 | let css = `font-weight: ${this.cssFontInfo.fontWeight};`;
|
5031 | if (this.cssFontInfo.italicAngle) {
|
5032 | css += `font-style: oblique ${this.cssFontInfo.italicAngle}deg;`;
|
5033 | }
|
5034 | rule = `@font-face {font-family:"${this.cssFontInfo.fontFamily}";${css}src:${url}}`;
|
5035 | }
|
5036 | this._inspectFont?.(this, url);
|
5037 | return rule;
|
5038 | }
|
5039 | getPathGenerator(objs, character) {
|
5040 | if (this.compiledGlyphs[character] !== undefined) {
|
5041 | return this.compiledGlyphs[character];
|
5042 | }
|
5043 | let cmds;
|
5044 | try {
|
5045 | cmds = objs.get(this.loadedName + "_path_" + character);
|
5046 | } catch (ex) {
|
5047 | if (!this.ignoreErrors) {
|
5048 | throw ex;
|
5049 | }
|
5050 | (0, _util.warn)(`getPathGenerator - ignoring character: "${ex}".`);
|
5051 | return this.compiledGlyphs[character] = function (c, size) {};
|
5052 | }
|
5053 | if (this.isEvalSupported && _util.FeatureTest.isEvalSupported) {
|
5054 | const jsBuf = [];
|
5055 | for (const current of cmds) {
|
5056 | const args = current.args !== undefined ? current.args.join(",") : "";
|
5057 | jsBuf.push("c.", current.cmd, "(", args, ");\n");
|
5058 | }
|
5059 | return this.compiledGlyphs[character] = new Function("c", "size", jsBuf.join(""));
|
5060 | }
|
5061 | return this.compiledGlyphs[character] = function (c, size) {
|
5062 | for (const current of cmds) {
|
5063 | if (current.cmd === "scale") {
|
5064 | current.args = [size, -size];
|
5065 | }
|
5066 | c[current.cmd].apply(c, current.args);
|
5067 | }
|
5068 | };
|
5069 | }
|
5070 | }
|
5071 | exports.FontFaceObject = FontFaceObject;
|
5072 |
|
5073 | }),
|
5074 |
|
5075 | ((__unused_webpack_module, exports) => {
|
5076 |
|
5077 |
|
5078 |
|
5079 | Object.defineProperty(exports, "__esModule", ({
|
5080 | value: true
|
5081 | }));
|
5082 | exports.isNodeJS = void 0;
|
5083 | const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
|
5084 | exports.isNodeJS = isNodeJS;
|
5085 |
|
5086 | }),
|
5087 |
|
5088 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
5089 |
|
5090 |
|
5091 |
|
5092 | Object.defineProperty(exports, "__esModule", ({
|
5093 | value: true
|
5094 | }));
|
5095 | exports.CanvasGraphics = void 0;
|
5096 | var _util = __w_pdfjs_require__(1);
|
5097 | var _display_utils = __w_pdfjs_require__(6);
|
5098 | var _pattern_helper = __w_pdfjs_require__(12);
|
5099 | var _image_utils = __w_pdfjs_require__(13);
|
5100 | var _is_node = __w_pdfjs_require__(10);
|
5101 | const MIN_FONT_SIZE = 16;
|
5102 | const MAX_FONT_SIZE = 100;
|
5103 | const MAX_GROUP_SIZE = 4096;
|
5104 | const EXECUTION_TIME = 15;
|
5105 | const EXECUTION_STEPS = 10;
|
5106 | const MAX_SIZE_TO_COMPILE = 1000;
|
5107 | const FULL_CHUNK_HEIGHT = 16;
|
5108 | function mirrorContextOperations(ctx, destCtx) {
|
5109 | if (ctx._removeMirroring) {
|
5110 | throw new Error("Context is already forwarding operations.");
|
5111 | }
|
5112 | ctx.__originalSave = ctx.save;
|
5113 | ctx.__originalRestore = ctx.restore;
|
5114 | ctx.__originalRotate = ctx.rotate;
|
5115 | ctx.__originalScale = ctx.scale;
|
5116 | ctx.__originalTranslate = ctx.translate;
|
5117 | ctx.__originalTransform = ctx.transform;
|
5118 | ctx.__originalSetTransform = ctx.setTransform;
|
5119 | ctx.__originalResetTransform = ctx.resetTransform;
|
5120 | ctx.__originalClip = ctx.clip;
|
5121 | ctx.__originalMoveTo = ctx.moveTo;
|
5122 | ctx.__originalLineTo = ctx.lineTo;
|
5123 | ctx.__originalBezierCurveTo = ctx.bezierCurveTo;
|
5124 | ctx.__originalRect = ctx.rect;
|
5125 | ctx.__originalClosePath = ctx.closePath;
|
5126 | ctx.__originalBeginPath = ctx.beginPath;
|
5127 | ctx._removeMirroring = () => {
|
5128 | ctx.save = ctx.__originalSave;
|
5129 | ctx.restore = ctx.__originalRestore;
|
5130 | ctx.rotate = ctx.__originalRotate;
|
5131 | ctx.scale = ctx.__originalScale;
|
5132 | ctx.translate = ctx.__originalTranslate;
|
5133 | ctx.transform = ctx.__originalTransform;
|
5134 | ctx.setTransform = ctx.__originalSetTransform;
|
5135 | ctx.resetTransform = ctx.__originalResetTransform;
|
5136 | ctx.clip = ctx.__originalClip;
|
5137 | ctx.moveTo = ctx.__originalMoveTo;
|
5138 | ctx.lineTo = ctx.__originalLineTo;
|
5139 | ctx.bezierCurveTo = ctx.__originalBezierCurveTo;
|
5140 | ctx.rect = ctx.__originalRect;
|
5141 | ctx.closePath = ctx.__originalClosePath;
|
5142 | ctx.beginPath = ctx.__originalBeginPath;
|
5143 | delete ctx._removeMirroring;
|
5144 | };
|
5145 | ctx.save = function ctxSave() {
|
5146 | destCtx.save();
|
5147 | this.__originalSave();
|
5148 | };
|
5149 | ctx.restore = function ctxRestore() {
|
5150 | destCtx.restore();
|
5151 | this.__originalRestore();
|
5152 | };
|
5153 | ctx.translate = function ctxTranslate(x, y) {
|
5154 | destCtx.translate(x, y);
|
5155 | this.__originalTranslate(x, y);
|
5156 | };
|
5157 | ctx.scale = function ctxScale(x, y) {
|
5158 | destCtx.scale(x, y);
|
5159 | this.__originalScale(x, y);
|
5160 | };
|
5161 | ctx.transform = function ctxTransform(a, b, c, d, e, f) {
|
5162 | destCtx.transform(a, b, c, d, e, f);
|
5163 | this.__originalTransform(a, b, c, d, e, f);
|
5164 | };
|
5165 | ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
|
5166 | destCtx.setTransform(a, b, c, d, e, f);
|
5167 | this.__originalSetTransform(a, b, c, d, e, f);
|
5168 | };
|
5169 | ctx.resetTransform = function ctxResetTransform() {
|
5170 | destCtx.resetTransform();
|
5171 | this.__originalResetTransform();
|
5172 | };
|
5173 | ctx.rotate = function ctxRotate(angle) {
|
5174 | destCtx.rotate(angle);
|
5175 | this.__originalRotate(angle);
|
5176 | };
|
5177 | ctx.clip = function ctxRotate(rule) {
|
5178 | destCtx.clip(rule);
|
5179 | this.__originalClip(rule);
|
5180 | };
|
5181 | ctx.moveTo = function (x, y) {
|
5182 | destCtx.moveTo(x, y);
|
5183 | this.__originalMoveTo(x, y);
|
5184 | };
|
5185 | ctx.lineTo = function (x, y) {
|
5186 | destCtx.lineTo(x, y);
|
5187 | this.__originalLineTo(x, y);
|
5188 | };
|
5189 | ctx.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
|
5190 | destCtx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
|
5191 | this.__originalBezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
|
5192 | };
|
5193 | ctx.rect = function (x, y, width, height) {
|
5194 | destCtx.rect(x, y, width, height);
|
5195 | this.__originalRect(x, y, width, height);
|
5196 | };
|
5197 | ctx.closePath = function () {
|
5198 | destCtx.closePath();
|
5199 | this.__originalClosePath();
|
5200 | };
|
5201 | ctx.beginPath = function () {
|
5202 | destCtx.beginPath();
|
5203 | this.__originalBeginPath();
|
5204 | };
|
5205 | }
|
5206 | class CachedCanvases {
|
5207 | constructor(canvasFactory) {
|
5208 | this.canvasFactory = canvasFactory;
|
5209 | this.cache = Object.create(null);
|
5210 | }
|
5211 | getCanvas(id, width, height) {
|
5212 | let canvasEntry;
|
5213 | if (this.cache[id] !== undefined) {
|
5214 | canvasEntry = this.cache[id];
|
5215 | this.canvasFactory.reset(canvasEntry, width, height);
|
5216 | } else {
|
5217 | canvasEntry = this.canvasFactory.create(width, height);
|
5218 | this.cache[id] = canvasEntry;
|
5219 | }
|
5220 | return canvasEntry;
|
5221 | }
|
5222 | delete(id) {
|
5223 | delete this.cache[id];
|
5224 | }
|
5225 | clear() {
|
5226 | for (const id in this.cache) {
|
5227 | const canvasEntry = this.cache[id];
|
5228 | this.canvasFactory.destroy(canvasEntry);
|
5229 | delete this.cache[id];
|
5230 | }
|
5231 | }
|
5232 | }
|
5233 | function drawImageAtIntegerCoords(ctx, srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH) {
|
5234 | const [a, b, c, d, tx, ty] = (0, _display_utils.getCurrentTransform)(ctx);
|
5235 | if (b === 0 && c === 0) {
|
5236 | const tlX = destX * a + tx;
|
5237 | const rTlX = Math.round(tlX);
|
5238 | const tlY = destY * d + ty;
|
5239 | const rTlY = Math.round(tlY);
|
5240 | const brX = (destX + destW) * a + tx;
|
5241 | const rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
|
5242 | const brY = (destY + destH) * d + ty;
|
5243 | const rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
|
5244 | ctx.setTransform(Math.sign(a), 0, 0, Math.sign(d), rTlX, rTlY);
|
5245 | ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rWidth, rHeight);
|
5246 | ctx.setTransform(a, b, c, d, tx, ty);
|
5247 | return [rWidth, rHeight];
|
5248 | }
|
5249 | if (a === 0 && d === 0) {
|
5250 | const tlX = destY * c + tx;
|
5251 | const rTlX = Math.round(tlX);
|
5252 | const tlY = destX * b + ty;
|
5253 | const rTlY = Math.round(tlY);
|
5254 | const brX = (destY + destH) * c + tx;
|
5255 | const rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
|
5256 | const brY = (destX + destW) * b + ty;
|
5257 | const rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
|
5258 | ctx.setTransform(0, Math.sign(b), Math.sign(c), 0, rTlX, rTlY);
|
5259 | ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rHeight, rWidth);
|
5260 | ctx.setTransform(a, b, c, d, tx, ty);
|
5261 | return [rHeight, rWidth];
|
5262 | }
|
5263 | ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH);
|
5264 | const scaleX = Math.hypot(a, b);
|
5265 | const scaleY = Math.hypot(c, d);
|
5266 | return [scaleX * destW, scaleY * destH];
|
5267 | }
|
5268 | function compileType3Glyph(imgData) {
|
5269 | const {
|
5270 | width,
|
5271 | height
|
5272 | } = imgData;
|
5273 | if (width > MAX_SIZE_TO_COMPILE || height > MAX_SIZE_TO_COMPILE) {
|
5274 | return null;
|
5275 | }
|
5276 | const POINT_TO_PROCESS_LIMIT = 1000;
|
5277 | const POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
|
5278 | const width1 = width + 1;
|
5279 | let points = new Uint8Array(width1 * (height + 1));
|
5280 | let i, j, j0;
|
5281 | const lineSize = width + 7 & ~7;
|
5282 | let data = new Uint8Array(lineSize * height),
|
5283 | pos = 0;
|
5284 | for (const elem of imgData.data) {
|
5285 | let mask = 128;
|
5286 | while (mask > 0) {
|
5287 | data[pos++] = elem & mask ? 0 : 255;
|
5288 | mask >>= 1;
|
5289 | }
|
5290 | }
|
5291 | let count = 0;
|
5292 | pos = 0;
|
5293 | if (data[pos] !== 0) {
|
5294 | points[0] = 1;
|
5295 | ++count;
|
5296 | }
|
5297 | for (j = 1; j < width; j++) {
|
5298 | if (data[pos] !== data[pos + 1]) {
|
5299 | points[j] = data[pos] ? 2 : 1;
|
5300 | ++count;
|
5301 | }
|
5302 | pos++;
|
5303 | }
|
5304 | if (data[pos] !== 0) {
|
5305 | points[j] = 2;
|
5306 | ++count;
|
5307 | }
|
5308 | for (i = 1; i < height; i++) {
|
5309 | pos = i * lineSize;
|
5310 | j0 = i * width1;
|
5311 | if (data[pos - lineSize] !== data[pos]) {
|
5312 | points[j0] = data[pos] ? 1 : 8;
|
5313 | ++count;
|
5314 | }
|
5315 | let sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
|
5316 | for (j = 1; j < width; j++) {
|
5317 | sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
|
5318 | if (POINT_TYPES[sum]) {
|
5319 | points[j0 + j] = POINT_TYPES[sum];
|
5320 | ++count;
|
5321 | }
|
5322 | pos++;
|
5323 | }
|
5324 | if (data[pos - lineSize] !== data[pos]) {
|
5325 | points[j0 + j] = data[pos] ? 2 : 4;
|
5326 | ++count;
|
5327 | }
|
5328 | if (count > POINT_TO_PROCESS_LIMIT) {
|
5329 | return null;
|
5330 | }
|
5331 | }
|
5332 | pos = lineSize * (height - 1);
|
5333 | j0 = i * width1;
|
5334 | if (data[pos] !== 0) {
|
5335 | points[j0] = 8;
|
5336 | ++count;
|
5337 | }
|
5338 | for (j = 1; j < width; j++) {
|
5339 | if (data[pos] !== data[pos + 1]) {
|
5340 | points[j0 + j] = data[pos] ? 4 : 8;
|
5341 | ++count;
|
5342 | }
|
5343 | pos++;
|
5344 | }
|
5345 | if (data[pos] !== 0) {
|
5346 | points[j0 + j] = 4;
|
5347 | ++count;
|
5348 | }
|
5349 | if (count > POINT_TO_PROCESS_LIMIT) {
|
5350 | return null;
|
5351 | }
|
5352 | const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
|
5353 | const path = new Path2D();
|
5354 | for (i = 0; count && i <= height; i++) {
|
5355 | let p = i * width1;
|
5356 | const end = p + width;
|
5357 | while (p < end && !points[p]) {
|
5358 | p++;
|
5359 | }
|
5360 | if (p === end) {
|
5361 | continue;
|
5362 | }
|
5363 | path.moveTo(p % width1, i);
|
5364 | const p0 = p;
|
5365 | let type = points[p];
|
5366 | do {
|
5367 | const step = steps[type];
|
5368 | do {
|
5369 | p += step;
|
5370 | } while (!points[p]);
|
5371 | const pp = points[p];
|
5372 | if (pp !== 5 && pp !== 10) {
|
5373 | type = pp;
|
5374 | points[p] = 0;
|
5375 | } else {
|
5376 | type = pp & 0x33 * type >> 4;
|
5377 | points[p] &= type >> 2 | type << 2;
|
5378 | }
|
5379 | path.lineTo(p % width1, p / width1 | 0);
|
5380 | if (!points[p]) {
|
5381 | --count;
|
5382 | }
|
5383 | } while (p0 !== p);
|
5384 | --i;
|
5385 | }
|
5386 | data = null;
|
5387 | points = null;
|
5388 | const drawOutline = function (c) {
|
5389 | c.save();
|
5390 | c.scale(1 / width, -1 / height);
|
5391 | c.translate(0, -height);
|
5392 | c.fill(path);
|
5393 | c.beginPath();
|
5394 | c.restore();
|
5395 | };
|
5396 | return drawOutline;
|
5397 | }
|
5398 | class CanvasExtraState {
|
5399 | constructor(width, height) {
|
5400 | this.alphaIsShape = false;
|
5401 | this.fontSize = 0;
|
5402 | this.fontSizeScale = 1;
|
5403 | this.textMatrix = _util.IDENTITY_MATRIX;
|
5404 | this.textMatrixScale = 1;
|
5405 | this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
|
5406 | this.leading = 0;
|
5407 | this.x = 0;
|
5408 | this.y = 0;
|
5409 | this.lineX = 0;
|
5410 | this.lineY = 0;
|
5411 | this.charSpacing = 0;
|
5412 | this.wordSpacing = 0;
|
5413 | this.textHScale = 1;
|
5414 | this.textRenderingMode = _util.TextRenderingMode.FILL;
|
5415 | this.textRise = 0;
|
5416 | this.fillColor = "#000000";
|
5417 | this.strokeColor = "#000000";
|
5418 | this.patternFill = false;
|
5419 | this.fillAlpha = 1;
|
5420 | this.strokeAlpha = 1;
|
5421 | this.lineWidth = 1;
|
5422 | this.activeSMask = null;
|
5423 | this.transferMaps = "none";
|
5424 | this.startNewPathAndClipBox([0, 0, width, height]);
|
5425 | }
|
5426 | clone() {
|
5427 | const clone = Object.create(this);
|
5428 | clone.clipBox = this.clipBox.slice();
|
5429 | return clone;
|
5430 | }
|
5431 | setCurrentPoint(x, y) {
|
5432 | this.x = x;
|
5433 | this.y = y;
|
5434 | }
|
5435 | updatePathMinMax(transform, x, y) {
|
5436 | [x, y] = _util.Util.applyTransform([x, y], transform);
|
5437 | this.minX = Math.min(this.minX, x);
|
5438 | this.minY = Math.min(this.minY, y);
|
5439 | this.maxX = Math.max(this.maxX, x);
|
5440 | this.maxY = Math.max(this.maxY, y);
|
5441 | }
|
5442 | updateRectMinMax(transform, rect) {
|
5443 | const p1 = _util.Util.applyTransform(rect, transform);
|
5444 | const p2 = _util.Util.applyTransform(rect.slice(2), transform);
|
5445 | this.minX = Math.min(this.minX, p1[0], p2[0]);
|
5446 | this.minY = Math.min(this.minY, p1[1], p2[1]);
|
5447 | this.maxX = Math.max(this.maxX, p1[0], p2[0]);
|
5448 | this.maxY = Math.max(this.maxY, p1[1], p2[1]);
|
5449 | }
|
5450 | updateScalingPathMinMax(transform, minMax) {
|
5451 | _util.Util.scaleMinMax(transform, minMax);
|
5452 | this.minX = Math.min(this.minX, minMax[0]);
|
5453 | this.maxX = Math.max(this.maxX, minMax[1]);
|
5454 | this.minY = Math.min(this.minY, minMax[2]);
|
5455 | this.maxY = Math.max(this.maxY, minMax[3]);
|
5456 | }
|
5457 | updateCurvePathMinMax(transform, x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
|
5458 | const box = _util.Util.bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3);
|
5459 | if (minMax) {
|
5460 | minMax[0] = Math.min(minMax[0], box[0], box[2]);
|
5461 | minMax[1] = Math.max(minMax[1], box[0], box[2]);
|
5462 | minMax[2] = Math.min(minMax[2], box[1], box[3]);
|
5463 | minMax[3] = Math.max(minMax[3], box[1], box[3]);
|
5464 | return;
|
5465 | }
|
5466 | this.updateRectMinMax(transform, box);
|
5467 | }
|
5468 | getPathBoundingBox(pathType = _pattern_helper.PathType.FILL, transform = null) {
|
5469 | const box = [this.minX, this.minY, this.maxX, this.maxY];
|
5470 | if (pathType === _pattern_helper.PathType.STROKE) {
|
5471 | if (!transform) {
|
5472 | (0, _util.unreachable)("Stroke bounding box must include transform.");
|
5473 | }
|
5474 | const scale = _util.Util.singularValueDecompose2dScale(transform);
|
5475 | const xStrokePad = scale[0] * this.lineWidth / 2;
|
5476 | const yStrokePad = scale[1] * this.lineWidth / 2;
|
5477 | box[0] -= xStrokePad;
|
5478 | box[1] -= yStrokePad;
|
5479 | box[2] += xStrokePad;
|
5480 | box[3] += yStrokePad;
|
5481 | }
|
5482 | return box;
|
5483 | }
|
5484 | updateClipFromPath() {
|
5485 | const intersect = _util.Util.intersect(this.clipBox, this.getPathBoundingBox());
|
5486 | this.startNewPathAndClipBox(intersect || [0, 0, 0, 0]);
|
5487 | }
|
5488 | isEmptyClip() {
|
5489 | return this.minX === Infinity;
|
5490 | }
|
5491 | startNewPathAndClipBox(box) {
|
5492 | this.clipBox = box;
|
5493 | this.minX = Infinity;
|
5494 | this.minY = Infinity;
|
5495 | this.maxX = 0;
|
5496 | this.maxY = 0;
|
5497 | }
|
5498 | getClippedPathBoundingBox(pathType = _pattern_helper.PathType.FILL, transform = null) {
|
5499 | return _util.Util.intersect(this.clipBox, this.getPathBoundingBox(pathType, transform));
|
5500 | }
|
5501 | }
|
5502 | function putBinaryImageData(ctx, imgData) {
|
5503 | if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
|
5504 | ctx.putImageData(imgData, 0, 0);
|
5505 | return;
|
5506 | }
|
5507 | const height = imgData.height,
|
5508 | width = imgData.width;
|
5509 | const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
|
5510 | const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
|
5511 | const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
|
5512 | const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
|
5513 | let srcPos = 0,
|
5514 | destPos;
|
5515 | const src = imgData.data;
|
5516 | const dest = chunkImgData.data;
|
5517 | let i, j, thisChunkHeight, elemsInThisChunk;
|
5518 | if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
|
5519 | const srcLength = src.byteLength;
|
5520 | const dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
|
5521 | const dest32DataLength = dest32.length;
|
5522 | const fullSrcDiff = width + 7 >> 3;
|
5523 | const white = 0xffffffff;
|
5524 | const black = _util.FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
|
5525 | for (i = 0; i < totalChunks; i++) {
|
5526 | thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
|
5527 | destPos = 0;
|
5528 | for (j = 0; j < thisChunkHeight; j++) {
|
5529 | const srcDiff = srcLength - srcPos;
|
5530 | let k = 0;
|
5531 | const kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
|
5532 | const kEndUnrolled = kEnd & ~7;
|
5533 | let mask = 0;
|
5534 | let srcByte = 0;
|
5535 | for (; k < kEndUnrolled; k += 8) {
|
5536 | srcByte = src[srcPos++];
|
5537 | dest32[destPos++] = srcByte & 128 ? white : black;
|
5538 | dest32[destPos++] = srcByte & 64 ? white : black;
|
5539 | dest32[destPos++] = srcByte & 32 ? white : black;
|
5540 | dest32[destPos++] = srcByte & 16 ? white : black;
|
5541 | dest32[destPos++] = srcByte & 8 ? white : black;
|
5542 | dest32[destPos++] = srcByte & 4 ? white : black;
|
5543 | dest32[destPos++] = srcByte & 2 ? white : black;
|
5544 | dest32[destPos++] = srcByte & 1 ? white : black;
|
5545 | }
|
5546 | for (; k < kEnd; k++) {
|
5547 | if (mask === 0) {
|
5548 | srcByte = src[srcPos++];
|
5549 | mask = 128;
|
5550 | }
|
5551 | dest32[destPos++] = srcByte & mask ? white : black;
|
5552 | mask >>= 1;
|
5553 | }
|
5554 | }
|
5555 | while (destPos < dest32DataLength) {
|
5556 | dest32[destPos++] = 0;
|
5557 | }
|
5558 | ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
|
5559 | }
|
5560 | } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
|
5561 | j = 0;
|
5562 | elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
|
5563 | for (i = 0; i < fullChunks; i++) {
|
5564 | dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
|
5565 | srcPos += elemsInThisChunk;
|
5566 | ctx.putImageData(chunkImgData, 0, j);
|
5567 | j += FULL_CHUNK_HEIGHT;
|
5568 | }
|
5569 | if (i < totalChunks) {
|
5570 | elemsInThisChunk = width * partialChunkHeight * 4;
|
5571 | dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
|
5572 | ctx.putImageData(chunkImgData, 0, j);
|
5573 | }
|
5574 | } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
|
5575 | thisChunkHeight = FULL_CHUNK_HEIGHT;
|
5576 | elemsInThisChunk = width * thisChunkHeight;
|
5577 | for (i = 0; i < totalChunks; i++) {
|
5578 | if (i >= fullChunks) {
|
5579 | thisChunkHeight = partialChunkHeight;
|
5580 | elemsInThisChunk = width * thisChunkHeight;
|
5581 | }
|
5582 | destPos = 0;
|
5583 | for (j = elemsInThisChunk; j--;) {
|
5584 | dest[destPos++] = src[srcPos++];
|
5585 | dest[destPos++] = src[srcPos++];
|
5586 | dest[destPos++] = src[srcPos++];
|
5587 | dest[destPos++] = 255;
|
5588 | }
|
5589 | ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
|
5590 | }
|
5591 | } else {
|
5592 | throw new Error(`bad image kind: ${imgData.kind}`);
|
5593 | }
|
5594 | }
|
5595 | function putBinaryImageMask(ctx, imgData) {
|
5596 | if (imgData.bitmap) {
|
5597 | ctx.drawImage(imgData.bitmap, 0, 0);
|
5598 | return;
|
5599 | }
|
5600 | const height = imgData.height,
|
5601 | width = imgData.width;
|
5602 | const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
|
5603 | const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
|
5604 | const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
|
5605 | const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
|
5606 | let srcPos = 0;
|
5607 | const src = imgData.data;
|
5608 | const dest = chunkImgData.data;
|
5609 | for (let i = 0; i < totalChunks; i++) {
|
5610 | const thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
|
5611 | ({
|
5612 | srcPos
|
5613 | } = (0, _image_utils.convertBlackAndWhiteToRGBA)({
|
5614 | src,
|
5615 | srcPos,
|
5616 | dest,
|
5617 | width,
|
5618 | height: thisChunkHeight,
|
5619 | nonBlackColor: 0
|
5620 | }));
|
5621 | ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
|
5622 | }
|
5623 | }
|
5624 | function copyCtxState(sourceCtx, destCtx) {
|
5625 | const properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font", "filter"];
|
5626 | for (const property of properties) {
|
5627 | if (sourceCtx[property] !== undefined) {
|
5628 | destCtx[property] = sourceCtx[property];
|
5629 | }
|
5630 | }
|
5631 | if (sourceCtx.setLineDash !== undefined) {
|
5632 | destCtx.setLineDash(sourceCtx.getLineDash());
|
5633 | destCtx.lineDashOffset = sourceCtx.lineDashOffset;
|
5634 | }
|
5635 | }
|
5636 | function resetCtxToDefault(ctx) {
|
5637 | ctx.strokeStyle = ctx.fillStyle = "#000000";
|
5638 | ctx.fillRule = "nonzero";
|
5639 | ctx.globalAlpha = 1;
|
5640 | ctx.lineWidth = 1;
|
5641 | ctx.lineCap = "butt";
|
5642 | ctx.lineJoin = "miter";
|
5643 | ctx.miterLimit = 10;
|
5644 | ctx.globalCompositeOperation = "source-over";
|
5645 | ctx.font = "10px sans-serif";
|
5646 | if (ctx.setLineDash !== undefined) {
|
5647 | ctx.setLineDash([]);
|
5648 | ctx.lineDashOffset = 0;
|
5649 | }
|
5650 | if (!_is_node.isNodeJS) {
|
5651 | ctx.filter = "none";
|
5652 | }
|
5653 | }
|
5654 | function composeSMaskBackdrop(bytes, r0, g0, b0) {
|
5655 | const length = bytes.length;
|
5656 | for (let i = 3; i < length; i += 4) {
|
5657 | const alpha = bytes[i];
|
5658 | if (alpha === 0) {
|
5659 | bytes[i - 3] = r0;
|
5660 | bytes[i - 2] = g0;
|
5661 | bytes[i - 1] = b0;
|
5662 | } else if (alpha < 255) {
|
5663 | const alpha_ = 255 - alpha;
|
5664 | bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
|
5665 | bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
|
5666 | bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
|
5667 | }
|
5668 | }
|
5669 | }
|
5670 | function composeSMaskAlpha(maskData, layerData, transferMap) {
|
5671 | const length = maskData.length;
|
5672 | const scale = 1 / 255;
|
5673 | for (let i = 3; i < length; i += 4) {
|
5674 | const alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
|
5675 | layerData[i] = layerData[i] * alpha * scale | 0;
|
5676 | }
|
5677 | }
|
5678 | function composeSMaskLuminosity(maskData, layerData, transferMap) {
|
5679 | const length = maskData.length;
|
5680 | for (let i = 3; i < length; i += 4) {
|
5681 | const y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
|
5682 | layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
|
5683 | }
|
5684 | }
|
5685 | function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap, layerOffsetX, layerOffsetY, maskOffsetX, maskOffsetY) {
|
5686 | const hasBackdrop = !!backdrop;
|
5687 | const r0 = hasBackdrop ? backdrop[0] : 0;
|
5688 | const g0 = hasBackdrop ? backdrop[1] : 0;
|
5689 | const b0 = hasBackdrop ? backdrop[2] : 0;
|
5690 | let composeFn;
|
5691 | if (subtype === "Luminosity") {
|
5692 | composeFn = composeSMaskLuminosity;
|
5693 | } else {
|
5694 | composeFn = composeSMaskAlpha;
|
5695 | }
|
5696 | const PIXELS_TO_PROCESS = 1048576;
|
5697 | const chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
|
5698 | for (let row = 0; row < height; row += chunkSize) {
|
5699 | const chunkHeight = Math.min(chunkSize, height - row);
|
5700 | const maskData = maskCtx.getImageData(layerOffsetX - maskOffsetX, row + (layerOffsetY - maskOffsetY), width, chunkHeight);
|
5701 | const layerData = layerCtx.getImageData(layerOffsetX, row + layerOffsetY, width, chunkHeight);
|
5702 | if (hasBackdrop) {
|
5703 | composeSMaskBackdrop(maskData.data, r0, g0, b0);
|
5704 | }
|
5705 | composeFn(maskData.data, layerData.data, transferMap);
|
5706 | layerCtx.putImageData(layerData, layerOffsetX, row + layerOffsetY);
|
5707 | }
|
5708 | }
|
5709 | function composeSMask(ctx, smask, layerCtx, layerBox) {
|
5710 | const layerOffsetX = layerBox[0];
|
5711 | const layerOffsetY = layerBox[1];
|
5712 | const layerWidth = layerBox[2] - layerOffsetX;
|
5713 | const layerHeight = layerBox[3] - layerOffsetY;
|
5714 | if (layerWidth === 0 || layerHeight === 0) {
|
5715 | return;
|
5716 | }
|
5717 | genericComposeSMask(smask.context, layerCtx, layerWidth, layerHeight, smask.subtype, smask.backdrop, smask.transferMap, layerOffsetX, layerOffsetY, smask.offsetX, smask.offsetY);
|
5718 | ctx.save();
|
5719 | ctx.globalAlpha = 1;
|
5720 | ctx.globalCompositeOperation = "source-over";
|
5721 | ctx.setTransform(1, 0, 0, 1, 0, 0);
|
5722 | ctx.drawImage(layerCtx.canvas, 0, 0);
|
5723 | ctx.restore();
|
5724 | }
|
5725 | function getImageSmoothingEnabled(transform, interpolate) {
|
5726 | const scale = _util.Util.singularValueDecompose2dScale(transform);
|
5727 | scale[0] = Math.fround(scale[0]);
|
5728 | scale[1] = Math.fround(scale[1]);
|
5729 | const actualScale = Math.fround((globalThis.devicePixelRatio || 1) * _display_utils.PixelsPerInch.PDF_TO_CSS_UNITS);
|
5730 | if (interpolate !== undefined) {
|
5731 | return interpolate;
|
5732 | } else if (scale[0] <= actualScale || scale[1] <= actualScale) {
|
5733 | return true;
|
5734 | }
|
5735 | return false;
|
5736 | }
|
5737 | const LINE_CAP_STYLES = ["butt", "round", "square"];
|
5738 | const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
|
5739 | const NORMAL_CLIP = {};
|
5740 | const EO_CLIP = {};
|
5741 | class CanvasGraphics {
|
5742 | constructor(canvasCtx, commonObjs, objs, canvasFactory, filterFactory, {
|
5743 | optionalContentConfig,
|
5744 | markedContentStack = null
|
5745 | }, annotationCanvasMap, pageColors) {
|
5746 | this.ctx = canvasCtx;
|
5747 | this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
|
5748 | this.stateStack = [];
|
5749 | this.pendingClip = null;
|
5750 | this.pendingEOFill = false;
|
5751 | this.res = null;
|
5752 | this.xobjs = null;
|
5753 | this.commonObjs = commonObjs;
|
5754 | this.objs = objs;
|
5755 | this.canvasFactory = canvasFactory;
|
5756 | this.filterFactory = filterFactory;
|
5757 | this.groupStack = [];
|
5758 | this.processingType3 = null;
|
5759 | this.baseTransform = null;
|
5760 | this.baseTransformStack = [];
|
5761 | this.groupLevel = 0;
|
5762 | this.smaskStack = [];
|
5763 | this.smaskCounter = 0;
|
5764 | this.tempSMask = null;
|
5765 | this.suspendedCtx = null;
|
5766 | this.contentVisible = true;
|
5767 | this.markedContentStack = markedContentStack || [];
|
5768 | this.optionalContentConfig = optionalContentConfig;
|
5769 | this.cachedCanvases = new CachedCanvases(this.canvasFactory);
|
5770 | this.cachedPatterns = new Map();
|
5771 | this.annotationCanvasMap = annotationCanvasMap;
|
5772 | this.viewportScale = 1;
|
5773 | this.outputScaleX = 1;
|
5774 | this.outputScaleY = 1;
|
5775 | this.pageColors = pageColors;
|
5776 | this._cachedScaleForStroking = [-1, 0];
|
5777 | this._cachedGetSinglePixelWidth = null;
|
5778 | this._cachedBitmapsMap = new Map();
|
5779 | }
|
5780 | getObject(data, fallback = null) {
|
5781 | if (typeof data === "string") {
|
5782 | return data.startsWith("g_") ? this.commonObjs.get(data) : this.objs.get(data);
|
5783 | }
|
5784 | return fallback;
|
5785 | }
|
5786 | beginDrawing({
|
5787 | transform,
|
5788 | viewport,
|
5789 | transparency = false,
|
5790 | background = null
|
5791 | }) {
|
5792 | const width = this.ctx.canvas.width;
|
5793 | const height = this.ctx.canvas.height;
|
5794 | const savedFillStyle = this.ctx.fillStyle;
|
5795 | this.ctx.fillStyle = background || "#ffffff";
|
5796 | this.ctx.fillRect(0, 0, width, height);
|
5797 | this.ctx.fillStyle = savedFillStyle;
|
5798 | if (transparency) {
|
5799 | const transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height);
|
5800 | this.compositeCtx = this.ctx;
|
5801 | this.transparentCanvas = transparentCanvas.canvas;
|
5802 | this.ctx = transparentCanvas.context;
|
5803 | this.ctx.save();
|
5804 | this.ctx.transform(...(0, _display_utils.getCurrentTransform)(this.compositeCtx));
|
5805 | }
|
5806 | this.ctx.save();
|
5807 | resetCtxToDefault(this.ctx);
|
5808 | if (transform) {
|
5809 | this.ctx.transform(...transform);
|
5810 | this.outputScaleX = transform[0];
|
5811 | this.outputScaleY = transform[0];
|
5812 | }
|
5813 | this.ctx.transform(...viewport.transform);
|
5814 | this.viewportScale = viewport.scale;
|
5815 | this.baseTransform = (0, _display_utils.getCurrentTransform)(this.ctx);
|
5816 | }
|
5817 | executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
|
5818 | const argsArray = operatorList.argsArray;
|
5819 | const fnArray = operatorList.fnArray;
|
5820 | let i = executionStartIdx || 0;
|
5821 | const argsArrayLen = argsArray.length;
|
5822 | if (argsArrayLen === i) {
|
5823 | return i;
|
5824 | }
|
5825 | const chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
|
5826 | const endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
|
5827 | let steps = 0;
|
5828 | const commonObjs = this.commonObjs;
|
5829 | const objs = this.objs;
|
5830 | let fnId;
|
5831 | while (true) {
|
5832 | if (stepper !== undefined && i === stepper.nextBreakPoint) {
|
5833 | stepper.breakIt(i, continueCallback);
|
5834 | return i;
|
5835 | }
|
5836 | fnId = fnArray[i];
|
5837 | if (fnId !== _util.OPS.dependency) {
|
5838 | this[fnId].apply(this, argsArray[i]);
|
5839 | } else {
|
5840 | for (const depObjId of argsArray[i]) {
|
5841 | const objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
|
5842 | if (!objsPool.has(depObjId)) {
|
5843 | objsPool.get(depObjId, continueCallback);
|
5844 | return i;
|
5845 | }
|
5846 | }
|
5847 | }
|
5848 | i++;
|
5849 | if (i === argsArrayLen) {
|
5850 | return i;
|
5851 | }
|
5852 | if (chunkOperations && ++steps > EXECUTION_STEPS) {
|
5853 | if (Date.now() > endTime) {
|
5854 | continueCallback();
|
5855 | return i;
|
5856 | }
|
5857 | steps = 0;
|
5858 | }
|
5859 | }
|
5860 | }
|
5861 | #restoreInitialState() {
|
5862 | while (this.stateStack.length || this.inSMaskMode) {
|
5863 | this.restore();
|
5864 | }
|
5865 | this.ctx.restore();
|
5866 | if (this.transparentCanvas) {
|
5867 | this.ctx = this.compositeCtx;
|
5868 | this.ctx.save();
|
5869 | this.ctx.setTransform(1, 0, 0, 1, 0, 0);
|
5870 | this.ctx.drawImage(this.transparentCanvas, 0, 0);
|
5871 | this.ctx.restore();
|
5872 | this.transparentCanvas = null;
|
5873 | }
|
5874 | }
|
5875 | endDrawing() {
|
5876 | this.#restoreInitialState();
|
5877 | this.cachedCanvases.clear();
|
5878 | this.cachedPatterns.clear();
|
5879 | for (const cache of this._cachedBitmapsMap.values()) {
|
5880 | for (const canvas of cache.values()) {
|
5881 | if (typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement) {
|
5882 | canvas.width = canvas.height = 0;
|
5883 | }
|
5884 | }
|
5885 | cache.clear();
|
5886 | }
|
5887 | this._cachedBitmapsMap.clear();
|
5888 | this.#drawFilter();
|
5889 | }
|
5890 | #drawFilter() {
|
5891 | if (this.pageColors) {
|
5892 | const hcmFilterId = this.filterFactory.addHCMFilter(this.pageColors.foreground, this.pageColors.background);
|
5893 | if (hcmFilterId !== "none") {
|
5894 | const savedFilter = this.ctx.filter;
|
5895 | this.ctx.filter = hcmFilterId;
|
5896 | this.ctx.drawImage(this.ctx.canvas, 0, 0);
|
5897 | this.ctx.filter = savedFilter;
|
5898 | }
|
5899 | }
|
5900 | }
|
5901 | _scaleImage(img, inverseTransform) {
|
5902 | const width = img.width;
|
5903 | const height = img.height;
|
5904 | let widthScale = Math.max(Math.hypot(inverseTransform[0], inverseTransform[1]), 1);
|
5905 | let heightScale = Math.max(Math.hypot(inverseTransform[2], inverseTransform[3]), 1);
|
5906 | let paintWidth = width,
|
5907 | paintHeight = height;
|
5908 | let tmpCanvasId = "prescale1";
|
5909 | let tmpCanvas, tmpCtx;
|
5910 | while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
|
5911 | let newWidth = paintWidth,
|
5912 | newHeight = paintHeight;
|
5913 | if (widthScale > 2 && paintWidth > 1) {
|
5914 | newWidth = paintWidth >= 16384 ? Math.floor(paintWidth / 2) - 1 || 1 : Math.ceil(paintWidth / 2);
|
5915 | widthScale /= paintWidth / newWidth;
|
5916 | }
|
5917 | if (heightScale > 2 && paintHeight > 1) {
|
5918 | newHeight = paintHeight >= 16384 ? Math.floor(paintHeight / 2) - 1 || 1 : Math.ceil(paintHeight) / 2;
|
5919 | heightScale /= paintHeight / newHeight;
|
5920 | }
|
5921 | tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
|
5922 | tmpCtx = tmpCanvas.context;
|
5923 | tmpCtx.clearRect(0, 0, newWidth, newHeight);
|
5924 | tmpCtx.drawImage(img, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
|
5925 | img = tmpCanvas.canvas;
|
5926 | paintWidth = newWidth;
|
5927 | paintHeight = newHeight;
|
5928 | tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
|
5929 | }
|
5930 | return {
|
5931 | img,
|
5932 | paintWidth,
|
5933 | paintHeight
|
5934 | };
|
5935 | }
|
5936 | _createMaskCanvas(img) {
|
5937 | const ctx = this.ctx;
|
5938 | const {
|
5939 | width,
|
5940 | height
|
5941 | } = img;
|
5942 | const fillColor = this.current.fillColor;
|
5943 | const isPatternFill = this.current.patternFill;
|
5944 | const currentTransform = (0, _display_utils.getCurrentTransform)(ctx);
|
5945 | let cache, cacheKey, scaled, maskCanvas;
|
5946 | if ((img.bitmap || img.data) && img.count > 1) {
|
5947 | const mainKey = img.bitmap || img.data.buffer;
|
5948 | cacheKey = JSON.stringify(isPatternFill ? currentTransform : [currentTransform.slice(0, 4), fillColor]);
|
5949 | cache = this._cachedBitmapsMap.get(mainKey);
|
5950 | if (!cache) {
|
5951 | cache = new Map();
|
5952 | this._cachedBitmapsMap.set(mainKey, cache);
|
5953 | }
|
5954 | const cachedImage = cache.get(cacheKey);
|
5955 | if (cachedImage && !isPatternFill) {
|
5956 | const offsetX = Math.round(Math.min(currentTransform[0], currentTransform[2]) + currentTransform[4]);
|
5957 | const offsetY = Math.round(Math.min(currentTransform[1], currentTransform[3]) + currentTransform[5]);
|
5958 | return {
|
5959 | canvas: cachedImage,
|
5960 | offsetX,
|
5961 | offsetY
|
5962 | };
|
5963 | }
|
5964 | scaled = cachedImage;
|
5965 | }
|
5966 | if (!scaled) {
|
5967 | maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
|
5968 | putBinaryImageMask(maskCanvas.context, img);
|
5969 | }
|
5970 | let maskToCanvas = _util.Util.transform(currentTransform, [1 / width, 0, 0, -1 / height, 0, 0]);
|
5971 | maskToCanvas = _util.Util.transform(maskToCanvas, [1, 0, 0, 1, 0, -height]);
|
5972 | const cord1 = _util.Util.applyTransform([0, 0], maskToCanvas);
|
5973 | const cord2 = _util.Util.applyTransform([width, height], maskToCanvas);
|
5974 | const rect = _util.Util.normalizeRect([cord1[0], cord1[1], cord2[0], cord2[1]]);
|
5975 | const drawnWidth = Math.round(rect[2] - rect[0]) || 1;
|
5976 | const drawnHeight = Math.round(rect[3] - rect[1]) || 1;
|
5977 | const fillCanvas = this.cachedCanvases.getCanvas("fillCanvas", drawnWidth, drawnHeight);
|
5978 | const fillCtx = fillCanvas.context;
|
5979 | const offsetX = Math.min(cord1[0], cord2[0]);
|
5980 | const offsetY = Math.min(cord1[1], cord2[1]);
|
5981 | fillCtx.translate(-offsetX, -offsetY);
|
5982 | fillCtx.transform(...maskToCanvas);
|
5983 | if (!scaled) {
|
5984 | scaled = this._scaleImage(maskCanvas.canvas, (0, _display_utils.getCurrentTransformInverse)(fillCtx));
|
5985 | scaled = scaled.img;
|
5986 | if (cache && isPatternFill) {
|
5987 | cache.set(cacheKey, scaled);
|
5988 | }
|
5989 | }
|
5990 | fillCtx.imageSmoothingEnabled = getImageSmoothingEnabled((0, _display_utils.getCurrentTransform)(fillCtx), img.interpolate);
|
5991 | drawImageAtIntegerCoords(fillCtx, scaled, 0, 0, scaled.width, scaled.height, 0, 0, width, height);
|
5992 | fillCtx.globalCompositeOperation = "source-in";
|
5993 | const inverse = _util.Util.transform((0, _display_utils.getCurrentTransformInverse)(fillCtx), [1, 0, 0, 1, -offsetX, -offsetY]);
|
5994 | fillCtx.fillStyle = isPatternFill ? fillColor.getPattern(ctx, this, inverse, _pattern_helper.PathType.FILL) : fillColor;
|
5995 | fillCtx.fillRect(0, 0, width, height);
|
5996 | if (cache && !isPatternFill) {
|
5997 | this.cachedCanvases.delete("fillCanvas");
|
5998 | cache.set(cacheKey, fillCanvas.canvas);
|
5999 | }
|
6000 | return {
|
6001 | canvas: fillCanvas.canvas,
|
6002 | offsetX: Math.round(offsetX),
|
6003 | offsetY: Math.round(offsetY)
|
6004 | };
|
6005 | }
|
6006 | setLineWidth(width) {
|
6007 | if (width !== this.current.lineWidth) {
|
6008 | this._cachedScaleForStroking[0] = -1;
|
6009 | }
|
6010 | this.current.lineWidth = width;
|
6011 | this.ctx.lineWidth = width;
|
6012 | }
|
6013 | setLineCap(style) {
|
6014 | this.ctx.lineCap = LINE_CAP_STYLES[style];
|
6015 | }
|
6016 | setLineJoin(style) {
|
6017 | this.ctx.lineJoin = LINE_JOIN_STYLES[style];
|
6018 | }
|
6019 | setMiterLimit(limit) {
|
6020 | this.ctx.miterLimit = limit;
|
6021 | }
|
6022 | setDash(dashArray, dashPhase) {
|
6023 | const ctx = this.ctx;
|
6024 | if (ctx.setLineDash !== undefined) {
|
6025 | ctx.setLineDash(dashArray);
|
6026 | ctx.lineDashOffset = dashPhase;
|
6027 | }
|
6028 | }
|
6029 | setRenderingIntent(intent) {}
|
6030 | setFlatness(flatness) {}
|
6031 | setGState(states) {
|
6032 | for (const [key, value] of states) {
|
6033 | switch (key) {
|
6034 | case "LW":
|
6035 | this.setLineWidth(value);
|
6036 | break;
|
6037 | case "LC":
|
6038 | this.setLineCap(value);
|
6039 | break;
|
6040 | case "LJ":
|
6041 | this.setLineJoin(value);
|
6042 | break;
|
6043 | case "ML":
|
6044 | this.setMiterLimit(value);
|
6045 | break;
|
6046 | case "D":
|
6047 | this.setDash(value[0], value[1]);
|
6048 | break;
|
6049 | case "RI":
|
6050 | this.setRenderingIntent(value);
|
6051 | break;
|
6052 | case "FL":
|
6053 | this.setFlatness(value);
|
6054 | break;
|
6055 | case "Font":
|
6056 | this.setFont(value[0], value[1]);
|
6057 | break;
|
6058 | case "CA":
|
6059 | this.current.strokeAlpha = value;
|
6060 | break;
|
6061 | case "ca":
|
6062 | this.current.fillAlpha = value;
|
6063 | this.ctx.globalAlpha = value;
|
6064 | break;
|
6065 | case "BM":
|
6066 | this.ctx.globalCompositeOperation = value;
|
6067 | break;
|
6068 | case "SMask":
|
6069 | this.current.activeSMask = value ? this.tempSMask : null;
|
6070 | this.tempSMask = null;
|
6071 | this.checkSMaskState();
|
6072 | break;
|
6073 | case "TR":
|
6074 | this.ctx.filter = this.current.transferMaps = this.filterFactory.addFilter(value);
|
6075 | break;
|
6076 | }
|
6077 | }
|
6078 | }
|
6079 | get inSMaskMode() {
|
6080 | return !!this.suspendedCtx;
|
6081 | }
|
6082 | checkSMaskState() {
|
6083 | const inSMaskMode = this.inSMaskMode;
|
6084 | if (this.current.activeSMask && !inSMaskMode) {
|
6085 | this.beginSMaskMode();
|
6086 | } else if (!this.current.activeSMask && inSMaskMode) {
|
6087 | this.endSMaskMode();
|
6088 | }
|
6089 | }
|
6090 | beginSMaskMode() {
|
6091 | if (this.inSMaskMode) {
|
6092 | throw new Error("beginSMaskMode called while already in smask mode");
|
6093 | }
|
6094 | const drawnWidth = this.ctx.canvas.width;
|
6095 | const drawnHeight = this.ctx.canvas.height;
|
6096 | const cacheId = "smaskGroupAt" + this.groupLevel;
|
6097 | const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight);
|
6098 | this.suspendedCtx = this.ctx;
|
6099 | this.ctx = scratchCanvas.context;
|
6100 | const ctx = this.ctx;
|
6101 | ctx.setTransform(...(0, _display_utils.getCurrentTransform)(this.suspendedCtx));
|
6102 | copyCtxState(this.suspendedCtx, ctx);
|
6103 | mirrorContextOperations(ctx, this.suspendedCtx);
|
6104 | this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
|
6105 | }
|
6106 | endSMaskMode() {
|
6107 | if (!this.inSMaskMode) {
|
6108 | throw new Error("endSMaskMode called while not in smask mode");
|
6109 | }
|
6110 | this.ctx._removeMirroring();
|
6111 | copyCtxState(this.ctx, this.suspendedCtx);
|
6112 | this.ctx = this.suspendedCtx;
|
6113 | this.suspendedCtx = null;
|
6114 | }
|
6115 | compose(dirtyBox) {
|
6116 | if (!this.current.activeSMask) {
|
6117 | return;
|
6118 | }
|
6119 | if (!dirtyBox) {
|
6120 | dirtyBox = [0, 0, this.ctx.canvas.width, this.ctx.canvas.height];
|
6121 | } else {
|
6122 | dirtyBox[0] = Math.floor(dirtyBox[0]);
|
6123 | dirtyBox[1] = Math.floor(dirtyBox[1]);
|
6124 | dirtyBox[2] = Math.ceil(dirtyBox[2]);
|
6125 | dirtyBox[3] = Math.ceil(dirtyBox[3]);
|
6126 | }
|
6127 | const smask = this.current.activeSMask;
|
6128 | const suspendedCtx = this.suspendedCtx;
|
6129 | composeSMask(suspendedCtx, smask, this.ctx, dirtyBox);
|
6130 | this.ctx.save();
|
6131 | this.ctx.setTransform(1, 0, 0, 1, 0, 0);
|
6132 | this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
|
6133 | this.ctx.restore();
|
6134 | }
|
6135 | save() {
|
6136 | if (this.inSMaskMode) {
|
6137 | copyCtxState(this.ctx, this.suspendedCtx);
|
6138 | this.suspendedCtx.save();
|
6139 | } else {
|
6140 | this.ctx.save();
|
6141 | }
|
6142 | const old = this.current;
|
6143 | this.stateStack.push(old);
|
6144 | this.current = old.clone();
|
6145 | }
|
6146 | restore() {
|
6147 | if (this.stateStack.length === 0 && this.inSMaskMode) {
|
6148 | this.endSMaskMode();
|
6149 | }
|
6150 | if (this.stateStack.length !== 0) {
|
6151 | this.current = this.stateStack.pop();
|
6152 | if (this.inSMaskMode) {
|
6153 | this.suspendedCtx.restore();
|
6154 | copyCtxState(this.suspendedCtx, this.ctx);
|
6155 | } else {
|
6156 | this.ctx.restore();
|
6157 | }
|
6158 | this.checkSMaskState();
|
6159 | this.pendingClip = null;
|
6160 | this._cachedScaleForStroking[0] = -1;
|
6161 | this._cachedGetSinglePixelWidth = null;
|
6162 | }
|
6163 | }
|
6164 | transform(a, b, c, d, e, f) {
|
6165 | this.ctx.transform(a, b, c, d, e, f);
|
6166 | this._cachedScaleForStroking[0] = -1;
|
6167 | this._cachedGetSinglePixelWidth = null;
|
6168 | }
|
6169 | constructPath(ops, args, minMax) {
|
6170 | const ctx = this.ctx;
|
6171 | const current = this.current;
|
6172 | let x = current.x,
|
6173 | y = current.y;
|
6174 | let startX, startY;
|
6175 | const currentTransform = (0, _display_utils.getCurrentTransform)(ctx);
|
6176 | const isScalingMatrix = currentTransform[0] === 0 && currentTransform[3] === 0 || currentTransform[1] === 0 && currentTransform[2] === 0;
|
6177 | const minMaxForBezier = isScalingMatrix ? minMax.slice(0) : null;
|
6178 | for (let i = 0, j = 0, ii = ops.length; i < ii; i++) {
|
6179 | switch (ops[i] | 0) {
|
6180 | case _util.OPS.rectangle:
|
6181 | x = args[j++];
|
6182 | y = args[j++];
|
6183 | const width = args[j++];
|
6184 | const height = args[j++];
|
6185 | const xw = x + width;
|
6186 | const yh = y + height;
|
6187 | ctx.moveTo(x, y);
|
6188 | if (width === 0 || height === 0) {
|
6189 | ctx.lineTo(xw, yh);
|
6190 | } else {
|
6191 | ctx.lineTo(xw, y);
|
6192 | ctx.lineTo(xw, yh);
|
6193 | ctx.lineTo(x, yh);
|
6194 | }
|
6195 | if (!isScalingMatrix) {
|
6196 | current.updateRectMinMax(currentTransform, [x, y, xw, yh]);
|
6197 | }
|
6198 | ctx.closePath();
|
6199 | break;
|
6200 | case _util.OPS.moveTo:
|
6201 | x = args[j++];
|
6202 | y = args[j++];
|
6203 | ctx.moveTo(x, y);
|
6204 | if (!isScalingMatrix) {
|
6205 | current.updatePathMinMax(currentTransform, x, y);
|
6206 | }
|
6207 | break;
|
6208 | case _util.OPS.lineTo:
|
6209 | x = args[j++];
|
6210 | y = args[j++];
|
6211 | ctx.lineTo(x, y);
|
6212 | if (!isScalingMatrix) {
|
6213 | current.updatePathMinMax(currentTransform, x, y);
|
6214 | }
|
6215 | break;
|
6216 | case _util.OPS.curveTo:
|
6217 | startX = x;
|
6218 | startY = y;
|
6219 | x = args[j + 4];
|
6220 | y = args[j + 5];
|
6221 | ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
|
6222 | current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], args[j + 2], args[j + 3], x, y, minMaxForBezier);
|
6223 | j += 6;
|
6224 | break;
|
6225 | case _util.OPS.curveTo2:
|
6226 | startX = x;
|
6227 | startY = y;
|
6228 | ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
|
6229 | current.updateCurvePathMinMax(currentTransform, startX, startY, x, y, args[j], args[j + 1], args[j + 2], args[j + 3], minMaxForBezier);
|
6230 | x = args[j + 2];
|
6231 | y = args[j + 3];
|
6232 | j += 4;
|
6233 | break;
|
6234 | case _util.OPS.curveTo3:
|
6235 | startX = x;
|
6236 | startY = y;
|
6237 | x = args[j + 2];
|
6238 | y = args[j + 3];
|
6239 | ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
|
6240 | current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], x, y, x, y, minMaxForBezier);
|
6241 | j += 4;
|
6242 | break;
|
6243 | case _util.OPS.closePath:
|
6244 | ctx.closePath();
|
6245 | break;
|
6246 | }
|
6247 | }
|
6248 | if (isScalingMatrix) {
|
6249 | current.updateScalingPathMinMax(currentTransform, minMaxForBezier);
|
6250 | }
|
6251 | current.setCurrentPoint(x, y);
|
6252 | }
|
6253 | closePath() {
|
6254 | this.ctx.closePath();
|
6255 | }
|
6256 | stroke(consumePath = true) {
|
6257 | const ctx = this.ctx;
|
6258 | const strokeColor = this.current.strokeColor;
|
6259 | ctx.globalAlpha = this.current.strokeAlpha;
|
6260 | if (this.contentVisible) {
|
6261 | if (typeof strokeColor === "object" && strokeColor?.getPattern) {
|
6262 | ctx.save();
|
6263 | ctx.strokeStyle = strokeColor.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.STROKE);
|
6264 | this.rescaleAndStroke(false);
|
6265 | ctx.restore();
|
6266 | } else {
|
6267 | this.rescaleAndStroke(true);
|
6268 | }
|
6269 | }
|
6270 | if (consumePath) {
|
6271 | this.consumePath(this.current.getClippedPathBoundingBox());
|
6272 | }
|
6273 | ctx.globalAlpha = this.current.fillAlpha;
|
6274 | }
|
6275 | closeStroke() {
|
6276 | this.closePath();
|
6277 | this.stroke();
|
6278 | }
|
6279 | fill(consumePath = true) {
|
6280 | const ctx = this.ctx;
|
6281 | const fillColor = this.current.fillColor;
|
6282 | const isPatternFill = this.current.patternFill;
|
6283 | let needRestore = false;
|
6284 | if (isPatternFill) {
|
6285 | ctx.save();
|
6286 | ctx.fillStyle = fillColor.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.FILL);
|
6287 | needRestore = true;
|
6288 | }
|
6289 | const intersect = this.current.getClippedPathBoundingBox();
|
6290 | if (this.contentVisible && intersect !== null) {
|
6291 | if (this.pendingEOFill) {
|
6292 | ctx.fill("evenodd");
|
6293 | this.pendingEOFill = false;
|
6294 | } else {
|
6295 | ctx.fill();
|
6296 | }
|
6297 | }
|
6298 | if (needRestore) {
|
6299 | ctx.restore();
|
6300 | }
|
6301 | if (consumePath) {
|
6302 | this.consumePath(intersect);
|
6303 | }
|
6304 | }
|
6305 | eoFill() {
|
6306 | this.pendingEOFill = true;
|
6307 | this.fill();
|
6308 | }
|
6309 | fillStroke() {
|
6310 | this.fill(false);
|
6311 | this.stroke(false);
|
6312 | this.consumePath();
|
6313 | }
|
6314 | eoFillStroke() {
|
6315 | this.pendingEOFill = true;
|
6316 | this.fillStroke();
|
6317 | }
|
6318 | closeFillStroke() {
|
6319 | this.closePath();
|
6320 | this.fillStroke();
|
6321 | }
|
6322 | closeEOFillStroke() {
|
6323 | this.pendingEOFill = true;
|
6324 | this.closePath();
|
6325 | this.fillStroke();
|
6326 | }
|
6327 | endPath() {
|
6328 | this.consumePath();
|
6329 | }
|
6330 | clip() {
|
6331 | this.pendingClip = NORMAL_CLIP;
|
6332 | }
|
6333 | eoClip() {
|
6334 | this.pendingClip = EO_CLIP;
|
6335 | }
|
6336 | beginText() {
|
6337 | this.current.textMatrix = _util.IDENTITY_MATRIX;
|
6338 | this.current.textMatrixScale = 1;
|
6339 | this.current.x = this.current.lineX = 0;
|
6340 | this.current.y = this.current.lineY = 0;
|
6341 | }
|
6342 | endText() {
|
6343 | const paths = this.pendingTextPaths;
|
6344 | const ctx = this.ctx;
|
6345 | if (paths === undefined) {
|
6346 | ctx.beginPath();
|
6347 | return;
|
6348 | }
|
6349 | ctx.save();
|
6350 | ctx.beginPath();
|
6351 | for (const path of paths) {
|
6352 | ctx.setTransform(...path.transform);
|
6353 | ctx.translate(path.x, path.y);
|
6354 | path.addToPath(ctx, path.fontSize);
|
6355 | }
|
6356 | ctx.restore();
|
6357 | ctx.clip();
|
6358 | ctx.beginPath();
|
6359 | delete this.pendingTextPaths;
|
6360 | }
|
6361 | setCharSpacing(spacing) {
|
6362 | this.current.charSpacing = spacing;
|
6363 | }
|
6364 | setWordSpacing(spacing) {
|
6365 | this.current.wordSpacing = spacing;
|
6366 | }
|
6367 | setHScale(scale) {
|
6368 | this.current.textHScale = scale / 100;
|
6369 | }
|
6370 | setLeading(leading) {
|
6371 | this.current.leading = -leading;
|
6372 | }
|
6373 | setFont(fontRefName, size) {
|
6374 | const fontObj = this.commonObjs.get(fontRefName);
|
6375 | const current = this.current;
|
6376 | if (!fontObj) {
|
6377 | throw new Error(`Can't find font for ${fontRefName}`);
|
6378 | }
|
6379 | current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
|
6380 | if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
|
6381 | (0, _util.warn)("Invalid font matrix for font " + fontRefName);
|
6382 | }
|
6383 | if (size < 0) {
|
6384 | size = -size;
|
6385 | current.fontDirection = -1;
|
6386 | } else {
|
6387 | current.fontDirection = 1;
|
6388 | }
|
6389 | this.current.font = fontObj;
|
6390 | this.current.fontSize = size;
|
6391 | if (fontObj.isType3Font) {
|
6392 | return;
|
6393 | }
|
6394 | const name = fontObj.loadedName || "sans-serif";
|
6395 | const typeface = fontObj.systemFontInfo?.css || `"${name}", ${fontObj.fallbackName}`;
|
6396 | let bold = "normal";
|
6397 | if (fontObj.black) {
|
6398 | bold = "900";
|
6399 | } else if (fontObj.bold) {
|
6400 | bold = "bold";
|
6401 | }
|
6402 | const italic = fontObj.italic ? "italic" : "normal";
|
6403 | let browserFontSize = size;
|
6404 | if (size < MIN_FONT_SIZE) {
|
6405 | browserFontSize = MIN_FONT_SIZE;
|
6406 | } else if (size > MAX_FONT_SIZE) {
|
6407 | browserFontSize = MAX_FONT_SIZE;
|
6408 | }
|
6409 | this.current.fontSizeScale = size / browserFontSize;
|
6410 | this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
|
6411 | }
|
6412 | setTextRenderingMode(mode) {
|
6413 | this.current.textRenderingMode = mode;
|
6414 | }
|
6415 | setTextRise(rise) {
|
6416 | this.current.textRise = rise;
|
6417 | }
|
6418 | moveText(x, y) {
|
6419 | this.current.x = this.current.lineX += x;
|
6420 | this.current.y = this.current.lineY += y;
|
6421 | }
|
6422 | setLeadingMoveText(x, y) {
|
6423 | this.setLeading(-y);
|
6424 | this.moveText(x, y);
|
6425 | }
|
6426 | setTextMatrix(a, b, c, d, e, f) {
|
6427 | this.current.textMatrix = [a, b, c, d, e, f];
|
6428 | this.current.textMatrixScale = Math.hypot(a, b);
|
6429 | this.current.x = this.current.lineX = 0;
|
6430 | this.current.y = this.current.lineY = 0;
|
6431 | }
|
6432 | nextLine() {
|
6433 | this.moveText(0, this.current.leading);
|
6434 | }
|
6435 | paintChar(character, x, y, patternTransform) {
|
6436 | const ctx = this.ctx;
|
6437 | const current = this.current;
|
6438 | const font = current.font;
|
6439 | const textRenderingMode = current.textRenderingMode;
|
6440 | const fontSize = current.fontSize / current.fontSizeScale;
|
6441 | const fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
|
6442 | const isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
|
6443 | const patternFill = current.patternFill && !font.missingFile;
|
6444 | let addToPath;
|
6445 | if (font.disableFontFace || isAddToPathSet || patternFill) {
|
6446 | addToPath = font.getPathGenerator(this.commonObjs, character);
|
6447 | }
|
6448 | if (font.disableFontFace || patternFill) {
|
6449 | ctx.save();
|
6450 | ctx.translate(x, y);
|
6451 | ctx.beginPath();
|
6452 | addToPath(ctx, fontSize);
|
6453 | if (patternTransform) {
|
6454 | ctx.setTransform(...patternTransform);
|
6455 | }
|
6456 | if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
6457 | ctx.fill();
|
6458 | }
|
6459 | if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
6460 | ctx.stroke();
|
6461 | }
|
6462 | ctx.restore();
|
6463 | } else {
|
6464 | if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
6465 | ctx.fillText(character, x, y);
|
6466 | }
|
6467 | if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
6468 | ctx.strokeText(character, x, y);
|
6469 | }
|
6470 | }
|
6471 | if (isAddToPathSet) {
|
6472 | const paths = this.pendingTextPaths ||= [];
|
6473 | paths.push({
|
6474 | transform: (0, _display_utils.getCurrentTransform)(ctx),
|
6475 | x,
|
6476 | y,
|
6477 | fontSize,
|
6478 | addToPath
|
6479 | });
|
6480 | }
|
6481 | }
|
6482 | get isFontSubpixelAAEnabled() {
|
6483 | const {
|
6484 | context: ctx
|
6485 | } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
|
6486 | ctx.scale(1.5, 1);
|
6487 | ctx.fillText("I", 0, 10);
|
6488 | const data = ctx.getImageData(0, 0, 10, 10).data;
|
6489 | let enabled = false;
|
6490 | for (let i = 3; i < data.length; i += 4) {
|
6491 | if (data[i] > 0 && data[i] < 255) {
|
6492 | enabled = true;
|
6493 | break;
|
6494 | }
|
6495 | }
|
6496 | return (0, _util.shadow)(this, "isFontSubpixelAAEnabled", enabled);
|
6497 | }
|
6498 | showText(glyphs) {
|
6499 | const current = this.current;
|
6500 | const font = current.font;
|
6501 | if (font.isType3Font) {
|
6502 | return this.showType3Text(glyphs);
|
6503 | }
|
6504 | const fontSize = current.fontSize;
|
6505 | if (fontSize === 0) {
|
6506 | return undefined;
|
6507 | }
|
6508 | const ctx = this.ctx;
|
6509 | const fontSizeScale = current.fontSizeScale;
|
6510 | const charSpacing = current.charSpacing;
|
6511 | const wordSpacing = current.wordSpacing;
|
6512 | const fontDirection = current.fontDirection;
|
6513 | const textHScale = current.textHScale * fontDirection;
|
6514 | const glyphsLength = glyphs.length;
|
6515 | const vertical = font.vertical;
|
6516 | const spacingDir = vertical ? 1 : -1;
|
6517 | const defaultVMetrics = font.defaultVMetrics;
|
6518 | const widthAdvanceScale = fontSize * current.fontMatrix[0];
|
6519 | const simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
|
6520 | ctx.save();
|
6521 | ctx.transform(...current.textMatrix);
|
6522 | ctx.translate(current.x, current.y + current.textRise);
|
6523 | if (fontDirection > 0) {
|
6524 | ctx.scale(textHScale, -1);
|
6525 | } else {
|
6526 | ctx.scale(textHScale, 1);
|
6527 | }
|
6528 | let patternTransform;
|
6529 | if (current.patternFill) {
|
6530 | ctx.save();
|
6531 | const pattern = current.fillColor.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.FILL);
|
6532 | patternTransform = (0, _display_utils.getCurrentTransform)(ctx);
|
6533 | ctx.restore();
|
6534 | ctx.fillStyle = pattern;
|
6535 | }
|
6536 | let lineWidth = current.lineWidth;
|
6537 | const scale = current.textMatrixScale;
|
6538 | if (scale === 0 || lineWidth === 0) {
|
6539 | const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
|
6540 | if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
6541 | lineWidth = this.getSinglePixelWidth();
|
6542 | }
|
6543 | } else {
|
6544 | lineWidth /= scale;
|
6545 | }
|
6546 | if (fontSizeScale !== 1.0) {
|
6547 | ctx.scale(fontSizeScale, fontSizeScale);
|
6548 | lineWidth /= fontSizeScale;
|
6549 | }
|
6550 | ctx.lineWidth = lineWidth;
|
6551 | if (font.isInvalidPDFjsFont) {
|
6552 | const chars = [];
|
6553 | let width = 0;
|
6554 | for (const glyph of glyphs) {
|
6555 | chars.push(glyph.unicode);
|
6556 | width += glyph.width;
|
6557 | }
|
6558 | ctx.fillText(chars.join(""), 0, 0);
|
6559 | current.x += width * widthAdvanceScale * textHScale;
|
6560 | ctx.restore();
|
6561 | this.compose();
|
6562 | return undefined;
|
6563 | }
|
6564 | let x = 0,
|
6565 | i;
|
6566 | for (i = 0; i < glyphsLength; ++i) {
|
6567 | const glyph = glyphs[i];
|
6568 | if (typeof glyph === "number") {
|
6569 | x += spacingDir * glyph * fontSize / 1000;
|
6570 | continue;
|
6571 | }
|
6572 | let restoreNeeded = false;
|
6573 | const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
|
6574 | const character = glyph.fontChar;
|
6575 | const accent = glyph.accent;
|
6576 | let scaledX, scaledY;
|
6577 | let width = glyph.width;
|
6578 | if (vertical) {
|
6579 | const vmetric = glyph.vmetric || defaultVMetrics;
|
6580 | const vx = -(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale;
|
6581 | const vy = vmetric[2] * widthAdvanceScale;
|
6582 | width = vmetric ? -vmetric[0] : width;
|
6583 | scaledX = vx / fontSizeScale;
|
6584 | scaledY = (x + vy) / fontSizeScale;
|
6585 | } else {
|
6586 | scaledX = x / fontSizeScale;
|
6587 | scaledY = 0;
|
6588 | }
|
6589 | if (font.remeasure && width > 0) {
|
6590 | const measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
|
6591 | if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
|
6592 | const characterScaleX = width / measuredWidth;
|
6593 | restoreNeeded = true;
|
6594 | ctx.save();
|
6595 | ctx.scale(characterScaleX, 1);
|
6596 | scaledX /= characterScaleX;
|
6597 | } else if (width !== measuredWidth) {
|
6598 | scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
|
6599 | }
|
6600 | }
|
6601 | if (this.contentVisible && (glyph.isInFont || font.missingFile)) {
|
6602 | if (simpleFillText && !accent) {
|
6603 | ctx.fillText(character, scaledX, scaledY);
|
6604 | } else {
|
6605 | this.paintChar(character, scaledX, scaledY, patternTransform);
|
6606 | if (accent) {
|
6607 | const scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
|
6608 | const scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
|
6609 | this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform);
|
6610 | }
|
6611 | }
|
6612 | }
|
6613 | let charWidth;
|
6614 | if (vertical) {
|
6615 | charWidth = width * widthAdvanceScale - spacing * fontDirection;
|
6616 | } else {
|
6617 | charWidth = width * widthAdvanceScale + spacing * fontDirection;
|
6618 | }
|
6619 | x += charWidth;
|
6620 | if (restoreNeeded) {
|
6621 | ctx.restore();
|
6622 | }
|
6623 | }
|
6624 | if (vertical) {
|
6625 | current.y -= x;
|
6626 | } else {
|
6627 | current.x += x * textHScale;
|
6628 | }
|
6629 | ctx.restore();
|
6630 | this.compose();
|
6631 | return undefined;
|
6632 | }
|
6633 | showType3Text(glyphs) {
|
6634 | const ctx = this.ctx;
|
6635 | const current = this.current;
|
6636 | const font = current.font;
|
6637 | const fontSize = current.fontSize;
|
6638 | const fontDirection = current.fontDirection;
|
6639 | const spacingDir = font.vertical ? 1 : -1;
|
6640 | const charSpacing = current.charSpacing;
|
6641 | const wordSpacing = current.wordSpacing;
|
6642 | const textHScale = current.textHScale * fontDirection;
|
6643 | const fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
|
6644 | const glyphsLength = glyphs.length;
|
6645 | const isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
|
6646 | let i, glyph, width, spacingLength;
|
6647 | if (isTextInvisible || fontSize === 0) {
|
6648 | return;
|
6649 | }
|
6650 | this._cachedScaleForStroking[0] = -1;
|
6651 | this._cachedGetSinglePixelWidth = null;
|
6652 | ctx.save();
|
6653 | ctx.transform(...current.textMatrix);
|
6654 | ctx.translate(current.x, current.y);
|
6655 | ctx.scale(textHScale, fontDirection);
|
6656 | for (i = 0; i < glyphsLength; ++i) {
|
6657 | glyph = glyphs[i];
|
6658 | if (typeof glyph === "number") {
|
6659 | spacingLength = spacingDir * glyph * fontSize / 1000;
|
6660 | this.ctx.translate(spacingLength, 0);
|
6661 | current.x += spacingLength * textHScale;
|
6662 | continue;
|
6663 | }
|
6664 | const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
|
6665 | const operatorList = font.charProcOperatorList[glyph.operatorListId];
|
6666 | if (!operatorList) {
|
6667 | (0, _util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
|
6668 | continue;
|
6669 | }
|
6670 | if (this.contentVisible) {
|
6671 | this.processingType3 = glyph;
|
6672 | this.save();
|
6673 | ctx.scale(fontSize, fontSize);
|
6674 | ctx.transform(...fontMatrix);
|
6675 | this.executeOperatorList(operatorList);
|
6676 | this.restore();
|
6677 | }
|
6678 | const transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
|
6679 | width = transformed[0] * fontSize + spacing;
|
6680 | ctx.translate(width, 0);
|
6681 | current.x += width * textHScale;
|
6682 | }
|
6683 | ctx.restore();
|
6684 | this.processingType3 = null;
|
6685 | }
|
6686 | setCharWidth(xWidth, yWidth) {}
|
6687 | setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
|
6688 | this.ctx.rect(llx, lly, urx - llx, ury - lly);
|
6689 | this.ctx.clip();
|
6690 | this.endPath();
|
6691 | }
|
6692 | getColorN_Pattern(IR) {
|
6693 | let pattern;
|
6694 | if (IR[0] === "TilingPattern") {
|
6695 | const color = IR[1];
|
6696 | const baseTransform = this.baseTransform || (0, _display_utils.getCurrentTransform)(this.ctx);
|
6697 | const canvasGraphicsFactory = {
|
6698 | createCanvasGraphics: ctx => {
|
6699 | return new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory, this.filterFactory, {
|
6700 | optionalContentConfig: this.optionalContentConfig,
|
6701 | markedContentStack: this.markedContentStack
|
6702 | });
|
6703 | }
|
6704 | };
|
6705 | pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
|
6706 | } else {
|
6707 | pattern = this._getPattern(IR[1], IR[2]);
|
6708 | }
|
6709 | return pattern;
|
6710 | }
|
6711 | setStrokeColorN() {
|
6712 | this.current.strokeColor = this.getColorN_Pattern(arguments);
|
6713 | }
|
6714 | setFillColorN() {
|
6715 | this.current.fillColor = this.getColorN_Pattern(arguments);
|
6716 | this.current.patternFill = true;
|
6717 | }
|
6718 | setStrokeRGBColor(r, g, b) {
|
6719 | const color = _util.Util.makeHexColor(r, g, b);
|
6720 | this.ctx.strokeStyle = color;
|
6721 | this.current.strokeColor = color;
|
6722 | }
|
6723 | setFillRGBColor(r, g, b) {
|
6724 | const color = _util.Util.makeHexColor(r, g, b);
|
6725 | this.ctx.fillStyle = color;
|
6726 | this.current.fillColor = color;
|
6727 | this.current.patternFill = false;
|
6728 | }
|
6729 | _getPattern(objId, matrix = null) {
|
6730 | let pattern;
|
6731 | if (this.cachedPatterns.has(objId)) {
|
6732 | pattern = this.cachedPatterns.get(objId);
|
6733 | } else {
|
6734 | pattern = (0, _pattern_helper.getShadingPattern)(this.getObject(objId));
|
6735 | this.cachedPatterns.set(objId, pattern);
|
6736 | }
|
6737 | if (matrix) {
|
6738 | pattern.matrix = matrix;
|
6739 | }
|
6740 | return pattern;
|
6741 | }
|
6742 | shadingFill(objId) {
|
6743 | if (!this.contentVisible) {
|
6744 | return;
|
6745 | }
|
6746 | const ctx = this.ctx;
|
6747 | this.save();
|
6748 | const pattern = this._getPattern(objId);
|
6749 | ctx.fillStyle = pattern.getPattern(ctx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.SHADING);
|
6750 | const inv = (0, _display_utils.getCurrentTransformInverse)(ctx);
|
6751 | if (inv) {
|
6752 | const canvas = ctx.canvas;
|
6753 | const width = canvas.width;
|
6754 | const height = canvas.height;
|
6755 | const bl = _util.Util.applyTransform([0, 0], inv);
|
6756 | const br = _util.Util.applyTransform([0, height], inv);
|
6757 | const ul = _util.Util.applyTransform([width, 0], inv);
|
6758 | const ur = _util.Util.applyTransform([width, height], inv);
|
6759 | const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
|
6760 | const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
|
6761 | const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
|
6762 | const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
|
6763 | this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
|
6764 | } else {
|
6765 | this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
|
6766 | }
|
6767 | this.compose(this.current.getClippedPathBoundingBox());
|
6768 | this.restore();
|
6769 | }
|
6770 | beginInlineImage() {
|
6771 | (0, _util.unreachable)("Should not call beginInlineImage");
|
6772 | }
|
6773 | beginImageData() {
|
6774 | (0, _util.unreachable)("Should not call beginImageData");
|
6775 | }
|
6776 | paintFormXObjectBegin(matrix, bbox) {
|
6777 | if (!this.contentVisible) {
|
6778 | return;
|
6779 | }
|
6780 | this.save();
|
6781 | this.baseTransformStack.push(this.baseTransform);
|
6782 | if (Array.isArray(matrix) && matrix.length === 6) {
|
6783 | this.transform(...matrix);
|
6784 | }
|
6785 | this.baseTransform = (0, _display_utils.getCurrentTransform)(this.ctx);
|
6786 | if (bbox) {
|
6787 | const width = bbox[2] - bbox[0];
|
6788 | const height = bbox[3] - bbox[1];
|
6789 | this.ctx.rect(bbox[0], bbox[1], width, height);
|
6790 | this.current.updateRectMinMax((0, _display_utils.getCurrentTransform)(this.ctx), bbox);
|
6791 | this.clip();
|
6792 | this.endPath();
|
6793 | }
|
6794 | }
|
6795 | paintFormXObjectEnd() {
|
6796 | if (!this.contentVisible) {
|
6797 | return;
|
6798 | }
|
6799 | this.restore();
|
6800 | this.baseTransform = this.baseTransformStack.pop();
|
6801 | }
|
6802 | beginGroup(group) {
|
6803 | if (!this.contentVisible) {
|
6804 | return;
|
6805 | }
|
6806 | this.save();
|
6807 | if (this.inSMaskMode) {
|
6808 | this.endSMaskMode();
|
6809 | this.current.activeSMask = null;
|
6810 | }
|
6811 | const currentCtx = this.ctx;
|
6812 | if (!group.isolated) {
|
6813 | (0, _util.info)("TODO: Support non-isolated groups.");
|
6814 | }
|
6815 | if (group.knockout) {
|
6816 | (0, _util.warn)("Knockout groups not supported.");
|
6817 | }
|
6818 | const currentTransform = (0, _display_utils.getCurrentTransform)(currentCtx);
|
6819 | if (group.matrix) {
|
6820 | currentCtx.transform(...group.matrix);
|
6821 | }
|
6822 | if (!group.bbox) {
|
6823 | throw new Error("Bounding box is required.");
|
6824 | }
|
6825 | let bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, (0, _display_utils.getCurrentTransform)(currentCtx));
|
6826 | const canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
|
6827 | bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
|
6828 | const offsetX = Math.floor(bounds[0]);
|
6829 | const offsetY = Math.floor(bounds[1]);
|
6830 | let drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
|
6831 | let drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
|
6832 | let scaleX = 1,
|
6833 | scaleY = 1;
|
6834 | if (drawnWidth > MAX_GROUP_SIZE) {
|
6835 | scaleX = drawnWidth / MAX_GROUP_SIZE;
|
6836 | drawnWidth = MAX_GROUP_SIZE;
|
6837 | }
|
6838 | if (drawnHeight > MAX_GROUP_SIZE) {
|
6839 | scaleY = drawnHeight / MAX_GROUP_SIZE;
|
6840 | drawnHeight = MAX_GROUP_SIZE;
|
6841 | }
|
6842 | this.current.startNewPathAndClipBox([0, 0, drawnWidth, drawnHeight]);
|
6843 | let cacheId = "groupAt" + this.groupLevel;
|
6844 | if (group.smask) {
|
6845 | cacheId += "_smask_" + this.smaskCounter++ % 2;
|
6846 | }
|
6847 | const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight);
|
6848 | const groupCtx = scratchCanvas.context;
|
6849 | groupCtx.scale(1 / scaleX, 1 / scaleY);
|
6850 | groupCtx.translate(-offsetX, -offsetY);
|
6851 | groupCtx.transform(...currentTransform);
|
6852 | if (group.smask) {
|
6853 | this.smaskStack.push({
|
6854 | canvas: scratchCanvas.canvas,
|
6855 | context: groupCtx,
|
6856 | offsetX,
|
6857 | offsetY,
|
6858 | scaleX,
|
6859 | scaleY,
|
6860 | subtype: group.smask.subtype,
|
6861 | backdrop: group.smask.backdrop,
|
6862 | transferMap: group.smask.transferMap || null,
|
6863 | startTransformInverse: null
|
6864 | });
|
6865 | } else {
|
6866 | currentCtx.setTransform(1, 0, 0, 1, 0, 0);
|
6867 | currentCtx.translate(offsetX, offsetY);
|
6868 | currentCtx.scale(scaleX, scaleY);
|
6869 | currentCtx.save();
|
6870 | }
|
6871 | copyCtxState(currentCtx, groupCtx);
|
6872 | this.ctx = groupCtx;
|
6873 | this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
|
6874 | this.groupStack.push(currentCtx);
|
6875 | this.groupLevel++;
|
6876 | }
|
6877 | endGroup(group) {
|
6878 | if (!this.contentVisible) {
|
6879 | return;
|
6880 | }
|
6881 | this.groupLevel--;
|
6882 | const groupCtx = this.ctx;
|
6883 | const ctx = this.groupStack.pop();
|
6884 | this.ctx = ctx;
|
6885 | this.ctx.imageSmoothingEnabled = false;
|
6886 | if (group.smask) {
|
6887 | this.tempSMask = this.smaskStack.pop();
|
6888 | this.restore();
|
6889 | } else {
|
6890 | this.ctx.restore();
|
6891 | const currentMtx = (0, _display_utils.getCurrentTransform)(this.ctx);
|
6892 | this.restore();
|
6893 | this.ctx.save();
|
6894 | this.ctx.setTransform(...currentMtx);
|
6895 | const dirtyBox = _util.Util.getAxialAlignedBoundingBox([0, 0, groupCtx.canvas.width, groupCtx.canvas.height], currentMtx);
|
6896 | this.ctx.drawImage(groupCtx.canvas, 0, 0);
|
6897 | this.ctx.restore();
|
6898 | this.compose(dirtyBox);
|
6899 | }
|
6900 | }
|
6901 | beginAnnotation(id, rect, transform, matrix, hasOwnCanvas) {
|
6902 | this.#restoreInitialState();
|
6903 | resetCtxToDefault(this.ctx);
|
6904 | this.ctx.save();
|
6905 | this.save();
|
6906 | if (this.baseTransform) {
|
6907 | this.ctx.setTransform(...this.baseTransform);
|
6908 | }
|
6909 | if (Array.isArray(rect) && rect.length === 4) {
|
6910 | const width = rect[2] - rect[0];
|
6911 | const height = rect[3] - rect[1];
|
6912 | if (hasOwnCanvas && this.annotationCanvasMap) {
|
6913 | transform = transform.slice();
|
6914 | transform[4] -= rect[0];
|
6915 | transform[5] -= rect[1];
|
6916 | rect = rect.slice();
|
6917 | rect[0] = rect[1] = 0;
|
6918 | rect[2] = width;
|
6919 | rect[3] = height;
|
6920 | const [scaleX, scaleY] = _util.Util.singularValueDecompose2dScale((0, _display_utils.getCurrentTransform)(this.ctx));
|
6921 | const {
|
6922 | viewportScale
|
6923 | } = this;
|
6924 | const canvasWidth = Math.ceil(width * this.outputScaleX * viewportScale);
|
6925 | const canvasHeight = Math.ceil(height * this.outputScaleY * viewportScale);
|
6926 | this.annotationCanvas = this.canvasFactory.create(canvasWidth, canvasHeight);
|
6927 | const {
|
6928 | canvas,
|
6929 | context
|
6930 | } = this.annotationCanvas;
|
6931 | this.annotationCanvasMap.set(id, canvas);
|
6932 | this.annotationCanvas.savedCtx = this.ctx;
|
6933 | this.ctx = context;
|
6934 | this.ctx.save();
|
6935 | this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);
|
6936 | resetCtxToDefault(this.ctx);
|
6937 | } else {
|
6938 | resetCtxToDefault(this.ctx);
|
6939 | this.ctx.rect(rect[0], rect[1], width, height);
|
6940 | this.ctx.clip();
|
6941 | this.endPath();
|
6942 | }
|
6943 | }
|
6944 | this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
|
6945 | this.transform(...transform);
|
6946 | this.transform(...matrix);
|
6947 | }
|
6948 | endAnnotation() {
|
6949 | if (this.annotationCanvas) {
|
6950 | this.ctx.restore();
|
6951 | this.#drawFilter();
|
6952 | this.ctx = this.annotationCanvas.savedCtx;
|
6953 | delete this.annotationCanvas.savedCtx;
|
6954 | delete this.annotationCanvas;
|
6955 | }
|
6956 | }
|
6957 | paintImageMaskXObject(img) {
|
6958 | if (!this.contentVisible) {
|
6959 | return;
|
6960 | }
|
6961 | const count = img.count;
|
6962 | img = this.getObject(img.data, img);
|
6963 | img.count = count;
|
6964 | const ctx = this.ctx;
|
6965 | const glyph = this.processingType3;
|
6966 | if (glyph) {
|
6967 | if (glyph.compiled === undefined) {
|
6968 | glyph.compiled = compileType3Glyph(img);
|
6969 | }
|
6970 | if (glyph.compiled) {
|
6971 | glyph.compiled(ctx);
|
6972 | return;
|
6973 | }
|
6974 | }
|
6975 | const mask = this._createMaskCanvas(img);
|
6976 | const maskCanvas = mask.canvas;
|
6977 | ctx.save();
|
6978 | ctx.setTransform(1, 0, 0, 1, 0, 0);
|
6979 | ctx.drawImage(maskCanvas, mask.offsetX, mask.offsetY);
|
6980 | ctx.restore();
|
6981 | this.compose();
|
6982 | }
|
6983 | paintImageMaskXObjectRepeat(img, scaleX, skewX = 0, skewY = 0, scaleY, positions) {
|
6984 | if (!this.contentVisible) {
|
6985 | return;
|
6986 | }
|
6987 | img = this.getObject(img.data, img);
|
6988 | const ctx = this.ctx;
|
6989 | ctx.save();
|
6990 | const currentTransform = (0, _display_utils.getCurrentTransform)(ctx);
|
6991 | ctx.transform(scaleX, skewX, skewY, scaleY, 0, 0);
|
6992 | const mask = this._createMaskCanvas(img);
|
6993 | ctx.setTransform(1, 0, 0, 1, mask.offsetX - currentTransform[4], mask.offsetY - currentTransform[5]);
|
6994 | for (let i = 0, ii = positions.length; i < ii; i += 2) {
|
6995 | const trans = _util.Util.transform(currentTransform, [scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]]);
|
6996 | const [x, y] = _util.Util.applyTransform([0, 0], trans);
|
6997 | ctx.drawImage(mask.canvas, x, y);
|
6998 | }
|
6999 | ctx.restore();
|
7000 | this.compose();
|
7001 | }
|
7002 | paintImageMaskXObjectGroup(images) {
|
7003 | if (!this.contentVisible) {
|
7004 | return;
|
7005 | }
|
7006 | const ctx = this.ctx;
|
7007 | const fillColor = this.current.fillColor;
|
7008 | const isPatternFill = this.current.patternFill;
|
7009 | for (const image of images) {
|
7010 | const {
|
7011 | data,
|
7012 | width,
|
7013 | height,
|
7014 | transform
|
7015 | } = image;
|
7016 | const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
|
7017 | const maskCtx = maskCanvas.context;
|
7018 | maskCtx.save();
|
7019 | const img = this.getObject(data, image);
|
7020 | putBinaryImageMask(maskCtx, img);
|
7021 | maskCtx.globalCompositeOperation = "source-in";
|
7022 | maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this, (0, _display_utils.getCurrentTransformInverse)(ctx), _pattern_helper.PathType.FILL) : fillColor;
|
7023 | maskCtx.fillRect(0, 0, width, height);
|
7024 | maskCtx.restore();
|
7025 | ctx.save();
|
7026 | ctx.transform(...transform);
|
7027 | ctx.scale(1, -1);
|
7028 | drawImageAtIntegerCoords(ctx, maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
|
7029 | ctx.restore();
|
7030 | }
|
7031 | this.compose();
|
7032 | }
|
7033 | paintImageXObject(objId) {
|
7034 | if (!this.contentVisible) {
|
7035 | return;
|
7036 | }
|
7037 | const imgData = this.getObject(objId);
|
7038 | if (!imgData) {
|
7039 | (0, _util.warn)("Dependent image isn't ready yet");
|
7040 | return;
|
7041 | }
|
7042 | this.paintInlineImageXObject(imgData);
|
7043 | }
|
7044 | paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
|
7045 | if (!this.contentVisible) {
|
7046 | return;
|
7047 | }
|
7048 | const imgData = this.getObject(objId);
|
7049 | if (!imgData) {
|
7050 | (0, _util.warn)("Dependent image isn't ready yet");
|
7051 | return;
|
7052 | }
|
7053 | const width = imgData.width;
|
7054 | const height = imgData.height;
|
7055 | const map = [];
|
7056 | for (let i = 0, ii = positions.length; i < ii; i += 2) {
|
7057 | map.push({
|
7058 | transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
|
7059 | x: 0,
|
7060 | y: 0,
|
7061 | w: width,
|
7062 | h: height
|
7063 | });
|
7064 | }
|
7065 | this.paintInlineImageXObjectGroup(imgData, map);
|
7066 | }
|
7067 | applyTransferMapsToCanvas(ctx) {
|
7068 | if (this.current.transferMaps !== "none") {
|
7069 | ctx.filter = this.current.transferMaps;
|
7070 | ctx.drawImage(ctx.canvas, 0, 0);
|
7071 | ctx.filter = "none";
|
7072 | }
|
7073 | return ctx.canvas;
|
7074 | }
|
7075 | applyTransferMapsToBitmap(imgData) {
|
7076 | if (this.current.transferMaps === "none") {
|
7077 | return imgData.bitmap;
|
7078 | }
|
7079 | const {
|
7080 | bitmap,
|
7081 | width,
|
7082 | height
|
7083 | } = imgData;
|
7084 | const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
|
7085 | const tmpCtx = tmpCanvas.context;
|
7086 | tmpCtx.filter = this.current.transferMaps;
|
7087 | tmpCtx.drawImage(bitmap, 0, 0);
|
7088 | tmpCtx.filter = "none";
|
7089 | return tmpCanvas.canvas;
|
7090 | }
|
7091 | paintInlineImageXObject(imgData) {
|
7092 | if (!this.contentVisible) {
|
7093 | return;
|
7094 | }
|
7095 | const width = imgData.width;
|
7096 | const height = imgData.height;
|
7097 | const ctx = this.ctx;
|
7098 | this.save();
|
7099 | if (!_is_node.isNodeJS) {
|
7100 | ctx.filter = "none";
|
7101 | }
|
7102 | ctx.scale(1 / width, -1 / height);
|
7103 | let imgToPaint;
|
7104 | if (imgData.bitmap) {
|
7105 | imgToPaint = this.applyTransferMapsToBitmap(imgData);
|
7106 | } else if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
|
7107 | imgToPaint = imgData;
|
7108 | } else {
|
7109 | const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
|
7110 | const tmpCtx = tmpCanvas.context;
|
7111 | putBinaryImageData(tmpCtx, imgData);
|
7112 | imgToPaint = this.applyTransferMapsToCanvas(tmpCtx);
|
7113 | }
|
7114 | const scaled = this._scaleImage(imgToPaint, (0, _display_utils.getCurrentTransformInverse)(ctx));
|
7115 | ctx.imageSmoothingEnabled = getImageSmoothingEnabled((0, _display_utils.getCurrentTransform)(ctx), imgData.interpolate);
|
7116 | drawImageAtIntegerCoords(ctx, scaled.img, 0, 0, scaled.paintWidth, scaled.paintHeight, 0, -height, width, height);
|
7117 | this.compose();
|
7118 | this.restore();
|
7119 | }
|
7120 | paintInlineImageXObjectGroup(imgData, map) {
|
7121 | if (!this.contentVisible) {
|
7122 | return;
|
7123 | }
|
7124 | const ctx = this.ctx;
|
7125 | let imgToPaint;
|
7126 | if (imgData.bitmap) {
|
7127 | imgToPaint = imgData.bitmap;
|
7128 | } else {
|
7129 | const w = imgData.width;
|
7130 | const h = imgData.height;
|
7131 | const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
|
7132 | const tmpCtx = tmpCanvas.context;
|
7133 | putBinaryImageData(tmpCtx, imgData);
|
7134 | imgToPaint = this.applyTransferMapsToCanvas(tmpCtx);
|
7135 | }
|
7136 | for (const entry of map) {
|
7137 | ctx.save();
|
7138 | ctx.transform(...entry.transform);
|
7139 | ctx.scale(1, -1);
|
7140 | drawImageAtIntegerCoords(ctx, imgToPaint, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
|
7141 | ctx.restore();
|
7142 | }
|
7143 | this.compose();
|
7144 | }
|
7145 | paintSolidColorImageMask() {
|
7146 | if (!this.contentVisible) {
|
7147 | return;
|
7148 | }
|
7149 | this.ctx.fillRect(0, 0, 1, 1);
|
7150 | this.compose();
|
7151 | }
|
7152 | markPoint(tag) {}
|
7153 | markPointProps(tag, properties) {}
|
7154 | beginMarkedContent(tag) {
|
7155 | this.markedContentStack.push({
|
7156 | visible: true
|
7157 | });
|
7158 | }
|
7159 | beginMarkedContentProps(tag, properties) {
|
7160 | if (tag === "OC") {
|
7161 | this.markedContentStack.push({
|
7162 | visible: this.optionalContentConfig.isVisible(properties)
|
7163 | });
|
7164 | } else {
|
7165 | this.markedContentStack.push({
|
7166 | visible: true
|
7167 | });
|
7168 | }
|
7169 | this.contentVisible = this.isContentVisible();
|
7170 | }
|
7171 | endMarkedContent() {
|
7172 | this.markedContentStack.pop();
|
7173 | this.contentVisible = this.isContentVisible();
|
7174 | }
|
7175 | beginCompat() {}
|
7176 | endCompat() {}
|
7177 | consumePath(clipBox) {
|
7178 | const isEmpty = this.current.isEmptyClip();
|
7179 | if (this.pendingClip) {
|
7180 | this.current.updateClipFromPath();
|
7181 | }
|
7182 | if (!this.pendingClip) {
|
7183 | this.compose(clipBox);
|
7184 | }
|
7185 | const ctx = this.ctx;
|
7186 | if (this.pendingClip) {
|
7187 | if (!isEmpty) {
|
7188 | if (this.pendingClip === EO_CLIP) {
|
7189 | ctx.clip("evenodd");
|
7190 | } else {
|
7191 | ctx.clip();
|
7192 | }
|
7193 | }
|
7194 | this.pendingClip = null;
|
7195 | }
|
7196 | this.current.startNewPathAndClipBox(this.current.clipBox);
|
7197 | ctx.beginPath();
|
7198 | }
|
7199 | getSinglePixelWidth() {
|
7200 | if (!this._cachedGetSinglePixelWidth) {
|
7201 | const m = (0, _display_utils.getCurrentTransform)(this.ctx);
|
7202 | if (m[1] === 0 && m[2] === 0) {
|
7203 | this._cachedGetSinglePixelWidth = 1 / Math.min(Math.abs(m[0]), Math.abs(m[3]));
|
7204 | } else {
|
7205 | const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
|
7206 | const normX = Math.hypot(m[0], m[2]);
|
7207 | const normY = Math.hypot(m[1], m[3]);
|
7208 | this._cachedGetSinglePixelWidth = Math.max(normX, normY) / absDet;
|
7209 | }
|
7210 | }
|
7211 | return this._cachedGetSinglePixelWidth;
|
7212 | }
|
7213 | getScaleForStroking() {
|
7214 | if (this._cachedScaleForStroking[0] === -1) {
|
7215 | const {
|
7216 | lineWidth
|
7217 | } = this.current;
|
7218 | const {
|
7219 | a,
|
7220 | b,
|
7221 | c,
|
7222 | d
|
7223 | } = this.ctx.getTransform();
|
7224 | let scaleX, scaleY;
|
7225 | if (b === 0 && c === 0) {
|
7226 | const normX = Math.abs(a);
|
7227 | const normY = Math.abs(d);
|
7228 | if (normX === normY) {
|
7229 | if (lineWidth === 0) {
|
7230 | scaleX = scaleY = 1 / normX;
|
7231 | } else {
|
7232 | const scaledLineWidth = normX * lineWidth;
|
7233 | scaleX = scaleY = scaledLineWidth < 1 ? 1 / scaledLineWidth : 1;
|
7234 | }
|
7235 | } else if (lineWidth === 0) {
|
7236 | scaleX = 1 / normX;
|
7237 | scaleY = 1 / normY;
|
7238 | } else {
|
7239 | const scaledXLineWidth = normX * lineWidth;
|
7240 | const scaledYLineWidth = normY * lineWidth;
|
7241 | scaleX = scaledXLineWidth < 1 ? 1 / scaledXLineWidth : 1;
|
7242 | scaleY = scaledYLineWidth < 1 ? 1 / scaledYLineWidth : 1;
|
7243 | }
|
7244 | } else {
|
7245 | const absDet = Math.abs(a * d - b * c);
|
7246 | const normX = Math.hypot(a, b);
|
7247 | const normY = Math.hypot(c, d);
|
7248 | if (lineWidth === 0) {
|
7249 | scaleX = normY / absDet;
|
7250 | scaleY = normX / absDet;
|
7251 | } else {
|
7252 | const baseArea = lineWidth * absDet;
|
7253 | scaleX = normY > baseArea ? normY / baseArea : 1;
|
7254 | scaleY = normX > baseArea ? normX / baseArea : 1;
|
7255 | }
|
7256 | }
|
7257 | this._cachedScaleForStroking[0] = scaleX;
|
7258 | this._cachedScaleForStroking[1] = scaleY;
|
7259 | }
|
7260 | return this._cachedScaleForStroking;
|
7261 | }
|
7262 | rescaleAndStroke(saveRestore) {
|
7263 | const {
|
7264 | ctx
|
7265 | } = this;
|
7266 | const {
|
7267 | lineWidth
|
7268 | } = this.current;
|
7269 | const [scaleX, scaleY] = this.getScaleForStroking();
|
7270 | ctx.lineWidth = lineWidth || 1;
|
7271 | if (scaleX === 1 && scaleY === 1) {
|
7272 | ctx.stroke();
|
7273 | return;
|
7274 | }
|
7275 | const dashes = ctx.getLineDash();
|
7276 | if (saveRestore) {
|
7277 | ctx.save();
|
7278 | }
|
7279 | ctx.scale(scaleX, scaleY);
|
7280 | if (dashes.length > 0) {
|
7281 | const scale = Math.max(scaleX, scaleY);
|
7282 | ctx.setLineDash(dashes.map(x => x / scale));
|
7283 | ctx.lineDashOffset /= scale;
|
7284 | }
|
7285 | ctx.stroke();
|
7286 | if (saveRestore) {
|
7287 | ctx.restore();
|
7288 | }
|
7289 | }
|
7290 | isContentVisible() {
|
7291 | for (let i = this.markedContentStack.length - 1; i >= 0; i--) {
|
7292 | if (!this.markedContentStack[i].visible) {
|
7293 | return false;
|
7294 | }
|
7295 | }
|
7296 | return true;
|
7297 | }
|
7298 | }
|
7299 | exports.CanvasGraphics = CanvasGraphics;
|
7300 | for (const op in _util.OPS) {
|
7301 | if (CanvasGraphics.prototype[op] !== undefined) {
|
7302 | CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
|
7303 | }
|
7304 | }
|
7305 |
|
7306 | }),
|
7307 |
|
7308 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
7309 |
|
7310 |
|
7311 |
|
7312 | Object.defineProperty(exports, "__esModule", ({
|
7313 | value: true
|
7314 | }));
|
7315 | exports.TilingPattern = exports.PathType = void 0;
|
7316 | exports.getShadingPattern = getShadingPattern;
|
7317 | var _util = __w_pdfjs_require__(1);
|
7318 | var _display_utils = __w_pdfjs_require__(6);
|
7319 | const PathType = {
|
7320 | FILL: "Fill",
|
7321 | STROKE: "Stroke",
|
7322 | SHADING: "Shading"
|
7323 | };
|
7324 | exports.PathType = PathType;
|
7325 | function applyBoundingBox(ctx, bbox) {
|
7326 | if (!bbox) {
|
7327 | return;
|
7328 | }
|
7329 | const width = bbox[2] - bbox[0];
|
7330 | const height = bbox[3] - bbox[1];
|
7331 | const region = new Path2D();
|
7332 | region.rect(bbox[0], bbox[1], width, height);
|
7333 | ctx.clip(region);
|
7334 | }
|
7335 | class BaseShadingPattern {
|
7336 | constructor() {
|
7337 | if (this.constructor === BaseShadingPattern) {
|
7338 | (0, _util.unreachable)("Cannot initialize BaseShadingPattern.");
|
7339 | }
|
7340 | }
|
7341 | getPattern() {
|
7342 | (0, _util.unreachable)("Abstract method `getPattern` called.");
|
7343 | }
|
7344 | }
|
7345 | class RadialAxialShadingPattern extends BaseShadingPattern {
|
7346 | constructor(IR) {
|
7347 | super();
|
7348 | this._type = IR[1];
|
7349 | this._bbox = IR[2];
|
7350 | this._colorStops = IR[3];
|
7351 | this._p0 = IR[4];
|
7352 | this._p1 = IR[5];
|
7353 | this._r0 = IR[6];
|
7354 | this._r1 = IR[7];
|
7355 | this.matrix = null;
|
7356 | }
|
7357 | _createGradient(ctx) {
|
7358 | let grad;
|
7359 | if (this._type === "axial") {
|
7360 | grad = ctx.createLinearGradient(this._p0[0], this._p0[1], this._p1[0], this._p1[1]);
|
7361 | } else if (this._type === "radial") {
|
7362 | grad = ctx.createRadialGradient(this._p0[0], this._p0[1], this._r0, this._p1[0], this._p1[1], this._r1);
|
7363 | }
|
7364 | for (const colorStop of this._colorStops) {
|
7365 | grad.addColorStop(colorStop[0], colorStop[1]);
|
7366 | }
|
7367 | return grad;
|
7368 | }
|
7369 | getPattern(ctx, owner, inverse, pathType) {
|
7370 | let pattern;
|
7371 | if (pathType === PathType.STROKE || pathType === PathType.FILL) {
|
7372 | const ownerBBox = owner.current.getClippedPathBoundingBox(pathType, (0, _display_utils.getCurrentTransform)(ctx)) || [0, 0, 0, 0];
|
7373 | const width = Math.ceil(ownerBBox[2] - ownerBBox[0]) || 1;
|
7374 | const height = Math.ceil(ownerBBox[3] - ownerBBox[1]) || 1;
|
7375 | const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", width, height, true);
|
7376 | const tmpCtx = tmpCanvas.context;
|
7377 | tmpCtx.clearRect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
|
7378 | tmpCtx.beginPath();
|
7379 | tmpCtx.rect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
|
7380 | tmpCtx.translate(-ownerBBox[0], -ownerBBox[1]);
|
7381 | inverse = _util.Util.transform(inverse, [1, 0, 0, 1, ownerBBox[0], ownerBBox[1]]);
|
7382 | tmpCtx.transform(...owner.baseTransform);
|
7383 | if (this.matrix) {
|
7384 | tmpCtx.transform(...this.matrix);
|
7385 | }
|
7386 | applyBoundingBox(tmpCtx, this._bbox);
|
7387 | tmpCtx.fillStyle = this._createGradient(tmpCtx);
|
7388 | tmpCtx.fill();
|
7389 | pattern = ctx.createPattern(tmpCanvas.canvas, "no-repeat");
|
7390 | const domMatrix = new DOMMatrix(inverse);
|
7391 | pattern.setTransform(domMatrix);
|
7392 | } else {
|
7393 | applyBoundingBox(ctx, this._bbox);
|
7394 | pattern = this._createGradient(ctx);
|
7395 | }
|
7396 | return pattern;
|
7397 | }
|
7398 | }
|
7399 | function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
|
7400 | const coords = context.coords,
|
7401 | colors = context.colors;
|
7402 | const bytes = data.data,
|
7403 | rowSize = data.width * 4;
|
7404 | let tmp;
|
7405 | if (coords[p1 + 1] > coords[p2 + 1]) {
|
7406 | tmp = p1;
|
7407 | p1 = p2;
|
7408 | p2 = tmp;
|
7409 | tmp = c1;
|
7410 | c1 = c2;
|
7411 | c2 = tmp;
|
7412 | }
|
7413 | if (coords[p2 + 1] > coords[p3 + 1]) {
|
7414 | tmp = p2;
|
7415 | p2 = p3;
|
7416 | p3 = tmp;
|
7417 | tmp = c2;
|
7418 | c2 = c3;
|
7419 | c3 = tmp;
|
7420 | }
|
7421 | if (coords[p1 + 1] > coords[p2 + 1]) {
|
7422 | tmp = p1;
|
7423 | p1 = p2;
|
7424 | p2 = tmp;
|
7425 | tmp = c1;
|
7426 | c1 = c2;
|
7427 | c2 = tmp;
|
7428 | }
|
7429 | const x1 = (coords[p1] + context.offsetX) * context.scaleX;
|
7430 | const y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
|
7431 | const x2 = (coords[p2] + context.offsetX) * context.scaleX;
|
7432 | const y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
|
7433 | const x3 = (coords[p3] + context.offsetX) * context.scaleX;
|
7434 | const y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
|
7435 | if (y1 >= y3) {
|
7436 | return;
|
7437 | }
|
7438 | const c1r = colors[c1],
|
7439 | c1g = colors[c1 + 1],
|
7440 | c1b = colors[c1 + 2];
|
7441 | const c2r = colors[c2],
|
7442 | c2g = colors[c2 + 1],
|
7443 | c2b = colors[c2 + 2];
|
7444 | const c3r = colors[c3],
|
7445 | c3g = colors[c3 + 1],
|
7446 | c3b = colors[c3 + 2];
|
7447 | const minY = Math.round(y1),
|
7448 | maxY = Math.round(y3);
|
7449 | let xa, car, cag, cab;
|
7450 | let xb, cbr, cbg, cbb;
|
7451 | for (let y = minY; y <= maxY; y++) {
|
7452 | if (y < y2) {
|
7453 | let k;
|
7454 | if (y < y1) {
|
7455 | k = 0;
|
7456 | } else {
|
7457 | k = (y1 - y) / (y1 - y2);
|
7458 | }
|
7459 | xa = x1 - (x1 - x2) * k;
|
7460 | car = c1r - (c1r - c2r) * k;
|
7461 | cag = c1g - (c1g - c2g) * k;
|
7462 | cab = c1b - (c1b - c2b) * k;
|
7463 | } else {
|
7464 | let k;
|
7465 | if (y > y3) {
|
7466 | k = 1;
|
7467 | } else if (y2 === y3) {
|
7468 | k = 0;
|
7469 | } else {
|
7470 | k = (y2 - y) / (y2 - y3);
|
7471 | }
|
7472 | xa = x2 - (x2 - x3) * k;
|
7473 | car = c2r - (c2r - c3r) * k;
|
7474 | cag = c2g - (c2g - c3g) * k;
|
7475 | cab = c2b - (c2b - c3b) * k;
|
7476 | }
|
7477 | let k;
|
7478 | if (y < y1) {
|
7479 | k = 0;
|
7480 | } else if (y > y3) {
|
7481 | k = 1;
|
7482 | } else {
|
7483 | k = (y1 - y) / (y1 - y3);
|
7484 | }
|
7485 | xb = x1 - (x1 - x3) * k;
|
7486 | cbr = c1r - (c1r - c3r) * k;
|
7487 | cbg = c1g - (c1g - c3g) * k;
|
7488 | cbb = c1b - (c1b - c3b) * k;
|
7489 | const x1_ = Math.round(Math.min(xa, xb));
|
7490 | const x2_ = Math.round(Math.max(xa, xb));
|
7491 | let j = rowSize * y + x1_ * 4;
|
7492 | for (let x = x1_; x <= x2_; x++) {
|
7493 | k = (xa - x) / (xa - xb);
|
7494 | if (k < 0) {
|
7495 | k = 0;
|
7496 | } else if (k > 1) {
|
7497 | k = 1;
|
7498 | }
|
7499 | bytes[j++] = car - (car - cbr) * k | 0;
|
7500 | bytes[j++] = cag - (cag - cbg) * k | 0;
|
7501 | bytes[j++] = cab - (cab - cbb) * k | 0;
|
7502 | bytes[j++] = 255;
|
7503 | }
|
7504 | }
|
7505 | }
|
7506 | function drawFigure(data, figure, context) {
|
7507 | const ps = figure.coords;
|
7508 | const cs = figure.colors;
|
7509 | let i, ii;
|
7510 | switch (figure.type) {
|
7511 | case "lattice":
|
7512 | const verticesPerRow = figure.verticesPerRow;
|
7513 | const rows = Math.floor(ps.length / verticesPerRow) - 1;
|
7514 | const cols = verticesPerRow - 1;
|
7515 | for (i = 0; i < rows; i++) {
|
7516 | let q = i * verticesPerRow;
|
7517 | for (let j = 0; j < cols; j++, q++) {
|
7518 | drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
|
7519 | drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
|
7520 | }
|
7521 | }
|
7522 | break;
|
7523 | case "triangles":
|
7524 | for (i = 0, ii = ps.length; i < ii; i += 3) {
|
7525 | drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
|
7526 | }
|
7527 | break;
|
7528 | default:
|
7529 | throw new Error("illegal figure");
|
7530 | }
|
7531 | }
|
7532 | class MeshShadingPattern extends BaseShadingPattern {
|
7533 | constructor(IR) {
|
7534 | super();
|
7535 | this._coords = IR[2];
|
7536 | this._colors = IR[3];
|
7537 | this._figures = IR[4];
|
7538 | this._bounds = IR[5];
|
7539 | this._bbox = IR[7];
|
7540 | this._background = IR[8];
|
7541 | this.matrix = null;
|
7542 | }
|
7543 | _createMeshCanvas(combinedScale, backgroundColor, cachedCanvases) {
|
7544 | const EXPECTED_SCALE = 1.1;
|
7545 | const MAX_PATTERN_SIZE = 3000;
|
7546 | const BORDER_SIZE = 2;
|
7547 | const offsetX = Math.floor(this._bounds[0]);
|
7548 | const offsetY = Math.floor(this._bounds[1]);
|
7549 | const boundsWidth = Math.ceil(this._bounds[2]) - offsetX;
|
7550 | const boundsHeight = Math.ceil(this._bounds[3]) - offsetY;
|
7551 | const width = Math.min(Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
|
7552 | const height = Math.min(Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
|
7553 | const scaleX = boundsWidth / width;
|
7554 | const scaleY = boundsHeight / height;
|
7555 | const context = {
|
7556 | coords: this._coords,
|
7557 | colors: this._colors,
|
7558 | offsetX: -offsetX,
|
7559 | offsetY: -offsetY,
|
7560 | scaleX: 1 / scaleX,
|
7561 | scaleY: 1 / scaleY
|
7562 | };
|
7563 | const paddedWidth = width + BORDER_SIZE * 2;
|
7564 | const paddedHeight = height + BORDER_SIZE * 2;
|
7565 | const tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
|
7566 | const tmpCtx = tmpCanvas.context;
|
7567 | const data = tmpCtx.createImageData(width, height);
|
7568 | if (backgroundColor) {
|
7569 | const bytes = data.data;
|
7570 | for (let i = 0, ii = bytes.length; i < ii; i += 4) {
|
7571 | bytes[i] = backgroundColor[0];
|
7572 | bytes[i + 1] = backgroundColor[1];
|
7573 | bytes[i + 2] = backgroundColor[2];
|
7574 | bytes[i + 3] = 255;
|
7575 | }
|
7576 | }
|
7577 | for (const figure of this._figures) {
|
7578 | drawFigure(data, figure, context);
|
7579 | }
|
7580 | tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
|
7581 | const canvas = tmpCanvas.canvas;
|
7582 | return {
|
7583 | canvas,
|
7584 | offsetX: offsetX - BORDER_SIZE * scaleX,
|
7585 | offsetY: offsetY - BORDER_SIZE * scaleY,
|
7586 | scaleX,
|
7587 | scaleY
|
7588 | };
|
7589 | }
|
7590 | getPattern(ctx, owner, inverse, pathType) {
|
7591 | applyBoundingBox(ctx, this._bbox);
|
7592 | let scale;
|
7593 | if (pathType === PathType.SHADING) {
|
7594 | scale = _util.Util.singularValueDecompose2dScale((0, _display_utils.getCurrentTransform)(ctx));
|
7595 | } else {
|
7596 | scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
|
7597 | if (this.matrix) {
|
7598 | const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
|
7599 | scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
|
7600 | }
|
7601 | }
|
7602 | const temporaryPatternCanvas = this._createMeshCanvas(scale, pathType === PathType.SHADING ? null : this._background, owner.cachedCanvases);
|
7603 | if (pathType !== PathType.SHADING) {
|
7604 | ctx.setTransform(...owner.baseTransform);
|
7605 | if (this.matrix) {
|
7606 | ctx.transform(...this.matrix);
|
7607 | }
|
7608 | }
|
7609 | ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
|
7610 | ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
|
7611 | return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
|
7612 | }
|
7613 | }
|
7614 | class DummyShadingPattern extends BaseShadingPattern {
|
7615 | getPattern() {
|
7616 | return "hotpink";
|
7617 | }
|
7618 | }
|
7619 | function getShadingPattern(IR) {
|
7620 | switch (IR[0]) {
|
7621 | case "RadialAxial":
|
7622 | return new RadialAxialShadingPattern(IR);
|
7623 | case "Mesh":
|
7624 | return new MeshShadingPattern(IR);
|
7625 | case "Dummy":
|
7626 | return new DummyShadingPattern();
|
7627 | }
|
7628 | throw new Error(`Unknown IR type: ${IR[0]}`);
|
7629 | }
|
7630 | const PaintType = {
|
7631 | COLORED: 1,
|
7632 | UNCOLORED: 2
|
7633 | };
|
7634 | class TilingPattern {
|
7635 | static MAX_PATTERN_SIZE = 3000;
|
7636 | constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
|
7637 | this.operatorList = IR[2];
|
7638 | this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
|
7639 | this.bbox = IR[4];
|
7640 | this.xstep = IR[5];
|
7641 | this.ystep = IR[6];
|
7642 | this.paintType = IR[7];
|
7643 | this.tilingType = IR[8];
|
7644 | this.color = color;
|
7645 | this.ctx = ctx;
|
7646 | this.canvasGraphicsFactory = canvasGraphicsFactory;
|
7647 | this.baseTransform = baseTransform;
|
7648 | }
|
7649 | createPatternCanvas(owner) {
|
7650 | const operatorList = this.operatorList;
|
7651 | const bbox = this.bbox;
|
7652 | const xstep = this.xstep;
|
7653 | const ystep = this.ystep;
|
7654 | const paintType = this.paintType;
|
7655 | const tilingType = this.tilingType;
|
7656 | const color = this.color;
|
7657 | const canvasGraphicsFactory = this.canvasGraphicsFactory;
|
7658 | (0, _util.info)("TilingType: " + tilingType);
|
7659 | const x0 = bbox[0],
|
7660 | y0 = bbox[1],
|
7661 | x1 = bbox[2],
|
7662 | y1 = bbox[3];
|
7663 | const matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
|
7664 | const curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
|
7665 | const combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
|
7666 | const dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
|
7667 | const dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
|
7668 | const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
|
7669 | const tmpCtx = tmpCanvas.context;
|
7670 | const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
|
7671 | graphics.groupLevel = owner.groupLevel;
|
7672 | this.setFillAndStrokeStyleToContext(graphics, paintType, color);
|
7673 | let adjustedX0 = x0;
|
7674 | let adjustedY0 = y0;
|
7675 | let adjustedX1 = x1;
|
7676 | let adjustedY1 = y1;
|
7677 | if (x0 < 0) {
|
7678 | adjustedX0 = 0;
|
7679 | adjustedX1 += Math.abs(x0);
|
7680 | }
|
7681 | if (y0 < 0) {
|
7682 | adjustedY0 = 0;
|
7683 | adjustedY1 += Math.abs(y0);
|
7684 | }
|
7685 | tmpCtx.translate(-(dimx.scale * adjustedX0), -(dimy.scale * adjustedY0));
|
7686 | graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
|
7687 | tmpCtx.save();
|
7688 | this.clipBbox(graphics, adjustedX0, adjustedY0, adjustedX1, adjustedY1);
|
7689 | graphics.baseTransform = (0, _display_utils.getCurrentTransform)(graphics.ctx);
|
7690 | graphics.executeOperatorList(operatorList);
|
7691 | graphics.endDrawing();
|
7692 | return {
|
7693 | canvas: tmpCanvas.canvas,
|
7694 | scaleX: dimx.scale,
|
7695 | scaleY: dimy.scale,
|
7696 | offsetX: adjustedX0,
|
7697 | offsetY: adjustedY0
|
7698 | };
|
7699 | }
|
7700 | getSizeAndScale(step, realOutputSize, scale) {
|
7701 | step = Math.abs(step);
|
7702 | const maxSize = Math.max(TilingPattern.MAX_PATTERN_SIZE, realOutputSize);
|
7703 | let size = Math.ceil(step * scale);
|
7704 | if (size >= maxSize) {
|
7705 | size = maxSize;
|
7706 | } else {
|
7707 | scale = size / step;
|
7708 | }
|
7709 | return {
|
7710 | scale,
|
7711 | size
|
7712 | };
|
7713 | }
|
7714 | clipBbox(graphics, x0, y0, x1, y1) {
|
7715 | const bboxWidth = x1 - x0;
|
7716 | const bboxHeight = y1 - y0;
|
7717 | graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
|
7718 | graphics.current.updateRectMinMax((0, _display_utils.getCurrentTransform)(graphics.ctx), [x0, y0, x1, y1]);
|
7719 | graphics.clip();
|
7720 | graphics.endPath();
|
7721 | }
|
7722 | setFillAndStrokeStyleToContext(graphics, paintType, color) {
|
7723 | const context = graphics.ctx,
|
7724 | current = graphics.current;
|
7725 | switch (paintType) {
|
7726 | case PaintType.COLORED:
|
7727 | const ctx = this.ctx;
|
7728 | context.fillStyle = ctx.fillStyle;
|
7729 | context.strokeStyle = ctx.strokeStyle;
|
7730 | current.fillColor = ctx.fillStyle;
|
7731 | current.strokeColor = ctx.strokeStyle;
|
7732 | break;
|
7733 | case PaintType.UNCOLORED:
|
7734 | const cssColor = _util.Util.makeHexColor(color[0], color[1], color[2]);
|
7735 | context.fillStyle = cssColor;
|
7736 | context.strokeStyle = cssColor;
|
7737 | current.fillColor = cssColor;
|
7738 | current.strokeColor = cssColor;
|
7739 | break;
|
7740 | default:
|
7741 | throw new _util.FormatError(`Unsupported paint type: ${paintType}`);
|
7742 | }
|
7743 | }
|
7744 | getPattern(ctx, owner, inverse, pathType) {
|
7745 | let matrix = inverse;
|
7746 | if (pathType !== PathType.SHADING) {
|
7747 | matrix = _util.Util.transform(matrix, owner.baseTransform);
|
7748 | if (this.matrix) {
|
7749 | matrix = _util.Util.transform(matrix, this.matrix);
|
7750 | }
|
7751 | }
|
7752 | const temporaryPatternCanvas = this.createPatternCanvas(owner);
|
7753 | let domMatrix = new DOMMatrix(matrix);
|
7754 | domMatrix = domMatrix.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
|
7755 | domMatrix = domMatrix.scale(1 / temporaryPatternCanvas.scaleX, 1 / temporaryPatternCanvas.scaleY);
|
7756 | const pattern = ctx.createPattern(temporaryPatternCanvas.canvas, "repeat");
|
7757 | pattern.setTransform(domMatrix);
|
7758 | return pattern;
|
7759 | }
|
7760 | }
|
7761 | exports.TilingPattern = TilingPattern;
|
7762 |
|
7763 | }),
|
7764 |
|
7765 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
7766 |
|
7767 |
|
7768 |
|
7769 | Object.defineProperty(exports, "__esModule", ({
|
7770 | value: true
|
7771 | }));
|
7772 | exports.convertBlackAndWhiteToRGBA = convertBlackAndWhiteToRGBA;
|
7773 | exports.convertToRGBA = convertToRGBA;
|
7774 | exports.grayToRGBA = grayToRGBA;
|
7775 | var _util = __w_pdfjs_require__(1);
|
7776 | function convertToRGBA(params) {
|
7777 | switch (params.kind) {
|
7778 | case _util.ImageKind.GRAYSCALE_1BPP:
|
7779 | return convertBlackAndWhiteToRGBA(params);
|
7780 | case _util.ImageKind.RGB_24BPP:
|
7781 | return convertRGBToRGBA(params);
|
7782 | }
|
7783 | return null;
|
7784 | }
|
7785 | function convertBlackAndWhiteToRGBA({
|
7786 | src,
|
7787 | srcPos = 0,
|
7788 | dest,
|
7789 | width,
|
7790 | height,
|
7791 | nonBlackColor = 0xffffffff,
|
7792 | inverseDecode = false
|
7793 | }) {
|
7794 | const black = _util.FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
|
7795 | const [zeroMapping, oneMapping] = inverseDecode ? [nonBlackColor, black] : [black, nonBlackColor];
|
7796 | const widthInSource = width >> 3;
|
7797 | const widthRemainder = width & 7;
|
7798 | const srcLength = src.length;
|
7799 | dest = new Uint32Array(dest.buffer);
|
7800 | let destPos = 0;
|
7801 | for (let i = 0; i < height; i++) {
|
7802 | for (const max = srcPos + widthInSource; srcPos < max; srcPos++) {
|
7803 | const elem = srcPos < srcLength ? src[srcPos] : 255;
|
7804 | dest[destPos++] = elem & 0b10000000 ? oneMapping : zeroMapping;
|
7805 | dest[destPos++] = elem & 0b1000000 ? oneMapping : zeroMapping;
|
7806 | dest[destPos++] = elem & 0b100000 ? oneMapping : zeroMapping;
|
7807 | dest[destPos++] = elem & 0b10000 ? oneMapping : zeroMapping;
|
7808 | dest[destPos++] = elem & 0b1000 ? oneMapping : zeroMapping;
|
7809 | dest[destPos++] = elem & 0b100 ? oneMapping : zeroMapping;
|
7810 | dest[destPos++] = elem & 0b10 ? oneMapping : zeroMapping;
|
7811 | dest[destPos++] = elem & 0b1 ? oneMapping : zeroMapping;
|
7812 | }
|
7813 | if (widthRemainder === 0) {
|
7814 | continue;
|
7815 | }
|
7816 | const elem = srcPos < srcLength ? src[srcPos++] : 255;
|
7817 | for (let j = 0; j < widthRemainder; j++) {
|
7818 | dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
|
7819 | }
|
7820 | }
|
7821 | return {
|
7822 | srcPos,
|
7823 | destPos
|
7824 | };
|
7825 | }
|
7826 | function convertRGBToRGBA({
|
7827 | src,
|
7828 | srcPos = 0,
|
7829 | dest,
|
7830 | destPos = 0,
|
7831 | width,
|
7832 | height
|
7833 | }) {
|
7834 | let i = 0;
|
7835 | const len32 = src.length >> 2;
|
7836 | const src32 = new Uint32Array(src.buffer, srcPos, len32);
|
7837 | if (_util.FeatureTest.isLittleEndian) {
|
7838 | for (; i < len32 - 2; i += 3, destPos += 4) {
|
7839 | const s1 = src32[i];
|
7840 | const s2 = src32[i + 1];
|
7841 | const s3 = src32[i + 2];
|
7842 | dest[destPos] = s1 | 0xff000000;
|
7843 | dest[destPos + 1] = s1 >>> 24 | s2 << 8 | 0xff000000;
|
7844 | dest[destPos + 2] = s2 >>> 16 | s3 << 16 | 0xff000000;
|
7845 | dest[destPos + 3] = s3 >>> 8 | 0xff000000;
|
7846 | }
|
7847 | for (let j = i * 4, jj = src.length; j < jj; j += 3) {
|
7848 | dest[destPos++] = src[j] | src[j + 1] << 8 | src[j + 2] << 16 | 0xff000000;
|
7849 | }
|
7850 | } else {
|
7851 | for (; i < len32 - 2; i += 3, destPos += 4) {
|
7852 | const s1 = src32[i];
|
7853 | const s2 = src32[i + 1];
|
7854 | const s3 = src32[i + 2];
|
7855 | dest[destPos] = s1 | 0xff;
|
7856 | dest[destPos + 1] = s1 << 24 | s2 >>> 8 | 0xff;
|
7857 | dest[destPos + 2] = s2 << 16 | s3 >>> 16 | 0xff;
|
7858 | dest[destPos + 3] = s3 << 8 | 0xff;
|
7859 | }
|
7860 | for (let j = i * 4, jj = src.length; j < jj; j += 3) {
|
7861 | dest[destPos++] = src[j] << 24 | src[j + 1] << 16 | src[j + 2] << 8 | 0xff;
|
7862 | }
|
7863 | }
|
7864 | return {
|
7865 | srcPos,
|
7866 | destPos
|
7867 | };
|
7868 | }
|
7869 | function grayToRGBA(src, dest) {
|
7870 | if (_util.FeatureTest.isLittleEndian) {
|
7871 | for (let i = 0, ii = src.length; i < ii; i++) {
|
7872 | dest[i] = src[i] * 0x10101 | 0xff000000;
|
7873 | }
|
7874 | } else {
|
7875 | for (let i = 0, ii = src.length; i < ii; i++) {
|
7876 | dest[i] = src[i] * 0x1010100 | 0x000000ff;
|
7877 | }
|
7878 | }
|
7879 | }
|
7880 |
|
7881 | }),
|
7882 |
|
7883 | ((__unused_webpack_module, exports) => {
|
7884 |
|
7885 |
|
7886 |
|
7887 | Object.defineProperty(exports, "__esModule", ({
|
7888 | value: true
|
7889 | }));
|
7890 | exports.GlobalWorkerOptions = void 0;
|
7891 | const GlobalWorkerOptions = Object.create(null);
|
7892 | exports.GlobalWorkerOptions = GlobalWorkerOptions;
|
7893 | GlobalWorkerOptions.workerPort = null;
|
7894 | GlobalWorkerOptions.workerSrc = "";
|
7895 |
|
7896 | }),
|
7897 |
|
7898 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
7899 |
|
7900 |
|
7901 |
|
7902 | Object.defineProperty(exports, "__esModule", ({
|
7903 | value: true
|
7904 | }));
|
7905 | exports.MessageHandler = void 0;
|
7906 | var _util = __w_pdfjs_require__(1);
|
7907 | const CallbackKind = {
|
7908 | UNKNOWN: 0,
|
7909 | DATA: 1,
|
7910 | ERROR: 2
|
7911 | };
|
7912 | const StreamKind = {
|
7913 | UNKNOWN: 0,
|
7914 | CANCEL: 1,
|
7915 | CANCEL_COMPLETE: 2,
|
7916 | CLOSE: 3,
|
7917 | ENQUEUE: 4,
|
7918 | ERROR: 5,
|
7919 | PULL: 6,
|
7920 | PULL_COMPLETE: 7,
|
7921 | START_COMPLETE: 8
|
7922 | };
|
7923 | function wrapReason(reason) {
|
7924 | if (!(reason instanceof Error || typeof reason === "object" && reason !== null)) {
|
7925 | (0, _util.unreachable)('wrapReason: Expected "reason" to be a (possibly cloned) Error.');
|
7926 | }
|
7927 | switch (reason.name) {
|
7928 | case "AbortException":
|
7929 | return new _util.AbortException(reason.message);
|
7930 | case "MissingPDFException":
|
7931 | return new _util.MissingPDFException(reason.message);
|
7932 | case "PasswordException":
|
7933 | return new _util.PasswordException(reason.message, reason.code);
|
7934 | case "UnexpectedResponseException":
|
7935 | return new _util.UnexpectedResponseException(reason.message, reason.status);
|
7936 | case "UnknownErrorException":
|
7937 | return new _util.UnknownErrorException(reason.message, reason.details);
|
7938 | default:
|
7939 | return new _util.UnknownErrorException(reason.message, reason.toString());
|
7940 | }
|
7941 | }
|
7942 | class MessageHandler {
|
7943 | constructor(sourceName, targetName, comObj) {
|
7944 | this.sourceName = sourceName;
|
7945 | this.targetName = targetName;
|
7946 | this.comObj = comObj;
|
7947 | this.callbackId = 1;
|
7948 | this.streamId = 1;
|
7949 | this.streamSinks = Object.create(null);
|
7950 | this.streamControllers = Object.create(null);
|
7951 | this.callbackCapabilities = Object.create(null);
|
7952 | this.actionHandler = Object.create(null);
|
7953 | this._onComObjOnMessage = event => {
|
7954 | const data = event.data;
|
7955 | if (data.targetName !== this.sourceName) {
|
7956 | return;
|
7957 | }
|
7958 | if (data.stream) {
|
7959 | this.#processStreamMessage(data);
|
7960 | return;
|
7961 | }
|
7962 | if (data.callback) {
|
7963 | const callbackId = data.callbackId;
|
7964 | const capability = this.callbackCapabilities[callbackId];
|
7965 | if (!capability) {
|
7966 | throw new Error(`Cannot resolve callback ${callbackId}`);
|
7967 | }
|
7968 | delete this.callbackCapabilities[callbackId];
|
7969 | if (data.callback === CallbackKind.DATA) {
|
7970 | capability.resolve(data.data);
|
7971 | } else if (data.callback === CallbackKind.ERROR) {
|
7972 | capability.reject(wrapReason(data.reason));
|
7973 | } else {
|
7974 | throw new Error("Unexpected callback case");
|
7975 | }
|
7976 | return;
|
7977 | }
|
7978 | const action = this.actionHandler[data.action];
|
7979 | if (!action) {
|
7980 | throw new Error(`Unknown action from worker: ${data.action}`);
|
7981 | }
|
7982 | if (data.callbackId) {
|
7983 | const cbSourceName = this.sourceName;
|
7984 | const cbTargetName = data.sourceName;
|
7985 | new Promise(function (resolve) {
|
7986 | resolve(action(data.data));
|
7987 | }).then(function (result) {
|
7988 | comObj.postMessage({
|
7989 | sourceName: cbSourceName,
|
7990 | targetName: cbTargetName,
|
7991 | callback: CallbackKind.DATA,
|
7992 | callbackId: data.callbackId,
|
7993 | data: result
|
7994 | });
|
7995 | }, function (reason) {
|
7996 | comObj.postMessage({
|
7997 | sourceName: cbSourceName,
|
7998 | targetName: cbTargetName,
|
7999 | callback: CallbackKind.ERROR,
|
8000 | callbackId: data.callbackId,
|
8001 | reason: wrapReason(reason)
|
8002 | });
|
8003 | });
|
8004 | return;
|
8005 | }
|
8006 | if (data.streamId) {
|
8007 | this.#createStreamSink(data);
|
8008 | return;
|
8009 | }
|
8010 | action(data.data);
|
8011 | };
|
8012 | comObj.addEventListener("message", this._onComObjOnMessage);
|
8013 | }
|
8014 | on(actionName, handler) {
|
8015 | const ah = this.actionHandler;
|
8016 | if (ah[actionName]) {
|
8017 | throw new Error(`There is already an actionName called "${actionName}"`);
|
8018 | }
|
8019 | ah[actionName] = handler;
|
8020 | }
|
8021 | send(actionName, data, transfers) {
|
8022 | this.comObj.postMessage({
|
8023 | sourceName: this.sourceName,
|
8024 | targetName: this.targetName,
|
8025 | action: actionName,
|
8026 | data
|
8027 | }, transfers);
|
8028 | }
|
8029 | sendWithPromise(actionName, data, transfers) {
|
8030 | const callbackId = this.callbackId++;
|
8031 | const capability = new _util.PromiseCapability();
|
8032 | this.callbackCapabilities[callbackId] = capability;
|
8033 | try {
|
8034 | this.comObj.postMessage({
|
8035 | sourceName: this.sourceName,
|
8036 | targetName: this.targetName,
|
8037 | action: actionName,
|
8038 | callbackId,
|
8039 | data
|
8040 | }, transfers);
|
8041 | } catch (ex) {
|
8042 | capability.reject(ex);
|
8043 | }
|
8044 | return capability.promise;
|
8045 | }
|
8046 | sendWithStream(actionName, data, queueingStrategy, transfers) {
|
8047 | const streamId = this.streamId++,
|
8048 | sourceName = this.sourceName,
|
8049 | targetName = this.targetName,
|
8050 | comObj = this.comObj;
|
8051 | return new ReadableStream({
|
8052 | start: controller => {
|
8053 | const startCapability = new _util.PromiseCapability();
|
8054 | this.streamControllers[streamId] = {
|
8055 | controller,
|
8056 | startCall: startCapability,
|
8057 | pullCall: null,
|
8058 | cancelCall: null,
|
8059 | isClosed: false
|
8060 | };
|
8061 | comObj.postMessage({
|
8062 | sourceName,
|
8063 | targetName,
|
8064 | action: actionName,
|
8065 | streamId,
|
8066 | data,
|
8067 | desiredSize: controller.desiredSize
|
8068 | }, transfers);
|
8069 | return startCapability.promise;
|
8070 | },
|
8071 | pull: controller => {
|
8072 | const pullCapability = new _util.PromiseCapability();
|
8073 | this.streamControllers[streamId].pullCall = pullCapability;
|
8074 | comObj.postMessage({
|
8075 | sourceName,
|
8076 | targetName,
|
8077 | stream: StreamKind.PULL,
|
8078 | streamId,
|
8079 | desiredSize: controller.desiredSize
|
8080 | });
|
8081 | return pullCapability.promise;
|
8082 | },
|
8083 | cancel: reason => {
|
8084 | (0, _util.assert)(reason instanceof Error, "cancel must have a valid reason");
|
8085 | const cancelCapability = new _util.PromiseCapability();
|
8086 | this.streamControllers[streamId].cancelCall = cancelCapability;
|
8087 | this.streamControllers[streamId].isClosed = true;
|
8088 | comObj.postMessage({
|
8089 | sourceName,
|
8090 | targetName,
|
8091 | stream: StreamKind.CANCEL,
|
8092 | streamId,
|
8093 | reason: wrapReason(reason)
|
8094 | });
|
8095 | return cancelCapability.promise;
|
8096 | }
|
8097 | }, queueingStrategy);
|
8098 | }
|
8099 | #createStreamSink(data) {
|
8100 | const streamId = data.streamId,
|
8101 | sourceName = this.sourceName,
|
8102 | targetName = data.sourceName,
|
8103 | comObj = this.comObj;
|
8104 | const self = this,
|
8105 | action = this.actionHandler[data.action];
|
8106 | const streamSink = {
|
8107 | enqueue(chunk, size = 1, transfers) {
|
8108 | if (this.isCancelled) {
|
8109 | return;
|
8110 | }
|
8111 | const lastDesiredSize = this.desiredSize;
|
8112 | this.desiredSize -= size;
|
8113 | if (lastDesiredSize > 0 && this.desiredSize <= 0) {
|
8114 | this.sinkCapability = new _util.PromiseCapability();
|
8115 | this.ready = this.sinkCapability.promise;
|
8116 | }
|
8117 | comObj.postMessage({
|
8118 | sourceName,
|
8119 | targetName,
|
8120 | stream: StreamKind.ENQUEUE,
|
8121 | streamId,
|
8122 | chunk
|
8123 | }, transfers);
|
8124 | },
|
8125 | close() {
|
8126 | if (this.isCancelled) {
|
8127 | return;
|
8128 | }
|
8129 | this.isCancelled = true;
|
8130 | comObj.postMessage({
|
8131 | sourceName,
|
8132 | targetName,
|
8133 | stream: StreamKind.CLOSE,
|
8134 | streamId
|
8135 | });
|
8136 | delete self.streamSinks[streamId];
|
8137 | },
|
8138 | error(reason) {
|
8139 | (0, _util.assert)(reason instanceof Error, "error must have a valid reason");
|
8140 | if (this.isCancelled) {
|
8141 | return;
|
8142 | }
|
8143 | this.isCancelled = true;
|
8144 | comObj.postMessage({
|
8145 | sourceName,
|
8146 | targetName,
|
8147 | stream: StreamKind.ERROR,
|
8148 | streamId,
|
8149 | reason: wrapReason(reason)
|
8150 | });
|
8151 | },
|
8152 | sinkCapability: new _util.PromiseCapability(),
|
8153 | onPull: null,
|
8154 | onCancel: null,
|
8155 | isCancelled: false,
|
8156 | desiredSize: data.desiredSize,
|
8157 | ready: null
|
8158 | };
|
8159 | streamSink.sinkCapability.resolve();
|
8160 | streamSink.ready = streamSink.sinkCapability.promise;
|
8161 | this.streamSinks[streamId] = streamSink;
|
8162 | new Promise(function (resolve) {
|
8163 | resolve(action(data.data, streamSink));
|
8164 | }).then(function () {
|
8165 | comObj.postMessage({
|
8166 | sourceName,
|
8167 | targetName,
|
8168 | stream: StreamKind.START_COMPLETE,
|
8169 | streamId,
|
8170 | success: true
|
8171 | });
|
8172 | }, function (reason) {
|
8173 | comObj.postMessage({
|
8174 | sourceName,
|
8175 | targetName,
|
8176 | stream: StreamKind.START_COMPLETE,
|
8177 | streamId,
|
8178 | reason: wrapReason(reason)
|
8179 | });
|
8180 | });
|
8181 | }
|
8182 | #processStreamMessage(data) {
|
8183 | const streamId = data.streamId,
|
8184 | sourceName = this.sourceName,
|
8185 | targetName = data.sourceName,
|
8186 | comObj = this.comObj;
|
8187 | const streamController = this.streamControllers[streamId],
|
8188 | streamSink = this.streamSinks[streamId];
|
8189 | switch (data.stream) {
|
8190 | case StreamKind.START_COMPLETE:
|
8191 | if (data.success) {
|
8192 | streamController.startCall.resolve();
|
8193 | } else {
|
8194 | streamController.startCall.reject(wrapReason(data.reason));
|
8195 | }
|
8196 | break;
|
8197 | case StreamKind.PULL_COMPLETE:
|
8198 | if (data.success) {
|
8199 | streamController.pullCall.resolve();
|
8200 | } else {
|
8201 | streamController.pullCall.reject(wrapReason(data.reason));
|
8202 | }
|
8203 | break;
|
8204 | case StreamKind.PULL:
|
8205 | if (!streamSink) {
|
8206 | comObj.postMessage({
|
8207 | sourceName,
|
8208 | targetName,
|
8209 | stream: StreamKind.PULL_COMPLETE,
|
8210 | streamId,
|
8211 | success: true
|
8212 | });
|
8213 | break;
|
8214 | }
|
8215 | if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
|
8216 | streamSink.sinkCapability.resolve();
|
8217 | }
|
8218 | streamSink.desiredSize = data.desiredSize;
|
8219 | new Promise(function (resolve) {
|
8220 | resolve(streamSink.onPull?.());
|
8221 | }).then(function () {
|
8222 | comObj.postMessage({
|
8223 | sourceName,
|
8224 | targetName,
|
8225 | stream: StreamKind.PULL_COMPLETE,
|
8226 | streamId,
|
8227 | success: true
|
8228 | });
|
8229 | }, function (reason) {
|
8230 | comObj.postMessage({
|
8231 | sourceName,
|
8232 | targetName,
|
8233 | stream: StreamKind.PULL_COMPLETE,
|
8234 | streamId,
|
8235 | reason: wrapReason(reason)
|
8236 | });
|
8237 | });
|
8238 | break;
|
8239 | case StreamKind.ENQUEUE:
|
8240 | (0, _util.assert)(streamController, "enqueue should have stream controller");
|
8241 | if (streamController.isClosed) {
|
8242 | break;
|
8243 | }
|
8244 | streamController.controller.enqueue(data.chunk);
|
8245 | break;
|
8246 | case StreamKind.CLOSE:
|
8247 | (0, _util.assert)(streamController, "close should have stream controller");
|
8248 | if (streamController.isClosed) {
|
8249 | break;
|
8250 | }
|
8251 | streamController.isClosed = true;
|
8252 | streamController.controller.close();
|
8253 | this.#deleteStreamController(streamController, streamId);
|
8254 | break;
|
8255 | case StreamKind.ERROR:
|
8256 | (0, _util.assert)(streamController, "error should have stream controller");
|
8257 | streamController.controller.error(wrapReason(data.reason));
|
8258 | this.#deleteStreamController(streamController, streamId);
|
8259 | break;
|
8260 | case StreamKind.CANCEL_COMPLETE:
|
8261 | if (data.success) {
|
8262 | streamController.cancelCall.resolve();
|
8263 | } else {
|
8264 | streamController.cancelCall.reject(wrapReason(data.reason));
|
8265 | }
|
8266 | this.#deleteStreamController(streamController, streamId);
|
8267 | break;
|
8268 | case StreamKind.CANCEL:
|
8269 | if (!streamSink) {
|
8270 | break;
|
8271 | }
|
8272 | new Promise(function (resolve) {
|
8273 | resolve(streamSink.onCancel?.(wrapReason(data.reason)));
|
8274 | }).then(function () {
|
8275 | comObj.postMessage({
|
8276 | sourceName,
|
8277 | targetName,
|
8278 | stream: StreamKind.CANCEL_COMPLETE,
|
8279 | streamId,
|
8280 | success: true
|
8281 | });
|
8282 | }, function (reason) {
|
8283 | comObj.postMessage({
|
8284 | sourceName,
|
8285 | targetName,
|
8286 | stream: StreamKind.CANCEL_COMPLETE,
|
8287 | streamId,
|
8288 | reason: wrapReason(reason)
|
8289 | });
|
8290 | });
|
8291 | streamSink.sinkCapability.reject(wrapReason(data.reason));
|
8292 | streamSink.isCancelled = true;
|
8293 | delete this.streamSinks[streamId];
|
8294 | break;
|
8295 | default:
|
8296 | throw new Error("Unexpected stream case");
|
8297 | }
|
8298 | }
|
8299 | async #deleteStreamController(streamController, streamId) {
|
8300 | await Promise.allSettled([streamController.startCall?.promise, streamController.pullCall?.promise, streamController.cancelCall?.promise]);
|
8301 | delete this.streamControllers[streamId];
|
8302 | }
|
8303 | destroy() {
|
8304 | this.comObj.removeEventListener("message", this._onComObjOnMessage);
|
8305 | }
|
8306 | }
|
8307 | exports.MessageHandler = MessageHandler;
|
8308 |
|
8309 | }),
|
8310 |
|
8311 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
8312 |
|
8313 |
|
8314 |
|
8315 | Object.defineProperty(exports, "__esModule", ({
|
8316 | value: true
|
8317 | }));
|
8318 | exports.Metadata = void 0;
|
8319 | var _util = __w_pdfjs_require__(1);
|
8320 | class Metadata {
|
8321 | #metadataMap;
|
8322 | #data;
|
8323 | constructor({
|
8324 | parsedData,
|
8325 | rawData
|
8326 | }) {
|
8327 | this.#metadataMap = parsedData;
|
8328 | this.#data = rawData;
|
8329 | }
|
8330 | getRaw() {
|
8331 | return this.#data;
|
8332 | }
|
8333 | get(name) {
|
8334 | return this.#metadataMap.get(name) ?? null;
|
8335 | }
|
8336 | getAll() {
|
8337 | return (0, _util.objectFromMap)(this.#metadataMap);
|
8338 | }
|
8339 | has(name) {
|
8340 | return this.#metadataMap.has(name);
|
8341 | }
|
8342 | }
|
8343 | exports.Metadata = Metadata;
|
8344 |
|
8345 | }),
|
8346 |
|
8347 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
8348 |
|
8349 |
|
8350 |
|
8351 | Object.defineProperty(exports, "__esModule", ({
|
8352 | value: true
|
8353 | }));
|
8354 | exports.OptionalContentConfig = void 0;
|
8355 | var _util = __w_pdfjs_require__(1);
|
8356 | var _murmurhash = __w_pdfjs_require__(8);
|
8357 | const INTERNAL = Symbol("INTERNAL");
|
8358 | class OptionalContentGroup {
|
8359 | #visible = true;
|
8360 | constructor(name, intent) {
|
8361 | this.name = name;
|
8362 | this.intent = intent;
|
8363 | }
|
8364 | get visible() {
|
8365 | return this.#visible;
|
8366 | }
|
8367 | _setVisible(internal, visible) {
|
8368 | if (internal !== INTERNAL) {
|
8369 | (0, _util.unreachable)("Internal method `_setVisible` called.");
|
8370 | }
|
8371 | this.#visible = visible;
|
8372 | }
|
8373 | }
|
8374 | class OptionalContentConfig {
|
8375 | #cachedGetHash = null;
|
8376 | #groups = new Map();
|
8377 | #initialHash = null;
|
8378 | #order = null;
|
8379 | constructor(data) {
|
8380 | this.name = null;
|
8381 | this.creator = null;
|
8382 | if (data === null) {
|
8383 | return;
|
8384 | }
|
8385 | this.name = data.name;
|
8386 | this.creator = data.creator;
|
8387 | this.#order = data.order;
|
8388 | for (const group of data.groups) {
|
8389 | this.#groups.set(group.id, new OptionalContentGroup(group.name, group.intent));
|
8390 | }
|
8391 | if (data.baseState === "OFF") {
|
8392 | for (const group of this.#groups.values()) {
|
8393 | group._setVisible(INTERNAL, false);
|
8394 | }
|
8395 | }
|
8396 | for (const on of data.on) {
|
8397 | this.#groups.get(on)._setVisible(INTERNAL, true);
|
8398 | }
|
8399 | for (const off of data.off) {
|
8400 | this.#groups.get(off)._setVisible(INTERNAL, false);
|
8401 | }
|
8402 | this.#initialHash = this.getHash();
|
8403 | }
|
8404 | #evaluateVisibilityExpression(array) {
|
8405 | const length = array.length;
|
8406 | if (length < 2) {
|
8407 | return true;
|
8408 | }
|
8409 | const operator = array[0];
|
8410 | for (let i = 1; i < length; i++) {
|
8411 | const element = array[i];
|
8412 | let state;
|
8413 | if (Array.isArray(element)) {
|
8414 | state = this.#evaluateVisibilityExpression(element);
|
8415 | } else if (this.#groups.has(element)) {
|
8416 | state = this.#groups.get(element).visible;
|
8417 | } else {
|
8418 | (0, _util.warn)(`Optional content group not found: ${element}`);
|
8419 | return true;
|
8420 | }
|
8421 | switch (operator) {
|
8422 | case "And":
|
8423 | if (!state) {
|
8424 | return false;
|
8425 | }
|
8426 | break;
|
8427 | case "Or":
|
8428 | if (state) {
|
8429 | return true;
|
8430 | }
|
8431 | break;
|
8432 | case "Not":
|
8433 | return !state;
|
8434 | default:
|
8435 | return true;
|
8436 | }
|
8437 | }
|
8438 | return operator === "And";
|
8439 | }
|
8440 | isVisible(group) {
|
8441 | if (this.#groups.size === 0) {
|
8442 | return true;
|
8443 | }
|
8444 | if (!group) {
|
8445 | (0, _util.warn)("Optional content group not defined.");
|
8446 | return true;
|
8447 | }
|
8448 | if (group.type === "OCG") {
|
8449 | if (!this.#groups.has(group.id)) {
|
8450 | (0, _util.warn)(`Optional content group not found: ${group.id}`);
|
8451 | return true;
|
8452 | }
|
8453 | return this.#groups.get(group.id).visible;
|
8454 | } else if (group.type === "OCMD") {
|
8455 | if (group.expression) {
|
8456 | return this.#evaluateVisibilityExpression(group.expression);
|
8457 | }
|
8458 | if (!group.policy || group.policy === "AnyOn") {
|
8459 | for (const id of group.ids) {
|
8460 | if (!this.#groups.has(id)) {
|
8461 | (0, _util.warn)(`Optional content group not found: ${id}`);
|
8462 | return true;
|
8463 | }
|
8464 | if (this.#groups.get(id).visible) {
|
8465 | return true;
|
8466 | }
|
8467 | }
|
8468 | return false;
|
8469 | } else if (group.policy === "AllOn") {
|
8470 | for (const id of group.ids) {
|
8471 | if (!this.#groups.has(id)) {
|
8472 | (0, _util.warn)(`Optional content group not found: ${id}`);
|
8473 | return true;
|
8474 | }
|
8475 | if (!this.#groups.get(id).visible) {
|
8476 | return false;
|
8477 | }
|
8478 | }
|
8479 | return true;
|
8480 | } else if (group.policy === "AnyOff") {
|
8481 | for (const id of group.ids) {
|
8482 | if (!this.#groups.has(id)) {
|
8483 | (0, _util.warn)(`Optional content group not found: ${id}`);
|
8484 | return true;
|
8485 | }
|
8486 | if (!this.#groups.get(id).visible) {
|
8487 | return true;
|
8488 | }
|
8489 | }
|
8490 | return false;
|
8491 | } else if (group.policy === "AllOff") {
|
8492 | for (const id of group.ids) {
|
8493 | if (!this.#groups.has(id)) {
|
8494 | (0, _util.warn)(`Optional content group not found: ${id}`);
|
8495 | return true;
|
8496 | }
|
8497 | if (this.#groups.get(id).visible) {
|
8498 | return false;
|
8499 | }
|
8500 | }
|
8501 | return true;
|
8502 | }
|
8503 | (0, _util.warn)(`Unknown optional content policy ${group.policy}.`);
|
8504 | return true;
|
8505 | }
|
8506 | (0, _util.warn)(`Unknown group type ${group.type}.`);
|
8507 | return true;
|
8508 | }
|
8509 | setVisibility(id, visible = true) {
|
8510 | if (!this.#groups.has(id)) {
|
8511 | (0, _util.warn)(`Optional content group not found: ${id}`);
|
8512 | return;
|
8513 | }
|
8514 | this.#groups.get(id)._setVisible(INTERNAL, !!visible);
|
8515 | this.#cachedGetHash = null;
|
8516 | }
|
8517 | get hasInitialVisibility() {
|
8518 | return this.getHash() === this.#initialHash;
|
8519 | }
|
8520 | getOrder() {
|
8521 | if (!this.#groups.size) {
|
8522 | return null;
|
8523 | }
|
8524 | if (this.#order) {
|
8525 | return this.#order.slice();
|
8526 | }
|
8527 | return [...this.#groups.keys()];
|
8528 | }
|
8529 | getGroups() {
|
8530 | return this.#groups.size > 0 ? (0, _util.objectFromMap)(this.#groups) : null;
|
8531 | }
|
8532 | getGroup(id) {
|
8533 | return this.#groups.get(id) || null;
|
8534 | }
|
8535 | getHash() {
|
8536 | if (this.#cachedGetHash !== null) {
|
8537 | return this.#cachedGetHash;
|
8538 | }
|
8539 | const hash = new _murmurhash.MurmurHash3_64();
|
8540 | for (const [id, group] of this.#groups) {
|
8541 | hash.update(`${id}:${group.visible}`);
|
8542 | }
|
8543 | return this.#cachedGetHash = hash.hexdigest();
|
8544 | }
|
8545 | }
|
8546 | exports.OptionalContentConfig = OptionalContentConfig;
|
8547 |
|
8548 | }),
|
8549 |
|
8550 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
8551 |
|
8552 |
|
8553 |
|
8554 | Object.defineProperty(exports, "__esModule", ({
|
8555 | value: true
|
8556 | }));
|
8557 | exports.PDFDataTransportStream = void 0;
|
8558 | var _util = __w_pdfjs_require__(1);
|
8559 | var _display_utils = __w_pdfjs_require__(6);
|
8560 | class PDFDataTransportStream {
|
8561 | constructor({
|
8562 | length,
|
8563 | initialData,
|
8564 | progressiveDone = false,
|
8565 | contentDispositionFilename = null,
|
8566 | disableRange = false,
|
8567 | disableStream = false
|
8568 | }, pdfDataRangeTransport) {
|
8569 | (0, _util.assert)(pdfDataRangeTransport, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
|
8570 | this._queuedChunks = [];
|
8571 | this._progressiveDone = progressiveDone;
|
8572 | this._contentDispositionFilename = contentDispositionFilename;
|
8573 | if (initialData?.length > 0) {
|
8574 | const buffer = initialData instanceof Uint8Array && initialData.byteLength === initialData.buffer.byteLength ? initialData.buffer : new Uint8Array(initialData).buffer;
|
8575 | this._queuedChunks.push(buffer);
|
8576 | }
|
8577 | this._pdfDataRangeTransport = pdfDataRangeTransport;
|
8578 | this._isStreamingSupported = !disableStream;
|
8579 | this._isRangeSupported = !disableRange;
|
8580 | this._contentLength = length;
|
8581 | this._fullRequestReader = null;
|
8582 | this._rangeReaders = [];
|
8583 | this._pdfDataRangeTransport.addRangeListener((begin, chunk) => {
|
8584 | this._onReceiveData({
|
8585 | begin,
|
8586 | chunk
|
8587 | });
|
8588 | });
|
8589 | this._pdfDataRangeTransport.addProgressListener((loaded, total) => {
|
8590 | this._onProgress({
|
8591 | loaded,
|
8592 | total
|
8593 | });
|
8594 | });
|
8595 | this._pdfDataRangeTransport.addProgressiveReadListener(chunk => {
|
8596 | this._onReceiveData({
|
8597 | chunk
|
8598 | });
|
8599 | });
|
8600 | this._pdfDataRangeTransport.addProgressiveDoneListener(() => {
|
8601 | this._onProgressiveDone();
|
8602 | });
|
8603 | this._pdfDataRangeTransport.transportReady();
|
8604 | }
|
8605 | _onReceiveData({
|
8606 | begin,
|
8607 | chunk
|
8608 | }) {
|
8609 | const buffer = chunk instanceof Uint8Array && chunk.byteLength === chunk.buffer.byteLength ? chunk.buffer : new Uint8Array(chunk).buffer;
|
8610 | if (begin === undefined) {
|
8611 | if (this._fullRequestReader) {
|
8612 | this._fullRequestReader._enqueue(buffer);
|
8613 | } else {
|
8614 | this._queuedChunks.push(buffer);
|
8615 | }
|
8616 | } else {
|
8617 | const found = this._rangeReaders.some(function (rangeReader) {
|
8618 | if (rangeReader._begin !== begin) {
|
8619 | return false;
|
8620 | }
|
8621 | rangeReader._enqueue(buffer);
|
8622 | return true;
|
8623 | });
|
8624 | (0, _util.assert)(found, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
|
8625 | }
|
8626 | }
|
8627 | get _progressiveDataLength() {
|
8628 | return this._fullRequestReader?._loaded ?? 0;
|
8629 | }
|
8630 | _onProgress(evt) {
|
8631 | if (evt.total === undefined) {
|
8632 | this._rangeReaders[0]?.onProgress?.({
|
8633 | loaded: evt.loaded
|
8634 | });
|
8635 | } else {
|
8636 | this._fullRequestReader?.onProgress?.({
|
8637 | loaded: evt.loaded,
|
8638 | total: evt.total
|
8639 | });
|
8640 | }
|
8641 | }
|
8642 | _onProgressiveDone() {
|
8643 | this._fullRequestReader?.progressiveDone();
|
8644 | this._progressiveDone = true;
|
8645 | }
|
8646 | _removeRangeReader(reader) {
|
8647 | const i = this._rangeReaders.indexOf(reader);
|
8648 | if (i >= 0) {
|
8649 | this._rangeReaders.splice(i, 1);
|
8650 | }
|
8651 | }
|
8652 | getFullReader() {
|
8653 | (0, _util.assert)(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
|
8654 | const queuedChunks = this._queuedChunks;
|
8655 | this._queuedChunks = null;
|
8656 | return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone, this._contentDispositionFilename);
|
8657 | }
|
8658 | getRangeReader(begin, end) {
|
8659 | if (end <= this._progressiveDataLength) {
|
8660 | return null;
|
8661 | }
|
8662 | const reader = new PDFDataTransportStreamRangeReader(this, begin, end);
|
8663 | this._pdfDataRangeTransport.requestDataRange(begin, end);
|
8664 | this._rangeReaders.push(reader);
|
8665 | return reader;
|
8666 | }
|
8667 | cancelAllRequests(reason) {
|
8668 | this._fullRequestReader?.cancel(reason);
|
8669 | for (const reader of this._rangeReaders.slice(0)) {
|
8670 | reader.cancel(reason);
|
8671 | }
|
8672 | this._pdfDataRangeTransport.abort();
|
8673 | }
|
8674 | }
|
8675 | exports.PDFDataTransportStream = PDFDataTransportStream;
|
8676 | class PDFDataTransportStreamReader {
|
8677 | constructor(stream, queuedChunks, progressiveDone = false, contentDispositionFilename = null) {
|
8678 | this._stream = stream;
|
8679 | this._done = progressiveDone || false;
|
8680 | this._filename = (0, _display_utils.isPdfFile)(contentDispositionFilename) ? contentDispositionFilename : null;
|
8681 | this._queuedChunks = queuedChunks || [];
|
8682 | this._loaded = 0;
|
8683 | for (const chunk of this._queuedChunks) {
|
8684 | this._loaded += chunk.byteLength;
|
8685 | }
|
8686 | this._requests = [];
|
8687 | this._headersReady = Promise.resolve();
|
8688 | stream._fullRequestReader = this;
|
8689 | this.onProgress = null;
|
8690 | }
|
8691 | _enqueue(chunk) {
|
8692 | if (this._done) {
|
8693 | return;
|
8694 | }
|
8695 | if (this._requests.length > 0) {
|
8696 | const requestCapability = this._requests.shift();
|
8697 | requestCapability.resolve({
|
8698 | value: chunk,
|
8699 | done: false
|
8700 | });
|
8701 | } else {
|
8702 | this._queuedChunks.push(chunk);
|
8703 | }
|
8704 | this._loaded += chunk.byteLength;
|
8705 | }
|
8706 | get headersReady() {
|
8707 | return this._headersReady;
|
8708 | }
|
8709 | get filename() {
|
8710 | return this._filename;
|
8711 | }
|
8712 | get isRangeSupported() {
|
8713 | return this._stream._isRangeSupported;
|
8714 | }
|
8715 | get isStreamingSupported() {
|
8716 | return this._stream._isStreamingSupported;
|
8717 | }
|
8718 | get contentLength() {
|
8719 | return this._stream._contentLength;
|
8720 | }
|
8721 | async read() {
|
8722 | if (this._queuedChunks.length > 0) {
|
8723 | const chunk = this._queuedChunks.shift();
|
8724 | return {
|
8725 | value: chunk,
|
8726 | done: false
|
8727 | };
|
8728 | }
|
8729 | if (this._done) {
|
8730 | return {
|
8731 | value: undefined,
|
8732 | done: true
|
8733 | };
|
8734 | }
|
8735 | const requestCapability = new _util.PromiseCapability();
|
8736 | this._requests.push(requestCapability);
|
8737 | return requestCapability.promise;
|
8738 | }
|
8739 | cancel(reason) {
|
8740 | this._done = true;
|
8741 | for (const requestCapability of this._requests) {
|
8742 | requestCapability.resolve({
|
8743 | value: undefined,
|
8744 | done: true
|
8745 | });
|
8746 | }
|
8747 | this._requests.length = 0;
|
8748 | }
|
8749 | progressiveDone() {
|
8750 | if (this._done) {
|
8751 | return;
|
8752 | }
|
8753 | this._done = true;
|
8754 | }
|
8755 | }
|
8756 | class PDFDataTransportStreamRangeReader {
|
8757 | constructor(stream, begin, end) {
|
8758 | this._stream = stream;
|
8759 | this._begin = begin;
|
8760 | this._end = end;
|
8761 | this._queuedChunk = null;
|
8762 | this._requests = [];
|
8763 | this._done = false;
|
8764 | this.onProgress = null;
|
8765 | }
|
8766 | _enqueue(chunk) {
|
8767 | if (this._done) {
|
8768 | return;
|
8769 | }
|
8770 | if (this._requests.length === 0) {
|
8771 | this._queuedChunk = chunk;
|
8772 | } else {
|
8773 | const requestsCapability = this._requests.shift();
|
8774 | requestsCapability.resolve({
|
8775 | value: chunk,
|
8776 | done: false
|
8777 | });
|
8778 | for (const requestCapability of this._requests) {
|
8779 | requestCapability.resolve({
|
8780 | value: undefined,
|
8781 | done: true
|
8782 | });
|
8783 | }
|
8784 | this._requests.length = 0;
|
8785 | }
|
8786 | this._done = true;
|
8787 | this._stream._removeRangeReader(this);
|
8788 | }
|
8789 | get isStreamingSupported() {
|
8790 | return false;
|
8791 | }
|
8792 | async read() {
|
8793 | if (this._queuedChunk) {
|
8794 | const chunk = this._queuedChunk;
|
8795 | this._queuedChunk = null;
|
8796 | return {
|
8797 | value: chunk,
|
8798 | done: false
|
8799 | };
|
8800 | }
|
8801 | if (this._done) {
|
8802 | return {
|
8803 | value: undefined,
|
8804 | done: true
|
8805 | };
|
8806 | }
|
8807 | const requestCapability = new _util.PromiseCapability();
|
8808 | this._requests.push(requestCapability);
|
8809 | return requestCapability.promise;
|
8810 | }
|
8811 | cancel(reason) {
|
8812 | this._done = true;
|
8813 | for (const requestCapability of this._requests) {
|
8814 | requestCapability.resolve({
|
8815 | value: undefined,
|
8816 | done: true
|
8817 | });
|
8818 | }
|
8819 | this._requests.length = 0;
|
8820 | this._stream._removeRangeReader(this);
|
8821 | }
|
8822 | }
|
8823 |
|
8824 | }),
|
8825 |
|
8826 | ((__unused_webpack_module, exports) => {
|
8827 |
|
8828 |
|
8829 |
|
8830 | Object.defineProperty(exports, "__esModule", ({
|
8831 | value: true
|
8832 | }));
|
8833 | exports.XfaText = void 0;
|
8834 | class XfaText {
|
8835 | static textContent(xfa) {
|
8836 | const items = [];
|
8837 | const output = {
|
8838 | items,
|
8839 | styles: Object.create(null)
|
8840 | };
|
8841 | function walk(node) {
|
8842 | if (!node) {
|
8843 | return;
|
8844 | }
|
8845 | let str = null;
|
8846 | const name = node.name;
|
8847 | if (name === "#text") {
|
8848 | str = node.value;
|
8849 | } else if (!XfaText.shouldBuildText(name)) {
|
8850 | return;
|
8851 | } else if (node?.attributes?.textContent) {
|
8852 | str = node.attributes.textContent;
|
8853 | } else if (node.value) {
|
8854 | str = node.value;
|
8855 | }
|
8856 | if (str !== null) {
|
8857 | items.push({
|
8858 | str
|
8859 | });
|
8860 | }
|
8861 | if (!node.children) {
|
8862 | return;
|
8863 | }
|
8864 | for (const child of node.children) {
|
8865 | walk(child);
|
8866 | }
|
8867 | }
|
8868 | walk(xfa);
|
8869 | return output;
|
8870 | }
|
8871 | static shouldBuildText(name) {
|
8872 | return !(name === "textarea" || name === "input" || name === "option" || name === "select");
|
8873 | }
|
8874 | }
|
8875 | exports.XfaText = XfaText;
|
8876 |
|
8877 | }),
|
8878 |
|
8879 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
8880 |
|
8881 |
|
8882 |
|
8883 | Object.defineProperty(exports, "__esModule", ({
|
8884 | value: true
|
8885 | }));
|
8886 | exports.NodeStandardFontDataFactory = exports.NodeFilterFactory = exports.NodeCanvasFactory = exports.NodeCMapReaderFactory = void 0;
|
8887 | var _base_factory = __w_pdfjs_require__(7);
|
8888 | ;
|
8889 | const fetchData = function (url) {
|
8890 | return new Promise((resolve, reject) => {
|
8891 | const fs = require("fs");
|
8892 | fs.readFile(url, (error, data) => {
|
8893 | if (error || !data) {
|
8894 | reject(new Error(error));
|
8895 | return;
|
8896 | }
|
8897 | resolve(new Uint8Array(data));
|
8898 | });
|
8899 | });
|
8900 | };
|
8901 | class NodeFilterFactory extends _base_factory.BaseFilterFactory {}
|
8902 | exports.NodeFilterFactory = NodeFilterFactory;
|
8903 | class NodeCanvasFactory extends _base_factory.BaseCanvasFactory {
|
8904 | _createCanvas(width, height) {
|
8905 | const Canvas = require("canvas");
|
8906 | return Canvas.createCanvas(width, height);
|
8907 | }
|
8908 | }
|
8909 | exports.NodeCanvasFactory = NodeCanvasFactory;
|
8910 | class NodeCMapReaderFactory extends _base_factory.BaseCMapReaderFactory {
|
8911 | _fetchData(url, compressionType) {
|
8912 | return fetchData(url).then(data => {
|
8913 | return {
|
8914 | cMapData: data,
|
8915 | compressionType
|
8916 | };
|
8917 | });
|
8918 | }
|
8919 | }
|
8920 | exports.NodeCMapReaderFactory = NodeCMapReaderFactory;
|
8921 | class NodeStandardFontDataFactory extends _base_factory.BaseStandardFontDataFactory {
|
8922 | _fetchData(url) {
|
8923 | return fetchData(url);
|
8924 | }
|
8925 | }
|
8926 | exports.NodeStandardFontDataFactory = NodeStandardFontDataFactory;
|
8927 |
|
8928 | }),
|
8929 |
|
8930 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
8931 |
|
8932 |
|
8933 |
|
8934 | Object.defineProperty(exports, "__esModule", ({
|
8935 | value: true
|
8936 | }));
|
8937 | exports.PDFNodeStream = void 0;
|
8938 | var _util = __w_pdfjs_require__(1);
|
8939 | var _network_utils = __w_pdfjs_require__(22);
|
8940 | ;
|
8941 | const fs = require("fs");
|
8942 | const http = require("http");
|
8943 | const https = require("https");
|
8944 | const url = require("url");
|
8945 | const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
|
8946 | function parseUrl(sourceUrl) {
|
8947 | const parsedUrl = url.parse(sourceUrl);
|
8948 | if (parsedUrl.protocol === "file:" || parsedUrl.host) {
|
8949 | return parsedUrl;
|
8950 | }
|
8951 | if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
|
8952 | return url.parse(`file:///${sourceUrl}`);
|
8953 | }
|
8954 | if (!parsedUrl.host) {
|
8955 | parsedUrl.protocol = "file:";
|
8956 | }
|
8957 | return parsedUrl;
|
8958 | }
|
8959 | class PDFNodeStream {
|
8960 | constructor(source) {
|
8961 | this.source = source;
|
8962 | this.url = parseUrl(source.url);
|
8963 | this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
|
8964 | this.isFsUrl = this.url.protocol === "file:";
|
8965 | this.httpHeaders = this.isHttp && source.httpHeaders || {};
|
8966 | this._fullRequestReader = null;
|
8967 | this._rangeRequestReaders = [];
|
8968 | }
|
8969 | get _progressiveDataLength() {
|
8970 | return this._fullRequestReader?._loaded ?? 0;
|
8971 | }
|
8972 | getFullReader() {
|
8973 | (0, _util.assert)(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
|
8974 | this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
|
8975 | return this._fullRequestReader;
|
8976 | }
|
8977 | getRangeReader(start, end) {
|
8978 | if (end <= this._progressiveDataLength) {
|
8979 | return null;
|
8980 | }
|
8981 | const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
|
8982 | this._rangeRequestReaders.push(rangeReader);
|
8983 | return rangeReader;
|
8984 | }
|
8985 | cancelAllRequests(reason) {
|
8986 | this._fullRequestReader?.cancel(reason);
|
8987 | for (const reader of this._rangeRequestReaders.slice(0)) {
|
8988 | reader.cancel(reason);
|
8989 | }
|
8990 | }
|
8991 | }
|
8992 | exports.PDFNodeStream = PDFNodeStream;
|
8993 | class BaseFullReader {
|
8994 | constructor(stream) {
|
8995 | this._url = stream.url;
|
8996 | this._done = false;
|
8997 | this._storedError = null;
|
8998 | this.onProgress = null;
|
8999 | const source = stream.source;
|
9000 | this._contentLength = source.length;
|
9001 | this._loaded = 0;
|
9002 | this._filename = null;
|
9003 | this._disableRange = source.disableRange || false;
|
9004 | this._rangeChunkSize = source.rangeChunkSize;
|
9005 | if (!this._rangeChunkSize && !this._disableRange) {
|
9006 | this._disableRange = true;
|
9007 | }
|
9008 | this._isStreamingSupported = !source.disableStream;
|
9009 | this._isRangeSupported = !source.disableRange;
|
9010 | this._readableStream = null;
|
9011 | this._readCapability = new _util.PromiseCapability();
|
9012 | this._headersCapability = new _util.PromiseCapability();
|
9013 | }
|
9014 | get headersReady() {
|
9015 | return this._headersCapability.promise;
|
9016 | }
|
9017 | get filename() {
|
9018 | return this._filename;
|
9019 | }
|
9020 | get contentLength() {
|
9021 | return this._contentLength;
|
9022 | }
|
9023 | get isRangeSupported() {
|
9024 | return this._isRangeSupported;
|
9025 | }
|
9026 | get isStreamingSupported() {
|
9027 | return this._isStreamingSupported;
|
9028 | }
|
9029 | async read() {
|
9030 | await this._readCapability.promise;
|
9031 | if (this._done) {
|
9032 | return {
|
9033 | value: undefined,
|
9034 | done: true
|
9035 | };
|
9036 | }
|
9037 | if (this._storedError) {
|
9038 | throw this._storedError;
|
9039 | }
|
9040 | const chunk = this._readableStream.read();
|
9041 | if (chunk === null) {
|
9042 | this._readCapability = new _util.PromiseCapability();
|
9043 | return this.read();
|
9044 | }
|
9045 | this._loaded += chunk.length;
|
9046 | this.onProgress?.({
|
9047 | loaded: this._loaded,
|
9048 | total: this._contentLength
|
9049 | });
|
9050 | const buffer = new Uint8Array(chunk).buffer;
|
9051 | return {
|
9052 | value: buffer,
|
9053 | done: false
|
9054 | };
|
9055 | }
|
9056 | cancel(reason) {
|
9057 | if (!this._readableStream) {
|
9058 | this._error(reason);
|
9059 | return;
|
9060 | }
|
9061 | this._readableStream.destroy(reason);
|
9062 | }
|
9063 | _error(reason) {
|
9064 | this._storedError = reason;
|
9065 | this._readCapability.resolve();
|
9066 | }
|
9067 | _setReadableStream(readableStream) {
|
9068 | this._readableStream = readableStream;
|
9069 | readableStream.on("readable", () => {
|
9070 | this._readCapability.resolve();
|
9071 | });
|
9072 | readableStream.on("end", () => {
|
9073 | readableStream.destroy();
|
9074 | this._done = true;
|
9075 | this._readCapability.resolve();
|
9076 | });
|
9077 | readableStream.on("error", reason => {
|
9078 | this._error(reason);
|
9079 | });
|
9080 | if (!this._isStreamingSupported && this._isRangeSupported) {
|
9081 | this._error(new _util.AbortException("streaming is disabled"));
|
9082 | }
|
9083 | if (this._storedError) {
|
9084 | this._readableStream.destroy(this._storedError);
|
9085 | }
|
9086 | }
|
9087 | }
|
9088 | class BaseRangeReader {
|
9089 | constructor(stream) {
|
9090 | this._url = stream.url;
|
9091 | this._done = false;
|
9092 | this._storedError = null;
|
9093 | this.onProgress = null;
|
9094 | this._loaded = 0;
|
9095 | this._readableStream = null;
|
9096 | this._readCapability = new _util.PromiseCapability();
|
9097 | const source = stream.source;
|
9098 | this._isStreamingSupported = !source.disableStream;
|
9099 | }
|
9100 | get isStreamingSupported() {
|
9101 | return this._isStreamingSupported;
|
9102 | }
|
9103 | async read() {
|
9104 | await this._readCapability.promise;
|
9105 | if (this._done) {
|
9106 | return {
|
9107 | value: undefined,
|
9108 | done: true
|
9109 | };
|
9110 | }
|
9111 | if (this._storedError) {
|
9112 | throw this._storedError;
|
9113 | }
|
9114 | const chunk = this._readableStream.read();
|
9115 | if (chunk === null) {
|
9116 | this._readCapability = new _util.PromiseCapability();
|
9117 | return this.read();
|
9118 | }
|
9119 | this._loaded += chunk.length;
|
9120 | this.onProgress?.({
|
9121 | loaded: this._loaded
|
9122 | });
|
9123 | const buffer = new Uint8Array(chunk).buffer;
|
9124 | return {
|
9125 | value: buffer,
|
9126 | done: false
|
9127 | };
|
9128 | }
|
9129 | cancel(reason) {
|
9130 | if (!this._readableStream) {
|
9131 | this._error(reason);
|
9132 | return;
|
9133 | }
|
9134 | this._readableStream.destroy(reason);
|
9135 | }
|
9136 | _error(reason) {
|
9137 | this._storedError = reason;
|
9138 | this._readCapability.resolve();
|
9139 | }
|
9140 | _setReadableStream(readableStream) {
|
9141 | this._readableStream = readableStream;
|
9142 | readableStream.on("readable", () => {
|
9143 | this._readCapability.resolve();
|
9144 | });
|
9145 | readableStream.on("end", () => {
|
9146 | readableStream.destroy();
|
9147 | this._done = true;
|
9148 | this._readCapability.resolve();
|
9149 | });
|
9150 | readableStream.on("error", reason => {
|
9151 | this._error(reason);
|
9152 | });
|
9153 | if (this._storedError) {
|
9154 | this._readableStream.destroy(this._storedError);
|
9155 | }
|
9156 | }
|
9157 | }
|
9158 | function createRequestOptions(parsedUrl, headers) {
|
9159 | return {
|
9160 | protocol: parsedUrl.protocol,
|
9161 | auth: parsedUrl.auth,
|
9162 | host: parsedUrl.hostname,
|
9163 | port: parsedUrl.port,
|
9164 | path: parsedUrl.path,
|
9165 | method: "GET",
|
9166 | headers
|
9167 | };
|
9168 | }
|
9169 | class PDFNodeStreamFullReader extends BaseFullReader {
|
9170 | constructor(stream) {
|
9171 | super(stream);
|
9172 | const handleResponse = response => {
|
9173 | if (response.statusCode === 404) {
|
9174 | const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
|
9175 | this._storedError = error;
|
9176 | this._headersCapability.reject(error);
|
9177 | return;
|
9178 | }
|
9179 | this._headersCapability.resolve();
|
9180 | this._setReadableStream(response);
|
9181 | const getResponseHeader = name => {
|
9182 | return this._readableStream.headers[name.toLowerCase()];
|
9183 | };
|
9184 | const {
|
9185 | allowRangeRequests,
|
9186 | suggestedLength
|
9187 | } = (0, _network_utils.validateRangeRequestCapabilities)({
|
9188 | getResponseHeader,
|
9189 | isHttp: stream.isHttp,
|
9190 | rangeChunkSize: this._rangeChunkSize,
|
9191 | disableRange: this._disableRange
|
9192 | });
|
9193 | this._isRangeSupported = allowRangeRequests;
|
9194 | this._contentLength = suggestedLength || this._contentLength;
|
9195 | this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
|
9196 | };
|
9197 | this._request = null;
|
9198 | if (this._url.protocol === "http:") {
|
9199 | this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
|
9200 | } else {
|
9201 | this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
|
9202 | }
|
9203 | this._request.on("error", reason => {
|
9204 | this._storedError = reason;
|
9205 | this._headersCapability.reject(reason);
|
9206 | });
|
9207 | this._request.end();
|
9208 | }
|
9209 | }
|
9210 | class PDFNodeStreamRangeReader extends BaseRangeReader {
|
9211 | constructor(stream, start, end) {
|
9212 | super(stream);
|
9213 | this._httpHeaders = {};
|
9214 | for (const property in stream.httpHeaders) {
|
9215 | const value = stream.httpHeaders[property];
|
9216 | if (value === undefined) {
|
9217 | continue;
|
9218 | }
|
9219 | this._httpHeaders[property] = value;
|
9220 | }
|
9221 | this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
|
9222 | const handleResponse = response => {
|
9223 | if (response.statusCode === 404) {
|
9224 | const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
|
9225 | this._storedError = error;
|
9226 | return;
|
9227 | }
|
9228 | this._setReadableStream(response);
|
9229 | };
|
9230 | this._request = null;
|
9231 | if (this._url.protocol === "http:") {
|
9232 | this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
|
9233 | } else {
|
9234 | this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
|
9235 | }
|
9236 | this._request.on("error", reason => {
|
9237 | this._storedError = reason;
|
9238 | });
|
9239 | this._request.end();
|
9240 | }
|
9241 | }
|
9242 | class PDFNodeStreamFsFullReader extends BaseFullReader {
|
9243 | constructor(stream) {
|
9244 | super(stream);
|
9245 | let path = decodeURIComponent(this._url.path);
|
9246 | if (fileUriRegex.test(this._url.href)) {
|
9247 | path = path.replace(/^\//, "");
|
9248 | }
|
9249 | fs.lstat(path, (error, stat) => {
|
9250 | if (error) {
|
9251 | if (error.code === "ENOENT") {
|
9252 | error = new _util.MissingPDFException(`Missing PDF "${path}".`);
|
9253 | }
|
9254 | this._storedError = error;
|
9255 | this._headersCapability.reject(error);
|
9256 | return;
|
9257 | }
|
9258 | this._contentLength = stat.size;
|
9259 | this._setReadableStream(fs.createReadStream(path));
|
9260 | this._headersCapability.resolve();
|
9261 | });
|
9262 | }
|
9263 | }
|
9264 | class PDFNodeStreamFsRangeReader extends BaseRangeReader {
|
9265 | constructor(stream, start, end) {
|
9266 | super(stream);
|
9267 | let path = decodeURIComponent(this._url.path);
|
9268 | if (fileUriRegex.test(this._url.href)) {
|
9269 | path = path.replace(/^\//, "");
|
9270 | }
|
9271 | this._setReadableStream(fs.createReadStream(path, {
|
9272 | start,
|
9273 | end: end - 1
|
9274 | }));
|
9275 | }
|
9276 | }
|
9277 |
|
9278 | }),
|
9279 |
|
9280 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
9281 |
|
9282 |
|
9283 |
|
9284 | Object.defineProperty(exports, "__esModule", ({
|
9285 | value: true
|
9286 | }));
|
9287 | exports.createResponseStatusError = createResponseStatusError;
|
9288 | exports.extractFilenameFromHeader = extractFilenameFromHeader;
|
9289 | exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;
|
9290 | exports.validateResponseStatus = validateResponseStatus;
|
9291 | var _util = __w_pdfjs_require__(1);
|
9292 | var _content_disposition = __w_pdfjs_require__(23);
|
9293 | var _display_utils = __w_pdfjs_require__(6);
|
9294 | function validateRangeRequestCapabilities({
|
9295 | getResponseHeader,
|
9296 | isHttp,
|
9297 | rangeChunkSize,
|
9298 | disableRange
|
9299 | }) {
|
9300 | const returnValues = {
|
9301 | allowRangeRequests: false,
|
9302 | suggestedLength: undefined
|
9303 | };
|
9304 | const length = parseInt(getResponseHeader("Content-Length"), 10);
|
9305 | if (!Number.isInteger(length)) {
|
9306 | return returnValues;
|
9307 | }
|
9308 | returnValues.suggestedLength = length;
|
9309 | if (length <= 2 * rangeChunkSize) {
|
9310 | return returnValues;
|
9311 | }
|
9312 | if (disableRange || !isHttp) {
|
9313 | return returnValues;
|
9314 | }
|
9315 | if (getResponseHeader("Accept-Ranges") !== "bytes") {
|
9316 | return returnValues;
|
9317 | }
|
9318 | const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
|
9319 | if (contentEncoding !== "identity") {
|
9320 | return returnValues;
|
9321 | }
|
9322 | returnValues.allowRangeRequests = true;
|
9323 | return returnValues;
|
9324 | }
|
9325 | function extractFilenameFromHeader(getResponseHeader) {
|
9326 | const contentDisposition = getResponseHeader("Content-Disposition");
|
9327 | if (contentDisposition) {
|
9328 | let filename = (0, _content_disposition.getFilenameFromContentDispositionHeader)(contentDisposition);
|
9329 | if (filename.includes("%")) {
|
9330 | try {
|
9331 | filename = decodeURIComponent(filename);
|
9332 | } catch (ex) {}
|
9333 | }
|
9334 | if ((0, _display_utils.isPdfFile)(filename)) {
|
9335 | return filename;
|
9336 | }
|
9337 | }
|
9338 | return null;
|
9339 | }
|
9340 | function createResponseStatusError(status, url) {
|
9341 | if (status === 404 || status === 0 && url.startsWith("file:")) {
|
9342 | return new _util.MissingPDFException('Missing PDF "' + url + '".');
|
9343 | }
|
9344 | return new _util.UnexpectedResponseException(`Unexpected server response (${status}) while retrieving PDF "${url}".`, status);
|
9345 | }
|
9346 | function validateResponseStatus(status) {
|
9347 | return status === 200 || status === 206;
|
9348 | }
|
9349 |
|
9350 | }),
|
9351 |
|
9352 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
9353 |
|
9354 |
|
9355 |
|
9356 | Object.defineProperty(exports, "__esModule", ({
|
9357 | value: true
|
9358 | }));
|
9359 | exports.getFilenameFromContentDispositionHeader = getFilenameFromContentDispositionHeader;
|
9360 | var _util = __w_pdfjs_require__(1);
|
9361 | function getFilenameFromContentDispositionHeader(contentDisposition) {
|
9362 | let needsEncodingFixup = true;
|
9363 | let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
|
9364 | if (tmp) {
|
9365 | tmp = tmp[1];
|
9366 | let filename = rfc2616unquote(tmp);
|
9367 | filename = unescape(filename);
|
9368 | filename = rfc5987decode(filename);
|
9369 | filename = rfc2047decode(filename);
|
9370 | return fixupEncoding(filename);
|
9371 | }
|
9372 | tmp = rfc2231getparam(contentDisposition);
|
9373 | if (tmp) {
|
9374 | const filename = rfc2047decode(tmp);
|
9375 | return fixupEncoding(filename);
|
9376 | }
|
9377 | tmp = toParamRegExp("filename", "i").exec(contentDisposition);
|
9378 | if (tmp) {
|
9379 | tmp = tmp[1];
|
9380 | let filename = rfc2616unquote(tmp);
|
9381 | filename = rfc2047decode(filename);
|
9382 | return fixupEncoding(filename);
|
9383 | }
|
9384 | function toParamRegExp(attributePattern, flags) {
|
9385 | return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
|
9386 | }
|
9387 | function textdecode(encoding, value) {
|
9388 | if (encoding) {
|
9389 | if (!/^[\x00-\xFF]+$/.test(value)) {
|
9390 | return value;
|
9391 | }
|
9392 | try {
|
9393 | const decoder = new TextDecoder(encoding, {
|
9394 | fatal: true
|
9395 | });
|
9396 | const buffer = (0, _util.stringToBytes)(value);
|
9397 | value = decoder.decode(buffer);
|
9398 | needsEncodingFixup = false;
|
9399 | } catch (e) {}
|
9400 | }
|
9401 | return value;
|
9402 | }
|
9403 | function fixupEncoding(value) {
|
9404 | if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
|
9405 | value = textdecode("utf-8", value);
|
9406 | if (needsEncodingFixup) {
|
9407 | value = textdecode("iso-8859-1", value);
|
9408 | }
|
9409 | }
|
9410 | return value;
|
9411 | }
|
9412 | function rfc2231getparam(contentDispositionStr) {
|
9413 | const matches = [];
|
9414 | let match;
|
9415 | const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
|
9416 | while ((match = iter.exec(contentDispositionStr)) !== null) {
|
9417 | let [, n, quot, part] = match;
|
9418 | n = parseInt(n, 10);
|
9419 | if (n in matches) {
|
9420 | if (n === 0) {
|
9421 | break;
|
9422 | }
|
9423 | continue;
|
9424 | }
|
9425 | matches[n] = [quot, part];
|
9426 | }
|
9427 | const parts = [];
|
9428 | for (let n = 0; n < matches.length; ++n) {
|
9429 | if (!(n in matches)) {
|
9430 | break;
|
9431 | }
|
9432 | let [quot, part] = matches[n];
|
9433 | part = rfc2616unquote(part);
|
9434 | if (quot) {
|
9435 | part = unescape(part);
|
9436 | if (n === 0) {
|
9437 | part = rfc5987decode(part);
|
9438 | }
|
9439 | }
|
9440 | parts.push(part);
|
9441 | }
|
9442 | return parts.join("");
|
9443 | }
|
9444 | function rfc2616unquote(value) {
|
9445 | if (value.startsWith('"')) {
|
9446 | const parts = value.slice(1).split('\\"');
|
9447 | for (let i = 0; i < parts.length; ++i) {
|
9448 | const quotindex = parts[i].indexOf('"');
|
9449 | if (quotindex !== -1) {
|
9450 | parts[i] = parts[i].slice(0, quotindex);
|
9451 | parts.length = i + 1;
|
9452 | }
|
9453 | parts[i] = parts[i].replaceAll(/\\(.)/g, "$1");
|
9454 | }
|
9455 | value = parts.join('"');
|
9456 | }
|
9457 | return value;
|
9458 | }
|
9459 | function rfc5987decode(extvalue) {
|
9460 | const encodingend = extvalue.indexOf("'");
|
9461 | if (encodingend === -1) {
|
9462 | return extvalue;
|
9463 | }
|
9464 | const encoding = extvalue.slice(0, encodingend);
|
9465 | const langvalue = extvalue.slice(encodingend + 1);
|
9466 | const value = langvalue.replace(/^[^']*'/, "");
|
9467 | return textdecode(encoding, value);
|
9468 | }
|
9469 | function rfc2047decode(value) {
|
9470 | if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
|
9471 | return value;
|
9472 | }
|
9473 | return value.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
|
9474 | if (encoding === "q" || encoding === "Q") {
|
9475 | text = text.replaceAll("_", " ");
|
9476 | text = text.replaceAll(/=([0-9a-fA-F]{2})/g, function (match, hex) {
|
9477 | return String.fromCharCode(parseInt(hex, 16));
|
9478 | });
|
9479 | return textdecode(charset, text);
|
9480 | }
|
9481 | try {
|
9482 | text = atob(text);
|
9483 | } catch (e) {}
|
9484 | return textdecode(charset, text);
|
9485 | });
|
9486 | }
|
9487 | return "";
|
9488 | }
|
9489 |
|
9490 | }),
|
9491 |
|
9492 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
9493 |
|
9494 |
|
9495 |
|
9496 | Object.defineProperty(exports, "__esModule", ({
|
9497 | value: true
|
9498 | }));
|
9499 | exports.PDFNetworkStream = void 0;
|
9500 | var _util = __w_pdfjs_require__(1);
|
9501 | var _network_utils = __w_pdfjs_require__(22);
|
9502 | ;
|
9503 | const OK_RESPONSE = 200;
|
9504 | const PARTIAL_CONTENT_RESPONSE = 206;
|
9505 | function getArrayBuffer(xhr) {
|
9506 | const data = xhr.response;
|
9507 | if (typeof data !== "string") {
|
9508 | return data;
|
9509 | }
|
9510 | return (0, _util.stringToBytes)(data).buffer;
|
9511 | }
|
9512 | class NetworkManager {
|
9513 | constructor(url, args = {}) {
|
9514 | this.url = url;
|
9515 | this.isHttp = /^https?:/i.test(url);
|
9516 | this.httpHeaders = this.isHttp && args.httpHeaders || Object.create(null);
|
9517 | this.withCredentials = args.withCredentials || false;
|
9518 | this.currXhrId = 0;
|
9519 | this.pendingRequests = Object.create(null);
|
9520 | }
|
9521 | requestRange(begin, end, listeners) {
|
9522 | const args = {
|
9523 | begin,
|
9524 | end
|
9525 | };
|
9526 | for (const prop in listeners) {
|
9527 | args[prop] = listeners[prop];
|
9528 | }
|
9529 | return this.request(args);
|
9530 | }
|
9531 | requestFull(listeners) {
|
9532 | return this.request(listeners);
|
9533 | }
|
9534 | request(args) {
|
9535 | const xhr = new XMLHttpRequest();
|
9536 | const xhrId = this.currXhrId++;
|
9537 | const pendingRequest = this.pendingRequests[xhrId] = {
|
9538 | xhr
|
9539 | };
|
9540 | xhr.open("GET", this.url);
|
9541 | xhr.withCredentials = this.withCredentials;
|
9542 | for (const property in this.httpHeaders) {
|
9543 | const value = this.httpHeaders[property];
|
9544 | if (value === undefined) {
|
9545 | continue;
|
9546 | }
|
9547 | xhr.setRequestHeader(property, value);
|
9548 | }
|
9549 | if (this.isHttp && "begin" in args && "end" in args) {
|
9550 | xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
|
9551 | pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
|
9552 | } else {
|
9553 | pendingRequest.expectedStatus = OK_RESPONSE;
|
9554 | }
|
9555 | xhr.responseType = "arraybuffer";
|
9556 | if (args.onError) {
|
9557 | xhr.onerror = function (evt) {
|
9558 | args.onError(xhr.status);
|
9559 | };
|
9560 | }
|
9561 | xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
|
9562 | xhr.onprogress = this.onProgress.bind(this, xhrId);
|
9563 | pendingRequest.onHeadersReceived = args.onHeadersReceived;
|
9564 | pendingRequest.onDone = args.onDone;
|
9565 | pendingRequest.onError = args.onError;
|
9566 | pendingRequest.onProgress = args.onProgress;
|
9567 | xhr.send(null);
|
9568 | return xhrId;
|
9569 | }
|
9570 | onProgress(xhrId, evt) {
|
9571 | const pendingRequest = this.pendingRequests[xhrId];
|
9572 | if (!pendingRequest) {
|
9573 | return;
|
9574 | }
|
9575 | pendingRequest.onProgress?.(evt);
|
9576 | }
|
9577 | onStateChange(xhrId, evt) {
|
9578 | const pendingRequest = this.pendingRequests[xhrId];
|
9579 | if (!pendingRequest) {
|
9580 | return;
|
9581 | }
|
9582 | const xhr = pendingRequest.xhr;
|
9583 | if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
|
9584 | pendingRequest.onHeadersReceived();
|
9585 | delete pendingRequest.onHeadersReceived;
|
9586 | }
|
9587 | if (xhr.readyState !== 4) {
|
9588 | return;
|
9589 | }
|
9590 | if (!(xhrId in this.pendingRequests)) {
|
9591 | return;
|
9592 | }
|
9593 | delete this.pendingRequests[xhrId];
|
9594 | if (xhr.status === 0 && this.isHttp) {
|
9595 | pendingRequest.onError?.(xhr.status);
|
9596 | return;
|
9597 | }
|
9598 | const xhrStatus = xhr.status || OK_RESPONSE;
|
9599 | const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
|
9600 | if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
|
9601 | pendingRequest.onError?.(xhr.status);
|
9602 | return;
|
9603 | }
|
9604 | const chunk = getArrayBuffer(xhr);
|
9605 | if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
|
9606 | const rangeHeader = xhr.getResponseHeader("Content-Range");
|
9607 | const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
|
9608 | pendingRequest.onDone({
|
9609 | begin: parseInt(matches[1], 10),
|
9610 | chunk
|
9611 | });
|
9612 | } else if (chunk) {
|
9613 | pendingRequest.onDone({
|
9614 | begin: 0,
|
9615 | chunk
|
9616 | });
|
9617 | } else {
|
9618 | pendingRequest.onError?.(xhr.status);
|
9619 | }
|
9620 | }
|
9621 | getRequestXhr(xhrId) {
|
9622 | return this.pendingRequests[xhrId].xhr;
|
9623 | }
|
9624 | isPendingRequest(xhrId) {
|
9625 | return xhrId in this.pendingRequests;
|
9626 | }
|
9627 | abortRequest(xhrId) {
|
9628 | const xhr = this.pendingRequests[xhrId].xhr;
|
9629 | delete this.pendingRequests[xhrId];
|
9630 | xhr.abort();
|
9631 | }
|
9632 | }
|
9633 | class PDFNetworkStream {
|
9634 | constructor(source) {
|
9635 | this._source = source;
|
9636 | this._manager = new NetworkManager(source.url, {
|
9637 | httpHeaders: source.httpHeaders,
|
9638 | withCredentials: source.withCredentials
|
9639 | });
|
9640 | this._rangeChunkSize = source.rangeChunkSize;
|
9641 | this._fullRequestReader = null;
|
9642 | this._rangeRequestReaders = [];
|
9643 | }
|
9644 | _onRangeRequestReaderClosed(reader) {
|
9645 | const i = this._rangeRequestReaders.indexOf(reader);
|
9646 | if (i >= 0) {
|
9647 | this._rangeRequestReaders.splice(i, 1);
|
9648 | }
|
9649 | }
|
9650 | getFullReader() {
|
9651 | (0, _util.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
|
9652 | this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
|
9653 | return this._fullRequestReader;
|
9654 | }
|
9655 | getRangeReader(begin, end) {
|
9656 | const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
|
9657 | reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
|
9658 | this._rangeRequestReaders.push(reader);
|
9659 | return reader;
|
9660 | }
|
9661 | cancelAllRequests(reason) {
|
9662 | this._fullRequestReader?.cancel(reason);
|
9663 | for (const reader of this._rangeRequestReaders.slice(0)) {
|
9664 | reader.cancel(reason);
|
9665 | }
|
9666 | }
|
9667 | }
|
9668 | exports.PDFNetworkStream = PDFNetworkStream;
|
9669 | class PDFNetworkStreamFullRequestReader {
|
9670 | constructor(manager, source) {
|
9671 | this._manager = manager;
|
9672 | const args = {
|
9673 | onHeadersReceived: this._onHeadersReceived.bind(this),
|
9674 | onDone: this._onDone.bind(this),
|
9675 | onError: this._onError.bind(this),
|
9676 | onProgress: this._onProgress.bind(this)
|
9677 | };
|
9678 | this._url = source.url;
|
9679 | this._fullRequestId = manager.requestFull(args);
|
9680 | this._headersReceivedCapability = new _util.PromiseCapability();
|
9681 | this._disableRange = source.disableRange || false;
|
9682 | this._contentLength = source.length;
|
9683 | this._rangeChunkSize = source.rangeChunkSize;
|
9684 | if (!this._rangeChunkSize && !this._disableRange) {
|
9685 | this._disableRange = true;
|
9686 | }
|
9687 | this._isStreamingSupported = false;
|
9688 | this._isRangeSupported = false;
|
9689 | this._cachedChunks = [];
|
9690 | this._requests = [];
|
9691 | this._done = false;
|
9692 | this._storedError = undefined;
|
9693 | this._filename = null;
|
9694 | this.onProgress = null;
|
9695 | }
|
9696 | _onHeadersReceived() {
|
9697 | const fullRequestXhrId = this._fullRequestId;
|
9698 | const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
|
9699 | const getResponseHeader = name => {
|
9700 | return fullRequestXhr.getResponseHeader(name);
|
9701 | };
|
9702 | const {
|
9703 | allowRangeRequests,
|
9704 | suggestedLength
|
9705 | } = (0, _network_utils.validateRangeRequestCapabilities)({
|
9706 | getResponseHeader,
|
9707 | isHttp: this._manager.isHttp,
|
9708 | rangeChunkSize: this._rangeChunkSize,
|
9709 | disableRange: this._disableRange
|
9710 | });
|
9711 | if (allowRangeRequests) {
|
9712 | this._isRangeSupported = true;
|
9713 | }
|
9714 | this._contentLength = suggestedLength || this._contentLength;
|
9715 | this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
|
9716 | if (this._isRangeSupported) {
|
9717 | this._manager.abortRequest(fullRequestXhrId);
|
9718 | }
|
9719 | this._headersReceivedCapability.resolve();
|
9720 | }
|
9721 | _onDone(data) {
|
9722 | if (data) {
|
9723 | if (this._requests.length > 0) {
|
9724 | const requestCapability = this._requests.shift();
|
9725 | requestCapability.resolve({
|
9726 | value: data.chunk,
|
9727 | done: false
|
9728 | });
|
9729 | } else {
|
9730 | this._cachedChunks.push(data.chunk);
|
9731 | }
|
9732 | }
|
9733 | this._done = true;
|
9734 | if (this._cachedChunks.length > 0) {
|
9735 | return;
|
9736 | }
|
9737 | for (const requestCapability of this._requests) {
|
9738 | requestCapability.resolve({
|
9739 | value: undefined,
|
9740 | done: true
|
9741 | });
|
9742 | }
|
9743 | this._requests.length = 0;
|
9744 | }
|
9745 | _onError(status) {
|
9746 | this._storedError = (0, _network_utils.createResponseStatusError)(status, this._url);
|
9747 | this._headersReceivedCapability.reject(this._storedError);
|
9748 | for (const requestCapability of this._requests) {
|
9749 | requestCapability.reject(this._storedError);
|
9750 | }
|
9751 | this._requests.length = 0;
|
9752 | this._cachedChunks.length = 0;
|
9753 | }
|
9754 | _onProgress(evt) {
|
9755 | this.onProgress?.({
|
9756 | loaded: evt.loaded,
|
9757 | total: evt.lengthComputable ? evt.total : this._contentLength
|
9758 | });
|
9759 | }
|
9760 | get filename() {
|
9761 | return this._filename;
|
9762 | }
|
9763 | get isRangeSupported() {
|
9764 | return this._isRangeSupported;
|
9765 | }
|
9766 | get isStreamingSupported() {
|
9767 | return this._isStreamingSupported;
|
9768 | }
|
9769 | get contentLength() {
|
9770 | return this._contentLength;
|
9771 | }
|
9772 | get headersReady() {
|
9773 | return this._headersReceivedCapability.promise;
|
9774 | }
|
9775 | async read() {
|
9776 | if (this._storedError) {
|
9777 | throw this._storedError;
|
9778 | }
|
9779 | if (this._cachedChunks.length > 0) {
|
9780 | const chunk = this._cachedChunks.shift();
|
9781 | return {
|
9782 | value: chunk,
|
9783 | done: false
|
9784 | };
|
9785 | }
|
9786 | if (this._done) {
|
9787 | return {
|
9788 | value: undefined,
|
9789 | done: true
|
9790 | };
|
9791 | }
|
9792 | const requestCapability = new _util.PromiseCapability();
|
9793 | this._requests.push(requestCapability);
|
9794 | return requestCapability.promise;
|
9795 | }
|
9796 | cancel(reason) {
|
9797 | this._done = true;
|
9798 | this._headersReceivedCapability.reject(reason);
|
9799 | for (const requestCapability of this._requests) {
|
9800 | requestCapability.resolve({
|
9801 | value: undefined,
|
9802 | done: true
|
9803 | });
|
9804 | }
|
9805 | this._requests.length = 0;
|
9806 | if (this._manager.isPendingRequest(this._fullRequestId)) {
|
9807 | this._manager.abortRequest(this._fullRequestId);
|
9808 | }
|
9809 | this._fullRequestReader = null;
|
9810 | }
|
9811 | }
|
9812 | class PDFNetworkStreamRangeRequestReader {
|
9813 | constructor(manager, begin, end) {
|
9814 | this._manager = manager;
|
9815 | const args = {
|
9816 | onDone: this._onDone.bind(this),
|
9817 | onError: this._onError.bind(this),
|
9818 | onProgress: this._onProgress.bind(this)
|
9819 | };
|
9820 | this._url = manager.url;
|
9821 | this._requestId = manager.requestRange(begin, end, args);
|
9822 | this._requests = [];
|
9823 | this._queuedChunk = null;
|
9824 | this._done = false;
|
9825 | this._storedError = undefined;
|
9826 | this.onProgress = null;
|
9827 | this.onClosed = null;
|
9828 | }
|
9829 | _close() {
|
9830 | this.onClosed?.(this);
|
9831 | }
|
9832 | _onDone(data) {
|
9833 | const chunk = data.chunk;
|
9834 | if (this._requests.length > 0) {
|
9835 | const requestCapability = this._requests.shift();
|
9836 | requestCapability.resolve({
|
9837 | value: chunk,
|
9838 | done: false
|
9839 | });
|
9840 | } else {
|
9841 | this._queuedChunk = chunk;
|
9842 | }
|
9843 | this._done = true;
|
9844 | for (const requestCapability of this._requests) {
|
9845 | requestCapability.resolve({
|
9846 | value: undefined,
|
9847 | done: true
|
9848 | });
|
9849 | }
|
9850 | this._requests.length = 0;
|
9851 | this._close();
|
9852 | }
|
9853 | _onError(status) {
|
9854 | this._storedError = (0, _network_utils.createResponseStatusError)(status, this._url);
|
9855 | for (const requestCapability of this._requests) {
|
9856 | requestCapability.reject(this._storedError);
|
9857 | }
|
9858 | this._requests.length = 0;
|
9859 | this._queuedChunk = null;
|
9860 | }
|
9861 | _onProgress(evt) {
|
9862 | if (!this.isStreamingSupported) {
|
9863 | this.onProgress?.({
|
9864 | loaded: evt.loaded
|
9865 | });
|
9866 | }
|
9867 | }
|
9868 | get isStreamingSupported() {
|
9869 | return false;
|
9870 | }
|
9871 | async read() {
|
9872 | if (this._storedError) {
|
9873 | throw this._storedError;
|
9874 | }
|
9875 | if (this._queuedChunk !== null) {
|
9876 | const chunk = this._queuedChunk;
|
9877 | this._queuedChunk = null;
|
9878 | return {
|
9879 | value: chunk,
|
9880 | done: false
|
9881 | };
|
9882 | }
|
9883 | if (this._done) {
|
9884 | return {
|
9885 | value: undefined,
|
9886 | done: true
|
9887 | };
|
9888 | }
|
9889 | const requestCapability = new _util.PromiseCapability();
|
9890 | this._requests.push(requestCapability);
|
9891 | return requestCapability.promise;
|
9892 | }
|
9893 | cancel(reason) {
|
9894 | this._done = true;
|
9895 | for (const requestCapability of this._requests) {
|
9896 | requestCapability.resolve({
|
9897 | value: undefined,
|
9898 | done: true
|
9899 | });
|
9900 | }
|
9901 | this._requests.length = 0;
|
9902 | if (this._manager.isPendingRequest(this._requestId)) {
|
9903 | this._manager.abortRequest(this._requestId);
|
9904 | }
|
9905 | this._close();
|
9906 | }
|
9907 | }
|
9908 |
|
9909 | }),
|
9910 |
|
9911 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
9912 |
|
9913 |
|
9914 |
|
9915 | Object.defineProperty(exports, "__esModule", ({
|
9916 | value: true
|
9917 | }));
|
9918 | exports.PDFFetchStream = void 0;
|
9919 | var _util = __w_pdfjs_require__(1);
|
9920 | var _network_utils = __w_pdfjs_require__(22);
|
9921 | ;
|
9922 | function createFetchOptions(headers, withCredentials, abortController) {
|
9923 | return {
|
9924 | method: "GET",
|
9925 | headers,
|
9926 | signal: abortController.signal,
|
9927 | mode: "cors",
|
9928 | credentials: withCredentials ? "include" : "same-origin",
|
9929 | redirect: "follow"
|
9930 | };
|
9931 | }
|
9932 | function createHeaders(httpHeaders) {
|
9933 | const headers = new Headers();
|
9934 | for (const property in httpHeaders) {
|
9935 | const value = httpHeaders[property];
|
9936 | if (value === undefined) {
|
9937 | continue;
|
9938 | }
|
9939 | headers.append(property, value);
|
9940 | }
|
9941 | return headers;
|
9942 | }
|
9943 | function getArrayBuffer(val) {
|
9944 | if (val instanceof Uint8Array) {
|
9945 | return val.buffer;
|
9946 | }
|
9947 | if (val instanceof ArrayBuffer) {
|
9948 | return val;
|
9949 | }
|
9950 | (0, _util.warn)(`getArrayBuffer - unexpected data format: ${val}`);
|
9951 | return new Uint8Array(val).buffer;
|
9952 | }
|
9953 | class PDFFetchStream {
|
9954 | constructor(source) {
|
9955 | this.source = source;
|
9956 | this.isHttp = /^https?:/i.test(source.url);
|
9957 | this.httpHeaders = this.isHttp && source.httpHeaders || {};
|
9958 | this._fullRequestReader = null;
|
9959 | this._rangeRequestReaders = [];
|
9960 | }
|
9961 | get _progressiveDataLength() {
|
9962 | return this._fullRequestReader?._loaded ?? 0;
|
9963 | }
|
9964 | getFullReader() {
|
9965 | (0, _util.assert)(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
|
9966 | this._fullRequestReader = new PDFFetchStreamReader(this);
|
9967 | return this._fullRequestReader;
|
9968 | }
|
9969 | getRangeReader(begin, end) {
|
9970 | if (end <= this._progressiveDataLength) {
|
9971 | return null;
|
9972 | }
|
9973 | const reader = new PDFFetchStreamRangeReader(this, begin, end);
|
9974 | this._rangeRequestReaders.push(reader);
|
9975 | return reader;
|
9976 | }
|
9977 | cancelAllRequests(reason) {
|
9978 | this._fullRequestReader?.cancel(reason);
|
9979 | for (const reader of this._rangeRequestReaders.slice(0)) {
|
9980 | reader.cancel(reason);
|
9981 | }
|
9982 | }
|
9983 | }
|
9984 | exports.PDFFetchStream = PDFFetchStream;
|
9985 | class PDFFetchStreamReader {
|
9986 | constructor(stream) {
|
9987 | this._stream = stream;
|
9988 | this._reader = null;
|
9989 | this._loaded = 0;
|
9990 | this._filename = null;
|
9991 | const source = stream.source;
|
9992 | this._withCredentials = source.withCredentials || false;
|
9993 | this._contentLength = source.length;
|
9994 | this._headersCapability = new _util.PromiseCapability();
|
9995 | this._disableRange = source.disableRange || false;
|
9996 | this._rangeChunkSize = source.rangeChunkSize;
|
9997 | if (!this._rangeChunkSize && !this._disableRange) {
|
9998 | this._disableRange = true;
|
9999 | }
|
10000 | this._abortController = new AbortController();
|
10001 | this._isStreamingSupported = !source.disableStream;
|
10002 | this._isRangeSupported = !source.disableRange;
|
10003 | this._headers = createHeaders(this._stream.httpHeaders);
|
10004 | const url = source.url;
|
10005 | fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
|
10006 | if (!(0, _network_utils.validateResponseStatus)(response.status)) {
|
10007 | throw (0, _network_utils.createResponseStatusError)(response.status, url);
|
10008 | }
|
10009 | this._reader = response.body.getReader();
|
10010 | this._headersCapability.resolve();
|
10011 | const getResponseHeader = name => {
|
10012 | return response.headers.get(name);
|
10013 | };
|
10014 | const {
|
10015 | allowRangeRequests,
|
10016 | suggestedLength
|
10017 | } = (0, _network_utils.validateRangeRequestCapabilities)({
|
10018 | getResponseHeader,
|
10019 | isHttp: this._stream.isHttp,
|
10020 | rangeChunkSize: this._rangeChunkSize,
|
10021 | disableRange: this._disableRange
|
10022 | });
|
10023 | this._isRangeSupported = allowRangeRequests;
|
10024 | this._contentLength = suggestedLength || this._contentLength;
|
10025 | this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
|
10026 | if (!this._isStreamingSupported && this._isRangeSupported) {
|
10027 | this.cancel(new _util.AbortException("Streaming is disabled."));
|
10028 | }
|
10029 | }).catch(this._headersCapability.reject);
|
10030 | this.onProgress = null;
|
10031 | }
|
10032 | get headersReady() {
|
10033 | return this._headersCapability.promise;
|
10034 | }
|
10035 | get filename() {
|
10036 | return this._filename;
|
10037 | }
|
10038 | get contentLength() {
|
10039 | return this._contentLength;
|
10040 | }
|
10041 | get isRangeSupported() {
|
10042 | return this._isRangeSupported;
|
10043 | }
|
10044 | get isStreamingSupported() {
|
10045 | return this._isStreamingSupported;
|
10046 | }
|
10047 | async read() {
|
10048 | await this._headersCapability.promise;
|
10049 | const {
|
10050 | value,
|
10051 | done
|
10052 | } = await this._reader.read();
|
10053 | if (done) {
|
10054 | return {
|
10055 | value,
|
10056 | done
|
10057 | };
|
10058 | }
|
10059 | this._loaded += value.byteLength;
|
10060 | this.onProgress?.({
|
10061 | loaded: this._loaded,
|
10062 | total: this._contentLength
|
10063 | });
|
10064 | return {
|
10065 | value: getArrayBuffer(value),
|
10066 | done: false
|
10067 | };
|
10068 | }
|
10069 | cancel(reason) {
|
10070 | this._reader?.cancel(reason);
|
10071 | this._abortController.abort();
|
10072 | }
|
10073 | }
|
10074 | class PDFFetchStreamRangeReader {
|
10075 | constructor(stream, begin, end) {
|
10076 | this._stream = stream;
|
10077 | this._reader = null;
|
10078 | this._loaded = 0;
|
10079 | const source = stream.source;
|
10080 | this._withCredentials = source.withCredentials || false;
|
10081 | this._readCapability = new _util.PromiseCapability();
|
10082 | this._isStreamingSupported = !source.disableStream;
|
10083 | this._abortController = new AbortController();
|
10084 | this._headers = createHeaders(this._stream.httpHeaders);
|
10085 | this._headers.append("Range", `bytes=${begin}-${end - 1}`);
|
10086 | const url = source.url;
|
10087 | fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
|
10088 | if (!(0, _network_utils.validateResponseStatus)(response.status)) {
|
10089 | throw (0, _network_utils.createResponseStatusError)(response.status, url);
|
10090 | }
|
10091 | this._readCapability.resolve();
|
10092 | this._reader = response.body.getReader();
|
10093 | }).catch(this._readCapability.reject);
|
10094 | this.onProgress = null;
|
10095 | }
|
10096 | get isStreamingSupported() {
|
10097 | return this._isStreamingSupported;
|
10098 | }
|
10099 | async read() {
|
10100 | await this._readCapability.promise;
|
10101 | const {
|
10102 | value,
|
10103 | done
|
10104 | } = await this._reader.read();
|
10105 | if (done) {
|
10106 | return {
|
10107 | value,
|
10108 | done
|
10109 | };
|
10110 | }
|
10111 | this._loaded += value.byteLength;
|
10112 | this.onProgress?.({
|
10113 | loaded: this._loaded
|
10114 | });
|
10115 | return {
|
10116 | value: getArrayBuffer(value),
|
10117 | done: false
|
10118 | };
|
10119 | }
|
10120 | cancel(reason) {
|
10121 | this._reader?.cancel(reason);
|
10122 | this._abortController.abort();
|
10123 | }
|
10124 | }
|
10125 |
|
10126 | }),
|
10127 |
|
10128 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
10129 |
|
10130 |
|
10131 |
|
10132 | Object.defineProperty(exports, "__esModule", ({
|
10133 | value: true
|
10134 | }));
|
10135 | exports.TextLayerRenderTask = void 0;
|
10136 | exports.renderTextLayer = renderTextLayer;
|
10137 | exports.updateTextLayer = updateTextLayer;
|
10138 | var _util = __w_pdfjs_require__(1);
|
10139 | var _display_utils = __w_pdfjs_require__(6);
|
10140 | const MAX_TEXT_DIVS_TO_RENDER = 100000;
|
10141 | const DEFAULT_FONT_SIZE = 30;
|
10142 | const DEFAULT_FONT_ASCENT = 0.8;
|
10143 | const ascentCache = new Map();
|
10144 | function getCtx(size, isOffscreenCanvasSupported) {
|
10145 | let ctx;
|
10146 | if (isOffscreenCanvasSupported && _util.FeatureTest.isOffscreenCanvasSupported) {
|
10147 | ctx = new OffscreenCanvas(size, size).getContext("2d", {
|
10148 | alpha: false
|
10149 | });
|
10150 | } else {
|
10151 | const canvas = document.createElement("canvas");
|
10152 | canvas.width = canvas.height = size;
|
10153 | ctx = canvas.getContext("2d", {
|
10154 | alpha: false
|
10155 | });
|
10156 | }
|
10157 | return ctx;
|
10158 | }
|
10159 | function getAscent(fontFamily, isOffscreenCanvasSupported) {
|
10160 | const cachedAscent = ascentCache.get(fontFamily);
|
10161 | if (cachedAscent) {
|
10162 | return cachedAscent;
|
10163 | }
|
10164 | const ctx = getCtx(DEFAULT_FONT_SIZE, isOffscreenCanvasSupported);
|
10165 | ctx.font = `${DEFAULT_FONT_SIZE}px ${fontFamily}`;
|
10166 | const metrics = ctx.measureText("");
|
10167 | let ascent = metrics.fontBoundingBoxAscent;
|
10168 | let descent = Math.abs(metrics.fontBoundingBoxDescent);
|
10169 | if (ascent) {
|
10170 | const ratio = ascent / (ascent + descent);
|
10171 | ascentCache.set(fontFamily, ratio);
|
10172 | ctx.canvas.width = ctx.canvas.height = 0;
|
10173 | return ratio;
|
10174 | }
|
10175 | ctx.strokeStyle = "red";
|
10176 | ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
|
10177 | ctx.strokeText("g", 0, 0);
|
10178 | let pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
|
10179 | descent = 0;
|
10180 | for (let i = pixels.length - 1 - 3; i >= 0; i -= 4) {
|
10181 | if (pixels[i] > 0) {
|
10182 | descent = Math.ceil(i / 4 / DEFAULT_FONT_SIZE);
|
10183 | break;
|
10184 | }
|
10185 | }
|
10186 | ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
|
10187 | ctx.strokeText("A", 0, DEFAULT_FONT_SIZE);
|
10188 | pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
|
10189 | ascent = 0;
|
10190 | for (let i = 0, ii = pixels.length; i < ii; i += 4) {
|
10191 | if (pixels[i] > 0) {
|
10192 | ascent = DEFAULT_FONT_SIZE - Math.floor(i / 4 / DEFAULT_FONT_SIZE);
|
10193 | break;
|
10194 | }
|
10195 | }
|
10196 | ctx.canvas.width = ctx.canvas.height = 0;
|
10197 | if (ascent) {
|
10198 | const ratio = ascent / (ascent + descent);
|
10199 | ascentCache.set(fontFamily, ratio);
|
10200 | return ratio;
|
10201 | }
|
10202 | ascentCache.set(fontFamily, DEFAULT_FONT_ASCENT);
|
10203 | return DEFAULT_FONT_ASCENT;
|
10204 | }
|
10205 | function appendText(task, geom, styles) {
|
10206 | const textDiv = document.createElement("span");
|
10207 | const textDivProperties = {
|
10208 | angle: 0,
|
10209 | canvasWidth: 0,
|
10210 | hasText: geom.str !== "",
|
10211 | hasEOL: geom.hasEOL,
|
10212 | fontSize: 0
|
10213 | };
|
10214 | task._textDivs.push(textDiv);
|
10215 | const tx = _util.Util.transform(task._transform, geom.transform);
|
10216 | let angle = Math.atan2(tx[1], tx[0]);
|
10217 | const style = styles[geom.fontName];
|
10218 | if (style.vertical) {
|
10219 | angle += Math.PI / 2;
|
10220 | }
|
10221 | const fontHeight = Math.hypot(tx[2], tx[3]);
|
10222 | const fontAscent = fontHeight * getAscent(style.fontFamily, task._isOffscreenCanvasSupported);
|
10223 | let left, top;
|
10224 | if (angle === 0) {
|
10225 | left = tx[4];
|
10226 | top = tx[5] - fontAscent;
|
10227 | } else {
|
10228 | left = tx[4] + fontAscent * Math.sin(angle);
|
10229 | top = tx[5] - fontAscent * Math.cos(angle);
|
10230 | }
|
10231 | const scaleFactorStr = "calc(var(--scale-factor)*";
|
10232 | const divStyle = textDiv.style;
|
10233 | if (task._container === task._rootContainer) {
|
10234 | divStyle.left = `${(100 * left / task._pageWidth).toFixed(2)}%`;
|
10235 | divStyle.top = `${(100 * top / task._pageHeight).toFixed(2)}%`;
|
10236 | } else {
|
10237 | divStyle.left = `${scaleFactorStr}${left.toFixed(2)}px)`;
|
10238 | divStyle.top = `${scaleFactorStr}${top.toFixed(2)}px)`;
|
10239 | }
|
10240 | divStyle.fontSize = `${scaleFactorStr}${fontHeight.toFixed(2)}px)`;
|
10241 | divStyle.fontFamily = style.fontFamily;
|
10242 | textDivProperties.fontSize = fontHeight;
|
10243 | textDiv.setAttribute("role", "presentation");
|
10244 | textDiv.textContent = geom.str;
|
10245 | textDiv.dir = geom.dir;
|
10246 | if (task._fontInspectorEnabled) {
|
10247 | textDiv.dataset.fontName = geom.fontName;
|
10248 | }
|
10249 | if (angle !== 0) {
|
10250 | textDivProperties.angle = angle * (180 / Math.PI);
|
10251 | }
|
10252 | let shouldScaleText = false;
|
10253 | if (geom.str.length > 1) {
|
10254 | shouldScaleText = true;
|
10255 | } else if (geom.str !== " " && geom.transform[0] !== geom.transform[3]) {
|
10256 | const absScaleX = Math.abs(geom.transform[0]),
|
10257 | absScaleY = Math.abs(geom.transform[3]);
|
10258 | if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
|
10259 | shouldScaleText = true;
|
10260 | }
|
10261 | }
|
10262 | if (shouldScaleText) {
|
10263 | textDivProperties.canvasWidth = style.vertical ? geom.height : geom.width;
|
10264 | }
|
10265 | task._textDivProperties.set(textDiv, textDivProperties);
|
10266 | if (task._isReadableStream) {
|
10267 | task._layoutText(textDiv);
|
10268 | }
|
10269 | }
|
10270 | function layout(params) {
|
10271 | const {
|
10272 | div,
|
10273 | scale,
|
10274 | properties,
|
10275 | ctx,
|
10276 | prevFontSize,
|
10277 | prevFontFamily
|
10278 | } = params;
|
10279 | const {
|
10280 | style
|
10281 | } = div;
|
10282 | let transform = "";
|
10283 | if (properties.canvasWidth !== 0 && properties.hasText) {
|
10284 | const {
|
10285 | fontFamily
|
10286 | } = style;
|
10287 | const {
|
10288 | canvasWidth,
|
10289 | fontSize
|
10290 | } = properties;
|
10291 | if (prevFontSize !== fontSize || prevFontFamily !== fontFamily) {
|
10292 | ctx.font = `${fontSize * scale}px ${fontFamily}`;
|
10293 | params.prevFontSize = fontSize;
|
10294 | params.prevFontFamily = fontFamily;
|
10295 | }
|
10296 | const {
|
10297 | width
|
10298 | } = ctx.measureText(div.textContent);
|
10299 | if (width > 0) {
|
10300 | transform = `scaleX(${canvasWidth * scale / width})`;
|
10301 | }
|
10302 | }
|
10303 | if (properties.angle !== 0) {
|
10304 | transform = `rotate(${properties.angle}deg) ${transform}`;
|
10305 | }
|
10306 | if (transform.length > 0) {
|
10307 | style.transform = transform;
|
10308 | }
|
10309 | }
|
10310 | function render(task) {
|
10311 | if (task._canceled) {
|
10312 | return;
|
10313 | }
|
10314 | const textDivs = task._textDivs;
|
10315 | const capability = task._capability;
|
10316 | const textDivsLength = textDivs.length;
|
10317 | if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
|
10318 | capability.resolve();
|
10319 | return;
|
10320 | }
|
10321 | if (!task._isReadableStream) {
|
10322 | for (const textDiv of textDivs) {
|
10323 | task._layoutText(textDiv);
|
10324 | }
|
10325 | }
|
10326 | capability.resolve();
|
10327 | }
|
10328 | class TextLayerRenderTask {
|
10329 | constructor({
|
10330 | textContentSource,
|
10331 | container,
|
10332 | viewport,
|
10333 | textDivs,
|
10334 | textDivProperties,
|
10335 | textContentItemsStr,
|
10336 | isOffscreenCanvasSupported
|
10337 | }) {
|
10338 | this._textContentSource = textContentSource;
|
10339 | this._isReadableStream = textContentSource instanceof ReadableStream;
|
10340 | this._container = this._rootContainer = container;
|
10341 | this._textDivs = textDivs || [];
|
10342 | this._textContentItemsStr = textContentItemsStr || [];
|
10343 | this._isOffscreenCanvasSupported = isOffscreenCanvasSupported;
|
10344 | this._fontInspectorEnabled = !!globalThis.FontInspector?.enabled;
|
10345 | this._reader = null;
|
10346 | this._textDivProperties = textDivProperties || new WeakMap();
|
10347 | this._canceled = false;
|
10348 | this._capability = new _util.PromiseCapability();
|
10349 | this._layoutTextParams = {
|
10350 | prevFontSize: null,
|
10351 | prevFontFamily: null,
|
10352 | div: null,
|
10353 | scale: viewport.scale * (globalThis.devicePixelRatio || 1),
|
10354 | properties: null,
|
10355 | ctx: getCtx(0, isOffscreenCanvasSupported)
|
10356 | };
|
10357 | const {
|
10358 | pageWidth,
|
10359 | pageHeight,
|
10360 | pageX,
|
10361 | pageY
|
10362 | } = viewport.rawDims;
|
10363 | this._transform = [1, 0, 0, -1, -pageX, pageY + pageHeight];
|
10364 | this._pageWidth = pageWidth;
|
10365 | this._pageHeight = pageHeight;
|
10366 | (0, _display_utils.setLayerDimensions)(container, viewport);
|
10367 | this._capability.promise.finally(() => {
|
10368 | this._layoutTextParams = null;
|
10369 | }).catch(() => {});
|
10370 | }
|
10371 | get promise() {
|
10372 | return this._capability.promise;
|
10373 | }
|
10374 | cancel() {
|
10375 | this._canceled = true;
|
10376 | if (this._reader) {
|
10377 | this._reader.cancel(new _util.AbortException("TextLayer task cancelled.")).catch(() => {});
|
10378 | this._reader = null;
|
10379 | }
|
10380 | this._capability.reject(new _util.AbortException("TextLayer task cancelled."));
|
10381 | }
|
10382 | _processItems(items, styleCache) {
|
10383 | for (const item of items) {
|
10384 | if (item.str === undefined) {
|
10385 | if (item.type === "beginMarkedContentProps" || item.type === "beginMarkedContent") {
|
10386 | const parent = this._container;
|
10387 | this._container = document.createElement("span");
|
10388 | this._container.classList.add("markedContent");
|
10389 | if (item.id !== null) {
|
10390 | this._container.setAttribute("id", `${item.id}`);
|
10391 | }
|
10392 | parent.append(this._container);
|
10393 | } else if (item.type === "endMarkedContent") {
|
10394 | this._container = this._container.parentNode;
|
10395 | }
|
10396 | continue;
|
10397 | }
|
10398 | this._textContentItemsStr.push(item.str);
|
10399 | appendText(this, item, styleCache);
|
10400 | }
|
10401 | }
|
10402 | _layoutText(textDiv) {
|
10403 | const textDivProperties = this._layoutTextParams.properties = this._textDivProperties.get(textDiv);
|
10404 | this._layoutTextParams.div = textDiv;
|
10405 | layout(this._layoutTextParams);
|
10406 | if (textDivProperties.hasText) {
|
10407 | this._container.append(textDiv);
|
10408 | }
|
10409 | if (textDivProperties.hasEOL) {
|
10410 | const br = document.createElement("br");
|
10411 | br.setAttribute("role", "presentation");
|
10412 | this._container.append(br);
|
10413 | }
|
10414 | }
|
10415 | _render() {
|
10416 | const capability = new _util.PromiseCapability();
|
10417 | let styleCache = Object.create(null);
|
10418 | if (this._isReadableStream) {
|
10419 | const pump = () => {
|
10420 | this._reader.read().then(({
|
10421 | value,
|
10422 | done
|
10423 | }) => {
|
10424 | if (done) {
|
10425 | capability.resolve();
|
10426 | return;
|
10427 | }
|
10428 | Object.assign(styleCache, value.styles);
|
10429 | this._processItems(value.items, styleCache);
|
10430 | pump();
|
10431 | }, capability.reject);
|
10432 | };
|
10433 | this._reader = this._textContentSource.getReader();
|
10434 | pump();
|
10435 | } else if (this._textContentSource) {
|
10436 | const {
|
10437 | items,
|
10438 | styles
|
10439 | } = this._textContentSource;
|
10440 | this._processItems(items, styles);
|
10441 | capability.resolve();
|
10442 | } else {
|
10443 | throw new Error('No "textContentSource" parameter specified.');
|
10444 | }
|
10445 | capability.promise.then(() => {
|
10446 | styleCache = null;
|
10447 | render(this);
|
10448 | }, this._capability.reject);
|
10449 | }
|
10450 | }
|
10451 | exports.TextLayerRenderTask = TextLayerRenderTask;
|
10452 | function renderTextLayer(params) {
|
10453 | if (!params.textContentSource && (params.textContent || params.textContentStream)) {
|
10454 | (0, _display_utils.deprecated)("The TextLayerRender `textContent`/`textContentStream` parameters " + "will be removed in the future, please use `textContentSource` instead.");
|
10455 | params.textContentSource = params.textContent || params.textContentStream;
|
10456 | }
|
10457 | const {
|
10458 | container,
|
10459 | viewport
|
10460 | } = params;
|
10461 | const style = getComputedStyle(container);
|
10462 | const visibility = style.getPropertyValue("visibility");
|
10463 | const scaleFactor = parseFloat(style.getPropertyValue("--scale-factor"));
|
10464 | if (visibility === "visible" && (!scaleFactor || Math.abs(scaleFactor - viewport.scale) > 1e-5)) {
|
10465 | console.error("The `--scale-factor` CSS-variable must be set, " + "to the same value as `viewport.scale`, " + "either on the `container`-element itself or higher up in the DOM.");
|
10466 | }
|
10467 | const task = new TextLayerRenderTask(params);
|
10468 | task._render();
|
10469 | return task;
|
10470 | }
|
10471 | function updateTextLayer({
|
10472 | container,
|
10473 | viewport,
|
10474 | textDivs,
|
10475 | textDivProperties,
|
10476 | isOffscreenCanvasSupported,
|
10477 | mustRotate = true,
|
10478 | mustRescale = true
|
10479 | }) {
|
10480 | if (mustRotate) {
|
10481 | (0, _display_utils.setLayerDimensions)(container, {
|
10482 | rotation: viewport.rotation
|
10483 | });
|
10484 | }
|
10485 | if (mustRescale) {
|
10486 | const ctx = getCtx(0, isOffscreenCanvasSupported);
|
10487 | const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
|
10488 | const params = {
|
10489 | prevFontSize: null,
|
10490 | prevFontFamily: null,
|
10491 | div: null,
|
10492 | scale,
|
10493 | properties: null,
|
10494 | ctx
|
10495 | };
|
10496 | for (const div of textDivs) {
|
10497 | params.properties = textDivProperties.get(div);
|
10498 | params.div = div;
|
10499 | layout(params);
|
10500 | }
|
10501 | }
|
10502 | }
|
10503 |
|
10504 | }),
|
10505 |
|
10506 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
10507 |
|
10508 |
|
10509 |
|
10510 | Object.defineProperty(exports, "__esModule", ({
|
10511 | value: true
|
10512 | }));
|
10513 | exports.AnnotationEditorLayer = void 0;
|
10514 | var _util = __w_pdfjs_require__(1);
|
10515 | var _tools = __w_pdfjs_require__(5);
|
10516 | var _freetext = __w_pdfjs_require__(28);
|
10517 | var _ink = __w_pdfjs_require__(29);
|
10518 | var _display_utils = __w_pdfjs_require__(6);
|
10519 | class AnnotationEditorLayer {
|
10520 | #accessibilityManager;
|
10521 | #allowClick = false;
|
10522 | #boundPointerup = this.pointerup.bind(this);
|
10523 | #boundPointerdown = this.pointerdown.bind(this);
|
10524 | #editors = new Map();
|
10525 | #hadPointerDown = false;
|
10526 | #isCleaningUp = false;
|
10527 | #uiManager;
|
10528 | static _initialized = false;
|
10529 | constructor(options) {
|
10530 | if (!AnnotationEditorLayer._initialized) {
|
10531 | AnnotationEditorLayer._initialized = true;
|
10532 | _freetext.FreeTextEditor.initialize(options.l10n);
|
10533 | _ink.InkEditor.initialize(options.l10n);
|
10534 | }
|
10535 | options.uiManager.registerEditorTypes([_freetext.FreeTextEditor, _ink.InkEditor]);
|
10536 | this.#uiManager = options.uiManager;
|
10537 | this.pageIndex = options.pageIndex;
|
10538 | this.div = options.div;
|
10539 | this.#accessibilityManager = options.accessibilityManager;
|
10540 | this.#uiManager.addLayer(this);
|
10541 | }
|
10542 | get isEmpty() {
|
10543 | return this.#editors.size === 0;
|
10544 | }
|
10545 | updateToolbar(mode) {
|
10546 | this.#uiManager.updateToolbar(mode);
|
10547 | }
|
10548 | updateMode(mode = this.#uiManager.getMode()) {
|
10549 | this.#cleanup();
|
10550 | if (mode === _util.AnnotationEditorType.INK) {
|
10551 | this.addInkEditorIfNeeded(false);
|
10552 | this.disableClick();
|
10553 | } else {
|
10554 | this.enableClick();
|
10555 | }
|
10556 | this.#uiManager.unselectAll();
|
10557 | if (mode !== _util.AnnotationEditorType.NONE) {
|
10558 | this.div.classList.toggle("freeTextEditing", mode === _util.AnnotationEditorType.FREETEXT);
|
10559 | this.div.classList.toggle("inkEditing", mode === _util.AnnotationEditorType.INK);
|
10560 | this.div.hidden = false;
|
10561 | }
|
10562 | }
|
10563 | addInkEditorIfNeeded(isCommitting) {
|
10564 | if (!isCommitting && this.#uiManager.getMode() !== _util.AnnotationEditorType.INK) {
|
10565 | return;
|
10566 | }
|
10567 | if (!isCommitting) {
|
10568 | for (const editor of this.#editors.values()) {
|
10569 | if (editor.isEmpty()) {
|
10570 | editor.setInBackground();
|
10571 | return;
|
10572 | }
|
10573 | }
|
10574 | }
|
10575 | const editor = this.#createAndAddNewEditor({
|
10576 | offsetX: 0,
|
10577 | offsetY: 0
|
10578 | });
|
10579 | editor.setInBackground();
|
10580 | }
|
10581 | setEditingState(isEditing) {
|
10582 | this.#uiManager.setEditingState(isEditing);
|
10583 | }
|
10584 | addCommands(params) {
|
10585 | this.#uiManager.addCommands(params);
|
10586 | }
|
10587 | enable() {
|
10588 | this.div.style.pointerEvents = "auto";
|
10589 | for (const editor of this.#editors.values()) {
|
10590 | editor.enableEditing();
|
10591 | }
|
10592 | }
|
10593 | disable() {
|
10594 | this.div.style.pointerEvents = "none";
|
10595 | for (const editor of this.#editors.values()) {
|
10596 | editor.disableEditing();
|
10597 | }
|
10598 | this.#cleanup();
|
10599 | if (this.isEmpty) {
|
10600 | this.div.hidden = true;
|
10601 | }
|
10602 | }
|
10603 | setActiveEditor(editor) {
|
10604 | const currentActive = this.#uiManager.getActive();
|
10605 | if (currentActive === editor) {
|
10606 | return;
|
10607 | }
|
10608 | this.#uiManager.setActiveEditor(editor);
|
10609 | }
|
10610 | enableClick() {
|
10611 | this.div.addEventListener("pointerdown", this.#boundPointerdown);
|
10612 | this.div.addEventListener("pointerup", this.#boundPointerup);
|
10613 | }
|
10614 | disableClick() {
|
10615 | this.div.removeEventListener("pointerdown", this.#boundPointerdown);
|
10616 | this.div.removeEventListener("pointerup", this.#boundPointerup);
|
10617 | }
|
10618 | attach(editor) {
|
10619 | this.#editors.set(editor.id, editor);
|
10620 | }
|
10621 | detach(editor) {
|
10622 | this.#editors.delete(editor.id);
|
10623 | this.#accessibilityManager?.removePointerInTextLayer(editor.contentDiv);
|
10624 | }
|
10625 | remove(editor) {
|
10626 | this.#uiManager.removeEditor(editor);
|
10627 | this.detach(editor);
|
10628 | editor.div.style.display = "none";
|
10629 | setTimeout(() => {
|
10630 | editor.div.style.display = "";
|
10631 | editor.div.remove();
|
10632 | editor.isAttachedToDOM = false;
|
10633 | if (document.activeElement === document.body) {
|
10634 | this.#uiManager.focusMainContainer();
|
10635 | }
|
10636 | }, 0);
|
10637 | if (!this.#isCleaningUp) {
|
10638 | this.addInkEditorIfNeeded(false);
|
10639 | }
|
10640 | }
|
10641 | #changeParent(editor) {
|
10642 | if (editor.parent === this) {
|
10643 | return;
|
10644 | }
|
10645 | this.attach(editor);
|
10646 | editor.parent?.detach(editor);
|
10647 | editor.setParent(this);
|
10648 | if (editor.div && editor.isAttachedToDOM) {
|
10649 | editor.div.remove();
|
10650 | this.div.append(editor.div);
|
10651 | }
|
10652 | }
|
10653 | add(editor) {
|
10654 | this.#changeParent(editor);
|
10655 | this.#uiManager.addEditor(editor);
|
10656 | this.attach(editor);
|
10657 | if (!editor.isAttachedToDOM) {
|
10658 | const div = editor.render();
|
10659 | this.div.append(div);
|
10660 | editor.isAttachedToDOM = true;
|
10661 | }
|
10662 | this.moveEditorInDOM(editor);
|
10663 | editor.onceAdded();
|
10664 | this.#uiManager.addToAnnotationStorage(editor);
|
10665 | }
|
10666 | moveEditorInDOM(editor) {
|
10667 | this.#accessibilityManager?.moveElementInDOM(this.div, editor.div, editor.contentDiv, true);
|
10668 | }
|
10669 | addOrRebuild(editor) {
|
10670 | if (editor.needsToBeRebuilt()) {
|
10671 | editor.rebuild();
|
10672 | } else {
|
10673 | this.add(editor);
|
10674 | }
|
10675 | }
|
10676 | addANewEditor(editor) {
|
10677 | const cmd = () => {
|
10678 | this.addOrRebuild(editor);
|
10679 | };
|
10680 | const undo = () => {
|
10681 | editor.remove();
|
10682 | };
|
10683 | this.addCommands({
|
10684 | cmd,
|
10685 | undo,
|
10686 | mustExec: true
|
10687 | });
|
10688 | }
|
10689 | addUndoableEditor(editor) {
|
10690 | const cmd = () => {
|
10691 | this.addOrRebuild(editor);
|
10692 | };
|
10693 | const undo = () => {
|
10694 | editor.remove();
|
10695 | };
|
10696 | this.addCommands({
|
10697 | cmd,
|
10698 | undo,
|
10699 | mustExec: false
|
10700 | });
|
10701 | }
|
10702 | getNextId() {
|
10703 | return this.#uiManager.getId();
|
10704 | }
|
10705 | #createNewEditor(params) {
|
10706 | switch (this.#uiManager.getMode()) {
|
10707 | case _util.AnnotationEditorType.FREETEXT:
|
10708 | return new _freetext.FreeTextEditor(params);
|
10709 | case _util.AnnotationEditorType.INK:
|
10710 | return new _ink.InkEditor(params);
|
10711 | }
|
10712 | return null;
|
10713 | }
|
10714 | deserialize(data) {
|
10715 | switch (data.annotationType) {
|
10716 | case _util.AnnotationEditorType.FREETEXT:
|
10717 | return _freetext.FreeTextEditor.deserialize(data, this, this.#uiManager);
|
10718 | case _util.AnnotationEditorType.INK:
|
10719 | return _ink.InkEditor.deserialize(data, this, this.#uiManager);
|
10720 | }
|
10721 | return null;
|
10722 | }
|
10723 | #createAndAddNewEditor(event) {
|
10724 | const id = this.getNextId();
|
10725 | const editor = this.#createNewEditor({
|
10726 | parent: this,
|
10727 | id,
|
10728 | x: event.offsetX,
|
10729 | y: event.offsetY,
|
10730 | uiManager: this.#uiManager
|
10731 | });
|
10732 | if (editor) {
|
10733 | this.add(editor);
|
10734 | }
|
10735 | return editor;
|
10736 | }
|
10737 | setSelected(editor) {
|
10738 | this.#uiManager.setSelected(editor);
|
10739 | }
|
10740 | toggleSelected(editor) {
|
10741 | this.#uiManager.toggleSelected(editor);
|
10742 | }
|
10743 | isSelected(editor) {
|
10744 | return this.#uiManager.isSelected(editor);
|
10745 | }
|
10746 | unselect(editor) {
|
10747 | this.#uiManager.unselect(editor);
|
10748 | }
|
10749 | pointerup(event) {
|
10750 | const {
|
10751 | isMac
|
10752 | } = _util.FeatureTest.platform;
|
10753 | if (event.button !== 0 || event.ctrlKey && isMac) {
|
10754 | return;
|
10755 | }
|
10756 | if (event.target !== this.div) {
|
10757 | return;
|
10758 | }
|
10759 | if (!this.#hadPointerDown) {
|
10760 | return;
|
10761 | }
|
10762 | this.#hadPointerDown = false;
|
10763 | if (!this.#allowClick) {
|
10764 | this.#allowClick = true;
|
10765 | return;
|
10766 | }
|
10767 | this.#createAndAddNewEditor(event);
|
10768 | }
|
10769 | pointerdown(event) {
|
10770 | const {
|
10771 | isMac
|
10772 | } = _util.FeatureTest.platform;
|
10773 | if (event.button !== 0 || event.ctrlKey && isMac) {
|
10774 | return;
|
10775 | }
|
10776 | if (event.target !== this.div) {
|
10777 | return;
|
10778 | }
|
10779 | this.#hadPointerDown = true;
|
10780 | const editor = this.#uiManager.getActive();
|
10781 | this.#allowClick = !editor || editor.isEmpty();
|
10782 | }
|
10783 | drop(event) {
|
10784 | const id = event.dataTransfer.getData("text/plain");
|
10785 | const editor = this.#uiManager.getEditor(id);
|
10786 | if (!editor) {
|
10787 | return;
|
10788 | }
|
10789 | event.preventDefault();
|
10790 | event.dataTransfer.dropEffect = "move";
|
10791 | this.#changeParent(editor);
|
10792 | const rect = this.div.getBoundingClientRect();
|
10793 | const endX = event.clientX - rect.x;
|
10794 | const endY = event.clientY - rect.y;
|
10795 | editor.translate(endX - editor.startX, endY - editor.startY);
|
10796 | this.moveEditorInDOM(editor);
|
10797 | editor.div.focus();
|
10798 | }
|
10799 | dragover(event) {
|
10800 | event.preventDefault();
|
10801 | }
|
10802 | destroy() {
|
10803 | if (this.#uiManager.getActive()?.parent === this) {
|
10804 | this.#uiManager.setActiveEditor(null);
|
10805 | }
|
10806 | for (const editor of this.#editors.values()) {
|
10807 | this.#accessibilityManager?.removePointerInTextLayer(editor.contentDiv);
|
10808 | editor.setParent(null);
|
10809 | editor.isAttachedToDOM = false;
|
10810 | editor.div.remove();
|
10811 | }
|
10812 | this.div = null;
|
10813 | this.#editors.clear();
|
10814 | this.#uiManager.removeLayer(this);
|
10815 | }
|
10816 | #cleanup() {
|
10817 | this.#isCleaningUp = true;
|
10818 | for (const editor of this.#editors.values()) {
|
10819 | if (editor.isEmpty()) {
|
10820 | editor.remove();
|
10821 | }
|
10822 | }
|
10823 | this.#isCleaningUp = false;
|
10824 | }
|
10825 | render({
|
10826 | viewport
|
10827 | }) {
|
10828 | this.viewport = viewport;
|
10829 | (0, _display_utils.setLayerDimensions)(this.div, viewport);
|
10830 | (0, _tools.bindEvents)(this, this.div, ["dragover", "drop"]);
|
10831 | for (const editor of this.#uiManager.getEditors(this.pageIndex)) {
|
10832 | this.add(editor);
|
10833 | }
|
10834 | this.updateMode();
|
10835 | }
|
10836 | update({
|
10837 | viewport
|
10838 | }) {
|
10839 | this.#uiManager.commitOrRemove();
|
10840 | this.viewport = viewport;
|
10841 | (0, _display_utils.setLayerDimensions)(this.div, {
|
10842 | rotation: viewport.rotation
|
10843 | });
|
10844 | this.updateMode();
|
10845 | }
|
10846 | get pageDimensions() {
|
10847 | const {
|
10848 | pageWidth,
|
10849 | pageHeight
|
10850 | } = this.viewport.rawDims;
|
10851 | return [pageWidth, pageHeight];
|
10852 | }
|
10853 | }
|
10854 | exports.AnnotationEditorLayer = AnnotationEditorLayer;
|
10855 |
|
10856 | }),
|
10857 |
|
10858 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
10859 |
|
10860 |
|
10861 |
|
10862 | Object.defineProperty(exports, "__esModule", ({
|
10863 | value: true
|
10864 | }));
|
10865 | exports.FreeTextEditor = void 0;
|
10866 | var _util = __w_pdfjs_require__(1);
|
10867 | var _tools = __w_pdfjs_require__(5);
|
10868 | var _editor = __w_pdfjs_require__(4);
|
10869 | class FreeTextEditor extends _editor.AnnotationEditor {
|
10870 | #boundEditorDivBlur = this.editorDivBlur.bind(this);
|
10871 | #boundEditorDivFocus = this.editorDivFocus.bind(this);
|
10872 | #boundEditorDivInput = this.editorDivInput.bind(this);
|
10873 | #boundEditorDivKeydown = this.editorDivKeydown.bind(this);
|
10874 | #color;
|
10875 | #content = "";
|
10876 | #editorDivId = `${this.id}-editor`;
|
10877 | #hasAlreadyBeenCommitted = false;
|
10878 | #fontSize;
|
10879 | static _freeTextDefaultContent = "";
|
10880 | static _l10nPromise;
|
10881 | static _internalPadding = 0;
|
10882 | static _defaultColor = null;
|
10883 | static _defaultFontSize = 10;
|
10884 | static _keyboardManager = new _tools.KeyboardManager([[["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"], FreeTextEditor.prototype.commitOrRemove]]);
|
10885 | static _type = "freetext";
|
10886 | constructor(params) {
|
10887 | super({
|
10888 | ...params,
|
10889 | name: "freeTextEditor"
|
10890 | });
|
10891 | this.#color = params.color || FreeTextEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor;
|
10892 | this.#fontSize = params.fontSize || FreeTextEditor._defaultFontSize;
|
10893 | }
|
10894 | static initialize(l10n) {
|
10895 | this._l10nPromise = new Map(["free_text2_default_content", "editor_free_text2_aria_label"].map(str => [str, l10n.get(str)]));
|
10896 | const style = getComputedStyle(document.documentElement);
|
10897 | this._internalPadding = parseFloat(style.getPropertyValue("--freetext-padding"));
|
10898 | }
|
10899 | static updateDefaultParams(type, value) {
|
10900 | switch (type) {
|
10901 | case _util.AnnotationEditorParamsType.FREETEXT_SIZE:
|
10902 | FreeTextEditor._defaultFontSize = value;
|
10903 | break;
|
10904 | case _util.AnnotationEditorParamsType.FREETEXT_COLOR:
|
10905 | FreeTextEditor._defaultColor = value;
|
10906 | break;
|
10907 | }
|
10908 | }
|
10909 | updateParams(type, value) {
|
10910 | switch (type) {
|
10911 | case _util.AnnotationEditorParamsType.FREETEXT_SIZE:
|
10912 | this.#updateFontSize(value);
|
10913 | break;
|
10914 | case _util.AnnotationEditorParamsType.FREETEXT_COLOR:
|
10915 | this.#updateColor(value);
|
10916 | break;
|
10917 | }
|
10918 | }
|
10919 | static get defaultPropertiesToUpdate() {
|
10920 | return [[_util.AnnotationEditorParamsType.FREETEXT_SIZE, FreeTextEditor._defaultFontSize], [_util.AnnotationEditorParamsType.FREETEXT_COLOR, FreeTextEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor]];
|
10921 | }
|
10922 | get propertiesToUpdate() {
|
10923 | return [[_util.AnnotationEditorParamsType.FREETEXT_SIZE, this.#fontSize], [_util.AnnotationEditorParamsType.FREETEXT_COLOR, this.#color]];
|
10924 | }
|
10925 | #updateFontSize(fontSize) {
|
10926 | const setFontsize = size => {
|
10927 | this.editorDiv.style.fontSize = `calc(${size}px * var(--scale-factor))`;
|
10928 | this.translate(0, -(size - this.#fontSize) * this.parentScale);
|
10929 | this.#fontSize = size;
|
10930 | this.#setEditorDimensions();
|
10931 | };
|
10932 | const savedFontsize = this.#fontSize;
|
10933 | this.addCommands({
|
10934 | cmd: () => {
|
10935 | setFontsize(fontSize);
|
10936 | },
|
10937 | undo: () => {
|
10938 | setFontsize(savedFontsize);
|
10939 | },
|
10940 | mustExec: true,
|
10941 | type: _util.AnnotationEditorParamsType.FREETEXT_SIZE,
|
10942 | overwriteIfSameType: true,
|
10943 | keepUndo: true
|
10944 | });
|
10945 | }
|
10946 | #updateColor(color) {
|
10947 | const savedColor = this.#color;
|
10948 | this.addCommands({
|
10949 | cmd: () => {
|
10950 | this.#color = this.editorDiv.style.color = color;
|
10951 | },
|
10952 | undo: () => {
|
10953 | this.#color = this.editorDiv.style.color = savedColor;
|
10954 | },
|
10955 | mustExec: true,
|
10956 | type: _util.AnnotationEditorParamsType.FREETEXT_COLOR,
|
10957 | overwriteIfSameType: true,
|
10958 | keepUndo: true
|
10959 | });
|
10960 | }
|
10961 | getInitialTranslation() {
|
10962 | const scale = this.parentScale;
|
10963 | return [-FreeTextEditor._internalPadding * scale, -(FreeTextEditor._internalPadding + this.#fontSize) * scale];
|
10964 | }
|
10965 | rebuild() {
|
10966 | super.rebuild();
|
10967 | if (this.div === null) {
|
10968 | return;
|
10969 | }
|
10970 | if (!this.isAttachedToDOM) {
|
10971 | this.parent.add(this);
|
10972 | }
|
10973 | }
|
10974 | enableEditMode() {
|
10975 | if (this.isInEditMode()) {
|
10976 | return;
|
10977 | }
|
10978 | this.parent.setEditingState(false);
|
10979 | this.parent.updateToolbar(_util.AnnotationEditorType.FREETEXT);
|
10980 | super.enableEditMode();
|
10981 | this.overlayDiv.classList.remove("enabled");
|
10982 | this.editorDiv.contentEditable = true;
|
10983 | this.div.draggable = false;
|
10984 | this.div.removeAttribute("aria-activedescendant");
|
10985 | this.editorDiv.addEventListener("keydown", this.#boundEditorDivKeydown);
|
10986 | this.editorDiv.addEventListener("focus", this.#boundEditorDivFocus);
|
10987 | this.editorDiv.addEventListener("blur", this.#boundEditorDivBlur);
|
10988 | this.editorDiv.addEventListener("input", this.#boundEditorDivInput);
|
10989 | }
|
10990 | disableEditMode() {
|
10991 | if (!this.isInEditMode()) {
|
10992 | return;
|
10993 | }
|
10994 | this.parent.setEditingState(true);
|
10995 | super.disableEditMode();
|
10996 | this.overlayDiv.classList.add("enabled");
|
10997 | this.editorDiv.contentEditable = false;
|
10998 | this.div.setAttribute("aria-activedescendant", this.#editorDivId);
|
10999 | this.div.draggable = true;
|
11000 | this.editorDiv.removeEventListener("keydown", this.#boundEditorDivKeydown);
|
11001 | this.editorDiv.removeEventListener("focus", this.#boundEditorDivFocus);
|
11002 | this.editorDiv.removeEventListener("blur", this.#boundEditorDivBlur);
|
11003 | this.editorDiv.removeEventListener("input", this.#boundEditorDivInput);
|
11004 | this.div.focus({
|
11005 | preventScroll: true
|
11006 | });
|
11007 | this.isEditing = false;
|
11008 | this.parent.div.classList.add("freeTextEditing");
|
11009 | }
|
11010 | focusin(event) {
|
11011 | super.focusin(event);
|
11012 | if (event.target !== this.editorDiv) {
|
11013 | this.editorDiv.focus();
|
11014 | }
|
11015 | }
|
11016 | onceAdded() {
|
11017 | if (this.width) {
|
11018 | return;
|
11019 | }
|
11020 | this.enableEditMode();
|
11021 | this.editorDiv.focus();
|
11022 | }
|
11023 | isEmpty() {
|
11024 | return !this.editorDiv || this.editorDiv.innerText.trim() === "";
|
11025 | }
|
11026 | remove() {
|
11027 | this.isEditing = false;
|
11028 | this.parent.setEditingState(true);
|
11029 | this.parent.div.classList.add("freeTextEditing");
|
11030 | super.remove();
|
11031 | }
|
11032 | #extractText() {
|
11033 | const divs = this.editorDiv.getElementsByTagName("div");
|
11034 | if (divs.length === 0) {
|
11035 | return this.editorDiv.innerText;
|
11036 | }
|
11037 | const buffer = [];
|
11038 | for (const div of divs) {
|
11039 | buffer.push(div.innerText.replace(/\r\n?|\n/, ""));
|
11040 | }
|
11041 | return buffer.join("\n");
|
11042 | }
|
11043 | #setEditorDimensions() {
|
11044 | const [parentWidth, parentHeight] = this.parentDimensions;
|
11045 | let rect;
|
11046 | if (this.isAttachedToDOM) {
|
11047 | rect = this.div.getBoundingClientRect();
|
11048 | } else {
|
11049 | const {
|
11050 | currentLayer,
|
11051 | div
|
11052 | } = this;
|
11053 | const savedDisplay = div.style.display;
|
11054 | div.style.display = "hidden";
|
11055 | currentLayer.div.append(this.div);
|
11056 | rect = div.getBoundingClientRect();
|
11057 | div.remove();
|
11058 | div.style.display = savedDisplay;
|
11059 | }
|
11060 | this.width = rect.width / parentWidth;
|
11061 | this.height = rect.height / parentHeight;
|
11062 | }
|
11063 | commit() {
|
11064 | if (!this.isInEditMode()) {
|
11065 | return;
|
11066 | }
|
11067 | super.commit();
|
11068 | if (!this.#hasAlreadyBeenCommitted) {
|
11069 | this.#hasAlreadyBeenCommitted = true;
|
11070 | this.parent.addUndoableEditor(this);
|
11071 | }
|
11072 | this.disableEditMode();
|
11073 | this.#content = this.#extractText().trimEnd();
|
11074 | this.#setEditorDimensions();
|
11075 | }
|
11076 | shouldGetKeyboardEvents() {
|
11077 | return this.isInEditMode();
|
11078 | }
|
11079 | dblclick(event) {
|
11080 | this.enableEditMode();
|
11081 | this.editorDiv.focus();
|
11082 | }
|
11083 | keydown(event) {
|
11084 | if (event.target === this.div && event.key === "Enter") {
|
11085 | this.enableEditMode();
|
11086 | this.editorDiv.focus();
|
11087 | }
|
11088 | }
|
11089 | editorDivKeydown(event) {
|
11090 | FreeTextEditor._keyboardManager.exec(this, event);
|
11091 | }
|
11092 | editorDivFocus(event) {
|
11093 | this.isEditing = true;
|
11094 | }
|
11095 | editorDivBlur(event) {
|
11096 | this.isEditing = false;
|
11097 | }
|
11098 | editorDivInput(event) {
|
11099 | this.parent.div.classList.toggle("freeTextEditing", this.isEmpty());
|
11100 | }
|
11101 | disableEditing() {
|
11102 | this.editorDiv.setAttribute("role", "comment");
|
11103 | this.editorDiv.removeAttribute("aria-multiline");
|
11104 | }
|
11105 | enableEditing() {
|
11106 | this.editorDiv.setAttribute("role", "textbox");
|
11107 | this.editorDiv.setAttribute("aria-multiline", true);
|
11108 | }
|
11109 | render() {
|
11110 | if (this.div) {
|
11111 | return this.div;
|
11112 | }
|
11113 | let baseX, baseY;
|
11114 | if (this.width) {
|
11115 | baseX = this.x;
|
11116 | baseY = this.y;
|
11117 | }
|
11118 | super.render();
|
11119 | this.editorDiv = document.createElement("div");
|
11120 | this.editorDiv.className = "internal";
|
11121 | this.editorDiv.setAttribute("id", this.#editorDivId);
|
11122 | this.enableEditing();
|
11123 | FreeTextEditor._l10nPromise.get("editor_free_text2_aria_label").then(msg => this.editorDiv?.setAttribute("aria-label", msg));
|
11124 | FreeTextEditor._l10nPromise.get("free_text2_default_content").then(msg => this.editorDiv?.setAttribute("default-content", msg));
|
11125 | this.editorDiv.contentEditable = true;
|
11126 | const {
|
11127 | style
|
11128 | } = this.editorDiv;
|
11129 | style.fontSize = `calc(${this.#fontSize}px * var(--scale-factor))`;
|
11130 | style.color = this.#color;
|
11131 | this.div.append(this.editorDiv);
|
11132 | this.overlayDiv = document.createElement("div");
|
11133 | this.overlayDiv.classList.add("overlay", "enabled");
|
11134 | this.div.append(this.overlayDiv);
|
11135 | (0, _tools.bindEvents)(this, this.div, ["dblclick", "keydown"]);
|
11136 | if (this.width) {
|
11137 | const [parentWidth, parentHeight] = this.parentDimensions;
|
11138 | this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
|
11139 | for (const line of this.#content.split("\n")) {
|
11140 | const div = document.createElement("div");
|
11141 | div.append(line ? document.createTextNode(line) : document.createElement("br"));
|
11142 | this.editorDiv.append(div);
|
11143 | }
|
11144 | this.div.draggable = true;
|
11145 | this.editorDiv.contentEditable = false;
|
11146 | } else {
|
11147 | this.div.draggable = false;
|
11148 | this.editorDiv.contentEditable = true;
|
11149 | }
|
11150 | return this.div;
|
11151 | }
|
11152 | get contentDiv() {
|
11153 | return this.editorDiv;
|
11154 | }
|
11155 | static deserialize(data, parent, uiManager) {
|
11156 | const editor = super.deserialize(data, parent, uiManager);
|
11157 | editor.#fontSize = data.fontSize;
|
11158 | editor.#color = _util.Util.makeHexColor(...data.color);
|
11159 | editor.#content = data.value;
|
11160 | return editor;
|
11161 | }
|
11162 | serialize() {
|
11163 | if (this.isEmpty()) {
|
11164 | return null;
|
11165 | }
|
11166 | const padding = FreeTextEditor._internalPadding * this.parentScale;
|
11167 | const rect = this.getRect(padding, padding);
|
11168 | const color = _editor.AnnotationEditor._colorManager.convert(this.isAttachedToDOM ? getComputedStyle(this.editorDiv).color : this.#color);
|
11169 | return {
|
11170 | annotationType: _util.AnnotationEditorType.FREETEXT,
|
11171 | color,
|
11172 | fontSize: this.#fontSize,
|
11173 | value: this.#content,
|
11174 | pageIndex: this.pageIndex,
|
11175 | rect,
|
11176 | rotation: this.rotation
|
11177 | };
|
11178 | }
|
11179 | }
|
11180 | exports.FreeTextEditor = FreeTextEditor;
|
11181 |
|
11182 | }),
|
11183 |
|
11184 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
11185 |
|
11186 |
|
11187 |
|
11188 | Object.defineProperty(exports, "__esModule", ({
|
11189 | value: true
|
11190 | }));
|
11191 | exports.InkEditor = void 0;
|
11192 | var _util = __w_pdfjs_require__(1);
|
11193 | var _editor = __w_pdfjs_require__(4);
|
11194 | var _tools = __w_pdfjs_require__(5);
|
11195 | const RESIZER_SIZE = 16;
|
11196 | class InkEditor extends _editor.AnnotationEditor {
|
11197 | #aspectRatio = 0;
|
11198 | #baseHeight = 0;
|
11199 | #baseWidth = 0;
|
11200 | #boundCanvasContextMenu = this.canvasContextMenu.bind(this);
|
11201 | #boundCanvasPointermove = this.canvasPointermove.bind(this);
|
11202 | #boundCanvasPointerleave = this.canvasPointerleave.bind(this);
|
11203 | #boundCanvasPointerup = this.canvasPointerup.bind(this);
|
11204 | #boundCanvasPointerdown = this.canvasPointerdown.bind(this);
|
11205 | #currentPath2D = new Path2D();
|
11206 | #disableEditing = false;
|
11207 | #hasSomethingToDraw = false;
|
11208 | #isCanvasInitialized = false;
|
11209 | #observer = null;
|
11210 | #realWidth = 0;
|
11211 | #realHeight = 0;
|
11212 | #requestFrameCallback = null;
|
11213 | static _defaultColor = null;
|
11214 | static _defaultOpacity = 1;
|
11215 | static _defaultThickness = 1;
|
11216 | static _l10nPromise;
|
11217 | static _type = "ink";
|
11218 | constructor(params) {
|
11219 | super({
|
11220 | ...params,
|
11221 | name: "inkEditor"
|
11222 | });
|
11223 | this.color = params.color || null;
|
11224 | this.thickness = params.thickness || null;
|
11225 | this.opacity = params.opacity || null;
|
11226 | this.paths = [];
|
11227 | this.bezierPath2D = [];
|
11228 | this.allRawPaths = [];
|
11229 | this.currentPath = [];
|
11230 | this.scaleFactor = 1;
|
11231 | this.translationX = this.translationY = 0;
|
11232 | this.x = 0;
|
11233 | this.y = 0;
|
11234 | }
|
11235 | static initialize(l10n) {
|
11236 | this._l10nPromise = new Map(["editor_ink_canvas_aria_label", "editor_ink2_aria_label"].map(str => [str, l10n.get(str)]));
|
11237 | }
|
11238 | static updateDefaultParams(type, value) {
|
11239 | switch (type) {
|
11240 | case _util.AnnotationEditorParamsType.INK_THICKNESS:
|
11241 | InkEditor._defaultThickness = value;
|
11242 | break;
|
11243 | case _util.AnnotationEditorParamsType.INK_COLOR:
|
11244 | InkEditor._defaultColor = value;
|
11245 | break;
|
11246 | case _util.AnnotationEditorParamsType.INK_OPACITY:
|
11247 | InkEditor._defaultOpacity = value / 100;
|
11248 | break;
|
11249 | }
|
11250 | }
|
11251 | updateParams(type, value) {
|
11252 | switch (type) {
|
11253 | case _util.AnnotationEditorParamsType.INK_THICKNESS:
|
11254 | this.#updateThickness(value);
|
11255 | break;
|
11256 | case _util.AnnotationEditorParamsType.INK_COLOR:
|
11257 | this.#updateColor(value);
|
11258 | break;
|
11259 | case _util.AnnotationEditorParamsType.INK_OPACITY:
|
11260 | this.#updateOpacity(value);
|
11261 | break;
|
11262 | }
|
11263 | }
|
11264 | static get defaultPropertiesToUpdate() {
|
11265 | return [[_util.AnnotationEditorParamsType.INK_THICKNESS, InkEditor._defaultThickness], [_util.AnnotationEditorParamsType.INK_COLOR, InkEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor], [_util.AnnotationEditorParamsType.INK_OPACITY, Math.round(InkEditor._defaultOpacity * 100)]];
|
11266 | }
|
11267 | get propertiesToUpdate() {
|
11268 | return [[_util.AnnotationEditorParamsType.INK_THICKNESS, this.thickness || InkEditor._defaultThickness], [_util.AnnotationEditorParamsType.INK_COLOR, this.color || InkEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor], [_util.AnnotationEditorParamsType.INK_OPACITY, Math.round(100 * (this.opacity ?? InkEditor._defaultOpacity))]];
|
11269 | }
|
11270 | #updateThickness(thickness) {
|
11271 | const savedThickness = this.thickness;
|
11272 | this.addCommands({
|
11273 | cmd: () => {
|
11274 | this.thickness = thickness;
|
11275 | this.#fitToContent();
|
11276 | },
|
11277 | undo: () => {
|
11278 | this.thickness = savedThickness;
|
11279 | this.#fitToContent();
|
11280 | },
|
11281 | mustExec: true,
|
11282 | type: _util.AnnotationEditorParamsType.INK_THICKNESS,
|
11283 | overwriteIfSameType: true,
|
11284 | keepUndo: true
|
11285 | });
|
11286 | }
|
11287 | #updateColor(color) {
|
11288 | const savedColor = this.color;
|
11289 | this.addCommands({
|
11290 | cmd: () => {
|
11291 | this.color = color;
|
11292 | this.#redraw();
|
11293 | },
|
11294 | undo: () => {
|
11295 | this.color = savedColor;
|
11296 | this.#redraw();
|
11297 | },
|
11298 | mustExec: true,
|
11299 | type: _util.AnnotationEditorParamsType.INK_COLOR,
|
11300 | overwriteIfSameType: true,
|
11301 | keepUndo: true
|
11302 | });
|
11303 | }
|
11304 | #updateOpacity(opacity) {
|
11305 | opacity /= 100;
|
11306 | const savedOpacity = this.opacity;
|
11307 | this.addCommands({
|
11308 | cmd: () => {
|
11309 | this.opacity = opacity;
|
11310 | this.#redraw();
|
11311 | },
|
11312 | undo: () => {
|
11313 | this.opacity = savedOpacity;
|
11314 | this.#redraw();
|
11315 | },
|
11316 | mustExec: true,
|
11317 | type: _util.AnnotationEditorParamsType.INK_OPACITY,
|
11318 | overwriteIfSameType: true,
|
11319 | keepUndo: true
|
11320 | });
|
11321 | }
|
11322 | rebuild() {
|
11323 | super.rebuild();
|
11324 | if (this.div === null) {
|
11325 | return;
|
11326 | }
|
11327 | if (!this.canvas) {
|
11328 | this.#createCanvas();
|
11329 | this.#createObserver();
|
11330 | }
|
11331 | if (!this.isAttachedToDOM) {
|
11332 | this.parent.add(this);
|
11333 | this.#setCanvasDims();
|
11334 | }
|
11335 | this.#fitToContent();
|
11336 | }
|
11337 | remove() {
|
11338 | if (this.canvas === null) {
|
11339 | return;
|
11340 | }
|
11341 | if (!this.isEmpty()) {
|
11342 | this.commit();
|
11343 | }
|
11344 | this.canvas.width = this.canvas.height = 0;
|
11345 | this.canvas.remove();
|
11346 | this.canvas = null;
|
11347 | this.#observer.disconnect();
|
11348 | this.#observer = null;
|
11349 | super.remove();
|
11350 | }
|
11351 | setParent(parent) {
|
11352 | if (!this.parent && parent) {
|
11353 | this._uiManager.removeShouldRescale(this);
|
11354 | } else if (this.parent && parent === null) {
|
11355 | this._uiManager.addShouldRescale(this);
|
11356 | }
|
11357 | super.setParent(parent);
|
11358 | }
|
11359 | onScaleChanging() {
|
11360 | const [parentWidth, parentHeight] = this.parentDimensions;
|
11361 | const width = this.width * parentWidth;
|
11362 | const height = this.height * parentHeight;
|
11363 | this.setDimensions(width, height);
|
11364 | }
|
11365 | enableEditMode() {
|
11366 | if (this.#disableEditing || this.canvas === null) {
|
11367 | return;
|
11368 | }
|
11369 | super.enableEditMode();
|
11370 | this.div.draggable = false;
|
11371 | this.canvas.addEventListener("pointerdown", this.#boundCanvasPointerdown);
|
11372 | }
|
11373 | disableEditMode() {
|
11374 | if (!this.isInEditMode() || this.canvas === null) {
|
11375 | return;
|
11376 | }
|
11377 | super.disableEditMode();
|
11378 | this.div.draggable = !this.isEmpty();
|
11379 | this.div.classList.remove("editing");
|
11380 | this.canvas.removeEventListener("pointerdown", this.#boundCanvasPointerdown);
|
11381 | }
|
11382 | onceAdded() {
|
11383 | this.div.draggable = !this.isEmpty();
|
11384 | }
|
11385 | isEmpty() {
|
11386 | return this.paths.length === 0 || this.paths.length === 1 && this.paths[0].length === 0;
|
11387 | }
|
11388 | #getInitialBBox() {
|
11389 | const {
|
11390 | parentRotation,
|
11391 | parentDimensions: [width, height]
|
11392 | } = this;
|
11393 | switch (parentRotation) {
|
11394 | case 90:
|
11395 | return [0, height, height, width];
|
11396 | case 180:
|
11397 | return [width, height, width, height];
|
11398 | case 270:
|
11399 | return [width, 0, height, width];
|
11400 | default:
|
11401 | return [0, 0, width, height];
|
11402 | }
|
11403 | }
|
11404 | #setStroke() {
|
11405 | const {
|
11406 | ctx,
|
11407 | color,
|
11408 | opacity,
|
11409 | thickness,
|
11410 | parentScale,
|
11411 | scaleFactor
|
11412 | } = this;
|
11413 | ctx.lineWidth = thickness * parentScale / scaleFactor;
|
11414 | ctx.lineCap = "round";
|
11415 | ctx.lineJoin = "round";
|
11416 | ctx.miterLimit = 10;
|
11417 | ctx.strokeStyle = `${color}${(0, _tools.opacityToHex)(opacity)}`;
|
11418 | }
|
11419 | #startDrawing(x, y) {
|
11420 | this.canvas.addEventListener("contextmenu", this.#boundCanvasContextMenu);
|
11421 | this.canvas.addEventListener("pointerleave", this.#boundCanvasPointerleave);
|
11422 | this.canvas.addEventListener("pointermove", this.#boundCanvasPointermove);
|
11423 | this.canvas.addEventListener("pointerup", this.#boundCanvasPointerup);
|
11424 | this.canvas.removeEventListener("pointerdown", this.#boundCanvasPointerdown);
|
11425 | this.isEditing = true;
|
11426 | if (!this.#isCanvasInitialized) {
|
11427 | this.#isCanvasInitialized = true;
|
11428 | this.#setCanvasDims();
|
11429 | this.thickness ||= InkEditor._defaultThickness;
|
11430 | this.color ||= InkEditor._defaultColor || _editor.AnnotationEditor._defaultLineColor;
|
11431 | this.opacity ??= InkEditor._defaultOpacity;
|
11432 | }
|
11433 | this.currentPath.push([x, y]);
|
11434 | this.#hasSomethingToDraw = false;
|
11435 | this.#setStroke();
|
11436 | this.#requestFrameCallback = () => {
|
11437 | this.#drawPoints();
|
11438 | if (this.#requestFrameCallback) {
|
11439 | window.requestAnimationFrame(this.#requestFrameCallback);
|
11440 | }
|
11441 | };
|
11442 | window.requestAnimationFrame(this.#requestFrameCallback);
|
11443 | }
|
11444 | #draw(x, y) {
|
11445 | const [lastX, lastY] = this.currentPath.at(-1);
|
11446 | if (this.currentPath.length > 1 && x === lastX && y === lastY) {
|
11447 | return;
|
11448 | }
|
11449 | const currentPath = this.currentPath;
|
11450 | let path2D = this.#currentPath2D;
|
11451 | currentPath.push([x, y]);
|
11452 | this.#hasSomethingToDraw = true;
|
11453 | if (currentPath.length <= 2) {
|
11454 | path2D.moveTo(...currentPath[0]);
|
11455 | path2D.lineTo(x, y);
|
11456 | return;
|
11457 | }
|
11458 | if (currentPath.length === 3) {
|
11459 | this.#currentPath2D = path2D = new Path2D();
|
11460 | path2D.moveTo(...currentPath[0]);
|
11461 | }
|
11462 | this.#makeBezierCurve(path2D, ...currentPath.at(-3), ...currentPath.at(-2), x, y);
|
11463 | }
|
11464 | #endPath() {
|
11465 | if (this.currentPath.length === 0) {
|
11466 | return;
|
11467 | }
|
11468 | const lastPoint = this.currentPath.at(-1);
|
11469 | this.#currentPath2D.lineTo(...lastPoint);
|
11470 | }
|
11471 | #stopDrawing(x, y) {
|
11472 | this.#requestFrameCallback = null;
|
11473 | x = Math.min(Math.max(x, 0), this.canvas.width);
|
11474 | y = Math.min(Math.max(y, 0), this.canvas.height);
|
11475 | this.#draw(x, y);
|
11476 | this.#endPath();
|
11477 | let bezier;
|
11478 | if (this.currentPath.length !== 1) {
|
11479 | bezier = this.#generateBezierPoints();
|
11480 | } else {
|
11481 | const xy = [x, y];
|
11482 | bezier = [[xy, xy.slice(), xy.slice(), xy]];
|
11483 | }
|
11484 | const path2D = this.#currentPath2D;
|
11485 | const currentPath = this.currentPath;
|
11486 | this.currentPath = [];
|
11487 | this.#currentPath2D = new Path2D();
|
11488 | const cmd = () => {
|
11489 | this.allRawPaths.push(currentPath);
|
11490 | this.paths.push(bezier);
|
11491 | this.bezierPath2D.push(path2D);
|
11492 | this.rebuild();
|
11493 | };
|
11494 | const undo = () => {
|
11495 | this.allRawPaths.pop();
|
11496 | this.paths.pop();
|
11497 | this.bezierPath2D.pop();
|
11498 | if (this.paths.length === 0) {
|
11499 | this.remove();
|
11500 | } else {
|
11501 | if (!this.canvas) {
|
11502 | this.#createCanvas();
|
11503 | this.#createObserver();
|
11504 | }
|
11505 | this.#fitToContent();
|
11506 | }
|
11507 | };
|
11508 | this.addCommands({
|
11509 | cmd,
|
11510 | undo,
|
11511 | mustExec: true
|
11512 | });
|
11513 | }
|
11514 | #drawPoints() {
|
11515 | if (!this.#hasSomethingToDraw) {
|
11516 | return;
|
11517 | }
|
11518 | this.#hasSomethingToDraw = false;
|
11519 | const thickness = Math.ceil(this.thickness * this.parentScale);
|
11520 | const lastPoints = this.currentPath.slice(-3);
|
11521 | const x = lastPoints.map(xy => xy[0]);
|
11522 | const y = lastPoints.map(xy => xy[1]);
|
11523 | const xMin = Math.min(...x) - thickness;
|
11524 | const xMax = Math.max(...x) + thickness;
|
11525 | const yMin = Math.min(...y) - thickness;
|
11526 | const yMax = Math.max(...y) + thickness;
|
11527 | const {
|
11528 | ctx
|
11529 | } = this;
|
11530 | ctx.save();
|
11531 | ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
11532 | for (const path of this.bezierPath2D) {
|
11533 | ctx.stroke(path);
|
11534 | }
|
11535 | ctx.stroke(this.#currentPath2D);
|
11536 | ctx.restore();
|
11537 | }
|
11538 | #makeBezierCurve(path2D, x0, y0, x1, y1, x2, y2) {
|
11539 | const prevX = (x0 + x1) / 2;
|
11540 | const prevY = (y0 + y1) / 2;
|
11541 | const x3 = (x1 + x2) / 2;
|
11542 | const y3 = (y1 + y2) / 2;
|
11543 | path2D.bezierCurveTo(prevX + 2 * (x1 - prevX) / 3, prevY + 2 * (y1 - prevY) / 3, x3 + 2 * (x1 - x3) / 3, y3 + 2 * (y1 - y3) / 3, x3, y3);
|
11544 | }
|
11545 | #generateBezierPoints() {
|
11546 | const path = this.currentPath;
|
11547 | if (path.length <= 2) {
|
11548 | return [[path[0], path[0], path.at(-1), path.at(-1)]];
|
11549 | }
|
11550 | const bezierPoints = [];
|
11551 | let i;
|
11552 | let [x0, y0] = path[0];
|
11553 | for (i = 1; i < path.length - 2; i++) {
|
11554 | const [x1, y1] = path[i];
|
11555 | const [x2, y2] = path[i + 1];
|
11556 | const x3 = (x1 + x2) / 2;
|
11557 | const y3 = (y1 + y2) / 2;
|
11558 | const control1 = [x0 + 2 * (x1 - x0) / 3, y0 + 2 * (y1 - y0) / 3];
|
11559 | const control2 = [x3 + 2 * (x1 - x3) / 3, y3 + 2 * (y1 - y3) / 3];
|
11560 | bezierPoints.push([[x0, y0], control1, control2, [x3, y3]]);
|
11561 | [x0, y0] = [x3, y3];
|
11562 | }
|
11563 | const [x1, y1] = path[i];
|
11564 | const [x2, y2] = path[i + 1];
|
11565 | const control1 = [x0 + 2 * (x1 - x0) / 3, y0 + 2 * (y1 - y0) / 3];
|
11566 | const control2 = [x2 + 2 * (x1 - x2) / 3, y2 + 2 * (y1 - y2) / 3];
|
11567 | bezierPoints.push([[x0, y0], control1, control2, [x2, y2]]);
|
11568 | return bezierPoints;
|
11569 | }
|
11570 | #redraw() {
|
11571 | if (this.isEmpty()) {
|
11572 | this.#updateTransform();
|
11573 | return;
|
11574 | }
|
11575 | this.#setStroke();
|
11576 | const {
|
11577 | canvas,
|
11578 | ctx
|
11579 | } = this;
|
11580 | ctx.setTransform(1, 0, 0, 1, 0, 0);
|
11581 | ctx.clearRect(0, 0, canvas.width, canvas.height);
|
11582 | this.#updateTransform();
|
11583 | for (const path of this.bezierPath2D) {
|
11584 | ctx.stroke(path);
|
11585 | }
|
11586 | }
|
11587 | commit() {
|
11588 | if (this.#disableEditing) {
|
11589 | return;
|
11590 | }
|
11591 | super.commit();
|
11592 | this.isEditing = false;
|
11593 | this.disableEditMode();
|
11594 | this.setInForeground();
|
11595 | this.#disableEditing = true;
|
11596 | this.div.classList.add("disabled");
|
11597 | this.#fitToContent(true);
|
11598 | this.parent.addInkEditorIfNeeded(true);
|
11599 | this.parent.moveEditorInDOM(this);
|
11600 | this.div.focus({
|
11601 | preventScroll: true
|
11602 | });
|
11603 | }
|
11604 | focusin(event) {
|
11605 | super.focusin(event);
|
11606 | this.enableEditMode();
|
11607 | }
|
11608 | canvasPointerdown(event) {
|
11609 | if (event.button !== 0 || !this.isInEditMode() || this.#disableEditing) {
|
11610 | return;
|
11611 | }
|
11612 | this.setInForeground();
|
11613 | event.preventDefault();
|
11614 | if (event.type !== "mouse") {
|
11615 | this.div.focus();
|
11616 | }
|
11617 | this.#startDrawing(event.offsetX, event.offsetY);
|
11618 | }
|
11619 | canvasContextMenu(event) {
|
11620 | event.preventDefault();
|
11621 | }
|
11622 | canvasPointermove(event) {
|
11623 | event.preventDefault();
|
11624 | this.#draw(event.offsetX, event.offsetY);
|
11625 | }
|
11626 | canvasPointerup(event) {
|
11627 | event.preventDefault();
|
11628 | this.#endDrawing(event);
|
11629 | }
|
11630 | canvasPointerleave(event) {
|
11631 | this.#endDrawing(event);
|
11632 | }
|
11633 | #endDrawing(event) {
|
11634 | this.canvas.removeEventListener("pointerleave", this.#boundCanvasPointerleave);
|
11635 | this.canvas.removeEventListener("pointermove", this.#boundCanvasPointermove);
|
11636 | this.canvas.removeEventListener("pointerup", this.#boundCanvasPointerup);
|
11637 | this.canvas.addEventListener("pointerdown", this.#boundCanvasPointerdown);
|
11638 | setTimeout(() => {
|
11639 | this.canvas.removeEventListener("contextmenu", this.#boundCanvasContextMenu);
|
11640 | }, 10);
|
11641 | this.#stopDrawing(event.offsetX, event.offsetY);
|
11642 | this.addToAnnotationStorage();
|
11643 | this.setInBackground();
|
11644 | }
|
11645 | #createCanvas() {
|
11646 | this.canvas = document.createElement("canvas");
|
11647 | this.canvas.width = this.canvas.height = 0;
|
11648 | this.canvas.className = "inkEditorCanvas";
|
11649 | InkEditor._l10nPromise.get("editor_ink_canvas_aria_label").then(msg => this.canvas?.setAttribute("aria-label", msg));
|
11650 | this.div.append(this.canvas);
|
11651 | this.ctx = this.canvas.getContext("2d");
|
11652 | }
|
11653 | #createObserver() {
|
11654 | this.#observer = new ResizeObserver(entries => {
|
11655 | const rect = entries[0].contentRect;
|
11656 | if (rect.width && rect.height) {
|
11657 | this.setDimensions(rect.width, rect.height);
|
11658 | }
|
11659 | });
|
11660 | this.#observer.observe(this.div);
|
11661 | }
|
11662 | render() {
|
11663 | if (this.div) {
|
11664 | return this.div;
|
11665 | }
|
11666 | let baseX, baseY;
|
11667 | if (this.width) {
|
11668 | baseX = this.x;
|
11669 | baseY = this.y;
|
11670 | }
|
11671 | super.render();
|
11672 | InkEditor._l10nPromise.get("editor_ink2_aria_label").then(msg => this.div?.setAttribute("aria-label", msg));
|
11673 | const [x, y, w, h] = this.#getInitialBBox();
|
11674 | this.setAt(x, y, 0, 0);
|
11675 | this.setDims(w, h);
|
11676 | this.#createCanvas();
|
11677 | if (this.width) {
|
11678 | const [parentWidth, parentHeight] = this.parentDimensions;
|
11679 | this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
|
11680 | this.#isCanvasInitialized = true;
|
11681 | this.#setCanvasDims();
|
11682 | this.setDims(this.width * parentWidth, this.height * parentHeight);
|
11683 | this.#redraw();
|
11684 | this.#setMinDims();
|
11685 | this.div.classList.add("disabled");
|
11686 | } else {
|
11687 | this.div.classList.add("editing");
|
11688 | this.enableEditMode();
|
11689 | }
|
11690 | this.#createObserver();
|
11691 | return this.div;
|
11692 | }
|
11693 | #setCanvasDims() {
|
11694 | if (!this.#isCanvasInitialized) {
|
11695 | return;
|
11696 | }
|
11697 | const [parentWidth, parentHeight] = this.parentDimensions;
|
11698 | this.canvas.width = Math.ceil(this.width * parentWidth);
|
11699 | this.canvas.height = Math.ceil(this.height * parentHeight);
|
11700 | this.#updateTransform();
|
11701 | }
|
11702 | setDimensions(width, height) {
|
11703 | const roundedWidth = Math.round(width);
|
11704 | const roundedHeight = Math.round(height);
|
11705 | if (this.#realWidth === roundedWidth && this.#realHeight === roundedHeight) {
|
11706 | return;
|
11707 | }
|
11708 | this.#realWidth = roundedWidth;
|
11709 | this.#realHeight = roundedHeight;
|
11710 | this.canvas.style.visibility = "hidden";
|
11711 | if (this.#aspectRatio && Math.abs(this.#aspectRatio - width / height) > 1e-2) {
|
11712 | height = Math.ceil(width / this.#aspectRatio);
|
11713 | this.setDims(width, height);
|
11714 | }
|
11715 | const [parentWidth, parentHeight] = this.parentDimensions;
|
11716 | this.width = width / parentWidth;
|
11717 | this.height = height / parentHeight;
|
11718 | if (this.#disableEditing) {
|
11719 | this.#setScaleFactor(width, height);
|
11720 | }
|
11721 | this.#setCanvasDims();
|
11722 | this.#redraw();
|
11723 | this.canvas.style.visibility = "visible";
|
11724 | this.fixDims();
|
11725 | }
|
11726 | #setScaleFactor(width, height) {
|
11727 | const padding = this.#getPadding();
|
11728 | const scaleFactorW = (width - padding) / this.#baseWidth;
|
11729 | const scaleFactorH = (height - padding) / this.#baseHeight;
|
11730 | this.scaleFactor = Math.min(scaleFactorW, scaleFactorH);
|
11731 | }
|
11732 | #updateTransform() {
|
11733 | const padding = this.#getPadding() / 2;
|
11734 | this.ctx.setTransform(this.scaleFactor, 0, 0, this.scaleFactor, this.translationX * this.scaleFactor + padding, this.translationY * this.scaleFactor + padding);
|
11735 | }
|
11736 | static #buildPath2D(bezier) {
|
11737 | const path2D = new Path2D();
|
11738 | for (let i = 0, ii = bezier.length; i < ii; i++) {
|
11739 | const [first, control1, control2, second] = bezier[i];
|
11740 | if (i === 0) {
|
11741 | path2D.moveTo(...first);
|
11742 | }
|
11743 | path2D.bezierCurveTo(control1[0], control1[1], control2[0], control2[1], second[0], second[1]);
|
11744 | }
|
11745 | return path2D;
|
11746 | }
|
11747 | #serializePaths(s, tx, ty, h) {
|
11748 | const NUMBER_OF_POINTS_ON_BEZIER_CURVE = 4;
|
11749 | const paths = [];
|
11750 | const padding = this.thickness / 2;
|
11751 | let buffer, points;
|
11752 | for (const bezier of this.paths) {
|
11753 | buffer = [];
|
11754 | points = [];
|
11755 | for (let i = 0, ii = bezier.length; i < ii; i++) {
|
11756 | const [first, control1, control2, second] = bezier[i];
|
11757 | const p10 = s * (first[0] + tx) + padding;
|
11758 | const p11 = h - s * (first[1] + ty) - padding;
|
11759 | const p20 = s * (control1[0] + tx) + padding;
|
11760 | const p21 = h - s * (control1[1] + ty) - padding;
|
11761 | const p30 = s * (control2[0] + tx) + padding;
|
11762 | const p31 = h - s * (control2[1] + ty) - padding;
|
11763 | const p40 = s * (second[0] + tx) + padding;
|
11764 | const p41 = h - s * (second[1] + ty) - padding;
|
11765 | if (i === 0) {
|
11766 | buffer.push(p10, p11);
|
11767 | points.push(p10, p11);
|
11768 | }
|
11769 | buffer.push(p20, p21, p30, p31, p40, p41);
|
11770 | this.#extractPointsOnBezier(p10, p11, p20, p21, p30, p31, p40, p41, NUMBER_OF_POINTS_ON_BEZIER_CURVE, points);
|
11771 | }
|
11772 | paths.push({
|
11773 | bezier: buffer,
|
11774 | points
|
11775 | });
|
11776 | }
|
11777 | return paths;
|
11778 | }
|
11779 | #extractPointsOnBezier(p10, p11, p20, p21, p30, p31, p40, p41, n, points) {
|
11780 | if (this.#isAlmostFlat(p10, p11, p20, p21, p30, p31, p40, p41)) {
|
11781 | points.push(p40, p41);
|
11782 | return;
|
11783 | }
|
11784 | for (let i = 1; i < n - 1; i++) {
|
11785 | const t = i / n;
|
11786 | const mt = 1 - t;
|
11787 | let q10 = t * p10 + mt * p20;
|
11788 | let q11 = t * p11 + mt * p21;
|
11789 | let q20 = t * p20 + mt * p30;
|
11790 | let q21 = t * p21 + mt * p31;
|
11791 | const q30 = t * p30 + mt * p40;
|
11792 | const q31 = t * p31 + mt * p41;
|
11793 | q10 = t * q10 + mt * q20;
|
11794 | q11 = t * q11 + mt * q21;
|
11795 | q20 = t * q20 + mt * q30;
|
11796 | q21 = t * q21 + mt * q31;
|
11797 | q10 = t * q10 + mt * q20;
|
11798 | q11 = t * q11 + mt * q21;
|
11799 | points.push(q10, q11);
|
11800 | }
|
11801 | points.push(p40, p41);
|
11802 | }
|
11803 | #isAlmostFlat(p10, p11, p20, p21, p30, p31, p40, p41) {
|
11804 | const tol = 10;
|
11805 | const ax = (3 * p20 - 2 * p10 - p40) ** 2;
|
11806 | const ay = (3 * p21 - 2 * p11 - p41) ** 2;
|
11807 | const bx = (3 * p30 - p10 - 2 * p40) ** 2;
|
11808 | const by = (3 * p31 - p11 - 2 * p41) ** 2;
|
11809 | return Math.max(ax, bx) + Math.max(ay, by) <= tol;
|
11810 | }
|
11811 | #getBbox() {
|
11812 | let xMin = Infinity;
|
11813 | let xMax = -Infinity;
|
11814 | let yMin = Infinity;
|
11815 | let yMax = -Infinity;
|
11816 | for (const path of this.paths) {
|
11817 | for (const [first, control1, control2, second] of path) {
|
11818 | const bbox = _util.Util.bezierBoundingBox(...first, ...control1, ...control2, ...second);
|
11819 | xMin = Math.min(xMin, bbox[0]);
|
11820 | yMin = Math.min(yMin, bbox[1]);
|
11821 | xMax = Math.max(xMax, bbox[2]);
|
11822 | yMax = Math.max(yMax, bbox[3]);
|
11823 | }
|
11824 | }
|
11825 | return [xMin, yMin, xMax, yMax];
|
11826 | }
|
11827 | #getPadding() {
|
11828 | return this.#disableEditing ? Math.ceil(this.thickness * this.parentScale) : 0;
|
11829 | }
|
11830 | #fitToContent(firstTime = false) {
|
11831 | if (this.isEmpty()) {
|
11832 | return;
|
11833 | }
|
11834 | if (!this.#disableEditing) {
|
11835 | this.#redraw();
|
11836 | return;
|
11837 | }
|
11838 | const bbox = this.#getBbox();
|
11839 | const padding = this.#getPadding();
|
11840 | this.#baseWidth = Math.max(RESIZER_SIZE, bbox[2] - bbox[0]);
|
11841 | this.#baseHeight = Math.max(RESIZER_SIZE, bbox[3] - bbox[1]);
|
11842 | const width = Math.ceil(padding + this.#baseWidth * this.scaleFactor);
|
11843 | const height = Math.ceil(padding + this.#baseHeight * this.scaleFactor);
|
11844 | const [parentWidth, parentHeight] = this.parentDimensions;
|
11845 | this.width = width / parentWidth;
|
11846 | this.height = height / parentHeight;
|
11847 | this.#aspectRatio = width / height;
|
11848 | this.#setMinDims();
|
11849 | const prevTranslationX = this.translationX;
|
11850 | const prevTranslationY = this.translationY;
|
11851 | this.translationX = -bbox[0];
|
11852 | this.translationY = -bbox[1];
|
11853 | this.#setCanvasDims();
|
11854 | this.#redraw();
|
11855 | this.#realWidth = width;
|
11856 | this.#realHeight = height;
|
11857 | this.setDims(width, height);
|
11858 | const unscaledPadding = firstTime ? padding / this.scaleFactor / 2 : 0;
|
11859 | this.translate(prevTranslationX - this.translationX - unscaledPadding, prevTranslationY - this.translationY - unscaledPadding);
|
11860 | }
|
11861 | #setMinDims() {
|
11862 | const {
|
11863 | style
|
11864 | } = this.div;
|
11865 | if (this.#aspectRatio >= 1) {
|
11866 | style.minHeight = `${RESIZER_SIZE}px`;
|
11867 | style.minWidth = `${Math.round(this.#aspectRatio * RESIZER_SIZE)}px`;
|
11868 | } else {
|
11869 | style.minWidth = `${RESIZER_SIZE}px`;
|
11870 | style.minHeight = `${Math.round(RESIZER_SIZE / this.#aspectRatio)}px`;
|
11871 | }
|
11872 | }
|
11873 | static deserialize(data, parent, uiManager) {
|
11874 | const editor = super.deserialize(data, parent, uiManager);
|
11875 | editor.thickness = data.thickness;
|
11876 | editor.color = _util.Util.makeHexColor(...data.color);
|
11877 | editor.opacity = data.opacity;
|
11878 | const [pageWidth, pageHeight] = editor.pageDimensions;
|
11879 | const width = editor.width * pageWidth;
|
11880 | const height = editor.height * pageHeight;
|
11881 | const scaleFactor = editor.parentScale;
|
11882 | const padding = data.thickness / 2;
|
11883 | editor.#aspectRatio = width / height;
|
11884 | editor.#disableEditing = true;
|
11885 | editor.#realWidth = Math.round(width);
|
11886 | editor.#realHeight = Math.round(height);
|
11887 | for (const {
|
11888 | bezier
|
11889 | } of data.paths) {
|
11890 | const path = [];
|
11891 | editor.paths.push(path);
|
11892 | let p0 = scaleFactor * (bezier[0] - padding);
|
11893 | let p1 = scaleFactor * (height - bezier[1] - padding);
|
11894 | for (let i = 2, ii = bezier.length; i < ii; i += 6) {
|
11895 | const p10 = scaleFactor * (bezier[i] - padding);
|
11896 | const p11 = scaleFactor * (height - bezier[i + 1] - padding);
|
11897 | const p20 = scaleFactor * (bezier[i + 2] - padding);
|
11898 | const p21 = scaleFactor * (height - bezier[i + 3] - padding);
|
11899 | const p30 = scaleFactor * (bezier[i + 4] - padding);
|
11900 | const p31 = scaleFactor * (height - bezier[i + 5] - padding);
|
11901 | path.push([[p0, p1], [p10, p11], [p20, p21], [p30, p31]]);
|
11902 | p0 = p30;
|
11903 | p1 = p31;
|
11904 | }
|
11905 | const path2D = this.#buildPath2D(path);
|
11906 | editor.bezierPath2D.push(path2D);
|
11907 | }
|
11908 | const bbox = editor.#getBbox();
|
11909 | editor.#baseWidth = Math.max(RESIZER_SIZE, bbox[2] - bbox[0]);
|
11910 | editor.#baseHeight = Math.max(RESIZER_SIZE, bbox[3] - bbox[1]);
|
11911 | editor.#setScaleFactor(width, height);
|
11912 | return editor;
|
11913 | }
|
11914 | serialize() {
|
11915 | if (this.isEmpty()) {
|
11916 | return null;
|
11917 | }
|
11918 | const rect = this.getRect(0, 0);
|
11919 | const height = this.rotation % 180 === 0 ? rect[3] - rect[1] : rect[2] - rect[0];
|
11920 | const color = _editor.AnnotationEditor._colorManager.convert(this.ctx.strokeStyle);
|
11921 | return {
|
11922 | annotationType: _util.AnnotationEditorType.INK,
|
11923 | color,
|
11924 | thickness: this.thickness,
|
11925 | opacity: this.opacity,
|
11926 | paths: this.#serializePaths(this.scaleFactor / this.parentScale, this.translationX, this.translationY, height),
|
11927 | pageIndex: this.pageIndex,
|
11928 | rect,
|
11929 | rotation: this.rotation
|
11930 | };
|
11931 | }
|
11932 | }
|
11933 | exports.InkEditor = InkEditor;
|
11934 |
|
11935 | }),
|
11936 |
|
11937 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
11938 |
|
11939 |
|
11940 |
|
11941 | Object.defineProperty(exports, "__esModule", ({
|
11942 | value: true
|
11943 | }));
|
11944 | exports.AnnotationLayer = void 0;
|
11945 | var _util = __w_pdfjs_require__(1);
|
11946 | var _display_utils = __w_pdfjs_require__(6);
|
11947 | var _annotation_storage = __w_pdfjs_require__(3);
|
11948 | var _scripting_utils = __w_pdfjs_require__(31);
|
11949 | var _xfa_layer = __w_pdfjs_require__(32);
|
11950 | const DEFAULT_TAB_INDEX = 1000;
|
11951 | const DEFAULT_FONT_SIZE = 9;
|
11952 | const GetElementsByNameSet = new WeakSet();
|
11953 | function getRectDims(rect) {
|
11954 | return {
|
11955 | width: rect[2] - rect[0],
|
11956 | height: rect[3] - rect[1]
|
11957 | };
|
11958 | }
|
11959 | class AnnotationElementFactory {
|
11960 | static create(parameters) {
|
11961 | const subtype = parameters.data.annotationType;
|
11962 | switch (subtype) {
|
11963 | case _util.AnnotationType.LINK:
|
11964 | return new LinkAnnotationElement(parameters);
|
11965 | case _util.AnnotationType.TEXT:
|
11966 | return new TextAnnotationElement(parameters);
|
11967 | case _util.AnnotationType.WIDGET:
|
11968 | const fieldType = parameters.data.fieldType;
|
11969 | switch (fieldType) {
|
11970 | case "Tx":
|
11971 | return new TextWidgetAnnotationElement(parameters);
|
11972 | case "Btn":
|
11973 | if (parameters.data.radioButton) {
|
11974 | return new RadioButtonWidgetAnnotationElement(parameters);
|
11975 | } else if (parameters.data.checkBox) {
|
11976 | return new CheckboxWidgetAnnotationElement(parameters);
|
11977 | }
|
11978 | return new PushButtonWidgetAnnotationElement(parameters);
|
11979 | case "Ch":
|
11980 | return new ChoiceWidgetAnnotationElement(parameters);
|
11981 | }
|
11982 | return new WidgetAnnotationElement(parameters);
|
11983 | case _util.AnnotationType.POPUP:
|
11984 | return new PopupAnnotationElement(parameters);
|
11985 | case _util.AnnotationType.FREETEXT:
|
11986 | return new FreeTextAnnotationElement(parameters);
|
11987 | case _util.AnnotationType.LINE:
|
11988 | return new LineAnnotationElement(parameters);
|
11989 | case _util.AnnotationType.SQUARE:
|
11990 | return new SquareAnnotationElement(parameters);
|
11991 | case _util.AnnotationType.CIRCLE:
|
11992 | return new CircleAnnotationElement(parameters);
|
11993 | case _util.AnnotationType.POLYLINE:
|
11994 | return new PolylineAnnotationElement(parameters);
|
11995 | case _util.AnnotationType.CARET:
|
11996 | return new CaretAnnotationElement(parameters);
|
11997 | case _util.AnnotationType.INK:
|
11998 | return new InkAnnotationElement(parameters);
|
11999 | case _util.AnnotationType.POLYGON:
|
12000 | return new PolygonAnnotationElement(parameters);
|
12001 | case _util.AnnotationType.HIGHLIGHT:
|
12002 | return new HighlightAnnotationElement(parameters);
|
12003 | case _util.AnnotationType.UNDERLINE:
|
12004 | return new UnderlineAnnotationElement(parameters);
|
12005 | case _util.AnnotationType.SQUIGGLY:
|
12006 | return new SquigglyAnnotationElement(parameters);
|
12007 | case _util.AnnotationType.STRIKEOUT:
|
12008 | return new StrikeOutAnnotationElement(parameters);
|
12009 | case _util.AnnotationType.STAMP:
|
12010 | return new StampAnnotationElement(parameters);
|
12011 | case _util.AnnotationType.FILEATTACHMENT:
|
12012 | return new FileAttachmentAnnotationElement(parameters);
|
12013 | default:
|
12014 | return new AnnotationElement(parameters);
|
12015 | }
|
12016 | }
|
12017 | }
|
12018 | class AnnotationElement {
|
12019 | constructor(parameters, {
|
12020 | isRenderable = false,
|
12021 | ignoreBorder = false,
|
12022 | createQuadrilaterals = false
|
12023 | } = {}) {
|
12024 | this.isRenderable = isRenderable;
|
12025 | this.data = parameters.data;
|
12026 | this.layer = parameters.layer;
|
12027 | this.page = parameters.page;
|
12028 | this.viewport = parameters.viewport;
|
12029 | this.linkService = parameters.linkService;
|
12030 | this.downloadManager = parameters.downloadManager;
|
12031 | this.imageResourcesPath = parameters.imageResourcesPath;
|
12032 | this.renderForms = parameters.renderForms;
|
12033 | this.svgFactory = parameters.svgFactory;
|
12034 | this.annotationStorage = parameters.annotationStorage;
|
12035 | this.enableScripting = parameters.enableScripting;
|
12036 | this.hasJSActions = parameters.hasJSActions;
|
12037 | this._fieldObjects = parameters.fieldObjects;
|
12038 | if (isRenderable) {
|
12039 | this.container = this._createContainer(ignoreBorder);
|
12040 | }
|
12041 | if (createQuadrilaterals) {
|
12042 | this.quadrilaterals = this._createQuadrilaterals(ignoreBorder);
|
12043 | }
|
12044 | }
|
12045 | _createContainer(ignoreBorder = false) {
|
12046 | const {
|
12047 | data,
|
12048 | page,
|
12049 | viewport
|
12050 | } = this;
|
12051 | const container = document.createElement("section");
|
12052 | container.setAttribute("data-annotation-id", data.id);
|
12053 | if (data.noRotate) {
|
12054 | container.classList.add("norotate");
|
12055 | }
|
12056 | const {
|
12057 | pageWidth,
|
12058 | pageHeight,
|
12059 | pageX,
|
12060 | pageY
|
12061 | } = viewport.rawDims;
|
12062 | const {
|
12063 | width,
|
12064 | height
|
12065 | } = getRectDims(data.rect);
|
12066 | const rect = _util.Util.normalizeRect([data.rect[0], page.view[3] - data.rect[1] + page.view[1], data.rect[2], page.view[3] - data.rect[3] + page.view[1]]);
|
12067 | if (!ignoreBorder && data.borderStyle.width > 0) {
|
12068 | container.style.borderWidth = `${data.borderStyle.width}px`;
|
12069 | const horizontalRadius = data.borderStyle.horizontalCornerRadius;
|
12070 | const verticalRadius = data.borderStyle.verticalCornerRadius;
|
12071 | if (horizontalRadius > 0 || verticalRadius > 0) {
|
12072 | const radius = `calc(${horizontalRadius}px * var(--scale-factor)) / calc(${verticalRadius}px * var(--scale-factor))`;
|
12073 | container.style.borderRadius = radius;
|
12074 | } else if (this instanceof RadioButtonWidgetAnnotationElement) {
|
12075 | const radius = `calc(${width}px * var(--scale-factor)) / calc(${height}px * var(--scale-factor))`;
|
12076 | container.style.borderRadius = radius;
|
12077 | }
|
12078 | switch (data.borderStyle.style) {
|
12079 | case _util.AnnotationBorderStyleType.SOLID:
|
12080 | container.style.borderStyle = "solid";
|
12081 | break;
|
12082 | case _util.AnnotationBorderStyleType.DASHED:
|
12083 | container.style.borderStyle = "dashed";
|
12084 | break;
|
12085 | case _util.AnnotationBorderStyleType.BEVELED:
|
12086 | (0, _util.warn)("Unimplemented border style: beveled");
|
12087 | break;
|
12088 | case _util.AnnotationBorderStyleType.INSET:
|
12089 | (0, _util.warn)("Unimplemented border style: inset");
|
12090 | break;
|
12091 | case _util.AnnotationBorderStyleType.UNDERLINE:
|
12092 | container.style.borderBottomStyle = "solid";
|
12093 | break;
|
12094 | default:
|
12095 | break;
|
12096 | }
|
12097 | const borderColor = data.borderColor || null;
|
12098 | if (borderColor) {
|
12099 | container.style.borderColor = _util.Util.makeHexColor(borderColor[0] | 0, borderColor[1] | 0, borderColor[2] | 0);
|
12100 | } else {
|
12101 | container.style.borderWidth = 0;
|
12102 | }
|
12103 | }
|
12104 | container.style.left = `${100 * (rect[0] - pageX) / pageWidth}%`;
|
12105 | container.style.top = `${100 * (rect[1] - pageY) / pageHeight}%`;
|
12106 | const {
|
12107 | rotation
|
12108 | } = data;
|
12109 | if (data.hasOwnCanvas || rotation === 0) {
|
12110 | container.style.width = `${100 * width / pageWidth}%`;
|
12111 | container.style.height = `${100 * height / pageHeight}%`;
|
12112 | } else {
|
12113 | this.setRotation(rotation, container);
|
12114 | }
|
12115 | return container;
|
12116 | }
|
12117 | setRotation(angle, container = this.container) {
|
12118 | const {
|
12119 | pageWidth,
|
12120 | pageHeight
|
12121 | } = this.viewport.rawDims;
|
12122 | const {
|
12123 | width,
|
12124 | height
|
12125 | } = getRectDims(this.data.rect);
|
12126 | let elementWidth, elementHeight;
|
12127 | if (angle % 180 === 0) {
|
12128 | elementWidth = 100 * width / pageWidth;
|
12129 | elementHeight = 100 * height / pageHeight;
|
12130 | } else {
|
12131 | elementWidth = 100 * height / pageWidth;
|
12132 | elementHeight = 100 * width / pageHeight;
|
12133 | }
|
12134 | container.style.width = `${elementWidth}%`;
|
12135 | container.style.height = `${elementHeight}%`;
|
12136 | container.setAttribute("data-main-rotation", (360 - angle) % 360);
|
12137 | }
|
12138 | get _commonActions() {
|
12139 | const setColor = (jsName, styleName, event) => {
|
12140 | const color = event.detail[jsName];
|
12141 | event.target.style[styleName] = _scripting_utils.ColorConverters[`${color[0]}_HTML`](color.slice(1));
|
12142 | };
|
12143 | return (0, _util.shadow)(this, "_commonActions", {
|
12144 | display: event => {
|
12145 | const hidden = event.detail.display % 2 === 1;
|
12146 | this.container.style.visibility = hidden ? "hidden" : "visible";
|
12147 | this.annotationStorage.setValue(this.data.id, {
|
12148 | hidden,
|
12149 | print: event.detail.display === 0 || event.detail.display === 3
|
12150 | });
|
12151 | },
|
12152 | print: event => {
|
12153 | this.annotationStorage.setValue(this.data.id, {
|
12154 | print: event.detail.print
|
12155 | });
|
12156 | },
|
12157 | hidden: event => {
|
12158 | this.container.style.visibility = event.detail.hidden ? "hidden" : "visible";
|
12159 | this.annotationStorage.setValue(this.data.id, {
|
12160 | hidden: event.detail.hidden
|
12161 | });
|
12162 | },
|
12163 | focus: event => {
|
12164 | setTimeout(() => event.target.focus({
|
12165 | preventScroll: false
|
12166 | }), 0);
|
12167 | },
|
12168 | userName: event => {
|
12169 | event.target.title = event.detail.userName;
|
12170 | },
|
12171 | readonly: event => {
|
12172 | if (event.detail.readonly) {
|
12173 | event.target.setAttribute("readonly", "");
|
12174 | } else {
|
12175 | event.target.removeAttribute("readonly");
|
12176 | }
|
12177 | },
|
12178 | required: event => {
|
12179 | this._setRequired(event.target, event.detail.required);
|
12180 | },
|
12181 | bgColor: event => {
|
12182 | setColor("bgColor", "backgroundColor", event);
|
12183 | },
|
12184 | fillColor: event => {
|
12185 | setColor("fillColor", "backgroundColor", event);
|
12186 | },
|
12187 | fgColor: event => {
|
12188 | setColor("fgColor", "color", event);
|
12189 | },
|
12190 | textColor: event => {
|
12191 | setColor("textColor", "color", event);
|
12192 | },
|
12193 | borderColor: event => {
|
12194 | setColor("borderColor", "borderColor", event);
|
12195 | },
|
12196 | strokeColor: event => {
|
12197 | setColor("strokeColor", "borderColor", event);
|
12198 | },
|
12199 | rotation: event => {
|
12200 | const angle = event.detail.rotation;
|
12201 | this.setRotation(angle);
|
12202 | this.annotationStorage.setValue(this.data.id, {
|
12203 | rotation: angle
|
12204 | });
|
12205 | }
|
12206 | });
|
12207 | }
|
12208 | _dispatchEventFromSandbox(actions, jsEvent) {
|
12209 | const commonActions = this._commonActions;
|
12210 | for (const name of Object.keys(jsEvent.detail)) {
|
12211 | const action = actions[name] || commonActions[name];
|
12212 | action?.(jsEvent);
|
12213 | }
|
12214 | }
|
12215 | _setDefaultPropertiesFromJS(element) {
|
12216 | if (!this.enableScripting) {
|
12217 | return;
|
12218 | }
|
12219 | const storedData = this.annotationStorage.getRawValue(this.data.id);
|
12220 | if (!storedData) {
|
12221 | return;
|
12222 | }
|
12223 | const commonActions = this._commonActions;
|
12224 | for (const [actionName, detail] of Object.entries(storedData)) {
|
12225 | const action = commonActions[actionName];
|
12226 | if (action) {
|
12227 | const eventProxy = {
|
12228 | detail: {
|
12229 | [actionName]: detail
|
12230 | },
|
12231 | target: element
|
12232 | };
|
12233 | action(eventProxy);
|
12234 | delete storedData[actionName];
|
12235 | }
|
12236 | }
|
12237 | }
|
12238 | _createQuadrilaterals(ignoreBorder = false) {
|
12239 | if (!this.data.quadPoints) {
|
12240 | return null;
|
12241 | }
|
12242 | const quadrilaterals = [];
|
12243 | const savedRect = this.data.rect;
|
12244 | for (const quadPoint of this.data.quadPoints) {
|
12245 | this.data.rect = [quadPoint[2].x, quadPoint[2].y, quadPoint[1].x, quadPoint[1].y];
|
12246 | quadrilaterals.push(this._createContainer(ignoreBorder));
|
12247 | }
|
12248 | this.data.rect = savedRect;
|
12249 | return quadrilaterals;
|
12250 | }
|
12251 | _createPopup(trigger, data) {
|
12252 | let container = this.container;
|
12253 | if (this.quadrilaterals) {
|
12254 | trigger ||= this.quadrilaterals;
|
12255 | container = this.quadrilaterals[0];
|
12256 | }
|
12257 | if (!trigger) {
|
12258 | trigger = document.createElement("div");
|
12259 | trigger.classList.add("popupTriggerArea");
|
12260 | container.append(trigger);
|
12261 | }
|
12262 | const popupElement = new PopupElement({
|
12263 | container,
|
12264 | trigger,
|
12265 | color: data.color,
|
12266 | titleObj: data.titleObj,
|
12267 | modificationDate: data.modificationDate,
|
12268 | contentsObj: data.contentsObj,
|
12269 | richText: data.richText,
|
12270 | hideWrapper: true
|
12271 | });
|
12272 | const popup = popupElement.render();
|
12273 | popup.style.left = "100%";
|
12274 | container.append(popup);
|
12275 | }
|
12276 | _renderQuadrilaterals(className) {
|
12277 | for (const quadrilateral of this.quadrilaterals) {
|
12278 | quadrilateral.classList.add(className);
|
12279 | }
|
12280 | return this.quadrilaterals;
|
12281 | }
|
12282 | render() {
|
12283 | (0, _util.unreachable)("Abstract method `AnnotationElement.render` called");
|
12284 | }
|
12285 | _getElementsByName(name, skipId = null) {
|
12286 | const fields = [];
|
12287 | if (this._fieldObjects) {
|
12288 | const fieldObj = this._fieldObjects[name];
|
12289 | if (fieldObj) {
|
12290 | for (const {
|
12291 | page,
|
12292 | id,
|
12293 | exportValues
|
12294 | } of fieldObj) {
|
12295 | if (page === -1) {
|
12296 | continue;
|
12297 | }
|
12298 | if (id === skipId) {
|
12299 | continue;
|
12300 | }
|
12301 | const exportValue = typeof exportValues === "string" ? exportValues : null;
|
12302 | const domElement = document.querySelector(`[data-element-id="${id}"]`);
|
12303 | if (domElement && !GetElementsByNameSet.has(domElement)) {
|
12304 | (0, _util.warn)(`_getElementsByName - element not allowed: ${id}`);
|
12305 | continue;
|
12306 | }
|
12307 | fields.push({
|
12308 | id,
|
12309 | exportValue,
|
12310 | domElement
|
12311 | });
|
12312 | }
|
12313 | }
|
12314 | return fields;
|
12315 | }
|
12316 | for (const domElement of document.getElementsByName(name)) {
|
12317 | const {
|
12318 | exportValue
|
12319 | } = domElement;
|
12320 | const id = domElement.getAttribute("data-element-id");
|
12321 | if (id === skipId) {
|
12322 | continue;
|
12323 | }
|
12324 | if (!GetElementsByNameSet.has(domElement)) {
|
12325 | continue;
|
12326 | }
|
12327 | fields.push({
|
12328 | id,
|
12329 | exportValue,
|
12330 | domElement
|
12331 | });
|
12332 | }
|
12333 | return fields;
|
12334 | }
|
12335 | }
|
12336 | class LinkAnnotationElement extends AnnotationElement {
|
12337 | constructor(parameters, options = null) {
|
12338 | super(parameters, {
|
12339 | isRenderable: true,
|
12340 | ignoreBorder: !!options?.ignoreBorder,
|
12341 | createQuadrilaterals: true
|
12342 | });
|
12343 | this.isTooltipOnly = parameters.data.isTooltipOnly;
|
12344 | }
|
12345 | render() {
|
12346 | const {
|
12347 | data,
|
12348 | linkService
|
12349 | } = this;
|
12350 | const link = document.createElement("a");
|
12351 | link.setAttribute("data-element-id", data.id);
|
12352 | let isBound = false;
|
12353 | if (data.url) {
|
12354 | linkService.addLinkAttributes(link, data.url, data.newWindow);
|
12355 | isBound = true;
|
12356 | } else if (data.action) {
|
12357 | this._bindNamedAction(link, data.action);
|
12358 | isBound = true;
|
12359 | } else if (data.attachment) {
|
12360 | this._bindAttachment(link, data.attachment);
|
12361 | isBound = true;
|
12362 | } else if (data.setOCGState) {
|
12363 | this.#bindSetOCGState(link, data.setOCGState);
|
12364 | isBound = true;
|
12365 | } else if (data.dest) {
|
12366 | this._bindLink(link, data.dest);
|
12367 | isBound = true;
|
12368 | } else {
|
12369 | if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) {
|
12370 | this._bindJSAction(link, data);
|
12371 | isBound = true;
|
12372 | }
|
12373 | if (data.resetForm) {
|
12374 | this._bindResetFormAction(link, data.resetForm);
|
12375 | isBound = true;
|
12376 | } else if (this.isTooltipOnly && !isBound) {
|
12377 | this._bindLink(link, "");
|
12378 | isBound = true;
|
12379 | }
|
12380 | }
|
12381 | if (this.quadrilaterals) {
|
12382 | return this._renderQuadrilaterals("linkAnnotation").map((quadrilateral, index) => {
|
12383 | const linkElement = index === 0 ? link : link.cloneNode();
|
12384 | quadrilateral.append(linkElement);
|
12385 | return quadrilateral;
|
12386 | });
|
12387 | }
|
12388 | this.container.classList.add("linkAnnotation");
|
12389 | if (isBound) {
|
12390 | this.container.append(link);
|
12391 | }
|
12392 | return this.container;
|
12393 | }
|
12394 | #setInternalLink() {
|
12395 | this.container.setAttribute("data-internal-link", "");
|
12396 | }
|
12397 | _bindLink(link, destination) {
|
12398 | link.href = this.linkService.getDestinationHash(destination);
|
12399 | link.onclick = () => {
|
12400 | if (destination) {
|
12401 | this.linkService.goToDestination(destination);
|
12402 | }
|
12403 | return false;
|
12404 | };
|
12405 | if (destination || destination === "") {
|
12406 | this.#setInternalLink();
|
12407 | }
|
12408 | }
|
12409 | _bindNamedAction(link, action) {
|
12410 | link.href = this.linkService.getAnchorUrl("");
|
12411 | link.onclick = () => {
|
12412 | this.linkService.executeNamedAction(action);
|
12413 | return false;
|
12414 | };
|
12415 | this.#setInternalLink();
|
12416 | }
|
12417 | _bindAttachment(link, attachment) {
|
12418 | link.href = this.linkService.getAnchorUrl("");
|
12419 | link.onclick = () => {
|
12420 | this.downloadManager?.openOrDownloadData(this.container, attachment.content, attachment.filename);
|
12421 | return false;
|
12422 | };
|
12423 | this.#setInternalLink();
|
12424 | }
|
12425 | #bindSetOCGState(link, action) {
|
12426 | link.href = this.linkService.getAnchorUrl("");
|
12427 | link.onclick = () => {
|
12428 | this.linkService.executeSetOCGState(action);
|
12429 | return false;
|
12430 | };
|
12431 | this.#setInternalLink();
|
12432 | }
|
12433 | _bindJSAction(link, data) {
|
12434 | link.href = this.linkService.getAnchorUrl("");
|
12435 | const map = new Map([["Action", "onclick"], ["Mouse Up", "onmouseup"], ["Mouse Down", "onmousedown"]]);
|
12436 | for (const name of Object.keys(data.actions)) {
|
12437 | const jsName = map.get(name);
|
12438 | if (!jsName) {
|
12439 | continue;
|
12440 | }
|
12441 | link[jsName] = () => {
|
12442 | this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
12443 | source: this,
|
12444 | detail: {
|
12445 | id: data.id,
|
12446 | name
|
12447 | }
|
12448 | });
|
12449 | return false;
|
12450 | };
|
12451 | }
|
12452 | if (!link.onclick) {
|
12453 | link.onclick = () => false;
|
12454 | }
|
12455 | this.#setInternalLink();
|
12456 | }
|
12457 | _bindResetFormAction(link, resetForm) {
|
12458 | const otherClickAction = link.onclick;
|
12459 | if (!otherClickAction) {
|
12460 | link.href = this.linkService.getAnchorUrl("");
|
12461 | }
|
12462 | this.#setInternalLink();
|
12463 | if (!this._fieldObjects) {
|
12464 | (0, _util.warn)(`_bindResetFormAction - "resetForm" action not supported, ` + "ensure that the `fieldObjects` parameter is provided.");
|
12465 | if (!otherClickAction) {
|
12466 | link.onclick = () => false;
|
12467 | }
|
12468 | return;
|
12469 | }
|
12470 | link.onclick = () => {
|
12471 | otherClickAction?.();
|
12472 | const {
|
12473 | fields: resetFormFields,
|
12474 | refs: resetFormRefs,
|
12475 | include
|
12476 | } = resetForm;
|
12477 | const allFields = [];
|
12478 | if (resetFormFields.length !== 0 || resetFormRefs.length !== 0) {
|
12479 | const fieldIds = new Set(resetFormRefs);
|
12480 | for (const fieldName of resetFormFields) {
|
12481 | const fields = this._fieldObjects[fieldName] || [];
|
12482 | for (const {
|
12483 | id
|
12484 | } of fields) {
|
12485 | fieldIds.add(id);
|
12486 | }
|
12487 | }
|
12488 | for (const fields of Object.values(this._fieldObjects)) {
|
12489 | for (const field of fields) {
|
12490 | if (fieldIds.has(field.id) === include) {
|
12491 | allFields.push(field);
|
12492 | }
|
12493 | }
|
12494 | }
|
12495 | } else {
|
12496 | for (const fields of Object.values(this._fieldObjects)) {
|
12497 | allFields.push(...fields);
|
12498 | }
|
12499 | }
|
12500 | const storage = this.annotationStorage;
|
12501 | const allIds = [];
|
12502 | for (const field of allFields) {
|
12503 | const {
|
12504 | id
|
12505 | } = field;
|
12506 | allIds.push(id);
|
12507 | switch (field.type) {
|
12508 | case "text":
|
12509 | {
|
12510 | const value = field.defaultValue || "";
|
12511 | storage.setValue(id, {
|
12512 | value
|
12513 | });
|
12514 | break;
|
12515 | }
|
12516 | case "checkbox":
|
12517 | case "radiobutton":
|
12518 | {
|
12519 | const value = field.defaultValue === field.exportValues;
|
12520 | storage.setValue(id, {
|
12521 | value
|
12522 | });
|
12523 | break;
|
12524 | }
|
12525 | case "combobox":
|
12526 | case "listbox":
|
12527 | {
|
12528 | const value = field.defaultValue || "";
|
12529 | storage.setValue(id, {
|
12530 | value
|
12531 | });
|
12532 | break;
|
12533 | }
|
12534 | default:
|
12535 | continue;
|
12536 | }
|
12537 | const domElement = document.querySelector(`[data-element-id="${id}"]`);
|
12538 | if (!domElement) {
|
12539 | continue;
|
12540 | } else if (!GetElementsByNameSet.has(domElement)) {
|
12541 | (0, _util.warn)(`_bindResetFormAction - element not allowed: ${id}`);
|
12542 | continue;
|
12543 | }
|
12544 | domElement.dispatchEvent(new Event("resetform"));
|
12545 | }
|
12546 | if (this.enableScripting) {
|
12547 | this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
12548 | source: this,
|
12549 | detail: {
|
12550 | id: "app",
|
12551 | ids: allIds,
|
12552 | name: "ResetForm"
|
12553 | }
|
12554 | });
|
12555 | }
|
12556 | return false;
|
12557 | };
|
12558 | }
|
12559 | }
|
12560 | class TextAnnotationElement extends AnnotationElement {
|
12561 | constructor(parameters) {
|
12562 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
|
12563 | super(parameters, {
|
12564 | isRenderable
|
12565 | });
|
12566 | }
|
12567 | render() {
|
12568 | this.container.classList.add("textAnnotation");
|
12569 | const image = document.createElement("img");
|
12570 | image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
|
12571 | image.alt = "[{{type}} Annotation]";
|
12572 | image.dataset.l10nId = "text_annotation_type";
|
12573 | image.dataset.l10nArgs = JSON.stringify({
|
12574 | type: this.data.name
|
12575 | });
|
12576 | if (!this.data.hasPopup) {
|
12577 | this._createPopup(image, this.data);
|
12578 | }
|
12579 | this.container.append(image);
|
12580 | return this.container;
|
12581 | }
|
12582 | }
|
12583 | class WidgetAnnotationElement extends AnnotationElement {
|
12584 | render() {
|
12585 | if (this.data.alternativeText) {
|
12586 | this.container.title = this.data.alternativeText;
|
12587 | }
|
12588 | return this.container;
|
12589 | }
|
12590 | showElementAndHideCanvas(element) {
|
12591 | if (this.data.hasOwnCanvas) {
|
12592 | if (element.previousSibling?.nodeName === "CANVAS") {
|
12593 | element.previousSibling.hidden = true;
|
12594 | }
|
12595 | element.hidden = false;
|
12596 | }
|
12597 | }
|
12598 | _getKeyModifier(event) {
|
12599 | const {
|
12600 | isWin,
|
12601 | isMac
|
12602 | } = _util.FeatureTest.platform;
|
12603 | return isWin && event.ctrlKey || isMac && event.metaKey;
|
12604 | }
|
12605 | _setEventListener(element, baseName, eventName, valueGetter) {
|
12606 | if (baseName.includes("mouse")) {
|
12607 | element.addEventListener(baseName, event => {
|
12608 | this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
12609 | source: this,
|
12610 | detail: {
|
12611 | id: this.data.id,
|
12612 | name: eventName,
|
12613 | value: valueGetter(event),
|
12614 | shift: event.shiftKey,
|
12615 | modifier: this._getKeyModifier(event)
|
12616 | }
|
12617 | });
|
12618 | });
|
12619 | } else {
|
12620 | element.addEventListener(baseName, event => {
|
12621 | this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
12622 | source: this,
|
12623 | detail: {
|
12624 | id: this.data.id,
|
12625 | name: eventName,
|
12626 | value: valueGetter(event)
|
12627 | }
|
12628 | });
|
12629 | });
|
12630 | }
|
12631 | }
|
12632 | _setEventListeners(element, names, getter) {
|
12633 | for (const [baseName, eventName] of names) {
|
12634 | if (eventName === "Action" || this.data.actions?.[eventName]) {
|
12635 | this._setEventListener(element, baseName, eventName, getter);
|
12636 | }
|
12637 | }
|
12638 | }
|
12639 | _setBackgroundColor(element) {
|
12640 | const color = this.data.backgroundColor || null;
|
12641 | element.style.backgroundColor = color === null ? "transparent" : _util.Util.makeHexColor(color[0], color[1], color[2]);
|
12642 | }
|
12643 | _setTextStyle(element) {
|
12644 | const TEXT_ALIGNMENT = ["left", "center", "right"];
|
12645 | const {
|
12646 | fontColor
|
12647 | } = this.data.defaultAppearanceData;
|
12648 | const fontSize = this.data.defaultAppearanceData.fontSize || DEFAULT_FONT_SIZE;
|
12649 | const style = element.style;
|
12650 | let computedFontSize;
|
12651 | const BORDER_SIZE = 2;
|
12652 | const roundToOneDecimal = x => Math.round(10 * x) / 10;
|
12653 | if (this.data.multiLine) {
|
12654 | const height = Math.abs(this.data.rect[3] - this.data.rect[1] - BORDER_SIZE);
|
12655 | const numberOfLines = Math.round(height / (_util.LINE_FACTOR * fontSize)) || 1;
|
12656 | const lineHeight = height / numberOfLines;
|
12657 | computedFontSize = Math.min(fontSize, roundToOneDecimal(lineHeight / _util.LINE_FACTOR));
|
12658 | } else {
|
12659 | const height = Math.abs(this.data.rect[3] - this.data.rect[1] - BORDER_SIZE);
|
12660 | computedFontSize = Math.min(fontSize, roundToOneDecimal(height / _util.LINE_FACTOR));
|
12661 | }
|
12662 | style.fontSize = `calc(${computedFontSize}px * var(--scale-factor))`;
|
12663 | style.color = _util.Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);
|
12664 | if (this.data.textAlignment !== null) {
|
12665 | style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
|
12666 | }
|
12667 | }
|
12668 | _setRequired(element, isRequired) {
|
12669 | if (isRequired) {
|
12670 | element.setAttribute("required", true);
|
12671 | } else {
|
12672 | element.removeAttribute("required");
|
12673 | }
|
12674 | element.setAttribute("aria-required", isRequired);
|
12675 | }
|
12676 | }
|
12677 | class TextWidgetAnnotationElement extends WidgetAnnotationElement {
|
12678 | constructor(parameters) {
|
12679 | const isRenderable = parameters.renderForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
|
12680 | super(parameters, {
|
12681 | isRenderable
|
12682 | });
|
12683 | }
|
12684 | setPropertyOnSiblings(base, key, value, keyInStorage) {
|
12685 | const storage = this.annotationStorage;
|
12686 | for (const element of this._getElementsByName(base.name, base.id)) {
|
12687 | if (element.domElement) {
|
12688 | element.domElement[key] = value;
|
12689 | }
|
12690 | storage.setValue(element.id, {
|
12691 | [keyInStorage]: value
|
12692 | });
|
12693 | }
|
12694 | }
|
12695 | render() {
|
12696 | const storage = this.annotationStorage;
|
12697 | const id = this.data.id;
|
12698 | this.container.classList.add("textWidgetAnnotation");
|
12699 | let element = null;
|
12700 | if (this.renderForms) {
|
12701 | const storedData = storage.getValue(id, {
|
12702 | value: this.data.fieldValue
|
12703 | });
|
12704 | let textContent = storedData.value || "";
|
12705 | const maxLen = storage.getValue(id, {
|
12706 | charLimit: this.data.maxLen
|
12707 | }).charLimit;
|
12708 | if (maxLen && textContent.length > maxLen) {
|
12709 | textContent = textContent.slice(0, maxLen);
|
12710 | }
|
12711 | let fieldFormattedValues = storedData.formattedValue || this.data.textContent?.join("\n") || null;
|
12712 | if (fieldFormattedValues && this.data.comb) {
|
12713 | fieldFormattedValues = fieldFormattedValues.replaceAll(/\s+/g, "");
|
12714 | }
|
12715 | const elementData = {
|
12716 | userValue: textContent,
|
12717 | formattedValue: fieldFormattedValues,
|
12718 | lastCommittedValue: null,
|
12719 | commitKey: 1
|
12720 | };
|
12721 | if (this.data.multiLine) {
|
12722 | element = document.createElement("textarea");
|
12723 | element.textContent = fieldFormattedValues ?? textContent;
|
12724 | if (this.data.doNotScroll) {
|
12725 | element.style.overflowY = "hidden";
|
12726 | }
|
12727 | } else {
|
12728 | element = document.createElement("input");
|
12729 | element.type = "text";
|
12730 | element.setAttribute("value", fieldFormattedValues ?? textContent);
|
12731 | if (this.data.doNotScroll) {
|
12732 | element.style.overflowX = "hidden";
|
12733 | }
|
12734 | }
|
12735 | if (this.data.hasOwnCanvas) {
|
12736 | element.hidden = true;
|
12737 | }
|
12738 | GetElementsByNameSet.add(element);
|
12739 | element.setAttribute("data-element-id", id);
|
12740 | element.disabled = this.data.readOnly;
|
12741 | element.name = this.data.fieldName;
|
12742 | element.tabIndex = DEFAULT_TAB_INDEX;
|
12743 | this._setRequired(element, this.data.required);
|
12744 | if (maxLen) {
|
12745 | element.maxLength = maxLen;
|
12746 | }
|
12747 | element.addEventListener("input", event => {
|
12748 | storage.setValue(id, {
|
12749 | value: event.target.value
|
12750 | });
|
12751 | this.setPropertyOnSiblings(element, "value", event.target.value, "value");
|
12752 | elementData.formattedValue = null;
|
12753 | });
|
12754 | element.addEventListener("resetform", event => {
|
12755 | const defaultValue = this.data.defaultFieldValue ?? "";
|
12756 | element.value = elementData.userValue = defaultValue;
|
12757 | elementData.formattedValue = null;
|
12758 | });
|
12759 | let blurListener = event => {
|
12760 | const {
|
12761 | formattedValue
|
12762 | } = elementData;
|
12763 | if (formattedValue !== null && formattedValue !== undefined) {
|
12764 | event.target.value = formattedValue;
|
12765 | }
|
12766 | event.target.scrollLeft = 0;
|
12767 | };
|
12768 | if (this.enableScripting && this.hasJSActions) {
|
12769 | element.addEventListener("focus", event => {
|
12770 | const {
|
12771 | target
|
12772 | } = event;
|
12773 | if (elementData.userValue) {
|
12774 | target.value = elementData.userValue;
|
12775 | }
|
12776 | elementData.lastCommittedValue = target.value;
|
12777 | elementData.commitKey = 1;
|
12778 | });
|
12779 | element.addEventListener("updatefromsandbox", jsEvent => {
|
12780 | this.showElementAndHideCanvas(jsEvent.target);
|
12781 | const actions = {
|
12782 | value(event) {
|
12783 | elementData.userValue = event.detail.value ?? "";
|
12784 | storage.setValue(id, {
|
12785 | value: elementData.userValue.toString()
|
12786 | });
|
12787 | event.target.value = elementData.userValue;
|
12788 | },
|
12789 | formattedValue(event) {
|
12790 | const {
|
12791 | formattedValue
|
12792 | } = event.detail;
|
12793 | elementData.formattedValue = formattedValue;
|
12794 | if (formattedValue !== null && formattedValue !== undefined && event.target !== document.activeElement) {
|
12795 | event.target.value = formattedValue;
|
12796 | }
|
12797 | storage.setValue(id, {
|
12798 | formattedValue
|
12799 | });
|
12800 | },
|
12801 | selRange(event) {
|
12802 | event.target.setSelectionRange(...event.detail.selRange);
|
12803 | },
|
12804 | charLimit: event => {
|
12805 | const {
|
12806 | charLimit
|
12807 | } = event.detail;
|
12808 | const {
|
12809 | target
|
12810 | } = event;
|
12811 | if (charLimit === 0) {
|
12812 | target.removeAttribute("maxLength");
|
12813 | return;
|
12814 | }
|
12815 | target.setAttribute("maxLength", charLimit);
|
12816 | let value = elementData.userValue;
|
12817 | if (!value || value.length <= charLimit) {
|
12818 | return;
|
12819 | }
|
12820 | value = value.slice(0, charLimit);
|
12821 | target.value = elementData.userValue = value;
|
12822 | storage.setValue(id, {
|
12823 | value
|
12824 | });
|
12825 | this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
12826 | source: this,
|
12827 | detail: {
|
12828 | id,
|
12829 | name: "Keystroke",
|
12830 | value,
|
12831 | willCommit: true,
|
12832 | commitKey: 1,
|
12833 | selStart: target.selectionStart,
|
12834 | selEnd: target.selectionEnd
|
12835 | }
|
12836 | });
|
12837 | }
|
12838 | };
|
12839 | this._dispatchEventFromSandbox(actions, jsEvent);
|
12840 | });
|
12841 | element.addEventListener("keydown", event => {
|
12842 | elementData.commitKey = 1;
|
12843 | let commitKey = -1;
|
12844 | if (event.key === "Escape") {
|
12845 | commitKey = 0;
|
12846 | } else if (event.key === "Enter" && !this.data.multiLine) {
|
12847 | commitKey = 2;
|
12848 | } else if (event.key === "Tab") {
|
12849 | elementData.commitKey = 3;
|
12850 | }
|
12851 | if (commitKey === -1) {
|
12852 | return;
|
12853 | }
|
12854 | const {
|
12855 | value
|
12856 | } = event.target;
|
12857 | if (elementData.lastCommittedValue === value) {
|
12858 | return;
|
12859 | }
|
12860 | elementData.lastCommittedValue = value;
|
12861 | elementData.userValue = value;
|
12862 | this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
12863 | source: this,
|
12864 | detail: {
|
12865 | id,
|
12866 | name: "Keystroke",
|
12867 | value,
|
12868 | willCommit: true,
|
12869 | commitKey,
|
12870 | selStart: event.target.selectionStart,
|
12871 | selEnd: event.target.selectionEnd
|
12872 | }
|
12873 | });
|
12874 | });
|
12875 | const _blurListener = blurListener;
|
12876 | blurListener = null;
|
12877 | element.addEventListener("blur", event => {
|
12878 | if (!event.relatedTarget) {
|
12879 | return;
|
12880 | }
|
12881 | const {
|
12882 | value
|
12883 | } = event.target;
|
12884 | elementData.userValue = value;
|
12885 | if (elementData.lastCommittedValue !== value) {
|
12886 | this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
12887 | source: this,
|
12888 | detail: {
|
12889 | id,
|
12890 | name: "Keystroke",
|
12891 | value,
|
12892 | willCommit: true,
|
12893 | commitKey: elementData.commitKey,
|
12894 | selStart: event.target.selectionStart,
|
12895 | selEnd: event.target.selectionEnd
|
12896 | }
|
12897 | });
|
12898 | }
|
12899 | _blurListener(event);
|
12900 | });
|
12901 | if (this.data.actions?.Keystroke) {
|
12902 | element.addEventListener("beforeinput", event => {
|
12903 | elementData.lastCommittedValue = null;
|
12904 | const {
|
12905 | data,
|
12906 | target
|
12907 | } = event;
|
12908 | const {
|
12909 | value,
|
12910 | selectionStart,
|
12911 | selectionEnd
|
12912 | } = target;
|
12913 | let selStart = selectionStart,
|
12914 | selEnd = selectionEnd;
|
12915 | switch (event.inputType) {
|
12916 | case "deleteWordBackward":
|
12917 | {
|
12918 | const match = value.substring(0, selectionStart).match(/\w*[^\w]*$/);
|
12919 | if (match) {
|
12920 | selStart -= match[0].length;
|
12921 | }
|
12922 | break;
|
12923 | }
|
12924 | case "deleteWordForward":
|
12925 | {
|
12926 | const match = value.substring(selectionStart).match(/^[^\w]*\w*/);
|
12927 | if (match) {
|
12928 | selEnd += match[0].length;
|
12929 | }
|
12930 | break;
|
12931 | }
|
12932 | case "deleteContentBackward":
|
12933 | if (selectionStart === selectionEnd) {
|
12934 | selStart -= 1;
|
12935 | }
|
12936 | break;
|
12937 | case "deleteContentForward":
|
12938 | if (selectionStart === selectionEnd) {
|
12939 | selEnd += 1;
|
12940 | }
|
12941 | break;
|
12942 | }
|
12943 | event.preventDefault();
|
12944 | this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
12945 | source: this,
|
12946 | detail: {
|
12947 | id,
|
12948 | name: "Keystroke",
|
12949 | value,
|
12950 | change: data || "",
|
12951 | willCommit: false,
|
12952 | selStart,
|
12953 | selEnd
|
12954 | }
|
12955 | });
|
12956 | });
|
12957 | }
|
12958 | this._setEventListeners(element, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.value);
|
12959 | }
|
12960 | if (blurListener) {
|
12961 | element.addEventListener("blur", blurListener);
|
12962 | }
|
12963 | if (this.data.comb) {
|
12964 | const fieldWidth = this.data.rect[2] - this.data.rect[0];
|
12965 | const combWidth = fieldWidth / maxLen;
|
12966 | element.classList.add("comb");
|
12967 | element.style.letterSpacing = `calc(${combWidth}px * var(--scale-factor) - 1ch)`;
|
12968 | }
|
12969 | } else {
|
12970 | element = document.createElement("div");
|
12971 | element.textContent = this.data.fieldValue;
|
12972 | element.style.verticalAlign = "middle";
|
12973 | element.style.display = "table-cell";
|
12974 | }
|
12975 | this._setTextStyle(element);
|
12976 | this._setBackgroundColor(element);
|
12977 | this._setDefaultPropertiesFromJS(element);
|
12978 | this.container.append(element);
|
12979 | return this.container;
|
12980 | }
|
12981 | }
|
12982 | class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
|
12983 | constructor(parameters) {
|
12984 | super(parameters, {
|
12985 | isRenderable: parameters.renderForms
|
12986 | });
|
12987 | }
|
12988 | render() {
|
12989 | const storage = this.annotationStorage;
|
12990 | const data = this.data;
|
12991 | const id = data.id;
|
12992 | let value = storage.getValue(id, {
|
12993 | value: data.exportValue === data.fieldValue
|
12994 | }).value;
|
12995 | if (typeof value === "string") {
|
12996 | value = value !== "Off";
|
12997 | storage.setValue(id, {
|
12998 | value
|
12999 | });
|
13000 | }
|
13001 | this.container.classList.add("buttonWidgetAnnotation", "checkBox");
|
13002 | const element = document.createElement("input");
|
13003 | GetElementsByNameSet.add(element);
|
13004 | element.setAttribute("data-element-id", id);
|
13005 | element.disabled = data.readOnly;
|
13006 | this._setRequired(element, this.data.required);
|
13007 | element.type = "checkbox";
|
13008 | element.name = data.fieldName;
|
13009 | if (value) {
|
13010 | element.setAttribute("checked", true);
|
13011 | }
|
13012 | element.setAttribute("exportValue", data.exportValue);
|
13013 | element.tabIndex = DEFAULT_TAB_INDEX;
|
13014 | element.addEventListener("change", event => {
|
13015 | const {
|
13016 | name,
|
13017 | checked
|
13018 | } = event.target;
|
13019 | for (const checkbox of this._getElementsByName(name, id)) {
|
13020 | const curChecked = checked && checkbox.exportValue === data.exportValue;
|
13021 | if (checkbox.domElement) {
|
13022 | checkbox.domElement.checked = curChecked;
|
13023 | }
|
13024 | storage.setValue(checkbox.id, {
|
13025 | value: curChecked
|
13026 | });
|
13027 | }
|
13028 | storage.setValue(id, {
|
13029 | value: checked
|
13030 | });
|
13031 | });
|
13032 | element.addEventListener("resetform", event => {
|
13033 | const defaultValue = data.defaultFieldValue || "Off";
|
13034 | event.target.checked = defaultValue === data.exportValue;
|
13035 | });
|
13036 | if (this.enableScripting && this.hasJSActions) {
|
13037 | element.addEventListener("updatefromsandbox", jsEvent => {
|
13038 | const actions = {
|
13039 | value(event) {
|
13040 | event.target.checked = event.detail.value !== "Off";
|
13041 | storage.setValue(id, {
|
13042 | value: event.target.checked
|
13043 | });
|
13044 | }
|
13045 | };
|
13046 | this._dispatchEventFromSandbox(actions, jsEvent);
|
13047 | });
|
13048 | this._setEventListeners(element, [["change", "Validate"], ["change", "Action"], ["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.checked);
|
13049 | }
|
13050 | this._setBackgroundColor(element);
|
13051 | this._setDefaultPropertiesFromJS(element);
|
13052 | this.container.append(element);
|
13053 | return this.container;
|
13054 | }
|
13055 | }
|
13056 | class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
|
13057 | constructor(parameters) {
|
13058 | super(parameters, {
|
13059 | isRenderable: parameters.renderForms
|
13060 | });
|
13061 | }
|
13062 | render() {
|
13063 | this.container.classList.add("buttonWidgetAnnotation", "radioButton");
|
13064 | const storage = this.annotationStorage;
|
13065 | const data = this.data;
|
13066 | const id = data.id;
|
13067 | let value = storage.getValue(id, {
|
13068 | value: data.fieldValue === data.buttonValue
|
13069 | }).value;
|
13070 | if (typeof value === "string") {
|
13071 | value = value !== data.buttonValue;
|
13072 | storage.setValue(id, {
|
13073 | value
|
13074 | });
|
13075 | }
|
13076 | const element = document.createElement("input");
|
13077 | GetElementsByNameSet.add(element);
|
13078 | element.setAttribute("data-element-id", id);
|
13079 | element.disabled = data.readOnly;
|
13080 | this._setRequired(element, this.data.required);
|
13081 | element.type = "radio";
|
13082 | element.name = data.fieldName;
|
13083 | if (value) {
|
13084 | element.setAttribute("checked", true);
|
13085 | }
|
13086 | element.tabIndex = DEFAULT_TAB_INDEX;
|
13087 | element.addEventListener("change", event => {
|
13088 | const {
|
13089 | name,
|
13090 | checked
|
13091 | } = event.target;
|
13092 | for (const radio of this._getElementsByName(name, id)) {
|
13093 | storage.setValue(radio.id, {
|
13094 | value: false
|
13095 | });
|
13096 | }
|
13097 | storage.setValue(id, {
|
13098 | value: checked
|
13099 | });
|
13100 | });
|
13101 | element.addEventListener("resetform", event => {
|
13102 | const defaultValue = data.defaultFieldValue;
|
13103 | event.target.checked = defaultValue !== null && defaultValue !== undefined && defaultValue === data.buttonValue;
|
13104 | });
|
13105 | if (this.enableScripting && this.hasJSActions) {
|
13106 | const pdfButtonValue = data.buttonValue;
|
13107 | element.addEventListener("updatefromsandbox", jsEvent => {
|
13108 | const actions = {
|
13109 | value: event => {
|
13110 | const checked = pdfButtonValue === event.detail.value;
|
13111 | for (const radio of this._getElementsByName(event.target.name)) {
|
13112 | const curChecked = checked && radio.id === id;
|
13113 | if (radio.domElement) {
|
13114 | radio.domElement.checked = curChecked;
|
13115 | }
|
13116 | storage.setValue(radio.id, {
|
13117 | value: curChecked
|
13118 | });
|
13119 | }
|
13120 | }
|
13121 | };
|
13122 | this._dispatchEventFromSandbox(actions, jsEvent);
|
13123 | });
|
13124 | this._setEventListeners(element, [["change", "Validate"], ["change", "Action"], ["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.checked);
|
13125 | }
|
13126 | this._setBackgroundColor(element);
|
13127 | this._setDefaultPropertiesFromJS(element);
|
13128 | this.container.append(element);
|
13129 | return this.container;
|
13130 | }
|
13131 | }
|
13132 | class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
|
13133 | constructor(parameters) {
|
13134 | super(parameters, {
|
13135 | ignoreBorder: parameters.data.hasAppearance
|
13136 | });
|
13137 | }
|
13138 | render() {
|
13139 | const container = super.render();
|
13140 | container.classList.add("buttonWidgetAnnotation", "pushButton");
|
13141 | if (this.data.alternativeText) {
|
13142 | container.title = this.data.alternativeText;
|
13143 | }
|
13144 | const linkElement = container.lastChild;
|
13145 | if (this.enableScripting && this.hasJSActions && linkElement) {
|
13146 | this._setDefaultPropertiesFromJS(linkElement);
|
13147 | linkElement.addEventListener("updatefromsandbox", jsEvent => {
|
13148 | this._dispatchEventFromSandbox({}, jsEvent);
|
13149 | });
|
13150 | }
|
13151 | return container;
|
13152 | }
|
13153 | }
|
13154 | class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
|
13155 | constructor(parameters) {
|
13156 | super(parameters, {
|
13157 | isRenderable: parameters.renderForms
|
13158 | });
|
13159 | }
|
13160 | render() {
|
13161 | this.container.classList.add("choiceWidgetAnnotation");
|
13162 | const storage = this.annotationStorage;
|
13163 | const id = this.data.id;
|
13164 | const storedData = storage.getValue(id, {
|
13165 | value: this.data.fieldValue
|
13166 | });
|
13167 | const selectElement = document.createElement("select");
|
13168 | GetElementsByNameSet.add(selectElement);
|
13169 | selectElement.setAttribute("data-element-id", id);
|
13170 | selectElement.disabled = this.data.readOnly;
|
13171 | this._setRequired(selectElement, this.data.required);
|
13172 | selectElement.name = this.data.fieldName;
|
13173 | selectElement.tabIndex = DEFAULT_TAB_INDEX;
|
13174 | let addAnEmptyEntry = this.data.combo && this.data.options.length > 0;
|
13175 | if (!this.data.combo) {
|
13176 | selectElement.size = this.data.options.length;
|
13177 | if (this.data.multiSelect) {
|
13178 | selectElement.multiple = true;
|
13179 | }
|
13180 | }
|
13181 | selectElement.addEventListener("resetform", event => {
|
13182 | const defaultValue = this.data.defaultFieldValue;
|
13183 | for (const option of selectElement.options) {
|
13184 | option.selected = option.value === defaultValue;
|
13185 | }
|
13186 | });
|
13187 | for (const option of this.data.options) {
|
13188 | const optionElement = document.createElement("option");
|
13189 | optionElement.textContent = option.displayValue;
|
13190 | optionElement.value = option.exportValue;
|
13191 | if (storedData.value.includes(option.exportValue)) {
|
13192 | optionElement.setAttribute("selected", true);
|
13193 | addAnEmptyEntry = false;
|
13194 | }
|
13195 | selectElement.append(optionElement);
|
13196 | }
|
13197 | let removeEmptyEntry = null;
|
13198 | if (addAnEmptyEntry) {
|
13199 | const noneOptionElement = document.createElement("option");
|
13200 | noneOptionElement.value = " ";
|
13201 | noneOptionElement.setAttribute("hidden", true);
|
13202 | noneOptionElement.setAttribute("selected", true);
|
13203 | selectElement.prepend(noneOptionElement);
|
13204 | removeEmptyEntry = () => {
|
13205 | noneOptionElement.remove();
|
13206 | selectElement.removeEventListener("input", removeEmptyEntry);
|
13207 | removeEmptyEntry = null;
|
13208 | };
|
13209 | selectElement.addEventListener("input", removeEmptyEntry);
|
13210 | }
|
13211 | const getValue = isExport => {
|
13212 | const name = isExport ? "value" : "textContent";
|
13213 | const {
|
13214 | options,
|
13215 | multiple
|
13216 | } = selectElement;
|
13217 | if (!multiple) {
|
13218 | return options.selectedIndex === -1 ? null : options[options.selectedIndex][name];
|
13219 | }
|
13220 | return Array.prototype.filter.call(options, option => option.selected).map(option => option[name]);
|
13221 | };
|
13222 | let selectedValues = getValue(false);
|
13223 | const getItems = event => {
|
13224 | const options = event.target.options;
|
13225 | return Array.prototype.map.call(options, option => {
|
13226 | return {
|
13227 | displayValue: option.textContent,
|
13228 | exportValue: option.value
|
13229 | };
|
13230 | });
|
13231 | };
|
13232 | if (this.enableScripting && this.hasJSActions) {
|
13233 | selectElement.addEventListener("updatefromsandbox", jsEvent => {
|
13234 | const actions = {
|
13235 | value(event) {
|
13236 | removeEmptyEntry?.();
|
13237 | const value = event.detail.value;
|
13238 | const values = new Set(Array.isArray(value) ? value : [value]);
|
13239 | for (const option of selectElement.options) {
|
13240 | option.selected = values.has(option.value);
|
13241 | }
|
13242 | storage.setValue(id, {
|
13243 | value: getValue(true)
|
13244 | });
|
13245 | selectedValues = getValue(false);
|
13246 | },
|
13247 | multipleSelection(event) {
|
13248 | selectElement.multiple = true;
|
13249 | },
|
13250 | remove(event) {
|
13251 | const options = selectElement.options;
|
13252 | const index = event.detail.remove;
|
13253 | options[index].selected = false;
|
13254 | selectElement.remove(index);
|
13255 | if (options.length > 0) {
|
13256 | const i = Array.prototype.findIndex.call(options, option => option.selected);
|
13257 | if (i === -1) {
|
13258 | options[0].selected = true;
|
13259 | }
|
13260 | }
|
13261 | storage.setValue(id, {
|
13262 | value: getValue(true),
|
13263 | items: getItems(event)
|
13264 | });
|
13265 | selectedValues = getValue(false);
|
13266 | },
|
13267 | clear(event) {
|
13268 | while (selectElement.length !== 0) {
|
13269 | selectElement.remove(0);
|
13270 | }
|
13271 | storage.setValue(id, {
|
13272 | value: null,
|
13273 | items: []
|
13274 | });
|
13275 | selectedValues = getValue(false);
|
13276 | },
|
13277 | insert(event) {
|
13278 | const {
|
13279 | index,
|
13280 | displayValue,
|
13281 | exportValue
|
13282 | } = event.detail.insert;
|
13283 | const selectChild = selectElement.children[index];
|
13284 | const optionElement = document.createElement("option");
|
13285 | optionElement.textContent = displayValue;
|
13286 | optionElement.value = exportValue;
|
13287 | if (selectChild) {
|
13288 | selectChild.before(optionElement);
|
13289 | } else {
|
13290 | selectElement.append(optionElement);
|
13291 | }
|
13292 | storage.setValue(id, {
|
13293 | value: getValue(true),
|
13294 | items: getItems(event)
|
13295 | });
|
13296 | selectedValues = getValue(false);
|
13297 | },
|
13298 | items(event) {
|
13299 | const {
|
13300 | items
|
13301 | } = event.detail;
|
13302 | while (selectElement.length !== 0) {
|
13303 | selectElement.remove(0);
|
13304 | }
|
13305 | for (const item of items) {
|
13306 | const {
|
13307 | displayValue,
|
13308 | exportValue
|
13309 | } = item;
|
13310 | const optionElement = document.createElement("option");
|
13311 | optionElement.textContent = displayValue;
|
13312 | optionElement.value = exportValue;
|
13313 | selectElement.append(optionElement);
|
13314 | }
|
13315 | if (selectElement.options.length > 0) {
|
13316 | selectElement.options[0].selected = true;
|
13317 | }
|
13318 | storage.setValue(id, {
|
13319 | value: getValue(true),
|
13320 | items: getItems(event)
|
13321 | });
|
13322 | selectedValues = getValue(false);
|
13323 | },
|
13324 | indices(event) {
|
13325 | const indices = new Set(event.detail.indices);
|
13326 | for (const option of event.target.options) {
|
13327 | option.selected = indices.has(option.index);
|
13328 | }
|
13329 | storage.setValue(id, {
|
13330 | value: getValue(true)
|
13331 | });
|
13332 | selectedValues = getValue(false);
|
13333 | },
|
13334 | editable(event) {
|
13335 | event.target.disabled = !event.detail.editable;
|
13336 | }
|
13337 | };
|
13338 | this._dispatchEventFromSandbox(actions, jsEvent);
|
13339 | });
|
13340 | selectElement.addEventListener("input", event => {
|
13341 | const exportValue = getValue(true);
|
13342 | storage.setValue(id, {
|
13343 | value: exportValue
|
13344 | });
|
13345 | event.preventDefault();
|
13346 | this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
13347 | source: this,
|
13348 | detail: {
|
13349 | id,
|
13350 | name: "Keystroke",
|
13351 | value: selectedValues,
|
13352 | changeEx: exportValue,
|
13353 | willCommit: false,
|
13354 | commitKey: 1,
|
13355 | keyDown: false
|
13356 | }
|
13357 | });
|
13358 | });
|
13359 | this._setEventListeners(selectElement, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"], ["input", "Action"], ["input", "Validate"]], event => event.target.value);
|
13360 | } else {
|
13361 | selectElement.addEventListener("input", function (event) {
|
13362 | storage.setValue(id, {
|
13363 | value: getValue(true)
|
13364 | });
|
13365 | });
|
13366 | }
|
13367 | if (this.data.combo) {
|
13368 | this._setTextStyle(selectElement);
|
13369 | } else {}
|
13370 | this._setBackgroundColor(selectElement);
|
13371 | this._setDefaultPropertiesFromJS(selectElement);
|
13372 | this.container.append(selectElement);
|
13373 | return this.container;
|
13374 | }
|
13375 | }
|
13376 | class PopupAnnotationElement extends AnnotationElement {
|
13377 | static IGNORE_TYPES = new Set(["Line", "Square", "Circle", "PolyLine", "Polygon", "Ink"]);
|
13378 | constructor(parameters) {
|
13379 | const {
|
13380 | data
|
13381 | } = parameters;
|
13382 | const isRenderable = !PopupAnnotationElement.IGNORE_TYPES.has(data.parentType) && !!(data.titleObj?.str || data.contentsObj?.str || data.richText?.str);
|
13383 | super(parameters, {
|
13384 | isRenderable
|
13385 | });
|
13386 | }
|
13387 | render() {
|
13388 | this.container.classList.add("popupAnnotation");
|
13389 | const parentElements = this.layer.querySelectorAll(`[data-annotation-id="${this.data.parentId}"]`);
|
13390 | if (parentElements.length === 0) {
|
13391 | return this.container;
|
13392 | }
|
13393 | const popup = new PopupElement({
|
13394 | container: this.container,
|
13395 | trigger: Array.from(parentElements),
|
13396 | color: this.data.color,
|
13397 | titleObj: this.data.titleObj,
|
13398 | modificationDate: this.data.modificationDate,
|
13399 | contentsObj: this.data.contentsObj,
|
13400 | richText: this.data.richText
|
13401 | });
|
13402 | const page = this.page;
|
13403 | const rect = _util.Util.normalizeRect([this.data.parentRect[0], page.view[3] - this.data.parentRect[1] + page.view[1], this.data.parentRect[2], page.view[3] - this.data.parentRect[3] + page.view[1]]);
|
13404 | const popupLeft = rect[0] + this.data.parentRect[2] - this.data.parentRect[0];
|
13405 | const popupTop = rect[1];
|
13406 | const {
|
13407 | pageWidth,
|
13408 | pageHeight,
|
13409 | pageX,
|
13410 | pageY
|
13411 | } = this.viewport.rawDims;
|
13412 | this.container.style.left = `${100 * (popupLeft - pageX) / pageWidth}%`;
|
13413 | this.container.style.top = `${100 * (popupTop - pageY) / pageHeight}%`;
|
13414 | this.container.append(popup.render());
|
13415 | return this.container;
|
13416 | }
|
13417 | }
|
13418 | class PopupElement {
|
13419 | constructor(parameters) {
|
13420 | this.container = parameters.container;
|
13421 | this.trigger = parameters.trigger;
|
13422 | this.color = parameters.color;
|
13423 | this.titleObj = parameters.titleObj;
|
13424 | this.modificationDate = parameters.modificationDate;
|
13425 | this.contentsObj = parameters.contentsObj;
|
13426 | this.richText = parameters.richText;
|
13427 | this.hideWrapper = parameters.hideWrapper || false;
|
13428 | this.pinned = false;
|
13429 | }
|
13430 | render() {
|
13431 | const BACKGROUND_ENLIGHT = 0.7;
|
13432 | const wrapper = document.createElement("div");
|
13433 | wrapper.classList.add("popupWrapper");
|
13434 | this.hideElement = this.hideWrapper ? wrapper : this.container;
|
13435 | this.hideElement.hidden = true;
|
13436 | const popup = document.createElement("div");
|
13437 | popup.classList.add("popup");
|
13438 | const color = this.color;
|
13439 | if (color) {
|
13440 | const r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
|
13441 | const g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
|
13442 | const b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
|
13443 | popup.style.backgroundColor = _util.Util.makeHexColor(r | 0, g | 0, b | 0);
|
13444 | }
|
13445 | const title = document.createElement("h1");
|
13446 | title.dir = this.titleObj.dir;
|
13447 | title.textContent = this.titleObj.str;
|
13448 | popup.append(title);
|
13449 | const dateObject = _display_utils.PDFDateString.toDateObject(this.modificationDate);
|
13450 | if (dateObject) {
|
13451 | const modificationDate = document.createElement("span");
|
13452 | modificationDate.classList.add("popupDate");
|
13453 | modificationDate.textContent = "{{date}}, {{time}}";
|
13454 | modificationDate.dataset.l10nId = "annotation_date_string";
|
13455 | modificationDate.dataset.l10nArgs = JSON.stringify({
|
13456 | date: dateObject.toLocaleDateString(),
|
13457 | time: dateObject.toLocaleTimeString()
|
13458 | });
|
13459 | popup.append(modificationDate);
|
13460 | }
|
13461 | if (this.richText?.str && (!this.contentsObj?.str || this.contentsObj.str === this.richText.str)) {
|
13462 | _xfa_layer.XfaLayer.render({
|
13463 | xfaHtml: this.richText.html,
|
13464 | intent: "richText",
|
13465 | div: popup
|
13466 | });
|
13467 | popup.lastChild.classList.add("richText", "popupContent");
|
13468 | } else {
|
13469 | const contents = this._formatContents(this.contentsObj);
|
13470 | popup.append(contents);
|
13471 | }
|
13472 | if (!Array.isArray(this.trigger)) {
|
13473 | this.trigger = [this.trigger];
|
13474 | }
|
13475 | for (const element of this.trigger) {
|
13476 | element.addEventListener("click", this._toggle.bind(this));
|
13477 | element.addEventListener("mouseover", this._show.bind(this, false));
|
13478 | element.addEventListener("mouseout", this._hide.bind(this, false));
|
13479 | }
|
13480 | popup.addEventListener("click", this._hide.bind(this, true));
|
13481 | wrapper.append(popup);
|
13482 | return wrapper;
|
13483 | }
|
13484 | _formatContents({
|
13485 | str,
|
13486 | dir
|
13487 | }) {
|
13488 | const p = document.createElement("p");
|
13489 | p.classList.add("popupContent");
|
13490 | p.dir = dir;
|
13491 | const lines = str.split(/(?:\r\n?|\n)/);
|
13492 | for (let i = 0, ii = lines.length; i < ii; ++i) {
|
13493 | const line = lines[i];
|
13494 | p.append(document.createTextNode(line));
|
13495 | if (i < ii - 1) {
|
13496 | p.append(document.createElement("br"));
|
13497 | }
|
13498 | }
|
13499 | return p;
|
13500 | }
|
13501 | _toggle() {
|
13502 | if (this.pinned) {
|
13503 | this._hide(true);
|
13504 | } else {
|
13505 | this._show(true);
|
13506 | }
|
13507 | }
|
13508 | _show(pin = false) {
|
13509 | if (pin) {
|
13510 | this.pinned = true;
|
13511 | }
|
13512 | if (this.hideElement.hidden) {
|
13513 | this.hideElement.hidden = false;
|
13514 | this.container.style.zIndex = parseInt(this.container.style.zIndex) + 1000;
|
13515 | }
|
13516 | }
|
13517 | _hide(unpin = true) {
|
13518 | if (unpin) {
|
13519 | this.pinned = false;
|
13520 | }
|
13521 | if (!this.hideElement.hidden && !this.pinned) {
|
13522 | this.hideElement.hidden = true;
|
13523 | this.container.style.zIndex = parseInt(this.container.style.zIndex) - 1000;
|
13524 | }
|
13525 | }
|
13526 | }
|
13527 | class FreeTextAnnotationElement extends AnnotationElement {
|
13528 | constructor(parameters) {
|
13529 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
|
13530 | super(parameters, {
|
13531 | isRenderable,
|
13532 | ignoreBorder: true
|
13533 | });
|
13534 | this.textContent = parameters.data.textContent;
|
13535 | }
|
13536 | render() {
|
13537 | this.container.classList.add("freeTextAnnotation");
|
13538 | if (this.textContent) {
|
13539 | const content = document.createElement("div");
|
13540 | content.classList.add("annotationTextContent");
|
13541 | content.setAttribute("role", "comment");
|
13542 | for (const line of this.textContent) {
|
13543 | const lineSpan = document.createElement("span");
|
13544 | lineSpan.textContent = line;
|
13545 | content.append(lineSpan);
|
13546 | }
|
13547 | this.container.append(content);
|
13548 | }
|
13549 | if (!this.data.hasPopup) {
|
13550 | this._createPopup(null, this.data);
|
13551 | }
|
13552 | return this.container;
|
13553 | }
|
13554 | }
|
13555 | class LineAnnotationElement extends AnnotationElement {
|
13556 | constructor(parameters) {
|
13557 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
|
13558 | super(parameters, {
|
13559 | isRenderable,
|
13560 | ignoreBorder: true
|
13561 | });
|
13562 | }
|
13563 | render() {
|
13564 | this.container.classList.add("lineAnnotation");
|
13565 | const data = this.data;
|
13566 | const {
|
13567 | width,
|
13568 | height
|
13569 | } = getRectDims(data.rect);
|
13570 | const svg = this.svgFactory.create(width, height, true);
|
13571 | const line = this.svgFactory.createElement("svg:line");
|
13572 | line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
|
13573 | line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
|
13574 | line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
|
13575 | line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
|
13576 | line.setAttribute("stroke-width", data.borderStyle.width || 1);
|
13577 | line.setAttribute("stroke", "transparent");
|
13578 | line.setAttribute("fill", "transparent");
|
13579 | svg.append(line);
|
13580 | this.container.append(svg);
|
13581 | this._createPopup(line, data);
|
13582 | return this.container;
|
13583 | }
|
13584 | }
|
13585 | class SquareAnnotationElement extends AnnotationElement {
|
13586 | constructor(parameters) {
|
13587 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
|
13588 | super(parameters, {
|
13589 | isRenderable,
|
13590 | ignoreBorder: true
|
13591 | });
|
13592 | }
|
13593 | render() {
|
13594 | this.container.classList.add("squareAnnotation");
|
13595 | const data = this.data;
|
13596 | const {
|
13597 | width,
|
13598 | height
|
13599 | } = getRectDims(data.rect);
|
13600 | const svg = this.svgFactory.create(width, height, true);
|
13601 | const borderWidth = data.borderStyle.width;
|
13602 | const square = this.svgFactory.createElement("svg:rect");
|
13603 | square.setAttribute("x", borderWidth / 2);
|
13604 | square.setAttribute("y", borderWidth / 2);
|
13605 | square.setAttribute("width", width - borderWidth);
|
13606 | square.setAttribute("height", height - borderWidth);
|
13607 | square.setAttribute("stroke-width", borderWidth || 1);
|
13608 | square.setAttribute("stroke", "transparent");
|
13609 | square.setAttribute("fill", "transparent");
|
13610 | svg.append(square);
|
13611 | this.container.append(svg);
|
13612 | this._createPopup(square, data);
|
13613 | return this.container;
|
13614 | }
|
13615 | }
|
13616 | class CircleAnnotationElement extends AnnotationElement {
|
13617 | constructor(parameters) {
|
13618 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
|
13619 | super(parameters, {
|
13620 | isRenderable,
|
13621 | ignoreBorder: true
|
13622 | });
|
13623 | }
|
13624 | render() {
|
13625 | this.container.classList.add("circleAnnotation");
|
13626 | const data = this.data;
|
13627 | const {
|
13628 | width,
|
13629 | height
|
13630 | } = getRectDims(data.rect);
|
13631 | const svg = this.svgFactory.create(width, height, true);
|
13632 | const borderWidth = data.borderStyle.width;
|
13633 | const circle = this.svgFactory.createElement("svg:ellipse");
|
13634 | circle.setAttribute("cx", width / 2);
|
13635 | circle.setAttribute("cy", height / 2);
|
13636 | circle.setAttribute("rx", width / 2 - borderWidth / 2);
|
13637 | circle.setAttribute("ry", height / 2 - borderWidth / 2);
|
13638 | circle.setAttribute("stroke-width", borderWidth || 1);
|
13639 | circle.setAttribute("stroke", "transparent");
|
13640 | circle.setAttribute("fill", "transparent");
|
13641 | svg.append(circle);
|
13642 | this.container.append(svg);
|
13643 | this._createPopup(circle, data);
|
13644 | return this.container;
|
13645 | }
|
13646 | }
|
13647 | class PolylineAnnotationElement extends AnnotationElement {
|
13648 | constructor(parameters) {
|
13649 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
|
13650 | super(parameters, {
|
13651 | isRenderable,
|
13652 | ignoreBorder: true
|
13653 | });
|
13654 | this.containerClassName = "polylineAnnotation";
|
13655 | this.svgElementName = "svg:polyline";
|
13656 | }
|
13657 | render() {
|
13658 | this.container.classList.add(this.containerClassName);
|
13659 | const data = this.data;
|
13660 | const {
|
13661 | width,
|
13662 | height
|
13663 | } = getRectDims(data.rect);
|
13664 | const svg = this.svgFactory.create(width, height, true);
|
13665 | let points = [];
|
13666 | for (const coordinate of data.vertices) {
|
13667 | const x = coordinate.x - data.rect[0];
|
13668 | const y = data.rect[3] - coordinate.y;
|
13669 | points.push(x + "," + y);
|
13670 | }
|
13671 | points = points.join(" ");
|
13672 | const polyline = this.svgFactory.createElement(this.svgElementName);
|
13673 | polyline.setAttribute("points", points);
|
13674 | polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
|
13675 | polyline.setAttribute("stroke", "transparent");
|
13676 | polyline.setAttribute("fill", "transparent");
|
13677 | svg.append(polyline);
|
13678 | this.container.append(svg);
|
13679 | this._createPopup(polyline, data);
|
13680 | return this.container;
|
13681 | }
|
13682 | }
|
13683 | class PolygonAnnotationElement extends PolylineAnnotationElement {
|
13684 | constructor(parameters) {
|
13685 | super(parameters);
|
13686 | this.containerClassName = "polygonAnnotation";
|
13687 | this.svgElementName = "svg:polygon";
|
13688 | }
|
13689 | }
|
13690 | class CaretAnnotationElement extends AnnotationElement {
|
13691 | constructor(parameters) {
|
13692 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
|
13693 | super(parameters, {
|
13694 | isRenderable,
|
13695 | ignoreBorder: true
|
13696 | });
|
13697 | }
|
13698 | render() {
|
13699 | this.container.classList.add("caretAnnotation");
|
13700 | if (!this.data.hasPopup) {
|
13701 | this._createPopup(null, this.data);
|
13702 | }
|
13703 | return this.container;
|
13704 | }
|
13705 | }
|
13706 | class InkAnnotationElement extends AnnotationElement {
|
13707 | constructor(parameters) {
|
13708 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
|
13709 | super(parameters, {
|
13710 | isRenderable,
|
13711 | ignoreBorder: true
|
13712 | });
|
13713 | this.containerClassName = "inkAnnotation";
|
13714 | this.svgElementName = "svg:polyline";
|
13715 | }
|
13716 | render() {
|
13717 | this.container.classList.add(this.containerClassName);
|
13718 | const data = this.data;
|
13719 | const {
|
13720 | width,
|
13721 | height
|
13722 | } = getRectDims(data.rect);
|
13723 | const svg = this.svgFactory.create(width, height, true);
|
13724 | for (const inkList of data.inkLists) {
|
13725 | let points = [];
|
13726 | for (const coordinate of inkList) {
|
13727 | const x = coordinate.x - data.rect[0];
|
13728 | const y = data.rect[3] - coordinate.y;
|
13729 | points.push(`${x},${y}`);
|
13730 | }
|
13731 | points = points.join(" ");
|
13732 | const polyline = this.svgFactory.createElement(this.svgElementName);
|
13733 | polyline.setAttribute("points", points);
|
13734 | polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
|
13735 | polyline.setAttribute("stroke", "transparent");
|
13736 | polyline.setAttribute("fill", "transparent");
|
13737 | this._createPopup(polyline, data);
|
13738 | svg.append(polyline);
|
13739 | }
|
13740 | this.container.append(svg);
|
13741 | return this.container;
|
13742 | }
|
13743 | }
|
13744 | class HighlightAnnotationElement extends AnnotationElement {
|
13745 | constructor(parameters) {
|
13746 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
|
13747 | super(parameters, {
|
13748 | isRenderable,
|
13749 | ignoreBorder: true,
|
13750 | createQuadrilaterals: true
|
13751 | });
|
13752 | }
|
13753 | render() {
|
13754 | if (!this.data.hasPopup) {
|
13755 | this._createPopup(null, this.data);
|
13756 | }
|
13757 | if (this.quadrilaterals) {
|
13758 | return this._renderQuadrilaterals("highlightAnnotation");
|
13759 | }
|
13760 | this.container.classList.add("highlightAnnotation");
|
13761 | return this.container;
|
13762 | }
|
13763 | }
|
13764 | class UnderlineAnnotationElement extends AnnotationElement {
|
13765 | constructor(parameters) {
|
13766 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
|
13767 | super(parameters, {
|
13768 | isRenderable,
|
13769 | ignoreBorder: true,
|
13770 | createQuadrilaterals: true
|
13771 | });
|
13772 | }
|
13773 | render() {
|
13774 | if (!this.data.hasPopup) {
|
13775 | this._createPopup(null, this.data);
|
13776 | }
|
13777 | if (this.quadrilaterals) {
|
13778 | return this._renderQuadrilaterals("underlineAnnotation");
|
13779 | }
|
13780 | this.container.classList.add("underlineAnnotation");
|
13781 | return this.container;
|
13782 | }
|
13783 | }
|
13784 | class SquigglyAnnotationElement extends AnnotationElement {
|
13785 | constructor(parameters) {
|
13786 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
|
13787 | super(parameters, {
|
13788 | isRenderable,
|
13789 | ignoreBorder: true,
|
13790 | createQuadrilaterals: true
|
13791 | });
|
13792 | }
|
13793 | render() {
|
13794 | if (!this.data.hasPopup) {
|
13795 | this._createPopup(null, this.data);
|
13796 | }
|
13797 | if (this.quadrilaterals) {
|
13798 | return this._renderQuadrilaterals("squigglyAnnotation");
|
13799 | }
|
13800 | this.container.classList.add("squigglyAnnotation");
|
13801 | return this.container;
|
13802 | }
|
13803 | }
|
13804 | class StrikeOutAnnotationElement extends AnnotationElement {
|
13805 | constructor(parameters) {
|
13806 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
|
13807 | super(parameters, {
|
13808 | isRenderable,
|
13809 | ignoreBorder: true,
|
13810 | createQuadrilaterals: true
|
13811 | });
|
13812 | }
|
13813 | render() {
|
13814 | if (!this.data.hasPopup) {
|
13815 | this._createPopup(null, this.data);
|
13816 | }
|
13817 | if (this.quadrilaterals) {
|
13818 | return this._renderQuadrilaterals("strikeoutAnnotation");
|
13819 | }
|
13820 | this.container.classList.add("strikeoutAnnotation");
|
13821 | return this.container;
|
13822 | }
|
13823 | }
|
13824 | class StampAnnotationElement extends AnnotationElement {
|
13825 | constructor(parameters) {
|
13826 | const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str || parameters.data.richText?.str);
|
13827 | super(parameters, {
|
13828 | isRenderable,
|
13829 | ignoreBorder: true
|
13830 | });
|
13831 | }
|
13832 | render() {
|
13833 | this.container.classList.add("stampAnnotation");
|
13834 | if (!this.data.hasPopup) {
|
13835 | this._createPopup(null, this.data);
|
13836 | }
|
13837 | return this.container;
|
13838 | }
|
13839 | }
|
13840 | class FileAttachmentAnnotationElement extends AnnotationElement {
|
13841 | constructor(parameters) {
|
13842 | super(parameters, {
|
13843 | isRenderable: true
|
13844 | });
|
13845 | const {
|
13846 | filename,
|
13847 | content
|
13848 | } = this.data.file;
|
13849 | this.filename = (0, _display_utils.getFilenameFromUrl)(filename, true);
|
13850 | this.content = content;
|
13851 | this.linkService.eventBus?.dispatch("fileattachmentannotation", {
|
13852 | source: this,
|
13853 | filename,
|
13854 | content
|
13855 | });
|
13856 | }
|
13857 | render() {
|
13858 | this.container.classList.add("fileAttachmentAnnotation");
|
13859 | let trigger;
|
13860 | if (this.data.hasAppearance) {
|
13861 | trigger = document.createElement("div");
|
13862 | } else {
|
13863 | trigger = document.createElement("img");
|
13864 | trigger.src = `${this.imageResourcesPath}annotation-${/paperclip/i.test(this.data.name) ? "paperclip" : "pushpin"}.svg`;
|
13865 | }
|
13866 | trigger.classList.add("popupTriggerArea");
|
13867 | trigger.addEventListener("dblclick", this._download.bind(this));
|
13868 | if (!this.data.hasPopup && (this.data.titleObj?.str || this.data.contentsObj?.str || this.data.richText)) {
|
13869 | this._createPopup(trigger, this.data);
|
13870 | }
|
13871 | this.container.append(trigger);
|
13872 | return this.container;
|
13873 | }
|
13874 | _download() {
|
13875 | this.downloadManager?.openOrDownloadData(this.container, this.content, this.filename);
|
13876 | }
|
13877 | }
|
13878 | class AnnotationLayer {
|
13879 | static #appendElement(element, id, div, accessibilityManager) {
|
13880 | const contentElement = element.firstChild || element;
|
13881 | contentElement.id = `${_display_utils.AnnotationPrefix}${id}`;
|
13882 | div.append(element);
|
13883 | accessibilityManager?.moveElementInDOM(div, element, contentElement, false);
|
13884 | }
|
13885 | static render(params) {
|
13886 | const {
|
13887 | annotations,
|
13888 | div,
|
13889 | viewport,
|
13890 | accessibilityManager
|
13891 | } = params;
|
13892 | (0, _display_utils.setLayerDimensions)(div, viewport);
|
13893 | const elementParams = {
|
13894 | data: null,
|
13895 | layer: div,
|
13896 | page: params.page,
|
13897 | viewport,
|
13898 | linkService: params.linkService,
|
13899 | downloadManager: params.downloadManager,
|
13900 | imageResourcesPath: params.imageResourcesPath || "",
|
13901 | renderForms: params.renderForms !== false,
|
13902 | svgFactory: new _display_utils.DOMSVGFactory(),
|
13903 | annotationStorage: params.annotationStorage || new _annotation_storage.AnnotationStorage(),
|
13904 | enableScripting: params.enableScripting === true,
|
13905 | hasJSActions: params.hasJSActions,
|
13906 | fieldObjects: params.fieldObjects
|
13907 | };
|
13908 | let zIndex = 0;
|
13909 | for (const data of annotations) {
|
13910 | if (data.noHTML) {
|
13911 | continue;
|
13912 | }
|
13913 | if (data.annotationType !== _util.AnnotationType.POPUP) {
|
13914 | const {
|
13915 | width,
|
13916 | height
|
13917 | } = getRectDims(data.rect);
|
13918 | if (width <= 0 || height <= 0) {
|
13919 | continue;
|
13920 | }
|
13921 | }
|
13922 | elementParams.data = data;
|
13923 | const element = AnnotationElementFactory.create(elementParams);
|
13924 | if (!element.isRenderable) {
|
13925 | continue;
|
13926 | }
|
13927 | const rendered = element.render();
|
13928 | if (data.hidden) {
|
13929 | rendered.style.visibility = "hidden";
|
13930 | }
|
13931 | if (Array.isArray(rendered)) {
|
13932 | for (const renderedElement of rendered) {
|
13933 | renderedElement.style.zIndex = zIndex++;
|
13934 | AnnotationLayer.#appendElement(renderedElement, data.id, div, accessibilityManager);
|
13935 | }
|
13936 | } else {
|
13937 | rendered.style.zIndex = zIndex++;
|
13938 | if (element instanceof PopupAnnotationElement) {
|
13939 | div.prepend(rendered);
|
13940 | } else {
|
13941 | AnnotationLayer.#appendElement(rendered, data.id, div, accessibilityManager);
|
13942 | }
|
13943 | }
|
13944 | }
|
13945 | this.#setAnnotationCanvasMap(div, params.annotationCanvasMap);
|
13946 | }
|
13947 | static update(params) {
|
13948 | const {
|
13949 | annotationCanvasMap,
|
13950 | div,
|
13951 | viewport
|
13952 | } = params;
|
13953 | (0, _display_utils.setLayerDimensions)(div, {
|
13954 | rotation: viewport.rotation
|
13955 | });
|
13956 | this.#setAnnotationCanvasMap(div, annotationCanvasMap);
|
13957 | div.hidden = false;
|
13958 | }
|
13959 | static #setAnnotationCanvasMap(div, annotationCanvasMap) {
|
13960 | if (!annotationCanvasMap) {
|
13961 | return;
|
13962 | }
|
13963 | for (const [id, canvas] of annotationCanvasMap) {
|
13964 | const element = div.querySelector(`[data-annotation-id="${id}"]`);
|
13965 | if (!element) {
|
13966 | continue;
|
13967 | }
|
13968 | const {
|
13969 | firstChild
|
13970 | } = element;
|
13971 | if (!firstChild) {
|
13972 | element.append(canvas);
|
13973 | } else if (firstChild.nodeName === "CANVAS") {
|
13974 | firstChild.replaceWith(canvas);
|
13975 | } else {
|
13976 | firstChild.before(canvas);
|
13977 | }
|
13978 | }
|
13979 | annotationCanvasMap.clear();
|
13980 | }
|
13981 | }
|
13982 | exports.AnnotationLayer = AnnotationLayer;
|
13983 |
|
13984 | }),
|
13985 |
|
13986 | ((__unused_webpack_module, exports) => {
|
13987 |
|
13988 |
|
13989 |
|
13990 | Object.defineProperty(exports, "__esModule", ({
|
13991 | value: true
|
13992 | }));
|
13993 | exports.ColorConverters = void 0;
|
13994 | function makeColorComp(n) {
|
13995 | return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
|
13996 | }
|
13997 | class ColorConverters {
|
13998 | static CMYK_G([c, y, m, k]) {
|
13999 | return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
|
14000 | }
|
14001 | static G_CMYK([g]) {
|
14002 | return ["CMYK", 0, 0, 0, 1 - g];
|
14003 | }
|
14004 | static G_RGB([g]) {
|
14005 | return ["RGB", g, g, g];
|
14006 | }
|
14007 | static G_HTML([g]) {
|
14008 | const G = makeColorComp(g);
|
14009 | return `#${G}${G}${G}`;
|
14010 | }
|
14011 | static RGB_G([r, g, b]) {
|
14012 | return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
|
14013 | }
|
14014 | static RGB_HTML([r, g, b]) {
|
14015 | const R = makeColorComp(r);
|
14016 | const G = makeColorComp(g);
|
14017 | const B = makeColorComp(b);
|
14018 | return `#${R}${G}${B}`;
|
14019 | }
|
14020 | static T_HTML() {
|
14021 | return "#00000000";
|
14022 | }
|
14023 | static CMYK_RGB([c, y, m, k]) {
|
14024 | return ["RGB", 1 - Math.min(1, c + k), 1 - Math.min(1, m + k), 1 - Math.min(1, y + k)];
|
14025 | }
|
14026 | static CMYK_HTML(components) {
|
14027 | const rgb = this.CMYK_RGB(components).slice(1);
|
14028 | return this.RGB_HTML(rgb);
|
14029 | }
|
14030 | static RGB_CMYK([r, g, b]) {
|
14031 | const c = 1 - r;
|
14032 | const m = 1 - g;
|
14033 | const y = 1 - b;
|
14034 | const k = Math.min(c, m, y);
|
14035 | return ["CMYK", c, m, y, k];
|
14036 | }
|
14037 | }
|
14038 | exports.ColorConverters = ColorConverters;
|
14039 |
|
14040 | }),
|
14041 |
|
14042 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
14043 |
|
14044 |
|
14045 |
|
14046 | Object.defineProperty(exports, "__esModule", ({
|
14047 | value: true
|
14048 | }));
|
14049 | exports.XfaLayer = void 0;
|
14050 | var _xfa_text = __w_pdfjs_require__(19);
|
14051 | class XfaLayer {
|
14052 | static setupStorage(html, id, element, storage, intent) {
|
14053 | const storedData = storage.getValue(id, {
|
14054 | value: null
|
14055 | });
|
14056 | switch (element.name) {
|
14057 | case "textarea":
|
14058 | if (storedData.value !== null) {
|
14059 | html.textContent = storedData.value;
|
14060 | }
|
14061 | if (intent === "print") {
|
14062 | break;
|
14063 | }
|
14064 | html.addEventListener("input", event => {
|
14065 | storage.setValue(id, {
|
14066 | value: event.target.value
|
14067 | });
|
14068 | });
|
14069 | break;
|
14070 | case "input":
|
14071 | if (element.attributes.type === "radio" || element.attributes.type === "checkbox") {
|
14072 | if (storedData.value === element.attributes.xfaOn) {
|
14073 | html.setAttribute("checked", true);
|
14074 | } else if (storedData.value === element.attributes.xfaOff) {
|
14075 | html.removeAttribute("checked");
|
14076 | }
|
14077 | if (intent === "print") {
|
14078 | break;
|
14079 | }
|
14080 | html.addEventListener("change", event => {
|
14081 | storage.setValue(id, {
|
14082 | value: event.target.checked ? event.target.getAttribute("xfaOn") : event.target.getAttribute("xfaOff")
|
14083 | });
|
14084 | });
|
14085 | } else {
|
14086 | if (storedData.value !== null) {
|
14087 | html.setAttribute("value", storedData.value);
|
14088 | }
|
14089 | if (intent === "print") {
|
14090 | break;
|
14091 | }
|
14092 | html.addEventListener("input", event => {
|
14093 | storage.setValue(id, {
|
14094 | value: event.target.value
|
14095 | });
|
14096 | });
|
14097 | }
|
14098 | break;
|
14099 | case "select":
|
14100 | if (storedData.value !== null) {
|
14101 | for (const option of element.children) {
|
14102 | if (option.attributes.value === storedData.value) {
|
14103 | option.attributes.selected = true;
|
14104 | }
|
14105 | }
|
14106 | }
|
14107 | html.addEventListener("input", event => {
|
14108 | const options = event.target.options;
|
14109 | const value = options.selectedIndex === -1 ? "" : options[options.selectedIndex].value;
|
14110 | storage.setValue(id, {
|
14111 | value
|
14112 | });
|
14113 | });
|
14114 | break;
|
14115 | }
|
14116 | }
|
14117 | static setAttributes({
|
14118 | html,
|
14119 | element,
|
14120 | storage = null,
|
14121 | intent,
|
14122 | linkService
|
14123 | }) {
|
14124 | const {
|
14125 | attributes
|
14126 | } = element;
|
14127 | const isHTMLAnchorElement = html instanceof HTMLAnchorElement;
|
14128 | if (attributes.type === "radio") {
|
14129 | attributes.name = `${attributes.name}-${intent}`;
|
14130 | }
|
14131 | for (const [key, value] of Object.entries(attributes)) {
|
14132 | if (value === null || value === undefined) {
|
14133 | continue;
|
14134 | }
|
14135 | switch (key) {
|
14136 | case "class":
|
14137 | if (value.length) {
|
14138 | html.setAttribute(key, value.join(" "));
|
14139 | }
|
14140 | break;
|
14141 | case "dataId":
|
14142 | break;
|
14143 | case "id":
|
14144 | html.setAttribute("data-element-id", value);
|
14145 | break;
|
14146 | case "style":
|
14147 | Object.assign(html.style, value);
|
14148 | break;
|
14149 | case "textContent":
|
14150 | html.textContent = value;
|
14151 | break;
|
14152 | default:
|
14153 | if (!isHTMLAnchorElement || key !== "href" && key !== "newWindow") {
|
14154 | html.setAttribute(key, value);
|
14155 | }
|
14156 | }
|
14157 | }
|
14158 | if (isHTMLAnchorElement) {
|
14159 | linkService.addLinkAttributes(html, attributes.href, attributes.newWindow);
|
14160 | }
|
14161 | if (storage && attributes.dataId) {
|
14162 | this.setupStorage(html, attributes.dataId, element, storage);
|
14163 | }
|
14164 | }
|
14165 | static render(parameters) {
|
14166 | const storage = parameters.annotationStorage;
|
14167 | const linkService = parameters.linkService;
|
14168 | const root = parameters.xfaHtml;
|
14169 | const intent = parameters.intent || "display";
|
14170 | const rootHtml = document.createElement(root.name);
|
14171 | if (root.attributes) {
|
14172 | this.setAttributes({
|
14173 | html: rootHtml,
|
14174 | element: root,
|
14175 | intent,
|
14176 | linkService
|
14177 | });
|
14178 | }
|
14179 | const stack = [[root, -1, rootHtml]];
|
14180 | const rootDiv = parameters.div;
|
14181 | rootDiv.append(rootHtml);
|
14182 | if (parameters.viewport) {
|
14183 | const transform = `matrix(${parameters.viewport.transform.join(",")})`;
|
14184 | rootDiv.style.transform = transform;
|
14185 | }
|
14186 | if (intent !== "richText") {
|
14187 | rootDiv.setAttribute("class", "xfaLayer xfaFont");
|
14188 | }
|
14189 | const textDivs = [];
|
14190 | while (stack.length > 0) {
|
14191 | const [parent, i, html] = stack.at(-1);
|
14192 | if (i + 1 === parent.children.length) {
|
14193 | stack.pop();
|
14194 | continue;
|
14195 | }
|
14196 | const child = parent.children[++stack.at(-1)[1]];
|
14197 | if (child === null) {
|
14198 | continue;
|
14199 | }
|
14200 | const {
|
14201 | name
|
14202 | } = child;
|
14203 | if (name === "#text") {
|
14204 | const node = document.createTextNode(child.value);
|
14205 | textDivs.push(node);
|
14206 | html.append(node);
|
14207 | continue;
|
14208 | }
|
14209 | let childHtml;
|
14210 | if (child?.attributes?.xmlns) {
|
14211 | childHtml = document.createElementNS(child.attributes.xmlns, name);
|
14212 | } else {
|
14213 | childHtml = document.createElement(name);
|
14214 | }
|
14215 | html.append(childHtml);
|
14216 | if (child.attributes) {
|
14217 | this.setAttributes({
|
14218 | html: childHtml,
|
14219 | element: child,
|
14220 | storage,
|
14221 | intent,
|
14222 | linkService
|
14223 | });
|
14224 | }
|
14225 | if (child.children && child.children.length > 0) {
|
14226 | stack.push([child, -1, childHtml]);
|
14227 | } else if (child.value) {
|
14228 | const node = document.createTextNode(child.value);
|
14229 | if (_xfa_text.XfaText.shouldBuildText(name)) {
|
14230 | textDivs.push(node);
|
14231 | }
|
14232 | childHtml.append(node);
|
14233 | }
|
14234 | }
|
14235 | for (const el of rootDiv.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea")) {
|
14236 | el.setAttribute("readOnly", true);
|
14237 | }
|
14238 | return {
|
14239 | textDivs
|
14240 | };
|
14241 | }
|
14242 | static update(parameters) {
|
14243 | const transform = `matrix(${parameters.viewport.transform.join(",")})`;
|
14244 | parameters.div.style.transform = transform;
|
14245 | parameters.div.hidden = false;
|
14246 | }
|
14247 | }
|
14248 | exports.XfaLayer = XfaLayer;
|
14249 |
|
14250 | }),
|
14251 |
|
14252 | ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
|
14253 |
|
14254 |
|
14255 |
|
14256 | Object.defineProperty(exports, "__esModule", ({
|
14257 | value: true
|
14258 | }));
|
14259 | exports.SVGGraphics = void 0;
|
14260 | var _display_utils = __w_pdfjs_require__(6);
|
14261 | var _util = __w_pdfjs_require__(1);
|
14262 | var _is_node = __w_pdfjs_require__(10);
|
14263 | let SVGGraphics = class {
|
14264 | constructor() {
|
14265 | (0, _util.unreachable)("Not implemented: SVGGraphics");
|
14266 | }
|
14267 | };
|
14268 | exports.SVGGraphics = SVGGraphics;
|
14269 | {
|
14270 | const SVG_DEFAULTS = {
|
14271 | fontStyle: "normal",
|
14272 | fontWeight: "normal",
|
14273 | fillColor: "#000000"
|
14274 | };
|
14275 | const XML_NS = "http://www.w3.org/XML/1998/namespace";
|
14276 | const XLINK_NS = "http://www.w3.org/1999/xlink";
|
14277 | const LINE_CAP_STYLES = ["butt", "round", "square"];
|
14278 | const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
|
14279 | const createObjectURL = function (data, contentType = "", forceDataSchema = false) {
|
14280 | if (URL.createObjectURL && typeof Blob !== "undefined" && !forceDataSchema) {
|
14281 | return URL.createObjectURL(new Blob([data], {
|
14282 | type: contentType
|
14283 | }));
|
14284 | }
|
14285 | const digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
14286 | let buffer = `data:${contentType};base64,`;
|
14287 | for (let i = 0, ii = data.length; i < ii; i += 3) {
|
14288 | const b1 = data[i] & 0xff;
|
14289 | const b2 = data[i + 1] & 0xff;
|
14290 | const b3 = data[i + 2] & 0xff;
|
14291 | const d1 = b1 >> 2,
|
14292 | d2 = (b1 & 3) << 4 | b2 >> 4;
|
14293 | const d3 = i + 1 < ii ? (b2 & 0xf) << 2 | b3 >> 6 : 64;
|
14294 | const d4 = i + 2 < ii ? b3 & 0x3f : 64;
|
14295 | buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
|
14296 | }
|
14297 | return buffer;
|
14298 | };
|
14299 | const convertImgDataToPng = function () {
|
14300 | const PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
14301 | const CHUNK_WRAPPER_SIZE = 12;
|
14302 | const crcTable = new Int32Array(256);
|
14303 | for (let i = 0; i < 256; i++) {
|
14304 | let c = i;
|
14305 | for (let h = 0; h < 8; h++) {
|
14306 | if (c & 1) {
|
14307 | c = 0xedb88320 ^ c >> 1 & 0x7fffffff;
|
14308 | } else {
|
14309 | c = c >> 1 & 0x7fffffff;
|
14310 | }
|
14311 | }
|
14312 | crcTable[i] = c;
|
14313 | }
|
14314 | function crc32(data, start, end) {
|
14315 | let crc = -1;
|
14316 | for (let i = start; i < end; i++) {
|
14317 | const a = (crc ^ data[i]) & 0xff;
|
14318 | const b = crcTable[a];
|
14319 | crc = crc >>> 8 ^ b;
|
14320 | }
|
14321 | return crc ^ -1;
|
14322 | }
|
14323 | function writePngChunk(type, body, data, offset) {
|
14324 | let p = offset;
|
14325 | const len = body.length;
|
14326 | data[p] = len >> 24 & 0xff;
|
14327 | data[p + 1] = len >> 16 & 0xff;
|
14328 | data[p + 2] = len >> 8 & 0xff;
|
14329 | data[p + 3] = len & 0xff;
|
14330 | p += 4;
|
14331 | data[p] = type.charCodeAt(0) & 0xff;
|
14332 | data[p + 1] = type.charCodeAt(1) & 0xff;
|
14333 | data[p + 2] = type.charCodeAt(2) & 0xff;
|
14334 | data[p + 3] = type.charCodeAt(3) & 0xff;
|
14335 | p += 4;
|
14336 | data.set(body, p);
|
14337 | p += body.length;
|
14338 | const crc = crc32(data, offset + 4, p);
|
14339 | data[p] = crc >> 24 & 0xff;
|
14340 | data[p + 1] = crc >> 16 & 0xff;
|
14341 | data[p + 2] = crc >> 8 & 0xff;
|
14342 | data[p + 3] = crc & 0xff;
|
14343 | }
|
14344 | function adler32(data, start, end) {
|
14345 | let a = 1;
|
14346 | let b = 0;
|
14347 | for (let i = start; i < end; ++i) {
|
14348 | a = (a + (data[i] & 0xff)) % 65521;
|
14349 | b = (b + a) % 65521;
|
14350 | }
|
14351 | return b << 16 | a;
|
14352 | }
|
14353 | function deflateSync(literals) {
|
14354 | if (!_is_node.isNodeJS) {
|
14355 | return deflateSyncUncompressed(literals);
|
14356 | }
|
14357 | try {
|
14358 | let input;
|
14359 | if (parseInt(process.versions.node) >= 8) {
|
14360 | input = literals;
|
14361 | } else {
|
14362 | input = Buffer.from(literals);
|
14363 | }
|
14364 | const output = require("zlib").deflateSync(input, {
|
14365 | level: 9
|
14366 | });
|
14367 | return output instanceof Uint8Array ? output : new Uint8Array(output);
|
14368 | } catch (e) {
|
14369 | (0, _util.warn)("Not compressing PNG because zlib.deflateSync is unavailable: " + e);
|
14370 | }
|
14371 | return deflateSyncUncompressed(literals);
|
14372 | }
|
14373 | function deflateSyncUncompressed(literals) {
|
14374 | let len = literals.length;
|
14375 | const maxBlockLength = 0xffff;
|
14376 | const deflateBlocks = Math.ceil(len / maxBlockLength);
|
14377 | const idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
|
14378 | let pi = 0;
|
14379 | idat[pi++] = 0x78;
|
14380 | idat[pi++] = 0x9c;
|
14381 | let pos = 0;
|
14382 | while (len > maxBlockLength) {
|
14383 | idat[pi++] = 0x00;
|
14384 | idat[pi++] = 0xff;
|
14385 | idat[pi++] = 0xff;
|
14386 | idat[pi++] = 0x00;
|
14387 | idat[pi++] = 0x00;
|
14388 | idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
|
14389 | pi += maxBlockLength;
|
14390 | pos += maxBlockLength;
|
14391 | len -= maxBlockLength;
|
14392 | }
|
14393 | idat[pi++] = 0x01;
|
14394 | idat[pi++] = len & 0xff;
|
14395 | idat[pi++] = len >> 8 & 0xff;
|
14396 | idat[pi++] = ~len & 0xffff & 0xff;
|
14397 | idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
|
14398 | idat.set(literals.subarray(pos), pi);
|
14399 | pi += literals.length - pos;
|
14400 | const adler = adler32(literals, 0, literals.length);
|
14401 | idat[pi++] = adler >> 24 & 0xff;
|
14402 | idat[pi++] = adler >> 16 & 0xff;
|
14403 | idat[pi++] = adler >> 8 & 0xff;
|
14404 | idat[pi++] = adler & 0xff;
|
14405 | return idat;
|
14406 | }
|
14407 | function encode(imgData, kind, forceDataSchema, isMask) {
|
14408 | const width = imgData.width;
|
14409 | const height = imgData.height;
|
14410 | let bitDepth, colorType, lineSize;
|
14411 | const bytes = imgData.data;
|
14412 | switch (kind) {
|
14413 | case _util.ImageKind.GRAYSCALE_1BPP:
|
14414 | colorType = 0;
|
14415 | bitDepth = 1;
|
14416 | lineSize = width + 7 >> 3;
|
14417 | break;
|
14418 | case _util.ImageKind.RGB_24BPP:
|
14419 | colorType = 2;
|
14420 | bitDepth = 8;
|
14421 | lineSize = width * 3;
|
14422 | break;
|
14423 | case _util.ImageKind.RGBA_32BPP:
|
14424 | colorType = 6;
|
14425 | bitDepth = 8;
|
14426 | lineSize = width * 4;
|
14427 | break;
|
14428 | default:
|
14429 | throw new Error("invalid format");
|
14430 | }
|
14431 | const literals = new Uint8Array((1 + lineSize) * height);
|
14432 | let offsetLiterals = 0,
|
14433 | offsetBytes = 0;
|
14434 | for (let y = 0; y < height; ++y) {
|
14435 | literals[offsetLiterals++] = 0;
|
14436 | literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
|
14437 | offsetBytes += lineSize;
|
14438 | offsetLiterals += lineSize;
|
14439 | }
|
14440 | if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
|
14441 | offsetLiterals = 0;
|
14442 | for (let y = 0; y < height; y++) {
|
14443 | offsetLiterals++;
|
14444 | for (let i = 0; i < lineSize; i++) {
|
14445 | literals[offsetLiterals++] ^= 0xff;
|
14446 | }
|
14447 | }
|
14448 | }
|
14449 | const ihdr = new Uint8Array([width >> 24 & 0xff, width >> 16 & 0xff, width >> 8 & 0xff, width & 0xff, height >> 24 & 0xff, height >> 16 & 0xff, height >> 8 & 0xff, height & 0xff, bitDepth, colorType, 0x00, 0x00, 0x00]);
|
14450 | const idat = deflateSync(literals);
|
14451 | const pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
|
14452 | const data = new Uint8Array(pngLength);
|
14453 | let offset = 0;
|
14454 | data.set(PNG_HEADER, offset);
|
14455 | offset += PNG_HEADER.length;
|
14456 | writePngChunk("IHDR", ihdr, data, offset);
|
14457 | offset += CHUNK_WRAPPER_SIZE + ihdr.length;
|
14458 | writePngChunk("IDATA", idat, data, offset);
|
14459 | offset += CHUNK_WRAPPER_SIZE + idat.length;
|
14460 | writePngChunk("IEND", new Uint8Array(0), data, offset);
|
14461 | return createObjectURL(data, "image/png", forceDataSchema);
|
14462 | }
|
14463 | return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
|
14464 | const kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
|
14465 | return encode(imgData, kind, forceDataSchema, isMask);
|
14466 | };
|
14467 | }();
|
14468 | class SVGExtraState {
|
14469 | constructor() {
|
14470 | this.fontSizeScale = 1;
|
14471 | this.fontWeight = SVG_DEFAULTS.fontWeight;
|
14472 | this.fontSize = 0;
|
14473 | this.textMatrix = _util.IDENTITY_MATRIX;
|
14474 | this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
|
14475 | this.leading = 0;
|
14476 | this.textRenderingMode = _util.TextRenderingMode.FILL;
|
14477 | this.textMatrixScale = 1;
|
14478 | this.x = 0;
|
14479 | this.y = 0;
|
14480 | this.lineX = 0;
|
14481 | this.lineY = 0;
|
14482 | this.charSpacing = 0;
|
14483 | this.wordSpacing = 0;
|
14484 | this.textHScale = 1;
|
14485 | this.textRise = 0;
|
14486 | this.fillColor = SVG_DEFAULTS.fillColor;
|
14487 | this.strokeColor = "#000000";
|
14488 | this.fillAlpha = 1;
|
14489 | this.strokeAlpha = 1;
|
14490 | this.lineWidth = 1;
|
14491 | this.lineJoin = "";
|
14492 | this.lineCap = "";
|
14493 | this.miterLimit = 0;
|
14494 | this.dashArray = [];
|
14495 | this.dashPhase = 0;
|
14496 | this.dependencies = [];
|
14497 | this.activeClipUrl = null;
|
14498 | this.clipGroup = null;
|
14499 | this.maskId = "";
|
14500 | }
|
14501 | clone() {
|
14502 | return Object.create(this);
|
14503 | }
|
14504 | setCurrentPoint(x, y) {
|
14505 | this.x = x;
|
14506 | this.y = y;
|
14507 | }
|
14508 | }
|
14509 | function opListToTree(opList) {
|
14510 | let opTree = [];
|
14511 | const tmp = [];
|
14512 | for (const opListElement of opList) {
|
14513 | if (opListElement.fn === "save") {
|
14514 | opTree.push({
|
14515 | fnId: 92,
|
14516 | fn: "group",
|
14517 | items: []
|
14518 | });
|
14519 | tmp.push(opTree);
|
14520 | opTree = opTree.at(-1).items;
|
14521 | continue;
|
14522 | }
|
14523 | if (opListElement.fn === "restore") {
|
14524 | opTree = tmp.pop();
|
14525 | } else {
|
14526 | opTree.push(opListElement);
|
14527 | }
|
14528 | }
|
14529 | return opTree;
|
14530 | }
|
14531 | function pf(value) {
|
14532 | if (Number.isInteger(value)) {
|
14533 | return value.toString();
|
14534 | }
|
14535 | const s = value.toFixed(10);
|
14536 | let i = s.length - 1;
|
14537 | if (s[i] !== "0") {
|
14538 | return s;
|
14539 | }
|
14540 | do {
|
14541 | i--;
|
14542 | } while (s[i] === "0");
|
14543 | return s.substring(0, s[i] === "." ? i : i + 1);
|
14544 | }
|
14545 | function pm(m) {
|
14546 | if (m[4] === 0 && m[5] === 0) {
|
14547 | if (m[1] === 0 && m[2] === 0) {
|
14548 | if (m[0] === 1 && m[3] === 1) {
|
14549 | return "";
|
14550 | }
|
14551 | return `scale(${pf(m[0])} ${pf(m[3])})`;
|
14552 | }
|
14553 | if (m[0] === m[3] && m[1] === -m[2]) {
|
14554 | const a = Math.acos(m[0]) * 180 / Math.PI;
|
14555 | return `rotate(${pf(a)})`;
|
14556 | }
|
14557 | } else {
|
14558 | if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
|
14559 | return `translate(${pf(m[4])} ${pf(m[5])})`;
|
14560 | }
|
14561 | }
|
14562 | return `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `${pf(m[5])})`;
|
14563 | }
|
14564 | let clipCount = 0;
|
14565 | let maskCount = 0;
|
14566 | let shadingCount = 0;
|
14567 | exports.SVGGraphics = SVGGraphics = class {
|
14568 | constructor(commonObjs, objs, forceDataSchema = false) {
|
14569 | (0, _display_utils.deprecated)("The SVG back-end is no longer maintained and *may* be removed in the future.");
|
14570 | this.svgFactory = new _display_utils.DOMSVGFactory();
|
14571 | this.current = new SVGExtraState();
|
14572 | this.transformMatrix = _util.IDENTITY_MATRIX;
|
14573 | this.transformStack = [];
|
14574 | this.extraStack = [];
|
14575 | this.commonObjs = commonObjs;
|
14576 | this.objs = objs;
|
14577 | this.pendingClip = null;
|
14578 | this.pendingEOFill = false;
|
14579 | this.embedFonts = false;
|
14580 | this.embeddedFonts = Object.create(null);
|
14581 | this.cssStyle = null;
|
14582 | this.forceDataSchema = !!forceDataSchema;
|
14583 | this._operatorIdMapping = [];
|
14584 | for (const op in _util.OPS) {
|
14585 | this._operatorIdMapping[_util.OPS[op]] = op;
|
14586 | }
|
14587 | }
|
14588 | getObject(data, fallback = null) {
|
14589 | if (typeof data === "string") {
|
14590 | return data.startsWith("g_") ? this.commonObjs.get(data) : this.objs.get(data);
|
14591 | }
|
14592 | return fallback;
|
14593 | }
|
14594 | save() {
|
14595 | this.transformStack.push(this.transformMatrix);
|
14596 | const old = this.current;
|
14597 | this.extraStack.push(old);
|
14598 | this.current = old.clone();
|
14599 | }
|
14600 | restore() {
|
14601 | this.transformMatrix = this.transformStack.pop();
|
14602 | this.current = this.extraStack.pop();
|
14603 | this.pendingClip = null;
|
14604 | this.tgrp = null;
|
14605 | }
|
14606 | group(items) {
|
14607 | this.save();
|
14608 | this.executeOpTree(items);
|
14609 | this.restore();
|
14610 | }
|
14611 | loadDependencies(operatorList) {
|
14612 | const fnArray = operatorList.fnArray;
|
14613 | const argsArray = operatorList.argsArray;
|
14614 | for (let i = 0, ii = fnArray.length; i < ii; i++) {
|
14615 | if (fnArray[i] !== _util.OPS.dependency) {
|
14616 | continue;
|
14617 | }
|
14618 | for (const obj of argsArray[i]) {
|
14619 | const objsPool = obj.startsWith("g_") ? this.commonObjs : this.objs;
|
14620 | const promise = new Promise(resolve => {
|
14621 | objsPool.get(obj, resolve);
|
14622 | });
|
14623 | this.current.dependencies.push(promise);
|
14624 | }
|
14625 | }
|
14626 | return Promise.all(this.current.dependencies);
|
14627 | }
|
14628 | transform(a, b, c, d, e, f) {
|
14629 | const transformMatrix = [a, b, c, d, e, f];
|
14630 | this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
|
14631 | this.tgrp = null;
|
14632 | }
|
14633 | getSVG(operatorList, viewport) {
|
14634 | this.viewport = viewport;
|
14635 | const svgElement = this._initialize(viewport);
|
14636 | return this.loadDependencies(operatorList).then(() => {
|
14637 | this.transformMatrix = _util.IDENTITY_MATRIX;
|
14638 | this.executeOpTree(this.convertOpList(operatorList));
|
14639 | return svgElement;
|
14640 | });
|
14641 | }
|
14642 | convertOpList(operatorList) {
|
14643 | const operatorIdMapping = this._operatorIdMapping;
|
14644 | const argsArray = operatorList.argsArray;
|
14645 | const fnArray = operatorList.fnArray;
|
14646 | const opList = [];
|
14647 | for (let i = 0, ii = fnArray.length; i < ii; i++) {
|
14648 | const fnId = fnArray[i];
|
14649 | opList.push({
|
14650 | fnId,
|
14651 | fn: operatorIdMapping[fnId],
|
14652 | args: argsArray[i]
|
14653 | });
|
14654 | }
|
14655 | return opListToTree(opList);
|
14656 | }
|
14657 | executeOpTree(opTree) {
|
14658 | for (const opTreeElement of opTree) {
|
14659 | const fn = opTreeElement.fn;
|
14660 | const fnId = opTreeElement.fnId;
|
14661 | const args = opTreeElement.args;
|
14662 | switch (fnId | 0) {
|
14663 | case _util.OPS.beginText:
|
14664 | this.beginText();
|
14665 | break;
|
14666 | case _util.OPS.dependency:
|
14667 | break;
|
14668 | case _util.OPS.setLeading:
|
14669 | this.setLeading(args);
|
14670 | break;
|
14671 | case _util.OPS.setLeadingMoveText:
|
14672 | this.setLeadingMoveText(args[0], args[1]);
|
14673 | break;
|
14674 | case _util.OPS.setFont:
|
14675 | this.setFont(args);
|
14676 | break;
|
14677 | case _util.OPS.showText:
|
14678 | this.showText(args[0]);
|
14679 | break;
|
14680 | case _util.OPS.showSpacedText:
|
14681 | this.showText(args[0]);
|
14682 | break;
|
14683 | case _util.OPS.endText:
|
14684 | this.endText();
|
14685 | break;
|
14686 | case _util.OPS.moveText:
|
14687 | this.moveText(args[0], args[1]);
|
14688 | break;
|
14689 | case _util.OPS.setCharSpacing:
|
14690 | this.setCharSpacing(args[0]);
|
14691 | break;
|
14692 | case _util.OPS.setWordSpacing:
|
14693 | this.setWordSpacing(args[0]);
|
14694 | break;
|
14695 | case _util.OPS.setHScale:
|
14696 | this.setHScale(args[0]);
|
14697 | break;
|
14698 | case _util.OPS.setTextMatrix:
|
14699 | this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
|
14700 | break;
|
14701 | case _util.OPS.setTextRise:
|
14702 | this.setTextRise(args[0]);
|
14703 | break;
|
14704 | case _util.OPS.setTextRenderingMode:
|
14705 | this.setTextRenderingMode(args[0]);
|
14706 | break;
|
14707 | case _util.OPS.setLineWidth:
|
14708 | this.setLineWidth(args[0]);
|
14709 | break;
|
14710 | case _util.OPS.setLineJoin:
|
14711 | this.setLineJoin(args[0]);
|
14712 | break;
|
14713 | case _util.OPS.setLineCap:
|
14714 | this.setLineCap(args[0]);
|
14715 | break;
|
14716 | case _util.OPS.setMiterLimit:
|
14717 | this.setMiterLimit(args[0]);
|
14718 | break;
|
14719 | case _util.OPS.setFillRGBColor:
|
14720 | this.setFillRGBColor(args[0], args[1], args[2]);
|
14721 | break;
|
14722 | case _util.OPS.setStrokeRGBColor:
|
14723 | this.setStrokeRGBColor(args[0], args[1], args[2]);
|
14724 | break;
|
14725 | case _util.OPS.setStrokeColorN:
|
14726 | this.setStrokeColorN(args);
|
14727 | break;
|
14728 | case _util.OPS.setFillColorN:
|
14729 | this.setFillColorN(args);
|
14730 | break;
|
14731 | case _util.OPS.shadingFill:
|
14732 | this.shadingFill(args[0]);
|
14733 | break;
|
14734 | case _util.OPS.setDash:
|
14735 | this.setDash(args[0], args[1]);
|
14736 | break;
|
14737 | case _util.OPS.setRenderingIntent:
|
14738 | this.setRenderingIntent(args[0]);
|
14739 | break;
|
14740 | case _util.OPS.setFlatness:
|
14741 | this.setFlatness(args[0]);
|
14742 | break;
|
14743 | case _util.OPS.setGState:
|
14744 | this.setGState(args[0]);
|
14745 | break;
|
14746 | case _util.OPS.fill:
|
14747 | this.fill();
|
14748 | break;
|
14749 | case _util.OPS.eoFill:
|
14750 | this.eoFill();
|
14751 | break;
|
14752 | case _util.OPS.stroke:
|
14753 | this.stroke();
|
14754 | break;
|
14755 | case _util.OPS.fillStroke:
|
14756 | this.fillStroke();
|
14757 | break;
|
14758 | case _util.OPS.eoFillStroke:
|
14759 | this.eoFillStroke();
|
14760 | break;
|
14761 | case _util.OPS.clip:
|
14762 | this.clip("nonzero");
|
14763 | break;
|
14764 | case _util.OPS.eoClip:
|
14765 | this.clip("evenodd");
|
14766 | break;
|
14767 | case _util.OPS.paintSolidColorImageMask:
|
14768 | this.paintSolidColorImageMask();
|
14769 | break;
|
14770 | case _util.OPS.paintImageXObject:
|
14771 | this.paintImageXObject(args[0]);
|
14772 | break;
|
14773 | case _util.OPS.paintInlineImageXObject:
|
14774 | this.paintInlineImageXObject(args[0]);
|
14775 | break;
|
14776 | case _util.OPS.paintImageMaskXObject:
|
14777 | this.paintImageMaskXObject(args[0]);
|
14778 | break;
|
14779 | case _util.OPS.paintFormXObjectBegin:
|
14780 | this.paintFormXObjectBegin(args[0], args[1]);
|
14781 | break;
|
14782 | case _util.OPS.paintFormXObjectEnd:
|
14783 | this.paintFormXObjectEnd();
|
14784 | break;
|
14785 | case _util.OPS.closePath:
|
14786 | this.closePath();
|
14787 | break;
|
14788 | case _util.OPS.closeStroke:
|
14789 | this.closeStroke();
|
14790 | break;
|
14791 | case _util.OPS.closeFillStroke:
|
14792 | this.closeFillStroke();
|
14793 | break;
|
14794 | case _util.OPS.closeEOFillStroke:
|
14795 | this.closeEOFillStroke();
|
14796 | break;
|
14797 | case _util.OPS.nextLine:
|
14798 | this.nextLine();
|
14799 | break;
|
14800 | case _util.OPS.transform:
|
14801 | this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
|
14802 | break;
|
14803 | case _util.OPS.constructPath:
|
14804 | this.constructPath(args[0], args[1]);
|
14805 | break;
|
14806 | case _util.OPS.endPath:
|
14807 | this.endPath();
|
14808 | break;
|
14809 | case 92:
|
14810 | this.group(opTreeElement.items);
|
14811 | break;
|
14812 | default:
|
14813 | (0, _util.warn)(`Unimplemented operator ${fn}`);
|
14814 | break;
|
14815 | }
|
14816 | }
|
14817 | }
|
14818 | setWordSpacing(wordSpacing) {
|
14819 | this.current.wordSpacing = wordSpacing;
|
14820 | }
|
14821 | setCharSpacing(charSpacing) {
|
14822 | this.current.charSpacing = charSpacing;
|
14823 | }
|
14824 | nextLine() {
|
14825 | this.moveText(0, this.current.leading);
|
14826 | }
|
14827 | setTextMatrix(a, b, c, d, e, f) {
|
14828 | const current = this.current;
|
14829 | current.textMatrix = current.lineMatrix = [a, b, c, d, e, f];
|
14830 | current.textMatrixScale = Math.hypot(a, b);
|
14831 | current.x = current.lineX = 0;
|
14832 | current.y = current.lineY = 0;
|
14833 | current.xcoords = [];
|
14834 | current.ycoords = [];
|
14835 | current.tspan = this.svgFactory.createElement("svg:tspan");
|
14836 | current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
|
14837 | current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
|
14838 | current.tspan.setAttributeNS(null, "y", pf(-current.y));
|
14839 | current.txtElement = this.svgFactory.createElement("svg:text");
|
14840 | current.txtElement.append(current.tspan);
|
14841 | }
|
14842 | beginText() {
|
14843 | const current = this.current;
|
14844 | current.x = current.lineX = 0;
|
14845 | current.y = current.lineY = 0;
|
14846 | current.textMatrix = _util.IDENTITY_MATRIX;
|
14847 | current.lineMatrix = _util.IDENTITY_MATRIX;
|
14848 | current.textMatrixScale = 1;
|
14849 | current.tspan = this.svgFactory.createElement("svg:tspan");
|
14850 | current.txtElement = this.svgFactory.createElement("svg:text");
|
14851 | current.txtgrp = this.svgFactory.createElement("svg:g");
|
14852 | current.xcoords = [];
|
14853 | current.ycoords = [];
|
14854 | }
|
14855 | moveText(x, y) {
|
14856 | const current = this.current;
|
14857 | current.x = current.lineX += x;
|
14858 | current.y = current.lineY += y;
|
14859 | current.xcoords = [];
|
14860 | current.ycoords = [];
|
14861 | current.tspan = this.svgFactory.createElement("svg:tspan");
|
14862 | current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
|
14863 | current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
|
14864 | current.tspan.setAttributeNS(null, "y", pf(-current.y));
|
14865 | }
|
14866 | showText(glyphs) {
|
14867 | const current = this.current;
|
14868 | const font = current.font;
|
14869 | const fontSize = current.fontSize;
|
14870 | if (fontSize === 0) {
|
14871 | return;
|
14872 | }
|
14873 | const fontSizeScale = current.fontSizeScale;
|
14874 | const charSpacing = current.charSpacing;
|
14875 | const wordSpacing = current.wordSpacing;
|
14876 | const fontDirection = current.fontDirection;
|
14877 | const textHScale = current.textHScale * fontDirection;
|
14878 | const vertical = font.vertical;
|
14879 | const spacingDir = vertical ? 1 : -1;
|
14880 | const defaultVMetrics = font.defaultVMetrics;
|
14881 | const widthAdvanceScale = fontSize * current.fontMatrix[0];
|
14882 | let x = 0;
|
14883 | for (const glyph of glyphs) {
|
14884 | if (glyph === null) {
|
14885 | x += fontDirection * wordSpacing;
|
14886 | continue;
|
14887 | } else if (typeof glyph === "number") {
|
14888 | x += spacingDir * glyph * fontSize / 1000;
|
14889 | continue;
|
14890 | }
|
14891 | const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
|
14892 | const character = glyph.fontChar;
|
14893 | let scaledX, scaledY;
|
14894 | let width = glyph.width;
|
14895 | if (vertical) {
|
14896 | let vx;
|
14897 | const vmetric = glyph.vmetric || defaultVMetrics;
|
14898 | vx = glyph.vmetric ? vmetric[1] : width * 0.5;
|
14899 | vx = -vx * widthAdvanceScale;
|
14900 | const vy = vmetric[2] * widthAdvanceScale;
|
14901 | width = vmetric ? -vmetric[0] : width;
|
14902 | scaledX = vx / fontSizeScale;
|
14903 | scaledY = (x + vy) / fontSizeScale;
|
14904 | } else {
|
14905 | scaledX = x / fontSizeScale;
|
14906 | scaledY = 0;
|
14907 | }
|
14908 | if (glyph.isInFont || font.missingFile) {
|
14909 | current.xcoords.push(current.x + scaledX);
|
14910 | if (vertical) {
|
14911 | current.ycoords.push(-current.y + scaledY);
|
14912 | }
|
14913 | current.tspan.textContent += character;
|
14914 | } else {}
|
14915 | let charWidth;
|
14916 | if (vertical) {
|
14917 | charWidth = width * widthAdvanceScale - spacing * fontDirection;
|
14918 | } else {
|
14919 | charWidth = width * widthAdvanceScale + spacing * fontDirection;
|
14920 | }
|
14921 | x += charWidth;
|
14922 | }
|
14923 | current.tspan.setAttributeNS(null, "x", current.xcoords.map(pf).join(" "));
|
14924 | if (vertical) {
|
14925 | current.tspan.setAttributeNS(null, "y", current.ycoords.map(pf).join(" "));
|
14926 | } else {
|
14927 | current.tspan.setAttributeNS(null, "y", pf(-current.y));
|
14928 | }
|
14929 | if (vertical) {
|
14930 | current.y -= x;
|
14931 | } else {
|
14932 | current.x += x * textHScale;
|
14933 | }
|
14934 | current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
|
14935 | current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
|
14936 | if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
|
14937 | current.tspan.setAttributeNS(null, "font-style", current.fontStyle);
|
14938 | }
|
14939 | if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
|
14940 | current.tspan.setAttributeNS(null, "font-weight", current.fontWeight);
|
14941 | }
|
14942 | const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
|
14943 | if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
14944 | if (current.fillColor !== SVG_DEFAULTS.fillColor) {
|
14945 | current.tspan.setAttributeNS(null, "fill", current.fillColor);
|
14946 | }
|
14947 | if (current.fillAlpha < 1) {
|
14948 | current.tspan.setAttributeNS(null, "fill-opacity", current.fillAlpha);
|
14949 | }
|
14950 | } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
|
14951 | current.tspan.setAttributeNS(null, "fill", "transparent");
|
14952 | } else {
|
14953 | current.tspan.setAttributeNS(null, "fill", "none");
|
14954 | }
|
14955 | if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
|
14956 | const lineWidthScale = 1 / (current.textMatrixScale || 1);
|
14957 | this._setStrokeAttributes(current.tspan, lineWidthScale);
|
14958 | }
|
14959 | let textMatrix = current.textMatrix;
|
14960 | if (current.textRise !== 0) {
|
14961 | textMatrix = textMatrix.slice();
|
14962 | textMatrix[5] += current.textRise;
|
14963 | }
|
14964 | current.txtElement.setAttributeNS(null, "transform", `${pm(textMatrix)} scale(${pf(textHScale)}, -1)`);
|
14965 | current.txtElement.setAttributeNS(XML_NS, "xml:space", "preserve");
|
14966 | current.txtElement.append(current.tspan);
|
14967 | current.txtgrp.append(current.txtElement);
|
14968 | this._ensureTransformGroup().append(current.txtElement);
|
14969 | }
|
14970 | setLeadingMoveText(x, y) {
|
14971 | this.setLeading(-y);
|
14972 | this.moveText(x, y);
|
14973 | }
|
14974 | addFontStyle(fontObj) {
|
14975 | if (!fontObj.data) {
|
14976 | throw new Error("addFontStyle: No font data available, " + 'ensure that the "fontExtraProperties" API parameter is set.');
|
14977 | }
|
14978 | if (!this.cssStyle) {
|
14979 | this.cssStyle = this.svgFactory.createElement("svg:style");
|
14980 | this.cssStyle.setAttributeNS(null, "type", "text/css");
|
14981 | this.defs.append(this.cssStyle);
|
14982 | }
|
14983 | const url = createObjectURL(fontObj.data, fontObj.mimetype, this.forceDataSchema);
|
14984 | this.cssStyle.textContent += `@font-face { font-family: "${fontObj.loadedName}";` + ` src: url(${url}); }\n`;
|
14985 | }
|
14986 | setFont(details) {
|
14987 | const current = this.current;
|
14988 | const fontObj = this.commonObjs.get(details[0]);
|
14989 | let size = details[1];
|
14990 | current.font = fontObj;
|
14991 | if (this.embedFonts && !fontObj.missingFile && !this.embeddedFonts[fontObj.loadedName]) {
|
14992 | this.addFontStyle(fontObj);
|
14993 | this.embeddedFonts[fontObj.loadedName] = fontObj;
|
14994 | }
|
14995 | current.fontMatrix = fontObj.fontMatrix || _util.FONT_IDENTITY_MATRIX;
|
14996 | let bold = "normal";
|
14997 | if (fontObj.black) {
|
14998 | bold = "900";
|
14999 | } else if (fontObj.bold) {
|
15000 | bold = "bold";
|
15001 | }
|
15002 | const italic = fontObj.italic ? "italic" : "normal";
|
15003 | if (size < 0) {
|
15004 | size = -size;
|
15005 | current.fontDirection = -1;
|
15006 | } else {
|
15007 | current.fontDirection = 1;
|
15008 | }
|
15009 | current.fontSize = size;
|
15010 | current.fontFamily = fontObj.loadedName;
|
15011 | current.fontWeight = bold;
|
15012 | current.fontStyle = italic;
|
15013 | current.tspan = this.svgFactory.createElement("svg:tspan");
|
15014 | current.tspan.setAttributeNS(null, "y", pf(-current.y));
|
15015 | current.xcoords = [];
|
15016 | current.ycoords = [];
|
15017 | }
|
15018 | endText() {
|
15019 | const current = this.current;
|
15020 | if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement?.hasChildNodes()) {
|
15021 | current.element = current.txtElement;
|
15022 | this.clip("nonzero");
|
15023 | this.endPath();
|
15024 | }
|
15025 | }
|
15026 | setLineWidth(width) {
|
15027 | if (width > 0) {
|
15028 | this.current.lineWidth = width;
|
15029 | }
|
15030 | }
|
15031 | setLineCap(style) {
|
15032 | this.current.lineCap = LINE_CAP_STYLES[style];
|
15033 | }
|
15034 | setLineJoin(style) {
|
15035 | this.current.lineJoin = LINE_JOIN_STYLES[style];
|
15036 | }
|
15037 | setMiterLimit(limit) {
|
15038 | this.current.miterLimit = limit;
|
15039 | }
|
15040 | setStrokeAlpha(strokeAlpha) {
|
15041 | this.current.strokeAlpha = strokeAlpha;
|
15042 | }
|
15043 | setStrokeRGBColor(r, g, b) {
|
15044 | this.current.strokeColor = _util.Util.makeHexColor(r, g, b);
|
15045 | }
|
15046 | setFillAlpha(fillAlpha) {
|
15047 | this.current.fillAlpha = fillAlpha;
|
15048 | }
|
15049 | setFillRGBColor(r, g, b) {
|
15050 | this.current.fillColor = _util.Util.makeHexColor(r, g, b);
|
15051 | this.current.tspan = this.svgFactory.createElement("svg:tspan");
|
15052 | this.current.xcoords = [];
|
15053 | this.current.ycoords = [];
|
15054 | }
|
15055 | setStrokeColorN(args) {
|
15056 | this.current.strokeColor = this._makeColorN_Pattern(args);
|
15057 | }
|
15058 | setFillColorN(args) {
|
15059 | this.current.fillColor = this._makeColorN_Pattern(args);
|
15060 | }
|
15061 | shadingFill(args) {
|
15062 | const width = this.viewport.width;
|
15063 | const height = this.viewport.height;
|
15064 | const inv = _util.Util.inverseTransform(this.transformMatrix);
|
15065 | const bl = _util.Util.applyTransform([0, 0], inv);
|
15066 | const br = _util.Util.applyTransform([0, height], inv);
|
15067 | const ul = _util.Util.applyTransform([width, 0], inv);
|
15068 | const ur = _util.Util.applyTransform([width, height], inv);
|
15069 | const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
|
15070 | const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
|
15071 | const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
|
15072 | const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
|
15073 | const rect = this.svgFactory.createElement("svg:rect");
|
15074 | rect.setAttributeNS(null, "x", x0);
|
15075 | rect.setAttributeNS(null, "y", y0);
|
15076 | rect.setAttributeNS(null, "width", x1 - x0);
|
15077 | rect.setAttributeNS(null, "height", y1 - y0);
|
15078 | rect.setAttributeNS(null, "fill", this._makeShadingPattern(args));
|
15079 | if (this.current.fillAlpha < 1) {
|
15080 | rect.setAttributeNS(null, "fill-opacity", this.current.fillAlpha);
|
15081 | }
|
15082 | this._ensureTransformGroup().append(rect);
|
15083 | }
|
15084 | _makeColorN_Pattern(args) {
|
15085 | if (args[0] === "TilingPattern") {
|
15086 | return this._makeTilingPattern(args);
|
15087 | }
|
15088 | return this._makeShadingPattern(args);
|
15089 | }
|
15090 | _makeTilingPattern(args) {
|
15091 | const color = args[1];
|
15092 | const operatorList = args[2];
|
15093 | const matrix = args[3] || _util.IDENTITY_MATRIX;
|
15094 | const [x0, y0, x1, y1] = args[4];
|
15095 | const xstep = args[5];
|
15096 | const ystep = args[6];
|
15097 | const paintType = args[7];
|
15098 | const tilingId = `shading${shadingCount++}`;
|
15099 | const [tx0, ty0, tx1, ty1] = _util.Util.normalizeRect([..._util.Util.applyTransform([x0, y0], matrix), ..._util.Util.applyTransform([x1, y1], matrix)]);
|
15100 | const [xscale, yscale] = _util.Util.singularValueDecompose2dScale(matrix);
|
15101 | const txstep = xstep * xscale;
|
15102 | const tystep = ystep * yscale;
|
15103 | const tiling = this.svgFactory.createElement("svg:pattern");
|
15104 | tiling.setAttributeNS(null, "id", tilingId);
|
15105 | tiling.setAttributeNS(null, "patternUnits", "userSpaceOnUse");
|
15106 | tiling.setAttributeNS(null, "width", txstep);
|
15107 | tiling.setAttributeNS(null, "height", tystep);
|
15108 | tiling.setAttributeNS(null, "x", `${tx0}`);
|
15109 | tiling.setAttributeNS(null, "y", `${ty0}`);
|
15110 | const svg = this.svg;
|
15111 | const transformMatrix = this.transformMatrix;
|
15112 | const fillColor = this.current.fillColor;
|
15113 | const strokeColor = this.current.strokeColor;
|
15114 | const bbox = this.svgFactory.create(tx1 - tx0, ty1 - ty0);
|
15115 | this.svg = bbox;
|
15116 | this.transformMatrix = matrix;
|
15117 | if (paintType === 2) {
|
15118 | const cssColor = _util.Util.makeHexColor(...color);
|
15119 | this.current.fillColor = cssColor;
|
15120 | this.current.strokeColor = cssColor;
|
15121 | }
|
15122 | this.executeOpTree(this.convertOpList(operatorList));
|
15123 | this.svg = svg;
|
15124 | this.transformMatrix = transformMatrix;
|
15125 | this.current.fillColor = fillColor;
|
15126 | this.current.strokeColor = strokeColor;
|
15127 | tiling.append(bbox.childNodes[0]);
|
15128 | this.defs.append(tiling);
|
15129 | return `url(#${tilingId})`;
|
15130 | }
|
15131 | _makeShadingPattern(args) {
|
15132 | if (typeof args === "string") {
|
15133 | args = this.objs.get(args);
|
15134 | }
|
15135 | switch (args[0]) {
|
15136 | case "RadialAxial":
|
15137 | const shadingId = `shading${shadingCount++}`;
|
15138 | const colorStops = args[3];
|
15139 | let gradient;
|
15140 | switch (args[1]) {
|
15141 | case "axial":
|
15142 | const point0 = args[4];
|
15143 | const point1 = args[5];
|
15144 | gradient = this.svgFactory.createElement("svg:linearGradient");
|
15145 | gradient.setAttributeNS(null, "id", shadingId);
|
15146 | gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
|
15147 | gradient.setAttributeNS(null, "x1", point0[0]);
|
15148 | gradient.setAttributeNS(null, "y1", point0[1]);
|
15149 | gradient.setAttributeNS(null, "x2", point1[0]);
|
15150 | gradient.setAttributeNS(null, "y2", point1[1]);
|
15151 | break;
|
15152 | case "radial":
|
15153 | const focalPoint = args[4];
|
15154 | const circlePoint = args[5];
|
15155 | const focalRadius = args[6];
|
15156 | const circleRadius = args[7];
|
15157 | gradient = this.svgFactory.createElement("svg:radialGradient");
|
15158 | gradient.setAttributeNS(null, "id", shadingId);
|
15159 | gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
|
15160 | gradient.setAttributeNS(null, "cx", circlePoint[0]);
|
15161 | gradient.setAttributeNS(null, "cy", circlePoint[1]);
|
15162 | gradient.setAttributeNS(null, "r", circleRadius);
|
15163 | gradient.setAttributeNS(null, "fx", focalPoint[0]);
|
15164 | gradient.setAttributeNS(null, "fy", focalPoint[1]);
|
15165 | gradient.setAttributeNS(null, "fr", focalRadius);
|
15166 | break;
|
15167 | default:
|
15168 | throw new Error(`Unknown RadialAxial type: ${args[1]}`);
|
15169 | }
|
15170 | for (const colorStop of colorStops) {
|
15171 | const stop = this.svgFactory.createElement("svg:stop");
|
15172 | stop.setAttributeNS(null, "offset", colorStop[0]);
|
15173 | stop.setAttributeNS(null, "stop-color", colorStop[1]);
|
15174 | gradient.append(stop);
|
15175 | }
|
15176 | this.defs.append(gradient);
|
15177 | return `url(#${shadingId})`;
|
15178 | case "Mesh":
|
15179 | (0, _util.warn)("Unimplemented pattern Mesh");
|
15180 | return null;
|
15181 | case "Dummy":
|
15182 | return "hotpink";
|
15183 | default:
|
15184 | throw new Error(`Unknown IR type: ${args[0]}`);
|
15185 | }
|
15186 | }
|
15187 | setDash(dashArray, dashPhase) {
|
15188 | this.current.dashArray = dashArray;
|
15189 | this.current.dashPhase = dashPhase;
|
15190 | }
|
15191 | constructPath(ops, args) {
|
15192 | const current = this.current;
|
15193 | let x = current.x,
|
15194 | y = current.y;
|
15195 | let d = [];
|
15196 | let j = 0;
|
15197 | for (const op of ops) {
|
15198 | switch (op | 0) {
|
15199 | case _util.OPS.rectangle:
|
15200 | x = args[j++];
|
15201 | y = args[j++];
|
15202 | const width = args[j++];
|
15203 | const height = args[j++];
|
15204 | const xw = x + width;
|
15205 | const yh = y + height;
|
15206 | d.push("M", pf(x), pf(y), "L", pf(xw), pf(y), "L", pf(xw), pf(yh), "L", pf(x), pf(yh), "Z");
|
15207 | break;
|
15208 | case _util.OPS.moveTo:
|
15209 | x = args[j++];
|
15210 | y = args[j++];
|
15211 | d.push("M", pf(x), pf(y));
|
15212 | break;
|
15213 | case _util.OPS.lineTo:
|
15214 | x = args[j++];
|
15215 | y = args[j++];
|
15216 | d.push("L", pf(x), pf(y));
|
15217 | break;
|
15218 | case _util.OPS.curveTo:
|
15219 | x = args[j + 4];
|
15220 | y = args[j + 5];
|
15221 | d.push("C", pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
|
15222 | j += 6;
|
15223 | break;
|
15224 | case _util.OPS.curveTo2:
|
15225 | d.push("C", pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
|
15226 | x = args[j + 2];
|
15227 | y = args[j + 3];
|
15228 | j += 4;
|
15229 | break;
|
15230 | case _util.OPS.curveTo3:
|
15231 | x = args[j + 2];
|
15232 | y = args[j + 3];
|
15233 | d.push("C", pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
|
15234 | j += 4;
|
15235 | break;
|
15236 | case _util.OPS.closePath:
|
15237 | d.push("Z");
|
15238 | break;
|
15239 | }
|
15240 | }
|
15241 | d = d.join(" ");
|
15242 | if (current.path && ops.length > 0 && ops[0] !== _util.OPS.rectangle && ops[0] !== _util.OPS.moveTo) {
|
15243 | d = current.path.getAttributeNS(null, "d") + d;
|
15244 | } else {
|
15245 | current.path = this.svgFactory.createElement("svg:path");
|
15246 | this._ensureTransformGroup().append(current.path);
|
15247 | }
|
15248 | current.path.setAttributeNS(null, "d", d);
|
15249 | current.path.setAttributeNS(null, "fill", "none");
|
15250 | current.element = current.path;
|
15251 | current.setCurrentPoint(x, y);
|
15252 | }
|
15253 | endPath() {
|
15254 | const current = this.current;
|
15255 | current.path = null;
|
15256 | if (!this.pendingClip) {
|
15257 | return;
|
15258 | }
|
15259 | if (!current.element) {
|
15260 | this.pendingClip = null;
|
15261 | return;
|
15262 | }
|
15263 | const clipId = `clippath${clipCount++}`;
|
15264 | const clipPath = this.svgFactory.createElement("svg:clipPath");
|
15265 | clipPath.setAttributeNS(null, "id", clipId);
|
15266 | clipPath.setAttributeNS(null, "transform", pm(this.transformMatrix));
|
15267 | const clipElement = current.element.cloneNode(true);
|
15268 | if (this.pendingClip === "evenodd") {
|
15269 | clipElement.setAttributeNS(null, "clip-rule", "evenodd");
|
15270 | } else {
|
15271 | clipElement.setAttributeNS(null, "clip-rule", "nonzero");
|
15272 | }
|
15273 | this.pendingClip = null;
|
15274 | clipPath.append(clipElement);
|
15275 | this.defs.append(clipPath);
|
15276 | if (current.activeClipUrl) {
|
15277 | current.clipGroup = null;
|
15278 | for (const prev of this.extraStack) {
|
15279 | prev.clipGroup = null;
|
15280 | }
|
15281 | clipPath.setAttributeNS(null, "clip-path", current.activeClipUrl);
|
15282 | }
|
15283 | current.activeClipUrl = `url(#${clipId})`;
|
15284 | this.tgrp = null;
|
15285 | }
|
15286 | clip(type) {
|
15287 | this.pendingClip = type;
|
15288 | }
|
15289 | closePath() {
|
15290 | const current = this.current;
|
15291 | if (current.path) {
|
15292 | const d = `${current.path.getAttributeNS(null, "d")}Z`;
|
15293 | current.path.setAttributeNS(null, "d", d);
|
15294 | }
|
15295 | }
|
15296 | setLeading(leading) {
|
15297 | this.current.leading = -leading;
|
15298 | }
|
15299 | setTextRise(textRise) {
|
15300 | this.current.textRise = textRise;
|
15301 | }
|
15302 | setTextRenderingMode(textRenderingMode) {
|
15303 | this.current.textRenderingMode = textRenderingMode;
|
15304 | }
|
15305 | setHScale(scale) {
|
15306 | this.current.textHScale = scale / 100;
|
15307 | }
|
15308 | setRenderingIntent(intent) {}
|
15309 | setFlatness(flatness) {}
|
15310 | setGState(states) {
|
15311 | for (const [key, value] of states) {
|
15312 | switch (key) {
|
15313 | case "LW":
|
15314 | this.setLineWidth(value);
|
15315 | break;
|
15316 | case "LC":
|
15317 | this.setLineCap(value);
|
15318 | break;
|
15319 | case "LJ":
|
15320 | this.setLineJoin(value);
|
15321 | break;
|
15322 | case "ML":
|
15323 | this.setMiterLimit(value);
|
15324 | break;
|
15325 | case "D":
|
15326 | this.setDash(value[0], value[1]);
|
15327 | break;
|
15328 | case "RI":
|
15329 | this.setRenderingIntent(value);
|
15330 | break;
|
15331 | case "FL":
|
15332 | this.setFlatness(value);
|
15333 | break;
|
15334 | case "Font":
|
15335 | this.setFont(value);
|
15336 | break;
|
15337 | case "CA":
|
15338 | this.setStrokeAlpha(value);
|
15339 | break;
|
15340 | case "ca":
|
15341 | this.setFillAlpha(value);
|
15342 | break;
|
15343 | default:
|
15344 | (0, _util.warn)(`Unimplemented graphic state operator ${key}`);
|
15345 | break;
|
15346 | }
|
15347 | }
|
15348 | }
|
15349 | fill() {
|
15350 | const current = this.current;
|
15351 | if (current.element) {
|
15352 | current.element.setAttributeNS(null, "fill", current.fillColor);
|
15353 | current.element.setAttributeNS(null, "fill-opacity", current.fillAlpha);
|
15354 | this.endPath();
|
15355 | }
|
15356 | }
|
15357 | stroke() {
|
15358 | const current = this.current;
|
15359 | if (current.element) {
|
15360 | this._setStrokeAttributes(current.element);
|
15361 | current.element.setAttributeNS(null, "fill", "none");
|
15362 | this.endPath();
|
15363 | }
|
15364 | }
|
15365 | _setStrokeAttributes(element, lineWidthScale = 1) {
|
15366 | const current = this.current;
|
15367 | let dashArray = current.dashArray;
|
15368 | if (lineWidthScale !== 1 && dashArray.length > 0) {
|
15369 | dashArray = dashArray.map(function (value) {
|
15370 | return lineWidthScale * value;
|
15371 | });
|
15372 | }
|
15373 | element.setAttributeNS(null, "stroke", current.strokeColor);
|
15374 | element.setAttributeNS(null, "stroke-opacity", current.strokeAlpha);
|
15375 | element.setAttributeNS(null, "stroke-miterlimit", pf(current.miterLimit));
|
15376 | element.setAttributeNS(null, "stroke-linecap", current.lineCap);
|
15377 | element.setAttributeNS(null, "stroke-linejoin", current.lineJoin);
|
15378 | element.setAttributeNS(null, "stroke-width", pf(lineWidthScale * current.lineWidth) + "px");
|
15379 | element.setAttributeNS(null, "stroke-dasharray", dashArray.map(pf).join(" "));
|
15380 | element.setAttributeNS(null, "stroke-dashoffset", pf(lineWidthScale * current.dashPhase) + "px");
|
15381 | }
|
15382 | eoFill() {
|
15383 | this.current.element?.setAttributeNS(null, "fill-rule", "evenodd");
|
15384 | this.fill();
|
15385 | }
|
15386 | fillStroke() {
|
15387 | this.stroke();
|
15388 | this.fill();
|
15389 | }
|
15390 | eoFillStroke() {
|
15391 | this.current.element?.setAttributeNS(null, "fill-rule", "evenodd");
|
15392 | this.fillStroke();
|
15393 | }
|
15394 | closeStroke() {
|
15395 | this.closePath();
|
15396 | this.stroke();
|
15397 | }
|
15398 | closeFillStroke() {
|
15399 | this.closePath();
|
15400 | this.fillStroke();
|
15401 | }
|
15402 | closeEOFillStroke() {
|
15403 | this.closePath();
|
15404 | this.eoFillStroke();
|
15405 | }
|
15406 | paintSolidColorImageMask() {
|
15407 | const rect = this.svgFactory.createElement("svg:rect");
|
15408 | rect.setAttributeNS(null, "x", "0");
|
15409 | rect.setAttributeNS(null, "y", "0");
|
15410 | rect.setAttributeNS(null, "width", "1px");
|
15411 | rect.setAttributeNS(null, "height", "1px");
|
15412 | rect.setAttributeNS(null, "fill", this.current.fillColor);
|
15413 | this._ensureTransformGroup().append(rect);
|
15414 | }
|
15415 | paintImageXObject(objId) {
|
15416 | const imgData = this.getObject(objId);
|
15417 | if (!imgData) {
|
15418 | (0, _util.warn)(`Dependent image with object ID ${objId} is not ready yet`);
|
15419 | return;
|
15420 | }
|
15421 | this.paintInlineImageXObject(imgData);
|
15422 | }
|
15423 | paintInlineImageXObject(imgData, mask) {
|
15424 | const width = imgData.width;
|
15425 | const height = imgData.height;
|
15426 | const imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
|
15427 | const cliprect = this.svgFactory.createElement("svg:rect");
|
15428 | cliprect.setAttributeNS(null, "x", "0");
|
15429 | cliprect.setAttributeNS(null, "y", "0");
|
15430 | cliprect.setAttributeNS(null, "width", pf(width));
|
15431 | cliprect.setAttributeNS(null, "height", pf(height));
|
15432 | this.current.element = cliprect;
|
15433 | this.clip("nonzero");
|
15434 | const imgEl = this.svgFactory.createElement("svg:image");
|
15435 | imgEl.setAttributeNS(XLINK_NS, "xlink:href", imgSrc);
|
15436 | imgEl.setAttributeNS(null, "x", "0");
|
15437 | imgEl.setAttributeNS(null, "y", pf(-height));
|
15438 | imgEl.setAttributeNS(null, "width", pf(width) + "px");
|
15439 | imgEl.setAttributeNS(null, "height", pf(height) + "px");
|
15440 | imgEl.setAttributeNS(null, "transform", `scale(${pf(1 / width)} ${pf(-1 / height)})`);
|
15441 | if (mask) {
|
15442 | mask.append(imgEl);
|
15443 | } else {
|
15444 | this._ensureTransformGroup().append(imgEl);
|
15445 | }
|
15446 | }
|
15447 | paintImageMaskXObject(img) {
|
15448 | const imgData = this.getObject(img.data, img);
|
15449 | if (imgData.bitmap) {
|
15450 | (0, _util.warn)("paintImageMaskXObject: ImageBitmap support is not implemented, " + "ensure that the `isOffscreenCanvasSupported` API parameter is disabled.");
|
15451 | return;
|
15452 | }
|
15453 | const current = this.current;
|
15454 | const width = imgData.width;
|
15455 | const height = imgData.height;
|
15456 | const fillColor = current.fillColor;
|
15457 | current.maskId = `mask${maskCount++}`;
|
15458 | const mask = this.svgFactory.createElement("svg:mask");
|
15459 | mask.setAttributeNS(null, "id", current.maskId);
|
15460 | const rect = this.svgFactory.createElement("svg:rect");
|
15461 | rect.setAttributeNS(null, "x", "0");
|
15462 | rect.setAttributeNS(null, "y", "0");
|
15463 | rect.setAttributeNS(null, "width", pf(width));
|
15464 | rect.setAttributeNS(null, "height", pf(height));
|
15465 | rect.setAttributeNS(null, "fill", fillColor);
|
15466 | rect.setAttributeNS(null, "mask", `url(#${current.maskId})`);
|
15467 | this.defs.append(mask);
|
15468 | this._ensureTransformGroup().append(rect);
|
15469 | this.paintInlineImageXObject(imgData, mask);
|
15470 | }
|
15471 | paintFormXObjectBegin(matrix, bbox) {
|
15472 | if (Array.isArray(matrix) && matrix.length === 6) {
|
15473 | this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
|
15474 | }
|
15475 | if (bbox) {
|
15476 | const width = bbox[2] - bbox[0];
|
15477 | const height = bbox[3] - bbox[1];
|
15478 | const cliprect = this.svgFactory.createElement("svg:rect");
|
15479 | cliprect.setAttributeNS(null, "x", bbox[0]);
|
15480 | cliprect.setAttributeNS(null, "y", bbox[1]);
|
15481 | cliprect.setAttributeNS(null, "width", pf(width));
|
15482 | cliprect.setAttributeNS(null, "height", pf(height));
|
15483 | this.current.element = cliprect;
|
15484 | this.clip("nonzero");
|
15485 | this.endPath();
|
15486 | }
|
15487 | }
|
15488 | paintFormXObjectEnd() {}
|
15489 | _initialize(viewport) {
|
15490 | const svg = this.svgFactory.create(viewport.width, viewport.height);
|
15491 | const definitions = this.svgFactory.createElement("svg:defs");
|
15492 | svg.append(definitions);
|
15493 | this.defs = definitions;
|
15494 | const rootGroup = this.svgFactory.createElement("svg:g");
|
15495 | rootGroup.setAttributeNS(null, "transform", pm(viewport.transform));
|
15496 | svg.append(rootGroup);
|
15497 | this.svg = rootGroup;
|
15498 | return svg;
|
15499 | }
|
15500 | _ensureClipGroup() {
|
15501 | if (!this.current.clipGroup) {
|
15502 | const clipGroup = this.svgFactory.createElement("svg:g");
|
15503 | clipGroup.setAttributeNS(null, "clip-path", this.current.activeClipUrl);
|
15504 | this.svg.append(clipGroup);
|
15505 | this.current.clipGroup = clipGroup;
|
15506 | }
|
15507 | return this.current.clipGroup;
|
15508 | }
|
15509 | _ensureTransformGroup() {
|
15510 | if (!this.tgrp) {
|
15511 | this.tgrp = this.svgFactory.createElement("svg:g");
|
15512 | this.tgrp.setAttributeNS(null, "transform", pm(this.transformMatrix));
|
15513 | if (this.current.activeClipUrl) {
|
15514 | this._ensureClipGroup().append(this.tgrp);
|
15515 | } else {
|
15516 | this.svg.append(this.tgrp);
|
15517 | }
|
15518 | }
|
15519 | return this.tgrp;
|
15520 | }
|
15521 | };
|
15522 | }
|
15523 |
|
15524 | })
|
15525 | ]);
|
15526 |
|
15527 |
|
15528 | var __webpack_module_cache__ = {};
|
15529 |
|
15530 |
|
15531 | function __w_pdfjs_require__(moduleId) {
|
15532 |
|
15533 | var cachedModule = __webpack_module_cache__[moduleId];
|
15534 | if (cachedModule !== undefined) {
|
15535 | return cachedModule.exports;
|
15536 | }
|
15537 |
|
15538 | var module = __webpack_module_cache__[moduleId] = {
|
15539 |
|
15540 |
|
15541 | exports: {}
|
15542 | };
|
15543 |
|
15544 |
|
15545 | __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
|
15546 |
|
15547 |
|
15548 | return module.exports;
|
15549 | }
|
15550 |
|
15551 |
|
15552 | var __webpack_exports__ = {};
|
15553 |
|
15554 | (() => {
|
15555 | var exports = __webpack_exports__;
|
15556 |
|
15557 |
|
15558 | Object.defineProperty(exports, "__esModule", ({
|
15559 | value: true
|
15560 | }));
|
15561 | Object.defineProperty(exports, "AbortException", ({
|
15562 | enumerable: true,
|
15563 | get: function () {
|
15564 | return _util.AbortException;
|
15565 | }
|
15566 | }));
|
15567 | Object.defineProperty(exports, "AnnotationEditorLayer", ({
|
15568 | enumerable: true,
|
15569 | get: function () {
|
15570 | return _annotation_editor_layer.AnnotationEditorLayer;
|
15571 | }
|
15572 | }));
|
15573 | Object.defineProperty(exports, "AnnotationEditorParamsType", ({
|
15574 | enumerable: true,
|
15575 | get: function () {
|
15576 | return _util.AnnotationEditorParamsType;
|
15577 | }
|
15578 | }));
|
15579 | Object.defineProperty(exports, "AnnotationEditorType", ({
|
15580 | enumerable: true,
|
15581 | get: function () {
|
15582 | return _util.AnnotationEditorType;
|
15583 | }
|
15584 | }));
|
15585 | Object.defineProperty(exports, "AnnotationEditorUIManager", ({
|
15586 | enumerable: true,
|
15587 | get: function () {
|
15588 | return _tools.AnnotationEditorUIManager;
|
15589 | }
|
15590 | }));
|
15591 | Object.defineProperty(exports, "AnnotationLayer", ({
|
15592 | enumerable: true,
|
15593 | get: function () {
|
15594 | return _annotation_layer.AnnotationLayer;
|
15595 | }
|
15596 | }));
|
15597 | Object.defineProperty(exports, "AnnotationMode", ({
|
15598 | enumerable: true,
|
15599 | get: function () {
|
15600 | return _util.AnnotationMode;
|
15601 | }
|
15602 | }));
|
15603 | Object.defineProperty(exports, "CMapCompressionType", ({
|
15604 | enumerable: true,
|
15605 | get: function () {
|
15606 | return _util.CMapCompressionType;
|
15607 | }
|
15608 | }));
|
15609 | Object.defineProperty(exports, "FeatureTest", ({
|
15610 | enumerable: true,
|
15611 | get: function () {
|
15612 | return _util.FeatureTest;
|
15613 | }
|
15614 | }));
|
15615 | Object.defineProperty(exports, "GlobalWorkerOptions", ({
|
15616 | enumerable: true,
|
15617 | get: function () {
|
15618 | return _worker_options.GlobalWorkerOptions;
|
15619 | }
|
15620 | }));
|
15621 | Object.defineProperty(exports, "InvalidPDFException", ({
|
15622 | enumerable: true,
|
15623 | get: function () {
|
15624 | return _util.InvalidPDFException;
|
15625 | }
|
15626 | }));
|
15627 | Object.defineProperty(exports, "MissingPDFException", ({
|
15628 | enumerable: true,
|
15629 | get: function () {
|
15630 | return _util.MissingPDFException;
|
15631 | }
|
15632 | }));
|
15633 | Object.defineProperty(exports, "OPS", ({
|
15634 | enumerable: true,
|
15635 | get: function () {
|
15636 | return _util.OPS;
|
15637 | }
|
15638 | }));
|
15639 | Object.defineProperty(exports, "PDFDataRangeTransport", ({
|
15640 | enumerable: true,
|
15641 | get: function () {
|
15642 | return _api.PDFDataRangeTransport;
|
15643 | }
|
15644 | }));
|
15645 | Object.defineProperty(exports, "PDFDateString", ({
|
15646 | enumerable: true,
|
15647 | get: function () {
|
15648 | return _display_utils.PDFDateString;
|
15649 | }
|
15650 | }));
|
15651 | Object.defineProperty(exports, "PDFWorker", ({
|
15652 | enumerable: true,
|
15653 | get: function () {
|
15654 | return _api.PDFWorker;
|
15655 | }
|
15656 | }));
|
15657 | Object.defineProperty(exports, "PasswordResponses", ({
|
15658 | enumerable: true,
|
15659 | get: function () {
|
15660 | return _util.PasswordResponses;
|
15661 | }
|
15662 | }));
|
15663 | Object.defineProperty(exports, "PermissionFlag", ({
|
15664 | enumerable: true,
|
15665 | get: function () {
|
15666 | return _util.PermissionFlag;
|
15667 | }
|
15668 | }));
|
15669 | Object.defineProperty(exports, "PixelsPerInch", ({
|
15670 | enumerable: true,
|
15671 | get: function () {
|
15672 | return _display_utils.PixelsPerInch;
|
15673 | }
|
15674 | }));
|
15675 | Object.defineProperty(exports, "PromiseCapability", ({
|
15676 | enumerable: true,
|
15677 | get: function () {
|
15678 | return _util.PromiseCapability;
|
15679 | }
|
15680 | }));
|
15681 | Object.defineProperty(exports, "RenderingCancelledException", ({
|
15682 | enumerable: true,
|
15683 | get: function () {
|
15684 | return _display_utils.RenderingCancelledException;
|
15685 | }
|
15686 | }));
|
15687 | Object.defineProperty(exports, "SVGGraphics", ({
|
15688 | enumerable: true,
|
15689 | get: function () {
|
15690 | return _svg.SVGGraphics;
|
15691 | }
|
15692 | }));
|
15693 | Object.defineProperty(exports, "UnexpectedResponseException", ({
|
15694 | enumerable: true,
|
15695 | get: function () {
|
15696 | return _util.UnexpectedResponseException;
|
15697 | }
|
15698 | }));
|
15699 | Object.defineProperty(exports, "Util", ({
|
15700 | enumerable: true,
|
15701 | get: function () {
|
15702 | return _util.Util;
|
15703 | }
|
15704 | }));
|
15705 | Object.defineProperty(exports, "VerbosityLevel", ({
|
15706 | enumerable: true,
|
15707 | get: function () {
|
15708 | return _util.VerbosityLevel;
|
15709 | }
|
15710 | }));
|
15711 | Object.defineProperty(exports, "XfaLayer", ({
|
15712 | enumerable: true,
|
15713 | get: function () {
|
15714 | return _xfa_layer.XfaLayer;
|
15715 | }
|
15716 | }));
|
15717 | Object.defineProperty(exports, "build", ({
|
15718 | enumerable: true,
|
15719 | get: function () {
|
15720 | return _api.build;
|
15721 | }
|
15722 | }));
|
15723 | Object.defineProperty(exports, "createValidAbsoluteUrl", ({
|
15724 | enumerable: true,
|
15725 | get: function () {
|
15726 | return _util.createValidAbsoluteUrl;
|
15727 | }
|
15728 | }));
|
15729 | Object.defineProperty(exports, "getDocument", ({
|
15730 | enumerable: true,
|
15731 | get: function () {
|
15732 | return _api.getDocument;
|
15733 | }
|
15734 | }));
|
15735 | Object.defineProperty(exports, "getFilenameFromUrl", ({
|
15736 | enumerable: true,
|
15737 | get: function () {
|
15738 | return _display_utils.getFilenameFromUrl;
|
15739 | }
|
15740 | }));
|
15741 | Object.defineProperty(exports, "getPdfFilenameFromUrl", ({
|
15742 | enumerable: true,
|
15743 | get: function () {
|
15744 | return _display_utils.getPdfFilenameFromUrl;
|
15745 | }
|
15746 | }));
|
15747 | Object.defineProperty(exports, "getXfaPageViewport", ({
|
15748 | enumerable: true,
|
15749 | get: function () {
|
15750 | return _display_utils.getXfaPageViewport;
|
15751 | }
|
15752 | }));
|
15753 | Object.defineProperty(exports, "isDataScheme", ({
|
15754 | enumerable: true,
|
15755 | get: function () {
|
15756 | return _display_utils.isDataScheme;
|
15757 | }
|
15758 | }));
|
15759 | Object.defineProperty(exports, "isPdfFile", ({
|
15760 | enumerable: true,
|
15761 | get: function () {
|
15762 | return _display_utils.isPdfFile;
|
15763 | }
|
15764 | }));
|
15765 | Object.defineProperty(exports, "loadScript", ({
|
15766 | enumerable: true,
|
15767 | get: function () {
|
15768 | return _display_utils.loadScript;
|
15769 | }
|
15770 | }));
|
15771 | Object.defineProperty(exports, "normalizeUnicode", ({
|
15772 | enumerable: true,
|
15773 | get: function () {
|
15774 | return _util.normalizeUnicode;
|
15775 | }
|
15776 | }));
|
15777 | Object.defineProperty(exports, "renderTextLayer", ({
|
15778 | enumerable: true,
|
15779 | get: function () {
|
15780 | return _text_layer.renderTextLayer;
|
15781 | }
|
15782 | }));
|
15783 | Object.defineProperty(exports, "setLayerDimensions", ({
|
15784 | enumerable: true,
|
15785 | get: function () {
|
15786 | return _display_utils.setLayerDimensions;
|
15787 | }
|
15788 | }));
|
15789 | Object.defineProperty(exports, "shadow", ({
|
15790 | enumerable: true,
|
15791 | get: function () {
|
15792 | return _util.shadow;
|
15793 | }
|
15794 | }));
|
15795 | Object.defineProperty(exports, "updateTextLayer", ({
|
15796 | enumerable: true,
|
15797 | get: function () {
|
15798 | return _text_layer.updateTextLayer;
|
15799 | }
|
15800 | }));
|
15801 | Object.defineProperty(exports, "version", ({
|
15802 | enumerable: true,
|
15803 | get: function () {
|
15804 | return _api.version;
|
15805 | }
|
15806 | }));
|
15807 | var _util = __w_pdfjs_require__(1);
|
15808 | var _api = __w_pdfjs_require__(2);
|
15809 | var _display_utils = __w_pdfjs_require__(6);
|
15810 | var _text_layer = __w_pdfjs_require__(26);
|
15811 | var _annotation_editor_layer = __w_pdfjs_require__(27);
|
15812 | var _tools = __w_pdfjs_require__(5);
|
15813 | var _annotation_layer = __w_pdfjs_require__(30);
|
15814 | var _worker_options = __w_pdfjs_require__(14);
|
15815 | var _svg = __w_pdfjs_require__(33);
|
15816 | var _xfa_layer = __w_pdfjs_require__(32);
|
15817 | const pdfjsVersion = '3.7.107';
|
15818 | const pdfjsBuild = '036f855dc';
|
15819 | })();
|
15820 |
|
15821 | return __webpack_exports__;
|
15822 | })()
|
15823 | ;
|
15824 | });
|
15825 |
|
\ | No newline at end of file |