rspress-plugin-api-extractor 0.1.1 → 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 +2 -1
  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.js +11 -664
  46. package/runtime/utils/decode-hast.js +18 -0
  47. package/runtime/utils/hast-renderer.js +10 -0
  48. package/runtime/index.css +0 -1016
package/index.js CHANGED
@@ -5,9 +5,10 @@ import { fileURLToPath } from "node:url";
5
5
  import { NodeContext, NodeFileSystem } from "@effect/platform-node";
6
6
  import { Context, Data, Effect, Layer, LogLevel, Logger, ManagedRuntime, Metric, MetricBoundaries, Option, Schema, Stream } from "effect";
7
7
  import { FileSystem } from "@effect/platform";
8
- import { ApiDocumentedItem, ApiItemKind, ApiModel, ApiReleaseTagMixin, ReleaseTag } from "@microsoft/api-extractor-model";
8
+ import { ApiDocumentedItem, ApiItemKind, ApiModel } from "@microsoft/api-extractor-model";
9
9
  import gray_matter from "gray-matter";
10
10
  import { createHash } from "node:crypto";
11
+ import { CrossLinker, TypeSignatureFormatter, extractPlainText, getDeprecation, getExamples, getParams, getReleaseTag, getReturns, getSummary, hasModifierTag, loadApiModel } from "api-extractor-llms";
11
12
  import { format } from "prettier";
12
13
  import { imageSizeFromFile } from "image-size/fromFile";
13
14
  import { rendererRich, transformerTwoslash } from "@shikijs/twoslash";
@@ -145,14 +146,7 @@ const logBuildSummary = Effect.gen(function*() {
145
146
  });
146
147
  class ApiParser {
147
148
  static hasModifierTag(item, tagName) {
148
- if (item instanceof ApiDocumentedItem) {
149
- const tsdoc = item.tsdocComment;
150
- if (tsdoc?.modifierTagSet) {
151
- const modifierTags = tsdoc.modifierTagSet.nodes || [];
152
- for (const tag of modifierTags)if (tag.tagName === `@${tagName}`) return true;
153
- }
154
- }
155
- return false;
149
+ return hasModifierTag(item, tagName);
156
150
  }
157
151
  static categorizeApiItems(source, categories) {
158
152
  const items = {};
@@ -209,143 +203,25 @@ class ApiParser {
209
203
  return members;
210
204
  }
211
205
  static extractPlainText(node) {
212
- const parts = [];
213
- const nodeAny = node;
214
- if ("PlainText" === node.kind) return nodeAny.text || "";
215
- if ("SoftBreak" === node.kind) return " ";
216
- if ("CodeSpan" === node.kind) return `\`${nodeAny.code || ""}\``;
217
- if ("LinkTag" === node.kind) {
218
- if (nodeAny.linkText) return ApiParser.extractPlainText(nodeAny.linkText);
219
- if (nodeAny.codeDestination?.memberReferences?.[0]?.memberIdentifier) return nodeAny.codeDestination.memberReferences[0].memberIdentifier.identifier || "";
220
- return "";
221
- }
222
- if (node.getChildNodes && "function" == typeof node.getChildNodes) {
223
- const children = node.getChildNodes();
224
- for (const child of children){
225
- const childText = ApiParser.extractPlainText(child);
226
- if (childText) parts.push(childText);
227
- }
228
- }
229
- return parts.join("");
206
+ return extractPlainText(node);
230
207
  }
231
208
  static getSummary(item) {
232
- if (item instanceof ApiDocumentedItem) {
233
- const tsdoc = item.tsdocComment;
234
- if (tsdoc?.summarySection) {
235
- const summary = ApiParser.extractPlainText(tsdoc.summarySection);
236
- return summary.replace(/\s+/g, " ").trim();
237
- }
238
- }
239
- return "";
209
+ return getSummary(item);
240
210
  }
241
211
  static getReleaseTag(item) {
242
- if (ApiReleaseTagMixin.isBaseClassOf(item)) {
243
- const releaseTag = item.releaseTag;
244
- switch(releaseTag){
245
- case ReleaseTag.Public:
246
- break;
247
- case ReleaseTag.Beta:
248
- return "Beta";
249
- case ReleaseTag.Alpha:
250
- return "Alpha";
251
- case ReleaseTag.Internal:
252
- return "Internal";
253
- default:
254
- break;
255
- }
256
- }
257
- return "Public";
212
+ return getReleaseTag(item);
258
213
  }
259
214
  static getParams(item) {
260
- const paramList = [];
261
- const paramTypes = new Map();
262
- const parameters = item.parameters;
263
- if (parameters && Array.isArray(parameters)) for (const param of parameters){
264
- const paramExcerpt = param.parameterTypeExcerpt;
265
- if (paramExcerpt?.text) {
266
- const paramName = param.name || "";
267
- paramTypes.set(paramName, paramExcerpt.text.trim());
268
- }
269
- }
270
- if (item instanceof ApiDocumentedItem) {
271
- const tsdoc = item.tsdocComment;
272
- if (tsdoc?.params) {
273
- for (const paramBlock of tsdoc.params.blocks){
274
- const paramAny = paramBlock;
275
- const paramName = paramAny.parameterName || "";
276
- const description = ApiParser.extractPlainText(paramAny.content);
277
- const paramType = paramTypes.get(paramName);
278
- paramList.push({
279
- name: paramName,
280
- ...null != paramType ? {
281
- type: paramType
282
- } : {},
283
- description: description.replace(/\s+/g, " ").trim()
284
- });
285
- }
286
- return paramList;
287
- }
288
- }
289
- if (paramTypes.size > 0) for (const [name, type] of paramTypes.entries())paramList.push({
290
- name,
291
- type,
292
- description: ""
293
- });
294
- return paramList;
215
+ return getParams(item);
295
216
  }
296
217
  static getReturns(item) {
297
- if (item instanceof ApiDocumentedItem) {
298
- const tsdoc = item.tsdocComment;
299
- if (tsdoc?.returnsBlock) {
300
- const returnsAny = tsdoc.returnsBlock;
301
- const description = ApiParser.extractPlainText(returnsAny.content);
302
- return {
303
- description: description.replace(/\s+/g, " ").trim()
304
- };
305
- }
306
- }
307
- return null;
218
+ return getReturns(item);
308
219
  }
309
220
  static getExamples(item) {
310
- if (item instanceof ApiDocumentedItem) {
311
- const tsdoc = item.tsdocComment;
312
- const examples = [];
313
- for (const customBlock of tsdoc?.customBlocks || []){
314
- const blockTag = customBlock.blockTag;
315
- if (blockTag?.tagNameWithUpperCase === "@EXAMPLE") {
316
- const content = customBlock.content;
317
- for (const node of content.nodes || [])if ("FencedCode" === node.kind) {
318
- const fencedCode = node;
319
- examples.push({
320
- language: fencedCode.language || "typescript",
321
- code: fencedCode.code || ""
322
- });
323
- }
324
- if (0 === examples.length) {
325
- const text = ApiParser.extractPlainText(content);
326
- if (text.trim()) examples.push({
327
- language: "typescript",
328
- code: text.trim()
329
- });
330
- }
331
- }
332
- }
333
- return examples;
334
- }
335
- return [];
221
+ return getExamples(item);
336
222
  }
337
223
  static getDeprecation(item) {
338
- if (item instanceof ApiDocumentedItem) {
339
- const tsdoc = item.tsdocComment;
340
- if (tsdoc?.deprecatedBlock) {
341
- const deprecatedAny = tsdoc.deprecatedBlock;
342
- const message = ApiParser.extractPlainText(deprecatedAny.content);
343
- return {
344
- message: message.replace(/\s+/g, " ").trim()
345
- };
346
- }
347
- }
348
- return null;
224
+ return getDeprecation(item);
349
225
  }
350
226
  static getInheritance(item) {
351
227
  const result = {};
@@ -841,21 +717,14 @@ class MarkdownCrossLinker {
841
717
  for (const [name, route] of routes)this.apiItemRoutes.set(name, route);
842
718
  }
843
719
  addCrossLinks(text) {
844
- let result = text;
845
- const sortedNames = Array.from(this.apiItemRoutes.keys()).sort((a, b)=>b.length - a.length);
846
- for (const name of sortedNames){
847
- const route = this.apiItemRoutes.get(name);
848
- if (!route) continue;
849
- const regex = new RegExp(`\\b${name}\\b(?![a-zA-Z])`, "g");
850
- result = result.replace(regex, (match, offset)=>{
851
- const beforeMatch = result.substring(0, offset);
852
- if (beforeMatch.endsWith("](") || beforeMatch.endsWith("[")) return match;
853
- const backtickCount = (beforeMatch.match(/`/g) || []).length;
854
- if (backtickCount % 2 === 1) return match;
855
- return `[${match}](${route})`;
856
- });
857
- }
858
- return result;
720
+ if (0 === this.apiItemRoutes.size) return text;
721
+ const refs = Array.from(this.apiItemRoutes.keys()).map((name)=>({
722
+ name,
723
+ kind: "type",
724
+ slug: name.toLowerCase()
725
+ }));
726
+ const linker = new CrossLinker(refs, (ref)=>this.apiItemRoutes.get(ref.name) ?? "");
727
+ return linker.addLinks(text);
859
728
  }
860
729
  addCrossLinksHtml(text) {
861
730
  let result = text;
@@ -878,57 +747,13 @@ class MarkdownCrossLinker {
878
747
  }
879
748
  }
880
749
  const markdownCrossLinker = new MarkdownCrossLinker();
881
- class TypeSignatureFormatter {
882
- maxLineLength;
883
- indent;
750
+ class formatter_TypeSignatureFormatter extends TypeSignatureFormatter {
884
751
  apiItemRoutes;
885
752
  constructor(maxLineLength = 80, indent = " ", apiItemRoutes){
886
- this.maxLineLength = maxLineLength;
887
- this.indent = indent;
888
- this.apiItemRoutes = apiItemRoutes;
889
- }
890
- format(excerpt) {
891
- if (!excerpt.spannedTokens || 0 === excerpt.spannedTokens.length) return this.stripExportDeclare(excerpt.text);
892
- const tokens = excerpt.spannedTokens;
893
- let currentLine = "";
894
- const lines = [];
895
- let bracketDepth = 0;
896
- let lastTokenText = "";
897
- for(let i = 0; i < tokens.length; i++){
898
- const token = tokens[i];
899
- let tokenText = token.text;
900
- if (0 === i) tokenText = this.stripExportDeclare(tokenText);
901
- if ("" === tokenText.trim()) continue;
902
- if ("{" === tokenText || "[" === tokenText || "(" === tokenText) bracketDepth++;
903
- else if ("}" === tokenText || "]" === tokenText || ")" === tokenText) bracketDepth--;
904
- const isUnion = "|" === tokenText.trim();
905
- const isIntersection = "&" === tokenText.trim();
906
- const isOperator = isUnion || isIntersection;
907
- if (lastTokenText && this.needsSpaceBefore(lastTokenText, tokenText)) currentLine += " ";
908
- currentLine += tokenText;
909
- lastTokenText = tokenText;
910
- if (isOperator && 0 === bracketDepth && currentLine.length > this.maxLineLength && i < tokens.length - 1) {
911
- lines.push(currentLine.trimEnd());
912
- currentLine = this.indent;
913
- }
914
- }
915
- if (currentLine.trim()) lines.push(currentLine.trimEnd());
916
- if (lines.length <= 1) {
917
- let result = "";
918
- let lastNonEmptyTokenText = "";
919
- for(let i = 0; i < tokens.length; i++){
920
- const token = tokens[i];
921
- let tokenText = token.text;
922
- if (0 === i) tokenText = this.stripExportDeclare(tokenText);
923
- if ("" !== tokenText.trim()) {
924
- if (lastNonEmptyTokenText && this.needsSpaceBefore(lastNonEmptyTokenText, tokenText)) result += " ";
925
- result += tokenText;
926
- lastNonEmptyTokenText = tokenText;
927
- }
928
- }
929
- return result.trimStart();
930
- }
931
- return this.stripExportDeclare(lines.join("\n"));
753
+ super({
754
+ maxLineLength,
755
+ indent
756
+ }), this.apiItemRoutes = apiItemRoutes;
932
757
  }
933
758
  addLinks(text, excerpt) {
934
759
  if (!excerpt.spannedTokens || !this.apiItemRoutes) return text;
@@ -945,40 +770,12 @@ class TypeSignatureFormatter {
945
770
  }
946
771
  return result;
947
772
  }
948
- stripExportDeclare(text) {
949
- const trimmed = text.trim();
950
- let result = trimmed.replace(/^export\s+declare\s+/i, "").replace(/^export\s+/i, "").replace(/^declare\s+/i, "");
951
- result = result.replace(/\bexport\s+declare\s+/gi, "").replace(/\bexport\s+/gi, "").replace(/\bdeclare\s+/gi, "");
952
- return result;
953
- }
954
- needsSpaceBefore(prevText, currentText) {
955
- if (/\s$/.test(prevText)) return false;
956
- if (/^\s/.test(currentText)) return false;
957
- if (currentText.trim().startsWith("<")) return false;
958
- if (currentText.trim().match(/^[,;]/)) return false;
959
- if (prevText.trim().endsWith(",")) return true;
960
- if ("=" === currentText.trim() || currentText.trim().startsWith("=")) return true;
961
- if (prevText.trim().endsWith("=")) return true;
962
- if ("|" === currentText.trim() || "&" === currentText.trim()) return true;
963
- if ("|" === prevText.trim() || "&" === prevText.trim()) return true;
964
- if ("{" === prevText.trim() && "}" !== currentText.trim()) return true;
965
- if ("}" === currentText.trim() && "{" !== prevText.trim()) return true;
966
- if (prevText.trim().match(/^[[(]$/)) return false;
967
- if (currentText.trim().match(/^[\])]$/)) return false;
968
- if (prevText.trim().endsWith(":")) return true;
969
- if (prevText.trim().endsWith("?:")) return true;
970
- if (currentText.trim().startsWith(":") && !prevText.trim().match(/[,;:?]$/)) return false;
971
- if (currentText.trim().startsWith("{") && /[a-zA-Z0-9_>]$/.test(prevText.trim())) return true;
972
- const prevEndsAlphanumeric = /[a-zA-Z0-9_>]$/.test(prevText.trim());
973
- const currentStartsAlphanumeric = /^[a-zA-Z0-9_<]/.test(currentText.trim());
974
- return prevEndsAlphanumeric && currentStartsAlphanumeric;
975
- }
976
773
  escapeRegExp(string) {
977
774
  return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
978
775
  }
979
776
  }
980
777
  class ClassPageGenerator {
981
- typeFormatter = new TypeSignatureFormatter();
778
+ typeFormatter = new formatter_TypeSignatureFormatter();
982
779
  async generate(apiClass, baseRoute, packageName, singularName, apiScope, apiName, sourceConfig, suppressExampleErrors, llmsPlugin, availableFrom) {
983
780
  const shouldSuppressErrors = suppressExampleErrors ?? true;
984
781
  const name = apiClass.displayName;
@@ -1364,7 +1161,7 @@ class EnumPageGenerator {
1364
1161
  }
1365
1162
  }
1366
1163
  class FunctionPageGenerator {
1367
- typeFormatter = new TypeSignatureFormatter();
1164
+ typeFormatter = new formatter_TypeSignatureFormatter();
1368
1165
  async generate(apiFunction, baseRoute, packageName, singularName, apiScope, apiName, sourceConfig, suppressExampleErrors, llmsPlugin, availableFrom) {
1369
1166
  const shouldSuppressErrors = suppressExampleErrors ?? true;
1370
1167
  const name = apiFunction.displayName;
@@ -1468,7 +1265,7 @@ overview: true
1468
1265
  }
1469
1266
  }
1470
1267
  class InterfacePageGenerator {
1471
- typeFormatter = new TypeSignatureFormatter();
1268
+ typeFormatter = new formatter_TypeSignatureFormatter();
1472
1269
  async generate(apiInterface, baseRoute, packageName, singularName, apiScope, apiName, sourceConfig, suppressExampleErrors, llmsPlugin, availableFrom) {
1473
1270
  const shouldSuppressErrors = suppressExampleErrors ?? true;
1474
1271
  const name = apiInterface.displayName;
@@ -1707,7 +1504,7 @@ class InterfacePageGenerator {
1707
1504
  }
1708
1505
  }
1709
1506
  class NamespacePageGenerator {
1710
- typeFormatter = new TypeSignatureFormatter();
1507
+ typeFormatter = new formatter_TypeSignatureFormatter();
1711
1508
  async generate(apiNamespace, baseRoute, packageName, singularName, apiScope, apiName, sourceConfig, suppressExampleErrors, llmsPlugin, availableFrom) {
1712
1509
  const shouldSuppressErrors = suppressExampleErrors ?? true;
1713
1510
  const name = apiNamespace.displayName;
@@ -1910,7 +1707,7 @@ class NamespacePageGenerator {
1910
1707
  }
1911
1708
  }
1912
1709
  class TypeAliasPageGenerator {
1913
- typeFormatter = new TypeSignatureFormatter();
1710
+ typeFormatter = new formatter_TypeSignatureFormatter();
1914
1711
  async generate(apiTypeAlias, baseRoute, packageName, singularName, apiScope, apiName, sourceConfig, suppressExampleErrors, llmsPlugin, availableFrom) {
1915
1712
  const shouldSuppressErrors = suppressExampleErrors ?? true;
1916
1713
  const name = apiTypeAlias.displayName;
@@ -1984,7 +1781,7 @@ class TypeAliasPageGenerator {
1984
1781
  }
1985
1782
  }
1986
1783
  class VariablePageGenerator {
1987
- typeFormatter = new TypeSignatureFormatter();
1784
+ typeFormatter = new formatter_TypeSignatureFormatter();
1988
1785
  async generate(apiVariable, baseRoute, packageName, singularName, apiScope, apiName, sourceConfig, suppressExampleErrors, llmsPlugin, availableFrom) {
1989
1786
  const shouldSuppressErrors = suppressExampleErrors ?? true;
1990
1787
  const name = apiVariable.displayName;
@@ -4172,10 +3969,9 @@ async function generateShikiHast(code, highlighter, transformers, enableTwoslash
4172
3969
  }
4173
3970
  class ApiModelLoader {
4174
3971
  static async loadFromPath(modelPath) {
4175
- const apiModel = new ApiModel();
4176
3972
  const resolvedPath = node_path.resolve(modelPath.toString());
4177
3973
  if (!node_fs.existsSync(resolvedPath)) throw new Error(`API model file not found: ${resolvedPath}`);
4178
- return apiModel.loadPackage(resolvedPath);
3974
+ return loadApiModel(resolvedPath);
4179
3975
  }
4180
3976
  static async loadPackageJsonFromPath(pkgPath) {
4181
3977
  const resolvedPath = node_path.resolve(pkgPath.toString());
@@ -6267,7 +6063,7 @@ function ApiExtractorPluginImpl(rawOptions) {
6267
6063
  if (rspressLlmsEnabled && resolvedLlmsPlugin.enabled && resolvedLlmsPlugin.scopes) {
6268
6064
  if (!updatedConfig.builderConfig.resolve) updatedConfig.builderConfig.resolve = {};
6269
6065
  const pluginDir = node_path.dirname(fileURLToPath(import.meta.url));
6270
- const customLlmsViewOptions = node_path.resolve(pluginDir, "../../src/runtime/components/ApiLlmsViewOptions/index.tsx");
6066
+ const customLlmsViewOptions = node_path.resolve(pluginDir, "runtime/components/ApiLlmsViewOptions/index.js");
6271
6067
  const pluginRequire = createRequire(import.meta.url);
6272
6068
  const rspressCoreDir = node_path.dirname(pluginRequire.resolve("@rspress/core/package.json"));
6273
6069
  const originalLlmsViewOptions = node_path.join(rspressCoreDir, "dist/theme/components/Llms/LlmsViewOptions.js");
@@ -6317,7 +6113,7 @@ function ApiExtractorPluginImpl(rawOptions) {
6317
6113
  updatedConfig.themeConfig.apiExtractorScopes = scopes;
6318
6114
  if (!updatedConfig.globalUIComponents) updatedConfig.globalUIComponents = [];
6319
6115
  const llmsComponentPluginDir = node_path.dirname(fileURLToPath(import.meta.url));
6320
- const llmsComponentPath = node_path.resolve(llmsComponentPluginDir, "../../src/runtime/components/ApiLlmsPackageActions/index.tsx");
6116
+ const llmsComponentPath = node_path.resolve(llmsComponentPluginDir, "runtime/components/ApiLlmsPackageActions/index.js");
6321
6117
  updatedConfig.globalUIComponents.push(llmsComponentPath);
6322
6118
  }
6323
6119
  return updatedConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rspress-plugin-api-extractor",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "description": "RSPress plugin for generating API documentation from TypeScript API Extractor models",
6
6
  "keywords": [
@@ -49,6 +49,7 @@
49
49
  "@effect/sql-sqlite-node": "^0.52.0",
50
50
  "@microsoft/api-extractor-model": "^7.33.8",
51
51
  "@shikijs/twoslash": "^4.1.0",
52
+ "api-extractor-llms": "0.1.0",
52
53
  "clsx": "^2.1.1",
53
54
  "effect": "^3.21.2",
54
55
  "gray-matter": "^4.0.3",
@@ -0,0 +1,29 @@
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ import { createElement, useMemo } from "react";
3
+ import { decodeHast } from "../../utils/decode-hast.js";
4
+ import { ExampleBlock } from "../ExampleBlock/index.js";
5
+ function ApiExample({ code, hast }) {
6
+ const parsedHast = useMemo(()=>decodeHast(hast, "ApiExample"), [
7
+ hast
8
+ ]);
9
+ if (import.meta.env.SSG_MD) {
10
+ const header = "```typescript\n";
11
+ const footer = "\n```\n";
12
+ return /*#__PURE__*/ jsx(Fragment, {
13
+ children: `${header}${code.trim()}${footer}`
14
+ });
15
+ }
16
+ if (parsedHast) return /*#__PURE__*/ createElement(ExampleBlock, {
17
+ hast: parsedHast,
18
+ code: code.trim()
19
+ });
20
+ return /*#__PURE__*/ jsx("pre", {
21
+ children: /*#__PURE__*/ jsx("code", {
22
+ className: "language-typescript",
23
+ children: code.trim()
24
+ })
25
+ });
26
+ }
27
+ const components_ApiExample = ApiExample;
28
+ export default components_ApiExample;
29
+ export { ApiExample };