{"version":3,"file":"runtime.mjs","names":[],"sources":["../src/media/provider-loader.ts"],"sourcesContent":["/**\n * Media Provider Loader\n *\n * Lazy-loads media providers from virtual module for frontend rendering.\n * Similar pattern to getDb() - providers are loaded on first use and cached.\n *\n * This allows EmDashMedia component to render media without requiring\n * the full EmDash runtime to be initialized.\n */\n\nimport type { MediaProvider, MediaProviderCapabilities } from \"./types.js\";\n\n/**\n * Media provider entry from virtual module\n */\ninterface MediaProviderEntry {\n\tid: string;\n\tname: string;\n\ticon?: string;\n\tcapabilities: MediaProviderCapabilities;\n\tcreateProvider: (ctx: Record<string, unknown>) => MediaProvider;\n}\n\n// Cached provider entries from virtual module\nlet virtualMediaProviders: MediaProviderEntry[] | undefined;\n\n// Cached provider instances (shared across calls)\nconst mediaProviderInstances = new Map<string, MediaProvider>();\n\n/**\n * Load media providers from virtual module\n */\nasync function loadMediaProviders(): Promise<void> {\n\tif (virtualMediaProviders === undefined) {\n\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t// @ts-ignore - virtual module\n\t\tconst providersModule = await import(\"virtual:emdash/media-providers\");\n\t\tvirtualMediaProviders = providersModule.mediaProviders || [];\n\t}\n}\n\n/**\n * Get a media provider by ID.\n *\n * Used by EmDashMedia component for frontend rendering.\n * Providers are lazy-loaded from virtual module and cached.\n *\n * @example\n * ```ts\n * const provider = await getMediaProvider(\"cloudflare-images\");\n * if (provider) {\n *   const embed = provider.getEmbed(mediaValue, { width: 800 });\n * }\n * ```\n */\nexport async function getMediaProvider(providerId: string): Promise<MediaProvider | undefined> {\n\t// Check cache first\n\tconst cached = mediaProviderInstances.get(providerId);\n\tif (cached) {\n\t\treturn cached;\n\t}\n\n\t// Load media providers from virtual module\n\tawait loadMediaProviders();\n\n\t// Find the provider entry\n\tconst entry = virtualMediaProviders?.find((p) => p.id === providerId);\n\tif (!entry) {\n\t\treturn undefined;\n\t}\n\n\t// Create the provider instance\n\t// For providers that don't need db/storage (like Cloudflare Images),\n\t// they'll get empty context and use env vars directly\n\tconst provider = entry.createProvider({});\n\tmediaProviderInstances.set(providerId, provider);\n\treturn provider;\n}\n"],"mappings":";;;;;;;AAwBA,IAAI;AAGJ,MAAM,yCAAyB,IAAI,KAA4B;;;;AAK/D,eAAe,qBAAoC;AAClD,KAAI,0BAA0B,OAI7B,0BADwB,MAAM,OAAO,mCACG,kBAAkB,EAAE;;;;;;;;;;;;;;;;AAkB9D,eAAsB,iBAAiB,YAAwD;CAE9F,MAAM,SAAS,uBAAuB,IAAI,WAAW;AACrD,KAAI,OACH,QAAO;AAIR,OAAM,oBAAoB;CAG1B,MAAM,QAAQ,uBAAuB,MAAM,MAAM,EAAE,OAAO,WAAW;AACrE,KAAI,CAAC,MACJ;CAMD,MAAM,WAAW,MAAM,eAAe,EAAE,CAAC;AACzC,wBAAuB,IAAI,YAAY,SAAS;AAChD,QAAO"}