@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.
Files changed (107) hide show
  1. package/dist/base.css +38 -0
  2. package/dist/components/activity/ActivityContent.svelte +7 -3
  3. package/dist/components/activity/ActivityStep.svelte +28 -11
  4. package/dist/components/activity/ActivityStep.svelte.d.ts +6 -0
  5. package/dist/components/activity/ActivityTrigger.svelte +5 -2
  6. package/dist/components/app-shell/AppShellBar.svelte +9 -4
  7. package/dist/components/app-shell/AppShellHeader.svelte +9 -5
  8. package/dist/components/approval/Approval.svelte +7 -4
  9. package/dist/components/button/Button.svelte +50 -26
  10. package/dist/components/card/Card.svelte +5 -2
  11. package/dist/components/changes-summary/ChangesSummary.svelte +11 -8
  12. package/dist/components/choice-cards/ChoiceCards.svelte +5 -2
  13. package/dist/components/collapsible/CollapsibleTrigger.svelte +5 -2
  14. package/dist/components/color-field/ColorField.svelte +397 -0
  15. package/dist/components/color-field/ColorField.svelte.d.ts +41 -0
  16. package/dist/components/command/styles.d.ts +8 -9
  17. package/dist/components/command/styles.js +11 -10
  18. package/dist/components/composer/ComposerAttachment.svelte +7 -3
  19. package/dist/components/composer/ComposerAttachments.svelte +5 -1
  20. package/dist/components/composer/ComposerModelPicker.svelte +37 -35
  21. package/dist/components/composer/ComposerRoot.svelte +9 -5
  22. package/dist/components/composer/ComposerTextarea.svelte +9 -6
  23. package/dist/components/composer/ComposerToggle.svelte +7 -4
  24. package/dist/components/composer/ComposerToolbar.svelte +5 -1
  25. package/dist/components/composer/ComposerTray.svelte +10 -7
  26. package/dist/components/conversation/ConversationContent.svelte +0 -2
  27. package/dist/components/conversation/ConversationRoot.svelte +124 -27
  28. package/dist/components/conversation/ConversationScrollButton.svelte +10 -7
  29. package/dist/components/conversation/scrolling.d.ts +18 -4
  30. package/dist/components/conversation/scrolling.js +28 -6
  31. package/dist/components/dialog/ConfirmDialog.svelte +5 -2
  32. package/dist/components/dialog/styles.d.ts +3 -4
  33. package/dist/components/dialog/styles.js +7 -6
  34. package/dist/components/frame/Frame.svelte +8 -5
  35. package/dist/components/hover-card/HoverCardContent.svelte +5 -1
  36. package/dist/components/input/Input.svelte +12 -8
  37. package/dist/components/markdown/MarkdownCode.svelte +0 -1
  38. package/dist/components/markdown/MarkdownDiagram.svelte +1 -2
  39. package/dist/components/markdown/styles.d.ts +0 -2
  40. package/dist/components/markdown/styles.js +0 -2
  41. package/dist/components/message/MessageActions.svelte +8 -4
  42. package/dist/components/message/MessageContent.svelte +6 -2
  43. package/dist/components/message/MessagePending.svelte +5 -2
  44. package/dist/components/message/MessageRoot.svelte +10 -4
  45. package/dist/components/message/MessageTime.svelte +5 -2
  46. package/dist/components/message/styles.d.ts +2 -2
  47. package/dist/components/message/styles.js +5 -3
  48. package/dist/components/notice/Notice.svelte +13 -4
  49. package/dist/components/plan/Plan.svelte +13 -10
  50. package/dist/components/popover/PopoverContent.svelte +8 -1
  51. package/dist/components/questionnaire/Questionnaire.svelte +12 -9
  52. package/dist/components/queued-message/QueuedMessage.svelte +14 -7
  53. package/dist/components/rail/RailItem.svelte +16 -7
  54. package/dist/components/rail/RailRoot.svelte +9 -4
  55. package/dist/components/rail/RailSeparator.svelte +5 -2
  56. package/dist/components/reasoning/ReasoningContent.svelte +6 -3
  57. package/dist/components/reasoning/ReasoningTrigger.svelte +5 -2
  58. package/dist/components/resize-handle/ResizeHandle.svelte +11 -7
  59. package/dist/components/search-button/SearchButton.svelte +6 -3
  60. package/dist/components/segmented/SegmentedControl.svelte +6 -3
  61. package/dist/components/settings-group/SettingsGroup.svelte +5 -2
  62. package/dist/components/sidebar/SidebarContent.svelte +8 -9
  63. package/dist/components/sidebar/SidebarFolder.svelte +8 -5
  64. package/dist/components/sidebar/SidebarFooter.svelte +5 -2
  65. package/dist/components/sidebar/SidebarGroup.svelte +11 -8
  66. package/dist/components/sidebar/SidebarHeader.svelte +9 -4
  67. package/dist/components/sidebar/SidebarItem.svelte +14 -9
  68. package/dist/components/split-button/SplitButton.svelte +5 -2
  69. package/dist/components/suggestions/SuggestionsItem.svelte +6 -3
  70. package/dist/components/suggestions/SuggestionsRoot.svelte +5 -1
  71. package/dist/components/tab-strip/TabStrip.svelte +21 -16
  72. package/dist/components/tabs/Tabs.svelte +7 -4
  73. package/dist/components/textarea/Textarea.svelte +6 -2
  74. package/dist/components/theme/Theme.svelte +32 -3
  75. package/dist/components/toast/Toaster.svelte +14 -5
  76. package/dist/components/toggle-group/ToggleGroupRoot.svelte +5 -1
  77. package/dist/components/tool/ToolContent.svelte +8 -4
  78. package/dist/components/tool/ToolSection.svelte +7 -4
  79. package/dist/components/tool/ToolTrigger.svelte +5 -2
  80. package/dist/components/tooltip/TooltipContent.svelte +7 -4
  81. package/dist/components/work-fold/WorkFold.svelte +9 -6
  82. package/dist/index.d.ts +2 -0
  83. package/dist/index.js +1 -0
  84. package/dist/internal/Code.svelte +6 -4
  85. package/dist/internal/Glyph.svelte +23 -2
  86. package/dist/internal/Glyph.svelte.d.ts +4 -1
  87. package/dist/internal/control.d.ts +6 -6
  88. package/dist/internal/control.js +9 -7
  89. package/dist/internal/hsv.d.ts +18 -0
  90. package/dist/internal/hsv.js +63 -0
  91. package/dist/internal/kinds.d.ts +1 -1
  92. package/dist/internal/kinds.js +3 -3
  93. package/dist/internal/layer.d.ts +10 -11
  94. package/dist/internal/layer.js +14 -13
  95. package/dist/internal/toggle.d.ts +8 -8
  96. package/dist/internal/toggle.js +22 -10
  97. package/dist/preset.d.ts +12 -3
  98. package/dist/preset.js +18 -4
  99. package/dist/tokens.stylex.d.ts +13 -3
  100. package/dist/tokens.stylex.js +25 -14
  101. package/package.json +1 -1
  102. package/skills/building-ui/SKILL.md +1 -1
  103. package/skills/building-ui/references/components.md +24 -0
  104. package/skills/markdown/SKILL.md +1 -1
  105. package/skills/setup/SKILL.md +9 -3
  106. package/skills/styling/SKILL.md +5 -2
  107. package/skills/theming/SKILL.md +48 -4
@@ -0,0 +1,397 @@
1
+ <!--
2
+ A colour: a swatch that opens Narvi's picker, and the colour as a hex, to type or paste any
3
+ CSS colour into. The picker is an area of saturation and brightness over a strip of hues,
4
+ each moved by the pointer or the arrow keys, and a pipette where the browser can take a
5
+ colour from the screen. It gives the colour back as `#rrggbb`. (Eregion's ColorField.)
6
+ -->
7
+ <script lang="ts" module>
8
+ import * as stylex from '@stylexjs/stylex';
9
+ import { Popover } from 'bits-ui';
10
+ import { untrack } from 'svelte';
11
+ import type { HTMLAttributes } from 'svelte/elements';
12
+ import type { ControlSize } from '../../internal/control.js';
13
+ import Glyph from '../../internal/Glyph.svelte';
14
+ import { hexToHsv, hsvToHex, parseHex, toHex, type Hsv } from '../../internal/hsv.js';
15
+ import { shared } from '../../internal/shared.js';
16
+ import { attrs, type Sx } from '../../internal/sx.js';
17
+ import { colors, density, radius } from '../../tokens.stylex.js';
18
+ import { media } from '../../media.stylex.js';
19
+ import Button from '../button/Button.svelte';
20
+ import { getFieldContext } from '../field/context.js';
21
+ import Input from '../input/Input.svelte';
22
+ import PopoverContent from '../popover/PopoverContent.svelte';
23
+
24
+ export type ColorFieldSize = ControlSize;
25
+
26
+ /** Words for the parts that need them. */
27
+ export type ColorFieldLabels = {
28
+ /** The swatch, which opens the picker: "Pick a colour for {label}" by default. */
29
+ pick?: string | undefined;
30
+ /** The area: "Saturation and brightness" by default. */
31
+ area?: string | undefined;
32
+ /** "Saturation" and "Brightness", read out with the area's place. */
33
+ saturation?: string | undefined;
34
+ brightness?: string | undefined;
35
+ /** The strip: "Hue" by default. */
36
+ hue?: string | undefined;
37
+ /** The pipette: "Take a colour from the screen" by default. */
38
+ eyedropper?: string | undefined;
39
+ };
40
+
41
+ export type ColorFieldProps = Omit<
42
+ HTMLAttributes<HTMLDivElement>,
43
+ 'children' | 'onchange' | 'class'
44
+ > & {
45
+ /**
46
+ * The colour. Bindable. Any CSS colour is taken (a hex, a name, `rgb()`, `oklch()`); the
47
+ * field shows it, and gives it back, as `#rrggbb`, without its alpha.
48
+ */
49
+ value?: string | undefined;
50
+ /** Called with the colour as `#rrggbb` as it changes: while dragging, and as it is typed. */
51
+ onchange?: ((color: string) => void) | undefined;
52
+ /**
53
+ * Names the colour, such as "Accent": the hex field takes it, unless a surrounding Field
54
+ * labels it, and the swatch and the picker are named from it.
55
+ */
56
+ label: string;
57
+ size?: ColorFieldSize | undefined;
58
+ disabled?: boolean | undefined;
59
+ /** Words for the swatch and the picker's parts. */
60
+ labels?: ColorFieldLabels | undefined;
61
+ sx?: Sx | undefined;
62
+ class?: string | undefined;
63
+ };
64
+
65
+ /** How far an arrow key moves, and with Shift or Page Up and Page Down. */
66
+ const STEP = 0.01;
67
+ const LEAP = 0.1;
68
+
69
+ const clamp = (value: number, max = 1) => Math.min(Math.max(value, 0), max);
70
+ const percent = (value: number) => Math.round(value * 100);
71
+
72
+ /** A length at the window's density (`density` in the tokens). */
73
+ const d = (rem: string) => `calc(${rem} * ${density.factor})`;
74
+
75
+ const styles = stylex.create({
76
+ field: { display: 'flex', alignItems: 'center', gap: d('0.5rem'), minWidth: 0 },
77
+ // A control's square, its edge the 3:1 boundary every control has, over the colour itself
78
+ swatch: {
79
+ flexShrink: 0,
80
+ boxSizing: 'border-box',
81
+ margin: 0,
82
+ padding: 0,
83
+ borderWidth: 0,
84
+ borderRadius: radius.control,
85
+ boxShadow: `inset 0 0 0 1px ${colors.borderControl}`,
86
+ cursor: { default: 'pointer', ':disabled': 'not-allowed' },
87
+ opacity: { default: 1, ':disabled': 0.5 },
88
+ // Forced colours drop the fill; the colour is still in the hex beside it
89
+ forcedColorAdjust: 'none'
90
+ },
91
+ sm: { width: d('1.75rem'), height: d('1.75rem'), borderRadius: radius.item },
92
+ md: { width: d('2.125rem'), height: d('2.125rem') },
93
+ lg: { width: d('2.5rem'), height: d('2.5rem'), borderRadius: radius.panel },
94
+ hex: { width: '7.5rem', fontVariantNumeric: 'tabular-nums' },
95
+ // The area: saturation across, brightness up
96
+ area: {
97
+ position: 'relative',
98
+ height: '9rem',
99
+ borderRadius: radius.control,
100
+ touchAction: 'none',
101
+ cursor: 'crosshair'
102
+ },
103
+ spectrum: {
104
+ display: 'block',
105
+ width: '100%',
106
+ height: '100%',
107
+ borderRadius: 'inherit'
108
+ },
109
+ row: { display: 'flex', alignItems: 'center', gap: d('0.5rem') },
110
+ hue: {
111
+ position: 'relative',
112
+ flexGrow: 1,
113
+ height: '0.75rem',
114
+ borderRadius: radius.pill,
115
+ touchAction: 'none',
116
+ cursor: 'pointer'
117
+ },
118
+ // A ring in the colour it stands on, white with a dark hairline either side, so it shows
119
+ // on any colour
120
+ thumb: {
121
+ position: 'absolute',
122
+ boxSizing: 'border-box',
123
+ width: '0.875rem',
124
+ height: '0.875rem',
125
+ borderRadius: radius.pill,
126
+ borderWidth: '2px',
127
+ borderStyle: 'solid',
128
+ borderColor: colors.thumb,
129
+ boxShadow: `0 0 0 1px ${colors.scrim}, inset 0 0 0 1px ${colors.scrim}`,
130
+ translate: '-50% -50%',
131
+ pointerEvents: 'none',
132
+ forcedColorAdjust: 'none'
133
+ },
134
+ // The strip's thumb sits on its middle
135
+ middle: { top: '50%' },
136
+ // Lit by the pointer only: a thumb that grows while held
137
+ held: { scale: { default: null, [media.motion]: 1.15 } }
138
+ });
139
+ </script>
140
+
141
+ <script lang="ts">
142
+ let {
143
+ value = $bindable('#000000'),
144
+ onchange,
145
+ label,
146
+ size = 'md',
147
+ disabled,
148
+ labels,
149
+ sx,
150
+ class: className,
151
+ ...rest
152
+ }: ColorFieldProps = $props();
153
+
154
+ const field = getFieldContext();
155
+ const off = $derived(disabled ?? field?.disabled ?? false);
156
+ const words = $derived({
157
+ pick: labels?.pick ?? `Pick a colour for ${label}`,
158
+ area: labels?.area ?? 'Saturation and brightness',
159
+ saturation: labels?.saturation ?? 'Saturation',
160
+ brightness: labels?.brightness ?? 'Brightness',
161
+ hue: labels?.hue ?? 'Hue',
162
+ eyedropper: labels?.eyedropper ?? 'Take a colour from the screen'
163
+ });
164
+
165
+ // A hex is read on the server too; any other colour once in the browser
166
+ let hsv = $state<Hsv>(hexToHsv(untrack(() => parseHex(value ?? '') ?? '#000000')));
167
+ const hex = $derived(hsvToHex(hsv));
168
+ // What is being typed into the hex field, until it is left
169
+ let typed = $state<string | null>(null);
170
+ let open = $state(false);
171
+ let holding = $state<'area' | 'hue' | null>(null);
172
+ // The picker is drawn only once it opens, in the browser, so this is never read on the server
173
+ const canPipette = typeof window !== 'undefined' && 'EyeDropper' in window;
174
+
175
+ // A colour given from outside moves the picker, keeping its hue where the colour has none
176
+ $effect.pre(() => {
177
+ const given = toHex(value ?? '');
178
+ untrack(() => {
179
+ if (given !== undefined && given !== hsvToHex(hsv)) hsv = hexToHsv(given, hsv.h);
180
+ });
181
+ });
182
+
183
+ function set(next: Hsv) {
184
+ hsv = next;
185
+ const color = hsvToHex(next);
186
+ if (color === value) return;
187
+ value = color;
188
+ onchange?.(color);
189
+ }
190
+
191
+ // The area, in the hue: white to the hue across, then to black down. Drawn small and
192
+ // stretched, as a smooth field loses nothing to it; a stylesheet would draw it as a gradient
193
+ // between colours, which Narvi keeps out of its surfaces.
194
+ function paintArea(canvas: HTMLCanvasElement) {
195
+ const hue = hsv.h;
196
+ const context = canvas.getContext('2d');
197
+ if (!context) return;
198
+ const { width, height } = canvas;
199
+ context.fillStyle = `hsl(${hue} 100% 50%)`;
200
+ context.fillRect(0, 0, width, height);
201
+ const white = context.createLinearGradient(0, 0, width, 0);
202
+ white.addColorStop(0, '#ffffff');
203
+ white.addColorStop(1, 'rgb(255 255 255 / 0)');
204
+ context.fillStyle = white;
205
+ context.fillRect(0, 0, width, height);
206
+ const black = context.createLinearGradient(0, 0, 0, height);
207
+ black.addColorStop(0, 'rgb(0 0 0 / 0)');
208
+ black.addColorStop(1, '#000000');
209
+ context.fillStyle = black;
210
+ context.fillRect(0, 0, width, height);
211
+ }
212
+
213
+ function paintHue(canvas: HTMLCanvasElement) {
214
+ const context = canvas.getContext('2d');
215
+ if (!context) return;
216
+ const strip = context.createLinearGradient(0, 0, canvas.width, 0);
217
+ for (let degree = 0; degree <= 360; degree += 60)
218
+ strip.addColorStop(degree / 360, `hsl(${degree} 100% 50%)`);
219
+ context.fillStyle = strip;
220
+ context.fillRect(0, 0, canvas.width, canvas.height);
221
+ }
222
+
223
+ /** Follows the pointer from a press on `part` until it is let go, anywhere on the page. */
224
+ function drag(part: 'area' | 'hue', place: (x: number, y: number) => void) {
225
+ return (event: PointerEvent & { currentTarget: HTMLElement }) => {
226
+ if (event.button !== 0) return;
227
+ event.preventDefault();
228
+ const element = event.currentTarget;
229
+ element.focus();
230
+ element.setPointerCapture(event.pointerId);
231
+ holding = part;
232
+ const at = (moving: PointerEvent) => {
233
+ const box = element.getBoundingClientRect();
234
+ place(
235
+ clamp((moving.clientX - box.left) / box.width),
236
+ clamp((moving.clientY - box.top) / box.height)
237
+ );
238
+ };
239
+ at(event);
240
+ const up = () => {
241
+ holding = null;
242
+ element.removeEventListener('pointermove', at);
243
+ element.removeEventListener('pointerup', up);
244
+ element.removeEventListener('pointercancel', up);
245
+ };
246
+ element.addEventListener('pointermove', at);
247
+ element.addEventListener('pointerup', up);
248
+ element.addEventListener('pointercancel', up);
249
+ };
250
+ }
251
+
252
+ const pressArea = drag('area', (x, y) => set({ h: hsv.h, s: x, v: 1 - y }));
253
+ const pressHue = drag('hue', (x) => set({ ...hsv, h: x * 359 }));
254
+
255
+ function areaKey(event: KeyboardEvent) {
256
+ const step = event.shiftKey ? LEAP : STEP;
257
+ let { s, v } = hsv;
258
+ if (event.key === 'ArrowRight') s += step;
259
+ else if (event.key === 'ArrowLeft') s -= step;
260
+ else if (event.key === 'ArrowUp') v += step;
261
+ else if (event.key === 'ArrowDown') v -= step;
262
+ else if (event.key === 'PageUp') v += LEAP;
263
+ else if (event.key === 'PageDown') v -= LEAP;
264
+ else if (event.key === 'Home') s = 0;
265
+ else if (event.key === 'End') s = 1;
266
+ else return;
267
+ event.preventDefault();
268
+ set({ h: hsv.h, s: clamp(s), v: clamp(v) });
269
+ }
270
+
271
+ function hueKey(event: KeyboardEvent) {
272
+ const step = event.shiftKey ? 10 : 1;
273
+ let { h } = hsv;
274
+ if (event.key === 'ArrowRight' || event.key === 'ArrowUp') h += step;
275
+ else if (event.key === 'ArrowLeft' || event.key === 'ArrowDown') h -= step;
276
+ else if (event.key === 'PageUp') h += 10;
277
+ else if (event.key === 'PageDown') h -= 10;
278
+ else if (event.key === 'Home') h = 0;
279
+ else if (event.key === 'End') h = 359;
280
+ else return;
281
+ event.preventDefault();
282
+ set({ ...hsv, h: clamp(Math.round(h), 359) });
283
+ }
284
+
285
+ async function pipette() {
286
+ const dropper = new (
287
+ window as unknown as {
288
+ EyeDropper: new () => { open(): Promise<{ sRGBHex: string }> };
289
+ }
290
+ ).EyeDropper();
291
+ try {
292
+ const { sRGBHex } = await dropper.open();
293
+ const color = toHex(sRGBHex);
294
+ if (color !== undefined) set(hexToHsv(color, hsv.h));
295
+ } catch {
296
+ // Escape, or a click that took nothing: the colour stays
297
+ }
298
+ }
299
+
300
+ function type(text: string) {
301
+ typed = text;
302
+ const color = toHex(text);
303
+ if (color !== undefined && color !== hex) set(hexToHsv(color, hsv.h));
304
+ }
305
+ </script>
306
+
307
+ <div data-slot="color-field" {...rest} {...attrs([styles.field, sx], className)}>
308
+ <Popover.Root bind:open>
309
+ <Popover.Trigger
310
+ disabled={off}
311
+ aria-label={words.pick}
312
+ data-slot="color-field-swatch"
313
+ {...attrs([styles.swatch, styles[size], shared.focusable])}
314
+ style="background-color: {hex}"
315
+ />
316
+ <PopoverContent width="15rem" layout="column" data-slot="color-field-picker">
317
+ <div
318
+ role="slider"
319
+ tabindex="0"
320
+ aria-label={words.area}
321
+ aria-valuemin={0}
322
+ aria-valuemax={100}
323
+ aria-valuenow={percent(hsv.s)}
324
+ aria-valuetext="{words.saturation} {percent(hsv.s)}%, {words.brightness} {percent(hsv.v)}%"
325
+ data-slot="color-field-area"
326
+ onpointerdown={pressArea}
327
+ onkeydown={areaKey}
328
+ {...stylex.attrs(styles.area, shared.focusable)}
329
+ >
330
+ <canvas
331
+ width="240"
332
+ height="144"
333
+ aria-hidden="true"
334
+ {@attach paintArea}
335
+ {...stylex.attrs(styles.spectrum)}
336
+ ></canvas>
337
+ <span
338
+ {...stylex.attrs(styles.thumb, holding === 'area' && styles.held)}
339
+ style="left: {hsv.s * 100}%; top: {(1 - hsv.v) * 100}%; background-color: {hex}"
340
+ ></span>
341
+ </div>
342
+ <div {...stylex.attrs(styles.row)}>
343
+ <div
344
+ role="slider"
345
+ tabindex="0"
346
+ aria-label={words.hue}
347
+ aria-valuemin={0}
348
+ aria-valuemax={359}
349
+ aria-valuenow={Math.round(hsv.h)}
350
+ aria-valuetext="{Math.round(hsv.h)}°"
351
+ data-slot="color-field-hue"
352
+ onpointerdown={pressHue}
353
+ onkeydown={hueKey}
354
+ {...stylex.attrs(styles.hue, shared.focusable)}
355
+ >
356
+ <canvas
357
+ width="360"
358
+ height="1"
359
+ aria-hidden="true"
360
+ {@attach paintHue}
361
+ {...stylex.attrs(styles.spectrum)}
362
+ ></canvas>
363
+ <span
364
+ {...stylex.attrs(styles.thumb, styles.middle, holding === 'hue' && styles.held)}
365
+ style="left: {(hsv.h / 359) * 100}%; background-color: hsl({hsv.h} 100% 50%)"
366
+ ></span>
367
+ </div>
368
+ {#if canPipette}
369
+ <Button
370
+ variant="ghost"
371
+ size="sm"
372
+ iconOnly
373
+ aria-label={words.eyedropper}
374
+ onclick={pipette}
375
+ >
376
+ <Glyph name="pipette" size={16} />
377
+ </Button>
378
+ {/if}
379
+ </div>
380
+ </PopoverContent>
381
+ </Popover.Root>
382
+ <Input
383
+ {size}
384
+ value={typed ?? hex}
385
+ disabled={off}
386
+ spellcheck="false"
387
+ autocomplete="off"
388
+ aria-label={field?.id ? undefined : label}
389
+ data-slot="color-field-hex"
390
+ sx={styles.hex}
391
+ oninput={(event) => type(event.currentTarget.value)}
392
+ onblur={() => (typed = null)}
393
+ onkeydown={(event) => {
394
+ if (event.key === 'Enter') typed = null;
395
+ }}
396
+ />
397
+ </div>
@@ -0,0 +1,41 @@
1
+ import type { HTMLAttributes } from 'svelte/elements';
2
+ import type { ControlSize } from '../../internal/control.js';
3
+ import { type Sx } from '../../internal/sx.js';
4
+ export type ColorFieldSize = ControlSize;
5
+ /** Words for the parts that need them. */
6
+ export type ColorFieldLabels = {
7
+ /** The swatch, which opens the picker: "Pick a colour for {label}" by default. */
8
+ pick?: string | undefined;
9
+ /** The area: "Saturation and brightness" by default. */
10
+ area?: string | undefined;
11
+ /** "Saturation" and "Brightness", read out with the area's place. */
12
+ saturation?: string | undefined;
13
+ brightness?: string | undefined;
14
+ /** The strip: "Hue" by default. */
15
+ hue?: string | undefined;
16
+ /** The pipette: "Take a colour from the screen" by default. */
17
+ eyedropper?: string | undefined;
18
+ };
19
+ export type ColorFieldProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onchange' | 'class'> & {
20
+ /**
21
+ * The colour. Bindable. Any CSS colour is taken (a hex, a name, `rgb()`, `oklch()`); the
22
+ * field shows it, and gives it back, as `#rrggbb`, without its alpha.
23
+ */
24
+ value?: string | undefined;
25
+ /** Called with the colour as `#rrggbb` as it changes: while dragging, and as it is typed. */
26
+ onchange?: ((color: string) => void) | undefined;
27
+ /**
28
+ * Names the colour, such as "Accent": the hex field takes it, unless a surrounding Field
29
+ * labels it, and the swatch and the picker are named from it.
30
+ */
31
+ label: string;
32
+ size?: ColorFieldSize | undefined;
33
+ disabled?: boolean | undefined;
34
+ /** Words for the swatch and the picker's parts. */
35
+ labels?: ColorFieldLabels | undefined;
36
+ sx?: Sx | undefined;
37
+ class?: string | undefined;
38
+ };
39
+ declare const ColorField: import("svelte").Component<ColorFieldProps, {}, "value">;
40
+ type ColorField = ReturnType<typeof ColorField>;
41
+ export default ColorField;
@@ -22,7 +22,7 @@ export declare const command: Readonly<{
22
22
  readonly input: Readonly<{
23
23
  readonly flexGrow: stylex.StyleXClassNameFor<"flexGrow", 1>;
24
24
  readonly minWidth: stylex.StyleXClassNameFor<"minWidth", 0>;
25
- readonly height: stylex.StyleXClassNameFor<"height", "3rem">;
25
+ readonly height: stylex.StyleXClassNameFor<"height", string>;
26
26
  readonly margin: stylex.StyleXClassNameFor<"margin", 0>;
27
27
  readonly padding: stylex.StyleXClassNameFor<"padding", 0>;
28
28
  readonly borderWidth: stylex.StyleXClassNameFor<"borderWidth", 0>;
@@ -40,16 +40,15 @@ export declare const command: Readonly<{
40
40
  readonly maxHeight: stylex.StyleXClassNameFor<"maxHeight", "min(24rem, 60dvh)">;
41
41
  readonly overflowY: stylex.StyleXClassNameFor<"overflowY", "auto">;
42
42
  readonly overscrollBehavior: stylex.StyleXClassNameFor<"overscrollBehavior", "contain">;
43
- readonly padding: stylex.StyleXClassNameFor<"padding", "0.375rem">;
44
- readonly scrollbarWidth: stylex.StyleXClassNameFor<"scrollbarWidth", "thin">;
45
- readonly scrollPaddingBlock: stylex.StyleXClassNameFor<"scrollPaddingBlock", "0.375rem">;
43
+ readonly padding: stylex.StyleXClassNameFor<"padding", string>;
44
+ readonly scrollPaddingBlock: stylex.StyleXClassNameFor<"scrollPaddingBlock", string>;
46
45
  }>;
47
46
  readonly item: Readonly<{
48
47
  readonly display: stylex.StyleXClassNameFor<"display", "flex">;
49
48
  readonly alignItems: stylex.StyleXClassNameFor<"alignItems", "center">;
50
49
  readonly gap: stylex.StyleXClassNameFor<"gap", "0.625rem">;
51
- readonly minHeight: stylex.StyleXClassNameFor<"minHeight", "2.375rem">;
52
- readonly paddingInline: stylex.StyleXClassNameFor<"paddingInline", "0.625rem">;
50
+ readonly minHeight: stylex.StyleXClassNameFor<"minHeight", string>;
51
+ readonly paddingInline: stylex.StyleXClassNameFor<"paddingInline", string>;
53
52
  readonly borderRadius: stylex.StyleXClassNameFor<"borderRadius", string>;
54
53
  readonly color: stylex.StyleXClassNameFor<"color", string>;
55
54
  readonly cursor: stylex.StyleXClassNameFor<"cursor", "default">;
@@ -70,7 +69,7 @@ export declare const command: Readonly<{
70
69
  readonly alignItems: stylex.StyleXClassNameFor<"alignItems", "center">;
71
70
  readonly gap: stylex.StyleXClassNameFor<"gap", "0.125rem">;
72
71
  readonly flexShrink: stylex.StyleXClassNameFor<"flexShrink", 0>;
73
- readonly marginInlineEnd: stylex.StyleXClassNameFor<"marginInlineEnd", "-0.5rem">;
72
+ readonly marginInlineEnd: stylex.StyleXClassNameFor<"marginInlineEnd", string>;
74
73
  }>;
75
74
  readonly badge: Readonly<{
76
75
  readonly '--narvi-icon-size': stylex.StyleXClassNameFor<"--narvi-icon-size", "0.875rem">;
@@ -86,7 +85,7 @@ export declare const command: Readonly<{
86
85
  readonly alignItems: stylex.StyleXClassNameFor<"alignItems", "center">;
87
86
  readonly gap: stylex.StyleXClassNameFor<"gap", string>;
88
87
  readonly minWidth: stylex.StyleXClassNameFor<"minWidth", 0>;
89
- readonly paddingBlock: stylex.StyleXClassNameFor<"paddingBlock", "0.375rem">;
88
+ readonly paddingBlock: stylex.StyleXClassNameFor<"paddingBlock", string>;
90
89
  }>;
91
90
  readonly wrapLabel: Readonly<{
92
91
  readonly minWidth: stylex.StyleXClassNameFor<"minWidth", 0>;
@@ -125,7 +124,7 @@ export declare const command: Readonly<{
125
124
  readonly alignItems: stylex.StyleXClassNameFor<"alignItems", "center">;
126
125
  readonly gap: stylex.StyleXClassNameFor<"gap", string>;
127
126
  readonly flexShrink: stylex.StyleXClassNameFor<"flexShrink", 0>;
128
- readonly minHeight: stylex.StyleXClassNameFor<"minHeight", "2.5rem">;
127
+ readonly minHeight: stylex.StyleXClassNameFor<"minHeight", string>;
129
128
  readonly paddingInline: stylex.StyleXClassNameFor<"paddingInline", string>;
130
129
  readonly borderTopWidth: stylex.StyleXClassNameFor<"borderTopWidth", "1px">;
131
130
  readonly borderTopStyle: stylex.StyleXClassNameFor<"borderTopStyle", "solid">;
@@ -1,7 +1,9 @@
1
1
  import * as stylex from '@stylexjs/stylex';
2
- import { colors, font, radius, space } from '../../tokens.stylex.js';
2
+ import { colors, density, font, radius, space } from '../../tokens.stylex.js';
3
3
  import { media } from '../../media.stylex.js';
4
4
  const SELECTED = ':is([data-selected])';
5
+ /** A length at the window's density (`density` in the tokens). */
6
+ const d = (rem) => `calc(${rem} * ${density.factor})`;
5
7
  export const command = stylex.create({
6
8
  root: {
7
9
  display: 'flex',
@@ -25,7 +27,7 @@ export const command = stylex.create({
25
27
  input: {
26
28
  flexGrow: 1,
27
29
  minWidth: 0,
28
- height: '3rem',
30
+ height: d('3rem'),
29
31
  margin: 0,
30
32
  padding: 0,
31
33
  borderWidth: 0,
@@ -40,16 +42,15 @@ export const command = stylex.create({
40
42
  maxHeight: 'min(24rem, 60dvh)',
41
43
  overflowY: 'auto',
42
44
  overscrollBehavior: 'contain',
43
- padding: '0.375rem',
44
- scrollbarWidth: 'thin',
45
- scrollPaddingBlock: '0.375rem'
45
+ padding: d('0.375rem'),
46
+ scrollPaddingBlock: d('0.375rem')
46
47
  },
47
48
  item: {
48
49
  display: 'flex',
49
50
  alignItems: 'center',
50
51
  gap: '0.625rem',
51
- minHeight: '2.375rem',
52
- paddingInline: '0.625rem',
52
+ minHeight: d('2.375rem'),
53
+ paddingInline: d('0.625rem'),
53
54
  borderRadius: radius.control,
54
55
  color: colors.text,
55
56
  cursor: 'default',
@@ -75,7 +76,7 @@ export const command = stylex.create({
75
76
  alignItems: 'center',
76
77
  gap: '0.125rem',
77
78
  flexShrink: 0,
78
- marginInlineEnd: '-0.5rem'
79
+ marginInlineEnd: d('-0.5rem')
79
80
  },
80
81
  badge: {
81
82
  '--narvi-icon-size': '0.875rem',
@@ -92,7 +93,7 @@ export const command = stylex.create({
92
93
  alignItems: 'center',
93
94
  gap: space.x2,
94
95
  minWidth: 0,
95
- paddingBlock: '0.375rem'
96
+ paddingBlock: d('0.375rem')
96
97
  },
97
98
  wrapLabel: {
98
99
  minWidth: 0,
@@ -129,7 +130,7 @@ export const command = stylex.create({
129
130
  alignItems: 'center',
130
131
  gap: space.x4,
131
132
  flexShrink: 0,
132
- minHeight: '2.5rem',
133
+ minHeight: d('2.5rem'),
133
134
  paddingInline: space.x4,
134
135
  borderTopWidth: '1px',
135
136
  borderTopStyle: 'solid',
@@ -4,7 +4,7 @@
4
4
  import Glyph from '../../internal/Glyph.svelte';
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 { useComposer } from './context.js';
10
10
 
@@ -22,6 +22,9 @@
22
22
  return `${(bytes / 1_000_000).toFixed(1)} MB`;
23
23
  }
24
24
 
25
+ /** A length at the window's density (`density` in the tokens). */
26
+ const d = (rem: string) => `calc(${rem} * ${density.factor})`;
27
+
25
28
  const styles = stylex.create({
26
29
  // A chip: the thumbnail's radius plus the padding, so the corners sit concentric
27
30
  chip: {
@@ -31,8 +34,9 @@
31
34
  alignItems: 'center',
32
35
  gap: '0.5rem',
33
36
  maxWidth: '13.75rem',
34
- height: '2.75rem',
35
- padding: '0.375rem',
37
+ // The thumbnail, which keeps its size, and the padding around it
38
+ height: `calc(2rem + ${d('0.75rem')})`,
39
+ padding: d('0.375rem'),
36
40
  // Clear of the remove button on the corner
37
41
  paddingInlineEnd: '1rem',
38
42
  borderRadius: radius.card,
@@ -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';
@@ -14,11 +15,14 @@
14
15
  children?: Snippet<[File]> | undefined;
15
16
  };
16
17
 
18
+ /** A length at the window's density (`density` in the tokens). */
19
+ const d = (rem: string) => `calc(${rem} * ${density.factor})`;
20
+
17
21
  const styles = stylex.create({
18
22
  list: {
19
23
  display: 'flex',
20
24
  flexWrap: 'wrap',
21
- gap: '0.5rem',
25
+ gap: d('0.5rem'),
22
26
  margin: 0,
23
27
  // Room above for the remove buttons, which sit on the chips' corners
24
28
  paddingTop: '0.375rem',