UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

67 lines (65 loc) 2.62 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); //#region src/ui/head.ts function getRemoteEntryScript(assetsUrl, integrity) { const script = { src: `${assetsUrl}/remoteEntry.js` }; if (integrity) { script.integrity = integrity; script.crossOrigin = "anonymous"; } return script; } function getThemeInitScript() { return { children: "(function(){var t=localStorage.getItem('theme');if(t==='dark'||(!t&&window.matchMedia('(prefers-color-scheme: dark)').matches)){document.documentElement.classList.add('dark');}})();" }; } function getHydrateScript(runtimeConfig, containerName = "ui", hydratePath = "./Hydrate") { return { children: ` window.__RUNTIME_CONFIG__=${JSON.stringify(runtimeConfig)}; function __hydrate(){ var container = window['${containerName}']; if (!container) { console.warn('[Hydrate] Container not ready yet, waiting...'); window.__hydrateRetry = window.__hydrateRetry || 0; if (window.__hydrateRetry < 10) { window.__hydrateRetry++; setTimeout(__hydrate, 100); return; } console.error('[Hydrate] Container not found after 10 retries'); return; } console.log('[Hydrate] Container available, starting init...'); container.init({}).then(function(){ return container.get('${hydratePath}'); }).then(function(mod){ return mod().hydrate(); }).catch(function(e){ console.error('[Hydrate] Failed:', e); }); } if(document.readyState==='loading'){document.addEventListener('DOMContentLoaded',__hydrate);}else{__hydrate();} `.trim() }; } function getRemoteScripts(options) { const { assetsUrl, runtimeConfig, containerName, hydratePath, integrity } = options; return [ getRemoteEntryScript(assetsUrl, integrity), getThemeInitScript(), getHydrateScript(runtimeConfig, containerName, hydratePath) ]; } function getBaseStyles() { return ` *, *::before, *::after { box-sizing: border-box; } html { height: 100%; height: 100dvh; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; color-scheme: light dark; } body { min-height: 100%; min-height: 100dvh; margin: 0; background-color: var(--background); color: var(--foreground); -webkit-tap-highlight-color: transparent; touch-action: manipulation; } #root { min-height: 100vh; } @supports (min-height: 100dvh) { #root { min-height: 100dvh; } } `.trim(); } //#endregion exports.getBaseStyles = getBaseStyles; exports.getHydrateScript = getHydrateScript; exports.getRemoteEntryScript = getRemoteEntryScript; exports.getRemoteScripts = getRemoteScripts; exports.getThemeInitScript = getThemeInitScript; //# sourceMappingURL=head.cjs.map