nuvra 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2348 @@
1
+ import { i as e, n as t } from "./page-DY5fdgcT.js";
2
+ import { t as n } from "./errors-tHVeiwWt.js";
3
+ //#region src/core/pdf-import/encodings.ts
4
+ var r = (e) => {
5
+ let t;
6
+ try {
7
+ t = new TextDecoder(e);
8
+ } catch {
9
+ t = void 0;
10
+ }
11
+ return Array.from({ length: 256 }, (e, n) => n < 32 ? "" : t ? t.decode(Uint8Array.of(n)) : String.fromCharCode(n));
12
+ }, i = r("windows-1252"), a = r("macintosh"), o = (() => {
13
+ let e = Array.from({ length: 256 }, (e, t) => t >= 32 && t < 127 ? String.fromCharCode(t) : "");
14
+ e[39] = "’", e[96] = "‘";
15
+ for (let t = 0; t < 48; t += 1) {
16
+ let n = "¡¢£⁄¥ƒ§¤'“«‹›fifl\0–†‡·\0¶•‚„”»…‰\0¿\0`´ˆ˜¯˘˙¨\0˚¸\0˝˛ˇ—"[t];
17
+ n !== "\0" && (e[161 + t] = n);
18
+ }
19
+ for (let [t, n] of Object.entries({
20
+ 225: "Æ",
21
+ 227: "ª",
22
+ 232: "Ł",
23
+ 233: "Ø",
24
+ 234: "Œ",
25
+ 235: "º",
26
+ 241: "æ",
27
+ 245: "ı",
28
+ 248: "ł",
29
+ 249: "ø",
30
+ 250: "œ",
31
+ 251: "ß"
32
+ })) e[Number(t)] = n;
33
+ return e;
34
+ })(), s = {
35
+ space: " ",
36
+ nbspace: "\xA0",
37
+ nonbreakingspace: "\xA0",
38
+ exclam: "!",
39
+ quotedbl: "\"",
40
+ numbersign: "#",
41
+ dollar: "$",
42
+ percent: "%",
43
+ ampersand: "&",
44
+ quotesingle: "'",
45
+ parenleft: "(",
46
+ parenright: ")",
47
+ asterisk: "*",
48
+ plus: "+",
49
+ comma: ",",
50
+ hyphen: "-",
51
+ sfthyphen: "­",
52
+ minus: "−",
53
+ period: ".",
54
+ slash: "/",
55
+ zero: "0",
56
+ one: "1",
57
+ two: "2",
58
+ three: "3",
59
+ four: "4",
60
+ five: "5",
61
+ six: "6",
62
+ seven: "7",
63
+ eight: "8",
64
+ nine: "9",
65
+ colon: ":",
66
+ semicolon: ";",
67
+ less: "<",
68
+ equal: "=",
69
+ greater: ">",
70
+ question: "?",
71
+ at: "@",
72
+ bracketleft: "[",
73
+ backslash: "\\",
74
+ bracketright: "]",
75
+ asciicircum: "^",
76
+ underscore: "_",
77
+ grave: "`",
78
+ braceleft: "{",
79
+ bar: "|",
80
+ braceright: "}",
81
+ asciitilde: "~",
82
+ quoteleft: "‘",
83
+ quoteright: "’",
84
+ quotedblleft: "“",
85
+ quotedblright: "”",
86
+ quotesinglbase: "‚",
87
+ quotedblbase: "„",
88
+ guillemotleft: "«",
89
+ guillemotright: "»",
90
+ guilsinglleft: "‹",
91
+ guilsinglright: "›",
92
+ endash: "–",
93
+ emdash: "—",
94
+ bullet: "•",
95
+ ellipsis: "…",
96
+ dagger: "†",
97
+ daggerdbl: "‡",
98
+ perthousand: "‰",
99
+ trademark: "™",
100
+ copyright: "©",
101
+ registered: "®",
102
+ degree: "°",
103
+ plusminus: "±",
104
+ multiply: "×",
105
+ divide: "÷",
106
+ section: "§",
107
+ paragraph: "¶",
108
+ periodcentered: "·",
109
+ middot: "·",
110
+ cent: "¢",
111
+ sterling: "£",
112
+ yen: "¥",
113
+ Euro: "€",
114
+ currency: "¤",
115
+ brokenbar: "¦",
116
+ dieresis: "¨",
117
+ ordfeminine: "ª",
118
+ ordmasculine: "º",
119
+ logicalnot: "¬",
120
+ macron: "¯",
121
+ acute: "´",
122
+ mu: "µ",
123
+ cedilla: "¸",
124
+ onesuperior: "¹",
125
+ twosuperior: "²",
126
+ threesuperior: "³",
127
+ onequarter: "¼",
128
+ onehalf: "½",
129
+ threequarters: "¾",
130
+ questiondown: "¿",
131
+ exclamdown: "¡",
132
+ florin: "ƒ",
133
+ circumflex: "ˆ",
134
+ tilde: "˜",
135
+ fi: "fi",
136
+ fl: "fl",
137
+ AE: "Æ",
138
+ ae: "æ",
139
+ OE: "Œ",
140
+ oe: "œ",
141
+ Oslash: "Ø",
142
+ oslash: "ø",
143
+ germandbls: "ß",
144
+ Eth: "Ð",
145
+ eth: "ð",
146
+ Thorn: "Þ",
147
+ thorn: "þ",
148
+ dotlessi: "ı",
149
+ Lslash: "Ł",
150
+ lslash: "ł",
151
+ numero: "№",
152
+ afii61352: "№",
153
+ commaturnedmod: "ʻ",
154
+ afii57929: "ʼ",
155
+ afii64937: "ʽ",
156
+ apostrophemod: "ʼ"
157
+ }, c = {
158
+ grave: "̀",
159
+ acute: "́",
160
+ circumflex: "̂",
161
+ tilde: "̃",
162
+ macron: "̄",
163
+ breve: "̆",
164
+ dotaccent: "̇",
165
+ dieresis: "̈",
166
+ ring: "̊",
167
+ hungarumlaut: "̋",
168
+ caron: "̌",
169
+ commaaccent: "̦",
170
+ cedilla: "̧",
171
+ ogonek: "̨"
172
+ }, l = (e) => {
173
+ if (e >= 10017 && e <= 10049) return e === 10023 ? "Ё" : String.fromCharCode(1040 + e - (e < 10023 ? 10017 : 10018));
174
+ if (e >= 10065 && e <= 10097) return e === 10071 ? "ё" : String.fromCharCode(1072 + e - (e < 10071 ? 10065 : 10066));
175
+ if (e === 10050) return "Ґ";
176
+ if (e >= 10051 && e <= 10061) return String.fromCharCode(1026 + e - 10051);
177
+ if (e === 10062) return "Ў";
178
+ if (e === 10098) return "ґ";
179
+ if (e >= 10099 && e <= 10109) return String.fromCharCode(1106 + e - 10099);
180
+ if (e === 10110) return "ў";
181
+ if (e === 10145) return "Џ";
182
+ if (e === 10193) return "џ";
183
+ }, u = /* @__PURE__ */ new Map(), d = (e) => {
184
+ if (u.has(e)) return u.get(e);
185
+ let t = f(e);
186
+ return u.set(e, t), t;
187
+ }, f = (e) => {
188
+ let t = e.split(".")[0] ?? "";
189
+ if (t.includes("_")) {
190
+ let e = t.split("_").map((e) => f(e));
191
+ return e.every(Boolean) ? e.join("") : void 0;
192
+ }
193
+ if (s[t] !== void 0) return s[t];
194
+ if (/^[A-Za-z]$/.test(t)) return t;
195
+ let n = /^uni((?:[\dA-F]{4})+)$/.exec(t);
196
+ if (n?.[1]) return (n[1].match(/.{4}/g) ?? []).map((e) => String.fromCharCode(Number.parseInt(e, 16))).join("");
197
+ let r = /^u([\dA-F]{4,6})$/.exec(t);
198
+ if (r?.[1]) {
199
+ let e = Number.parseInt(r[1], 16);
200
+ return e <= 1114111 ? String.fromCodePoint(e) : void 0;
201
+ }
202
+ let i = /^afii(\d{5})$/.exec(t);
203
+ if (i?.[1]) return l(Number(i[1]));
204
+ let a = /^([A-Za-z])(grave|acute|circumflex|tilde|macron|breve|dotaccent|dieresis|ring|hungarumlaut|caron|commaaccent|cedilla|ogonek)$/.exec(t);
205
+ if (a?.[1] && a[2]) return `${a[1]}${c[a[2]]}`.normalize("NFC");
206
+ }, p = [
207
+ 278,
208
+ 278,
209
+ 355,
210
+ 556,
211
+ 556,
212
+ 889,
213
+ 667,
214
+ 191,
215
+ 333,
216
+ 333,
217
+ 389,
218
+ 584,
219
+ 278,
220
+ 333,
221
+ 278,
222
+ 278,
223
+ 556,
224
+ 556,
225
+ 556,
226
+ 556,
227
+ 556,
228
+ 556,
229
+ 556,
230
+ 556,
231
+ 556,
232
+ 556,
233
+ 278,
234
+ 278,
235
+ 584,
236
+ 584,
237
+ 584,
238
+ 556,
239
+ 1015,
240
+ 667,
241
+ 667,
242
+ 722,
243
+ 722,
244
+ 667,
245
+ 611,
246
+ 778,
247
+ 722,
248
+ 278,
249
+ 500,
250
+ 667,
251
+ 556,
252
+ 833,
253
+ 722,
254
+ 778,
255
+ 667,
256
+ 778,
257
+ 722,
258
+ 667,
259
+ 611,
260
+ 722,
261
+ 667,
262
+ 944,
263
+ 667,
264
+ 667,
265
+ 611,
266
+ 278,
267
+ 278,
268
+ 278,
269
+ 469,
270
+ 556,
271
+ 333,
272
+ 556,
273
+ 556,
274
+ 500,
275
+ 556,
276
+ 556,
277
+ 278,
278
+ 556,
279
+ 556,
280
+ 222,
281
+ 222,
282
+ 500,
283
+ 222,
284
+ 833,
285
+ 556,
286
+ 556,
287
+ 556,
288
+ 556,
289
+ 333,
290
+ 500,
291
+ 278,
292
+ 556,
293
+ 500,
294
+ 722,
295
+ 500,
296
+ 500,
297
+ 500,
298
+ 334,
299
+ 260,
300
+ 334,
301
+ 584
302
+ ], m = [
303
+ 250,
304
+ 333,
305
+ 408,
306
+ 500,
307
+ 500,
308
+ 833,
309
+ 778,
310
+ 180,
311
+ 333,
312
+ 333,
313
+ 500,
314
+ 564,
315
+ 250,
316
+ 333,
317
+ 250,
318
+ 278,
319
+ 500,
320
+ 500,
321
+ 500,
322
+ 500,
323
+ 500,
324
+ 500,
325
+ 500,
326
+ 500,
327
+ 500,
328
+ 500,
329
+ 278,
330
+ 278,
331
+ 564,
332
+ 564,
333
+ 564,
334
+ 444,
335
+ 921,
336
+ 722,
337
+ 667,
338
+ 667,
339
+ 722,
340
+ 611,
341
+ 556,
342
+ 722,
343
+ 722,
344
+ 333,
345
+ 389,
346
+ 722,
347
+ 611,
348
+ 889,
349
+ 722,
350
+ 722,
351
+ 556,
352
+ 722,
353
+ 667,
354
+ 556,
355
+ 611,
356
+ 722,
357
+ 722,
358
+ 944,
359
+ 722,
360
+ 722,
361
+ 611,
362
+ 333,
363
+ 278,
364
+ 333,
365
+ 469,
366
+ 500,
367
+ 333,
368
+ 444,
369
+ 500,
370
+ 444,
371
+ 500,
372
+ 444,
373
+ 333,
374
+ 500,
375
+ 500,
376
+ 278,
377
+ 278,
378
+ 500,
379
+ 278,
380
+ 778,
381
+ 500,
382
+ 500,
383
+ 500,
384
+ 500,
385
+ 333,
386
+ 389,
387
+ 278,
388
+ 500,
389
+ 500,
390
+ 722,
391
+ 500,
392
+ 500,
393
+ 444,
394
+ 480,
395
+ 200,
396
+ 480,
397
+ 541
398
+ ], h = (e, t) => {
399
+ if (/courier|mono/i.test(e)) return 600;
400
+ let n = /times|serif|roman/i.test(e) ? m : p;
401
+ return n[t.charCodeAt(0) - 32] ?? (n === m ? 480 : 530);
402
+ }, g = class e {
403
+ value;
404
+ static cache = /* @__PURE__ */ new Map();
405
+ constructor(e) {
406
+ this.value = e;
407
+ }
408
+ static of(t) {
409
+ let n = e.cache.get(t);
410
+ return n || (n = new e(t), e.cache.set(t, n)), n;
411
+ }
412
+ }, _ = class {
413
+ num;
414
+ gen;
415
+ constructor(e, t) {
416
+ this.num = e, this.gen = t;
417
+ }
418
+ }, v = class {
419
+ name;
420
+ constructor(e) {
421
+ this.name = e;
422
+ }
423
+ }, y = class {
424
+ entries = /* @__PURE__ */ new Map();
425
+ get(e) {
426
+ return this.entries.get(e);
427
+ }
428
+ has(e) {
429
+ return this.entries.has(e);
430
+ }
431
+ }, b = class {
432
+ dict;
433
+ raw;
434
+ constructor(e, t) {
435
+ this.dict = e, this.raw = t;
436
+ }
437
+ }, x = /* @__PURE__ */ new Uint8Array(256);
438
+ for (let e of [
439
+ 0,
440
+ 9,
441
+ 10,
442
+ 12,
443
+ 13,
444
+ 32
445
+ ]) x[e] = 1;
446
+ var ee = /* @__PURE__ */ new Uint8Array(256);
447
+ for (let e of "()<>[]{}/%") ee[e.charCodeAt(0)] = 1;
448
+ var te = (e) => !x[e] && !ee[e], ne = {
449
+ 110: 10,
450
+ 114: 13,
451
+ 116: 9,
452
+ 98: 8,
453
+ 102: 12,
454
+ 40: 40,
455
+ 41: 41,
456
+ 92: 92
457
+ }, re = Symbol("["), S = Symbol("]"), C = Symbol("<<"), w = Symbol(">>"), T = Symbol("EOF"), E = (e, t, n) => {
458
+ let r = "";
459
+ for (let i = t; i < n; i += 1) r += String.fromCharCode(e[i]);
460
+ return r;
461
+ }, D = class {
462
+ data;
463
+ position;
464
+ constructor(e, t = 0) {
465
+ this.data = e, this.position = t;
466
+ }
467
+ skipWhitespace() {
468
+ let { data: e } = this;
469
+ for (; this.position < e.length;) {
470
+ let t = e[this.position];
471
+ if (x[t]) this.position += 1;
472
+ else if (t === 37) for (; this.position < e.length && e[this.position] !== 10 && e[this.position] !== 13;) this.position += 1;
473
+ else return;
474
+ }
475
+ }
476
+ next() {
477
+ this.skipWhitespace();
478
+ let { data: e } = this;
479
+ if (this.position >= e.length) return T;
480
+ switch (e[this.position]) {
481
+ case 91: return this.position += 1, re;
482
+ case 93: return this.position += 1, S;
483
+ case 40: return this.literalString();
484
+ case 47: return this.name();
485
+ case 60: return e[this.position + 1] === 60 ? (this.position += 2, C) : this.hexString();
486
+ case 62: return this.position += e[this.position + 1] === 62 ? 2 : 1, w;
487
+ case 123:
488
+ case 125: return this.position += 1, this.next();
489
+ default: return this.word();
490
+ }
491
+ }
492
+ word() {
493
+ let { data: e } = this, t = this.position;
494
+ for (; this.position < e.length && te(e[this.position]);) this.position += 1;
495
+ if (this.position === t) return this.position += 1, this.next();
496
+ let n = E(e, t, this.position), r = n.charCodeAt(0);
497
+ if (r >= 48 && r <= 57 || r === 43 || r === 45 || r === 46) {
498
+ let e = Number(n);
499
+ return Number.isFinite(e) ? e : 0;
500
+ }
501
+ return n === "true" ? !0 : n === "false" ? !1 : n === "null" ? null : new v(n);
502
+ }
503
+ name() {
504
+ let { data: e } = this;
505
+ this.position += 1;
506
+ let t = "";
507
+ for (; this.position < e.length && te(e[this.position]);) {
508
+ let n = e[this.position];
509
+ if (n === 35) {
510
+ let n = Number.parseInt(E(e, this.position + 1, this.position + 3), 16);
511
+ if (Number.isFinite(n)) {
512
+ t += String.fromCharCode(n), this.position += 3;
513
+ continue;
514
+ }
515
+ }
516
+ t += String.fromCharCode(n), this.position += 1;
517
+ }
518
+ return g.of(t);
519
+ }
520
+ literalString() {
521
+ let { data: e } = this;
522
+ this.position += 1;
523
+ let t = [], n = 1;
524
+ for (; this.position < e.length;) {
525
+ let r = e[this.position++];
526
+ if (r === 40) n += 1;
527
+ else if (r === 41) {
528
+ if (--n, n === 0) break;
529
+ } else if (r === 92) {
530
+ let n = e[this.position++], r = ne[n];
531
+ if (r !== void 0) t.push(r);
532
+ else if (n >= 48 && n <= 55) {
533
+ let r = n - 48;
534
+ for (let t = 1; t < 3; t += 1) {
535
+ let t = e[this.position];
536
+ if (t < 48 || t > 55) break;
537
+ r = r * 8 + (t - 48), this.position += 1;
538
+ }
539
+ t.push(r & 255);
540
+ } else n === 13 ? e[this.position] === 10 && (this.position += 1) : n !== 10 && t.push(n);
541
+ continue;
542
+ }
543
+ t.push(r);
544
+ }
545
+ return Uint8Array.from(t);
546
+ }
547
+ hexString() {
548
+ let { data: e } = this, t = this.position + 1, n = t;
549
+ for (; n < e.length && e[n] !== 62;) n += 1;
550
+ this.position = n + 1;
551
+ let r = [];
552
+ for (let i = t; i < n; i += 1) {
553
+ let t = e[i], n = t >= 48 && t <= 57 ? t - 48 : t >= 65 && t <= 70 ? t - 55 : t >= 97 && t <= 102 ? t - 87 : -1;
554
+ n >= 0 && r.push(n);
555
+ }
556
+ r.length % 2 && r.push(0);
557
+ let i = new Uint8Array(r.length / 2);
558
+ for (let e = 0; e < i.length; e += 1) i[e] = r[e * 2] << 4 | r[e * 2 + 1];
559
+ return i;
560
+ }
561
+ skipStreamEol() {
562
+ this.data[this.position] === 13 && (this.position += 1), this.data[this.position] === 10 && (this.position += 1);
563
+ }
564
+ matchesAt(e, t) {
565
+ for (let n = 0; n < t.length; n += 1) if (this.data[e + n] !== t.charCodeAt(n)) return !1;
566
+ return !0;
567
+ }
568
+ indexOf(e, t = this.position) {
569
+ let { data: n } = this, r = e.charCodeAt(0);
570
+ for (let i = n.indexOf(r, t); i >= 0; i = n.indexOf(r, i + 1)) if (this.matchesAt(i, e)) return i;
571
+ return -1;
572
+ }
573
+ }, O = (e, t) => e instanceof v && (t === void 0 || e.name === t), k = class {
574
+ lexer;
575
+ resolveLength;
576
+ buffer = [];
577
+ constructor(e, t = (e) => typeof e == "number" ? e : void 0) {
578
+ this.lexer = e, this.resolveLength = t;
579
+ }
580
+ shift() {
581
+ return this.buffer.length ? this.buffer.shift() : this.lexer.next();
582
+ }
583
+ peek(e) {
584
+ for (; this.buffer.length <= e;) this.buffer.push(this.lexer.next());
585
+ return this.buffer[e];
586
+ }
587
+ next() {
588
+ let e = this.shift();
589
+ if (e === T) return T;
590
+ if (e === re) return this.array();
591
+ if (e === C) return this.dictOrStream();
592
+ if (e === S || e === w) return this.next();
593
+ if (typeof e == "number" && Number.isInteger(e) && e >= 0) {
594
+ let t = this.peek(0);
595
+ if (typeof t == "number" && Number.isInteger(t) && O(this.peek(1), "R")) return this.buffer.splice(0, 2), new _(e, t);
596
+ }
597
+ return e;
598
+ }
599
+ value() {
600
+ let e = this.next();
601
+ return e === T || e instanceof v ? null : e;
602
+ }
603
+ array() {
604
+ let e = [];
605
+ for (;;) {
606
+ let t = this.peek(0);
607
+ if (t === T) return e;
608
+ if (t === S) return this.shift(), e;
609
+ let n = this.next();
610
+ n !== T && !(n instanceof v) && e.push(n);
611
+ }
612
+ }
613
+ dictOrStream() {
614
+ let e = new y();
615
+ for (;;) {
616
+ let t = this.peek(0);
617
+ if (t === T) return e;
618
+ if (t === w) {
619
+ this.shift();
620
+ break;
621
+ }
622
+ let n = this.next();
623
+ if (!(n instanceof g)) continue;
624
+ if (this.peek(0) === w) break;
625
+ let r = this.next();
626
+ r !== T && !(r instanceof v) && e.entries.set(n.value, r);
627
+ }
628
+ return this.buffer.length === 0 && this.isStreamAhead() ? this.stream(e) : e;
629
+ }
630
+ isStreamAhead() {
631
+ let { lexer: e } = this, t = e.position;
632
+ return O(e.next(), "stream") ? !0 : (e.position = t, !1);
633
+ }
634
+ stream(e) {
635
+ let { lexer: t } = this;
636
+ t.skipStreamEol();
637
+ let n = t.position, r = this.resolveLength(e.get("Length")), i = r === void 0 ? -1 : n + r;
638
+ if (i < n || i > t.data.length || !this.endsStreamAt(i)) {
639
+ let e = t.indexOf("endstream", n);
640
+ for (i = e < 0 ? t.data.length : e; i > n && (t.data[i - 1] === 10 || t.data[i - 1] === 13);) --i;
641
+ }
642
+ let a = t.data.subarray(n, i), o = t.indexOf("endstream", i);
643
+ return t.position = o < 0 ? t.data.length : o + 9, new b(e, a);
644
+ }
645
+ endsStreamAt(e) {
646
+ let { data: t } = this.lexer, n = e;
647
+ for (; n < e + 4 && x[t[n] ?? 0];) n += 1;
648
+ return this.lexer.matchesAt(n, "endstream");
649
+ }
650
+ }, A = (e, t = 0, n = e.length) => E(e, t, n), j = (e) => e.reduce((e, t) => e * 256 + t, 0), M = (e) => {
651
+ let t = "";
652
+ for (let n = 0; n + 1 < e.length; n += 2) t += String.fromCharCode(e[n] << 8 | e[n + 1]);
653
+ return t;
654
+ }, ie = (e, t) => t === 0 || !e ? e : e.slice(0, -1) + String.fromCharCode(e.charCodeAt(e.length - 1) + t), N = 65536, ae = (e) => {
655
+ let t = {
656
+ codespaces: [],
657
+ unicode: /* @__PURE__ */ new Map(),
658
+ cids: /* @__PURE__ */ new Map()
659
+ }, n = new k(new D(e)), r = [];
660
+ for (let e = n.next(); e !== T; e = n.next()) {
661
+ if (!(e instanceof v)) {
662
+ r.push(e);
663
+ continue;
664
+ }
665
+ switch (e.name) {
666
+ case "endcodespacerange":
667
+ for (let e = 0; e + 1 < r.length; e += 2) {
668
+ let n = r[e], i = r[e + 1];
669
+ n instanceof Uint8Array && i instanceof Uint8Array && t.codespaces.push({
670
+ length: n.length,
671
+ low: j(n),
672
+ high: j(i)
673
+ });
674
+ }
675
+ break;
676
+ case "endbfchar":
677
+ for (let e = 0; e + 1 < r.length; e += 2) {
678
+ let n = r[e], i = r[e + 1];
679
+ if (n instanceof Uint8Array && i instanceof Uint8Array) t.unicode.set(j(n), M(i));
680
+ else if (n instanceof Uint8Array && i instanceof g) {
681
+ let e = d(i.value);
682
+ e && t.unicode.set(j(n), e);
683
+ }
684
+ }
685
+ break;
686
+ case "endbfrange":
687
+ for (let e = 0; e + 2 < r.length; e += 3) {
688
+ let n = r[e], i = r[e + 1], a = r[e + 2];
689
+ if (!(n instanceof Uint8Array) || !(i instanceof Uint8Array)) continue;
690
+ let o = j(n), s = Math.min(j(i), o + N);
691
+ for (let e = o; e <= s; e += 1) {
692
+ let n = e - o;
693
+ a instanceof Uint8Array ? t.unicode.set(e, ie(M(a), n)) : Array.isArray(a) && a[n] instanceof Uint8Array && t.unicode.set(e, M(a[n]));
694
+ }
695
+ }
696
+ break;
697
+ case "endcidchar":
698
+ for (let e = 0; e + 1 < r.length; e += 2) {
699
+ let n = r[e], i = r[e + 1];
700
+ n instanceof Uint8Array && typeof i == "number" && t.cids.set(j(n), i);
701
+ }
702
+ break;
703
+ case "endcidrange": for (let e = 0; e + 2 < r.length; e += 3) {
704
+ let n = r[e], i = r[e + 1], a = r[e + 2];
705
+ if (!(n instanceof Uint8Array) || !(i instanceof Uint8Array) || typeof a != "number") continue;
706
+ let o = j(n), s = Math.min(j(i), o + N);
707
+ for (let e = o; e <= s; e += 1) t.cids.set(e, a + e - o);
708
+ }
709
+ }
710
+ r.length = 0;
711
+ }
712
+ return t;
713
+ }, oe = [
714
+ [/times/i, "Times New Roman"],
715
+ [/arial|helvetica|liberationsans|arimo/i, "Arial"],
716
+ [/courier|liberationmono|cousine/i, "Courier New"],
717
+ [/calibri|carlito/i, "Calibri"],
718
+ [/cambria|caladea/i, "Cambria"],
719
+ [/georgia/i, "Georgia"],
720
+ [/tahoma/i, "Tahoma"],
721
+ [/verdana/i, "Verdana"]
722
+ ], se = 4, ce = 64, le = 1 << 18, P = 1e3, ue = class {
723
+ name;
724
+ bold;
725
+ italic;
726
+ family;
727
+ sizeScale;
728
+ composite;
729
+ codespaces;
730
+ toUnicode;
731
+ cids;
732
+ encoding;
733
+ differences = /* @__PURE__ */ new Map();
734
+ widths = /* @__PURE__ */ new Map();
735
+ defaultWidth;
736
+ widthScale;
737
+ measuredByName;
738
+ glyphCache = /* @__PURE__ */ new Map();
739
+ constructor(e, t) {
740
+ let n = e.name(t.get("Subtype"));
741
+ this.composite = n === "Type0";
742
+ let r = this.composite ? e.dict(e.array(t.get("DescendantFonts"))?.[0]) : void 0, i = e.dict((r ?? t).get("FontDescriptor"));
743
+ this.name = (e.name(t.get("BaseFont")) ?? e.name(r?.get("BaseFont")) ?? "").replace(/^[A-Z]{6}\+/, "");
744
+ let a = e.number(i?.get("Flags")) ?? 0, o = e.number(i?.get("FontWeight")) ?? 0;
745
+ this.bold = /bold|black|heavy|semibold|demi/i.test(this.name) || o >= 600 || (a & le) !== 0, this.italic = /italic|oblique|kursiv/i.test(this.name) || (a & ce) !== 0 || (e.number(i?.get("ItalicAngle")) ?? 0) !== 0, this.family = oe.find(([e]) => e.test(this.name))?.[1];
746
+ let s = e.stream(t.get("ToUnicode"));
747
+ if (this.toUnicode = s ? ae(e.bytes(s)).unicode : void 0, this.composite) {
748
+ let n = e.get(t.get("Encoding")), i = e.stream(n), a = i ? ae(e.bytes(i)) : void 0;
749
+ this.cids = a?.cids.size ? a.cids : void 0, this.codespaces = a?.codespaces.length ? a.codespaces : [{
750
+ length: 2,
751
+ low: 0,
752
+ high: 65535
753
+ }], this.encoding = void 0, this.defaultWidth = e.number(r?.get("DW")) ?? P, this.readCidWidths(e, e.array(r?.get("W")) ?? []), this.widthScale = 1, this.sizeScale = 1, this.measuredByName = !1;
754
+ } else {
755
+ this.codespaces = [{
756
+ length: 1,
757
+ low: 0,
758
+ high: 255
759
+ }], this.cids = void 0, this.encoding = this.readEncoding(e, t, n, a);
760
+ let r = e.number(t.get("FirstChar")) ?? 0, o = e.numbers(t.get("Widths"));
761
+ o?.forEach((e, t) => {
762
+ this.widths.set(r + t, e);
763
+ }), this.defaultWidth = e.number(i?.get("MissingWidth"));
764
+ let s = n === "Type3" ? e.numbers(t.get("FontMatrix")) : void 0;
765
+ this.widthScale = s?.[0] ? Math.abs(s[0]) * 1e3 : 1, this.sizeScale = s?.[3] ? Math.abs(s[3]) * 1e3 : 1, this.measuredByName = !o?.length;
766
+ }
767
+ }
768
+ readEncoding(e, t, n, r) {
769
+ let s = e.get(t.get("Encoding")), c = s instanceof g ? s.value : e.name(e.dict(s)?.get("BaseEncoding")), l = e.array(e.dict(s)?.get("Differences")) ?? [], u = 0;
770
+ for (let t of l) {
771
+ let n = e.get(t);
772
+ typeof n == "number" ? u = n : n instanceof g && (this.differences.set(u, n.value), u += 1);
773
+ }
774
+ if (c === "WinAnsiEncoding") return i;
775
+ if (c === "MacRomanEncoding") return a;
776
+ if (c === "StandardEncoding" || c === "MacExpertEncoding") return o;
777
+ if (!(r & se && !l.length)) return n === "TrueType" ? i : o;
778
+ }
779
+ readCidWidths(e, t) {
780
+ for (let n = 0; n < t.length;) {
781
+ let r = e.number(t[n]), i = e.get(t[n + 1]);
782
+ if (r === void 0) break;
783
+ if (Array.isArray(i)) i.forEach((t, n) => {
784
+ this.widths.set(r + n, e.number(t) ?? 0);
785
+ }), n += 2;
786
+ else {
787
+ let a = e.number(i) ?? r, o = e.number(t[n + 2]) ?? 0;
788
+ for (let e = r; e <= Math.min(a, r + N); e += 1) this.widths.set(e, o);
789
+ n += 3;
790
+ }
791
+ }
792
+ }
793
+ decode(e) {
794
+ let t = [];
795
+ for (let n = 0; n < e.length;) {
796
+ let r = this.codeLength(e, n), i = j(e.subarray(n, n + r));
797
+ n += r;
798
+ let a = this.glyphCache.get(i);
799
+ a || (a = this.describe(i, r), this.glyphCache.set(i, a)), t.push(a);
800
+ }
801
+ return t;
802
+ }
803
+ codeLength(e, t) {
804
+ if (!this.composite) return 1;
805
+ for (let n = 1; n <= 4 && t + n <= e.length; n += 1) {
806
+ let r = j(e.subarray(t, t + n));
807
+ if (this.codespaces.some((e) => e.length === n && r >= e.low && r <= e.high)) return n;
808
+ }
809
+ return Math.min(...this.codespaces.map((e) => e.length), e.length - t);
810
+ }
811
+ describe(e, t) {
812
+ let n = this.unicodeOf(e);
813
+ return {
814
+ text: n,
815
+ width: this.widthOf(e, n),
816
+ wordSpace: t === 1 && e === 32
817
+ };
818
+ }
819
+ unicodeOf(e) {
820
+ let t = this.toUnicode?.get(e);
821
+ if (t && t !== "\0") return t;
822
+ if (this.composite) return "";
823
+ let n = this.differences.get(e);
824
+ if (n) {
825
+ let e = d(n);
826
+ if (e !== void 0) return e;
827
+ }
828
+ return this.encoding ? this.encoding[e] ?? "" : e >= 32 ? String.fromCharCode(e) : "";
829
+ }
830
+ widthOf(e, t) {
831
+ if (this.composite) {
832
+ let t = this.cids?.get(e) ?? e;
833
+ return this.widths.get(t) ?? this.defaultWidth ?? P;
834
+ }
835
+ let n = this.widths.get(e);
836
+ return n === void 0 ? this.measuredByName ? h(this.name, t || " ") : (this.defaultWidth ?? 0) * this.widthScale : n * this.widthScale;
837
+ }
838
+ }, de = 25e6, fe = (e) => {
839
+ let t = "", n = 32768;
840
+ for (let r = 0; r < e.length; r += n) t += String.fromCharCode(...e.subarray(r, r + n));
841
+ return btoa(t);
842
+ }, pe = (e, t, n = 0) => {
843
+ let r = e.get(t), i = r instanceof g ? r.value : e.name(e.array(r)?.[0]), a = e.array(r) ?? [];
844
+ switch (i) {
845
+ case "DeviceGray":
846
+ case "CalGray":
847
+ case "G": return { components: 1 };
848
+ case "DeviceRGB":
849
+ case "CalRGB":
850
+ case "RGB": return { components: 3 };
851
+ case "DeviceCMYK":
852
+ case "CMYK": return {
853
+ components: 4,
854
+ cmyk: !0
855
+ };
856
+ case "ICCBased": {
857
+ let t = e.number(e.dict(a[1])?.get("N")) ?? 3;
858
+ return {
859
+ components: t,
860
+ cmyk: t === 4
861
+ };
862
+ }
863
+ case "Indexed":
864
+ case "I": {
865
+ if (n > 2) return;
866
+ let t = pe(e, a[1], n + 1), r = e.get(a[3]), i = r instanceof Uint8Array ? r : r instanceof b ? e.bytes(r) : void 0;
867
+ if (!t || !i) return;
868
+ let o = (e.number(a[2]) ?? 0) + 1, s = new Uint8Array(o * 3);
869
+ for (let e = 0; e < o; e += 1) {
870
+ let n = Array.from(i.subarray(e * t.components, (e + 1) * t.components), (e) => e / 255);
871
+ s.set(me(n, t), e * 3);
872
+ }
873
+ return {
874
+ components: 1,
875
+ palette: s
876
+ };
877
+ }
878
+ default: return;
879
+ }
880
+ }, me = (e, t) => {
881
+ if (t.components === 1) {
882
+ let t = Math.round((e[0] ?? 0) * 255);
883
+ return [
884
+ t,
885
+ t,
886
+ t
887
+ ];
888
+ }
889
+ if (t.cmyk) {
890
+ let [t = 0, n = 0, r = 0, i = 0] = e;
891
+ return [
892
+ Math.round(255 * (1 - t) * (1 - i)),
893
+ Math.round(255 * (1 - n) * (1 - i)),
894
+ Math.round(255 * (1 - r) * (1 - i))
895
+ ];
896
+ }
897
+ return [
898
+ Math.round((e[0] ?? 0) * 255),
899
+ Math.round((e[1] ?? 0) * 255),
900
+ Math.round((e[2] ?? 0) * 255)
901
+ ];
902
+ }, he = (e, t, n) => {
903
+ let r = Math.ceil(n * t / 8), i = (1 << Math.min(t, 16)) - 1;
904
+ return (n, a) => {
905
+ let o = a * t, s = n * r + (o >> 3);
906
+ if (t === 8 || t === 16) return e[s] ?? 0;
907
+ let c = 8 - (o & 7) - t;
908
+ return ((e[s] ?? 0) >> c & i) * (255 / i);
909
+ };
910
+ }, ge = (e, t, n, r, i, a) => {
911
+ let o = new Uint8ClampedArray(t * n * 4), s = he(e, r, t * i.components), c = Array(i.components);
912
+ for (let l = 0; l < n; l += 1) for (let n = 0; n < t; n += 1) {
913
+ let u = (l * t + n) * 4;
914
+ if (i.palette) {
915
+ let a = n * r, s = e[l * Math.ceil(t * r / 8) + (a >> 3)] ?? 0, c = r === 8 ? s : s >> 8 - (a & 7) - r & (1 << r) - 1;
916
+ o[u] = i.palette[c * 3] ?? 0, o[u + 1] = i.palette[c * 3 + 1] ?? 0, o[u + 2] = i.palette[c * 3 + 2] ?? 0;
917
+ } else {
918
+ for (let e = 0; e < i.components; e += 1) c[e] = s(l, n * i.components + e) / 255;
919
+ let [e, t, r] = me(c, i);
920
+ o[u] = e, o[u + 1] = t, o[u + 2] = r;
921
+ }
922
+ o[u + 3] = a ? a(l, n) : 255;
923
+ }
924
+ return o;
925
+ }, _e = (e, t, n) => {
926
+ if (typeof document > "u") return null;
927
+ let r = document.createElement("canvas"), i = r.getContext("2d");
928
+ return !i || typeof ImageData > "u" ? null : (r.width = t, r.height = n, i.putImageData(new ImageData(e, t, n), 0, 0), r.toDataURL("image/png"));
929
+ }, ve = (e, t) => {
930
+ let { dict: n } = t;
931
+ if (n.get("ImageMask") === !0) return null;
932
+ try {
933
+ let { data: r, imageFilter: i } = e.decode(t);
934
+ if (i === "DCTDecode" || i === "DCT") return `data:image/jpeg;base64,${fe(r)}`;
935
+ if (i) return null;
936
+ let a = e.number(n.get("Width")) ?? 0, o = e.number(n.get("Height")) ?? 0, s = e.number(n.get("BitsPerComponent")) ?? 8, c = pe(e, n.get("ColorSpace"));
937
+ if (!c || a <= 0 || o <= 0 || a * o > de) return null;
938
+ let l = e.stream(n.get("SMask")), u;
939
+ return l && e.number(l.dict.get("Width")) === a && e.number(l.dict.get("Height")) === o && (u = he(e.bytes(l), e.number(l.dict.get("BitsPerComponent")) ?? 8, a)), _e(ge(r, a, o, s, c, u), a, o);
940
+ } catch {
941
+ return null;
942
+ }
943
+ }, F = [
944
+ 1,
945
+ 0,
946
+ 0,
947
+ 1,
948
+ 0,
949
+ 0
950
+ ], I = (e, t) => [
951
+ e[0] * t[0] + e[1] * t[2],
952
+ e[0] * t[1] + e[1] * t[3],
953
+ e[2] * t[0] + e[3] * t[2],
954
+ e[2] * t[1] + e[3] * t[3],
955
+ e[4] * t[0] + e[5] * t[2] + t[4],
956
+ e[4] * t[1] + e[5] * t[3] + t[5]
957
+ ], L = (e, t, n) => [e[0] * t + e[2] * n + e[4], e[1] * t + e[3] * n + e[5]], ye = (e) => {
958
+ let [t, n, r, i] = e.box;
959
+ switch (e.rotate) {
960
+ case 90: return [
961
+ 0,
962
+ 1,
963
+ 1,
964
+ 0,
965
+ -n,
966
+ -t
967
+ ];
968
+ case 180: return [
969
+ -1,
970
+ 0,
971
+ 0,
972
+ 1,
973
+ r,
974
+ -n
975
+ ];
976
+ case 270: return [
977
+ 0,
978
+ -1,
979
+ -1,
980
+ 0,
981
+ i,
982
+ r
983
+ ];
984
+ default: return [
985
+ 1,
986
+ 0,
987
+ 0,
988
+ -1,
989
+ -t,
990
+ i
991
+ ];
992
+ }
993
+ }, R = (e) => Math.round(Math.min(1, Math.max(0, e)) * 255).toString(16).padStart(2, "0"), be = (e) => {
994
+ if (e.length === 1) {
995
+ let t = e[0];
996
+ return `#${R(t)}${R(t)}${R(t)}`;
997
+ }
998
+ if (e.length === 3) return `#${e.map(R).join("")}`;
999
+ if (e.length === 4) {
1000
+ let [t, n, r, i] = e;
1001
+ return `#${R((1 - t) * (1 - i))}${R((1 - n) * (1 - i))}${R((1 - r) * (1 - i))}`;
1002
+ }
1003
+ return "#000000";
1004
+ }, xe = 12, Se = .12, z = 12, Ce = 3, we = /* @__PURE__ */ new Set([
1005
+ "S",
1006
+ "s",
1007
+ "f",
1008
+ "F",
1009
+ "f*",
1010
+ "B",
1011
+ "B*",
1012
+ "b",
1013
+ "b*"
1014
+ ]), Te = (e) => {
1015
+ let t = e.map(([e]) => e), n = e.map(([, e]) => e), r = Math.min(...t), i = Math.min(...n);
1016
+ return {
1017
+ x: r,
1018
+ y: i,
1019
+ width: Math.max(...t) - r,
1020
+ height: Math.max(...n) - i
1021
+ };
1022
+ }, Ee = class {
1023
+ doc;
1024
+ fonts = /* @__PURE__ */ new Map();
1025
+ images = /* @__PURE__ */ new Map();
1026
+ constructor(e) {
1027
+ this.doc = e;
1028
+ }
1029
+ read(e) {
1030
+ let [t, n, r, i] = e.box, a = e.rotate === 90 || e.rotate === 270, o = {
1031
+ width: a ? i - n : r - t,
1032
+ height: a ? r - t : i - n,
1033
+ spans: [],
1034
+ images: [],
1035
+ rules: []
1036
+ }, s = new De(this, o, e.resources, ye(e));
1037
+ return s.execute(this.doc.contents(e), 0), s.flush(), o;
1038
+ }
1039
+ get document() {
1040
+ return this.doc;
1041
+ }
1042
+ font(e) {
1043
+ let t = this.fonts.get(e);
1044
+ return t || (t = new ue(this.doc, e), this.fonts.set(e, t)), t;
1045
+ }
1046
+ image(e) {
1047
+ return this.images.has(e) || this.images.set(e, ve(this.doc, e)), this.images.get(e) ?? null;
1048
+ }
1049
+ }, De = class {
1050
+ reader;
1051
+ content;
1052
+ resources;
1053
+ state;
1054
+ stack = [];
1055
+ textMatrix = F;
1056
+ lineMatrix = F;
1057
+ span = null;
1058
+ spanEnd = 0;
1059
+ path = [];
1060
+ point = [0, 0];
1061
+ constructor(e, t, n, r) {
1062
+ this.reader = e, this.content = t, this.resources = n, this.state = {
1063
+ ctm: r,
1064
+ color: "#000000",
1065
+ font: void 0,
1066
+ fontSize: 0,
1067
+ charSpacing: 0,
1068
+ wordSpacing: 0,
1069
+ scale: 1,
1070
+ leading: 0,
1071
+ rise: 0,
1072
+ renderMode: 0
1073
+ };
1074
+ }
1075
+ get doc() {
1076
+ return this.reader.document;
1077
+ }
1078
+ execute(e, t) {
1079
+ let n = new k(new D(e)), r = [];
1080
+ for (let e = n.next(); e !== T; e = n.next()) {
1081
+ if (!(e instanceof v)) {
1082
+ r.push(e);
1083
+ continue;
1084
+ }
1085
+ e.name === "BI" ? Ae(n.lexer) : this.operator(e.name, r, t), r.length = 0;
1086
+ }
1087
+ }
1088
+ number(e, t) {
1089
+ let n = e[t];
1090
+ return typeof n == "number" ? n : 0;
1091
+ }
1092
+ operator(e, t, n) {
1093
+ let r = this.state, i = (e) => this.number(t, e);
1094
+ switch (e) {
1095
+ case "q":
1096
+ this.stack.push({ ...r });
1097
+ break;
1098
+ case "Q":
1099
+ this.state = this.stack.pop() ?? r;
1100
+ break;
1101
+ case "cm":
1102
+ r.ctm = I([
1103
+ i(0),
1104
+ i(1),
1105
+ i(2),
1106
+ i(3),
1107
+ i(4),
1108
+ i(5)
1109
+ ], r.ctm);
1110
+ break;
1111
+ case "BT":
1112
+ this.textMatrix = F, this.lineMatrix = F;
1113
+ break;
1114
+ case "ET": break;
1115
+ case "Tf": {
1116
+ let e = t[0], n = this.doc.dict(this.resources.get("Font")), a = e instanceof g ? this.doc.dict(n?.get(e.value)) : void 0;
1117
+ r.font = a ? this.reader.font(a) : void 0, r.fontSize = i(1);
1118
+ break;
1119
+ }
1120
+ case "Tc":
1121
+ r.charSpacing = i(0);
1122
+ break;
1123
+ case "Tw":
1124
+ r.wordSpacing = i(0);
1125
+ break;
1126
+ case "Tz":
1127
+ r.scale = i(0) / 100;
1128
+ break;
1129
+ case "TL":
1130
+ r.leading = i(0);
1131
+ break;
1132
+ case "Ts":
1133
+ r.rise = i(0);
1134
+ break;
1135
+ case "Tr":
1136
+ r.renderMode = i(0);
1137
+ break;
1138
+ case "Td":
1139
+ this.moveLine(i(0), i(1));
1140
+ break;
1141
+ case "TD":
1142
+ r.leading = -i(1), this.moveLine(i(0), i(1));
1143
+ break;
1144
+ case "Tm":
1145
+ this.lineMatrix = [
1146
+ i(0),
1147
+ i(1),
1148
+ i(2),
1149
+ i(3),
1150
+ i(4),
1151
+ i(5)
1152
+ ], this.textMatrix = this.lineMatrix;
1153
+ break;
1154
+ case "T*":
1155
+ this.moveLine(0, -r.leading);
1156
+ break;
1157
+ case "Tj":
1158
+ this.show(t[0]);
1159
+ break;
1160
+ case "'":
1161
+ this.moveLine(0, -r.leading), this.show(t[0]);
1162
+ break;
1163
+ case "\"":
1164
+ r.wordSpacing = i(0), r.charSpacing = i(1), this.moveLine(0, -r.leading), this.show(t[2]);
1165
+ break;
1166
+ case "TJ":
1167
+ for (let e of Array.isArray(t[0]) ? t[0] : []) typeof e == "number" ? this.advance(-e / 1e3 * r.fontSize * r.scale) : this.show(e);
1168
+ break;
1169
+ case "g":
1170
+ case "rg":
1171
+ case "k":
1172
+ r.color = be(t.filter((e) => typeof e == "number"));
1173
+ break;
1174
+ case "sc":
1175
+ case "scn": {
1176
+ let e = t.filter((e) => typeof e == "number");
1177
+ (e.length === 1 || e.length === 3 || e.length === 4) && (r.color = be(e));
1178
+ break;
1179
+ }
1180
+ case "Do":
1181
+ this.drawXObject(t[0], n);
1182
+ break;
1183
+ case "re": {
1184
+ let [e, t, n, a] = [
1185
+ i(0),
1186
+ i(1),
1187
+ i(2),
1188
+ i(3)
1189
+ ], o = [
1190
+ [e, t],
1191
+ [e + n, t],
1192
+ [e, t + a],
1193
+ [e + n, t + a]
1194
+ ];
1195
+ this.path.push(Te(o.map(([e, t]) => L(r.ctm, e, t))));
1196
+ break;
1197
+ }
1198
+ case "m":
1199
+ this.point = L(r.ctm, i(0), i(1));
1200
+ break;
1201
+ case "l": {
1202
+ let e = L(r.ctm, i(0), i(1));
1203
+ this.path.push(Te([this.point, e])), this.point = e;
1204
+ break;
1205
+ }
1206
+ case "c":
1207
+ this.point = L(r.ctm, i(4), i(5));
1208
+ break;
1209
+ case "v":
1210
+ case "y":
1211
+ this.point = L(r.ctm, i(2), i(3));
1212
+ break;
1213
+ case "n":
1214
+ this.path = [];
1215
+ break;
1216
+ default: we.has(e) && this.paintPath(e);
1217
+ }
1218
+ }
1219
+ paintPath(e) {
1220
+ let t = e !== "f" && e !== "F" && e !== "f*";
1221
+ for (let e of this.path) {
1222
+ let n = Math.min(e.width, e.height) <= Ce;
1223
+ if ((n || t) && Math.max(e.width, e.height) >= z / 2) {
1224
+ if (n) this.content.rules.push(e);
1225
+ else {
1226
+ let { x: t, y: n, width: r, height: i } = e;
1227
+ this.content.rules.push({
1228
+ x: t,
1229
+ y: n,
1230
+ width: r,
1231
+ height: 0
1232
+ }, {
1233
+ x: t,
1234
+ y: n + i,
1235
+ width: r,
1236
+ height: 0
1237
+ }, {
1238
+ x: t,
1239
+ y: n,
1240
+ width: 0,
1241
+ height: i
1242
+ }, {
1243
+ x: t + r,
1244
+ y: n,
1245
+ width: 0,
1246
+ height: i
1247
+ });
1248
+ }
1249
+ }
1250
+ }
1251
+ this.path = [];
1252
+ }
1253
+ moveLine(e, t) {
1254
+ this.lineMatrix = I([
1255
+ 1,
1256
+ 0,
1257
+ 0,
1258
+ 1,
1259
+ e,
1260
+ t
1261
+ ], this.lineMatrix), this.textMatrix = this.lineMatrix;
1262
+ }
1263
+ advance(e) {
1264
+ this.textMatrix = I([
1265
+ 1,
1266
+ 0,
1267
+ 0,
1268
+ 1,
1269
+ e,
1270
+ 0
1271
+ ], this.textMatrix);
1272
+ }
1273
+ show(e) {
1274
+ let { state: t } = this, n = t.font;
1275
+ if (n && e instanceof Uint8Array) for (let r of n.decode(e)) {
1276
+ let e = I(this.textMatrix, t.ctm), i = I([
1277
+ t.fontSize * t.scale,
1278
+ 0,
1279
+ 0,
1280
+ t.fontSize,
1281
+ 0,
1282
+ t.rise
1283
+ ], e), [a, o] = L(i, 0, 0), s = Math.hypot(i[2], i[3]) * n.sizeScale, c = i[0] > 0 && Math.abs(i[1]) < i[0] * .1, l = (r.width / 1e3 * t.fontSize + t.charSpacing + (r.wordSpace ? t.wordSpacing : 0)) * t.scale;
1284
+ r.text && c && s > .5 && this.addGlyph(r.text, a, o, l * Math.hypot(e[0], e[1]), s, n), this.advance(l);
1285
+ }
1286
+ }
1287
+ addGlyph(e, t, n, r, i, a) {
1288
+ let { state: o } = this, s = this.span, c = s && Math.abs(s.y - n) < i * .2 && Math.abs(s.size - i) < .5 && Math.abs(this.spanEnd - t) < i * Se && s.bold === (a.bold || o.renderMode === 2) && s.italic === a.italic && s.color === o.color;
1289
+ s && c ? (s.text += e, s.width = t + r - s.x) : (this.flush(), this.span = {
1290
+ text: e,
1291
+ x: t,
1292
+ y: n,
1293
+ width: r,
1294
+ size: i,
1295
+ bold: a.bold || o.renderMode === 2,
1296
+ italic: a.italic,
1297
+ family: a.family,
1298
+ color: o.color
1299
+ }), this.spanEnd = t + r;
1300
+ }
1301
+ flush() {
1302
+ this.span?.text.trim() && this.content.spans.push(this.span), this.span = null;
1303
+ }
1304
+ drawXObject(e, t) {
1305
+ let { doc: n } = this;
1306
+ if (!(e instanceof g)) return;
1307
+ let r = n.stream(n.dict(this.resources.get("XObject"))?.get(e.value));
1308
+ if (!r) return;
1309
+ let i = n.name(r.dict.get("Subtype"));
1310
+ i === "Image" ? this.placeImage(r) : i === "Form" && t < xe && this.runForm(r, t);
1311
+ }
1312
+ runForm(e, t) {
1313
+ let { doc: n } = this, r = { ...this.state }, i = this.resources, a = [this.textMatrix, this.lineMatrix], o = n.numbers(e.dict.get("Matrix"));
1314
+ o?.length === 6 && (this.state.ctm = I(o, this.state.ctm)), this.resources = n.dict(e.dict.get("Resources")) ?? this.resources, this.execute(n.bytes(e), t + 1), this.state = r, this.resources = i, [this.textMatrix, this.lineMatrix] = a;
1315
+ }
1316
+ placeImage(e) {
1317
+ let { ctm: t } = this.state, n = [
1318
+ L(t, 0, 0),
1319
+ L(t, 1, 0),
1320
+ L(t, 0, 1),
1321
+ L(t, 1, 1)
1322
+ ], r = n.map(([e]) => e), i = n.map(([, e]) => e), a = Math.min(...r), o = Math.min(...i), s = Math.max(...r) - a, c = Math.max(...i) - o;
1323
+ if (s < z || c < z) return;
1324
+ let l = this.reader.image(e);
1325
+ l && this.content.images.push({
1326
+ src: l,
1327
+ x: a,
1328
+ y: o,
1329
+ width: s,
1330
+ height: c
1331
+ });
1332
+ }
1333
+ }, Oe = (e) => e === void 0 || e === 32 || e === 10 || e === 13 || e === 9, ke = (e, t, n) => {
1334
+ let r = e.indexOf(t, n);
1335
+ for (; r >= 0 && !(Oe(e.data[r - 1]) && Oe(e.data[r + 2]));) r = e.indexOf(t, r + 2);
1336
+ return r;
1337
+ }, Ae = (e) => {
1338
+ let t = ke(e, "ID", e.position), n = t < 0 ? -1 : ke(e, "EI", t + 3);
1339
+ e.position = n < 0 ? e.data.length : n + 2;
1340
+ }, je = 15, Me = [
1341
+ 3,
1342
+ 4,
1343
+ 5,
1344
+ 6,
1345
+ 7,
1346
+ 8,
1347
+ 9,
1348
+ 10,
1349
+ 11,
1350
+ 13,
1351
+ 15,
1352
+ 17,
1353
+ 19,
1354
+ 23,
1355
+ 27,
1356
+ 31,
1357
+ 35,
1358
+ 43,
1359
+ 51,
1360
+ 59,
1361
+ 67,
1362
+ 83,
1363
+ 99,
1364
+ 115,
1365
+ 131,
1366
+ 163,
1367
+ 195,
1368
+ 227,
1369
+ 258
1370
+ ], Ne = [
1371
+ 0,
1372
+ 0,
1373
+ 0,
1374
+ 0,
1375
+ 0,
1376
+ 0,
1377
+ 0,
1378
+ 0,
1379
+ 1,
1380
+ 1,
1381
+ 1,
1382
+ 1,
1383
+ 2,
1384
+ 2,
1385
+ 2,
1386
+ 2,
1387
+ 3,
1388
+ 3,
1389
+ 3,
1390
+ 3,
1391
+ 4,
1392
+ 4,
1393
+ 4,
1394
+ 4,
1395
+ 5,
1396
+ 5,
1397
+ 5,
1398
+ 5,
1399
+ 0
1400
+ ], Pe = [
1401
+ 1,
1402
+ 2,
1403
+ 3,
1404
+ 4,
1405
+ 5,
1406
+ 7,
1407
+ 9,
1408
+ 13,
1409
+ 17,
1410
+ 25,
1411
+ 33,
1412
+ 49,
1413
+ 65,
1414
+ 97,
1415
+ 129,
1416
+ 193,
1417
+ 257,
1418
+ 385,
1419
+ 513,
1420
+ 769,
1421
+ 1025,
1422
+ 1537,
1423
+ 2049,
1424
+ 3073,
1425
+ 4097,
1426
+ 6145,
1427
+ 8193,
1428
+ 12289,
1429
+ 16385,
1430
+ 24577
1431
+ ], Fe = [
1432
+ 0,
1433
+ 0,
1434
+ 0,
1435
+ 0,
1436
+ 1,
1437
+ 1,
1438
+ 2,
1439
+ 2,
1440
+ 3,
1441
+ 3,
1442
+ 4,
1443
+ 4,
1444
+ 5,
1445
+ 5,
1446
+ 6,
1447
+ 6,
1448
+ 7,
1449
+ 7,
1450
+ 8,
1451
+ 8,
1452
+ 9,
1453
+ 9,
1454
+ 10,
1455
+ 10,
1456
+ 11,
1457
+ 11,
1458
+ 12,
1459
+ 12,
1460
+ 13,
1461
+ 13
1462
+ ], Ie = [
1463
+ 16,
1464
+ 17,
1465
+ 18,
1466
+ 0,
1467
+ 8,
1468
+ 7,
1469
+ 9,
1470
+ 6,
1471
+ 10,
1472
+ 5,
1473
+ 11,
1474
+ 4,
1475
+ 12,
1476
+ 3,
1477
+ 13,
1478
+ 2,
1479
+ 14,
1480
+ 1,
1481
+ 15
1482
+ ], B = (e) => {
1483
+ let t = /* @__PURE__ */ new Uint16Array(16);
1484
+ for (let n = 0; n < e.length; n += 1) {
1485
+ let r = e[n];
1486
+ t[r] = t[r] + 1;
1487
+ }
1488
+ t[0] = 0;
1489
+ let n = /* @__PURE__ */ new Uint16Array(16);
1490
+ for (let e = 1; e < je; e += 1) n[e + 1] = n[e] + t[e];
1491
+ let r = new Uint16Array(e.length);
1492
+ for (let t = 0; t < e.length; t += 1) {
1493
+ let i = e[t];
1494
+ if (!i) continue;
1495
+ let a = n[i];
1496
+ r[a] = t, n[i] = a + 1;
1497
+ }
1498
+ return {
1499
+ counts: t,
1500
+ symbols: r
1501
+ };
1502
+ }, Le = B(Array.from({ length: 288 }, (e, t) => t < 144 ? 8 : t < 256 ? 9 : t < 280 ? 7 : 8)), Re = B(Array(30).fill(5)), V = class extends Error {}, ze = class {
1503
+ input;
1504
+ position;
1505
+ bitBuffer = 0;
1506
+ bitCount = 0;
1507
+ output;
1508
+ length = 0;
1509
+ constructor(e, t) {
1510
+ this.input = e, this.position = t, this.output = new Uint8Array(Math.max(1024, e.length * 4));
1511
+ }
1512
+ run() {
1513
+ try {
1514
+ let e = 0;
1515
+ for (; !e;) {
1516
+ e = this.bits(1);
1517
+ let t = this.bits(2);
1518
+ if (t === 0) this.stored();
1519
+ else if (t === 1) this.codes(Le, Re);
1520
+ else if (t === 2) this.dynamic();
1521
+ else throw new V();
1522
+ }
1523
+ } catch (e) {
1524
+ if (!(e instanceof V)) throw e;
1525
+ }
1526
+ return this.output.subarray(0, this.length);
1527
+ }
1528
+ bits(e) {
1529
+ for (; this.bitCount < e;) {
1530
+ if (this.position >= this.input.length) throw new V();
1531
+ this.bitBuffer |= this.input[this.position++] << this.bitCount, this.bitCount += 8;
1532
+ }
1533
+ let t = this.bitBuffer & (1 << e) - 1;
1534
+ return this.bitBuffer >>>= e, this.bitCount -= e, t;
1535
+ }
1536
+ ensure(e) {
1537
+ if (this.length + e <= this.output.length) return;
1538
+ let t = this.output.length * 2;
1539
+ for (; t < this.length + e;) t *= 2;
1540
+ let n = new Uint8Array(t);
1541
+ n.set(this.output.subarray(0, this.length)), this.output = n;
1542
+ }
1543
+ stored() {
1544
+ if (this.bitBuffer = 0, this.bitCount = 0, this.position + 4 > this.input.length) throw new V();
1545
+ let e = this.input[this.position] | this.input[this.position + 1] << 8;
1546
+ this.position += 4;
1547
+ let t = Math.min(e, this.input.length - this.position);
1548
+ if (this.ensure(t), this.output.set(this.input.subarray(this.position, this.position + t), this.length), this.length += t, this.position += t, t < e) throw new V();
1549
+ }
1550
+ decode(e) {
1551
+ let t = 0, n = 0, r = 0;
1552
+ for (let i = 1; i <= je; i += 1) {
1553
+ t |= this.bits(1);
1554
+ let a = e.counts[i];
1555
+ if (t - a < n) return e.symbols[r + (t - n)];
1556
+ r += a, n = n + a << 1, t <<= 1;
1557
+ }
1558
+ throw new V();
1559
+ }
1560
+ codes(e, t) {
1561
+ for (;;) {
1562
+ let n = this.decode(e);
1563
+ if (n < 256) {
1564
+ this.ensure(1), this.output[this.length++] = n;
1565
+ continue;
1566
+ }
1567
+ if (n === 256) return;
1568
+ let r = n - 257;
1569
+ if (r >= 29) throw new V();
1570
+ let i = Me[r] + this.bits(Ne[r]), a = this.decode(t);
1571
+ if (a >= 30) throw new V();
1572
+ let o = Pe[a] + this.bits(Fe[a]);
1573
+ if (o > this.length) throw new V();
1574
+ this.ensure(i);
1575
+ for (let e = 0; e < i; e += 1) this.output[this.length] = this.output[this.length - o], this.length += 1;
1576
+ }
1577
+ }
1578
+ dynamic() {
1579
+ let e = this.bits(5) + 257, t = this.bits(5) + 1, n = this.bits(4) + 4, r = /* @__PURE__ */ new Uint8Array(19);
1580
+ for (let e = 0; e < n; e += 1) r[Ie[e]] = this.bits(3);
1581
+ let i = B(r), a = new Uint8Array(e + t);
1582
+ for (let e = 0; e < a.length;) {
1583
+ let t = this.decode(i);
1584
+ if (t < 16) {
1585
+ a[e++] = t;
1586
+ continue;
1587
+ }
1588
+ let n, r = 0;
1589
+ if (t === 16) {
1590
+ if (e === 0) throw new V();
1591
+ r = a[e - 1], n = 3 + this.bits(2);
1592
+ } else n = t === 17 ? 3 + this.bits(3) : 11 + this.bits(7);
1593
+ if (e + n > a.length) throw new V();
1594
+ a.fill(r, e, e + n), e += n;
1595
+ }
1596
+ this.codes(B(a.subarray(0, e)), B(a.subarray(e)));
1597
+ }
1598
+ }, Be = (e) => {
1599
+ let t = e[0] ?? 0, n = e[1] ?? 0;
1600
+ return (t & 15) == 8 && (t << 8 | n) % 31 == 0;
1601
+ }, Ve = (e) => new ze(e, Be(e) ? 2 : 0).run(), He = /* @__PURE__ */ new Set([
1602
+ "DCTDecode",
1603
+ "DCT",
1604
+ "JPXDecode",
1605
+ "CCITTFaxDecode",
1606
+ "CCF",
1607
+ "JBIG2Decode"
1608
+ ]), Ue = {
1609
+ predictor: 1,
1610
+ colors: 1,
1611
+ bitsPerComponent: 8,
1612
+ columns: 1,
1613
+ earlyChange: 1
1614
+ }, We = (e) => e === 32 || e === 10 || e === 13 || e === 9 || e === 12 || e === 0, Ge = (e) => e >= 48 && e <= 57 ? e - 48 : e >= 65 && e <= 70 ? e - 55 : e >= 97 && e <= 102 ? e - 87 : -1, Ke = (e) => {
1615
+ let t = new Uint8Array(e.length + 1 >> 1), n = 0, r = -1;
1616
+ for (let i of e) {
1617
+ if (i === 62) break;
1618
+ let e = Ge(i);
1619
+ e < 0 || (r < 0 ? r = e : (t[n++] = r << 4 | e, r = -1));
1620
+ }
1621
+ return r >= 0 && (t[n++] = r << 4), t.subarray(0, n);
1622
+ }, qe = (e) => {
1623
+ let t = new Uint8Array(Math.ceil(e.length * 4 / 5) + 4), n = 0, r = 0, i = 0, a = (e) => {
1624
+ for (let i = 3; i >= 4 - e; --i) t[n++] = r >>> i * 8 & 255;
1625
+ };
1626
+ for (let o = 0; o < e.length; o += 1) {
1627
+ let s = e[o];
1628
+ if (s === 126) break;
1629
+ if (!We(s)) {
1630
+ if (s === 122 && i === 0) {
1631
+ t.fill(0, n, n + 4), n += 4;
1632
+ continue;
1633
+ }
1634
+ s < 33 || s > 117 || (r = r * 85 + (s - 33), i += 1, i === 5 && (a(4), r = 0, i = 0));
1635
+ }
1636
+ }
1637
+ if (i > 1) {
1638
+ for (let e = i; e < 5; e += 1) r = r * 85 + 84;
1639
+ a(i - 1);
1640
+ }
1641
+ return t.subarray(0, n);
1642
+ }, Je = (e) => {
1643
+ let t = [];
1644
+ for (let n = 0; n < e.length;) {
1645
+ let r = e[n++];
1646
+ if (r === 128) break;
1647
+ if (r < 128) for (let i = 0; i <= r && n < e.length; i += 1) t.push(e[n++]);
1648
+ else {
1649
+ let i = e[n++] ?? 0;
1650
+ for (let e = 0; e < 257 - r; e += 1) t.push(i);
1651
+ }
1652
+ }
1653
+ return Uint8Array.from(t);
1654
+ }, Ye = (e, t) => {
1655
+ let n = [], r = [], i = () => {
1656
+ r = Array.from({ length: 258 }, (e, t) => t < 256 ? [t] : []);
1657
+ };
1658
+ i();
1659
+ let a = 9, o = 0, s = 0, c = null;
1660
+ for (let l of e) for (o = o << 8 | l, s += 8; s >= a;) {
1661
+ let e = o >>> s - a & (1 << a) - 1;
1662
+ if (s -= a, e === 256) {
1663
+ i(), a = 9, c = null;
1664
+ continue;
1665
+ }
1666
+ if (e === 257) return Uint8Array.from(n);
1667
+ let l = r[e] ?? (c && e === r.length ? [...c, c[0]] : void 0);
1668
+ if (!l) return Uint8Array.from(n);
1669
+ for (let e of l) n.push(e);
1670
+ c && r.push([...c, l[0]]), c = l, r.length + t >= 1 << a && a < 12 && (a += 1);
1671
+ }
1672
+ return Uint8Array.from(n);
1673
+ }, Xe = (e, t, n) => {
1674
+ let r = e + t - n, i = Math.abs(r - e), a = Math.abs(r - t), o = Math.abs(r - n);
1675
+ return i <= a && i <= o ? e : a <= o ? t : n;
1676
+ }, H = (e, t) => {
1677
+ let { predictor: n, colors: r, bitsPerComponent: i, columns: a } = t;
1678
+ if (n < 2) return e;
1679
+ let o = Math.max(1, Math.ceil(r * i / 8)), s = Math.ceil(r * i * a / 8);
1680
+ if (n === 2) {
1681
+ if (i !== 8) return e;
1682
+ let t = e.slice();
1683
+ for (let e = 0; e + s <= t.length; e += s) for (let n = o; n < s; n += 1) t[e + n] = t[e + n] + t[e + n - o] & 255;
1684
+ return t;
1685
+ }
1686
+ let c = Math.floor(e.length / (s + 1)), l = new Uint8Array(c * s);
1687
+ for (let t = 0; t < c; t += 1) {
1688
+ let n = t * (s + 1), r = t * s, i = e[n];
1689
+ for (let a = 0; a < s; a += 1) {
1690
+ let c = e[n + 1 + a], u = a >= o ? l[r + a - o] : 0, d = t > 0 ? l[r - s + a] : 0, f = t > 0 && a >= o ? l[r - s + a - o] : 0, p = c;
1691
+ i === 1 ? p = c + u : i === 2 ? p = c + d : i === 3 ? p = c + (u + d >> 1) : i === 4 && (p = c + Xe(u, d, f)), l[r + a] = p & 255;
1692
+ }
1693
+ }
1694
+ return l;
1695
+ }, Ze = (e, t, n) => {
1696
+ switch (e) {
1697
+ case "FlateDecode":
1698
+ case "Fl": return H(Ve(t), n);
1699
+ case "LZWDecode":
1700
+ case "LZW": return H(Ye(t, n.earlyChange), n);
1701
+ case "ASCIIHexDecode":
1702
+ case "AHx": return Ke(t);
1703
+ case "ASCII85Decode":
1704
+ case "A85": return qe(t);
1705
+ case "RunLengthDecode":
1706
+ case "RL": return Je(t);
1707
+ default: throw Error(`Unsupported PDF filter: ${e}`);
1708
+ }
1709
+ }, Qe = 64, $e = 2048, et = class {
1710
+ data;
1711
+ xref = /* @__PURE__ */ new Map();
1712
+ cache = /* @__PURE__ */ new Map();
1713
+ loading = /* @__PURE__ */ new Set();
1714
+ objectStreams = /* @__PURE__ */ new Map();
1715
+ trailer = new y();
1716
+ repaired = !1;
1717
+ constructor(e) {
1718
+ if (this.data = e, A(e, 0, Math.min(1024, e.length)).indexOf("%PDF-") < 0) throw new n("invalid");
1719
+ try {
1720
+ this.readXrefChain();
1721
+ } catch {
1722
+ this.xref.clear();
1723
+ }
1724
+ if (this.get(this.trailer.get("Root")) instanceof y || this.rebuildXref(), !(this.get(this.trailer.get("Root")) instanceof y)) throw new n("invalid");
1725
+ if (this.trailer.has("Encrypt")) throw new n("encrypted");
1726
+ }
1727
+ get(e) {
1728
+ return e instanceof _ ? this.object(e.num) : e;
1729
+ }
1730
+ dict(e) {
1731
+ let t = this.get(e);
1732
+ return t instanceof y ? t : t instanceof b ? t.dict : void 0;
1733
+ }
1734
+ number(e) {
1735
+ let t = this.get(e);
1736
+ return typeof t == "number" ? t : void 0;
1737
+ }
1738
+ name(e) {
1739
+ let t = this.get(e);
1740
+ return t instanceof g ? t.value : void 0;
1741
+ }
1742
+ array(e) {
1743
+ let t = this.get(e);
1744
+ return Array.isArray(t) ? t : void 0;
1745
+ }
1746
+ numbers(e) {
1747
+ return this.array(e)?.map((e) => this.number(e) ?? 0);
1748
+ }
1749
+ stream(e) {
1750
+ let t = this.get(e);
1751
+ return t instanceof b ? t : void 0;
1752
+ }
1753
+ filters(e) {
1754
+ let t = this.get(e.dict.get("Filter"));
1755
+ return (Array.isArray(t) ? t : t ? [t] : []).map((e) => this.name(e) ?? "").filter(Boolean);
1756
+ }
1757
+ decode(e) {
1758
+ let t = this.filters(e), n = this.get(e.dict.get("DecodeParms") ?? e.dict.get("DP")), r = Array.isArray(n) ? n : [n], i = e.raw;
1759
+ for (let e = 0; e < t.length; e += 1) {
1760
+ let n = t[e];
1761
+ if (He.has(n)) return {
1762
+ data: i,
1763
+ imageFilter: n
1764
+ };
1765
+ i = Ze(n, i, this.predictor(r[e] ?? r[0]));
1766
+ }
1767
+ return { data: i };
1768
+ }
1769
+ bytes(e) {
1770
+ let t = this.stream(e);
1771
+ if (!t) return /* @__PURE__ */ new Uint8Array();
1772
+ try {
1773
+ return this.decode(t).data;
1774
+ } catch {
1775
+ return /* @__PURE__ */ new Uint8Array();
1776
+ }
1777
+ }
1778
+ predictor(e) {
1779
+ let t = this.dict(e);
1780
+ if (!t) return Ue;
1781
+ let n = (e, n) => this.number(t.get(e)) ?? n;
1782
+ return {
1783
+ predictor: n("Predictor", 1),
1784
+ colors: n("Colors", 1),
1785
+ bitsPerComponent: n("BitsPerComponent", 8),
1786
+ columns: n("Columns", 1),
1787
+ earlyChange: n("EarlyChange", 1)
1788
+ };
1789
+ }
1790
+ pages() {
1791
+ let e = [], t = this.dict(this.trailer.get("Root")), n = /* @__PURE__ */ new Set(), r = (t, i, a) => {
1792
+ if (!t || n.has(t) || a > Qe) return;
1793
+ n.add(t);
1794
+ let o = this.dict(t.get("Resources")) ?? i.resources, s = this.box(t.get("CropBox")) ?? this.box(t.get("MediaBox")) ?? i.box, c = this.number(t.get("Rotate")) ?? i.rotate, l = this.array(t.get("Kids"));
1795
+ if (l && this.name(t.get("Type")) !== "Page") {
1796
+ for (let e of l) r(this.dict(e), {
1797
+ resources: o,
1798
+ box: s,
1799
+ rotate: c
1800
+ }, a + 1);
1801
+ return;
1802
+ }
1803
+ e.push({
1804
+ dict: t,
1805
+ resources: o ?? new y(),
1806
+ box: s ?? [
1807
+ 0,
1808
+ 0,
1809
+ 595.28,
1810
+ 841.89
1811
+ ],
1812
+ rotate: ((c ?? 0) % 360 + 360) % 360
1813
+ });
1814
+ };
1815
+ return r(this.dict(t?.get("Pages")), {}, 0), e;
1816
+ }
1817
+ box(e) {
1818
+ let t = this.numbers(e);
1819
+ if (!t || t.length < 4) return;
1820
+ let [n, r, i, a] = t;
1821
+ if (n !== i && r !== a) return [
1822
+ Math.min(n, i),
1823
+ Math.min(r, a),
1824
+ Math.max(n, i),
1825
+ Math.max(r, a)
1826
+ ];
1827
+ }
1828
+ contents(e) {
1829
+ let t = this.get(e.dict.get("Contents")), n = (Array.isArray(t) ? t : [t]).map((e) => this.bytes(e)), r = n.reduce((e, t) => e + t.length + 1, 0), i = new Uint8Array(r), a = 0;
1830
+ for (let e of n) i.set(e, a), i[a + e.length] = 10, a += e.length + 1;
1831
+ return i;
1832
+ }
1833
+ object(e) {
1834
+ if (this.cache.has(e)) return this.cache.get(e);
1835
+ let t = this.xref.get(e);
1836
+ if (!t || this.loading.has(e)) return null;
1837
+ this.loading.add(e);
1838
+ let n;
1839
+ try {
1840
+ n = t.kind === "offset" ? this.objectAt(t.offset, e) : this.compressedObject(t);
1841
+ } catch {
1842
+ n = null;
1843
+ } finally {
1844
+ this.loading.delete(e);
1845
+ }
1846
+ return n === void 0 && !this.repaired ? (this.rebuildXref(), this.object(e)) : (this.cache.set(e, n ?? null), n ?? null);
1847
+ }
1848
+ parserAt(e) {
1849
+ return new k(new D(this.data, e), (e) => this.number(e));
1850
+ }
1851
+ objectAt(e, t) {
1852
+ let n = this.parserAt(e), r = n.next(), i = n.next(), a = n.next();
1853
+ if (typeof r == "number" && typeof i == "number" && O(a, "obj") && (t === void 0 || r === t)) return n.value();
1854
+ }
1855
+ compressedObject(e) {
1856
+ let t = this.objectStreams.get(e.stream);
1857
+ if (!t) {
1858
+ let n = this.stream(this.object(e.stream));
1859
+ if (!n) return null;
1860
+ let r = this.decode(n).data, i = this.number(n.dict.get("N")) ?? 0, a = this.number(n.dict.get("First")) ?? 0, o = new k(new D(r)), s = [];
1861
+ for (let e = 0; e < i; e += 1) o.next(), s.push(Number(o.next()));
1862
+ t = {
1863
+ offsets: s,
1864
+ data: r,
1865
+ first: a
1866
+ }, this.objectStreams.set(e.stream, t);
1867
+ }
1868
+ let n = t.offsets[e.index];
1869
+ return n === void 0 ? null : new k(new D(t.data, t.first + n)).value();
1870
+ }
1871
+ readXrefChain() {
1872
+ let e = A(this.data, Math.max(0, this.data.length - $e)), t = /startxref\s+(\d+)/g, n;
1873
+ for (let r = t.exec(e); r; r = t.exec(e)) n = Number(r[1]);
1874
+ let r = /* @__PURE__ */ new Set(), i = !0;
1875
+ for (; n !== void 0 && !r.has(n) && n < this.data.length;) {
1876
+ r.add(n);
1877
+ let e = this.readXrefSection(n);
1878
+ if (!e) break;
1879
+ i && (this.trailer = e), i = !1;
1880
+ let t = this.number(e.get("XRefStm"));
1881
+ t !== void 0 && !r.has(t) && this.readXrefSection(t), n = this.number(e.get("Prev"));
1882
+ }
1883
+ }
1884
+ readXrefSection(e) {
1885
+ let t = new D(this.data, e), n = t.position;
1886
+ if (O(t.next(), "xref")) return this.readXrefTable(t);
1887
+ t.position = n;
1888
+ let r = this.stream(this.objectAt(e));
1889
+ return r ? this.readXrefStream(r) : void 0;
1890
+ }
1891
+ readXrefTable(e) {
1892
+ let t = new k(e);
1893
+ for (;;) {
1894
+ let e = t.next();
1895
+ if (O(e, "trailer")) break;
1896
+ let n = t.next();
1897
+ if (typeof e != "number" || typeof n != "number") return;
1898
+ for (let r = 0; r < n; r += 1) {
1899
+ let n = t.next();
1900
+ t.next();
1901
+ let i = t.next(), a = e + r;
1902
+ typeof n != "number" || this.xref.has(a) || O(i, "n") && n > 0 && this.xref.set(a, {
1903
+ kind: "offset",
1904
+ offset: n
1905
+ });
1906
+ }
1907
+ }
1908
+ let n = t.value();
1909
+ return n instanceof y ? n : void 0;
1910
+ }
1911
+ readXrefStream(e) {
1912
+ let t = this.numbers(e.dict.get("W")) ?? [
1913
+ 1,
1914
+ 2,
1915
+ 1
1916
+ ], n = this.number(e.dict.get("Size")) ?? 0, r = this.numbers(e.dict.get("Index")) ?? [0, n], i = this.decode(e).data, a = t.reduce((e, t) => e + t, 0), o = (e, n, r) => {
1917
+ let o = t[n] ?? 0;
1918
+ if (!o) return r;
1919
+ let s = e * a;
1920
+ for (let e = 0; e < n; e += 1) s += t[e] ?? 0;
1921
+ let c = 0;
1922
+ for (let e = 0; e < o; e += 1) c = c * 256 + (i[s + e] ?? 0);
1923
+ return c;
1924
+ }, s = 0;
1925
+ for (let e = 0; e + 1 < r.length; e += 2) {
1926
+ let t = r[e], n = r[e + 1];
1927
+ for (let e = 0; e < n && (s + 1) * a <= i.length; e += 1, s += 1) {
1928
+ let n = t + e;
1929
+ if (this.xref.has(n)) continue;
1930
+ let r = o(s, 0, 1);
1931
+ r === 1 ? this.xref.set(n, {
1932
+ kind: "offset",
1933
+ offset: o(s, 1, 0)
1934
+ }) : r === 2 && this.xref.set(n, {
1935
+ kind: "compressed",
1936
+ stream: o(s, 1, 0),
1937
+ index: o(s, 2, 0)
1938
+ });
1939
+ }
1940
+ }
1941
+ return e.dict;
1942
+ }
1943
+ rebuildXref() {
1944
+ this.repaired = !0, this.xref.clear(), this.cache.clear(), this.objectStreams.clear();
1945
+ let e = new TextDecoder("latin1").decode(this.data), t = /(\d+)\s+(\d+)\s+obj\b/g;
1946
+ for (let n = t.exec(e); n; n = t.exec(e)) this.xref.set(Number(n[1]), {
1947
+ kind: "offset",
1948
+ offset: n.index
1949
+ });
1950
+ let n;
1951
+ for (let [e, t] of this.xref) {
1952
+ if (t.kind !== "offset") continue;
1953
+ let r = this.object(e);
1954
+ if (!(r instanceof b)) continue;
1955
+ let i = this.name(r.dict.get("Type"));
1956
+ i === "ObjStm" && this.indexObjectStream(e, r), i === "XRef" && r.dict.has("Root") && (n = r.dict);
1957
+ }
1958
+ for (let t = e.lastIndexOf("trailer"); t >= 0; t = e.lastIndexOf("trailer", t - 1)) {
1959
+ let e = this.parserAt(t + 7).value();
1960
+ if (e instanceof y && e.has("Root")) {
1961
+ n = e;
1962
+ break;
1963
+ }
1964
+ }
1965
+ if (!n) for (let e of this.xref.keys()) {
1966
+ let t = this.object(e);
1967
+ t instanceof y && this.name(t.get("Type")) === "Catalog" && (n = new y(), n.entries.set("Root", new _(e, 0)));
1968
+ }
1969
+ this.trailer = n ?? new y();
1970
+ }
1971
+ indexObjectStream(e, t) {
1972
+ let n = this.number(t.dict.get("N")) ?? 0, r = new k(new D(this.bytes(t)));
1973
+ for (let t = 0; t < n; t += 1) {
1974
+ let n = r.next();
1975
+ if (r.next(), n === T) return;
1976
+ typeof n == "number" && !this.xref.has(n) && this.xref.set(n, {
1977
+ kind: "compressed",
1978
+ stream: e,
1979
+ index: t
1980
+ });
1981
+ }
1982
+ }
1983
+ }, tt = 96 / 72, U = 25.4 / 72, nt = 12, rt = "Times New Roman", W = 3, it = .12, at = 1.6, ot = 8, st = .75, ct = (e) => e.replace(/[&<>"]/g, (e) => ({
1984
+ "&": "&amp;",
1985
+ "<": "&lt;",
1986
+ ">": "&gt;",
1987
+ "\"": "&quot;"
1988
+ })[e] ?? e), G = (e, t = 1) => Math.round(e / t) * t, lt = (e) => {
1989
+ if (!e.length) return;
1990
+ let t = [...e].sort((e, t) => e - t);
1991
+ return t[Math.floor(t.length / 2)];
1992
+ }, K = (e, t) => {
1993
+ if (!e.length) return;
1994
+ let n = [...e].sort((e, t) => e - t);
1995
+ return n[Math.min(n.length - 1, Math.floor(n.length * t))];
1996
+ }, q = (e) => {
1997
+ let t = /* @__PURE__ */ new Map();
1998
+ for (let [n, r] of e) t.set(n, (t.get(n) ?? 0) + r);
1999
+ let n;
2000
+ for (let [e, r] of t) (n === void 0 || r > (t.get(n) ?? 0)) && (n = e);
2001
+ return n;
2002
+ }, ut = (e, t) => e.size === t.size && e.bold === t.bold && e.italic === t.italic && e.family === t.family && e.color === t.color, J = (e, t) => {
2003
+ let n = e.at(-1);
2004
+ n && ut(n, t) ? n.text += t.text : e.push({ ...t });
2005
+ }, dt = (e) => ({
2006
+ text: e.text,
2007
+ size: G(e.size, .5),
2008
+ bold: e.bold,
2009
+ italic: e.italic,
2010
+ family: e.family,
2011
+ color: /^#[0-2][\da-f][0-2][\da-f][0-2][\da-f]$/i.test(e.color) ? "#000000" : e.color.toLowerCase()
2012
+ }), ft = (e, t) => {
2013
+ let n = [], r, i = -Infinity;
2014
+ for (let a of e) {
2015
+ let e = a.x - i, o = r !== void 0 && wt.test(r.text.trim());
2016
+ !r || e > Math.max(at * t, 12) && !o ? (r = {
2017
+ left: a.x,
2018
+ right: a.x + a.width,
2019
+ runs: [],
2020
+ text: ""
2021
+ }, n.push(r)) : e > t * .18 && !r.text.endsWith(" ") && !a.text.startsWith(" ") && (J(r.runs, {
2022
+ ...dt(a),
2023
+ text: " "
2024
+ }), r.text += " "), J(r.runs, dt(a)), r.text += a.text, r.right = Math.max(r.right, a.x + a.width), i = Math.max(i, a.x + a.width);
2025
+ }
2026
+ for (let e of n) e.text = e.text.replace(/\s+/g, " ").trim(), pt(e.runs);
2027
+ return n.filter((e) => e.text);
2028
+ }, pt = (e) => {
2029
+ for (let t of e) t.text = t.text.replace(/\s+/g, " ");
2030
+ let t = e[0];
2031
+ t && (t.text = t.text.replace(/^\s+/, ""));
2032
+ let n = e.at(-1);
2033
+ n && (n.text = n.text.replace(/\s+$/, ""));
2034
+ for (let t = e.length - 1; t >= 0; --t) e[t]?.text || e.splice(t, 1);
2035
+ }, mt = (e, t) => {
2036
+ let n = [...e.spans].sort((e, t) => e.y - t.y || e.x - t.x), r = [];
2037
+ for (let e of n) {
2038
+ let t = r.at(-1), n = t?.[0];
2039
+ t && n && Math.abs(e.y - n.y) < Math.min(e.size, n.size) * .45 ? t.push(e) : r.push([e]);
2040
+ }
2041
+ return r.map((e) => {
2042
+ e.sort((e, t) => e.x - t.x);
2043
+ let n = q(e.map((e) => [G(e.size, .5), e.text.length])) ?? 12, r = e.reduce((e, t) => e + (t.bold ? t.text.trim().length : 0), 0), i = e.reduce((e, t) => e + t.text.trim().length, 0), a = ft(e, n);
2044
+ return {
2045
+ page: t,
2046
+ baseline: q(e.map((e) => [G(e.y, .5), e.text.length])) ?? e[0].y,
2047
+ left: Math.min(...a.map((e) => e.left)),
2048
+ right: Math.max(...a.map((e) => e.right)),
2049
+ size: n,
2050
+ bold: r > i / 2,
2051
+ cells: a,
2052
+ text: a.map((e) => e.text).join(" ")
2053
+ };
2054
+ }).filter((e) => e.cells.length);
2055
+ }, ht = (e) => e.text.toLowerCase().replace(/\d+/g, "#").replace(/\s+/g, " "), gt = (e, t, n, r) => {
2056
+ let i = e.text.replace(/\d+/g, (e) => {
2057
+ let r = Number(e);
2058
+ return r === t ? "{page}" : r === n && n > 1 ? "{pages}" : e;
2059
+ });
2060
+ /^\d+$/.test(i) && (i = "{page}");
2061
+ let a = (e.left + e.right) / 2;
2062
+ return Math.abs(a - r / 2) < r * .1 ? {
2063
+ left: "",
2064
+ center: i,
2065
+ right: ""
2066
+ } : a < r / 2 ? {
2067
+ left: i,
2068
+ center: "",
2069
+ right: ""
2070
+ } : {
2071
+ left: "",
2072
+ center: "",
2073
+ right: i
2074
+ };
2075
+ }, _t = (e, t) => {
2076
+ let n = {};
2077
+ for (let r of ["header", "footer"]) {
2078
+ let i = e.map((e, n) => {
2079
+ let i = t[n]?.height ?? 842;
2080
+ return (r === "header" ? e.slice(0, 2) : e.slice(-2)).filter((e) => r === "header" ? e.baseline < i * it : e.baseline > i * .88);
2081
+ }), a = /* @__PURE__ */ new Map();
2082
+ for (let e of i) for (let t of new Set(e.map(ht))) a.set(t, (a.get(t) ?? 0) + 1);
2083
+ let o = e.length > 1 ? Math.max(2, Math.ceil(e.length / 2)) : 1, s = new Set([...a].filter(([t, n]) => n >= o && (e.length > 1 || /^[\s#\-–—.]*#[\s#\-–—.]*$/.test(t))).map(([e]) => e));
2084
+ s.size && e.forEach((a, o) => {
2085
+ let c = i[o]?.filter((e) => s.has(ht(e))) ?? [];
2086
+ if (c.length && !n[r]) {
2087
+ let i = c[0];
2088
+ n[r] = gt(i, o + 1, e.length, t[o]?.width ?? 595);
2089
+ }
2090
+ e[o] = a.filter((e) => !c.includes(e));
2091
+ });
2092
+ }
2093
+ return n;
2094
+ }, vt = (e, t) => e.findIndex((e) => Math.abs(e - t.left) <= ot), yt = (e, t) => e.cells.every((e) => {
2095
+ let n = vt(t, e), r = t[n + 1];
2096
+ return n >= 0 && (r === void 0 || e.right <= r + ot);
2097
+ }), bt = (e) => e.cells.slice(1).every((t, n) => t.left - e.cells[n].right > e.size * 4), xt = (e, t, n) => {
2098
+ let r = e[t];
2099
+ if (!r || r.cells.length < 2) return;
2100
+ let i = r.cells.map((e) => e.left), a = [r.cells.map((e) => [e])], o = r, s = t + 1;
2101
+ for (; s < e.length; s += 1) {
2102
+ let t = e[s], n = t.baseline - o.baseline;
2103
+ if (t.page !== r.page || n > t.size * 3 || !yt(t, i)) break;
2104
+ let c = a.at(-1), l = n < t.size * 1.5 && t.cells.length < i.length, u = l ? c : i.map(() => []);
2105
+ for (let e of t.cells) u[vt(i, e)]?.push(e);
2106
+ if (!l) {
2107
+ if (t.cells.length < 2 && a.length >= 1 && n >= t.size * 1.5) break;
2108
+ a.push(u);
2109
+ }
2110
+ o = t;
2111
+ }
2112
+ if (a.length < 2 && !bt(r)) return;
2113
+ let c = r.baseline - r.size, l = o.baseline + o.size * .4, u = Math.min(...i), d = Math.max(...e.slice(t, s).map((e) => e.right));
2114
+ return {
2115
+ block: {
2116
+ kind: "table",
2117
+ rows: a,
2118
+ columns: i,
2119
+ right: d,
2120
+ bordered: n.filter((e) => St(e, {
2121
+ x: u,
2122
+ y: c,
2123
+ width: d - u,
2124
+ height: l - c
2125
+ })).length >= 3
2126
+ },
2127
+ end: s
2128
+ };
2129
+ }, Y = 8, St = (e, t) => e.x <= t.x + t.width + Y && e.x + e.width >= t.x - Y ? e.width >= e.height ? e.y >= t.y - Y && e.y <= t.y + t.height + Y : Math.min(e.y + e.height, t.y + t.height) - Math.max(e.y, t.y) > t.height / 2 : !1, Ct = "\\u2022\\u25cf\\u25aa\\u25a0\\u25e6\\u25cb\\u2023\\u2219\\u00b7\\uf0b7\\uf0a7\\uf076\\uf0d8\\uf0fc\\u2013\\u2014-", X = RegExp(`^[${Ct}]\\s+`, "u"), Z = /^(\d{1,3})[.)]\s+/, wt = RegExp(`^(?:[${Ct}]|\\d{1,3}[.)])$`, "u"), Tt = (e, t) => e.size >= t * 1.15 || e.bold && e.size >= t + .75, Et = class {
2130
+ area;
2131
+ lineGap;
2132
+ constructor(e, t) {
2133
+ this.area = e, this.lineGap = t;
2134
+ }
2135
+ alignmentOf(e) {
2136
+ let { left: t, right: n } = this.area(e.page), r = n - t, i = e.left - t, a = n - e.right;
2137
+ return a < e.size * .8 ? i > r * .25 ? "right" : "left" : Math.abs(i - a) < Math.max(r * .04, e.size) && i > Math.max(e.size * 2, r * .06) ? "center" : "left";
2138
+ }
2139
+ startsNew(e, t) {
2140
+ let n = e.lines.at(-1), { left: r, right: i } = this.area(t.page);
2141
+ if (X.test(t.text) || Z.test(t.text) || Math.abs(t.size - n.size) > .75 || t.bold !== n.bold) return !0;
2142
+ let a = this.alignmentOf(t), o = e.alignment === "left" || e.alignment === "justify";
2143
+ if (a === "left" !== o || !o && a !== e.alignment) return !0;
2144
+ let s = n.right < i - Math.max(t.size * 3, (i - r) * .12);
2145
+ if (o && s) return !0;
2146
+ if (t.page !== n.page) return t.left > r + t.size * .5;
2147
+ if (t.baseline - n.baseline > this.lineGap(t.size) * 1.35) return !0;
2148
+ if (!o) return !1;
2149
+ if (e.list) return t.left < e.lines[0].left - 2;
2150
+ let c = e.lines.length > 1 ? n.left : void 0;
2151
+ return c === void 0 ? t.left > n.left + t.size : Math.abs(t.left - c) > t.size;
2152
+ }
2153
+ build(e) {
2154
+ let t = [], n;
2155
+ for (let r of e) {
2156
+ let e = t.at(-1);
2157
+ if (e && n && !this.startsNew(e, r)) e.lines.push(r);
2158
+ else {
2159
+ let e = n && n.page === r.page ? r.baseline - n.baseline : 0;
2160
+ t.push({
2161
+ lines: [r],
2162
+ alignment: this.alignmentOf(r),
2163
+ list: Dt(r.text),
2164
+ spaceBefore: Math.max(0, e - this.lineGap(r.size))
2165
+ });
2166
+ }
2167
+ n = r;
2168
+ }
2169
+ for (let e of t) this.refineAlignment(e);
2170
+ return t;
2171
+ }
2172
+ refineAlignment(e) {
2173
+ if (e.alignment !== "left" || e.lines.length < 2) return;
2174
+ let { right: t } = this.area(e.lines[0].page);
2175
+ e.lines.slice(0, -1).every((e) => t - e.right < e.size * .6) && (e.alignment = "justify");
2176
+ }
2177
+ }, Dt = (e) => {
2178
+ let t = Z.exec(e);
2179
+ return t ? {
2180
+ ordered: !0,
2181
+ start: Number(t[1])
2182
+ } : X.test(e) ? {
2183
+ ordered: !1,
2184
+ start: 1
2185
+ } : void 0;
2186
+ }, Ot = (e) => {
2187
+ let t = [];
2188
+ for (let n of e) {
2189
+ let e = n.cells.flatMap((e, t) => t === 0 ? e.runs : [{
2190
+ ...e.runs[0],
2191
+ text: " "
2192
+ }, ...e.runs]), r = t.at(-1);
2193
+ r && (r.text.endsWith("­") ? r.text = r.text.slice(0, -1) : !r.text.endsWith("-") && !r.text.endsWith(" ") && J(t, {
2194
+ ...e[0] ?? r,
2195
+ text: " "
2196
+ }));
2197
+ for (let n of e) J(t, n);
2198
+ }
2199
+ return t;
2200
+ }, kt = (e) => {
2201
+ let t = e.map((e) => ({ ...e })), n = t[0];
2202
+ return n && (n.text = n.text.replace(Z, "").replace(X, "")), t.filter((e) => e.text);
2203
+ }, At = (e, t) => {
2204
+ let n = ct(e.text);
2205
+ if (!t) {
2206
+ let t = [];
2207
+ Math.abs(e.size - nt) > .25 && t.push(`font-size: ${e.size}pt`), e.family && e.family !== rt && t.push(`font-family: ${e.family.includes(" ") ? `'${e.family}'` : e.family}`), t.length && (n = `<span style="${ct(t.join("; "))}">${n}</span>`), e.bold && (n = `<strong>${n}</strong>`);
2208
+ }
2209
+ return e.color !== "#000000" && (n = `<span style="color: ${e.color}">${n}</span>`), e.italic && (n = `<em>${n}</em>`), n;
2210
+ }, Q = (e, t = !1) => e.map((e) => At(e, t)).join(""), $ = (e) => Math.round(e * tt), jt = class {
2211
+ area;
2212
+ bodySize;
2213
+ lineGaps;
2214
+ headingLevels = /* @__PURE__ */ new Map();
2215
+ constructor(e, t, n, r) {
2216
+ this.area = e, this.bodySize = t, this.lineGaps = r;
2217
+ let i = n.filter((e) => Tt(e, t)).map((e) => e.size);
2218
+ [...new Set(i)].sort((e, t) => t - e).slice(0, 3).forEach((e, t) => {
2219
+ this.headingLevels.set(e, t + 1);
2220
+ });
2221
+ }
2222
+ lineGapOf(e) {
2223
+ return this.lineGaps.get(e) ?? e * 1.2;
2224
+ }
2225
+ write(e) {
2226
+ let t = [];
2227
+ for (let n of e) n.kind === "break" ? t.push("<div data-type=\"page-break\"></div>") : n.kind === "image" ? t.push(this.image(n.image, n.area)) : n.kind === "table" ? t.push(this.table(n)) : t.push(this.paragraphs(n.lines));
2228
+ return t.join("");
2229
+ }
2230
+ paragraphs(e) {
2231
+ let t = new Et(this.area, (e) => this.lineGapOf(e)).build(e), n = "", r, i = () => {
2232
+ if (!r) return;
2233
+ let e = r.ordered ? "ol" : "ul", t = r.ordered && r.start > 1 ? ` start="${r.start}"` : "";
2234
+ n += `<${e}${t}>${r.items.map((e) => `<li>${e}</li>`).join("")}</${e}>`, r = void 0;
2235
+ };
2236
+ for (let e of t) {
2237
+ let t = this.headingLevel(e);
2238
+ if (e.list && !t) {
2239
+ (!r || r.ordered !== e.list.ordered) && (i(), r = {
2240
+ ordered: e.list.ordered,
2241
+ items: [],
2242
+ start: e.list.start
2243
+ }), r.items.push(`<p>${Q(kt(Ot(e.lines)))}</p>`);
2244
+ continue;
2245
+ }
2246
+ i(), n += this.paragraph(e, t);
2247
+ }
2248
+ return i(), n;
2249
+ }
2250
+ headingLevel(e) {
2251
+ let t = e.lines.map((e) => e.text).join(" ");
2252
+ if (!(e.lines.length > 3 || t.length > 200) && e.lines.every((e) => Tt(e, this.bodySize))) return this.headingLevels.get(e.lines[0].size);
2253
+ }
2254
+ paragraph(e, t) {
2255
+ let n = e.lines[0], { left: r } = this.area(n.page), i = [], a = [];
2256
+ if (e.alignment !== "left" && i.push(`text-align: ${e.alignment}`), e.alignment === "left" || e.alignment === "justify") {
2257
+ let t = e.lines.length > 1 ? Math.min(...e.lines.slice(1).map((e) => e.left)) : n.left, a = t - r, o = n.left - t;
2258
+ a > 2 && i.push(`margin-left: ${$(a)}px`), Math.abs(o) > 2 && i.push(`text-indent: ${$(o)}px`);
2259
+ }
2260
+ e.spaceBefore >= 4 && a.push(`data-space-before="${G(e.spaceBefore)}"`), i.length && a.push(`style="${i.join("; ")}"`);
2261
+ let o = t ? `h${t}` : "p", s = Q(Ot(e.lines), t !== void 0);
2262
+ return `<${o}${a.length ? ` ${a.join(" ")}` : ""}>${s}</${o}>`;
2263
+ }
2264
+ table(e) {
2265
+ let t = `<colgroup>${e.columns.map((t, n) => (e.columns[n + 1] ?? e.right) - t).map((e) => `<col style="width: ${$(e)}px">`).join("")}</colgroup>`, n = e.rows.map((e) => `<tr>${e.map((e) => `<td><p>${Q(e.flatMap((e, t) => t === 0 ? e.runs : [{
2266
+ ...e.runs[0],
2267
+ text: " "
2268
+ }, ...e.runs]))}</p></td>`).join("")}</tr>`).join("");
2269
+ return `<table${e.bordered ? "" : " data-type=\"signature\""}>${t}<tbody>${n}</tbody></table>`;
2270
+ }
2271
+ image(e, t) {
2272
+ let n = t.right - t.left, r = e.width > n ? n / e.width : 1, i = e.x + e.width / 2;
2273
+ return `<p${Math.abs(i - (t.left + t.right) / 2) < (t.right - t.left) * .1 ? " style=\"text-align: center\"" : ""}><img src="${e.src}" alt="" width="${$(e.width * r)}" height="${$(e.height * r)}"></p>`;
2274
+ }
2275
+ }, Mt = (n, r, i, a) => {
2276
+ let o = n[0], s = o.width * U, c = o.height * U, l = [Math.min(s, c), Math.max(s, c)], u = Object.keys(e).find((t) => Math.abs(e[t].width - l[0]) < W && Math.abs(e[t].height - l[1]) < W) ?? "a4", d = t[0].margins, f = r.flat(), p = (e, t) => e === void 0 ? t : Math.min(60, Math.max(5, G(e * U, .5))), m = lt(r.map((e) => e[0]).filter((e) => !!e).map((e) => e.baseline - e.size)), h = K(r.filter((e, t) => {
2277
+ let r = e.at(-1);
2278
+ return r !== void 0 && r.baseline > (n[t]?.height ?? 842) * st;
2279
+ }).map((e) => e.at(-1).baseline), .9), g = {
2280
+ size: u,
2281
+ orientation: s > c ? "landscape" : "portrait",
2282
+ margins: f.length ? {
2283
+ top: p(m, d.top),
2284
+ right: p(o.width - i.right, d.right),
2285
+ bottom: p(h === void 0 ? void 0 : o.height - h - 4, d.bottom),
2286
+ left: p(i.left, d.left)
2287
+ } : { ...d }
2288
+ };
2289
+ return a.header && (g.header = a.header), a.footer && (g.footer = a.footer), g;
2290
+ }, Nt = (e) => {
2291
+ let t = e.map(mt), n = _t(t, e), r = t.flat(), i = r.reduce((e, t) => e + t.text.length, 0), a = q(r.map((e) => [e.size, e.text.length])) ?? nt, o = r.filter((e) => Math.abs(e.size - a) < .75), s = {
2292
+ left: K(o.map((e) => e.left), .05) ?? 72,
2293
+ right: K(o.map((e) => e.right), .95) ?? (e[0]?.width ?? 595) - 72
2294
+ }, c = t.map((e) => {
2295
+ let t = e.filter((e) => Math.abs(e.size - a) < .75);
2296
+ return t.length < 5 ? s : {
2297
+ left: K(t.map((e) => e.left), .05) ?? s.left,
2298
+ right: K(t.map((e) => e.right), .95) ?? s.right
2299
+ };
2300
+ }), l = (e) => c[e] ?? s, u = /* @__PURE__ */ new Map();
2301
+ for (let e of t) e.forEach((t, n) => {
2302
+ let r = t.baseline - (e[n - 1]?.baseline ?? -Infinity);
2303
+ r > 0 && r < t.size * 2.2 && u.set(t.size, [...u.get(t.size) ?? [], r]);
2304
+ });
2305
+ let d = new jt(l, a, r, new Map([...u].map(([e, t]) => [e, K(t, .3) ?? e * 1.2]))), f = [], p = (e) => {
2306
+ let t = f.at(-1);
2307
+ t?.kind === "lines" ? t.lines.push(e) : f.push({
2308
+ kind: "lines",
2309
+ lines: [e]
2310
+ });
2311
+ };
2312
+ return t.forEach((n, r) => {
2313
+ let i = e[r], a = [...i.images].sort((e, t) => e.y - t.y), o = 0, s = (e) => {
2314
+ for (; o < a.length && a[o].y <= e; o += 1) f.push({
2315
+ kind: "image",
2316
+ image: a[o],
2317
+ area: l(r)
2318
+ });
2319
+ };
2320
+ for (let e = 0; e < n.length;) {
2321
+ let t = n[e];
2322
+ s(t.baseline - t.size);
2323
+ let r = xt(n, e, i.rules);
2324
+ r ? (f.push(r.block), e = r.end) : (p(t), e += 1);
2325
+ }
2326
+ s(Infinity);
2327
+ let c = Math.max(n.at(-1)?.baseline ?? 0, ...i.images.map((e) => e.y + e.height));
2328
+ r < t.length - 1 && c < i.height * st && f.push({ kind: "break" });
2329
+ }), {
2330
+ html: d.write(f),
2331
+ page: Mt(e, t, c[0] ?? s, n),
2332
+ characters: i
2333
+ };
2334
+ }, Pt = () => new Promise((e) => setTimeout(e, 0)), Ft = async (e) => {
2335
+ let t = new et(e instanceof Uint8Array ? e : new Uint8Array(e)), r = new Ee(t), i = [];
2336
+ for (let e of t.pages()) i.push(r.read(e)), await Pt();
2337
+ if (!i.length) throw new n("empty");
2338
+ let { html: a, page: o, characters: s } = Nt(i);
2339
+ if (!s && !i.some((e) => e.images.length)) throw new n("empty");
2340
+ return {
2341
+ html: a,
2342
+ page: o
2343
+ };
2344
+ };
2345
+ //#endregion
2346
+ export { Ft as readPdf };
2347
+
2348
+ //# sourceMappingURL=pdf-import-Cu3c_cO5.js.map