@bubblebrain-ai/bubble 0.0.12 → 0.0.13

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 (128) hide show
  1. package/dist/agent/input-controller.d.ts +11 -0
  2. package/dist/agent/input-controller.js +30 -0
  3. package/dist/agent.d.ts +6 -4
  4. package/dist/agent.js +38 -0
  5. package/dist/main.js +58 -9
  6. package/dist/slash-commands/commands.js +27 -0
  7. package/dist/slash-commands/types.d.ts +10 -0
  8. package/dist/tui/clipboard.d.ts +1 -0
  9. package/dist/tui/clipboard.js +53 -0
  10. package/dist/tui/detect-theme.d.ts +2 -0
  11. package/dist/tui/detect-theme.js +87 -0
  12. package/dist/tui/display-history.d.ts +62 -0
  13. package/dist/tui/display-history.js +305 -0
  14. package/dist/tui/edit-diff.d.ts +11 -0
  15. package/dist/tui/edit-diff.js +52 -0
  16. package/dist/tui/escape-confirmation.d.ts +15 -0
  17. package/dist/tui/escape-confirmation.js +30 -0
  18. package/dist/tui/file-mentions.d.ts +29 -0
  19. package/dist/tui/file-mentions.js +174 -0
  20. package/dist/tui/global-key-router.d.ts +3 -0
  21. package/dist/tui/global-key-router.js +87 -0
  22. package/dist/tui/image-paste.d.ts +95 -0
  23. package/dist/tui/image-paste.js +505 -0
  24. package/dist/tui/input-history.d.ts +16 -0
  25. package/dist/tui/input-history.js +79 -0
  26. package/dist/tui/markdown-inline.d.ts +22 -0
  27. package/dist/tui/markdown-inline.js +68 -0
  28. package/dist/tui/markdown-theme-rules.d.ts +23 -0
  29. package/dist/tui/markdown-theme-rules.js +164 -0
  30. package/dist/tui/markdown-theme.d.ts +5 -0
  31. package/dist/tui/markdown-theme.js +27 -0
  32. package/dist/tui/opencode-spinner.d.ts +22 -0
  33. package/dist/tui/opencode-spinner.js +216 -0
  34. package/dist/tui/prompt-keybindings.d.ts +42 -0
  35. package/dist/tui/prompt-keybindings.js +35 -0
  36. package/dist/tui/recent-activity.d.ts +8 -0
  37. package/dist/tui/recent-activity.js +71 -0
  38. package/dist/tui/render-signature.d.ts +1 -0
  39. package/dist/tui/render-signature.js +7 -0
  40. package/dist/tui/run.d.ts +45 -0
  41. package/dist/tui/run.js +8816 -0
  42. package/dist/tui/session-display.d.ts +6 -0
  43. package/dist/tui/session-display.js +12 -0
  44. package/dist/tui/sidebar-mcp.d.ts +31 -0
  45. package/dist/tui/sidebar-mcp.js +62 -0
  46. package/dist/tui/sidebar-state.d.ts +12 -0
  47. package/dist/tui/sidebar-state.js +69 -0
  48. package/dist/tui/streaming-tool-args.d.ts +15 -0
  49. package/dist/tui/streaming-tool-args.js +30 -0
  50. package/dist/tui/tool-renderers/fallback.d.ts +2 -0
  51. package/dist/tui/tool-renderers/fallback.js +75 -0
  52. package/dist/tui/tool-renderers/registry.d.ts +3 -0
  53. package/dist/tui/tool-renderers/registry.js +11 -0
  54. package/dist/tui/tool-renderers/subagent.d.ts +2 -0
  55. package/dist/tui/tool-renderers/subagent.js +135 -0
  56. package/dist/tui/tool-renderers/types.d.ts +36 -0
  57. package/dist/tui/tool-renderers/types.js +1 -0
  58. package/dist/tui/tool-renderers/write-preview.d.ts +12 -0
  59. package/dist/tui/tool-renderers/write-preview.js +30 -0
  60. package/dist/tui/tool-renderers/write.d.ts +6 -0
  61. package/dist/tui/tool-renderers/write.js +88 -0
  62. package/dist/tui/trace-groups.d.ts +27 -0
  63. package/dist/tui/trace-groups.js +412 -0
  64. package/dist/tui/wordmark.d.ts +15 -0
  65. package/dist/tui/wordmark.js +179 -0
  66. package/dist/tui-ink/app.js +44 -5
  67. package/dist/tui-ink/message-list.js +9 -1
  68. package/dist/tui-ink/theme.d.ts +3 -9
  69. package/dist/tui-ink/theme.js +39 -45
  70. package/dist/tui-ink/welcome.js +22 -78
  71. package/dist/tui-opentui/app.d.ts +54 -0
  72. package/dist/tui-opentui/app.js +1363 -0
  73. package/dist/tui-opentui/approval/approval-dialog.d.ts +15 -0
  74. package/dist/tui-opentui/approval/approval-dialog.js +139 -0
  75. package/dist/tui-opentui/approval/diff-view.d.ts +9 -0
  76. package/dist/tui-opentui/approval/diff-view.js +43 -0
  77. package/dist/tui-opentui/approval/select.d.ts +37 -0
  78. package/dist/tui-opentui/approval/select.js +91 -0
  79. package/dist/tui-opentui/detect-theme.d.ts +2 -0
  80. package/dist/tui-opentui/detect-theme.js +87 -0
  81. package/dist/tui-opentui/display-history.d.ts +55 -0
  82. package/dist/tui-opentui/display-history.js +129 -0
  83. package/dist/tui-opentui/edit-diff.d.ts +11 -0
  84. package/dist/tui-opentui/edit-diff.js +52 -0
  85. package/dist/tui-opentui/feedback-dialog.d.ts +21 -0
  86. package/dist/tui-opentui/feedback-dialog.js +164 -0
  87. package/dist/tui-opentui/feishu-setup-picker.d.ts +7 -0
  88. package/dist/tui-opentui/feishu-setup-picker.js +272 -0
  89. package/dist/tui-opentui/file-mentions.d.ts +29 -0
  90. package/dist/tui-opentui/file-mentions.js +174 -0
  91. package/dist/tui-opentui/footer.d.ts +26 -0
  92. package/dist/tui-opentui/footer.js +40 -0
  93. package/dist/tui-opentui/image-paste.d.ts +54 -0
  94. package/dist/tui-opentui/image-paste.js +288 -0
  95. package/dist/tui-opentui/input-box.d.ts +34 -0
  96. package/dist/tui-opentui/input-box.js +471 -0
  97. package/dist/tui-opentui/input-history.d.ts +16 -0
  98. package/dist/tui-opentui/input-history.js +79 -0
  99. package/dist/tui-opentui/markdown.d.ts +66 -0
  100. package/dist/tui-opentui/markdown.js +127 -0
  101. package/dist/tui-opentui/message-list.d.ts +31 -0
  102. package/dist/tui-opentui/message-list.js +125 -0
  103. package/dist/tui-opentui/model-picker.d.ts +63 -0
  104. package/dist/tui-opentui/model-picker.js +450 -0
  105. package/dist/tui-opentui/plan-confirm.d.ts +9 -0
  106. package/dist/tui-opentui/plan-confirm.js +124 -0
  107. package/dist/tui-opentui/question-dialog.d.ts +10 -0
  108. package/dist/tui-opentui/question-dialog.js +110 -0
  109. package/dist/tui-opentui/recent-activity.d.ts +8 -0
  110. package/dist/tui-opentui/recent-activity.js +71 -0
  111. package/dist/tui-opentui/run-session-picker.d.ts +10 -0
  112. package/dist/tui-opentui/run-session-picker.js +28 -0
  113. package/dist/tui-opentui/run.d.ts +38 -0
  114. package/dist/tui-opentui/run.js +48 -0
  115. package/dist/tui-opentui/session-picker.d.ts +12 -0
  116. package/dist/tui-opentui/session-picker.js +120 -0
  117. package/dist/tui-opentui/theme.d.ts +89 -0
  118. package/dist/tui-opentui/theme.js +157 -0
  119. package/dist/tui-opentui/todos.d.ts +9 -0
  120. package/dist/tui-opentui/todos.js +45 -0
  121. package/dist/tui-opentui/trace-groups.d.ts +27 -0
  122. package/dist/tui-opentui/trace-groups.js +412 -0
  123. package/dist/tui-opentui/use-terminal-size.d.ts +4 -0
  124. package/dist/tui-opentui/use-terminal-size.js +5 -0
  125. package/dist/tui-opentui/welcome.d.ts +25 -0
  126. package/dist/tui-opentui/welcome.js +77 -0
  127. package/dist/types.d.ts +24 -0
  128. package/package.json +5 -1
@@ -0,0 +1,16 @@
1
+ export declare function defaultHistoryFilePath(): string;
2
+ export declare function loadHistorySync(filePath?: string): string[];
3
+ export declare function appendHistoryEntry(entry: string, filePath?: string): void;
4
+ export interface HistoryNavState {
5
+ history: string[];
6
+ index: number | null;
7
+ draft: string;
8
+ }
9
+ export interface HistoryNavResult {
10
+ text: string;
11
+ index: number | null;
12
+ draft: string;
13
+ changed: boolean;
14
+ }
15
+ export declare function stepHistory(state: HistoryNavState, direction: "up" | "down", currentText: string): HistoryNavResult;
16
+ export declare function pushHistoryEntry(history: string[], entry: string): string[];
@@ -0,0 +1,79 @@
1
+ import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { getBubbleHome } from "../bubble-home.js";
4
+ const MAX_HISTORY_ENTRIES = 1000;
5
+ export function defaultHistoryFilePath() {
6
+ return join(getBubbleHome(), "input-history.jsonl");
7
+ }
8
+ // JSONL on disk: each line is a JSON-encoded string. JSON encoding handles
9
+ // embedded newlines and quotes so multi-line composer entries round-trip safely.
10
+ export function loadHistorySync(filePath = defaultHistoryFilePath()) {
11
+ try {
12
+ if (!existsSync(filePath))
13
+ return [];
14
+ const raw = readFileSync(filePath, "utf8");
15
+ const out = [];
16
+ for (const line of raw.split("\n")) {
17
+ if (!line)
18
+ continue;
19
+ try {
20
+ const parsed = JSON.parse(line);
21
+ if (typeof parsed === "string" && parsed.length > 0)
22
+ out.push(parsed);
23
+ }
24
+ catch {
25
+ // Malformed line - skip rather than fail the whole load.
26
+ }
27
+ }
28
+ return out.length > MAX_HISTORY_ENTRIES ? out.slice(-MAX_HISTORY_ENTRIES) : out;
29
+ }
30
+ catch {
31
+ return [];
32
+ }
33
+ }
34
+ export function appendHistoryEntry(entry, filePath = defaultHistoryFilePath()) {
35
+ if (!entry || entry.trim().length === 0)
36
+ return;
37
+ try {
38
+ mkdirSync(dirname(filePath), { recursive: true });
39
+ appendFileSync(filePath, JSON.stringify(entry) + "\n", "utf8");
40
+ }
41
+ catch {
42
+ // Persistence is best-effort; never crash the composer over disk IO.
43
+ }
44
+ }
45
+ // Pure transition for up/down navigation. `index === null` means the user is
46
+ // editing a fresh draft; otherwise it points at history[index]. When stepping
47
+ // from the draft into history we snapshot the current text so down past the
48
+ // newest entry can restore it.
49
+ export function stepHistory(state, direction, currentText) {
50
+ const { history, index, draft } = state;
51
+ const noChange = { text: currentText, index, draft, changed: false };
52
+ if (direction === "up") {
53
+ if (history.length === 0)
54
+ return noChange;
55
+ if (index === null) {
56
+ const newIdx = history.length - 1;
57
+ return { text: history[newIdx], index: newIdx, draft: currentText, changed: true };
58
+ }
59
+ if (index > 0) {
60
+ return { text: history[index - 1], index: index - 1, draft, changed: true };
61
+ }
62
+ return noChange;
63
+ }
64
+ if (index === null)
65
+ return noChange;
66
+ if (index < history.length - 1) {
67
+ return { text: history[index + 1], index: index + 1, draft, changed: true };
68
+ }
69
+ return { text: draft, index: null, draft: "", changed: true };
70
+ }
71
+ // Push to in-memory history with last-entry dedupe so repeated identical
72
+ // submissions don't spam the stack.
73
+ export function pushHistoryEntry(history, entry) {
74
+ if (!entry || entry.trim().length === 0)
75
+ return history;
76
+ if (history.length > 0 && history[history.length - 1] === entry)
77
+ return history;
78
+ return [...history, entry];
79
+ }
@@ -0,0 +1,22 @@
1
+ export interface MarkdownInlineSegment {
2
+ text: string;
3
+ color?: "text" | "textMuted" | "success" | "warning" | "secondary";
4
+ bold?: boolean;
5
+ italic?: boolean;
6
+ dim?: boolean;
7
+ }
8
+ type InlineToken = {
9
+ type?: string;
10
+ text?: string;
11
+ raw?: string;
12
+ href?: string;
13
+ tokens?: InlineToken[];
14
+ };
15
+ interface InlineStyle {
16
+ bold?: boolean;
17
+ italic?: boolean;
18
+ dim?: boolean;
19
+ color?: MarkdownInlineSegment["color"];
20
+ }
21
+ export declare function markdownInlineSegments(tokens: InlineToken[] | undefined, fallback?: string, style?: InlineStyle): MarkdownInlineSegment[];
22
+ export {};
@@ -0,0 +1,68 @@
1
+ export function markdownInlineSegments(tokens, fallback = "", style = {}) {
2
+ const segments = [];
3
+ for (const token of tokens ?? []) {
4
+ appendInlineToken(segments, token, style);
5
+ }
6
+ if (segments.length === 0 && fallback) {
7
+ appendStyled(segments, fallback, style);
8
+ }
9
+ return segments;
10
+ }
11
+ function appendInlineToken(segments, token, style) {
12
+ switch (token.type) {
13
+ case "strong":
14
+ appendInlineTokens(segments, token.tokens, { ...style, bold: true });
15
+ return;
16
+ case "em":
17
+ appendInlineTokens(segments, token.tokens, { ...style, italic: true, color: style.color ?? "warning" });
18
+ return;
19
+ case "del":
20
+ appendInlineTokens(segments, token.tokens, { ...style, dim: true, color: style.color ?? "textMuted" });
21
+ return;
22
+ case "codespan":
23
+ appendStyled(segments, token.text ?? "", { ...style, color: "success" });
24
+ return;
25
+ case "link":
26
+ appendInlineTokens(segments, token.tokens, { ...style, color: style.color ?? "secondary" });
27
+ return;
28
+ case "br":
29
+ appendStyled(segments, "\n", style);
30
+ return;
31
+ case "text":
32
+ case "paragraph":
33
+ case "list_item":
34
+ case "heading":
35
+ if (token.tokens?.length) {
36
+ appendInlineTokens(segments, token.tokens, style);
37
+ }
38
+ else {
39
+ appendStyled(segments, token.text ?? token.raw ?? "", style);
40
+ }
41
+ return;
42
+ case "space":
43
+ return;
44
+ default:
45
+ if (token.tokens?.length) {
46
+ appendInlineTokens(segments, token.tokens, style);
47
+ }
48
+ else {
49
+ appendStyled(segments, token.text ?? token.raw ?? "", style);
50
+ }
51
+ }
52
+ }
53
+ function appendInlineTokens(segments, tokens, style) {
54
+ for (const child of tokens ?? []) {
55
+ appendInlineToken(segments, child, style);
56
+ }
57
+ }
58
+ function appendStyled(segments, text, style) {
59
+ if (!text)
60
+ return;
61
+ segments.push({
62
+ text,
63
+ color: style.color ?? "text",
64
+ bold: style.bold,
65
+ italic: style.italic,
66
+ dim: style.dim,
67
+ });
68
+ }
@@ -0,0 +1,23 @@
1
+ export interface MarkdownThemePalette {
2
+ text: string;
3
+ textMuted: string;
4
+ background: string;
5
+ secondary: string;
6
+ info: string;
7
+ success: string;
8
+ warning: string;
9
+ accent: string;
10
+ error: string;
11
+ }
12
+ export interface SyntaxThemeRule {
13
+ scope: string[];
14
+ style: {
15
+ foreground?: string;
16
+ background?: string;
17
+ bold?: boolean;
18
+ italic?: boolean;
19
+ underline?: boolean;
20
+ dim?: boolean;
21
+ };
22
+ }
23
+ export declare function buildMarkdownThemeRules(theme: MarkdownThemePalette): SyntaxThemeRule[];
@@ -0,0 +1,164 @@
1
+ export function buildMarkdownThemeRules(theme) {
2
+ return [
3
+ {
4
+ scope: ["default"],
5
+ style: {
6
+ foreground: theme.text,
7
+ },
8
+ },
9
+ {
10
+ scope: ["comment", "comment.documentation"],
11
+ style: {
12
+ foreground: theme.textMuted,
13
+ italic: true,
14
+ },
15
+ },
16
+ {
17
+ scope: ["string", "symbol", "character", "character.special", "string.escape"],
18
+ style: {
19
+ foreground: theme.success,
20
+ },
21
+ },
22
+ {
23
+ scope: ["number", "boolean", "constant", "float"],
24
+ style: {
25
+ foreground: theme.warning,
26
+ },
27
+ },
28
+ {
29
+ scope: [
30
+ "keyword",
31
+ "keyword.import",
32
+ "keyword.return",
33
+ "keyword.conditional",
34
+ "keyword.repeat",
35
+ "keyword.coroutine",
36
+ "keyword.directive",
37
+ "keyword.modifier",
38
+ "keyword.exception",
39
+ "string.regexp",
40
+ ],
41
+ style: {
42
+ foreground: theme.accent,
43
+ italic: true,
44
+ },
45
+ },
46
+ {
47
+ scope: ["keyword.type", "type", "class", "module"],
48
+ style: {
49
+ foreground: theme.info,
50
+ bold: true,
51
+ },
52
+ },
53
+ {
54
+ scope: ["function", "function.call", "function.method", "function.method.call", "constructor"],
55
+ style: {
56
+ foreground: theme.secondary,
57
+ },
58
+ },
59
+ {
60
+ scope: ["variable", "variable.parameter", "variable.member", "property", "parameter"],
61
+ style: {
62
+ foreground: theme.text,
63
+ },
64
+ },
65
+ {
66
+ scope: ["operator", "keyword.operator", "punctuation.delimiter", "punctuation.special"],
67
+ style: {
68
+ foreground: theme.info,
69
+ },
70
+ },
71
+ {
72
+ scope: ["punctuation", "punctuation.bracket"],
73
+ style: {
74
+ foreground: theme.text,
75
+ },
76
+ },
77
+ {
78
+ scope: ["variable.builtin", "type.builtin", "function.builtin", "module.builtin", "constant.builtin", "variable.super"],
79
+ style: {
80
+ foreground: theme.error,
81
+ },
82
+ },
83
+ {
84
+ scope: ["markup.heading", "markup.heading.1", "markup.heading.2", "markup.heading.3", "markup.heading.4", "markup.heading.5", "markup.heading.6"],
85
+ style: {
86
+ foreground: theme.text,
87
+ bold: true,
88
+ },
89
+ },
90
+ {
91
+ scope: ["markup.bold", "markup.strong"],
92
+ style: {
93
+ foreground: theme.text,
94
+ bold: true,
95
+ },
96
+ },
97
+ {
98
+ scope: ["markup.italic"],
99
+ style: {
100
+ foreground: theme.warning,
101
+ italic: true,
102
+ },
103
+ },
104
+ {
105
+ scope: ["markup.strikethrough"],
106
+ style: {
107
+ foreground: theme.textMuted,
108
+ dim: true,
109
+ },
110
+ },
111
+ {
112
+ scope: ["markup.list"],
113
+ style: {
114
+ foreground: theme.secondary,
115
+ },
116
+ },
117
+ {
118
+ scope: ["markup.quote"],
119
+ style: {
120
+ foreground: theme.warning,
121
+ italic: true,
122
+ },
123
+ },
124
+ {
125
+ scope: ["markup.raw", "markup.raw.block"],
126
+ style: {
127
+ foreground: theme.success,
128
+ },
129
+ },
130
+ {
131
+ scope: ["markup.raw.inline"],
132
+ style: {
133
+ foreground: theme.success,
134
+ background: theme.background,
135
+ },
136
+ },
137
+ {
138
+ scope: ["markup.link", "markup.link.url", "string.special.url"],
139
+ style: {
140
+ foreground: theme.secondary,
141
+ underline: true,
142
+ },
143
+ },
144
+ {
145
+ scope: ["markup.link.label", "label"],
146
+ style: {
147
+ foreground: theme.info,
148
+ underline: true,
149
+ },
150
+ },
151
+ {
152
+ scope: ["spell", "nospell"],
153
+ style: {
154
+ foreground: theme.text,
155
+ },
156
+ },
157
+ {
158
+ scope: ["conceal"],
159
+ style: {
160
+ foreground: theme.textMuted,
161
+ },
162
+ },
163
+ ];
164
+ }
@@ -0,0 +1,5 @@
1
+ import { SyntaxStyle } from "@opentui/core";
2
+ import { type MarkdownThemePalette } from "./markdown-theme-rules.js";
3
+ export type { MarkdownThemePalette } from "./markdown-theme-rules.js";
4
+ export declare function createMarkdownSyntaxStyle(theme: MarkdownThemePalette): SyntaxStyle;
5
+ export declare function createSubtleMarkdownSyntaxStyle(theme: MarkdownThemePalette, opacity?: number): SyntaxStyle;
@@ -0,0 +1,27 @@
1
+ import { SyntaxStyle } from "@opentui/core";
2
+ import { buildMarkdownThemeRules } from "./markdown-theme-rules.js";
3
+ export function createMarkdownSyntaxStyle(theme) {
4
+ return SyntaxStyle.fromTheme(buildMarkdownThemeRules(theme));
5
+ }
6
+ export function createSubtleMarkdownSyntaxStyle(theme, opacity = 0.6) {
7
+ const alpha = Math.max(0, Math.min(1, opacity));
8
+ return SyntaxStyle.fromTheme(buildMarkdownThemeRules(theme).map((rule) => ({
9
+ ...rule,
10
+ style: {
11
+ ...rule.style,
12
+ foreground: rule.style.foreground
13
+ ? applyAlpha(rule.style.foreground, alpha)
14
+ : rule.style.foreground,
15
+ },
16
+ })));
17
+ }
18
+ function applyAlpha(color, opacity) {
19
+ if (!color.startsWith("#"))
20
+ return color;
21
+ const hex = color.slice(1);
22
+ if (hex.length !== 6 && hex.length !== 8)
23
+ return color;
24
+ const rgb = hex.slice(0, 6);
25
+ const alpha = Math.round(opacity * 255).toString(16).padStart(2, "0");
26
+ return `#${rgb}${alpha}`;
27
+ }
@@ -0,0 +1,22 @@
1
+ import type { ColorInput } from "@opentui/core";
2
+ import { RGBA } from "@opentui/core";
3
+ type ColorGenerator = (frameIndex: number, charIndex: number, totalFrames: number, totalChars: number) => ColorInput;
4
+ export declare function deriveTrailColors(brightColor: ColorInput, steps?: number): RGBA[];
5
+ export declare function deriveInactiveColor(brightColor: ColorInput, factor?: number): RGBA;
6
+ export type KnightRiderStyle = "blocks" | "diamonds";
7
+ export interface KnightRiderOptions {
8
+ width?: number;
9
+ style?: KnightRiderStyle;
10
+ holdStart?: number;
11
+ holdEnd?: number;
12
+ colors?: ColorInput[];
13
+ color?: ColorInput;
14
+ trailSteps?: number;
15
+ defaultColor?: ColorInput;
16
+ inactiveFactor?: number;
17
+ enableFading?: boolean;
18
+ minAlpha?: number;
19
+ }
20
+ export declare function createFrames(options?: KnightRiderOptions): string[];
21
+ export declare function createColors(options?: KnightRiderOptions): ColorGenerator;
22
+ export {};
@@ -0,0 +1,216 @@
1
+ import { RGBA } from "@opentui/core";
2
+ function getScannerState(frameIndex, totalChars, options) {
3
+ const { direction = "forward", holdFrames = {} } = options;
4
+ if (direction === "bidirectional") {
5
+ const forwardFrames = totalChars;
6
+ const holdEndFrames = holdFrames.end ?? 0;
7
+ const backwardFrames = totalChars - 1;
8
+ if (frameIndex < forwardFrames) {
9
+ return {
10
+ activePosition: frameIndex,
11
+ isHolding: false,
12
+ holdProgress: 0,
13
+ holdTotal: 0,
14
+ movementProgress: frameIndex,
15
+ movementTotal: forwardFrames,
16
+ isMovingForward: true,
17
+ };
18
+ }
19
+ if (frameIndex < forwardFrames + holdEndFrames) {
20
+ return {
21
+ activePosition: totalChars - 1,
22
+ isHolding: true,
23
+ holdProgress: frameIndex - forwardFrames,
24
+ holdTotal: holdEndFrames,
25
+ movementProgress: 0,
26
+ movementTotal: 0,
27
+ isMovingForward: true,
28
+ };
29
+ }
30
+ if (frameIndex < forwardFrames + holdEndFrames + backwardFrames) {
31
+ const backwardIndex = frameIndex - forwardFrames - holdEndFrames;
32
+ return {
33
+ activePosition: totalChars - 2 - backwardIndex,
34
+ isHolding: false,
35
+ holdProgress: 0,
36
+ holdTotal: 0,
37
+ movementProgress: backwardIndex,
38
+ movementTotal: backwardFrames,
39
+ isMovingForward: false,
40
+ };
41
+ }
42
+ return {
43
+ activePosition: 0,
44
+ isHolding: true,
45
+ holdProgress: frameIndex - forwardFrames - holdEndFrames - backwardFrames,
46
+ holdTotal: holdFrames.start ?? 0,
47
+ movementProgress: 0,
48
+ movementTotal: 0,
49
+ isMovingForward: false,
50
+ };
51
+ }
52
+ if (direction === "backward") {
53
+ return {
54
+ activePosition: totalChars - 1 - (frameIndex % totalChars),
55
+ isHolding: false,
56
+ holdProgress: 0,
57
+ holdTotal: 0,
58
+ movementProgress: frameIndex % totalChars,
59
+ movementTotal: totalChars,
60
+ isMovingForward: false,
61
+ };
62
+ }
63
+ return {
64
+ activePosition: frameIndex % totalChars,
65
+ isHolding: false,
66
+ holdProgress: 0,
67
+ holdTotal: 0,
68
+ movementProgress: frameIndex % totalChars,
69
+ movementTotal: totalChars,
70
+ isMovingForward: true,
71
+ };
72
+ }
73
+ function calculateColorIndex(frameIndex, charIndex, totalChars, options, state) {
74
+ const { trailLength } = options;
75
+ const { activePosition, isHolding, holdProgress, isMovingForward } = state ?? getScannerState(frameIndex, totalChars, options);
76
+ const directionalDistance = isMovingForward
77
+ ? activePosition - charIndex
78
+ : charIndex - activePosition;
79
+ if (isHolding)
80
+ return directionalDistance + holdProgress;
81
+ if (directionalDistance > 0 && directionalDistance < trailLength)
82
+ return directionalDistance;
83
+ if (directionalDistance === 0)
84
+ return 0;
85
+ return -1;
86
+ }
87
+ function createKnightRiderTrail(options) {
88
+ const { colors, defaultColor, enableFading = true, minAlpha = 0 } = options;
89
+ const defaultRgba = defaultColor instanceof RGBA ? defaultColor : RGBA.fromHex(defaultColor || "#000000");
90
+ const baseInactiveAlpha = defaultRgba.a;
91
+ let cachedFrameIndex = -1;
92
+ let cachedState = null;
93
+ return (frameIndex, charIndex, _totalFrames, totalChars) => {
94
+ if (frameIndex !== cachedFrameIndex) {
95
+ cachedFrameIndex = frameIndex;
96
+ cachedState = getScannerState(frameIndex, totalChars, options);
97
+ }
98
+ const state = cachedState;
99
+ const index = calculateColorIndex(frameIndex, charIndex, totalChars, options, state);
100
+ const { isHolding, holdProgress, holdTotal, movementProgress, movementTotal } = state;
101
+ let fadeFactor = 1.0;
102
+ if (enableFading) {
103
+ if (isHolding && holdTotal > 0) {
104
+ const progress = Math.min(holdProgress / holdTotal, 1);
105
+ fadeFactor = Math.max(minAlpha, 1 - progress * (1 - minAlpha));
106
+ }
107
+ else if (!isHolding && movementTotal > 0) {
108
+ const progress = Math.min(movementProgress / Math.max(1, movementTotal - 1), 1);
109
+ fadeFactor = minAlpha + progress * (1 - minAlpha);
110
+ }
111
+ }
112
+ defaultRgba.a = baseInactiveAlpha * fadeFactor;
113
+ if (index === -1)
114
+ return defaultRgba;
115
+ return colors[index] ?? defaultRgba;
116
+ };
117
+ }
118
+ export function deriveTrailColors(brightColor, steps = 6) {
119
+ const baseRgba = brightColor instanceof RGBA ? brightColor : RGBA.fromHex(brightColor);
120
+ const colors = [];
121
+ for (let i = 0; i < steps; i++) {
122
+ let alpha;
123
+ let brightnessFactor;
124
+ if (i === 0) {
125
+ alpha = 1.0;
126
+ brightnessFactor = 1.0;
127
+ }
128
+ else if (i === 1) {
129
+ alpha = 0.9;
130
+ brightnessFactor = 1.15;
131
+ }
132
+ else {
133
+ alpha = Math.pow(0.65, i - 1);
134
+ brightnessFactor = 1.0;
135
+ }
136
+ const r = Math.min(1.0, baseRgba.r * brightnessFactor);
137
+ const g = Math.min(1.0, baseRgba.g * brightnessFactor);
138
+ const b = Math.min(1.0, baseRgba.b * brightnessFactor);
139
+ colors.push(RGBA.fromValues(r, g, b, alpha));
140
+ }
141
+ return colors;
142
+ }
143
+ export function deriveInactiveColor(brightColor, factor = 0.2) {
144
+ const baseRgba = brightColor instanceof RGBA ? brightColor : RGBA.fromHex(brightColor);
145
+ return RGBA.fromValues(baseRgba.r, baseRgba.g, baseRgba.b, factor);
146
+ }
147
+ export function createFrames(options = {}) {
148
+ const width = options.width ?? 8;
149
+ const style = options.style ?? "diamonds";
150
+ const holdStart = options.holdStart ?? 30;
151
+ const holdEnd = options.holdEnd ?? 9;
152
+ const colors = options.colors ??
153
+ (options.color
154
+ ? deriveTrailColors(options.color, options.trailSteps)
155
+ : [
156
+ RGBA.fromHex("#ff0000"),
157
+ RGBA.fromHex("#ff5555"),
158
+ RGBA.fromHex("#dd0000"),
159
+ RGBA.fromHex("#aa0000"),
160
+ RGBA.fromHex("#770000"),
161
+ RGBA.fromHex("#440000"),
162
+ ]);
163
+ const defaultColor = options.defaultColor ??
164
+ (options.color ? deriveInactiveColor(options.color, options.inactiveFactor) : RGBA.fromHex("#330000"));
165
+ const trailOptions = {
166
+ colors,
167
+ trailLength: colors.length,
168
+ defaultColor,
169
+ direction: "bidirectional",
170
+ holdFrames: { start: holdStart, end: holdEnd },
171
+ enableFading: options.enableFading,
172
+ minAlpha: options.minAlpha,
173
+ };
174
+ const totalFrames = width + holdEnd + (width - 1) + holdStart;
175
+ return Array.from({ length: totalFrames }, (_, frameIndex) => {
176
+ return Array.from({ length: width }, (_, charIndex) => {
177
+ const index = calculateColorIndex(frameIndex, charIndex, width, trailOptions);
178
+ if (style === "diamonds") {
179
+ const shapes = ["⬥", "◆", "⬩", "⬪"];
180
+ if (index >= 0 && index < trailOptions.colors.length) {
181
+ return shapes[Math.min(index, shapes.length - 1)];
182
+ }
183
+ return "·";
184
+ }
185
+ const isActive = index >= 0 && index < trailOptions.colors.length;
186
+ return isActive ? "■" : "⬝";
187
+ }).join("");
188
+ });
189
+ }
190
+ export function createColors(options = {}) {
191
+ const holdStart = options.holdStart ?? 30;
192
+ const holdEnd = options.holdEnd ?? 9;
193
+ const colors = options.colors ??
194
+ (options.color
195
+ ? deriveTrailColors(options.color, options.trailSteps)
196
+ : [
197
+ RGBA.fromHex("#ff0000"),
198
+ RGBA.fromHex("#ff5555"),
199
+ RGBA.fromHex("#dd0000"),
200
+ RGBA.fromHex("#aa0000"),
201
+ RGBA.fromHex("#770000"),
202
+ RGBA.fromHex("#440000"),
203
+ ]);
204
+ const defaultColor = options.defaultColor ??
205
+ (options.color ? deriveInactiveColor(options.color, options.inactiveFactor) : RGBA.fromHex("#330000"));
206
+ const trailOptions = {
207
+ colors,
208
+ trailLength: colors.length,
209
+ defaultColor,
210
+ direction: "bidirectional",
211
+ holdFrames: { start: holdStart, end: holdEnd },
212
+ enableFading: options.enableFading,
213
+ minAlpha: options.minAlpha,
214
+ };
215
+ return createKnightRiderTrail(trailOptions);
216
+ }
@@ -0,0 +1,42 @@
1
+ export declare const PROMPT_TEXTAREA_KEYBINDINGS: ({
2
+ name: string;
3
+ action: "submit";
4
+ shift?: undefined;
5
+ ctrl?: undefined;
6
+ meta?: undefined;
7
+ } | {
8
+ name: string;
9
+ shift: true;
10
+ action: "newline";
11
+ ctrl?: undefined;
12
+ meta?: undefined;
13
+ } | {
14
+ name: string;
15
+ ctrl: true;
16
+ action: "newline";
17
+ shift?: undefined;
18
+ meta?: undefined;
19
+ } | {
20
+ name: string;
21
+ meta: true;
22
+ action: "newline";
23
+ shift?: undefined;
24
+ ctrl?: undefined;
25
+ } | {
26
+ name: string;
27
+ action: "newline";
28
+ shift?: undefined;
29
+ ctrl?: undefined;
30
+ meta?: undefined;
31
+ })[];
32
+ export declare function isModifiedEnterSequence(input: {
33
+ raw?: string;
34
+ sequence?: string;
35
+ }): boolean;
36
+ export declare function isModeCycleSequence(value?: string): boolean;
37
+ export declare function isEscapeSequence(value?: string): boolean;
38
+ export declare function isModeCycleKeyEvent(input: {
39
+ name?: string;
40
+ raw?: string;
41
+ sequence?: string;
42
+ }): boolean;