UNPKG

histoire

Version:

A fast story book powered by Vite

20 lines (19 loc) • 802 B
import { getContextRegistry } from '../registry.js'; /** Each context owns its transform capture and cleanup lifetime. */ const captures = new WeakMap(); /** Captures inline docs during normal transformation, never importing story later. */ export function captureInlineDocs(ctx, path, docs) { let entries = captures.get(ctx); if (!entries) { captures.set(ctx, entries = new Map()); getContextRegistry(ctx).cleanup.add(() => { captures.delete(ctx); }); } entries.set(path, Object.freeze({ ...docs })); } /** Returns only docs transformed from this completed source version. */ export function getInlineDocs(ctx, path, sourceSha256) { const docs = captures.get(ctx)?.get(path); return docs?.sourceSha256 === sourceSha256 ? docs : undefined; }