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