rspress-plugin-api-extractor 0.1.2 → 0.2.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 (109) hide show
  1. package/README.md +2 -2
  2. package/api-extracted-package.js +426 -0
  3. package/build-program.js +120 -0
  4. package/build-stages.js +664 -0
  5. package/category-resolver.js +50 -0
  6. package/code-post-processor.js +38 -0
  7. package/config-helpers.js +106 -0
  8. package/config-utils.js +258 -0
  9. package/content-hash.js +79 -0
  10. package/errors.js +29 -0
  11. package/formatter.js +69 -0
  12. package/hide-cut-transformer.js +96 -0
  13. package/index.d.ts +901 -831
  14. package/index.js +4 -6128
  15. package/layers/ConfigServiceLive.js +377 -0
  16. package/layers/ObservabilityLive.js +136 -0
  17. package/layers/PathDerivationServiceLive.js +16 -0
  18. package/layers/SnapshotServiceLive.js +94 -0
  19. package/layers/TypeRegistryServiceLive.js +46 -0
  20. package/llms-processing.js +270 -0
  21. package/llms-program.js +262 -0
  22. package/loader.js +186 -0
  23. package/markdown/cross-linker.js +156 -0
  24. package/markdown/helpers.js +364 -0
  25. package/markdown/index.js +11 -0
  26. package/markdown/page-generators/class-page.js +357 -0
  27. package/markdown/page-generators/enum-page.js +152 -0
  28. package/markdown/page-generators/function-page.js +127 -0
  29. package/markdown/page-generators/index-pages.js +27 -0
  30. package/markdown/page-generators/interface-page.js +307 -0
  31. package/markdown/page-generators/namespace-page.js +280 -0
  32. package/markdown/page-generators/type-alias-page.js +110 -0
  33. package/markdown/page-generators/variable-page.js +110 -0
  34. package/markdown/shiki-utils.js +48 -0
  35. package/migrations/001_create_snapshots.js +25 -0
  36. package/model-loader.js +95 -0
  37. package/multi-entry-resolver.js +70 -0
  38. package/og-resolver.js +271 -0
  39. package/package.json +63 -73
  40. package/path-derivation.js +48 -0
  41. package/plugin.js +218 -0
  42. package/prettier-formatter.js +73 -0
  43. package/public/tsconfig/rspress.json +44 -0
  44. package/remark-api-codeblocks.js +130 -0
  45. package/remark-with-api.js +172 -0
  46. package/route-collisions.js +52 -0
  47. package/runtime/components/ApiExample/index.js +29 -25
  48. package/runtime/components/ApiLlmsPackageActions/index.js +252 -323
  49. package/runtime/components/ApiLlmsViewOptions/index.js +269 -340
  50. package/runtime/components/ApiMember/index.js +49 -47
  51. package/runtime/components/ApiSignature/index.js +32 -28
  52. package/runtime/components/EnumMembersTable/{index_module.css → index.css} +18 -19
  53. package/runtime/components/EnumMembersTable/index.js +36 -67
  54. package/runtime/components/EnumMembersTable/index.module.js +9 -6
  55. package/runtime/components/ExampleBlock/{index_module.css → index.css} +2 -3
  56. package/runtime/components/ExampleBlock/index.js +23 -28
  57. package/runtime/components/ExampleBlock/index.module.js +8 -5
  58. package/runtime/components/MarkdownContent/index.js +26 -18
  59. package/runtime/components/MarkdownText/index.js +28 -22
  60. package/runtime/components/MemberSignature/{index_module.css → index.css} +5 -6
  61. package/runtime/components/MemberSignature/index.js +46 -46
  62. package/runtime/components/MemberSignature/index.module.js +9 -6
  63. package/runtime/components/ParametersTable/{index_module.css → index.css} +19 -20
  64. package/runtime/components/ParametersTable/index.js +36 -67
  65. package/runtime/components/ParametersTable/index.module.js +9 -6
  66. package/runtime/components/SignatureBlock/{index_module.css → index.css} +5 -6
  67. package/runtime/components/SignatureBlock/index.js +30 -29
  68. package/runtime/components/SignatureBlock/index.module.js +9 -6
  69. package/runtime/components/SignatureCode/{index_module.css → index.css} +9 -10
  70. package/runtime/components/SignatureCode/index.js +40 -32
  71. package/runtime/components/SignatureCode/index.module.js +9 -6
  72. package/runtime/components/SignatureToolbar/{index_module.css → index.css} +18 -20
  73. package/runtime/components/SignatureToolbar/index.js +48 -51
  74. package/runtime/components/SignatureToolbar/index.module.js +13 -10
  75. package/runtime/components/buttons/ButtonGroup.js +13 -6
  76. package/runtime/components/buttons/CopyCodeButton.js +40 -38
  77. package/runtime/components/buttons/WrapSignatureButton.js +20 -16
  78. package/runtime/components/buttons/{index_module.css → index.css} +5 -6
  79. package/runtime/components/buttons/index.module.js +8 -5
  80. package/runtime/components/icons/CheckIcon/index.js +20 -17
  81. package/runtime/components/icons/CopyIcon/index.js +20 -17
  82. package/runtime/components/icons/UnwrapIcon/index.js +22 -18
  83. package/runtime/components/icons/WrapIcon/index.js +20 -17
  84. package/runtime/components/shared/_twoslash.css +3 -10
  85. package/runtime/components/shared/variables.css +0 -3
  86. package/runtime/hooks/useWrapToggle.js +32 -9
  87. package/runtime/index.d.ts +513 -173
  88. package/runtime/index.js +11 -9
  89. package/runtime/utils/decode-hast.js +31 -16
  90. package/runtime/utils/hast-renderer.js +21 -7
  91. package/schemas/config.js +199 -0
  92. package/schemas/index.js +5 -0
  93. package/schemas/opengraph.js +26 -0
  94. package/schemas/performance.js +19 -0
  95. package/serve.js +133 -0
  96. package/services/ConfigService.js +7 -0
  97. package/services/PathDerivationService.js +7 -0
  98. package/services/SnapshotService.js +7 -0
  99. package/services/TypeRegistryService.js +7 -0
  100. package/shiki-transformer.js +758 -0
  101. package/tsconfig-parser.js +127 -0
  102. package/tsdoc-metadata.json +11 -11
  103. package/twoslash-patterns.js +87 -0
  104. package/twoslash-transformer.js +316 -0
  105. package/type-reference-extractor.js +201 -0
  106. package/typescript-config.js +168 -0
  107. package/vfs-registry.js +121 -0
  108. package/0~llms-program.js +0 -344
  109. package/runtime/components/ApiLlmsPackageActions/index.module.js +0 -2
@@ -1,365 +1,294 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
1
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
3
  import { useI18n, usePage, useSite } from "@rspress/core/runtime";
3
4
  import { useMdUrl } from "@rspress/core/theme";
4
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
5
+
6
+ //#region src/runtime/components/ApiLlmsViewOptions/index.tsx
7
+ /**
8
+ * Custom LlmsViewOptions that replaces RSPress's default via resolve.alias.
9
+ *
10
+ * - Outside package scope: reproduces the original RSPress dropdown behavior
11
+ * - Inside package scope: adds package-level copy/open actions to the dropdown
12
+ *
13
+ * Uses RSPress's own CSS classes (rp-llms-*) for visual consistency.
14
+ */
5
15
  function resolveUrl(urlPath) {
6
- if ("u" < typeof window) return urlPath;
7
- return urlPath.startsWith("http") ? urlPath : `${window.location.origin}${urlPath}`;
16
+ if (typeof window === "undefined") return urlPath;
17
+ return urlPath.startsWith("http") ? urlPath : `${window.location.origin}${urlPath}`;
8
18
  }
9
19
  function findScope(pathname, scopes) {
10
- const sorted = [
11
- ...scopes
12
- ].sort((a, b)=>b.packageRoute.length - a.packageRoute.length);
13
- for (const s of sorted){
14
- const base = s.packageRoute.endsWith("/") ? s.packageRoute : `${s.packageRoute}/`;
15
- if (pathname === s.packageRoute || pathname.startsWith(base)) return s;
16
- }
17
- return null;
20
+ const sorted = [...scopes].sort((a, b) => b.packageRoute.length - a.packageRoute.length);
21
+ for (const s of sorted) {
22
+ const base = s.packageRoute.endsWith("/") ? s.packageRoute : `${s.packageRoute}/`;
23
+ if (pathname === s.packageRoute || pathname.startsWith(base)) return s;
24
+ }
25
+ return null;
18
26
  }
19
27
  async function copyText(text) {
20
- await navigator.clipboard.writeText(text);
28
+ await navigator.clipboard.writeText(text);
21
29
  }
22
30
  function DownArrow({ className }) {
23
- return /*#__PURE__*/ jsxs("svg", {
24
- className: className,
25
- width: 16,
26
- height: 16,
27
- viewBox: "0 0 24 24",
28
- fill: "none",
29
- stroke: "currentColor",
30
- strokeWidth: 2,
31
- strokeLinecap: "round",
32
- strokeLinejoin: "round",
33
- children: [
34
- /*#__PURE__*/ jsx("title", {
35
- children: "Toggle menu"
36
- }),
37
- /*#__PURE__*/ jsx("path", {
38
- d: "m6 9 6 6 6-6"
39
- })
40
- ]
41
- });
31
+ return /* @__PURE__ */ jsxs("svg", {
32
+ className,
33
+ width: 16,
34
+ height: 16,
35
+ viewBox: "0 0 24 24",
36
+ fill: "none",
37
+ stroke: "currentColor",
38
+ strokeWidth: 2,
39
+ strokeLinecap: "round",
40
+ strokeLinejoin: "round",
41
+ children: [/* @__PURE__ */ jsx("title", { children: "Toggle menu" }), /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" })]
42
+ });
42
43
  }
43
44
  function LinkIcon() {
44
- return /*#__PURE__*/ jsxs("svg", {
45
- width: 16,
46
- height: 16,
47
- viewBox: "0 0 24 24",
48
- fill: "none",
49
- stroke: "currentColor",
50
- strokeWidth: 2,
51
- strokeLinecap: "round",
52
- strokeLinejoin: "round",
53
- children: [
54
- /*#__PURE__*/ jsx("title", {
55
- children: "Link"
56
- }),
57
- /*#__PURE__*/ jsx("path", {
58
- d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"
59
- }),
60
- /*#__PURE__*/ jsx("path", {
61
- d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"
62
- })
63
- ]
64
- });
45
+ return /* @__PURE__ */ jsxs("svg", {
46
+ width: 16,
47
+ height: 16,
48
+ viewBox: "0 0 24 24",
49
+ fill: "none",
50
+ stroke: "currentColor",
51
+ strokeWidth: 2,
52
+ strokeLinecap: "round",
53
+ strokeLinejoin: "round",
54
+ children: [
55
+ /* @__PURE__ */ jsx("title", { children: "Link" }),
56
+ /* @__PURE__ */ jsx("path", { d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" }),
57
+ /* @__PURE__ */ jsx("path", { d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" })
58
+ ]
59
+ });
65
60
  }
66
61
  function CopyIcon() {
67
- return /*#__PURE__*/ jsxs("svg", {
68
- width: 16,
69
- height: 16,
70
- viewBox: "0 0 24 24",
71
- fill: "none",
72
- stroke: "currentColor",
73
- strokeWidth: 2,
74
- strokeLinecap: "round",
75
- strokeLinejoin: "round",
76
- children: [
77
- /*#__PURE__*/ jsx("title", {
78
- children: "Copy"
79
- }),
80
- /*#__PURE__*/ jsx("rect", {
81
- x: 9,
82
- y: 9,
83
- width: 13,
84
- height: 13,
85
- rx: 2,
86
- ry: 2
87
- }),
88
- /*#__PURE__*/ jsx("path", {
89
- d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"
90
- })
91
- ]
92
- });
62
+ return /* @__PURE__ */ jsxs("svg", {
63
+ width: 16,
64
+ height: 16,
65
+ viewBox: "0 0 24 24",
66
+ fill: "none",
67
+ stroke: "currentColor",
68
+ strokeWidth: 2,
69
+ strokeLinecap: "round",
70
+ strokeLinejoin: "round",
71
+ children: [
72
+ /* @__PURE__ */ jsx("title", { children: "Copy" }),
73
+ /* @__PURE__ */ jsx("rect", {
74
+ x: 9,
75
+ y: 9,
76
+ width: 13,
77
+ height: 13,
78
+ rx: 2,
79
+ ry: 2
80
+ }),
81
+ /* @__PURE__ */ jsx("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
82
+ ]
83
+ });
93
84
  }
94
85
  function ExternalLinkIcon() {
95
- return /*#__PURE__*/ jsxs("svg", {
96
- width: 12,
97
- height: 12,
98
- viewBox: "0 0 24 24",
99
- fill: "none",
100
- stroke: "currentColor",
101
- strokeWidth: 2,
102
- strokeLinecap: "round",
103
- strokeLinejoin: "round",
104
- children: [
105
- /*#__PURE__*/ jsx("title", {
106
- children: "External link"
107
- }),
108
- /*#__PURE__*/ jsx("path", {
109
- d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"
110
- }),
111
- /*#__PURE__*/ jsx("polyline", {
112
- points: "15 3 21 3 21 9"
113
- }),
114
- /*#__PURE__*/ jsx("line", {
115
- x1: 10,
116
- y1: 14,
117
- x2: 21,
118
- y2: 3
119
- })
120
- ]
121
- });
86
+ return /* @__PURE__ */ jsxs("svg", {
87
+ width: 12,
88
+ height: 12,
89
+ viewBox: "0 0 24 24",
90
+ fill: "none",
91
+ stroke: "currentColor",
92
+ strokeWidth: 2,
93
+ strokeLinecap: "round",
94
+ strokeLinejoin: "round",
95
+ children: [
96
+ /* @__PURE__ */ jsx("title", { children: "External link" }),
97
+ /* @__PURE__ */ jsx("path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" }),
98
+ /* @__PURE__ */ jsx("polyline", { points: "15 3 21 3 21 9" }),
99
+ /* @__PURE__ */ jsx("line", {
100
+ x1: 10,
101
+ y1: 14,
102
+ x2: 21,
103
+ y2: 3
104
+ })
105
+ ]
106
+ });
122
107
  }
123
108
  function ChatGPTIcon() {
124
- return /*#__PURE__*/ jsxs("svg", {
125
- role: "img",
126
- viewBox: "0 0 24 24",
127
- fill: "currentColor",
128
- xmlns: "http://www.w3.org/2000/svg",
129
- width: 16,
130
- height: 16,
131
- children: [
132
- /*#__PURE__*/ jsx("title", {
133
- children: "ChatGPT"
134
- }),
135
- /*#__PURE__*/ jsx("path", {
136
- 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"
137
- })
138
- ]
139
- });
109
+ return /* @__PURE__ */ jsxs("svg", {
110
+ role: "img",
111
+ viewBox: "0 0 24 24",
112
+ fill: "currentColor",
113
+ xmlns: "http://www.w3.org/2000/svg",
114
+ width: 16,
115
+ height: 16,
116
+ children: [/* @__PURE__ */ jsx("title", { children: "ChatGPT" }), /* @__PURE__ */ jsx("path", { 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" })]
117
+ });
140
118
  }
141
119
  function ClaudeIcon() {
142
- return /*#__PURE__*/ jsxs("svg", {
143
- fill: "currentColor",
144
- role: "img",
145
- viewBox: "0 0 24 24",
146
- xmlns: "http://www.w3.org/2000/svg",
147
- width: 16,
148
- height: 16,
149
- children: [
150
- /*#__PURE__*/ jsx("title", {
151
- children: "Anthropic"
152
- }),
153
- /*#__PURE__*/ jsx("path", {
154
- 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"
155
- })
156
- ]
157
- });
120
+ return /* @__PURE__ */ jsxs("svg", {
121
+ fill: "currentColor",
122
+ role: "img",
123
+ viewBox: "0 0 24 24",
124
+ xmlns: "http://www.w3.org/2000/svg",
125
+ width: 16,
126
+ height: 16,
127
+ children: [/* @__PURE__ */ jsx("title", { children: "Anthropic" }), /* @__PURE__ */ jsx("path", { 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" })]
128
+ });
158
129
  }
159
130
  function LlmsViewOptions(props) {
160
- const { site } = useSite();
161
- const { page } = usePage();
162
- const { pathname } = useMdUrl();
163
- const t = useI18n();
164
- const [isOpen, setIsOpen] = useState(false);
165
- const [feedback, setFeedback] = useState(null);
166
- const dropdownRef = useRef(null);
167
- const llmsUI = site?.themeConfig?.llmsUI;
168
- const configOptions = "object" == typeof llmsUI ? llmsUI?.viewOptions : void 0;
169
- const options = props.options ?? configOptions ?? [
170
- "markdownLink",
171
- "chatgpt",
172
- "claude"
173
- ];
174
- const tc = site?.themeConfig;
175
- const scopes = tc?.apiExtractorScopes ?? [];
176
- const activeScope = useMemo(()=>findScope(page.routePath, scopes), [
177
- page.routePath,
178
- scopes
179
- ]);
180
- useEffect(()=>{
181
- if (!isOpen) return;
182
- const handler = (e)=>{
183
- if (dropdownRef.current && !dropdownRef.current.contains(e.target)) setIsOpen(false);
184
- };
185
- document.addEventListener("mousedown", handler);
186
- return ()=>document.removeEventListener("mousedown", handler);
187
- }, [
188
- isOpen
189
- ]);
190
- const fullMarkdownUrl = useMemo(()=>"u" > typeof window ? new URL(pathname, window.location.origin).toString() : "", [
191
- pathname
192
- ]);
193
- const pageQ = `Read ${fullMarkdownUrl}, I want to ask questions about it.`;
194
- const pageItems = useMemo(()=>{
195
- const builtins = {
196
- markdownLink: {
197
- title: t("copyMarkdownLinkText"),
198
- icon: /*#__PURE__*/ jsx(LinkIcon, {}),
199
- onClick: ()=>copyText(fullMarkdownUrl)
200
- },
201
- chatgpt: {
202
- title: t("openInText", {
203
- name: "ChatGPT"
204
- }),
205
- href: `https://chatgpt.com/?${new URLSearchParams({
206
- hints: "search",
207
- q: pageQ
208
- })}`,
209
- icon: /*#__PURE__*/ jsx(ChatGPTIcon, {})
210
- },
211
- claude: {
212
- title: t("openInText", {
213
- name: "Claude"
214
- }),
215
- href: `https://claude.ai/new?${new URLSearchParams({
216
- q: pageQ
217
- })}`,
218
- icon: /*#__PURE__*/ jsx(ClaudeIcon, {})
219
- }
220
- };
221
- return options.map((opt)=>{
222
- if ("string" == typeof opt) return builtins[opt] ?? null;
223
- return opt;
224
- }).filter(Boolean);
225
- }, [
226
- options,
227
- fullMarkdownUrl,
228
- pageQ,
229
- t
230
- ]);
231
- const showFeedback = useCallback((msg)=>{
232
- setFeedback(msg);
233
- setTimeout(()=>setFeedback(null), 1500);
234
- }, []);
235
- const handleCopyDocs = useCallback(async ()=>{
236
- if (!activeScope) return;
237
- try {
238
- const res = await fetch(resolveUrl(activeScope.llmsDocsTxt));
239
- await copyText(await res.text());
240
- showFeedback("Copied!");
241
- } catch {
242
- showFeedback("Failed");
243
- }
244
- }, [
245
- activeScope,
246
- showFeedback
247
- ]);
248
- const handleCopyLink = useCallback(async (urlPath)=>{
249
- try {
250
- await copyText(resolveUrl(urlPath));
251
- showFeedback("Copied!");
252
- } catch {
253
- showFeedback("Failed");
254
- }
255
- }, [
256
- showFeedback
257
- ]);
258
- if (!pathname) return null;
259
- const packageItems = [];
260
- if (activeScope) {
261
- const pkgQ = `Read ${resolveUrl(activeScope.llmsTxt)}, I want to ask questions about the ${activeScope.name} package.`;
262
- packageItems.push({
263
- title: feedback ?? `Copy ${activeScope.name} docs`,
264
- icon: /*#__PURE__*/ jsx(CopyIcon, {}),
265
- onClick: handleCopyDocs
266
- }, {
267
- title: "Copy llms.txt link",
268
- icon: /*#__PURE__*/ jsx(LinkIcon, {}),
269
- onClick: ()=>handleCopyLink(activeScope.llmsTxt)
270
- }, {
271
- title: "Copy llms-full.txt link",
272
- icon: /*#__PURE__*/ jsx(LinkIcon, {}),
273
- onClick: ()=>handleCopyLink(activeScope.llmsFullTxt)
274
- }, {
275
- title: `Open ${activeScope.name} in ChatGPT`,
276
- href: `https://chatgpt.com/?${new URLSearchParams({
277
- hints: "search",
278
- q: pkgQ
279
- })}`,
280
- icon: /*#__PURE__*/ jsx(ChatGPTIcon, {})
281
- }, {
282
- title: `Open ${activeScope.name} in Claude`,
283
- href: `https://claude.ai/new?${new URLSearchParams({
284
- q: pkgQ
285
- })}`,
286
- icon: /*#__PURE__*/ jsx(ClaudeIcon, {})
287
- });
288
- }
289
- return /*#__PURE__*/ jsxs("button", {
290
- ref: dropdownRef,
291
- type: "button",
292
- className: `rp-llms-button rp-llms-view-options__trigger ${isOpen ? "rp-llms-view-options__trigger--active" : ""}`,
293
- onClick: ()=>setIsOpen(!isOpen),
294
- children: [
295
- /*#__PURE__*/ jsx(DownArrow, {
296
- className: `rp-llms-view-options__arrow ${isOpen ? "rp-llms-view-options__arrow--rotated" : ""}`
297
- }),
298
- isOpen && /*#__PURE__*/ jsxs("div", {
299
- className: "rp-llms-view-options__menu",
300
- children: [
301
- pageItems.map((item)=>/*#__PURE__*/ jsx(MenuItem, {
302
- item: item,
303
- onClose: ()=>setIsOpen(false)
304
- }, item.title)),
305
- packageItems.length > 0 && /*#__PURE__*/ jsxs(Fragment, {
306
- children: [
307
- /*#__PURE__*/ jsx("div", {
308
- style: {
309
- height: 1,
310
- margin: "4px 0",
311
- background: "var(--rp-c-divider)"
312
- }
313
- }),
314
- packageItems.map((item)=>/*#__PURE__*/ jsx(MenuItem, {
315
- item: item,
316
- onClose: ()=>setIsOpen(false)
317
- }, item.title))
318
- ]
319
- })
320
- ]
321
- })
322
- ]
323
- });
131
+ const { site } = useSite();
132
+ const { page } = usePage();
133
+ const { pathname } = useMdUrl();
134
+ const t = useI18n();
135
+ const [isOpen, setIsOpen] = useState(false);
136
+ const [feedback, setFeedback] = useState(null);
137
+ const dropdownRef = useRef(null);
138
+ const llmsUI = site?.themeConfig?.llmsUI;
139
+ const configOptions = typeof llmsUI === "object" ? llmsUI?.viewOptions : void 0;
140
+ const options = props.options ?? configOptions ?? [
141
+ "markdownLink",
142
+ "chatgpt",
143
+ "claude"
144
+ ];
145
+ const scopes = (site?.themeConfig)?.apiExtractorScopes ?? [];
146
+ const activeScope = useMemo(() => findScope(page.routePath, scopes), [page.routePath, scopes]);
147
+ useEffect(() => {
148
+ if (!isOpen) return;
149
+ const handler = (e) => {
150
+ if (dropdownRef.current && !dropdownRef.current.contains(e.target)) setIsOpen(false);
151
+ };
152
+ document.addEventListener("mousedown", handler);
153
+ return () => document.removeEventListener("mousedown", handler);
154
+ }, [isOpen]);
155
+ const fullMarkdownUrl = useMemo(() => typeof window !== "undefined" ? new URL(pathname, window.location.origin).toString() : "", [pathname]);
156
+ const pageQ = `Read ${fullMarkdownUrl}, I want to ask questions about it.`;
157
+ const pageItems = useMemo(() => {
158
+ const builtins = {
159
+ markdownLink: {
160
+ title: t("copyMarkdownLinkText"),
161
+ icon: /* @__PURE__ */ jsx(LinkIcon, {}),
162
+ onClick: () => copyText(fullMarkdownUrl)
163
+ },
164
+ chatgpt: {
165
+ title: t("openInText", { name: "ChatGPT" }),
166
+ href: `https://chatgpt.com/?${new URLSearchParams({
167
+ hints: "search",
168
+ q: pageQ
169
+ })}`,
170
+ icon: /* @__PURE__ */ jsx(ChatGPTIcon, {})
171
+ },
172
+ claude: {
173
+ title: t("openInText", { name: "Claude" }),
174
+ href: `https://claude.ai/new?${new URLSearchParams({ q: pageQ })}`,
175
+ icon: /* @__PURE__ */ jsx(ClaudeIcon, {})
176
+ }
177
+ };
178
+ return options.map((opt) => {
179
+ if (typeof opt === "string") return builtins[opt] ?? null;
180
+ return opt;
181
+ }).filter(Boolean);
182
+ }, [
183
+ options,
184
+ fullMarkdownUrl,
185
+ pageQ,
186
+ t
187
+ ]);
188
+ const showFeedback = useCallback((msg) => {
189
+ setFeedback(msg);
190
+ setTimeout(() => setFeedback(null), 1500);
191
+ }, []);
192
+ const handleCopyDocs = useCallback(async () => {
193
+ if (!activeScope) return;
194
+ try {
195
+ await copyText(await (await fetch(resolveUrl(activeScope.llmsDocsTxt))).text());
196
+ showFeedback("Copied!");
197
+ } catch {
198
+ showFeedback("Failed");
199
+ }
200
+ }, [activeScope, showFeedback]);
201
+ const handleCopyLink = useCallback(async (urlPath) => {
202
+ try {
203
+ await copyText(resolveUrl(urlPath));
204
+ showFeedback("Copied!");
205
+ } catch {
206
+ showFeedback("Failed");
207
+ }
208
+ }, [showFeedback]);
209
+ if (!pathname) return null;
210
+ const packageItems = [];
211
+ if (activeScope) {
212
+ const pkgQ = `Read ${resolveUrl(activeScope.llmsTxt)}, I want to ask questions about the ${activeScope.name} package.`;
213
+ packageItems.push({
214
+ title: feedback ?? `Copy ${activeScope.name} docs`,
215
+ icon: /* @__PURE__ */ jsx(CopyIcon, {}),
216
+ onClick: handleCopyDocs
217
+ }, {
218
+ title: "Copy llms.txt link",
219
+ icon: /* @__PURE__ */ jsx(LinkIcon, {}),
220
+ onClick: () => handleCopyLink(activeScope.llmsTxt)
221
+ }, {
222
+ title: "Copy llms-full.txt link",
223
+ icon: /* @__PURE__ */ jsx(LinkIcon, {}),
224
+ onClick: () => handleCopyLink(activeScope.llmsFullTxt)
225
+ }, {
226
+ title: `Open ${activeScope.name} in ChatGPT`,
227
+ href: `https://chatgpt.com/?${new URLSearchParams({
228
+ hints: "search",
229
+ q: pkgQ
230
+ })}`,
231
+ icon: /* @__PURE__ */ jsx(ChatGPTIcon, {})
232
+ }, {
233
+ title: `Open ${activeScope.name} in Claude`,
234
+ href: `https://claude.ai/new?${new URLSearchParams({ q: pkgQ })}`,
235
+ icon: /* @__PURE__ */ jsx(ClaudeIcon, {})
236
+ });
237
+ }
238
+ return /* @__PURE__ */ jsxs("button", {
239
+ ref: dropdownRef,
240
+ type: "button",
241
+ className: `rp-llms-button rp-llms-view-options__trigger ${isOpen ? "rp-llms-view-options__trigger--active" : ""}`,
242
+ onClick: () => setIsOpen(!isOpen),
243
+ children: [/* @__PURE__ */ jsx(DownArrow, { className: `rp-llms-view-options__arrow ${isOpen ? "rp-llms-view-options__arrow--rotated" : ""}` }), isOpen && /* @__PURE__ */ jsxs("div", {
244
+ className: "rp-llms-view-options__menu",
245
+ children: [pageItems.map((item) => /* @__PURE__ */ jsx(MenuItem, {
246
+ item,
247
+ onClose: () => setIsOpen(false)
248
+ }, item.title)), packageItems.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", { style: {
249
+ height: 1,
250
+ margin: "4px 0",
251
+ background: "var(--rp-c-divider)"
252
+ } }), packageItems.map((item) => /* @__PURE__ */ jsx(MenuItem, {
253
+ item,
254
+ onClose: () => setIsOpen(false)
255
+ }, item.title))] })]
256
+ })]
257
+ });
324
258
  }
325
259
  function MenuItem({ item, onClose }) {
326
- if (item.href) return /*#__PURE__*/ jsxs("a", {
327
- className: "rp-llms-view-options__menu-item",
328
- href: item.href,
329
- target: "_blank",
330
- rel: "noopener noreferrer",
331
- onClick: onClose,
332
- children: [
333
- /*#__PURE__*/ jsx("span", {
334
- className: "rp-llms-view-options__item-icon",
335
- children: item.icon
336
- }),
337
- /*#__PURE__*/ jsx("span", {
338
- children: item.title
339
- }),
340
- /*#__PURE__*/ jsx("span", {
341
- className: "rp-llms-view-options__external-icon",
342
- children: /*#__PURE__*/ jsx(ExternalLinkIcon, {})
343
- })
344
- ]
345
- });
346
- return /*#__PURE__*/ jsxs("button", {
347
- type: "button",
348
- className: "rp-llms-view-options__menu-item",
349
- onClick: (e)=>{
350
- e.stopPropagation();
351
- item.onClick?.();
352
- onClose();
353
- },
354
- children: [
355
- /*#__PURE__*/ jsx("span", {
356
- className: "rp-llms-view-options__item-icon",
357
- children: item.icon
358
- }),
359
- /*#__PURE__*/ jsx("span", {
360
- children: item.title
361
- })
362
- ]
363
- });
260
+ if (item.href) return /* @__PURE__ */ jsxs("a", {
261
+ className: "rp-llms-view-options__menu-item",
262
+ href: item.href,
263
+ target: "_blank",
264
+ rel: "noopener noreferrer",
265
+ onClick: onClose,
266
+ children: [
267
+ /* @__PURE__ */ jsx("span", {
268
+ className: "rp-llms-view-options__item-icon",
269
+ children: item.icon
270
+ }),
271
+ /* @__PURE__ */ jsx("span", { children: item.title }),
272
+ /* @__PURE__ */ jsx("span", {
273
+ className: "rp-llms-view-options__external-icon",
274
+ children: /* @__PURE__ */ jsx(ExternalLinkIcon, {})
275
+ })
276
+ ]
277
+ });
278
+ return /* @__PURE__ */ jsxs("button", {
279
+ type: "button",
280
+ className: "rp-llms-view-options__menu-item",
281
+ onClick: (e) => {
282
+ e.stopPropagation();
283
+ item.onClick?.();
284
+ onClose();
285
+ },
286
+ children: [/* @__PURE__ */ jsx("span", {
287
+ className: "rp-llms-view-options__item-icon",
288
+ children: item.icon
289
+ }), /* @__PURE__ */ jsx("span", { children: item.title })]
290
+ });
364
291
  }
365
- export { LlmsViewOptions };
292
+
293
+ //#endregion
294
+ export { LlmsViewOptions };