@bigpixelrocket/uiok 0.0.0-stage → 0.1.1

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 (280) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE +569 -0
  4. package/README.md +44 -2
  5. package/dist/VisuallyHidden.d.ts +13 -0
  6. package/dist/VisuallyHidden.js +13 -0
  7. package/dist/activity/ActivityBar.d.ts +29 -0
  8. package/dist/activity/ActivityBar.js +21 -0
  9. package/dist/activity/activity.css +43 -0
  10. package/dist/activity/index.d.ts +2 -0
  11. package/dist/activity/index.js +2 -0
  12. package/dist/button/Button.d.ts +26 -0
  13. package/dist/button/Button.js +14 -0
  14. package/dist/button/IconButton.d.ts +18 -0
  15. package/dist/button/IconButton.js +14 -0
  16. package/dist/button/button.css +95 -0
  17. package/dist/button/index.d.ts +3 -0
  18. package/dist/button/index.js +3 -0
  19. package/dist/charts/Drawing.d.ts +27 -0
  20. package/dist/charts/Drawing.js +117 -0
  21. package/dist/charts/Drawing.logic.d.ts +2 -0
  22. package/dist/charts/Drawing.logic.js +22 -0
  23. package/dist/charts/Line.logic.d.ts +33 -0
  24. package/dist/charts/Line.logic.js +72 -0
  25. package/dist/charts/LineChart.d.ts +34 -0
  26. package/dist/charts/LineChart.js +100 -0
  27. package/dist/charts/Pie.logic.d.ts +16 -0
  28. package/dist/charts/Pie.logic.js +28 -0
  29. package/dist/charts/PieChart.d.ts +20 -0
  30. package/dist/charts/PieChart.js +16 -0
  31. package/dist/charts/ResultChart.d.ts +47 -0
  32. package/dist/charts/ResultChart.js +175 -0
  33. package/dist/charts/ResultChart.logic.d.ts +42 -0
  34. package/dist/charts/ResultChart.logic.js +165 -0
  35. package/dist/charts/Scatter.logic.d.ts +55 -0
  36. package/dist/charts/Scatter.logic.js +134 -0
  37. package/dist/charts/ScatterChart.d.ts +36 -0
  38. package/dist/charts/ScatterChart.js +99 -0
  39. package/dist/charts/charts.css +310 -0
  40. package/dist/charts/index.d.ts +14 -0
  41. package/dist/charts/index.js +11 -0
  42. package/dist/charts/seriesColour.d.ts +2 -0
  43. package/dist/charts/seriesColour.js +8 -0
  44. package/dist/clock/index.d.ts +2 -0
  45. package/dist/clock/index.js +2 -0
  46. package/dist/clock/useClock.d.ts +14 -0
  47. package/dist/clock/useClock.js +57 -0
  48. package/dist/datetime/DateTimePicker.d.ts +50 -0
  49. package/dist/datetime/DateTimePicker.js +98 -0
  50. package/dist/datetime/DateTimePicker.logic.d.ts +59 -0
  51. package/dist/datetime/DateTimePicker.logic.js +103 -0
  52. package/dist/datetime/datetime.css +115 -0
  53. package/dist/datetime/index.d.ts +7 -0
  54. package/dist/datetime/index.js +7 -0
  55. package/dist/dialog/ConfirmDialog.d.ts +73 -0
  56. package/dist/dialog/ConfirmDialog.js +30 -0
  57. package/dist/dialog/DialogLegend.d.ts +21 -0
  58. package/dist/dialog/DialogLegend.js +28 -0
  59. package/dist/dialog/DialogLegend.logic.d.ts +145 -0
  60. package/dist/dialog/DialogLegend.logic.js +71 -0
  61. package/dist/dialog/ModalDialog.d.ts +101 -0
  62. package/dist/dialog/ModalDialog.js +184 -0
  63. package/dist/dialog/dialog.css +283 -0
  64. package/dist/dialog/index.d.ts +8 -0
  65. package/dist/dialog/index.js +8 -0
  66. package/dist/filter/FilterEscape.d.ts +16 -0
  67. package/dist/filter/FilterEscape.js +15 -0
  68. package/dist/filter/FilterIcon.d.ts +8 -0
  69. package/dist/filter/FilterIcon.js +11 -0
  70. package/dist/filter/filter.css +42 -0
  71. package/dist/filter/index.d.ts +3 -0
  72. package/dist/filter/index.js +3 -0
  73. package/dist/grid/DataGrid.d.ts +149 -0
  74. package/dist/grid/DataGrid.js +373 -0
  75. package/dist/grid/DataGrid.logic.d.ts +57 -0
  76. package/dist/grid/DataGrid.logic.js +121 -0
  77. package/dist/grid/grid.css +206 -0
  78. package/dist/grid/index.d.ts +7 -0
  79. package/dist/grid/index.js +7 -0
  80. package/dist/index.d.ts +32 -0
  81. package/dist/index.js +32 -0
  82. package/dist/keyboard/BrowserKeys.d.ts +15 -0
  83. package/dist/keyboard/BrowserKeys.js +28 -0
  84. package/dist/keyboard/KeyChord.logic.d.ts +25 -0
  85. package/dist/keyboard/KeyChord.logic.js +50 -0
  86. package/dist/keyboard/Keyboard.logic.d.ts +84 -0
  87. package/dist/keyboard/Keyboard.logic.js +137 -0
  88. package/dist/keyboard/OverlayWatch.d.ts +28 -0
  89. package/dist/keyboard/OverlayWatch.js +119 -0
  90. package/dist/keyboard/PageSelectAll.d.ts +14 -0
  91. package/dist/keyboard/PageSelectAll.js +22 -0
  92. package/dist/keyboard/index.d.ts +9 -0
  93. package/dist/keyboard/index.js +9 -0
  94. package/dist/keychord/KeyChord.d.ts +16 -0
  95. package/dist/keychord/KeyChord.js +55 -0
  96. package/dist/keychord/index.d.ts +2 -0
  97. package/dist/keychord/index.js +2 -0
  98. package/dist/keychord/keychord.css +41 -0
  99. package/dist/labels/UiokLabels.d.ts +41 -0
  100. package/dist/labels/UiokLabels.js +31 -0
  101. package/dist/labels/UiokProvider.d.ts +44 -0
  102. package/dist/labels/UiokProvider.js +54 -0
  103. package/dist/labels/charts.d.ts +34 -0
  104. package/dist/labels/charts.js +15 -0
  105. package/dist/labels/dateTime.d.ts +32 -0
  106. package/dist/labels/dateTime.js +14 -0
  107. package/dist/labels/dialog.d.ts +18 -0
  108. package/dist/labels/dialog.js +6 -0
  109. package/dist/labels/index.d.ts +13 -0
  110. package/dist/labels/index.js +13 -0
  111. package/dist/labels/keys.d.ts +28 -0
  112. package/dist/labels/keys.js +53 -0
  113. package/dist/labels/legend.d.ts +21 -0
  114. package/dist/labels/legend.js +7 -0
  115. package/dist/labels/listing.d.ts +16 -0
  116. package/dist/labels/listing.js +8 -0
  117. package/dist/labels/pager.d.ts +32 -0
  118. package/dist/labels/pager.js +20 -0
  119. package/dist/labels/palette.d.ts +17 -0
  120. package/dist/labels/palette.js +6 -0
  121. package/dist/labels/selectAll.d.ts +15 -0
  122. package/dist/labels/selectAll.js +6 -0
  123. package/dist/labels/terminal.d.ts +25 -0
  124. package/dist/labels/terminal.js +9 -0
  125. package/dist/legend/KeyLegend.logic.d.ts +84 -0
  126. package/dist/legend/KeyLegend.logic.js +109 -0
  127. package/dist/legend/KeyLegendStrip.d.ts +36 -0
  128. package/dist/legend/KeyLegendStrip.js +82 -0
  129. package/dist/legend/index.d.ts +3 -0
  130. package/dist/legend/index.js +3 -0
  131. package/dist/legend/legend.css +148 -0
  132. package/dist/listing/CurrentDot.d.ts +15 -0
  133. package/dist/listing/CurrentDot.js +13 -0
  134. package/dist/listing/Listing.d.ts +230 -0
  135. package/dist/listing/Listing.js +265 -0
  136. package/dist/listing/PathParts.logic.d.ts +17 -0
  137. package/dist/listing/PathParts.logic.js +18 -0
  138. package/dist/listing/index.d.ts +10 -0
  139. package/dist/listing/index.js +10 -0
  140. package/dist/listing/listing.css +867 -0
  141. package/dist/menu/MenuQuery.logic.d.ts +69 -0
  142. package/dist/menu/MenuQuery.logic.js +75 -0
  143. package/dist/menu/fuzzyMatch.d.ts +31 -0
  144. package/dist/menu/fuzzyMatch.js +296 -0
  145. package/dist/menu/index.d.ts +9 -0
  146. package/dist/menu/index.js +9 -0
  147. package/dist/menu/menu.css +203 -0
  148. package/dist/menu/useBellBeat.d.ts +8 -0
  149. package/dist/menu/useBellBeat.js +26 -0
  150. package/dist/namecut/NameCut.d.ts +22 -0
  151. package/dist/namecut/NameCut.js +28 -0
  152. package/dist/namecut/NameCut.logic.d.ts +51 -0
  153. package/dist/namecut/NameCut.logic.js +120 -0
  154. package/dist/namecut/index.d.ts +3 -0
  155. package/dist/namecut/index.js +3 -0
  156. package/dist/namecut/namecut.css +67 -0
  157. package/dist/pager/Pager.d.ts +37 -0
  158. package/dist/pager/Pager.js +38 -0
  159. package/dist/pager/Pager.logic.d.ts +13 -0
  160. package/dist/pager/Pager.logic.js +63 -0
  161. package/dist/pager/index.d.ts +7 -0
  162. package/dist/pager/index.js +7 -0
  163. package/dist/pager/pager.css +62 -0
  164. package/dist/palette/Palette.d.ts +79 -0
  165. package/dist/palette/Palette.js +60 -0
  166. package/dist/palette/index.d.ts +6 -0
  167. package/dist/palette/index.js +6 -0
  168. package/dist/palette/palette.css +159 -0
  169. package/dist/pane/PaneActions.d.ts +104 -0
  170. package/dist/pane/PaneActions.js +62 -0
  171. package/dist/pane/PaneFrame.d.ts +51 -0
  172. package/dist/pane/PaneFrame.js +28 -0
  173. package/dist/pane/PaneKeys.d.ts +41 -0
  174. package/dist/pane/PaneKeys.js +104 -0
  175. package/dist/pane/PaneKeys.logic.d.ts +95 -0
  176. package/dist/pane/PaneKeys.logic.js +109 -0
  177. package/dist/pane/index.d.ts +11 -0
  178. package/dist/pane/index.js +11 -0
  179. package/dist/pane/usePaneKeys.d.ts +141 -0
  180. package/dist/pane/usePaneKeys.js +313 -0
  181. package/dist/run/RunHeader.d.ts +50 -0
  182. package/dist/run/RunHeader.js +31 -0
  183. package/dist/run/RunProgress.logic.d.ts +29 -0
  184. package/dist/run/RunProgress.logic.js +34 -0
  185. package/dist/run/index.d.ts +3 -0
  186. package/dist/run/index.js +3 -0
  187. package/dist/run/run.css +190 -0
  188. package/dist/segmented/SegmentedChoice.d.ts +22 -0
  189. package/dist/segmented/SegmentedChoice.js +31 -0
  190. package/dist/segmented/index.d.ts +2 -0
  191. package/dist/segmented/index.js +2 -0
  192. package/dist/segmented/segmented.css +49 -0
  193. package/dist/selectall/CheckRange.logic.d.ts +8 -0
  194. package/dist/selectall/CheckRange.logic.js +23 -0
  195. package/dist/selectall/SelectAllBar.d.ts +25 -0
  196. package/dist/selectall/SelectAllBar.js +24 -0
  197. package/dist/selectall/index.d.ts +7 -0
  198. package/dist/selectall/index.js +7 -0
  199. package/dist/selectall/selectall.css +31 -0
  200. package/dist/store/KeepUnchanged.logic.d.ts +19 -0
  201. package/dist/store/KeepUnchanged.logic.js +33 -0
  202. package/dist/store/SameProps.d.ts +15 -0
  203. package/dist/store/SameProps.js +46 -0
  204. package/dist/store/ValueStore.d.ts +17 -0
  205. package/dist/store/ValueStore.js +23 -0
  206. package/dist/store/index.d.ts +8 -0
  207. package/dist/store/index.js +8 -0
  208. package/dist/store/useStableHandlers.d.ts +13 -0
  209. package/dist/store/useStableHandlers.js +22 -0
  210. package/dist/styles.css +85 -0
  211. package/dist/tabs/PageTabs.d.ts +38 -0
  212. package/dist/tabs/PageTabs.js +33 -0
  213. package/dist/tabs/index.d.ts +2 -0
  214. package/dist/tabs/index.js +2 -0
  215. package/dist/tabs/tabs.css +64 -0
  216. package/dist/terminal/Terminal.d.ts +104 -0
  217. package/dist/terminal/Terminal.js +309 -0
  218. package/dist/terminal/Terminal.logic.d.ts +66 -0
  219. package/dist/terminal/Terminal.logic.js +156 -0
  220. package/dist/terminal/TerminalMenu.d.ts +36 -0
  221. package/dist/terminal/TerminalMenu.js +87 -0
  222. package/dist/terminal/TerminalMenu.logic.d.ts +78 -0
  223. package/dist/terminal/TerminalMenu.logic.js +68 -0
  224. package/dist/terminal/TerminalScrollback.d.ts +10 -0
  225. package/dist/terminal/TerminalScrollback.js +11 -0
  226. package/dist/terminal/ghostty/LICENSE +21 -0
  227. package/dist/terminal/ghostty/core.d.ts +315 -0
  228. package/dist/terminal/ghostty/core.js +1189 -0
  229. package/dist/terminal/ghostty/fallbackColors.d.ts +12 -0
  230. package/dist/terminal/ghostty/fallbackColors.js +23 -0
  231. package/dist/terminal/ghostty/fonts/LICENSE +21 -0
  232. package/dist/terminal/ghostty/fonts/SymbolsNerdFontMono-Regular.woff2 +0 -0
  233. package/dist/terminal/ghostty/keyCodes.logic.d.ts +20 -0
  234. package/dist/terminal/ghostty/keyCodes.logic.js +249 -0
  235. package/dist/terminal/ghostty/links.logic.d.ts +39 -0
  236. package/dist/terminal/ghostty/links.logic.js +84 -0
  237. package/dist/terminal/ghostty/renderer.d.ts +98 -0
  238. package/dist/terminal/ghostty/renderer.js +481 -0
  239. package/dist/terminal/ghostty/runtime.d.ts +126 -0
  240. package/dist/terminal/ghostty/runtime.js +346 -0
  241. package/dist/terminal/ghostty/spriteGlyphs.logic.d.ts +64 -0
  242. package/dist/terminal/ghostty/spriteGlyphs.logic.js +546 -0
  243. package/dist/terminal/ghostty/surface.d.ts +285 -0
  244. package/dist/terminal/ghostty/surface.js +1565 -0
  245. package/dist/terminal/ghostty/surface.logic.d.ts +181 -0
  246. package/dist/terminal/ghostty/surface.logic.js +392 -0
  247. package/dist/terminal/ghostty/vendor/LICENSE +21 -0
  248. package/dist/terminal/ghostty/vendor/ghostty-effects.wasm +0 -0
  249. package/dist/terminal/ghostty/vendor/ghostty-vt.wasm +0 -0
  250. package/dist/terminal/index.d.ts +12 -0
  251. package/dist/terminal/index.js +12 -0
  252. package/dist/terminal/terminal.css +169 -0
  253. package/dist/text/MarkedText.d.ts +14 -0
  254. package/dist/text/MarkedText.js +11 -0
  255. package/dist/text/highlightSegments.d.ts +13 -0
  256. package/dist/text/highlightSegments.js +29 -0
  257. package/dist/text/index.d.ts +3 -0
  258. package/dist/text/index.js +3 -0
  259. package/dist/text/text.css +11 -0
  260. package/dist/themes/attributes.d.ts +21 -0
  261. package/dist/themes/attributes.js +41 -0
  262. package/dist/themes/catalog.d.ts +125 -0
  263. package/dist/themes/catalog.js +940 -0
  264. package/dist/themes/color.d.ts +29 -0
  265. package/dist/themes/color.js +52 -0
  266. package/dist/themes/ids.d.ts +139 -0
  267. package/dist/themes/ids.js +59 -0
  268. package/dist/themes/index.d.ts +12 -0
  269. package/dist/themes/index.js +12 -0
  270. package/dist/themes/themes.generated.css +1830 -0
  271. package/dist/themes/tokens.d.ts +189 -0
  272. package/dist/themes/tokens.js +462 -0
  273. package/dist/tooltip/Tooltip.d.ts +21 -0
  274. package/dist/tooltip/Tooltip.js +105 -0
  275. package/dist/tooltip/Tooltip.logic.d.ts +49 -0
  276. package/dist/tooltip/Tooltip.logic.js +50 -0
  277. package/dist/tooltip/index.d.ts +3 -0
  278. package/dist/tooltip/index.js +3 -0
  279. package/dist/tooltip/tooltip.css +45 -0
  280. package/package.json +91 -4
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Whether a menu or a palette refuses the query `next`: it would empty a
3
+ * menu that `previous` still filled. A loaded list is complete, so an empty
4
+ * result is certain and the character is refused instead of leaving a dead
5
+ * query to backspace out of. A shorter query always passes, and so does one
6
+ * that excludes with `!`, which widens again as its term grows. A menu with
7
+ * no rows yet (still loading, failed, or empty) refuses nothing.
8
+ */
9
+ export declare const menuQueryRefused: (previous: string, next: string, rowsBefore: number, rowsAfter: number) => boolean;
10
+ /**
11
+ * A menu cursor moved by `delta` rows, clamped to the list; null for an
12
+ * empty list. With no cursor yet, a move down enters at the first row and a
13
+ * move up at the last.
14
+ */
15
+ export declare function moveMenuCursor(cursor: number | null, delta: number, length: number): number | null;
16
+ /** A palette row the cursor can stand on unless it is taken. */
17
+ export interface PickableRow {
18
+ /** What the row stands for, which the cursor follows as the list changes. */
19
+ readonly key: string;
20
+ /** Nothing to do here (already installed, already added): listed, dimmed, and passed over. */
21
+ readonly taken: boolean;
22
+ }
23
+ /**
24
+ * The row the cursor stands on: the one it was moved to, while that row is
25
+ * listed and still pickable, else the first pickable row, else none. A row
26
+ * that becomes taken meanwhile (another client did it) moves the cursor on,
27
+ * so the primary verb never asks for what is already done.
28
+ */
29
+ export declare function pickableCursor(items: readonly PickableRow[], pointed: string | null): number | null;
30
+ /**
31
+ * The cursor moved by `delta` over the pickable rows alone, clamped to
32
+ * them; null when none is pickable.
33
+ */
34
+ export declare function movedPickableCursor(items: readonly PickableRow[], cursor: number | null, delta: number): number | null;
35
+ /**
36
+ * A level a menu or a palette opened in place, with the row that opened it.
37
+ * A trail of them, outermost first, is how deep the surface stands.
38
+ */
39
+ export interface LevelStep<Level> {
40
+ readonly level: Level;
41
+ /**
42
+ * The key of the row the level was opened from, where the cursor lands on
43
+ * the way back; null for a level opened some other way.
44
+ */
45
+ readonly from: string | null;
46
+ }
47
+ /** The level a trail stands in: its last step's, or null at the top. */
48
+ export declare const trailLevel: <Level>(trail: readonly LevelStep<Level>[]) => Level | null;
49
+ /** The trail after the row keyed `from` opens `level` one step deeper. */
50
+ export declare const enteredLevel: <Level>(trail: readonly LevelStep<Level>[], level: Level, from: string | null) => readonly LevelStep<Level>[];
51
+ /** One step back out of a trail, and the row the cursor returns to there. */
52
+ export interface LevelReturn<Level> {
53
+ readonly trail: readonly LevelStep<Level>[];
54
+ /** The key of the row that opened the level left, or null when none did. */
55
+ readonly pointed: string | null;
56
+ }
57
+ /**
58
+ * Steps back out of the trail's last level, the way an iPod's wheel does:
59
+ * the cursor lands on the row that opened it, at every depth, not on the
60
+ * first row. Null at the top, where there is nothing to step back from.
61
+ * The surface still checks that the row is listed (`returnedCursor`), since
62
+ * the list may have changed while the level showed.
63
+ */
64
+ export declare function leftLevel<Level>(trail: readonly LevelStep<Level>[]): LevelReturn<Level> | null;
65
+ /**
66
+ * Where the cursor stands after stepping back: the row keyed `pointed`
67
+ * while it is listed, else null, which leaves the surface's own resting row.
68
+ */
69
+ export declare function returnedCursor(keys: readonly string[], pointed: string | null): number | null;
@@ -0,0 +1,75 @@
1
+ /*
2
+ * Pure rules every filtered menu and palette shares: which keystroke a query
3
+ * refuses, how the cursor moves through the rows, and where it lands when a
4
+ * level opened in place is left.
5
+ */
6
+ import { hasNegativeTerms } from './fuzzyMatch.js';
7
+ /**
8
+ * Whether a menu or a palette refuses the query `next`: it would empty a
9
+ * menu that `previous` still filled. A loaded list is complete, so an empty
10
+ * result is certain and the character is refused instead of leaving a dead
11
+ * query to backspace out of. A shorter query always passes, and so does one
12
+ * that excludes with `!`, which widens again as its term grows. A menu with
13
+ * no rows yet (still loading, failed, or empty) refuses nothing.
14
+ */
15
+ export const menuQueryRefused = (previous, next, rowsBefore, rowsAfter) => next.length >= previous.length && !hasNegativeTerms(next) && rowsBefore > 0 && rowsAfter === 0;
16
+ /**
17
+ * A menu cursor moved by `delta` rows, clamped to the list; null for an
18
+ * empty list. With no cursor yet, a move down enters at the first row and a
19
+ * move up at the last.
20
+ */
21
+ export function moveMenuCursor(cursor, delta, length) {
22
+ if (length === 0) {
23
+ return null;
24
+ }
25
+ if (cursor === null) {
26
+ return delta > 0 ? 0 : length - 1;
27
+ }
28
+ return Math.min(length - 1, Math.max(0, cursor + delta));
29
+ }
30
+ /**
31
+ * The row the cursor stands on: the one it was moved to, while that row is
32
+ * listed and still pickable, else the first pickable row, else none. A row
33
+ * that becomes taken meanwhile (another client did it) moves the cursor on,
34
+ * so the primary verb never asks for what is already done.
35
+ */
36
+ export function pickableCursor(items, pointed) {
37
+ const kept = pointed === null ? -1 : items.findIndex((item) => item.key === pointed && !item.taken);
38
+ if (kept !== -1)
39
+ return kept;
40
+ const first = items.findIndex((item) => !item.taken);
41
+ return first === -1 ? null : first;
42
+ }
43
+ /**
44
+ * The cursor moved by `delta` over the pickable rows alone, clamped to
45
+ * them; null when none is pickable.
46
+ */
47
+ export function movedPickableCursor(items, cursor, delta) {
48
+ const pickable = items.flatMap((item, index) => (item.taken ? [] : [index]));
49
+ const at = cursor === null ? null : pickable.indexOf(cursor);
50
+ const next = moveMenuCursor(at === -1 ? null : at, delta, pickable.length);
51
+ return next === null ? null : (pickable[next] ?? null);
52
+ }
53
+ /** The level a trail stands in: its last step's, or null at the top. */
54
+ export const trailLevel = (trail) => trail.at(-1)?.level ?? null;
55
+ /** The trail after the row keyed `from` opens `level` one step deeper. */
56
+ export const enteredLevel = (trail, level, from) => [...trail, { level, from }];
57
+ /**
58
+ * Steps back out of the trail's last level, the way an iPod's wheel does:
59
+ * the cursor lands on the row that opened it, at every depth, not on the
60
+ * first row. Null at the top, where there is nothing to step back from.
61
+ * The surface still checks that the row is listed (`returnedCursor`), since
62
+ * the list may have changed while the level showed.
63
+ */
64
+ export function leftLevel(trail) {
65
+ const last = trail.at(-1);
66
+ return last === undefined ? null : { trail: trail.slice(0, -1), pointed: last.from };
67
+ }
68
+ /**
69
+ * Where the cursor stands after stepping back: the row keyed `pointed`
70
+ * while it is listed, else null, which leaves the surface's own resting row.
71
+ */
72
+ export function returnedCursor(keys, pointed) {
73
+ const at = pointed === null ? -1 : keys.indexOf(pointed);
74
+ return at === -1 ? null : at;
75
+ }
@@ -0,0 +1,31 @@
1
+ /** Where a query hit a candidate, and how well. */
2
+ export interface FuzzyMatch {
3
+ /** Higher is better; zero for an empty query or one that only excludes. */
4
+ readonly score: number;
5
+ /** UTF-16 code unit indices into the candidate the query matched, ascending. */
6
+ readonly positions: readonly number[];
7
+ }
8
+ /**
9
+ * Whether a query holds a term once parsed; whitespace and bare operators
10
+ * (`!`, `'`, `^`, `$`) carry none. A filter treats a query without terms as
11
+ * no filter at all.
12
+ */
13
+ export declare const hasQueryTerms: (query: string) => boolean;
14
+ /**
15
+ * Whether the query excludes with `!`. Every other operator only narrows as
16
+ * characters are added, but a negative term widens again as it grows: `!f`
17
+ * excludes more names than `!foo`, so an empty result midway is not a dead
18
+ * end (`menuQueryRefused`).
19
+ */
20
+ export declare const hasNegativeTerms: (query: string) => boolean;
21
+ /**
22
+ * Matches one string against a query, or null when it does not match.
23
+ * Whitespace-separated terms are ANDed and their scores summed; `!term`
24
+ * excludes, and `'exact`, `^prefix`, `suffix$`, and `^whole$` switch a term
25
+ * to contiguous matching. A lowercase term ignores case; one with an
26
+ * uppercase character honours it. An empty query (or one that only
27
+ * excludes) matches at zero with no positions, so "no filter" needs no
28
+ * branch. The last query stays compiled, because a list is matched row
29
+ * after row against the same one.
30
+ */
31
+ export declare const matchQuery: (candidate: string, query: string) => FuzzyMatch | null;
@@ -0,0 +1,296 @@
1
+ /*
2
+ * Fuzzy subsequence matching for filtered menus, palettes, and listings.
3
+ *
4
+ * fzf-style scoring: dynamic programming evaluates every valid subsequence, so
5
+ * consecutive runs, word boundaries, and camelCase starts beat a scattered
6
+ * match that happens to begin earlier. Anchoring on the first occurrence alone
7
+ * (fzf's simple algorithm) would score `config` against
8
+ * `components/config.ts` across the first word instead of on the real one.
9
+ * Positions come back with the score because a row marks exactly the
10
+ * characters the query hit (`MarkedText`).
11
+ *
12
+ * Case folding is per UTF-16 code unit, never per string, so a matched
13
+ * position always indexes the candidate as written.
14
+ */
15
+ /** Every matched character earns this before bonuses, so any match scores above zero. */
16
+ const BASE = 16;
17
+ /** An adjacent pair reads as one word and must outrank the same characters scattered. */
18
+ const BONUS_CONSECUTIVE = 8;
19
+ /** The first character, or one following a separator, starts a word. */
20
+ const BONUS_BOUNDARY = 14;
21
+ /** A lowercase-to-uppercase step starts a word inside a camelCase name. */
22
+ const BONUS_CAMEL = 12;
23
+ /** Opening a gap costs more than widening one, so runs stay together. */
24
+ const PENALTY_GAP_START = 3;
25
+ /** Each further skipped character inside an open gap. */
26
+ const PENALTY_GAP_EXTENSION = 1;
27
+ /** The score of a candidate the query does not match. */
28
+ const NO_MATCH = Number.NEGATIVE_INFINITY;
29
+ /** A cell no subsequence reaches. Real scores stay far above it. */
30
+ const UNREACHED = -(2 ** 30);
31
+ let caseTablesCache = null;
32
+ const caseTables = () => {
33
+ if (caseTablesCache !== null)
34
+ return caseTablesCache;
35
+ const fold = new Uint16Array(65536);
36
+ const upper = new Uint8Array(65536);
37
+ for (let unit = 0; unit < 65536; unit += 1) {
38
+ const character = String.fromCharCode(unit);
39
+ const lower = character.toLowerCase();
40
+ fold[unit] = lower.length === 1 ? lower.charCodeAt(0) : unit;
41
+ upper[unit] = character === character.toUpperCase() && character !== lower ? 1 : 0;
42
+ }
43
+ caseTablesCache = { fold, upper };
44
+ return caseTablesCache;
45
+ };
46
+ /** Characters that end a word in a name or a path: `/ \ - _ .` and space. */
47
+ const isSeparator = (unit) => unit === 47 || unit === 92 || unit === 45 || unit === 95 || unit === 46 || unit === 32;
48
+ const literalScore = (length) => BASE * length + BONUS_CONSECUTIVE * Math.max(0, length - 1);
49
+ /**
50
+ * Parses the compact query syntax; whitespace means AND. `!` negates, `'`
51
+ * asks for a contiguous run, `^` and `$` anchor. A lowercase term ignores
52
+ * case and a single uppercase character makes that term case-sensitive.
53
+ */
54
+ const compileQuery = (query) => {
55
+ const terms = [];
56
+ let positiveTerms = 0;
57
+ for (const raw of query.trim().split(/\s+/u)) {
58
+ let text = raw;
59
+ const negative = text.startsWith('!');
60
+ if (negative)
61
+ text = text.slice(1);
62
+ const exact = text.startsWith("'");
63
+ if (exact)
64
+ text = text.slice(1);
65
+ const anchoredStart = text.startsWith('^');
66
+ if (anchoredStart)
67
+ text = text.slice(1);
68
+ const anchoredEnd = text.endsWith('$');
69
+ if (anchoredEnd)
70
+ text = text.slice(0, -1);
71
+ if (text === '')
72
+ continue;
73
+ const kind = anchoredStart && anchoredEnd
74
+ ? 'equals'
75
+ : anchoredStart
76
+ ? 'prefix'
77
+ : anchoredEnd
78
+ ? 'suffix'
79
+ : exact
80
+ ? 'contains'
81
+ : 'fuzzy';
82
+ // Indexed, not iterated: iterating a string yields code points, which would
83
+ // drop the second half of every character outside the basic plane.
84
+ const needle = new Uint16Array(text.length);
85
+ for (let index = 0; index < text.length; index += 1)
86
+ needle[index] = text.charCodeAt(index);
87
+ // A folding term is already lowercase, so its needle needs no folding.
88
+ terms.push({ kind, negative, fold: text === text.toLowerCase(), needle });
89
+ if (!negative)
90
+ positiveTerms += 1;
91
+ }
92
+ return { terms, positiveTerms };
93
+ };
94
+ /**
95
+ * Whether a query holds a term once parsed; whitespace and bare operators
96
+ * (`!`, `'`, `^`, `$`) carry none. A filter treats a query without terms as
97
+ * no filter at all.
98
+ */
99
+ export const hasQueryTerms = (query) => compileQuery(query).terms.length > 0;
100
+ /**
101
+ * Whether the query excludes with `!`. Every other operator only narrows as
102
+ * characters are added, but a negative term widens again as it grows: `!f`
103
+ * excludes more names than `!foo`, so an empty result midway is not a dead
104
+ * end (`menuQueryRefused`).
105
+ */
106
+ export const hasNegativeTerms = (query) => compileQuery(query).terms.some((term) => term.negative);
107
+ /**
108
+ * A typed array's cell at an index the loops below keep in range, which the
109
+ * compiler's indexed-access check cannot see.
110
+ */
111
+ const cell = (cells, index) => cells[index];
112
+ let previousRow = new Int32Array(256);
113
+ let currentRow = new Int32Array(256);
114
+ let parentCells = new Int32Array(1024);
115
+ /**
116
+ * Scores a subsequence term, or `NO_MATCH`. The dynamic program retains the
117
+ * highest score for every possible last position; its running gap maximum
118
+ * makes the gap transition linear in candidate length instead of comparing
119
+ * every pair of positions. Rows are reused, so scoring allocates nothing, and
120
+ * the parent links behind the positions are kept only when a caller asks.
121
+ */
122
+ const scoreSubsequence = (term, text, length, positions) => {
123
+ const needle = term.needle;
124
+ const needleLength = needle.length;
125
+ if (needleLength > length)
126
+ return NO_MATCH;
127
+ if (previousRow.length < length) {
128
+ previousRow = new Int32Array(length * 2);
129
+ currentRow = new Int32Array(length * 2);
130
+ }
131
+ if (positions !== null && parentCells.length < needleLength * length) {
132
+ parentCells = new Int32Array(needleLength * length * 2);
133
+ }
134
+ const tables = caseTables();
135
+ const fold = term.fold ? tables.fold : null;
136
+ const upper = tables.upper;
137
+ let previous = previousRow;
138
+ let current = currentRow;
139
+ for (let needleIndex = 0; needleIndex < needleLength; needleIndex += 1) {
140
+ const wanted = cell(needle, needleIndex);
141
+ let bestGapValue = UNREACHED;
142
+ let bestGapIndex = -1;
143
+ let reached = false;
144
+ for (let index = 0; index < length; index += 1) {
145
+ const gapIndex = index - 2;
146
+ if (needleIndex > 0 && gapIndex >= 0 && cell(previous, gapIndex) > UNREACHED) {
147
+ const value = cell(previous, gapIndex) + gapIndex * PENALTY_GAP_EXTENSION;
148
+ if (value > bestGapValue) {
149
+ bestGapValue = value;
150
+ bestGapIndex = gapIndex;
151
+ }
152
+ }
153
+ const unit = cell(text, index);
154
+ if ((fold === null ? unit : cell(fold, unit)) !== wanted) {
155
+ current[index] = UNREACHED;
156
+ continue;
157
+ }
158
+ const before = index === 0 ? 47 : cell(text, index - 1);
159
+ const characterScore = isSeparator(before)
160
+ ? BASE + BONUS_BOUNDARY
161
+ : cell(upper, unit) === 1 && cell(upper, before) === 0
162
+ ? BASE + BONUS_CAMEL
163
+ : BASE;
164
+ let score = UNREACHED;
165
+ let parent = -1;
166
+ if (needleIndex === 0) {
167
+ score = characterScore;
168
+ }
169
+ else {
170
+ if (bestGapIndex >= 0) {
171
+ score =
172
+ bestGapValue + characterScore - PENALTY_GAP_START - gapIndex * PENALTY_GAP_EXTENSION;
173
+ parent = bestGapIndex;
174
+ }
175
+ if (index > 0 && cell(previous, index - 1) > UNREACHED) {
176
+ const consecutiveScore = cell(previous, index - 1) + characterScore + BONUS_CONSECUTIVE;
177
+ if (consecutiveScore >= score) {
178
+ score = consecutiveScore;
179
+ parent = index - 1;
180
+ }
181
+ }
182
+ }
183
+ current[index] = score;
184
+ if (positions !== null)
185
+ parentCells[needleIndex * length + index] = parent;
186
+ if (score > UNREACHED)
187
+ reached = true;
188
+ }
189
+ if (!reached)
190
+ return NO_MATCH;
191
+ const swap = previous;
192
+ previous = current;
193
+ current = swap;
194
+ }
195
+ let bestIndex = -1;
196
+ let bestScore = UNREACHED;
197
+ for (let index = 0; index < length; index += 1) {
198
+ if (cell(previous, index) > bestScore) {
199
+ bestScore = cell(previous, index);
200
+ bestIndex = index;
201
+ }
202
+ }
203
+ if (positions !== null) {
204
+ const first = positions.length;
205
+ let position = bestIndex;
206
+ for (let needleIndex = needleLength - 1; needleIndex >= 0; needleIndex -= 1) {
207
+ positions[first + needleIndex] = position;
208
+ position = cell(parentCells, needleIndex * length + position);
209
+ }
210
+ }
211
+ return bestScore;
212
+ };
213
+ /** Where a contiguous term starts in the candidate, or -1. */
214
+ const literalStart = (term, text, length) => {
215
+ const needle = term.needle;
216
+ const needleLength = needle.length;
217
+ if (needleLength > length)
218
+ return -1;
219
+ const fold = term.fold ? caseTables().fold : null;
220
+ const matchesAt = (start) => {
221
+ for (let offset = 0; offset < needleLength; offset += 1) {
222
+ const unit = cell(text, start + offset);
223
+ if ((fold === null ? unit : cell(fold, unit)) !== cell(needle, offset))
224
+ return false;
225
+ }
226
+ return true;
227
+ };
228
+ switch (term.kind) {
229
+ case 'equals':
230
+ return needleLength === length && matchesAt(0) ? 0 : -1;
231
+ case 'prefix':
232
+ return matchesAt(0) ? 0 : -1;
233
+ case 'suffix':
234
+ return matchesAt(length - needleLength) ? length - needleLength : -1;
235
+ default:
236
+ for (let start = 0; start <= length - needleLength; start += 1) {
237
+ if (matchesAt(start))
238
+ return start;
239
+ }
240
+ return -1;
241
+ }
242
+ };
243
+ /** Scores one term against a candidate, appending its positions when asked. */
244
+ const scoreTerm = (term, text, length, positions) => {
245
+ if (term.kind === 'fuzzy')
246
+ return scoreSubsequence(term, text, length, positions);
247
+ const start = literalStart(term, text, length);
248
+ if (start < 0)
249
+ return NO_MATCH;
250
+ if (positions !== null) {
251
+ for (let offset = 0; offset < term.needle.length; offset += 1)
252
+ positions.push(start + offset);
253
+ }
254
+ return literalScore(term.needle.length);
255
+ };
256
+ let stringUnits = new Uint16Array(256);
257
+ let cachedQueryText = null;
258
+ let cachedQuery = null;
259
+ /**
260
+ * Matches one string against a query, or null when it does not match.
261
+ * Whitespace-separated terms are ANDed and their scores summed; `!term`
262
+ * excludes, and `'exact`, `^prefix`, `suffix$`, and `^whole$` switch a term
263
+ * to contiguous matching. A lowercase term ignores case; one with an
264
+ * uppercase character honours it. An empty query (or one that only
265
+ * excludes) matches at zero with no positions, so "no filter" needs no
266
+ * branch. The last query stays compiled, because a list is matched row
267
+ * after row against the same one.
268
+ */
269
+ export const matchQuery = (candidate, query) => {
270
+ if (cachedQuery === null || cachedQueryText !== query) {
271
+ cachedQuery = compileQuery(query);
272
+ cachedQueryText = query;
273
+ }
274
+ if (stringUnits.length < candidate.length)
275
+ stringUnits = new Uint16Array(candidate.length * 2);
276
+ for (let index = 0; index < candidate.length; index += 1) {
277
+ stringUnits[index] = candidate.charCodeAt(index);
278
+ }
279
+ const positions = [];
280
+ let score = 0;
281
+ for (const term of cachedQuery.terms) {
282
+ if (term.negative) {
283
+ if (scoreTerm(term, stringUnits, candidate.length, null) !== NO_MATCH)
284
+ return null;
285
+ continue;
286
+ }
287
+ const termScore = scoreTerm(term, stringUnits, candidate.length, positions);
288
+ if (termScore === NO_MATCH)
289
+ return null;
290
+ score += termScore;
291
+ }
292
+ if (cachedQuery.positiveTerms > 1) {
293
+ return { score, positions: [...new Set(positions)].sort((left, right) => left - right) };
294
+ }
295
+ return { score, positions };
296
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Filtered menus: the fuzzy matcher (`matchQuery`), the rules every filtered
3
+ * menu and palette shares (a refused keystroke, the cursor's moves, the trail
4
+ * of levels opened in place), the visual bell's beat, and the menu look in
5
+ * menu.css under `.listing-root`.
6
+ */
7
+ export { hasNegativeTerms, hasQueryTerms, matchQuery, type FuzzyMatch } from './fuzzyMatch.js';
8
+ export { enteredLevel, leftLevel, menuQueryRefused, movedPickableCursor, moveMenuCursor, pickableCursor, returnedCursor, trailLevel, type LevelReturn, type LevelStep, type PickableRow } from './MenuQuery.logic.js';
9
+ export { useBellBeat } from './useBellBeat.js';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Filtered menus: the fuzzy matcher (`matchQuery`), the rules every filtered
3
+ * menu and palette shares (a refused keystroke, the cursor's moves, the trail
4
+ * of levels opened in place), the visual bell's beat, and the menu look in
5
+ * menu.css under `.listing-root`.
6
+ */
7
+ export { hasNegativeTerms, hasQueryTerms, matchQuery } from './fuzzyMatch.js';
8
+ export { enteredLevel, leftLevel, menuQueryRefused, movedPickableCursor, moveMenuCursor, pickableCursor, returnedCursor, trailLevel } from './MenuQuery.logic.js';
9
+ export { useBellBeat } from './useBellBeat.js';