scordi-extension 1.14.1

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 (132) hide show
  1. package/README.md +243 -0
  2. package/dist/.vite/manifest.json +67 -0
  3. package/dist/assets/DataExtractBlock-B7AuVonx.js +6 -0
  4. package/dist/assets/index-B9PKMhAi.js +6 -0
  5. package/dist/assets/index-CMlx_xZE.css +1 -0
  6. package/dist/assets/index-CZjAbH8z.js +1 -0
  7. package/dist/assets/index-DkFIvNAm.css +1 -0
  8. package/dist/assets/index-r5QRyJ4m.js +1 -0
  9. package/dist/assets/index.html-BIbPySIb.js +74 -0
  10. package/dist/assets/index.html-cr-_Qdxq.js +49 -0
  11. package/dist/assets/index.ts-BqxJYCmp.js +160 -0
  12. package/dist/assets/internal-messages-Drf0Gb9U.js +1 -0
  13. package/dist/assets/loading-page-1924caaa.js +51 -0
  14. package/dist/assets/main.tsx-BEyI95mZ.js +2 -0
  15. package/dist/assets/main.tsx-BKzdlur-.js +2 -0
  16. package/dist/assets/main.tsx-loader-BYP9L25W.js +13 -0
  17. package/dist/assets/main.tsx-loader-FYb0LhDu.js +13 -0
  18. package/dist/assets/schemas-C8r0jYHO.js +21 -0
  19. package/dist/blocks/AiParseDataBlock.d.ts +183 -0
  20. package/dist/blocks/AiParseDataBlock.d.ts.map +1 -0
  21. package/dist/blocks/ClearValueFormBlock.d.ts +49 -0
  22. package/dist/blocks/ClearValueFormBlock.d.ts.map +1 -0
  23. package/dist/blocks/DataExtractBlock.d.ts +23 -0
  24. package/dist/blocks/DataExtractBlock.d.ts.map +1 -0
  25. package/dist/blocks/ElementExistsBlock.d.ts +45 -0
  26. package/dist/blocks/ElementExistsBlock.d.ts.map +1 -0
  27. package/dist/blocks/EventClickBlock.d.ts +67 -0
  28. package/dist/blocks/EventClickBlock.d.ts.map +1 -0
  29. package/dist/blocks/FetchApiBlock.d.ts +49 -0
  30. package/dist/blocks/FetchApiBlock.d.ts.map +1 -0
  31. package/dist/blocks/GetAttributeValueBlock.d.ts +49 -0
  32. package/dist/blocks/GetAttributeValueBlock.d.ts.map +1 -0
  33. package/dist/blocks/GetElementDataBlock.d.ts +88 -0
  34. package/dist/blocks/GetElementDataBlock.d.ts.map +1 -0
  35. package/dist/blocks/GetTextBlock.d.ts +85 -0
  36. package/dist/blocks/GetTextBlock.d.ts.map +1 -0
  37. package/dist/blocks/GetValueFormBlock.d.ts +49 -0
  38. package/dist/blocks/GetValueFormBlock.d.ts.map +1 -0
  39. package/dist/blocks/KeypressBlock.d.ts +31 -0
  40. package/dist/blocks/KeypressBlock.d.ts.map +1 -0
  41. package/dist/blocks/SaveAssetsBlock.d.ts +45 -0
  42. package/dist/blocks/SaveAssetsBlock.d.ts.map +1 -0
  43. package/dist/blocks/ScrollBlock.d.ts +65 -0
  44. package/dist/blocks/ScrollBlock.d.ts.map +1 -0
  45. package/dist/blocks/SetValueFormBlock.d.ts +53 -0
  46. package/dist/blocks/SetValueFormBlock.d.ts.map +1 -0
  47. package/dist/blocks/WaitBlock.d.ts +19 -0
  48. package/dist/blocks/WaitBlock.d.ts.map +1 -0
  49. package/dist/blocks/index.d.ts +667 -0
  50. package/dist/blocks/index.d.ts.map +1 -0
  51. package/dist/blocks/types.d.ts +53 -0
  52. package/dist/blocks/types.d.ts.map +1 -0
  53. package/dist/content/elements/finders/CssSelector.d.ts +8 -0
  54. package/dist/content/elements/finders/CssSelector.d.ts.map +1 -0
  55. package/dist/content/elements/finders/ElementSelector.d.ts +6 -0
  56. package/dist/content/elements/finders/ElementSelector.d.ts.map +1 -0
  57. package/dist/content/elements/finders/IframeSelector.d.ts +6 -0
  58. package/dist/content/elements/finders/IframeSelector.d.ts.map +1 -0
  59. package/dist/content/elements/finders/ShadowDOMSelector.d.ts +20 -0
  60. package/dist/content/elements/finders/ShadowDOMSelector.d.ts.map +1 -0
  61. package/dist/content/elements/finders/XPathFinder.d.ts +6 -0
  62. package/dist/content/elements/finders/XPathFinder.d.ts.map +1 -0
  63. package/dist/content/elements/index.d.ts +13 -0
  64. package/dist/content/elements/index.d.ts.map +1 -0
  65. package/dist/content/elements/utils/CSSSelectorGenerator.d.ts +23 -0
  66. package/dist/content/elements/utils/CSSSelectorGenerator.d.ts.map +1 -0
  67. package/dist/content/elements/utils/XPathGenerator.d.ts +25 -0
  68. package/dist/content/elements/utils/XPathGenerator.d.ts.map +1 -0
  69. package/dist/logo.png +0 -0
  70. package/dist/manifest.json +58 -0
  71. package/dist/public/logo.png +0 -0
  72. package/dist/sdk/EightGClient.d.ts +18 -0
  73. package/dist/sdk/EightGClient.d.ts.map +1 -0
  74. package/dist/sdk/errors.d.ts +10 -0
  75. package/dist/sdk/errors.d.ts.map +1 -0
  76. package/dist/sdk/index.d.ts +4 -0
  77. package/dist/sdk/index.d.ts.map +1 -0
  78. package/dist/sdk/index.js +7904 -0
  79. package/dist/sdk/logo.png +0 -0
  80. package/dist/sdk/types.d.ts +109 -0
  81. package/dist/sdk/types.d.ts.map +1 -0
  82. package/dist/service-worker-loader.js +1 -0
  83. package/dist/src/blocks/AiParseDataBlock.ts.js +101 -0
  84. package/dist/src/blocks/ClearValueFormBlock.ts.js +55 -0
  85. package/dist/src/blocks/DataExtractBlock.ts.js +28 -0
  86. package/dist/src/blocks/ElementExistsBlock.ts.js +26 -0
  87. package/dist/src/blocks/EventClickBlock.ts.js +143 -0
  88. package/dist/src/blocks/FetchApiBlock.ts.js +50 -0
  89. package/dist/src/blocks/GetAttributeValueBlock.ts.js +33 -0
  90. package/dist/src/blocks/GetElementDataBlock.ts.js +114 -0
  91. package/dist/src/blocks/GetTextBlock.ts.js +152 -0
  92. package/dist/src/blocks/GetValueFormBlock.ts.js +52 -0
  93. package/dist/src/blocks/KeypressBlock.ts.js +89 -0
  94. package/dist/src/blocks/SaveAssetsBlock.ts.js +35 -0
  95. package/dist/src/blocks/ScrollBlock.ts.js +111 -0
  96. package/dist/src/blocks/SetValueFormBlock.ts.js +56 -0
  97. package/dist/src/blocks/WaitBlock.ts.js +24 -0
  98. package/dist/src/blocks/index.ts.js +163 -0
  99. package/dist/src/blocks/types.ts.js +11 -0
  100. package/dist/src/content/elements/finders/CssSelector.ts.js +51 -0
  101. package/dist/src/content/elements/finders/ElementSelector.ts.js +20 -0
  102. package/dist/src/content/elements/finders/IframeSelector.ts.js +32 -0
  103. package/dist/src/content/elements/finders/ShadowDOMSelector.ts.js +38 -0
  104. package/dist/src/content/elements/finders/XPathFinder.ts.js +32 -0
  105. package/dist/src/content/elements/index.ts.js +26 -0
  106. package/dist/src/content/elements/utils/CSSSelectorGenerator.ts.js +72 -0
  107. package/dist/src/content/elements/utils/XPathGenerator.ts.js +62 -0
  108. package/dist/src/content/handler/ExternalMessageHandler.ts.js +78 -0
  109. package/dist/src/content/handler/InternalMessageHandler.ts.js +18 -0
  110. package/dist/src/content/kernel/MessageKernel.ts.js +83 -0
  111. package/dist/src/content/main.tsx-loader.js +22 -0
  112. package/dist/src/content/main.tsx.js +13 -0
  113. package/dist/src/content/utils/index.ts.js +1 -0
  114. package/dist/src/content/utils/synchronizedLock.ts.js +35 -0
  115. package/dist/src/popup/index.html +11 -0
  116. package/dist/src/types/internal-messages.ts.js +15 -0
  117. package/dist/types/external-messages.d.ts +29 -0
  118. package/dist/types/external-messages.d.ts.map +1 -0
  119. package/dist/types/index.d.ts +3 -0
  120. package/dist/types/index.d.ts.map +1 -0
  121. package/dist/types/internal-messages.d.ts +58 -0
  122. package/dist/types/internal-messages.d.ts.map +1 -0
  123. package/dist/vendor/.vite-deps-chunk-PR4QN5HX.js__v--ba9031c0.js +42 -0
  124. package/dist/vendor/.vite-deps-jsonata.js__v--ba9031c0.js +5761 -0
  125. package/dist/vendor/.vite-deps-zod.js__v--ba9031c0.js +12651 -0
  126. package/dist/vendor/crx-client-port.js +66 -0
  127. package/dist/vendor/crx-client-preamble.js +4 -0
  128. package/dist/vendor/react-refresh.js +670 -0
  129. package/dist/vendor/vite-client.js +1098 -0
  130. package/dist/vendor/vite-dist-client-env.mjs.js +19 -0
  131. package/dist/vendor/webcomponents-custom-elements.js +47 -0
  132. package/package.json +70 -0
@@ -0,0 +1,1098 @@
1
+ import { HMRPort } from '/vendor/crx-client-port.js';import '/vendor/webcomponents-custom-elements.js';import "/vendor/vite-dist-client-env.mjs.js";
2
+
3
+ //#region ../../node_modules/.pnpm/@oxc-project+runtime@0.81.0/node_modules/@oxc-project/runtime/src/helpers/esm/typeof.js
4
+ function _typeof(o) {
5
+ "@babel/helpers - typeof";
6
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
7
+ return typeof o$1;
8
+ } : function(o$1) {
9
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
10
+ }, _typeof(o);
11
+ }
12
+
13
+ //#endregion
14
+ //#region ../../node_modules/.pnpm/@oxc-project+runtime@0.81.0/node_modules/@oxc-project/runtime/src/helpers/esm/toPrimitive.js
15
+ function toPrimitive(t, r) {
16
+ if ("object" != _typeof(t) || !t) return t;
17
+ var e = t[Symbol.toPrimitive];
18
+ if (void 0 !== e) {
19
+ var i = e.call(t, r || "default");
20
+ if ("object" != _typeof(i)) return i;
21
+ throw new TypeError("@@toPrimitive must return a primitive value.");
22
+ }
23
+ return ("string" === r ? String : Number)(t);
24
+ }
25
+
26
+ //#endregion
27
+ //#region ../../node_modules/.pnpm/@oxc-project+runtime@0.81.0/node_modules/@oxc-project/runtime/src/helpers/esm/toPropertyKey.js
28
+ function toPropertyKey(t) {
29
+ var i = toPrimitive(t, "string");
30
+ return "symbol" == _typeof(i) ? i : i + "";
31
+ }
32
+
33
+ //#endregion
34
+ //#region ../../node_modules/.pnpm/@oxc-project+runtime@0.81.0/node_modules/@oxc-project/runtime/src/helpers/esm/defineProperty.js
35
+ function _defineProperty(e, r, t) {
36
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
37
+ value: t,
38
+ enumerable: !0,
39
+ configurable: !0,
40
+ writable: !0
41
+ }) : e[r] = t, e;
42
+ }
43
+
44
+ //#endregion
45
+ //#region src/shared/hmr.ts
46
+ var HMRContext = class {
47
+ constructor(hmrClient$1, ownerPath) {
48
+ this.hmrClient = hmrClient$1;
49
+ this.ownerPath = ownerPath;
50
+ _defineProperty(this, "newListeners", void 0);
51
+ if (!hmrClient$1.dataMap.has(ownerPath)) hmrClient$1.dataMap.set(ownerPath, {});
52
+ const mod = hmrClient$1.hotModulesMap.get(ownerPath);
53
+ if (mod) mod.callbacks = [];
54
+ const staleListeners = hmrClient$1.ctxToListenersMap.get(ownerPath);
55
+ if (staleListeners) for (const [event, staleFns] of staleListeners) {
56
+ const listeners = hmrClient$1.customListenersMap.get(event);
57
+ if (listeners) hmrClient$1.customListenersMap.set(event, listeners.filter((l) => !staleFns.includes(l)));
58
+ }
59
+ this.newListeners = /* @__PURE__ */ new Map();
60
+ hmrClient$1.ctxToListenersMap.set(ownerPath, this.newListeners);
61
+ }
62
+ get data() {
63
+ return this.hmrClient.dataMap.get(this.ownerPath);
64
+ }
65
+ accept(deps, callback) {
66
+ if (typeof deps === "function" || !deps) this.acceptDeps([this.ownerPath], ([mod]) => deps?.(mod));
67
+ else if (typeof deps === "string") this.acceptDeps([deps], ([mod]) => callback?.(mod));
68
+ else if (Array.isArray(deps)) this.acceptDeps(deps, callback);
69
+ else throw new Error(`invalid hot.accept() usage.`);
70
+ }
71
+ acceptExports(_, callback) {
72
+ this.acceptDeps([this.ownerPath], ([mod]) => callback?.(mod));
73
+ }
74
+ dispose(cb) {
75
+ this.hmrClient.disposeMap.set(this.ownerPath, cb);
76
+ }
77
+ prune(cb) {
78
+ this.hmrClient.pruneMap.set(this.ownerPath, cb);
79
+ }
80
+ decline() {}
81
+ invalidate(message) {
82
+ const firstInvalidatedBy = this.hmrClient.currentFirstInvalidatedBy ?? this.ownerPath;
83
+ this.hmrClient.notifyListeners("vite:invalidate", {
84
+ path: this.ownerPath,
85
+ message,
86
+ firstInvalidatedBy
87
+ });
88
+ this.send("vite:invalidate", {
89
+ path: this.ownerPath,
90
+ message,
91
+ firstInvalidatedBy
92
+ });
93
+ this.hmrClient.logger.debug(`invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`);
94
+ }
95
+ on(event, cb) {
96
+ const addToMap = (map) => {
97
+ const existing = map.get(event) || [];
98
+ existing.push(cb);
99
+ map.set(event, existing);
100
+ };
101
+ addToMap(this.hmrClient.customListenersMap);
102
+ addToMap(this.newListeners);
103
+ }
104
+ off(event, cb) {
105
+ const removeFromMap = (map) => {
106
+ const existing = map.get(event);
107
+ if (existing === void 0) return;
108
+ const pruned = existing.filter((l) => l !== cb);
109
+ if (pruned.length === 0) {
110
+ map.delete(event);
111
+ return;
112
+ }
113
+ map.set(event, pruned);
114
+ };
115
+ removeFromMap(this.hmrClient.customListenersMap);
116
+ removeFromMap(this.newListeners);
117
+ }
118
+ send(event, data) {
119
+ this.hmrClient.send({
120
+ type: "custom",
121
+ event,
122
+ data
123
+ });
124
+ }
125
+ acceptDeps(deps, callback = () => {}) {
126
+ const mod = this.hmrClient.hotModulesMap.get(this.ownerPath) || {
127
+ id: this.ownerPath,
128
+ callbacks: []
129
+ };
130
+ mod.callbacks.push({
131
+ deps,
132
+ fn: callback
133
+ });
134
+ this.hmrClient.hotModulesMap.set(this.ownerPath, mod);
135
+ }
136
+ };
137
+ var HMRClient = class {
138
+ constructor(logger, transport$1, importUpdatedModule) {
139
+ this.logger = logger;
140
+ this.transport = transport$1;
141
+ this.importUpdatedModule = importUpdatedModule;
142
+ _defineProperty(this, "hotModulesMap", /* @__PURE__ */ new Map());
143
+ _defineProperty(this, "disposeMap", /* @__PURE__ */ new Map());
144
+ _defineProperty(this, "pruneMap", /* @__PURE__ */ new Map());
145
+ _defineProperty(this, "dataMap", /* @__PURE__ */ new Map());
146
+ _defineProperty(this, "customListenersMap", /* @__PURE__ */ new Map());
147
+ _defineProperty(this, "ctxToListenersMap", /* @__PURE__ */ new Map());
148
+ _defineProperty(this, "currentFirstInvalidatedBy", void 0);
149
+ _defineProperty(this, "updateQueue", []);
150
+ _defineProperty(this, "pendingUpdateQueue", false);
151
+ }
152
+ async notifyListeners(event, data) {
153
+ const cbs = this.customListenersMap.get(event);
154
+ if (cbs) await Promise.allSettled(cbs.map((cb) => cb(data)));
155
+ }
156
+ send(payload) {
157
+ this.transport.send(payload).catch((err) => {
158
+ this.logger.error(err);
159
+ });
160
+ }
161
+ clear() {
162
+ this.hotModulesMap.clear();
163
+ this.disposeMap.clear();
164
+ this.pruneMap.clear();
165
+ this.dataMap.clear();
166
+ this.customListenersMap.clear();
167
+ this.ctxToListenersMap.clear();
168
+ }
169
+ async prunePaths(paths) {
170
+ await Promise.all(paths.map((path) => {
171
+ const disposer = this.disposeMap.get(path);
172
+ if (disposer) return disposer(this.dataMap.get(path));
173
+ }));
174
+ paths.forEach((path) => {
175
+ const fn = this.pruneMap.get(path);
176
+ if (fn) fn(this.dataMap.get(path));
177
+ });
178
+ }
179
+ warnFailedUpdate(err, path) {
180
+ if (!(err instanceof Error) || !err.message.includes("fetch")) this.logger.error(err);
181
+ this.logger.error(`Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`);
182
+ }
183
+ /**
184
+ * buffer multiple hot updates triggered by the same src change
185
+ * so that they are invoked in the same order they were sent.
186
+ * (otherwise the order may be inconsistent because of the http request round trip)
187
+ */
188
+ async queueUpdate(payload) {
189
+ this.updateQueue.push(this.fetchUpdate(payload));
190
+ if (!this.pendingUpdateQueue) {
191
+ this.pendingUpdateQueue = true;
192
+ await Promise.resolve();
193
+ this.pendingUpdateQueue = false;
194
+ const loading = [...this.updateQueue];
195
+ this.updateQueue = [];
196
+ (await Promise.all(loading)).forEach((fn) => fn && fn());
197
+ }
198
+ }
199
+ async fetchUpdate(update) {
200
+ const { path, acceptedPath, firstInvalidatedBy } = update;
201
+ const mod = this.hotModulesMap.get(path);
202
+ if (!mod) return;
203
+ let fetchedModule;
204
+ const isSelfUpdate = path === acceptedPath;
205
+ const qualifiedCallbacks = mod.callbacks.filter(({ deps }) => deps.includes(acceptedPath));
206
+ if (isSelfUpdate || qualifiedCallbacks.length > 0) {
207
+ const disposer = this.disposeMap.get(acceptedPath);
208
+ if (disposer) await disposer(this.dataMap.get(acceptedPath));
209
+ try {
210
+ fetchedModule = await this.importUpdatedModule(update);
211
+ } catch (e) {
212
+ this.warnFailedUpdate(e, acceptedPath);
213
+ }
214
+ }
215
+ return () => {
216
+ try {
217
+ this.currentFirstInvalidatedBy = firstInvalidatedBy;
218
+ for (const { deps, fn } of qualifiedCallbacks) fn(deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0));
219
+ const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
220
+ this.logger.debug(`hot updated: ${loggedPath}`);
221
+ } finally {
222
+ this.currentFirstInvalidatedBy = void 0;
223
+ }
224
+ };
225
+ }
226
+ };
227
+
228
+ //#endregion
229
+ //#region ../../node_modules/.pnpm/nanoid@5.1.5/node_modules/nanoid/non-secure/index.js
230
+ let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
231
+ let nanoid = (size = 21) => {
232
+ let id = "";
233
+ let i = size | 0;
234
+ while (i--) id += urlAlphabet[Math.random() * 64 | 0];
235
+ return id;
236
+ };
237
+
238
+ //#endregion
239
+ //#region src/shared/constants.ts
240
+ let SOURCEMAPPING_URL = "sourceMa";
241
+ SOURCEMAPPING_URL += "ppingURL";
242
+
243
+ //#endregion
244
+ //#region src/shared/utils.ts
245
+ const isWindows = typeof process !== "undefined" && process.platform === "win32";
246
+ const AsyncFunction = async function() {}.constructor;
247
+ function promiseWithResolvers() {
248
+ let resolve;
249
+ let reject;
250
+ const promise = new Promise((_resolve, _reject) => {
251
+ resolve = _resolve;
252
+ reject = _reject;
253
+ });
254
+ return {
255
+ promise,
256
+ resolve,
257
+ reject
258
+ };
259
+ }
260
+
261
+ //#endregion
262
+ //#region src/shared/moduleRunnerTransport.ts
263
+ function reviveInvokeError(e) {
264
+ const error = new Error(e.message || "Unknown invoke error");
265
+ Object.assign(error, e, { runnerError: /* @__PURE__ */ new Error("RunnerError") });
266
+ return error;
267
+ }
268
+ const createInvokeableTransport = (transport$1) => {
269
+ if (transport$1.invoke) return {
270
+ ...transport$1,
271
+ async invoke(name, data) {
272
+ const result = await transport$1.invoke({
273
+ type: "custom",
274
+ event: "vite:invoke",
275
+ data: {
276
+ id: "send",
277
+ name,
278
+ data
279
+ }
280
+ });
281
+ if ("error" in result) throw reviveInvokeError(result.error);
282
+ return result.result;
283
+ }
284
+ };
285
+ if (!transport$1.send || !transport$1.connect) throw new Error("transport must implement send and connect when invoke is not implemented");
286
+ const rpcPromises = /* @__PURE__ */ new Map();
287
+ return {
288
+ ...transport$1,
289
+ connect({ onMessage, onDisconnection }) {
290
+ return transport$1.connect({
291
+ onMessage(payload) {
292
+ if (payload.type === "custom" && payload.event === "vite:invoke") {
293
+ const data = payload.data;
294
+ if (data.id.startsWith("response:")) {
295
+ const invokeId = data.id.slice(9);
296
+ const promise = rpcPromises.get(invokeId);
297
+ if (!promise) return;
298
+ if (promise.timeoutId) clearTimeout(promise.timeoutId);
299
+ rpcPromises.delete(invokeId);
300
+ const { error, result } = data.data;
301
+ if (error) promise.reject(error);
302
+ else promise.resolve(result);
303
+ return;
304
+ }
305
+ }
306
+ onMessage(payload);
307
+ },
308
+ onDisconnection
309
+ });
310
+ },
311
+ disconnect() {
312
+ rpcPromises.forEach((promise) => {
313
+ promise.reject(/* @__PURE__ */ new Error(`transport was disconnected, cannot call ${JSON.stringify(promise.name)}`));
314
+ });
315
+ rpcPromises.clear();
316
+ return transport$1.disconnect?.();
317
+ },
318
+ send(data) {
319
+ return transport$1.send(data);
320
+ },
321
+ async invoke(name, data) {
322
+ const promiseId = nanoid();
323
+ const wrappedData = {
324
+ type: "custom",
325
+ event: "vite:invoke",
326
+ data: {
327
+ name,
328
+ id: `send:${promiseId}`,
329
+ data
330
+ }
331
+ };
332
+ const sendPromise = transport$1.send(wrappedData);
333
+ const { promise, resolve, reject } = promiseWithResolvers();
334
+ const timeout = transport$1.timeout ?? 6e4;
335
+ let timeoutId;
336
+ if (timeout > 0) {
337
+ timeoutId = setTimeout(() => {
338
+ rpcPromises.delete(promiseId);
339
+ reject(/* @__PURE__ */ new Error(`transport invoke timed out after ${timeout}ms (data: ${JSON.stringify(wrappedData)})`));
340
+ }, timeout);
341
+ timeoutId?.unref?.();
342
+ }
343
+ rpcPromises.set(promiseId, {
344
+ resolve,
345
+ reject,
346
+ name,
347
+ timeoutId
348
+ });
349
+ if (sendPromise) sendPromise.catch((err) => {
350
+ clearTimeout(timeoutId);
351
+ rpcPromises.delete(promiseId);
352
+ reject(err);
353
+ });
354
+ try {
355
+ return await promise;
356
+ } catch (err) {
357
+ throw reviveInvokeError(err);
358
+ }
359
+ }
360
+ };
361
+ };
362
+ const normalizeModuleRunnerTransport = (transport$1) => {
363
+ const invokeableTransport = createInvokeableTransport(transport$1);
364
+ let isConnected = !invokeableTransport.connect;
365
+ let connectingPromise;
366
+ return {
367
+ ...transport$1,
368
+ ...invokeableTransport.connect ? { async connect(onMessage) {
369
+ if (isConnected) return;
370
+ if (connectingPromise) {
371
+ await connectingPromise;
372
+ return;
373
+ }
374
+ const maybePromise = invokeableTransport.connect({
375
+ onMessage: onMessage ?? (() => {}),
376
+ onDisconnection() {
377
+ isConnected = false;
378
+ }
379
+ });
380
+ if (maybePromise) {
381
+ connectingPromise = maybePromise;
382
+ await connectingPromise;
383
+ connectingPromise = void 0;
384
+ }
385
+ isConnected = true;
386
+ } } : {},
387
+ ...invokeableTransport.disconnect ? { async disconnect() {
388
+ if (!isConnected) return;
389
+ if (connectingPromise) await connectingPromise;
390
+ isConnected = false;
391
+ await invokeableTransport.disconnect();
392
+ } } : {},
393
+ async send(data) {
394
+ if (!invokeableTransport.send) return;
395
+ if (!isConnected) if (connectingPromise) await connectingPromise;
396
+ else throw new Error("send was called before connect");
397
+ await invokeableTransport.send(data);
398
+ },
399
+ async invoke(name, data) {
400
+ if (!isConnected) if (connectingPromise) await connectingPromise;
401
+ else throw new Error("invoke was called before connect");
402
+ return invokeableTransport.invoke(name, data);
403
+ }
404
+ };
405
+ };
406
+ const createWebSocketModuleRunnerTransport = (options) => {
407
+ const pingInterval = options.pingInterval ?? 3e4;
408
+ let ws;
409
+ let pingIntervalId;
410
+ return {
411
+ async connect({ onMessage, onDisconnection }) {
412
+ const socket = options.createConnection();
413
+ socket.addEventListener("message", async ({ data }) => {
414
+ onMessage(JSON.parse(data));
415
+ });
416
+ let isOpened = socket.readyState === socket.OPEN;
417
+ if (!isOpened) await new Promise((resolve, reject) => {
418
+ socket.addEventListener("open", () => {
419
+ isOpened = true;
420
+ resolve();
421
+ }, { once: true });
422
+ socket.addEventListener("close", async () => {
423
+ if (!isOpened) {
424
+ reject(/* @__PURE__ */ new Error("WebSocket closed without opened."));
425
+ return;
426
+ }
427
+ onMessage({
428
+ type: "custom",
429
+ event: "vite:ws:disconnect",
430
+ data: { webSocket: socket }
431
+ });
432
+ onDisconnection();
433
+ });
434
+ });
435
+ onMessage({
436
+ type: "custom",
437
+ event: "vite:ws:connect",
438
+ data: { webSocket: socket }
439
+ });
440
+ ws = socket;
441
+ pingIntervalId = setInterval(() => {
442
+ if (socket.readyState === socket.OPEN) socket.send(JSON.stringify({ type: "ping" }));
443
+ }, pingInterval);
444
+ },
445
+ disconnect() {
446
+ clearInterval(pingIntervalId);
447
+ ws?.close();
448
+ },
449
+ send(data) {
450
+ ws.send(JSON.stringify(data));
451
+ }
452
+ };
453
+ };
454
+
455
+ //#endregion
456
+ //#region src/shared/hmrHandler.ts
457
+ function createHMRHandler(handler) {
458
+ const queue = new Queue();
459
+ return (payload) => queue.enqueue(() => handler(payload));
460
+ }
461
+ var Queue = class {
462
+ constructor() {
463
+ _defineProperty(this, "queue", []);
464
+ _defineProperty(this, "pending", false);
465
+ }
466
+ enqueue(promise) {
467
+ return new Promise((resolve, reject) => {
468
+ this.queue.push({
469
+ promise,
470
+ resolve,
471
+ reject
472
+ });
473
+ this.dequeue();
474
+ });
475
+ }
476
+ dequeue() {
477
+ if (this.pending) return false;
478
+ const item = this.queue.shift();
479
+ if (!item) return false;
480
+ this.pending = true;
481
+ item.promise().then(item.resolve).catch(item.reject).finally(() => {
482
+ this.pending = false;
483
+ this.dequeue();
484
+ });
485
+ return true;
486
+ }
487
+ };
488
+
489
+ //#endregion
490
+ //#region src/client/overlay.ts
491
+ const hmrConfigName = "vite.config.ts";
492
+ const base$1 = "/" || "/";
493
+ function h(e, attrs = {}, ...children) {
494
+ const elem = document.createElement(e);
495
+ for (const [k, v] of Object.entries(attrs)) elem.setAttribute(k, v);
496
+ elem.append(...children);
497
+ return elem;
498
+ }
499
+ const templateStyle = `
500
+ :host {
501
+ position: fixed;
502
+ top: 0;
503
+ left: 0;
504
+ width: 100%;
505
+ height: 100%;
506
+ z-index: 99999;
507
+ --monospace: 'SFMono-Regular', Consolas,
508
+ 'Liberation Mono', Menlo, Courier, monospace;
509
+ --red: #ff5555;
510
+ --yellow: #e2aa53;
511
+ --purple: #cfa4ff;
512
+ --cyan: #2dd9da;
513
+ --dim: #c9c9c9;
514
+
515
+ --window-background: #181818;
516
+ --window-color: #d8d8d8;
517
+ }
518
+
519
+ .backdrop {
520
+ position: fixed;
521
+ z-index: 99999;
522
+ top: 0;
523
+ left: 0;
524
+ width: 100%;
525
+ height: 100%;
526
+ overflow-y: scroll;
527
+ margin: 0;
528
+ background: rgba(0, 0, 0, 0.66);
529
+ }
530
+
531
+ .window {
532
+ font-family: var(--monospace);
533
+ line-height: 1.5;
534
+ max-width: 80vw;
535
+ color: var(--window-color);
536
+ box-sizing: border-box;
537
+ margin: 30px auto;
538
+ padding: 2.5vh 4vw;
539
+ position: relative;
540
+ background: var(--window-background);
541
+ border-radius: 6px 6px 8px 8px;
542
+ box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);
543
+ overflow: hidden;
544
+ border-top: 8px solid var(--red);
545
+ direction: ltr;
546
+ text-align: left;
547
+ }
548
+
549
+ pre {
550
+ font-family: var(--monospace);
551
+ font-size: 16px;
552
+ margin-top: 0;
553
+ margin-bottom: 1em;
554
+ overflow-x: scroll;
555
+ scrollbar-width: none;
556
+ }
557
+
558
+ pre::-webkit-scrollbar {
559
+ display: none;
560
+ }
561
+
562
+ pre.frame::-webkit-scrollbar {
563
+ display: block;
564
+ height: 5px;
565
+ }
566
+
567
+ pre.frame::-webkit-scrollbar-thumb {
568
+ background: #999;
569
+ border-radius: 5px;
570
+ }
571
+
572
+ pre.frame {
573
+ scrollbar-width: thin;
574
+ }
575
+
576
+ .message {
577
+ line-height: 1.3;
578
+ font-weight: 600;
579
+ white-space: pre-wrap;
580
+ }
581
+
582
+ .message-body {
583
+ color: var(--red);
584
+ }
585
+
586
+ .plugin {
587
+ color: var(--purple);
588
+ }
589
+
590
+ .file {
591
+ color: var(--cyan);
592
+ margin-bottom: 0;
593
+ white-space: pre-wrap;
594
+ word-break: break-all;
595
+ }
596
+
597
+ .frame {
598
+ color: var(--yellow);
599
+ }
600
+
601
+ .stack {
602
+ font-size: 13px;
603
+ color: var(--dim);
604
+ }
605
+
606
+ .tip {
607
+ font-size: 13px;
608
+ color: #999;
609
+ border-top: 1px dotted #999;
610
+ padding-top: 13px;
611
+ line-height: 1.8;
612
+ }
613
+
614
+ code {
615
+ font-size: 13px;
616
+ font-family: var(--monospace);
617
+ color: var(--yellow);
618
+ }
619
+
620
+ .file-link {
621
+ text-decoration: underline;
622
+ cursor: pointer;
623
+ }
624
+
625
+ kbd {
626
+ line-height: 1.5;
627
+ font-family: ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
628
+ font-size: 0.75rem;
629
+ font-weight: 700;
630
+ background-color: rgb(38, 40, 44);
631
+ color: rgb(166, 167, 171);
632
+ padding: 0.15rem 0.3rem;
633
+ border-radius: 0.25rem;
634
+ border-width: 0.0625rem 0.0625rem 0.1875rem;
635
+ border-style: solid;
636
+ border-color: rgb(54, 57, 64);
637
+ border-image: initial;
638
+ }
639
+ `;
640
+ const createTemplate = () => h("div", {
641
+ class: "backdrop",
642
+ part: "backdrop"
643
+ }, h("div", {
644
+ class: "window",
645
+ part: "window"
646
+ }, h("pre", {
647
+ class: "message",
648
+ part: "message"
649
+ }, h("span", {
650
+ class: "plugin",
651
+ part: "plugin"
652
+ }), h("span", {
653
+ class: "message-body",
654
+ part: "message-body"
655
+ })), h("pre", {
656
+ class: "file",
657
+ part: "file"
658
+ }), h("pre", {
659
+ class: "frame",
660
+ part: "frame"
661
+ }), h("pre", {
662
+ class: "stack",
663
+ part: "stack"
664
+ }), h("div", {
665
+ class: "tip",
666
+ part: "tip"
667
+ }, "Click outside, press ", h("kbd", {}, "Esc"), " key, or fix the code to dismiss.", h("br"), "You can also disable this overlay by setting ", h("code", { part: "config-option-name" }, "server.hmr.overlay"), " to ", h("code", { part: "config-option-value" }, "false"), " in ", h("code", { part: "config-file-name" }, hmrConfigName), ".")), h("style", {}, templateStyle));
668
+ const fileRE = /(?:file:\/\/)?(?:[a-zA-Z]:\\|\/).*?:\d+:\d+/g;
669
+ const codeframeRE = /^(?:>?\s*\d+\s+\|.*|\s+\|\s*\^.*)\r?\n/gm;
670
+ const { HTMLElement = class {} } = globalThis;
671
+ var ErrorOverlay = class extends HTMLElement {
672
+ constructor(err, links = true) {
673
+ super();
674
+ _defineProperty(this, "root", void 0);
675
+ _defineProperty(this, "closeOnEsc", void 0);
676
+ this.root = this.attachShadow({ mode: "open" });
677
+ this.root.appendChild(createTemplate());
678
+ codeframeRE.lastIndex = 0;
679
+ const hasFrame = err.frame && codeframeRE.test(err.frame);
680
+ const message = hasFrame ? err.message.replace(codeframeRE, "") : err.message;
681
+ if (err.plugin) this.text(".plugin", `[plugin:${err.plugin}] `);
682
+ this.text(".message-body", message.trim());
683
+ const [file] = (err.loc?.file || err.id || "unknown file").split(`?`);
684
+ if (err.loc) this.text(".file", `${file}:${err.loc.line}:${err.loc.column}`, links);
685
+ else if (err.id) this.text(".file", file);
686
+ if (hasFrame) this.text(".frame", err.frame.trim());
687
+ this.text(".stack", err.stack, links);
688
+ this.root.querySelector(".window").addEventListener("click", (e) => {
689
+ e.stopPropagation();
690
+ });
691
+ this.addEventListener("click", () => {
692
+ this.close();
693
+ });
694
+ this.closeOnEsc = (e) => {
695
+ if (e.key === "Escape" || e.code === "Escape") this.close();
696
+ };
697
+ document.addEventListener("keydown", this.closeOnEsc);
698
+ }
699
+ text(selector, text, linkFiles = false) {
700
+ const el = this.root.querySelector(selector);
701
+ if (!linkFiles) el.textContent = text;
702
+ else {
703
+ let curIndex = 0;
704
+ let match;
705
+ fileRE.lastIndex = 0;
706
+ while (match = fileRE.exec(text)) {
707
+ const { 0: file, index } = match;
708
+ const frag = text.slice(curIndex, index);
709
+ el.appendChild(document.createTextNode(frag));
710
+ const link = document.createElement("a");
711
+ link.textContent = file;
712
+ link.className = "file-link";
713
+ link.onclick = () => {
714
+ fetch(new URL(`${base$1}__open-in-editor?file=${encodeURIComponent(file)}`, import.meta.url));
715
+ };
716
+ el.appendChild(link);
717
+ curIndex += frag.length + file.length;
718
+ }
719
+ if (curIndex < text.length) el.appendChild(document.createTextNode(text.slice(curIndex)));
720
+ }
721
+ }
722
+ close() {
723
+ this.parentNode?.removeChild(this);
724
+ document.removeEventListener("keydown", this.closeOnEsc);
725
+ }
726
+ };
727
+ const overlayId = "vite-error-overlay";
728
+ const { customElements } = globalThis;
729
+ if (customElements && !customElements.get(overlayId)) customElements.define(overlayId, ErrorOverlay);
730
+
731
+ //#endregion
732
+ //#region src/client/client.ts
733
+ console.debug("[vite] connecting...");
734
+ const importMetaUrl = new URL(import.meta.url);
735
+ const serverHost = "localhost:5173/";
736
+ const socketProtocol = null || (importMetaUrl.protocol === "https:" ? "wss" : "ws");
737
+ const hmrPort = null;
738
+ const socketHost = `${"localhost" || importMetaUrl.hostname}:${hmrPort || importMetaUrl.port}${"/"}`;
739
+ const directSocketHost = "localhost:5173/";
740
+ const base = "/" || "/";
741
+ const hmrTimeout = 30000;
742
+ const wsToken = "adLV0yfLI-10";
743
+ const transport = normalizeModuleRunnerTransport((() => {
744
+ let wsTransport = createWebSocketModuleRunnerTransport({
745
+ createConnection: () => new HMRPort(`${socketProtocol}://${socketHost}?token=${wsToken}`, "vite-hmr"),
746
+ pingInterval: hmrTimeout
747
+ });
748
+ return {
749
+ async connect(handlers) {
750
+ try {
751
+ await wsTransport.connect(handlers);
752
+ } catch (e) {
753
+ if (!hmrPort) {
754
+ wsTransport = createWebSocketModuleRunnerTransport({
755
+ createConnection: () => new WebSocket(`${socketProtocol}://${directSocketHost}?token=${wsToken}`, "vite-hmr"),
756
+ pingInterval: hmrTimeout
757
+ });
758
+ try {
759
+ await wsTransport.connect(handlers);
760
+ console.info("[vite] Direct websocket connection fallback. Check out https://vite.dev/config/server-options.html#server-hmr to remove the previous connection error.");
761
+ } catch (e$1) {
762
+ if (e$1 instanceof Error && e$1.message.includes("WebSocket closed without opened.")) {
763
+ const currentScriptHostURL = new URL(import.meta.url);
764
+ const currentScriptHost = currentScriptHostURL.host + currentScriptHostURL.pathname.replace(/@vite\/client$/, "");
765
+ console.error(`[vite] failed to connect to websocket.
766
+ your current setup:
767
+ (browser) ${currentScriptHost} <--[HTTP]--> ${serverHost} (server)\n (browser) ${socketHost} <--[WebSocket (failing)]--> ${directSocketHost} (server)\nCheck out your Vite / network configuration and https://vite.dev/config/server-options.html#server-hmr .`);
768
+ }
769
+ }
770
+ return;
771
+ }
772
+ console.error(`[vite] failed to connect to websocket (${e}). `);
773
+ throw e;
774
+ }
775
+ },
776
+ async disconnect() {
777
+ await wsTransport.disconnect();
778
+ },
779
+ send(data) {
780
+ wsTransport.send(data);
781
+ }
782
+ };
783
+ })());
784
+ let willUnload = false;
785
+ if (typeof window !== "undefined") window.addEventListener?.("beforeunload", () => {
786
+ willUnload = true;
787
+ });
788
+ function cleanUrl(pathname) {
789
+ const url = new URL(pathname, "http://vite.dev");
790
+ url.searchParams.delete("direct");
791
+ return url.pathname + url.search;
792
+ }
793
+ let isFirstUpdate = true;
794
+ const outdatedLinkTags = /* @__PURE__ */ new WeakSet();
795
+ const debounceReload = (time) => {
796
+ let timer;
797
+ return () => {
798
+ if (timer) {
799
+ clearTimeout(timer);
800
+ timer = null;
801
+ }
802
+ timer = setTimeout(() => {
803
+ location.reload();
804
+ }, time);
805
+ };
806
+ };
807
+ const pageReload = debounceReload(20);
808
+ const hmrClient = new HMRClient({
809
+ error: (err) => console.error("[vite]", err),
810
+ debug: (...msg) => console.debug("[vite]", ...msg)
811
+ }, transport, async function importUpdatedModule({ acceptedPath, timestamp, explicitImportRequired, isWithinCircularImport }) {
812
+ const [acceptedPathWithoutQuery, query] = acceptedPath.split(`?`);
813
+ const importPromise = import(
814
+ /* @vite-ignore */
815
+ base + acceptedPathWithoutQuery.slice(1) + `?${explicitImportRequired ? "import&" : ""}t=${timestamp}${query ? `&${query}` : ""}`
816
+ );
817
+ if (isWithinCircularImport) importPromise.catch(() => {
818
+ console.info(`[hmr] ${acceptedPath} failed to apply HMR as it's within a circular import. Reloading page to reset the execution order. To debug and break the circular import, you can run \`vite --debug hmr\` to log the circular dependency path if a file change triggered it.`);
819
+ pageReload();
820
+ });
821
+ return await importPromise;
822
+ });
823
+ transport.connect(createHMRHandler(handleMessage));
824
+ async function handleMessage(payload) {
825
+ switch (payload.type) {
826
+ case "connected":
827
+ console.debug(`[vite] connected.`);
828
+ break;
829
+ case "update":
830
+ await hmrClient.notifyListeners("vite:beforeUpdate", payload);
831
+ if (hasDocument) if (isFirstUpdate && hasErrorOverlay()) {
832
+ location.reload();
833
+ return;
834
+ } else {
835
+ if (enableOverlay) clearErrorOverlay();
836
+ isFirstUpdate = false;
837
+ }
838
+ await Promise.all(payload.updates.map(async (update) => {
839
+ if (update.type === "js-update") return hmrClient.queueUpdate(update);
840
+ const { path, timestamp } = update;
841
+ const searchUrl = cleanUrl(path);
842
+ const el = Array.from(document.querySelectorAll("link")).find((e) => !outdatedLinkTags.has(e) && cleanUrl(e.href).includes(searchUrl));
843
+ if (!el) return;
844
+ const newPath = `${base}${searchUrl.slice(1)}${searchUrl.includes("?") ? "&" : "?"}t=${timestamp}`;
845
+ return new Promise((resolve) => {
846
+ const newLinkTag = el.cloneNode();
847
+ newLinkTag.href = new URL(newPath, el.href).href;
848
+ const removeOldEl = () => {
849
+ el.remove();
850
+ console.debug(`[vite] css hot updated: ${searchUrl}`);
851
+ resolve();
852
+ };
853
+ newLinkTag.addEventListener("load", removeOldEl);
854
+ newLinkTag.addEventListener("error", removeOldEl);
855
+ outdatedLinkTags.add(el);
856
+ el.after(newLinkTag);
857
+ });
858
+ }));
859
+ await hmrClient.notifyListeners("vite:afterUpdate", payload);
860
+ break;
861
+ case "custom":
862
+ await hmrClient.notifyListeners(payload.event, payload.data);
863
+ if (payload.event === "vite:ws:disconnect") {
864
+ if (hasDocument && !willUnload) {
865
+ console.log(`[vite] server connection lost. Polling for restart...`);
866
+ const socket = payload.data.webSocket;
867
+ const url = new URL(socket.url);
868
+ url.search = "";
869
+ await waitForSuccessfulPing(url.href);
870
+ location.reload();
871
+ }
872
+ }
873
+ break;
874
+ case "full-reload":
875
+ await hmrClient.notifyListeners("vite:beforeFullReload", payload);
876
+ if (hasDocument) if (payload.path && payload.path.endsWith(".html")) {
877
+ const pagePath = decodeURI(location.pathname);
878
+ const payloadPath = base + payload.path.slice(1);
879
+ if (pagePath === payloadPath || payload.path === "/index.html" || pagePath.endsWith("/") && pagePath + "index.html" === payloadPath) pageReload();
880
+ return;
881
+ } else pageReload();
882
+ break;
883
+ case "prune":
884
+ await hmrClient.notifyListeners("vite:beforePrune", payload);
885
+ await hmrClient.prunePaths(payload.paths);
886
+ break;
887
+ case "error":
888
+ await hmrClient.notifyListeners("vite:error", payload);
889
+ if (hasDocument) {
890
+ const err = payload.err;
891
+ if (enableOverlay) createErrorOverlay(err);
892
+ else console.error(`[vite] Internal Server Error\n${err.message}\n${err.stack}`);
893
+ }
894
+ break;
895
+ case "ping": break;
896
+ default: {
897
+ const check = payload;
898
+ return check;
899
+ }
900
+ }
901
+ }
902
+ const enableOverlay = true;
903
+ const hasDocument = "document" in globalThis;
904
+ function createErrorOverlay(err) {
905
+ clearErrorOverlay();
906
+ const { customElements: customElements$1 } = globalThis;
907
+ if (customElements$1) {
908
+ const ErrorOverlayConstructor = customElements$1.get(overlayId);
909
+ document.body.appendChild(new ErrorOverlayConstructor(err));
910
+ }
911
+ }
912
+ function clearErrorOverlay() {
913
+ document.querySelectorAll(overlayId).forEach((n) => n.close());
914
+ }
915
+ function hasErrorOverlay() {
916
+ return document.querySelectorAll(overlayId).length;
917
+ }
918
+ function waitForSuccessfulPing(socketUrl) {
919
+ if (typeof SharedWorker === "undefined") {
920
+ const visibilityManager = {
921
+ currentState: document.visibilityState,
922
+ listeners: /* @__PURE__ */ new Set()
923
+ };
924
+ const onVisibilityChange = () => {
925
+ visibilityManager.currentState = document.visibilityState;
926
+ for (const listener of visibilityManager.listeners) listener(visibilityManager.currentState);
927
+ };
928
+ document.addEventListener("visibilitychange", onVisibilityChange);
929
+ return waitForSuccessfulPingInternal(socketUrl, visibilityManager);
930
+ }
931
+ const blob = new Blob([
932
+ "\"use strict\";",
933
+ `const waitForSuccessfulPingInternal = ${waitForSuccessfulPingInternal.toString()};`,
934
+ `const fn = ${pingWorkerContentMain.toString()};`,
935
+ `fn(${JSON.stringify(socketUrl)})`
936
+ ], { type: "application/javascript" });
937
+ const objURL = URL.createObjectURL(blob);
938
+ const sharedWorker = new SharedWorker(objURL);
939
+ return new Promise((resolve, reject) => {
940
+ const onVisibilityChange = () => {
941
+ sharedWorker.port.postMessage({ visibility: document.visibilityState });
942
+ };
943
+ document.addEventListener("visibilitychange", onVisibilityChange);
944
+ sharedWorker.port.addEventListener("message", (event) => {
945
+ document.removeEventListener("visibilitychange", onVisibilityChange);
946
+ sharedWorker.port.close();
947
+ const data = event.data;
948
+ if (data.type === "error") {
949
+ reject(data.error);
950
+ return;
951
+ }
952
+ resolve();
953
+ });
954
+ onVisibilityChange();
955
+ sharedWorker.port.start();
956
+ });
957
+ }
958
+ function pingWorkerContentMain(socketUrl) {
959
+ self.addEventListener("connect", (_event) => {
960
+ const event = _event;
961
+ const port = event.ports[0];
962
+ if (!socketUrl) {
963
+ port.postMessage({
964
+ type: "error",
965
+ error: /* @__PURE__ */ new Error("socketUrl not found")
966
+ });
967
+ return;
968
+ }
969
+ const visibilityManager = {
970
+ currentState: "visible",
971
+ listeners: /* @__PURE__ */ new Set()
972
+ };
973
+ port.addEventListener("message", (event$1) => {
974
+ const { visibility } = event$1.data;
975
+ visibilityManager.currentState = visibility;
976
+ console.debug("[vite] new window visibility", visibility);
977
+ for (const listener of visibilityManager.listeners) listener(visibility);
978
+ });
979
+ port.start();
980
+ console.debug("[vite] connected from window");
981
+ waitForSuccessfulPingInternal(socketUrl, visibilityManager).then(() => {
982
+ console.debug("[vite] ping successful");
983
+ try {
984
+ port.postMessage({ type: "success" });
985
+ } catch (error) {
986
+ port.postMessage({
987
+ type: "error",
988
+ error
989
+ });
990
+ }
991
+ }, (error) => {
992
+ console.debug("[vite] error happened", error);
993
+ try {
994
+ port.postMessage({
995
+ type: "error",
996
+ error
997
+ });
998
+ } catch (error$1) {
999
+ port.postMessage({
1000
+ type: "error",
1001
+ error: error$1
1002
+ });
1003
+ }
1004
+ });
1005
+ });
1006
+ }
1007
+ async function waitForSuccessfulPingInternal(socketUrl, visibilityManager, ms = 1e3) {
1008
+ function wait(ms$1) {
1009
+ return new Promise((resolve) => setTimeout(resolve, ms$1));
1010
+ }
1011
+ async function ping() {
1012
+ try {
1013
+ const socket = new WebSocket(socketUrl, "vite-ping");
1014
+ return new Promise((resolve) => {
1015
+ function onOpen() {
1016
+ resolve(true);
1017
+ close();
1018
+ }
1019
+ function onError() {
1020
+ resolve(false);
1021
+ close();
1022
+ }
1023
+ function close() {
1024
+ socket.removeEventListener("open", onOpen);
1025
+ socket.removeEventListener("error", onError);
1026
+ socket.close();
1027
+ }
1028
+ socket.addEventListener("open", onOpen);
1029
+ socket.addEventListener("error", onError);
1030
+ });
1031
+ } catch {
1032
+ return false;
1033
+ }
1034
+ }
1035
+ function waitForWindowShow(visibilityManager$1) {
1036
+ return new Promise((resolve) => {
1037
+ const onChange = (newVisibility) => {
1038
+ if (newVisibility === "visible") {
1039
+ resolve();
1040
+ visibilityManager$1.listeners.delete(onChange);
1041
+ }
1042
+ };
1043
+ visibilityManager$1.listeners.add(onChange);
1044
+ });
1045
+ }
1046
+ if (await ping()) return;
1047
+ await wait(ms);
1048
+ while (true) if (visibilityManager.currentState === "visible") {
1049
+ if (await ping()) break;
1050
+ await wait(ms);
1051
+ } else await waitForWindowShow(visibilityManager);
1052
+ }
1053
+ const sheetsMap = /* @__PURE__ */ new Map();
1054
+ if ("document" in globalThis) document.querySelectorAll("style[data-vite-dev-id]").forEach((el) => {
1055
+ sheetsMap.set(el.getAttribute("data-vite-dev-id"), el);
1056
+ });
1057
+ const cspNonce = "document" in globalThis ? document.querySelector("meta[property=csp-nonce]")?.nonce : void 0;
1058
+ let lastInsertedStyle;
1059
+ function updateStyle(id, content) {
1060
+ let style = sheetsMap.get(id);
1061
+ if (!style) {
1062
+ style = document.createElement("style");
1063
+ style.setAttribute("type", "text/css");
1064
+ style.setAttribute("data-vite-dev-id", id);
1065
+ style.textContent = content;
1066
+ if (cspNonce) style.setAttribute("nonce", cspNonce);
1067
+ if (!lastInsertedStyle) {
1068
+ document.head.appendChild(style);
1069
+ setTimeout(() => {
1070
+ lastInsertedStyle = void 0;
1071
+ }, 0);
1072
+ } else lastInsertedStyle.insertAdjacentElement("afterend", style);
1073
+ lastInsertedStyle = style;
1074
+ } else style.textContent = content;
1075
+ sheetsMap.set(id, style);
1076
+ }
1077
+ function removeStyle(id) {
1078
+ const style = sheetsMap.get(id);
1079
+ if (style) {
1080
+ document.head.removeChild(style);
1081
+ sheetsMap.delete(id);
1082
+ }
1083
+ }
1084
+ function createHotContext(ownerPath) {
1085
+ return new HMRContext(hmrClient, ownerPath);
1086
+ }
1087
+ /**
1088
+ * urls here are dynamic import() urls that couldn't be statically analyzed
1089
+ */
1090
+ function injectQuery(url, queryToInject) {
1091
+ if (url[0] !== "." && url[0] !== "/") return url;
1092
+ const pathname = url.replace(/[?#].*$/, "");
1093
+ const { search, hash } = new URL(url, "http://vite.dev");
1094
+ return `${pathname}?${queryToInject}${search ? `&` + search.slice(1) : ""}${hash || ""}`;
1095
+ }
1096
+
1097
+ //#endregion
1098
+ export { ErrorOverlay, createHotContext, injectQuery, removeStyle, updateStyle };