@vaadin-component-factory/vcf-pdf-viewer 0.9.0 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/README.md +1 -1
  2. package/package.json +33 -18
  3. package/{src/display → pdfjs/dist}/display_utils.js +344 -139
  4. package/{src/display → pdfjs/dist}/fetch_stream.js +115 -97
  5. package/pdfjs/dist/get.js +1857 -0
  6. package/pdfjs/dist/index.js +767 -0
  7. package/pdfjs/dist/l10n_utils.js +140 -0
  8. package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
  9. package/{src/display → pdfjs/dist}/network.js +149 -87
  10. package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
  11. package/{src/display → pdfjs/dist}/node_stream.js +133 -98
  12. package/pdfjs/dist/pdf.js +12778 -0
  13. package/pdfjs/dist/pdf_link_service.js +638 -0
  14. package/pdfjs/dist/pdf_rendering_queue.js +199 -0
  15. package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
  16. package/pdfjs/dist/pdf_viewer.js +3598 -0
  17. package/pdfjs/dist/typeof.js +100 -0
  18. package/pdfjs/dist/ui_utils.js +1033 -0
  19. package/{src/shared → pdfjs/dist}/util.js +301 -287
  20. package/pdfjs/dist/worker.js +62813 -0
  21. package/src/vcf-pdf-viewer.js +77 -27
  22. package/theme/lumo/vcf-pdf-viewer-styles.js +1 -1
  23. package/theme/material/vcf-pdf-viewer.js +2 -2
  24. package/src/core/.eslintrc +0 -13
  25. package/src/core/annotation.js +0 -2948
  26. package/src/core/arithmetic_decoder.js +0 -182
  27. package/src/core/ascii_85_stream.js +0 -98
  28. package/src/core/ascii_hex_stream.js +0 -79
  29. package/src/core/base_stream.js +0 -110
  30. package/src/core/bidi.js +0 -438
  31. package/src/core/calibri_factors.js +0 -308
  32. package/src/core/catalog.js +0 -1459
  33. package/src/core/ccitt.js +0 -1062
  34. package/src/core/ccitt_stream.js +0 -60
  35. package/src/core/cff_font.js +0 -116
  36. package/src/core/cff_parser.js +0 -1949
  37. package/src/core/charsets.js +0 -119
  38. package/src/core/chunked_stream.js +0 -557
  39. package/src/core/cmap.js +0 -1039
  40. package/src/core/colorspace.js +0 -1533
  41. package/src/core/core_utils.js +0 -464
  42. package/src/core/crypto.js +0 -1900
  43. package/src/core/decode_stream.js +0 -170
  44. package/src/core/decrypt_stream.js +0 -59
  45. package/src/core/default_appearance.js +0 -99
  46. package/src/core/document.js +0 -1456
  47. package/src/core/encodings.js +0 -301
  48. package/src/core/evaluator.js +0 -4601
  49. package/src/core/file_spec.js +0 -108
  50. package/src/core/flate_stream.js +0 -402
  51. package/src/core/font_renderer.js +0 -882
  52. package/src/core/fonts.js +0 -3260
  53. package/src/core/fonts_utils.js +0 -221
  54. package/src/core/function.js +0 -1257
  55. package/src/core/glyf.js +0 -706
  56. package/src/core/glyphlist.js +0 -4558
  57. package/src/core/helvetica_factors.js +0 -353
  58. package/src/core/image.js +0 -802
  59. package/src/core/image_utils.js +0 -291
  60. package/src/core/jbig2.js +0 -2572
  61. package/src/core/jbig2_stream.js +0 -73
  62. package/src/core/jpeg_stream.js +0 -105
  63. package/src/core/jpg.js +0 -1416
  64. package/src/core/jpx.js +0 -2343
  65. package/src/core/jpx_stream.js +0 -87
  66. package/src/core/liberationsans_widths.js +0 -221
  67. package/src/core/lzw_stream.js +0 -150
  68. package/src/core/metadata_parser.js +0 -146
  69. package/src/core/metrics.js +0 -2970
  70. package/src/core/murmurhash3.js +0 -139
  71. package/src/core/myriadpro_factors.js +0 -290
  72. package/src/core/name_number_tree.js +0 -153
  73. package/src/core/object_loader.js +0 -149
  74. package/src/core/opentype_file_builder.js +0 -154
  75. package/src/core/operator_list.js +0 -734
  76. package/src/core/parser.js +0 -1416
  77. package/src/core/pattern.js +0 -985
  78. package/src/core/pdf_manager.js +0 -217
  79. package/src/core/predictor_stream.js +0 -238
  80. package/src/core/primitives.js +0 -402
  81. package/src/core/ps_parser.js +0 -272
  82. package/src/core/run_length_stream.js +0 -61
  83. package/src/core/segoeui_factors.js +0 -308
  84. package/src/core/standard_fonts.js +0 -817
  85. package/src/core/stream.js +0 -103
  86. package/src/core/struct_tree.js +0 -335
  87. package/src/core/to_unicode_map.js +0 -103
  88. package/src/core/type1_font.js +0 -421
  89. package/src/core/type1_parser.js +0 -776
  90. package/src/core/unicode.js +0 -1649
  91. package/src/core/worker.js +0 -848
  92. package/src/core/worker_stream.js +0 -135
  93. package/src/core/writer.js +0 -278
  94. package/src/core/xfa/bind.js +0 -652
  95. package/src/core/xfa/builder.js +0 -207
  96. package/src/core/xfa/config.js +0 -1926
  97. package/src/core/xfa/connection_set.js +0 -202
  98. package/src/core/xfa/data.js +0 -82
  99. package/src/core/xfa/datasets.js +0 -76
  100. package/src/core/xfa/factory.js +0 -111
  101. package/src/core/xfa/fonts.js +0 -181
  102. package/src/core/xfa/formcalc_lexer.js +0 -385
  103. package/src/core/xfa/formcalc_parser.js +0 -1340
  104. package/src/core/xfa/html_utils.js +0 -639
  105. package/src/core/xfa/layout.js +0 -383
  106. package/src/core/xfa/locale_set.js +0 -345
  107. package/src/core/xfa/namespaces.js +0 -81
  108. package/src/core/xfa/parser.js +0 -184
  109. package/src/core/xfa/setup.js +0 -38
  110. package/src/core/xfa/signature.js +0 -40
  111. package/src/core/xfa/som.js +0 -338
  112. package/src/core/xfa/stylesheet.js +0 -40
  113. package/src/core/xfa/template.js +0 -6260
  114. package/src/core/xfa/text.js +0 -290
  115. package/src/core/xfa/unknown.js +0 -29
  116. package/src/core/xfa/utils.js +0 -217
  117. package/src/core/xfa/xdp.js +0 -59
  118. package/src/core/xfa/xfa_object.js +0 -1130
  119. package/src/core/xfa/xhtml.js +0 -543
  120. package/src/core/xfa_fonts.js +0 -208
  121. package/src/core/xml_parser.js +0 -507
  122. package/src/core/xref.js +0 -899
  123. package/src/display/annotation_layer.js +0 -2107
  124. package/src/display/annotation_storage.js +0 -113
  125. package/src/display/api.js +0 -3292
  126. package/src/display/base_factory.js +0 -180
  127. package/src/display/canvas.js +0 -2828
  128. package/src/display/font_loader.js +0 -484
  129. package/src/display/metadata.js +0 -41
  130. package/src/display/network_utils.js +0 -100
  131. package/src/display/node_utils.js +0 -83
  132. package/src/display/optional_content_config.js +0 -189
  133. package/src/display/pattern_helper.js +0 -659
  134. package/src/display/svg.js +0 -1709
  135. package/src/display/text_layer.js +0 -847
  136. package/src/display/transport_stream.js +0 -303
  137. package/src/display/worker_options.js +0 -40
  138. package/src/display/xfa_layer.js +0 -204
  139. package/src/doc_helper.js +0 -25
  140. package/src/images/logo.svg +0 -41
  141. package/src/interfaces.js +0 -169
  142. package/src/license_header.js +0 -14
  143. package/src/license_header_libre.js +0 -21
  144. package/src/pdf.image_decoders.js +0 -46
  145. package/src/pdf.js +0 -146
  146. package/src/pdf.sandbox.external.js +0 -181
  147. package/src/pdf.sandbox.js +0 -151
  148. package/src/pdf.scripting.js +0 -25
  149. package/src/pdf.worker.entry.js +0 -19
  150. package/src/pdf.worker.js +0 -23
  151. package/src/scripting_api/aform.js +0 -608
  152. package/src/scripting_api/app.js +0 -621
  153. package/src/scripting_api/color.js +0 -129
  154. package/src/scripting_api/common.js +0 -58
  155. package/src/scripting_api/console.js +0 -38
  156. package/src/scripting_api/constants.js +0 -208
  157. package/src/scripting_api/doc.js +0 -1195
  158. package/src/scripting_api/error.js +0 -23
  159. package/src/scripting_api/event.js +0 -232
  160. package/src/scripting_api/field.js +0 -620
  161. package/src/scripting_api/fullscreen.js +0 -145
  162. package/src/scripting_api/initialization.js +0 -223
  163. package/src/scripting_api/pdf_object.js +0 -24
  164. package/src/scripting_api/print_params.js +0 -146
  165. package/src/scripting_api/proxy.js +0 -139
  166. package/src/scripting_api/thermometer.js +0 -69
  167. package/src/scripting_api/util.js +0 -581
  168. package/src/shared/.eslintrc +0 -13
  169. package/src/shared/cffStandardStrings.js +0 -311
  170. package/src/shared/compatibility.js +0 -114
  171. package/src/shared/fonts_utils.js +0 -429
  172. package/src/shared/is_node.js +0 -27
  173. package/src/shared/scripting_utils.js +0 -85
  174. package/src/worker_loader.js +0 -32
@@ -1,119 +0,0 @@
1
- /* Copyright 2012 Mozilla Foundation
2
- *
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
-
16
- // prettier-ignore
17
- const ISOAdobeCharset = [
18
- ".notdef", "space", "exclam", "quotedbl", "numbersign", "dollar",
19
- "percent", "ampersand", "quoteright", "parenleft", "parenright",
20
- "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero",
21
- "one", "two", "three", "four", "five", "six", "seven", "eight",
22
- "nine", "colon", "semicolon", "less", "equal", "greater", "question",
23
- "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
24
- "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
25
- "bracketleft", "backslash", "bracketright", "asciicircum", "underscore",
26
- "quoteleft", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
27
- "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
28
- "braceleft", "bar", "braceright", "asciitilde", "exclamdown", "cent",
29
- "sterling", "fraction", "yen", "florin", "section", "currency",
30
- "quotesingle", "quotedblleft", "guillemotleft", "guilsinglleft",
31
- "guilsinglright", "fi", "fl", "endash", "dagger", "daggerdbl",
32
- "periodcentered", "paragraph", "bullet", "quotesinglbase",
33
- "quotedblbase", "quotedblright", "guillemotright", "ellipsis",
34
- "perthousand", "questiondown", "grave", "acute", "circumflex", "tilde",
35
- "macron", "breve", "dotaccent", "dieresis", "ring", "cedilla",
36
- "hungarumlaut", "ogonek", "caron", "emdash", "AE", "ordfeminine",
37
- "Lslash", "Oslash", "OE", "ordmasculine", "ae", "dotlessi", "lslash",
38
- "oslash", "oe", "germandbls", "onesuperior", "logicalnot", "mu",
39
- "trademark", "Eth", "onehalf", "plusminus", "Thorn", "onequarter",
40
- "divide", "brokenbar", "degree", "thorn", "threequarters", "twosuperior",
41
- "registered", "minus", "eth", "multiply", "threesuperior", "copyright",
42
- "Aacute", "Acircumflex", "Adieresis", "Agrave", "Aring", "Atilde",
43
- "Ccedilla", "Eacute", "Ecircumflex", "Edieresis", "Egrave", "Iacute",
44
- "Icircumflex", "Idieresis", "Igrave", "Ntilde", "Oacute", "Ocircumflex",
45
- "Odieresis", "Ograve", "Otilde", "Scaron", "Uacute", "Ucircumflex",
46
- "Udieresis", "Ugrave", "Yacute", "Ydieresis", "Zcaron", "aacute",
47
- "acircumflex", "adieresis", "agrave", "aring", "atilde", "ccedilla",
48
- "eacute", "ecircumflex", "edieresis", "egrave", "iacute", "icircumflex",
49
- "idieresis", "igrave", "ntilde", "oacute", "ocircumflex", "odieresis",
50
- "ograve", "otilde", "scaron", "uacute", "ucircumflex", "udieresis",
51
- "ugrave", "yacute", "ydieresis", "zcaron"
52
- ];
53
-
54
- // prettier-ignore
55
- const ExpertCharset = [
56
- ".notdef", "space", "exclamsmall", "Hungarumlautsmall", "dollaroldstyle",
57
- "dollarsuperior", "ampersandsmall", "Acutesmall", "parenleftsuperior",
58
- "parenrightsuperior", "twodotenleader", "onedotenleader", "comma",
59
- "hyphen", "period", "fraction", "zerooldstyle", "oneoldstyle",
60
- "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle",
61
- "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle",
62
- "colon", "semicolon", "commasuperior", "threequartersemdash",
63
- "periodsuperior", "questionsmall", "asuperior", "bsuperior",
64
- "centsuperior", "dsuperior", "esuperior", "isuperior", "lsuperior",
65
- "msuperior", "nsuperior", "osuperior", "rsuperior", "ssuperior",
66
- "tsuperior", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior",
67
- "parenrightinferior", "Circumflexsmall", "hyphensuperior", "Gravesmall",
68
- "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall",
69
- "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall",
70
- "Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall",
71
- "Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary",
72
- "onefitted", "rupiah", "Tildesmall", "exclamdownsmall", "centoldstyle",
73
- "Lslashsmall", "Scaronsmall", "Zcaronsmall", "Dieresissmall",
74
- "Brevesmall", "Caronsmall", "Dotaccentsmall", "Macronsmall",
75
- "figuredash", "hypheninferior", "Ogoneksmall", "Ringsmall",
76
- "Cedillasmall", "onequarter", "onehalf", "threequarters",
77
- "questiondownsmall", "oneeighth", "threeeighths", "fiveeighths",
78
- "seveneighths", "onethird", "twothirds", "zerosuperior", "onesuperior",
79
- "twosuperior", "threesuperior", "foursuperior", "fivesuperior",
80
- "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior",
81
- "zeroinferior", "oneinferior", "twoinferior", "threeinferior",
82
- "fourinferior", "fiveinferior", "sixinferior", "seveninferior",
83
- "eightinferior", "nineinferior", "centinferior", "dollarinferior",
84
- "periodinferior", "commainferior", "Agravesmall", "Aacutesmall",
85
- "Acircumflexsmall", "Atildesmall", "Adieresissmall", "Aringsmall",
86
- "AEsmall", "Ccedillasmall", "Egravesmall", "Eacutesmall",
87
- "Ecircumflexsmall", "Edieresissmall", "Igravesmall", "Iacutesmall",
88
- "Icircumflexsmall", "Idieresissmall", "Ethsmall", "Ntildesmall",
89
- "Ogravesmall", "Oacutesmall", "Ocircumflexsmall", "Otildesmall",
90
- "Odieresissmall", "OEsmall", "Oslashsmall", "Ugravesmall", "Uacutesmall",
91
- "Ucircumflexsmall", "Udieresissmall", "Yacutesmall", "Thornsmall",
92
- "Ydieresissmall"
93
- ];
94
-
95
- // prettier-ignore
96
- const ExpertSubsetCharset = [
97
- ".notdef", "space", "dollaroldstyle", "dollarsuperior",
98
- "parenleftsuperior", "parenrightsuperior", "twodotenleader",
99
- "onedotenleader", "comma", "hyphen", "period", "fraction",
100
- "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle",
101
- "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle",
102
- "eightoldstyle", "nineoldstyle", "colon", "semicolon", "commasuperior",
103
- "threequartersemdash", "periodsuperior", "asuperior", "bsuperior",
104
- "centsuperior", "dsuperior", "esuperior", "isuperior", "lsuperior",
105
- "msuperior", "nsuperior", "osuperior", "rsuperior", "ssuperior",
106
- "tsuperior", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior",
107
- "parenrightinferior", "hyphensuperior", "colonmonetary", "onefitted",
108
- "rupiah", "centoldstyle", "figuredash", "hypheninferior", "onequarter",
109
- "onehalf", "threequarters", "oneeighth", "threeeighths", "fiveeighths",
110
- "seveneighths", "onethird", "twothirds", "zerosuperior", "onesuperior",
111
- "twosuperior", "threesuperior", "foursuperior", "fivesuperior",
112
- "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior",
113
- "zeroinferior", "oneinferior", "twoinferior", "threeinferior",
114
- "fourinferior", "fiveinferior", "sixinferior", "seveninferior",
115
- "eightinferior", "nineinferior", "centinferior", "dollarinferior",
116
- "periodinferior", "commainferior"
117
- ];
118
-
119
- export { ExpertCharset, ExpertSubsetCharset, ISOAdobeCharset };
@@ -1,557 +0,0 @@
1
- /* Copyright 2012 Mozilla Foundation
2
- *
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
-
16
- import {
17
- arrayByteLength,
18
- arraysToBytes,
19
- createPromiseCapability,
20
- } from "../shared/util.js";
21
- import { MissingDataException } from "./core_utils.js";
22
- import { Stream } from "./stream.js";
23
-
24
- class ChunkedStream extends Stream {
25
- constructor(length, chunkSize, manager) {
26
- super(
27
- /* arrayBuffer = */ new Uint8Array(length),
28
- /* start = */ 0,
29
- /* length = */ length,
30
- /* dict = */ null
31
- );
32
-
33
- this.chunkSize = chunkSize;
34
- this._loadedChunks = new Set();
35
- this.numChunks = Math.ceil(length / chunkSize);
36
- this.manager = manager;
37
- this.progressiveDataLength = 0;
38
- this.lastSuccessfulEnsureByteChunk = -1; // Single-entry cache
39
- }
40
-
41
- // If a particular stream does not implement one or more of these methods,
42
- // an error should be thrown.
43
- getMissingChunks() {
44
- const chunks = [];
45
- for (let chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
46
- if (!this._loadedChunks.has(chunk)) {
47
- chunks.push(chunk);
48
- }
49
- }
50
- return chunks;
51
- }
52
-
53
- get numChunksLoaded() {
54
- return this._loadedChunks.size;
55
- }
56
-
57
- get isDataLoaded() {
58
- return this.numChunksLoaded === this.numChunks;
59
- }
60
-
61
- onReceiveData(begin, chunk) {
62
- const chunkSize = this.chunkSize;
63
- if (begin % chunkSize !== 0) {
64
- throw new Error(`Bad begin offset: ${begin}`);
65
- }
66
-
67
- // Using `this.length` is inaccurate here since `this.start` can be moved
68
- // (see the `moveStart` method).
69
- const end = begin + chunk.byteLength;
70
- if (end % chunkSize !== 0 && end !== this.bytes.length) {
71
- throw new Error(`Bad end offset: ${end}`);
72
- }
73
-
74
- this.bytes.set(new Uint8Array(chunk), begin);
75
- const beginChunk = Math.floor(begin / chunkSize);
76
- const endChunk = Math.floor((end - 1) / chunkSize) + 1;
77
-
78
- for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
79
- // Since a value can only occur *once* in a `Set`, there's no need to
80
- // manually check `Set.prototype.has()` before adding the value here.
81
- this._loadedChunks.add(curChunk);
82
- }
83
- }
84
-
85
- onReceiveProgressiveData(data) {
86
- let position = this.progressiveDataLength;
87
- const beginChunk = Math.floor(position / this.chunkSize);
88
-
89
- this.bytes.set(new Uint8Array(data), position);
90
- position += data.byteLength;
91
- this.progressiveDataLength = position;
92
- const endChunk =
93
- position >= this.end
94
- ? this.numChunks
95
- : Math.floor(position / this.chunkSize);
96
-
97
- for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
98
- // Since a value can only occur *once* in a `Set`, there's no need to
99
- // manually check `Set.prototype.has()` before adding the value here.
100
- this._loadedChunks.add(curChunk);
101
- }
102
- }
103
-
104
- ensureByte(pos) {
105
- if (pos < this.progressiveDataLength) {
106
- return;
107
- }
108
-
109
- const chunk = Math.floor(pos / this.chunkSize);
110
- if (chunk === this.lastSuccessfulEnsureByteChunk) {
111
- return;
112
- }
113
-
114
- if (!this._loadedChunks.has(chunk)) {
115
- throw new MissingDataException(pos, pos + 1);
116
- }
117
- this.lastSuccessfulEnsureByteChunk = chunk;
118
- }
119
-
120
- ensureRange(begin, end) {
121
- if (begin >= end) {
122
- return;
123
- }
124
- if (end <= this.progressiveDataLength) {
125
- return;
126
- }
127
-
128
- const chunkSize = this.chunkSize;
129
- const beginChunk = Math.floor(begin / chunkSize);
130
- const endChunk = Math.floor((end - 1) / chunkSize) + 1;
131
- for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
132
- if (!this._loadedChunks.has(chunk)) {
133
- throw new MissingDataException(begin, end);
134
- }
135
- }
136
- }
137
-
138
- nextEmptyChunk(beginChunk) {
139
- const numChunks = this.numChunks;
140
- for (let i = 0; i < numChunks; ++i) {
141
- const chunk = (beginChunk + i) % numChunks; // Wrap around to beginning.
142
- if (!this._loadedChunks.has(chunk)) {
143
- return chunk;
144
- }
145
- }
146
- return null;
147
- }
148
-
149
- hasChunk(chunk) {
150
- return this._loadedChunks.has(chunk);
151
- }
152
-
153
- getByte() {
154
- const pos = this.pos;
155
- if (pos >= this.end) {
156
- return -1;
157
- }
158
- if (pos >= this.progressiveDataLength) {
159
- this.ensureByte(pos);
160
- }
161
- return this.bytes[this.pos++];
162
- }
163
-
164
- getBytes(length, forceClamped = false) {
165
- const bytes = this.bytes;
166
- const pos = this.pos;
167
- const strEnd = this.end;
168
-
169
- if (!length) {
170
- if (strEnd > this.progressiveDataLength) {
171
- this.ensureRange(pos, strEnd);
172
- }
173
- const subarray = bytes.subarray(pos, strEnd);
174
- // `this.bytes` is always a `Uint8Array` here.
175
- return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
176
- }
177
-
178
- let end = pos + length;
179
- if (end > strEnd) {
180
- end = strEnd;
181
- }
182
- if (end > this.progressiveDataLength) {
183
- this.ensureRange(pos, end);
184
- }
185
-
186
- this.pos = end;
187
- const subarray = bytes.subarray(pos, end);
188
- // `this.bytes` is always a `Uint8Array` here.
189
- return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
190
- }
191
-
192
- getByteRange(begin, end) {
193
- if (begin < 0) {
194
- begin = 0;
195
- }
196
- if (end > this.end) {
197
- end = this.end;
198
- }
199
- if (end > this.progressiveDataLength) {
200
- this.ensureRange(begin, end);
201
- }
202
- return this.bytes.subarray(begin, end);
203
- }
204
-
205
- makeSubStream(start, length, dict = null) {
206
- if (length) {
207
- if (start + length > this.progressiveDataLength) {
208
- this.ensureRange(start, start + length);
209
- }
210
- } else {
211
- // When the `length` is undefined you do *not*, under any circumstances,
212
- // want to fallback on calling `this.ensureRange(start, this.end)` since
213
- // that would force the *entire* PDF file to be loaded, thus completely
214
- // breaking the whole purpose of using streaming and/or range requests.
215
- //
216
- // However, not doing any checking here could very easily lead to wasted
217
- // time/resources during e.g. parsing, since `MissingDataException`s will
218
- // require data to be re-parsed, which we attempt to minimize by at least
219
- // checking that the *beginning* of the data is available here.
220
- if (start >= this.progressiveDataLength) {
221
- this.ensureByte(start);
222
- }
223
- }
224
-
225
- function ChunkedStreamSubstream() {}
226
- ChunkedStreamSubstream.prototype = Object.create(this);
227
- ChunkedStreamSubstream.prototype.getMissingChunks = function () {
228
- const chunkSize = this.chunkSize;
229
- const beginChunk = Math.floor(this.start / chunkSize);
230
- const endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
231
- const missingChunks = [];
232
- for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
233
- if (!this._loadedChunks.has(chunk)) {
234
- missingChunks.push(chunk);
235
- }
236
- }
237
- return missingChunks;
238
- };
239
- Object.defineProperty(ChunkedStreamSubstream.prototype, "isDataLoaded", {
240
- get() {
241
- if (this.numChunksLoaded === this.numChunks) {
242
- return true;
243
- }
244
- return this.getMissingChunks().length === 0;
245
- },
246
- configurable: true,
247
- });
248
-
249
- const subStream = new ChunkedStreamSubstream();
250
- subStream.pos = subStream.start = start;
251
- subStream.end = start + length || this.end;
252
- subStream.dict = dict;
253
- return subStream;
254
- }
255
-
256
- getBaseStreams() {
257
- return [this];
258
- }
259
- }
260
-
261
- class ChunkedStreamManager {
262
- constructor(pdfNetworkStream, args) {
263
- this.length = args.length;
264
- this.chunkSize = args.rangeChunkSize;
265
- this.stream = new ChunkedStream(this.length, this.chunkSize, this);
266
- this.pdfNetworkStream = pdfNetworkStream;
267
- this.disableAutoFetch = args.disableAutoFetch;
268
- this.msgHandler = args.msgHandler;
269
-
270
- this.currRequestId = 0;
271
-
272
- this._chunksNeededByRequest = new Map();
273
- this._requestsByChunk = new Map();
274
- this._promisesByRequest = new Map();
275
- this.progressiveDataLength = 0;
276
- this.aborted = false;
277
-
278
- this._loadedStreamCapability = createPromiseCapability();
279
- }
280
-
281
- onLoadedStream() {
282
- return this._loadedStreamCapability.promise;
283
- }
284
-
285
- sendRequest(begin, end) {
286
- const rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
287
- if (!rangeReader.isStreamingSupported) {
288
- rangeReader.onProgress = this.onProgress.bind(this);
289
- }
290
-
291
- let chunks = [],
292
- loaded = 0;
293
- const promise = new Promise((resolve, reject) => {
294
- const readChunk = chunk => {
295
- try {
296
- if (!chunk.done) {
297
- const data = chunk.value;
298
- chunks.push(data);
299
- loaded += arrayByteLength(data);
300
- if (rangeReader.isStreamingSupported) {
301
- this.onProgress({ loaded });
302
- }
303
- rangeReader.read().then(readChunk, reject);
304
- return;
305
- }
306
- const chunkData = arraysToBytes(chunks);
307
- chunks = null;
308
- resolve(chunkData);
309
- } catch (e) {
310
- reject(e);
311
- }
312
- };
313
- rangeReader.read().then(readChunk, reject);
314
- });
315
- promise.then(data => {
316
- if (this.aborted) {
317
- return; // Ignoring any data after abort.
318
- }
319
- this.onReceiveData({ chunk: data, begin });
320
- });
321
- // TODO check errors
322
- }
323
-
324
- /**
325
- * Get all the chunks that are not yet loaded and group them into
326
- * contiguous ranges to load in as few requests as possible.
327
- */
328
- requestAllChunks() {
329
- const missingChunks = this.stream.getMissingChunks();
330
- this._requestChunks(missingChunks);
331
- return this._loadedStreamCapability.promise;
332
- }
333
-
334
- _requestChunks(chunks) {
335
- const requestId = this.currRequestId++;
336
-
337
- const chunksNeeded = new Set();
338
- this._chunksNeededByRequest.set(requestId, chunksNeeded);
339
- for (const chunk of chunks) {
340
- if (!this.stream.hasChunk(chunk)) {
341
- chunksNeeded.add(chunk);
342
- }
343
- }
344
-
345
- if (chunksNeeded.size === 0) {
346
- return Promise.resolve();
347
- }
348
-
349
- const capability = createPromiseCapability();
350
- this._promisesByRequest.set(requestId, capability);
351
-
352
- const chunksToRequest = [];
353
- for (const chunk of chunksNeeded) {
354
- let requestIds = this._requestsByChunk.get(chunk);
355
- if (!requestIds) {
356
- requestIds = [];
357
- this._requestsByChunk.set(chunk, requestIds);
358
-
359
- chunksToRequest.push(chunk);
360
- }
361
- requestIds.push(requestId);
362
- }
363
-
364
- if (chunksToRequest.length > 0) {
365
- const groupedChunksToRequest = this.groupChunks(chunksToRequest);
366
- for (const groupedChunk of groupedChunksToRequest) {
367
- const begin = groupedChunk.beginChunk * this.chunkSize;
368
- const end = Math.min(
369
- groupedChunk.endChunk * this.chunkSize,
370
- this.length
371
- );
372
- this.sendRequest(begin, end);
373
- }
374
- }
375
-
376
- return capability.promise.catch(reason => {
377
- if (this.aborted) {
378
- return; // Ignoring any pending requests after abort.
379
- }
380
- throw reason;
381
- });
382
- }
383
-
384
- getStream() {
385
- return this.stream;
386
- }
387
-
388
- /**
389
- * Loads any chunks in the requested range that are not yet loaded.
390
- */
391
- requestRange(begin, end) {
392
- end = Math.min(end, this.length);
393
-
394
- const beginChunk = this.getBeginChunk(begin);
395
- const endChunk = this.getEndChunk(end);
396
-
397
- const chunks = [];
398
- for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
399
- chunks.push(chunk);
400
- }
401
- return this._requestChunks(chunks);
402
- }
403
-
404
- requestRanges(ranges = []) {
405
- const chunksToRequest = [];
406
- for (const range of ranges) {
407
- const beginChunk = this.getBeginChunk(range.begin);
408
- const endChunk = this.getEndChunk(range.end);
409
- for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
410
- if (!chunksToRequest.includes(chunk)) {
411
- chunksToRequest.push(chunk);
412
- }
413
- }
414
- }
415
-
416
- chunksToRequest.sort(function (a, b) {
417
- return a - b;
418
- });
419
- return this._requestChunks(chunksToRequest);
420
- }
421
-
422
- /**
423
- * Groups a sorted array of chunks into as few contiguous larger
424
- * chunks as possible.
425
- */
426
- groupChunks(chunks) {
427
- const groupedChunks = [];
428
- let beginChunk = -1;
429
- let prevChunk = -1;
430
-
431
- for (let i = 0, ii = chunks.length; i < ii; ++i) {
432
- const chunk = chunks[i];
433
- if (beginChunk < 0) {
434
- beginChunk = chunk;
435
- }
436
-
437
- if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
438
- groupedChunks.push({ beginChunk, endChunk: prevChunk + 1 });
439
- beginChunk = chunk;
440
- }
441
- if (i + 1 === chunks.length) {
442
- groupedChunks.push({ beginChunk, endChunk: chunk + 1 });
443
- }
444
-
445
- prevChunk = chunk;
446
- }
447
- return groupedChunks;
448
- }
449
-
450
- onProgress(args) {
451
- this.msgHandler.send("DocProgress", {
452
- loaded: this.stream.numChunksLoaded * this.chunkSize + args.loaded,
453
- total: this.length,
454
- });
455
- }
456
-
457
- onReceiveData(args) {
458
- const chunk = args.chunk;
459
- const isProgressive = args.begin === undefined;
460
- const begin = isProgressive ? this.progressiveDataLength : args.begin;
461
- const end = begin + chunk.byteLength;
462
-
463
- const beginChunk = Math.floor(begin / this.chunkSize);
464
- const endChunk =
465
- end < this.length
466
- ? Math.floor(end / this.chunkSize)
467
- : Math.ceil(end / this.chunkSize);
468
-
469
- if (isProgressive) {
470
- this.stream.onReceiveProgressiveData(chunk);
471
- this.progressiveDataLength = end;
472
- } else {
473
- this.stream.onReceiveData(begin, chunk);
474
- }
475
-
476
- if (this.stream.isDataLoaded) {
477
- this._loadedStreamCapability.resolve(this.stream);
478
- }
479
-
480
- const loadedRequests = [];
481
- for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
482
- // The server might return more chunks than requested.
483
- const requestIds = this._requestsByChunk.get(curChunk);
484
- if (!requestIds) {
485
- continue;
486
- }
487
- this._requestsByChunk.delete(curChunk);
488
-
489
- for (const requestId of requestIds) {
490
- const chunksNeeded = this._chunksNeededByRequest.get(requestId);
491
- if (chunksNeeded.has(curChunk)) {
492
- chunksNeeded.delete(curChunk);
493
- }
494
-
495
- if (chunksNeeded.size > 0) {
496
- continue;
497
- }
498
- loadedRequests.push(requestId);
499
- }
500
- }
501
-
502
- // If there are no pending requests, automatically fetch the next
503
- // unfetched chunk of the PDF file.
504
- if (!this.disableAutoFetch && this._requestsByChunk.size === 0) {
505
- let nextEmptyChunk;
506
- if (this.stream.numChunksLoaded === 1) {
507
- // This is a special optimization so that after fetching the first
508
- // chunk, rather than fetching the second chunk, we fetch the last
509
- // chunk.
510
- const lastChunk = this.stream.numChunks - 1;
511
- if (!this.stream.hasChunk(lastChunk)) {
512
- nextEmptyChunk = lastChunk;
513
- }
514
- } else {
515
- nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
516
- }
517
- if (Number.isInteger(nextEmptyChunk)) {
518
- this._requestChunks([nextEmptyChunk]);
519
- }
520
- }
521
-
522
- for (const requestId of loadedRequests) {
523
- const capability = this._promisesByRequest.get(requestId);
524
- this._promisesByRequest.delete(requestId);
525
- capability.resolve();
526
- }
527
-
528
- this.msgHandler.send("DocProgress", {
529
- loaded: this.stream.numChunksLoaded * this.chunkSize,
530
- total: this.length,
531
- });
532
- }
533
-
534
- onError(err) {
535
- this._loadedStreamCapability.reject(err);
536
- }
537
-
538
- getBeginChunk(begin) {
539
- return Math.floor(begin / this.chunkSize);
540
- }
541
-
542
- getEndChunk(end) {
543
- return Math.floor((end - 1) / this.chunkSize) + 1;
544
- }
545
-
546
- abort(reason) {
547
- this.aborted = true;
548
- if (this.pdfNetworkStream) {
549
- this.pdfNetworkStream.cancelAllRequests(reason);
550
- }
551
- for (const capability of this._promisesByRequest.values()) {
552
- capability.reject(reason);
553
- }
554
- }
555
- }
556
-
557
- export { ChunkedStream, ChunkedStreamManager };