fumadocs-core 16.4.5 → 16.4.7

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 (187) hide show
  1. package/dist/{advanced-DSlc7qa9.js → advanced-tbtFDsHU.js} +3 -3
  2. package/dist/advanced-tbtFDsHU.js.map +1 -0
  3. package/dist/{algolia-FqjcaTcD.d.ts → algolia-BFVpYDZ_.d.ts} +2 -2
  4. package/dist/{algolia-FqjcaTcD.d.ts.map → algolia-BFVpYDZ_.d.ts.map} +1 -1
  5. package/dist/{algolia-BGWM-DkQ.js → algolia-Dbt0kj8j.js} +2 -2
  6. package/dist/algolia-Dbt0kj8j.js.map +1 -0
  7. package/dist/breadcrumb.d.ts +1 -1
  8. package/dist/breadcrumb.js +2 -2
  9. package/dist/breadcrumb.js.map +1 -1
  10. package/dist/{codeblock-utils-Dh1w8ICD.d.ts → codeblock-utils-CdA7nXLP.d.ts} +1 -1
  11. package/dist/{codeblock-utils-Dh1w8ICD.d.ts.map → codeblock-utils-CdA7nXLP.d.ts.map} +1 -1
  12. package/dist/content/mdx/preset-bundler.d.ts +8 -8
  13. package/dist/content/mdx/preset-bundler.js +1 -1
  14. package/dist/content/mdx/preset-runtime.d.ts +8 -8
  15. package/dist/content/mdx/preset-runtime.js +1 -1
  16. package/dist/content/toc.js +1 -1
  17. package/dist/{definitions-DJAPG-2U.d.ts → definitions-Ca2P2viV.d.ts} +1 -1
  18. package/dist/{definitions-DJAPG-2U.d.ts.map → definitions-Ca2P2viV.d.ts.map} +1 -1
  19. package/dist/{fetch-B1nmMSyw.js → fetch-CiphcAUR.js} +1 -1
  20. package/dist/{fetch-B1nmMSyw.js.map → fetch-CiphcAUR.js.map} +1 -1
  21. package/dist/framework/index.d.ts +4 -4
  22. package/dist/framework/next.d.ts +2 -2
  23. package/dist/framework/react-router.d.ts +2 -2
  24. package/dist/framework/react-router.js.map +1 -1
  25. package/dist/framework/tanstack.d.ts +2 -2
  26. package/dist/framework/tanstack.js.map +1 -1
  27. package/dist/framework/waku.d.ts +2 -2
  28. package/dist/framework/waku.js.map +1 -1
  29. package/dist/highlight/client.d.ts +1 -1
  30. package/dist/highlight/client.js +1 -1
  31. package/dist/highlight/client.js.map +1 -1
  32. package/dist/highlight/index.d.ts +1 -1
  33. package/dist/highlight/index.js +1 -1
  34. package/dist/i18n/index.d.ts +1 -1
  35. package/dist/i18n/middleware.d.ts +1 -1
  36. package/dist/i18n/middleware.js.map +1 -1
  37. package/dist/{icon-5lVe3l-0.js → icon-CL3r1pNG.js} +1 -1
  38. package/dist/{icon-5lVe3l-0.js.map → icon-CL3r1pNG.js.map} +1 -1
  39. package/dist/index-BaMZ8PEK.d.ts +45 -0
  40. package/dist/index-BaMZ8PEK.d.ts.map +1 -0
  41. package/dist/index-CmGSoB4T.d.ts +18 -0
  42. package/dist/index-CmGSoB4T.d.ts.map +1 -0
  43. package/dist/{index-BhVrX5J1.d.ts → index-DxhhLscI.d.ts} +1 -1
  44. package/dist/{index-BhVrX5J1.d.ts.map → index-DxhhLscI.d.ts.map} +1 -1
  45. package/dist/{index-Co_C8NEi.d.ts → index-aE27-b16.d.ts} +5 -4
  46. package/dist/index-aE27-b16.d.ts.map +1 -0
  47. package/dist/{mdast-utils-ix4DsXJP.js → mdast-utils-B8O-41y4.js} +1 -1
  48. package/dist/{mdast-utils-ix4DsXJP.js.map → mdast-utils-B8O-41y4.js.map} +1 -1
  49. package/dist/mdx-plugins/codeblock-utils.d.ts +1 -1
  50. package/dist/mdx-plugins/codeblock-utils.js.map +1 -1
  51. package/dist/mdx-plugins/index.d.ts +16 -15
  52. package/dist/mdx-plugins/index.js +6 -5
  53. package/dist/mdx-plugins/rehype-code.d.ts +1 -1
  54. package/dist/mdx-plugins/rehype-code.js +2 -2
  55. package/dist/mdx-plugins/rehype-toc.d.ts +1 -1
  56. package/dist/mdx-plugins/rehype-toc.js +1 -1
  57. package/dist/mdx-plugins/remark-admonition.d.ts +1 -1
  58. package/dist/mdx-plugins/remark-admonition.js +1 -1
  59. package/dist/mdx-plugins/remark-code-tab.d.ts +1 -1
  60. package/dist/mdx-plugins/remark-code-tab.js.map +1 -1
  61. package/dist/mdx-plugins/remark-directive-admonition.d.ts +1 -1
  62. package/dist/mdx-plugins/remark-directive-admonition.js.map +1 -1
  63. package/dist/mdx-plugins/remark-feedback-block.d.ts +2 -0
  64. package/dist/mdx-plugins/remark-feedback-block.js +48 -0
  65. package/dist/mdx-plugins/remark-feedback-block.js.map +1 -0
  66. package/dist/mdx-plugins/remark-gfm.d.ts +1 -1
  67. package/dist/mdx-plugins/remark-heading.d.ts +1 -1
  68. package/dist/mdx-plugins/remark-heading.js +1 -1
  69. package/dist/mdx-plugins/remark-heading.js.map +1 -1
  70. package/dist/mdx-plugins/remark-image.d.ts +1 -1
  71. package/dist/mdx-plugins/remark-image.js.map +1 -1
  72. package/dist/mdx-plugins/remark-mdx-files.d.ts +1 -1
  73. package/dist/mdx-plugins/remark-mdx-files.js.map +1 -1
  74. package/dist/mdx-plugins/remark-mdx-mermaid.d.ts +1 -1
  75. package/dist/mdx-plugins/remark-npm.d.ts +1 -1
  76. package/dist/mdx-plugins/remark-npm.js.map +1 -1
  77. package/dist/mdx-plugins/remark-steps.d.ts +1 -1
  78. package/dist/mdx-plugins/remark-steps.js.map +1 -1
  79. package/dist/mdx-plugins/remark-structure.d.ts +1 -1
  80. package/dist/mdx-plugins/remark-structure.js +1 -1
  81. package/dist/mdx-plugins/remark-structure.js.map +1 -1
  82. package/dist/{mixedbread-DSiQfUnN.js → mixedbread-CPGJEgwq.js} +3 -3
  83. package/dist/mixedbread-CPGJEgwq.js.map +1 -0
  84. package/dist/negotiation/index.js.map +1 -1
  85. package/dist/{normalize-url-3WQZ_H_j.js → normalize-url-CEfNKxaE.js} +1 -1
  86. package/dist/{normalize-url-3WQZ_H_j.js.map → normalize-url-CEfNKxaE.js.map} +1 -1
  87. package/dist/{orama-cloud-legacy-CRZzZXWn.js → orama-cloud-legacy-NJTbB19B.js} +3 -3
  88. package/dist/orama-cloud-legacy-NJTbB19B.js.map +1 -0
  89. package/dist/{orama-cloud-BMDBfk05.js → orama-cloud-yicpgD0c.js} +3 -3
  90. package/dist/orama-cloud-yicpgD0c.js.map +1 -0
  91. package/dist/page-tree/index.d.ts +3 -45
  92. package/dist/page-tree/index.js +1 -1
  93. package/dist/{path-D6M0ZQvO.js → path-CECfI3nn.js} +2 -2
  94. package/dist/{path-D6M0ZQvO.js.map → path-CECfI3nn.js.map} +1 -1
  95. package/dist/{rehype-code-Bd52chOe.d.ts → rehype-code-BUrju-yF.d.ts} +1 -1
  96. package/dist/{rehype-code-Bd52chOe.d.ts.map → rehype-code-BUrju-yF.d.ts.map} +1 -1
  97. package/dist/{rehype-code-j8FAEnuU.js → rehype-code-Ct5Pb6BZ.js} +2 -2
  98. package/dist/rehype-code-Ct5Pb6BZ.js.map +1 -0
  99. package/dist/{rehype-toc-Dqgey2tW.js → rehype-toc-CTG0x7La.js} +1 -1
  100. package/dist/rehype-toc-CTG0x7La.js.map +1 -0
  101. package/dist/{rehype-toc-BJVsblvp.d.ts → rehype-toc-Dcgzd_Vy.d.ts} +1 -1
  102. package/dist/{rehype-toc-BJVsblvp.d.ts.map → rehype-toc-Dcgzd_Vy.d.ts.map} +1 -1
  103. package/dist/{remark-admonition-Chku_iWO.d.ts → remark-admonition-BvgS4oU1.d.ts} +1 -1
  104. package/dist/{remark-admonition-Chku_iWO.d.ts.map → remark-admonition-BvgS4oU1.d.ts.map} +1 -1
  105. package/dist/{remark-code-tab-C0f6BPcw.d.ts → remark-code-tab-Ds_BdYXz.d.ts} +1 -1
  106. package/dist/{remark-code-tab-C0f6BPcw.d.ts.map → remark-code-tab-Ds_BdYXz.d.ts.map} +1 -1
  107. package/dist/{remark-directive-admonition-CBwJdh9z.d.ts → remark-directive-admonition-02cR5K1L.d.ts} +1 -1
  108. package/dist/{remark-directive-admonition-CBwJdh9z.d.ts.map → remark-directive-admonition-02cR5K1L.d.ts.map} +1 -1
  109. package/dist/remark-feedback-block-fAyt4LdQ.d.ts +52 -0
  110. package/dist/remark-feedback-block-fAyt4LdQ.d.ts.map +1 -0
  111. package/dist/{remark-heading-CUAe4zIu.d.ts → remark-heading-CSButCYt.d.ts} +1 -1
  112. package/dist/{remark-heading-CUAe4zIu.d.ts.map → remark-heading-CSButCYt.d.ts.map} +1 -1
  113. package/dist/{remark-image-DMRnxsRO.d.ts → remark-image-C3MnP-3r.d.ts} +1 -1
  114. package/dist/{remark-image-DMRnxsRO.d.ts.map → remark-image-C3MnP-3r.d.ts.map} +1 -1
  115. package/dist/{remark-mdx-files-B5KMXnfh.d.ts → remark-mdx-files-BXUiiX3M.d.ts} +1 -1
  116. package/dist/{remark-mdx-files-B5KMXnfh.d.ts.map → remark-mdx-files-BXUiiX3M.d.ts.map} +1 -1
  117. package/dist/{remark-mdx-mermaid-C_4W5gfj.d.ts → remark-mdx-mermaid-C5ZBxx8x.d.ts} +1 -1
  118. package/dist/{remark-mdx-mermaid-C_4W5gfj.d.ts.map → remark-mdx-mermaid-C5ZBxx8x.d.ts.map} +1 -1
  119. package/dist/{remark-npm-CykFgJn2.d.ts → remark-npm-DADZg0pf.d.ts} +1 -1
  120. package/dist/{remark-npm-CykFgJn2.d.ts.map → remark-npm-DADZg0pf.d.ts.map} +1 -1
  121. package/dist/{remark-steps-5-DmLVv3.d.ts → remark-steps-CWEE34cT.d.ts} +1 -1
  122. package/dist/{remark-steps-5-DmLVv3.d.ts.map → remark-steps-CWEE34cT.d.ts.map} +1 -1
  123. package/dist/{remark-structure-CszwnaMR.d.ts → remark-structure-ChKxMXnK.d.ts} +1 -1
  124. package/dist/{remark-structure-CszwnaMR.d.ts.map → remark-structure-ChKxMXnK.d.ts.map} +1 -1
  125. package/dist/{remove-undefined-B7zJF-YS.js → remove-undefined-Buxsprgu.js} +1 -1
  126. package/dist/{remove-undefined-B7zJF-YS.js.map → remove-undefined-Buxsprgu.js.map} +1 -1
  127. package/dist/search/algolia.d.ts +2 -2
  128. package/dist/search/algolia.js.map +1 -1
  129. package/dist/search/client.d.ts +7 -5
  130. package/dist/search/client.d.ts.map +1 -1
  131. package/dist/search/client.js +6 -6
  132. package/dist/search/index.js +1 -1
  133. package/dist/search/orama-cloud-legacy.d.ts +5 -5
  134. package/dist/search/orama-cloud-legacy.js.map +1 -1
  135. package/dist/search/orama-cloud.d.ts +5 -5
  136. package/dist/search/orama-cloud.js.map +1 -1
  137. package/dist/search/server.d.ts +6 -4
  138. package/dist/search/server.js +4 -4
  139. package/dist/search/server.js.map +1 -1
  140. package/dist/{search-DcH54N2x.js → search-DzqmOjzV.js} +1 -1
  141. package/dist/search-DzqmOjzV.js.map +1 -0
  142. package/dist/{server-BzFuYBxW.d.ts → server-CLPpotS9.d.ts} +4 -4
  143. package/dist/{server-BzFuYBxW.d.ts.map → server-CLPpotS9.d.ts.map} +1 -1
  144. package/dist/{shiki-DoHr6fEj.js → shiki-B4NO99XD.js} +1 -1
  145. package/dist/shiki-B4NO99XD.js.map +1 -0
  146. package/dist/{shiki-Bdk0JGsB.d.ts → shiki-vKy7H_iw.d.ts} +1 -1
  147. package/dist/{shiki-Bdk0JGsB.d.ts.map → shiki-vKy7H_iw.d.ts.map} +1 -1
  148. package/dist/source/client/index.d.ts +4 -18
  149. package/dist/source/client/index.js +17 -10
  150. package/dist/source/client/index.js.map +1 -1
  151. package/dist/source/index.d.ts +4 -2
  152. package/dist/source/index.js +14 -11
  153. package/dist/source/index.js.map +1 -1
  154. package/dist/source/plugins/lucide-icons.d.ts +4 -2
  155. package/dist/source/plugins/lucide-icons.d.ts.map +1 -1
  156. package/dist/source/plugins/lucide-icons.js +1 -1
  157. package/dist/source/plugins/slugs.d.ts +4 -2
  158. package/dist/source/plugins/slugs.js +1 -1
  159. package/dist/source/plugins/slugs.js.map +1 -1
  160. package/dist/{static-DAjBQpus.js → static-C_WBOzek.js} +2 -2
  161. package/dist/static-C_WBOzek.js.map +1 -0
  162. package/dist/toc.js.map +1 -1
  163. package/dist/{util-92szu3Vf.js → util-Dn-wseQ5.js} +1 -1
  164. package/dist/{util-92szu3Vf.js.map → util-Dn-wseQ5.js.map} +1 -1
  165. package/dist/{util-ofJFdM-e.d.ts → util-d5FlPx1Z.d.ts} +1 -1
  166. package/dist/util-d5FlPx1Z.d.ts.map +1 -0
  167. package/dist/utils/use-effect-event.js.map +1 -1
  168. package/dist/{utils-bAoAH1Rh.js → utils-D10VxgVc.js} +1 -1
  169. package/dist/utils-D10VxgVc.js.map +1 -0
  170. package/package.json +12 -12
  171. package/dist/advanced-DSlc7qa9.js.map +0 -1
  172. package/dist/algolia-BGWM-DkQ.js.map +0 -1
  173. package/dist/index-Co_C8NEi.d.ts.map +0 -1
  174. package/dist/mixedbread-DSiQfUnN.js.map +0 -1
  175. package/dist/orama-cloud-BMDBfk05.js.map +0 -1
  176. package/dist/orama-cloud-legacy-CRZzZXWn.js.map +0 -1
  177. package/dist/page-tree/index.d.ts.map +0 -1
  178. package/dist/rehype-code-j8FAEnuU.js.map +0 -1
  179. package/dist/rehype-toc-Dqgey2tW.js.map +0 -1
  180. package/dist/search-DcH54N2x.js.map +0 -1
  181. package/dist/shiki-DoHr6fEj.js.map +0 -1
  182. package/dist/source/client/index.d.ts.map +0 -1
  183. package/dist/static-DAjBQpus.js.map +0 -1
  184. package/dist/util-ofJFdM-e.d.ts.map +0 -1
  185. package/dist/utils-bAoAH1Rh.js.map +0 -1
  186. /package/dist/{chunk-C1JLJEPO.js → chunk-C9UIFEcR.js} +0 -0
  187. /package/dist/{remark-gfm-B2aZXutO.d.ts → remark-gfm-jrvaEZw5.d.ts} +0 -0
@@ -37,4 +37,4 @@ function toMdxExport(name, value) {
37
37
 
38
38
  //#endregion
39
39
  export { toMdxExport as n, flattenNode as t };
40
- //# sourceMappingURL=mdast-utils-ix4DsXJP.js.map
40
+ //# sourceMappingURL=mdast-utils-B8O-41y4.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mdast-utils-ix4DsXJP.js","names":[],"sources":["../src/mdx-plugins/mdast-utils.ts"],"sourcesContent":["import type { RootContent } from 'mdast';\nimport { valueToEstree } from 'estree-util-value-to-estree';\n\nexport function flattenNode(node: RootContent): string {\n if ('children' in node) return node.children.map((child) => flattenNode(child)).join('');\n\n if ('value' in node && typeof node.value === 'string') return node.value;\n\n return '';\n}\n\nexport function toMdxExport(name: string, value: unknown): RootContent {\n return {\n type: 'mdxjsEsm',\n value: '',\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n body: [\n {\n type: 'ExportNamedDeclaration',\n attributes: [],\n specifiers: [],\n source: null,\n declaration: {\n type: 'VariableDeclaration',\n kind: 'let',\n declarations: [\n {\n type: 'VariableDeclarator',\n id: {\n type: 'Identifier',\n name,\n },\n init: valueToEstree(value),\n },\n ],\n },\n },\n ],\n },\n },\n };\n}\n"],"mappings":";;;AAGA,SAAgB,YAAY,MAA2B;AACrD,KAAI,cAAc,KAAM,QAAO,KAAK,SAAS,KAAK,UAAU,YAAY,MAAM,CAAC,CAAC,KAAK,GAAG;AAExF,KAAI,WAAW,QAAQ,OAAO,KAAK,UAAU,SAAU,QAAO,KAAK;AAEnE,QAAO;;AAGT,SAAgB,YAAY,MAAc,OAA6B;AACrE,QAAO;EACL,MAAM;EACN,OAAO;EACP,MAAM,EACJ,QAAQ;GACN,MAAM;GACN,YAAY;GACZ,MAAM,CACJ;IACE,MAAM;IACN,YAAY,EAAE;IACd,YAAY,EAAE;IACd,QAAQ;IACR,aAAa;KACX,MAAM;KACN,MAAM;KACN,cAAc,CACZ;MACE,MAAM;MACN,IAAI;OACF,MAAM;OACN;OACD;MACD,MAAM,cAAc,MAAM;MAC3B,CACF;KACF;IACF,CACF;GACF,EACF;EACF"}
1
+ {"version":3,"file":"mdast-utils-B8O-41y4.js","names":[],"sources":["../src/mdx-plugins/mdast-utils.ts"],"sourcesContent":["import type { RootContent } from 'mdast';\nimport { valueToEstree } from 'estree-util-value-to-estree';\n\nexport function flattenNode(node: RootContent): string {\n if ('children' in node) return node.children.map((child) => flattenNode(child)).join('');\n\n if ('value' in node && typeof node.value === 'string') return node.value;\n\n return '';\n}\n\nexport function toMdxExport(name: string, value: unknown): RootContent {\n return {\n type: 'mdxjsEsm',\n value: '',\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n body: [\n {\n type: 'ExportNamedDeclaration',\n attributes: [],\n specifiers: [],\n source: null,\n declaration: {\n type: 'VariableDeclaration',\n kind: 'let',\n declarations: [\n {\n type: 'VariableDeclarator',\n id: {\n type: 'Identifier',\n name,\n },\n init: valueToEstree(value),\n },\n ],\n },\n },\n ],\n },\n },\n };\n}\n"],"mappings":";;;AAGA,SAAgB,YAAY,MAA2B;AACrD,KAAI,cAAc,KAAM,QAAO,KAAK,SAAS,KAAK,UAAU,YAAY,MAAM,CAAC,CAAC,KAAK,GAAG;AAExF,KAAI,WAAW,QAAQ,OAAO,KAAK,UAAU,SAAU,QAAO,KAAK;AAEnE,QAAO;;AAGT,SAAgB,YAAY,MAAc,OAA6B;AACrE,QAAO;EACL,MAAM;EACN,OAAO;EACP,MAAM,EACJ,QAAQ;GACN,MAAM;GACN,YAAY;GACZ,MAAM,CACJ;IACE,MAAM;IACN,YAAY,EAAE;IACd,YAAY,EAAE;IACd,QAAQ;IACR,aAAa;KACX,MAAM;KACN,MAAM;KACN,cAAc,CACZ;MACE,MAAM;MACN,IAAI;OACF,MAAM;OACN;OACD;MACD,MAAM,cAAc,MAAM;MAC3B,CACF;KACF;IACF,CACF;GACF,EACF;EACF"}
@@ -1,2 +1,2 @@
1
- import { i as parseCodeBlockAttributes, n as CodeBlockTabsOptions, r as generateCodeBlockTabs, t as CodeBlockAttributes } from "../codeblock-utils-Dh1w8ICD.js";
1
+ import { i as parseCodeBlockAttributes, n as CodeBlockTabsOptions, r as generateCodeBlockTabs, t as CodeBlockAttributes } from "../codeblock-utils-CdA7nXLP.js";
2
2
  export { CodeBlockAttributes, CodeBlockTabsOptions, generateCodeBlockTabs, parseCodeBlockAttributes };
@@ -1 +1 @@
1
- {"version":3,"file":"codeblock-utils.js","names":["attributes: MdxJsxAttribute[]","children: MdxJsxFlowElement[]","attributes: CodeBlockAttributes['attributes']"],"sources":["../../src/mdx-plugins/codeblock-utils.ts"],"sourcesContent":["import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport type { BlockContent, Text } from 'mdast';\n\nexport interface CodeBlockTabsOptions {\n attributes?: MdxJsxAttribute[];\n defaultValue?: string;\n persist?:\n | {\n id: string;\n }\n | false;\n triggers: {\n value: string;\n children: (BlockContent | Text)[];\n }[];\n tabs: {\n value: string;\n children: BlockContent[];\n }[];\n}\n\nexport function generateCodeBlockTabs({\n persist = false,\n defaultValue,\n triggers,\n tabs,\n ...options\n}: CodeBlockTabsOptions): MdxJsxFlowElement {\n const attributes: MdxJsxAttribute[] = [];\n if (options.attributes) attributes.push(...options.attributes);\n\n if (defaultValue) {\n attributes.push({\n type: 'mdxJsxAttribute',\n name: 'defaultValue',\n value: defaultValue,\n });\n }\n\n if (typeof persist === 'object') {\n attributes.push(\n {\n type: 'mdxJsxAttribute',\n name: 'groupId',\n value: persist.id,\n },\n {\n type: 'mdxJsxAttribute',\n name: 'persist',\n value: null,\n },\n );\n }\n\n const children: MdxJsxFlowElement[] = [\n {\n type: 'mdxJsxFlowElement',\n name: 'CodeBlockTabsList',\n attributes: [],\n children: triggers.map(\n (trigger) =>\n ({\n type: 'mdxJsxFlowElement',\n attributes: [{ type: 'mdxJsxAttribute', name: 'value', value: trigger.value }],\n name: 'CodeBlockTabsTrigger',\n children: trigger.children,\n }) as MdxJsxFlowElement,\n ),\n },\n ];\n\n for (const tab of tabs) {\n children.push({\n type: 'mdxJsxFlowElement',\n name: 'CodeBlockTab',\n attributes: [{ type: 'mdxJsxAttribute', name: 'value', value: tab.value }],\n children: tab.children,\n });\n }\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'CodeBlockTabs',\n attributes,\n children,\n };\n}\n\nexport interface CodeBlockAttributes<Name extends string = string> {\n attributes: Partial<Record<Name, string | null>>;\n rest: string;\n}\n\n/**\n * Parse Fumadocs-style code block attributes from meta string, like `title=\"hello world\"`\n */\nexport function parseCodeBlockAttributes<Name extends string = string>(\n meta: string,\n allowedNames?: Name[],\n): CodeBlockAttributes<Name> {\n let str = meta;\n const StringRegex = /(?<=^|\\s)(?<name>\\w+)(?:=(?:\"([^\"]*)\"|'([^']*)'))?/g;\n const attributes: CodeBlockAttributes['attributes'] = {};\n\n str = str.replaceAll(StringRegex, (match, name, value_1, value_2) => {\n if (allowedNames && !allowedNames.includes(name)) return match;\n\n attributes[name] = value_1 ?? value_2 ?? null;\n return '';\n });\n\n return {\n rest: str,\n attributes,\n };\n}\n"],"mappings":";AAqBA,SAAgB,sBAAsB,EACpC,UAAU,OACV,cACA,UACA,MACA,GAAG,WACuC;CAC1C,MAAMA,aAAgC,EAAE;AACxC,KAAI,QAAQ,WAAY,YAAW,KAAK,GAAG,QAAQ,WAAW;AAE9D,KAAI,aACF,YAAW,KAAK;EACd,MAAM;EACN,MAAM;EACN,OAAO;EACR,CAAC;AAGJ,KAAI,OAAO,YAAY,SACrB,YAAW,KACT;EACE,MAAM;EACN,MAAM;EACN,OAAO,QAAQ;EAChB,EACD;EACE,MAAM;EACN,MAAM;EACN,OAAO;EACR,CACF;CAGH,MAAMC,WAAgC,CACpC;EACE,MAAM;EACN,MAAM;EACN,YAAY,EAAE;EACd,UAAU,SAAS,KAChB,aACE;GACC,MAAM;GACN,YAAY,CAAC;IAAE,MAAM;IAAmB,MAAM;IAAS,OAAO,QAAQ;IAAO,CAAC;GAC9E,MAAM;GACN,UAAU,QAAQ;GACnB,EACJ;EACF,CACF;AAED,MAAK,MAAM,OAAO,KAChB,UAAS,KAAK;EACZ,MAAM;EACN,MAAM;EACN,YAAY,CAAC;GAAE,MAAM;GAAmB,MAAM;GAAS,OAAO,IAAI;GAAO,CAAC;EAC1E,UAAU,IAAI;EACf,CAAC;AAGJ,QAAO;EACL,MAAM;EACN,MAAM;EACN;EACA;EACD;;;;;AAWH,SAAgB,yBACd,MACA,cAC2B;CAC3B,IAAI,MAAM;CACV,MAAM,cAAc;CACpB,MAAMC,aAAgD,EAAE;AAExD,OAAM,IAAI,WAAW,cAAc,OAAO,MAAM,SAAS,YAAY;AACnE,MAAI,gBAAgB,CAAC,aAAa,SAAS,KAAK,CAAE,QAAO;AAEzD,aAAW,QAAQ,WAAW,WAAW;AACzC,SAAO;GACP;AAEF,QAAO;EACL,MAAM;EACN;EACD"}
1
+ {"version":3,"file":"codeblock-utils.js","names":[],"sources":["../../src/mdx-plugins/codeblock-utils.ts"],"sourcesContent":["import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport type { BlockContent, Text } from 'mdast';\n\nexport interface CodeBlockTabsOptions {\n attributes?: MdxJsxAttribute[];\n defaultValue?: string;\n persist?:\n | {\n id: string;\n }\n | false;\n triggers: {\n value: string;\n children: (BlockContent | Text)[];\n }[];\n tabs: {\n value: string;\n children: BlockContent[];\n }[];\n}\n\nexport function generateCodeBlockTabs({\n persist = false,\n defaultValue,\n triggers,\n tabs,\n ...options\n}: CodeBlockTabsOptions): MdxJsxFlowElement {\n const attributes: MdxJsxAttribute[] = [];\n if (options.attributes) attributes.push(...options.attributes);\n\n if (defaultValue) {\n attributes.push({\n type: 'mdxJsxAttribute',\n name: 'defaultValue',\n value: defaultValue,\n });\n }\n\n if (typeof persist === 'object') {\n attributes.push(\n {\n type: 'mdxJsxAttribute',\n name: 'groupId',\n value: persist.id,\n },\n {\n type: 'mdxJsxAttribute',\n name: 'persist',\n value: null,\n },\n );\n }\n\n const children: MdxJsxFlowElement[] = [\n {\n type: 'mdxJsxFlowElement',\n name: 'CodeBlockTabsList',\n attributes: [],\n children: triggers.map(\n (trigger) =>\n ({\n type: 'mdxJsxFlowElement',\n attributes: [{ type: 'mdxJsxAttribute', name: 'value', value: trigger.value }],\n name: 'CodeBlockTabsTrigger',\n children: trigger.children,\n }) as MdxJsxFlowElement,\n ),\n },\n ];\n\n for (const tab of tabs) {\n children.push({\n type: 'mdxJsxFlowElement',\n name: 'CodeBlockTab',\n attributes: [{ type: 'mdxJsxAttribute', name: 'value', value: tab.value }],\n children: tab.children,\n });\n }\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'CodeBlockTabs',\n attributes,\n children,\n };\n}\n\nexport interface CodeBlockAttributes<Name extends string = string> {\n attributes: Partial<Record<Name, string | null>>;\n rest: string;\n}\n\n/**\n * Parse Fumadocs-style code block attributes from meta string, like `title=\"hello world\"`\n */\nexport function parseCodeBlockAttributes<Name extends string = string>(\n meta: string,\n allowedNames?: Name[],\n): CodeBlockAttributes<Name> {\n let str = meta;\n const StringRegex = /(?<=^|\\s)(?<name>\\w+)(?:=(?:\"([^\"]*)\"|'([^']*)'))?/g;\n const attributes: CodeBlockAttributes['attributes'] = {};\n\n str = str.replaceAll(StringRegex, (match, name, value_1, value_2) => {\n if (allowedNames && !allowedNames.includes(name)) return match;\n\n attributes[name] = value_1 ?? value_2 ?? null;\n return '';\n });\n\n return {\n rest: str,\n attributes,\n };\n}\n"],"mappings":";AAqBA,SAAgB,sBAAsB,EACpC,UAAU,OACV,cACA,UACA,MACA,GAAG,WACuC;CAC1C,MAAM,aAAgC,EAAE;AACxC,KAAI,QAAQ,WAAY,YAAW,KAAK,GAAG,QAAQ,WAAW;AAE9D,KAAI,aACF,YAAW,KAAK;EACd,MAAM;EACN,MAAM;EACN,OAAO;EACR,CAAC;AAGJ,KAAI,OAAO,YAAY,SACrB,YAAW,KACT;EACE,MAAM;EACN,MAAM;EACN,OAAO,QAAQ;EAChB,EACD;EACE,MAAM;EACN,MAAM;EACN,OAAO;EACR,CACF;CAGH,MAAM,WAAgC,CACpC;EACE,MAAM;EACN,MAAM;EACN,YAAY,EAAE;EACd,UAAU,SAAS,KAChB,aACE;GACC,MAAM;GACN,YAAY,CAAC;IAAE,MAAM;IAAmB,MAAM;IAAS,OAAO,QAAQ;IAAO,CAAC;GAC9E,MAAM;GACN,UAAU,QAAQ;GACnB,EACJ;EACF,CACF;AAED,MAAK,MAAM,OAAO,KAChB,UAAS,KAAK;EACZ,MAAM;EACN,MAAM;EACN,YAAY,CAAC;GAAE,MAAM;GAAmB,MAAM;GAAS,OAAO,IAAI;GAAO,CAAC;EAC1E,UAAU,IAAI;EACf,CAAC;AAGJ,QAAO;EACL,MAAM;EACN,MAAM;EACN;EACA;EACD;;;;;AAWH,SAAgB,yBACd,MACA,cAC2B;CAC3B,IAAI,MAAM;CACV,MAAM,cAAc;CACpB,MAAM,aAAgD,EAAE;AAExD,OAAM,IAAI,WAAW,cAAc,OAAO,MAAM,SAAS,YAAY;AACnE,MAAI,gBAAgB,CAAC,aAAa,SAAS,KAAK,CAAE,QAAO;AAEzD,aAAW,QAAQ,WAAW,WAAW;AACzC,SAAO;GACP;AAEF,QAAO;EACL,MAAM;EACN;EACD"}
@@ -1,15 +1,16 @@
1
- import { n as remarkGfm, t as RemarkGfmOptions } from "../remark-gfm-B2aZXutO.js";
2
- import { a as CodeBlockIcon, i as transformerTab, n as rehypeCode, o as transformerIcon, r as rehypeCodeDefaultOptions, t as RehypeCodeOptions } from "../rehype-code-Bd52chOe.js";
3
- import { n as remarkImage, t as RemarkImageOptions } from "../remark-image-DMRnxsRO.js";
4
- import { a as structure, i as remarkStructureDefaultOptions, n as StructuredData, r as remarkStructure, t as StructureOptions } from "../remark-structure-CszwnaMR.js";
5
- import { n as remarkHeading, t as RemarkHeadingOptions } from "../remark-heading-CUAe4zIu.js";
6
- import { n as remarkAdmonition, t as RemarkAdmonitionOptions } from "../remark-admonition-Chku_iWO.js";
7
- import { n as remarkDirectiveAdmonition, t as RemarkDirectiveAdmonitionOptions } from "../remark-directive-admonition-CBwJdh9z.js";
8
- import { n as rehypeToc, t as RehypeTocOptions } from "../rehype-toc-BJVsblvp.js";
9
- import { n as remarkCodeTab, t as RemarkCodeTabOptions } from "../remark-code-tab-C0f6BPcw.js";
10
- import { n as remarkSteps, t as RemarkStepsOptions } from "../remark-steps-5-DmLVv3.js";
11
- import { n as remarkNpm, t as RemarkNpmOptions } from "../remark-npm-CykFgJn2.js";
12
- import { i as parseCodeBlockAttributes, n as CodeBlockTabsOptions, r as generateCodeBlockTabs, t as CodeBlockAttributes } from "../codeblock-utils-Dh1w8ICD.js";
13
- import { a as remarkMdxFiles, r as RemarkMdxFilesOptions } from "../remark-mdx-files-B5KMXnfh.js";
14
- import { n as remarkMdxMermaid, t as RemarkMdxMermaidOptions } from "../remark-mdx-mermaid-C_4W5gfj.js";
15
- export { CodeBlockAttributes, CodeBlockIcon, CodeBlockTabsOptions, RehypeCodeOptions, RehypeTocOptions, RemarkAdmonitionOptions, RemarkCodeTabOptions, RemarkDirectiveAdmonitionOptions, RemarkGfmOptions, RemarkHeadingOptions, RemarkImageOptions, type RemarkMdxFilesOptions, RemarkMdxMermaidOptions, RemarkNpmOptions, RemarkStepsOptions, StructureOptions, StructuredData, generateCodeBlockTabs, parseCodeBlockAttributes, rehypeCode, rehypeCodeDefaultOptions, rehypeToc, remarkAdmonition, remarkCodeTab, remarkDirectiveAdmonition, remarkGfm, remarkHeading, remarkImage, remarkMdxFiles, remarkMdxMermaid, remarkNpm, remarkSteps, remarkStructure, remarkStructureDefaultOptions, structure, transformerIcon, transformerTab };
1
+ import { n as remarkGfm, t as RemarkGfmOptions } from "../remark-gfm-jrvaEZw5.js";
2
+ import { a as CodeBlockIcon, i as transformerTab, n as rehypeCode, o as transformerIcon, r as rehypeCodeDefaultOptions, t as RehypeCodeOptions } from "../rehype-code-BUrju-yF.js";
3
+ import { n as remarkImage, t as RemarkImageOptions } from "../remark-image-C3MnP-3r.js";
4
+ import { a as structure, i as remarkStructureDefaultOptions, n as StructuredData, r as remarkStructure, t as StructureOptions } from "../remark-structure-ChKxMXnK.js";
5
+ import { n as remarkHeading, t as RemarkHeadingOptions } from "../remark-heading-CSButCYt.js";
6
+ import { n as remarkAdmonition, t as RemarkAdmonitionOptions } from "../remark-admonition-BvgS4oU1.js";
7
+ import { n as remarkDirectiveAdmonition, t as RemarkDirectiveAdmonitionOptions } from "../remark-directive-admonition-02cR5K1L.js";
8
+ import { n as rehypeToc, t as RehypeTocOptions } from "../rehype-toc-Dcgzd_Vy.js";
9
+ import { n as remarkCodeTab, t as RemarkCodeTabOptions } from "../remark-code-tab-Ds_BdYXz.js";
10
+ import { n as remarkSteps, t as RemarkStepsOptions } from "../remark-steps-CWEE34cT.js";
11
+ import { n as remarkNpm, t as RemarkNpmOptions } from "../remark-npm-DADZg0pf.js";
12
+ import { i as parseCodeBlockAttributes, n as CodeBlockTabsOptions, r as generateCodeBlockTabs, t as CodeBlockAttributes } from "../codeblock-utils-CdA7nXLP.js";
13
+ import { a as remarkMdxFiles, r as RemarkMdxFilesOptions } from "../remark-mdx-files-BXUiiX3M.js";
14
+ import { n as remarkMdxMermaid, t as RemarkMdxMermaidOptions } from "../remark-mdx-mermaid-C5ZBxx8x.js";
15
+ import { n as RemarkFeedbackBlockOptions, r as remarkFeedbackBlock, t as FeedbackBlockProps } from "../remark-feedback-block-fAyt4LdQ.js";
16
+ export { CodeBlockAttributes, CodeBlockIcon, CodeBlockTabsOptions, FeedbackBlockProps, RehypeCodeOptions, RehypeTocOptions, RemarkAdmonitionOptions, RemarkCodeTabOptions, RemarkDirectiveAdmonitionOptions, RemarkFeedbackBlockOptions, RemarkGfmOptions, RemarkHeadingOptions, RemarkImageOptions, type RemarkMdxFilesOptions, RemarkMdxMermaidOptions, RemarkNpmOptions, RemarkStepsOptions, StructureOptions, StructuredData, generateCodeBlockTabs, parseCodeBlockAttributes, rehypeCode, rehypeCodeDefaultOptions, rehypeToc, remarkAdmonition, remarkCodeTab, remarkDirectiveAdmonition, remarkFeedbackBlock, remarkGfm, remarkHeading, remarkImage, remarkMdxFiles, remarkMdxMermaid, remarkNpm, remarkSteps, remarkStructure, remarkStructureDefaultOptions, structure, transformerIcon, transformerTab };
@@ -1,18 +1,19 @@
1
- import "../mdast-utils-ix4DsXJP.js";
1
+ import "../mdast-utils-B8O-41y4.js";
2
2
  import { remarkHeading } from "./remark-heading.js";
3
- import "../shiki-DoHr6fEj.js";
3
+ import "../shiki-B4NO99XD.js";
4
4
  import { generateCodeBlockTabs, parseCodeBlockAttributes } from "./codeblock-utils.js";
5
5
  import { remarkGfm } from "./remark-gfm.js";
6
- import { i as transformerIcon, n as rehypeCodeDefaultOptions, r as transformerTab, t as rehypeCode } from "../rehype-code-j8FAEnuU.js";
6
+ import { i as transformerIcon, n as rehypeCodeDefaultOptions, r as transformerTab, t as rehypeCode } from "../rehype-code-Ct5Pb6BZ.js";
7
7
  import { remarkImage } from "./remark-image.js";
8
8
  import { remarkStructure, remarkStructureDefaultOptions, structure } from "./remark-structure.js";
9
9
  import { remarkAdmonition } from "./remark-admonition.js";
10
10
  import { remarkDirectiveAdmonition } from "./remark-directive-admonition.js";
11
- import { t as rehypeToc } from "../rehype-toc-Dqgey2tW.js";
11
+ import { t as rehypeToc } from "../rehype-toc-CTG0x7La.js";
12
12
  import { remarkCodeTab } from "./remark-code-tab.js";
13
13
  import { remarkSteps } from "./remark-steps.js";
14
14
  import { remarkNpm } from "./remark-npm.js";
15
15
  import { remarkMdxFiles } from "./remark-mdx-files.js";
16
16
  import { remarkMdxMermaid } from "./remark-mdx-mermaid.js";
17
+ import { remarkFeedbackBlock } from "./remark-feedback-block.js";
17
18
 
18
- export { generateCodeBlockTabs, parseCodeBlockAttributes, rehypeCode, rehypeCodeDefaultOptions, rehypeToc, remarkAdmonition, remarkCodeTab, remarkDirectiveAdmonition, remarkGfm, remarkHeading, remarkImage, remarkMdxFiles, remarkMdxMermaid, remarkNpm, remarkSteps, remarkStructure, remarkStructureDefaultOptions, structure, transformerIcon, transformerTab };
19
+ export { generateCodeBlockTabs, parseCodeBlockAttributes, rehypeCode, rehypeCodeDefaultOptions, rehypeToc, remarkAdmonition, remarkCodeTab, remarkDirectiveAdmonition, remarkFeedbackBlock, remarkGfm, remarkHeading, remarkImage, remarkMdxFiles, remarkMdxMermaid, remarkNpm, remarkSteps, remarkStructure, remarkStructureDefaultOptions, structure, transformerIcon, transformerTab };
@@ -1,2 +1,2 @@
1
- import { a as CodeBlockIcon, i as transformerTab, n as rehypeCode, o as transformerIcon, r as rehypeCodeDefaultOptions, t as RehypeCodeOptions } from "../rehype-code-Bd52chOe.js";
1
+ import { a as CodeBlockIcon, i as transformerTab, n as rehypeCode, o as transformerIcon, r as rehypeCodeDefaultOptions, t as RehypeCodeOptions } from "../rehype-code-BUrju-yF.js";
2
2
  export { CodeBlockIcon, RehypeCodeOptions, rehypeCode, rehypeCodeDefaultOptions, transformerIcon, transformerTab };
@@ -1,5 +1,5 @@
1
- import "../shiki-DoHr6fEj.js";
1
+ import "../shiki-B4NO99XD.js";
2
2
  import "./codeblock-utils.js";
3
- import { i as transformerIcon, n as rehypeCodeDefaultOptions, r as transformerTab, t as rehypeCode } from "../rehype-code-j8FAEnuU.js";
3
+ import { i as transformerIcon, n as rehypeCodeDefaultOptions, r as transformerTab, t as rehypeCode } from "../rehype-code-Ct5Pb6BZ.js";
4
4
 
5
5
  export { rehypeCode, rehypeCodeDefaultOptions, transformerIcon, transformerTab };
@@ -1,2 +1,2 @@
1
- import { n as rehypeToc, t as RehypeTocOptions } from "../rehype-toc-BJVsblvp.js";
1
+ import { n as rehypeToc, t as RehypeTocOptions } from "../rehype-toc-Dcgzd_Vy.js";
2
2
  export { RehypeTocOptions, rehypeToc };
@@ -1,3 +1,3 @@
1
- import { t as rehypeToc } from "../rehype-toc-Dqgey2tW.js";
1
+ import { t as rehypeToc } from "../rehype-toc-CTG0x7La.js";
2
2
 
3
3
  export { rehypeToc };
@@ -1,2 +1,2 @@
1
- import { n as remarkAdmonition, t as RemarkAdmonitionOptions } from "../remark-admonition-Chku_iWO.js";
1
+ import { n as remarkAdmonition, t as RemarkAdmonitionOptions } from "../remark-admonition-BvgS4oU1.js";
2
2
  export { RemarkAdmonitionOptions, remarkAdmonition };
@@ -1,4 +1,4 @@
1
- import { t as flattenNode } from "../mdast-utils-ix4DsXJP.js";
1
+ import { t as flattenNode } from "../mdast-utils-B8O-41y4.js";
2
2
  import { visit } from "unist-util-visit";
3
3
 
4
4
  //#region src/mdx-plugins/remark-admonition.ts
@@ -1,2 +1,2 @@
1
- import { n as remarkCodeTab, t as RemarkCodeTabOptions } from "../remark-code-tab-C0f6BPcw.js";
1
+ import { n as remarkCodeTab, t as RemarkCodeTabOptions } from "../remark-code-tab-Ds_BdYXz.js";
2
2
  export { RemarkCodeTabOptions, remarkCodeTab };
@@ -1 +1 @@
1
- {"version":3,"file":"remark-code-tab.js","names":["children: MdxJsxFlowElement[]","children","localTabs: TabType"],"sources":["../../src/mdx-plugins/remark-code-tab.ts"],"sourcesContent":["import type { Processor, Transformer } from 'unified';\nimport type { BlockContent, Code, DefinitionContent, Root } from 'mdast';\nimport { visit } from 'unist-util-visit';\nimport type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport { generateCodeBlockTabs, parseCodeBlockAttributes } from '@/mdx-plugins/codeblock-utils';\n\ntype TabType = keyof typeof Types;\nexport interface RemarkCodeTabOptions {\n Tabs?: TabType;\n\n /**\n * Parse MDX in tab values\n *\n * @defaultValue false\n */\n parseMdx?: boolean;\n}\n\ndeclare module 'mdast' {\n export interface CodeData {\n tab?: string;\n }\n}\n\nconst Tabs = {\n convert(\n processor: Processor,\n nodes: Code[],\n withMdx = false,\n withParent = true,\n ): MdxJsxFlowElement {\n const tabs = Array.from(processTabValue(nodes).entries());\n\n if (!withMdx) {\n const children: MdxJsxFlowElement[] = tabs.map(([name, codes]) => {\n return {\n type: 'mdxJsxFlowElement',\n name: 'Tab',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'value',\n value: name,\n },\n ],\n children: codes,\n };\n });\n\n if (!withParent) return createFragment(children);\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'Tabs',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'items',\n value: {\n type: 'mdxJsxAttributeValueExpression',\n value: tabs.map(([name]) => name).join(', '),\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n comments: [],\n body: [\n {\n type: 'ExpressionStatement',\n expression: {\n type: 'ArrayExpression',\n elements: tabs.map(([name]) => ({\n type: 'Literal',\n value: name,\n })),\n },\n },\n ],\n },\n },\n },\n },\n ],\n children,\n };\n }\n\n const children: MdxJsxFlowElement[] = [\n {\n type: 'mdxJsxFlowElement',\n name: 'TabsList',\n attributes: [],\n children: tabs.map(([name]) => ({\n type: 'mdxJsxFlowElement',\n name: 'TabsTrigger',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'value',\n value: name,\n },\n ],\n children: [mdxToAst(processor, name) as unknown as BlockContent],\n })),\n },\n ...tabs.map(\n ([name, codes]) =>\n ({\n type: 'mdxJsxFlowElement',\n name: 'TabsContent',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'value',\n value: name,\n },\n ],\n children: codes,\n }) as MdxJsxFlowElement,\n ),\n ];\n\n if (!withParent) return createFragment(children);\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'Tabs',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'defaultValue',\n value: tabs[0][0],\n },\n ],\n children,\n };\n },\n};\n\nconst CodeBlockTabs = {\n convert(\n processor: Processor,\n nodes: Code[],\n withMdx = false,\n withParent = true,\n ): MdxJsxFlowElement {\n const tabs = Array.from(processTabValue(nodes).entries());\n\n const node = generateCodeBlockTabs({\n defaultValue: tabs[0][0],\n triggers: tabs.map(([name]) => ({\n value: name,\n children: [\n withMdx\n ? (mdxToAst(processor, name) as unknown as BlockContent)\n : {\n type: 'text',\n value: name,\n },\n ],\n })),\n tabs: tabs.map(([name, codes]) => ({\n value: name,\n children: codes,\n })),\n });\n\n if (!withParent) return createFragment(node.children);\n return node;\n },\n};\n\nconst Types = {\n CodeBlockTabs,\n Tabs,\n};\n\nexport function remarkCodeTab(\n this: Processor,\n options: RemarkCodeTabOptions = {},\n): Transformer<Root, Root> {\n const { parseMdx = false, Tabs = 'CodeBlockTabs' } = options;\n\n return (tree) => {\n const ignored = new WeakSet();\n\n visit(tree, (node) => {\n if (!('children' in node) || ignored.has(node)) return 'skip';\n let localTabs: TabType = Tabs;\n let localParseMdx = parseMdx;\n let withParent = true;\n\n if (node.type === 'mdxJsxFlowElement' && node.name && node.name in Types) {\n withParent = false;\n localTabs = node.name as TabType;\n\n // for `Tabs` in simple mode, it doesn't support MDX tab names\n if (node.name === 'Tabs' && localParseMdx) {\n localParseMdx = node.attributes.every(\n (attribute) => attribute.type !== 'mdxJsxAttribute' || attribute.name !== 'items',\n );\n }\n }\n\n let start = -1;\n let end = 0;\n const close = () => {\n if (start === -1 || start === end) return;\n const replacement = Types[localTabs].convert(\n this,\n node.children.slice(start, end) as Code[],\n localParseMdx,\n withParent,\n );\n\n ignored.add(replacement);\n node.children.splice(start, end - start, replacement);\n end = start;\n start = -1;\n };\n\n for (; end < node.children.length; end++) {\n const child = node.children[end];\n if (child.type !== 'code' || !child.meta) {\n close();\n continue;\n }\n\n const meta = parseCodeBlockAttributes(child.meta, ['tab']);\n if (!meta.attributes.tab) {\n close();\n continue;\n }\n\n if (start === -1) start = end;\n child.meta = meta.rest;\n child.data ??= {};\n child.data.tab = meta.attributes.tab;\n }\n\n close();\n });\n };\n}\n\nfunction processTabValue(nodes: Code[]) {\n const out = new Map<string, Code[]>();\n\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n const name = node.data?.tab ?? `Tab ${i + 1}`;\n const li = out.get(name) ?? [];\n li.push(node);\n out.set(name, li);\n }\n return out;\n}\n\n/**\n * MDX tab name to tab trigger node children\n */\nfunction mdxToAst(processor: Processor, name: string) {\n const node = processor.parse(name) as Root;\n\n if (node.type === 'root') {\n node.children = node.children.flatMap((child) => {\n if (child.type === 'paragraph') return child.children;\n\n return child;\n });\n }\n\n return node;\n}\n\nfunction createFragment(children: (BlockContent | DefinitionContent)[]): MdxJsxFlowElement {\n return {\n type: 'mdxJsxF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AO,IAAI,EAC/B,eACA,WACD;AAED,YAAQ,IAAI,YAAY;AACxB,SAAK,SAAS,OAAO,OAAO,MAAM,OAAO,YAAY;AACrD,UAAM;AACN,YAAQ;;AAGV,UAAO,MAAM,KAAK,SAAS,QAAQ,OAAO;IACxC,MAAM,QAAQ,KAAK,SAAS;AAC5B,QAAI,MAAM,SAAS,UAAU,CAAC,MAAM,MAAM;AACxC,YAAO;AACP;;IAGF,MAAM,OAAO,yBAAyB,MAAM,MAAM,CAAC,MAAM,CAAC;AAC1D,QAAI,CAAC,KAAK,WAAW,KAAK;AACxB,YAAO;AACP;;AAGF,QAAI,UAAU,GAAI,SAAQ;AAC1B,UAAM,OAAO,KAAK;AAClB,UAAM,SAAS,EAAE;AACjB,UAAM,KAAK,MAAM,KAAK,WAAW;;AAGnC,UAAO;IACP;;;AAIN,SAAS,gBAAgB,OAAe;CACtC,MAAM,sBAAM,IAAI,KAAqB;AAErC,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,MAAM,OAAO,MAAM;EACnB,MAAM,OAAO,KAAK,MAAM,OAAO,OAAO,IAAI;EAC1C,MAAM,KAAK,IAAI,IAAI,KAAK,IAAI,EAAE;AAC9B,KAAG,KAAK,KAAK;AACb,MAAI,IAAI,MAAM,GAAG;;AAEnB,QAAO;;;;;AAMT,SAAS,SAAS,WAAsB,MAAc;CACpD,MAAM,OAAO,UAAU,MAAM,KAAK;AAElC,KAAI,KAAK,SAAS,OAChB,MAAK,WAAW,KAAK,SAAS,SAAS,UAAU;AAC/C,MAAI,MAAM,SAAS,YAAa,QAAO,MAAM;AAE7C,SAAO;GACP;AAGJ,QAAO;;AAGT,SAAS,eAAe,UAAmE;AACzF,QAAO;EACL,MAAM;EACN,MAAM;EACN,YAAY,EAAE;EACd;EACD"}
1
+ {"version":3,"file":"remark-code-tab.js","names":["children"],"sources":["../../src/mdx-plugins/remark-code-tab.ts"],"sourcesContent":["import type { Processor, Transformer } from 'unified';\nimport type { BlockContent, Code, DefinitionContent, Root } from 'mdast';\nimport { visit } from 'unist-util-visit';\nimport type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport { generateCodeBlockTabs, parseCodeBlockAttributes } from '@/mdx-plugins/codeblock-utils';\n\ntype TabType = keyof typeof Types;\nexport interface RemarkCodeTabOptions {\n Tabs?: TabType;\n\n /**\n * Parse MDX in tab values\n *\n * @defaultValue false\n */\n parseMdx?: boolean;\n}\n\ndeclare module 'mdast' {\n export interface CodeData {\n tab?: string;\n }\n}\n\nconst Tabs = {\n convert(\n processor: Processor,\n nodes: Code[],\n withMdx = false,\n withParent = true,\n ): MdxJsxFlowElement {\n const tabs = Array.from(processTabValue(nodes).entries());\n\n if (!withMdx) {\n const children: MdxJsxFlowElement[] = tabs.map(([name, codes]) => {\n return {\n type: 'mdxJsxFlowElement',\n name: 'Tab',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'value',\n value: name,\n },\n ],\n children: codes,\n };\n });\n\n if (!withParent) return createFragment(children);\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'Tabs',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'items',\n value: {\n type: 'mdxJsxAttributeValueExpression',\n value: tabs.map(([name]) => name).join(', '),\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n comments: [],\n body: [\n {\n type: 'ExpressionStatement',\n expression: {\n type: 'ArrayExpression',\n elements: tabs.map(([name]) => ({\n type: 'Literal',\n value: name,\n })),\n },\n },\n ],\n },\n },\n },\n },\n ],\n children,\n };\n }\n\n const children: MdxJsxFlowElement[] = [\n {\n type: 'mdxJsxFlowElement',\n name: 'TabsList',\n attributes: [],\n children: tabs.map(([name]) => ({\n type: 'mdxJsxFlowElement',\n name: 'TabsTrigger',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'value',\n value: name,\n },\n ],\n children: [mdxToAst(processor, name) as unknown as BlockContent],\n })),\n },\n ...tabs.map(\n ([name, codes]) =>\n ({\n type: 'mdxJsxFlowElement',\n name: 'TabsContent',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'value',\n value: name,\n },\n ],\n children: codes,\n }) as MdxJsxFlowElement,\n ),\n ];\n\n if (!withParent) return createFragment(children);\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'Tabs',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'defaultValue',\n value: tabs[0][0],\n },\n ],\n children,\n };\n },\n};\n\nconst CodeBlockTabs = {\n convert(\n processor: Processor,\n nodes: Code[],\n withMdx = false,\n withParent = true,\n ): MdxJsxFlowElement {\n const tabs = Array.from(processTabValue(nodes).entries());\n\n const node = generateCodeBlockTabs({\n defaultValue: tabs[0][0],\n triggers: tabs.map(([name]) => ({\n value: name,\n children: [\n withMdx\n ? (mdxToAst(processor, name) as unknown as BlockContent)\n : {\n type: 'text',\n value: name,\n },\n ],\n })),\n tabs: tabs.map(([name, codes]) => ({\n value: name,\n children: codes,\n })),\n });\n\n if (!withParent) return createFragment(node.children);\n return node;\n },\n};\n\nconst Types = {\n CodeBlockTabs,\n Tabs,\n};\n\nexport function remarkCodeTab(\n this: Processor,\n options: RemarkCodeTabOptions = {},\n): Transformer<Root, Root> {\n const { parseMdx = false, Tabs = 'CodeBlockTabs' } = options;\n\n return (tree) => {\n const ignored = new WeakSet();\n\n visit(tree, (node) => {\n if (!('children' in node) || ignored.has(node)) return 'skip';\n let localTabs: TabType = Tabs;\n let localParseMdx = parseMdx;\n let withParent = true;\n\n if (node.type === 'mdxJsxFlowElement' && node.name && node.name in Types) {\n withParent = false;\n localTabs = node.name as TabType;\n\n // for `Tabs` in simple mode, it doesn't support MDX tab names\n if (node.name === 'Tabs' && localParseMdx) {\n localParseMdx = node.attributes.every(\n (attribute) => attribute.type !== 'mdxJsxAttribute' || attribute.name !== 'items',\n );\n }\n }\n\n let start = -1;\n let end = 0;\n const close = () => {\n if (start === -1 || start === end) return;\n const replacement = Types[localTabs].convert(\n this,\n node.children.slice(start, end) as Code[],\n localParseMdx,\n withParent,\n );\n\n ignored.add(replacement);\n node.children.splice(start, end - start, replacement);\n end = start;\n start = -1;\n };\n\n for (; end < node.children.length; end++) {\n const child = node.children[end];\n if (child.type !== 'code' || !child.meta) {\n close();\n continue;\n }\n\n const meta = parseCodeBlockAttributes(child.meta, ['tab']);\n if (!meta.attributes.tab) {\n close();\n continue;\n }\n\n if (start === -1) start = end;\n child.meta = meta.rest;\n child.data ??= {};\n child.data.tab = meta.attributes.tab;\n }\n\n close();\n });\n };\n}\n\nfunction processTabValue(nodes: Code[]) {\n const out = new Map<string, Code[]>();\n\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n const name = node.data?.tab ?? `Tab ${i + 1}`;\n const li = out.get(name) ?? [];\n li.push(node);\n out.set(name, li);\n }\n return out;\n}\n\n/**\n * MDX tab name to tab trigger node children\n */\nfunction mdxToAst(processor: Processor, name: string) {\n const node = processor.parse(name) as Root;\n\n if (node.type === 'root') {\n node.children = node.children.flatMap((child) => {\n if (child.type === 'paragraph') return child.children;\n\n return child;\n });\n }\n\n return node;\n}\n\nfunction createFragment(children: (BlockContent | DefinitionContent)[]): MdxJsxFlowElement {\n return {\n type: 'mdxJsxFlowElement',\n name: null,\n attributes: [],\n children,\n };\n}\n"],"mappings":";;;;AA4KA,MAAM,QAAQ;CACZ,eAlCoB,EACpB,QACE,WACA,OACA,UAAU,OACV,aAAa,MACM;EACnB,MAAM,OAAO,MAAM,KAAK,gBAAgB,MAAM,CAAC,SAAS,CAAC;EAEzD,MAAM,OAAO,sBAAsB;GACjC,cAAc,KAAK,GAAG;GACtB,UAAU,KAAK,KAAK,CAAC,WAAW;IAC9B,OAAO;IACP,UAAU,CACR,UACK,SAAS,WAAW,KAAK,GAC1B;KACE,MAAM;KACN,OAAO;KACR,CACN;IACF,EAAE;GACH,MAAM,KAAK,KAAK,CAAC,MAAM,YAAY;IACjC,OAAO;IACP,UAAU;IACX,EAAE;GACJ,CAAC;AAEF,MAAI,CAAC,WA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WAAW;;AAGnC,UAAO;IACP;;;AAIN,SAAS,gBAAgB,OAAe;CACtC,MAAM,sBAAM,IAAI,KAAqB;AAErC,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,MAAM,OAAO,MAAM;EACnB,MAAM,OAAO,KAAK,MAAM,OAAO,OAAO,IAAI;EAC1C,MAAM,KAAK,IAAI,IAAI,KAAK,IAAI,EAAE;AAC9B,KAAG,KAAK,KAAK;AACb,MAAI,IAAI,MAAM,GAAG;;AAEnB,QAAO;;;;;AAMT,SAAS,SAAS,WAAsB,MAAc;CACpD,MAAM,OAAO,UAAU,MAAM,KAAK;AAElC,KAAI,KAAK,SAAS,OAChB,MAAK,WAAW,KAAK,SAAS,SAAS,UAAU;AAC/C,MAAI,MAAM,SAAS,YAAa,QAAO,MAAM;AAE7C,SAAO;GACP;AAGJ,QAAO;;AAGT,SAAS,eAAe,UAAmE;AACzF,QAAO;EACL,MAAM;EACN,MAAM;EACN,YAAY,EAAE;EACd;EACD"}
@@ -1,2 +1,2 @@
1
- import { n as remarkDirectiveAdmonition, t as RemarkDirectiveAdmonitionOptions } from "../remark-directive-admonition-CBwJdh9z.js";
1
+ import { n as remarkDirectiveAdmonition, t as RemarkDirectiveAdmonitionOptions } from "../remark-directive-admonition-02cR5K1L.js";
2
2
  export { RemarkDirectiveAdmonitionOptions, remarkDirectiveAdmonition };
@@ -1 +1 @@
1
- {"version":3,"file":"remark-directive-admonition.js","names":["attributes: MdxJsxAttribute[]","titleNodes: PhrasingContent[]","descriptionNodes: (BlockContent | DefinitionContent)[]","children: MdxJsxFlowElement[]"],"sources":["../../src/mdx-plugins/remark-directive-admonition.ts"],"sourcesContent":["import type { BlockContent, DefinitionContent, PhrasingContent, Root } from 'mdast';\nimport type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport { Transformer } from 'unified';\nimport { visit } from 'unist-util-visit';\n\nexport interface RemarkDirectiveAdmonitionOptions {\n /**\n * the tag names of Callout component.\n */\n tags?: {\n CalloutContainer?: string;\n CalloutTitle?: string;\n CalloutDescription?: string;\n };\n\n /**\n * All supported admonition types and their linked Callout type.\n *\n * When specified, all defaults will be cleared.\n */\n types?: Record<string, string>;\n}\n\n/**\n * Remark Plugin to support Admonition syntax in Docusaurus, useful for migrating from Docusaurus.\n *\n * Requires [`remark-directive`](https://github.com/remarkjs/remark-directive) to be configured.\n */\nexport function remarkDirectiveAdmonition({\n tags: {\n CalloutContainer = 'CalloutContainer',\n CalloutTitle = 'CalloutTitle',\n CalloutDescription = 'CalloutDescription',\n } = {},\n types = {\n note: 'info',\n tip: 'info',\n info: 'info',\n warn: 'warning',\n warning: 'warning',\n danger: 'error',\n success: 'success',\n },\n}: RemarkDirectiveAdmonitionOptions = {}): Transformer<Root, Root> {\n return (tree) => {\n visit(tree, 'containerDirective', (node) => {\n if (!(node.name in types)) return;\n\n const attributes: MdxJsxAttribute[] = [\n {\n type: 'mdxJsxAttribute',\n name: 'type',\n value: types[node.name],\n },\n ];\n\n for (const [k, v] of Object.entries(node.attributes ?? {})) {\n attributes.push({\n type: 'mdxJsxAttribute',\n name: k,\n value: v,\n });\n }\n\n const titleNodes: PhrasingContent[] = [];\n const descriptionNodes: (BlockContent | DefinitionContent)[] = [];\n\n for (const item of node.children) {\n if (item.type === 'paragraph' && item.data?.directiveLabel) {\n titleNodes.push(...item.children);\n } else {\n descriptionNodes.push(item);\n }\n }\n\n const children: MdxJsxFlowElement[] = [];\n\n if (titleNodes.length > 0) {\n children.push({\n type: 'mdxJsxFlowElement',\n name: CalloutTitle,\n attributes: [],\n children: titleNodes as BlockContent[],\n });\n }\n\n if (descriptionNodes.length > 0) {\n children.push({\n type: 'mdxJsxFlowElement',\n name: CalloutDescription,\n attributes: [],\n children: descriptionNodes,\n });\n }\n\n Object.assign(node, {\n type: 'mdxJsxFlowElement',\n attributes,\n name: CalloutContainer,\n children,\n } satisfies MdxJsxFlowElement);\n });\n };\n}\n"],"mappings":";;;;;;;;AA4BA,SAAgB,0BAA0B,EACxC,MAAM,EACJ,mBAAmB,oBACnB,eAAe,gBACf,qBAAqB,yBACnB,EAAE,EACN,QAAQ;CACN,MAAM;CACN,KAAK;CACL,MAAM;CACN,MAAM;CACN,SAAS;CACT,QAAQ;CACR,SAAS;CACV,KACmC,EAAE,EAA2B;AACjE,SAAQ,SAAS;AACf,QAAM,MAAM,uBAAuB,SAAS;AAC1C,OAAI,EAAE,KAAK,QAAQ,OAAQ;GAE3B,MAAMA,aAAgC,CACpC;IACE,MAAM;IACN,MAAM;IACN,OAAO,MAAM,KAAK;IACnB,CACF;AAED,QAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,KAAK,cAAc,EAAE,CAAC,CACxD,YAAW,KAAK;IACd,MAAM;IACN,MAAM;IACN,OAAO;IACR,CAAC;GAGJ,MAAMC,aAAgC,EAAE;GACxC,MAAMC,mBAAyD,EAAE;AAEjE,QAAK,MAAM,QAAQ,KAAK,SACtB,KAAI,KAAK,SAAS,eAAe,KAAK,MAAM,eAC1C,YAAW,KAAK,GAAG,KAAK,SAAS;OAEjC,kBAAiB,KAAK,KAAK;GAI/B,MAAMC,WAAgC,EAAE;AAExC,OAAI,WAAW,SAAS,EACtB,UAAS,KAAK;IACZ,MAAM;IACN,MAAM;IACN,YAAY,EAAE;IACd,UAAU;IACX,CAAC;AAGJ,OAAI,iBAAiB,SAAS,EAC5B,UAAS,KAAK;IACZ,MAAM;IACN,MAAM;IACN,YAAY,EAAE;IACd,UAAU;IACX,CAAC;AAGJ,UAAO,OAAO,MAAM;IAClB,MAAM;IACN;IACA,MAAM;IACN;IACD,CAA6B;IAC9B"}
1
+ {"version":3,"file":"remark-directive-admonition.js","names":[],"sources":["../../src/mdx-plugins/remark-directive-admonition.ts"],"sourcesContent":["import type { BlockContent, DefinitionContent, PhrasingContent, Root } from 'mdast';\nimport type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport { Transformer } from 'unified';\nimport { visit } from 'unist-util-visit';\n\nexport interface RemarkDirectiveAdmonitionOptions {\n /**\n * the tag names of Callout component.\n */\n tags?: {\n CalloutContainer?: string;\n CalloutTitle?: string;\n CalloutDescription?: string;\n };\n\n /**\n * All supported admonition types and their linked Callout type.\n *\n * When specified, all defaults will be cleared.\n */\n types?: Record<string, string>;\n}\n\n/**\n * Remark Plugin to support Admonition syntax in Docusaurus, useful for migrating from Docusaurus.\n *\n * Requires [`remark-directive`](https://github.com/remarkjs/remark-directive) to be configured.\n */\nexport function remarkDirectiveAdmonition({\n tags: {\n CalloutContainer = 'CalloutContainer',\n CalloutTitle = 'CalloutTitle',\n CalloutDescription = 'CalloutDescription',\n } = {},\n types = {\n note: 'info',\n tip: 'info',\n info: 'info',\n warn: 'warning',\n warning: 'warning',\n danger: 'error',\n success: 'success',\n },\n}: RemarkDirectiveAdmonitionOptions = {}): Transformer<Root, Root> {\n return (tree) => {\n visit(tree, 'containerDirective', (node) => {\n if (!(node.name in types)) return;\n\n const attributes: MdxJsxAttribute[] = [\n {\n type: 'mdxJsxAttribute',\n name: 'type',\n value: types[node.name],\n },\n ];\n\n for (const [k, v] of Object.entries(node.attributes ?? {})) {\n attributes.push({\n type: 'mdxJsxAttribute',\n name: k,\n value: v,\n });\n }\n\n const titleNodes: PhrasingContent[] = [];\n const descriptionNodes: (BlockContent | DefinitionContent)[] = [];\n\n for (const item of node.children) {\n if (item.type === 'paragraph' && item.data?.directiveLabel) {\n titleNodes.push(...item.children);\n } else {\n descriptionNodes.push(item);\n }\n }\n\n const children: MdxJsxFlowElement[] = [];\n\n if (titleNodes.length > 0) {\n children.push({\n type: 'mdxJsxFlowElement',\n name: CalloutTitle,\n attributes: [],\n children: titleNodes as BlockContent[],\n });\n }\n\n if (descriptionNodes.length > 0) {\n children.push({\n type: 'mdxJsxFlowElement',\n name: CalloutDescription,\n attributes: [],\n children: descriptionNodes,\n });\n }\n\n Object.assign(node, {\n type: 'mdxJsxFlowElement',\n attributes,\n name: CalloutContainer,\n children,\n } satisfies MdxJsxFlowElement);\n });\n };\n}\n"],"mappings":";;;;;;;;AA4BA,SAAgB,0BAA0B,EACxC,MAAM,EACJ,mBAAmB,oBACnB,eAAe,gBACf,qBAAqB,yBACnB,EAAE,EACN,QAAQ;CACN,MAAM;CACN,KAAK;CACL,MAAM;CACN,MAAM;CACN,SAAS;CACT,QAAQ;CACR,SAAS;CACV,KACmC,EAAE,EAA2B;AACjE,SAAQ,SAAS;AACf,QAAM,MAAM,uBAAuB,SAAS;AAC1C,OAAI,EAAE,KAAK,QAAQ,OAAQ;GAE3B,MAAM,aAAgC,CACpC;IACE,MAAM;IACN,MAAM;IACN,OAAO,MAAM,KAAK;IACnB,CACF;AAED,QAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,KAAK,cAAc,EAAE,CAAC,CACxD,YAAW,KAAK;IACd,MAAM;IACN,MAAM;IACN,OAAO;IACR,CAAC;GAGJ,MAAM,aAAgC,EAAE;GACxC,MAAM,mBAAyD,EAAE;AAEjE,QAAK,MAAM,QAAQ,KAAK,SACtB,KAAI,KAAK,SAAS,eAAe,KAAK,MAAM,eAC1C,YAAW,KAAK,GAAG,KAAK,SAAS;OAEjC,kBAAiB,KAAK,KAAK;GAI/B,MAAM,WAAgC,EAAE;AAExC,OAAI,WAAW,SAAS,EACtB,UAAS,KAAK;IACZ,MAAM;IACN,MAAM;IACN,YAAY,EAAE;IACd,UAAU;IACX,CAAC;AAGJ,OAAI,iBAAiB,SAAS,EAC5B,UAAS,KAAK;IACZ,MAAM;IACN,MAAM;IACN,YAAY,EAAE;IACd,UAAU;IACX,CAAC;AAGJ,UAAO,OAAO,MAAM;IAClB,MAAM;IACN;IACA,MAAM;IACN;IACD,CAA6B;IAC9B"}
@@ -0,0 +1,2 @@
1
+ import { n as RemarkFeedbackBlockOptions, r as remarkFeedbackBlock, t as FeedbackBlockProps } from "../remark-feedback-block-fAyt4LdQ.js";
2
+ export { FeedbackBlockProps, RemarkFeedbackBlockOptions, remarkFeedbackBlock };
@@ -0,0 +1,48 @@
1
+ import { t as flattenNode } from "../mdast-utils-B8O-41y4.js";
2
+ import { visit } from "unist-util-visit";
3
+ import { createHash } from "node:crypto";
4
+
5
+ //#region src/mdx-plugins/remark-feedback-block.ts
6
+ /**
7
+ * Generate MDX `<FeedbackBlock />` elements with an unique `id` for every block-like element.
8
+ *
9
+ * Note: the uniqueness is only guaranteed per MDX file/page.
10
+ */
11
+ function remarkFeedbackBlock({ generateHash = ({ body }) => createHash("md5").update(body).digest("hex").substring(0, 16), tagName = "FeedbackBlock", resolve = (node) => node.type === "paragraph" || node.type === "image" || node.type === "list", generateBody = true } = {}) {
12
+ return (tree) => {
13
+ const counts = /* @__PURE__ */ new Map();
14
+ visit(tree, (node, index, parent) => {
15
+ if (node.type === "root") return;
16
+ const resolved = resolve(node);
17
+ if (resolved === false) return;
18
+ if (resolved === "skip") return "skip";
19
+ const text = flattenNode(node).trim();
20
+ if (text.length === 0 || !parent || typeof index !== "number") return;
21
+ let id = generateHash({ body: text });
22
+ const count = counts.get(id) ?? 0;
23
+ if (count > 0) id = `${id}-${count}`;
24
+ counts.set(id, count + 1);
25
+ const wrapper = {
26
+ type: "mdxJsxFlowElement",
27
+ name: tagName,
28
+ attributes: [{
29
+ type: "mdxJsxAttribute",
30
+ name: "id",
31
+ value: id
32
+ }],
33
+ children: [node]
34
+ };
35
+ if (generateBody) wrapper.attributes.push({
36
+ type: "mdxJsxAttribute",
37
+ name: "body",
38
+ value: text
39
+ });
40
+ parent.children[index] = wrapper;
41
+ return "skip";
42
+ });
43
+ };
44
+ }
45
+
46
+ //#endregion
47
+ export { remarkFeedbackBlock };
48
+ //# sourceMappingURL=remark-feedback-block.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remark-feedback-block.js","names":[],"sources":["../../src/mdx-plugins/remark-feedback-block.ts"],"sourcesContent":["import type { Transformer } from 'unified';\nimport type { BlockContent, Root, RootContent } from 'mdast';\nimport type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport { visit } from 'unist-util-visit';\nimport { createHash } from 'node:crypto';\nimport { flattenNode } from './mdast-utils';\n\nexport interface RemarkFeedbackBlockOptions {\n /**\n * generate block ID, default to using MD5.\n */\n generateHash?: (ctx: { body: string }) => string;\n\n /**\n * @defaultValue FeedbackBlock\n */\n tagName?: string;\n\n /**\n * determine how the node should be resolved into a feedback block.\n *\n * scan paragraph, list, and image nodes by default.\n *\n * @returns\n * - `true`: convert the node into a feedback block.\n * - `false`: skip the current node and look into its children.\n * - `skip`: skip the current node and its children.\n */\n resolve?: (node: RootContent) => boolean | 'skip';\n\n /**\n * generate & include the block body to `<FeedbackBlock body=\"...\" />` as string\n *\n * @defaultValue true\n */\n generateBody?: boolean;\n}\n\nexport interface FeedbackBlockProps {\n id: string;\n /** the text body of block, only exists when `generateBody` is enabled. */\n body?: string;\n}\n\n/**\n * Generate MDX `<FeedbackBlock />` elements with an unique `id` for every block-like element.\n *\n * Note: the uniqueness is only guaranteed per MDX file/page.\n */\nexport function remarkFeedbackBlock({\n generateHash = ({ body }) => createHash('md5').update(body).digest('hex').substring(0, 16),\n tagName = 'FeedbackBlock',\n resolve = (node) => node.type === 'paragraph' || node.type === 'image' || node.type === 'list',\n generateBody = true,\n}: RemarkFeedbackBlockOptions = {}): Transformer<Root, Root> {\n return (tree) => {\n const counts = new Map<string, number>();\n\n visit(tree, (node, index, parent) => {\n if (node.type === 'root') return;\n const resolved = resolve(node);\n if (resolved === false) return;\n if (resolved === 'skip') return 'skip';\n\n const text = flattenNode(node).trim();\n if (text.length === 0 || !parent || typeof index !== 'number') return;\n let id = generateHash({ body: text });\n const count = counts.get(id) ?? 0;\n if (count > 0) id = `${id}-${count}`;\n counts.set(id, count + 1);\n\n const wrapper: MdxJsxFlowElement = {\n type: 'mdxJsxFlowElement',\n name: tagName,\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'id',\n value: id,\n },\n ],\n children: [node as BlockContent],\n };\n if (generateBody)\n wrapper.attributes.push({\n type: 'mdxJsxAttribute',\n name: 'body',\n value: text,\n });\n\n parent.children[index] = wrapper;\n return 'skip';\n });\n };\n}\n"],"mappings":";;;;;;;;;;AAiDA,SAAgB,oBAAoB,EAClC,gBAAgB,EAAE,WAAW,WAAW,MAAM,CAAC,OAAO,KAAK,CAAC,OAAO,MAAM,CAAC,UAAU,GAAG,GAAG,EAC1F,UAAU,iBACV,WAAW,SAAS,KAAK,SAAS,eAAe,KAAK,SAAS,WAAW,KAAK,SAAS,QACxF,eAAe,SACe,EAAE,EAA2B;AAC3D,SAAQ,SAAS;EACf,MAAM,yBAAS,IAAI,KAAqB;AAExC,QAAM,OAAO,MAAM,OAAO,WAAW;AACnC,OAAI,KAAK,SAAS,OAAQ;GAC1B,MAAM,WAAW,QAAQ,KAAK;AAC9B,OAAI,aAAa,MAAO;AACxB,OAAI,aAAa,OAAQ,QAAO;GAEhC,MAAM,OAAO,YAAY,KAAK,CAAC,MAAM;AACrC,OAAI,KAAK,WAAW,KAAK,CAAC,UAAU,OAAO,UAAU,SAAU;GAC/D,IAAI,KAAK,aAAa,EAAE,MAAM,MAAM,CAAC;GACrC,MAAM,QAAQ,OAAO,IAAI,GAAG,IAAI;AAChC,OAAI,QAAQ,EAAG,MAAK,GAAG,GAAG,GAAG;AAC7B,UAAO,IAAI,IAAI,QAAQ,EAAE;GAEzB,MAAM,UAA6B;IACjC,MAAM;IACN,MAAM;IACN,YAAY,CACV;KACE,MAAM;KACN,MAAM;KACN,OAAO;KACR,CACF;IACD,UAAU,CAAC,KAAqB;IACjC;AACD,OAAI,aACF,SAAQ,WAAW,KAAK;IACtB,MAAM;IACN,MAAM;IACN,OAAO;IACR,CAAC;AAEJ,UAAO,SAAS,SAAS;AACzB,UAAO;IACP"}
@@ -1,2 +1,2 @@
1
- import { n as remarkGfm, t as RemarkGfmOptions } from "../remark-gfm-B2aZXutO.js";
1
+ import { n as remarkGfm, t as RemarkGfmOptions } from "../remark-gfm-jrvaEZw5.js";
2
2
  export { RemarkGfmOptions, remarkGfm };
@@ -1,2 +1,2 @@
1
- import { n as remarkHeading, t as RemarkHeadingOptions } from "../remark-heading-CUAe4zIu.js";
1
+ import { n as remarkHeading, t as RemarkHeadingOptions } from "../remark-heading-CSButCYt.js";
2
2
  export { RemarkHeadingOptions, remarkHeading };
@@ -1,4 +1,4 @@
1
- import { t as flattenNode } from "../mdast-utils-ix4DsXJP.js";
1
+ import { t as flattenNode } from "../mdast-utils-B8O-41y4.js";
2
2
  import Slugger from "github-slugger";
3
3
  import { visit } from "unist-util-visit";
4
4
 
@@ -1 +1 @@
1
- {"version":3,"file":"remark-heading.js","names":["toc: TOCItemType[]","flattened: string | null"],"sources":["../../src/mdx-plugins/remark-heading.ts"],"sourcesContent":["import Slugger from 'github-slugger';\nimport type { Heading, Root } from 'mdast';\nimport type { Transformer } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport type { TOCItemType } from '@/toc';\nimport { flattenNode } from '@/mdx-plugins/mdast-utils';\n\nconst slugger = new Slugger();\n\ndeclare module 'mdast' {\n export interface HeadingData extends Data {\n hProperties?: {\n id?: string;\n };\n }\n}\n\nconst regex = /\\s*\\[#(?<slug>[^]+?)]\\s*$/;\n\nexport interface RemarkHeadingOptions {\n slug?: (root: Root, heading: Heading, text: string) => string;\n\n /**\n * Allow custom headings ids\n *\n * @defaultValue true\n */\n customId?: boolean;\n\n /**\n * Attach an array of `TOCItemType` to `file.data.toc`\n *\n * @defaultValue true\n */\n generateToc?: boolean;\n}\n\n/**\n * Add heading ids and extract TOC\n */\nexport function remarkHeading({\n slug: defaultSlug,\n customId = true,\n generateToc = true,\n}: RemarkHeadingOptions = {}): Transformer<Root, Root> {\n return (root, file) => {\n const toc: TOCItemType[] = [];\n slugger.reset();\n\n visit(root, 'heading', (heading) => {\n heading.data ||= {};\n heading.data.hProperties ||= {};\n const props = heading.data.hProperties;\n\n const lastNode = heading.children.at(-1);\n if (lastNode?.type === 'text' && customId) {\n const match = regex.exec(lastNode.value);\n\n if (match?.[1]) {\n props.id = match[1];\n lastNode.value = lastNode.value.slice(0, match.index);\n }\n }\n\n let flattened: string | null = null;\n if (!props.id) {\n flattened ??= flattenNode(heading);\n\n props.id = defaultSlug ? defaultSlug(root, heading, flattened) : slugger.slug(flattened);\n }\n\n if (generateToc) {\n toc.push({\n title: flattened ?? flattenNode(heading),\n url: `#${props.id}`,\n depth: heading.depth,\n });\n }\n\n return 'skip';\n });\n\n if (generateToc) file.data.toc = toc;\n };\n}\n"],"mappings":";;;;;AAOA,MAAM,UAAU,IAAI,SAAS;AAU7B,MAAM,QAAQ;;;;AAuBd,SAAgB,cAAc,EAC5B,MAAM,aACN,WAAW,MACX,cAAc,SACU,EAAE,EAA2B;AACrD,SAAQ,MAAM,SAAS;EACrB,MAAMA,MAAqB,EAAE;AAC7B,UAAQ,OAAO;AAEf,QAAM,MAAM,YAAY,YAAY;AAClC,WAAQ,SAAS,EAAE;AACnB,WAAQ,KAAK,gBAAgB,EAAE;GAC/B,MAAM,QAAQ,QAAQ,KAAK;GAE3B,MAAM,WAAW,QAAQ,SAAS,GAAG,GAAG;AACxC,OAAI,UAAU,SAAS,UAAU,UAAU;IACzC,MAAM,QAAQ,MAAM,KAAK,SAAS,MAAM;AAExC,QAAI,QAAQ,IAAI;AACd,WAAM,KAAK,MAAM;AACjB,cAAS,QAAQ,SAAS,MAAM,MAAM,GAAG,MAAM,MAAM;;;GAIzD,IAAIC,YAA2B;AAC/B,OAAI,CAAC,MAAM,IAAI;AACb,kBAAc,YAAY,QAAQ;AAElC,UAAM,KAAK,cAAc,YAAY,MAAM,SAAS,UAAU,GAAG,QAAQ,KAAK,UAAU;;AAG1F,OAAI,YACF,KAAI,KAAK;IACP,OAAO,aAAa,YAAY,QAAQ;IACxC,KAAK,IAAI,MAAM;IACf,OAAO,QAAQ;IAChB,CAAC;AAGJ,UAAO;IACP;AAEF,MAAI,YAAa,MAAK,KAAK,MAAM"}
1
+ {"version":3,"file":"remark-heading.js","names":[],"sources":["../../src/mdx-plugins/remark-heading.ts"],"sourcesContent":["import Slugger from 'github-slugger';\nimport type { Heading, Root } from 'mdast';\nimport type { Transformer } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport type { TOCItemType } from '@/toc';\nimport { flattenNode } from '@/mdx-plugins/mdast-utils';\n\nconst slugger = new Slugger();\n\ndeclare module 'mdast' {\n export interface HeadingData extends Data {\n hProperties?: {\n id?: string;\n };\n }\n}\n\nconst regex = /\\s*\\[#(?<slug>[^]+?)]\\s*$/;\n\nexport interface RemarkHeadingOptions {\n slug?: (root: Root, heading: Heading, text: string) => string;\n\n /**\n * Allow custom headings ids\n *\n * @defaultValue true\n */\n customId?: boolean;\n\n /**\n * Attach an array of `TOCItemType` to `file.data.toc`\n *\n * @defaultValue true\n */\n generateToc?: boolean;\n}\n\n/**\n * Add heading ids and extract TOC\n */\nexport function remarkHeading({\n slug: defaultSlug,\n customId = true,\n generateToc = true,\n}: RemarkHeadingOptions = {}): Transformer<Root, Root> {\n return (root, file) => {\n const toc: TOCItemType[] = [];\n slugger.reset();\n\n visit(root, 'heading', (heading) => {\n heading.data ||= {};\n heading.data.hProperties ||= {};\n const props = heading.data.hProperties;\n\n const lastNode = heading.children.at(-1);\n if (lastNode?.type === 'text' && customId) {\n const match = regex.exec(lastNode.value);\n\n if (match?.[1]) {\n props.id = match[1];\n lastNode.value = lastNode.value.slice(0, match.index);\n }\n }\n\n let flattened: string | null = null;\n if (!props.id) {\n flattened ??= flattenNode(heading);\n\n props.id = defaultSlug ? defaultSlug(root, heading, flattened) : slugger.slug(flattened);\n }\n\n if (generateToc) {\n toc.push({\n title: flattened ?? flattenNode(heading),\n url: `#${props.id}`,\n depth: heading.depth,\n });\n }\n\n return 'skip';\n });\n\n if (generateToc) file.data.toc = toc;\n };\n}\n"],"mappings":";;;;;AAOA,MAAM,UAAU,IAAI,SAAS;AAU7B,MAAM,QAAQ;;;;AAuBd,SAAgB,cAAc,EAC5B,MAAM,aACN,WAAW,MACX,cAAc,SACU,EAAE,EAA2B;AACrD,SAAQ,MAAM,SAAS;EACrB,MAAM,MAAqB,EAAE;AAC7B,UAAQ,OAAO;AAEf,QAAM,MAAM,YAAY,YAAY;AAClC,WAAQ,SAAS,EAAE;AACnB,WAAQ,KAAK,gBAAgB,EAAE;GAC/B,MAAM,QAAQ,QAAQ,KAAK;GAE3B,MAAM,WAAW,QAAQ,SAAS,GAAG,GAAG;AACxC,OAAI,UAAU,SAAS,UAAU,UAAU;IACzC,MAAM,QAAQ,MAAM,KAAK,SAAS,MAAM;AAExC,QAAI,QAAQ,IAAI;AACd,WAAM,KAAK,MAAM;AACjB,cAAS,QAAQ,SAAS,MAAM,MAAM,GAAG,MAAM,MAAM;;;GAIzD,IAAI,YAA2B;AAC/B,OAAI,CAAC,MAAM,IAAI;AACb,kBAAc,YAAY,QAAQ;AAElC,UAAM,KAAK,cAAc,YAAY,MAAM,SAAS,UAAU,GAAG,QAAQ,KAAK,UAAU;;AAG1F,OAAI,YACF,KAAI,KAAK;IACP,OAAO,aAAa,YAAY,QAAQ;IACxC,KAAK,IAAI,MAAM;IACf,OAAO,QAAQ;IAChB,CAAC;AAGJ,UAAO;IACP;AAEF,MAAI,YAAa,MAAK,KAAK,MAAM"}
@@ -1,2 +1,2 @@
1
- import { n as remarkImage, t as RemarkImageOptions } from "../remark-image-DMRnxsRO.js";
1
+ import { n as remarkImage, t as RemarkImageOptions } from "../remark-image-C3MnP-3r.js";
2
2
  export { RemarkImageOptions, remarkImage };
@@ -1 +1 @@
1
- {"version":3,"file":"remark-image.js","names":["path","importsToInject: { variableName: string; importPath: string }[]","promises: Promise<void>[]","attributes: MdxJsxAttribute[]","out: MdxJsxFlowElement"],"sources":["../../src/mdx-plugins/remark-image.ts"],"sourcesContent":["import * as path from 'node:path';\nimport type { Image, Root } from 'mdast';\nimport type { Transformer } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport type { MdxjsEsm } from 'mdast-util-mdxjs-esm';\nimport type { ISizeCalculationResult } from 'image-size/types/interface';\nimport type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport { fileURLToPath } from 'node:url';\n\nconst VALID_BLUR_EXT = ['.jpeg', '.png', '.webp', '.avif', '.jpg'];\nconst EXTERNAL_URL_REGEX = /^https?:\\/\\//;\n\ntype ExternalImageOptions =\n | {\n /**\n * timeout for fetching remote images (in milliseconds)\n */\n timeout?: number;\n }\n | boolean;\n\nexport interface RemarkImageOptions {\n /**\n * Directory or base URL to resolve absolute image paths\n */\n publicDir?: string;\n\n /**\n * Preferred placeholder type, only available with `useImport` + local images.\n *\n * @defaultValue 'blur'\n */\n placeholder?: 'blur' | 'none';\n\n /**\n * Define how to handle errors when fetching image size.\n *\n * - `error` (default): throw an error.\n * - `ignore`: do absolutely nothing (Next.js Image component may complain).\n * - `hide`: remove that image element.\n *\n * @defaultValue 'error'\n */\n onError?: 'error' | 'hide' | 'ignore' | ((error: Error) => void);\n\n /**\n * Import images in the file, and let bundlers handle it.\n *\n * ```tsx\n * import MyImage from \"./public/img.png\";\n *\n * <img src={MyImage} />\n * ```\n *\n * When disabled, `placeholder` will be ignored.\n *\n * @defaultValue true\n */\n useImport?: boolean;\n\n /**\n * Fetch image size of external URLs\n *\n * @defaultValue true\n */\n external?: ExternalImageOptions;\n}\n\ntype Source =\n | {\n type: 'url';\n url: URL;\n }\n | {\n type: 'file';\n file: string;\n };\n\n/**\n * Turn images into Next.js Image compatible usage.\n */\nexport function remarkImage({\n placeholder = 'blur',\n external = true,\n useImport = true,\n onError = 'error',\n publicDir = path.join(process.cwd(), 'public'),\n}: RemarkImageOptions = {}): Transformer<Root, Root> {\n return async (tree, file) => {\n const importsToInject: { variableName: string; importPath: string }[] = [];\n const promises: Promise<void>[] = [];\n\n async function onImage(src: Source, node: Image): Promise<MdxJsxFlowElement | undefined> {\n const attributes: MdxJsxAttribute[] = [\n {\n type: 'mdxJsxAttribute',\n name: 'alt',\n value: node.alt ?? 'image',\n },\n ];\n\n if (node.title) {\n attributes.push({\n type: 'mdxJsxAttribute',\n name: 'title',\n value: node.title,\n });\n }\n\n if (src.type === 'file' && useImport) {\n // Unique variable name for the given static image URL\n const variableName = `__img${importsToInject.length}`;\n const hasBlur =\n placeholder === 'blur' && VALID_BLUR_EXT.some((ext) => src.file.endsWith(ext));\n\n if (!file.dirname) {\n throw new Error(\n 'When `useImport` is enabled, you must specify `dirname` in the VFile passed to compiler.',\n );\n }\n\n importsToInject.push({\n variableName,\n importPath: getImportPath(src.file, file.dirname),\n });\n\n attributes.push({\n type: 'mdxJsxAttribute',\n name: 'src',\n value: {\n type: 'mdxJsxAttributeValueExpression',\n value: variableName,\n data: {\n estree: {\n body: [\n {\n type: 'ExpressionStatement',\n expression: { type: 'Identifier', name: variableName },\n },\n ],\n type: 'Program',\n sourceType: 'script',\n },\n },\n },\n });\n\n const out: MdxJsxFlowElement = {\n children: [],\n type: 'mdxJsxFlowElement',\n name: 'img',\n attributes,\n };\n\n if (hasBlur) {\n out.attributes.push({\n type: 'mdxJsxAttribute',\n name: 'placeholder',\n value: 'blur',\n });\n }\n\n return out;\n }\n\n const size = await getImageSize(src, external).catch((e) => {\n throw new Error(\n `[Remark Image] Failed obtain image size for ${node.url} (public directory configured as ${publicDir})`,\n {\n cause: e,\n },\n );\n });\n\n if (!size) return;\n\n attributes.push(\n {\n type: 'mdxJsxAttribute',\n name: 'src',\n // `src` doesn't support file paths, we can use `node.url` for files and let the underlying framework handle it\n value: src.type === 'url' ? src.url.toString() : node.url,\n },\n {\n type: 'mdxJsxAttribute',\n name: 'width',\n value: size.width.toString(),\n },\n {\n type: 'mdxJsxAttribute',\n name: 'height',\n value: size.height.toString(),\n },\n );\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'img',\n attributes,\n children: [],\n };\n }\n\n visit(tree, 'image', (node) => {\n const src = parseSrc(decodeURI(node.url), publicDir, file.dirname);\n if (!src) return;\n\n const task = onImage(src, node)\n .catch((e) => {\n // ignore SVG as it is not always needed\n if (onError === 'ignore' || node.url.endsWith('.svg')) {\n return;\n }\n\n if (onError === 'hide') {\n return {\n type: 'mdxJsxFlowElement',\n name: null,\n attributes: [],\n children: [],\n } satisfies MdxJsxFlowElement;\n }\n\n if (onError === 'error') throw e;\n onError(e);\n })\n .then((res) => {\n if (res) Object.assign(node, res);\n });\n\n promises.push(task);\n });\n\n await Promise.all(promises);\n if (importsToInject.length === 0) return;\n\n const imports = importsToInject.map(\n ({ variableName, importPath }) =>\n ({\n type: 'mdxjsEsm',\n data: {\n estree: {\n body: [\n {\n type: 'ImportDeclaration',\n source: { type: 'Literal', value: importPath },\n specifiers: [\n {\n type: 'ImportDefaultSpecifier',\n local: { type: 'Identifier', name: variableName },\n },\n ],\n },\n ],\n },\n },\n }) as MdxjsEsm,\n );\n\n tree.children.unshift(...imports);\n };\n}\n\nfunction getImportPath(file: string, dir: string): string {\n const relative = path.relative(dir, file).replaceAll(path.sep, '/');\n\n return relative.startsWith('../') ? relative : `./${relative}`;\n}\n\n/**\n * @param src - src href\n * @param publicDir - dir/url to resolve absolute paths\n * @param dir - dir to resolve relative paths\n */\nfunction parseSrc(src: string, publicDir: string, dir?: string): Source | undefined {\n if (src.startsWith('file:///')) return { type: 'file', file: fileURLToPath(src) };\n\n if (EXTERNAL_URL_REGEX.test(src)) {\n return {\n type: 'url',\n url: new URL(src),\n };\n }\n\n if (src.startsWith('/')) {\n if (EXTERNAL_URL_REGEX.test(publicDir)) {\n const url = new URL(publicDir);\n const segs = [...url.pathname.split('/'), ...src.split('/')].filter((v) => v.length > 0);\n\n url.pathname = `/${segs.join('/')}`;\n return { type: 'url', url };\n }\n\n return {\n type: 'file',\n file: path.join(publicDir, src),\n };\n }\n\n if (!dir) {\n console.warn(\n `[Remark Image] found relative path ${src} but missing 'dirname' in VFile, this image will be skipped for now.`,\n );\n return;\n }\n\n return {\n type: 'file',\n file: path.join(dir, src),\n };\n}\n\nasync function getImageSize(\n src: Source,\n onExternal: ExternalImageOptions,\n): Promise<ISizeCalculationResult | undefined> {\n if (src.type === 'file') {\n const { imageSizeFromFile } = await import('image-size/fromFile');\n return imageSizeFromFile(src.file);\n }\n if (onExternal === false) return;\n\n const { timeout } = typeof onExternal === 'object' ? onExternal : {};\n const res = await fetch(src.url, {\n signal: typeof timeout === 'number' ? AbortSignal.timeout(timeout) : undefined,\n });\n if (!res.ok) {\n throw new Error(\n `[Remark Image] Failed to fetch ${src.url} (${res.status}): ${await res.text()}`,\n );\n }\n\n const { imageSize } = await import('image-size');\n return imageSize(new Uint8Array(await res.arrayBuffer()));\n}\n"],"mappings":";;;;;AASA,MAAM,iBAAiB;CAAC;CAAS;CAAQ;CAAS;CAAS;CAAO;AAClE,MAAM,qBAAqB;;;;AAuE3B,SAAgB,YAAY,EAC1B,cAAc,QACd,WAAW,MACX,YAAY,MACZ,UAAU,SACV,YAAYA,OAAK,KAAK,QAAQ,KAAK,EAAE,SAAS,KACxB,EAAE,EAA2B;AACnD,QAAO,OAAO,MAAM,SAAS;EAC3B,MAAMC,kBAAkE,EAAE;EAC1E,MAAMC,WAA4B,EAAE;EAEpC,eAAe,QAAQ,KAAa,MAAqD;GACvF,MAAMC,aAAgC,CACpC;IACE,MAAM;IACN,MAAM;IACN,OAAO,KAAK,OAAO;IACpB,CACF;AAED,OAAI,KAAK,MACP,YAAW,KAAK;IACd,MAAM;IACN,MAAM;IACN,OAAO,KAAK;IACb,CAAC;AAGJ,OAAI,IAAI,SAAS,UAAU,WAAW;IAEpC,MAAM,eAAe,QAAQ,gBAAgB;IAC7C,MAAM,UACJ,gBAAgB,UAAU,eAAe,MAAM,QAAQ,IAAI,KAAK,SAAS,IAAI,CAAC;AAEhF,QAAI,CAAC,KAAK,QACR,OAAM,IAAI,MACR,2FACD;AAGH,oBAAgB,KAAK;KACnB;KACA,YAAY,cAAc,IAAI,MAAM,KAAK,QAAQ;KAClD,CAAC;AAEF,eAAW,KAAK;KACd,MAAM;KACN,MAAM;KACN,OAAO;MACL,MAAM;MACN,OAAO;MACP,MAAM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AM;EACN,MAAMA,OAAK,KAAK,KAAK,IAAI;EAC1B;;AAGH,eAAe,aACb,KACA,YAC6C;AAC7C,KAAI,IAAI,SAAS,QAAQ;EACvB,MAAM,EAAE,sBAAsB,MAAM,OAAO;AAC3C,SAAO,kBAAkB,IAAI,KAAK;;AAEpC,KAAI,eAAe,MAAO;CAE1B,MAAM,EAAE,YAAY,OAAO,eAAe,WAAW,aAAa,EAAE;CACpE,MAAM,MAAM,MAAM,MAAM,IAAI,KAAK,EAC/B,QAAQ,OAAO,YAAY,WAAW,YAAY,QAAQ,QAAQ,GAAG,QACtE,CAAC;AACF,KAAI,CAAC,IAAI,GACP,OAAM,IAAI,MACR,kCAAkC,IAAI,IAAI,IAAI,IAAI,OAAO,KAAK,MAAM,IAAI,MAAM,GAC/E;CAGH,MAAM,EAAE,cAAc,MAAM,OAAO;AACnC,QAAO,UAAU,IAAI,WAAW,MAAM,IAAI,aAAa,CAAC,CAAC"}
1
+ {"version":3,"file":"remark-image.js","names":["path"],"sources":["../../src/mdx-plugins/remark-image.ts"],"sourcesContent":["import * as path from 'node:path';\nimport type { Image, Root } from 'mdast';\nimport type { Transformer } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport type { MdxjsEsm } from 'mdast-util-mdxjs-esm';\nimport type { ISizeCalculationResult } from 'image-size/types/interface';\nimport type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport { fileURLToPath } from 'node:url';\n\nconst VALID_BLUR_EXT = ['.jpeg', '.png', '.webp', '.avif', '.jpg'];\nconst EXTERNAL_URL_REGEX = /^https?:\\/\\//;\n\ntype ExternalImageOptions =\n | {\n /**\n * timeout for fetching remote images (in milliseconds)\n */\n timeout?: number;\n }\n | boolean;\n\nexport interface RemarkImageOptions {\n /**\n * Directory or base URL to resolve absolute image paths\n */\n publicDir?: string;\n\n /**\n * Preferred placeholder type, only available with `useImport` + local images.\n *\n * @defaultValue 'blur'\n */\n placeholder?: 'blur' | 'none';\n\n /**\n * Define how to handle errors when fetching image size.\n *\n * - `error` (default): throw an error.\n * - `ignore`: do absolutely nothing (Next.js Image component may complain).\n * - `hide`: remove that image element.\n *\n * @defaultValue 'error'\n */\n onError?: 'error' | 'hide' | 'ignore' | ((error: Error) => void);\n\n /**\n * Import images in the file, and let bundlers handle it.\n *\n * ```tsx\n * import MyImage from \"./public/img.png\";\n *\n * <img src={MyImage} />\n * ```\n *\n * When disabled, `placeholder` will be ignored.\n *\n * @defaultValue true\n */\n useImport?: boolean;\n\n /**\n * Fetch image size of external URLs\n *\n * @defaultValue true\n */\n external?: ExternalImageOptions;\n}\n\ntype Source =\n | {\n type: 'url';\n url: URL;\n }\n | {\n type: 'file';\n file: string;\n };\n\n/**\n * Turn images into Next.js Image compatible usage.\n */\nexport function remarkImage({\n placeholder = 'blur',\n external = true,\n useImport = true,\n onError = 'error',\n publicDir = path.join(process.cwd(), 'public'),\n}: RemarkImageOptions = {}): Transformer<Root, Root> {\n return async (tree, file) => {\n const importsToInject: { variableName: string; importPath: string }[] = [];\n const promises: Promise<void>[] = [];\n\n async function onImage(src: Source, node: Image): Promise<MdxJsxFlowElement | undefined> {\n const attributes: MdxJsxAttribute[] = [\n {\n type: 'mdxJsxAttribute',\n name: 'alt',\n value: node.alt ?? 'image',\n },\n ];\n\n if (node.title) {\n attributes.push({\n type: 'mdxJsxAttribute',\n name: 'title',\n value: node.title,\n });\n }\n\n if (src.type === 'file' && useImport) {\n // Unique variable name for the given static image URL\n const variableName = `__img${importsToInject.length}`;\n const hasBlur =\n placeholder === 'blur' && VALID_BLUR_EXT.some((ext) => src.file.endsWith(ext));\n\n if (!file.dirname) {\n throw new Error(\n 'When `useImport` is enabled, you must specify `dirname` in the VFile passed to compiler.',\n );\n }\n\n importsToInject.push({\n variableName,\n importPath: getImportPath(src.file, file.dirname),\n });\n\n attributes.push({\n type: 'mdxJsxAttribute',\n name: 'src',\n value: {\n type: 'mdxJsxAttributeValueExpression',\n value: variableName,\n data: {\n estree: {\n body: [\n {\n type: 'ExpressionStatement',\n expression: { type: 'Identifier', name: variableName },\n },\n ],\n type: 'Program',\n sourceType: 'script',\n },\n },\n },\n });\n\n const out: MdxJsxFlowElement = {\n children: [],\n type: 'mdxJsxFlowElement',\n name: 'img',\n attributes,\n };\n\n if (hasBlur) {\n out.attributes.push({\n type: 'mdxJsxAttribute',\n name: 'placeholder',\n value: 'blur',\n });\n }\n\n return out;\n }\n\n const size = await getImageSize(src, external).catch((e) => {\n throw new Error(\n `[Remark Image] Failed obtain image size for ${node.url} (public directory configured as ${publicDir})`,\n {\n cause: e,\n },\n );\n });\n\n if (!size) return;\n\n attributes.push(\n {\n type: 'mdxJsxAttribute',\n name: 'src',\n // `src` doesn't support file paths, we can use `node.url` for files and let the underlying framework handle it\n value: src.type === 'url' ? src.url.toString() : node.url,\n },\n {\n type: 'mdxJsxAttribute',\n name: 'width',\n value: size.width.toString(),\n },\n {\n type: 'mdxJsxAttribute',\n name: 'height',\n value: size.height.toString(),\n },\n );\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'img',\n attributes,\n children: [],\n };\n }\n\n visit(tree, 'image', (node) => {\n const src = parseSrc(decodeURI(node.url), publicDir, file.dirname);\n if (!src) return;\n\n const task = onImage(src, node)\n .catch((e) => {\n // ignore SVG as it is not always needed\n if (onError === 'ignore' || node.url.endsWith('.svg')) {\n return;\n }\n\n if (onError === 'hide') {\n return {\n type: 'mdxJsxFlowElement',\n name: null,\n attributes: [],\n children: [],\n } satisfies MdxJsxFlowElement;\n }\n\n if (onError === 'error') throw e;\n onError(e);\n })\n .then((res) => {\n if (res) Object.assign(node, res);\n });\n\n promises.push(task);\n });\n\n await Promise.all(promises);\n if (importsToInject.length === 0) return;\n\n const imports = importsToInject.map(\n ({ variableName, importPath }) =>\n ({\n type: 'mdxjsEsm',\n data: {\n estree: {\n body: [\n {\n type: 'ImportDeclaration',\n source: { type: 'Literal', value: importPath },\n specifiers: [\n {\n type: 'ImportDefaultSpecifier',\n local: { type: 'Identifier', name: variableName },\n },\n ],\n },\n ],\n },\n },\n }) as MdxjsEsm,\n );\n\n tree.children.unshift(...imports);\n };\n}\n\nfunction getImportPath(file: string, dir: string): string {\n const relative = path.relative(dir, file).replaceAll(path.sep, '/');\n\n return relative.startsWith('../') ? relative : `./${relative}`;\n}\n\n/**\n * @param src - src href\n * @param publicDir - dir/url to resolve absolute paths\n * @param dir - dir to resolve relative paths\n */\nfunction parseSrc(src: string, publicDir: string, dir?: string): Source | undefined {\n if (src.startsWith('file:///')) return { type: 'file', file: fileURLToPath(src) };\n\n if (EXTERNAL_URL_REGEX.test(src)) {\n return {\n type: 'url',\n url: new URL(src),\n };\n }\n\n if (src.startsWith('/')) {\n if (EXTERNAL_URL_REGEX.test(publicDir)) {\n const url = new URL(publicDir);\n const segs = [...url.pathname.split('/'), ...src.split('/')].filter((v) => v.length > 0);\n\n url.pathname = `/${segs.join('/')}`;\n return { type: 'url', url };\n }\n\n return {\n type: 'file',\n file: path.join(publicDir, src),\n };\n }\n\n if (!dir) {\n console.warn(\n `[Remark Image] found relative path ${src} but missing 'dirname' in VFile, this image will be skipped for now.`,\n );\n return;\n }\n\n return {\n type: 'file',\n file: path.join(dir, src),\n };\n}\n\nasync function getImageSize(\n src: Source,\n onExternal: ExternalImageOptions,\n): Promise<ISizeCalculationResult | undefined> {\n if (src.type === 'file') {\n const { imageSizeFromFile } = await import('image-size/fromFile');\n return imageSizeFromFile(src.file);\n }\n if (onExternal === false) return;\n\n const { timeout } = typeof onExternal === 'object' ? onExternal : {};\n const res = await fetch(src.url, {\n signal: typeof timeout === 'number' ? AbortSignal.timeout(timeout) : undefined,\n });\n if (!res.ok) {\n throw new Error(\n `[Remark Image] Failed to fetch ${src.url} (${res.status}): ${await res.text()}`,\n );\n }\n\n const { imageSize } = await import('image-size');\n return imageSize(new Uint8Array(await res.arrayBuffer()));\n}\n"],"mappings":";;;;;AASA,MAAM,iBAAiB;CAAC;CAAS;CAAQ;CAAS;CAAS;CAAO;AAClE,MAAM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AI,IAAI,IAAI,IAAI,OAAO,KAAK,MAAM,IAAI,MAAM,GAC/E;CAGH,MAAM,EAAE,cAAc,MAAM,OAAO;AACnC,QAAO,UAAU,IAAI,WAAW,MAAM,IAAI,aAAa,CAAC,CAAC"}
@@ -1,2 +1,2 @@
1
- import { a as remarkMdxFiles, i as ToMdxOptions, n as FolderNode, r as RemarkMdxFilesOptions, t as FileNode } from "../remark-mdx-files-B5KMXnfh.js";
1
+ import { a as remarkMdxFiles, i as ToMdxOptions, n as FolderNode, r as RemarkMdxFilesOptions, t as FileNode } from "../remark-mdx-files-BXUiiX3M.js";
2
2
  export { FileNode, FolderNode, RemarkMdxFilesOptions, ToMdxOptions, remarkMdxFiles };
@@ -1 +1 @@
1
- {"version":3,"file":"remark-mdx-files.js","names":["match: RegExpMatchArray | null","node: Node","parent: Node | undefined","attributes: MdxJsxAttribute[]","queue: Promise<void>[]","parsed: AutoFilesProps","root: FolderNode","fileNode: FileNode"],"sources":["../../src/mdx-plugins/remark-mdx-files.ts"],"sourcesContent":["import type { Root } from 'mdast';\nimport { visit } from 'unist-util-visit';\nimport type { Transformer } from 'unified';\nimport type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport type { VFile } from 'vfile';\nimport path from 'node:path';\n\nexport interface FileNode {\n depth: number;\n type: 'file';\n name: string;\n}\n\nexport interface FolderNode {\n depth: number;\n type: 'folder';\n name: string;\n children: Node[];\n}\n\nexport interface ToMdxOptions {\n defaultOpenAll: boolean;\n}\n\ntype Node = FileNode | FolderNode;\n\nexport interface RemarkMdxFilesOptions {\n /**\n * @defaultValue files\n */\n lang?: string;\n toMdx?: (node: Node, options: ToMdxOptions) => MdxJsxFlowElement;\n}\n\ninterface AutoFilesProps extends Partial<ToMdxOptions> {\n dir?: string;\n patterns?: string[];\n}\n\nfunction parseFileTree(code: string) {\n const lines = code.split(/\\r?\\n/);\n const stack = new Map<number, Node>();\n\n for (const line of lines) {\n let depth = 0;\n let name = line;\n let match: RegExpMatchArray | null;\n\n while ((match = /(?:├──|│|└──)\\s*/.exec(name))) {\n name = name.slice(match[0].length);\n depth++;\n }\n\n if (!name) continue;\n const node: Node = name.endsWith('/')\n ? { type: 'folder', name, children: [], depth }\n : { type: 'file', name, depth };\n\n let parent: Node | undefined;\n for (let i = depth - 1; i >= 0 && !parent; i--) {\n parent = stack.get(i);\n }\n\n stack.set(depth, node);\n if (!parent) continue;\n if (parent.type === 'file') {\n Object.assign(parent, {\n type: 'folder',\n children: [],\n });\n }\n\n (parent as FolderNode).children.push(node);\n }\n\n return stack.get(0);\n}\n\nfunction defaultToMDX(node: Node, options: ToMdxOptions, depth = 0): MdxJsxFlowElement {\n if (depth === 0) {\n return {\n type: 'mdxJsxFlowElement',\n name: 'Files',\n attributes: [],\n children: [defaultToMDX(node, options, depth + 1)],\n };\n }\n\n const attributes: MdxJsxAttribute[] = [\n { type: 'mdxJsxAttribute', name: 'name', value: node.name },\n ];\n\n if (node.type === 'file') {\n return {\n type: 'mdxJsxFlowElement',\n attributes,\n children: [],\n name: 'File',\n };\n }\n\n if (options.defaultOpenAll) {\n attributes.push({\n type: 'mdxJsxAttribute',\n name: 'defaultOpen',\n value: null,\n });\n }\n\n return {\n type: 'mdxJsxFlowElement',\n attributes,\n name: 'Folder',\n children: node.children.map((item) => defaultToMDX(item, options, depth + 1)),\n };\n}\n\n/**\n *\n * **Files CodeBlock:**\n *\n * Convert codeblocks with `files` as lang, like:\n *\n * ```files\n * project\n * ├── src\n * │ ├── index.js\n * │ └── utils\n * │ └── helper.js\n * ├── package.json\n * ```\n *\n * into MDX `<Files />` component.\n *\n * **Auto Files:**\n *\n * Generates MDX `<Files />` component from file system.\n *\n * ```mdx\n * <auto-files dir=\"scripts\" pattern=\"my-dir/*\" defaultOpenAll />\n * ```\n */\nexport function remarkMdxFiles(options: RemarkMdxFilesOptions = {}): Transformer<Root, Root> {\n const { lang = 'files', toMdx = defaultToMDX } = options;\n\n async function autoFiles(\n file: VFile,\n node: MdxJsxFlowElement,\n { patterns, dir, defaultOpenAll = false }: AutoFilesProps,\n ) {\n const { glob } = await import('tinyglobby');\n if (!patterns) {\n file.fail('Missing `pattern` prop in <auto-files>', {\n place: node.position,\n });\n }\n\n const baseDir = file.dirname ?? file.cwd;\n const cwd = dir ? path.join(baseDir, dir) : baseDir;\n const files = await glob(patterns, { cwd });\n Object.assign(node, toMdx(buildFileTreeFromGlob(cwd, files), { defaultOpenAll }));\n }\n\n return async (tree, file) => {\n const queue: Promise<void>[] = [];\n\n visit(tree, ['code', 'mdxJsxFlowElement'] as const, (node) => {\n if (node.type === 'code') {\n if (node.lang !== lang || !node.value) return;\n\n const fileTree = parseFileTree(node.value);\n if (!fileTree) return;\n\n Object.assign(\n node,\n toMdx(fileTree, {\n defaultOpenAll: true,\n }),\n );\n return 'skip';\n }\n\n if (node.type === 'mdxJsxFlowElement') {\n if (node.name !== 'auto-files') return;\n const parsed: AutoFilesProps = {};\n for (const attr of node.attributes) {\n if (attr.type !== 'mdxJsxAttribute') continue;\n const { name, value } = attr;\n\n switch (name) {\n case 'dir':\n if (typeof value === 'string') parsed.dir = value;\n break;\n case 'pattern':\n if (typeof value === 'string') {\n parsed.patterns ??= [];\n parsed.patterns.push(value);\n }\n break;\n case 'defaultOpenAll':\n parsed.defaultOpenAll = true;\n break;\n }\n }\n\n queue.push(autoFiles(file, node, parsed));\n return 'skip';\n }\n });\n\n await Promise.all(queue);\n };\n}\n\nfunction buildFileTreeFromGlob(dir: string, files: string[]): Node {\n const nodeMap = new Map<string, FolderNode>();\n const root: FolderNode = {\n depth: 0,\n type: 'folder',\n name: path.basename(dir),\n children: [],\n };\n nodeMap.set('', root);\n\n for (const file of files) {\n const parts = path\n .normalize(file)\n .split(path.sep)\n .filter((part) => part.length > 0);\n let currentPath = '';\n let current = root;\n\n for (let i = 0; i < parts.length; i++) {\n const name = parts[i];\n const nextPath = path.join(currentPath, name);\n\n if (i === parts.length - 1) {\n // Add file node.\n const fileNode: FileNode = { depth: i + 1, type: 'file', name };\n current.children.push(fileNode);\n } else {\n // Add or retrieve folder node using the map.\n let folder = nodeMap.get(nextPath);\n\n if (!folder) {\n folder = { depth: i + 1, type: 'folder', name, children: [] };\n nodeMap.set(nextPath, folder);\n current.children.push(folder);\n }\n\n current = folder;\n currentPath = nextPath;\n }\n }\n }\n\n return root;\n}\n"],"mappings":";;;;AAuCA,SAAS,cAAc,MAAc;CACnC,MAAM,QAAQ,KAAK,MAAM,QAAQ;CACjC,MAAM,wBAAQ,IAAI,KAAmB;AAErC,MAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,QAAQ;EACZ,IAAI,OAAO;EACX,IAAIA;AAEJ,SAAQ,QAAQ,mBAAmB,KAAK,KAAK,EAAG;AAC9C,UAAO,KAAK,MAAM,MAAM,GAAG,OAAO;AAClC;;AAGF,MAAI,CAAC,KAAM;EACX,MAAMC,OAAa,KAAK,SAAS,IAAI,GACjC;GAAE,MAAM;GAAU;GAAM,UAAU,EAAE;GAAE;GAAO,GAC7C;GAAE,MAAM;GAAQ;GAAM;GAAO;EAEjC,IAAIC;AACJ,OAAK,IAAI,IAAI,QAAQ,GAAG,KAAK,KAAK,CAAC,QAAQ,IACzC,UAAS,MAAM,IAAI,EAAE;AAGvB,QAAM,IAAI,OAAO,KAAK;AACtB,MAAI,CAAC,OAAQ;AACb,MAAI,OAAO,SAAS,OAClB,QAAO,OAAO,QAAQ;GACpB,MAAM;GACN,UAAU,EAAE;GACb,CAAC;AAGJ,EAAC,OAAsB,SAAS,KAAK,KAAK;;AAG5C,QAAO,MAAM,IAAI,EAAE;;AAGrB,SAAS,aAAa,MAAY,SAAuB,QAAQ,GAAsB;AACrF,KAAI,UAAU,EACZ,QAAO;EACL,MAAM;EACN,MAAM;EACN,YAAY,EAAE;EACd,UAAU,CAAC,aAAa,MAAM,SAAS,QAAQ,EAAE,CAAC;EACnD;CAGH,MAAMC,aAAgC,CACpC;EAAE,MAAM;EAAmB,MAAM;EAAQ,OAAO,KAAK;E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AAK,OAAO;;AAG/B,cAAU;AACV,kBAAc;;;;AAKpB,QAAO"}
1
+ {"version":3,"file":"remark-mdx-files.js","names":[],"sources":["../../src/mdx-plugins/remark-mdx-files.ts"],"sourcesContent":["import type { Root } from 'mdast';\nimport { visit } from 'unist-util-visit';\nimport type { Transformer } from 'unified';\nimport type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport type { VFile } from 'vfile';\nimport path from 'node:path';\n\nexport interface FileNode {\n depth: number;\n type: 'file';\n name: string;\n}\n\nexport interface FolderNode {\n depth: number;\n type: 'folder';\n name: string;\n children: Node[];\n}\n\nexport interface ToMdxOptions {\n defaultOpenAll: boolean;\n}\n\ntype Node = FileNode | FolderNode;\n\nexport interface RemarkMdxFilesOptions {\n /**\n * @defaultValue files\n */\n lang?: string;\n toMdx?: (node: Node, options: ToMdxOptions) => MdxJsxFlowElement;\n}\n\ninterface AutoFilesProps extends Partial<ToMdxOptions> {\n dir?: string;\n patterns?: string[];\n}\n\nfunction parseFileTree(code: string) {\n const lines = code.split(/\\r?\\n/);\n const stack = new Map<number, Node>();\n\n for (const line of lines) {\n let depth = 0;\n let name = line;\n let match: RegExpMatchArray | null;\n\n while ((match = /(?:├──|│|└──)\\s*/.exec(name))) {\n name = name.slice(match[0].length);\n depth++;\n }\n\n if (!name) continue;\n const node: Node = name.endsWith('/')\n ? { type: 'folder', name, children: [], depth }\n : { type: 'file', name, depth };\n\n let parent: Node | undefined;\n for (let i = depth - 1; i >= 0 && !parent; i--) {\n parent = stack.get(i);\n }\n\n stack.set(depth, node);\n if (!parent) continue;\n if (parent.type === 'file') {\n Object.assign(parent, {\n type: 'folder',\n children: [],\n });\n }\n\n (parent as FolderNode).children.push(node);\n }\n\n return stack.get(0);\n}\n\nfunction defaultToMDX(node: Node, options: ToMdxOptions, depth = 0): MdxJsxFlowElement {\n if (depth === 0) {\n return {\n type: 'mdxJsxFlowElement',\n name: 'Files',\n attributes: [],\n children: [defaultToMDX(node, options, depth + 1)],\n };\n }\n\n const attributes: MdxJsxAttribute[] = [\n { type: 'mdxJsxAttribute', name: 'name', value: node.name },\n ];\n\n if (node.type === 'file') {\n return {\n type: 'mdxJsxFlowElement',\n attributes,\n children: [],\n name: 'File',\n };\n }\n\n if (options.defaultOpenAll) {\n attributes.push({\n type: 'mdxJsxAttribute',\n name: 'defaultOpen',\n value: null,\n });\n }\n\n return {\n type: 'mdxJsxFlowElement',\n attributes,\n name: 'Folder',\n children: node.children.map((item) => defaultToMDX(item, options, depth + 1)),\n };\n}\n\n/**\n *\n * **Files CodeBlock:**\n *\n * Convert codeblocks with `files` as lang, like:\n *\n * ```files\n * project\n * ├── src\n * │ ├── index.js\n * │ └── utils\n * │ └── helper.js\n * ├── package.json\n * ```\n *\n * into MDX `<Files />` component.\n *\n * **Auto Files:**\n *\n * Generates MDX `<Files />` component from file system.\n *\n * ```mdx\n * <auto-files dir=\"scripts\" pattern=\"my-dir/*\" defaultOpenAll />\n * ```\n */\nexport function remarkMdxFiles(options: RemarkMdxFilesOptions = {}): Transformer<Root, Root> {\n const { lang = 'files', toMdx = defaultToMDX } = options;\n\n async function autoFiles(\n file: VFile,\n node: MdxJsxFlowElement,\n { patterns, dir, defaultOpenAll = false }: AutoFilesProps,\n ) {\n const { glob } = await import('tinyglobby');\n if (!patterns) {\n file.fail('Missing `pattern` prop in <auto-files>', {\n place: node.position,\n });\n }\n\n const baseDir = file.dirname ?? file.cwd;\n const cwd = dir ? path.join(baseDir, dir) : baseDir;\n const files = await glob(patterns, { cwd });\n Object.assign(node, toMdx(buildFileTreeFromGlob(cwd, files), { defaultOpenAll }));\n }\n\n return async (tree, file) => {\n const queue: Promise<void>[] = [];\n\n visit(tree, ['code', 'mdxJsxFlowElement'] as const, (node) => {\n if (node.type === 'code') {\n if (node.lang !== lang || !node.value) return;\n\n const fileTree = parseFileTree(node.value);\n if (!fileTree) return;\n\n Object.assign(\n node,\n toMdx(fileTree, {\n defaultOpenAll: true,\n }),\n );\n return 'skip';\n }\n\n if (node.type === 'mdxJsxFlowElement') {\n if (node.name !== 'auto-files') return;\n const parsed: AutoFilesProps = {};\n for (const attr of node.attributes) {\n if (attr.type !== 'mdxJsxAttribute') continue;\n const { name, value } = attr;\n\n switch (name) {\n case 'dir':\n if (typeof value === 'string') parsed.dir = value;\n break;\n case 'pattern':\n if (typeof value === 'string') {\n parsed.patterns ??= [];\n parsed.patterns.push(value);\n }\n break;\n case 'defaultOpenAll':\n parsed.defaultOpenAll = true;\n break;\n }\n }\n\n queue.push(autoFiles(file, node, parsed));\n return 'skip';\n }\n });\n\n await Promise.all(queue);\n };\n}\n\nfunction buildFileTreeFromGlob(dir: string, files: string[]): Node {\n const nodeMap = new Map<string, FolderNode>();\n const root: FolderNode = {\n depth: 0,\n type: 'folder',\n name: path.basename(dir),\n children: [],\n };\n nodeMap.set('', root);\n\n for (const file of files) {\n const parts = path\n .normalize(file)\n .split(path.sep)\n .filter((part) => part.length > 0);\n let currentPath = '';\n let current = root;\n\n for (let i = 0; i < parts.length; i++) {\n const name = parts[i];\n const nextPath = path.join(currentPath, name);\n\n if (i === parts.length - 1) {\n // Add file node.\n const fileNode: FileNode = { depth: i + 1, type: 'file', name };\n current.children.push(fileNode);\n } else {\n // Add or retrieve folder node using the map.\n let folder = nodeMap.get(nextPath);\n\n if (!folder) {\n folder = { depth: i + 1, type: 'folder', name, children: [] };\n nodeMap.set(nextPath, folder);\n current.children.push(folder);\n }\n\n current = folder;\n currentPath = nextPath;\n }\n }\n }\n\n return root;\n}\n"],"mappings":";;;;AAuCA,SAAS,cAAc,MAAc;CACnC,MAAM,QAAQ,KAAK,MAAM,QAAQ;CACjC,MAAM,wBAAQ,IAAI,KAAmB;AAErC,MAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,QAAQ;EACZ,IAAI,OAAO;EACX,IAAI;AAEJ,SAAQ,QAAQ,mBAAmB,KAAK,KAAK,EAAG;AAC9C,UAAO,KAAK,MAAM,MAAM,GAAG,OAAO;AAClC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;EACvB,OAAO;EACP,MAAM;EACN,MAAM,KAAK,SAAS,IAAI;EACxB,UAAU,EAAE;EACb;AACD,SAAQ,IAAI,IAAI,KAAK;AAErB,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,KACX,UAAU,KAAK,CACf,MAAM,KAAK,IAAI,CACf,QAAQ,SAAS,KAAK,SAAS,EAAE;EACpC,IAAI,cAAc;EAClB,IAAI,UAAU;AAEd,OAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;GACrC,MAAM,OAAO,MAAM;GACnB,MAAM,WAAW,KAAK,KAAK,aAAa,KAAK;AAE7C,OAAI,MAAM,MAAM,SAAS,GAAG;IAE1B,MAAM,WAAqB;KAAE,OAAO,IAAI;KAAG,MAAM;KAAQ;KAAM;AAC/D,YAAQ,SAAS,KAAK,SAAS;UAC1B;IAEL,IAAI,SAAS,QAAQ,IAAI,SAAS;AAElC,QAAI,CAAC,QAAQ;AACX,cAAS;MAAE,OAAO,IAAI;MAAG,MAAM;MAAU;MAAM,UAAU,EAAE;MAAE;AAC7D,aAAQ,IAAI,UAAU,OAAO;AAC7B,aAAQ,SAAS,KAAK,OAAO;;AAG/B,cAAU;AACV,kBAAc;;;;AAKpB,QAAO"}
@@ -1,2 +1,2 @@
1
- import { n as remarkMdxMermaid, t as RemarkMdxMermaidOptions } from "../remark-mdx-mermaid-C_4W5gfj.js";
1
+ import { n as remarkMdxMermaid, t as RemarkMdxMermaidOptions } from "../remark-mdx-mermaid-C5ZBxx8x.js";
2
2
  export { RemarkMdxMermaidOptions, remarkMdxMermaid };
@@ -1,2 +1,2 @@
1
- import { n as remarkNpm, t as RemarkNpmOptions } from "../remark-npm-CykFgJn2.js";
1
+ import { n as remarkNpm, t as RemarkNpmOptions } from "../remark-npm-DADZg0pf.js";
2
2
  export { RemarkNpmOptions, remarkNpm };
@@ -1 +1 @@
1
- {"version":3,"file":"remark-npm.js","names":["options: CodeBlockTabsOptions"],"sources":["../../src/mdx-plugins/remark-npm.ts"],"sourcesContent":["import type { Root } from 'mdast';\nimport type { Transformer } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport convert from 'npm-to-yarn';\nimport { type CodeBlockTabsOptions, generateCodeBlockTabs } from '@/mdx-plugins/codeblock-utils';\n\ninterface PackageManager {\n name: string;\n\n /**\n * Default to `name`\n */\n value?: string;\n\n /**\n * Convert from npm to another package manager\n */\n command: (command: string) => string | undefined;\n}\n\nexport interface RemarkNpmOptions {\n /**\n * Persist Tab value (Fumadocs UI only)\n *\n * @defaultValue false\n */\n persist?:\n | {\n id: string;\n }\n | false;\n\n packageManagers?: PackageManager[];\n}\n\nconst aliases = ['npm', 'package-install'];\n\n/**\n * It generates multiple tabs of codeblocks for different package managers from a npm command codeblock.\n */\nexport function remarkNpm({\n persist = false,\n packageManagers = [\n { command: (cmd) => convert(cmd, 'npm'), name: 'npm' },\n { command: (cmd) => convert(cmd, 'pnpm'), name: 'pnpm' },\n { command: (cmd) => convert(cmd, 'yarn'), name: 'yarn' },\n { command: (cmd) => convert(cmd, 'bun'), name: 'bun' },\n ],\n}: RemarkNpmOptions = {}): Transformer<Root, Root> {\n return (tree) => {\n visit(tree, 'code', (node) => {\n if (!node.lang || !aliases.includes(node.lang)) return;\n let code = node.value;\n\n if (node.lang === 'package-install' && !code.startsWith('npm') && !code.startsWith('npx')) {\n code = `npm install ${code}`;\n }\n const options: CodeBlockTabsOptions = {\n persist,\n tabs: [],\n triggers: [],\n };\n\n for (const manager of packageManagers) {\n const value = manager.value ?? manager.name;\n const command = manager.command(code);\n if (!command || command.length === 0) continue;\n\n options.defaultValue ??= value;\n options.triggers.push({\n value,\n children: [{ type: 'text', value: manager.name }],\n });\n options.tabs.push({\n value,\n children: [\n {\n type: 'code',\n lang: 'bash',\n meta: node.meta,\n value: command,\n },\n ],\n });\n }\n\n Object.assign(node, generateCodeBlockTabs(options));\n return 'skip';\n });\n };\n}\n"],"mappings":";;;;;AAmCA,MAAM,UAAU,CAAC,OAAO,kBAAkB;;;;AAK1C,SAAgB,UAAU,EACxB,UAAU,OACV,kBAAkB;CAChB;EAAE,UAAU,QAAQ,QAAQ,KAAK,MAAM;EAAE,MAAM;EAAO;CACtD;EAAE,UAAU,QAAQ,QAAQ,KAAK,OAAO;EAAE,MAAM;EAAQ;CACxD;EAAE,UAAU,QAAQ,QAAQ,KAAK,OAAO;EAAE,MAAM;EAAQ;CACxD;EAAE,UAAU,QAAQ,QAAQ,KAAK,MAAM;EAAE,MAAM;EAAO;CACvD,KACmB,EAAE,EAA2B;AACjD,SAAQ,SAAS;AACf,QAAM,MAAM,SAAS,SAAS;AAC5B,OAAI,CAAC,KAAK,QAAQ,CAAC,QAAQ,SAAS,KAAK,KAAK,CAAE;GAChD,IAAI,OAAO,KAAK;AAEhB,OAAI,KAAK,SAAS,qBAAqB,CAAC,KAAK,WAAW,MAAM,IAAI,CAAC,KAAK,WAAW,MAAM,CACvF,QAAO,eAAe;GAExB,MAAMA,UAAgC;IACpC;IACA,MAAM,EAAE;IACR,UAAU,EAAE;IACb;AAED,QAAK,MAAM,WAAW,iBAAiB;IACrC,MAAM,QAAQ,QAAQ,SAAS,QAAQ;IACvC,MAAM,UAAU,QAAQ,QAAQ,KAAK;AACrC,QAAI,CAAC,WAAW,QAAQ,WAAW,EAAG;AAEtC,YAAQ,iBAAiB;AACzB,YAAQ,SAAS,KAAK;KACpB;KACA,UAAU,CAAC;MAAE,MAAM;MAAQ,OAAO,QAAQ;MAAM,CAAC;KAClD,CAAC;AACF,YAAQ,KAAK,KAAK;KAChB;KACA,UAAU,CACR;MACE,MAAM;MACN,MAAM;MACN,MAAM,KAAK;MACX,OAAO;MACR,CACF;KACF,CAAC;;AAGJ,UAAO,OAAO,MAAM,sBAAsB,QAAQ,CAAC;AACnD,UAAO;IACP"}
1
+ {"version":3,"file":"remark-npm.js","names":[],"sources":["../../src/mdx-plugins/remark-npm.ts"],"sourcesContent":["import type { Root } from 'mdast';\nimport type { Transformer } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport convert from 'npm-to-yarn';\nimport { type CodeBlockTabsOptions, generateCodeBlockTabs } from '@/mdx-plugins/codeblock-utils';\n\ninterface PackageManager {\n name: string;\n\n /**\n * Default to `name`\n */\n value?: string;\n\n /**\n * Convert from npm to another package manager\n */\n command: (command: string) => string | undefined;\n}\n\nexport interface RemarkNpmOptions {\n /**\n * Persist Tab value (Fumadocs UI only)\n *\n * @defaultValue false\n */\n persist?:\n | {\n id: string;\n }\n | false;\n\n packageManagers?: PackageManager[];\n}\n\nconst aliases = ['npm', 'package-install'];\n\n/**\n * It generates multiple tabs of codeblocks for different package managers from a npm command codeblock.\n */\nexport function remarkNpm({\n persist = false,\n packageManagers = [\n { command: (cmd) => convert(cmd, 'npm'), name: 'npm' },\n { command: (cmd) => convert(cmd, 'pnpm'), name: 'pnpm' },\n { command: (cmd) => convert(cmd, 'yarn'), name: 'yarn' },\n { command: (cmd) => convert(cmd, 'bun'), name: 'bun' },\n ],\n}: RemarkNpmOptions = {}): Transformer<Root, Root> {\n return (tree) => {\n visit(tree, 'code', (node) => {\n if (!node.lang || !aliases.includes(node.lang)) return;\n let code = node.value;\n\n if (node.lang === 'package-install' && !code.startsWith('npm') && !code.startsWith('npx')) {\n code = `npm install ${code}`;\n }\n const options: CodeBlockTabsOptions = {\n persist,\n tabs: [],\n triggers: [],\n };\n\n for (const manager of packageManagers) {\n const value = manager.value ?? manager.name;\n const command = manager.command(code);\n if (!command || command.length === 0) continue;\n\n options.defaultValue ??= value;\n options.triggers.push({\n value,\n children: [{ type: 'text', value: manager.name }],\n });\n options.tabs.push({\n value,\n children: [\n {\n type: 'code',\n lang: 'bash',\n meta: node.meta,\n value: command,\n },\n ],\n });\n }\n\n Object.assign(node, generateCodeBlockTabs(options));\n return 'skip';\n });\n };\n}\n"],"mappings":";;;;;AAmCA,MAAM,UAAU,CAAC,OAAO,kBAAkB;;;;AAK1C,SAAgB,UAAU,EACxB,UAAU,OACV,kBAAkB;CAChB;EAAE,UAAU,QAAQ,QAAQ,KAAK,MAAM;EAAE,MAAM;EAAO;CACtD;EAAE,UAAU,QAAQ,QAAQ,KAAK,OAAO;EAAE,MAAM;EAAQ;CACxD;EAAE,UAAU,QAAQ,QAAQ,KAAK,OAAO;EAAE,MAAM;EAAQ;CACxD;EAAE,UAAU,QAAQ,QAAQ,KAAK,MAAM;EAAE,MAAM;EAAO;CACvD,KACmB,EAAE,EAA2B;AACjD,SAAQ,SAAS;AACf,QAAM,MAAM,SAAS,SAAS;AAC5B,OAAI,CAAC,KAAK,QAAQ,CAAC,QAAQ,SAAS,KAAK,KAAK,CAAE;GAChD,IAAI,OAAO,KAAK;AAEhB,OAAI,KAAK,SAAS,qBAAqB,CAAC,KAAK,WAAW,MAAM,IAAI,CAAC,KAAK,WAAW,MAAM,CACvF,QAAO,eAAe;GAExB,MAAM,UAAgC;IACpC;IACA,MAAM,EAAE;IACR,UAAU,EAAE;IACb;AAED,QAAK,MAAM,WAAW,iBAAiB;IACrC,MAAM,QAAQ,QAAQ,SAAS,QAAQ;IACvC,MAAM,UAAU,QAAQ,QAAQ,KAAK;AACrC,QAAI,CAAC,WAAW,QAAQ,WAAW,EAAG;AAEtC,YAAQ,iBAAiB;AACzB,YAAQ,SAAS,KAAK;KACpB;KACA,UAAU,CAAC;MAAE,MAAM;MAAQ,OAAO,QAAQ;MAAM,CAAC;KAClD,CAAC;AACF,YAAQ,KAAK,KAAK;KAChB;KACA,UAAU,CACR;MACE,MAAM;MACN,MAAM;MACN,MAAM,KAAK;MACX,OAAO;MACR,CACF;KACF,CAAC;;AAGJ,UAAO,OAAO,MAAM,sBAAsB,QAAQ,CAAC;AACnD,UAAO;IACP"}
@@ -1,2 +1,2 @@
1
- import { n as remarkSteps, t as RemarkStepsOptions } from "../remark-steps-5-DmLVv3.js";
1
+ import { n as remarkSteps, t as RemarkStepsOptions } from "../remark-steps-CWEE34cT.js";
2
2
  export { RemarkStepsOptions, remarkSteps };
@@ -1 +1 @@
1
- {"version":3,"file":"remark-steps.js","names":["children: MdxJsxFlowElement[]"],"sources":["../../src/mdx-plugins/remark-steps.ts"],"sourcesContent":["import type { Transformer } from 'unified';\nimport type { BlockContent, Heading, Root, RootContent } from 'mdast';\nimport { visit } from 'unist-util-visit';\nimport type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\n\nexport interface RemarkStepsOptions {\n /**\n * Class name for steps container\n *\n * @defaultValue fd-steps\n */\n steps?: string;\n\n /**\n * Class name for step container\n *\n * @defaultValue fd-step\n */\n step?: string;\n}\n\nconst StepRegex = /^(\\d+)\\.\\s(.+)$/;\n\n/**\n * Convert headings in the format of `1. Hello World` into steps.\n */\nexport function remarkSteps({\n steps = 'fd-steps',\n step = 'fd-step',\n}: RemarkStepsOptions = {}): Transformer<Root, Root> {\n function convertToSteps(nodes: RootContent[]): MdxJsxFlowElement {\n const depth = (nodes[0] as Heading).depth;\n const children: MdxJsxFlowElement[] = [];\n\n for (const node of nodes) {\n if (node.type === 'heading' && node.depth === depth) {\n children.push({\n type: 'mdxJsxFlowElement',\n name: 'div',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'className',\n value: step,\n },\n ],\n children: [node],\n });\n } else {\n children[children.length - 1].children.push(node as BlockContent);\n }\n }\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'div',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'className',\n value: steps,\n },\n ],\n data: {\n _fd_step: true,\n } as object,\n children,\n };\n }\n\n return (tree) => {\n visit(tree, (parent) => {\n if (!('children' in parent) || parent.type === 'heading') return;\n if (parent.data && '_fd_step' in parent.data) return 'skip';\n\n let startIdx = -1;\n let i = 0;\n\n const onEnd = () => {\n if (startIdx === -1) return;\n // range: start index to i - 1\n const item = {};\n const nodes = parent.children.splice(startIdx, i - startIdx, item as RootContent);\n Object.assign(item, convertToSteps(nodes));\n i = startIdx + 1;\n startIdx = -1;\n };\n\n for (; i < parent.children.length; i++) {\n const node = parent.children[i];\n\n if (node.type !== 'heading') continue;\n if (startIdx !== -1) {\n const startDepth = (parent.children[startIdx] as Heading).depth;\n\n if (node.depth > startDepth) continue;\n else if (node.depth < startDepth) onEnd();\n }\n\n const head = node.children.filter((c) => c.type === 'text').at(0);\n if (!head) {\n onEnd();\n continue;\n }\n\n const match = StepRegex.exec(head.value);\n if (!match) {\n onEnd();\n continue;\n }\n\n head.value = match[2];\n if (startIdx === -1) startIdx = i;\n }\n\n onEnd();\n });\n };\n}\n"],"mappings":";;;AAqBA,MAAM,YAAY;;;;AAKlB,SAAgB,YAAY,EAC1B,QAAQ,YACR,OAAO,cACe,EAAE,EAA2B;CACnD,SAAS,eAAe,OAAyC;EAC/D,MAAM,QAAS,MAAM,GAAe;EACpC,MAAMA,WAAgC,EAAE;AAExC,OAAK,MAAM,QAAQ,MACjB,KAAI,KAAK,SAAS,aAAa,KAAK,UAAU,MAC5C,UAAS,KAAK;GACZ,MAAM;GACN,MAAM;GACN,YAAY,CACV;IACE,MAAM;IACN,MAAM;IACN,OAAO;IACR,CACF;GACD,UAAU,CAAC,KAAK;GACjB,CAAC;MAEF,UAAS,SAAS,SAAS,GAAG,SAAS,KAAK,KAAqB;AAIrE,SAAO;GACL,MAAM;GACN,MAAM;GACN,YAAY,CACV;IACE,MAAM;IACN,MAAM;IACN,OAAO;IACR,CACF;GACD,MAAM,EACJ,UAAU,MACX;GACD;GACD;;AAGH,SAAQ,SAAS;AACf,QAAM,OAAO,WAAW;AACtB,OAAI,EAAE,cAAc,WAAW,OAAO,SAAS,UAAW;AAC1D,OAAI,OAAO,QAAQ,cAAc,OAAO,KAAM,QAAO;GAErD,IAAI,WAAW;GACf,IAAI,IAAI;GAER,MAAM,cAAc;AAClB,QAAI,aAAa,GAAI;IAErB,MAAM,OAAO,EAAE;IACf,MAAM,QAAQ,OAAO,SAAS,OAAO,UAAU,IAAI,UAAU,KAAoB;AACjF,WAAO,OAAO,MAAM,eAAe,MAAM,CAAC;AAC1C,QAAI,WAAW;AACf,eAAW;;AAGb,UAAO,IAAI,OAAO,SAAS,QAAQ,KAAK;IACtC,MAAM,OAAO,OAAO,SAAS;AAE7B,QAAI,KAAK,SAAS,UAAW;AAC7B,QAAI,aAAa,IAAI;KACnB,MAAM,aAAc,OAAO,SAAS,UAAsB;AAE1D,SAAI,KAAK,QAAQ,WAAY;cACpB,KAAK,QAAQ,WAAY,QAAO;;IAG3C,MAAM,OAAO,KAAK,SAAS,QAAQ,MAAM,EAAE,SAAS,OAAO,CAAC,GAAG,EAAE;AACjE,QAAI,CAAC,MAAM;AACT,YAAO;AACP;;IAGF,MAAM,QAAQ,UAAU,KAAK,KAAK,MAAM;AACxC,QAAI,CAAC,OAAO;AACV,YAAO;AACP;;AAGF,SAAK,QAAQ,MAAM;AACnB,QAAI,aAAa,GAAI,YAAW;;AAGlC,UAAO;IACP"}
1
+ {"version":3,"file":"remark-steps.js","names":[],"sources":["../../src/mdx-plugins/remark-steps.ts"],"sourcesContent":["import type { Transformer } from 'unified';\nimport type { BlockContent, Heading, Root, RootContent } from 'mdast';\nimport { visit } from 'unist-util-visit';\nimport type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\n\nexport interface RemarkStepsOptions {\n /**\n * Class name for steps container\n *\n * @defaultValue fd-steps\n */\n steps?: string;\n\n /**\n * Class name for step container\n *\n * @defaultValue fd-step\n */\n step?: string;\n}\n\nconst StepRegex = /^(\\d+)\\.\\s(.+)$/;\n\n/**\n * Convert headings in the format of `1. Hello World` into steps.\n */\nexport function remarkSteps({\n steps = 'fd-steps',\n step = 'fd-step',\n}: RemarkStepsOptions = {}): Transformer<Root, Root> {\n function convertToSteps(nodes: RootContent[]): MdxJsxFlowElement {\n const depth = (nodes[0] as Heading).depth;\n const children: MdxJsxFlowElement[] = [];\n\n for (const node of nodes) {\n if (node.type === 'heading' && node.depth === depth) {\n children.push({\n type: 'mdxJsxFlowElement',\n name: 'div',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'className',\n value: step,\n },\n ],\n children: [node],\n });\n } else {\n children[children.length - 1].children.push(node as BlockContent);\n }\n }\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'div',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'className',\n value: steps,\n },\n ],\n data: {\n _fd_step: true,\n } as object,\n children,\n };\n }\n\n return (tree) => {\n visit(tree, (parent) => {\n if (!('children' in parent) || parent.type === 'heading') return;\n if (parent.data && '_fd_step' in parent.data) return 'skip';\n\n let startIdx = -1;\n let i = 0;\n\n const onEnd = () => {\n if (startIdx === -1) return;\n // range: start index to i - 1\n const item = {};\n const nodes = parent.children.splice(startIdx, i - startIdx, item as RootContent);\n Object.assign(item, convertToSteps(nodes));\n i = startIdx + 1;\n startIdx = -1;\n };\n\n for (; i < parent.children.length; i++) {\n const node = parent.children[i];\n\n if (node.type !== 'heading') continue;\n if (startIdx !== -1) {\n const startDepth = (parent.children[startIdx] as Heading).depth;\n\n if (node.depth > startDepth) continue;\n else if (node.depth < startDepth) onEnd();\n }\n\n const head = node.children.filter((c) => c.type === 'text').at(0);\n if (!head) {\n onEnd();\n continue;\n }\n\n const match = StepRegex.exec(head.value);\n if (!match) {\n onEnd();\n continue;\n }\n\n head.value = match[2];\n if (startIdx === -1) startIdx = i;\n }\n\n onEnd();\n });\n };\n}\n"],"mappings":";;;AAqBA,MAAM,YAAY;;;;AAKlB,SAAgB,YAAY,EAC1B,QAAQ,YACR,OAAO,cACe,EAAE,EAA2B;CACnD,SAAS,eAAe,OAAyC;EAC/D,MAAM,QAAS,MAAM,GAAe;EACpC,MAAM,WAAgC,EAAE;AAExC,OAAK,MAAM,QAAQ,MACjB,KAAI,KAAK,SAAS,aAAa,KAAK,UAAU,MAC5C,UAAS,KAAK;GACZ,MAAM;GACN,MAAM;GACN,YAAY,CACV;IACE,MAAM;IACN,MAAM;IACN,OAAO;IACR,CACF;GACD,UAAU,CAAC,KAAK;GACjB,CAAC;MAEF,UAAS,SAAS,SAAS,GAAG,SAAS,KAAK,KAAqB;AAIrE,SAAO;GACL,MAAM;GACN,MAAM;GACN,YAAY,CACV;IACE,MAAM;IACN,MAAM;IACN,OAAO;IACR,CACF;GACD,MAAM,EACJ,UAAU,MACX;GACD;GACD;;AAGH,SAAQ,SAAS;AACf,QAAM,OAAO,WAAW;AACtB,OAAI,EAAE,cAAc,WAAW,OAAO,SAAS,UAAW;AAC1D,OAAI,OAAO,QAAQ,cAAc,OAAO,KAAM,QAAO;GAErD,IAAI,WAAW;GACf,IAAI,IAAI;GAER,MAAM,cAAc;AAClB,QAAI,aAAa,GAAI;IAErB,MAAM,OAAO,EAAE;IACf,MAAM,QAAQ,OAAO,SAAS,OAAO,UAAU,IAAI,UAAU,KAAoB;AACjF,WAAO,OAAO,MAAM,eAAe,MAAM,CAAC;AAC1C,QAAI,WAAW;AACf,eAAW;;AAGb,UAAO,IAAI,OAAO,SAAS,QAAQ,KAAK;IACtC,MAAM,OAAO,OAAO,SAAS;AAE7B,QAAI,KAAK,SAAS,UAAW;AAC7B,QAAI,aAAa,IAAI;KACnB,MAAM,aAAc,OAAO,SAAS,UAAsB;AAE1D,SAAI,KAAK,QAAQ,WAAY;cACpB,KAAK,QAAQ,WAAY,QAAO;;IAG3C,MAAM,OAAO,KAAK,SAAS,QAAQ,MAAM,EAAE,SAAS,OAAO,CAAC,GAAG,EAAE;AACjE,QAAI,CAAC,MAAM;AACT,YAAO;AACP;;IAGF,MAAM,QAAQ,UAAU,KAAK,KAAK,MAAM;AACxC,QAAI,CAAC,OAAO;AACV,YAAO;AACP;;AAGF,SAAK,QAAQ,MAAM;AACnB,QAAI,aAAa,GAAI,YAAW;;AAGlC,UAAO;IACP"}
@@ -1,2 +1,2 @@
1
- import { a as structure, i as remarkStructureDefaultOptions, n as StructuredData, r as remarkStructure, t as StructureOptions } from "../remark-structure-CszwnaMR.js";
1
+ import { a as structure, i as remarkStructureDefaultOptions, n as StructuredData, r as remarkStructure, t as StructureOptions } from "../remark-structure-ChKxMXnK.js";
2
2
  export { StructureOptions, StructuredData, remarkStructure, remarkStructureDefaultOptions, structure };
@@ -1,4 +1,4 @@
1
- import { n as toMdxExport, t as flattenNode } from "../mdast-utils-ix4DsXJP.js";
1
+ import { n as toMdxExport, t as flattenNode } from "../mdast-utils-B8O-41y4.js";
2
2
  import { remark } from "remark";
3
3
  import remarkGfm from "remark-gfm";
4
4
  import Slugger from "github-slugger";