@mui/internal-docs-infra 0.1.1-alpha.12 → 0.1.1-alpha.14

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 (50) hide show
  1. package/CodeHighlighter/CodeHighlighterClient.d.ts.map +1 -1
  2. package/CodeHighlighter/CodeHighlighterClient.js +45 -16
  3. package/CodeHighlighter/addPathsToVariant.d.ts +18 -0
  4. package/CodeHighlighter/addPathsToVariant.d.ts.map +1 -0
  5. package/CodeHighlighter/addPathsToVariant.js +352 -0
  6. package/CodeHighlighter/applyTransform.js +4 -4
  7. package/{useDemo → CodeHighlighter}/examineVariant.d.ts +1 -1
  8. package/CodeHighlighter/examineVariant.d.ts.map +1 -0
  9. package/CodeHighlighter/examineVariant.js +103 -0
  10. package/CodeHighlighter/mergeMetadata.d.ts +40 -0
  11. package/CodeHighlighter/mergeMetadata.d.ts.map +1 -0
  12. package/CodeHighlighter/mergeMetadata.js +189 -0
  13. package/CodeHighlighter/parseCode.js +10 -10
  14. package/CodeHighlighter/types.d.ts +11 -3
  15. package/CodeHighlighter/types.d.ts.map +1 -1
  16. package/package.json +1 -1
  17. package/pipeline/parseSource/addLineGutters.d.ts +7 -0
  18. package/pipeline/parseSource/addLineGutters.d.ts.map +1 -1
  19. package/pipeline/parseSource/addLineGutters.js +44 -0
  20. package/pipeline/parseSource/parseSource.d.ts.map +1 -1
  21. package/pipeline/parseSource/parseSource.js +1 -0
  22. package/useCode/useCode.d.ts +2 -3
  23. package/useCode/useCode.d.ts.map +1 -1
  24. package/useCode/useCodeUtils.d.ts +6 -7
  25. package/useCode/useCodeUtils.d.ts.map +1 -1
  26. package/useCode/useCodeUtils.js +7 -2
  27. package/useCode/useCopyFunctionality.d.ts +2 -1
  28. package/useCode/useCopyFunctionality.d.ts.map +1 -1
  29. package/useCode/useFileNavigation.d.ts +4 -16
  30. package/useCode/useFileNavigation.d.ts.map +1 -1
  31. package/useCode/useFileNavigation.js +23 -2
  32. package/useCode/useSourceEditing.d.ts +5 -3
  33. package/useCode/useSourceEditing.d.ts.map +1 -1
  34. package/useCode/useTransformManagement.d.ts +6 -4
  35. package/useCode/useTransformManagement.d.ts.map +1 -1
  36. package/useCode/useVariantSelection.d.ts +2 -2
  37. package/useCode/useVariantSelection.d.ts.map +1 -1
  38. package/useDemo/createCodeSandbox.d.ts.map +1 -1
  39. package/useDemo/createCodeSandbox.js +2 -3
  40. package/useDemo/exportVariant.d.ts +49 -11
  41. package/useDemo/exportVariant.d.ts.map +1 -1
  42. package/useDemo/exportVariant.js +170 -94
  43. package/useDemo/flattenVariant.d.ts +2 -0
  44. package/useDemo/flattenVariant.d.ts.map +1 -1
  45. package/useDemo/flattenVariant.js +19 -178
  46. package/useDemo/useDemo.d.ts +7 -0
  47. package/useDemo/useDemo.d.ts.map +1 -1
  48. package/useDemo/useDemo.js +37 -18
  49. package/useDemo/examineVariant.d.ts.map +0 -1
  50. package/useDemo/examineVariant.js +0 -134
@@ -1,16 +1,18 @@
1
- import type { Code } from "../CodeHighlighter/types.js";
1
+ import type { Code, VariantCode } from "../CodeHighlighter/types.js";
2
+ import { createTransformedFiles } from "./useCodeUtils.js";
3
+ import { CodeHighlighterContextType } from "../CodeHighlighter/CodeHighlighterContext.js";
2
4
  interface UseTransformManagementProps {
3
- context?: any;
5
+ context?: CodeHighlighterContextType;
4
6
  effectiveCode: Code;
5
7
  selectedVariantKey: string;
6
- selectedVariant: any;
8
+ selectedVariant: VariantCode | null;
7
9
  initialTransform?: string;
8
10
  shouldHighlight: boolean;
9
11
  }
10
12
  export interface UseTransformManagementResult {
11
13
  availableTransforms: string[];
12
14
  selectedTransform: string | null;
13
- transformedFiles: any;
15
+ transformedFiles: ReturnType<typeof createTransformedFiles>;
14
16
  selectTransform: (transformName: string | null) => void;
15
17
  }
16
18
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"useTransformManagement.d.ts","sourceRoot":"","sources":["../../src/useCode/useTransformManagement.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAIrD,UAAU,2BAA2B;IACnC,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,aAAa,EAAE,IAAI,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,GAAG,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,4BAA4B;IAC3C,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,gBAAgB,EAAE,GAAG,CAAC;IACtB,eAAe,EAAE,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACzD;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,OAAO,EACP,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,EAAE,2BAA2B,GAAG,4BAA4B,CAqE5D"}
1
+ {"version":3,"file":"useTransformManagement.d.ts","sourceRoot":"","sources":["../../src/useCode/useTransformManagement.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAA0B,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAEhF,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AAEvF,UAAU,2BAA2B;IACnC,OAAO,CAAC,EAAE,0BAA0B,CAAC;IACrC,aAAa,EAAE,IAAI,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,WAAW,GAAG,IAAI,CAAC;IACpC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,4BAA4B;IAC3C,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,gBAAgB,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC;IAC5D,eAAe,EAAE,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACzD;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,OAAO,EACP,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,EAAE,2BAA2B,GAAG,4BAA4B,CAqE5D"}
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import type { Code } from "../CodeHighlighter/types.js";
2
+ import type { Code, VariantCode } from "../CodeHighlighter/types.js";
3
3
  interface UseVariantSelectionProps {
4
4
  effectiveCode: Code;
5
5
  initialVariant?: string;
@@ -7,7 +7,7 @@ interface UseVariantSelectionProps {
7
7
  export interface UseVariantSelectionResult {
8
8
  variantKeys: string[];
9
9
  selectedVariantKey: string;
10
- selectedVariant: any;
10
+ selectedVariant: VariantCode | null;
11
11
  selectVariant: React.Dispatch<React.SetStateAction<string>>;
12
12
  }
13
13
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"useVariantSelection.d.ts","sourceRoot":"","sources":["../../src/useCode/useVariantSelection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,UAAU,wBAAwB;IAChC,aAAa,EAAE,IAAI,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,GAAG,CAAC;IACrB,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;CAC7D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,aAAa,EACb,cAAc,GACf,EAAE,wBAAwB,GAAG,yBAAyB,CA+EtD"}
1
+ {"version":3,"file":"useVariantSelection.d.ts","sourceRoot":"","sources":["../../src/useCode/useVariantSelection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGlE,UAAU,wBAAwB;IAChC,aAAa,EAAE,IAAI,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,WAAW,GAAG,IAAI,CAAC;IACpC,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;CAC7D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,aAAa,EACb,cAAc,GACf,EAAE,wBAAwB,GAAG,yBAAyB,CA+EtD"}
@@ -1 +1 @@
1
- {"version":3,"file":"createCodeSandbox.d.ts","sourceRoot":"","sources":["../../src/useDemo/createCodeSandbox.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAYvD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,cAAc,EACd,QAAQ,GACT,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAsBA"}
1
+ {"version":3,"file":"createCodeSandbox.d.ts","sourceRoot":"","sources":["../../src/useDemo/createCodeSandbox.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAYvD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,cAAc,EACd,QAAQ,GACT,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAqBA"}
@@ -35,11 +35,10 @@ export function createCodeSandbox(_ref) {
35
35
  files: files
36
36
  });
37
37
 
38
- // ref: https://codesandbox.io/docs/api/#define-api
38
+ // ref: https://codesandbox.io/docs/learn/browser-sandboxes/cli-api#supported-parameters
39
39
  var formData = {
40
40
  parameters: parameters,
41
- embed: '1',
42
- query: "module=/".concat(rootFile, "&fontsize=12")
41
+ query: "file=".concat(rootFile)
43
42
  };
44
43
  return {
45
44
  url: 'https://codesandbox.io/api/v1/sandboxes/define',
@@ -2,7 +2,7 @@
2
2
  * Export variant functionality to add extra files like package.json, tsconfig, etc.
3
3
  * Users can pass configuration options that vary the output here.
4
4
  */
5
- import type { VariantCode } from "../CodeHighlighter/types.js";
5
+ import type { VariantCode, VariantExtraFiles } from "../CodeHighlighter/types.js";
6
6
  /**
7
7
  * Extract filename from URL or return undefined if not available
8
8
  */
@@ -10,7 +10,7 @@ export declare function getFilenameFromVariant(variantCode: VariantCode): string
10
10
  /**
11
11
  * Generate a unique entrypoint filename that doesn't conflict with existing files
12
12
  */
13
- export declare function generateEntrypointFilename(existingFiles: Record<string, any>, sourceFilename: string | undefined, useTypescript: boolean, pathPrefix?: string): string;
13
+ export declare function generateEntrypointFilename(existingFiles: VariantExtraFiles, sourceFilename: string | undefined, useTypescript: boolean, pathPrefix?: string): string;
14
14
  /**
15
15
  * Generate the relative import path from entrypoint to source file
16
16
  */
@@ -36,12 +36,26 @@ export interface ExportConfig {
36
36
  title?: string;
37
37
  /** Description for package.json */
38
38
  description?: string;
39
+ /** The variant name/identifier for this specific code variant */
40
+ variantName?: string;
41
+ /**
42
+ * Language for the HTML document (default is 'en')
43
+ */
44
+ language?: string;
39
45
  /**
40
46
  * Prefix for output file paths (e.g., 'public/' for CRA, '' for Vite)
41
47
  * @example
42
48
  * htmlPrefix: 'public/' // outputs index.html to correct depth + public/index.html
43
49
  */
44
50
  htmlPrefix?: string;
51
+ /**
52
+ * Prefix for asset files (e.g., 'assets/' for CRA)
53
+ */
54
+ assetPrefix?: string;
55
+ /**
56
+ * Prefix for code files (e.g., 'src/' for Vite)
57
+ */
58
+ sourcePrefix?: string;
45
59
  /**
46
60
  * Whether the framework handles entrypoint and HTML generation (e.g., CRA with webpack)
47
61
  * When true, skips generating index.html and entrypoint files
@@ -50,7 +64,7 @@ export interface ExportConfig {
50
64
  /**
51
65
  * Custom HTML template function
52
66
  * @example
53
- * htmlTemplate: ({ language, title, description, head, entrypoint }) =>
67
+ * htmlTemplate: ({ language, title, description, head, entrypoint, variant, variantName }) =>
54
68
  * `<!doctype html><html><head><title>${title}</title>${head || ''}</head><body><div id="root"></div><script src="${entrypoint}"></script></body></html>`
55
69
  */
56
70
  htmlTemplate?: (params: {
@@ -59,16 +73,20 @@ export interface ExportConfig {
59
73
  description: string;
60
74
  head?: string;
61
75
  entrypoint: string;
76
+ variant?: VariantCode;
77
+ variantName?: string;
62
78
  }) => string;
63
79
  /**
64
80
  * Custom head template function for generating additional head content
65
81
  * @example
66
- * headTemplate: ({ sourcePrefix, assetPrefix }) =>
82
+ * headTemplate: ({ sourcePrefix, assetPrefix, variant, variantName }) =>
67
83
  * `<link rel="stylesheet" href="${assetPrefix}/styles.css" />\n<meta name="theme-color" content="#000000" />`
68
84
  */
69
85
  headTemplate?: (params: {
70
86
  sourcePrefix: string;
71
87
  assetPrefix: string;
88
+ variant?: VariantCode;
89
+ variantName?: string;
72
90
  }) => string;
73
91
  /** Custom React root index template function */
74
92
  rootIndexTemplate?: (params: {
@@ -92,17 +110,37 @@ export interface ExportConfig {
92
110
  /** Custom metadata files to add */
93
111
  extraMetadataFiles?: Record<string, {
94
112
  source: string;
95
- metadata?: boolean;
96
113
  }>;
97
114
  /** Framework-specific files that override default files (index.html, entrypoint, etc.) */
98
- frameworkFiles?: Record<string, {
99
- source: string;
100
- metadata?: boolean;
101
- }>;
115
+ frameworkFiles?: {
116
+ variant?: VariantCode;
117
+ globals?: VariantExtraFiles;
118
+ };
119
+ /**
120
+ * Custom export function to use instead of the default exportVariant or exportVariantAsCra
121
+ * @example
122
+ * exportFunction: (variantCode, config) => ({ exported: customProcessedCode, rootFile: 'custom-entry.js' })
123
+ */
124
+ exportFunction?: (variantCode: VariantCode, config: ExportConfig) => {
125
+ exported: VariantCode;
126
+ rootFile: string;
127
+ };
128
+ /**
129
+ * Transform function that runs at the very start of the export process
130
+ * Can modify the variant code and metadata before any other processing happens
131
+ * @example
132
+ * transformVariant: (variant, globals, variantName) => ({
133
+ * variant: { ...variant, source: modifiedSource },
134
+ * globals: { ...globals, extraFiles: { ...globals.extraFiles, 'theme.css': { source: '.new {}', metadata: true } } }
135
+ * })
136
+ */
137
+ transformVariant?: (variant: VariantCode, variantName?: string, globals?: VariantExtraFiles) => {
138
+ variant?: VariantCode;
139
+ globals?: VariantExtraFiles;
140
+ } | undefined;
102
141
  }
103
142
  /**
104
- * Export a VariantCode with additional configuration files
105
- * Returns an object with the exported VariantCode and rootPath path
143
+ * Export a variant as a standalone project with metadata files properly scoped
106
144
  */
107
145
  export declare function exportVariant(variantCode: VariantCode, config?: ExportConfig): {
108
146
  exported: VariantCode;
@@ -1 +1 @@
1
- {"version":3,"file":"exportVariant.d.ts","sourceRoot":"","sources":["../../src/useDemo/exportVariant.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAK5D;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,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,OAAO,CAAC,EAAE,WAAW,CAAC;QAAC,OAAO,CAAC,EAAE,iBAAiB,CAAA;KAAE,CAAC;IACxE;;;;OAIG;IACH,cAAc,CAAC,EAAE,CACf,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,YAAY,KACjB;QAAE,QAAQ,EAAE,WAAW,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,CACjB,OAAO,EAAE,WAAW,EACpB,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,iBAAiB,KACxB;QAAE,OAAO,CAAC,EAAE,WAAW,CAAC;QAAC,OAAO,CAAC,EAAE,iBAAiB,CAAA;KAAE,GAAG,SAAS,CAAC;CACzE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,WAAW,EAAE,WAAW,EACxB,MAAM,GAAE,YAAiB,GACxB;IAAE,QAAQ,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAuV7C"}
@@ -1,5 +1,5 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  /**
4
4
  * Export variant functionality to add extra files like package.json, tsconfig, etc.
5
5
  * Users can pass configuration options that vary the output here.
@@ -7,7 +7,37 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
7
7
 
8
8
  import { externalsToPackages } from "../pipeline/loaderUtils/index.js";
9
9
  import { getFileNameFromUrl } from "../pipeline/loaderUtils/getFileNameFromUrl.js";
10
- import { createPathContext } from "./examineVariant.js";
10
+ import { createPathContext } from "../CodeHighlighter/examineVariant.js";
11
+ import { mergeMetadata, extractMetadata } from "../CodeHighlighter/mergeMetadata.js";
12
+ /**
13
+ * Merges multiple file objects into a single object.
14
+ * Similar to mergeExternals but for file structures.
15
+ * Automatically adds metadata: false to files that don't have a metadata property.
16
+ */
17
+ function mergeFiles() {
18
+ var merged = {};
19
+ for (var _len = arguments.length, fileSets = new Array(_len), _key = 0; _key < _len; _key++) {
20
+ fileSets[_key] = arguments[_key];
21
+ }
22
+ for (var _i = 0, _fileSets = fileSets; _i < _fileSets.length; _i++) {
23
+ var fileSet = _fileSets[_i];
24
+ for (var _i2 = 0, _Object$entries = Object.entries(fileSet); _i2 < _Object$entries.length; _i2++) {
25
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
26
+ fileName = _Object$entries$_i[0],
27
+ fileData = _Object$entries$_i[1];
28
+ // Later files override earlier ones (similar to Object.assign behavior)
29
+ var normalizedData = typeof fileData === 'string' ? {
30
+ source: fileData
31
+ } : _objectSpread({}, fileData);
32
+ // Add metadata: false if not already set (source files default to false)
33
+ if (!('metadata' in normalizedData)) {
34
+ normalizedData.metadata = false;
35
+ }
36
+ merged[fileName] = normalizedData;
37
+ }
38
+ }
39
+ return merged;
40
+ }
11
41
 
12
42
  /**
13
43
  * Extract filename from URL or return undefined if not available
@@ -30,15 +60,15 @@ export function getFilenameFromVariant(variantCode) {
30
60
  export function generateEntrypointFilename(existingFiles, sourceFilename, useTypescript) {
31
61
  var pathPrefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
32
62
  var ext = useTypescript ? 'tsx' : 'jsx';
33
- var candidates = ["".concat(pathPrefix, "index.").concat(ext), "".concat(pathPrefix, "entrypoint.").concat(ext), "".concat(pathPrefix, "main.").concat(ext)];
63
+ var candidates = ["".concat(pathPrefix, "App.").concat(ext), "".concat(pathPrefix, "entrypoint.").concat(ext), "".concat(pathPrefix, "main.").concat(ext)];
34
64
 
35
65
  // If we have a source filename, also try variations
36
66
  if (sourceFilename) {
37
67
  var baseName = sourceFilename.replace(/\.[^.]*$/, '');
38
68
  candidates.push("".concat(pathPrefix).concat(baseName, "-entry.").concat(ext));
39
69
  }
40
- for (var _i = 0, _candidates = candidates; _i < _candidates.length; _i++) {
41
- var candidate = _candidates[_i];
70
+ for (var _i3 = 0, _candidates = candidates; _i3 < _candidates.length; _i3++) {
71
+ var candidate = _candidates[_i3];
42
72
  if (candidate !== "".concat(pathPrefix).concat(sourceFilename) && !existingFiles[candidate]) {
43
73
  return candidate;
44
74
  }
@@ -74,17 +104,24 @@ export function defaultHtmlTemplate(_ref) {
74
104
  return "<!doctype html>\n<html lang=\"".concat(language, "\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>").concat(title, "</title>\n <meta name=\"description\" content=\"").concat(description, "\" />").concat(head ? "\n ".concat(head) : '', "\n </head>\n <body>\n <div id=\"root\"></div>").concat(entrypoint ? "\n <script type=\"module\" src=\"".concat(entrypoint, "\"></script>") : '', "\n </body>\n</html>");
75
105
  }
76
106
  /**
77
- * Export a VariantCode with additional configuration files
78
- * Returns an object with the exported VariantCode and rootPath path
107
+ * Export a variant as a standalone project with metadata files properly scoped
79
108
  */
80
109
  export function exportVariant(variantCode) {
110
+ var _frameworkFiles$varia;
81
111
  var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
82
112
  var _config$title = config.title,
83
113
  title = _config$title === void 0 ? 'Demo' : _config$title,
84
114
  _config$description = config.description,
85
115
  description = _config$description === void 0 ? 'Demo created with Vite' : _config$description,
116
+ variantName = config.variantName,
117
+ _config$language = config.language,
118
+ language = _config$language === void 0 ? 'en' : _config$language,
86
119
  _config$htmlPrefix = config.htmlPrefix,
87
120
  htmlPrefix = _config$htmlPrefix === void 0 ? '' : _config$htmlPrefix,
121
+ _config$sourcePrefix = config.sourcePrefix,
122
+ sourcePrefix = _config$sourcePrefix === void 0 ? 'src/' : _config$sourcePrefix,
123
+ _config$assetPrefix = config.assetPrefix,
124
+ assetPrefix = _config$assetPrefix === void 0 ? '' : _config$assetPrefix,
88
125
  _config$frameworkHand = config.frameworkHandlesEntrypoint,
89
126
  frameworkHandlesEntrypoint = _config$frameworkHand === void 0 ? false : _config$frameworkHand,
90
127
  htmlTemplate = config.htmlTemplate,
@@ -106,7 +143,23 @@ export function exportVariant(variantCode) {
106
143
  _config$extraMetadata = config.extraMetadataFiles,
107
144
  extraMetadataFiles = _config$extraMetadata === void 0 ? {} : _config$extraMetadata,
108
145
  _config$frameworkFile = config.frameworkFiles,
109
- frameworkFiles = _config$frameworkFile === void 0 ? {} : _config$frameworkFile;
146
+ frameworkFiles = _config$frameworkFile === void 0 ? {} : _config$frameworkFile,
147
+ transformVariant = config.transformVariant;
148
+
149
+ // Use extractMetadata to properly separate metadata and non-metadata files
150
+ var _extractMetadata = extractMetadata(variantCode),
151
+ processedVariantCode = _extractMetadata.variant,
152
+ processedGlobals = _extractMetadata.metadata;
153
+ if (transformVariant) {
154
+ var transformed = transformVariant(processedVariantCode, variantName, processedGlobals);
155
+ if (transformed) {
156
+ // Re-extract metadata after transformation
157
+ var result = extractMetadata(transformed.variant || variantCode);
158
+ processedVariantCode = result.variant;
159
+ // Combine metadata from extraction with transformed globals
160
+ processedGlobals = _objectSpread(_objectSpread({}, result.metadata), transformed.globals);
161
+ }
162
+ }
110
163
 
111
164
  // If packageType is explicitly provided (even as undefined), use that value
112
165
  var finalPackageType;
@@ -117,50 +170,70 @@ export function exportVariant(variantCode) {
117
170
  }
118
171
 
119
172
  // Get existing extraFiles and source filename
120
- var existingExtraFiles = variantCode.extraFiles || {};
121
- var sourceFilename = getFilenameFromVariant(variantCode);
173
+ var sourceFilename = getFilenameFromVariant(processedVariantCode);
122
174
 
123
- // Get path context to calculate proper URLs
124
- var pathContext = createPathContext(variantCode);
175
+ // Get path context to understand navigation
176
+ var pathContext = createPathContext(variantCode); // Determine if we need to rename the source file (if it's index.tsx in src dir)
125
177
 
126
- // Calculate the correct prefix for metadata files based on path depth
127
- var metadataPrefix = '../'.repeat(pathContext.maxBackNavigation + 1);
178
+ var ext = useTypescript ? 'tsx' : 'jsx';
179
+ var isSourceFileIndex = sourceFilename === "index.".concat(ext);
180
+ // Use urlDirectory to determine if it's in src root (should only have 'src' as the directory)
181
+ var isInSrcRoot = pathContext.urlDirectory.length <= 1;
182
+ var actualSourceFilename = sourceFilename;
183
+
184
+ // Use urlDirectory to construct the full path from src root
185
+ var directoryPath = pathContext.urlDirectory.slice(1).join('/'); // Remove 'src' and join the rest
186
+ var actualRootFile = directoryPath ? "".concat(sourcePrefix).concat(directoryPath, "/").concat(sourceFilename) : "".concat(sourcePrefix).concat(sourceFilename);
128
187
 
129
- // Generate unique entrypoint filename
130
- var entrypointFilename = generateEntrypointFilename(existingExtraFiles, sourceFilename, useTypescript);
188
+ // If the source file is index.tsx and it's in the src root, we need to rename it
189
+ if (isSourceFileIndex && isInSrcRoot) {
190
+ actualSourceFilename = generateEntrypointFilename(processedVariantCode.extraFiles || {}, sourceFilename, useTypescript);
191
+ actualRootFile = "".concat(sourcePrefix).concat(actualSourceFilename);
192
+ }
131
193
 
132
- // Calculate the entrypoint URL relative to the root
133
- var entrypoint = "/src/".concat(pathContext.pathInwardFromRoot).concat(entrypointFilename);
194
+ // The main entrypoint is always src/index.tsx (or .jsx)
195
+ var mainEntrypointFilename = "index.".concat(ext);
196
+ var entrypoint = "".concat(sourcePrefix).concat(mainEntrypointFilename);
134
197
 
135
198
  // Get relative import path for the main component
136
- var rootFile = "src/".concat(pathContext.pathInwardFromRoot).concat(sourceFilename);
137
- var importPath = getRelativeImportPath(sourceFilename);
138
- var importString = variantCode.namedExport ? "import { ".concat(variantCode.namedExport, " as App } from '").concat(importPath, "';") : "import App from '".concat(importPath, "';");
139
-
140
- // Create new extraFiles object
141
- var newExtraFiles = _objectSpread({}, existingExtraFiles);
142
-
143
- // Add framework-specific files (if any)
144
- for (var _i2 = 0, _Object$entries = Object.entries(frameworkFiles); _i2 < _Object$entries.length; _i2++) {
145
- var _fileData$metadata;
146
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
147
- fileName = _Object$entries$_i[0],
148
- fileData = _Object$entries$_i[1];
149
- newExtraFiles[fileName] = {
150
- source: fileData.source,
151
- metadata: (_fileData$metadata = fileData.metadata) != null ? _fileData$metadata : true
152
- };
199
+ var importPath;
200
+ if (isInSrcRoot) {
201
+ // Component is in src root - import directly
202
+ importPath = getRelativeImportPath(actualSourceFilename);
203
+ } else {
204
+ // Component is in a subdirectory - import with full path from src root
205
+ // Use urlDirectory excluding the root level to get the full directory path
206
+ var _directoryPath = pathContext.urlDirectory.slice(1).join('/'); // Remove 'src' and join the rest
207
+ var componentPath = _directoryPath ? "".concat(_directoryPath, "/").concat(actualSourceFilename) : actualSourceFilename;
208
+ importPath = "./".concat((componentPath || '').replace(/\.[^.]*$/, '')); // Remove extension
209
+ }
210
+
211
+ // Strip /index from the end of import paths since module resolution handles it automatically
212
+ if (importPath.endsWith('/index')) {
213
+ importPath = importPath.slice(0, -6); // Remove '/index'
214
+ }
215
+ var importString = processedVariantCode.namedExport ? "import { ".concat(processedVariantCode.namedExport, " as App } from '").concat(importPath, "';") : "import App from '".concat(importPath, "';");
216
+
217
+ // Collect all files that will be generated
218
+ var generatedFiles = {};
219
+
220
+ // Update the variant's fileName if we renamed it
221
+ if (isSourceFileIndex && isInSrcRoot && actualSourceFilename && actualSourceFilename !== sourceFilename) {
222
+ processedVariantCode.fileName = actualSourceFilename;
153
223
  }
154
224
 
155
- // Check if we're using a framework (has framework files)
156
- var isFramework = frameworkFiles && Object.keys(frameworkFiles).length > 0;
157
- var externalPackages = externalsToPackages(variantCode.externals || []);
225
+ // Check if they're providing their own framework
226
+ var isFramework = 'frameworkFiles' in config;
227
+ var externalPackages = externalsToPackages(processedVariantCode.externals || []);
158
228
  var variantDeps = Object.keys(externalPackages).reduce(function (acc, pkg) {
159
229
  acc[pkg] = 'latest';
160
230
  return acc;
161
231
  }, {});
162
232
 
163
- // Generate package.json (always)
233
+ // Collect metadata files to be generated
234
+ var metadataFiles = {};
235
+
236
+ // Generate package.json
164
237
  var packageJson = _objectSpread(_objectSpread({
165
238
  "private": true,
166
239
  name: title.toLowerCase().replace(/[^a-z0-9]/g, '-'),
@@ -188,62 +261,35 @@ export function exportVariant(variantCode) {
188
261
  '@types/react-dom': 'latest'
189
262
  }), devDependencies)
190
263
  }, packageJsonFields);
191
- newExtraFiles["".concat(metadataPrefix, "package.json")] = {
192
- source: JSON.stringify(packageJson, null, 2),
193
- metadata: true
264
+ metadataFiles['package.json'] = {
265
+ source: JSON.stringify(packageJson, null, 2)
194
266
  };
195
267
 
196
268
  // Generate entrypoint and HTML files unless framework handles them
197
269
  if (!frameworkHandlesEntrypoint) {
198
- // Add index.html (with configurable prefix for different frameworks)
199
- var headContent = headTemplate ? headTemplate({
200
- sourcePrefix: '/src',
201
- assetPrefix: ''
202
- }) : undefined;
203
- var htmlContent = htmlTemplate ? htmlTemplate({
204
- language: 'en',
205
- title: title,
206
- description: description,
207
- head: headContent,
208
- entrypoint: entrypoint
209
- }) : defaultHtmlTemplate({
210
- language: 'en',
211
- title: title,
212
- description: description,
213
- head: headContent,
214
- entrypoint: entrypoint
215
- });
216
- var htmlFilePath = htmlPrefix ? "".concat(metadataPrefix).concat(htmlPrefix, "index.html") : "".concat(metadataPrefix, "index.html");
217
- newExtraFiles[htmlFilePath] = {
218
- source: htmlContent,
219
- metadata: true
220
- };
221
-
222
270
  // Create entrypoint file that imports the main component
223
271
  var defaultEntrypointContent = "import * as React from 'react';\nimport * as ReactDOM from 'react-dom/client';\n".concat(importString, "\n\nReactDOM.createRoot(document.getElementById('root')").concat(useTypescript ? '!' : '', ").render(\n <React.StrictMode>\n <App />\n </React.StrictMode>\n);");
224
272
  var entrypointContent = rootIndexTemplate ? rootIndexTemplate({
225
273
  importString: importString,
226
274
  useTypescript: useTypescript
227
275
  }) : defaultEntrypointContent;
228
- newExtraFiles[entrypointFilename] = {
229
- source: entrypointContent,
230
- metadata: false
276
+ generatedFiles[mainEntrypointFilename] = {
277
+ source: entrypointContent
231
278
  };
232
279
  }
233
280
 
234
281
  // Add Vite config file only if no framework files (Vite-specific)
235
282
  if (!isFramework) {
236
283
  var viteConfigContent = "import { defineConfig } from 'vite';\nimport react from '@vitejs/plugin-react';\nimport { externalsToPackages } from '../loaderUtils/externalsToPackages';\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n plugins: [react()],\n define: { 'process.env': {} },\n});";
237
- newExtraFiles["".concat(metadataPrefix, "vite.config.").concat(useTypescript ? 'ts' : 'js')] = {
238
- source: viteConfigContent,
239
- metadata: true
284
+ metadataFiles["vite.config.".concat(useTypescript ? 'ts' : 'js')] = {
285
+ source: viteConfigContent
240
286
  };
241
287
  }
242
288
 
243
- // Add TypeScript configuration if requested (up one directory, metadata: true)
289
+ // Add TypeScript configuration if requested
244
290
  if (useTypescript) {
245
291
  // Check if frameworkFiles already includes a tsconfig
246
- var hasFrameworkTsConfig = frameworkFiles && Object.keys(frameworkFiles).some(function (fileName) {
292
+ var hasFrameworkTsConfig = (frameworkFiles == null ? void 0 : frameworkFiles.globals) && Object.keys(frameworkFiles.globals).some(function (fileName) {
247
293
  return fileName.includes('tsconfig.json') && !fileName.includes('tsconfig.node.json');
248
294
  });
249
295
  if (!hasFrameworkTsConfig) {
@@ -272,9 +318,8 @@ export function exportVariant(variantCode) {
272
318
  path: './tsconfig.node.json'
273
319
  }]
274
320
  });
275
- newExtraFiles["".concat(metadataPrefix, "tsconfig.json")] = {
276
- source: JSON.stringify(defaultTsConfig, null, 2),
277
- metadata: true
321
+ metadataFiles['tsconfig.json'] = {
322
+ source: JSON.stringify(defaultTsConfig, null, 2)
278
323
  };
279
324
  }
280
325
 
@@ -291,30 +336,61 @@ export function exportVariant(variantCode) {
291
336
  },
292
337
  include: ['vite.config.ts']
293
338
  };
294
- newExtraFiles["".concat(metadataPrefix, "tsconfig.node.json")] = {
295
- source: JSON.stringify(nodeTsConfig, null, 2),
296
- metadata: true
339
+ metadataFiles['tsconfig.node.json'] = {
340
+ source: JSON.stringify(nodeTsConfig, null, 2)
297
341
  };
298
342
  }
299
343
  }
300
344
 
301
- // Add custom metadata files (respect metadata flag)
302
- for (var _i3 = 0, _Object$entries2 = Object.entries(extraMetadataFiles); _i3 < _Object$entries2.length; _i3++) {
303
- var _fileData$metadata2;
304
- var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i3], 2),
305
- _fileName = _Object$entries2$_i[0],
306
- _fileData = _Object$entries2$_i[1];
307
- newExtraFiles["".concat(metadataPrefix).concat(_fileName)] = {
308
- source: _fileData.source,
309
- metadata: (_fileData$metadata2 = _fileData.metadata) != null ? _fileData$metadata2 : true
345
+ // Generate HTML file after all files are ready
346
+ if (!frameworkHandlesEntrypoint) {
347
+ // Add index.html
348
+ var headContent = headTemplate ? headTemplate({
349
+ sourcePrefix: sourcePrefix,
350
+ assetPrefix: assetPrefix,
351
+ variant: processedVariantCode,
352
+ variantName: variantName
353
+ }) : undefined;
354
+ var htmlContent = htmlTemplate ? htmlTemplate({
355
+ language: language,
356
+ title: title,
357
+ description: description,
358
+ head: headContent,
359
+ entrypoint: entrypoint,
360
+ variant: processedVariantCode,
361
+ variantName: variantName
362
+ }) : defaultHtmlTemplate({
363
+ language: language,
364
+ title: title,
365
+ description: description,
366
+ head: headContent,
367
+ entrypoint: entrypoint
368
+ });
369
+ var htmlFileName = htmlPrefix ? "".concat(htmlPrefix, "index.html") : 'index.html';
370
+ metadataFiles[htmlFileName] = {
371
+ source: htmlContent
310
372
  };
311
373
  }
312
374
 
313
- // Return new VariantCode with updated extraFiles
375
+ // Merge all metadata files including framework metadata and globals
376
+ var allMetadataFiles = mergeFiles(processedGlobals || {}, metadataFiles, extraMetadataFiles, frameworkFiles.globals || {});
377
+
378
+ // Merge all files using mergeMetadata to properly position everything with 'src/' (sourcePrefix opt) prefix
379
+ var allSourceFilesWithFramework = mergeFiles(processedVariantCode.extraFiles || {}, generatedFiles, ((_frameworkFiles$varia = frameworkFiles.variant) == null ? void 0 : _frameworkFiles$varia.extraFiles) || {});
380
+
381
+ // Update the variant with all source files including framework source files
382
+ var finalVariantWithSources = _objectSpread(_objectSpread({}, processedVariantCode), {}, {
383
+ extraFiles: allSourceFilesWithFramework
384
+ });
385
+
386
+ // Use mergeMetadata to position everything correctly
387
+ var finalVariant = mergeMetadata(finalVariantWithSources, allMetadataFiles, {
388
+ metadataPrefix: sourcePrefix
389
+ });
390
+
391
+ // Return new VariantCode with properly positioned files
314
392
  return {
315
- exported: _objectSpread(_objectSpread({}, variantCode), {}, {
316
- extraFiles: newExtraFiles
317
- }),
318
- rootFile: rootFile
393
+ exported: finalVariant,
394
+ rootFile: actualRootFile
319
395
  };
320
396
  }
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Flatten variant utility to convert a VariantCode into a flat files list
3
3
  * Handles relative path resolution and metadata file scoping
4
+ * Uses addPathsToVariant for the core logic, then flattens the result
4
5
  */
5
6
  import type { VariantCode } from "../CodeHighlighter/types.js";
6
7
  export interface FlatFile {
@@ -13,5 +14,6 @@ export interface FlattenedFiles {
13
14
  /**
14
15
  * Flatten a VariantCode into a flat files structure
15
16
  * Resolves relative paths and handles metadata file scoping
17
+ * Uses addPathsToVariant for path resolution logic
16
18
  */
17
19
  export declare function flattenVariant(variant: VariantCode): FlattenedFiles;
@@ -1 +1 @@
1
- {"version":3,"file":"flattenVariant.d.ts","sourceRoot":"","sources":["../../src/useDemo/flattenVariant.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAK3E,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC;CAC9B;AAiLD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CA+BnE"}
1
+ {"version":3,"file":"flattenVariant.d.ts","sourceRoot":"","sources":["../../src/useDemo/flattenVariant.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAI3E,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC;CAC9B;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CA6BnE"}