@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
package/dist/preset.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Presets: a whole Narvi look in one short code, such as `1caaba`.
3
3
  *
4
- * A preset picks an accent, a stone, a radius, three faces, a pace of motion
5
- * and a colour scheme. From it come the token overrides for `stylex.createTheme`
4
+ * A preset picks an accent, a stone, a radius, three faces, a pace of motion,
5
+ * a colour scheme and a density. From it come the token overrides for `stylex.createTheme`
6
6
  * and the files to drop into an app. Nothing here depends on Svelte or StyleX, so
7
7
  * the docs and a command-line tool can share it.
8
8
  */
@@ -82,6 +82,14 @@ export declare const motions: ReadonlyArray<Option<MotionId> & {
82
82
  }>;
83
83
  export type SchemeId = 'dark' | 'light' | 'system';
84
84
  export declare const schemes: ReadonlyArray<Option<SchemeId>>;
85
+ export type DensityId = 'compact' | 'default' | 'roomy';
86
+ /**
87
+ * How tightly the interface sits: `density.factor`, which the spacing scale and the padding
88
+ * and heights of rows and controls are multiplied by. Text keeps its size at every density.
89
+ */
90
+ export declare const densities: ReadonlyArray<Option<DensityId> & {
91
+ factor: number;
92
+ }>;
85
93
  export type Preset = {
86
94
  accent: AccentId;
87
95
  stone: StoneId;
@@ -91,6 +99,7 @@ export type Preset = {
91
99
  mono: MonoId;
92
100
  motion: MotionId;
93
101
  scheme: SchemeId;
102
+ density: DensityId;
94
103
  };
95
104
  export declare const defaultPreset: Preset;
96
105
  /** A preset as a short code: a version digit, then one letter per choice. */
@@ -112,7 +121,7 @@ export declare const inkTints: Readonly<Record<string, readonly [percent: number
112
121
  export declare const ACCENT_SOFT: readonly [10, 14];
113
122
  export declare const ACCENT_HALO: readonly [20, 26];
114
123
  /** Token overrides by token group, for `stylex.createTheme`. Empty groups are left out. */
115
- export type Overrides = Partial<Record<'colors' | 'radius' | 'font' | 'motion', Record<string, string>>>;
124
+ export type Overrides = Partial<Record<'colors' | 'radius' | 'font' | 'motion' | 'density', Record<string, string>>>;
116
125
  export declare function overrides(preset: Preset): Overrides;
117
126
  export type PresetFile = {
118
127
  path: string;
package/dist/preset.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Presets: a whole Narvi look in one short code, such as `1caaba`.
3
3
  *
4
- * A preset picks an accent, a stone, a radius, three faces, a pace of motion
5
- * and a colour scheme. From it come the token overrides for `stylex.createTheme`
4
+ * A preset picks an accent, a stone, a radius, three faces, a pace of motion,
5
+ * a colour scheme and a density. From it come the token overrides for `stylex.createTheme`
6
6
  * and the files to drop into an app. Nothing here depends on Svelte or StyleX, so
7
7
  * the docs and a command-line tool can share it.
8
8
  */
@@ -232,6 +232,15 @@ export const schemes = [
232
232
  { id: 'light', label: 'Light' },
233
233
  { id: 'system', label: 'System' }
234
234
  ];
235
+ /**
236
+ * How tightly the interface sits: `density.factor`, which the spacing scale and the padding
237
+ * and heights of rows and controls are multiplied by. Text keeps its size at every density.
238
+ */
239
+ export const densities = [
240
+ { id: 'compact', label: 'Compact', factor: 0.75 },
241
+ { id: 'default', label: 'Default', factor: 1 },
242
+ { id: 'roomy', label: 'Roomy', factor: 1.25 }
243
+ ];
235
244
  export const defaultPreset = {
236
245
  accent: 'blue',
237
246
  stone: 'cool',
@@ -240,7 +249,8 @@ export const defaultPreset = {
240
249
  display: 'cormorant',
241
250
  mono: 'geist-mono',
242
251
  motion: 'standard',
243
- scheme: 'dark'
252
+ scheme: 'dark',
253
+ density: 'default'
244
254
  };
245
255
  // The order of the fields in a code. New fields only ever go on the end.
246
256
  const fields = [
@@ -251,7 +261,8 @@ const fields = [
251
261
  ['display', displays],
252
262
  ['mono', monos],
253
263
  ['motion', motions],
254
- ['scheme', schemes]
264
+ ['scheme', schemes],
265
+ ['density', densities]
255
266
  ];
256
267
  const VERSION = '1';
257
268
  const DIGITS = 'abcdefghijklmnopqrstuvwxyz';
@@ -356,6 +367,9 @@ export function overrides(preset) {
356
367
  if (durations) {
357
368
  result.motion = Object.fromEntries(Object.entries(durations).map(([key, ms]) => [key, `${ms}ms`]));
358
369
  }
370
+ const factor = densities.find((option) => option.id === preset.density)?.factor ?? 1;
371
+ if (factor !== 1)
372
+ result.density = { factor: String(factor) };
359
373
  return result;
360
374
  }
361
375
  /** The font packages a preset needs, beyond Narvi itself. */
@@ -59,9 +59,19 @@ export declare const colors: stylex.VarGroup<Readonly<{
59
59
  codePunct: string;
60
60
  }>, symbol>;
61
61
  /**
62
- * 4px spacing scale, in rem. Narvi is sized in rem throughout, so an app that
63
- * sets the root font size (13px for a dense window, 18px for a roomy one) scales
64
- * every part with it. Hairlines, outlines and shadows stay in px, to stay crisp.
62
+ * How tightly the interface sits: a number that the spacing scale, the padding of rows and
63
+ * controls, and their heights are multiplied by. Text, line heights, icons, radii, hairlines
64
+ * and focus rings keep their size, so a compact window holds more without its words getting
65
+ * smaller. Set it with `stylex.createTheme(density, { factor: '0.85' })`, or from a setting the
66
+ * app keeps at run time, `{ factor: 'var(--density, 1)' }`.
67
+ */
68
+ export declare const density: stylex.VarGroup<Readonly<{
69
+ factor: string;
70
+ }>, symbol>;
71
+ /**
72
+ * 4px spacing scale, in rem, times the density. Narvi is sized in rem throughout, so an app
73
+ * that sets the root font size scales every part with it, text included; `density` moves only
74
+ * the room around the text. Hairlines, outlines and shadows stay in px, to stay crisp.
65
75
  */
66
76
  export declare const space: stylex.VarGroup<Readonly<{
67
77
  x1: string;
@@ -91,23 +91,34 @@ export const colors = stylex.defineVars({
91
91
  codePunct: 'light-dark(#626872, #929baa)'
92
92
  });
93
93
  /**
94
- * 4px spacing scale, in rem. Narvi is sized in rem throughout, so an app that
95
- * sets the root font size (13px for a dense window, 18px for a roomy one) scales
96
- * every part with it. Hairlines, outlines and shadows stay in px, to stay crisp.
94
+ * How tightly the interface sits: a number that the spacing scale, the padding of rows and
95
+ * controls, and their heights are multiplied by. Text, line heights, icons, radii, hairlines
96
+ * and focus rings keep their size, so a compact window holds more without its words getting
97
+ * smaller. Set it with `stylex.createTheme(density, { factor: '0.85' })`, or from a setting the
98
+ * app keeps at run time, `{ factor: 'var(--density, 1)' }`.
99
+ */
100
+ export const density = stylex.defineVars({
101
+ factor: '1'
102
+ });
103
+ const d = (rem) => `calc(${rem} * ${density.factor})`;
104
+ /**
105
+ * 4px spacing scale, in rem, times the density. Narvi is sized in rem throughout, so an app
106
+ * that sets the root font size scales every part with it, text included; `density` moves only
107
+ * the room around the text. Hairlines, outlines and shadows stay in px, to stay crisp.
97
108
  */
98
109
  export const space = stylex.defineVars({
99
- x1: '0.25rem',
110
+ x1: d('0.25rem'),
100
111
  // 6px: between an icon and its words, or two close items
101
- x1_5: '0.375rem',
102
- x2: '0.5rem',
103
- x3: '0.75rem',
104
- x4: '1rem',
105
- x5: '1.25rem',
106
- x6: '1.5rem',
107
- x8: '2rem',
108
- x10: '2.5rem',
109
- x12: '3rem',
110
- x16: '4rem'
112
+ x1_5: d('0.375rem'),
113
+ x2: d('0.5rem'),
114
+ x3: d('0.75rem'),
115
+ x4: d('1rem'),
116
+ x5: d('1.25rem'),
117
+ x6: d('1.5rem'),
118
+ x8: d('2rem'),
119
+ x10: d('2.5rem'),
120
+ x12: d('3rem'),
121
+ x16: d('4rem')
111
122
  });
112
123
  /**
113
124
  * Radii, named for what takes them, so two things of one kind agree without a number.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diegopluna/narvi",
3
- "version": "0.3.10",
3
+ "version": "0.3.12",
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.10'
15
+ library_version: '0.3.12'
16
16
  requires:
17
17
  - setup
18
18
  sources:
@@ -38,6 +38,7 @@ component: import the namespace (`Dialog`) and use `Dialog.Root`. Docs and live
38
38
  | `Switch` | A setting that takes effect at once | `switch` |
39
39
  | `SegmentedControl` | One of a few options, all visible (`options: { value, label, title? }[]`, `onchange`) | `segmented-control` |
40
40
  | `Slider` | A value or a range along a track | `slider` |
41
+ | `ColorField` | A colour: a swatch that opens Narvi's picker, beside a hex field (`label`, `bind:value`, `onchange`, `size`, `labels`) | `color-field` |
41
42
  | `SplitButton` | A main action joined to a menu of how to do it (`menu`, `menuLabel`, `label`, `variant` incl. `ghost`, `shape`, `mainDisabled`, `mainSx`/`menuSx`, `menuMinWidth`) | `split-button` |
42
43
  | `Toggle` | A button that stays pressed (`tone`: `accent`, or `neutral` for toolbar icons) | `toggle` |
43
44
  | `ToggleGroup.Root`, `.Item` | Toggles that belong together: one pressed, or any number | `toggle-group` |
@@ -57,6 +58,16 @@ for a tab's own buttons, `beside` for the tab shown in a split, and per tab `tab
57
58
  `onchange(id)`; a name cleared comes as `''`; `addMenu` (Menu parts) makes the add button open
58
59
  a menu.
59
60
 
61
+ ### Colour fields
62
+
63
+ `ColorField` takes any CSS colour as `value` (a hex, a name, `rgb()`, `oklch()`) and shows and
64
+ gives it back as `#rrggbb`, without alpha, through `bind:value` and `onchange`, which fires while
65
+ dragging and as a colour is typed. `label` names the hex field (a surrounding `Field` labels it
66
+ instead) and the swatch ("Pick a colour for {label}"). The picker is Narvi's own, the same on
67
+ every system: an area of saturation and brightness, a hue strip, and a pipette where the browser
68
+ has `EyeDropper`. Don't put an `<input type="color">` beside it or under it; the system's picker
69
+ is what it replaces. Only a hex is read on the server.
70
+
60
71
  ### Split buttons
61
72
 
62
73
  `SplitButton` takes a `menu` snippet, `menuLabel` for the chevron and `label` for the group.
@@ -238,6 +249,13 @@ sidebar's width yourself, and don't put a `translate` of your own on `AppShell.M
238
249
  </Composer.Root>
239
250
  ```
240
251
 
252
+ The conversation tells the person's scrolling from its own: a wheel, a swipe, a key that scrolls
253
+ up (⌘↑ and Ctrl+Home too) or the scrollbar lets go at once, even mid-stream; so does an upward
254
+ scroll while the pointer is over an iframe in it or a button is held. Don't add listeners of your
255
+ own to stop it following. A fold opened at the end keeps its toggle in place: a toggle is a button
256
+ with `aria-expanded` and no `aria-haspopup`, and its fold the nearest `[data-disclosure]`, or the
257
+ toggle's parent; put `data-disclosure` on a fold of your own whose toggle is nested deeper.
258
+
241
259
  ## Agent timeline
242
260
 
243
261
  Docs slug: `agent-timeline`.
@@ -264,6 +282,12 @@ your own matches the part cut off, which the step marks with `data-output-cut`.
264
282
  words of `[data-activity-step-toggle]` from what such a find searches. Don't add a button of
265
283
  your own for it. `outputLabels` renames it.
266
284
 
285
+ `Activity.Step`'s icon is the kind's (a terminal, a square pen, an eye, a magnifier, a globe, a
286
+ wrench, a bot); its `icon` snippet puts one of your own, such as a Lucide icon, in its place, sized
287
+ to fit and in the step's colour. Inside an opened row the icon stays quiet: grey while it runs,
288
+ with its spinner (the row above is what is lit), and a faint red when it did not go through, its
289
+ badge saying it in words. Don't recolour it with a wrapper of your own.
290
+
267
291
  ## Utilities
268
292
 
269
293
  - `sx()`, `classes()` and the `Sx` type: see the `styling` 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.10'
15
+ library_version: '0.3.12'
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.10'
14
+ library_version: '0.3.12'
15
15
  sources:
16
16
  - src/lib/vite.ts
17
17
  - src/lib/base.css
@@ -101,8 +101,10 @@ Narvi is below 1.0, so a minor release can change an API. Pin the version you bu
101
101
 
102
102
  `base.css` sets `color-scheme: light dark` (which Narvi's colours follow) and paints the root in
103
103
  the `bg` and `text` tokens. It also adds a small reset: border-box sizing; no margin on the body,
104
- headings, paragraphs and figures; lists without markers; and media as blocks. It sits in the
105
- `narvi.base` layer, below every component, and any rule of yours outside a layer beats both.
104
+ headings, paragraphs and figures; lists without markers; and media as blocks. It draws every
105
+ scrollbar too: 6px, no track, a thumb in `borderStrong` (`::-webkit-scrollbar`, and
106
+ `scrollbar-width: thin` with `scrollbar-color` in Firefox only). It sits in the `narvi.base`
107
+ layer, below every component, and any rule of yours outside a layer beats both.
106
108
 
107
109
  4. Use a component:
108
110
 
@@ -179,6 +181,10 @@ properties: `p-0` on a Card removes its padding, not a part of it.
179
181
  plugin, or switch schemes with a rule such as `:root[data-theme='dark'] { color-scheme: dark }`.
180
182
  - **MEDIUM: putting the font on a layout `<div>`.** Popups are placed at the end of `<body>`,
181
183
  outside that div, and fall back to the system font. Set `font-family` on `:root`.
184
+ - **MEDIUM: `scrollbar-width` or `scrollbar-color` on an element.** In Chromium 121 and later
185
+ (Electron too) either one turns off `::-webkit-scrollbar` for that element, and it shows the
186
+ system's scrollbar instead of Narvi's. Leave both off; `scrollbar-width: none` is fine where a
187
+ scrollbar is hidden on purpose.
182
188
  - **MEDIUM: theming `bg` or `text` without updating the root.** `base.css` paints the root with
183
189
  copies of those tokens. If you override them, set `:root { background-color; color }` to match.
184
190
 
@@ -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.10'
15
+ library_version: '0.3.12'
16
16
  requires:
17
17
  - setup
18
18
  sources:
@@ -81,7 +81,10 @@ package root) breaks them.
81
81
  `codeNumber`, `codeLiteral`, `codePunct`. The primary button: `primary`, `onPrimary`. The
82
82
  thumb of a switch or slider: `thumb`.
83
83
  - `space`: a 4px scale from `x1` (4px) to `x16` (64px), with `x1_5` (6px) between an icon and
84
- its words.
84
+ its words, at the default density. Each step is times `density.factor`, so it follows the app's
85
+ density setting (see the `theming` skill).
86
+ - `density`: one `factor`, 1 by default. Multiply a part's own padding or height by it
87
+ (`` `calc(0.375rem * ${density.factor})` ``) to follow the density; leave text, icons and radii.
85
88
  - `radius`, named for what takes it: `chip` (a key cap, a checkbox), `item` (a small control),
86
89
  `control` (a button, a field, a row), `panel` (a notice, a sheet), `card` (a card, a popover),
87
90
  `frame` and `pill`.
@@ -3,15 +3,16 @@ name: theming
3
3
  description: >
4
4
  Use when changing light/dark mode, adding a theme toggle, scoping a colour scheme to part of a
5
5
  page, rebranding Narvi's accent with a custom theme, applying themes worked out at run time
6
- (imported, picked or computed) through CSS variables, or reading a Narvi colour token in a
7
- canvas, WebGL or chart library, in an app that uses @diegopluna/narvi.
6
+ (imported, picked or computed) through CSS variables, adding a Compact, Default or Roomy density
7
+ setting that changes how tightly the window sits, or reading a Narvi colour token in a canvas,
8
+ WebGL or chart library, in an app that uses @diegopluna/narvi.
8
9
  metadata:
9
10
  purpose: >
10
11
  Control Narvi's light and dark schemes, override its tokens with custom themes that also reach
11
12
  menus and dialogs, and resolve token colours for drawing code that cannot read CSS variables.
12
13
  type: core
13
14
  library: '@diegopluna/narvi'
14
- library_version: '0.3.10'
15
+ library_version: '0.3.12'
15
16
  requires:
16
17
  - setup
17
18
  sources:
@@ -21,6 +22,8 @@ sources:
21
22
  - src/lib/base.css
22
23
  - src/routes/docs/theming/+page.svelte
23
24
  - src/routes/docs/theming/RuntimeTheme.svelte
25
+ - src/routes/docs/theming/Density.svelte
26
+ - src/lib/preset.ts
24
27
  ---
25
28
 
26
29
  # Theme Narvi
@@ -220,6 +223,39 @@ development, measure the pairs with `resolveRgba` (below): `text` and `textMuted
220
223
  `borderControl` 3:1 and no more (on `bg` by day, on `bgRaised` by night), and `onAccent` 4.5:1 on
221
224
  `accent`.
222
225
 
226
+ ### Set the density
227
+
228
+ `density.factor` (1 by default) sets how tightly the interface sits. The spacing scale, the
229
+ padding of rows, controls and surfaces, and the heights of rows and controls are multiplied by
230
+ it. Text, line heights, icons, radii, borders and focus rings keep their size, as do touch
231
+ targets on a coarse pointer, a small Button's 40px hit area, and the bar beside macOS' window
232
+ buttons. The presets use 0.75 (Compact), 1 and 1.25 (Roomy). For a setting the person changes,
233
+ compile one theme that reads a variable, put it on `<html>`, and set the variable:
234
+
235
+ ```ts
236
+ // src/lib/density.ts
237
+ import * as stylex from '@stylexjs/stylex';
238
+ import { density } from '@diegopluna/narvi/tokens.stylex.js';
239
+
240
+ export const densityTheme = stylex.createTheme(density, { factor: 'var(--density, 1)' });
241
+
242
+ export function applyDensity(choice: 'compact' | 'default' | 'roomy') {
243
+ const factor = { compact: 0.75, default: 1, roomy: 1.25 }[choice];
244
+ document.documentElement.style.setProperty('--density', String(factor));
245
+ }
246
+ ```
247
+
248
+ Add `stylex.attrs(densityTheme).class` to `<html>` as for any theme (above). For a part of the
249
+ page, `<Theme theme={densityTheme}>` works too. Anywhere else it does not: a CSS variable built
250
+ from another is worked out where it is declared, and the spacing scale is declared on `:root` and
251
+ again by each `Theme`, so a density theme on a plain `<div>` reaches the components' own sizes but
252
+ leaves the spacing scale at the root's density.
253
+
254
+ Scale your own parts with it by using the `space` tokens, which already follow it, or by
255
+ multiplying: `` paddingBlock: `calc(0.375rem * ${density.factor})` ``. A row never gets shorter
256
+ than its text, because its line height does not change. To make the text larger or smaller as
257
+ well, set the root font size instead; Narvi is sized in rem.
258
+
223
259
  ### Paint a token in a canvas, WebGL or a chart
224
260
 
225
261
  A token is a CSS variable that holds a `light-dark()` pair, which drawing code cannot read. Ask
@@ -265,12 +301,18 @@ scheme changes (`matchMedia('(prefers-color-scheme: dark)')`, or your toggle).
265
301
  are tokens too: leave them out and an info Notice, toast or Badge keeps Narvi's
266
302
  blue beside your own statuses.
267
303
  - **MEDIUM: overriding `bg` or `text` without the root.** `base.css` paints `:root` with copies
268
- of those two. Set the root's `background-color` and `color` to match your override.
304
+ of those two. Set the root's `background-color` and `color` to match your override. Its
305
+ scrollbars take `--narvi-scrollbar-thumb` and `--narvi-scrollbar-thumb-hover`, copies of
306
+ `borderStrong` and `borderControl`: `Theme` sets them again from its theme, and a theme applied
307
+ to the root some other way sets them on the root too.
269
308
  - **HIGH: a variable without a fallback.** `accent: 'var(--app-accent)'` makes the token invalid
270
309
  until the app sets the variable, and every property that reads it falls back to transparent or
271
310
  to the inherited colour. Write `var(--app-accent, light-dark(…))`.
272
311
  - **MEDIUM: a run-time theme that overrides some tokens.** It looks patched, as an override of
273
312
  `accent` alone does. Map every colour token, as above.
313
+ - **MEDIUM: a density theme on a plain element.** Its class on a `<div>` makes Buttons and rows
314
+ inside it denser but keeps the gaps and padding that come from `space` at the root's
315
+ density. Put it on `<html>` or pass it to a `Theme`.
274
316
  - **MEDIUM: `resolveColor` during SSR.** It needs the DOM, so it throws or returns nothing on the
275
317
  server.
276
318
 
@@ -280,5 +322,7 @@ scheme changes (`matchMedia('(prefers-color-scheme: dark)')`, or your toggle).
280
322
  - With a brand theme on `<html>`, a focused Button's ring and an open Select's highlighted item
281
323
  use the new accent.
282
324
  - A canvas colour matches the CSS one in both schemes.
325
+ - With a density theme on `<html>` and `--density: 0.75`, a medium Button is 24px tall instead of
326
+ 32px and its label keeps its font size.
283
327
  - With a run-time theme, setting `--app-accent` on `<html>` changes a focused Button's ring and an
284
328
  open Select's check at once, and removing it brings back Narvi's accent.