@mui/internal-docs-infra 0.12.1-canary.2 → 0.12.1-canary.21
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.
- package/ChunkProvider/PreloadProvider.mjs +1 -2
- package/ChunkProvider/usePreload.d.mts +1 -1
- package/ChunkProvider/usePreload.mjs +0 -1
- package/CodeControllerContext/CodeControllerContext.d.mts +45 -10
- package/CodeControllerContext/CodeControllerContext.mjs +15 -1
- package/CodeHighlighter/CodeHighlighterClient.d.mts +3 -2
- package/CodeHighlighter/CodeHighlighterClient.mjs +113 -18
- package/CodeHighlighter/CodeHighlighterContext.d.mts +9 -3
- package/CodeHighlighter/buildStringFallback.d.mts +1 -1
- package/CodeHighlighter/codeToFallbackProps.d.mts +1 -1
- package/CodeHighlighter/createClientProps.mjs +3 -0
- package/CodeHighlighter/fallbackCompression.d.mts +1 -1
- package/CodeHighlighter/parseControlledCode.d.mts +13 -4
- package/CodeHighlighter/parseControlledCode.mjs +41 -49
- package/CodeHighlighter/types.d.mts +21 -0
- package/CodeHighlighter/useGrammarsReady.mjs +44 -9
- package/CodeProvider/CodeProvider.d.mts +1 -1
- package/CodeProvider/CodeProviderLazy.d.mts +1 -1
- package/CodeProvider/createParseSourceWorkerClient.d.mts +6 -0
- package/CodeProvider/createParseSourceWorkerClient.mjs +83 -15
- package/CodeProvider/useCodeProviderValue.mjs +50 -4
- package/abstractCreateDemo/abstractCreateDemo.d.mts +15 -1
- package/abstractCreateDemo/abstractCreateDemo.mjs +8 -0
- package/abstractCreateDemoClient/abstractCreateDemoClient.mjs +4 -0
- package/abstractCreateTypes/abstractCreateTypes.d.mts +12 -1
- package/abstractCreateTypes/abstractCreateTypes.mjs +4 -0
- package/abstractCreateTypes/typesToJsx.d.mts +8 -0
- package/abstractCreateTypes/typesToJsx.mjs +2 -1
- package/cli/loadNextConfig.d.mts +9 -0
- package/cli/loadNextConfig.mjs +11 -2
- package/cli/runValidate.mjs +15 -7
- package/cli/validateWorker.d.mts +1 -0
- package/cli/validateWorker.mjs +2 -1
- package/createDemoData/createDemoData.d.mts +1 -1
- package/package.json +34 -5
- package/pipeline/cacheUtils/constants.d.mts +5 -0
- package/pipeline/cacheUtils/constants.mjs +5 -0
- package/pipeline/cacheUtils/hashCacheContent.d.mts +5 -0
- package/pipeline/cacheUtils/hashCacheContent.mjs +9 -0
- package/pipeline/cacheUtils/index.d.mts +9 -0
- package/pipeline/cacheUtils/index.mjs +7 -0
- package/pipeline/cacheUtils/loadFileCache.d.mts +13 -0
- package/pipeline/cacheUtils/loadFileCache.mjs +20 -0
- package/pipeline/cacheUtils/loadFileCacheEntry.d.mts +13 -0
- package/pipeline/cacheUtils/loadFileCacheEntry.mjs +47 -0
- package/pipeline/cacheUtils/resolveCachePath.d.mts +16 -0
- package/pipeline/cacheUtils/resolveCachePath.mjs +24 -0
- package/pipeline/cacheUtils/saveFileCache.d.mts +17 -0
- package/pipeline/cacheUtils/saveFileCache.mjs +54 -0
- package/pipeline/cacheUtils/types.d.mts +23 -0
- package/pipeline/cacheUtils/types.mjs +1 -0
- package/pipeline/cacheUtils/withFileCache.d.mts +40 -0
- package/pipeline/cacheUtils/withFileCache.mjs +81 -0
- package/pipeline/hastUtils/hastUtils.d.mts +1 -1
- package/pipeline/hastUtils/hastUtils.mjs +0 -1
- package/pipeline/loadIsomorphicCodeSource/loadIsomorphicCodeSource.d.mts +1 -1
- package/pipeline/loadIsomorphicCodeSource/loadIsomorphicCodeSource.mjs +1 -1
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransform.mjs +0 -1
- package/pipeline/loadIsomorphicCodeVariant/diffHast.d.mts +1 -1
- package/pipeline/loadIsomorphicCodeVariant/hasAllCodeVariants.d.mts +1 -1
- package/pipeline/loadIsomorphicCodeVariant/maybeCodeInitialData.d.mts +1 -1
- package/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.d.mts +6 -0
- package/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.mjs +2 -1
- package/pipeline/loadPrecomputedTypes/loadPrecomputedTypes.d.mts +6 -0
- package/pipeline/loadPrecomputedTypes/loadPrecomputedTypes.mjs +5 -1
- package/pipeline/loadServerCodeMeta/resolveModulePathWithFs.d.mts +1 -1
- package/pipeline/loadServerCodeMeta/resolveModulePathWithFs.mjs +0 -1
- package/pipeline/loadServerPageIndex/enrichPageIndex.d.mts +15 -0
- package/pipeline/loadServerPageIndex/enrichPageIndex.mjs +50 -0
- package/pipeline/loadServerPageIndex/extractPrefixAndTitle.d.mts +19 -0
- package/pipeline/loadServerPageIndex/extractPrefixAndTitle.mjs +80 -0
- package/pipeline/loadServerPageIndex/index.d.mts +5 -2
- package/pipeline/loadServerPageIndex/index.mjs +4 -1
- package/pipeline/loadServerPageIndex/loadServerPageIndex.d.mts +13 -22
- package/pipeline/loadServerPageIndex/loadServerPageIndex.mjs +32 -124
- package/pipeline/loadServerPageIndex/resolvePageIndexCacheKey.d.mts +13 -0
- package/pipeline/loadServerPageIndex/resolvePageIndexCacheKey.mjs +23 -0
- package/pipeline/loadServerTypes/highlightTypes.d.mts +3 -3
- package/pipeline/loadServerTypes/highlightTypesMeta.d.mts +4 -4
- package/pipeline/loadServerTypes/loadServerTypes.d.mts +2 -2
- package/pipeline/loadServerTypes/loadServerTypes.mjs +67 -7
- package/pipeline/loadServerTypesMeta/createOptimizedProgram.d.mts +2 -1
- package/pipeline/loadServerTypesMeta/formatClass.d.mts +2 -2
- package/pipeline/loadServerTypesMeta/formatComponent.d.mts +2 -2
- package/pipeline/loadServerTypesMeta/formatFunction.d.mts +2 -2
- package/pipeline/loadServerTypesMeta/formatHook.d.mts +2 -2
- package/pipeline/loadServerTypesMeta/formatRaw.d.mts +2 -2
- package/pipeline/loadServerTypesMeta/formatType.d.mts +1 -1
- package/pipeline/loadServerTypesMeta/loadServerTypesMeta.d.mts +7 -7
- package/pipeline/loadServerTypesMeta/loadServerTypesMeta.mjs +1 -1
- package/pipeline/loadServerTypesMeta/processTypes.d.mts +2 -2
- package/pipeline/loadServerTypesMeta/worker.d.mts +1 -1
- package/pipeline/loadServerTypesText/loadServerTypesText.d.mts +16 -2
- package/pipeline/loadServerTypesText/loadServerTypesText.mjs +30 -8
- package/pipeline/loadServerTypesText/normalizeTypesSourceDataForCache.d.mts +2 -0
- package/pipeline/loadServerTypesText/normalizeTypesSourceDataForCache.mjs +144 -0
- package/pipeline/loadServerTypesText/resolveTypesCacheKey.d.mts +19 -0
- package/pipeline/loadServerTypesText/resolveTypesCacheKey.mjs +29 -0
- package/pipeline/loaderUtils/parseImportsAndComments.d.mts +5 -3
- package/pipeline/loaderUtils/parseImportsAndComments.mjs +284 -40
- package/pipeline/parseCreateFactoryCall/parseCreateFactoryCall.d.mts +2 -2
- package/pipeline/parseCreateFactoryCall/parseCreateFactoryCall.mjs +2 -3
- package/pipeline/parseSource/detectFileTypes.d.mts +16 -0
- package/pipeline/parseSource/detectFileTypes.mjs +44 -0
- package/pipeline/syncPageIndex/mergeMetadataMarkdown.d.mts +25 -1
- package/pipeline/syncPageIndex/mergeMetadataMarkdown.mjs +79 -49
- package/pipeline/syncPageIndex/metadataToMarkdown.d.mts +15 -1
- package/pipeline/syncPageIndex/metadataToMarkdown.mjs +32 -10
- package/pipeline/syncPageIndex/syncPageIndex.d.mts +12 -0
- package/pipeline/syncPageIndex/syncPageIndex.mjs +154 -40
- package/pipeline/syncTypes/generateTypesMarkdown.d.mts +2 -2
- package/pipeline/syncTypes/syncTypes.d.mts +7 -0
- package/pipeline/syncTypes/syncTypes.mjs +31 -1
- package/pipeline/transformHtmlCodeBlock/transformHtmlCodeBlock.mjs +1 -1
- package/pipeline/transformMarkdownCode/transformMarkdownCode.mjs +25 -15
- package/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.mjs +3 -0
- package/pipeline/transformMarkdownMetadata/types.d.mts +8 -1
- package/useCode/EditableEngine.d.mts +1 -1
- package/useCode/Pre.d.mts +9 -2
- package/useCode/Pre.mjs +4 -3
- package/useCode/TransformEngine.d.mts +1 -1
- package/useCode/useCode.d.mts +17 -1
- package/useCode/useCode.mjs +22 -1
- package/useCode/useCopyFunctionality.d.mts +2 -2
- package/useCode/useEditable.browser.mjs +0 -1
- package/useCode/useFileNavigation.d.mts +3 -0
- package/useCode/useFileNavigation.mjs +3 -1
- package/useCode/useSourceEditing.mjs +45 -10
- package/useCode/useSourceEnhancing.mjs +41 -9
- package/useCode/useTransformManagement.d.mts +2 -2
- package/useCode/useTransformManagement.mjs +19 -3
- package/useCode/useUIState.d.mts +4 -0
- package/useCode/useUIState.mjs +8 -1
- package/useCode/useVariantSelection.d.mts +1 -1
- package/useCoordinated/useCoordinated.d.mts +1 -1
- package/useCoordinated/useCoordinatedLocalStorage.d.mts +1 -1
- package/useCoordinated/useCoordinatedLocalStorage.mjs +0 -1
- package/useCoordinated/useCoordinatedPreference.d.mts +1 -1
- package/useCoordinated/useCoordinatedPreference.mjs +0 -1
- package/useCrossTabState/index.d.mts +2 -0
- package/useCrossTabState/index.mjs +2 -0
- package/useCrossTabState/useCrossTabMirror.d.mts +26 -0
- package/useCrossTabState/useCrossTabMirror.mjs +108 -0
- package/useCrossTabState/useCrossTabState.d.mts +21 -0
- package/useCrossTabState/useCrossTabState.mjs +31 -0
- package/useDemo/exportVariant.mjs +2 -4
- package/useDemo/exportVariantAsCra.d.mts +1 -1
- package/useDemo/exportVariantAsCra.mjs +0 -1
- package/useDemo/useDemo.d.mts +4 -1
- package/useDemo/useDemo.mjs +5 -0
- package/useDemoController/BuildEngine.d.mts +2 -0
- package/useDemoController/BuildEngine.mjs +10 -0
- package/useDemoController/DemoRunner.d.mts +34 -0
- package/useDemoController/DemoRunner.mjs +83 -0
- package/useDemoController/ErrorBoundary.d.mts +34 -0
- package/useDemoController/ErrorBoundary.mjs +49 -0
- package/useDemoController/Runner.d.mts +44 -0
- package/useDemoController/Runner.mjs +71 -0
- package/useDemoController/absolutizeImports.d.mts +13 -0
- package/useDemoController/absolutizeImports.mjs +73 -0
- package/useDemoController/buildScope.d.mts +48 -0
- package/useDemoController/buildScope.mjs +270 -0
- package/useDemoController/collectSources.d.mts +67 -0
- package/useDemoController/collectSources.mjs +92 -0
- package/useDemoController/compileCssModule.d.mts +64 -0
- package/useDemoController/compileCssModule.mjs +40 -0
- package/useDemoController/compileCssWithPostcss.d.mts +17 -0
- package/useDemoController/compileCssWithPostcss.mjs +89 -0
- package/useDemoController/compileModule.d.mts +14 -0
- package/useDemoController/compileModule.mjs +17 -0
- package/useDemoController/constants.d.mts +13 -0
- package/useDemoController/constants.mjs +13 -0
- package/useDemoController/createRequire.d.mts +10 -0
- package/useDemoController/createRequire.mjs +17 -0
- package/useDemoController/createTranspileWorkerClient.d.mts +27 -0
- package/useDemoController/createTranspileWorkerClient.mjs +139 -0
- package/useDemoController/cssModules.d.mts +47 -0
- package/useDemoController/currentBrowserTarget.d.mts +16 -0
- package/useDemoController/currentBrowserTarget.mjs +36 -0
- package/useDemoController/evalCode.d.mts +12 -0
- package/useDemoController/evalCode.mjs +35 -0
- package/useDemoController/generateCssModuleSource.d.mts +11 -0
- package/useDemoController/generateCssModuleSource.mjs +55 -0
- package/useDemoController/generateElement.d.mts +21 -0
- package/useDemoController/generateElement.mjs +26 -0
- package/useDemoController/hashString.d.mts +11 -0
- package/useDemoController/hashString.mjs +20 -0
- package/useDemoController/importCode.d.mts +11 -0
- package/useDemoController/importCode.mjs +15 -0
- package/useDemoController/index.d.mts +1 -0
- package/useDemoController/index.mjs +1 -0
- package/useDemoController/instantiateElement.d.mts +24 -0
- package/useDemoController/instantiateElement.mjs +57 -0
- package/useDemoController/instantiateModule.d.mts +17 -0
- package/useDemoController/instantiateModule.mjs +24 -0
- package/useDemoController/resolveCssImports.d.mts +27 -0
- package/useDemoController/resolveCssImports.mjs +79 -0
- package/useDemoController/transformCode.d.mts +14 -0
- package/useDemoController/transformCode.mjs +42 -0
- package/useDemoController/transpileClientSingleton.d.mts +10 -0
- package/useDemoController/transpileClientSingleton.mjs +83 -0
- package/useDemoController/transpileSource.d.mts +29 -0
- package/useDemoController/transpileSource.mjs +36 -0
- package/useDemoController/transpileWorker.d.mts +14 -0
- package/useDemoController/transpileWorker.mjs +41 -0
- package/useDemoController/types.d.mts +30 -0
- package/useDemoController/types.mjs +1 -0
- package/useDemoController/useDemoController.d.mts +54 -0
- package/useDemoController/useDemoController.mjs +186 -0
- package/useDemoController/useRunner.d.mts +53 -0
- package/useDemoController/useRunner.mjs +118 -0
- package/useDemoController/useVariantBuilds.d.mts +31 -0
- package/useDemoController/useVariantBuilds.mjs +188 -0
- package/useSearch/types.d.mts +1 -1
- package/useType/TypesDataProvider.d.mts +1 -1
- package/useType/TypesDataProvider.mjs +1 -2
- package/useType/useType.d.mts +1 -1
- package/useType/useTypeProp.d.mts +1 -1
- package/withDocsInfra/withDeploymentConfig.mjs +57 -0
- package/withDocsInfra/withDocsInfra.d.mts +14 -0
- package/withDocsInfra/withDocsInfra.mjs +25 -11
|
@@ -641,6 +641,32 @@ function skipWhitespace(text, start) {
|
|
|
641
641
|
return pos;
|
|
642
642
|
}
|
|
643
643
|
|
|
644
|
+
/**
|
|
645
|
+
* Skips whitespace and line (`//`) or block comments, returning the next
|
|
646
|
+
* significant position. Used to read a dynamic import's specifier past a leading
|
|
647
|
+
* comment — e.g. a webpack magic comment before the module string.
|
|
648
|
+
*/
|
|
649
|
+
function skipWhitespaceAndComments(text, start) {
|
|
650
|
+
let pos = start;
|
|
651
|
+
for (;;) {
|
|
652
|
+
pos = skipWhitespace(text, pos);
|
|
653
|
+
if (text[pos] === '/' && text[pos + 1] === '/') {
|
|
654
|
+
pos += 2;
|
|
655
|
+
while (pos < text.length && text[pos] !== '\n') {
|
|
656
|
+
pos += 1;
|
|
657
|
+
}
|
|
658
|
+
} else if (text[pos] === '/' && text[pos + 1] === '*') {
|
|
659
|
+
pos += 2;
|
|
660
|
+
while (pos < text.length && !(text[pos] === '*' && text[pos + 1] === '/')) {
|
|
661
|
+
pos += 1;
|
|
662
|
+
}
|
|
663
|
+
pos += 2;
|
|
664
|
+
} else {
|
|
665
|
+
return pos;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
644
670
|
/**
|
|
645
671
|
* Reads a JavaScript identifier starting at the given position.
|
|
646
672
|
* @param text - The text to read from
|
|
@@ -678,7 +704,9 @@ function readQuotedString(text, start) {
|
|
|
678
704
|
while (pos < text.length) {
|
|
679
705
|
const ch = text[pos];
|
|
680
706
|
if (ch === '\\' && pos + 1 < text.length) {
|
|
681
|
-
//
|
|
707
|
+
// Keep the escaped character (drop the backslash): `\"` denotes a literal quote
|
|
708
|
+
// in the specifier, so it must stay in the path rather than being dropped.
|
|
709
|
+
value += text[pos + 1];
|
|
682
710
|
pos += 2;
|
|
683
711
|
continue;
|
|
684
712
|
}
|
|
@@ -901,6 +929,131 @@ function parseCssImportStatement(cssCode, start) {
|
|
|
901
929
|
};
|
|
902
930
|
}
|
|
903
931
|
|
|
932
|
+
/**
|
|
933
|
+
* Records one CSS import path into the relative or external bucket, with its
|
|
934
|
+
* source position for rewriting. Shared by `@import`, `composes ... from`, and
|
|
935
|
+
* `@value ... from`. In CSS a path is relative unless it has a protocol,
|
|
936
|
+
* hostname, or scoped-package (`@scope/`) prefix.
|
|
937
|
+
*/
|
|
938
|
+
function recordCssImport(modulePath, pathStart, pathEnd, cssResult, cssExternals, cssFilePath, positionMapper) {
|
|
939
|
+
const hasProtocol = /^https?:\/\//.test(modulePath);
|
|
940
|
+
const hasHostname = /^\/\//.test(modulePath);
|
|
941
|
+
const isScopedPackage = /^@[^/]+\//.test(modulePath);
|
|
942
|
+
const isRelative = !hasProtocol && !hasHostname && !isScopedPackage;
|
|
943
|
+
const position = {
|
|
944
|
+
start: positionMapper(pathStart),
|
|
945
|
+
end: positionMapper(pathEnd)
|
|
946
|
+
};
|
|
947
|
+
if (isRelative) {
|
|
948
|
+
// Normalize bare filenames (e.g. "reset.css") to relative paths.
|
|
949
|
+
let normalizedPath = modulePath;
|
|
950
|
+
if (!normalizedPath.startsWith('./') && !normalizedPath.startsWith('../')) {
|
|
951
|
+
normalizedPath = `./${normalizedPath}`;
|
|
952
|
+
}
|
|
953
|
+
if (!cssResult[modulePath]) {
|
|
954
|
+
cssResult[modulePath] = {
|
|
955
|
+
url: resolveRelativeImport(cssFilePath, normalizedPath),
|
|
956
|
+
names: [],
|
|
957
|
+
positions: []
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
cssResult[modulePath].positions.push(position);
|
|
961
|
+
} else {
|
|
962
|
+
if (!cssExternals[modulePath]) {
|
|
963
|
+
cssExternals[modulePath] = {
|
|
964
|
+
names: [],
|
|
965
|
+
positions: []
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
cssExternals[modulePath].positions.push(position);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
/** Index of the `;` or `}` ending a CSS statement at/after `start` (string-aware). */
|
|
973
|
+
function findCssStatementEnd(text, start) {
|
|
974
|
+
let pos = start;
|
|
975
|
+
while (pos < text.length) {
|
|
976
|
+
const ch = text[pos];
|
|
977
|
+
if (ch === ';' || ch === '}') {
|
|
978
|
+
return pos;
|
|
979
|
+
}
|
|
980
|
+
if (ch === '"' || ch === "'") {
|
|
981
|
+
pos += 1;
|
|
982
|
+
while (pos < text.length && text[pos] !== ch) {
|
|
983
|
+
pos += text[pos] === '\\' ? 2 : 1;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
pos += 1;
|
|
987
|
+
}
|
|
988
|
+
return text.length;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* Scans a `composes`/`@value` statement body (`[start, end)`) for a
|
|
993
|
+
* `from "<path>"` clause, skipping any quoted string before it. Returns the
|
|
994
|
+
* quoted module path with its position (quotes included), or null for a same-file
|
|
995
|
+
* `composes`, a `from global`, or a plain `@value` definition.
|
|
996
|
+
*/
|
|
997
|
+
function parseCssFromClause(text, start, end) {
|
|
998
|
+
let pos = start;
|
|
999
|
+
while (pos < end) {
|
|
1000
|
+
const ch = text[pos];
|
|
1001
|
+
// Skip a quoted string (e.g. a `@value` definition's string value).
|
|
1002
|
+
if (ch === '"' || ch === "'") {
|
|
1003
|
+
pos += 1;
|
|
1004
|
+
while (pos < end && text[pos] !== ch) {
|
|
1005
|
+
pos += text[pos] === '\\' ? 2 : 1;
|
|
1006
|
+
}
|
|
1007
|
+
pos += 1;
|
|
1008
|
+
continue;
|
|
1009
|
+
}
|
|
1010
|
+
// A standalone `from` keyword introduces the source module.
|
|
1011
|
+
if (ch === 'f' && text.slice(pos, pos + 4) === 'from' && !isIdentifierChar(text[pos - 1] || '') && !isIdentifierChar(text[pos + 4] || '')) {
|
|
1012
|
+
const quoteStart = skipWhitespace(text, pos + 4);
|
|
1013
|
+
const quote = text[quoteStart];
|
|
1014
|
+
if (quote !== '"' && quote !== "'") {
|
|
1015
|
+
return null; // `from global` or other non-path source
|
|
1016
|
+
}
|
|
1017
|
+
let cursor = quoteStart + 1;
|
|
1018
|
+
let modulePath = '';
|
|
1019
|
+
while (cursor < end && text[cursor] !== quote) {
|
|
1020
|
+
if (text[cursor] === '\\' && cursor + 1 < end) {
|
|
1021
|
+
// Keep the escaped character (drop the backslash): `\"` denotes a literal
|
|
1022
|
+
// quote in the specifier, so it must stay in the path, not be lost.
|
|
1023
|
+
modulePath += text[cursor + 1];
|
|
1024
|
+
cursor += 2;
|
|
1025
|
+
continue;
|
|
1026
|
+
}
|
|
1027
|
+
modulePath += text[cursor];
|
|
1028
|
+
cursor += 1;
|
|
1029
|
+
}
|
|
1030
|
+
if (text[cursor] !== quote) {
|
|
1031
|
+
return null; // unterminated
|
|
1032
|
+
}
|
|
1033
|
+
return {
|
|
1034
|
+
modulePath,
|
|
1035
|
+
pathStart: quoteStart,
|
|
1036
|
+
pathEnd: cursor + 1
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
pos += 1;
|
|
1040
|
+
}
|
|
1041
|
+
return null;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/** Whether `pos` begins a CSS declaration (a property), not a selector or value. */
|
|
1045
|
+
function atCssDeclarationStart(text, pos) {
|
|
1046
|
+
let index = pos - 1;
|
|
1047
|
+
while (index >= 0 && isWhitespace(text[index])) {
|
|
1048
|
+
index -= 1;
|
|
1049
|
+
}
|
|
1050
|
+
if (index < 0) {
|
|
1051
|
+
return true;
|
|
1052
|
+
}
|
|
1053
|
+
const ch = text[index];
|
|
1054
|
+
return ch === '{' || ch === ';' || ch === '}';
|
|
1055
|
+
}
|
|
1056
|
+
|
|
904
1057
|
// CSS import detector function
|
|
905
1058
|
function detectCssImport(sourceText, pos, cssResult, cssExternals, cssFilePath, positionMapper) {
|
|
906
1059
|
const ch = sourceText[pos];
|
|
@@ -910,46 +1063,52 @@ function detectCssImport(sourceText, pos, cssResult, cssExternals, cssFilePath,
|
|
|
910
1063
|
// Parse the @import statement
|
|
911
1064
|
const importResult = parseCssImportStatement(sourceText, pos);
|
|
912
1065
|
if (importResult.modulePath && importResult.pathStart !== undefined && importResult.pathEnd !== undefined) {
|
|
913
|
-
|
|
914
|
-
// or are scoped npm packages (start with @scope/)
|
|
915
|
-
const hasProtocol = /^https?:\/\//.test(importResult.modulePath);
|
|
916
|
-
const hasHostname = /^\/\//.test(importResult.modulePath);
|
|
917
|
-
const isScopedPackage = /^@[^/]+\//.test(importResult.modulePath);
|
|
918
|
-
const isRelative = !hasProtocol && !hasHostname && !isScopedPackage;
|
|
919
|
-
const position = {
|
|
920
|
-
start: positionMapper(importResult.pathStart),
|
|
921
|
-
end: positionMapper(importResult.pathEnd)
|
|
922
|
-
};
|
|
923
|
-
if (isRelative) {
|
|
924
|
-
// Normalize bare filenames (e.g. "reset.css") to relative paths
|
|
925
|
-
let normalizedPath = importResult.modulePath;
|
|
926
|
-
if (!normalizedPath.startsWith('./') && !normalizedPath.startsWith('../')) {
|
|
927
|
-
normalizedPath = `./${normalizedPath}`;
|
|
928
|
-
}
|
|
929
|
-
const resolvedUrl = resolveRelativeImport(cssFilePath, normalizedPath);
|
|
930
|
-
if (!cssResult[importResult.modulePath]) {
|
|
931
|
-
cssResult[importResult.modulePath] = {
|
|
932
|
-
url: resolvedUrl,
|
|
933
|
-
names: [],
|
|
934
|
-
positions: []
|
|
935
|
-
};
|
|
936
|
-
}
|
|
937
|
-
cssResult[importResult.modulePath].positions.push(position);
|
|
938
|
-
} else {
|
|
939
|
-
if (!cssExternals[importResult.modulePath]) {
|
|
940
|
-
cssExternals[importResult.modulePath] = {
|
|
941
|
-
names: [],
|
|
942
|
-
positions: []
|
|
943
|
-
};
|
|
944
|
-
}
|
|
945
|
-
cssExternals[importResult.modulePath].positions.push(position);
|
|
946
|
-
}
|
|
1066
|
+
recordCssImport(importResult.modulePath, importResult.pathStart, importResult.pathEnd, cssResult, cssExternals, cssFilePath, positionMapper);
|
|
947
1067
|
}
|
|
948
1068
|
return {
|
|
949
1069
|
found: true,
|
|
950
1070
|
nextPos: importResult.nextPos
|
|
951
1071
|
};
|
|
952
1072
|
}
|
|
1073
|
+
|
|
1074
|
+
// Look for `@value <names> from "<path>"` — a cross-file CSS-module value import
|
|
1075
|
+
// (a plain `@value name: value;` definition has no `from` and is left alone).
|
|
1076
|
+
if (ch === '@' && sourceText.slice(pos, pos + 6) === '@value' && isWhitespace(sourceText[pos + 6] || '')) {
|
|
1077
|
+
const stop = findCssStatementEnd(sourceText, pos + 6);
|
|
1078
|
+
const fromClause = parseCssFromClause(sourceText, pos + 6, stop);
|
|
1079
|
+
if (fromClause) {
|
|
1080
|
+
recordCssImport(fromClause.modulePath, fromClause.pathStart, fromClause.pathEnd, cssResult, cssExternals, cssFilePath, positionMapper);
|
|
1081
|
+
return {
|
|
1082
|
+
found: true,
|
|
1083
|
+
nextPos: stop
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
return {
|
|
1087
|
+
found: false,
|
|
1088
|
+
nextPos: pos
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
// Look for `composes: <names> from "<path>"` — a cross-file CSS-module
|
|
1093
|
+
// composition (a same-file `composes: a b;` or `from global` is left alone).
|
|
1094
|
+
if (ch === 'c' && sourceText.slice(pos, pos + 8) === 'composes' && !isIdentifierChar(sourceText[pos + 8] || '') && atCssDeclarationStart(sourceText, pos)) {
|
|
1095
|
+
const colon = skipWhitespace(sourceText, pos + 8);
|
|
1096
|
+
if (sourceText[colon] === ':') {
|
|
1097
|
+
const stop = findCssStatementEnd(sourceText, colon + 1);
|
|
1098
|
+
const fromClause = parseCssFromClause(sourceText, colon + 1, stop);
|
|
1099
|
+
if (fromClause) {
|
|
1100
|
+
recordCssImport(fromClause.modulePath, fromClause.pathStart, fromClause.pathEnd, cssResult, cssExternals, cssFilePath, positionMapper);
|
|
1101
|
+
return {
|
|
1102
|
+
found: true,
|
|
1103
|
+
nextPos: stop
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
return {
|
|
1108
|
+
found: false,
|
|
1109
|
+
nextPos: pos
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
953
1112
|
return {
|
|
954
1113
|
found: false,
|
|
955
1114
|
nextPos: pos
|
|
@@ -1019,6 +1178,16 @@ function parseJSImports(code, filePath, result, externals, isMdxFile, removeComm
|
|
|
1019
1178
|
pos = skipWhitespace(text, pos);
|
|
1020
1179
|
}
|
|
1021
1180
|
|
|
1181
|
+
// Dynamic import: `import('...')`. Step into the parens so its string-literal
|
|
1182
|
+
// specifier is read by the side-effect handling below (a dynamic import has no
|
|
1183
|
+
// bound names, so it's recorded just like a side-effect import). A non-literal
|
|
1184
|
+
// argument — an identifier or a template — is left untouched since it can't be
|
|
1185
|
+
// resolved statically. Skip a leading comment too (e.g. a webpack magic comment)
|
|
1186
|
+
// so the specifier after it is still read.
|
|
1187
|
+
if (pos < textLen && text[pos] === '(') {
|
|
1188
|
+
pos = skipWhitespaceAndComments(text, pos + 1);
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1022
1191
|
// Check if this is a side-effect import (starts with quote)
|
|
1023
1192
|
if (pos < textLen && (text[pos] === '"' || text[pos] === "'")) {
|
|
1024
1193
|
const {
|
|
@@ -1362,12 +1531,85 @@ function detectJavaScriptImport(sourceText, pos, _positionMapper) {
|
|
|
1362
1531
|
};
|
|
1363
1532
|
}
|
|
1364
1533
|
|
|
1365
|
-
// Look for 'import' keyword (not part of an identifier, and not preceded by
|
|
1366
|
-
|
|
1534
|
+
// Look for 'import' keyword (not part of an identifier, and not preceded by `@`
|
|
1535
|
+
// or `.` — the latter would be a member call like `obj.import('./x')`, not a
|
|
1536
|
+
// dynamic import).
|
|
1537
|
+
if (ch === 'i' && sourceText.slice(pos, pos + 6) === 'import' && (pos === 0 || /[^a-zA-Z0-9_$@.]/.test(sourceText[pos - 1])) && /[^a-zA-Z0-9_$]/.test(sourceText[pos + 6] || '')) {
|
|
1367
1538
|
// Mark start of import statement
|
|
1368
1539
|
const importStart = pos;
|
|
1369
1540
|
const len = sourceText.length;
|
|
1370
1541
|
|
|
1542
|
+
// Dynamic import `import(...)`: end the statement at the matching `)`. The
|
|
1543
|
+
// generic statement scan below ends at the next `;` (a dynamic import has no
|
|
1544
|
+
// `from`), which would swallow a LATER `import('./b')` in the same expression
|
|
1545
|
+
// (e.g. a one-lined tab map) and leave it undetected. Closing at `)` lets the
|
|
1546
|
+
// scanner resume and find each one. Parens, strings, templates AND comments are
|
|
1547
|
+
// tracked so a nested paren, the quoted specifier, or a `)`/quote inside a
|
|
1548
|
+
// `/* … */` (e.g. a webpack magic comment or `/* user's tab */`) doesn't end it
|
|
1549
|
+
// early.
|
|
1550
|
+
let parenPos = pos + 6;
|
|
1551
|
+
while (parenPos < len && /\s/.test(sourceText[parenPos] || '')) {
|
|
1552
|
+
parenPos += 1;
|
|
1553
|
+
}
|
|
1554
|
+
if (sourceText[parenPos] === '(') {
|
|
1555
|
+
let depth = 0;
|
|
1556
|
+
let dynState = 'code';
|
|
1557
|
+
let dynQuote = '';
|
|
1558
|
+
let k = parenPos;
|
|
1559
|
+
while (k < len) {
|
|
1560
|
+
const ck = sourceText[k];
|
|
1561
|
+
if (dynState === 'code') {
|
|
1562
|
+
if (ck === '/' && sourceText[k + 1] === '/') {
|
|
1563
|
+
dynState = 'line-comment';
|
|
1564
|
+
k += 2;
|
|
1565
|
+
continue;
|
|
1566
|
+
}
|
|
1567
|
+
if (ck === '/' && sourceText[k + 1] === '*') {
|
|
1568
|
+
dynState = 'block-comment';
|
|
1569
|
+
k += 2;
|
|
1570
|
+
continue;
|
|
1571
|
+
}
|
|
1572
|
+
if (ck === '(') {
|
|
1573
|
+
depth += 1;
|
|
1574
|
+
} else if (ck === ')') {
|
|
1575
|
+
depth -= 1;
|
|
1576
|
+
if (depth === 0) {
|
|
1577
|
+
k += 1;
|
|
1578
|
+
break;
|
|
1579
|
+
}
|
|
1580
|
+
} else if (ck === '"' || ck === "'" || ck === '`') {
|
|
1581
|
+
dynState = ck === '`' ? 'template' : 'string';
|
|
1582
|
+
dynQuote = ck;
|
|
1583
|
+
}
|
|
1584
|
+
} else if (dynState === 'line-comment') {
|
|
1585
|
+
if (ck === '\n') {
|
|
1586
|
+
dynState = 'code';
|
|
1587
|
+
}
|
|
1588
|
+
} else if (dynState === 'block-comment') {
|
|
1589
|
+
if (ck === '*' && sourceText[k + 1] === '/') {
|
|
1590
|
+
dynState = 'code';
|
|
1591
|
+
k += 2;
|
|
1592
|
+
continue;
|
|
1593
|
+
}
|
|
1594
|
+
} else if (ck === '\\') {
|
|
1595
|
+
k += 2;
|
|
1596
|
+
continue;
|
|
1597
|
+
} else if (dynState === 'string' && ck === dynQuote || dynState === 'template' && ck === '`') {
|
|
1598
|
+
dynState = 'code';
|
|
1599
|
+
}
|
|
1600
|
+
k += 1;
|
|
1601
|
+
}
|
|
1602
|
+
return {
|
|
1603
|
+
found: true,
|
|
1604
|
+
nextPos: k,
|
|
1605
|
+
statement: {
|
|
1606
|
+
start: importStart,
|
|
1607
|
+
end: k,
|
|
1608
|
+
text: sourceText.slice(importStart, k)
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1371
1613
|
// Now, scan forward to find the end of the statement (semicolon or proper end for side-effect imports)
|
|
1372
1614
|
let j = pos + 6;
|
|
1373
1615
|
let importState = 'code';
|
|
@@ -1493,16 +1735,18 @@ function detectJavaScriptImport(sourceText, pos, _positionMapper) {
|
|
|
1493
1735
|
* parsed straight out of remote sources without first being mapped onto a
|
|
1494
1736
|
* placeholder `file://` URL.
|
|
1495
1737
|
*
|
|
1738
|
+
* Parsing is fully synchronous — no I/O, no `await`.
|
|
1739
|
+
*
|
|
1496
1740
|
* @param code - The source code to parse
|
|
1497
1741
|
* @param fileUrl - The file URL (`file://`, `http://`, `https://`) or path, used to determine file type and resolve relative imports
|
|
1498
1742
|
* @param options - Optional configuration for comment processing
|
|
1499
1743
|
* @param options.removeCommentsWithPrefix - Array of prefixes; comments starting with these will be stripped from output
|
|
1500
1744
|
* @param options.notableCommentsPrefix - Array of prefixes; comments starting with these will be collected regardless of stripping
|
|
1501
|
-
* @returns
|
|
1745
|
+
* @returns Parsed import data, optionally including processed code and collected comments
|
|
1502
1746
|
*
|
|
1503
1747
|
* @example
|
|
1504
1748
|
* ```typescript
|
|
1505
|
-
* const result =
|
|
1749
|
+
* const result = parseImportsAndComments(
|
|
1506
1750
|
* 'import React from "react";\nimport { Button } from "./Button";\nexport { Icon } from "./Icon";',
|
|
1507
1751
|
* '/src/App.tsx'
|
|
1508
1752
|
* );
|
|
@@ -1511,7 +1755,7 @@ function detectJavaScriptImport(sourceText, pos, _positionMapper) {
|
|
|
1511
1755
|
* // result.relative['./Icon'] contains the Icon re-export
|
|
1512
1756
|
* ```
|
|
1513
1757
|
*/
|
|
1514
|
-
export
|
|
1758
|
+
export function parseImportsAndComments(code, fileUrl, options) {
|
|
1515
1759
|
const result = {};
|
|
1516
1760
|
const externals = {};
|
|
1517
1761
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ImportsAndComments } from "../loaderUtils/index.mjs";
|
|
2
|
+
import type { SplitArguments } from "./parseFunctionArguments.mjs";
|
|
3
3
|
import type { Externals } from "../../CodeHighlighter/types.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* Parse options for create* factory call parsing
|
|
@@ -527,7 +527,7 @@ export async function parseCreateFactoryCall(code, filePath, parseOptions = {},
|
|
|
527
527
|
}
|
|
528
528
|
}
|
|
529
529
|
// Get import mappings from precomputed imports or parse them
|
|
530
|
-
importsAndComments = importsAndComments ||
|
|
530
|
+
importsAndComments = importsAndComments || parseImportsAndComments(code, filePath);
|
|
531
531
|
|
|
532
532
|
// Process the match using shared logic
|
|
533
533
|
const parsed = await processCreateFactoryMatch(match, code, filePath, parseOptions, importsAndComments);
|
|
@@ -566,8 +566,7 @@ export async function parseAllCreateFactoryCalls(code, filePath, parseOptions =
|
|
|
566
566
|
const exportName = exportMatch?.[1] || 'unknown';
|
|
567
567
|
|
|
568
568
|
// Get import mappings from precomputed imports or parse them
|
|
569
|
-
|
|
570
|
-
importsAndComments = importsAndComments || (await parseImportsAndComments(code, filePath));
|
|
569
|
+
importsAndComments = importsAndComments || parseImportsAndComments(code, filePath);
|
|
571
570
|
|
|
572
571
|
// Process the match using shared logic
|
|
573
572
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Code } from "../../CodeHighlighter/types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Detects which live-editing engine chunks a code block will need, by file
|
|
4
|
+
* extension across every variant — so a host can PRELOAD them the moment editing
|
|
5
|
+
* activates (before the first keystroke): `js` when any file is JS/TS/JSX/TSX/MJS
|
|
6
|
+
* (it will be transpiled and built), `css` when any file is CSS (it will be
|
|
7
|
+
* compiled). Reads only file names/keys, never source — cheap and synchronous, so
|
|
8
|
+
* it can run on every render.
|
|
9
|
+
*
|
|
10
|
+
* Bare string variants (no file metadata) and `undefined` variants contribute
|
|
11
|
+
* nothing.
|
|
12
|
+
*/
|
|
13
|
+
export declare function detectFileTypes(code: Code): {
|
|
14
|
+
js: boolean;
|
|
15
|
+
css: boolean;
|
|
16
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Extensions whose files need the transpile + build engine when edited live. */
|
|
2
|
+
const JS_EXTENSIONS = ['.js', '.mjs', '.jsx', '.ts', '.tsx'];
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Detects which live-editing engine chunks a code block will need, by file
|
|
6
|
+
* extension across every variant — so a host can PRELOAD them the moment editing
|
|
7
|
+
* activates (before the first keystroke): `js` when any file is JS/TS/JSX/TSX/MJS
|
|
8
|
+
* (it will be transpiled and built), `css` when any file is CSS (it will be
|
|
9
|
+
* compiled). Reads only file names/keys, never source — cheap and synchronous, so
|
|
10
|
+
* it can run on every render.
|
|
11
|
+
*
|
|
12
|
+
* Bare string variants (no file metadata) and `undefined` variants contribute
|
|
13
|
+
* nothing.
|
|
14
|
+
*/
|
|
15
|
+
export function detectFileTypes(code) {
|
|
16
|
+
let js = false;
|
|
17
|
+
let css = false;
|
|
18
|
+
for (const variant of Object.values(code)) {
|
|
19
|
+
if (!variant || typeof variant === 'string') {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const fileNames = [variant.fileName, ...(variant.extraFiles ? Object.keys(variant.extraFiles) : [])];
|
|
23
|
+
for (const fileName of fileNames) {
|
|
24
|
+
if (!fileName) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (fileName.endsWith('.css')) {
|
|
28
|
+
css = true;
|
|
29
|
+
} else if (JS_EXTENSIONS.some(extension => fileName.endsWith(extension))) {
|
|
30
|
+
js = true;
|
|
31
|
+
}
|
|
32
|
+
if (js && css) {
|
|
33
|
+
return {
|
|
34
|
+
js,
|
|
35
|
+
css
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
js,
|
|
42
|
+
css
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { MetadataToMarkdownOptions, PagesMetadata } from "./metadataToMarkdown.mjs";
|
|
2
2
|
/**
|
|
3
3
|
* Options for mergeMetadataMarkdown
|
|
4
4
|
*/
|
|
@@ -25,6 +25,30 @@ export interface MergeMetadataMarkdownOptions extends Omit<MetadataToMarkdownOpt
|
|
|
25
25
|
*/
|
|
26
26
|
preserveExistingTitleAndSlug?: boolean;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Result of merging new metadata into existing markdown: the normalized
|
|
30
|
+
* `PagesMetadata` that renders to the merged markdown, plus the rendering options
|
|
31
|
+
* needed to reproduce that markdown.
|
|
32
|
+
*/
|
|
33
|
+
export interface MergedMetadataResult {
|
|
34
|
+
/** The normalized pages metadata that renders to the merged markdown. */
|
|
35
|
+
metadata: PagesMetadata;
|
|
36
|
+
/** Effective wrapper component to render with (undefined = no wrapper). */
|
|
37
|
+
indexWrapperComponent?: string;
|
|
38
|
+
/** Editable marker to render with (e.g. the alphabetical-sort marker), if any. */
|
|
39
|
+
editableMarker?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Merges new page metadata with existing markdown content and returns the
|
|
43
|
+
* normalized `PagesMetadata` (and rendering options) without serializing to markdown.
|
|
44
|
+
*
|
|
45
|
+
* This is the in-memory source of truth that {@link mergeMetadataMarkdown} renders.
|
|
46
|
+
* `syncPageIndex` reuses it to pre-populate the page-index cache, so the cached
|
|
47
|
+
* value matches a fresh read of the rendered markdown.
|
|
48
|
+
*
|
|
49
|
+
* See {@link mergeMetadataMarkdown} for the ordering and merge semantics.
|
|
50
|
+
*/
|
|
51
|
+
export declare function mergeMetadataPages(existingMarkdown: string | undefined, newMetadata: PagesMetadata, options?: MergeMetadataMarkdownOptions): Promise<MergedMetadataResult>;
|
|
28
52
|
/**
|
|
29
53
|
* Merges new page metadata with existing markdown content, preserving the order
|
|
30
54
|
* of pages from the existing markdown when available, unless the file contains
|