@ngrok/mantle 0.66.16 → 0.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +32 -0
  2. package/dist/accordion.d.ts +1 -1
  3. package/dist/alert-dialog.d.ts +12 -12
  4. package/dist/alert.d.ts +3 -3
  5. package/dist/anchor.d.ts +1 -1
  6. package/dist/{as-child-XMVTepJu.d.ts → as-child-CRRsxi3Y.d.ts} +1 -1
  7. package/dist/badge.d.ts +2 -2
  8. package/dist/booleanish-CBGdPL3Q.js.map +1 -1
  9. package/dist/{button-B6StZJsz.d.ts → button-B--2eT25.d.ts} +9 -9
  10. package/dist/button.d.ts +3 -3
  11. package/dist/card.d.ts +1 -1
  12. package/dist/checkbox.d.ts +1 -1
  13. package/dist/code-block.d.ts +176 -249
  14. package/dist/code-block.js +2 -8
  15. package/dist/code-block.js.map +1 -1
  16. package/dist/code-block_highlight-utils.d.ts +2 -0
  17. package/dist/code-block_highlight-utils.js +1 -0
  18. package/dist/color.d.ts +1 -1
  19. package/dist/combobox.d.ts +2 -2
  20. package/dist/combobox.js +1 -1
  21. package/dist/command.d.ts +14 -14
  22. package/dist/command.js +1 -1
  23. package/dist/data-table.d.ts +3 -3
  24. package/dist/data-table.js +1 -1
  25. package/dist/{deep-non-nullable-BLM3Gz0I.d.ts → deep-non-nullable-BBByg3-i.d.ts} +1 -1
  26. package/dist/description-list.d.ts +1 -1
  27. package/dist/{dialog-DUOIIhuN.js → dialog-PqWYibMO.js} +1 -1
  28. package/dist/{dialog-DUOIIhuN.js.map → dialog-PqWYibMO.js.map} +1 -1
  29. package/dist/dialog.d.ts +2 -2
  30. package/dist/dialog.js +1 -1
  31. package/dist/{direction-DYYpi-JC.d.ts → direction-C_bMxZXm.d.ts} +1 -1
  32. package/dist/{direction-DfrtFTny.js → direction-Ca88oQhP.js} +1 -1
  33. package/dist/{direction-DfrtFTny.js.map → direction-Ca88oQhP.js.map} +1 -1
  34. package/dist/{dropdown-menu-CUwyTKyu.js → dropdown-menu-9nO7ch0t.js} +2 -2
  35. package/dist/{dropdown-menu-CUwyTKyu.js.map → dropdown-menu-9nO7ch0t.js.map} +1 -1
  36. package/dist/{dropdown-menu-BEjpuGrT.d.ts → dropdown-menu-slQCdKvp.d.ts} +2 -2
  37. package/dist/dropdown-menu.d.ts +1 -1
  38. package/dist/dropdown-menu.js +1 -1
  39. package/dist/hooks.d.ts +6 -2
  40. package/dist/hooks.js +1 -1
  41. package/dist/hooks.js.map +1 -1
  42. package/dist/{icon-B1XLv02t.d.ts → icon-BkSBkfH9.d.ts} +2 -2
  43. package/dist/{icon-button-2r6S3HVA.d.ts → icon-button-DMNdrMSf.d.ts} +3 -3
  44. package/dist/icon.d.ts +3 -3
  45. package/dist/icons.d.ts +3 -3
  46. package/dist/icons.js +1 -1
  47. package/dist/{in-view-ca-moloX.d.ts → in-view-DS0PgFGa.d.ts} +1 -1
  48. package/dist/{in-view-bPnaWEL4.js → in-view-DiFJ28EF.js} +1 -1
  49. package/dist/{in-view-bPnaWEL4.js.map → in-view-DiFJ28EF.js.map} +1 -1
  50. package/dist/{index-s8rMcilU.d.ts → index-BerTFFEC.d.ts} +1 -1
  51. package/dist/{index-BLCvtjLi.d.ts → index-C0yxjFyf.d.ts} +1 -1
  52. package/dist/{index-ViSCOUrU.d.ts → index-CI-RDnHZ.d.ts} +2 -2
  53. package/dist/{index-DWqhfw9n.d.ts → index-Cxmuw3UT.d.ts} +2 -2
  54. package/dist/input.d.ts +2 -2
  55. package/dist/input.js +1 -1
  56. package/dist/{is-input-BFR8yMM7.js → is-input-CC_n6EGM.js} +1 -1
  57. package/dist/{is-input-BFR8yMM7.js.map → is-input-CC_n6EGM.js.map} +1 -1
  58. package/dist/{kbd-CtTyMWXB.js → kbd-wgm9K9D5.js} +1 -1
  59. package/dist/{kbd-CtTyMWXB.js.map → kbd-wgm9K9D5.js.map} +1 -1
  60. package/dist/kbd.js +1 -1
  61. package/dist/mantle.css +64 -52
  62. package/dist/media-object.d.ts +1 -1
  63. package/dist/multi-select.d.ts +2 -2
  64. package/dist/multi-select.js +1 -1
  65. package/dist/multi-select.js.map +1 -1
  66. package/dist/pagination.d.ts +3 -3
  67. package/dist/pagination.js +1 -1
  68. package/dist/{primitive-tuHqhoRE.d.ts → primitive-BmWrmUz1.d.ts} +1 -1
  69. package/dist/radio-group.d.ts +1 -1
  70. package/dist/radio-group.js +1 -1
  71. package/dist/resolve-pre-rendered-props-51i50IL2.d.ts +165 -0
  72. package/dist/resolve-pre-rendered-props-Bu2cvS9A.js +11 -0
  73. package/dist/resolve-pre-rendered-props-Bu2cvS9A.js.map +1 -0
  74. package/dist/sandboxed-on-click.d.ts +1 -1
  75. package/dist/{select-BkvbNKQ7.d.ts → select-B3jxZhYg.d.ts} +3 -3
  76. package/dist/{select-BXBu1jP_.js → select-Z13w6WBS.js} +2 -2
  77. package/dist/{select-BXBu1jP_.js.map → select-Z13w6WBS.js.map} +1 -1
  78. package/dist/select.d.ts +1 -1
  79. package/dist/select.js +1 -1
  80. package/dist/{separator-fSV4z0Pq.js → separator-BuP5aENE.js} +1 -1
  81. package/dist/{separator-fSV4z0Pq.js.map → separator-BuP5aENE.js.map} +1 -1
  82. package/dist/separator.d.ts +1 -1
  83. package/dist/separator.js +1 -1
  84. package/dist/sheet.d.ts +2 -2
  85. package/dist/{sort-CfPsu1Gs.js → sort-mo52clyh.js} +2 -2
  86. package/dist/{sort-CfPsu1Gs.js.map → sort-mo52clyh.js.map} +1 -1
  87. package/dist/split-button.d.ts +3 -3
  88. package/dist/split-button.js +1 -1
  89. package/dist/{svg-only-Ct2mB46K.d.ts → svg-only-BH9PBSGl.d.ts} +2 -2
  90. package/dist/{table-Bs1D5Aj7.d.ts → table-CU7zx1pH.d.ts} +1 -1
  91. package/dist/{table-bSFWy29w.js → table-OYhLMxeE.js} +1 -1
  92. package/dist/{table-bSFWy29w.js.map → table-OYhLMxeE.js.map} +1 -1
  93. package/dist/table.d.ts +1 -1
  94. package/dist/table.js +1 -1
  95. package/dist/tabs.js +1 -1
  96. package/dist/tabs.js.map +1 -1
  97. package/dist/text-area.d.ts +1 -1
  98. package/dist/theme.d.ts +4 -4
  99. package/dist/{themes-Dk0VkyqX.d.ts → themes-D_v8H0nY.d.ts} +1 -1
  100. package/dist/toast.d.ts +3 -3
  101. package/dist/{types-DgXUgkpc.d.ts → types-Cq6RWU7Q.d.ts} +1 -1
  102. package/dist/{types-Dh4BVhXC.d.ts → types-yU-Byhue.d.ts} +1 -1
  103. package/dist/types.d.ts +5 -5
  104. package/dist/use-copy-to-clipboard-B6wH6hDd.js +2 -0
  105. package/dist/use-copy-to-clipboard-B6wH6hDd.js.map +1 -0
  106. package/dist/{use-prefers-reduced-motion-BiG6QGkf.js → use-prefers-reduced-motion-BcwST13S.js} +1 -1
  107. package/dist/{use-prefers-reduced-motion-BiG6QGkf.js.map → use-prefers-reduced-motion-BcwST13S.js.map} +1 -1
  108. package/dist/utils.d.ts +2 -2
  109. package/dist/utils.js +1 -1
  110. package/dist/{variant-props-UE-phTwh.d.ts → variant-props-Bm6Y-jfm.d.ts} +2 -2
  111. package/dist/{with-style-props-D1QFTzj6.d.ts → with-style-props-9-k1s4ov.d.ts} +1 -1
  112. package/package.json +8 -5
  113. package/dist/use-copy-to-clipboard-BCpEp-sO.js +0 -2
  114. package/dist/use-copy-to-clipboard-BCpEp-sO.js.map +0 -1
@@ -1,104 +1,139 @@
1
- import { t as SvgAttributes } from "./types-Dh4BVhXC.js";
2
- import { t as WithAsChild } from "./as-child-XMVTepJu.js";
1
+ import { t as SvgAttributes } from "./types-yU-Byhue.js";
2
+ import { t as WithAsChild } from "./as-child-CRRsxi3Y.js";
3
+ import { C as parseLanguage, D as LineRange, E as decorateHighlightedHtml, S as isSupportedLanguage, _ as normalizeIndentation, a as Mode, b as isIndentation, c as ResolvedPreRenderedCodeBlockProps, d as parseMetastring, f as resolvePreRenderedCodeBlockProps, g as parseCodeBlockShowLineNumbers, h as parseCodeBlockLineNumberStart, i as MetaInput, l as defaultMeta, m as parseCodeBlockHighlightLines, n as DefaultMeta, o as ResolvePreRenderedCodeBlockPropsInput, p as tokenizeMetastring, r as Meta, s as ResolvePreRenderedCodeBlockPropsResult, t as CodeBlockPreElementInput, u as normalizeValue, v as Indentation, w as supportedLanguages, x as SupportedLanguage, y as inferIndentation } from "./resolve-pre-rendered-props-51i50IL2.js";
3
4
  import * as react from "react";
4
5
  import { ComponentProps, HTMLAttributes, ReactNode } from "react";
5
6
  import * as react_jsx_runtime0 from "react/jsx-runtime";
7
+ import { Content, List, Trigger } from "@radix-ui/react-tabs";
6
8
 
7
- //#region src/components/code-block/supported-languages.d.ts
9
+ //#region src/components/code-block/mantle-code.d.ts
10
+ declare const mantleCodeBlockValueBrand: unique symbol;
8
11
  /**
9
- * List of supported languages for syntax highlighting.
10
- * @private
11
- */
12
- declare const supportedLanguages: readonly ["bash", "cs", "csharp", "css", "dotnet", "go", "html", "java", "javascript", "js", "json", "jsx", "markup", "plain", "plaintext", "py", "python", "rb", "ruby", "rust", "sh", "shell", "text", "ts", "tsx", "txt", "typescript", "xml", "yaml", "yml"];
13
- /**
14
- * Supported languages for syntax highlighting.
15
- */
16
- type SupportedLanguage = (typeof supportedLanguages)[number];
17
- /**
18
- * Parses a markdown code block (```) language class into a SupportedLanguage.
19
- * Defaults to "sh" if no supported language is found.
20
- */
21
- declare function parseLanguage(value: `language-${string}` | `lang-${string}` | (string & {}) | undefined): SupportedLanguage;
22
- /**
23
- * Type Predicate: checks if an arbitrary value is a supported syntax highlighting language.
24
- */
25
- declare const isSupportedLanguage: (value: unknown) => value is SupportedLanguage;
26
- /**
27
- * Formats a language name into a class name that Prism.js can understand.
28
- * @default "language-sh"
29
- */
30
- declare function formatLanguageClassName(language?: SupportedLanguage | undefined): "language-html" | "language-ruby" | "language-text" | "language-py" | "language-go" | "language-plaintext" | "language-bash" | "language-cs" | "language-csharp" | "language-css" | "language-dotnet" | "language-java" | "language-javascript" | "language-js" | "language-json" | "language-jsx" | "language-markup" | "language-plain" | "language-python" | "language-rb" | "language-rust" | "language-sh" | "language-shell" | "language-ts" | "language-tsx" | "language-txt" | "language-typescript" | "language-xml" | "language-yaml" | "language-yml";
31
- //#endregion
32
- //#region src/components/code-block/indentation.d.ts
33
- declare const indentations: readonly ["tabs", "spaces"];
34
- type Indentation = (typeof indentations)[number];
35
- /**
36
- * Type Predicate: checks if the given value is a valid indentation type.
37
- */
38
- //#endregion
39
- //#region src/components/code-block/line-numbers.d.ts
40
- /**
41
- * A line range is a string in the format of `start-end` where `start` and `end` are line numbers.
12
+ * The value produced by `mantleCode()`. Contains pre-rendered Shiki HTML (injected
13
+ * by the Vite plugin at build time) and the original code string for the copy button.
14
+ *
15
+ * `~preHtml` is required at render time. Runtime syntax highlighting is intentionally
16
+ * unsupported; only placeholder substitution for interpolated values is performed.
42
17
  */
43
- type LineRange = `${number}-${number}`;
44
- //#endregion
45
- //#region src/components/code-block/parse-metastring.d.ts
46
- declare const modes: readonly ["cli", "file", "traffic-policy"];
47
- type Mode = (typeof modes)[number];
48
- type MetaInput = {
49
- collapsible?: boolean | undefined;
50
- disableCopy?: boolean | undefined;
51
- indentation?: Indentation | undefined;
52
- mode?: Mode | undefined;
53
- title?: string | undefined;
18
+ type MantleCodeBlockValue = {
19
+ /**
20
+ * Nominal type brand to prevent accidental use of plain objects.
21
+ */
22
+ [mantleCodeBlockValueBrand]: true;
23
+ /**
24
+ * The language used for syntax highlighting.
25
+ */
26
+ language: SupportedLanguage;
27
+ /**
28
+ * The original code string (used by the copy button).
29
+ */
30
+ code: string;
31
+ /**
32
+ * Fully pre-rendered Shiki HTML injected by the Vite plugin or server highlighter.
33
+ * This must be present for rendering.
34
+ *
35
+ * **Security:** This HTML is injected via `dangerouslySetInnerHTML`. It must
36
+ * come from a trusted source (Shiki output from the Vite plugin or
37
+ * `createMantleServerSyntaxHighlighter`). Never pass unsanitized user input.
38
+ */
39
+ "~preHtml"?: string | undefined;
40
+ /**
41
+ * Runtime values used to replace `SHIKI_VAL_N` placeholders in `~preHtml`.
42
+ * This enables interpolated template expressions while preserving build-time highlighting.
43
+ */
44
+ "~preVals"?: unknown[] | undefined;
45
+ /**
46
+ * Placeholder token prefix used by the Vite transform for interpolated values.
47
+ * When omitted, CodeBlock falls back to the legacy `SHIKI_VAL_<n>` format.
48
+ */
49
+ "~preValToken"?: string | undefined;
50
+ /**
51
+ * Optional default for line-number rendering when this value is displayed.
52
+ */
53
+ "~showLineNumbers"?: boolean | undefined;
54
+ /**
55
+ * Optional default highlighted line numbers/ranges when this value is displayed.
56
+ */
57
+ "~highlightLines"?: (LineRange | number)[] | undefined;
58
+ /**
59
+ * Optional default start line number when line numbers are displayed.
60
+ * @default 1
61
+ */
62
+ "~lineNumberStart"?: number | undefined;
54
63
  };
55
- type Meta = {
56
- collapsible: boolean;
57
- disableCopy: boolean;
64
+ /** Maps each key starting with `OldPrefix` to `NewPrefix`, leaving other keys unchanged. */
65
+ type ReplacePrefix<T, OldPrefix extends string, NewPrefix extends string> = { [K in keyof T as K extends `${OldPrefix}${infer Rest}` ? `${NewPrefix}${Rest}` : K]: T[K] };
66
+ /** Public input shape for `createMantleCodeBlockValue`, with `~`-prefixed keys renamed to unprefixed. */
67
+ type MantleCodeBlockValueInput = ReplacePrefix<Omit<MantleCodeBlockValue, typeof mantleCodeBlockValueBrand>, "~", "">;
68
+ /** Options for configuring line numbers, highlights, and indentation in `mantleCode()`. */
69
+ type MantleCodeOptions = {
70
+ highlightLines?: (LineRange | number)[] | undefined;
58
71
  indentation?: Indentation | undefined;
59
- mode?: Mode | undefined;
60
- title?: string | undefined;
72
+ lineNumberStart?: number | undefined;
73
+ showLineNumbers?: boolean | undefined;
61
74
  };
62
- declare const defaultMeta: {
63
- readonly collapsible: false;
64
- readonly disableCopy: false;
65
- readonly indentation: undefined;
66
- readonly mode: undefined;
67
- readonly title: undefined;
68
- };
69
- type DefaultMeta = typeof defaultMeta;
70
75
  /**
71
- * Parses a markdown code block (```) metastring into a meta object.
72
- * Defaults to DefaultMeta if no metastring given or if metastring is invalid.
73
- * Useful for parsing the metastring from a markdown code block to pass into the
74
- * CodeBlock components as props.
76
+ * Creates a `MantleCodeBlockValue` for use with `CodeBlock.Code`.
77
+ *
78
+ * **Security:** The `preHtml` field is rendered via `dangerouslySetInnerHTML`.
79
+ * Only pass HTML produced by Shiki (via the Vite plugin or
80
+ * `createMantleServerSyntaxHighlighter`). Never pass unsanitized user input as `preHtml`.
75
81
  */
76
- declare function parseMetastring(input: string | undefined): Meta;
82
+ declare function createMantleCodeBlockValue({
83
+ preHtml,
84
+ preValToken,
85
+ preVals,
86
+ highlightLines,
87
+ lineNumberStart,
88
+ showLineNumbers,
89
+ code,
90
+ language
91
+ }: MantleCodeBlockValueInput): MantleCodeBlockValue;
92
+ /**
93
+ * Tagged template literal for Shiki syntax highlighting.
94
+ *
95
+ * Returns a `MantleCodeBlockValue` that `CodeBlock.Code` renders.
96
+ * The Vite transform plugin rewrites calls to this function at build time,
97
+ * inlining pre-rendered Shiki HTML so that no highlighting work happens in the browser.
98
+ * Configure it via `mantleCodeBlockPlugins()` in `vite.config.ts`.
99
+ *
100
+ * Interpolated template expressions are supported via placeholder substitution.
101
+ *
102
+ * @example
103
+ * ```tsx
104
+ * // Static string
105
+ * mantleCode("typescript")`const x: string = "hello";`
106
+ * // Interpolated string
107
+ * mantleCode("typescript")`const greeting = "Hello, ${name}!";`
108
+ * ```
109
+ */
110
+ declare function mantleCode(language: SupportedLanguage, options?: MantleCodeOptions): (strings: TemplateStringsArray, ...values: unknown[]) => MantleCodeBlockValue;
77
111
  //#endregion
78
112
  //#region src/components/code-block/code-block.d.ts
79
- type CodeBlockCodeProps = Omit<ComponentProps<"pre">, "children"> & {
113
+ type CodeBlockRootProps = Omit<ComponentProps<"div">, "align"> & WithAsChild & {
80
114
  /**
81
- * The code to display in the code block. Should be code formatted as a string. This code will be passed to our syntax highlighter.
115
+ * The default active tab value (uncontrolled).
116
+ * Only relevant when using `CodeBlock.TabList` / `CodeBlock.TabContent`.
82
117
  */
83
- value: string;
118
+ defaultTab?: string;
84
119
  /**
85
- * @todo not implemented yet
120
+ * The controlled active tab value.
121
+ * Only relevant when using `CodeBlock.TabList` / `CodeBlock.TabContent`.
86
122
  */
87
- highlightLines?: (LineRange | number)[];
123
+ activeTab?: string;
88
124
  /**
89
- * The type of indentation to use. Can be either "tabs" or "spaces".
90
- * @default inferred from the given language, fallback to `spaces`
125
+ * Callback fired when the active tab changes.
126
+ * Only relevant when using `CodeBlock.TabList` / `CodeBlock.TabContent`.
91
127
  */
92
- indentation?: Indentation;
93
- /**
94
- * The language of the code block. This will be used to determine how to syntax highlight the code.
95
- * @default `"text"`.
96
- */
97
- language?: SupportedLanguage;
128
+ onActiveTabChange?: (value: string) => void;
129
+ };
130
+ type CodeBlockCodeProps = Omit<ComponentProps<"pre">, "children"> & {
98
131
  /**
99
- * @todo not implemented yet
132
+ * The code value produced by `mantleCode("lang")` tagged template.
133
+ * Contains pre-rendered Shiki HTML (when the Vite plugin is active) and
134
+ * the original code string for the copy button.
100
135
  */
101
- showLineNumbers?: boolean;
136
+ value: MantleCodeBlockValue;
102
137
  };
103
138
  type CodeBlockCopyButtonProps = Omit<ComponentProps<"button">, "children" | "type"> & WithAsChild & {
104
139
  /**
@@ -113,7 +148,7 @@ type CodeBlockCopyButtonProps = Omit<ComponentProps<"button">, "children" | "typ
113
148
  type CodeBlockExpanderButtonProps = Omit<ComponentProps<"button">, "children" | "aria-controls" | "aria-expanded"> & WithAsChild;
114
149
  type CodeBlockIconProps = Omit<SvgAttributes, "children"> & ({
115
150
  /**
116
- * A custom icon to display in the code block header.
151
+ * A custom icon SVG to display in the code block header.
117
152
  * (Pass only one of `svg` or `preset`.)
118
153
  */
119
154
  svg: ReactNode;
@@ -124,7 +159,7 @@ type CodeBlockIconProps = Omit<SvgAttributes, "children"> & ({
124
159
  preset?: undefined | never;
125
160
  } | {
126
161
  /**
127
- * A custom icon to display in the code block header.
162
+ * A custom icon SVG to display in the code block header.
128
163
  * (Pass only one of `svg` or `preset`.)
129
164
  */
130
165
  svg?: undefined | never;
@@ -135,27 +170,15 @@ type CodeBlockIconProps = Omit<SvgAttributes, "children"> & ({
135
170
  preset: Mode;
136
171
  });
137
172
  /**
138
- * A small icon that represents the type of code block being displayed,
139
- * rendered as an SVG next to the code block title in the code block header.
140
- *
141
- * You can pass in a custom SVG component or use one of the presets
142
- * (pass only one of `svg` or `preset`).
143
- *
144
- * @see https://mantle.ngrok.com/components/code-block#codeblockicon
173
+ * A small icon for the `CodeBlock` header. Pass either a custom `svg`
174
+ * or a `preset` value (not both).
145
175
  *
146
176
  * @example
147
177
  * ```tsx
148
- * <CodeBlock.Root>
149
- * <CodeBlock.Header>
150
- * <CodeBlock.Icon preset="file" />
151
- * <CodeBlock.Title>…</CodeBlock.Title>
152
- * </CodeBlock.Header>
153
- * <CodeBlock.Body>
154
- * <CodeBlock.CopyButton />
155
- * <CodeBlock.Code language="…" value={fmtCode\`…\`} />
156
- * </CodeBlock.Body>
157
- * <CodeBlock.ExpanderButton />
158
- * </CodeBlock.Root>
178
+ * <CodeBlock.Header>
179
+ * <CodeBlock.Icon preset="file" />
180
+ * <CodeBlock.Title>example.ts</CodeBlock.Title>
181
+ * </CodeBlock.Header>
159
182
  * ```
160
183
  */
161
184
  declare function CodeBlockIconComponent({
@@ -167,174 +190,90 @@ declare function CodeBlockIconComponent({
167
190
  declare namespace CodeBlockIconComponent {
168
191
  var displayName: string;
169
192
  }
193
+ type CodeBlockTabListProps = Omit<ComponentProps<typeof List>, "asChild" | "loop">;
194
+ type CodeBlockTabTriggerProps = Omit<ComponentProps<typeof Trigger>, "asChild">;
195
+ type CodeBlockTabContentProps = Omit<ComponentProps<typeof Content>, "asChild" | "forceMount">;
170
196
  /**
171
- * Code blocks render and apply syntax highlighting to blocks of code.
197
+ * Shiki-powered code blocks with build-time syntax highlighting and zero browser bundle.
172
198
  *
173
- * @see https://mantle.ngrok.com/components/code-block
199
+ * Use `mantleCodeBlockPlugins()` to enable pre-rendering at build time.
174
200
  *
175
201
  * @example
176
202
  * ```tsx
177
203
  * <CodeBlock.Root>
178
204
  * <CodeBlock.Header>
179
205
  * <CodeBlock.Icon preset="file" />
180
- * <CodeBlock.Title>…</CodeBlock.Title>
206
+ * <CodeBlock.Title>example.ts</CodeBlock.Title>
181
207
  * </CodeBlock.Header>
182
208
  * <CodeBlock.Body>
183
209
  * <CodeBlock.CopyButton />
184
- * <CodeBlock.Code language="" value={fmtCode\`…\`} />
210
+ * <CodeBlock.Code value={mantleCode("typescript")`const x = "hello";`} />
185
211
  * </CodeBlock.Body>
186
212
  * <CodeBlock.ExpanderButton />
187
213
  * </CodeBlock.Root>
214
+ *
215
+ * // Server-highlighted HTML fetched via an action route + React Query mutation
216
+ * const highlightMutation = useMutation({
217
+ * mutationFn: async () => {
218
+ * const response = await fetch("/api/shiki-highlight", {
219
+ * method: "POST",
220
+ * headers: { "Content-Type": "application/json" },
221
+ * body: JSON.stringify({ code: source, language: "typescript" }),
222
+ * });
223
+ * return response.json();
224
+ * },
225
+ * });
226
+ *
227
+ * const serverValue = createMantleCodeBlockValue({
228
+ * language: "typescript",
229
+ * code: source,
230
+ * preHtml: highlightMutation.data?.html,
231
+ * });
188
232
  * ```
189
233
  */
190
234
  declare const CodeBlock: {
191
235
  /**
192
- * Code blocks render and apply syntax highlighting to blocks of code.
193
- * This is the root component for all code block components.
194
- *
195
- * @see https://mantle.ngrok.com/components/code-block#codeblockroot
196
- *
197
- * @example
198
- * ```tsx
199
- * <CodeBlock.Root>
200
- * <CodeBlock.Header>
201
- * <CodeBlock.Icon preset="file" />
202
- * <CodeBlock.Title>…</CodeBlock.Title>
203
- * </CodeBlock.Header>
204
- * <CodeBlock.Body>
205
- * <CodeBlock.CopyButton />
206
- * <CodeBlock.Code language="…" value={fmtCode\`…\`} />
207
- * </CodeBlock.Body>
208
- * <CodeBlock.ExpanderButton />
209
- * </CodeBlock.Root>
210
- * ```
236
+ * The root component of the `CodeBlock`.
211
237
  */
212
- readonly Root: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "align"> & WithAsChild, "ref"> & react.RefAttributes<HTMLDivElement>>;
238
+ readonly Root: react.ForwardRefExoticComponent<Omit<CodeBlockRootProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
213
239
  /**
214
- * The body of the `CodeBlock`. This is where the `CodeBlock.Code` and optional
215
- * `CodeBlock.CopyButton` is rendered.
216
- *
217
- * @see https://mantle.ngrok.com/components/code-block#codeblockbody
218
- *
219
- * @example
220
- * ```tsx
221
- * <CodeBlock.Root>
222
- * <CodeBlock.Body>
223
- * <CodeBlock.CopyButton />
224
- * <CodeBlock.Code language="…" value={fmtCode\`…\`} />
225
- * </CodeBlock.Body>
226
- * </CodeBlock.Root>
227
- * ```
240
+ * The body of the `CodeBlock`. Contains `Code` and optional `CopyButton`.
228
241
  */
229
242
  readonly Body: react.ForwardRefExoticComponent<Omit<react.ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & WithAsChild, "ref"> & react.RefAttributes<HTMLDivElement>>;
230
243
  /**
231
- * The `CodeBlock` content. This is where the code is rendered and syntax highlighted.
232
- *
233
- * @see https://mantle.ngrok.com/components/code-block#codeblockcode
234
- *
235
- * @example
236
- * ```tsx
237
- * <CodeBlock.Root>
238
- * <CodeBlock.Body>
239
- * <CodeBlock.Code
240
- * language="sh"
241
- * value={fmtCode`ffmpeg -i multichannel.mxf -map 0:v:0 -map 0:a:0`}
242
- * />
243
- * </CodeBlock.Body>
244
- * </CodeBlock.Root>
245
- * ```
244
+ * The code content. Renders pre-highlighted Shiki HTML when the Vite plugin is active.
246
245
  */
247
246
  readonly Code: react.ForwardRefExoticComponent<Omit<CodeBlockCodeProps, "ref"> & react.RefAttributes<HTMLPreElement>>;
248
247
  /**
249
- * The (optional) copy button of the `CodeBlock`. Render this as a child of the
250
- * `CodeBlock.Body` to allow users to copy the code block contents to their
251
- * clipboard.
252
- *
253
- * @see https://mantle.ngrok.com/components/code-block#codeblockcopybutton
254
- *
255
- * @example
256
- * ```tsx
257
- * <CodeBlock.Root>
258
- * <CodeBlock.Body>
259
- * <CodeBlock.CopyButton />
260
- * <CodeBlock.Code language="…" value={fmtCode\`…\`} />
261
- * </CodeBlock.Body>
262
- * </CodeBlock.Root>
263
- * ```
248
+ * The optional copy button.
264
249
  */
265
250
  readonly CopyButton: react.ForwardRefExoticComponent<Omit<CodeBlockCopyButtonProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
266
251
  /**
267
- * The (optional) expander button of the `CodeBlock`. Render this as a child of the
268
- * `CodeBlock.Body` to allow users to expand/collapse the code block contents.
269
- *
270
- * @see https://mantle.ngrok.com/components/code-block#codeblockexpanderbutton
271
- *
272
- * @example
273
- * ```tsx
274
- * <CodeBlock.Root>
275
- * <CodeBlock.Body>
276
- * <CodeBlock.Code language="…" value={fmtCode\`…\`} />
277
- * </CodeBlock.Body>
278
- * <CodeBlock.ExpanderButton />
279
- * </CodeBlock.Root>
280
- * ```
252
+ * The optional expander button for collapsible code blocks.
281
253
  */
282
254
  readonly ExpanderButton: react.ForwardRefExoticComponent<Omit<CodeBlockExpanderButtonProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
283
255
  /**
284
- * The (optional) header slot of the `CodeBlock`. This is where things like the
285
- * `CodeBlock.Icon` and `CodeBlock.Title` are rendered.
286
- *
287
- * @see https://mantle.ngrok.com/components/code-block#codeblockheader
288
- *
289
- * @example
290
- * ```tsx
291
- * <CodeBlock.Root>
292
- * <CodeBlock.Header>
293
- * <CodeBlock.Icon preset="file" />
294
- * <CodeBlock.Title>…</CodeBlock.Title>
295
- * </CodeBlock.Header>
296
- * <CodeBlock.Body>
297
- * <CodeBlock.Code language="…" value={fmtCode\`…\`} />
298
- * </CodeBlock.Body>
299
- * </CodeBlock.Root>
300
- * ```
256
+ * The optional header slot for icon and title.
301
257
  */
302
258
  readonly Header: react.ForwardRefExoticComponent<Omit<react.ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & WithAsChild, "ref"> & react.RefAttributes<HTMLDivElement>>;
303
259
  /**
304
- * A small icon that represents the type of code block being displayed,
305
- * rendered as an SVG next to the code block title in the code block header.
306
- *
307
- * You can pass in a custom SVG component or use one of the presets
308
- * (pass only one of `svg` or `preset`).
309
- *
310
- * @see https://mantle.ngrok.com/components/code-block#codeblockicon
311
- *
312
- * @example
313
- * ```tsx
314
- * <CodeBlock.Root>
315
- * <CodeBlock.Header>
316
- * <CodeBlock.Icon preset="file" />
317
- * <CodeBlock.Title>…</CodeBlock.Title>
318
- * </CodeBlock.Header>
319
- * </CodeBlock.Root>
320
- * ```
260
+ * A small icon for the code block header. Use `preset` or `svg`.
321
261
  */
322
262
  readonly Icon: typeof CodeBlockIconComponent;
323
263
  /**
324
- * The (optional) title of the `CodeBlock`. Default renders as an h3 element,
325
- * use asChild to render something else.
326
- *
327
- * @see https://mantle.ngrok.com/components/code-block#codeblocktitle
328
- *
329
- * @example
330
- * ```tsx
331
- * <CodeBlock.Root>
332
- * <CodeBlock.Header>
333
- * <CodeBlock.Icon preset="file" />
334
- * <CodeBlock.Title>example.js</CodeBlock.Title>
335
- * </CodeBlock.Header>
336
- * </CodeBlock.Root>
337
- * ```
264
+ * Conditionally renders children when the associated tab is active.
265
+ */
266
+ readonly TabContent: react.ForwardRefExoticComponent<Omit<CodeBlockTabContentProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
267
+ /**
268
+ * A tab list for the code block header. Renders pill-styled tabs for switching code.
269
+ */
270
+ readonly TabList: react.ForwardRefExoticComponent<Omit<CodeBlockTabListProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
271
+ /**
272
+ * A pill-styled tab trigger for the code block header. Must be inside `TabList`.
273
+ */
274
+ readonly TabTrigger: react.ForwardRefExoticComponent<Omit<CodeBlockTabTriggerProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
275
+ /**
276
+ * The optional title rendered in the header.
338
277
  */
339
278
  readonly Title: react.ForwardRefExoticComponent<HTMLAttributes<HTMLHeadingElement> & {
340
279
  asChild?: boolean;
@@ -363,26 +302,14 @@ declare const CodeBlock: {
363
302
  */
364
303
  declare function escapeHtml(value: string): string;
365
304
  //#endregion
366
- //#region src/components/code-block/fmt-code.d.ts
367
- type Primitive = string | number | boolean | undefined | null;
305
+ //#region src/components/code-block/has-more-than-n-lines.d.ts
368
306
  /**
369
- * Tagged template literal to format code blocks and normalize leading indentation
370
- */
371
- declare function fmtCode(strings: TemplateStringsArray, ...values: Primitive[]): string;
372
- //#endregion
373
- //#region src/components/code-block/normalize-indentation.d.ts
374
- type Options = {
375
- /**
376
- * The indentation type to use. Can be either "tabs" or "spaces".
377
- * @default "spaces"
378
- */
379
- indentation?: Indentation;
380
- };
381
- /**
382
- * Trim any leading and trailing whitespace/empty lines, convert leading
383
- * indentation to the given options.indentation
307
+ * Returns `true` if `value` has more than `maxLines` newline-delimited lines.
308
+ *
309
+ * This is equivalent to `value.split("\\n").length > maxLines`, but avoids
310
+ * allocating an intermediate array and can early-return once the threshold is exceeded.
384
311
  */
385
- declare function normalizeIndentation(value: string, options?: Options): string;
312
+ declare function hasMoreThanNLines(value: string, maxLines: number): boolean;
386
313
  //#endregion
387
- export { CodeBlock, type DefaultMeta, type Meta, type MetaInput, type Mode, type SupportedLanguage, defaultMeta, escapeHtml, fmtCode, formatLanguageClassName, isSupportedLanguage, normalizeIndentation, parseLanguage, parseMetastring, supportedLanguages };
314
+ export { CodeBlock, type CodeBlockPreElementInput, type DefaultMeta, type Indentation, type LineRange, type MantleCodeBlockValue, type MantleCodeOptions, type Meta, type MetaInput, type Mode, type ResolvePreRenderedCodeBlockPropsInput, type ResolvePreRenderedCodeBlockPropsResult, type ResolvedPreRenderedCodeBlockProps, type SupportedLanguage, createMantleCodeBlockValue, decorateHighlightedHtml, defaultMeta, escapeHtml, hasMoreThanNLines, inferIndentation, isIndentation, isSupportedLanguage, mantleCode, normalizeIndentation, normalizeValue, parseCodeBlockHighlightLines, parseCodeBlockLineNumberStart, parseCodeBlockShowLineNumbers, parseLanguage, parseMetastring, resolvePreRenderedCodeBlockProps, supportedLanguages, tokenizeMetastring };
388
315
  //# sourceMappingURL=code-block.d.ts.map
@@ -1,9 +1,3 @@
1
- import{t as e}from"./cx-D1HYnpvA.js";import{t}from"./icon-BMH0fD_b.js";import{t as n}from"./booleanish-CBGdPL3Q.js";import{t as r}from"./slot-D_ZUrdEW.js";import{t as i}from"./use-copy-to-clipboard-BCpEp-sO.js";import{t as a}from"./traffic-policy-file-CroUMbsd.js";import{CaretDownIcon as o}from"@phosphor-icons/react/CaretDown";import{createContext as s,forwardRef as c,useContext as l,useEffect as u,useId as d,useMemo as f,useRef as p,useState as m}from"react";import h from"clsx";import g from"tiny-invariant";import{Fragment as _,jsx as v,jsxs as y}from"react/jsx-runtime";import{CheckIcon as b}from"@phosphor-icons/react/Check";import{CopyIcon as x}from"@phosphor-icons/react/Copy";import{FileTextIcon as S}from"@phosphor-icons/react/FileText";import{TerminalIcon as C}from"@phosphor-icons/react/Terminal";import w from"prismjs";import"prismjs/components/prism-bash.js";import"prismjs/components/prism-csharp.js";import"prismjs/components/prism-css.js";import"prismjs/components/prism-go.js";import"prismjs/components/prism-java.js";import"prismjs/components/prism-javascript.js";import"prismjs/components/prism-json.js";import"prismjs/components/prism-jsx.js";import"prismjs/components/prism-markup.js";import"prismjs/components/prism-python.js";import"prismjs/components/prism-ruby.js";import"prismjs/components/prism-rust.js";import"prismjs/components/prism-tsx.js";import"prismjs/components/prism-typescript.js";import"prismjs/components/prism-yaml.js";function T(e){let t=-1;for(let n=0;n<e.length;n++){let r=e[n];if(r===`&`||r===`<`||r===`>`||r===`"`||r===`'`){t=n;break}}if(t===-1)return e;let n=e.slice(0,t);for(let r=t;r<e.length;r++){let t=e[r];switch(t){case`&`:n+=`&amp;`;break;case`<`:n+=`&lt;`;break;case`>`:n+=`&gt;`;break;case`"`:n+=`&quot;`;break;case`'`:n+=`&#39;`;break;default:n+=t}}return n}const E=[`tabs`,`spaces`];function D(e){return E.includes(e)}function O(e,t){return t||(j(e)?`tabs`:(M(e),`spaces`))}const k=new Set([`csharp`,`css`,`go`,`html`,`java`,`javascript`,`js`,`jsx`,`ts`,`tsx`,`typescript`,`xml`]),A=new Set([`python`,`py`,`yaml`,`yml`,`ruby`,`rb`]);function j(e){return k.has(e)}function M(e){return A.has(e)}function N(e,...t){if(!ee(e)||!Array.isArray(t))throw Error("It looks like you tried to call `fmtCode` as a function. Make sure to use it as a tagged template.\n Example: fmtCode`SELECT * FROM users`, not fmtCode('SELECT * FROM users')");let n=String.raw({raw:e},...t),r=P(n),i=n.trim().split(`
2
- `),a=Array(i.length);for(let e=0;e<i.length;e++){let t=i[e];t!=null&&(a[e]=F(t)?t:t.slice(r))}return a.join(`
3
- `)}function P(e){let t=1/0,n=0,r=!0;for(let i=0;i<e.length;i++){let a=e[i];if(r){if(a===` `||a===` `){n+=1;continue}if(a===`
4
- `||a===`\r`){n=0;continue}if(n<t&&(t=n,t===0))return 0;r=!1;continue}(a===`
5
- `||a===`\r`)&&(r=!0,n=0)}return t===1/0?0:t}function ee(e){return Array.isArray(e)&&`raw`in e&&Array.isArray(e.raw)}function F(e){let t=e[0];return t!=null&&t!==` `&&t!==` `}function I(e,t){let n=t?.indentation??`spaces`,r=e.replace(/\r\n?/g,`
6
- `),i=r.trim();if(i===``)return``;let a=P(r),o=i.split(`
7
- `),s=Array(o.length);for(let e=0;e<o.length;e++){let t=o[e];t!=null&&(s[e]=te(ne(t)?t:t.slice(a),n))}return s.join(`
8
- `)}function te(e,t){let n=0;for(;n<e.length;){let t=e[n];if(t!==` `&&t!==` `)break;n+=1}if(n===0||n===e.length)return e;let r=e.slice(0,n);return(t===`spaces`?r.replace(/\t/g,` `):r.replace(/ {2}/g,` `))+e.slice(n)}function ne(e){let t=e[0];return t!=null&&t!==` `&&t!==` `}const L=`bash.cs.csharp.css.dotnet.go.html.java.javascript.js.json.jsx.markup.plain.plaintext.py.python.rb.ruby.rust.sh.shell.text.ts.tsx.txt.typescript.xml.yaml.yml`.split(`.`),R=new Set(L);function z(e){if(!e)return`sh`;let t=e.trim().slice(e.indexOf(`-`)+1);return B(t)?t:`sh`}const B=e=>typeof e==`string`&&R.has(e);function V(e=`sh`){return`language-${e??`sh`}`}const H=new Map;function re(e,t){return`${e}\u0000${t}`}function ie(e,t,n){let r=re(e,t),i=H.get(r);if(i!=null)return H.delete(r),H.set(r,i),i;let a=w.highlight(t,n,e);if(H.set(r,a),H.size>100){let e=H.keys().next().value;e!=null&&H.delete(e)}return a}const U=s({codeId:void 0,copyText:``,hasCodeExpander:!1,isCodeExpanded:!1,registerCodeId:()=>{},setCopyText:()=>{},setHasCodeExpander:()=>{},setIsCodeExpanded:()=>{},unregisterCodeId:()=>{}}),W=c(({asChild:t=!1,className:n,...i},a)=>{let[o,s]=m(``),[c,l]=m(!1),[u,d]=m(!1),[p,h]=m(void 0),_=f(()=>({codeId:p,copyText:o,hasCodeExpander:c,isCodeExpanded:u,registerCodeId:e=>{h(t=>(g(t==null,`You can only render a single CodeBlockCode within a CodeBlock.`),e))},setCopyText:s,setHasCodeExpander:l,setIsCodeExpanded:d,unregisterCodeId:e=>{h(t=>{g(t===e,`You can only render a single CodeBlockCode within a CodeBlock.`)})}}),[p,o,c,u]),y=t?r:`div`;return v(U.Provider,{value:_,children:v(y,{"data-slot":`code-block`,className:e(`text-mono overflow-hidden rounded-md border border-gray-300 bg-gray-50 font-mono`,`[&_svg]:shrink-0`,n),ref:a,...i})})});W.displayName=`CodeBlock`;const G=c(({asChild:t=!1,className:n,...i},a)=>v(t?r:`div`,{className:e(`relative`,n),ref:a,...i}));G.displayName=`CodeBlockBody`;const K=c(({className:t,highlightLines:n,indentation:r,language:i=`text`,showLineNumbers:a,style:o,tabIndex:s,value:c,...p},_)=>{let y=d(),{hasCodeExpander:b,isCodeExpanded:x,registerCodeId:S,setCopyText:C,unregisterCodeId:E}=l(U),D=O(i,r),k=f(()=>I(c,{indentation:D}),[c,D]),A=f(()=>T(k),[k]),[j,M]=m(()=>A);u(()=>{let e=w.languages[i];g(e,`CodeBlock does not support the language "${i}". The syntax highlighter does not have a grammar for this language. The supported languages are: ${L.join(`, `)}.`),M(ie(i,k,e))},[k,i]),u(()=>{C(k)},[k,C]),u(()=>(S(y),()=>{E(y)}),[y,S,E]);let N=V(i);return v(`pre`,{"aria-expanded":b?x:void 0,className:e(`scrollbar overflow-x-auto overflow-y-hidden p-4 pr-14`,`text-mono m-0 font-mono`,`aria-collapsed:max-h-[13.6rem]`,N,t),"data-lang":i,id:y,ref:_,style:{...o,tabSize:2,MozTabSize:2},tabIndex:s??-1,...p,children:v(`code`,{className:h(`text-size-inherit`,N),dangerouslySetInnerHTML:{__html:j},suppressHydrationWarning:!0})})});K.displayName=`CodeBlockCode`;const q=c(({asChild:t=!1,className:n,...i},a)=>v(t?r:`div`,{className:e(`flex items-center gap-1 border-b border-gray-300 bg-gray-100 px-4 py-2 text-gray-700`,n),ref:a,...i}));q.displayName=`CodeBlockHeader`;const J=c(({asChild:t=!1,className:n,...i},a)=>v(t?r:`h3`,{ref:a,className:e(`text-mono m-0 font-mono font-normal`,n),...i}));J.displayName=`CodeBlockTitle`;const Y=c(({asChild:n=!1,className:a,onCopy:o,onCopyError:s,onClick:c,...d},f)=>{let{copyText:h}=l(U),[,g]=i(),[S,C]=m(!1),w=p(void 0);return u(()=>()=>{w.current!=null&&clearTimeout(w.current)},[]),y(n?r:`button`,{type:`button`,className:e(`focus-visible:border-accent-600 focus-visible:ring-focus-accent absolute right-2.5 top-2.5 z-10 flex size-7 items-center justify-center rounded border border-gray-300 bg-gray-50 shadow-[-1rem_0_0.75rem_-0.375rem_var(--color-gray-50),1rem_0_0_-0.25rem_var(--color-gray-50)] hover:border-gray-400 hover:bg-gray-200 focus-visible:outline-hidden focus-visible:ring-4`,S&&`bg-filled-success text-on-filled hover:bg-filled-success focus:bg-filled-success focus-visible:border-success-600 focus-visible:ring-focus-success w-auto gap-1 border-transparent pl-2 pr-1.5 hover:border-transparent`,a),ref:f,onClick:async e=>{try{if(c?.(e),e.defaultPrevented){w.current!=null&&clearTimeout(w.current);return}await g(h),o?.(h),C(!0),w.current!=null&&clearTimeout(w.current),w.current=setTimeout(()=>{C(!1)},2e3)}catch(e){s?.(e)}},...d,children:[v(`span`,{className:`sr-only`,children:`Copy code`}),S?y(_,{children:[`Copied`,v(t,{svg:v(b,{weight:`bold`}),className:`size-4`})]}):v(t,{svg:v(x,{}),className:`-ml-px`})]})});Y.displayName=`CodeBlockCopyButton`;const X=c(({asChild:n=!1,className:i,onClick:a,...s},c)=>{let{codeId:d,isCodeExpanded:f,setIsCodeExpanded:p,setHasCodeExpander:m}=l(U);return u(()=>(m(!0),()=>{m(!1)}),[m]),y(n?r:`button`,{...s,"aria-controls":d,"aria-expanded":f,className:e(`flex w-full items-center justify-center gap-0.5 border-t border-gray-300 bg-gray-50 px-4 py-2 font-sans text-gray-700 hover:bg-gray-100`,i),ref:c,type:`button`,onClick:e=>{p(e=>!e),a?.(e)},children:[f?`Show less`:`Show more`,` `,v(t,{svg:v(o,{weight:`bold`}),className:e(`size-4`,f&&`rotate-180`,`transition-all duration-150`)})]})});X.displayName=`CodeBlockExpanderButton`;function Z({className:e,preset:n,svg:r,...i}){let o=r;if(n!=null)switch(n){case`file`:o=v(S,{weight:`fill`});break;case`cli`:o=v(C,{weight:`fill`});break;case`traffic-policy`:o=v(a,{});break}return v(t,{className:e,svg:o,...i})}Z.displayName=`CodeBlockIcon`;const ae={Root:W,Body:G,Code:K,CopyButton:Y,ExpanderButton:X,Header:q,Icon:Z,Title:J},Q={collapsible:!1,disableCopy:!1,indentation:void 0,mode:void 0,title:void 0};function oe(e){let t=e?.trim()??``;if(!t)return Q;let n={},r=ce(t);for(let e of r){let t=e.indexOf(`=`),r=t===-1?e:e.slice(0,t),i=t===-1?void 0:e.slice(t+1);r&&(n[r]=se(i)??!0)}try{let e=$(n);return{...Q,...e}}catch{return Q}}function se(e){return e?.trim().replace(/^"(.*)"$/,`$1`)}function ce(e){let t=e?.trim()??``,n=[],r=``,i=!1;for(let e of t)e===` `&&!i?r&&=(n.push(r),``):(e===`"`&&(i=!i),r+=e);return r&&n.push(r),n}function le(e){return e===`cli`||e===`file`||e===`traffic-policy`}function $(e){let{collapsible:t=Q.collapsible,disableCopy:r=Q.disableCopy,indentation:i=Q.indentation,mode:a=Q.mode,title:o=Q.title}=e;return{collapsible:typeof t==`string`||typeof t==`boolean`?n(t):Q.collapsible,disableCopy:typeof r==`string`||typeof r==`boolean`?n(r):Q.disableCopy,indentation:D(i)?i:Q.indentation,mode:le(a)?a:Q.mode,title:typeof o==`string`?o.trim():Q.title}}export{ae as CodeBlock,Q as defaultMeta,T as escapeHtml,N as fmtCode,V as formatLanguageClassName,B as isSupportedLanguage,I as normalizeIndentation,z as parseLanguage,oe as parseMetastring,L as supportedLanguages};
1
+ import{t as e}from"./cx-D1HYnpvA.js";import{t}from"./icon-BMH0fD_b.js";import{t as n}from"./slot-D_ZUrdEW.js";import{t as r}from"./use-copy-to-clipboard-B6wH6hDd.js";import{t as i}from"./traffic-policy-file-CroUMbsd.js";import{a,c as o,d as s,f as c,h as l,i as u,l as d,m as f,n as p,o as m,p as h,r as g,s as _,t as v,u as y}from"./resolve-pre-rendered-props-Bu2cvS9A.js";import{CaretDownIcon as b}from"@phosphor-icons/react/CaretDown";import{createContext as x,forwardRef as S,useCallback as C,useContext as w,useEffect as T,useId as ee,useLayoutEffect as te,useMemo as E,useRef as D,useState as O}from"react";import k from"tiny-invariant";import{Fragment as ne,jsx as A,jsxs as j}from"react/jsx-runtime";import{CheckIcon as re}from"@phosphor-icons/react/Check";import{CopyIcon as ie}from"@phosphor-icons/react/Copy";import{FileTextIcon as M}from"@phosphor-icons/react/FileText";import{TerminalIcon as ae}from"@phosphor-icons/react/Terminal";import{Content as oe,List as se,Root as N,Trigger as ce}from"@radix-ui/react-tabs";function P(e){let t=-1;for(let n=0;n<e.length;n++){let r=e[n];if(r===`&`||r===`<`||r===`>`||r===`"`||r===`'`){t=n;break}}if(t===-1)return e;let n=e.slice(0,t);for(let r=t;r<e.length;r++){let t=e[r];switch(t){case`&`:n+=`&amp;`;break;case`<`:n+=`&lt;`;break;case`>`:n+=`&gt;`;break;case`"`:n+=`&quot;`;break;case`'`:n+=`&#39;`;break;default:n+=t}}return n}const F=x(null);function I(){let e=w(F);return k(e!=null,`CodeBlock subcomponents must be rendered within a <CodeBlock.Root>.`),e}const L=S(({asChild:t=!1,className:r,defaultTab:i,activeTab:a,onActiveTabChange:o,...s},c)=>{let l=D(``),[u,d]=O(!1),[f,p]=O(!1),[m,h]=O(void 0),g=C(e=>{h(t=>(k(t==null,`You can only render a single CodeBlock.Code within a CodeBlock.`),e))},[]),_=C(e=>{h(t=>{k(t===e,`You can only render a single CodeBlock.Code within a CodeBlock.`)})},[]),v=E(()=>({codeId:m,copyTextRef:l,hasCodeExpander:u,isCodeExpanded:f,registerCodeId:g,setHasCodeExpander:d,setIsCodeExpanded:p,unregisterCodeId:_}),[m,u,f,g,_]),y=i!==void 0||a!==void 0,b=A(t?n:`div`,{"data-slot":`code-block`,className:e(`text-mono w-full overflow-hidden rounded-md border border-gray-300 bg-gray-50 font-mono`,`[&_svg]:shrink-0`,r),ref:c,...s});return A(F.Provider,{value:v,children:y?A(N,{asChild:!0,defaultValue:i,value:a,onValueChange:o,children:b}):b})});L.displayName=`CodeBlock`;const R=S(({asChild:t=!1,className:r,...i},a)=>A(t?n:`div`,{className:e(`relative`,r),ref:a,...i}));R.displayName=`CodeBlockBody`;const le=/SHIKI_VAL_(\d+)/g;function ue(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}const z=new Map;function B(e){if(e==null||e.length===0)return le;let t=z.get(e);return t??(z.size>=500&&z.clear(),t=RegExp(`${ue(e)}(\\d+)__`,`g`),z.set(e,t)),t}function V(e,t,n,r){if(n==null){if(!e.includes(`SHIKI_VAL_`))return e}else if(!e.includes(n))return e;return e.replaceAll(B(n),(e,n)=>{let i=Number.parseInt(n,10);return Number.isNaN(i)||i<0||i>=t.length?e:r(t[i])})}function H(e,t,n){return V(e,t,n,e=>P(String(e)))}function de(e,t,n){return V(e,t,n,e=>String(e))}const U=S(({className:t,style:n,tabIndex:r,value:i,...a},o)=>{let s=ee(),{copyTextRef:c,hasCodeExpander:l,isCodeExpanded:u,registerCodeId:d,unregisterCodeId:f}=I(),{language:p,code:m,"~preValToken":h,"~preVals":g,"~highlightLines":_,"~lineNumberStart":v,"~preHtml":y,"~showLineNumbers":b}=i,x=_,S=v??1,C=b??!1,w=E(()=>g!=null&&g.length>0?de(m,g,h):m,[h,g,m]);te(()=>{c.current=w},[c,w]),T(()=>(d(s),()=>{f(s)}),[s,d,f]);let D=E(()=>{if(y!=null)return g!=null&&g.length>0?H(y,g,h):y},[y,h,g]),O=D!=null,k=D??P(w);return A(`pre`,{"aria-expanded":l?u:void 0,className:e(`scrollbar overflow-x-auto overflow-y-hidden py-4`,!O&&`pr-14`,`data-[mantle-line-numbers~='false']:pl-4`,`text-mono m-0 font-mono`,`aria-collapsed:max-h-[13.6rem]`,t),"data-highlighted":O?`true`:`false`,"data-lang":p,"data-mantle-highlight-lines":O&&x!=null&&x.length>0?x.join(`,`):void 0,"data-mantle-line-number-start":O&&C?String(S):`1`,"data-mantle-line-numbers":O&&C?`true`:`false`,id:s,ref:o,style:{...n,"--mantle-line-number-start":String(S),tabSize:2,MozTabSize:2},tabIndex:r??-1,...a,children:A(`code`,{className:`text-size-inherit block min-w-full w-max`,dangerouslySetInnerHTML:{__html:k}})})});U.displayName=`CodeBlockCode`;const W=S(({asChild:t=!1,className:r,...i},a)=>A(t?n:`div`,{className:e(`flex items-center gap-1 border-b border-gray-300 bg-gray-100 px-4 py-2 text-gray-700`,r),ref:a,...i}));W.displayName=`CodeBlockHeader`;const G=S(({asChild:t=!1,className:r,...i},a)=>A(t?n:`h3`,{ref:a,className:e(`text-mono m-0 font-mono font-normal`,r),...i}));G.displayName=`CodeBlockTitle`;const K=S(({asChild:i=!1,className:a,onCopy:o,onCopyError:s,onClick:c,...l},u)=>{let{copyTextRef:d}=I(),[,f]=r(),[p,m]=O(!1),h=D(void 0);return T(()=>()=>{h.current!=null&&clearTimeout(h.current)},[]),j(i?n:`button`,{type:`button`,className:e(`focus-visible:border-accent-600 focus-visible:ring-focus-accent absolute right-2.5 top-2.5 z-10 flex size-7 items-center justify-center rounded border border-gray-300 bg-gray-50 hover:border-gray-400 hover:bg-gray-200 focus-visible:outline-hidden focus-visible:ring-4`,`shadow-[-1rem_0_0.75rem_-0.375rem_var(--color-gray-50),1rem_0_0_-0.25rem_var(--color-gray-50)]`,p&&`bg-filled-success text-on-filled hover:bg-filled-success focus:bg-filled-success focus-visible:border-success-600 focus-visible:ring-focus-success w-auto gap-1 border-transparent pl-2 pr-1.5 hover:border-transparent`,a),ref:u,onClick:async e=>{try{if(c?.(e),e.defaultPrevented){h.current!=null&&clearTimeout(h.current);return}let t=d.current;await f(t),o?.(t),m(!0),h.current!=null&&clearTimeout(h.current),h.current=setTimeout(()=>{m(!1)},2e3)}catch(e){s?.(e)}},...l,children:[A(`span`,{className:`sr-only`,children:`Copy code`}),p?j(ne,{children:[`Copied`,A(t,{svg:A(re,{weight:`bold`}),className:`size-4`})]}):A(t,{svg:A(ie,{}),className:`-ml-px`})]})});K.displayName=`CodeBlockCopyButton`;const q=S(({asChild:r=!1,className:i,onClick:a,...o},s)=>{let{codeId:c,isCodeExpanded:l,setIsCodeExpanded:u,setHasCodeExpander:d}=I();return T(()=>(d(!0),()=>{d(!1)}),[d]),j(r?n:`button`,{...o,"aria-controls":c,"aria-expanded":l,className:e(`flex w-full items-center justify-center gap-0.5 border-t border-gray-300 bg-gray-50 px-4 py-2 font-sans text-gray-700 hover:bg-gray-100`,i),ref:s,type:`button`,onClick:e=>{u(e=>!e),a?.(e)},children:[l?`Show less`:`Show more`,` `,A(t,{svg:A(b,{weight:`bold`}),className:e(`size-4`,l&&`rotate-180`,`transition-all duration-150`)})]})});q.displayName=`CodeBlockExpanderButton`;function J({className:e,preset:n,svg:r,...a}){let o=r;if(n!=null)switch(n){case`file`:o=A(M,{weight:`fill`});break;case`cli`:o=A(ae,{weight:`fill`});break;case`traffic-policy`:o=A(i,{});break}return A(t,{className:e,svg:o,...a})}J.displayName=`CodeBlockIcon`;const Y=S(({className:t,...n},r)=>A(se,{className:e(`flex items-center gap-1`,t),ref:r,...n}));Y.displayName=`CodeBlockTabList`;const X=S(({className:t,...n},r)=>A(ce,{className:e(`cursor-pointer rounded-full px-3 py-1 text-sm font-medium`,`text-gray-600 outline-hidden`,`hover:text-gray-900`,`data-[state=active]:bg-accent-500/20 data-[state=active]:text-blue-700`,`focus-visible:ring-focus-accent focus-visible:ring-4`,t),ref:r,...n}));X.displayName=`CodeBlockTabTrigger`;const Z=S((e,t)=>A(oe,{ref:t,...e}));Z.displayName=`CodeBlockTabContent`;const Q={Root:L,Body:R,Code:U,CopyButton:K,ExpanderButton:q,Header:W,Icon:J,TabContent:Z,TabList:Y,TabTrigger:X,Title:G},fe=Symbol(`MantleCodeBlockValue`);function $({preHtml:e,preValToken:t,preVals:n,highlightLines:r,lineNumberStart:i,showLineNumbers:a,code:o,language:s}){return{[fe]:!0,language:s,code:o,"~preHtml":e,"~preValToken":t,"~preVals":n,"~highlightLines":r,"~lineNumberStart":i,"~showLineNumbers":a}}function pe(e,t){let n=``;for(let r=0;r<e.length;r+=1)n+=e[r]??``,r<t.length&&(n+=String(t[r]));return n}function me(e,t={}){return(n,...r)=>$({language:e,code:pe(n,r),preHtml:void 0,preVals:r.length>0?r:void 0,highlightLines:t.highlightLines,lineNumberStart:t.lineNumberStart,showLineNumbers:t.showLineNumbers})}function he(e,t){let n=1;if(n>t)return!0;for(let r=0;r<e.length;r++)if(e[r]===`
2
+ `&&(n+=1,n>t))return!0;return!1}export{Q as CodeBlock,$ as createMantleCodeBlockValue,l as decorateHighlightedHtml,v as defaultMeta,P as escapeHtml,he as hasMoreThanNLines,h as inferIndentation,f as isIndentation,d as isSupportedLanguage,me as mantleCode,c as normalizeIndentation,p as normalizeValue,m as parseCodeBlockHighlightLines,_ as parseCodeBlockLineNumberStart,o as parseCodeBlockShowLineNumbers,y as parseLanguage,g as parseMetastring,u as resolvePreRenderedCodeBlockProps,s as supportedLanguages,a as tokenizeMetastring};
9
3
  //# sourceMappingURL=code-block.js.map