@diegopluna/narvi 0.3.10 → 0.3.12
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/base.css +38 -0
- package/dist/components/activity/ActivityContent.svelte +7 -3
- package/dist/components/activity/ActivityStep.svelte +28 -11
- package/dist/components/activity/ActivityStep.svelte.d.ts +6 -0
- package/dist/components/activity/ActivityTrigger.svelte +5 -2
- package/dist/components/app-shell/AppShellBar.svelte +9 -4
- package/dist/components/app-shell/AppShellHeader.svelte +9 -5
- package/dist/components/approval/Approval.svelte +7 -4
- package/dist/components/button/Button.svelte +50 -26
- package/dist/components/card/Card.svelte +5 -2
- package/dist/components/changes-summary/ChangesSummary.svelte +11 -8
- package/dist/components/choice-cards/ChoiceCards.svelte +5 -2
- package/dist/components/collapsible/CollapsibleTrigger.svelte +5 -2
- package/dist/components/color-field/ColorField.svelte +397 -0
- package/dist/components/color-field/ColorField.svelte.d.ts +41 -0
- package/dist/components/command/styles.d.ts +8 -9
- package/dist/components/command/styles.js +11 -10
- package/dist/components/composer/ComposerAttachment.svelte +7 -3
- package/dist/components/composer/ComposerAttachments.svelte +5 -1
- package/dist/components/composer/ComposerModelPicker.svelte +37 -35
- package/dist/components/composer/ComposerRoot.svelte +9 -5
- package/dist/components/composer/ComposerTextarea.svelte +9 -6
- package/dist/components/composer/ComposerToggle.svelte +7 -4
- package/dist/components/composer/ComposerToolbar.svelte +5 -1
- package/dist/components/composer/ComposerTray.svelte +10 -7
- package/dist/components/conversation/ConversationContent.svelte +0 -2
- package/dist/components/conversation/ConversationRoot.svelte +124 -27
- package/dist/components/conversation/ConversationScrollButton.svelte +10 -7
- package/dist/components/conversation/scrolling.d.ts +18 -4
- package/dist/components/conversation/scrolling.js +28 -6
- package/dist/components/dialog/ConfirmDialog.svelte +5 -2
- package/dist/components/dialog/styles.d.ts +3 -4
- package/dist/components/dialog/styles.js +7 -6
- package/dist/components/frame/Frame.svelte +8 -5
- package/dist/components/hover-card/HoverCardContent.svelte +5 -1
- package/dist/components/input/Input.svelte +12 -8
- package/dist/components/markdown/MarkdownCode.svelte +0 -1
- package/dist/components/markdown/MarkdownDiagram.svelte +1 -2
- package/dist/components/markdown/styles.d.ts +0 -2
- package/dist/components/markdown/styles.js +0 -2
- package/dist/components/message/MessageActions.svelte +8 -4
- package/dist/components/message/MessageContent.svelte +6 -2
- package/dist/components/message/MessagePending.svelte +5 -2
- package/dist/components/message/MessageRoot.svelte +10 -4
- package/dist/components/message/MessageTime.svelte +5 -2
- package/dist/components/message/styles.d.ts +2 -2
- package/dist/components/message/styles.js +5 -3
- package/dist/components/notice/Notice.svelte +13 -4
- package/dist/components/plan/Plan.svelte +13 -10
- package/dist/components/popover/PopoverContent.svelte +8 -1
- package/dist/components/questionnaire/Questionnaire.svelte +12 -9
- package/dist/components/queued-message/QueuedMessage.svelte +14 -7
- package/dist/components/rail/RailItem.svelte +16 -7
- package/dist/components/rail/RailRoot.svelte +9 -4
- package/dist/components/rail/RailSeparator.svelte +5 -2
- package/dist/components/reasoning/ReasoningContent.svelte +6 -3
- package/dist/components/reasoning/ReasoningTrigger.svelte +5 -2
- package/dist/components/resize-handle/ResizeHandle.svelte +11 -7
- package/dist/components/search-button/SearchButton.svelte +6 -3
- package/dist/components/segmented/SegmentedControl.svelte +6 -3
- package/dist/components/settings-group/SettingsGroup.svelte +5 -2
- package/dist/components/sidebar/SidebarContent.svelte +8 -9
- package/dist/components/sidebar/SidebarFolder.svelte +8 -5
- package/dist/components/sidebar/SidebarFooter.svelte +5 -2
- package/dist/components/sidebar/SidebarGroup.svelte +11 -8
- package/dist/components/sidebar/SidebarHeader.svelte +9 -4
- package/dist/components/sidebar/SidebarItem.svelte +14 -9
- package/dist/components/split-button/SplitButton.svelte +5 -2
- package/dist/components/suggestions/SuggestionsItem.svelte +6 -3
- package/dist/components/suggestions/SuggestionsRoot.svelte +5 -1
- package/dist/components/tab-strip/TabStrip.svelte +21 -16
- package/dist/components/tabs/Tabs.svelte +7 -4
- package/dist/components/textarea/Textarea.svelte +6 -2
- package/dist/components/theme/Theme.svelte +32 -3
- package/dist/components/toast/Toaster.svelte +14 -5
- package/dist/components/toggle-group/ToggleGroupRoot.svelte +5 -1
- package/dist/components/tool/ToolContent.svelte +8 -4
- package/dist/components/tool/ToolSection.svelte +7 -4
- package/dist/components/tool/ToolTrigger.svelte +5 -2
- package/dist/components/tooltip/TooltipContent.svelte +7 -4
- package/dist/components/work-fold/WorkFold.svelte +9 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/internal/Code.svelte +6 -4
- package/dist/internal/Glyph.svelte +23 -2
- package/dist/internal/Glyph.svelte.d.ts +4 -1
- package/dist/internal/control.d.ts +6 -6
- package/dist/internal/control.js +9 -7
- package/dist/internal/hsv.d.ts +18 -0
- package/dist/internal/hsv.js +63 -0
- package/dist/internal/kinds.d.ts +1 -1
- package/dist/internal/kinds.js +3 -3
- package/dist/internal/layer.d.ts +10 -11
- package/dist/internal/layer.js +14 -13
- package/dist/internal/toggle.d.ts +8 -8
- package/dist/internal/toggle.js +22 -10
- package/dist/preset.d.ts +12 -3
- package/dist/preset.js +18 -4
- package/dist/tokens.stylex.d.ts +13 -3
- package/dist/tokens.stylex.js +25 -14
- package/package.json +1 -1
- package/skills/building-ui/SKILL.md +1 -1
- package/skills/building-ui/references/components.md +24 -0
- package/skills/markdown/SKILL.md +1 -1
- package/skills/setup/SKILL.md +9 -3
- package/skills/styling/SKILL.md +5 -2
- package/skills/theming/SKILL.md +48 -4
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { visuallyHidden } from '../../visually-hidden.js';
|
|
9
9
|
import { shared } from '../../internal/shared.js';
|
|
10
10
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
11
|
-
import { colors, font, motion, radius } from '../../tokens.stylex.js';
|
|
11
|
+
import { colors, density, font, motion, radius } from '../../tokens.stylex.js';
|
|
12
12
|
import { media } from '../../media.stylex.js';
|
|
13
13
|
import { getComposerContext } from './context.js';
|
|
14
14
|
|
|
@@ -118,6 +118,9 @@
|
|
|
118
118
|
const GAP = 6;
|
|
119
119
|
const MARGIN = 8;
|
|
120
120
|
|
|
121
|
+
/** A length at the window's density (`density` in the tokens). */
|
|
122
|
+
const d = (rem: string) => `calc(${rem} * ${density.factor})`;
|
|
123
|
+
|
|
121
124
|
const styles = stylex.create({
|
|
122
125
|
trigger: {
|
|
123
126
|
display: 'inline-flex',
|
|
@@ -125,10 +128,10 @@
|
|
|
125
128
|
flexShrink: 1,
|
|
126
129
|
gap: '0.25rem',
|
|
127
130
|
minWidth: 0,
|
|
128
|
-
height: '1.75rem',
|
|
131
|
+
height: d('1.75rem'),
|
|
129
132
|
margin: 0,
|
|
130
|
-
paddingInlineStart: '0.625rem',
|
|
131
|
-
paddingInlineEnd: '0.375rem',
|
|
133
|
+
paddingInlineStart: d('0.625rem'),
|
|
134
|
+
paddingInlineEnd: d('0.375rem'),
|
|
132
135
|
borderWidth: 0,
|
|
133
136
|
borderRadius: `calc(${radius.card} * 4 / 3)`,
|
|
134
137
|
backgroundColor: {
|
|
@@ -173,17 +176,16 @@
|
|
|
173
176
|
maxWidth: 'min(320px, calc(100vw - 16px))',
|
|
174
177
|
maxHeight: 'min(360px, var(--narvi-picker-room, 360px))',
|
|
175
178
|
margin: 0,
|
|
176
|
-
padding: '0.25rem',
|
|
179
|
+
padding: d('0.25rem'),
|
|
177
180
|
overflowY: 'auto',
|
|
178
181
|
overscrollBehavior: 'contain',
|
|
179
182
|
borderWidth: 0,
|
|
180
|
-
// Inner items are 8px round with 4px of padding: 12px outside
|
|
183
|
+
// Inner items are 8px round with 4px of padding: 12px outside, at the default density
|
|
181
184
|
borderRadius: radius.card,
|
|
182
185
|
backgroundColor: colors.bgRaised,
|
|
183
186
|
boxShadow: `inset 0 0 0 1px ${colors.borderStrong}, 0 16px 40px -12px ${colors.shadow}`,
|
|
184
187
|
color: colors.text,
|
|
185
188
|
fontFamily: font.body,
|
|
186
|
-
scrollbarWidth: 'thin',
|
|
187
189
|
outlineStyle: 'solid',
|
|
188
190
|
outlineWidth: { default: 0, [media.forcedColors]: '1px' },
|
|
189
191
|
outlineColor: 'CanvasText',
|
|
@@ -206,7 +208,7 @@
|
|
|
206
208
|
list: {
|
|
207
209
|
display: 'flex',
|
|
208
210
|
flexDirection: 'column',
|
|
209
|
-
gap: '
|
|
211
|
+
gap: d('0.125rem'),
|
|
210
212
|
outlineStyle: 'none'
|
|
211
213
|
},
|
|
212
214
|
// The rail, then a hairline, then the list. The rail stays put as the list scrolls.
|
|
@@ -217,22 +219,22 @@
|
|
|
217
219
|
top: 0,
|
|
218
220
|
display: 'flex',
|
|
219
221
|
flexDirection: 'column',
|
|
220
|
-
gap: '
|
|
222
|
+
gap: d('0.125rem'),
|
|
221
223
|
flexShrink: 0
|
|
222
224
|
},
|
|
223
225
|
divider: {
|
|
224
226
|
alignSelf: 'stretch',
|
|
225
227
|
flexShrink: 0,
|
|
226
228
|
width: '1px',
|
|
227
|
-
marginInline: '0.25rem',
|
|
229
|
+
marginInline: d('0.25rem'),
|
|
228
230
|
backgroundColor: colors.border
|
|
229
231
|
},
|
|
230
232
|
provider: {
|
|
231
233
|
'--narvi-icon-size': '1rem',
|
|
232
234
|
display: 'grid',
|
|
233
235
|
placeItems: 'center',
|
|
234
|
-
width: '2rem',
|
|
235
|
-
height: '2rem',
|
|
236
|
+
width: d('2rem'),
|
|
237
|
+
height: d('2rem'),
|
|
236
238
|
margin: 0,
|
|
237
239
|
padding: 0,
|
|
238
240
|
borderWidth: 0,
|
|
@@ -263,13 +265,13 @@
|
|
|
263
265
|
group: {
|
|
264
266
|
display: 'flex',
|
|
265
267
|
flexDirection: 'column',
|
|
266
|
-
gap: '
|
|
267
|
-
paddingTop: '0.25rem'
|
|
268
|
+
gap: d('0.125rem'),
|
|
269
|
+
paddingTop: d('0.25rem')
|
|
268
270
|
},
|
|
269
271
|
groupLabel: {
|
|
270
|
-
paddingTop: '0.375rem',
|
|
271
|
-
paddingBottom: '0.25rem',
|
|
272
|
-
paddingInline: '0.625rem',
|
|
272
|
+
paddingTop: d('0.375rem'),
|
|
273
|
+
paddingBottom: d('0.25rem'),
|
|
274
|
+
paddingInline: d('0.625rem'),
|
|
273
275
|
color: colors.textSubtle,
|
|
274
276
|
fontSize: font.sizeCaption,
|
|
275
277
|
fontWeight: font.weightMedium,
|
|
@@ -280,9 +282,9 @@
|
|
|
280
282
|
gridTemplateColumns: 'minmax(0, 1fr) 16px',
|
|
281
283
|
alignItems: 'center',
|
|
282
284
|
columnGap: '0.75rem',
|
|
283
|
-
minHeight: '2.25rem',
|
|
284
|
-
paddingBlock: '0.4375rem',
|
|
285
|
-
paddingInline: '0.625rem',
|
|
285
|
+
minHeight: d('2.25rem'),
|
|
286
|
+
paddingBlock: d('0.4375rem'),
|
|
287
|
+
paddingInline: d('0.625rem'),
|
|
286
288
|
borderRadius: radius.control,
|
|
287
289
|
cursor: 'pointer',
|
|
288
290
|
userSelect: 'none',
|
|
@@ -372,16 +374,16 @@
|
|
|
372
374
|
search: {
|
|
373
375
|
'--narvi-icon-size': '0.875rem',
|
|
374
376
|
position: 'sticky',
|
|
375
|
-
top: '-0.25rem',
|
|
377
|
+
top: d('-0.25rem'),
|
|
376
378
|
zIndex: 1,
|
|
377
379
|
display: 'flex',
|
|
378
380
|
alignItems: 'center',
|
|
379
381
|
gap: '0.5rem',
|
|
380
|
-
marginTop: '-0.25rem',
|
|
381
|
-
marginBottom: '0.25rem',
|
|
382
|
-
paddingTop: '0.25rem',
|
|
383
|
-
paddingInline: '0.625rem',
|
|
384
|
-
minHeight: '2.25rem',
|
|
382
|
+
marginTop: d('-0.25rem'),
|
|
383
|
+
marginBottom: d('0.25rem'),
|
|
384
|
+
paddingTop: d('0.25rem'),
|
|
385
|
+
paddingInline: d('0.625rem'),
|
|
386
|
+
minHeight: d('2.25rem'),
|
|
385
387
|
backgroundColor: colors.bgRaised,
|
|
386
388
|
boxShadow: `inset 0 -1px 0 ${colors.border}`,
|
|
387
389
|
color: colors.textSubtle
|
|
@@ -389,7 +391,7 @@
|
|
|
389
391
|
searchField: {
|
|
390
392
|
flexGrow: 1,
|
|
391
393
|
minWidth: 0,
|
|
392
|
-
height: '2rem',
|
|
394
|
+
height: d('2rem'),
|
|
393
395
|
margin: 0,
|
|
394
396
|
padding: 0,
|
|
395
397
|
borderWidth: 0,
|
|
@@ -401,12 +403,12 @@
|
|
|
401
403
|
'::placeholder': { color: colors.textSubtle }
|
|
402
404
|
},
|
|
403
405
|
empty: {
|
|
404
|
-
paddingBlock: '0.75rem',
|
|
405
|
-
paddingInline: '0.625rem',
|
|
406
|
+
paddingBlock: d('0.75rem'),
|
|
407
|
+
paddingInline: d('0.625rem'),
|
|
406
408
|
color: colors.textMuted,
|
|
407
409
|
fontSize: font.sizeMeta
|
|
408
410
|
},
|
|
409
|
-
olderRow: { gridTemplateColumns: 'minmax(0, 1fr) 16px', minHeight: '2rem' },
|
|
411
|
+
olderRow: { gridTemplateColumns: 'minmax(0, 1fr) 16px', minHeight: d('2rem') },
|
|
410
412
|
olderName: { color: colors.textMuted, fontWeight: font.weightRegular },
|
|
411
413
|
olderChevron: {
|
|
412
414
|
gridColumn: '2',
|
|
@@ -420,10 +422,10 @@
|
|
|
420
422
|
// What Shift and ⌘ do, at the foot of the list
|
|
421
423
|
hint: {
|
|
422
424
|
margin: 0,
|
|
423
|
-
marginTop: '0.25rem',
|
|
424
|
-
paddingTop: '0.5rem',
|
|
425
|
-
paddingBottom: '0.25rem',
|
|
426
|
-
paddingInline: '0.625rem',
|
|
425
|
+
marginTop: d('0.25rem'),
|
|
426
|
+
paddingTop: d('0.5rem'),
|
|
427
|
+
paddingBottom: d('0.25rem'),
|
|
428
|
+
paddingInline: d('0.625rem'),
|
|
427
429
|
boxShadow: `inset 0 1px 0 ${colors.border}`,
|
|
428
430
|
color: colors.textSubtle,
|
|
429
431
|
fontSize: font.sizeCaption,
|
|
@@ -432,7 +434,7 @@
|
|
|
432
434
|
railRule: {
|
|
433
435
|
alignSelf: 'stretch',
|
|
434
436
|
height: '1px',
|
|
435
|
-
marginBlock: '0.125rem',
|
|
437
|
+
marginBlock: d('0.125rem'),
|
|
436
438
|
backgroundColor: colors.border
|
|
437
439
|
}
|
|
438
440
|
});
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import type { HTMLFormAttributes } from 'svelte/elements';
|
|
6
6
|
import { shared } from '../../internal/shared.js';
|
|
7
7
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
8
|
-
import { colors, font, motion, radius } from '../../tokens.stylex.js';
|
|
8
|
+
import { colors, density, font, motion, radius } from '../../tokens.stylex.js';
|
|
9
9
|
import { media } from '../../media.stylex.js';
|
|
10
10
|
import {
|
|
11
11
|
accepts,
|
|
@@ -79,19 +79,23 @@
|
|
|
79
79
|
return marked ?? form.querySelector<HTMLElement>(EDITABLE);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/** A length at the window's density (`density` in the tokens). */
|
|
83
|
+
const d = (rem: string) => `calc(${rem} * ${density.factor})`;
|
|
84
|
+
|
|
82
85
|
const styles = stylex.create({
|
|
83
86
|
root: {
|
|
84
87
|
position: 'relative',
|
|
85
88
|
boxSizing: 'border-box',
|
|
86
89
|
display: 'flex',
|
|
87
90
|
flexDirection: 'column',
|
|
88
|
-
gap: '0.25rem',
|
|
91
|
+
gap: d('0.25rem'),
|
|
89
92
|
minWidth: 0,
|
|
90
93
|
margin: 0,
|
|
91
|
-
padding: '0.5rem',
|
|
94
|
+
padding: d('0.5rem'),
|
|
92
95
|
// The controls' radius plus this padding, so the corners sit concentric.
|
|
93
|
-
// Both follow the radius scale: 1rem and 1.5rem by default.
|
|
94
|
-
|
|
96
|
+
// Both follow the radius scale: 1rem and 1.5rem by default. The padding part follows the
|
|
97
|
+
// density.
|
|
98
|
+
borderRadius: `calc(${radius.card} * 4 / 3 + ${d('0.5rem')})`,
|
|
95
99
|
backgroundColor: colors.bgRaised,
|
|
96
100
|
color: colors.text,
|
|
97
101
|
fontFamily: font.body,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as stylex from '@stylexjs/stylex';
|
|
3
3
|
import type { HTMLTextareaAttributes } from 'svelte/elements';
|
|
4
4
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
5
|
-
import { colors, font } from '../../tokens.stylex.js';
|
|
5
|
+
import { colors, density, font } from '../../tokens.stylex.js';
|
|
6
6
|
import { useComposer } from './context.js';
|
|
7
7
|
|
|
8
8
|
export type ComposerTextareaProps = Omit<HTMLTextareaAttributes, 'value' | 'children'> & {
|
|
@@ -10,17 +10,21 @@
|
|
|
10
10
|
ref?: HTMLTextAreaElement | null | undefined;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
/** A length at the window's density (`density` in the tokens). */
|
|
14
|
+
const d = (rem: string) => `calc(${rem} * ${density.factor})`;
|
|
15
|
+
|
|
13
16
|
const styles = stylex.create({
|
|
14
17
|
textarea: {
|
|
15
18
|
boxSizing: 'border-box',
|
|
16
19
|
display: 'block',
|
|
17
20
|
width: '100%',
|
|
18
|
-
// One line to start; it grows with what is typed, then scrolls
|
|
19
|
-
|
|
21
|
+
// One line to start; it grows with what is typed, then scrolls. The line keeps its
|
|
22
|
+
// height and the padding follows the density.
|
|
23
|
+
minHeight: `calc(1lh + ${d('0.75rem')})`,
|
|
20
24
|
maxHeight: '14rem',
|
|
21
25
|
margin: 0,
|
|
22
|
-
paddingBlock: '0.375rem',
|
|
23
|
-
paddingInline: '0.5rem',
|
|
26
|
+
paddingBlock: d('0.375rem'),
|
|
27
|
+
paddingInline: d('0.5rem'),
|
|
24
28
|
borderWidth: 0,
|
|
25
29
|
backgroundColor: 'transparent',
|
|
26
30
|
color: colors.text,
|
|
@@ -31,7 +35,6 @@
|
|
|
31
35
|
fieldSizing: 'content',
|
|
32
36
|
resize: 'none',
|
|
33
37
|
overflowY: 'auto',
|
|
34
|
-
scrollbarWidth: 'thin',
|
|
35
38
|
// The frame around it shows the focus
|
|
36
39
|
outlineStyle: 'none',
|
|
37
40
|
cursor: { default: 'text', ':disabled': 'not-allowed' },
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
5
5
|
import { shared } from '../../internal/shared.js';
|
|
6
6
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
7
|
-
import { colors, font, motion, radius } from '../../tokens.stylex.js';
|
|
7
|
+
import { colors, density, font, motion, radius } from '../../tokens.stylex.js';
|
|
8
8
|
import { media } from '../../media.stylex.js';
|
|
9
9
|
import { getComposerContext } from './context.js';
|
|
10
10
|
|
|
@@ -19,15 +19,18 @@
|
|
|
19
19
|
children?: Snippet | undefined;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
/** A length at the window's density (`density` in the tokens). */
|
|
23
|
+
const d = (rem: string) => `calc(${rem} * ${density.factor})`;
|
|
24
|
+
|
|
22
25
|
const styles = stylex.create({
|
|
23
26
|
toggle: {
|
|
24
27
|
display: 'inline-flex',
|
|
25
28
|
alignItems: 'center',
|
|
26
29
|
flexShrink: 0,
|
|
27
30
|
gap: '0.375rem',
|
|
28
|
-
height: '1.75rem',
|
|
31
|
+
height: d('1.75rem'),
|
|
29
32
|
margin: 0,
|
|
30
|
-
paddingInline: '0.625rem',
|
|
33
|
+
paddingInline: d('0.625rem'),
|
|
31
34
|
borderWidth: 0,
|
|
32
35
|
borderRadius: `calc(${radius.card} * 4 / 3)`,
|
|
33
36
|
backgroundColor: {
|
|
@@ -58,7 +61,7 @@
|
|
|
58
61
|
}
|
|
59
62
|
},
|
|
60
63
|
// The icon leads, so the pill is a touch tighter on that side
|
|
61
|
-
withIcon: { paddingInlineStart: '0.5rem' },
|
|
64
|
+
withIcon: { paddingInlineStart: d('0.5rem') },
|
|
62
65
|
// On: a fill of the accent, the one colour that marks state
|
|
63
66
|
on: {
|
|
64
67
|
backgroundColor: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
2
|
import * as stylex from '@stylexjs/stylex';
|
|
3
|
+
import { density } from '../../tokens.stylex.js';
|
|
3
4
|
import type { Snippet } from 'svelte';
|
|
4
5
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
5
6
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
@@ -10,11 +11,14 @@
|
|
|
10
11
|
children?: Snippet | undefined;
|
|
11
12
|
};
|
|
12
13
|
|
|
14
|
+
/** A length at the window's density (`density` in the tokens). */
|
|
15
|
+
const d = (rem: string) => `calc(${rem} * ${density.factor})`;
|
|
16
|
+
|
|
13
17
|
const styles = stylex.create({
|
|
14
18
|
toolbar: {
|
|
15
19
|
display: 'flex',
|
|
16
20
|
alignItems: 'center',
|
|
17
|
-
gap: '0.25rem',
|
|
21
|
+
gap: d('0.25rem'),
|
|
18
22
|
minWidth: 0
|
|
19
23
|
}
|
|
20
24
|
});
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import type { Snippet } from 'svelte';
|
|
13
13
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
14
14
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
15
|
-
import { colors, radius } from '../../tokens.stylex.js';
|
|
15
|
+
import { colors, density, radius } from '../../tokens.stylex.js';
|
|
16
16
|
|
|
17
17
|
export type ComposerTrayProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
|
|
18
18
|
/** Names what is waiting, for assistive technology. */
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
children?: Snippet | undefined;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
/** A length at the window's density (`density` in the tokens). */
|
|
33
|
+
const d = (rem: string) => `calc(${rem} * ${density.factor})`;
|
|
34
|
+
|
|
32
35
|
const styles = stylex.create({
|
|
33
36
|
tray: { display: 'flex', flexDirection: 'column', minWidth: 0 },
|
|
34
37
|
// A flat fill whose foot tucks in behind the composer by the composer's own radius, so
|
|
@@ -37,12 +40,12 @@
|
|
|
37
40
|
pending: {
|
|
38
41
|
display: { default: 'none', ':has(> :not(:empty, [hidden], template))': 'flex' },
|
|
39
42
|
flexDirection: 'column',
|
|
40
|
-
gap: '0.375rem',
|
|
41
|
-
padding: '0.375rem',
|
|
42
|
-
paddingBottom: `calc(${radius.card} * 4 / 3 + 0.875rem)`,
|
|
43
|
-
marginBottom: `calc(-1 * (${radius.card} * 4 / 3 + 0.5rem))`,
|
|
44
|
-
borderStartStartRadius: `calc(${radius.card} + 0.375rem)`,
|
|
45
|
-
borderStartEndRadius: `calc(${radius.card} + 0.375rem)`,
|
|
43
|
+
gap: d('0.375rem'),
|
|
44
|
+
padding: d('0.375rem'),
|
|
45
|
+
paddingBottom: `calc(${radius.card} * 4 / 3 + ${d('0.875rem')})`,
|
|
46
|
+
marginBottom: `calc(-1 * (${radius.card} * 4 / 3 + ${d('0.5rem')}))`,
|
|
47
|
+
borderStartStartRadius: `calc(${radius.card} + ${d('0.375rem')})`,
|
|
48
|
+
borderStartEndRadius: `calc(${radius.card} + ${d('0.375rem')})`,
|
|
46
49
|
backgroundColor: colors.fillMuted,
|
|
47
50
|
outlineStyle: 'solid',
|
|
48
51
|
outlineWidth: '1px',
|
|
@@ -26,8 +26,6 @@
|
|
|
26
26
|
overflowAnchor: 'none',
|
|
27
27
|
overscrollBehavior: 'contain',
|
|
28
28
|
scrollbarGutter: 'stable',
|
|
29
|
-
scrollbarWidth: 'thin',
|
|
30
|
-
scrollbarColor: `${colors.borderStrong} transparent`,
|
|
31
29
|
outlineStyle: 'solid',
|
|
32
30
|
outlineWidth: { default: 0, ':focus-visible': '2px' },
|
|
33
31
|
outlineColor: colors.focusRing,
|
|
@@ -34,10 +34,12 @@
|
|
|
34
34
|
import {
|
|
35
35
|
FOLLOW_BAND,
|
|
36
36
|
INTENT_WINDOW,
|
|
37
|
-
|
|
37
|
+
TOGGLE_WINDOW,
|
|
38
|
+
frameHasInput,
|
|
38
39
|
isUpKey,
|
|
39
40
|
onScrollbar,
|
|
40
|
-
scrollsInside
|
|
41
|
+
scrollsInside,
|
|
42
|
+
toggleOf
|
|
41
43
|
} from './scrolling.js';
|
|
42
44
|
import type { ConversationMode } from './context.js';
|
|
43
45
|
|
|
@@ -52,6 +54,7 @@
|
|
|
52
54
|
|
|
53
55
|
// How far the message before an anchored one peeks above it
|
|
54
56
|
const PEEK = 64;
|
|
57
|
+
const SAME = 0.5;
|
|
55
58
|
|
|
56
59
|
let atBottom = $state(true);
|
|
57
60
|
let mode = $state<ConversationMode>('following');
|
|
@@ -59,18 +62,41 @@
|
|
|
59
62
|
let viewport: HTMLElement | null = null;
|
|
60
63
|
let anchored: HTMLElement | null = null;
|
|
61
64
|
let lastTop = 0;
|
|
62
|
-
// When the person last made a gesture that scrolls up
|
|
63
|
-
// conversation last moved itself
|
|
65
|
+
// When the person last made a gesture that scrolls up
|
|
64
66
|
let intentAt = -Infinity;
|
|
65
|
-
|
|
67
|
+
// Where the conversation last put itself, which tells its own moves from the person's
|
|
68
|
+
let ownTop = 0;
|
|
69
|
+
// Whether a button is held down in the conversation, as while a selection is dragged
|
|
70
|
+
let pressing = false;
|
|
71
|
+
// A fold's toggle just pressed: where it sat in the view, and how tall its fold was
|
|
72
|
+
let toggled: {
|
|
73
|
+
element: HTMLElement;
|
|
74
|
+
fold: Element;
|
|
75
|
+
viewportTop: number;
|
|
76
|
+
height: number;
|
|
77
|
+
until: number;
|
|
78
|
+
keeping: boolean;
|
|
79
|
+
} | null = null;
|
|
66
80
|
|
|
67
81
|
const reduceMotion = () => matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
68
82
|
const distance = (el: HTMLElement) => el.scrollHeight - el.clientHeight - el.scrollTop;
|
|
83
|
+
// How far below the view the content itself ends, leaving out the room for a reply
|
|
84
|
+
const below = (el: HTMLElement) => distance(el) - spacer;
|
|
85
|
+
const overflows = (el: HTMLElement) => el.scrollHeight > el.clientHeight + SAME;
|
|
86
|
+
const topIn = (element: Element, el: HTMLElement) =>
|
|
87
|
+
element.getBoundingClientRect().top - el.getBoundingClientRect().top;
|
|
69
88
|
|
|
70
89
|
function moveTo(top: number, behavior: ScrollBehavior = 'instant') {
|
|
71
90
|
if (!viewport) return;
|
|
72
|
-
selfAt = performance.now();
|
|
73
91
|
viewport.scrollTo({ top, behavior });
|
|
92
|
+
ownTop = viewport.scrollTop;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The person took the view: stop following, and stop keeping a toggle in place. */
|
|
96
|
+
function letGo() {
|
|
97
|
+
intentAt = performance.now();
|
|
98
|
+
toggled = null;
|
|
99
|
+
mode = 'free';
|
|
74
100
|
}
|
|
75
101
|
|
|
76
102
|
/**
|
|
@@ -81,6 +107,8 @@
|
|
|
81
107
|
if (!viewport) return;
|
|
82
108
|
anchored = null;
|
|
83
109
|
spacer = 0;
|
|
110
|
+
toggled = null;
|
|
111
|
+
intentAt = -Infinity;
|
|
84
112
|
mode = 'following';
|
|
85
113
|
moveTo(viewport.scrollHeight, behavior ?? (reduceMotion() ? 'instant' : 'smooth'));
|
|
86
114
|
}
|
|
@@ -88,11 +116,7 @@
|
|
|
88
116
|
// Where an anchored message sits in the scroller's own coordinates
|
|
89
117
|
function topOf(message: HTMLElement) {
|
|
90
118
|
if (!viewport) return 0;
|
|
91
|
-
return (
|
|
92
|
-
message.getBoundingClientRect().top -
|
|
93
|
-
viewport.getBoundingClientRect().top +
|
|
94
|
-
viewport.scrollTop
|
|
95
|
-
);
|
|
119
|
+
return topIn(message, viewport) + viewport.scrollTop;
|
|
96
120
|
}
|
|
97
121
|
|
|
98
122
|
// The room needed beneath the content so the anchored message can reach the top
|
|
@@ -123,6 +147,7 @@
|
|
|
123
147
|
export function anchor(message: HTMLElement, behavior?: ScrollBehavior) {
|
|
124
148
|
if (!viewport) return;
|
|
125
149
|
anchored = message;
|
|
150
|
+
toggled = null;
|
|
126
151
|
mode = 'anchored';
|
|
127
152
|
settleSpacer();
|
|
128
153
|
// The spacer is laid out before the scroll, so there is room to reach the target
|
|
@@ -135,46 +160,108 @@
|
|
|
135
160
|
});
|
|
136
161
|
}
|
|
137
162
|
|
|
163
|
+
/**
|
|
164
|
+
* A fold opened at the end keeps its toggle where it was, rather than the view following what
|
|
165
|
+
* it opened down and taking the toggle up out of sight. As much of what it opened shows as
|
|
166
|
+
* fits below, the toggle rising no higher than the peek; if that leaves more below the view,
|
|
167
|
+
* the conversation stops following, as T3 Code's does. Says whether it kept one.
|
|
168
|
+
*/
|
|
169
|
+
function keepToggle(el: HTMLElement) {
|
|
170
|
+
const kept = toggled;
|
|
171
|
+
if (!kept) return false;
|
|
172
|
+
if (performance.now() > kept.until || !kept.element.isConnected) {
|
|
173
|
+
toggled = null;
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
kept.keeping ||=
|
|
177
|
+
mode === 'following' &&
|
|
178
|
+
Math.abs(kept.fold.getBoundingClientRect().height - kept.height) > SAME;
|
|
179
|
+
if (!kept.keeping) return false;
|
|
180
|
+
const drift = topIn(kept.element, el) - kept.viewportTop;
|
|
181
|
+
const hidden =
|
|
182
|
+
kept.fold.getBoundingClientRect().bottom - el.getBoundingClientRect().bottom - drift;
|
|
183
|
+
const lift = Math.max(0, Math.min(hidden, kept.viewportTop - PEEK));
|
|
184
|
+
moveTo(el.scrollTop + drift + lift);
|
|
185
|
+
if (below(el) > threshold) mode = 'free';
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
|
|
138
189
|
function attach(el: HTMLElement, content: HTMLElement) {
|
|
139
190
|
viewport = el;
|
|
140
191
|
// Open at the latest message
|
|
141
192
|
moveTo(el.scrollHeight);
|
|
142
193
|
lastTop = el.scrollTop;
|
|
143
194
|
|
|
144
|
-
|
|
145
|
-
|
|
195
|
+
// Each gesture lets go as it happens: a wheel turned up, unless something inside takes
|
|
196
|
+
// it, it goes sideways or it zooms
|
|
146
197
|
const onwheel = (event: WheelEvent) => {
|
|
147
|
-
if (event.
|
|
198
|
+
if (event.ctrlKey || event.shiftKey || Math.abs(event.deltaX) > Math.abs(event.deltaY))
|
|
199
|
+
return;
|
|
200
|
+
if (event.deltaY < 0 && overflows(el) && !scrollsInside(event.target, el, event.deltaY))
|
|
201
|
+
letGo();
|
|
148
202
|
};
|
|
149
203
|
const onkeydown = (event: KeyboardEvent) => {
|
|
150
|
-
if (isUpKey(event))
|
|
204
|
+
if (isUpKey(event) && overflows(el)) letGo();
|
|
151
205
|
};
|
|
206
|
+
// A press on the scrollbar takes the view; one anywhere else is held until it is let go
|
|
152
207
|
const onpointerdown = (event: PointerEvent) => {
|
|
153
|
-
if (onScrollbar(event, el))
|
|
208
|
+
if (onScrollbar(event, el)) {
|
|
209
|
+
if (overflows(el)) letGo();
|
|
210
|
+
} else pressing = true;
|
|
154
211
|
};
|
|
212
|
+
const onpointerup = () => (pressing = false);
|
|
155
213
|
let touchY = 0;
|
|
156
214
|
const ontouchstart = (event: TouchEvent) => (touchY = event.touches[0]?.clientY ?? 0);
|
|
157
215
|
const ontouchmove = (event: TouchEvent) => {
|
|
158
216
|
const y = event.touches[0]?.clientY ?? 0;
|
|
159
217
|
// A finger moving down scrolls the content up
|
|
160
|
-
if (y > touchY && !scrollsInside(event.target, el, -1))
|
|
218
|
+
if (y > touchY && !scrollsInside(event.target, el, -1)) letGo();
|
|
161
219
|
touchY = y;
|
|
162
220
|
};
|
|
221
|
+
// A fold's toggle, by the pointer or a key, before the fold opens or shuts
|
|
222
|
+
const onclick = (event: MouseEvent) => {
|
|
223
|
+
const toggle = toggleOf(event.target);
|
|
224
|
+
if (!toggle || !content.contains(toggle)) return;
|
|
225
|
+
const fold = toggle.closest('[data-disclosure]') ?? toggle.parentElement ?? toggle;
|
|
226
|
+
toggled = {
|
|
227
|
+
element: toggle,
|
|
228
|
+
fold,
|
|
229
|
+
viewportTop: topIn(toggle, el),
|
|
230
|
+
height: fold.getBoundingClientRect().height,
|
|
231
|
+
until: performance.now() + TOGGLE_WINDOW,
|
|
232
|
+
keeping: false
|
|
233
|
+
};
|
|
234
|
+
};
|
|
163
235
|
|
|
164
236
|
const onscroll = () => {
|
|
165
|
-
const now = performance.now();
|
|
166
237
|
const top = el.scrollTop;
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
238
|
+
const end = below(el);
|
|
239
|
+
const movedUp = top < lastTop - SAME;
|
|
240
|
+
const movedDown = top > lastTop + SAME;
|
|
241
|
+
if (
|
|
242
|
+
// A move up the conversation did not make and no listener heard: a wheel over a
|
|
243
|
+
// frame, which takes it, or a selection dragged past the top. Not one that leaves
|
|
244
|
+
// the view at the end, as content shrinking does.
|
|
245
|
+
movedUp &&
|
|
246
|
+
Math.abs(top - ownTop) > SAME &&
|
|
247
|
+
(pressing || frameHasInput(el)) &&
|
|
248
|
+
(mode !== 'following' || end > threshold)
|
|
249
|
+
) {
|
|
250
|
+
letGo();
|
|
251
|
+
} else if (
|
|
252
|
+
mode === 'free' &&
|
|
253
|
+
end <= threshold &&
|
|
254
|
+
// Not inside the room left for a reply, well below where the content ends: following
|
|
255
|
+
// would take the spacer away and the text being read up with it
|
|
256
|
+
(end >= -threshold || spacer === 0) &&
|
|
257
|
+
// Not while a gesture up is still on its way, unless the person came back down
|
|
258
|
+
(movedDown || performance.now() - intentAt > INTENT_WINDOW)
|
|
259
|
+
) {
|
|
173
260
|
mode = 'following';
|
|
174
261
|
anchored = null;
|
|
175
262
|
spacer = 0;
|
|
176
263
|
}
|
|
177
|
-
atBottom =
|
|
264
|
+
atBottom = distance(el) <= threshold;
|
|
178
265
|
lastTop = top;
|
|
179
266
|
};
|
|
180
267
|
|
|
@@ -182,8 +269,10 @@
|
|
|
182
269
|
// after layout and before paint, so correcting here never shows a frame
|
|
183
270
|
// at the old position.
|
|
184
271
|
const observer = new ResizeObserver(() => {
|
|
185
|
-
|
|
186
|
-
|
|
272
|
+
if (!keepToggle(el)) {
|
|
273
|
+
settleSpacer();
|
|
274
|
+
if (mode === 'following') moveTo(el.scrollHeight);
|
|
275
|
+
}
|
|
187
276
|
atBottom = mode === 'following' || distance(el) <= threshold;
|
|
188
277
|
lastTop = el.scrollTop;
|
|
189
278
|
});
|
|
@@ -196,6 +285,9 @@
|
|
|
196
285
|
el.addEventListener('pointerdown', onpointerdown);
|
|
197
286
|
el.addEventListener('touchstart', ontouchstart, { passive: true });
|
|
198
287
|
el.addEventListener('touchmove', ontouchmove, { passive: true });
|
|
288
|
+
el.addEventListener('click', onclick, { capture: true });
|
|
289
|
+
window.addEventListener('pointerup', onpointerup);
|
|
290
|
+
window.addEventListener('pointercancel', onpointerup);
|
|
199
291
|
|
|
200
292
|
return () => {
|
|
201
293
|
observer.disconnect();
|
|
@@ -205,6 +297,11 @@
|
|
|
205
297
|
el.removeEventListener('pointerdown', onpointerdown);
|
|
206
298
|
el.removeEventListener('touchstart', ontouchstart);
|
|
207
299
|
el.removeEventListener('touchmove', ontouchmove);
|
|
300
|
+
el.removeEventListener('click', onclick, { capture: true });
|
|
301
|
+
window.removeEventListener('pointerup', onpointerup);
|
|
302
|
+
window.removeEventListener('pointercancel', onpointerup);
|
|
303
|
+
pressing = false;
|
|
304
|
+
toggled = null;
|
|
208
305
|
if (viewport === el) viewport = null;
|
|
209
306
|
};
|
|
210
307
|
}
|