@diegopluna/narvi 0.3.7 → 0.3.8

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.
@@ -5,12 +5,14 @@
5
5
  -->
6
6
  <script lang="ts" module>
7
7
  import * as stylex from '@stylexjs/stylex';
8
- import type { Snippet } from 'svelte';
8
+ import { untrack, type Snippet } from 'svelte';
9
9
  import type { HTMLAttributes } from 'svelte/elements';
10
10
  import { emphasis, KIND_GLYPHS, type ActionKind } from '../../internal/kinds.js';
11
11
  import { attrs, type Sx } from '../../internal/sx.js';
12
+ import { getFoldShown } from '../../internal/fold-shown.js';
12
13
  import Tile from '../../internal/Tile.svelte';
13
14
  import { colors, font, radius } from '../../tokens.stylex.js';
15
+ import Button from '../button/Button.svelte';
14
16
  import Spinner from '../spinner/Spinner.svelte';
15
17
 
16
18
  export type ActivityStepKind = ActionKind;
@@ -24,6 +26,14 @@
24
26
 
25
27
  type Badged = 'failed' | 'declined' | 'blocked' | 'neutral';
26
28
 
29
+ /** Words for the control under a long output. */
30
+ export type ActivityStepOutputLabels = {
31
+ /** "Show all output" by default. */
32
+ showAll?: string | undefined;
33
+ /** "Show less" by default. */
34
+ showLess?: string | undefined;
35
+ };
36
+
27
37
  export type ActivityStepProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> & {
28
38
  kind?: ActivityStepKind | undefined;
29
39
  /** The command, the path, the query: shown as code. Cut to one line, unless `wrap`. */
@@ -37,6 +47,14 @@
37
47
  output?: string | undefined;
38
48
  /** How much of the output to keep, from the end, in characters. */
39
49
  tail?: number | undefined;
50
+ /**
51
+ * Shows all of an output longer than `tail`, not only its end. A control under the output
52
+ * turns it on and off. Bindable: keep it where the conversation is drawn again, or set it
53
+ * when a find of your own finds something in the part cut off.
54
+ */
55
+ showAll?: boolean | undefined;
56
+ /** Words for that control. */
57
+ outputLabels?: ActivityStepOutputLabels | undefined;
40
58
  /** Words for the statuses that need them. */
41
59
  statusLabels?: Partial<Record<Badged, string>> | undefined;
42
60
  /** Anything else: images, a diff. */
@@ -107,6 +125,7 @@
107
125
  minWidth: 0
108
126
  },
109
127
  reason: { margin: 0, color: colors.textMuted, fontSize: font.sizeMeta },
128
+ more: { alignSelf: 'flex-start' },
110
129
  output: {
111
130
  margin: 0,
112
131
  maxHeight: '10rem',
@@ -134,6 +153,8 @@
134
153
  reason,
135
154
  output,
136
155
  tail = 4000,
156
+ showAll = $bindable(false),
157
+ outputLabels,
137
158
  statusLabels,
138
159
  wrap = false,
139
160
  children,
@@ -142,20 +163,60 @@
142
163
  ...rest
143
164
  }: ActivityStepProps = $props();
144
165
 
145
- const shown = $derived(output && output.length > tail ? `…${output.slice(-tail)}` : output);
166
+ const cut = $derived(output !== undefined && output.length > tail);
167
+ const shown = $derived(cut && !showAll ? `…${output!.slice(-tail)}` : output);
146
168
  const parts = $derived(emphasis(kind, label));
147
169
  const bad = $derived(status === 'failed' || status === 'declined' || status === 'blocked');
148
170
  const badged = $derived(bad || status === 'neutral');
171
+ const uid = $props.id();
172
+ const outputId = `${uid}-output`;
173
+
174
+ // Long output opens at its end, where the result is, and stays there as more is printed,
175
+ // unless the reader has scrolled up to read. Its box is measured only while it is shown: not
176
+ // in a shut fold, whose content is never laid out just to be read, and not before it has a
177
+ // size, as in a tab or a thread out of sight. Shown again, it goes back to the end.
178
+ const foldShown = getFoldShown();
179
+ let box = $state<HTMLPreElement | null>(null);
180
+ let atEnd = true;
181
+ const showing = (element: HTMLElement) => untrack(foldShown) && element.clientHeight > 0;
182
+
183
+ function end() {
184
+ if (box && atEnd && showing(box)) box.scrollTop = box.scrollHeight;
185
+ }
186
+
187
+ $effect(() => {
188
+ if (box && foldShown()) untrack(end);
189
+ });
190
+
191
+ function follow(element: HTMLPreElement) {
192
+ const scrolled = () => {
193
+ // A box out of sight scrolls nowhere: that is not the reader leaving the end
194
+ if (!showing(element)) return;
195
+ atEnd = element.scrollHeight - element.clientHeight - element.scrollTop < 2;
196
+ };
197
+ element.addEventListener('scroll', scrolled, { passive: true });
198
+ const resized = new ResizeObserver(end);
199
+ resized.observe(element);
200
+ const printed = new MutationObserver(end);
201
+ printed.observe(element, { characterData: true, childList: true, subtree: true });
202
+ return () => {
203
+ element.removeEventListener('scroll', scrolled);
204
+ resized.disconnect();
205
+ printed.disconnect();
206
+ };
207
+ }
149
208
 
150
- // Long output opens at its end, where the result is
151
- function toEnd(element: HTMLElement) {
152
- element.scrollTop = element.scrollHeight;
209
+ // All of it, or its end again, with the end in view either way
210
+ function toggleAll() {
211
+ atEnd = true;
212
+ showAll = !showAll;
153
213
  }
154
214
  </script>
155
215
 
156
216
  <div
157
217
  data-slot="activity-step"
158
218
  data-status={status}
219
+ data-output-cut={(cut && !showAll) || undefined}
159
220
  {...rest}
160
221
  {...attrs([styles.step, sx], className)}
161
222
  >
@@ -183,7 +244,26 @@
183
244
  {#if reason}<p {...stylex.attrs(styles.reason)}>{reason}</p>{/if}
184
245
  {#if shown}
185
246
  <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
186
- <pre tabindex="0" {...stylex.attrs(styles.output)} {@attach toEnd}>{shown}</pre>
247
+ <pre
248
+ bind:this={box}
249
+ id={outputId}
250
+ tabindex="0"
251
+ {...stylex.attrs(styles.output)}
252
+ {@attach follow}>{shown}</pre>
253
+ {#if cut}
254
+ <Button
255
+ variant="link"
256
+ size="xs"
257
+ sx={styles.more}
258
+ aria-expanded={showAll}
259
+ aria-controls={outputId}
260
+ data-activity-step-toggle
261
+ onclick={toggleAll}
262
+ >{showAll
263
+ ? (outputLabels?.showLess ?? 'Show less')
264
+ : (outputLabels?.showAll ?? 'Show all output')}</Button
265
+ >
266
+ {/if}
187
267
  {/if}
188
268
  {@render children?.()}
189
269
  </div>
@@ -1,4 +1,4 @@
1
- import type { Snippet } from 'svelte';
1
+ import { type Snippet } from 'svelte';
2
2
  import type { HTMLAttributes } from 'svelte/elements';
3
3
  import { type ActionKind } from '../../internal/kinds.js';
4
4
  import { type Sx } from '../../internal/sx.js';
@@ -10,6 +10,13 @@ export type ActivityStepKind = ActionKind;
10
10
  */
11
11
  export type ActivityStepStatus = 'running' | 'done' | 'failed' | 'declined' | 'blocked' | 'neutral';
12
12
  type Badged = 'failed' | 'declined' | 'blocked' | 'neutral';
13
+ /** Words for the control under a long output. */
14
+ export type ActivityStepOutputLabels = {
15
+ /** "Show all output" by default. */
16
+ showAll?: string | undefined;
17
+ /** "Show less" by default. */
18
+ showLess?: string | undefined;
19
+ };
13
20
  export type ActivityStepProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> & {
14
21
  kind?: ActivityStepKind | undefined;
15
22
  /** The command, the path, the query: shown as code. Cut to one line, unless `wrap`. */
@@ -23,6 +30,14 @@ export type ActivityStepProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'
23
30
  output?: string | undefined;
24
31
  /** How much of the output to keep, from the end, in characters. */
25
32
  tail?: number | undefined;
33
+ /**
34
+ * Shows all of an output longer than `tail`, not only its end. A control under the output
35
+ * turns it on and off. Bindable: keep it where the conversation is drawn again, or set it
36
+ * when a find of your own finds something in the part cut off.
37
+ */
38
+ showAll?: boolean | undefined;
39
+ /** Words for that control. */
40
+ outputLabels?: ActivityStepOutputLabels | undefined;
26
41
  /** Words for the statuses that need them. */
27
42
  statusLabels?: Partial<Record<Badged, string>> | undefined;
28
43
  /** Anything else: images, a diff. */
@@ -30,6 +45,6 @@ export type ActivityStepProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'
30
45
  sx?: Sx | undefined;
31
46
  class?: string | undefined;
32
47
  };
33
- declare const ActivityStep: import("svelte").Component<ActivityStepProps, {}, "">;
48
+ declare const ActivityStep: import("svelte").Component<ActivityStepProps, {}, "showAll">;
34
49
  type ActivityStep = ReturnType<typeof ActivityStep>;
35
50
  export default ActivityStep;
@@ -8,6 +8,6 @@ export { Root, Trigger, Content, Step, Thought, Icon };
8
8
  export type { ActivityContentProps } from './ActivityContent.svelte';
9
9
  export type { ActivityIconProps, ActivityIconTone } from './ActivityIcon.svelte';
10
10
  export type { ActivityRootProps } from './ActivityRoot.svelte';
11
- export type { ActivityStepKind, ActivityStepProps, ActivityStepStatus } from './ActivityStep.svelte';
11
+ export type { ActivityStepKind, ActivityStepOutputLabels, ActivityStepProps, ActivityStepStatus } from './ActivityStep.svelte';
12
12
  export type { ActivityThoughtProps } from './ActivityThought.svelte';
13
13
  export type { ActivityTriggerProps } from './ActivityTrigger.svelte';
@@ -1,9 +1,9 @@
1
1
  <script lang="ts" module>
2
2
  import * as stylex from '@stylexjs/stylex';
3
- import type { Snippet } from 'svelte';
3
+ import { untrack, type Snippet } from 'svelte';
4
4
  import type { HTMLAttributes } from 'svelte/elements';
5
5
  import { attrs, type Sx } from '../../internal/sx.js';
6
- import { getAppShellSheetContext } from './context.js';
6
+ import { getAppShellContext, getAppShellSheetContext } from './context.js';
7
7
 
8
8
  export type AppShellMainProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
9
9
  sx?: Sx | undefined;
@@ -27,19 +27,79 @@
27
27
  // scroll and what is typed in it are as they were when the panel is restored
28
28
  covered: { visibility: 'hidden' }
29
29
  });
30
+
31
+ // `motion.slow` and `motion.easeInOut`, as the sidebar's column slides with
32
+ const GLIDE: KeyframeAnimationOptions = {
33
+ duration: 200,
34
+ easing: 'cubic-bezier(0.77, 0, 0.175, 1)',
35
+ id: 'narvi-glide'
36
+ };
37
+
38
+ /**
39
+ * The sidebar beside the page shows or hides at once, so the page is laid out once at its
40
+ * new width rather than on every frame. What is under the page's header then glides from
41
+ * where its centre was to where it is, by half the sidebar's width: a conversation down
42
+ * the middle moves as it would if the page were widening, while the sidebar slides over
43
+ * the edge. The header takes its place at once: its start is under the sidebar as it
44
+ * comes or goes, and its end does not move. So does a panel in a row of the page's own,
45
+ * with its edge: only what is beside it glides.
46
+ */
47
+ function glide(main: HTMLElement, sidebar: HTMLElement, open: boolean) {
48
+ if (!matchMedia('(prefers-reduced-motion: no-preference)').matches) return;
49
+ const width = sidebar.firstElementChild?.getBoundingClientRect().width ?? 0;
50
+ if (width === 0) return;
51
+ const rtl = getComputedStyle(main).direction === 'rtl';
52
+ const shift = ((open ? -1 : 1) * (rtl ? -1 : 1) * width) / 2;
53
+ for (const child of gliders(main)) {
54
+ // Shown again before the last glide has ended: from wherever it has got to
55
+ const gliding = child.getAnimations().filter((animation) => animation.id === GLIDE.id);
56
+ const from = gliding.length > 0 ? parseFloat(getComputedStyle(child).translate) || 0 : 0;
57
+ for (const animation of gliding) animation.cancel();
58
+ child.animate([{ translate: `${from + shift}px 0` }, { translate: '0 0' }], GLIDE);
59
+ }
60
+ }
61
+
62
+ const STAYS = new Set(['app-shell-header', 'app-shell-panel', 'resize-handle']);
63
+
64
+ // What glides: the page's parts under its header, and in a row that holds a panel, the
65
+ // parts beside the panel
66
+ function gliders(parent: Element): HTMLElement[] {
67
+ return [...parent.children].flatMap((child) => {
68
+ if (!(child instanceof HTMLElement) || STAYS.has(child.dataset.slot ?? '')) return [];
69
+ return child.querySelector('[data-slot="app-shell-panel"]') ? gliders(child) : [child];
70
+ });
71
+ }
30
72
  </script>
31
73
 
32
74
  <script lang="ts">
33
75
  let { sx, class: className, children, ...rest }: AppShellMainProps = $props();
34
76
 
77
+ const shell = getAppShellContext();
35
78
  const sheet = getAppShellSheetContext();
36
79
  const covered = $derived(sheet?.covered ?? false);
80
+ let element = $state<HTMLElement | null>(null);
81
+
82
+ // Each time the sidebar beside this page shows or hides; not when a narrow window makes it
83
+ // a drawer over the page, or takes it back
84
+ let last: { open: boolean; narrow: boolean } | undefined;
85
+ $effect(() => {
86
+ if (!shell || !element) return;
87
+ const now = { open: shell.open, narrow: shell.narrow };
88
+ const before = last;
89
+ last = now;
90
+ if (!before || before.narrow || now.narrow || before.open === now.open) return;
91
+ const sidebar = element.parentElement?.querySelector<HTMLElement>(
92
+ ':scope > [data-slot="app-shell-sidebar"]'
93
+ );
94
+ if (sidebar) untrack(() => glide(element!, sidebar, now.open));
95
+ });
37
96
  </script>
38
97
 
39
98
  <!-- Not focusable by default: with `tabindex="-1"` a click on plain text in the page would move
40
99
  focus to the whole of it, away from a panel that keeps its own, such as a find bar. Pass a
41
100
  `tabindex` to make it the target of a skip link. -->
42
101
  <main
102
+ bind:this={element}
43
103
  data-slot="app-shell-main"
44
104
  inert={covered || undefined}
45
105
  {...rest}
@@ -1,4 +1,4 @@
1
- import type { Snippet } from 'svelte';
1
+ import { type Snippet } from 'svelte';
2
2
  import type { HTMLAttributes } from 'svelte/elements';
3
3
  import { type Sx } from '../../internal/sx.js';
4
4
  export type AppShellMainProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
@@ -33,13 +33,13 @@
33
33
  overflow: 'clip',
34
34
  color: colors.text
35
35
  },
36
+ // Beside the page, its room is given or taken back at once, and it is the column that
37
+ // moves: it slides on a transform, over the page, so the page is laid out once for each
38
+ // show or hide rather than on every frame of the slide. The column overflows the room
39
+ // it no longer has while it slides away, and the sheet clips it.
36
40
  wide: {
37
41
  width: 'var(--narvi-sidebar-width)',
38
- // A flush sheet gives it the page's colour; on a sheet with an edge it has none
39
- backgroundColor: 'var(--narvi-sidebar-surface, transparent)',
40
- transitionProperty: { default: 'none', [media.motion]: 'width' },
41
- transitionDuration: motion.slow,
42
- transitionTimingFunction: motion.easeInOut
42
+ overflow: 'visible'
43
43
  },
44
44
  collapsed: { width: 0 },
45
45
  // Narrow: a drawer over the page, from the start edge, after the rail
@@ -78,9 +78,9 @@
78
78
  transitionDuration: motion.slow,
79
79
  transitionTimingFunction: motion.easeOut
80
80
  },
81
- // The column keeps its width while the sidebar narrows, so its rows are clipped
82
- // rather than squeezed and reflowed on every frame. The hairline that divides it
83
- // from the page is on the column, so it goes when the sidebar does.
81
+ // The column keeps its width whatever room the sidebar has, so its rows are never
82
+ // squeezed or reflowed. The hairline that divides it from the page is on the column,
83
+ // so it goes when the sidebar does.
84
84
  column: {
85
85
  boxSizing: 'border-box',
86
86
  display: 'flex',
@@ -92,7 +92,22 @@
92
92
  borderInlineEndStyle: 'solid',
93
93
  borderInlineEndColor: colors.border
94
94
  },
95
- columnDrawer: { width: '100%', borderInlineEndWidth: 0 }
95
+ columnDrawer: { width: '100%', borderInlineEndWidth: 0 },
96
+ // It slides over the page, so it is never see-through: a flush sheet gives it the page's
97
+ // colour, and a sheet with an edge its own
98
+ columnWide: {
99
+ backgroundColor: `var(--narvi-sidebar-surface, ${colors.bgRaised})`,
100
+ // Shown at once when it opens, hidden only once it has slid away
101
+ transitionProperty: { default: 'visibility', [media.motion]: 'translate, visibility' },
102
+ transitionDuration: { default: '0s', [media.motion]: `${motion.slow}, 0s` },
103
+ transitionDelay: { default: '0s', [media.motion]: '0s, 0s' },
104
+ transitionTimingFunction: motion.easeInOut
105
+ },
106
+ columnAway: {
107
+ translate: { default: '-100% 0', ':dir(rtl)': '100% 0' },
108
+ visibility: 'hidden',
109
+ transitionDelay: { default: '0s', [media.motion]: `0s, ${motion.slow}` }
110
+ }
96
111
  });
97
112
  </script>
98
113
 
@@ -162,7 +177,12 @@
162
177
  className
163
178
  )}
164
179
  >
165
- <div {...stylex.attrs(styles.column, shell.narrow && styles.columnDrawer)}>
180
+ <div
181
+ {...stylex.attrs(
182
+ styles.column,
183
+ shell.narrow ? styles.columnDrawer : [styles.columnWide, !shell.open && styles.columnAway]
184
+ )}
185
+ >
166
186
  {@render children?.()}
167
187
  </div>
168
188
  </aside>
@@ -25,7 +25,8 @@
25
25
  import * as stylex from '@stylexjs/stylex';
26
26
  import { attrs, classes, type Sx } from '../../internal/sx.js';
27
27
  import { media } from '../../media.stylex.js';
28
- import { colors } from '../../tokens.stylex.js';
28
+ import { colors, play } from '../../tokens.stylex.js';
29
+ import { whileVisible } from '../../internal/visible.js';
29
30
  import { resolvePlugins, setMarkdownContext, type MarkdownContext } from './context.js';
30
31
  import MarkdownBlocks from './MarkdownBlocks.svelte';
31
32
  import MarkdownFootnotes from './MarkdownFootnotes.svelte';
@@ -134,7 +135,9 @@
134
135
  WebkitUserSelect: 'none',
135
136
  animationName: { default: null, [media.motion]: blink },
136
137
  animationDuration: '1.1s',
137
- animationIterationCount: 'infinite'
138
+ animationIterationCount: 'infinite',
139
+ // It blinks only while it can be seen
140
+ animationPlayState: play.whileVisible
138
141
  },
139
142
  block: { boxShadow: '0.36em 0 0 0.28em currentColor', borderRadius: '1px' },
140
143
  circle: {
@@ -556,10 +559,16 @@
556
559
 
557
560
  // The caret is one element, put at the end of the text after each update (see `caret.ts`)
558
561
  let caretElement: HTMLSpanElement | null = null;
562
+ let stopWatchingCaret: (() => void) | void = undefined;
563
+ const removeCaret = () => {
564
+ caretElement?.remove();
565
+ stopWatchingCaret?.();
566
+ stopWatchingCaret = undefined;
567
+ };
559
568
  $effect(() => {
560
569
  if (!root) return;
561
570
  if (!streaming || !caret) {
562
- caretElement?.remove();
571
+ removeCaret();
563
572
  return;
564
573
  }
565
574
  // Read, so that this runs again after every change to what is drawn
@@ -573,8 +582,9 @@
573
582
  }
574
583
  caretElement.className = caret === 'circle' ? caretClasses.circle : caretClasses.block;
575
584
  placeCaret(root, caretElement);
585
+ stopWatchingCaret ??= whileVisible(caretElement);
576
586
  });
577
- $effect(() => () => caretElement?.remove());
587
+ $effect(() => removeCaret);
578
588
 
579
589
  let mounted = false;
580
590
  $effect(() => {
@@ -173,7 +173,8 @@
173
173
  <span {...stylex.attrs(styles.grow)}></span>
174
174
  {#if trailing}<span {...stylex.attrs(styles.trail)}>{@render trailing()}</span>{/if}
175
175
  </button>
176
- <Collapse open={shown} id="{uid}-rows">
176
+ <!-- Built while shut: a current row in it holds it open, and has to be there to -->
177
+ <Collapse open={shown} lazy={false} id="{uid}-rows">
177
178
  <ul aria-label={label} {...stylex.attrs(styles.list)}>{@render children?.()}</ul>
178
179
  </Collapse>
179
180
  </li>
@@ -163,7 +163,8 @@
163
163
  </div>
164
164
  {/if}
165
165
  {#if collapsible && label}
166
- <Collapse open={shown} id="{uid}-list">
166
+ <!-- Built while shut: a current row in it holds it open, and has to be there to -->
167
+ <Collapse open={shown} lazy={false} id="{uid}-list">
167
168
  <ul {...listName} {...stylex.attrs(styles.list)}>{@render children?.()}</ul>
168
169
  </Collapse>
169
170
  {:else}
@@ -4,6 +4,12 @@
4
4
  end steps aside for them. Its fills (under the pointer, open, picked) lie on a
5
5
  layer of their own, over the row's background, so a background given in `sx`
6
6
  is the row's resting fill and the fills still show over it.
7
+
8
+ A row out of sight is not laid out or painted (`content-visibility: auto`), so a
9
+ list of a thousand threads costs what the dozen in view do. It keeps the size it
10
+ was last drawn at, or a row's of one or two lines until then, so the scrollbar
11
+ does not jump. Nothing it draws reaches past its box, focus rings included, so
12
+ the containment never clips them and never has to come off.
7
13
  -->
8
14
  <script lang="ts" module>
9
15
  import * as stylex from '@stylexjs/stylex';
@@ -75,7 +81,15 @@
75
81
  ':is([data-state="open"], :has([data-slot="sidebar-item-actions"] [aria-expanded="true"]))';
76
82
 
77
83
  const styles = stylex.create({
78
- item: { position: 'relative', listStyleType: 'none' },
84
+ item: {
85
+ position: 'relative',
86
+ listStyleType: 'none',
87
+ contentVisibility: 'auto',
88
+ // Two lines: 50px
89
+ containIntrinsicSize: 'auto 3.125rem'
90
+ },
91
+ // One line: 30px
92
+ itemOneLine: { containIntrinsicSize: 'auto 1.875rem' },
79
93
  // Its group or folder is folded, and this is not the open row
80
94
  foldedAway: { display: 'none' },
81
95
  row: {
@@ -187,9 +201,11 @@
187
201
  trailHides: {
188
202
  opacity: {
189
203
  default: 1,
204
+ // Repeated inside: the media query outranks a condition outside it
190
205
  [media.hover]: {
191
206
  default: 1,
192
207
  [stylex.when.ancestor(':hover', sidebarItemMarker)]: 0,
208
+ [stylex.when.ancestor(':focus-within', sidebarItemMarker)]: 0,
193
209
  [stylex.when.ancestor(OPEN, sidebarItemMarker)]: 0
194
210
  },
195
211
  [stylex.when.ancestor(':focus-within', sidebarItemMarker)]: 0,
@@ -213,7 +229,9 @@
213
229
  },
214
230
  // The tray sits 1px inside the row, so its radius is the row's less 1px. Narvi's small
215
231
  // buttons reach past their own edges to be easy to hit; here that would reach into the
216
- // rows above and below, so the tray clips them, and shows the focus ring itself.
232
+ // rows above and below, so the tray clips them, and shows the focus ring itself: over
233
+ // its hairline and out to the row's edge, no further, so the row's containment never
234
+ // clips it.
217
235
  actions: {
218
236
  position: 'absolute',
219
237
  top: '1px',
@@ -227,12 +245,15 @@
227
245
  outlineStyle: 'solid',
228
246
  outlineWidth: { default: 0, ':focus-within': '2px' },
229
247
  outlineColor: colors.focusRing,
230
- outlineOffset: '1px',
248
+ outlineOffset: '-1px',
231
249
  opacity: {
232
250
  default: 1,
251
+ // Repeated inside: the media query outranks a condition outside it, and keyboard
252
+ // focus on a computer with a mouse would show no actions
233
253
  [media.hover]: {
234
254
  default: 0,
235
255
  [stylex.when.ancestor(':hover', sidebarItemMarker)]: 1,
256
+ [stylex.when.ancestor(':focus-within', sidebarItemMarker)]: 1,
236
257
  [stylex.when.ancestor(OPEN, sidebarItemMarker)]: 1
237
258
  },
238
259
  [stylex.when.ancestor(':focus-within', sidebarItemMarker)]: 1,
@@ -243,6 +264,7 @@
243
264
  [media.hover]: {
244
265
  default: 'none',
245
266
  [stylex.when.ancestor(':hover', sidebarItemMarker)]: 'auto',
267
+ [stylex.when.ancestor(':focus-within', sidebarItemMarker)]: 'auto',
246
268
  [stylex.when.ancestor(OPEN, sidebarItemMarker)]: 'auto'
247
269
  },
248
270
  [stylex.when.ancestor(':focus-within', sidebarItemMarker)]: 'auto',
@@ -332,7 +354,15 @@
332
354
  style:--narvi-sidebar-depth={depth || undefined}
333
355
  {...itemProps}
334
356
  data-slot="sidebar-item"
335
- {...attrs([styles.item, away && styles.foldedAway, sidebarItemMarker], itemProps?.class)}
357
+ {...attrs(
358
+ [
359
+ styles.item,
360
+ (compact || !meta) && styles.itemOneLine,
361
+ away && styles.foldedAway,
362
+ sidebarItemMarker
363
+ ],
364
+ itemProps?.class
365
+ )}
336
366
  >
337
367
  {#if href !== undefined}
338
368
  <a
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export * as AppShell from './components/app-shell/index.js';
4
4
  export { getAppShellContext } from './components/app-shell/index.js';
5
5
  export type { AppShellBarProps, AppShellContext, AppShellHeaderProps, AppShellMainProps, AppShellPanelProps, AppShellPanesProps, AppShellRailProps, AppShellRootProps, AppShellSheetProps, AppShellSidebarProps, AppShellToggleProps } from './components/app-shell/index.js';
6
6
  export * as Activity from './components/activity/index.js';
7
- export type { ActivityContentProps, ActivityIconProps, ActivityIconTone, ActivityRootProps, ActivityStepKind, ActivityStepProps, ActivityStepStatus, ActivityThoughtProps, ActivityTriggerProps } from './components/activity/index.js';
7
+ export type { ActivityContentProps, ActivityIconProps, ActivityIconTone, ActivityRootProps, ActivityStepKind, ActivityStepOutputLabels, ActivityStepProps, ActivityStepStatus, ActivityThoughtProps, ActivityTriggerProps } from './components/activity/index.js';
8
8
  export { default as Announcer } from './components/announcer/Announcer.svelte';
9
9
  export type { AnnouncerProps } from './components/announcer/Announcer.svelte';
10
10
  export * as Avatar from './components/avatar/index.js';
@@ -164,7 +164,7 @@ export { default as Theme } from './components/theme/Theme.svelte';
164
164
  export type { ThemeOverrides, ThemeProps, ThemeScheme } from './components/theme/Theme.svelte';
165
165
  export { default as WorkFold } from './components/work-fold/WorkFold.svelte';
166
166
  export type { WorkFoldProps } from './components/work-fold/WorkFold.svelte';
167
- export { whileVisible } from './internal/visible.js';
167
+ export { setPageHidden, whileVisible } from './internal/visible.js';
168
168
  export { resolveColor, resolveRgba } from './color.js';
169
169
  export type { ResolveColorOptions, Rgba } from './color.js';
170
170
  export { classes, sx } from './internal/sx.js';
package/dist/index.js CHANGED
@@ -123,8 +123,9 @@ export { default as Theme } from './components/theme/Theme.svelte';
123
123
  export { default as WorkFold } from './components/work-fold/WorkFold.svelte';
124
124
  // For an animation of your own that never ends: `whileVisible` runs it only while it can be
125
125
  // seen, with `animationPlayState: play.whileVisible` from the tokens. Spinner, Shimmer,
126
- // Skeleton and Progress use it.
127
- export { whileVisible } from './internal/visible.js';
126
+ // Skeleton, Progress and Markdown's caret use it. `setPageHidden` is the host's word that the
127
+ // page is out of sight where the document cannot tell, such as a minimized Electron window.
128
+ export { setPageHidden, whileVisible } from './internal/visible.js';
128
129
  // The colour a token paints as, for a <canvas>, WebGL or a chart library, which
129
130
  // cannot read `var()` or `light-dark()` themselves.
130
131
  export { resolveColor, resolveRgba } from './color.js';
@@ -12,6 +12,7 @@
12
12
  import { attrs, type Sx } from './sx.js';
13
13
  import { motion } from '../tokens.stylex.js';
14
14
  import { media } from '../media.stylex.js';
15
+ import { getFoldShown, setFoldShown } from './fold-shown.js';
15
16
 
16
17
  const styles = stylex.create({
17
18
  region: {
@@ -47,6 +48,7 @@
47
48
  <script lang="ts">
48
49
  let {
49
50
  open,
51
+ lazy = true,
50
52
  sx,
51
53
  innerSx,
52
54
  innerClass,
@@ -55,17 +57,30 @@
55
57
  ...rest
56
58
  }: Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
57
59
  open: boolean;
60
+ /** Builds the content the first time it opens. Off, it is built while shut too. */
61
+ lazy?: boolean | undefined;
58
62
  sx?: Sx | undefined;
59
63
  innerSx?: Sx | undefined;
60
64
  innerClass?: ClassValue | null | undefined;
61
65
  children?: Snippet | undefined;
62
66
  } = $props();
67
+
68
+ // What is inside is shown while this is open and every fold around it is
69
+ const outerShown = getFoldShown();
70
+ setFoldShown(() => open && outerShown());
71
+
72
+ // Once open, it stays built. A plain variable: it only ever turns true, and only with `open`.
73
+ let opened = false;
74
+ const built = $derived.by(() => {
75
+ if (open) opened = true;
76
+ return opened || !lazy;
77
+ });
63
78
  </script>
64
79
 
65
80
  <div inert={!open} {...rest} {...attrs([styles.region, open && styles.open, sx], className)}>
66
81
  <div {...stylex.attrs(styles.inner, open && styles.innerOpen)}>
67
82
  <div {...attrs([innerSx], innerClass)}>
68
- {@render children?.()}
83
+ {#if built}{@render children?.()}{/if}
69
84
  </div>
70
85
  </div>
71
86
  </div>
@@ -3,6 +3,8 @@ import type { ClassValue, HTMLAttributes } from 'svelte/elements';
3
3
  import { type Sx } from './sx.js';
4
4
  type $$ComponentProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
5
5
  open: boolean;
6
+ /** Builds the content the first time it opens. Off, it is built while shut too. */
7
+ lazy?: boolean | undefined;
6
8
  sx?: Sx | undefined;
7
9
  innerSx?: Sx | undefined;
8
10
  innerClass?: ClassValue | null | undefined;
@@ -0,0 +1,3 @@
1
+ /** True outside any fold. Reactive where it is read in an effect or a template. */
2
+ export declare function getFoldShown(): () => boolean;
3
+ export declare function setFoldShown(shown: () => boolean): void;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Whether what is inside a fold is shown: open, in every fold around it. A part that reads its
3
+ * own size, such as a step's output scrolling to its end, reads it only while this is true, so
4
+ * a shut fold's content is never laid out just to be measured.
5
+ */
6
+ import { getContext, setContext } from 'svelte';
7
+ const KEY = Symbol('narvi.fold-shown');
8
+ /** True outside any fold. Reactive where it is read in an effect or a template. */
9
+ export function getFoldShown() {
10
+ return getContext(KEY) ?? (() => true);
11
+ }
12
+ export function setFoldShown(shown) {
13
+ setContext(KEY, shown);
14
+ }
@@ -5,7 +5,13 @@
5
5
  * screens up the conversation, or in a window behind another, is paid for and
6
6
  * never looked at. So every one of Narvi's reads its play state from a custom
7
7
  * property, and this sets that property: running while the element is in the
8
- * viewport and the document is showing, paused otherwise.
8
+ * viewport and the page is showing, paused otherwise.
9
+ *
10
+ * The page is showing unless the document says it is hidden or the host does. A
11
+ * desktop app that keeps its window running in the background, such as an Electron
12
+ * one with background throttling off, is never hidden to the document: minimized or
13
+ * closed to the tray, it still counts as showing. The host knows better, and says so
14
+ * with `setPageHidden`.
9
15
  *
10
16
  * The animations themselves are stepped (`steps(30)` over two seconds, say), so
11
17
  * the compositor draws a handful of frames a second, not one for every refresh
@@ -29,4 +35,21 @@
29
35
  * ```
30
36
  */
31
37
  import type { Attachment } from 'svelte/attachments';
38
+ /**
39
+ * Tells Narvi whether the host has hidden the page, where the document cannot tell: an
40
+ * Electron window minimized or closed to the tray with background throttling off, a view
41
+ * kept alive out of sight. While it is hidden, every animation that never ends pauses: the
42
+ * spinners, shimmers, skeletons, progress bars and carets, and your own that use
43
+ * `whileVisible`. They run again once it is shown, where they can be seen.
44
+ *
45
+ * ```ts
46
+ * import { setPageHidden } from '@diegopluna/narvi';
47
+ *
48
+ * // However the host tells the page: here, a bridge from an Electron preload script
49
+ * bridge.onWindowAway((away) => setPageHidden(away));
50
+ * ```
51
+ *
52
+ * The document's own `hidden` still counts: this only adds to it.
53
+ */
54
+ export declare function setPageHidden(hidden: boolean): void;
32
55
  export declare const whileVisible: Attachment<HTMLElement | SVGElement>;
@@ -1,13 +1,37 @@
1
1
  const watched = new Map();
2
2
  let observer = null;
3
+ // Hidden by the host's word, whatever the document says
4
+ let hiddenByHost = false;
3
5
  function apply(item) {
4
- const running = item.inView && !document.hidden;
6
+ const running = item.inView && !document.hidden && !hiddenByHost;
5
7
  item.element.style.setProperty('--narvi-play', running ? 'running' : 'paused');
6
8
  }
7
9
  function applyAll() {
8
10
  for (const item of watched.values())
9
11
  apply(item);
10
12
  }
13
+ /**
14
+ * Tells Narvi whether the host has hidden the page, where the document cannot tell: an
15
+ * Electron window minimized or closed to the tray with background throttling off, a view
16
+ * kept alive out of sight. While it is hidden, every animation that never ends pauses: the
17
+ * spinners, shimmers, skeletons, progress bars and carets, and your own that use
18
+ * `whileVisible`. They run again once it is shown, where they can be seen.
19
+ *
20
+ * ```ts
21
+ * import { setPageHidden } from '@diegopluna/narvi';
22
+ *
23
+ * // However the host tells the page: here, a bridge from an Electron preload script
24
+ * bridge.onWindowAway((away) => setPageHidden(away));
25
+ * ```
26
+ *
27
+ * The document's own `hidden` still counts: this only adds to it.
28
+ */
29
+ export function setPageHidden(hidden) {
30
+ if (hiddenByHost === hidden)
31
+ return;
32
+ hiddenByHost = hidden;
33
+ applyAll();
34
+ }
11
35
  export const whileVisible = (element) => {
12
36
  // Nothing to watch with: leave the animation running, as it would without this
13
37
  if (typeof IntersectionObserver === 'undefined')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diegopluna/narvi",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "packageManager": "pnpm@12.18.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -12,7 +12,7 @@ metadata:
12
12
  Grid, and Narvi's conventions for colour, labels and copy.
13
13
  type: core
14
14
  library: '@diegopluna/narvi'
15
- library_version: '0.3.7'
15
+ library_version: '0.3.8'
16
16
  requires:
17
17
  - setup
18
18
  sources:
@@ -34,7 +34,7 @@ sources:
34
34
  - src/lib/components/dialog/DialogContent.svelte
35
35
  - src/lib/components/tab-strip/TabStrip.svelte
36
36
  - src/lib/components/split-button/SplitButton.svelte
37
- - src/lib/components/app-shell/AppShellPanel.svelte
37
+ - src/lib/components/app-shell/*.svelte
38
38
  - src/lib/components/composer/ComposerModelPicker.svelte
39
39
  - src/lib/components/questionnaire/Questionnaire.svelte
40
40
  - src/lib/components/button/Button.svelte
@@ -166,6 +166,12 @@ toggle in the sidebar's head and one with `when="closed"` in the page's header,
166
166
  while the sidebar is away. `windowInset` then clears the traffic lights in whichever head is
167
167
  first. Don't use a rail without a bar in a window that has traffic lights: they are wider than it.
168
168
 
169
+ A `Sidebar.Item` out of sight is not laid out or painted (`content-visibility: auto`): it keeps
170
+ the size it was last drawn at, or 30px for one line and 50px for two until then. Nothing it draws
171
+ reaches past its box, its actions' focus ring included. Don't add containment of your own through
172
+ `itemProps`, don't turn it off while a row has focus, and don't virtualise a list of rows to save
173
+ their drawing: they are already skipped, and stay in the accessibility tree and the page's find.
174
+
169
175
  ```svelte
170
176
  <AppShell.Root bind:sidebarOpen windowInset="5.25rem">
171
177
  <AppShell.Sheet flush>
@@ -189,6 +195,11 @@ inert, and with `hideCovered` hides them too (still laid out, so their scroll is
189
195
  come back as they were. `edgeLabel` names its resize edge for assistive technology ("Resize
190
196
  panel"), and `edgeTitle` gives the edge a tooltip ("Drag to resize, double-click to reset").
191
197
 
198
+ The sidebar beside the page gives or takes its room at once and slides on a transform, so the
199
+ page is laid out once per show or hide. What is under `AppShell.Header` glides on `translate`
200
+ for 200ms; the header, the panel and its edge take their places at once. Don't animate the
201
+ sidebar's width yourself, and don't put a `translate` of your own on `AppShell.Main`'s children.
202
+
192
203
  ## AI chat
193
204
 
194
205
  | Component | Use it for | Docs slug |
@@ -242,11 +253,25 @@ Docs slug: `agent-timeline`.
242
253
  | `ChangesSummary` (`ChangedFile[]`), `ChangeStats` (`additions`, `deletions`) | What a turn changed, and +12 −3 counts |
243
254
  | `Divider` (`label`, or children; `role`) | A labelled break in a timeline: a new day, "Context compacted" |
244
255
 
256
+ Folds (`Collapsible`, `Tool`, `Reasoning`, `Activity`, `WorkFold`) build their content the
257
+ first time they open and keep it after. Don't query elements inside one that was never opened,
258
+ and don't wrap its content in an `{#if open}` of your own. `Activity.Step`'s `output` opens at
259
+ its end once its box can be seen, and stays there as more is printed unless the reader scrolls
260
+ up: don't scroll it yourself. It is measured only while its fold is open. Past `tail` (4,000
261
+ characters) only the end shows, under a "Show all output" button of the step's own; bind
262
+ `showAll` to keep that choice where the conversation is drawn again, and set it when a find of
263
+ your own matches the part cut off, which the step marks with `data-output-cut`. Leave out the
264
+ words of `[data-activity-step-toggle]` from what such a find searches. Don't add a button of
265
+ your own for it. `outputLabels` renames it.
266
+
245
267
  ## Utilities
246
268
 
247
269
  - `sx()`, `classes()` and the `Sx` type: see the `styling` skill.
248
270
  - `resolveColor()` and `resolveRgba()`: see the `theming` skill.
249
271
  - `whileVisible`: an attachment that runs an animation that never ends only while it can be seen, with `animationPlayState: play.whileVisible` from the tokens. Step the animation itself.
250
- Shimmer, Skeleton and Progress run on it. Spinner does not: it is a CSS animation of `rotate`,
251
- one turn in 600ms, so it stays smooth.
272
+ Shimmer, Skeleton, Progress and Markdown's caret run on it, stepped. Spinner pauses with it
273
+ too, but is not stepped: it is a CSS animation of `rotate`, one turn in 600ms, so it stays smooth.
274
+ - `setPageHidden(hidden)`: tells Narvi the host has hidden the page where the document cannot
275
+ tell, such as a minimized Electron window that keeps running. Every `whileVisible` animation
276
+ pauses until it is called with `false`.
252
277
  - `DevStyles`: see the `setup` skill.
@@ -12,7 +12,7 @@ metadata:
12
12
  patching the DOM, and decide which links and images text from a model may load.
13
13
  type: core
14
14
  library: '@diegopluna/narvi'
15
- library_version: '0.3.7'
15
+ library_version: '0.3.8'
16
16
  requires:
17
17
  - setup
18
18
  sources:
@@ -11,7 +11,7 @@ metadata:
11
11
  4 when the app uses it.
12
12
  type: lifecycle
13
13
  library: '@diegopluna/narvi'
14
- library_version: '0.3.7'
14
+ library_version: '0.3.8'
15
15
  sources:
16
16
  - src/lib/vite.ts
17
17
  - src/lib/base.css
@@ -12,7 +12,7 @@ metadata:
12
12
  hover, motion and forced-colour preferences.
13
13
  type: core
14
14
  library: '@diegopluna/narvi'
15
- library_version: '0.3.7'
15
+ library_version: '0.3.8'
16
16
  requires:
17
17
  - setup
18
18
  sources:
@@ -23,6 +23,7 @@ sources:
23
23
  - src/routes/docs/styling/+page.svelte
24
24
  - src/lib/markers.stylex.ts
25
25
  - src/lib/visually-hidden.ts
26
+ - src/lib/internal/visible.ts
26
27
  - src/lib/typography.ts
27
28
  ---
28
29
 
@@ -102,6 +103,11 @@ package root) breaks them.
102
103
  - `play.whileVisible`: the `animationPlayState` for an animation that never ends. Attach
103
104
  `whileVisible` (from the package root) to its element and it runs only while it can be seen.
104
105
  Step such an animation (`steps(30)` over two seconds) so it costs a few frames a second.
106
+ - `setPageHidden(hidden)` (from the package root) is the host's word that the page is out of
107
+ sight where `document.hidden` stays false, as in an Electron window with background
108
+ throttling off, minimized or closed to the tray. Call it with `true` then and `false` when the
109
+ window is back: every `whileVisible` animation pauses meanwhile, Narvi's spinners, shimmers,
110
+ skeletons, progress bars and Markdown's caret among them. Don't pause them by hand.
105
111
  - `motion`: `fast` 120ms, `base` 150ms, `slow` 200ms; `easeOut` for feedback, `easeInOut` for
106
112
  things that travel. Nothing in an interface takes longer than `motion.slow`.
107
113
  - `pageMotion`: a slower scale for pages read as they scroll (`Reveal` uses it). Never use it
@@ -11,7 +11,7 @@ metadata:
11
11
  menus and dialogs, and resolve token colours for drawing code that cannot read CSS variables.
12
12
  type: core
13
13
  library: '@diegopluna/narvi'
14
- library_version: '0.3.7'
14
+ library_version: '0.3.8'
15
15
  requires:
16
16
  - setup
17
17
  sources: