'use strict'; var path2 = require('path'); var core = require('@kubb/core'); var pluginOas = require('@kubb/plugin-oas'); var fs = require('fs'); var pkg = require('handlebars'); var server = require('react-dom/server'); var styledComponents = require('styled-components'); var redoc = require('redoc'); var jsxRuntime = require('react/jsx-runtime'); function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } var path2__default = /*#__PURE__*/_interopDefault(path2); var fs__default = /*#__PURE__*/_interopDefault(fs); var pkg__default = /*#__PURE__*/_interopDefault(pkg); var redoc__default = /*#__PURE__*/_interopDefault(redoc); var __getOwnPropNames = Object.getOwnPropertyNames; var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) { if (typeof require !== "undefined") return require.apply(this, arguments); throw Error('Dynamic require of "' + x + '" is not supported'); }); var __esm = (fn, res) => function __init() { return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; }; // ../../node_modules/.pnpm/tsup@8.3.5_@microsoft+api-extractor@7.47.11_@types+node@20.17.6__@swc+core@1.7.22_jiti@2.4.0__afcbdmn77djggoyp3p3b3gekj4/node_modules/tsup/assets/cjs_shims.js var init_cjs_shims = __esm({ "../../node_modules/.pnpm/tsup@8.3.5_@microsoft+api-extractor@7.47.11_@types+node@20.17.6__@swc+core@1.7.22_jiti@2.4.0__afcbdmn77djggoyp3p3b3gekj4/node_modules/tsup/assets/cjs_shims.js"() { } }); // src/index.ts init_cjs_shims(); // src/plugin.ts init_cjs_shims(); // ../fs/src/index.ts init_cjs_shims(); function trimExtName(text) { return text.replace(/\.[^/.]+$/, ""); } // src/redoc.tsx init_cjs_shims(); function escapeClosingScriptTag(str) { return str.replace(/<\/script>/g, "<\\/script>"); } function escapeUnicode(str) { return str.replace(/\u2028|\u2029/g, (m) => "\\u202" + (m === "\u2028" ? "8" : "9")); } function sanitizeJSONString(str) { return escapeClosingScriptTag(escapeUnicode(str)); } async function getPageHTML(api, { title, disableGoogleFont, templateOptions, redocOptions = {} } = {}) { const apiUrl = redocOptions.specUrl; const { Redoc, createStore } = redoc__default.default || __require("redoc"); const store = await createStore(api, apiUrl, redocOptions); const sheet = new styledComponents.ServerStyleSheet(); const error = console.error; console.error = (...args) => { if (/defaultProps/.test(args[0])) return; error(...args); }; const html = server.renderToString(sheet.collectStyles(/* @__PURE__ */ jsxRuntime.jsx(Redoc, { store }))); const state = await store.toJS(); const css = sheet.getStyleTags(); const templateFileName = path2__default.default.join(__dirname, "../static/redoc.hbs"); const template = pkg__default.default.compile(fs__default.default.readFileSync(templateFileName).toString()); return template({ redocHTML: `
${html || ""}
`, redocHead: ( // biome-ignore lint/style/useTemplate: `` + css ), title: title || api.info.title || "ReDoc documentation", disableGoogleFont, templateOptions }); } // src/plugin.ts var pluginRedocName = "plugin-redoc"; var pluginRedoc = core.createPlugin((options) => { const { output = { path: "docs.html" } } = options; return { name: pluginRedocName, options: { output, name: trimExtName(output.path) }, pre: [pluginOas.pluginOasName], async buildStart() { const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]); const oas = await swaggerPlugin.context.getOas(); await oas.dereference(); const root = path2__default.default.resolve(this.config.root, this.config.output.path); const pageHTML = await getPageHTML(oas.api); await this.fileManager.write(path2__default.default.resolve(root, output.path || "./docs.html"), pageHTML); } }; }); exports.pluginRedoc = pluginRedoc; exports.pluginRedocName = pluginRedocName; //# sourceMappingURL=index.cjs.map //# sourceMappingURL=index.cjs.map