@bleedingdev/modern-js-runtime 3.8.3-ultramodern.6 → 3.9.0-ultramodern.10
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/cjs/cli/code.js +3 -1
- package/dist/cjs/cli/ssr/index.js +2 -74
- package/dist/cjs/core/browser/hydrate.js +6 -1
- package/dist/cjs/core/context/index.js +4 -43
- package/dist/cjs/core/context/public.js +4 -7
- package/dist/cjs/core/context/runtime.js +17 -5
- package/dist/cjs/core/react/wrapper.js +22 -65
- package/dist/cjs/core/server/helmet.js +5 -4
- package/dist/cjs/core/server/requestResponse.js +4 -4
- package/dist/cjs/core/server/routerCleanup.js +2 -2
- package/dist/cjs/core/server/shared.js +171 -4
- package/dist/cjs/core/server/stream/afterTemplate.js +21 -16
- package/dist/cjs/core/server/stream/beforeTemplate.js +34 -25
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +28 -21
- package/dist/cjs/core/server/stream/createReadableStream.js +208 -123
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +159 -90
- package/dist/cjs/core/server/stream/deferredScript.js +3 -3
- package/dist/cjs/core/server/stream/shared.js +2 -2
- package/dist/cjs/core/server/string/index.js +100 -64
- package/dist/cjs/core/server/string/loadable.js +34 -19
- package/dist/cjs/core/server/string/ssrData.js +5 -12
- package/dist/cjs/core/server/utils.js +1 -2
- package/dist/cjs/document/cli/index.js +1 -2
- package/dist/cjs/exports/head.js +7 -14
- package/dist/cjs/router/runtime/PrefetchLink.js +67 -123
- package/dist/cjs/router/runtime/hooks.js +13 -2
- package/dist/cjs/router/runtime/internal.js +7 -45
- package/dist/cjs/router/runtime/plugin.js +2 -8
- package/dist/cjs/router/runtime/plugin.node.js +2 -30
- package/dist/cjs/router/runtime/redirect.js +1 -1
- package/dist/esm/cli/code.mjs +3 -1
- package/dist/esm/cli/ssr/index.mjs +3 -72
- package/dist/esm/core/browser/hydrate.mjs +7 -2
- package/dist/esm/core/context/index.mjs +2 -5
- package/dist/esm/core/context/public.mjs +1 -5
- package/dist/esm/core/context/runtime.mjs +13 -4
- package/dist/esm/core/react/wrapper.mjs +21 -67
- package/dist/esm/core/server/helmet.mjs +5 -4
- package/dist/esm/core/server/requestResponse.mjs +3 -3
- package/dist/esm/core/server/routerCleanup.mjs +1 -1
- package/dist/esm/core/server/shared.mjs +153 -1
- package/dist/esm/core/server/stream/afterTemplate.mjs +23 -18
- package/dist/esm/core/server/stream/beforeTemplate.mjs +37 -28
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +31 -24
- package/dist/esm/core/server/stream/createReadableStream.mjs +207 -122
- package/dist/esm/core/server/stream/createReadableStream.worker.mjs +149 -90
- package/dist/esm/core/server/stream/deferredScript.mjs +3 -3
- package/dist/esm/core/server/stream/shared.mjs +2 -2
- package/dist/esm/core/server/string/index.mjs +104 -68
- package/dist/esm/core/server/string/loadable.mjs +34 -19
- package/dist/esm/core/server/string/ssrData.mjs +5 -12
- package/dist/esm/core/server/utils.mjs +1 -2
- package/dist/esm/document/cli/index.mjs +2 -3
- package/dist/esm/exports/head.mjs +7 -14
- package/dist/esm/router/runtime/PrefetchLink.mjs +68 -124
- package/dist/esm/router/runtime/hooks.mjs +9 -1
- package/dist/esm/router/runtime/internal.mjs +2 -33
- package/dist/esm/router/runtime/plugin.mjs +1 -7
- package/dist/esm/router/runtime/plugin.node.mjs +1 -29
- package/dist/esm/router/runtime/redirect.mjs +1 -1
- package/dist/esm-node/cli/code.mjs +3 -1
- package/dist/esm-node/cli/ssr/index.mjs +3 -72
- package/dist/esm-node/core/browser/hydrate.mjs +7 -2
- package/dist/esm-node/core/context/index.mjs +2 -5
- package/dist/esm-node/core/context/public.mjs +1 -5
- package/dist/esm-node/core/context/runtime.mjs +13 -4
- package/dist/esm-node/core/react/wrapper.mjs +21 -67
- package/dist/esm-node/core/server/helmet.mjs +5 -4
- package/dist/esm-node/core/server/requestResponse.mjs +3 -3
- package/dist/esm-node/core/server/routerCleanup.mjs +1 -1
- package/dist/esm-node/core/server/shared.mjs +153 -1
- package/dist/esm-node/core/server/stream/afterTemplate.mjs +23 -18
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +37 -28
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +31 -24
- package/dist/esm-node/core/server/stream/createReadableStream.mjs +207 -122
- package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +149 -90
- package/dist/esm-node/core/server/stream/deferredScript.mjs +3 -3
- package/dist/esm-node/core/server/stream/shared.mjs +2 -2
- package/dist/esm-node/core/server/string/index.mjs +104 -68
- package/dist/esm-node/core/server/string/loadable.mjs +34 -19
- package/dist/esm-node/core/server/string/ssrData.mjs +5 -12
- package/dist/esm-node/core/server/utils.mjs +1 -2
- package/dist/esm-node/document/cli/index.mjs +2 -3
- package/dist/esm-node/exports/head.mjs +7 -14
- package/dist/esm-node/router/runtime/PrefetchLink.mjs +68 -124
- package/dist/esm-node/router/runtime/hooks.mjs +9 -1
- package/dist/esm-node/router/runtime/internal.mjs +2 -33
- package/dist/esm-node/router/runtime/plugin.mjs +1 -7
- package/dist/esm-node/router/runtime/plugin.node.mjs +1 -29
- package/dist/esm-node/router/runtime/redirect.mjs +1 -1
- package/dist/types/cli/index.d.ts +7 -7
- package/dist/types/cli/ssr/index.d.ts +0 -3
- package/dist/types/core/browser/hydrate.d.ts +1 -1
- package/dist/types/core/browser/index.d.ts +1 -1
- package/dist/types/core/compat/hooks.d.ts +1 -1
- package/dist/types/core/compat/index.d.ts +1 -1
- package/dist/types/core/compat/requestContext.d.ts +3 -3
- package/dist/types/core/config.d.ts +1 -1
- package/dist/types/core/context/index.d.ts +8 -10
- package/dist/types/core/context/monitors/index.d.ts +1 -1
- package/dist/types/core/context/monitors/index.server.d.ts +1 -1
- package/dist/types/core/context/public.d.ts +1 -23
- package/dist/types/core/context/runtime.d.ts +27 -3
- package/dist/types/core/context/serverPayload/index.d.ts +1 -1
- package/dist/types/core/index.d.ts +5 -5
- package/dist/types/core/plugin/index.d.ts +1 -1
- package/dist/types/core/plugin/types.d.ts +2 -2
- package/dist/types/core/react/wrapper.d.ts +7 -1
- package/dist/types/core/server/helmet.d.ts +4 -5
- package/dist/types/core/server/index.d.ts +2 -2
- package/dist/types/core/server/react/index.d.ts +2 -2
- package/dist/types/core/server/requestHandler.d.ts +3 -3
- package/dist/types/core/server/requestResponse.d.ts +3 -3
- package/dist/types/core/server/routerCleanup.d.ts +2 -2
- package/dist/types/core/server/server.d.ts +4 -4
- package/dist/types/core/server/shared.d.ts +25 -2
- package/dist/types/core/server/stream/afterTemplate.d.ts +5 -4
- package/dist/types/core/server/stream/beforeTemplate.d.ts +6 -3
- package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +6 -3
- package/dist/types/core/server/stream/createReadableStream.d.ts +1 -1
- package/dist/types/core/server/stream/createReadableStream.worker.d.ts +1 -1
- package/dist/types/core/server/stream/index.d.ts +1 -1
- package/dist/types/core/server/stream/shared.d.ts +5 -5
- package/dist/types/core/server/stream/template.d.ts +2 -2
- package/dist/types/core/server/string/index.d.ts +1 -1
- package/dist/types/core/server/string/loadable.d.ts +7 -4
- package/dist/types/core/server/string/ssrData.d.ts +5 -4
- package/dist/types/core/server/string/types.d.ts +2 -6
- package/dist/types/core/server/tracer.d.ts +1 -1
- package/dist/types/core/server/utils.d.ts +2 -2
- package/dist/types/core/types.d.ts +2 -3
- package/dist/types/document/index.d.ts +12 -12
- package/dist/types/exports/config-routes.d.ts +1 -1
- package/dist/types/exports/head.d.ts +2 -2
- package/dist/types/index.d.ts +9 -9
- package/dist/types/internal.d.ts +1 -1
- package/dist/types/react-server.d.ts +3 -3
- package/dist/types/router/cli/code/getClientRoutes/index.d.ts +1 -1
- package/dist/types/router/cli/handler.d.ts +1 -1
- package/dist/types/router/cli/index.d.ts +3 -3
- package/dist/types/router/index.d.ts +1 -1
- package/dist/types/router/internal.d.ts +2 -2
- package/dist/types/router/runtime/PrefetchLink.d.ts +27 -2
- package/dist/types/router/runtime/hooks.d.ts +19 -2
- package/dist/types/router/runtime/index.d.ts +4 -4
- package/dist/types/router/runtime/internal.d.ts +5 -22
- package/dist/types/router/runtime/plugin.d.ts +3 -3
- package/dist/types/router/runtime/plugin.node.d.ts +3 -3
- package/dist/types/router/runtime/rsc-router.d.ts +3 -3
- package/dist/types/router/runtime/types.d.ts +2 -43
- package/dist/types/router/runtime/utils.d.ts +1 -1
- package/package.json +19 -47
- package/rstest.config.mts +32 -2
- package/dist/cjs/boundary-debugger/index.js +0 -317
- package/dist/cjs/core/context/extensions.js +0 -74
- package/dist/cjs/core/context/helmetContext.js +0 -54
- package/dist/cjs/core/server/federatedCss.js +0 -58
- package/dist/cjs/core/server/scriptOrder.js +0 -140
- package/dist/cjs/module-federation/consume-surface.js +0 -199
- package/dist/cjs/module-federation/distributed-ssr.js +0 -135
- package/dist/cjs/module-federation/index.js +0 -316
- package/dist/cjs/module-federation/last-known-good.js +0 -157
- package/dist/cjs/module-federation/manifest-recovery-runtime-plugin.js +0 -129
- package/dist/cjs/module-federation/surface-resolution-types.js +0 -61
- package/dist/cjs/router/runtime/lifecycle.js +0 -167
- package/dist/cjs/router/runtime/provider.js +0 -153
- package/dist/esm/boundary-debugger/index.mjs +0 -277
- package/dist/esm/core/context/extensions.mjs +0 -33
- package/dist/esm/core/context/helmetContext.mjs +0 -13
- package/dist/esm/core/server/federatedCss.mjs +0 -20
- package/dist/esm/core/server/scriptOrder.mjs +0 -90
- package/dist/esm/module-federation/consume-surface.mjs +0 -158
- package/dist/esm/module-federation/distributed-ssr.mjs +0 -82
- package/dist/esm/module-federation/index.mjs +0 -115
- package/dist/esm/module-federation/last-known-good.mjs +0 -113
- package/dist/esm/module-federation/manifest-recovery-runtime-plugin.mjs +0 -89
- package/dist/esm/module-federation/surface-resolution-types.mjs +0 -8
- package/dist/esm/router/runtime/lifecycle.mjs +0 -105
- package/dist/esm/router/runtime/provider.mjs +0 -100
- package/dist/esm-node/boundary-debugger/index.mjs +0 -278
- package/dist/esm-node/core/context/extensions.mjs +0 -34
- package/dist/esm-node/core/context/helmetContext.mjs +0 -14
- package/dist/esm-node/core/server/federatedCss.mjs +0 -21
- package/dist/esm-node/core/server/scriptOrder.mjs +0 -91
- package/dist/esm-node/module-federation/consume-surface.mjs +0 -159
- package/dist/esm-node/module-federation/distributed-ssr.mjs +0 -83
- package/dist/esm-node/module-federation/index.mjs +0 -116
- package/dist/esm-node/module-federation/last-known-good.mjs +0 -114
- package/dist/esm-node/module-federation/manifest-recovery-runtime-plugin.mjs +0 -90
- package/dist/esm-node/module-federation/surface-resolution-types.mjs +0 -9
- package/dist/esm-node/router/runtime/lifecycle.mjs +0 -106
- package/dist/esm-node/router/runtime/provider.mjs +0 -101
- package/dist/types/boundary-debugger/index.d.ts +0 -28
- package/dist/types/core/context/extensions.d.ts +0 -35
- package/dist/types/core/context/helmetContext.d.ts +0 -10
- package/dist/types/core/server/federatedCss.d.ts +0 -5
- package/dist/types/core/server/scriptOrder.d.ts +0 -25
- package/dist/types/module-federation/consume-surface.d.ts +0 -104
- package/dist/types/module-federation/distributed-ssr.d.ts +0 -61
- package/dist/types/module-federation/index.d.ts +0 -71
- package/dist/types/module-federation/last-known-good.d.ts +0 -52
- package/dist/types/module-federation/manifest-recovery-runtime-plugin.d.ts +0 -25
- package/dist/types/module-federation/surface-resolution-types.d.ts +0 -23
- package/dist/types/router/runtime/lifecycle.d.ts +0 -27
- package/dist/types/router/runtime/provider.d.ts +0 -78
- /package/dist/esm/{rslib-runtime.mjs → rslib-runtime~1.mjs} +0 -0
- /package/dist/esm-node/{rslib-runtime.mjs → rslib-runtime~0.mjs} +0 -0
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { createRuntimeContextExtension } from "../../core/context/extensions.mjs";
|
|
2
|
-
const routerRuntimeStateExtension = createRuntimeContextExtension('@modern-js/runtime:router-runtime-state');
|
|
3
|
-
const routerServerSnapshotExtension = createRuntimeContextExtension('@modern-js/runtime:router-server-snapshot');
|
|
4
|
-
function getRouterRuntimeState(runtimeContext) {
|
|
5
|
-
return routerRuntimeStateExtension.get(runtimeContext);
|
|
6
|
-
}
|
|
7
|
-
function getRouterServerSnapshot(runtimeContext) {
|
|
8
|
-
return routerServerSnapshotExtension.get(runtimeContext);
|
|
9
|
-
}
|
|
10
|
-
function toHydrationScripts(state) {
|
|
11
|
-
if (state.hydrationScripts?.length) return state.hydrationScripts;
|
|
12
|
-
return state.hydrationScript ? [
|
|
13
|
-
state.hydrationScript
|
|
14
|
-
] : void 0;
|
|
15
|
-
}
|
|
16
|
-
function getMatchedRouteIdsFromMatches(matches) {
|
|
17
|
-
const routeIds = matches?.map((match)=>match.assetRouteId ?? match.routeId).filter((routeId)=>'string' == typeof routeId);
|
|
18
|
-
return routeIds?.length ? routeIds : void 0;
|
|
19
|
-
}
|
|
20
|
-
function createRouterServerSnapshot(state) {
|
|
21
|
-
const hydrationScripts = toHydrationScripts(state);
|
|
22
|
-
const matchedRouteIds = state.matchedRouteIds ?? getMatchedRouteIdsFromMatches(state.matches);
|
|
23
|
-
return {
|
|
24
|
-
...state,
|
|
25
|
-
...hydrationScripts?.length ? {
|
|
26
|
-
hydrationScript: state.hydrationScript ?? hydrationScripts[0],
|
|
27
|
-
hydrationScripts
|
|
28
|
-
} : {},
|
|
29
|
-
...matchedRouteIds ? {
|
|
30
|
-
matchedRouteIds
|
|
31
|
-
} : {}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
function createRouterRuntimeState(state) {
|
|
35
|
-
const hasSnapshotState = Boolean(state.serverSnapshot) || Boolean(state.hydrationScript) || Boolean(state.hydrationScripts?.length) || Boolean(state.matchedRouteIds?.length) || Boolean(state.matches?.length);
|
|
36
|
-
const serverSnapshot = state.serverSnapshot ? createRouterServerSnapshot({
|
|
37
|
-
...state.serverSnapshot,
|
|
38
|
-
framework: state.serverSnapshot.framework ?? state.framework,
|
|
39
|
-
basename: state.serverSnapshot.basename ?? state.basename,
|
|
40
|
-
hydrationScript: state.serverSnapshot.hydrationScript ?? state.hydrationScript,
|
|
41
|
-
hydrationScripts: state.serverSnapshot.hydrationScripts ?? state.hydrationScripts,
|
|
42
|
-
matchedRouteIds: state.serverSnapshot.matchedRouteIds ?? state.matchedRouteIds,
|
|
43
|
-
matches: state.serverSnapshot.matches ?? state.matches
|
|
44
|
-
}) : hasSnapshotState ? createRouterServerSnapshot({
|
|
45
|
-
framework: state.framework,
|
|
46
|
-
basename: state.basename,
|
|
47
|
-
hydrationScript: state.hydrationScript,
|
|
48
|
-
hydrationScripts: state.hydrationScripts,
|
|
49
|
-
matchedRouteIds: state.matchedRouteIds,
|
|
50
|
-
matches: state.matches
|
|
51
|
-
}) : void 0;
|
|
52
|
-
const hydrationScripts = toHydrationScripts({
|
|
53
|
-
hydrationScript: state.hydrationScript ?? serverSnapshot?.hydrationScript,
|
|
54
|
-
hydrationScripts: state.hydrationScripts ?? serverSnapshot?.hydrationScripts
|
|
55
|
-
});
|
|
56
|
-
const matchedRouteIds = state.matchedRouteIds ?? serverSnapshot?.matchedRouteIds ?? getMatchedRouteIdsFromMatches(state.matches);
|
|
57
|
-
return {
|
|
58
|
-
...state,
|
|
59
|
-
...hydrationScripts?.length ? {
|
|
60
|
-
hydrationScript: state.hydrationScript ?? hydrationScripts[0],
|
|
61
|
-
hydrationScripts
|
|
62
|
-
} : {},
|
|
63
|
-
...matchedRouteIds ? {
|
|
64
|
-
matchedRouteIds
|
|
65
|
-
} : {},
|
|
66
|
-
...serverSnapshot ? {
|
|
67
|
-
serverSnapshot
|
|
68
|
-
} : {}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function applyRouterRuntimeState(runtimeContext, state) {
|
|
72
|
-
const normalized = createRouterRuntimeState(state);
|
|
73
|
-
routerRuntimeStateExtension.set(runtimeContext, normalized);
|
|
74
|
-
if (normalized.serverSnapshot) routerServerSnapshotExtension.set(runtimeContext, normalized.serverSnapshot);
|
|
75
|
-
return runtimeContext;
|
|
76
|
-
}
|
|
77
|
-
function applyRouterServerPrepareResult(runtimeContext, result) {
|
|
78
|
-
const state = createRouterRuntimeState({
|
|
79
|
-
...result.state,
|
|
80
|
-
cleanup: result.cleanup ?? result.state.cleanup,
|
|
81
|
-
serverSnapshot: result.snapshot ?? result.state.serverSnapshot
|
|
82
|
-
});
|
|
83
|
-
applyRouterRuntimeState(runtimeContext, state);
|
|
84
|
-
return runtimeContext;
|
|
85
|
-
}
|
|
86
|
-
function getRouterHydrationScripts(runtimeContext) {
|
|
87
|
-
const serverSnapshot = getRouterServerSnapshot(runtimeContext);
|
|
88
|
-
const runtimeState = getRouterRuntimeState(runtimeContext);
|
|
89
|
-
return serverSnapshot?.hydrationScripts ?? toHydrationScripts({
|
|
90
|
-
hydrationScript: serverSnapshot?.hydrationScript
|
|
91
|
-
}) ?? runtimeState?.hydrationScripts ?? toHydrationScripts({
|
|
92
|
-
hydrationScript: runtimeState?.hydrationScript
|
|
93
|
-
}) ?? [];
|
|
94
|
-
}
|
|
95
|
-
function getRouterMatchedRouteIds(runtimeContext) {
|
|
96
|
-
const serverSnapshot = getRouterServerSnapshot(runtimeContext);
|
|
97
|
-
const runtimeState = getRouterRuntimeState(runtimeContext);
|
|
98
|
-
return serverSnapshot?.matchedRouteIds ?? getMatchedRouteIdsFromMatches(serverSnapshot?.matches) ?? runtimeState?.matchedRouteIds ?? getMatchedRouteIdsFromMatches(runtimeState?.matches);
|
|
99
|
-
}
|
|
100
|
-
async function cleanupRouterRuntimeState(runtimeContext) {
|
|
101
|
-
try {
|
|
102
|
-
await getRouterRuntimeState(runtimeContext)?.cleanup?.();
|
|
103
|
-
} catch {}
|
|
104
|
-
}
|
|
105
|
-
export { applyRouterRuntimeState, applyRouterServerPrepareResult, cleanupRouterRuntimeState, createRouterRuntimeState, createRouterServerSnapshot, getRouterHydrationScripts, getRouterMatchedRouteIds, getRouterRuntimeState, getRouterServerSnapshot };
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter } from "./hooks.mjs";
|
|
2
|
-
const routerProviderRegistryHooks = {
|
|
3
|
-
modifyRoutes: modifyRoutes,
|
|
4
|
-
onBeforeCreateRoutes: onBeforeCreateRoutes,
|
|
5
|
-
onBeforeCreateRouter: onBeforeCreateRouter,
|
|
6
|
-
onAfterCreateRouter: onAfterCreateRouter,
|
|
7
|
-
onBeforeHydrateRouter: onBeforeHydrateRouter,
|
|
8
|
-
onAfterHydrateRouter: onAfterHydrateRouter
|
|
9
|
-
};
|
|
10
|
-
function reportUnsupportedProviderRegistryHooks(providerPlugin) {
|
|
11
|
-
const unsupportedHookNames = Object.keys(providerPlugin.registryHooks ?? {}).filter((hookName)=>!(hookName in routerProviderRegistryHooks));
|
|
12
|
-
if (unsupportedHookNames.length > 0) console.warn(`[@modern-js/runtime] The router provider "${providerPlugin.name}" declares registry hooks outside the router hook contract: ${unsupportedHookNames.join(', ')}. These hooks are not registered when the provider is resolved through \`runtime.router.framework\` — declare them on a separate runtime plugin instead.`);
|
|
13
|
-
return unsupportedHookNames;
|
|
14
|
-
}
|
|
15
|
-
function createRouterProviderRealm(registrations) {
|
|
16
|
-
const providers = new Map();
|
|
17
|
-
let defaultProvider;
|
|
18
|
-
for (const registration of registrations){
|
|
19
|
-
if (0 === registration.name.length) throw new Error('[@modern-js/runtime] A router provider realm cannot contain an unnamed provider.');
|
|
20
|
-
if (providers.has(registration.name)) throw new Error(`[@modern-js/runtime] Router provider "${registration.name}" is declared more than once in the same runtime realm.`);
|
|
21
|
-
if (true === registration.isDefault && void 0 !== defaultProvider && defaultProvider !== registration.name) throw new Error(`[@modern-js/runtime] Router provider realm declares both "${defaultProvider}" and "${registration.name}" as defaults.`);
|
|
22
|
-
providers.set(registration.name, registration.factory);
|
|
23
|
-
if (true === registration.isDefault) defaultProvider = registration.name;
|
|
24
|
-
}
|
|
25
|
-
const providerNames = Object.freeze([
|
|
26
|
-
...providers.keys()
|
|
27
|
-
]);
|
|
28
|
-
return Object.freeze({
|
|
29
|
-
...void 0 !== defaultProvider ? {
|
|
30
|
-
defaultProvider
|
|
31
|
-
} : {},
|
|
32
|
-
get: (name)=>providers.get(name),
|
|
33
|
-
names: ()=>providerNames
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
const REGISTRY_SLOT = Symbol.for('@modern-js/runtime:router-providers:v3');
|
|
37
|
-
const LEGACY_V2_REGISTRY_SLOT = Symbol.for('@modern-js/runtime:router-providers:v2');
|
|
38
|
-
function getRegistry() {
|
|
39
|
-
const host = globalThis;
|
|
40
|
-
host[REGISTRY_SLOT] ??= {
|
|
41
|
-
providers: new Map(),
|
|
42
|
-
duplicateProviders: new Set(),
|
|
43
|
-
warnedDuplicates: new Set()
|
|
44
|
-
};
|
|
45
|
-
host[REGISTRY_SLOT].duplicateProviders ??= new Set();
|
|
46
|
-
host[REGISTRY_SLOT].warnedDuplicates ??= new Set();
|
|
47
|
-
return host[REGISTRY_SLOT];
|
|
48
|
-
}
|
|
49
|
-
function getLegacyV2Registry() {
|
|
50
|
-
const host = globalThis;
|
|
51
|
-
return host[LEGACY_V2_REGISTRY_SLOT];
|
|
52
|
-
}
|
|
53
|
-
function registerRouterProvider(name, factory, options = {}) {
|
|
54
|
-
const registry = getRegistry();
|
|
55
|
-
const existing = registry.providers.get(name);
|
|
56
|
-
if (void 0 !== existing) {
|
|
57
|
-
if (existing !== factory) registry.duplicateProviders.add(name);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (true === options.isDefault) registry.defaultProvider = name;
|
|
61
|
-
registry.providers.set(name, factory);
|
|
62
|
-
}
|
|
63
|
-
function resolveRouterProvider(framework, options = {}) {
|
|
64
|
-
if (void 0 !== options.realm) {
|
|
65
|
-
const name = framework || options.realm.defaultProvider;
|
|
66
|
-
const realmProviderNames = options.realm.names();
|
|
67
|
-
if (void 0 === name) throw new Error(`[@modern-js/runtime] The app-owned router provider realm does not declare a default provider. Available realm providers: ${realmProviderNames.join(', ') || '(none)'}.`);
|
|
68
|
-
const factory = options.realm.get(name);
|
|
69
|
-
if (void 0 === factory) throw new Error(`[@modern-js/runtime] Router provider "${name}" is not registered in the app-owned router provider realm. Available realm providers: ${realmProviderNames.join(', ') || '(none)'}. Compatibility registry fallback is disabled for app-owned realms.`);
|
|
70
|
-
return factory;
|
|
71
|
-
}
|
|
72
|
-
const registry = getRegistry();
|
|
73
|
-
const legacyV2Registry = getLegacyV2Registry();
|
|
74
|
-
const name = framework || options.localDefault?.name || registry.defaultProvider || legacyV2Registry?.defaultProvider;
|
|
75
|
-
if (void 0 === name) throw new Error('[@modern-js/runtime] No default router provider is registered. This is a bug in the runtime setup.');
|
|
76
|
-
if (void 0 !== options.localDefault && name === options.localDefault.name) return options.localDefault.factory;
|
|
77
|
-
const factory = registry.providers.get(name);
|
|
78
|
-
if (void 0 !== factory) {
|
|
79
|
-
if (registry.duplicateProviders.has(name) && !registry.warnedDuplicates.has(name)) {
|
|
80
|
-
registry.warnedDuplicates.add(name);
|
|
81
|
-
console.warn(`[@modern-js/runtime] The router provider "${name}" was registered more than once with different module instances, and a router wrapper without an app-owned provider realm is resolving the mixed-version compatibility fallback. The fallback is keeping the first registration. Modern router wrappers isolate app-owned realms automatically. For an older wrapper, share the provider runtime between Module Federation host and remotes or upgrade every app to a realm-aware runtime.`);
|
|
82
|
-
}
|
|
83
|
-
return factory;
|
|
84
|
-
}
|
|
85
|
-
const legacyV2Factory = legacyV2Registry?.providers.get(name);
|
|
86
|
-
if (void 0 !== legacyV2Factory) return legacyV2Factory;
|
|
87
|
-
if ('tanstack' === name) throw new Error("[@modern-js/runtime] `runtime.router.framework` is set to \"tanstack\", but no TanStack router provider is registered. Install @modern-js/plugin-tanstack, add `tanstackRouterPlugin()` to the `plugins` array in modern.config.ts, and make sure '@modern-js/plugin-tanstack/runtime' is imported (e.g. in modern.runtime.ts).");
|
|
88
|
-
throw new Error(`[@modern-js/runtime] Unknown router framework "${name}". Registered providers: ${[
|
|
89
|
-
...new Set([
|
|
90
|
-
...registry.providers.keys(),
|
|
91
|
-
...legacyV2Registry?.providers.keys() ?? []
|
|
92
|
-
])
|
|
93
|
-
].join(', ') || '(none)'}. Install and register the plugin that provides this router framework.`);
|
|
94
|
-
}
|
|
95
|
-
function unsafe_resetRouterProvidersForTesting() {
|
|
96
|
-
const host = globalThis;
|
|
97
|
-
delete host[REGISTRY_SLOT];
|
|
98
|
-
delete host[LEGACY_V2_REGISTRY_SLOT];
|
|
99
|
-
}
|
|
100
|
-
export { createRouterProviderRealm, registerRouterProvider, reportUnsupportedProviderRegistryHooks, resolveRouterProvider, routerProviderRegistryHooks, unsafe_resetRouterProvidersForTesting };
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useMemo, useState } from "react";
|
|
4
|
-
const defaultStorageKey = 'modernjs:boundary-debugger:enabled';
|
|
5
|
-
const queryParamName = 'modern-boundaries';
|
|
6
|
-
const boundarySelector = '[data-modern-boundary-id]';
|
|
7
|
-
const defaultLabels = {
|
|
8
|
-
cs: {
|
|
9
|
-
toggle: 'zobrazit hranice týmů'
|
|
10
|
-
},
|
|
11
|
-
en: {
|
|
12
|
-
toggle: 'show team boundaries'
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const palette = [
|
|
16
|
-
'#ff5a5f',
|
|
17
|
-
'#30e27a',
|
|
18
|
-
'#f6cf45',
|
|
19
|
-
'#7c8cff',
|
|
20
|
-
'#29b6f6'
|
|
21
|
-
];
|
|
22
|
-
const readStoredEnabled = (storageKey, fallback)=>{
|
|
23
|
-
if ("u" < typeof window) return fallback;
|
|
24
|
-
try {
|
|
25
|
-
const stored = window.localStorage.getItem(storageKey);
|
|
26
|
-
return null === stored ? fallback : 'true' === stored;
|
|
27
|
-
} catch {
|
|
28
|
-
return fallback;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const writeStoredEnabled = (storageKey, enabled)=>{
|
|
32
|
-
if ("u" < typeof window) return;
|
|
33
|
-
try {
|
|
34
|
-
window.localStorage.setItem(storageKey, String(enabled));
|
|
35
|
-
} catch {}
|
|
36
|
-
};
|
|
37
|
-
const parseEnabledOverride = (value)=>{
|
|
38
|
-
if (null === value) return;
|
|
39
|
-
const normalized = value.toLowerCase();
|
|
40
|
-
if ('1' === normalized || 'true' === normalized) return true;
|
|
41
|
-
if ('0' === normalized || 'false' === normalized) return false;
|
|
42
|
-
};
|
|
43
|
-
const readQueryEnabledOverride = ()=>{
|
|
44
|
-
if ("u" < typeof window) return;
|
|
45
|
-
try {
|
|
46
|
-
return parseEnabledOverride(new URLSearchParams(window.location.search).get(queryParamName));
|
|
47
|
-
} catch {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
const detectLanguage = ()=>{
|
|
52
|
-
if ("u" < typeof document) return 'en';
|
|
53
|
-
const htmlLanguage = document.documentElement.lang;
|
|
54
|
-
if ('' !== htmlLanguage) return htmlLanguage.split('-')[0] || 'en';
|
|
55
|
-
if ("u" < typeof window) return 'en';
|
|
56
|
-
return window.location.pathname.split('/').filter(Boolean)[0] || 'en';
|
|
57
|
-
};
|
|
58
|
-
const hashBoundaryId = (id)=>{
|
|
59
|
-
let hash = 0;
|
|
60
|
-
for(let index = 0; index < id.length; index++)hash = 31 * hash + id.charCodeAt(index) >>> 0;
|
|
61
|
-
return hash;
|
|
62
|
-
};
|
|
63
|
-
const formatRectKey = (rect)=>[
|
|
64
|
-
Math.round(100 * rect.left) / 100,
|
|
65
|
-
Math.round(100 * rect.top) / 100,
|
|
66
|
-
Math.round(100 * rect.width) / 100,
|
|
67
|
-
Math.round(100 * rect.height) / 100
|
|
68
|
-
].join(':');
|
|
69
|
-
const getBoundaryId = (element)=>element.dataset.modernBoundaryId ?? element.dataset.mfRemote ?? element.getAttribute('data-mf-remote') ?? void 0;
|
|
70
|
-
const collectBoundaryElements = (legacySelector)=>{
|
|
71
|
-
const elements = new Set();
|
|
72
|
-
for (const element of document.querySelectorAll(boundarySelector))elements.add(element);
|
|
73
|
-
if (void 0 === legacySelector || '' === legacySelector) return Array.from(elements);
|
|
74
|
-
try {
|
|
75
|
-
for (const element of document.querySelectorAll(legacySelector))elements.add(element);
|
|
76
|
-
} catch {}
|
|
77
|
-
return Array.from(elements);
|
|
78
|
-
};
|
|
79
|
-
function BoundaryDebugger({ controlMode = 'visible', enabledByDefault = false, labels = defaultLabels, legacySelector, metadata, storageKey = defaultStorageKey }) {
|
|
80
|
-
const [mounted, setMounted] = useState(false);
|
|
81
|
-
const [enabled, setEnabled] = useState(false);
|
|
82
|
-
const [boxes, setBoxes] = useState([]);
|
|
83
|
-
const boundaries = useMemo(()=>new Map(metadata.boundaries.map((entry, index)=>[
|
|
84
|
-
entry.mfName,
|
|
85
|
-
{
|
|
86
|
-
...entry,
|
|
87
|
-
color: entry.color ?? palette[index % palette.length],
|
|
88
|
-
label: entry.label ?? entry.appId
|
|
89
|
-
}
|
|
90
|
-
])), [
|
|
91
|
-
metadata
|
|
92
|
-
]);
|
|
93
|
-
const language = mounted ? detectLanguage() : 'en';
|
|
94
|
-
const toggleLabel = labels[language]?.toggle ?? labels.en?.toggle ?? defaultLabels.en?.toggle ?? 'show team boundaries';
|
|
95
|
-
useEffect(()=>{
|
|
96
|
-
setMounted(true);
|
|
97
|
-
const queryOverride = readQueryEnabledOverride();
|
|
98
|
-
setEnabled(queryOverride ?? readStoredEnabled(storageKey, enabledByDefault));
|
|
99
|
-
}, [
|
|
100
|
-
enabledByDefault,
|
|
101
|
-
storageKey
|
|
102
|
-
]);
|
|
103
|
-
useEffect(()=>{
|
|
104
|
-
if (!mounted) return;
|
|
105
|
-
writeStoredEnabled(storageKey, enabled);
|
|
106
|
-
}, [
|
|
107
|
-
enabled,
|
|
108
|
-
mounted,
|
|
109
|
-
storageKey
|
|
110
|
-
]);
|
|
111
|
-
useEffect(()=>{
|
|
112
|
-
if (!enabled) return void setBoxes([]);
|
|
113
|
-
let resizeObserver;
|
|
114
|
-
const observedElements = new Set();
|
|
115
|
-
const observeBoundaryElements = (elements)=>{
|
|
116
|
-
if (void 0 === resizeObserver) return;
|
|
117
|
-
for (const element of elements)if (!observedElements.has(element)) {
|
|
118
|
-
observedElements.add(element);
|
|
119
|
-
resizeObserver.observe(element);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
const readBoxes = ()=>{
|
|
123
|
-
const elements = collectBoundaryElements(legacySelector);
|
|
124
|
-
observeBoundaryElements(elements);
|
|
125
|
-
const seenBoxes = new Set();
|
|
126
|
-
const nextBoxes = elements.map((element)=>{
|
|
127
|
-
const boundaryId = getBoundaryId(element);
|
|
128
|
-
if (void 0 === boundaryId || '' === boundaryId) return;
|
|
129
|
-
const rect = element.getBoundingClientRect();
|
|
130
|
-
if (rect.width <= 0 || rect.height <= 0) return;
|
|
131
|
-
const rectKey = formatRectKey(rect);
|
|
132
|
-
const boxKey = `${boundaryId}:${rectKey}`;
|
|
133
|
-
if (seenBoxes.has(boxKey)) return;
|
|
134
|
-
seenBoxes.add(boxKey);
|
|
135
|
-
const boundary = boundaries.get(boundaryId);
|
|
136
|
-
const color = boundary?.color ?? palette[hashBoundaryId(boundaryId) % palette.length];
|
|
137
|
-
const label = boundary?.label ?? boundary?.appId ?? boundaryId;
|
|
138
|
-
const expose = element.dataset.modernMfExpose;
|
|
139
|
-
const detail = void 0 !== expose && '' !== expose && expose !== label && expose !== boundaryId ? expose : void 0;
|
|
140
|
-
const box = {
|
|
141
|
-
color,
|
|
142
|
-
height: rect.height,
|
|
143
|
-
id: boxKey,
|
|
144
|
-
label,
|
|
145
|
-
left: rect.left,
|
|
146
|
-
top: rect.top,
|
|
147
|
-
width: rect.width
|
|
148
|
-
};
|
|
149
|
-
if (void 0 !== detail) box.detail = detail;
|
|
150
|
-
return box;
|
|
151
|
-
}).filter((box)=>void 0 !== box);
|
|
152
|
-
setBoxes(nextBoxes);
|
|
153
|
-
};
|
|
154
|
-
resizeObserver = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver(readBoxes);
|
|
155
|
-
readBoxes();
|
|
156
|
-
const mutationObserver = new MutationObserver(readBoxes);
|
|
157
|
-
mutationObserver.observe(document.body, {
|
|
158
|
-
childList: true,
|
|
159
|
-
subtree: true
|
|
160
|
-
});
|
|
161
|
-
window.addEventListener('resize', readBoxes);
|
|
162
|
-
window.addEventListener('scroll', readBoxes, true);
|
|
163
|
-
return ()=>{
|
|
164
|
-
mutationObserver.disconnect();
|
|
165
|
-
resizeObserver?.disconnect();
|
|
166
|
-
window.removeEventListener('resize', readBoxes);
|
|
167
|
-
window.removeEventListener('scroll', readBoxes, true);
|
|
168
|
-
};
|
|
169
|
-
}, [
|
|
170
|
-
boundaries,
|
|
171
|
-
enabled,
|
|
172
|
-
legacySelector
|
|
173
|
-
]);
|
|
174
|
-
if (!mounted) return null;
|
|
175
|
-
const shouldRenderToggle = 'visible' === controlMode || 'hidden-when-off' === controlMode && enabled;
|
|
176
|
-
return /*#__PURE__*/ jsxs(Fragment, {
|
|
177
|
-
children: [
|
|
178
|
-
shouldRenderToggle ? /*#__PURE__*/ jsxs("label", {
|
|
179
|
-
style: {
|
|
180
|
-
alignItems: 'center',
|
|
181
|
-
background: 'rgba(255, 255, 255, 0.96)',
|
|
182
|
-
border: '1px solid rgba(0, 0, 0, 0.1)',
|
|
183
|
-
borderRadius: 10,
|
|
184
|
-
boxShadow: '0 10px 28px rgba(0, 0, 0, 0.14)',
|
|
185
|
-
color: '#111827',
|
|
186
|
-
display: 'flex',
|
|
187
|
-
font: '600 13px/1.2 system-ui, sans-serif',
|
|
188
|
-
gap: 8,
|
|
189
|
-
left: 'max(12px, env(safe-area-inset-left))',
|
|
190
|
-
maxWidth: 'calc(100vw - 24px)',
|
|
191
|
-
padding: '9px 11px',
|
|
192
|
-
position: 'fixed',
|
|
193
|
-
top: 'max(12px, env(safe-area-inset-top))',
|
|
194
|
-
zIndex: 2147483000
|
|
195
|
-
},
|
|
196
|
-
children: [
|
|
197
|
-
/*#__PURE__*/ jsx("input", {
|
|
198
|
-
checked: enabled,
|
|
199
|
-
onChange: (event)=>setEnabled(event.currentTarget.checked),
|
|
200
|
-
type: "checkbox"
|
|
201
|
-
}),
|
|
202
|
-
/*#__PURE__*/ jsx("span", {
|
|
203
|
-
children: toggleLabel
|
|
204
|
-
})
|
|
205
|
-
]
|
|
206
|
-
}) : null,
|
|
207
|
-
enabled ? /*#__PURE__*/ jsx("div", {
|
|
208
|
-
"aria-hidden": "true",
|
|
209
|
-
children: boxes.map((box)=>/*#__PURE__*/ jsx("div", {
|
|
210
|
-
"data-modern-boundary-overlay": "",
|
|
211
|
-
"data-modern-boundary-overlay-id": box.id,
|
|
212
|
-
"data-modern-boundary-overlay-label": box.label,
|
|
213
|
-
style: {
|
|
214
|
-
border: `2px solid ${box.color}`,
|
|
215
|
-
borderRadius: 8,
|
|
216
|
-
boxSizing: 'border-box',
|
|
217
|
-
boxShadow: `0 0 0 1px rgba(255,255,255,.72), 0 6px 20px color-mix(in srgb, ${box.color} 20%, transparent)`,
|
|
218
|
-
height: box.height,
|
|
219
|
-
left: box.left,
|
|
220
|
-
pointerEvents: 'none',
|
|
221
|
-
position: 'fixed',
|
|
222
|
-
top: box.top,
|
|
223
|
-
width: box.width,
|
|
224
|
-
zIndex: 2147482999
|
|
225
|
-
},
|
|
226
|
-
children: /*#__PURE__*/ jsxs("span", {
|
|
227
|
-
style: {
|
|
228
|
-
background: box.color,
|
|
229
|
-
borderRadius: 999,
|
|
230
|
-
color: '#111827',
|
|
231
|
-
display: 'grid',
|
|
232
|
-
font: '800 11px/1.1 system-ui, sans-serif',
|
|
233
|
-
gap: 3,
|
|
234
|
-
maxWidth: 'min(280px, calc(100vw - 24px))',
|
|
235
|
-
padding: '5px 8px',
|
|
236
|
-
position: 'absolute',
|
|
237
|
-
right: 4,
|
|
238
|
-
top: 4,
|
|
239
|
-
whiteSpace: 'nowrap'
|
|
240
|
-
},
|
|
241
|
-
children: [
|
|
242
|
-
/*#__PURE__*/ jsx("span", {
|
|
243
|
-
children: box.label
|
|
244
|
-
}),
|
|
245
|
-
void 0 !== box.detail && '' !== box.detail ? /*#__PURE__*/ jsx("span", {
|
|
246
|
-
style: {
|
|
247
|
-
font: '700 10px/1.1 system-ui, sans-serif',
|
|
248
|
-
opacity: 0.82,
|
|
249
|
-
overflow: 'hidden',
|
|
250
|
-
textOverflow: 'ellipsis'
|
|
251
|
-
},
|
|
252
|
-
children: box.detail
|
|
253
|
-
}) : null
|
|
254
|
-
]
|
|
255
|
-
})
|
|
256
|
-
}, box.id))
|
|
257
|
-
}) : null
|
|
258
|
-
]
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
const ultramodernBoundaryDebuggerPlugin = (options)=>({
|
|
262
|
-
name: '@modern-js/runtime/boundary-debugger',
|
|
263
|
-
setup: (api)=>{
|
|
264
|
-
api.wrapRoot((App)=>(props)=>/*#__PURE__*/ jsxs(Fragment, {
|
|
265
|
-
children: [
|
|
266
|
-
/*#__PURE__*/ jsx(App, {
|
|
267
|
-
...props
|
|
268
|
-
}),
|
|
269
|
-
/*#__PURE__*/ jsx(BoundaryDebugger, {
|
|
270
|
-
...options
|
|
271
|
-
})
|
|
272
|
-
]
|
|
273
|
-
}));
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
const boundary_debugger = ultramodernBoundaryDebuggerPlugin;
|
|
277
|
-
export default boundary_debugger;
|
|
278
|
-
export { ultramodernBoundaryDebuggerPlugin };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
const EXTENSIONS_SLOT = Symbol.for('@modern-js/runtime:context-extensions');
|
|
3
|
-
function getStore(context) {
|
|
4
|
-
return context[EXTENSIONS_SLOT];
|
|
5
|
-
}
|
|
6
|
-
function ensureStore(context) {
|
|
7
|
-
const target = context;
|
|
8
|
-
const store = target[EXTENSIONS_SLOT] ?? new Map();
|
|
9
|
-
Object.defineProperty(target, EXTENSIONS_SLOT, {
|
|
10
|
-
configurable: true,
|
|
11
|
-
enumerable: true,
|
|
12
|
-
value: store
|
|
13
|
-
});
|
|
14
|
-
return store;
|
|
15
|
-
}
|
|
16
|
-
function stripRuntimeContextExtensions(context) {
|
|
17
|
-
delete context[EXTENSIONS_SLOT];
|
|
18
|
-
}
|
|
19
|
-
function createRuntimeContextExtension(id) {
|
|
20
|
-
const key = Symbol.for(`@modern-js/runtime:context-extension:${id}`);
|
|
21
|
-
return {
|
|
22
|
-
key,
|
|
23
|
-
get (context) {
|
|
24
|
-
return getStore(context)?.get(key);
|
|
25
|
-
},
|
|
26
|
-
set (context, value) {
|
|
27
|
-
ensureStore(context).set(key, value);
|
|
28
|
-
},
|
|
29
|
-
remove (context) {
|
|
30
|
-
getStore(context)?.delete(key);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export { createRuntimeContextExtension, stripRuntimeContextExtensions };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { createRuntimeContextExtension } from "./extensions.mjs";
|
|
3
|
-
const helmetContextExtension = createRuntimeContextExtension('@modern-js/runtime:helmet-context');
|
|
4
|
-
function getHelmetContext(context) {
|
|
5
|
-
return helmetContextExtension.get(context);
|
|
6
|
-
}
|
|
7
|
-
function ensureHelmetContext(context) {
|
|
8
|
-
const existing = helmetContextExtension.get(context);
|
|
9
|
-
if (void 0 !== existing) return existing;
|
|
10
|
-
const created = {};
|
|
11
|
-
helmetContextExtension.set(context, created);
|
|
12
|
-
return created;
|
|
13
|
-
}
|
|
14
|
-
export { ensureHelmetContext, getHelmetContext };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { escapeHtmlAttribute } from "@modern-js/runtime-extensions";
|
|
3
|
-
import { attributesToString, hasStylesheetLink } from "./utils.mjs";
|
|
4
|
-
const createFederatedCssLinks = (assets, options)=>{
|
|
5
|
-
if (void 0 === assets || 0 === assets.length) return '';
|
|
6
|
-
const seen = new Set(options.existingAssets || []);
|
|
7
|
-
const attributes = attributesToString(Object.fromEntries(Object.entries(options.attributes || {}).filter(([name])=>![
|
|
8
|
-
'href',
|
|
9
|
-
'rel'
|
|
10
|
-
].includes(name.toLowerCase()))));
|
|
11
|
-
const links = [];
|
|
12
|
-
for (const asset of assets){
|
|
13
|
-
const href = escapeHtmlAttribute(asset);
|
|
14
|
-
if (!('' === asset || seen.has(asset) || hasStylesheetLink(options.template, asset) || hasStylesheetLink(options.template, href))) {
|
|
15
|
-
seen.add(asset);
|
|
16
|
-
links.push(`<link${attributes} href="${href}" rel="stylesheet" />`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return links.join('');
|
|
20
|
-
};
|
|
21
|
-
export { createFederatedCssLinks };
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { getRouterMatchedRouteIds } from "../../router/runtime/lifecycle.mjs";
|
|
3
|
-
import { CHUNK_JS_PLACEHOLDER } from "./constants.mjs";
|
|
4
|
-
import { attributesToString, safeReplace } from "./utils.mjs";
|
|
5
|
-
function getScriptTags(template) {
|
|
6
|
-
const scriptRegExp = /<script\b[^>]*\bsrc=(["'])(.*?)\1[^>]*><\/script>/g;
|
|
7
|
-
return Array.from(template.matchAll(scriptRegExp)).map((match)=>({
|
|
8
|
-
index: match.index ?? 0,
|
|
9
|
-
tag: match[0],
|
|
10
|
-
src: match[2]
|
|
11
|
-
}));
|
|
12
|
-
}
|
|
13
|
-
function getAssetBasename(src) {
|
|
14
|
-
const withoutQuery = src.split(/[?#]/)[0];
|
|
15
|
-
return withoutQuery.split('/').pop() || withoutQuery;
|
|
16
|
-
}
|
|
17
|
-
function isEntryScript(src, entryName, asyncEntry) {
|
|
18
|
-
const basename = getAssetBasename(src);
|
|
19
|
-
const prefix = asyncEntry ? `async-${entryName}` : entryName;
|
|
20
|
-
return basename === `${prefix}.js` || basename.startsWith(`${prefix}.`) || basename.startsWith(`${prefix}-`);
|
|
21
|
-
}
|
|
22
|
-
const dedupeByUrl = (chunks)=>{
|
|
23
|
-
const seen = new Set();
|
|
24
|
-
return chunks.filter((chunk)=>{
|
|
25
|
-
if (void 0 === chunk.url || '' === chunk.url || seen.has(chunk.url)) return false;
|
|
26
|
-
seen.add(chunk.url);
|
|
27
|
-
return true;
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
const isAsyncEntryScriptChunk = (chunk, entryName)=>{
|
|
31
|
-
if (void 0 === chunk.url || !chunk.url.endsWith('.js')) return false;
|
|
32
|
-
const asyncEntryName = `async-${entryName}`;
|
|
33
|
-
const filename = chunk.filename ?? chunk.url;
|
|
34
|
-
const basename = filename.split('/').pop() ?? filename;
|
|
35
|
-
return basename === `${asyncEntryName}.js` || basename.startsWith(`${asyncEntryName}.`) || basename.startsWith(`${asyncEntryName}-`);
|
|
36
|
-
};
|
|
37
|
-
function getRouteAssets(runtimeContext, routeManifest = runtimeContext.routeManifest) {
|
|
38
|
-
return routeManifest?.routeAssets;
|
|
39
|
-
}
|
|
40
|
-
function getMatchedRouteAssets(runtimeContext, routeManifest) {
|
|
41
|
-
const routeAssets = getRouteAssets(runtimeContext, routeManifest);
|
|
42
|
-
if (void 0 === routeAssets) return [];
|
|
43
|
-
const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
|
|
44
|
-
return matchedRouteIds.flatMap((routeId)=>routeAssets[routeId]?.assets ?? []);
|
|
45
|
-
}
|
|
46
|
-
function getMatchedRouteChunks(runtimeContext, routeManifest, routeAssetToChunk) {
|
|
47
|
-
if (void 0 === routeManifest) return [];
|
|
48
|
-
return getMatchedRouteAssets(runtimeContext, routeManifest).map(routeAssetToChunk);
|
|
49
|
-
}
|
|
50
|
-
const orderHydrationScriptChunks = ({ asyncEntryChunks, collectedChunks, matchedRouteChunks, entryName })=>{
|
|
51
|
-
const asyncEntryScriptChunks = [];
|
|
52
|
-
const asyncEntryDependencyChunks = [];
|
|
53
|
-
for (const chunk of asyncEntryChunks)if (isAsyncEntryScriptChunk(chunk, entryName)) asyncEntryScriptChunks.push(chunk);
|
|
54
|
-
else asyncEntryDependencyChunks.push(chunk);
|
|
55
|
-
return dedupeByUrl([
|
|
56
|
-
...asyncEntryDependencyChunks,
|
|
57
|
-
...collectedChunks,
|
|
58
|
-
...matchedRouteChunks,
|
|
59
|
-
...asyncEntryScriptChunks
|
|
60
|
-
]);
|
|
61
|
-
};
|
|
62
|
-
function injectBeforeHydrationEntryScript(template, scripts, entryName = 'index') {
|
|
63
|
-
if ('' === scripts) return template;
|
|
64
|
-
const scriptTags = getScriptTags(template);
|
|
65
|
-
const target = scriptTags.find((match)=>isEntryScript(match.src, entryName, false)) ?? scriptTags.find((match)=>isEntryScript(match.src, entryName, true));
|
|
66
|
-
if (void 0 === target) return template;
|
|
67
|
-
return `${template.slice(0, target.index)}${scripts}${template.slice(target.index)}`;
|
|
68
|
-
}
|
|
69
|
-
function replaceChunkJsPlaceholder(template, scripts, entryName, placeholder = CHUNK_JS_PLACEHOLDER) {
|
|
70
|
-
if (!template.includes(placeholder)) return template;
|
|
71
|
-
if ('' === scripts) return safeReplace(template, placeholder, '');
|
|
72
|
-
const withoutPlaceholder = safeReplace(template, placeholder, '');
|
|
73
|
-
const withEarlyScripts = injectBeforeHydrationEntryScript(withoutPlaceholder, scripts, entryName);
|
|
74
|
-
if (withEarlyScripts !== withoutPlaceholder) return withEarlyScripts;
|
|
75
|
-
return safeReplace(template, placeholder, scripts);
|
|
76
|
-
}
|
|
77
|
-
function createRouteHydrationScriptTags(runtimeContext, entryName, options = {}) {
|
|
78
|
-
const { nonce, template } = options;
|
|
79
|
-
const routeAssets = getRouteAssets(runtimeContext);
|
|
80
|
-
if (void 0 === routeAssets) return '';
|
|
81
|
-
const existingScriptSrcs = void 0 === template ? new Set() : new Set(getScriptTags(template).map(({ src })=>src));
|
|
82
|
-
const jsAssets = Array.from(new Set([
|
|
83
|
-
...getMatchedRouteAssets(runtimeContext),
|
|
84
|
-
...routeAssets[`async-${entryName}`]?.assets ?? []
|
|
85
|
-
].filter((asset)=>asset.endsWith('.js'))));
|
|
86
|
-
return jsAssets.filter((asset)=>!existingScriptSrcs.has(asset)).map((asset)=>`<script${attributesToString({
|
|
87
|
-
src: asset,
|
|
88
|
-
nonce: nonce || void 0
|
|
89
|
-
})}></script>`).join(' ');
|
|
90
|
-
}
|
|
91
|
-
export { createRouteHydrationScriptTags, getMatchedRouteChunks, injectBeforeHydrationEntryScript, orderHydrationScriptChunks, replaceChunkJsPlaceholder };
|