packages/core/src/lib/pibbl.ts
This is the source snapshot used to build these API details. View this revision on GitHub.
1 import { prepareLayoutModule } from './layout/wasm/module.js';
2 import { reserveMount } from './mount-request.js';
3 import { assertMountRequest, mountPreparedPibbl } from './mount-prepared-pibbl.js';
4 import type { PibblController, PibblNode } from './types.js';
5 import type { PibblConfig } from './surface/types.js';
6
7 /**
8 * Fetches and compiles the external layout WASM ahead of mounting. Concurrent
9 * calls share one attempt; a later call retries after failure. Creates no mount.
10 * HTML preload can independently warm the network cache.
11 * @returns A Promise fulfilled when the compatible compiled module is ready.
12 * @throws Rejects on fetch, integrity or compilation failure, with the original cause.
13 * @see {@link pibbl}
14 */
15 export function prepareLayoutEngine(): Promise<void> { return prepareLayoutModule(); }
16
17 /**
18 * Prepares the external layout engine, then mounts or updates one Canvas.
19 * The first live mount owns surface configuration and its lifetime signal.
20 * Layout, component evaluation and scheduled frames remain synchronous.
21 * @param canvas The HTML Canvas owned by the mount.
22 * @param element The branded recursive root descriptor. See {@link PibblNode}.
23 * @param config Surface and lifetime options. See {@link PibblConfig}.
24 * @returns A Promise for the stable {@link PibblController}; dispose releases the mount.
25 * @throws Rejects on loading/mount failure, or with AbortError on cancellation,
26 * supersession or disposal while pending. A later call retries failed loading.
27 * @see {@link prepareLayoutEngine}
28 * @see {@link PibblController}
29 */
30 export async function pibbl(
31 canvas: HTMLCanvasElement,
32 element: PibblNode,
33 config?: PibblConfig,
34 ): Promise<PibblController> {
35 assertMountRequest(canvas, element, config);
36 const request = reserveMount(canvas, config?.signal);
37 try {
38 await Promise.race([prepareLayoutModule(), request.cancelled]);
39 request.assertCurrent();
40 // Clear only the pending reservation; mounted lifetime ownership takes over.
41 request.finish();
42 return mountPreparedPibbl(canvas, element, config);
43 } finally {
44 request.finish();
45 }
46 }
47
Documentation version
Section titled “Documentation version”Documentation built with @pibbl/core 0.0.2, revision a1dcf8e. ALPHA — NOT FOR PRODUCTION USE.