@diegopluna/narvi 0.0.1 → 0.1.0

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 (112) hide show
  1. package/README.md +27 -8
  2. package/dist/base.css +96 -0
  3. package/dist/color.d.ts +38 -0
  4. package/dist/color.js +88 -0
  5. package/dist/components/activity/ActivityTrigger.svelte +2 -3
  6. package/dist/components/app-shell/AppShellHeader.svelte +2 -3
  7. package/dist/components/app-shell/AppShellSidebar.svelte +6 -6
  8. package/dist/components/approval/Approval.svelte +8 -4
  9. package/dist/components/button/Button.svelte +15 -18
  10. package/dist/components/card/Card.svelte +98 -12
  11. package/dist/components/card/Card.svelte.d.ts +8 -3
  12. package/dist/components/checkbox/Checkbox.svelte +16 -13
  13. package/dist/components/collapsible/CollapsibleContent.svelte +38 -0
  14. package/dist/components/collapsible/CollapsibleContent.svelte.d.ts +11 -0
  15. package/dist/components/collapsible/CollapsibleRoot.svelte +44 -0
  16. package/dist/components/collapsible/CollapsibleRoot.svelte.d.ts +11 -0
  17. package/dist/components/collapsible/CollapsibleTrigger.svelte +83 -0
  18. package/dist/components/collapsible/CollapsibleTrigger.svelte.d.ts +13 -0
  19. package/dist/components/collapsible/context.d.ts +5 -0
  20. package/dist/components/collapsible/context.js +11 -0
  21. package/dist/components/collapsible/index.d.ts +7 -0
  22. package/dist/components/collapsible/index.js +4 -0
  23. package/dist/components/command/styles.js +3 -3
  24. package/dist/components/composer/ComposerAttachment.svelte +4 -6
  25. package/dist/components/composer/ComposerModelPicker.svelte +8 -10
  26. package/dist/components/composer/ComposerRoot.svelte +7 -6
  27. package/dist/components/composer/ComposerSubmit.svelte +4 -5
  28. package/dist/components/composer/ComposerToggle.svelte +11 -11
  29. package/dist/components/conversation/ConversationScrollButton.svelte +6 -8
  30. package/dist/components/dialog/DialogContent.svelte +5 -1
  31. package/dist/components/dialog/styles.d.ts +0 -23
  32. package/dist/components/dialog/styles.js +7 -43
  33. package/dist/components/grid/Grid.svelte +111 -0
  34. package/dist/components/grid/Grid.svelte.d.ts +27 -0
  35. package/dist/components/hover-card/HoverCardContent.svelte +50 -0
  36. package/dist/components/hover-card/HoverCardContent.svelte.d.ts +10 -0
  37. package/dist/components/hover-card/HoverCardRoot.svelte +22 -0
  38. package/dist/components/hover-card/HoverCardRoot.svelte.d.ts +5 -0
  39. package/dist/components/hover-card/index.d.ts +7 -0
  40. package/dist/components/hover-card/index.js +7 -0
  41. package/dist/components/link/Link.svelte +2 -4
  42. package/dist/components/message/MessageAction.svelte +2 -3
  43. package/dist/components/message/MessageActions.svelte +2 -3
  44. package/dist/components/message/MessageCopy.svelte +4 -5
  45. package/dist/components/message/MessageRoot.svelte +3 -4
  46. package/dist/components/message/MessageTime.svelte +2 -3
  47. package/dist/components/plan/Plan.svelte +3 -4
  48. package/dist/components/progress/Progress.svelte +4 -6
  49. package/dist/components/rail/RailItem.svelte +9 -9
  50. package/dist/components/reasoning/ReasoningTrigger.svelte +2 -3
  51. package/dist/components/resize-handle/ResizeHandle.svelte +3 -5
  52. package/dist/components/reveal/Reveal.svelte +89 -0
  53. package/dist/components/reveal/Reveal.svelte.d.ts +17 -0
  54. package/dist/components/reveal/revealed.d.ts +38 -0
  55. package/dist/components/reveal/revealed.js +79 -0
  56. package/dist/components/segmented/SegmentedControl.svelte +5 -9
  57. package/dist/components/sheet/SheetContent.svelte +63 -0
  58. package/dist/components/sheet/SheetContent.svelte.d.ts +18 -0
  59. package/dist/components/sheet/index.d.ts +12 -0
  60. package/dist/components/sheet/index.js +12 -0
  61. package/dist/components/sheet/styles.d.ts +51 -0
  62. package/dist/components/sheet/styles.js +65 -0
  63. package/dist/components/shimmer/Shimmer.svelte +8 -6
  64. package/dist/components/sidebar/SidebarGroup.svelte +5 -3
  65. package/dist/components/sidebar/SidebarItem.svelte +10 -8
  66. package/dist/components/slider/Slider.svelte +199 -0
  67. package/dist/components/slider/Slider.svelte.d.ts +55 -0
  68. package/dist/components/stack/Stack.svelte +37 -44
  69. package/dist/components/stack/Stack.svelte.d.ts +12 -6
  70. package/dist/components/suggestions/SuggestionsItem.svelte +7 -9
  71. package/dist/components/switch/Switch.svelte +8 -12
  72. package/dist/components/tabs/Tabs.svelte +3 -6
  73. package/dist/components/text/Text.svelte +47 -5
  74. package/dist/components/text/Text.svelte.d.ts +8 -2
  75. package/dist/components/toast/Toaster.svelte +7 -5
  76. package/dist/components/toggle/Toggle.svelte +40 -0
  77. package/dist/components/toggle/Toggle.svelte.d.ts +15 -0
  78. package/dist/components/toggle-group/ToggleGroupItem.svelte +37 -0
  79. package/dist/components/toggle-group/ToggleGroupItem.svelte.d.ts +12 -0
  80. package/dist/components/toggle-group/ToggleGroupRoot.svelte +95 -0
  81. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +33 -0
  82. package/dist/components/toggle-group/context.d.ts +6 -0
  83. package/dist/components/toggle-group/context.js +11 -0
  84. package/dist/components/toggle-group/index.d.ts +5 -0
  85. package/dist/components/toggle-group/index.js +3 -0
  86. package/dist/components/tool/ToolTrigger.svelte +4 -6
  87. package/dist/components/tooltip/TooltipContent.svelte +6 -3
  88. package/dist/components/work-fold/WorkFold.svelte +12 -25
  89. package/dist/components/work-fold/WorkFold.svelte.d.ts +1 -1
  90. package/dist/index.d.ts +25 -3
  91. package/dist/index.js +24 -2
  92. package/dist/internal/Chevron.svelte +2 -3
  93. package/dist/internal/Collapse.svelte +6 -5
  94. package/dist/internal/Collapse.svelte.d.ts +2 -1
  95. package/dist/internal/control.js +4 -4
  96. package/dist/internal/layer.js +6 -8
  97. package/dist/internal/layout.d.ts +13 -0
  98. package/dist/internal/layout.js +453 -0
  99. package/dist/internal/responsive.d.ts +45 -0
  100. package/dist/internal/responsive.js +42 -0
  101. package/dist/internal/sx.d.ts +39 -4
  102. package/dist/internal/sx.js +17 -0
  103. package/dist/internal/toggle.d.ts +74 -0
  104. package/dist/internal/toggle.js +87 -0
  105. package/dist/media.stylex.d.ts +52 -0
  106. package/dist/media.stylex.js +53 -0
  107. package/dist/preset.js +9 -3
  108. package/dist/tokens.stylex.d.ts +15 -0
  109. package/dist/tokens.stylex.js +24 -2
  110. package/dist/vite.d.ts +27 -3
  111. package/dist/vite.js +25 -3
  112. package/package.json +14 -5
package/README.md CHANGED
@@ -28,8 +28,7 @@ The tests need a browser once: `pnpm exec playwright install chromium-headless-s
28
28
 
29
29
  ## Use it in an app
30
30
 
31
- Narvi is not on npm yet. To try it elsewhere, run `pnpm build:lib && pnpm pack` and install the
32
- tarball. Then add the plugin after `sveltekit()`:
31
+ Install `@diegopluna/narvi` from npm, then add the plugin after `sveltekit()`:
33
32
 
34
33
  ```ts
35
34
  // vite.config.ts
@@ -42,9 +41,16 @@ export default defineConfig({
42
41
  });
43
42
  ```
44
43
 
45
- Mount `<DevStyles />` in the root layout, import a stylesheet that sets
46
- `:root { color-scheme: light dark; }`, and import components from `@diegopluna/narvi`. The docs site covers
47
- this in full under Installation.
44
+ Mount `<DevStyles />` in the root layout, start your stylesheet with
45
+ `@import '@diegopluna/narvi/base.css';` (the page's colours, `color-scheme` and a small reset), and import
46
+ components from `@diegopluna/narvi`. The docs site covers this in full under Installation.
47
+
48
+ ## Release
49
+
50
+ Run the Release workflow from the Actions tab, or `gh workflow run release.yml -f bump=patch`
51
+ (or `minor`, `major`). On `main`, it runs the checks, bumps the version, publishes to npm, then
52
+ pushes the version commit and tag and writes the GitHub release. Nothing is pushed unless the
53
+ publish succeeds, so a failed run can be run again.
48
54
 
49
55
  ## How it is put together
50
56
 
@@ -52,6 +58,14 @@ this in full under Installation.
52
58
  `light-dark()` declaration, so the theme follows `color-scheme`. The palette is stone and
53
59
  moonlight: near-black and warm paper for surfaces, a pale metal ("mithril") for the solid button,
54
60
  and one silver-blue ("ithildin") that is kept for state: focus, selection and progress.
61
+ - **Conditions** live in `src/lib/media.stylex.ts`: `media.hover`, `media.motion`, `media.forcedColors`
62
+ and the rest, and the breakpoints `sm` to `xl`, as `defineConsts` constants that any file can import.
63
+ - **The base stylesheet**, `src/lib/base.css`, holds what belongs on the document: `color-scheme`, the
64
+ page's colours and a small reset, in the `narvi.base` layer below every component. Its colours are
65
+ copied from the tokens by `scripts/base-css.js` when the library is built, and a test checks them.
66
+ - **Layout props** on Stack and Grid take a value or values by breakpoint. They compile to static
67
+ classes: one rule reads a custom property per breakpoint (`src/lib/internal/layout.ts`), and each
68
+ value is a class that sets one of them (`src/lib/internal/responsive.ts` explains how).
55
69
  - **Components** live in `src/lib/components/<name>/<Name>.svelte`. Styles are created in the
56
70
  `<script module>` block and applied with the `attrs` helper from `src/lib/internal/sx.ts`, which
57
71
  also merges the consumer's `sx` and `class`. Interface text inherits the page's font; only large
@@ -59,7 +73,10 @@ this in full under Installation.
59
73
  - **Edges are shadows.** Hairlines and top highlights are drawn with `box-shadow`, so
60
74
  `src/lib/internal/shared.ts` adds a transparent outline that becomes the edge in forced-colours
61
75
  mode. Control boundaries (`colors.edge`) hold 3:1 against their surface.
62
- - **The Vite plugin** in `src/lib/vite.ts` is a preset over `@stylexjs/unplugin`.
76
+ - **The Vite plugin** in `src/lib/vite.ts` is a preset over `@stylexjs/unplugin`. It puts every
77
+ style in one cascade layer, `narvi`, so unlayered CSS beats it, and declares `narvi.base` first
78
+ inside it, so `base.css` stays below the components whichever stylesheet loads first. `narvi({ tailwind: true })`
79
+ orders that layer between Tailwind's `base` and its `components` and `utilities`.
63
80
 
64
81
  The look started as a study in `Frame` + `Card`: a tray around an inset panel, whose radius is the
65
82
  panel's radius plus the gap between them. Hover styles sit behind `@media (hover: hover) and (pointer: fine)` and
@@ -79,5 +96,7 @@ movement behind `prefers-reduced-motion: no-preference`.
79
96
  4. Add the page to `src/docs/nav.ts`.
80
97
 
81
98
  Two StyleX rules to keep in mind: values inside `stylex.create` must be known at build time, so a
82
- constant such as a media query has to be defined in the same file, and tokens must be imported
83
- straight from `tokens.stylex.js`.
99
+ media query comes from `media.stylex.js` (or is written in the same file), and tokens and media
100
+ queries must be imported straight from their `.stylex.js` files. Use `media` throughout rather than
101
+ writing a condition out: StyleX ranks a constant condition above a written one, and orders constant
102
+ breakpoints by width only when they are in px.
package/dist/base.css ADDED
@@ -0,0 +1,96 @@
1
+ /*
2
+ * Narvi's base stylesheet: what a StyleX app needs on the document itself, and a small reset.
3
+ *
4
+ * @import '@diegopluna/narvi/base.css';
5
+ *
6
+ * It sits in `narvi.base`, the lowest layer of Narvi's own, so every component beats it, and
7
+ * any CSS of yours outside a layer beats both. The Narvi Vite plugin declares that layer
8
+ * first, so the order holds whichever stylesheet the browser reads first.
9
+ *
10
+ * A colour followed by a comment naming a token is copied from that token when the library
11
+ * is built (`scripts/base-css.js`), so the page and the components never drift apart.
12
+ */
13
+ @layer narvi.base {
14
+ *,
15
+ *::before,
16
+ *::after {
17
+ box-sizing: border-box;
18
+ }
19
+
20
+ :root {
21
+ /* Narvi's colours take their light or dark half from this. */
22
+ color-scheme: light dark;
23
+ /* The page, on the root rather than the body, so overscroll shows it too */
24
+ background-color: light-dark(#f4f3ef, #06080c); /* colors.bg */
25
+ color: light-dark(#14171c, #e9edf3); /* colors.text */
26
+ /* Narvi's interface text inherits the page's face: set your own on the root */
27
+ font-family:
28
+ system-ui,
29
+ -apple-system,
30
+ 'Segoe UI',
31
+ Roboto,
32
+ sans-serif;
33
+ -webkit-text-size-adjust: 100%;
34
+ text-size-adjust: 100%;
35
+ -webkit-font-smoothing: antialiased;
36
+ -moz-osx-font-smoothing: grayscale;
37
+ text-rendering: optimizeLegibility;
38
+ }
39
+
40
+ body {
41
+ margin: 0;
42
+ }
43
+
44
+ /* Spacing comes from layout (Stack, Grid, gap), not from the browser's margins */
45
+ h1,
46
+ h2,
47
+ h3,
48
+ h4,
49
+ h5,
50
+ h6,
51
+ p,
52
+ blockquote,
53
+ figure,
54
+ dl,
55
+ dd,
56
+ pre {
57
+ margin: 0;
58
+ }
59
+
60
+ /* A list is laid out as you style it: no markers, no 40px indent */
61
+ ul,
62
+ ol,
63
+ menu {
64
+ margin: 0;
65
+ padding: 0;
66
+ list-style: none;
67
+ }
68
+
69
+ /* Media sit on their own line, and shrink with their container */
70
+ img,
71
+ picture,
72
+ svg,
73
+ video,
74
+ canvas,
75
+ audio,
76
+ iframe,
77
+ embed,
78
+ object {
79
+ display: block;
80
+ }
81
+
82
+ img,
83
+ video {
84
+ max-width: 100%;
85
+ height: auto;
86
+ }
87
+
88
+ /* Form controls take the page's face rather than the system's. Only the face: their size
89
+ and line height are left to the browser, or to the component, as without a reset. */
90
+ button,
91
+ input,
92
+ select,
93
+ textarea {
94
+ font-family: inherit;
95
+ }
96
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Narvi writes every colour with `light-dark()`, and its tokens are CSS
3
+ * variables. A stylesheet resolves both, but a `<canvas>`, WebGL or a charting
4
+ * library cannot: they need the colour the browser would actually paint. These
5
+ * helpers ask the browser for it, by giving the colour to a hidden element.
6
+ *
7
+ * They run in the browser only. A colour can change when the scheme does, so
8
+ * read it again when `prefers-color-scheme` or a `Theme` around `scope` changes.
9
+ */
10
+ /** Red, green and blue from 0 to 255, and alpha from 0 to 1. */
11
+ export type Rgba = [r: number, g: number, b: number, alpha: number];
12
+ export type ResolveColorOptions = {
13
+ /**
14
+ * Where the colour is read, which decides its scheme and theme: a token inside
15
+ * a dark `Theme` resolves to its dark value. Defaults to `document.body`.
16
+ */
17
+ scope?: Element;
18
+ };
19
+ /**
20
+ * The colour a CSS colour or Narvi token paints as, with `var()` and
21
+ * `light-dark()` resolved, as a string any canvas accepts.
22
+ *
23
+ * ```ts
24
+ * import { colors } from '@diegopluna/narvi/tokens.stylex.js';
25
+ *
26
+ * context.fillStyle = resolveColor(colors.ithil);
27
+ * ```
28
+ */
29
+ export declare function resolveColor(color: string, options?: ResolveColorOptions): string;
30
+ /**
31
+ * The same colour as numbers, for code that mixes or animates channels itself:
32
+ * WebGL uniforms, particle systems, gradients built by hand.
33
+ *
34
+ * ```ts
35
+ * const [r, g, b] = resolveRgba(colors.text);
36
+ * ```
37
+ */
38
+ export declare function resolveRgba(color: string, options?: ResolveColorOptions): Rgba;
package/dist/color.js ADDED
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Narvi writes every colour with `light-dark()`, and its tokens are CSS
3
+ * variables. A stylesheet resolves both, but a `<canvas>`, WebGL or a charting
4
+ * library cannot: they need the colour the browser would actually paint. These
5
+ * helpers ask the browser for it, by giving the colour to a hidden element.
6
+ *
7
+ * They run in the browser only. A colour can change when the scheme does, so
8
+ * read it again when `prefers-color-scheme` or a `Theme` around `scope` changes.
9
+ */
10
+ /**
11
+ * The colour a CSS colour or Narvi token paints as, with `var()` and
12
+ * `light-dark()` resolved, as a string any canvas accepts.
13
+ *
14
+ * ```ts
15
+ * import { colors } from '@diegopluna/narvi/tokens.stylex.js';
16
+ *
17
+ * context.fillStyle = resolveColor(colors.ithil);
18
+ * ```
19
+ */
20
+ export function resolveColor(color, options = {}) {
21
+ return probe(color, options.scope);
22
+ }
23
+ /**
24
+ * The same colour as numbers, for code that mixes or animates channels itself:
25
+ * WebGL uniforms, particle systems, gradients built by hand.
26
+ *
27
+ * ```ts
28
+ * const [r, g, b] = resolveRgba(colors.text);
29
+ * ```
30
+ */
31
+ export function resolveRgba(color, options = {}) {
32
+ const resolved = probe(color, options.scope);
33
+ return (parse(resolved) ??
34
+ // Any other space (`oklch()`, `lab()`, …) converted to sRGB by the browser.
35
+ // Relative colour syntax keeps the alpha exact, where a canvas would round it.
36
+ parse(probe(`rgb(from ${resolved} r g b / alpha)`, options.scope)) ??
37
+ paint(resolved));
38
+ }
39
+ function probe(color, scope = document.body) {
40
+ const element = document.createElement('span');
41
+ element.style.display = 'none';
42
+ element.style.color = color;
43
+ scope.append(element);
44
+ const resolved = getComputedStyle(element).color;
45
+ element.remove();
46
+ return resolved;
47
+ }
48
+ const clamp = (value, max) => Math.min(Math.max(value, 0), max);
49
+ /** Reads `rgb()`, `rgba()` and `color(srgb …)`, the forms browsers compute sRGB colours to. */
50
+ function parse(color) {
51
+ const legacy = /^rgba?\(\s*([^)]+)\)$/i.exec(color);
52
+ if (legacy) {
53
+ const parts = legacy[1]
54
+ .split(/[\s,/]+/)
55
+ .filter(Boolean)
56
+ .map(Number);
57
+ if (parts.length < 3 || parts.some(Number.isNaN))
58
+ return undefined;
59
+ const [r, g, b, alpha = 1] = parts;
60
+ return [clamp(r, 255), clamp(g, 255), clamp(b, 255), clamp(alpha, 1)];
61
+ }
62
+ const srgb = /^color\(\s*srgb\s+([^)]+)\)$/i.exec(color);
63
+ if (srgb) {
64
+ const parts = srgb[1]
65
+ .split(/[\s/]+/)
66
+ .filter(Boolean)
67
+ .map(Number);
68
+ if (parts.length < 3 || parts.some(Number.isNaN))
69
+ return undefined;
70
+ const [r, g, b, alpha = 1] = parts;
71
+ const channel = (value) => Math.round(clamp(value, 1) * 255);
72
+ return [channel(r), channel(g), channel(b), clamp(alpha, 1)];
73
+ }
74
+ return undefined;
75
+ }
76
+ /** The last resort, for a browser without relative colours: paint a pixel and read it back. */
77
+ function paint(color) {
78
+ const canvas = document.createElement('canvas');
79
+ canvas.width = 1;
80
+ canvas.height = 1;
81
+ const context = canvas.getContext('2d', { willReadFrequently: true });
82
+ if (!context)
83
+ return [0, 0, 0, 0];
84
+ context.fillStyle = color;
85
+ context.fillRect(0, 0, 1, 1);
86
+ const [r, g, b, a] = context.getImageData(0, 0, 1, 1).data;
87
+ return [r, g, b, a / 255];
88
+ }
@@ -7,6 +7,7 @@
7
7
  import { attrs, type Sx } from '../../internal/sx.js';
8
8
  import Tile from '../../internal/Tile.svelte';
9
9
  import { colors, font, motion, radius } from '../../tokens.stylex.js';
10
+ import { media } from '../../media.stylex.js';
10
11
  import RollingText from '../rolling-text/RollingText.svelte';
11
12
  import { getActivityContext } from './context.js';
12
13
 
@@ -24,8 +25,6 @@
24
25
  sx?: Sx;
25
26
  };
26
27
 
27
- const HOVER = '@media (hover: hover) and (pointer: fine)';
28
-
29
28
  const styles = stylex.create({
30
29
  trigger: {
31
30
  display: 'flex',
@@ -39,7 +38,7 @@
39
38
  borderWidth: 0,
40
39
  borderRadius: radius.xs,
41
40
  backgroundColor: 'transparent',
42
- color: { default: colors.textMuted, ':hover': { default: null, [HOVER]: colors.text } },
41
+ color: { default: colors.textMuted, ':hover': { default: null, [media.hover]: colors.text } },
43
42
  fontFamily: 'inherit',
44
43
  fontSize: font.sizeMd,
45
44
  lineHeight: font.leadingSnug,
@@ -5,6 +5,7 @@
5
5
  import { shared } from '../../internal/shared.js';
6
6
  import { attrs, type Sx } from '../../internal/sx.js';
7
7
  import { colors, font, motion } from '../../tokens.stylex.js';
8
+ import { media } from '../../media.stylex.js';
8
9
 
9
10
  export type AppShellHeaderProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
10
11
  /**
@@ -16,8 +17,6 @@
16
17
  children?: Snippet;
17
18
  };
18
19
 
19
- const MOTION = '@media (prefers-reduced-motion: no-preference)';
20
-
21
20
  const styles = stylex.create({
22
21
  header: {
23
22
  display: 'flex',
@@ -34,7 +33,7 @@
34
33
  borderBottomStyle: 'solid',
35
34
  borderBottomColor: colors.line,
36
35
  fontSize: font.sizeMd,
37
- transitionProperty: { default: 'none', [MOTION]: 'padding-inline-start' },
36
+ transitionProperty: { default: 'none', [media.motion]: 'padding-inline-start' },
38
37
  transitionDuration: motion.slow,
39
38
  transitionTimingFunction: motion.easeInOut
40
39
  }
@@ -4,6 +4,7 @@
4
4
  import type { HTMLAttributes } from 'svelte/elements';
5
5
  import { attrs, type Sx } from '../../internal/sx.js';
6
6
  import { colors, motion } from '../../tokens.stylex.js';
7
+ import { media } from '../../media.stylex.js';
7
8
  import { useAppShell } from './context.js';
8
9
 
9
10
  export type AppShellSidebarProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
@@ -18,7 +19,6 @@
18
19
  children?: Snippet;
19
20
  };
20
21
 
21
- const MOTION = '@media (prefers-reduced-motion: no-preference)';
22
22
  // The drawer's curve: quick out of the edge, a long gentle settle
23
23
  const DRAWER = 'cubic-bezier(0.32, 0.72, 0, 1)';
24
24
 
@@ -34,7 +34,7 @@
34
34
  },
35
35
  wide: {
36
36
  width: 'calc(var(--narvi-sidebar-width) + var(--narvi-rail-current, 0px))',
37
- transitionProperty: { default: 'none', [MOTION]: 'width' },
37
+ transitionProperty: { default: 'none', [media.motion]: 'width' },
38
38
  transitionDuration: motion.slow,
39
39
  transitionTimingFunction: motion.easeInOut
40
40
  },
@@ -53,15 +53,15 @@
53
53
  // Hidden only once it has slid away; shown at once when it opens, so
54
54
  // focus can move into it on the first frame
55
55
  visibility: 'hidden',
56
- transitionProperty: { default: 'visibility', [MOTION]: 'translate, visibility' },
57
- transitionDuration: { default: '0s', [MOTION]: '320ms, 0s' },
58
- transitionDelay: { default: '0s', [MOTION]: '0s, 320ms' },
56
+ transitionProperty: { default: 'visibility', [media.motion]: 'translate, visibility' },
57
+ transitionDuration: { default: '0s', [media.motion]: '320ms, 0s' },
58
+ transitionDelay: { default: '0s', [media.motion]: '0s, 320ms' },
59
59
  transitionTimingFunction: DRAWER
60
60
  },
61
61
  drawerOpen: {
62
62
  translate: '0 0',
63
63
  visibility: 'visible',
64
- transitionDelay: { default: '0s', [MOTION]: '0s, 0s' }
64
+ transitionDelay: { default: '0s', [media.motion]: '0s, 0s' }
65
65
  },
66
66
  scrim: {
67
67
  position: 'fixed',
@@ -10,6 +10,7 @@
10
10
  import Glyph from '../../internal/Glyph.svelte';
11
11
  import { attrs, type Sx } from '../../internal/sx.js';
12
12
  import { colors, font, motion, radius, space } from '../../tokens.stylex.js';
13
+ import { media } from '../../media.stylex.js';
13
14
  import Button from '../button/Button.svelte';
14
15
 
15
16
  export type ApprovalChoice = {
@@ -48,8 +49,6 @@
48
49
  class?: string;
49
50
  };
50
51
 
51
- const MOTION = '@media (prefers-reduced-motion: no-preference)';
52
-
53
52
  const styles = stylex.create({
54
53
  card: {
55
54
  display: 'flex',
@@ -60,8 +59,11 @@
60
59
  backgroundColor: `color-mix(in oklab, ${colors.warning} 7%, ${colors.bgRaised})`,
61
60
  boxShadow: `inset 0 0 0 1px color-mix(in oklab, ${colors.warning} 40%, transparent)`,
62
61
  opacity: { default: 1, '@starting-style': 0 },
63
- translate: { default: null, [MOTION]: { default: '0 0', '@starting-style': '0 0.375rem' } },
64
- transitionProperty: { default: 'opacity', [MOTION]: 'opacity, translate' },
62
+ translate: {
63
+ default: null,
64
+ [media.motion]: { default: '0 0', '@starting-style': '0 0.375rem' }
65
+ },
66
+ transitionProperty: { default: 'opacity', [media.motion]: 'opacity, translate' },
65
67
  transitionDuration: motion.slow,
66
68
  transitionTimingFunction: motion.easeOut
67
69
  },
@@ -90,6 +92,8 @@
90
92
  files: {
91
93
  margin: 0,
92
94
  paddingInlineStart: '1rem',
95
+ // Stated, not left to the browser: a reset such as base.css removes markers
96
+ listStyleType: 'disc',
93
97
  color: colors.textMuted,
94
98
  fontFamily: font.mono,
95
99
  fontSize: font.sizeXs,
@@ -5,6 +5,7 @@
5
5
  import { shared } from '../../internal/shared.js';
6
6
  import { attrs, type Sx } from '../../internal/sx.js';
7
7
  import { colors, font, motion, radius } from '../../tokens.stylex.js';
8
+ import { media } from '../../media.stylex.js';
8
9
  import Spinner from '../spinner/Spinner.svelte';
9
10
 
10
11
  export type ButtonVariant = 'primary' | 'secondary' | 'soft' | 'ghost' | 'danger';
@@ -25,10 +26,6 @@
25
26
  children?: Snippet;
26
27
  };
27
28
 
28
- // StyleX needs these in the same file to evaluate them at build time
29
- const HOVER = '@media (hover: hover) and (pointer: fine)';
30
- const MOTION = '@media (prefers-reduced-motion: no-preference)';
31
-
32
29
  const styles = stylex.create({
33
30
  base: {
34
31
  position: 'relative',
@@ -49,16 +46,16 @@
49
46
  appearance: 'none',
50
47
  WebkitTapHighlightColor: 'transparent',
51
48
  // Press feedback, only for people who have not asked for less motion
52
- scale: { default: null, ':active': { default: null, [MOTION]: 0.96 } },
49
+ scale: { default: null, ':active': { default: null, [media.motion]: 0.96 } },
53
50
  // The press answers at once with a strong ease-out. Hover colours use a plain ease.
54
51
  transitionProperty: {
55
52
  default: 'background-color, color, filter',
56
- [MOTION]: 'scale, background-color, color, filter'
53
+ [media.motion]: 'scale, background-color, color, filter'
57
54
  },
58
55
  transitionDuration: motion.base,
59
56
  transitionTimingFunction: {
60
57
  default: 'ease',
61
- [MOTION]: `${motion.easeOut}, ease, ease, ease`
58
+ [media.motion]: `${motion.easeOut}, ease, ease, ease`
62
59
  }
63
60
  },
64
61
 
@@ -95,7 +92,7 @@
95
92
  color: colors.onMithril,
96
93
  backgroundImage: `linear-gradient(180deg, ${colors.mithrilTop}, ${colors.mithrilBottom})`,
97
94
  boxShadow: `inset 0 1px 0 ${colors.mithrilEdge}, inset 0 -1px 0 rgb(0 0 0 / 0.14), 0 1px 2px rgb(0 0 0 / 0.4), 0 10px 22px -10px ${colors.mithrilDrop}`,
98
- filter: { default: null, ':hover': { default: null, [HOVER]: 'brightness(1.06)' } },
95
+ filter: { default: null, ':hover': { default: null, [media.hover]: 'brightness(1.06)' } },
99
96
  // The deeper hover shadow is a layer of its own that fades in. Fading
100
97
  // opacity is cheap; animating the shadow itself repaints it every frame.
101
98
  '::before': {
@@ -104,7 +101,7 @@
104
101
  inset: 0,
105
102
  borderRadius: 'inherit',
106
103
  boxShadow: `0 12px 22px -10px ${colors.mithrilDrop}`,
107
- opacity: { default: 0, ':hover': { default: null, [HOVER]: 1 } },
104
+ opacity: { default: 0, ':hover': { default: null, [media.hover]: 1 } },
108
105
  pointerEvents: 'none',
109
106
  transitionProperty: 'opacity',
110
107
  transitionDuration: motion.base,
@@ -115,7 +112,7 @@
115
112
  color: colors.text,
116
113
  backgroundColor: {
117
114
  default: colors.surfaceRaised,
118
- ':hover': { default: null, [HOVER]: colors.hover }
115
+ ':hover': { default: null, [media.hover]: colors.hover }
119
116
  },
120
117
  boxShadow: `inset 0 0 0 1px ${colors.lineStrong}, inset 0 1px 0 ${colors.highlight}, 0 1px 2px ${colors.shade}`
121
118
  },
@@ -123,17 +120,17 @@
123
120
  color: colors.ithil,
124
121
  backgroundColor: {
125
122
  default: colors.ithilSoft,
126
- ':hover': { default: null, [HOVER]: colors.focusHalo }
123
+ ':hover': { default: null, [media.hover]: colors.focusHalo }
127
124
  }
128
125
  },
129
126
  ghost: {
130
127
  color: {
131
128
  default: colors.textMuted,
132
- ':hover': { default: null, [HOVER]: colors.text }
129
+ ':hover': { default: null, [media.hover]: colors.text }
133
130
  },
134
131
  backgroundColor: {
135
132
  default: 'transparent',
136
- ':hover': { default: null, [HOVER]: colors.hover }
133
+ ':hover': { default: null, [media.hover]: colors.hover }
137
134
  }
138
135
  },
139
136
  danger: {
@@ -142,7 +139,7 @@
142
139
  default: 'transparent',
143
140
  ':hover': {
144
141
  default: null,
145
- [HOVER]: `color-mix(in oklab, ${colors.danger} 12%, transparent)`
142
+ [media.hover]: `color-mix(in oklab, ${colors.danger} 12%, transparent)`
146
143
  }
147
144
  },
148
145
  boxShadow: `inset 0 0 0 1px color-mix(in oklab, ${colors.danger} 45%, transparent)`
@@ -163,7 +160,7 @@
163
160
  alignItems: 'center',
164
161
  justifyContent: 'center',
165
162
  gap: 'inherit',
166
- transitionProperty: { default: 'opacity', [MOTION]: 'opacity, filter' },
163
+ transitionProperty: { default: 'opacity', [media.motion]: 'opacity, filter' },
167
164
  transitionDuration: motion.base,
168
165
  transitionTimingFunction: motion.easeOut
169
166
  },
@@ -171,7 +168,7 @@
171
168
  // and not two things overlapping
172
169
  contentHidden: {
173
170
  opacity: 0,
174
- filter: { default: null, [MOTION]: 'blur(2px)' }
171
+ filter: { default: null, [media.motion]: 'blur(2px)' }
175
172
  },
176
173
  // The spinner fades in as the label fades out. It leaves at once: when the
177
174
  // work is done, the label should be back without delay.
@@ -181,8 +178,8 @@
181
178
  display: 'grid',
182
179
  placeItems: 'center',
183
180
  opacity: { default: 1, '@starting-style': 0 },
184
- scale: { default: null, [MOTION]: { default: 1, '@starting-style': 0.9 } },
185
- transitionProperty: { default: 'opacity', [MOTION]: 'opacity, scale' },
181
+ scale: { default: null, [media.motion]: { default: 1, '@starting-style': 0.9 } },
182
+ transitionProperty: { default: 'opacity', [media.motion]: 'opacity, scale' },
186
183
  transitionDuration: motion.base,
187
184
  transitionTimingFunction: motion.easeOut
188
185
  }