@kumix/ui 0.3.9 → 0.3.11

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 (169) hide show
  1. package/README.md +15 -14
  2. package/dist/components/motion/adaptive-stepper.d.ts +32 -0
  3. package/dist/components/motion/adaptive-stepper.d.ts.map +1 -0
  4. package/dist/components/motion/adaptive-stepper.js +302 -0
  5. package/dist/components/motion/adaptive-stepper.js.map +1 -0
  6. package/dist/components/motion/animated-sidebar.d.ts.map +1 -1
  7. package/dist/components/motion/animated-sidebar.js.map +1 -1
  8. package/dist/components/motion/availability-scheduler/copy-menu.js +1 -1
  9. package/dist/components/motion/availability-scheduler/day-row.d.ts.map +1 -1
  10. package/dist/components/motion/availability-scheduler/day-row.js +15 -7
  11. package/dist/components/motion/availability-scheduler/day-row.js.map +1 -1
  12. package/dist/components/motion/availability-scheduler/index.js +1 -1
  13. package/dist/components/motion/button/index.d.ts +2 -1
  14. package/dist/components/motion/button/index.js +2 -1
  15. package/dist/components/motion/button/metallic.d.ts +10 -0
  16. package/dist/components/motion/button/metallic.d.ts.map +1 -0
  17. package/dist/components/motion/button/metallic.js +71 -0
  18. package/dist/components/motion/button/metallic.js.map +1 -0
  19. package/dist/components/motion/combobox/content.js +1 -1
  20. package/dist/components/motion/combobox/context.js +216 -1
  21. package/dist/components/motion/combobox/context.js.map +1 -0
  22. package/dist/components/motion/combobox/list.js +1 -1
  23. package/dist/components/motion/combobox/trigger.js +1 -1
  24. package/dist/components/motion/combobox.js +1 -1
  25. package/dist/components/motion/expandable-control.d.ts +28 -0
  26. package/dist/components/motion/expandable-control.d.ts.map +1 -0
  27. package/dist/components/motion/expandable-control.js +149 -0
  28. package/dist/components/motion/expandable-control.js.map +1 -0
  29. package/dist/components/motion/expanding-arrow-button.d.ts +12 -0
  30. package/dist/components/motion/expanding-arrow-button.d.ts.map +1 -0
  31. package/dist/components/motion/expanding-arrow-button.js +142 -0
  32. package/dist/components/motion/expanding-arrow-button.js.map +1 -0
  33. package/dist/components/motion/file-tree.d.ts +42 -0
  34. package/dist/components/motion/file-tree.d.ts.map +1 -0
  35. package/dist/components/motion/file-tree.js +272 -0
  36. package/dist/components/motion/file-tree.js.map +1 -0
  37. package/dist/components/motion/input.d.ts +2 -0
  38. package/dist/components/motion/input.d.ts.map +1 -1
  39. package/dist/components/motion/input.js +28 -25
  40. package/dist/components/motion/input.js.map +1 -1
  41. package/dist/components/motion/liquid.d.ts +30 -0
  42. package/dist/components/motion/liquid.d.ts.map +1 -0
  43. package/dist/components/motion/liquid.js +248 -0
  44. package/dist/components/motion/liquid.js.map +1 -0
  45. package/dist/components/motion/multi-select/content.d.ts +16 -0
  46. package/dist/components/motion/multi-select/content.d.ts.map +1 -0
  47. package/dist/components/motion/multi-select/content.js +91 -0
  48. package/dist/components/motion/multi-select/content.js.map +1 -0
  49. package/dist/components/motion/multi-select/context.d.ts +64 -0
  50. package/dist/components/motion/multi-select/context.d.ts.map +1 -0
  51. package/dist/{context-BizvUNZv.js → components/motion/multi-select/context.js} +44 -114
  52. package/dist/components/motion/multi-select/context.js.map +1 -0
  53. package/dist/components/motion/multi-select/index.d.ts +5 -0
  54. package/dist/components/motion/multi-select/index.js +6 -0
  55. package/dist/components/motion/multi-select/list.d.ts +40 -0
  56. package/dist/components/motion/multi-select/list.d.ts.map +1 -0
  57. package/dist/components/motion/multi-select/list.js +144 -0
  58. package/dist/components/motion/multi-select/list.js.map +1 -0
  59. package/dist/components/motion/multi-select/trigger.d.ts +22 -0
  60. package/dist/components/motion/multi-select/trigger.d.ts.map +1 -0
  61. package/dist/components/motion/multi-select/trigger.js +185 -0
  62. package/dist/components/motion/multi-select/trigger.js.map +1 -0
  63. package/dist/components/motion/signup-form.js +6 -2
  64. package/dist/components/motion/signup-form.js.map +1 -1
  65. package/dist/components/motion/table/index.js.map +1 -1
  66. package/dist/components/reui/alert.d.ts +1 -1
  67. package/dist/components/reui/badge.d.ts +1 -1
  68. package/dist/components/reui/cascader/cascader-async.d.ts.map +1 -1
  69. package/dist/components/reui/cascader/cascader-async.js.map +1 -1
  70. package/dist/components/reui/cascader/cascader-virtual.d.ts.map +1 -1
  71. package/dist/components/reui/cascader/cascader-virtual.js.map +1 -1
  72. package/dist/components/reui/cascader/cascader.d.ts.map +1 -1
  73. package/dist/components/reui/cascader/cascader.js.map +1 -1
  74. package/dist/components/reui/code-block/code-block-highlight.d.ts +216 -0
  75. package/dist/components/reui/code-block/code-block-highlight.d.ts.map +1 -0
  76. package/dist/components/reui/code-block/code-block-highlight.js +792 -0
  77. package/dist/components/reui/code-block/code-block-highlight.js.map +1 -0
  78. package/dist/components/reui/code-block/code-block.d.ts +197 -0
  79. package/dist/components/reui/code-block/code-block.d.ts.map +1 -0
  80. package/dist/components/reui/code-block/code-block.js +1150 -0
  81. package/dist/components/reui/code-block/code-block.js.map +1 -0
  82. package/dist/components/reui/data-grid/data-grid-cell-selection.d.ts +117 -0
  83. package/dist/components/reui/data-grid/data-grid-cell-selection.d.ts.map +1 -0
  84. package/dist/components/reui/data-grid/data-grid-cell-selection.js +1554 -0
  85. package/dist/components/reui/data-grid/data-grid-cell-selection.js.map +1 -0
  86. package/dist/components/reui/data-grid/data-grid-column-filter.d.ts.map +1 -1
  87. package/dist/components/reui/data-grid/data-grid-column-filter.js +6 -4
  88. package/dist/components/reui/data-grid/data-grid-column-filter.js.map +1 -1
  89. package/dist/components/reui/data-grid/data-grid-column-header.d.ts.map +1 -1
  90. package/dist/components/reui/data-grid/data-grid-column-header.js +10 -7
  91. package/dist/components/reui/data-grid/data-grid-column-header.js.map +1 -1
  92. package/dist/components/reui/data-grid/data-grid-column-visibility.js +3 -2
  93. package/dist/components/reui/data-grid/data-grid-column-visibility.js.map +1 -1
  94. package/dist/components/reui/data-grid/data-grid-i18n.d.ts +2 -0
  95. package/dist/components/reui/data-grid/data-grid-i18n.js +53 -0
  96. package/dist/components/reui/data-grid/data-grid-i18n.js.map +1 -0
  97. package/dist/components/reui/data-grid/data-grid-pagination.js +14 -8
  98. package/dist/components/reui/data-grid/data-grid-pagination.js.map +1 -1
  99. package/dist/components/reui/data-grid/data-grid-scroll-area.d.ts.map +1 -1
  100. package/dist/components/reui/data-grid/data-grid-scroll-area.js +3 -3
  101. package/dist/components/reui/data-grid/data-grid-scroll-area.js.map +1 -1
  102. package/dist/components/reui/data-grid/data-grid-table-dnd-rows.d.ts.map +1 -1
  103. package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js +6 -4
  104. package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js.map +1 -1
  105. package/dist/components/reui/data-grid/data-grid-table-dnd.js +2 -2
  106. package/dist/components/reui/data-grid/data-grid-table-dnd.js.map +1 -1
  107. package/dist/components/reui/data-grid/data-grid-table-virtual.d.ts +17 -1
  108. package/dist/components/reui/data-grid/data-grid-table-virtual.d.ts.map +1 -1
  109. package/dist/components/reui/data-grid/data-grid-table-virtual.js +146 -50
  110. package/dist/components/reui/data-grid/data-grid-table-virtual.js.map +1 -1
  111. package/dist/components/reui/data-grid/data-grid-table.d.ts +23 -4
  112. package/dist/components/reui/data-grid/data-grid-table.d.ts.map +1 -1
  113. package/dist/components/reui/data-grid/data-grid-table.js +215 -68
  114. package/dist/components/reui/data-grid/data-grid-table.js.map +1 -1
  115. package/dist/components/reui/data-grid/data-grid.d.ts +276 -6
  116. package/dist/components/reui/data-grid/data-grid.d.ts.map +1 -1
  117. package/dist/components/reui/data-grid/data-grid.js +150 -15
  118. package/dist/components/reui/data-grid/data-grid.js.map +1 -1
  119. package/dist/components/reui/filters/filters-advanced.js.map +1 -1
  120. package/dist/components/reui/filters/filters-chip.js.map +1 -1
  121. package/dist/components/reui/filters/filters.d.ts.map +1 -1
  122. package/dist/components/reui/filters/filters.js.map +1 -1
  123. package/dist/components/reui/frame.d.ts +1 -1
  124. package/dist/components/reui/gantt/gantt-bar.js +42 -12
  125. package/dist/components/reui/gantt/gantt-bar.js.map +1 -1
  126. package/dist/components/reui/gantt/gantt-dnd.d.ts.map +1 -1
  127. package/dist/components/reui/gantt/gantt-dnd.js +22 -7
  128. package/dist/components/reui/gantt/gantt-dnd.js.map +1 -1
  129. package/dist/components/reui/gantt/gantt-i18n.d.ts +8 -0
  130. package/dist/components/reui/gantt/gantt-i18n.d.ts.map +1 -1
  131. package/dist/components/reui/gantt/gantt-i18n.js +6 -1
  132. package/dist/components/reui/gantt/gantt-i18n.js.map +1 -1
  133. package/dist/components/reui/gantt/gantt-lib.d.ts +59 -2
  134. package/dist/components/reui/gantt/gantt-lib.d.ts.map +1 -1
  135. package/dist/components/reui/gantt/gantt-lib.js +67 -2
  136. package/dist/components/reui/gantt/gantt-lib.js.map +1 -1
  137. package/dist/components/reui/gantt/gantt-recurrence.js +3 -3
  138. package/dist/components/reui/gantt/gantt-recurrence.js.map +1 -1
  139. package/dist/components/reui/gantt/gantt-types.d.ts +32 -1
  140. package/dist/components/reui/gantt/gantt-types.d.ts.map +1 -1
  141. package/dist/components/reui/gantt/gantt-view.d.ts.map +1 -1
  142. package/dist/components/reui/gantt/gantt-view.js +324 -35
  143. package/dist/components/reui/gantt/gantt-view.js.map +1 -1
  144. package/dist/components/reui/gantt/gantt.d.ts +71 -2
  145. package/dist/components/reui/gantt/gantt.d.ts.map +1 -1
  146. package/dist/components/reui/gantt/gantt.js +8 -0
  147. package/dist/components/reui/gantt/gantt.js.map +1 -1
  148. package/dist/components/reui/icon-tile.d.ts +1 -1
  149. package/dist/components/ui/attachment.d.ts +1 -1
  150. package/dist/components/ui/badge.d.ts +1 -1
  151. package/dist/components/ui/bubble.d.ts +1 -1
  152. package/dist/components/ui/button-group.d.ts +1 -1
  153. package/dist/components/ui/button.d.ts +1 -1
  154. package/dist/components/ui/field.d.ts +1 -1
  155. package/dist/components/ui/item.d.ts +1 -1
  156. package/dist/components/ui/message-scroller.js +1 -1
  157. package/dist/components/ui/message-scroller.js.map +1 -1
  158. package/dist/components/ui/sidebar.d.ts +1 -1
  159. package/dist/components/ui/toggle.d.ts +1 -1
  160. package/dist/{copy-menu-1FKoMc9o.js → copy-menu-C5GaT4Z-.js} +67 -2
  161. package/dist/copy-menu-C5GaT4Z-.js.map +1 -0
  162. package/dist/data-grid-i18n-52UUYPbr.d.ts +66 -0
  163. package/dist/data-grid-i18n-52UUYPbr.d.ts.map +1 -0
  164. package/dist/types-smkWN_7x.d.ts.map +1 -1
  165. package/dist/use-active-option-CmX6Z-4S.js +86 -0
  166. package/dist/use-active-option-CmX6Z-4S.js.map +1 -0
  167. package/package.json +7 -13
  168. package/dist/context-BizvUNZv.js.map +0 -1
  169. package/dist/copy-menu-1FKoMc9o.js.map +0 -1
@@ -0,0 +1,792 @@
1
+ "use client";
2
+ //#region src/components/reui/code-block/code-block-highlight.tsx
3
+ /**
4
+ * A STATIC map, never ``import(`shiki/langs/${lang}.mjs`)``: a template import
5
+ * makes bundlers bundle all ~200 grammars. Written out, each entry is its own
6
+ * lazy chunk. To add a language, add a line: that is the intended extension
7
+ * point of this file.
8
+ */
9
+ const codeBlockLanguages = {
10
+ bash: () => import("shiki/langs/bash.mjs"),
11
+ c: () => import("shiki/langs/c.mjs"),
12
+ cpp: () => import("shiki/langs/cpp.mjs"),
13
+ csharp: () => import("shiki/langs/csharp.mjs"),
14
+ css: () => import("shiki/langs/css.mjs"),
15
+ diff: () => import("shiki/langs/diff.mjs"),
16
+ docker: () => import("shiki/langs/docker.mjs"),
17
+ go: () => import("shiki/langs/go.mjs"),
18
+ graphql: () => import("shiki/langs/graphql.mjs"),
19
+ html: () => import("shiki/langs/html.mjs"),
20
+ java: () => import("shiki/langs/java.mjs"),
21
+ javascript: () => import("shiki/langs/javascript.mjs"),
22
+ json: () => import("shiki/langs/json.mjs"),
23
+ jsx: () => import("shiki/langs/jsx.mjs"),
24
+ kotlin: () => import("shiki/langs/kotlin.mjs"),
25
+ markdown: () => import("shiki/langs/markdown.mjs"),
26
+ php: () => import("shiki/langs/php.mjs"),
27
+ python: () => import("shiki/langs/python.mjs"),
28
+ ruby: () => import("shiki/langs/ruby.mjs"),
29
+ rust: () => import("shiki/langs/rust.mjs"),
30
+ scss: () => import("shiki/langs/scss.mjs"),
31
+ shell: () => import("shiki/langs/shellscript.mjs"),
32
+ sql: () => import("shiki/langs/sql.mjs"),
33
+ swift: () => import("shiki/langs/swift.mjs"),
34
+ toml: () => import("shiki/langs/toml.mjs"),
35
+ tsx: () => import("shiki/langs/tsx.mjs"),
36
+ typescript: () => import("shiki/langs/typescript.mjs"),
37
+ vue: () => import("shiki/langs/vue.mjs"),
38
+ yaml: () => import("shiki/langs/yaml.mjs")
39
+ };
40
+ /** Spellings a consumer is likely to pass, mapped onto the map above. */
41
+ const LANGUAGE_ALIASES = {
42
+ "c++": "cpp",
43
+ "c#": "csharp",
44
+ cs: "csharp",
45
+ dockerfile: "docker",
46
+ htm: "html",
47
+ js: "javascript",
48
+ jsonc: "json",
49
+ md: "markdown",
50
+ mdx: "markdown",
51
+ py: "python",
52
+ rb: "ruby",
53
+ rs: "rust",
54
+ sh: "shell",
55
+ shellscript: "shell",
56
+ ts: "typescript",
57
+ yml: "yaml",
58
+ zsh: "shell"
59
+ };
60
+ const codeBlockThemes = {
61
+ "github-light": () => import("shiki/themes/github-light.mjs"),
62
+ "github-dark": () => import("shiki/themes/github-dark.mjs"),
63
+ /**
64
+ * Design-token theming: every token colour becomes a `var(--code-token-*)`
65
+ * reference, so the palette lives in the consumer's stylesheet and follows
66
+ * their themes. Pass as BOTH sides. Variables consumed (prefix `--code-`):
67
+ * foreground, token-constant, token-string, token-comment, token-keyword,
68
+ * token-parameter, token-function, token-string-expression,
69
+ * token-punctuation, token-link.
70
+ */
71
+ "css-variables": async () => {
72
+ const { createCssVariablesTheme } = await import("shiki/core");
73
+ return createCssVariablesTheme({
74
+ name: "css-variables",
75
+ variablePrefix: "--code-",
76
+ fontStyle: true
77
+ });
78
+ }
79
+ };
80
+ const DEFAULT_CODE_BLOCK_THEMES = {
81
+ light: "github-light",
82
+ dark: "github-dark"
83
+ };
84
+ /** Resolves an alias and reports whether the grammar is actually available. */
85
+ function resolveCodeBlockLanguage(language) {
86
+ if (!language) return void 0;
87
+ const normalized = language.trim().toLowerCase();
88
+ const resolved = LANGUAGE_ALIASES[normalized] ?? normalized;
89
+ return resolved in codeBlockLanguages ? resolved : void 0;
90
+ }
91
+ /**
92
+ * Turns `[2, 3]` or `"2-4,7"` into a set of source line numbers.
93
+ *
94
+ * Deliberately total: a reversed range, a negative bound or outright garbage
95
+ * yields an empty set rather than throwing. These values often come from user
96
+ * content or from a model, and a code viewer that crashes on a bad range is
97
+ * worse than one that shows no highlight.
98
+ */
99
+ function parseLineSpec(spec) {
100
+ const out = /* @__PURE__ */ new Set();
101
+ if (!spec) return out;
102
+ if (Array.isArray(spec)) {
103
+ for (const value of spec) if (Number.isInteger(value) && value > 0) out.add(value);
104
+ return out;
105
+ }
106
+ for (const part of spec.split(",")) {
107
+ const trimmed = part.trim();
108
+ if (!trimmed) continue;
109
+ const range = trimmed.match(/^(\d+)\s*-\s*(\d+)$/);
110
+ if (range) {
111
+ const start = Number(range[1]);
112
+ const end = Number(range[2]);
113
+ if (start > 0 && end >= start) for (let line = start; line <= end; line += 1) out.add(line);
114
+ continue;
115
+ }
116
+ if (/^\d+$/.test(trimmed)) {
117
+ const single = Number(trimmed);
118
+ if (single > 0) out.add(single);
119
+ }
120
+ }
121
+ return out;
122
+ }
123
+ /** Normalises line endings so every downstream offset is LF-based. */
124
+ function normalizeCode(code) {
125
+ return code.replace(/\r\n?/g, "\n");
126
+ }
127
+ /**
128
+ * Character ranges for `highlightedWords`, as shiki `decorations`.
129
+ *
130
+ * shiki rejects overlapping decorations, so a later match that would overlap an
131
+ * earlier one is dropped rather than passed through to throw.
132
+ */
133
+ function buildWordDecorations(code, words) {
134
+ if (!words?.length) return [];
135
+ const lineStarts = [0];
136
+ for (let index = 0; index < code.length; index += 1) if (code[index] === "\n") lineStarts.push(index + 1);
137
+ const lineAt = (offset) => {
138
+ let low = 0;
139
+ let high = lineStarts.length - 1;
140
+ while (low < high) {
141
+ const mid = Math.ceil((low + high) / 2);
142
+ if (lineStarts[mid] <= offset) low = mid;
143
+ else high = mid - 1;
144
+ }
145
+ return low + 1;
146
+ };
147
+ const taken = [];
148
+ const out = [];
149
+ for (const entry of words) {
150
+ const word = typeof entry === "string" ? entry : entry.word;
151
+ if (!word) continue;
152
+ const limit = typeof entry === "string" ? void 0 : parseLineSpec(entry.lines);
153
+ let from = code.indexOf(word);
154
+ while (from !== -1) {
155
+ const to = from + word.length;
156
+ const withinLimit = !limit || limit.size === 0 || limit.has(lineAt(from));
157
+ const overlaps = taken.some((r) => from < r.end && to > r.start);
158
+ if (withinLimit && !overlaps) {
159
+ taken.push({
160
+ start: from,
161
+ end: to
162
+ });
163
+ out.push({
164
+ start: from,
165
+ end: to,
166
+ properties: { class: "cb-word" }
167
+ });
168
+ }
169
+ from = code.indexOf(word, from + word.length);
170
+ }
171
+ }
172
+ return out.sort((a, b) => a.start - b.start);
173
+ }
174
+ /**
175
+ * Strips `[!code ...]` notation from a copy payload: the transformer already
176
+ * drops it from RENDERED output, but the raw `code` string would paste the
177
+ * comment into someone's editor.
178
+ */
179
+ function stripNotationComments(code) {
180
+ return code.split("\n").map((line) => line.replace(/\s*(?:\/\/|#|--|;|%|<!--|\/\*)\s*\[!code[^\]]*\]\s*(?:-->|\*\/)?\s*$/, "")).join("\n");
181
+ }
182
+ /**
183
+ * Plain, unhighlighted lines. One token per line, no colour.
184
+ *
185
+ * This is both the `highlight={false}` renderer and the first paint of a
186
+ * streaming block, so the tail of a stream is readable before its grammar pass
187
+ * lands and no frame is ever blank.
188
+ */
189
+ function toPlainLines(code, startLine = 1) {
190
+ return normalizeCode(code).split("\n").map((text, index) => ({
191
+ tokens: text ? [{ content: text }] : [],
192
+ number: startLine + index,
193
+ text
194
+ }));
195
+ }
196
+ /**
197
+ * Pulls `code` and `language` out of the props react-markdown gives a `pre`:
198
+ * the glue every AI chat app writes by hand, shipped here instead. Tolerant by
199
+ * construction, because a still-streaming fence has no closing delimiter and
200
+ * often no language yet, and must render as plain text rather than throw.
201
+ */
202
+ function markdownCodeProps(props) {
203
+ let language;
204
+ let code = "";
205
+ const readClassName = (value) => {
206
+ if (typeof value !== "string") return;
207
+ const match = value.match(/(?:^|\s)language-([\w+#-]+)/);
208
+ if (match && !language) language = match[1];
209
+ };
210
+ const walk = (node) => {
211
+ if (node === null || node === void 0 || node === false) return;
212
+ if (typeof node === "string") {
213
+ code += node;
214
+ return;
215
+ }
216
+ if (typeof node === "number") {
217
+ code += String(node);
218
+ return;
219
+ }
220
+ if (Array.isArray(node)) {
221
+ for (const child of node) walk(child);
222
+ return;
223
+ }
224
+ if (typeof node === "object" && "props" in node) {
225
+ const nodeProps = node.props;
226
+ if (!nodeProps) return;
227
+ readClassName(nodeProps.className);
228
+ walk(nodeProps.children);
229
+ }
230
+ };
231
+ readClassName(props.className);
232
+ walk(props.children);
233
+ return {
234
+ code: code.replace(/\n$/, ""),
235
+ language
236
+ };
237
+ }
238
+ /**
239
+ * Splits markdown into prose and fenced code, for transcripts that render a
240
+ * raw assistant message without a markdown dependency. The unterminated
241
+ * trailing fence is the point: mid-stream it comes back as a code part flagged
242
+ * `open`, instead of being dropped or read as prose.
243
+ */
244
+ function markdownFences(markdown) {
245
+ const parts = [];
246
+ const lines = markdown.split("\n");
247
+ let inFence = false;
248
+ let opener = "";
249
+ let language;
250
+ let buffer = [];
251
+ const flushText = () => {
252
+ const text = buffer.join("\n").trim();
253
+ if (text) parts.push({
254
+ type: "text",
255
+ content: text,
256
+ open: false
257
+ });
258
+ buffer = [];
259
+ };
260
+ const flushCode = (open) => {
261
+ parts.push({
262
+ type: "code",
263
+ content: buffer.join("\n"),
264
+ language,
265
+ open
266
+ });
267
+ buffer = [];
268
+ language = void 0;
269
+ };
270
+ for (const line of lines) {
271
+ const fence = line.match(/^\s*(`{3,}|~{3,})([\w+#-]*)\s*$/);
272
+ if (fence && !inFence) {
273
+ flushText();
274
+ inFence = true;
275
+ opener = fence[1];
276
+ language = fence[2] || void 0;
277
+ continue;
278
+ }
279
+ if (fence && inFence && fence[1][0] === opener[0] && fence[1].length >= opener.length && !fence[2]) {
280
+ flushCode(false);
281
+ inFence = false;
282
+ continue;
283
+ }
284
+ buffer.push(line);
285
+ }
286
+ if (inFence) flushCode(true);
287
+ else flushText();
288
+ return parts;
289
+ }
290
+ let highlighterPromise = null;
291
+ const loadedLanguages = /* @__PURE__ */ new Set();
292
+ const loadedThemes = /* @__PURE__ */ new Set();
293
+ /**
294
+ * One highlighter per page, on the JavaScript regex engine: oniguruma needs
295
+ * WebAssembly, which forces `'wasm-unsafe-eval'` into every consumer's CSP.
296
+ * `forgiving` keeps an inexpressible grammar pattern from taking the block
297
+ * down.
298
+ */
299
+ async function loadHighlighter() {
300
+ if (!highlighterPromise) highlighterPromise = (async () => {
301
+ const [{ createHighlighterCore }, { createJavaScriptRegexEngine }] = await Promise.all([import("shiki/core"), import("shiki/engine/javascript")]);
302
+ return await createHighlighterCore({
303
+ themes: [],
304
+ langs: [],
305
+ engine: createJavaScriptRegexEngine({ forgiving: true })
306
+ });
307
+ })();
308
+ return highlighterPromise;
309
+ }
310
+ /**
311
+ * Themes register per name, on demand, exactly like languages.
312
+ *
313
+ * Baking the FIRST caller's pair into the singleton looks correct until a page
314
+ * holds two blocks with different `themes` props: the second silently renders
315
+ * in the first one's colours, because the singleton never learns about the
316
+ * request. Loading by name makes every block's prop actually mean something.
317
+ */
318
+ const warnedThemes = /* @__PURE__ */ new Set();
319
+ async function ensureTheme(highlighter, name, side = "light") {
320
+ const resolved = name in codeBlockThemes ? name : DEFAULT_CODE_BLOCK_THEMES[side];
321
+ if (resolved !== name && process.env.NODE_ENV !== "production" && !warnedThemes.has(name)) {
322
+ warnedThemes.add(name);
323
+ console.warn(`[code-block] Unknown theme "${name}" - falling back to "${resolved}". Register it in codeBlockThemes to use it.`);
324
+ }
325
+ if (loadedThemes.has(resolved)) return resolved;
326
+ await highlighter.loadTheme(await codeBlockThemes[resolved]());
327
+ loadedThemes.add(resolved);
328
+ return resolved;
329
+ }
330
+ async function ensureLanguage(highlighter, language) {
331
+ if (loadedLanguages.has(language)) return;
332
+ const loader = codeBlockLanguages[language];
333
+ if (!loader) return;
334
+ await highlighter.loadLanguage(await loader());
335
+ loadedLanguages.add(language);
336
+ }
337
+ const FONT_STYLE_BY_DECLARATION = {
338
+ "font-style:italic": "italic",
339
+ "font-weight:bold": "bold",
340
+ "text-decoration:underline": "underline"
341
+ };
342
+ /** Splits shiki's inline `style` string into the fields a token carries. */
343
+ function readTokenStyle(style) {
344
+ if (typeof style !== "string") return {};
345
+ const out = {};
346
+ for (const declaration of style.split(";")) {
347
+ const trimmed = declaration.trim();
348
+ if (!trimmed) continue;
349
+ const separator = trimmed.indexOf(":");
350
+ if (separator === -1) continue;
351
+ const property = trimmed.slice(0, separator).trim();
352
+ const value = trimmed.slice(separator + 1).trim();
353
+ if (property === "color") out.color = value;
354
+ else if (property === "--shiki-dark") out.colorDark = value;
355
+ else {
356
+ const fontStyle = FONT_STYLE_BY_DECLARATION[`${property}:${value}`];
357
+ if (fontStyle) out.fontStyle = fontStyle;
358
+ }
359
+ }
360
+ return out;
361
+ }
362
+ /**
363
+ * shiki emits raw `class` (string or array), not hast's `className`; reading
364
+ * only `className` finds nothing, which looks like a transformer that never
365
+ * ran.
366
+ */
367
+ function classListOf(node) {
368
+ const value = node.properties?.class ?? node.properties?.className;
369
+ if (Array.isArray(value)) return value.map(String);
370
+ if (typeof value === "string") return value.split(/\s+/).filter(Boolean);
371
+ return [];
372
+ }
373
+ /** Maps the classes shiki transformers put on a line onto line state. */
374
+ function stateFromClasses(classes) {
375
+ const state = {};
376
+ if (classes.includes("highlighted")) state.highlighted = true;
377
+ if (classes.includes("focused")) state.focused = true;
378
+ if (classes.includes("diff")) {
379
+ if (classes.includes("add")) state.diff = "add";
380
+ else if (classes.includes("remove")) state.diff = "remove";
381
+ }
382
+ for (const level of [
383
+ "error",
384
+ "warning",
385
+ "info"
386
+ ]) if (classes.includes(level)) state.level = level;
387
+ return Object.keys(state).length ? state : void 0;
388
+ }
389
+ function collectTokens(node, out, inWord) {
390
+ for (const child of node.children ?? []) {
391
+ if (child.type === "text") {
392
+ if (!child.value) continue;
393
+ out.push(inWord ? {
394
+ content: child.value,
395
+ word: true
396
+ } : { content: child.value });
397
+ continue;
398
+ }
399
+ if (child.type !== "element") continue;
400
+ const classes = classListOf(child);
401
+ const childInWord = inWord || classes.includes("cb-word");
402
+ const style = readTokenStyle(child.properties?.style);
403
+ const hasStyle = Boolean(style.color || style.colorDark || style.fontStyle);
404
+ const onlyText = (child.children ?? []).every((grandChild) => grandChild.type === "text");
405
+ if (hasStyle && onlyText) {
406
+ const content = (child.children ?? []).map((c) => c.value ?? "").join("");
407
+ if (!content) continue;
408
+ out.push({
409
+ content,
410
+ ...style,
411
+ ...childInWord ? { word: true } : {}
412
+ });
413
+ continue;
414
+ }
415
+ collectTokens(child, out, childInWord);
416
+ }
417
+ }
418
+ function findCodeElement(root) {
419
+ if (root.type === "element" && root.tagName === "code") return root;
420
+ for (const child of root.children ?? []) {
421
+ const found = findCodeElement(child);
422
+ if (found) return found;
423
+ }
424
+ }
425
+ const MAX_TRACKED_DOCUMENTS = 24;
426
+ /**
427
+ * Previous result per option signature, so a growing stream can reuse lines.
428
+ * Keyed WITH the caller's instanceKey: without it, two same-configured blocks
429
+ * evicted each other's entry on every interleaved pass. Bounded above because
430
+ * module state outlives requests on the server.
431
+ */
432
+ const previousDocuments = /* @__PURE__ */ new Map();
433
+ function sameLine(a, b) {
434
+ if (a.number !== b.number || a.text !== b.text) return false;
435
+ if (a.tokens.length !== b.tokens.length) return false;
436
+ if (JSON.stringify(a.state ?? null) !== JSON.stringify(b.state ?? null)) return false;
437
+ for (let index = 0; index < a.tokens.length; index += 1) {
438
+ const left = a.tokens[index];
439
+ const right = b.tokens[index];
440
+ if (left.content !== right.content || left.color !== right.color || left.colorDark !== right.colorDark || left.fontStyle !== right.fontStyle || left.word !== right.word) return false;
441
+ }
442
+ return true;
443
+ }
444
+ /**
445
+ * Swaps freshly built lines for the previous pass's objects where nothing
446
+ * changed. This is why streaming is cheap: the row is a reference-equality
447
+ * `memo`, so without this, appending one token to a 400 line file re-renders
448
+ * 400 subtrees per chunk.
449
+ */
450
+ function reuseUnchangedLines(key, next) {
451
+ const previous = previousDocuments.get(key);
452
+ if (previous) for (let index = 0; index < next.length; index += 1) {
453
+ const before = previous[index];
454
+ if (before && sameLine(before, next[index])) next[index] = before;
455
+ }
456
+ previousDocuments.set(key, next);
457
+ if (previousDocuments.size > MAX_TRACKED_DOCUMENTS) {
458
+ const oldest = previousDocuments.keys().next().value;
459
+ if (oldest !== void 0) previousDocuments.delete(oldest);
460
+ }
461
+ return next;
462
+ }
463
+ function applyPropState(lines, options) {
464
+ const highlighted = parseLineSpec(options.highlightedLines);
465
+ const focused = parseLineSpec(options.focusedLines);
466
+ const added = parseLineSpec(options.diff?.added);
467
+ const removed = parseLineSpec(options.diff?.removed);
468
+ const levels = {
469
+ error: parseLineSpec(options.lineLevels?.error),
470
+ warning: parseLineSpec(options.lineLevels?.warning),
471
+ info: parseLineSpec(options.lineLevels?.info)
472
+ };
473
+ lines.forEach((line, index) => {
474
+ const source = index + 1;
475
+ const state = { ...line.state };
476
+ if (highlighted.has(source)) state.highlighted = true;
477
+ if (focused.has(source)) state.focused = true;
478
+ if (added.has(source)) state.diff = "add";
479
+ else if (removed.has(source)) state.diff = "remove";
480
+ for (const level of [
481
+ "error",
482
+ "warning",
483
+ "info"
484
+ ]) if (levels[level].has(source)) state.level = level;
485
+ line.state = Object.keys(state).length ? state : void 0;
486
+ });
487
+ }
488
+ /**
489
+ * Highlights `code` into the renderer's line shape. Built on `codeToHast` so
490
+ * consumer transformers run and their line classes land in `line.state`,
491
+ * making prop state and `[!code ++]` notation one feature, not two code
492
+ * paths. Safe in a server component: the result is plain JSON.
493
+ */
494
+ async function highlightCode(code, options = {}) {
495
+ const source = normalizeCode(code);
496
+ const startLine = options.startLine ?? 1;
497
+ const language = resolveCodeBlockLanguage(options.language);
498
+ if (!language) return toPlainLines(source, startLine);
499
+ const themes = options.themes ?? DEFAULT_CODE_BLOCK_THEMES;
500
+ const signature = JSON.stringify([
501
+ options.instanceKey ?? null,
502
+ language,
503
+ themes,
504
+ startLine,
505
+ options.highlightedLines ?? null,
506
+ options.highlightedWords ?? null,
507
+ options.focusedLines ?? null,
508
+ options.diff ?? null,
509
+ options.lineLevels ?? null,
510
+ (options.transformers ?? []).length
511
+ ]);
512
+ let root;
513
+ try {
514
+ const highlighter = await loadHighlighter();
515
+ const [light, dark] = await Promise.all([ensureTheme(highlighter, themes.light), ensureTheme(highlighter, themes.dark)]);
516
+ await ensureLanguage(highlighter, language);
517
+ root = highlighter.codeToHast(source, {
518
+ lang: language,
519
+ themes: {
520
+ light,
521
+ dark
522
+ },
523
+ defaultColor: "light",
524
+ cssVariablePrefix: "--shiki-",
525
+ decorations: buildWordDecorations(source, options.highlightedWords),
526
+ ...options.transformers?.length ? { transformers: options.transformers } : {}
527
+ });
528
+ } catch {
529
+ return toPlainLines(source, startLine);
530
+ }
531
+ const codeElement = findCodeElement(root);
532
+ if (!codeElement) return toPlainLines(source, startLine);
533
+ const lines = [];
534
+ for (const child of codeElement.children ?? []) {
535
+ if (child.type !== "element") continue;
536
+ const tokens = [];
537
+ collectTokens(child, tokens, false);
538
+ lines.push({
539
+ tokens,
540
+ number: startLine + lines.length,
541
+ text: tokens.map((token) => token.content).join(""),
542
+ state: stateFromClasses(classListOf(child))
543
+ });
544
+ }
545
+ if (!lines.length) return toPlainLines(source, startLine);
546
+ applyPropState(lines, options);
547
+ return reuseUnchangedLines(signature, lines);
548
+ }
549
+ /** Test seam: drops the singleton and every cached document. */
550
+ function resetCodeBlockHighlighter() {
551
+ highlighterPromise = null;
552
+ loadedLanguages.clear();
553
+ loadedThemes.clear();
554
+ previousDocuments.clear();
555
+ }
556
+ /**
557
+ * The 16 SGR slots as CSS variables with readable defaults per theme, so a
558
+ * consumer retints terminal output next to their other design tokens
559
+ * (`--code-ansi-red`, `--code-ansi-bright-blue`, ...). 256-colour and
560
+ * truecolor sequences bypass the palette and emit their literal colour.
561
+ */
562
+ const ANSI_SLOTS = [
563
+ "black",
564
+ "red",
565
+ "green",
566
+ "yellow",
567
+ "blue",
568
+ "magenta",
569
+ "cyan",
570
+ "white",
571
+ "bright-black",
572
+ "bright-red",
573
+ "bright-green",
574
+ "bright-yellow",
575
+ "bright-blue",
576
+ "bright-magenta",
577
+ "bright-cyan",
578
+ "bright-white"
579
+ ];
580
+ const ANSI_LIGHT = [
581
+ "#3f3f46",
582
+ "#dc2626",
583
+ "#16a34a",
584
+ "#a16207",
585
+ "#2563eb",
586
+ "#9333ea",
587
+ "#0891b2",
588
+ "#71717a",
589
+ "#52525b",
590
+ "#ef4444",
591
+ "#22c55e",
592
+ "#ca8a04",
593
+ "#3b82f6",
594
+ "#a855f7",
595
+ "#06b6d4",
596
+ "#a1a1aa"
597
+ ];
598
+ const ANSI_DARK = [
599
+ "#a1a1aa",
600
+ "#f87171",
601
+ "#4ade80",
602
+ "#facc15",
603
+ "#60a5fa",
604
+ "#c084fc",
605
+ "#22d3ee",
606
+ "#e4e4e7",
607
+ "#71717a",
608
+ "#fca5a5",
609
+ "#86efac",
610
+ "#fde047",
611
+ "#93c5fd",
612
+ "#d8b4fe",
613
+ "#67e8f9",
614
+ "#fafafa"
615
+ ];
616
+ const ansiVar = (slot, fallback) => `var(--code-ansi-${ANSI_SLOTS[slot]}, ${fallback})`;
617
+ /** xterm 256-colour index to hex, computed rather than tabled. */
618
+ function ansi256(index) {
619
+ if (index < 16) return ANSI_DARK[index];
620
+ if (index >= 232) {
621
+ const h = (8 + (index - 232) * 10).toString(16).padStart(2, "0");
622
+ return `#${h}${h}${h}`;
623
+ }
624
+ const cube = [
625
+ 0,
626
+ 95,
627
+ 135,
628
+ 175,
629
+ 215,
630
+ 255
631
+ ];
632
+ const n = index - 16;
633
+ const to = (v) => cube[v].toString(16).padStart(2, "0");
634
+ return `#${to(Math.floor(n / 36))}${to(Math.floor(n / 6) % 6)}${to(n % 6)}`;
635
+ }
636
+ const SGR_RE = /\x1b\[([0-9;]*)m/g;
637
+ const OTHER_ESCAPES_RE = /\x1b(?:\[(?![0-9;]*m)[0-9;?]*[A-Za-z]|\][^\x07]*(?:\x07|\x1b\\)|[()][0-9A-B])/g;
638
+ /**
639
+ * Terminal output with SGR colour codes, as renderable lines: feed the result
640
+ * to the `lines` prop. Covers what agent stdout actually uses - 30-37 / 90-97
641
+ * foregrounds, 38;5;n and 38;2;r;g;b, bold, italic, underline and resets.
642
+ * Backgrounds and cursor movements are STRIPPED rather than rendered: a code
643
+ * surface has its own background, and a partial screen-drawing stream is
644
+ * better read as text than half-drawn.
645
+ */
646
+ function ansiToLines(text, startLine = 1) {
647
+ return normalizeCode(text).replace(OTHER_ESCAPES_RE, "").split("\n").map((raw, index) => {
648
+ const tokens = [];
649
+ const style = {};
650
+ let plain = "";
651
+ let last = 0;
652
+ const flush = (content) => {
653
+ if (!content) return;
654
+ const fontStyle = style.bold ? "bold" : style.italic ? "italic" : style.underline ? "underline" : void 0;
655
+ tokens.push({
656
+ content,
657
+ color: style.color,
658
+ colorDark: style.colorDark,
659
+ fontStyle
660
+ });
661
+ };
662
+ SGR_RE.lastIndex = 0;
663
+ let match;
664
+ while (match = SGR_RE.exec(raw)) {
665
+ flush(raw.slice(last, match.index));
666
+ plain += raw.slice(last, match.index);
667
+ last = match.index + match[0].length;
668
+ const params = (match[1] || "0").split(";").map(Number);
669
+ for (let i = 0; i < params.length; i += 1) {
670
+ const code = params[i];
671
+ if (code === 0) {
672
+ delete style.color;
673
+ delete style.colorDark;
674
+ style.bold = style.italic = style.underline = false;
675
+ } else if (code === 1) style.bold = true;
676
+ else if (code === 3) style.italic = true;
677
+ else if (code === 4) style.underline = true;
678
+ else if (code === 22) style.bold = false;
679
+ else if (code === 23) style.italic = false;
680
+ else if (code === 24) style.underline = false;
681
+ else if (code === 39) {
682
+ delete style.color;
683
+ delete style.colorDark;
684
+ } else if (code >= 30 && code <= 37) {
685
+ style.color = ansiVar(code - 30, ANSI_LIGHT[code - 30]);
686
+ style.colorDark = ansiVar(code - 30, ANSI_DARK[code - 30]);
687
+ } else if (code >= 90 && code <= 97) {
688
+ style.color = ansiVar(code - 82, ANSI_LIGHT[code - 82]);
689
+ style.colorDark = ansiVar(code - 82, ANSI_DARK[code - 82]);
690
+ } else if (code === 38 && params[i + 1] === 5) {
691
+ style.color = style.colorDark = ansi256(params[i + 2] ?? 0);
692
+ i += 2;
693
+ } else if (code === 38 && params[i + 1] === 2) {
694
+ const [r, g, b] = [
695
+ params[i + 2] ?? 0,
696
+ params[i + 3] ?? 0,
697
+ params[i + 4] ?? 0
698
+ ];
699
+ style.color = style.colorDark = `#${[
700
+ r,
701
+ g,
702
+ b
703
+ ].map((v) => v.toString(16).padStart(2, "0")).join("")}`;
704
+ i += 4;
705
+ } else if (code === 48 && (params[i + 1] === 5 || params[i + 1] === 2)) i += params[i + 1] === 5 ? 2 : 4;
706
+ }
707
+ }
708
+ flush(raw.slice(last));
709
+ plain += raw.slice(last);
710
+ return {
711
+ number: startLine + index,
712
+ text: plain,
713
+ tokens
714
+ };
715
+ });
716
+ }
717
+ /**
718
+ * A `git diff` / unified patch, as renderable per-file line sets: feed each
719
+ * file's `lines` to the `lines` prop and the diff tints, `+`/`-` glyphs and
720
+ * dual old/new gutter numbers all come from the parse - no `diff` prop
721
+ * arithmetic against a hand-concatenated string. Tokens are plain; patches
722
+ * read by tint, not grammar.
723
+ */
724
+ function parseUnifiedDiff(patch) {
725
+ const files = [];
726
+ let current = null;
727
+ let oldNumber = 0;
728
+ let newNumber = 0;
729
+ let width = 4;
730
+ const push = (text, state, gutter) => {
731
+ if (!current) return;
732
+ current.lines.push({
733
+ number: current.lines.length + 1,
734
+ text,
735
+ tokens: [{ content: text }],
736
+ state,
737
+ gutter
738
+ });
739
+ };
740
+ const pad = (value) => (value === null ? "" : String(value)).padStart(width);
741
+ for (const raw of normalizeCode(patch).split("\n")) {
742
+ const fileHeader = raw.match(/^diff --git a\/(.+) b\/(.+)$/);
743
+ const plusHeader = raw.match(/^\+\+\+ (?:b\/)?(.+)$/);
744
+ if (fileHeader || plusHeader) {
745
+ const name = fileHeader ? fileHeader[2] : plusHeader[1];
746
+ if (name !== "/dev/null" && (!current || current.file !== name)) {
747
+ current = {
748
+ file: name,
749
+ lines: [],
750
+ added: 0,
751
+ removed: 0,
752
+ hunks: []
753
+ };
754
+ files.push(current);
755
+ }
756
+ continue;
757
+ }
758
+ if (/^(---|index |old mode|new mode|new file|deleted file|similarity|rename |Binary )/.test(raw)) continue;
759
+ const hunk = raw.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/);
760
+ if (hunk && current) {
761
+ oldNumber = Number(hunk[1]);
762
+ newNumber = Number(hunk[3]);
763
+ width = Math.max(String(oldNumber + Number(hunk[2] ?? 0)).length, String(newNumber + Number(hunk[4] ?? 0)).length, 2);
764
+ current.hunks.push({
765
+ header: raw,
766
+ at: current.lines.length + 1
767
+ });
768
+ push(hunk[5].trim() || raw, { level: "info" }, `${"·".padStart(width)} ${"·".padStart(width)}`);
769
+ continue;
770
+ }
771
+ if (!current || !raw && files.length === 0) continue;
772
+ if (raw.startsWith("+")) {
773
+ push(raw.slice(1), { diff: "add" }, `${pad(null)} ${pad(newNumber)}`);
774
+ newNumber += 1;
775
+ current.added += 1;
776
+ } else if (raw.startsWith("-")) {
777
+ push(raw.slice(1), { diff: "remove" }, `${pad(oldNumber)} ${pad(null)}`);
778
+ oldNumber += 1;
779
+ current.removed += 1;
780
+ } else if (raw.startsWith(" ") || raw === "") {
781
+ if (current.lines.length === 0 && raw === "") continue;
782
+ push(raw.slice(1), void 0, `${pad(oldNumber)} ${pad(newNumber)}`);
783
+ oldNumber += 1;
784
+ newNumber += 1;
785
+ }
786
+ }
787
+ return files;
788
+ }
789
+ //#endregion
790
+ export { DEFAULT_CODE_BLOCK_THEMES, ansiToLines, buildWordDecorations, codeBlockLanguages, codeBlockThemes, highlightCode, markdownCodeProps, markdownFences, normalizeCode, parseLineSpec, parseUnifiedDiff, resetCodeBlockHighlighter, resolveCodeBlockLanguage, stripNotationComments, toPlainLines };
791
+
792
+ //# sourceMappingURL=code-block-highlight.js.map