@mui/internal-docs-infra 0.12.1-canary.39 → 0.12.1-canary.40

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.
@@ -15,8 +15,8 @@ export interface StringFallbackResult {
15
15
  * `sourceEnhancers` the live render uses over a cheap line-guttered HAST
16
16
  * (`parsePlainText` — gutters, no syntax highlighting). The inline-string
17
17
  * fallback path otherwise wraps the whole source in one un-windowed focus frame,
18
- * so an oversized / `@focus` / `@highlight` block paints its full text before
19
- * hydration then snaps to the collapsed window. Running the enhancers here makes
18
+ * so an oversized source (with or without `@focus` / `@highlight` directives)
19
+ * paints its full text before hydration then snaps to the collapsed window. Running the enhancers here makes
20
20
  * the loading frames match the live render, and the resulting `root.data` carries
21
21
  * the `totalLines` / `focusedLines` the compact fallback can't preserve.
22
22
  *
@@ -9,8 +9,8 @@ function isPromiseLike(value) {
9
9
  * `sourceEnhancers` the live render uses over a cheap line-guttered HAST
10
10
  * (`parsePlainText` — gutters, no syntax highlighting). The inline-string
11
11
  * fallback path otherwise wraps the whole source in one un-windowed focus frame,
12
- * so an oversized / `@focus` / `@highlight` block paints its full text before
13
- * hydration then snaps to the collapsed window. Running the enhancers here makes
12
+ * so an oversized source (with or without `@focus` / `@highlight` directives)
13
+ * paints its full text before hydration then snaps to the collapsed window. Running the enhancers here makes
14
14
  * the loading frames match the live render, and the resulting `root.data` carries
15
15
  * the `totalLines` / `focusedLines` the compact fallback can't preserve.
16
16
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-docs-infra",
3
- "version": "0.12.1-canary.39",
3
+ "version": "0.12.1-canary.40",
4
4
  "author": "MUI Team",
5
5
  "description": "MUI Infra - internal documentation creation tools.",
6
6
  "license": "MIT",
@@ -804,5 +804,5 @@
804
804
  "bin": {
805
805
  "docs-infra": "./cli/index.mjs"
806
806
  },
807
- "gitSha": "3ce58e4dbb827caca255cf9b285beafd9f10967f"
807
+ "gitSha": "99c21315b55b03f58d832f7854e628da68343a10"
808
808
  }
@@ -0,0 +1,20 @@
1
+ import type { Element } from 'hast';
2
+ import type { FrameRange } from "../parseSource/calculateFrameRanges.mjs";
3
+ /**
4
+ * Calculates the `data-frame-indent` level of each region frame, keyed by its
5
+ * index in `frameRanges`.
6
+ *
7
+ * Frames shown while collapsed form one contiguous window and share its indent,
8
+ * so shifting each of them by its own level keeps their left edges aligned.
9
+ * Hidden region frames use the indent of their whole region instead:
10
+ *
11
+ * focus 1–2 ─┐
12
+ * highlighted 3 ├─ window: min indent of lines 1–4
13
+ * focus 4 ─┘
14
+ * normal 5–6 (no indent)
15
+ * highlighted-unfocused 7–8 ── region: min indent of lines 7–8
16
+ *
17
+ * @param frameRanges - Ordered frame ranges covering the source
18
+ * @param lineElements - Map of line numbers to their line elements
19
+ */
20
+ export declare function calculateFrameIndentLevels(frameRanges: FrameRange[], lineElements: Map<number, Element>): Map<number, number>;
@@ -0,0 +1,63 @@
1
+ import { COLLAPSED_VISIBLE_FRAME_TYPES } from "../parseSource/frameVisibility.mjs";
2
+ import { calculateFrameIndent } from "./calculateFrameIndent.mjs";
3
+
4
+ /**
5
+ * Calculates the `data-frame-indent` level of each region frame, keyed by its
6
+ * index in `frameRanges`.
7
+ *
8
+ * Frames shown while collapsed form one contiguous window and share its indent,
9
+ * so shifting each of them by its own level keeps their left edges aligned.
10
+ * Hidden region frames use the indent of their whole region instead:
11
+ *
12
+ * focus 1–2 ─┐
13
+ * highlighted 3 ├─ window: min indent of lines 1–4
14
+ * focus 4 ─┘
15
+ * normal 5–6 (no indent)
16
+ * highlighted-unfocused 7–8 ── region: min indent of lines 7–8
17
+ *
18
+ * @param frameRanges - Ordered frame ranges covering the source
19
+ * @param lineElements - Map of line numbers to their line elements
20
+ */
21
+ export function calculateFrameIndentLevels(frameRanges, lineElements) {
22
+ const frameIndentLevels = new Map();
23
+ const windowFrames = [];
24
+ const windowLines = [];
25
+ const regionFrames = new Map();
26
+ const regionLines = new Map();
27
+ function collectLines(range) {
28
+ const lines = [];
29
+ for (let line = range.startLine; line <= range.endLine; line += 1) {
30
+ const element = lineElements.get(line);
31
+ if (element) {
32
+ lines.push(element);
33
+ }
34
+ }
35
+ return lines;
36
+ }
37
+ for (let frameIndex = 0; frameIndex < frameRanges.length; frameIndex += 1) {
38
+ const range = frameRanges[frameIndex];
39
+ if (COLLAPSED_VISIBLE_FRAME_TYPES.has(range.type)) {
40
+ windowFrames.push(frameIndex);
41
+ windowLines.push(...collectLines(range));
42
+ continue;
43
+ }
44
+ if (range.regionIndex === undefined) {
45
+ continue;
46
+ }
47
+ regionFrames.set(range.regionIndex, [...(regionFrames.get(range.regionIndex) ?? []), frameIndex]);
48
+ regionLines.set(range.regionIndex, [...(regionLines.get(range.regionIndex) ?? []), ...collectLines(range)]);
49
+ }
50
+ for (const [regionIndex, frames] of regionFrames) {
51
+ const indentLevel = calculateFrameIndent(regionLines.get(regionIndex) ?? []);
52
+ for (const frameIndex of frames) {
53
+ frameIndentLevels.set(frameIndex, indentLevel);
54
+ }
55
+ }
56
+ if (windowFrames.length > 0) {
57
+ const indentLevel = calculateFrameIndent(windowLines);
58
+ for (const frameIndex of windowFrames) {
59
+ frameIndentLevels.set(frameIndex, indentLevel);
60
+ }
61
+ }
62
+ return frameIndentLevels;
63
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The prefix used to identify emphasis comments in source code.
3
+ * Comments starting with this prefix will be processed for emphasis.
4
+ */
5
+ export declare const EMPHASIS_COMMENT_PREFIX = "@highlight";
6
+ /**
7
+ * The prefix used to identify focus-only comments in source code.
8
+ * Comments starting with this prefix will mark the region as focused without highlighting.
9
+ */
10
+ export declare const FOCUS_COMMENT_PREFIX = "@focus";
11
+ /**
12
+ * Modifier token used inside focused `@highlight` / `@focus` comments
13
+ * to override padding for that focus region.
14
+ * Example: combine `@highlight`, `@focus`, and `@padding 2`.
15
+ */
16
+ export declare const PADDING_COMMENT_PREFIX = "@padding";
17
+ /**
18
+ * Modifier token used inside focused `@highlight` / `@focus` comments
19
+ * to override the maximum size for that focus region.
20
+ * Example: combine `@highlight`, `@focus`, and `@min 6`.
21
+ */
22
+ export declare const MIN_COMMENT_PREFIX = "@min";
23
+ /**
24
+ * Replaces quoted content with underscores of the same length so directive
25
+ * matching only sees unquoted text. Backslash-escaped characters stay inside
26
+ * the current quoted section.
27
+ */
28
+ export declare function maskQuotedContent(content: string): string;
29
+ /**
30
+ * Extracts quoted strings while treating backslash-escaped quote characters
31
+ * as content. Returned strings preserve their original escape sequences.
32
+ */
33
+ export declare function extractQuotedCommentStrings(content: string): string[];
34
+ /**
35
+ * Collects whitespace-delimited comment tokens while ignoring quoted text.
36
+ */
37
+ export declare function getUnquotedCommentTokens(comment: string): string[];
38
+ /**
39
+ * Returns whether a parsed comment contains a real focus directive.
40
+ */
41
+ export declare function hasFocusDirective(comment: string): boolean;
@@ -0,0 +1,130 @@
1
+ /**
2
+ * The prefix used to identify emphasis comments in source code.
3
+ * Comments starting with this prefix will be processed for emphasis.
4
+ */
5
+ export const EMPHASIS_COMMENT_PREFIX = '@highlight';
6
+
7
+ /**
8
+ * The prefix used to identify focus-only comments in source code.
9
+ * Comments starting with this prefix will mark the region as focused without highlighting.
10
+ */
11
+ export const FOCUS_COMMENT_PREFIX = '@focus';
12
+
13
+ /**
14
+ * Modifier token used inside focused `@highlight` / `@focus` comments
15
+ * to override padding for that focus region.
16
+ * Example: combine `@highlight`, `@focus`, and `@padding 2`.
17
+ */
18
+ export const PADDING_COMMENT_PREFIX = '@padding';
19
+
20
+ /**
21
+ * Modifier token used inside focused `@highlight` / `@focus` comments
22
+ * to override the maximum size for that focus region.
23
+ * Example: combine `@highlight`, `@focus`, and `@min 6`.
24
+ */
25
+ export const MIN_COMMENT_PREFIX = '@min';
26
+
27
+ /**
28
+ * Replaces quoted content with underscores of the same length so directive
29
+ * matching only sees unquoted text. Backslash-escaped characters stay inside
30
+ * the current quoted section.
31
+ */
32
+ export function maskQuotedContent(content) {
33
+ let result = '';
34
+ let quote;
35
+ for (let index = 0; index < content.length; index += 1) {
36
+ const character = content[index];
37
+ if (quote) {
38
+ result += '_';
39
+ if (character === '\\' && index + 1 < content.length) {
40
+ index += 1;
41
+ result += '_';
42
+ } else if (character === quote) {
43
+ quote = undefined;
44
+ }
45
+ } else if (character === '"' || character === "'") {
46
+ quote = character;
47
+ result += '_';
48
+ } else {
49
+ result += character;
50
+ }
51
+ }
52
+ return result;
53
+ }
54
+
55
+ /**
56
+ * Extracts quoted strings while treating backslash-escaped quote characters
57
+ * as content. Returned strings preserve their original escape sequences.
58
+ */
59
+ export function extractQuotedCommentStrings(content) {
60
+ const strings = [];
61
+ let quote;
62
+ let contentStart = -1;
63
+ for (let index = 0; index < content.length; index += 1) {
64
+ const character = content[index];
65
+ if (quote) {
66
+ if (character === '\\' && index + 1 < content.length) {
67
+ index += 1;
68
+ } else if (character === quote) {
69
+ if (index > contentStart) {
70
+ strings.push(content.slice(contentStart, index));
71
+ }
72
+ quote = undefined;
73
+ contentStart = -1;
74
+ }
75
+ } else if (character === '"' || character === "'") {
76
+ quote = character;
77
+ contentStart = index + 1;
78
+ }
79
+ }
80
+ return strings;
81
+ }
82
+
83
+ /**
84
+ * Collects whitespace-delimited comment tokens while ignoring quoted text.
85
+ */
86
+ export function getUnquotedCommentTokens(comment) {
87
+ const tokens = [];
88
+ let currentToken = '';
89
+ let quote;
90
+ function pushCurrentToken() {
91
+ if (currentToken) {
92
+ tokens.push(currentToken);
93
+ currentToken = '';
94
+ }
95
+ }
96
+ for (let index = 0; index < comment.length; index += 1) {
97
+ const character = comment[index];
98
+ if (quote) {
99
+ if (character === '\\' && index + 1 < comment.length) {
100
+ index += 1;
101
+ } else if (character === quote) {
102
+ quote = undefined;
103
+ }
104
+ continue;
105
+ }
106
+ if (character === '"' || character === "'") {
107
+ pushCurrentToken();
108
+ quote = character;
109
+ } else if (character === ' ' || character === '\t' || character === '\n' || character === '\r') {
110
+ pushCurrentToken();
111
+ } else {
112
+ currentToken += character;
113
+ }
114
+ }
115
+ pushCurrentToken();
116
+ return tokens;
117
+ }
118
+
119
+ /**
120
+ * Returns whether a parsed comment contains a real focus directive.
121
+ */
122
+ export function hasFocusDirective(comment) {
123
+ const tokens = getUnquotedCommentTokens(comment);
124
+ const firstToken = tokens[0];
125
+ if (firstToken === FOCUS_COMMENT_PREFIX || firstToken === `${FOCUS_COMMENT_PREFIX}-start` || firstToken === `${FOCUS_COMMENT_PREFIX}-end`) {
126
+ return true;
127
+ }
128
+ const acceptsFocusModifier = firstToken === EMPHASIS_COMMENT_PREFIX || firstToken === `${EMPHASIS_COMMENT_PREFIX}-start` || firstToken === `${EMPHASIS_COMMENT_PREFIX}-text`;
129
+ return acceptsFocusModifier && tokens.includes(FOCUS_COMMENT_PREFIX);
130
+ }
@@ -1,71 +1,27 @@
1
1
  import type { SourceEnhancer } from "../../CodeHighlighter/types.mjs";
2
2
  import type { EnhanceCodeEmphasisOptions } from "../parseSource/calculateFrameRanges.mjs";
3
3
  export type { EmphasisMeta, EnhanceCodeEmphasisOptions, FrameRange } from "../parseSource/calculateFrameRanges.mjs";
4
+ export { EMPHASIS_COMMENT_PREFIX, FOCUS_COMMENT_PREFIX, MIN_COMMENT_PREFIX, PADDING_COMMENT_PREFIX } from "./emphasisCommentUtils.mjs";
4
5
  /**
5
- * The prefix used to identify emphasis comments in source code.
6
- * Comments starting with this prefix will be processed for emphasis.
7
- */
8
- export declare const EMPHASIS_COMMENT_PREFIX = "@highlight";
9
- /**
10
- * The prefix used to identify focus-only comments in source code.
11
- * Comments starting with this prefix will mark the region as focused without highlighting.
12
- */
13
- export declare const FOCUS_COMMENT_PREFIX = "@focus";
14
- /**
15
- * Modifier token used inside `@highlight` / `@focus` comments
16
- * to override padding for that directive.
17
- * Example: @highlight @padding 2.
18
- */
19
- export declare const PADDING_COMMENT_PREFIX = "@padding";
20
- /**
21
- * Modifier token used inside `@highlight` / `@focus` comments
22
- * to override focus max size for that directive.
23
- * Example: @highlight @min 6.
24
- */
25
- export declare const MIN_COMMENT_PREFIX = "@min";
26
- /**
27
- * Creates a source enhancer that adds emphasis to code lines based on `@highlight` comments
28
- * and restructures frames around highlighted regions.
29
- *
30
- * Supports five patterns:
31
- *
32
- * 1. **Single line emphasis** - emphasizes the line containing the comment:
33
- * ```jsx
34
- * <h1>Heading 1</h1> {/* @highlight *\/}
35
- * ```
36
- *
37
- * 2. **Multiline emphasis** - emphasizes all lines between start and end:
38
- * ```jsx
39
- * // @highlight-start
40
- * <div>
41
- * <h1>Heading 1</h1>
42
- * </div>
43
- * // @highlight-end
44
- * ```
45
- *
46
- * 3. **Multiline with description**:
47
- * ```jsx
48
- * // @highlight-start "we add a heading"
49
- * <div>
50
- * <h1>Heading 1</h1>
51
- * </div>
52
- * // @highlight-end
53
- * ```
54
- *
55
- * 4. **Text highlight** - highlights specific text within a line:
56
- * ```jsx
57
- * <h1>Heading 1</h1> {/* @highlight-text "Heading 1" *\/}
58
- * ```
59
- *
60
- * 5. **Focus override** - mark a region for padding focus:
61
- * ```jsx
62
- * <h1>Heading 1</h1> {/* @highlight @focus *\/}
63
- * ```
64
- *
65
- * Emphasized lines receive a `data-hl` attribute on their `<span class="line">` element.
66
- * When highlights exist, frames are restructured with `data-frame-type` attributes
67
- * (`highlighted`, `padding-top`, `padding-bottom`, or omitted for normal).
68
- * Highlighted frames also receive `data-frame-indent` with the shared indent level.
6
+ * Creates a source enhancer that renders `@highlight` as visual emphasis and
7
+ * uses `@focus` to select the collapsed preview.
8
+ *
9
+ * Supports six patterns:
10
+ *
11
+ * 1. **Single line emphasis** - `@highlight` emphasizes its line.
12
+ * 2. **Multiline emphasis** - `@highlight-start` and `@highlight-end`
13
+ * emphasize the lines between them.
14
+ * 3. **Multiline with description** - add a quoted description after
15
+ * `@highlight-start`.
16
+ * 4. **Text highlight** - `@highlight-text "Heading 1"` emphasizes matching text.
17
+ * 5. **Focused highlight** - combine `@highlight` with `@focus` to emphasize a line
18
+ * and select it for the collapsed preview.
19
+ * 6. **Focus only** - `@focus-start` and `@focus-end` select preview lines
20
+ * without emphasizing them.
21
+ *
22
+ * Frames are restructured with `data-frame-type` attributes for focused and highlighted
23
+ * regions. A highlight nested inside a focus frame receives line-level `data-hl` so both
24
+ * layers remain visible. Set `emitFrameIndent` to add the shared indent level to region frames.
69
25
  *
70
26
  * @param options - Optional configuration for padding frames
71
27
  * @returns A `SourceEnhancer` function
@@ -79,8 +35,9 @@ export declare const MIN_COMMENT_PREFIX = "@min";
79
35
  */
80
36
  export declare function createEnhanceCodeEmphasis(options?: EnhanceCodeEmphasisOptions): SourceEnhancer;
81
37
  /**
82
- * Default source enhancer that adds emphasis to code lines based on `@highlight` comments.
83
- * Uses no padding frames by default. Use `createEnhanceCodeEmphasis` for configurable padding.
38
+ * Default source enhancer that renders `@highlight` emphasis and uses `@focus`
39
+ * to select the collapsed preview. Uses no padding frames by default. Use
40
+ * `createEnhanceCodeEmphasis` for configurable padding.
84
41
  *
85
42
  * @example
86
43
  * ```ts