@vitejs/devtools 0.0.0-alpha.1 → 0.0.0-alpha.3

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 (66) hide show
  1. package/{bin.mjs → bin.js} +1 -1
  2. package/dist/cli.js +99 -0
  3. package/dist/client/inject.d.ts +4 -0
  4. package/dist/client/inject.js +33 -0
  5. package/dist/client/standalone/assets/index-C0WqLnSL.js +7 -0
  6. package/dist/client/standalone/assets/index-DLsPMQDX.css +1 -0
  7. package/dist/client/standalone/index.html +14 -0
  8. package/dist/client/webcomponents.d.ts +45 -0
  9. package/dist/client/webcomponents.js +807 -0
  10. package/dist/core-uTAXYiA1.js +6650 -0
  11. package/dist/dirs-B7dOX6eI.js +9 -0
  12. package/dist/dirs.d.ts +5 -0
  13. package/dist/dirs.js +3 -0
  14. package/dist/index.d.ts +36 -0
  15. package/dist/index.js +4 -0
  16. package/dist/plugins-DDjui9Ga.js +1314 -0
  17. package/package.json +48 -57
  18. package/dist/cli-B_fm1Ing.mjs +0 -1039
  19. package/dist/cli.d.mts +0 -1
  20. package/dist/cli.mjs +0 -3
  21. package/dist/dirs-6LDFDMFM.mjs +0 -7
  22. package/dist/dirs.d.mts +0 -4
  23. package/dist/dirs.mjs +0 -3
  24. package/dist/functions-BdbZxtmk.mjs +0 -3
  25. package/dist/functions-d6vvbndK.mjs +0 -234
  26. package/dist/index.d.mts +0 -13
  27. package/dist/index.mjs +0 -7
  28. package/dist/nitro.json +0 -15
  29. package/dist/node/cli.d.mts +0 -1
  30. package/dist/node/cli.mjs +0 -3
  31. package/dist/public/200.html +0 -16
  32. package/dist/public/404.html +0 -16
  33. package/dist/public/_nuxt/B4lqwDon.js +0 -1
  34. package/dist/public/_nuxt/BMB3EEfo.js +0 -1
  35. package/dist/public/_nuxt/BYYDnj5Q.js +0 -1
  36. package/dist/public/_nuxt/BeSFnMzD.js +0 -1
  37. package/dist/public/_nuxt/BfzgVO01.js +0 -1
  38. package/dist/public/_nuxt/BpyJ-U40.js +0 -1
  39. package/dist/public/_nuxt/BxkFQq1F.js +0 -1
  40. package/dist/public/_nuxt/C1DPtPHu.js +0 -1
  41. package/dist/public/_nuxt/C8oXVTvZ.js +0 -1
  42. package/dist/public/_nuxt/CWPvh8od.js +0 -1
  43. package/dist/public/_nuxt/CiwsH4Q6.js +0 -33
  44. package/dist/public/_nuxt/CsnZqsGp.js +0 -16
  45. package/dist/public/_nuxt/CzEHI6hC.js +0 -1
  46. package/dist/public/_nuxt/D-iXojuv.js +0 -1
  47. package/dist/public/_nuxt/DHpfOFMA.js +0 -1
  48. package/dist/public/_nuxt/DsbJux3u.js +0 -1
  49. package/dist/public/_nuxt/builds/latest.json +0 -1
  50. package/dist/public/_nuxt/builds/meta/3597016d-955b-44d8-83dd-f083d7311779.json +0 -1
  51. package/dist/public/_nuxt/diff.worker-9IK9E-UB.js +0 -10
  52. package/dist/public/_nuxt/entry.BHghYYEP.css +0 -1
  53. package/dist/public/_nuxt/error-404.7Y6KY23b.css +0 -1
  54. package/dist/public/_nuxt/error-500.CaUb23JJ.css +0 -1
  55. package/dist/public/_nuxt/graph.BGBTj9Q7.css +0 -1
  56. package/dist/public/dot-grid-dark.png +0 -0
  57. package/dist/public/dot-grid-light.png +0 -0
  58. package/dist/public/favicon.svg +0 -15
  59. package/dist/public/fonts/dmmono-612bc94f.woff2 +0 -0
  60. package/dist/public/fonts/dmmono-cbe07c46.woff2 +0 -0
  61. package/dist/public/fonts/dmsans-b28079ff.woff2 +0 -0
  62. package/dist/public/fonts/dmsans-b4f1d45c.woff2 +0 -0
  63. package/dist/public/index.html +0 -16
  64. package/dist/public/vite-devtools.svg +0 -17
  65. /package/{LICENSE.md → LICENSE} +0 -0
  66. /package/dist/{cli-C3YoliaZ.d.mts → cli.d.ts} +0 -0
@@ -0,0 +1,1314 @@
1
+ import { dirClientStandalone, dirDist } from "./dirs-B7dOX6eI.js";
2
+ import { existsSync } from "node:fs";
3
+ import Debug from "debug";
4
+ import sirv from "sirv";
5
+ import { defineRpcFunction, getRpcHandler } from "@vitejs/devtools-kit";
6
+ import { DevToolsViteUI } from "@vitejs/devtools-vite";
7
+ import { join } from "node:path";
8
+ import process$1 from "node:process";
9
+ import { normalizePath } from "vite";
10
+ import { createRpcServer } from "@vitejs/devtools-rpc";
11
+ import { createWsRpcPreset } from "@vitejs/devtools-rpc/presets/ws/server";
12
+ import { createServer } from "node:net";
13
+ import { networkInterfaces } from "node:os";
14
+ import "node:fs/promises";
15
+
16
+ //#region rolldown:runtime
17
+ var __create = Object.create;
18
+ var __defProp = Object.defineProperty;
19
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
20
+ var __getOwnPropNames = Object.getOwnPropertyNames;
21
+ var __getProtoOf = Object.getPrototypeOf;
22
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
23
+ var __commonJS = (cb, mod) => function() {
24
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i$1 = 0, n$1 = keys.length, key; i$1 < n$1; i$1++) {
28
+ key = keys[i$1];
29
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
30
+ get: ((k) => from[k]).bind(null, key),
31
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
32
+ });
33
+ }
34
+ return to;
35
+ };
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
37
+ value: mod,
38
+ enumerable: true
39
+ }) : target, mod));
40
+
41
+ //#endregion
42
+ //#region src/node/host-docks.ts
43
+ var DevToolsDockHost = class {
44
+ views = /* @__PURE__ */ new Map();
45
+ constructor() {}
46
+ values() {
47
+ return Array.from(this.views.values());
48
+ }
49
+ register(view) {
50
+ this.views.set(view.id, view);
51
+ }
52
+ };
53
+
54
+ //#endregion
55
+ //#region src/node/host-functions.ts
56
+ var RpcFunctionsHost = class {
57
+ definitions = /* @__PURE__ */ new Map();
58
+ functions;
59
+ context = void 0;
60
+ constructor() {
61
+ const definitions = this.definitions;
62
+ const self = this;
63
+ this.functions = new Proxy({}, {
64
+ get(_, prop) {
65
+ const definition = definitions.get(prop);
66
+ if (!definition) return void 0;
67
+ return getRpcHandler(definition, self.context);
68
+ },
69
+ has(_, prop) {
70
+ return definitions.has(prop);
71
+ },
72
+ getOwnPropertyDescriptor(_, prop) {
73
+ return {
74
+ value: definitions.get(prop)?.handler,
75
+ configurable: true,
76
+ enumerable: true
77
+ };
78
+ },
79
+ ownKeys() {
80
+ return Array.from(definitions.keys());
81
+ }
82
+ });
83
+ }
84
+ register(fn) {
85
+ this.definitions.set(fn.name, fn);
86
+ }
87
+ };
88
+
89
+ //#endregion
90
+ //#region src/node/rpc/list-dock-entries.ts
91
+ const listDockEntries = defineRpcFunction({
92
+ name: "vite:core:list-dock-entries",
93
+ type: "query",
94
+ setup: (context) => {
95
+ return { handler: () => Array.from(context.docks.values()) };
96
+ }
97
+ });
98
+
99
+ //#endregion
100
+ //#region src/node/rpc/list-rpc-functions.ts
101
+ const listRpcFunctions = defineRpcFunction({
102
+ name: "vite:core:list-rpc-functions",
103
+ type: "action",
104
+ setup: (context) => {
105
+ return { async handler() {
106
+ return Object.fromEntries(Array.from(context.rpc.definitions.entries()).map(([name, fn]) => [name, { type: fn.type }]));
107
+ } };
108
+ }
109
+ });
110
+
111
+ //#endregion
112
+ //#region src/node/rpc/open-in-editor.ts
113
+ const openInEditor = defineRpcFunction({
114
+ name: "vite:core:open-in-editor",
115
+ type: "action",
116
+ setup: () => {
117
+ return { handler: async (path) => {
118
+ await import("launch-editor").then((r$2) => r$2.default(path));
119
+ } };
120
+ }
121
+ });
122
+
123
+ //#endregion
124
+ //#region src/node/rpc/open-in-finder.ts
125
+ const openInFinder = defineRpcFunction({
126
+ name: "vite:core:open-in-finder",
127
+ type: "action",
128
+ setup: () => {
129
+ return { handler: async (path) => {
130
+ await import("open").then((r$2) => r$2.default(path));
131
+ } };
132
+ }
133
+ });
134
+
135
+ //#endregion
136
+ //#region src/node/rpc/index.ts
137
+ const builtinRpcFunctions = [
138
+ listRpcFunctions,
139
+ listDockEntries,
140
+ openInEditor,
141
+ openInFinder
142
+ ];
143
+
144
+ //#endregion
145
+ //#region src/node/context.ts
146
+ const debug = Debug("vite:devtools:context");
147
+ async function createDevToolsContext(viteConfig, viteServer) {
148
+ const cwd = viteConfig.root;
149
+ const rpcHost = new RpcFunctionsHost();
150
+ const docksHost = new DevToolsDockHost();
151
+ const context = {
152
+ cwd,
153
+ viteConfig,
154
+ viteServer,
155
+ mode: viteConfig.command === "serve" ? "dev" : "build",
156
+ rpc: rpcHost,
157
+ docks: docksHost,
158
+ hostStatic,
159
+ staticDirs: []
160
+ };
161
+ rpcHost.context = context;
162
+ function hostStatic(baseUrl, distDir) {
163
+ if (!existsSync(distDir)) throw new Error(`[Vite DevTools] distDir ${distDir} does not exist`);
164
+ if (viteConfig.command === "serve") {
165
+ if (!viteServer) throw new Error("[Vite DevTools] viteServer is required in dev mode");
166
+ viteServer.middlewares.use(baseUrl, sirv(distDir, {
167
+ dev: true,
168
+ single: true
169
+ }));
170
+ } else context.staticDirs.push({
171
+ baseUrl,
172
+ distDir
173
+ });
174
+ }
175
+ for (const fn of builtinRpcFunctions) rpcHost.register(fn);
176
+ const plugins = viteConfig.plugins.filter((plugin) => "devtools" in plugin);
177
+ for (const plugin of plugins) {
178
+ if (!plugin.devtools?.setup) continue;
179
+ try {
180
+ debug(`Setting up plugin ${plugin.name}`);
181
+ await plugin.devtools?.setup?.(context);
182
+ } catch (error) {
183
+ console.error(`[Vite DevTools] Error setting up plugin ${plugin.name}:`, error);
184
+ throw error;
185
+ }
186
+ }
187
+ return context;
188
+ }
189
+
190
+ //#endregion
191
+ //#region src/node/plugins/injection.ts
192
+ function DevToolsInjection() {
193
+ return {
194
+ name: "vite:devtools:injection",
195
+ enforce: "post",
196
+ transformIndexHtml() {
197
+ return [{
198
+ tag: "script",
199
+ attrs: {
200
+ src: `/@fs/${process$1.env.VITE_DEVTOOLS_LOCAL_DEV ? normalizePath(join(dirDist, "..", "src/client/inject/index.ts")) : normalizePath(join(dirDist, "client/inject.js"))}`,
201
+ type: "module"
202
+ },
203
+ injectTo: "body"
204
+ }];
205
+ }
206
+ };
207
+ }
208
+
209
+ //#endregion
210
+ //#region ../../node_modules/.pnpm/ufo@1.6.1/node_modules/ufo/dist/index.mjs
211
+ const r$1 = String.fromCharCode;
212
+ const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
213
+ const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
214
+ const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
215
+ const TRAILING_SLASH_RE = /\/$|\/\?|\/#/;
216
+ const JOIN_LEADING_SLASH_RE = /^\.?\//;
217
+ function hasProtocol(inputString, opts = {}) {
218
+ if (typeof opts === "boolean") opts = { acceptRelative: opts };
219
+ if (opts.strict) return PROTOCOL_STRICT_REGEX.test(inputString);
220
+ return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
221
+ }
222
+ function hasTrailingSlash(input = "", respectQueryAndFragment) {
223
+ if (!respectQueryAndFragment) return input.endsWith("/");
224
+ return TRAILING_SLASH_RE.test(input);
225
+ }
226
+ function withoutTrailingSlash(input = "", respectQueryAndFragment) {
227
+ if (!respectQueryAndFragment) return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
228
+ if (!hasTrailingSlash(input, true)) return input || "/";
229
+ let path = input;
230
+ let fragment = "";
231
+ const fragmentIndex = input.indexOf("#");
232
+ if (fragmentIndex !== -1) {
233
+ path = input.slice(0, fragmentIndex);
234
+ fragment = input.slice(fragmentIndex);
235
+ }
236
+ const [s0, ...s$1] = path.split("?");
237
+ return ((s0.endsWith("/") ? s0.slice(0, -1) : s0) || "/") + (s$1.length > 0 ? `?${s$1.join("?")}` : "") + fragment;
238
+ }
239
+ function withTrailingSlash(input = "", respectQueryAndFragment) {
240
+ if (!respectQueryAndFragment) return input.endsWith("/") ? input : input + "/";
241
+ if (hasTrailingSlash(input, true)) return input || "/";
242
+ let path = input;
243
+ let fragment = "";
244
+ const fragmentIndex = input.indexOf("#");
245
+ if (fragmentIndex !== -1) {
246
+ path = input.slice(0, fragmentIndex);
247
+ fragment = input.slice(fragmentIndex);
248
+ if (!path) return fragment;
249
+ }
250
+ const [s0, ...s$1] = path.split("?");
251
+ return s0 + "/" + (s$1.length > 0 ? `?${s$1.join("?")}` : "") + fragment;
252
+ }
253
+ function isNonEmptyURL(url) {
254
+ return url && url !== "/";
255
+ }
256
+ function joinURL(base, ...input) {
257
+ let url = base || "";
258
+ for (const segment of input.filter((url2) => isNonEmptyURL(url2))) if (url) {
259
+ const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
260
+ url = withTrailingSlash(url) + _segment;
261
+ } else url = segment;
262
+ return url;
263
+ }
264
+ const protocolRelative = Symbol.for("ufo:protocolRelative");
265
+ function parseURL(input = "", defaultProto) {
266
+ const _specialProtoMatch = input.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);
267
+ if (_specialProtoMatch) {
268
+ const [, _proto, _pathname = ""] = _specialProtoMatch;
269
+ return {
270
+ protocol: _proto.toLowerCase(),
271
+ pathname: _pathname,
272
+ href: _proto + _pathname,
273
+ auth: "",
274
+ host: "",
275
+ search: "",
276
+ hash: ""
277
+ };
278
+ }
279
+ if (!hasProtocol(input, { acceptRelative: true })) return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
280
+ const [, protocol = "", auth, hostAndPath = ""] = input.replace(/\\/g, "/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || [];
281
+ let [, host = "", path = ""] = hostAndPath.match(/([^#/?]*)(.*)?/) || [];
282
+ if (protocol === "file:") path = path.replace(/\/(?=[A-Za-z]:)/, "");
283
+ const { pathname, search, hash } = parsePath(path);
284
+ return {
285
+ protocol: protocol.toLowerCase(),
286
+ auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
287
+ host,
288
+ pathname,
289
+ search,
290
+ hash,
291
+ [protocolRelative]: !protocol
292
+ };
293
+ }
294
+ function parsePath(input = "") {
295
+ const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
296
+ return {
297
+ pathname,
298
+ search,
299
+ hash
300
+ };
301
+ }
302
+
303
+ //#endregion
304
+ //#region ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
305
+ function isPlainObject(value) {
306
+ if (value === null || typeof value !== "object") return false;
307
+ const prototype = Object.getPrototypeOf(value);
308
+ if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
309
+ if (Symbol.iterator in value) return false;
310
+ if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
311
+ return true;
312
+ }
313
+ function _defu(baseObject, defaults, namespace = ".", merger) {
314
+ if (!isPlainObject(defaults)) return _defu(baseObject, {}, namespace, merger);
315
+ const object = Object.assign({}, defaults);
316
+ for (const key in baseObject) {
317
+ if (key === "__proto__" || key === "constructor") continue;
318
+ const value = baseObject[key];
319
+ if (value === null || value === void 0) continue;
320
+ if (merger && merger(object, key, value, namespace)) continue;
321
+ if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
322
+ else if (isPlainObject(value) && isPlainObject(object[key])) object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
323
+ else object[key] = value;
324
+ }
325
+ return object;
326
+ }
327
+ function createDefu(merger) {
328
+ return (...arguments_) => arguments_.reduce((p$1, c$1) => _defu(p$1, c$1, "", merger), {});
329
+ }
330
+ const defu = createDefu();
331
+ const defuFn = createDefu((object, key, currentValue) => {
332
+ if (object[key] !== void 0 && typeof currentValue === "function") {
333
+ object[key] = currentValue(object[key]);
334
+ return true;
335
+ }
336
+ });
337
+ const defuArrayFn = createDefu((object, key, currentValue) => {
338
+ if (Array.isArray(object[key]) && typeof currentValue === "function") {
339
+ object[key] = currentValue(object[key]);
340
+ return true;
341
+ }
342
+ });
343
+
344
+ //#endregion
345
+ //#region ../../node_modules/.pnpm/h3@1.15.4/node_modules/h3/dist/index.mjs
346
+ function hasProp(obj, prop) {
347
+ try {
348
+ return prop in obj;
349
+ } catch {
350
+ return false;
351
+ }
352
+ }
353
+ var H3Error = class extends Error {
354
+ static __h3_error__ = true;
355
+ statusCode = 500;
356
+ fatal = false;
357
+ unhandled = false;
358
+ statusMessage;
359
+ data;
360
+ cause;
361
+ constructor(message, opts = {}) {
362
+ super(message, opts);
363
+ if (opts.cause && !this.cause) this.cause = opts.cause;
364
+ }
365
+ toJSON() {
366
+ const obj = {
367
+ message: this.message,
368
+ statusCode: sanitizeStatusCode(this.statusCode, 500)
369
+ };
370
+ if (this.statusMessage) obj.statusMessage = sanitizeStatusMessage(this.statusMessage);
371
+ if (this.data !== void 0) obj.data = this.data;
372
+ return obj;
373
+ }
374
+ };
375
+ function createError(input) {
376
+ if (typeof input === "string") return new H3Error(input);
377
+ if (isError(input)) return input;
378
+ const err = new H3Error(input.message ?? input.statusMessage ?? "", { cause: input.cause || input });
379
+ if (hasProp(input, "stack")) try {
380
+ Object.defineProperty(err, "stack", { get() {
381
+ return input.stack;
382
+ } });
383
+ } catch {
384
+ try {
385
+ err.stack = input.stack;
386
+ } catch {}
387
+ }
388
+ if (input.data) err.data = input.data;
389
+ if (input.statusCode) err.statusCode = sanitizeStatusCode(input.statusCode, err.statusCode);
390
+ else if (input.status) err.statusCode = sanitizeStatusCode(input.status, err.statusCode);
391
+ if (input.statusMessage) err.statusMessage = input.statusMessage;
392
+ else if (input.statusText) err.statusMessage = input.statusText;
393
+ if (err.statusMessage) {
394
+ const originalMessage = err.statusMessage;
395
+ if (sanitizeStatusMessage(err.statusMessage) !== originalMessage) console.warn("[h3] Please prefer using `message` for longer error messages instead of `statusMessage`. In the future, `statusMessage` will be sanitized by default.");
396
+ }
397
+ if (input.fatal !== void 0) err.fatal = input.fatal;
398
+ if (input.unhandled !== void 0) err.unhandled = input.unhandled;
399
+ return err;
400
+ }
401
+ function sendError(event, error, debug$1) {
402
+ if (event.handled) return;
403
+ const h3Error = isError(error) ? error : createError(error);
404
+ const responseBody = {
405
+ statusCode: h3Error.statusCode,
406
+ statusMessage: h3Error.statusMessage,
407
+ stack: [],
408
+ data: h3Error.data
409
+ };
410
+ if (debug$1) responseBody.stack = (h3Error.stack || "").split("\n").map((l$1) => l$1.trim());
411
+ if (event.handled) return;
412
+ const _code = Number.parseInt(h3Error.statusCode);
413
+ setResponseStatus(event, _code, h3Error.statusMessage);
414
+ event.node.res.setHeader("content-type", MIMES.json);
415
+ event.node.res.end(JSON.stringify(responseBody, void 0, 2));
416
+ }
417
+ function isError(input) {
418
+ return input?.constructor?.__h3_error__ === true;
419
+ }
420
+ const RawBodySymbol = Symbol.for("h3RawBody");
421
+ const ParsedBodySymbol = Symbol.for("h3ParsedBody");
422
+ const MIMES = {
423
+ html: "text/html",
424
+ json: "application/json"
425
+ };
426
+ const DISALLOWED_STATUS_CHARS = /[^\u0009\u0020-\u007E]/g;
427
+ function sanitizeStatusMessage(statusMessage = "") {
428
+ return statusMessage.replace(DISALLOWED_STATUS_CHARS, "");
429
+ }
430
+ function sanitizeStatusCode(statusCode, defaultStatusCode = 200) {
431
+ if (!statusCode) return defaultStatusCode;
432
+ if (typeof statusCode === "string") statusCode = Number.parseInt(statusCode, 10);
433
+ if (statusCode < 100 || statusCode > 999) return defaultStatusCode;
434
+ return statusCode;
435
+ }
436
+ function splitCookiesString(cookiesString) {
437
+ if (Array.isArray(cookiesString)) return cookiesString.flatMap((c$1) => splitCookiesString(c$1));
438
+ if (typeof cookiesString !== "string") return [];
439
+ const cookiesStrings = [];
440
+ let pos = 0;
441
+ let start;
442
+ let ch;
443
+ let lastComma;
444
+ let nextStart;
445
+ let cookiesSeparatorFound;
446
+ const skipWhitespace = () => {
447
+ while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) pos += 1;
448
+ return pos < cookiesString.length;
449
+ };
450
+ const notSpecialChar = () => {
451
+ ch = cookiesString.charAt(pos);
452
+ return ch !== "=" && ch !== ";" && ch !== ",";
453
+ };
454
+ while (pos < cookiesString.length) {
455
+ start = pos;
456
+ cookiesSeparatorFound = false;
457
+ while (skipWhitespace()) {
458
+ ch = cookiesString.charAt(pos);
459
+ if (ch === ",") {
460
+ lastComma = pos;
461
+ pos += 1;
462
+ skipWhitespace();
463
+ nextStart = pos;
464
+ while (pos < cookiesString.length && notSpecialChar()) pos += 1;
465
+ if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
466
+ cookiesSeparatorFound = true;
467
+ pos = nextStart;
468
+ cookiesStrings.push(cookiesString.slice(start, lastComma));
469
+ start = pos;
470
+ } else pos = lastComma + 1;
471
+ } else pos += 1;
472
+ }
473
+ if (!cookiesSeparatorFound || pos >= cookiesString.length) cookiesStrings.push(cookiesString.slice(start));
474
+ }
475
+ return cookiesStrings;
476
+ }
477
+ const defer = typeof setImmediate === "undefined" ? (fn) => fn() : setImmediate;
478
+ function send(event, data, type) {
479
+ if (type) defaultContentType(event, type);
480
+ return new Promise((resolve) => {
481
+ defer(() => {
482
+ if (!event.handled) event.node.res.end(data);
483
+ resolve();
484
+ });
485
+ });
486
+ }
487
+ function sendNoContent(event, code) {
488
+ if (event.handled) return;
489
+ if (!code && event.node.res.statusCode !== 200) code = event.node.res.statusCode;
490
+ const _code = sanitizeStatusCode(code, 204);
491
+ if (_code === 204) event.node.res.removeHeader("content-length");
492
+ event.node.res.writeHead(_code);
493
+ event.node.res.end();
494
+ }
495
+ function setResponseStatus(event, code, text) {
496
+ if (code) event.node.res.statusCode = sanitizeStatusCode(code, event.node.res.statusCode);
497
+ if (text) event.node.res.statusMessage = sanitizeStatusMessage(text);
498
+ }
499
+ function defaultContentType(event, type) {
500
+ if (type && event.node.res.statusCode !== 304 && !event.node.res.getHeader("content-type")) event.node.res.setHeader("content-type", type);
501
+ }
502
+ function sendRedirect(event, location, code = 302) {
503
+ event.node.res.statusCode = sanitizeStatusCode(code, event.node.res.statusCode);
504
+ event.node.res.setHeader("location", location);
505
+ const html = `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=${location.replace(/"/g, "%22")}"></head></html>`;
506
+ return send(event, html, MIMES.html);
507
+ }
508
+ function isStream(data) {
509
+ if (!data || typeof data !== "object") return false;
510
+ if (typeof data.pipe === "function") {
511
+ if (typeof data._read === "function") return true;
512
+ if (typeof data.abort === "function") return true;
513
+ }
514
+ if (typeof data.pipeTo === "function") return true;
515
+ return false;
516
+ }
517
+ function isWebResponse(data) {
518
+ return typeof Response !== "undefined" && data instanceof Response;
519
+ }
520
+ function sendStream(event, stream) {
521
+ if (!stream || typeof stream !== "object") throw new Error("[h3] Invalid stream provided.");
522
+ event.node.res._data = stream;
523
+ if (!event.node.res.socket) {
524
+ event._handled = true;
525
+ return Promise.resolve();
526
+ }
527
+ if (hasProp(stream, "pipeTo") && typeof stream.pipeTo === "function") return stream.pipeTo(new WritableStream({ write(chunk) {
528
+ event.node.res.write(chunk);
529
+ } })).then(() => {
530
+ event.node.res.end();
531
+ });
532
+ if (hasProp(stream, "pipe") && typeof stream.pipe === "function") return new Promise((resolve, reject) => {
533
+ stream.pipe(event.node.res);
534
+ if (stream.on) {
535
+ stream.on("end", () => {
536
+ event.node.res.end();
537
+ resolve();
538
+ });
539
+ stream.on("error", (error) => {
540
+ reject(error);
541
+ });
542
+ }
543
+ event.node.res.on("close", () => {
544
+ if (stream.abort) stream.abort();
545
+ });
546
+ });
547
+ throw new Error("[h3] Invalid or incompatible stream provided.");
548
+ }
549
+ function sendWebResponse(event, response) {
550
+ for (const [key, value] of response.headers) if (key === "set-cookie") event.node.res.appendHeader(key, splitCookiesString(value));
551
+ else event.node.res.setHeader(key, value);
552
+ if (response.status) event.node.res.statusCode = sanitizeStatusCode(response.status, event.node.res.statusCode);
553
+ if (response.statusText) event.node.res.statusMessage = sanitizeStatusMessage(response.statusText);
554
+ if (response.redirected) event.node.res.setHeader("location", response.url);
555
+ if (!response.body) {
556
+ event.node.res.end();
557
+ return;
558
+ }
559
+ return sendStream(event, response.body);
560
+ }
561
+ const getSessionPromise = Symbol("getSession");
562
+ var H3Event = class {
563
+ "__is_event__" = true;
564
+ node;
565
+ web;
566
+ context = {};
567
+ _method;
568
+ _path;
569
+ _headers;
570
+ _requestBody;
571
+ _handled = false;
572
+ _onBeforeResponseCalled;
573
+ _onAfterResponseCalled;
574
+ constructor(req, res) {
575
+ this.node = {
576
+ req,
577
+ res
578
+ };
579
+ }
580
+ get method() {
581
+ if (!this._method) this._method = (this.node.req.method || "GET").toUpperCase();
582
+ return this._method;
583
+ }
584
+ get path() {
585
+ return this._path || this.node.req.url || "/";
586
+ }
587
+ get headers() {
588
+ if (!this._headers) this._headers = _normalizeNodeHeaders(this.node.req.headers);
589
+ return this._headers;
590
+ }
591
+ get handled() {
592
+ return this._handled || this.node.res.writableEnded || this.node.res.headersSent;
593
+ }
594
+ respondWith(response) {
595
+ return Promise.resolve(response).then((_response) => sendWebResponse(this, _response));
596
+ }
597
+ toString() {
598
+ return `[${this.method}] ${this.path}`;
599
+ }
600
+ toJSON() {
601
+ return this.toString();
602
+ }
603
+ /** @deprecated Please use `event.node.req` instead. */
604
+ get req() {
605
+ return this.node.req;
606
+ }
607
+ /** @deprecated Please use `event.node.res` instead. */
608
+ get res() {
609
+ return this.node.res;
610
+ }
611
+ };
612
+ function createEvent(req, res) {
613
+ return new H3Event(req, res);
614
+ }
615
+ function _normalizeNodeHeaders(nodeHeaders) {
616
+ const headers = new Headers();
617
+ for (const [name, value] of Object.entries(nodeHeaders)) if (Array.isArray(value)) for (const item of value) headers.append(name, item);
618
+ else if (value) headers.set(name, value);
619
+ return headers;
620
+ }
621
+ function defineEventHandler(handler) {
622
+ if (typeof handler === "function") {
623
+ handler.__is_handler__ = true;
624
+ return handler;
625
+ }
626
+ const _hooks = {
627
+ onRequest: _normalizeArray(handler.onRequest),
628
+ onBeforeResponse: _normalizeArray(handler.onBeforeResponse)
629
+ };
630
+ const _handler = (event) => {
631
+ return _callHandler(event, handler.handler, _hooks);
632
+ };
633
+ _handler.__is_handler__ = true;
634
+ _handler.__resolve__ = handler.handler.__resolve__;
635
+ _handler.__websocket__ = handler.websocket;
636
+ return _handler;
637
+ }
638
+ function _normalizeArray(input) {
639
+ return input ? Array.isArray(input) ? input : [input] : void 0;
640
+ }
641
+ async function _callHandler(event, handler, hooks) {
642
+ if (hooks.onRequest) for (const hook of hooks.onRequest) {
643
+ await hook(event);
644
+ if (event.handled) return;
645
+ }
646
+ const response = { body: await handler(event) };
647
+ if (hooks.onBeforeResponse) for (const hook of hooks.onBeforeResponse) await hook(event, response);
648
+ return response.body;
649
+ }
650
+ const eventHandler = defineEventHandler;
651
+ function isEventHandler(input) {
652
+ return hasProp(input, "__is_handler__");
653
+ }
654
+ function toEventHandler(input, _, _route) {
655
+ if (!isEventHandler(input)) console.warn("[h3] Implicit event handler conversion is deprecated. Use `eventHandler()` or `fromNodeMiddleware()` to define event handlers.", _route && _route !== "/" ? `
656
+ Route: ${_route}` : "", `
657
+ Handler: ${input}`);
658
+ return input;
659
+ }
660
+ function defineLazyEventHandler(factory) {
661
+ let _promise;
662
+ let _resolved;
663
+ const resolveHandler = () => {
664
+ if (_resolved) return Promise.resolve(_resolved);
665
+ if (!_promise) _promise = Promise.resolve(factory()).then((r$2) => {
666
+ const handler2 = r$2.default || r$2;
667
+ if (typeof handler2 !== "function") throw new TypeError("Invalid lazy handler result. It should be a function:", handler2);
668
+ _resolved = { handler: toEventHandler(r$2.default || r$2) };
669
+ return _resolved;
670
+ });
671
+ return _promise;
672
+ };
673
+ const handler = eventHandler((event) => {
674
+ if (_resolved) return _resolved.handler(event);
675
+ return resolveHandler().then((r$2) => r$2.handler(event));
676
+ });
677
+ handler.__resolve__ = resolveHandler;
678
+ return handler;
679
+ }
680
+ const lazyEventHandler = defineLazyEventHandler;
681
+ const H3Headers = globalThis.Headers;
682
+ const H3Response = globalThis.Response;
683
+ function createApp(options = {}) {
684
+ const stack = [];
685
+ const handler = createAppEventHandler(stack, options);
686
+ const resolve = createResolver(stack);
687
+ handler.__resolve__ = resolve;
688
+ const getWebsocket = cachedFn(() => websocketOptions(resolve, options));
689
+ const app = {
690
+ use: (arg1, arg2, arg3) => use(app, arg1, arg2, arg3),
691
+ resolve,
692
+ handler,
693
+ stack,
694
+ options,
695
+ get websocket() {
696
+ return getWebsocket();
697
+ }
698
+ };
699
+ return app;
700
+ }
701
+ function use(app, arg1, arg2, arg3) {
702
+ if (Array.isArray(arg1)) for (const i$1 of arg1) use(app, i$1, arg2, arg3);
703
+ else if (Array.isArray(arg2)) for (const i$1 of arg2) use(app, arg1, i$1, arg3);
704
+ else if (typeof arg1 === "string") app.stack.push(normalizeLayer({
705
+ ...arg3,
706
+ route: arg1,
707
+ handler: arg2
708
+ }));
709
+ else if (typeof arg1 === "function") app.stack.push(normalizeLayer({
710
+ ...arg2,
711
+ handler: arg1
712
+ }));
713
+ else app.stack.push(normalizeLayer({ ...arg1 }));
714
+ return app;
715
+ }
716
+ function createAppEventHandler(stack, options) {
717
+ const spacing = options.debug ? 2 : void 0;
718
+ return eventHandler(async (event) => {
719
+ event.node.req.originalUrl = event.node.req.originalUrl || event.node.req.url || "/";
720
+ const _reqPath = event._path || event.node.req.url || "/";
721
+ let _layerPath;
722
+ if (options.onRequest) await options.onRequest(event);
723
+ for (const layer of stack) {
724
+ if (layer.route.length > 1) {
725
+ if (!_reqPath.startsWith(layer.route)) continue;
726
+ _layerPath = _reqPath.slice(layer.route.length) || "/";
727
+ } else _layerPath = _reqPath;
728
+ if (layer.match && !layer.match(_layerPath, event)) continue;
729
+ event._path = _layerPath;
730
+ event.node.req.url = _layerPath;
731
+ const val = await layer.handler(event);
732
+ const _body = val === void 0 ? void 0 : await val;
733
+ if (_body !== void 0) {
734
+ const _response = { body: _body };
735
+ if (options.onBeforeResponse) {
736
+ event._onBeforeResponseCalled = true;
737
+ await options.onBeforeResponse(event, _response);
738
+ }
739
+ await handleHandlerResponse(event, _response.body, spacing);
740
+ if (options.onAfterResponse) {
741
+ event._onAfterResponseCalled = true;
742
+ await options.onAfterResponse(event, _response);
743
+ }
744
+ return;
745
+ }
746
+ if (event.handled) {
747
+ if (options.onAfterResponse) {
748
+ event._onAfterResponseCalled = true;
749
+ await options.onAfterResponse(event, void 0);
750
+ }
751
+ return;
752
+ }
753
+ }
754
+ if (!event.handled) throw createError({
755
+ statusCode: 404,
756
+ statusMessage: `Cannot find any path matching ${event.path || "/"}.`
757
+ });
758
+ if (options.onAfterResponse) {
759
+ event._onAfterResponseCalled = true;
760
+ await options.onAfterResponse(event, void 0);
761
+ }
762
+ });
763
+ }
764
+ function createResolver(stack) {
765
+ return async (path) => {
766
+ let _layerPath;
767
+ for (const layer of stack) {
768
+ if (layer.route === "/" && !layer.handler.__resolve__) continue;
769
+ if (!path.startsWith(layer.route)) continue;
770
+ _layerPath = path.slice(layer.route.length) || "/";
771
+ if (layer.match && !layer.match(_layerPath, void 0)) continue;
772
+ let res = {
773
+ route: layer.route,
774
+ handler: layer.handler
775
+ };
776
+ if (res.handler.__resolve__) {
777
+ const _res = await res.handler.__resolve__(_layerPath);
778
+ if (!_res) continue;
779
+ res = {
780
+ ...res,
781
+ ..._res,
782
+ route: joinURL(res.route || "/", _res.route || "/")
783
+ };
784
+ }
785
+ return res;
786
+ }
787
+ };
788
+ }
789
+ function normalizeLayer(input) {
790
+ let handler = input.handler;
791
+ if (handler.handler) handler = handler.handler;
792
+ if (input.lazy) handler = lazyEventHandler(handler);
793
+ else if (!isEventHandler(handler)) handler = toEventHandler(handler, void 0, input.route);
794
+ return {
795
+ route: withoutTrailingSlash(input.route),
796
+ match: input.match,
797
+ handler
798
+ };
799
+ }
800
+ function handleHandlerResponse(event, val, jsonSpace) {
801
+ if (val === null) return sendNoContent(event);
802
+ if (val) {
803
+ if (isWebResponse(val)) return sendWebResponse(event, val);
804
+ if (isStream(val)) return sendStream(event, val);
805
+ if (val.buffer) return send(event, val);
806
+ if (val.arrayBuffer && typeof val.arrayBuffer === "function") return val.arrayBuffer().then((arrayBuffer) => {
807
+ return send(event, Buffer.from(arrayBuffer), val.type);
808
+ });
809
+ if (val instanceof Error) throw createError(val);
810
+ if (typeof val.end === "function") return true;
811
+ }
812
+ const valType = typeof val;
813
+ if (valType === "string") return send(event, val, MIMES.html);
814
+ if (valType === "object" || valType === "boolean" || valType === "number") return send(event, JSON.stringify(val, void 0, jsonSpace), MIMES.json);
815
+ if (valType === "bigint") return send(event, val.toString(), MIMES.json);
816
+ throw createError({
817
+ statusCode: 500,
818
+ statusMessage: `[h3] Cannot send ${valType} as response.`
819
+ });
820
+ }
821
+ function cachedFn(fn) {
822
+ let cache;
823
+ return () => {
824
+ if (!cache) cache = fn();
825
+ return cache;
826
+ };
827
+ }
828
+ function websocketOptions(evResolver, appOptions) {
829
+ return {
830
+ ...appOptions.websocket,
831
+ async resolve(info) {
832
+ const url = info.request?.url || info.url || "/";
833
+ const { pathname } = typeof url === "string" ? parseURL(url) : url;
834
+ return (await evResolver(pathname))?.handler?.__websocket__ || {};
835
+ }
836
+ };
837
+ }
838
+ function fromNodeMiddleware(handler) {
839
+ if (isEventHandler(handler)) return handler;
840
+ if (typeof handler !== "function") throw new TypeError("Invalid handler. It should be a function:", handler);
841
+ return eventHandler((event) => {
842
+ return callNodeListener(handler, event.node.req, event.node.res);
843
+ });
844
+ }
845
+ function toNodeListener(app) {
846
+ const toNodeHandle = async function(req, res) {
847
+ const event = createEvent(req, res);
848
+ try {
849
+ await app.handler(event);
850
+ } catch (_error) {
851
+ const error = createError(_error);
852
+ if (!isError(_error)) error.unhandled = true;
853
+ setResponseStatus(event, error.statusCode, error.statusMessage);
854
+ if (app.options.onError) await app.options.onError(error, event);
855
+ if (event.handled) return;
856
+ if (error.unhandled || error.fatal) console.error("[h3]", error.fatal ? "[fatal]" : "[unhandled]", error);
857
+ if (app.options.onBeforeResponse && !event._onBeforeResponseCalled) await app.options.onBeforeResponse(event, { body: error });
858
+ await sendError(event, error, !!app.options.debug);
859
+ if (app.options.onAfterResponse && !event._onAfterResponseCalled) await app.options.onAfterResponse(event, { body: error });
860
+ }
861
+ };
862
+ return toNodeHandle;
863
+ }
864
+ function callNodeListener(handler, req, res) {
865
+ const isMiddleware = handler.length > 2;
866
+ return new Promise((resolve, reject) => {
867
+ const next = (err) => {
868
+ if (isMiddleware) {
869
+ res.off("close", next);
870
+ res.off("error", next);
871
+ }
872
+ return err ? reject(createError(err)) : resolve(void 0);
873
+ };
874
+ try {
875
+ const returned = handler(req, res, next);
876
+ if (isMiddleware && returned === void 0) {
877
+ res.once("close", next);
878
+ res.once("error", next);
879
+ } else resolve(returned);
880
+ } catch (error) {
881
+ next(error);
882
+ }
883
+ });
884
+ }
885
+
886
+ //#endregion
887
+ //#region ../../node_modules/.pnpm/ansis@4.2.0/node_modules/ansis/index.cjs
888
+ var require_ansis = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/ansis@4.2.0/node_modules/ansis/index.cjs": ((exports, module) => {
889
+ let e, t, r, { defineProperty: l, setPrototypeOf: n, create: o, keys: s } = Object, i = "", { round: c, max: a$1 } = Math, p = (e$1) => {
890
+ let t$1 = /([a-f\d]{3,6})/i.exec(e$1)?.[1], r$2 = t$1?.length, l$1 = parseInt(6 ^ r$2 ? 3 ^ r$2 ? "0" : t$1[0] + t$1[0] + t$1[1] + t$1[1] + t$1[2] + t$1[2] : t$1, 16);
891
+ return [
892
+ l$1 >> 16 & 255,
893
+ l$1 >> 8 & 255,
894
+ 255 & l$1
895
+ ];
896
+ }, u = (e$1, t$1, r$2) => e$1 ^ t$1 || t$1 ^ r$2 ? 16 + 36 * c(e$1 / 51) + 6 * c(t$1 / 51) + c(r$2 / 51) : 8 > e$1 ? 16 : e$1 > 248 ? 231 : c(24 * (e$1 - 8) / 247) + 232, d = (e$1) => {
897
+ let t$1, r$2, l$1, n$1, o$1;
898
+ return 8 > e$1 ? 30 + e$1 : 16 > e$1 ? e$1 - 8 + 90 : (232 > e$1 ? (o$1 = (e$1 -= 16) % 36, t$1 = (e$1 / 36 | 0) / 5, r$2 = (o$1 / 6 | 0) / 5, l$1 = o$1 % 6 / 5) : t$1 = r$2 = l$1 = (10 * (e$1 - 232) + 8) / 255, n$1 = 2 * a$1(t$1, r$2, l$1), n$1 ? 30 + (c(l$1) << 2 | c(r$2) << 1 | c(t$1)) + (2 ^ n$1 ? 0 : 60) : 30);
899
+ }, f = (() => {
900
+ let r$2 = (e$1) => o$1.some(((t$1) => e$1.test(t$1))), l$1 = globalThis, n$1 = l$1.process ?? {}, o$1 = n$1.argv ?? [], i$1 = n$1.env ?? {}, c$1 = -1;
901
+ try {
902
+ e = "," + s(i$1).join(",");
903
+ } catch (e$1) {
904
+ i$1 = {}, c$1 = 0;
905
+ }
906
+ let a$2 = "FORCE_COLOR", p$1 = {
907
+ false: 0,
908
+ 0: 0,
909
+ 1: 1,
910
+ 2: 2,
911
+ 3: 3
912
+ }[i$1[a$2]] ?? -1, u$1 = a$2 in i$1 && p$1 || r$2(/^--color=?(true|always)?$/);
913
+ return u$1 && (c$1 = p$1), ~c$1 || (c$1 = ((r$3, l$2, n$2) => (t = r$3.TERM, {
914
+ "24bit": 3,
915
+ truecolor: 3,
916
+ ansi256: 2,
917
+ ansi: 1
918
+ }[r$3.COLORTERM] || (r$3.CI ? /,GITHUB/.test(e) ? 3 : 1 : l$2 && "dumb" !== t ? n$2 ? 3 : /-256/.test(t) ? 2 : 1 : 0)))(i$1, !!i$1.PM2_HOME || i$1.NEXT_RUNTIME?.includes("edge") || !!n$1.stdout?.isTTY, "win32" === n$1.platform)), !p$1 || i$1.NO_COLOR || r$2(/^--(no-color|color=(false|never))$/) ? 0 : l$1.window?.chrome || u$1 && !c$1 ? 3 : c$1;
919
+ })(), g = {
920
+ open: i,
921
+ close: i
922
+ }, h = 39, b = 49, O = {}, m = ({ p: e$1 }, { open: t$1, close: l$1 }) => {
923
+ let o$1 = (e$2, ...r$2) => {
924
+ if (!e$2) {
925
+ if (t$1 && t$1 === l$1) return t$1;
926
+ if ((e$2 ?? i) === i) return i;
927
+ }
928
+ let n$1, s$2 = e$2.raw ? String.raw({ raw: e$2 }, ...r$2) : i + e$2, c$2 = o$1.p, a$2 = c$2.o, p$1 = c$2.c;
929
+ if (s$2.includes("\x1B")) for (; c$2; c$2 = c$2.p) {
930
+ let { open: e$3, close: t$2 } = c$2, r$3 = t$2.length, l$2 = i, o$2 = 0;
931
+ if (r$3) for (; ~(n$1 = s$2.indexOf(t$2, o$2)); o$2 = n$1 + r$3) l$2 += s$2.slice(o$2, n$1) + e$3;
932
+ s$2 = l$2 + s$2.slice(o$2);
933
+ }
934
+ return a$2 + (s$2.includes("\n") ? s$2.replace(/(\r?\n)/g, p$1 + "$1" + a$2) : s$2) + p$1;
935
+ }, s$1 = t$1, c$1 = l$1;
936
+ return e$1 && (s$1 = e$1.o + t$1, c$1 = l$1 + e$1.c), n(o$1, r), o$1.p = {
937
+ open: t$1,
938
+ close: l$1,
939
+ o: s$1,
940
+ c: c$1,
941
+ p: e$1
942
+ }, o$1.open = s$1, o$1.close = c$1, o$1;
943
+ };
944
+ const w = new function e$1(t$1 = f) {
945
+ let s$1 = {
946
+ Ansis: e$1,
947
+ level: t$1,
948
+ isSupported: () => a$2,
949
+ strip: (e$2) => e$2.replace(/[›][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, i),
950
+ extend(e$2) {
951
+ for (let t$2 in e$2) {
952
+ let r$2 = e$2[t$2], l$1 = (typeof r$2)[0];
953
+ "s" === l$1 ? (c$1(t$2, T(...p(r$2))), c$1(_(t$2), v(...p(r$2)))) : c$1(t$2, r$2, "f" === l$1);
954
+ }
955
+ return r = o({}, O), n(s$1, r), s$1;
956
+ }
957
+ }, c$1 = (e$2, t$2, r$2) => {
958
+ O[e$2] = { get() {
959
+ let n$1 = r$2 ? (...e$3) => m(this, t$2(...e$3)) : m(this, t$2);
960
+ return l(this, e$2, { value: n$1 }), n$1;
961
+ } };
962
+ }, a$2 = t$1 > 0, w$1 = (e$2, t$2) => a$2 ? {
963
+ open: `[${e$2}m`,
964
+ close: `[${t$2}m`
965
+ } : g, y = (e$2) => (t$2) => e$2(...p(t$2)), R = (e$2, t$2) => (r$2, l$1, n$1) => w$1(`${e$2}8;2;${r$2};${l$1};${n$1}`, t$2), $ = (e$2, t$2) => (r$2, l$1, n$1) => w$1(((e$3, t$3, r$3) => d(u(e$3, t$3, r$3)))(r$2, l$1, n$1) + e$2, t$2), x = (e$2) => (t$2, r$2, l$1) => e$2(u(t$2, r$2, l$1)), T = R(3, h), v = R(4, b), C = (e$2) => w$1("38;5;" + e$2, h), E = (e$2) => w$1("48;5;" + e$2, b);
966
+ 2 === t$1 ? (T = x(C), v = x(E)) : 1 === t$1 && (T = $(0, h), v = $(10, b), C = (e$2) => w$1(d(e$2), h), E = (e$2) => w$1(d(e$2) + 10, b));
967
+ let M, I = {
968
+ fg: C,
969
+ bg: E,
970
+ rgb: T,
971
+ bgRgb: v,
972
+ hex: y(T),
973
+ bgHex: y(v),
974
+ visible: g,
975
+ reset: w$1(0, 0),
976
+ bold: w$1(1, 22),
977
+ dim: w$1(2, 22),
978
+ italic: w$1(3, 23),
979
+ underline: w$1(4, 24),
980
+ inverse: w$1(7, 27),
981
+ hidden: w$1(8, 28),
982
+ strikethrough: w$1(9, 29)
983
+ }, _ = (e$2) => "bg" + e$2[0].toUpperCase() + e$2.slice(1), k = "Bright";
984
+ return "black,red,green,yellow,blue,magenta,cyan,white,gray".split(",").map(((e$2, t$2) => {
985
+ M = _(e$2), 8 > t$2 ? (I[e$2 + k] = w$1(90 + t$2, h), I[M + k] = w$1(100 + t$2, b)) : t$2 = 60, I[e$2] = w$1(30 + t$2, h), I[M] = w$1(40 + t$2, b);
986
+ })), s$1.extend(I);
987
+ }();
988
+ module.exports = w, w.default = w;
989
+ }) });
990
+
991
+ //#endregion
992
+ //#region ../../node_modules/.pnpm/ansis@4.2.0/node_modules/ansis/index.mjs
993
+ var import_ansis = /* @__PURE__ */ __toESM(require_ansis(), 1);
994
+ var ansis_default = import_ansis.default;
995
+ const { Ansis, fg, bg, rgb, bgRgb, hex, bgHex, reset, inverse, hidden, visible, bold, dim, italic, underline, strikethrough, black, red, green, yellow, blue, magenta, cyan, white, gray, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bgGray, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright } = import_ansis.default;
996
+
997
+ //#endregion
998
+ //#region ../../node_modules/.pnpm/get-port-please@3.2.0/node_modules/get-port-please/dist/index.mjs
999
+ const unsafePorts = /* @__PURE__ */ new Set([
1000
+ 1,
1001
+ 7,
1002
+ 9,
1003
+ 11,
1004
+ 13,
1005
+ 15,
1006
+ 17,
1007
+ 19,
1008
+ 20,
1009
+ 21,
1010
+ 22,
1011
+ 23,
1012
+ 25,
1013
+ 37,
1014
+ 42,
1015
+ 43,
1016
+ 53,
1017
+ 69,
1018
+ 77,
1019
+ 79,
1020
+ 87,
1021
+ 95,
1022
+ 101,
1023
+ 102,
1024
+ 103,
1025
+ 104,
1026
+ 109,
1027
+ 110,
1028
+ 111,
1029
+ 113,
1030
+ 115,
1031
+ 117,
1032
+ 119,
1033
+ 123,
1034
+ 135,
1035
+ 137,
1036
+ 139,
1037
+ 143,
1038
+ 161,
1039
+ 179,
1040
+ 389,
1041
+ 427,
1042
+ 465,
1043
+ 512,
1044
+ 513,
1045
+ 514,
1046
+ 515,
1047
+ 526,
1048
+ 530,
1049
+ 531,
1050
+ 532,
1051
+ 540,
1052
+ 548,
1053
+ 554,
1054
+ 556,
1055
+ 563,
1056
+ 587,
1057
+ 601,
1058
+ 636,
1059
+ 989,
1060
+ 990,
1061
+ 993,
1062
+ 995,
1063
+ 1719,
1064
+ 1720,
1065
+ 1723,
1066
+ 2049,
1067
+ 3659,
1068
+ 4045,
1069
+ 5060,
1070
+ 5061,
1071
+ 6e3,
1072
+ 6566,
1073
+ 6665,
1074
+ 6666,
1075
+ 6667,
1076
+ 6668,
1077
+ 6669,
1078
+ 6697,
1079
+ 10080
1080
+ ]);
1081
+ function isUnsafePort(port) {
1082
+ return unsafePorts.has(port);
1083
+ }
1084
+ function isSafePort(port) {
1085
+ return !isUnsafePort(port);
1086
+ }
1087
+ var GetPortError = class extends Error {
1088
+ constructor(message, opts) {
1089
+ super(message, opts);
1090
+ this.message = message;
1091
+ }
1092
+ name = "GetPortError";
1093
+ };
1094
+ function _log(verbose, message) {
1095
+ if (verbose) console.log(`[get-port] ${message}`);
1096
+ }
1097
+ function _generateRange(from, to) {
1098
+ if (to < from) return [];
1099
+ const r$2 = [];
1100
+ for (let index = from; index <= to; index++) r$2.push(index);
1101
+ return r$2;
1102
+ }
1103
+ function _tryPort(port, host) {
1104
+ return new Promise((resolve) => {
1105
+ const server = createServer();
1106
+ server.unref();
1107
+ server.on("error", () => {
1108
+ resolve(false);
1109
+ });
1110
+ server.listen({
1111
+ port,
1112
+ host
1113
+ }, () => {
1114
+ const { port: port2 } = server.address();
1115
+ server.close(() => {
1116
+ resolve(isSafePort(port2) && port2);
1117
+ });
1118
+ });
1119
+ });
1120
+ }
1121
+ function _getLocalHosts(additional) {
1122
+ const hosts = new Set(additional);
1123
+ for (const _interface of Object.values(networkInterfaces())) for (const config of _interface || []) if (config.address && !config.internal && !config.address.startsWith("fe80::") && !config.address.startsWith("169.254")) hosts.add(config.address);
1124
+ return [...hosts];
1125
+ }
1126
+ async function _findPort(ports, host) {
1127
+ for (const port of ports) {
1128
+ const r$2 = await _tryPort(port, host);
1129
+ if (r$2) return r$2;
1130
+ }
1131
+ }
1132
+ function _fmtOnHost(hostname) {
1133
+ return hostname ? `on host ${JSON.stringify(hostname)}` : "on any host";
1134
+ }
1135
+ const HOSTNAME_RE = /^(?!-)[\d.:A-Za-z-]{1,63}(?<!-)$/;
1136
+ function _validateHostname(hostname, _public, verbose) {
1137
+ if (hostname && !HOSTNAME_RE.test(hostname)) {
1138
+ const fallbackHost = _public ? "0.0.0.0" : "127.0.0.1";
1139
+ _log(verbose, `Invalid hostname: ${JSON.stringify(hostname)}. Using ${JSON.stringify(fallbackHost)} as fallback.`);
1140
+ return fallbackHost;
1141
+ }
1142
+ return hostname;
1143
+ }
1144
+ async function getPort(_userOptions = {}) {
1145
+ if (typeof _userOptions === "number" || typeof _userOptions === "string") _userOptions = { port: Number.parseInt(_userOptions + "") || 0 };
1146
+ const _port = Number(_userOptions.port ?? process.env.PORT);
1147
+ const _userSpecifiedAnyPort = Boolean(_userOptions.port || _userOptions.ports?.length || _userOptions.portRange?.length);
1148
+ const options = {
1149
+ random: _port === 0,
1150
+ ports: [],
1151
+ portRange: [],
1152
+ alternativePortRange: _userSpecifiedAnyPort ? [] : [3e3, 3100],
1153
+ verbose: false,
1154
+ ..._userOptions,
1155
+ port: _port,
1156
+ host: _validateHostname(_userOptions.host ?? process.env.HOST, _userOptions.public, _userOptions.verbose)
1157
+ };
1158
+ if (options.random && !_userSpecifiedAnyPort) return getRandomPort(options.host);
1159
+ const portsToCheck = [
1160
+ options.port,
1161
+ ...options.ports,
1162
+ ..._generateRange(...options.portRange)
1163
+ ].filter((port) => {
1164
+ if (!port) return false;
1165
+ if (!isSafePort(port)) {
1166
+ _log(options.verbose, `Ignoring unsafe port: ${port}`);
1167
+ return false;
1168
+ }
1169
+ return true;
1170
+ });
1171
+ if (portsToCheck.length === 0) portsToCheck.push(3e3);
1172
+ let availablePort = await _findPort(portsToCheck, options.host);
1173
+ if (!availablePort && options.alternativePortRange.length > 0) {
1174
+ availablePort = await _findPort(_generateRange(...options.alternativePortRange), options.host);
1175
+ if (portsToCheck.length > 0) {
1176
+ let message = `Unable to find an available port (tried ${portsToCheck.join("-")} ${_fmtOnHost(options.host)}).`;
1177
+ if (availablePort) message += ` Using alternative port ${availablePort}.`;
1178
+ _log(options.verbose, message);
1179
+ }
1180
+ }
1181
+ if (!availablePort && _userOptions.random !== false) {
1182
+ availablePort = await getRandomPort(options.host);
1183
+ if (availablePort) _log(options.verbose, `Using random port ${availablePort}`);
1184
+ }
1185
+ if (!availablePort) {
1186
+ const triedRanges = [
1187
+ options.port,
1188
+ options.portRange.join("-"),
1189
+ options.alternativePortRange.join("-")
1190
+ ].filter(Boolean).join(", ");
1191
+ throw new GetPortError(`Unable to find an available port ${_fmtOnHost(options.host)} (tried ${triedRanges})`);
1192
+ }
1193
+ return availablePort;
1194
+ }
1195
+ async function getRandomPort(host) {
1196
+ const port = await checkPort(0, host);
1197
+ if (port === false) throw new GetPortError(`Unable to find a random port ${_fmtOnHost(host)}`);
1198
+ return port;
1199
+ }
1200
+ async function checkPort(port, host = process.env.HOST, verbose) {
1201
+ if (!host) host = _getLocalHosts([void 0, "0.0.0.0"]);
1202
+ if (!Array.isArray(host)) return _tryPort(port, host);
1203
+ for (const _host of host) {
1204
+ const _port = await _tryPort(port, _host);
1205
+ if (_port === false) {
1206
+ if (port < 1024 && verbose) _log(verbose, `Unable to listen to the privileged port ${port} ${_fmtOnHost(_host)}`);
1207
+ return false;
1208
+ }
1209
+ if (port === 0 && _port !== 0) port = _port;
1210
+ }
1211
+ return port;
1212
+ }
1213
+
1214
+ //#endregion
1215
+ //#region src/node/constants.ts
1216
+ const MARK_CHECK = ansis_default.green("✔");
1217
+ const MARK_INFO = ansis_default.blue("ℹ");
1218
+ const MARK_ERROR = ansis_default.red("✖");
1219
+ const MARK_NODE = "⬢";
1220
+
1221
+ //#endregion
1222
+ //#region src/node/ws.ts
1223
+ async function createWsServer(options) {
1224
+ const rpcHost = options.context.rpc;
1225
+ const port = options.portWebSocket ?? await getPort({
1226
+ port: 7812,
1227
+ random: true
1228
+ });
1229
+ const wsClients = /* @__PURE__ */ new Set();
1230
+ const preset = createWsRpcPreset({
1231
+ port,
1232
+ onConnected: (ws) => {
1233
+ wsClients.add(ws);
1234
+ console.log(ansis_default.green`${MARK_CHECK} Websocket client connected`);
1235
+ },
1236
+ onDisconnected: (ws) => {
1237
+ wsClients.delete(ws);
1238
+ console.log(ansis_default.red`${MARK_CHECK} Websocket client disconnected`);
1239
+ }
1240
+ });
1241
+ const rpc = createRpcServer(rpcHost.functions, {
1242
+ preset,
1243
+ rpcOptions: { onError(error, name) {
1244
+ console.error(ansis_default.red`⬢ RPC error on executing "${ansis_default.bold(name)}":`);
1245
+ console.error(error);
1246
+ throw error;
1247
+ } }
1248
+ });
1249
+ const getMetadata = async () => {
1250
+ return {
1251
+ backend: "websocket",
1252
+ websocket: port
1253
+ };
1254
+ };
1255
+ return {
1256
+ port,
1257
+ rpc,
1258
+ functions: rpcHost,
1259
+ getMetadata
1260
+ };
1261
+ }
1262
+
1263
+ //#endregion
1264
+ //#region src/node/server.ts
1265
+ async function createDevToolsMiddleware(options) {
1266
+ const app = createApp();
1267
+ const { rpc, getMetadata } = await createWsServer(options);
1268
+ app.use("/api/connection.json", eventHandler(async (event) => {
1269
+ event.node.res.setHeader("Content-Type", "application/json");
1270
+ return event.node.res.end(JSON.stringify(await getMetadata()));
1271
+ }));
1272
+ app.use(fromNodeMiddleware(sirv(dirClientStandalone, {
1273
+ dev: true,
1274
+ single: true
1275
+ })));
1276
+ return {
1277
+ h3: app,
1278
+ middleware: toNodeListener(app),
1279
+ rpc
1280
+ };
1281
+ }
1282
+
1283
+ //#endregion
1284
+ //#region src/node/plugins/server.ts
1285
+ /**
1286
+ * Core plugin for enabling Vite DevTools
1287
+ */
1288
+ function DevToolsServer() {
1289
+ return {
1290
+ name: "vite:devtools:server",
1291
+ enforce: "post",
1292
+ apply: "serve",
1293
+ async configureServer(viteDevServer) {
1294
+ const context = await createDevToolsContext(viteDevServer.config, viteDevServer);
1295
+ const { middleware } = await createDevToolsMiddleware({
1296
+ cwd: viteDevServer.config.root,
1297
+ context
1298
+ });
1299
+ viteDevServer.middlewares.use("/__vite_devtools__/", middleware);
1300
+ }
1301
+ };
1302
+ }
1303
+
1304
+ //#endregion
1305
+ //#region src/node/plugins/index.ts
1306
+ function DevTools(options = {}) {
1307
+ const { builtinDevTools = true } = options;
1308
+ const plugins = [DevToolsInjection(), DevToolsServer()];
1309
+ if (builtinDevTools) plugins.push(DevToolsViteUI());
1310
+ return plugins;
1311
+ }
1312
+
1313
+ //#endregion
1314
+ export { DevTools, MARK_NODE, ansis_default, createApp, createDevToolsContext, createDevToolsMiddleware, eventHandler, getPort, sendRedirect, toNodeListener };