@causyne/agent 1.20.0 → 1.20.5
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.
- package/README.md +0 -18
- package/package.json +1 -1
- package/src/acp/client.js +2 -1
- package/src/acp/client.ts +2 -1
- package/src/acp/server.js +5 -6
- package/src/acp/server.ts +4 -6
- package/src/agentLoop.d.ts +1 -0
- package/src/agentLoop.js +505 -241
- package/src/agentLoop.ts +527 -258
- package/src/agentPolicy.js +9 -0
- package/src/agentPolicy.ts +9 -0
- package/src/approvalPolicy.js +55 -0
- package/src/approvalPolicy.ts +66 -0
- package/src/browser/browserRuntime.js +217 -14
- package/src/browser/browserRuntime.ts +255 -14
- package/src/browser/causyneBrowser.js +1215 -68
- package/src/browser/causyneBrowser.ts +1340 -72
- package/src/cliMode.js +52 -29
- package/src/commands.js +141 -17
- package/src/config.js +22 -12
- package/src/continuum/ui/continuumPicker.js +18 -1
- package/src/continuum/ui/continuumPicker.ts +19 -1
- package/src/dynamicCatalogue.js +87 -20
- package/src/dynamicCatalogue.ts +85 -15
- package/src/launchIntent.js +40 -0
- package/src/launchIntent.ts +49 -0
- package/src/memoryManager.js +26 -2
- package/src/modelCatalogue.js +2 -0
- package/src/planCache.js +320 -11
- package/src/planCache.ts +402 -13
- package/src/providers/acp.js +67 -1
- package/src/providers/acp.ts +65 -2
- package/src/providers/antigravity.d.ts +5 -1
- package/src/providers/antigravity.js +643 -32
- package/src/providers/antigravity.ts +671 -33
- package/src/providers/base.d.ts +9 -0
- package/src/providers/factory.js +2 -0
- package/src/providers/pi.js +157 -0
- package/src/providers/pi.ts +144 -0
- package/src/provisioning/capabilityProvisioner.js +17 -0
- package/src/provisioning/capabilityTools.js +1 -1
- package/src/sandbox.js +30 -39
- package/src/sessionJournal.js +53 -10
- package/src/sessionJournal.ts +64 -10
- package/src/taskShape.js +9 -9
- package/src/taskShape.ts +9 -9
- package/src/timeMachine.js +124 -0
- package/src/timeMachine.ts +141 -0
- package/src/toolPacks.js +4 -10
- package/src/tools/archive.js +196 -59
- package/src/tools/archive.ts +220 -0
- package/src/tools/browserAutomator.js +78 -9
- package/src/tools/browserAutomator.ts +90 -9
- package/src/tools/desktopOpen.js +114 -31
- package/src/tools/desktopOpen.ts +144 -0
- package/src/tools/gitExec.js +5 -3
- package/src/tools/nativeEngine.js +4 -3
- package/src/tools/nativeEngine.ts +5 -3
- package/src/tools/openSourceToolProvisioner.js +5 -4
- package/src/tools/openSourceToolProvisioner.ts +5 -4
- package/src/tools/registry.js +3 -0
- package/src/tools/screenshot.js +55 -71
- package/src/tools/screenshot.ts +70 -0
- package/src/tools/sysRun.js +284 -117
- package/src/tools/sysRun.ts +347 -0
- package/src/tools/toolSelfRepair.js +109 -2
- package/src/tools/toolSelfRepair.ts +100 -2
- package/src/tools/updatePlan.js +49 -1
- package/src/tools/updatePlan.ts +43 -1
- package/src/tools/viewImage.js +93 -78
- package/src/tools/viewImage.ts +116 -0
- package/src/tools/webFetch.js +20 -6
- package/src/tools/webFetch.ts +26 -6
- package/src/tui/block.d.ts +1 -0
- package/src/tui/chatRenderer.d.ts +21 -0
- package/src/tui/chatRenderer.js +34 -47
- package/src/tui/clipboardSync.js +28 -1
- package/src/tui/clipboardSync.ts +26 -1
- package/src/tui/codeProgress.js +299 -0
- package/src/tui/codeProgress.ts +304 -0
- package/src/tui/codeStreamRenderer.js +116 -0
- package/src/tui/codeStreamRenderer.ts +124 -0
- package/src/tui/commandPresentation.js +11 -0
- package/src/tui/commandPresentation.ts +18 -0
- package/src/tui/completion.js +45 -13
- package/src/tui/composerControls.js +66 -0
- package/src/tui/composerControls.ts +78 -0
- package/src/tui/diff.d.ts +2 -0
- package/src/tui/home.js +4 -2
- package/src/tui/homeTransition.js +21 -0
- package/src/tui/homeTransition.ts +27 -0
- package/src/tui/homeView.js +62 -0
- package/src/tui/homeView.ts +91 -0
- package/src/tui/layout.js +46 -0
- package/src/tui/layout.ts +52 -0
- package/src/tui/messageActionPlacement.js +16 -0
- package/src/tui/messageActionPlacement.ts +25 -0
- package/src/tui/messageInteraction.js +221 -0
- package/src/tui/messageInteraction.ts +275 -0
- package/src/tui/modelPicker.js +4 -24
- package/src/tui/modelPicker.ts +4 -20
- package/src/tui/mouseHover.js +6 -0
- package/src/tui/mouseHover.ts +5 -0
- package/src/tui/prompt.js +152 -76
- package/src/tui/resizeRecovery.js +15 -0
- package/src/tui/resizeRecovery.ts +27 -0
- package/src/tui/scrollInteraction.js +97 -0
- package/src/tui/scrollInteraction.ts +189 -0
- package/src/tui/sessionLayout.js +12 -0
- package/src/tui/sessionLayout.ts +12 -0
- package/src/tui/sessionPicker.js +111 -16
- package/src/tui/sessionPicker.ts +121 -16
- package/src/tui/sessionSidebar.js +78 -0
- package/src/tui/sessionSidebar.ts +95 -0
- package/src/tui/setup.js +1 -1
- package/src/tui/setup.ts +1 -1
- package/src/tui/stageSurface.js +120 -58
- package/src/tui/text.d.ts +5 -0
- package/src/tui/textLayout.js +23 -0
- package/src/tui/textLayout.ts +28 -0
- package/src/tui/viewport.js +204 -279
- package/src/tui/viewport.ts +326 -0
- package/src/types/contracts.ts +54 -0
- package/src/utils/paths.js +5 -4
- package/src/utils/paths.ts +5 -5
package/src/tui/viewport.js
CHANGED
|
@@ -28,13 +28,8 @@
|
|
|
28
28
|
// genuinely the right number. The fractional accumulator is what allows a
|
|
29
29
|
// non-integer speed without drifting.
|
|
30
30
|
//
|
|
31
|
-
// Pure
|
|
32
|
-
|
|
33
|
-
// Rows per wheel notch. opencode's default, and its acceleration is opt-in for
|
|
34
|
-
// good reason: an accelerating wheel in a transcript overshoots the thing you
|
|
35
|
-
// were trying to read.
|
|
31
|
+
// Pure TypeScript. No dependency, no shell.
|
|
36
32
|
export const DEFAULT_SCROLL_SPEED = 3;
|
|
37
|
-
|
|
38
33
|
/**
|
|
39
34
|
* Opt-in wheel acceleration, the same shape opencode uses.
|
|
40
35
|
*
|
|
@@ -47,291 +42,221 @@ export const DEFAULT_SCROLL_SPEED = 3;
|
|
|
47
42
|
* the same few milliseconds, and counting both makes the curve run away.
|
|
48
43
|
*/
|
|
49
44
|
export class ScrollAcceleration {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
45
|
+
historySize;
|
|
46
|
+
streakTimeout;
|
|
47
|
+
minTickInterval;
|
|
48
|
+
intervals;
|
|
49
|
+
lastTick;
|
|
50
|
+
constructor({ history = 3, streakTimeout = 150, minTickInterval = 6 } = {}) {
|
|
51
|
+
this.historySize = history;
|
|
52
|
+
this.streakTimeout = streakTimeout;
|
|
53
|
+
this.minTickInterval = minTickInterval;
|
|
54
|
+
this.intervals = [];
|
|
55
|
+
this.lastTick = 0;
|
|
56
|
+
}
|
|
57
|
+
reset() {
|
|
58
|
+
this.intervals = [];
|
|
59
|
+
this.lastTick = 0;
|
|
60
|
+
}
|
|
61
|
+
tick(now = Date.now()) {
|
|
62
|
+
const A = 0.8;
|
|
63
|
+
const tau = 3;
|
|
64
|
+
const maxMultiplier = 6;
|
|
65
|
+
const gap = this.lastTick ? now - this.lastTick : Infinity;
|
|
66
|
+
if (gap === Infinity || gap > this.streakTimeout) {
|
|
67
|
+
this.lastTick = now;
|
|
68
|
+
this.intervals = [];
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
if (gap < this.minTickInterval)
|
|
72
|
+
return 1;
|
|
73
|
+
this.lastTick = now;
|
|
74
|
+
this.intervals.push(gap);
|
|
75
|
+
if (this.intervals.length > this.historySize)
|
|
76
|
+
this.intervals.shift();
|
|
77
|
+
const average = this.intervals.reduce((sum, v) => sum + v, 0) / this.intervals.length;
|
|
78
|
+
const velocity = 100 / average;
|
|
79
|
+
return Math.min(1 + A * (Math.exp(velocity / tau) - 1), maxMultiplier);
|
|
73
80
|
}
|
|
74
|
-
if (gap < this.minTickInterval) return 1;
|
|
75
|
-
|
|
76
|
-
this.lastTick = now;
|
|
77
|
-
this.intervals.push(gap);
|
|
78
|
-
if (this.intervals.length > this.historySize) this.intervals.shift();
|
|
79
|
-
|
|
80
|
-
const average = this.intervals.reduce((sum, v) => sum + v, 0) / this.intervals.length;
|
|
81
|
-
const velocity = 100 / average;
|
|
82
|
-
return Math.min(1 + A * (Math.exp(velocity / tau) - 1), maxMultiplier);
|
|
83
|
-
}
|
|
84
81
|
}
|
|
85
|
-
|
|
86
82
|
// How close to the bottom counts as "back at the bottom" for the purposes of
|
|
87
83
|
// resuming follow.
|
|
88
84
|
const REENGAGE_TOLERANCE = 1;
|
|
89
|
-
|
|
90
85
|
export class Viewport {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
get width() { return this.viewWidth; }
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Geometry changed — a resize, or the input box growing under the viewport.
|
|
113
|
-
*
|
|
114
|
-
* Resizing must not silently unfollow: growing the viewport reduces
|
|
115
|
-
* maxScrollTop, which would leave scrollTop above it and read as "the user
|
|
116
|
-
* scrolled away". refresh() re-derives from the new geometry instead.
|
|
117
|
-
*/
|
|
118
|
-
resize({ height, width } = {}) {
|
|
119
|
-
if (Number.isFinite(height) && height > 0) this.viewHeight = Math.floor(height);
|
|
120
|
-
if (Number.isFinite(width) && width > 0) this.viewWidth = Math.floor(width);
|
|
121
|
-
this.refresh();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
contentHeight() {
|
|
125
|
-
return this.transcript ? this.transcript.height(this.viewWidth) : 0;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
maxScrollTop() {
|
|
129
|
-
return Math.max(0, this.contentHeight() - this.viewHeight);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Is there enough content for scrolling to mean anything?
|
|
134
|
-
*
|
|
135
|
-
* The `> 1` rather than `> 0` is deliberate and comes from the reference: one
|
|
136
|
-
* row of overflow is not a scroll, and treating it as one makes the follow
|
|
137
|
-
* flag flicker on every wrapped line during streaming.
|
|
138
|
-
*/
|
|
139
|
-
scrollable() {
|
|
140
|
-
return this.maxScrollTop() > 1;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
atBottom() {
|
|
144
|
-
return this.scrollTop >= this.maxScrollTop();
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
get following() {
|
|
148
|
-
return !this.manual;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Re-derive the follow flag from where we now are. Called after EVERY scroll
|
|
153
|
-
* mutation, whoever caused it.
|
|
154
|
-
*/
|
|
155
|
-
sync() {
|
|
156
|
-
if (this.applyingSticky) {
|
|
157
|
-
// A move we made ourselves. It is only allowed to CLEAR the flag — by
|
|
158
|
-
// arriving back at the bottom — never to set it.
|
|
159
|
-
if (this.manual && this.scrollable() && this.atBottom()) {
|
|
86
|
+
transcript;
|
|
87
|
+
viewHeight;
|
|
88
|
+
viewWidth;
|
|
89
|
+
speed;
|
|
90
|
+
acceleration;
|
|
91
|
+
scrollTop;
|
|
92
|
+
manual;
|
|
93
|
+
applyingSticky;
|
|
94
|
+
accumulator;
|
|
95
|
+
unseen;
|
|
96
|
+
lastWheelMoved;
|
|
97
|
+
constructor({ transcript = null, height = 20, width = 80, speed = DEFAULT_SCROLL_SPEED, acceleration = null } = {}) {
|
|
98
|
+
this.transcript = transcript;
|
|
99
|
+
this.viewHeight = Math.max(1, Math.floor(height));
|
|
100
|
+
this.viewWidth = Math.max(1, Math.floor(width));
|
|
101
|
+
this.speed = speed > 0 ? speed : DEFAULT_SCROLL_SPEED;
|
|
102
|
+
this.acceleration = acceleration || null;
|
|
103
|
+
this.scrollTop = 0;
|
|
160
104
|
this.manual = false;
|
|
105
|
+
this.applyingSticky = false;
|
|
106
|
+
this.accumulator = 0;
|
|
161
107
|
this.unseen = 0;
|
|
162
|
-
|
|
163
|
-
return;
|
|
108
|
+
this.lastWheelMoved = false;
|
|
164
109
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
110
|
+
get height() { return this.viewHeight; }
|
|
111
|
+
get width() { return this.viewWidth; }
|
|
112
|
+
/**
|
|
113
|
+
* Geometry changed — a resize, or the input box growing under the viewport.
|
|
114
|
+
*/
|
|
115
|
+
resize({ height, width } = {}) {
|
|
116
|
+
if (height !== undefined && Number.isFinite(height) && height > 0)
|
|
117
|
+
this.viewHeight = Math.floor(height);
|
|
118
|
+
if (width !== undefined && Number.isFinite(width) && width > 0)
|
|
119
|
+
this.viewWidth = Math.floor(width);
|
|
120
|
+
this.refresh();
|
|
121
|
+
}
|
|
122
|
+
contentHeight() {
|
|
123
|
+
return this.transcript ? this.transcript.height(this.viewWidth) : 0;
|
|
124
|
+
}
|
|
125
|
+
maxScrollTop() {
|
|
126
|
+
return Math.max(0, this.contentHeight() - this.viewHeight);
|
|
127
|
+
}
|
|
128
|
+
scrollable() {
|
|
129
|
+
return this.maxScrollTop() > 1;
|
|
130
|
+
}
|
|
131
|
+
atBottom() {
|
|
132
|
+
return this.scrollTop >= this.maxScrollTop();
|
|
133
|
+
}
|
|
134
|
+
get following() {
|
|
135
|
+
return !this.manual;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Re-derive the follow flag from where we now are. Called after EVERY scroll
|
|
139
|
+
* mutation, whoever caused it.
|
|
140
|
+
*/
|
|
141
|
+
sync() {
|
|
142
|
+
if (this.applyingSticky) {
|
|
143
|
+
if (this.manual && this.scrollable() && this.atBottom()) {
|
|
144
|
+
this.manual = false;
|
|
145
|
+
this.unseen = 0;
|
|
146
|
+
}
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
this.manual = this.scrollable() && !this.atBottom();
|
|
150
|
+
if (!this.manual)
|
|
151
|
+
this.unseen = 0;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The content changed height — a token arrived, a tool printed, a frame was
|
|
155
|
+
* evicted. This is where auto-scroll actually happens.
|
|
156
|
+
*/
|
|
157
|
+
refresh(grownBy = 0) {
|
|
158
|
+
const wasApplying = this.applyingSticky;
|
|
159
|
+
this.applyingSticky = true;
|
|
160
|
+
try {
|
|
161
|
+
const max = this.maxScrollTop();
|
|
162
|
+
const tolerance = grownBy > 0 ? REENGAGE_TOLERANCE : 0;
|
|
163
|
+
if (!this.manual) {
|
|
164
|
+
this.scrollTop = max;
|
|
165
|
+
this.unseen = 0;
|
|
166
|
+
}
|
|
167
|
+
else if (max > 0 && this.scrollTop >= max - tolerance) {
|
|
168
|
+
this.manual = false;
|
|
169
|
+
this.scrollTop = max;
|
|
170
|
+
this.unseen = 0;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
this.scrollTop = Math.min(this.scrollTop, max);
|
|
174
|
+
if (grownBy > 0)
|
|
175
|
+
this.unseen += grownBy;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
this.applyingSticky = wasApplying;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
scrollTo(position, { snap = false } = {}) {
|
|
183
|
+
const max = this.maxScrollTop();
|
|
184
|
+
let next = Math.max(0, Math.min(Math.round(position), max));
|
|
185
|
+
if (snap && next > this.scrollTop && max - next <= REENGAGE_TOLERANCE)
|
|
186
|
+
next = max;
|
|
187
|
+
if (next !== this.scrollTop)
|
|
188
|
+
this.scrollTop = next;
|
|
189
|
+
this.sync();
|
|
190
|
+
return this.scrollTop;
|
|
191
|
+
}
|
|
192
|
+
scrollBy(delta) {
|
|
193
|
+
return this.scrollTo(this.scrollTop + delta, { snap: delta > 0 });
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* One wheel notch. `direction` is 'up' or 'down'.
|
|
197
|
+
*
|
|
198
|
+
* The accumulator carries the fraction so a speed of, say, 1.5 does not
|
|
199
|
+
* quietly round to 1 or 2 forever.
|
|
200
|
+
*/
|
|
201
|
+
wheel(direction, notches = 1, now = Date.now()) {
|
|
202
|
+
const before = this.scrollTop;
|
|
203
|
+
const multiplier = this.acceleration ? this.acceleration.tick(now) : 1;
|
|
204
|
+
const amount = Math.abs(notches) * this.speed * multiplier;
|
|
205
|
+
this.accumulator += direction === 'up' ? -amount : amount;
|
|
206
|
+
const whole = Math.trunc(this.accumulator);
|
|
207
|
+
if (whole !== 0) {
|
|
208
|
+
this.accumulator -= whole;
|
|
209
|
+
this.scrollBy(whole);
|
|
210
|
+
}
|
|
211
|
+
this.lastWheelMoved = this.scrollTop !== before;
|
|
212
|
+
return this.scrollTop;
|
|
213
|
+
}
|
|
214
|
+
pageUp() { return this.scrollBy(-Math.max(1, this.viewHeight - 1)); }
|
|
215
|
+
pageDown() { return this.scrollBy(Math.max(1, this.viewHeight - 1)); }
|
|
216
|
+
halfPageUp() { return this.scrollBy(-Math.max(1, Math.floor(this.viewHeight / 2))); }
|
|
217
|
+
halfPageDown() { return this.scrollBy(Math.max(1, Math.floor(this.viewHeight / 2))); }
|
|
218
|
+
lineUp(n = 1) { return this.scrollBy(-n); }
|
|
219
|
+
lineDown(n = 1) { return this.scrollBy(n); }
|
|
220
|
+
toTop() { return this.scrollTo(0); }
|
|
221
|
+
toBottom() {
|
|
197
222
|
this.manual = false;
|
|
198
|
-
this.scrollTop = max;
|
|
199
223
|
this.unseen = 0;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
224
|
+
this.refresh();
|
|
225
|
+
return this.scrollTop;
|
|
226
|
+
}
|
|
227
|
+
jump(direction, kinds = null) {
|
|
228
|
+
if (!this.transcript || typeof this.transcript.markers !== 'function')
|
|
229
|
+
return this.scrollTop;
|
|
230
|
+
const markers = this.transcript.markers(this.viewWidth)
|
|
231
|
+
.filter((m) => !kinds || kinds.includes(m.kind));
|
|
232
|
+
if (markers.length === 0)
|
|
233
|
+
return this.scrollTop;
|
|
234
|
+
if (direction < 0) {
|
|
235
|
+
const previous = markers.filter((m) => m.row < this.scrollTop).pop();
|
|
236
|
+
return this.scrollTo(previous ? previous.row : 0);
|
|
237
|
+
}
|
|
238
|
+
const next = markers.find((m) => m.row > this.scrollTop);
|
|
239
|
+
return next ? this.scrollTo(next.row) : this.toBottom();
|
|
208
240
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
// The reference puts it in the growth handler (ScrollBox.ts:497-512), where
|
|
218
|
-
// it covers the case that actually annoys people: a wheel of three rows per
|
|
219
|
-
// notch lands you one row short of the bottom, and follow never resumes.
|
|
220
|
-
// But that handler runs on every repaint here, so a flat tolerance also
|
|
221
|
-
// undoes a deliberate one-row scroll UP — a key that visibly does nothing.
|
|
222
|
-
//
|
|
223
|
-
// The two are mechanically identical and differ only in intent, and the
|
|
224
|
-
// direction of travel is the one piece of intent that IS available. So the
|
|
225
|
-
// snap is applied to downward motion only: scrolling down to within a row
|
|
226
|
-
// of the end means the end; scrolling up by one row means one row.
|
|
227
|
-
if (snap && next > this.scrollTop && max - next <= REENGAGE_TOLERANCE) next = max;
|
|
228
|
-
|
|
229
|
-
if (next !== this.scrollTop) this.scrollTop = next;
|
|
230
|
-
this.sync();
|
|
231
|
-
return this.scrollTop;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
scrollBy(delta) {
|
|
235
|
-
return this.scrollTo(this.scrollTop + delta, { snap: delta > 0 });
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* One wheel notch. `direction` is 'up' or 'down'.
|
|
240
|
-
*
|
|
241
|
-
* The accumulator carries the fraction so a speed of, say, 1.5 does not
|
|
242
|
-
* quietly round to 1 or 2 forever.
|
|
243
|
-
*/
|
|
244
|
-
wheel(direction, notches = 1, now = Date.now()) {
|
|
245
|
-
const before = this.scrollTop;
|
|
246
|
-
const multiplier = this.acceleration ? this.acceleration.tick(now) : 1;
|
|
247
|
-
const amount = Math.abs(notches) * this.speed * multiplier;
|
|
248
|
-
this.accumulator += direction === 'up' ? -amount : amount;
|
|
249
|
-
const whole = Math.trunc(this.accumulator);
|
|
250
|
-
if (whole !== 0) {
|
|
251
|
-
this.accumulator -= whole;
|
|
252
|
-
this.scrollBy(whole);
|
|
241
|
+
rows() {
|
|
242
|
+
const window = this.transcript && typeof this.transcript.slice === 'function'
|
|
243
|
+
? this.transcript.slice(this.viewWidth, this.scrollTop, this.viewHeight)
|
|
244
|
+
: [];
|
|
245
|
+
const out = window.slice(0, this.viewHeight);
|
|
246
|
+
while (out.length < this.viewHeight)
|
|
247
|
+
out.push('');
|
|
248
|
+
return out;
|
|
253
249
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
// is no reason to inherit that.)
|
|
266
|
-
pageUp() { return this.scrollBy(-Math.max(1, this.viewHeight - 1)); }
|
|
267
|
-
pageDown() { return this.scrollBy(Math.max(1, this.viewHeight - 1)); }
|
|
268
|
-
halfPageUp() { return this.scrollBy(-Math.max(1, Math.floor(this.viewHeight / 2))); }
|
|
269
|
-
halfPageDown() { return this.scrollBy(Math.max(1, Math.floor(this.viewHeight / 2))); }
|
|
270
|
-
lineUp(n = 1) { return this.scrollBy(-n); }
|
|
271
|
-
lineDown(n = 1) { return this.scrollBy(n); }
|
|
272
|
-
toTop() { return this.scrollTo(0); }
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Jump to the bottom and resume following.
|
|
276
|
-
*
|
|
277
|
-
* scrollTo() alone would land at the bottom and sync() would clear the flag,
|
|
278
|
-
* but only if the content is scrollable; going through the sticky path makes
|
|
279
|
-
* "follow again" unconditional, which is what the user means by pressing it.
|
|
280
|
-
*/
|
|
281
|
-
toBottom() {
|
|
282
|
-
this.manual = false;
|
|
283
|
-
this.unseen = 0;
|
|
284
|
-
this.refresh();
|
|
285
|
-
return this.scrollTop;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Frame boundaries, for step-to-step and turn-to-turn jumps.
|
|
290
|
-
*/
|
|
291
|
-
jump(direction, kinds = null) {
|
|
292
|
-
if (!this.transcript) return this.scrollTop;
|
|
293
|
-
const markers = this.transcript.markers(this.viewWidth)
|
|
294
|
-
.filter((m) => !kinds || kinds.includes(m.kind));
|
|
295
|
-
if (markers.length === 0) return this.scrollTop;
|
|
296
|
-
|
|
297
|
-
if (direction < 0) {
|
|
298
|
-
const previous = markers.filter((m) => m.row < this.scrollTop).pop();
|
|
299
|
-
return this.scrollTo(previous ? previous.row : 0);
|
|
250
|
+
state() {
|
|
251
|
+
const max = this.maxScrollTop();
|
|
252
|
+
return {
|
|
253
|
+
scrollTop: this.scrollTop,
|
|
254
|
+
max,
|
|
255
|
+
height: this.viewHeight,
|
|
256
|
+
contentHeight: this.contentHeight(),
|
|
257
|
+
following: this.following,
|
|
258
|
+
unseen: this.unseen,
|
|
259
|
+
progress: max > 0 ? this.scrollTop / max : null
|
|
260
|
+
};
|
|
300
261
|
}
|
|
301
|
-
const next = markers.find((m) => m.row > this.scrollTop);
|
|
302
|
-
return next ? this.scrollTo(next.row) : this.toBottom();
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* The rows on screen, top-aligned and padded to the full height.
|
|
307
|
-
*
|
|
308
|
-
* Top-aligned because that is what the reference does: content starts at the
|
|
309
|
-
* top of the box and the gap sits above the prompt, not below the first
|
|
310
|
-
* message.
|
|
311
|
-
*/
|
|
312
|
-
rows() {
|
|
313
|
-
const window = this.transcript
|
|
314
|
-
? this.transcript.slice(this.viewWidth, this.scrollTop, this.viewHeight)
|
|
315
|
-
: [];
|
|
316
|
-
const out = window.slice(0, this.viewHeight);
|
|
317
|
-
while (out.length < this.viewHeight) out.push('');
|
|
318
|
-
return out;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Where we are, for the rail and the "N new below" affordance.
|
|
323
|
-
*/
|
|
324
|
-
state() {
|
|
325
|
-
const max = this.maxScrollTop();
|
|
326
|
-
return {
|
|
327
|
-
scrollTop: this.scrollTop,
|
|
328
|
-
max,
|
|
329
|
-
height: this.viewHeight,
|
|
330
|
-
contentHeight: this.contentHeight(),
|
|
331
|
-
following: this.following,
|
|
332
|
-
unseen: this.unseen,
|
|
333
|
-
// 0..1, or null when there is nothing to scroll.
|
|
334
|
-
progress: max > 0 ? this.scrollTop / max : null
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
262
|
}
|