@dcloudio/uni-cli-shared 3.0.0-4080720251210001 → 3.0.0-5000320260312001

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.
Files changed (145) hide show
  1. package/dist/constants.d.ts +3 -0
  2. package/dist/constants.js +6 -1
  3. package/dist/deps.js +6 -1
  4. package/dist/dom2/index.d.ts +1 -0
  5. package/dist/dom2/index.js +17 -0
  6. package/dist/dom2/sharedData.d.ts +2 -0
  7. package/dist/dom2/sharedData.js +19 -0
  8. package/dist/easycom.js +34 -5
  9. package/dist/env/define.d.ts +3 -0
  10. package/dist/env/define.js +12 -0
  11. package/dist/hbx/alias.js +15 -17
  12. package/dist/hbx/index.d.ts +1 -1
  13. package/dist/hbx/index.js +4 -2
  14. package/dist/hbx/log.d.ts +5 -0
  15. package/dist/hbx/log.js +44 -1
  16. package/dist/i18n.js +4 -0
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.js +1 -0
  19. package/dist/json/app/manifest/index.d.ts +1 -0
  20. package/dist/json/app/manifest/index.js +3 -1
  21. package/dist/json/mp/pages.js +0 -5
  22. package/dist/json/pages.d.ts +2 -2
  23. package/dist/json/pages.js +4 -1
  24. package/dist/json/uni-x/index.d.ts +1 -1
  25. package/dist/json/utils.js +31 -22
  26. package/dist/logs/console.js +1 -1
  27. package/dist/logs/index.d.ts +11 -0
  28. package/dist/logs/index.js +34 -1
  29. package/dist/messages/en.d.ts +6 -3
  30. package/dist/messages/en.js +6 -3
  31. package/dist/messages/index.d.ts +11 -5
  32. package/dist/messages/zh_CN.d.ts +5 -2
  33. package/dist/messages/zh_CN.js +5 -2
  34. package/dist/mp/assets.d.ts +1 -0
  35. package/dist/mp/assets.js +27 -1
  36. package/dist/mp/externalClasses.d.ts +38 -2
  37. package/dist/mp/externalClasses.js +90 -4
  38. package/dist/mp/index.d.ts +4 -3
  39. package/dist/mp/index.js +11 -1
  40. package/dist/mp/plugin.d.ts +1 -0
  41. package/dist/mp/plugin.js +14 -1
  42. package/dist/mp/style.d.ts +1 -0
  43. package/dist/mp/style.js +8 -1
  44. package/dist/mp/usingComponents.d.ts +1 -0
  45. package/dist/mp/usingComponents.js +17 -1
  46. package/dist/postcss/index.d.ts +2 -0
  47. package/dist/postcss/index.js +3 -1
  48. package/dist/postcss/plugins/stylePluginExternal.d.ts +17 -0
  49. package/dist/postcss/plugins/stylePluginExternal.js +127 -0
  50. package/dist/postcss/plugins/stylePluginScoped.js +30 -0
  51. package/dist/preprocess/context.js +2 -0
  52. package/dist/preprocess/index.d.ts +9 -6
  53. package/dist/preprocess/index.js +33 -8
  54. package/dist/resolve.js +5 -1
  55. package/dist/uni_modules.js +20 -4
  56. package/dist/utils.d.ts +2 -2
  57. package/dist/utils.js +9 -6
  58. package/dist/utsUtils.d.ts +1 -0
  59. package/dist/utsUtils.js +2 -1
  60. package/dist/vite/autoImport.js +91 -6
  61. package/dist/vite/plugins/console.js +1 -1
  62. package/dist/vite/plugins/cssScoped.js +2 -1
  63. package/dist/vite/plugins/easycom.js +7 -0
  64. package/dist/vite/plugins/json.js +69 -2
  65. package/dist/vite/plugins/pre.js +4 -2
  66. package/dist/vite/plugins/sfc.js +1 -1
  67. package/dist/vite/plugins/stats.js +32 -0
  68. package/dist/vite/plugins/uts/ext-api.js +1 -1
  69. package/dist/vite/plugins/uts/uni_modules.js +12 -0
  70. package/dist/vite/plugins/uts/uvue.js +7 -2
  71. package/dist/vite/plugins/vitejs/plugins/asset.d.ts +1 -0
  72. package/dist/vite/plugins/vitejs/plugins/asset.js +19 -1
  73. package/dist/vite/plugins/vitejs/plugins/css.d.ts +2 -1
  74. package/dist/vite/plugins/vitejs/plugins/css.js +27 -10
  75. package/dist/vite/utils/ast.d.ts +2 -1
  76. package/dist/vite/utils/ast.js +5 -1
  77. package/dist/vue/parse.d.ts +2 -0
  78. package/dist/vue/parse.js +3 -1
  79. package/dist/vue/transforms/index.d.ts +1 -0
  80. package/dist/vue/transforms/index.js +1 -0
  81. package/dist/vue/transforms/transformLineBreak.d.ts +2 -0
  82. package/dist/vue/transforms/transformLineBreak.js +15 -0
  83. package/dist/vue/transforms/transformTag.d.ts +1 -1
  84. package/dist/vue/transforms/transformTag.js +5 -0
  85. package/dist/vue/transforms/x/transformMPBuiltInTag.js +2 -2
  86. package/dist/vue/utils.js +8 -1
  87. package/lib/@vue/compiler-core/dist/compiler-core.cjs.js +42 -23
  88. package/lib/@vue/compiler-core/dist/compiler-core.cjs.prod.js +42 -23
  89. package/lib/@vue/compiler-core/dist/compiler-core.esm-bundler.js +39 -19
  90. package/lib/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +4635 -1024
  91. package/lib/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +8762 -7849
  92. package/lib/dom2/app/@vitejs/plugin-vue/LICENSE +21 -0
  93. package/lib/dom2/app/@vitejs/plugin-vue/README.md +278 -0
  94. package/lib/dom2/app/@vitejs/plugin-vue/dist/index.cjs +3353 -0
  95. package/lib/dom2/app/@vitejs/plugin-vue/dist/index.d.cts +113 -0
  96. package/lib/dom2/app/@vitejs/plugin-vue/dist/index.d.mts +111 -0
  97. package/lib/dom2/app/@vitejs/plugin-vue/dist/index.d.ts +113 -0
  98. package/lib/dom2/app/@vitejs/plugin-vue/dist/index.mjs +3338 -0
  99. package/lib/dom2/app/@vitejs/plugin-vue/package.json +50 -0
  100. package/lib/dom2/app/@vue/compiler-core/LICENSE +21 -0
  101. package/lib/dom2/app/@vue/compiler-core/README.md +1 -0
  102. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.js +5492 -0
  103. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.prod.js +5436 -0
  104. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.d.ts +1187 -0
  105. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.esm-bundler.js +4335 -0
  106. package/lib/dom2/app/@vue/compiler-core/index.js +7 -0
  107. package/lib/dom2/app/@vue/compiler-core/package.json +58 -0
  108. package/lib/dom2/app/@vue/compiler-dom/LICENSE +21 -0
  109. package/lib/dom2/app/@vue/compiler-dom/README.md +1 -0
  110. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.js +762 -0
  111. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +736 -0
  112. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.d.ts +73 -0
  113. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +5051 -0
  114. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +11 -0
  115. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +557 -0
  116. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.js +5234 -0
  117. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.prod.js +11 -0
  118. package/lib/dom2/app/@vue/compiler-dom/index.js +7 -0
  119. package/lib/dom2/app/@vue/compiler-dom/package.json +57 -0
  120. package/lib/dom2/app/@vue/compiler-sfc/LICENSE +21 -0
  121. package/lib/dom2/app/@vue/compiler-sfc/README.md +80 -0
  122. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +15528 -0
  123. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.d.ts +11595 -0
  124. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +41525 -0
  125. package/lib/dom2/app/@vue/compiler-sfc/package.json +68 -0
  126. package/lib/dom2/app/@vue/compiler-vapor/LICENSE +21 -0
  127. package/lib/dom2/app/@vue/compiler-vapor/README.md +1 -0
  128. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.cjs.js +3584 -0
  129. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.d.ts +22858 -0
  130. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.esm-browser.js +22438 -0
  131. package/lib/dom2/app/@vue/compiler-vapor/package.json +51 -0
  132. package/lib/dom2/app/@vue/compiler-vapor-dom2/dist/compiler-vapor-dom2.cjs.js +1 -0
  133. package/lib/dom2/app/@vue/compiler-vapor-dom2/package.json +56 -0
  134. package/lib/dom2/app/@vue/shared/LICENSE +21 -0
  135. package/lib/dom2/app/@vue/shared/README.md +3 -0
  136. package/lib/dom2/app/@vue/shared/dist/shared.cjs.js +773 -0
  137. package/lib/dom2/app/@vue/shared/dist/shared.cjs.prod.js +773 -0
  138. package/lib/dom2/app/@vue/shared/dist/shared.d.ts +412 -0
  139. package/lib/dom2/app/@vue/shared/dist/shared.esm-bundler.js +688 -0
  140. package/lib/dom2/app/@vue/shared/index.js +7 -0
  141. package/lib/dom2/app/@vue/shared/package.json +47 -0
  142. package/lib/preprocess/lib/preprocess.js +9 -3
  143. package/lib/vapor/@vue/compiler-core/dist/compiler-core.cjs.js +1 -1
  144. package/lib/vapor/@vue/compiler-core/dist/compiler-core.cjs.prod.js +1 -1
  145. package/package.json +8 -6
@@ -0,0 +1,3338 @@
1
+ import fs from 'node:fs';
2
+ import { normalizePath as normalizePath$1, isCSSRequest, transformWithEsbuild, formatPostcssSourceMap, createFilter } from 'vite';
3
+ import { shallowRef, computed } from 'vue';
4
+ import { createRequire } from 'node:module';
5
+ import path from 'node:path';
6
+ import crypto from 'node:crypto';
7
+ import require$$0 from 'tty';
8
+ import require$$1 from 'util';
9
+
10
+ const version = "5.2.4";
11
+
12
+ function resolveCompiler(root) {
13
+ const compiler = tryResolveCompiler(root) || tryResolveCompiler();
14
+ if (!compiler) {
15
+ throw new Error(
16
+ `Failed to resolve vue/compiler-sfc.
17
+ @vitejs/plugin-vue requires vue (>=3.2.25) to be present in the dependency tree.`
18
+ );
19
+ }
20
+ return compiler;
21
+ }
22
+ function tryResolveCompiler(root) {
23
+ const vueMeta = tryRequire("vue/package.json", root);
24
+ if (vueMeta && vueMeta.version.split(".")[0] >= 3) {
25
+ return tryRequire("vue/compiler-sfc", root);
26
+ }
27
+ }
28
+ const _require = createRequire(import.meta.url);
29
+ function tryRequire(id, from) {
30
+ try {
31
+ return from ? _require(_require.resolve(id, { paths: [from] })) : _require(id);
32
+ } catch (e) {
33
+ }
34
+ }
35
+
36
+ function parseVueRequest(id) {
37
+ const [filename, rawQuery] = id.split(`?`, 2);
38
+ const query = Object.fromEntries(new URLSearchParams(rawQuery));
39
+ if (query.vue != null) {
40
+ query.vue = true;
41
+ }
42
+ if (query.index != null) {
43
+ query.index = Number(query.index);
44
+ }
45
+ if (query.raw != null) {
46
+ query.raw = true;
47
+ }
48
+ if (query.url != null) {
49
+ query.url = true;
50
+ }
51
+ if (query.scoped != null) {
52
+ query.scoped = true;
53
+ }
54
+ return {
55
+ filename,
56
+ query
57
+ };
58
+ }
59
+
60
+ const cache = /* @__PURE__ */ new Map();
61
+ const hmrCache = /* @__PURE__ */ new Map();
62
+ const prevCache = /* @__PURE__ */ new Map();
63
+ function createDescriptor(filename, source, {
64
+ root,
65
+ isProduction,
66
+ sourceMap,
67
+ compiler,
68
+ template,
69
+ features
70
+ }, hmr = false) {
71
+ const { descriptor, errors } = compiler.parse(source, {
72
+ filename,
73
+ sourceMap,
74
+ templateParseOptions: template?.compilerOptions
75
+ });
76
+ const normalizedPath = normalizePath$1(path.relative(root, filename));
77
+ const componentIdGenerator = features?.componentIdGenerator;
78
+ if (componentIdGenerator === "filepath") {
79
+ descriptor.id = getHash(normalizedPath);
80
+ } else if (componentIdGenerator === "filepath-source") {
81
+ descriptor.id = getHash(normalizedPath + source);
82
+ } else if (typeof componentIdGenerator === "function") {
83
+ descriptor.id = componentIdGenerator(
84
+ normalizedPath,
85
+ source,
86
+ isProduction,
87
+ getHash
88
+ );
89
+ } else {
90
+ descriptor.id = getHash(normalizedPath + (isProduction ? source : ""));
91
+ }
92
+ (hmr ? hmrCache : cache).set(filename, descriptor);
93
+ return { descriptor, errors };
94
+ }
95
+ function getPrevDescriptor(filename) {
96
+ return prevCache.get(filename);
97
+ }
98
+ function invalidateDescriptor(filename, hmr = false) {
99
+ const _cache = hmr ? hmrCache : cache;
100
+ const prev = _cache.get(filename);
101
+ _cache.delete(filename);
102
+ if (prev) {
103
+ prevCache.set(filename, prev);
104
+ }
105
+ }
106
+ function getDescriptor(filename, options, createIfNotFound = true, hmr = false, code) {
107
+ const _cache = hmr ? hmrCache : cache;
108
+ if (_cache.has(filename)) {
109
+ return _cache.get(filename);
110
+ }
111
+ if (createIfNotFound) {
112
+ const { descriptor, errors } = createDescriptor(
113
+ filename,
114
+ code ?? fs.readFileSync(filename, "utf-8"),
115
+ options,
116
+ hmr
117
+ );
118
+ if (errors.length && !hmr) {
119
+ throw errors[0];
120
+ }
121
+ return descriptor;
122
+ }
123
+ }
124
+ function getSrcDescriptor(filename, query) {
125
+ if (query.scoped) {
126
+ return cache.get(`${filename}?src=${query.src}`);
127
+ }
128
+ return cache.get(filename);
129
+ }
130
+ function getTempSrcDescriptor(filename, query) {
131
+ return {
132
+ filename,
133
+ id: query.id || "",
134
+ styles: [
135
+ {
136
+ scoped: query.scoped,
137
+ loc: {
138
+ start: { line: 0, column: 0 }
139
+ }
140
+ }
141
+ ],
142
+ isTemp: true
143
+ };
144
+ }
145
+ function setSrcDescriptor(filename, entry, scoped) {
146
+ if (scoped) {
147
+ cache.set(`${filename}?src=${entry.id}`, entry);
148
+ return;
149
+ }
150
+ cache.set(filename, entry);
151
+ }
152
+ const hash = (
153
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins -- crypto.hash is supported in Node 21.7.0+, 20.12.0+
154
+ crypto.hash ?? ((algorithm, data, outputEncoding) => crypto.createHash(algorithm).update(data).digest(outputEncoding))
155
+ );
156
+ function getHash(text) {
157
+ return hash("sha256", text, "hex").substring(0, 8);
158
+ }
159
+
160
+ function slash(path) {
161
+ const isExtendedLengthPath = path.startsWith('\\\\?\\');
162
+
163
+ if (isExtendedLengthPath) {
164
+ return path;
165
+ }
166
+
167
+ return path.replace(/\\/g, '/');
168
+ }
169
+
170
+ function createRollupError(id, error) {
171
+ if (error.customPrint) {
172
+ return error;
173
+ }
174
+ const { message, name, stack } = error;
175
+ const rollupError = {
176
+ id,
177
+ plugin: "vue",
178
+ message,
179
+ name,
180
+ stack
181
+ };
182
+ Object.defineProperty(rollupError, "message", {
183
+ get() {
184
+ return message;
185
+ },
186
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
187
+ set(_v) {
188
+ }
189
+ });
190
+ if ("code" in error && error.loc) {
191
+ rollupError.loc = {
192
+ file: id,
193
+ line: error.loc.start.line,
194
+ column: error.loc.start.column
195
+ };
196
+ }
197
+ return rollupError;
198
+ }
199
+
200
+ async function transformTemplateAsModule(code, descriptor, options, pluginContext, ssr, customElement) {
201
+ const result = compile(
202
+ code,
203
+ descriptor,
204
+ options,
205
+ pluginContext,
206
+ ssr,
207
+ customElement
208
+ );
209
+ let returnCode = result.code;
210
+ if (options.devServer && options.devServer.config.server.hmr !== false && !ssr && !options.isProduction) {
211
+ returnCode += `
212
+ import.meta.hot.accept(({ render }) => {
213
+ __VUE_HMR_RUNTIME__.rerender(${JSON.stringify(descriptor.id)}, render)
214
+ })`;
215
+ }
216
+ return {
217
+ code: returnCode,
218
+ map: result.map
219
+ };
220
+ }
221
+ function transformTemplateInMain(code, descriptor, options, pluginContext, ssr, customElement) {
222
+ const result = compile(
223
+ code,
224
+ descriptor,
225
+ options,
226
+ pluginContext,
227
+ ssr,
228
+ customElement
229
+ );
230
+ return {
231
+ ...result,
232
+ code: result.code.replace(
233
+ /\nexport (function|const) (render|ssrRender)/,
234
+ "\n$1 _sfc_$2"
235
+ )
236
+ };
237
+ }
238
+ function compile(code, descriptor, options, pluginContext, ssr, customElement) {
239
+ const filename = descriptor.filename;
240
+ resolveScript(false, descriptor, options, ssr, customElement);
241
+ const result = options.compiler.compileTemplate({
242
+ ...resolveTemplateCompilerOptions(descriptor, options, ssr),
243
+ source: code
244
+ });
245
+ if (result.errors.length) {
246
+ result.errors.forEach(
247
+ (error) => pluginContext.error(
248
+ typeof error === "string" ? { id: filename, message: error } : createRollupError(filename, error)
249
+ )
250
+ );
251
+ }
252
+ if (result.tips.length) {
253
+ result.tips.forEach(
254
+ (tip) => pluginContext.warn({
255
+ id: filename,
256
+ message: tip
257
+ })
258
+ );
259
+ }
260
+ return result;
261
+ }
262
+ function resolveTemplateCompilerOptions(descriptor, options, ssr) {
263
+ const block = descriptor.template;
264
+ if (!block) {
265
+ return;
266
+ }
267
+ const resolvedScript = getResolvedScript(descriptor, ssr);
268
+ const hasScoped = descriptor.styles.some((s) => s.scoped);
269
+ const { id, filename, cssVars } = descriptor;
270
+ let transformAssetUrls = options.template?.transformAssetUrls;
271
+ let assetUrlOptions;
272
+ if (transformAssetUrls === false) ; else if (options.devServer) {
273
+ if (filename.startsWith(options.root)) {
274
+ const devBase = options.devServer.config.base;
275
+ assetUrlOptions = {
276
+ base: (options.devServer.config.server?.origin ?? "") + devBase + slash(path.relative(options.root, path.dirname(filename))),
277
+ includeAbsolute: !!devBase
278
+ };
279
+ }
280
+ } else {
281
+ assetUrlOptions = {
282
+ includeAbsolute: true
283
+ };
284
+ }
285
+ if (transformAssetUrls && typeof transformAssetUrls === "object") {
286
+ if (Object.values(transformAssetUrls).some((val) => Array.isArray(val))) {
287
+ transformAssetUrls = {
288
+ ...assetUrlOptions,
289
+ tags: transformAssetUrls
290
+ };
291
+ } else {
292
+ transformAssetUrls = { ...assetUrlOptions, ...transformAssetUrls };
293
+ }
294
+ } else {
295
+ transformAssetUrls = assetUrlOptions;
296
+ }
297
+ let preprocessOptions = block.lang && options.template?.preprocessOptions;
298
+ if (block.lang === "pug") {
299
+ preprocessOptions = {
300
+ doctype: "html",
301
+ ...preprocessOptions
302
+ };
303
+ }
304
+ const expressionPlugins = options.template?.compilerOptions?.expressionPlugins || [];
305
+ const lang = descriptor.scriptSetup?.lang || descriptor.script?.lang;
306
+ if (lang && /tsx?$/.test(lang) && !expressionPlugins.includes("typescript")) {
307
+ expressionPlugins.push("typescript");
308
+ }
309
+ const extraOptions = options.template?.compilerOptions?.extraOptions?.(descriptor);
310
+ if (extraOptions.helper) {
311
+ extraOptions.className = extraOptions.helper.GCN(
312
+ descriptor.filename,
313
+ process.env.UNI_INPUT_DIR
314
+ );
315
+ extraOptions.r = extraOptions.helper.K;
316
+ }
317
+ return {
318
+ ...options.template,
319
+ // @ts-expect-error TODO remove when 3.6 is out
320
+ vapor: descriptor.vapor,
321
+ id,
322
+ ast: canReuseAST(options.compiler.version) ? descriptor.template?.ast : void 0,
323
+ filename,
324
+ scoped: hasScoped,
325
+ slotted: descriptor.slotted,
326
+ isProd: options.isProduction,
327
+ inMap: block.src ? void 0 : block.map,
328
+ ssr,
329
+ ssrCssVars: cssVars,
330
+ transformAssetUrls,
331
+ preprocessLang: block.lang === "html" ? void 0 : block.lang,
332
+ preprocessOptions,
333
+ compilerOptions: {
334
+ ...options.template?.compilerOptions,
335
+ // fixed by uts 需要额外添加参数,比如className
336
+ ...extraOptions,
337
+ scopeId: hasScoped ? `data-v-${id}` : void 0,
338
+ bindingMetadata: resolvedScript ? resolvedScript.bindings : void 0,
339
+ expressionPlugins,
340
+ sourceMap: options.sourceMap
341
+ }
342
+ };
343
+ }
344
+ function canReuseAST(version) {
345
+ if (version) {
346
+ const [_, minor, patch] = version.split(".").map(Number);
347
+ if (minor >= 4 && patch >= 3) {
348
+ return true;
349
+ }
350
+ }
351
+ return false;
352
+ }
353
+
354
+ let clientCache = /* @__PURE__ */ new WeakMap();
355
+ let ssrCache = /* @__PURE__ */ new WeakMap();
356
+ const typeDepToSFCMap = /* @__PURE__ */ new Map();
357
+ function invalidateScript(filename) {
358
+ const desc = cache.get(filename);
359
+ if (desc) {
360
+ clientCache.delete(desc);
361
+ ssrCache.delete(desc);
362
+ }
363
+ }
364
+ function getResolvedScript(descriptor, ssr) {
365
+ return (ssr ? ssrCache : clientCache).get(descriptor);
366
+ }
367
+ function setResolvedScript(descriptor, script, ssr) {
368
+ (ssr ? ssrCache : clientCache).set(descriptor, script);
369
+ }
370
+ function clearScriptCache() {
371
+ clientCache = /* @__PURE__ */ new WeakMap();
372
+ ssrCache = /* @__PURE__ */ new WeakMap();
373
+ }
374
+ function isUseInlineTemplate(descriptor, options) {
375
+ if (process.env.UNI_APP_X_DOM2 === "true") {
376
+ return true;
377
+ }
378
+ return !options.devServer && !options.devToolsEnabled && !!descriptor.scriptSetup && !descriptor.template?.src;
379
+ }
380
+ const scriptIdentifier = `_sfc_main`;
381
+ function resolveScript(useCache, descriptor, options, ssr, customElement) {
382
+ if (!descriptor.script && !descriptor.scriptSetup) {
383
+ return null;
384
+ }
385
+ if (useCache) {
386
+ const cached = getResolvedScript(descriptor, ssr);
387
+ if (cached) {
388
+ return cached;
389
+ }
390
+ }
391
+ const extraOptions = options.script?.extraOptions?.(descriptor);
392
+ if (extraOptions.helper) {
393
+ extraOptions.className = extraOptions.helper.GCN(
394
+ descriptor.filename,
395
+ process.env.UNI_INPUT_DIR
396
+ );
397
+ }
398
+ const resolved = options.compiler.compileScript(descriptor, {
399
+ ...options.script,
400
+ // fixed by uts 传递额外参数
401
+ ...extraOptions,
402
+ id: descriptor.id,
403
+ isProd: options.isProduction,
404
+ inlineTemplate: isUseInlineTemplate(descriptor, options),
405
+ templateOptions: resolveTemplateCompilerOptions(descriptor, options, ssr),
406
+ sourceMap: options.sourceMap,
407
+ genDefaultAs: canInlineMain(descriptor, options) ? scriptIdentifier : void 0,
408
+ customElement,
409
+ propsDestructure: options.features?.propsDestructure ?? options.script?.propsDestructure
410
+ });
411
+ if (!options.isProduction && resolved?.deps) {
412
+ for (const [key, sfcs] of typeDepToSFCMap) {
413
+ if (sfcs.has(descriptor.filename) && !resolved.deps.includes(key)) {
414
+ sfcs.delete(descriptor.filename);
415
+ }
416
+ }
417
+ for (const dep of resolved.deps) {
418
+ const existingSet = typeDepToSFCMap.get(dep);
419
+ if (!existingSet) {
420
+ typeDepToSFCMap.set(dep, /* @__PURE__ */ new Set([descriptor.filename]));
421
+ } else {
422
+ existingSet.add(descriptor.filename);
423
+ }
424
+ }
425
+ }
426
+ setResolvedScript(descriptor, resolved, ssr);
427
+ return resolved;
428
+ }
429
+ function canInlineMain(descriptor, options) {
430
+ if (descriptor.script?.src || descriptor.scriptSetup?.src) {
431
+ return false;
432
+ }
433
+ const lang = descriptor.script?.lang || descriptor.scriptSetup?.lang;
434
+ if (!lang || lang === "js") {
435
+ return true;
436
+ }
437
+ if (lang === "ts" && options.devServer) {
438
+ return true;
439
+ }
440
+ return false;
441
+ }
442
+
443
+ const comma = ','.charCodeAt(0);
444
+ const semicolon = ';'.charCodeAt(0);
445
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
446
+ const intToChar = new Uint8Array(64); // 64 possible chars.
447
+ const charToInt = new Uint8Array(128); // z is 122 in ASCII
448
+ for (let i = 0; i < chars.length; i++) {
449
+ const c = chars.charCodeAt(i);
450
+ intToChar[i] = c;
451
+ charToInt[c] = i;
452
+ }
453
+ function decodeInteger(reader, relative) {
454
+ let value = 0;
455
+ let shift = 0;
456
+ let integer = 0;
457
+ do {
458
+ const c = reader.next();
459
+ integer = charToInt[c];
460
+ value |= (integer & 31) << shift;
461
+ shift += 5;
462
+ } while (integer & 32);
463
+ const shouldNegate = value & 1;
464
+ value >>>= 1;
465
+ if (shouldNegate) {
466
+ value = -2147483648 | -value;
467
+ }
468
+ return relative + value;
469
+ }
470
+ function encodeInteger(builder, num, relative) {
471
+ let delta = num - relative;
472
+ delta = delta < 0 ? (-delta << 1) | 1 : delta << 1;
473
+ do {
474
+ let clamped = delta & 0b011111;
475
+ delta >>>= 5;
476
+ if (delta > 0)
477
+ clamped |= 0b100000;
478
+ builder.write(intToChar[clamped]);
479
+ } while (delta > 0);
480
+ return num;
481
+ }
482
+ function hasMoreVlq(reader, max) {
483
+ if (reader.pos >= max)
484
+ return false;
485
+ return reader.peek() !== comma;
486
+ }
487
+
488
+ const bufLength = 1024 * 16;
489
+ // Provide a fallback for older environments.
490
+ const td = typeof TextDecoder !== 'undefined'
491
+ ? /* #__PURE__ */ new TextDecoder()
492
+ : typeof Buffer !== 'undefined'
493
+ ? {
494
+ decode(buf) {
495
+ const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
496
+ return out.toString();
497
+ },
498
+ }
499
+ : {
500
+ decode(buf) {
501
+ let out = '';
502
+ for (let i = 0; i < buf.length; i++) {
503
+ out += String.fromCharCode(buf[i]);
504
+ }
505
+ return out;
506
+ },
507
+ };
508
+ class StringWriter {
509
+ constructor() {
510
+ this.pos = 0;
511
+ this.out = '';
512
+ this.buffer = new Uint8Array(bufLength);
513
+ }
514
+ write(v) {
515
+ const { buffer } = this;
516
+ buffer[this.pos++] = v;
517
+ if (this.pos === bufLength) {
518
+ this.out += td.decode(buffer);
519
+ this.pos = 0;
520
+ }
521
+ }
522
+ flush() {
523
+ const { buffer, out, pos } = this;
524
+ return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
525
+ }
526
+ }
527
+ class StringReader {
528
+ constructor(buffer) {
529
+ this.pos = 0;
530
+ this.buffer = buffer;
531
+ }
532
+ next() {
533
+ return this.buffer.charCodeAt(this.pos++);
534
+ }
535
+ peek() {
536
+ return this.buffer.charCodeAt(this.pos);
537
+ }
538
+ indexOf(char) {
539
+ const { buffer, pos } = this;
540
+ const idx = buffer.indexOf(char, pos);
541
+ return idx === -1 ? buffer.length : idx;
542
+ }
543
+ }
544
+
545
+ function decode(mappings) {
546
+ const { length } = mappings;
547
+ const reader = new StringReader(mappings);
548
+ const decoded = [];
549
+ let genColumn = 0;
550
+ let sourcesIndex = 0;
551
+ let sourceLine = 0;
552
+ let sourceColumn = 0;
553
+ let namesIndex = 0;
554
+ do {
555
+ const semi = reader.indexOf(';');
556
+ const line = [];
557
+ let sorted = true;
558
+ let lastCol = 0;
559
+ genColumn = 0;
560
+ while (reader.pos < semi) {
561
+ let seg;
562
+ genColumn = decodeInteger(reader, genColumn);
563
+ if (genColumn < lastCol)
564
+ sorted = false;
565
+ lastCol = genColumn;
566
+ if (hasMoreVlq(reader, semi)) {
567
+ sourcesIndex = decodeInteger(reader, sourcesIndex);
568
+ sourceLine = decodeInteger(reader, sourceLine);
569
+ sourceColumn = decodeInteger(reader, sourceColumn);
570
+ if (hasMoreVlq(reader, semi)) {
571
+ namesIndex = decodeInteger(reader, namesIndex);
572
+ seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];
573
+ }
574
+ else {
575
+ seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
576
+ }
577
+ }
578
+ else {
579
+ seg = [genColumn];
580
+ }
581
+ line.push(seg);
582
+ reader.pos++;
583
+ }
584
+ if (!sorted)
585
+ sort(line);
586
+ decoded.push(line);
587
+ reader.pos = semi + 1;
588
+ } while (reader.pos <= length);
589
+ return decoded;
590
+ }
591
+ function sort(line) {
592
+ line.sort(sortComparator$1);
593
+ }
594
+ function sortComparator$1(a, b) {
595
+ return a[0] - b[0];
596
+ }
597
+ function encode(decoded) {
598
+ const writer = new StringWriter();
599
+ let sourcesIndex = 0;
600
+ let sourceLine = 0;
601
+ let sourceColumn = 0;
602
+ let namesIndex = 0;
603
+ for (let i = 0; i < decoded.length; i++) {
604
+ const line = decoded[i];
605
+ if (i > 0)
606
+ writer.write(semicolon);
607
+ if (line.length === 0)
608
+ continue;
609
+ let genColumn = 0;
610
+ for (let j = 0; j < line.length; j++) {
611
+ const segment = line[j];
612
+ if (j > 0)
613
+ writer.write(comma);
614
+ genColumn = encodeInteger(writer, segment[0], genColumn);
615
+ if (segment.length === 1)
616
+ continue;
617
+ sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
618
+ sourceLine = encodeInteger(writer, segment[2], sourceLine);
619
+ sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
620
+ if (segment.length === 4)
621
+ continue;
622
+ namesIndex = encodeInteger(writer, segment[4], namesIndex);
623
+ }
624
+ }
625
+ return writer.flush();
626
+ }
627
+
628
+ // Matches the scheme of a URL, eg "http://"
629
+ const schemeRegex = /^[\w+.-]+:\/\//;
630
+ /**
631
+ * Matches the parts of a URL:
632
+ * 1. Scheme, including ":", guaranteed.
633
+ * 2. User/password, including "@", optional.
634
+ * 3. Host, guaranteed.
635
+ * 4. Port, including ":", optional.
636
+ * 5. Path, including "/", optional.
637
+ * 6. Query, including "?", optional.
638
+ * 7. Hash, including "#", optional.
639
+ */
640
+ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
641
+ /**
642
+ * File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
643
+ * with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
644
+ *
645
+ * 1. Host, optional.
646
+ * 2. Path, which may include "/", guaranteed.
647
+ * 3. Query, including "?", optional.
648
+ * 4. Hash, including "#", optional.
649
+ */
650
+ const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
651
+ function isAbsoluteUrl(input) {
652
+ return schemeRegex.test(input);
653
+ }
654
+ function isSchemeRelativeUrl(input) {
655
+ return input.startsWith('//');
656
+ }
657
+ function isAbsolutePath(input) {
658
+ return input.startsWith('/');
659
+ }
660
+ function isFileUrl(input) {
661
+ return input.startsWith('file:');
662
+ }
663
+ function isRelative(input) {
664
+ return /^[.?#]/.test(input);
665
+ }
666
+ function parseAbsoluteUrl(input) {
667
+ const match = urlRegex.exec(input);
668
+ return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/', match[6] || '', match[7] || '');
669
+ }
670
+ function parseFileUrl(input) {
671
+ const match = fileRegex.exec(input);
672
+ const path = match[2];
673
+ return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path, match[3] || '', match[4] || '');
674
+ }
675
+ function makeUrl(scheme, user, host, port, path, query, hash) {
676
+ return {
677
+ scheme,
678
+ user,
679
+ host,
680
+ port,
681
+ path,
682
+ query,
683
+ hash,
684
+ type: 7 /* Absolute */,
685
+ };
686
+ }
687
+ function parseUrl(input) {
688
+ if (isSchemeRelativeUrl(input)) {
689
+ const url = parseAbsoluteUrl('http:' + input);
690
+ url.scheme = '';
691
+ url.type = 6 /* SchemeRelative */;
692
+ return url;
693
+ }
694
+ if (isAbsolutePath(input)) {
695
+ const url = parseAbsoluteUrl('http://foo.com' + input);
696
+ url.scheme = '';
697
+ url.host = '';
698
+ url.type = 5 /* AbsolutePath */;
699
+ return url;
700
+ }
701
+ if (isFileUrl(input))
702
+ return parseFileUrl(input);
703
+ if (isAbsoluteUrl(input))
704
+ return parseAbsoluteUrl(input);
705
+ const url = parseAbsoluteUrl('http://foo.com/' + input);
706
+ url.scheme = '';
707
+ url.host = '';
708
+ url.type = input
709
+ ? input.startsWith('?')
710
+ ? 3 /* Query */
711
+ : input.startsWith('#')
712
+ ? 2 /* Hash */
713
+ : 4 /* RelativePath */
714
+ : 1 /* Empty */;
715
+ return url;
716
+ }
717
+ function stripPathFilename(path) {
718
+ // If a path ends with a parent directory "..", then it's a relative path with excess parent
719
+ // paths. It's not a file, so we can't strip it.
720
+ if (path.endsWith('/..'))
721
+ return path;
722
+ const index = path.lastIndexOf('/');
723
+ return path.slice(0, index + 1);
724
+ }
725
+ function mergePaths(url, base) {
726
+ normalizePath(base, base.type);
727
+ // If the path is just a "/", then it was an empty path to begin with (remember, we're a relative
728
+ // path).
729
+ if (url.path === '/') {
730
+ url.path = base.path;
731
+ }
732
+ else {
733
+ // Resolution happens relative to the base path's directory, not the file.
734
+ url.path = stripPathFilename(base.path) + url.path;
735
+ }
736
+ }
737
+ /**
738
+ * The path can have empty directories "//", unneeded parents "foo/..", or current directory
739
+ * "foo/.". We need to normalize to a standard representation.
740
+ */
741
+ function normalizePath(url, type) {
742
+ const rel = type <= 4 /* RelativePath */;
743
+ const pieces = url.path.split('/');
744
+ // We need to preserve the first piece always, so that we output a leading slash. The item at
745
+ // pieces[0] is an empty string.
746
+ let pointer = 1;
747
+ // Positive is the number of real directories we've output, used for popping a parent directory.
748
+ // Eg, "foo/bar/.." will have a positive 2, and we can decrement to be left with just "foo".
749
+ let positive = 0;
750
+ // We need to keep a trailing slash if we encounter an empty directory (eg, splitting "foo/" will
751
+ // generate `["foo", ""]` pieces). And, if we pop a parent directory. But once we encounter a
752
+ // real directory, we won't need to append, unless the other conditions happen again.
753
+ let addTrailingSlash = false;
754
+ for (let i = 1; i < pieces.length; i++) {
755
+ const piece = pieces[i];
756
+ // An empty directory, could be a trailing slash, or just a double "//" in the path.
757
+ if (!piece) {
758
+ addTrailingSlash = true;
759
+ continue;
760
+ }
761
+ // If we encounter a real directory, then we don't need to append anymore.
762
+ addTrailingSlash = false;
763
+ // A current directory, which we can always drop.
764
+ if (piece === '.')
765
+ continue;
766
+ // A parent directory, we need to see if there are any real directories we can pop. Else, we
767
+ // have an excess of parents, and we'll need to keep the "..".
768
+ if (piece === '..') {
769
+ if (positive) {
770
+ addTrailingSlash = true;
771
+ positive--;
772
+ pointer--;
773
+ }
774
+ else if (rel) {
775
+ // If we're in a relativePath, then we need to keep the excess parents. Else, in an absolute
776
+ // URL, protocol relative URL, or an absolute path, we don't need to keep excess.
777
+ pieces[pointer++] = piece;
778
+ }
779
+ continue;
780
+ }
781
+ // We've encountered a real directory. Move it to the next insertion pointer, which accounts for
782
+ // any popped or dropped directories.
783
+ pieces[pointer++] = piece;
784
+ positive++;
785
+ }
786
+ let path = '';
787
+ for (let i = 1; i < pointer; i++) {
788
+ path += '/' + pieces[i];
789
+ }
790
+ if (!path || (addTrailingSlash && !path.endsWith('/..'))) {
791
+ path += '/';
792
+ }
793
+ url.path = path;
794
+ }
795
+ /**
796
+ * Attempts to resolve `input` URL/path relative to `base`.
797
+ */
798
+ function resolve$1(input, base) {
799
+ if (!input && !base)
800
+ return '';
801
+ const url = parseUrl(input);
802
+ let inputType = url.type;
803
+ if (base && inputType !== 7 /* Absolute */) {
804
+ const baseUrl = parseUrl(base);
805
+ const baseType = baseUrl.type;
806
+ switch (inputType) {
807
+ case 1 /* Empty */:
808
+ url.hash = baseUrl.hash;
809
+ // fall through
810
+ case 2 /* Hash */:
811
+ url.query = baseUrl.query;
812
+ // fall through
813
+ case 3 /* Query */:
814
+ case 4 /* RelativePath */:
815
+ mergePaths(url, baseUrl);
816
+ // fall through
817
+ case 5 /* AbsolutePath */:
818
+ // The host, user, and port are joined, you can't copy one without the others.
819
+ url.user = baseUrl.user;
820
+ url.host = baseUrl.host;
821
+ url.port = baseUrl.port;
822
+ // fall through
823
+ case 6 /* SchemeRelative */:
824
+ // The input doesn't have a schema at least, so we need to copy at least that over.
825
+ url.scheme = baseUrl.scheme;
826
+ }
827
+ if (baseType > inputType)
828
+ inputType = baseType;
829
+ }
830
+ normalizePath(url, inputType);
831
+ const queryHash = url.query + url.hash;
832
+ switch (inputType) {
833
+ // This is impossible, because of the empty checks at the start of the function.
834
+ // case UrlType.Empty:
835
+ case 2 /* Hash */:
836
+ case 3 /* Query */:
837
+ return queryHash;
838
+ case 4 /* RelativePath */: {
839
+ // The first char is always a "/", and we need it to be relative.
840
+ const path = url.path.slice(1);
841
+ if (!path)
842
+ return queryHash || '.';
843
+ if (isRelative(base || input) && !isRelative(path)) {
844
+ // If base started with a leading ".", or there is no base and input started with a ".",
845
+ // then we need to ensure that the relative path starts with a ".". We don't know if
846
+ // relative starts with a "..", though, so check before prepending.
847
+ return './' + path + queryHash;
848
+ }
849
+ return path + queryHash;
850
+ }
851
+ case 5 /* AbsolutePath */:
852
+ return url.path + queryHash;
853
+ default:
854
+ return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
855
+ }
856
+ }
857
+
858
+ function resolve(input, base) {
859
+ // The base is always treated as a directory, if it's not empty.
860
+ // https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327
861
+ // https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
862
+ if (base && !base.endsWith('/'))
863
+ base += '/';
864
+ return resolve$1(input, base);
865
+ }
866
+
867
+ /**
868
+ * Removes everything after the last "/", but leaves the slash.
869
+ */
870
+ function stripFilename(path) {
871
+ if (!path)
872
+ return '';
873
+ const index = path.lastIndexOf('/');
874
+ return path.slice(0, index + 1);
875
+ }
876
+
877
+ const COLUMN$1 = 0;
878
+ const SOURCES_INDEX = 1;
879
+ const SOURCE_LINE = 2;
880
+ const SOURCE_COLUMN = 3;
881
+ const NAMES_INDEX = 4;
882
+
883
+ function maybeSort(mappings, owned) {
884
+ const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
885
+ if (unsortedIndex === mappings.length)
886
+ return mappings;
887
+ // If we own the array (meaning we parsed it from JSON), then we're free to directly mutate it. If
888
+ // not, we do not want to modify the consumer's input array.
889
+ if (!owned)
890
+ mappings = mappings.slice();
891
+ for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
892
+ mappings[i] = sortSegments(mappings[i], owned);
893
+ }
894
+ return mappings;
895
+ }
896
+ function nextUnsortedSegmentLine(mappings, start) {
897
+ for (let i = start; i < mappings.length; i++) {
898
+ if (!isSorted(mappings[i]))
899
+ return i;
900
+ }
901
+ return mappings.length;
902
+ }
903
+ function isSorted(line) {
904
+ for (let j = 1; j < line.length; j++) {
905
+ if (line[j][COLUMN$1] < line[j - 1][COLUMN$1]) {
906
+ return false;
907
+ }
908
+ }
909
+ return true;
910
+ }
911
+ function sortSegments(line, owned) {
912
+ if (!owned)
913
+ line = line.slice();
914
+ return line.sort(sortComparator);
915
+ }
916
+ function sortComparator(a, b) {
917
+ return a[COLUMN$1] - b[COLUMN$1];
918
+ }
919
+
920
+ let found = false;
921
+ /**
922
+ * A binary search implementation that returns the index if a match is found.
923
+ * If no match is found, then the left-index (the index associated with the item that comes just
924
+ * before the desired index) is returned. To maintain proper sort order, a splice would happen at
925
+ * the next index:
926
+ *
927
+ * ```js
928
+ * const array = [1, 3];
929
+ * const needle = 2;
930
+ * const index = binarySearch(array, needle, (item, needle) => item - needle);
931
+ *
932
+ * assert.equal(index, 0);
933
+ * array.splice(index + 1, 0, needle);
934
+ * assert.deepEqual(array, [1, 2, 3]);
935
+ * ```
936
+ */
937
+ function binarySearch(haystack, needle, low, high) {
938
+ while (low <= high) {
939
+ const mid = low + ((high - low) >> 1);
940
+ const cmp = haystack[mid][COLUMN$1] - needle;
941
+ if (cmp === 0) {
942
+ found = true;
943
+ return mid;
944
+ }
945
+ if (cmp < 0) {
946
+ low = mid + 1;
947
+ }
948
+ else {
949
+ high = mid - 1;
950
+ }
951
+ }
952
+ found = false;
953
+ return low - 1;
954
+ }
955
+ function upperBound(haystack, needle, index) {
956
+ for (let i = index + 1; i < haystack.length; index = i++) {
957
+ if (haystack[i][COLUMN$1] !== needle)
958
+ break;
959
+ }
960
+ return index;
961
+ }
962
+ function lowerBound(haystack, needle, index) {
963
+ for (let i = index - 1; i >= 0; index = i--) {
964
+ if (haystack[i][COLUMN$1] !== needle)
965
+ break;
966
+ }
967
+ return index;
968
+ }
969
+ function memoizedState() {
970
+ return {
971
+ lastKey: -1,
972
+ lastNeedle: -1,
973
+ lastIndex: -1,
974
+ };
975
+ }
976
+ /**
977
+ * This overly complicated beast is just to record the last tested line/column and the resulting
978
+ * index, allowing us to skip a few tests if mappings are monotonically increasing.
979
+ */
980
+ function memoizedBinarySearch(haystack, needle, state, key) {
981
+ const { lastKey, lastNeedle, lastIndex } = state;
982
+ let low = 0;
983
+ let high = haystack.length - 1;
984
+ if (key === lastKey) {
985
+ if (needle === lastNeedle) {
986
+ found = lastIndex !== -1 && haystack[lastIndex][COLUMN$1] === needle;
987
+ return lastIndex;
988
+ }
989
+ if (needle >= lastNeedle) {
990
+ // lastIndex may be -1 if the previous needle was not found.
991
+ low = lastIndex === -1 ? 0 : lastIndex;
992
+ }
993
+ else {
994
+ high = lastIndex;
995
+ }
996
+ }
997
+ state.lastKey = key;
998
+ state.lastNeedle = needle;
999
+ return (state.lastIndex = binarySearch(haystack, needle, low, high));
1000
+ }
1001
+
1002
+ const LINE_GTR_ZERO = '`line` must be greater than 0 (lines start at line 1)';
1003
+ const COL_GTR_EQ_ZERO = '`column` must be greater than or equal to 0 (columns start at column 0)';
1004
+ const LEAST_UPPER_BOUND = -1;
1005
+ const GREATEST_LOWER_BOUND = 1;
1006
+ class TraceMap {
1007
+ constructor(map, mapUrl) {
1008
+ const isString = typeof map === 'string';
1009
+ if (!isString && map._decodedMemo)
1010
+ return map;
1011
+ const parsed = (isString ? JSON.parse(map) : map);
1012
+ const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
1013
+ this.version = version;
1014
+ this.file = file;
1015
+ this.names = names || [];
1016
+ this.sourceRoot = sourceRoot;
1017
+ this.sources = sources;
1018
+ this.sourcesContent = sourcesContent;
1019
+ this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || undefined;
1020
+ const from = resolve(sourceRoot || '', stripFilename(mapUrl));
1021
+ this.resolvedSources = sources.map((s) => resolve(s || '', from));
1022
+ const { mappings } = parsed;
1023
+ if (typeof mappings === 'string') {
1024
+ this._encoded = mappings;
1025
+ this._decoded = undefined;
1026
+ }
1027
+ else {
1028
+ this._encoded = undefined;
1029
+ this._decoded = maybeSort(mappings, isString);
1030
+ }
1031
+ this._decodedMemo = memoizedState();
1032
+ this._bySources = undefined;
1033
+ this._bySourceMemos = undefined;
1034
+ }
1035
+ }
1036
+ /**
1037
+ * Typescript doesn't allow friend access to private fields, so this just casts the map into a type
1038
+ * with public access modifiers.
1039
+ */
1040
+ function cast$2(map) {
1041
+ return map;
1042
+ }
1043
+ /**
1044
+ * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
1045
+ */
1046
+ function decodedMappings(map) {
1047
+ var _a;
1048
+ return ((_a = cast$2(map))._decoded || (_a._decoded = decode(cast$2(map)._encoded)));
1049
+ }
1050
+ /**
1051
+ * A higher-level API to find the source/line/column associated with a generated line/column
1052
+ * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
1053
+ * `source-map` library.
1054
+ */
1055
+ function originalPositionFor(map, needle) {
1056
+ let { line, column, bias } = needle;
1057
+ line--;
1058
+ if (line < 0)
1059
+ throw new Error(LINE_GTR_ZERO);
1060
+ if (column < 0)
1061
+ throw new Error(COL_GTR_EQ_ZERO);
1062
+ const decoded = decodedMappings(map);
1063
+ // It's common for parent source maps to have pointers to lines that have no
1064
+ // mapping (like a "//# sourceMappingURL=") at the end of the child file.
1065
+ if (line >= decoded.length)
1066
+ return OMapping(null, null, null, null);
1067
+ const segments = decoded[line];
1068
+ const index = traceSegmentInternal(segments, cast$2(map)._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
1069
+ if (index === -1)
1070
+ return OMapping(null, null, null, null);
1071
+ const segment = segments[index];
1072
+ if (segment.length === 1)
1073
+ return OMapping(null, null, null, null);
1074
+ const { names, resolvedSources } = map;
1075
+ return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
1076
+ }
1077
+ /**
1078
+ * Iterates each mapping in generated position order.
1079
+ */
1080
+ function eachMapping(map, cb) {
1081
+ const decoded = decodedMappings(map);
1082
+ const { names, resolvedSources } = map;
1083
+ for (let i = 0; i < decoded.length; i++) {
1084
+ const line = decoded[i];
1085
+ for (let j = 0; j < line.length; j++) {
1086
+ const seg = line[j];
1087
+ const generatedLine = i + 1;
1088
+ const generatedColumn = seg[0];
1089
+ let source = null;
1090
+ let originalLine = null;
1091
+ let originalColumn = null;
1092
+ let name = null;
1093
+ if (seg.length !== 1) {
1094
+ source = resolvedSources[seg[1]];
1095
+ originalLine = seg[2] + 1;
1096
+ originalColumn = seg[3];
1097
+ }
1098
+ if (seg.length === 5)
1099
+ name = names[seg[4]];
1100
+ cb({
1101
+ generatedLine,
1102
+ generatedColumn,
1103
+ source,
1104
+ originalLine,
1105
+ originalColumn,
1106
+ name,
1107
+ });
1108
+ }
1109
+ }
1110
+ }
1111
+ function OMapping(source, line, column, name) {
1112
+ return { source, line, column, name };
1113
+ }
1114
+ function traceSegmentInternal(segments, memo, line, column, bias) {
1115
+ let index = memoizedBinarySearch(segments, column, memo, line);
1116
+ if (found) {
1117
+ index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
1118
+ }
1119
+ else if (bias === LEAST_UPPER_BOUND)
1120
+ index++;
1121
+ if (index === -1 || index === segments.length)
1122
+ return -1;
1123
+ return index;
1124
+ }
1125
+
1126
+ /**
1127
+ * SetArray acts like a `Set` (allowing only one occurrence of a string `key`), but provides the
1128
+ * index of the `key` in the backing array.
1129
+ *
1130
+ * This is designed to allow synchronizing a second array with the contents of the backing array,
1131
+ * like how in a sourcemap `sourcesContent[i]` is the source content associated with `source[i]`,
1132
+ * and there are never duplicates.
1133
+ */
1134
+ class SetArray {
1135
+ constructor() {
1136
+ this._indexes = { __proto__: null };
1137
+ this.array = [];
1138
+ }
1139
+ }
1140
+ /**
1141
+ * Typescript doesn't allow friend access to private fields, so this just casts the set into a type
1142
+ * with public access modifiers.
1143
+ */
1144
+ function cast$1(set) {
1145
+ return set;
1146
+ }
1147
+ /**
1148
+ * Gets the index associated with `key` in the backing array, if it is already present.
1149
+ */
1150
+ function get(setarr, key) {
1151
+ return cast$1(setarr)._indexes[key];
1152
+ }
1153
+ /**
1154
+ * Puts `key` into the backing array, if it is not already present. Returns
1155
+ * the index of the `key` in the backing array.
1156
+ */
1157
+ function put(setarr, key) {
1158
+ // The key may or may not be present. If it is present, it's a number.
1159
+ const index = get(setarr, key);
1160
+ if (index !== undefined)
1161
+ return index;
1162
+ const { array, _indexes: indexes } = cast$1(setarr);
1163
+ const length = array.push(key);
1164
+ return (indexes[key] = length - 1);
1165
+ }
1166
+
1167
+ const COLUMN = 0;
1168
+
1169
+ const NO_NAME = -1;
1170
+ /**
1171
+ * Provides the state to generate a sourcemap.
1172
+ */
1173
+ class GenMapping {
1174
+ constructor({ file, sourceRoot } = {}) {
1175
+ this._names = new SetArray();
1176
+ this._sources = new SetArray();
1177
+ this._sourcesContent = [];
1178
+ this._mappings = [];
1179
+ this.file = file;
1180
+ this.sourceRoot = sourceRoot;
1181
+ this._ignoreList = new SetArray();
1182
+ }
1183
+ }
1184
+ /**
1185
+ * Typescript doesn't allow friend access to private fields, so this just casts the map into a type
1186
+ * with public access modifiers.
1187
+ */
1188
+ function cast(map) {
1189
+ return map;
1190
+ }
1191
+ function addMapping(map, mapping) {
1192
+ return addMappingInternal(false, map, mapping);
1193
+ }
1194
+ /**
1195
+ * Adds/removes the content of the source file to the source map.
1196
+ */
1197
+ function setSourceContent(map, source, content) {
1198
+ const { _sources: sources, _sourcesContent: sourcesContent } = cast(map);
1199
+ const index = put(sources, source);
1200
+ sourcesContent[index] = content;
1201
+ }
1202
+ /**
1203
+ * Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects
1204
+ * a sourcemap, or to JSON.stringify.
1205
+ */
1206
+ function toDecodedMap(map) {
1207
+ const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, _ignoreList: ignoreList, } = cast(map);
1208
+ removeEmptyFinalLines(mappings);
1209
+ return {
1210
+ version: 3,
1211
+ file: map.file || undefined,
1212
+ names: names.array,
1213
+ sourceRoot: map.sourceRoot || undefined,
1214
+ sources: sources.array,
1215
+ sourcesContent,
1216
+ mappings,
1217
+ ignoreList: ignoreList.array,
1218
+ };
1219
+ }
1220
+ /**
1221
+ * Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects
1222
+ * a sourcemap, or to JSON.stringify.
1223
+ */
1224
+ function toEncodedMap(map) {
1225
+ const decoded = toDecodedMap(map);
1226
+ return Object.assign(Object.assign({}, decoded), { mappings: encode(decoded.mappings) });
1227
+ }
1228
+ /**
1229
+ * Constructs a new GenMapping, using the already present mappings of the input.
1230
+ */
1231
+ function fromMap(input) {
1232
+ const map = new TraceMap(input);
1233
+ const gen = new GenMapping({ file: map.file, sourceRoot: map.sourceRoot });
1234
+ putAll(cast(gen)._names, map.names);
1235
+ putAll(cast(gen)._sources, map.sources);
1236
+ cast(gen)._sourcesContent = map.sourcesContent || map.sources.map(() => null);
1237
+ cast(gen)._mappings = decodedMappings(map);
1238
+ if (map.ignoreList)
1239
+ putAll(cast(gen)._ignoreList, map.ignoreList);
1240
+ return gen;
1241
+ }
1242
+ // This split declaration is only so that terser can elminiate the static initialization block.
1243
+ function addSegmentInternal(skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
1244
+ const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, } = cast(map);
1245
+ const line = getLine(mappings, genLine);
1246
+ const index = getColumnIndex(line, genColumn);
1247
+ if (!source) {
1248
+ return insert(line, index, [genColumn]);
1249
+ }
1250
+ const sourcesIndex = put(sources, source);
1251
+ const namesIndex = name ? put(names, name) : NO_NAME;
1252
+ if (sourcesIndex === sourcesContent.length)
1253
+ sourcesContent[sourcesIndex] = content !== null && content !== void 0 ? content : null;
1254
+ return insert(line, index, name
1255
+ ? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex]
1256
+ : [genColumn, sourcesIndex, sourceLine, sourceColumn]);
1257
+ }
1258
+ function getLine(mappings, index) {
1259
+ for (let i = mappings.length; i <= index; i++) {
1260
+ mappings[i] = [];
1261
+ }
1262
+ return mappings[index];
1263
+ }
1264
+ function getColumnIndex(line, genColumn) {
1265
+ let index = line.length;
1266
+ for (let i = index - 1; i >= 0; index = i--) {
1267
+ const current = line[i];
1268
+ if (genColumn >= current[COLUMN])
1269
+ break;
1270
+ }
1271
+ return index;
1272
+ }
1273
+ function insert(array, index, value) {
1274
+ for (let i = array.length; i > index; i--) {
1275
+ array[i] = array[i - 1];
1276
+ }
1277
+ array[index] = value;
1278
+ }
1279
+ function removeEmptyFinalLines(mappings) {
1280
+ const { length } = mappings;
1281
+ let len = length;
1282
+ for (let i = len - 1; i >= 0; len = i, i--) {
1283
+ if (mappings[i].length > 0)
1284
+ break;
1285
+ }
1286
+ if (len < length)
1287
+ mappings.length = len;
1288
+ }
1289
+ function putAll(setarr, array) {
1290
+ for (let i = 0; i < array.length; i++)
1291
+ put(setarr, array[i]);
1292
+ }
1293
+ function addMappingInternal(skipable, map, mapping) {
1294
+ const { generated, source, original, name, content } = mapping;
1295
+ if (!source) {
1296
+ return addSegmentInternal(skipable, map, generated.line - 1, generated.column, null, null, null, null, null);
1297
+ }
1298
+ return addSegmentInternal(skipable, map, generated.line - 1, generated.column, source, original.line - 1, original.column, name, content);
1299
+ }
1300
+
1301
+ function getDefaultExportFromCjs (x) {
1302
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1303
+ }
1304
+
1305
+ var src = {exports: {}};
1306
+
1307
+ var browser = {exports: {}};
1308
+
1309
+ /**
1310
+ * Helpers.
1311
+ */
1312
+
1313
+ var ms;
1314
+ var hasRequiredMs;
1315
+
1316
+ function requireMs () {
1317
+ if (hasRequiredMs) return ms;
1318
+ hasRequiredMs = 1;
1319
+ var s = 1000;
1320
+ var m = s * 60;
1321
+ var h = m * 60;
1322
+ var d = h * 24;
1323
+ var w = d * 7;
1324
+ var y = d * 365.25;
1325
+
1326
+ /**
1327
+ * Parse or format the given `val`.
1328
+ *
1329
+ * Options:
1330
+ *
1331
+ * - `long` verbose formatting [false]
1332
+ *
1333
+ * @param {String|Number} val
1334
+ * @param {Object} [options]
1335
+ * @throws {Error} throw an error if val is not a non-empty string or a number
1336
+ * @return {String|Number}
1337
+ * @api public
1338
+ */
1339
+
1340
+ ms = function (val, options) {
1341
+ options = options || {};
1342
+ var type = typeof val;
1343
+ if (type === 'string' && val.length > 0) {
1344
+ return parse(val);
1345
+ } else if (type === 'number' && isFinite(val)) {
1346
+ return options.long ? fmtLong(val) : fmtShort(val);
1347
+ }
1348
+ throw new Error(
1349
+ 'val is not a non-empty string or a valid number. val=' +
1350
+ JSON.stringify(val)
1351
+ );
1352
+ };
1353
+
1354
+ /**
1355
+ * Parse the given `str` and return milliseconds.
1356
+ *
1357
+ * @param {String} str
1358
+ * @return {Number}
1359
+ * @api private
1360
+ */
1361
+
1362
+ function parse(str) {
1363
+ str = String(str);
1364
+ if (str.length > 100) {
1365
+ return;
1366
+ }
1367
+ 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(
1368
+ str
1369
+ );
1370
+ if (!match) {
1371
+ return;
1372
+ }
1373
+ var n = parseFloat(match[1]);
1374
+ var type = (match[2] || 'ms').toLowerCase();
1375
+ switch (type) {
1376
+ case 'years':
1377
+ case 'year':
1378
+ case 'yrs':
1379
+ case 'yr':
1380
+ case 'y':
1381
+ return n * y;
1382
+ case 'weeks':
1383
+ case 'week':
1384
+ case 'w':
1385
+ return n * w;
1386
+ case 'days':
1387
+ case 'day':
1388
+ case 'd':
1389
+ return n * d;
1390
+ case 'hours':
1391
+ case 'hour':
1392
+ case 'hrs':
1393
+ case 'hr':
1394
+ case 'h':
1395
+ return n * h;
1396
+ case 'minutes':
1397
+ case 'minute':
1398
+ case 'mins':
1399
+ case 'min':
1400
+ case 'm':
1401
+ return n * m;
1402
+ case 'seconds':
1403
+ case 'second':
1404
+ case 'secs':
1405
+ case 'sec':
1406
+ case 's':
1407
+ return n * s;
1408
+ case 'milliseconds':
1409
+ case 'millisecond':
1410
+ case 'msecs':
1411
+ case 'msec':
1412
+ case 'ms':
1413
+ return n;
1414
+ default:
1415
+ return undefined;
1416
+ }
1417
+ }
1418
+
1419
+ /**
1420
+ * Short format for `ms`.
1421
+ *
1422
+ * @param {Number} ms
1423
+ * @return {String}
1424
+ * @api private
1425
+ */
1426
+
1427
+ function fmtShort(ms) {
1428
+ var msAbs = Math.abs(ms);
1429
+ if (msAbs >= d) {
1430
+ return Math.round(ms / d) + 'd';
1431
+ }
1432
+ if (msAbs >= h) {
1433
+ return Math.round(ms / h) + 'h';
1434
+ }
1435
+ if (msAbs >= m) {
1436
+ return Math.round(ms / m) + 'm';
1437
+ }
1438
+ if (msAbs >= s) {
1439
+ return Math.round(ms / s) + 's';
1440
+ }
1441
+ return ms + 'ms';
1442
+ }
1443
+
1444
+ /**
1445
+ * Long format for `ms`.
1446
+ *
1447
+ * @param {Number} ms
1448
+ * @return {String}
1449
+ * @api private
1450
+ */
1451
+
1452
+ function fmtLong(ms) {
1453
+ var msAbs = Math.abs(ms);
1454
+ if (msAbs >= d) {
1455
+ return plural(ms, msAbs, d, 'day');
1456
+ }
1457
+ if (msAbs >= h) {
1458
+ return plural(ms, msAbs, h, 'hour');
1459
+ }
1460
+ if (msAbs >= m) {
1461
+ return plural(ms, msAbs, m, 'minute');
1462
+ }
1463
+ if (msAbs >= s) {
1464
+ return plural(ms, msAbs, s, 'second');
1465
+ }
1466
+ return ms + ' ms';
1467
+ }
1468
+
1469
+ /**
1470
+ * Pluralization helper.
1471
+ */
1472
+
1473
+ function plural(ms, msAbs, n, name) {
1474
+ var isPlural = msAbs >= n * 1.5;
1475
+ return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
1476
+ }
1477
+ return ms;
1478
+ }
1479
+
1480
+ var common;
1481
+ var hasRequiredCommon;
1482
+
1483
+ function requireCommon () {
1484
+ if (hasRequiredCommon) return common;
1485
+ hasRequiredCommon = 1;
1486
+ /**
1487
+ * This is the common logic for both the Node.js and web browser
1488
+ * implementations of `debug()`.
1489
+ */
1490
+
1491
+ function setup(env) {
1492
+ createDebug.debug = createDebug;
1493
+ createDebug.default = createDebug;
1494
+ createDebug.coerce = coerce;
1495
+ createDebug.disable = disable;
1496
+ createDebug.enable = enable;
1497
+ createDebug.enabled = enabled;
1498
+ createDebug.humanize = requireMs();
1499
+ createDebug.destroy = destroy;
1500
+
1501
+ Object.keys(env).forEach(key => {
1502
+ createDebug[key] = env[key];
1503
+ });
1504
+
1505
+ /**
1506
+ * The currently active debug mode names, and names to skip.
1507
+ */
1508
+
1509
+ createDebug.names = [];
1510
+ createDebug.skips = [];
1511
+
1512
+ /**
1513
+ * Map of special "%n" handling functions, for the debug "format" argument.
1514
+ *
1515
+ * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
1516
+ */
1517
+ createDebug.formatters = {};
1518
+
1519
+ /**
1520
+ * Selects a color for a debug namespace
1521
+ * @param {String} namespace The namespace string for the debug instance to be colored
1522
+ * @return {Number|String} An ANSI color code for the given namespace
1523
+ * @api private
1524
+ */
1525
+ function selectColor(namespace) {
1526
+ let hash = 0;
1527
+
1528
+ for (let i = 0; i < namespace.length; i++) {
1529
+ hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
1530
+ hash |= 0; // Convert to 32bit integer
1531
+ }
1532
+
1533
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
1534
+ }
1535
+ createDebug.selectColor = selectColor;
1536
+
1537
+ /**
1538
+ * Create a debugger with the given `namespace`.
1539
+ *
1540
+ * @param {String} namespace
1541
+ * @return {Function}
1542
+ * @api public
1543
+ */
1544
+ function createDebug(namespace) {
1545
+ let prevTime;
1546
+ let enableOverride = null;
1547
+ let namespacesCache;
1548
+ let enabledCache;
1549
+
1550
+ function debug(...args) {
1551
+ // Disabled?
1552
+ if (!debug.enabled) {
1553
+ return;
1554
+ }
1555
+
1556
+ const self = debug;
1557
+
1558
+ // Set `diff` timestamp
1559
+ const curr = Number(new Date());
1560
+ const ms = curr - (prevTime || curr);
1561
+ self.diff = ms;
1562
+ self.prev = prevTime;
1563
+ self.curr = curr;
1564
+ prevTime = curr;
1565
+
1566
+ args[0] = createDebug.coerce(args[0]);
1567
+
1568
+ if (typeof args[0] !== 'string') {
1569
+ // Anything else let's inspect with %O
1570
+ args.unshift('%O');
1571
+ }
1572
+
1573
+ // Apply any `formatters` transformations
1574
+ let index = 0;
1575
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
1576
+ // If we encounter an escaped % then don't increase the array index
1577
+ if (match === '%%') {
1578
+ return '%';
1579
+ }
1580
+ index++;
1581
+ const formatter = createDebug.formatters[format];
1582
+ if (typeof formatter === 'function') {
1583
+ const val = args[index];
1584
+ match = formatter.call(self, val);
1585
+
1586
+ // Now we need to remove `args[index]` since it's inlined in the `format`
1587
+ args.splice(index, 1);
1588
+ index--;
1589
+ }
1590
+ return match;
1591
+ });
1592
+
1593
+ // Apply env-specific formatting (colors, etc.)
1594
+ createDebug.formatArgs.call(self, args);
1595
+
1596
+ const logFn = self.log || createDebug.log;
1597
+ logFn.apply(self, args);
1598
+ }
1599
+
1600
+ debug.namespace = namespace;
1601
+ debug.useColors = createDebug.useColors();
1602
+ debug.color = createDebug.selectColor(namespace);
1603
+ debug.extend = extend;
1604
+ debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
1605
+
1606
+ Object.defineProperty(debug, 'enabled', {
1607
+ enumerable: true,
1608
+ configurable: false,
1609
+ get: () => {
1610
+ if (enableOverride !== null) {
1611
+ return enableOverride;
1612
+ }
1613
+ if (namespacesCache !== createDebug.namespaces) {
1614
+ namespacesCache = createDebug.namespaces;
1615
+ enabledCache = createDebug.enabled(namespace);
1616
+ }
1617
+
1618
+ return enabledCache;
1619
+ },
1620
+ set: v => {
1621
+ enableOverride = v;
1622
+ }
1623
+ });
1624
+
1625
+ // Env-specific initialization logic for debug instances
1626
+ if (typeof createDebug.init === 'function') {
1627
+ createDebug.init(debug);
1628
+ }
1629
+
1630
+ return debug;
1631
+ }
1632
+
1633
+ function extend(namespace, delimiter) {
1634
+ const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
1635
+ newDebug.log = this.log;
1636
+ return newDebug;
1637
+ }
1638
+
1639
+ /**
1640
+ * Enables a debug mode by namespaces. This can include modes
1641
+ * separated by a colon and wildcards.
1642
+ *
1643
+ * @param {String} namespaces
1644
+ * @api public
1645
+ */
1646
+ function enable(namespaces) {
1647
+ createDebug.save(namespaces);
1648
+ createDebug.namespaces = namespaces;
1649
+
1650
+ createDebug.names = [];
1651
+ createDebug.skips = [];
1652
+
1653
+ const split = (typeof namespaces === 'string' ? namespaces : '')
1654
+ .trim()
1655
+ .replace(' ', ',')
1656
+ .split(',')
1657
+ .filter(Boolean);
1658
+
1659
+ for (const ns of split) {
1660
+ if (ns[0] === '-') {
1661
+ createDebug.skips.push(ns.slice(1));
1662
+ } else {
1663
+ createDebug.names.push(ns);
1664
+ }
1665
+ }
1666
+ }
1667
+
1668
+ /**
1669
+ * Checks if the given string matches a namespace template, honoring
1670
+ * asterisks as wildcards.
1671
+ *
1672
+ * @param {String} search
1673
+ * @param {String} template
1674
+ * @return {Boolean}
1675
+ */
1676
+ function matchesTemplate(search, template) {
1677
+ let searchIndex = 0;
1678
+ let templateIndex = 0;
1679
+ let starIndex = -1;
1680
+ let matchIndex = 0;
1681
+
1682
+ while (searchIndex < search.length) {
1683
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
1684
+ // Match character or proceed with wildcard
1685
+ if (template[templateIndex] === '*') {
1686
+ starIndex = templateIndex;
1687
+ matchIndex = searchIndex;
1688
+ templateIndex++; // Skip the '*'
1689
+ } else {
1690
+ searchIndex++;
1691
+ templateIndex++;
1692
+ }
1693
+ } else if (starIndex !== -1) { // eslint-disable-line no-negated-condition
1694
+ // Backtrack to the last '*' and try to match more characters
1695
+ templateIndex = starIndex + 1;
1696
+ matchIndex++;
1697
+ searchIndex = matchIndex;
1698
+ } else {
1699
+ return false; // No match
1700
+ }
1701
+ }
1702
+
1703
+ // Handle trailing '*' in template
1704
+ while (templateIndex < template.length && template[templateIndex] === '*') {
1705
+ templateIndex++;
1706
+ }
1707
+
1708
+ return templateIndex === template.length;
1709
+ }
1710
+
1711
+ /**
1712
+ * Disable debug output.
1713
+ *
1714
+ * @return {String} namespaces
1715
+ * @api public
1716
+ */
1717
+ function disable() {
1718
+ const namespaces = [
1719
+ ...createDebug.names,
1720
+ ...createDebug.skips.map(namespace => '-' + namespace)
1721
+ ].join(',');
1722
+ createDebug.enable('');
1723
+ return namespaces;
1724
+ }
1725
+
1726
+ /**
1727
+ * Returns true if the given mode name is enabled, false otherwise.
1728
+ *
1729
+ * @param {String} name
1730
+ * @return {Boolean}
1731
+ * @api public
1732
+ */
1733
+ function enabled(name) {
1734
+ for (const skip of createDebug.skips) {
1735
+ if (matchesTemplate(name, skip)) {
1736
+ return false;
1737
+ }
1738
+ }
1739
+
1740
+ for (const ns of createDebug.names) {
1741
+ if (matchesTemplate(name, ns)) {
1742
+ return true;
1743
+ }
1744
+ }
1745
+
1746
+ return false;
1747
+ }
1748
+
1749
+ /**
1750
+ * Coerce `val`.
1751
+ *
1752
+ * @param {Mixed} val
1753
+ * @return {Mixed}
1754
+ * @api private
1755
+ */
1756
+ function coerce(val) {
1757
+ if (val instanceof Error) {
1758
+ return val.stack || val.message;
1759
+ }
1760
+ return val;
1761
+ }
1762
+
1763
+ /**
1764
+ * XXX DO NOT USE. This is a temporary stub function.
1765
+ * XXX It WILL be removed in the next major release.
1766
+ */
1767
+ function destroy() {
1768
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
1769
+ }
1770
+
1771
+ createDebug.enable(createDebug.load());
1772
+
1773
+ return createDebug;
1774
+ }
1775
+
1776
+ common = setup;
1777
+ return common;
1778
+ }
1779
+
1780
+ /* eslint-env browser */
1781
+
1782
+ var hasRequiredBrowser;
1783
+
1784
+ function requireBrowser () {
1785
+ if (hasRequiredBrowser) return browser.exports;
1786
+ hasRequiredBrowser = 1;
1787
+ (function (module, exports) {
1788
+ /**
1789
+ * This is the web browser implementation of `debug()`.
1790
+ */
1791
+
1792
+ exports.formatArgs = formatArgs;
1793
+ exports.save = save;
1794
+ exports.load = load;
1795
+ exports.useColors = useColors;
1796
+ exports.storage = localstorage();
1797
+ exports.destroy = (() => {
1798
+ let warned = false;
1799
+
1800
+ return () => {
1801
+ if (!warned) {
1802
+ warned = true;
1803
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
1804
+ }
1805
+ };
1806
+ })();
1807
+
1808
+ /**
1809
+ * Colors.
1810
+ */
1811
+
1812
+ exports.colors = [
1813
+ '#0000CC',
1814
+ '#0000FF',
1815
+ '#0033CC',
1816
+ '#0033FF',
1817
+ '#0066CC',
1818
+ '#0066FF',
1819
+ '#0099CC',
1820
+ '#0099FF',
1821
+ '#00CC00',
1822
+ '#00CC33',
1823
+ '#00CC66',
1824
+ '#00CC99',
1825
+ '#00CCCC',
1826
+ '#00CCFF',
1827
+ '#3300CC',
1828
+ '#3300FF',
1829
+ '#3333CC',
1830
+ '#3333FF',
1831
+ '#3366CC',
1832
+ '#3366FF',
1833
+ '#3399CC',
1834
+ '#3399FF',
1835
+ '#33CC00',
1836
+ '#33CC33',
1837
+ '#33CC66',
1838
+ '#33CC99',
1839
+ '#33CCCC',
1840
+ '#33CCFF',
1841
+ '#6600CC',
1842
+ '#6600FF',
1843
+ '#6633CC',
1844
+ '#6633FF',
1845
+ '#66CC00',
1846
+ '#66CC33',
1847
+ '#9900CC',
1848
+ '#9900FF',
1849
+ '#9933CC',
1850
+ '#9933FF',
1851
+ '#99CC00',
1852
+ '#99CC33',
1853
+ '#CC0000',
1854
+ '#CC0033',
1855
+ '#CC0066',
1856
+ '#CC0099',
1857
+ '#CC00CC',
1858
+ '#CC00FF',
1859
+ '#CC3300',
1860
+ '#CC3333',
1861
+ '#CC3366',
1862
+ '#CC3399',
1863
+ '#CC33CC',
1864
+ '#CC33FF',
1865
+ '#CC6600',
1866
+ '#CC6633',
1867
+ '#CC9900',
1868
+ '#CC9933',
1869
+ '#CCCC00',
1870
+ '#CCCC33',
1871
+ '#FF0000',
1872
+ '#FF0033',
1873
+ '#FF0066',
1874
+ '#FF0099',
1875
+ '#FF00CC',
1876
+ '#FF00FF',
1877
+ '#FF3300',
1878
+ '#FF3333',
1879
+ '#FF3366',
1880
+ '#FF3399',
1881
+ '#FF33CC',
1882
+ '#FF33FF',
1883
+ '#FF6600',
1884
+ '#FF6633',
1885
+ '#FF9900',
1886
+ '#FF9933',
1887
+ '#FFCC00',
1888
+ '#FFCC33'
1889
+ ];
1890
+
1891
+ /**
1892
+ * Currently only WebKit-based Web Inspectors, Firefox >= v31,
1893
+ * and the Firebug extension (any Firefox version) are known
1894
+ * to support "%c" CSS customizations.
1895
+ *
1896
+ * TODO: add a `localStorage` variable to explicitly enable/disable colors
1897
+ */
1898
+
1899
+ // eslint-disable-next-line complexity
1900
+ function useColors() {
1901
+ // NB: In an Electron preload script, document will be defined but not fully
1902
+ // initialized. Since we know we're in Chrome, we'll just detect this case
1903
+ // explicitly
1904
+ if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
1905
+ return true;
1906
+ }
1907
+
1908
+ // Internet Explorer and Edge do not support colors.
1909
+ if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
1910
+ return false;
1911
+ }
1912
+
1913
+ let m;
1914
+
1915
+ // Is webkit? http://stackoverflow.com/a/16459606/376773
1916
+ // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
1917
+ // eslint-disable-next-line no-return-assign
1918
+ return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
1919
+ // Is firebug? http://stackoverflow.com/a/398120/376773
1920
+ (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
1921
+ // Is firefox >= v31?
1922
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
1923
+ (typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
1924
+ // Double check webkit in userAgent just in case we are in a worker
1925
+ (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
1926
+ }
1927
+
1928
+ /**
1929
+ * Colorize log arguments if enabled.
1930
+ *
1931
+ * @api public
1932
+ */
1933
+
1934
+ function formatArgs(args) {
1935
+ args[0] = (this.useColors ? '%c' : '') +
1936
+ this.namespace +
1937
+ (this.useColors ? ' %c' : ' ') +
1938
+ args[0] +
1939
+ (this.useColors ? '%c ' : ' ') +
1940
+ '+' + module.exports.humanize(this.diff);
1941
+
1942
+ if (!this.useColors) {
1943
+ return;
1944
+ }
1945
+
1946
+ const c = 'color: ' + this.color;
1947
+ args.splice(1, 0, c, 'color: inherit');
1948
+
1949
+ // The final "%c" is somewhat tricky, because there could be other
1950
+ // arguments passed either before or after the %c, so we need to
1951
+ // figure out the correct index to insert the CSS into
1952
+ let index = 0;
1953
+ let lastC = 0;
1954
+ args[0].replace(/%[a-zA-Z%]/g, match => {
1955
+ if (match === '%%') {
1956
+ return;
1957
+ }
1958
+ index++;
1959
+ if (match === '%c') {
1960
+ // We only are interested in the *last* %c
1961
+ // (the user may have provided their own)
1962
+ lastC = index;
1963
+ }
1964
+ });
1965
+
1966
+ args.splice(lastC, 0, c);
1967
+ }
1968
+
1969
+ /**
1970
+ * Invokes `console.debug()` when available.
1971
+ * No-op when `console.debug` is not a "function".
1972
+ * If `console.debug` is not available, falls back
1973
+ * to `console.log`.
1974
+ *
1975
+ * @api public
1976
+ */
1977
+ exports.log = console.debug || console.log || (() => {});
1978
+
1979
+ /**
1980
+ * Save `namespaces`.
1981
+ *
1982
+ * @param {String} namespaces
1983
+ * @api private
1984
+ */
1985
+ function save(namespaces) {
1986
+ try {
1987
+ if (namespaces) {
1988
+ exports.storage.setItem('debug', namespaces);
1989
+ } else {
1990
+ exports.storage.removeItem('debug');
1991
+ }
1992
+ } catch (error) {
1993
+ // Swallow
1994
+ // XXX (@Qix-) should we be logging these?
1995
+ }
1996
+ }
1997
+
1998
+ /**
1999
+ * Load `namespaces`.
2000
+ *
2001
+ * @return {String} returns the previously persisted debug modes
2002
+ * @api private
2003
+ */
2004
+ function load() {
2005
+ let r;
2006
+ try {
2007
+ r = exports.storage.getItem('debug');
2008
+ } catch (error) {
2009
+ // Swallow
2010
+ // XXX (@Qix-) should we be logging these?
2011
+ }
2012
+
2013
+ // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
2014
+ if (!r && typeof process !== 'undefined' && 'env' in process) {
2015
+ r = process.env.DEBUG;
2016
+ }
2017
+
2018
+ return r;
2019
+ }
2020
+
2021
+ /**
2022
+ * Localstorage attempts to return the localstorage.
2023
+ *
2024
+ * This is necessary because safari throws
2025
+ * when a user disables cookies/localstorage
2026
+ * and you attempt to access it.
2027
+ *
2028
+ * @return {LocalStorage}
2029
+ * @api private
2030
+ */
2031
+
2032
+ function localstorage() {
2033
+ try {
2034
+ // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
2035
+ // The Browser also has localStorage in the global context.
2036
+ return localStorage;
2037
+ } catch (error) {
2038
+ // Swallow
2039
+ // XXX (@Qix-) should we be logging these?
2040
+ }
2041
+ }
2042
+
2043
+ module.exports = requireCommon()(exports);
2044
+
2045
+ const {formatters} = module.exports;
2046
+
2047
+ /**
2048
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
2049
+ */
2050
+
2051
+ formatters.j = function (v) {
2052
+ try {
2053
+ return JSON.stringify(v);
2054
+ } catch (error) {
2055
+ return '[UnexpectedJSONParseError]: ' + error.message;
2056
+ }
2057
+ };
2058
+ } (browser, browser.exports));
2059
+ return browser.exports;
2060
+ }
2061
+
2062
+ var node = {exports: {}};
2063
+
2064
+ /**
2065
+ * Module dependencies.
2066
+ */
2067
+
2068
+ var hasRequiredNode;
2069
+
2070
+ function requireNode () {
2071
+ if (hasRequiredNode) return node.exports;
2072
+ hasRequiredNode = 1;
2073
+ (function (module, exports) {
2074
+ const tty = require$$0;
2075
+ const util = require$$1;
2076
+
2077
+ /**
2078
+ * This is the Node.js implementation of `debug()`.
2079
+ */
2080
+
2081
+ exports.init = init;
2082
+ exports.log = log;
2083
+ exports.formatArgs = formatArgs;
2084
+ exports.save = save;
2085
+ exports.load = load;
2086
+ exports.useColors = useColors;
2087
+ exports.destroy = util.deprecate(
2088
+ () => {},
2089
+ 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
2090
+ );
2091
+
2092
+ /**
2093
+ * Colors.
2094
+ */
2095
+
2096
+ exports.colors = [6, 2, 3, 4, 5, 1];
2097
+
2098
+ try {
2099
+ // Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
2100
+ // eslint-disable-next-line import/no-extraneous-dependencies
2101
+ const supportsColor = require('supports-color');
2102
+
2103
+ if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
2104
+ exports.colors = [
2105
+ 20,
2106
+ 21,
2107
+ 26,
2108
+ 27,
2109
+ 32,
2110
+ 33,
2111
+ 38,
2112
+ 39,
2113
+ 40,
2114
+ 41,
2115
+ 42,
2116
+ 43,
2117
+ 44,
2118
+ 45,
2119
+ 56,
2120
+ 57,
2121
+ 62,
2122
+ 63,
2123
+ 68,
2124
+ 69,
2125
+ 74,
2126
+ 75,
2127
+ 76,
2128
+ 77,
2129
+ 78,
2130
+ 79,
2131
+ 80,
2132
+ 81,
2133
+ 92,
2134
+ 93,
2135
+ 98,
2136
+ 99,
2137
+ 112,
2138
+ 113,
2139
+ 128,
2140
+ 129,
2141
+ 134,
2142
+ 135,
2143
+ 148,
2144
+ 149,
2145
+ 160,
2146
+ 161,
2147
+ 162,
2148
+ 163,
2149
+ 164,
2150
+ 165,
2151
+ 166,
2152
+ 167,
2153
+ 168,
2154
+ 169,
2155
+ 170,
2156
+ 171,
2157
+ 172,
2158
+ 173,
2159
+ 178,
2160
+ 179,
2161
+ 184,
2162
+ 185,
2163
+ 196,
2164
+ 197,
2165
+ 198,
2166
+ 199,
2167
+ 200,
2168
+ 201,
2169
+ 202,
2170
+ 203,
2171
+ 204,
2172
+ 205,
2173
+ 206,
2174
+ 207,
2175
+ 208,
2176
+ 209,
2177
+ 214,
2178
+ 215,
2179
+ 220,
2180
+ 221
2181
+ ];
2182
+ }
2183
+ } catch (error) {
2184
+ // Swallow - we only care if `supports-color` is available; it doesn't have to be.
2185
+ }
2186
+
2187
+ /**
2188
+ * Build up the default `inspectOpts` object from the environment variables.
2189
+ *
2190
+ * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
2191
+ */
2192
+
2193
+ exports.inspectOpts = Object.keys(process.env).filter(key => {
2194
+ return /^debug_/i.test(key);
2195
+ }).reduce((obj, key) => {
2196
+ // Camel-case
2197
+ const prop = key
2198
+ .substring(6)
2199
+ .toLowerCase()
2200
+ .replace(/_([a-z])/g, (_, k) => {
2201
+ return k.toUpperCase();
2202
+ });
2203
+
2204
+ // Coerce string value into JS value
2205
+ let val = process.env[key];
2206
+ if (/^(yes|on|true|enabled)$/i.test(val)) {
2207
+ val = true;
2208
+ } else if (/^(no|off|false|disabled)$/i.test(val)) {
2209
+ val = false;
2210
+ } else if (val === 'null') {
2211
+ val = null;
2212
+ } else {
2213
+ val = Number(val);
2214
+ }
2215
+
2216
+ obj[prop] = val;
2217
+ return obj;
2218
+ }, {});
2219
+
2220
+ /**
2221
+ * Is stdout a TTY? Colored output is enabled when `true`.
2222
+ */
2223
+
2224
+ function useColors() {
2225
+ return 'colors' in exports.inspectOpts ?
2226
+ Boolean(exports.inspectOpts.colors) :
2227
+ tty.isatty(process.stderr.fd);
2228
+ }
2229
+
2230
+ /**
2231
+ * Adds ANSI color escape codes if enabled.
2232
+ *
2233
+ * @api public
2234
+ */
2235
+
2236
+ function formatArgs(args) {
2237
+ const {namespace: name, useColors} = this;
2238
+
2239
+ if (useColors) {
2240
+ const c = this.color;
2241
+ const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
2242
+ const prefix = ` ${colorCode};1m${name} \u001B[0m`;
2243
+
2244
+ args[0] = prefix + args[0].split('\n').join('\n' + prefix);
2245
+ args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
2246
+ } else {
2247
+ args[0] = getDate() + name + ' ' + args[0];
2248
+ }
2249
+ }
2250
+
2251
+ function getDate() {
2252
+ if (exports.inspectOpts.hideDate) {
2253
+ return '';
2254
+ }
2255
+ return new Date().toISOString() + ' ';
2256
+ }
2257
+
2258
+ /**
2259
+ * Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr.
2260
+ */
2261
+
2262
+ function log(...args) {
2263
+ return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + '\n');
2264
+ }
2265
+
2266
+ /**
2267
+ * Save `namespaces`.
2268
+ *
2269
+ * @param {String} namespaces
2270
+ * @api private
2271
+ */
2272
+ function save(namespaces) {
2273
+ if (namespaces) {
2274
+ process.env.DEBUG = namespaces;
2275
+ } else {
2276
+ // If you set a process.env field to null or undefined, it gets cast to the
2277
+ // string 'null' or 'undefined'. Just delete instead.
2278
+ delete process.env.DEBUG;
2279
+ }
2280
+ }
2281
+
2282
+ /**
2283
+ * Load `namespaces`.
2284
+ *
2285
+ * @return {String} returns the previously persisted debug modes
2286
+ * @api private
2287
+ */
2288
+
2289
+ function load() {
2290
+ return process.env.DEBUG;
2291
+ }
2292
+
2293
+ /**
2294
+ * Init logic for `debug` instances.
2295
+ *
2296
+ * Create a new `inspectOpts` object in case `useColors` is set
2297
+ * differently for a particular `debug` instance.
2298
+ */
2299
+
2300
+ function init(debug) {
2301
+ debug.inspectOpts = {};
2302
+
2303
+ const keys = Object.keys(exports.inspectOpts);
2304
+ for (let i = 0; i < keys.length; i++) {
2305
+ debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
2306
+ }
2307
+ }
2308
+
2309
+ module.exports = requireCommon()(exports);
2310
+
2311
+ const {formatters} = module.exports;
2312
+
2313
+ /**
2314
+ * Map %o to `util.inspect()`, all on a single line.
2315
+ */
2316
+
2317
+ formatters.o = function (v) {
2318
+ this.inspectOpts.colors = this.useColors;
2319
+ return util.inspect(v, this.inspectOpts)
2320
+ .split('\n')
2321
+ .map(str => str.trim())
2322
+ .join(' ');
2323
+ };
2324
+
2325
+ /**
2326
+ * Map %O to `util.inspect()`, allowing multiple lines if needed.
2327
+ */
2328
+
2329
+ formatters.O = function (v) {
2330
+ this.inspectOpts.colors = this.useColors;
2331
+ return util.inspect(v, this.inspectOpts);
2332
+ };
2333
+ } (node, node.exports));
2334
+ return node.exports;
2335
+ }
2336
+
2337
+ /**
2338
+ * Detect Electron renderer / nwjs process, which is node, but we should
2339
+ * treat as a browser.
2340
+ */
2341
+
2342
+ var hasRequiredSrc;
2343
+
2344
+ function requireSrc () {
2345
+ if (hasRequiredSrc) return src.exports;
2346
+ hasRequiredSrc = 1;
2347
+ if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
2348
+ src.exports = requireBrowser();
2349
+ } else {
2350
+ src.exports = requireNode();
2351
+ }
2352
+ return src.exports;
2353
+ }
2354
+
2355
+ var srcExports = requireSrc();
2356
+ const _debug = /*@__PURE__*/getDefaultExportFromCjs(srcExports);
2357
+
2358
+ const debug = _debug("vite:hmr");
2359
+ const directRequestRE = /(?:\?|&)direct\b/;
2360
+ async function handleHotUpdate({ file, modules, read }, options, customElement, typeDepModules) {
2361
+ const prevDescriptor = getDescriptor(file, options, false, true);
2362
+ if (!prevDescriptor) {
2363
+ return;
2364
+ }
2365
+ const content = await read();
2366
+ const { descriptor } = createDescriptor(file, content, options, true);
2367
+ let needRerender = false;
2368
+ const affectedModules = /* @__PURE__ */ new Set();
2369
+ const mainModule = getMainModule(modules);
2370
+ const templateModule = modules.find((m) => /type=template/.test(m.url));
2371
+ resolveScript(false, descriptor, options, false, customElement);
2372
+ const scriptChanged = hasScriptChanged(prevDescriptor, descriptor);
2373
+ if (scriptChanged) {
2374
+ affectedModules.add(getScriptModule(modules) || mainModule);
2375
+ }
2376
+ if (!isEqualBlock(descriptor.template, prevDescriptor.template)) {
2377
+ if (!scriptChanged) {
2378
+ setResolvedScript(
2379
+ descriptor,
2380
+ getResolvedScript(prevDescriptor, false),
2381
+ false
2382
+ );
2383
+ }
2384
+ affectedModules.add(templateModule);
2385
+ needRerender = true;
2386
+ }
2387
+ let didUpdateStyle = false;
2388
+ const prevStyles = prevDescriptor.styles || [];
2389
+ const nextStyles = descriptor.styles || [];
2390
+ if (prevDescriptor.cssVars.join("") !== descriptor.cssVars.join("")) {
2391
+ affectedModules.add(mainModule);
2392
+ }
2393
+ if (prevStyles.some((s) => s.scoped) !== nextStyles.some((s) => s.scoped)) {
2394
+ affectedModules.add(templateModule);
2395
+ affectedModules.add(mainModule);
2396
+ }
2397
+ for (let i = 0; i < nextStyles.length; i++) {
2398
+ const prev = prevStyles[i];
2399
+ const next = nextStyles[i];
2400
+ if (!prev || !isEqualBlock(prev, next)) {
2401
+ didUpdateStyle = true;
2402
+ const mod = modules.find(
2403
+ (m) => m.url.includes(`type=style&index=${i}`) && m.url.endsWith(`.${next.lang || "css"}`) && !directRequestRE.test(m.url)
2404
+ );
2405
+ if (mod) {
2406
+ affectedModules.add(mod);
2407
+ if (mod.url.includes("&inline")) {
2408
+ affectedModules.add(mainModule);
2409
+ }
2410
+ } else {
2411
+ affectedModules.add(mainModule);
2412
+ }
2413
+ }
2414
+ }
2415
+ if (prevStyles.length > nextStyles.length) {
2416
+ affectedModules.add(mainModule);
2417
+ }
2418
+ const prevCustoms = prevDescriptor.customBlocks || [];
2419
+ const nextCustoms = descriptor.customBlocks || [];
2420
+ if (prevCustoms.length !== nextCustoms.length) {
2421
+ affectedModules.add(mainModule);
2422
+ } else {
2423
+ for (let i = 0; i < nextCustoms.length; i++) {
2424
+ const prev = prevCustoms[i];
2425
+ const next = nextCustoms[i];
2426
+ if (!prev || !isEqualBlock(prev, next)) {
2427
+ const mod = modules.find(
2428
+ (m) => m.url.includes(`type=${prev.type}&index=${i}`)
2429
+ );
2430
+ if (mod) {
2431
+ affectedModules.add(mod);
2432
+ } else {
2433
+ affectedModules.add(mainModule);
2434
+ }
2435
+ }
2436
+ }
2437
+ }
2438
+ const updateType = [];
2439
+ if (needRerender) {
2440
+ updateType.push(`template`);
2441
+ if (!templateModule) {
2442
+ affectedModules.add(mainModule);
2443
+ } else if (mainModule && !affectedModules.has(mainModule)) {
2444
+ const styleImporters = [...mainModule.importers].filter(
2445
+ (m) => isCSSRequest(m.url)
2446
+ );
2447
+ styleImporters.forEach((m) => affectedModules.add(m));
2448
+ }
2449
+ }
2450
+ if (didUpdateStyle) {
2451
+ updateType.push(`style`);
2452
+ }
2453
+ if (updateType.length) {
2454
+ if (file.endsWith(".vue")) {
2455
+ invalidateDescriptor(file);
2456
+ } else {
2457
+ cache.set(file, descriptor);
2458
+ }
2459
+ debug(`[vue:update(${updateType.join("&")})] ${file}`);
2460
+ }
2461
+ return [...affectedModules, ...typeDepModules || []].filter(
2462
+ Boolean
2463
+ );
2464
+ }
2465
+ function isEqualBlock(a, b) {
2466
+ if (!a && !b) return true;
2467
+ if (!a || !b) return false;
2468
+ if (a.src && b.src && a.src === b.src) return true;
2469
+ if (a.content !== b.content) return false;
2470
+ const keysA = Object.keys(a.attrs);
2471
+ const keysB = Object.keys(b.attrs);
2472
+ if (keysA.length !== keysB.length) {
2473
+ return false;
2474
+ }
2475
+ return keysA.every((key) => a.attrs[key] === b.attrs[key]);
2476
+ }
2477
+ function isOnlyTemplateChanged(prev, next) {
2478
+ 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]));
2479
+ }
2480
+ function deepEqual(obj1, obj2, excludeProps = [], deepParentsOfObj1 = []) {
2481
+ if (typeof obj1 !== typeof obj2) {
2482
+ return false;
2483
+ }
2484
+ if (obj1 == null || obj2 == null || typeof obj1 !== "object" || deepParentsOfObj1.includes(obj1)) {
2485
+ return obj1 === obj2;
2486
+ }
2487
+ const keys1 = Object.keys(obj1);
2488
+ const keys2 = Object.keys(obj2);
2489
+ if (keys1.length !== keys2.length) {
2490
+ return false;
2491
+ }
2492
+ for (const key of keys1) {
2493
+ if (excludeProps.includes(key)) {
2494
+ continue;
2495
+ }
2496
+ if (!deepEqual(obj1[key], obj2[key], excludeProps, [
2497
+ ...deepParentsOfObj1,
2498
+ obj1
2499
+ ])) {
2500
+ return false;
2501
+ }
2502
+ }
2503
+ return true;
2504
+ }
2505
+ function isEqualAst(prev, next) {
2506
+ if (typeof prev === "undefined" || typeof next === "undefined") {
2507
+ return prev === next;
2508
+ }
2509
+ if (prev.length !== next.length) {
2510
+ return false;
2511
+ }
2512
+ for (let i = 0; i < prev.length; i++) {
2513
+ const prevNode = prev[i];
2514
+ const nextNode = next[i];
2515
+ if (
2516
+ // deep equal, but ignore start/end/loc/range/leadingComments/trailingComments/innerComments
2517
+ !deepEqual(prevNode, nextNode, [
2518
+ "start",
2519
+ "end",
2520
+ "loc",
2521
+ "range",
2522
+ "leadingComments",
2523
+ "trailingComments",
2524
+ "innerComments",
2525
+ // https://github.com/vuejs/core/issues/11923
2526
+ // avoid comparing the following properties of typeParameters
2527
+ // as it may be imported from 3rd lib and complex to compare
2528
+ "_ownerScope",
2529
+ "_resolvedReference",
2530
+ "_resolvedElements"
2531
+ ])
2532
+ ) {
2533
+ return false;
2534
+ }
2535
+ }
2536
+ return true;
2537
+ }
2538
+ function hasScriptChanged(prev, next) {
2539
+ const prevScript = getResolvedScript(prev, false);
2540
+ const nextScript = getResolvedScript(next, false);
2541
+ if (!isEqualBlock(prev.script, next.script) && !isEqualAst(prevScript?.scriptAst, nextScript?.scriptAst)) {
2542
+ return true;
2543
+ }
2544
+ if (!isEqualBlock(prev.scriptSetup, next.scriptSetup) && !isEqualAst(prevScript?.scriptSetupAst, nextScript?.scriptSetupAst)) {
2545
+ return true;
2546
+ }
2547
+ const prevResolvedScript = getResolvedScript(prev, false);
2548
+ const prevImports = prevResolvedScript?.imports;
2549
+ if (prevImports) {
2550
+ return !next.template || next.shouldForceReload(prevImports);
2551
+ }
2552
+ return false;
2553
+ }
2554
+ function getMainModule(modules) {
2555
+ return modules.filter((m) => !/type=/.test(m.url) || /type=script/.test(m.url)).sort((m1, m2) => {
2556
+ return m1.url.length - m2.url.length;
2557
+ })[0];
2558
+ }
2559
+ function getScriptModule(modules) {
2560
+ return modules.find((m) => /type=script.*&lang\.\w+$/.test(m.url));
2561
+ }
2562
+ function handleTypeDepChange(affectedComponents, { modules, server: { moduleGraph } }) {
2563
+ const affected = /* @__PURE__ */ new Set();
2564
+ for (const file of affectedComponents) {
2565
+ invalidateScript(file);
2566
+ const mods = moduleGraph.getModulesByFile(file);
2567
+ if (mods) {
2568
+ const arr = [...mods];
2569
+ affected.add(getScriptModule(arr) || getMainModule(arr));
2570
+ }
2571
+ }
2572
+ return [...modules, ...affected];
2573
+ }
2574
+
2575
+ const EXPORT_HELPER_ID = "\0plugin-vue:export-helper";
2576
+ const helperCode = `
2577
+ export default (sfc, props) => {
2578
+ const target = sfc.__vccOpts || sfc;
2579
+ for (const [key, val] of props) {
2580
+ target[key] = val;
2581
+ }
2582
+ return target;
2583
+ }
2584
+ `;
2585
+
2586
+ async function transformMain(code, filename, options, pluginContext, ssr, customElement) {
2587
+ const { devServer, isProduction, devToolsEnabled } = options;
2588
+ const prevDescriptor = getPrevDescriptor(filename);
2589
+ const { descriptor, errors } = createDescriptor(filename, code, options);
2590
+ if (fs.existsSync(filename)) {
2591
+ getDescriptor(
2592
+ filename,
2593
+ options,
2594
+ true,
2595
+ true,
2596
+ // for vue files, create descriptor from fs read to be consistent with
2597
+ // logic in handleHotUpdate()
2598
+ // for non vue files, e.g. md files in vitepress, we assume
2599
+ // `hmrContext.read` is overwritten so handleHotUpdate() is dealing with
2600
+ // post-transform code, so we populate the descriptor with post-transform
2601
+ // code here as well.
2602
+ filename.endsWith(".vue") ? void 0 : code
2603
+ );
2604
+ }
2605
+ if (errors.length) {
2606
+ errors.forEach(
2607
+ (error) => pluginContext.error(createRollupError(filename, error))
2608
+ );
2609
+ return null;
2610
+ }
2611
+ const attachedProps = [];
2612
+ const hasScoped = descriptor.styles.some((s) => s.scoped);
2613
+ const { code: scriptCode, map: scriptMap } = await genScriptCode(
2614
+ descriptor,
2615
+ options,
2616
+ pluginContext,
2617
+ ssr,
2618
+ customElement
2619
+ );
2620
+ const hasTemplateImport = descriptor.template && !isUseInlineTemplate(descriptor, options);
2621
+ let templateCode = "";
2622
+ let templateMap = void 0;
2623
+ if (hasTemplateImport) {
2624
+ ({ code: templateCode, map: templateMap } = await genTemplateCode(
2625
+ descriptor,
2626
+ options,
2627
+ pluginContext,
2628
+ ssr,
2629
+ customElement
2630
+ ));
2631
+ }
2632
+ if (hasTemplateImport) {
2633
+ attachedProps.push(
2634
+ ssr ? ["ssrRender", "_sfc_ssrRender"] : ["render", "_sfc_render"]
2635
+ );
2636
+ } else {
2637
+ if (prevDescriptor && !isEqualBlock(descriptor.template, prevDescriptor.template)) {
2638
+ attachedProps.push([ssr ? "ssrRender" : "render", "() => {}"]);
2639
+ }
2640
+ }
2641
+ const stylesCode = await genStyleCode(
2642
+ descriptor,
2643
+ pluginContext,
2644
+ customElement,
2645
+ attachedProps
2646
+ );
2647
+ const customBlocksCode = await genCustomBlockCode(descriptor, pluginContext);
2648
+ const output = [
2649
+ scriptCode,
2650
+ templateCode,
2651
+ stylesCode,
2652
+ customBlocksCode
2653
+ ];
2654
+ if (hasScoped) {
2655
+ attachedProps.push([`__scopeId`, JSON.stringify(`data-v-${descriptor.id}`)]);
2656
+ }
2657
+ if (devToolsEnabled || devServer && !isProduction) {
2658
+ attachedProps.push([
2659
+ `__file`,
2660
+ JSON.stringify(isProduction ? path.basename(filename) : filename)
2661
+ ]);
2662
+ }
2663
+ if (devServer && devServer.config.server.hmr !== false && !ssr && !isProduction) {
2664
+ output.push(`_sfc_main.__hmrId = ${JSON.stringify(descriptor.id)}`);
2665
+ output.push(
2666
+ `typeof __VUE_HMR_RUNTIME__ !== 'undefined' && __VUE_HMR_RUNTIME__.createRecord(_sfc_main.__hmrId, _sfc_main)`
2667
+ );
2668
+ output.push(
2669
+ `import.meta.hot.on('file-changed', ({ file }) => {`,
2670
+ ` __VUE_HMR_RUNTIME__.CHANGED_FILE = file`,
2671
+ `})`
2672
+ );
2673
+ if (prevDescriptor && isOnlyTemplateChanged(prevDescriptor, descriptor)) {
2674
+ output.push(
2675
+ `export const _rerender_only = __VUE_HMR_RUNTIME__.CHANGED_FILE === ${JSON.stringify(normalizePath$1(filename))}`
2676
+ );
2677
+ }
2678
+ output.push(
2679
+ `import.meta.hot.accept(mod => {`,
2680
+ ` if (!mod) return`,
2681
+ ` const { default: updated, _rerender_only } = mod`,
2682
+ ` if (_rerender_only) {`,
2683
+ ` __VUE_HMR_RUNTIME__.rerender(updated.__hmrId, updated.render)`,
2684
+ ` } else {`,
2685
+ ` __VUE_HMR_RUNTIME__.reload(updated.__hmrId, updated)`,
2686
+ ` }`,
2687
+ `})`
2688
+ );
2689
+ }
2690
+ if (ssr) {
2691
+ const normalizedFilename = normalizePath$1(
2692
+ path.relative(options.root, filename)
2693
+ );
2694
+ output.push(
2695
+ `import { useSSRContext as __vite_useSSRContext } from 'vue'`,
2696
+ `const _sfc_setup = _sfc_main.setup`,
2697
+ `_sfc_main.setup = (props, ctx) => {`,
2698
+ ` const ssrContext = __vite_useSSRContext()`,
2699
+ ` ;(ssrContext.modules || (ssrContext.modules = new Set())).add(${JSON.stringify(
2700
+ normalizedFilename
2701
+ )})`,
2702
+ ` return _sfc_setup ? _sfc_setup(props, ctx) : undefined`,
2703
+ `}`
2704
+ );
2705
+ }
2706
+ let resolvedMap = void 0;
2707
+ if (options.sourceMap) {
2708
+ if (templateMap) {
2709
+ const from = scriptMap ?? {
2710
+ file: filename,
2711
+ sourceRoot: "",
2712
+ version: 3,
2713
+ sources: [],
2714
+ sourcesContent: [],
2715
+ names: [],
2716
+ mappings: ""
2717
+ };
2718
+ const gen = fromMap(
2719
+ // version property of result.map is declared as string
2720
+ // but actually it is `3`
2721
+ from
2722
+ );
2723
+ const tracer = new TraceMap(
2724
+ // same above
2725
+ templateMap
2726
+ );
2727
+ const offset = (scriptCode.match(/\r?\n/g)?.length ?? 0) + 1;
2728
+ eachMapping(tracer, (m) => {
2729
+ if (m.source == null) return;
2730
+ addMapping(gen, {
2731
+ source: m.source,
2732
+ original: { line: m.originalLine, column: m.originalColumn },
2733
+ generated: {
2734
+ line: m.generatedLine + offset,
2735
+ column: m.generatedColumn
2736
+ }
2737
+ });
2738
+ });
2739
+ resolvedMap = toEncodedMap(gen);
2740
+ resolvedMap.sourcesContent = templateMap.sourcesContent;
2741
+ } else {
2742
+ resolvedMap = scriptMap;
2743
+ }
2744
+ }
2745
+ if (!attachedProps.length) {
2746
+ output.push(`export default _sfc_main`);
2747
+ } else {
2748
+ output.push(
2749
+ `import _export_sfc from '${EXPORT_HELPER_ID}'`,
2750
+ `export default /*#__PURE__*/_export_sfc(_sfc_main, [${attachedProps.map(([key, val]) => `['${key}',${val}]`).join(",")}])`
2751
+ );
2752
+ }
2753
+ let resolvedCode = output.join("\n");
2754
+ const lang = descriptor.scriptSetup?.lang || descriptor.script?.lang;
2755
+ if (lang && /tsx?$/.test(lang) && !descriptor.script?.src) {
2756
+ const { transformWithOxc } = await import('vite');
2757
+ if (transformWithOxc) {
2758
+ const { code: code2, map } = await transformWithOxc(
2759
+ resolvedCode,
2760
+ filename,
2761
+ {
2762
+ // #430 support decorators in .vue file
2763
+ // target can be overridden by oxc config target
2764
+ // @ts-ignore Rolldown-specific
2765
+ ...options.devServer?.config.oxc,
2766
+ lang: "ts",
2767
+ sourcemap: options.sourceMap
2768
+ },
2769
+ resolvedMap
2770
+ );
2771
+ resolvedCode = code2;
2772
+ resolvedMap = resolvedMap ? map : resolvedMap;
2773
+ } else {
2774
+ const { code: code2, map } = await transformWithEsbuild(
2775
+ resolvedCode,
2776
+ filename,
2777
+ {
2778
+ target: "esnext",
2779
+ charset: "utf8",
2780
+ // #430 support decorators in .vue file
2781
+ // target can be overridden by esbuild config target
2782
+ ...options.devServer?.config.esbuild,
2783
+ loader: "ts",
2784
+ sourcemap: options.sourceMap
2785
+ },
2786
+ resolvedMap
2787
+ );
2788
+ resolvedCode = code2;
2789
+ resolvedMap = resolvedMap ? map : resolvedMap;
2790
+ }
2791
+ }
2792
+ return {
2793
+ code: resolvedCode,
2794
+ map: resolvedMap || {
2795
+ mappings: ""
2796
+ },
2797
+ meta: {
2798
+ vite: {
2799
+ lang: descriptor.script?.lang || descriptor.scriptSetup?.lang || "js"
2800
+ }
2801
+ }
2802
+ };
2803
+ }
2804
+ async function genTemplateCode(descriptor, options, pluginContext, ssr, customElement) {
2805
+ const template = descriptor.template;
2806
+ const hasScoped = descriptor.styles.some((style) => style.scoped);
2807
+ if ((!template.lang || template.lang === "html") && !template.src) {
2808
+ return transformTemplateInMain(
2809
+ template.content,
2810
+ descriptor,
2811
+ options,
2812
+ pluginContext,
2813
+ ssr,
2814
+ customElement
2815
+ );
2816
+ } else {
2817
+ if (template.src) {
2818
+ await linkSrcToDescriptor(
2819
+ template.src,
2820
+ descriptor,
2821
+ pluginContext,
2822
+ hasScoped
2823
+ );
2824
+ }
2825
+ const src = template.src || descriptor.filename;
2826
+ const srcQuery = template.src ? hasScoped ? `&src=${descriptor.id}` : "&src=true" : "";
2827
+ const scopedQuery = hasScoped ? `&scoped=${descriptor.id}` : ``;
2828
+ const attrsQuery = attrsToQuery(template.attrs, "js", true);
2829
+ const query = `?vue&type=template${srcQuery}${scopedQuery}${attrsQuery}`;
2830
+ const request = JSON.stringify(src + query);
2831
+ const renderFnName = ssr ? "ssrRender" : "render";
2832
+ return {
2833
+ code: `import { ${renderFnName} as _sfc_${renderFnName} } from ${request}`,
2834
+ map: void 0
2835
+ };
2836
+ }
2837
+ }
2838
+ async function genScriptCode(descriptor, options, pluginContext, ssr, customElement) {
2839
+ const vaporFlag = descriptor.vapor ? "__vapor: true" : "";
2840
+ let scriptCode = `const ${scriptIdentifier} = { ${vaporFlag} }`;
2841
+ let map;
2842
+ const script = resolveScript(false, descriptor, options, ssr, customElement);
2843
+ if (script) {
2844
+ if (canInlineMain(descriptor, options)) {
2845
+ if (!options.compiler.version) {
2846
+ const userPlugins = options.script?.babelParserPlugins || [];
2847
+ const defaultPlugins = script.lang === "ts" ? userPlugins.includes("decorators") ? ["typescript"] : ["typescript", "decorators-legacy"] : [];
2848
+ scriptCode = options.compiler.rewriteDefault(
2849
+ script.content,
2850
+ scriptIdentifier,
2851
+ [...defaultPlugins, ...userPlugins]
2852
+ );
2853
+ } else {
2854
+ scriptCode = script.content;
2855
+ }
2856
+ map = script.map;
2857
+ } else {
2858
+ if (script.src) {
2859
+ await linkSrcToDescriptor(script.src, descriptor, pluginContext, false);
2860
+ }
2861
+ const src = script.src || descriptor.filename;
2862
+ const langFallback = script.src && path.extname(src).slice(1) || "js";
2863
+ const attrsQuery = attrsToQuery(script.attrs, langFallback);
2864
+ const srcQuery = script.src ? `&src=true` : ``;
2865
+ const query = `?vue&type=script${srcQuery}${attrsQuery}`;
2866
+ const request = JSON.stringify(src + query);
2867
+ scriptCode = `import _sfc_main from ${request}
2868
+ export * from ${request}`;
2869
+ }
2870
+ }
2871
+ return {
2872
+ code: scriptCode,
2873
+ map
2874
+ };
2875
+ }
2876
+ async function genStyleCode(descriptor, pluginContext, customElement, attachedProps) {
2877
+ let stylesCode = ``;
2878
+ let cssModulesMap;
2879
+ if (descriptor.styles.length) {
2880
+ for (let i = 0; i < descriptor.styles.length; i++) {
2881
+ const style = descriptor.styles[i];
2882
+ if (style.src) {
2883
+ await linkSrcToDescriptor(
2884
+ style.src,
2885
+ descriptor,
2886
+ pluginContext,
2887
+ style.scoped
2888
+ );
2889
+ }
2890
+ const src = style.src || descriptor.filename;
2891
+ const attrsQuery = attrsToQuery(style.attrs, "css");
2892
+ const srcQuery = style.src ? style.scoped ? `&src=${descriptor.id}` : "&src=true" : "";
2893
+ const directQuery = customElement ? `&inline` : ``;
2894
+ const scopedQuery = style.scoped ? `&scoped=${descriptor.id}` : ``;
2895
+ const query = `?vue&type=style&index=${i}${srcQuery}${directQuery}${scopedQuery}`;
2896
+ const styleRequest = src + query + attrsQuery;
2897
+ if (style.module) {
2898
+ if (customElement) {
2899
+ throw new Error(
2900
+ `<style module> is not supported in custom elements mode.`
2901
+ );
2902
+ }
2903
+ const [importCode, nameMap] = genCSSModulesCode(
2904
+ i,
2905
+ styleRequest,
2906
+ style.module
2907
+ );
2908
+ stylesCode += importCode;
2909
+ Object.assign(cssModulesMap ||= {}, nameMap);
2910
+ } else {
2911
+ if (customElement) {
2912
+ stylesCode += `
2913
+ import _style_${i} from ${JSON.stringify(
2914
+ styleRequest
2915
+ )}`;
2916
+ } else {
2917
+ stylesCode += `
2918
+ import ${JSON.stringify(styleRequest)}`;
2919
+ }
2920
+ }
2921
+ }
2922
+ if (customElement) {
2923
+ attachedProps.push([
2924
+ `styles`,
2925
+ `[${descriptor.styles.map((_, i) => `_style_${i}`).join(",")}]`
2926
+ ]);
2927
+ }
2928
+ }
2929
+ if (cssModulesMap) {
2930
+ const mappingCode = Object.entries(cssModulesMap).reduce(
2931
+ (code, [key, value]) => code + `"${key}":${value},
2932
+ `,
2933
+ "{\n"
2934
+ ) + "}";
2935
+ stylesCode += `
2936
+ const cssModules = ${mappingCode}`;
2937
+ attachedProps.push([`__cssModules`, `cssModules`]);
2938
+ }
2939
+ return stylesCode;
2940
+ }
2941
+ function genCSSModulesCode(index, request, moduleName) {
2942
+ const styleVar = `style${index}`;
2943
+ const exposedName = typeof moduleName === "string" ? moduleName : "$style";
2944
+ const moduleRequest = request.replace(/\.(\w+)$/, ".module.$1");
2945
+ return [
2946
+ `
2947
+ import ${styleVar} from ${JSON.stringify(moduleRequest)}`,
2948
+ { [exposedName]: styleVar }
2949
+ ];
2950
+ }
2951
+ async function genCustomBlockCode(descriptor, pluginContext) {
2952
+ let code = "";
2953
+ for (let index = 0; index < descriptor.customBlocks.length; index++) {
2954
+ const block = descriptor.customBlocks[index];
2955
+ if (block.src) {
2956
+ await linkSrcToDescriptor(block.src, descriptor, pluginContext, false);
2957
+ }
2958
+ const src = block.src || descriptor.filename;
2959
+ const attrsQuery = attrsToQuery(block.attrs, block.type);
2960
+ const srcQuery = block.src ? `&src=true` : ``;
2961
+ const query = `?vue&type=${block.type}&index=${index}${srcQuery}${attrsQuery}`;
2962
+ const request = JSON.stringify(src + query);
2963
+ code += `import block${index} from ${request}
2964
+ `;
2965
+ code += `if (typeof block${index} === 'function') block${index}(_sfc_main)
2966
+ `;
2967
+ }
2968
+ return code;
2969
+ }
2970
+ async function linkSrcToDescriptor(src, descriptor, pluginContext, scoped) {
2971
+ const srcFile = (await pluginContext.resolve(src, descriptor.filename))?.id || src;
2972
+ setSrcDescriptor(srcFile.replace(/\?.*$/, ""), descriptor, scoped);
2973
+ }
2974
+ const ignoreList = [
2975
+ "id",
2976
+ "index",
2977
+ "src",
2978
+ "type",
2979
+ "lang",
2980
+ "module",
2981
+ "scoped",
2982
+ "generic"
2983
+ ];
2984
+ function attrsToQuery(attrs, langFallback, forceLangFallback = false) {
2985
+ let query = ``;
2986
+ for (const name in attrs) {
2987
+ const value = attrs[name];
2988
+ if (!ignoreList.includes(name)) {
2989
+ query += `&${encodeURIComponent(name)}${value ? `=${encodeURIComponent(value)}` : ``}`;
2990
+ }
2991
+ }
2992
+ if (langFallback || attrs.lang) {
2993
+ query += `lang` in attrs ? forceLangFallback ? `&lang.${langFallback}` : `&lang.${attrs.lang}` : `&lang.${langFallback}`;
2994
+ }
2995
+ return query;
2996
+ }
2997
+
2998
+ function cacheFormatSource(fn) {
2999
+ const cache = /* @__PURE__ */ Object.create(null);
3000
+ return (root, str) => {
3001
+ const hit = cache[str];
3002
+ return hit || (cache[str] = fn(root, str));
3003
+ };
3004
+ }
3005
+ const formatSource = cacheFormatSource((root, str) => {
3006
+ return normalizePath$1(path.isAbsolute(str) ? path.relative(root, str) : str);
3007
+ });
3008
+ function mergeSourceMaps(firstMap, secondMap, root) {
3009
+ const firstTracer = new TraceMap(
3010
+ firstMap
3011
+ );
3012
+ const secondTracer = new TraceMap(
3013
+ secondMap
3014
+ );
3015
+ const gen = new GenMapping({
3016
+ file: secondMap.file || firstTracer.file,
3017
+ sourceRoot: secondMap.sourceRoot || firstTracer.sourceRoot
3018
+ });
3019
+ if (firstTracer.sources) {
3020
+ firstTracer.sources.forEach((source, index) => {
3021
+ const content = firstTracer.sourcesContent?.[index];
3022
+ if (content)
3023
+ setSourceContent(
3024
+ gen,
3025
+ root && source ? formatSource(root, source) : source || "",
3026
+ content
3027
+ );
3028
+ });
3029
+ }
3030
+ eachMapping(secondTracer, (m) => {
3031
+ if (!m.source) return;
3032
+ const originalPos = originalPositionFor(firstTracer, {
3033
+ line: m.originalLine,
3034
+ column: m.originalColumn
3035
+ });
3036
+ if (originalPos.source) {
3037
+ addMapping(gen, {
3038
+ source: root && originalPos.source ? formatSource(root, originalPos.source) : originalPos.source,
3039
+ original: {
3040
+ line: originalPos.line ?? 1,
3041
+ column: originalPos.column ?? 0
3042
+ },
3043
+ generated: { line: m.generatedLine, column: m.generatedColumn },
3044
+ name: originalPos.name ?? m.name ?? ""
3045
+ });
3046
+ }
3047
+ });
3048
+ return toEncodedMap(gen);
3049
+ }
3050
+ async function transformStyle(code, descriptor, index, options, pluginContext, filename, id) {
3051
+ const block = descriptor.styles[index];
3052
+ const result = await options.compiler.compileStyleAsync({
3053
+ ...options.style,
3054
+ filename: descriptor.filename,
3055
+ id: `data-v-${descriptor.id}`,
3056
+ isProd: options.isProduction,
3057
+ source: code,
3058
+ scoped: block.scoped,
3059
+ ...options.cssDevSourcemap ? {
3060
+ postcssOptions: {
3061
+ map: {
3062
+ from: filename,
3063
+ inline: false,
3064
+ annotation: false
3065
+ }
3066
+ }
3067
+ } : {}
3068
+ });
3069
+ if (result.errors.length) {
3070
+ result.errors.forEach((error) => {
3071
+ if (error.line && error.column) {
3072
+ error.loc = {
3073
+ file: descriptor.filename,
3074
+ line: error.line + block.loc.start.line,
3075
+ column: error.column
3076
+ };
3077
+ }
3078
+ pluginContext.error(error);
3079
+ });
3080
+ return null;
3081
+ }
3082
+ const map = result.map ? await formatPostcssSourceMap(
3083
+ // version property of result.map is declared as string
3084
+ // but actually it is a number
3085
+ result.map,
3086
+ filename
3087
+ ) : { mappings: "" };
3088
+ let finalMap;
3089
+ if (map && map.mappings !== "") {
3090
+ const moduleInfo = pluginContext.getModuleInfo(id);
3091
+ const cssPreprocessorSourceMap = moduleInfo?.meta?.uni?.cssPreprocessorSourceMap;
3092
+ if (cssPreprocessorSourceMap) {
3093
+ finalMap = mergeSourceMaps(cssPreprocessorSourceMap, map, options.root);
3094
+ } else {
3095
+ finalMap = map;
3096
+ }
3097
+ if (block.map) {
3098
+ finalMap = mergeSourceMaps(block.map, finalMap, options.root);
3099
+ }
3100
+ }
3101
+ return {
3102
+ code: result.code,
3103
+ // fixed by uts
3104
+ map: null,
3105
+ meta: block.scoped && !descriptor.isTemp ? {
3106
+ vite: {
3107
+ cssScopeTo: [descriptor.filename, "default"]
3108
+ },
3109
+ // fixed by uts
3110
+ // 走 rollup 的 sourcemap 机制目前有问题
3111
+ // 所以先自己存储使用
3112
+ uni: {
3113
+ cssSourceMap: finalMap
3114
+ }
3115
+ } : {
3116
+ // fixed by uts
3117
+ uni: {
3118
+ cssSourceMap: finalMap
3119
+ }
3120
+ }
3121
+ };
3122
+ }
3123
+
3124
+ function vuePlugin(rawOptions = {}) {
3125
+ clearScriptCache();
3126
+ const options = shallowRef({
3127
+ isProduction: process.env.NODE_ENV === "production",
3128
+ compiler: null,
3129
+ // to be set in buildStart
3130
+ include: /\.vue$/,
3131
+ customElement: /\.ce\.vue$/,
3132
+ ...rawOptions,
3133
+ root: process.cwd(),
3134
+ sourceMap: true,
3135
+ cssDevSourcemap: false
3136
+ });
3137
+ const filter = computed(
3138
+ () => createFilter(options.value.include, options.value.exclude)
3139
+ );
3140
+ const customElementFilter = computed(() => {
3141
+ const customElement = options.value.features?.customElement || options.value.customElement;
3142
+ return typeof customElement === "boolean" ? () => customElement : createFilter(customElement);
3143
+ });
3144
+ return {
3145
+ name: "vite:vue",
3146
+ api: {
3147
+ get options() {
3148
+ return options.value;
3149
+ },
3150
+ set options(value) {
3151
+ options.value = value;
3152
+ },
3153
+ version
3154
+ },
3155
+ handleHotUpdate(ctx) {
3156
+ ctx.server.ws.send({
3157
+ type: "custom",
3158
+ event: "file-changed",
3159
+ data: { file: normalizePath$1(ctx.file) }
3160
+ });
3161
+ if (options.value.compiler.invalidateTypeCache) {
3162
+ options.value.compiler.invalidateTypeCache(ctx.file);
3163
+ }
3164
+ let typeDepModules;
3165
+ const matchesFilter = filter.value(ctx.file);
3166
+ if (typeDepToSFCMap.has(ctx.file)) {
3167
+ typeDepModules = handleTypeDepChange(
3168
+ typeDepToSFCMap.get(ctx.file),
3169
+ ctx
3170
+ );
3171
+ if (!matchesFilter) return typeDepModules;
3172
+ }
3173
+ if (matchesFilter) {
3174
+ return handleHotUpdate(
3175
+ ctx,
3176
+ options.value,
3177
+ customElementFilter.value(ctx.file),
3178
+ typeDepModules
3179
+ );
3180
+ }
3181
+ },
3182
+ config(config) {
3183
+ const parseDefine = (v) => {
3184
+ try {
3185
+ return typeof v === "string" ? JSON.parse(v) : v;
3186
+ } catch (err) {
3187
+ return v;
3188
+ }
3189
+ };
3190
+ return {
3191
+ resolve: {
3192
+ dedupe: config.build?.ssr ? [] : ["vue"]
3193
+ },
3194
+ define: {
3195
+ __VUE_OPTIONS_API__: options.value.features?.optionsAPI ?? parseDefine(config.define?.__VUE_OPTIONS_API__) ?? true,
3196
+ __VUE_PROD_DEVTOOLS__: (options.value.features?.prodDevtools || parseDefine(config.define?.__VUE_PROD_DEVTOOLS__)) ?? false,
3197
+ __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: (options.value.features?.prodHydrationMismatchDetails || parseDefine(
3198
+ config.define?.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__
3199
+ )) ?? false
3200
+ },
3201
+ ssr: {
3202
+ // @ts-ignore -- config.legacy.buildSsrCjsExternalHeuristics will be removed in Vite 5
3203
+ external: config.legacy?.buildSsrCjsExternalHeuristics ? ["vue", "@vue/server-renderer"] : []
3204
+ }
3205
+ };
3206
+ },
3207
+ configResolved(config) {
3208
+ options.value = {
3209
+ ...options.value,
3210
+ root: config.root,
3211
+ sourceMap: config.command === "build" ? !!config.build.sourcemap : true,
3212
+ cssDevSourcemap: config.css?.devSourcemap ?? false,
3213
+ isProduction: config.isProduction,
3214
+ devToolsEnabled: !!(options.value.features?.prodDevtools || config.define.__VUE_PROD_DEVTOOLS__ || !config.isProduction)
3215
+ };
3216
+ const _warn = config.logger.warn;
3217
+ config.logger.warn = (...args) => {
3218
+ const msg = args[0];
3219
+ if (msg.match(
3220
+ /\[lightningcss\] '(deep|slotted|global)' is not recognized as a valid pseudo-/
3221
+ )) {
3222
+ return;
3223
+ }
3224
+ _warn(...args);
3225
+ };
3226
+ },
3227
+ // fixed by uts 启用该代码,会导致一个vue页面变更,其他所有vue页面都会被编译
3228
+ // shouldTransformCachedModule({ id }) {
3229
+ // if (transformCachedModule && parseVueRequest(id).query.vue) {
3230
+ // return true
3231
+ // }
3232
+ // return false
3233
+ // },
3234
+ configureServer(server) {
3235
+ options.value.devServer = server;
3236
+ },
3237
+ buildStart() {
3238
+ const compiler = options.value.compiler = options.value.compiler || resolveCompiler(options.value.root);
3239
+ if (compiler.invalidateTypeCache) {
3240
+ options.value.devServer?.watcher.on("unlink", (file) => {
3241
+ compiler.invalidateTypeCache(file);
3242
+ });
3243
+ }
3244
+ },
3245
+ async resolveId(id) {
3246
+ if (id === EXPORT_HELPER_ID) {
3247
+ return id;
3248
+ }
3249
+ if (parseVueRequest(id).query.vue) {
3250
+ return id;
3251
+ }
3252
+ },
3253
+ load(id, opt) {
3254
+ if (id === EXPORT_HELPER_ID) {
3255
+ return helperCode;
3256
+ }
3257
+ const ssr = opt?.ssr === true;
3258
+ const { filename, query } = parseVueRequest(id);
3259
+ if (query.vue) {
3260
+ if (query.src) {
3261
+ return fs.readFileSync(filename, "utf-8");
3262
+ }
3263
+ const descriptor = getDescriptor(filename, options.value);
3264
+ let block;
3265
+ if (query.type === "script") {
3266
+ block = resolveScript(
3267
+ // fixed by uts
3268
+ true,
3269
+ descriptor,
3270
+ options.value,
3271
+ ssr,
3272
+ customElementFilter.value(filename)
3273
+ );
3274
+ } else if (query.type === "template") {
3275
+ block = descriptor.template;
3276
+ } else if (query.type === "style") {
3277
+ block = descriptor.styles[query.index];
3278
+ } else if (query.index != null) {
3279
+ block = descriptor.customBlocks[query.index];
3280
+ }
3281
+ if (block) {
3282
+ return {
3283
+ code: block.content,
3284
+ map: block.map
3285
+ };
3286
+ }
3287
+ }
3288
+ },
3289
+ transform(code, id, opt) {
3290
+ const ssr = opt?.ssr === true;
3291
+ const { filename, query } = parseVueRequest(id);
3292
+ if (query.raw || query.url) {
3293
+ return;
3294
+ }
3295
+ if (!filter.value(filename) && !query.vue) {
3296
+ return;
3297
+ }
3298
+ if (!query.vue) {
3299
+ return transformMain(
3300
+ code,
3301
+ filename,
3302
+ options.value,
3303
+ this,
3304
+ ssr,
3305
+ customElementFilter.value(filename)
3306
+ );
3307
+ } else {
3308
+ const descriptor = query.src ? getSrcDescriptor(filename, query) || getTempSrcDescriptor(filename, query) : getDescriptor(filename, options.value);
3309
+ if (query.src) {
3310
+ this.addWatchFile(filename);
3311
+ }
3312
+ if (query.type === "template") {
3313
+ return transformTemplateAsModule(
3314
+ code,
3315
+ descriptor,
3316
+ options.value,
3317
+ this,
3318
+ ssr,
3319
+ customElementFilter.value(filename)
3320
+ );
3321
+ } else if (query.type === "style") {
3322
+ return transformStyle(
3323
+ code,
3324
+ descriptor,
3325
+ Number(query.index || 0),
3326
+ options.value,
3327
+ this,
3328
+ filename,
3329
+ // fixed by uts
3330
+ id
3331
+ );
3332
+ }
3333
+ }
3334
+ }
3335
+ };
3336
+ }
3337
+
3338
+ export { vuePlugin as default, parseVueRequest };