import { PreparedImage } from "./image-pipeline.ts"; export interface DraftImage { placeholder: string; prepared: PreparedImage; } /** Owns numbering and active draft identity; pending work cannot revive removed entries. */ export class DraftStore { images = new Map(); private nextNumber = 1; allocate(text = "", entries: ReadonlyMap = this.images): string { let marker: string; do { marker = `[Image #${this.nextNumber++}]`; } while (text.includes(marker) || entries.has(marker)); return marker; } reset(nextNumber?: number): void { this.images = new Map(); if (nextNumber !== undefined) this.nextNumber = nextNumber; } has(image: DraftImage): boolean { return this.images.get(image.placeholder) === image; } reference(marker: string): string | undefined { return this.images.get(marker)?.prepared.reference; } }