1// Package-owned browser boot orchestration.2import { restoreDeclaredSink } from "./data-sink.ts";3import { registerProductionServiceWorker } from "./pwa.ts";45let booted = false;67/**8 * Starts lofi's browser lifecycle once for the current document.9 *10 * Import the module that calls `defineLofiApp` first so the runtime can resolve11 * the app definition. Safe to call more than once; later calls are no-ops.12 *13 * @example14 * ```ts15 * import { bootLofi } from "@nzip/lofi";16 * // Importing app.ts registers defineLofiApp before the runtime boots.17 * import { app } from "../app.ts";18 *19 * void app;20 * void bootLofi();21 * ```22 *23 * @returns A promise that resolves once boot has been scheduled for this document.24 */25export async function bootLofi(): Promise<void> {26 if (booted || typeof document === "undefined") return;27 booted = true;28 // The sink envelope must be open before lifecycle.ts reads the sync29 // location at import time. A restore failure degrades to local-only; it30 // must never brick boot.31 try {32 await restoreDeclaredSink();33 } catch {34 // Continue local-only; enrollment can re-declare the sink.35 }36 await import("./lifecycle.ts");37 registerProductionServiceWorker();38 if (import.meta.env.DEV) void import("./probe.ts");39}