@greppleai/grip-tui 0.0.0-stage → 0.0.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 (158) hide show
  1. package/README.md +818 -2
  2. package/dist/autocomplete.d.ts +48 -0
  3. package/dist/autocomplete.d.ts.map +1 -0
  4. package/dist/autocomplete.js +566 -0
  5. package/dist/autocomplete.js.map +1 -0
  6. package/dist/components/alt-screen-flash.d.ts +13 -0
  7. package/dist/components/alt-screen-flash.d.ts.map +1 -0
  8. package/dist/components/alt-screen-flash.js +37 -0
  9. package/dist/components/alt-screen-flash.js.map +1 -0
  10. package/dist/components/box.d.ts +22 -0
  11. package/dist/components/box.d.ts.map +1 -0
  12. package/dist/components/box.js +104 -0
  13. package/dist/components/box.js.map +1 -0
  14. package/dist/components/cancellable-loader.d.ts +22 -0
  15. package/dist/components/cancellable-loader.d.ts.map +1 -0
  16. package/dist/components/cancellable-loader.js +35 -0
  17. package/dist/components/cancellable-loader.js.map +1 -0
  18. package/dist/components/editor.d.ts +292 -0
  19. package/dist/components/editor.d.ts.map +1 -0
  20. package/dist/components/editor.js +1887 -0
  21. package/dist/components/editor.js.map +1 -0
  22. package/dist/components/h-stack.d.ts +7 -0
  23. package/dist/components/h-stack.d.ts.map +1 -0
  24. package/dist/components/h-stack.js +43 -0
  25. package/dist/components/h-stack.js.map +1 -0
  26. package/dist/components/image.d.ts +32 -0
  27. package/dist/components/image.d.ts.map +1 -0
  28. package/dist/components/image.js +76 -0
  29. package/dist/components/image.js.map +1 -0
  30. package/dist/components/input.d.ts +46 -0
  31. package/dist/components/input.d.ts.map +1 -0
  32. package/dist/components/input.js +352 -0
  33. package/dist/components/input.js.map +1 -0
  34. package/dist/components/loader.d.ts +32 -0
  35. package/dist/components/loader.d.ts.map +1 -0
  36. package/dist/components/loader.js +80 -0
  37. package/dist/components/loader.js.map +1 -0
  38. package/dist/components/markdown.d.ts +132 -0
  39. package/dist/components/markdown.d.ts.map +1 -0
  40. package/dist/components/markdown.js +717 -0
  41. package/dist/components/markdown.js.map +1 -0
  42. package/dist/components/scroll-view.d.ts +53 -0
  43. package/dist/components/scroll-view.d.ts.map +1 -0
  44. package/dist/components/scroll-view.js +173 -0
  45. package/dist/components/scroll-view.js.map +1 -0
  46. package/dist/components/select-list.d.ts +50 -0
  47. package/dist/components/select-list.d.ts.map +1 -0
  48. package/dist/components/select-list.js +159 -0
  49. package/dist/components/select-list.js.map +1 -0
  50. package/dist/components/settings-list.d.ts +52 -0
  51. package/dist/components/settings-list.d.ts.map +1 -0
  52. package/dist/components/settings-list.js +187 -0
  53. package/dist/components/settings-list.js.map +1 -0
  54. package/dist/components/spacer.d.ts +12 -0
  55. package/dist/components/spacer.d.ts.map +1 -0
  56. package/dist/components/spacer.js +23 -0
  57. package/dist/components/spacer.js.map +1 -0
  58. package/dist/components/stack.d.ts +32 -0
  59. package/dist/components/stack.d.ts.map +1 -0
  60. package/dist/components/stack.js +122 -0
  61. package/dist/components/stack.js.map +1 -0
  62. package/dist/components/text.d.ts +19 -0
  63. package/dist/components/text.d.ts.map +1 -0
  64. package/dist/components/text.js +89 -0
  65. package/dist/components/text.js.map +1 -0
  66. package/dist/components/truncated-text.d.ts +13 -0
  67. package/dist/components/truncated-text.d.ts.map +1 -0
  68. package/dist/components/truncated-text.js +51 -0
  69. package/dist/components/truncated-text.js.map +1 -0
  70. package/dist/components/v-stack.d.ts +8 -0
  71. package/dist/components/v-stack.d.ts.map +1 -0
  72. package/dist/components/v-stack.js +27 -0
  73. package/dist/components/v-stack.js.map +1 -0
  74. package/dist/editor-component.d.ts +39 -0
  75. package/dist/editor-component.d.ts.map +1 -0
  76. package/dist/editor-component.js +2 -0
  77. package/dist/editor-component.js.map +1 -0
  78. package/dist/fuzzy.d.ts +16 -0
  79. package/dist/fuzzy.d.ts.map +1 -0
  80. package/dist/fuzzy.js +101 -0
  81. package/dist/fuzzy.js.map +1 -0
  82. package/dist/index.d.ts +30 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +41 -0
  85. package/dist/index.js.map +1 -0
  86. package/dist/keybindings.d.ts +243 -0
  87. package/dist/keybindings.d.ts.map +1 -0
  88. package/dist/keybindings.js +209 -0
  89. package/dist/keybindings.js.map +1 -0
  90. package/dist/keys.d.ts +184 -0
  91. package/dist/keys.d.ts.map +1 -0
  92. package/dist/keys.js +1053 -0
  93. package/dist/keys.js.map +1 -0
  94. package/dist/kill-ring.d.ts +30 -0
  95. package/dist/kill-ring.d.ts.map +1 -0
  96. package/dist/kill-ring.js +37 -0
  97. package/dist/kill-ring.js.map +1 -0
  98. package/dist/latex.d.ts +10 -0
  99. package/dist/latex.d.ts.map +1 -0
  100. package/dist/latex.js +1406 -0
  101. package/dist/latex.js.map +1 -0
  102. package/dist/layout-node.d.ts +43 -0
  103. package/dist/layout-node.d.ts.map +1 -0
  104. package/dist/layout-node.js +6 -0
  105. package/dist/layout-node.js.map +1 -0
  106. package/dist/layout.d.ts +40 -0
  107. package/dist/layout.d.ts.map +1 -0
  108. package/dist/layout.js +386 -0
  109. package/dist/layout.js.map +1 -0
  110. package/dist/native-modifiers.d.ts +3 -0
  111. package/dist/native-modifiers.d.ts.map +1 -0
  112. package/dist/native-modifiers.js +53 -0
  113. package/dist/native-modifiers.js.map +1 -0
  114. package/dist/stdin-buffer.d.ts +58 -0
  115. package/dist/stdin-buffer.d.ts.map +1 -0
  116. package/dist/stdin-buffer.js +318 -0
  117. package/dist/stdin-buffer.js.map +1 -0
  118. package/dist/terminal-control.d.ts +5 -0
  119. package/dist/terminal-control.d.ts.map +1 -0
  120. package/dist/terminal-control.js +26 -0
  121. package/dist/terminal-control.js.map +1 -0
  122. package/dist/terminal-image.d.ts +112 -0
  123. package/dist/terminal-image.d.ts.map +1 -0
  124. package/dist/terminal-image.js +508 -0
  125. package/dist/terminal-image.js.map +1 -0
  126. package/dist/terminal.d.ts +117 -0
  127. package/dist/terminal.d.ts.map +1 -0
  128. package/dist/terminal.js +490 -0
  129. package/dist/terminal.js.map +1 -0
  130. package/dist/tui-alt-screen.d.ts +114 -0
  131. package/dist/tui-alt-screen.d.ts.map +1 -0
  132. package/dist/tui-alt-screen.js +950 -0
  133. package/dist/tui-alt-screen.js.map +1 -0
  134. package/dist/tui-main-screen.d.ts +52 -0
  135. package/dist/tui-main-screen.d.ts.map +1 -0
  136. package/dist/tui-main-screen.js +511 -0
  137. package/dist/tui-main-screen.js.map +1 -0
  138. package/dist/tui.d.ts +295 -0
  139. package/dist/tui.d.ts.map +1 -0
  140. package/dist/tui.js +868 -0
  141. package/dist/tui.js.map +1 -0
  142. package/dist/undo-stack.d.ts +17 -0
  143. package/dist/undo-stack.d.ts.map +1 -0
  144. package/dist/undo-stack.js +25 -0
  145. package/dist/undo-stack.js.map +1 -0
  146. package/dist/utils.d.ts +96 -0
  147. package/dist/utils.d.ts.map +1 -0
  148. package/dist/utils.js +1106 -0
  149. package/dist/utils.js.map +1 -0
  150. package/dist/word-navigation.d.ts +25 -0
  151. package/dist/word-navigation.d.ts.map +1 -0
  152. package/dist/word-navigation.js +94 -0
  153. package/dist/word-navigation.js.map +1 -0
  154. package/native/darwin/prebuilds/darwin-arm64/darwin-modifiers.node +0 -0
  155. package/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
  156. package/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  157. package/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  158. package/package.json +47 -5
@@ -0,0 +1,122 @@
1
+ import { LAYOUT_NODE, } from "../layout-node.js";
2
+ import { Container } from "../tui.js";
3
+ function isStackEntry(child) {
4
+ return !("render" in child);
5
+ }
6
+ function normalizeSize(value, fallback) {
7
+ return value === undefined || !Number.isFinite(value) ? fallback : Math.max(0, Math.floor(value));
8
+ }
9
+ export class Stack extends Container {
10
+ entries = [];
11
+ gap;
12
+ align;
13
+ constructor(children = [], options = {}) {
14
+ super();
15
+ this.gap = normalizeSize(options.gap, 0);
16
+ this.align = options.align ?? "stretch";
17
+ for (const child of children) {
18
+ if (isStackEntry(child))
19
+ this.addChild(child.component, child);
20
+ else
21
+ this.addChild(child);
22
+ }
23
+ }
24
+ addChild(component, options = {}) {
25
+ super.addChild(component);
26
+ this.entries.push({
27
+ component,
28
+ ...(options.basis === undefined ? {} : { basis: options.basis }),
29
+ ...(options.grow === undefined ? {} : { grow: normalizeSize(options.grow, 0) }),
30
+ ...(options.shrink === undefined ? {} : { shrink: normalizeSize(options.shrink, 1) }),
31
+ ...(options.minSize === undefined ? {} : { minSize: normalizeSize(options.minSize, 0) }),
32
+ ...(options.maxSize === undefined ? {} : { maxSize: normalizeSize(options.maxSize, Number.MAX_SAFE_INTEGER) }),
33
+ ...(options.visible === undefined ? {} : { visible: options.visible }),
34
+ });
35
+ }
36
+ removeChild(component) {
37
+ super.removeChild(component);
38
+ const index = this.entries.findIndex((entry) => entry.component === component);
39
+ if (index !== -1)
40
+ this.entries.splice(index, 1);
41
+ }
42
+ clear() {
43
+ super.clear();
44
+ this.entries.length = 0;
45
+ }
46
+ [LAYOUT_NODE]() {
47
+ return {
48
+ type: this.layoutType,
49
+ entries: this.entries,
50
+ gap: this.gap,
51
+ align: this.align,
52
+ };
53
+ }
54
+ }
55
+ export function visibleStackEntries(entries, viewport) {
56
+ return entries.filter((entry) => entry.visible?.(viewport) ?? true);
57
+ }
58
+ function clampSize(size, entry) {
59
+ const min = Math.max(0, Math.floor(entry.minSize ?? 0));
60
+ const max = Math.max(min, Math.floor(entry.maxSize ?? Number.MAX_SAFE_INTEGER));
61
+ return Math.max(min, Math.min(max, Math.max(0, Math.floor(size))));
62
+ }
63
+ function getDistributionWeight(entry, size, mode) {
64
+ return mode === "grow" ? (entry.grow ?? 0) : (entry.shrink ?? 1) * Math.max(1, size);
65
+ }
66
+ function getDistributionCapacity(entry, size, mode) {
67
+ return mode === "grow" ? (entry.maxSize ?? Number.MAX_SAFE_INTEGER) - size : size - (entry.minSize ?? 0);
68
+ }
69
+ function collectDistributionCandidates(sizes, entries, mode) {
70
+ const candidates = [];
71
+ for (let index = 0; index < entries.length; index++) {
72
+ const entry = entries[index];
73
+ const size = sizes[index];
74
+ const weight = getDistributionWeight(entry, size, mode);
75
+ const capacity = getDistributionCapacity(entry, size, mode);
76
+ if (weight > 0 && capacity > 0)
77
+ candidates.push({ index, weight, capacity });
78
+ }
79
+ return candidates;
80
+ }
81
+ function distributeStackSizeRound(sizes, candidates, amount, mode) {
82
+ const totalWeight = candidates.reduce((sum, candidate) => sum + candidate.weight, 0);
83
+ let remaining = amount;
84
+ let distributed = 0;
85
+ for (const candidate of candidates) {
86
+ if (remaining <= 0)
87
+ break;
88
+ const proposed = Math.max(1, Math.floor((remaining * candidate.weight) / totalWeight));
89
+ const delta = Math.min(remaining, proposed, candidate.capacity);
90
+ if (delta <= 0)
91
+ continue;
92
+ sizes[candidate.index] = sizes[candidate.index] + (mode === "grow" ? delta : -delta);
93
+ remaining -= delta;
94
+ distributed += delta;
95
+ }
96
+ return distributed;
97
+ }
98
+ function distribute(sizes, entries, amount, mode) {
99
+ let remaining = amount;
100
+ while (remaining > 0) {
101
+ const candidates = collectDistributionCandidates(sizes, entries, mode);
102
+ if (candidates.length === 0)
103
+ return;
104
+ const distributed = distributeStackSizeRound(sizes, candidates, remaining, mode);
105
+ if (distributed === 0)
106
+ return;
107
+ remaining -= distributed;
108
+ }
109
+ }
110
+ export function allocateStackSizes(entries, intrinsicSizes, availableSize, gap) {
111
+ const sizes = entries.map((entry, index) => clampSize(entry.basis === undefined || entry.basis === "auto" ? (intrinsicSizes[index] ?? 0) : entry.basis, entry));
112
+ if (availableSize === undefined)
113
+ return sizes;
114
+ const contentSize = Math.max(0, Math.floor(availableSize) - Math.max(0, entries.length - 1) * gap);
115
+ const total = sizes.reduce((sum, size) => sum + size, 0);
116
+ if (total < contentSize)
117
+ distribute(sizes, entries, contentSize - total, "grow");
118
+ else if (total > contentSize)
119
+ distribute(sizes, entries, total - contentSize, "shrink");
120
+ return sizes;
121
+ }
122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F,OAAO,KAAK,CAAC;AAAA,CACb","sourcesContent":["import {\n\tLAYOUT_NODE,\n\ttype LayoutViewport,\n\ttype StackAlignment,\n\ttype StackLayoutEntry,\n\ttype StackLayoutNode,\n\ttype StackLayoutType,\n} from \"../layout-node.ts\";\nimport { type Component, Container } from \"../tui.ts\";\n\ntype StackDistributionMode = \"grow\" | \"shrink\";\n\ninterface StackDistributionCandidate {\n\tindex: number;\n\tweight: number;\n\tcapacity: number;\n}\n\nexport interface StackEntryOptions {\n\tbasis?: number | \"auto\";\n\tgrow?: number;\n\tshrink?: number;\n\tminSize?: number;\n\tmaxSize?: number;\n\tvisible?: (viewport: LayoutViewport) => boolean;\n}\n\nexport interface StackEntry extends StackEntryOptions {\n\tcomponent: Component;\n}\n\nexport type StackChild = Component | StackEntry;\n\nexport interface StackOptions {\n\tgap?: number;\n\talign?: StackAlignment;\n}\n\nfunction isStackEntry(child: StackChild): child is StackEntry {\n\treturn !(\"render\" in child);\n}\n\nfunction normalizeSize(value: number | undefined, fallback: number): number {\n\treturn value === undefined || !Number.isFinite(value) ? fallback : Math.max(0, Math.floor(value));\n}\n\nexport abstract class Stack extends Container {\n\tprotected readonly entries: StackLayoutEntry[] = [];\n\tprotected readonly gap: number;\n\tprotected readonly align: StackAlignment;\n\tprotected abstract readonly layoutType: StackLayoutType;\n\n\tconstructor(children: StackChild[] = [], options: StackOptions = {}) {\n\t\tsuper();\n\t\tthis.gap = normalizeSize(options.gap, 0);\n\t\tthis.align = options.align ?? \"stretch\";\n\t\tfor (const child of children) {\n\t\t\tif (isStackEntry(child)) this.addChild(child.component, child);\n\t\t\telse this.addChild(child);\n\t\t}\n\t}\n\n\toverride addChild(component: Component, options: StackEntryOptions = {}): void {\n\t\tsuper.addChild(component);\n\t\tthis.entries.push({\n\t\t\tcomponent,\n\t\t\t...(options.basis === undefined ? {} : { basis: options.basis }),\n\t\t\t...(options.grow === undefined ? {} : { grow: normalizeSize(options.grow, 0) }),\n\t\t\t...(options.shrink === undefined ? {} : { shrink: normalizeSize(options.shrink, 1) }),\n\t\t\t...(options.minSize === undefined ? {} : { minSize: normalizeSize(options.minSize, 0) }),\n\t\t\t...(options.maxSize === undefined ? {} : { maxSize: normalizeSize(options.maxSize, Number.MAX_SAFE_INTEGER) }),\n\t\t\t...(options.visible === undefined ? {} : { visible: options.visible }),\n\t\t});\n\t}\n\n\toverride removeChild(component: Component): void {\n\t\tsuper.removeChild(component);\n\t\tconst index = this.entries.findIndex((entry) => entry.component === component);\n\t\tif (index !== -1) this.entries.splice(index, 1);\n\t}\n\n\toverride clear(): void {\n\t\tsuper.clear();\n\t\tthis.entries.length = 0;\n\t}\n\n\t[LAYOUT_NODE](): StackLayoutNode {\n\t\treturn {\n\t\t\ttype: this.layoutType,\n\t\t\tentries: this.entries,\n\t\t\tgap: this.gap,\n\t\t\talign: this.align,\n\t\t};\n\t}\n}\n\nexport function visibleStackEntries(\n\tentries: readonly StackLayoutEntry[],\n\tviewport: LayoutViewport,\n): StackLayoutEntry[] {\n\treturn entries.filter((entry) => entry.visible?.(viewport) ?? true);\n}\n\nfunction clampSize(size: number, entry: StackLayoutEntry): number {\n\tconst min = Math.max(0, Math.floor(entry.minSize ?? 0));\n\tconst max = Math.max(min, Math.floor(entry.maxSize ?? Number.MAX_SAFE_INTEGER));\n\treturn Math.max(min, Math.min(max, Math.max(0, Math.floor(size))));\n}\n\nfunction getDistributionWeight(entry: StackLayoutEntry, size: number, mode: StackDistributionMode): number {\n\treturn mode === \"grow\" ? (entry.grow ?? 0) : (entry.shrink ?? 1) * Math.max(1, size);\n}\n\nfunction getDistributionCapacity(entry: StackLayoutEntry, size: number, mode: StackDistributionMode): number {\n\treturn mode === \"grow\" ? (entry.maxSize ?? Number.MAX_SAFE_INTEGER) - size : size - (entry.minSize ?? 0);\n}\n\nfunction collectDistributionCandidates(\n\tsizes: number[],\n\tentries: readonly StackLayoutEntry[],\n\tmode: StackDistributionMode,\n): StackDistributionCandidate[] {\n\tconst candidates: StackDistributionCandidate[] = [];\n\tfor (let index = 0; index < entries.length; index++) {\n\t\tconst entry = entries[index]!;\n\t\tconst size = sizes[index]!;\n\t\tconst weight = getDistributionWeight(entry, size, mode);\n\t\tconst capacity = getDistributionCapacity(entry, size, mode);\n\t\tif (weight > 0 && capacity > 0) candidates.push({ index, weight, capacity });\n\t}\n\treturn candidates;\n}\n\nfunction distributeStackSizeRound(\n\tsizes: number[],\n\tcandidates: StackDistributionCandidate[],\n\tamount: number,\n\tmode: StackDistributionMode,\n): number {\n\tconst totalWeight = candidates.reduce((sum, candidate) => sum + candidate.weight, 0);\n\tlet remaining = amount;\n\tlet distributed = 0;\n\tfor (const candidate of candidates) {\n\t\tif (remaining <= 0) break;\n\t\tconst proposed = Math.max(1, Math.floor((remaining * candidate.weight) / totalWeight));\n\t\tconst delta = Math.min(remaining, proposed, candidate.capacity);\n\t\tif (delta <= 0) continue;\n\t\tsizes[candidate.index] = sizes[candidate.index]! + (mode === \"grow\" ? delta : -delta);\n\t\tremaining -= delta;\n\t\tdistributed += delta;\n\t}\n\treturn distributed;\n}\n\nfunction distribute(\n\tsizes: number[],\n\tentries: readonly StackLayoutEntry[],\n\tamount: number,\n\tmode: StackDistributionMode,\n): void {\n\tlet remaining = amount;\n\twhile (remaining > 0) {\n\t\tconst candidates = collectDistributionCandidates(sizes, entries, mode);\n\t\tif (candidates.length === 0) return;\n\t\tconst distributed = distributeStackSizeRound(sizes, candidates, remaining, mode);\n\t\tif (distributed === 0) return;\n\t\tremaining -= distributed;\n\t}\n}\n\nexport function allocateStackSizes(\n\tentries: readonly StackLayoutEntry[],\n\tintrinsicSizes: readonly number[],\n\tavailableSize: number | undefined,\n\tgap: number,\n): number[] {\n\tconst sizes = entries.map((entry, index) =>\n\t\tclampSize(\n\t\t\tentry.basis === undefined || entry.basis === \"auto\" ? (intrinsicSizes[index] ?? 0) : entry.basis,\n\t\t\tentry,\n\t\t),\n\t);\n\tif (availableSize === undefined) return sizes;\n\n\tconst contentSize = Math.max(0, Math.floor(availableSize) - Math.max(0, entries.length - 1) * gap);\n\tconst total = sizes.reduce((sum, size) => sum + size, 0);\n\tif (total < contentSize) distribute(sizes, entries, contentSize - total, \"grow\");\n\telse if (total > contentSize) distribute(sizes, entries, total - contentSize, \"shrink\");\n\treturn sizes;\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import type { Component } from "../tui.ts";
2
+ /**
3
+ * Text component - displays multi-line text with word wrapping
4
+ */
5
+ export declare class Text implements Component {
6
+ private text;
7
+ private paddingX;
8
+ private paddingY;
9
+ private customBgFn?;
10
+ private cachedText?;
11
+ private cachedWidth?;
12
+ private cachedLines?;
13
+ constructor(text?: string, paddingX?: number, paddingY?: number, customBgFn?: (text: string) => string);
14
+ setText(text: string): void;
15
+ setCustomBgFn(customBgFn?: (text: string) => string): void;
16
+ invalidate(): void;
17
+ render(width: number): string[];
18
+ }
19
+ //# sourceMappingURL=text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/components/text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C;;GAEG;AACH,qBAAa,IAAK,YAAW,SAAS;IACrC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAC,CAA2B;IAG9C,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,WAAW,CAAC,CAAW;IAE/B,YAAY,IAAI,GAAE,MAAW,EAAE,QAAQ,GAAE,MAAU,EAAE,QAAQ,GAAE,MAAU,EAAE,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,EAK/G;IAED,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAK1B;IAED,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAKzD;IAED,UAAU,IAAI,IAAI,CAIjB;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CA4D9B;CACD","sourcesContent":["import type { Component } from \"../tui.ts\";\nimport { applyBackgroundToLine, visibleWidth, wrapTextWithAnsi } from \"../utils.ts\";\n\n/**\n * Text component - displays multi-line text with word wrapping\n */\nexport class Text implements Component {\n\tprivate text: string;\n\tprivate paddingX: number; // Left/right padding\n\tprivate paddingY: number; // Top/bottom padding\n\tprivate customBgFn?: (text: string) => string;\n\n\t// Cache for rendered output\n\tprivate cachedText?: string;\n\tprivate cachedWidth?: number;\n\tprivate cachedLines?: string[];\n\n\tconstructor(text: string = \"\", paddingX: number = 1, paddingY: number = 1, customBgFn?: (text: string) => string) {\n\t\tthis.text = text;\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingY = paddingY;\n\t\tthis.customBgFn = customBgFn;\n\t}\n\n\tsetText(text: string): void {\n\t\tthis.text = text;\n\t\tthis.cachedText = undefined;\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n\n\tsetCustomBgFn(customBgFn?: (text: string) => string): void {\n\t\tthis.customBgFn = customBgFn;\n\t\tthis.cachedText = undefined;\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.cachedText = undefined;\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n\n\trender(width: number): string[] {\n\t\t// Check cache\n\t\tif (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {\n\t\t\treturn this.cachedLines;\n\t\t}\n\n\t\t// Don't render anything if there's no actual text\n\t\tif (!this.text || this.text.trim() === \"\") {\n\t\t\tconst result: string[] = [];\n\t\t\tthis.cachedText = this.text;\n\t\t\tthis.cachedWidth = width;\n\t\t\tthis.cachedLines = result;\n\t\t\treturn result;\n\t\t}\n\n\t\t// Replace tabs with 3 spaces\n\t\tconst normalizedText = this.text.replace(/\\t/g, \" \");\n\n\t\t// Calculate content width (subtract left/right margins)\n\t\tconst contentWidth = Math.max(1, width - this.paddingX * 2);\n\n\t\t// Wrap text (this preserves ANSI codes but does NOT pad)\n\t\tconst wrappedLines = wrapTextWithAnsi(normalizedText, contentWidth);\n\n\t\t// Add margins and background to each line\n\t\tconst leftMargin = \" \".repeat(this.paddingX);\n\t\tconst rightMargin = \" \".repeat(this.paddingX);\n\t\tconst contentLines: string[] = [];\n\n\t\tfor (const line of wrappedLines) {\n\t\t\t// Add margins\n\t\t\tconst lineWithMargins = leftMargin + line + rightMargin;\n\n\t\t\t// Apply background if specified (this also pads to full width)\n\t\t\tif (this.customBgFn) {\n\t\t\t\tcontentLines.push(applyBackgroundToLine(lineWithMargins, width, this.customBgFn));\n\t\t\t} else {\n\t\t\t\t// No background - just pad to width with spaces\n\t\t\t\tconst visibleLen = visibleWidth(lineWithMargins);\n\t\t\t\tconst paddingNeeded = Math.max(0, width - visibleLen);\n\t\t\t\tcontentLines.push(lineWithMargins + \" \".repeat(paddingNeeded));\n\t\t\t}\n\t\t}\n\n\t\t// Add top/bottom padding (empty lines)\n\t\tconst emptyLine = \" \".repeat(width);\n\t\tconst emptyLines: string[] = [];\n\t\tfor (let i = 0; i < this.paddingY; i++) {\n\t\t\tconst line = this.customBgFn ? applyBackgroundToLine(emptyLine, width, this.customBgFn) : emptyLine;\n\t\t\temptyLines.push(line);\n\t\t}\n\n\t\tconst result = [...emptyLines, ...contentLines, ...emptyLines];\n\n\t\t// Update cache\n\t\tthis.cachedText = this.text;\n\t\tthis.cachedWidth = width;\n\t\tthis.cachedLines = result;\n\n\t\treturn result.length > 0 ? result : [\"\"];\n\t}\n}\n"]}
@@ -0,0 +1,89 @@
1
+ import { applyBackgroundToLine, visibleWidth, wrapTextWithAnsi } from "../utils.js";
2
+ /**
3
+ * Text component - displays multi-line text with word wrapping
4
+ */
5
+ export class Text {
6
+ text;
7
+ paddingX; // Left/right padding
8
+ paddingY; // Top/bottom padding
9
+ customBgFn;
10
+ // Cache for rendered output
11
+ cachedText;
12
+ cachedWidth;
13
+ cachedLines;
14
+ constructor(text = "", paddingX = 1, paddingY = 1, customBgFn) {
15
+ this.text = text;
16
+ this.paddingX = paddingX;
17
+ this.paddingY = paddingY;
18
+ this.customBgFn = customBgFn;
19
+ }
20
+ setText(text) {
21
+ this.text = text;
22
+ this.cachedText = undefined;
23
+ this.cachedWidth = undefined;
24
+ this.cachedLines = undefined;
25
+ }
26
+ setCustomBgFn(customBgFn) {
27
+ this.customBgFn = customBgFn;
28
+ this.cachedText = undefined;
29
+ this.cachedWidth = undefined;
30
+ this.cachedLines = undefined;
31
+ }
32
+ invalidate() {
33
+ this.cachedText = undefined;
34
+ this.cachedWidth = undefined;
35
+ this.cachedLines = undefined;
36
+ }
37
+ render(width) {
38
+ // Check cache
39
+ if (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {
40
+ return this.cachedLines;
41
+ }
42
+ // Don't render anything if there's no actual text
43
+ if (!this.text || this.text.trim() === "") {
44
+ const result = [];
45
+ this.cachedText = this.text;
46
+ this.cachedWidth = width;
47
+ this.cachedLines = result;
48
+ return result;
49
+ }
50
+ // Replace tabs with 3 spaces
51
+ const normalizedText = this.text.replace(/\t/g, " ");
52
+ // Calculate content width (subtract left/right margins)
53
+ const contentWidth = Math.max(1, width - this.paddingX * 2);
54
+ // Wrap text (this preserves ANSI codes but does NOT pad)
55
+ const wrappedLines = wrapTextWithAnsi(normalizedText, contentWidth);
56
+ // Add margins and background to each line
57
+ const leftMargin = " ".repeat(this.paddingX);
58
+ const rightMargin = " ".repeat(this.paddingX);
59
+ const contentLines = [];
60
+ for (const line of wrappedLines) {
61
+ // Add margins
62
+ const lineWithMargins = leftMargin + line + rightMargin;
63
+ // Apply background if specified (this also pads to full width)
64
+ if (this.customBgFn) {
65
+ contentLines.push(applyBackgroundToLine(lineWithMargins, width, this.customBgFn));
66
+ }
67
+ else {
68
+ // No background - just pad to width with spaces
69
+ const visibleLen = visibleWidth(lineWithMargins);
70
+ const paddingNeeded = Math.max(0, width - visibleLen);
71
+ contentLines.push(lineWithMargins + " ".repeat(paddingNeeded));
72
+ }
73
+ }
74
+ // Add top/bottom padding (empty lines)
75
+ const emptyLine = " ".repeat(width);
76
+ const emptyLines = [];
77
+ for (let i = 0; i < this.paddingY; i++) {
78
+ const line = this.customBgFn ? applyBackgroundToLine(emptyLine, width, this.customBgFn) : emptyLine;
79
+ emptyLines.push(line);
80
+ }
81
+ const result = [...emptyLines, ...contentLines, ...emptyLines];
82
+ // Update cache
83
+ this.cachedText = this.text;
84
+ this.cachedWidth = width;
85
+ this.cachedLines = result;
86
+ return result.length > 0 ? result : [""];
87
+ }
88
+ }
89
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/components/text.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpF;;GAEG;AACH,MAAM,OAAO,IAAI;IACR,IAAI,CAAS;IACb,QAAQ,CAAS,CAAC,qBAAqB;IACvC,QAAQ,CAAS,CAAC,qBAAqB;IACvC,UAAU,CAA4B;IAE9C,4BAA4B;IACpB,UAAU,CAAU;IACpB,WAAW,CAAU;IACrB,WAAW,CAAY;IAE/B,YAAY,IAAI,GAAW,EAAE,EAAE,QAAQ,GAAW,CAAC,EAAE,QAAQ,GAAW,CAAC,EAAE,UAAqC,EAAE;QACjH,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAAA,CAC7B;IAED,OAAO,CAAC,IAAY,EAAQ;QAC3B,IAAI,CAAC,IAAI,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C,CAAC,CAAC,qBAAqB,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACpG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QAED,MAAM,MAAM,GAAG,CAAC,GAAG,UAAU,EAAE,GAAG,YAAY,EAAE,GAAG,UAAU,CAAC,CAAC;QAE/D,eAAe;QACf,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAE1B,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAAA,CACzC;CACD","sourcesContent":["import type { Component } from \"../tui.ts\";\nimport { applyBackgroundToLine, visibleWidth, wrapTextWithAnsi } from \"../utils.ts\";\n\n/**\n * Text component - displays multi-line text with word wrapping\n */\nexport class Text implements Component {\n\tprivate text: string;\n\tprivate paddingX: number; // Left/right padding\n\tprivate paddingY: number; // Top/bottom padding\n\tprivate customBgFn?: (text: string) => string;\n\n\t// Cache for rendered output\n\tprivate cachedText?: string;\n\tprivate cachedWidth?: number;\n\tprivate cachedLines?: string[];\n\n\tconstructor(text: string = \"\", paddingX: number = 1, paddingY: number = 1, customBgFn?: (text: string) => string) {\n\t\tthis.text = text;\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingY = paddingY;\n\t\tthis.customBgFn = customBgFn;\n\t}\n\n\tsetText(text: string): void {\n\t\tthis.text = text;\n\t\tthis.cachedText = undefined;\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n\n\tsetCustomBgFn(customBgFn?: (text: string) => string): void {\n\t\tthis.customBgFn = customBgFn;\n\t\tthis.cachedText = undefined;\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.cachedText = undefined;\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n\n\trender(width: number): string[] {\n\t\t// Check cache\n\t\tif (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {\n\t\t\treturn this.cachedLines;\n\t\t}\n\n\t\t// Don't render anything if there's no actual text\n\t\tif (!this.text || this.text.trim() === \"\") {\n\t\t\tconst result: string[] = [];\n\t\t\tthis.cachedText = this.text;\n\t\t\tthis.cachedWidth = width;\n\t\t\tthis.cachedLines = result;\n\t\t\treturn result;\n\t\t}\n\n\t\t// Replace tabs with 3 spaces\n\t\tconst normalizedText = this.text.replace(/\\t/g, \" \");\n\n\t\t// Calculate content width (subtract left/right margins)\n\t\tconst contentWidth = Math.max(1, width - this.paddingX * 2);\n\n\t\t// Wrap text (this preserves ANSI codes but does NOT pad)\n\t\tconst wrappedLines = wrapTextWithAnsi(normalizedText, contentWidth);\n\n\t\t// Add margins and background to each line\n\t\tconst leftMargin = \" \".repeat(this.paddingX);\n\t\tconst rightMargin = \" \".repeat(this.paddingX);\n\t\tconst contentLines: string[] = [];\n\n\t\tfor (const line of wrappedLines) {\n\t\t\t// Add margins\n\t\t\tconst lineWithMargins = leftMargin + line + rightMargin;\n\n\t\t\t// Apply background if specified (this also pads to full width)\n\t\t\tif (this.customBgFn) {\n\t\t\t\tcontentLines.push(applyBackgroundToLine(lineWithMargins, width, this.customBgFn));\n\t\t\t} else {\n\t\t\t\t// No background - just pad to width with spaces\n\t\t\t\tconst visibleLen = visibleWidth(lineWithMargins);\n\t\t\t\tconst paddingNeeded = Math.max(0, width - visibleLen);\n\t\t\t\tcontentLines.push(lineWithMargins + \" \".repeat(paddingNeeded));\n\t\t\t}\n\t\t}\n\n\t\t// Add top/bottom padding (empty lines)\n\t\tconst emptyLine = \" \".repeat(width);\n\t\tconst emptyLines: string[] = [];\n\t\tfor (let i = 0; i < this.paddingY; i++) {\n\t\t\tconst line = this.customBgFn ? applyBackgroundToLine(emptyLine, width, this.customBgFn) : emptyLine;\n\t\t\temptyLines.push(line);\n\t\t}\n\n\t\tconst result = [...emptyLines, ...contentLines, ...emptyLines];\n\n\t\t// Update cache\n\t\tthis.cachedText = this.text;\n\t\tthis.cachedWidth = width;\n\t\tthis.cachedLines = result;\n\n\t\treturn result.length > 0 ? result : [\"\"];\n\t}\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { Component } from "../tui.ts";
2
+ /**
3
+ * Text component that truncates to fit viewport width
4
+ */
5
+ export declare class TruncatedText implements Component {
6
+ private text;
7
+ private paddingX;
8
+ private paddingY;
9
+ constructor(text: string, paddingX?: number, paddingY?: number);
10
+ invalidate(): void;
11
+ render(width: number): string[];
12
+ }
13
+ //# sourceMappingURL=truncated-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"truncated-text.d.ts","sourceRoot":"","sources":["../../src/components/truncated-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C;;GAEG;AACH,qBAAa,aAAc,YAAW,SAAS;IAC9C,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IAEzB,YAAY,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,EAAE,QAAQ,GAAE,MAAU,EAInE;IAED,UAAU,IAAI,IAAI,CAEjB;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CA0C9B;CACD","sourcesContent":["import type { Component } from \"../tui.ts\";\nimport { truncateToWidth, visibleWidth } from \"../utils.ts\";\n\n/**\n * Text component that truncates to fit viewport width\n */\nexport class TruncatedText implements Component {\n\tprivate text: string;\n\tprivate paddingX: number;\n\tprivate paddingY: number;\n\n\tconstructor(text: string, paddingX: number = 0, paddingY: number = 0) {\n\t\tthis.text = text;\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingY = paddingY;\n\t}\n\n\tinvalidate(): void {\n\t\t// No cached state to invalidate currently\n\t}\n\n\trender(width: number): string[] {\n\t\tconst result: string[] = [];\n\n\t\t// Empty line padded to width\n\t\tconst emptyLine = \" \".repeat(width);\n\n\t\t// Add vertical padding above\n\t\tfor (let i = 0; i < this.paddingY; i++) {\n\t\t\tresult.push(emptyLine);\n\t\t}\n\n\t\t// Calculate available width after horizontal padding\n\t\tconst availableWidth = Math.max(1, width - this.paddingX * 2);\n\n\t\t// Take only the first line (stop at newline)\n\t\tlet singleLineText = this.text;\n\t\tconst newlineIndex = this.text.indexOf(\"\\n\");\n\t\tif (newlineIndex !== -1) {\n\t\t\tsingleLineText = this.text.substring(0, newlineIndex);\n\t\t}\n\n\t\t// Truncate text if needed (accounting for ANSI codes)\n\t\tconst displayText = truncateToWidth(singleLineText, availableWidth);\n\n\t\t// Add horizontal padding\n\t\tconst leftPadding = \" \".repeat(this.paddingX);\n\t\tconst rightPadding = \" \".repeat(this.paddingX);\n\t\tconst lineWithPadding = leftPadding + displayText + rightPadding;\n\n\t\t// Pad line to exactly width characters\n\t\tconst lineVisibleWidth = visibleWidth(lineWithPadding);\n\t\tconst paddingNeeded = Math.max(0, width - lineVisibleWidth);\n\t\tconst finalLine = lineWithPadding + \" \".repeat(paddingNeeded);\n\n\t\tresult.push(finalLine);\n\n\t\t// Add vertical padding below\n\t\tfor (let i = 0; i < this.paddingY; i++) {\n\t\t\tresult.push(emptyLine);\n\t\t}\n\n\t\treturn result;\n\t}\n}\n"]}
@@ -0,0 +1,51 @@
1
+ import { truncateToWidth, visibleWidth } from "../utils.js";
2
+ /**
3
+ * Text component that truncates to fit viewport width
4
+ */
5
+ export class TruncatedText {
6
+ text;
7
+ paddingX;
8
+ paddingY;
9
+ constructor(text, paddingX = 0, paddingY = 0) {
10
+ this.text = text;
11
+ this.paddingX = paddingX;
12
+ this.paddingY = paddingY;
13
+ }
14
+ invalidate() {
15
+ // No cached state to invalidate currently
16
+ }
17
+ render(width) {
18
+ const result = [];
19
+ // Empty line padded to width
20
+ const emptyLine = " ".repeat(width);
21
+ // Add vertical padding above
22
+ for (let i = 0; i < this.paddingY; i++) {
23
+ result.push(emptyLine);
24
+ }
25
+ // Calculate available width after horizontal padding
26
+ const availableWidth = Math.max(1, width - this.paddingX * 2);
27
+ // Take only the first line (stop at newline)
28
+ let singleLineText = this.text;
29
+ const newlineIndex = this.text.indexOf("\n");
30
+ if (newlineIndex !== -1) {
31
+ singleLineText = this.text.substring(0, newlineIndex);
32
+ }
33
+ // Truncate text if needed (accounting for ANSI codes)
34
+ const displayText = truncateToWidth(singleLineText, availableWidth);
35
+ // Add horizontal padding
36
+ const leftPadding = " ".repeat(this.paddingX);
37
+ const rightPadding = " ".repeat(this.paddingX);
38
+ const lineWithPadding = leftPadding + displayText + rightPadding;
39
+ // Pad line to exactly width characters
40
+ const lineVisibleWidth = visibleWidth(lineWithPadding);
41
+ const paddingNeeded = Math.max(0, width - lineVisibleWidth);
42
+ const finalLine = lineWithPadding + " ".repeat(paddingNeeded);
43
+ result.push(finalLine);
44
+ // Add vertical padding below
45
+ for (let i = 0; i < this.paddingY; i++) {
46
+ result.push(emptyLine);
47
+ }
48
+ return result;
49
+ }
50
+ }
51
+ //# sourceMappingURL=truncated-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"truncated-text.js","sourceRoot":"","sources":["../../src/components/truncated-text.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE5D;;GAEG;AACH,MAAM,OAAO,aAAa;IACjB,IAAI,CAAS;IACb,QAAQ,CAAS;IACjB,QAAQ,CAAS;IAEzB,YAAY,IAAY,EAAE,QAAQ,GAAW,CAAC,EAAE,QAAQ,GAAW,CAAC,EAAE;QACrE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QA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Aa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,gBAAgB,CAAC,CAAC;QAC5D,MAAM,SAAS,GAAG,eAAe,GAAG,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QAE9D,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAEvB,6BAA6B;QAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC;QAED,OAAO,MAAM,CAAC;IAAA,CACd;CACD","sourcesContent":["import type { Component } from \"../tui.ts\";\nimport { truncateToWidth, visibleWidth } from \"../utils.ts\";\n\n/**\n * Text component that truncates to fit viewport width\n */\nexport class TruncatedText implements Component {\n\tprivate text: string;\n\tprivate paddingX: number;\n\tprivate paddingY: number;\n\n\tconstructor(text: string, paddingX: number = 0, paddingY: number = 0) {\n\t\tthis.text = text;\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingY = paddingY;\n\t}\n\n\tinvalidate(): void {\n\t\t// No cached state to invalidate currently\n\t}\n\n\trender(width: number): string[] {\n\t\tconst result: string[] = [];\n\n\t\t// Empty line padded to width\n\t\tconst emptyLine = \" \".repeat(width);\n\n\t\t// Add vertical padding above\n\t\tfor (let i = 0; i < this.paddingY; i++) {\n\t\t\tresult.push(emptyLine);\n\t\t}\n\n\t\t// Calculate available width after horizontal padding\n\t\tconst availableWidth = Math.max(1, width - this.paddingX * 2);\n\n\t\t// Take only the first line (stop at newline)\n\t\tlet singleLineText = this.text;\n\t\tconst newlineIndex = this.text.indexOf(\"\\n\");\n\t\tif (newlineIndex !== -1) {\n\t\t\tsingleLineText = this.text.substring(0, newlineIndex);\n\t\t}\n\n\t\t// Truncate text if needed (accounting for ANSI codes)\n\t\tconst displayText = truncateToWidth(singleLineText, availableWidth);\n\n\t\t// Add horizontal padding\n\t\tconst leftPadding = \" \".repeat(this.paddingX);\n\t\tconst rightPadding = \" \".repeat(this.paddingX);\n\t\tconst lineWithPadding = leftPadding + displayText + rightPadding;\n\n\t\t// Pad line to exactly width characters\n\t\tconst lineVisibleWidth = visibleWidth(lineWithPadding);\n\t\tconst paddingNeeded = Math.max(0, width - lineVisibleWidth);\n\t\tconst finalLine = lineWithPadding + \" \".repeat(paddingNeeded);\n\n\t\tresult.push(finalLine);\n\n\t\t// Add vertical padding below\n\t\tfor (let i = 0; i < this.paddingY; i++) {\n\t\t\tresult.push(emptyLine);\n\t\t}\n\n\t\treturn result;\n\t}\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { Stack, type StackChild, type StackOptions } from "./stack.ts";
2
+ export declare class VStack extends Stack {
3
+ protected readonly layoutType: "vstack";
4
+ constructor(children?: StackChild[], options?: StackOptions);
5
+ render(width: number): string[];
6
+ }
7
+ export type { StackChild, StackEntry, StackEntryOptions, StackOptions } from "./stack.ts";
8
+ //# sourceMappingURL=v-stack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v-stack.d.ts","sourceRoot":"","sources":["../../src/components/v-stack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAuB,MAAM,YAAY,CAAC;AAEhH,qBAAa,MAAO,SAAQ,KAAK;IAChC,SAAS,CAAC,QAAQ,CAAC,UAAU,WAAqB;IAElD,YAAY,QAAQ,GAAE,UAAU,EAAO,EAAE,OAAO,GAAE,YAAiB,EAElE;IAGQ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAoBvC;CACD;AAED,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC","sourcesContent":["import { allocateStackSizes, Stack, type StackChild, type StackOptions, visibleStackEntries } from \"./stack.ts\";\n\nexport class VStack extends Stack {\n\tprotected readonly layoutType = \"vstack\" as const;\n\n\tconstructor(children: StackChild[] = [], options: StackOptions = {}) {\n\t\tsuper(children, options);\n\t}\n\n\t// grip-ignore noExcessiveCollectionIterations: Each child contributes its rendered, gap, and padding rows exactly once, so the nested writes are linear in the final output lines. @class:3-32\n\toverride render(width: number): string[] {\n\t\tconst viewport = { width: Math.max(1, width), height: Number.MAX_SAFE_INTEGER };\n\t\tconst entries = visibleStackEntries(this.entries, viewport);\n\t\tconst rendered = entries.map((entry) => entry.component.render(viewport.width));\n\t\tconst sizes = allocateStackSizes(\n\t\t\tentries,\n\t\t\trendered.map((lines) => lines.length),\n\t\t\tundefined,\n\t\t\tthis.gap,\n\t\t);\n\t\tconst lines: string[] = [];\n\t\tfor (let index = 0; index < entries.length; index++) {\n\t\t\tif (index > 0) {\n\t\t\t\tfor (let gap = 0; gap < this.gap; gap++) lines.push(\"\");\n\t\t\t}\n\t\t\tconst childLines = rendered[index]!.slice(0, sizes[index]);\n\t\t\tlines.push(...childLines);\n\t\t\tfor (let padding = childLines.length; padding < sizes[index]!; padding++) lines.push(\"\");\n\t\t}\n\t\treturn lines;\n\t}\n}\n\nexport type { StackChild, StackEntry, StackEntryOptions, StackOptions } from \"./stack.ts\";\n"]}
@@ -0,0 +1,27 @@
1
+ import { allocateStackSizes, Stack, visibleStackEntries } from "./stack.js";
2
+ export class VStack extends Stack {
3
+ layoutType = "vstack";
4
+ constructor(children = [], options = {}) {
5
+ super(children, options);
6
+ }
7
+ // grip-ignore noExcessiveCollectionIterations: Each child contributes its rendered, gap, and padding rows exactly once, so the nested writes are linear in the final output lines. @class:3-32
8
+ render(width) {
9
+ const viewport = { width: Math.max(1, width), height: Number.MAX_SAFE_INTEGER };
10
+ const entries = visibleStackEntries(this.entries, viewport);
11
+ const rendered = entries.map((entry) => entry.component.render(viewport.width));
12
+ const sizes = allocateStackSizes(entries, rendered.map((lines) => lines.length), undefined, this.gap);
13
+ const lines = [];
14
+ for (let index = 0; index < entries.length; index++) {
15
+ if (index > 0) {
16
+ for (let gap = 0; gap < this.gap; gap++)
17
+ lines.push("");
18
+ }
19
+ const childLines = rendered[index].slice(0, sizes[index]);
20
+ lines.push(...childLines);
21
+ for (let padding = childLines.length; padding < sizes[index]; padding++)
22
+ lines.push("");
23
+ }
24
+ return lines;
25
+ }
26
+ }
27
+ //# sourceMappingURL=v-stack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v-stack.js","sourceRoot":"","sources":["../../src/components/v-stack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAsC,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEhH,MAAM,OAAO,MAAO,SAAQ,KAAK;IACb,UAAU,GAAG,QAAiB,CAAC;IAElD,YAAY,QAAQ,GAAiB,EAAE,EAAE,OAAO,GAAiB,EAAE,EAAE;QACpE,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAAA,CACzB;IAED,+LAA+L;IACtL,MAAM,CAAC,KAAa,EAAY;QACxC,MAAM,QAAQ,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAChF,MAAM,OAAO,GAAG,mBAAmB,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC5D,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QAChF,MAAM,KAAK,GAAG,kBAAkB,CAC/B,OAAO,EACP,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EACrC,SAAS,EACT,IAAI,CAAC,GAAG,CACR,CAAC;QACF,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YACrD,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;gBACf,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE;oBAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACzD,CAAC;YACD,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,CAAE,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;YAC3D,KAAK,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;YAC1B,KAAK,IAAI,OAAO,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,KAAK,CAAC,KAAK,CAAE,EAAE,OAAO,EAAE;gBAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1F,CAAC;QACD,OAAO,KAAK,CAAC;IAAA,CACb;CACD","sourcesContent":["import { allocateStackSizes, Stack, type StackChild, type StackOptions, visibleStackEntries } from \"./stack.ts\";\n\nexport class VStack extends Stack {\n\tprotected readonly layoutType = \"vstack\" as const;\n\n\tconstructor(children: StackChild[] = [], options: StackOptions = {}) {\n\t\tsuper(children, options);\n\t}\n\n\t// grip-ignore noExcessiveCollectionIterations: Each child contributes its rendered, gap, and padding rows exactly once, so the nested writes are linear in the final output lines. @class:3-32\n\toverride render(width: number): string[] {\n\t\tconst viewport = { width: Math.max(1, width), height: Number.MAX_SAFE_INTEGER };\n\t\tconst entries = visibleStackEntries(this.entries, viewport);\n\t\tconst rendered = entries.map((entry) => entry.component.render(viewport.width));\n\t\tconst sizes = allocateStackSizes(\n\t\t\tentries,\n\t\t\trendered.map((lines) => lines.length),\n\t\t\tundefined,\n\t\t\tthis.gap,\n\t\t);\n\t\tconst lines: string[] = [];\n\t\tfor (let index = 0; index < entries.length; index++) {\n\t\t\tif (index > 0) {\n\t\t\t\tfor (let gap = 0; gap < this.gap; gap++) lines.push(\"\");\n\t\t\t}\n\t\t\tconst childLines = rendered[index]!.slice(0, sizes[index]);\n\t\t\tlines.push(...childLines);\n\t\t\tfor (let padding = childLines.length; padding < sizes[index]!; padding++) lines.push(\"\");\n\t\t}\n\t\treturn lines;\n\t}\n}\n\nexport type { StackChild, StackEntry, StackEntryOptions, StackOptions } from \"./stack.ts\";\n"]}
@@ -0,0 +1,39 @@
1
+ import type { AutocompleteProvider } from "./autocomplete.ts";
2
+ import type { Component } from "./tui.ts";
3
+ /**
4
+ * Interface for custom editor components.
5
+ *
6
+ * This allows extensions to provide their own editor implementation
7
+ * (e.g., vim mode, emacs mode, custom keybindings) while maintaining
8
+ * compatibility with the core application.
9
+ */
10
+ export interface EditorComponent extends Component {
11
+ /** Get the current text content */
12
+ getText(): string;
13
+ /** Set the text content */
14
+ setText(text: string): void;
15
+ /** Handle raw terminal input (key presses, paste sequences, etc.) */
16
+ handleInput(data: string): void;
17
+ /** Called when user submits (e.g., Enter key) */
18
+ onSubmit?: (text: string) => void;
19
+ /** Called when text changes */
20
+ onChange?: (text: string) => void;
21
+ /** Add text to history for up/down navigation */
22
+ addToHistory?(text: string): void;
23
+ /** Insert text at current cursor position */
24
+ insertTextAtCursor?(text: string): void;
25
+ /**
26
+ * Get text with any markers expanded (e.g., paste markers).
27
+ * Falls back to getText() if not implemented.
28
+ */
29
+ getExpandedText?(): string;
30
+ /** Set the autocomplete provider */
31
+ setAutocompleteProvider?(provider: AutocompleteProvider): void;
32
+ /** Border color function */
33
+ borderColor?: (str: string) => string;
34
+ /** Set horizontal padding */
35
+ setPaddingX?(padding: number): void;
36
+ /** Set max visible items in autocomplete dropdown */
37
+ setAutocompleteMaxVisible?(maxVisible: number): void;
38
+ }
39
+ //# sourceMappingURL=editor-component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor-component.d.ts","sourceRoot":"","sources":["../src/editor-component.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,WAAW,eAAgB,SAAQ,SAAS;IAKjD,mCAAmC;IACnC,OAAO,IAAI,MAAM,CAAC;IAElB,2BAA2B;IAC3B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5B,qEAAqE;IACrE,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAMhC,iDAAiD;IACjD,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAElC,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAMlC,iDAAiD;IACjD,YAAY,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAMlC,6CAA6C;IAC7C,kBAAkB,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAExC;;;OAGG;IACH,eAAe,CAAC,IAAI,MAAM,CAAC;IAM3B,oCAAoC;IACpC,uBAAuB,CAAC,CAAC,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAM/D,4BAA4B;IAC5B,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IAEtC,6BAA6B;IAC7B,WAAW,CAAC,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpC,qDAAqD;IACrD,yBAAyB,CAAC,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CACrD","sourcesContent":["import type { AutocompleteProvider } from \"./autocomplete.ts\";\nimport type { Component } from \"./tui.ts\";\n\n/**\n * Interface for custom editor components.\n *\n * This allows extensions to provide their own editor implementation\n * (e.g., vim mode, emacs mode, custom keybindings) while maintaining\n * compatibility with the core application.\n */\nexport interface EditorComponent extends Component {\n\t// =========================================================================\n\t// Core text access (required)\n\t// =========================================================================\n\n\t/** Get the current text content */\n\tgetText(): string;\n\n\t/** Set the text content */\n\tsetText(text: string): void;\n\n\t/** Handle raw terminal input (key presses, paste sequences, etc.) */\n\thandleInput(data: string): void;\n\n\t// =========================================================================\n\t// Callbacks (required)\n\t// =========================================================================\n\n\t/** Called when user submits (e.g., Enter key) */\n\tonSubmit?: (text: string) => void;\n\n\t/** Called when text changes */\n\tonChange?: (text: string) => void;\n\n\t// =========================================================================\n\t// History support (optional)\n\t// =========================================================================\n\n\t/** Add text to history for up/down navigation */\n\taddToHistory?(text: string): void;\n\n\t// =========================================================================\n\t// Advanced text manipulation (optional)\n\t// =========================================================================\n\n\t/** Insert text at current cursor position */\n\tinsertTextAtCursor?(text: string): void;\n\n\t/**\n\t * Get text with any markers expanded (e.g., paste markers).\n\t * Falls back to getText() if not implemented.\n\t */\n\tgetExpandedText?(): string;\n\n\t// =========================================================================\n\t// Autocomplete support (optional)\n\t// =========================================================================\n\n\t/** Set the autocomplete provider */\n\tsetAutocompleteProvider?(provider: AutocompleteProvider): void;\n\n\t// =========================================================================\n\t// Appearance (optional)\n\t// =========================================================================\n\n\t/** Border color function */\n\tborderColor?: (str: string) => string;\n\n\t/** Set horizontal padding */\n\tsetPaddingX?(padding: number): void;\n\n\t/** Set max visible items in autocomplete dropdown */\n\tsetAutocompleteMaxVisible?(maxVisible: number): void;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=editor-component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor-component.js","sourceRoot":"","sources":["../src/editor-component.ts"],"names":[],"mappings":"","sourcesContent":["import type { AutocompleteProvider } from \"./autocomplete.ts\";\nimport type { Component } from \"./tui.ts\";\n\n/**\n * Interface for custom editor components.\n *\n * This allows extensions to provide their own editor implementation\n * (e.g., vim mode, emacs mode, custom keybindings) while maintaining\n * compatibility with the core application.\n */\nexport interface EditorComponent extends Component {\n\t// =========================================================================\n\t// Core text access (required)\n\t// =========================================================================\n\n\t/** Get the current text content */\n\tgetText(): string;\n\n\t/** Set the text content */\n\tsetText(text: string): void;\n\n\t/** Handle raw terminal input (key presses, paste sequences, etc.) */\n\thandleInput(data: string): void;\n\n\t// =========================================================================\n\t// Callbacks (required)\n\t// =========================================================================\n\n\t/** Called when user submits (e.g., Enter key) */\n\tonSubmit?: (text: string) => void;\n\n\t/** Called when text changes */\n\tonChange?: (text: string) => void;\n\n\t// =========================================================================\n\t// History support (optional)\n\t// =========================================================================\n\n\t/** Add text to history for up/down navigation */\n\taddToHistory?(text: string): void;\n\n\t// =========================================================================\n\t// Advanced text manipulation (optional)\n\t// =========================================================================\n\n\t/** Insert text at current cursor position */\n\tinsertTextAtCursor?(text: string): void;\n\n\t/**\n\t * Get text with any markers expanded (e.g., paste markers).\n\t * Falls back to getText() if not implemented.\n\t */\n\tgetExpandedText?(): string;\n\n\t// =========================================================================\n\t// Autocomplete support (optional)\n\t// =========================================================================\n\n\t/** Set the autocomplete provider */\n\tsetAutocompleteProvider?(provider: AutocompleteProvider): void;\n\n\t// =========================================================================\n\t// Appearance (optional)\n\t// =========================================================================\n\n\t/** Border color function */\n\tborderColor?: (str: string) => string;\n\n\t/** Set horizontal padding */\n\tsetPaddingX?(padding: number): void;\n\n\t/** Set max visible items in autocomplete dropdown */\n\tsetAutocompleteMaxVisible?(maxVisible: number): void;\n}\n"]}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Fuzzy matching utilities.
3
+ * Matches if all query characters appear in order (not necessarily consecutive).
4
+ * Lower score = better match.
5
+ */
6
+ export interface FuzzyMatch {
7
+ matches: boolean;
8
+ score: number;
9
+ }
10
+ export declare function fuzzyMatch(query: string, text: string): FuzzyMatch;
11
+ /**
12
+ * Filter and sort items by fuzzy match quality (best matches first).
13
+ * Supports space-separated tokens: all tokens must match.
14
+ */
15
+ export declare function fuzzyFilter<T>(items: T[], query: string, getText: (item: T) => string): T[];
16
+ //# sourceMappingURL=fuzzy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fuzzy.d.ts","sourceRoot":"","sources":["../src/fuzzy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,UAAU;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACd;AAqCD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CA2BlE;AAED;;;GAGG;AAEH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,CAAC,EAAE,CAsC3F","sourcesContent":["/**\n * Fuzzy matching utilities.\n * Matches if all query characters appear in order (not necessarily consecutive).\n * Lower score = better match.\n */\n\nexport interface FuzzyMatch {\n\tmatches: boolean;\n\tscore: number;\n}\n\ninterface FuzzyMatchState {\n\tqueryIndex: number;\n\tscore: number;\n\tlastMatchIndex: number;\n\tconsecutiveMatches: number;\n}\n\nfunction scoreFuzzyCharacterMatch(state: FuzzyMatchState, text: string, index: number): void {\n\tconst isWordBoundary = index === 0 || /[\\s\\-_./:]/.test(text[index - 1]!);\n\tif (state.lastMatchIndex === index - 1) {\n\t\tstate.consecutiveMatches++;\n\t\tstate.score -= state.consecutiveMatches * 5;\n\t} else {\n\t\tstate.consecutiveMatches = 0;\n\t\tif (state.lastMatchIndex >= 0) state.score += (index - state.lastMatchIndex - 1) * 2;\n\t}\n\tif (isWordBoundary) state.score -= 10;\n\tstate.score += index * 0.1;\n\tstate.lastMatchIndex = index;\n\tstate.queryIndex++;\n}\n\nfunction matchNormalizedQuery(normalizedQuery: string, text: string): FuzzyMatch {\n\tif (normalizedQuery.length === 0) return { matches: true, score: 0 };\n\tif (normalizedQuery.length > text.length) return { matches: false, score: 0 };\n\tconst state: FuzzyMatchState = { queryIndex: 0, score: 0, lastMatchIndex: -1, consecutiveMatches: 0 };\n\tfor (let index = 0; index < text.length && state.queryIndex < normalizedQuery.length; index++) {\n\t\tif (text[index] !== normalizedQuery[state.queryIndex]) continue;\n\t\tscoreFuzzyCharacterMatch(state, text, index);\n\t}\n\tif (state.queryIndex < normalizedQuery.length) return { matches: false, score: 0 };\n\tif (normalizedQuery === text) state.score -= 100;\n\treturn { matches: true, score: state.score };\n}\n\nexport function fuzzyMatch(query: string, text: string): FuzzyMatch {\n\tconst queryLower = query.toLowerCase();\n\tconst textLower = text.toLowerCase();\n\n\tconst primaryMatch = matchNormalizedQuery(queryLower, textLower);\n\tif (primaryMatch.matches) {\n\t\treturn primaryMatch;\n\t}\n\n\tconst alphaNumericMatch = queryLower.match(/^(?<letters>[a-z]+)(?<digits>[0-9]+)$/);\n\tconst numericAlphaMatch = queryLower.match(/^(?<digits>[0-9]+)(?<letters>[a-z]+)$/);\n\tconst swappedQuery = alphaNumericMatch\n\t\t? `${alphaNumericMatch.groups?.digits ?? \"\"}${alphaNumericMatch.groups?.letters ?? \"\"}`\n\t\t: numericAlphaMatch\n\t\t\t? `${numericAlphaMatch.groups?.letters ?? \"\"}${numericAlphaMatch.groups?.digits ?? \"\"}`\n\t\t\t: \"\";\n\n\tif (!swappedQuery) {\n\t\treturn primaryMatch;\n\t}\n\n\tconst swappedMatch = matchNormalizedQuery(swappedQuery, textLower);\n\tif (!swappedMatch.matches) {\n\t\treturn primaryMatch;\n\t}\n\n\treturn { matches: true, score: swappedMatch.score + 5 };\n}\n\n/**\n * Filter and sort items by fuzzy match quality (best matches first).\n * Supports space-separated tokens: all tokens must match.\n */\n// grip-ignore noExcessiveCollectionIterations: Multi-token filtering must independently score every query token against each candidate item, with short-circuiting on the first failed token.\nexport function fuzzyFilter<T>(items: T[], query: string, getText: (item: T) => string): T[] {\n\tif (!query.trim()) {\n\t\treturn items;\n\t}\n\n\tconst tokens = query\n\t\t.trim()\n\t\t.split(/\\s+/)\n\t\t.filter((t) => t.length > 0);\n\n\tif (tokens.length === 0) {\n\t\treturn items;\n\t}\n\n\tconst results: { item: T; totalScore: number }[] = [];\n\n\tfor (const item of items) {\n\t\tconst text = getText(item);\n\t\tlet totalScore = 0;\n\t\tlet allMatch = true;\n\n\t\tfor (const token of tokens) {\n\t\t\tconst match = fuzzyMatch(token, text);\n\t\t\tif (match.matches) {\n\t\t\t\ttotalScore += match.score;\n\t\t\t} else {\n\t\t\t\tallMatch = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (allMatch) {\n\t\t\tresults.push({ item, totalScore });\n\t\t}\n\t}\n\n\tresults.sort((a, b) => a.totalScore - b.totalScore);\n\treturn results.map((r) => r.item);\n}\n"]}
package/dist/fuzzy.js ADDED
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Fuzzy matching utilities.
3
+ * Matches if all query characters appear in order (not necessarily consecutive).
4
+ * Lower score = better match.
5
+ */
6
+ function scoreFuzzyCharacterMatch(state, text, index) {
7
+ const isWordBoundary = index === 0 || /[\s\-_./:]/.test(text[index - 1]);
8
+ if (state.lastMatchIndex === index - 1) {
9
+ state.consecutiveMatches++;
10
+ state.score -= state.consecutiveMatches * 5;
11
+ }
12
+ else {
13
+ state.consecutiveMatches = 0;
14
+ if (state.lastMatchIndex >= 0)
15
+ state.score += (index - state.lastMatchIndex - 1) * 2;
16
+ }
17
+ if (isWordBoundary)
18
+ state.score -= 10;
19
+ state.score += index * 0.1;
20
+ state.lastMatchIndex = index;
21
+ state.queryIndex++;
22
+ }
23
+ function matchNormalizedQuery(normalizedQuery, text) {
24
+ if (normalizedQuery.length === 0)
25
+ return { matches: true, score: 0 };
26
+ if (normalizedQuery.length > text.length)
27
+ return { matches: false, score: 0 };
28
+ const state = { queryIndex: 0, score: 0, lastMatchIndex: -1, consecutiveMatches: 0 };
29
+ for (let index = 0; index < text.length && state.queryIndex < normalizedQuery.length; index++) {
30
+ if (text[index] !== normalizedQuery[state.queryIndex])
31
+ continue;
32
+ scoreFuzzyCharacterMatch(state, text, index);
33
+ }
34
+ if (state.queryIndex < normalizedQuery.length)
35
+ return { matches: false, score: 0 };
36
+ if (normalizedQuery === text)
37
+ state.score -= 100;
38
+ return { matches: true, score: state.score };
39
+ }
40
+ export function fuzzyMatch(query, text) {
41
+ const queryLower = query.toLowerCase();
42
+ const textLower = text.toLowerCase();
43
+ const primaryMatch = matchNormalizedQuery(queryLower, textLower);
44
+ if (primaryMatch.matches) {
45
+ return primaryMatch;
46
+ }
47
+ const alphaNumericMatch = queryLower.match(/^(?<letters>[a-z]+)(?<digits>[0-9]+)$/);
48
+ const numericAlphaMatch = queryLower.match(/^(?<digits>[0-9]+)(?<letters>[a-z]+)$/);
49
+ const swappedQuery = alphaNumericMatch
50
+ ? `${alphaNumericMatch.groups?.digits ?? ""}${alphaNumericMatch.groups?.letters ?? ""}`
51
+ : numericAlphaMatch
52
+ ? `${numericAlphaMatch.groups?.letters ?? ""}${numericAlphaMatch.groups?.digits ?? ""}`
53
+ : "";
54
+ if (!swappedQuery) {
55
+ return primaryMatch;
56
+ }
57
+ const swappedMatch = matchNormalizedQuery(swappedQuery, textLower);
58
+ if (!swappedMatch.matches) {
59
+ return primaryMatch;
60
+ }
61
+ return { matches: true, score: swappedMatch.score + 5 };
62
+ }
63
+ /**
64
+ * Filter and sort items by fuzzy match quality (best matches first).
65
+ * Supports space-separated tokens: all tokens must match.
66
+ */
67
+ // grip-ignore noExcessiveCollectionIterations: Multi-token filtering must independently score every query token against each candidate item, with short-circuiting on the first failed token.
68
+ export function fuzzyFilter(items, query, getText) {
69
+ if (!query.trim()) {
70
+ return items;
71
+ }
72
+ const tokens = query
73
+ .trim()
74
+ .split(/\s+/)
75
+ .filter((t) => t.length > 0);
76
+ if (tokens.length === 0) {
77
+ return items;
78
+ }
79
+ const results = [];
80
+ for (const item of items) {
81
+ const text = getText(item);
82
+ let totalScore = 0;
83
+ let allMatch = true;
84
+ for (const token of tokens) {
85
+ const match = fuzzyMatch(token, text);
86
+ if (match.matches) {
87
+ totalScore += match.score;
88
+ }
89
+ else {
90
+ allMatch = false;
91
+ break;
92
+ }
93
+ }
94
+ if (allMatch) {
95
+ results.push({ item, totalScore });
96
+ }
97
+ }
98
+ results.sort((a, b) => a.totalScore - b.totalScore);
99
+ return results.map((r) => r.item);
100
+ }
101
+ //# sourceMappingURL=fuzzy.js.map