feat(frontend): enhance chat streaming visuals with shimmer effect and fade tail

- Introduce a shimmer effect for in-progress step titles in chat components, providing visual feedback during processing.
- Implement a trailing fade effect for the most recently streamed characters in chat markdown, enhancing the typing experience.
- Update CSS styles to support the new shimmer and fade effects, ensuring smooth transitions and visual coherence.
- Add tests to verify the functionality of the shimmer effect and the application of the fade tail in markdown rendering.
This commit is contained in:
wizardchen
2026-06-19 23:28:47 +08:00
committed by lyingbug
parent 58461a5b68
commit cc9de85c25
8 changed files with 222 additions and 35 deletions
@@ -16,6 +16,21 @@
letter-spacing: normal;
-webkit-font-smoothing: antialiased;
// Trailing fade on the newest streamed characters: the tail is wrapped in
// this span (see applyStreamingTailFade) so its right edge dissolves, giving
// a soft "just typed" reveal that settles once streaming stops and the wrap
// is no longer emitted.
:deep(.stream-fade-tail) {
-webkit-mask-image: linear-gradient(to right,
rgba(0, 0, 0, 1) 0%,
rgba(0, 0, 0, 0.7) 30%,
rgba(0, 0, 0, 0) 100%);
mask-image: linear-gradient(to right,
rgba(0, 0, 0, 1) 0%,
rgba(0, 0, 0, 0.7) 30%,
rgba(0, 0, 0, 0) 100%);
}
:deep(p) {
margin: 0 0 0.25em;
line-height: 1.625;
@@ -23,6 +23,61 @@
}
}
// A light sweep across in-progress text (the "光影" / shimmer effect). The base
// is the muted secondary color and a brighter band slides across, signalling
// "this step is still running" without the layout cost of a spinner.
// One full gradient width (background-size is 200%) so the loop is seamless.
@keyframes chatStreamShimmer {
0% {
background-position: 100% 50%;
}
100% {
background-position: -100% 50%;
}
}
.chat-stream-shimmer-text() {
// Stronger contrast: a dim placeholder base with a bright primary glint, so
// the sweeping band reads clearly rather than as a subtle shift.
background-image: linear-gradient(100deg,
var(--td-text-color-placeholder) 0%,
var(--td-text-color-placeholder) 36%,
var(--td-text-color-primary) 50%,
var(--td-text-color-placeholder) 64%,
var(--td-text-color-placeholder) 100%);
background-size: 200% 100%;
// Let the gradient tile (default repeat): the dim stops on both ends match,
// so the element is always fully painted and the band sweeps seamlessly.
// (no-repeat would leave the uncovered area transparent -> invisible text.)
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
color: transparent;
animation: chatStreamShimmer 1.5s linear infinite;
// Keep the sweep on its own compositor layer so it stays smooth while the
// surrounding timeline relayouts on each streamed token.
will-change: background-position;
}
// In-progress step / thinking / tool-call titles shimmer while pending. Both the
// agent timeline (.action-pending) and the RAG pipeline (.is-running) opt in.
.action-card.action-pending .action-name,
.action-name.is-running {
.chat-stream-shimmer-text();
}
@media (prefers-reduced-motion: reduce) {
.action-card.action-pending .action-name,
.action-name.is-running {
animation: none;
background-image: none;
-webkit-text-fill-color: var(--td-text-color-secondary);
color: var(--td-text-color-secondary);
}
}
.streaming-loading-node {
.tree-child-content {
position: relative;
@@ -14,3 +14,17 @@ test('timeline loading uses shared gray bounce dots on the axis', () => {
assert.match(css, /animation:\s*chatTimelineTypingBounce/)
assert.match(css, /animation-delay:\s*0\.2s/)
})
test('in-progress step titles get the streaming shimmer sweep', () => {
// Both timelines opt into the shimmer: agent (.action-pending) and RAG (.is-running).
assert.match(css, /\.action-card\.action-pending \.action-name,\s*\.action-name\.is-running/)
assert.match(css, /-webkit-background-clip:\s*text/)
assert.match(css, /animation:\s*chatStreamShimmer/)
assert.match(css, /@keyframes chatStreamShimmer/)
})
test('shimmer is disabled under reduced motion', () => {
assert.match(css, /@media \(prefers-reduced-motion: reduce\)/)
const reducedBlock = css.slice(css.indexOf('@media (prefers-reduced-motion: reduce)'))
assert.match(reducedBlock, /animation:\s*none/)
})