/** * The one place an engine is chosen: everything else speaks the `Engine` contract only. * `createLocalEngineWithWorker` constructs synchronously and boots lazily (the viewer warms it * up when it starts), so the page renders at once and only opening a document waits for it. */ import type { Engine, OpenInput } from '@embedpdf/angular/runtime'; import { createLocalEngineWithWorker } from '@embedpdf/engine'; export function createEngine(): Engine { return createLocalEngineWithWorker({ // Thunk: the Worker allocates when the engine boots, not at construction. worker: () => new Worker(new URL('./engine.worker', import.meta.url), { type: 'module' }), }); } export const fetchBytes = async (url: string): Promise => { const response = await fetch(url); if (!response.ok) { throw new Error(`failed to fetch ${url}: ${response.status} ${response.statusText}`); } return new Uint8Array(await response.arrayBuffer()); }; /** The local engine opens BYTES (no URL kind) — fetch, then hand over. */ export async function sampleSource(id: string, url: string): Promise { return { kind: 'bytes', id, bytes: await fetchBytes(url) }; }