@diegopluna/narvi 0.3.11 → 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 (86) hide show
  1. package/dist/components/activity/ActivityContent.svelte +7 -3
  2. package/dist/components/activity/ActivityStep.svelte +9 -6
  3. package/dist/components/activity/ActivityTrigger.svelte +5 -2
  4. package/dist/components/app-shell/AppShellBar.svelte +9 -4
  5. package/dist/components/app-shell/AppShellHeader.svelte +9 -5
  6. package/dist/components/approval/Approval.svelte +7 -4
  7. package/dist/components/button/Button.svelte +50 -26
  8. package/dist/components/card/Card.svelte +5 -2
  9. package/dist/components/changes-summary/ChangesSummary.svelte +11 -8
  10. package/dist/components/choice-cards/ChoiceCards.svelte +5 -2
  11. package/dist/components/collapsible/CollapsibleTrigger.svelte +5 -2
  12. package/dist/components/color-field/ColorField.svelte +9 -6
  13. package/dist/components/command/styles.d.ts +8 -8
  14. package/dist/components/command/styles.js +11 -9
  15. package/dist/components/composer/ComposerAttachment.svelte +7 -3
  16. package/dist/components/composer/ComposerAttachments.svelte +5 -1
  17. package/dist/components/composer/ComposerModelPicker.svelte +37 -34
  18. package/dist/components/composer/ComposerRoot.svelte +9 -5
  19. package/dist/components/composer/ComposerTextarea.svelte +9 -5
  20. package/dist/components/composer/ComposerToggle.svelte +7 -4
  21. package/dist/components/composer/ComposerToolbar.svelte +5 -1
  22. package/dist/components/composer/ComposerTray.svelte +10 -7
  23. package/dist/components/conversation/ConversationScrollButton.svelte +10 -7
  24. package/dist/components/dialog/ConfirmDialog.svelte +5 -2
  25. package/dist/components/dialog/styles.d.ts +3 -3
  26. package/dist/components/dialog/styles.js +6 -4
  27. package/dist/components/frame/Frame.svelte +8 -5
  28. package/dist/components/hover-card/HoverCardContent.svelte +5 -1
  29. package/dist/components/input/Input.svelte +12 -8
  30. package/dist/components/message/MessageActions.svelte +8 -4
  31. package/dist/components/message/MessageContent.svelte +6 -2
  32. package/dist/components/message/MessagePending.svelte +5 -2
  33. package/dist/components/message/MessageRoot.svelte +10 -4
  34. package/dist/components/message/MessageTime.svelte +5 -2
  35. package/dist/components/message/styles.d.ts +2 -2
  36. package/dist/components/message/styles.js +5 -3
  37. package/dist/components/notice/Notice.svelte +13 -4
  38. package/dist/components/plan/Plan.svelte +13 -10
  39. package/dist/components/popover/PopoverContent.svelte +8 -1
  40. package/dist/components/questionnaire/Questionnaire.svelte +12 -9
  41. package/dist/components/queued-message/QueuedMessage.svelte +14 -7
  42. package/dist/components/rail/RailItem.svelte +16 -7
  43. package/dist/components/rail/RailRoot.svelte +9 -4
  44. package/dist/components/rail/RailSeparator.svelte +5 -2
  45. package/dist/components/reasoning/ReasoningContent.svelte +6 -3
  46. package/dist/components/reasoning/ReasoningTrigger.svelte +5 -2
  47. package/dist/components/search-button/SearchButton.svelte +6 -3
  48. package/dist/components/segmented/SegmentedControl.svelte +6 -3
  49. package/dist/components/settings-group/SettingsGroup.svelte +5 -2
  50. package/dist/components/sidebar/SidebarContent.svelte +8 -4
  51. package/dist/components/sidebar/SidebarFolder.svelte +8 -5
  52. package/dist/components/sidebar/SidebarFooter.svelte +5 -2
  53. package/dist/components/sidebar/SidebarGroup.svelte +11 -8
  54. package/dist/components/sidebar/SidebarHeader.svelte +9 -4
  55. package/dist/components/sidebar/SidebarItem.svelte +14 -9
  56. package/dist/components/split-button/SplitButton.svelte +5 -2
  57. package/dist/components/suggestions/SuggestionsItem.svelte +6 -3
  58. package/dist/components/suggestions/SuggestionsRoot.svelte +5 -1
  59. package/dist/components/tab-strip/TabStrip.svelte +21 -16
  60. package/dist/components/tabs/Tabs.svelte +7 -4
  61. package/dist/components/textarea/Textarea.svelte +6 -2
  62. package/dist/components/theme/Theme.svelte +28 -2
  63. package/dist/components/toast/Toaster.svelte +14 -5
  64. package/dist/components/toggle-group/ToggleGroupRoot.svelte +5 -1
  65. package/dist/components/tool/ToolContent.svelte +8 -4
  66. package/dist/components/tool/ToolSection.svelte +7 -4
  67. package/dist/components/tool/ToolTrigger.svelte +5 -2
  68. package/dist/components/tooltip/TooltipContent.svelte +7 -4
  69. package/dist/components/work-fold/WorkFold.svelte +9 -6
  70. package/dist/internal/Code.svelte +6 -3
  71. package/dist/internal/control.d.ts +6 -6
  72. package/dist/internal/control.js +9 -7
  73. package/dist/internal/layer.d.ts +10 -10
  74. package/dist/internal/layer.js +14 -12
  75. package/dist/internal/toggle.d.ts +8 -8
  76. package/dist/internal/toggle.js +22 -10
  77. package/dist/preset.d.ts +12 -3
  78. package/dist/preset.js +18 -4
  79. package/dist/tokens.stylex.d.ts +13 -3
  80. package/dist/tokens.stylex.js +25 -14
  81. package/package.json +1 -1
  82. package/skills/building-ui/SKILL.md +1 -1
  83. package/skills/markdown/SKILL.md +1 -1
  84. package/skills/setup/SKILL.md +1 -1
  85. package/skills/styling/SKILL.md +5 -2
  86. package/skills/theming/SKILL.md +44 -3
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.11",
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.11'
15
+ library_version: '0.3.12'
16
16
  requires:
17
17
  - setup
18
18
  sources:
@@ -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.11'
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.11'
14
+ library_version: '0.3.12'
15
15
  sources:
16
16
  - src/lib/vite.ts
17
17
  - src/lib/base.css
@@ -12,7 +12,7 @@ metadata:
12
12
  hover, motion and forced-colour preferences.
13
13
  type: core
14
14
  library: '@diegopluna/narvi'
15
- library_version: '0.3.11'
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.11'
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
@@ -274,6 +310,9 @@ scheme changes (`matchMedia('(prefers-color-scheme: dark)')`, or your toggle).
274
310
  to the inherited colour. Write `var(--app-accent, light-dark(…))`.
275
311
  - **MEDIUM: a run-time theme that overrides some tokens.** It looks patched, as an override of
276
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`.
277
316
  - **MEDIUM: `resolveColor` during SSR.** It needs the DOM, so it throws or returns nothing on the
278
317
  server.
279
318
 
@@ -283,5 +322,7 @@ scheme changes (`matchMedia('(prefers-color-scheme: dark)')`, or your toggle).
283
322
  - With a brand theme on `<html>`, a focused Button's ring and an open Select's highlighted item
284
323
  use the new accent.
285
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.
286
327
  - With a run-time theme, setting `--app-accent` on `<html>` changes a focused Button's ring and an
287
328
  open Select's check at once, and removing it brings back Narvi's accent.