mintlify 1.1.3 → 1.1.4

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 (160) hide show
  1. package/bin/local-preview/injectNav.js +94 -0
  2. package/bin/local-preview/injectNav.js.map +1 -0
  3. package/bin/local-preview/utils/metadata.js +1 -0
  4. package/bin/local-preview/utils/metadata.js.map +1 -1
  5. package/bin/mint/client/.babel-plugin-macrosrc.json +5 -0
  6. package/bin/mint/client/.babelrc +4 -0
  7. package/bin/mint/client/.editorconfig +12 -0
  8. package/bin/mint/client/.eslintrc.json +7 -0
  9. package/bin/mint/client/.prettierignore +4 -0
  10. package/bin/mint/client/.prettierrc +14 -0
  11. package/bin/mint/client/.vscode/launch.json +28 -0
  12. package/bin/mint/client/README.md +44 -0
  13. package/bin/mint/client/jest.config.ts +195 -0
  14. package/bin/mint/client/next-env.d.ts +4 -0
  15. package/bin/mint/client/next.config.js +152 -0
  16. package/bin/mint/client/package.json +139 -0
  17. package/bin/mint/client/postcss.config.cjs +9 -0
  18. package/bin/mint/client/prebuild/faviconConfig.js +35 -0
  19. package/bin/mint/client/prebuild/getOpenApiContext.js +53 -0
  20. package/bin/mint/client/prebuild/index.js +117 -0
  21. package/bin/mint/client/prebuild/injectNav.js +115 -0
  22. package/bin/mint/client/prebuild/slugToTitle.js +7 -0
  23. package/bin/mint/client/rehype/withApiComponents.js +60 -0
  24. package/bin/mint/client/rehype/withCodeBlocks.js +54 -0
  25. package/bin/mint/client/rehype/withLayouts.js +113 -0
  26. package/bin/mint/client/rehype/withLinkRoles.js +13 -0
  27. package/bin/mint/client/rehype/withRawComponents.js +13 -0
  28. package/bin/mint/client/rehype/withStaticProps.js +25 -0
  29. package/bin/mint/client/rehype/withSyntaxHighlighting.js +60 -0
  30. package/bin/mint/client/remark/utils.js +369 -0
  31. package/bin/mint/client/remark/withFrames.js +55 -0
  32. package/bin/mint/client/remark/withImportsInjected.js +36 -0
  33. package/bin/mint/client/remark/withNextLinks.js +37 -0
  34. package/bin/mint/client/remark/withTableOfContents.js +71 -0
  35. package/bin/mint/client/scripts/local.js +177 -0
  36. package/bin/mint/client/sentry.client.config.js +15 -0
  37. package/bin/mint/client/sentry.properties +4 -0
  38. package/bin/mint/client/sentry.server.config.js +15 -0
  39. package/bin/mint/client/src/analytics/AbstractAnalyticsImplementation.ts +50 -0
  40. package/bin/mint/client/src/analytics/AnalyticsContext.ts +5 -0
  41. package/bin/mint/client/src/analytics/AnalyticsMediator.ts +101 -0
  42. package/bin/mint/client/src/analytics/FakeAnalyticsMediator.ts +9 -0
  43. package/bin/mint/client/src/analytics/GA4Script.tsx +33 -0
  44. package/bin/mint/client/src/analytics/implementations/amplitude.ts +26 -0
  45. package/bin/mint/client/src/analytics/implementations/fathom.ts +38 -0
  46. package/bin/mint/client/src/analytics/implementations/ga4.ts +33 -0
  47. package/bin/mint/client/src/analytics/implementations/hotjar.ts +53 -0
  48. package/bin/mint/client/src/analytics/implementations/mixpanel-browser.d.ts +1 -0
  49. package/bin/mint/client/src/analytics/implementations/mixpanel.ts +52 -0
  50. package/bin/mint/client/src/analytics/implementations/posthog.ts +37 -0
  51. package/bin/mint/client/src/components/Accordion/Accordion.tsx +43 -0
  52. package/bin/mint/client/src/components/Accordion/index.ts +4 -0
  53. package/bin/mint/client/src/components/ApiExample.tsx +9 -0
  54. package/bin/mint/client/src/components/Card.tsx +51 -0
  55. package/bin/mint/client/src/components/CodeGroup.tsx +132 -0
  56. package/bin/mint/client/src/components/Editor.tsx +12 -0
  57. package/bin/mint/client/src/components/Expandable.tsx +40 -0
  58. package/bin/mint/client/src/components/Heading.tsx +84 -0
  59. package/bin/mint/client/src/components/Param.tsx +56 -0
  60. package/bin/mint/client/src/components/Request.tsx +19 -0
  61. package/bin/mint/client/src/components/ResponseField.tsx +33 -0
  62. package/bin/mint/client/src/components/TabBar.tsx +61 -0
  63. package/bin/mint/client/src/config.ts +115 -0
  64. package/bin/mint/client/src/css/bar-of-progress.css +10 -0
  65. package/bin/mint/client/src/css/base.css +29 -0
  66. package/bin/mint/client/src/css/font-awesome.css +7 -0
  67. package/bin/mint/client/src/css/fonts.css +44 -0
  68. package/bin/mint/client/src/css/main.css +11 -0
  69. package/bin/mint/client/src/css/prism.css +270 -0
  70. package/bin/mint/client/src/css/utilities.css +43 -0
  71. package/bin/mint/client/src/enums/components.ts +8 -0
  72. package/bin/mint/client/src/fonts/FiraCode-VF.woff +0 -0
  73. package/bin/mint/client/src/fonts/FiraCode-VF.woff2 +0 -0
  74. package/bin/mint/client/src/fonts/IBMPlexMono-Regular.ttf +0 -0
  75. package/bin/mint/client/src/fonts/IBMPlexMono-SemiBold.ttf +0 -0
  76. package/bin/mint/client/src/fonts/Inter-italic-latin.var.woff2 +0 -0
  77. package/bin/mint/client/src/fonts/Inter-roman-latin.var.woff2 +0 -0
  78. package/bin/mint/client/src/fonts/Pally-Variable.ttf +0 -0
  79. package/bin/mint/client/src/fonts/SourceSansPro-Regular.otf +0 -0
  80. package/bin/mint/client/src/fonts/SourceSerifPro-Regular.ttf +0 -0
  81. package/bin/mint/client/src/fonts/Synonym-Variable.ttf +0 -0
  82. package/bin/mint/client/src/fonts/Ubuntu-Mono-bold.woff2 +0 -0
  83. package/bin/mint/client/src/fonts/generated/IBMPlexMono-Regular-subset.woff2 +0 -0
  84. package/bin/mint/client/src/fonts/generated/IBMPlexMono-Regular-subset.zopfli.woff +0 -0
  85. package/bin/mint/client/src/fonts/generated/IBMPlexMono-Regular.module.css +11 -0
  86. package/bin/mint/client/src/fonts/generated/IBMPlexMono-SemiBold-subset.woff2 +0 -0
  87. package/bin/mint/client/src/fonts/generated/IBMPlexMono-SemiBold-subset.zopfli.woff +0 -0
  88. package/bin/mint/client/src/fonts/generated/IBMPlexMono-SemiBold.module.css +11 -0
  89. package/bin/mint/client/src/fonts/generated/Pally-Variable-subset.woff2 +0 -0
  90. package/bin/mint/client/src/fonts/generated/Pally-Variable-subset.zopfli.woff +0 -0
  91. package/bin/mint/client/src/fonts/generated/Pally-Variable.module.css +11 -0
  92. package/bin/mint/client/src/fonts/generated/SourceSerifPro-Regular-subset.woff2 +0 -0
  93. package/bin/mint/client/src/fonts/generated/SourceSerifPro-Regular-subset.zopfli.woff +0 -0
  94. package/bin/mint/client/src/fonts/generated/SourceSerifPro-Regular.module.css +11 -0
  95. package/bin/mint/client/src/fonts/generated/Synonym-Variable-subset.woff2 +0 -0
  96. package/bin/mint/client/src/fonts/generated/Synonym-Variable-subset.zopfli.woff +0 -0
  97. package/bin/mint/client/src/fonts/generated/Synonym-Variable.module.css +11 -0
  98. package/bin/mint/client/src/fonts/generated/TenorSans-Regular-subset.woff2 +0 -0
  99. package/bin/mint/client/src/fonts/generated/TenorSans-Regular-subset.zopfli.woff +0 -0
  100. package/bin/mint/client/src/fonts/generated/TenorSans-Regular.module.css +11 -0
  101. package/bin/mint/client/src/hooks/useActionKey.ts +20 -0
  102. package/bin/mint/client/src/hooks/useIsomorphicLayoutEffect.ts +3 -0
  103. package/bin/mint/client/src/hooks/useMedia.ts +27 -0
  104. package/bin/mint/client/src/hooks/usePrevNext.ts +34 -0
  105. package/bin/mint/client/src/hooks/useTop.ts +15 -0
  106. package/bin/mint/client/src/icons/CopyToClipboard.tsx +33 -0
  107. package/bin/mint/client/src/index.d.ts +1 -0
  108. package/bin/mint/client/src/layouts/ApiSupplemental.tsx +173 -0
  109. package/bin/mint/client/src/layouts/ContentsLayout.tsx +256 -0
  110. package/bin/mint/client/src/layouts/DocumentationLayout.tsx +44 -0
  111. package/bin/mint/client/src/layouts/OpenApiContent.tsx +301 -0
  112. package/bin/mint/client/src/layouts/SidebarLayout.tsx +412 -0
  113. package/bin/mint/client/src/layouts/UserFeedback.tsx +73 -0
  114. package/bin/mint/client/src/layouts/getGroupsInDivision.ts +25 -0
  115. package/bin/mint/client/src/layouts/isPathInGroupPages.ts +10 -0
  116. package/bin/mint/client/src/metadata.ts +58 -0
  117. package/bin/mint/client/src/nav.json +219 -0
  118. package/bin/mint/client/src/openapi.ts +3 -0
  119. package/bin/mint/client/src/pages/404.tsx +73 -0
  120. package/bin/mint/client/src/pages/_app.tsx +138 -0
  121. package/bin/mint/client/src/pages/_document.tsx +57 -0
  122. package/bin/mint/client/src/pages/api/issue.ts +10 -0
  123. package/bin/mint/client/src/pages/api/name.ts +8 -0
  124. package/bin/mint/client/src/pages/api/request.ts +31 -0
  125. package/bin/mint/client/src/pages/api/suggest.ts +10 -0
  126. package/bin/mint/client/src/pages/api/syntax-highlighted-json.ts +13 -0
  127. package/bin/mint/client/src/pages/api/utils.ts +6 -0
  128. package/bin/mint/client/src/pages/index.tsx +31 -0
  129. package/bin/mint/client/src/ui/Api.tsx +359 -0
  130. package/bin/mint/client/src/ui/Footer.tsx +124 -0
  131. package/bin/mint/client/src/ui/Header.tsx +370 -0
  132. package/bin/mint/client/src/ui/Logo.tsx +55 -0
  133. package/bin/mint/client/src/ui/PageHeader.tsx +51 -0
  134. package/bin/mint/client/src/ui/Search.tsx +386 -0
  135. package/bin/mint/client/src/ui/ThemeToggle.tsx +285 -0
  136. package/bin/mint/client/src/ui/Title.tsx +22 -0
  137. package/bin/mint/client/src/ui/TopLevelLink.tsx +122 -0
  138. package/bin/mint/client/src/utils/api.ts +252 -0
  139. package/bin/mint/client/src/utils/brands.ts +217 -0
  140. package/bin/mint/client/src/utils/castArray.ts +3 -0
  141. package/bin/mint/client/src/utils/childrenArray.ts +3 -0
  142. package/bin/mint/client/src/utils/fit.ts +27 -0
  143. package/bin/mint/client/src/utils/fontAwesome.ts +577 -0
  144. package/bin/mint/client/src/utils/getAnalyticsConfig.ts +14 -0
  145. package/bin/mint/client/src/utils/getLogoHref.ts +9 -0
  146. package/bin/mint/client/src/utils/getOpenApiContext.ts +26 -0
  147. package/bin/mint/client/src/utils/importAll.ts +6 -0
  148. package/bin/mint/client/src/utils/isObject.ts +3 -0
  149. package/bin/mint/client/src/utils/kebabToTitleCase.ts +3 -0
  150. package/bin/mint/client/src/utils/loadImage.ts +8 -0
  151. package/bin/mint/client/src/utils/slugToTitle.ts +7 -0
  152. package/bin/mint/client/src/utils/wait.ts +5 -0
  153. package/bin/mint/client/tailwind.config.cjs +323 -0
  154. package/bin/mint/client/test/test.test.ts +5 -0
  155. package/bin/mint/client/tsconfig.json +36 -0
  156. package/bin/mint/client/yarn.lock +9702 -0
  157. package/package.json +1 -1
  158. package/src/local-preview/utils/metadata.ts +1 -0
  159. package/bin/local-preview/helper-commands/cleanCommand.js +0 -8
  160. package/bin/local-preview/helper-commands/cleanCommand.js.map +0 -1
@@ -0,0 +1,113 @@
1
+ import { getEsmNode } from '../remark/utils.js';
2
+
3
+ const withLayouts = () => {
4
+ return (tree) => {
5
+ const importNode = getEsmNode(
6
+ `import { ContentsLayout as _Default } from '@/layouts/ContentsLayout'`
7
+ );
8
+ tree.children.unshift(importNode);
9
+ tree.children.push({
10
+ type: 'mdxjsEsm',
11
+ value: `export default (props) => <_Default {...props} tableOfContents={tableOfContents} apiComponents={apiComponents}>{props.children}</_Default>`,
12
+ data: {
13
+ estree: {
14
+ type: 'Program',
15
+ sourceType: 'module',
16
+ body: [
17
+ {
18
+ type: 'ExportDefaultDeclaration',
19
+ declaration: {
20
+ type: 'ArrowFunctionExpression',
21
+ async: false,
22
+ expression: true,
23
+ generator: false,
24
+ id: null,
25
+ body: {
26
+ type: 'JSXElement',
27
+ children: [
28
+ {
29
+ type: 'JSXExpressionContainer',
30
+ expression: {
31
+ type: 'MemberExpression',
32
+ computed: false,
33
+ optional: false,
34
+ object: {
35
+ name: 'props',
36
+ type: 'Identifier',
37
+ },
38
+ property: {
39
+ name: 'children',
40
+ type: 'Identifier',
41
+ },
42
+ },
43
+ },
44
+ ],
45
+ closingElement: {
46
+ type: 'JSXClosingElement',
47
+ name: {
48
+ type: 'JSXIdentifier',
49
+ name: '_Default',
50
+ },
51
+ },
52
+ openingElement: {
53
+ type: 'JSXOpeningElement',
54
+ selfClosing: false,
55
+ name: {
56
+ type: 'JSXIdentifier',
57
+ name: '_Default',
58
+ },
59
+ attributes: [
60
+ {
61
+ type: 'JSXSpreadAttribute',
62
+ argument: {
63
+ type: 'Identifier',
64
+ name: 'props',
65
+ },
66
+ },
67
+ {
68
+ type: 'JSXAttribute',
69
+ name: {
70
+ type: 'JSXIdentifier',
71
+ name: 'tableOfContents',
72
+ },
73
+ value: {
74
+ type: 'JSXExpressionContainer',
75
+ expression: {
76
+ type: 'Identifier',
77
+ name: 'tableOfContents',
78
+ },
79
+ },
80
+ },
81
+ {
82
+ type: 'JSXAttribute',
83
+ name: {
84
+ type: 'JSXIdentifier',
85
+ name: 'apiComponents',
86
+ },
87
+ value: {
88
+ type: 'JSXExpressionContainer',
89
+ expression: {
90
+ type: 'Identifier',
91
+ name: 'apiComponents',
92
+ },
93
+ },
94
+ },
95
+ ],
96
+ },
97
+ },
98
+ params: [
99
+ {
100
+ type: 'Identifier',
101
+ name: 'props',
102
+ },
103
+ ],
104
+ },
105
+ },
106
+ ],
107
+ },
108
+ },
109
+ });
110
+ };
111
+ };
112
+
113
+ export default withLayouts;
@@ -0,0 +1,13 @@
1
+ import visit from 'unist-util-visit';
2
+
3
+ const withLinkRoles = () => {
4
+ return (tree) => {
5
+ visit(tree, 'element', (element) => {
6
+ if (['ol', 'ul'].includes(element.tagName)) {
7
+ element.properties.role = 'list';
8
+ }
9
+ });
10
+ };
11
+ };
12
+
13
+ export default withLinkRoles;
@@ -0,0 +1,13 @@
1
+ import { fromHtml } from 'hast-util-from-html';
2
+ import visit from 'unist-util-visit';
3
+
4
+ const withRawComponents = () => {
5
+ return (tree) => {
6
+ visit(tree, 'raw', (raw, i, parent) => {
7
+ const rawAst = fromHtml(raw.value, { fragment: true });
8
+ parent.children[i] = rawAst;
9
+ });
10
+ };
11
+ };
12
+
13
+ export default withRawComponents;
@@ -0,0 +1,25 @@
1
+ import { parse } from 'acorn';
2
+
3
+ const withStaticProps = (map) => {
4
+ return function transformer(tree) {
5
+ tree.children.push({
6
+ type: 'mdxjsEsm',
7
+ data: {
8
+ estree: parse(
9
+ `
10
+ export const getStaticProps = async () => {
11
+ return {
12
+ props: ${map},
13
+ }
14
+ }`,
15
+ {
16
+ sourceType: 'module',
17
+ ecmaVersion: 2020,
18
+ }
19
+ ),
20
+ },
21
+ });
22
+ };
23
+ };
24
+
25
+ export default withStaticProps;
@@ -0,0 +1,60 @@
1
+ import { toString } from 'hast-util-to-string';
2
+ import { refractor } from 'refractor';
3
+ import docker from 'refractor/lang/docker.js';
4
+ import jsx from 'refractor/lang/jsx.js';
5
+ import protobuf from 'refractor/lang/protobuf.js';
6
+ import visit from 'unist-util-visit';
7
+
8
+ refractor.register(jsx);
9
+ refractor.register(docker);
10
+ refractor.register(protobuf);
11
+
12
+ const withSyntaxHighlighting = (options) => {
13
+ options = options || {};
14
+
15
+ if (options.alias) {
16
+ refractor.alias(options.alias);
17
+ }
18
+
19
+ return (tree) => {
20
+ visit(tree, 'element', visitor);
21
+ };
22
+
23
+ function visitor(node, _, parent) {
24
+ if (!parent || parent.tagName !== 'pre' || node.tagName !== 'code') {
25
+ return;
26
+ }
27
+
28
+ const lang = getLanguage(node);
29
+
30
+ if (lang === null) {
31
+ return;
32
+ }
33
+
34
+ let result;
35
+ try {
36
+ parent.properties.className = (parent.properties.className || []).concat('language-' + lang);
37
+ result = refractor.highlight(toString(node), lang);
38
+ node.children = result.children;
39
+ } catch (err) {
40
+ if (options.ignoreMissing && /Unknown language/.test(err.message)) {
41
+ return;
42
+ }
43
+ throw err;
44
+ }
45
+ }
46
+ };
47
+
48
+ function getLanguage(node) {
49
+ const className = node.properties.className || [];
50
+
51
+ for (const classListItem of className) {
52
+ if (classListItem.slice(0, 9) === 'language-') {
53
+ return classListItem.slice(9).toLowerCase();
54
+ }
55
+ }
56
+
57
+ return null;
58
+ }
59
+
60
+ export default withSyntaxHighlighting;
@@ -0,0 +1,369 @@
1
+ import * as acorn from 'acorn';
2
+ import { fromMarkdown } from 'mdast-util-from-markdown';
3
+ import { mdxJsxFromMarkdown } from 'mdast-util-mdx-jsx';
4
+ import { mdxjsEsmFromMarkdown } from 'mdast-util-mdxjs-esm';
5
+ import { mdxJsx } from 'micromark-extension-mdx-jsx';
6
+ import { mdxjsEsm } from 'micromark-extension-mdxjs-esm';
7
+ import Prism from 'prismjs';
8
+ import loadLanguages from 'prismjs/components/index.js';
9
+ import redent from 'redent';
10
+
11
+ loadLanguages();
12
+
13
+ const HTML_TAG =
14
+ /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/gi;
15
+ const PSEUDO_CLASSES = [
16
+ 'active',
17
+ 'any-link',
18
+ 'blank',
19
+ 'checked',
20
+ 'current',
21
+ 'default',
22
+ 'defined',
23
+ 'dir',
24
+ 'disabled',
25
+ 'drop',
26
+ 'empty',
27
+ 'enabled',
28
+ 'first',
29
+ 'first-child',
30
+ 'first-of-type',
31
+ 'fullscreen',
32
+ 'future',
33
+ 'focus',
34
+ 'focus-visible',
35
+ 'focus-within',
36
+ 'has',
37
+ 'host',
38
+ 'host',
39
+ 'host-context',
40
+ 'hover',
41
+ 'indeterminate',
42
+ 'in-range',
43
+ 'invalid',
44
+ 'is',
45
+ 'lang',
46
+ 'last-child',
47
+ 'last-of-type',
48
+ 'left',
49
+ 'link',
50
+ 'local-link',
51
+ 'not',
52
+ 'nth-child',
53
+ 'nth-col',
54
+ 'nth-last-child',
55
+ 'nth-last-col',
56
+ 'nth-last-of-type',
57
+ 'nth-of-type',
58
+ 'only-child',
59
+ 'only-of-type',
60
+ 'optional',
61
+ 'out-of-range',
62
+ 'past',
63
+ 'picture-in-picture',
64
+ 'placeholder-shown',
65
+ 'read-only',
66
+ 'read-write',
67
+ 'required',
68
+ 'right',
69
+ 'root',
70
+ 'scope',
71
+ 'state',
72
+ 'target',
73
+ 'target-within',
74
+ 'user-invalid',
75
+ 'valid',
76
+ 'visited',
77
+ 'where',
78
+ ];
79
+
80
+ Prism.hooks.add('wrap', (env) => {
81
+ if (env.type === 'atrule') {
82
+ const content = env.content.replace(HTML_TAG, '');
83
+ if (content.startsWith('@apply')) {
84
+ env.classes.push('atapply');
85
+ }
86
+ } else if (env.type === 'pseudo-class') {
87
+ if (!new RegExp(`^::?(${PSEUDO_CLASSES.join('|')})`).test(env.content)) {
88
+ env.classes = env.classes.filter((x) => x !== 'pseudo-class');
89
+ }
90
+ }
91
+ });
92
+
93
+ Prism.hooks.add('after-tokenize', ({ language, tokens }) => {
94
+ if (language === 'css') {
95
+ fixSelectorEscapeTokens(tokens);
96
+ }
97
+ });
98
+
99
+ export function fixSelectorEscapeTokens(tokens) {
100
+ for (let token of tokens) {
101
+ if (typeof token === 'string') continue;
102
+ if (token.type !== 'selector') continue;
103
+ for (let i = 0; i < token.content.length; i++) {
104
+ if (token.content[i] === '\\' && token.content[i - 1]?.type === 'class') {
105
+ token.content[i] = new Prism.Token('punctuation', token.content[i]);
106
+ token.content[i + 1].type = 'class';
107
+ }
108
+ }
109
+ }
110
+ }
111
+
112
+ export const createMdxJsxAttribute = (key, value) => {
113
+ return {
114
+ type: 'mdxJsxAttribute',
115
+ name: key,
116
+ value,
117
+ };
118
+ };
119
+
120
+ export const tomdxJsxFlowElement = (input) => {
121
+ const tree = fromMarkdown(input, {
122
+ extensions: [mdxJsx({ acorn: acorn, addResult: true })],
123
+ mdastExtensions: [mdxJsxFromMarkdown()],
124
+ });
125
+ return tree.children[0];
126
+ };
127
+
128
+ export const getEsmNode = (input) => {
129
+ const tree = fromMarkdown(input, {
130
+ extensions: [mdxjsEsm({ acorn, addResult: true })],
131
+ mdastExtensions: [mdxjsEsmFromMarkdown],
132
+ });
133
+ return tree.children[0];
134
+ };
135
+
136
+ export function addImportString(tree, jsx) {
137
+ tree.children.unshift(getEsmNode(jsx));
138
+ }
139
+
140
+ export function addImport(tree, mod, name) {
141
+ const jsx = `import { ${name} as _${name} } from '${mod}'`;
142
+ tree.children.unshift(getEsmNode(jsx));
143
+ return `_${name}`;
144
+ }
145
+
146
+ export function addDefaultImport(tree, mod, name) {
147
+ const jsx = `import _${name} from '${mod}'`;
148
+ tree.children.unshift(getEsmNode(jsx));
149
+ return `_${name}`;
150
+ }
151
+
152
+ export function addExport(tree, name, value) {
153
+ const jsx = `export const ${name} = ${JSON.stringify(value)}`;
154
+ tree.children.push(getEsmNode(jsx));
155
+ }
156
+
157
+ function hasLineHighlights(code) {
158
+ return code.split('\n').some((line) => line === '' || /^[> ] /.test(line));
159
+ }
160
+
161
+ export function highlightCode(code, prismLanguage) {
162
+ const isDiff = prismLanguage.startsWith('diff-');
163
+ const language = isDiff ? prismLanguage.substr(5) : prismLanguage;
164
+ const grammar = Prism.languages[language];
165
+ if (!grammar) {
166
+ console.warn(`Unrecognised language: ${prismLanguage}`);
167
+ return Prism.util.encode(code);
168
+ }
169
+
170
+ let addedLines = [];
171
+ let removedLines = [];
172
+ if (isDiff) {
173
+ code = code.replace(/(?:^[+\- ] |^[+-]$)/gm, (match, offset) => {
174
+ let line = code.substr(0, offset).split('\n').length - 1;
175
+ if (match.startsWith('+')) {
176
+ addedLines.push(line);
177
+ } else if (match.startsWith('-')) {
178
+ removedLines.push(line);
179
+ }
180
+ return '';
181
+ });
182
+ }
183
+
184
+ let highlightedLines = [];
185
+
186
+ if (hasLineHighlights(code)) {
187
+ let match;
188
+ let re = /^>/m;
189
+ while ((match = re.exec(code)) !== null) {
190
+ let line = code.substr(0, match.index).split('\n').length - 1;
191
+ highlightedLines.push(line);
192
+ code = code.substr(0, match.index) + ' ' + code.substr(match.index + 1);
193
+ }
194
+ code = redent(code);
195
+ }
196
+
197
+ function stringify(line, className) {
198
+ let empty = line.every((token) => token.empty);
199
+
200
+ if (!className && empty) {
201
+ return '\n';
202
+ }
203
+
204
+ let commonTypes = [];
205
+ for (let i = 0; i < line.length; i++) {
206
+ let token = line[i];
207
+ if (i === 0) {
208
+ commonTypes.push(...token.types);
209
+ } else {
210
+ commonTypes = commonTypes.filter((type) => token.types.includes(type));
211
+ }
212
+ }
213
+ if (commonTypes.length) {
214
+ for (let i = 0; i < line.length; i++) {
215
+ let token = line[i];
216
+ token.types = token.types.filter((type) => !commonTypes.includes(type));
217
+ }
218
+ }
219
+
220
+ let lineClassName = ['token', ...commonTypes, className].filter(Boolean).join(' ');
221
+
222
+ if (empty) {
223
+ return `<span class="${lineClassName}">\n</span>`;
224
+ }
225
+
226
+ return `<span class="${lineClassName}">${line
227
+ .map((token) =>
228
+ token.types.length
229
+ ? `<span class="token ${token.types.join(' ')}">${token.content}</span>`
230
+ : token.content
231
+ )
232
+ .join('')}\n</span>`;
233
+ }
234
+
235
+ if (highlightedLines.length && language !== 'demo') {
236
+ let lines = normalizeTokens(Prism.util.encode(Prism.tokenize(code, grammar)));
237
+
238
+ code = lines
239
+ .map((line, index) =>
240
+ stringify(
241
+ line,
242
+ `block${
243
+ highlightedLines.includes(index)
244
+ ? ' -mx-5 pr-5 border-l-4 border-primary-light bg-primary-light/[0.15]'
245
+ : ''
246
+ }`
247
+ )
248
+ )
249
+ .join('');
250
+ } else {
251
+ code = Prism.highlight(code, grammar, prismLanguage);
252
+ }
253
+
254
+ return language === 'html'
255
+ ? code.replace(
256
+ /\*\*(.*?)\*\*/g,
257
+ (_, text) => `<span class="code-highlight bg-code-highlight">${text}</span>`
258
+ )
259
+ : code;
260
+ }
261
+
262
+ // https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/utils/normalizeTokens.js
263
+
264
+ const newlineRe = /\r\n|\r|\n/;
265
+
266
+ // Empty lines need to contain a single empty token, denoted with { empty: true }
267
+ function normalizeEmptyLines(line) {
268
+ if (line.length === 0) {
269
+ line.push({
270
+ types: ['plain'],
271
+ content: '',
272
+ empty: true,
273
+ });
274
+ } else if (line.length === 1 && line[0].content === '') {
275
+ line[0].empty = true;
276
+ }
277
+ }
278
+
279
+ function appendTypes(types, add) {
280
+ const typesSize = types.length;
281
+ if (typesSize > 0 && types[typesSize - 1] === add) {
282
+ return types;
283
+ }
284
+
285
+ return types.concat(add);
286
+ }
287
+
288
+ // Takes an array of Prism's tokens and groups them by line, turning plain
289
+ // strings into tokens as well. Tokens can become recursive in some cases,
290
+ // which means that their types are concatenated. Plain-string tokens however
291
+ // are always of type "plain".
292
+ // This is not recursive to avoid exceeding the call-stack limit, since it's unclear
293
+ // how nested Prism's tokens can become
294
+ export function normalizeTokens(tokens) {
295
+ const typeArrStack = [[]];
296
+ const tokenArrStack = [tokens];
297
+ const tokenArrIndexStack = [0];
298
+ const tokenArrSizeStack = [tokens.length];
299
+
300
+ let i = 0;
301
+ let stackIndex = 0;
302
+ let currentLine = [];
303
+
304
+ const acc = [currentLine];
305
+
306
+ while (stackIndex > -1) {
307
+ while ((i = tokenArrIndexStack[stackIndex]++) < tokenArrSizeStack[stackIndex]) {
308
+ let content;
309
+ let types = typeArrStack[stackIndex];
310
+
311
+ const tokenArr = tokenArrStack[stackIndex];
312
+ const token = tokenArr[i];
313
+
314
+ // Determine content and append type to types if necessary
315
+ if (typeof token === 'string') {
316
+ types = stackIndex > 0 ? types : ['plain'];
317
+ content = token;
318
+ } else {
319
+ types = appendTypes(types, token.type);
320
+ if (token.alias) {
321
+ types = appendTypes(types, token.alias);
322
+ }
323
+
324
+ content = token.content;
325
+ }
326
+
327
+ // If token.content is an array, increase the stack depth and repeat this while-loop
328
+ if (typeof content !== 'string') {
329
+ stackIndex++;
330
+ typeArrStack.push(types);
331
+ tokenArrStack.push(content);
332
+ tokenArrIndexStack.push(0);
333
+ tokenArrSizeStack.push(content.length);
334
+ continue;
335
+ }
336
+
337
+ // Split by newlines
338
+ const splitByNewlines = content.split(newlineRe);
339
+ const newlineCount = splitByNewlines.length;
340
+
341
+ currentLine.push({ types, content: splitByNewlines[0] });
342
+
343
+ // Create a new line for each string on a new line
344
+ for (let i = 1; i < newlineCount; i++) {
345
+ normalizeEmptyLines(currentLine);
346
+ acc.push((currentLine = []));
347
+ currentLine.push({ types, content: splitByNewlines[i] });
348
+ }
349
+ }
350
+
351
+ // Decreate the stack depth
352
+ stackIndex--;
353
+ typeArrStack.pop();
354
+ tokenArrStack.pop();
355
+ tokenArrIndexStack.pop();
356
+ tokenArrSizeStack.pop();
357
+ }
358
+
359
+ normalizeEmptyLines(currentLine);
360
+ return acc;
361
+ }
362
+
363
+ export function simplifyToken(token) {
364
+ if (typeof token === 'string') return token;
365
+ return [
366
+ token.type,
367
+ Array.isArray(token.content) ? token.content.map(simplifyToken) : token.content,
368
+ ];
369
+ }
@@ -0,0 +1,55 @@
1
+ import { addImport, tomdxJsxFlowElement } from './utils.js';
2
+
3
+ const withFrames = () => {
4
+ return (tree) => {
5
+ let preTree = { children: [] };
6
+ let componentName;
7
+
8
+ tree.children = tree.children.map((node, index) => {
9
+ // Start of horizontal block: -- block
10
+ if (
11
+ node.type === 'paragraph' &&
12
+ node.children.length === 1 &&
13
+ node.children[0].value === '-- block'
14
+ ) {
15
+ node.type = 'jsx';
16
+ node.value = `<div className='grid md:grid-cols-2 md:gap-8'><div>`;
17
+ }
18
+
19
+ // Start a new column: -- column
20
+ if (
21
+ node.type === 'paragraph' &&
22
+ node.children.length === 1 &&
23
+ node.children[0].value === '-- column'
24
+ ) {
25
+ node.type = 'jsx';
26
+ node.value = `</div><div>`;
27
+ }
28
+
29
+ // End of horizontal block: -- /block
30
+ if (
31
+ node.type === 'paragraph' &&
32
+ node.children.length === 1 &&
33
+ node.children[0].value === '-- /block'
34
+ ) {
35
+ node.type = 'jsx';
36
+ node.value = `</div></div>`;
37
+ }
38
+
39
+ if (node.type === 'mdxJsxFlowElement' && (node.name === 'Example' || node.name === 'Frame')) {
40
+ if (!componentName) {
41
+ componentName = addImport(preTree, '@mintlify/components', 'Frame');
42
+ }
43
+ node.name = componentName;
44
+ }
45
+ if (node.type === 'jsx') {
46
+ node = tomdxJsxFlowElement(node.value);
47
+ }
48
+ return node;
49
+ });
50
+
51
+ tree.children = [...preTree.children, ...tree.children];
52
+ };
53
+ };
54
+
55
+ export default withFrames;
@@ -0,0 +1,36 @@
1
+ import { addImportString } from './utils.js';
2
+
3
+ const imports = `
4
+ import { Accordion, AccordionGroup } from '@/components/Accordion'
5
+ import { Heading } from '@/components/Heading'
6
+ import { CodeGroup, SnippetGroup } from '@/components/CodeGroup'
7
+ import { RequestSimple } from '@/components/Request'
8
+ import { RequestExample, ResponseExample } from '@/components/ApiExample'
9
+ import { Param, ParamField } from '@/components/Param'
10
+ import { Card } from '@/components/Card'
11
+ import { ResponseField } from '@/components/ResponseField'
12
+ import { Expandable } from '@/components/Expandable'
13
+ import { CardGroup, Info, Warning, Note, Tip, Check } from '@mintlify/components'
14
+ import { Tabs, Tab } from '@mintlify/components'
15
+ import { Tooltip } from '@mintlify/components'
16
+ import { solid, regular, light, thin, duotone, brands } from '@fortawesome/fontawesome-svg-core/import.macro'
17
+ `;
18
+
19
+ const withImportsInjected = () => {
20
+ return (tree) => {
21
+ tree.children = tree.children.filter((node) => {
22
+ return (
23
+ (node.type === 'import' && !node.value?.includes('@/components/')) || node.type !== 'import'
24
+ );
25
+ });
26
+
27
+ imports
28
+ .trim()
29
+ .split('\n')
30
+ .forEach((importLine) => {
31
+ addImportString(tree, importLine);
32
+ });
33
+ };
34
+ };
35
+
36
+ export default withImportsInjected;