1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | "use strict";
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
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;
|
46 |
|
47 | function getDefaultPreferences() {
|
48 | if (!defaultPreferences) {
|
49 | defaultPreferences = Promise.resolve({
|
50 | "cursorToolOnLoad": 0,
|
51 | "defaultZoomValue": "",
|
52 | "disablePageLabels": false,
|
53 | "enablePrintAutoRotate": false,
|
54 | "enableWebGL": false,
|
55 | "eventBusDispatchToDOM": false,
|
56 | "externalLinkTarget": 0,
|
57 | "historyUpdateUrl": false,
|
58 | "pdfBugEnabled": false,
|
59 | "renderer": "canvas",
|
60 | "renderInteractiveForms": false,
|
61 | "sidebarViewOnLoad": -1,
|
62 | "scrollModeOnLoad": -1,
|
63 | "spreadModeOnLoad": -1,
|
64 | "textLayerMode": 1,
|
65 | "useOnlyCssZoom": false,
|
66 | "viewOnLoad": 0,
|
67 | "disableAutoFetch": false,
|
68 | "disableFontFace": false,
|
69 | "disableRange": false,
|
70 | "disableStream": false
|
71 | });
|
72 | }
|
73 |
|
74 | return defaultPreferences;
|
75 | }
|
76 |
|
77 | var BasePreferences =
|
78 |
|
79 | function () {
|
80 | function BasePreferences() {
|
81 | var _this = this;
|
82 |
|
83 | _classCallCheck(this, BasePreferences);
|
84 |
|
85 | if (this.constructor === BasePreferences) {
|
86 | throw new Error('Cannot initialize BasePreferences.');
|
87 | }
|
88 |
|
89 | this.prefs = null;
|
90 | this._initializedPromise = getDefaultPreferences().then(function (defaults) {
|
91 | Object.defineProperty(_this, 'defaults', {
|
92 | value: Object.freeze(defaults),
|
93 | writable: false,
|
94 | enumerable: true,
|
95 | configurable: false
|
96 | });
|
97 | _this.prefs = Object.assign(Object.create(null), defaults);
|
98 | return _this._readFromStorage(defaults);
|
99 | }).then(function (prefs) {
|
100 | if (!prefs) {
|
101 | return;
|
102 | }
|
103 |
|
104 | for (var name in prefs) {
|
105 | var defaultValue = _this.defaults[name],
|
106 | prefValue = prefs[name];
|
107 |
|
108 | if (defaultValue === undefined || _typeof(prefValue) !== _typeof(defaultValue)) {
|
109 | continue;
|
110 | }
|
111 |
|
112 | _this.prefs[name] = prefValue;
|
113 | }
|
114 | });
|
115 | }
|
116 |
|
117 | _createClass(BasePreferences, [{
|
118 | key: "_writeToStorage",
|
119 | value: function () {
|
120 | var _writeToStorage2 = _asyncToGenerator(
|
121 |
|
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 |
|
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');
|
154 |
|
155 | case 1:
|
156 | case "end":
|
157 | return _context2.stop();
|
158 | }
|
159 | }
|
160 | }, _callee2);
|
161 | }));
|
162 |
|
163 | function _readFromStorage(_x2) {
|
164 | return _readFromStorage2.apply(this, arguments);
|
165 | }
|
166 |
|
167 | return _readFromStorage;
|
168 | }()
|
169 | }, {
|
170 | key: "reset",
|
171 | value: function () {
|
172 | var _reset = _asyncToGenerator(
|
173 |
|
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;
|
181 |
|
182 | case 2:
|
183 | this.prefs = Object.assign(Object.create(null), this.defaults);
|
184 | return _context3.abrupt("return", this._writeToStorage(this.defaults));
|
185 |
|
186 | case 4:
|
187 | case "end":
|
188 | return _context3.stop();
|
189 | }
|
190 | }
|
191 | }, _callee3, this);
|
192 | }));
|
193 |
|
194 | function reset() {
|
195 | return _reset.apply(this, arguments);
|
196 | }
|
197 |
|
198 | return reset;
|
199 | }()
|
200 | }, {
|
201 | key: "set",
|
202 | value: function () {
|
203 | var _set = _asyncToGenerator(
|
204 |
|
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);
|
279 | }
|
280 |
|
281 | return set;
|
282 | }()
|
283 | }, {
|
284 | key: "get",
|
285 | value: function () {
|
286 | var _get = _asyncToGenerator(
|
287 |
|
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);
|
316 |
|
317 | case 10:
|
318 | return _context5.abrupt("return", defaultValue);
|
319 |
|
320 | case 11:
|
321 | case "end":
|
322 | return _context5.stop();
|
323 | }
|
324 | }
|
325 | }, _callee5, this);
|
326 | }));
|
327 |
|
328 | function get(_x5) {
|
329 | return _get.apply(this, arguments);
|
330 | }
|
331 |
|
332 | return get;
|
333 | }()
|
334 | }, {
|
335 | key: "getAll",
|
336 | value: function () {
|
337 | var _getAll = _asyncToGenerator(
|
338 |
|
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 | }
|
361 |
|
362 | return getAll;
|
363 | }()
|
364 | }]);
|
365 |
|
366 | return BasePreferences;
|
367 | }();
|
368 |
|
369 | exports.BasePreferences = BasePreferences; |
\ | No newline at end of file |