@sdxc/ui 2026.11.11 → 2026.11.17

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 (204) hide show
  1. package/README.md +114 -61
  2. package/dist/app/app-shell-toggle.d.ts +2 -0
  3. package/dist/app/app-shell-toggle.js +5 -2
  4. package/dist/app/app-shell.d.ts +25 -1
  5. package/dist/app/app-shell.js +73 -38
  6. package/dist/app/auto-refresh.d.ts +2 -0
  7. package/dist/app/auto-refresh.js +3 -3
  8. package/dist/app/behaviors/refresh-schedule.d.ts +8 -3
  9. package/dist/app/behaviors/refresh-schedule.js +4 -3
  10. package/dist/app/board.d.ts +123 -0
  11. package/dist/app/board.js +224 -0
  12. package/dist/app/chart.d.ts +2 -2
  13. package/dist/app/chart.js +7 -3
  14. package/dist/app/check-runs.d.ts +116 -0
  15. package/dist/app/check-runs.js +201 -0
  16. package/dist/app/code-view.d.ts +172 -0
  17. package/dist/app/code-view.js +414 -0
  18. package/dist/app/command-palette.d.ts +38 -3
  19. package/dist/app/command-palette.js +53 -5
  20. package/dist/app/contribution-graph.d.ts +106 -0
  21. package/dist/app/contribution-graph.js +289 -0
  22. package/dist/app/detail-sheet.d.ts +7 -0
  23. package/dist/app/detail-sheet.js +7 -7
  24. package/dist/app/diff.d.ts +200 -0
  25. package/dist/app/diff.js +702 -0
  26. package/dist/app/filter-bar.d.ts +20 -0
  27. package/dist/app/filter-bar.js +35 -15
  28. package/dist/app/filter-menu.d.ts +144 -0
  29. package/dist/app/filter-menu.js +480 -0
  30. package/dist/app/gantt.d.ts +108 -0
  31. package/dist/app/gantt.js +420 -0
  32. package/dist/app/index.d.ts +20 -0
  33. package/dist/app/index.js +20 -0
  34. package/dist/app/log-viewer.d.ts +120 -0
  35. package/dist/app/log-viewer.js +384 -0
  36. package/dist/app/merge-box.d.ts +97 -0
  37. package/dist/app/merge-box.js +227 -0
  38. package/dist/app/mixins/app-shell-controls.d.ts +4 -1
  39. package/dist/app/mixins/app-shell-controls.js +64 -4
  40. package/dist/app/mixins/auto-refresh.d.ts +5 -2
  41. package/dist/app/mixins/auto-refresh.js +9 -3
  42. package/dist/app/mixins/close-popover-on-submit.d.ts +16 -0
  43. package/dist/app/mixins/close-popover-on-submit.js +32 -0
  44. package/dist/app/mixins/code-view-selection.d.ts +60 -0
  45. package/dist/app/mixins/code-view-selection.js +276 -0
  46. package/dist/app/mixins/command-palette.d.ts +15 -4
  47. package/dist/app/mixins/command-palette.js +94 -6
  48. package/dist/app/mixins/contribution-graph-keys.d.ts +19 -0
  49. package/dist/app/mixins/contribution-graph-keys.js +155 -0
  50. package/dist/app/mixins/diff-interactions.d.ts +72 -0
  51. package/dist/app/mixins/diff-interactions.js +269 -0
  52. package/dist/app/mixins/filter-menu-keys.d.ts +41 -0
  53. package/dist/app/mixins/filter-menu-keys.js +91 -0
  54. package/dist/app/mixins/gantt-today.d.ts +17 -0
  55. package/dist/app/mixins/gantt-today.js +50 -0
  56. package/dist/app/mixins/log-viewer.d.ts +29 -0
  57. package/dist/app/mixins/log-viewer.js +347 -0
  58. package/dist/app/mixins/optimistic-toggle-sync.d.ts +5 -0
  59. package/dist/app/mixins/optimistic-toggle-sync.js +25 -1
  60. package/dist/app/mixins/save-bar-sync.d.ts +7 -1
  61. package/dist/app/mixins/save-bar-sync.js +23 -4
  62. package/dist/app/mixins/save-status-sync.js +23 -1
  63. package/dist/app/mixins/split-view.js +1 -1
  64. package/dist/app/mixins/submit-on-close.d.ts +17 -0
  65. package/dist/app/mixins/submit-on-close.js +52 -0
  66. package/dist/app/mixins/tree-filter.d.ts +44 -0
  67. package/dist/app/mixins/tree-filter.js +111 -0
  68. package/dist/app/mixins/tree-navigation.d.ts +50 -0
  69. package/dist/app/mixins/tree-navigation.js +216 -0
  70. package/dist/app/optimistic-toggle.d.ts +8 -0
  71. package/dist/app/optimistic-toggle.js +3 -2
  72. package/dist/app/page-header.d.ts +18 -3
  73. package/dist/app/page-header.js +105 -50
  74. package/dist/app/profile-picker.d.ts +47 -0
  75. package/dist/app/profile-picker.js +104 -0
  76. package/dist/app/review-thread.d.ts +115 -0
  77. package/dist/app/review-thread.js +116 -0
  78. package/dist/app/save-bar.d.ts +5 -0
  79. package/dist/app/save-bar.js +1 -1
  80. package/dist/app/save-status.js +1 -1
  81. package/dist/app/settings-layout.d.ts +5 -0
  82. package/dist/app/settings-layout.js +5 -5
  83. package/dist/app/skeleton.d.ts +9 -0
  84. package/dist/app/skeleton.js +28 -0
  85. package/dist/app/split-view.d.ts +4 -0
  86. package/dist/app/split-view.js +3 -3
  87. package/dist/app/styles/code-tokens.d.ts +24 -0
  88. package/dist/app/styles/code-tokens.js +47 -0
  89. package/dist/app/tab-bar.d.ts +59 -0
  90. package/dist/app/tab-bar.js +111 -0
  91. package/dist/app/tree.d.ts +111 -14
  92. package/dist/app/tree.js +202 -15
  93. package/dist/app/utils/ansi.d.ts +55 -0
  94. package/dist/app/utils/ansi.js +157 -0
  95. package/dist/app/utils/diff-rows.d.ts +82 -0
  96. package/dist/app/utils/diff-rows.js +209 -0
  97. package/dist/app/utils/fuzzy-path.d.ts +58 -0
  98. package/dist/app/utils/fuzzy-path.js +202 -0
  99. package/dist/app/utils/line-range.d.ts +48 -0
  100. package/dist/app/utils/line-range.js +61 -0
  101. package/dist/app/utils/log-lines.d.ts +107 -0
  102. package/dist/app/utils/log-lines.js +170 -0
  103. package/dist/app/utils/tree-filter.d.ts +19 -0
  104. package/dist/app/utils/tree-filter.js +26 -0
  105. package/dist/app/view-options.d.ts +2 -0
  106. package/dist/app/view-options.js +2 -2
  107. package/dist/chat/activity.d.ts +72 -0
  108. package/dist/chat/activity.js +184 -0
  109. package/dist/chat/composer-submit.d.ts +38 -0
  110. package/dist/chat/composer-submit.js +44 -0
  111. package/dist/chat/composer.d.ts +47 -0
  112. package/dist/chat/composer.js +100 -0
  113. package/dist/chat/index.d.ts +6 -0
  114. package/dist/chat/index.js +6 -0
  115. package/dist/chat/mixins/composer-send.d.ts +32 -0
  116. package/dist/chat/mixins/composer-send.js +121 -0
  117. package/dist/chat/mixins/reveal-stream.d.ts +68 -0
  118. package/dist/chat/mixins/reveal-stream.js +184 -0
  119. package/dist/chat/mixins/stream-target.d.ts +18 -0
  120. package/dist/chat/mixins/stream-target.js +38 -0
  121. package/dist/components/button.js +7 -1
  122. package/dist/components/character-count.d.ts +44 -0
  123. package/dist/components/character-count.js +68 -0
  124. package/dist/components/index.d.ts +2 -0
  125. package/dist/components/index.js +2 -0
  126. package/dist/components/label-chip.d.ts +42 -0
  127. package/dist/components/label-chip.js +86 -0
  128. package/dist/components/property-list.d.ts +9 -2
  129. package/dist/components/property-list.js +37 -10
  130. package/dist/components/textarea.js +6 -1
  131. package/dist/components/timeline.d.ts +62 -5
  132. package/dist/components/timeline.js +124 -5
  133. package/dist/docs/code-block.js +8 -31
  134. package/dist/docs/file-tree.js +3 -48
  135. package/dist/landing/case-study.d.ts +79 -0
  136. package/dist/landing/case-study.js +162 -0
  137. package/dist/landing/contributor-wall.d.ts +72 -0
  138. package/dist/landing/contributor-wall.js +129 -0
  139. package/dist/landing/countdown.d.ts +88 -0
  140. package/dist/landing/countdown.js +91 -0
  141. package/dist/landing/episode-player.d.ts +87 -0
  142. package/dist/landing/episode-player.js +113 -0
  143. package/dist/landing/faq-band.d.ts +3 -2
  144. package/dist/landing/faq-band.js +4 -3
  145. package/dist/landing/index.d.ts +7 -0
  146. package/dist/landing/index.js +7 -0
  147. package/dist/landing/landing-header.js +15 -4
  148. package/dist/landing/mixins/countdown-tick.d.ts +29 -0
  149. package/dist/landing/mixins/countdown-tick.js +65 -0
  150. package/dist/landing/mixins/usage-estimate-live.d.ts +32 -0
  151. package/dist/landing/mixins/usage-estimate-live.js +120 -0
  152. package/dist/landing/phone-frame.d.ts +2 -1
  153. package/dist/landing/price-list.d.ts +68 -0
  154. package/dist/landing/price-list.js +125 -0
  155. package/dist/landing/scroll-scene.d.ts +59 -0
  156. package/dist/landing/scroll-scene.js +70 -0
  157. package/dist/landing/sponsor-wall.d.ts +30 -6
  158. package/dist/landing/sponsor-wall.js +70 -14
  159. package/dist/landing/typed-terminal.d.ts +24 -6
  160. package/dist/landing/typed-terminal.js +22 -14
  161. package/dist/landing/usage-estimate.d.ts +127 -0
  162. package/dist/landing/usage-estimate.js +164 -0
  163. package/dist/landing/utils/countdown.d.ts +33 -0
  164. package/dist/landing/utils/countdown.js +42 -0
  165. package/dist/landing/utils/pause-toggle.d.ts +2 -1
  166. package/dist/mixins/character-count.d.ts +62 -0
  167. package/dist/mixins/character-count.js +139 -0
  168. package/dist/mixins/index.d.ts +6 -2
  169. package/dist/mixins/index.js +6 -2
  170. package/dist/mixins/invoker-fields.d.ts +18 -0
  171. package/dist/mixins/invoker-fields.js +60 -0
  172. package/dist/mixins/media-sync.d.ts +58 -0
  173. package/dist/mixins/media-sync.js +102 -0
  174. package/dist/mixins/menu-keys.d.ts +11 -0
  175. package/dist/mixins/menu-keys.js +79 -70
  176. package/dist/mixins/sortable.d.ts +96 -0
  177. package/dist/mixins/sortable.js +433 -0
  178. package/dist/utils/code-lines.d.ts +26 -0
  179. package/dist/utils/code-lines.js +29 -0
  180. package/dist/utils/file-icon.d.ts +31 -0
  181. package/dist/utils/file-icon.js +60 -0
  182. package/dist/utils/index.d.ts +2 -0
  183. package/dist/utils/index.js +2 -0
  184. package/dist/utils/write-cookie.d.ts +15 -15
  185. package/dist/utils/write-cookie.js +10 -16
  186. package/dist/video/episode-list.d.ts +48 -0
  187. package/dist/video/episode-list.js +161 -0
  188. package/dist/video/index.d.ts +15 -0
  189. package/dist/video/index.js +15 -0
  190. package/dist/video/mixins/video-player-sync.d.ts +27 -0
  191. package/dist/video/mixins/video-player-sync.js +413 -0
  192. package/dist/video/mixins/video-shelf-steps.d.ts +20 -0
  193. package/dist/video/mixins/video-shelf-steps.js +79 -0
  194. package/dist/video/title-hero.d.ts +51 -0
  195. package/dist/video/title-hero.js +170 -0
  196. package/dist/video/utils/timeline.d.ts +55 -0
  197. package/dist/video/utils/timeline.js +90 -0
  198. package/dist/video/video-card.d.ts +51 -0
  199. package/dist/video/video-card.js +135 -0
  200. package/dist/video/video-player.d.ts +261 -0
  201. package/dist/video/video-player.js +927 -0
  202. package/dist/video/video-shelf.d.ts +58 -0
  203. package/dist/video/video-shelf.js +155 -0
  204. package/package.json +6 -3
@@ -0,0 +1,209 @@
1
+ /**
2
+ * The arithmetic a diff view draws from: hunk headers as git writes them, deleted and added
3
+ * lines paired for the split view, each side of a hunk highlighted as one run of source,
4
+ * word ranges cut into marked runs, and the five-block bar of a file's change.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { tokenizeLines } from "@sdxc/highlight";
10
+ /** Blocks a file's change bar draws. */
11
+ export const CHANGE_BLOCKS = 5;
12
+ /**
13
+ * Highlighted runs per hunk, keyed by language, so a page that draws a hunk twice (a file
14
+ * and its thread excerpt) tokenizes it once. Keyed on the hunk object, the cache lives as
15
+ * long as the parsed patch does.
16
+ */
17
+ const HUNK_TOKENS = new WeakMap();
18
+ /**
19
+ * Writes a hunk's header line as git does: `@@ -20,7 +20,8 @@ section`, leaving out a count
20
+ * of 1, so the text matches the patch it came from.
21
+ *
22
+ * @param hunk The hunk to name.
23
+ * @returns The header text, section included when the hunk has one.
24
+ * @example hunkHeader({ oldStart: 20, oldLines: 7, newStart: 20, newLines: 8, lines: [] }) // "@@ -20,7 +20,8 @@"
25
+ */
26
+ export function hunkHeader(hunk) {
27
+ let side = (start, count) => (count === 1 ? `${start}` : `${start},${count}`);
28
+ let header = `@@ -${side(hunk.oldStart, hunk.oldLines)} +${side(hunk.newStart, hunk.newLines)} @@`;
29
+ return hunk.section ? `${header} ${hunk.section}` : header;
30
+ }
31
+ /**
32
+ * Pairs a hunk's lines for the split view: a context line fills both sides, and a run of
33
+ * deletions followed by a run of additions lines up row by row, the shorter run leaving
34
+ * fillers on its side.
35
+ *
36
+ * @param lines The hunk's lines, in patch order.
37
+ * @returns One row per drawn line pair.
38
+ */
39
+ export function splitRows(lines) {
40
+ let rows = [];
41
+ let index = 0;
42
+ while (index < lines.length) {
43
+ if (lines[index].kind === "context") {
44
+ rows.push({ old: index, new: index });
45
+ index += 1;
46
+ continue;
47
+ }
48
+ let dels = [];
49
+ let adds = [];
50
+ while (index < lines.length && lines[index].kind === "del")
51
+ dels.push(index++);
52
+ while (index < lines.length && lines[index].kind === "add")
53
+ adds.push(index++);
54
+ for (let pair = 0; pair < Math.max(dels.length, adds.length); pair += 1) {
55
+ rows.push({ old: dels[pair], new: adds[pair] });
56
+ }
57
+ }
58
+ return rows;
59
+ }
60
+ /**
61
+ * Highlights a hunk as two runs of source, the old side (context and deletions) and the new
62
+ * side (context and additions), each tokenized in one pass, so a string or comment that
63
+ * spans lines inside the hunk paints whole. Context lines take the new side's runs.
64
+ *
65
+ * @param hunk The hunk to highlight.
66
+ * @param language The language its file highlights as; omitted, every line is one plain run.
67
+ * @returns One list of runs per entry of `hunk.lines`.
68
+ */
69
+ export function hunkTokens(hunk, language) {
70
+ if (!language) {
71
+ return hunk.lines.map((line) => (line.text ? [{ type: "plain", value: line.text }] : []));
72
+ }
73
+ let byLanguage = HUNK_TOKENS.get(hunk);
74
+ let cached = byLanguage?.get(language);
75
+ if (cached)
76
+ return cached;
77
+ let oldIndices = [];
78
+ let newIndices = [];
79
+ for (let [index, line] of hunk.lines.entries()) {
80
+ if (line.kind !== "add")
81
+ oldIndices.push(index);
82
+ if (line.kind !== "del")
83
+ newIndices.push(index);
84
+ }
85
+ let runs = Array.from({ length: hunk.lines.length }, () => []);
86
+ paintSide(hunk, oldIndices, language, runs, "del");
87
+ paintSide(hunk, newIndices, language, runs, "new");
88
+ if (!byLanguage) {
89
+ byLanguage = new Map();
90
+ HUNK_TOKENS.set(hunk, byLanguage);
91
+ }
92
+ byLanguage.set(language, runs);
93
+ return runs;
94
+ }
95
+ /**
96
+ * Tokenizes one side's lines as a single source and writes each line's runs back to its
97
+ * slot: the old side's pass keeps only deletions, and the new side's pass keeps context
98
+ * lines and additions.
99
+ */
100
+ function paintSide(hunk, indices, language, runs, keeps) {
101
+ if (indices.length === 0)
102
+ return;
103
+ let source = indices.map((index) => hunk.lines[index].text).join("\n");
104
+ let lines = tokenizeLines(source, language);
105
+ for (let [position, index] of indices.entries()) {
106
+ let isDel = hunk.lines[index].kind === "del";
107
+ if (isDel === (keeps === "del"))
108
+ runs[index] = lines[position]?.tokens ?? [];
109
+ }
110
+ }
111
+ /**
112
+ * Cuts a line's runs at the edges of its changed word ranges, so each piece is either all
113
+ * inside a range or all outside it, and neighbouring pieces of one type and marking merge.
114
+ *
115
+ * @param runs The line's highlighted runs, covering its text in order.
116
+ * @param words `[start, end)` offsets of the changed spans; absent or empty marks nothing.
117
+ * @returns The runs, each flagged as marked or not.
118
+ * @example markRuns([{ type: "plain", value: "let b = 3;" }], [[8, 9]]) // "let b = " | "3" (marked) | ";"
119
+ */
120
+ export function markRuns(runs, words) {
121
+ let pieces = [];
122
+ let push = (type, value, marked) => {
123
+ if (value === "")
124
+ return;
125
+ let last = pieces[pieces.length - 1];
126
+ if (last && last.type === type && last.marked === marked)
127
+ last.value += value;
128
+ else
129
+ pieces.push({ type, value, marked });
130
+ };
131
+ let ranges = words ?? [];
132
+ let offset = 0;
133
+ let range = 0;
134
+ for (let run of runs) {
135
+ let start = offset;
136
+ let end = offset + run.value.length;
137
+ let cursor = start;
138
+ while (cursor < end) {
139
+ while (range < ranges.length && ranges[range][1] <= cursor)
140
+ range += 1;
141
+ let next = ranges[range];
142
+ if (next === undefined || next[0] >= end) {
143
+ push(run.type, run.value.slice(cursor - start), false);
144
+ cursor = end;
145
+ }
146
+ else if (next[0] > cursor) {
147
+ push(run.type, run.value.slice(cursor - start, next[0] - start), false);
148
+ cursor = next[0];
149
+ }
150
+ else {
151
+ let stop = Math.min(end, next[1]);
152
+ push(run.type, run.value.slice(cursor - start, stop - start), true);
153
+ cursor = stop;
154
+ }
155
+ }
156
+ offset = end;
157
+ }
158
+ return pieces;
159
+ }
160
+ /**
161
+ * The five blocks a file's change bar draws: additions and deletions in proportion to the
162
+ * change, each at least one block when nonzero, and neutral blocks for the rest when the
163
+ * change is smaller than the bar.
164
+ *
165
+ * @param additions Lines added.
166
+ * @param deletions Lines deleted.
167
+ * @returns {@link CHANGE_BLOCKS} blocks, additions first.
168
+ * @example changeBlocks(12, 3) // ["add", "add", "add", "add", "del"]
169
+ */
170
+ export function changeBlocks(additions, deletions) {
171
+ let total = additions + deletions;
172
+ if (total === 0)
173
+ return Array.from({ length: CHANGE_BLOCKS }, () => "neutral");
174
+ let filled = Math.min(CHANGE_BLOCKS, total);
175
+ let added = Math.round((additions / total) * filled);
176
+ if (additions > 0 && added === 0)
177
+ added = 1;
178
+ if (deletions > 0 && added === filled)
179
+ added = filled - 1;
180
+ let blocks = [];
181
+ for (let index = 0; index < CHANGE_BLOCKS; index += 1) {
182
+ if (index < added)
183
+ blocks.push("add");
184
+ else if (index < filled)
185
+ blocks.push("del");
186
+ else
187
+ blocks.push("neutral");
188
+ }
189
+ return blocks;
190
+ }
191
+ /** FNV-1a offset basis, the starting state of the hash that names a file from its path. */
192
+ const FNV_OFFSET = 0x811c9dc5;
193
+ /** FNV-1a prime, which spreads each character through the hash. */
194
+ const FNV_PRIME = 0x01000193;
195
+ /**
196
+ * A short id derived from a path, so a file's card and line anchors keep the same ids on
197
+ * every render of the same change, and a link to `#diff-<hash>R12` survives a reload.
198
+ *
199
+ * @param path The file's path.
200
+ * @returns A base-36 hash, stable across runs.
201
+ */
202
+ export function pathHash(path) {
203
+ let hash = FNV_OFFSET;
204
+ for (let index = 0; index < path.length; index += 1) {
205
+ hash ^= path.charCodeAt(index);
206
+ hash = Math.imul(hash, FNV_PRIME);
207
+ }
208
+ return (hash >>> 0).toString(36);
209
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Fuzzy matching for file paths: a query matches when its characters appear in order, and a
3
+ * match scores higher where it lands on a path-segment or word start, runs consecutively, or
4
+ * falls in the file's own name. Shared by the palette's finder and a server's `/find` page.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ /** One path a query matched, with where. */
10
+ export interface FuzzyMatch {
11
+ path: string;
12
+ /** Higher is better; only comparable between results of the same query. */
13
+ score: number;
14
+ /** The UTF-16 offsets of the matched characters, ascending, for bolding them. */
15
+ positions: number[];
16
+ /** The path's index in the list it came from. */
17
+ index: number;
18
+ }
19
+ /** One stretch of a path, and whether the query matched it; the shape `Highlight` reads. */
20
+ export interface FuzzySegment {
21
+ text: string;
22
+ match: boolean;
23
+ }
24
+ /**
25
+ * Scores `query` against one path. Case is ignored and whitespace in the query is dropped; an
26
+ * empty query matches every path with a score of 0.
27
+ *
28
+ * @param query What was typed.
29
+ * @param path The path to score.
30
+ * @returns The score and matched offsets, or `null` when the characters do not appear in order.
31
+ * @example fuzzyScore("plv", "packages/log-viewer.tsx") // { score: …, positions: [0, 9, 13] }
32
+ */
33
+ export declare function fuzzyScore(query: string, path: string): {
34
+ score: number;
35
+ positions: number[];
36
+ } | null;
37
+ /**
38
+ * Ranks the paths `query` matches, best first; ties go to the shorter path, then to the
39
+ * earlier one. An empty query keeps the list's own order. Linear in the paths and quadratic
40
+ * only in one path's length times the query's, so 5,000 paths rank within a keystroke.
41
+ *
42
+ * @param query What was typed.
43
+ * @param paths Every path to search.
44
+ * @param limit How many results to keep. @default 50
45
+ * @returns The best `limit` matches with their offsets.
46
+ * @example fuzzyFilter(url.searchParams.get("q") ?? "", tree.paths, 100)
47
+ */
48
+ export declare function fuzzyFilter(query: string, paths: readonly string[], limit?: number): FuzzyMatch[];
49
+ /**
50
+ * Splits a path into stretches at the matched offsets, merging neighbours, so a renderer can
51
+ * bold each matched run with one element.
52
+ *
53
+ * @param path The matched path.
54
+ * @param positions The offsets a {@link FuzzyMatch} reports.
55
+ * @returns The path's stretches in order.
56
+ * @example fuzzySegments("src/app.ts", [4, 5]) // [{ text: "src/", match: false }, { text: "ap", match: true }, …]
57
+ */
58
+ export declare function fuzzySegments(path: string, positions: readonly number[]): FuzzySegment[];
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Fuzzy matching for file paths: a query matches when its characters appear in order, and a
3
+ * match scores higher where it lands on a path-segment or word start, runs consecutively, or
4
+ * falls in the file's own name. Shared by the palette's finder and a server's `/find` page.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ /** Every matched character earns this much before bonuses. */
10
+ const SCORE_MATCH = 16;
11
+ /** A match on the first character of a path segment (the start, or just after `/`). */
12
+ const BONUS_SEGMENT_START = 40;
13
+ /** A match on a word start inside a segment: after `-`, `_`, `.` or a space, or a camelCase hump. */
14
+ const BONUS_WORD_START = 28;
15
+ /** A match right after the previous query character's match. */
16
+ const BONUS_CONSECUTIVE = 36;
17
+ /** A match inside the last segment, the file's own name. */
18
+ const BONUS_BASENAME = 10;
19
+ /** What each skipped path character between two matches costs. */
20
+ const PENALTY_GAP = 1;
21
+ /** Stands for "no way to match here"; far below any reachable score. */
22
+ const UNREACHABLE = -1e9;
23
+ /** How many results {@link fuzzyFilter} returns when `limit` is omitted. */
24
+ const DEFAULT_LIMIT = 50;
25
+ /** Reused score and back-pointer tables, grown to the largest query × path seen. */
26
+ const TABLES = { scores: new Float64Array(0), from: new Int32Array(0) };
27
+ /** Lower-cases a query and drops its whitespace, since paths are matched character by character. */
28
+ function foldQuery(query) {
29
+ return query.toLowerCase().replace(/\s+/g, "");
30
+ }
31
+ /** Lower-cases a path keeping every offset, so positions found in it index the original. */
32
+ function foldPath(path) {
33
+ let folded = path.toLowerCase();
34
+ if (folded.length === path.length)
35
+ return folded;
36
+ let out = "";
37
+ for (let char of path) {
38
+ let lower = char.toLowerCase();
39
+ out += lower.length === char.length ? lower : char;
40
+ }
41
+ return out;
42
+ }
43
+ /** Whether every character of `query` appears in `text` in order. */
44
+ function isSubsequence(query, text) {
45
+ let at = 0;
46
+ for (let index = 0; index < query.length; index++) {
47
+ at = text.indexOf(query[index], at);
48
+ if (at === -1)
49
+ return false;
50
+ at++;
51
+ }
52
+ return true;
53
+ }
54
+ /** The bonus a match at `index` earns for where it lands in the path. */
55
+ function positionBonus(path, index, basenameStart) {
56
+ let bonus = index >= basenameStart ? BONUS_BASENAME : 0;
57
+ if (index === 0)
58
+ return bonus + BONUS_SEGMENT_START;
59
+ let previous = path[index - 1];
60
+ if (previous === "/")
61
+ return bonus + BONUS_SEGMENT_START;
62
+ if (previous === "-" || previous === "_" || previous === "." || previous === " ") {
63
+ return bonus + BONUS_WORD_START;
64
+ }
65
+ let char = path[index];
66
+ let isUpper = char !== char.toLowerCase();
67
+ let previousIsLower = previous !== previous.toUpperCase();
68
+ return isUpper && previousIsLower ? bonus + BONUS_WORD_START : bonus;
69
+ }
70
+ /** Scores a folded query against one path whose folded form is `folded`, or `null` when it misses. */
71
+ function scoreFolded(query, path, folded) {
72
+ let rows = query.length;
73
+ if (rows === 0)
74
+ return { score: 0, positions: [] };
75
+ if (!isSubsequence(query, folded))
76
+ return null;
77
+ let cols = folded.length;
78
+ let size = rows * cols;
79
+ if (TABLES.scores.length < size) {
80
+ TABLES.scores = new Float64Array(size * 2);
81
+ TABLES.from = new Int32Array(size * 2);
82
+ }
83
+ let { scores, from } = TABLES;
84
+ let basenameStart = path.lastIndexOf("/") + 1;
85
+ for (let row = 0; row < rows; row++) {
86
+ let char = query[row];
87
+ let base = row * cols;
88
+ let above = base - cols;
89
+ /** The best score of the previous row up to `col - 1`, less the gap from there to here. */
90
+ let carried = UNREACHABLE;
91
+ let carriedFrom = -1;
92
+ for (let col = 0; col < cols; col++) {
93
+ if (row > 0 && col > 0) {
94
+ carried -= PENALTY_GAP;
95
+ let previous = scores[above + col - 1];
96
+ if (previous >= carried) {
97
+ carried = previous;
98
+ carriedFrom = col - 1;
99
+ }
100
+ }
101
+ if (folded[col] !== char) {
102
+ scores[base + col] = UNREACHABLE;
103
+ continue;
104
+ }
105
+ let earned = SCORE_MATCH + positionBonus(path, col, basenameStart);
106
+ if (row === 0) {
107
+ scores[base + col] = earned;
108
+ from[base + col] = -1;
109
+ continue;
110
+ }
111
+ let best = carried;
112
+ let bestFrom = carriedFrom;
113
+ if (col > 0) {
114
+ let consecutive = scores[above + col - 1] + BONUS_CONSECUTIVE;
115
+ if (consecutive >= best) {
116
+ best = consecutive;
117
+ bestFrom = col - 1;
118
+ }
119
+ }
120
+ scores[base + col] = best <= UNREACHABLE / 2 ? UNREACHABLE : best + earned;
121
+ from[base + col] = bestFrom;
122
+ }
123
+ }
124
+ let last = (rows - 1) * cols;
125
+ let end = -1;
126
+ let score = UNREACHABLE;
127
+ for (let col = 0; col < cols; col++) {
128
+ if (scores[last + col] > score) {
129
+ score = scores[last + col];
130
+ end = col;
131
+ }
132
+ }
133
+ if (end === -1 || score <= UNREACHABLE / 2)
134
+ return null;
135
+ let positions = Array.from({ length: rows });
136
+ let col = end;
137
+ for (let row = rows - 1; row >= 0; row--) {
138
+ positions[row] = col;
139
+ col = from[row * cols + col];
140
+ }
141
+ return { score, positions };
142
+ }
143
+ /**
144
+ * Scores `query` against one path. Case is ignored and whitespace in the query is dropped; an
145
+ * empty query matches every path with a score of 0.
146
+ *
147
+ * @param query What was typed.
148
+ * @param path The path to score.
149
+ * @returns The score and matched offsets, or `null` when the characters do not appear in order.
150
+ * @example fuzzyScore("plv", "packages/log-viewer.tsx") // { score: …, positions: [0, 9, 13] }
151
+ */
152
+ export function fuzzyScore(query, path) {
153
+ return scoreFolded(foldQuery(query), path, foldPath(path));
154
+ }
155
+ /**
156
+ * Ranks the paths `query` matches, best first; ties go to the shorter path, then to the
157
+ * earlier one. An empty query keeps the list's own order. Linear in the paths and quadratic
158
+ * only in one path's length times the query's, so 5,000 paths rank within a keystroke.
159
+ *
160
+ * @param query What was typed.
161
+ * @param paths Every path to search.
162
+ * @param limit How many results to keep. @default 50
163
+ * @returns The best `limit` matches with their offsets.
164
+ * @example fuzzyFilter(url.searchParams.get("q") ?? "", tree.paths, 100)
165
+ */
166
+ export function fuzzyFilter(query, paths, limit = DEFAULT_LIMIT) {
167
+ let folded = foldQuery(query);
168
+ if (folded === "") {
169
+ return paths.slice(0, limit).map((path, index) => ({ path, score: 0, positions: [], index }));
170
+ }
171
+ let matches = [];
172
+ for (let index = 0; index < paths.length; index++) {
173
+ let path = paths[index];
174
+ let match = scoreFolded(folded, path, foldPath(path));
175
+ if (match !== null)
176
+ matches.push({ path, score: match.score, positions: match.positions, index });
177
+ }
178
+ matches.sort((a, b) => b.score - a.score || a.path.length - b.path.length || a.index - b.index);
179
+ return matches.slice(0, limit);
180
+ }
181
+ /**
182
+ * Splits a path into stretches at the matched offsets, merging neighbours, so a renderer can
183
+ * bold each matched run with one element.
184
+ *
185
+ * @param path The matched path.
186
+ * @param positions The offsets a {@link FuzzyMatch} reports.
187
+ * @returns The path's stretches in order.
188
+ * @example fuzzySegments("src/app.ts", [4, 5]) // [{ text: "src/", match: false }, { text: "ap", match: true }, …]
189
+ */
190
+ export function fuzzySegments(path, positions) {
191
+ let marked = new Set(positions);
192
+ let segments = [];
193
+ for (let index = 0; index < path.length; index++) {
194
+ let match = marked.has(index);
195
+ let last = segments.at(-1);
196
+ if (last !== undefined && last.match === match)
197
+ last.text += path[index];
198
+ else
199
+ segments.push({ text: path[index], match });
200
+ }
201
+ return segments;
202
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Reads and writes a cited range of source lines in the two forms an address carries it:
3
+ * the `?L=3-8` query a server paints without script, and the `#L3-L8` fragment a script
4
+ * keeps in the address bar, so both sides agree on what a link selects.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ /** A range of lines, counted from 1, `start` never after `end`. */
10
+ export interface LineRange {
11
+ start: number;
12
+ end: number;
13
+ }
14
+ /**
15
+ * Reads a line range from a query value (`3-8`, `3`) or a fragment (`#L3-L8`, `L3`), in
16
+ * either order. Anything else, a line below 1 included, reads as no range.
17
+ *
18
+ * @param value A `?L=` value or a location hash.
19
+ * @returns The range, or `undefined` when the value names none.
20
+ * @example parseLineRange(url.searchParams.get("L")) // { start: 3, end: 8 } for ?L=3-8
21
+ */
22
+ export declare function parseLineRange(value: string | null | undefined): LineRange | undefined;
23
+ /**
24
+ * Writes a range as a `?L=` value: `3-8`, or `3` for one line.
25
+ *
26
+ * @param range The lines to cite.
27
+ * @returns The query value.
28
+ */
29
+ export declare function lineRangeQuery(range: LineRange): string;
30
+ /**
31
+ * Writes a range as a fragment: `#L3-L8`, or `#L3` for one line, which the line's own
32
+ * anchor answers to.
33
+ *
34
+ * @param range The lines to cite.
35
+ * @returns The fragment, `#` included.
36
+ */
37
+ export declare function lineRangeHash(range: LineRange): string;
38
+ /**
39
+ * The address a line's number links to without script: the line as a `?L=` query, so the
40
+ * server paints it, and its anchor, so the browser scrolls to it. Other query parameters
41
+ * of `base` are kept.
42
+ *
43
+ * @param line The line, counted from 1.
44
+ * @param base The page's own address, relative or absolute.
45
+ * @returns A link to the line on the same page.
46
+ * @example lineLink(10, "/blob/main/app.ts?plain=1") // "/blob/main/app.ts?plain=1&L=10#L10"
47
+ */
48
+ export declare function lineLink(line: number, base?: string): string;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Reads and writes a cited range of source lines in the two forms an address carries it:
3
+ * the `?L=3-8` query a server paints without script, and the `#L3-L8` fragment a script
4
+ * keeps in the address bar, so both sides agree on what a link selects.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ /**
10
+ * Reads a line range from a query value (`3-8`, `3`) or a fragment (`#L3-L8`, `L3`), in
11
+ * either order. Anything else, a line below 1 included, reads as no range.
12
+ *
13
+ * @param value A `?L=` value or a location hash.
14
+ * @returns The range, or `undefined` when the value names none.
15
+ * @example parseLineRange(url.searchParams.get("L")) // { start: 3, end: 8 } for ?L=3-8
16
+ */
17
+ export function parseLineRange(value) {
18
+ let match = /^#?L?(\d+)(?:-L?(\d+))?$/i.exec((value ?? "").trim());
19
+ if (match === null)
20
+ return undefined;
21
+ let first = Number(match[1]);
22
+ let second = match[2] === undefined ? first : Number(match[2]);
23
+ if (first < 1 || second < 1)
24
+ return undefined;
25
+ return { start: Math.min(first, second), end: Math.max(first, second) };
26
+ }
27
+ /**
28
+ * Writes a range as a `?L=` value: `3-8`, or `3` for one line.
29
+ *
30
+ * @param range The lines to cite.
31
+ * @returns The query value.
32
+ */
33
+ export function lineRangeQuery(range) {
34
+ return range.start === range.end ? String(range.start) : `${range.start}-${range.end}`;
35
+ }
36
+ /**
37
+ * Writes a range as a fragment: `#L3-L8`, or `#L3` for one line, which the line's own
38
+ * anchor answers to.
39
+ *
40
+ * @param range The lines to cite.
41
+ * @returns The fragment, `#` included.
42
+ */
43
+ export function lineRangeHash(range) {
44
+ return range.start === range.end ? `#L${range.start}` : `#L${range.start}-L${range.end}`;
45
+ }
46
+ /**
47
+ * The address a line's number links to without script: the line as a `?L=` query, so the
48
+ * server paints it, and its anchor, so the browser scrolls to it. Other query parameters
49
+ * of `base` are kept.
50
+ *
51
+ * @param line The line, counted from 1.
52
+ * @param base The page's own address, relative or absolute.
53
+ * @returns A link to the line on the same page.
54
+ * @example lineLink(10, "/blob/main/app.ts?plain=1") // "/blob/main/app.ts?plain=1&L=10#L10"
55
+ */
56
+ export function lineLink(line, base = "") {
57
+ let [path = "", query = ""] = base.split("#")[0].split("?");
58
+ let params = new URLSearchParams(query);
59
+ params.set("L", String(line));
60
+ return `${path}?${params.toString()}#L${line}`;
61
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * The shape of a CI log before it is drawn: workflow markers (`##[group]`, `##[error]`…) read
3
+ * off each line, groups nested into a tree, and the tree cut into chunks the browser can skip
4
+ * painting. Shared by the server render and the island that appends streamed lines.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { AnsiSpan, AnsiStyle } from "./ansi.js";
10
+ /**
11
+ * A line number no real log reaches, passed to a line-link builder so the link's shape can be
12
+ * read back as a template, with `{n}` where the number goes, for lines that stream in later.
13
+ */
14
+ export declare const LOG_LINE_PLACEHOLDER = 987654321;
15
+ /** How a line reads at a glance: an error or warning annotation, a command echo, or plain output. */
16
+ export type LogTone = "danger" | "warning" | "notice" | "command" | "muted";
17
+ /** One line of a step's log as the server holds it. */
18
+ export interface LogLine {
19
+ /** The line's number within its step, starting at 1. */
20
+ n: number;
21
+ /** The raw text, ANSI escapes and workflow markers included. */
22
+ text: string;
23
+ /** When the line was written, as ISO 8601. */
24
+ ts?: string;
25
+ /** Marks the line as opening or closing a fold, for logs that carry no `##[group]` markers. */
26
+ group?: "start" | "end";
27
+ }
28
+ /** A line read for drawing: its marker removed, its tone set and its text split into ANSI spans. */
29
+ export interface LogEntry {
30
+ n: number;
31
+ spans: AnsiSpan[];
32
+ ts?: string;
33
+ tone?: LogTone;
34
+ }
35
+ /** A node of the drawn tree: a line, or a fold whose title line opens it. */
36
+ export type LogNode = {
37
+ kind: "line";
38
+ entry: LogEntry;
39
+ } | {
40
+ kind: "group";
41
+ entry: LogEntry;
42
+ children: LogNode[];
43
+ lines: number;
44
+ hasError: boolean;
45
+ };
46
+ /** What a line's leading workflow marker makes it. */
47
+ export type LogMarker = "group" | "endgroup" | LogTone | undefined;
48
+ /**
49
+ * Reads a line's leading workflow marker, returning it with the marker removed from the text.
50
+ *
51
+ * @param text The raw line.
52
+ * @returns The marker (or `undefined`) and the text to draw.
53
+ * @example readMarker("##[error]Process completed with exit code 1.") // { marker: "danger", text: "Process completed…" }
54
+ */
55
+ export declare function readMarker(text: string): {
56
+ marker: LogMarker;
57
+ text: string;
58
+ };
59
+ /**
60
+ * Splits a raw streamed line into its ISO timestamp and the text after it.
61
+ *
62
+ * @param raw A line as a CI runner writes it.
63
+ * @returns The timestamp, when the line starts with one, and the text.
64
+ * @example splitTimestamp("2026-11-13T09:00:01.123Z Run tests") // { ts: "2026-11-13T09:00:01.123Z", text: "Run tests" }
65
+ */
66
+ export declare function splitTimestamp(raw: string): {
67
+ ts?: string;
68
+ text: string;
69
+ };
70
+ /**
71
+ * The time a line shows: an ISO timestamp as `HH:MM:SS` UTC, anything else as given, so the
72
+ * server's lines and streamed ones read alike.
73
+ *
74
+ * @param ts The line's timestamp.
75
+ * @returns The time to draw beside the line.
76
+ * @example formatLogTime("2026-11-13T09:00:01.123Z") // "09:00:01"
77
+ */
78
+ export declare function formatLogTime(ts: string): string;
79
+ /**
80
+ * Nests a step's lines into folds: a `##[group]` line (or `group: "start"`) opens a fold
81
+ * titled by its text, `##[endgroup]` (or `group: "end"`) closes the innermost one and is not
82
+ * drawn, and a fold still open at the end closes there.
83
+ *
84
+ * @param lines The step's lines in order.
85
+ * @returns The top-level nodes.
86
+ * @example buildLogTree([{ n: 1, text: "##[group]Install" }, { n: 2, text: "ok" }, { n: 3, text: "##[endgroup]" }])
87
+ */
88
+ export declare function buildLogTree(lines: readonly LogLine[]): LogNode[];
89
+ /**
90
+ * Cuts sibling nodes into runs of about `size` lines, a fold counting all of its lines, so
91
+ * each run can be skipped as one box while off screen. A fold is never split.
92
+ *
93
+ * @param nodes Sibling nodes in order.
94
+ * @param size The lines a run aims for.
95
+ * @returns The runs, in order.
96
+ * @example chunkLogNodes(buildLogTree(lines), 200)
97
+ */
98
+ export declare function chunkLogNodes(nodes: readonly LogNode[], size: number): LogNode[][];
99
+ /**
100
+ * The attributes a styled span carries, which the viewer's stylesheet tones; the same names
101
+ * serve the server's markup and the lines the island appends.
102
+ *
103
+ * @param style The span's ANSI style.
104
+ * @returns `data-fg`, `data-bg`, `data-b`, `data-dim`, `data-i` and `data-u`, where set.
105
+ * @example ansiAttributes({ fg: "red", bold: true }) // { "data-fg": "red", "data-b": "" }
106
+ */
107
+ export declare function ansiAttributes(style: AnsiStyle): Record<string, string>;