{"version":3,"sources":["jsdelivr-header.js","/npm/storybook-builder-vite@0.1.23/index.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,wvBCJA,MAAA,GAAA,aAAA,QAAA,OACA,KAAA,aAAA,QAAA,SACA,wBAAA,QAAA,2BACA,cAAA,QAAA,iBACA,QAAA,QAAA,WAWA,SAAS,iBAAiB,EAA0B,GAClD,OAAO,MAAO,EAAK,EAAK,KACtB,IAAK,EAAI,IAAI,MAAM,yBAEjB,YADA,IAMF,QAAgC,IAA5B,EAAI,MAAM,cAEZ,YADA,IAIF,MAAM,EAAY,GAAG,aAAa,KAAK,QAAQ,UAAW,KAAM,QAAS,eAAgB,SACnF,QAAkB,EAAA,wBAAA,qBAAoB,EAAW,GACjD,QAAoB,EAAO,mBAAmB,eAAgB,GACpE,EAAI,UAAU,eAAgB,aAC9B,EAAI,OAAO,KAAK,KAAK,EAAY,CAErC,CAEO,MAAM,MAA8B,OAAS,YAAW,UAAS,SAAQ,OAAQ,MACtF,MAAM,QAAe,EAAA,cAAA,kBAAiB,EAA4B,GAsBlE,OAlBA,EAAO,IAAI,aAAa,CAAC,EAAc,KACrC,EAAI,OAAO,gBAAiB,YAC5B,EAAI,OAAO,eAAgB,oBAAoB,IAGjD,EAAO,UAAU,iBAAiB,EAA4B,IAC9D,EAAO,IAAI,EAAO,aAYX,CACL,KAXF,eAAoB,GAClB,IACE,aAAa,EAAO,O,CACpB,MAAO,GACP,QAAQ,KAAK,8B,CAGf,MAAM,CACR,EAIE,MAAO,GACP,UAAW,QAAQ,OAAO,GAC3B,EA3BU,QAAA,MAAK,MA8BX,MAAM,MAA8B,OAAS,cAC3C,EAAA,QAAA,OAAU,GADN,QAAA,MAAK,MAIL,QAAA,YAAc,GACd,QAAA,eAAiB","file":"/npm/storybook-builder-vite@0.1.23/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/storybook-builder-vite@0.1.23/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// noinspection JSUnusedGlobalSymbols\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { transformIframeHtml } from './transform-iframe-html';\nimport { createViteServer } from './vite-server';\nimport { build as viteBuild } from './build';\n\nimport type { Builder } from '@storybook/core-common';\nimport type { RequestHandler, Request, Response } from 'express';\nimport type { UserConfig, ViteDevServer } from 'vite';\nimport type { ExtendedOptions } from './types';\n\nexport interface ViteStats {}\n\nexport type ViteBuilder = Builder<UserConfig, ViteStats>;\n\nfunction iframeMiddleware(options: ExtendedOptions, server: ViteDevServer): RequestHandler {\n  return async (req, res, next) => {\n    if (!req.url.match(/^\\/iframe\\.html($|\\?)/)) {\n      next();\n      return;\n    }\n\n    // We need to handle `html-proxy` params for style tag HMR https://github.com/storybookjs/builder-vite/issues/266#issuecomment-1055677865\n    // e.g. /iframe.html?html-proxy&index=0.css\n    if (req.query['html-proxy'] !== undefined) {\n      next();\n      return;\n    }\n\n    const indexHtml = fs.readFileSync(path.resolve(__dirname, '..', 'input', 'iframe.html'), 'utf-8');\n    const generated = await transformIframeHtml(indexHtml, options);\n    const transformed = await server.transformIndexHtml('/iframe.html', generated);\n    res.setHeader('Content-Type', 'text/html');\n    res.status(200).send(transformed);\n  };\n}\n\nexport const start: ViteBuilder['start'] = async ({ startTime, options, router, server: devServer }) => {\n  const server = await createViteServer(options as ExtendedOptions, devServer);\n\n  // Just mock this endpoint (which is really Webpack-specific) so we don't get spammed with 404 in browser devtools\n  // TODO: we should either show some sort of progress from Vite, or just try to disable the whole Loader in the Manager UI.\n  router.get('/progress', (req: Request, res: Response) => {\n    res.header('Cache-Control', 'no-cache');\n    res.header('Content-Type', 'text/event-stream');\n  });\n\n  router.use(await iframeMiddleware(options as ExtendedOptions, server));\n  router.use(server.middlewares);\n\n  async function bail(e?: Error): Promise<void> {\n    try {\n      return await server.close();\n    } catch (err) {\n      console.warn('unable to close vite server');\n    }\n\n    throw e;\n  }\n\n  return {\n    bail,\n    stats: {} as ViteStats,\n    totalTime: process.hrtime(startTime),\n  };\n};\n\nexport const build: ViteBuilder['build'] = async ({ options }) => {\n  return viteBuild(options as ExtendedOptions);\n};\n\nexport const corePresets = [];\nexport const previewPresets = [];\n"]}