@mui/internal-docs-infra 0.2.0-alpha.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/esm/CodeHighlighter/CodeHighlighter.js +54 -39
  2. package/esm/CodeHighlighter/CodeHighlighterClient.js +77 -33
  3. package/esm/CodeHighlighter/errors.js +1 -1
  4. package/esm/CodeHighlighter/loadFallbackCode.js +6 -2
  5. package/esm/CodeHighlighter/loadVariant.js +64 -22
  6. package/esm/CodeHighlighter/maybeInitialData.d.ts +2 -2
  7. package/esm/CodeHighlighter/maybeInitialData.js +2 -2
  8. package/esm/CodeHighlighter/transformSource.js +57 -17
  9. package/esm/CodeHighlighter/types.d.ts +20 -3
  10. package/esm/abstractCreateDemo/abstractCreateDemo.d.ts +4 -2
  11. package/esm/abstractCreateDemo/abstractCreateDemo.js +2 -1
  12. package/esm/pipeline/hastUtils/hastUtils.d.ts +6 -0
  13. package/esm/pipeline/hastUtils/hastUtils.js +20 -0
  14. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +3 -1
  15. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +2 -1
  16. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +6 -4
  17. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +443 -258
  18. package/esm/pipeline/loadServerSource/loadServerSource.js +59 -19
  19. package/esm/pipeline/loaderUtils/index.d.ts +1 -1
  20. package/esm/pipeline/loaderUtils/index.js +1 -1
  21. package/esm/pipeline/loaderUtils/parseImportsAndComments.d.ts +91 -0
  22. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +1329 -0
  23. package/esm/pipeline/loaderUtils/processRelativeImports.d.ts +8 -3
  24. package/esm/pipeline/loaderUtils/processRelativeImports.js +237 -118
  25. package/esm/pipeline/loaderUtils/resolveModulePath.d.ts +7 -3
  26. package/esm/pipeline/loaderUtils/resolveModulePath.js +3 -3
  27. package/esm/pipeline/loaderUtils/resolveModulePathWithFs.d.ts +4 -0
  28. package/esm/pipeline/loaderUtils/rewriteImports.d.ts +12 -5
  29. package/esm/pipeline/loaderUtils/rewriteImports.js +56 -26
  30. package/esm/pipeline/transformHtmlCodePrecomputed/index.d.ts +2 -0
  31. package/esm/pipeline/transformHtmlCodePrecomputed/index.js +4 -0
  32. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.d.ts +13 -0
  33. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +415 -0
  34. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +304 -47
  35. package/esm/useCode/Pre.js +5 -0
  36. package/esm/useCode/useFileNavigation.js +4 -0
  37. package/esm/withDocsInfra/withDocsInfra.d.ts +12 -1
  38. package/esm/withDocsInfra/withDocsInfra.js +34 -6
  39. package/package.json +6 -4
  40. package/esm/pipeline/loaderUtils/parseImports.d.ts +0 -19
  41. package/esm/pipeline/loaderUtils/parseImports.js +0 -306
  42. package/esm/pipeline/transformHtmlCode/index.d.ts +0 -2
  43. package/esm/pipeline/transformHtmlCode/index.js +0 -4
  44. package/esm/pipeline/transformHtmlCode/transformHtmlCode.d.ts +0 -13
  45. package/esm/pipeline/transformHtmlCode/transformHtmlCode.js +0 -300
@@ -14,11 +14,11 @@ import { getFileNameFromUrl } from "../pipeline/loaderUtils/getFileNameFromUrl.j
14
14
  import { codeToFallbackProps } from "./codeToFallbackProps.js";
15
15
  import * as Errors from "./errors.js";
16
16
  import { jsx as _jsx } from "react/jsx-runtime";
17
- var DEFAULT_HIGHLIGHT_AT = 'stream';
18
17
  var DEBUG = false; // Set to true for debugging purposes
19
18
 
20
19
  function createClientProps(props) {
21
- var highlightAt = props.highlightAt === 'stream' ? 'init' : props.highlightAt;
20
+ var highlightAfter = props.highlightAfter === 'stream' ? 'init' : props.highlightAfter;
21
+ var enhanceAfter = props.enhanceAfter === 'stream' ? 'init' : props.enhanceAfter;
22
22
  var contentProps = _extends({
23
23
  code: props.code || props.precompute,
24
24
  components: props.components,
@@ -37,7 +37,8 @@ function createClientProps(props) {
37
37
  fileName: props.fileName,
38
38
  initialVariant: props.initialVariant,
39
39
  defaultVariant: props.defaultVariant,
40
- highlightAt: highlightAt || 'init',
40
+ highlightAfter: highlightAfter || 'idle',
41
+ enhanceAfter: enhanceAfter || 'idle',
41
42
  skipFallback: props.skipFallback,
42
43
  controlled: props.controlled,
43
44
  name: props.name,
@@ -169,12 +170,19 @@ function _CodeSourceLoader() {
169
170
  _iterator.f();
170
171
  }
171
172
  }
173
+ var output = 'hastGzip';
174
+ if (props.deferParsing === 'json') {
175
+ output = 'hastJson';
176
+ } else if (props.deferParsing === 'none') {
177
+ output = 'hast';
178
+ }
172
179
  return loadVariant(variantUrl, variantName, variantCode, {
173
180
  sourceParser: props.sourceParser,
174
181
  loadSource: props.loadSource,
175
182
  loadVariantMeta: props.loadVariantMeta,
176
183
  sourceTransformers: props.sourceTransformers,
177
- globalsCode: resolvedGlobalsCode
184
+ globalsCode: resolvedGlobalsCode,
185
+ output: output
178
186
  }).then(function (variant) {
179
187
  return {
180
188
  name: variantName,
@@ -247,6 +255,11 @@ function _CodeHighlighterSuspense() {
247
255
  return _regenerator().w(function (_context3) {
248
256
  while (1) switch (_context3.n) {
249
257
  case 0:
258
+ _context3.n = 1;
259
+ return new Promise(function (resolve) {
260
+ setTimeout(resolve, 0);
261
+ });
262
+ case 1:
250
263
  return _context3.a(2, props.children);
251
264
  }
252
265
  }, _callee3);
@@ -280,40 +293,46 @@ function renderWithInitialSource(props) {
280
293
  components: components
281
294
  }, fallbackProps), props.contentProps);
282
295
  var fallback = /*#__PURE__*/_jsx(ContentLoading, _extends({}, contentProps));
283
- if (props.forceClient) {
284
- return renderCodeHighlighter(_extends(_extends({}, props), {}, {
285
- fallback: fallback
286
- }));
296
+ if (props.highlightAfter === 'stream' && !props.forceClient) {
297
+ return /*#__PURE__*/_jsx(React.Suspense, {
298
+ fallback: fallback,
299
+ children: /*#__PURE__*/_jsx(CodeHighlighterSuspense, {
300
+ children: renderCodeHighlighter(_extends(_extends({}, props), {}, {
301
+ fallback: fallback,
302
+ skipFallback: props.enhanceAfter === 'stream'
303
+ }))
304
+ })
305
+ });
287
306
  }
288
- return /*#__PURE__*/_jsx(React.Suspense, {
289
- fallback: fallback,
290
- children: /*#__PURE__*/_jsx(CodeHighlighterSuspense, {
291
- children: renderCodeHighlighter(_extends(_extends({}, props), {}, {
292
- fallback: fallback,
293
- skipFallback: true
294
- }))
295
- })
296
- });
307
+ return renderCodeHighlighter(_extends(_extends({}, props), {}, {
308
+ fallback: fallback
309
+ }));
297
310
  }
298
311
  function CodeInitialSourceLoader(_x3) {
299
312
  return _CodeInitialSourceLoader.apply(this, arguments);
300
313
  }
301
314
  function _CodeInitialSourceLoader() {
302
315
  _CodeInitialSourceLoader = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(props) {
303
- var url, initialVariant, highlightAt, fallbackUsesExtraFiles, fallbackUsesAllVariants, sourceParser, loadSource, loadVariantMeta, loadCodeMeta, fileName, variants, globalsCode, ContentLoading, _yield$loadFallbackCo, code, initialFilename, initialSource, initialExtraFiles, processedGlobalsCode;
316
+ var url, initialVariant, highlightAfter, fallbackUsesExtraFiles, fallbackUsesAllVariants, sourceParser, loadSource, loadVariantMeta, loadCodeMeta, fileName, variants, globalsCode, ContentLoading, output, _yield$loadFallbackCo, code, initialFilename, initialSource, initialExtraFiles, processedGlobalsCode;
304
317
  return _regenerator().w(function (_context4) {
305
318
  while (1) switch (_context4.n) {
306
319
  case 0:
307
- url = props.url, initialVariant = props.initialVariant, highlightAt = props.highlightAt, 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;
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;
308
321
  if (url) {
309
322
  _context4.n = 1;
310
323
  break;
311
324
  }
312
325
  throw new Errors.ErrorCodeHighlighterServerMissingUrl();
313
326
  case 1:
327
+ output = 'hastGzip';
328
+ if (props.deferParsing === 'json') {
329
+ output = 'hastJson';
330
+ } else if (props.deferParsing === 'none') {
331
+ output = 'hast';
332
+ }
314
333
  _context4.n = 2;
315
334
  return loadFallbackCode(url, initialVariant, props.code, {
316
- shouldHighlight: highlightAt === 'init',
335
+ shouldHighlight: highlightAfter === 'init',
317
336
  fallbackUsesExtraFiles: fallbackUsesExtraFiles,
318
337
  fallbackUsesAllVariants: fallbackUsesAllVariants,
319
338
  sourceParser: sourceParser,
@@ -322,7 +341,8 @@ function _CodeInitialSourceLoader() {
322
341
  loadCodeMeta: loadCodeMeta,
323
342
  initialFilename: fileName,
324
343
  variants: variants,
325
- globalsCode: globalsCode
344
+ globalsCode: globalsCode,
345
+ output: output
326
346
  });
327
347
  case 2:
328
348
  _yield$loadFallbackCo = _context4.v;
@@ -345,7 +365,7 @@ function _CodeInitialSourceLoader() {
345
365
  return _CodeInitialSourceLoader.apply(this, arguments);
346
366
  }
347
367
  export function CodeHighlighter(props) {
348
- var _code, _props$components2;
368
+ var _code, _props$precompute, _props$components2;
349
369
  // Validate mutually exclusive props
350
370
  if (props.children && (props.code || props.precompute)) {
351
371
  throw new Errors.ErrorCodeHighlighterServerInvalidProps();
@@ -381,35 +401,25 @@ export function CodeHighlighter(props) {
381
401
  }
382
402
  var ContentLoading = props.ContentLoading;
383
403
  if (!ContentLoading) {
384
- if (props.highlightAt === 'stream') {
385
- // if the user explicitly sets highlightAt to 'stream', we need a ContentLoading component
404
+ if (props.highlightAfter === 'stream') {
405
+ // if the user explicitly sets highlightAfter to 'stream', we need a ContentLoading component
386
406
  throw new Errors.ErrorCodeHighlighterServerMissingContentLoading();
387
407
  }
388
408
  return renderCodeHighlighter(_extends(_extends({}, props), {}, {
389
409
  code: code
390
410
  }));
391
411
  }
392
-
393
- // Check if any loader functions are available
394
- var hasAnyLoaderFunction = !!(props.loadCodeMeta || props.loadVariantMeta || props.loadSource || props.sourceParser || props.sourceTransformers);
395
-
396
- // If no loader functions are available, skip async loading and go directly to client
397
- if (!hasAnyLoaderFunction) {
398
- return renderCodeHighlighter(_extends(_extends({}, props), {}, {
399
- code: code
400
- }));
401
- }
402
412
  var initialKey = props.initialVariant || props.variant || props.defaultVariant || variants[0];
403
- var initial = (_code = code) == null ? void 0 : _code[initialKey];
413
+ var initial = ((_code = code) == null ? void 0 : _code[initialKey]) || ((_props$precompute = props.precompute) == null ? void 0 : _props$precompute[initialKey]);
404
414
  if (!initial && !((_props$components2 = props.components) != null && _props$components2[initialKey])) {
405
415
  throw new Errors.ErrorCodeHighlighterServerMissingVariant(initialKey);
406
416
  }
407
417
 
408
418
  // TODO: use initial.filesOrder to determing which source to use
409
- var highlightAt = props.highlightAt || DEFAULT_HIGHLIGHT_AT;
419
+
410
420
  var _maybeInitialData = maybeInitialData(variants, initialKey, code || props.precompute, undefined,
411
421
  // TODO: use initial.filesOrder if provided?
412
- highlightAt === 'init', props.fallbackUsesExtraFiles, props.fallbackUsesAllVariants),
422
+ props.highlightAfter === 'init', props.fallbackUsesExtraFiles, props.fallbackUsesAllVariants),
413
423
  initialData = _maybeInitialData.initialData,
414
424
  reason = _maybeInitialData.reason;
415
425
  if (!initialData) {
@@ -417,8 +427,13 @@ export function CodeHighlighter(props) {
417
427
  // eslint-disable-next-line no-console
418
428
  console.log('Initial data not found:', reason);
419
429
  }
420
- if (props.forceClient) {
421
- if (highlightAt === 'init') {
430
+
431
+ // Check if any loader functions are available
432
+ var hasAnyLoaderFunction = !!(props.loadCodeMeta || props.loadVariantMeta || props.loadSource || props.sourceParser || props.sourceTransformers);
433
+
434
+ // If no loader functions are available, skip async loading and go directly to client
435
+ if (!hasAnyLoaderFunction || props.forceClient) {
436
+ if (props.highlightAfter === 'init') {
422
437
  throw new Errors.ErrorCodeHighlighterServerInvalidClientMode();
423
438
  }
424
439
  return renderCodeHighlighter(_extends(_extends({}, props), {}, {
@@ -26,7 +26,7 @@ function useInitialData(_ref) {
26
26
  setCode = _ref.setCode,
27
27
  fileName = _ref.fileName,
28
28
  url = _ref.url,
29
- highlightAt = _ref.highlightAt,
29
+ highlightAfter = _ref.highlightAfter,
30
30
  fallbackUsesExtraFiles = _ref.fallbackUsesExtraFiles,
31
31
  fallbackUsesAllVariants = _ref.fallbackUsesAllVariants,
32
32
  isControlled = _ref.isControlled,
@@ -39,8 +39,8 @@ function useInitialData(_ref) {
39
39
  loadSource = _useCodeContext.loadSource,
40
40
  loadFallbackCode = _useCodeContext.loadFallbackCode;
41
41
  var _React$useMemo = React.useMemo(function () {
42
- return maybeInitialData(variants, variantName, code, fileName, highlightAt === 'init', fallbackUsesExtraFiles, fallbackUsesAllVariants);
43
- }, [variants, variantName, code, fileName, highlightAt, fallbackUsesExtraFiles, fallbackUsesAllVariants]),
42
+ return maybeInitialData(variants, variantName, code, fileName, highlightAfter === 'init', fallbackUsesExtraFiles, fallbackUsesAllVariants);
43
+ }, [variants, variantName, code, fileName, highlightAfter, fallbackUsesExtraFiles, fallbackUsesAllVariants]),
44
44
  initialData = _React$useMemo.initialData,
45
45
  reason = _React$useMemo.reason;
46
46
  var needsFallback = !initialData && !isControlled;
@@ -74,7 +74,7 @@ function useInitialData(_ref) {
74
74
  }
75
75
  _context.n = 1;
76
76
  return loadFallbackCode(url, variantName, code, {
77
- shouldHighlight: highlightAt === 'init',
77
+ shouldHighlight: highlightAfter === 'init',
78
78
  fallbackUsesExtraFiles: fallbackUsesExtraFiles,
79
79
  fallbackUsesAllVariants: fallbackUsesAllVariants,
80
80
  sourceParser: sourceParser,
@@ -105,7 +105,7 @@ function useInitialData(_ref) {
105
105
  }
106
106
  }, _callee);
107
107
  }))();
108
- }, [initialData, reason, needsFallback, variantName, code, setCode, highlightAt, url, sourceParser, loadSource, loadVariantMeta, loadCodeMeta, fallbackUsesExtraFiles, fallbackUsesAllVariants, fileName, variants, globalsCode, setProcessedGlobalsCode, loadFallbackCode]);
108
+ }, [initialData, reason, needsFallback, variantName, code, setCode, highlightAfter, url, sourceParser, loadSource, loadVariantMeta, loadCodeMeta, fallbackUsesExtraFiles, fallbackUsesAllVariants, fileName, variants, globalsCode, setProcessedGlobalsCode, loadFallbackCode]);
109
109
  }
110
110
  function useAllVariants(_ref3) {
111
111
  var readyForContent = _ref3.readyForContent,
@@ -302,36 +302,33 @@ function useAllVariants(_ref3) {
302
302
  readyForContent: readyForContent
303
303
  };
304
304
  }
305
+ function yieldToMain() {
306
+ var _scheduler;
307
+ if ((_scheduler = globalThis.scheduler) != null && _scheduler["yield"]) {
308
+ return globalThis.scheduler["yield"]();
309
+ }
310
+
311
+ // Fall back to yielding with setTimeout.
312
+ return new Promise(function (resolve) {
313
+ setTimeout(resolve, 0);
314
+ });
315
+ }
305
316
  function useCodeParsing(_ref6) {
306
317
  var code = _ref6.code,
307
318
  readyForContent = _ref6.readyForContent,
308
- highlightAt = _ref6.highlightAt,
319
+ highlightAfter = _ref6.highlightAfter,
320
+ isHydrated = _ref6.isHydrated,
309
321
  forceClient = _ref6.forceClient,
310
322
  url = _ref6.url;
311
323
  var _useCodeContext3 = useCodeContext(),
312
324
  parseSource = _useCodeContext3.parseSource,
313
325
  parseCode = _useCodeContext3.parseCode;
314
-
315
- // Use useSyncExternalStore to detect hydration
316
- var subscribe = React.useCallback(function () {
317
- return function () {};
318
- }, []);
319
- var getSnapshot = React.useCallback(function () {
320
- return true;
321
- }, []);
322
- var getServerSnapshot = React.useCallback(function () {
323
- return false;
324
- }, []);
325
- var useIsHydrated = function useIsHydrated() {
326
- return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
327
- };
328
- var isHydrated = useIsHydrated();
329
- var _React$useState = React.useState(highlightAt === 'init' || highlightAt === 'hydration' && isHydrated),
326
+ var _React$useState = React.useState(highlightAfter === 'init' || highlightAfter === 'hydration' && isHydrated),
330
327
  _React$useState2 = _slicedToArray(_React$useState, 2),
331
328
  isHighlightAllowed = _React$useState2[0],
332
329
  setIsHighlightAllowed = _React$useState2[1];
333
330
  React.useEffect(function () {
334
- if (highlightAt === 'idle') {
331
+ if (highlightAfter === 'idle') {
335
332
  var idleRequest = window.requestIdleCallback(function () {
336
333
  setIsHighlightAllowed(true);
337
334
  });
@@ -340,16 +337,20 @@ function useCodeParsing(_ref6) {
340
337
  };
341
338
  }
342
339
  return undefined;
343
- }, [highlightAt]);
340
+ }, [highlightAfter]);
344
341
 
345
342
  // Update highlight allowed state when hydration completes
346
343
  React.useEffect(function () {
347
- if (highlightAt === 'hydration' && isHydrated) {
348
- setIsHighlightAllowed(true);
344
+ if (highlightAfter === 'hydration' && isHydrated) {
345
+ // we should ensure that each code highlighter is enhanced as a separate task
346
+ // this should run from top to bottom
347
+ yieldToMain().then(function () {
348
+ return setIsHighlightAllowed(true);
349
+ });
349
350
  }
350
- }, [highlightAt, isHydrated]);
351
+ }, [highlightAfter, isHydrated]);
351
352
 
352
- // Determine if we should highlight based on the highlightAt setting
353
+ // Determine if we should highlight based on the highlightAfter setting
353
354
  var shouldHighlight = React.useMemo(function () {
354
355
  if (!readyForContent) {
355
356
  return false;
@@ -851,7 +852,8 @@ export function CodeHighlighterClient(props) {
851
852
  }
852
853
  var fileName = (controlled == null || (_controlled$selection2 = controlled.selection) == null ? void 0 : _controlled$selection2.fileName) || props.fileName || initialFilename;
853
854
  var url = props.url,
854
- highlightAt = props.highlightAt,
855
+ highlightAfter = props.highlightAfter,
856
+ enhanceAfter = props.enhanceAfter,
855
857
  fallbackUsesExtraFiles = props.fallbackUsesExtraFiles,
856
858
  fallbackUsesAllVariants = props.fallbackUsesAllVariants;
857
859
  useInitialData({
@@ -861,13 +863,54 @@ export function CodeHighlighterClient(props) {
861
863
  setCode: setCode,
862
864
  fileName: fileName,
863
865
  url: url,
864
- highlightAt: highlightAt,
866
+ highlightAfter: highlightAfter,
865
867
  fallbackUsesExtraFiles: fallbackUsesExtraFiles,
866
868
  fallbackUsesAllVariants: fallbackUsesAllVariants,
867
869
  isControlled: isControlled,
868
870
  globalsCode: props.globalsCode,
869
871
  setProcessedGlobalsCode: setProcessedGlobalsCode
870
872
  });
873
+
874
+ // Use useSyncExternalStore to detect hydration
875
+ var subscribe = React.useCallback(function () {
876
+ return function () {};
877
+ }, []);
878
+ var getSnapshot = React.useCallback(function () {
879
+ return true;
880
+ }, []);
881
+ var getServerSnapshot = React.useCallback(function () {
882
+ return false;
883
+ }, []);
884
+ var useIsHydrated = function useIsHydrated() {
885
+ return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
886
+ };
887
+ var isHydrated = useIsHydrated();
888
+ var _React$useState1 = React.useState(enhanceAfter === 'init' || enhanceAfter === 'hydration' && isHydrated),
889
+ _React$useState10 = _slicedToArray(_React$useState1, 2),
890
+ isEnhanceAllowed = _React$useState10[0],
891
+ setIsEnhanceAllowed = _React$useState10[1];
892
+ React.useEffect(function () {
893
+ if (enhanceAfter === 'idle') {
894
+ var idleRequest = window.requestIdleCallback(function () {
895
+ setIsEnhanceAllowed(true);
896
+ });
897
+ return function () {
898
+ return window.cancelIdleCallback(idleRequest);
899
+ };
900
+ }
901
+ return undefined;
902
+ }, [enhanceAfter]);
903
+
904
+ // Update enhance allowed state when hydration completes
905
+ React.useEffect(function () {
906
+ if (enhanceAfter === 'hydration' && isHydrated) {
907
+ // we should ensure that each code highlighter is enhanced as a separate task
908
+ // this should run from top to bottom
909
+ yieldToMain().then(function () {
910
+ return setIsEnhanceAllowed(true);
911
+ });
912
+ }
913
+ }, [enhanceAfter, isHydrated]);
871
914
  var readyForContent = React.useMemo(function () {
872
915
  if (!code) {
873
916
  return false;
@@ -877,7 +920,7 @@ export function CodeHighlighterClient(props) {
877
920
 
878
921
  // Separate check for activeCode to determine when to show fallback
879
922
  var activeCodeReady = React.useMemo(function () {
880
- if (!activeCode) {
923
+ if (!activeCode || !isEnhanceAllowed) {
881
924
  return false;
882
925
  }
883
926
 
@@ -889,7 +932,7 @@ export function CodeHighlighterClient(props) {
889
932
  // For regular code, use the existing hasAllVariants function
890
933
  var regularCode = props.code || code;
891
934
  return regularCode ? hasAllVariants(variants, regularCode) : false;
892
- }, [activeCode, controlled == null ? void 0 : controlled.code, variants, props.code, code]);
935
+ }, [activeCode, isEnhanceAllowed, controlled == null ? void 0 : controlled.code, variants, props.code, code]);
893
936
  useAllVariants({
894
937
  readyForContent: readyForContent,
895
938
  variants: variants,
@@ -927,7 +970,8 @@ export function CodeHighlighterClient(props) {
927
970
  var _useCodeParsing = useCodeParsing({
928
971
  code: codeWithGlobals,
929
972
  readyForContent: readyForContent || Boolean(props.code),
930
- highlightAt: highlightAt,
973
+ highlightAfter: highlightAfter,
974
+ isHydrated: isHydrated,
931
975
  forceClient: props.forceClient,
932
976
  url: props.url
933
977
  }),
@@ -190,7 +190,7 @@ export var ErrorCodeHighlighterServerMissingContentLoading = /*#__PURE__*/functi
190
190
  export var ErrorCodeHighlighterServerInvalidClientMode = /*#__PURE__*/function (_ErrorCodeHighlighter17) {
191
191
  function ErrorCodeHighlighterServerInvalidClientMode() {
192
192
  _classCallCheck(this, ErrorCodeHighlighterServerInvalidClientMode);
193
- return _callSuper(this, ErrorCodeHighlighterServerInvalidClientMode, ["Invalid client mode - Client only mode with highlightAt: init requires precomputed and parsed source code"]);
193
+ return _callSuper(this, ErrorCodeHighlighterServerInvalidClientMode, ["Invalid client mode - Client only mode with highlightAfter: init requires precomputed and parsed source code"]);
194
194
  }
195
195
  _inherits(ErrorCodeHighlighterServerInvalidClientMode, _ErrorCodeHighlighter17);
196
196
  return _createClass(ErrorCodeHighlighterServerInvalidClientMode);
@@ -99,6 +99,7 @@ function _loadFallbackCode() {
99
99
  initialFilename,
100
100
  variants,
101
101
  globalsCode,
102
+ output,
102
103
  initial,
103
104
  _allFileNames,
104
105
  fileSource,
@@ -142,7 +143,7 @@ function _loadFallbackCode() {
142
143
  while (1) switch (_context4.p = _context4.n) {
143
144
  case 0:
144
145
  options = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : {};
145
- shouldHighlight = options.shouldHighlight, fallbackUsesExtraFiles = options.fallbackUsesExtraFiles, fallbackUsesAllVariants = options.fallbackUsesAllVariants, sourceParser = options.sourceParser, loadSource = options.loadSource, loadVariantMeta = options.loadVariantMeta, loadCodeMeta = options.loadCodeMeta, initialFilename = options.initialFilename, variants = options.variants, globalsCode = options.globalsCode;
146
+ shouldHighlight = options.shouldHighlight, fallbackUsesExtraFiles = options.fallbackUsesExtraFiles, fallbackUsesAllVariants = options.fallbackUsesAllVariants, sourceParser = options.sourceParser, loadSource = options.loadSource, loadVariantMeta = options.loadVariantMeta, loadCodeMeta = options.loadCodeMeta, initialFilename = options.initialFilename, variants = options.variants, globalsCode = options.globalsCode, output = options.output;
146
147
  loaded = _extends({}, loaded);
147
148
 
148
149
  // Step 1: Ensure we have the initial variant loaded
@@ -458,7 +459,9 @@ function _loadFallbackCode() {
458
459
  // Don't apply transforms for fallback
459
460
  disableParsing: !shouldHighlight,
460
461
  // Only parse if highlighting is needed
461
- globalsCode: resolvedGlobalsCode // Pass resolved globalsCode
462
+ globalsCode: resolvedGlobalsCode,
463
+ // Pass resolved globalsCode
464
+ output: output
462
465
  });
463
466
  case 38:
464
467
  _yield$loadVariant = _context4.v;
@@ -565,6 +568,7 @@ function _loadFallbackCode() {
565
568
  // sourceTransformers
566
569
  disableTransforms: true,
567
570
  disableParsing: !shouldHighlight,
571
+ output: output,
568
572
  globalsCode: globalsCodeObjects && globalsCodeObjects.length > 0 ? function () {
569
573
  // Convert globalsCodeObjects to VariantCode | string for this specific variant
570
574
  var variantGlobalsCode = [];
@@ -6,10 +6,25 @@ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIt
6
6
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
7
7
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
8
8
  import * as path from 'path-module';
9
+ import { compress, strToU8 } from 'fflate';
10
+ import { encode } from 'uint8-to-base64';
9
11
  import { transformSource } from "./transformSource.js";
10
12
  import { transformParsedSource } from "./transformParsedSource.js";
11
13
  import { getFileNameFromUrl } from "../pipeline/loaderUtils/index.js";
12
14
  import { mergeExternals } from "../pipeline/loaderUtils/mergeExternals.js";
15
+ function compressAsync(input) {
16
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17
+ return new Promise(function (resolve, reject) {
18
+ compress(input, options, function (err, output) {
19
+ if (err) {
20
+ reject(err);
21
+ } else {
22
+ resolve(output);
23
+ }
24
+ });
25
+ });
26
+ }
27
+
13
28
  /**
14
29
  * Check if a path is absolute (either filesystem absolute or URL)
15
30
  */
@@ -141,10 +156,12 @@ function _loadSingleFile() {
141
156
  finalTransforms,
142
157
  sourceString,
143
158
  parseSource,
159
+ hastGzip,
144
160
  _args = arguments,
145
161
  _t,
146
162
  _t2,
147
- _t3;
163
+ _t3,
164
+ _t4;
148
165
  return _regenerator().w(function (_context) {
149
166
  while (1) switch (_context.p = _context.n) {
150
167
  case 0:
@@ -306,7 +323,7 @@ function _loadSingleFile() {
306
323
  finalTransforms = _context.v;
307
324
  case 22:
308
325
  if (!(typeof finalSource === 'string' && !disableParsing)) {
309
- _context.n = 28;
326
+ _context.n = 31;
310
327
  break;
311
328
  }
312
329
  if (sourceParser) {
@@ -331,13 +348,38 @@ function _loadSingleFile() {
331
348
  case 25:
332
349
  finalTransforms = _context.v;
333
350
  case 26:
334
- _context.n = 28;
335
- break;
351
+ if (!(options.output === 'hastGzip' && process.env.NODE_ENV === 'production')) {
352
+ _context.n = 28;
353
+ break;
354
+ }
355
+ _t3 = encode;
356
+ _context.n = 27;
357
+ return compressAsync(strToU8(JSON.stringify(finalSource)), {
358
+ consume: true,
359
+ level: 9
360
+ });
336
361
  case 27:
337
- _context.p = 27;
338
- _t3 = _context.v;
339
- throw new Error("Failed to parse source code (variant: ".concat(variantName, ", file: ").concat(fileName, ", url: ").concat(url, "): ").concat(_t3 instanceof Error ? _t3.message : ''));
362
+ hastGzip = _t3(_context.v);
363
+ finalSource = {
364
+ hastGzip: hastGzip
365
+ };
366
+ _context.n = 29;
367
+ break;
340
368
  case 28:
369
+ if (options.output === 'hastJson' || options.output === 'hastGzip') {
370
+ // in development, we skip compression but still convert to JSON
371
+ finalSource = {
372
+ hastJson: JSON.stringify(finalSource)
373
+ };
374
+ }
375
+ case 29:
376
+ _context.n = 31;
377
+ break;
378
+ case 30:
379
+ _context.p = 30;
380
+ _t4 = _context.v;
381
+ throw new Error("Failed to parse source code (variant: ".concat(variantName, ", file: ").concat(fileName, ", url: ").concat(url, "): ").concat(_t4 instanceof Error ? _t4.message : ''));
382
+ case 31:
341
383
  return _context.a(2, {
342
384
  source: finalSource,
343
385
  transforms: finalTransforms,
@@ -346,7 +388,7 @@ function _loadSingleFile() {
346
388
  externals: externalsFromSource
347
389
  });
348
390
  }
349
- }, _callee, null, [[23, 27], [8, 13, 14, 15], [2, 18]]);
391
+ }, _callee, null, [[23, 30], [8, 13, 14, 15], [2, 18]]);
350
392
  }));
351
393
  return _loadSingleFile.apply(this, arguments);
352
394
  }
@@ -397,7 +439,7 @@ function _loadExtraFiles() {
397
439
  convertedKey,
398
440
  normalizedConvertedKey,
399
441
  _args4 = arguments,
400
- _t5;
442
+ _t6;
401
443
  return _regenerator().w(function (_context4) {
402
444
  while (1) switch (_context4.p = _context4.n) {
403
445
  case 0:
@@ -417,7 +459,7 @@ function _loadExtraFiles() {
417
459
  allExternals = {}; // Start loading all extra files in parallel
418
460
  extraFilePromises = Object.entries(extraFiles).map(/*#__PURE__*/function () {
419
461
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
420
- var _ref3, fileName, fileData, fileUrl, sourceData, transforms, fileResult, filesUsedFromFile, externalsFromFile, _t4;
462
+ var _ref3, fileName, fileData, fileUrl, sourceData, transforms, fileResult, filesUsedFromFile, externalsFromFile, _t5;
421
463
  return _regenerator().w(function (_context2) {
422
464
  while (1) switch (_context2.p = _context2.n) {
423
465
  case 0:
@@ -475,8 +517,8 @@ function _loadExtraFiles() {
475
517
  });
476
518
  case 6:
477
519
  _context2.p = 6;
478
- _t4 = _context2.v;
479
- throw new Error("Failed to load extra file (variant: ".concat(variantName, ", file: ").concat(fileName, ", url: ").concat(baseUrl, "): ").concat(_t4 instanceof Error ? _t4.message : ''));
520
+ _t5 = _context2.v;
521
+ throw new Error("Failed to load extra file (variant: ".concat(variantName, ", file: ").concat(fileName, ", url: ").concat(baseUrl, "): ").concat(_t5 instanceof Error ? _t5.message : ''));
480
522
  case 7:
481
523
  return _context2.a(2);
482
524
  }
@@ -565,8 +607,8 @@ function _loadExtraFiles() {
565
607
  break;
566
608
  case 7:
567
609
  _context4.p = 7;
568
- _t5 = _context4.v;
569
- _iterator2.e(_t5);
610
+ _t6 = _context4.v;
611
+ _iterator2.e(_t6);
570
612
  case 8:
571
613
  _context4.p = 8;
572
614
  _iterator2.f();
@@ -681,7 +723,7 @@ function _loadVariant() {
681
723
  _extraFilesResult,
682
724
  finalVariant,
683
725
  _args6 = arguments,
684
- _t8;
726
+ _t9;
685
727
  return _regenerator().w(function (_context6) {
686
728
  while (1) switch (_context6.p = _context6.n) {
687
729
  case 0:
@@ -726,8 +768,8 @@ function _loadVariant() {
726
768
  break;
727
769
  case 5:
728
770
  _context6.p = 5;
729
- _t8 = _context6.v;
730
- throw new Error("Failed to load variant code (variant: ".concat(variantName, ", url: ").concat(variant, "): ").concat(JSON.stringify(_t8)));
771
+ _t9 = _context6.v;
772
+ throw new Error("Failed to load variant code (variant: ".concat(variantName, ", url: ").concat(variant, "): ").concat(JSON.stringify(_t9)));
731
773
  case 6:
732
774
  loadedFiles = new Set();
733
775
  if (url) {
@@ -833,7 +875,7 @@ function _loadVariant() {
833
875
  // Process all globals items in parallel
834
876
  globalsPromises = globalsCode.map(/*#__PURE__*/function () {
835
877
  var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(globalsItem) {
836
- var globalsVariant, _getFileNameFromUrl2, globalsFileName, globalsResult, _t6, _t7;
878
+ var globalsVariant, _getFileNameFromUrl2, globalsFileName, globalsResult, _t7, _t8;
837
879
  return _regenerator().w(function (_context5) {
838
880
  while (1) switch (_context5.p = _context5.n) {
839
881
  case 0:
@@ -869,8 +911,8 @@ function _loadVariant() {
869
911
  break;
870
912
  case 4:
871
913
  _context5.p = 4;
872
- _t6 = _context5.v;
873
- throw new Error("Failed to load globalsCode variant metadata (variant: ".concat(variantName, ", url: ").concat(globalsItem, "): ").concat(JSON.stringify(_t6)));
914
+ _t7 = _context5.v;
915
+ throw new Error("Failed to load globalsCode variant metadata (variant: ".concat(variantName, ", url: ").concat(globalsItem, "): ").concat(JSON.stringify(_t7)));
874
916
  case 5:
875
917
  _context5.n = 7;
876
918
  break;
@@ -888,8 +930,8 @@ function _loadVariant() {
888
930
  return _context5.a(2, globalsResult);
889
931
  case 9:
890
932
  _context5.p = 9;
891
- _t7 = _context5.v;
892
- throw new Error("Failed to load globalsCode (variant: ".concat(variantName, "): ").concat(_t7 instanceof Error ? _t7.message : JSON.stringify(_t7)));
933
+ _t8 = _context5.v;
934
+ throw new Error("Failed to load globalsCode (variant: ".concat(variantName, "): ").concat(_t8 instanceof Error ? _t8.message : JSON.stringify(_t8)));
893
935
  case 10:
894
936
  return _context5.a(2);
895
937
  }
@@ -67,7 +67,7 @@ import { Code, VariantExtraFiles, VariantSource } from "./types.js";
67
67
  * initialKey,
68
68
  * code || props.precompute,
69
69
  * undefined,
70
- * highlightAt === 'init',
70
+ * highlightAfter === 'init',
71
71
  * props.fallbackUsesExtraFiles,
72
72
  * props.fallbackUsesAllVariants,
73
73
  * );
@@ -84,7 +84,7 @@ import { Code, VariantExtraFiles, VariantSource } from "./types.js";
84
84
  * variantName,
85
85
  * code,
86
86
  * fileName,
87
- * highlightAt === 'init',
87
+ * highlightAfter === 'init',
88
88
  * fallbackUsesExtraFiles,
89
89
  * fallbackUsesAllVariants,
90
90
  * ), [dependencies]);