@clarify-labs/renderer 0.2.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/output/AppShell-D3FsVHQK.js +390 -0
  2. package/output/AppShell-D3FsVHQK.js.map +1 -0
  3. package/output/AppShell-DeaJ-rgo.cjs +409 -0
  4. package/output/AppShell-DeaJ-rgo.cjs.map +1 -0
  5. package/output/OpenApiOperation-DYXG-6Rw.js +1772 -0
  6. package/output/OpenApiOperation-DYXG-6Rw.js.map +1 -0
  7. package/output/OpenApiOperation-mhoi-s4N.cjs +1840 -0
  8. package/output/OpenApiOperation-mhoi-s4N.cjs.map +1 -0
  9. package/output/app/PageNavigation.d.ts +7 -0
  10. package/output/app/PageSkeleton.d.ts +1 -0
  11. package/output/{components → app}/SectionProvider.d.ts +3 -2
  12. package/output/chunk-DakpK96I.cjs +43 -0
  13. package/output/client.cjs +1 -1
  14. package/output/client.js +1 -1
  15. package/output/components/Button.d.ts +18 -0
  16. package/output/components/Code.d.ts +11 -7
  17. package/output/components/Collapse.d.ts +9 -0
  18. package/output/components/Heading.d.ts +10 -0
  19. package/output/components/Logo.d.ts +2 -0
  20. package/output/components/Prose.d.ts +7 -0
  21. package/output/components/Tag.d.ts +34 -0
  22. package/output/components/index.d.ts +9 -79
  23. package/output/components/patterns.d.ts +4 -2
  24. package/output/context.d.ts +1 -6
  25. package/output/core/context.d.ts +8 -0
  26. package/output/core/i18n.d.ts +5 -0
  27. package/output/core/index.d.ts +3 -0
  28. package/output/core/types.d.ts +174 -0
  29. package/output/i18n.d.ts +1 -0
  30. package/output/index.cjs +135 -766
  31. package/output/index.cjs.map +1 -1
  32. package/output/index.d.ts +15 -4
  33. package/output/index.js +108 -751
  34. package/output/index.js.map +1 -1
  35. package/output/markdown.cjs +3 -0
  36. package/output/markdown.d.ts +1 -0
  37. package/output/markdown.js +2 -0
  38. package/output/mdx/DocShell.d.ts +7 -0
  39. package/output/mdx/Markdown.d.ts +7 -0
  40. package/output/mdx/components.d.ts +7 -7
  41. package/output/mdx/primitives.d.ts +18 -12
  42. package/output/mdx/remark.d.ts +2 -0
  43. package/output/openapi/components/ExamplePanels.d.ts +36 -0
  44. package/output/openapi/components/OpenApiOperation.d.ts +33 -0
  45. package/output/openapi/components/SchemaProperties.d.ts +20 -0
  46. package/output/openapi/entry.d.ts +13 -0
  47. package/output/openapi/index.d.ts +3 -20
  48. package/output/openapi/lib/helpers.d.ts +25 -0
  49. package/output/openapi/lib/request-code.d.ts +18 -0
  50. package/output/openapi/lib/spec-path.d.ts +2 -0
  51. package/output/openapi/types.d.ts +70 -0
  52. package/output/preview/openapi.d.ts +28 -0
  53. package/output/preview.cjs +734 -0
  54. package/output/preview.cjs.map +1 -0
  55. package/output/preview.d.ts +19 -0
  56. package/output/preview.js +731 -0
  57. package/output/preview.js.map +1 -0
  58. package/output/remark-DNOdJz5i.cjs +14 -0
  59. package/output/remark-DNOdJz5i.cjs.map +1 -0
  60. package/output/remark-o5sg9Ilv.js +7 -0
  61. package/output/remark-o5sg9Ilv.js.map +1 -0
  62. package/output/{render-bPMMBoDH.js → render-BpavVnAe.js} +3 -2
  63. package/output/render-BpavVnAe.js.map +1 -0
  64. package/output/{render-z9rSQ00n.cjs → render-CjZt3edL.cjs} +6 -5
  65. package/output/render-CjZt3edL.cjs.map +1 -0
  66. package/output/renderer.css +1702 -591
  67. package/output/server.cjs +7 -5
  68. package/output/server.cjs.map +1 -1
  69. package/output/server.js +4 -2
  70. package/output/server.js.map +1 -1
  71. package/output/shell/ContentActions.d.ts +1 -0
  72. package/output/shell/Header.d.ts +4 -3
  73. package/output/shell/Navigation.d.ts +3 -2
  74. package/output/shell/Search.d.ts +6 -4
  75. package/output/{components → shell}/SiteLogo.d.ts +1 -1
  76. package/output/shell/icons.d.ts +5 -0
  77. package/output/shell/mobile.d.ts +5 -3
  78. package/output/{AppShell-Ci894P_0.js → shell-BlMMdTpZ.js} +1228 -867
  79. package/output/shell-BlMMdTpZ.js.map +1 -0
  80. package/output/{AppShell-4KB3lU-n.cjs → shell-_MyLsMUI.cjs} +1403 -1036
  81. package/output/shell-_MyLsMUI.cjs.map +1 -0
  82. package/output/{components → theme}/ThemeProvider.d.ts +3 -2
  83. package/output/types.d.ts +1 -121
  84. package/output/utils/clipboard.d.ts +1 -0
  85. package/output/utils/hash.d.ts +1 -0
  86. package/output/utils/href.d.ts +5 -0
  87. package/output/utils/lucide.d.ts +17 -0
  88. package/output/utils/path.d.ts +2 -0
  89. package/package.json +24 -10
  90. package/output/AppShell-4KB3lU-n.cjs.map +0 -1
  91. package/output/AppShell-Ci894P_0.js.map +0 -1
  92. package/output/render-bPMMBoDH.js.map +0 -1
  93. package/output/render-z9rSQ00n.cjs.map +0 -1
  94. /package/output/{components → app}/BuiltWithClarify.d.ts +0 -0
  95. /package/output/{components → app}/PageFooter.d.ts +0 -0
  96. /package/output/openapi/{utils.d.ts → lib/utils.d.ts} +0 -0
  97. /package/output/{components → theme}/ThemeToggle.d.ts +0 -0
package/output/index.js CHANGED
@@ -1,174 +1,37 @@
1
- import { C as Card, D as SectionProvider, E as BuiltWithClarify, O as useSectionStore, S as Pre, T as Callout, _ as GridPattern, a as Heading, b as Code, c as Tag, d as useTheme, f as PageFooter, g as useOpenApis, h as useClarifyConfig, i as DocShell, k as remToPx, l as ThemeToggle, m as OpenApisContext, n as ApiEndpointCard, o as Logo, p as ClarifyConfigContext, r as Button, s as Prose, t as AppShell, u as ThemeProvider, v as HeroPattern, w as CardGroup, x as CodeGroup, y as Feedback } from "./AppShell-Ci894P_0.js";
2
- import { t as render } from "./render-bPMMBoDH.js";
3
- import { createElement, useRef, useState } from "react";
4
- import { Link, useLocation } from "react-router-dom";
5
- import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
6
- import clsx from "clsx";
7
- import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from "@headlessui/react";
8
- import { CheckIcon, ChevronsUpDownIcon } from "lucide-react";
9
- import { slug } from "github-slugger";
10
- //#region \0rolldown/runtime.js
11
- var __defProp = Object.defineProperty;
12
- var __exportAll = (all, no_symbols) => {
13
- let target = {};
14
- for (var name in all) __defProp(target, name, {
15
- get: all[name],
16
- enumerable: true
17
- });
18
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
19
- return target;
20
- };
21
- //#endregion
22
- //#region source/mdx/primitives.tsx
23
- var primitives_exports = /* @__PURE__ */ __exportAll({
24
- Button: () => Button,
25
- Callout: () => Callout,
26
- Card: () => Card,
27
- CardGroup: () => CardGroup,
28
- CodeGroup: () => CodeGroup,
29
- Col: () => Col,
30
- Note: () => Note,
31
- Properties: () => Properties,
32
- Property: () => Property,
33
- Row: () => Row,
34
- a: () => a,
35
- code: () => code,
36
- h2: () => h2,
37
- h3: () => h3,
38
- pre: () => pre,
39
- wrapper: () => wrapper
40
- });
41
- function wrapper(arg0) {
42
- const { children } = arg0;
43
- return /* @__PURE__ */ jsxs("article", {
44
- className: "clarify-mdx-page flex h-full flex-col pt-16 pb-10",
45
- children: [/* @__PURE__ */ jsx(Prose, {
46
- className: "flex-auto",
47
- children
48
- }), /* @__PURE__ */ jsx(PageFooter, {})]
49
- });
50
- }
51
- function a(arg0) {
52
- const { href = "", ...props } = arg0;
53
- if (href.startsWith("/") && !href.startsWith("//")) return /* @__PURE__ */ jsx(Link, {
54
- to: href,
55
- ...props
56
- });
57
- return /* @__PURE__ */ jsx("a", {
58
- href,
59
- ...props
60
- });
61
- }
62
- var code = Code;
63
- var pre = Pre;
64
- function h2(props) {
65
- return createElement(Heading, {
66
- level: 2,
67
- ...props
68
- });
69
- }
70
- function h3(props) {
71
- return createElement(Heading, {
72
- level: 3,
73
- ...props
74
- });
75
- }
76
- function InfoIcon(props) {
77
- return /* @__PURE__ */ jsxs("svg", {
78
- viewBox: "0 0 16 16",
79
- "aria-hidden": "true",
80
- ...props,
81
- children: [
82
- /* @__PURE__ */ jsx("circle", {
83
- cx: "8",
84
- cy: "8",
85
- r: "8",
86
- strokeWidth: "0"
87
- }),
88
- /* @__PURE__ */ jsx("path", {
89
- fill: "none",
90
- strokeLinecap: "round",
91
- strokeLinejoin: "round",
92
- strokeWidth: "1.5",
93
- d: "M6.75 7.75h1.5v3.5"
94
- }),
95
- /* @__PURE__ */ jsx("circle", {
96
- cx: "8",
97
- cy: "4",
98
- r: ".5",
99
- fill: "none"
100
- })
101
- ]
102
- });
103
- }
104
- function Note(arg0) {
105
- const { children } = arg0;
106
- return /* @__PURE__ */ jsxs("div", {
107
- className: "clarify-note my-6 flex gap-2.5 rounded-2xl border border-emerald-500/20 bg-emerald-50/50 p-4 text-sm/6 text-emerald-900 dark:border-emerald-500/30 dark:bg-emerald-500/5 dark:text-emerald-200 dark:[--tw-prose-links-hover:var(--color-emerald-300)] dark:[--tw-prose-links:var(--color-white)]",
108
- children: [/* @__PURE__ */ jsx(InfoIcon, { className: "mt-1 h-4 w-4 flex-none fill-emerald-500 stroke-white dark:fill-emerald-200/20 dark:stroke-emerald-200" }), /* @__PURE__ */ jsx("div", {
109
- className: "*:first:mt-0 *:last:mb-0",
110
- children
111
- })]
112
- });
113
- }
114
- function Row(arg0) {
115
- const { children } = arg0;
116
- return /* @__PURE__ */ jsx("div", {
117
- className: "clarify-row grid grid-cols-1 items-start gap-x-16 gap-y-10 xl:max-w-none xl:grid-cols-2",
118
- children
119
- });
120
- }
121
- function Col(arg0) {
122
- const { children, sticky = false } = arg0;
123
- return /* @__PURE__ */ jsx("div", {
124
- className: clsx("clarify-col *:first:mt-0 *:last:mb-0", sticky && "xl:sticky xl:top-24"),
125
- children
126
- });
1
+ import { f as Markdown, n as OpenApiOperation$1, p as primitives_exports } from "./OpenApiOperation-DYXG-6Rw.js";
2
+ import { E as useTheme, F as OpenApisContext, I as useClarifyConfig, L as useOpenApis, M as useBuiltInText, N as ClarifyConfigContext, T as ThemeProvider, _ as Callout, a as GridPattern, b as useSectionStore, c as Heading, d as Collapse, f as Code, g as CardGroup, h as Card, i as Prose, l as Tag, m as Pre, o as HeroPattern, p as CodeGroup, s as Logo, u as Feedback, v as Button, w as ThemeToggle, x as remToPx, y as SectionProvider } from "./shell-BlMMdTpZ.js";
3
+ import { n as PageFooter, r as BuiltWithClarify, t as AppShell } from "./AppShell-D3FsVHQK.js";
4
+ import { t as markdownRemarkPlugins } from "./remark-o5sg9Ilv.js";
5
+ import { t as render } from "./render-BpavVnAe.js";
6
+ import { useLocation } from "react-router-dom";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ //#region source/openapi/lib/spec-path.ts
9
+ var VIRTUAL_PREFIX = "virtual:clarify-page/";
10
+ function resolveRelativePath(fromDir, to) {
11
+ const parts = (fromDir + "/" + to).split("/").filter(Boolean);
12
+ const stack = [];
13
+ for (const part of parts) if (part === "..") stack.pop();
14
+ else if (part !== ".") stack.push(part);
15
+ return stack.join("/");
127
16
  }
128
- function Properties(arg0) {
129
- const { children } = arg0;
130
- return /* @__PURE__ */ jsx("div", {
131
- className: "clarify-properties my-6",
132
- children: /* @__PURE__ */ jsx("ul", {
133
- role: "list",
134
- className: "m-0 list-none divide-y divide-zinc-900/5 p-0 dark:divide-white/5",
135
- children
136
- })
137
- });
17
+ function normalizeSpecPath(specPath, currentRoutePath, routePrefix = "") {
18
+ if (specPath.startsWith(VIRTUAL_PREFIX)) return specPath;
19
+ const normalizedRoutePrefix = routePrefix.replace(/^\/+|\/+$/g, "");
20
+ const normalizedSpecPath = specPath.startsWith("/") && normalizedRoutePrefix && specPath.slice(1).startsWith(`${normalizedRoutePrefix}/`) ? "/" + specPath.slice(normalizedRoutePrefix.length + 2) : specPath;
21
+ if (normalizedSpecPath.startsWith("/")) return VIRTUAL_PREFIX + normalizedSpecPath.replace(/^\//, "");
22
+ const fromDir = currentRoutePath === "/" ? "" : currentRoutePath?.replace(/^\//, "").replace(/\/[^/]*$/, "") ?? "";
23
+ return VIRTUAL_PREFIX + resolveRelativePath(normalizedRoutePrefix && fromDir.startsWith(`${normalizedRoutePrefix}/`) ? fromDir.slice(normalizedRoutePrefix.length + 1) : fromDir, normalizedSpecPath);
138
24
  }
139
- function Property(arg0) {
140
- const { name, children, type } = arg0;
141
- return /* @__PURE__ */ jsx("li", {
142
- className: "clarify-property m-0 px-0 py-4 first:pt-0 last:pb-0",
143
- children: /* @__PURE__ */ jsxs("dl", {
144
- className: "m-0 flex flex-wrap items-center gap-x-3 gap-y-2",
145
- children: [
146
- /* @__PURE__ */ jsx("dt", {
147
- className: "sr-only",
148
- children: "Name"
149
- }),
150
- /* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx("code", { children: name }) }),
151
- type ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("dt", {
152
- className: "sr-only",
153
- children: "Type"
154
- }), /* @__PURE__ */ jsx("dd", {
155
- className: "font-mono text-xs text-zinc-400 dark:text-zinc-500",
156
- children: type
157
- })] }) : null,
158
- /* @__PURE__ */ jsx("dt", {
159
- className: "sr-only",
160
- children: "Description"
161
- }),
162
- /* @__PURE__ */ jsx("dd", {
163
- className: "w-full flex-none *:first:mt-0 *:last:mb-0",
164
- children
165
- })
166
- ]
167
- })
168
- });
25
+ function useOpenApiSpec(spec, specPath) {
26
+ const specs = useOpenApis();
27
+ const location = useLocation();
28
+ const config = useClarifyConfig();
29
+ if (spec) return spec;
30
+ if (!specPath) return null;
31
+ return specs[normalizeSpecPath(specPath, location.pathname, config.routePrefix)] ?? null;
169
32
  }
170
33
  //#endregion
171
- //#region source/openapi/utils.ts
34
+ //#region source/openapi/lib/utils.ts
172
35
  var OPENAPI_HTTP_METHODS = [
173
36
  "get",
174
37
  "put",
@@ -182,14 +45,27 @@ var OPENAPI_HTTP_METHODS = [
182
45
  function isOpenAPIHttpMethod(method) {
183
46
  return OPENAPI_HTTP_METHODS.includes(method.toLowerCase());
184
47
  }
48
+ function isRecord(value) {
49
+ return typeof value === "object" && value !== null && !Array.isArray(value);
50
+ }
51
+ function resolveOpenApiRef(spec, ref) {
52
+ if (!ref.startsWith("#/")) return void 0;
53
+ return ref.slice(2).split("/").map((part) => part.replace(/~1/g, "/").replace(/~0/g, "~")).reduce((current, part) => isRecord(current) ? current[part] : void 0, spec);
54
+ }
55
+ function getPathItem(spec, path) {
56
+ const pathItem = spec.paths?.[path];
57
+ const resolved = isRecord(pathItem) && typeof pathItem.$ref === "string" ? resolveOpenApiRef(spec, pathItem.$ref) : pathItem;
58
+ return isRecord(resolved) ? resolved : void 0;
59
+ }
185
60
  function getOpenApiOperation(spec, path, method) {
186
61
  if (!isOpenAPIHttpMethod(method)) return void 0;
187
- return spec.paths?.[path]?.[method.toLowerCase()];
62
+ return getPathItem(spec, path)?.[method.toLowerCase()];
188
63
  }
189
64
  function listOpenApiOperations(spec) {
190
65
  const paths = spec.paths ?? {};
191
66
  const operations = [];
192
- for (const [path, pathItem] of Object.entries(paths)) {
67
+ for (const path of Object.keys(paths)) {
68
+ const pathItem = getPathItem(spec, path);
193
69
  if (!pathItem) continue;
194
70
  for (const method of OPENAPI_HTTP_METHODS) {
195
71
  const operation = pathItem[method];
@@ -203,559 +79,38 @@ function listOpenApiOperations(spec) {
203
79
  return operations;
204
80
  }
205
81
  //#endregion
206
- //#region source/openapi/index.tsx
207
- var VIRTUAL_PREFIX = "virtual:clarify-page/";
208
- function isRecord(value) {
209
- return typeof value === "object" && value !== null && !Array.isArray(value);
210
- }
211
- function isReference(value) {
212
- return isRecord(value) && typeof value.$ref === "string";
213
- }
214
- function resolveReferenceName(ref) {
215
- return ref.split("/").filter(Boolean).at(-1) ?? ref;
216
- }
217
- function getPathItem(spec, path) {
218
- const pathItem = spec.paths?.[path];
219
- return isRecord(pathItem) ? pathItem : void 0;
220
- }
221
- function getOperationParameters(spec, path, operation) {
222
- const pathParameters = getPathItem(spec, path)?.parameters;
223
- const operationParameters = operation.parameters;
224
- return [...Array.isArray(pathParameters) ? pathParameters : [], ...Array.isArray(operationParameters) ? operationParameters : []].filter((parameter) => isRecord(parameter) && !isReference(parameter));
225
- }
226
- function getRequestBody(operation) {
227
- const requestBody = operation.requestBody;
228
- return isRecord(requestBody) && !isReference(requestBody) ? requestBody : void 0;
229
- }
230
- function getMediaTypeEntries(content) {
231
- if (!isRecord(content)) return [];
232
- return Object.entries(content).filter(([, value]) => isRecord(value) && !isReference(value)).map(([mediaType, value]) => ({
233
- mediaType,
234
- value
235
- })).sort((a, z) => {
236
- return (a.mediaType.includes("json") ? 0 : 1) - (z.mediaType.includes("json") ? 0 : 1);
237
- });
238
- }
239
- function getJsonLikeContent(content) {
240
- return getMediaTypeEntries(content)[0];
241
- }
242
- function getExampleValue(example) {
243
- if (isRecord(example) && "value" in example) return example.value;
244
- if (isRecord(example) && "externalValue" in example) return void 0;
245
- return example;
246
- }
247
- function getExampleTitle(key, example) {
248
- if (isRecord(example)) {
249
- const summary = typeof example.summary === "string" ? example.summary : void 0;
250
- return {
251
- title: summary ?? key,
252
- summary
253
- };
254
- }
255
- return { title: key };
256
- }
257
- function getExampleEntries(mediaType) {
258
- if (!mediaType) return [];
259
- if (isRecord(mediaType.examples)) {
260
- const examples = [];
261
- for (const [key, example] of Object.entries(mediaType.examples)) {
262
- const value = getExampleValue(example);
263
- if (typeof value === "undefined") continue;
264
- const { title, summary } = getExampleTitle(key, example);
265
- examples.push({
266
- key,
267
- title,
268
- summary,
269
- value
270
- });
271
- }
272
- if (examples.length > 0) return examples;
273
- }
274
- if (typeof mediaType.example !== "undefined") return [{
275
- key: "default",
276
- title: "Example",
277
- value: mediaType.example
278
- }];
279
- const generated = schemaToExample(mediaType.schema);
280
- return typeof generated === "undefined" ? [] : [{
281
- key: "schema",
282
- title: "Schema example",
283
- value: generated,
284
- generated: true
285
- }];
286
- }
287
- function getContentExample(mediaType) {
288
- return getExampleEntries(mediaType)[0]?.value;
289
- }
290
- function schemaToType(schema) {
291
- if (!isRecord(schema)) return void 0;
292
- if (isReference(schema)) return resolveReferenceName(schema.$ref);
293
- if (Array.isArray(schema.enum)) return schema.enum.map(String).join(" | ");
294
- const oneOf = schema.oneOf ?? schema.anyOf;
295
- if (Array.isArray(oneOf)) return oneOf.map(schemaToType).filter(Boolean).join(" | ");
296
- if (schema.type === "array") return `${schemaToType(schema.items) ?? "unknown"}[]`;
297
- return typeof schema.type === "string" ? schema.type : void 0;
298
- }
299
- function schemaToExample(schema, depth = 0) {
300
- if (!isRecord(schema) || depth > 3) return void 0;
301
- if (typeof schema.example !== "undefined") return schema.example;
302
- if (typeof schema.default !== "undefined") return schema.default;
303
- if (Array.isArray(schema.enum)) return schema.enum[0];
304
- if (isReference(schema)) return { id: resolveReferenceName(schema.$ref) };
305
- if (schema.type === "array") return [schemaToExample(schema.items, depth + 1) ?? "string"];
306
- if (schema.type === "object" || isRecord(schema.properties)) {
307
- const properties = isRecord(schema.properties) ? schema.properties : {};
308
- return Object.fromEntries(Object.entries(properties).slice(0, 8).map(([name, propertySchema]) => [name, schemaToExample(propertySchema, depth + 1) ?? exampleForType(schemaToType(propertySchema))]));
309
- }
310
- return exampleForType(schemaToType(schema));
311
- }
312
- function exampleForType(type) {
313
- if (!type) return "string";
314
- if (type.endsWith("[]")) return [];
315
- if (type.includes("integer") || type.includes("number")) return 42;
316
- if (type.includes("boolean")) return true;
317
- if (type.includes("object")) return {};
318
- return "string";
319
- }
320
- function stringifyExample(value) {
321
- if (typeof value === "undefined") return "";
322
- if (typeof value === "string") return value;
323
- return JSON.stringify(value, null, 2);
324
- }
325
- function shellQuote(value) {
326
- return `'${value.replace(/'/g, `'"'"'`)}'`;
327
- }
328
- function getServerUrl(spec) {
329
- const servers = spec.servers;
330
- if (!Array.isArray(servers)) return "";
331
- const firstServer = servers.find(isRecord);
332
- return typeof firstServer?.url === "string" ? firstServer.url : "";
333
- }
334
- function buildOperationUrl(spec, path, parameters) {
335
- const query = parameters.filter((parameter) => parameter.in === "query" && parameter.name).map((parameter) => `${parameter.name}={${parameter.name}}`).join("&");
336
- return `${getServerUrl(spec).replace(/\/$/, "")}${path}${query ? `?${query}` : ""}`;
337
- }
338
- function buildCurlExample(arg0) {
339
- const { spec, path, method, parameters, requestContent } = arg0;
340
- const url = buildOperationUrl(spec, path, parameters);
341
- const lines = [`curl ${method === "GET" ? "-G " : ""}${shellQuote(url)}`];
342
- if (method !== "GET") lines.push(` -X ${method}`);
343
- lines.push(" -H 'Authorization: Bearer {token}'");
344
- lines.push(" -H 'Accept: application/json'");
345
- const requestExample = getContentExample(requestContent?.value);
346
- if (requestContent && typeof requestExample !== "undefined") {
347
- lines.push(` -H 'Content-Type: ${requestContent.mediaType}'`);
348
- lines.push(` -d ${shellQuote(stringifyExample(requestExample))}`);
349
- }
350
- return lines.join(" \\\n");
351
- }
352
- function getResponseEntries(operation) {
353
- const responses = operation.responses;
354
- if (!isRecord(responses)) return [];
355
- return Object.entries(responses).filter(([, response]) => isRecord(response) && !isReference(response)).map(([status, response]) => ({
356
- status,
357
- response
358
- }));
359
- }
360
- function SchemaProperties(arg0) {
361
- const { title, schema } = arg0;
362
- const targetSchema = isReference(schema) ? void 0 : schema;
363
- const properties = isRecord(targetSchema) && isRecord(targetSchema.properties) ? targetSchema.properties : void 0;
364
- const required = isRecord(targetSchema) && Array.isArray(targetSchema.required) ? targetSchema.required.map(String) : [];
365
- if (!properties || Object.keys(properties).length === 0) return null;
366
- return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", { children: title }), /* @__PURE__ */ jsx(Properties, { children: Object.entries(properties).map(([name, propertySchema]) => {
367
- const property = isRecord(propertySchema) ? propertySchema : {};
368
- const type = schemaToType(propertySchema);
369
- const description = typeof property.description === "string" ? property.description : void 0;
370
- const isRequired = required.includes(name);
371
- return /* @__PURE__ */ jsx(Property, {
372
- name,
373
- type: isRequired && type ? `${type}, required` : type,
374
- children: description ?? (isRequired ? "Required." : "Optional.")
375
- }, name);
376
- }) })] });
377
- }
378
- function ParameterList(arg0) {
379
- const { title, parameters } = arg0;
380
- if (parameters.length === 0) return null;
381
- return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", { children: title }), /* @__PURE__ */ jsx(Properties, { children: parameters.map((parameter) => /* @__PURE__ */ jsx(Property, {
382
- name: parameter.name ?? "parameter",
383
- type: [schemaToType(parameter.schema), parameter.required ? "required" : void 0].filter(Boolean).join(", ") || void 0,
384
- children: parameter.description ?? `${parameter.in ?? "Operation"} parameter.`
385
- }, `${parameter.in}-${parameter.name}`)) })] });
386
- }
387
- function ResponseList(arg0) {
388
- const { operation } = arg0;
389
- const responses = getResponseEntries(operation);
390
- if (responses.length === 0) return null;
391
- return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", { children: "Responses" }), /* @__PURE__ */ jsx(Properties, { children: responses.map(({ status, response }) => {
392
- return /* @__PURE__ */ jsx(Property, {
393
- name: status,
394
- type: schemaToType(getJsonLikeContent(response.content)?.value.schema),
395
- children: response.description ?? "Response."
396
- }, status);
397
- }) })] });
398
- }
399
- function codeLanguageForMediaType(mediaType) {
400
- if (!mediaType) return "json";
401
- if (mediaType.includes("json")) return "json";
402
- if (mediaType.includes("yaml") || mediaType.includes("yml")) return "yaml";
403
- if (mediaType.startsWith("text/")) return "text";
404
- if (mediaType.includes("xml")) return "xml";
405
- return "text";
406
- }
407
- function SelectControl(arg0) {
408
- const { label, value, options, onChange } = arg0;
409
- if (options.length <= 1) return null;
410
- return /* @__PURE__ */ jsx(Listbox, {
411
- value,
412
- onChange,
413
- children: /* @__PURE__ */ jsxs("div", {
414
- className: "clarify-api-select relative flex flex-col gap-1 text-[0.625rem]/5 font-semibold tracking-widest text-zinc-400 uppercase",
415
- children: [/* @__PURE__ */ jsxs(ListboxButton, {
416
- className: "clarify-api-select-button flex min-w-32 items-center justify-between gap-2 rounded-lg border border-white/10 bg-zinc-900 px-2.5 py-1.5 font-mono text-xs font-medium tracking-normal text-zinc-100 outline-hidden transition hover:border-white/20 focus:border-emerald-400 focus:ring-2 focus:ring-emerald-400/20 data-open:border-emerald-400 data-open:ring-2 data-open:ring-emerald-400/20",
417
- children: [/* @__PURE__ */ jsxs("span", {
418
- className: "flex flex-col items-start gap-0.5 truncate",
419
- children: [/* @__PURE__ */ jsx("span", {
420
- className: "font-sans text-[0.625rem]/4 font-semibold tracking-widest text-zinc-500 uppercase",
421
- children: label
422
- }), /* @__PURE__ */ jsx("span", {
423
- className: "truncate",
424
- children: value
425
- })]
426
- }), /* @__PURE__ */ jsx(ChevronsUpDownIcon, {
427
- className: "h-3.5 w-3.5 shrink-0 text-zinc-500",
428
- "aria-hidden": "true"
429
- })]
430
- }), /* @__PURE__ */ jsx(ListboxOptions, {
431
- anchor: "bottom start",
432
- className: "clarify-api-select-options z-30 mt-1 max-h-64 w-(--button-width) min-w-40 overflow-auto rounded-xl border border-white/10 bg-zinc-900 p-1 text-xs shadow-lg shadow-black/20 [--anchor-gap:--spacing(1)] focus:outline-none",
433
- children: options.map((option) => /* @__PURE__ */ jsxs(ListboxOption, {
434
- value: option,
435
- className: "clarify-api-select-option group flex cursor-default items-center justify-between gap-3 rounded-lg px-2.5 py-2 font-mono text-xs text-zinc-300 select-none data-focus:bg-white/10 data-focus:text-white data-selected:text-emerald-300",
436
- children: [/* @__PURE__ */ jsx("span", {
437
- className: "truncate",
438
- children: option
439
- }), /* @__PURE__ */ jsx(CheckIcon, {
440
- className: "h-3.5 w-3.5 shrink-0 opacity-0 group-data-selected:opacity-100",
441
- "aria-hidden": "true"
442
- })]
443
- }, option))
444
- })]
445
- })
446
- });
447
- }
448
- function ExamplePicker(arg0) {
449
- const { examples, selectedKey, onSelect } = arg0;
450
- const scrollerRef = useRef(null);
451
- if (examples.length <= 1) return null;
452
- function scrollBy(direction) {
453
- const el = scrollerRef.current;
454
- if (!el) return;
455
- el.scrollBy({
456
- left: direction * Math.max(120, el.clientWidth * .6),
457
- behavior: "smooth"
458
- });
459
- }
460
- return /* @__PURE__ */ jsxs("div", {
461
- className: "relative -mr-1 flex min-w-0 flex-1 items-center gap-1",
462
- children: [
463
- /* @__PURE__ */ jsx("button", {
464
- type: "button",
465
- "aria-label": "Scroll examples left",
466
- onClick: () => scrollBy(-1),
467
- className: "flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-zinc-500 transition hover:bg-white/5 hover:text-zinc-200",
468
- children: /* @__PURE__ */ jsx("svg", {
469
- viewBox: "0 0 20 20",
470
- fill: "currentColor",
471
- className: "h-3 w-3",
472
- children: /* @__PURE__ */ jsx("path", {
473
- fillRule: "evenodd",
474
- d: "M12.79 5.23a.75.75 0 010 1.06L9.06 10l3.73 3.71a.75.75 0 11-1.06 1.06l-4.25-4.24a.75.75 0 010-1.06l4.25-4.24a.75.75 0 011.06 0z",
475
- clipRule: "evenodd"
476
- })
477
- })
478
- }),
479
- /* @__PURE__ */ jsx("div", {
480
- ref: scrollerRef,
481
- className: "flex min-w-0 flex-1 items-center gap-1.5 overflow-x-auto whitespace-nowrap scroll-smooth scrollbar-none [&::-webkit-scrollbar]:hidden",
482
- children: examples.map((example) => /* @__PURE__ */ jsx("button", {
483
- type: "button",
484
- onClick: () => onSelect(example.key),
485
- title: example.summary,
486
- className: ["shrink-0 rounded-md px-2 py-0.5 text-xs font-medium transition", example.key === selectedKey ? "bg-white/10 text-white" : "text-zinc-400 hover:bg-white/5 hover:text-zinc-200"].join(" "),
487
- children: example.title
488
- }, example.key))
489
- }),
490
- /* @__PURE__ */ jsx("button", {
491
- type: "button",
492
- "aria-label": "Scroll examples right",
493
- onClick: () => scrollBy(1),
494
- className: "flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-zinc-500 transition hover:bg-white/5 hover:text-zinc-200",
495
- children: /* @__PURE__ */ jsx("svg", {
496
- viewBox: "0 0 20 20",
497
- fill: "currentColor",
498
- className: "h-3 w-3",
499
- children: /* @__PURE__ */ jsx("path", {
500
- fillRule: "evenodd",
501
- d: "M7.21 14.77a.75.75 0 010-1.06L10.94 10 7.21 6.29a.75.75 0 111.06-1.06l4.25 4.24a.75.75 0 010 1.06l-4.25 4.24a.75.75 0 01-1.06 0z",
502
- clipRule: "evenodd"
503
- })
504
- })
505
- })
506
- ]
507
- });
508
- }
509
- function CopyCodeButton(arg0) {
510
- const { code } = arg0;
511
- const [copied, setCopied] = useState(false);
512
- return /* @__PURE__ */ jsx("button", {
513
- type: "button",
514
- onClick: () => {
515
- window.navigator.clipboard.writeText(code).then(() => {
516
- setCopied(true);
517
- window.setTimeout(() => setCopied(false), 1e3);
518
- });
519
- },
520
- className: "absolute top-3.5 right-4 rounded-full bg-white/5 px-3 py-1 text-2xs font-medium text-zinc-400 opacity-0 transition hover:bg-white/10 hover:text-zinc-200 group-hover:opacity-100 focus:opacity-100",
521
- children: copied ? "Copied!" : "Copy"
522
- });
523
- }
524
- function ApiExampleCodeGroup(arg0) {
525
- const { title, tag, label, code, language, examples, selectedExampleKey, onSelectExample } = arg0;
526
- return /* @__PURE__ */ jsx("div", {
527
- className: "clarify-api-example my-6 overflow-hidden rounded-2xl bg-zinc-900 shadow-md dark:ring-1 dark:ring-white/10",
528
- children: /* @__PURE__ */ jsxs("div", {
529
- className: "not-prose",
530
- children: [
531
- /* @__PURE__ */ jsxs("div", {
532
- className: "clarify-api-example-header flex min-h-[calc(--spacing(12)+1px)] flex-wrap items-center gap-x-4 border-b border-zinc-700 bg-zinc-800 px-4 dark:border-zinc-800 dark:bg-transparent",
533
- children: [/* @__PURE__ */ jsx("h3", {
534
- className: "shrink-0 py-3 text-xs font-semibold text-white",
535
- children: title
536
- }), examples && examples.length > 1 && selectedExampleKey && onSelectExample ? /* @__PURE__ */ jsx(ExamplePicker, {
537
- examples,
538
- selectedKey: selectedExampleKey,
539
- onSelect: onSelectExample
540
- }) : null]
541
- }),
542
- tag || label ? /* @__PURE__ */ jsxs("div", {
543
- className: "flex h-9 items-center gap-2 border-y border-t-transparent border-b-white/7.5 bg-zinc-900 px-4 dark:border-b-white/5 dark:bg-white/1",
544
- children: [
545
- tag ? /* @__PURE__ */ jsx("span", {
546
- className: "font-mono text-[0.625rem]/6 font-semibold text-emerald-400",
547
- children: tag
548
- }) : null,
549
- tag && label ? /* @__PURE__ */ jsx("span", { className: "h-0.5 w-0.5 rounded-full bg-zinc-500" }) : null,
550
- label ? /* @__PURE__ */ jsx("span", {
551
- className: "font-mono text-xs text-zinc-400",
552
- children: label
553
- }) : null
554
- ]
555
- }) : null,
556
- /* @__PURE__ */ jsxs("div", {
557
- className: "clarify-api-example-code group relative",
558
- children: [/* @__PURE__ */ jsx("pre", {
559
- className: "overflow-x-auto p-4 text-xs text-white",
560
- children: /* @__PURE__ */ jsx("code", {
561
- className: `language-${language}`,
562
- children: code
563
- })
564
- }), /* @__PURE__ */ jsx(CopyCodeButton, { code })]
565
- })
566
- ]
567
- })
568
- });
569
- }
570
- function RequestExamplesPanel(arg0) {
571
- const { spec, path, method, parameters, requestContents } = arg0;
572
- const [selectedMediaType, setSelectedMediaType] = useState(requestContents[0]?.mediaType ?? "");
573
- const selectedContent = requestContents.find((content) => content.mediaType === selectedMediaType) ?? requestContents[0];
574
- const examples = getExampleEntries(selectedContent?.value);
575
- const [selectedExampleKey, setSelectedExampleKey] = useState(examples[0]?.key ?? "");
576
- const selectedExample = examples.find((example) => example.key === selectedExampleKey) ?? examples[0];
577
- const curl = buildCurlExample({
578
- spec,
579
- path,
580
- method,
581
- parameters,
582
- requestContent: selectedContent ? {
583
- ...selectedContent,
584
- value: {
585
- ...selectedContent.value,
586
- example: selectedExample?.value,
587
- examples: void 0
588
- }
589
- } : void 0
590
- });
591
- return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
592
- className: "mb-3 flex flex-wrap gap-3",
593
- children: /* @__PURE__ */ jsx(SelectControl, {
594
- label: "Media type",
595
- value: selectedContent?.mediaType ?? "",
596
- options: requestContents.map((content) => content.mediaType),
597
- onChange: (value) => {
598
- setSelectedMediaType(value);
599
- setSelectedExampleKey(getExampleEntries(requestContents.find((content) => content.mediaType === value)?.value)[0]?.key ?? "");
600
- }
601
- })
602
- }), /* @__PURE__ */ jsx(ApiExampleCodeGroup, {
603
- title: "Request",
604
- tag: method,
605
- label: path,
606
- code: curl,
607
- language: "bash",
608
- examples,
609
- selectedExampleKey: selectedExample?.key,
610
- onSelectExample: setSelectedExampleKey
611
- })] });
612
- }
613
- function ResponseExamplesPanel(arg0) {
614
- const { operation } = arg0;
615
- const responses = getResponseEntries(operation).filter(({ response }) => getMediaTypeEntries(response.content).length > 0);
616
- const [selectedStatus, setSelectedStatus] = useState(responses.find(({ status }) => status.startsWith("2"))?.status ?? responses[0]?.status ?? "");
617
- const selectedResponse = responses.find(({ status }) => status === selectedStatus) ?? responses[0];
618
- const responseContents = getMediaTypeEntries(selectedResponse?.response.content);
619
- const [selectedMediaType, setSelectedMediaType] = useState(responseContents[0]?.mediaType ?? "");
620
- const selectedContent = responseContents.find((content) => content.mediaType === selectedMediaType) ?? responseContents[0];
621
- const examples = getExampleEntries(selectedContent?.value);
622
- const [selectedExampleKey, setSelectedExampleKey] = useState(examples[0]?.key ?? "");
623
- const selectedExample = examples.find((example) => example.key === selectedExampleKey) ?? examples[0];
624
- const responseCode = stringifyExample(selectedExample?.value);
625
- if (!selectedResponse || !selectedContent || !responseCode) return null;
626
- return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
627
- className: "mb-3 flex flex-wrap gap-3",
628
- children: [/* @__PURE__ */ jsx(SelectControl, {
629
- label: "Status",
630
- value: selectedResponse.status,
631
- options: responses.map(({ status }) => status),
632
- onChange: (value) => {
633
- const nextContents = getMediaTypeEntries(responses.find(({ status }) => status === value)?.response.content);
634
- setSelectedStatus(value);
635
- setSelectedMediaType(nextContents[0]?.mediaType ?? "");
636
- setSelectedExampleKey(getExampleEntries(nextContents[0]?.value)[0]?.key ?? "");
637
- }
638
- }), /* @__PURE__ */ jsx(SelectControl, {
639
- label: "Media type",
640
- value: selectedContent.mediaType,
641
- options: responseContents.map((content) => content.mediaType),
642
- onChange: (value) => {
643
- setSelectedMediaType(value);
644
- setSelectedExampleKey(getExampleEntries(responseContents.find((content) => content.mediaType === value)?.value)[0]?.key ?? "");
645
- }
646
- })]
647
- }), /* @__PURE__ */ jsx(ApiExampleCodeGroup, {
648
- title: "Response",
649
- tag: selectedResponse.status,
650
- label: selectedContent.mediaType,
651
- code: responseCode,
652
- language: codeLanguageForMediaType(selectedContent.mediaType),
653
- examples,
654
- selectedExampleKey: selectedExample?.key,
655
- onSelectExample: setSelectedExampleKey
656
- })] });
657
- }
658
- function EndpointExamples(arg0) {
659
- const { spec, path, method, operation, parameters, requestContents } = arg0;
660
- return /* @__PURE__ */ jsxs("div", {
661
- className: "space-y-6",
662
- children: [/* @__PURE__ */ jsx(RequestExamplesPanel, {
663
- spec,
664
- path,
665
- method,
666
- parameters,
667
- requestContents
668
- }), /* @__PURE__ */ jsx(ResponseExamplesPanel, { operation })]
669
- });
670
- }
82
+ //#region source/openapi/entry.tsx
671
83
  function OpenApiHeader(arg0) {
672
84
  const { spec } = arg0;
85
+ const t = useBuiltInText();
673
86
  return /* @__PURE__ */ jsxs("header", {
674
87
  className: "mb-16",
675
88
  children: [
676
89
  /* @__PURE__ */ jsx("p", {
677
- className: "mb-3 font-mono text-xs/6 font-medium tracking-widest text-emerald-500 uppercase dark:text-emerald-400",
678
- children: "OpenAPI Reference"
90
+ className: "mb-3 text-xs/6 font-medium tracking-widest text-emerald-500 uppercase dark:text-emerald-400",
91
+ children: t("openapi.openApiReference")
679
92
  }),
680
- /* @__PURE__ */ jsx("h1", { children: spec.info?.title ?? "API Documentation" }),
681
- spec.info?.description ? /* @__PURE__ */ jsx("p", {
682
- className: "lead",
93
+ /* @__PURE__ */ jsx("h1", { children: spec.info?.title ?? t("openapi.apiDocumentation") }),
94
+ spec.info?.description ? /* @__PURE__ */ jsx(Markdown, {
95
+ className: "lead *:first:mt-0 *:last:mb-0",
683
96
  children: spec.info.description
684
97
  }) : null,
685
- spec.info?.version ? /* @__PURE__ */ jsxs("p", {
98
+ spec.info?.version ? /* @__PURE__ */ jsx("p", {
686
99
  className: "text-sm text-zinc-500 dark:text-zinc-400",
687
- children: ["Version ", spec.info.version]
100
+ children: t("openapi.version", { version: spec.info.version })
688
101
  }) : null
689
102
  ]
690
103
  });
691
104
  }
692
- function OpenApiOperation(arg0) {
693
- const { spec, path, method, operation } = arg0;
694
- const id = slug(`${method.toLowerCase()} ${path}`);
695
- const summary = operation.summary ?? `${method} ${path}`;
696
- const description = operation.description;
697
- const parameters = getOperationParameters(spec, path, operation);
698
- const requestBody = getRequestBody(operation);
699
- const requestContents = getMediaTypeEntries(requestBody?.content);
700
- const requestSchema = requestContents[0]?.value.schema;
701
- const groupedParameters = {
702
- path: parameters.filter((parameter) => parameter.in === "path"),
703
- query: parameters.filter((parameter) => parameter.in === "query"),
704
- header: parameters.filter((parameter) => parameter.in === "header")
705
- };
706
- return /* @__PURE__ */ jsxs("section", {
707
- className: "clarify-api-endpoint scroll-mt-24",
708
- "aria-labelledby": id,
709
- children: [/* @__PURE__ */ jsx(Heading, {
710
- id,
711
- tag: method,
712
- label: path,
713
- children: summary
714
- }), /* @__PURE__ */ jsxs(Row, { children: [/* @__PURE__ */ jsxs(Col, { children: [
715
- description ? /* @__PURE__ */ jsx("p", { children: description }) : null,
716
- /* @__PURE__ */ jsx(ParameterList, {
717
- title: "Path parameters",
718
- parameters: groupedParameters.path
719
- }),
720
- /* @__PURE__ */ jsx(ParameterList, {
721
- title: "Query parameters",
722
- parameters: groupedParameters.query
723
- }),
724
- /* @__PURE__ */ jsx(ParameterList, {
725
- title: "Headers",
726
- parameters: groupedParameters.header
727
- }),
728
- requestBody && requestContents.length > 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
729
- /* @__PURE__ */ jsx("h3", { children: "Request body" }),
730
- typeof requestBody.description === "string" ? /* @__PURE__ */ jsx("p", { children: requestBody.description }) : null,
731
- /* @__PURE__ */ jsx(SchemaProperties, {
732
- title: "Body properties",
733
- schema: requestSchema
734
- })
735
- ] }) : null,
736
- /* @__PURE__ */ jsx(ResponseList, { operation })
737
- ] }), /* @__PURE__ */ jsx(Col, {
738
- sticky: true,
739
- children: /* @__PURE__ */ jsx(EndpointExamples, {
740
- spec,
741
- path,
742
- method,
743
- operation,
744
- parameters,
745
- requestContents
746
- })
747
- })] })]
748
- });
749
- }
750
105
  function OpenApiPaths(arg0) {
751
106
  const { spec } = arg0;
752
107
  return /* @__PURE__ */ jsx("div", {
753
- className: "clarify-api-endpoints space-y-16",
108
+ className: "clarify-api-endpoints divide-y divide-zinc-200/70 dark:divide-white/10",
754
109
  children: listOpenApiOperations(spec).map(({ path, method, operation }) => ({
755
110
  path,
756
111
  method: method.toUpperCase(),
757
112
  operation
758
- })).map(({ path, method, operation }) => /* @__PURE__ */ jsx(OpenApiOperation, {
113
+ })).map(({ path, method, operation }) => /* @__PURE__ */ jsx(OpenApiOperation$1, {
759
114
  spec,
760
115
  path,
761
116
  method,
@@ -763,72 +118,48 @@ function OpenApiPaths(arg0) {
763
118
  }, `${method}-${path}`))
764
119
  });
765
120
  }
766
- function resolveRelativePath(fromDir, to) {
767
- const parts = (fromDir + "/" + to).split("/").filter(Boolean);
768
- const stack = [];
769
- for (const part of parts) if (part === "..") stack.pop();
770
- else if (part !== ".") stack.push(part);
771
- return stack.join("/");
772
- }
773
- function normalizeSpecPath(specPath, currentRoutePath, routePrefix = "") {
774
- if (specPath.startsWith(VIRTUAL_PREFIX)) return specPath;
775
- const normalizedRoutePrefix = routePrefix.replace(/^\/+|\/+$/g, "");
776
- const normalizedSpecPath = specPath.startsWith("/") && normalizedRoutePrefix && specPath.slice(1).startsWith(`${normalizedRoutePrefix}/`) ? "/" + specPath.slice(normalizedRoutePrefix.length + 2) : specPath;
777
- if (normalizedSpecPath.startsWith("/")) return VIRTUAL_PREFIX + normalizedSpecPath.replace(/^\//, "");
778
- const fromDir = currentRoutePath === "/" ? "" : currentRoutePath?.replace(/^\//, "").replace(/\/[^/]*$/, "") ?? "";
779
- return VIRTUAL_PREFIX + resolveRelativePath(normalizedRoutePrefix && fromDir.startsWith(`${normalizedRoutePrefix}/`) ? fromDir.slice(normalizedRoutePrefix.length + 1) : fromDir, normalizedSpecPath);
780
- }
781
- function useOpenApiSpec(spec, specPath) {
782
- const specs = useOpenApis();
783
- const location = useLocation();
784
- const config = useClarifyConfig();
785
- if (spec) return spec;
786
- if (!specPath) return null;
787
- return specs[normalizeSpecPath(specPath, location.pathname, config.routePrefix)] ?? null;
788
- }
789
121
  function WarningBox(arg0) {
790
122
  const { children, tone = "amber" } = arg0;
791
123
  return /* @__PURE__ */ jsx("div", {
792
- className: clsx("clarify-warning", tone === "red" ? "rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-700 dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-200" : "rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-700 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-200"),
124
+ className: `clarify-warning ${tone === "red" ? "rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-700 dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-200" : "rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-700 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-200"}`,
793
125
  children
794
126
  });
795
127
  }
796
- function OpenApiPage(arg0) {
128
+ function OpenApiDocument(arg0) {
797
129
  const { spec, specPath } = arg0;
130
+ const t = useBuiltInText();
798
131
  const resolved = useOpenApiSpec(spec, specPath);
799
- if (!resolved) return /* @__PURE__ */ jsxs(WarningBox, { children: ["OpenAPI spec not found: ", specPath ?? "(未提供 spec 或 specPath)"] });
800
- return /* @__PURE__ */ jsxs("article", {
132
+ if (!resolved) return /* @__PURE__ */ jsx(WarningBox, { children: t("openapi.specNotFound", { specPath: specPath ?? t("openapi.specPathMissing") }) });
133
+ return /* @__PURE__ */ jsx("article", {
801
134
  className: "clarify-openapi-page flex h-full flex-col pt-16 pb-10",
802
- children: [/* @__PURE__ */ jsxs(Prose, {
135
+ children: /* @__PURE__ */ jsxs(Prose, {
803
136
  className: "flex-auto",
804
137
  children: [/* @__PURE__ */ jsx(OpenApiHeader, { spec: resolved }), /* @__PURE__ */ jsx(OpenApiPaths, { spec: resolved })]
805
- }), /* @__PURE__ */ jsx(PageFooter, {})]
138
+ })
806
139
  });
807
140
  }
808
- function ApiEndpoint(arg0) {
141
+ function OpenApiOperationWithSpec(arg0) {
809
142
  const { spec, path, method } = arg0;
143
+ const t = useBuiltInText();
810
144
  const op = getOpenApiOperation(spec, path, method);
811
- if (!op) return /* @__PURE__ */ jsxs(WarningBox, {
145
+ if (!op) return /* @__PURE__ */ jsx(WarningBox, {
812
146
  tone: "red",
813
- children: [
814
- "Endpoint not found: ",
815
- method.toUpperCase(),
816
- " ",
817
- path
818
- ]
147
+ children: t("openapi.endpointNotFound", { endpoint: `${method.toUpperCase()} ${path}` })
819
148
  });
820
- return /* @__PURE__ */ jsx(OpenApiOperation, {
149
+ const normalizedMethod = method.toUpperCase();
150
+ return /* @__PURE__ */ jsx(OpenApiOperation$1, {
821
151
  spec,
822
152
  path,
823
- method: method.toUpperCase(),
153
+ method: normalizedMethod,
824
154
  operation: op
825
- });
155
+ }, `${normalizedMethod}-${path}`);
826
156
  }
827
- function OpenApiEndpoint(arg0) {
157
+ function OpenApiOperation(arg0) {
828
158
  const { specPath, path, method } = arg0;
159
+ const t = useBuiltInText();
829
160
  const spec = useOpenApiSpec(void 0, specPath);
830
- if (!spec) return /* @__PURE__ */ jsxs(WarningBox, { children: ["OpenAPI spec not found: ", specPath] });
831
- return /* @__PURE__ */ jsx(ApiEndpoint, {
161
+ if (!spec) return /* @__PURE__ */ jsx(WarningBox, { children: t("openapi.specNotFound", { specPath }) });
162
+ return /* @__PURE__ */ jsx(OpenApiOperationWithSpec, {
832
163
  spec,
833
164
  path,
834
165
  method
@@ -836,18 +167,44 @@ function OpenApiEndpoint(arg0) {
836
167
  }
837
168
  //#endregion
838
169
  //#region source/mdx/components.ts
170
+ var builtInMDXComponents = {
171
+ ...primitives_exports,
172
+ Markdown,
173
+ Collapse
174
+ };
175
+ var builtInOpenAPIComponents = {
176
+ OpenApiDocument,
177
+ OpenApiOperation
178
+ };
839
179
  function useMDXComponents(components = {}) {
840
180
  return {
841
181
  ...components,
842
- ...primitives_exports,
843
- OpenApiPage,
844
- ApiEndpoint,
845
- OpenApiEndpoint,
846
- ApiEndpointCard,
847
- DocShell
182
+ ...builtInMDXComponents,
183
+ ...builtInOpenAPIComponents
848
184
  };
849
185
  }
850
186
  //#endregion
851
- export { ApiEndpoint, ApiEndpointCard, AppShell, BuiltWithClarify, Button, Callout, Card, CardGroup, ClarifyConfigContext, Code, CodeGroup, DocShell, Feedback, GridPattern, Heading, HeroPattern, Logo, OpenApiEndpoint, OpenApiPage, OpenApisContext, PageFooter, Pre, Prose, SectionProvider, Tag, ThemeProvider, ThemeToggle, remToPx, render, useClarifyConfig, useMDXComponents, useOpenApis, useSectionStore, useTheme };
187
+ //#region source/mdx/DocShell.tsx
188
+ function DocShell(arg0) {
189
+ const { title, subtitle, children } = arg0;
190
+ return /* @__PURE__ */ jsx("main", {
191
+ className: "clarify-doc-shell min-h-screen bg-white px-6 py-10 text-zinc-900 dark:bg-zinc-950 dark:text-white md:px-10",
192
+ children: /* @__PURE__ */ jsxs("div", {
193
+ className: "mx-auto max-w-6xl",
194
+ children: [/* @__PURE__ */ jsxs("header", {
195
+ className: "mb-10",
196
+ children: [/* @__PURE__ */ jsx("h1", {
197
+ className: "text-3xl font-bold tracking-tight md:text-5xl",
198
+ children: title
199
+ }), subtitle ? /* @__PURE__ */ jsx("p", {
200
+ className: "mt-3 max-w-2xl text-zinc-600 dark:text-zinc-400",
201
+ children: subtitle
202
+ }) : null]
203
+ }), /* @__PURE__ */ jsx(Prose, { children })]
204
+ })
205
+ });
206
+ }
207
+ //#endregion
208
+ export { AppShell, BuiltWithClarify, Button, Callout, Card, CardGroup, ClarifyConfigContext, Code, CodeGroup, Collapse, DocShell, Feedback, GridPattern, Heading, HeroPattern, Logo, Markdown, OpenApiDocument, OpenApiOperation, OpenApisContext, PageFooter, Pre, Prose, SectionProvider, Tag, ThemeProvider, ThemeToggle, markdownRemarkPlugins, remToPx, render, useClarifyConfig, useMDXComponents, useOpenApis, useSectionStore, useTheme };
852
209
 
853
210
  //# sourceMappingURL=index.js.map