pdfjs-dist 2.0.550 → 2.3.200

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 (168) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +21618 -14369
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +22758 -11399
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/image_decoders/pdf.image_decoders.js +11500 -0
  10. package/image_decoders/pdf.image_decoders.js.map +1 -0
  11. package/image_decoders/pdf.image_decoders.min.js +1 -0
  12. package/lib/core/annotation.js +767 -258
  13. package/lib/core/arithmetic_decoder.js +275 -245
  14. package/lib/core/bidi.js +65 -6
  15. package/lib/core/ccitt.js +173 -18
  16. package/lib/core/ccitt_stream.js +15 -6
  17. package/lib/core/cff_parser.js +433 -61
  18. package/lib/core/charsets.js +5 -4
  19. package/lib/core/chunked_stream.js +428 -157
  20. package/lib/core/cmap.js +326 -87
  21. package/lib/core/colorspace.js +874 -594
  22. package/lib/core/core_utils.js +173 -0
  23. package/lib/core/crypto.js +290 -45
  24. package/lib/core/document.js +575 -272
  25. package/lib/core/encodings.js +19 -10
  26. package/lib/core/evaluator.js +1032 -351
  27. package/lib/core/font_renderer.js +331 -97
  28. package/lib/core/fonts.js +813 -196
  29. package/lib/core/function.js +253 -27
  30. package/lib/core/glyphlist.js +5 -3
  31. package/lib/core/image.js +169 -62
  32. package/lib/core/image_utils.js +111 -0
  33. package/lib/core/jbig2.js +502 -72
  34. package/lib/core/jbig2_stream.js +19 -8
  35. package/lib/core/jpeg_stream.js +38 -13
  36. package/lib/core/jpg.js +293 -52
  37. package/lib/core/jpx.js +419 -12
  38. package/lib/core/jpx_stream.js +18 -6
  39. package/lib/core/metrics.js +15 -15
  40. package/lib/core/murmurhash3.js +56 -34
  41. package/lib/core/obj.js +1368 -500
  42. package/lib/core/operator_list.js +159 -43
  43. package/lib/core/parser.js +544 -199
  44. package/lib/core/pattern.js +170 -21
  45. package/lib/core/pdf_manager.js +324 -134
  46. package/lib/core/primitives.js +169 -61
  47. package/lib/core/ps_parser.js +134 -45
  48. package/lib/core/standard_fonts.js +17 -17
  49. package/lib/core/stream.js +327 -34
  50. package/lib/core/type1_parser.js +148 -8
  51. package/lib/core/unicode.js +32 -5
  52. package/lib/core/worker.js +215 -229
  53. package/lib/core/worker_stream.js +277 -0
  54. package/lib/display/annotation_layer.js +618 -192
  55. package/lib/display/api.js +1798 -882
  56. package/lib/display/api_compatibility.js +5 -10
  57. package/lib/display/canvas.js +366 -45
  58. package/lib/display/content_disposition.js +71 -24
  59. package/lib/display/display_utils.js +777 -0
  60. package/lib/display/fetch_stream.js +205 -87
  61. package/lib/display/font_loader.js +468 -236
  62. package/lib/display/metadata.js +38 -16
  63. package/lib/display/network.js +635 -428
  64. package/lib/display/network_utils.js +38 -19
  65. package/lib/display/node_stream.js +367 -175
  66. package/lib/display/pattern_helper.js +103 -36
  67. package/lib/display/svg.js +1232 -519
  68. package/lib/display/text_layer.js +208 -75
  69. package/lib/display/transport_stream.js +345 -94
  70. package/lib/display/webgl.js +64 -18
  71. package/lib/display/worker_options.js +5 -4
  72. package/lib/display/xml_parser.js +166 -53
  73. package/lib/examples/node/domstubs.js +60 -4
  74. package/lib/pdf.js +35 -14
  75. package/lib/pdf.worker.js +5 -3
  76. package/lib/shared/compatibility.js +170 -572
  77. package/lib/shared/global_scope.js +2 -2
  78. package/lib/shared/is_node.js +4 -4
  79. package/lib/shared/message_handler.js +216 -163
  80. package/lib/shared/streams_polyfill.js +21 -17
  81. package/lib/shared/util.js +495 -385
  82. package/lib/test/unit/annotation_spec.js +1464 -401
  83. package/lib/test/unit/api_spec.js +718 -361
  84. package/lib/test/unit/bidi_spec.js +7 -7
  85. package/lib/test/unit/cff_parser_spec.js +54 -11
  86. package/lib/test/unit/clitests_helper.js +9 -10
  87. package/lib/test/unit/cmap_spec.js +95 -41
  88. package/lib/test/unit/colorspace_spec.js +115 -63
  89. package/lib/test/unit/core_utils_spec.js +191 -0
  90. package/lib/test/unit/crypto_spec.js +17 -5
  91. package/lib/test/unit/custom_spec.js +43 -55
  92. package/lib/test/unit/display_svg_spec.js +34 -18
  93. package/lib/test/unit/display_utils_spec.js +273 -0
  94. package/lib/test/unit/document_spec.js +8 -13
  95. package/lib/test/unit/encodings_spec.js +25 -45
  96. package/lib/test/unit/evaluator_spec.js +59 -20
  97. package/lib/test/unit/fetch_stream_spec.js +111 -0
  98. package/lib/test/unit/function_spec.js +17 -5
  99. package/lib/test/unit/jasmine-boot.js +33 -20
  100. package/lib/test/unit/message_handler_spec.js +30 -13
  101. package/lib/test/unit/metadata_spec.js +71 -11
  102. package/lib/test/unit/murmurhash3_spec.js +3 -3
  103. package/lib/test/unit/network_spec.js +22 -55
  104. package/lib/test/unit/network_utils_spec.js +105 -14
  105. package/lib/test/unit/node_stream_spec.js +58 -34
  106. package/lib/test/unit/parser_spec.js +162 -71
  107. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  108. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  109. package/lib/test/unit/pdf_history_spec.js +21 -9
  110. package/lib/test/unit/primitives_spec.js +55 -22
  111. package/lib/test/unit/stream_spec.js +12 -4
  112. package/lib/test/unit/test_utils.js +273 -56
  113. package/lib/test/unit/testreporter.js +21 -3
  114. package/lib/test/unit/type1_parser_spec.js +9 -7
  115. package/lib/test/unit/ui_utils_spec.js +236 -36
  116. package/lib/test/unit/unicode_spec.js +18 -15
  117. package/lib/test/unit/util_spec.js +87 -128
  118. package/lib/web/annotation_layer_builder.js +39 -22
  119. package/lib/web/app.js +1252 -609
  120. package/lib/web/app_options.js +103 -65
  121. package/lib/web/base_viewer.js +522 -242
  122. package/lib/web/chromecom.js +259 -117
  123. package/lib/web/debugger.js +166 -22
  124. package/lib/web/download_manager.js +31 -12
  125. package/lib/web/firefox_print_service.js +27 -14
  126. package/lib/web/firefoxcom.js +318 -78
  127. package/lib/web/genericcom.js +89 -30
  128. package/lib/web/genericl10n.js +142 -30
  129. package/lib/web/grab_to_pan.js +28 -4
  130. package/lib/web/interfaces.js +174 -47
  131. package/lib/web/overlay_manager.js +235 -85
  132. package/lib/web/password_prompt.js +22 -14
  133. package/lib/web/pdf_attachment_viewer.js +38 -18
  134. package/lib/web/pdf_cursor_tools.js +39 -16
  135. package/lib/web/pdf_document_properties.js +255 -136
  136. package/lib/web/pdf_find_bar.js +84 -40
  137. package/lib/web/pdf_find_controller.js +495 -184
  138. package/lib/web/pdf_find_utils.js +111 -0
  139. package/lib/web/pdf_history.js +190 -53
  140. package/lib/web/pdf_link_service.js +144 -79
  141. package/lib/web/pdf_outline_viewer.js +124 -47
  142. package/lib/web/pdf_page_view.js +194 -74
  143. package/lib/web/pdf_presentation_mode.js +99 -34
  144. package/lib/web/pdf_print_service.js +59 -13
  145. package/lib/web/pdf_rendering_queue.js +28 -9
  146. package/lib/web/pdf_sidebar.js +144 -81
  147. package/lib/web/pdf_sidebar_resizer.js +42 -16
  148. package/lib/web/pdf_single_page_viewer.js +74 -66
  149. package/lib/web/pdf_thumbnail_view.js +104 -33
  150. package/lib/web/pdf_thumbnail_viewer.js +66 -26
  151. package/lib/web/pdf_viewer.component.js +112 -32
  152. package/lib/web/pdf_viewer.js +82 -87
  153. package/lib/web/preferences.js +284 -91
  154. package/lib/web/secondary_toolbar.js +132 -59
  155. package/lib/web/text_layer_builder.js +134 -59
  156. package/lib/web/toolbar.js +80 -43
  157. package/lib/web/ui_utils.js +400 -134
  158. package/lib/web/view_history.js +215 -67
  159. package/lib/web/viewer_compatibility.js +3 -8
  160. package/package.json +3 -2
  161. package/web/pdf_viewer.css +23 -15
  162. package/web/pdf_viewer.js +3429 -1245
  163. package/web/pdf_viewer.js.map +1 -1
  164. package/external/streams/streams-lib.js +0 -3962
  165. package/lib/display/dom_utils.js +0 -429
  166. package/lib/test/unit/dom_utils_spec.js +0 -89
  167. package/lib/test/unit/fonts_spec.js +0 -81
  168. package/lib/web/dom_events.js +0 -137
@@ -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 2017 Mozilla Foundation
5
+ * Copyright 2019 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.
@@ -19,43 +19,87 @@
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.clearPrimitiveCaches = clearPrimitiveCaches;
28
+ exports.isEOF = isEOF;
29
+ exports.isCmd = isCmd;
30
+ exports.isDict = isDict;
31
+ exports.isName = isName;
32
+ exports.isRef = isRef;
33
+ exports.isRefsEqual = isRefsEqual;
34
+ exports.isStream = isStream;
35
+ exports.RefSetCache = exports.RefSet = exports.Ref = exports.Name = exports.Dict = exports.Cmd = exports.EOF = void 0;
36
+
37
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
27
38
 
28
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
39
+ var _util = require("../shared/util");
40
+
41
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
42
+
43
+ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
44
+
45
+ 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); } }
46
+
47
+ 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); }); }; }
29
48
 
30
49
  var EOF = {};
50
+ exports.EOF = EOF;
51
+
31
52
  var Name = function NameClosure() {
53
+ var nameCache = Object.create(null);
54
+
32
55
  function Name(name) {
33
56
  this.name = name;
34
57
  }
58
+
35
59
  Name.prototype = {};
36
- var nameCache = Object.create(null);
60
+
37
61
  Name.get = function Name_get(name) {
38
62
  var nameValue = nameCache[name];
39
63
  return nameValue ? nameValue : nameCache[name] = new Name(name);
40
64
  };
65
+
66
+ Name._clearCache = function () {
67
+ nameCache = Object.create(null);
68
+ };
69
+
41
70
  return Name;
42
71
  }();
72
+
73
+ exports.Name = Name;
74
+
43
75
  var Cmd = function CmdClosure() {
76
+ var cmdCache = Object.create(null);
77
+
44
78
  function Cmd(cmd) {
45
79
  this.cmd = cmd;
46
80
  }
81
+
47
82
  Cmd.prototype = {};
48
- var cmdCache = Object.create(null);
83
+
49
84
  Cmd.get = function Cmd_get(cmd) {
50
85
  var cmdValue = cmdCache[cmd];
51
86
  return cmdValue ? cmdValue : cmdCache[cmd] = new Cmd(cmd);
52
87
  };
88
+
89
+ Cmd._clearCache = function () {
90
+ cmdCache = Object.create(null);
91
+ };
92
+
53
93
  return Cmd;
54
94
  }();
95
+
96
+ exports.Cmd = Cmd;
97
+
55
98
  var Dict = function DictClosure() {
56
99
  var nonSerializable = function nonSerializableClosure() {
57
100
  return nonSerializable;
58
101
  };
102
+
59
103
  function Dict(xref) {
60
104
  this._map = Object.create(null);
61
105
  this.xref = xref;
@@ -63,59 +107,88 @@ var Dict = function DictClosure() {
63
107
  this.suppressEncryption = false;
64
108
  this.__nonSerializable__ = nonSerializable;
65
109
  }
110
+
66
111
  Dict.prototype = {
67
112
  assignXref: function Dict_assignXref(newXref) {
68
113
  this.xref = newXref;
69
114
  },
70
- get: function Dict_get(key1, key2, key3) {
71
- var value;
72
- var xref = this.xref,
73
- suppressEncryption = this.suppressEncryption;
74
- if (typeof (value = this._map[key1]) !== 'undefined' || key1 in this._map || typeof key2 === 'undefined') {
75
- return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
76
- }
77
- if (typeof (value = this._map[key2]) !== 'undefined' || key2 in this._map || typeof key3 === 'undefined') {
78
- return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
79
- }
80
- value = this._map[key3] || null;
81
- return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
82
- },
83
- getAsync: function Dict_getAsync(key1, key2, key3) {
84
- var value;
85
- var xref = this.xref,
86
- suppressEncryption = this.suppressEncryption;
87
- if (typeof (value = this._map[key1]) !== 'undefined' || key1 in this._map || typeof key2 === 'undefined') {
88
- if (xref) {
89
- return xref.fetchIfRefAsync(value, suppressEncryption);
90
- }
91
- return Promise.resolve(value);
92
- }
93
- if (typeof (value = this._map[key2]) !== 'undefined' || key2 in this._map || typeof key3 === 'undefined') {
94
- if (xref) {
95
- return xref.fetchIfRefAsync(value, suppressEncryption);
115
+ get: function get(key1, key2, key3) {
116
+ var value = this._map[key1];
117
+
118
+ if (value === undefined && !(key1 in this._map) && key2 !== undefined) {
119
+ value = this._map[key2];
120
+
121
+ if (value === undefined && !(key2 in this._map) && key3 !== undefined) {
122
+ value = this._map[key3];
96
123
  }
97
- return Promise.resolve(value);
98
124
  }
99
- value = this._map[key3] || null;
100
- if (xref) {
101
- return xref.fetchIfRefAsync(value, suppressEncryption);
125
+
126
+ if (value instanceof Ref && this.xref) {
127
+ return this.xref.fetch(value, this.suppressEncryption);
102
128
  }
103
- return Promise.resolve(value);
129
+
130
+ return value;
104
131
  },
105
- getArray: function Dict_getArray(key1, key2, key3) {
132
+ getAsync: function () {
133
+ var _getAsync = _asyncToGenerator(
134
+ /*#__PURE__*/
135
+ _regenerator["default"].mark(function _callee(key1, key2, key3) {
136
+ var value;
137
+ return _regenerator["default"].wrap(function _callee$(_context) {
138
+ while (1) {
139
+ switch (_context.prev = _context.next) {
140
+ case 0:
141
+ value = this._map[key1];
142
+
143
+ if (value === undefined && !(key1 in this._map) && key2 !== undefined) {
144
+ value = this._map[key2];
145
+
146
+ if (value === undefined && !(key2 in this._map) && key3 !== undefined) {
147
+ value = this._map[key3];
148
+ }
149
+ }
150
+
151
+ if (!(value instanceof Ref && this.xref)) {
152
+ _context.next = 4;
153
+ break;
154
+ }
155
+
156
+ return _context.abrupt("return", this.xref.fetchAsync(value, this.suppressEncryption));
157
+
158
+ case 4:
159
+ return _context.abrupt("return", value);
160
+
161
+ case 5:
162
+ case "end":
163
+ return _context.stop();
164
+ }
165
+ }
166
+ }, _callee, this);
167
+ }));
168
+
169
+ function getAsync(_x, _x2, _x3) {
170
+ return _getAsync.apply(this, arguments);
171
+ }
172
+
173
+ return getAsync;
174
+ }(),
175
+ getArray: function getArray(key1, key2, key3) {
106
176
  var value = this.get(key1, key2, key3);
107
- var xref = this.xref,
108
- suppressEncryption = this.suppressEncryption;
109
- if (!Array.isArray(value) || !xref) {
177
+
178
+ if (!Array.isArray(value) || !this.xref) {
110
179
  return value;
111
180
  }
181
+
112
182
  value = value.slice();
183
+
113
184
  for (var i = 0, ii = value.length; i < ii; i++) {
114
- if (!isRef(value[i])) {
185
+ if (!(value[i] instanceof Ref)) {
115
186
  continue;
116
187
  }
117
- value[i] = xref.fetch(value[i], suppressEncryption);
188
+
189
+ value[i] = this.xref.fetch(value[i], this.suppressEncryption);
118
190
  }
191
+
119
192
  return value;
120
193
  },
121
194
  getRaw: function Dict_getRaw(key) {
@@ -137,44 +210,72 @@ var Dict = function DictClosure() {
137
210
  }
138
211
  };
139
212
  Dict.empty = new Dict(null);
213
+
140
214
  Dict.merge = function (xref, dictArray) {
141
215
  var mergedDict = new Dict(xref);
216
+
142
217
  for (var i = 0, ii = dictArray.length; i < ii; i++) {
143
218
  var dict = dictArray[i];
219
+
144
220
  if (!isDict(dict)) {
145
221
  continue;
146
222
  }
223
+
147
224
  for (var keyName in dict._map) {
148
225
  if (mergedDict._map[keyName] !== undefined) {
149
226
  continue;
150
227
  }
228
+
151
229
  mergedDict._map[keyName] = dict._map[keyName];
152
230
  }
153
231
  }
232
+
154
233
  return mergedDict;
155
234
  };
235
+
156
236
  return Dict;
157
237
  }();
238
+
239
+ exports.Dict = Dict;
240
+
158
241
  var Ref = function RefClosure() {
242
+ var refCache = Object.create(null);
243
+
159
244
  function Ref(num, gen) {
160
245
  this.num = num;
161
246
  this.gen = gen;
162
247
  }
248
+
163
249
  Ref.prototype = {
164
250
  toString: function Ref_toString() {
165
- var str = this.num + 'R';
166
- if (this.gen !== 0) {
167
- str += this.gen;
251
+ if (this.gen === 0) {
252
+ return "".concat(this.num, "R");
168
253
  }
169
- return str;
254
+
255
+ return "".concat(this.num, "R").concat(this.gen);
170
256
  }
171
257
  };
258
+
259
+ Ref.get = function (num, gen) {
260
+ var key = gen === 0 ? "".concat(num, "R") : "".concat(num, "R").concat(gen);
261
+ var refValue = refCache[key];
262
+ return refValue ? refValue : refCache[key] = new Ref(num, gen);
263
+ };
264
+
265
+ Ref._clearCache = function () {
266
+ refCache = Object.create(null);
267
+ };
268
+
172
269
  return Ref;
173
270
  }();
271
+
272
+ exports.Ref = Ref;
273
+
174
274
  var RefSet = function RefSetClosure() {
175
275
  function RefSet() {
176
276
  this.dict = Object.create(null);
177
277
  }
278
+
178
279
  RefSet.prototype = {
179
280
  has: function RefSet_has(ref) {
180
281
  return ref.toString() in this.dict;
@@ -188,10 +289,14 @@ var RefSet = function RefSetClosure() {
188
289
  };
189
290
  return RefSet;
190
291
  }();
292
+
293
+ exports.RefSet = RefSet;
294
+
191
295
  var RefSetCache = function RefSetCacheClosure() {
192
296
  function RefSetCache() {
193
297
  this.dict = Object.create(null);
194
298
  }
299
+
195
300
  RefSetCache.prototype = {
196
301
  get: function RefSetCache_get(ref) {
197
302
  return this.dict[ref.toString()];
@@ -216,38 +321,41 @@ var RefSetCache = function RefSetCacheClosure() {
216
321
  };
217
322
  return RefSetCache;
218
323
  }();
324
+
325
+ exports.RefSetCache = RefSetCache;
326
+
219
327
  function isEOF(v) {
220
328
  return v === EOF;
221
329
  }
330
+
222
331
  function isName(v, name) {
223
332
  return v instanceof Name && (name === undefined || v.name === name);
224
333
  }
334
+
225
335
  function isCmd(v, cmd) {
226
336
  return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
227
337
  }
338
+
228
339
  function isDict(v, type) {
229
340
  return v instanceof Dict && (type === undefined || isName(v.get('Type'), type));
230
341
  }
342
+
231
343
  function isRef(v) {
232
344
  return v instanceof Ref;
233
345
  }
346
+
234
347
  function isRefsEqual(v1, v2) {
235
348
  return v1.num === v2.num && v1.gen === v2.gen;
236
349
  }
350
+
237
351
  function isStream(v) {
238
- return (typeof v === 'undefined' ? 'undefined' : _typeof(v)) === 'object' && v !== null && v.getBytes !== undefined;
352
+ return _typeof(v) === 'object' && v !== null && v.getBytes !== undefined;
239
353
  }
240
- exports.EOF = EOF;
241
- exports.Cmd = Cmd;
242
- exports.Dict = Dict;
243
- exports.Name = Name;
244
- exports.Ref = Ref;
245
- exports.RefSet = RefSet;
246
- exports.RefSetCache = RefSetCache;
247
- exports.isEOF = isEOF;
248
- exports.isCmd = isCmd;
249
- exports.isDict = isDict;
250
- exports.isName = isName;
251
- exports.isRef = isRef;
252
- exports.isRefsEqual = isRefsEqual;
253
- exports.isStream = isStream;
354
+
355
+ function clearPrimitiveCaches() {
356
+ Cmd._clearCache();
357
+
358
+ Name._clearCache();
359
+
360
+ Ref._clearCache();
361
+ }
@@ -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 2017 Mozilla Foundation
5
+ * Copyright 2019 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.
@@ -19,50 +19,72 @@
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.PostScriptParser = exports.PostScriptLexer = undefined;
27
+ exports.PostScriptParser = exports.PostScriptLexer = void 0;
28
28
 
29
- var _util = require('../shared/util');
29
+ var _util = require("../shared/util");
30
30
 
31
- var _primitives = require('./primitives');
31
+ var _primitives = require("./primitives");
32
32
 
33
- var PostScriptParser = function PostScriptParserClosure() {
33
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
34
+
35
+ 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); } }
36
+
37
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
38
+
39
+ var PostScriptParser =
40
+ /*#__PURE__*/
41
+ function () {
34
42
  function PostScriptParser(lexer) {
43
+ _classCallCheck(this, PostScriptParser);
44
+
35
45
  this.lexer = lexer;
36
46
  this.operators = [];
37
47
  this.token = null;
38
48
  this.prev = null;
39
49
  }
40
- PostScriptParser.prototype = {
41
- nextToken: function PostScriptParser_nextToken() {
50
+
51
+ _createClass(PostScriptParser, [{
52
+ key: "nextToken",
53
+ value: function nextToken() {
42
54
  this.prev = this.token;
43
55
  this.token = this.lexer.getToken();
44
- },
45
- accept: function PostScriptParser_accept(type) {
56
+ }
57
+ }, {
58
+ key: "accept",
59
+ value: function accept(type) {
46
60
  if (this.token.type === type) {
47
61
  this.nextToken();
48
62
  return true;
49
63
  }
64
+
50
65
  return false;
51
- },
52
- expect: function PostScriptParser_expect(type) {
66
+ }
67
+ }, {
68
+ key: "expect",
69
+ value: function expect(type) {
53
70
  if (this.accept(type)) {
54
71
  return true;
55
72
  }
56
- throw new _util.FormatError('Unexpected symbol: found ' + this.token.type + ' expected ' + type + '.');
57
- },
58
- parse: function PostScriptParser_parse() {
73
+
74
+ throw new _util.FormatError("Unexpected symbol: found ".concat(this.token.type, " expected ").concat(type, "."));
75
+ }
76
+ }, {
77
+ key: "parse",
78
+ value: function parse() {
59
79
  this.nextToken();
60
80
  this.expect(PostScriptTokenTypes.LBRACE);
61
81
  this.parseBlock();
62
82
  this.expect(PostScriptTokenTypes.RBRACE);
63
83
  return this.operators;
64
- },
65
- parseBlock: function PostScriptParser_parseBlock() {
84
+ }
85
+ }, {
86
+ key: "parseBlock",
87
+ value: function parseBlock() {
66
88
  while (true) {
67
89
  if (this.accept(PostScriptTokenTypes.NUMBER)) {
68
90
  this.operators.push(this.prev.value);
@@ -74,12 +96,15 @@ var PostScriptParser = function PostScriptParserClosure() {
74
96
  return;
75
97
  }
76
98
  }
77
- },
78
- parseCondition: function PostScriptParser_parseCondition() {
99
+ }
100
+ }, {
101
+ key: "parseCondition",
102
+ value: function parseCondition() {
79
103
  var conditionLocation = this.operators.length;
80
104
  this.operators.push(null, null);
81
105
  this.parseBlock();
82
106
  this.expect(PostScriptTokenTypes.RBRACE);
107
+
83
108
  if (this.accept(PostScriptTokenTypes.IF)) {
84
109
  this.operators[conditionLocation] = this.operators.length;
85
110
  this.operators[conditionLocation + 1] = 'jz';
@@ -98,9 +123,12 @@ var PostScriptParser = function PostScriptParserClosure() {
98
123
  throw new _util.FormatError('PS Function: error parsing conditional.');
99
124
  }
100
125
  }
101
- };
126
+ }]);
127
+
102
128
  return PostScriptParser;
103
129
  }();
130
+
131
+ exports.PostScriptParser = PostScriptParser;
104
132
  var PostScriptTokenTypes = {
105
133
  LBRACE: 0,
106
134
  RBRACE: 1,
@@ -109,42 +137,86 @@ var PostScriptTokenTypes = {
109
137
  IF: 4,
110
138
  IFELSE: 5
111
139
  };
140
+
112
141
  var PostScriptToken = function PostScriptTokenClosure() {
113
- function PostScriptToken(type, value) {
114
- this.type = type;
115
- this.value = value;
116
- }
117
142
  var opCache = Object.create(null);
118
- PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
119
- var opValue = opCache[op];
120
- if (opValue) {
121
- return opValue;
143
+
144
+ var PostScriptToken =
145
+ /*#__PURE__*/
146
+ function () {
147
+ function PostScriptToken(type, value) {
148
+ _classCallCheck(this, PostScriptToken);
149
+
150
+ this.type = type;
151
+ this.value = value;
122
152
  }
123
- return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
124
- };
125
- PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE, '{');
126
- PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE, '}');
127
- PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
128
- PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE, 'IFELSE');
153
+
154
+ _createClass(PostScriptToken, null, [{
155
+ key: "getOperator",
156
+ value: function getOperator(op) {
157
+ var opValue = opCache[op];
158
+
159
+ if (opValue) {
160
+ return opValue;
161
+ }
162
+
163
+ return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
164
+ }
165
+ }, {
166
+ key: "LBRACE",
167
+ get: function get() {
168
+ return (0, _util.shadow)(this, 'LBRACE', new PostScriptToken(PostScriptTokenTypes.LBRACE, '{'));
169
+ }
170
+ }, {
171
+ key: "RBRACE",
172
+ get: function get() {
173
+ return (0, _util.shadow)(this, 'RBRACE', new PostScriptToken(PostScriptTokenTypes.RBRACE, '}'));
174
+ }
175
+ }, {
176
+ key: "IF",
177
+ get: function get() {
178
+ return (0, _util.shadow)(this, 'IF', new PostScriptToken(PostScriptTokenTypes.IF, 'IF'));
179
+ }
180
+ }, {
181
+ key: "IFELSE",
182
+ get: function get() {
183
+ return (0, _util.shadow)(this, 'IFELSE', new PostScriptToken(PostScriptTokenTypes.IFELSE, 'IFELSE'));
184
+ }
185
+ }]);
186
+
187
+ return PostScriptToken;
188
+ }();
189
+
129
190
  return PostScriptToken;
130
191
  }();
131
- var PostScriptLexer = function PostScriptLexerClosure() {
192
+
193
+ var PostScriptLexer =
194
+ /*#__PURE__*/
195
+ function () {
132
196
  function PostScriptLexer(stream) {
197
+ _classCallCheck(this, PostScriptLexer);
198
+
133
199
  this.stream = stream;
134
200
  this.nextChar();
135
201
  this.strBuf = [];
136
202
  }
137
- PostScriptLexer.prototype = {
138
- nextChar: function PostScriptLexer_nextChar() {
203
+
204
+ _createClass(PostScriptLexer, [{
205
+ key: "nextChar",
206
+ value: function nextChar() {
139
207
  return this.currentChar = this.stream.getByte();
140
- },
141
- getToken: function PostScriptLexer_getToken() {
208
+ }
209
+ }, {
210
+ key: "getToken",
211
+ value: function getToken() {
142
212
  var comment = false;
143
213
  var ch = this.currentChar;
214
+
144
215
  while (true) {
145
216
  if (ch < 0) {
146
217
  return _primitives.EOF;
147
218
  }
219
+
148
220
  if (comment) {
149
221
  if (ch === 0x0A || ch === 0x0D) {
150
222
  comment = false;
@@ -154,8 +226,10 @@ var PostScriptLexer = function PostScriptLexerClosure() {
154
226
  } else if (!(0, _util.isSpace)(ch)) {
155
227
  break;
156
228
  }
229
+
157
230
  ch = this.nextChar();
158
231
  }
232
+
159
233
  switch (ch | 0) {
160
234
  case 0x30:
161
235
  case 0x31:
@@ -171,34 +245,45 @@ var PostScriptLexer = function PostScriptLexerClosure() {
171
245
  case 0x2D:
172
246
  case 0x2E:
173
247
  return new PostScriptToken(PostScriptTokenTypes.NUMBER, this.getNumber());
248
+
174
249
  case 0x7B:
175
250
  this.nextChar();
176
251
  return PostScriptToken.LBRACE;
252
+
177
253
  case 0x7D:
178
254
  this.nextChar();
179
255
  return PostScriptToken.RBRACE;
180
256
  }
257
+
181
258
  var strBuf = this.strBuf;
182
259
  strBuf.length = 0;
183
260
  strBuf[0] = String.fromCharCode(ch);
261
+
184
262
  while ((ch = this.nextChar()) >= 0 && (ch >= 0x41 && ch <= 0x5A || ch >= 0x61 && ch <= 0x7A)) {
185
263
  strBuf.push(String.fromCharCode(ch));
186
264
  }
265
+
187
266
  var str = strBuf.join('');
267
+
188
268
  switch (str.toLowerCase()) {
189
269
  case 'if':
190
270
  return PostScriptToken.IF;
271
+
191
272
  case 'ifelse':
192
273
  return PostScriptToken.IFELSE;
274
+
193
275
  default:
194
276
  return PostScriptToken.getOperator(str);
195
277
  }
196
- },
197
- getNumber: function PostScriptLexer_getNumber() {
278
+ }
279
+ }, {
280
+ key: "getNumber",
281
+ value: function getNumber() {
198
282
  var ch = this.currentChar;
199
283
  var strBuf = this.strBuf;
200
284
  strBuf.length = 0;
201
285
  strBuf[0] = String.fromCharCode(ch);
286
+
202
287
  while ((ch = this.nextChar()) >= 0) {
203
288
  if (ch >= 0x30 && ch <= 0x39 || ch === 0x2D || ch === 0x2E) {
204
289
  strBuf.push(String.fromCharCode(ch));
@@ -206,14 +291,18 @@ var PostScriptLexer = function PostScriptLexerClosure() {
206
291
  break;
207
292
  }
208
293
  }
294
+
209
295
  var value = parseFloat(strBuf.join(''));
296
+
210
297
  if (isNaN(value)) {
211
- throw new _util.FormatError('Invalid floating point number: ' + value);
298
+ throw new _util.FormatError("Invalid floating point number: ".concat(value));
212
299
  }
300
+
213
301
  return value;
214
302
  }
215
- };
303
+ }]);
304
+
216
305
  return PostScriptLexer;
217
306
  }();
218
- exports.PostScriptLexer = PostScriptLexer;
219
- exports.PostScriptParser = PostScriptParser;
307
+
308
+ exports.PostScriptLexer = PostScriptLexer;