@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,108 +0,0 @@
1
- /* Copyright 2021 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 { isDict, isStream } from "./primitives.js";
17
- import { stringToPDFString, warn } from "../shared/util.js";
18
-
19
- function pickPlatformItem(dict) {
20
- // Look for the filename in this order:
21
- // UF, F, Unix, Mac, DOS
22
- if (dict.has("UF")) {
23
- return dict.get("UF");
24
- } else if (dict.has("F")) {
25
- return dict.get("F");
26
- } else if (dict.has("Unix")) {
27
- return dict.get("Unix");
28
- } else if (dict.has("Mac")) {
29
- return dict.get("Mac");
30
- } else if (dict.has("DOS")) {
31
- return dict.get("DOS");
32
- }
33
- return null;
34
- }
35
-
36
- /**
37
- * "A PDF file can refer to the contents of another file by using a File
38
- * Specification (PDF 1.1)", see the spec (7.11) for more details.
39
- * NOTE: Only embedded files are supported (as part of the attachments support)
40
- * TODO: support the 'URL' file system (with caching if !/V), portable
41
- * collections attributes and related files (/RF)
42
- */
43
- class FileSpec {
44
- constructor(root, xref) {
45
- if (!root || !isDict(root)) {
46
- return;
47
- }
48
- this.xref = xref;
49
- this.root = root;
50
- if (root.has("FS")) {
51
- this.fs = root.get("FS");
52
- }
53
- this.description = root.has("Desc")
54
- ? stringToPDFString(root.get("Desc"))
55
- : "";
56
- if (root.has("RF")) {
57
- warn("Related file specifications are not supported");
58
- }
59
- this.contentAvailable = true;
60
- if (!root.has("EF")) {
61
- this.contentAvailable = false;
62
- warn("Non-embedded file specifications are not supported");
63
- }
64
- }
65
-
66
- get filename() {
67
- if (!this._filename && this.root) {
68
- const filename = pickPlatformItem(this.root) || "unnamed";
69
- this._filename = stringToPDFString(filename) // lgtm [js/double-escaping]
70
- .replace(/\\\\/g, "\\")
71
- .replace(/\\\//g, "/")
72
- .replace(/\\/g, "/");
73
- }
74
- return this._filename;
75
- }
76
-
77
- get content() {
78
- if (!this.contentAvailable) {
79
- return null;
80
- }
81
- if (!this.contentRef && this.root) {
82
- this.contentRef = pickPlatformItem(this.root.get("EF"));
83
- }
84
- let content = null;
85
- if (this.contentRef) {
86
- const fileObj = this.xref.fetchIfRef(this.contentRef);
87
- if (fileObj && isStream(fileObj)) {
88
- content = fileObj.getBytes();
89
- } else {
90
- warn(
91
- "Embedded file specification points to non-existing/invalid content"
92
- );
93
- }
94
- } else {
95
- warn("Embedded file specification does not have a content");
96
- }
97
- return content;
98
- }
99
-
100
- get serializable() {
101
- return {
102
- filename: this.filename,
103
- content: this.content,
104
- };
105
- }
106
- }
107
-
108
- export { FileSpec };
@@ -1,402 +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
- /* Copyright 1996-2003 Glyph & Cog, LLC
16
- *
17
- * The flate stream implementation contained in this file is a JavaScript port
18
- * of XPDF's implementation, made available under the Apache 2.0 open source
19
- * license.
20
- */
21
-
22
- import { DecodeStream } from "./decode_stream.js";
23
- import { FormatError } from "../shared/util.js";
24
-
25
- const codeLenCodeMap = new Int32Array([
26
- 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
27
- ]);
28
-
29
- const lengthDecode = new Int32Array([
30
- 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
31
- 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
32
- 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
33
- 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102,
34
- ]);
35
-
36
- const distDecode = new Int32Array([
37
- 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
38
- 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
39
- 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
40
- 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001,
41
- ]);
42
-
43
- const fixedLitCodeTab = [
44
- new Int32Array([
45
- 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
46
- 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
47
- 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
48
- 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
49
- 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
50
- 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
51
- 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
52
- 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
53
- 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
54
- 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
55
- 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
56
- 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
57
- 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
58
- 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
59
- 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
60
- 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
61
- 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
62
- 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
63
- 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
64
- 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
65
- 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
66
- 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
67
- 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
68
- 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
69
- 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
70
- 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
71
- 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
72
- 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
73
- 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
74
- 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
75
- 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
76
- 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
77
- 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
78
- 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
79
- 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
80
- 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
81
- 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
82
- 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
83
- 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
84
- 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
85
- 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
86
- 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
87
- 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
88
- 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
89
- 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
90
- 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
91
- 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
92
- 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
93
- 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
94
- 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
95
- 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
96
- 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
97
- 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
98
- 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
99
- 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
100
- 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
101
- 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
102
- 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
103
- 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
104
- 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
105
- 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
106
- 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
107
- 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
108
- 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff,
109
- ]),
110
- 9,
111
- ];
112
-
113
- const fixedDistCodeTab = [
114
- new Int32Array([
115
- 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
116
- 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
117
- 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
118
- 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000,
119
- ]),
120
- 5,
121
- ];
122
-
123
- class FlateStream extends DecodeStream {
124
- constructor(str, maybeLength) {
125
- super(maybeLength);
126
-
127
- this.str = str;
128
- this.dict = str.dict;
129
-
130
- const cmf = str.getByte();
131
- const flg = str.getByte();
132
- if (cmf === -1 || flg === -1) {
133
- throw new FormatError(`Invalid header in flate stream: ${cmf}, ${flg}`);
134
- }
135
- if ((cmf & 0x0f) !== 0x08) {
136
- throw new FormatError(
137
- `Unknown compression method in flate stream: ${cmf}, ${flg}`
138
- );
139
- }
140
- if (((cmf << 8) + flg) % 31 !== 0) {
141
- throw new FormatError(`Bad FCHECK in flate stream: ${cmf}, ${flg}`);
142
- }
143
- if (flg & 0x20) {
144
- throw new FormatError(`FDICT bit set in flate stream: ${cmf}, ${flg}`);
145
- }
146
-
147
- this.codeSize = 0;
148
- this.codeBuf = 0;
149
- }
150
-
151
- getBits(bits) {
152
- const str = this.str;
153
- let codeSize = this.codeSize;
154
- let codeBuf = this.codeBuf;
155
-
156
- let b;
157
- while (codeSize < bits) {
158
- if ((b = str.getByte()) === -1) {
159
- throw new FormatError("Bad encoding in flate stream");
160
- }
161
- codeBuf |= b << codeSize;
162
- codeSize += 8;
163
- }
164
- b = codeBuf & ((1 << bits) - 1);
165
- this.codeBuf = codeBuf >> bits;
166
- this.codeSize = codeSize -= bits;
167
-
168
- return b;
169
- }
170
-
171
- getCode(table) {
172
- const str = this.str;
173
- const codes = table[0];
174
- const maxLen = table[1];
175
- let codeSize = this.codeSize;
176
- let codeBuf = this.codeBuf;
177
-
178
- let b;
179
- while (codeSize < maxLen) {
180
- if ((b = str.getByte()) === -1) {
181
- // premature end of stream. code might however still be valid.
182
- // codeSize < codeLen check below guards against incomplete codeVal.
183
- break;
184
- }
185
- codeBuf |= b << codeSize;
186
- codeSize += 8;
187
- }
188
- const code = codes[codeBuf & ((1 << maxLen) - 1)];
189
- const codeLen = code >> 16;
190
- const codeVal = code & 0xffff;
191
- if (codeLen < 1 || codeSize < codeLen) {
192
- throw new FormatError("Bad encoding in flate stream");
193
- }
194
- this.codeBuf = codeBuf >> codeLen;
195
- this.codeSize = codeSize - codeLen;
196
- return codeVal;
197
- }
198
-
199
- generateHuffmanTable(lengths) {
200
- const n = lengths.length;
201
-
202
- // find max code length
203
- let maxLen = 0;
204
- let i;
205
- for (i = 0; i < n; ++i) {
206
- if (lengths[i] > maxLen) {
207
- maxLen = lengths[i];
208
- }
209
- }
210
-
211
- // build the table
212
- const size = 1 << maxLen;
213
- const codes = new Int32Array(size);
214
- for (
215
- let len = 1, code = 0, skip = 2;
216
- len <= maxLen;
217
- ++len, code <<= 1, skip <<= 1
218
- ) {
219
- for (let val = 0; val < n; ++val) {
220
- if (lengths[val] === len) {
221
- // bit-reverse the code
222
- let code2 = 0;
223
- let t = code;
224
- for (i = 0; i < len; ++i) {
225
- code2 = (code2 << 1) | (t & 1);
226
- t >>= 1;
227
- }
228
-
229
- // fill the table entries
230
- for (i = code2; i < size; i += skip) {
231
- codes[i] = (len << 16) | val;
232
- }
233
- ++code;
234
- }
235
- }
236
- }
237
-
238
- return [codes, maxLen];
239
- }
240
-
241
- readBlock() {
242
- let buffer, len;
243
- const str = this.str;
244
- // read block header
245
- let hdr = this.getBits(3);
246
- if (hdr & 1) {
247
- this.eof = true;
248
- }
249
- hdr >>= 1;
250
-
251
- if (hdr === 0) {
252
- // uncompressed block
253
- let b;
254
-
255
- if ((b = str.getByte()) === -1) {
256
- throw new FormatError("Bad block header in flate stream");
257
- }
258
- let blockLen = b;
259
- if ((b = str.getByte()) === -1) {
260
- throw new FormatError("Bad block header in flate stream");
261
- }
262
- blockLen |= b << 8;
263
- if ((b = str.getByte()) === -1) {
264
- throw new FormatError("Bad block header in flate stream");
265
- }
266
- let check = b;
267
- if ((b = str.getByte()) === -1) {
268
- throw new FormatError("Bad block header in flate stream");
269
- }
270
- check |= b << 8;
271
- if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
272
- // Ignoring error for bad "empty" block (see issue 1277)
273
- throw new FormatError("Bad uncompressed block length in flate stream");
274
- }
275
-
276
- this.codeBuf = 0;
277
- this.codeSize = 0;
278
-
279
- const bufferLength = this.bufferLength,
280
- end = bufferLength + blockLen;
281
- buffer = this.ensureBuffer(end);
282
- this.bufferLength = end;
283
-
284
- if (blockLen === 0) {
285
- if (str.peekByte() === -1) {
286
- this.eof = true;
287
- }
288
- } else {
289
- const block = str.getBytes(blockLen);
290
- buffer.set(block, bufferLength);
291
- if (block.length < blockLen) {
292
- this.eof = true;
293
- }
294
- }
295
- return;
296
- }
297
-
298
- let litCodeTable;
299
- let distCodeTable;
300
- if (hdr === 1) {
301
- // compressed block, fixed codes
302
- litCodeTable = fixedLitCodeTab;
303
- distCodeTable = fixedDistCodeTab;
304
- } else if (hdr === 2) {
305
- // compressed block, dynamic codes
306
- const numLitCodes = this.getBits(5) + 257;
307
- const numDistCodes = this.getBits(5) + 1;
308
- const numCodeLenCodes = this.getBits(4) + 4;
309
-
310
- // build the code lengths code table
311
- const codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
312
-
313
- let i;
314
- for (i = 0; i < numCodeLenCodes; ++i) {
315
- codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
316
- }
317
- const codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
318
-
319
- // build the literal and distance code tables
320
- len = 0;
321
- i = 0;
322
- const codes = numLitCodes + numDistCodes;
323
- const codeLengths = new Uint8Array(codes);
324
- let bitsLength, bitsOffset, what;
325
- while (i < codes) {
326
- const code = this.getCode(codeLenCodeTab);
327
- if (code === 16) {
328
- bitsLength = 2;
329
- bitsOffset = 3;
330
- what = len;
331
- } else if (code === 17) {
332
- bitsLength = 3;
333
- bitsOffset = 3;
334
- what = len = 0;
335
- } else if (code === 18) {
336
- bitsLength = 7;
337
- bitsOffset = 11;
338
- what = len = 0;
339
- } else {
340
- codeLengths[i++] = len = code;
341
- continue;
342
- }
343
-
344
- let repeatLength = this.getBits(bitsLength) + bitsOffset;
345
- while (repeatLength-- > 0) {
346
- codeLengths[i++] = what;
347
- }
348
- }
349
-
350
- litCodeTable = this.generateHuffmanTable(
351
- codeLengths.subarray(0, numLitCodes)
352
- );
353
- distCodeTable = this.generateHuffmanTable(
354
- codeLengths.subarray(numLitCodes, codes)
355
- );
356
- } else {
357
- throw new FormatError("Unknown block type in flate stream");
358
- }
359
-
360
- buffer = this.buffer;
361
- let limit = buffer ? buffer.length : 0;
362
- let pos = this.bufferLength;
363
- while (true) {
364
- let code1 = this.getCode(litCodeTable);
365
- if (code1 < 256) {
366
- if (pos + 1 >= limit) {
367
- buffer = this.ensureBuffer(pos + 1);
368
- limit = buffer.length;
369
- }
370
- buffer[pos++] = code1;
371
- continue;
372
- }
373
- if (code1 === 256) {
374
- this.bufferLength = pos;
375
- return;
376
- }
377
- code1 -= 257;
378
- code1 = lengthDecode[code1];
379
- let code2 = code1 >> 16;
380
- if (code2 > 0) {
381
- code2 = this.getBits(code2);
382
- }
383
- len = (code1 & 0xffff) + code2;
384
- code1 = this.getCode(distCodeTable);
385
- code1 = distDecode[code1];
386
- code2 = code1 >> 16;
387
- if (code2 > 0) {
388
- code2 = this.getBits(code2);
389
- }
390
- const dist = (code1 & 0xffff) + code2;
391
- if (pos + len >= limit) {
392
- buffer = this.ensureBuffer(pos + len);
393
- limit = buffer.length;
394
- }
395
- for (let k = 0; k < len; ++k, ++pos) {
396
- buffer[pos] = buffer[pos - dist];
397
- }
398
- }
399
- }
400
- }
401
-
402
- export { FlateStream };