@crxjs/vite-plugin 2.0.0-beta.1 → 2.0.0-beta.10
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/README.md +1 -1
- package/dist/index.cjs +0 -3587
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +377 -2115
- package/package.json +26 -32
package/dist/index.cjs
CHANGED
|
@@ -2,3434 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var acornWalk = require('acorn-walk');
|
|
6
|
-
var crypto = require('crypto');
|
|
7
|
-
var debug$2 = require('debug');
|
|
8
|
-
var v8 = require('v8');
|
|
9
|
-
var path = require('path');
|
|
10
|
-
var fsx = require('fs-extra');
|
|
11
|
-
var perf_hooks = require('perf_hooks');
|
|
12
|
-
var rollup = require('rollup');
|
|
13
|
-
var lexer = require('es-module-lexer');
|
|
14
|
-
var promises = require('fs/promises');
|
|
15
|
-
var MagicString = require('magic-string');
|
|
16
|
-
var vite = require('vite');
|
|
17
|
-
var fs = require('fs');
|
|
18
|
-
var module$1 = require('module');
|
|
19
|
-
var fg = require('fast-glob');
|
|
20
|
-
var getPort = require('get-port');
|
|
21
|
-
var cheerio = require('cheerio');
|
|
22
|
-
var jsesc = require('jsesc');
|
|
23
|
-
var colors = require('picocolors');
|
|
24
|
-
|
|
25
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
26
|
-
|
|
27
|
-
function _interopNamespace(e) {
|
|
28
|
-
if (e && e.__esModule) return e;
|
|
29
|
-
var n = Object.create(null);
|
|
30
|
-
if (e) {
|
|
31
|
-
Object.keys(e).forEach(function (k) {
|
|
32
|
-
if (k !== 'default') {
|
|
33
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
34
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
get: function () { return e[k]; }
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
n["default"] = e;
|
|
42
|
-
return Object.freeze(n);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
var debug__default = /*#__PURE__*/_interopDefaultLegacy(debug$2);
|
|
46
|
-
var v8__default = /*#__PURE__*/_interopDefaultLegacy(v8);
|
|
47
|
-
var fsx__default = /*#__PURE__*/_interopDefaultLegacy(fsx);
|
|
48
|
-
var lexer__namespace = /*#__PURE__*/_interopNamespace(lexer);
|
|
49
|
-
var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
|
|
50
|
-
var fg__default = /*#__PURE__*/_interopDefaultLegacy(fg);
|
|
51
|
-
var getPort__default = /*#__PURE__*/_interopDefaultLegacy(getPort);
|
|
52
|
-
var jsesc__default = /*#__PURE__*/_interopDefaultLegacy(jsesc);
|
|
53
|
-
var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
|
|
54
|
-
|
|
55
|
-
const pluginName$1 = "crx:optionsProvider";
|
|
56
|
-
const pluginOptionsProvider = (options) => {
|
|
57
|
-
return {
|
|
58
|
-
name: pluginName$1,
|
|
59
|
-
api: {
|
|
60
|
-
crx: {
|
|
61
|
-
options
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
const getOptions = ({ plugins }) => {
|
|
67
|
-
if (typeof plugins === "undefined") {
|
|
68
|
-
throw new Error("config.plugins is undefined");
|
|
69
|
-
}
|
|
70
|
-
let options;
|
|
71
|
-
for (const p of plugins.flat()) {
|
|
72
|
-
if (isCrxPlugin(p)) {
|
|
73
|
-
if (p.name === pluginName$1) {
|
|
74
|
-
const plugin = p;
|
|
75
|
-
options = plugin.api.crx.options;
|
|
76
|
-
if (options)
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (typeof options === "undefined") {
|
|
82
|
-
throw Error("Unable to get CRXJS options");
|
|
83
|
-
}
|
|
84
|
-
return options;
|
|
85
|
-
};
|
|
86
|
-
function isCrxPlugin(p) {
|
|
87
|
-
return !!p && typeof p === "object" && !(p instanceof Promise) && !Array.isArray(p) && p.name.startsWith("crx:");
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
var workerHmrClient = "const ownOrigin = new URL(chrome.runtime.getURL(\"/\")).origin;\nself.addEventListener(\"fetch\", (fetchEvent) => {\n const url = new URL(fetchEvent.request.url);\n if (url.origin === ownOrigin) {\n fetchEvent.respondWith(sendToServer(url));\n }\n});\nasync function sendToServer(url) {\n url.protocol = \"http:\";\n url.host = \"localhost\";\n url.port = __SERVER_PORT__;\n url.searchParams.set(\"t\", Date.now().toString());\n const response = await fetch(url.href.replace(/=$|=(?=&)/g, \"\"));\n return new Response(response.body, {\n headers: {\n \"Content-Type\": response.headers.get(\"Content-Type\") ?? \"text/javascript\"\n }\n });\n}\nconst ports = /* @__PURE__ */ new Set();\nchrome.runtime.onConnect.addListener((port) => {\n if (port.name === \"@crx/client\") {\n ports.add(port);\n port.onDisconnect.addListener((port2) => ports.delete(port2));\n port.onMessage.addListener((message) => {\n });\n port.postMessage({ data: JSON.stringify({ type: \"connected\" }) });\n }\n});\nfunction notifyContentScripts(payload) {\n const data = JSON.stringify(payload);\n for (const port of ports)\n port.postMessage({ data });\n}\nconsole.log(\"[vite] connecting...\");\nconst socketProtocol = __HMR_PROTOCOL__ || (location.protocol === \"https:\" ? \"wss\" : \"ws\");\nconst socketHost = `${__HMR_HOSTNAME__ || location.hostname}:${__HMR_PORT__}`;\nconst socket = new WebSocket(`${socketProtocol}://${socketHost}`, \"vite-hmr\");\nconst base = __BASE__ || \"/\";\nsocket.addEventListener(\"message\", async ({ data }) => {\n handleSocketMessage(JSON.parse(data));\n});\nfunction isCrxHmrPayload(x) {\n return x.type === \"custom\" && x.event.startsWith(\"crx:\");\n}\nfunction handleSocketMessage(payload) {\n if (isCrxHmrPayload(payload)) {\n handleCrxHmrPayload(payload);\n } else if (payload.type === \"connected\") {\n console.log(`[vite] connected.`);\n const interval = setInterval(() => socket.send(\"ping\"), __HMR_TIMEOUT__);\n socket.addEventListener(\"close\", () => clearInterval(interval));\n }\n}\nfunction handleCrxHmrPayload(payload) {\n notifyContentScripts(payload);\n switch (payload.event) {\n case \"crx:runtime-reload\":\n console.log(\"[crx] runtime reload\");\n chrome.runtime.reload();\n break;\n }\n}\nasync function waitForSuccessfulPing(ms = 1e3) {\n while (true) {\n try {\n await fetch(`${base}__vite_ping`);\n break;\n } catch (e) {\n await new Promise((resolve) => setTimeout(resolve, ms));\n }\n }\n}\nsocket.addEventListener(\"close\", async ({ wasClean }) => {\n if (wasClean)\n return;\n console.log(`[vite] server connection lost. polling for restart...`);\n await waitForSuccessfulPing();\n handleCrxHmrPayload({\n type: \"custom\",\n event: \"crx:runtime-reload\"\n });\n});\n";
|
|
91
|
-
|
|
92
|
-
const _debug = (id) => debug__default["default"]("crx").extend(id);
|
|
93
|
-
const structuredClone = (obj) => {
|
|
94
|
-
return v8__default["default"].deserialize(v8__default["default"].serialize(obj));
|
|
95
|
-
};
|
|
96
|
-
const hash = (data, length = 5) => crypto.createHash("sha1").update(data).digest("base64").replace(/[^A-Za-z0-9]/g, "").slice(0, length);
|
|
97
|
-
const isString = (x) => typeof x === "string";
|
|
98
|
-
function isObject(value) {
|
|
99
|
-
return Object.prototype.toString.call(value) === "[object Object]";
|
|
100
|
-
}
|
|
101
|
-
const isResourceByMatch = (x) => "matches" in x;
|
|
102
|
-
function decodeManifest(code) {
|
|
103
|
-
const tree = this.parse(code);
|
|
104
|
-
let literal;
|
|
105
|
-
let templateElement;
|
|
106
|
-
acornWalk.simple(tree, {
|
|
107
|
-
Literal(node) {
|
|
108
|
-
literal = node;
|
|
109
|
-
},
|
|
110
|
-
TemplateElement(node) {
|
|
111
|
-
templateElement = node;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
let manifestJson = literal?.value;
|
|
115
|
-
if (!manifestJson)
|
|
116
|
-
manifestJson = templateElement?.value?.cooked;
|
|
117
|
-
if (!manifestJson)
|
|
118
|
-
throw new Error("unable to parse manifest code");
|
|
119
|
-
let result = JSON.parse(manifestJson);
|
|
120
|
-
if (typeof result === "string")
|
|
121
|
-
result = JSON.parse(result);
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
function encodeManifest(manifest) {
|
|
125
|
-
const json = JSON.stringify(JSON.stringify(manifest));
|
|
126
|
-
return `export default ${json}`;
|
|
127
|
-
}
|
|
128
|
-
function parseJsonAsset(bundle, key) {
|
|
129
|
-
const asset = bundle[key];
|
|
130
|
-
if (typeof asset === "undefined")
|
|
131
|
-
throw new TypeError(`OutputBundle["${key}"] is undefined.`);
|
|
132
|
-
if (asset.type !== "asset")
|
|
133
|
-
throw new Error(`OutputBundle["${key}"] is not an OutputAsset.`);
|
|
134
|
-
if (typeof asset.source !== "string")
|
|
135
|
-
throw new TypeError(`OutputBundle["${key}"].source is not a string.`);
|
|
136
|
-
return JSON.parse(asset.source);
|
|
137
|
-
}
|
|
138
|
-
const getMatchPatternOrigin = (pattern) => {
|
|
139
|
-
if (pattern.startsWith("<"))
|
|
140
|
-
return pattern;
|
|
141
|
-
const [schema, rest] = pattern.split("://");
|
|
142
|
-
const [origin, pathname] = rest.split("/");
|
|
143
|
-
const root = `${schema}://${origin}`;
|
|
144
|
-
return pathname ? `${root}/*` : root;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const {
|
|
148
|
-
basename,
|
|
149
|
-
dirname,
|
|
150
|
-
extname,
|
|
151
|
-
delimiter,
|
|
152
|
-
format,
|
|
153
|
-
isAbsolute,
|
|
154
|
-
join,
|
|
155
|
-
normalize,
|
|
156
|
-
parse,
|
|
157
|
-
relative,
|
|
158
|
-
resolve,
|
|
159
|
-
toNamespacedPath,
|
|
160
|
-
sep
|
|
161
|
-
} = path.posix;
|
|
162
|
-
|
|
163
|
-
function defineClientValues(code, config) {
|
|
164
|
-
let options = config.server.hmr;
|
|
165
|
-
options = options && typeof options !== "boolean" ? options : {};
|
|
166
|
-
const host = options.host || null;
|
|
167
|
-
const protocol = options.protocol || null;
|
|
168
|
-
const timeout = options.timeout || 3e4;
|
|
169
|
-
const overlay = options.overlay !== false;
|
|
170
|
-
let hmrPort;
|
|
171
|
-
if (isObject(config.server.hmr)) {
|
|
172
|
-
hmrPort = config.server.hmr.clientPort || config.server.hmr.port;
|
|
173
|
-
}
|
|
174
|
-
if (config.server.middlewareMode) {
|
|
175
|
-
hmrPort = String(hmrPort || 24678);
|
|
176
|
-
} else {
|
|
177
|
-
hmrPort = String(hmrPort || options.port || config.server.port);
|
|
178
|
-
}
|
|
179
|
-
let hmrBase = config.base;
|
|
180
|
-
if (options.path) {
|
|
181
|
-
hmrBase = join(hmrBase, options.path);
|
|
182
|
-
}
|
|
183
|
-
if (hmrBase !== "/") {
|
|
184
|
-
hmrPort = normalize(`${hmrPort}${hmrBase}`);
|
|
185
|
-
}
|
|
186
|
-
return code.replace(`__MODE__`, JSON.stringify(config.mode)).replace(`__BASE__`, JSON.stringify(config.base)).replace(`__DEFINES__`, serializeDefine(config.define || {})).replace(`__HMR_PROTOCOL__`, JSON.stringify(protocol)).replace(`__HMR_HOSTNAME__`, JSON.stringify(host)).replace(`__HMR_PORT__`, JSON.stringify(hmrPort)).replace(`__HMR_TIMEOUT__`, JSON.stringify(timeout)).replace(`__HMR_ENABLE_OVERLAY__`, JSON.stringify(overlay)).replace(`__SERVER_PORT__`, JSON.stringify(config.server.port?.toString()));
|
|
187
|
-
function serializeDefine(define) {
|
|
188
|
-
let res = `{`;
|
|
189
|
-
for (const key in define) {
|
|
190
|
-
const val = define[key];
|
|
191
|
-
res += `${JSON.stringify(key)}: ${typeof val === "string" ? `(${val})` : JSON.stringify(val)}, `;
|
|
192
|
-
}
|
|
193
|
-
return res + `}`;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/******************************************************************************
|
|
198
|
-
Copyright (c) Microsoft Corporation.
|
|
199
|
-
|
|
200
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
201
|
-
purpose with or without fee is hereby granted.
|
|
202
|
-
|
|
203
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
204
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
205
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
206
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
207
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
208
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
209
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
210
|
-
***************************************************************************** */
|
|
211
|
-
/* global Reflect, Promise */
|
|
212
|
-
|
|
213
|
-
var extendStatics = function(d, b) {
|
|
214
|
-
extendStatics = Object.setPrototypeOf ||
|
|
215
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
216
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
217
|
-
return extendStatics(d, b);
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
function __extends(d, b) {
|
|
221
|
-
if (typeof b !== "function" && b !== null)
|
|
222
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
223
|
-
extendStatics(d, b);
|
|
224
|
-
function __() { this.constructor = d; }
|
|
225
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
229
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
230
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
231
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
232
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
233
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
234
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function __generator(thisArg, body) {
|
|
239
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
240
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
241
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
242
|
-
function step(op) {
|
|
243
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
244
|
-
while (_) try {
|
|
245
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
246
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
247
|
-
switch (op[0]) {
|
|
248
|
-
case 0: case 1: t = op; break;
|
|
249
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
250
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
251
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
252
|
-
default:
|
|
253
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
254
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
255
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
256
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
257
|
-
if (t[2]) _.ops.pop();
|
|
258
|
-
_.trys.pop(); continue;
|
|
259
|
-
}
|
|
260
|
-
op = body.call(thisArg, _);
|
|
261
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
262
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function __values(o) {
|
|
267
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
268
|
-
if (m) return m.call(o);
|
|
269
|
-
if (o && typeof o.length === "number") return {
|
|
270
|
-
next: function () {
|
|
271
|
-
if (o && i >= o.length) o = void 0;
|
|
272
|
-
return { value: o && o[i++], done: !o };
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function __read(o, n) {
|
|
279
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
280
|
-
if (!m) return o;
|
|
281
|
-
var i = m.call(o), r, ar = [], e;
|
|
282
|
-
try {
|
|
283
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
284
|
-
}
|
|
285
|
-
catch (error) { e = { error: error }; }
|
|
286
|
-
finally {
|
|
287
|
-
try {
|
|
288
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
289
|
-
}
|
|
290
|
-
finally { if (e) throw e.error; }
|
|
291
|
-
}
|
|
292
|
-
return ar;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
function __spreadArray(to, from, pack) {
|
|
296
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
297
|
-
if (ar || !(i in from)) {
|
|
298
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
299
|
-
ar[i] = from[i];
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function __await(v) {
|
|
306
|
-
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
310
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
311
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
312
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
313
|
-
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
314
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
315
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
316
|
-
function fulfill(value) { resume("next", value); }
|
|
317
|
-
function reject(value) { resume("throw", value); }
|
|
318
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function __asyncValues(o) {
|
|
322
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
323
|
-
var m = o[Symbol.asyncIterator], i;
|
|
324
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
325
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
326
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
function isFunction(value) {
|
|
330
|
-
return typeof value === 'function';
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
function createErrorClass(createImpl) {
|
|
334
|
-
var _super = function (instance) {
|
|
335
|
-
Error.call(instance);
|
|
336
|
-
instance.stack = new Error().stack;
|
|
337
|
-
};
|
|
338
|
-
var ctorFunc = createImpl(_super);
|
|
339
|
-
ctorFunc.prototype = Object.create(Error.prototype);
|
|
340
|
-
ctorFunc.prototype.constructor = ctorFunc;
|
|
341
|
-
return ctorFunc;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
var UnsubscriptionError = createErrorClass(function (_super) {
|
|
345
|
-
return function UnsubscriptionErrorImpl(errors) {
|
|
346
|
-
_super(this);
|
|
347
|
-
this.message = errors
|
|
348
|
-
? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ')
|
|
349
|
-
: '';
|
|
350
|
-
this.name = 'UnsubscriptionError';
|
|
351
|
-
this.errors = errors;
|
|
352
|
-
};
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
function arrRemove(arr, item) {
|
|
356
|
-
if (arr) {
|
|
357
|
-
var index = arr.indexOf(item);
|
|
358
|
-
0 <= index && arr.splice(index, 1);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
var Subscription = (function () {
|
|
363
|
-
function Subscription(initialTeardown) {
|
|
364
|
-
this.initialTeardown = initialTeardown;
|
|
365
|
-
this.closed = false;
|
|
366
|
-
this._parentage = null;
|
|
367
|
-
this._finalizers = null;
|
|
368
|
-
}
|
|
369
|
-
Subscription.prototype.unsubscribe = function () {
|
|
370
|
-
var e_1, _a, e_2, _b;
|
|
371
|
-
var errors;
|
|
372
|
-
if (!this.closed) {
|
|
373
|
-
this.closed = true;
|
|
374
|
-
var _parentage = this._parentage;
|
|
375
|
-
if (_parentage) {
|
|
376
|
-
this._parentage = null;
|
|
377
|
-
if (Array.isArray(_parentage)) {
|
|
378
|
-
try {
|
|
379
|
-
for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
|
|
380
|
-
var parent_1 = _parentage_1_1.value;
|
|
381
|
-
parent_1.remove(this);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
385
|
-
finally {
|
|
386
|
-
try {
|
|
387
|
-
if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
|
|
388
|
-
}
|
|
389
|
-
finally { if (e_1) throw e_1.error; }
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
else {
|
|
393
|
-
_parentage.remove(this);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
var initialFinalizer = this.initialTeardown;
|
|
397
|
-
if (isFunction(initialFinalizer)) {
|
|
398
|
-
try {
|
|
399
|
-
initialFinalizer();
|
|
400
|
-
}
|
|
401
|
-
catch (e) {
|
|
402
|
-
errors = e instanceof UnsubscriptionError ? e.errors : [e];
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
var _finalizers = this._finalizers;
|
|
406
|
-
if (_finalizers) {
|
|
407
|
-
this._finalizers = null;
|
|
408
|
-
try {
|
|
409
|
-
for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
|
|
410
|
-
var finalizer = _finalizers_1_1.value;
|
|
411
|
-
try {
|
|
412
|
-
execFinalizer(finalizer);
|
|
413
|
-
}
|
|
414
|
-
catch (err) {
|
|
415
|
-
errors = errors !== null && errors !== void 0 ? errors : [];
|
|
416
|
-
if (err instanceof UnsubscriptionError) {
|
|
417
|
-
errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
420
|
-
errors.push(err);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
426
|
-
finally {
|
|
427
|
-
try {
|
|
428
|
-
if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
|
|
429
|
-
}
|
|
430
|
-
finally { if (e_2) throw e_2.error; }
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
if (errors) {
|
|
434
|
-
throw new UnsubscriptionError(errors);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
Subscription.prototype.add = function (teardown) {
|
|
439
|
-
var _a;
|
|
440
|
-
if (teardown && teardown !== this) {
|
|
441
|
-
if (this.closed) {
|
|
442
|
-
execFinalizer(teardown);
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
if (teardown instanceof Subscription) {
|
|
446
|
-
if (teardown.closed || teardown._hasParent(this)) {
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
teardown._addParent(this);
|
|
450
|
-
}
|
|
451
|
-
(this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
Subscription.prototype._hasParent = function (parent) {
|
|
456
|
-
var _parentage = this._parentage;
|
|
457
|
-
return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));
|
|
458
|
-
};
|
|
459
|
-
Subscription.prototype._addParent = function (parent) {
|
|
460
|
-
var _parentage = this._parentage;
|
|
461
|
-
this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
|
|
462
|
-
};
|
|
463
|
-
Subscription.prototype._removeParent = function (parent) {
|
|
464
|
-
var _parentage = this._parentage;
|
|
465
|
-
if (_parentage === parent) {
|
|
466
|
-
this._parentage = null;
|
|
467
|
-
}
|
|
468
|
-
else if (Array.isArray(_parentage)) {
|
|
469
|
-
arrRemove(_parentage, parent);
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
Subscription.prototype.remove = function (teardown) {
|
|
473
|
-
var _finalizers = this._finalizers;
|
|
474
|
-
_finalizers && arrRemove(_finalizers, teardown);
|
|
475
|
-
if (teardown instanceof Subscription) {
|
|
476
|
-
teardown._removeParent(this);
|
|
477
|
-
}
|
|
478
|
-
};
|
|
479
|
-
Subscription.EMPTY = (function () {
|
|
480
|
-
var empty = new Subscription();
|
|
481
|
-
empty.closed = true;
|
|
482
|
-
return empty;
|
|
483
|
-
})();
|
|
484
|
-
return Subscription;
|
|
485
|
-
}());
|
|
486
|
-
var EMPTY_SUBSCRIPTION = Subscription.EMPTY;
|
|
487
|
-
function isSubscription(value) {
|
|
488
|
-
return (value instanceof Subscription ||
|
|
489
|
-
(value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe)));
|
|
490
|
-
}
|
|
491
|
-
function execFinalizer(finalizer) {
|
|
492
|
-
if (isFunction(finalizer)) {
|
|
493
|
-
finalizer();
|
|
494
|
-
}
|
|
495
|
-
else {
|
|
496
|
-
finalizer.unsubscribe();
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
var config = {
|
|
501
|
-
onUnhandledError: null,
|
|
502
|
-
onStoppedNotification: null,
|
|
503
|
-
Promise: undefined,
|
|
504
|
-
useDeprecatedSynchronousErrorHandling: false,
|
|
505
|
-
useDeprecatedNextContext: false,
|
|
506
|
-
};
|
|
507
|
-
|
|
508
|
-
var timeoutProvider = {
|
|
509
|
-
setTimeout: function (handler, timeout) {
|
|
510
|
-
var args = [];
|
|
511
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
512
|
-
args[_i - 2] = arguments[_i];
|
|
513
|
-
}
|
|
514
|
-
var delegate = timeoutProvider.delegate;
|
|
515
|
-
if (delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) {
|
|
516
|
-
return delegate.setTimeout.apply(delegate, __spreadArray([handler, timeout], __read(args)));
|
|
517
|
-
}
|
|
518
|
-
return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
519
|
-
},
|
|
520
|
-
clearTimeout: function (handle) {
|
|
521
|
-
var delegate = timeoutProvider.delegate;
|
|
522
|
-
return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle);
|
|
523
|
-
},
|
|
524
|
-
delegate: undefined,
|
|
525
|
-
};
|
|
526
|
-
|
|
527
|
-
function reportUnhandledError(err) {
|
|
528
|
-
timeoutProvider.setTimeout(function () {
|
|
529
|
-
{
|
|
530
|
-
throw err;
|
|
531
|
-
}
|
|
532
|
-
});
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
function noop() { }
|
|
536
|
-
|
|
537
|
-
var COMPLETE_NOTIFICATION = (function () { return createNotification('C', undefined, undefined); })();
|
|
538
|
-
function errorNotification(error) {
|
|
539
|
-
return createNotification('E', undefined, error);
|
|
540
|
-
}
|
|
541
|
-
function nextNotification(value) {
|
|
542
|
-
return createNotification('N', value, undefined);
|
|
543
|
-
}
|
|
544
|
-
function createNotification(kind, value, error) {
|
|
545
|
-
return {
|
|
546
|
-
kind: kind,
|
|
547
|
-
value: value,
|
|
548
|
-
error: error,
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
var context = null;
|
|
553
|
-
function errorContext(cb) {
|
|
554
|
-
if (config.useDeprecatedSynchronousErrorHandling) {
|
|
555
|
-
var isRoot = !context;
|
|
556
|
-
if (isRoot) {
|
|
557
|
-
context = { errorThrown: false, error: null };
|
|
558
|
-
}
|
|
559
|
-
cb();
|
|
560
|
-
if (isRoot) {
|
|
561
|
-
var _a = context, errorThrown = _a.errorThrown, error = _a.error;
|
|
562
|
-
context = null;
|
|
563
|
-
if (errorThrown) {
|
|
564
|
-
throw error;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
else {
|
|
569
|
-
cb();
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
var Subscriber = (function (_super) {
|
|
574
|
-
__extends(Subscriber, _super);
|
|
575
|
-
function Subscriber(destination) {
|
|
576
|
-
var _this = _super.call(this) || this;
|
|
577
|
-
_this.isStopped = false;
|
|
578
|
-
if (destination) {
|
|
579
|
-
_this.destination = destination;
|
|
580
|
-
if (isSubscription(destination)) {
|
|
581
|
-
destination.add(_this);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
else {
|
|
585
|
-
_this.destination = EMPTY_OBSERVER;
|
|
586
|
-
}
|
|
587
|
-
return _this;
|
|
588
|
-
}
|
|
589
|
-
Subscriber.create = function (next, error, complete) {
|
|
590
|
-
return new SafeSubscriber(next, error, complete);
|
|
591
|
-
};
|
|
592
|
-
Subscriber.prototype.next = function (value) {
|
|
593
|
-
if (this.isStopped) {
|
|
594
|
-
handleStoppedNotification(nextNotification(value), this);
|
|
595
|
-
}
|
|
596
|
-
else {
|
|
597
|
-
this._next(value);
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
Subscriber.prototype.error = function (err) {
|
|
601
|
-
if (this.isStopped) {
|
|
602
|
-
handleStoppedNotification(errorNotification(err), this);
|
|
603
|
-
}
|
|
604
|
-
else {
|
|
605
|
-
this.isStopped = true;
|
|
606
|
-
this._error(err);
|
|
607
|
-
}
|
|
608
|
-
};
|
|
609
|
-
Subscriber.prototype.complete = function () {
|
|
610
|
-
if (this.isStopped) {
|
|
611
|
-
handleStoppedNotification(COMPLETE_NOTIFICATION, this);
|
|
612
|
-
}
|
|
613
|
-
else {
|
|
614
|
-
this.isStopped = true;
|
|
615
|
-
this._complete();
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
Subscriber.prototype.unsubscribe = function () {
|
|
619
|
-
if (!this.closed) {
|
|
620
|
-
this.isStopped = true;
|
|
621
|
-
_super.prototype.unsubscribe.call(this);
|
|
622
|
-
this.destination = null;
|
|
623
|
-
}
|
|
624
|
-
};
|
|
625
|
-
Subscriber.prototype._next = function (value) {
|
|
626
|
-
this.destination.next(value);
|
|
627
|
-
};
|
|
628
|
-
Subscriber.prototype._error = function (err) {
|
|
629
|
-
try {
|
|
630
|
-
this.destination.error(err);
|
|
631
|
-
}
|
|
632
|
-
finally {
|
|
633
|
-
this.unsubscribe();
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
Subscriber.prototype._complete = function () {
|
|
637
|
-
try {
|
|
638
|
-
this.destination.complete();
|
|
639
|
-
}
|
|
640
|
-
finally {
|
|
641
|
-
this.unsubscribe();
|
|
642
|
-
}
|
|
643
|
-
};
|
|
644
|
-
return Subscriber;
|
|
645
|
-
}(Subscription));
|
|
646
|
-
var _bind = Function.prototype.bind;
|
|
647
|
-
function bind(fn, thisArg) {
|
|
648
|
-
return _bind.call(fn, thisArg);
|
|
649
|
-
}
|
|
650
|
-
var ConsumerObserver = (function () {
|
|
651
|
-
function ConsumerObserver(partialObserver) {
|
|
652
|
-
this.partialObserver = partialObserver;
|
|
653
|
-
}
|
|
654
|
-
ConsumerObserver.prototype.next = function (value) {
|
|
655
|
-
var partialObserver = this.partialObserver;
|
|
656
|
-
if (partialObserver.next) {
|
|
657
|
-
try {
|
|
658
|
-
partialObserver.next(value);
|
|
659
|
-
}
|
|
660
|
-
catch (error) {
|
|
661
|
-
handleUnhandledError(error);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
};
|
|
665
|
-
ConsumerObserver.prototype.error = function (err) {
|
|
666
|
-
var partialObserver = this.partialObserver;
|
|
667
|
-
if (partialObserver.error) {
|
|
668
|
-
try {
|
|
669
|
-
partialObserver.error(err);
|
|
670
|
-
}
|
|
671
|
-
catch (error) {
|
|
672
|
-
handleUnhandledError(error);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
else {
|
|
676
|
-
handleUnhandledError(err);
|
|
677
|
-
}
|
|
678
|
-
};
|
|
679
|
-
ConsumerObserver.prototype.complete = function () {
|
|
680
|
-
var partialObserver = this.partialObserver;
|
|
681
|
-
if (partialObserver.complete) {
|
|
682
|
-
try {
|
|
683
|
-
partialObserver.complete();
|
|
684
|
-
}
|
|
685
|
-
catch (error) {
|
|
686
|
-
handleUnhandledError(error);
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
};
|
|
690
|
-
return ConsumerObserver;
|
|
691
|
-
}());
|
|
692
|
-
var SafeSubscriber = (function (_super) {
|
|
693
|
-
__extends(SafeSubscriber, _super);
|
|
694
|
-
function SafeSubscriber(observerOrNext, error, complete) {
|
|
695
|
-
var _this = _super.call(this) || this;
|
|
696
|
-
var partialObserver;
|
|
697
|
-
if (isFunction(observerOrNext) || !observerOrNext) {
|
|
698
|
-
partialObserver = {
|
|
699
|
-
next: observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined,
|
|
700
|
-
error: error !== null && error !== void 0 ? error : undefined,
|
|
701
|
-
complete: complete !== null && complete !== void 0 ? complete : undefined,
|
|
702
|
-
};
|
|
703
|
-
}
|
|
704
|
-
else {
|
|
705
|
-
var context_1;
|
|
706
|
-
if (_this && config.useDeprecatedNextContext) {
|
|
707
|
-
context_1 = Object.create(observerOrNext);
|
|
708
|
-
context_1.unsubscribe = function () { return _this.unsubscribe(); };
|
|
709
|
-
partialObserver = {
|
|
710
|
-
next: observerOrNext.next && bind(observerOrNext.next, context_1),
|
|
711
|
-
error: observerOrNext.error && bind(observerOrNext.error, context_1),
|
|
712
|
-
complete: observerOrNext.complete && bind(observerOrNext.complete, context_1),
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
else {
|
|
716
|
-
partialObserver = observerOrNext;
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
_this.destination = new ConsumerObserver(partialObserver);
|
|
720
|
-
return _this;
|
|
721
|
-
}
|
|
722
|
-
return SafeSubscriber;
|
|
723
|
-
}(Subscriber));
|
|
724
|
-
function handleUnhandledError(error) {
|
|
725
|
-
{
|
|
726
|
-
reportUnhandledError(error);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
function defaultErrorHandler(err) {
|
|
730
|
-
throw err;
|
|
731
|
-
}
|
|
732
|
-
function handleStoppedNotification(notification, subscriber) {
|
|
733
|
-
var onStoppedNotification = config.onStoppedNotification;
|
|
734
|
-
onStoppedNotification && timeoutProvider.setTimeout(function () { return onStoppedNotification(notification, subscriber); });
|
|
735
|
-
}
|
|
736
|
-
var EMPTY_OBSERVER = {
|
|
737
|
-
closed: true,
|
|
738
|
-
next: noop,
|
|
739
|
-
error: defaultErrorHandler,
|
|
740
|
-
complete: noop,
|
|
741
|
-
};
|
|
742
|
-
|
|
743
|
-
var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })();
|
|
744
|
-
|
|
745
|
-
function identity(x) {
|
|
746
|
-
return x;
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
function pipeFromArray(fns) {
|
|
750
|
-
if (fns.length === 0) {
|
|
751
|
-
return identity;
|
|
752
|
-
}
|
|
753
|
-
if (fns.length === 1) {
|
|
754
|
-
return fns[0];
|
|
755
|
-
}
|
|
756
|
-
return function piped(input) {
|
|
757
|
-
return fns.reduce(function (prev, fn) { return fn(prev); }, input);
|
|
758
|
-
};
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
var Observable = (function () {
|
|
762
|
-
function Observable(subscribe) {
|
|
763
|
-
if (subscribe) {
|
|
764
|
-
this._subscribe = subscribe;
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
Observable.prototype.lift = function (operator) {
|
|
768
|
-
var observable = new Observable();
|
|
769
|
-
observable.source = this;
|
|
770
|
-
observable.operator = operator;
|
|
771
|
-
return observable;
|
|
772
|
-
};
|
|
773
|
-
Observable.prototype.subscribe = function (observerOrNext, error, complete) {
|
|
774
|
-
var _this = this;
|
|
775
|
-
var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
|
|
776
|
-
errorContext(function () {
|
|
777
|
-
var _a = _this, operator = _a.operator, source = _a.source;
|
|
778
|
-
subscriber.add(operator
|
|
779
|
-
?
|
|
780
|
-
operator.call(subscriber, source)
|
|
781
|
-
: source
|
|
782
|
-
?
|
|
783
|
-
_this._subscribe(subscriber)
|
|
784
|
-
:
|
|
785
|
-
_this._trySubscribe(subscriber));
|
|
786
|
-
});
|
|
787
|
-
return subscriber;
|
|
788
|
-
};
|
|
789
|
-
Observable.prototype._trySubscribe = function (sink) {
|
|
790
|
-
try {
|
|
791
|
-
return this._subscribe(sink);
|
|
792
|
-
}
|
|
793
|
-
catch (err) {
|
|
794
|
-
sink.error(err);
|
|
795
|
-
}
|
|
796
|
-
};
|
|
797
|
-
Observable.prototype.forEach = function (next, promiseCtor) {
|
|
798
|
-
var _this = this;
|
|
799
|
-
promiseCtor = getPromiseCtor(promiseCtor);
|
|
800
|
-
return new promiseCtor(function (resolve, reject) {
|
|
801
|
-
var subscriber = new SafeSubscriber({
|
|
802
|
-
next: function (value) {
|
|
803
|
-
try {
|
|
804
|
-
next(value);
|
|
805
|
-
}
|
|
806
|
-
catch (err) {
|
|
807
|
-
reject(err);
|
|
808
|
-
subscriber.unsubscribe();
|
|
809
|
-
}
|
|
810
|
-
},
|
|
811
|
-
error: reject,
|
|
812
|
-
complete: resolve,
|
|
813
|
-
});
|
|
814
|
-
_this.subscribe(subscriber);
|
|
815
|
-
});
|
|
816
|
-
};
|
|
817
|
-
Observable.prototype._subscribe = function (subscriber) {
|
|
818
|
-
var _a;
|
|
819
|
-
return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
|
|
820
|
-
};
|
|
821
|
-
Observable.prototype[observable] = function () {
|
|
822
|
-
return this;
|
|
823
|
-
};
|
|
824
|
-
Observable.prototype.pipe = function () {
|
|
825
|
-
var operations = [];
|
|
826
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
827
|
-
operations[_i] = arguments[_i];
|
|
828
|
-
}
|
|
829
|
-
return pipeFromArray(operations)(this);
|
|
830
|
-
};
|
|
831
|
-
Observable.prototype.toPromise = function (promiseCtor) {
|
|
832
|
-
var _this = this;
|
|
833
|
-
promiseCtor = getPromiseCtor(promiseCtor);
|
|
834
|
-
return new promiseCtor(function (resolve, reject) {
|
|
835
|
-
var value;
|
|
836
|
-
_this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); });
|
|
837
|
-
});
|
|
838
|
-
};
|
|
839
|
-
Observable.create = function (subscribe) {
|
|
840
|
-
return new Observable(subscribe);
|
|
841
|
-
};
|
|
842
|
-
return Observable;
|
|
843
|
-
}());
|
|
844
|
-
function getPromiseCtor(promiseCtor) {
|
|
845
|
-
var _a;
|
|
846
|
-
return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
|
|
847
|
-
}
|
|
848
|
-
function isObserver(value) {
|
|
849
|
-
return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
|
|
850
|
-
}
|
|
851
|
-
function isSubscriber(value) {
|
|
852
|
-
return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
function hasLift(source) {
|
|
856
|
-
return isFunction(source === null || source === void 0 ? void 0 : source.lift);
|
|
857
|
-
}
|
|
858
|
-
function operate(init) {
|
|
859
|
-
return function (source) {
|
|
860
|
-
if (hasLift(source)) {
|
|
861
|
-
return source.lift(function (liftedSource) {
|
|
862
|
-
try {
|
|
863
|
-
return init(liftedSource, this);
|
|
864
|
-
}
|
|
865
|
-
catch (err) {
|
|
866
|
-
this.error(err);
|
|
867
|
-
}
|
|
868
|
-
});
|
|
869
|
-
}
|
|
870
|
-
throw new TypeError('Unable to lift unknown Observable type');
|
|
871
|
-
};
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
|
|
875
|
-
return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
|
|
876
|
-
}
|
|
877
|
-
var OperatorSubscriber = (function (_super) {
|
|
878
|
-
__extends(OperatorSubscriber, _super);
|
|
879
|
-
function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
|
|
880
|
-
var _this = _super.call(this, destination) || this;
|
|
881
|
-
_this.onFinalize = onFinalize;
|
|
882
|
-
_this.shouldUnsubscribe = shouldUnsubscribe;
|
|
883
|
-
_this._next = onNext
|
|
884
|
-
? function (value) {
|
|
885
|
-
try {
|
|
886
|
-
onNext(value);
|
|
887
|
-
}
|
|
888
|
-
catch (err) {
|
|
889
|
-
destination.error(err);
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
: _super.prototype._next;
|
|
893
|
-
_this._error = onError
|
|
894
|
-
? function (err) {
|
|
895
|
-
try {
|
|
896
|
-
onError(err);
|
|
897
|
-
}
|
|
898
|
-
catch (err) {
|
|
899
|
-
destination.error(err);
|
|
900
|
-
}
|
|
901
|
-
finally {
|
|
902
|
-
this.unsubscribe();
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
: _super.prototype._error;
|
|
906
|
-
_this._complete = onComplete
|
|
907
|
-
? function () {
|
|
908
|
-
try {
|
|
909
|
-
onComplete();
|
|
910
|
-
}
|
|
911
|
-
catch (err) {
|
|
912
|
-
destination.error(err);
|
|
913
|
-
}
|
|
914
|
-
finally {
|
|
915
|
-
this.unsubscribe();
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
: _super.prototype._complete;
|
|
919
|
-
return _this;
|
|
920
|
-
}
|
|
921
|
-
OperatorSubscriber.prototype.unsubscribe = function () {
|
|
922
|
-
var _a;
|
|
923
|
-
if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
|
|
924
|
-
var closed_1 = this.closed;
|
|
925
|
-
_super.prototype.unsubscribe.call(this);
|
|
926
|
-
!closed_1 && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
927
|
-
}
|
|
928
|
-
};
|
|
929
|
-
return OperatorSubscriber;
|
|
930
|
-
}(Subscriber));
|
|
931
|
-
|
|
932
|
-
var ObjectUnsubscribedError = createErrorClass(function (_super) {
|
|
933
|
-
return function ObjectUnsubscribedErrorImpl() {
|
|
934
|
-
_super(this);
|
|
935
|
-
this.name = 'ObjectUnsubscribedError';
|
|
936
|
-
this.message = 'object unsubscribed';
|
|
937
|
-
};
|
|
938
|
-
});
|
|
939
|
-
|
|
940
|
-
var Subject = (function (_super) {
|
|
941
|
-
__extends(Subject, _super);
|
|
942
|
-
function Subject() {
|
|
943
|
-
var _this = _super.call(this) || this;
|
|
944
|
-
_this.closed = false;
|
|
945
|
-
_this.currentObservers = null;
|
|
946
|
-
_this.observers = [];
|
|
947
|
-
_this.isStopped = false;
|
|
948
|
-
_this.hasError = false;
|
|
949
|
-
_this.thrownError = null;
|
|
950
|
-
return _this;
|
|
951
|
-
}
|
|
952
|
-
Subject.prototype.lift = function (operator) {
|
|
953
|
-
var subject = new AnonymousSubject(this, this);
|
|
954
|
-
subject.operator = operator;
|
|
955
|
-
return subject;
|
|
956
|
-
};
|
|
957
|
-
Subject.prototype._throwIfClosed = function () {
|
|
958
|
-
if (this.closed) {
|
|
959
|
-
throw new ObjectUnsubscribedError();
|
|
960
|
-
}
|
|
961
|
-
};
|
|
962
|
-
Subject.prototype.next = function (value) {
|
|
963
|
-
var _this = this;
|
|
964
|
-
errorContext(function () {
|
|
965
|
-
var e_1, _a;
|
|
966
|
-
_this._throwIfClosed();
|
|
967
|
-
if (!_this.isStopped) {
|
|
968
|
-
if (!_this.currentObservers) {
|
|
969
|
-
_this.currentObservers = Array.from(_this.observers);
|
|
970
|
-
}
|
|
971
|
-
try {
|
|
972
|
-
for (var _b = __values(_this.currentObservers), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
973
|
-
var observer = _c.value;
|
|
974
|
-
observer.next(value);
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
978
|
-
finally {
|
|
979
|
-
try {
|
|
980
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
981
|
-
}
|
|
982
|
-
finally { if (e_1) throw e_1.error; }
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
});
|
|
986
|
-
};
|
|
987
|
-
Subject.prototype.error = function (err) {
|
|
988
|
-
var _this = this;
|
|
989
|
-
errorContext(function () {
|
|
990
|
-
_this._throwIfClosed();
|
|
991
|
-
if (!_this.isStopped) {
|
|
992
|
-
_this.hasError = _this.isStopped = true;
|
|
993
|
-
_this.thrownError = err;
|
|
994
|
-
var observers = _this.observers;
|
|
995
|
-
while (observers.length) {
|
|
996
|
-
observers.shift().error(err);
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
});
|
|
1000
|
-
};
|
|
1001
|
-
Subject.prototype.complete = function () {
|
|
1002
|
-
var _this = this;
|
|
1003
|
-
errorContext(function () {
|
|
1004
|
-
_this._throwIfClosed();
|
|
1005
|
-
if (!_this.isStopped) {
|
|
1006
|
-
_this.isStopped = true;
|
|
1007
|
-
var observers = _this.observers;
|
|
1008
|
-
while (observers.length) {
|
|
1009
|
-
observers.shift().complete();
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
});
|
|
1013
|
-
};
|
|
1014
|
-
Subject.prototype.unsubscribe = function () {
|
|
1015
|
-
this.isStopped = this.closed = true;
|
|
1016
|
-
this.observers = this.currentObservers = null;
|
|
1017
|
-
};
|
|
1018
|
-
Object.defineProperty(Subject.prototype, "observed", {
|
|
1019
|
-
get: function () {
|
|
1020
|
-
var _a;
|
|
1021
|
-
return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
1022
|
-
},
|
|
1023
|
-
enumerable: false,
|
|
1024
|
-
configurable: true
|
|
1025
|
-
});
|
|
1026
|
-
Subject.prototype._trySubscribe = function (subscriber) {
|
|
1027
|
-
this._throwIfClosed();
|
|
1028
|
-
return _super.prototype._trySubscribe.call(this, subscriber);
|
|
1029
|
-
};
|
|
1030
|
-
Subject.prototype._subscribe = function (subscriber) {
|
|
1031
|
-
this._throwIfClosed();
|
|
1032
|
-
this._checkFinalizedStatuses(subscriber);
|
|
1033
|
-
return this._innerSubscribe(subscriber);
|
|
1034
|
-
};
|
|
1035
|
-
Subject.prototype._innerSubscribe = function (subscriber) {
|
|
1036
|
-
var _this = this;
|
|
1037
|
-
var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
|
|
1038
|
-
if (hasError || isStopped) {
|
|
1039
|
-
return EMPTY_SUBSCRIPTION;
|
|
1040
|
-
}
|
|
1041
|
-
this.currentObservers = null;
|
|
1042
|
-
observers.push(subscriber);
|
|
1043
|
-
return new Subscription(function () {
|
|
1044
|
-
_this.currentObservers = null;
|
|
1045
|
-
arrRemove(observers, subscriber);
|
|
1046
|
-
});
|
|
1047
|
-
};
|
|
1048
|
-
Subject.prototype._checkFinalizedStatuses = function (subscriber) {
|
|
1049
|
-
var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
|
|
1050
|
-
if (hasError) {
|
|
1051
|
-
subscriber.error(thrownError);
|
|
1052
|
-
}
|
|
1053
|
-
else if (isStopped) {
|
|
1054
|
-
subscriber.complete();
|
|
1055
|
-
}
|
|
1056
|
-
};
|
|
1057
|
-
Subject.prototype.asObservable = function () {
|
|
1058
|
-
var observable = new Observable();
|
|
1059
|
-
observable.source = this;
|
|
1060
|
-
return observable;
|
|
1061
|
-
};
|
|
1062
|
-
Subject.create = function (destination, source) {
|
|
1063
|
-
return new AnonymousSubject(destination, source);
|
|
1064
|
-
};
|
|
1065
|
-
return Subject;
|
|
1066
|
-
}(Observable));
|
|
1067
|
-
var AnonymousSubject = (function (_super) {
|
|
1068
|
-
__extends(AnonymousSubject, _super);
|
|
1069
|
-
function AnonymousSubject(destination, source) {
|
|
1070
|
-
var _this = _super.call(this) || this;
|
|
1071
|
-
_this.destination = destination;
|
|
1072
|
-
_this.source = source;
|
|
1073
|
-
return _this;
|
|
1074
|
-
}
|
|
1075
|
-
AnonymousSubject.prototype.next = function (value) {
|
|
1076
|
-
var _a, _b;
|
|
1077
|
-
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
|
|
1078
|
-
};
|
|
1079
|
-
AnonymousSubject.prototype.error = function (err) {
|
|
1080
|
-
var _a, _b;
|
|
1081
|
-
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
|
|
1082
|
-
};
|
|
1083
|
-
AnonymousSubject.prototype.complete = function () {
|
|
1084
|
-
var _a, _b;
|
|
1085
|
-
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1086
|
-
};
|
|
1087
|
-
AnonymousSubject.prototype._subscribe = function (subscriber) {
|
|
1088
|
-
var _a, _b;
|
|
1089
|
-
return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : EMPTY_SUBSCRIPTION;
|
|
1090
|
-
};
|
|
1091
|
-
return AnonymousSubject;
|
|
1092
|
-
}(Subject));
|
|
1093
|
-
|
|
1094
|
-
var dateTimestampProvider = {
|
|
1095
|
-
now: function () {
|
|
1096
|
-
return (dateTimestampProvider.delegate || Date).now();
|
|
1097
|
-
},
|
|
1098
|
-
delegate: undefined,
|
|
1099
|
-
};
|
|
1100
|
-
|
|
1101
|
-
var ReplaySubject = (function (_super) {
|
|
1102
|
-
__extends(ReplaySubject, _super);
|
|
1103
|
-
function ReplaySubject(_bufferSize, _windowTime, _timestampProvider) {
|
|
1104
|
-
if (_bufferSize === void 0) { _bufferSize = Infinity; }
|
|
1105
|
-
if (_windowTime === void 0) { _windowTime = Infinity; }
|
|
1106
|
-
if (_timestampProvider === void 0) { _timestampProvider = dateTimestampProvider; }
|
|
1107
|
-
var _this = _super.call(this) || this;
|
|
1108
|
-
_this._bufferSize = _bufferSize;
|
|
1109
|
-
_this._windowTime = _windowTime;
|
|
1110
|
-
_this._timestampProvider = _timestampProvider;
|
|
1111
|
-
_this._buffer = [];
|
|
1112
|
-
_this._infiniteTimeWindow = true;
|
|
1113
|
-
_this._infiniteTimeWindow = _windowTime === Infinity;
|
|
1114
|
-
_this._bufferSize = Math.max(1, _bufferSize);
|
|
1115
|
-
_this._windowTime = Math.max(1, _windowTime);
|
|
1116
|
-
return _this;
|
|
1117
|
-
}
|
|
1118
|
-
ReplaySubject.prototype.next = function (value) {
|
|
1119
|
-
var _a = this, isStopped = _a.isStopped, _buffer = _a._buffer, _infiniteTimeWindow = _a._infiniteTimeWindow, _timestampProvider = _a._timestampProvider, _windowTime = _a._windowTime;
|
|
1120
|
-
if (!isStopped) {
|
|
1121
|
-
_buffer.push(value);
|
|
1122
|
-
!_infiniteTimeWindow && _buffer.push(_timestampProvider.now() + _windowTime);
|
|
1123
|
-
}
|
|
1124
|
-
this._trimBuffer();
|
|
1125
|
-
_super.prototype.next.call(this, value);
|
|
1126
|
-
};
|
|
1127
|
-
ReplaySubject.prototype._subscribe = function (subscriber) {
|
|
1128
|
-
this._throwIfClosed();
|
|
1129
|
-
this._trimBuffer();
|
|
1130
|
-
var subscription = this._innerSubscribe(subscriber);
|
|
1131
|
-
var _a = this, _infiniteTimeWindow = _a._infiniteTimeWindow, _buffer = _a._buffer;
|
|
1132
|
-
var copy = _buffer.slice();
|
|
1133
|
-
for (var i = 0; i < copy.length && !subscriber.closed; i += _infiniteTimeWindow ? 1 : 2) {
|
|
1134
|
-
subscriber.next(copy[i]);
|
|
1135
|
-
}
|
|
1136
|
-
this._checkFinalizedStatuses(subscriber);
|
|
1137
|
-
return subscription;
|
|
1138
|
-
};
|
|
1139
|
-
ReplaySubject.prototype._trimBuffer = function () {
|
|
1140
|
-
var _a = this, _bufferSize = _a._bufferSize, _timestampProvider = _a._timestampProvider, _buffer = _a._buffer, _infiniteTimeWindow = _a._infiniteTimeWindow;
|
|
1141
|
-
var adjustedBufferSize = (_infiniteTimeWindow ? 1 : 2) * _bufferSize;
|
|
1142
|
-
_bufferSize < Infinity && adjustedBufferSize < _buffer.length && _buffer.splice(0, _buffer.length - adjustedBufferSize);
|
|
1143
|
-
if (!_infiniteTimeWindow) {
|
|
1144
|
-
var now = _timestampProvider.now();
|
|
1145
|
-
var last = 0;
|
|
1146
|
-
for (var i = 1; i < _buffer.length && _buffer[i] <= now; i += 2) {
|
|
1147
|
-
last = i;
|
|
1148
|
-
}
|
|
1149
|
-
last && _buffer.splice(0, last + 1);
|
|
1150
|
-
}
|
|
1151
|
-
};
|
|
1152
|
-
return ReplaySubject;
|
|
1153
|
-
}(Subject));
|
|
1154
|
-
|
|
1155
|
-
var Action = (function (_super) {
|
|
1156
|
-
__extends(Action, _super);
|
|
1157
|
-
function Action(scheduler, work) {
|
|
1158
|
-
return _super.call(this) || this;
|
|
1159
|
-
}
|
|
1160
|
-
Action.prototype.schedule = function (state, delay) {
|
|
1161
|
-
return this;
|
|
1162
|
-
};
|
|
1163
|
-
return Action;
|
|
1164
|
-
}(Subscription));
|
|
1165
|
-
|
|
1166
|
-
var intervalProvider = {
|
|
1167
|
-
setInterval: function (handler, timeout) {
|
|
1168
|
-
var args = [];
|
|
1169
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
1170
|
-
args[_i - 2] = arguments[_i];
|
|
1171
|
-
}
|
|
1172
|
-
var delegate = intervalProvider.delegate;
|
|
1173
|
-
if (delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) {
|
|
1174
|
-
return delegate.setInterval.apply(delegate, __spreadArray([handler, timeout], __read(args)));
|
|
1175
|
-
}
|
|
1176
|
-
return setInterval.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
1177
|
-
},
|
|
1178
|
-
clearInterval: function (handle) {
|
|
1179
|
-
var delegate = intervalProvider.delegate;
|
|
1180
|
-
return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearInterval) || clearInterval)(handle);
|
|
1181
|
-
},
|
|
1182
|
-
delegate: undefined,
|
|
1183
|
-
};
|
|
1184
|
-
|
|
1185
|
-
var AsyncAction = (function (_super) {
|
|
1186
|
-
__extends(AsyncAction, _super);
|
|
1187
|
-
function AsyncAction(scheduler, work) {
|
|
1188
|
-
var _this = _super.call(this, scheduler, work) || this;
|
|
1189
|
-
_this.scheduler = scheduler;
|
|
1190
|
-
_this.work = work;
|
|
1191
|
-
_this.pending = false;
|
|
1192
|
-
return _this;
|
|
1193
|
-
}
|
|
1194
|
-
AsyncAction.prototype.schedule = function (state, delay) {
|
|
1195
|
-
if (delay === void 0) { delay = 0; }
|
|
1196
|
-
if (this.closed) {
|
|
1197
|
-
return this;
|
|
1198
|
-
}
|
|
1199
|
-
this.state = state;
|
|
1200
|
-
var id = this.id;
|
|
1201
|
-
var scheduler = this.scheduler;
|
|
1202
|
-
if (id != null) {
|
|
1203
|
-
this.id = this.recycleAsyncId(scheduler, id, delay);
|
|
1204
|
-
}
|
|
1205
|
-
this.pending = true;
|
|
1206
|
-
this.delay = delay;
|
|
1207
|
-
this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
|
|
1208
|
-
return this;
|
|
1209
|
-
};
|
|
1210
|
-
AsyncAction.prototype.requestAsyncId = function (scheduler, _id, delay) {
|
|
1211
|
-
if (delay === void 0) { delay = 0; }
|
|
1212
|
-
return intervalProvider.setInterval(scheduler.flush.bind(scheduler, this), delay);
|
|
1213
|
-
};
|
|
1214
|
-
AsyncAction.prototype.recycleAsyncId = function (_scheduler, id, delay) {
|
|
1215
|
-
if (delay === void 0) { delay = 0; }
|
|
1216
|
-
if (delay != null && this.delay === delay && this.pending === false) {
|
|
1217
|
-
return id;
|
|
1218
|
-
}
|
|
1219
|
-
intervalProvider.clearInterval(id);
|
|
1220
|
-
return undefined;
|
|
1221
|
-
};
|
|
1222
|
-
AsyncAction.prototype.execute = function (state, delay) {
|
|
1223
|
-
if (this.closed) {
|
|
1224
|
-
return new Error('executing a cancelled action');
|
|
1225
|
-
}
|
|
1226
|
-
this.pending = false;
|
|
1227
|
-
var error = this._execute(state, delay);
|
|
1228
|
-
if (error) {
|
|
1229
|
-
return error;
|
|
1230
|
-
}
|
|
1231
|
-
else if (this.pending === false && this.id != null) {
|
|
1232
|
-
this.id = this.recycleAsyncId(this.scheduler, this.id, null);
|
|
1233
|
-
}
|
|
1234
|
-
};
|
|
1235
|
-
AsyncAction.prototype._execute = function (state, _delay) {
|
|
1236
|
-
var errored = false;
|
|
1237
|
-
var errorValue;
|
|
1238
|
-
try {
|
|
1239
|
-
this.work(state);
|
|
1240
|
-
}
|
|
1241
|
-
catch (e) {
|
|
1242
|
-
errored = true;
|
|
1243
|
-
errorValue = e ? e : new Error('Scheduled action threw falsy error');
|
|
1244
|
-
}
|
|
1245
|
-
if (errored) {
|
|
1246
|
-
this.unsubscribe();
|
|
1247
|
-
return errorValue;
|
|
1248
|
-
}
|
|
1249
|
-
};
|
|
1250
|
-
AsyncAction.prototype.unsubscribe = function () {
|
|
1251
|
-
if (!this.closed) {
|
|
1252
|
-
var _a = this, id = _a.id, scheduler = _a.scheduler;
|
|
1253
|
-
var actions = scheduler.actions;
|
|
1254
|
-
this.work = this.state = this.scheduler = null;
|
|
1255
|
-
this.pending = false;
|
|
1256
|
-
arrRemove(actions, this);
|
|
1257
|
-
if (id != null) {
|
|
1258
|
-
this.id = this.recycleAsyncId(scheduler, id, null);
|
|
1259
|
-
}
|
|
1260
|
-
this.delay = null;
|
|
1261
|
-
_super.prototype.unsubscribe.call(this);
|
|
1262
|
-
}
|
|
1263
|
-
};
|
|
1264
|
-
return AsyncAction;
|
|
1265
|
-
}(Action));
|
|
1266
|
-
|
|
1267
|
-
var Scheduler = (function () {
|
|
1268
|
-
function Scheduler(schedulerActionCtor, now) {
|
|
1269
|
-
if (now === void 0) { now = Scheduler.now; }
|
|
1270
|
-
this.schedulerActionCtor = schedulerActionCtor;
|
|
1271
|
-
this.now = now;
|
|
1272
|
-
}
|
|
1273
|
-
Scheduler.prototype.schedule = function (work, delay, state) {
|
|
1274
|
-
if (delay === void 0) { delay = 0; }
|
|
1275
|
-
return new this.schedulerActionCtor(this, work).schedule(state, delay);
|
|
1276
|
-
};
|
|
1277
|
-
Scheduler.now = dateTimestampProvider.now;
|
|
1278
|
-
return Scheduler;
|
|
1279
|
-
}());
|
|
1280
|
-
|
|
1281
|
-
var AsyncScheduler = (function (_super) {
|
|
1282
|
-
__extends(AsyncScheduler, _super);
|
|
1283
|
-
function AsyncScheduler(SchedulerAction, now) {
|
|
1284
|
-
if (now === void 0) { now = Scheduler.now; }
|
|
1285
|
-
var _this = _super.call(this, SchedulerAction, now) || this;
|
|
1286
|
-
_this.actions = [];
|
|
1287
|
-
_this._active = false;
|
|
1288
|
-
_this._scheduled = undefined;
|
|
1289
|
-
return _this;
|
|
1290
|
-
}
|
|
1291
|
-
AsyncScheduler.prototype.flush = function (action) {
|
|
1292
|
-
var actions = this.actions;
|
|
1293
|
-
if (this._active) {
|
|
1294
|
-
actions.push(action);
|
|
1295
|
-
return;
|
|
1296
|
-
}
|
|
1297
|
-
var error;
|
|
1298
|
-
this._active = true;
|
|
1299
|
-
do {
|
|
1300
|
-
if ((error = action.execute(action.state, action.delay))) {
|
|
1301
|
-
break;
|
|
1302
|
-
}
|
|
1303
|
-
} while ((action = actions.shift()));
|
|
1304
|
-
this._active = false;
|
|
1305
|
-
if (error) {
|
|
1306
|
-
while ((action = actions.shift())) {
|
|
1307
|
-
action.unsubscribe();
|
|
1308
|
-
}
|
|
1309
|
-
throw error;
|
|
1310
|
-
}
|
|
1311
|
-
};
|
|
1312
|
-
return AsyncScheduler;
|
|
1313
|
-
}(Scheduler));
|
|
1314
|
-
|
|
1315
|
-
var asyncScheduler = new AsyncScheduler(AsyncAction);
|
|
1316
|
-
var async = asyncScheduler;
|
|
1317
|
-
|
|
1318
|
-
var EMPTY = new Observable(function (subscriber) { return subscriber.complete(); });
|
|
1319
|
-
|
|
1320
|
-
function isScheduler(value) {
|
|
1321
|
-
return value && isFunction(value.schedule);
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
function last(arr) {
|
|
1325
|
-
return arr[arr.length - 1];
|
|
1326
|
-
}
|
|
1327
|
-
function popScheduler(args) {
|
|
1328
|
-
return isScheduler(last(args)) ? args.pop() : undefined;
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
|
|
1332
|
-
|
|
1333
|
-
function isPromise(value) {
|
|
1334
|
-
return isFunction(value === null || value === void 0 ? void 0 : value.then);
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
function isInteropObservable(input) {
|
|
1338
|
-
return isFunction(input[observable]);
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
|
-
function isAsyncIterable(obj) {
|
|
1342
|
-
return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]);
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
function createInvalidObservableTypeError(input) {
|
|
1346
|
-
return new TypeError("You provided " + (input !== null && typeof input === 'object' ? 'an invalid object' : "'" + input + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
function getSymbolIterator() {
|
|
1350
|
-
if (typeof Symbol !== 'function' || !Symbol.iterator) {
|
|
1351
|
-
return '@@iterator';
|
|
1352
|
-
}
|
|
1353
|
-
return Symbol.iterator;
|
|
1354
|
-
}
|
|
1355
|
-
var iterator = getSymbolIterator();
|
|
1356
|
-
|
|
1357
|
-
function isIterable(input) {
|
|
1358
|
-
return isFunction(input === null || input === void 0 ? void 0 : input[iterator]);
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
function readableStreamLikeToAsyncGenerator(readableStream) {
|
|
1362
|
-
return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
|
|
1363
|
-
var reader, _a, value, done;
|
|
1364
|
-
return __generator(this, function (_b) {
|
|
1365
|
-
switch (_b.label) {
|
|
1366
|
-
case 0:
|
|
1367
|
-
reader = readableStream.getReader();
|
|
1368
|
-
_b.label = 1;
|
|
1369
|
-
case 1:
|
|
1370
|
-
_b.trys.push([1, , 9, 10]);
|
|
1371
|
-
_b.label = 2;
|
|
1372
|
-
case 2:
|
|
1373
|
-
return [4, __await(reader.read())];
|
|
1374
|
-
case 3:
|
|
1375
|
-
_a = _b.sent(), value = _a.value, done = _a.done;
|
|
1376
|
-
if (!done) return [3, 5];
|
|
1377
|
-
return [4, __await(void 0)];
|
|
1378
|
-
case 4: return [2, _b.sent()];
|
|
1379
|
-
case 5: return [4, __await(value)];
|
|
1380
|
-
case 6: return [4, _b.sent()];
|
|
1381
|
-
case 7:
|
|
1382
|
-
_b.sent();
|
|
1383
|
-
return [3, 2];
|
|
1384
|
-
case 8: return [3, 10];
|
|
1385
|
-
case 9:
|
|
1386
|
-
reader.releaseLock();
|
|
1387
|
-
return [7];
|
|
1388
|
-
case 10: return [2];
|
|
1389
|
-
}
|
|
1390
|
-
});
|
|
1391
|
-
});
|
|
1392
|
-
}
|
|
1393
|
-
function isReadableStreamLike(obj) {
|
|
1394
|
-
return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
function innerFrom(input) {
|
|
1398
|
-
if (input instanceof Observable) {
|
|
1399
|
-
return input;
|
|
1400
|
-
}
|
|
1401
|
-
if (input != null) {
|
|
1402
|
-
if (isInteropObservable(input)) {
|
|
1403
|
-
return fromInteropObservable(input);
|
|
1404
|
-
}
|
|
1405
|
-
if (isArrayLike(input)) {
|
|
1406
|
-
return fromArrayLike(input);
|
|
1407
|
-
}
|
|
1408
|
-
if (isPromise(input)) {
|
|
1409
|
-
return fromPromise(input);
|
|
1410
|
-
}
|
|
1411
|
-
if (isAsyncIterable(input)) {
|
|
1412
|
-
return fromAsyncIterable(input);
|
|
1413
|
-
}
|
|
1414
|
-
if (isIterable(input)) {
|
|
1415
|
-
return fromIterable(input);
|
|
1416
|
-
}
|
|
1417
|
-
if (isReadableStreamLike(input)) {
|
|
1418
|
-
return fromReadableStreamLike(input);
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
throw createInvalidObservableTypeError(input);
|
|
1422
|
-
}
|
|
1423
|
-
function fromInteropObservable(obj) {
|
|
1424
|
-
return new Observable(function (subscriber) {
|
|
1425
|
-
var obs = obj[observable]();
|
|
1426
|
-
if (isFunction(obs.subscribe)) {
|
|
1427
|
-
return obs.subscribe(subscriber);
|
|
1428
|
-
}
|
|
1429
|
-
throw new TypeError('Provided object does not correctly implement Symbol.observable');
|
|
1430
|
-
});
|
|
1431
|
-
}
|
|
1432
|
-
function fromArrayLike(array) {
|
|
1433
|
-
return new Observable(function (subscriber) {
|
|
1434
|
-
for (var i = 0; i < array.length && !subscriber.closed; i++) {
|
|
1435
|
-
subscriber.next(array[i]);
|
|
1436
|
-
}
|
|
1437
|
-
subscriber.complete();
|
|
1438
|
-
});
|
|
1439
|
-
}
|
|
1440
|
-
function fromPromise(promise) {
|
|
1441
|
-
return new Observable(function (subscriber) {
|
|
1442
|
-
promise
|
|
1443
|
-
.then(function (value) {
|
|
1444
|
-
if (!subscriber.closed) {
|
|
1445
|
-
subscriber.next(value);
|
|
1446
|
-
subscriber.complete();
|
|
1447
|
-
}
|
|
1448
|
-
}, function (err) { return subscriber.error(err); })
|
|
1449
|
-
.then(null, reportUnhandledError);
|
|
1450
|
-
});
|
|
1451
|
-
}
|
|
1452
|
-
function fromIterable(iterable) {
|
|
1453
|
-
return new Observable(function (subscriber) {
|
|
1454
|
-
var e_1, _a;
|
|
1455
|
-
try {
|
|
1456
|
-
for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
|
|
1457
|
-
var value = iterable_1_1.value;
|
|
1458
|
-
subscriber.next(value);
|
|
1459
|
-
if (subscriber.closed) {
|
|
1460
|
-
return;
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1465
|
-
finally {
|
|
1466
|
-
try {
|
|
1467
|
-
if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1);
|
|
1468
|
-
}
|
|
1469
|
-
finally { if (e_1) throw e_1.error; }
|
|
1470
|
-
}
|
|
1471
|
-
subscriber.complete();
|
|
1472
|
-
});
|
|
1473
|
-
}
|
|
1474
|
-
function fromAsyncIterable(asyncIterable) {
|
|
1475
|
-
return new Observable(function (subscriber) {
|
|
1476
|
-
process$1(asyncIterable, subscriber).catch(function (err) { return subscriber.error(err); });
|
|
1477
|
-
});
|
|
1478
|
-
}
|
|
1479
|
-
function fromReadableStreamLike(readableStream) {
|
|
1480
|
-
return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream));
|
|
1481
|
-
}
|
|
1482
|
-
function process$1(asyncIterable, subscriber) {
|
|
1483
|
-
var asyncIterable_1, asyncIterable_1_1;
|
|
1484
|
-
var e_2, _a;
|
|
1485
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1486
|
-
var value, e_2_1;
|
|
1487
|
-
return __generator(this, function (_b) {
|
|
1488
|
-
switch (_b.label) {
|
|
1489
|
-
case 0:
|
|
1490
|
-
_b.trys.push([0, 5, 6, 11]);
|
|
1491
|
-
asyncIterable_1 = __asyncValues(asyncIterable);
|
|
1492
|
-
_b.label = 1;
|
|
1493
|
-
case 1: return [4, asyncIterable_1.next()];
|
|
1494
|
-
case 2:
|
|
1495
|
-
if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done)) return [3, 4];
|
|
1496
|
-
value = asyncIterable_1_1.value;
|
|
1497
|
-
subscriber.next(value);
|
|
1498
|
-
if (subscriber.closed) {
|
|
1499
|
-
return [2];
|
|
1500
|
-
}
|
|
1501
|
-
_b.label = 3;
|
|
1502
|
-
case 3: return [3, 1];
|
|
1503
|
-
case 4: return [3, 11];
|
|
1504
|
-
case 5:
|
|
1505
|
-
e_2_1 = _b.sent();
|
|
1506
|
-
e_2 = { error: e_2_1 };
|
|
1507
|
-
return [3, 11];
|
|
1508
|
-
case 6:
|
|
1509
|
-
_b.trys.push([6, , 9, 10]);
|
|
1510
|
-
if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return))) return [3, 8];
|
|
1511
|
-
return [4, _a.call(asyncIterable_1)];
|
|
1512
|
-
case 7:
|
|
1513
|
-
_b.sent();
|
|
1514
|
-
_b.label = 8;
|
|
1515
|
-
case 8: return [3, 10];
|
|
1516
|
-
case 9:
|
|
1517
|
-
if (e_2) throw e_2.error;
|
|
1518
|
-
return [7];
|
|
1519
|
-
case 10: return [7];
|
|
1520
|
-
case 11:
|
|
1521
|
-
subscriber.complete();
|
|
1522
|
-
return [2];
|
|
1523
|
-
}
|
|
1524
|
-
});
|
|
1525
|
-
});
|
|
1526
|
-
}
|
|
1527
|
-
|
|
1528
|
-
function executeSchedule(parentSubscription, scheduler, work, delay, repeat) {
|
|
1529
|
-
if (delay === void 0) { delay = 0; }
|
|
1530
|
-
if (repeat === void 0) { repeat = false; }
|
|
1531
|
-
var scheduleSubscription = scheduler.schedule(function () {
|
|
1532
|
-
work();
|
|
1533
|
-
if (repeat) {
|
|
1534
|
-
parentSubscription.add(this.schedule(null, delay));
|
|
1535
|
-
}
|
|
1536
|
-
else {
|
|
1537
|
-
this.unsubscribe();
|
|
1538
|
-
}
|
|
1539
|
-
}, delay);
|
|
1540
|
-
parentSubscription.add(scheduleSubscription);
|
|
1541
|
-
if (!repeat) {
|
|
1542
|
-
return scheduleSubscription;
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
function observeOn(scheduler, delay) {
|
|
1547
|
-
if (delay === void 0) { delay = 0; }
|
|
1548
|
-
return operate(function (source, subscriber) {
|
|
1549
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) { return executeSchedule(subscriber, scheduler, function () { return subscriber.next(value); }, delay); }, function () { return executeSchedule(subscriber, scheduler, function () { return subscriber.complete(); }, delay); }, function (err) { return executeSchedule(subscriber, scheduler, function () { return subscriber.error(err); }, delay); }));
|
|
1550
|
-
});
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
|
-
function subscribeOn(scheduler, delay) {
|
|
1554
|
-
if (delay === void 0) { delay = 0; }
|
|
1555
|
-
return operate(function (source, subscriber) {
|
|
1556
|
-
subscriber.add(scheduler.schedule(function () { return source.subscribe(subscriber); }, delay));
|
|
1557
|
-
});
|
|
1558
|
-
}
|
|
1559
|
-
|
|
1560
|
-
function scheduleObservable(input, scheduler) {
|
|
1561
|
-
return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
function schedulePromise(input, scheduler) {
|
|
1565
|
-
return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
function scheduleArray(input, scheduler) {
|
|
1569
|
-
return new Observable(function (subscriber) {
|
|
1570
|
-
var i = 0;
|
|
1571
|
-
return scheduler.schedule(function () {
|
|
1572
|
-
if (i === input.length) {
|
|
1573
|
-
subscriber.complete();
|
|
1574
|
-
}
|
|
1575
|
-
else {
|
|
1576
|
-
subscriber.next(input[i++]);
|
|
1577
|
-
if (!subscriber.closed) {
|
|
1578
|
-
this.schedule();
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
});
|
|
1582
|
-
});
|
|
1583
|
-
}
|
|
1584
|
-
|
|
1585
|
-
function scheduleIterable(input, scheduler) {
|
|
1586
|
-
return new Observable(function (subscriber) {
|
|
1587
|
-
var iterator$1;
|
|
1588
|
-
executeSchedule(subscriber, scheduler, function () {
|
|
1589
|
-
iterator$1 = input[iterator]();
|
|
1590
|
-
executeSchedule(subscriber, scheduler, function () {
|
|
1591
|
-
var _a;
|
|
1592
|
-
var value;
|
|
1593
|
-
var done;
|
|
1594
|
-
try {
|
|
1595
|
-
(_a = iterator$1.next(), value = _a.value, done = _a.done);
|
|
1596
|
-
}
|
|
1597
|
-
catch (err) {
|
|
1598
|
-
subscriber.error(err);
|
|
1599
|
-
return;
|
|
1600
|
-
}
|
|
1601
|
-
if (done) {
|
|
1602
|
-
subscriber.complete();
|
|
1603
|
-
}
|
|
1604
|
-
else {
|
|
1605
|
-
subscriber.next(value);
|
|
1606
|
-
}
|
|
1607
|
-
}, 0, true);
|
|
1608
|
-
});
|
|
1609
|
-
return function () { return isFunction(iterator$1 === null || iterator$1 === void 0 ? void 0 : iterator$1.return) && iterator$1.return(); };
|
|
1610
|
-
});
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1613
|
-
function scheduleAsyncIterable(input, scheduler) {
|
|
1614
|
-
if (!input) {
|
|
1615
|
-
throw new Error('Iterable cannot be null');
|
|
1616
|
-
}
|
|
1617
|
-
return new Observable(function (subscriber) {
|
|
1618
|
-
executeSchedule(subscriber, scheduler, function () {
|
|
1619
|
-
var iterator = input[Symbol.asyncIterator]();
|
|
1620
|
-
executeSchedule(subscriber, scheduler, function () {
|
|
1621
|
-
iterator.next().then(function (result) {
|
|
1622
|
-
if (result.done) {
|
|
1623
|
-
subscriber.complete();
|
|
1624
|
-
}
|
|
1625
|
-
else {
|
|
1626
|
-
subscriber.next(result.value);
|
|
1627
|
-
}
|
|
1628
|
-
});
|
|
1629
|
-
}, 0, true);
|
|
1630
|
-
});
|
|
1631
|
-
});
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
|
-
function scheduleReadableStreamLike(input, scheduler) {
|
|
1635
|
-
return scheduleAsyncIterable(readableStreamLikeToAsyncGenerator(input), scheduler);
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
|
-
function scheduled(input, scheduler) {
|
|
1639
|
-
if (input != null) {
|
|
1640
|
-
if (isInteropObservable(input)) {
|
|
1641
|
-
return scheduleObservable(input, scheduler);
|
|
1642
|
-
}
|
|
1643
|
-
if (isArrayLike(input)) {
|
|
1644
|
-
return scheduleArray(input, scheduler);
|
|
1645
|
-
}
|
|
1646
|
-
if (isPromise(input)) {
|
|
1647
|
-
return schedulePromise(input, scheduler);
|
|
1648
|
-
}
|
|
1649
|
-
if (isAsyncIterable(input)) {
|
|
1650
|
-
return scheduleAsyncIterable(input, scheduler);
|
|
1651
|
-
}
|
|
1652
|
-
if (isIterable(input)) {
|
|
1653
|
-
return scheduleIterable(input, scheduler);
|
|
1654
|
-
}
|
|
1655
|
-
if (isReadableStreamLike(input)) {
|
|
1656
|
-
return scheduleReadableStreamLike(input, scheduler);
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
throw createInvalidObservableTypeError(input);
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
function from(input, scheduler) {
|
|
1663
|
-
return scheduler ? scheduled(input, scheduler) : innerFrom(input);
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
function of() {
|
|
1667
|
-
var args = [];
|
|
1668
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1669
|
-
args[_i] = arguments[_i];
|
|
1670
|
-
}
|
|
1671
|
-
var scheduler = popScheduler(args);
|
|
1672
|
-
return from(args, scheduler);
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
|
-
var EmptyError = createErrorClass(function (_super) { return function EmptyErrorImpl() {
|
|
1676
|
-
_super(this);
|
|
1677
|
-
this.name = 'EmptyError';
|
|
1678
|
-
this.message = 'no elements in sequence';
|
|
1679
|
-
}; });
|
|
1680
|
-
|
|
1681
|
-
function firstValueFrom(source, config) {
|
|
1682
|
-
var hasConfig = typeof config === 'object';
|
|
1683
|
-
return new Promise(function (resolve, reject) {
|
|
1684
|
-
var subscriber = new SafeSubscriber({
|
|
1685
|
-
next: function (value) {
|
|
1686
|
-
resolve(value);
|
|
1687
|
-
subscriber.unsubscribe();
|
|
1688
|
-
},
|
|
1689
|
-
error: reject,
|
|
1690
|
-
complete: function () {
|
|
1691
|
-
if (hasConfig) {
|
|
1692
|
-
resolve(config.defaultValue);
|
|
1693
|
-
}
|
|
1694
|
-
else {
|
|
1695
|
-
reject(new EmptyError());
|
|
1696
|
-
}
|
|
1697
|
-
},
|
|
1698
|
-
});
|
|
1699
|
-
source.subscribe(subscriber);
|
|
1700
|
-
});
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1703
|
-
function isValidDate(value) {
|
|
1704
|
-
return value instanceof Date && !isNaN(value);
|
|
1705
|
-
}
|
|
1706
|
-
|
|
1707
|
-
function map(project, thisArg) {
|
|
1708
|
-
return operate(function (source, subscriber) {
|
|
1709
|
-
var index = 0;
|
|
1710
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1711
|
-
subscriber.next(project.call(thisArg, value, index++));
|
|
1712
|
-
}));
|
|
1713
|
-
});
|
|
1714
|
-
}
|
|
1715
|
-
|
|
1716
|
-
function mergeInternals(source, subscriber, project, concurrent, onBeforeNext, expand, innerSubScheduler, additionalFinalizer) {
|
|
1717
|
-
var buffer = [];
|
|
1718
|
-
var active = 0;
|
|
1719
|
-
var index = 0;
|
|
1720
|
-
var isComplete = false;
|
|
1721
|
-
var checkComplete = function () {
|
|
1722
|
-
if (isComplete && !buffer.length && !active) {
|
|
1723
|
-
subscriber.complete();
|
|
1724
|
-
}
|
|
1725
|
-
};
|
|
1726
|
-
var outerNext = function (value) { return (active < concurrent ? doInnerSub(value) : buffer.push(value)); };
|
|
1727
|
-
var doInnerSub = function (value) {
|
|
1728
|
-
expand && subscriber.next(value);
|
|
1729
|
-
active++;
|
|
1730
|
-
var innerComplete = false;
|
|
1731
|
-
innerFrom(project(value, index++)).subscribe(createOperatorSubscriber(subscriber, function (innerValue) {
|
|
1732
|
-
onBeforeNext === null || onBeforeNext === void 0 ? void 0 : onBeforeNext(innerValue);
|
|
1733
|
-
if (expand) {
|
|
1734
|
-
outerNext(innerValue);
|
|
1735
|
-
}
|
|
1736
|
-
else {
|
|
1737
|
-
subscriber.next(innerValue);
|
|
1738
|
-
}
|
|
1739
|
-
}, function () {
|
|
1740
|
-
innerComplete = true;
|
|
1741
|
-
}, undefined, function () {
|
|
1742
|
-
if (innerComplete) {
|
|
1743
|
-
try {
|
|
1744
|
-
active--;
|
|
1745
|
-
var _loop_1 = function () {
|
|
1746
|
-
var bufferedValue = buffer.shift();
|
|
1747
|
-
if (innerSubScheduler) {
|
|
1748
|
-
executeSchedule(subscriber, innerSubScheduler, function () { return doInnerSub(bufferedValue); });
|
|
1749
|
-
}
|
|
1750
|
-
else {
|
|
1751
|
-
doInnerSub(bufferedValue);
|
|
1752
|
-
}
|
|
1753
|
-
};
|
|
1754
|
-
while (buffer.length && active < concurrent) {
|
|
1755
|
-
_loop_1();
|
|
1756
|
-
}
|
|
1757
|
-
checkComplete();
|
|
1758
|
-
}
|
|
1759
|
-
catch (err) {
|
|
1760
|
-
subscriber.error(err);
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
}));
|
|
1764
|
-
};
|
|
1765
|
-
source.subscribe(createOperatorSubscriber(subscriber, outerNext, function () {
|
|
1766
|
-
isComplete = true;
|
|
1767
|
-
checkComplete();
|
|
1768
|
-
}));
|
|
1769
|
-
return function () {
|
|
1770
|
-
additionalFinalizer === null || additionalFinalizer === void 0 ? void 0 : additionalFinalizer();
|
|
1771
|
-
};
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
function mergeMap(project, resultSelector, concurrent) {
|
|
1775
|
-
if (concurrent === void 0) { concurrent = Infinity; }
|
|
1776
|
-
if (isFunction(resultSelector)) {
|
|
1777
|
-
return mergeMap(function (a, i) { return map(function (b, ii) { return resultSelector(a, b, i, ii); })(innerFrom(project(a, i))); }, concurrent);
|
|
1778
|
-
}
|
|
1779
|
-
else if (typeof resultSelector === 'number') {
|
|
1780
|
-
concurrent = resultSelector;
|
|
1781
|
-
}
|
|
1782
|
-
return operate(function (source, subscriber) { return mergeInternals(source, subscriber, project, concurrent); });
|
|
1783
|
-
}
|
|
1784
|
-
|
|
1785
|
-
function mergeAll(concurrent) {
|
|
1786
|
-
if (concurrent === void 0) { concurrent = Infinity; }
|
|
1787
|
-
return mergeMap(identity, concurrent);
|
|
1788
|
-
}
|
|
1789
|
-
|
|
1790
|
-
function concatAll() {
|
|
1791
|
-
return mergeAll(1);
|
|
1792
|
-
}
|
|
1793
|
-
|
|
1794
|
-
function concat$1() {
|
|
1795
|
-
var args = [];
|
|
1796
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1797
|
-
args[_i] = arguments[_i];
|
|
1798
|
-
}
|
|
1799
|
-
return concatAll()(from(args, popScheduler(args)));
|
|
1800
|
-
}
|
|
1801
|
-
|
|
1802
|
-
function timer(dueTime, intervalOrScheduler, scheduler) {
|
|
1803
|
-
if (dueTime === void 0) { dueTime = 0; }
|
|
1804
|
-
if (scheduler === void 0) { scheduler = async; }
|
|
1805
|
-
var intervalDuration = -1;
|
|
1806
|
-
if (intervalOrScheduler != null) {
|
|
1807
|
-
if (isScheduler(intervalOrScheduler)) {
|
|
1808
|
-
scheduler = intervalOrScheduler;
|
|
1809
|
-
}
|
|
1810
|
-
else {
|
|
1811
|
-
intervalDuration = intervalOrScheduler;
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
return new Observable(function (subscriber) {
|
|
1815
|
-
var due = isValidDate(dueTime) ? +dueTime - scheduler.now() : dueTime;
|
|
1816
|
-
if (due < 0) {
|
|
1817
|
-
due = 0;
|
|
1818
|
-
}
|
|
1819
|
-
var n = 0;
|
|
1820
|
-
return scheduler.schedule(function () {
|
|
1821
|
-
if (!subscriber.closed) {
|
|
1822
|
-
subscriber.next(n++);
|
|
1823
|
-
if (0 <= intervalDuration) {
|
|
1824
|
-
this.schedule(undefined, intervalDuration);
|
|
1825
|
-
}
|
|
1826
|
-
else {
|
|
1827
|
-
subscriber.complete();
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
}, due);
|
|
1831
|
-
});
|
|
1832
|
-
}
|
|
1833
|
-
|
|
1834
|
-
function filter(predicate, thisArg) {
|
|
1835
|
-
return operate(function (source, subscriber) {
|
|
1836
|
-
var index = 0;
|
|
1837
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) { return predicate.call(thisArg, value, index++) && subscriber.next(value); }));
|
|
1838
|
-
});
|
|
1839
|
-
}
|
|
1840
|
-
|
|
1841
|
-
function buffer(closingNotifier) {
|
|
1842
|
-
return operate(function (source, subscriber) {
|
|
1843
|
-
var currentBuffer = [];
|
|
1844
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) { return currentBuffer.push(value); }, function () {
|
|
1845
|
-
subscriber.next(currentBuffer);
|
|
1846
|
-
subscriber.complete();
|
|
1847
|
-
}));
|
|
1848
|
-
closingNotifier.subscribe(createOperatorSubscriber(subscriber, function () {
|
|
1849
|
-
var b = currentBuffer;
|
|
1850
|
-
currentBuffer = [];
|
|
1851
|
-
subscriber.next(b);
|
|
1852
|
-
}, noop));
|
|
1853
|
-
return function () {
|
|
1854
|
-
currentBuffer = null;
|
|
1855
|
-
};
|
|
1856
|
-
});
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1859
|
-
function scanInternals(accumulator, seed, hasSeed, emitOnNext, emitBeforeComplete) {
|
|
1860
|
-
return function (source, subscriber) {
|
|
1861
|
-
var hasState = hasSeed;
|
|
1862
|
-
var state = seed;
|
|
1863
|
-
var index = 0;
|
|
1864
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1865
|
-
var i = index++;
|
|
1866
|
-
state = hasState
|
|
1867
|
-
?
|
|
1868
|
-
accumulator(state, value, i)
|
|
1869
|
-
:
|
|
1870
|
-
((hasState = true), value);
|
|
1871
|
-
emitOnNext && subscriber.next(state);
|
|
1872
|
-
}, emitBeforeComplete &&
|
|
1873
|
-
(function () {
|
|
1874
|
-
hasState && subscriber.next(state);
|
|
1875
|
-
subscriber.complete();
|
|
1876
|
-
})));
|
|
1877
|
-
};
|
|
1878
|
-
}
|
|
1879
|
-
|
|
1880
|
-
function reduce(accumulator, seed) {
|
|
1881
|
-
return operate(scanInternals(accumulator, seed, arguments.length >= 2, false, true));
|
|
1882
|
-
}
|
|
1883
|
-
|
|
1884
|
-
var arrReducer = function (arr, value) { return (arr.push(value), arr); };
|
|
1885
|
-
function toArray() {
|
|
1886
|
-
return operate(function (source, subscriber) {
|
|
1887
|
-
reduce(arrReducer, [])(source).subscribe(subscriber);
|
|
1888
|
-
});
|
|
1889
|
-
}
|
|
1890
|
-
|
|
1891
|
-
function concat() {
|
|
1892
|
-
var args = [];
|
|
1893
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1894
|
-
args[_i] = arguments[_i];
|
|
1895
|
-
}
|
|
1896
|
-
var scheduler = popScheduler(args);
|
|
1897
|
-
return operate(function (source, subscriber) {
|
|
1898
|
-
concatAll()(from(__spreadArray([source], __read(args)), scheduler)).subscribe(subscriber);
|
|
1899
|
-
});
|
|
1900
|
-
}
|
|
1901
|
-
|
|
1902
|
-
function concatWith() {
|
|
1903
|
-
var otherSources = [];
|
|
1904
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1905
|
-
otherSources[_i] = arguments[_i];
|
|
1906
|
-
}
|
|
1907
|
-
return concat.apply(void 0, __spreadArray([], __read(otherSources)));
|
|
1908
|
-
}
|
|
1909
|
-
|
|
1910
|
-
function defaultIfEmpty(defaultValue) {
|
|
1911
|
-
return operate(function (source, subscriber) {
|
|
1912
|
-
var hasValue = false;
|
|
1913
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1914
|
-
hasValue = true;
|
|
1915
|
-
subscriber.next(value);
|
|
1916
|
-
}, function () {
|
|
1917
|
-
if (!hasValue) {
|
|
1918
|
-
subscriber.next(defaultValue);
|
|
1919
|
-
}
|
|
1920
|
-
subscriber.complete();
|
|
1921
|
-
}));
|
|
1922
|
-
});
|
|
1923
|
-
}
|
|
1924
|
-
|
|
1925
|
-
function take(count) {
|
|
1926
|
-
return count <= 0
|
|
1927
|
-
?
|
|
1928
|
-
function () { return EMPTY; }
|
|
1929
|
-
: operate(function (source, subscriber) {
|
|
1930
|
-
var seen = 0;
|
|
1931
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1932
|
-
if (++seen <= count) {
|
|
1933
|
-
subscriber.next(value);
|
|
1934
|
-
if (count <= seen) {
|
|
1935
|
-
subscriber.complete();
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
}));
|
|
1939
|
-
});
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
function throwIfEmpty(errorFactory) {
|
|
1943
|
-
if (errorFactory === void 0) { errorFactory = defaultErrorFactory; }
|
|
1944
|
-
return operate(function (source, subscriber) {
|
|
1945
|
-
var hasValue = false;
|
|
1946
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1947
|
-
hasValue = true;
|
|
1948
|
-
subscriber.next(value);
|
|
1949
|
-
}, function () { return (hasValue ? subscriber.complete() : subscriber.error(errorFactory())); }));
|
|
1950
|
-
});
|
|
1951
|
-
}
|
|
1952
|
-
function defaultErrorFactory() {
|
|
1953
|
-
return new EmptyError();
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
|
-
function first(predicate, defaultValue) {
|
|
1957
|
-
var hasDefaultValue = arguments.length >= 2;
|
|
1958
|
-
return function (source) {
|
|
1959
|
-
return source.pipe(predicate ? filter(function (v, i) { return predicate(v, i, source); }) : identity, take(1), hasDefaultValue ? defaultIfEmpty(defaultValue) : throwIfEmpty(function () { return new EmptyError(); }));
|
|
1960
|
-
};
|
|
1961
|
-
}
|
|
1962
|
-
|
|
1963
|
-
function retry(configOrCount) {
|
|
1964
|
-
if (configOrCount === void 0) { configOrCount = Infinity; }
|
|
1965
|
-
var config;
|
|
1966
|
-
if (configOrCount && typeof configOrCount === 'object') {
|
|
1967
|
-
config = configOrCount;
|
|
1968
|
-
}
|
|
1969
|
-
else {
|
|
1970
|
-
config = {
|
|
1971
|
-
count: configOrCount,
|
|
1972
|
-
};
|
|
1973
|
-
}
|
|
1974
|
-
var _a = config.count, count = _a === void 0 ? Infinity : _a, delay = config.delay, _b = config.resetOnSuccess, resetOnSuccess = _b === void 0 ? false : _b;
|
|
1975
|
-
return count <= 0
|
|
1976
|
-
? identity
|
|
1977
|
-
: operate(function (source, subscriber) {
|
|
1978
|
-
var soFar = 0;
|
|
1979
|
-
var innerSub;
|
|
1980
|
-
var subscribeForRetry = function () {
|
|
1981
|
-
var syncUnsub = false;
|
|
1982
|
-
innerSub = source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1983
|
-
if (resetOnSuccess) {
|
|
1984
|
-
soFar = 0;
|
|
1985
|
-
}
|
|
1986
|
-
subscriber.next(value);
|
|
1987
|
-
}, undefined, function (err) {
|
|
1988
|
-
if (soFar++ < count) {
|
|
1989
|
-
var resub_1 = function () {
|
|
1990
|
-
if (innerSub) {
|
|
1991
|
-
innerSub.unsubscribe();
|
|
1992
|
-
innerSub = null;
|
|
1993
|
-
subscribeForRetry();
|
|
1994
|
-
}
|
|
1995
|
-
else {
|
|
1996
|
-
syncUnsub = true;
|
|
1997
|
-
}
|
|
1998
|
-
};
|
|
1999
|
-
if (delay != null) {
|
|
2000
|
-
var notifier = typeof delay === 'number' ? timer(delay) : innerFrom(delay(err, soFar));
|
|
2001
|
-
var notifierSubscriber_1 = createOperatorSubscriber(subscriber, function () {
|
|
2002
|
-
notifierSubscriber_1.unsubscribe();
|
|
2003
|
-
resub_1();
|
|
2004
|
-
}, function () {
|
|
2005
|
-
subscriber.complete();
|
|
2006
|
-
});
|
|
2007
|
-
notifier.subscribe(notifierSubscriber_1);
|
|
2008
|
-
}
|
|
2009
|
-
else {
|
|
2010
|
-
resub_1();
|
|
2011
|
-
}
|
|
2012
|
-
}
|
|
2013
|
-
else {
|
|
2014
|
-
subscriber.error(err);
|
|
2015
|
-
}
|
|
2016
|
-
}));
|
|
2017
|
-
if (syncUnsub) {
|
|
2018
|
-
innerSub.unsubscribe();
|
|
2019
|
-
innerSub = null;
|
|
2020
|
-
subscribeForRetry();
|
|
2021
|
-
}
|
|
2022
|
-
};
|
|
2023
|
-
subscribeForRetry();
|
|
2024
|
-
});
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
|
-
function startWith() {
|
|
2028
|
-
var values = [];
|
|
2029
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2030
|
-
values[_i] = arguments[_i];
|
|
2031
|
-
}
|
|
2032
|
-
var scheduler = popScheduler(values);
|
|
2033
|
-
return operate(function (source, subscriber) {
|
|
2034
|
-
(scheduler ? concat$1(values, source, scheduler) : concat$1(values, source)).subscribe(subscriber);
|
|
2035
|
-
});
|
|
2036
|
-
}
|
|
2037
|
-
|
|
2038
|
-
function switchMap(project, resultSelector) {
|
|
2039
|
-
return operate(function (source, subscriber) {
|
|
2040
|
-
var innerSubscriber = null;
|
|
2041
|
-
var index = 0;
|
|
2042
|
-
var isComplete = false;
|
|
2043
|
-
var checkComplete = function () { return isComplete && !innerSubscriber && subscriber.complete(); };
|
|
2044
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
2045
|
-
innerSubscriber === null || innerSubscriber === void 0 ? void 0 : innerSubscriber.unsubscribe();
|
|
2046
|
-
var innerIndex = 0;
|
|
2047
|
-
var outerIndex = index++;
|
|
2048
|
-
innerFrom(project(value, outerIndex)).subscribe((innerSubscriber = createOperatorSubscriber(subscriber, function (innerValue) { return subscriber.next(resultSelector ? resultSelector(value, innerValue, outerIndex, innerIndex++) : innerValue); }, function () {
|
|
2049
|
-
innerSubscriber = null;
|
|
2050
|
-
checkComplete();
|
|
2051
|
-
})));
|
|
2052
|
-
}, function () {
|
|
2053
|
-
isComplete = true;
|
|
2054
|
-
checkComplete();
|
|
2055
|
-
}));
|
|
2056
|
-
});
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
function takeUntil(notifier) {
|
|
2060
|
-
return operate(function (source, subscriber) {
|
|
2061
|
-
innerFrom(notifier).subscribe(createOperatorSubscriber(subscriber, function () { return subscriber.complete(); }, noop));
|
|
2062
|
-
!subscriber.closed && source.subscribe(subscriber);
|
|
2063
|
-
});
|
|
2064
|
-
}
|
|
2065
|
-
|
|
2066
|
-
class RxMap extends Map {
|
|
2067
|
-
static isChangeType = {
|
|
2068
|
-
clear: (x) => x.type === "clear",
|
|
2069
|
-
delete: (x) => x.type === "delete",
|
|
2070
|
-
set: (x) => x.type === "set"
|
|
2071
|
-
};
|
|
2072
|
-
change$;
|
|
2073
|
-
constructor(iterable) {
|
|
2074
|
-
super(iterable);
|
|
2075
|
-
const change$ = new Subject();
|
|
2076
|
-
this.change$ = change$.asObservable();
|
|
2077
|
-
const changeMethodKeys = ["clear", "set", "delete"];
|
|
2078
|
-
for (const type of changeMethodKeys) {
|
|
2079
|
-
const method = this[type];
|
|
2080
|
-
this[type] = function(...args) {
|
|
2081
|
-
const result = method.call(this, ...args);
|
|
2082
|
-
change$.next({ type, key: args[0], value: args[1], map: this });
|
|
2083
|
-
return result;
|
|
2084
|
-
}.bind(this);
|
|
2085
|
-
}
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
|
|
2089
|
-
const outputFiles = new RxMap();
|
|
2090
|
-
|
|
2091
|
-
_debug("file-writer").extend("utilities");
|
|
2092
|
-
function prefix$1(prefix2, text) {
|
|
2093
|
-
return text.startsWith(prefix2) ? text : prefix2 + text;
|
|
2094
|
-
}
|
|
2095
|
-
function strip(prefix2, text) {
|
|
2096
|
-
return text?.startsWith(prefix2) ? text?.slice(prefix2.length) : text;
|
|
2097
|
-
}
|
|
2098
|
-
function formatFileData(script) {
|
|
2099
|
-
script.id = prefix$1("/", script.id);
|
|
2100
|
-
if (script.fileName)
|
|
2101
|
-
script.fileName = strip("/", script.fileName);
|
|
2102
|
-
if (script.loaderName)
|
|
2103
|
-
script.loaderName = strip("/", script.loaderName);
|
|
2104
|
-
return script;
|
|
2105
|
-
}
|
|
2106
|
-
function getFileName({ type, id }) {
|
|
2107
|
-
let fileName = id.replace(/t=\d+&/, "").replace(/^\//, "").replace(/\?/g, "__").replace(/&/g, "_").replace(/=/g, "--");
|
|
2108
|
-
if (fileName.includes("node_modules/")) {
|
|
2109
|
-
fileName = `vendor/${fileName.split("node_modules/").pop().replace(/\//g, "-")}`;
|
|
2110
|
-
} else if (fileName.startsWith("@")) {
|
|
2111
|
-
fileName = `vendor/${fileName.slice("@".length).replace(/\//g, "-")}`;
|
|
2112
|
-
} else if (fileName.startsWith(".vite/deps/")) {
|
|
2113
|
-
fileName = `vendor/${fileName.slice(".vite/deps/".length)}`;
|
|
2114
|
-
}
|
|
2115
|
-
switch (type) {
|
|
2116
|
-
case "iife":
|
|
2117
|
-
return `${fileName}.iife.js`;
|
|
2118
|
-
case "loader":
|
|
2119
|
-
return `${fileName}-loader.js`;
|
|
2120
|
-
case "module":
|
|
2121
|
-
return `${fileName}.js`;
|
|
2122
|
-
case "asset":
|
|
2123
|
-
return fileName;
|
|
2124
|
-
default:
|
|
2125
|
-
throw new Error(`Unexpected script type "${type}" for "${JSON.stringify({
|
|
2126
|
-
type,
|
|
2127
|
-
id
|
|
2128
|
-
})}"`);
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
|
-
function getOutputPath(server, fileName) {
|
|
2132
|
-
const {
|
|
2133
|
-
root,
|
|
2134
|
-
build: { outDir }
|
|
2135
|
-
} = server.config;
|
|
2136
|
-
const target = isAbsolute(outDir) ? join(outDir, fileName) : join(root, outDir, fileName);
|
|
2137
|
-
return target;
|
|
2138
|
-
}
|
|
2139
|
-
function getViteUrl({ type, id }) {
|
|
2140
|
-
if (type === "asset") {
|
|
2141
|
-
throw new Error(`File type "${type}" not implemented.`);
|
|
2142
|
-
} else if (type === "iife") {
|
|
2143
|
-
throw new Error(`File type "${type}" not implemented.`);
|
|
2144
|
-
} else if (type === "loader") {
|
|
2145
|
-
throw new Error("Vite does not transform loader files.");
|
|
2146
|
-
} else if (type === "module") {
|
|
2147
|
-
if (id.startsWith("/@id/"))
|
|
2148
|
-
return id.slice("/@id/".length).replace("__x00__", "\0");
|
|
2149
|
-
return prefix$1("/", id);
|
|
2150
|
-
} else {
|
|
2151
|
-
throw new Error(`Invalid file type: "${type}"`);
|
|
2152
|
-
}
|
|
2153
|
-
}
|
|
2154
|
-
async function fileReady(script) {
|
|
2155
|
-
const fileName = getFileName(script);
|
|
2156
|
-
const file = outputFiles.get(fileName);
|
|
2157
|
-
if (!file)
|
|
2158
|
-
throw new Error("unknown script type and id");
|
|
2159
|
-
const { deps } = await file.file;
|
|
2160
|
-
await Promise.all(deps.map(fileReady));
|
|
2161
|
-
}
|
|
2162
|
-
|
|
2163
|
-
const viteClientId = "/@vite/client";
|
|
2164
|
-
const customElementsId = "/@webcomponents/custom-elements";
|
|
2165
|
-
const contentHmrPortId = "/@crx/client-port";
|
|
2166
|
-
const manifestId = "/@crx/manifest";
|
|
2167
|
-
const preambleId = "/@crx/client-preamble";
|
|
2168
|
-
const stubId = "/@crx/stub";
|
|
2169
|
-
const workerClientId = "/@crx/client-worker";
|
|
2170
|
-
|
|
2171
|
-
const pluginBackground = () => {
|
|
2172
|
-
let config;
|
|
2173
|
-
return [
|
|
2174
|
-
{
|
|
2175
|
-
name: "crx:background-client",
|
|
2176
|
-
apply: "serve",
|
|
2177
|
-
resolveId(source) {
|
|
2178
|
-
if (source === `/${workerClientId}`)
|
|
2179
|
-
return workerClientId;
|
|
2180
|
-
},
|
|
2181
|
-
load(id) {
|
|
2182
|
-
if (id === workerClientId) {
|
|
2183
|
-
const base = `http://localhost:${config.server.port}/`;
|
|
2184
|
-
return defineClientValues(workerHmrClient.replace("__BASE__", JSON.stringify(base)), config);
|
|
2185
|
-
}
|
|
2186
|
-
}
|
|
2187
|
-
},
|
|
2188
|
-
{
|
|
2189
|
-
name: "crx:background-loader-file",
|
|
2190
|
-
enforce: "post",
|
|
2191
|
-
configResolved(_config) {
|
|
2192
|
-
config = _config;
|
|
2193
|
-
},
|
|
2194
|
-
renderCrxManifest(manifest) {
|
|
2195
|
-
const worker = manifest.background?.service_worker;
|
|
2196
|
-
let loader;
|
|
2197
|
-
if (config.command === "serve") {
|
|
2198
|
-
const port = config.server.port?.toString();
|
|
2199
|
-
if (typeof port === "undefined")
|
|
2200
|
-
throw new Error("server port is undefined in watch mode");
|
|
2201
|
-
loader = `import 'http:/localhost:${port}/@vite/env';
|
|
2202
|
-
`;
|
|
2203
|
-
loader += `import 'http://localhost:${port}${workerClientId}';
|
|
2204
|
-
`;
|
|
2205
|
-
if (worker)
|
|
2206
|
-
loader += `import 'http://localhost:${port}/${worker}';
|
|
2207
|
-
`;
|
|
2208
|
-
} else if (worker) {
|
|
2209
|
-
loader = `import './${worker}';
|
|
2210
|
-
`;
|
|
2211
|
-
} else {
|
|
2212
|
-
return null;
|
|
2213
|
-
}
|
|
2214
|
-
const refId = this.emitFile({
|
|
2215
|
-
type: "asset",
|
|
2216
|
-
fileName: getFileName({ type: "loader", id: "service-worker" }),
|
|
2217
|
-
source: loader
|
|
2218
|
-
});
|
|
2219
|
-
manifest.background = {
|
|
2220
|
-
service_worker: this.getFileName(refId),
|
|
2221
|
-
type: "module"
|
|
2222
|
-
};
|
|
2223
|
-
return manifest;
|
|
2224
|
-
}
|
|
2225
|
-
}
|
|
2226
|
-
];
|
|
2227
|
-
};
|
|
2228
|
-
|
|
2229
|
-
var contentHmrPort = "function isCrxHMRPayload(x) {\n return x.type === \"custom\" && x.event.startsWith(\"crx:\");\n}\nclass HMRPort {\n port;\n callbacks = /* @__PURE__ */ new Map();\n constructor() {\n setInterval(() => {\n try {\n this.port?.postMessage({ data: \"ping\" });\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"Extension context invalidated.\")) {\n location.reload();\n } else\n throw error;\n }\n }, __CRX_HMR_TIMEOUT__);\n setInterval(this.initPort, 5 * 60 * 1e3);\n this.initPort();\n }\n initPort = () => {\n this.port?.disconnect();\n this.port = chrome.runtime.connect({ name: \"@crx/client\" });\n this.port.onDisconnect.addListener(this.handleDisconnect.bind(this));\n this.port.onMessage.addListener(this.handleMessage.bind(this));\n this.port.postMessage({ type: \"connected\" });\n };\n handleDisconnect = () => {\n if (this.callbacks.has(\"close\"))\n for (const cb of this.callbacks.get(\"close\")) {\n cb({ wasClean: true });\n }\n };\n handleMessage = (message) => {\n const forward = (data) => {\n if (this.callbacks.has(\"message\"))\n for (const cb of this.callbacks.get(\"message\")) {\n cb({ data });\n }\n };\n const payload = JSON.parse(message.data);\n if (isCrxHMRPayload(payload)) {\n if (payload.event === \"crx:runtime-reload\") {\n console.log(\"[crx] runtime reload\");\n setTimeout(() => location.reload(), 500);\n } else {\n forward(JSON.stringify(payload.data));\n }\n } else {\n forward(message.data);\n }\n };\n addEventListener = (event, callback) => {\n const cbs = this.callbacks.get(event) ?? /* @__PURE__ */ new Set();\n cbs.add(callback);\n this.callbacks.set(event, cbs);\n };\n send = (data) => {\n if (this.port)\n this.port.postMessage({ data });\n else\n throw new Error(\"HMRPort is not initialized\");\n };\n}\n\nexport { HMRPort };\n";
|
|
2230
|
-
|
|
2231
|
-
var contentDevLoader = "(function () {\n 'use strict';\n\n (async () => {\n if (__PREAMBLE__)\n await import(\n /* @vite-ignore */\n chrome.runtime.getURL(__PREAMBLE__)\n );\n await import(\n /* @vite-ignore */\n chrome.runtime.getURL(__CLIENT__)\n );\n await import(\n /* @vite-ignore */\n chrome.runtime.getURL(__SCRIPT__)\n );\n })().catch(console.error);\n\n})();\n";
|
|
2232
|
-
|
|
2233
|
-
var contentProLoader = "(function () {\n 'use strict';\n\n (async () => {\n await import(\n /* @vite-ignore */\n chrome.runtime.getURL(__SCRIPT__)\n );\n })().catch(console.error);\n\n})();\n";
|
|
2234
|
-
|
|
2235
|
-
const contentScripts = new RxMap();
|
|
2236
|
-
contentScripts.change$.pipe(filter(RxMap.isChangeType.set)).subscribe(({ map, value }) => {
|
|
2237
|
-
const keyNames = [
|
|
2238
|
-
"refId",
|
|
2239
|
-
"id",
|
|
2240
|
-
"fileName",
|
|
2241
|
-
"loaderName",
|
|
2242
|
-
"resolvedId",
|
|
2243
|
-
"scriptId"
|
|
2244
|
-
];
|
|
2245
|
-
for (const keyName of keyNames) {
|
|
2246
|
-
const key = value[keyName];
|
|
2247
|
-
if (typeof key === "undefined" || map.has(key)) {
|
|
2248
|
-
continue;
|
|
2249
|
-
} else {
|
|
2250
|
-
map.set(key, value);
|
|
2251
|
-
}
|
|
2252
|
-
}
|
|
2253
|
-
});
|
|
2254
|
-
function hashScriptId(script) {
|
|
2255
|
-
return hash(`${script.type}&${script.id}`);
|
|
2256
|
-
}
|
|
2257
|
-
function createDevLoader({
|
|
2258
|
-
preamble,
|
|
2259
|
-
client,
|
|
2260
|
-
fileName
|
|
2261
|
-
}) {
|
|
2262
|
-
return contentDevLoader.replace(/__PREAMBLE__/g, JSON.stringify(preamble)).replace(/__CLIENT__/g, JSON.stringify(client)).replace(/__SCRIPT__/g, JSON.stringify(fileName)).replace(/__TIMESTAMP__/g, JSON.stringify(Date.now()));
|
|
2263
|
-
}
|
|
2264
|
-
function createProLoader({ fileName }) {
|
|
2265
|
-
return contentProLoader.replace(/__SCRIPT__/g, JSON.stringify(fileName));
|
|
2266
|
-
}
|
|
2267
|
-
|
|
2268
|
-
const serverEvent$ = new ReplaySubject(1);
|
|
2269
|
-
const close$ = serverEvent$.pipe(filter((e) => e.type === "close"), switchMap((e) => of(e)));
|
|
2270
|
-
const start$ = serverEvent$.pipe(filter((e) => e.type === "start"), switchMap((e) => of(e)));
|
|
2271
|
-
const fileWriterEvent$ = new ReplaySubject(1);
|
|
2272
|
-
const buildEnd$ = fileWriterEvent$.pipe(filter((e) => e.type === "build_end"), switchMap((e) => of(e)));
|
|
2273
|
-
fileWriterEvent$.pipe(filter((e) => e.type === "build_start"), switchMap((e) => of(e)));
|
|
2274
|
-
const allFilesReady$ = buildEnd$.pipe(switchMap(() => outputFiles.change$.pipe(startWith({ type: "start" }))), map(() => [...outputFiles.values()]), switchMap((files) => Promise.allSettled(files.map(({ file }) => file))));
|
|
2275
|
-
const isRejected = (x) => x?.status === "rejected";
|
|
2276
|
-
const fileWriterError$ = allFilesReady$.pipe(mergeMap((results) => results.filter(isRejected)), map((rejected) => ({ err: rejected.reason, type: "error" })));
|
|
2277
|
-
firstValueFrom(fileWriterError$.pipe(takeUntil(serverEvent$.pipe(first(({ type }) => type === "close"))), toArray()));
|
|
2278
|
-
function prepFileData(fileId) {
|
|
2279
|
-
const fileName = getFileName(fileId);
|
|
2280
|
-
if (fileId.type === "asset") {
|
|
2281
|
-
return prepAsset(fileName, fileId);
|
|
2282
|
-
} else {
|
|
2283
|
-
return prepScript(fileName, fileId);
|
|
2284
|
-
}
|
|
2285
|
-
}
|
|
2286
|
-
function prepAsset(fileName, { id, source }) {
|
|
2287
|
-
return ($) => $.pipe(mergeMap(async ({ server }) => {
|
|
2288
|
-
const target = getOutputPath(server, fileName);
|
|
2289
|
-
return {
|
|
2290
|
-
target,
|
|
2291
|
-
source: source ?? await promises.readFile(join(server.config.root, id)),
|
|
2292
|
-
deps: []
|
|
2293
|
-
};
|
|
2294
|
-
}));
|
|
2295
|
-
}
|
|
2296
|
-
function prepScript(fileName, script) {
|
|
2297
|
-
return ($) => $.pipe(mergeMap(async ({ server }) => {
|
|
2298
|
-
const target = getOutputPath(server, fileName);
|
|
2299
|
-
const viteUrl = getViteUrl(script);
|
|
2300
|
-
const transformResult = await server.transformRequest(viteUrl);
|
|
2301
|
-
if (!transformResult)
|
|
2302
|
-
throw new TypeError(`Unable to load "${script.id}" from server.`);
|
|
2303
|
-
const { code, deps = [], dynamicDeps = [] } = transformResult;
|
|
2304
|
-
return { target, code, deps: [...deps, ...dynamicDeps].flat(), server };
|
|
2305
|
-
}), retry({ count: 10, delay: 100 }), mergeMap(async ({ target, server, ...rest }) => {
|
|
2306
|
-
const plugins = server.config.plugins;
|
|
2307
|
-
let { code, deps } = rest;
|
|
2308
|
-
for (const plugin of plugins) {
|
|
2309
|
-
const r = await plugin.renderCrxDevScript?.(code, script);
|
|
2310
|
-
if (typeof r === "string")
|
|
2311
|
-
code = r;
|
|
2312
|
-
}
|
|
2313
|
-
return { target, code, deps };
|
|
2314
|
-
}), mergeMap(async ({ target, code, deps }) => {
|
|
2315
|
-
await lexer__namespace.init;
|
|
2316
|
-
const [imports] = lexer__namespace.parse(code, fileName);
|
|
2317
|
-
const depSet = new Set(deps);
|
|
2318
|
-
const magic = new MagicString__default["default"](code);
|
|
2319
|
-
for (const i of imports)
|
|
2320
|
-
if (i.n) {
|
|
2321
|
-
depSet.add(i.n);
|
|
2322
|
-
const fileName2 = getFileName({ type: "module", id: i.n });
|
|
2323
|
-
magic.overwrite(i.s, i.e, `/${fileName2}`);
|
|
2324
|
-
}
|
|
2325
|
-
return { target, source: magic.toString(), deps: [...depSet] };
|
|
2326
|
-
}));
|
|
2327
|
-
}
|
|
2328
|
-
async function allFilesReady() {
|
|
2329
|
-
await firstValueFrom(allFilesReady$);
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
const { outputFile } = fsx__default["default"];
|
|
2333
|
-
_debug("file-writer");
|
|
2334
|
-
async function start({
|
|
2335
|
-
server
|
|
2336
|
-
}) {
|
|
2337
|
-
serverEvent$.next({ type: "start", server });
|
|
2338
|
-
const plugins = server.config.plugins.filter((p) => p.name?.startsWith("crx:"));
|
|
2339
|
-
const { rollupOptions, outDir } = server.config.build;
|
|
2340
|
-
const inputOptions = {
|
|
2341
|
-
input: "index.html",
|
|
2342
|
-
...rollupOptions,
|
|
2343
|
-
plugins
|
|
2344
|
-
};
|
|
2345
|
-
const rollupOutputOptions = [rollupOptions.output].flat()[0];
|
|
2346
|
-
const outputOptions = {
|
|
2347
|
-
...rollupOutputOptions,
|
|
2348
|
-
dir: outDir,
|
|
2349
|
-
format: "es"
|
|
2350
|
-
};
|
|
2351
|
-
fileWriterEvent$.next({ type: "build_start" });
|
|
2352
|
-
const build = await rollup.rollup(inputOptions);
|
|
2353
|
-
await build.write(outputOptions);
|
|
2354
|
-
fileWriterEvent$.next({ type: "build_end" });
|
|
2355
|
-
await allFilesReady();
|
|
2356
|
-
}
|
|
2357
|
-
async function close() {
|
|
2358
|
-
serverEvent$.next({ type: "close" });
|
|
2359
|
-
}
|
|
2360
|
-
function add(script) {
|
|
2361
|
-
const fileName = getFileName(script);
|
|
2362
|
-
let file = outputFiles.get(fileName);
|
|
2363
|
-
if (typeof file === "undefined") {
|
|
2364
|
-
file = formatFileData({
|
|
2365
|
-
...script,
|
|
2366
|
-
fileName,
|
|
2367
|
-
file: write(script)
|
|
2368
|
-
});
|
|
2369
|
-
outputFiles.set(file.fileName, file);
|
|
2370
|
-
}
|
|
2371
|
-
return file;
|
|
2372
|
-
}
|
|
2373
|
-
function update(_id) {
|
|
2374
|
-
const id = prefix$1("/", _id);
|
|
2375
|
-
const types = ["iife", "module"];
|
|
2376
|
-
const updatedFiles = [];
|
|
2377
|
-
for (const type of types) {
|
|
2378
|
-
const fileName = getFileName({ id, type });
|
|
2379
|
-
const scriptFile = outputFiles.get(fileName);
|
|
2380
|
-
if (scriptFile) {
|
|
2381
|
-
scriptFile.file = write({ id, type });
|
|
2382
|
-
updatedFiles.push(scriptFile);
|
|
2383
|
-
outputFiles.set(fileName, scriptFile);
|
|
2384
|
-
}
|
|
2385
|
-
}
|
|
2386
|
-
return updatedFiles;
|
|
2387
|
-
}
|
|
2388
|
-
async function write(fileId) {
|
|
2389
|
-
const start2 = perf_hooks.performance.now();
|
|
2390
|
-
const deps = await firstValueFrom(start$.pipe(prepFileData(fileId), mergeMap(async ({ target, source, deps: deps2 }) => {
|
|
2391
|
-
const files = deps2.map((id) => {
|
|
2392
|
-
const r = [add({ id, type: "module" })];
|
|
2393
|
-
if (id.includes("?import")) {
|
|
2394
|
-
const [imported] = id.split("?import");
|
|
2395
|
-
r.push(add({ id: imported, type: "asset" }));
|
|
2396
|
-
}
|
|
2397
|
-
return r;
|
|
2398
|
-
}).flat();
|
|
2399
|
-
if (source instanceof Uint8Array)
|
|
2400
|
-
await outputFile(target, source);
|
|
2401
|
-
else
|
|
2402
|
-
await outputFile(target, source, { encoding: "utf8" });
|
|
2403
|
-
return files;
|
|
2404
|
-
}), takeUntil(close$), concatWith(of([]))));
|
|
2405
|
-
const close2 = perf_hooks.performance.now();
|
|
2406
|
-
return { start: start2, close: close2, deps };
|
|
2407
|
-
}
|
|
2408
|
-
|
|
2409
|
-
const pluginContentScripts = () => {
|
|
2410
|
-
let server;
|
|
2411
|
-
let preambleCode;
|
|
2412
|
-
let hmrTimeout;
|
|
2413
|
-
let sub = new Subscription();
|
|
2414
|
-
return [
|
|
2415
|
-
{
|
|
2416
|
-
name: "crx:content-scripts",
|
|
2417
|
-
apply: "serve",
|
|
2418
|
-
config(config) {
|
|
2419
|
-
const { contentScripts: contentScripts2 = {} } = getOptions(config);
|
|
2420
|
-
hmrTimeout = contentScripts2.hmrTimeout ?? 5e3;
|
|
2421
|
-
preambleCode = preambleCode ?? contentScripts2.preambleCode;
|
|
2422
|
-
},
|
|
2423
|
-
async configureServer(_server) {
|
|
2424
|
-
server = _server;
|
|
2425
|
-
if (typeof preambleCode === "undefined" && server.config.plugins.some(({ name = "none" }) => name.toLowerCase().includes("react"))) {
|
|
2426
|
-
try {
|
|
2427
|
-
const react = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@vitejs/plugin-react')); });
|
|
2428
|
-
preambleCode = react.default.preambleCode;
|
|
2429
|
-
} catch (error) {
|
|
2430
|
-
preambleCode = false;
|
|
2431
|
-
}
|
|
2432
|
-
}
|
|
2433
|
-
sub.add(contentScripts.change$.pipe(filter(RxMap.isChangeType.set)).subscribe(({ value: script }) => {
|
|
2434
|
-
const { type, id } = script;
|
|
2435
|
-
if (type === "loader") {
|
|
2436
|
-
let preamble = { fileName: "" };
|
|
2437
|
-
if (preambleCode)
|
|
2438
|
-
preamble = add({ type: "module", id: preambleId });
|
|
2439
|
-
const client = add({ type: "module", id: viteClientId });
|
|
2440
|
-
const file = add({ type: "module", id });
|
|
2441
|
-
const loader = add({
|
|
2442
|
-
type: "asset",
|
|
2443
|
-
id: getFileName({ type: "loader", id }),
|
|
2444
|
-
source: createDevLoader({
|
|
2445
|
-
preamble: preamble.fileName,
|
|
2446
|
-
client: client.fileName,
|
|
2447
|
-
fileName: file.fileName
|
|
2448
|
-
})
|
|
2449
|
-
});
|
|
2450
|
-
script.fileName = loader.fileName;
|
|
2451
|
-
} else if (type === "iife") {
|
|
2452
|
-
throw new Error("IIFE content scripts are not implemented");
|
|
2453
|
-
} else {
|
|
2454
|
-
const file = add({ type: "module", id });
|
|
2455
|
-
script.fileName = file.fileName;
|
|
2456
|
-
}
|
|
2457
|
-
}));
|
|
2458
|
-
},
|
|
2459
|
-
resolveId(source) {
|
|
2460
|
-
if (source === preambleId)
|
|
2461
|
-
return preambleId;
|
|
2462
|
-
if (source === contentHmrPortId)
|
|
2463
|
-
return contentHmrPortId;
|
|
2464
|
-
},
|
|
2465
|
-
load(id) {
|
|
2466
|
-
if (id === preambleId && typeof preambleCode === "string") {
|
|
2467
|
-
const defined = preambleCode.replace(/__BASE__/g, server.config.base);
|
|
2468
|
-
return defined;
|
|
2469
|
-
}
|
|
2470
|
-
if (id === contentHmrPortId) {
|
|
2471
|
-
const defined = contentHmrPort.replace("__CRX_HMR_TIMEOUT__", JSON.stringify(hmrTimeout));
|
|
2472
|
-
return defined;
|
|
2473
|
-
}
|
|
2474
|
-
},
|
|
2475
|
-
closeBundle() {
|
|
2476
|
-
sub.unsubscribe();
|
|
2477
|
-
sub = new Subscription();
|
|
2478
|
-
}
|
|
2479
|
-
},
|
|
2480
|
-
{
|
|
2481
|
-
name: "crx:content-scripts",
|
|
2482
|
-
apply: "build",
|
|
2483
|
-
enforce: "pre",
|
|
2484
|
-
generateBundle() {
|
|
2485
|
-
for (const [key, script] of contentScripts)
|
|
2486
|
-
if (key === script.refId) {
|
|
2487
|
-
if (script.type === "module") {
|
|
2488
|
-
const fileName = this.getFileName(script.refId);
|
|
2489
|
-
script.fileName = fileName;
|
|
2490
|
-
} else if (script.type === "loader") {
|
|
2491
|
-
const fileName = this.getFileName(script.refId);
|
|
2492
|
-
script.fileName = fileName;
|
|
2493
|
-
const refId = this.emitFile({
|
|
2494
|
-
type: "asset",
|
|
2495
|
-
name: getFileName({ type: "loader", id: basename(script.id) }),
|
|
2496
|
-
source: createProLoader({ fileName })
|
|
2497
|
-
});
|
|
2498
|
-
script.loaderName = this.getFileName(refId);
|
|
2499
|
-
} else if (script.type === "iife") {
|
|
2500
|
-
throw new Error("IIFE content scripts are not implemented");
|
|
2501
|
-
}
|
|
2502
|
-
contentScripts.set(script.refId, formatFileData(script));
|
|
2503
|
-
}
|
|
2504
|
-
}
|
|
2505
|
-
}
|
|
2506
|
-
];
|
|
2507
|
-
};
|
|
2508
|
-
|
|
2509
|
-
const pluginContentScriptsCss = () => {
|
|
2510
|
-
let injectCss;
|
|
2511
|
-
return {
|
|
2512
|
-
name: "crx:content-scripts-css",
|
|
2513
|
-
enforce: "post",
|
|
2514
|
-
config(config) {
|
|
2515
|
-
const { contentScripts: contentScripts2 = {} } = getOptions(config);
|
|
2516
|
-
injectCss = contentScripts2.injectCss ?? true;
|
|
2517
|
-
},
|
|
2518
|
-
renderCrxManifest(manifest) {
|
|
2519
|
-
if (injectCss) {
|
|
2520
|
-
if (manifest.content_scripts) {
|
|
2521
|
-
for (const script of manifest.content_scripts)
|
|
2522
|
-
if (script.js)
|
|
2523
|
-
for (const fileName of script.js)
|
|
2524
|
-
if (contentScripts.has(fileName)) {
|
|
2525
|
-
const { css } = contentScripts.get(fileName);
|
|
2526
|
-
if (css?.length)
|
|
2527
|
-
script.css = [script.css ?? [], css].flat();
|
|
2528
|
-
} else {
|
|
2529
|
-
throw new Error(`Content script is undefined by fileName: ${fileName}`);
|
|
2530
|
-
}
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
return manifest;
|
|
2534
|
-
}
|
|
2535
|
-
};
|
|
2536
|
-
};
|
|
2537
|
-
|
|
2538
|
-
const pluginDeclaredContentScripts = () => {
|
|
2539
|
-
return [];
|
|
2540
|
-
};
|
|
2541
|
-
|
|
2542
|
-
const _dynamicScriptRegEx = /\b(import.meta).CRX_DYNAMIC_SCRIPT_(.+?);$/gm;
|
|
2543
|
-
const dynamicScriptRegEx = () => {
|
|
2544
|
-
_dynamicScriptRegEx.lastIndex = 0;
|
|
2545
|
-
return _dynamicScriptRegEx;
|
|
2546
|
-
};
|
|
2547
|
-
const pluginDynamicContentScripts = () => {
|
|
2548
|
-
let config;
|
|
2549
|
-
return [
|
|
2550
|
-
{
|
|
2551
|
-
name: "crx:dynamic-content-scripts-loader",
|
|
2552
|
-
enforce: "pre",
|
|
2553
|
-
configResolved(_config) {
|
|
2554
|
-
config = _config;
|
|
2555
|
-
},
|
|
2556
|
-
async resolveId(_source, importer) {
|
|
2557
|
-
if (importer && _source.includes("?script")) {
|
|
2558
|
-
const url = new URL(_source, "stub://stub");
|
|
2559
|
-
if (url.searchParams.has("script")) {
|
|
2560
|
-
const [source] = _source.split("?");
|
|
2561
|
-
const resolved = await this.resolve(source, importer, {
|
|
2562
|
-
skipSelf: true
|
|
2563
|
-
});
|
|
2564
|
-
if (!resolved)
|
|
2565
|
-
throw new Error(`Could not resolve dynamic script: "${_source}" from "${importer}"`);
|
|
2566
|
-
const { id } = resolved;
|
|
2567
|
-
let type = "loader";
|
|
2568
|
-
if (url.searchParams.has("module")) {
|
|
2569
|
-
type = "module";
|
|
2570
|
-
} else if (url.searchParams.has("iife")) {
|
|
2571
|
-
type = "iife";
|
|
2572
|
-
}
|
|
2573
|
-
const scriptId = hashScriptId({ type, id });
|
|
2574
|
-
const resolvedId = `${id}?scriptId=${scriptId}`;
|
|
2575
|
-
let script = contentScripts.get(resolvedId);
|
|
2576
|
-
if (typeof script === "undefined") {
|
|
2577
|
-
let refId;
|
|
2578
|
-
let fileName;
|
|
2579
|
-
let loaderName;
|
|
2580
|
-
if (config.command === "build") {
|
|
2581
|
-
refId = this.emitFile({
|
|
2582
|
-
type: "chunk",
|
|
2583
|
-
id,
|
|
2584
|
-
name: basename(id)
|
|
2585
|
-
});
|
|
2586
|
-
} else {
|
|
2587
|
-
refId = scriptId;
|
|
2588
|
-
const relId = relative(config.root, id);
|
|
2589
|
-
fileName = getFileName({
|
|
2590
|
-
type: type === "iife" ? "iife" : "module",
|
|
2591
|
-
id: relId
|
|
2592
|
-
});
|
|
2593
|
-
if (type === "loader")
|
|
2594
|
-
loaderName = getFileName({ type, id: relId });
|
|
2595
|
-
}
|
|
2596
|
-
script = formatFileData({
|
|
2597
|
-
type,
|
|
2598
|
-
id: relative(config.root, id),
|
|
2599
|
-
isDynamicScript: true,
|
|
2600
|
-
fileName,
|
|
2601
|
-
loaderName,
|
|
2602
|
-
refId,
|
|
2603
|
-
scriptId,
|
|
2604
|
-
matches: []
|
|
2605
|
-
});
|
|
2606
|
-
contentScripts.set(script.id, script);
|
|
2607
|
-
}
|
|
2608
|
-
return resolvedId;
|
|
2609
|
-
} else if (url.searchParams.has("scriptId")) {
|
|
2610
|
-
return _source;
|
|
2611
|
-
}
|
|
2612
|
-
}
|
|
2613
|
-
},
|
|
2614
|
-
async load(id) {
|
|
2615
|
-
const index = id.indexOf("?scriptId=");
|
|
2616
|
-
if (index > -1) {
|
|
2617
|
-
const scriptId = id.slice(index + "?scriptId=".length);
|
|
2618
|
-
const script = contentScripts.get(scriptId);
|
|
2619
|
-
if (config.command === "build") {
|
|
2620
|
-
return `export default import.meta.CRX_DYNAMIC_SCRIPT_${script.refId};`;
|
|
2621
|
-
} else if (typeof script.fileName === "string") {
|
|
2622
|
-
await fileReady(script);
|
|
2623
|
-
return `export default ${JSON.stringify(script.fileName)};`;
|
|
2624
|
-
} else {
|
|
2625
|
-
throw new Error(`Content script fileName is undefined: "${script.id}"`);
|
|
2626
|
-
}
|
|
2627
|
-
}
|
|
2628
|
-
}
|
|
2629
|
-
},
|
|
2630
|
-
{
|
|
2631
|
-
name: "crx:dynamic-content-scripts-build",
|
|
2632
|
-
apply: "build",
|
|
2633
|
-
generateBundle(options, bundle) {
|
|
2634
|
-
for (const chunk of Object.values(bundle))
|
|
2635
|
-
if (chunk.type === "chunk") {
|
|
2636
|
-
if (dynamicScriptRegEx().test(chunk.code)) {
|
|
2637
|
-
const replaced = chunk.code.replace(dynamicScriptRegEx(), (match, p1, scriptKey) => {
|
|
2638
|
-
const script = contentScripts.get(scriptKey);
|
|
2639
|
-
if (typeof script === "undefined")
|
|
2640
|
-
throw new Error(`Content script refId is undefined: "${match}"`);
|
|
2641
|
-
if (typeof script.fileName === "undefined")
|
|
2642
|
-
throw new Error(`Content script fileName is undefined: "${script.id}"`);
|
|
2643
|
-
return `${JSON.stringify(`/${script.loaderName ?? script.fileName}`)};`;
|
|
2644
|
-
});
|
|
2645
|
-
chunk.code = replaced;
|
|
2646
|
-
}
|
|
2647
|
-
}
|
|
2648
|
-
}
|
|
2649
|
-
}
|
|
2650
|
-
];
|
|
2651
|
-
};
|
|
2652
|
-
|
|
2653
|
-
const logger = vite.createLogger("error", { prefix: "crxjs" });
|
|
2654
|
-
const pluginFileWriter = () => {
|
|
2655
|
-
fileWriterError$.subscribe((error) => {
|
|
2656
|
-
logger.error(error.err.message, { error: error.err });
|
|
2657
|
-
});
|
|
2658
|
-
return {
|
|
2659
|
-
name: "crx:file-writer",
|
|
2660
|
-
apply: "serve",
|
|
2661
|
-
configureServer(server) {
|
|
2662
|
-
server.httpServer?.on("listening", async () => {
|
|
2663
|
-
try {
|
|
2664
|
-
await start({ server });
|
|
2665
|
-
} catch (error) {
|
|
2666
|
-
console.error(error);
|
|
2667
|
-
server.close();
|
|
2668
|
-
}
|
|
2669
|
-
});
|
|
2670
|
-
server.httpServer?.on("close", () => close());
|
|
2671
|
-
},
|
|
2672
|
-
closeBundle() {
|
|
2673
|
-
outputFiles.clear();
|
|
2674
|
-
}
|
|
2675
|
-
};
|
|
2676
|
-
};
|
|
2677
|
-
|
|
2678
|
-
const _require = typeof require === "undefined" ? module$1.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href))) : require;
|
|
2679
|
-
const customElementsPath = _require.resolve(customElementsId.slice(1));
|
|
2680
|
-
const customElementsCode = fs.readFileSync(customElementsPath, "utf8");
|
|
2681
|
-
const customElementsMap = fs.readFileSync(`${customElementsPath}.map`, "utf8");
|
|
2682
|
-
const pluginFileWriterPolyfill = () => {
|
|
2683
|
-
return {
|
|
2684
|
-
name: "crx:file-writer-polyfill",
|
|
2685
|
-
apply: "serve",
|
|
2686
|
-
enforce: "pre",
|
|
2687
|
-
resolveId(source) {
|
|
2688
|
-
if (source === customElementsId) {
|
|
2689
|
-
return customElementsId;
|
|
2690
|
-
}
|
|
2691
|
-
},
|
|
2692
|
-
load(id) {
|
|
2693
|
-
if (id === customElementsId) {
|
|
2694
|
-
return { code: customElementsCode, map: customElementsMap };
|
|
2695
|
-
}
|
|
2696
|
-
},
|
|
2697
|
-
renderCrxDevScript(code, { type, id }) {
|
|
2698
|
-
if (type === "module" && id === viteClientId) {
|
|
2699
|
-
const magic = new MagicString__default["default"](code);
|
|
2700
|
-
magic.prepend(`import '${customElementsId}';`);
|
|
2701
|
-
magic.prepend(`import { HMRPort } from '${contentHmrPortId}';`);
|
|
2702
|
-
const ws = "new WebSocket";
|
|
2703
|
-
const index = code.indexOf(ws);
|
|
2704
|
-
magic.overwrite(index, index + ws.length, "new HMRPort");
|
|
2705
|
-
return magic.toString();
|
|
2706
|
-
}
|
|
2707
|
-
}
|
|
2708
|
-
};
|
|
2709
|
-
};
|
|
2710
|
-
|
|
2711
|
-
async function manifestFiles(manifest, options = {}) {
|
|
2712
|
-
let locales = [];
|
|
2713
|
-
if (manifest.default_locale)
|
|
2714
|
-
locales = await fg__default["default"]("_locales/**/messages.json", options);
|
|
2715
|
-
const rulesets = manifest.declarative_net_request?.rule_resources.flatMap(({ path }) => path) ?? [];
|
|
2716
|
-
const contentScripts = manifest.content_scripts?.flatMap(({ js }) => js) ?? [];
|
|
2717
|
-
const contentStyles = manifest.content_scripts?.flatMap(({ css }) => css);
|
|
2718
|
-
const serviceWorker = manifest.background?.service_worker;
|
|
2719
|
-
const htmlPages = htmlFiles(manifest);
|
|
2720
|
-
const icons = [
|
|
2721
|
-
Object.values(isString(manifest.icons) ? [manifest.icons] : manifest.icons ?? {}),
|
|
2722
|
-
Object.values(isString(manifest.action?.default_icon) ? [manifest.action?.default_icon] : manifest.action?.default_icon ?? {})
|
|
2723
|
-
].flat();
|
|
2724
|
-
let webAccessibleResources = [];
|
|
2725
|
-
if (manifest.web_accessible_resources) {
|
|
2726
|
-
const resources = await Promise.all(manifest.web_accessible_resources.flatMap(({ resources: resources2 }) => resources2).map(async (r) => {
|
|
2727
|
-
if (["*", "**/*"].includes(r))
|
|
2728
|
-
return void 0;
|
|
2729
|
-
if (fg__default["default"].isDynamicPattern(r))
|
|
2730
|
-
return fg__default["default"](r, options);
|
|
2731
|
-
return r;
|
|
2732
|
-
}));
|
|
2733
|
-
webAccessibleResources = resources.flat().filter(isString);
|
|
2734
|
-
}
|
|
2735
|
-
return {
|
|
2736
|
-
contentScripts: [...new Set(contentScripts)].filter(isString),
|
|
2737
|
-
contentStyles: [...new Set(contentStyles)].filter(isString),
|
|
2738
|
-
html: htmlPages,
|
|
2739
|
-
icons: [...new Set(icons)].filter(isString),
|
|
2740
|
-
locales: [...new Set(locales)].filter(isString),
|
|
2741
|
-
rulesets: [...new Set(rulesets)].filter(isString),
|
|
2742
|
-
background: [serviceWorker].filter(isString),
|
|
2743
|
-
webAccessibleResources
|
|
2744
|
-
};
|
|
2745
|
-
}
|
|
2746
|
-
async function dirFiles(dir) {
|
|
2747
|
-
const files = await fg__default["default"](`${dir}/**/*`);
|
|
2748
|
-
return files;
|
|
2749
|
-
}
|
|
2750
|
-
function htmlFiles(manifest) {
|
|
2751
|
-
const files = [
|
|
2752
|
-
manifest.action?.default_popup,
|
|
2753
|
-
Object.values(manifest.chrome_url_overrides ?? {}),
|
|
2754
|
-
manifest.devtools_page,
|
|
2755
|
-
manifest.options_page,
|
|
2756
|
-
manifest.options_ui?.page,
|
|
2757
|
-
manifest.sandbox?.pages
|
|
2758
|
-
].flat().filter(isString).map((s) => s.split("#")[0]).sort();
|
|
2759
|
-
return [...new Set(files)];
|
|
2760
|
-
}
|
|
2761
|
-
|
|
2762
|
-
const pluginFileWriterPublic = () => {
|
|
2763
|
-
let config;
|
|
2764
|
-
return {
|
|
2765
|
-
name: "crx:file-writer-public",
|
|
2766
|
-
apply: "serve",
|
|
2767
|
-
configResolved(_config) {
|
|
2768
|
-
config = _config;
|
|
2769
|
-
},
|
|
2770
|
-
async generateBundle() {
|
|
2771
|
-
const publicDir = isAbsolute(config.publicDir) ? config.publicDir : resolve(config.root, config.publicDir);
|
|
2772
|
-
const files = await dirFiles(publicDir);
|
|
2773
|
-
for (const filepath of files) {
|
|
2774
|
-
const source = await promises.readFile(filepath);
|
|
2775
|
-
const fileName = relative(publicDir, filepath);
|
|
2776
|
-
this.emitFile({ type: "asset", source, fileName });
|
|
2777
|
-
}
|
|
2778
|
-
}
|
|
2779
|
-
};
|
|
2780
|
-
};
|
|
2781
|
-
|
|
2782
|
-
_debug("file-writer").extend("hmr");
|
|
2783
|
-
const isCrxHMRPayload = (p) => p.type === "custom" && p.event.startsWith("crx:");
|
|
2784
|
-
const hmrPayload$ = new Subject();
|
|
2785
|
-
const crxHMRPayload$ = hmrPayload$.pipe(filter((p) => !isCrxHMRPayload(p)), buffer(allFilesReady$), mergeMap((pps) => {
|
|
2786
|
-
let fullReload;
|
|
2787
|
-
const payloads = [];
|
|
2788
|
-
for (const p of pps)
|
|
2789
|
-
if (p.type === "full-reload") {
|
|
2790
|
-
fullReload = p;
|
|
2791
|
-
} else {
|
|
2792
|
-
payloads.push(p);
|
|
2793
|
-
}
|
|
2794
|
-
if (fullReload)
|
|
2795
|
-
payloads.push(fullReload);
|
|
2796
|
-
return payloads;
|
|
2797
|
-
}), map((p) => {
|
|
2798
|
-
switch (p.type) {
|
|
2799
|
-
case "full-reload": {
|
|
2800
|
-
const fullReload = {
|
|
2801
|
-
type: "full-reload",
|
|
2802
|
-
path: p.path && getViteUrl({ id: p.path, type: "module" })
|
|
2803
|
-
};
|
|
2804
|
-
return fullReload;
|
|
2805
|
-
}
|
|
2806
|
-
case "prune": {
|
|
2807
|
-
const prune = {
|
|
2808
|
-
type: "prune",
|
|
2809
|
-
paths: p.paths.map((id) => getViteUrl({ id, type: "module" }))
|
|
2810
|
-
};
|
|
2811
|
-
return prune;
|
|
2812
|
-
}
|
|
2813
|
-
case "update": {
|
|
2814
|
-
const update = {
|
|
2815
|
-
type: "update",
|
|
2816
|
-
updates: p.updates.map(({ acceptedPath: ap, path: p2, ...rest }) => ({
|
|
2817
|
-
...rest,
|
|
2818
|
-
acceptedPath: prefix$1("/", getFileName({ id: ap, type: "module" })),
|
|
2819
|
-
path: prefix$1("/", getFileName({ id: p2, type: "module" }))
|
|
2820
|
-
}))
|
|
2821
|
-
};
|
|
2822
|
-
return update;
|
|
2823
|
-
}
|
|
2824
|
-
default:
|
|
2825
|
-
return p;
|
|
2826
|
-
}
|
|
2827
|
-
}), filter((p) => {
|
|
2828
|
-
switch (p.type) {
|
|
2829
|
-
case "full-reload":
|
|
2830
|
-
return typeof p.path === "undefined";
|
|
2831
|
-
case "prune":
|
|
2832
|
-
return p.paths.length > 0;
|
|
2833
|
-
case "update":
|
|
2834
|
-
return p.updates.length > 0;
|
|
2835
|
-
default:
|
|
2836
|
-
return true;
|
|
2837
|
-
}
|
|
2838
|
-
}), map((data) => {
|
|
2839
|
-
return {
|
|
2840
|
-
type: "custom",
|
|
2841
|
-
event: "crx:content-script-payload",
|
|
2842
|
-
data
|
|
2843
|
-
};
|
|
2844
|
-
}));
|
|
2845
|
-
|
|
2846
|
-
function isImporter(file) {
|
|
2847
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2848
|
-
const pred = (changedNode) => {
|
|
2849
|
-
seen.add(changedNode);
|
|
2850
|
-
if (changedNode.file === file)
|
|
2851
|
-
return true;
|
|
2852
|
-
for (const parentNode of changedNode.importers) {
|
|
2853
|
-
const unseen = !seen.has(parentNode);
|
|
2854
|
-
if (unseen && pred(parentNode))
|
|
2855
|
-
return true;
|
|
2856
|
-
}
|
|
2857
|
-
return false;
|
|
2858
|
-
};
|
|
2859
|
-
return pred;
|
|
2860
|
-
}
|
|
2861
|
-
|
|
2862
|
-
const debug$1 = _debug("hmr");
|
|
2863
|
-
const crxRuntimeReload = {
|
|
2864
|
-
type: "custom",
|
|
2865
|
-
event: "crx:runtime-reload"
|
|
2866
|
-
};
|
|
2867
|
-
const pluginHMR = () => {
|
|
2868
|
-
let inputManifestFiles;
|
|
2869
|
-
let decoratedSend;
|
|
2870
|
-
let config;
|
|
2871
|
-
let subs;
|
|
2872
|
-
return [
|
|
2873
|
-
{
|
|
2874
|
-
name: "crx:hmr",
|
|
2875
|
-
apply: "serve",
|
|
2876
|
-
enforce: "pre",
|
|
2877
|
-
async config({ server = {}, ...config2 }) {
|
|
2878
|
-
if (server.hmr === false)
|
|
2879
|
-
return;
|
|
2880
|
-
if (server.hmr === true)
|
|
2881
|
-
server.hmr = {};
|
|
2882
|
-
server.hmr = server.hmr ?? {};
|
|
2883
|
-
server.hmr.host = "localhost";
|
|
2884
|
-
server.hmr.port = server.hmr.port ?? await getPort__default["default"]({ port: getPort.portNumbers(5200, 5300) });
|
|
2885
|
-
return { server, ...config2 };
|
|
2886
|
-
},
|
|
2887
|
-
configResolved(_config) {
|
|
2888
|
-
config = _config;
|
|
2889
|
-
const { watch = {} } = config.server;
|
|
2890
|
-
config.server.watch = watch;
|
|
2891
|
-
watch.ignored = watch.ignored ? [...new Set([watch.ignored].flat())] : [];
|
|
2892
|
-
const outDir = isAbsolute(config.build.outDir) ? config.build.outDir : join(config.root, config.build.outDir, "**/*");
|
|
2893
|
-
if (!watch.ignored.includes(outDir))
|
|
2894
|
-
watch.ignored.push(outDir);
|
|
2895
|
-
},
|
|
2896
|
-
configureServer(server) {
|
|
2897
|
-
if (server.ws.send !== decoratedSend) {
|
|
2898
|
-
const { send } = server.ws;
|
|
2899
|
-
decoratedSend = (payload) => {
|
|
2900
|
-
if (payload.type === "error") {
|
|
2901
|
-
send({
|
|
2902
|
-
type: "custom",
|
|
2903
|
-
event: "crx:content-script-payload",
|
|
2904
|
-
data: payload
|
|
2905
|
-
});
|
|
2906
|
-
} else {
|
|
2907
|
-
hmrPayload$.next(payload);
|
|
2908
|
-
}
|
|
2909
|
-
send(payload);
|
|
2910
|
-
};
|
|
2911
|
-
server.ws.send = decoratedSend;
|
|
2912
|
-
subs = new Subscription(() => subs = new Subscription());
|
|
2913
|
-
subs.add(fileWriterError$.subscribe(send));
|
|
2914
|
-
subs.add(crxHMRPayload$.subscribe((payload) => {
|
|
2915
|
-
send(payload);
|
|
2916
|
-
}));
|
|
2917
|
-
}
|
|
2918
|
-
},
|
|
2919
|
-
closeBundle() {
|
|
2920
|
-
subs.unsubscribe();
|
|
2921
|
-
},
|
|
2922
|
-
handleHotUpdate({ modules, server }) {
|
|
2923
|
-
const { root } = server.config;
|
|
2924
|
-
const relFiles = /* @__PURE__ */ new Set();
|
|
2925
|
-
for (const m of modules)
|
|
2926
|
-
if (m.id?.startsWith(root)) {
|
|
2927
|
-
relFiles.add(m.id.slice(server.config.root.length));
|
|
2928
|
-
}
|
|
2929
|
-
if (inputManifestFiles.background.length) {
|
|
2930
|
-
const background = prefix$1("/", inputManifestFiles.background[0]);
|
|
2931
|
-
if (relFiles.has(background) || modules.some(isImporter(join(server.config.root, background)))) {
|
|
2932
|
-
debug$1("sending runtime reload");
|
|
2933
|
-
server.ws.send(crxRuntimeReload);
|
|
2934
|
-
return [];
|
|
2935
|
-
}
|
|
2936
|
-
}
|
|
2937
|
-
for (const [key, script] of contentScripts)
|
|
2938
|
-
if (key === script.id) {
|
|
2939
|
-
if (relFiles.has(script.id) || modules.some(isImporter(join(server.config.root, script.id)))) {
|
|
2940
|
-
relFiles.forEach((relFile) => update(relFile));
|
|
2941
|
-
}
|
|
2942
|
-
}
|
|
2943
|
-
}
|
|
2944
|
-
},
|
|
2945
|
-
{
|
|
2946
|
-
name: "crx:hmr",
|
|
2947
|
-
apply: "serve",
|
|
2948
|
-
enforce: "post",
|
|
2949
|
-
async transformCrxManifest(manifest) {
|
|
2950
|
-
inputManifestFiles = await manifestFiles(manifest, { cwd: config.root });
|
|
2951
|
-
return null;
|
|
2952
|
-
},
|
|
2953
|
-
renderCrxDevScript(code, { id: _id, type }) {
|
|
2954
|
-
if (type === "module" && _id !== "/@vite/client" && code.includes("createHotContext")) {
|
|
2955
|
-
const id = _id.replace(/t=\d+&/, "");
|
|
2956
|
-
const escaped = id.replace(/([?&.])/g, "\\$1");
|
|
2957
|
-
const regexp = new RegExp(`(?<=createHotContext\\(")${escaped}(?="\\))`);
|
|
2958
|
-
const fileUrl = prefix$1("/", getFileName({ id, type }));
|
|
2959
|
-
const replaced = code.replace(regexp, fileUrl);
|
|
2960
|
-
return replaced;
|
|
2961
|
-
} else {
|
|
2962
|
-
return code;
|
|
2963
|
-
}
|
|
2964
|
-
}
|
|
2965
|
-
}
|
|
2966
|
-
];
|
|
2967
|
-
};
|
|
2968
|
-
|
|
2969
|
-
var loader = "try {\n for (const p of JSON.parse(SCRIPTS)) {\n const url = new URL(p, \"https://stub\");\n url.searchParams.set(\"t\", Date.now().toString());\n const req = url.pathname + url.search;\n await import(\n /* @vite-ignore */\n req\n );\n }\n} catch (error) {\n console.error(error);\n}\n";
|
|
2970
|
-
|
|
2971
|
-
const pluginName = "crx:html-inline-scripts";
|
|
2972
|
-
const debug = _debug(pluginName);
|
|
2973
|
-
const prefix = "@crx/inline-script";
|
|
2974
|
-
const isInlineTag = (t) => t.tag === "script" && !t.attrs?.src;
|
|
2975
|
-
const toKey = (ctx) => {
|
|
2976
|
-
const { dir, name } = parse(ctx.path);
|
|
2977
|
-
return join(prefix, dir, name);
|
|
2978
|
-
};
|
|
2979
|
-
const pluginHtmlInlineScripts = () => {
|
|
2980
|
-
const pages = /* @__PURE__ */ new Map();
|
|
2981
|
-
const auditTransformIndexHtml = (p) => {
|
|
2982
|
-
let transform;
|
|
2983
|
-
if (typeof p.transformIndexHtml === "function") {
|
|
2984
|
-
transform = p.transformIndexHtml;
|
|
2985
|
-
p.transformIndexHtml = auditor;
|
|
2986
|
-
} else if (typeof p.transformIndexHtml === "object") {
|
|
2987
|
-
transform = p.transformIndexHtml.transform;
|
|
2988
|
-
p.transformIndexHtml.transform = auditor;
|
|
2989
|
-
}
|
|
2990
|
-
async function auditor(_html, ctx) {
|
|
2991
|
-
const result = await transform(_html, ctx);
|
|
2992
|
-
if (!result || typeof result === "string")
|
|
2993
|
-
return result;
|
|
2994
|
-
let html;
|
|
2995
|
-
let tags;
|
|
2996
|
-
if (Array.isArray(result)) {
|
|
2997
|
-
tags = new Set(result);
|
|
2998
|
-
} else {
|
|
2999
|
-
tags = new Set(result.tags);
|
|
3000
|
-
html = result.html;
|
|
3001
|
-
}
|
|
3002
|
-
const scripts = [];
|
|
3003
|
-
for (const t of tags)
|
|
3004
|
-
if (t.tag === "script") {
|
|
3005
|
-
tags.delete(t);
|
|
3006
|
-
scripts.push(t);
|
|
3007
|
-
}
|
|
3008
|
-
const key = toKey(ctx);
|
|
3009
|
-
const page = pages.get(key);
|
|
3010
|
-
page.scripts.push(...scripts);
|
|
3011
|
-
pages.set(key, page);
|
|
3012
|
-
return html ? { html, tags: [...tags] } : [...tags];
|
|
3013
|
-
}
|
|
3014
|
-
};
|
|
3015
|
-
let base;
|
|
3016
|
-
const prePlugin = {
|
|
3017
|
-
name: "crx:html-auditor-pre",
|
|
3018
|
-
transformIndexHtml(html, ctx) {
|
|
3019
|
-
const key = toKey(ctx);
|
|
3020
|
-
pages.set(key, {
|
|
3021
|
-
...ctx,
|
|
3022
|
-
scripts: [
|
|
3023
|
-
{
|
|
3024
|
-
tag: "script",
|
|
3025
|
-
attrs: {
|
|
3026
|
-
type: "module",
|
|
3027
|
-
src: join(base, "@vite/client")
|
|
3028
|
-
},
|
|
3029
|
-
injectTo: "head-prepend"
|
|
3030
|
-
}
|
|
3031
|
-
]
|
|
3032
|
-
});
|
|
3033
|
-
}
|
|
3034
|
-
};
|
|
3035
|
-
const postPlugin = {
|
|
3036
|
-
name: "crx:html-auditor-post",
|
|
3037
|
-
transformIndexHtml(html, ctx) {
|
|
3038
|
-
const key = toKey(ctx);
|
|
3039
|
-
const p = pages.get(key);
|
|
3040
|
-
if (p?.scripts.some(isInlineTag)) {
|
|
3041
|
-
const $ = cheerio.load(html);
|
|
3042
|
-
p.scripts.push(...$("script").toArray().map((el) => ({
|
|
3043
|
-
tag: "script",
|
|
3044
|
-
attrs: { src: $(el).attr("src"), type: "module" }
|
|
3045
|
-
})));
|
|
3046
|
-
$("script").remove();
|
|
3047
|
-
const loader2 = {
|
|
3048
|
-
tag: "script",
|
|
3049
|
-
attrs: { src: `${key}?t=${Date.now()}`, type: "module" }
|
|
3050
|
-
};
|
|
3051
|
-
return { html: $.html(), tags: [loader2] };
|
|
3052
|
-
}
|
|
3053
|
-
return p?.scripts ?? void 0;
|
|
3054
|
-
}
|
|
3055
|
-
};
|
|
3056
|
-
return {
|
|
3057
|
-
name: "crx:html-auditor",
|
|
3058
|
-
apply: "serve",
|
|
3059
|
-
configResolved(config) {
|
|
3060
|
-
base = config.base;
|
|
3061
|
-
const plugins = config.plugins;
|
|
3062
|
-
for (const p of plugins)
|
|
3063
|
-
auditTransformIndexHtml(p);
|
|
3064
|
-
plugins.unshift(prePlugin);
|
|
3065
|
-
plugins.push(postPlugin);
|
|
3066
|
-
},
|
|
3067
|
-
configureServer(server) {
|
|
3068
|
-
const { transformIndexHtml } = server;
|
|
3069
|
-
server.transformIndexHtml = async function auditor(url, html, originalUrl) {
|
|
3070
|
-
let result = await transformIndexHtml(url, html, originalUrl);
|
|
3071
|
-
if (result.includes(prefix))
|
|
3072
|
-
result = result.replace(/\s+<script.+?@vite\/client.+?script>/, "");
|
|
3073
|
-
return result;
|
|
3074
|
-
};
|
|
3075
|
-
},
|
|
3076
|
-
resolveId(source) {
|
|
3077
|
-
const i = source.indexOf(prefix);
|
|
3078
|
-
if (i > -1)
|
|
3079
|
-
return source.slice(i);
|
|
3080
|
-
},
|
|
3081
|
-
load(id) {
|
|
3082
|
-
if (id.startsWith(prefix)) {
|
|
3083
|
-
const page = pages.get(id);
|
|
3084
|
-
if (page) {
|
|
3085
|
-
const inline = page.scripts.filter(isInlineTag).map((t) => t.children).join("\n");
|
|
3086
|
-
const dir = dirname(page.path);
|
|
3087
|
-
const scripts = page.scripts.map(({ attrs }) => attrs?.src).filter(isString).filter((src) => src !== "/@vite/client").map((src) => src.startsWith(".") ? resolve(dir, src) : src);
|
|
3088
|
-
const json = `"${jsesc__default["default"](JSON.stringify(scripts), {
|
|
3089
|
-
quotes: "double"
|
|
3090
|
-
})}"`;
|
|
3091
|
-
return [inline, loader.replace("SCRIPTS", json)].join("\n");
|
|
3092
|
-
} else {
|
|
3093
|
-
debug("page missing %s", id);
|
|
3094
|
-
}
|
|
3095
|
-
}
|
|
3096
|
-
}
|
|
3097
|
-
};
|
|
3098
|
-
};
|
|
3099
|
-
|
|
3100
|
-
var precontrollerJs = "const id = setInterval(() => location.reload(), 100);\nsetTimeout(() => clearInterval(id), 5e3);\n";
|
|
3101
|
-
|
|
3102
|
-
var precontrollerHtml = "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <title>Waiting for the extension service worker...</title>\n <script src=\"%SCRIPT%\"></script>\n </head>\n <body>\n <h1>Waiting for service worker</h1>\n\n <p>\n If you see this message, it means the service worker has not loaded fully.\n </p>\n\n <p>This page is never added in production.</p>\n </body>\n</html>\n";
|
|
3103
|
-
|
|
3104
|
-
const { readFile } = fs.promises;
|
|
3105
|
-
const pluginManifest = () => {
|
|
3106
|
-
let manifest;
|
|
3107
|
-
let plugins;
|
|
3108
|
-
let refId;
|
|
3109
|
-
let config;
|
|
3110
|
-
return [
|
|
3111
|
-
{
|
|
3112
|
-
name: "crx:manifest-init",
|
|
3113
|
-
enforce: "pre",
|
|
3114
|
-
async config(config2, env) {
|
|
3115
|
-
const { manifest: _manifest } = await getOptions(config2);
|
|
3116
|
-
manifest = await (typeof _manifest === "function" ? _manifest(env) : _manifest);
|
|
3117
|
-
if (manifest.manifest_version !== 3)
|
|
3118
|
-
throw new Error(`CRXJS does not support Manifest v${manifest.manifest_version}, please use Manifest v3`);
|
|
3119
|
-
if (env.command === "serve") {
|
|
3120
|
-
const {
|
|
3121
|
-
contentScripts: js,
|
|
3122
|
-
background: sw,
|
|
3123
|
-
html
|
|
3124
|
-
} = await manifestFiles(manifest, { cwd: config2.root });
|
|
3125
|
-
const { entries = [] } = config2.optimizeDeps ?? {};
|
|
3126
|
-
let { input = [] } = config2.build?.rollupOptions ?? {};
|
|
3127
|
-
if (typeof input === "string")
|
|
3128
|
-
input = [input];
|
|
3129
|
-
else
|
|
3130
|
-
input = Object.values(input);
|
|
3131
|
-
input = input.map((f) => {
|
|
3132
|
-
let result = f;
|
|
3133
|
-
if (isAbsolute(f)) {
|
|
3134
|
-
result = relative(config2.root ?? process.cwd(), f);
|
|
3135
|
-
}
|
|
3136
|
-
return result;
|
|
3137
|
-
});
|
|
3138
|
-
const set = new Set([entries, input].flat());
|
|
3139
|
-
for (const x of [js, sw, html].flat())
|
|
3140
|
-
set.add(x);
|
|
3141
|
-
return {
|
|
3142
|
-
...config2,
|
|
3143
|
-
optimizeDeps: {
|
|
3144
|
-
...config2.optimizeDeps,
|
|
3145
|
-
entries: [...set]
|
|
3146
|
-
}
|
|
3147
|
-
};
|
|
3148
|
-
}
|
|
3149
|
-
},
|
|
3150
|
-
buildStart(options) {
|
|
3151
|
-
if (options.plugins)
|
|
3152
|
-
plugins = options.plugins;
|
|
3153
|
-
}
|
|
3154
|
-
},
|
|
3155
|
-
{
|
|
3156
|
-
name: "crx:manifest-loader",
|
|
3157
|
-
enforce: "pre",
|
|
3158
|
-
buildStart(options) {
|
|
3159
|
-
if (typeof options.input !== "undefined") {
|
|
3160
|
-
refId = this.emitFile({
|
|
3161
|
-
type: "chunk",
|
|
3162
|
-
id: manifestId,
|
|
3163
|
-
name: "crx-manifest.js",
|
|
3164
|
-
preserveSignature: "strict"
|
|
3165
|
-
});
|
|
3166
|
-
}
|
|
3167
|
-
},
|
|
3168
|
-
resolveId(source) {
|
|
3169
|
-
if (source === manifestId)
|
|
3170
|
-
return manifestId;
|
|
3171
|
-
return null;
|
|
3172
|
-
},
|
|
3173
|
-
load(id) {
|
|
3174
|
-
if (id === manifestId)
|
|
3175
|
-
return encodeManifest(manifest);
|
|
3176
|
-
return null;
|
|
3177
|
-
}
|
|
3178
|
-
},
|
|
3179
|
-
{
|
|
3180
|
-
name: "crx:stub-input",
|
|
3181
|
-
enforce: "pre",
|
|
3182
|
-
options({ input, ...options }) {
|
|
3183
|
-
let finalInput = input;
|
|
3184
|
-
if (isString(input) && input.endsWith("index.html")) {
|
|
3185
|
-
finalInput = stubId;
|
|
3186
|
-
}
|
|
3187
|
-
if (config.command === "serve") {
|
|
3188
|
-
if (Array.isArray(input)) {
|
|
3189
|
-
finalInput = input.filter((x) => !x.endsWith(".html"));
|
|
3190
|
-
} else if (typeof input === "object") {
|
|
3191
|
-
for (const [key, value] of Object.entries(input))
|
|
3192
|
-
if (value.endsWith(".html"))
|
|
3193
|
-
delete input[key];
|
|
3194
|
-
}
|
|
3195
|
-
}
|
|
3196
|
-
return { input: finalInput, ...options };
|
|
3197
|
-
},
|
|
3198
|
-
resolveId(source) {
|
|
3199
|
-
if (source === stubId)
|
|
3200
|
-
return stubId;
|
|
3201
|
-
return null;
|
|
3202
|
-
},
|
|
3203
|
-
load(id) {
|
|
3204
|
-
if (id === stubId)
|
|
3205
|
-
return `console.log('stub')`;
|
|
3206
|
-
return null;
|
|
3207
|
-
},
|
|
3208
|
-
generateBundle(options, bundle) {
|
|
3209
|
-
for (const [key, chunk] of Object.entries(bundle)) {
|
|
3210
|
-
if (chunk.type === "chunk" && chunk.facadeModuleId === stubId) {
|
|
3211
|
-
delete bundle[key];
|
|
3212
|
-
break;
|
|
3213
|
-
}
|
|
3214
|
-
}
|
|
3215
|
-
}
|
|
3216
|
-
},
|
|
3217
|
-
{
|
|
3218
|
-
name: "crx:manifest-post",
|
|
3219
|
-
enforce: "post",
|
|
3220
|
-
configResolved(_config) {
|
|
3221
|
-
config = _config;
|
|
3222
|
-
const plugins2 = config.plugins;
|
|
3223
|
-
const crx = plugins2.findIndex(({ name }) => name === "crx:manifest-post");
|
|
3224
|
-
const [plugin] = plugins2.splice(crx, 1);
|
|
3225
|
-
plugins2.push(plugin);
|
|
3226
|
-
},
|
|
3227
|
-
async transform(code, id) {
|
|
3228
|
-
if (id !== manifestId)
|
|
3229
|
-
return;
|
|
3230
|
-
let manifest2 = decodeManifest.call(this, code);
|
|
3231
|
-
for (const plugin of plugins) {
|
|
3232
|
-
try {
|
|
3233
|
-
const m = structuredClone(manifest2);
|
|
3234
|
-
const result = await plugin.transformCrxManifest?.call(this, m);
|
|
3235
|
-
manifest2 = result ?? manifest2;
|
|
3236
|
-
} catch (error) {
|
|
3237
|
-
if (error instanceof Error)
|
|
3238
|
-
error.message = `[${plugin.name}] ${error.message}`;
|
|
3239
|
-
throw error;
|
|
3240
|
-
}
|
|
3241
|
-
}
|
|
3242
|
-
if (config.command === "serve") {
|
|
3243
|
-
if (manifest2.content_scripts)
|
|
3244
|
-
for (const { js = [], matches = [] } of manifest2.content_scripts)
|
|
3245
|
-
for (const id2 of js) {
|
|
3246
|
-
contentScripts.set(prefix$1("/", id2), formatFileData({
|
|
3247
|
-
type: "loader",
|
|
3248
|
-
id: id2,
|
|
3249
|
-
matches,
|
|
3250
|
-
refId: hashScriptId({ type: "loader", id: id2 }),
|
|
3251
|
-
fileName: getFileName({ type: "loader", id: id2 })
|
|
3252
|
-
}));
|
|
3253
|
-
}
|
|
3254
|
-
} else {
|
|
3255
|
-
if (manifest2.content_scripts)
|
|
3256
|
-
for (const { js = [], matches = [] } of manifest2.content_scripts)
|
|
3257
|
-
for (const file of js) {
|
|
3258
|
-
const id2 = join(config.root, file);
|
|
3259
|
-
const refId2 = this.emitFile({
|
|
3260
|
-
type: "chunk",
|
|
3261
|
-
id: id2,
|
|
3262
|
-
name: basename(file)
|
|
3263
|
-
});
|
|
3264
|
-
contentScripts.set(file, formatFileData({
|
|
3265
|
-
type: "loader",
|
|
3266
|
-
id: file,
|
|
3267
|
-
refId: refId2,
|
|
3268
|
-
matches
|
|
3269
|
-
}));
|
|
3270
|
-
}
|
|
3271
|
-
if (manifest2.background?.service_worker) {
|
|
3272
|
-
const file = manifest2.background.service_worker;
|
|
3273
|
-
const id2 = join(config.root, file);
|
|
3274
|
-
const refId2 = this.emitFile({
|
|
3275
|
-
type: "chunk",
|
|
3276
|
-
id: id2,
|
|
3277
|
-
name: basename(file)
|
|
3278
|
-
});
|
|
3279
|
-
manifest2.background.service_worker = refId2;
|
|
3280
|
-
}
|
|
3281
|
-
for (const file of htmlFiles(manifest2)) {
|
|
3282
|
-
const id2 = join(config.root, file);
|
|
3283
|
-
this.emitFile({
|
|
3284
|
-
type: "chunk",
|
|
3285
|
-
id: id2,
|
|
3286
|
-
name: basename(file)
|
|
3287
|
-
});
|
|
3288
|
-
}
|
|
3289
|
-
}
|
|
3290
|
-
const encoded = encodeManifest(manifest2);
|
|
3291
|
-
return encoded;
|
|
3292
|
-
},
|
|
3293
|
-
async generateBundle(options, bundle) {
|
|
3294
|
-
const manifestName = this.getFileName(refId);
|
|
3295
|
-
const manifestJs = bundle[manifestName];
|
|
3296
|
-
let manifest2 = decodeManifest.call(this, manifestJs.code);
|
|
3297
|
-
if (config.command === "serve") {
|
|
3298
|
-
if (manifest2.content_scripts)
|
|
3299
|
-
for (const script of manifest2.content_scripts) {
|
|
3300
|
-
script.js = script.js?.map((id) => getFileName({ id, type: "loader" }));
|
|
3301
|
-
}
|
|
3302
|
-
} else {
|
|
3303
|
-
if (manifest2.background?.service_worker) {
|
|
3304
|
-
const ref = manifest2.background.service_worker;
|
|
3305
|
-
const name = this.getFileName(ref);
|
|
3306
|
-
manifest2.background.service_worker = name;
|
|
3307
|
-
}
|
|
3308
|
-
manifest2.content_scripts = manifest2.content_scripts?.map(({ js = [], ...rest }) => {
|
|
3309
|
-
return {
|
|
3310
|
-
js: js.map((id) => {
|
|
3311
|
-
const script = contentScripts.get(id);
|
|
3312
|
-
const fileName = script?.loaderName ?? script?.fileName;
|
|
3313
|
-
if (typeof fileName === "undefined")
|
|
3314
|
-
throw new Error(`Content script fileName is undefined: "${id}"`);
|
|
3315
|
-
return fileName;
|
|
3316
|
-
}),
|
|
3317
|
-
...rest
|
|
3318
|
-
};
|
|
3319
|
-
});
|
|
3320
|
-
}
|
|
3321
|
-
for (const plugin of plugins) {
|
|
3322
|
-
try {
|
|
3323
|
-
const m = structuredClone(manifest2);
|
|
3324
|
-
const result = await plugin.renderCrxManifest?.call(this, m, bundle);
|
|
3325
|
-
manifest2 = result ?? manifest2;
|
|
3326
|
-
} catch (error) {
|
|
3327
|
-
const name = `[${plugin.name}]`;
|
|
3328
|
-
let message = error;
|
|
3329
|
-
if (error instanceof Error) {
|
|
3330
|
-
message = colors__default["default"].red(`${name} ${error.stack ? error.stack : error.message}`);
|
|
3331
|
-
} else if (typeof error === "string") {
|
|
3332
|
-
message = colors__default["default"].red(`${name} ${error}`);
|
|
3333
|
-
}
|
|
3334
|
-
console.log(message);
|
|
3335
|
-
throw new Error(`Error in ${plugin.name}.renderCrxManifest`);
|
|
3336
|
-
}
|
|
3337
|
-
}
|
|
3338
|
-
const assetTypes = [
|
|
3339
|
-
"icons",
|
|
3340
|
-
"locales",
|
|
3341
|
-
"rulesets",
|
|
3342
|
-
"webAccessibleResources"
|
|
3343
|
-
];
|
|
3344
|
-
const files = await manifestFiles(manifest2, { cwd: config.root });
|
|
3345
|
-
await Promise.all(assetTypes.map((k) => files[k]).flat().map(async (f) => {
|
|
3346
|
-
if (typeof bundle[f] === "undefined") {
|
|
3347
|
-
let filename = join(config.root, f);
|
|
3348
|
-
if (!fs.existsSync(filename))
|
|
3349
|
-
filename = join(config.publicDir, f);
|
|
3350
|
-
if (!fs.existsSync(filename))
|
|
3351
|
-
throw new Error(`ENOENT: Could not load manifest asset "${f}".
|
|
3352
|
-
Manifest assets must exist in one of these directories:
|
|
3353
|
-
Project root: "${config.root}"
|
|
3354
|
-
Public dir: "${config.publicDir}"`);
|
|
3355
|
-
this.emitFile({
|
|
3356
|
-
type: "asset",
|
|
3357
|
-
fileName: f,
|
|
3358
|
-
source: await readFile(filename)
|
|
3359
|
-
});
|
|
3360
|
-
}
|
|
3361
|
-
}));
|
|
3362
|
-
if (config.command === "serve" && files.html.length) {
|
|
3363
|
-
const refId2 = this.emitFile({
|
|
3364
|
-
type: "asset",
|
|
3365
|
-
name: "precontroller.js",
|
|
3366
|
-
source: precontrollerJs
|
|
3367
|
-
});
|
|
3368
|
-
const precontrollerJsName = this.getFileName(refId2);
|
|
3369
|
-
files.html.map((f) => this.emitFile({
|
|
3370
|
-
type: "asset",
|
|
3371
|
-
fileName: f,
|
|
3372
|
-
source: precontrollerHtml.replace("%SCRIPT%", `/${precontrollerJsName}`)
|
|
3373
|
-
}));
|
|
3374
|
-
}
|
|
3375
|
-
const manifestJson = bundle["manifest.json"];
|
|
3376
|
-
if (typeof manifestJson === "undefined") {
|
|
3377
|
-
this.emitFile({
|
|
3378
|
-
type: "asset",
|
|
3379
|
-
fileName: "manifest.json",
|
|
3380
|
-
source: JSON.stringify(manifest2, null, 2)
|
|
3381
|
-
});
|
|
3382
|
-
} else {
|
|
3383
|
-
manifestJson.source = JSON.stringify(manifest2, null, 2);
|
|
3384
|
-
}
|
|
3385
|
-
delete bundle[manifestName];
|
|
3386
|
-
}
|
|
3387
|
-
}
|
|
3388
|
-
];
|
|
3389
|
-
};
|
|
3390
|
-
|
|
3391
|
-
function compileFileResources(fileName, {
|
|
3392
|
-
chunks,
|
|
3393
|
-
files,
|
|
3394
|
-
config
|
|
3395
|
-
}, resources = {
|
|
3396
|
-
assets: /* @__PURE__ */ new Set(),
|
|
3397
|
-
css: /* @__PURE__ */ new Set(),
|
|
3398
|
-
imports: /* @__PURE__ */ new Set()
|
|
3399
|
-
}) {
|
|
3400
|
-
const chunk = chunks.get(fileName);
|
|
3401
|
-
if (chunk) {
|
|
3402
|
-
const { modules, facadeModuleId, imports, dynamicImports } = chunk;
|
|
3403
|
-
for (const x of imports)
|
|
3404
|
-
resources.imports.add(x);
|
|
3405
|
-
for (const x of dynamicImports)
|
|
3406
|
-
resources.imports.add(x);
|
|
3407
|
-
for (const x of [...imports, ...dynamicImports])
|
|
3408
|
-
compileFileResources(x, { chunks, files, config }, resources);
|
|
3409
|
-
for (const m of Object.keys(modules))
|
|
3410
|
-
if (m !== facadeModuleId) {
|
|
3411
|
-
const key = prefix$1("/", relative(config.root, m.split("?")[0]));
|
|
3412
|
-
const script = contentScripts.get(key);
|
|
3413
|
-
if (script)
|
|
3414
|
-
if (typeof script.fileName === "undefined") {
|
|
3415
|
-
throw new Error(`Content script fileName for ${m} is undefined`);
|
|
3416
|
-
} else {
|
|
3417
|
-
resources.imports.add(script.fileName);
|
|
3418
|
-
compileFileResources(script.fileName, { chunks, files, config }, resources);
|
|
3419
|
-
}
|
|
3420
|
-
}
|
|
3421
|
-
}
|
|
3422
|
-
const file = files.get(fileName);
|
|
3423
|
-
if (file) {
|
|
3424
|
-
const { assets = [], css = [] } = file;
|
|
3425
|
-
for (const x of assets)
|
|
3426
|
-
resources.assets.add(x);
|
|
3427
|
-
for (const x of css)
|
|
3428
|
-
resources.css.add(x);
|
|
3429
|
-
}
|
|
3430
|
-
return resources;
|
|
3431
|
-
}
|
|
3432
|
-
|
|
3433
5
|
const defineManifest = (manifest) => manifest;
|
|
3434
6
|
const defineDynamicResource = ({
|
|
3435
7
|
matches = ["http://*/*", "https://*/*"],
|
|
@@ -3441,164 +13,5 @@ const defineDynamicResource = ({
|
|
|
3441
13
|
});
|
|
3442
14
|
const DYNAMIC_RESOURCE = "<dynamic_resource>";
|
|
3443
15
|
|
|
3444
|
-
_debug("web-acc-res");
|
|
3445
|
-
const pluginWebAccessibleResources = () => {
|
|
3446
|
-
let config;
|
|
3447
|
-
let injectCss;
|
|
3448
|
-
return [
|
|
3449
|
-
{
|
|
3450
|
-
name: "crx:web-accessible-resources",
|
|
3451
|
-
apply: "serve",
|
|
3452
|
-
enforce: "post",
|
|
3453
|
-
renderCrxManifest(manifest) {
|
|
3454
|
-
manifest.web_accessible_resources = manifest.web_accessible_resources ?? [];
|
|
3455
|
-
manifest.web_accessible_resources = manifest.web_accessible_resources.map(({ resources, ...rest }) => ({
|
|
3456
|
-
resources: resources.filter((r) => r !== DYNAMIC_RESOURCE),
|
|
3457
|
-
...rest
|
|
3458
|
-
})).filter(({ resources }) => resources.length);
|
|
3459
|
-
manifest.web_accessible_resources.push({
|
|
3460
|
-
use_dynamic_url: true,
|
|
3461
|
-
matches: ["<all_urls>"],
|
|
3462
|
-
resources: ["**/*", "*"]
|
|
3463
|
-
});
|
|
3464
|
-
return manifest;
|
|
3465
|
-
}
|
|
3466
|
-
},
|
|
3467
|
-
{
|
|
3468
|
-
name: "crx:web-accessible-resources",
|
|
3469
|
-
apply: "build",
|
|
3470
|
-
enforce: "post",
|
|
3471
|
-
async config({ build, ...config2 }, { command }) {
|
|
3472
|
-
const { contentScripts: contentScripts2 = {} } = await getOptions(config2);
|
|
3473
|
-
injectCss = contentScripts2.injectCss ?? true;
|
|
3474
|
-
return { ...config2, build: { ...build, manifest: command === "build" } };
|
|
3475
|
-
},
|
|
3476
|
-
configResolved(_config) {
|
|
3477
|
-
config = _config;
|
|
3478
|
-
},
|
|
3479
|
-
async renderCrxManifest(manifest, bundle) {
|
|
3480
|
-
const { web_accessible_resources: _war = [] } = manifest;
|
|
3481
|
-
const dynamicScriptMatches = /* @__PURE__ */ new Set();
|
|
3482
|
-
let dynamicScriptDynamicUrl = false;
|
|
3483
|
-
const web_accessible_resources = [];
|
|
3484
|
-
for (const r of _war) {
|
|
3485
|
-
const i = r.resources.indexOf(DYNAMIC_RESOURCE);
|
|
3486
|
-
if (i > -1 && isResourceByMatch(r)) {
|
|
3487
|
-
r.resources = [...r.resources];
|
|
3488
|
-
r.resources.splice(i, 1);
|
|
3489
|
-
for (const p of r.matches)
|
|
3490
|
-
dynamicScriptMatches.add(p);
|
|
3491
|
-
dynamicScriptDynamicUrl = r.use_dynamic_url ?? false;
|
|
3492
|
-
}
|
|
3493
|
-
if (r.resources.length > 0)
|
|
3494
|
-
web_accessible_resources.push(r);
|
|
3495
|
-
}
|
|
3496
|
-
if (dynamicScriptMatches.size === 0) {
|
|
3497
|
-
dynamicScriptMatches.add("http://*/*");
|
|
3498
|
-
dynamicScriptMatches.add("https://*/*");
|
|
3499
|
-
}
|
|
3500
|
-
if (contentScripts.size > 0) {
|
|
3501
|
-
const viteManifest = parseJsonAsset(bundle, "manifest.json");
|
|
3502
|
-
const viteFiles = /* @__PURE__ */ new Map();
|
|
3503
|
-
for (const [, file] of Object.entries(viteManifest))
|
|
3504
|
-
viteFiles.set(file.file, file);
|
|
3505
|
-
if (viteFiles.size === 0)
|
|
3506
|
-
return null;
|
|
3507
|
-
const bundleChunks = /* @__PURE__ */ new Map();
|
|
3508
|
-
for (const chunk of Object.values(bundle))
|
|
3509
|
-
if (chunk.type === "chunk")
|
|
3510
|
-
bundleChunks.set(chunk.fileName, chunk);
|
|
3511
|
-
const moduleScriptResources = /* @__PURE__ */ new Map();
|
|
3512
|
-
for (const [
|
|
3513
|
-
key,
|
|
3514
|
-
{ id, fileName, matches, type, isDynamicScript = false }
|
|
3515
|
-
] of contentScripts)
|
|
3516
|
-
if (key === id) {
|
|
3517
|
-
if (isDynamicScript || matches.length)
|
|
3518
|
-
if (typeof fileName === "undefined") {
|
|
3519
|
-
throw new Error(`Content script filename is undefined for "${id}"`);
|
|
3520
|
-
} else {
|
|
3521
|
-
const { assets, css, imports } = compileFileResources(fileName, { chunks: bundleChunks, files: viteFiles, config });
|
|
3522
|
-
contentScripts.get(key).css = [...css];
|
|
3523
|
-
if (type === "loader")
|
|
3524
|
-
imports.add(fileName);
|
|
3525
|
-
const resource = {
|
|
3526
|
-
matches: isDynamicScript ? [...dynamicScriptMatches] : matches,
|
|
3527
|
-
resources: [...assets, ...imports],
|
|
3528
|
-
use_dynamic_url: isDynamicScript ? dynamicScriptDynamicUrl : true
|
|
3529
|
-
};
|
|
3530
|
-
if (isDynamicScript || !injectCss) {
|
|
3531
|
-
resource.resources.push(...css);
|
|
3532
|
-
}
|
|
3533
|
-
if (resource.resources.length)
|
|
3534
|
-
if (type === "module") {
|
|
3535
|
-
moduleScriptResources.set(fileName, resource);
|
|
3536
|
-
} else {
|
|
3537
|
-
resource.matches = resource.matches.map(getMatchPatternOrigin);
|
|
3538
|
-
web_accessible_resources.push(resource);
|
|
3539
|
-
}
|
|
3540
|
-
}
|
|
3541
|
-
}
|
|
3542
|
-
for (const r of web_accessible_resources)
|
|
3543
|
-
if (isResourceByMatch(r))
|
|
3544
|
-
for (const res of r.resources)
|
|
3545
|
-
moduleScriptResources.delete(res);
|
|
3546
|
-
web_accessible_resources.push(...moduleScriptResources.values());
|
|
3547
|
-
}
|
|
3548
|
-
const hashedResources = /* @__PURE__ */ new Map();
|
|
3549
|
-
const combinedResources = [];
|
|
3550
|
-
for (const r of web_accessible_resources)
|
|
3551
|
-
if (isResourceByMatch(r)) {
|
|
3552
|
-
const { matches, resources, use_dynamic_url = false } = r;
|
|
3553
|
-
const key = JSON.stringify([use_dynamic_url, matches.sort()]);
|
|
3554
|
-
const combined = hashedResources.get(key) ?? /* @__PURE__ */ new Set();
|
|
3555
|
-
for (const res of resources)
|
|
3556
|
-
combined.add(res);
|
|
3557
|
-
hashedResources.set(key, combined);
|
|
3558
|
-
} else {
|
|
3559
|
-
combinedResources.push(r);
|
|
3560
|
-
}
|
|
3561
|
-
for (const [key, resources] of hashedResources)
|
|
3562
|
-
if (resources.size > 0) {
|
|
3563
|
-
const [use_dynamic_url, matches] = JSON.parse(key);
|
|
3564
|
-
combinedResources.push({
|
|
3565
|
-
matches,
|
|
3566
|
-
resources: [...resources],
|
|
3567
|
-
use_dynamic_url
|
|
3568
|
-
});
|
|
3569
|
-
}
|
|
3570
|
-
if (combinedResources.length === 0)
|
|
3571
|
-
delete manifest.web_accessible_resources;
|
|
3572
|
-
else
|
|
3573
|
-
manifest.web_accessible_resources = combinedResources;
|
|
3574
|
-
return manifest;
|
|
3575
|
-
}
|
|
3576
|
-
}
|
|
3577
|
-
];
|
|
3578
|
-
};
|
|
3579
|
-
|
|
3580
|
-
const crx = (options) => {
|
|
3581
|
-
return [
|
|
3582
|
-
pluginOptionsProvider(options),
|
|
3583
|
-
pluginBackground(),
|
|
3584
|
-
pluginContentScripts(),
|
|
3585
|
-
pluginDeclaredContentScripts(),
|
|
3586
|
-
pluginDynamicContentScripts(),
|
|
3587
|
-
pluginFileWriter(),
|
|
3588
|
-
pluginFileWriterPublic(),
|
|
3589
|
-
pluginFileWriterPolyfill(),
|
|
3590
|
-
pluginHtmlInlineScripts(),
|
|
3591
|
-
pluginWebAccessibleResources(),
|
|
3592
|
-
pluginContentScriptsCss(),
|
|
3593
|
-
pluginHMR(),
|
|
3594
|
-
pluginManifest()
|
|
3595
|
-
].flat();
|
|
3596
|
-
};
|
|
3597
|
-
const chromeExtension = crx;
|
|
3598
|
-
|
|
3599
|
-
exports.allFilesReady = allFilesReady;
|
|
3600
|
-
exports.chromeExtension = chromeExtension;
|
|
3601
|
-
exports.crx = crx;
|
|
3602
16
|
exports.defineDynamicResource = defineDynamicResource;
|
|
3603
17
|
exports.defineManifest = defineManifest;
|
|
3604
|
-
exports.filesReady = fileReady;
|