pdfjs-dist 2.3.200 → 2.4.456

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 (185) hide show
  1. package/README.md +4 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +6499 -17971
  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 +19303 -29896
  8. package/build/pdf.worker.js.map +1 -1
  9. package/build/pdf.worker.min.js +22 -1
  10. package/es5/build/pdf.js +25473 -0
  11. package/es5/build/pdf.js.map +1 -0
  12. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  13. package/es5/build/pdf.worker.js +57878 -0
  14. package/es5/build/pdf.worker.js.map +1 -0
  15. package/es5/web/images/annotation-check.svg +11 -0
  16. package/es5/web/images/annotation-comment.svg +16 -0
  17. package/es5/web/images/annotation-help.svg +26 -0
  18. package/es5/web/images/annotation-insert.svg +10 -0
  19. package/es5/web/images/annotation-key.svg +11 -0
  20. package/es5/web/images/annotation-newparagraph.svg +11 -0
  21. package/es5/web/images/annotation-noicon.svg +7 -0
  22. package/es5/web/images/annotation-note.svg +42 -0
  23. package/es5/web/images/annotation-paragraph.svg +16 -0
  24. package/es5/web/images/loading-icon.gif +0 -0
  25. package/es5/web/images/shadow.png +0 -0
  26. package/es5/web/images/texture.png +0 -0
  27. package/es5/web/pdf_viewer.css +407 -0
  28. package/es5/web/pdf_viewer.js +7757 -0
  29. package/es5/web/pdf_viewer.js.map +1 -0
  30. package/image_decoders/pdf.image_decoders.js +1333 -4839
  31. package/image_decoders/pdf.image_decoders.js.map +1 -1
  32. package/image_decoders/pdf.image_decoders.min.js +22 -1
  33. package/lib/README.md +7 -0
  34. package/lib/core/annotation.js +683 -1066
  35. package/lib/core/arithmetic_decoder.js +81 -97
  36. package/lib/core/bidi.js +54 -46
  37. package/lib/core/ccitt.js +88 -81
  38. package/lib/core/ccitt_stream.js +15 -14
  39. package/lib/core/cff_parser.js +196 -193
  40. package/lib/core/charsets.js +4 -4
  41. package/lib/core/chunked_stream.js +441 -569
  42. package/lib/core/cmap.js +220 -279
  43. package/lib/core/colorspace.js +699 -863
  44. package/lib/core/core_utils.js +59 -80
  45. package/lib/core/crypto.js +379 -437
  46. package/lib/core/document.js +564 -673
  47. package/lib/core/encodings.js +15 -15
  48. package/lib/core/evaluator.js +983 -889
  49. package/lib/core/font_renderer.js +128 -171
  50. package/lib/core/fonts.js +451 -400
  51. package/lib/core/function.js +289 -285
  52. package/lib/core/glyphlist.js +4527 -4527
  53. package/lib/core/image.js +138 -117
  54. package/lib/core/image_utils.js +46 -63
  55. package/lib/core/jbig2.js +324 -332
  56. package/lib/core/jbig2_stream.js +18 -17
  57. package/lib/core/jpeg_stream.js +133 -24
  58. package/lib/core/jpg.js +238 -210
  59. package/lib/core/jpx.js +158 -157
  60. package/lib/core/jpx_stream.js +28 -28
  61. package/lib/core/metrics.js +2928 -2928
  62. package/lib/core/murmurhash3.js +87 -102
  63. package/lib/core/obj.js +1111 -1302
  64. package/lib/core/operator_list.js +55 -42
  65. package/lib/core/parser.js +956 -987
  66. package/lib/core/pattern.js +69 -69
  67. package/lib/core/pdf_manager.js +149 -316
  68. package/lib/core/primitives.js +45 -77
  69. package/lib/core/ps_parser.js +175 -214
  70. package/lib/core/standard_fonts.js +237 -236
  71. package/lib/core/stream.js +83 -77
  72. package/lib/core/type1_parser.js +78 -68
  73. package/lib/core/unicode.js +1654 -1654
  74. package/lib/core/worker.js +148 -196
  75. package/lib/core/worker_stream.js +101 -210
  76. package/lib/display/annotation_layer.js +733 -1155
  77. package/lib/display/api.js +1539 -1928
  78. package/lib/display/api_compatibility.js +10 -8
  79. package/lib/display/canvas.js +159 -158
  80. package/lib/display/content_disposition.js +36 -55
  81. package/lib/display/display_utils.js +298 -551
  82. package/lib/display/fetch_stream.js +181 -305
  83. package/lib/display/font_loader.js +273 -416
  84. package/lib/display/metadata.js +86 -98
  85. package/lib/display/network.js +376 -511
  86. package/lib/display/network_utils.js +20 -19
  87. package/lib/display/node_stream.js +276 -460
  88. package/lib/display/pattern_helper.js +76 -44
  89. package/lib/display/svg.js +1137 -1405
  90. package/lib/display/text_layer.js +75 -82
  91. package/lib/display/transport_stream.js +236 -374
  92. package/lib/display/webgl.js +70 -83
  93. package/lib/display/worker_options.js +3 -3
  94. package/lib/display/xml_parser.js +303 -392
  95. package/lib/examples/node/domstubs.js +37 -37
  96. package/lib/pdf.js +22 -21
  97. package/lib/pdf.worker.js +5 -5
  98. package/lib/shared/compatibility.js +2 -251
  99. package/lib/shared/is_node.js +7 -6
  100. package/lib/shared/message_handler.js +222 -194
  101. package/lib/shared/util.js +269 -405
  102. package/lib/test/unit/annotation_spec.js +1089 -1014
  103. package/lib/test/unit/api_spec.js +617 -544
  104. package/lib/test/unit/bidi_spec.js +7 -7
  105. package/lib/test/unit/cff_parser_spec.js +63 -62
  106. package/lib/test/unit/clitests_helper.js +7 -9
  107. package/lib/test/unit/cmap_spec.js +84 -86
  108. package/lib/test/unit/colorspace_spec.js +154 -154
  109. package/lib/test/unit/core_utils_spec.js +125 -105
  110. package/lib/test/unit/crypto_spec.js +181 -181
  111. package/lib/test/unit/custom_spec.js +22 -24
  112. package/lib/test/unit/display_svg_spec.js +35 -36
  113. package/lib/test/unit/display_utils_spec.js +139 -149
  114. package/lib/test/unit/document_spec.js +16 -16
  115. package/lib/test/unit/encodings_spec.js +12 -34
  116. package/lib/test/unit/evaluator_spec.js +81 -95
  117. package/lib/test/unit/fetch_stream_spec.js +30 -30
  118. package/lib/test/unit/function_spec.js +206 -204
  119. package/lib/test/unit/jasmine-boot.js +48 -32
  120. package/lib/test/unit/message_handler_spec.js +172 -162
  121. package/lib/test/unit/metadata_spec.js +69 -69
  122. package/lib/test/unit/murmurhash3_spec.js +12 -12
  123. package/lib/test/unit/network_spec.js +12 -12
  124. package/lib/test/unit/network_utils_spec.js +152 -152
  125. package/lib/test/unit/node_stream_spec.js +74 -90
  126. package/lib/test/unit/parser_spec.js +107 -113
  127. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  128. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  129. package/lib/test/unit/pdf_history_spec.js +32 -32
  130. package/lib/test/unit/primitives_spec.js +117 -115
  131. package/lib/test/unit/stream_spec.js +16 -14
  132. package/lib/test/unit/test_utils.js +119 -285
  133. package/lib/test/unit/testreporter.js +19 -19
  134. package/lib/test/unit/type1_parser_spec.js +41 -41
  135. package/lib/test/unit/ui_utils_spec.js +318 -426
  136. package/lib/test/unit/unicode_spec.js +42 -42
  137. package/lib/test/unit/util_spec.js +122 -143
  138. package/lib/web/annotation_layer_builder.js +66 -103
  139. package/lib/web/app.js +1166 -1196
  140. package/lib/web/app_options.js +61 -77
  141. package/lib/web/base_viewer.js +804 -850
  142. package/lib/web/chromecom.js +164 -249
  143. package/lib/web/debugger.js +149 -205
  144. package/lib/web/download_manager.js +38 -57
  145. package/lib/web/firefox_print_service.js +35 -30
  146. package/lib/web/firefoxcom.js +175 -374
  147. package/lib/web/genericcom.js +26 -108
  148. package/lib/web/genericl10n.js +24 -153
  149. package/lib/web/grab_to_pan.js +30 -30
  150. package/lib/web/interfaces.js +80 -258
  151. package/lib/web/overlay_manager.js +70 -246
  152. package/lib/web/password_prompt.js +38 -64
  153. package/lib/web/pdf_attachment_viewer.js +105 -130
  154. package/lib/web/pdf_cursor_tools.js +75 -102
  155. package/lib/web/pdf_document_properties.js +227 -376
  156. package/lib/web/pdf_find_bar.js +137 -171
  157. package/lib/web/pdf_find_controller.js +492 -549
  158. package/lib/web/pdf_find_utils.js +13 -13
  159. package/lib/web/pdf_history.js +395 -406
  160. package/lib/web/pdf_link_service.js +302 -349
  161. package/lib/web/pdf_outline_viewer.js +148 -209
  162. package/lib/web/pdf_page_view.js +449 -507
  163. package/lib/web/pdf_presentation_mode.js +304 -357
  164. package/lib/web/pdf_print_service.js +90 -104
  165. package/lib/web/pdf_rendering_queue.js +87 -108
  166. package/lib/web/pdf_sidebar.js +264 -304
  167. package/lib/web/pdf_sidebar_resizer.js +92 -119
  168. package/lib/web/pdf_single_page_viewer.js +77 -126
  169. package/lib/web/pdf_thumbnail_view.js +276 -297
  170. package/lib/web/pdf_thumbnail_viewer.js +186 -206
  171. package/lib/web/pdf_viewer.component.js +20 -21
  172. package/lib/web/pdf_viewer.js +55 -115
  173. package/lib/web/preferences.js +66 -273
  174. package/lib/web/secondary_toolbar.js +164 -196
  175. package/lib/web/text_layer_builder.js +284 -317
  176. package/lib/web/toolbar.js +216 -211
  177. package/lib/web/ui_utils.js +303 -404
  178. package/lib/web/view_history.js +49 -222
  179. package/lib/web/viewer_compatibility.js +7 -5
  180. package/package.json +2 -9
  181. package/web/pdf_viewer.css +25 -18
  182. package/web/pdf_viewer.js +3481 -4764
  183. package/web/pdf_viewer.js.map +1 -1
  184. package/webpack.js +14 -5
  185. package/lib/shared/streams_polyfill.js +0 -43
@@ -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,137 +26,77 @@ Object.defineProperty(exports, "__esModule", {
26
26
  });
27
27
  exports.PDFViewer = void 0;
28
28
 
29
- var _base_viewer = require("./base_viewer");
29
+ var _base_viewer = require("./base_viewer.js");
30
30
 
31
31
  var _pdf = require("../pdf");
32
32
 
33
- 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); }
34
-
35
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
36
-
37
- 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); } }
38
-
39
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
40
-
41
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
42
-
43
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
44
-
45
- function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
46
-
47
- function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
48
-
49
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
50
-
51
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
33
+ class PDFViewer extends _base_viewer.BaseViewer {
34
+ get _setDocumentViewerElement() {
35
+ return (0, _pdf.shadow)(this, "_setDocumentViewerElement", this.viewer);
36
+ }
52
37
 
53
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
38
+ _scrollIntoView({
39
+ pageDiv,
40
+ pageSpot = null,
41
+ pageNumber = null
42
+ }) {
43
+ if (!pageSpot && !this.isInPresentationMode) {
44
+ const left = pageDiv.offsetLeft + pageDiv.clientLeft;
45
+ const right = left + pageDiv.clientWidth;
46
+ const {
47
+ scrollLeft,
48
+ clientWidth
49
+ } = this.container;
50
+
51
+ if (this._isScrollModeHorizontal || left < scrollLeft || right > scrollLeft + clientWidth) {
52
+ pageSpot = {
53
+ left: 0,
54
+ top: 0
55
+ };
56
+ }
57
+ }
54
58
 
55
- var PDFViewer =
56
- /*#__PURE__*/
57
- function (_BaseViewer) {
58
- _inherits(PDFViewer, _BaseViewer);
59
+ super._scrollIntoView({
60
+ pageDiv,
61
+ pageSpot,
62
+ pageNumber
63
+ });
64
+ }
59
65
 
60
- function PDFViewer() {
61
- _classCallCheck(this, PDFViewer);
66
+ _getVisiblePages() {
67
+ if (this.isInPresentationMode) {
68
+ return this._getCurrentVisiblePage();
69
+ }
62
70
 
63
- return _possibleConstructorReturn(this, _getPrototypeOf(PDFViewer).apply(this, arguments));
71
+ return super._getVisiblePages();
64
72
  }
65
73
 
66
- _createClass(PDFViewer, [{
67
- key: "_scrollIntoView",
68
- value: function _scrollIntoView(_ref) {
69
- var pageDiv = _ref.pageDiv,
70
- _ref$pageSpot = _ref.pageSpot,
71
- pageSpot = _ref$pageSpot === void 0 ? null : _ref$pageSpot,
72
- _ref$pageNumber = _ref.pageNumber,
73
- pageNumber = _ref$pageNumber === void 0 ? null : _ref$pageNumber;
74
-
75
- if (!pageSpot && !this.isInPresentationMode) {
76
- var left = pageDiv.offsetLeft + pageDiv.clientLeft;
77
- var right = left + pageDiv.clientWidth;
78
- var _this$container = this.container,
79
- scrollLeft = _this$container.scrollLeft,
80
- clientWidth = _this$container.clientWidth;
81
-
82
- if (this._isScrollModeHorizontal || left < scrollLeft || right > scrollLeft + clientWidth) {
83
- pageSpot = {
84
- left: 0,
85
- top: 0
86
- };
87
- }
88
- }
89
-
90
- _get(_getPrototypeOf(PDFViewer.prototype), "_scrollIntoView", this).call(this, {
91
- pageDiv: pageDiv,
92
- pageSpot: pageSpot,
93
- pageNumber: pageNumber
94
- });
74
+ _updateHelper(visiblePages) {
75
+ if (this.isInPresentationMode) {
76
+ return;
95
77
  }
96
- }, {
97
- key: "_getVisiblePages",
98
- value: function _getVisiblePages() {
99
- if (this.isInPresentationMode) {
100
- return this._getCurrentVisiblePage();
101
- }
102
78
 
103
- return _get(_getPrototypeOf(PDFViewer.prototype), "_getVisiblePages", this).call(this);
104
- }
105
- }, {
106
- key: "_updateHelper",
107
- value: function _updateHelper(visiblePages) {
108
- if (this.isInPresentationMode) {
109
- return;
110
- }
79
+ let currentId = this._currentPageNumber;
80
+ let stillFullyVisible = false;
111
81
 
112
- var currentId = this._currentPageNumber;
113
- var stillFullyVisible = false;
114
- var _iteratorNormalCompletion = true;
115
- var _didIteratorError = false;
116
- var _iteratorError = undefined;
117
-
118
- try {
119
- for (var _iterator = visiblePages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
120
- var page = _step.value;
121
-
122
- if (page.percent < 100) {
123
- break;
124
- }
125
-
126
- if (page.id === currentId) {
127
- stillFullyVisible = true;
128
- break;
129
- }
130
- }
131
- } catch (err) {
132
- _didIteratorError = true;
133
- _iteratorError = err;
134
- } finally {
135
- try {
136
- if (!_iteratorNormalCompletion && _iterator["return"] != null) {
137
- _iterator["return"]();
138
- }
139
- } finally {
140
- if (_didIteratorError) {
141
- throw _iteratorError;
142
- }
143
- }
82
+ for (const page of visiblePages) {
83
+ if (page.percent < 100) {
84
+ break;
144
85
  }
145
86
 
146
- if (!stillFullyVisible) {
147
- currentId = visiblePages[0].id;
87
+ if (page.id === currentId) {
88
+ stillFullyVisible = true;
89
+ break;
148
90
  }
149
-
150
- this._setCurrentPageNumber(currentId);
151
91
  }
152
- }, {
153
- key: "_setDocumentViewerElement",
154
- get: function get() {
155
- return (0, _pdf.shadow)(this, '_setDocumentViewerElement', this.viewer);
92
+
93
+ if (!stillFullyVisible) {
94
+ currentId = visiblePages[0].id;
156
95
  }
157
- }]);
158
96
 
159
- return PDFViewer;
160
- }(_base_viewer.BaseViewer);
97
+ this._setCurrentPageNumber(currentId);
98
+ }
99
+
100
+ }
161
101
 
162
102
  exports.PDFViewer = PDFViewer;
@@ -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.
@@ -25,24 +25,7 @@ Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
27
  exports.BasePreferences = void 0;
28
-
29
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
30
-
31
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
32
-
33
- 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); } }
34
-
35
- 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); }); }; }
36
-
37
- 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); }
38
-
39
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
40
-
41
- 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); } }
42
-
43
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
44
-
45
- var defaultPreferences = null;
28
+ let defaultPreferences = null;
46
29
 
47
30
  function getDefaultPreferences() {
48
31
  if (!defaultPreferences) {
@@ -55,6 +38,7 @@ function getDefaultPreferences() {
55
38
  "eventBusDispatchToDOM": false,
56
39
  "externalLinkTarget": 0,
57
40
  "historyUpdateUrl": false,
41
+ "ignoreDestinationZoom": false,
58
42
  "pdfBugEnabled": false,
59
43
  "renderer": "canvas",
60
44
  "renderInteractiveForms": false,
@@ -74,296 +58,105 @@ function getDefaultPreferences() {
74
58
  return defaultPreferences;
75
59
  }
76
60
 
77
- var BasePreferences =
78
- /*#__PURE__*/
79
- function () {
80
- function BasePreferences() {
81
- var _this = this;
82
-
83
- _classCallCheck(this, BasePreferences);
84
-
61
+ class BasePreferences {
62
+ constructor() {
85
63
  if (this.constructor === BasePreferences) {
86
- throw new Error('Cannot initialize BasePreferences.');
64
+ throw new Error("Cannot initialize BasePreferences.");
87
65
  }
88
66
 
89
67
  this.prefs = null;
90
- this._initializedPromise = getDefaultPreferences().then(function (defaults) {
91
- Object.defineProperty(_this, 'defaults', {
68
+ this._initializedPromise = getDefaultPreferences().then(defaults => {
69
+ Object.defineProperty(this, "defaults", {
92
70
  value: Object.freeze(defaults),
93
71
  writable: false,
94
72
  enumerable: true,
95
73
  configurable: false
96
74
  });
97
- _this.prefs = Object.assign(Object.create(null), defaults);
98
- return _this._readFromStorage(defaults);
99
- }).then(function (prefs) {
75
+ this.prefs = Object.assign(Object.create(null), defaults);
76
+ return this._readFromStorage(defaults);
77
+ }).then(prefs => {
100
78
  if (!prefs) {
101
79
  return;
102
80
  }
103
81
 
104
- for (var name in prefs) {
105
- var defaultValue = _this.defaults[name],
106
- prefValue = prefs[name];
82
+ for (const name in prefs) {
83
+ const defaultValue = this.defaults[name],
84
+ prefValue = prefs[name];
107
85
 
108
- if (defaultValue === undefined || _typeof(prefValue) !== _typeof(defaultValue)) {
86
+ if (defaultValue === undefined || typeof prefValue !== typeof defaultValue) {
109
87
  continue;
110
88
  }
111
89
 
112
- _this.prefs[name] = prefValue;
90
+ this.prefs[name] = prefValue;
113
91
  }
114
92
  });
115
93
  }
116
94
 
117
- _createClass(BasePreferences, [{
118
- key: "_writeToStorage",
119
- value: function () {
120
- var _writeToStorage2 = _asyncToGenerator(
121
- /*#__PURE__*/
122
- _regenerator["default"].mark(function _callee(prefObj) {
123
- return _regenerator["default"].wrap(function _callee$(_context) {
124
- while (1) {
125
- switch (_context.prev = _context.next) {
126
- case 0:
127
- throw new Error('Not implemented: _writeToStorage');
128
-
129
- case 1:
130
- case "end":
131
- return _context.stop();
132
- }
133
- }
134
- }, _callee);
135
- }));
136
-
137
- function _writeToStorage(_x) {
138
- return _writeToStorage2.apply(this, arguments);
139
- }
140
-
141
- return _writeToStorage;
142
- }()
143
- }, {
144
- key: "_readFromStorage",
145
- value: function () {
146
- var _readFromStorage2 = _asyncToGenerator(
147
- /*#__PURE__*/
148
- _regenerator["default"].mark(function _callee2(prefObj) {
149
- return _regenerator["default"].wrap(function _callee2$(_context2) {
150
- while (1) {
151
- switch (_context2.prev = _context2.next) {
152
- case 0:
153
- throw new Error('Not implemented: _readFromStorage');
95
+ async _writeToStorage(prefObj) {
96
+ throw new Error("Not implemented: _writeToStorage");
97
+ }
154
98
 
155
- case 1:
156
- case "end":
157
- return _context2.stop();
158
- }
159
- }
160
- }, _callee2);
161
- }));
99
+ async _readFromStorage(prefObj) {
100
+ throw new Error("Not implemented: _readFromStorage");
101
+ }
162
102
 
163
- function _readFromStorage(_x2) {
164
- return _readFromStorage2.apply(this, arguments);
165
- }
103
+ async reset() {
104
+ await this._initializedPromise;
105
+ this.prefs = Object.assign(Object.create(null), this.defaults);
106
+ return this._writeToStorage(this.defaults);
107
+ }
166
108
 
167
- return _readFromStorage;
168
- }()
169
- }, {
170
- key: "reset",
171
- value: function () {
172
- var _reset = _asyncToGenerator(
173
- /*#__PURE__*/
174
- _regenerator["default"].mark(function _callee3() {
175
- return _regenerator["default"].wrap(function _callee3$(_context3) {
176
- while (1) {
177
- switch (_context3.prev = _context3.next) {
178
- case 0:
179
- _context3.next = 2;
180
- return this._initializedPromise;
109
+ async set(name, value) {
110
+ await this._initializedPromise;
111
+ const defaultValue = this.defaults[name];
181
112
 
182
- case 2:
183
- this.prefs = Object.assign(Object.create(null), this.defaults);
184
- return _context3.abrupt("return", this._writeToStorage(this.defaults));
113
+ if (defaultValue === undefined) {
114
+ throw new Error(`Set preference: "${name}" is undefined.`);
115
+ } else if (value === undefined) {
116
+ throw new Error("Set preference: no value is specified.");
117
+ }
185
118
 
186
- case 4:
187
- case "end":
188
- return _context3.stop();
189
- }
190
- }
191
- }, _callee3, this);
192
- }));
119
+ const valueType = typeof value;
120
+ const defaultType = typeof defaultValue;
193
121
 
194
- function reset() {
195
- return _reset.apply(this, arguments);
122
+ if (valueType !== defaultType) {
123
+ if (valueType === "number" && defaultType === "string") {
124
+ value = value.toString();
125
+ } else {
126
+ throw new Error(`Set preference: "${value}" is a ${valueType}, ` + `expected a ${defaultType}.`);
196
127
  }
197
-
198
- return reset;
199
- }()
200
- }, {
201
- key: "set",
202
- value: function () {
203
- var _set = _asyncToGenerator(
204
- /*#__PURE__*/
205
- _regenerator["default"].mark(function _callee4(name, value) {
206
- var defaultValue, valueType, defaultType;
207
- return _regenerator["default"].wrap(function _callee4$(_context4) {
208
- while (1) {
209
- switch (_context4.prev = _context4.next) {
210
- case 0:
211
- _context4.next = 2;
212
- return this._initializedPromise;
213
-
214
- case 2:
215
- defaultValue = this.defaults[name];
216
-
217
- if (!(defaultValue === undefined)) {
218
- _context4.next = 7;
219
- break;
220
- }
221
-
222
- throw new Error("Set preference: \"".concat(name, "\" is undefined."));
223
-
224
- case 7:
225
- if (!(value === undefined)) {
226
- _context4.next = 9;
227
- break;
228
- }
229
-
230
- throw new Error('Set preference: no value is specified.');
231
-
232
- case 9:
233
- valueType = _typeof(value);
234
- defaultType = _typeof(defaultValue);
235
-
236
- if (!(valueType !== defaultType)) {
237
- _context4.next = 19;
238
- break;
239
- }
240
-
241
- if (!(valueType === 'number' && defaultType === 'string')) {
242
- _context4.next = 16;
243
- break;
244
- }
245
-
246
- value = value.toString();
247
- _context4.next = 17;
248
- break;
249
-
250
- case 16:
251
- throw new Error("Set preference: \"".concat(value, "\" is a ").concat(valueType, ", ") + "expected a ".concat(defaultType, "."));
252
-
253
- case 17:
254
- _context4.next = 21;
255
- break;
256
-
257
- case 19:
258
- if (!(valueType === 'number' && !Number.isInteger(value))) {
259
- _context4.next = 21;
260
- break;
261
- }
262
-
263
- throw new Error("Set preference: \"".concat(value, "\" must be an integer."));
264
-
265
- case 21:
266
- this.prefs[name] = value;
267
- return _context4.abrupt("return", this._writeToStorage(this.prefs));
268
-
269
- case 23:
270
- case "end":
271
- return _context4.stop();
272
- }
273
- }
274
- }, _callee4, this);
275
- }));
276
-
277
- function set(_x3, _x4) {
278
- return _set.apply(this, arguments);
128
+ } else {
129
+ if (valueType === "number" && !Number.isInteger(value)) {
130
+ throw new Error(`Set preference: "${value}" must be an integer.`);
279
131
  }
132
+ }
280
133
 
281
- return set;
282
- }()
283
- }, {
284
- key: "get",
285
- value: function () {
286
- var _get = _asyncToGenerator(
287
- /*#__PURE__*/
288
- _regenerator["default"].mark(function _callee5(name) {
289
- var defaultValue, prefValue;
290
- return _regenerator["default"].wrap(function _callee5$(_context5) {
291
- while (1) {
292
- switch (_context5.prev = _context5.next) {
293
- case 0:
294
- _context5.next = 2;
295
- return this._initializedPromise;
296
-
297
- case 2:
298
- defaultValue = this.defaults[name];
299
-
300
- if (!(defaultValue === undefined)) {
301
- _context5.next = 7;
302
- break;
303
- }
304
-
305
- throw new Error("Get preference: \"".concat(name, "\" is undefined."));
306
-
307
- case 7:
308
- prefValue = this.prefs[name];
309
-
310
- if (!(prefValue !== undefined)) {
311
- _context5.next = 10;
312
- break;
313
- }
314
-
315
- return _context5.abrupt("return", prefValue);
134
+ this.prefs[name] = value;
135
+ return this._writeToStorage(this.prefs);
136
+ }
316
137
 
317
- case 10:
318
- return _context5.abrupt("return", defaultValue);
138
+ async get(name) {
139
+ await this._initializedPromise;
140
+ const defaultValue = this.defaults[name];
319
141
 
320
- case 11:
321
- case "end":
322
- return _context5.stop();
323
- }
324
- }
325
- }, _callee5, this);
326
- }));
142
+ if (defaultValue === undefined) {
143
+ throw new Error(`Get preference: "${name}" is undefined.`);
144
+ } else {
145
+ const prefValue = this.prefs[name];
327
146
 
328
- function get(_x5) {
329
- return _get.apply(this, arguments);
147
+ if (prefValue !== undefined) {
148
+ return prefValue;
330
149
  }
150
+ }
331
151
 
332
- return get;
333
- }()
334
- }, {
335
- key: "getAll",
336
- value: function () {
337
- var _getAll = _asyncToGenerator(
338
- /*#__PURE__*/
339
- _regenerator["default"].mark(function _callee6() {
340
- return _regenerator["default"].wrap(function _callee6$(_context6) {
341
- while (1) {
342
- switch (_context6.prev = _context6.next) {
343
- case 0:
344
- _context6.next = 2;
345
- return this._initializedPromise;
346
-
347
- case 2:
348
- return _context6.abrupt("return", Object.assign(Object.create(null), this.defaults, this.prefs));
349
-
350
- case 3:
351
- case "end":
352
- return _context6.stop();
353
- }
354
- }
355
- }, _callee6, this);
356
- }));
357
-
358
- function getAll() {
359
- return _getAll.apply(this, arguments);
360
- }
152
+ return defaultValue;
153
+ }
361
154
 
362
- return getAll;
363
- }()
364
- }]);
155
+ async getAll() {
156
+ await this._initializedPromise;
157
+ return Object.assign(Object.create(null), this.defaults, this.prefs);
158
+ }
365
159
 
366
- return BasePreferences;
367
- }();
160
+ }
368
161
 
369
162
  exports.BasePreferences = BasePreferences;