pdfjs-dist 2.6.347 → 2.7.570

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.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

Files changed (158) hide show
  1. package/README.md +3 -3
  2. package/bower.json +1 -1
  3. package/build/pdf.js +2050 -1087
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +18219 -10436
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/es5/build/pdf.d.ts +1 -0
  10. package/es5/build/pdf.js +6623 -6654
  11. package/es5/build/pdf.js.map +1 -1
  12. package/es5/build/pdf.min.js +1 -1
  13. package/es5/build/pdf.worker.js +20815 -13888
  14. package/es5/build/pdf.worker.js.map +1 -1
  15. package/es5/build/pdf.worker.min.js +1 -1
  16. package/es5/image_decoders/pdf.image_decoders.js +3817 -4946
  17. package/es5/image_decoders/pdf.image_decoders.js.map +1 -1
  18. package/es5/image_decoders/pdf.image_decoders.min.js +1 -1
  19. package/es5/web/pdf_viewer.css +18 -15
  20. package/es5/web/pdf_viewer.js +1094 -514
  21. package/es5/web/pdf_viewer.js.map +1 -1
  22. package/image_decoders/pdf.image_decoders.js +774 -168
  23. package/image_decoders/pdf.image_decoders.js.map +1 -1
  24. package/image_decoders/pdf.image_decoders.min.js +1 -1
  25. package/lib/core/annotation.js +556 -108
  26. package/lib/core/cff_parser.js +7 -1
  27. package/lib/core/charsets.js +1 -1
  28. package/lib/core/cmap.js +20 -1
  29. package/lib/core/core_utils.js +162 -3
  30. package/lib/core/crypto.js +1 -1
  31. package/lib/core/default_appearance.js +132 -0
  32. package/lib/core/document.js +115 -9
  33. package/lib/core/encodings.js +1 -1
  34. package/lib/core/evaluator.js +168 -74
  35. package/lib/core/fonts.js +97 -11
  36. package/lib/core/function.js +5 -10
  37. package/lib/core/glyphlist.js +11 -4529
  38. package/lib/core/image_utils.js +30 -1
  39. package/lib/core/jpg.js +1 -1
  40. package/lib/core/jpx.js +5 -5
  41. package/lib/core/murmurhash3.js +1 -1
  42. package/lib/core/obj.js +123 -39
  43. package/lib/core/pattern.js +4 -4
  44. package/lib/core/primitives.js +24 -5
  45. package/lib/core/standard_fonts.js +1 -1
  46. package/lib/core/stream.js +5 -1
  47. package/lib/core/unicode.js +15 -1387
  48. package/lib/core/worker.js +58 -17
  49. package/lib/core/writer.js +68 -4
  50. package/lib/display/annotation_layer.js +712 -119
  51. package/lib/display/annotation_storage.js +21 -4
  52. package/lib/display/api.js +88 -18
  53. package/lib/display/canvas.js +414 -375
  54. package/lib/display/display_utils.js +11 -4
  55. package/lib/display/fetch_stream.js +3 -3
  56. package/lib/display/font_loader.js +2 -3
  57. package/lib/display/metadata.js +54 -20
  58. package/lib/display/node_stream.js +1 -1
  59. package/lib/display/optional_content_config.js +1 -1
  60. package/lib/display/pattern_helper.js +109 -113
  61. package/lib/display/svg.js +5 -5
  62. package/lib/display/text_layer.js +54 -54
  63. package/lib/display/transport_stream.js +4 -4
  64. package/lib/display/webgl.js +65 -68
  65. package/lib/examples/node/domstubs.js +9 -4
  66. package/lib/pdf.js +2 -2
  67. package/lib/pdf.sandbox.js +311 -0
  68. package/lib/pdf.worker.js +2 -2
  69. package/lib/shared/scripting_utils.js +84 -0
  70. package/lib/shared/util.js +129 -14
  71. package/lib/{display → shared}/xml_parser.js +112 -4
  72. package/lib/test/unit/annotation_spec.js +831 -109
  73. package/lib/test/unit/annotation_storage_spec.js +28 -10
  74. package/lib/test/unit/api_spec.js +190 -160
  75. package/lib/test/unit/bidi_spec.js +6 -6
  76. package/lib/test/unit/cff_parser_spec.js +73 -73
  77. package/lib/test/unit/clitests_helper.js +2 -0
  78. package/lib/test/unit/cmap_spec.js +48 -74
  79. package/lib/test/unit/core_utils_spec.js +34 -0
  80. package/lib/test/unit/crypto_spec.js +162 -199
  81. package/lib/test/unit/custom_spec.js +7 -18
  82. package/lib/test/unit/default_appearance_spec.js +54 -0
  83. package/lib/test/unit/display_svg_spec.js +24 -19
  84. package/lib/test/unit/display_utils_spec.js +1 -1
  85. package/lib/test/unit/document_spec.js +187 -20
  86. package/lib/test/unit/evaluator_spec.js +30 -30
  87. package/lib/test/unit/function_spec.js +165 -165
  88. package/lib/test/unit/jasmine-boot.js +52 -53
  89. package/lib/test/unit/metadata_spec.js +2 -2
  90. package/lib/test/unit/murmurhash3_spec.js +29 -16
  91. package/lib/test/unit/network_spec.js +21 -21
  92. package/lib/test/unit/pdf_find_controller_spec.js +131 -69
  93. package/lib/test/unit/pdf_find_utils_spec.js +10 -10
  94. package/lib/test/unit/scripting_spec.js +1104 -0
  95. package/lib/test/unit/stream_spec.js +8 -8
  96. package/lib/test/unit/test_utils.js +16 -19
  97. package/lib/test/unit/testreporter.js +11 -4
  98. package/lib/test/unit/type1_parser_spec.js +23 -23
  99. package/lib/test/unit/ui_utils_spec.js +78 -35
  100. package/lib/test/unit/unicode_spec.js +7 -7
  101. package/lib/test/unit/util_spec.js +26 -3
  102. package/lib/test/unit/writer_spec.js +16 -1
  103. package/lib/test/unit/xml_spec.js +117 -0
  104. package/lib/web/annotation_layer_builder.js +18 -6
  105. package/lib/web/app.js +579 -161
  106. package/lib/web/app_options.js +14 -0
  107. package/lib/web/base_tree_viewer.js +50 -0
  108. package/lib/web/base_viewer.js +350 -14
  109. package/lib/web/chromecom.js +9 -1
  110. package/lib/web/debugger.js +1 -2
  111. package/lib/web/download_manager.js +0 -15
  112. package/lib/web/firefox_print_service.js +6 -4
  113. package/lib/web/firefoxcom.js +84 -69
  114. package/lib/web/generic_scripting.js +55 -0
  115. package/lib/web/genericcom.js +9 -1
  116. package/lib/web/grab_to_pan.js +1 -1
  117. package/lib/web/interfaces.js +9 -3
  118. package/lib/web/pdf_attachment_viewer.js +1 -3
  119. package/lib/web/pdf_cursor_tools.js +20 -13
  120. package/lib/web/pdf_document_properties.js +48 -61
  121. package/lib/web/pdf_find_bar.js +1 -3
  122. package/lib/web/pdf_find_controller.js +58 -12
  123. package/lib/web/pdf_history.js +43 -21
  124. package/lib/web/pdf_layer_viewer.js +1 -9
  125. package/lib/web/pdf_link_service.js +108 -78
  126. package/lib/web/pdf_outline_viewer.js +166 -10
  127. package/lib/web/pdf_page_view.js +14 -14
  128. package/lib/web/pdf_presentation_mode.js +21 -31
  129. package/lib/web/pdf_rendering_queue.js +8 -1
  130. package/lib/web/pdf_sidebar.js +62 -107
  131. package/lib/web/pdf_sidebar_resizer.js +11 -21
  132. package/lib/web/pdf_single_page_viewer.js +8 -0
  133. package/lib/web/pdf_thumbnail_view.js +26 -26
  134. package/lib/web/pdf_thumbnail_viewer.js +13 -2
  135. package/lib/web/pdf_viewer.component.js +2 -2
  136. package/lib/web/pdf_viewer.js +3 -1
  137. package/lib/web/preferences.js +33 -44
  138. package/lib/web/text_layer_builder.js +2 -9
  139. package/lib/web/ui_utils.js +78 -46
  140. package/lib/web/viewer_compatibility.js +1 -2
  141. package/package.json +4 -1
  142. package/types/display/annotation_layer.d.ts +18 -3
  143. package/types/display/api.d.ts +110 -54
  144. package/types/display/canvas.d.ts +1 -1
  145. package/types/display/display_utils.d.ts +96 -95
  146. package/types/display/fetch_stream.d.ts +2 -2
  147. package/types/display/metadata.d.ts +4 -0
  148. package/types/display/pattern_helper.d.ts +1 -1
  149. package/types/display/text_layer.d.ts +7 -7
  150. package/types/display/transport_stream.d.ts +1 -1
  151. package/types/shared/scripting_utils.d.ts +12 -0
  152. package/types/shared/util.d.ts +281 -250
  153. package/types/shared/xml_parser.d.ts +64 -0
  154. package/web/pdf_viewer.css +18 -15
  155. package/web/pdf_viewer.js +809 -408
  156. package/web/pdf_viewer.js.map +1 -1
  157. package/webpack.js +1 -1
  158. package/types/display/xml_parser.d.ts +0 -35
package/lib/pdf.worker.js CHANGED
@@ -33,5 +33,5 @@ Object.defineProperty(exports, "WorkerMessageHandler", {
33
33
 
34
34
  var _worker = require("./core/worker.js");
35
35
 
36
- const pdfjsVersion = '2.6.347';
37
- const pdfjsBuild = '3be9c65f';
36
+ const pdfjsVersion = '2.7.570';
37
+ const pdfjsBuild = 'f2c7338b0';
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @licstart The following is the entire license notice for the
3
+ * Javascript code in this page
4
+ *
5
+ * Copyright 2020 Mozilla Foundation
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ * @licend The above is the entire license notice for the
20
+ * Javascript code in this page
21
+ */
22
+ "use strict";
23
+
24
+ Object.defineProperty(exports, "__esModule", {
25
+ value: true
26
+ });
27
+ exports.ColorConverters = void 0;
28
+
29
+ function makeColorComp(n) {
30
+ return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
31
+ }
32
+
33
+ class ColorConverters {
34
+ static CMYK_G([c, y, m, k]) {
35
+ return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
36
+ }
37
+
38
+ static G_CMYK([g]) {
39
+ return ["CMYK", 0, 0, 0, 1 - g];
40
+ }
41
+
42
+ static G_RGB([g]) {
43
+ return ["RGB", g, g, g];
44
+ }
45
+
46
+ static G_HTML([g]) {
47
+ const G = makeColorComp(g);
48
+ return `#${G}${G}${G}`;
49
+ }
50
+
51
+ static RGB_G([r, g, b]) {
52
+ return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
53
+ }
54
+
55
+ static RGB_HTML([r, g, b]) {
56
+ const R = makeColorComp(r);
57
+ const G = makeColorComp(g);
58
+ const B = makeColorComp(b);
59
+ return `#${R}${G}${B}`;
60
+ }
61
+
62
+ static T_HTML() {
63
+ return "#00000000";
64
+ }
65
+
66
+ static CMYK_RGB([c, y, m, k]) {
67
+ return ["RGB", 1 - Math.min(1, c + k), 1 - Math.min(1, m + k), 1 - Math.min(1, y + k)];
68
+ }
69
+
70
+ static CMYK_HTML(components) {
71
+ return this.RGB_HTML(this.CMYK_RGB(components));
72
+ }
73
+
74
+ static RGB_CMYK([r, g, b]) {
75
+ const c = 1 - r;
76
+ const m = 1 - g;
77
+ const y = 1 - b;
78
+ const k = Math.min(c, m, y);
79
+ return ["CMYK", c, m, y, k];
80
+ }
81
+
82
+ }
83
+
84
+ exports.ColorConverters = ColorConverters;
@@ -29,28 +29,33 @@ exports.arraysToBytes = arraysToBytes;
29
29
  exports.assert = assert;
30
30
  exports.bytesToString = bytesToString;
31
31
  exports.createPromiseCapability = createPromiseCapability;
32
+ exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
33
+ exports.encodeToXmlString = encodeToXmlString;
32
34
  exports.escapeString = escapeString;
33
35
  exports.getModificationDate = getModificationDate;
34
36
  exports.getVerbosityLevel = getVerbosityLevel;
35
37
  exports.info = info;
36
38
  exports.isArrayBuffer = isArrayBuffer;
37
39
  exports.isArrayEqual = isArrayEqual;
40
+ exports.isAscii = isAscii;
38
41
  exports.isBool = isBool;
39
42
  exports.isNum = isNum;
40
- exports.isString = isString;
41
43
  exports.isSameOrigin = isSameOrigin;
42
- exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
44
+ exports.isString = isString;
45
+ exports.objectFromEntries = objectFromEntries;
46
+ exports.objectSize = objectSize;
43
47
  exports.removeNullCharacters = removeNullCharacters;
44
48
  exports.setVerbosityLevel = setVerbosityLevel;
45
49
  exports.shadow = shadow;
46
50
  exports.string32 = string32;
47
51
  exports.stringToBytes = stringToBytes;
48
52
  exports.stringToPDFString = stringToPDFString;
53
+ exports.stringToUTF16BEString = stringToUTF16BEString;
49
54
  exports.stringToUTF8String = stringToUTF8String;
55
+ exports.unreachable = unreachable;
50
56
  exports.utf8StringToString = utf8StringToString;
51
57
  exports.warn = warn;
52
- exports.unreachable = unreachable;
53
- exports.IsEvalSupportedCached = exports.IsLittleEndianCached = exports.createObjectURL = exports.FormatError = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.MissingPDFException = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VerbosityLevel = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = exports.BaseException = void 0;
58
+ exports.VerbosityLevel = exports.Util = exports.UNSUPPORTED_FEATURES = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.IsLittleEndianCached = exports.IsEvalSupportedCached = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FontType = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.createObjectURL = exports.CMapCompressionType = exports.BaseException = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.AnnotationActionEventType = exports.AbortException = void 0;
54
59
 
55
60
  require("./compatibility.js");
56
61
 
@@ -183,6 +188,36 @@ const AnnotationBorderStyleType = {
183
188
  UNDERLINE: 5
184
189
  };
185
190
  exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
191
+ const AnnotationActionEventType = {
192
+ E: "Mouse Enter",
193
+ X: "Mouse Exit",
194
+ D: "Mouse Down",
195
+ U: "Mouse Up",
196
+ Fo: "Focus",
197
+ Bl: "Blur",
198
+ PO: "PageOpen",
199
+ PC: "PageClose",
200
+ PV: "PageVisible",
201
+ PI: "PageInvisible",
202
+ K: "Keystroke",
203
+ F: "Format",
204
+ V: "Validate",
205
+ C: "Calculate"
206
+ };
207
+ exports.AnnotationActionEventType = AnnotationActionEventType;
208
+ const DocumentActionEventType = {
209
+ WC: "WillClose",
210
+ WS: "WillSave",
211
+ DS: "DidSave",
212
+ WP: "WillPrint",
213
+ DP: "DidPrint"
214
+ };
215
+ exports.DocumentActionEventType = DocumentActionEventType;
216
+ const PageActionEventType = {
217
+ O: "PageOpen",
218
+ C: "PageClose"
219
+ };
220
+ exports.PageActionEventType = PageActionEventType;
186
221
  const StreamType = {
187
222
  UNKNOWN: "UNKNOWN",
188
223
  FLATE: "FLATE",
@@ -591,6 +626,14 @@ function string32(value) {
591
626
  return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
592
627
  }
593
628
 
629
+ function objectSize(obj) {
630
+ return Object.keys(obj).length;
631
+ }
632
+
633
+ function objectFromEntries(iterable) {
634
+ return Object.assign(Object.create(null), Object.fromEntries(iterable));
635
+ }
636
+
594
637
  function isLittleEndian() {
595
638
  const buffer8 = new Uint8Array(4);
596
639
  buffer8[0] = 1;
@@ -622,14 +665,11 @@ const IsEvalSupportedCached = {
622
665
 
623
666
  };
624
667
  exports.IsEvalSupportedCached = IsEvalSupportedCached;
625
- const rgbBuf = ["rgb(", 0, ",", 0, ",", 0, ")"];
668
+ const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
626
669
 
627
670
  class Util {
628
- static makeCssRgb(r, g, b) {
629
- rgbBuf[1] = r;
630
- rgbBuf[3] = g;
631
- rgbBuf[5] = b;
632
- return rgbBuf.join("");
671
+ static makeHexColor(r, g, b) {
672
+ return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
633
673
  }
634
674
 
635
675
  static transform(m1, m2) {
@@ -751,7 +791,31 @@ function stringToPDFString(str) {
751
791
  }
752
792
 
753
793
  function escapeString(str) {
754
- return str.replace(/([\(\)\\])/g, "\\$1");
794
+ return str.replace(/([()\\\n\r])/g, match => {
795
+ if (match === "\n") {
796
+ return "\\n";
797
+ } else if (match === "\r") {
798
+ return "\\r";
799
+ }
800
+
801
+ return `\\${match}`;
802
+ });
803
+ }
804
+
805
+ function isAscii(str) {
806
+ return /^[\x00-\x7F]*$/.test(str);
807
+ }
808
+
809
+ function stringToUTF16BEString(str) {
810
+ const buf = ["\xFE\xFF"];
811
+
812
+ for (let i = 0, ii = str.length; i < ii; i++) {
813
+ const char = str.charCodeAt(i);
814
+ buf.push(String.fromCharCode(char >> 8 & 0xff));
815
+ buf.push(String.fromCharCode(char & 0xff));
816
+ }
817
+
818
+ return buf.join("");
755
819
  }
756
820
 
757
821
  function stringToUTF8String(str) {
@@ -788,8 +852,8 @@ function isArrayEqual(arr1, arr2) {
788
852
  });
789
853
  }
790
854
 
791
- function getModificationDate(date = new Date(Date.now())) {
792
- const buffer = [date.getUTCFullYear().toString(), (date.getUTCMonth() + 1).toString().padStart(2, "0"), (date.getUTCDate() + 1).toString().padStart(2, "0"), date.getUTCHours().toString().padStart(2, "0"), date.getUTCMinutes().toString().padStart(2, "0"), date.getUTCSeconds().toString().padStart(2, "0")];
855
+ function getModificationDate(date = new Date()) {
856
+ const buffer = [date.getUTCFullYear().toString(), (date.getUTCMonth() + 1).toString().padStart(2, "0"), date.getUTCDate().toString().padStart(2, "0"), date.getUTCHours().toString().padStart(2, "0"), date.getUTCMinutes().toString().padStart(2, "0"), date.getUTCSeconds().toString().padStart(2, "0")];
793
857
  return buffer.join("");
794
858
  }
795
859
 
@@ -843,4 +907,55 @@ const createObjectURL = function createObjectURLClosure() {
843
907
  };
844
908
  }();
845
909
 
846
- exports.createObjectURL = createObjectURL;
910
+ exports.createObjectURL = createObjectURL;
911
+ const XMLEntities = {
912
+ 0x3c: "&lt;",
913
+ 0x3e: "&gt;",
914
+ 0x26: "&amp;",
915
+ 0x22: "&quot;",
916
+ 0x27: "&apos;"
917
+ };
918
+
919
+ function encodeToXmlString(str) {
920
+ const buffer = [];
921
+ let start = 0;
922
+
923
+ for (let i = 0, ii = str.length; i < ii; i++) {
924
+ const char = str.codePointAt(i);
925
+
926
+ if (0x20 <= char && char <= 0x7e) {
927
+ const entity = XMLEntities[char];
928
+
929
+ if (entity) {
930
+ if (start < i) {
931
+ buffer.push(str.substring(start, i));
932
+ }
933
+
934
+ buffer.push(entity);
935
+ start = i + 1;
936
+ }
937
+ } else {
938
+ if (start < i) {
939
+ buffer.push(str.substring(start, i));
940
+ }
941
+
942
+ buffer.push(`&#x${char.toString(16).toUpperCase()};`);
943
+
944
+ if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) {
945
+ i++;
946
+ }
947
+
948
+ start = i + 1;
949
+ }
950
+ }
951
+
952
+ if (buffer.length === 0) {
953
+ return str;
954
+ }
955
+
956
+ if (start < str.length) {
957
+ buffer.push(str.substring(start, str.length));
958
+ }
959
+
960
+ return buffer.join("");
961
+ }
@@ -24,7 +24,10 @@
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.SimpleXMLParser = void 0;
27
+ exports.SimpleXMLParser = exports.SimpleDOMNode = void 0;
28
+
29
+ var _util = require("./util.js");
30
+
28
31
  const XMLParserErrorCode = {
29
32
  NoError: 0,
30
33
  EndOfDocument: -1,
@@ -58,9 +61,9 @@ class XMLParserBase {
58
61
  _resolveEntities(s) {
59
62
  return s.replace(/&([^;]+);/g, (all, entity) => {
60
63
  if (entity.substring(0, 2) === "#x") {
61
- return String.fromCharCode(parseInt(entity.substring(2), 16));
64
+ return String.fromCodePoint(parseInt(entity.substring(2), 16));
62
65
  } else if (entity.substring(0, 1) === "#") {
63
- return String.fromCharCode(parseInt(entity.substring(1), 10));
66
+ return String.fromCodePoint(parseInt(entity.substring(1), 10));
64
67
  }
65
68
 
66
69
  switch (entity) {
@@ -365,14 +368,111 @@ class SimpleDOMNode {
365
368
  return this.childNodes && this.childNodes.length > 0;
366
369
  }
367
370
 
371
+ searchNode(paths, pos) {
372
+ if (pos >= paths.length) {
373
+ return this;
374
+ }
375
+
376
+ const component = paths[pos];
377
+ const stack = [];
378
+ let node = this;
379
+
380
+ while (true) {
381
+ if (component.name === node.nodeName) {
382
+ if (component.pos === 0) {
383
+ const res = node.searchNode(paths, pos + 1);
384
+
385
+ if (res !== null) {
386
+ return res;
387
+ }
388
+ } else if (stack.length === 0) {
389
+ return null;
390
+ } else {
391
+ const [parent] = stack.pop();
392
+ let siblingPos = 0;
393
+
394
+ for (const child of parent.childNodes) {
395
+ if (component.name === child.nodeName) {
396
+ if (siblingPos === component.pos) {
397
+ return child.searchNode(paths, pos + 1);
398
+ }
399
+
400
+ siblingPos++;
401
+ }
402
+ }
403
+
404
+ return node.searchNode(paths, pos + 1);
405
+ }
406
+ }
407
+
408
+ if (node.childNodes && node.childNodes.length !== 0) {
409
+ stack.push([node, 0]);
410
+ node = node.childNodes[0];
411
+ } else if (stack.length === 0) {
412
+ return null;
413
+ } else {
414
+ while (stack.length !== 0) {
415
+ const [parent, currentPos] = stack.pop();
416
+ const newPos = currentPos + 1;
417
+
418
+ if (newPos < parent.childNodes.length) {
419
+ stack.push([parent, newPos]);
420
+ node = parent.childNodes[newPos];
421
+ break;
422
+ }
423
+ }
424
+
425
+ if (stack.length === 0) {
426
+ return null;
427
+ }
428
+ }
429
+ }
430
+ }
431
+
432
+ dump(buffer) {
433
+ if (this.nodeName === "#text") {
434
+ buffer.push((0, _util.encodeToXmlString)(this.nodeValue));
435
+ return;
436
+ }
437
+
438
+ buffer.push(`<${this.nodeName}`);
439
+
440
+ if (this.attributes) {
441
+ for (const attribute of this.attributes) {
442
+ buffer.push(` ${attribute.name}="${(0, _util.encodeToXmlString)(attribute.value)}"`);
443
+ }
444
+ }
445
+
446
+ if (this.hasChildNodes()) {
447
+ buffer.push(">");
448
+
449
+ for (const child of this.childNodes) {
450
+ child.dump(buffer);
451
+ }
452
+
453
+ buffer.push(`</${this.nodeName}>`);
454
+ } else if (this.nodeValue) {
455
+ buffer.push(`>${(0, _util.encodeToXmlString)(this.nodeValue)}</${this.nodeName}>`);
456
+ } else {
457
+ buffer.push("/>");
458
+ }
459
+ }
460
+
368
461
  }
369
462
 
463
+ exports.SimpleDOMNode = SimpleDOMNode;
464
+
370
465
  class SimpleXMLParser extends XMLParserBase {
371
- constructor() {
466
+ constructor({
467
+ hasAttributes = false,
468
+ lowerCaseName = false
469
+ }) {
372
470
  super();
373
471
  this._currentFragment = null;
374
472
  this._stack = null;
375
473
  this._errorCode = XMLParserErrorCode.NoError;
474
+ this._hasAttributes = hasAttributes;
475
+ this._lowerCaseName = lowerCaseName;
376
476
  }
377
477
 
378
478
  parseFromString(data) {
@@ -422,9 +522,17 @@ class SimpleXMLParser extends XMLParserBase {
422
522
  }
423
523
 
424
524
  onBeginElement(name, attributes, isEmpty) {
525
+ if (this._lowerCaseName) {
526
+ name = name.toLowerCase();
527
+ }
528
+
425
529
  const node = new SimpleDOMNode(name);
426
530
  node.childNodes = [];
427
531
 
532
+ if (this._hasAttributes) {
533
+ node.attributes = attributes;
534
+ }
535
+
428
536
  this._currentFragment.push(node);
429
537
 
430
538
  if (isEmpty) {