@diegopluna/narvi 0.3.2 → 0.3.4

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 (133) hide show
  1. package/dist/components/activity/ActivityIcon.svelte +54 -0
  2. package/dist/components/activity/ActivityIcon.svelte.d.ts +24 -0
  3. package/dist/components/activity/ActivityStep.svelte +47 -13
  4. package/dist/components/activity/ActivityStep.svelte.d.ts +13 -4
  5. package/dist/components/activity/ActivityThought.svelte +24 -5
  6. package/dist/components/activity/ActivityThought.svelte.d.ts +12 -2
  7. package/dist/components/activity/index.d.ts +3 -1
  8. package/dist/components/activity/index.js +2 -1
  9. package/dist/components/app-shell/AppShellHeader.svelte +18 -4
  10. package/dist/components/app-shell/AppShellHeader.svelte.d.ts +5 -0
  11. package/dist/components/app-shell/AppShellMain.svelte +14 -2
  12. package/dist/components/app-shell/AppShellPanel.svelte +77 -12
  13. package/dist/components/app-shell/AppShellPanel.svelte.d.ts +11 -1
  14. package/dist/components/app-shell/AppShellSheet.svelte +11 -1
  15. package/dist/components/app-shell/context.d.ts +8 -0
  16. package/dist/components/app-shell/context.js +7 -0
  17. package/dist/components/approval/Approval.svelte +14 -1
  18. package/dist/components/approval/Approval.svelte.d.ts +5 -0
  19. package/dist/components/avatar/AvatarRoot.svelte +20 -7
  20. package/dist/components/avatar/AvatarRoot.svelte.d.ts +10 -3
  21. package/dist/components/badge/Badge.svelte +3 -1
  22. package/dist/components/badge/Badge.svelte.d.ts +1 -1
  23. package/dist/components/button/Button.svelte +28 -6
  24. package/dist/components/button/Button.svelte.d.ts +7 -0
  25. package/dist/components/composer/ComposerModelPicker.svelte +80 -13
  26. package/dist/components/composer/ComposerModelPicker.svelte.d.ts +23 -6
  27. package/dist/components/composer/ComposerRoot.svelte +51 -12
  28. package/dist/components/composer/ComposerRoot.svelte.d.ts +16 -0
  29. package/dist/components/composer/ComposerSubmit.svelte +19 -5
  30. package/dist/components/composer/ComposerSubmit.svelte.d.ts +3 -1
  31. package/dist/components/composer/ComposerToggle.svelte +18 -4
  32. package/dist/components/composer/ComposerToggle.svelte.d.ts +2 -0
  33. package/dist/components/composer/ComposerTray.svelte +17 -3
  34. package/dist/components/composer/ComposerTray.svelte.d.ts +5 -0
  35. package/dist/components/composer/context.d.ts +4 -1
  36. package/dist/components/dialog/DialogContent.svelte +22 -12
  37. package/dist/components/dialog/DialogContent.svelte.d.ts +10 -0
  38. package/dist/components/divider/Divider.svelte +56 -14
  39. package/dist/components/divider/Divider.svelte.d.ts +13 -3
  40. package/dist/components/empty-state/EmptyState.svelte +12 -2
  41. package/dist/components/empty-state/EmptyState.svelte.d.ts +6 -0
  42. package/dist/components/heading/Heading.svelte +15 -0
  43. package/dist/components/heading/Heading.svelte.d.ts +6 -0
  44. package/dist/components/hover-card/HoverCardContent.svelte +18 -2
  45. package/dist/components/hover-card/HoverCardContent.svelte.d.ts +8 -0
  46. package/dist/components/input/Input.svelte +13 -3
  47. package/dist/components/input/Input.svelte.d.ts +10 -2
  48. package/dist/components/markdown/Markdown.svelte +22 -2
  49. package/dist/components/markdown/MarkdownDiagram.svelte +33 -2
  50. package/dist/components/markdown/MarkdownFile.svelte +56 -10
  51. package/dist/components/markdown/MarkdownMath.svelte +6 -0
  52. package/dist/components/markdown/MarkdownTable.svelte +3 -4
  53. package/dist/components/markdown/context.d.ts +6 -0
  54. package/dist/components/markdown/labels.d.ts +7 -0
  55. package/dist/components/markdown/labels.js +2 -0
  56. package/dist/components/menu/MenuCheckboxItem.svelte +44 -7
  57. package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +12 -2
  58. package/dist/components/menu/MenuContent.svelte +10 -2
  59. package/dist/components/menu/MenuContent.svelte.d.ts +10 -0
  60. package/dist/components/menu/MenuItem.svelte +17 -2
  61. package/dist/components/menu/MenuItem.svelte.d.ts +8 -0
  62. package/dist/components/menu/MenuSubContent.svelte +10 -2
  63. package/dist/components/menu/MenuSubContent.svelte.d.ts +10 -0
  64. package/dist/components/menu/MenuSubTrigger.svelte +19 -2
  65. package/dist/components/menu/MenuSubTrigger.svelte.d.ts +6 -0
  66. package/dist/components/message/MessageBubble.svelte +40 -0
  67. package/dist/components/message/MessageBubble.svelte.d.ts +12 -0
  68. package/dist/components/message/MessageContent.svelte +23 -14
  69. package/dist/components/message/MessageContent.svelte.d.ts +6 -0
  70. package/dist/components/message/MessageCopy.svelte +27 -15
  71. package/dist/components/message/MessageCopy.svelte.d.ts +9 -2
  72. package/dist/components/message/MessageRoot.svelte +20 -3
  73. package/dist/components/message/MessageRoot.svelte.d.ts +6 -0
  74. package/dist/components/message/context.d.ts +2 -0
  75. package/dist/components/message/index.d.ts +4 -1
  76. package/dist/components/message/index.js +3 -2
  77. package/dist/components/message/styles.d.ts +30 -0
  78. package/dist/components/message/styles.js +24 -0
  79. package/dist/components/notice/Notice.svelte +3 -3
  80. package/dist/components/popover/PopoverContent.svelte +27 -3
  81. package/dist/components/popover/PopoverContent.svelte.d.ts +18 -0
  82. package/dist/components/questionnaire/Questionnaire.svelte +103 -19
  83. package/dist/components/questionnaire/Questionnaire.svelte.d.ts +13 -1
  84. package/dist/components/queued-message/QueuedMessage.svelte +44 -6
  85. package/dist/components/queued-message/QueuedMessage.svelte.d.ts +12 -1
  86. package/dist/components/segmented/SegmentedControl.svelte +12 -1
  87. package/dist/components/segmented/SegmentedControl.svelte.d.ts +3 -1
  88. package/dist/components/select/Select.svelte +43 -6
  89. package/dist/components/select/Select.svelte.d.ts +14 -0
  90. package/dist/components/settings-row/SettingsRow.svelte +87 -37
  91. package/dist/components/settings-row/SettingsRow.svelte.d.ts +13 -0
  92. package/dist/components/split-button/SplitButton.svelte +137 -0
  93. package/dist/components/split-button/SplitButton.svelte.d.ts +29 -0
  94. package/dist/components/tab-strip/TabStrip.svelte +337 -93
  95. package/dist/components/tab-strip/TabStrip.svelte.d.ts +36 -1
  96. package/dist/components/tab-strip/drag.svelte.d.ts +31 -0
  97. package/dist/components/tab-strip/drag.svelte.js +148 -0
  98. package/dist/components/toast/Toaster.svelte +1 -1
  99. package/dist/components/toggle/Toggle.svelte +12 -2
  100. package/dist/components/toggle/Toggle.svelte.d.ts +11 -1
  101. package/dist/components/toggle-group/ToggleGroupItem.svelte +10 -1
  102. package/dist/components/toggle-group/ToggleGroupRoot.svelte +7 -1
  103. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +3 -1
  104. package/dist/components/toggle-group/context.d.ts +2 -1
  105. package/dist/components/tooltip/TooltipContent.svelte +13 -1
  106. package/dist/components/tooltip/TooltipContent.svelte.d.ts +10 -0
  107. package/dist/components/work-fold/WorkFold.svelte +13 -4
  108. package/dist/components/work-fold/WorkFold.svelte.d.ts +2 -1
  109. package/dist/focus-ring.d.ts +29 -0
  110. package/dist/focus-ring.js +42 -0
  111. package/dist/index.d.ts +8 -5
  112. package/dist/index.js +8 -2
  113. package/dist/internal/Collapse.svelte +15 -2
  114. package/dist/internal/Glyph.svelte +28 -0
  115. package/dist/internal/Glyph.svelte.d.ts +5 -0
  116. package/dist/internal/Tile.svelte +3 -2
  117. package/dist/internal/layer.d.ts +23 -0
  118. package/dist/internal/layer.js +19 -0
  119. package/dist/internal/toggle.d.ts +8 -1
  120. package/dist/internal/toggle.js +20 -2
  121. package/dist/markdown/file-paths.d.ts +7 -0
  122. package/dist/markdown/file-paths.js +29 -0
  123. package/dist/markdown/files.d.ts +22 -2
  124. package/dist/markdown/files.js +45 -14
  125. package/dist/tokens.stylex.d.ts +3 -0
  126. package/dist/tokens.stylex.js +5 -1
  127. package/package.json +1 -1
  128. package/skills/building-ui/SKILL.md +77 -5
  129. package/skills/building-ui/references/components.md +51 -50
  130. package/skills/markdown/SKILL.md +22 -6
  131. package/skills/setup/SKILL.md +1 -1
  132. package/skills/styling/SKILL.md +10 -3
  133. package/skills/theming/SKILL.md +11 -4
@@ -7,7 +7,13 @@
7
7
  import { colors, font, radius, space } from '../../tokens.stylex.js';
8
8
 
9
9
  export type EmptyStateProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'title'> & {
10
+ /** What is empty, as a heading. */
10
11
  title: string;
12
+ /**
13
+ * The heading's level, for the page's outline: `2` by default, for a place that stands
14
+ * where a section's content would be. Its look stays the same at every level.
15
+ */
16
+ level?: 1 | 2 | 3 | 4 | 5 | 6 | undefined;
11
17
  /** What to do about it: text, or a snippet with code or a link in it. */
12
18
  description?: string | Snippet | undefined;
13
19
  /** An icon or picture above the title. */
@@ -42,8 +48,11 @@
42
48
  title: {
43
49
  margin: 0,
44
50
  color: colors.text,
51
+ fontFamily: font.body,
45
52
  fontSize: font.sizeReading,
46
- fontWeight: font.weightSemibold
53
+ fontWeight: font.weightSemibold,
54
+ lineHeight: font.leadingSnug,
55
+ letterSpacing: 'normal'
47
56
  },
48
57
  description: {
49
58
  maxWidth: '26rem',
@@ -65,6 +74,7 @@
65
74
  <script lang="ts">
66
75
  let {
67
76
  title,
77
+ level = 2,
68
78
  description,
69
79
  media,
70
80
  actions,
@@ -76,7 +86,7 @@
76
86
 
77
87
  <div data-slot="empty-state" {...rest} {...attrs([styles.empty, sx], className)}>
78
88
  {#if media}<div {...stylex.attrs(styles.media)}>{@render media()}</div>{/if}
79
- <p {...stylex.attrs(styles.title)}>{title}</p>
89
+ <svelte:element this={`h${level}`} {...stylex.attrs(styles.title)}>{title}</svelte:element>
80
90
  {#if description}
81
91
  <p {...stylex.attrs(styles.description)}>
82
92
  {#if typeof description === 'string'}{description}{:else}{@render description()}{/if}
@@ -2,7 +2,13 @@ import type { Snippet } from 'svelte';
2
2
  import type { HTMLAttributes } from 'svelte/elements';
3
3
  import { type Sx } from '../../internal/sx.js';
4
4
  export type EmptyStateProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'title'> & {
5
+ /** What is empty, as a heading. */
5
6
  title: string;
7
+ /**
8
+ * The heading's level, for the page's outline: `2` by default, for a place that stands
9
+ * where a section's content would be. Its look stays the same at every level.
10
+ */
11
+ level?: 1 | 2 | 3 | 4 | 5 | 6 | undefined;
6
12
  /** What to do about it: text, or a snippet with code or a link in it. */
7
13
  description?: string | Snippet | undefined;
8
14
  /** An icon or picture above the title. */
@@ -7,12 +7,18 @@
7
7
 
8
8
  export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
9
9
  export type HeadingSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
10
+ export type HeadingWeight = 'regular' | 'medium' | 'semibold' | 'display';
10
11
 
11
12
  export type HeadingProps = Omit<HTMLAttributes<HTMLHeadingElement>, 'children'> & {
12
13
  /** Semantic level: renders `h1` to `h6`. Pick it for the document outline, not the look. */
13
14
  level?: HeadingLevel | undefined;
14
15
  /** Visual size. `xl` and up are set in the display serif; smaller ones in the interface font. */
15
16
  size?: HeadingSize | undefined;
17
+ /**
18
+ * Its weight, from the font's roles. By default the interface sizes are semibold and the
19
+ * display sizes take the display face's own weight (`display`).
20
+ */
21
+ weight?: HeadingWeight | undefined;
16
22
  /** Cuts the heading off with an ellipsis on one line, for a name that may run long. */
17
23
  truncate?: boolean | undefined;
18
24
  sx?: Sx | undefined;
@@ -47,6 +53,13 @@
47
53
  }
48
54
  });
49
55
 
56
+ const weights = stylex.create({
57
+ regular: { fontWeight: font.weightRegular },
58
+ medium: { fontWeight: font.weightMedium },
59
+ semibold: { fontWeight: font.weightSemibold },
60
+ display: { fontWeight: font.weightDisplay }
61
+ });
62
+
50
63
  const sizes = stylex.create({
51
64
  sm: { fontSize: font.sizeBody },
52
65
  md: { fontSize: font.sizeReading },
@@ -77,6 +90,7 @@
77
90
  let {
78
91
  level = 2,
79
92
  size,
93
+ weight,
80
94
  truncate = false,
81
95
  sx,
82
96
  class: className,
@@ -95,6 +109,7 @@
95
109
  styles.base,
96
110
  isDisplay(resolved) ? styles.display : styles.interface,
97
111
  sizes[resolved],
112
+ weight && weights[weight],
98
113
  truncate && styles.truncate,
99
114
  sx
100
115
  ],
@@ -3,11 +3,17 @@ import type { HTMLAttributes } from 'svelte/elements';
3
3
  import { type Sx } from '../../internal/sx.js';
4
4
  export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
5
5
  export type HeadingSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
6
+ export type HeadingWeight = 'regular' | 'medium' | 'semibold' | 'display';
6
7
  export type HeadingProps = Omit<HTMLAttributes<HTMLHeadingElement>, 'children'> & {
7
8
  /** Semantic level: renders `h1` to `h6`. Pick it for the document outline, not the look. */
8
9
  level?: HeadingLevel | undefined;
9
10
  /** Visual size. `xl` and up are set in the display serif; smaller ones in the interface font. */
10
11
  size?: HeadingSize | undefined;
12
+ /**
13
+ * Its weight, from the font's roles. By default the interface sizes are semibold and the
14
+ * display sizes take the display face's own weight (`display`).
15
+ */
16
+ weight?: HeadingWeight | undefined;
11
17
  /** Cuts the heading off with an ellipsis on one line, for a name that may run long. */
12
18
  truncate?: boolean | undefined;
13
19
  sx?: Sx | undefined;
@@ -8,6 +8,10 @@
8
8
 
9
9
  export type HoverCardContentProps = Loose<
10
10
  Omit<LinkPreview.ContentProps, 'children' | 'child'> & {
11
+ /** `column` sets its content one part under another, with room between them. */
12
+ layout?: 'block' | 'column' | undefined;
13
+ /** `none` takes the padding away, for content that brings its own. */
14
+ padding?: 'default' | 'none' | undefined;
11
15
  sx?: Sx | undefined;
12
16
  children?: Snippet | undefined;
13
17
  }
@@ -19,7 +23,8 @@
19
23
  width: '20rem',
20
24
  minWidth: 0,
21
25
  padding: '0.75rem'
22
- }
26
+ },
27
+ bare: { padding: 0 }
23
28
  });
24
29
  </script>
25
30
 
@@ -29,6 +34,8 @@
29
34
  sideOffset = 6,
30
35
  collisionPadding = 8,
31
36
  align = 'start',
37
+ layout = 'block',
38
+ padding = 'default',
32
39
  ref = $bindable(null),
33
40
  sx,
34
41
  class: className,
@@ -46,7 +53,16 @@
46
53
  {align}
47
54
  data-slot="hover-card-content"
48
55
  {...rest}
49
- {...attrs([layer.surface, styles.card, sx], className)}
56
+ {...attrs(
57
+ [
58
+ layer.surface,
59
+ styles.card,
60
+ padding === 'none' && styles.bare,
61
+ layout === 'column' && layer.column,
62
+ sx
63
+ ],
64
+ className
65
+ )}
50
66
  >
51
67
  {@render children?.()}
52
68
  </LinkPreview.Content>
@@ -3,10 +3,18 @@ import { LinkPreview } from 'bits-ui';
3
3
  import type { Snippet } from 'svelte';
4
4
  import { type Sx } from '../../internal/sx.js';
5
5
  export type HoverCardContentProps = Loose<Omit<LinkPreview.ContentProps, 'children' | 'child'> & {
6
+ /** `column` sets its content one part under another, with room between them. */
7
+ layout?: 'block' | 'column' | undefined;
8
+ /** `none` takes the padding away, for content that brings its own. */
9
+ padding?: 'default' | 'none' | undefined;
6
10
  sx?: Sx | undefined;
7
11
  children?: Snippet | undefined;
8
12
  }>;
9
13
  declare const HoverCardContent: import("svelte").Component<Loose<Omit<LinkPreview.ContentProps, "children" | "child"> & {
14
+ /** `column` sets its content one part under another, with room between them. */
15
+ layout?: "block" | "column" | undefined;
16
+ /** `none` takes the padding away, for content that brings its own. */
17
+ padding?: "default" | "none" | undefined;
10
18
  sx?: Sx | undefined;
11
19
  children?: Snippet | undefined;
12
20
  }>, {}, "ref">;
@@ -16,10 +16,18 @@
16
16
  invalid?: boolean | undefined;
17
17
  /**
18
18
  * An icon at the start of the field, such as a magnifier, sized to the field. With one,
19
- * `sx` and `class` style the element around the field.
19
+ * `sx` and `class` style the element around the field, and `inputSx` and `inputClass`
20
+ * the field itself.
20
21
  */
21
22
  icon?: Snippet | undefined;
22
23
  sx?: Sx | undefined;
24
+ /**
25
+ * Styles for the field itself, whether or not there is an `icon`: its text, its fill,
26
+ * its edge. Without an icon they go after `sx`.
27
+ */
28
+ inputSx?: Sx | undefined;
29
+ /** Classes for the field itself, as `inputSx`. */
30
+ inputClass?: ClassValue | null | undefined;
23
31
  ref?: HTMLInputElement | null | undefined;
24
32
  };
25
33
 
@@ -59,6 +67,8 @@
59
67
  'aria-describedby': describedBy,
60
68
  sx,
61
69
  class: className,
70
+ inputSx,
71
+ inputClass,
62
72
  ref = $bindable(null),
63
73
  ...rest
64
74
  }: InputProps = $props();
@@ -86,8 +96,8 @@
86
96
  <span data-icons aria-hidden="true" {...stylex.attrs(styles.icon, iconStyles[size])}>
87
97
  {@render icon()}
88
98
  </span>
89
- {@render input([besideStyles[size]])}
99
+ {@render input([besideStyles[size], inputSx], inputClass)}
90
100
  </span>
91
101
  {:else}
92
- {@render input([sx], className)}
102
+ {@render input([sx, inputSx], [className, inputClass])}
93
103
  {/if}
@@ -1,5 +1,5 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { HTMLInputAttributes } from 'svelte/elements';
2
+ import type { ClassValue, HTMLInputAttributes } from 'svelte/elements';
3
3
  import '../../internal/icons.css';
4
4
  import { type ControlSize } from '../../internal/control.js';
5
5
  import { type Sx } from '../../internal/sx.js';
@@ -10,10 +10,18 @@ export type InputProps = Omit<HTMLInputAttributes, 'size' | 'children'> & {
10
10
  invalid?: boolean | undefined;
11
11
  /**
12
12
  * An icon at the start of the field, such as a magnifier, sized to the field. With one,
13
- * `sx` and `class` style the element around the field.
13
+ * `sx` and `class` style the element around the field, and `inputSx` and `inputClass`
14
+ * the field itself.
14
15
  */
15
16
  icon?: Snippet | undefined;
16
17
  sx?: Sx | undefined;
18
+ /**
19
+ * Styles for the field itself, whether or not there is an `icon`: its text, its fill,
20
+ * its edge. Without an icon they go after `sx`.
21
+ */
22
+ inputSx?: Sx | undefined;
23
+ /** Classes for the field itself, as `inputSx`. */
24
+ inputClass?: ClassValue | null | undefined;
17
25
  ref?: HTMLInputElement | null | undefined;
18
26
  };
19
27
  declare const Input: import("svelte").Component<InputProps, {}, "value" | "ref">;
@@ -38,6 +38,7 @@
38
38
  import { measureScrollables } from './scrollable.js';
39
39
  import { staticHtml, type StaticContext } from './static.js';
40
40
  import { prose } from './styles.js';
41
+ import { visuallyHidden } from '../../visually-hidden.js';
41
42
 
42
43
  export type MarkdownProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
43
44
  /** The Markdown text: all of it so far, while it streams. */
@@ -479,8 +480,11 @@
479
480
  if (block?.type === 'code') saveFile(codeFileName(codeTitle(block), block.lang), code);
480
481
  } else
481
482
  void navigator.clipboard.writeText(withoutControls(code)).then(
482
- () => showCopied(button, words.copied),
483
- () => {}
483
+ () => {
484
+ showCopied(button, words.copied);
485
+ announce(words.copied);
486
+ },
487
+ () => announce(words.copyFailed)
484
488
  );
485
489
  }
486
490
  }
@@ -613,6 +617,7 @@
613
617
  get labels() {
614
618
  return words;
615
619
  },
620
+ announce,
616
621
  woken: (id) => woken.has(id),
617
622
  task: () => ontaskchange,
618
623
  math: {
@@ -654,6 +659,20 @@
654
659
  }
655
660
  };
656
661
  setMarkdownContext(context);
662
+
663
+ /** What the document's status region says now: emptied a moment later, so it can say it again. */
664
+ let said = $state('');
665
+ let saidTimer: ReturnType<typeof setTimeout> | undefined;
666
+ function announce(message: string) {
667
+ clearTimeout(saidTimer);
668
+ // Emptied first, so the same words twice in a row are read twice
669
+ said = '';
670
+ saidTimer = setTimeout(() => {
671
+ said = message;
672
+ saidTimer = setTimeout(() => (said = ''), 2000);
673
+ }, 50);
674
+ }
675
+ $effect(() => () => clearTimeout(saidTimer));
657
676
  </script>
658
677
 
659
678
  <div
@@ -690,6 +709,7 @@
690
709
  footnotes={before ? NO_FOOTNOTES : footnotes}
691
710
  order={before ? NO_ORDER : footnoteOrder.order}
692
711
  />
712
+ <span role="status" data-markdown-status {...stylex.attrs(visuallyHidden)}>{said}</span>
693
713
  </div>
694
714
 
695
715
  <!--
@@ -168,6 +168,7 @@
168
168
  let { node }: MarkdownDiagramProps = $props();
169
169
 
170
170
  const md = getMarkdownContext();
171
+ const uid = $props.id();
171
172
 
172
173
  const source = $derived(node.value.trim());
173
174
 
@@ -183,6 +184,29 @@
183
184
  let expanded = $state(false);
184
185
  let stage = $state<HTMLElement | null>(null);
185
186
 
187
+ // A diagram's name holds the first of its words: enough to know it by, not all it says
188
+ const NAMED_LABELS = 12;
189
+
190
+ /**
191
+ * Names the picture, which Pele leaves without a name unless its source gives a title:
192
+ * the words in it, so a screen reader can tell one diagram from the next.
193
+ */
194
+ function name(element: HTMLElement) {
195
+ const svg = element.querySelector<SVGSVGElement>(':scope > svg');
196
+ if (!svg) return;
197
+ svg.setAttribute('role', 'img');
198
+ if (svg.hasAttribute('aria-labelledby')) return;
199
+ // Read once, while the name is written: nothing reacts to it
200
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
201
+ const words = new Set<string>();
202
+ for (const text of svg.querySelectorAll('text')) {
203
+ const word = text.textContent?.replace(/\s+/g, ' ').trim();
204
+ if (word) words.add(word);
205
+ if (words.size === NAMED_LABELS) break;
206
+ }
207
+ svg.setAttribute('aria-label', md.labels.diagramPicture([...words]));
208
+ }
209
+
186
210
  /**
187
211
  * Pele shrinks a diagram to the width it has. In a narrow column that makes its labels too
188
212
  * small to read, so past three quarters of its own size the diagram scrolls instead.
@@ -204,6 +228,8 @@
204
228
  ([pele, sanitize]) => {
205
229
  if (gone) return;
206
230
  mounted = pele.mount(element, text, {
231
+ // Two drawings of one diagram, and two diagrams, keep the ids of their titles apart
232
+ idPrefix: `${md.id}-diagram-${uid}-${zoom ? 'zoom' : 'page'}`,
207
233
  links: false,
208
234
  images: false,
209
235
  zoom: zoom
@@ -222,6 +248,7 @@
222
248
  onRender: () => {
223
249
  failure = null;
224
250
  drawn = true;
251
+ name(element);
225
252
  if (!zoom) keepLegible(element);
226
253
  },
227
254
  onError: (cause) =>
@@ -242,6 +269,9 @@
242
269
  }
243
270
 
244
271
  $effect(() => draw(canvas, false));
272
+ $effect(() => {
273
+ if (failure) md.announce(md.labels.diagramFailed(failure.message));
274
+ });
245
275
  // The full-size view draws its own copy, which pans and zooms
246
276
  $effect(() => draw(stage, true));
247
277
  </script>
@@ -263,8 +293,9 @@
263
293
  {/if}
264
294
  </div>
265
295
  {#if failure}
266
- <!-- Said, not shouted: a thread can open with several of these -->
267
- <p role="status" {...attrs([styles.failure])}>
296
+ <!-- Read out through the reply's one status region (below), not a region of its own:
297
+ said, not shouted, as a thread can open with several of these -->
298
+ <p data-markdown-diagram-failure {...attrs([styles.failure])}>
268
299
  {md.labels.diagramFailed(failure.message)}
269
300
  </p>
270
301
  {/if}
@@ -1,15 +1,16 @@
1
1
  <!--
2
- A file named in a reply, as a chip: its name, with the whole path as its title. With a way
3
- to open files it is a button; without one it only shows.
2
+ A file named in a reply, as a chip: an icon for its kind (a folder, code, an image, text,
3
+ data) or the app's own, its name, with the whole path as its title. With a way to open
4
+ files it is a button; without one it only shows.
4
5
  -->
5
6
  <script lang="ts" module>
6
7
  import * as stylex from '@stylexjs/stylex';
7
8
  import type { Snippet } from 'svelte';
8
- import Glyph, { glyphHtml } from '../../internal/Glyph.svelte';
9
+ import Glyph, { glyphHtml, type GlyphName } from '../../internal/Glyph.svelte';
9
10
  import { attrs, classes } from '../../internal/sx.js';
10
11
  import type { StaticTools } from '../../markdown/plugin.js';
11
12
  import type { InlineCustom } from '../../markdown/ast.js';
12
- import { formatPosition, type FileReference } from '../../markdown/file-paths.js';
13
+ import { formatPosition, type FileKind, type FileReference } from '../../markdown/file-paths.js';
13
14
  import { colors, motion, radius } from '../../tokens.stylex.js';
14
15
  import { media } from '../../media.stylex.js';
15
16
 
@@ -59,6 +60,18 @@
59
60
  // A chip made from a link keeps the link's words, in the text's own face
60
61
  words: { fontFamily: 'inherit', fontSize: '0.9375em' },
61
62
  icon: { flexShrink: 0, color: colors.textSubtle },
63
+ // The app's own icon, an SVG drawn as a mask in the colour it gives, or the icon's
64
+ own: {
65
+ display: 'inline-block',
66
+ width: '12px',
67
+ height: '12px',
68
+ backgroundColor: 'currentColor',
69
+ maskImage: 'var(--narvi-file-icon)',
70
+ maskSize: 'contain',
71
+ maskRepeat: 'no-repeat',
72
+ maskPosition: 'center',
73
+ forcedColorAdjust: 'auto'
74
+ },
62
75
  label: { minWidth: 0, overflowWrap: 'anywhere' }
63
76
  });
64
77
 
@@ -69,6 +82,32 @@
69
82
  buttonWords: classes(styles.chip, styles.button, styles.words)
70
83
  };
71
84
  const iconClass = classes(styles.icon);
85
+ const ownIconClass = classes(styles.icon, styles.own);
86
+
87
+ type ChipData = FileReference & {
88
+ source: string;
89
+ link?: boolean | undefined;
90
+ kind?: FileKind | undefined;
91
+ icon?: { url: string; color?: string | undefined } | undefined;
92
+ };
93
+
94
+ const KIND_GLYPHS: Record<FileKind, GlyphName> = {
95
+ folder: 'folder',
96
+ code: 'fileCode',
97
+ image: 'fileImage',
98
+ text: 'fileText',
99
+ data: 'fileData',
100
+ file: 'file'
101
+ };
102
+
103
+ /** The icon as markup: the app's own, or Narvi's for the kind. */
104
+ function iconHtml(file: ChipData, escape: (text: string) => string): string {
105
+ if (file.icon) {
106
+ const color = file.icon.color ? `; color: ${escape(file.icon.color)}` : '';
107
+ return `<span aria-hidden="true" class="${ownIconClass}" style="--narvi-file-icon: url(&quot;${escape(file.icon.url)}&quot;)${color}"></span>`;
108
+ }
109
+ return glyphHtml(KIND_GLYPHS[file.kind ?? 'file'], 12, 1.5, iconClass);
110
+ }
72
111
  const labelClass = classes(styles.label);
73
112
 
74
113
  /**
@@ -76,11 +115,11 @@
76
115
  * file it names, for `chipFile` to read back when it is pressed.
77
116
  */
78
117
  export function fileHtml(node: InlineCustom, opens: boolean, tools: StaticTools): string {
79
- const file = node.data as FileReference & { source: string; link?: boolean | undefined };
118
+ const file = node.data as ChipData;
80
119
  const attributes =
81
120
  ` data-markdown-file="true" data-markdown-copy="${tools.escape(file.source)}"` +
82
121
  ` title="${tools.escape(file.path + formatPosition(file))}"`;
83
- const inside = `${glyphHtml('file', 12, 1.5, iconClass)}<span class="${labelClass}">${tools.children()}</span>`;
122
+ const inside = `${iconHtml(file, tools.escape)}<span class="${labelClass}">${tools.children()}</span>`;
84
123
  if (!opens)
85
124
  return `<span${attributes} class="${file.link ? chipClass.shownWords : chipClass.shown}">${inside}</span>`;
86
125
  const { path, line, column, endLine } = file;
@@ -102,14 +141,21 @@
102
141
  <script lang="ts">
103
142
  let { node, children, open }: MarkdownFileProps = $props();
104
143
 
105
- const file = $derived(
106
- node.data as FileReference & { source: string; link?: boolean | undefined }
107
- );
144
+ const file = $derived(node.data as ChipData);
108
145
  const title = $derived(file.path + formatPosition(file));
109
146
  </script>
110
147
 
111
148
  {#snippet content()}
112
- <Glyph name="file" size={12} {...attrs([styles.icon])} />
149
+ {#if file.icon}
150
+ <span
151
+ aria-hidden="true"
152
+ style:--narvi-file-icon={`url("${file.icon.url}")`}
153
+ style:color={file.icon.color}
154
+ {...attrs([styles.icon, styles.own])}
155
+ ></span>
156
+ {:else}
157
+ <Glyph name={KIND_GLYPHS[file.kind ?? 'file']} size={12} {...attrs([styles.icon])} />
158
+ {/if}
113
159
  <span {...attrs([styles.label])}>{@render children?.()}</span>
114
160
  {/snippet}
115
161
 
@@ -37,6 +37,8 @@
37
37
  // characters takes seconds, and 85 KB of nested braces make 12 MB of markup. No formula a
38
38
  // person reads is this long; a longer one shows as its source.
39
39
  const MAX_TEX = 10_000;
40
+ // KaTeX escapes the TeX it writes here, so no `<` comes before the closing tag
41
+ const ANNOTATION = /<annotation encoding="application\/x-tex">[^<]*<\/annotation>/g;
40
42
  const MAX_MARKUP = 200_000;
41
43
  // Many formulas, each within those limits, could still fill the page with millions of
42
44
  // elements. A document's formulas share this much markup; past it, they show as source.
@@ -63,6 +65,10 @@
63
65
  } catch {
64
66
  html = '';
65
67
  }
68
+ // KaTeX keeps the formula's TeX in its MathML as an annotation. Hidden as it is, the
69
+ // page's find and a test's text search still find it, so the source reads as being
70
+ // on the page twice. A copy takes the TeX from `data-markdown-copy`, so it goes.
71
+ html = html.replace(ANNOTATION, '');
66
72
  if (html.length > MAX_MARKUP) html = '';
67
73
  while (cache.size >= CACHE_SIZE || (cached + html.length > CACHE_BYTES && cache.size > 0)) {
68
74
  const oldest = cache.keys().next().value!;
@@ -3,7 +3,6 @@
3
3
  on hover or focus, copies it as Markdown or CSV, or saves it as a CSV file.
4
4
  -->
5
5
  <script lang="ts" module>
6
- import { visuallyHidden } from '../../visually-hidden.js';
7
6
  import * as stylex from '@stylexjs/stylex';
8
7
  import Glyph, { glyphHtml } from '../../internal/Glyph.svelte';
9
8
  import { markdownTableMarker } from '../../internal/markers.stylex.js';
@@ -120,7 +119,7 @@
120
119
  bare: true,
121
120
  inner: glyphHtml('copy')
122
121
  }) +
123
- `</div><span role="status" class="${classes(visuallyHidden)}"></span></div>`
122
+ `</div></div>`
124
123
  );
125
124
  }
126
125
  </script>
@@ -149,8 +148,10 @@
149
148
  try {
150
149
  await navigator.clipboard.writeText(text);
151
150
  } catch {
151
+ md.announce(md.labels.copyFailed);
152
152
  return;
153
153
  }
154
+ md.announce(md.labels.copied);
154
155
  copied = true;
155
156
  clearTimeout(timer);
156
157
  timer = setTimeout(() => (copied = false), 2000);
@@ -252,7 +253,5 @@
252
253
  </Menu.Root>
253
254
  {/if}
254
255
  </div>
255
- <!-- Outside the button: a button's contents are not read out as they change -->
256
- <span role="status" {...attrs([visuallyHidden])}>{copied ? md.labels.copied : ''}</span>
257
256
  {/if}
258
257
  </div>
@@ -35,6 +35,12 @@ export type MarkdownContext = {
35
35
  breaks: () => boolean;
36
36
  /** The words the controls show. */
37
37
  labels: MarkdownLabels;
38
+ /**
39
+ * Says a short message to assistive technology, in the document's one status region:
40
+ * "Copied", or why a diagram could not be drawn. One region for the whole reply, not one
41
+ * per code block and table, so a long reply is not full of empty ones.
42
+ */
43
+ announce: (message: string) => void;
38
44
  /** Called when a task item's box is ticked or cleared, when the app takes that. */
39
45
  task: () => ((item: ListItem, checked: boolean) => unknown) | undefined;
40
46
  /** Whether a block that `static` wrote has been asked for as parts: a table whose menu is wanted. */
@@ -6,6 +6,8 @@ export type MarkdownLabels = {
6
6
  copyCode: string;
7
7
  downloadCode: string;
8
8
  copied: string;
9
+ /** Said when the clipboard turned a copy away. */
10
+ copyFailed: string;
9
11
  /** Names the table's menu button. */
10
12
  tableActions: string;
11
13
  copyAsMarkdown: string;
@@ -19,6 +21,11 @@ export type MarkdownLabels = {
19
21
  zoomIn: string;
20
22
  zoomOut: string;
21
23
  resetZoom: string;
24
+ /**
25
+ * Names a diagram's picture for assistive technology, from the words in it, when its
26
+ * source gives it no title (`accTitle`).
27
+ */
28
+ diagramPicture: (labels: string[]) => string;
22
29
  /** Says a diagram could not be drawn, with the reason. */
23
30
  diagramFailed: (reason: string) => string;
24
31
  diagramNotLoaded: string;
@@ -2,6 +2,7 @@ export const defaultLabels = {
2
2
  copyCode: 'Copy code',
3
3
  downloadCode: 'Download code',
4
4
  copied: 'Copied',
5
+ copyFailed: "Couldn't copy",
5
6
  tableActions: 'Copy or save this table',
6
7
  copyAsMarkdown: 'Copy as Markdown',
7
8
  copyAsCsv: 'Copy as CSV',
@@ -14,6 +15,7 @@ export const defaultLabels = {
14
15
  zoomIn: 'Zoom in',
15
16
  zoomOut: 'Zoom out',
16
17
  resetZoom: 'Reset zoom',
18
+ diagramPicture: (labels) => (labels.length ? `Diagram: ${labels.join(', ')}` : 'Diagram'),
17
19
  diagramFailed: (reason) => `This diagram could not be drawn: ${reason}`,
18
20
  diagramNotLoaded: 'What draws diagrams could not be loaded.',
19
21
  diagramInvalid: 'It is not a diagram that can be drawn.',