Criada a API do site
This commit is contained in:
20
node_modules/vite-hot-client/dist/index.d.mts
generated
vendored
Normal file
20
node_modules/vite-hot-client/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/// <reference types="vite/client" />
|
||||
type ViteHotContext = Exclude<ImportMeta['hot'], undefined>;
|
||||
interface ViteClient {
|
||||
createHotContext: (path: string) => ViteHotContext;
|
||||
}
|
||||
/**
|
||||
* Get the module of `/@vite/client`
|
||||
*/
|
||||
declare function getViteClient(base?: string, warning?: boolean): Promise<ViteClient | undefined>;
|
||||
declare function createHotContext(path?: string, base?: string): Promise<ViteHotContext | undefined>;
|
||||
/**
|
||||
* Guess the vite client provided bases from the current pathname.
|
||||
*/
|
||||
declare function guessBasesFromPathname(pathname?: string): string[];
|
||||
/**
|
||||
* Try to resolve the vite client provided bases.
|
||||
*/
|
||||
declare function tryCreateHotContext(path?: string, bases?: string[]): Promise<ViteHotContext | undefined>;
|
||||
|
||||
export { type ViteClient, type ViteHotContext, createHotContext, getViteClient, guessBasesFromPathname, tryCreateHotContext };
|
||||
20
node_modules/vite-hot-client/dist/index.d.ts
generated
vendored
Normal file
20
node_modules/vite-hot-client/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/// <reference types="vite/client" />
|
||||
type ViteHotContext = Exclude<ImportMeta['hot'], undefined>;
|
||||
interface ViteClient {
|
||||
createHotContext: (path: string) => ViteHotContext;
|
||||
}
|
||||
/**
|
||||
* Get the module of `/@vite/client`
|
||||
*/
|
||||
declare function getViteClient(base?: string, warning?: boolean): Promise<ViteClient | undefined>;
|
||||
declare function createHotContext(path?: string, base?: string): Promise<ViteHotContext | undefined>;
|
||||
/**
|
||||
* Guess the vite client provided bases from the current pathname.
|
||||
*/
|
||||
declare function guessBasesFromPathname(pathname?: string): string[];
|
||||
/**
|
||||
* Try to resolve the vite client provided bases.
|
||||
*/
|
||||
declare function tryCreateHotContext(path?: string, bases?: string[]): Promise<ViteHotContext | undefined>;
|
||||
|
||||
export { type ViteClient, type ViteHotContext, createHotContext, getViteClient, guessBasesFromPathname, tryCreateHotContext };
|
||||
36
node_modules/vite-hot-client/dist/index.mjs
generated
vendored
Normal file
36
node_modules/vite-hot-client/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
async function getViteClient(base = "/", warning = true) {
|
||||
try {
|
||||
const url = `${base}@vite/client`;
|
||||
const res = await fetch(url);
|
||||
const text = await res.text();
|
||||
if (text.startsWith("<") || !res.headers.get("content-type")?.includes("javascript"))
|
||||
throw new Error("Not javascript");
|
||||
return await import(
|
||||
/* @vite-ignore */
|
||||
url
|
||||
);
|
||||
} catch {
|
||||
if (warning)
|
||||
console.error(`[vite-hot-client] Failed to import "${base}@vite/client"`);
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
async function createHotContext(path = "/____", base = "/") {
|
||||
const viteClient = await getViteClient(base);
|
||||
return viteClient?.createHotContext(path);
|
||||
}
|
||||
function guessBasesFromPathname(pathname = window.location.pathname) {
|
||||
return pathname.split("/").map((i, idx, arr) => arr.slice(0, idx + 1).join("/") || "/");
|
||||
}
|
||||
async function tryCreateHotContext(path = "/___", bases) {
|
||||
bases = bases ?? guessBasesFromPathname();
|
||||
for (const base of bases) {
|
||||
const viteClient = await getViteClient(base, false);
|
||||
const hot = viteClient?.createHotContext(path);
|
||||
if (hot)
|
||||
return hot;
|
||||
}
|
||||
console.error("[vite-hot-client] Failed to import vite client, tried with:", bases);
|
||||
}
|
||||
|
||||
export { createHotContext, getViteClient, guessBasesFromPathname, tryCreateHotContext };
|
||||
Reference in New Issue
Block a user