'use client'; // Promise-singleton init for the browser layout engine. The first caller // kicks off the wasm fetch + font registration; subsequent callers get // the same in-flight promise. Survives App Router client navigations. // // CRITICAL: the layout-engine browser barrel statically re-exports // dropflow's browser wrapper, which transitively imports dropflow's // wasm.js. wasm.js does `await environment.wasmLocator()` at module top // level. If we statically import the barrel here, that top-level await // fires at page-load — before our locator is installed — and throws // "Wasm location not configured". So we dynamic-import the whole barrel // inside the singleton. This keeps the entire dropflow subtree out of // the synchronous module graph for any page that imports this file. let promise: Promise | null = null; export function ensureBrowserEngine(): Promise { if (!promise) { promise = (async () => { const { initLayoutEngine } = await import( '@banner-studio/layout-engine/browser' ); await initLayoutEngine({ fonts: [ { family: 'Inter', weight: 400, path: '/fonts/Inter-Regular.ttf' }, { family: 'Inter', weight: 700, path: '/fonts/Inter-Bold.ttf' } ] }); })(); } return promise; }