@katlux/providers 0.1.0-beta.9 → 0.1.1-alpha.100
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/LICENSE +200 -21
- package/README.md +8 -3
- package/dist/index.cjs +3225 -4848
- package/dist/index.d.cts +595 -1483
- package/dist/index.d.mts +595 -1483
- package/dist/index.d.ts +595 -1483
- package/dist/index.mjs +3197 -4850
- package/dist/nuxtAppCompat.cjs +35 -0
- package/dist/nuxtAppCompat.d.cts +21 -0
- package/dist/nuxtAppCompat.d.mts +21 -0
- package/dist/nuxtAppCompat.d.ts +21 -0
- package/dist/nuxtAppCompat.mjs +27 -0
- package/dist/nuxtAppCompat.server.cjs +45 -0
- package/dist/nuxtAppCompat.server.d.cts +21 -0
- package/dist/nuxtAppCompat.server.d.mts +21 -0
- package/dist/nuxtAppCompat.server.d.ts +21 -0
- package/dist/nuxtAppCompat.server.mjs +37 -0
- package/dist/shared/providers.C8C1HrDy.mjs +228 -0
- package/dist/shared/providers.CxZeMH3Y.cjs +241 -0
- package/package.json +25 -3
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./shared/providers.CxZeMH3Y.cjs');
|
|
4
|
+
|
|
5
|
+
function getNuxtApp() {
|
|
6
|
+
return index.getPlatformApp();
|
|
7
|
+
}
|
|
8
|
+
function getNuxtData(key, nuxtApp) {
|
|
9
|
+
const val = index.getSSRData(key, nuxtApp);
|
|
10
|
+
return { data: { value: val } };
|
|
11
|
+
}
|
|
12
|
+
async function getAsyncData(key, fetcher, nuxtApp) {
|
|
13
|
+
const val = await index.fetchWithSSR(key, fetcher, nuxtApp);
|
|
14
|
+
return { data: { value: val } };
|
|
15
|
+
}
|
|
16
|
+
function clearNuxtDataKey(key, nuxtApp) {
|
|
17
|
+
index.clearSSRData(key, nuxtApp);
|
|
18
|
+
}
|
|
19
|
+
function onNuxtReadyCallback(cb) {
|
|
20
|
+
index.onPlatformReady(cb);
|
|
21
|
+
}
|
|
22
|
+
function getRoute() {
|
|
23
|
+
return index.getAppRoute();
|
|
24
|
+
}
|
|
25
|
+
function getRouter() {
|
|
26
|
+
return index.getAppRouter();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.clearNuxtDataKey = clearNuxtDataKey;
|
|
30
|
+
exports.getAsyncData = getAsyncData;
|
|
31
|
+
exports.getNuxtApp = getNuxtApp;
|
|
32
|
+
exports.getNuxtData = getNuxtData;
|
|
33
|
+
exports.getRoute = getRoute;
|
|
34
|
+
exports.getRouter = getRouter;
|
|
35
|
+
exports.onNuxtReadyCallback = onNuxtReadyCallback;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nuxtAppCompat.ts — Backwards-compatibility wrapper mapping legacy Nuxt-named helpers
|
|
3
|
+
* to the framework-agnostic hydration bridge.
|
|
4
|
+
*/
|
|
5
|
+
declare function getNuxtApp(): any;
|
|
6
|
+
declare function getNuxtData(key: string, nuxtApp?: any): {
|
|
7
|
+
data: {
|
|
8
|
+
value: any;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
declare function getAsyncData<T>(key: string, fetcher: () => Promise<T>, nuxtApp?: any): Promise<{
|
|
12
|
+
data: {
|
|
13
|
+
value: T | null;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
declare function clearNuxtDataKey(key: string, nuxtApp?: any): void;
|
|
17
|
+
declare function onNuxtReadyCallback(cb: () => void): void;
|
|
18
|
+
declare function getRoute(): any;
|
|
19
|
+
declare function getRouter(): any;
|
|
20
|
+
|
|
21
|
+
export { clearNuxtDataKey, getAsyncData, getNuxtApp, getNuxtData, getRoute, getRouter, onNuxtReadyCallback };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nuxtAppCompat.ts — Backwards-compatibility wrapper mapping legacy Nuxt-named helpers
|
|
3
|
+
* to the framework-agnostic hydration bridge.
|
|
4
|
+
*/
|
|
5
|
+
declare function getNuxtApp(): any;
|
|
6
|
+
declare function getNuxtData(key: string, nuxtApp?: any): {
|
|
7
|
+
data: {
|
|
8
|
+
value: any;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
declare function getAsyncData<T>(key: string, fetcher: () => Promise<T>, nuxtApp?: any): Promise<{
|
|
12
|
+
data: {
|
|
13
|
+
value: T | null;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
declare function clearNuxtDataKey(key: string, nuxtApp?: any): void;
|
|
17
|
+
declare function onNuxtReadyCallback(cb: () => void): void;
|
|
18
|
+
declare function getRoute(): any;
|
|
19
|
+
declare function getRouter(): any;
|
|
20
|
+
|
|
21
|
+
export { clearNuxtDataKey, getAsyncData, getNuxtApp, getNuxtData, getRoute, getRouter, onNuxtReadyCallback };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nuxtAppCompat.ts — Backwards-compatibility wrapper mapping legacy Nuxt-named helpers
|
|
3
|
+
* to the framework-agnostic hydration bridge.
|
|
4
|
+
*/
|
|
5
|
+
declare function getNuxtApp(): any;
|
|
6
|
+
declare function getNuxtData(key: string, nuxtApp?: any): {
|
|
7
|
+
data: {
|
|
8
|
+
value: any;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
declare function getAsyncData<T>(key: string, fetcher: () => Promise<T>, nuxtApp?: any): Promise<{
|
|
12
|
+
data: {
|
|
13
|
+
value: T | null;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
declare function clearNuxtDataKey(key: string, nuxtApp?: any): void;
|
|
17
|
+
declare function onNuxtReadyCallback(cb: () => void): void;
|
|
18
|
+
declare function getRoute(): any;
|
|
19
|
+
declare function getRouter(): any;
|
|
20
|
+
|
|
21
|
+
export { clearNuxtDataKey, getAsyncData, getNuxtApp, getNuxtData, getRoute, getRouter, onNuxtReadyCallback };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { g as getPlatformApp, c as getSSRData, f as fetchWithSSR, d as clearSSRData, o as onPlatformReady, a as getAppRoute, b as getAppRouter } from './shared/providers.C8C1HrDy.mjs';
|
|
2
|
+
|
|
3
|
+
function getNuxtApp() {
|
|
4
|
+
return getPlatformApp();
|
|
5
|
+
}
|
|
6
|
+
function getNuxtData(key, nuxtApp) {
|
|
7
|
+
const val = getSSRData(key, nuxtApp);
|
|
8
|
+
return { data: { value: val } };
|
|
9
|
+
}
|
|
10
|
+
async function getAsyncData(key, fetcher, nuxtApp) {
|
|
11
|
+
const val = await fetchWithSSR(key, fetcher, nuxtApp);
|
|
12
|
+
return { data: { value: val } };
|
|
13
|
+
}
|
|
14
|
+
function clearNuxtDataKey(key, nuxtApp) {
|
|
15
|
+
clearSSRData(key, nuxtApp);
|
|
16
|
+
}
|
|
17
|
+
function onNuxtReadyCallback(cb) {
|
|
18
|
+
onPlatformReady(cb);
|
|
19
|
+
}
|
|
20
|
+
function getRoute() {
|
|
21
|
+
return getAppRoute();
|
|
22
|
+
}
|
|
23
|
+
function getRouter() {
|
|
24
|
+
return getAppRouter();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { clearNuxtDataKey, getAsyncData, getNuxtApp, getNuxtData, getRoute, getRouter, onNuxtReadyCallback };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function getNuxtApp() {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
function getNuxtData(key, nuxtApp) {
|
|
7
|
+
const val = nuxtApp?.payload?.data?.[key] ?? null;
|
|
8
|
+
return { data: { value: val } };
|
|
9
|
+
}
|
|
10
|
+
async function getAsyncData(key, fetcher, nuxtApp) {
|
|
11
|
+
if (nuxtApp?.payload?.data?.[key] !== void 0) {
|
|
12
|
+
return { data: { value: nuxtApp.payload.data[key] } };
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const res = await fetcher();
|
|
16
|
+
if (nuxtApp?.payload?.data) {
|
|
17
|
+
nuxtApp.payload.data[key] = res;
|
|
18
|
+
}
|
|
19
|
+
return { data: { value: res } };
|
|
20
|
+
} catch {
|
|
21
|
+
return { data: { value: null } };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function clearNuxtDataKey(key, nuxtApp) {
|
|
25
|
+
if (nuxtApp?.payload?.data) {
|
|
26
|
+
delete nuxtApp.payload.data[key];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function onNuxtReadyCallback(cb) {
|
|
30
|
+
setTimeout(cb, 0);
|
|
31
|
+
}
|
|
32
|
+
function getRoute() {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
function getRouter() {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.clearNuxtDataKey = clearNuxtDataKey;
|
|
40
|
+
exports.getAsyncData = getAsyncData;
|
|
41
|
+
exports.getNuxtApp = getNuxtApp;
|
|
42
|
+
exports.getNuxtData = getNuxtData;
|
|
43
|
+
exports.getRoute = getRoute;
|
|
44
|
+
exports.getRouter = getRouter;
|
|
45
|
+
exports.onNuxtReadyCallback = onNuxtReadyCallback;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nuxtAppCompat.server.ts — Server-side environment compatibility.
|
|
3
|
+
* Signatures match nuxtAppCompat.ts exactly.
|
|
4
|
+
*/
|
|
5
|
+
declare function getNuxtApp(): any;
|
|
6
|
+
declare function getNuxtData(key: string, nuxtApp?: any): {
|
|
7
|
+
data: {
|
|
8
|
+
value: any;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
declare function getAsyncData<T>(key: string, fetcher: () => Promise<T>, nuxtApp?: any): Promise<{
|
|
12
|
+
data: {
|
|
13
|
+
value: T | null;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
declare function clearNuxtDataKey(key: string, nuxtApp?: any): void;
|
|
17
|
+
declare function onNuxtReadyCallback(cb: () => void): void;
|
|
18
|
+
declare function getRoute(): any;
|
|
19
|
+
declare function getRouter(): any;
|
|
20
|
+
|
|
21
|
+
export { clearNuxtDataKey, getAsyncData, getNuxtApp, getNuxtData, getRoute, getRouter, onNuxtReadyCallback };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nuxtAppCompat.server.ts — Server-side environment compatibility.
|
|
3
|
+
* Signatures match nuxtAppCompat.ts exactly.
|
|
4
|
+
*/
|
|
5
|
+
declare function getNuxtApp(): any;
|
|
6
|
+
declare function getNuxtData(key: string, nuxtApp?: any): {
|
|
7
|
+
data: {
|
|
8
|
+
value: any;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
declare function getAsyncData<T>(key: string, fetcher: () => Promise<T>, nuxtApp?: any): Promise<{
|
|
12
|
+
data: {
|
|
13
|
+
value: T | null;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
declare function clearNuxtDataKey(key: string, nuxtApp?: any): void;
|
|
17
|
+
declare function onNuxtReadyCallback(cb: () => void): void;
|
|
18
|
+
declare function getRoute(): any;
|
|
19
|
+
declare function getRouter(): any;
|
|
20
|
+
|
|
21
|
+
export { clearNuxtDataKey, getAsyncData, getNuxtApp, getNuxtData, getRoute, getRouter, onNuxtReadyCallback };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nuxtAppCompat.server.ts — Server-side environment compatibility.
|
|
3
|
+
* Signatures match nuxtAppCompat.ts exactly.
|
|
4
|
+
*/
|
|
5
|
+
declare function getNuxtApp(): any;
|
|
6
|
+
declare function getNuxtData(key: string, nuxtApp?: any): {
|
|
7
|
+
data: {
|
|
8
|
+
value: any;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
declare function getAsyncData<T>(key: string, fetcher: () => Promise<T>, nuxtApp?: any): Promise<{
|
|
12
|
+
data: {
|
|
13
|
+
value: T | null;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
declare function clearNuxtDataKey(key: string, nuxtApp?: any): void;
|
|
17
|
+
declare function onNuxtReadyCallback(cb: () => void): void;
|
|
18
|
+
declare function getRoute(): any;
|
|
19
|
+
declare function getRouter(): any;
|
|
20
|
+
|
|
21
|
+
export { clearNuxtDataKey, getAsyncData, getNuxtApp, getNuxtData, getRoute, getRouter, onNuxtReadyCallback };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
function getNuxtApp() {
|
|
2
|
+
return null;
|
|
3
|
+
}
|
|
4
|
+
function getNuxtData(key, nuxtApp) {
|
|
5
|
+
const val = nuxtApp?.payload?.data?.[key] ?? null;
|
|
6
|
+
return { data: { value: val } };
|
|
7
|
+
}
|
|
8
|
+
async function getAsyncData(key, fetcher, nuxtApp) {
|
|
9
|
+
if (nuxtApp?.payload?.data?.[key] !== void 0) {
|
|
10
|
+
return { data: { value: nuxtApp.payload.data[key] } };
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const res = await fetcher();
|
|
14
|
+
if (nuxtApp?.payload?.data) {
|
|
15
|
+
nuxtApp.payload.data[key] = res;
|
|
16
|
+
}
|
|
17
|
+
return { data: { value: res } };
|
|
18
|
+
} catch {
|
|
19
|
+
return { data: { value: null } };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function clearNuxtDataKey(key, nuxtApp) {
|
|
23
|
+
if (nuxtApp?.payload?.data) {
|
|
24
|
+
delete nuxtApp.payload.data[key];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function onNuxtReadyCallback(cb) {
|
|
28
|
+
setTimeout(cb, 0);
|
|
29
|
+
}
|
|
30
|
+
function getRoute() {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function getRouter() {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { clearNuxtDataKey, getAsyncData, getNuxtApp, getNuxtData, getRoute, getRouter, onNuxtReadyCallback };
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
class DefaultHydrationAdapter {
|
|
2
|
+
getSSRData(key, context) {
|
|
3
|
+
const contextData = context?.payload?.data?.[key] ?? context?.ssrContext?.payload?.data?.[key];
|
|
4
|
+
if (contextData !== void 0 && contextData !== null) {
|
|
5
|
+
return contextData;
|
|
6
|
+
}
|
|
7
|
+
if (typeof window !== "undefined") {
|
|
8
|
+
const win = window;
|
|
9
|
+
const clientData = win.__KATLUX_DATA__?.[key] ?? win.__INITIAL_DATA__?.[key] ?? win.__NEXT_DATA__?.props?.pageProps?.[key] ?? win.__NUXT__?.payload?.data?.[key];
|
|
10
|
+
if (clientData !== void 0 && clientData !== null) {
|
|
11
|
+
return clientData;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
async fetchWithSSR(key, fetcher, context) {
|
|
17
|
+
const cached = this.getSSRData(key, context);
|
|
18
|
+
if (cached !== null) {
|
|
19
|
+
return cached;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const result = await fetcher();
|
|
23
|
+
if (context?.payload?.data) {
|
|
24
|
+
context.payload.data[key] = result;
|
|
25
|
+
} else if (context?.ssrContext?.payload?.data) {
|
|
26
|
+
context.ssrContext.payload.data[key] = result;
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
clearSSRData(key, context) {
|
|
34
|
+
if (context?.payload?.data) {
|
|
35
|
+
delete context.payload.data[key];
|
|
36
|
+
}
|
|
37
|
+
if (context?.ssrContext?.payload?.data) {
|
|
38
|
+
delete context.ssrContext.payload.data[key];
|
|
39
|
+
}
|
|
40
|
+
if (typeof window !== "undefined") {
|
|
41
|
+
const win = window;
|
|
42
|
+
if (win.__KATLUX_DATA__?.payload?.data) delete win.__KATLUX_DATA__.payload.data[key];
|
|
43
|
+
if (win.__INITIAL_DATA__?.payload?.data) delete win.__INITIAL_DATA__.payload.data[key];
|
|
44
|
+
if (win.__NUXT__?.payload?.data) delete win.__NUXT__.payload.data[key];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
getSSRPayload(context) {
|
|
48
|
+
if (context?.payload?.data) return context.payload.data;
|
|
49
|
+
if (context?.ssrContext?.payload?.data) return context.ssrContext.payload.data;
|
|
50
|
+
if (typeof window !== "undefined") {
|
|
51
|
+
const win = window;
|
|
52
|
+
return win.__KATLUX_DATA__?.payload?.data || win.__KATLUX_DATA__ || win.__INITIAL_DATA__?.payload?.data || win.__INITIAL_DATA__ || win.__NUXT__?.payload?.data || null;
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getGlobalNuxt() {
|
|
59
|
+
if (typeof globalThis.useNuxtApp === "function") {
|
|
60
|
+
try {
|
|
61
|
+
return globalThis.useNuxtApp();
|
|
62
|
+
} catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
class NuxtHydrationAdapter {
|
|
69
|
+
fallback = new DefaultHydrationAdapter();
|
|
70
|
+
getSSRData(key, context) {
|
|
71
|
+
const app = context || getGlobalNuxt();
|
|
72
|
+
if (app?.runWithContext && typeof globalThis.useNuxtData === "function") {
|
|
73
|
+
try {
|
|
74
|
+
const res = app.runWithContext(() => globalThis.useNuxtData(key));
|
|
75
|
+
const val = res?.data?.value ?? res?.data ?? res;
|
|
76
|
+
if (val !== void 0 && val !== null) return val;
|
|
77
|
+
} catch {
|
|
78
|
+
}
|
|
79
|
+
} else if (typeof globalThis.useNuxtData === "function") {
|
|
80
|
+
try {
|
|
81
|
+
const res = globalThis.useNuxtData(key);
|
|
82
|
+
const val = res?.data?.value ?? res?.data ?? res;
|
|
83
|
+
if (val !== void 0 && val !== null) return val;
|
|
84
|
+
} catch {
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return this.fallback.getSSRData(key, context);
|
|
88
|
+
}
|
|
89
|
+
async fetchWithSSR(key, fetcher, context) {
|
|
90
|
+
const app = context || getGlobalNuxt();
|
|
91
|
+
if (app?.runWithContext && typeof globalThis.useAsyncData === "function") {
|
|
92
|
+
try {
|
|
93
|
+
const res = await app.runWithContext(() => globalThis.useAsyncData(key, fetcher));
|
|
94
|
+
const val = res?.data?.value ?? res?.data ?? res;
|
|
95
|
+
if (val !== void 0 && val !== null) return val;
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
} else if (typeof globalThis.useAsyncData === "function") {
|
|
99
|
+
try {
|
|
100
|
+
const res = await globalThis.useAsyncData(key, fetcher);
|
|
101
|
+
const val = res?.data?.value ?? res?.data ?? res;
|
|
102
|
+
if (val !== void 0 && val !== null) return val;
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return this.fallback.fetchWithSSR(key, fetcher, context);
|
|
107
|
+
}
|
|
108
|
+
clearSSRData(key, context) {
|
|
109
|
+
const app = context || getGlobalNuxt();
|
|
110
|
+
if (app?.runWithContext && typeof globalThis.clearNuxtData === "function") {
|
|
111
|
+
try {
|
|
112
|
+
app.runWithContext(() => globalThis.clearNuxtData(key));
|
|
113
|
+
} catch {
|
|
114
|
+
}
|
|
115
|
+
} else if (typeof globalThis.clearNuxtData === "function") {
|
|
116
|
+
try {
|
|
117
|
+
globalThis.clearNuxtData(key);
|
|
118
|
+
} catch {
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
this.fallback.clearSSRData(key, context);
|
|
122
|
+
}
|
|
123
|
+
getSSRPayload(context) {
|
|
124
|
+
const app = context || getGlobalNuxt();
|
|
125
|
+
const payload = app?.payload?.data || app?.ssrContext?.payload?.data;
|
|
126
|
+
if (payload) return payload;
|
|
127
|
+
return this.fallback.getSSRPayload(context);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let currentAdapter = null;
|
|
132
|
+
function getHydrationAdapter() {
|
|
133
|
+
if (!currentAdapter) {
|
|
134
|
+
if (typeof globalThis.useNuxtApp === "function") {
|
|
135
|
+
currentAdapter = new NuxtHydrationAdapter();
|
|
136
|
+
} else {
|
|
137
|
+
currentAdapter = new DefaultHydrationAdapter();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return currentAdapter;
|
|
141
|
+
}
|
|
142
|
+
function setHydrationAdapter(adapter) {
|
|
143
|
+
currentAdapter = adapter;
|
|
144
|
+
}
|
|
145
|
+
function getSSRData(key, context) {
|
|
146
|
+
return getHydrationAdapter().getSSRData(key, context);
|
|
147
|
+
}
|
|
148
|
+
async function fetchWithSSR(key, fetcher, context) {
|
|
149
|
+
return await getHydrationAdapter().fetchWithSSR(key, fetcher, context);
|
|
150
|
+
}
|
|
151
|
+
function clearSSRData(key, context) {
|
|
152
|
+
getHydrationAdapter().clearSSRData?.(key, context);
|
|
153
|
+
}
|
|
154
|
+
function getSSRPayload(context) {
|
|
155
|
+
return getHydrationAdapter().getSSRPayload?.(context) ?? null;
|
|
156
|
+
}
|
|
157
|
+
function getPlatformApp() {
|
|
158
|
+
if (typeof globalThis.useNuxtApp === "function") {
|
|
159
|
+
try {
|
|
160
|
+
return globalThis.useNuxtApp();
|
|
161
|
+
} catch {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
function getAppRoute() {
|
|
168
|
+
if (typeof globalThis.useRoute === "function") {
|
|
169
|
+
try {
|
|
170
|
+
return globalThis.useRoute();
|
|
171
|
+
} catch {
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (typeof window !== "undefined") {
|
|
175
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
176
|
+
const query = {};
|
|
177
|
+
searchParams.forEach((val, key) => {
|
|
178
|
+
query[key] = val;
|
|
179
|
+
});
|
|
180
|
+
return { query, path: window.location.pathname };
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
function getAppRouter() {
|
|
185
|
+
if (typeof globalThis.useRouter === "function") {
|
|
186
|
+
try {
|
|
187
|
+
return globalThis.useRouter();
|
|
188
|
+
} catch {
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (typeof window !== "undefined") {
|
|
192
|
+
return {
|
|
193
|
+
replace: (options) => {
|
|
194
|
+
const url = new URL(window.location.href);
|
|
195
|
+
url.search = "";
|
|
196
|
+
if (options.query) {
|
|
197
|
+
for (const [k, v] of Object.entries(options.query)) {
|
|
198
|
+
if (v !== void 0 && v !== null) {
|
|
199
|
+
url.searchParams.set(k, String(v));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
window.history.replaceState({}, "", url.toString());
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
function onPlatformReady(cb) {
|
|
210
|
+
if (typeof globalThis.onNuxtReady === "function") {
|
|
211
|
+
try {
|
|
212
|
+
globalThis.onNuxtReady(cb);
|
|
213
|
+
return;
|
|
214
|
+
} catch {
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (typeof window !== "undefined") {
|
|
218
|
+
if (document.readyState === "complete") {
|
|
219
|
+
setTimeout(cb, 0);
|
|
220
|
+
} else {
|
|
221
|
+
window.addEventListener("DOMContentLoaded", cb, { once: true });
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
setTimeout(cb, 0);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { DefaultHydrationAdapter as D, NuxtHydrationAdapter as N, getAppRoute as a, getAppRouter as b, getSSRData as c, clearSSRData as d, getSSRPayload as e, fetchWithSSR as f, getPlatformApp as g, getHydrationAdapter as h, onPlatformReady as o, setHydrationAdapter as s };
|