@ruckc/truss-chat 1.51.0 → 1.52.0
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/dist/ChatMessage.svelte +2 -4
- package/dist/ChatThread.svelte +3 -1
- package/dist/ToolCall.svelte +5 -6
- package/dist/scrollfocus.d.ts +18 -0
- package/dist/scrollfocus.js +92 -0
- package/package.json +2 -2
package/dist/ChatMessage.svelte
CHANGED
|
@@ -166,18 +166,16 @@
|
|
|
166
166
|
.rtoggle { display: inline-flex; align-items: center; gap: var(--tr-space-1); min-height: var(--tr-control-h-sm); max-width: 100%; padding: 0 var(--tr-space-1); border: 0; border-radius: var(--tr-radius-sm); background: none; color: inherit; font: inherit; cursor: pointer; }
|
|
167
167
|
.rtoggle:hover { color: var(--tr-on-surface); }
|
|
168
168
|
.rtoggle:focus-visible { outline: none; box-shadow: var(--tr-focus-ring); }
|
|
169
|
-
.chev { display: inline-flex; transition: transform var(--tr-dur) var(--tr-ease); }
|
|
169
|
+
.chev { display: inline-flex; transition: transform var(--tr-dur-move) var(--tr-ease); }
|
|
170
170
|
.chev[data-open='true'] { transform: rotate(180deg); }
|
|
171
171
|
.thinking { font-style: italic; opacity: 0.85; animation: pulse 1.6s infinite ease-in-out; }
|
|
172
172
|
.rbody { margin-top: var(--tr-space-1); padding-inline-start: var(--tr-space-3); border-inline-start: 2px solid var(--tr-outline-variant); min-width: 0; overflow-wrap: anywhere; line-height: 1.5; }
|
|
173
173
|
@keyframes pulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }
|
|
174
|
-
@media (prefers-reduced-motion: reduce) { .thinking { animation: none; } }
|
|
175
174
|
.tools { display: flex; flex-direction: column; gap: var(--tr-space-1); width: 100%; min-width: 0; }
|
|
176
175
|
|
|
177
176
|
.typing { display: inline-flex; gap: 4px; align-items: center; height: 1.5em; vertical-align: bottom; }
|
|
178
177
|
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--tr-on-surface-variant); animation: bounce 1.2s infinite ease-in-out; }
|
|
179
178
|
.typing i:nth-child(2) { animation-delay: 0.15s; }
|
|
180
179
|
.typing i:nth-child(3) { animation-delay: 0.3s; }
|
|
181
|
-
@keyframes bounce { 0%, 60%, 100% { opacity: 0.35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
|
|
182
|
-
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: 0.7; } }
|
|
180
|
+
@keyframes bounce { 0%, 60%, 100% { opacity: 0.35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(calc(-3px * var(--tr-motion-distance))); } }
|
|
183
181
|
</style>
|
package/dist/ChatThread.svelte
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
<script lang="ts">
|
|
12
12
|
import { useLabels } from './labels.js';
|
|
13
|
+
import { scrollFocus } from './scrollfocus.js';
|
|
13
14
|
import { onDestroy, onMount, type Snippet } from 'svelte';
|
|
14
15
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
15
16
|
import { Button } from '@ruckc/truss-ui';
|
|
@@ -162,7 +163,7 @@
|
|
|
162
163
|
|
|
163
164
|
<div {...rest} class={['thread', klass]}>
|
|
164
165
|
<!-- aria-live="off": a log is implicitly polite, which would announce every streamed token; finished replies go through the live region below instead -->
|
|
165
|
-
<div class="log" role="log" aria-live="off" aria-label={label ?? L.conversation} bind:this={log} onscroll={(e) => { onscroll(e); measure(); }} onfocusin={infocus} onfocusout={outfocus}>
|
|
166
|
+
<div class="log" role="log" aria-live="off" aria-label={label ?? L.conversation} bind:this={log} onscroll={(e) => { onscroll(e); measure(); }} onfocusin={infocus} onfocusout={outfocus} {@attach scrollFocus(() => ({ role: false }))}>
|
|
166
167
|
<div class="content" bind:this={content}>{@render children()}</div>
|
|
167
168
|
</div>
|
|
168
169
|
{#if !follow && !stepAside}
|
|
@@ -174,6 +175,7 @@
|
|
|
174
175
|
<style>
|
|
175
176
|
.thread { position: relative; display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; }
|
|
176
177
|
.log { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; border-radius: var(--tr-radius-md); }
|
|
178
|
+
.log:focus-visible { outline: none; box-shadow: inset var(--tr-focus-ring); }
|
|
177
179
|
.content { display: flex; flex-direction: column; gap: var(--tr-space-4); padding: var(--tr-space-3); min-width: 0; }
|
|
178
180
|
.jump { position: absolute; inset-inline: 0; bottom: var(--tr-space-3); display: flex; justify-content: center; pointer-events: none; }
|
|
179
181
|
.jump :global(.tr-btn) { pointer-events: auto; box-shadow: var(--tr-elevation-2); }
|
package/dist/ToolCall.svelte
CHANGED
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
|
|
65
65
|
<script lang="ts">
|
|
66
66
|
import { useLabels } from './labels.js';
|
|
67
|
+
import { scrollFocus } from './scrollfocus.js';
|
|
67
68
|
import { onDestroy, untrack, type Snippet } from 'svelte';
|
|
68
69
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
69
70
|
import { Button, Dialog, Icon, Tooltip } from '@ruckc/truss-ui';
|
|
@@ -181,8 +182,6 @@
|
|
|
181
182
|
timer = setTimeout(() => (copied = undefined), 2000);
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
/** A scrolling region must be reachable by keyboard so it can be scrolled with the arrow keys. */
|
|
185
|
-
const focusable = (node: HTMLElement) => void (node.tabIndex = 0);
|
|
186
185
|
</script>
|
|
187
186
|
|
|
188
187
|
{#snippet icon()}
|
|
@@ -211,7 +210,7 @@
|
|
|
211
210
|
</span>
|
|
212
211
|
</div>
|
|
213
212
|
{#if !folded}
|
|
214
|
-
<pre id="{uid}-{s.key}" {@attach
|
|
213
|
+
<pre id="{uid}-{s.key}" {@attach scrollFocus(() => ({ label: s.title }))}>{c.text}</pre>
|
|
215
214
|
{#if c.hidden}
|
|
216
215
|
<Button variant="minimal" size="sm" aria-expanded={c.open} aria-controls="{uid}-{s.key}" onclick={() => (expanded[s.key] = !c.open)}>{c.open ? L.showLess : L.showAll(c.hidden)}</Button>
|
|
217
216
|
{/if}
|
|
@@ -256,7 +255,7 @@
|
|
|
256
255
|
<div class="row">{@render lead()}<span class="name">{shown}</span>{#if line}<span class="summary" title={line}>{line}</span>{/if}<span class="status">{statusText}</span></div>
|
|
257
256
|
{/if}
|
|
258
257
|
{#if hasBody && mode === 'inline' && open}
|
|
259
|
-
<div class="details" id="{uid}-details">{@render body()}</div>
|
|
258
|
+
<div class="details" id="{uid}-details" {@attach scrollFocus()}>{@render body()}</div>
|
|
260
259
|
{/if}
|
|
261
260
|
</div>
|
|
262
261
|
{#if hasBody && mode === 'dialog' && mounted}
|
|
@@ -286,7 +285,7 @@
|
|
|
286
285
|
.summary { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--tr-on-surface-variant); }
|
|
287
286
|
.status { flex: none; color: var(--tr-on-surface-variant); }
|
|
288
287
|
[data-status='failed'] .status { color: var(--tr-danger); font-weight: 600; }
|
|
289
|
-
.chev { display: inline-flex; flex: none; color: var(--tr-on-surface-variant); transition: transform var(--tr-dur) var(--tr-ease); }
|
|
288
|
+
.chev { display: inline-flex; flex: none; color: var(--tr-on-surface-variant); transition: transform var(--tr-dur-move) var(--tr-ease); }
|
|
290
289
|
.chev[data-open='true'] { transform: rotate(180deg); }
|
|
291
290
|
.details { width: 100%; box-sizing: border-box; padding: var(--tr-space-2) var(--tr-space-3) var(--tr-space-3); overflow-x: auto; overflow-wrap: anywhere; }
|
|
292
291
|
.tool[data-variant='row'] .details { border-top: 1px solid var(--tr-outline-variant); }
|
|
@@ -311,6 +310,6 @@
|
|
|
311
310
|
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: var(--tr-space-2); }
|
|
312
311
|
.sec-title { font-weight: 600; font-size: var(--tr-text-sm); }
|
|
313
312
|
pre { margin: 0; max-width: 100%; max-height: min(40vh, 320px); overflow: auto; box-sizing: border-box; padding: var(--tr-space-2) var(--tr-space-3); border: 1px solid var(--tr-outline-variant); border-radius: var(--tr-radius-md); background: var(--tr-surface-container); color: var(--tr-on-surface); font-family: var(--tr-font-mono); font-size: var(--tr-text-sm); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; tab-size: 2; }
|
|
314
|
-
pre:focus-visible { outline: none; box-shadow: var(--tr-focus-ring); }
|
|
313
|
+
.details:focus-visible, pre:focus-visible { outline: none; box-shadow: var(--tr-focus-ring); }
|
|
315
314
|
[data-section='error'] pre { border-color: var(--tr-danger); }
|
|
316
315
|
</style>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Attachment } from 'svelte/attachments';
|
|
2
|
+
/**
|
|
3
|
+
* @internal Makes a scroll container reachable by keyboard while (and only while) it scrolls and has nothing of its own to Tab to (axe `scrollable-region-focusable`, #269).
|
|
4
|
+
*
|
|
5
|
+
* A keyboard user can scroll a region only when it, or something inside it, can take focus. So while the content overflows and holds no tabbable control, the element gets
|
|
6
|
+
* `tabindex="0"`, `role="region"` and an accessible name, and a focus ring from its component's CSS (`:focus-visible`). With a tabbable control inside, the control is the tab stop
|
|
7
|
+
* (focusing it scrolls it into view, and axe accepts that), and an extra stop on the container would only make Tab slower. When nothing overflows there is no tab stop at all.
|
|
8
|
+
* Re-measured when the element or its children resize and when its content changes. It writes nothing on the server (attachments run in the browser), so the markup carries no
|
|
9
|
+
* tab stop until it has been measured and there is no hydration mismatch.
|
|
10
|
+
*
|
|
11
|
+
* `get` supplies the name: `labelledby` (an element id, preferred) or `label` (text). Without either, the role is left off (a nameless region is noise) and only the tab stop is added.
|
|
12
|
+
* `role: false` keeps the element's own role (`main`). Attributes the app set itself (`tabindex` other than `-1`, `role`, `aria-label`, `aria-labelledby`) are never overwritten.
|
|
13
|
+
*/
|
|
14
|
+
export declare function scrollFocus(get?: () => {
|
|
15
|
+
labelledby?: string;
|
|
16
|
+
label?: string;
|
|
17
|
+
role?: boolean;
|
|
18
|
+
}): Attachment<HTMLElement>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/** Elements a keyboard user can Tab to on their own. A `tabindex="-1"` element is only focusable by script, so it does not count. */
|
|
2
|
+
const TABBABLE = 'a[href],area[href],button,input:not([type="hidden"]),select,textarea,summary,iframe,audio[controls],video[controls],[contenteditable]:not([contenteditable="false"]),[tabindex]';
|
|
3
|
+
function tabbableWithin(el) {
|
|
4
|
+
for (const c of el.querySelectorAll(TABBABLE)) {
|
|
5
|
+
const t = c.getAttribute('tabindex');
|
|
6
|
+
if (t !== null && Number(t) < 0)
|
|
7
|
+
continue;
|
|
8
|
+
if (c.matches(':disabled') || c.closest('[hidden],[inert]') || c.getClientRects().length === 0)
|
|
9
|
+
continue;
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
/** Whether `el` scrolls right now: it clips its overflow (`auto`/`scroll`) and its content is larger than its box. */
|
|
15
|
+
function scrolls(el) {
|
|
16
|
+
const cs = getComputedStyle(el);
|
|
17
|
+
return (/auto|scroll/.test(cs.overflowY) && el.scrollHeight > el.clientHeight + 1) || (/auto|scroll/.test(cs.overflowX) && el.scrollWidth > el.clientWidth + 1);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @internal Makes a scroll container reachable by keyboard while (and only while) it scrolls and has nothing of its own to Tab to (axe `scrollable-region-focusable`, #269).
|
|
21
|
+
*
|
|
22
|
+
* A keyboard user can scroll a region only when it, or something inside it, can take focus. So while the content overflows and holds no tabbable control, the element gets
|
|
23
|
+
* `tabindex="0"`, `role="region"` and an accessible name, and a focus ring from its component's CSS (`:focus-visible`). With a tabbable control inside, the control is the tab stop
|
|
24
|
+
* (focusing it scrolls it into view, and axe accepts that), and an extra stop on the container would only make Tab slower. When nothing overflows there is no tab stop at all.
|
|
25
|
+
* Re-measured when the element or its children resize and when its content changes. It writes nothing on the server (attachments run in the browser), so the markup carries no
|
|
26
|
+
* tab stop until it has been measured and there is no hydration mismatch.
|
|
27
|
+
*
|
|
28
|
+
* `get` supplies the name: `labelledby` (an element id, preferred) or `label` (text). Without either, the role is left off (a nameless region is noise) and only the tab stop is added.
|
|
29
|
+
* `role: false` keeps the element's own role (`main`). Attributes the app set itself (`tabindex` other than `-1`, `role`, `aria-label`, `aria-labelledby`) are never overwritten.
|
|
30
|
+
*/
|
|
31
|
+
export function scrollFocus(get) {
|
|
32
|
+
return (el) => {
|
|
33
|
+
let added = [];
|
|
34
|
+
let restore; // a programmatic-only `tabindex="-1"` (Shell's `main`) is replaced while the tab stop is on
|
|
35
|
+
let queued = false;
|
|
36
|
+
const clear = () => {
|
|
37
|
+
for (const a of added)
|
|
38
|
+
el.removeAttribute(a);
|
|
39
|
+
added = [];
|
|
40
|
+
if (restore !== undefined) {
|
|
41
|
+
el.setAttribute('tabindex', restore);
|
|
42
|
+
restore = undefined;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const set = (name, value) => { if (!el.hasAttribute(name)) {
|
|
46
|
+
el.setAttribute(name, value);
|
|
47
|
+
added.push(name);
|
|
48
|
+
} };
|
|
49
|
+
const measure = () => {
|
|
50
|
+
queued = false;
|
|
51
|
+
const on = scrolls(el) && !tabbableWithin(el);
|
|
52
|
+
if (!on) {
|
|
53
|
+
clear();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (added.length)
|
|
57
|
+
return;
|
|
58
|
+
const { labelledby, label, role = true } = get?.() ?? {};
|
|
59
|
+
const named = !!(labelledby || label) && !el.hasAttribute('aria-label') && !el.hasAttribute('aria-labelledby');
|
|
60
|
+
if (el.getAttribute('tabindex') === '-1') {
|
|
61
|
+
restore = '-1';
|
|
62
|
+
el.removeAttribute('tabindex');
|
|
63
|
+
}
|
|
64
|
+
set('tabindex', '0');
|
|
65
|
+
if (role && (named || el.hasAttribute('aria-label') || el.hasAttribute('aria-labelledby')))
|
|
66
|
+
set('role', 'region');
|
|
67
|
+
if (named) {
|
|
68
|
+
if (labelledby)
|
|
69
|
+
set('aria-labelledby', labelledby);
|
|
70
|
+
else
|
|
71
|
+
set('aria-label', label);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
// coalesce bursts (a virtual list scrolling, many nodes added) into one measurement per microtask
|
|
75
|
+
const schedule = () => { if (!queued) {
|
|
76
|
+
queued = true;
|
|
77
|
+
queueMicrotask(measure);
|
|
78
|
+
} };
|
|
79
|
+
const ro = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(schedule);
|
|
80
|
+
const watchKids = () => { if (ro) {
|
|
81
|
+
ro.disconnect();
|
|
82
|
+
ro.observe(el);
|
|
83
|
+
for (const k of el.children)
|
|
84
|
+
ro.observe(k);
|
|
85
|
+
} };
|
|
86
|
+
const mo = new MutationObserver(() => { watchKids(); schedule(); });
|
|
87
|
+
mo.observe(el, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ['tabindex', 'disabled', 'hidden', 'inert', 'href'] });
|
|
88
|
+
watchKids();
|
|
89
|
+
measure();
|
|
90
|
+
return () => { ro?.disconnect(); mo.disconnect(); clear(); };
|
|
91
|
+
};
|
|
92
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruckc/truss-chat",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.52.0",
|
|
4
4
|
"description": "Chat building blocks for Truss UI: thread, messages, tool calls, composer, status line and a question form",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@ruckc/truss-ui": "^1.0.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@ruckc/truss-markdown": "^1.
|
|
30
|
+
"@ruckc/truss-markdown": "^1.52.0"
|
|
31
31
|
},
|
|
32
32
|
"author": "Curtis Ruck",
|
|
33
33
|
"homepage": "https://truss.ruck.io",
|