{"version":3,"file":"registry.cjs","names":[],"sources":["../../../src/image/registry.ts"],"sourcesContent":["// --- Shared image registry (build-time singleton) ---\n//\n// This module owns the mutable state the image pipeline relies on:\n//   * `renderRegistry`  — images registered by `image()` during a render pass.\n//   * `activeManifest`  — the processed manifest used to emit `<picture>`.\n//\n// It MUST stay in its own chunk (`dist/lib/image/registry.js`) so that both the\n// CLI bundle (`dist/lib/cli.js`) and the library entry (`dist/lib/image/index.js`)\n// import the *same* physical module instance. If the registry state is inlined\n// into the CLI, `consumeImageRegistry()` reads a different (empty) array than\n// the one the app's `image()` calls populated, and the two-pass build silently\n// processes nothing. Both vite configs externalize this chunk to enforce that.\n\nimport type { ImageManifest } from \"./service.js\";\n\nexport type ImageFormat = \"webp\" | \"avif\" | \"jpeg\" | \"png\";\n\nexport interface RegisteredImage {\n  src: string;\n  widths: number[];\n  formats: ImageFormat[];\n}\n\nconst renderRegistry: RegisteredImage[] = [];\n\n/**\n * The active image manifest (if loaded). When set, image() emits real\n * <picture>/<source> markup from the manifest instead of a plain <img>.\n */\nlet activeManifest: ImageManifest | null = null;\n\n/**\n * Set the active image manifest. Called by the build pipeline after\n * processing, or by the SSR server on startup.\n */\nexport function setImageManifest(manifest: ImageManifest | null): void {\n  activeManifest = manifest;\n}\n\n/**\n * Returns the currently active image manifest (or null). Used by `image()`\n * to decide between `<picture>` (manifest present) and plain `<img>`.\n */\nexport function getActiveManifest(): ImageManifest | null {\n  return activeManifest;\n}\n\n/**\n * Returns the images registered during the current render pass and clears\n * the registry. Called by the build pipeline after rendering all pages.\n */\nexport function consumeImageRegistry(): RegisteredImage[] {\n  const items = [...renderRegistry];\n  renderRegistry.length = 0;\n  return items;\n}\n\n/**\n * Registers an image for build-time processing (if sharp is available).\n */\nexport function registerImage(src: string, widths: number[]): void {\n  // Avoid duplicates in the same render pass.\n  const existing = renderRegistry.find(\n    (r) => r.src === src && r.widths.join(\",\") === widths.join(\",\"),\n  );\n  if (!existing) {\n    renderRegistry.push({ src, widths, formats: [\"webp\", \"avif\"] });\n  }\n}\n"],"mappings":"mEAuBA,IAAM,EAAoC,CAAC,EAMvC,EAAuC,KAM3C,SAAgB,EAAiB,EAAsC,CACrE,EAAiB,CACnB,CAMA,SAAgB,GAA0C,CACxD,OAAO,CACT,CAMA,SAAgB,GAA0C,CACxD,IAAM,EAAQ,CAAC,GAAG,CAAc,EAEhC,MADA,GAAe,OAAS,EACjB,CACT,CAKA,SAAgB,EAAc,EAAa,EAAwB,CAEhD,EAAe,KAC7B,GAAM,EAAE,MAAQ,GAAO,EAAE,OAAO,KAAK,GAAG,IAAM,EAAO,KAAK,GAAG,CAE3D,GACH,EAAe,KAAK,CAAE,MAAK,SAAQ,QAAS,CAAC,OAAQ,MAAM,CAAE,CAAC,CAElE"}