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