pdfjs-dist 2.1.266 → 2.5.207

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 (191) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/README.md +4 -0
  3. package/bower.json +1 -1
  4. package/build/pdf.js +8382 -18492
  5. package/build/pdf.js.map +1 -1
  6. package/build/pdf.min.js +22 -1
  7. package/build/pdf.worker.entry.js +5 -3
  8. package/build/pdf.worker.js +20417 -29816
  9. package/build/pdf.worker.js.map +1 -1
  10. package/build/pdf.worker.min.js +22 -1
  11. package/es5/build/pdf.js +25688 -0
  12. package/es5/build/pdf.js.map +1 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +58239 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/web/images/annotation-check.svg +11 -0
  17. package/es5/web/images/annotation-comment.svg +16 -0
  18. package/es5/web/images/annotation-help.svg +26 -0
  19. package/es5/web/images/annotation-insert.svg +10 -0
  20. package/es5/web/images/annotation-key.svg +11 -0
  21. package/es5/web/images/annotation-newparagraph.svg +11 -0
  22. package/es5/web/images/annotation-noicon.svg +7 -0
  23. package/es5/web/images/annotation-note.svg +42 -0
  24. package/es5/web/images/annotation-paragraph.svg +16 -0
  25. package/es5/web/images/loading-icon.gif +0 -0
  26. package/es5/web/images/shadow.png +0 -0
  27. package/es5/web/images/texture.png +0 -0
  28. package/es5/web/pdf_viewer.css +403 -0
  29. package/es5/web/pdf_viewer.js +7742 -0
  30. package/es5/web/pdf_viewer.js.map +1 -0
  31. package/image_decoders/pdf.image_decoders.js +1475 -4897
  32. package/image_decoders/pdf.image_decoders.js.map +1 -1
  33. package/image_decoders/pdf.image_decoders.min.js +22 -1
  34. package/lib/README.md +7 -0
  35. package/lib/core/annotation.js +750 -899
  36. package/lib/core/arithmetic_decoder.js +81 -97
  37. package/lib/core/bidi.js +54 -46
  38. package/lib/core/ccitt.js +88 -81
  39. package/lib/core/ccitt_stream.js +15 -14
  40. package/lib/core/cff_parser.js +235 -183
  41. package/lib/core/charsets.js +4 -4
  42. package/lib/core/chunked_stream.js +447 -542
  43. package/lib/core/cmap.js +222 -264
  44. package/lib/core/colorspace.js +699 -863
  45. package/lib/core/core_utils.js +152 -0
  46. package/lib/core/crypto.js +379 -437
  47. package/lib/core/document.js +573 -660
  48. package/lib/core/encodings.js +15 -15
  49. package/lib/core/evaluator.js +1103 -868
  50. package/lib/core/font_renderer.js +135 -178
  51. package/lib/core/fonts.js +570 -491
  52. package/lib/core/function.js +291 -288
  53. package/lib/core/glyphlist.js +4527 -4526
  54. package/lib/core/image.js +145 -149
  55. package/lib/core/image_utils.js +170 -0
  56. package/lib/core/jbig2.js +325 -316
  57. package/lib/core/jbig2_stream.js +18 -17
  58. package/lib/core/jpeg_stream.js +21 -26
  59. package/lib/core/jpg.js +284 -232
  60. package/lib/core/jpx.js +161 -143
  61. package/lib/core/jpx_stream.js +28 -28
  62. package/lib/core/metrics.js +2929 -2929
  63. package/lib/core/murmurhash3.js +90 -101
  64. package/lib/core/obj.js +1183 -1157
  65. package/lib/core/operator_list.js +99 -67
  66. package/lib/core/parser.js +972 -911
  67. package/lib/core/pattern.js +87 -70
  68. package/lib/core/pdf_manager.js +150 -315
  69. package/lib/core/primitives.js +83 -56
  70. package/lib/core/ps_parser.js +175 -214
  71. package/lib/core/standard_fonts.js +237 -236
  72. package/lib/core/stream.js +94 -74
  73. package/lib/core/type1_parser.js +87 -69
  74. package/lib/core/unicode.js +1654 -1654
  75. package/lib/core/worker.js +193 -390
  76. package/lib/core/worker_stream.js +168 -0
  77. package/lib/display/annotation_layer.js +741 -972
  78. package/lib/display/api.js +1500 -1791
  79. package/lib/display/api_compatibility.js +12 -17
  80. package/lib/display/canvas.js +165 -165
  81. package/lib/display/content_disposition.js +40 -59
  82. package/lib/display/display_utils.js +515 -0
  83. package/lib/display/fetch_stream.js +183 -298
  84. package/lib/display/font_loader.js +273 -413
  85. package/lib/display/metadata.js +86 -98
  86. package/lib/display/network.js +266 -359
  87. package/lib/display/network_utils.js +25 -18
  88. package/lib/display/node_stream.js +285 -458
  89. package/lib/display/pattern_helper.js +113 -65
  90. package/lib/display/svg.js +1166 -901
  91. package/lib/display/text_layer.js +156 -132
  92. package/lib/display/transport_stream.js +262 -278
  93. package/lib/display/webgl.js +70 -83
  94. package/lib/display/worker_options.js +3 -3
  95. package/lib/display/xml_parser.js +303 -392
  96. package/lib/examples/node/domstubs.js +40 -37
  97. package/lib/pdf.js +226 -59
  98. package/lib/pdf.worker.js +14 -6
  99. package/lib/shared/compatibility.js +3 -246
  100. package/lib/shared/is_node.js +7 -6
  101. package/lib/shared/message_handler.js +327 -332
  102. package/lib/shared/util.js +266 -416
  103. package/lib/test/unit/annotation_spec.js +1555 -701
  104. package/lib/test/unit/api_spec.js +802 -604
  105. package/lib/test/unit/bidi_spec.js +7 -7
  106. package/lib/test/unit/cff_parser_spec.js +84 -69
  107. package/lib/test/unit/clitests_helper.js +7 -9
  108. package/lib/test/unit/cmap_spec.js +74 -76
  109. package/lib/test/unit/colorspace_spec.js +166 -161
  110. package/lib/test/unit/core_utils_spec.js +211 -0
  111. package/lib/test/unit/crypto_spec.js +181 -181
  112. package/lib/test/unit/custom_spec.js +20 -22
  113. package/lib/test/unit/display_svg_spec.js +34 -39
  114. package/lib/test/unit/display_utils_spec.js +263 -0
  115. package/lib/test/unit/document_spec.js +16 -21
  116. package/lib/test/unit/encodings_spec.js +12 -34
  117. package/lib/test/unit/evaluator_spec.js +83 -83
  118. package/lib/test/unit/fetch_stream_spec.js +111 -0
  119. package/lib/test/unit/function_spec.js +206 -204
  120. package/lib/test/unit/jasmine-boot.js +46 -30
  121. package/lib/test/unit/message_handler_spec.js +173 -159
  122. package/lib/test/unit/metadata_spec.js +69 -69
  123. package/lib/test/unit/murmurhash3_spec.js +12 -12
  124. package/lib/test/unit/network_spec.js +13 -61
  125. package/lib/test/unit/network_utils_spec.js +183 -119
  126. package/lib/test/unit/node_stream_spec.js +78 -92
  127. package/lib/test/unit/parser_spec.js +172 -114
  128. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  129. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  130. package/lib/test/unit/pdf_history_spec.js +32 -32
  131. package/lib/test/unit/primitives_spec.js +140 -125
  132. package/lib/test/unit/stream_spec.js +16 -14
  133. package/lib/test/unit/test_utils.js +131 -143
  134. package/lib/test/unit/testreporter.js +19 -19
  135. package/lib/test/unit/type1_parser_spec.js +42 -42
  136. package/lib/test/unit/ui_utils_spec.js +297 -459
  137. package/lib/test/unit/unicode_spec.js +38 -38
  138. package/lib/test/unit/util_spec.js +121 -305
  139. package/lib/web/annotation_layer_builder.js +66 -103
  140. package/lib/web/app.js +1328 -1214
  141. package/lib/web/app_options.js +105 -107
  142. package/lib/web/base_viewer.js +824 -838
  143. package/lib/web/chromecom.js +165 -252
  144. package/lib/web/debugger.js +149 -205
  145. package/lib/web/download_manager.js +39 -55
  146. package/lib/web/firefox_print_service.js +37 -27
  147. package/lib/web/firefoxcom.js +212 -363
  148. package/lib/web/genericcom.js +26 -108
  149. package/lib/web/genericl10n.js +24 -153
  150. package/lib/web/grab_to_pan.js +32 -30
  151. package/lib/web/interfaces.js +80 -254
  152. package/lib/web/overlay_manager.js +70 -246
  153. package/lib/web/password_prompt.js +38 -64
  154. package/lib/web/pdf_attachment_viewer.js +113 -131
  155. package/lib/web/pdf_cursor_tools.js +75 -102
  156. package/lib/web/pdf_document_properties.js +221 -306
  157. package/lib/web/pdf_find_bar.js +136 -170
  158. package/lib/web/pdf_find_controller.js +491 -548
  159. package/lib/web/pdf_find_utils.js +13 -13
  160. package/lib/web/pdf_history.js +397 -406
  161. package/lib/web/pdf_link_service.js +304 -348
  162. package/lib/web/pdf_outline_viewer.js +140 -175
  163. package/lib/web/pdf_page_view.js +452 -523
  164. package/lib/web/pdf_presentation_mode.js +308 -357
  165. package/lib/web/pdf_print_service.js +90 -104
  166. package/lib/web/pdf_rendering_queue.js +84 -108
  167. package/lib/web/pdf_sidebar.js +276 -306
  168. package/lib/web/pdf_sidebar_resizer.js +92 -119
  169. package/lib/web/pdf_single_page_viewer.js +77 -126
  170. package/lib/web/pdf_thumbnail_view.js +276 -297
  171. package/lib/web/pdf_thumbnail_viewer.js +186 -206
  172. package/lib/web/pdf_viewer.component.js +20 -21
  173. package/lib/web/pdf_viewer.js +55 -115
  174. package/lib/web/preferences.js +82 -286
  175. package/lib/web/secondary_toolbar.js +164 -196
  176. package/lib/web/text_layer_builder.js +282 -339
  177. package/lib/web/toolbar.js +217 -210
  178. package/lib/web/ui_utils.js +267 -420
  179. package/lib/web/view_history.js +52 -226
  180. package/lib/web/viewer_compatibility.js +21 -6
  181. package/package.json +2 -9
  182. package/web/pdf_viewer.css +35 -25
  183. package/web/pdf_viewer.js +3489 -4855
  184. package/web/pdf_viewer.js.map +1 -1
  185. package/webpack.js +14 -5
  186. package/external/streams/streams-lib.js +0 -3962
  187. package/external/url/url-lib.js +0 -627
  188. package/lib/display/dom_utils.js +0 -494
  189. package/lib/shared/streams_polyfill.js +0 -43
  190. package/lib/shared/url_polyfill.js +0 -56
  191. package/lib/test/unit/dom_utils_spec.js +0 -89
@@ -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 2018 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,14 +450,15 @@ var renderTextLayer = function renderTextLayerClosure() {
448
450
  });
449
451
  }
450
452
 
451
- function TextLayerRenderTask(_ref) {
452
- var textContent = _ref.textContent,
453
- textContentStream = _ref.textContentStream,
454
- container = _ref.container,
455
- viewport = _ref.viewport,
456
- textDivs = _ref.textDivs,
457
- textContentItemsStr = _ref.textContentItemsStr,
458
- enhanceTextSelection = _ref.enhanceTextSelection;
453
+ function TextLayerRenderTask({
454
+ textContent,
455
+ textContentStream,
456
+ container,
457
+ viewport,
458
+ textDivs,
459
+ textContentItemsStr,
460
+ enhanceTextSelection
461
+ }) {
459
462
  this._textContent = textContent;
460
463
  this._textContentStream = textContentStream;
461
464
  this._container = container;
@@ -463,7 +466,7 @@ var renderTextLayer = function renderTextLayerClosure() {
463
466
  this._textDivs = textDivs || [];
464
467
  this._textContentItemsStr = textContentItemsStr || [];
465
468
  this._enhanceTextSelection = !!enhanceTextSelection;
466
- this._fontInspectorEnabled = !!(_global_scope.default.FontInspector && _global_scope.default.FontInspector.enabled);
469
+ this._fontInspectorEnabled = !!(globalThis.FontInspector && globalThis.FontInspector.enabled);
467
470
  this._reader = null;
468
471
  this._layoutTextLastFontSize = null;
469
472
  this._layoutTextLastFontFamily = null;
@@ -474,6 +477,14 @@ var renderTextLayer = function renderTextLayerClosure() {
474
477
  this._capability = (0, _util.createPromiseCapability)();
475
478
  this._renderTimer = null;
476
479
  this._bounds = [];
480
+
481
+ this._capability.promise.finally(() => {
482
+ if (this._layoutTextCtx) {
483
+ this._layoutTextCtx.canvas.width = 0;
484
+ this._layoutTextCtx.canvas.height = 0;
485
+ this._layoutTextCtx = null;
486
+ }
487
+ }).catch(() => {});
477
488
  }
478
489
 
479
490
  TextLayerRenderTask.prototype = {
@@ -482,92 +493,100 @@ var renderTextLayer = function renderTextLayerClosure() {
482
493
  },
483
494
 
484
495
  cancel: function TextLayer_cancel() {
496
+ this._canceled = true;
497
+
485
498
  if (this._reader) {
486
- this._reader.cancel(new _util.AbortException('text layer task cancelled'));
499
+ this._reader.cancel(new _util.AbortException("TextLayer task cancelled."));
487
500
 
488
501
  this._reader = null;
489
502
  }
490
503
 
491
- this._canceled = true;
492
-
493
504
  if (this._renderTimer !== null) {
494
505
  clearTimeout(this._renderTimer);
495
506
  this._renderTimer = null;
496
507
  }
497
508
 
498
- this._capability.reject('canceled');
509
+ this._capability.reject(new Error("TextLayer task cancelled."));
499
510
  },
500
- _processItems: function _processItems(items, styleCache) {
501
- for (var i = 0, len = items.length; i < len; i++) {
511
+
512
+ _processItems(items, styleCache) {
513
+ for (let i = 0, len = items.length; i < len; i++) {
502
514
  this._textContentItemsStr.push(items[i].str);
503
515
 
504
516
  appendText(this, items[i], styleCache);
505
517
  }
506
518
  },
507
- _layoutText: function _layoutText(textDiv) {
508
- var textLayerFrag = this._container;
509
519
 
510
- var textDivProperties = this._textDivProperties.get(textDiv);
520
+ _layoutText(textDiv) {
521
+ const textDivProperties = this._textDivProperties.get(textDiv);
511
522
 
512
523
  if (textDivProperties.isWhitespace) {
513
524
  return;
514
525
  }
515
526
 
516
- var fontSize = textDiv.style.fontSize;
517
- var fontFamily = textDiv.style.fontFamily;
527
+ let transform = "";
518
528
 
519
- if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
520
- this._layoutTextCtx.font = fontSize + ' ' + fontFamily;
521
- this._layoutTextLastFontSize = fontSize;
522
- this._layoutTextLastFontFamily = fontFamily;
523
- }
529
+ if (textDivProperties.canvasWidth !== 0) {
530
+ const {
531
+ fontSize,
532
+ fontFamily
533
+ } = textDiv.style;
524
534
 
525
- var width = this._layoutTextCtx.measureText(textDiv.textContent).width;
535
+ if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
536
+ this._layoutTextCtx.font = `${fontSize} ${fontFamily}`;
537
+ this._layoutTextLastFontSize = fontSize;
538
+ this._layoutTextLastFontFamily = fontFamily;
539
+ }
526
540
 
527
- var transform = '';
541
+ const {
542
+ width
543
+ } = this._layoutTextCtx.measureText(textDiv.textContent);
528
544
 
529
- if (textDivProperties.canvasWidth !== 0 && width > 0) {
530
- textDivProperties.scale = textDivProperties.canvasWidth / width;
531
- transform = "scaleX(".concat(textDivProperties.scale, ")");
545
+ if (width > 0) {
546
+ textDivProperties.scale = textDivProperties.canvasWidth / width;
547
+ transform = `scaleX(${textDivProperties.scale})`;
548
+ }
532
549
  }
533
550
 
534
551
  if (textDivProperties.angle !== 0) {
535
- transform = "rotate(".concat(textDivProperties.angle, "deg) ").concat(transform);
552
+ transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
536
553
  }
537
554
 
538
555
  if (transform.length > 0) {
539
- textDivProperties.originalTransform = transform;
556
+ if (this._enhanceTextSelection) {
557
+ textDivProperties.originalTransform = transform;
558
+ }
559
+
540
560
  textDiv.style.transform = transform;
541
561
  }
542
562
 
543
563
  this._textDivProperties.set(textDiv, textDivProperties);
544
564
 
545
- textLayerFrag.appendChild(textDiv);
565
+ this._container.appendChild(textDiv);
546
566
  },
547
- _render: function TextLayer_render(timeout) {
548
- var _this = this;
549
567
 
550
- var capability = (0, _util.createPromiseCapability)();
551
- var styleCache = Object.create(null);
552
- var canvas = document.createElement('canvas');
568
+ _render: function TextLayer_render(timeout) {
569
+ const capability = (0, _util.createPromiseCapability)();
570
+ let styleCache = Object.create(null);
571
+ const canvas = document.createElement("canvas");
553
572
  canvas.mozOpaque = true;
554
- this._layoutTextCtx = canvas.getContext('2d', {
573
+ this._layoutTextCtx = canvas.getContext("2d", {
555
574
  alpha: false
556
575
  });
557
576
 
558
577
  if (this._textContent) {
559
- var textItems = this._textContent.items;
560
- var textStyles = this._textContent.styles;
578
+ const textItems = this._textContent.items;
579
+ const textStyles = this._textContent.styles;
561
580
 
562
581
  this._processItems(textItems, textStyles);
563
582
 
564
583
  capability.resolve();
565
584
  } else if (this._textContentStream) {
566
- var pump = function pump() {
567
- _this._reader.read().then(function (_ref2) {
568
- var value = _ref2.value,
569
- done = _ref2.done;
570
-
585
+ const pump = () => {
586
+ this._reader.read().then(({
587
+ value,
588
+ done
589
+ }) => {
571
590
  if (done) {
572
591
  capability.resolve();
573
592
  return;
@@ -575,7 +594,7 @@ var renderTextLayer = function renderTextLayerClosure() {
575
594
 
576
595
  Object.assign(styleCache, value.styles);
577
596
 
578
- _this._processItems(value.items, styleCache);
597
+ this._processItems(value.items, styleCache);
579
598
 
580
599
  pump();
581
600
  }, capability.reject);
@@ -584,18 +603,18 @@ var renderTextLayer = function renderTextLayerClosure() {
584
603
  this._reader = this._textContentStream.getReader();
585
604
  pump();
586
605
  } else {
587
- throw new Error('Neither "textContent" nor "textContentStream"' + ' parameters specified.');
606
+ throw new Error('Neither "textContent" nor "textContentStream"' + " parameters specified.");
588
607
  }
589
608
 
590
- capability.promise.then(function () {
609
+ capability.promise.then(() => {
591
610
  styleCache = null;
592
611
 
593
612
  if (!timeout) {
594
- render(_this);
613
+ render(this);
595
614
  } else {
596
- _this._renderTimer = setTimeout(function () {
597
- render(_this);
598
- _this._renderTimer = null;
615
+ this._renderTimer = setTimeout(() => {
616
+ render(this);
617
+ this._renderTimer = null;
599
618
  }, timeout);
600
619
  }
601
620
  }, this._capability.reject);
@@ -610,55 +629,60 @@ var renderTextLayer = function renderTextLayerClosure() {
610
629
  this._bounds = null;
611
630
  }
612
631
 
632
+ const transformBuf = [],
633
+ paddingBuf = [];
634
+
613
635
  for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
614
- var div = this._textDivs[i];
636
+ const div = this._textDivs[i];
615
637
 
616
- var divProperties = this._textDivProperties.get(div);
638
+ const divProps = this._textDivProperties.get(div);
617
639
 
618
- if (divProperties.isWhitespace) {
640
+ if (divProps.isWhitespace) {
619
641
  continue;
620
642
  }
621
643
 
622
644
  if (expandDivs) {
623
- var transform = '',
624
- padding = '';
625
-
626
- if (divProperties.scale !== 1) {
627
- transform = 'scaleX(' + divProperties.scale + ')';
628
- }
645
+ transformBuf.length = 0;
646
+ paddingBuf.length = 0;
629
647
 
630
- if (divProperties.angle !== 0) {
631
- transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
648
+ if (divProps.originalTransform) {
649
+ transformBuf.push(divProps.originalTransform);
632
650
  }
633
651
 
634
- if (divProperties.paddingLeft !== 0) {
635
- padding += ' padding-left: ' + divProperties.paddingLeft / divProperties.scale + 'px;';
636
- transform += ' translateX(' + -divProperties.paddingLeft / divProperties.scale + 'px)';
652
+ if (divProps.paddingTop > 0) {
653
+ paddingBuf.push(`${divProps.paddingTop}px`);
654
+ transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
655
+ } else {
656
+ paddingBuf.push(0);
637
657
  }
638
658
 
639
- if (divProperties.paddingTop !== 0) {
640
- padding += ' padding-top: ' + divProperties.paddingTop + 'px;';
641
- transform += ' translateY(' + -divProperties.paddingTop + 'px)';
659
+ if (divProps.paddingRight > 0) {
660
+ paddingBuf.push(`${divProps.paddingRight / divProps.scale}px`);
661
+ } else {
662
+ paddingBuf.push(0);
642
663
  }
643
664
 
644
- if (divProperties.paddingRight !== 0) {
645
- padding += ' padding-right: ' + divProperties.paddingRight / divProperties.scale + 'px;';
665
+ if (divProps.paddingBottom > 0) {
666
+ paddingBuf.push(`${divProps.paddingBottom}px`);
667
+ } else {
668
+ paddingBuf.push(0);
646
669
  }
647
670
 
648
- if (divProperties.paddingBottom !== 0) {
649
- padding += ' padding-bottom: ' + divProperties.paddingBottom + 'px;';
671
+ if (divProps.paddingLeft > 0) {
672
+ paddingBuf.push(`${divProps.paddingLeft / divProps.scale}px`);
673
+ transformBuf.push(`translateX(${-divProps.paddingLeft / divProps.scale}px)`);
674
+ } else {
675
+ paddingBuf.push(0);
650
676
  }
651
677
 
652
- if (padding !== '') {
653
- div.setAttribute('style', divProperties.style + padding);
654
- }
678
+ div.style.padding = paddingBuf.join(" ");
655
679
 
656
- if (transform !== '') {
657
- div.style.transform = transform;
680
+ if (transformBuf.length) {
681
+ div.style.transform = transformBuf.join(" ");
658
682
  }
659
683
  } else {
660
- div.style.padding = 0;
661
- div.style.transform = divProperties.originalTransform || '';
684
+ div.style.padding = null;
685
+ div.style.transform = divProps.originalTransform;
662
686
  }
663
687
  }
664
688
  }