pdfjs-dist 2.0.943 → 2.1.266

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 (159) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +15329 -11095
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +12497 -4184
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/image_decoders/pdf.image_decoders.js +3438 -1209
  9. package/image_decoders/pdf.image_decoders.js.map +1 -1
  10. package/image_decoders/pdf.image_decoders.min.js +1 -1
  11. package/lib/core/annotation.js +335 -109
  12. package/lib/core/arithmetic_decoder.js +274 -244
  13. package/lib/core/bidi.js +64 -5
  14. package/lib/core/ccitt.js +172 -17
  15. package/lib/core/ccitt_stream.js +14 -5
  16. package/lib/core/cff_parser.js +304 -28
  17. package/lib/core/charsets.js +4 -3
  18. package/lib/core/chunked_stream.js +379 -149
  19. package/lib/core/cmap.js +210 -40
  20. package/lib/core/colorspace.js +332 -187
  21. package/lib/core/crypto.js +289 -44
  22. package/lib/core/document.js +508 -249
  23. package/lib/core/encodings.js +18 -9
  24. package/lib/core/evaluator.js +657 -119
  25. package/lib/core/font_renderer.js +217 -34
  26. package/lib/core/fonts.js +632 -41
  27. package/lib/core/function.js +252 -26
  28. package/lib/core/glyphlist.js +2 -1
  29. package/lib/core/image.js +124 -27
  30. package/lib/core/jbig2.js +425 -65
  31. package/lib/core/jbig2_stream.js +18 -7
  32. package/lib/core/jpeg_stream.js +24 -8
  33. package/lib/core/jpg.js +208 -16
  34. package/lib/core/jpx.js +395 -5
  35. package/lib/core/jpx_stream.js +17 -5
  36. package/lib/core/metrics.js +3 -3
  37. package/lib/core/murmurhash3.js +23 -5
  38. package/lib/core/obj.js +625 -132
  39. package/lib/core/operator_list.js +104 -3
  40. package/lib/core/parser.js +262 -25
  41. package/lib/core/pattern.js +144 -12
  42. package/lib/core/pdf_manager.js +104 -70
  43. package/lib/core/primitives.js +74 -21
  44. package/lib/core/ps_parser.js +133 -44
  45. package/lib/core/standard_fonts.js +9 -9
  46. package/lib/core/stream.js +283 -31
  47. package/lib/core/type1_parser.js +138 -6
  48. package/lib/core/unicode.js +28 -1
  49. package/lib/core/worker.js +192 -57
  50. package/lib/display/annotation_layer.js +303 -123
  51. package/lib/display/api.js +1073 -574
  52. package/lib/display/api_compatibility.js +4 -1
  53. package/lib/display/canvas.js +314 -18
  54. package/lib/display/content_disposition.js +70 -23
  55. package/lib/display/dom_utils.js +112 -59
  56. package/lib/display/fetch_stream.js +95 -50
  57. package/lib/display/font_loader.js +250 -132
  58. package/lib/display/metadata.js +37 -15
  59. package/lib/display/network.js +123 -34
  60. package/lib/display/network_utils.js +23 -10
  61. package/lib/display/node_stream.js +162 -65
  62. package/lib/display/pattern_helper.js +57 -6
  63. package/lib/display/svg.js +194 -18
  64. package/lib/display/text_layer.js +128 -14
  65. package/lib/display/transport_stream.js +83 -27
  66. package/lib/display/webgl.js +63 -17
  67. package/lib/display/worker_options.js +4 -3
  68. package/lib/display/xml_parser.js +162 -52
  69. package/lib/examples/node/domstubs.js +56 -3
  70. package/lib/pdf.js +15 -2
  71. package/lib/pdf.worker.js +4 -2
  72. package/lib/shared/compatibility.js +129 -26
  73. package/lib/shared/global_scope.js +1 -1
  74. package/lib/shared/is_node.js +3 -3
  75. package/lib/shared/message_handler.js +103 -45
  76. package/lib/shared/streams_polyfill.js +20 -16
  77. package/lib/shared/url_polyfill.js +8 -2
  78. package/lib/shared/util.js +246 -84
  79. package/lib/test/unit/annotation_spec.js +99 -73
  80. package/lib/test/unit/api_spec.js +347 -113
  81. package/lib/test/unit/bidi_spec.js +6 -6
  82. package/lib/test/unit/cff_parser_spec.js +17 -5
  83. package/lib/test/unit/clitests_helper.js +7 -8
  84. package/lib/test/unit/cmap_spec.js +79 -25
  85. package/lib/test/unit/colorspace_spec.js +65 -18
  86. package/lib/test/unit/crypto_spec.js +16 -4
  87. package/lib/test/unit/custom_spec.js +40 -52
  88. package/lib/test/unit/display_svg_spec.js +32 -16
  89. package/lib/test/unit/document_spec.js +2 -2
  90. package/lib/test/unit/dom_utils_spec.js +8 -8
  91. package/lib/test/unit/encodings_spec.js +24 -44
  92. package/lib/test/unit/evaluator_spec.js +15 -8
  93. package/lib/test/unit/function_spec.js +16 -4
  94. package/lib/test/unit/jasmine-boot.js +29 -16
  95. package/lib/test/unit/message_handler_spec.js +19 -6
  96. package/lib/test/unit/metadata_spec.js +64 -11
  97. package/lib/test/unit/murmurhash3_spec.js +2 -2
  98. package/lib/test/unit/network_spec.js +19 -4
  99. package/lib/test/unit/network_utils_spec.js +6 -4
  100. package/lib/test/unit/node_stream_spec.js +50 -26
  101. package/lib/test/unit/parser_spec.js +13 -29
  102. package/lib/test/unit/pdf_find_controller_spec.js +144 -32
  103. package/lib/test/unit/pdf_find_utils_spec.js +10 -9
  104. package/lib/test/unit/pdf_history_spec.js +20 -8
  105. package/lib/test/unit/primitives_spec.js +23 -3
  106. package/lib/test/unit/stream_spec.js +8 -3
  107. package/lib/test/unit/test_utils.js +89 -26
  108. package/lib/test/unit/testreporter.js +19 -1
  109. package/lib/test/unit/type1_parser_spec.js +7 -5
  110. package/lib/test/unit/ui_utils_spec.js +162 -38
  111. package/lib/test/unit/unicode_spec.js +13 -10
  112. package/lib/test/unit/util_spec.js +89 -9
  113. package/lib/web/annotation_layer_builder.js +38 -21
  114. package/lib/web/app.js +610 -245
  115. package/lib/web/app_options.js +54 -34
  116. package/lib/web/base_viewer.js +359 -162
  117. package/lib/web/chromecom.js +159 -80
  118. package/lib/web/debugger.js +161 -17
  119. package/lib/web/download_manager.js +29 -11
  120. package/lib/web/firefox_print_service.js +16 -8
  121. package/lib/web/firefoxcom.js +127 -91
  122. package/lib/web/genericcom.js +50 -31
  123. package/lib/web/genericl10n.js +46 -34
  124. package/lib/web/grab_to_pan.js +25 -3
  125. package/lib/web/interfaces.js +108 -61
  126. package/lib/web/overlay_manager.js +67 -45
  127. package/lib/web/password_prompt.js +20 -12
  128. package/lib/web/pdf_attachment_viewer.js +37 -17
  129. package/lib/web/pdf_cursor_tools.js +38 -15
  130. package/lib/web/pdf_document_properties.js +65 -24
  131. package/lib/web/pdf_find_bar.js +48 -20
  132. package/lib/web/pdf_find_controller.js +290 -89
  133. package/lib/web/pdf_find_utils.js +19 -3
  134. package/lib/web/pdf_history.js +186 -49
  135. package/lib/web/pdf_link_service.js +127 -52
  136. package/lib/web/pdf_outline_viewer.js +71 -21
  137. package/lib/web/pdf_page_view.js +188 -63
  138. package/lib/web/pdf_presentation_mode.js +98 -33
  139. package/lib/web/pdf_print_service.js +54 -10
  140. package/lib/web/pdf_rendering_queue.js +26 -4
  141. package/lib/web/pdf_sidebar.js +116 -62
  142. package/lib/web/pdf_sidebar_resizer.js +41 -15
  143. package/lib/web/pdf_single_page_viewer.js +65 -68
  144. package/lib/web/pdf_thumbnail_view.js +102 -31
  145. package/lib/web/pdf_thumbnail_viewer.js +62 -22
  146. package/lib/web/pdf_viewer.component.js +111 -31
  147. package/lib/web/pdf_viewer.js +80 -60
  148. package/lib/web/preferences.js +61 -39
  149. package/lib/web/secondary_toolbar.js +101 -82
  150. package/lib/web/text_layer_builder.js +124 -69
  151. package/lib/web/toolbar.js +67 -27
  152. package/lib/web/ui_utils.js +284 -128
  153. package/lib/web/view_history.js +75 -51
  154. package/lib/web/viewer_compatibility.js +2 -1
  155. package/package.json +1 -1
  156. package/web/pdf_viewer.css +1 -1
  157. package/web/pdf_viewer.js +2200 -973
  158. package/web/pdf_viewer.js.map +1 -1
  159. package/lib/web/dom_events.js +0 -140
@@ -19,22 +19,22 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.PDFDataTransportStream = undefined;
27
+ exports.PDFDataTransportStream = void 0;
28
28
 
29
- var _regenerator = require('babel-runtime/regenerator');
29
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
30
30
 
31
- var _regenerator2 = _interopRequireDefault(_regenerator);
32
-
33
- var _util = require('../shared/util');
31
+ var _util = require("../shared/util");
34
32
 
35
33
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36
34
 
37
- function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
35
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
36
+
37
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
38
38
 
39
39
  var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
40
40
  function PDFDataTransportStream(params, pdfDataRangeTransport) {
@@ -43,33 +43,46 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
43
43
  (0, _util.assert)(pdfDataRangeTransport);
44
44
  this._queuedChunks = [];
45
45
  var initialData = params.initialData;
46
+
46
47
  if (initialData && initialData.length > 0) {
47
48
  var buffer = new Uint8Array(initialData).buffer;
49
+
48
50
  this._queuedChunks.push(buffer);
49
51
  }
52
+
50
53
  this._pdfDataRangeTransport = pdfDataRangeTransport;
51
54
  this._isStreamingSupported = !params.disableStream;
52
55
  this._isRangeSupported = !params.disableRange;
53
56
  this._contentLength = params.length;
54
57
  this._fullRequestReader = null;
55
58
  this._rangeReaders = [];
59
+
56
60
  this._pdfDataRangeTransport.addRangeListener(function (begin, chunk) {
57
61
  _this._onReceiveData({
58
62
  begin: begin,
59
63
  chunk: chunk
60
64
  });
61
65
  });
66
+
62
67
  this._pdfDataRangeTransport.addProgressListener(function (loaded) {
63
- _this._onProgress({ loaded: loaded });
68
+ _this._onProgress({
69
+ loaded: loaded
70
+ });
64
71
  });
72
+
65
73
  this._pdfDataRangeTransport.addProgressiveReadListener(function (chunk) {
66
- _this._onReceiveData({ chunk: chunk });
74
+ _this._onReceiveData({
75
+ chunk: chunk
76
+ });
67
77
  });
78
+
68
79
  this._pdfDataRangeTransport.transportReady();
69
80
  }
81
+
70
82
  PDFDataTransportStream.prototype = {
71
83
  _onReceiveData: function PDFDataTransportStream_onReceiveData(args) {
72
84
  var buffer = new Uint8Array(args.chunk).buffer;
85
+
73
86
  if (args.begin === undefined) {
74
87
  if (this._fullRequestReader) {
75
88
  this._fullRequestReader._enqueue(buffer);
@@ -81,22 +94,29 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
81
94
  if (rangeReader._begin !== args.begin) {
82
95
  return false;
83
96
  }
97
+
84
98
  rangeReader._enqueue(buffer);
99
+
85
100
  return true;
86
101
  });
102
+
87
103
  (0, _util.assert)(found);
88
104
  }
89
105
  },
90
106
  _onProgress: function PDFDataTransportStream_onDataProgress(evt) {
91
107
  if (this._rangeReaders.length > 0) {
92
108
  var firstReader = this._rangeReaders[0];
109
+
93
110
  if (firstReader.onProgress) {
94
- firstReader.onProgress({ loaded: evt.loaded });
111
+ firstReader.onProgress({
112
+ loaded: evt.loaded
113
+ });
95
114
  }
96
115
  }
97
116
  },
98
117
  _removeRangeReader: function PDFDataTransportStream_removeRangeReader(reader) {
99
118
  var i = this._rangeReaders.indexOf(reader);
119
+
100
120
  if (i >= 0) {
101
121
  this._rangeReaders.splice(i, 1);
102
122
  }
@@ -109,21 +129,28 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
109
129
  },
110
130
  getRangeReader: function PDFDataTransportStream_getRangeReader(begin, end) {
111
131
  var reader = new PDFDataTransportStreamRangeReader(this, begin, end);
132
+
112
133
  this._pdfDataRangeTransport.requestDataRange(begin, end);
134
+
113
135
  this._rangeReaders.push(reader);
136
+
114
137
  return reader;
115
138
  },
116
139
  cancelAllRequests: function PDFDataTransportStream_cancelAllRequests(reason) {
117
140
  if (this._fullRequestReader) {
118
141
  this._fullRequestReader.cancel(reason);
119
142
  }
143
+
120
144
  var readers = this._rangeReaders.slice(0);
145
+
121
146
  readers.forEach(function (rangeReader) {
122
147
  rangeReader.cancel(reason);
123
148
  });
149
+
124
150
  this._pdfDataRangeTransport.abort();
125
151
  }
126
152
  };
153
+
127
154
  function PDFDataTransportStreamReader(stream, queuedChunks) {
128
155
  this._stream = stream;
129
156
  this._done = false;
@@ -134,40 +161,52 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
134
161
  stream._fullRequestReader = this;
135
162
  this.onProgress = null;
136
163
  }
164
+
137
165
  PDFDataTransportStreamReader.prototype = {
138
166
  _enqueue: function PDFDataTransportStreamReader_enqueue(chunk) {
139
167
  if (this._done) {
140
168
  return;
141
169
  }
170
+
142
171
  if (this._requests.length > 0) {
143
172
  var requestCapability = this._requests.shift();
173
+
144
174
  requestCapability.resolve({
145
175
  value: chunk,
146
176
  done: false
147
177
  });
148
178
  return;
149
179
  }
180
+
150
181
  this._queuedChunks.push(chunk);
151
182
  },
183
+
152
184
  get headersReady() {
153
185
  return this._headersReady;
154
186
  },
187
+
155
188
  get filename() {
156
189
  return this._filename;
157
190
  },
191
+
158
192
  get isRangeSupported() {
159
193
  return this._stream._isRangeSupported;
160
194
  },
195
+
161
196
  get isStreamingSupported() {
162
197
  return this._stream._isStreamingSupported;
163
198
  },
199
+
164
200
  get contentLength() {
165
201
  return this._stream._contentLength;
166
202
  },
203
+
167
204
  read: function () {
168
- var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
205
+ var _read = _asyncToGenerator(
206
+ /*#__PURE__*/
207
+ _regenerator.default.mark(function _callee() {
169
208
  var chunk, requestCapability;
170
- return _regenerator2.default.wrap(function _callee$(_context) {
209
+ return _regenerator.default.wrap(function _callee$(_context) {
171
210
  while (1) {
172
211
  switch (_context.prev = _context.next) {
173
212
  case 0:
@@ -177,7 +216,7 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
177
216
  }
178
217
 
179
218
  chunk = this._queuedChunks.shift();
180
- return _context.abrupt('return', {
219
+ return _context.abrupt("return", {
181
220
  value: chunk,
182
221
  done: false
183
222
  });
@@ -188,7 +227,7 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
188
227
  break;
189
228
  }
190
229
 
191
- return _context.abrupt('return', {
230
+ return _context.abrupt("return", {
192
231
  value: undefined,
193
232
  done: true
194
233
  });
@@ -197,10 +236,11 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
197
236
  requestCapability = (0, _util.createPromiseCapability)();
198
237
 
199
238
  this._requests.push(requestCapability);
200
- return _context.abrupt('return', requestCapability.promise);
239
+
240
+ return _context.abrupt("return", requestCapability.promise);
201
241
 
202
242
  case 8:
203
- case 'end':
243
+ case "end":
204
244
  return _context.stop();
205
245
  }
206
246
  }
@@ -208,23 +248,25 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
208
248
  }));
209
249
 
210
250
  function read() {
211
- return _ref.apply(this, arguments);
251
+ return _read.apply(this, arguments);
212
252
  }
213
253
 
214
254
  return read;
215
255
  }(),
216
-
217
256
  cancel: function PDFDataTransportStreamReader_cancel(reason) {
218
257
  this._done = true;
258
+
219
259
  this._requests.forEach(function (requestCapability) {
220
260
  requestCapability.resolve({
221
261
  value: undefined,
222
262
  done: true
223
263
  });
224
264
  });
265
+
225
266
  this._requests = [];
226
267
  }
227
268
  };
269
+
228
270
  function PDFDataTransportStreamRangeReader(stream, begin, end) {
229
271
  this._stream = stream;
230
272
  this._begin = begin;
@@ -234,37 +276,48 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
234
276
  this._done = false;
235
277
  this.onProgress = null;
236
278
  }
279
+
237
280
  PDFDataTransportStreamRangeReader.prototype = {
238
281
  _enqueue: function PDFDataTransportStreamRangeReader_enqueue(chunk) {
239
282
  if (this._done) {
240
283
  return;
241
284
  }
285
+
242
286
  if (this._requests.length === 0) {
243
287
  this._queuedChunk = chunk;
244
288
  } else {
245
289
  var requestsCapability = this._requests.shift();
290
+
246
291
  requestsCapability.resolve({
247
292
  value: chunk,
248
293
  done: false
249
294
  });
295
+
250
296
  this._requests.forEach(function (requestCapability) {
251
297
  requestCapability.resolve({
252
298
  value: undefined,
253
299
  done: true
254
300
  });
255
301
  });
302
+
256
303
  this._requests = [];
257
304
  }
305
+
258
306
  this._done = true;
307
+
259
308
  this._stream._removeRangeReader(this);
260
309
  },
310
+
261
311
  get isStreamingSupported() {
262
312
  return false;
263
313
  },
314
+
264
315
  read: function () {
265
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
316
+ var _read2 = _asyncToGenerator(
317
+ /*#__PURE__*/
318
+ _regenerator.default.mark(function _callee2() {
266
319
  var chunk, requestCapability;
267
- return _regenerator2.default.wrap(function _callee2$(_context2) {
320
+ return _regenerator.default.wrap(function _callee2$(_context2) {
268
321
  while (1) {
269
322
  switch (_context2.prev = _context2.next) {
270
323
  case 0:
@@ -274,9 +327,8 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
274
327
  }
275
328
 
276
329
  chunk = this._queuedChunk;
277
-
278
330
  this._queuedChunk = null;
279
- return _context2.abrupt('return', {
331
+ return _context2.abrupt("return", {
280
332
  value: chunk,
281
333
  done: false
282
334
  });
@@ -287,7 +339,7 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
287
339
  break;
288
340
  }
289
341
 
290
- return _context2.abrupt('return', {
342
+ return _context2.abrupt("return", {
291
343
  value: undefined,
292
344
  done: true
293
345
  });
@@ -296,10 +348,11 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
296
348
  requestCapability = (0, _util.createPromiseCapability)();
297
349
 
298
350
  this._requests.push(requestCapability);
299
- return _context2.abrupt('return', requestCapability.promise);
351
+
352
+ return _context2.abrupt("return", requestCapability.promise);
300
353
 
301
354
  case 9:
302
- case 'end':
355
+ case "end":
303
356
  return _context2.stop();
304
357
  }
305
358
  }
@@ -307,24 +360,27 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() {
307
360
  }));
308
361
 
309
362
  function read() {
310
- return _ref2.apply(this, arguments);
363
+ return _read2.apply(this, arguments);
311
364
  }
312
365
 
313
366
  return read;
314
367
  }(),
315
-
316
368
  cancel: function PDFDataTransportStreamRangeReader_cancel(reason) {
317
369
  this._done = true;
370
+
318
371
  this._requests.forEach(function (requestCapability) {
319
372
  requestCapability.resolve({
320
373
  value: undefined,
321
374
  done: true
322
375
  });
323
376
  });
377
+
324
378
  this._requests = [];
379
+
325
380
  this._stream._removeRangeReader(this);
326
381
  }
327
382
  };
328
383
  return PDFDataTransportStream;
329
384
  }();
385
+
330
386
  exports.PDFDataTransportStream = PDFDataTransportStream;
@@ -19,23 +19,27 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.WebGLContext = undefined;
27
+ exports.WebGLContext = void 0;
28
28
 
29
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
30
-
31
- var _util = require('../shared/util');
29
+ var _util = require("../shared/util");
32
30
 
33
31
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
34
32
 
35
- var WebGLContext = function () {
33
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
34
+
35
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
36
+
37
+ var WebGLContext =
38
+ /*#__PURE__*/
39
+ function () {
36
40
  function WebGLContext(_ref) {
37
41
  var _ref$enable = _ref.enable,
38
- enable = _ref$enable === undefined ? false : _ref$enable;
42
+ enable = _ref$enable === void 0 ? false : _ref$enable;
39
43
 
40
44
  _classCallCheck(this, WebGLContext);
41
45
 
@@ -43,37 +47,37 @@ var WebGLContext = function () {
43
47
  }
44
48
 
45
49
  _createClass(WebGLContext, [{
46
- key: 'composeSMask',
50
+ key: "composeSMask",
47
51
  value: function composeSMask(_ref2) {
48
52
  var layer = _ref2.layer,
49
53
  mask = _ref2.mask,
50
54
  properties = _ref2.properties;
51
-
52
55
  return WebGLUtils.composeSMask(layer, mask, properties);
53
56
  }
54
57
  }, {
55
- key: 'drawFigures',
58
+ key: "drawFigures",
56
59
  value: function drawFigures(_ref3) {
57
60
  var width = _ref3.width,
58
61
  height = _ref3.height,
59
62
  backgroundColor = _ref3.backgroundColor,
60
63
  figures = _ref3.figures,
61
64
  context = _ref3.context;
62
-
63
65
  return WebGLUtils.drawFigures(width, height, backgroundColor, figures, context);
64
66
  }
65
67
  }, {
66
- key: 'clear',
68
+ key: "clear",
67
69
  value: function clear() {
68
70
  WebGLUtils.cleanup();
69
71
  }
70
72
  }, {
71
- key: 'isEnabled',
73
+ key: "isEnabled",
72
74
  get: function get() {
73
75
  var enabled = this._enabled;
76
+
74
77
  if (enabled) {
75
78
  enabled = WebGLUtils.tryInitGL();
76
79
  }
80
+
77
81
  return (0, _util.shadow)(this, 'isEnabled', enabled);
78
82
  }
79
83
  }]);
@@ -81,37 +85,49 @@ var WebGLContext = function () {
81
85
  return WebGLContext;
82
86
  }();
83
87
 
88
+ exports.WebGLContext = WebGLContext;
89
+
84
90
  var WebGLUtils = function WebGLUtilsClosure() {
85
91
  function loadShader(gl, code, shaderType) {
86
92
  var shader = gl.createShader(shaderType);
87
93
  gl.shaderSource(shader, code);
88
94
  gl.compileShader(shader);
89
95
  var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
96
+
90
97
  if (!compiled) {
91
98
  var errorMsg = gl.getShaderInfoLog(shader);
92
99
  throw new Error('Error during shader compilation: ' + errorMsg);
93
100
  }
101
+
94
102
  return shader;
95
103
  }
104
+
96
105
  function createVertexShader(gl, code) {
97
106
  return loadShader(gl, code, gl.VERTEX_SHADER);
98
107
  }
108
+
99
109
  function createFragmentShader(gl, code) {
100
110
  return loadShader(gl, code, gl.FRAGMENT_SHADER);
101
111
  }
112
+
102
113
  function createProgram(gl, shaders) {
103
114
  var program = gl.createProgram();
115
+
104
116
  for (var i = 0, ii = shaders.length; i < ii; ++i) {
105
117
  gl.attachShader(program, shaders[i]);
106
118
  }
119
+
107
120
  gl.linkProgram(program);
108
121
  var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
122
+
109
123
  if (!linked) {
110
124
  var errorMsg = gl.getProgramInfoLog(program);
111
125
  throw new Error('Error during program linking: ' + errorMsg);
112
126
  }
127
+
113
128
  return program;
114
129
  }
130
+
115
131
  function createTexture(gl, image, textureId) {
116
132
  gl.activeTexture(textureId);
117
133
  var texture = gl.createTexture();
@@ -123,14 +139,20 @@ var WebGLUtils = function WebGLUtilsClosure() {
123
139
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
124
140
  return texture;
125
141
  }
142
+
126
143
  var currentGL, currentCanvas;
144
+
127
145
  function generateGL() {
128
146
  if (currentGL) {
129
147
  return;
130
148
  }
149
+
131
150
  currentCanvas = document.createElement('canvas');
132
- currentGL = currentCanvas.getContext('webgl', { premultipliedalpha: false });
151
+ currentGL = currentCanvas.getContext('webgl', {
152
+ premultipliedalpha: false
153
+ });
133
154
  }
155
+
134
156
  var smaskVertexShaderCode = '\
135
157
  attribute vec2 a_position; \
136
158
  attribute vec2 a_texCoord; \
@@ -174,6 +196,7 @@ var WebGLUtils = function WebGLUtilsClosure() {
174
196
  gl_FragColor = imageColor; \
175
197
  } ';
176
198
  var smaskCache = null;
199
+
177
200
  function initSmaskGL() {
178
201
  var canvas, gl;
179
202
  generateGL();
@@ -204,12 +227,15 @@ var WebGLUtils = function WebGLUtilsClosure() {
204
227
  gl.uniform1i(texMaskLocation, 1);
205
228
  smaskCache = cache;
206
229
  }
230
+
207
231
  function composeSMask(layer, mask, properties) {
208
232
  var width = layer.width,
209
233
  height = layer.height;
234
+
210
235
  if (!smaskCache) {
211
236
  initSmaskGL();
212
237
  }
238
+
213
239
  var cache = smaskCache,
214
240
  canvas = cache.canvas,
215
241
  gl = cache.gl;
@@ -217,11 +243,13 @@ var WebGLUtils = function WebGLUtilsClosure() {
217
243
  canvas.height = height;
218
244
  gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
219
245
  gl.uniform2f(cache.resolutionLocation, width, height);
246
+
220
247
  if (properties.backdrop) {
221
248
  gl.uniform4f(cache.resolutionLocation, properties.backdrop[0], properties.backdrop[1], properties.backdrop[2], 1);
222
249
  } else {
223
250
  gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
224
251
  }
252
+
225
253
  gl.uniform1i(cache.subtypeLocation, properties.subtype === 'Luminosity' ? 1 : 0);
226
254
  var texture = createTexture(gl, layer, gl.TEXTURE0);
227
255
  var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
@@ -241,6 +269,7 @@ var WebGLUtils = function WebGLUtilsClosure() {
241
269
  gl.deleteBuffer(buffer);
242
270
  return canvas;
243
271
  }
272
+
244
273
  var figuresVertexShaderCode = '\
245
274
  attribute vec2 a_position; \
246
275
  attribute vec3 a_color; \
@@ -267,6 +296,7 @@ var WebGLUtils = function WebGLUtilsClosure() {
267
296
  gl_FragColor = v_color; \
268
297
  } ';
269
298
  var figuresCache = null;
299
+
270
300
  function initFiguresGL() {
271
301
  var canvas, gl;
272
302
  generateGL();
@@ -288,10 +318,12 @@ var WebGLUtils = function WebGLUtilsClosure() {
288
318
  cache.colorLocation = gl.getAttribLocation(program, 'a_color');
289
319
  figuresCache = cache;
290
320
  }
321
+
291
322
  function drawFigures(width, height, backgroundColor, figures, context) {
292
323
  if (!figuresCache) {
293
324
  initFiguresGL();
294
325
  }
326
+
295
327
  var cache = figuresCache,
296
328
  canvas = cache.canvas,
297
329
  gl = cache.gl;
@@ -301,33 +333,40 @@ var WebGLUtils = function WebGLUtilsClosure() {
301
333
  gl.uniform2f(cache.resolutionLocation, width, height);
302
334
  var count = 0;
303
335
  var i, ii, rows;
336
+
304
337
  for (i = 0, ii = figures.length; i < ii; i++) {
305
338
  switch (figures[i].type) {
306
339
  case 'lattice':
307
340
  rows = figures[i].coords.length / figures[i].verticesPerRow | 0;
308
341
  count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
309
342
  break;
343
+
310
344
  case 'triangles':
311
345
  count += figures[i].coords.length;
312
346
  break;
313
347
  }
314
348
  }
349
+
315
350
  var coords = new Float32Array(count * 2);
316
351
  var colors = new Uint8Array(count * 3);
317
352
  var coordsMap = context.coords,
318
353
  colorsMap = context.colors;
319
354
  var pIndex = 0,
320
355
  cIndex = 0;
356
+
321
357
  for (i = 0, ii = figures.length; i < ii; i++) {
322
358
  var figure = figures[i],
323
359
  ps = figure.coords,
324
360
  cs = figure.colors;
361
+
325
362
  switch (figure.type) {
326
363
  case 'lattice':
327
364
  var cols = figure.verticesPerRow;
328
365
  rows = ps.length / cols | 0;
366
+
329
367
  for (var row = 1; row < rows; row++) {
330
368
  var offset = row * cols + 1;
369
+
331
370
  for (var col = 1; col < cols; col++, offset++) {
332
371
  coords[pIndex] = coordsMap[ps[offset - cols - 1]];
333
372
  coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
@@ -363,7 +402,9 @@ var WebGLUtils = function WebGLUtilsClosure() {
363
402
  cIndex += 18;
364
403
  }
365
404
  }
405
+
366
406
  break;
407
+
367
408
  case 'triangles':
368
409
  for (var j = 0, jj = ps.length; j < jj; j++) {
369
410
  coords[pIndex] = coordsMap[ps[j]];
@@ -374,14 +415,17 @@ var WebGLUtils = function WebGLUtilsClosure() {
374
415
  pIndex += 2;
375
416
  cIndex += 3;
376
417
  }
418
+
377
419
  break;
378
420
  }
379
421
  }
422
+
380
423
  if (backgroundColor) {
381
424
  gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255, backgroundColor[2] / 255, 1.0);
382
425
  } else {
383
426
  gl.clearColor(0, 0, 0, 0);
384
427
  }
428
+
385
429
  gl.clear(gl.COLOR_BUFFER_BIT);
386
430
  var coordsBuffer = gl.createBuffer();
387
431
  gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
@@ -401,15 +445,16 @@ var WebGLUtils = function WebGLUtilsClosure() {
401
445
  gl.deleteBuffer(colorsBuffer);
402
446
  return canvas;
403
447
  }
448
+
404
449
  return {
405
450
  tryInitGL: function tryInitGL() {
406
451
  try {
407
452
  generateGL();
408
453
  return !!currentGL;
409
454
  } catch (ex) {}
455
+
410
456
  return false;
411
457
  },
412
-
413
458
  composeSMask: composeSMask,
414
459
  drawFigures: drawFigures,
415
460
  cleanup: function cleanup() {
@@ -417,13 +462,14 @@ var WebGLUtils = function WebGLUtilsClosure() {
417
462
  smaskCache.canvas.width = 0;
418
463
  smaskCache.canvas.height = 0;
419
464
  }
465
+
420
466
  if (figuresCache && figuresCache.canvas) {
421
467
  figuresCache.canvas.width = 0;
422
468
  figuresCache.canvas.height = 0;
423
469
  }
470
+
424
471
  smaskCache = null;
425
472
  figuresCache = null;
426
473
  }
427
474
  };
428
- }();
429
- exports.WebGLContext = WebGLContext;
475
+ }();
@@ -19,12 +19,13 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
+ exports.GlobalWorkerOptions = void 0;
27
28
  var GlobalWorkerOptions = Object.create(null);
29
+ exports.GlobalWorkerOptions = GlobalWorkerOptions;
28
30
  GlobalWorkerOptions.workerPort = GlobalWorkerOptions.workerPort === undefined ? null : GlobalWorkerOptions.workerPort;
29
- GlobalWorkerOptions.workerSrc = GlobalWorkerOptions.workerSrc === undefined ? '' : GlobalWorkerOptions.workerSrc;
30
- exports.GlobalWorkerOptions = GlobalWorkerOptions;
31
+ GlobalWorkerOptions.workerSrc = GlobalWorkerOptions.workerSrc === undefined ? '' : GlobalWorkerOptions.workerSrc;