{"version":3,"sources":["../../../src/server/og/image-response.ts"],"sourcesContent":["type OgModule = typeof import('next/dist/compiled/@vercel/og')\n\nfunction importModule(): Promise<\n  typeof import('next/dist/compiled/@vercel/og')\n> {\n  return import(\n    process.env.NEXT_RUNTIME === 'edge'\n      ? 'next/dist/compiled/@vercel/og/index.edge.js'\n      : 'next/dist/compiled/@vercel/og/index.node.js'\n  )\n}\n\n// The Cache Components-specific caching path (and its React Flight and Node\n// stream dependencies) lives in a separate module that is only required for\n// Node.js Cache Components builds. The `NEXT_RUNTIME` guard matters because\n// `__NEXT_CACHE_COMPONENTS` is derived from config, not the per-route runtime,\n// so it stays `true` in edge bundles too. A Pages Router edge route that\n// renders an `ImageResponse` is valid under Cache Components, and without the\n// guard this node-only module would be pulled into that edge bundle and fail to\n// compile. (App Router edge routes, including metadata routes, are\n// independently rejected at compile time under Cache Components.) Both checks\n// fold to constants at build time, so the `require` is eliminated as dead code\n// for edge builds and for apps without Cache Components, which keep\n// ImageResponse's original streaming behavior.\nlet getCachedImageResponseBody:\n  | typeof import('./cache-image-response').getCachedImageResponseBody\n  | undefined\nif (\n  process.env.NEXT_RUNTIME !== 'edge' &&\n  process.env.__NEXT_CACHE_COMPONENTS\n) {\n  getCachedImageResponseBody = (\n    require('./cache-image-response') as typeof import('./cache-image-response')\n  ).getCachedImageResponseBody\n}\n\n/**\n * The ImageResponse class allows you to generate dynamic images using JSX and CSS.\n * This is useful for generating social media images such as Open Graph images, Twitter cards, and more.\n *\n * Read more: [Next.js Docs: `ImageResponse`](https://nextjs.org/docs/app/api-reference/functions/image-response)\n */\nexport class ImageResponse extends Response {\n  public static displayName = 'ImageResponse'\n  constructor(...args: ConstructorParameters<OgModule['ImageResponse']>) {\n    // Under Cache Components, route the render through the cache so metadata\n    // image routes can be statically prerendered. Otherwise stream the rendered\n    // image directly from the underlying `@vercel/og` response.\n    const readable = getCachedImageResponseBody\n      ? getCachedImageResponseBody(args)\n      : new ReadableStream({\n          async start(controller) {\n            const OGImageResponse: typeof import('next/dist/compiled/@vercel/og').ImageResponse =\n              // So far we have to manually determine which build to use, as the\n              // auto resolving is not working\n              (await importModule()).ImageResponse\n            const imageResponse = new OGImageResponse(...args) as Response\n\n            if (!imageResponse.body) {\n              return controller.close()\n            }\n\n            const reader = imageResponse.body.getReader()\n            while (true) {\n              const { done, value } = await reader.read()\n              if (done) {\n                return controller.close()\n              }\n              controller.enqueue(value)\n            }\n          },\n        })\n\n    const options = args[1] || {}\n\n    const headers = new Headers({\n      'content-type': 'image/png',\n      'cache-control':\n        process.env.NODE_ENV === 'development'\n          ? 'no-cache, no-store'\n          : 'public, max-age=0, must-revalidate',\n    })\n    if (options.headers) {\n      const newHeaders = new Headers(options.headers)\n      newHeaders.forEach((value, key) => headers.set(key, value))\n    }\n    super(readable, {\n      headers,\n      status: options.status,\n      statusText: options.statusText,\n    })\n  }\n}\n"],"names":["ImageResponse","importModule","process","env","NEXT_RUNTIME","getCachedImageResponseBody","__NEXT_CACHE_COMPONENTS","require","Response","displayName","constructor","args","readable","ReadableStream","start","controller","OGImageResponse","imageResponse","body","close","reader","getReader","done","value","read","enqueue","options","headers","Headers","NODE_ENV","newHeaders","forEach","key","set","status","statusText"],"mappings":";;;;+BA0CaA;;;eAAAA;;;AAxCb,SAASC;IAGP,OAAO,MAAM,CACXC,QAAQC,GAAG,CAACC,YAAY,KAAK,SACzB,gDACA;AAER;AAEA,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAC5E,+EAA+E;AAC/E,yEAAyE;AACzE,8EAA8E;AAC9E,gFAAgF;AAChF,mEAAmE;AACnE,8EAA8E;AAC9E,+EAA+E;AAC/E,oEAAoE;AACpE,+CAA+C;AAC/C,IAAIC;AAGJ,IACEH,QAAQC,GAAG,CAACC,YAAY,KAAK,UAC7BF,QAAQC,GAAG,CAACG,uBAAuB,EACnC;IACAD,6BAA6B,AAC3BE,QAAQ,0BACRF,0BAA0B;AAC9B;AAQO,MAAML,sBAAsBQ;qBACnBC,cAA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