rspress-plugin-api-extractor 0.1.0 → 0.1.2

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 (48) hide show
  1. package/index.js +32 -236
  2. package/package.json +3 -3
  3. package/runtime/components/ApiExample/index.js +29 -0
  4. package/runtime/components/ApiLlmsPackageActions/index.js +348 -0
  5. package/runtime/components/ApiLlmsPackageActions/index.module.js +2 -0
  6. package/runtime/components/ApiLlmsViewOptions/index.js +365 -0
  7. package/runtime/components/ApiMember/index.js +51 -0
  8. package/runtime/components/ApiSignature/index.js +32 -0
  9. package/runtime/components/EnumMembersTable/index.js +69 -0
  10. package/runtime/components/EnumMembersTable/index.module.js +7 -0
  11. package/runtime/components/EnumMembersTable/index_module.css +100 -0
  12. package/runtime/components/ExampleBlock/index.js +36 -0
  13. package/runtime/components/ExampleBlock/index.module.js +6 -0
  14. package/runtime/components/ExampleBlock/index_module.css +12 -0
  15. package/runtime/components/MarkdownContent/index.js +23 -0
  16. package/runtime/components/MarkdownText/index.js +27 -0
  17. package/runtime/components/MemberSignature/index.js +54 -0
  18. package/runtime/components/MemberSignature/index.module.js +7 -0
  19. package/runtime/components/MemberSignature/index_module.css +27 -0
  20. package/runtime/components/ParametersTable/index.js +69 -0
  21. package/runtime/components/ParametersTable/index.module.js +7 -0
  22. package/runtime/components/ParametersTable/index_module.css +104 -0
  23. package/runtime/components/SignatureBlock/index.js +35 -0
  24. package/runtime/components/SignatureBlock/index.module.js +7 -0
  25. package/runtime/components/SignatureBlock/index_module.css +27 -0
  26. package/runtime/components/SignatureCode/index.js +36 -0
  27. package/runtime/components/SignatureCode/index.module.js +7 -0
  28. package/runtime/components/SignatureCode/index_module.css +53 -0
  29. package/runtime/components/SignatureToolbar/index.js +55 -0
  30. package/runtime/components/SignatureToolbar/index.module.js +11 -0
  31. package/runtime/components/SignatureToolbar/index_module.css +124 -0
  32. package/runtime/components/buttons/ButtonGroup.js +9 -0
  33. package/runtime/components/buttons/CopyCodeButton.js +42 -0
  34. package/runtime/components/buttons/WrapSignatureButton.js +20 -0
  35. package/runtime/components/buttons/index.module.js +6 -0
  36. package/runtime/components/buttons/index_module.css +37 -0
  37. package/runtime/components/icons/CheckIcon/index.js +20 -0
  38. package/runtime/components/icons/CopyIcon/index.js +20 -0
  39. package/runtime/components/icons/UnwrapIcon/index.js +21 -0
  40. package/runtime/components/icons/WrapIcon/index.js +20 -0
  41. package/runtime/components/shared/_twoslash.css +447 -0
  42. package/runtime/components/shared/types.js +0 -0
  43. package/runtime/components/shared/variables.css +85 -0
  44. package/runtime/hooks/useWrapToggle.js +12 -0
  45. package/runtime/index.d.ts +173 -0
  46. package/runtime/index.js +11 -0
  47. package/runtime/utils/decode-hast.js +18 -0
  48. package/runtime/utils/hast-renderer.js +10 -0
@@ -0,0 +1,348 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { usePage, useSite } from "@rspress/core/runtime";
3
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
+ import { createPortal } from "react-dom";
5
+ function resolveUrl(urlPath) {
6
+ if ("u" < typeof window) return urlPath;
7
+ if (urlPath.startsWith("http://") || urlPath.startsWith("https://")) return urlPath;
8
+ return `${window.location.origin}${urlPath}`;
9
+ }
10
+ function findMatchingScope(pathname, scopes) {
11
+ const sorted = [
12
+ ...scopes
13
+ ].sort((a, b)=>b.packageRoute.length - a.packageRoute.length);
14
+ for (const scope of sorted){
15
+ const base = scope.packageRoute.endsWith("/") ? scope.packageRoute : `${scope.packageRoute}/`;
16
+ if (pathname === scope.packageRoute || pathname.startsWith(base)) return scope;
17
+ }
18
+ return null;
19
+ }
20
+ async function copyToClipboard(text) {
21
+ await navigator.clipboard.writeText(text);
22
+ }
23
+ function ApiLlmsPackageActions() {
24
+ const { site } = useSite();
25
+ const { page } = usePage();
26
+ const [outlineTarget, setOutlineTarget] = useState(null);
27
+ const scopes = useMemo(()=>{
28
+ if (import.meta.env.SSG_MD) return [];
29
+ const tc = site?.themeConfig;
30
+ return tc?.apiExtractorScopes ?? [];
31
+ }, [
32
+ site
33
+ ]);
34
+ const activeScope = useMemo(()=>findMatchingScope(page.routePath, scopes), [
35
+ page.routePath,
36
+ scopes
37
+ ]);
38
+ const placement = useMemo(()=>{
39
+ const llmsUI = site?.themeConfig?.llmsUI;
40
+ return "object" == typeof llmsUI ? llmsUI?.placement ?? "title" : "title";
41
+ }, [
42
+ site
43
+ ]);
44
+ useEffect(()=>{
45
+ if (import.meta.env.SSG_MD || !activeScope) return void setOutlineTarget(null);
46
+ if ("outline" !== placement) return;
47
+ const timer = setTimeout(()=>{
48
+ setOutlineTarget(document.querySelector(".rp-outline__bottom"));
49
+ }, 100);
50
+ return ()=>clearTimeout(timer);
51
+ }, [
52
+ activeScope,
53
+ placement,
54
+ page.routePath
55
+ ]);
56
+ if (import.meta.env.SSG_MD || !activeScope) return null;
57
+ if ("outline" === placement && outlineTarget) return /*#__PURE__*/ createPortal(/*#__PURE__*/ jsx(OutlinePackageActions, {
58
+ scope: activeScope
59
+ }), outlineTarget);
60
+ return null;
61
+ }
62
+ function OutlinePackageActions({ scope }) {
63
+ const [copyFeedback, setCopyFeedback] = useState(null);
64
+ const [isOpenMenuOpen, setIsOpenMenuOpen] = useState(false);
65
+ const wrapperRef = useRef(null);
66
+ useEffect(()=>{
67
+ if (!isOpenMenuOpen) return;
68
+ const handleClick = (e)=>{
69
+ if (wrapperRef.current && !wrapperRef.current.contains(e.target)) setIsOpenMenuOpen(false);
70
+ };
71
+ document.addEventListener("mousedown", handleClick);
72
+ return ()=>document.removeEventListener("mousedown", handleClick);
73
+ }, [
74
+ isOpenMenuOpen
75
+ ]);
76
+ const handleCopyDocs = useCallback(async ()=>{
77
+ try {
78
+ const url = resolveUrl(scope.llmsDocsTxt);
79
+ const response = await fetch(url);
80
+ const text = await response.text();
81
+ await copyToClipboard(text);
82
+ setCopyFeedback("Copied!");
83
+ setTimeout(()=>setCopyFeedback(null), 1500);
84
+ } catch {
85
+ setCopyFeedback("Failed");
86
+ setTimeout(()=>setCopyFeedback(null), 1500);
87
+ }
88
+ }, [
89
+ scope
90
+ ]);
91
+ const handleCopyLink = useCallback(async (urlPath)=>{
92
+ try {
93
+ await copyToClipboard(resolveUrl(urlPath));
94
+ setCopyFeedback("Copied!");
95
+ setTimeout(()=>setCopyFeedback(null), 1500);
96
+ } catch {
97
+ setCopyFeedback("Failed");
98
+ setTimeout(()=>setCopyFeedback(null), 1500);
99
+ }
100
+ }, []);
101
+ const llmsTxtUrl = resolveUrl(scope.llmsTxt);
102
+ const q = `Read ${llmsTxtUrl}, I want to ask questions about the ${scope.name} package.`;
103
+ return /*#__PURE__*/ jsxs(Fragment, {
104
+ children: [
105
+ /*#__PURE__*/ jsxs("button", {
106
+ type: "button",
107
+ className: "rp-outline__action-row",
108
+ onClick: handleCopyDocs,
109
+ children: [
110
+ /*#__PURE__*/ jsx(CopyIcon, {}),
111
+ /*#__PURE__*/ jsx("span", {
112
+ children: copyFeedback ?? `Copy ${scope.name} docs`
113
+ })
114
+ ]
115
+ }),
116
+ /*#__PURE__*/ jsxs("button", {
117
+ type: "button",
118
+ className: "rp-outline__action-row",
119
+ onClick: ()=>handleCopyLink(scope.llmsTxt),
120
+ children: [
121
+ /*#__PURE__*/ jsx(LinkIcon, {}),
122
+ /*#__PURE__*/ jsx("span", {
123
+ children: "Copy llms.txt link"
124
+ })
125
+ ]
126
+ }),
127
+ /*#__PURE__*/ jsxs("div", {
128
+ ref: wrapperRef,
129
+ className: "rp-outline__open-in-wrapper",
130
+ children: [
131
+ /*#__PURE__*/ jsxs("button", {
132
+ type: "button",
133
+ className: "rp-outline__action-row",
134
+ onClick: ()=>setIsOpenMenuOpen(!isOpenMenuOpen),
135
+ children: [
136
+ /*#__PURE__*/ jsx(ExternalLinkIcon, {}),
137
+ /*#__PURE__*/ jsxs("span", {
138
+ children: [
139
+ "Open ",
140
+ scope.name,
141
+ " in chat"
142
+ ]
143
+ })
144
+ ]
145
+ }),
146
+ isOpenMenuOpen && /*#__PURE__*/ jsxs("div", {
147
+ className: "rp-llms-view-options__menu",
148
+ children: [
149
+ /*#__PURE__*/ jsxs("a", {
150
+ className: "rp-llms-view-options__menu-item",
151
+ href: `https://chatgpt.com/?${new URLSearchParams({
152
+ hints: "search",
153
+ q
154
+ })}`,
155
+ target: "_blank",
156
+ rel: "noopener noreferrer",
157
+ onClick: ()=>setIsOpenMenuOpen(false),
158
+ children: [
159
+ /*#__PURE__*/ jsx("span", {
160
+ className: "rp-llms-view-options__item-icon",
161
+ children: /*#__PURE__*/ jsx(ChatGPTIcon, {})
162
+ }),
163
+ /*#__PURE__*/ jsx("span", {
164
+ children: "Open in ChatGPT"
165
+ }),
166
+ /*#__PURE__*/ jsx("span", {
167
+ className: "rp-llms-view-options__external-icon",
168
+ children: /*#__PURE__*/ jsx(ExternalLinkSmallIcon, {})
169
+ })
170
+ ]
171
+ }),
172
+ /*#__PURE__*/ jsxs("a", {
173
+ className: "rp-llms-view-options__menu-item",
174
+ href: `https://claude.ai/new?${new URLSearchParams({
175
+ q
176
+ })}`,
177
+ target: "_blank",
178
+ rel: "noopener noreferrer",
179
+ onClick: ()=>setIsOpenMenuOpen(false),
180
+ children: [
181
+ /*#__PURE__*/ jsx("span", {
182
+ className: "rp-llms-view-options__item-icon",
183
+ children: /*#__PURE__*/ jsx(ClaudeIcon, {})
184
+ }),
185
+ /*#__PURE__*/ jsx("span", {
186
+ children: "Open in Claude"
187
+ }),
188
+ /*#__PURE__*/ jsx("span", {
189
+ className: "rp-llms-view-options__external-icon",
190
+ children: /*#__PURE__*/ jsx(ExternalLinkSmallIcon, {})
191
+ })
192
+ ]
193
+ })
194
+ ]
195
+ })
196
+ ]
197
+ })
198
+ ]
199
+ });
200
+ }
201
+ function CopyIcon() {
202
+ return /*#__PURE__*/ jsxs("svg", {
203
+ width: 16,
204
+ height: 16,
205
+ viewBox: "0 0 24 24",
206
+ fill: "none",
207
+ stroke: "currentColor",
208
+ strokeWidth: 2,
209
+ strokeLinecap: "round",
210
+ strokeLinejoin: "round",
211
+ children: [
212
+ /*#__PURE__*/ jsx("title", {
213
+ children: "Copy"
214
+ }),
215
+ /*#__PURE__*/ jsx("rect", {
216
+ x: 9,
217
+ y: 9,
218
+ width: 13,
219
+ height: 13,
220
+ rx: 2,
221
+ ry: 2
222
+ }),
223
+ /*#__PURE__*/ jsx("path", {
224
+ d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"
225
+ })
226
+ ]
227
+ });
228
+ }
229
+ function LinkIcon() {
230
+ return /*#__PURE__*/ jsxs("svg", {
231
+ width: 16,
232
+ height: 16,
233
+ viewBox: "0 0 24 24",
234
+ fill: "none",
235
+ stroke: "currentColor",
236
+ strokeWidth: 2,
237
+ strokeLinecap: "round",
238
+ strokeLinejoin: "round",
239
+ children: [
240
+ /*#__PURE__*/ jsx("title", {
241
+ children: "Link"
242
+ }),
243
+ /*#__PURE__*/ jsx("path", {
244
+ d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"
245
+ }),
246
+ /*#__PURE__*/ jsx("path", {
247
+ d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"
248
+ })
249
+ ]
250
+ });
251
+ }
252
+ function ExternalLinkIcon() {
253
+ return /*#__PURE__*/ jsxs("svg", {
254
+ width: 16,
255
+ height: 16,
256
+ viewBox: "0 0 24 24",
257
+ fill: "none",
258
+ stroke: "currentColor",
259
+ strokeWidth: 2,
260
+ strokeLinecap: "round",
261
+ strokeLinejoin: "round",
262
+ children: [
263
+ /*#__PURE__*/ jsx("title", {
264
+ children: "External link"
265
+ }),
266
+ /*#__PURE__*/ jsx("path", {
267
+ d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"
268
+ }),
269
+ /*#__PURE__*/ jsx("polyline", {
270
+ points: "15 3 21 3 21 9"
271
+ }),
272
+ /*#__PURE__*/ jsx("line", {
273
+ x1: 10,
274
+ y1: 14,
275
+ x2: 21,
276
+ y2: 3
277
+ })
278
+ ]
279
+ });
280
+ }
281
+ function ExternalLinkSmallIcon() {
282
+ return /*#__PURE__*/ jsxs("svg", {
283
+ width: 12,
284
+ height: 12,
285
+ viewBox: "0 0 24 24",
286
+ fill: "none",
287
+ stroke: "currentColor",
288
+ strokeWidth: 2,
289
+ strokeLinecap: "round",
290
+ strokeLinejoin: "round",
291
+ children: [
292
+ /*#__PURE__*/ jsx("title", {
293
+ children: "External link"
294
+ }),
295
+ /*#__PURE__*/ jsx("path", {
296
+ d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"
297
+ }),
298
+ /*#__PURE__*/ jsx("polyline", {
299
+ points: "15 3 21 3 21 9"
300
+ }),
301
+ /*#__PURE__*/ jsx("line", {
302
+ x1: 10,
303
+ y1: 14,
304
+ x2: 21,
305
+ y2: 3
306
+ })
307
+ ]
308
+ });
309
+ }
310
+ function ChatGPTIcon() {
311
+ return /*#__PURE__*/ jsxs("svg", {
312
+ role: "img",
313
+ viewBox: "0 0 24 24",
314
+ fill: "currentColor",
315
+ xmlns: "http://www.w3.org/2000/svg",
316
+ width: 16,
317
+ height: 16,
318
+ children: [
319
+ /*#__PURE__*/ jsx("title", {
320
+ children: "ChatGPT"
321
+ }),
322
+ /*#__PURE__*/ jsx("path", {
323
+ d: "M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z"
324
+ })
325
+ ]
326
+ });
327
+ }
328
+ function ClaudeIcon() {
329
+ return /*#__PURE__*/ jsxs("svg", {
330
+ fill: "currentColor",
331
+ role: "img",
332
+ viewBox: "0 0 24 24",
333
+ xmlns: "http://www.w3.org/2000/svg",
334
+ width: 16,
335
+ height: 16,
336
+ children: [
337
+ /*#__PURE__*/ jsx("title", {
338
+ children: "Anthropic"
339
+ }),
340
+ /*#__PURE__*/ jsx("path", {
341
+ d: "M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z"
342
+ })
343
+ ]
344
+ });
345
+ }
346
+ const components_ApiLlmsPackageActions = ApiLlmsPackageActions;
347
+ export default components_ApiLlmsPackageActions;
348
+ export { ApiLlmsPackageActions };
@@ -0,0 +1,2 @@
1
+ const index_module = {};
2
+ export default index_module;