@blaaiz/docs-core 0.1.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 (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +103 -0
  3. package/dist/chunk-3ZX4WIE3.js +2984 -0
  4. package/dist/chunk-3ZX4WIE3.js.map +1 -0
  5. package/dist/chunk-JCYR6RPE.js +31 -0
  6. package/dist/chunk-JCYR6RPE.js.map +1 -0
  7. package/dist/chunk-ZKOOKLZ3.js +124 -0
  8. package/dist/chunk-ZKOOKLZ3.js.map +1 -0
  9. package/dist/cli.js +534 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/generator.cjs +508 -0
  12. package/dist/generator.cjs.map +1 -0
  13. package/dist/generator.d.cts +122 -0
  14. package/dist/generator.d.ts +122 -0
  15. package/dist/generator.js +177 -0
  16. package/dist/generator.js.map +1 -0
  17. package/dist/index.cjs +3024 -0
  18. package/dist/index.cjs.map +1 -0
  19. package/dist/index.d.cts +1182 -0
  20. package/dist/index.d.ts +1182 -0
  21. package/dist/index.js +3 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/navigation-CGqFIPlP.d.cts +498 -0
  24. package/dist/navigation-CGqFIPlP.d.ts +498 -0
  25. package/dist/openapi-types-CJ6p5Cux.d.cts +78 -0
  26. package/dist/openapi-types-CJ6p5Cux.d.ts +78 -0
  27. package/dist/ui/api-try-it.cjs +654 -0
  28. package/dist/ui/api-try-it.cjs.map +1 -0
  29. package/dist/ui/api-try-it.d.cts +78 -0
  30. package/dist/ui/api-try-it.d.ts +78 -0
  31. package/dist/ui/api-try-it.js +509 -0
  32. package/dist/ui/api-try-it.js.map +1 -0
  33. package/dist/ui/ask-ai.cjs +810 -0
  34. package/dist/ui/ask-ai.cjs.map +1 -0
  35. package/dist/ui/ask-ai.d.cts +57 -0
  36. package/dist/ui/ask-ai.d.ts +57 -0
  37. package/dist/ui/ask-ai.js +808 -0
  38. package/dist/ui/ask-ai.js.map +1 -0
  39. package/dist/ui/copy-page.cjs +312 -0
  40. package/dist/ui/copy-page.cjs.map +1 -0
  41. package/dist/ui/copy-page.d.cts +33 -0
  42. package/dist/ui/copy-page.d.ts +33 -0
  43. package/dist/ui/copy-page.js +183 -0
  44. package/dist/ui/copy-page.js.map +1 -0
  45. package/dist/ui/mermaid.cjs +363 -0
  46. package/dist/ui/mermaid.cjs.map +1 -0
  47. package/dist/ui/mermaid.d.cts +13 -0
  48. package/dist/ui/mermaid.d.ts +13 -0
  49. package/dist/ui/mermaid.js +361 -0
  50. package/dist/ui/mermaid.js.map +1 -0
  51. package/dist/ui.cjs +661 -0
  52. package/dist/ui.cjs.map +1 -0
  53. package/dist/ui.d.cts +428 -0
  54. package/dist/ui.d.ts +428 -0
  55. package/dist/ui.js +537 -0
  56. package/dist/ui.js.map +1 -0
  57. package/package.json +145 -0
  58. package/patches/fumadocs-openapi.patch +173 -0
  59. package/skills/AGENTS-section.md +36 -0
  60. package/skills/SKILL.md +363 -0
  61. package/styles/api-reference.css +1417 -0
  62. package/styles/ask-ai.css +563 -0
  63. package/styles/auth.css +462 -0
  64. package/styles/docs.css +247 -0
  65. package/styles/home.css +376 -0
  66. package/templates/init/content/docs/index.mdx.tmpl +52 -0
  67. package/templates/init/content/docs/meta.json.tmpl +3 -0
  68. package/templates/init/content/docs.json.tmpl +12 -0
  69. package/templates/init/content/nav.json.tmpl +7 -0
  70. package/templates/init/docs.config.ts.tmpl +36 -0
  71. package/templates/init/env.example.tmpl +15 -0
@@ -0,0 +1,654 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ var react = require('react');
5
+ var reactDom = require('react-dom');
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+
8
+ // src/ui/clipboard.ts
9
+ function legacyCopy(text) {
10
+ try {
11
+ const area = document.createElement("textarea");
12
+ area.value = text;
13
+ area.style.position = "fixed";
14
+ area.style.opacity = "0";
15
+ document.body.appendChild(area);
16
+ area.select();
17
+ const ok = document.execCommand("copy");
18
+ document.body.removeChild(area);
19
+ return ok;
20
+ } catch {
21
+ return false;
22
+ }
23
+ }
24
+ async function copyToClipboard(text) {
25
+ const clip = navigator.clipboard;
26
+ if (typeof clip?.writeText === "function") {
27
+ try {
28
+ await clip.writeText(text);
29
+ return true;
30
+ } catch {
31
+ }
32
+ }
33
+ return legacyCopy(text);
34
+ }
35
+ var GLYPHS = {
36
+ house: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
37
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" }),
38
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M9 22V12h6v10" })
39
+ ] }),
40
+ book: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1 0-5H20" }),
41
+ code: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
42
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m16 18 6-6-6-6" }),
43
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m8 6-6 6 6 6" })
44
+ ] }),
45
+ rocket: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
46
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91 0z" }),
47
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z" }),
48
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0" }),
49
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5" })
50
+ ] }),
51
+ terminal: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
52
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m4 17 6-6-6-6" }),
53
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 19h8" })
54
+ ] }),
55
+ wallet: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
56
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1" }),
57
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4" })
58
+ ] }),
59
+ key: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
60
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4" }),
61
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m21 2-9.6 9.6" }),
62
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "7.5", cy: "15.5", r: "5.5" })
63
+ ] }),
64
+ webhook: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
65
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2" }),
66
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06" }),
67
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8" })
68
+ ] }),
69
+ globe: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
70
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "10" }),
71
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20" }),
72
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M2 12h20" })
73
+ ] }),
74
+ mail: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
75
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "2", y: "4", width: "20", height: "16", rx: "2" }),
76
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7" })
77
+ ] }),
78
+ user: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
79
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "8", r: "4" }),
80
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 21a8 8 0 0 1 16 0" })
81
+ ] }),
82
+ lock: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
83
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "3", y: "11", width: "18", height: "11", rx: "2" }),
84
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M7 11V7a5 5 0 0 1 10 0v4" })
85
+ ] }),
86
+ /** A circled `i` — an informational note, and the generic error state. */
87
+ info: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
88
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "10" }),
89
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 8v4M12 16h.01", strokeLinecap: "round" })
90
+ ] }),
91
+ /** A warning triangle — a caution, and the `500` screen. */
92
+ alert: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
93
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z" }),
94
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 9v4M12 17h.01", strokeLinecap: "round" })
95
+ ] }),
96
+ /** A light bulb — a tip. */
97
+ bulb: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M9 18h6M10 22h4M12 2a7 7 0 0 0-4 12.7c.6.5 1 1.3 1 2.1V17h6v-.2c0-.8.4-1.6 1-2.1A7 7 0 0 0 12 2Z" }),
98
+ /** A circle with a cross — the `404` screen. */
99
+ crossCircle: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
100
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "10" }),
101
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m14.31 8-1.31 2.4M9.69 8l4.62 8M14.31 16 9.69 8", strokeLinecap: "round" })
102
+ ] }),
103
+ /** Struck-through signal bars — the offline screen. */
104
+ offline: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
105
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5 12.55a11 11 0 0 1 14 0M8.5 16.11a6 6 0 0 1 7 0M12 20h.01", strokeLinecap: "round" }),
106
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m2 2 20 20", strokeLinecap: "round" })
107
+ ] }),
108
+ copy: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M9 9h9a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H9a2 2 0 0 1-2-2v-9a2 2 0 0 1 2-2ZM5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" }),
109
+ check: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 6 9 17l-5-5" }),
110
+ chevronDown: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m6 9 6 6 6-6" }),
111
+ /** Stacked chevrons — a value this control switches between. */
112
+ chevronUpDown: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m7 15 5 5 5-5M7 9l5-5 5 5" }),
113
+ /** An open arc — one turn of a loading spinner. */
114
+ spinner: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M21 12a9 9 0 1 1-6.219-8.56", strokeLinecap: "round" }),
115
+ markdown: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
116
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "2", y: "5", width: "20", height: "14", rx: "2" }),
117
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6 15V9l3 3 3-3v6M17 9v4m0 0 2-2m-2 2-2-2" })
118
+ ] })
119
+ };
120
+ function strokeIcon(name, options = {}) {
121
+ return /* @__PURE__ */ jsxRuntime.jsx(
122
+ "svg",
123
+ {
124
+ ...options.className === void 0 ? {} : { className: options.className },
125
+ ...options.size === void 0 ? {} : { width: options.size, height: options.size },
126
+ viewBox: "0 0 24 24",
127
+ fill: "none",
128
+ stroke: "currentColor",
129
+ strokeWidth: options.strokeWidth ?? 2,
130
+ ...options.rounded ? { strokeLinecap: "round", strokeLinejoin: "round" } : {},
131
+ "aria-hidden": "true",
132
+ children: GLYPHS[name]
133
+ },
134
+ options.key
135
+ );
136
+ }
137
+ function filledIcon(path, options = {}) {
138
+ return /* @__PURE__ */ jsxRuntime.jsx(
139
+ "svg",
140
+ {
141
+ ...options.className === void 0 ? {} : { className: options.className },
142
+ ...options.size === void 0 ? {} : { width: options.size, height: options.size },
143
+ viewBox: "0 0 24 24",
144
+ fill: "currentColor",
145
+ "aria-hidden": "true",
146
+ children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: path })
147
+ },
148
+ options.key
149
+ );
150
+ }
151
+ var PLAY_PATH = "M8 5v14l11-7z";
152
+ function chevronUpDownIcon() {
153
+ return strokeIcon("chevronUpDown", { rounded: true });
154
+ }
155
+ function playIcon() {
156
+ return filledIcon(PLAY_PATH);
157
+ }
158
+ function spinnerIcon() {
159
+ return strokeIcon("spinner", { strokeWidth: 2.5, className: "api-tryit-spin" });
160
+ }
161
+ function copyIcon() {
162
+ return strokeIcon("copy");
163
+ }
164
+ function checkIcon() {
165
+ return strokeIcon("check", { strokeWidth: 2.5, rounded: true });
166
+ }
167
+ var ENUM_CARD = 'div[class*="prose-no-margin"] > div[class*="mt-2"][class*="flex-row"] > div[class*="flex-col"][class*="bg-fd-secondary"]';
168
+ var enumMenuUsers = 0;
169
+ var detachEnumMenus = null;
170
+ function installEnumMenus() {
171
+ const closeAll = (except) => {
172
+ document.querySelectorAll(`${ENUM_CARD}[data-open]`).forEach((card) => {
173
+ if (card !== except) {
174
+ card.removeAttribute("data-open");
175
+ }
176
+ });
177
+ };
178
+ const onClick = (event) => {
179
+ const target = event.target;
180
+ const card = target?.closest(ENUM_CARD) ?? null;
181
+ if (card && target?.closest("ul") && card.hasAttribute("data-open")) {
182
+ return;
183
+ }
184
+ closeAll(card);
185
+ card?.toggleAttribute("data-open");
186
+ };
187
+ const onKey = (event) => {
188
+ if (event.key === "Escape") {
189
+ closeAll();
190
+ }
191
+ };
192
+ document.addEventListener("click", onClick);
193
+ document.addEventListener("keydown", onKey);
194
+ detachEnumMenus = () => {
195
+ document.removeEventListener("click", onClick);
196
+ document.removeEventListener("keydown", onKey);
197
+ closeAll();
198
+ };
199
+ }
200
+ function useEnumMenus() {
201
+ react.useEffect(() => {
202
+ enumMenuUsers += 1;
203
+ if (enumMenuUsers === 1) {
204
+ installEnumMenus();
205
+ }
206
+ return () => {
207
+ enumMenuUsers -= 1;
208
+ if (enumMenuUsers === 0) {
209
+ detachEnumMenus?.();
210
+ detachEnumMenus = null;
211
+ }
212
+ };
213
+ }, []);
214
+ }
215
+ function pathSegments(path) {
216
+ const parts = path.split("/").filter(Boolean);
217
+ return parts.map((part, index) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "api-tryit-seg", children: [
218
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "api-tryit-slash", children: "/" }),
219
+ part
220
+ ] }, `${String(index)}-${part}`));
221
+ }
222
+ function RequestBar({
223
+ method,
224
+ path,
225
+ serverUrl,
226
+ servers,
227
+ onSelectServer,
228
+ formRef
229
+ }) {
230
+ const [baseUrl, setBaseUrl] = react.useState((serverUrl ?? "").replace(/\/$/, ""));
231
+ const [copied, setCopied] = react.useState(false);
232
+ const [loading, setLoading] = react.useState(false);
233
+ const [menuOpen, setMenuOpen] = react.useState(false);
234
+ const [menuAt, setMenuAt] = react.useState(null);
235
+ const envRef = react.useRef(null);
236
+ const menuRef = react.useRef(null);
237
+ const inline = onSelectServer && servers && servers.length > 1 ? { list: servers, select: onSelectServer } : null;
238
+ react.useEffect(() => {
239
+ if (!menuOpen) {
240
+ return;
241
+ }
242
+ const onDown = (event) => {
243
+ const target = event.target;
244
+ if (!envRef.current?.contains(target) && !menuRef.current?.contains(target)) {
245
+ setMenuOpen(false);
246
+ }
247
+ };
248
+ const onKey = (event) => {
249
+ if (event.key === "Escape") {
250
+ event.stopPropagation();
251
+ setMenuOpen(false);
252
+ }
253
+ };
254
+ document.addEventListener("mousedown", onDown);
255
+ document.addEventListener("keydown", onKey, true);
256
+ return () => {
257
+ document.removeEventListener("mousedown", onDown);
258
+ document.removeEventListener("keydown", onKey, true);
259
+ };
260
+ }, [menuOpen]);
261
+ react.useEffect(() => {
262
+ const root = formRef.current;
263
+ if (!root) {
264
+ return;
265
+ }
266
+ const read = () => {
267
+ const text = root.querySelector("form > button code")?.textContent?.trim();
268
+ if (text) {
269
+ setBaseUrl(text.replace(/\/$/, ""));
270
+ }
271
+ const send = root.querySelector("form > div > button");
272
+ setLoading(send?.hasAttribute("disabled") ?? false);
273
+ };
274
+ read();
275
+ const observer = new MutationObserver(read);
276
+ observer.observe(root, {
277
+ subtree: true,
278
+ childList: true,
279
+ characterData: true,
280
+ attributes: true,
281
+ attributeFilter: ["disabled"]
282
+ });
283
+ return () => {
284
+ observer.disconnect();
285
+ };
286
+ }, [formRef]);
287
+ const clickHidden = (selector) => {
288
+ const el = formRef.current?.querySelector(selector);
289
+ el?.click();
290
+ };
291
+ const fullUrl = `${baseUrl}/${path.replace(/^\/+/, "")}`;
292
+ const copyUrl = () => {
293
+ const flash = () => {
294
+ setCopied(true);
295
+ setTimeout(() => {
296
+ setCopied(false);
297
+ }, 1600);
298
+ };
299
+ void copyToClipboard(fullUrl).then((ok) => {
300
+ if (ok) {
301
+ flash();
302
+ }
303
+ });
304
+ };
305
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "api-tryit-reqline not-prose", children: [
306
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "api-tryit-reqbar", children: [
307
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "api-tryit-reqmethod", "data-method": method.toLowerCase(), children: method.toUpperCase() }),
308
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "api-tryit-reqscroll", children: [
309
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "api-tryit-envwrap", children: [
310
+ /* @__PURE__ */ jsxRuntime.jsxs(
311
+ "button",
312
+ {
313
+ type: "button",
314
+ ref: envRef,
315
+ className: "api-tryit-env",
316
+ "aria-label": "Change server",
317
+ "aria-haspopup": inline ? "listbox" : "dialog",
318
+ "aria-expanded": inline ? menuOpen : void 0,
319
+ onClick: () => {
320
+ if (inline) {
321
+ const rect = envRef.current?.getBoundingClientRect();
322
+ if (rect) {
323
+ setMenuAt({ top: rect.bottom + 7, left: rect.left - 8 });
324
+ }
325
+ setMenuOpen((prev) => !prev);
326
+ } else {
327
+ clickHidden("form > button");
328
+ }
329
+ },
330
+ children: [
331
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "api-tryit-baseurl", children: baseUrl }),
332
+ chevronUpDownIcon()
333
+ ]
334
+ }
335
+ ),
336
+ inline && menuOpen && menuAt ? reactDom.createPortal(
337
+ /* @__PURE__ */ jsxRuntime.jsx(
338
+ "ul",
339
+ {
340
+ ref: menuRef,
341
+ className: "api-tryit-envmenu",
342
+ role: "listbox",
343
+ "aria-label": "API server",
344
+ style: { top: menuAt.top, left: menuAt.left },
345
+ children: inline.list.map((option) => {
346
+ const active = option.url.replace(/\/$/, "") === baseUrl;
347
+ return /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs(
348
+ "button",
349
+ {
350
+ type: "button",
351
+ role: "option",
352
+ "aria-selected": active,
353
+ className: "api-tryit-envitem",
354
+ "data-active": active ? "" : void 0,
355
+ onClick: () => {
356
+ inline.select(option.url);
357
+ setMenuOpen(false);
358
+ },
359
+ children: [
360
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "api-tryit-envcheck", children: active ? checkIcon() : null }),
361
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "api-tryit-envurl", children: option.url })
362
+ ]
363
+ }
364
+ ) }, option.url);
365
+ })
366
+ }
367
+ ),
368
+ document.body
369
+ ) : null
370
+ ] }),
371
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "api-tryit-reqpath", children: pathSegments(path) })
372
+ ] }),
373
+ /* @__PURE__ */ jsxRuntime.jsx(
374
+ "button",
375
+ {
376
+ type: "button",
377
+ className: "api-tryit-copy",
378
+ "aria-label": copied ? "Copied" : "Copy URL",
379
+ "data-copied": copied ? "" : void 0,
380
+ onClick: copyUrl,
381
+ children: copied ? checkIcon() : copyIcon()
382
+ }
383
+ )
384
+ ] }),
385
+ /* @__PURE__ */ jsxRuntime.jsxs(
386
+ "button",
387
+ {
388
+ type: "button",
389
+ className: "api-tryit-send",
390
+ "data-loading": loading ? "" : void 0,
391
+ disabled: loading,
392
+ onClick: () => {
393
+ clickHidden("form > div > button");
394
+ },
395
+ children: [
396
+ loading ? "Sending" : "Send",
397
+ loading ? spinnerIcon() : playIcon()
398
+ ]
399
+ }
400
+ )
401
+ ] });
402
+ }
403
+ function ApiTryIt({
404
+ method,
405
+ path,
406
+ serverUrl,
407
+ servers,
408
+ onSelectServer,
409
+ children,
410
+ example
411
+ }) {
412
+ const [open, setOpen] = react.useState(false);
413
+ const [mounted, setMounted] = react.useState(false);
414
+ const formRef = react.useRef(null);
415
+ useEnumMenus();
416
+ react.useEffect(() => {
417
+ setMounted(true);
418
+ }, []);
419
+ react.useEffect(() => {
420
+ if (!open) {
421
+ return;
422
+ }
423
+ const onKey = (event) => {
424
+ if (event.key === "Escape") {
425
+ setOpen(false);
426
+ }
427
+ };
428
+ document.addEventListener("keydown", onKey);
429
+ document.body.style.overflow = "hidden";
430
+ document.body.classList.add("api-tryit-open");
431
+ return () => {
432
+ document.removeEventListener("keydown", onKey);
433
+ document.body.style.overflow = "";
434
+ document.body.classList.remove("api-tryit-open");
435
+ };
436
+ }, [open]);
437
+ const host = serverUrl ? serverUrl.replace(/^https?:\/\//, "").replace(/\/$/, "") : null;
438
+ const onBackdrop = (event) => {
439
+ if (event.target === event.currentTarget) {
440
+ setOpen(false);
441
+ }
442
+ };
443
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
444
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "api-tryit-bar not-prose", children: [
445
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "api-tryit-method", "data-method": method.toLowerCase(), children: method.toUpperCase() }),
446
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "api-tryit-url", children: [
447
+ host ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "api-tryit-host", children: host }) : null,
448
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "api-tryit-path", children: path })
449
+ ] }),
450
+ /* @__PURE__ */ jsxRuntime.jsxs(
451
+ "button",
452
+ {
453
+ type: "button",
454
+ className: "api-tryit-btn",
455
+ onClick: () => {
456
+ setOpen(true);
457
+ },
458
+ children: [
459
+ "Try it",
460
+ filledIcon(PLAY_PATH, { size: 11 })
461
+ ]
462
+ }
463
+ )
464
+ ] }),
465
+ mounted && open ? reactDom.createPortal(
466
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "api-tryit-overlay", onClick: onBackdrop, children: /* @__PURE__ */ jsxRuntime.jsxs(
467
+ "div",
468
+ {
469
+ className: "api-tryit-modal",
470
+ "data-columns": example ? "2" : "1",
471
+ role: "dialog",
472
+ "aria-label": "API playground",
473
+ children: [
474
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "api-tryit-form", ref: formRef, children: [
475
+ /* @__PURE__ */ jsxRuntime.jsx(
476
+ RequestBar,
477
+ {
478
+ method,
479
+ path,
480
+ serverUrl,
481
+ servers,
482
+ onSelectServer,
483
+ formRef
484
+ }
485
+ ),
486
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "api-tryit-scroll", children })
487
+ ] }),
488
+ example ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "api-tryit-example", children: example }) : null
489
+ ]
490
+ }
491
+ ) }),
492
+ document.body
493
+ ) : null
494
+ ] });
495
+ }
496
+ ApiTryIt.acceptsExample = true;
497
+ function tokenizeJson(source) {
498
+ const pattern = /("(?:\\.|[^"\\])*")(\s*:)?|(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)|\b(true|false|null)\b|([{}[\],:])/g;
499
+ const tokens = [];
500
+ let last = 0;
501
+ let match;
502
+ while ((match = pattern.exec(source)) !== null) {
503
+ if (match.index > last) {
504
+ tokens.push({ text: source.slice(last, match.index) });
505
+ }
506
+ if (match[1] !== void 0) {
507
+ if (match[2] !== void 0) {
508
+ tokens.push({ text: match[1], kind: "key" });
509
+ tokens.push({ text: match[2], kind: "punctuation" });
510
+ } else {
511
+ tokens.push({ text: match[1], kind: "string" });
512
+ }
513
+ } else if (match[3] !== void 0) {
514
+ tokens.push({ text: match[3], kind: "number" });
515
+ } else if (match[4] !== void 0) {
516
+ tokens.push({ text: match[4], kind: "literal" });
517
+ } else if (match[5] !== void 0) {
518
+ tokens.push({ text: match[5], kind: "punctuation" });
519
+ }
520
+ last = pattern.lastIndex;
521
+ }
522
+ if (last < source.length) {
523
+ tokens.push({ text: source.slice(last) });
524
+ }
525
+ return tokens;
526
+ }
527
+ function setReactTextareaValue(el, next) {
528
+ const descriptor = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, "value");
529
+ const setter = descriptor?.set;
530
+ setter?.call(el, next);
531
+ el.dispatchEvent(new Event("input", { bubbles: true }));
532
+ }
533
+ function JsonBodyEditor({ sectionRef }) {
534
+ const sourceRef = react.useRef(null);
535
+ const [value, setValue] = react.useState(null);
536
+ const [error, setError] = react.useState(null);
537
+ const [copied, setCopied] = react.useState(false);
538
+ react.useEffect(() => {
539
+ const root = sectionRef.current;
540
+ if (!root) {
541
+ return;
542
+ }
543
+ const read = () => {
544
+ const el = root.querySelector("textarea:not(.api-json-input)");
545
+ sourceRef.current = el;
546
+ setValue(el ? el.value : null);
547
+ };
548
+ read();
549
+ const observer = new MutationObserver(read);
550
+ observer.observe(root, { subtree: true, childList: true });
551
+ return () => {
552
+ observer.disconnect();
553
+ };
554
+ }, [sectionRef]);
555
+ if (value === null) {
556
+ return null;
557
+ }
558
+ const push = (next) => {
559
+ setValue(next);
560
+ try {
561
+ JSON.parse(next);
562
+ setError(null);
563
+ } catch (cause) {
564
+ setError(cause instanceof Error ? cause.message : "Invalid JSON.");
565
+ }
566
+ if (sourceRef.current) {
567
+ setReactTextareaValue(sourceRef.current, next);
568
+ }
569
+ };
570
+ const format = () => {
571
+ try {
572
+ push(JSON.stringify(JSON.parse(value), null, 2));
573
+ } catch {
574
+ }
575
+ };
576
+ const copy = () => {
577
+ const flash = () => {
578
+ setCopied(true);
579
+ setTimeout(() => {
580
+ setCopied(false);
581
+ }, 1600);
582
+ };
583
+ void copyToClipboard(value).then((ok) => {
584
+ if (ok) {
585
+ flash();
586
+ }
587
+ });
588
+ };
589
+ const onKeyDown = (event) => {
590
+ if (event.key !== "Tab") {
591
+ return;
592
+ }
593
+ event.preventDefault();
594
+ const el = event.currentTarget;
595
+ const { selectionStart: start, selectionEnd: end } = el;
596
+ const next = `${value.slice(0, start)} ${value.slice(end)}`;
597
+ push(next);
598
+ requestAnimationFrame(() => {
599
+ el.selectionStart = el.selectionEnd = start + 2;
600
+ });
601
+ };
602
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "api-json", "data-invalid": error ? "" : void 0, children: [
603
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "api-json-toolbar", children: [
604
+ /* @__PURE__ */ jsxRuntime.jsx(
605
+ "button",
606
+ {
607
+ type: "button",
608
+ className: "api-json-action",
609
+ onClick: format,
610
+ disabled: error !== null,
611
+ children: "Format"
612
+ }
613
+ ),
614
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "api-json-action", onClick: copy, children: copied ? "Copied" : "Copy" })
615
+ ] }),
616
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "api-json-editor", children: [
617
+ /* @__PURE__ */ jsxRuntime.jsxs("pre", { className: "api-json-mirror", "aria-hidden": "true", children: [
618
+ tokenizeJson(value).map((token, index) => /* @__PURE__ */ jsxRuntime.jsx("span", { "data-token": token.kind, children: token.text }, `${String(index)}-${token.kind ?? "plain"}`)),
619
+ "\n"
620
+ ] }),
621
+ /* @__PURE__ */ jsxRuntime.jsx(
622
+ "textarea",
623
+ {
624
+ className: "api-json-input",
625
+ value,
626
+ spellCheck: false,
627
+ "aria-label": "Request body JSON",
628
+ onChange: (event) => {
629
+ push(event.target.value);
630
+ },
631
+ onKeyDown
632
+ }
633
+ )
634
+ ] }),
635
+ error ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "api-json-error", role: "alert", children: error }) : null
636
+ ] });
637
+ }
638
+ function ApiPlaygroundSection({
639
+ title,
640
+ type,
641
+ children
642
+ }) {
643
+ const sectionRef = react.useRef(null);
644
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "api-tryit-section", "data-type": type, ref: sectionRef, children: [
645
+ title ? /* @__PURE__ */ jsxRuntime.jsx("h4", { className: "api-tryit-section-title", children: title }) : null,
646
+ children,
647
+ type === "body" ? /* @__PURE__ */ jsxRuntime.jsx(JsonBodyEditor, { sectionRef }) : null
648
+ ] });
649
+ }
650
+
651
+ exports.ApiPlaygroundSection = ApiPlaygroundSection;
652
+ exports.ApiTryIt = ApiTryIt;
653
+ //# sourceMappingURL=api-try-it.cjs.map
654
+ //# sourceMappingURL=api-try-it.cjs.map