@vertexvis/viewer 0.18.1 → 0.18.2-testing.0
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.
- package/dist/components/_commonjsHelpers.js +41 -0
- package/dist/components/_commonjsHelpers.js.map +1 -0
- package/dist/components/browser.esm.js +3173 -0
- package/dist/components/browser.esm.js.map +1 -0
- package/dist/components/bundle.esm.js +2250 -0
- package/dist/components/bundle.esm.js.map +1 -0
- package/dist/components/bundle.esm2.js +39740 -0
- package/dist/components/bundle.esm2.js.map +1 -0
- package/dist/components/config.js +81 -0
- package/dist/components/config.js.map +1 -0
- package/dist/components/controller.js +7627 -0
- package/dist/components/controller.js.map +1 -0
- package/dist/components/controller2.js +124 -0
- package/dist/components/controller2.js.map +1 -0
- package/dist/components/controller3.js +111 -0
- package/dist/components/controller3.js.map +1 -0
- package/dist/components/cursors.js +110 -0
- package/dist/components/cursors.js.map +1 -0
- package/dist/components/dom.js +43 -0
- package/dist/components/dom.js.map +1 -0
- package/dist/components/dom2.js +10 -0
- package/dist/components/dom2.js.map +1 -0
- package/dist/components/elementRectObserver.js +25 -0
- package/dist/components/elementRectObserver.js.map +1 -0
- package/dist/components/entities.js +179 -0
- package/dist/components/entities.js.map +1 -0
- package/dist/components/errors.js +80 -0
- package/dist/components/errors.js.map +1 -0
- package/dist/components/events.js +11 -0
- package/dist/components/events.js.map +1 -0
- package/dist/components/index.d.ts +26 -0
- package/dist/components/index.js +365 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index2.js +63 -0
- package/dist/components/index2.js.map +1 -0
- package/dist/components/interactions.js +236 -0
- package/dist/components/interactions.js.map +1 -0
- package/dist/components/mapper.js +9811 -0
- package/dist/components/mapper.js.map +1 -0
- package/dist/components/markup.js +33 -0
- package/dist/components/markup.js.map +1 -0
- package/dist/components/model.js +134 -0
- package/dist/components/model.js.map +1 -0
- package/dist/components/model2.js +157 -0
- package/dist/components/model2.js.map +1 -0
- package/dist/components/overlays.js +76 -0
- package/dist/components/overlays.js.map +1 -0
- package/dist/components/png-decoder.js +2405 -0
- package/dist/components/png-decoder.js.map +1 -0
- package/dist/components/regl-component.js +12582 -0
- package/dist/components/regl-component.js.map +1 -0
- package/dist/components/results.js +24 -0
- package/dist/components/results.js.map +1 -0
- package/dist/components/row.js +32 -0
- package/dist/components/row.js.map +1 -0
- package/dist/components/scene-tree-search.js +146 -0
- package/dist/components/scene-tree-search.js.map +1 -0
- package/dist/components/scene-tree-table-layout.js +928 -0
- package/dist/components/scene-tree-table-layout.js.map +1 -0
- package/dist/components/scene-tree-toolbar.js +35 -0
- package/dist/components/scene-tree-toolbar.js.map +1 -0
- package/dist/components/scene.js +1508 -0
- package/dist/components/scene.js.map +1 -0
- package/dist/components/stencil.js +25 -0
- package/dist/components/stencil.js.map +1 -0
- package/dist/components/streamAttributes.js +40833 -0
- package/dist/components/streamAttributes.js.map +1 -0
- package/dist/components/templates.js +36 -0
- package/dist/components/templates.js.map +1 -0
- package/dist/components/tslib.es6.js +125 -0
- package/dist/components/tslib.es6.js.map +1 -0
- package/dist/components/vertex-scene-tree-search.d.ts +11 -0
- package/dist/components/vertex-scene-tree-search.js +11 -0
- package/dist/components/vertex-scene-tree-search.js.map +1 -0
- package/dist/components/vertex-scene-tree-table-cell.d.ts +11 -0
- package/dist/components/vertex-scene-tree-table-cell.js +209 -0
- package/dist/components/vertex-scene-tree-table-cell.js.map +1 -0
- package/dist/components/vertex-scene-tree-table-column.d.ts +11 -0
- package/dist/components/vertex-scene-tree-table-column.js +42 -0
- package/dist/components/vertex-scene-tree-table-column.js.map +1 -0
- package/dist/components/vertex-scene-tree-table-header.d.ts +11 -0
- package/dist/components/vertex-scene-tree-table-header.js +38 -0
- package/dist/components/vertex-scene-tree-table-header.js.map +1 -0
- package/dist/components/vertex-scene-tree-table-layout.d.ts +11 -0
- package/dist/components/vertex-scene-tree-table-layout.js +11 -0
- package/dist/components/vertex-scene-tree-table-layout.js.map +1 -0
- package/dist/components/vertex-scene-tree-table-resize-divider.d.ts +11 -0
- package/dist/components/vertex-scene-tree-table-resize-divider.js +57 -0
- package/dist/components/vertex-scene-tree-table-resize-divider.js.map +1 -0
- package/dist/components/vertex-scene-tree-toolbar-group.d.ts +11 -0
- package/dist/components/vertex-scene-tree-toolbar-group.js +38 -0
- package/dist/components/vertex-scene-tree-toolbar-group.js.map +1 -0
- package/dist/components/vertex-scene-tree-toolbar.d.ts +11 -0
- package/dist/components/vertex-scene-tree-toolbar.js +11 -0
- package/dist/components/vertex-scene-tree-toolbar.js.map +1 -0
- package/dist/components/vertex-scene-tree.d.ts +11 -0
- package/dist/components/vertex-scene-tree.js +803 -0
- package/dist/components/vertex-scene-tree.js.map +1 -0
- package/dist/components/vertex-viewer-box-query-tool.d.ts +11 -0
- package/dist/components/vertex-viewer-box-query-tool.js +352 -0
- package/dist/components/vertex-viewer-box-query-tool.js.map +1 -0
- package/dist/components/vertex-viewer-button.d.ts +11 -0
- package/dist/components/vertex-viewer-button.js +11 -0
- package/dist/components/vertex-viewer-button.js.map +1 -0
- package/dist/components/vertex-viewer-default-toolbar.d.ts +11 -0
- package/dist/components/vertex-viewer-default-toolbar.js +99 -0
- package/dist/components/vertex-viewer-default-toolbar.js.map +1 -0
- package/dist/components/vertex-viewer-dom-element.d.ts +11 -0
- package/dist/components/vertex-viewer-dom-element.js +11 -0
- package/dist/components/vertex-viewer-dom-element.js.map +1 -0
- package/dist/components/vertex-viewer-dom-group.d.ts +11 -0
- package/dist/components/vertex-viewer-dom-group.js +11 -0
- package/dist/components/vertex-viewer-dom-group.js.map +1 -0
- package/dist/components/vertex-viewer-dom-renderer.d.ts +11 -0
- package/dist/components/vertex-viewer-dom-renderer.js +11 -0
- package/dist/components/vertex-viewer-dom-renderer.js.map +1 -0
- package/dist/components/vertex-viewer-hit-result-indicator.d.ts +11 -0
- package/dist/components/vertex-viewer-hit-result-indicator.js +335 -0
- package/dist/components/vertex-viewer-hit-result-indicator.js.map +1 -0
- package/dist/components/vertex-viewer-icon.d.ts +11 -0
- package/dist/components/vertex-viewer-icon.js +11 -0
- package/dist/components/vertex-viewer-icon.js.map +1 -0
- package/dist/components/vertex-viewer-layer.d.ts +11 -0
- package/dist/components/vertex-viewer-layer.js +11 -0
- package/dist/components/vertex-viewer-layer.js.map +1 -0
- package/dist/components/vertex-viewer-markup-arrow.d.ts +11 -0
- package/dist/components/vertex-viewer-markup-arrow.js +11 -0
- package/dist/components/vertex-viewer-markup-arrow.js.map +1 -0
- package/dist/components/vertex-viewer-markup-circle.d.ts +11 -0
- package/dist/components/vertex-viewer-markup-circle.js +11 -0
- package/dist/components/vertex-viewer-markup-circle.js.map +1 -0
- package/dist/components/vertex-viewer-markup-freeform.d.ts +11 -0
- package/dist/components/vertex-viewer-markup-freeform.js +11 -0
- package/dist/components/vertex-viewer-markup-freeform.js.map +1 -0
- package/dist/components/vertex-viewer-markup-tool.d.ts +11 -0
- package/dist/components/vertex-viewer-markup-tool.js +257 -0
- package/dist/components/vertex-viewer-markup-tool.js.map +1 -0
- package/dist/components/vertex-viewer-markup.d.ts +11 -0
- package/dist/components/vertex-viewer-markup.js +362 -0
- package/dist/components/vertex-viewer-markup.js.map +1 -0
- package/dist/components/vertex-viewer-measurement-details.d.ts +11 -0
- package/dist/components/vertex-viewer-measurement-details.js +307 -0
- package/dist/components/vertex-viewer-measurement-details.js.map +1 -0
- package/dist/components/vertex-viewer-measurement-distance.d.ts +11 -0
- package/dist/components/vertex-viewer-measurement-distance.js +1067 -0
- package/dist/components/vertex-viewer-measurement-distance.js.map +1 -0
- package/dist/components/vertex-viewer-measurement-line.d.ts +11 -0
- package/dist/components/vertex-viewer-measurement-line.js +11 -0
- package/dist/components/vertex-viewer-measurement-line.js.map +1 -0
- package/dist/components/vertex-viewer-measurement-overlays.d.ts +11 -0
- package/dist/components/vertex-viewer-measurement-overlays.js +11 -0
- package/dist/components/vertex-viewer-measurement-overlays.js.map +1 -0
- package/dist/components/vertex-viewer-measurement-precise.d.ts +11 -0
- package/dist/components/vertex-viewer-measurement-precise.js +362 -0
- package/dist/components/vertex-viewer-measurement-precise.js.map +1 -0
- package/dist/components/vertex-viewer-pin-group.d.ts +11 -0
- package/dist/components/vertex-viewer-pin-group.js +11 -0
- package/dist/components/vertex-viewer-pin-group.js.map +1 -0
- package/dist/components/vertex-viewer-pin-label-line.d.ts +11 -0
- package/dist/components/vertex-viewer-pin-label-line.js +11 -0
- package/dist/components/vertex-viewer-pin-label-line.js.map +1 -0
- package/dist/components/vertex-viewer-pin-label.d.ts +11 -0
- package/dist/components/vertex-viewer-pin-label.js +11 -0
- package/dist/components/vertex-viewer-pin-label.js.map +1 -0
- package/dist/components/vertex-viewer-pin-tool.d.ts +11 -0
- package/dist/components/vertex-viewer-pin-tool.js +430 -0
- package/dist/components/vertex-viewer-pin-tool.js.map +1 -0
- package/dist/components/vertex-viewer-spinner.d.ts +11 -0
- package/dist/components/vertex-viewer-spinner.js +11 -0
- package/dist/components/vertex-viewer-spinner.js.map +1 -0
- package/dist/components/vertex-viewer-toolbar-group.d.ts +11 -0
- package/dist/components/vertex-viewer-toolbar-group.js +11 -0
- package/dist/components/vertex-viewer-toolbar-group.js.map +1 -0
- package/dist/components/vertex-viewer-toolbar.d.ts +11 -0
- package/dist/components/vertex-viewer-toolbar.js +11 -0
- package/dist/components/vertex-viewer-toolbar.js.map +1 -0
- package/dist/components/vertex-viewer-transform-widget.d.ts +11 -0
- package/dist/components/vertex-viewer-transform-widget.js +838 -0
- package/dist/components/vertex-viewer-transform-widget.js.map +1 -0
- package/dist/components/vertex-viewer-view-cube.d.ts +11 -0
- package/dist/components/vertex-viewer-view-cube.js +270 -0
- package/dist/components/vertex-viewer-view-cube.js.map +1 -0
- package/dist/components/vertex-viewer.d.ts +11 -0
- package/dist/components/vertex-viewer.js +3543 -0
- package/dist/components/vertex-viewer.js.map +1 -0
- package/dist/components/viewer-button.js +35 -0
- package/dist/components/viewer-button.js.map +1 -0
- package/dist/components/viewer-dom-element.js +250 -0
- package/dist/components/viewer-dom-element.js.map +1 -0
- package/dist/components/viewer-dom-group.js +214 -0
- package/dist/components/viewer-dom-group.js.map +1 -0
- package/dist/components/viewer-dom-renderer.js +295 -0
- package/dist/components/viewer-dom-renderer.js.map +1 -0
- package/dist/components/viewer-icon.js +87 -0
- package/dist/components/viewer-icon.js.map +1 -0
- package/dist/components/viewer-layer.js +46 -0
- package/dist/components/viewer-layer.js.map +1 -0
- package/dist/components/viewer-markup-arrow.js +235 -0
- package/dist/components/viewer-markup-arrow.js.map +1 -0
- package/dist/components/viewer-markup-circle-components.js +42 -0
- package/dist/components/viewer-markup-circle-components.js.map +1 -0
- package/dist/components/viewer-markup-circle.js +201 -0
- package/dist/components/viewer-markup-circle.js.map +1 -0
- package/dist/components/viewer-markup-freeform.js +251 -0
- package/dist/components/viewer-markup-freeform.js.map +1 -0
- package/dist/components/viewer-measurement-line.js +77 -0
- package/dist/components/viewer-measurement-line.js.map +1 -0
- package/dist/components/viewer-measurement-overlays.js +184 -0
- package/dist/components/viewer-measurement-overlays.js.map +1 -0
- package/dist/components/viewer-pin-group.js +207 -0
- package/dist/components/viewer-pin-group.js.map +1 -0
- package/dist/components/viewer-pin-label-line.js +43 -0
- package/dist/components/viewer-pin-label-line.js.map +1 -0
- package/dist/components/viewer-pin-label.js +427 -0
- package/dist/components/viewer-pin-label.js.map +1 -0
- package/dist/components/viewer-spinner.js +53 -0
- package/dist/components/viewer-spinner.js.map +1 -0
- package/dist/components/viewer-toolbar-group.js +42 -0
- package/dist/components/viewer-toolbar-group.js.map +1 -0
- package/dist/components/viewer-toolbar.js +61 -0
- package/dist/components/viewer-toolbar.js.map +1 -0
- package/dist/components/viewport.js +188 -0
- package/dist/components/viewport.js.map +1 -0
- package/dist/components/wrappers_pb.js +1926 -0
- package/dist/components/wrappers_pb.js.map +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,2405 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 Vertex Software LLC. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { d as __awaiter$2, e as __generator, b as __spreadArray } from './tslib.es6.js';
|
|
5
|
+
import { c as createCommonjsModule } from './_commonjsHelpers.js';
|
|
6
|
+
|
|
7
|
+
const DefaultErrorSerializer = {
|
|
8
|
+
deserialize(message) {
|
|
9
|
+
return Object.assign(Error(message.message), {
|
|
10
|
+
name: message.name,
|
|
11
|
+
stack: message.stack
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
serialize(error) {
|
|
15
|
+
return {
|
|
16
|
+
__error_marker: "$$error",
|
|
17
|
+
message: error.message,
|
|
18
|
+
name: error.name,
|
|
19
|
+
stack: error.stack
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const isSerializedError = (thing) => thing && typeof thing === "object" && "__error_marker" in thing && thing.__error_marker === "$$error";
|
|
24
|
+
const DefaultSerializer = {
|
|
25
|
+
deserialize(message) {
|
|
26
|
+
if (isSerializedError(message)) {
|
|
27
|
+
return DefaultErrorSerializer.deserialize(message);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return message;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
serialize(input) {
|
|
34
|
+
if (input instanceof Error) {
|
|
35
|
+
return DefaultErrorSerializer.serialize(input);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return input;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
let registeredSerializer = DefaultSerializer;
|
|
44
|
+
function deserialize(message) {
|
|
45
|
+
return registeredSerializer.deserialize(message);
|
|
46
|
+
}
|
|
47
|
+
function serialize(input) {
|
|
48
|
+
return registeredSerializer.serialize(input);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Source: <https://github.com/parcel-bundler/parcel/blob/master/packages/core/parcel-bundler/src/builtins/bundle-url.js>
|
|
52
|
+
let bundleURL;
|
|
53
|
+
function getBundleURLCached() {
|
|
54
|
+
if (!bundleURL) {
|
|
55
|
+
bundleURL = getBundleURL();
|
|
56
|
+
}
|
|
57
|
+
return bundleURL;
|
|
58
|
+
}
|
|
59
|
+
function getBundleURL() {
|
|
60
|
+
// Attempt to find the URL of the current script and use that as the base URL
|
|
61
|
+
try {
|
|
62
|
+
throw new Error;
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
const matches = ("" + err.stack).match(/(https?|file|ftp|chrome-extension|moz-extension):\/\/[^)\n]+/g);
|
|
66
|
+
if (matches) {
|
|
67
|
+
return getBaseURL(matches[0]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return "/";
|
|
71
|
+
}
|
|
72
|
+
function getBaseURL(url) {
|
|
73
|
+
return ("" + url).replace(/^((?:https?|file|ftp|chrome-extension|moz-extension):\/\/.+)?\/[^/]+(?:\?.*)?$/, '$1') + '/';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// tslint:disable max-classes-per-file
|
|
77
|
+
const defaultPoolSize = typeof navigator !== "undefined" && navigator.hardwareConcurrency
|
|
78
|
+
? navigator.hardwareConcurrency
|
|
79
|
+
: 4;
|
|
80
|
+
const isAbsoluteURL = (value) => /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(value);
|
|
81
|
+
function createSourceBlobURL(code) {
|
|
82
|
+
const blob = new Blob([code], { type: "application/javascript" });
|
|
83
|
+
return URL.createObjectURL(blob);
|
|
84
|
+
}
|
|
85
|
+
function selectWorkerImplementation() {
|
|
86
|
+
if (typeof Worker === "undefined") {
|
|
87
|
+
// Might happen on Safari, for instance
|
|
88
|
+
// The idea is to only fail if the constructor is actually used
|
|
89
|
+
return class NoWebWorker {
|
|
90
|
+
constructor() {
|
|
91
|
+
throw Error("No web worker implementation available. You might have tried to spawn a worker within a worker in a browser that doesn't support workers in workers.");
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
class WebWorker extends Worker {
|
|
96
|
+
constructor(url, options) {
|
|
97
|
+
var _a, _b;
|
|
98
|
+
if (typeof url === "string" && options && options._baseURL) {
|
|
99
|
+
url = new URL(url, options._baseURL);
|
|
100
|
+
}
|
|
101
|
+
else if (typeof url === "string" && !isAbsoluteURL(url) && getBundleURLCached().match(/^file:\/\//i)) {
|
|
102
|
+
url = new URL(url, getBundleURLCached().replace(/\/[^\/]+$/, "/"));
|
|
103
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.CORSWorkaround) !== null && _a !== void 0 ? _a : true) {
|
|
104
|
+
url = createSourceBlobURL(`importScripts(${JSON.stringify(url)});`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (typeof url === "string" && isAbsoluteURL(url)) {
|
|
108
|
+
// Create source code blob loading JS file via `importScripts()`
|
|
109
|
+
// to circumvent worker CORS restrictions
|
|
110
|
+
if ((_b = options === null || options === void 0 ? void 0 : options.CORSWorkaround) !== null && _b !== void 0 ? _b : true) {
|
|
111
|
+
url = createSourceBlobURL(`importScripts(${JSON.stringify(url)});`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
super(url, options);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
class BlobWorker extends WebWorker {
|
|
118
|
+
constructor(blob, options) {
|
|
119
|
+
const url = window.URL.createObjectURL(blob);
|
|
120
|
+
super(url, options);
|
|
121
|
+
}
|
|
122
|
+
static fromText(source, options) {
|
|
123
|
+
const blob = new window.Blob([source], { type: "text/javascript" });
|
|
124
|
+
return new BlobWorker(blob, options);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
blob: BlobWorker,
|
|
129
|
+
default: WebWorker
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
let implementation;
|
|
133
|
+
function getWorkerImplementation() {
|
|
134
|
+
if (!implementation) {
|
|
135
|
+
implementation = selectWorkerImplementation();
|
|
136
|
+
}
|
|
137
|
+
return implementation;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Helpers.
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
var s = 1000;
|
|
145
|
+
var m = s * 60;
|
|
146
|
+
var h = m * 60;
|
|
147
|
+
var d = h * 24;
|
|
148
|
+
var w = d * 7;
|
|
149
|
+
var y = d * 365.25;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Parse or format the given `val`.
|
|
153
|
+
*
|
|
154
|
+
* Options:
|
|
155
|
+
*
|
|
156
|
+
* - `long` verbose formatting [false]
|
|
157
|
+
*
|
|
158
|
+
* @param {String|Number} val
|
|
159
|
+
* @param {Object} [options]
|
|
160
|
+
* @throws {Error} throw an error if val is not a non-empty string or a number
|
|
161
|
+
* @return {String|Number}
|
|
162
|
+
* @api public
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
var ms = function(val, options) {
|
|
166
|
+
options = options || {};
|
|
167
|
+
var type = typeof val;
|
|
168
|
+
if (type === 'string' && val.length > 0) {
|
|
169
|
+
return parse(val);
|
|
170
|
+
} else if (type === 'number' && isFinite(val)) {
|
|
171
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
|
172
|
+
}
|
|
173
|
+
throw new Error(
|
|
174
|
+
'val is not a non-empty string or a valid number. val=' +
|
|
175
|
+
JSON.stringify(val)
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Parse the given `str` and return milliseconds.
|
|
181
|
+
*
|
|
182
|
+
* @param {String} str
|
|
183
|
+
* @return {Number}
|
|
184
|
+
* @api private
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
function parse(str) {
|
|
188
|
+
str = String(str);
|
|
189
|
+
if (str.length > 100) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
193
|
+
str
|
|
194
|
+
);
|
|
195
|
+
if (!match) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
var n = parseFloat(match[1]);
|
|
199
|
+
var type = (match[2] || 'ms').toLowerCase();
|
|
200
|
+
switch (type) {
|
|
201
|
+
case 'years':
|
|
202
|
+
case 'year':
|
|
203
|
+
case 'yrs':
|
|
204
|
+
case 'yr':
|
|
205
|
+
case 'y':
|
|
206
|
+
return n * y;
|
|
207
|
+
case 'weeks':
|
|
208
|
+
case 'week':
|
|
209
|
+
case 'w':
|
|
210
|
+
return n * w;
|
|
211
|
+
case 'days':
|
|
212
|
+
case 'day':
|
|
213
|
+
case 'd':
|
|
214
|
+
return n * d;
|
|
215
|
+
case 'hours':
|
|
216
|
+
case 'hour':
|
|
217
|
+
case 'hrs':
|
|
218
|
+
case 'hr':
|
|
219
|
+
case 'h':
|
|
220
|
+
return n * h;
|
|
221
|
+
case 'minutes':
|
|
222
|
+
case 'minute':
|
|
223
|
+
case 'mins':
|
|
224
|
+
case 'min':
|
|
225
|
+
case 'm':
|
|
226
|
+
return n * m;
|
|
227
|
+
case 'seconds':
|
|
228
|
+
case 'second':
|
|
229
|
+
case 'secs':
|
|
230
|
+
case 'sec':
|
|
231
|
+
case 's':
|
|
232
|
+
return n * s;
|
|
233
|
+
case 'milliseconds':
|
|
234
|
+
case 'millisecond':
|
|
235
|
+
case 'msecs':
|
|
236
|
+
case 'msec':
|
|
237
|
+
case 'ms':
|
|
238
|
+
return n;
|
|
239
|
+
default:
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Short format for `ms`.
|
|
246
|
+
*
|
|
247
|
+
* @param {Number} ms
|
|
248
|
+
* @return {String}
|
|
249
|
+
* @api private
|
|
250
|
+
*/
|
|
251
|
+
|
|
252
|
+
function fmtShort(ms) {
|
|
253
|
+
var msAbs = Math.abs(ms);
|
|
254
|
+
if (msAbs >= d) {
|
|
255
|
+
return Math.round(ms / d) + 'd';
|
|
256
|
+
}
|
|
257
|
+
if (msAbs >= h) {
|
|
258
|
+
return Math.round(ms / h) + 'h';
|
|
259
|
+
}
|
|
260
|
+
if (msAbs >= m) {
|
|
261
|
+
return Math.round(ms / m) + 'm';
|
|
262
|
+
}
|
|
263
|
+
if (msAbs >= s) {
|
|
264
|
+
return Math.round(ms / s) + 's';
|
|
265
|
+
}
|
|
266
|
+
return ms + 'ms';
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Long format for `ms`.
|
|
271
|
+
*
|
|
272
|
+
* @param {Number} ms
|
|
273
|
+
* @return {String}
|
|
274
|
+
* @api private
|
|
275
|
+
*/
|
|
276
|
+
|
|
277
|
+
function fmtLong(ms) {
|
|
278
|
+
var msAbs = Math.abs(ms);
|
|
279
|
+
if (msAbs >= d) {
|
|
280
|
+
return plural(ms, msAbs, d, 'day');
|
|
281
|
+
}
|
|
282
|
+
if (msAbs >= h) {
|
|
283
|
+
return plural(ms, msAbs, h, 'hour');
|
|
284
|
+
}
|
|
285
|
+
if (msAbs >= m) {
|
|
286
|
+
return plural(ms, msAbs, m, 'minute');
|
|
287
|
+
}
|
|
288
|
+
if (msAbs >= s) {
|
|
289
|
+
return plural(ms, msAbs, s, 'second');
|
|
290
|
+
}
|
|
291
|
+
return ms + ' ms';
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Pluralization helper.
|
|
296
|
+
*/
|
|
297
|
+
|
|
298
|
+
function plural(ms, msAbs, n, name) {
|
|
299
|
+
var isPlural = msAbs >= n * 1.5;
|
|
300
|
+
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* This is the common logic for both the Node.js and web browser
|
|
305
|
+
* implementations of `debug()`.
|
|
306
|
+
*/
|
|
307
|
+
|
|
308
|
+
function setup(env) {
|
|
309
|
+
createDebug.debug = createDebug;
|
|
310
|
+
createDebug.default = createDebug;
|
|
311
|
+
createDebug.coerce = coerce;
|
|
312
|
+
createDebug.disable = disable;
|
|
313
|
+
createDebug.enable = enable;
|
|
314
|
+
createDebug.enabled = enabled;
|
|
315
|
+
createDebug.humanize = ms;
|
|
316
|
+
createDebug.destroy = destroy;
|
|
317
|
+
|
|
318
|
+
Object.keys(env).forEach(key => {
|
|
319
|
+
createDebug[key] = env[key];
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* The currently active debug mode names, and names to skip.
|
|
324
|
+
*/
|
|
325
|
+
|
|
326
|
+
createDebug.names = [];
|
|
327
|
+
createDebug.skips = [];
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Map of special "%n" handling functions, for the debug "format" argument.
|
|
331
|
+
*
|
|
332
|
+
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
|
333
|
+
*/
|
|
334
|
+
createDebug.formatters = {};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Selects a color for a debug namespace
|
|
338
|
+
* @param {String} namespace The namespace string for the for the debug instance to be colored
|
|
339
|
+
* @return {Number|String} An ANSI color code for the given namespace
|
|
340
|
+
* @api private
|
|
341
|
+
*/
|
|
342
|
+
function selectColor(namespace) {
|
|
343
|
+
let hash = 0;
|
|
344
|
+
|
|
345
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
346
|
+
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
|
347
|
+
hash |= 0; // Convert to 32bit integer
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
351
|
+
}
|
|
352
|
+
createDebug.selectColor = selectColor;
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Create a debugger with the given `namespace`.
|
|
356
|
+
*
|
|
357
|
+
* @param {String} namespace
|
|
358
|
+
* @return {Function}
|
|
359
|
+
* @api public
|
|
360
|
+
*/
|
|
361
|
+
function createDebug(namespace) {
|
|
362
|
+
let prevTime;
|
|
363
|
+
let enableOverride = null;
|
|
364
|
+
let namespacesCache;
|
|
365
|
+
let enabledCache;
|
|
366
|
+
|
|
367
|
+
function debug(...args) {
|
|
368
|
+
// Disabled?
|
|
369
|
+
if (!debug.enabled) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const self = debug;
|
|
374
|
+
|
|
375
|
+
// Set `diff` timestamp
|
|
376
|
+
const curr = Number(new Date());
|
|
377
|
+
const ms = curr - (prevTime || curr);
|
|
378
|
+
self.diff = ms;
|
|
379
|
+
self.prev = prevTime;
|
|
380
|
+
self.curr = curr;
|
|
381
|
+
prevTime = curr;
|
|
382
|
+
|
|
383
|
+
args[0] = createDebug.coerce(args[0]);
|
|
384
|
+
|
|
385
|
+
if (typeof args[0] !== 'string') {
|
|
386
|
+
// Anything else let's inspect with %O
|
|
387
|
+
args.unshift('%O');
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Apply any `formatters` transformations
|
|
391
|
+
let index = 0;
|
|
392
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
393
|
+
// If we encounter an escaped % then don't increase the array index
|
|
394
|
+
if (match === '%%') {
|
|
395
|
+
return '%';
|
|
396
|
+
}
|
|
397
|
+
index++;
|
|
398
|
+
const formatter = createDebug.formatters[format];
|
|
399
|
+
if (typeof formatter === 'function') {
|
|
400
|
+
const val = args[index];
|
|
401
|
+
match = formatter.call(self, val);
|
|
402
|
+
|
|
403
|
+
// Now we need to remove `args[index]` since it's inlined in the `format`
|
|
404
|
+
args.splice(index, 1);
|
|
405
|
+
index--;
|
|
406
|
+
}
|
|
407
|
+
return match;
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
// Apply env-specific formatting (colors, etc.)
|
|
411
|
+
createDebug.formatArgs.call(self, args);
|
|
412
|
+
|
|
413
|
+
const logFn = self.log || createDebug.log;
|
|
414
|
+
logFn.apply(self, args);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
debug.namespace = namespace;
|
|
418
|
+
debug.useColors = createDebug.useColors();
|
|
419
|
+
debug.color = createDebug.selectColor(namespace);
|
|
420
|
+
debug.extend = extend;
|
|
421
|
+
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
|
422
|
+
|
|
423
|
+
Object.defineProperty(debug, 'enabled', {
|
|
424
|
+
enumerable: true,
|
|
425
|
+
configurable: false,
|
|
426
|
+
get: () => {
|
|
427
|
+
if (enableOverride !== null) {
|
|
428
|
+
return enableOverride;
|
|
429
|
+
}
|
|
430
|
+
if (namespacesCache !== createDebug.namespaces) {
|
|
431
|
+
namespacesCache = createDebug.namespaces;
|
|
432
|
+
enabledCache = createDebug.enabled(namespace);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return enabledCache;
|
|
436
|
+
},
|
|
437
|
+
set: v => {
|
|
438
|
+
enableOverride = v;
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
// Env-specific initialization logic for debug instances
|
|
443
|
+
if (typeof createDebug.init === 'function') {
|
|
444
|
+
createDebug.init(debug);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return debug;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function extend(namespace, delimiter) {
|
|
451
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
|
452
|
+
newDebug.log = this.log;
|
|
453
|
+
return newDebug;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Enables a debug mode by namespaces. This can include modes
|
|
458
|
+
* separated by a colon and wildcards.
|
|
459
|
+
*
|
|
460
|
+
* @param {String} namespaces
|
|
461
|
+
* @api public
|
|
462
|
+
*/
|
|
463
|
+
function enable(namespaces) {
|
|
464
|
+
createDebug.save(namespaces);
|
|
465
|
+
createDebug.namespaces = namespaces;
|
|
466
|
+
|
|
467
|
+
createDebug.names = [];
|
|
468
|
+
createDebug.skips = [];
|
|
469
|
+
|
|
470
|
+
let i;
|
|
471
|
+
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
|
472
|
+
const len = split.length;
|
|
473
|
+
|
|
474
|
+
for (i = 0; i < len; i++) {
|
|
475
|
+
if (!split[i]) {
|
|
476
|
+
// ignore empty strings
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
namespaces = split[i].replace(/\*/g, '.*?');
|
|
481
|
+
|
|
482
|
+
if (namespaces[0] === '-') {
|
|
483
|
+
createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
|
484
|
+
} else {
|
|
485
|
+
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Disable debug output.
|
|
492
|
+
*
|
|
493
|
+
* @return {String} namespaces
|
|
494
|
+
* @api public
|
|
495
|
+
*/
|
|
496
|
+
function disable() {
|
|
497
|
+
const namespaces = [
|
|
498
|
+
...createDebug.names.map(toNamespace),
|
|
499
|
+
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
|
500
|
+
].join(',');
|
|
501
|
+
createDebug.enable('');
|
|
502
|
+
return namespaces;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Returns true if the given mode name is enabled, false otherwise.
|
|
507
|
+
*
|
|
508
|
+
* @param {String} name
|
|
509
|
+
* @return {Boolean}
|
|
510
|
+
* @api public
|
|
511
|
+
*/
|
|
512
|
+
function enabled(name) {
|
|
513
|
+
if (name[name.length - 1] === '*') {
|
|
514
|
+
return true;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
let i;
|
|
518
|
+
let len;
|
|
519
|
+
|
|
520
|
+
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
|
521
|
+
if (createDebug.skips[i].test(name)) {
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
|
527
|
+
if (createDebug.names[i].test(name)) {
|
|
528
|
+
return true;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Convert regexp to namespace
|
|
537
|
+
*
|
|
538
|
+
* @param {RegExp} regxep
|
|
539
|
+
* @return {String} namespace
|
|
540
|
+
* @api private
|
|
541
|
+
*/
|
|
542
|
+
function toNamespace(regexp) {
|
|
543
|
+
return regexp.toString()
|
|
544
|
+
.substring(2, regexp.toString().length - 2)
|
|
545
|
+
.replace(/\.\*\?$/, '*');
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Coerce `val`.
|
|
550
|
+
*
|
|
551
|
+
* @param {Mixed} val
|
|
552
|
+
* @return {Mixed}
|
|
553
|
+
* @api private
|
|
554
|
+
*/
|
|
555
|
+
function coerce(val) {
|
|
556
|
+
if (val instanceof Error) {
|
|
557
|
+
return val.stack || val.message;
|
|
558
|
+
}
|
|
559
|
+
return val;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* XXX DO NOT USE. This is a temporary stub function.
|
|
564
|
+
* XXX It WILL be removed in the next major release.
|
|
565
|
+
*/
|
|
566
|
+
function destroy() {
|
|
567
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
createDebug.enable(createDebug.load());
|
|
571
|
+
|
|
572
|
+
return createDebug;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
var common = setup;
|
|
576
|
+
|
|
577
|
+
var browser = createCommonjsModule(function (module, exports) {
|
|
578
|
+
/* eslint-env browser */
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* This is the web browser implementation of `debug()`.
|
|
582
|
+
*/
|
|
583
|
+
|
|
584
|
+
exports.formatArgs = formatArgs;
|
|
585
|
+
exports.save = save;
|
|
586
|
+
exports.load = load;
|
|
587
|
+
exports.useColors = useColors;
|
|
588
|
+
exports.storage = localstorage();
|
|
589
|
+
exports.destroy = (() => {
|
|
590
|
+
let warned = false;
|
|
591
|
+
|
|
592
|
+
return () => {
|
|
593
|
+
if (!warned) {
|
|
594
|
+
warned = true;
|
|
595
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
})();
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Colors.
|
|
602
|
+
*/
|
|
603
|
+
|
|
604
|
+
exports.colors = [
|
|
605
|
+
'#0000CC',
|
|
606
|
+
'#0000FF',
|
|
607
|
+
'#0033CC',
|
|
608
|
+
'#0033FF',
|
|
609
|
+
'#0066CC',
|
|
610
|
+
'#0066FF',
|
|
611
|
+
'#0099CC',
|
|
612
|
+
'#0099FF',
|
|
613
|
+
'#00CC00',
|
|
614
|
+
'#00CC33',
|
|
615
|
+
'#00CC66',
|
|
616
|
+
'#00CC99',
|
|
617
|
+
'#00CCCC',
|
|
618
|
+
'#00CCFF',
|
|
619
|
+
'#3300CC',
|
|
620
|
+
'#3300FF',
|
|
621
|
+
'#3333CC',
|
|
622
|
+
'#3333FF',
|
|
623
|
+
'#3366CC',
|
|
624
|
+
'#3366FF',
|
|
625
|
+
'#3399CC',
|
|
626
|
+
'#3399FF',
|
|
627
|
+
'#33CC00',
|
|
628
|
+
'#33CC33',
|
|
629
|
+
'#33CC66',
|
|
630
|
+
'#33CC99',
|
|
631
|
+
'#33CCCC',
|
|
632
|
+
'#33CCFF',
|
|
633
|
+
'#6600CC',
|
|
634
|
+
'#6600FF',
|
|
635
|
+
'#6633CC',
|
|
636
|
+
'#6633FF',
|
|
637
|
+
'#66CC00',
|
|
638
|
+
'#66CC33',
|
|
639
|
+
'#9900CC',
|
|
640
|
+
'#9900FF',
|
|
641
|
+
'#9933CC',
|
|
642
|
+
'#9933FF',
|
|
643
|
+
'#99CC00',
|
|
644
|
+
'#99CC33',
|
|
645
|
+
'#CC0000',
|
|
646
|
+
'#CC0033',
|
|
647
|
+
'#CC0066',
|
|
648
|
+
'#CC0099',
|
|
649
|
+
'#CC00CC',
|
|
650
|
+
'#CC00FF',
|
|
651
|
+
'#CC3300',
|
|
652
|
+
'#CC3333',
|
|
653
|
+
'#CC3366',
|
|
654
|
+
'#CC3399',
|
|
655
|
+
'#CC33CC',
|
|
656
|
+
'#CC33FF',
|
|
657
|
+
'#CC6600',
|
|
658
|
+
'#CC6633',
|
|
659
|
+
'#CC9900',
|
|
660
|
+
'#CC9933',
|
|
661
|
+
'#CCCC00',
|
|
662
|
+
'#CCCC33',
|
|
663
|
+
'#FF0000',
|
|
664
|
+
'#FF0033',
|
|
665
|
+
'#FF0066',
|
|
666
|
+
'#FF0099',
|
|
667
|
+
'#FF00CC',
|
|
668
|
+
'#FF00FF',
|
|
669
|
+
'#FF3300',
|
|
670
|
+
'#FF3333',
|
|
671
|
+
'#FF3366',
|
|
672
|
+
'#FF3399',
|
|
673
|
+
'#FF33CC',
|
|
674
|
+
'#FF33FF',
|
|
675
|
+
'#FF6600',
|
|
676
|
+
'#FF6633',
|
|
677
|
+
'#FF9900',
|
|
678
|
+
'#FF9933',
|
|
679
|
+
'#FFCC00',
|
|
680
|
+
'#FFCC33'
|
|
681
|
+
];
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
|
685
|
+
* and the Firebug extension (any Firefox version) are known
|
|
686
|
+
* to support "%c" CSS customizations.
|
|
687
|
+
*
|
|
688
|
+
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
|
689
|
+
*/
|
|
690
|
+
|
|
691
|
+
// eslint-disable-next-line complexity
|
|
692
|
+
function useColors() {
|
|
693
|
+
// NB: In an Electron preload script, document will be defined but not fully
|
|
694
|
+
// initialized. Since we know we're in Chrome, we'll just detect this case
|
|
695
|
+
// explicitly
|
|
696
|
+
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
|
697
|
+
return true;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// Internet Explorer and Edge do not support colors.
|
|
701
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
|
706
|
+
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
|
707
|
+
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
|
708
|
+
// Is firebug? http://stackoverflow.com/a/398120/376773
|
|
709
|
+
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
|
710
|
+
// Is firefox >= v31?
|
|
711
|
+
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
712
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
|
713
|
+
// Double check webkit in userAgent just in case we are in a worker
|
|
714
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Colorize log arguments if enabled.
|
|
719
|
+
*
|
|
720
|
+
* @api public
|
|
721
|
+
*/
|
|
722
|
+
|
|
723
|
+
function formatArgs(args) {
|
|
724
|
+
args[0] = (this.useColors ? '%c' : '') +
|
|
725
|
+
this.namespace +
|
|
726
|
+
(this.useColors ? ' %c' : ' ') +
|
|
727
|
+
args[0] +
|
|
728
|
+
(this.useColors ? '%c ' : ' ') +
|
|
729
|
+
'+' + module.exports.humanize(this.diff);
|
|
730
|
+
|
|
731
|
+
if (!this.useColors) {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
const c = 'color: ' + this.color;
|
|
736
|
+
args.splice(1, 0, c, 'color: inherit');
|
|
737
|
+
|
|
738
|
+
// The final "%c" is somewhat tricky, because there could be other
|
|
739
|
+
// arguments passed either before or after the %c, so we need to
|
|
740
|
+
// figure out the correct index to insert the CSS into
|
|
741
|
+
let index = 0;
|
|
742
|
+
let lastC = 0;
|
|
743
|
+
args[0].replace(/%[a-zA-Z%]/g, match => {
|
|
744
|
+
if (match === '%%') {
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
index++;
|
|
748
|
+
if (match === '%c') {
|
|
749
|
+
// We only are interested in the *last* %c
|
|
750
|
+
// (the user may have provided their own)
|
|
751
|
+
lastC = index;
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
args.splice(lastC, 0, c);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Invokes `console.debug()` when available.
|
|
760
|
+
* No-op when `console.debug` is not a "function".
|
|
761
|
+
* If `console.debug` is not available, falls back
|
|
762
|
+
* to `console.log`.
|
|
763
|
+
*
|
|
764
|
+
* @api public
|
|
765
|
+
*/
|
|
766
|
+
exports.log = console.debug || console.log || (() => {});
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* Save `namespaces`.
|
|
770
|
+
*
|
|
771
|
+
* @param {String} namespaces
|
|
772
|
+
* @api private
|
|
773
|
+
*/
|
|
774
|
+
function save(namespaces) {
|
|
775
|
+
try {
|
|
776
|
+
if (namespaces) {
|
|
777
|
+
exports.storage.setItem('debug', namespaces);
|
|
778
|
+
} else {
|
|
779
|
+
exports.storage.removeItem('debug');
|
|
780
|
+
}
|
|
781
|
+
} catch (error) {
|
|
782
|
+
// Swallow
|
|
783
|
+
// XXX (@Qix-) should we be logging these?
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Load `namespaces`.
|
|
789
|
+
*
|
|
790
|
+
* @return {String} returns the previously persisted debug modes
|
|
791
|
+
* @api private
|
|
792
|
+
*/
|
|
793
|
+
function load() {
|
|
794
|
+
let r;
|
|
795
|
+
try {
|
|
796
|
+
r = exports.storage.getItem('debug');
|
|
797
|
+
} catch (error) {
|
|
798
|
+
// Swallow
|
|
799
|
+
// XXX (@Qix-) should we be logging these?
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
|
803
|
+
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
|
804
|
+
r = process.env.DEBUG;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
return r;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Localstorage attempts to return the localstorage.
|
|
812
|
+
*
|
|
813
|
+
* This is necessary because safari throws
|
|
814
|
+
* when a user disables cookies/localstorage
|
|
815
|
+
* and you attempt to access it.
|
|
816
|
+
*
|
|
817
|
+
* @return {LocalStorage}
|
|
818
|
+
* @api private
|
|
819
|
+
*/
|
|
820
|
+
|
|
821
|
+
function localstorage() {
|
|
822
|
+
try {
|
|
823
|
+
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
|
824
|
+
// The Browser also has localStorage in the global context.
|
|
825
|
+
return localStorage;
|
|
826
|
+
} catch (error) {
|
|
827
|
+
// Swallow
|
|
828
|
+
// XXX (@Qix-) should we be logging these?
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
module.exports = common(exports);
|
|
833
|
+
|
|
834
|
+
const {formatters} = module.exports;
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
|
838
|
+
*/
|
|
839
|
+
|
|
840
|
+
formatters.j = function (v) {
|
|
841
|
+
try {
|
|
842
|
+
return JSON.stringify(v);
|
|
843
|
+
} catch (error) {
|
|
844
|
+
return '[UnexpectedJSONParseError]: ' + error.message;
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
const hasSymbols = () => typeof Symbol === "function";
|
|
850
|
+
const hasSymbol = (name) => hasSymbols() && Boolean(Symbol[name]);
|
|
851
|
+
const getSymbol = (name) => hasSymbol(name) ? Symbol[name] : "@@" + name;
|
|
852
|
+
if (!hasSymbol("asyncIterator")) {
|
|
853
|
+
Symbol.asyncIterator = Symbol.asyncIterator || Symbol.for("Symbol.asyncIterator");
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* Based on <https://raw.githubusercontent.com/zenparsing/zen-observable/master/src/Observable.js>
|
|
858
|
+
* At commit: f63849a8c60af5d514efc8e9d6138d8273c49ad6
|
|
859
|
+
*/
|
|
860
|
+
const SymbolIterator = getSymbol("iterator");
|
|
861
|
+
const SymbolObservable = getSymbol("observable");
|
|
862
|
+
const SymbolSpecies = getSymbol("species");
|
|
863
|
+
// === Abstract Operations ===
|
|
864
|
+
function getMethod(obj, key) {
|
|
865
|
+
const value = obj[key];
|
|
866
|
+
if (value == null) {
|
|
867
|
+
return undefined;
|
|
868
|
+
}
|
|
869
|
+
if (typeof value !== "function") {
|
|
870
|
+
throw new TypeError(value + " is not a function");
|
|
871
|
+
}
|
|
872
|
+
return value;
|
|
873
|
+
}
|
|
874
|
+
function getSpecies(obj) {
|
|
875
|
+
let ctor = obj.constructor;
|
|
876
|
+
if (ctor !== undefined) {
|
|
877
|
+
ctor = ctor[SymbolSpecies];
|
|
878
|
+
if (ctor === null) {
|
|
879
|
+
ctor = undefined;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
return ctor !== undefined ? ctor : Observable;
|
|
883
|
+
}
|
|
884
|
+
function isObservable(x) {
|
|
885
|
+
return x instanceof Observable; // SPEC: Brand check
|
|
886
|
+
}
|
|
887
|
+
function hostReportError(error) {
|
|
888
|
+
if (hostReportError.log) {
|
|
889
|
+
hostReportError.log(error);
|
|
890
|
+
}
|
|
891
|
+
else {
|
|
892
|
+
setTimeout(() => { throw error; }, 0);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
function enqueue(fn) {
|
|
896
|
+
Promise.resolve().then(() => {
|
|
897
|
+
try {
|
|
898
|
+
fn();
|
|
899
|
+
}
|
|
900
|
+
catch (e) {
|
|
901
|
+
hostReportError(e);
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
function cleanupSubscription(subscription) {
|
|
906
|
+
const cleanup = subscription._cleanup;
|
|
907
|
+
if (cleanup === undefined) {
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
subscription._cleanup = undefined;
|
|
911
|
+
if (!cleanup) {
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
try {
|
|
915
|
+
if (typeof cleanup === "function") {
|
|
916
|
+
cleanup();
|
|
917
|
+
}
|
|
918
|
+
else {
|
|
919
|
+
const unsubscribe = getMethod(cleanup, "unsubscribe");
|
|
920
|
+
if (unsubscribe) {
|
|
921
|
+
unsubscribe.call(cleanup);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
catch (e) {
|
|
926
|
+
hostReportError(e);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
function closeSubscription(subscription) {
|
|
930
|
+
subscription._observer = undefined;
|
|
931
|
+
subscription._queue = undefined;
|
|
932
|
+
subscription._state = "closed";
|
|
933
|
+
}
|
|
934
|
+
function flushSubscription(subscription) {
|
|
935
|
+
const queue = subscription._queue;
|
|
936
|
+
if (!queue) {
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
subscription._queue = undefined;
|
|
940
|
+
subscription._state = "ready";
|
|
941
|
+
for (const item of queue) {
|
|
942
|
+
notifySubscription(subscription, item.type, item.value);
|
|
943
|
+
if (subscription._state === "closed") {
|
|
944
|
+
break;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
function notifySubscription(subscription, type, value) {
|
|
949
|
+
subscription._state = "running";
|
|
950
|
+
const observer = subscription._observer;
|
|
951
|
+
try {
|
|
952
|
+
const m = observer ? getMethod(observer, type) : undefined;
|
|
953
|
+
switch (type) {
|
|
954
|
+
case "next":
|
|
955
|
+
if (m)
|
|
956
|
+
m.call(observer, value);
|
|
957
|
+
break;
|
|
958
|
+
case "error":
|
|
959
|
+
closeSubscription(subscription);
|
|
960
|
+
if (m)
|
|
961
|
+
m.call(observer, value);
|
|
962
|
+
else
|
|
963
|
+
throw value;
|
|
964
|
+
break;
|
|
965
|
+
case "complete":
|
|
966
|
+
closeSubscription(subscription);
|
|
967
|
+
if (m)
|
|
968
|
+
m.call(observer);
|
|
969
|
+
break;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
catch (e) {
|
|
973
|
+
hostReportError(e);
|
|
974
|
+
}
|
|
975
|
+
if (subscription._state === "closed") {
|
|
976
|
+
cleanupSubscription(subscription);
|
|
977
|
+
}
|
|
978
|
+
else if (subscription._state === "running") {
|
|
979
|
+
subscription._state = "ready";
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
function onNotify(subscription, type, value) {
|
|
983
|
+
if (subscription._state === "closed") {
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
if (subscription._state === "buffering") {
|
|
987
|
+
subscription._queue = subscription._queue || [];
|
|
988
|
+
subscription._queue.push({ type, value });
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
if (subscription._state !== "ready") {
|
|
992
|
+
subscription._state = "buffering";
|
|
993
|
+
subscription._queue = [{ type, value }];
|
|
994
|
+
enqueue(() => flushSubscription(subscription));
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
notifySubscription(subscription, type, value);
|
|
998
|
+
}
|
|
999
|
+
class Subscription {
|
|
1000
|
+
constructor(observer, subscriber) {
|
|
1001
|
+
// ASSERT: observer is an object
|
|
1002
|
+
// ASSERT: subscriber is callable
|
|
1003
|
+
this._cleanup = undefined;
|
|
1004
|
+
this._observer = observer;
|
|
1005
|
+
this._queue = undefined;
|
|
1006
|
+
this._state = "initializing";
|
|
1007
|
+
const subscriptionObserver = new SubscriptionObserver(this);
|
|
1008
|
+
try {
|
|
1009
|
+
this._cleanup = subscriber.call(undefined, subscriptionObserver);
|
|
1010
|
+
}
|
|
1011
|
+
catch (e) {
|
|
1012
|
+
subscriptionObserver.error(e);
|
|
1013
|
+
}
|
|
1014
|
+
if (this._state === "initializing") {
|
|
1015
|
+
this._state = "ready";
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
get closed() {
|
|
1019
|
+
return this._state === "closed";
|
|
1020
|
+
}
|
|
1021
|
+
unsubscribe() {
|
|
1022
|
+
if (this._state !== "closed") {
|
|
1023
|
+
closeSubscription(this);
|
|
1024
|
+
cleanupSubscription(this);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
class SubscriptionObserver {
|
|
1029
|
+
constructor(subscription) { this._subscription = subscription; }
|
|
1030
|
+
get closed() { return this._subscription._state === "closed"; }
|
|
1031
|
+
next(value) { onNotify(this._subscription, "next", value); }
|
|
1032
|
+
error(value) { onNotify(this._subscription, "error", value); }
|
|
1033
|
+
complete() { onNotify(this._subscription, "complete"); }
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* The basic Observable class. This primitive is used to wrap asynchronous
|
|
1037
|
+
* data streams in a common standardized data type that is interoperable
|
|
1038
|
+
* between libraries and can be composed to represent more complex processes.
|
|
1039
|
+
*/
|
|
1040
|
+
class Observable {
|
|
1041
|
+
constructor(subscriber) {
|
|
1042
|
+
if (!(this instanceof Observable)) {
|
|
1043
|
+
throw new TypeError("Observable cannot be called as a function");
|
|
1044
|
+
}
|
|
1045
|
+
if (typeof subscriber !== "function") {
|
|
1046
|
+
throw new TypeError("Observable initializer must be a function");
|
|
1047
|
+
}
|
|
1048
|
+
this._subscriber = subscriber;
|
|
1049
|
+
}
|
|
1050
|
+
subscribe(nextOrObserver, onError, onComplete) {
|
|
1051
|
+
if (typeof nextOrObserver !== "object" || nextOrObserver === null) {
|
|
1052
|
+
nextOrObserver = {
|
|
1053
|
+
next: nextOrObserver,
|
|
1054
|
+
error: onError,
|
|
1055
|
+
complete: onComplete
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
return new Subscription(nextOrObserver, this._subscriber);
|
|
1059
|
+
}
|
|
1060
|
+
pipe(first, ...mappers) {
|
|
1061
|
+
// tslint:disable-next-line no-this-assignment
|
|
1062
|
+
let intermediate = this;
|
|
1063
|
+
for (const mapper of [first, ...mappers]) {
|
|
1064
|
+
intermediate = mapper(intermediate);
|
|
1065
|
+
}
|
|
1066
|
+
return intermediate;
|
|
1067
|
+
}
|
|
1068
|
+
tap(nextOrObserver, onError, onComplete) {
|
|
1069
|
+
const tapObserver = typeof nextOrObserver !== "object" || nextOrObserver === null
|
|
1070
|
+
? {
|
|
1071
|
+
next: nextOrObserver,
|
|
1072
|
+
error: onError,
|
|
1073
|
+
complete: onComplete
|
|
1074
|
+
}
|
|
1075
|
+
: nextOrObserver;
|
|
1076
|
+
return new Observable(observer => {
|
|
1077
|
+
return this.subscribe({
|
|
1078
|
+
next(value) {
|
|
1079
|
+
tapObserver.next && tapObserver.next(value);
|
|
1080
|
+
observer.next(value);
|
|
1081
|
+
},
|
|
1082
|
+
error(error) {
|
|
1083
|
+
tapObserver.error && tapObserver.error(error);
|
|
1084
|
+
observer.error(error);
|
|
1085
|
+
},
|
|
1086
|
+
complete() {
|
|
1087
|
+
tapObserver.complete && tapObserver.complete();
|
|
1088
|
+
observer.complete();
|
|
1089
|
+
},
|
|
1090
|
+
start(subscription) {
|
|
1091
|
+
tapObserver.start && tapObserver.start(subscription);
|
|
1092
|
+
}
|
|
1093
|
+
});
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
forEach(fn) {
|
|
1097
|
+
return new Promise((resolve, reject) => {
|
|
1098
|
+
if (typeof fn !== "function") {
|
|
1099
|
+
reject(new TypeError(fn + " is not a function"));
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
function done() {
|
|
1103
|
+
subscription.unsubscribe();
|
|
1104
|
+
resolve(undefined);
|
|
1105
|
+
}
|
|
1106
|
+
const subscription = this.subscribe({
|
|
1107
|
+
next(value) {
|
|
1108
|
+
try {
|
|
1109
|
+
fn(value, done);
|
|
1110
|
+
}
|
|
1111
|
+
catch (e) {
|
|
1112
|
+
reject(e);
|
|
1113
|
+
subscription.unsubscribe();
|
|
1114
|
+
}
|
|
1115
|
+
},
|
|
1116
|
+
error(error) {
|
|
1117
|
+
reject(error);
|
|
1118
|
+
},
|
|
1119
|
+
complete() {
|
|
1120
|
+
resolve(undefined);
|
|
1121
|
+
}
|
|
1122
|
+
});
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
map(fn) {
|
|
1126
|
+
if (typeof fn !== "function") {
|
|
1127
|
+
throw new TypeError(fn + " is not a function");
|
|
1128
|
+
}
|
|
1129
|
+
const C = getSpecies(this);
|
|
1130
|
+
return new C(observer => this.subscribe({
|
|
1131
|
+
next(value) {
|
|
1132
|
+
let propagatedValue = value;
|
|
1133
|
+
try {
|
|
1134
|
+
propagatedValue = fn(value);
|
|
1135
|
+
}
|
|
1136
|
+
catch (e) {
|
|
1137
|
+
return observer.error(e);
|
|
1138
|
+
}
|
|
1139
|
+
observer.next(propagatedValue);
|
|
1140
|
+
},
|
|
1141
|
+
error(e) { observer.error(e); },
|
|
1142
|
+
complete() { observer.complete(); },
|
|
1143
|
+
}));
|
|
1144
|
+
}
|
|
1145
|
+
filter(fn) {
|
|
1146
|
+
if (typeof fn !== "function") {
|
|
1147
|
+
throw new TypeError(fn + " is not a function");
|
|
1148
|
+
}
|
|
1149
|
+
const C = getSpecies(this);
|
|
1150
|
+
return new C(observer => this.subscribe({
|
|
1151
|
+
next(value) {
|
|
1152
|
+
try {
|
|
1153
|
+
if (!fn(value))
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
catch (e) {
|
|
1157
|
+
return observer.error(e);
|
|
1158
|
+
}
|
|
1159
|
+
observer.next(value);
|
|
1160
|
+
},
|
|
1161
|
+
error(e) { observer.error(e); },
|
|
1162
|
+
complete() { observer.complete(); },
|
|
1163
|
+
}));
|
|
1164
|
+
}
|
|
1165
|
+
reduce(fn, seed) {
|
|
1166
|
+
if (typeof fn !== "function") {
|
|
1167
|
+
throw new TypeError(fn + " is not a function");
|
|
1168
|
+
}
|
|
1169
|
+
const C = getSpecies(this);
|
|
1170
|
+
const hasSeed = arguments.length > 1;
|
|
1171
|
+
let hasValue = false;
|
|
1172
|
+
let acc = seed;
|
|
1173
|
+
return new C(observer => this.subscribe({
|
|
1174
|
+
next(value) {
|
|
1175
|
+
const first = !hasValue;
|
|
1176
|
+
hasValue = true;
|
|
1177
|
+
if (!first || hasSeed) {
|
|
1178
|
+
try {
|
|
1179
|
+
acc = fn(acc, value);
|
|
1180
|
+
}
|
|
1181
|
+
catch (e) {
|
|
1182
|
+
return observer.error(e);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
else {
|
|
1186
|
+
acc = value;
|
|
1187
|
+
}
|
|
1188
|
+
},
|
|
1189
|
+
error(e) { observer.error(e); },
|
|
1190
|
+
complete() {
|
|
1191
|
+
if (!hasValue && !hasSeed) {
|
|
1192
|
+
return observer.error(new TypeError("Cannot reduce an empty sequence"));
|
|
1193
|
+
}
|
|
1194
|
+
observer.next(acc);
|
|
1195
|
+
observer.complete();
|
|
1196
|
+
},
|
|
1197
|
+
}));
|
|
1198
|
+
}
|
|
1199
|
+
concat(...sources) {
|
|
1200
|
+
const C = getSpecies(this);
|
|
1201
|
+
return new C(observer => {
|
|
1202
|
+
let subscription;
|
|
1203
|
+
let index = 0;
|
|
1204
|
+
function startNext(next) {
|
|
1205
|
+
subscription = next.subscribe({
|
|
1206
|
+
next(v) { observer.next(v); },
|
|
1207
|
+
error(e) { observer.error(e); },
|
|
1208
|
+
complete() {
|
|
1209
|
+
if (index === sources.length) {
|
|
1210
|
+
subscription = undefined;
|
|
1211
|
+
observer.complete();
|
|
1212
|
+
}
|
|
1213
|
+
else {
|
|
1214
|
+
startNext(C.from(sources[index++]));
|
|
1215
|
+
}
|
|
1216
|
+
},
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
startNext(this);
|
|
1220
|
+
return () => {
|
|
1221
|
+
if (subscription) {
|
|
1222
|
+
subscription.unsubscribe();
|
|
1223
|
+
subscription = undefined;
|
|
1224
|
+
}
|
|
1225
|
+
};
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
flatMap(fn) {
|
|
1229
|
+
if (typeof fn !== "function") {
|
|
1230
|
+
throw new TypeError(fn + " is not a function");
|
|
1231
|
+
}
|
|
1232
|
+
const C = getSpecies(this);
|
|
1233
|
+
return new C(observer => {
|
|
1234
|
+
const subscriptions = [];
|
|
1235
|
+
const outer = this.subscribe({
|
|
1236
|
+
next(value) {
|
|
1237
|
+
let normalizedValue;
|
|
1238
|
+
if (fn) {
|
|
1239
|
+
try {
|
|
1240
|
+
normalizedValue = fn(value);
|
|
1241
|
+
}
|
|
1242
|
+
catch (e) {
|
|
1243
|
+
return observer.error(e);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
else {
|
|
1247
|
+
normalizedValue = value;
|
|
1248
|
+
}
|
|
1249
|
+
const inner = C.from(normalizedValue).subscribe({
|
|
1250
|
+
next(innerValue) { observer.next(innerValue); },
|
|
1251
|
+
error(e) { observer.error(e); },
|
|
1252
|
+
complete() {
|
|
1253
|
+
const i = subscriptions.indexOf(inner);
|
|
1254
|
+
if (i >= 0)
|
|
1255
|
+
subscriptions.splice(i, 1);
|
|
1256
|
+
completeIfDone();
|
|
1257
|
+
},
|
|
1258
|
+
});
|
|
1259
|
+
subscriptions.push(inner);
|
|
1260
|
+
},
|
|
1261
|
+
error(e) { observer.error(e); },
|
|
1262
|
+
complete() { completeIfDone(); },
|
|
1263
|
+
});
|
|
1264
|
+
function completeIfDone() {
|
|
1265
|
+
if (outer.closed && subscriptions.length === 0) {
|
|
1266
|
+
observer.complete();
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
return () => {
|
|
1270
|
+
subscriptions.forEach(s => s.unsubscribe());
|
|
1271
|
+
outer.unsubscribe();
|
|
1272
|
+
};
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
[(SymbolObservable)]() { return this; }
|
|
1276
|
+
static from(x) {
|
|
1277
|
+
const C = (typeof this === "function" ? this : Observable);
|
|
1278
|
+
if (x == null) {
|
|
1279
|
+
throw new TypeError(x + " is not an object");
|
|
1280
|
+
}
|
|
1281
|
+
const observableMethod = getMethod(x, SymbolObservable);
|
|
1282
|
+
if (observableMethod) {
|
|
1283
|
+
const observable = observableMethod.call(x);
|
|
1284
|
+
if (Object(observable) !== observable) {
|
|
1285
|
+
throw new TypeError(observable + " is not an object");
|
|
1286
|
+
}
|
|
1287
|
+
if (isObservable(observable) && observable.constructor === C) {
|
|
1288
|
+
return observable;
|
|
1289
|
+
}
|
|
1290
|
+
return new C(observer => observable.subscribe(observer));
|
|
1291
|
+
}
|
|
1292
|
+
if (hasSymbol("iterator")) {
|
|
1293
|
+
const iteratorMethod = getMethod(x, SymbolIterator);
|
|
1294
|
+
if (iteratorMethod) {
|
|
1295
|
+
return new C(observer => {
|
|
1296
|
+
enqueue(() => {
|
|
1297
|
+
if (observer.closed)
|
|
1298
|
+
return;
|
|
1299
|
+
for (const item of iteratorMethod.call(x)) {
|
|
1300
|
+
observer.next(item);
|
|
1301
|
+
if (observer.closed)
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
observer.complete();
|
|
1305
|
+
});
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
if (Array.isArray(x)) {
|
|
1310
|
+
return new C(observer => {
|
|
1311
|
+
enqueue(() => {
|
|
1312
|
+
if (observer.closed)
|
|
1313
|
+
return;
|
|
1314
|
+
for (const item of x) {
|
|
1315
|
+
observer.next(item);
|
|
1316
|
+
if (observer.closed)
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
observer.complete();
|
|
1320
|
+
});
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
throw new TypeError(x + " is not observable");
|
|
1324
|
+
}
|
|
1325
|
+
static of(...items) {
|
|
1326
|
+
const C = (typeof this === "function" ? this : Observable);
|
|
1327
|
+
return new C(observer => {
|
|
1328
|
+
enqueue(() => {
|
|
1329
|
+
if (observer.closed)
|
|
1330
|
+
return;
|
|
1331
|
+
for (const item of items) {
|
|
1332
|
+
observer.next(item);
|
|
1333
|
+
if (observer.closed)
|
|
1334
|
+
return;
|
|
1335
|
+
}
|
|
1336
|
+
observer.complete();
|
|
1337
|
+
});
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
static get [SymbolSpecies]() { return this; }
|
|
1341
|
+
}
|
|
1342
|
+
if (hasSymbols()) {
|
|
1343
|
+
Object.defineProperty(Observable, Symbol("extensions"), {
|
|
1344
|
+
value: {
|
|
1345
|
+
symbol: SymbolObservable,
|
|
1346
|
+
hostReportError,
|
|
1347
|
+
},
|
|
1348
|
+
configurable: true,
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
/**
|
|
1353
|
+
* Unsubscribe from a subscription returned by something that looks like an observable,
|
|
1354
|
+
* but is not necessarily our observable implementation.
|
|
1355
|
+
*/
|
|
1356
|
+
function unsubscribe(subscription) {
|
|
1357
|
+
if (typeof subscription === "function") {
|
|
1358
|
+
subscription();
|
|
1359
|
+
}
|
|
1360
|
+
else if (subscription && typeof subscription.unsubscribe === "function") {
|
|
1361
|
+
subscription.unsubscribe();
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
// TODO: This observer iteration approach looks inelegant and expensive
|
|
1366
|
+
// Idea: Come up with super class for Subscription that contains the
|
|
1367
|
+
// notify*, ... methods and use it here
|
|
1368
|
+
/**
|
|
1369
|
+
* A subject is a "hot" observable (see `multicast`) that has its observer
|
|
1370
|
+
* methods (`.next(value)`, `.error(error)`, `.complete()`) exposed.
|
|
1371
|
+
*
|
|
1372
|
+
* Be careful, though! With great power comes great responsibility. Only use
|
|
1373
|
+
* the `Subject` when you really need to trigger updates "from the outside" and
|
|
1374
|
+
* try to keep the code that can access it to a minimum. Return
|
|
1375
|
+
* `Observable.from(mySubject)` to not allow other code to mutate.
|
|
1376
|
+
*/
|
|
1377
|
+
class MulticastSubject extends Observable {
|
|
1378
|
+
constructor() {
|
|
1379
|
+
super(observer => {
|
|
1380
|
+
this._observers.add(observer);
|
|
1381
|
+
return () => this._observers.delete(observer);
|
|
1382
|
+
});
|
|
1383
|
+
this._observers = new Set();
|
|
1384
|
+
}
|
|
1385
|
+
next(value) {
|
|
1386
|
+
for (const observer of this._observers) {
|
|
1387
|
+
observer.next(value);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
error(error) {
|
|
1391
|
+
for (const observer of this._observers) {
|
|
1392
|
+
observer.error(error);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
complete() {
|
|
1396
|
+
for (const observer of this._observers) {
|
|
1397
|
+
observer.complete();
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
// TODO: Subject already creates additional observables "under the hood",
|
|
1403
|
+
// now we introduce even more. A true native MulticastObservable
|
|
1404
|
+
// would be preferable.
|
|
1405
|
+
/**
|
|
1406
|
+
* Takes a "cold" observable and returns a wrapping "hot" observable that
|
|
1407
|
+
* proxies the input observable's values and errors.
|
|
1408
|
+
*
|
|
1409
|
+
* An observable is called "cold" when its initialization function is run
|
|
1410
|
+
* for each new subscriber. This is how observable-fns's `Observable`
|
|
1411
|
+
* implementation works.
|
|
1412
|
+
*
|
|
1413
|
+
* A hot observable is an observable where new subscribers subscribe to
|
|
1414
|
+
* the upcoming values of an already-initialiazed observable.
|
|
1415
|
+
*
|
|
1416
|
+
* The multicast observable will lazily subscribe to the source observable
|
|
1417
|
+
* once it has its first own subscriber and will unsubscribe from the
|
|
1418
|
+
* source observable when its last own subscriber unsubscribed.
|
|
1419
|
+
*/
|
|
1420
|
+
function multicast(coldObservable) {
|
|
1421
|
+
const subject = new MulticastSubject();
|
|
1422
|
+
let sourceSubscription;
|
|
1423
|
+
let subscriberCount = 0;
|
|
1424
|
+
return new Observable(observer => {
|
|
1425
|
+
// Init source subscription lazily
|
|
1426
|
+
if (!sourceSubscription) {
|
|
1427
|
+
sourceSubscription = coldObservable.subscribe(subject);
|
|
1428
|
+
}
|
|
1429
|
+
// Pipe all events from `subject` into this observable
|
|
1430
|
+
const subscription = subject.subscribe(observer);
|
|
1431
|
+
subscriberCount++;
|
|
1432
|
+
return () => {
|
|
1433
|
+
subscriberCount--;
|
|
1434
|
+
subscription.unsubscribe();
|
|
1435
|
+
// Close source subscription once last subscriber has unsubscribed
|
|
1436
|
+
if (subscriberCount === 0) {
|
|
1437
|
+
unsubscribe(sourceSubscription);
|
|
1438
|
+
sourceSubscription = undefined;
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
// Based on <https://github.com/es-shims/Promise.allSettled/blob/master/implementation.js>
|
|
1445
|
+
function allSettled(values) {
|
|
1446
|
+
return Promise.all(values.map(item => {
|
|
1447
|
+
const onFulfill = (value) => {
|
|
1448
|
+
return { status: 'fulfilled', value };
|
|
1449
|
+
};
|
|
1450
|
+
const onReject = (reason) => {
|
|
1451
|
+
return { status: 'rejected', reason };
|
|
1452
|
+
};
|
|
1453
|
+
const itemPromise = Promise.resolve(item);
|
|
1454
|
+
try {
|
|
1455
|
+
return itemPromise.then(onFulfill, onReject);
|
|
1456
|
+
}
|
|
1457
|
+
catch (error) {
|
|
1458
|
+
return Promise.reject(error);
|
|
1459
|
+
}
|
|
1460
|
+
}));
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
/** Pool event type. Specifies the type of each `PoolEvent`. */
|
|
1464
|
+
var PoolEventType;
|
|
1465
|
+
(function (PoolEventType) {
|
|
1466
|
+
PoolEventType["initialized"] = "initialized";
|
|
1467
|
+
PoolEventType["taskCanceled"] = "taskCanceled";
|
|
1468
|
+
PoolEventType["taskCompleted"] = "taskCompleted";
|
|
1469
|
+
PoolEventType["taskFailed"] = "taskFailed";
|
|
1470
|
+
PoolEventType["taskQueued"] = "taskQueued";
|
|
1471
|
+
PoolEventType["taskQueueDrained"] = "taskQueueDrained";
|
|
1472
|
+
PoolEventType["taskStart"] = "taskStart";
|
|
1473
|
+
PoolEventType["terminated"] = "terminated";
|
|
1474
|
+
})(PoolEventType || (PoolEventType = {}));
|
|
1475
|
+
|
|
1476
|
+
const $errors = Symbol("thread.errors");
|
|
1477
|
+
const $events = Symbol("thread.events");
|
|
1478
|
+
const $terminate = Symbol("thread.terminate");
|
|
1479
|
+
const $transferable = Symbol("thread.transferable");
|
|
1480
|
+
const $worker = Symbol("thread.worker");
|
|
1481
|
+
|
|
1482
|
+
function fail$1(message) {
|
|
1483
|
+
throw Error(message);
|
|
1484
|
+
}
|
|
1485
|
+
/** Thread utility functions. Use them to manage or inspect a `spawn()`-ed thread. */
|
|
1486
|
+
const Thread = {
|
|
1487
|
+
/** Return an observable that can be used to subscribe to all errors happening in the thread. */
|
|
1488
|
+
errors(thread) {
|
|
1489
|
+
return thread[$errors] || fail$1("Error observable not found. Make sure to pass a thread instance as returned by the spawn() promise.");
|
|
1490
|
+
},
|
|
1491
|
+
/** Return an observable that can be used to subscribe to internal events happening in the thread. Useful for debugging. */
|
|
1492
|
+
events(thread) {
|
|
1493
|
+
return thread[$events] || fail$1("Events observable not found. Make sure to pass a thread instance as returned by the spawn() promise.");
|
|
1494
|
+
},
|
|
1495
|
+
/** Terminate a thread. Remember to terminate every thread when you are done using it. */
|
|
1496
|
+
terminate(thread) {
|
|
1497
|
+
return thread[$terminate]();
|
|
1498
|
+
}
|
|
1499
|
+
};
|
|
1500
|
+
|
|
1501
|
+
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1502
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1503
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1504
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1505
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1506
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1507
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1508
|
+
});
|
|
1509
|
+
};
|
|
1510
|
+
let nextPoolID = 1;
|
|
1511
|
+
function createArray(size) {
|
|
1512
|
+
const array = [];
|
|
1513
|
+
for (let index = 0; index < size; index++) {
|
|
1514
|
+
array.push(index);
|
|
1515
|
+
}
|
|
1516
|
+
return array;
|
|
1517
|
+
}
|
|
1518
|
+
function delay(ms) {
|
|
1519
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
1520
|
+
}
|
|
1521
|
+
function flatMap(array, mapper) {
|
|
1522
|
+
return array.reduce((flattened, element) => [...flattened, ...mapper(element)], []);
|
|
1523
|
+
}
|
|
1524
|
+
function slugify(text) {
|
|
1525
|
+
return text.replace(/\W/g, " ").trim().replace(/\s+/g, "-");
|
|
1526
|
+
}
|
|
1527
|
+
function spawnWorkers(spawnWorker, count) {
|
|
1528
|
+
return createArray(count).map(() => ({
|
|
1529
|
+
init: spawnWorker(),
|
|
1530
|
+
runningTasks: []
|
|
1531
|
+
}));
|
|
1532
|
+
}
|
|
1533
|
+
class WorkerPool {
|
|
1534
|
+
constructor(spawnWorker, optionsOrSize) {
|
|
1535
|
+
this.eventSubject = new MulticastSubject();
|
|
1536
|
+
this.initErrors = [];
|
|
1537
|
+
this.isClosing = false;
|
|
1538
|
+
this.nextTaskID = 1;
|
|
1539
|
+
this.taskQueue = [];
|
|
1540
|
+
const options = typeof optionsOrSize === "number"
|
|
1541
|
+
? { size: optionsOrSize }
|
|
1542
|
+
: optionsOrSize || {};
|
|
1543
|
+
const { size = defaultPoolSize } = options;
|
|
1544
|
+
this.debug = browser(`threads:pool:${slugify(options.name || String(nextPoolID++))}`);
|
|
1545
|
+
this.options = options;
|
|
1546
|
+
this.workers = spawnWorkers(spawnWorker, size);
|
|
1547
|
+
this.eventObservable = multicast(Observable.from(this.eventSubject));
|
|
1548
|
+
Promise.all(this.workers.map(worker => worker.init)).then(() => this.eventSubject.next({
|
|
1549
|
+
type: PoolEventType.initialized,
|
|
1550
|
+
size: this.workers.length
|
|
1551
|
+
}), error => {
|
|
1552
|
+
this.debug("Error while initializing pool worker:", error);
|
|
1553
|
+
this.eventSubject.error(error);
|
|
1554
|
+
this.initErrors.push(error);
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
findIdlingWorker() {
|
|
1558
|
+
const { concurrency = 1 } = this.options;
|
|
1559
|
+
return this.workers.find(worker => worker.runningTasks.length < concurrency);
|
|
1560
|
+
}
|
|
1561
|
+
runPoolTask(worker, task) {
|
|
1562
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
1563
|
+
const workerID = this.workers.indexOf(worker) + 1;
|
|
1564
|
+
this.debug(`Running task #${task.id} on worker #${workerID}...`);
|
|
1565
|
+
this.eventSubject.next({
|
|
1566
|
+
type: PoolEventType.taskStart,
|
|
1567
|
+
taskID: task.id,
|
|
1568
|
+
workerID
|
|
1569
|
+
});
|
|
1570
|
+
try {
|
|
1571
|
+
const returnValue = yield task.run(yield worker.init);
|
|
1572
|
+
this.debug(`Task #${task.id} completed successfully`);
|
|
1573
|
+
this.eventSubject.next({
|
|
1574
|
+
type: PoolEventType.taskCompleted,
|
|
1575
|
+
returnValue,
|
|
1576
|
+
taskID: task.id,
|
|
1577
|
+
workerID
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
1580
|
+
catch (error) {
|
|
1581
|
+
this.debug(`Task #${task.id} failed`);
|
|
1582
|
+
this.eventSubject.next({
|
|
1583
|
+
type: PoolEventType.taskFailed,
|
|
1584
|
+
taskID: task.id,
|
|
1585
|
+
error,
|
|
1586
|
+
workerID
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
run(worker, task) {
|
|
1592
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
1593
|
+
const runPromise = (() => __awaiter$1(this, void 0, void 0, function* () {
|
|
1594
|
+
const removeTaskFromWorkersRunningTasks = () => {
|
|
1595
|
+
worker.runningTasks = worker.runningTasks.filter(someRunPromise => someRunPromise !== runPromise);
|
|
1596
|
+
};
|
|
1597
|
+
// Defer task execution by one tick to give handlers time to subscribe
|
|
1598
|
+
yield delay(0);
|
|
1599
|
+
try {
|
|
1600
|
+
yield this.runPoolTask(worker, task);
|
|
1601
|
+
}
|
|
1602
|
+
finally {
|
|
1603
|
+
removeTaskFromWorkersRunningTasks();
|
|
1604
|
+
if (!this.isClosing) {
|
|
1605
|
+
this.scheduleWork();
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
}))();
|
|
1609
|
+
worker.runningTasks.push(runPromise);
|
|
1610
|
+
});
|
|
1611
|
+
}
|
|
1612
|
+
scheduleWork() {
|
|
1613
|
+
this.debug(`Attempt de-queueing a task in order to run it...`);
|
|
1614
|
+
const availableWorker = this.findIdlingWorker();
|
|
1615
|
+
if (!availableWorker)
|
|
1616
|
+
return;
|
|
1617
|
+
const nextTask = this.taskQueue.shift();
|
|
1618
|
+
if (!nextTask) {
|
|
1619
|
+
this.debug(`Task queue is empty`);
|
|
1620
|
+
this.eventSubject.next({ type: PoolEventType.taskQueueDrained });
|
|
1621
|
+
return;
|
|
1622
|
+
}
|
|
1623
|
+
this.run(availableWorker, nextTask);
|
|
1624
|
+
}
|
|
1625
|
+
taskCompletion(taskID) {
|
|
1626
|
+
return new Promise((resolve, reject) => {
|
|
1627
|
+
const eventSubscription = this.events().subscribe(event => {
|
|
1628
|
+
if (event.type === PoolEventType.taskCompleted && event.taskID === taskID) {
|
|
1629
|
+
eventSubscription.unsubscribe();
|
|
1630
|
+
resolve(event.returnValue);
|
|
1631
|
+
}
|
|
1632
|
+
else if (event.type === PoolEventType.taskFailed && event.taskID === taskID) {
|
|
1633
|
+
eventSubscription.unsubscribe();
|
|
1634
|
+
reject(event.error);
|
|
1635
|
+
}
|
|
1636
|
+
else if (event.type === PoolEventType.terminated) {
|
|
1637
|
+
eventSubscription.unsubscribe();
|
|
1638
|
+
reject(Error("Pool has been terminated before task was run."));
|
|
1639
|
+
}
|
|
1640
|
+
});
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
settled(allowResolvingImmediately = false) {
|
|
1644
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
1645
|
+
const getCurrentlyRunningTasks = () => flatMap(this.workers, worker => worker.runningTasks);
|
|
1646
|
+
const taskFailures = [];
|
|
1647
|
+
const failureSubscription = this.eventObservable.subscribe(event => {
|
|
1648
|
+
if (event.type === PoolEventType.taskFailed) {
|
|
1649
|
+
taskFailures.push(event.error);
|
|
1650
|
+
}
|
|
1651
|
+
});
|
|
1652
|
+
if (this.initErrors.length > 0) {
|
|
1653
|
+
return Promise.reject(this.initErrors[0]);
|
|
1654
|
+
}
|
|
1655
|
+
if (allowResolvingImmediately && this.taskQueue.length === 0) {
|
|
1656
|
+
yield allSettled(getCurrentlyRunningTasks());
|
|
1657
|
+
return taskFailures;
|
|
1658
|
+
}
|
|
1659
|
+
yield new Promise((resolve, reject) => {
|
|
1660
|
+
const subscription = this.eventObservable.subscribe({
|
|
1661
|
+
next(event) {
|
|
1662
|
+
if (event.type === PoolEventType.taskQueueDrained) {
|
|
1663
|
+
subscription.unsubscribe();
|
|
1664
|
+
resolve(void 0);
|
|
1665
|
+
}
|
|
1666
|
+
},
|
|
1667
|
+
error: reject // make a pool-wide error reject the completed() result promise
|
|
1668
|
+
});
|
|
1669
|
+
});
|
|
1670
|
+
yield allSettled(getCurrentlyRunningTasks());
|
|
1671
|
+
failureSubscription.unsubscribe();
|
|
1672
|
+
return taskFailures;
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
completed(allowResolvingImmediately = false) {
|
|
1676
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
1677
|
+
const settlementPromise = this.settled(allowResolvingImmediately);
|
|
1678
|
+
const earlyExitPromise = new Promise((resolve, reject) => {
|
|
1679
|
+
const subscription = this.eventObservable.subscribe({
|
|
1680
|
+
next(event) {
|
|
1681
|
+
if (event.type === PoolEventType.taskQueueDrained) {
|
|
1682
|
+
subscription.unsubscribe();
|
|
1683
|
+
resolve(settlementPromise);
|
|
1684
|
+
}
|
|
1685
|
+
else if (event.type === PoolEventType.taskFailed) {
|
|
1686
|
+
subscription.unsubscribe();
|
|
1687
|
+
reject(event.error);
|
|
1688
|
+
}
|
|
1689
|
+
},
|
|
1690
|
+
error: reject // make a pool-wide error reject the completed() result promise
|
|
1691
|
+
});
|
|
1692
|
+
});
|
|
1693
|
+
const errors = yield Promise.race([
|
|
1694
|
+
settlementPromise,
|
|
1695
|
+
earlyExitPromise
|
|
1696
|
+
]);
|
|
1697
|
+
if (errors.length > 0) {
|
|
1698
|
+
throw errors[0];
|
|
1699
|
+
}
|
|
1700
|
+
});
|
|
1701
|
+
}
|
|
1702
|
+
events() {
|
|
1703
|
+
return this.eventObservable;
|
|
1704
|
+
}
|
|
1705
|
+
queue(taskFunction) {
|
|
1706
|
+
const { maxQueuedJobs = Infinity } = this.options;
|
|
1707
|
+
if (this.isClosing) {
|
|
1708
|
+
throw Error(`Cannot schedule pool tasks after terminate() has been called.`);
|
|
1709
|
+
}
|
|
1710
|
+
if (this.initErrors.length > 0) {
|
|
1711
|
+
throw this.initErrors[0];
|
|
1712
|
+
}
|
|
1713
|
+
const taskID = this.nextTaskID++;
|
|
1714
|
+
const taskCompletion = this.taskCompletion(taskID);
|
|
1715
|
+
taskCompletion.catch((error) => {
|
|
1716
|
+
// Prevent unhandled rejections here as we assume the user will use
|
|
1717
|
+
// `pool.completed()`, `pool.settled()` or `task.catch()` to handle errors
|
|
1718
|
+
this.debug(`Task #${taskID} errored:`, error);
|
|
1719
|
+
});
|
|
1720
|
+
const task = {
|
|
1721
|
+
id: taskID,
|
|
1722
|
+
run: taskFunction,
|
|
1723
|
+
cancel: () => {
|
|
1724
|
+
if (this.taskQueue.indexOf(task) === -1)
|
|
1725
|
+
return;
|
|
1726
|
+
this.taskQueue = this.taskQueue.filter(someTask => someTask !== task);
|
|
1727
|
+
this.eventSubject.next({
|
|
1728
|
+
type: PoolEventType.taskCanceled,
|
|
1729
|
+
taskID: task.id
|
|
1730
|
+
});
|
|
1731
|
+
},
|
|
1732
|
+
then: taskCompletion.then.bind(taskCompletion)
|
|
1733
|
+
};
|
|
1734
|
+
if (this.taskQueue.length >= maxQueuedJobs) {
|
|
1735
|
+
throw Error("Maximum number of pool tasks queued. Refusing to queue another one.\n" +
|
|
1736
|
+
"This usually happens for one of two reasons: We are either at peak " +
|
|
1737
|
+
"workload right now or some tasks just won't finish, thus blocking the pool.");
|
|
1738
|
+
}
|
|
1739
|
+
this.debug(`Queueing task #${task.id}...`);
|
|
1740
|
+
this.taskQueue.push(task);
|
|
1741
|
+
this.eventSubject.next({
|
|
1742
|
+
type: PoolEventType.taskQueued,
|
|
1743
|
+
taskID: task.id
|
|
1744
|
+
});
|
|
1745
|
+
this.scheduleWork();
|
|
1746
|
+
return task;
|
|
1747
|
+
}
|
|
1748
|
+
terminate(force) {
|
|
1749
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
1750
|
+
this.isClosing = true;
|
|
1751
|
+
if (!force) {
|
|
1752
|
+
yield this.completed(true);
|
|
1753
|
+
}
|
|
1754
|
+
this.eventSubject.next({
|
|
1755
|
+
type: PoolEventType.terminated,
|
|
1756
|
+
remainingQueue: [...this.taskQueue]
|
|
1757
|
+
});
|
|
1758
|
+
this.eventSubject.complete();
|
|
1759
|
+
yield Promise.all(this.workers.map((worker) => __awaiter$1(this, void 0, void 0, function* () { return Thread.terminate(yield worker.init); })));
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
WorkerPool.EventType = PoolEventType;
|
|
1764
|
+
/**
|
|
1765
|
+
* Thread pool constructor. Creates a new pool and spawns its worker threads.
|
|
1766
|
+
*/
|
|
1767
|
+
function PoolConstructor(spawnWorker, optionsOrSize) {
|
|
1768
|
+
// The function exists only so we don't need to use `new` to create a pool (we still can, though).
|
|
1769
|
+
// If the Pool is a class or not is an implementation detail that should not concern the user.
|
|
1770
|
+
return new WorkerPool(spawnWorker, optionsOrSize);
|
|
1771
|
+
}
|
|
1772
|
+
PoolConstructor.EventType = PoolEventType;
|
|
1773
|
+
/**
|
|
1774
|
+
* Thread pool constructor. Creates a new pool and spawns its worker threads.
|
|
1775
|
+
*/
|
|
1776
|
+
const Pool = PoolConstructor;
|
|
1777
|
+
|
|
1778
|
+
const doNothing$1 = () => undefined;
|
|
1779
|
+
/**
|
|
1780
|
+
* Creates a new promise and exposes its resolver function.
|
|
1781
|
+
* Use with care!
|
|
1782
|
+
*/
|
|
1783
|
+
function createPromiseWithResolver() {
|
|
1784
|
+
let alreadyResolved = false;
|
|
1785
|
+
let resolvedTo;
|
|
1786
|
+
let resolver = doNothing$1;
|
|
1787
|
+
const promise = new Promise(resolve => {
|
|
1788
|
+
if (alreadyResolved) {
|
|
1789
|
+
resolve(resolvedTo);
|
|
1790
|
+
}
|
|
1791
|
+
else {
|
|
1792
|
+
resolver = resolve;
|
|
1793
|
+
}
|
|
1794
|
+
});
|
|
1795
|
+
const exposedResolver = (value) => {
|
|
1796
|
+
alreadyResolved = true;
|
|
1797
|
+
resolvedTo = value;
|
|
1798
|
+
resolver(resolvedTo);
|
|
1799
|
+
};
|
|
1800
|
+
return [promise, exposedResolver];
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
/// <reference lib="dom" />
|
|
1804
|
+
/** Event as emitted by worker thread. Subscribe to using `Thread.events(thread)`. */
|
|
1805
|
+
var WorkerEventType;
|
|
1806
|
+
(function (WorkerEventType) {
|
|
1807
|
+
WorkerEventType["internalError"] = "internalError";
|
|
1808
|
+
WorkerEventType["message"] = "message";
|
|
1809
|
+
WorkerEventType["termination"] = "termination";
|
|
1810
|
+
})(WorkerEventType || (WorkerEventType = {}));
|
|
1811
|
+
|
|
1812
|
+
const doNothing = () => undefined;
|
|
1813
|
+
const returnInput = (input) => input;
|
|
1814
|
+
const runDeferred = (fn) => Promise.resolve().then(fn);
|
|
1815
|
+
function fail(error) {
|
|
1816
|
+
throw error;
|
|
1817
|
+
}
|
|
1818
|
+
function isThenable(thing) {
|
|
1819
|
+
return thing && typeof thing.then === "function";
|
|
1820
|
+
}
|
|
1821
|
+
/**
|
|
1822
|
+
* Creates a hybrid, combining the APIs of an Observable and a Promise.
|
|
1823
|
+
*
|
|
1824
|
+
* It is used to proxy async process states when we are initially not sure
|
|
1825
|
+
* if that async process will yield values once (-> Promise) or multiple
|
|
1826
|
+
* times (-> Observable).
|
|
1827
|
+
*
|
|
1828
|
+
* Note that the observable promise inherits some of the observable's characteristics:
|
|
1829
|
+
* The `init` function will be called *once for every time anyone subscribes to it*.
|
|
1830
|
+
*
|
|
1831
|
+
* If this is undesired, derive a hot observable from it using `makeHot()` and
|
|
1832
|
+
* subscribe to that.
|
|
1833
|
+
*/
|
|
1834
|
+
class ObservablePromise extends Observable {
|
|
1835
|
+
constructor(init) {
|
|
1836
|
+
super((originalObserver) => {
|
|
1837
|
+
// tslint:disable-next-line no-this-assignment
|
|
1838
|
+
const self = this;
|
|
1839
|
+
const observer = Object.assign(Object.assign({}, originalObserver), { complete() {
|
|
1840
|
+
originalObserver.complete();
|
|
1841
|
+
self.onCompletion();
|
|
1842
|
+
}, error(error) {
|
|
1843
|
+
originalObserver.error(error);
|
|
1844
|
+
self.onError(error);
|
|
1845
|
+
},
|
|
1846
|
+
next(value) {
|
|
1847
|
+
originalObserver.next(value);
|
|
1848
|
+
self.onNext(value);
|
|
1849
|
+
} });
|
|
1850
|
+
try {
|
|
1851
|
+
this.initHasRun = true;
|
|
1852
|
+
return init(observer);
|
|
1853
|
+
}
|
|
1854
|
+
catch (error) {
|
|
1855
|
+
observer.error(error);
|
|
1856
|
+
}
|
|
1857
|
+
});
|
|
1858
|
+
this.initHasRun = false;
|
|
1859
|
+
this.fulfillmentCallbacks = [];
|
|
1860
|
+
this.rejectionCallbacks = [];
|
|
1861
|
+
this.firstValueSet = false;
|
|
1862
|
+
this.state = "pending";
|
|
1863
|
+
}
|
|
1864
|
+
onNext(value) {
|
|
1865
|
+
if (!this.firstValueSet) {
|
|
1866
|
+
this.firstValue = value;
|
|
1867
|
+
this.firstValueSet = true;
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
onError(error) {
|
|
1871
|
+
this.state = "rejected";
|
|
1872
|
+
this.rejection = error;
|
|
1873
|
+
for (const onRejected of this.rejectionCallbacks) {
|
|
1874
|
+
// Promisifying the call to turn errors into unhandled promise rejections
|
|
1875
|
+
// instead of them failing sync and cancelling the iteration
|
|
1876
|
+
runDeferred(() => onRejected(error));
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
onCompletion() {
|
|
1880
|
+
this.state = "fulfilled";
|
|
1881
|
+
for (const onFulfilled of this.fulfillmentCallbacks) {
|
|
1882
|
+
// Promisifying the call to turn errors into unhandled promise rejections
|
|
1883
|
+
// instead of them failing sync and cancelling the iteration
|
|
1884
|
+
runDeferred(() => onFulfilled(this.firstValue));
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
then(onFulfilledRaw, onRejectedRaw) {
|
|
1888
|
+
const onFulfilled = onFulfilledRaw || returnInput;
|
|
1889
|
+
const onRejected = onRejectedRaw || fail;
|
|
1890
|
+
let onRejectedCalled = false;
|
|
1891
|
+
return new Promise((resolve, reject) => {
|
|
1892
|
+
const rejectionCallback = (error) => {
|
|
1893
|
+
if (onRejectedCalled)
|
|
1894
|
+
return;
|
|
1895
|
+
onRejectedCalled = true;
|
|
1896
|
+
try {
|
|
1897
|
+
resolve(onRejected(error));
|
|
1898
|
+
}
|
|
1899
|
+
catch (anotherError) {
|
|
1900
|
+
reject(anotherError);
|
|
1901
|
+
}
|
|
1902
|
+
};
|
|
1903
|
+
const fulfillmentCallback = (value) => {
|
|
1904
|
+
try {
|
|
1905
|
+
resolve(onFulfilled(value));
|
|
1906
|
+
}
|
|
1907
|
+
catch (error) {
|
|
1908
|
+
rejectionCallback(error);
|
|
1909
|
+
}
|
|
1910
|
+
};
|
|
1911
|
+
if (!this.initHasRun) {
|
|
1912
|
+
this.subscribe({ error: rejectionCallback });
|
|
1913
|
+
}
|
|
1914
|
+
if (this.state === "fulfilled") {
|
|
1915
|
+
return resolve(onFulfilled(this.firstValue));
|
|
1916
|
+
}
|
|
1917
|
+
if (this.state === "rejected") {
|
|
1918
|
+
onRejectedCalled = true;
|
|
1919
|
+
return resolve(onRejected(this.rejection));
|
|
1920
|
+
}
|
|
1921
|
+
this.fulfillmentCallbacks.push(fulfillmentCallback);
|
|
1922
|
+
this.rejectionCallbacks.push(rejectionCallback);
|
|
1923
|
+
});
|
|
1924
|
+
}
|
|
1925
|
+
catch(onRejected) {
|
|
1926
|
+
return this.then(undefined, onRejected);
|
|
1927
|
+
}
|
|
1928
|
+
finally(onCompleted) {
|
|
1929
|
+
const handler = onCompleted || doNothing;
|
|
1930
|
+
return this.then((value) => {
|
|
1931
|
+
handler();
|
|
1932
|
+
return value;
|
|
1933
|
+
}, () => handler());
|
|
1934
|
+
}
|
|
1935
|
+
static from(thing) {
|
|
1936
|
+
if (isThenable(thing)) {
|
|
1937
|
+
return new ObservablePromise(observer => {
|
|
1938
|
+
const onFulfilled = (value) => {
|
|
1939
|
+
observer.next(value);
|
|
1940
|
+
observer.complete();
|
|
1941
|
+
};
|
|
1942
|
+
const onRejected = (error) => {
|
|
1943
|
+
observer.error(error);
|
|
1944
|
+
};
|
|
1945
|
+
thing.then(onFulfilled, onRejected);
|
|
1946
|
+
});
|
|
1947
|
+
}
|
|
1948
|
+
else {
|
|
1949
|
+
return super.from(thing);
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
function isTransferable$1(thing) {
|
|
1955
|
+
if (!thing || typeof thing !== "object")
|
|
1956
|
+
return false;
|
|
1957
|
+
// Don't check too thoroughly, since the list of transferable things in JS might grow over time
|
|
1958
|
+
return true;
|
|
1959
|
+
}
|
|
1960
|
+
function isTransferDescriptor(thing) {
|
|
1961
|
+
return thing && typeof thing === "object" && thing[$transferable];
|
|
1962
|
+
}
|
|
1963
|
+
function Transfer(payload, transferables) {
|
|
1964
|
+
if (!transferables) {
|
|
1965
|
+
if (!isTransferable$1(payload))
|
|
1966
|
+
throw Error();
|
|
1967
|
+
transferables = [payload];
|
|
1968
|
+
}
|
|
1969
|
+
return {
|
|
1970
|
+
[$transferable]: true,
|
|
1971
|
+
send: payload,
|
|
1972
|
+
transferables
|
|
1973
|
+
};
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
/////////////////////////////
|
|
1977
|
+
// Messages sent by master:
|
|
1978
|
+
var MasterMessageType;
|
|
1979
|
+
(function (MasterMessageType) {
|
|
1980
|
+
MasterMessageType["cancel"] = "cancel";
|
|
1981
|
+
MasterMessageType["run"] = "run";
|
|
1982
|
+
})(MasterMessageType || (MasterMessageType = {}));
|
|
1983
|
+
////////////////////////////
|
|
1984
|
+
// Messages sent by worker:
|
|
1985
|
+
var WorkerMessageType;
|
|
1986
|
+
(function (WorkerMessageType) {
|
|
1987
|
+
WorkerMessageType["error"] = "error";
|
|
1988
|
+
WorkerMessageType["init"] = "init";
|
|
1989
|
+
WorkerMessageType["result"] = "result";
|
|
1990
|
+
WorkerMessageType["running"] = "running";
|
|
1991
|
+
WorkerMessageType["uncaughtError"] = "uncaughtError";
|
|
1992
|
+
})(WorkerMessageType || (WorkerMessageType = {}));
|
|
1993
|
+
|
|
1994
|
+
/*
|
|
1995
|
+
* This source file contains the code for proxying calls in the master thread to calls in the workers
|
|
1996
|
+
* by `.postMessage()`-ing.
|
|
1997
|
+
*
|
|
1998
|
+
* Keep in mind that this code can make or break the program's performance! Need to optimize more…
|
|
1999
|
+
*/
|
|
2000
|
+
const debugMessages$1 = browser("threads:master:messages");
|
|
2001
|
+
let nextJobUID = 1;
|
|
2002
|
+
const dedupe = (array) => Array.from(new Set(array));
|
|
2003
|
+
const isJobErrorMessage = (data) => data && data.type === WorkerMessageType.error;
|
|
2004
|
+
const isJobResultMessage = (data) => data && data.type === WorkerMessageType.result;
|
|
2005
|
+
const isJobStartMessage = (data) => data && data.type === WorkerMessageType.running;
|
|
2006
|
+
function createObservableForJob(worker, jobUID) {
|
|
2007
|
+
return new Observable(observer => {
|
|
2008
|
+
let asyncType;
|
|
2009
|
+
const messageHandler = ((event) => {
|
|
2010
|
+
debugMessages$1("Message from worker:", event.data);
|
|
2011
|
+
if (!event.data || event.data.uid !== jobUID)
|
|
2012
|
+
return;
|
|
2013
|
+
if (isJobStartMessage(event.data)) {
|
|
2014
|
+
asyncType = event.data.resultType;
|
|
2015
|
+
}
|
|
2016
|
+
else if (isJobResultMessage(event.data)) {
|
|
2017
|
+
if (asyncType === "promise") {
|
|
2018
|
+
if (typeof event.data.payload !== "undefined") {
|
|
2019
|
+
observer.next(deserialize(event.data.payload));
|
|
2020
|
+
}
|
|
2021
|
+
observer.complete();
|
|
2022
|
+
worker.removeEventListener("message", messageHandler);
|
|
2023
|
+
}
|
|
2024
|
+
else {
|
|
2025
|
+
if (event.data.payload) {
|
|
2026
|
+
observer.next(deserialize(event.data.payload));
|
|
2027
|
+
}
|
|
2028
|
+
if (event.data.complete) {
|
|
2029
|
+
observer.complete();
|
|
2030
|
+
worker.removeEventListener("message", messageHandler);
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
else if (isJobErrorMessage(event.data)) {
|
|
2035
|
+
const error = deserialize(event.data.error);
|
|
2036
|
+
if (asyncType === "promise" || !asyncType) {
|
|
2037
|
+
observer.error(error);
|
|
2038
|
+
}
|
|
2039
|
+
else {
|
|
2040
|
+
observer.error(error);
|
|
2041
|
+
}
|
|
2042
|
+
worker.removeEventListener("message", messageHandler);
|
|
2043
|
+
}
|
|
2044
|
+
});
|
|
2045
|
+
worker.addEventListener("message", messageHandler);
|
|
2046
|
+
return () => {
|
|
2047
|
+
if (asyncType === "observable" || !asyncType) {
|
|
2048
|
+
const cancelMessage = {
|
|
2049
|
+
type: MasterMessageType.cancel,
|
|
2050
|
+
uid: jobUID
|
|
2051
|
+
};
|
|
2052
|
+
worker.postMessage(cancelMessage);
|
|
2053
|
+
}
|
|
2054
|
+
worker.removeEventListener("message", messageHandler);
|
|
2055
|
+
};
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
function prepareArguments(rawArgs) {
|
|
2059
|
+
if (rawArgs.length === 0) {
|
|
2060
|
+
// Exit early if possible
|
|
2061
|
+
return {
|
|
2062
|
+
args: [],
|
|
2063
|
+
transferables: []
|
|
2064
|
+
};
|
|
2065
|
+
}
|
|
2066
|
+
const args = [];
|
|
2067
|
+
const transferables = [];
|
|
2068
|
+
for (const arg of rawArgs) {
|
|
2069
|
+
if (isTransferDescriptor(arg)) {
|
|
2070
|
+
args.push(serialize(arg.send));
|
|
2071
|
+
transferables.push(...arg.transferables);
|
|
2072
|
+
}
|
|
2073
|
+
else {
|
|
2074
|
+
args.push(serialize(arg));
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
return {
|
|
2078
|
+
args,
|
|
2079
|
+
transferables: transferables.length === 0 ? transferables : dedupe(transferables)
|
|
2080
|
+
};
|
|
2081
|
+
}
|
|
2082
|
+
function createProxyFunction(worker, method) {
|
|
2083
|
+
return ((...rawArgs) => {
|
|
2084
|
+
const uid = nextJobUID++;
|
|
2085
|
+
const { args, transferables } = prepareArguments(rawArgs);
|
|
2086
|
+
const runMessage = {
|
|
2087
|
+
type: MasterMessageType.run,
|
|
2088
|
+
uid,
|
|
2089
|
+
method,
|
|
2090
|
+
args
|
|
2091
|
+
};
|
|
2092
|
+
debugMessages$1("Sending command to run function to worker:", runMessage);
|
|
2093
|
+
try {
|
|
2094
|
+
worker.postMessage(runMessage, transferables);
|
|
2095
|
+
}
|
|
2096
|
+
catch (error) {
|
|
2097
|
+
return ObservablePromise.from(Promise.reject(error));
|
|
2098
|
+
}
|
|
2099
|
+
return ObservablePromise.from(multicast(createObservableForJob(worker, uid)));
|
|
2100
|
+
});
|
|
2101
|
+
}
|
|
2102
|
+
function createProxyModule(worker, methodNames) {
|
|
2103
|
+
const proxy = {};
|
|
2104
|
+
for (const methodName of methodNames) {
|
|
2105
|
+
proxy[methodName] = createProxyFunction(worker, methodName);
|
|
2106
|
+
}
|
|
2107
|
+
return proxy;
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2111
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2112
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
2113
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
2114
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
2115
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
2116
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2117
|
+
});
|
|
2118
|
+
};
|
|
2119
|
+
const debugMessages = browser("threads:master:messages");
|
|
2120
|
+
const debugSpawn = browser("threads:master:spawn");
|
|
2121
|
+
const debugThreadUtils = browser("threads:master:thread-utils");
|
|
2122
|
+
const isInitMessage = (data) => data && data.type === "init";
|
|
2123
|
+
const isUncaughtErrorMessage = (data) => data && data.type === "uncaughtError";
|
|
2124
|
+
const initMessageTimeout = typeof process !== "undefined" && process.env.THREADS_WORKER_INIT_TIMEOUT
|
|
2125
|
+
? Number.parseInt(process.env.THREADS_WORKER_INIT_TIMEOUT, 10)
|
|
2126
|
+
: 10000;
|
|
2127
|
+
function withTimeout(promise, timeoutInMs, errorMessage) {
|
|
2128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2129
|
+
let timeoutHandle;
|
|
2130
|
+
const timeout = new Promise((resolve, reject) => {
|
|
2131
|
+
timeoutHandle = setTimeout(() => reject(Error(errorMessage)), timeoutInMs);
|
|
2132
|
+
});
|
|
2133
|
+
const result = yield Promise.race([
|
|
2134
|
+
promise,
|
|
2135
|
+
timeout
|
|
2136
|
+
]);
|
|
2137
|
+
clearTimeout(timeoutHandle);
|
|
2138
|
+
return result;
|
|
2139
|
+
});
|
|
2140
|
+
}
|
|
2141
|
+
function receiveInitMessage(worker) {
|
|
2142
|
+
return new Promise((resolve, reject) => {
|
|
2143
|
+
const messageHandler = ((event) => {
|
|
2144
|
+
debugMessages("Message from worker before finishing initialization:", event.data);
|
|
2145
|
+
if (isInitMessage(event.data)) {
|
|
2146
|
+
worker.removeEventListener("message", messageHandler);
|
|
2147
|
+
resolve(event.data);
|
|
2148
|
+
}
|
|
2149
|
+
else if (isUncaughtErrorMessage(event.data)) {
|
|
2150
|
+
worker.removeEventListener("message", messageHandler);
|
|
2151
|
+
reject(deserialize(event.data.error));
|
|
2152
|
+
}
|
|
2153
|
+
});
|
|
2154
|
+
worker.addEventListener("message", messageHandler);
|
|
2155
|
+
});
|
|
2156
|
+
}
|
|
2157
|
+
function createEventObservable(worker, workerTermination) {
|
|
2158
|
+
return new Observable(observer => {
|
|
2159
|
+
const messageHandler = ((messageEvent) => {
|
|
2160
|
+
const workerEvent = {
|
|
2161
|
+
type: WorkerEventType.message,
|
|
2162
|
+
data: messageEvent.data
|
|
2163
|
+
};
|
|
2164
|
+
observer.next(workerEvent);
|
|
2165
|
+
});
|
|
2166
|
+
const rejectionHandler = ((errorEvent) => {
|
|
2167
|
+
debugThreadUtils("Unhandled promise rejection event in thread:", errorEvent);
|
|
2168
|
+
const workerEvent = {
|
|
2169
|
+
type: WorkerEventType.internalError,
|
|
2170
|
+
error: Error(errorEvent.reason)
|
|
2171
|
+
};
|
|
2172
|
+
observer.next(workerEvent);
|
|
2173
|
+
});
|
|
2174
|
+
worker.addEventListener("message", messageHandler);
|
|
2175
|
+
worker.addEventListener("unhandledrejection", rejectionHandler);
|
|
2176
|
+
workerTermination.then(() => {
|
|
2177
|
+
const terminationEvent = {
|
|
2178
|
+
type: WorkerEventType.termination
|
|
2179
|
+
};
|
|
2180
|
+
worker.removeEventListener("message", messageHandler);
|
|
2181
|
+
worker.removeEventListener("unhandledrejection", rejectionHandler);
|
|
2182
|
+
observer.next(terminationEvent);
|
|
2183
|
+
observer.complete();
|
|
2184
|
+
});
|
|
2185
|
+
});
|
|
2186
|
+
}
|
|
2187
|
+
function createTerminator(worker) {
|
|
2188
|
+
const [termination, resolver] = createPromiseWithResolver();
|
|
2189
|
+
const terminate = () => __awaiter(this, void 0, void 0, function* () {
|
|
2190
|
+
debugThreadUtils("Terminating worker");
|
|
2191
|
+
// Newer versions of worker_threads workers return a promise
|
|
2192
|
+
yield worker.terminate();
|
|
2193
|
+
resolver();
|
|
2194
|
+
});
|
|
2195
|
+
return { terminate, termination };
|
|
2196
|
+
}
|
|
2197
|
+
function setPrivateThreadProps(raw, worker, workerEvents, terminate) {
|
|
2198
|
+
const workerErrors = workerEvents
|
|
2199
|
+
.filter(event => event.type === WorkerEventType.internalError)
|
|
2200
|
+
.map(errorEvent => errorEvent.error);
|
|
2201
|
+
// tslint:disable-next-line prefer-object-spread
|
|
2202
|
+
return Object.assign(raw, {
|
|
2203
|
+
[$errors]: workerErrors,
|
|
2204
|
+
[$events]: workerEvents,
|
|
2205
|
+
[$terminate]: terminate,
|
|
2206
|
+
[$worker]: worker
|
|
2207
|
+
});
|
|
2208
|
+
}
|
|
2209
|
+
/**
|
|
2210
|
+
* Spawn a new thread. Takes a fresh worker instance, wraps it in a thin
|
|
2211
|
+
* abstraction layer to provide the transparent API and verifies that
|
|
2212
|
+
* the worker has initialized successfully.
|
|
2213
|
+
*
|
|
2214
|
+
* @param worker Instance of `Worker`. Either a web worker, `worker_threads` worker or `tiny-worker` worker.
|
|
2215
|
+
* @param [options]
|
|
2216
|
+
* @param [options.timeout] Init message timeout. Default: 10000 or set by environment variable.
|
|
2217
|
+
*/
|
|
2218
|
+
function spawn(worker, options) {
|
|
2219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2220
|
+
debugSpawn("Initializing new thread");
|
|
2221
|
+
const timeout = options && options.timeout ? options.timeout : initMessageTimeout;
|
|
2222
|
+
const initMessage = yield withTimeout(receiveInitMessage(worker), timeout, `Timeout: Did not receive an init message from worker after ${timeout}ms. Make sure the worker calls expose().`);
|
|
2223
|
+
const exposed = initMessage.exposed;
|
|
2224
|
+
const { termination, terminate } = createTerminator(worker);
|
|
2225
|
+
const events = createEventObservable(worker, termination);
|
|
2226
|
+
if (exposed.type === "function") {
|
|
2227
|
+
const proxy = createProxyFunction(worker);
|
|
2228
|
+
return setPrivateThreadProps(proxy, worker, events, terminate);
|
|
2229
|
+
}
|
|
2230
|
+
else if (exposed.type === "module") {
|
|
2231
|
+
const proxy = createProxyModule(worker, exposed.methods);
|
|
2232
|
+
return setPrivateThreadProps(proxy, worker, events, terminate);
|
|
2233
|
+
}
|
|
2234
|
+
else {
|
|
2235
|
+
const type = exposed.type;
|
|
2236
|
+
throw Error(`Worker init message states unexpected type of expose(): ${type}`);
|
|
2237
|
+
}
|
|
2238
|
+
});
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
/** Separate class to spawn workers from source code blobs or strings. */
|
|
2242
|
+
const BlobWorker = getWorkerImplementation().blob;
|
|
2243
|
+
/** Worker implementation. Either web worker or a node.js Worker class. */
|
|
2244
|
+
getWorkerImplementation().default;
|
|
2245
|
+
|
|
2246
|
+
var TerminateController = /** @class */ (function () {
|
|
2247
|
+
function TerminateController() {
|
|
2248
|
+
this.threads = [];
|
|
2249
|
+
this.pools = [];
|
|
2250
|
+
}
|
|
2251
|
+
TerminateController.prototype.addThread = function (thread) {
|
|
2252
|
+
this.threads.push(thread);
|
|
2253
|
+
};
|
|
2254
|
+
TerminateController.prototype.addPool = function (pool) {
|
|
2255
|
+
this.pools.push(pool);
|
|
2256
|
+
};
|
|
2257
|
+
TerminateController.prototype.terminate = function (force) {
|
|
2258
|
+
if (force === void 0) { force = false; }
|
|
2259
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
2260
|
+
return __generator(this, function (_a) {
|
|
2261
|
+
switch (_a.label) {
|
|
2262
|
+
case 0: return [4 /*yield*/, Promise.all(__spreadArray(__spreadArray([], this.threads.map(function (t) { return Thread.terminate(t); })), this.pools.map(function (p) { return p.terminate(force); })))];
|
|
2263
|
+
case 1:
|
|
2264
|
+
_a.sent();
|
|
2265
|
+
return [2 /*return*/];
|
|
2266
|
+
}
|
|
2267
|
+
});
|
|
2268
|
+
});
|
|
2269
|
+
};
|
|
2270
|
+
return TerminateController;
|
|
2271
|
+
}());
|
|
2272
|
+
|
|
2273
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2274
|
+
function getGlobal() {
|
|
2275
|
+
if (typeof globalThis !== 'undefined') {
|
|
2276
|
+
return globalThis;
|
|
2277
|
+
}
|
|
2278
|
+
else if (typeof self !== 'undefined') {
|
|
2279
|
+
return self;
|
|
2280
|
+
}
|
|
2281
|
+
else if (typeof window !== 'undefined') {
|
|
2282
|
+
return window;
|
|
2283
|
+
}
|
|
2284
|
+
else if (typeof global !== 'undefined') {
|
|
2285
|
+
return global;
|
|
2286
|
+
}
|
|
2287
|
+
throw new Error('unable to locate global object');
|
|
2288
|
+
}
|
|
2289
|
+
var globalThis$1 = getGlobal();
|
|
2290
|
+
|
|
2291
|
+
function instanceOf(obj, className) {
|
|
2292
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2293
|
+
var Type = globalThis$1[className];
|
|
2294
|
+
return Type != null && obj instanceof Type;
|
|
2295
|
+
}
|
|
2296
|
+
function isTransferable(obj) {
|
|
2297
|
+
return (instanceOf(obj, 'ArrayBuffer') ||
|
|
2298
|
+
instanceOf(obj, 'MessagePort') ||
|
|
2299
|
+
instanceOf(obj, 'ImageBitmap') ||
|
|
2300
|
+
instanceOf(obj, 'OffscreenCanvas'));
|
|
2301
|
+
}
|
|
2302
|
+
function isTypedArray(obj) {
|
|
2303
|
+
return (instanceOf(obj, 'Int8Array') ||
|
|
2304
|
+
instanceOf(obj, 'Uint8Array') ||
|
|
2305
|
+
instanceOf(obj, 'Uint8ClampedArray') ||
|
|
2306
|
+
instanceOf(obj, 'Int16Array') ||
|
|
2307
|
+
instanceOf(obj, 'Uint16Array') ||
|
|
2308
|
+
instanceOf(obj, 'Int32Array') ||
|
|
2309
|
+
instanceOf(obj, 'Uint32Array') ||
|
|
2310
|
+
instanceOf(obj, 'Float32Array') ||
|
|
2311
|
+
instanceOf(obj, 'Float64Array') ||
|
|
2312
|
+
instanceOf(obj, 'BigInt64Array') ||
|
|
2313
|
+
instanceOf(obj, 'BigUint64Array'));
|
|
2314
|
+
}
|
|
2315
|
+
/**
|
|
2316
|
+
* A function that will recursively inspect an object and return a Threads
|
|
2317
|
+
* `Transfer` that contains all the `Transferable`s in the given object.
|
|
2318
|
+
*
|
|
2319
|
+
* @param obj The object to make transferable.
|
|
2320
|
+
* @returns A `Transfer` from Threads.
|
|
2321
|
+
*/
|
|
2322
|
+
function makeTransferable(obj) {
|
|
2323
|
+
if (isTransferable(obj)) {
|
|
2324
|
+
return Transfer(obj);
|
|
2325
|
+
}
|
|
2326
|
+
else if (obj != null && typeof obj === 'object') {
|
|
2327
|
+
var transferables = findTransferables(obj);
|
|
2328
|
+
return Transfer(obj, transferables);
|
|
2329
|
+
}
|
|
2330
|
+
else {
|
|
2331
|
+
return obj;
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
function findTransferables(obj) {
|
|
2335
|
+
if (isTransferable(obj)) {
|
|
2336
|
+
return [obj];
|
|
2337
|
+
}
|
|
2338
|
+
else if (typeof obj === 'object') {
|
|
2339
|
+
if (Array.isArray(obj)) {
|
|
2340
|
+
var result_1 = [];
|
|
2341
|
+
obj.forEach(function (o) { return result_1.push.apply(result_1, findTransferables(o)); });
|
|
2342
|
+
return result_1;
|
|
2343
|
+
}
|
|
2344
|
+
else if (isTypedArray(obj)) {
|
|
2345
|
+
return [obj.buffer];
|
|
2346
|
+
}
|
|
2347
|
+
else if (obj != null) {
|
|
2348
|
+
return Object.values(obj).reduce(function (acc, value) {
|
|
2349
|
+
acc.push.apply(acc, findTransferables(value));
|
|
2350
|
+
return acc;
|
|
2351
|
+
}, []);
|
|
2352
|
+
}
|
|
2353
|
+
else {
|
|
2354
|
+
return [];
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
else {
|
|
2358
|
+
return [];
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
const workerName = "png-decoder-worker.js";
|
|
2363
|
+
const workerText = `!function(){"use strict";
|
|
2364
|
+
/*! *****************************************************************************
|
|
2365
|
+
Copyright (c) Microsoft Corporation.
|
|
2366
|
+
|
|
2367
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
2368
|
+
purpose with or without fee is hereby granted.
|
|
2369
|
+
|
|
2370
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
2371
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
2372
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
2373
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
2374
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
2375
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
2376
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
2377
|
+
***************************************************************************** */function t(t,e,n,i){return new(n||(n=Promise))((function(r,a){function s(t){try{l(i.next(t))}catch(t){a(t)}}function o(t){try{l(i.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,o)}l((i=i.apply(t,e||[])).next())}))}function e(t,e){var n,i,r,a,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return a={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function o(a){return function(o){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&a[0]?i.return:a[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,a[1])).done)return r;switch(i=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,i=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){s.label=a[1];break}if(6===a[0]&&s.label<r[1]){s.label=r[1],r=a;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(a);break}r[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],i=0}finally{n=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,o])}}}const n={deserialize:t=>Object.assign(Error(t.message),{name:t.name,stack:t.stack}),serialize:t=>({__error_marker:"$$error",message:t.message,name:t.name,stack:t.stack})};let i={deserialize(t){return(e=t)&&"object"==typeof e&&"__error_marker"in e&&"$$error"===e.__error_marker?n.deserialize(t):t;var e},serialize:t=>t instanceof Error?n.serialize(t):t};function r(t){return i.deserialize(t)}function a(t){return i.serialize(t)}const s=Symbol("thread.transferable");function o(t,e){if(!e){if(!(n=t)||"object"!=typeof n)throw Error();e=[t]}var n;return{[s]:!0,send:t,transferables:e}}var l,h;!function(t){t.cancel="cancel",t.run="run"}(l||(l={})),function(t){t.error="error",t.init="init",t.result="result",t.running="running",t.uncaughtError="uncaughtError"}(h||(h={}));var d=function(){const t="undefined"!=typeof self&&"undefined"!=typeof Window&&self instanceof Window;return!("undefined"==typeof self||!self.postMessage||t)},f=function(t,e){self.postMessage(t,e)},c=function(t){const e=e=>{t(e.data)};return self.addEventListener("message",e),()=>{self.removeEventListener("message",e)}},u=function(t,e,n,i){return new(n||(n=Promise))((function(r,a){function s(t){try{l(i.next(t))}catch(t){a(t)}}function o(t){try{l(i.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,o)}l((i=i.apply(t,e||[])).next())}))};let _=!1;const p=new Map,w=t=>t&&t.type===l.run,b=t=>{return!!(e=t)&&("symbol"==typeof Symbol.observable&&"function"==typeof e[Symbol.observable]?e===e[Symbol.observable]():"function"==typeof e["@@observable"]&&e===e["@@observable"]())||function(t){return t&&"object"==typeof t&&"function"==typeof t.subscribe}(t);var e};function g(t){return function(t){return t&&"object"==typeof t&&t[s]}(t)?{payload:t.send,transferables:t.transferables}:{payload:t,transferables:void 0}}function m(t,e){const{payload:n,transferables:i}=g(e),r={type:h.error,uid:t,error:a(n)};f(r,i)}function y(t,e,n){const{payload:i,transferables:r}=g(n),a={type:h.result,uid:t,complete:!!e||void 0,payload:i};f(a,r)}function k(t){try{const e={type:h.uncaughtError,error:a(t)};f(e)}catch(e){console.error("Not reporting uncaught error back to master thread as it occured while reporting an uncaught error already.Latest error:",e,"Original error:",t)}}function v(t,e,n){return u(this,void 0,void 0,(function*(){let i;try{i=e(...n)}catch(e){return m(t,e)}const r=b(i)?"observable":"promise";if(function(t,e){const n={type:h.running,uid:t,resultType:e};f(n)}(t,r),b(i)){const e=i.subscribe((e=>y(t,!1,a(e))),(e=>{m(t,a(e)),p.delete(t)}),(()=>{y(t,!0),p.delete(t)}));p.set(t,e)}else try{const e=yield i;y(t,!0,a(e))}catch(e){m(t,a(e))}}))}function E(t){if(!d())throw Error("expose() called in the master thread.");if(_)throw Error("expose() called more than once. This is not possible. Pass an object to expose() if you want to expose multiple functions.");if(_=!0,"function"==typeof t)c((e=>{w(e)&&!e.method&&v(e.uid,t,e.args.map(r))})),function(){const t={type:h.init,exposed:{type:"function"}};f(t)}();else{if("object"!=typeof t||!t)throw Error(\`Invalid argument passed to expose(). Expected a function or an object, got: \${t}\`);c((e=>{w(e)&&e.method&&v(e.uid,t[e.method],e.args.map(r))}));!function(t){const e={type:h.init,exposed:{type:"module",methods:t}};f(e)}(Object.keys(t).filter((e=>"function"==typeof t[e])))}c((t=>{if((e=t)&&e.type===l.cancel){const e=t.uid,n=p.get(e);n&&(n.unsubscribe(),p.delete(e))}var e}))}"undefined"!=typeof self&&"function"==typeof self.addEventListener&&d()&&(self.addEventListener("error",(t=>{setTimeout((()=>k(t.error||t)),250)})),self.addEventListener("unhandledrejection",(t=>{const e=t.reason;e&&"string"==typeof e.message&&setTimeout((()=>k(e)),250)}))),"undefined"!=typeof process&&"function"==typeof process.on&&d()&&(process.on("uncaughtException",(t=>{setTimeout((()=>k(t)),250)})),process.on("unhandledRejection",(t=>{t&&"string"==typeof t.message&&setTimeout((()=>k(t)),250)})));var A=function(){if("undefined"!=typeof globalThis)return globalThis;if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")}();function x(t,e){var n=A[e];return null!=n&&t instanceof n}function U(t){return x(t,"ArrayBuffer")||x(t,"MessagePort")||x(t,"ImageBitmap")||x(t,"OffscreenCanvas")}function z(t){return U(t)?o(t):null!=t&&"object"==typeof t?o(t,R(t)):t}function R(t){if(U(t))return[t];if("object"==typeof t){if(Array.isArray(t)){var e=[];return t.forEach((function(t){return e.push.apply(e,R(t))})),e}return function(t){return x(t,"Int8Array")||x(t,"Uint8Array")||x(t,"Uint8ClampedArray")||x(t,"Int16Array")||x(t,"Uint16Array")||x(t,"Int32Array")||x(t,"Uint32Array")||x(t,"Float32Array")||x(t,"Float64Array")||x(t,"BigInt64Array")||x(t,"BigUint64Array")}(t)?[t.buffer]:null!=t?Object.values(t).reduce((function(t,e){return t.push.apply(t,R(e)),t}),[]):[]}return[]}!function(t){if(t.TextEncoder&&t.TextDecoder)return!1;function e(t="utf-8"){if("utf-8"!==t)throw new RangeError(\`Failed to construct 'TextEncoder': The encoding label provided ('\${t}') is invalid.\`)}function n(t="utf-8",e={fatal:!1}){if("utf-8"!==t)throw new RangeError(\`Failed to construct 'TextDecoder': The encoding label provided ('\${t}') is invalid.\`);if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t,e={stream:!1}){if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");let n=0;const i=t.length;let r=0,a=Math.max(32,i+(i>>1)+7),s=new Uint8Array(a>>3<<3);for(;n<i;){let e=t.charCodeAt(n++);if(e>=55296&&e<=56319){if(n<i){const i=t.charCodeAt(n);56320==(64512&i)&&(++n,e=((1023&e)<<10)+(1023&i)+65536)}if(e>=55296&&e<=56319)continue}if(r+4>s.length){a+=8,a*=1+n/t.length*2,a=a>>3<<3;const e=new Uint8Array(a);e.set(s),s=e}if(0!=(4294967168&e)){if(0==(4294965248&e))s[r++]=e>>6&31|192;else if(0==(4294901760&e))s[r++]=e>>12&15|224,s[r++]=e>>6&63|128;else{if(0!=(4292870144&e))continue;s[r++]=e>>18&7|240,s[r++]=e>>12&63|128,s[r++]=e>>6&63|128}s[r++]=63&e|128}else s[r++]=e}return s.slice(0,r)},Object.defineProperty(n.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(n.prototype,"fatal",{value:!1}),Object.defineProperty(n.prototype,"ignoreBOM",{value:!1}),n.prototype.decode=function(t,e={stream:!1}){if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");const n=new Uint8Array(t);let i=0;const r=n.length,a=[];for(;i<r;){const t=n[i++];if(0===t)break;if(0==(128&t))a.push(t);else if(192==(224&t)){const e=63&n[i++];a.push((31&t)<<6|e)}else if(224==(240&t)){const e=63&n[i++],r=63&n[i++];a.push((31&t)<<12|e<<6|r)}else if(240==(248&t)){let e=(7&t)<<18|(63&n[i++])<<12|(63&n[i++])<<6|63&n[i++];e>65535&&(e-=65536,a.push(e>>>10&1023|55296),e=56320|1023&e),a.push(e)}}return String.fromCharCode.apply(null,a)},t.TextEncoder=e,t.TextDecoder=n}("undefined"!=typeof window?window:"undefined"!=typeof self?self:void 0);const L=new TextDecoder("utf-8");const T=new TextEncoder;class N{constructor(t=8192,e={}){let n=!1;"number"==typeof t?t=new ArrayBuffer(t):(n=!0,this.lastWrittenByte=t.byteLength);const i=e.offset?e.offset>>>0:0,r=t.byteLength-i;let a=i;(ArrayBuffer.isView(t)||t instanceof N)&&(t.byteLength!==t.buffer.byteLength&&(a=t.byteOffset+i),t=t.buffer),this.lastWrittenByte=n?r:0,this.buffer=t,this.length=r,this.byteLength=r,this.byteOffset=a,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,a,r),this._mark=0,this._marks=[]}available(t=1){return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(t=1){return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(t=1){if(!this.available(t)){const e=2*(this.offset+t),n=new Uint8Array(e);n.set(new Uint8Array(this.buffer)),this.buffer=n.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(t=1){const e=new Uint8Array(t);for(let n=0;n<t;n++)e[n]=this.readByte();return e}readInt16(){const t=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,t}readUint16(){const t=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,t}readInt32(){const t=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,t}readUint32(){const t=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat32(){const t=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat64(){const t=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,t}readChar(){return String.fromCharCode(this.readInt8())}readChars(t=1){let e="";for(let n=0;n<t;n++)e+=this.readChar();return e}readUtf8(t=1){return e=this.readBytes(t),L.decode(e);var e}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let e=0;e<t.length;e++)this._data.setUint8(this.offset++,t[e]);return this._updateLastWrittenByte(),this}writeInt16(t){return this.ensureAvailable(2),this._data.setInt16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(t){return this.ensureAvailable(2),this._data.setUint16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(t){return this.ensureAvailable(4),this._data.setInt32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(t){return this.ensureAvailable(4),this._data.setUint32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(t){return this.ensureAvailable(4),this._data.setFloat32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(t){return this.ensureAvailable(8),this._data.setFloat64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(t){return this.writeUint8(t.charCodeAt(0))}writeChars(t){for(let e=0;e<t.length;e++)this.writeUint8(t.charCodeAt(e));return this}writeUtf8(t){return this.writeBytes(function(t){return T.encode(t)}(t))}toArray(){return new Uint8Array(this.buffer,this.byteOffset,this.lastWrittenByte)}_updateLastWrittenByte(){this.offset>this.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}
|
|
2378
|
+
/*! pako 2.0.4 https://github.com/nodeca/pako @license (MIT AND Zlib) */function O(t){let e=t.length;for(;--e>=0;)t[e]=0}const S=256,C=286,D=30,I=15,B=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),Z=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),F=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),M=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),P=new Array(576);O(P);const H=new Array(60);O(H);const j=new Array(512);O(j);const W=new Array(256);O(W);const K=new Array(29);O(K);const $=new Array(D);function Y(t,e,n,i,r){this.static_tree=t,this.extra_bits=e,this.extra_base=n,this.elems=i,this.max_length=r,this.has_stree=t&&t.length}let G,X,V;function q(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}O($);const J=t=>t<256?j[t]:j[256+(t>>>7)],Q=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},tt=(t,e,n)=>{t.bi_valid>16-n?(t.bi_buf|=e<<t.bi_valid&65535,Q(t,t.bi_buf),t.bi_buf=e>>16-t.bi_valid,t.bi_valid+=n-16):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=n)},et=(t,e,n)=>{tt(t,n[2*e],n[2*e+1])},nt=(t,e)=>{let n=0;do{n|=1&t,t>>>=1,n<<=1}while(--e>0);return n>>>1},it=(t,e,n)=>{const i=new Array(16);let r,a,s=0;for(r=1;r<=I;r++)i[r]=s=s+n[r-1]<<1;for(a=0;a<=e;a++){let e=t[2*a+1];0!==e&&(t[2*a]=nt(i[e]++,e))}},rt=t=>{let e;for(e=0;e<C;e++)t.dyn_ltree[2*e]=0;for(e=0;e<D;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},at=t=>{t.bi_valid>8?Q(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},st=(t,e,n,i)=>{const r=2*e,a=2*n;return t[r]<t[a]||t[r]===t[a]&&i[e]<=i[n]},ot=(t,e,n)=>{const i=t.heap[n];let r=n<<1;for(;r<=t.heap_len&&(r<t.heap_len&&st(e,t.heap[r+1],t.heap[r],t.depth)&&r++,!st(e,i,t.heap[r],t.depth));)t.heap[n]=t.heap[r],n=r,r<<=1;t.heap[n]=i},lt=(t,e,n)=>{let i,r,a,s,o=0;if(0!==t.last_lit)do{i=t.pending_buf[t.d_buf+2*o]<<8|t.pending_buf[t.d_buf+2*o+1],r=t.pending_buf[t.l_buf+o],o++,0===i?et(t,r,e):(a=W[r],et(t,a+S+1,e),s=B[a],0!==s&&(r-=K[a],tt(t,r,s)),i--,a=J(i),et(t,a,n),s=Z[a],0!==s&&(i-=$[a],tt(t,i,s)))}while(o<t.last_lit);et(t,256,e)},ht=(t,e)=>{const n=e.dyn_tree,i=e.stat_desc.static_tree,r=e.stat_desc.has_stree,a=e.stat_desc.elems;let s,o,l,h=-1;for(t.heap_len=0,t.heap_max=573,s=0;s<a;s++)0!==n[2*s]?(t.heap[++t.heap_len]=h=s,t.depth[s]=0):n[2*s+1]=0;for(;t.heap_len<2;)l=t.heap[++t.heap_len]=h<2?++h:0,n[2*l]=1,t.depth[l]=0,t.opt_len--,r&&(t.static_len-=i[2*l+1]);for(e.max_code=h,s=t.heap_len>>1;s>=1;s--)ot(t,n,s);l=a;do{s=t.heap[1],t.heap[1]=t.heap[t.heap_len--],ot(t,n,1),o=t.heap[1],t.heap[--t.heap_max]=s,t.heap[--t.heap_max]=o,n[2*l]=n[2*s]+n[2*o],t.depth[l]=(t.depth[s]>=t.depth[o]?t.depth[s]:t.depth[o])+1,n[2*s+1]=n[2*o+1]=l,t.heap[1]=l++,ot(t,n,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const n=e.dyn_tree,i=e.max_code,r=e.stat_desc.static_tree,a=e.stat_desc.has_stree,s=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,l=e.stat_desc.max_length;let h,d,f,c,u,_,p=0;for(c=0;c<=I;c++)t.bl_count[c]=0;for(n[2*t.heap[t.heap_max]+1]=0,h=t.heap_max+1;h<573;h++)d=t.heap[h],c=n[2*n[2*d+1]+1]+1,c>l&&(c=l,p++),n[2*d+1]=c,d>i||(t.bl_count[c]++,u=0,d>=o&&(u=s[d-o]),_=n[2*d],t.opt_len+=_*(c+u),a&&(t.static_len+=_*(r[2*d+1]+u)));if(0!==p){do{for(c=l-1;0===t.bl_count[c];)c--;t.bl_count[c]--,t.bl_count[c+1]+=2,t.bl_count[l]--,p-=2}while(p>0);for(c=l;0!==c;c--)for(d=t.bl_count[c];0!==d;)f=t.heap[--h],f>i||(n[2*f+1]!==c&&(t.opt_len+=(c-n[2*f+1])*n[2*f],n[2*f+1]=c),d--)}})(t,e),it(n,h,t.bl_count)},dt=(t,e,n)=>{let i,r,a=-1,s=e[1],o=0,l=7,h=4;for(0===s&&(l=138,h=3),e[2*(n+1)+1]=65535,i=0;i<=n;i++)r=s,s=e[2*(i+1)+1],++o<l&&r===s||(o<h?t.bl_tree[2*r]+=o:0!==r?(r!==a&&t.bl_tree[2*r]++,t.bl_tree[32]++):o<=10?t.bl_tree[34]++:t.bl_tree[36]++,o=0,a=r,0===s?(l=138,h=3):r===s?(l=6,h=3):(l=7,h=4))},ft=(t,e,n)=>{let i,r,a=-1,s=e[1],o=0,l=7,h=4;for(0===s&&(l=138,h=3),i=0;i<=n;i++)if(r=s,s=e[2*(i+1)+1],!(++o<l&&r===s)){if(o<h)do{et(t,r,t.bl_tree)}while(0!=--o);else 0!==r?(r!==a&&(et(t,r,t.bl_tree),o--),et(t,16,t.bl_tree),tt(t,o-3,2)):o<=10?(et(t,17,t.bl_tree),tt(t,o-3,3)):(et(t,18,t.bl_tree),tt(t,o-11,7));o=0,a=r,0===s?(l=138,h=3):r===s?(l=6,h=3):(l=7,h=4)}};let ct=!1;const ut=(t,e,n,i)=>{tt(t,0+(i?1:0),3),((t,e,n,i)=>{at(t),i&&(Q(t,n),Q(t,~n)),t.pending_buf.set(t.window.subarray(e,e+n),t.pending),t.pending+=n})(t,e,n,!0)};var _t=(t,e,n,i)=>{let r,a,s=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,n=4093624447;for(e=0;e<=31;e++,n>>>=1)if(1&n&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<S;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),ht(t,t.l_desc),ht(t,t.d_desc),s=(t=>{let e;for(dt(t,t.dyn_ltree,t.l_desc.max_code),dt(t,t.dyn_dtree,t.d_desc.max_code),ht(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*M[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),r=t.opt_len+3+7>>>3,a=t.static_len+3+7>>>3,a<=r&&(r=a)):r=a=n+5,n+4<=r&&-1!==e?ut(t,e,n,i):4===t.strategy||a===r?(tt(t,2+(i?1:0),3),lt(t,P,H)):(tt(t,4+(i?1:0),3),((t,e,n,i)=>{let r;for(tt(t,e-257,5),tt(t,n-1,5),tt(t,i-4,4),r=0;r<i;r++)tt(t,t.bl_tree[2*M[r]+1],3);ft(t,t.dyn_ltree,e-1),ft(t,t.dyn_dtree,n-1)})(t,t.l_desc.max_code+1,t.d_desc.max_code+1,s+1),lt(t,t.dyn_ltree,t.dyn_dtree)),rt(t),i&&at(t)},pt={_tr_init:t=>{ct||((()=>{let t,e,n,i,r;const a=new Array(16);for(n=0,i=0;i<28;i++)for(K[i]=n,t=0;t<1<<B[i];t++)W[n++]=i;for(W[n-1]=i,r=0,i=0;i<16;i++)for($[i]=r,t=0;t<1<<Z[i];t++)j[r++]=i;for(r>>=7;i<D;i++)for($[i]=r<<7,t=0;t<1<<Z[i]-7;t++)j[256+r++]=i;for(e=0;e<=I;e++)a[e]=0;for(t=0;t<=143;)P[2*t+1]=8,t++,a[8]++;for(;t<=255;)P[2*t+1]=9,t++,a[9]++;for(;t<=279;)P[2*t+1]=7,t++,a[7]++;for(;t<=287;)P[2*t+1]=8,t++,a[8]++;for(it(P,287,a),t=0;t<D;t++)H[2*t+1]=5,H[2*t]=nt(t,5);G=new Y(P,B,257,C,I),X=new Y(H,Z,0,D,I),V=new Y(new Array(0),F,0,19,7)})(),ct=!0),t.l_desc=new q(t.dyn_ltree,G),t.d_desc=new q(t.dyn_dtree,X),t.bl_desc=new q(t.bl_tree,V),t.bi_buf=0,t.bi_valid=0,rt(t)},_tr_stored_block:ut,_tr_flush_block:_t,_tr_tally:(t,e,n)=>(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&n,t.last_lit++,0===e?t.dyn_ltree[2*n]++:(t.matches++,e--,t.dyn_ltree[2*(W[n]+S+1)]++,t.dyn_dtree[2*J(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{tt(t,2,3),et(t,256,P),(t=>{16===t.bi_valid?(Q(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}};var wt=(t,e,n,i)=>{let r=65535&t|0,a=t>>>16&65535|0,s=0;for(;0!==n;){s=n>2e3?2e3:n,n-=s;do{r=r+e[i++]|0,a=a+r|0}while(--s);r%=65521,a%=65521}return r|a<<16|0};const bt=new Uint32Array((()=>{let t,e=[];for(var n=0;n<256;n++){t=n;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;e[n]=t}return e})());var gt=(t,e,n,i)=>{const r=bt,a=i+n;t^=-1;for(let n=i;n<a;n++)t=t>>>8^r[255&(t^e[n])];return-1^t},mt={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},yt={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:kt,_tr_stored_block:vt,_tr_flush_block:Et,_tr_tally:At,_tr_align:xt}=pt,{Z_NO_FLUSH:Ut,Z_PARTIAL_FLUSH:zt,Z_FULL_FLUSH:Rt,Z_FINISH:Lt,Z_BLOCK:Tt,Z_OK:Nt,Z_STREAM_END:Ot,Z_STREAM_ERROR:St,Z_DATA_ERROR:Ct,Z_BUF_ERROR:Dt,Z_DEFAULT_COMPRESSION:It,Z_FILTERED:Bt,Z_HUFFMAN_ONLY:Zt,Z_RLE:Ft,Z_FIXED:Mt,Z_DEFAULT_STRATEGY:Pt,Z_UNKNOWN:Ht,Z_DEFLATED:jt}=yt,Wt=258,Kt=262,$t=103,Yt=113,Gt=666,Xt=(t,e)=>(t.msg=mt[e],e),Vt=t=>(t<<1)-(t>4?9:0),qt=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let Jt=(t,e,n)=>(e<<t.hash_shift^n)&t.hash_mask;const Qt=t=>{const e=t.state;let n=e.pending;n>t.avail_out&&(n=t.avail_out),0!==n&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+n),t.next_out),t.next_out+=n,e.pending_out+=n,t.total_out+=n,t.avail_out-=n,e.pending-=n,0===e.pending&&(e.pending_out=0))},te=(t,e)=>{Et(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,Qt(t.strm)},ee=(t,e)=>{t.pending_buf[t.pending++]=e},ne=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},ie=(t,e,n,i)=>{let r=t.avail_in;return r>i&&(r=i),0===r?0:(t.avail_in-=r,e.set(t.input.subarray(t.next_in,t.next_in+r),n),1===t.state.wrap?t.adler=wt(t.adler,e,r,n):2===t.state.wrap&&(t.adler=gt(t.adler,e,r,n)),t.next_in+=r,t.total_in+=r,r)},re=(t,e)=>{let n,i,r=t.max_chain_length,a=t.strstart,s=t.prev_length,o=t.nice_match;const l=t.strstart>t.w_size-Kt?t.strstart-(t.w_size-Kt):0,h=t.window,d=t.w_mask,f=t.prev,c=t.strstart+Wt;let u=h[a+s-1],_=h[a+s];t.prev_length>=t.good_match&&(r>>=2),o>t.lookahead&&(o=t.lookahead);do{if(n=e,h[n+s]===_&&h[n+s-1]===u&&h[n]===h[a]&&h[++n]===h[a+1]){a+=2,n++;do{}while(h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&a<c);if(i=Wt-(c-a),a=c-Wt,i>s){if(t.match_start=e,s=i,i>=o)break;u=h[a+s-1],_=h[a+s]}}}while((e=f[e&d])>l&&0!=--r);return s<=t.lookahead?s:t.lookahead},ae=t=>{const e=t.w_size;let n,i,r,a,s;do{if(a=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-Kt)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,i=t.hash_size,n=i;do{r=t.head[--n],t.head[n]=r>=e?r-e:0}while(--i);i=e,n=i;do{r=t.prev[--n],t.prev[n]=r>=e?r-e:0}while(--i);a+=e}if(0===t.strm.avail_in)break;if(i=ie(t.strm,t.window,t.strstart+t.lookahead,a),t.lookahead+=i,t.lookahead+t.insert>=3)for(s=t.strstart-t.insert,t.ins_h=t.window[s],t.ins_h=Jt(t,t.ins_h,t.window[s+1]);t.insert&&(t.ins_h=Jt(t,t.ins_h,t.window[s+3-1]),t.prev[s&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=s,s++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<Kt&&0!==t.strm.avail_in)},se=(t,e)=>{let n,i;for(;;){if(t.lookahead<Kt){if(ae(t),t.lookahead<Kt&&e===Ut)return 1;if(0===t.lookahead)break}if(n=0,t.lookahead>=3&&(t.ins_h=Jt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==n&&t.strstart-n<=t.w_size-Kt&&(t.match_length=re(t,n)),t.match_length>=3)if(i=At(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=Jt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=Jt(t,t.ins_h,t.window[t.strstart+1]);else i=At(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(i&&(te(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===Lt?(te(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(te(t,!1),0===t.strm.avail_out)?1:2},oe=(t,e)=>{let n,i,r;for(;;){if(t.lookahead<Kt){if(ae(t),t.lookahead<Kt&&e===Ut)return 1;if(0===t.lookahead)break}if(n=0,t.lookahead>=3&&(t.ins_h=Jt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==n&&t.prev_length<t.max_lazy_match&&t.strstart-n<=t.w_size-Kt&&(t.match_length=re(t,n),t.match_length<=5&&(t.strategy===Bt||3===t.match_length&&t.strstart-t.match_start>4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){r=t.strstart+t.lookahead-3,i=At(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=r&&(t.ins_h=Jt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,i&&(te(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(i=At(t,0,t.window[t.strstart-1]),i&&te(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(i=At(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===Lt?(te(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(te(t,!1),0===t.strm.avail_out)?1:2};function le(t,e,n,i,r){this.good_length=t,this.max_lazy=e,this.nice_length=n,this.max_chain=i,this.func=r}const he=[new le(0,0,0,0,((t,e)=>{let n=65535;for(n>t.pending_buf_size-5&&(n=t.pending_buf_size-5);;){if(t.lookahead<=1){if(ae(t),0===t.lookahead&&e===Ut)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const i=t.block_start+n;if((0===t.strstart||t.strstart>=i)&&(t.lookahead=t.strstart-i,t.strstart=i,te(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-Kt&&(te(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Lt?(te(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(te(t,!1),t.strm.avail_out),1)})),new le(4,4,8,4,se),new le(4,5,16,8,se),new le(4,6,32,32,se),new le(4,4,16,16,oe),new le(8,16,32,32,oe),new le(8,16,128,128,oe),new le(8,32,128,256,oe),new le(32,128,258,1024,oe),new le(32,258,258,4096,oe)];function de(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=jt,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),qt(this.dyn_ltree),qt(this.dyn_dtree),qt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),qt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),qt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const fe=t=>{if(!t||!t.state)return Xt(t,St);t.total_in=t.total_out=0,t.data_type=Ht;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:Yt,t.adler=2===e.wrap?0:1,e.last_flush=Ut,kt(e),Nt},ce=t=>{const e=fe(t);var n;return e===Nt&&((n=t.state).window_size=2*n.w_size,qt(n.head),n.max_lazy_match=he[n.level].max_lazy,n.good_match=he[n.level].good_length,n.nice_match=he[n.level].nice_length,n.max_chain_length=he[n.level].max_chain,n.strstart=0,n.block_start=0,n.lookahead=0,n.insert=0,n.match_length=n.prev_length=2,n.match_available=0,n.ins_h=0),e},ue=(t,e,n,i,r,a)=>{if(!t)return St;let s=1;if(e===It&&(e=6),i<0?(s=0,i=-i):i>15&&(s=2,i-=16),r<1||r>9||n!==jt||i<8||i>15||e<0||e>9||a<0||a>Mt)return Xt(t,St);8===i&&(i=9);const o=new de;return t.state=o,o.strm=t,o.wrap=s,o.gzhead=null,o.w_bits=i,o.w_size=1<<o.w_bits,o.w_mask=o.w_size-1,o.hash_bits=r+7,o.hash_size=1<<o.hash_bits,o.hash_mask=o.hash_size-1,o.hash_shift=~~((o.hash_bits+3-1)/3),o.window=new Uint8Array(2*o.w_size),o.head=new Uint16Array(o.hash_size),o.prev=new Uint16Array(o.w_size),o.lit_bufsize=1<<r+6,o.pending_buf_size=4*o.lit_bufsize,o.pending_buf=new Uint8Array(o.pending_buf_size),o.d_buf=1*o.lit_bufsize,o.l_buf=3*o.lit_bufsize,o.level=e,o.strategy=a,o.method=n,ce(t)};var _e={deflateInit:(t,e)=>ue(t,e,jt,15,8,Pt),deflateInit2:ue,deflateReset:ce,deflateResetKeep:fe,deflateSetHeader:(t,e)=>t&&t.state?2!==t.state.wrap?St:(t.state.gzhead=e,Nt):St,deflate:(t,e)=>{let n,i;if(!t||!t.state||e>Tt||e<0)return t?Xt(t,St):St;const r=t.state;if(!t.output||!t.input&&0!==t.avail_in||r.status===Gt&&e!==Lt)return Xt(t,0===t.avail_out?Dt:St);r.strm=t;const a=r.last_flush;if(r.last_flush=e,42===r.status)if(2===r.wrap)t.adler=0,ee(r,31),ee(r,139),ee(r,8),r.gzhead?(ee(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),ee(r,255&r.gzhead.time),ee(r,r.gzhead.time>>8&255),ee(r,r.gzhead.time>>16&255),ee(r,r.gzhead.time>>24&255),ee(r,9===r.level?2:r.strategy>=Zt||r.level<2?4:0),ee(r,255&r.gzhead.os),r.gzhead.extra&&r.gzhead.extra.length&&(ee(r,255&r.gzhead.extra.length),ee(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(t.adler=gt(t.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=69):(ee(r,0),ee(r,0),ee(r,0),ee(r,0),ee(r,0),ee(r,9===r.level?2:r.strategy>=Zt||r.level<2?4:0),ee(r,3),r.status=Yt);else{let e=jt+(r.w_bits-8<<4)<<8,n=-1;n=r.strategy>=Zt||r.level<2?0:r.level<6?1:6===r.level?2:3,e|=n<<6,0!==r.strstart&&(e|=32),e+=31-e%31,r.status=Yt,ne(r,e),0!==r.strstart&&(ne(r,t.adler>>>16),ne(r,65535&t.adler)),t.adler=1}if(69===r.status)if(r.gzhead.extra){for(n=r.pending;r.gzindex<(65535&r.gzhead.extra.length)&&(r.pending!==r.pending_buf_size||(r.gzhead.hcrc&&r.pending>n&&(t.adler=gt(t.adler,r.pending_buf,r.pending-n,n)),Qt(t),n=r.pending,r.pending!==r.pending_buf_size));)ee(r,255&r.gzhead.extra[r.gzindex]),r.gzindex++;r.gzhead.hcrc&&r.pending>n&&(t.adler=gt(t.adler,r.pending_buf,r.pending-n,n)),r.gzindex===r.gzhead.extra.length&&(r.gzindex=0,r.status=73)}else r.status=73;if(73===r.status)if(r.gzhead.name){n=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>n&&(t.adler=gt(t.adler,r.pending_buf,r.pending-n,n)),Qt(t),n=r.pending,r.pending===r.pending_buf_size)){i=1;break}i=r.gzindex<r.gzhead.name.length?255&r.gzhead.name.charCodeAt(r.gzindex++):0,ee(r,i)}while(0!==i);r.gzhead.hcrc&&r.pending>n&&(t.adler=gt(t.adler,r.pending_buf,r.pending-n,n)),0===i&&(r.gzindex=0,r.status=91)}else r.status=91;if(91===r.status)if(r.gzhead.comment){n=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>n&&(t.adler=gt(t.adler,r.pending_buf,r.pending-n,n)),Qt(t),n=r.pending,r.pending===r.pending_buf_size)){i=1;break}i=r.gzindex<r.gzhead.comment.length?255&r.gzhead.comment.charCodeAt(r.gzindex++):0,ee(r,i)}while(0!==i);r.gzhead.hcrc&&r.pending>n&&(t.adler=gt(t.adler,r.pending_buf,r.pending-n,n)),0===i&&(r.status=$t)}else r.status=$t;if(r.status===$t&&(r.gzhead.hcrc?(r.pending+2>r.pending_buf_size&&Qt(t),r.pending+2<=r.pending_buf_size&&(ee(r,255&t.adler),ee(r,t.adler>>8&255),t.adler=0,r.status=Yt)):r.status=Yt),0!==r.pending){if(Qt(t),0===t.avail_out)return r.last_flush=-1,Nt}else if(0===t.avail_in&&Vt(e)<=Vt(a)&&e!==Lt)return Xt(t,Dt);if(r.status===Gt&&0!==t.avail_in)return Xt(t,Dt);if(0!==t.avail_in||0!==r.lookahead||e!==Ut&&r.status!==Gt){let n=r.strategy===Zt?((t,e)=>{let n;for(;;){if(0===t.lookahead&&(ae(t),0===t.lookahead)){if(e===Ut)return 1;break}if(t.match_length=0,n=At(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,n&&(te(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Lt?(te(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(te(t,!1),0===t.strm.avail_out)?1:2})(r,e):r.strategy===Ft?((t,e)=>{let n,i,r,a;const s=t.window;for(;;){if(t.lookahead<=Wt){if(ae(t),t.lookahead<=Wt&&e===Ut)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(r=t.strstart-1,i=s[r],i===s[++r]&&i===s[++r]&&i===s[++r])){a=t.strstart+Wt;do{}while(i===s[++r]&&i===s[++r]&&i===s[++r]&&i===s[++r]&&i===s[++r]&&i===s[++r]&&i===s[++r]&&i===s[++r]&&r<a);t.match_length=Wt-(a-r),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(n=At(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(n=At(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),n&&(te(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Lt?(te(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(te(t,!1),0===t.strm.avail_out)?1:2})(r,e):he[r.level].func(r,e);if(3!==n&&4!==n||(r.status=Gt),1===n||3===n)return 0===t.avail_out&&(r.last_flush=-1),Nt;if(2===n&&(e===zt?xt(r):e!==Tt&&(vt(r,0,0,!1),e===Rt&&(qt(r.head),0===r.lookahead&&(r.strstart=0,r.block_start=0,r.insert=0))),Qt(t),0===t.avail_out))return r.last_flush=-1,Nt}return e!==Lt?Nt:r.wrap<=0?Ot:(2===r.wrap?(ee(r,255&t.adler),ee(r,t.adler>>8&255),ee(r,t.adler>>16&255),ee(r,t.adler>>24&255),ee(r,255&t.total_in),ee(r,t.total_in>>8&255),ee(r,t.total_in>>16&255),ee(r,t.total_in>>24&255)):(ne(r,t.adler>>>16),ne(r,65535&t.adler)),Qt(t),r.wrap>0&&(r.wrap=-r.wrap),0!==r.pending?Nt:Ot)},deflateEnd:t=>{if(!t||!t.state)return St;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==$t&&e!==Yt&&e!==Gt?Xt(t,St):(t.state=null,e===Yt?Xt(t,Ct):Nt)},deflateSetDictionary:(t,e)=>{let n=e.length;if(!t||!t.state)return St;const i=t.state,r=i.wrap;if(2===r||1===r&&42!==i.status||i.lookahead)return St;if(1===r&&(t.adler=wt(t.adler,e,n,0)),i.wrap=0,n>=i.w_size){0===r&&(qt(i.head),i.strstart=0,i.block_start=0,i.insert=0);let t=new Uint8Array(i.w_size);t.set(e.subarray(n-i.w_size,n),0),e=t,n=i.w_size}const a=t.avail_in,s=t.next_in,o=t.input;for(t.avail_in=n,t.next_in=0,t.input=e,ae(i);i.lookahead>=3;){let t=i.strstart,e=i.lookahead-2;do{i.ins_h=Jt(i,i.ins_h,i.window[t+3-1]),i.prev[t&i.w_mask]=i.head[i.ins_h],i.head[i.ins_h]=t,t++}while(--e);i.strstart=t,i.lookahead=2,ae(i)}return i.strstart+=i.lookahead,i.block_start=i.strstart,i.insert=i.lookahead,i.lookahead=0,i.match_length=i.prev_length=2,i.match_available=0,t.next_in=s,t.input=o,t.avail_in=a,i.wrap=r,Nt},deflateInfo:"pako deflate (from Nodeca project)"};const pe=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var we=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const n=e.shift();if(n){if("object"!=typeof n)throw new TypeError(n+"must be non-object");for(const e in n)pe(n,e)&&(t[e]=n[e])}}return t},be=t=>{let e=0;for(let n=0,i=t.length;n<i;n++)e+=t[n].length;const n=new Uint8Array(e);for(let e=0,i=0,r=t.length;e<r;e++){let r=t[e];n.set(r,i),i+=r.length}return n};let ge=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(t){ge=!1}const me=new Uint8Array(256);for(let t=0;t<256;t++)me[t]=t>=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;me[254]=me[254]=1;var ye=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,n,i,r,a,s=t.length,o=0;for(r=0;r<s;r++)n=t.charCodeAt(r),55296==(64512&n)&&r+1<s&&(i=t.charCodeAt(r+1),56320==(64512&i)&&(n=65536+(n-55296<<10)+(i-56320),r++)),o+=n<128?1:n<2048?2:n<65536?3:4;for(e=new Uint8Array(o),a=0,r=0;a<o;r++)n=t.charCodeAt(r),55296==(64512&n)&&r+1<s&&(i=t.charCodeAt(r+1),56320==(64512&i)&&(n=65536+(n-55296<<10)+(i-56320),r++)),n<128?e[a++]=n:n<2048?(e[a++]=192|n>>>6,e[a++]=128|63&n):n<65536?(e[a++]=224|n>>>12,e[a++]=128|n>>>6&63,e[a++]=128|63&n):(e[a++]=240|n>>>18,e[a++]=128|n>>>12&63,e[a++]=128|n>>>6&63,e[a++]=128|63&n);return e},ke=(t,e)=>{const n=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let i,r;const a=new Array(2*n);for(r=0,i=0;i<n;){let e=t[i++];if(e<128){a[r++]=e;continue}let s=me[e];if(s>4)a[r++]=65533,i+=s-1;else{for(e&=2===s?31:3===s?15:7;s>1&&i<n;)e=e<<6|63&t[i++],s--;s>1?a[r++]=65533:e<65536?a[r++]=e:(e-=65536,a[r++]=55296|e>>10&1023,a[r++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&ge)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let n="";for(let i=0;i<e;i++)n+=String.fromCharCode(t[i]);return n})(a,r)},ve=(t,e)=>{(e=e||t.length)>t.length&&(e=t.length);let n=e-1;for(;n>=0&&128==(192&t[n]);)n--;return n<0||0===n?e:n+me[t[n]]>e?n:e};var Ee=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Ae=Object.prototype.toString,{Z_NO_FLUSH:xe,Z_SYNC_FLUSH:Ue,Z_FULL_FLUSH:ze,Z_FINISH:Re,Z_OK:Le,Z_STREAM_END:Te,Z_DEFAULT_COMPRESSION:Ne,Z_DEFAULT_STRATEGY:Oe,Z_DEFLATED:Se}=yt;function Ce(t){this.options=we({level:Ne,method:Se,chunkSize:16384,windowBits:15,memLevel:8,strategy:Oe},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ee,this.strm.avail_out=0;let n=_e.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(n!==Le)throw new Error(mt[n]);if(e.header&&_e.deflateSetHeader(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?ye(e.dictionary):"[object ArrayBuffer]"===Ae.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,n=_e.deflateSetDictionary(this.strm,t),n!==Le)throw new Error(mt[n]);this._dict_set=!0}}Ce.prototype.push=function(t,e){const n=this.strm,i=this.options.chunkSize;let r,a;if(this.ended)return!1;for(a=e===~~e?e:!0===e?Re:xe,"string"==typeof t?n.input=ye(t):"[object ArrayBuffer]"===Ae.call(t)?n.input=new Uint8Array(t):n.input=t,n.next_in=0,n.avail_in=n.input.length;;)if(0===n.avail_out&&(n.output=new Uint8Array(i),n.next_out=0,n.avail_out=i),(a===Ue||a===ze)&&n.avail_out<=6)this.onData(n.output.subarray(0,n.next_out)),n.avail_out=0;else{if(r=_e.deflate(n,a),r===Te)return n.next_out>0&&this.onData(n.output.subarray(0,n.next_out)),r=_e.deflateEnd(this.strm),this.onEnd(r),this.ended=!0,r===Le;if(0!==n.avail_out){if(a>0&&n.next_out>0)this.onData(n.output.subarray(0,n.next_out)),n.avail_out=0;else if(0===n.avail_in)break}else this.onData(n.output)}return!0},Ce.prototype.onData=function(t){this.chunks.push(t)},Ce.prototype.onEnd=function(t){t===Le&&(this.result=be(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var De=function(t,e){let n,i,r,a,s,o,l,h,d,f,c,u,_,p,w,b,g,m,y,k,v,E,A,x;const U=t.state;n=t.next_in,A=t.input,i=n+(t.avail_in-5),r=t.next_out,x=t.output,a=r-(e-t.avail_out),s=r+(t.avail_out-257),o=U.dmax,l=U.wsize,h=U.whave,d=U.wnext,f=U.window,c=U.hold,u=U.bits,_=U.lencode,p=U.distcode,w=(1<<U.lenbits)-1,b=(1<<U.distbits)-1;t:do{u<15&&(c+=A[n++]<<u,u+=8,c+=A[n++]<<u,u+=8),g=_[c&w];e:for(;;){if(m=g>>>24,c>>>=m,u-=m,m=g>>>16&255,0===m)x[r++]=65535&g;else{if(!(16&m)){if(0==(64&m)){g=_[(65535&g)+(c&(1<<m)-1)];continue e}if(32&m){U.mode=12;break t}t.msg="invalid literal/length code",U.mode=30;break t}y=65535&g,m&=15,m&&(u<m&&(c+=A[n++]<<u,u+=8),y+=c&(1<<m)-1,c>>>=m,u-=m),u<15&&(c+=A[n++]<<u,u+=8,c+=A[n++]<<u,u+=8),g=p[c&b];n:for(;;){if(m=g>>>24,c>>>=m,u-=m,m=g>>>16&255,!(16&m)){if(0==(64&m)){g=p[(65535&g)+(c&(1<<m)-1)];continue n}t.msg="invalid distance code",U.mode=30;break t}if(k=65535&g,m&=15,u<m&&(c+=A[n++]<<u,u+=8,u<m&&(c+=A[n++]<<u,u+=8)),k+=c&(1<<m)-1,k>o){t.msg="invalid distance too far back",U.mode=30;break t}if(c>>>=m,u-=m,m=r-a,k>m){if(m=k-m,m>h&&U.sane){t.msg="invalid distance too far back",U.mode=30;break t}if(v=0,E=f,0===d){if(v+=l-m,m<y){y-=m;do{x[r++]=f[v++]}while(--m);v=r-k,E=x}}else if(d<m){if(v+=l+d-m,m-=d,m<y){y-=m;do{x[r++]=f[v++]}while(--m);if(v=0,d<y){m=d,y-=m;do{x[r++]=f[v++]}while(--m);v=r-k,E=x}}}else if(v+=d-m,m<y){y-=m;do{x[r++]=f[v++]}while(--m);v=r-k,E=x}for(;y>2;)x[r++]=E[v++],x[r++]=E[v++],x[r++]=E[v++],y-=3;y&&(x[r++]=E[v++],y>1&&(x[r++]=E[v++]))}else{v=r-k;do{x[r++]=x[v++],x[r++]=x[v++],x[r++]=x[v++],y-=3}while(y>2);y&&(x[r++]=x[v++],y>1&&(x[r++]=x[v++]))}break}}break}}while(n<i&&r<s);y=u>>3,n-=y,u-=y<<3,c&=(1<<u)-1,t.next_in=n,t.next_out=r,t.avail_in=n<i?i-n+5:5-(n-i),t.avail_out=r<s?s-r+257:257-(r-s),U.hold=c,U.bits=u};const Ie=15,Be=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),Ze=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),Fe=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),Me=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var Pe=(t,e,n,i,r,a,s,o)=>{const l=o.bits;let h,d,f,c,u,_,p=0,w=0,b=0,g=0,m=0,y=0,k=0,v=0,E=0,A=0,x=null,U=0;const z=new Uint16Array(16),R=new Uint16Array(16);let L,T,N,O=null,S=0;for(p=0;p<=Ie;p++)z[p]=0;for(w=0;w<i;w++)z[e[n+w]]++;for(m=l,g=Ie;g>=1&&0===z[g];g--);if(m>g&&(m=g),0===g)return r[a++]=20971520,r[a++]=20971520,o.bits=1,0;for(b=1;b<g&&0===z[b];b++);for(m<b&&(m=b),v=1,p=1;p<=Ie;p++)if(v<<=1,v-=z[p],v<0)return-1;if(v>0&&(0===t||1!==g))return-1;for(R[1]=0,p=1;p<Ie;p++)R[p+1]=R[p]+z[p];for(w=0;w<i;w++)0!==e[n+w]&&(s[R[e[n+w]]++]=w);if(0===t?(x=O=s,_=19):1===t?(x=Be,U-=257,O=Ze,S-=257,_=256):(x=Fe,O=Me,_=-1),A=0,w=0,p=b,u=a,y=m,k=0,f=-1,E=1<<m,c=E-1,1===t&&E>852||2===t&&E>592)return 1;for(;;){L=p-k,s[w]<_?(T=0,N=s[w]):s[w]>_?(T=O[S+s[w]],N=x[U+s[w]]):(T=96,N=0),h=1<<p-k,d=1<<y,b=d;do{d-=h,r[u+(A>>k)+d]=L<<24|T<<16|N|0}while(0!==d);for(h=1<<p-1;A&h;)h>>=1;if(0!==h?(A&=h-1,A+=h):A=0,w++,0==--z[p]){if(p===g)break;p=e[n+s[w]]}if(p>m&&(A&c)!==f){for(0===k&&(k=m),u+=b,y=p-k,v=1<<y;y+k<g&&(v-=z[y+k],!(v<=0));)y++,v<<=1;if(E+=1<<y,1===t&&E>852||2===t&&E>592)return 1;f=A&c,r[f]=m<<24|y<<16|u-a|0}}return 0!==A&&(r[u+A]=p-k<<24|64<<16|0),o.bits=m,0};const{Z_FINISH:He,Z_BLOCK:je,Z_TREES:We,Z_OK:Ke,Z_STREAM_END:$e,Z_NEED_DICT:Ye,Z_STREAM_ERROR:Ge,Z_DATA_ERROR:Xe,Z_MEM_ERROR:Ve,Z_BUF_ERROR:qe,Z_DEFLATED:Je}=yt,Qe=12,tn=30,en=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function nn(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const rn=t=>{if(!t||!t.state)return Ge;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,Ke},an=t=>{if(!t||!t.state)return Ge;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,rn(t)},sn=(t,e)=>{let n;if(!t||!t.state)return Ge;const i=t.state;return e<0?(n=0,e=-e):(n=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?Ge:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=n,i.wbits=e,an(t))},on=(t,e)=>{if(!t)return Ge;const n=new nn;t.state=n,n.window=null;const i=sn(t,e);return i!==Ke&&(t.state=null),i};let ln,hn,dn=!0;const fn=t=>{if(dn){ln=new Int32Array(512),hn=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(Pe(1,t.lens,0,288,ln,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;Pe(2,t.lens,0,32,hn,0,t.work,{bits:5}),dn=!1}t.lencode=ln,t.lenbits=9,t.distcode=hn,t.distbits=5},cn=(t,e,n,i)=>{let r;const a=t.state;return null===a.window&&(a.wsize=1<<a.wbits,a.wnext=0,a.whave=0,a.window=new Uint8Array(a.wsize)),i>=a.wsize?(a.window.set(e.subarray(n-a.wsize,n),0),a.wnext=0,a.whave=a.wsize):(r=a.wsize-a.wnext,r>i&&(r=i),a.window.set(e.subarray(n-i,n-i+r),a.wnext),(i-=r)?(a.window.set(e.subarray(n-i,n),0),a.wnext=i,a.whave=a.wsize):(a.wnext+=r,a.wnext===a.wsize&&(a.wnext=0),a.whave<a.wsize&&(a.whave+=r))),0};var un={inflateReset:an,inflateReset2:sn,inflateResetKeep:rn,inflateInit:t=>on(t,15),inflateInit2:on,inflate:(t,e)=>{let n,i,r,a,s,o,l,h,d,f,c,u,_,p,w,b,g,m,y,k,v,E,A=0;const x=new Uint8Array(4);let U,z;const R=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return Ge;n=t.state,n.mode===Qe&&(n.mode=13),s=t.next_out,r=t.output,l=t.avail_out,a=t.next_in,i=t.input,o=t.avail_in,h=n.hold,d=n.bits,f=o,c=l,E=Ke;t:for(;;)switch(n.mode){case 1:if(0===n.wrap){n.mode=13;break}for(;d<16;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}if(2&n.wrap&&35615===h){n.check=0,x[0]=255&h,x[1]=h>>>8&255,n.check=gt(n.check,x,2,0),h=0,d=0,n.mode=2;break}if(n.flags=0,n.head&&(n.head.done=!1),!(1&n.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",n.mode=tn;break}if((15&h)!==Je){t.msg="unknown compression method",n.mode=tn;break}if(h>>>=4,d-=4,v=8+(15&h),0===n.wbits)n.wbits=v;else if(v>n.wbits){t.msg="invalid window size",n.mode=tn;break}n.dmax=1<<n.wbits,t.adler=n.check=1,n.mode=512&h?10:Qe,h=0,d=0;break;case 2:for(;d<16;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}if(n.flags=h,(255&n.flags)!==Je){t.msg="unknown compression method",n.mode=tn;break}if(57344&n.flags){t.msg="unknown header flags set",n.mode=tn;break}n.head&&(n.head.text=h>>8&1),512&n.flags&&(x[0]=255&h,x[1]=h>>>8&255,n.check=gt(n.check,x,2,0)),h=0,d=0,n.mode=3;case 3:for(;d<32;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}n.head&&(n.head.time=h),512&n.flags&&(x[0]=255&h,x[1]=h>>>8&255,x[2]=h>>>16&255,x[3]=h>>>24&255,n.check=gt(n.check,x,4,0)),h=0,d=0,n.mode=4;case 4:for(;d<16;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}n.head&&(n.head.xflags=255&h,n.head.os=h>>8),512&n.flags&&(x[0]=255&h,x[1]=h>>>8&255,n.check=gt(n.check,x,2,0)),h=0,d=0,n.mode=5;case 5:if(1024&n.flags){for(;d<16;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}n.length=h,n.head&&(n.head.extra_len=h),512&n.flags&&(x[0]=255&h,x[1]=h>>>8&255,n.check=gt(n.check,x,2,0)),h=0,d=0}else n.head&&(n.head.extra=null);n.mode=6;case 6:if(1024&n.flags&&(u=n.length,u>o&&(u=o),u&&(n.head&&(v=n.head.extra_len-n.length,n.head.extra||(n.head.extra=new Uint8Array(n.head.extra_len)),n.head.extra.set(i.subarray(a,a+u),v)),512&n.flags&&(n.check=gt(n.check,i,u,a)),o-=u,a+=u,n.length-=u),n.length))break t;n.length=0,n.mode=7;case 7:if(2048&n.flags){if(0===o)break t;u=0;do{v=i[a+u++],n.head&&v&&n.length<65536&&(n.head.name+=String.fromCharCode(v))}while(v&&u<o);if(512&n.flags&&(n.check=gt(n.check,i,u,a)),o-=u,a+=u,v)break t}else n.head&&(n.head.name=null);n.length=0,n.mode=8;case 8:if(4096&n.flags){if(0===o)break t;u=0;do{v=i[a+u++],n.head&&v&&n.length<65536&&(n.head.comment+=String.fromCharCode(v))}while(v&&u<o);if(512&n.flags&&(n.check=gt(n.check,i,u,a)),o-=u,a+=u,v)break t}else n.head&&(n.head.comment=null);n.mode=9;case 9:if(512&n.flags){for(;d<16;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}if(h!==(65535&n.check)){t.msg="header crc mismatch",n.mode=tn;break}h=0,d=0}n.head&&(n.head.hcrc=n.flags>>9&1,n.head.done=!0),t.adler=n.check=0,n.mode=Qe;break;case 10:for(;d<32;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}t.adler=n.check=en(h),h=0,d=0,n.mode=11;case 11:if(0===n.havedict)return t.next_out=s,t.avail_out=l,t.next_in=a,t.avail_in=o,n.hold=h,n.bits=d,Ye;t.adler=n.check=1,n.mode=Qe;case Qe:if(e===je||e===We)break t;case 13:if(n.last){h>>>=7&d,d-=7&d,n.mode=27;break}for(;d<3;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}switch(n.last=1&h,h>>>=1,d-=1,3&h){case 0:n.mode=14;break;case 1:if(fn(n),n.mode=20,e===We){h>>>=2,d-=2;break t}break;case 2:n.mode=17;break;case 3:t.msg="invalid block type",n.mode=tn}h>>>=2,d-=2;break;case 14:for(h>>>=7&d,d-=7&d;d<32;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}if((65535&h)!=(h>>>16^65535)){t.msg="invalid stored block lengths",n.mode=tn;break}if(n.length=65535&h,h=0,d=0,n.mode=15,e===We)break t;case 15:n.mode=16;case 16:if(u=n.length,u){if(u>o&&(u=o),u>l&&(u=l),0===u)break t;r.set(i.subarray(a,a+u),s),o-=u,a+=u,l-=u,s+=u,n.length-=u;break}n.mode=Qe;break;case 17:for(;d<14;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}if(n.nlen=257+(31&h),h>>>=5,d-=5,n.ndist=1+(31&h),h>>>=5,d-=5,n.ncode=4+(15&h),h>>>=4,d-=4,n.nlen>286||n.ndist>30){t.msg="too many length or distance symbols",n.mode=tn;break}n.have=0,n.mode=18;case 18:for(;n.have<n.ncode;){for(;d<3;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}n.lens[R[n.have++]]=7&h,h>>>=3,d-=3}for(;n.have<19;)n.lens[R[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,U={bits:n.lenbits},E=Pe(0,n.lens,0,19,n.lencode,0,n.work,U),n.lenbits=U.bits,E){t.msg="invalid code lengths set",n.mode=tn;break}n.have=0,n.mode=19;case 19:for(;n.have<n.nlen+n.ndist;){for(;A=n.lencode[h&(1<<n.lenbits)-1],w=A>>>24,b=A>>>16&255,g=65535&A,!(w<=d);){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}if(g<16)h>>>=w,d-=w,n.lens[n.have++]=g;else{if(16===g){for(z=w+2;d<z;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}if(h>>>=w,d-=w,0===n.have){t.msg="invalid bit length repeat",n.mode=tn;break}v=n.lens[n.have-1],u=3+(3&h),h>>>=2,d-=2}else if(17===g){for(z=w+3;d<z;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}h>>>=w,d-=w,v=0,u=3+(7&h),h>>>=3,d-=3}else{for(z=w+7;d<z;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}h>>>=w,d-=w,v=0,u=11+(127&h),h>>>=7,d-=7}if(n.have+u>n.nlen+n.ndist){t.msg="invalid bit length repeat",n.mode=tn;break}for(;u--;)n.lens[n.have++]=v}}if(n.mode===tn)break;if(0===n.lens[256]){t.msg="invalid code -- missing end-of-block",n.mode=tn;break}if(n.lenbits=9,U={bits:n.lenbits},E=Pe(1,n.lens,0,n.nlen,n.lencode,0,n.work,U),n.lenbits=U.bits,E){t.msg="invalid literal/lengths set",n.mode=tn;break}if(n.distbits=6,n.distcode=n.distdyn,U={bits:n.distbits},E=Pe(2,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,U),n.distbits=U.bits,E){t.msg="invalid distances set",n.mode=tn;break}if(n.mode=20,e===We)break t;case 20:n.mode=21;case 21:if(o>=6&&l>=258){t.next_out=s,t.avail_out=l,t.next_in=a,t.avail_in=o,n.hold=h,n.bits=d,De(t,c),s=t.next_out,r=t.output,l=t.avail_out,a=t.next_in,i=t.input,o=t.avail_in,h=n.hold,d=n.bits,n.mode===Qe&&(n.back=-1);break}for(n.back=0;A=n.lencode[h&(1<<n.lenbits)-1],w=A>>>24,b=A>>>16&255,g=65535&A,!(w<=d);){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}if(b&&0==(240&b)){for(m=w,y=b,k=g;A=n.lencode[k+((h&(1<<m+y)-1)>>m)],w=A>>>24,b=A>>>16&255,g=65535&A,!(m+w<=d);){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}h>>>=m,d-=m,n.back+=m}if(h>>>=w,d-=w,n.back+=w,n.length=g,0===b){n.mode=26;break}if(32&b){n.back=-1,n.mode=Qe;break}if(64&b){t.msg="invalid literal/length code",n.mode=tn;break}n.extra=15&b,n.mode=22;case 22:if(n.extra){for(z=n.extra;d<z;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}n.length+=h&(1<<n.extra)-1,h>>>=n.extra,d-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=23;case 23:for(;A=n.distcode[h&(1<<n.distbits)-1],w=A>>>24,b=A>>>16&255,g=65535&A,!(w<=d);){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}if(0==(240&b)){for(m=w,y=b,k=g;A=n.distcode[k+((h&(1<<m+y)-1)>>m)],w=A>>>24,b=A>>>16&255,g=65535&A,!(m+w<=d);){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}h>>>=m,d-=m,n.back+=m}if(h>>>=w,d-=w,n.back+=w,64&b){t.msg="invalid distance code",n.mode=tn;break}n.offset=g,n.extra=15&b,n.mode=24;case 24:if(n.extra){for(z=n.extra;d<z;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}n.offset+=h&(1<<n.extra)-1,h>>>=n.extra,d-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){t.msg="invalid distance too far back",n.mode=tn;break}n.mode=25;case 25:if(0===l)break t;if(u=c-l,n.offset>u){if(u=n.offset-u,u>n.whave&&n.sane){t.msg="invalid distance too far back",n.mode=tn;break}u>n.wnext?(u-=n.wnext,_=n.wsize-u):_=n.wnext-u,u>n.length&&(u=n.length),p=n.window}else p=r,_=s-n.offset,u=n.length;u>l&&(u=l),l-=u,n.length-=u;do{r[s++]=p[_++]}while(--u);0===n.length&&(n.mode=21);break;case 26:if(0===l)break t;r[s++]=n.length,l--,n.mode=21;break;case 27:if(n.wrap){for(;d<32;){if(0===o)break t;o--,h|=i[a++]<<d,d+=8}if(c-=l,t.total_out+=c,n.total+=c,c&&(t.adler=n.check=n.flags?gt(n.check,r,c,s-c):wt(n.check,r,c,s-c)),c=l,(n.flags?h:en(h))!==n.check){t.msg="incorrect data check",n.mode=tn;break}h=0,d=0}n.mode=28;case 28:if(n.wrap&&n.flags){for(;d<32;){if(0===o)break t;o--,h+=i[a++]<<d,d+=8}if(h!==(4294967295&n.total)){t.msg="incorrect length check",n.mode=tn;break}h=0,d=0}n.mode=29;case 29:E=$e;break t;case tn:E=Xe;break t;case 31:return Ve;default:return Ge}return t.next_out=s,t.avail_out=l,t.next_in=a,t.avail_in=o,n.hold=h,n.bits=d,(n.wsize||c!==t.avail_out&&n.mode<tn&&(n.mode<27||e!==He))&&cn(t,t.output,t.next_out,c-t.avail_out),f-=t.avail_in,c-=t.avail_out,t.total_in+=f,t.total_out+=c,n.total+=c,n.wrap&&c&&(t.adler=n.check=n.flags?gt(n.check,r,c,t.next_out-c):wt(n.check,r,c,t.next_out-c)),t.data_type=n.bits+(n.last?64:0)+(n.mode===Qe?128:0)+(20===n.mode||15===n.mode?256:0),(0===f&&0===c||e===He)&&E===Ke&&(E=qe),E},inflateEnd:t=>{if(!t||!t.state)return Ge;let e=t.state;return e.window&&(e.window=null),t.state=null,Ke},inflateGetHeader:(t,e)=>{if(!t||!t.state)return Ge;const n=t.state;return 0==(2&n.wrap)?Ge:(n.head=e,e.done=!1,Ke)},inflateSetDictionary:(t,e)=>{const n=e.length;let i,r,a;return t&&t.state?(i=t.state,0!==i.wrap&&11!==i.mode?Ge:11===i.mode&&(r=1,r=wt(r,e,n,0),r!==i.check)?Xe:(a=cn(t,e,n,n),a?(i.mode=31,Ve):(i.havedict=1,Ke))):Ge},inflateInfo:"pako inflate (from Nodeca project)"};var _n=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const pn=Object.prototype.toString,{Z_NO_FLUSH:wn,Z_FINISH:bn,Z_OK:gn,Z_STREAM_END:mn,Z_NEED_DICT:yn,Z_STREAM_ERROR:kn,Z_DATA_ERROR:vn,Z_MEM_ERROR:En}=yt;function An(t){this.options=we({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ee,this.strm.avail_out=0;let n=un.inflateInit2(this.strm,e.windowBits);if(n!==gn)throw new Error(mt[n]);if(this.header=new _n,un.inflateGetHeader(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=ye(e.dictionary):"[object ArrayBuffer]"===pn.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(n=un.inflateSetDictionary(this.strm,e.dictionary),n!==gn)))throw new Error(mt[n])}function xn(t,e){const n=new An(e);if(n.push(t),n.err)throw n.msg||mt[n.err];return n.result}An.prototype.push=function(t,e){const n=this.strm,i=this.options.chunkSize,r=this.options.dictionary;let a,s,o;if(this.ended)return!1;for(s=e===~~e?e:!0===e?bn:wn,"[object ArrayBuffer]"===pn.call(t)?n.input=new Uint8Array(t):n.input=t,n.next_in=0,n.avail_in=n.input.length;;){for(0===n.avail_out&&(n.output=new Uint8Array(i),n.next_out=0,n.avail_out=i),a=un.inflate(n,s),a===yn&&r&&(a=un.inflateSetDictionary(n,r),a===gn?a=un.inflate(n,s):a===vn&&(a=yn));n.avail_in>0&&a===mn&&n.state.wrap>0&&0!==t[n.next_in];)un.inflateReset(n),a=un.inflate(n,s);switch(a){case kn:case vn:case yn:case En:return this.onEnd(a),this.ended=!0,!1}if(o=n.avail_out,n.next_out&&(0===n.avail_out||a===mn))if("string"===this.options.to){let t=ve(n.output,n.next_out),e=n.next_out-t,r=ke(n.output,t);n.next_out=e,n.avail_out=i-e,e&&n.output.set(n.output.subarray(t,t+e),0),this.onData(r)}else this.onData(n.output.length===n.next_out?n.output:n.output.subarray(0,n.next_out));if(a!==gn||0!==o){if(a===mn)return a=un.inflateEnd(this.strm),this.onEnd(a),this.ended=!0,!0;if(0===n.avail_in)break}}return!0},An.prototype.onData=function(t){this.chunks.push(t)},An.prototype.onEnd=function(t){t===gn&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=be(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Un={Inflate:An,inflate:xn,inflateRaw:function(t,e){return(e=e||{}).raw=!0,xn(t,e)},ungzip:xn,constants:yt};const{Inflate:zn,inflate:Rn,inflateRaw:Ln,ungzip:Tn}=Un;var Nn=zn,On=Rn;const Sn=[137,80,78,71,13,10,26,10],Cn=[];for(let t=0;t<256;t++){let e=t;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;Cn[t]=e}const Dn=4294967295;function In(t,e){return(function(t,e,n){let i=t;for(let t=0;t<n;t++)i=Cn[255&(i^e[t])]^i>>>8;return i}(Dn,t,e)^Dn)>>>0}var Bn,Zn,Fn,Mn;!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(Bn||(Bn={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(Zn||(Zn={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(Fn||(Fn={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(Mn||(Mn={}));const Pn=new Uint8Array(0),Hn=new Uint16Array([255]),jn=255===new Uint8Array(Hn.buffer)[0];class Wn extends N{constructor(t,e={}){super(t);const{checkCrc:n=!1}=e;this._checkCrc=n,this._inflator=new Nn,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._end=!1,this._hasPalette=!1,this._palette=[],this._compressionMethod=Zn.UNKNOWN,this._filterMethod=Fn.UNKNOWN,this._interlaceMethod=Mn.UNKNOWN,this._colorType=-1,this.setBigEndian()}decode(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(let t=0;t<Sn.length;t++)if(this.readUint8()!==Sn[t])throw new Error(\`wrong PNG signature. Byte at \${t} should be \${Sn[t]}.\`)}decodeChunk(){const t=this.readUint32(),e=this.readChars(4),n=this.offset;switch(e){case"IHDR":this.decodeIHDR();break;case"PLTE":this.decodePLTE(t);break;case"IDAT":this.decodeIDAT(t);break;case"IEND":this._end=!0;break;case"tRNS":this.decodetRNS(t);break;case"iCCP":this.decodeiCCP(t);break;case"tEXt":this.decodetEXt(t);break;case"pHYs":this.decodepHYs();break;default:this.skip(t)}if(this.offset-n!==t)throw new Error(\`Length mismatch while decoding chunk \${e}\`);if(this._checkCrc){const n=this.readUint32(),i=t+4,r=In(new Uint8Array(this.buffer,this.byteOffset+this.offset-i-4,i),i);if(r!==n)throw new Error(\`CRC mismatch for chunk \${e}. Expected \${n}, found \${r}\`)}else this.skip(4)}decodeIHDR(){const t=this._png;t.width=this.readUint32(),t.height=this.readUint32(),t.depth=function(t){if(1!==t&&2!==t&&4!==t&&8!==t&&16!==t)throw new Error(\`invalid bit depth: \${t}\`);return t}(this.readUint8());const e=this.readUint8();let n;switch(this._colorType=e,e){case Bn.GREYSCALE:n=1;break;case Bn.TRUECOLOUR:n=3;break;case Bn.INDEXED_COLOUR:n=1;break;case Bn.GREYSCALE_ALPHA:n=2;break;case Bn.TRUECOLOUR_ALPHA:n=4;break;default:throw new Error(\`Unknown color type: \${e}\`)}if(this._png.channels=n,this._compressionMethod=this.readUint8(),this._compressionMethod!==Zn.DEFLATE)throw new Error(\`Unsupported compression method: \${this._compressionMethod}\`);this._filterMethod=this.readUint8(),this._interlaceMethod=this.readUint8()}decodePLTE(t){if(t%3!=0)throw new RangeError(\`PLTE field length must be a multiple of 3. Got \${t}\`);const e=t/3;this._hasPalette=!0;const n=[];this._palette=n;for(let t=0;t<e;t++)n.push([this.readUint8(),this.readUint8(),this.readUint8()])}decodeIDAT(t){this._inflator.push(new Uint8Array(this.buffer,this.offset+this.byteOffset,t)),this.skip(t)}decodetRNS(t){if(3===this._colorType){if(t>this._palette.length)throw new Error(\`tRNS chunk contains more alpha values than there are palette colors (\${t} vs \${this._palette.length})\`);let e=0;for(;e<t;e++){const t=this.readByte();this._palette[e].push(t)}for(;e<this._palette.length;e++)this._palette[e].push(255)}}decodeiCCP(t){let e,n="";for(;"\0"!==(e=this.readChar());)n+=e;const i=this.readUint8();if(i!==Zn.DEFLATE)throw new Error(\`Unsupported iCCP compression method: \${i}\`);const r=this.readBytes(t-n.length-2);this._png.iccEmbeddedProfile={name:n,profile:On(r)}}decodetEXt(t){let e,n="";for(;"\0"!==(e=this.readChar());)n+=e;this._png.text[n]=this.readChars(t-n.length-1)}decodepHYs(){const t=this.readUint32(),e=this.readUint32(),n=this.readByte();this._png.resolution={x:t,y:e,unit:n}}decodeImage(){if(this._inflator.err)throw new Error(\`Error while decompressing the data: \${this._inflator.err}\`);const t=this._inflator.result;if(this._filterMethod!==Fn.ADAPTIVE)throw new Error(\`Filter method \${this._filterMethod} not supported\`);if(this._interlaceMethod!==Mn.NO_INTERLACE)throw new Error(\`Interlace method \${this._interlaceMethod} not supported\`);this.decodeInterlaceNull(t)}decodeInterlaceNull(t){const e=this._png.height,n=this._png.channels*this._png.depth/8,i=this._png.width*n,r=new Uint8Array(this._png.height*i);let a,s,o=Pn,l=0;for(let h=0;h<e;h++){switch(a=t.subarray(l+1,l+1+i),s=r.subarray(h*i,(h+1)*i),t[l]){case 0:Kn(a,s,i);break;case 1:$n(a,s,i,n);break;case 2:Yn(a,s,o,i);break;case 3:Gn(a,s,o,i,n);break;case 4:Xn(a,s,o,i,n);break;default:throw new Error(\`Unsupported filter: \${t[l]}\`)}o=s,l+=i+1}if(this._hasPalette&&(this._png.palette=this._palette),16===this._png.depth){const t=new Uint16Array(r.buffer);if(jn)for(let e=0;e<t.length;e++)t[e]=(255&(h=t[e]))<<8|h>>8&255;this._png.data=t}else this._png.data=r;var h}}function Kn(t,e,n){for(let i=0;i<n;i++)e[i]=t[i]}function $n(t,e,n,i){let r=0;for(;r<i;r++)e[r]=t[r];for(;r<n;r++)e[r]=t[r]+e[r-i]&255}function Yn(t,e,n,i){let r=0;if(0===n.length)for(;r<i;r++)e[r]=t[r];else for(;r<i;r++)e[r]=t[r]+n[r]&255}function Gn(t,e,n,i,r){let a=0;if(0===n.length){for(;a<r;a++)e[a]=t[a];for(;a<i;a++)e[a]=t[a]+(e[a-r]>>1)&255}else{for(;a<r;a++)e[a]=t[a]+(n[a]>>1)&255;for(;a<i;a++)e[a]=t[a]+(e[a-r]+n[a]>>1)&255}}function Xn(t,e,n,i,r){let a=0;if(0===n.length){for(;a<r;a++)e[a]=t[a];for(;a<i;a++)e[a]=t[a]+e[a-r]&255}else{for(;a<r;a++)e[a]=t[a]+n[a]&255;for(;a<i;a++)e[a]=t[a]+Vn(e[a-r],n[a],n[a-r])&255}}function Vn(t,e,n){const i=t+e-n,r=Math.abs(i-t),a=Math.abs(i-e),s=Math.abs(i-n);return r<=a&&r<=s?t:a<=s?e:n}var qn;!function(t){t[t.UNKNOWN=0]="UNKNOWN",t[t.METRE=1]="METRE"}(qn||(qn={}));!function(n,i){var r=(void 0===i?{}:i).expose,a=void 0===r?E:r;function s(n){var i=this;return function(){for(var r=[],a=0;a<arguments.length;a++)r[a]=arguments[a];return t(i,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.apply(void 0,r)];case 1:return[2,z(t.sent())]}}))}))}}if("function"==typeof n)return a(s(n));var o=Object.entries(n).reduce((function(t,e){var n=e[0],i=e[1];return t[n]=s(i),t}),{});a(o)}((async t=>{return new Wn(t,e).decode();var e}))}();
|
|
2379
|
+
`;
|
|
2380
|
+
|
|
2381
|
+
function makeController() {
|
|
2382
|
+
return new TerminateController();
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2385
|
+
function makeWorker() {
|
|
2386
|
+
return BlobWorker.fromText(workerText, { name: workerName });
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
async function spawnWorker(terminate) {
|
|
2390
|
+
const fn = await spawn(makeWorker());
|
|
2391
|
+
if (terminate != null) {
|
|
2392
|
+
terminate.addThread(fn);
|
|
2393
|
+
}
|
|
2394
|
+
return (...args) => {
|
|
2395
|
+
return fn.apply(null, [...args.map((a) => makeTransferable(a))]);
|
|
2396
|
+
};
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
function spawnPool(options) {
|
|
2400
|
+
return Pool(() => spawnWorker(options.terminate), options);
|
|
2401
|
+
}
|
|
2402
|
+
|
|
2403
|
+
export { makeController, makeWorker, spawnPool, spawnWorker };
|
|
2404
|
+
|
|
2405
|
+
//# sourceMappingURL=png-decoder.js.map
|