@mui/internal-docs-infra 0.3.1-canary.2 → 0.3.1-canary.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 (110) hide show
  1. package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
  2. package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
  3. package/esm/CodeHighlighter/CodeHighlighter.js +252 -327
  4. package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
  5. package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
  6. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
  7. package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
  8. package/esm/CodeHighlighter/errors.js +248 -400
  9. package/esm/CodeHighlighter/parseControlledCode.js +12 -20
  10. package/esm/CodeHighlighter/types.d.ts +7 -1
  11. package/esm/CodeProvider/CodeContext.js +3 -3
  12. package/esm/CodeProvider/CodeProvider.js +31 -40
  13. package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
  14. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
  15. package/esm/cli/index.js +1 -1
  16. package/esm/cli/runValidate.js +160 -264
  17. package/esm/createDemoData/createDemoData.js +11 -12
  18. package/esm/createSitemap/createSitemap.js +2 -2
  19. package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
  20. package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
  21. package/esm/pipeline/hastUtils/hastUtils.js +16 -17
  22. package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
  23. package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
  24. package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
  25. package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
  26. package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
  27. package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
  28. package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
  29. package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
  30. package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +517 -727
  31. package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +683 -1032
  32. package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
  33. package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
  34. package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
  35. package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
  36. package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
  37. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
  38. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
  39. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
  40. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
  41. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
  42. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
  43. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
  44. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
  45. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
  46. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
  47. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
  48. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
  49. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
  50. package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
  51. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
  52. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
  53. package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
  54. package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
  55. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
  56. package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
  57. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
  58. package/esm/pipeline/loaderUtils/getLanguageFromExtension.d.ts +24 -0
  59. package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +62 -0
  60. package/esm/pipeline/loaderUtils/index.d.ts +2 -1
  61. package/esm/pipeline/loaderUtils/index.js +2 -1
  62. package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
  63. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
  64. package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
  65. package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
  66. package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
  67. package/esm/pipeline/parseSource/addLineGutters.js +33 -45
  68. package/esm/pipeline/parseSource/grammars.d.ts +12 -1
  69. package/esm/pipeline/parseSource/grammars.js +36 -4
  70. package/esm/pipeline/parseSource/index.d.ts +2 -1
  71. package/esm/pipeline/parseSource/index.js +2 -1
  72. package/esm/pipeline/parseSource/parseSource.js +23 -32
  73. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
  74. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
  75. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
  76. package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
  77. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +266 -320
  78. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
  79. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +183 -267
  80. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
  81. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
  82. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
  83. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
  84. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
  85. package/esm/useCode/Pre.d.ts +2 -0
  86. package/esm/useCode/Pre.js +58 -60
  87. package/esm/useCode/useCode.js +59 -61
  88. package/esm/useCode/useCodeUtils.js +54 -63
  89. package/esm/useCode/useCopyFunctionality.js +10 -9
  90. package/esm/useCode/useFileNavigation.js +171 -209
  91. package/esm/useCode/useSourceEditing.js +17 -14
  92. package/esm/useCode/useTransformManagement.js +23 -26
  93. package/esm/useCode/useUIState.js +12 -20
  94. package/esm/useCode/useVariantSelection.js +62 -79
  95. package/esm/useCopier/index.js +29 -56
  96. package/esm/useDemo/createCodeSandbox.js +12 -15
  97. package/esm/useDemo/createStackBlitz.js +14 -20
  98. package/esm/useDemo/exportVariant.js +200 -180
  99. package/esm/useDemo/exportVariantAsCra.js +22 -25
  100. package/esm/useDemo/useDemo.js +80 -84
  101. package/esm/useErrors/ErrorsContext.js +1 -1
  102. package/esm/useErrors/useErrors.js +3 -3
  103. package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
  104. package/esm/usePreference/PreferencesProvider.js +1 -1
  105. package/esm/usePreference/usePreference.js +9 -11
  106. package/esm/useSearch/useSearch.js +290 -387
  107. package/esm/useUrlHashState/useUrlHashState.js +11 -14
  108. package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
  109. package/esm/withDocsInfra/withDocsInfra.js +99 -101
  110. package/package.json +7 -4
@@ -1,32 +1,27 @@
1
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
- import _regenerator from "@babel/runtime/helpers/esm/regenerator";
3
- import _typeof from "@babel/runtime/helpers/esm/typeof";
4
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
6
- import _extends from "@babel/runtime/helpers/esm/extends";
7
1
  import * as React from 'react';
8
2
  import { loadCodeVariant } from "../pipeline/loadCodeVariant/loadCodeVariant.js";
9
3
  import { loadCodeFallback } from "../pipeline/loadCodeVariant/loadCodeFallback.js";
10
4
  import { CodeHighlighterClient } from "./CodeHighlighterClient.js";
11
5
  import { maybeCodeInitialData } from "../pipeline/loadCodeVariant/maybeCodeInitialData.js";
12
6
  import { hasAllVariants } from "../pipeline/loadCodeVariant/hasAllCodeVariants.js";
13
- import { getFileNameFromUrl } from "../pipeline/loaderUtils/getFileNameFromUrl.js";
7
+ import { getFileNameFromUrl, getLanguageFromExtension } from "../pipeline/loaderUtils/index.js";
14
8
  import { codeToFallbackProps } from "./codeToFallbackProps.js";
15
9
  import * as Errors from "./errors.js";
16
10
  import { jsx as _jsx } from "react/jsx-runtime";
17
- var DEBUG = false; // Set to true for debugging purposes
11
+ const DEBUG = false; // Set to true for debugging purposes
18
12
 
19
13
  function createClientProps(props) {
20
- var highlightAfter = props.highlightAfter === 'stream' ? 'init' : props.highlightAfter;
21
- var enhanceAfter = props.enhanceAfter === 'stream' ? 'init' : props.enhanceAfter;
22
- var contentProps = _extends({
14
+ const highlightAfter = props.highlightAfter === 'stream' ? 'init' : props.highlightAfter;
15
+ const enhanceAfter = props.enhanceAfter === 'stream' ? 'init' : props.enhanceAfter;
16
+ const contentProps = {
23
17
  code: props.code || props.precompute,
24
18
  components: props.components,
25
19
  name: props.name,
26
20
  slug: props.slug,
27
21
  url: props.url,
28
- variantType: props.variantType
29
- }, props.contentProps);
22
+ variantType: props.variantType,
23
+ ...props.contentProps
24
+ };
30
25
  return {
31
26
  url: props.url,
32
27
  code: props.code,
@@ -49,379 +44,306 @@ function createClientProps(props) {
49
44
  // otherwise we will get an error because functions can't be serialized
50
45
  // On the client, in order to send data to these components, we have to set context
51
46
  fallback: props.fallback,
52
- children: /*#__PURE__*/_jsx(props.Content, _extends({}, contentProps))
47
+ children: /*#__PURE__*/_jsx(props.Content, {
48
+ ...contentProps
49
+ })
53
50
  };
54
51
  }
55
- function CodeSourceLoader(_x) {
56
- return _CodeSourceLoader.apply(this, arguments);
57
- }
58
- function _CodeSourceLoader() {
59
- _CodeSourceLoader = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(props) {
60
- var loadedCode, processedGlobalsCode, hasStringUrls, globalsPromises, variantNames, variantCodes, processedCode, errors, _iterator2, _step2, item, clientProps, _t2;
61
- return _regenerator().w(function (_context2) {
62
- while (1) switch (_context2.p = _context2.n) {
63
- case 0:
64
- // Start with the loaded code from precompute, or load it if needed
65
- loadedCode = props.code || props.precompute;
66
- if (loadedCode) {
67
- _context2.n = 5;
68
- break;
69
- }
70
- if (props.loadCodeMeta) {
71
- _context2.n = 1;
72
- break;
73
- }
74
- throw new Errors.ErrorCodeHighlighterServerMissingLoadCodeMeta();
75
- case 1:
76
- if (props.url) {
77
- _context2.n = 2;
78
- break;
79
- }
80
- throw new Errors.ErrorCodeHighlighterServerMissingUrlForLoadCodeMeta();
81
- case 2:
82
- _context2.p = 2;
83
- _context2.n = 3;
84
- return props.loadCodeMeta(props.url);
85
- case 3:
86
- loadedCode = _context2.v;
87
- _context2.n = 5;
88
- break;
89
- case 4:
90
- _context2.p = 4;
91
- _t2 = _context2.v;
92
- throw new Errors.ErrorCodeHighlighterServerLoadCodeFailure(props.url, _t2);
93
- case 5:
94
- // TODO: if props.variant is provided, we should only load that variant
95
- // Process globalsCode: use already processed version if available, otherwise convert string URLs to Code objects
96
- processedGlobalsCode = props.processedGlobalsCode;
97
- if (!(!processedGlobalsCode && props.globalsCode && props.globalsCode.length > 0)) {
98
- _context2.n = 8;
99
- break;
100
- }
101
- hasStringUrls = props.globalsCode.some(function (item) {
102
- return typeof item === 'string';
103
- });
104
- if (!(hasStringUrls && !props.loadCodeMeta)) {
105
- _context2.n = 6;
106
- break;
107
- }
108
- throw new Errors.ErrorCodeHighlighterServerMissingLoadCodeMetaForGlobals();
109
- case 6:
110
- // Load all string URLs in parallel, keep Code objects as-is
111
- globalsPromises = props.globalsCode.map(/*#__PURE__*/function () {
112
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(globalItem) {
113
- var _t;
114
- return _regenerator().w(function (_context) {
115
- while (1) switch (_context.p = _context.n) {
116
- case 0:
117
- if (!(typeof globalItem === 'string')) {
118
- _context.n = 4;
119
- break;
120
- }
121
- _context.p = 1;
122
- _context.n = 2;
123
- return props.loadCodeMeta(globalItem);
124
- case 2:
125
- return _context.a(2, _context.v);
126
- case 3:
127
- _context.p = 3;
128
- _t = _context.v;
129
- throw new Errors.ErrorCodeHighlighterServerLoadGlobalsFailure(globalItem, _t);
130
- case 4:
131
- return _context.a(2, globalItem);
132
- case 5:
133
- return _context.a(2);
134
- }
135
- }, _callee, null, [[1, 3]]);
136
- }));
137
- return function (_x4) {
138
- return _ref.apply(this, arguments);
139
- };
140
- }());
141
- _context2.n = 7;
142
- return Promise.all(globalsPromises);
143
- case 7:
144
- processedGlobalsCode = _context2.v;
145
- case 8:
146
- variantNames = Object.keys(props.components || loadedCode || {});
147
- _context2.n = 9;
148
- return Promise.all(variantNames.map(function (variantName) {
149
- var variantCode = loadedCode[variantName];
150
- var variantUrl = _typeof(variantCode) === 'object' && variantCode != null && variantCode.url ? variantCode.url : props.url;
52
+ async function CodeSourceLoader(props) {
53
+ // Start with the loaded code from precompute, or load it if needed
54
+ let loadedCode = props.code || props.precompute;
55
+ if (!loadedCode) {
56
+ if (!props.loadCodeMeta) {
57
+ throw new Errors.ErrorCodeHighlighterServerMissingLoadCodeMeta();
58
+ }
59
+ if (!props.url) {
60
+ throw new Errors.ErrorCodeHighlighterServerMissingUrlForLoadCodeMeta();
61
+ }
62
+ try {
63
+ loadedCode = await props.loadCodeMeta(props.url);
64
+ } catch (error) {
65
+ throw new Errors.ErrorCodeHighlighterServerLoadCodeFailure(props.url, error);
66
+ }
67
+ }
68
+
69
+ // TODO: if props.variant is provided, we should only load that variant
70
+
71
+ // Process globalsCode: use already processed version if available, otherwise convert string URLs to Code objects
72
+ let processedGlobalsCode = props.processedGlobalsCode;
73
+ if (!processedGlobalsCode && props.globalsCode && props.globalsCode.length > 0) {
74
+ const hasStringUrls = props.globalsCode.some(item => typeof item === 'string');
75
+ if (hasStringUrls && !props.loadCodeMeta) {
76
+ throw new Errors.ErrorCodeHighlighterServerMissingLoadCodeMetaForGlobals();
77
+ }
151
78
 
152
- // Convert processedGlobalsCode to VariantCode | string for this specific variant
153
- var resolvedGlobalsCode;
154
- if (processedGlobalsCode && processedGlobalsCode.length > 0) {
155
- resolvedGlobalsCode = [];
156
- var _iterator = _createForOfIteratorHelper(processedGlobalsCode),
157
- _step;
158
- try {
159
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
160
- var codeObj = _step.value;
161
- // Only include if this variant exists in the globalsCode
162
- var targetVariant = codeObj[variantName];
163
- if (targetVariant) {
164
- resolvedGlobalsCode.push(targetVariant);
165
- }
166
- }
167
- } catch (err) {
168
- _iterator.e(err);
169
- } finally {
170
- _iterator.f();
171
- }
172
- }
173
- var output = 'hastGzip';
174
- if (props.deferParsing === 'json') {
175
- output = 'hastJson';
176
- } else if (props.deferParsing === 'none') {
177
- output = 'hast';
178
- }
179
- return loadCodeVariant(variantUrl, variantName, variantCode, {
180
- sourceParser: props.sourceParser,
181
- loadSource: props.loadSource,
182
- loadVariantMeta: props.loadVariantMeta,
183
- sourceTransformers: props.sourceTransformers,
184
- globalsCode: resolvedGlobalsCode,
185
- output: output
186
- }).then(function (variant) {
187
- return {
188
- name: variantName,
189
- variant: variant
190
- };
191
- })["catch"](function (error) {
192
- return {
193
- error: error
194
- };
195
- });
196
- }));
197
- case 9:
198
- variantCodes = _context2.v;
199
- processedCode = {};
200
- errors = [];
201
- _iterator2 = _createForOfIteratorHelper(variantCodes);
202
- try {
203
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
204
- item = _step2.value;
205
- if ('error' in item) {
206
- console.error(new Errors.ErrorCodeHighlighterServerLoadVariantFailure(props.url, item.error));
207
- errors.push(item.error);
208
- } else {
209
- processedCode[item.name] = item.variant.code;
210
- }
211
- }
212
- } catch (err) {
213
- _iterator2.e(err);
214
- } finally {
215
- _iterator2.f();
216
- }
217
- if (!(errors.length > 0)) {
218
- _context2.n = 10;
219
- break;
220
- }
221
- throw new Errors.ErrorCodeHighlighterServerLoadVariantsFailure(props.url, errors);
222
- case 10:
223
- clientProps = createClientProps(_extends(_extends({}, props), {}, {
224
- code: processedCode,
225
- processedGlobalsCode: processedGlobalsCode
226
- }));
227
- return _context2.a(2, /*#__PURE__*/_jsx(CodeHighlighterClient, _extends({}, clientProps)));
79
+ // Load all string URLs in parallel, keep Code objects as-is
80
+ const globalsPromises = props.globalsCode.map(async globalItem => {
81
+ if (typeof globalItem === 'string') {
82
+ // String URL - load Code object via loadCodeMeta
83
+ try {
84
+ return await props.loadCodeMeta(globalItem);
85
+ } catch (error) {
86
+ throw new Errors.ErrorCodeHighlighterServerLoadGlobalsFailure(globalItem, error);
87
+ }
88
+ } else {
89
+ // Code object - return as-is
90
+ return globalItem;
228
91
  }
229
- }, _callee2, null, [[2, 4]]);
92
+ });
93
+ processedGlobalsCode = await Promise.all(globalsPromises);
94
+ }
95
+ const variantNames = Object.keys(props.components || loadedCode || {});
96
+ const variantCodes = await Promise.all(variantNames.map(variantName => {
97
+ const variantCode = loadedCode[variantName];
98
+ const variantUrl = typeof variantCode === 'object' && variantCode?.url ? variantCode.url : props.url;
99
+
100
+ // Convert processedGlobalsCode to VariantCode | string for this specific variant
101
+ let resolvedGlobalsCode;
102
+ if (processedGlobalsCode && processedGlobalsCode.length > 0) {
103
+ resolvedGlobalsCode = [];
104
+ for (const codeObj of processedGlobalsCode) {
105
+ // Only include if this variant exists in the globalsCode
106
+ const targetVariant = codeObj[variantName];
107
+ if (targetVariant) {
108
+ resolvedGlobalsCode.push(targetVariant);
109
+ }
110
+ }
111
+ }
112
+ let output = 'hastGzip';
113
+ if (props.deferParsing === 'json') {
114
+ output = 'hastJson';
115
+ } else if (props.deferParsing === 'none') {
116
+ output = 'hast';
117
+ }
118
+ return loadCodeVariant(variantUrl, variantName, variantCode, {
119
+ sourceParser: props.sourceParser,
120
+ loadSource: props.loadSource,
121
+ loadVariantMeta: props.loadVariantMeta,
122
+ sourceTransformers: props.sourceTransformers,
123
+ globalsCode: resolvedGlobalsCode,
124
+ output
125
+ }).then(variant => ({
126
+ name: variantName,
127
+ variant
128
+ })).catch(error => ({
129
+ error
130
+ }));
230
131
  }));
231
- return _CodeSourceLoader.apply(this, arguments);
132
+ const processedCode = {};
133
+ const errors = [];
134
+ for (const item of variantCodes) {
135
+ if ('error' in item) {
136
+ console.error(new Errors.ErrorCodeHighlighterServerLoadVariantFailure(props.url, item.error));
137
+ errors.push(item.error);
138
+ } else {
139
+ processedCode[item.name] = item.variant.code;
140
+ }
141
+ }
142
+ if (errors.length > 0) {
143
+ throw new Errors.ErrorCodeHighlighterServerLoadVariantsFailure(props.url, errors);
144
+ }
145
+ const clientProps = createClientProps({
146
+ ...props,
147
+ code: processedCode,
148
+ processedGlobalsCode
149
+ });
150
+ return /*#__PURE__*/_jsx(CodeHighlighterClient, {
151
+ ...clientProps
152
+ });
232
153
  }
233
154
  function renderCodeHighlighter(props) {
234
- var code = props.code || props.precompute;
235
- var variants = props.variants || Object.keys(props.components || code || {});
236
- var allCodeVariantsLoaded = code && hasAllVariants(variants, code, true);
155
+ const code = props.code || props.precompute;
156
+ const variants = props.variants || Object.keys(props.components || code || {});
157
+ const allCodeVariantsLoaded = code && hasAllVariants(variants, code, true);
237
158
 
238
159
  // Check if any loader functions are available before trying async loading
239
- var hasAnyLoaderFunction = !!(props.loadCodeMeta || props.loadVariantMeta || props.loadSource || props.sourceParser || props.sourceTransformers);
160
+ const hasAnyLoaderFunction = !!(props.loadCodeMeta || props.loadVariantMeta || props.loadSource || props.sourceParser || props.sourceTransformers);
240
161
  if (!allCodeVariantsLoaded && hasAnyLoaderFunction && !props.forceClient) {
241
- return /*#__PURE__*/_jsx(CodeSourceLoader, _extends({}, props));
162
+ return /*#__PURE__*/_jsx(CodeSourceLoader, {
163
+ ...props
164
+ });
242
165
  }
243
- var clientProps = createClientProps(props);
244
- return /*#__PURE__*/_jsx(CodeHighlighterClient, _extends({}, clientProps));
166
+ const clientProps = createClientProps(props);
167
+ return /*#__PURE__*/_jsx(CodeHighlighterClient, {
168
+ ...clientProps
169
+ });
245
170
  }
246
171
 
247
172
  /**
248
173
  * Ensures that the suspense boundary is always rendered, even if none of the children have async operations.
249
174
  */
250
- function CodeHighlighterSuspense(_x2) {
251
- return _CodeHighlighterSuspense.apply(this, arguments);
252
- }
253
- function _CodeHighlighterSuspense() {
254
- _CodeHighlighterSuspense = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(props) {
255
- return _regenerator().w(function (_context3) {
256
- while (1) switch (_context3.n) {
257
- case 0:
258
- _context3.n = 1;
259
- return new Promise(function (resolve) {
260
- setTimeout(resolve, 0);
261
- });
262
- case 1:
263
- return _context3.a(2, props.children);
264
- }
265
- }, _callee3);
266
- }));
267
- return _CodeHighlighterSuspense.apply(this, arguments);
175
+ async function CodeHighlighterSuspense(props) {
176
+ await new Promise(resolve => {
177
+ setTimeout(resolve, 0);
178
+ });
179
+ return props.children;
268
180
  }
269
181
  function renderWithInitialSource(props) {
270
- var _props$components;
271
- var ContentLoading = props.ContentLoading;
272
- var url = props.url,
273
- slug = props.slug,
274
- name = props.name,
275
- initialVariant = props.initialVariant,
276
- code = props.code,
277
- initialFilename = props.initialFilename,
278
- fallbackUsesExtraFiles = props.fallbackUsesExtraFiles,
279
- fallbackUsesAllVariants = props.fallbackUsesAllVariants;
280
- var fallbackProps = codeToFallbackProps(initialVariant, code, initialFilename, fallbackUsesExtraFiles, fallbackUsesAllVariants);
182
+ const ContentLoading = props.ContentLoading;
183
+ const {
184
+ url,
185
+ slug,
186
+ name,
187
+ initialVariant,
188
+ code,
189
+ initialFilename,
190
+ fallbackUsesExtraFiles,
191
+ fallbackUsesAllVariants
192
+ } = props;
193
+ const fallbackProps = codeToFallbackProps(initialVariant, code, initialFilename, fallbackUsesExtraFiles, fallbackUsesAllVariants);
281
194
 
282
195
  // Get the component for the selected variant
283
- var component = (_props$components = props.components) == null ? void 0 : _props$components[initialVariant];
196
+ const component = props.components?.[initialVariant];
284
197
 
285
198
  // Only include components (plural) if we're also including extraVariants
286
- var components = fallbackProps.extraVariants ? props.components : undefined;
287
- var contentProps = _extends(_extends({
288
- name: name,
289
- slug: slug,
290
- url: url,
291
- initialFilename: initialFilename,
292
- component: component,
293
- components: components
294
- }, fallbackProps), props.contentProps);
295
- var fallback = /*#__PURE__*/_jsx(ContentLoading, _extends({}, contentProps));
199
+ const components = fallbackProps.extraVariants ? props.components : undefined;
200
+ const contentProps = {
201
+ name,
202
+ slug,
203
+ url,
204
+ initialFilename,
205
+ component,
206
+ components,
207
+ ...fallbackProps,
208
+ ...props.contentProps
209
+ };
210
+ const fallback = /*#__PURE__*/_jsx(ContentLoading, {
211
+ ...contentProps
212
+ });
296
213
  if (props.highlightAfter === 'stream' && !props.forceClient) {
297
214
  return /*#__PURE__*/_jsx(React.Suspense, {
298
215
  fallback: fallback,
299
216
  children: /*#__PURE__*/_jsx(CodeHighlighterSuspense, {
300
- children: renderCodeHighlighter(_extends(_extends({}, props), {}, {
301
- fallback: fallback,
217
+ children: renderCodeHighlighter({
218
+ ...props,
219
+ fallback,
302
220
  skipFallback: props.enhanceAfter === 'stream'
303
- }))
221
+ })
304
222
  })
305
223
  });
306
224
  }
307
- return renderCodeHighlighter(_extends(_extends({}, props), {}, {
308
- fallback: fallback
309
- }));
225
+ return renderCodeHighlighter({
226
+ ...props,
227
+ fallback
228
+ });
310
229
  }
311
- function CodeInitialSourceLoader(_x3) {
312
- return _CodeInitialSourceLoader.apply(this, arguments);
313
- }
314
- function _CodeInitialSourceLoader() {
315
- _CodeInitialSourceLoader = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(props) {
316
- var url, initialVariant, highlightAfter, fallbackUsesExtraFiles, fallbackUsesAllVariants, sourceParser, loadSource, loadVariantMeta, loadCodeMeta, fileName, variants, globalsCode, ContentLoading, output, _yield$loadCodeFallba, code, initialFilename, initialSource, initialExtraFiles, processedGlobalsCode;
317
- return _regenerator().w(function (_context4) {
318
- while (1) switch (_context4.n) {
319
- case 0:
320
- url = props.url, initialVariant = props.initialVariant, highlightAfter = props.highlightAfter, fallbackUsesExtraFiles = props.fallbackUsesExtraFiles, fallbackUsesAllVariants = props.fallbackUsesAllVariants, sourceParser = props.sourceParser, loadSource = props.loadSource, loadVariantMeta = props.loadVariantMeta, loadCodeMeta = props.loadCodeMeta, fileName = props.fileName, variants = props.variants, globalsCode = props.globalsCode, ContentLoading = props.ContentLoading;
321
- if (url) {
322
- _context4.n = 1;
323
- break;
324
- }
325
- throw new Errors.ErrorCodeHighlighterServerMissingUrl();
326
- case 1:
327
- output = 'hastGzip';
328
- if (props.deferParsing === 'json') {
329
- output = 'hastJson';
330
- } else if (props.deferParsing === 'none') {
331
- output = 'hast';
332
- }
333
- _context4.n = 2;
334
- return loadCodeFallback(url, initialVariant, props.code, {
335
- shouldHighlight: highlightAfter === 'init',
336
- fallbackUsesExtraFiles: fallbackUsesExtraFiles,
337
- fallbackUsesAllVariants: fallbackUsesAllVariants,
338
- sourceParser: sourceParser,
339
- loadSource: loadSource,
340
- loadVariantMeta: loadVariantMeta,
341
- loadCodeMeta: loadCodeMeta,
342
- initialFilename: fileName,
343
- variants: variants,
344
- globalsCode: globalsCode,
345
- output: output
346
- });
347
- case 2:
348
- _yield$loadCodeFallba = _context4.v;
349
- code = _yield$loadCodeFallba.code;
350
- initialFilename = _yield$loadCodeFallba.initialFilename;
351
- initialSource = _yield$loadCodeFallba.initialSource;
352
- initialExtraFiles = _yield$loadCodeFallba.initialExtraFiles;
353
- processedGlobalsCode = _yield$loadCodeFallba.processedGlobalsCode;
354
- return _context4.a(2, renderWithInitialSource(_extends(_extends({}, props), {}, {
355
- ContentLoading: ContentLoading,
356
- code: code,
357
- initialFilename: initialFilename,
358
- initialSource: initialSource,
359
- initialExtraFiles: initialExtraFiles,
360
- processedGlobalsCode: processedGlobalsCode
361
- })));
362
- }
363
- }, _callee4);
364
- }));
365
- return _CodeInitialSourceLoader.apply(this, arguments);
230
+ async function CodeInitialSourceLoader(props) {
231
+ const {
232
+ url,
233
+ initialVariant,
234
+ highlightAfter,
235
+ fallbackUsesExtraFiles,
236
+ fallbackUsesAllVariants,
237
+ sourceParser,
238
+ loadSource,
239
+ loadVariantMeta,
240
+ loadCodeMeta,
241
+ fileName,
242
+ variants,
243
+ globalsCode,
244
+ ContentLoading
245
+ } = props;
246
+ if (!url) {
247
+ throw new Errors.ErrorCodeHighlighterServerMissingUrl();
248
+ }
249
+ let output = 'hastGzip';
250
+ if (props.deferParsing === 'json') {
251
+ output = 'hastJson';
252
+ } else if (props.deferParsing === 'none') {
253
+ output = 'hast';
254
+ }
255
+ const {
256
+ code,
257
+ initialFilename,
258
+ initialSource,
259
+ initialExtraFiles,
260
+ processedGlobalsCode
261
+ } = await loadCodeFallback(url, initialVariant, props.code, {
262
+ shouldHighlight: highlightAfter === 'init',
263
+ fallbackUsesExtraFiles,
264
+ fallbackUsesAllVariants,
265
+ sourceParser,
266
+ loadSource,
267
+ loadVariantMeta,
268
+ loadCodeMeta,
269
+ initialFilename: fileName,
270
+ variants,
271
+ globalsCode,
272
+ output
273
+ });
274
+ return renderWithInitialSource({
275
+ ...props,
276
+ ContentLoading,
277
+ code,
278
+ initialFilename,
279
+ initialSource,
280
+ initialExtraFiles,
281
+ processedGlobalsCode
282
+ });
366
283
  }
367
284
  export function CodeHighlighter(props) {
368
- var _code, _props$precompute, _props$components2;
369
285
  // Validate mutually exclusive props
370
286
  if (props.children && (props.code || props.precompute)) {
371
287
  throw new Errors.ErrorCodeHighlighterServerInvalidProps();
372
288
  }
373
289
 
374
290
  // Handle children as string -> Default variant
375
- var code = props.code;
291
+ let code = props.code;
376
292
  if (props.children && typeof props.children === 'string') {
377
- var fileName = props.fileName || (props.url ? getFileNameFromUrl(props.url).fileName : undefined);
293
+ const fileName = props.fileName || (props.url ? getFileNameFromUrl(props.url).fileName : undefined);
294
+ // Derive language: use explicit prop, or derive from fileName extension
295
+ let language = props.language;
296
+ if (!language && fileName) {
297
+ const extension = fileName.slice(fileName.lastIndexOf('.'));
298
+ language = getLanguageFromExtension(extension);
299
+ }
378
300
  code = {
379
301
  Default: {
380
- fileName: fileName,
302
+ fileName,
303
+ language,
381
304
  source: props.children,
382
305
  url: props.url
383
306
  }
384
307
  };
385
308
  }
386
- var variants = props.variants || Object.keys(props.components || code || props.precompute || {});
309
+ const variants = props.variants || Object.keys(props.components || code || props.precompute || {});
387
310
  if (variants.length === 0) {
388
311
  throw new Errors.ErrorCodeHighlighterServerMissingData();
389
312
  }
390
313
 
391
314
  // Validate fileName is provided when extraFiles are present
392
315
  if (code) {
393
- for (var _i = 0, _Object$entries = Object.entries(code); _i < _Object$entries.length; _i++) {
394
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
395
- variantName = _Object$entries$_i[0],
396
- variantCode = _Object$entries$_i[1];
397
- if (_typeof(variantCode) === 'object' && variantCode != null && variantCode.extraFiles && Object.keys(variantCode.extraFiles).length > 0 && !variantCode.fileName && !variantCode.url) {
316
+ for (const [variantName, variantCode] of Object.entries(code)) {
317
+ if (typeof variantCode === 'object' && variantCode?.extraFiles && Object.keys(variantCode.extraFiles).length > 0 && !variantCode.fileName && !variantCode.url) {
398
318
  throw new Errors.ErrorCodeHighlighterServerMissingFileName(variantName);
399
319
  }
400
320
  }
401
321
  }
402
- var ContentLoading = props.ContentLoading;
322
+ const ContentLoading = props.ContentLoading;
403
323
  if (!ContentLoading) {
404
324
  if (props.highlightAfter === 'stream') {
405
325
  // if the user explicitly sets highlightAfter to 'stream', we need a ContentLoading component
406
326
  throw new Errors.ErrorCodeHighlighterServerMissingContentLoading();
407
327
  }
408
- return renderCodeHighlighter(_extends(_extends({}, props), {}, {
409
- code: code
410
- }));
328
+ return renderCodeHighlighter({
329
+ ...props,
330
+ code
331
+ });
411
332
  }
412
- var initialKey = props.initialVariant || props.variant || props.defaultVariant || variants[0];
413
- var initial = ((_code = code) == null ? void 0 : _code[initialKey]) || ((_props$precompute = props.precompute) == null ? void 0 : _props$precompute[initialKey]);
414
- if (!initial && !((_props$components2 = props.components) != null && _props$components2[initialKey])) {
333
+ const initialKey = props.initialVariant || props.variant || props.defaultVariant || variants[0];
334
+ const initial = code?.[initialKey] || props.precompute?.[initialKey];
335
+ if (!initial && !props.components?.[initialKey]) {
415
336
  throw new Errors.ErrorCodeHighlighterServerMissingVariant(initialKey);
416
337
  }
417
338
 
418
339
  // TODO: use initial.filesOrder to determing which source to use
419
340
 
420
- var _maybeCodeInitialData = maybeCodeInitialData(variants, initialKey, code || props.precompute, undefined,
421
- // TODO: use initial.filesOrder if provided?
422
- props.highlightAfter === 'init', props.fallbackUsesExtraFiles, props.fallbackUsesAllVariants),
423
- initialData = _maybeCodeInitialData.initialData,
424
- reason = _maybeCodeInitialData.reason;
341
+ const {
342
+ initialData,
343
+ reason
344
+ } = maybeCodeInitialData(variants, initialKey, code || props.precompute, undefined,
345
+ // TODO: use initial.filesOrder if provided?
346
+ props.highlightAfter === 'init', props.fallbackUsesExtraFiles, props.fallbackUsesAllVariants);
425
347
  if (!initialData) {
426
348
  if (DEBUG) {
427
349
  // eslint-disable-next-line no-console
@@ -429,28 +351,31 @@ export function CodeHighlighter(props) {
429
351
  }
430
352
 
431
353
  // Check if any loader functions are available
432
- var hasAnyLoaderFunction = !!(props.loadCodeMeta || props.loadVariantMeta || props.loadSource || props.sourceParser || props.sourceTransformers);
354
+ const hasAnyLoaderFunction = !!(props.loadCodeMeta || props.loadVariantMeta || props.loadSource || props.sourceParser || props.sourceTransformers);
433
355
 
434
356
  // If no loader functions are available, skip async loading and go directly to client
435
357
  if (!hasAnyLoaderFunction || props.forceClient) {
436
358
  if (props.highlightAfter === 'init') {
437
359
  throw new Errors.ErrorCodeHighlighterServerInvalidClientMode();
438
360
  }
439
- return renderCodeHighlighter(_extends(_extends({}, props), {}, {
440
- code: code
441
- }));
361
+ return renderCodeHighlighter({
362
+ ...props,
363
+ code
364
+ });
442
365
  }
443
- return /*#__PURE__*/_jsx(CodeInitialSourceLoader, _extends(_extends({}, props), {}, {
366
+ return /*#__PURE__*/_jsx(CodeInitialSourceLoader, {
367
+ ...props,
444
368
  ContentLoading: ContentLoading,
445
369
  initialVariant: initialKey
446
- }));
370
+ });
447
371
  }
448
- return renderWithInitialSource(_extends(_extends({}, props), {}, {
372
+ return renderWithInitialSource({
373
+ ...props,
449
374
  code: initialData.code,
450
- ContentLoading: ContentLoading,
375
+ ContentLoading,
451
376
  initialVariant: initialKey,
452
377
  initialFilename: initialData.initialFilename,
453
378
  initialSource: initialData.initialSource,
454
379
  initialExtraFiles: initialData.initialExtraFiles
455
- }));
380
+ });
456
381
  }