@shijiu/jsview 1.9.921 → 1.9.943-next-vue.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2729 @@
1
+ import fs from 'node:fs';
2
+ import { isCSSRequest, normalizePath as normalizePath$1, transformWithEsbuild, formatPostcssSourceMap, createFilter } from 'vite';
3
+ import { createRequire } from 'node:module';
4
+ import path from 'node:path';
5
+ import { createHash } from 'node:crypto';
6
+ import require$$0 from 'tty';
7
+ import require$$1 from 'util';
8
+
9
+ function resolveCompiler(root) {
10
+ const compiler = tryRequire("vue/compiler-sfc", root) || tryRequire("vue/compiler-sfc");
11
+ if (!compiler) {
12
+ throw new Error(
13
+ `Failed to resolve vue/compiler-sfc.
14
+ @vitejs/plugin-vue requires vue (>=3.2.25) to be present in the dependency tree.`
15
+ );
16
+ }
17
+ return compiler;
18
+ }
19
+ const _require = createRequire(import.meta.url);
20
+ function tryRequire(id, from) {
21
+ try {
22
+ return from ? _require(_require.resolve(id, { paths: [from] })) : _require(id);
23
+ } catch (e) {
24
+ }
25
+ }
26
+
27
+ function parseVueRequest(id) {
28
+ const [filename, rawQuery] = id.split(`?`, 2);
29
+ const query = Object.fromEntries(new URLSearchParams(rawQuery));
30
+ if (query.vue != null) {
31
+ query.vue = true;
32
+ }
33
+ if (query.index != null) {
34
+ query.index = Number(query.index);
35
+ }
36
+ if (query.raw != null) {
37
+ query.raw = true;
38
+ }
39
+ if (query.url != null) {
40
+ query.url = true;
41
+ }
42
+ if (query.scoped != null) {
43
+ query.scoped = true;
44
+ }
45
+ return {
46
+ filename,
47
+ query
48
+ };
49
+ }
50
+
51
+ function slash(path) {
52
+ const isExtendedLengthPath = /^\\\\\?\\/.test(path);
53
+
54
+ if (isExtendedLengthPath) {
55
+ return path;
56
+ }
57
+
58
+ return path.replace(/\\/g, '/');
59
+ }
60
+
61
+ const cache = /* @__PURE__ */ new Map();
62
+ const prevCache = /* @__PURE__ */ new Map();
63
+ function createDescriptor(filename, source, { root, isProduction, sourceMap, compiler }) {
64
+ const { descriptor, errors } = compiler.parse(source, {
65
+ filename,
66
+ sourceMap
67
+ });
68
+ const normalizedPath = slash(path.normalize(path.relative(root, filename)));
69
+ descriptor.id = getHash(normalizedPath + (isProduction ? source : ""));
70
+ cache.set(filename, descriptor);
71
+ return { descriptor, errors };
72
+ }
73
+ function getPrevDescriptor(filename) {
74
+ return prevCache.get(filename);
75
+ }
76
+ function setPrevDescriptor(filename, entry) {
77
+ prevCache.set(filename, entry);
78
+ }
79
+ function getDescriptor(filename, options, createIfNotFound = true) {
80
+ if (cache.has(filename)) {
81
+ return cache.get(filename);
82
+ }
83
+ if (createIfNotFound) {
84
+ const { descriptor, errors } = createDescriptor(
85
+ filename,
86
+ fs.readFileSync(filename, "utf-8"),
87
+ options
88
+ );
89
+ if (errors.length) {
90
+ throw errors[0];
91
+ }
92
+ return descriptor;
93
+ }
94
+ }
95
+ function getSrcDescriptor(filename, query) {
96
+ if (query.scoped) {
97
+ return cache.get(`${filename}?src=${query.src}`);
98
+ }
99
+ return cache.get(filename);
100
+ }
101
+ function setSrcDescriptor(filename, entry, scoped) {
102
+ if (scoped) {
103
+ cache.set(`${filename}?src=${entry.id}`, entry);
104
+ return;
105
+ }
106
+ cache.set(filename, entry);
107
+ }
108
+ function getHash(text) {
109
+ return createHash("sha256").update(text).digest("hex").substring(0, 8);
110
+ }
111
+
112
+ function createRollupError(id, error) {
113
+ const { message, name, stack } = error;
114
+ const rollupError = {
115
+ id,
116
+ plugin: "vue",
117
+ message,
118
+ name,
119
+ stack
120
+ };
121
+ if ("code" in error && error.loc) {
122
+ rollupError.loc = {
123
+ file: id,
124
+ line: error.loc.start.line,
125
+ column: error.loc.start.column
126
+ };
127
+ }
128
+ return rollupError;
129
+ }
130
+
131
+ async function transformTemplateAsModule(code, descriptor, options, pluginContext, ssr) {
132
+ const result = compile(code, descriptor, options, pluginContext, ssr);
133
+ let returnCode = result.code;
134
+ if (options.devServer && options.devServer.config.server.hmr !== false && !ssr && !options.isProduction) {
135
+ returnCode += `
136
+ import.meta.hot.accept(({ render }) => {
137
+ __VUE_HMR_RUNTIME__.rerender(${JSON.stringify(descriptor.id)}, render)
138
+ })`;
139
+ }
140
+ return {
141
+ code: returnCode,
142
+ map: result.map
143
+ };
144
+ }
145
+ function transformTemplateInMain(code, descriptor, options, pluginContext, ssr) {
146
+ const result = compile(code, descriptor, options, pluginContext, ssr);
147
+ return {
148
+ ...result,
149
+ code: result.code.replace(
150
+ /\nexport (function|const) (render|ssrRender)/,
151
+ "\n$1 _sfc_$2"
152
+ )
153
+ };
154
+ }
155
+ function compile(code, descriptor, options, pluginContext, ssr) {
156
+ const filename = descriptor.filename;
157
+ const result = options.compiler.compileTemplate({
158
+ ...resolveTemplateCompilerOptions(descriptor, options, ssr),
159
+ source: code
160
+ });
161
+ if (result.errors.length) {
162
+ result.errors.forEach(
163
+ (error) => pluginContext.error(
164
+ typeof error === "string" ? { id: filename, message: error } : createRollupError(filename, error)
165
+ )
166
+ );
167
+ }
168
+ if (result.tips.length) {
169
+ result.tips.forEach(
170
+ (tip) => pluginContext.warn({
171
+ id: filename,
172
+ message: tip
173
+ })
174
+ );
175
+ }
176
+ return result;
177
+ }
178
+ function resolveTemplateCompilerOptions(descriptor, options, ssr) {
179
+ const block = descriptor.template;
180
+ if (!block) {
181
+ return;
182
+ }
183
+ const resolvedScript = getResolvedScript(descriptor, ssr);
184
+ const hasScoped = descriptor.styles.some((s) => s.scoped);
185
+ const { id, filename, cssVars } = descriptor;
186
+ let transformAssetUrls = options.template?.transformAssetUrls;
187
+ let assetUrlOptions;
188
+ if (options.devServer) {
189
+ if (filename.startsWith(options.root)) {
190
+ const devBase = options.devServer.config.base;
191
+ assetUrlOptions = {
192
+ base: (options.devServer.config.server?.origin ?? "") + devBase + slash(path.relative(options.root, path.dirname(filename)))
193
+ };
194
+ }
195
+ } else if (transformAssetUrls !== false) {
196
+ assetUrlOptions = {
197
+ includeAbsolute: true
198
+ };
199
+ }
200
+ if (transformAssetUrls && typeof transformAssetUrls === "object") {
201
+ if (Object.values(transformAssetUrls).some((val) => Array.isArray(val))) {
202
+ transformAssetUrls = {
203
+ ...assetUrlOptions,
204
+ tags: transformAssetUrls
205
+ };
206
+ } else {
207
+ transformAssetUrls = { ...assetUrlOptions, ...transformAssetUrls };
208
+ }
209
+ } else {
210
+ transformAssetUrls = assetUrlOptions;
211
+ }
212
+ let preprocessOptions = block.lang && options.template?.preprocessOptions;
213
+ if (block.lang === "pug") {
214
+ preprocessOptions = {
215
+ doctype: "html",
216
+ ...preprocessOptions
217
+ };
218
+ }
219
+ const expressionPlugins = options.template?.compilerOptions?.expressionPlugins || [];
220
+ const lang = descriptor.scriptSetup?.lang || descriptor.script?.lang;
221
+ if (lang && /tsx?$/.test(lang) && !expressionPlugins.includes("typescript")) {
222
+ expressionPlugins.push("typescript");
223
+ }
224
+ return {
225
+ ...options.template,
226
+ id,
227
+ filename,
228
+ scoped: hasScoped,
229
+ slotted: descriptor.slotted,
230
+ isProd: options.isProduction,
231
+ inMap: block.src ? void 0 : block.map,
232
+ ssr,
233
+ ssrCssVars: cssVars,
234
+ transformAssetUrls,
235
+ preprocessLang: block.lang,
236
+ preprocessOptions,
237
+ compilerOptions: {
238
+ ...options.template?.compilerOptions,
239
+ scopeId: hasScoped ? `data-v-${id}` : void 0,
240
+ bindingMetadata: resolvedScript ? resolvedScript.bindings : void 0,
241
+ expressionPlugins,
242
+ sourceMap: options.sourceMap
243
+ }
244
+ };
245
+ }
246
+
247
+ const clientCache = /* @__PURE__ */ new WeakMap();
248
+ const ssrCache = /* @__PURE__ */ new WeakMap();
249
+ function getResolvedScript(descriptor, ssr) {
250
+ return (ssr ? ssrCache : clientCache).get(descriptor);
251
+ }
252
+ function setResolvedScript(descriptor, script, ssr) {
253
+ (ssr ? ssrCache : clientCache).set(descriptor, script);
254
+ }
255
+ function isUseInlineTemplate(descriptor, isProd) {
256
+ return isProd && !!descriptor.scriptSetup && !descriptor.template?.src;
257
+ }
258
+ function resolveScript(descriptor, options, ssr) {
259
+ if (!descriptor.script && !descriptor.scriptSetup) {
260
+ return null;
261
+ }
262
+ const cacheToUse = ssr ? ssrCache : clientCache;
263
+ const cached = cacheToUse.get(descriptor);
264
+ if (cached) {
265
+ return cached;
266
+ }
267
+ let resolved = null;
268
+ resolved = options.compiler.compileScript(descriptor, {
269
+ ...options.script,
270
+ id: descriptor.id,
271
+ isProd: options.isProduction,
272
+ inlineTemplate: isUseInlineTemplate(descriptor, !options.devServer),
273
+ reactivityTransform: options.reactivityTransform !== false,
274
+ templateOptions: resolveTemplateCompilerOptions(descriptor, options, ssr),
275
+ sourceMap: options.sourceMap
276
+ });
277
+ cacheToUse.set(descriptor, resolved);
278
+ return resolved;
279
+ }
280
+
281
+ const comma = ','.charCodeAt(0);
282
+ const semicolon = ';'.charCodeAt(0);
283
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
284
+ const intToChar = new Uint8Array(64); // 64 possible chars.
285
+ const charToInt = new Uint8Array(128); // z is 122 in ASCII
286
+ for (let i = 0; i < chars.length; i++) {
287
+ const c = chars.charCodeAt(i);
288
+ intToChar[i] = c;
289
+ charToInt[c] = i;
290
+ }
291
+ // Provide a fallback for older environments.
292
+ const td = typeof TextDecoder !== 'undefined'
293
+ ? /* #__PURE__ */ new TextDecoder()
294
+ : typeof Buffer !== 'undefined'
295
+ ? {
296
+ decode(buf) {
297
+ const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
298
+ return out.toString();
299
+ },
300
+ }
301
+ : {
302
+ decode(buf) {
303
+ let out = '';
304
+ for (let i = 0; i < buf.length; i++) {
305
+ out += String.fromCharCode(buf[i]);
306
+ }
307
+ return out;
308
+ },
309
+ };
310
+ function decode(mappings) {
311
+ const state = new Int32Array(5);
312
+ const decoded = [];
313
+ let index = 0;
314
+ do {
315
+ const semi = indexOf(mappings, index);
316
+ const line = [];
317
+ let sorted = true;
318
+ let lastCol = 0;
319
+ state[0] = 0;
320
+ for (let i = index; i < semi; i++) {
321
+ let seg;
322
+ i = decodeInteger(mappings, i, state, 0); // genColumn
323
+ const col = state[0];
324
+ if (col < lastCol)
325
+ sorted = false;
326
+ lastCol = col;
327
+ if (hasMoreVlq(mappings, i, semi)) {
328
+ i = decodeInteger(mappings, i, state, 1); // sourcesIndex
329
+ i = decodeInteger(mappings, i, state, 2); // sourceLine
330
+ i = decodeInteger(mappings, i, state, 3); // sourceColumn
331
+ if (hasMoreVlq(mappings, i, semi)) {
332
+ i = decodeInteger(mappings, i, state, 4); // namesIndex
333
+ seg = [col, state[1], state[2], state[3], state[4]];
334
+ }
335
+ else {
336
+ seg = [col, state[1], state[2], state[3]];
337
+ }
338
+ }
339
+ else {
340
+ seg = [col];
341
+ }
342
+ line.push(seg);
343
+ }
344
+ if (!sorted)
345
+ sort(line);
346
+ decoded.push(line);
347
+ index = semi + 1;
348
+ } while (index <= mappings.length);
349
+ return decoded;
350
+ }
351
+ function indexOf(mappings, index) {
352
+ const idx = mappings.indexOf(';', index);
353
+ return idx === -1 ? mappings.length : idx;
354
+ }
355
+ function decodeInteger(mappings, pos, state, j) {
356
+ let value = 0;
357
+ let shift = 0;
358
+ let integer = 0;
359
+ do {
360
+ const c = mappings.charCodeAt(pos++);
361
+ integer = charToInt[c];
362
+ value |= (integer & 31) << shift;
363
+ shift += 5;
364
+ } while (integer & 32);
365
+ const shouldNegate = value & 1;
366
+ value >>>= 1;
367
+ if (shouldNegate) {
368
+ value = -0x80000000 | -value;
369
+ }
370
+ state[j] += value;
371
+ return pos;
372
+ }
373
+ function hasMoreVlq(mappings, i, length) {
374
+ if (i >= length)
375
+ return false;
376
+ return mappings.charCodeAt(i) !== comma;
377
+ }
378
+ function sort(line) {
379
+ line.sort(sortComparator$1);
380
+ }
381
+ function sortComparator$1(a, b) {
382
+ return a[0] - b[0];
383
+ }
384
+ function encode(decoded) {
385
+ const state = new Int32Array(5);
386
+ const bufLength = 1024 * 16;
387
+ const subLength = bufLength - 36;
388
+ const buf = new Uint8Array(bufLength);
389
+ const sub = buf.subarray(0, subLength);
390
+ let pos = 0;
391
+ let out = '';
392
+ for (let i = 0; i < decoded.length; i++) {
393
+ const line = decoded[i];
394
+ if (i > 0) {
395
+ if (pos === bufLength) {
396
+ out += td.decode(buf);
397
+ pos = 0;
398
+ }
399
+ buf[pos++] = semicolon;
400
+ }
401
+ if (line.length === 0)
402
+ continue;
403
+ state[0] = 0;
404
+ for (let j = 0; j < line.length; j++) {
405
+ const segment = line[j];
406
+ // We can push up to 5 ints, each int can take at most 7 chars, and we
407
+ // may push a comma.
408
+ if (pos > subLength) {
409
+ out += td.decode(sub);
410
+ buf.copyWithin(0, subLength, pos);
411
+ pos -= subLength;
412
+ }
413
+ if (j > 0)
414
+ buf[pos++] = comma;
415
+ pos = encodeInteger(buf, pos, state, segment, 0); // genColumn
416
+ if (segment.length === 1)
417
+ continue;
418
+ pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex
419
+ pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine
420
+ pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn
421
+ if (segment.length === 4)
422
+ continue;
423
+ pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex
424
+ }
425
+ }
426
+ return out + td.decode(buf.subarray(0, pos));
427
+ }
428
+ function encodeInteger(buf, pos, state, segment, j) {
429
+ const next = segment[j];
430
+ let num = next - state[j];
431
+ state[j] = next;
432
+ num = num < 0 ? (-num << 1) | 1 : num << 1;
433
+ do {
434
+ let clamped = num & 0b011111;
435
+ num >>>= 5;
436
+ if (num > 0)
437
+ clamped |= 0b100000;
438
+ buf[pos++] = intToChar[clamped];
439
+ } while (num > 0);
440
+ return pos;
441
+ }
442
+
443
+ // Matches the scheme of a URL, eg "http://"
444
+ const schemeRegex = /^[\w+.-]+:\/\//;
445
+ /**
446
+ * Matches the parts of a URL:
447
+ * 1. Scheme, including ":", guaranteed.
448
+ * 2. User/password, including "@", optional.
449
+ * 3. Host, guaranteed.
450
+ * 4. Port, including ":", optional.
451
+ * 5. Path, including "/", optional.
452
+ * 6. Query, including "?", optional.
453
+ * 7. Hash, including "#", optional.
454
+ */
455
+ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
456
+ /**
457
+ * File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
458
+ * with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
459
+ *
460
+ * 1. Host, optional.
461
+ * 2. Path, which may include "/", guaranteed.
462
+ * 3. Query, including "?", optional.
463
+ * 4. Hash, including "#", optional.
464
+ */
465
+ const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
466
+ var UrlType;
467
+ (function (UrlType) {
468
+ UrlType[UrlType["Empty"] = 1] = "Empty";
469
+ UrlType[UrlType["Hash"] = 2] = "Hash";
470
+ UrlType[UrlType["Query"] = 3] = "Query";
471
+ UrlType[UrlType["RelativePath"] = 4] = "RelativePath";
472
+ UrlType[UrlType["AbsolutePath"] = 5] = "AbsolutePath";
473
+ UrlType[UrlType["SchemeRelative"] = 6] = "SchemeRelative";
474
+ UrlType[UrlType["Absolute"] = 7] = "Absolute";
475
+ })(UrlType || (UrlType = {}));
476
+ function isAbsoluteUrl(input) {
477
+ return schemeRegex.test(input);
478
+ }
479
+ function isSchemeRelativeUrl(input) {
480
+ return input.startsWith('//');
481
+ }
482
+ function isAbsolutePath(input) {
483
+ return input.startsWith('/');
484
+ }
485
+ function isFileUrl(input) {
486
+ return input.startsWith('file:');
487
+ }
488
+ function isRelative(input) {
489
+ return /^[.?#]/.test(input);
490
+ }
491
+ function parseAbsoluteUrl(input) {
492
+ const match = urlRegex.exec(input);
493
+ return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/', match[6] || '', match[7] || '');
494
+ }
495
+ function parseFileUrl(input) {
496
+ const match = fileRegex.exec(input);
497
+ const path = match[2];
498
+ return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path, match[3] || '', match[4] || '');
499
+ }
500
+ function makeUrl(scheme, user, host, port, path, query, hash) {
501
+ return {
502
+ scheme,
503
+ user,
504
+ host,
505
+ port,
506
+ path,
507
+ query,
508
+ hash,
509
+ type: UrlType.Absolute,
510
+ };
511
+ }
512
+ function parseUrl(input) {
513
+ if (isSchemeRelativeUrl(input)) {
514
+ const url = parseAbsoluteUrl('http:' + input);
515
+ url.scheme = '';
516
+ url.type = UrlType.SchemeRelative;
517
+ return url;
518
+ }
519
+ if (isAbsolutePath(input)) {
520
+ const url = parseAbsoluteUrl('http://foo.com' + input);
521
+ url.scheme = '';
522
+ url.host = '';
523
+ url.type = UrlType.AbsolutePath;
524
+ return url;
525
+ }
526
+ if (isFileUrl(input))
527
+ return parseFileUrl(input);
528
+ if (isAbsoluteUrl(input))
529
+ return parseAbsoluteUrl(input);
530
+ const url = parseAbsoluteUrl('http://foo.com/' + input);
531
+ url.scheme = '';
532
+ url.host = '';
533
+ url.type = input
534
+ ? input.startsWith('?')
535
+ ? UrlType.Query
536
+ : input.startsWith('#')
537
+ ? UrlType.Hash
538
+ : UrlType.RelativePath
539
+ : UrlType.Empty;
540
+ return url;
541
+ }
542
+ function stripPathFilename(path) {
543
+ // If a path ends with a parent directory "..", then it's a relative path with excess parent
544
+ // paths. It's not a file, so we can't strip it.
545
+ if (path.endsWith('/..'))
546
+ return path;
547
+ const index = path.lastIndexOf('/');
548
+ return path.slice(0, index + 1);
549
+ }
550
+ function mergePaths(url, base) {
551
+ normalizePath(base, base.type);
552
+ // If the path is just a "/", then it was an empty path to begin with (remember, we're a relative
553
+ // path).
554
+ if (url.path === '/') {
555
+ url.path = base.path;
556
+ }
557
+ else {
558
+ // Resolution happens relative to the base path's directory, not the file.
559
+ url.path = stripPathFilename(base.path) + url.path;
560
+ }
561
+ }
562
+ /**
563
+ * The path can have empty directories "//", unneeded parents "foo/..", or current directory
564
+ * "foo/.". We need to normalize to a standard representation.
565
+ */
566
+ function normalizePath(url, type) {
567
+ const rel = type <= UrlType.RelativePath;
568
+ const pieces = url.path.split('/');
569
+ // We need to preserve the first piece always, so that we output a leading slash. The item at
570
+ // pieces[0] is an empty string.
571
+ let pointer = 1;
572
+ // Positive is the number of real directories we've output, used for popping a parent directory.
573
+ // Eg, "foo/bar/.." will have a positive 2, and we can decrement to be left with just "foo".
574
+ let positive = 0;
575
+ // We need to keep a trailing slash if we encounter an empty directory (eg, splitting "foo/" will
576
+ // generate `["foo", ""]` pieces). And, if we pop a parent directory. But once we encounter a
577
+ // real directory, we won't need to append, unless the other conditions happen again.
578
+ let addTrailingSlash = false;
579
+ for (let i = 1; i < pieces.length; i++) {
580
+ const piece = pieces[i];
581
+ // An empty directory, could be a trailing slash, or just a double "//" in the path.
582
+ if (!piece) {
583
+ addTrailingSlash = true;
584
+ continue;
585
+ }
586
+ // If we encounter a real directory, then we don't need to append anymore.
587
+ addTrailingSlash = false;
588
+ // A current directory, which we can always drop.
589
+ if (piece === '.')
590
+ continue;
591
+ // A parent directory, we need to see if there are any real directories we can pop. Else, we
592
+ // have an excess of parents, and we'll need to keep the "..".
593
+ if (piece === '..') {
594
+ if (positive) {
595
+ addTrailingSlash = true;
596
+ positive--;
597
+ pointer--;
598
+ }
599
+ else if (rel) {
600
+ // If we're in a relativePath, then we need to keep the excess parents. Else, in an absolute
601
+ // URL, protocol relative URL, or an absolute path, we don't need to keep excess.
602
+ pieces[pointer++] = piece;
603
+ }
604
+ continue;
605
+ }
606
+ // We've encountered a real directory. Move it to the next insertion pointer, which accounts for
607
+ // any popped or dropped directories.
608
+ pieces[pointer++] = piece;
609
+ positive++;
610
+ }
611
+ let path = '';
612
+ for (let i = 1; i < pointer; i++) {
613
+ path += '/' + pieces[i];
614
+ }
615
+ if (!path || (addTrailingSlash && !path.endsWith('/..'))) {
616
+ path += '/';
617
+ }
618
+ url.path = path;
619
+ }
620
+ /**
621
+ * Attempts to resolve `input` URL/path relative to `base`.
622
+ */
623
+ function resolve$1(input, base) {
624
+ if (!input && !base)
625
+ return '';
626
+ const url = parseUrl(input);
627
+ let inputType = url.type;
628
+ if (base && inputType !== UrlType.Absolute) {
629
+ const baseUrl = parseUrl(base);
630
+ const baseType = baseUrl.type;
631
+ switch (inputType) {
632
+ case UrlType.Empty:
633
+ url.hash = baseUrl.hash;
634
+ // fall through
635
+ case UrlType.Hash:
636
+ url.query = baseUrl.query;
637
+ // fall through
638
+ case UrlType.Query:
639
+ case UrlType.RelativePath:
640
+ mergePaths(url, baseUrl);
641
+ // fall through
642
+ case UrlType.AbsolutePath:
643
+ // The host, user, and port are joined, you can't copy one without the others.
644
+ url.user = baseUrl.user;
645
+ url.host = baseUrl.host;
646
+ url.port = baseUrl.port;
647
+ // fall through
648
+ case UrlType.SchemeRelative:
649
+ // The input doesn't have a schema at least, so we need to copy at least that over.
650
+ url.scheme = baseUrl.scheme;
651
+ }
652
+ if (baseType > inputType)
653
+ inputType = baseType;
654
+ }
655
+ normalizePath(url, inputType);
656
+ const queryHash = url.query + url.hash;
657
+ switch (inputType) {
658
+ // This is impossible, because of the empty checks at the start of the function.
659
+ // case UrlType.Empty:
660
+ case UrlType.Hash:
661
+ case UrlType.Query:
662
+ return queryHash;
663
+ case UrlType.RelativePath: {
664
+ // The first char is always a "/", and we need it to be relative.
665
+ const path = url.path.slice(1);
666
+ if (!path)
667
+ return queryHash || '.';
668
+ if (isRelative(base || input) && !isRelative(path)) {
669
+ // If base started with a leading ".", or there is no base and input started with a ".",
670
+ // then we need to ensure that the relative path starts with a ".". We don't know if
671
+ // relative starts with a "..", though, so check before prepending.
672
+ return './' + path + queryHash;
673
+ }
674
+ return path + queryHash;
675
+ }
676
+ case UrlType.AbsolutePath:
677
+ return url.path + queryHash;
678
+ default:
679
+ return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
680
+ }
681
+ }
682
+
683
+ function resolve(input, base) {
684
+ // The base is always treated as a directory, if it's not empty.
685
+ // https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327
686
+ // https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
687
+ if (base && !base.endsWith('/'))
688
+ base += '/';
689
+ return resolve$1(input, base);
690
+ }
691
+
692
+ /**
693
+ * Removes everything after the last "/", but leaves the slash.
694
+ */
695
+ function stripFilename(path) {
696
+ if (!path)
697
+ return '';
698
+ const index = path.lastIndexOf('/');
699
+ return path.slice(0, index + 1);
700
+ }
701
+
702
+ const COLUMN$1 = 0;
703
+
704
+ function maybeSort(mappings, owned) {
705
+ const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
706
+ if (unsortedIndex === mappings.length)
707
+ return mappings;
708
+ // If we own the array (meaning we parsed it from JSON), then we're free to directly mutate it. If
709
+ // not, we do not want to modify the consumer's input array.
710
+ if (!owned)
711
+ mappings = mappings.slice();
712
+ for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
713
+ mappings[i] = sortSegments(mappings[i], owned);
714
+ }
715
+ return mappings;
716
+ }
717
+ function nextUnsortedSegmentLine(mappings, start) {
718
+ for (let i = start; i < mappings.length; i++) {
719
+ if (!isSorted(mappings[i]))
720
+ return i;
721
+ }
722
+ return mappings.length;
723
+ }
724
+ function isSorted(line) {
725
+ for (let j = 1; j < line.length; j++) {
726
+ if (line[j][COLUMN$1] < line[j - 1][COLUMN$1]) {
727
+ return false;
728
+ }
729
+ }
730
+ return true;
731
+ }
732
+ function sortSegments(line, owned) {
733
+ if (!owned)
734
+ line = line.slice();
735
+ return line.sort(sortComparator);
736
+ }
737
+ function sortComparator(a, b) {
738
+ return a[COLUMN$1] - b[COLUMN$1];
739
+ }
740
+ function memoizedState() {
741
+ return {
742
+ lastKey: -1,
743
+ lastNeedle: -1,
744
+ lastIndex: -1,
745
+ };
746
+ }
747
+ /**
748
+ * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
749
+ */
750
+ let decodedMappings;
751
+ /**
752
+ * Iterates each mapping in generated position order.
753
+ */
754
+ let eachMapping;
755
+ class TraceMap {
756
+ constructor(map, mapUrl) {
757
+ const isString = typeof map === 'string';
758
+ if (!isString && map._decodedMemo)
759
+ return map;
760
+ const parsed = (isString ? JSON.parse(map) : map);
761
+ const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
762
+ this.version = version;
763
+ this.file = file;
764
+ this.names = names;
765
+ this.sourceRoot = sourceRoot;
766
+ this.sources = sources;
767
+ this.sourcesContent = sourcesContent;
768
+ const from = resolve(sourceRoot || '', stripFilename(mapUrl));
769
+ this.resolvedSources = sources.map((s) => resolve(s || '', from));
770
+ const { mappings } = parsed;
771
+ if (typeof mappings === 'string') {
772
+ this._encoded = mappings;
773
+ this._decoded = undefined;
774
+ }
775
+ else {
776
+ this._encoded = undefined;
777
+ this._decoded = maybeSort(mappings, isString);
778
+ }
779
+ this._decodedMemo = memoizedState();
780
+ this._bySources = undefined;
781
+ this._bySourceMemos = undefined;
782
+ }
783
+ }
784
+ (() => {
785
+ decodedMappings = (map) => {
786
+ return (map._decoded || (map._decoded = decode(map._encoded)));
787
+ };
788
+ eachMapping = (map, cb) => {
789
+ const decoded = decodedMappings(map);
790
+ const { names, resolvedSources } = map;
791
+ for (let i = 0; i < decoded.length; i++) {
792
+ const line = decoded[i];
793
+ for (let j = 0; j < line.length; j++) {
794
+ const seg = line[j];
795
+ const generatedLine = i + 1;
796
+ const generatedColumn = seg[0];
797
+ let source = null;
798
+ let originalLine = null;
799
+ let originalColumn = null;
800
+ let name = null;
801
+ if (seg.length !== 1) {
802
+ source = resolvedSources[seg[1]];
803
+ originalLine = seg[2] + 1;
804
+ originalColumn = seg[3];
805
+ }
806
+ if (seg.length === 5)
807
+ name = names[seg[4]];
808
+ cb({
809
+ generatedLine,
810
+ generatedColumn,
811
+ source,
812
+ originalLine,
813
+ originalColumn,
814
+ name,
815
+ });
816
+ }
817
+ }
818
+ };
819
+ })();
820
+
821
+ /**
822
+ * Gets the index associated with `key` in the backing array, if it is already present.
823
+ */
824
+ let get;
825
+ /**
826
+ * Puts `key` into the backing array, if it is not already present. Returns
827
+ * the index of the `key` in the backing array.
828
+ */
829
+ let put;
830
+ /**
831
+ * SetArray acts like a `Set` (allowing only one occurrence of a string `key`), but provides the
832
+ * index of the `key` in the backing array.
833
+ *
834
+ * This is designed to allow synchronizing a second array with the contents of the backing array,
835
+ * like how in a sourcemap `sourcesContent[i]` is the source content associated with `source[i]`,
836
+ * and there are never duplicates.
837
+ */
838
+ class SetArray {
839
+ constructor() {
840
+ this._indexes = { __proto__: null };
841
+ this.array = [];
842
+ }
843
+ }
844
+ (() => {
845
+ get = (strarr, key) => strarr._indexes[key];
846
+ put = (strarr, key) => {
847
+ // The key may or may not be present. If it is present, it's a number.
848
+ const index = get(strarr, key);
849
+ if (index !== undefined)
850
+ return index;
851
+ const { array, _indexes: indexes } = strarr;
852
+ return (indexes[key] = array.push(key) - 1);
853
+ };
854
+ })();
855
+
856
+ const COLUMN = 0;
857
+ const SOURCES_INDEX = 1;
858
+ const SOURCE_LINE = 2;
859
+ const SOURCE_COLUMN = 3;
860
+ const NAMES_INDEX = 4;
861
+
862
+ const NO_NAME = -1;
863
+ /**
864
+ * A high-level API to associate a generated position with an original source position. Line is
865
+ * 1-based, but column is 0-based, due to legacy behavior in `source-map` library.
866
+ */
867
+ let addMapping;
868
+ /**
869
+ * Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects
870
+ * a sourcemap, or to JSON.stringify.
871
+ */
872
+ let toDecodedMap;
873
+ /**
874
+ * Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects
875
+ * a sourcemap, or to JSON.stringify.
876
+ */
877
+ let toEncodedMap;
878
+ /**
879
+ * Constructs a new GenMapping, using the already present mappings of the input.
880
+ */
881
+ let fromMap;
882
+ // This split declaration is only so that terser can elminiate the static initialization block.
883
+ let addSegmentInternal;
884
+ /**
885
+ * Provides the state to generate a sourcemap.
886
+ */
887
+ class GenMapping {
888
+ constructor({ file, sourceRoot } = {}) {
889
+ this._names = new SetArray();
890
+ this._sources = new SetArray();
891
+ this._sourcesContent = [];
892
+ this._mappings = [];
893
+ this.file = file;
894
+ this.sourceRoot = sourceRoot;
895
+ }
896
+ }
897
+ (() => {
898
+ addMapping = (map, mapping) => {
899
+ return addMappingInternal(false, map, mapping);
900
+ };
901
+ toDecodedMap = (map) => {
902
+ const { file, sourceRoot, _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, } = map;
903
+ removeEmptyFinalLines(mappings);
904
+ return {
905
+ version: 3,
906
+ file: file || undefined,
907
+ names: names.array,
908
+ sourceRoot: sourceRoot || undefined,
909
+ sources: sources.array,
910
+ sourcesContent,
911
+ mappings,
912
+ };
913
+ };
914
+ toEncodedMap = (map) => {
915
+ const decoded = toDecodedMap(map);
916
+ return Object.assign(Object.assign({}, decoded), { mappings: encode(decoded.mappings) });
917
+ };
918
+ fromMap = (input) => {
919
+ const map = new TraceMap(input);
920
+ const gen = new GenMapping({ file: map.file, sourceRoot: map.sourceRoot });
921
+ putAll(gen._names, map.names);
922
+ putAll(gen._sources, map.sources);
923
+ gen._sourcesContent = map.sourcesContent || map.sources.map(() => null);
924
+ gen._mappings = decodedMappings(map);
925
+ return gen;
926
+ };
927
+ // Internal helpers
928
+ addSegmentInternal = (skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
929
+ const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, } = map;
930
+ const line = getLine(mappings, genLine);
931
+ const index = getColumnIndex(line, genColumn);
932
+ if (!source) {
933
+ if (skipable && skipSourceless(line, index))
934
+ return;
935
+ return insert(line, index, [genColumn]);
936
+ }
937
+ const sourcesIndex = put(sources, source);
938
+ const namesIndex = name ? put(names, name) : NO_NAME;
939
+ if (sourcesIndex === sourcesContent.length)
940
+ sourcesContent[sourcesIndex] = content !== null && content !== void 0 ? content : null;
941
+ if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
942
+ return;
943
+ }
944
+ return insert(line, index, name
945
+ ? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex]
946
+ : [genColumn, sourcesIndex, sourceLine, sourceColumn]);
947
+ };
948
+ })();
949
+ function getLine(mappings, index) {
950
+ for (let i = mappings.length; i <= index; i++) {
951
+ mappings[i] = [];
952
+ }
953
+ return mappings[index];
954
+ }
955
+ function getColumnIndex(line, genColumn) {
956
+ let index = line.length;
957
+ for (let i = index - 1; i >= 0; index = i--) {
958
+ const current = line[i];
959
+ if (genColumn >= current[COLUMN])
960
+ break;
961
+ }
962
+ return index;
963
+ }
964
+ function insert(array, index, value) {
965
+ for (let i = array.length; i > index; i--) {
966
+ array[i] = array[i - 1];
967
+ }
968
+ array[index] = value;
969
+ }
970
+ function removeEmptyFinalLines(mappings) {
971
+ const { length } = mappings;
972
+ let len = length;
973
+ for (let i = len - 1; i >= 0; len = i, i--) {
974
+ if (mappings[i].length > 0)
975
+ break;
976
+ }
977
+ if (len < length)
978
+ mappings.length = len;
979
+ }
980
+ function putAll(strarr, array) {
981
+ for (let i = 0; i < array.length; i++)
982
+ put(strarr, array[i]);
983
+ }
984
+ function skipSourceless(line, index) {
985
+ // The start of a line is already sourceless, so adding a sourceless segment to the beginning
986
+ // doesn't generate any useful information.
987
+ if (index === 0)
988
+ return true;
989
+ const prev = line[index - 1];
990
+ // If the previous segment is also sourceless, then adding another sourceless segment doesn't
991
+ // genrate any new information. Else, this segment will end the source/named segment and point to
992
+ // a sourceless position, which is useful.
993
+ return prev.length === 1;
994
+ }
995
+ function skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex) {
996
+ // A source/named segment at the start of a line gives position at that genColumn
997
+ if (index === 0)
998
+ return false;
999
+ const prev = line[index - 1];
1000
+ // If the previous segment is sourceless, then we're transitioning to a source.
1001
+ if (prev.length === 1)
1002
+ return false;
1003
+ // If the previous segment maps to the exact same source position, then this segment doesn't
1004
+ // provide any new position information.
1005
+ return (sourcesIndex === prev[SOURCES_INDEX] &&
1006
+ sourceLine === prev[SOURCE_LINE] &&
1007
+ sourceColumn === prev[SOURCE_COLUMN] &&
1008
+ namesIndex === (prev.length === 5 ? prev[NAMES_INDEX] : NO_NAME));
1009
+ }
1010
+ function addMappingInternal(skipable, map, mapping) {
1011
+ const { generated, source, original, name, content } = mapping;
1012
+ if (!source) {
1013
+ return addSegmentInternal(skipable, map, generated.line - 1, generated.column, null, null, null, null, null);
1014
+ }
1015
+ const s = source;
1016
+ return addSegmentInternal(skipable, map, generated.line - 1, generated.column, s, original.line - 1, original.column, name, content);
1017
+ }
1018
+
1019
+ function getDefaultExportFromCjs (x) {
1020
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1021
+ }
1022
+
1023
+ var src = {exports: {}};
1024
+
1025
+ var browser = {exports: {}};
1026
+
1027
+ /**
1028
+ * Helpers.
1029
+ */
1030
+
1031
+ var ms;
1032
+ var hasRequiredMs;
1033
+
1034
+ function requireMs () {
1035
+ if (hasRequiredMs) return ms;
1036
+ hasRequiredMs = 1;
1037
+ var s = 1000;
1038
+ var m = s * 60;
1039
+ var h = m * 60;
1040
+ var d = h * 24;
1041
+ var w = d * 7;
1042
+ var y = d * 365.25;
1043
+
1044
+ /**
1045
+ * Parse or format the given `val`.
1046
+ *
1047
+ * Options:
1048
+ *
1049
+ * - `long` verbose formatting [false]
1050
+ *
1051
+ * @param {String|Number} val
1052
+ * @param {Object} [options]
1053
+ * @throws {Error} throw an error if val is not a non-empty string or a number
1054
+ * @return {String|Number}
1055
+ * @api public
1056
+ */
1057
+
1058
+ ms = function(val, options) {
1059
+ options = options || {};
1060
+ var type = typeof val;
1061
+ if (type === 'string' && val.length > 0) {
1062
+ return parse(val);
1063
+ } else if (type === 'number' && isFinite(val)) {
1064
+ return options.long ? fmtLong(val) : fmtShort(val);
1065
+ }
1066
+ throw new Error(
1067
+ 'val is not a non-empty string or a valid number. val=' +
1068
+ JSON.stringify(val)
1069
+ );
1070
+ };
1071
+
1072
+ /**
1073
+ * Parse the given `str` and return milliseconds.
1074
+ *
1075
+ * @param {String} str
1076
+ * @return {Number}
1077
+ * @api private
1078
+ */
1079
+
1080
+ function parse(str) {
1081
+ str = String(str);
1082
+ if (str.length > 100) {
1083
+ return;
1084
+ }
1085
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
1086
+ str
1087
+ );
1088
+ if (!match) {
1089
+ return;
1090
+ }
1091
+ var n = parseFloat(match[1]);
1092
+ var type = (match[2] || 'ms').toLowerCase();
1093
+ switch (type) {
1094
+ case 'years':
1095
+ case 'year':
1096
+ case 'yrs':
1097
+ case 'yr':
1098
+ case 'y':
1099
+ return n * y;
1100
+ case 'weeks':
1101
+ case 'week':
1102
+ case 'w':
1103
+ return n * w;
1104
+ case 'days':
1105
+ case 'day':
1106
+ case 'd':
1107
+ return n * d;
1108
+ case 'hours':
1109
+ case 'hour':
1110
+ case 'hrs':
1111
+ case 'hr':
1112
+ case 'h':
1113
+ return n * h;
1114
+ case 'minutes':
1115
+ case 'minute':
1116
+ case 'mins':
1117
+ case 'min':
1118
+ case 'm':
1119
+ return n * m;
1120
+ case 'seconds':
1121
+ case 'second':
1122
+ case 'secs':
1123
+ case 'sec':
1124
+ case 's':
1125
+ return n * s;
1126
+ case 'milliseconds':
1127
+ case 'millisecond':
1128
+ case 'msecs':
1129
+ case 'msec':
1130
+ case 'ms':
1131
+ return n;
1132
+ default:
1133
+ return undefined;
1134
+ }
1135
+ }
1136
+
1137
+ /**
1138
+ * Short format for `ms`.
1139
+ *
1140
+ * @param {Number} ms
1141
+ * @return {String}
1142
+ * @api private
1143
+ */
1144
+
1145
+ function fmtShort(ms) {
1146
+ var msAbs = Math.abs(ms);
1147
+ if (msAbs >= d) {
1148
+ return Math.round(ms / d) + 'd';
1149
+ }
1150
+ if (msAbs >= h) {
1151
+ return Math.round(ms / h) + 'h';
1152
+ }
1153
+ if (msAbs >= m) {
1154
+ return Math.round(ms / m) + 'm';
1155
+ }
1156
+ if (msAbs >= s) {
1157
+ return Math.round(ms / s) + 's';
1158
+ }
1159
+ return ms + 'ms';
1160
+ }
1161
+
1162
+ /**
1163
+ * Long format for `ms`.
1164
+ *
1165
+ * @param {Number} ms
1166
+ * @return {String}
1167
+ * @api private
1168
+ */
1169
+
1170
+ function fmtLong(ms) {
1171
+ var msAbs = Math.abs(ms);
1172
+ if (msAbs >= d) {
1173
+ return plural(ms, msAbs, d, 'day');
1174
+ }
1175
+ if (msAbs >= h) {
1176
+ return plural(ms, msAbs, h, 'hour');
1177
+ }
1178
+ if (msAbs >= m) {
1179
+ return plural(ms, msAbs, m, 'minute');
1180
+ }
1181
+ if (msAbs >= s) {
1182
+ return plural(ms, msAbs, s, 'second');
1183
+ }
1184
+ return ms + ' ms';
1185
+ }
1186
+
1187
+ /**
1188
+ * Pluralization helper.
1189
+ */
1190
+
1191
+ function plural(ms, msAbs, n, name) {
1192
+ var isPlural = msAbs >= n * 1.5;
1193
+ return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
1194
+ }
1195
+ return ms;
1196
+ }
1197
+
1198
+ var common;
1199
+ var hasRequiredCommon;
1200
+
1201
+ function requireCommon () {
1202
+ if (hasRequiredCommon) return common;
1203
+ hasRequiredCommon = 1;
1204
+ /**
1205
+ * This is the common logic for both the Node.js and web browser
1206
+ * implementations of `debug()`.
1207
+ */
1208
+
1209
+ function setup(env) {
1210
+ createDebug.debug = createDebug;
1211
+ createDebug.default = createDebug;
1212
+ createDebug.coerce = coerce;
1213
+ createDebug.disable = disable;
1214
+ createDebug.enable = enable;
1215
+ createDebug.enabled = enabled;
1216
+ createDebug.humanize = requireMs();
1217
+ createDebug.destroy = destroy;
1218
+
1219
+ Object.keys(env).forEach(key => {
1220
+ createDebug[key] = env[key];
1221
+ });
1222
+
1223
+ /**
1224
+ * The currently active debug mode names, and names to skip.
1225
+ */
1226
+
1227
+ createDebug.names = [];
1228
+ createDebug.skips = [];
1229
+
1230
+ /**
1231
+ * Map of special "%n" handling functions, for the debug "format" argument.
1232
+ *
1233
+ * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
1234
+ */
1235
+ createDebug.formatters = {};
1236
+
1237
+ /**
1238
+ * Selects a color for a debug namespace
1239
+ * @param {String} namespace The namespace string for the debug instance to be colored
1240
+ * @return {Number|String} An ANSI color code for the given namespace
1241
+ * @api private
1242
+ */
1243
+ function selectColor(namespace) {
1244
+ let hash = 0;
1245
+
1246
+ for (let i = 0; i < namespace.length; i++) {
1247
+ hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
1248
+ hash |= 0; // Convert to 32bit integer
1249
+ }
1250
+
1251
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
1252
+ }
1253
+ createDebug.selectColor = selectColor;
1254
+
1255
+ /**
1256
+ * Create a debugger with the given `namespace`.
1257
+ *
1258
+ * @param {String} namespace
1259
+ * @return {Function}
1260
+ * @api public
1261
+ */
1262
+ function createDebug(namespace) {
1263
+ let prevTime;
1264
+ let enableOverride = null;
1265
+ let namespacesCache;
1266
+ let enabledCache;
1267
+
1268
+ function debug(...args) {
1269
+ // Disabled?
1270
+ if (!debug.enabled) {
1271
+ return;
1272
+ }
1273
+
1274
+ const self = debug;
1275
+
1276
+ // Set `diff` timestamp
1277
+ const curr = Number(new Date());
1278
+ const ms = curr - (prevTime || curr);
1279
+ self.diff = ms;
1280
+ self.prev = prevTime;
1281
+ self.curr = curr;
1282
+ prevTime = curr;
1283
+
1284
+ args[0] = createDebug.coerce(args[0]);
1285
+
1286
+ if (typeof args[0] !== 'string') {
1287
+ // Anything else let's inspect with %O
1288
+ args.unshift('%O');
1289
+ }
1290
+
1291
+ // Apply any `formatters` transformations
1292
+ let index = 0;
1293
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
1294
+ // If we encounter an escaped % then don't increase the array index
1295
+ if (match === '%%') {
1296
+ return '%';
1297
+ }
1298
+ index++;
1299
+ const formatter = createDebug.formatters[format];
1300
+ if (typeof formatter === 'function') {
1301
+ const val = args[index];
1302
+ match = formatter.call(self, val);
1303
+
1304
+ // Now we need to remove `args[index]` since it's inlined in the `format`
1305
+ args.splice(index, 1);
1306
+ index--;
1307
+ }
1308
+ return match;
1309
+ });
1310
+
1311
+ // Apply env-specific formatting (colors, etc.)
1312
+ createDebug.formatArgs.call(self, args);
1313
+
1314
+ const logFn = self.log || createDebug.log;
1315
+ logFn.apply(self, args);
1316
+ }
1317
+
1318
+ debug.namespace = namespace;
1319
+ debug.useColors = createDebug.useColors();
1320
+ debug.color = createDebug.selectColor(namespace);
1321
+ debug.extend = extend;
1322
+ debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
1323
+
1324
+ Object.defineProperty(debug, 'enabled', {
1325
+ enumerable: true,
1326
+ configurable: false,
1327
+ get: () => {
1328
+ if (enableOverride !== null) {
1329
+ return enableOverride;
1330
+ }
1331
+ if (namespacesCache !== createDebug.namespaces) {
1332
+ namespacesCache = createDebug.namespaces;
1333
+ enabledCache = createDebug.enabled(namespace);
1334
+ }
1335
+
1336
+ return enabledCache;
1337
+ },
1338
+ set: v => {
1339
+ enableOverride = v;
1340
+ }
1341
+ });
1342
+
1343
+ // Env-specific initialization logic for debug instances
1344
+ if (typeof createDebug.init === 'function') {
1345
+ createDebug.init(debug);
1346
+ }
1347
+
1348
+ return debug;
1349
+ }
1350
+
1351
+ function extend(namespace, delimiter) {
1352
+ const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
1353
+ newDebug.log = this.log;
1354
+ return newDebug;
1355
+ }
1356
+
1357
+ /**
1358
+ * Enables a debug mode by namespaces. This can include modes
1359
+ * separated by a colon and wildcards.
1360
+ *
1361
+ * @param {String} namespaces
1362
+ * @api public
1363
+ */
1364
+ function enable(namespaces) {
1365
+ createDebug.save(namespaces);
1366
+ createDebug.namespaces = namespaces;
1367
+
1368
+ createDebug.names = [];
1369
+ createDebug.skips = [];
1370
+
1371
+ let i;
1372
+ const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
1373
+ const len = split.length;
1374
+
1375
+ for (i = 0; i < len; i++) {
1376
+ if (!split[i]) {
1377
+ // ignore empty strings
1378
+ continue;
1379
+ }
1380
+
1381
+ namespaces = split[i].replace(/\*/g, '.*?');
1382
+
1383
+ if (namespaces[0] === '-') {
1384
+ createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
1385
+ } else {
1386
+ createDebug.names.push(new RegExp('^' + namespaces + '$'));
1387
+ }
1388
+ }
1389
+ }
1390
+
1391
+ /**
1392
+ * Disable debug output.
1393
+ *
1394
+ * @return {String} namespaces
1395
+ * @api public
1396
+ */
1397
+ function disable() {
1398
+ const namespaces = [
1399
+ ...createDebug.names.map(toNamespace),
1400
+ ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
1401
+ ].join(',');
1402
+ createDebug.enable('');
1403
+ return namespaces;
1404
+ }
1405
+
1406
+ /**
1407
+ * Returns true if the given mode name is enabled, false otherwise.
1408
+ *
1409
+ * @param {String} name
1410
+ * @return {Boolean}
1411
+ * @api public
1412
+ */
1413
+ function enabled(name) {
1414
+ if (name[name.length - 1] === '*') {
1415
+ return true;
1416
+ }
1417
+
1418
+ let i;
1419
+ let len;
1420
+
1421
+ for (i = 0, len = createDebug.skips.length; i < len; i++) {
1422
+ if (createDebug.skips[i].test(name)) {
1423
+ return false;
1424
+ }
1425
+ }
1426
+
1427
+ for (i = 0, len = createDebug.names.length; i < len; i++) {
1428
+ if (createDebug.names[i].test(name)) {
1429
+ return true;
1430
+ }
1431
+ }
1432
+
1433
+ return false;
1434
+ }
1435
+
1436
+ /**
1437
+ * Convert regexp to namespace
1438
+ *
1439
+ * @param {RegExp} regxep
1440
+ * @return {String} namespace
1441
+ * @api private
1442
+ */
1443
+ function toNamespace(regexp) {
1444
+ return regexp.toString()
1445
+ .substring(2, regexp.toString().length - 2)
1446
+ .replace(/\.\*\?$/, '*');
1447
+ }
1448
+
1449
+ /**
1450
+ * Coerce `val`.
1451
+ *
1452
+ * @param {Mixed} val
1453
+ * @return {Mixed}
1454
+ * @api private
1455
+ */
1456
+ function coerce(val) {
1457
+ if (val instanceof Error) {
1458
+ return val.stack || val.message;
1459
+ }
1460
+ return val;
1461
+ }
1462
+
1463
+ /**
1464
+ * XXX DO NOT USE. This is a temporary stub function.
1465
+ * XXX It WILL be removed in the next major release.
1466
+ */
1467
+ function destroy() {
1468
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
1469
+ }
1470
+
1471
+ createDebug.enable(createDebug.load());
1472
+
1473
+ return createDebug;
1474
+ }
1475
+
1476
+ common = setup;
1477
+ return common;
1478
+ }
1479
+
1480
+ /* eslint-env browser */
1481
+
1482
+ var hasRequiredBrowser;
1483
+
1484
+ function requireBrowser () {
1485
+ if (hasRequiredBrowser) return browser.exports;
1486
+ hasRequiredBrowser = 1;
1487
+ (function (module, exports) {
1488
+ /**
1489
+ * This is the web browser implementation of `debug()`.
1490
+ */
1491
+
1492
+ exports.formatArgs = formatArgs;
1493
+ exports.save = save;
1494
+ exports.load = load;
1495
+ exports.useColors = useColors;
1496
+ exports.storage = localstorage();
1497
+ exports.destroy = (() => {
1498
+ let warned = false;
1499
+
1500
+ return () => {
1501
+ if (!warned) {
1502
+ warned = true;
1503
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
1504
+ }
1505
+ };
1506
+ })();
1507
+
1508
+ /**
1509
+ * Colors.
1510
+ */
1511
+
1512
+ exports.colors = [
1513
+ '#0000CC',
1514
+ '#0000FF',
1515
+ '#0033CC',
1516
+ '#0033FF',
1517
+ '#0066CC',
1518
+ '#0066FF',
1519
+ '#0099CC',
1520
+ '#0099FF',
1521
+ '#00CC00',
1522
+ '#00CC33',
1523
+ '#00CC66',
1524
+ '#00CC99',
1525
+ '#00CCCC',
1526
+ '#00CCFF',
1527
+ '#3300CC',
1528
+ '#3300FF',
1529
+ '#3333CC',
1530
+ '#3333FF',
1531
+ '#3366CC',
1532
+ '#3366FF',
1533
+ '#3399CC',
1534
+ '#3399FF',
1535
+ '#33CC00',
1536
+ '#33CC33',
1537
+ '#33CC66',
1538
+ '#33CC99',
1539
+ '#33CCCC',
1540
+ '#33CCFF',
1541
+ '#6600CC',
1542
+ '#6600FF',
1543
+ '#6633CC',
1544
+ '#6633FF',
1545
+ '#66CC00',
1546
+ '#66CC33',
1547
+ '#9900CC',
1548
+ '#9900FF',
1549
+ '#9933CC',
1550
+ '#9933FF',
1551
+ '#99CC00',
1552
+ '#99CC33',
1553
+ '#CC0000',
1554
+ '#CC0033',
1555
+ '#CC0066',
1556
+ '#CC0099',
1557
+ '#CC00CC',
1558
+ '#CC00FF',
1559
+ '#CC3300',
1560
+ '#CC3333',
1561
+ '#CC3366',
1562
+ '#CC3399',
1563
+ '#CC33CC',
1564
+ '#CC33FF',
1565
+ '#CC6600',
1566
+ '#CC6633',
1567
+ '#CC9900',
1568
+ '#CC9933',
1569
+ '#CCCC00',
1570
+ '#CCCC33',
1571
+ '#FF0000',
1572
+ '#FF0033',
1573
+ '#FF0066',
1574
+ '#FF0099',
1575
+ '#FF00CC',
1576
+ '#FF00FF',
1577
+ '#FF3300',
1578
+ '#FF3333',
1579
+ '#FF3366',
1580
+ '#FF3399',
1581
+ '#FF33CC',
1582
+ '#FF33FF',
1583
+ '#FF6600',
1584
+ '#FF6633',
1585
+ '#FF9900',
1586
+ '#FF9933',
1587
+ '#FFCC00',
1588
+ '#FFCC33'
1589
+ ];
1590
+
1591
+ /**
1592
+ * Currently only WebKit-based Web Inspectors, Firefox >= v31,
1593
+ * and the Firebug extension (any Firefox version) are known
1594
+ * to support "%c" CSS customizations.
1595
+ *
1596
+ * TODO: add a `localStorage` variable to explicitly enable/disable colors
1597
+ */
1598
+
1599
+ // eslint-disable-next-line complexity
1600
+ function useColors() {
1601
+ // NB: In an Electron preload script, document will be defined but not fully
1602
+ // initialized. Since we know we're in Chrome, we'll just detect this case
1603
+ // explicitly
1604
+ if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
1605
+ return true;
1606
+ }
1607
+
1608
+ // Internet Explorer and Edge do not support colors.
1609
+ if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
1610
+ return false;
1611
+ }
1612
+
1613
+ // Is webkit? http://stackoverflow.com/a/16459606/376773
1614
+ // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
1615
+ return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
1616
+ // Is firebug? http://stackoverflow.com/a/398120/376773
1617
+ (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
1618
+ // Is firefox >= v31?
1619
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
1620
+ (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
1621
+ // Double check webkit in userAgent just in case we are in a worker
1622
+ (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
1623
+ }
1624
+
1625
+ /**
1626
+ * Colorize log arguments if enabled.
1627
+ *
1628
+ * @api public
1629
+ */
1630
+
1631
+ function formatArgs(args) {
1632
+ args[0] = (this.useColors ? '%c' : '') +
1633
+ this.namespace +
1634
+ (this.useColors ? ' %c' : ' ') +
1635
+ args[0] +
1636
+ (this.useColors ? '%c ' : ' ') +
1637
+ '+' + module.exports.humanize(this.diff);
1638
+
1639
+ if (!this.useColors) {
1640
+ return;
1641
+ }
1642
+
1643
+ const c = 'color: ' + this.color;
1644
+ args.splice(1, 0, c, 'color: inherit');
1645
+
1646
+ // The final "%c" is somewhat tricky, because there could be other
1647
+ // arguments passed either before or after the %c, so we need to
1648
+ // figure out the correct index to insert the CSS into
1649
+ let index = 0;
1650
+ let lastC = 0;
1651
+ args[0].replace(/%[a-zA-Z%]/g, match => {
1652
+ if (match === '%%') {
1653
+ return;
1654
+ }
1655
+ index++;
1656
+ if (match === '%c') {
1657
+ // We only are interested in the *last* %c
1658
+ // (the user may have provided their own)
1659
+ lastC = index;
1660
+ }
1661
+ });
1662
+
1663
+ args.splice(lastC, 0, c);
1664
+ }
1665
+
1666
+ /**
1667
+ * Invokes `console.debug()` when available.
1668
+ * No-op when `console.debug` is not a "function".
1669
+ * If `console.debug` is not available, falls back
1670
+ * to `console.log`.
1671
+ *
1672
+ * @api public
1673
+ */
1674
+ exports.log = console.debug || console.log || (() => {});
1675
+
1676
+ /**
1677
+ * Save `namespaces`.
1678
+ *
1679
+ * @param {String} namespaces
1680
+ * @api private
1681
+ */
1682
+ function save(namespaces) {
1683
+ try {
1684
+ if (namespaces) {
1685
+ exports.storage.setItem('debug', namespaces);
1686
+ } else {
1687
+ exports.storage.removeItem('debug');
1688
+ }
1689
+ } catch (error) {
1690
+ // Swallow
1691
+ // XXX (@Qix-) should we be logging these?
1692
+ }
1693
+ }
1694
+
1695
+ /**
1696
+ * Load `namespaces`.
1697
+ *
1698
+ * @return {String} returns the previously persisted debug modes
1699
+ * @api private
1700
+ */
1701
+ function load() {
1702
+ let r;
1703
+ try {
1704
+ r = exports.storage.getItem('debug');
1705
+ } catch (error) {
1706
+ // Swallow
1707
+ // XXX (@Qix-) should we be logging these?
1708
+ }
1709
+
1710
+ // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
1711
+ if (!r && typeof process !== 'undefined' && 'env' in process) {
1712
+ r = process.env.DEBUG;
1713
+ }
1714
+
1715
+ return r;
1716
+ }
1717
+
1718
+ /**
1719
+ * Localstorage attempts to return the localstorage.
1720
+ *
1721
+ * This is necessary because safari throws
1722
+ * when a user disables cookies/localstorage
1723
+ * and you attempt to access it.
1724
+ *
1725
+ * @return {LocalStorage}
1726
+ * @api private
1727
+ */
1728
+
1729
+ function localstorage() {
1730
+ try {
1731
+ // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
1732
+ // The Browser also has localStorage in the global context.
1733
+ return localStorage;
1734
+ } catch (error) {
1735
+ // Swallow
1736
+ // XXX (@Qix-) should we be logging these?
1737
+ }
1738
+ }
1739
+
1740
+ module.exports = requireCommon()(exports);
1741
+
1742
+ const {formatters} = module.exports;
1743
+
1744
+ /**
1745
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
1746
+ */
1747
+
1748
+ formatters.j = function (v) {
1749
+ try {
1750
+ return JSON.stringify(v);
1751
+ } catch (error) {
1752
+ return '[UnexpectedJSONParseError]: ' + error.message;
1753
+ }
1754
+ };
1755
+ } (browser, browser.exports));
1756
+ return browser.exports;
1757
+ }
1758
+
1759
+ var node = {exports: {}};
1760
+
1761
+ /**
1762
+ * Module dependencies.
1763
+ */
1764
+
1765
+ var hasRequiredNode;
1766
+
1767
+ function requireNode () {
1768
+ if (hasRequiredNode) return node.exports;
1769
+ hasRequiredNode = 1;
1770
+ (function (module, exports) {
1771
+ const tty = require$$0;
1772
+ const util = require$$1;
1773
+
1774
+ /**
1775
+ * This is the Node.js implementation of `debug()`.
1776
+ */
1777
+
1778
+ exports.init = init;
1779
+ exports.log = log;
1780
+ exports.formatArgs = formatArgs;
1781
+ exports.save = save;
1782
+ exports.load = load;
1783
+ exports.useColors = useColors;
1784
+ exports.destroy = util.deprecate(
1785
+ () => {},
1786
+ 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
1787
+ );
1788
+
1789
+ /**
1790
+ * Colors.
1791
+ */
1792
+
1793
+ exports.colors = [6, 2, 3, 4, 5, 1];
1794
+
1795
+ try {
1796
+ // Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
1797
+ // eslint-disable-next-line import/no-extraneous-dependencies
1798
+ const supportsColor = require('supports-color');
1799
+
1800
+ if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
1801
+ exports.colors = [
1802
+ 20,
1803
+ 21,
1804
+ 26,
1805
+ 27,
1806
+ 32,
1807
+ 33,
1808
+ 38,
1809
+ 39,
1810
+ 40,
1811
+ 41,
1812
+ 42,
1813
+ 43,
1814
+ 44,
1815
+ 45,
1816
+ 56,
1817
+ 57,
1818
+ 62,
1819
+ 63,
1820
+ 68,
1821
+ 69,
1822
+ 74,
1823
+ 75,
1824
+ 76,
1825
+ 77,
1826
+ 78,
1827
+ 79,
1828
+ 80,
1829
+ 81,
1830
+ 92,
1831
+ 93,
1832
+ 98,
1833
+ 99,
1834
+ 112,
1835
+ 113,
1836
+ 128,
1837
+ 129,
1838
+ 134,
1839
+ 135,
1840
+ 148,
1841
+ 149,
1842
+ 160,
1843
+ 161,
1844
+ 162,
1845
+ 163,
1846
+ 164,
1847
+ 165,
1848
+ 166,
1849
+ 167,
1850
+ 168,
1851
+ 169,
1852
+ 170,
1853
+ 171,
1854
+ 172,
1855
+ 173,
1856
+ 178,
1857
+ 179,
1858
+ 184,
1859
+ 185,
1860
+ 196,
1861
+ 197,
1862
+ 198,
1863
+ 199,
1864
+ 200,
1865
+ 201,
1866
+ 202,
1867
+ 203,
1868
+ 204,
1869
+ 205,
1870
+ 206,
1871
+ 207,
1872
+ 208,
1873
+ 209,
1874
+ 214,
1875
+ 215,
1876
+ 220,
1877
+ 221
1878
+ ];
1879
+ }
1880
+ } catch (error) {
1881
+ // Swallow - we only care if `supports-color` is available; it doesn't have to be.
1882
+ }
1883
+
1884
+ /**
1885
+ * Build up the default `inspectOpts` object from the environment variables.
1886
+ *
1887
+ * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
1888
+ */
1889
+
1890
+ exports.inspectOpts = Object.keys(process.env).filter(key => {
1891
+ return /^debug_/i.test(key);
1892
+ }).reduce((obj, key) => {
1893
+ // Camel-case
1894
+ const prop = key
1895
+ .substring(6)
1896
+ .toLowerCase()
1897
+ .replace(/_([a-z])/g, (_, k) => {
1898
+ return k.toUpperCase();
1899
+ });
1900
+
1901
+ // Coerce string value into JS value
1902
+ let val = process.env[key];
1903
+ if (/^(yes|on|true|enabled)$/i.test(val)) {
1904
+ val = true;
1905
+ } else if (/^(no|off|false|disabled)$/i.test(val)) {
1906
+ val = false;
1907
+ } else if (val === 'null') {
1908
+ val = null;
1909
+ } else {
1910
+ val = Number(val);
1911
+ }
1912
+
1913
+ obj[prop] = val;
1914
+ return obj;
1915
+ }, {});
1916
+
1917
+ /**
1918
+ * Is stdout a TTY? Colored output is enabled when `true`.
1919
+ */
1920
+
1921
+ function useColors() {
1922
+ return 'colors' in exports.inspectOpts ?
1923
+ Boolean(exports.inspectOpts.colors) :
1924
+ tty.isatty(process.stderr.fd);
1925
+ }
1926
+
1927
+ /**
1928
+ * Adds ANSI color escape codes if enabled.
1929
+ *
1930
+ * @api public
1931
+ */
1932
+
1933
+ function formatArgs(args) {
1934
+ const {namespace: name, useColors} = this;
1935
+
1936
+ if (useColors) {
1937
+ const c = this.color;
1938
+ const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
1939
+ const prefix = ` ${colorCode};1m${name} \u001B[0m`;
1940
+
1941
+ args[0] = prefix + args[0].split('\n').join('\n' + prefix);
1942
+ args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
1943
+ } else {
1944
+ args[0] = getDate() + name + ' ' + args[0];
1945
+ }
1946
+ }
1947
+
1948
+ function getDate() {
1949
+ if (exports.inspectOpts.hideDate) {
1950
+ return '';
1951
+ }
1952
+ return new Date().toISOString() + ' ';
1953
+ }
1954
+
1955
+ /**
1956
+ * Invokes `util.format()` with the specified arguments and writes to stderr.
1957
+ */
1958
+
1959
+ function log(...args) {
1960
+ return process.stderr.write(util.format(...args) + '\n');
1961
+ }
1962
+
1963
+ /**
1964
+ * Save `namespaces`.
1965
+ *
1966
+ * @param {String} namespaces
1967
+ * @api private
1968
+ */
1969
+ function save(namespaces) {
1970
+ if (namespaces) {
1971
+ process.env.DEBUG = namespaces;
1972
+ } else {
1973
+ // If you set a process.env field to null or undefined, it gets cast to the
1974
+ // string 'null' or 'undefined'. Just delete instead.
1975
+ delete process.env.DEBUG;
1976
+ }
1977
+ }
1978
+
1979
+ /**
1980
+ * Load `namespaces`.
1981
+ *
1982
+ * @return {String} returns the previously persisted debug modes
1983
+ * @api private
1984
+ */
1985
+
1986
+ function load() {
1987
+ return process.env.DEBUG;
1988
+ }
1989
+
1990
+ /**
1991
+ * Init logic for `debug` instances.
1992
+ *
1993
+ * Create a new `inspectOpts` object in case `useColors` is set
1994
+ * differently for a particular `debug` instance.
1995
+ */
1996
+
1997
+ function init(debug) {
1998
+ debug.inspectOpts = {};
1999
+
2000
+ const keys = Object.keys(exports.inspectOpts);
2001
+ for (let i = 0; i < keys.length; i++) {
2002
+ debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
2003
+ }
2004
+ }
2005
+
2006
+ module.exports = requireCommon()(exports);
2007
+
2008
+ const {formatters} = module.exports;
2009
+
2010
+ /**
2011
+ * Map %o to `util.inspect()`, all on a single line.
2012
+ */
2013
+
2014
+ formatters.o = function (v) {
2015
+ this.inspectOpts.colors = this.useColors;
2016
+ return util.inspect(v, this.inspectOpts)
2017
+ .split('\n')
2018
+ .map(str => str.trim())
2019
+ .join(' ');
2020
+ };
2021
+
2022
+ /**
2023
+ * Map %O to `util.inspect()`, allowing multiple lines if needed.
2024
+ */
2025
+
2026
+ formatters.O = function (v) {
2027
+ this.inspectOpts.colors = this.useColors;
2028
+ return util.inspect(v, this.inspectOpts);
2029
+ };
2030
+ } (node, node.exports));
2031
+ return node.exports;
2032
+ }
2033
+
2034
+ /**
2035
+ * Detect Electron renderer / nwjs process, which is node, but we should
2036
+ * treat as a browser.
2037
+ */
2038
+
2039
+ (function (module) {
2040
+ if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
2041
+ module.exports = requireBrowser();
2042
+ } else {
2043
+ module.exports = requireNode();
2044
+ }
2045
+ } (src));
2046
+
2047
+ const _debug = /*@__PURE__*/getDefaultExportFromCjs(src.exports);
2048
+
2049
+ const debug = _debug("vite:hmr");
2050
+ const directRequestRE = /(?:\?|&)direct\b/;
2051
+ async function handleHotUpdate({ file, modules, read, server }, options) {
2052
+ const prevDescriptor = getDescriptor(file, options, false);
2053
+ if (!prevDescriptor) {
2054
+ return;
2055
+ }
2056
+ setPrevDescriptor(file, prevDescriptor);
2057
+ const content = await read();
2058
+ const { descriptor } = createDescriptor(file, content, options);
2059
+ let needRerender = false;
2060
+ const affectedModules = /* @__PURE__ */ new Set();
2061
+ const mainModule = modules.filter((m) => !/type=/.test(m.url) || /type=script/.test(m.url)).sort((m1, m2) => {
2062
+ return m1.url.length - m2.url.length;
2063
+ })[0];
2064
+ const templateModule = modules.find((m) => /type=template/.test(m.url));
2065
+ const scriptChanged = hasScriptChanged(prevDescriptor, descriptor);
2066
+ if (scriptChanged) {
2067
+ let scriptModule;
2068
+ if (descriptor.scriptSetup?.lang && !descriptor.scriptSetup.src || descriptor.script?.lang && !descriptor.script.src) {
2069
+ const scriptModuleRE = new RegExp(
2070
+ `type=script.*&lang.${descriptor.scriptSetup?.lang || descriptor.script?.lang}$`
2071
+ );
2072
+ scriptModule = modules.find((m) => scriptModuleRE.test(m.url));
2073
+ }
2074
+ affectedModules.add(scriptModule || mainModule);
2075
+ }
2076
+ if (!isEqualBlock(descriptor.template, prevDescriptor.template)) {
2077
+ if (!scriptChanged) {
2078
+ setResolvedScript(
2079
+ descriptor,
2080
+ getResolvedScript(prevDescriptor, false),
2081
+ false
2082
+ );
2083
+ }
2084
+ affectedModules.add(templateModule);
2085
+ needRerender = true;
2086
+ }
2087
+ let didUpdateStyle = false;
2088
+ const prevStyles = prevDescriptor.styles || [];
2089
+ const nextStyles = descriptor.styles || [];
2090
+ if (prevDescriptor.cssVars.join("") !== descriptor.cssVars.join("")) {
2091
+ affectedModules.add(mainModule);
2092
+ }
2093
+ if (prevStyles.some((s) => s.scoped) !== nextStyles.some((s) => s.scoped)) {
2094
+ affectedModules.add(templateModule);
2095
+ affectedModules.add(mainModule);
2096
+ }
2097
+ for (let i = 0; i < nextStyles.length; i++) {
2098
+ const prev = prevStyles[i];
2099
+ const next = nextStyles[i];
2100
+ if (!prev || !isEqualBlock(prev, next)) {
2101
+ didUpdateStyle = true;
2102
+ const mod = modules.find(
2103
+ (m) => m.url.includes(`type=style&index=${i}`) && m.url.endsWith(`.${next.lang || "css"}`) && !directRequestRE.test(m.url)
2104
+ );
2105
+ if (mod) {
2106
+ affectedModules.add(mod);
2107
+ if (mod.url.includes("&inline")) {
2108
+ affectedModules.add(mainModule);
2109
+ }
2110
+ } else {
2111
+ affectedModules.add(mainModule);
2112
+ }
2113
+ }
2114
+ }
2115
+ if (prevStyles.length > nextStyles.length) {
2116
+ affectedModules.add(mainModule);
2117
+ }
2118
+ // JsView Add >>>
2119
+ // 当Style发生变化时,更新Script,同步CSS to JS
2120
+ affectedModules.add(mainModule);
2121
+ // JsView Add <<<
2122
+ const prevCustoms = prevDescriptor.customBlocks || [];
2123
+ const nextCustoms = descriptor.customBlocks || [];
2124
+ if (prevCustoms.length !== nextCustoms.length) {
2125
+ affectedModules.add(mainModule);
2126
+ } else {
2127
+ for (let i = 0; i < nextCustoms.length; i++) {
2128
+ const prev = prevCustoms[i];
2129
+ const next = nextCustoms[i];
2130
+ if (!prev || !isEqualBlock(prev, next)) {
2131
+ const mod = modules.find(
2132
+ (m) => m.url.includes(`type=${prev.type}&index=${i}`)
2133
+ );
2134
+ if (mod) {
2135
+ affectedModules.add(mod);
2136
+ } else {
2137
+ affectedModules.add(mainModule);
2138
+ }
2139
+ }
2140
+ }
2141
+ }
2142
+ const updateType = [];
2143
+ if (needRerender) {
2144
+ updateType.push(`template`);
2145
+ if (!templateModule) {
2146
+ affectedModules.add(mainModule);
2147
+ } else if (mainModule && !affectedModules.has(mainModule)) {
2148
+ const styleImporters = [...mainModule.importers].filter(
2149
+ (m) => isCSSRequest(m.url)
2150
+ );
2151
+ styleImporters.forEach((m) => affectedModules.add(m));
2152
+ }
2153
+ }
2154
+ if (didUpdateStyle) {
2155
+ updateType.push(`style`);
2156
+ }
2157
+ if (updateType.length) {
2158
+ debug(`[vue:update(${updateType.join("&")})] ${file}`);
2159
+ }
2160
+ return [...affectedModules].filter(Boolean);
2161
+ }
2162
+ function isEqualBlock(a, b) {
2163
+ if (!a && !b)
2164
+ return true;
2165
+ if (!a || !b)
2166
+ return false;
2167
+ if (a.src && b.src && a.src === b.src)
2168
+ return true;
2169
+ if (a.content !== b.content)
2170
+ return false;
2171
+ const keysA = Object.keys(a.attrs);
2172
+ const keysB = Object.keys(b.attrs);
2173
+ if (keysA.length !== keysB.length) {
2174
+ return false;
2175
+ }
2176
+ return keysA.every((key) => a.attrs[key] === b.attrs[key]);
2177
+ }
2178
+ function isOnlyTemplateChanged(prev, next) {
2179
+ return !hasScriptChanged(prev, next) && prev.styles.length === next.styles.length && prev.styles.every((s, i) => isEqualBlock(s, next.styles[i])) && prev.customBlocks.length === next.customBlocks.length && prev.customBlocks.every((s, i) => isEqualBlock(s, next.customBlocks[i]));
2180
+ }
2181
+ function hasScriptChanged(prev, next) {
2182
+ if (!isEqualBlock(prev.script, next.script)) {
2183
+ return true;
2184
+ }
2185
+ if (!isEqualBlock(prev.scriptSetup, next.scriptSetup)) {
2186
+ return true;
2187
+ }
2188
+ const prevResolvedScript = getResolvedScript(prev, false);
2189
+ const prevImports = prevResolvedScript?.imports;
2190
+ if (prevImports) {
2191
+ return !next.template || next.shouldForceReload(prevImports);
2192
+ }
2193
+ return false;
2194
+ }
2195
+
2196
+ const EXPORT_HELPER_ID = "\0plugin-vue:export-helper";
2197
+ const helperCode = `
2198
+ export default (sfc, props) => {
2199
+ const target = sfc.__vccOpts || sfc;
2200
+ for (const [key, val] of props) {
2201
+ target[key] = val;
2202
+ }
2203
+ return target;
2204
+ }
2205
+ `;
2206
+
2207
+ async function transformMain(code, filename, options, pluginContext, ssr, asCustomElement) {
2208
+ const { devServer, isProduction, devToolsEnabled } = options;
2209
+ const prevDescriptor = getPrevDescriptor(filename);
2210
+ const { descriptor, errors } = createDescriptor(filename, code, options);
2211
+ if (errors.length) {
2212
+ errors.forEach(
2213
+ (error) => pluginContext.error(createRollupError(filename, error))
2214
+ );
2215
+ return null;
2216
+ }
2217
+ const attachedProps = [];
2218
+ const hasScoped = descriptor.styles.some((s) => s.scoped);
2219
+ const { code: scriptCode, map: scriptMap } = await genScriptCode(
2220
+ descriptor,
2221
+ options,
2222
+ pluginContext,
2223
+ ssr
2224
+ );
2225
+ const hasTemplateImport = descriptor.template && !isUseInlineTemplate(descriptor, !devServer);
2226
+ let templateCode = "";
2227
+ let templateMap = void 0;
2228
+ if (hasTemplateImport) {
2229
+ ({ code: templateCode, map: templateMap } = await genTemplateCode(
2230
+ descriptor,
2231
+ options,
2232
+ pluginContext,
2233
+ ssr
2234
+ ));
2235
+ }
2236
+ if (hasTemplateImport) {
2237
+ attachedProps.push(
2238
+ ssr ? ["ssrRender", "_sfc_ssrRender"] : ["render", "_sfc_render"]
2239
+ );
2240
+ } else {
2241
+ if (prevDescriptor && !isEqualBlock(descriptor.template, prevDescriptor.template)) {
2242
+ attachedProps.push([ssr ? "ssrRender" : "render", "() => {}"]);
2243
+ }
2244
+ }
2245
+ const stylesCode = await genStyleCode(
2246
+ descriptor,
2247
+ pluginContext,
2248
+ asCustomElement,
2249
+ attachedProps
2250
+ );
2251
+ const customBlocksCode = await genCustomBlockCode(descriptor, pluginContext);
2252
+ const output = [
2253
+ scriptCode,
2254
+ templateCode,
2255
+ stylesCode,
2256
+ customBlocksCode
2257
+ ];
2258
+ if (hasScoped) {
2259
+ attachedProps.push([`__scopeId`, JSON.stringify(`data-v-${descriptor.id}`)]);
2260
+ }
2261
+ if (devToolsEnabled || devServer && !isProduction) {
2262
+ attachedProps.push([
2263
+ `__file`,
2264
+ JSON.stringify(isProduction ? path.basename(filename) : filename)
2265
+ ]);
2266
+ }
2267
+ if (devServer && devServer.config.server.hmr !== false && !ssr && !isProduction) {
2268
+ output.push(`_sfc_main.__hmrId = ${JSON.stringify(descriptor.id)}`);
2269
+ output.push(
2270
+ `typeof __VUE_HMR_RUNTIME__ !== 'undefined' && __VUE_HMR_RUNTIME__.createRecord(_sfc_main.__hmrId, _sfc_main)`
2271
+ );
2272
+ if (prevDescriptor && isOnlyTemplateChanged(prevDescriptor, descriptor)) {
2273
+ output.push(`export const _rerender_only = true`);
2274
+ }
2275
+ output.push(
2276
+ `import.meta.hot.accept(mod => {`,
2277
+ ` if (!mod) return`,
2278
+ ` const { default: updated, _rerender_only } = mod`,
2279
+ ` if (_rerender_only) {`,
2280
+ ` __VUE_HMR_RUNTIME__.rerender(updated.__hmrId, updated.render)`,
2281
+ ` } else {`,
2282
+ ` __VUE_HMR_RUNTIME__.reload(updated.__hmrId, updated)`,
2283
+ ` }`,
2284
+ `})`
2285
+ );
2286
+ }
2287
+ if (ssr) {
2288
+ const normalizedFilename = normalizePath$1(
2289
+ path.relative(options.root, filename)
2290
+ );
2291
+ output.push(
2292
+ `import { useSSRContext as __vite_useSSRContext } from 'vue'`,
2293
+ `const _sfc_setup = _sfc_main.setup`,
2294
+ `_sfc_main.setup = (props, ctx) => {`,
2295
+ ` const ssrContext = __vite_useSSRContext()`,
2296
+ ` ;(ssrContext.modules || (ssrContext.modules = new Set())).add(${JSON.stringify(
2297
+ normalizedFilename
2298
+ )})`,
2299
+ ` return _sfc_setup ? _sfc_setup(props, ctx) : undefined`,
2300
+ `}`
2301
+ );
2302
+ }
2303
+ let resolvedMap = void 0;
2304
+ if (options.sourceMap) {
2305
+ if (scriptMap && templateMap) {
2306
+ const gen = fromMap(
2307
+ scriptMap
2308
+ );
2309
+ const tracer = new TraceMap(
2310
+ templateMap
2311
+ );
2312
+ const offset = (scriptCode.match(/\r?\n/g)?.length ?? 0) + 1;
2313
+ eachMapping(tracer, (m) => {
2314
+ if (m.source == null)
2315
+ return;
2316
+ addMapping(gen, {
2317
+ source: m.source,
2318
+ original: { line: m.originalLine, column: m.originalColumn },
2319
+ generated: {
2320
+ line: m.generatedLine + offset,
2321
+ column: m.generatedColumn
2322
+ }
2323
+ });
2324
+ });
2325
+ resolvedMap = toEncodedMap(gen);
2326
+ resolvedMap.sourcesContent = templateMap.sourcesContent;
2327
+ } else {
2328
+ resolvedMap = scriptMap ?? templateMap;
2329
+ }
2330
+ }
2331
+ if (!attachedProps.length) {
2332
+ output.push(`export default _sfc_main`);
2333
+ } else {
2334
+ output.push(
2335
+ `import _export_sfc from '${EXPORT_HELPER_ID}'`,
2336
+ `export default /*#__PURE__*/_export_sfc(_sfc_main, [${attachedProps.map(([key, val]) => `['${key}',${val}]`).join(",")}])`
2337
+ );
2338
+ }
2339
+ let resolvedCode = output.join("\n");
2340
+ const lang = descriptor.scriptSetup?.lang || descriptor.script?.lang;
2341
+ if (lang && /tsx?$/.test(lang) && !descriptor.script?.src) {
2342
+ const { code: code2, map } = await transformWithEsbuild(
2343
+ resolvedCode,
2344
+ filename,
2345
+ {
2346
+ loader: "ts",
2347
+ target: "esnext",
2348
+ sourcemap: options.sourceMap
2349
+ },
2350
+ resolvedMap
2351
+ );
2352
+ resolvedCode = code2;
2353
+ resolvedMap = resolvedMap ? map : resolvedMap;
2354
+ }
2355
+ return {
2356
+ code: resolvedCode,
2357
+ map: resolvedMap || {
2358
+ mappings: ""
2359
+ },
2360
+ meta: {
2361
+ vite: {
2362
+ lang: descriptor.script?.lang || descriptor.scriptSetup?.lang || "js"
2363
+ }
2364
+ }
2365
+ };
2366
+ }
2367
+ async function genTemplateCode(descriptor, options, pluginContext, ssr) {
2368
+ const template = descriptor.template;
2369
+ const hasScoped = descriptor.styles.some((style) => style.scoped);
2370
+ if (!template.lang && !template.src) {
2371
+ return transformTemplateInMain(
2372
+ template.content,
2373
+ descriptor,
2374
+ options,
2375
+ pluginContext,
2376
+ ssr
2377
+ );
2378
+ } else {
2379
+ if (template.src) {
2380
+ await linkSrcToDescriptor(
2381
+ template.src,
2382
+ descriptor,
2383
+ pluginContext,
2384
+ hasScoped
2385
+ );
2386
+ }
2387
+ const src = template.src || descriptor.filename;
2388
+ const srcQuery = template.src ? hasScoped ? `&src=${descriptor.id}` : "&src=true" : "";
2389
+ const scopedQuery = hasScoped ? `&scoped=${descriptor.id}` : ``;
2390
+ const attrsQuery = attrsToQuery(template.attrs, "js", true);
2391
+ const query = `?vue&type=template${srcQuery}${scopedQuery}${attrsQuery}`;
2392
+ const request = JSON.stringify(src + query);
2393
+ const renderFnName = ssr ? "ssrRender" : "render";
2394
+ return {
2395
+ code: `import { ${renderFnName} as _sfc_${renderFnName} } from ${request}`,
2396
+ map: void 0
2397
+ };
2398
+ }
2399
+ }
2400
+ async function genScriptCode(descriptor, options, pluginContext, ssr) {
2401
+ let scriptCode = `const _sfc_main = {}`;
2402
+ let map;
2403
+ const script = resolveScript(descriptor, options, ssr);
2404
+ if (script) {
2405
+ if ((!script.lang || script.lang === "ts" && options.devServer) && !script.src) {
2406
+ const userPlugins = options.script?.babelParserPlugins || [];
2407
+ const defaultPlugins = script.lang === "ts" ? userPlugins.includes("decorators") ? ["typescript"] : ["typescript", "decorators-legacy"] : [];
2408
+ scriptCode = options.compiler.rewriteDefault(
2409
+ script.content,
2410
+ "_sfc_main",
2411
+ [...defaultPlugins, ...userPlugins]
2412
+ );
2413
+ map = script.map;
2414
+ } else {
2415
+ if (script.src) {
2416
+ await linkSrcToDescriptor(script.src, descriptor, pluginContext, false);
2417
+ }
2418
+ const src = script.src || descriptor.filename;
2419
+ const langFallback = script.src && path.extname(src).slice(1) || "js";
2420
+ const attrsQuery = attrsToQuery(script.attrs, langFallback);
2421
+ const srcQuery = script.src ? `&src=true` : ``;
2422
+ const query = `?vue&type=script${srcQuery}${attrsQuery}`;
2423
+ const request = JSON.stringify(src + query);
2424
+ scriptCode = `import _sfc_main from ${request}
2425
+ export * from ${request}`;
2426
+ }
2427
+ }
2428
+ return {
2429
+ code: scriptCode,
2430
+ map
2431
+ };
2432
+ }
2433
+ async function genStyleCode(descriptor, pluginContext, asCustomElement, attachedProps) {
2434
+ let stylesCode = ``;
2435
+ let cssModulesMap;
2436
+ if (descriptor.styles.length) {
2437
+ for (let i = 0; i < descriptor.styles.length; i++) {
2438
+ const style = descriptor.styles[i];
2439
+ if (style.src) {
2440
+ await linkSrcToDescriptor(
2441
+ style.src,
2442
+ descriptor,
2443
+ pluginContext,
2444
+ style.scoped
2445
+ );
2446
+ }
2447
+ const src = style.src || descriptor.filename;
2448
+ const attrsQuery = attrsToQuery(style.attrs, "css");
2449
+ const srcQuery = style.src ? style.scoped ? `&src=${descriptor.id}` : "&src=true" : "";
2450
+ const directQuery = asCustomElement ? `&inline` : ``;
2451
+ const scopedQuery = style.scoped ? `&scoped=${descriptor.id}` : ``;
2452
+ const query = `?vue&type=style&index=${i}${srcQuery}${directQuery}${scopedQuery}`;
2453
+ const styleRequest = src + query + attrsQuery;
2454
+ if (style.module) {
2455
+ if (asCustomElement) {
2456
+ throw new Error(
2457
+ `<style module> is not supported in custom elements mode.`
2458
+ );
2459
+ }
2460
+ const [importCode, nameMap] = genCSSModulesCode(
2461
+ i,
2462
+ styleRequest,
2463
+ style.module
2464
+ );
2465
+ stylesCode += importCode;
2466
+ Object.assign(cssModulesMap || (cssModulesMap = {}), nameMap);
2467
+ } else {
2468
+ if (asCustomElement) {
2469
+ stylesCode += `
2470
+ import _style_${i} from ${JSON.stringify(
2471
+ styleRequest
2472
+ )}`;
2473
+ } else {
2474
+ stylesCode += `
2475
+ import ${JSON.stringify(styleRequest)}`;
2476
+ }
2477
+ }
2478
+ }
2479
+ if (asCustomElement) {
2480
+ attachedProps.push([
2481
+ `styles`,
2482
+ `[${descriptor.styles.map((_, i) => `_style_${i}`).join(",")}]`
2483
+ ]);
2484
+ }
2485
+ }
2486
+ if (cssModulesMap) {
2487
+ const mappingCode = Object.entries(cssModulesMap).reduce(
2488
+ (code, [key, value]) => code + `"${key}":${value},
2489
+ `,
2490
+ "{\n"
2491
+ ) + "}";
2492
+ stylesCode += `
2493
+ const cssModules = ${mappingCode}`;
2494
+ attachedProps.push([`__cssModules`, `cssModules`]);
2495
+ }
2496
+ return stylesCode;
2497
+ }
2498
+ function genCSSModulesCode(index, request, moduleName) {
2499
+ const styleVar = `style${index}`;
2500
+ const exposedName = typeof moduleName === "string" ? moduleName : "$style";
2501
+ const moduleRequest = request.replace(/\.(\w+)$/, ".module.$1");
2502
+ return [
2503
+ `
2504
+ import ${styleVar} from ${JSON.stringify(moduleRequest)}`,
2505
+ { [exposedName]: styleVar }
2506
+ ];
2507
+ }
2508
+ async function genCustomBlockCode(descriptor, pluginContext) {
2509
+ let code = "";
2510
+ for (let index = 0; index < descriptor.customBlocks.length; index++) {
2511
+ const block = descriptor.customBlocks[index];
2512
+ if (block.src) {
2513
+ await linkSrcToDescriptor(block.src, descriptor, pluginContext, false);
2514
+ }
2515
+ const src = block.src || descriptor.filename;
2516
+ const attrsQuery = attrsToQuery(block.attrs, block.type);
2517
+ const srcQuery = block.src ? `&src=true` : ``;
2518
+ const query = `?vue&type=${block.type}&index=${index}${srcQuery}${attrsQuery}`;
2519
+ const request = JSON.stringify(src + query);
2520
+ code += `import block${index} from ${request}
2521
+ `;
2522
+ code += `if (typeof block${index} === 'function') block${index}(_sfc_main)
2523
+ `;
2524
+ }
2525
+ return code;
2526
+ }
2527
+ async function linkSrcToDescriptor(src, descriptor, pluginContext, scoped) {
2528
+ const srcFile = (await pluginContext.resolve(src, descriptor.filename))?.id || src;
2529
+ setSrcDescriptor(srcFile.replace(/\?.*$/, ""), descriptor, scoped);
2530
+ }
2531
+ const ignoreList = ["id", "index", "src", "type", "lang", "module", "scoped"];
2532
+ function attrsToQuery(attrs, langFallback, forceLangFallback = false) {
2533
+ let query = ``;
2534
+ for (const name in attrs) {
2535
+ const value = attrs[name];
2536
+ if (!ignoreList.includes(name)) {
2537
+ query += `&${encodeURIComponent(name)}${value ? `=${encodeURIComponent(value)}` : ``}`;
2538
+ }
2539
+ }
2540
+ if (langFallback || attrs.lang) {
2541
+ query += `lang` in attrs ? forceLangFallback ? `&lang.${langFallback}` : `&lang.${attrs.lang}` : `&lang.${langFallback}`;
2542
+ }
2543
+ return query;
2544
+ }
2545
+
2546
+ async function transformStyle(code, descriptor, index, options, pluginContext, filename) {
2547
+ const block = descriptor.styles[index];
2548
+ const result = await options.compiler.compileStyleAsync({
2549
+ ...options.style,
2550
+ filename: descriptor.filename,
2551
+ id: `data-v-${descriptor.id}`,
2552
+ isProd: options.isProduction,
2553
+ source: code,
2554
+ scoped: block.scoped,
2555
+ ...options.cssDevSourcemap ? {
2556
+ postcssOptions: {
2557
+ map: {
2558
+ from: filename,
2559
+ inline: false,
2560
+ annotation: false
2561
+ }
2562
+ }
2563
+ } : {}
2564
+ });
2565
+ if (result.errors.length) {
2566
+ result.errors.forEach((error) => {
2567
+ if (error.line && error.column) {
2568
+ error.loc = {
2569
+ file: descriptor.filename,
2570
+ line: error.line + block.loc.start.line,
2571
+ column: error.column
2572
+ };
2573
+ }
2574
+ pluginContext.error(error);
2575
+ });
2576
+ return null;
2577
+ }
2578
+ const map = result.map ? await formatPostcssSourceMap(
2579
+ result.map,
2580
+ filename
2581
+ ) : { mappings: "" };
2582
+ return {
2583
+ code: result.code,
2584
+ map
2585
+ };
2586
+ }
2587
+
2588
+ function vuePlugin(rawOptions = {}) {
2589
+ const {
2590
+ include = /\.vue$/,
2591
+ exclude,
2592
+ customElement = /\.ce\.vue$/,
2593
+ reactivityTransform = false
2594
+ } = rawOptions;
2595
+ const filter = createFilter(include, exclude);
2596
+ const customElementFilter = typeof customElement === "boolean" ? () => customElement : createFilter(customElement);
2597
+ const refTransformFilter = reactivityTransform === false ? () => false : reactivityTransform === true ? createFilter(/\.(j|t)sx?$/, /node_modules/) : createFilter(reactivityTransform);
2598
+ let options = {
2599
+ isProduction: process.env.NODE_ENV === "production",
2600
+ compiler: null,
2601
+ ...rawOptions,
2602
+ include,
2603
+ exclude,
2604
+ customElement,
2605
+ reactivityTransform,
2606
+ root: process.cwd(),
2607
+ sourceMap: true,
2608
+ cssDevSourcemap: false,
2609
+ devToolsEnabled: process.env.NODE_ENV !== "production"
2610
+ };
2611
+ return {
2612
+ name: "vite:vue",
2613
+ handleHotUpdate(ctx) {
2614
+ if (!filter(ctx.file)) {
2615
+ return;
2616
+ }
2617
+ return handleHotUpdate(ctx, options);
2618
+ },
2619
+ config(config) {
2620
+ return {
2621
+ resolve: {
2622
+ dedupe: config.build?.ssr ? [] : ["vue"]
2623
+ },
2624
+ define: {
2625
+ __VUE_OPTIONS_API__: config.define?.__VUE_OPTIONS_API__ ?? true,
2626
+ __VUE_PROD_DEVTOOLS__: config.define?.__VUE_PROD_DEVTOOLS__ ?? false
2627
+ },
2628
+ ssr: {
2629
+ external: config.legacy?.buildSsrCjsExternalHeuristics ? ["vue", "@vue/server-renderer"] : []
2630
+ }
2631
+ };
2632
+ },
2633
+ configResolved(config) {
2634
+ options = {
2635
+ ...options,
2636
+ root: config.root,
2637
+ sourceMap: config.command === "build" ? !!config.build.sourcemap : true,
2638
+ cssDevSourcemap: config.css?.devSourcemap ?? false,
2639
+ isProduction: config.isProduction,
2640
+ devToolsEnabled: !!config.define.__VUE_PROD_DEVTOOLS__ || !config.isProduction
2641
+ };
2642
+ },
2643
+ configureServer(server) {
2644
+ options.devServer = server;
2645
+ },
2646
+ buildStart() {
2647
+ options.compiler = options.compiler || resolveCompiler(options.root);
2648
+ },
2649
+ async resolveId(id) {
2650
+ if (id === EXPORT_HELPER_ID) {
2651
+ return id;
2652
+ }
2653
+ if (parseVueRequest(id).query.vue) {
2654
+ return id;
2655
+ }
2656
+ },
2657
+ load(id, opt) {
2658
+ const ssr = opt?.ssr === true;
2659
+ if (id === EXPORT_HELPER_ID) {
2660
+ return helperCode;
2661
+ }
2662
+ const { filename, query } = parseVueRequest(id);
2663
+ if (query.vue) {
2664
+ if (query.src) {
2665
+ return fs.readFileSync(filename, "utf-8");
2666
+ }
2667
+ const descriptor = getDescriptor(filename, options);
2668
+ let block;
2669
+ if (query.type === "script") {
2670
+ block = getResolvedScript(descriptor, ssr);
2671
+ } else if (query.type === "template") {
2672
+ block = descriptor.template;
2673
+ } else if (query.type === "style") {
2674
+ block = descriptor.styles[query.index];
2675
+ } else if (query.index != null) {
2676
+ block = descriptor.customBlocks[query.index];
2677
+ }
2678
+ if (block) {
2679
+ return {
2680
+ code: block.content,
2681
+ map: block.map
2682
+ };
2683
+ }
2684
+ }
2685
+ },
2686
+ transform(code, id, opt) {
2687
+ const ssr = opt?.ssr === true;
2688
+ const { filename, query } = parseVueRequest(id);
2689
+ if (query.raw || query.url) {
2690
+ return;
2691
+ }
2692
+ if (!filter(filename) && !query.vue) {
2693
+ if (!query.vue && refTransformFilter(filename) && options.compiler.shouldTransformRef(code)) {
2694
+ return options.compiler.transformRef(code, {
2695
+ filename,
2696
+ sourceMap: true
2697
+ });
2698
+ }
2699
+ return;
2700
+ }
2701
+ if (!query.vue) {
2702
+ return transformMain(
2703
+ code,
2704
+ filename,
2705
+ options,
2706
+ this,
2707
+ ssr,
2708
+ customElementFilter(filename)
2709
+ );
2710
+ } else {
2711
+ const descriptor = query.src ? getSrcDescriptor(filename, query) : getDescriptor(filename, options);
2712
+ if (query.type === "template") {
2713
+ return transformTemplateAsModule(code, descriptor, options, this, ssr);
2714
+ } else if (query.type === "style") {
2715
+ return transformStyle(
2716
+ code,
2717
+ descriptor,
2718
+ Number(query.index),
2719
+ options,
2720
+ this,
2721
+ filename
2722
+ );
2723
+ }
2724
+ }
2725
+ }
2726
+ };
2727
+ }
2728
+
2729
+ export { vuePlugin as default, parseVueRequest };