@depup/nextra 4.6.1-depup.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 (293) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -0
  3. package/changes.json +110 -0
  4. package/dist/client/components/banner/close-banner-button.d.ts +8 -0
  5. package/dist/client/components/banner/close-banner-button.js +45 -0
  6. package/dist/client/components/banner/index.client.d.ts +5 -0
  7. package/dist/client/components/banner/index.client.js +46 -0
  8. package/dist/client/components/banner/index.d.ts +51 -0
  9. package/dist/client/components/banner/index.js +93 -0
  10. package/dist/client/components/bleed.d.ts +63 -0
  11. package/dist/client/components/bleed.js +54 -0
  12. package/dist/client/components/button.d.ts +9 -0
  13. package/dist/client/components/button.js +55 -0
  14. package/dist/client/components/callout.d.ts +136 -0
  15. package/dist/client/components/callout.js +99 -0
  16. package/dist/client/components/cards.d.ts +104 -0
  17. package/dist/client/components/cards.js +132 -0
  18. package/dist/client/components/collapse.d.ts +12 -0
  19. package/dist/client/components/collapse.js +143 -0
  20. package/dist/client/components/file-tree/file.d.ts +9 -0
  21. package/dist/client/components/file-tree/file.js +43 -0
  22. package/dist/client/components/file-tree/folder.d.ts +12 -0
  23. package/dist/client/components/file-tree/folder.js +94 -0
  24. package/dist/client/components/file-tree/index.d.ts +57 -0
  25. package/dist/client/components/file-tree/index.js +12 -0
  26. package/dist/client/components/file-tree/tree.d.ts +5 -0
  27. package/dist/client/components/file-tree/tree.js +41 -0
  28. package/dist/client/components/head.d.ts +139 -0
  29. package/dist/client/components/head.js +202 -0
  30. package/dist/client/components/image-zoom.d.ts +6 -0
  31. package/dist/client/components/image-zoom.js +79 -0
  32. package/dist/client/components/index.d.ts +56 -0
  33. package/dist/client/components/index.js +42 -0
  34. package/dist/client/components/playground.d.ts +90 -0
  35. package/dist/client/components/playground.js +103 -0
  36. package/dist/client/components/popup/index.client.d.ts +7 -0
  37. package/dist/client/components/popup/index.client.js +83 -0
  38. package/dist/client/components/popup/index.d.ts +12 -0
  39. package/dist/client/components/popup/index.js +11 -0
  40. package/dist/client/components/search.d.ts +88 -0
  41. package/dist/client/components/search.js +426 -0
  42. package/dist/client/components/select.d.ts +19 -0
  43. package/dist/client/components/select.js +109 -0
  44. package/dist/client/components/skip-nav/index.client.d.ts +5 -0
  45. package/dist/client/components/skip-nav/index.client.js +45 -0
  46. package/dist/client/components/skip-nav/index.d.ts +6 -0
  47. package/dist/client/components/skip-nav/index.js +24 -0
  48. package/dist/client/components/steps.d.ts +64 -0
  49. package/dist/client/components/steps.js +74 -0
  50. package/dist/client/components/tabs/index.client.d.ts +21 -0
  51. package/dist/client/components/tabs/index.client.js +243 -0
  52. package/dist/client/components/tabs/index.d.ts +53 -0
  53. package/dist/client/components/tabs/index.js +9 -0
  54. package/dist/client/evaluate.d.ts +30 -0
  55. package/dist/client/evaluate.js +17 -0
  56. package/dist/client/hocs/index.d.ts +4 -0
  57. package/dist/client/hocs/index.js +6 -0
  58. package/dist/client/hocs/with-github-alert.d.ts +11 -0
  59. package/dist/client/hocs/with-github-alert.js +30 -0
  60. package/dist/client/hocs/with-icons.d.ts +6 -0
  61. package/dist/client/hocs/with-icons.js +76 -0
  62. package/dist/client/hooks/index.d.ts +4 -0
  63. package/dist/client/hooks/index.js +10 -0
  64. package/dist/client/hooks/use-copy.d.ts +9 -0
  65. package/dist/client/hooks/use-copy.js +77 -0
  66. package/dist/client/hooks/use-fs-route.d.ts +3 -0
  67. package/dist/client/hooks/use-fs-route.js +20 -0
  68. package/dist/client/hooks/use-hash.d.ts +3 -0
  69. package/dist/client/hooks/use-hash.js +20 -0
  70. package/dist/client/hooks/use-mounted.d.ts +3 -0
  71. package/dist/client/hooks/use-mounted.js +13 -0
  72. package/dist/client/icons/arrow-right.d.ts +5 -0
  73. package/dist/client/icons/arrow-right.js +24 -0
  74. package/dist/client/icons/chatgpt.d.ts +2 -0
  75. package/dist/client/icons/chatgpt.js +24 -0
  76. package/dist/client/icons/check.d.ts +2 -0
  77. package/dist/client/icons/check.js +24 -0
  78. package/dist/client/icons/claude.d.ts +2 -0
  79. package/dist/client/icons/claude.js +81 -0
  80. package/dist/client/icons/copy.d.ts +2 -0
  81. package/dist/client/icons/copy.js +31 -0
  82. package/dist/client/icons/cpp.d.ts +2 -0
  83. package/dist/client/icons/cpp.js +24 -0
  84. package/dist/client/icons/cross-circled.d.ts +2 -0
  85. package/dist/client/icons/cross-circled.js +24 -0
  86. package/dist/client/icons/csharp.d.ts +2 -0
  87. package/dist/client/icons/csharp.js +24 -0
  88. package/dist/client/icons/css.d.ts +2 -0
  89. package/dist/client/icons/css.js +24 -0
  90. package/dist/client/icons/discord.d.ts +2 -0
  91. package/dist/client/icons/discord.js +24 -0
  92. package/dist/client/icons/expand.d.ts +2 -0
  93. package/dist/client/icons/expand.js +31 -0
  94. package/dist/client/icons/file.d.ts +2 -0
  95. package/dist/client/icons/file.js +24 -0
  96. package/dist/client/icons/folder-open.d.ts +2 -0
  97. package/dist/client/icons/folder-open.js +24 -0
  98. package/dist/client/icons/folder.d.ts +2 -0
  99. package/dist/client/icons/folder.js +24 -0
  100. package/dist/client/icons/github-caution.d.ts +2 -0
  101. package/dist/client/icons/github-caution.js +24 -0
  102. package/dist/client/icons/github-important.d.ts +2 -0
  103. package/dist/client/icons/github-important.js +24 -0
  104. package/dist/client/icons/github-note.d.ts +2 -0
  105. package/dist/client/icons/github-note.js +24 -0
  106. package/dist/client/icons/github-tip.d.ts +2 -0
  107. package/dist/client/icons/github-tip.js +24 -0
  108. package/dist/client/icons/github-warning.d.ts +2 -0
  109. package/dist/client/icons/github-warning.js +24 -0
  110. package/dist/client/icons/github.d.ts +2 -0
  111. package/dist/client/icons/github.js +24 -0
  112. package/dist/client/icons/globe.d.ts +2 -0
  113. package/dist/client/icons/globe.js +24 -0
  114. package/dist/client/icons/go.d.ts +2 -0
  115. package/dist/client/icons/go.js +46 -0
  116. package/dist/client/icons/graphql.d.ts +2 -0
  117. package/dist/client/icons/graphql.js +56 -0
  118. package/dist/client/icons/index.d.ts +2 -0
  119. package/dist/client/icons/index.js +92 -0
  120. package/dist/client/icons/javascript.d.ts +2 -0
  121. package/dist/client/icons/javascript.js +24 -0
  122. package/dist/client/icons/json.d.ts +2 -0
  123. package/dist/client/icons/json.js +41 -0
  124. package/dist/client/icons/link-arrow.d.ts +2 -0
  125. package/dist/client/icons/link-arrow.js +31 -0
  126. package/dist/client/icons/link.d.ts +2 -0
  127. package/dist/client/icons/link.js +24 -0
  128. package/dist/client/icons/markdown.d.ts +2 -0
  129. package/dist/client/icons/markdown.js +24 -0
  130. package/dist/client/icons/mdx.d.ts +2 -0
  131. package/dist/client/icons/mdx.js +24 -0
  132. package/dist/client/icons/menu.d.ts +2 -0
  133. package/dist/client/icons/menu.js +36 -0
  134. package/dist/client/icons/moon.d.ts +2 -0
  135. package/dist/client/icons/moon.js +24 -0
  136. package/dist/client/icons/move.d.ts +2 -0
  137. package/dist/client/icons/move.js +24 -0
  138. package/dist/client/icons/python.d.ts +2 -0
  139. package/dist/client/icons/python.js +31 -0
  140. package/dist/client/icons/react.d.ts +2 -0
  141. package/dist/client/icons/react.js +38 -0
  142. package/dist/client/icons/rust.d.ts +2 -0
  143. package/dist/client/icons/rust.js +31 -0
  144. package/dist/client/icons/spinner.d.ts +2 -0
  145. package/dist/client/icons/spinner.js +31 -0
  146. package/dist/client/icons/sun.d.ts +2 -0
  147. package/dist/client/icons/sun.js +24 -0
  148. package/dist/client/icons/svelte.d.ts +2 -0
  149. package/dist/client/icons/svelte.js +31 -0
  150. package/dist/client/icons/terminal.d.ts +2 -0
  151. package/dist/client/icons/terminal.js +24 -0
  152. package/dist/client/icons/terraform.d.ts +2 -0
  153. package/dist/client/icons/terraform.js +24 -0
  154. package/dist/client/icons/typescript.d.ts +2 -0
  155. package/dist/client/icons/typescript.js +24 -0
  156. package/dist/client/icons/word-wrap.d.ts +2 -0
  157. package/dist/client/icons/word-wrap.js +24 -0
  158. package/dist/client/icons/x.d.ts +2 -0
  159. package/dist/client/icons/x.js +24 -0
  160. package/dist/client/mdx-components/anchor.d.ts +10 -0
  161. package/dist/client/mdx-components/anchor.js +109 -0
  162. package/dist/client/mdx-components/code.d.ts +7 -0
  163. package/dist/client/mdx-components/code.js +52 -0
  164. package/dist/client/mdx-components/details.d.ts +5 -0
  165. package/dist/client/mdx-components/details.js +166 -0
  166. package/dist/client/mdx-components/image.d.ts +28 -0
  167. package/dist/client/mdx-components/image.js +39 -0
  168. package/dist/client/mdx-components/index.d.ts +11 -0
  169. package/dist/client/mdx-components/index.js +16 -0
  170. package/dist/client/mdx-components/pre/copy-to-clipboard.d.ts +5 -0
  171. package/dist/client/mdx-components/pre/copy-to-clipboard.js +49 -0
  172. package/dist/client/mdx-components/pre/index.d.ts +16 -0
  173. package/dist/client/mdx-components/pre/index.js +156 -0
  174. package/dist/client/mdx-components/pre/toggle-word-wrap-button.d.ts +7 -0
  175. package/dist/client/mdx-components/pre/toggle-word-wrap-button.js +31 -0
  176. package/dist/client/mdx-components/summary.d.ts +5 -0
  177. package/dist/client/mdx-components/summary.js +80 -0
  178. package/dist/client/mdx-components/table.d.ts +57 -0
  179. package/dist/client/mdx-components/table.js +95 -0
  180. package/dist/client/mdx-components.d.ts +89 -0
  181. package/dist/client/mdx-components.js +15 -0
  182. package/dist/client/mdx-remote.d.ts +62 -0
  183. package/dist/client/mdx-remote.js +36 -0
  184. package/dist/client/normalize-pages.d.ts +84 -0
  185. package/dist/client/normalize-pages.js +232 -0
  186. package/dist/client/package.json +1 -0
  187. package/dist/client/pages.d.ts +131 -0
  188. package/dist/client/pages.js +39 -0
  189. package/dist/client/remove-links.d.ts +6 -0
  190. package/dist/client/remove-links.js +35 -0
  191. package/dist/client/setup-page.d.ts +18 -0
  192. package/dist/client/setup-page.js +14 -0
  193. package/dist/server/compile-metadata.d.ts +12 -0
  194. package/dist/server/compile-metadata.js +39 -0
  195. package/dist/server/compile.d.ts +39 -0
  196. package/dist/server/compile.js +158 -0
  197. package/dist/server/constants.d.ts +15 -0
  198. package/dist/server/constants.js +22 -0
  199. package/dist/server/fetch-filepaths-from-github.d.ts +10 -0
  200. package/dist/server/fetch-filepaths-from-github.js +36 -0
  201. package/dist/server/index.d.ts +39 -0
  202. package/dist/server/index.js +203 -0
  203. package/dist/server/loader.d.ts +18 -0
  204. package/dist/server/loader.js +155 -0
  205. package/dist/server/locales.d.ts +22 -0
  206. package/dist/server/locales.js +38 -0
  207. package/dist/server/page-map/find-meta-and-page-file-paths.d.ts +8 -0
  208. package/dist/server/page-map/find-meta-and-page-file-paths.js +32 -0
  209. package/dist/server/page-map/get.d.ts +50 -0
  210. package/dist/server/page-map/get.js +28 -0
  211. package/dist/server/page-map/index-page.d.ts +21 -0
  212. package/dist/server/page-map/index-page.js +57 -0
  213. package/dist/server/page-map/index.d.ts +26 -0
  214. package/dist/server/page-map/index.js +24 -0
  215. package/dist/server/page-map/merge-meta-with-page-map.d.ts +17 -0
  216. package/dist/server/page-map/merge-meta-with-page-map.js +74 -0
  217. package/dist/server/page-map/normalize.d.ts +17 -0
  218. package/dist/server/page-map/normalize.js +122 -0
  219. package/dist/server/page-map/placeholder.d.ts +2 -0
  220. package/dist/server/page-map/placeholder.js +0 -0
  221. package/dist/server/page-map/to-ast.d.ts +18 -0
  222. package/dist/server/page-map/to-ast.js +47 -0
  223. package/dist/server/page-map/to-js.d.ts +21 -0
  224. package/dist/server/page-map/to-js.js +72 -0
  225. package/dist/server/page-map/to-page-map.d.ts +26 -0
  226. package/dist/server/page-map/to-page-map.js +101 -0
  227. package/dist/server/recma-plugins/index.d.ts +3 -0
  228. package/dist/server/recma-plugins/index.js +4 -0
  229. package/dist/server/recma-plugins/recma-rewrite.d.ts +11 -0
  230. package/dist/server/recma-plugins/recma-rewrite.js +98 -0
  231. package/dist/server/rehype-plugins/index.d.ts +18 -0
  232. package/dist/server/rehype-plugins/index.js +16 -0
  233. package/dist/server/rehype-plugins/rehype-better-react-mathjax.d.ts +24 -0
  234. package/dist/server/rehype-plugins/rehype-better-react-mathjax.js +96 -0
  235. package/dist/server/rehype-plugins/rehype-extract-toc-content.d.ts +6 -0
  236. package/dist/server/rehype-plugins/rehype-extract-toc-content.js +119 -0
  237. package/dist/server/rehype-plugins/rehype-twoslash-popup.d.ts +6 -0
  238. package/dist/server/rehype-plugins/rehype-twoslash-popup.js +50 -0
  239. package/dist/server/rehype-plugins/rehype.d.ts +21 -0
  240. package/dist/server/rehype-plugins/rehype.js +84 -0
  241. package/dist/server/remark-plugins/index.d.ts +15 -0
  242. package/dist/server/remark-plugins/index.js +26 -0
  243. package/dist/server/remark-plugins/remark-assign-frontmatter.d.ts +10 -0
  244. package/dist/server/remark-plugins/remark-assign-frontmatter.js +24 -0
  245. package/dist/server/remark-plugins/remark-custom-heading-id.d.ts +9 -0
  246. package/dist/server/remark-plugins/remark-custom-heading-id.js +18 -0
  247. package/dist/server/remark-plugins/remark-export-only-metadata.d.ts +6 -0
  248. package/dist/server/remark-plugins/remark-export-only-metadata.js +18 -0
  249. package/dist/server/remark-plugins/remark-export-source-code.d.ts +6 -0
  250. package/dist/server/remark-plugins/remark-export-source-code.js +35 -0
  251. package/dist/server/remark-plugins/remark-headings.d.ts +12 -0
  252. package/dist/server/remark-plugins/remark-headings.js +133 -0
  253. package/dist/server/remark-plugins/remark-link-rewrite.d.ts +11 -0
  254. package/dist/server/remark-plugins/remark-link-rewrite.js +12 -0
  255. package/dist/server/remark-plugins/remark-mdx-disable-explicit-jsx.d.ts +10 -0
  256. package/dist/server/remark-plugins/remark-mdx-disable-explicit-jsx.js +10 -0
  257. package/dist/server/remark-plugins/remark-mdx-frontmatter.d.ts +6 -0
  258. package/dist/server/remark-plugins/remark-mdx-frontmatter.js +37 -0
  259. package/dist/server/remark-plugins/remark-mdx-title.d.ts +10 -0
  260. package/dist/server/remark-plugins/remark-mdx-title.js +53 -0
  261. package/dist/server/remark-plugins/remark-remove-imports.d.ts +6 -0
  262. package/dist/server/remark-plugins/remark-remove-imports.js +12 -0
  263. package/dist/server/remark-plugins/remark-static-image.d.ts +6 -0
  264. package/dist/server/remark-plugins/remark-static-image.js +107 -0
  265. package/dist/server/schemas.d.ts +352 -0
  266. package/dist/server/schemas.js +240 -0
  267. package/dist/server/tsdoc/base.d.ts +38 -0
  268. package/dist/server/tsdoc/base.js +284 -0
  269. package/dist/server/tsdoc/index.d.ts +6 -0
  270. package/dist/server/tsdoc/index.js +10 -0
  271. package/dist/server/tsdoc/tsdoc.d.ts +102 -0
  272. package/dist/server/tsdoc/tsdoc.js +262 -0
  273. package/dist/server/tsdoc/types.d.ts +64 -0
  274. package/dist/server/tsdoc/types.js +0 -0
  275. package/dist/server/tsdoc/zod-to-ts.d.ts +5 -0
  276. package/dist/server/tsdoc/zod-to-ts.js +107 -0
  277. package/dist/server/twoslash.d.ts +6 -0
  278. package/dist/server/twoslash.js +60 -0
  279. package/dist/server/utils.d.ts +12 -0
  280. package/dist/server/utils.js +45 -0
  281. package/dist/types.d.ts +128 -0
  282. package/dist/types.generated.d.ts +203 -0
  283. package/dist/types.generated.js +0 -0
  284. package/dist/types.js +0 -0
  285. package/loader.cjs +24 -0
  286. package/package.json +265 -0
  287. package/styles/cards.css +24 -0
  288. package/styles/code-block.css +266 -0
  289. package/styles/default.css +55 -0
  290. package/styles/react-medium-image-zoom.css +101 -0
  291. package/styles/scrollbar.css +14 -0
  292. package/styles/steps.css +22 -0
  293. package/styles/subheading-anchor.css +25 -0
@@ -0,0 +1,133 @@
1
+ import Slugger from "github-slugger";
2
+ import { visit } from "unist-util-visit";
3
+ import { visitChildren } from "unist-util-visit-children";
4
+ import { MARKDOWN_EXTENSION_RE } from "../constants.js";
5
+ import { createAstObject } from "../utils.js";
6
+ const getFlattenedValue = (node) => node.children.map(
7
+ (child) => "children" in child ? getFlattenedValue(child) : "value" in child ? child.value : ""
8
+ ).join("");
9
+ const remarkHeadings = ({ exportName = "toc", isRemoteContent }) => {
10
+ const headings = [];
11
+ const slugger = new Slugger();
12
+ return (ast, file) => {
13
+ const PartialComponentToHeadingsName = /* @__PURE__ */ Object.create(null);
14
+ visit(
15
+ ast,
16
+ [
17
+ "heading",
18
+ // push partial component's `toc` export name to headings list
19
+ "mdxJsxFlowElement",
20
+ // verify .md/.mdx exports and attach named `toc` export
21
+ "mdxjsEsm"
22
+ ],
23
+ (node, index, parent) => {
24
+ if (node.type === "heading") {
25
+ if (node.depth === 1) {
26
+ return;
27
+ }
28
+ node.data ||= {};
29
+ const headingProps = node.data.hProperties ||= {};
30
+ const value = getFlattenedValue(node);
31
+ const id = slugger.slug(headingProps.id || value);
32
+ headingProps.id = id;
33
+ headings.push({ depth: node.depth, value, id });
34
+ return;
35
+ }
36
+ const isTab = node.type === "mdxJsxFlowElement" && node.name === "Tabs.Tab";
37
+ if (isTab) {
38
+ const itemsAttr = parent?.type === "mdxJsxFlowElement" && parent.name === "Tabs" && parent.attributes.find(
39
+ (attr) => attr.type === "mdxJsxAttribute" && attr.name === "items"
40
+ );
41
+ if (!itemsAttr) return;
42
+ const tabName = itemsAttr.value.data.estree.body[0].expression.elements.map(
43
+ (el) => el.value
44
+ )[index];
45
+ const id = slugger.slug(tabName);
46
+ node.children.unshift({
47
+ type: "mdxJsxFlowElement",
48
+ name: "h3",
49
+ data: { _mdxExplicitJsx: true },
50
+ children: [{ type: "text", value: tabName }],
51
+ attributes: [
52
+ { type: "mdxJsxAttribute", name: "id", value: id },
53
+ {
54
+ type: "mdxJsxAttribute",
55
+ name: "style",
56
+ value: {
57
+ type: "mdxJsxAttributeValueExpression",
58
+ value: "",
59
+ data: {
60
+ estree: {
61
+ type: "Program",
62
+ sourceType: "module",
63
+ comments: [],
64
+ body: [
65
+ {
66
+ type: "ExpressionStatement",
67
+ expression: createAstObject({
68
+ visibility: "hidden",
69
+ width: 0,
70
+ height: 0
71
+ })
72
+ }
73
+ ]
74
+ }
75
+ }
76
+ }
77
+ }
78
+ ]
79
+ });
80
+ }
81
+ const isDetails = node.type === "mdxJsxFlowElement" && node.name === "details";
82
+ if (isDetails) {
83
+ const visitor = visitChildren((node2) => {
84
+ const isSummary = node2.type === "mdxJsxTextElement" && node2.name === "summary";
85
+ if (isSummary) {
86
+ const value = getFlattenedValue(node2);
87
+ const id = slugger.slug(value);
88
+ node2.attributes.push({
89
+ type: "mdxJsxAttribute",
90
+ name: "id",
91
+ value: id
92
+ });
93
+ } else if ("children" in node2) {
94
+ visitor(node2);
95
+ }
96
+ });
97
+ visitor(node);
98
+ }
99
+ if (isRemoteContent) {
100
+ } else if (node.type === "mdxjsEsm") {
101
+ for (const child of node.data.estree.body) {
102
+ if (child.type !== "ImportDeclaration") continue;
103
+ const importPath = child.source.value;
104
+ const isMdxImport = MARKDOWN_EXTENSION_RE.test(importPath);
105
+ if (!isMdxImport) continue;
106
+ const componentName = child.specifiers.find(
107
+ (o) => o.type === "ImportDefaultSpecifier"
108
+ )?.local.name;
109
+ if (!componentName) continue;
110
+ const { length } = Object.keys(PartialComponentToHeadingsName);
111
+ const exportAsName = `${exportName}${length}`;
112
+ PartialComponentToHeadingsName[componentName] = exportAsName;
113
+ child.specifiers.push({
114
+ type: "ImportSpecifier",
115
+ imported: { type: "Identifier", name: exportName },
116
+ local: { type: "Identifier", name: exportAsName }
117
+ });
118
+ }
119
+ } else {
120
+ const headingsName = PartialComponentToHeadingsName[node.name];
121
+ if (headingsName) {
122
+ headings.push(headingsName);
123
+ }
124
+ }
125
+ }
126
+ );
127
+ file.data.toc = headings;
128
+ };
129
+ };
130
+ export {
131
+ getFlattenedValue,
132
+ remarkHeadings
133
+ };
@@ -0,0 +1,11 @@
1
+ import { Root } from 'mdast';
2
+ import { Plugin } from './lib/index.js';
3
+
4
+ type RemarkLinkRewriteOptions = {
5
+ pattern: RegExp;
6
+ replace: string;
7
+ excludeExternalLinks?: boolean;
8
+ };
9
+ declare const remarkLinkRewrite: Plugin<[RemarkLinkRewriteOptions], Root>;
10
+
11
+ export { type RemarkLinkRewriteOptions, remarkLinkRewrite };
@@ -0,0 +1,12 @@
1
+ import { visit } from "unist-util-visit";
2
+ import { EXTERNAL_URL_RE } from "../constants.js";
3
+ const remarkLinkRewrite = ({ pattern, replace, excludeExternalLinks }) => (ast) => {
4
+ visit(ast, "link", (node) => {
5
+ if (!excludeExternalLinks || !EXTERNAL_URL_RE.test(node.url)) {
6
+ node.url = node.url.replace(pattern, replace);
7
+ }
8
+ });
9
+ };
10
+ export {
11
+ remarkLinkRewrite
12
+ };
@@ -0,0 +1,10 @@
1
+ import { Root } from 'mdast';
2
+ import { Plugin } from './lib/index.js';
3
+
4
+ declare const remarkMdxDisableExplicitJsx: Plugin<[
5
+ {
6
+ whiteList: string[];
7
+ }
8
+ ], Root>;
9
+
10
+ export { remarkMdxDisableExplicitJsx };
@@ -0,0 +1,10 @@
1
+ import { visit } from "unist-util-visit";
2
+ const remarkMdxDisableExplicitJsx = ({ whiteList }) => (ast) => {
3
+ const test = whiteList.map((name) => ({ name }));
4
+ visit(ast, test, (node) => {
5
+ delete node.data._mdxExplicitJsx;
6
+ });
7
+ };
8
+ export {
9
+ remarkMdxDisableExplicitJsx
10
+ };
@@ -0,0 +1,6 @@
1
+ import { Root } from 'mdast';
2
+ import { Plugin } from './lib/index.js';
3
+
4
+ declare const remarkMdxFrontMatter: Plugin<[], Root>;
5
+
6
+ export { remarkMdxFrontMatter };
@@ -0,0 +1,37 @@
1
+ import { valueToEstree } from "estree-util-value-to-estree";
2
+ import { parse as parseYaml } from "yaml";
3
+ import { createAstExportConst } from "../utils.js";
4
+ import { isExportNode } from "./remark-mdx-title.js";
5
+ function createNode(data) {
6
+ return {
7
+ type: "mdxjsEsm",
8
+ data: {
9
+ estree: {
10
+ body: [createAstExportConst("metadata", valueToEstree(data))]
11
+ }
12
+ }
13
+ };
14
+ }
15
+ const transformer = (ast) => {
16
+ const yamlNodeIndex = ast.children.findIndex((node) => node.type === "yaml");
17
+ const esmNodeIndex = ast.children.findIndex(
18
+ (node) => isExportNode(node, "metadata")
19
+ );
20
+ const hasYaml = yamlNodeIndex !== -1;
21
+ const hasEsm = esmNodeIndex !== -1;
22
+ if (hasYaml) {
23
+ if (hasEsm) {
24
+ throw new Error(
25
+ "Both YAML front matter and `metadata` aren't supported. Keep only 1."
26
+ );
27
+ }
28
+ const node = ast.children[yamlNodeIndex];
29
+ ast.children[yamlNodeIndex] = createNode(parseYaml(node.value) ?? {});
30
+ } else if (!hasEsm) {
31
+ ast.children.unshift(createNode({}));
32
+ }
33
+ };
34
+ const remarkMdxFrontMatter = () => transformer;
35
+ export {
36
+ remarkMdxFrontMatter
37
+ };
@@ -0,0 +1,10 @@
1
+ import { Property } from 'estree';
2
+ import { Root, RootContent } from 'mdast';
3
+ import { MdxjsEsmHast } from 'mdast-util-mdxjs-esm';
4
+ import { Plugin } from './lib/index.js';
5
+
6
+ declare function getFrontMatterASTObject(node: MdxjsEsmHast): Property[];
7
+ declare function isExportNode(node: MdxjsEsmHast | RootContent, varName: string): node is MdxjsEsmHast;
8
+ declare const remarkMdxTitle: Plugin<[], Root>;
9
+
10
+ export { getFrontMatterASTObject, isExportNode, remarkMdxTitle };
@@ -0,0 +1,53 @@
1
+ import path from "path";
2
+ import { EXIT, visit } from "unist-util-visit";
3
+ import { pageTitleFromFilename } from "../utils.js";
4
+ import { getFlattenedValue } from "./remark-headings.js";
5
+ function getFrontMatterASTObject(node) {
6
+ const [n] = node.data.estree.body;
7
+ return n.declaration.declarations[0].init.properties;
8
+ }
9
+ function isExportNode(node, varName) {
10
+ if (node.type !== "mdxjsEsm") return false;
11
+ const n = node.data.estree.body[0];
12
+ if (n.type !== "ExportNamedDeclaration") return false;
13
+ const name = n.declaration?.declarations?.[0].id.name;
14
+ if (!name) return false;
15
+ return name === varName;
16
+ }
17
+ const transformer = (ast, file) => {
18
+ let title = "";
19
+ const frontMatterNode = ast.children.find(
20
+ (node) => isExportNode(node, "metadata")
21
+ );
22
+ for (const { key, value } of getFrontMatterASTObject(frontMatterNode)) {
23
+ if (key.type === "Literal" && key.value === "title") {
24
+ title = value.value;
25
+ break;
26
+ }
27
+ if (key.type === "Identifier" && key.name === "title") {
28
+ title = value.value;
29
+ break;
30
+ }
31
+ }
32
+ if (!title) {
33
+ visit(ast, { type: "heading", depth: 1 }, (node) => {
34
+ title = getFlattenedValue(node);
35
+ return EXIT;
36
+ });
37
+ if (!title) {
38
+ const [filePath] = file.history;
39
+ if (filePath) {
40
+ title = pageTitleFromFilename(path.parse(filePath).name);
41
+ }
42
+ }
43
+ if (title) {
44
+ file.data.title = title;
45
+ }
46
+ }
47
+ };
48
+ const remarkMdxTitle = () => transformer;
49
+ export {
50
+ getFrontMatterASTObject,
51
+ isExportNode,
52
+ remarkMdxTitle
53
+ };
@@ -0,0 +1,6 @@
1
+ import { Root } from 'mdast';
2
+ import { Plugin } from './lib/index.js';
3
+
4
+ declare const remarkRemoveImports: Plugin<[], Root>;
5
+
6
+ export { remarkRemoveImports };
@@ -0,0 +1,12 @@
1
+ import { remove } from "unist-util-remove";
2
+ const transformer = (ast) => {
3
+ remove(
4
+ ast,
5
+ (node) => node.type === "mdxjsEsm" && // @ts-expect-error -- fixme
6
+ node.data.estree.body[0].type === "ImportDeclaration"
7
+ );
8
+ };
9
+ const remarkRemoveImports = () => transformer;
10
+ export {
11
+ remarkRemoveImports
12
+ };
@@ -0,0 +1,6 @@
1
+ import { Root } from 'mdast';
2
+ import { Plugin } from './lib/index.js';
3
+
4
+ declare const remarkStaticImage: Plugin<[], Root>;
5
+
6
+ export { remarkStaticImage };
@@ -0,0 +1,107 @@
1
+ import path from "path";
2
+ import { visit } from "unist-util-visit";
3
+ import { EXTERNAL_URL_RE } from "../constants.js";
4
+ const VALID_BLUR_EXT = [".jpeg", ".png", ".webp", ".avif", ".jpg"];
5
+ const VARIABLE_PREFIX = "__img";
6
+ const transformer = (ast) => {
7
+ const definitionNodes = [];
8
+ const imageImports = /* @__PURE__ */ new Set();
9
+ const imageNodes = [];
10
+ visit(ast, "definition", (node) => {
11
+ definitionNodes.push(node);
12
+ });
13
+ visit(ast, ["image", "imageReference"], (_node) => {
14
+ const node = _node;
15
+ let url = decodeURI(
16
+ node.type === "image" ? node.url : definitionNodes.find(
17
+ (definition) => definition.identifier === node.identifier
18
+ )?.url ?? ""
19
+ );
20
+ if (!url) {
21
+ return;
22
+ }
23
+ if (EXTERNAL_URL_RE.test(url)) {
24
+ return;
25
+ }
26
+ if (url.startsWith("/")) {
27
+ url = path.posix.join("private-next-root-dir", "public", url);
28
+ }
29
+ imageImports.add(url);
30
+ node.url = url;
31
+ imageNodes.push(node);
32
+ });
33
+ const imageUrls = [...imageImports];
34
+ for (const node of imageNodes) {
35
+ const { url } = node;
36
+ const imageIndex = imageUrls.indexOf(url);
37
+ const variableName = `${VARIABLE_PREFIX}${imageIndex}`;
38
+ const hasBlur = VALID_BLUR_EXT.some((ext) => url.endsWith(ext));
39
+ Object.assign(node, {
40
+ type: "mdxJsxFlowElement",
41
+ name: "img",
42
+ attributes: [
43
+ // do not render empty alt in html markup
44
+ node.alt && {
45
+ type: "mdxJsxAttribute",
46
+ name: "alt",
47
+ value: node.alt
48
+ },
49
+ hasBlur && {
50
+ type: "mdxJsxAttribute",
51
+ name: "placeholder",
52
+ value: "blur"
53
+ },
54
+ {
55
+ type: "mdxJsxAttribute",
56
+ name: "src",
57
+ value: {
58
+ type: "mdxJsxAttributeValueExpression",
59
+ value: variableName,
60
+ data: {
61
+ estree: {
62
+ body: [
63
+ {
64
+ type: "ExpressionStatement",
65
+ expression: { type: "Identifier", name: variableName }
66
+ }
67
+ ]
68
+ }
69
+ }
70
+ }
71
+ }
72
+ ].filter((v) => !!v)
73
+ });
74
+ }
75
+ if (imageUrls.length) {
76
+ ast.children.unshift(
77
+ ...imageUrls.map(
78
+ (imageUrl, index) => ({
79
+ type: "mdxjsEsm",
80
+ data: {
81
+ estree: {
82
+ body: [
83
+ {
84
+ type: "ImportDeclaration",
85
+ source: { type: "Literal", value: imageUrl },
86
+ specifiers: [
87
+ {
88
+ type: "ImportDefaultSpecifier",
89
+ local: {
90
+ type: "Identifier",
91
+ name: `${VARIABLE_PREFIX}${index}`
92
+ }
93
+ }
94
+ ]
95
+ }
96
+ ]
97
+ }
98
+ }
99
+ })
100
+ )
101
+ );
102
+ }
103
+ };
104
+ const remarkStaticImage = () => transformer;
105
+ export {
106
+ remarkStaticImage
107
+ };