@mui/internal-docs-infra 0.1.1-canary.9 → 0.2.0-alpha.2

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 (217) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +3 -11
  3. package/esm/CodeControllerContext/CodeControllerContext.d.ts +62 -0
  4. package/esm/CodeControllerContext/CodeControllerContext.js +33 -0
  5. package/esm/CodeControllerContext/index.d.ts +1 -0
  6. package/esm/CodeControllerContext/index.js +1 -0
  7. package/esm/CodeExternalsContext/CodeExternalsContext.d.ts +8 -0
  8. package/esm/CodeExternalsContext/CodeExternalsContext.js +8 -0
  9. package/esm/CodeExternalsContext/index.d.ts +1 -0
  10. package/esm/CodeExternalsContext/index.js +1 -0
  11. package/esm/CodeHighlighter/CodeHighlighter.d.ts +2 -0
  12. package/esm/CodeHighlighter/CodeHighlighter.js +441 -0
  13. package/esm/CodeHighlighter/CodeHighlighterClient.d.ts +2 -0
  14. package/esm/CodeHighlighter/CodeHighlighterClient.js +984 -0
  15. package/esm/CodeHighlighter/CodeHighlighterContext.d.ts +16 -0
  16. package/esm/CodeHighlighter/CodeHighlighterContext.js +15 -0
  17. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +7 -0
  18. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +14 -0
  19. package/esm/CodeHighlighter/addPathsToVariant.d.ts +14 -0
  20. package/esm/CodeHighlighter/addPathsToVariant.js +68 -0
  21. package/esm/CodeHighlighter/applyTransform.d.ts +19 -0
  22. package/esm/CodeHighlighter/applyTransform.js +75 -0
  23. package/esm/CodeHighlighter/calculateMainFilePath.d.ts +1 -0
  24. package/esm/CodeHighlighter/calculateMainFilePath.js +108 -0
  25. package/esm/CodeHighlighter/codeToFallbackProps.d.ts +2 -0
  26. package/esm/CodeHighlighter/codeToFallbackProps.js +73 -0
  27. package/esm/CodeHighlighter/errors.d.ts +141 -0
  28. package/esm/CodeHighlighter/errors.js +441 -0
  29. package/esm/CodeHighlighter/examineVariant.d.ts +25 -0
  30. package/esm/CodeHighlighter/examineVariant.js +73 -0
  31. package/esm/CodeHighlighter/hasAllVariants.d.ts +27 -0
  32. package/esm/CodeHighlighter/hasAllVariants.js +63 -0
  33. package/esm/CodeHighlighter/index.d.ts +1 -0
  34. package/esm/CodeHighlighter/index.js +1 -0
  35. package/esm/CodeHighlighter/loadFallbackCode.d.ts +10 -0
  36. package/esm/CodeHighlighter/loadFallbackCode.js +679 -0
  37. package/esm/CodeHighlighter/loadVariant.d.ts +12 -0
  38. package/esm/CodeHighlighter/loadVariant.js +1044 -0
  39. package/esm/CodeHighlighter/maybeInitialData.d.ts +108 -0
  40. package/esm/CodeHighlighter/maybeInitialData.js +192 -0
  41. package/esm/CodeHighlighter/mergeMetadata.d.ts +40 -0
  42. package/esm/CodeHighlighter/mergeMetadata.js +165 -0
  43. package/esm/CodeHighlighter/parseCode.d.ts +6 -0
  44. package/esm/CodeHighlighter/parseCode.js +134 -0
  45. package/esm/CodeHighlighter/parseControlledCode.d.ts +6 -0
  46. package/esm/CodeHighlighter/parseControlledCode.js +87 -0
  47. package/esm/CodeHighlighter/pathUtils.d.ts +120 -0
  48. package/esm/CodeHighlighter/pathUtils.js +258 -0
  49. package/esm/CodeHighlighter/transformCode.d.ts +21 -0
  50. package/esm/CodeHighlighter/transformCode.js +251 -0
  51. package/esm/CodeHighlighter/transformParsedSource.d.ts +3 -0
  52. package/esm/CodeHighlighter/transformParsedSource.js +60 -0
  53. package/esm/CodeHighlighter/transformSource.d.ts +2 -0
  54. package/esm/CodeHighlighter/transformSource.js +103 -0
  55. package/esm/CodeHighlighter/types.d.ts +276 -0
  56. package/esm/CodeHighlighter/types.js +1 -0
  57. package/esm/CodeProvider/CodeContext.d.ts +31 -0
  58. package/esm/CodeProvider/CodeContext.js +12 -0
  59. package/esm/CodeProvider/CodeProvider.d.ts +13 -0
  60. package/esm/CodeProvider/CodeProvider.js +83 -0
  61. package/esm/CodeProvider/index.d.ts +1 -0
  62. package/esm/CodeProvider/index.js +1 -0
  63. package/esm/abstractCreateDemo/abstractCreateDemo.d.ts +45 -0
  64. package/esm/abstractCreateDemo/abstractCreateDemo.js +100 -0
  65. package/esm/abstractCreateDemo/index.d.ts +1 -0
  66. package/esm/abstractCreateDemo/index.js +1 -0
  67. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.d.ts +32 -0
  68. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +52 -0
  69. package/esm/abstractCreateDemoClient/index.d.ts +1 -0
  70. package/esm/abstractCreateDemoClient/index.js +1 -0
  71. package/esm/createDemoData/createDemoData.d.ts +44 -0
  72. package/esm/createDemoData/createDemoData.js +74 -0
  73. package/esm/createDemoData/index.d.ts +1 -0
  74. package/esm/createDemoData/index.js +1 -0
  75. package/esm/createDemoData/types.d.ts +25 -0
  76. package/esm/createDemoData/types.js +1 -0
  77. package/esm/pipeline/hastUtils/hastUtils.d.ts +11 -0
  78. package/esm/pipeline/hastUtils/hastUtils.js +67 -0
  79. package/esm/pipeline/hastUtils/index.d.ts +1 -0
  80. package/esm/pipeline/hastUtils/index.js +1 -0
  81. package/esm/pipeline/loadPrecomputedCodeHighlighter/index.d.ts +2 -0
  82. package/esm/pipeline/loadPrecomputedCodeHighlighter/index.js +4 -0
  83. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +14 -0
  84. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +178 -0
  85. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +47 -0
  86. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +849 -0
  87. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.d.ts +85 -0
  88. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +715 -0
  89. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +14 -0
  90. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +73 -0
  91. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.d.ts +11 -0
  92. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +203 -0
  93. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.d.ts +6 -0
  94. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +23 -0
  95. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.d.ts +6 -0
  96. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +148 -0
  97. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.d.ts +9 -0
  98. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +198 -0
  99. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.d.ts +2 -0
  100. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.js +4 -0
  101. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.d.ts +5 -0
  102. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +21 -0
  103. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.d.ts +15 -0
  104. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +233 -0
  105. package/esm/pipeline/loadServerCodeMeta/index.d.ts +1 -0
  106. package/esm/pipeline/loadServerCodeMeta/index.js +1 -0
  107. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +24 -0
  108. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +90 -0
  109. package/esm/pipeline/loadServerSource/index.d.ts +1 -0
  110. package/esm/pipeline/loadServerSource/index.js +1 -0
  111. package/esm/pipeline/loadServerSource/loadServerSource.d.ts +25 -0
  112. package/esm/pipeline/loadServerSource/loadServerSource.js +134 -0
  113. package/esm/pipeline/loaderUtils/externalsToPackages.d.ts +1 -0
  114. package/esm/pipeline/loaderUtils/externalsToPackages.js +46 -0
  115. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.d.ts +34 -0
  116. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +161 -0
  117. package/esm/pipeline/loaderUtils/getFileNameFromUrl.d.ts +12 -0
  118. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +66 -0
  119. package/esm/pipeline/loaderUtils/index.d.ts +7 -0
  120. package/esm/pipeline/loaderUtils/index.js +7 -0
  121. package/esm/pipeline/loaderUtils/mergeExternals.d.ts +32 -0
  122. package/esm/pipeline/loaderUtils/mergeExternals.js +72 -0
  123. package/esm/pipeline/loaderUtils/parseImports.d.ts +19 -0
  124. package/esm/pipeline/loaderUtils/parseImports.js +306 -0
  125. package/esm/pipeline/loaderUtils/processRelativeImports.d.ts +19 -0
  126. package/esm/pipeline/loaderUtils/processRelativeImports.js +352 -0
  127. package/esm/pipeline/loaderUtils/resolveModulePath.d.ts +87 -0
  128. package/esm/pipeline/loaderUtils/resolveModulePath.js +1435 -0
  129. package/esm/pipeline/loaderUtils/resolveModulePathWithFs.d.ts +47 -0
  130. package/esm/pipeline/loaderUtils/resolveModulePathWithFs.js +150 -0
  131. package/esm/pipeline/loaderUtils/rewriteImports.d.ts +9 -0
  132. package/esm/pipeline/loaderUtils/rewriteImports.js +35 -0
  133. package/esm/pipeline/parseSource/addLineGutters.d.ts +9 -0
  134. package/esm/pipeline/parseSource/addLineGutters.js +181 -0
  135. package/esm/pipeline/parseSource/grammars.d.ts +2 -0
  136. package/esm/pipeline/parseSource/grammars.js +27 -0
  137. package/esm/pipeline/parseSource/index.d.ts +1 -0
  138. package/esm/pipeline/parseSource/index.js +1 -0
  139. package/esm/pipeline/parseSource/parseSource.d.ts +3 -0
  140. package/esm/pipeline/parseSource/parseSource.js +51 -0
  141. package/esm/pipeline/transformHtmlCode/index.d.ts +2 -0
  142. package/esm/pipeline/transformHtmlCode/index.js +4 -0
  143. package/esm/pipeline/transformHtmlCode/transformHtmlCode.d.ts +13 -0
  144. package/esm/pipeline/transformHtmlCode/transformHtmlCode.js +300 -0
  145. package/esm/pipeline/transformMarkdownCode/index.d.ts +2 -0
  146. package/esm/pipeline/transformMarkdownCode/index.js +4 -0
  147. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.d.ts +2 -0
  148. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +514 -0
  149. package/esm/pipeline/transformTypescriptToJavascript/index.d.ts +1 -0
  150. package/esm/pipeline/transformTypescriptToJavascript/index.js +1 -0
  151. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.d.ts +13 -0
  152. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +131 -0
  153. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.d.ts +3 -0
  154. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +31 -0
  155. package/esm/useCode/Pre.d.ts +15 -0
  156. package/esm/useCode/Pre.js +164 -0
  157. package/esm/useCode/index.d.ts +1 -0
  158. package/esm/useCode/index.js +1 -0
  159. package/esm/useCode/useCode.d.ts +41 -0
  160. package/esm/useCode/useCode.js +128 -0
  161. package/esm/useCode/useCodeUtils.d.ts +44 -0
  162. package/esm/useCode/useCodeUtils.js +245 -0
  163. package/esm/useCode/useCopyFunctionality.d.ts +18 -0
  164. package/esm/useCode/useCopyFunctionality.js +28 -0
  165. package/esm/useCode/useFileNavigation.d.ts +41 -0
  166. package/esm/useCode/useFileNavigation.js +453 -0
  167. package/esm/useCode/useSourceEditing.d.ts +21 -0
  168. package/esm/useCode/useSourceEditing.js +32 -0
  169. package/esm/useCode/useTransformManagement.d.ts +30 -0
  170. package/esm/useCode/useTransformManagement.js +72 -0
  171. package/esm/useCode/useUIState.d.ts +16 -0
  172. package/esm/useCode/useUIState.js +21 -0
  173. package/esm/useCode/useVariantSelection.d.ts +23 -0
  174. package/esm/useCode/useVariantSelection.js +75 -0
  175. package/esm/useCopier/index.d.ts +1 -1
  176. package/esm/useCopier/index.js +5 -5
  177. package/esm/useDemo/createCodeSandbox.d.ts +15 -0
  178. package/esm/useDemo/createCodeSandbox.js +42 -0
  179. package/esm/useDemo/createStackBlitz.d.ts +22 -0
  180. package/esm/useDemo/createStackBlitz.js +38 -0
  181. package/esm/useDemo/exportVariant.d.ts +184 -0
  182. package/esm/useDemo/exportVariant.js +422 -0
  183. package/esm/useDemo/exportVariantAsCra.d.ts +15 -0
  184. package/esm/useDemo/exportVariantAsCra.js +57 -0
  185. package/esm/useDemo/flattenVariant.d.ts +19 -0
  186. package/esm/useDemo/flattenVariant.js +49 -0
  187. package/esm/useDemo/index.d.ts +6 -51
  188. package/esm/useDemo/index.js +6 -104
  189. package/esm/useDemo/useDemo.d.ts +81 -0
  190. package/esm/useDemo/useDemo.js +193 -0
  191. package/esm/useErrors/ErrorsContext.d.ts +6 -0
  192. package/esm/useErrors/ErrorsContext.js +8 -0
  193. package/esm/useErrors/index.d.ts +1 -0
  194. package/esm/useErrors/index.js +1 -0
  195. package/esm/useErrors/useErrors.d.ts +5 -0
  196. package/esm/useErrors/useErrors.js +7 -0
  197. package/esm/useLocalStorageState/index.d.ts +2 -0
  198. package/esm/useLocalStorageState/index.js +2 -0
  199. package/esm/useLocalStorageState/useLocalStorageState.d.ts +14 -0
  200. package/esm/useLocalStorageState/useLocalStorageState.js +128 -0
  201. package/esm/usePreference/PreferencesProvider.d.ts +6 -0
  202. package/esm/usePreference/PreferencesProvider.js +8 -0
  203. package/esm/usePreference/index.d.ts +2 -0
  204. package/esm/usePreference/index.js +2 -0
  205. package/esm/usePreference/usePreference.d.ts +2 -0
  206. package/esm/usePreference/usePreference.js +25 -0
  207. package/esm/useUrlHashState/index.d.ts +1 -0
  208. package/esm/useUrlHashState/index.js +1 -0
  209. package/esm/useUrlHashState/useUrlHashState.d.ts +5 -0
  210. package/esm/useUrlHashState/useUrlHashState.js +68 -0
  211. package/esm/withDocsInfra/index.d.ts +1 -0
  212. package/esm/withDocsInfra/index.js +1 -0
  213. package/esm/withDocsInfra/withDocsInfra.d.ts +82 -0
  214. package/esm/withDocsInfra/withDocsInfra.js +147 -0
  215. package/package.json +178 -11
  216. package/esm/useCopier/index.d.ts.map +0 -1
  217. package/esm/useDemo/index.d.ts.map +0 -1
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ import { Code, ControlledCode } from "./types.js";
3
+ import { Selection } from "../CodeControllerContext/index.js";
4
+ export interface CodeHighlighterContextType {
5
+ code?: Code;
6
+ setCode?: React.Dispatch<React.SetStateAction<ControlledCode | undefined>>;
7
+ selection?: Selection;
8
+ setSelection?: React.Dispatch<React.SetStateAction<Selection>>;
9
+ components?: Record<string, React.ReactNode>;
10
+ availableTransforms?: string[];
11
+ url?: string;
12
+ deferHighlight?: boolean;
13
+ }
14
+ export declare const CodeHighlighterContext: React.Context<CodeHighlighterContextType | undefined>;
15
+ export declare function useCodeHighlighterContext(): CodeHighlighterContextType;
16
+ export declare function useCodeHighlighterContextOptional(): CodeHighlighterContextType | undefined;
@@ -0,0 +1,15 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ export var CodeHighlighterContext = /*#__PURE__*/React.createContext(undefined);
5
+ if (process.env.NODE_ENV !== "production") CodeHighlighterContext.displayName = "CodeHighlighterContext";
6
+ export function useCodeHighlighterContext() {
7
+ var context = React.useContext(CodeHighlighterContext);
8
+ if (context === undefined) {
9
+ throw new Error('CodeHighlighterContext is missing. `useCodeHighlighterContext` must be used within a `CodeHighlighter` component.');
10
+ }
11
+ return context;
12
+ }
13
+ export function useCodeHighlighterContextOptional() {
14
+ return React.useContext(CodeHighlighterContext);
15
+ }
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import { ContentLoadingVariant } from "./types.js";
3
+ export interface CodeHighlighterFallbackContext extends ContentLoadingVariant {
4
+ extraVariants?: Record<string, ContentLoadingVariant>;
5
+ }
6
+ export declare const CodeHighlighterFallbackContext: React.Context<CodeHighlighterFallbackContext | undefined>;
7
+ export declare function useCodeHighlighterFallbackContext(): CodeHighlighterFallbackContext;
@@ -0,0 +1,14 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ export var CodeHighlighterFallbackContext = /*#__PURE__*/React.createContext(undefined);
5
+ if (process.env.NODE_ENV !== "production") CodeHighlighterFallbackContext.displayName = "CodeHighlighterFallbackContext";
6
+ export function useCodeHighlighterFallbackContext() {
7
+ var context = React.useContext(CodeHighlighterFallbackContext);
8
+ if (context === undefined) {
9
+ throw new Error('CodeHighlighterFallbackContext is missing. `useCodeHighlighterFallbackContext` must be used within a `CodeHighlighter` component.');
10
+ }
11
+ return context;
12
+ }
13
+
14
+ // TODO: rename to ContentMinimal
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Add path utility to add path property to each file in a variant
3
+ * Uses calculateMainFilePath utility and URL resolution for simplified path calculation
4
+ */
5
+ import type { VariantCode, VariantSource } from "./types.js";
6
+ export interface FileWithPath {
7
+ source?: VariantSource;
8
+ metadata?: boolean;
9
+ path: string;
10
+ }
11
+ /**
12
+ * Add flat paths to all files in a variant
13
+ */
14
+ export declare function addPathsToVariant(variant: VariantCode): VariantCode;
@@ -0,0 +1,68 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ /**
4
+ * Add path utility to add path property to each file in a variant
5
+ * Uses calculateMainFilePath utility and URL resolution for simplified path calculation
6
+ */
7
+
8
+ import { calculateMaxBackNavigation, createSyntheticDirectories } from "./pathUtils.js";
9
+ import { calculateMainFilePath } from "./calculateMainFilePath.js";
10
+ /**
11
+ * Add flat paths to all files in a variant
12
+ */
13
+ export function addPathsToVariant(variant) {
14
+ var url = variant.url || '';
15
+ var fileName = variant.fileName || '';
16
+
17
+ // Calculate actual back navigation needed based on extraFiles
18
+ var backNavResult = variant.extraFiles ? calculateMaxBackNavigation(variant.extraFiles) : {
19
+ maxBackNavigation: 0,
20
+ maxSourceBackNavigation: 0
21
+ };
22
+
23
+ // Create a synthetic URL for variants without URL to ensure consistent processing
24
+ var effectiveUrl = url;
25
+ if (!url && fileName) {
26
+ effectiveUrl = "file:///".concat(fileName);
27
+ }
28
+
29
+ // Calculate main file path using only the back navigation needed by source files
30
+ var mainFileUrl = effectiveUrl ? calculateMainFilePath(effectiveUrl, backNavResult.maxBackNavigation, backNavResult.maxSourceBackNavigation, variant.metadataPrefix, fileName || undefined // Only pass fileName if it's not empty
31
+ ) : undefined;
32
+
33
+ // Extract just the path part from the file:// URL and remove leading slash
34
+ var path = mainFileUrl ? new URL(mainFileUrl).pathname.slice(1) : undefined;
35
+ return _extends(_extends({}, variant), {}, {
36
+ path: path,
37
+ extraFiles: calculateExtraFilesPaths(variant.extraFiles, mainFileUrl || "file:///".concat(backNavResult.maxBackNavigation > 0 ? "".concat(createSyntheticDirectories(backNavResult.maxBackNavigation).join('/'), "/") : '', "temp.txt"))
38
+ });
39
+ }
40
+
41
+ /**
42
+ * Calculate paths for all extra files using the same logic as the main file
43
+ */
44
+ function calculateExtraFilesPaths(extraFiles, mainFileUrl) {
45
+ if (!extraFiles) {
46
+ return undefined;
47
+ }
48
+ var result = {};
49
+ for (var _i = 0, _Object$entries = Object.entries(extraFiles); _i < _Object$entries.length; _i++) {
50
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
51
+ relativePath = _Object$entries$_i[0],
52
+ fileContent = _Object$entries$_i[1];
53
+ // Resolve the relative path against the main file URL
54
+ try {
55
+ var resolvedUrl = new URL(relativePath, mainFileUrl);
56
+ var file = typeof fileContent === 'string' ? {
57
+ source: fileContent
58
+ } : fileContent;
59
+ result[relativePath] = _extends(_extends({}, file), {}, {
60
+ path: resolvedUrl.pathname.slice(1)
61
+ });
62
+ } catch (_unused) {
63
+ // If URL resolution fails, skip this file
64
+ continue;
65
+ }
66
+ }
67
+ return _extends(_extends({}, extraFiles), result);
68
+ }
@@ -0,0 +1,19 @@
1
+ import type { VariantSource, Transforms } from "./types.js";
2
+ /**
3
+ * Applies a specific transform to a variant source and returns the transformed source
4
+ * @param source - The original variant source (string, HastNodes, or hastJson object)
5
+ * @param transforms - Object containing all available transforms
6
+ * @param transformKey - The key of the specific transform to apply
7
+ * @returns The transformed variant source in the same format as the input
8
+ * @throws Error if the transform key doesn't exist or patching fails
9
+ */
10
+ export declare function applyTransform(source: VariantSource, transforms: Transforms, transformKey: string): VariantSource;
11
+ /**
12
+ * Applies multiple transforms to a variant source in sequence
13
+ * @param source - The original variant source
14
+ * @param transforms - Object containing all available transforms
15
+ * @param transformKeys - Array of transform keys to apply in order
16
+ * @returns The transformed variant source in the same format as the input
17
+ * @throws Error if any transform key doesn't exist or patching fails
18
+ */
19
+ export declare function applyTransforms(source: VariantSource, transforms: Transforms, transformKeys: string[]): VariantSource;
@@ -0,0 +1,75 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
+ import { patch, clone } from 'jsondiffpatch';
3
+ /**
4
+ * Applies a specific transform to a variant source and returns the transformed source
5
+ * @param source - The original variant source (string, HastNodes, or hastJson object)
6
+ * @param transforms - Object containing all available transforms
7
+ * @param transformKey - The key of the specific transform to apply
8
+ * @returns The transformed variant source in the same format as the input
9
+ * @throws Error if the transform key doesn't exist or patching fails
10
+ */
11
+ export function applyTransform(source, transforms, transformKey) {
12
+ var transform = transforms[transformKey];
13
+ if (!transform) {
14
+ throw new Error("Transform \"".concat(transformKey, "\" not found in transforms"));
15
+ }
16
+
17
+ // Determine the format of the source and apply the appropriate transform strategy
18
+ if (typeof source === 'string') {
19
+ // For string sources, deltas are typically line-array based (from transformSource)
20
+ var sourceLines = source.split('\n');
21
+ var patched = patch(sourceLines, transform.delta);
22
+ if (!Array.isArray(patched)) {
23
+ throw new Error("Patch for transform \"".concat(transformKey, "\" did not return an array"));
24
+ }
25
+ return patched.join('\n');
26
+ }
27
+
28
+ // For Hast node sources, deltas are typically node-based (from transformParsedSource)
29
+ var sourceRoot;
30
+ var isHastJson = 'hastJson' in source;
31
+ if (isHastJson) {
32
+ sourceRoot = JSON.parse(source.hastJson);
33
+ } else {
34
+ sourceRoot = source;
35
+ }
36
+
37
+ // Apply the node-based delta
38
+ var patchedNodes = patch(clone(sourceRoot), transform.delta);
39
+ if (!patchedNodes) {
40
+ throw new Error("Patch for transform \"".concat(transformKey, "\" returned null/undefined"));
41
+ }
42
+
43
+ // Return in the same format as the input
44
+ if (isHastJson) {
45
+ return {
46
+ hastJson: JSON.stringify(patchedNodes)
47
+ };
48
+ }
49
+ return patchedNodes;
50
+ }
51
+
52
+ /**
53
+ * Applies multiple transforms to a variant source in sequence
54
+ * @param source - The original variant source
55
+ * @param transforms - Object containing all available transforms
56
+ * @param transformKeys - Array of transform keys to apply in order
57
+ * @returns The transformed variant source in the same format as the input
58
+ * @throws Error if any transform key doesn't exist or patching fails
59
+ */
60
+ export function applyTransforms(source, transforms, transformKeys) {
61
+ var currentSource = source;
62
+ var _iterator = _createForOfIteratorHelper(transformKeys),
63
+ _step;
64
+ try {
65
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
66
+ var transformKey = _step.value;
67
+ currentSource = applyTransform(currentSource, transforms, transformKey);
68
+ }
69
+ } catch (err) {
70
+ _iterator.e(err);
71
+ } finally {
72
+ _iterator.f();
73
+ }
74
+ return currentSource;
75
+ }
@@ -0,0 +1 @@
1
+ export declare function calculateMainFilePath(url: string, maxBackNav: number, maxSourceBackNav?: number, metadataPrefix?: string, fileName?: string): string;
@@ -0,0 +1,108 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import { createSyntheticDirectories, buildPath } from './pathUtils.js';
3
+ export function calculateMainFilePath(url, maxBackNav, maxSourceBackNav, metadataPrefix, fileName) {
4
+ // Handle optional parameters with defaults
5
+ var actualMaxSourceBackNav = maxSourceBackNav != null ? maxSourceBackNav : maxBackNav;
6
+ var actualMetadataPrefix = metadataPrefix != null ? metadataPrefix : '';
7
+
8
+ // Handle empty URL
9
+ if (!url) {
10
+ return '';
11
+ }
12
+
13
+ // Extract URL parts and filename
14
+ var urlSegments;
15
+ var filename;
16
+ var hasTrailingSlash = false;
17
+ try {
18
+ // Try to parse as URL first
19
+ var urlObj = new URL(url);
20
+ hasTrailingSlash = urlObj.pathname.endsWith('/');
21
+ var pathSegments = urlObj.pathname.split('/').filter(Boolean);
22
+ var baseFilename;
23
+ if (hasTrailingSlash) {
24
+ // If URL ends with /, there's no filename - all segments are path segments
25
+ baseFilename = '';
26
+ urlSegments = pathSegments;
27
+ } else {
28
+ // Normal case - last segment is the filename
29
+ baseFilename = pathSegments.pop() || '';
30
+ urlSegments = pathSegments;
31
+ }
32
+
33
+ // Use provided fileName or preserve query and hash from URL
34
+ if (fileName !== undefined) {
35
+ filename = fileName;
36
+ } else {
37
+ filename = baseFilename + urlObj.search + urlObj.hash;
38
+ if (hasTrailingSlash && !baseFilename) {
39
+ filename = "".concat(filename, "/");
40
+ }
41
+ }
42
+ } catch (_unused) {
43
+ // Fallback to simple string parsing for relative paths
44
+ hasTrailingSlash = url.endsWith('/');
45
+ var urlParts = url.split('/');
46
+ var _baseFilename;
47
+ if (hasTrailingSlash) {
48
+ // If URL ends with /, there's no filename - all segments are path segments
49
+ _baseFilename = urlParts.pop() || ''; // Remove the empty string after trailing slash
50
+ urlSegments = urlParts.filter(function (part) {
51
+ return part !== '';
52
+ }); // Remove empty segments
53
+ } else {
54
+ // Normal case - last segment is the filename
55
+ _baseFilename = urlParts.pop() || '';
56
+ urlSegments = urlParts.filter(function (part) {
57
+ return part !== '';
58
+ }); // Remove empty segments
59
+ }
60
+
61
+ // Use provided fileName or fallback to extracted baseFilename
62
+ if (fileName !== undefined) {
63
+ filename = fileName;
64
+ } else {
65
+ filename = _baseFilename;
66
+ if (hasTrailingSlash && !_baseFilename) {
67
+ filename = "".concat(filename, "/");
68
+ }
69
+ }
70
+ }
71
+
72
+ // Work with a copy of URL segments to avoid mutations
73
+ var remainingUrlSegments = _toConsumableArray(urlSegments);
74
+
75
+ // Take actualMaxSourceBackNav items from the end for sourcePath
76
+ var sourcePath = remainingUrlSegments.splice(-actualMaxSourceBackNav, actualMaxSourceBackNav);
77
+
78
+ // Calculate unhandledBackNav, accounting for missing sourcePath segments
79
+ var unhandledBackNav = maxBackNav - actualMaxSourceBackNav;
80
+
81
+ // Add any missing sourcePath segments to unhandledBackNav
82
+ var missingSourcePathSegments = actualMaxSourceBackNav - sourcePath.length;
83
+ unhandledBackNav += missingSourcePathSegments;
84
+
85
+ // Split actualMetadataPrefix and subtract that count from unhandledBackNav
86
+ var metadataPrefixSegments = actualMetadataPrefix.split('/').filter(function (part) {
87
+ return part !== '';
88
+ });
89
+ unhandledBackNav -= metadataPrefixSegments.length;
90
+
91
+ // Calculate metadataPath from remaining URL segments (what's left after sourcePath)
92
+ var metadataSegmentsNeeded = Math.max(0, unhandledBackNav);
93
+ var metadataSegmentsAvailable = Math.min(metadataSegmentsNeeded, remainingUrlSegments.length);
94
+ var metadataPath = remainingUrlSegments.splice(-metadataSegmentsAvailable, metadataSegmentsAvailable);
95
+
96
+ // Update unhandledBackNav with segments we couldn't fulfill from URL
97
+ unhandledBackNav = metadataSegmentsNeeded - metadataSegmentsAvailable;
98
+
99
+ // Create synthetic directories for any remaining unhandledBackNav
100
+ var syntheticDirs = createSyntheticDirectories(unhandledBackNav);
101
+
102
+ // Combine all parts to create the final path using buildPath utility
103
+ // Order: [synthetic directories] + [metadataPath] + [metadataPrefix] + [sourcePath] + [filename]
104
+ var path = buildPath(syntheticDirs, metadataPath, metadataPrefixSegments, sourcePath, filename);
105
+
106
+ // Return as file:// URL unless the result is empty
107
+ return path ? "file:///".concat(path) : path;
108
+ }
@@ -0,0 +1,2 @@
1
+ import { BaseContentLoadingProps, Code } from "./types.js";
2
+ export declare function codeToFallbackProps(variant: string, code?: Code, fileName?: string, needsAllFiles?: boolean, needsAllVariants?: boolean): BaseContentLoadingProps;
@@ -0,0 +1,73 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import { stringOrHastToJsx } from "../pipeline/hastUtils/index.js";
5
+ function toExtraSource(variantCode, fileName) {
6
+ return Object.entries(variantCode.extraFiles || {}).reduce(function (acc, _ref) {
7
+ var _ref2 = _slicedToArray(_ref, 2),
8
+ name = _ref2[0],
9
+ file = _ref2[1];
10
+ if (name !== fileName && _typeof(file) === 'object' && file != null && file.source) {
11
+ acc[name] = stringOrHastToJsx(file.source);
12
+ }
13
+ return acc;
14
+ }, {});
15
+ }
16
+ export function codeToFallbackProps(variant, code, fileName) {
17
+ var needsAllFiles = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
18
+ var needsAllVariants = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
19
+ var variantCode = code == null ? void 0 : code[variant];
20
+ if (!variantCode || typeof variantCode === 'string') {
21
+ return {};
22
+ }
23
+ var fileNames = [variantCode.fileName].concat(_toConsumableArray(Object.keys(variantCode.extraFiles || {}))).filter(function (name) {
24
+ return Boolean(name);
25
+ });
26
+ var source;
27
+ if (fileName && fileName !== variantCode.fileName) {
28
+ var _variantCode$extraFil;
29
+ var fileData = (_variantCode$extraFil = variantCode.extraFiles) == null ? void 0 : _variantCode$extraFil[fileName];
30
+ if (fileData && _typeof(fileData) === 'object' && 'source' in fileData && fileData.source) {
31
+ source = stringOrHastToJsx(fileData.source);
32
+ }
33
+ } else if (variantCode.source) {
34
+ source = stringOrHastToJsx(variantCode.source);
35
+ }
36
+ if (needsAllVariants || needsAllFiles) {
37
+ var extraSource = toExtraSource(variantCode, fileName);
38
+ if (needsAllVariants) {
39
+ var extraVariants = Object.entries(code || {}).reduce(function (acc, _ref3) {
40
+ var _ref4 = _slicedToArray(_ref3, 2),
41
+ name = _ref4[0],
42
+ vCode = _ref4[1];
43
+ if (name !== variant && vCode && typeof vCode !== 'string') {
44
+ var extraVariantExtraSource = toExtraSource(vCode, vCode.fileName);
45
+ acc[name] = {
46
+ fileNames: [vCode.fileName].concat(_toConsumableArray(Object.keys(vCode.extraFiles || {}))).filter(function (fn) {
47
+ return Boolean(fn);
48
+ }),
49
+ // TODO: use filesOrder if provided
50
+ source: vCode.source && stringOrHastToJsx(vCode.source),
51
+ extraSource: extraVariantExtraSource
52
+ };
53
+ }
54
+ return acc;
55
+ }, {});
56
+ return {
57
+ fileNames: fileNames,
58
+ source: source,
59
+ extraSource: extraSource,
60
+ extraVariants: extraVariants
61
+ };
62
+ }
63
+ return {
64
+ fileNames: fileNames,
65
+ source: source,
66
+ extraSource: extraSource
67
+ };
68
+ }
69
+ return {
70
+ fileNames: fileNames,
71
+ source: source
72
+ };
73
+ }
@@ -0,0 +1,141 @@
1
+ export declare class ErrorCodeHighlighter extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare class ErrorCodeHighlighterServer extends ErrorCodeHighlighter {
5
+ constructor(message: string);
6
+ }
7
+ export declare class ErrorCodeHighlighterClient extends ErrorCodeHighlighter {
8
+ constructor(message: string);
9
+ }
10
+ export declare class ErrorCodeHighlighterServerConfiguration extends ErrorCodeHighlighterServer {
11
+ constructor(message: string);
12
+ }
13
+ export declare class ErrorCodeHighlighterServerLoader extends ErrorCodeHighlighterServer {
14
+ constructor(message: string);
15
+ }
16
+ export declare class ErrorCodeHighlighterServerValidation extends ErrorCodeHighlighterServer {
17
+ constructor(message: string);
18
+ }
19
+ export declare class ErrorCodeHighlighterClientConfiguration extends ErrorCodeHighlighterClient {
20
+ constructor(message: string);
21
+ }
22
+ export declare class ErrorCodeHighlighterClientLoader extends ErrorCodeHighlighterClient {
23
+ constructor(message: string);
24
+ }
25
+ export declare class ErrorCodeHighlighterClientValidation extends ErrorCodeHighlighterClient {
26
+ constructor(message: string);
27
+ }
28
+ export declare class ErrorCodeHighlighterClientProvider extends ErrorCodeHighlighterClient {
29
+ constructor(message: string);
30
+ }
31
+ export declare class ErrorCodeHighlighterServerMissingLoadCodeMeta extends ErrorCodeHighlighterServerConfiguration {
32
+ constructor(context?: string);
33
+ }
34
+ export declare class ErrorCodeHighlighterServerMissingLoadCodeMetaForGlobals extends ErrorCodeHighlighterServerConfiguration {
35
+ constructor();
36
+ }
37
+ export declare class ErrorCodeHighlighterServerMissingUrl extends ErrorCodeHighlighterServerValidation {
38
+ constructor(context?: string);
39
+ }
40
+ export declare class ErrorCodeHighlighterServerMissingUrlForLoadCodeMeta extends ErrorCodeHighlighterServerValidation {
41
+ constructor();
42
+ }
43
+ export declare class ErrorCodeHighlighterServerInvalidProps extends ErrorCodeHighlighterServerValidation {
44
+ constructor();
45
+ }
46
+ export declare class ErrorCodeHighlighterServerMissingData extends ErrorCodeHighlighterServerValidation {
47
+ constructor();
48
+ }
49
+ export declare class ErrorCodeHighlighterServerMissingVariant extends ErrorCodeHighlighterServerValidation {
50
+ constructor(variantName: string);
51
+ }
52
+ export declare class ErrorCodeHighlighterServerMissingFileName extends ErrorCodeHighlighterServerValidation {
53
+ constructor(variantName: string);
54
+ }
55
+ export declare class ErrorCodeHighlighterServerMissingContentLoading extends ErrorCodeHighlighterServerConfiguration {
56
+ constructor();
57
+ }
58
+ export declare class ErrorCodeHighlighterServerInvalidClientMode extends ErrorCodeHighlighterServerValidation {
59
+ constructor();
60
+ }
61
+ export declare class ErrorCodeHighlighterServerLoadCodeFailure extends ErrorCodeHighlighterServerLoader {
62
+ constructor(url: string, error: any);
63
+ }
64
+ export declare class ErrorCodeHighlighterServerLoadGlobalsFailure extends ErrorCodeHighlighterServerLoader {
65
+ constructor(url: string, error: any);
66
+ }
67
+ export declare class ErrorCodeHighlighterServerLoadVariantsFailure extends ErrorCodeHighlighterServerLoader {
68
+ constructor(url: string, errors: Error[]);
69
+ }
70
+ export declare class ErrorCodeHighlighterClientMissingLoadFallbackCode extends ErrorCodeHighlighterClientProvider {
71
+ constructor(url?: string);
72
+ }
73
+ export declare class ErrorCodeHighlighterClientMissingLoadVariant extends ErrorCodeHighlighterClientProvider {
74
+ constructor(url?: string);
75
+ }
76
+ export declare class ErrorCodeHighlighterClientMissingLoadCodeMeta extends ErrorCodeHighlighterClientProvider {
77
+ constructor(context?: string);
78
+ }
79
+ export declare class ErrorCodeHighlighterClientMissingLoadCodeMetaForNoCode extends ErrorCodeHighlighterClientProvider {
80
+ constructor(url?: string);
81
+ }
82
+ export declare class ErrorCodeHighlighterClientMissingLoadCodeMetaForGlobals extends ErrorCodeHighlighterClientProvider {
83
+ constructor();
84
+ }
85
+ export declare class ErrorCodeHighlighterClientMissingLoadCodeMetaForStringUrls extends ErrorCodeHighlighterClientProvider {
86
+ constructor();
87
+ }
88
+ export declare class ErrorCodeHighlighterClientMissingLoadSource extends ErrorCodeHighlighterClientProvider {
89
+ constructor(context?: string);
90
+ }
91
+ export declare class ErrorCodeHighlighterClientMissingLoadSourceForNoCode extends ErrorCodeHighlighterClientProvider {
92
+ constructor();
93
+ }
94
+ export declare class ErrorCodeHighlighterClientMissingLoadSourceForUnloadedUrls extends ErrorCodeHighlighterClientProvider {
95
+ constructor();
96
+ }
97
+ export declare class ErrorCodeHighlighterClientMissingUrl extends ErrorCodeHighlighterClientValidation {
98
+ constructor(context?: string);
99
+ }
100
+ export declare class ErrorCodeHighlighterClientMissingUrlForFallback extends ErrorCodeHighlighterClientValidation {
101
+ constructor();
102
+ }
103
+ export declare class ErrorCodeHighlighterClientMissingUrlForVariants extends ErrorCodeHighlighterClientValidation {
104
+ constructor();
105
+ }
106
+ export declare class ErrorCodeHighlighterClientMissingData extends ErrorCodeHighlighterClientValidation {
107
+ constructor();
108
+ }
109
+ export declare class ErrorCodeHighlighterServerLoadVariantFailure extends ErrorCodeHighlighterServerLoader {
110
+ constructor(url: string, error: Error);
111
+ }
112
+ export declare class ErrorCodeHighlighterClientLoadFallbackFailure extends ErrorCodeHighlighterClientLoader {
113
+ constructor(error: Error);
114
+ }
115
+ export declare class ErrorCodeHighlighterClientLoadVariantsFailure extends ErrorCodeHighlighterClientLoader {
116
+ constructor(url: string, errors: Error[]);
117
+ }
118
+ export declare class ErrorCodeHighlighterClientLoadAllVariantsFailure extends ErrorCodeHighlighterClientLoader {
119
+ constructor(url: string, error: Error);
120
+ }
121
+ export declare class ErrorCodeHighlighterClientMissingParseSource extends ErrorCodeHighlighterClientProvider {
122
+ constructor(url?: string, isForceClient?: boolean);
123
+ }
124
+ export declare class ErrorCodeHighlighterClientMissingParseCode extends ErrorCodeHighlighterClientProvider {
125
+ constructor(url?: string, isForceClient?: boolean);
126
+ }
127
+ export declare class ErrorCodeHighlighterClientMissingParseControlledCode extends ErrorCodeHighlighterClientProvider {
128
+ constructor(url?: string, isForceClient?: boolean);
129
+ }
130
+ export declare class ErrorCodeHighlighterClientTransformProcessingFailure extends ErrorCodeHighlighterClientLoader {
131
+ constructor(error: Error);
132
+ }
133
+ export declare class ErrorCodeHighlighterClientMissingLoadVariantForGlobals extends ErrorCodeHighlighterClientProvider {
134
+ constructor();
135
+ }
136
+ export declare class ErrorCodeHighlighterClientLoadVariantFailureForGlobals extends ErrorCodeHighlighterClientLoader {
137
+ constructor(variantName: string, originalUrl?: string, error?: Error);
138
+ }
139
+ export declare class ErrorCodeHighlighterClientLoadGlobalsCodeFailure extends ErrorCodeHighlighterClientLoader {
140
+ constructor(url: string, error: Error);
141
+ }