pdfjs-dist 2.2.228 → 2.6.347

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 (229) hide show
  1. package/README.md +4 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +8816 -19300
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +22 -1
  6. package/build/pdf.worker.entry.js +5 -3
  7. package/build/pdf.worker.js +27185 -35746
  8. package/build/pdf.worker.js.map +1 -1
  9. package/build/pdf.worker.min.js +22 -1
  10. package/es5/build/pdf.js +26665 -0
  11. package/es5/build/pdf.js.map +1 -0
  12. package/es5/build/pdf.min.js +22 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +61231 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/build/pdf.worker.min.js +22 -0
  17. package/es5/image_decoders/pdf.image_decoders.js +12529 -0
  18. package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
  19. package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
  20. package/es5/web/images/annotation-check.svg +11 -0
  21. package/es5/web/images/annotation-comment.svg +16 -0
  22. package/es5/web/images/annotation-help.svg +26 -0
  23. package/es5/web/images/annotation-insert.svg +10 -0
  24. package/es5/web/images/annotation-key.svg +11 -0
  25. package/es5/web/images/annotation-newparagraph.svg +11 -0
  26. package/es5/web/images/annotation-noicon.svg +7 -0
  27. package/es5/web/images/annotation-note.svg +42 -0
  28. package/es5/web/images/annotation-paragraph.svg +16 -0
  29. package/es5/web/images/loading-icon.gif +0 -0
  30. package/es5/web/images/shadow.png +0 -0
  31. package/es5/web/pdf_viewer.css +406 -0
  32. package/es5/web/pdf_viewer.js +7886 -0
  33. package/es5/web/pdf_viewer.js.map +1 -0
  34. package/image_decoders/pdf.image_decoders.js +1498 -4832
  35. package/image_decoders/pdf.image_decoders.js.map +1 -1
  36. package/image_decoders/pdf.image_decoders.min.js +22 -1
  37. package/lib/README.md +7 -0
  38. package/lib/core/annotation.js +1144 -927
  39. package/lib/core/arithmetic_decoder.js +81 -97
  40. package/lib/core/bidi.js +54 -46
  41. package/lib/core/ccitt.js +88 -81
  42. package/lib/core/ccitt_stream.js +15 -14
  43. package/lib/core/cff_parser.js +747 -716
  44. package/lib/core/charsets.js +4 -4
  45. package/lib/core/chunked_stream.js +462 -553
  46. package/lib/core/cmap.js +231 -277
  47. package/lib/core/colorspace.js +715 -857
  48. package/lib/core/core_utils.js +57 -52
  49. package/lib/core/crypto.js +416 -437
  50. package/lib/core/document.js +629 -670
  51. package/lib/core/encodings.js +15 -15
  52. package/lib/core/evaluator.js +3229 -2800
  53. package/lib/core/font_renderer.js +135 -178
  54. package/lib/core/fonts.js +602 -534
  55. package/lib/core/function.js +355 -279
  56. package/lib/core/glyphlist.js +4527 -4526
  57. package/lib/core/image.js +442 -439
  58. package/lib/core/image_utils.js +221 -61
  59. package/lib/core/jbig2.js +325 -316
  60. package/lib/core/jbig2_stream.js +18 -17
  61. package/lib/core/jpeg_stream.js +21 -26
  62. package/lib/core/jpg.js +289 -233
  63. package/lib/core/jpx.js +161 -143
  64. package/lib/core/jpx_stream.js +28 -28
  65. package/lib/core/metrics.js +2928 -2928
  66. package/lib/core/murmurhash3.js +87 -102
  67. package/lib/core/obj.js +1343 -1300
  68. package/lib/core/operator_list.js +90 -67
  69. package/lib/core/parser.js +990 -987
  70. package/lib/core/pattern.js +105 -77
  71. package/lib/core/pdf_manager.js +149 -316
  72. package/lib/core/primitives.js +156 -104
  73. package/lib/core/ps_parser.js +175 -214
  74. package/lib/core/standard_fonts.js +237 -236
  75. package/lib/core/stream.js +94 -74
  76. package/lib/core/type1_parser.js +89 -69
  77. package/lib/core/unicode.js +1654 -1654
  78. package/lib/core/worker.js +275 -290
  79. package/lib/core/worker_stream.js +101 -210
  80. package/lib/core/writer.js +242 -0
  81. package/lib/display/annotation_layer.js +772 -1041
  82. package/lib/display/annotation_storage.js +89 -0
  83. package/lib/display/api.js +1575 -1868
  84. package/lib/display/api_compatibility.js +12 -17
  85. package/lib/display/canvas.js +370 -222
  86. package/lib/display/content_disposition.js +40 -59
  87. package/lib/display/display_utils.js +341 -536
  88. package/lib/display/fetch_stream.js +188 -304
  89. package/lib/display/font_loader.js +282 -414
  90. package/lib/display/metadata.js +81 -99
  91. package/lib/display/network.js +362 -511
  92. package/lib/display/network_utils.js +25 -18
  93. package/lib/display/node_stream.js +283 -465
  94. package/lib/display/node_utils.js +87 -0
  95. package/lib/display/optional_content_config.js +184 -0
  96. package/lib/display/pattern_helper.js +93 -44
  97. package/lib/display/svg.js +1163 -1401
  98. package/lib/display/text_layer.js +154 -137
  99. package/lib/display/transport_stream.js +237 -375
  100. package/lib/display/webgl.js +70 -83
  101. package/lib/display/worker_options.js +3 -3
  102. package/lib/display/xml_parser.js +303 -392
  103. package/lib/examples/node/domstubs.js +37 -37
  104. package/lib/pdf.js +220 -58
  105. package/lib/pdf.worker.js +14 -6
  106. package/lib/shared/compatibility.js +3 -246
  107. package/lib/shared/is_node.js +7 -6
  108. package/lib/shared/message_handler.js +327 -332
  109. package/lib/shared/util.js +271 -306
  110. package/lib/test/unit/annotation_spec.js +1902 -763
  111. package/lib/test/unit/annotation_storage_spec.js +83 -0
  112. package/lib/test/unit/api_spec.js +790 -592
  113. package/lib/test/unit/bidi_spec.js +7 -7
  114. package/lib/test/unit/cff_parser_spec.js +73 -72
  115. package/lib/test/unit/clitests_helper.js +7 -9
  116. package/lib/test/unit/cmap_spec.js +86 -88
  117. package/lib/test/unit/colorspace_spec.js +346 -154
  118. package/lib/test/unit/core_utils_spec.js +125 -105
  119. package/lib/test/unit/crypto_spec.js +232 -185
  120. package/lib/test/unit/custom_spec.js +150 -24
  121. package/lib/test/unit/display_svg_spec.js +34 -39
  122. package/lib/test/unit/display_utils_spec.js +139 -149
  123. package/lib/test/unit/document_spec.js +128 -17
  124. package/lib/test/unit/encodings_spec.js +12 -34
  125. package/lib/test/unit/evaluator_spec.js +112 -91
  126. package/lib/test/unit/fetch_stream_spec.js +31 -29
  127. package/lib/test/unit/function_spec.js +206 -204
  128. package/lib/test/unit/jasmine-boot.js +48 -32
  129. package/lib/test/unit/message_handler_spec.js +173 -159
  130. package/lib/test/unit/metadata_spec.js +71 -71
  131. package/lib/test/unit/murmurhash3_spec.js +12 -12
  132. package/lib/test/unit/network_spec.js +13 -11
  133. package/lib/test/unit/network_utils_spec.js +158 -144
  134. package/lib/test/unit/node_stream_spec.js +76 -90
  135. package/lib/test/unit/parser_spec.js +108 -114
  136. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  137. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  138. package/lib/test/unit/pdf_history_spec.js +32 -32
  139. package/lib/test/unit/primitives_spec.js +337 -156
  140. package/lib/test/unit/stream_spec.js +16 -14
  141. package/lib/test/unit/test_utils.js +91 -304
  142. package/lib/test/unit/testreporter.js +33 -22
  143. package/lib/test/unit/type1_parser_spec.js +42 -42
  144. package/lib/test/unit/ui_utils_spec.js +299 -461
  145. package/lib/test/unit/unicode_spec.js +42 -42
  146. package/lib/test/unit/util_spec.js +129 -149
  147. package/lib/test/unit/writer_spec.js +84 -0
  148. package/lib/web/annotation_layer_builder.js +78 -111
  149. package/lib/web/app.js +1542 -1267
  150. package/lib/web/app_options.js +76 -91
  151. package/lib/web/base_tree_viewer.js +100 -0
  152. package/lib/web/base_viewer.js +869 -834
  153. package/lib/web/chromecom.js +165 -252
  154. package/lib/web/debugger.js +149 -205
  155. package/lib/web/download_manager.js +34 -58
  156. package/lib/web/firefox_print_service.js +62 -34
  157. package/lib/web/firefoxcom.js +206 -374
  158. package/lib/web/genericcom.js +26 -108
  159. package/lib/web/genericl10n.js +24 -153
  160. package/lib/web/grab_to_pan.js +30 -30
  161. package/lib/web/interfaces.js +80 -254
  162. package/lib/web/overlay_manager.js +70 -246
  163. package/lib/web/password_prompt.js +38 -64
  164. package/lib/web/pdf_attachment_viewer.js +150 -126
  165. package/lib/web/pdf_cursor_tools.js +75 -102
  166. package/lib/web/pdf_document_properties.js +229 -383
  167. package/lib/web/pdf_find_bar.js +136 -170
  168. package/lib/web/pdf_find_controller.js +492 -548
  169. package/lib/web/pdf_find_utils.js +13 -13
  170. package/lib/web/pdf_history.js +397 -406
  171. package/lib/web/pdf_layer_viewer.js +208 -0
  172. package/lib/web/pdf_link_service.js +304 -348
  173. package/lib/web/pdf_outline_viewer.js +119 -212
  174. package/lib/web/pdf_page_view.js +474 -513
  175. package/lib/web/pdf_presentation_mode.js +308 -357
  176. package/lib/web/pdf_print_service.js +96 -110
  177. package/lib/web/pdf_rendering_queue.js +87 -108
  178. package/lib/web/pdf_sidebar.js +286 -302
  179. package/lib/web/pdf_sidebar_resizer.js +92 -119
  180. package/lib/web/pdf_single_page_viewer.js +77 -126
  181. package/lib/web/pdf_thumbnail_view.js +289 -297
  182. package/lib/web/pdf_thumbnail_viewer.js +202 -206
  183. package/lib/web/pdf_viewer.component.js +20 -21
  184. package/lib/web/pdf_viewer.js +55 -115
  185. package/lib/web/preferences.js +69 -273
  186. package/lib/web/secondary_toolbar.js +164 -196
  187. package/lib/web/text_layer_builder.js +284 -319
  188. package/lib/web/toolbar.js +217 -210
  189. package/lib/web/ui_utils.js +274 -421
  190. package/lib/web/view_history.js +52 -226
  191. package/lib/web/viewer_compatibility.js +21 -6
  192. package/package.json +4 -9
  193. package/types/display/annotation_layer.d.ts +61 -0
  194. package/types/display/annotation_storage.d.ts +36 -0
  195. package/types/display/api.d.ts +1107 -0
  196. package/types/display/api_compatibility.d.ts +1 -0
  197. package/types/display/canvas.d.ts +4 -0
  198. package/types/display/content_disposition.d.ts +7 -0
  199. package/types/display/display_utils.d.ts +243 -0
  200. package/types/display/fetch_stream.d.ts +67 -0
  201. package/types/display/font_loader.d.ts +19 -0
  202. package/types/display/metadata.d.ts +9 -0
  203. package/types/display/network.d.ts +80 -0
  204. package/types/display/network_utils.d.ts +14 -0
  205. package/types/display/node_stream.d.ts +72 -0
  206. package/types/display/node_utils.d.ts +6 -0
  207. package/types/display/optional_content_config.d.ts +12 -0
  208. package/types/display/pattern_helper.d.ts +5 -0
  209. package/types/display/svg.d.ts +2 -0
  210. package/types/display/text_layer.d.ts +83 -0
  211. package/types/display/transport_stream.d.ts +57 -0
  212. package/types/display/webgl.d.ts +20 -0
  213. package/types/display/worker_options.d.ts +27 -0
  214. package/types/display/xml_parser.d.ts +35 -0
  215. package/types/pdf.d.ts +33 -0
  216. package/types/shared/compatibility.d.ts +1 -0
  217. package/types/shared/is_node.d.ts +1 -0
  218. package/types/shared/message_handler.d.ts +62 -0
  219. package/types/shared/util.d.ts +421 -0
  220. package/web/images/shadow.png +0 -0
  221. package/web/pdf_viewer.css +29 -27
  222. package/web/pdf_viewer.js +3524 -4746
  223. package/web/pdf_viewer.js.map +1 -1
  224. package/webpack.js +6 -5
  225. package/external/streams/streams-lib.js +0 -3962
  226. package/external/url/url-lib.js +0 -627
  227. package/lib/shared/streams_polyfill.js +0 -43
  228. package/lib/shared/url_polyfill.js +0 -56
  229. package/web/images/texture.png +0 -0
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2019 Mozilla Foundation
5
+ * Copyright 2020 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -26,11 +26,7 @@ Object.defineProperty(exports, "__esModule", {
26
26
  });
27
27
  exports.renderTextLayer = void 0;
28
28
 
29
- var _util = require("../shared/util");
30
-
31
- var _global_scope = _interopRequireDefault(require("../shared/global_scope"));
32
-
33
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
29
+ var _util = require("../shared/util.js");
34
30
 
35
31
  var renderTextLayer = function renderTextLayerClosure() {
36
32
  var MAX_TEXT_DIVS_TO_RENDER = 100000;
@@ -40,12 +36,9 @@ var renderTextLayer = function renderTextLayerClosure() {
40
36
  return !NonWhitespaceRegexp.test(str);
41
37
  }
42
38
 
43
- var styleBuf = ['left: ', 0, 'px; top: ', 0, 'px; font-size: ', 0, 'px; font-family: ', '', ';'];
44
-
45
39
  function appendText(task, geom, styles) {
46
- var textDiv = document.createElement('span');
40
+ var textDiv = document.createElement("span");
47
41
  var textDivProperties = {
48
- style: null,
49
42
  angle: 0,
50
43
  canvasWidth: 0,
51
44
  isWhitespace: false,
@@ -85,8 +78,7 @@ var renderTextLayer = function renderTextLayerClosure() {
85
78
  fontAscent = (1 + style.descent) * fontAscent;
86
79
  }
87
80
 
88
- var left;
89
- var top;
81
+ let left, top;
90
82
 
91
83
  if (angle === 0) {
92
84
  left = tx[4];
@@ -96,12 +88,10 @@ var renderTextLayer = function renderTextLayerClosure() {
96
88
  top = tx[5] - fontAscent * Math.cos(angle);
97
89
  }
98
90
 
99
- styleBuf[1] = left;
100
- styleBuf[3] = top;
101
- styleBuf[5] = fontHeight;
102
- styleBuf[7] = style.fontFamily;
103
- textDivProperties.style = styleBuf.join('');
104
- textDiv.setAttribute('style', textDivProperties.style);
91
+ textDiv.style.left = `${left}px`;
92
+ textDiv.style.top = `${top}px`;
93
+ textDiv.style.fontSize = `${fontHeight}px`;
94
+ textDiv.style.fontFamily = style.fontFamily;
105
95
  textDiv.textContent = geom.str;
106
96
 
107
97
  if (task._fontInspectorEnabled) {
@@ -112,7 +102,20 @@ var renderTextLayer = function renderTextLayerClosure() {
112
102
  textDivProperties.angle = angle * (180 / Math.PI);
113
103
  }
114
104
 
105
+ let shouldScaleText = false;
106
+
115
107
  if (geom.str.length > 1) {
108
+ shouldScaleText = true;
109
+ } else if (geom.transform[0] !== geom.transform[3]) {
110
+ const absScaleX = Math.abs(geom.transform[0]),
111
+ absScaleY = Math.abs(geom.transform[3]);
112
+
113
+ if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
114
+ shouldScaleText = true;
115
+ }
116
+ }
117
+
118
+ if (shouldScaleText) {
116
119
  if (style.vertical) {
117
120
  textDivProperties.canvasWidth = geom.height * task._viewport.scale;
118
121
  } else {
@@ -153,7 +156,7 @@ var renderTextLayer = function renderTextLayerClosure() {
153
156
  bottom: b[3],
154
157
  div: textDiv,
155
158
  size: [divWidth, divHeight],
156
- m: m
159
+ m
157
160
  });
158
161
  }
159
162
  }
@@ -183,6 +186,20 @@ var renderTextLayer = function renderTextLayerClosure() {
183
186
  capability.resolve();
184
187
  }
185
188
 
189
+ function findPositiveMin(ts, offset, count) {
190
+ let result = 0;
191
+
192
+ for (let i = 0; i < count; i++) {
193
+ const t = ts[offset++];
194
+
195
+ if (t > 0) {
196
+ result = result ? Math.min(t, result) : t;
197
+ }
198
+ }
199
+
200
+ return result;
201
+ }
202
+
186
203
  function expand(task) {
187
204
  var bounds = task._bounds;
188
205
  var viewport = task._viewport;
@@ -211,41 +228,26 @@ var renderTextLayer = function renderTextLayerClosure() {
211
228
  s = m[1];
212
229
  var points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
213
230
  var ts = new Float64Array(64);
214
- points.forEach(function (p, i) {
231
+ points.forEach(function (p, j) {
215
232
  var t = _util.Util.applyTransform(p, m);
216
233
 
217
- ts[i + 0] = c && (e.left - t[0]) / c;
218
- ts[i + 4] = s && (e.top - t[1]) / s;
219
- ts[i + 8] = c && (e.right - t[0]) / c;
220
- ts[i + 12] = s && (e.bottom - t[1]) / s;
221
- ts[i + 16] = s && (e.left - t[0]) / -s;
222
- ts[i + 20] = c && (e.top - t[1]) / c;
223
- ts[i + 24] = s && (e.right - t[0]) / -s;
224
- ts[i + 28] = c && (e.bottom - t[1]) / c;
225
- ts[i + 32] = c && (e.left - t[0]) / -c;
226
- ts[i + 36] = s && (e.top - t[1]) / -s;
227
- ts[i + 40] = c && (e.right - t[0]) / -c;
228
- ts[i + 44] = s && (e.bottom - t[1]) / -s;
229
- ts[i + 48] = s && (e.left - t[0]) / s;
230
- ts[i + 52] = c && (e.top - t[1]) / -c;
231
- ts[i + 56] = s && (e.right - t[0]) / s;
232
- ts[i + 60] = c && (e.bottom - t[1]) / -c;
234
+ ts[j + 0] = c && (e.left - t[0]) / c;
235
+ ts[j + 4] = s && (e.top - t[1]) / s;
236
+ ts[j + 8] = c && (e.right - t[0]) / c;
237
+ ts[j + 12] = s && (e.bottom - t[1]) / s;
238
+ ts[j + 16] = s && (e.left - t[0]) / -s;
239
+ ts[j + 20] = c && (e.top - t[1]) / c;
240
+ ts[j + 24] = s && (e.right - t[0]) / -s;
241
+ ts[j + 28] = c && (e.bottom - t[1]) / c;
242
+ ts[j + 32] = c && (e.left - t[0]) / -c;
243
+ ts[j + 36] = s && (e.top - t[1]) / -s;
244
+ ts[j + 40] = c && (e.right - t[0]) / -c;
245
+ ts[j + 44] = s && (e.bottom - t[1]) / -s;
246
+ ts[j + 48] = s && (e.left - t[0]) / s;
247
+ ts[j + 52] = c && (e.top - t[1]) / -c;
248
+ ts[j + 56] = s && (e.right - t[0]) / s;
249
+ ts[j + 60] = c && (e.bottom - t[1]) / -c;
233
250
  });
234
-
235
- var findPositiveMin = function findPositiveMin(ts, offset, count) {
236
- var result = 0;
237
-
238
- for (var i = 0; i < count; i++) {
239
- var t = ts[offset++];
240
-
241
- if (t > 0) {
242
- result = result ? Math.min(t, result) : t;
243
- }
244
- }
245
-
246
- return result;
247
- };
248
-
249
251
  var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
250
252
  divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
251
253
  divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
@@ -448,24 +450,24 @@ var renderTextLayer = function renderTextLayerClosure() {
448
450
  });
449
451
  }
450
452
 
451
- function TextLayerRenderTask(_ref) {
452
- var _this = this;
453
-
454
- var textContent = _ref.textContent,
455
- textContentStream = _ref.textContentStream,
456
- container = _ref.container,
457
- viewport = _ref.viewport,
458
- textDivs = _ref.textDivs,
459
- textContentItemsStr = _ref.textContentItemsStr,
460
- enhanceTextSelection = _ref.enhanceTextSelection;
453
+ function TextLayerRenderTask({
454
+ textContent,
455
+ textContentStream,
456
+ container,
457
+ viewport,
458
+ textDivs,
459
+ textContentItemsStr,
460
+ enhanceTextSelection
461
+ }) {
461
462
  this._textContent = textContent;
462
463
  this._textContentStream = textContentStream;
463
464
  this._container = container;
465
+ this._document = container.ownerDocument;
464
466
  this._viewport = viewport;
465
467
  this._textDivs = textDivs || [];
466
468
  this._textContentItemsStr = textContentItemsStr || [];
467
469
  this._enhanceTextSelection = !!enhanceTextSelection;
468
- this._fontInspectorEnabled = !!(_global_scope["default"].FontInspector && _global_scope["default"].FontInspector.enabled);
470
+ this._fontInspectorEnabled = !!(globalThis.FontInspector && globalThis.FontInspector.enabled);
469
471
  this._reader = null;
470
472
  this._layoutTextLastFontSize = null;
471
473
  this._layoutTextLastFontFamily = null;
@@ -477,13 +479,13 @@ var renderTextLayer = function renderTextLayerClosure() {
477
479
  this._renderTimer = null;
478
480
  this._bounds = [];
479
481
 
480
- this._capability.promise["finally"](function () {
481
- if (_this._layoutTextCtx) {
482
- _this._layoutTextCtx.canvas.width = 0;
483
- _this._layoutTextCtx.canvas.height = 0;
484
- _this._layoutTextCtx = null;
482
+ this._capability.promise.finally(() => {
483
+ if (this._layoutTextCtx) {
484
+ this._layoutTextCtx.canvas.width = 0;
485
+ this._layoutTextCtx.canvas.height = 0;
486
+ this._layoutTextCtx = null;
485
487
  }
486
- });
488
+ }).catch(() => {});
487
489
  }
488
490
 
489
491
  TextLayerRenderTask.prototype = {
@@ -495,7 +497,7 @@ var renderTextLayer = function renderTextLayerClosure() {
495
497
  this._canceled = true;
496
498
 
497
499
  if (this._reader) {
498
- this._reader.cancel(new _util.AbortException('TextLayer task cancelled.'));
500
+ this._reader.cancel(new _util.AbortException("TextLayer task cancelled."));
499
501
 
500
502
  this._reader = null;
501
503
  }
@@ -505,79 +507,89 @@ var renderTextLayer = function renderTextLayerClosure() {
505
507
  this._renderTimer = null;
506
508
  }
507
509
 
508
- this._capability.reject(new Error('TextLayer task cancelled.'));
510
+ this._capability.reject(new Error("TextLayer task cancelled."));
509
511
  },
510
- _processItems: function _processItems(items, styleCache) {
511
- for (var i = 0, len = items.length; i < len; i++) {
512
+
513
+ _processItems(items, styleCache) {
514
+ for (let i = 0, len = items.length; i < len; i++) {
512
515
  this._textContentItemsStr.push(items[i].str);
513
516
 
514
517
  appendText(this, items[i], styleCache);
515
518
  }
516
519
  },
517
- _layoutText: function _layoutText(textDiv) {
518
- var textLayerFrag = this._container;
519
520
 
520
- var textDivProperties = this._textDivProperties.get(textDiv);
521
+ _layoutText(textDiv) {
522
+ const textDivProperties = this._textDivProperties.get(textDiv);
521
523
 
522
524
  if (textDivProperties.isWhitespace) {
523
525
  return;
524
526
  }
525
527
 
526
- var fontSize = textDiv.style.fontSize;
527
- var fontFamily = textDiv.style.fontFamily;
528
+ let transform = "";
528
529
 
529
- if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
530
- this._layoutTextCtx.font = fontSize + ' ' + fontFamily;
531
- this._layoutTextLastFontSize = fontSize;
532
- this._layoutTextLastFontFamily = fontFamily;
533
- }
530
+ if (textDivProperties.canvasWidth !== 0) {
531
+ const {
532
+ fontSize,
533
+ fontFamily
534
+ } = textDiv.style;
534
535
 
535
- var width = this._layoutTextCtx.measureText(textDiv.textContent).width;
536
+ if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
537
+ this._layoutTextCtx.font = `${fontSize} ${fontFamily}`;
538
+ this._layoutTextLastFontSize = fontSize;
539
+ this._layoutTextLastFontFamily = fontFamily;
540
+ }
536
541
 
537
- var transform = '';
542
+ const {
543
+ width
544
+ } = this._layoutTextCtx.measureText(textDiv.textContent);
538
545
 
539
- if (textDivProperties.canvasWidth !== 0 && width > 0) {
540
- textDivProperties.scale = textDivProperties.canvasWidth / width;
541
- transform = "scaleX(".concat(textDivProperties.scale, ")");
546
+ if (width > 0) {
547
+ textDivProperties.scale = textDivProperties.canvasWidth / width;
548
+ transform = `scaleX(${textDivProperties.scale})`;
549
+ }
542
550
  }
543
551
 
544
552
  if (textDivProperties.angle !== 0) {
545
- transform = "rotate(".concat(textDivProperties.angle, "deg) ").concat(transform);
553
+ transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
546
554
  }
547
555
 
548
556
  if (transform.length > 0) {
549
- textDivProperties.originalTransform = transform;
557
+ if (this._enhanceTextSelection) {
558
+ textDivProperties.originalTransform = transform;
559
+ }
560
+
550
561
  textDiv.style.transform = transform;
551
562
  }
552
563
 
553
564
  this._textDivProperties.set(textDiv, textDivProperties);
554
565
 
555
- textLayerFrag.appendChild(textDiv);
566
+ this._container.appendChild(textDiv);
556
567
  },
568
+
557
569
  _render: function TextLayer_render(timeout) {
558
- var _this2 = this;
570
+ const capability = (0, _util.createPromiseCapability)();
571
+ let styleCache = Object.create(null);
572
+
573
+ const canvas = this._document.createElement("canvas");
559
574
 
560
- var capability = (0, _util.createPromiseCapability)();
561
- var styleCache = Object.create(null);
562
- var canvas = document.createElement('canvas');
563
575
  canvas.mozOpaque = true;
564
- this._layoutTextCtx = canvas.getContext('2d', {
576
+ this._layoutTextCtx = canvas.getContext("2d", {
565
577
  alpha: false
566
578
  });
567
579
 
568
580
  if (this._textContent) {
569
- var textItems = this._textContent.items;
570
- var textStyles = this._textContent.styles;
581
+ const textItems = this._textContent.items;
582
+ const textStyles = this._textContent.styles;
571
583
 
572
584
  this._processItems(textItems, textStyles);
573
585
 
574
586
  capability.resolve();
575
587
  } else if (this._textContentStream) {
576
- var pump = function pump() {
577
- _this2._reader.read().then(function (_ref2) {
578
- var value = _ref2.value,
579
- done = _ref2.done;
580
-
588
+ const pump = () => {
589
+ this._reader.read().then(({
590
+ value,
591
+ done
592
+ }) => {
581
593
  if (done) {
582
594
  capability.resolve();
583
595
  return;
@@ -585,7 +597,7 @@ var renderTextLayer = function renderTextLayerClosure() {
585
597
 
586
598
  Object.assign(styleCache, value.styles);
587
599
 
588
- _this2._processItems(value.items, styleCache);
600
+ this._processItems(value.items, styleCache);
589
601
 
590
602
  pump();
591
603
  }, capability.reject);
@@ -594,18 +606,18 @@ var renderTextLayer = function renderTextLayerClosure() {
594
606
  this._reader = this._textContentStream.getReader();
595
607
  pump();
596
608
  } else {
597
- throw new Error('Neither "textContent" nor "textContentStream"' + ' parameters specified.');
609
+ throw new Error('Neither "textContent" nor "textContentStream"' + " parameters specified.");
598
610
  }
599
611
 
600
- capability.promise.then(function () {
612
+ capability.promise.then(() => {
601
613
  styleCache = null;
602
614
 
603
615
  if (!timeout) {
604
- render(_this2);
616
+ render(this);
605
617
  } else {
606
- _this2._renderTimer = setTimeout(function () {
607
- render(_this2);
608
- _this2._renderTimer = null;
618
+ this._renderTimer = setTimeout(() => {
619
+ render(this);
620
+ this._renderTimer = null;
609
621
  }, timeout);
610
622
  }
611
623
  }, this._capability.reject);
@@ -620,55 +632,60 @@ var renderTextLayer = function renderTextLayerClosure() {
620
632
  this._bounds = null;
621
633
  }
622
634
 
635
+ const transformBuf = [],
636
+ paddingBuf = [];
637
+
623
638
  for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
624
- var div = this._textDivs[i];
639
+ const div = this._textDivs[i];
625
640
 
626
- var divProperties = this._textDivProperties.get(div);
641
+ const divProps = this._textDivProperties.get(div);
627
642
 
628
- if (divProperties.isWhitespace) {
643
+ if (divProps.isWhitespace) {
629
644
  continue;
630
645
  }
631
646
 
632
647
  if (expandDivs) {
633
- var transform = '',
634
- padding = '';
635
-
636
- if (divProperties.scale !== 1) {
637
- transform = 'scaleX(' + divProperties.scale + ')';
638
- }
648
+ transformBuf.length = 0;
649
+ paddingBuf.length = 0;
639
650
 
640
- if (divProperties.angle !== 0) {
641
- transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
651
+ if (divProps.originalTransform) {
652
+ transformBuf.push(divProps.originalTransform);
642
653
  }
643
654
 
644
- if (divProperties.paddingLeft !== 0) {
645
- padding += ' padding-left: ' + divProperties.paddingLeft / divProperties.scale + 'px;';
646
- transform += ' translateX(' + -divProperties.paddingLeft / divProperties.scale + 'px)';
655
+ if (divProps.paddingTop > 0) {
656
+ paddingBuf.push(`${divProps.paddingTop}px`);
657
+ transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
658
+ } else {
659
+ paddingBuf.push(0);
647
660
  }
648
661
 
649
- if (divProperties.paddingTop !== 0) {
650
- padding += ' padding-top: ' + divProperties.paddingTop + 'px;';
651
- transform += ' translateY(' + -divProperties.paddingTop + 'px)';
662
+ if (divProps.paddingRight > 0) {
663
+ paddingBuf.push(`${divProps.paddingRight / divProps.scale}px`);
664
+ } else {
665
+ paddingBuf.push(0);
652
666
  }
653
667
 
654
- if (divProperties.paddingRight !== 0) {
655
- padding += ' padding-right: ' + divProperties.paddingRight / divProperties.scale + 'px;';
668
+ if (divProps.paddingBottom > 0) {
669
+ paddingBuf.push(`${divProps.paddingBottom}px`);
670
+ } else {
671
+ paddingBuf.push(0);
656
672
  }
657
673
 
658
- if (divProperties.paddingBottom !== 0) {
659
- padding += ' padding-bottom: ' + divProperties.paddingBottom + 'px;';
674
+ if (divProps.paddingLeft > 0) {
675
+ paddingBuf.push(`${divProps.paddingLeft / divProps.scale}px`);
676
+ transformBuf.push(`translateX(${-divProps.paddingLeft / divProps.scale}px)`);
677
+ } else {
678
+ paddingBuf.push(0);
660
679
  }
661
680
 
662
- if (padding !== '') {
663
- div.setAttribute('style', divProperties.style + padding);
664
- }
681
+ div.style.padding = paddingBuf.join(" ");
665
682
 
666
- if (transform !== '') {
667
- div.style.transform = transform;
683
+ if (transformBuf.length) {
684
+ div.style.transform = transformBuf.join(" ");
668
685
  }
669
686
  } else {
670
- div.style.padding = 0;
671
- div.style.transform = divProperties.originalTransform || '';
687
+ div.style.padding = null;
688
+ div.style.transform = divProps.originalTransform;
672
689
  }
673
690
  }
674
691
  }