@peaske7/readit 0.2.0 → 0.3.0-rc.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 (179) hide show
  1. package/.claude/CLAUDE.md +118 -76
  2. package/.claude/commands/review.md +1 -1
  3. package/.claude/roadmap.md +32 -9
  4. package/.claude/user-stories.md +100 -15
  5. package/AGENTS.md +30 -26
  6. package/Makefile +32 -0
  7. package/README.md +90 -2
  8. package/biome.json +18 -8
  9. package/bun.lock +426 -568
  10. package/bunfig.toml +2 -0
  11. package/docs/perf-baseline.md +56 -1
  12. package/docs/superpowers/specs/2026-03-27-go-server-rewrite-design.md +284 -0
  13. package/e2e/comments.spec.ts +14 -58
  14. package/e2e/document-load.spec.ts +1 -23
  15. package/e2e/export.spec.ts +4 -4
  16. package/e2e/perf/add-comment.spec.ts +9 -11
  17. package/e2e/perf/fixtures/generate.ts +1 -5
  18. package/e2e/perf/screenshot-final.png +0 -0
  19. package/e2e/perf/utils/metrics.ts +73 -9
  20. package/e2e/persistence-file.spec.ts +41 -26
  21. package/e2e/utils/selection.ts +17 -73
  22. package/go/cmd/readit/main.go +416 -0
  23. package/go/go.mod +20 -0
  24. package/go/go.sum +41 -0
  25. package/go/internal/server/anchor.go +302 -0
  26. package/go/internal/server/anchor_test.go +111 -0
  27. package/go/internal/server/comments.go +390 -0
  28. package/go/internal/server/documents.go +113 -0
  29. package/go/internal/server/embed.go +17 -0
  30. package/go/internal/server/headings.go +33 -0
  31. package/go/internal/server/headings_test.go +75 -0
  32. package/go/internal/server/htmltext.go +123 -0
  33. package/go/internal/server/markdown.go +157 -0
  34. package/go/internal/server/markdown_bench_test.go +42 -0
  35. package/go/internal/server/markdown_test.go +79 -0
  36. package/go/internal/server/server.go +453 -0
  37. package/go/internal/server/server_bench_test.go +122 -0
  38. package/go/internal/server/settings.go +110 -0
  39. package/go/internal/server/sse.go +140 -0
  40. package/go/internal/server/storage.go +275 -0
  41. package/go/internal/server/storage_test.go +152 -0
  42. package/go/internal/server/template.go +66 -0
  43. package/go/internal/server/types.go +101 -0
  44. package/go/internal/server/watcher.go +74 -0
  45. package/index.html +4 -14
  46. package/nvim-readit/lua/readit/health.lua +64 -0
  47. package/nvim-readit/lua/readit/init.lua +463 -0
  48. package/nvim-readit/plugin/readit.lua +19 -0
  49. package/package.json +20 -28
  50. package/shell/_readit +158 -0
  51. package/shell/readit.zsh +87 -0
  52. package/src/App.svelte +890 -0
  53. package/src/cli.ts +183 -21
  54. package/src/components/ActionsMenu.svelte +95 -0
  55. package/src/components/CommentBadge.svelte +67 -0
  56. package/src/components/CommentErrorBanner.svelte +33 -0
  57. package/src/components/CommentInput.svelte +75 -0
  58. package/src/components/CommentListItem.svelte +95 -0
  59. package/src/components/CommentManager.svelte +129 -0
  60. package/src/components/CommentNav.svelte +109 -0
  61. package/src/components/DocumentViewer.svelte +233 -0
  62. package/src/components/FloatingComment.svelte +107 -0
  63. package/src/components/Header.svelte +76 -0
  64. package/src/components/InlineEditor.svelte +72 -0
  65. package/src/components/MarginNote.svelte +167 -0
  66. package/src/components/MarginNotesContainer.svelte +33 -0
  67. package/src/components/MermaidEnhancer.svelte +218 -0
  68. package/src/components/MermaidModal.svelte +67 -0
  69. package/src/components/RawModal.svelte +126 -0
  70. package/src/components/ReanchorConfirm.svelte +30 -0
  71. package/src/components/SettingsModal.svelte +220 -0
  72. package/src/components/ShortcutCapture.svelte +82 -0
  73. package/src/components/ShortcutList.svelte +145 -0
  74. package/src/components/TabBar.svelte +52 -0
  75. package/src/components/TableOfContents.svelte +125 -0
  76. package/src/components/ui/ActionLink.svelte +40 -0
  77. package/src/components/ui/{Button.tsx → Button.svelte} +19 -20
  78. package/src/components/ui/Dialog.svelte +97 -0
  79. package/src/components/ui/DropdownMenu.svelte +85 -0
  80. package/src/components/ui/DropdownMenuItem.svelte +38 -0
  81. package/src/components/ui/DropdownMenuSeparator.svelte +11 -0
  82. package/src/components/ui/{Text.tsx → Text.svelte} +18 -23
  83. package/src/env.d.ts +6 -0
  84. package/src/index.css +141 -166
  85. package/src/lib/__fixtures__/bench-data.ts +0 -13
  86. package/src/lib/anchor.bench.ts +1 -12
  87. package/src/lib/anchor.test.ts +0 -8
  88. package/src/lib/anchor.ts +0 -4
  89. package/src/lib/comment-storage.bench.ts +49 -0
  90. package/src/lib/comment-storage.test.ts +103 -33
  91. package/src/lib/comment-storage.ts +25 -18
  92. package/src/lib/export.bench.ts +21 -0
  93. package/src/lib/export.ts +0 -1
  94. package/src/lib/fetch-or-throw.test.ts +59 -0
  95. package/src/lib/fetch-or-throw.ts +12 -0
  96. package/src/{hooks/useHeadings.test.ts → lib/headings.test.ts} +10 -24
  97. package/src/{hooks/useHeadings.ts → lib/headings.ts} +11 -13
  98. package/src/lib/highlight/core.test.ts +0 -5
  99. package/src/lib/highlight/dom.ts +52 -216
  100. package/src/lib/highlight/highlight-registry.ts +221 -0
  101. package/src/lib/highlight/highlight.bench.ts +92 -0
  102. package/src/lib/highlight/highlighter.ts +112 -132
  103. package/src/lib/highlight/resolver.ts +5 -79
  104. package/src/lib/highlight/types.ts +0 -5
  105. package/src/lib/html-text.test.ts +162 -0
  106. package/src/lib/html-text.ts +161 -0
  107. package/src/lib/i18n/en.ts +34 -0
  108. package/src/lib/i18n/ja.ts +34 -0
  109. package/src/lib/i18n/types.ts +33 -0
  110. package/src/lib/key-lock.test.ts +104 -0
  111. package/src/lib/key-lock.ts +23 -0
  112. package/src/lib/margin-layout.bench.ts +61 -0
  113. package/src/lib/margin-layout.ts +0 -7
  114. package/src/lib/markdown-renderer.test.ts +154 -0
  115. package/src/lib/markdown-renderer.ts +178 -0
  116. package/src/lib/mermaid-config.ts +38 -0
  117. package/src/lib/mermaid-renderer.ts +162 -0
  118. package/src/lib/mermaid-worker.ts +60 -0
  119. package/src/lib/positions.ts +31 -24
  120. package/src/lib/shortcut-registry.ts +244 -0
  121. package/src/lib/utils.ts +0 -29
  122. package/src/main.ts +16 -0
  123. package/src/schema.ts +16 -5
  124. package/src/server.ts +355 -95
  125. package/src/stores/app.svelte.ts +231 -0
  126. package/src/stores/locale.svelte.ts +46 -0
  127. package/src/stores/settings.svelte.ts +90 -0
  128. package/src/stores/shortcuts.svelte.ts +104 -0
  129. package/src/stores/ui.svelte.ts +12 -0
  130. package/src/template.ts +104 -0
  131. package/src/test-setup.ts +47 -0
  132. package/svelte.config.js +5 -0
  133. package/tsconfig.json +2 -2
  134. package/vite.config.ts +23 -3
  135. package/vscode-readit/.mcp.json +7 -0
  136. package/vscode-readit/.vscodeignore +7 -0
  137. package/vscode-readit/bun.lock +78 -0
  138. package/vscode-readit/icon.svg +10 -0
  139. package/vscode-readit/package.json +110 -0
  140. package/vscode-readit/src/extension.ts +117 -0
  141. package/vscode-readit/src/server-manager.ts +272 -0
  142. package/vscode-readit/src/webview-provider.ts +204 -0
  143. package/vscode-readit/tsconfig.json +20 -0
  144. package/e2e/fixtures/sample.html +0 -13
  145. package/src/App.tsx +0 -368
  146. package/src/components/ActionsMenu.tsx +0 -91
  147. package/src/components/DocumentViewer/CodeBlock.tsx +0 -160
  148. package/src/components/DocumentViewer/DocumentViewer.tsx +0 -230
  149. package/src/components/DocumentViewer/MermaidDiagram.tsx +0 -136
  150. package/src/components/Header.tsx +0 -54
  151. package/src/components/InlineEditor.tsx +0 -74
  152. package/src/components/MarginNote.tsx +0 -185
  153. package/src/components/MarginNotes.tsx +0 -23
  154. package/src/components/RawModal.tsx +0 -144
  155. package/src/components/ReanchorConfirm.tsx +0 -36
  156. package/src/components/SettingsModal.tsx +0 -232
  157. package/src/components/TabBar.tsx +0 -60
  158. package/src/components/TableOfContents.tsx +0 -108
  159. package/src/components/comments/CommentBadge.tsx +0 -49
  160. package/src/components/comments/CommentInput.tsx +0 -86
  161. package/src/components/comments/CommentListItem.tsx +0 -90
  162. package/src/components/comments/CommentManager.tsx +0 -129
  163. package/src/components/comments/CommentNav.tsx +0 -109
  164. package/src/components/ui/ActionLink.tsx +0 -28
  165. package/src/components/ui/Dialog.tsx +0 -116
  166. package/src/components/ui/DropdownMenu.tsx +0 -158
  167. package/src/contexts/CommentContext.tsx +0 -198
  168. package/src/contexts/LocaleContext.tsx +0 -76
  169. package/src/contexts/PositionsContext.tsx +0 -16
  170. package/src/contexts/SettingsContext.tsx +0 -133
  171. package/src/hooks/useClickOutside.ts +0 -31
  172. package/src/hooks/useCommentNavigation.ts +0 -107
  173. package/src/hooks/useComments.ts +0 -311
  174. package/src/hooks/useDocument.ts +0 -157
  175. package/src/hooks/useScrollSpy.ts +0 -77
  176. package/src/hooks/useTextSelection.ts +0 -86
  177. package/src/lib/highlight/worker.ts +0 -45
  178. package/src/main.tsx +0 -13
  179. package/src/store.ts +0 -222
@@ -0,0 +1,30 @@
1
+ <script lang="ts">
2
+ import { t } from "../stores/locale.svelte";
3
+ import Button from "./ui/Button.svelte";
4
+ import Text from "./ui/Text.svelte";
5
+
6
+ interface Props {
7
+ selectionText: string;
8
+ onconfirm: () => void;
9
+ oncancel: () => void;
10
+ }
11
+
12
+ let { selectionText, onconfirm, oncancel }: Props = $props();
13
+ </script>
14
+
15
+ <div class="border-t border-zinc-200 dark:border-zinc-700 pt-2 pb-3 pl-6">
16
+ <Text variant="body" class="mb-2">
17
+ {t("reanchor.question")}
18
+ </Text>
19
+ <Text variant="caption" class="italic line-clamp-2 mb-2">
20
+ "{selectionText}"
21
+ </Text>
22
+ <div class="flex gap-3 text-sm">
23
+ <Button variant="link" size="sm" onclick={onconfirm}>
24
+ {t("reanchor.confirm")}
25
+ </Button>
26
+ <Button variant="ghost" size="sm" onclick={oncancel}>
27
+ {t("reanchor.cancel")}
28
+ </Button>
29
+ </div>
30
+ </div>
@@ -0,0 +1,220 @@
1
+ <script lang="ts">
2
+ import { Check, ChevronDown } from "lucide-svelte";
3
+ import { type Locale, Locales } from "../lib/i18n";
4
+ import { cn } from "../lib/utils";
5
+ import { FontFamilies, type FontFamily, ThemeModes } from "../schema";
6
+ import { localeState, setLocale, t } from "../stores/locale.svelte";
7
+ import {
8
+ settings,
9
+ updateFontFamily,
10
+ updateThemeMode,
11
+ } from "../stores/settings.svelte";
12
+ import ShortcutList from "./ShortcutList.svelte";
13
+ import Dialog from "./ui/Dialog.svelte";
14
+ import DropdownMenu from "./ui/DropdownMenu.svelte";
15
+ import DropdownMenuItem from "./ui/DropdownMenuItem.svelte";
16
+ import Text from "./ui/Text.svelte";
17
+
18
+ interface Props {
19
+ open: boolean;
20
+ onclose: () => void;
21
+ }
22
+
23
+ let { open = $bindable(false), onclose }: Props = $props();
24
+
25
+ const LOCALE_OPTIONS = [
26
+ { value: Locales.JA, label: "日本語" },
27
+ { value: Locales.EN, label: "English" },
28
+ ] as const;
29
+
30
+ let themeOptions = $derived([
31
+ { value: ThemeModes.SYSTEM, label: t("settings.theme.system") },
32
+ { value: ThemeModes.LIGHT, label: t("settings.theme.light") },
33
+ { value: ThemeModes.DARK, label: t("settings.theme.dark") },
34
+ ]);
35
+
36
+ let fontOptions = $derived([
37
+ {
38
+ value: FontFamilies.SERIF,
39
+ label: t("settings.font.serif"),
40
+ fontClass: "font-serif",
41
+ },
42
+ {
43
+ value: FontFamilies.SANS_SERIF,
44
+ label: t("settings.font.sansSerif"),
45
+ fontClass: "font-sans",
46
+ },
47
+ ]);
48
+
49
+ let activeTheme = $derived(
50
+ themeOptions.find((o) => o.value === settings.themeMode) ?? themeOptions[0],
51
+ );
52
+ let activeFont = $derived(
53
+ fontOptions.find((o) => o.value === settings.fontFamily) ?? fontOptions[0],
54
+ );
55
+ let activeLocale = $derived(
56
+ LOCALE_OPTIONS.find((o) => o.value === localeState.locale) ??
57
+ LOCALE_OPTIONS[0],
58
+ );
59
+
60
+ const triggerClassName = cn(
61
+ "inline-flex items-center gap-2 px-2.5 py-1.5 rounded-lg text-sm",
62
+ "border border-zinc-200 dark:border-zinc-700",
63
+ "bg-white dark:bg-zinc-800",
64
+ "text-zinc-700 dark:text-zinc-300",
65
+ "hover:bg-zinc-50 dark:hover:bg-zinc-700/50",
66
+ "transition-colors cursor-pointer",
67
+ );
68
+
69
+ let themeDropdownOpen = $state(false);
70
+ let fontDropdownOpen = $state(false);
71
+ let localeDropdownOpen = $state(false);
72
+ </script>
73
+
74
+ <Dialog bind:open {onclose} contentClass="max-w-md">
75
+ {#snippet header()}
76
+ {t("settings.title")}
77
+ {/snippet}
78
+
79
+ <div class="space-y-4">
80
+ <div>
81
+ <Text variant="overline" as="h3" class="mb-3">
82
+ {t("settings.theme")}
83
+ </Text>
84
+ <DropdownMenu bind:open={themeDropdownOpen} align="start" contentClass="min-w-[160px]">
85
+ {#snippet trigger()}
86
+ <button type="button" class={triggerClassName}>
87
+ {#if activeTheme.value === ThemeModes.SYSTEM}
88
+ <span
89
+ class="size-2.5 rounded-full bg-gradient-to-r from-amber-400 to-indigo-400"
90
+ ></span>
91
+ {:else}
92
+ <span
93
+ class={cn(
94
+ "size-2.5 rounded-full",
95
+ activeTheme.value === ThemeModes.LIGHT
96
+ ? "bg-amber-400"
97
+ : "bg-indigo-400",
98
+ )}
99
+ ></span>
100
+ {/if}
101
+ <span
102
+ class="text-[10px] font-semibold leading-none text-zinc-500 dark:text-zinc-400 bg-zinc-100 dark:bg-zinc-800 rounded px-1 py-0.5"
103
+ >Aa</span>
104
+ <span>{activeTheme.label}</span>
105
+ <ChevronDown class="size-3 text-zinc-400 dark:text-zinc-500" />
106
+ </button>
107
+ {/snippet}
108
+
109
+ {#each themeOptions as option (option.value)}
110
+ <DropdownMenuItem
111
+ onselect={() => {
112
+ updateThemeMode(option.value);
113
+ themeDropdownOpen = false;
114
+ }}
115
+ class="flex items-center gap-2"
116
+ >
117
+ {#if option.value === ThemeModes.SYSTEM}
118
+ <span
119
+ class="size-2.5 rounded-full bg-gradient-to-r from-amber-400 to-indigo-400"
120
+ ></span>
121
+ {:else}
122
+ <span
123
+ class={cn(
124
+ "size-2.5 rounded-full",
125
+ option.value === ThemeModes.LIGHT
126
+ ? "bg-amber-400"
127
+ : "bg-indigo-400",
128
+ )}
129
+ ></span>
130
+ {/if}
131
+ <span
132
+ class="text-[10px] font-semibold leading-none text-zinc-500 dark:text-zinc-400 bg-zinc-100 dark:bg-zinc-800 rounded px-1 py-0.5"
133
+ >Aa</span>
134
+ <span class="flex-1">{option.label}</span>
135
+ {#if settings.themeMode === option.value}
136
+ <Check class="size-3.5 text-zinc-500 dark:text-zinc-400" />
137
+ {/if}
138
+ </DropdownMenuItem>
139
+ {/each}
140
+ </DropdownMenu>
141
+ </div>
142
+
143
+ <div>
144
+ <Text variant="overline" as="h3" class="mb-3">
145
+ {t("settings.font")}
146
+ </Text>
147
+ <DropdownMenu bind:open={fontDropdownOpen} align="start" contentClass="min-w-[160px]">
148
+ {#snippet trigger()}
149
+ <button type="button" class={triggerClassName}>
150
+ <span
151
+ class={cn(
152
+ "text-[10px] font-semibold leading-none text-zinc-500 dark:text-zinc-400 bg-zinc-100 dark:bg-zinc-800 rounded px-1 py-0.5",
153
+ activeFont.fontClass,
154
+ )}
155
+ >Aa</span>
156
+ <span>{activeFont.label}</span>
157
+ <ChevronDown class="size-3 text-zinc-400 dark:text-zinc-500" />
158
+ </button>
159
+ {/snippet}
160
+
161
+ {#each fontOptions as option (option.value)}
162
+ <DropdownMenuItem
163
+ onselect={() => {
164
+ updateFontFamily(option.value as FontFamily);
165
+ fontDropdownOpen = false;
166
+ }}
167
+ class="flex items-center gap-2"
168
+ >
169
+ <span
170
+ class={cn(
171
+ "text-[10px] font-semibold leading-none text-zinc-500 dark:text-zinc-400 bg-zinc-100 dark:bg-zinc-800 rounded px-1 py-0.5",
172
+ option.fontClass,
173
+ )}
174
+ >Aa</span>
175
+ <span class="flex-1">{option.label}</span>
176
+ {#if settings.fontFamily === option.value}
177
+ <Check class="size-3.5 text-zinc-500 dark:text-zinc-400" />
178
+ {/if}
179
+ </DropdownMenuItem>
180
+ {/each}
181
+ </DropdownMenu>
182
+ </div>
183
+
184
+ <div>
185
+ <Text variant="overline" as="h3" class="mb-3">
186
+ {t("settings.language")}
187
+ </Text>
188
+ <DropdownMenu bind:open={localeDropdownOpen} align="start" contentClass="min-w-[160px]">
189
+ {#snippet trigger()}
190
+ <button type="button" class={triggerClassName}>
191
+ <span>{activeLocale.label}</span>
192
+ <ChevronDown class="size-3 text-zinc-400 dark:text-zinc-500" />
193
+ </button>
194
+ {/snippet}
195
+
196
+ {#each LOCALE_OPTIONS as option (option.value)}
197
+ <DropdownMenuItem
198
+ onselect={() => {
199
+ setLocale(option.value as Locale);
200
+ localeDropdownOpen = false;
201
+ }}
202
+ class="flex items-center gap-2"
203
+ >
204
+ <span class="flex-1">{option.label}</span>
205
+ {#if localeState.locale === option.value}
206
+ <Check class="size-3.5 text-zinc-500 dark:text-zinc-400" />
207
+ {/if}
208
+ </DropdownMenuItem>
209
+ {/each}
210
+ </DropdownMenu>
211
+ </div>
212
+
213
+ <div>
214
+ <Text variant="overline" as="h3" class="mb-3">
215
+ {t("shortcuts.title")}
216
+ </Text>
217
+ <ShortcutList />
218
+ </div>
219
+ </div>
220
+ </Dialog>
@@ -0,0 +1,82 @@
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import {
4
+ eventToBinding,
5
+ formatBinding,
6
+ isReservedBinding,
7
+ } from "../lib/shortcut-registry";
8
+ import { cn } from "../lib/utils";
9
+ import type { ShortcutBinding } from "../schema";
10
+ import { t } from "../stores/locale.svelte";
11
+
12
+ interface Props {
13
+ oncapture: (binding: ShortcutBinding) => void;
14
+ oncancel: () => void;
15
+ }
16
+
17
+ let { oncapture, oncancel }: Props = $props();
18
+
19
+ let captureEl: HTMLDivElement | undefined = $state();
20
+ let error = $state<string | null>(null);
21
+ const isMac = navigator.platform.includes("Mac");
22
+
23
+ function handleKeyDown(e: KeyboardEvent) {
24
+ e.preventDefault();
25
+ e.stopPropagation();
26
+
27
+ if (
28
+ e.key === "Alt" ||
29
+ e.key === "Shift" ||
30
+ e.key === "Control" ||
31
+ e.key === "Meta"
32
+ ) {
33
+ return;
34
+ }
35
+
36
+ if (e.key === "Escape" && !e.altKey && !e.metaKey && !e.shiftKey) {
37
+ oncancel();
38
+ return;
39
+ }
40
+
41
+ const binding = eventToBinding(e);
42
+
43
+ if (isReservedBinding(binding, isMac)) {
44
+ error = t("shortcutCapture.reserved", {
45
+ binding: formatBinding(binding, isMac),
46
+ });
47
+ return;
48
+ }
49
+
50
+ error = null;
51
+ oncapture(binding);
52
+ }
53
+
54
+ onMount(() => {
55
+ captureEl?.focus();
56
+ });
57
+ </script>
58
+
59
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
60
+ <div
61
+ role="button"
62
+ aria-label={t("shortcutCapture.ariaLabel")}
63
+ bind:this={captureEl}
64
+ tabindex={0}
65
+ onkeydown={handleKeyDown}
66
+ onblur={oncancel}
67
+ class={cn(
68
+ "inline-flex items-center gap-1.5 px-2 py-1 rounded-md text-xs font-medium",
69
+ "bg-amber-50 dark:bg-amber-900/30",
70
+ "border border-amber-300 dark:border-amber-600",
71
+ "text-amber-700 dark:text-amber-300",
72
+ "outline-none ring-2 ring-amber-400/50",
73
+ "animate-pulse",
74
+ )}
75
+ >
76
+ <span>{t("shortcutCapture.pressKeys")}</span>
77
+ {#if error}
78
+ <span class="text-red-500 dark:text-red-400 text-[10px] animate-none"
79
+ >{error}</span
80
+ >
81
+ {/if}
82
+ </div>
@@ -0,0 +1,145 @@
1
+ <script lang="ts">
2
+ import {
3
+ bindingsEqual,
4
+ formatBinding,
5
+ SHORTCUT_GROUPS,
6
+ type ShortcutDefinition,
7
+ } from "../lib/shortcut-registry";
8
+ import { cn } from "../lib/utils";
9
+ import type { ShortcutBinding } from "../schema";
10
+ import { t } from "../stores/locale.svelte";
11
+ import {
12
+ resetToDefaults,
13
+ shortcutState,
14
+ toggleEnabled,
15
+ updateBinding,
16
+ } from "../stores/shortcuts.svelte";
17
+ import ShortcutCapture from "./ShortcutCapture.svelte";
18
+ import Button from "./ui/Button.svelte";
19
+ import Text from "./ui/Text.svelte";
20
+
21
+ const isMac = navigator.platform.includes("Mac");
22
+ let capturingId = $state<string | null>(null);
23
+
24
+ function handleCapture(id: string, binding: ShortcutBinding) {
25
+ capturingId = null;
26
+ updateBinding(id, binding);
27
+ }
28
+
29
+ function handleCancelCapture() {
30
+ capturingId = null;
31
+ }
32
+
33
+ function startCapture(id: string) {
34
+ capturingId = id;
35
+ }
36
+
37
+ function getShortcut(id: string): ShortcutDefinition | undefined {
38
+ return shortcutState.shortcuts.find((s) => s.id === id);
39
+ }
40
+
41
+ function isModified(shortcut: ShortcutDefinition): boolean {
42
+ return (
43
+ !shortcut.enabled ||
44
+ !bindingsEqual(shortcut.binding, shortcut.defaultBinding)
45
+ );
46
+ }
47
+
48
+ let hasModifications = $derived(
49
+ shortcutState.shortcuts.some((s) => isModified(s)),
50
+ );
51
+ </script>
52
+
53
+ <div class="space-y-4">
54
+ {#each SHORTCUT_GROUPS as group (group.label)}
55
+ <div>
56
+ <Text variant="caption" as="div" class="mb-2 font-medium">
57
+ {t(group.label)}
58
+ </Text>
59
+
60
+ <div class="space-y-1">
61
+ {#each group.ids as id (id)}
62
+ {@const shortcut = getShortcut(id)}
63
+ {#if shortcut}
64
+ <div
65
+ class={cn(
66
+ "flex items-center gap-3 px-2 py-1.5 rounded-lg",
67
+ "hover:bg-zinc-50 dark:hover:bg-zinc-800/50",
68
+ !shortcut.enabled && "opacity-50",
69
+ )}
70
+ >
71
+ <div class="flex-1 min-w-0">
72
+ <div class="text-xs text-zinc-700 dark:text-zinc-300">
73
+ {t(shortcut.label)}
74
+ </div>
75
+ </div>
76
+
77
+ <div class="flex items-center gap-2">
78
+ {#if capturingId === shortcut.id}
79
+ <ShortcutCapture
80
+ oncapture={(binding) =>
81
+ handleCapture(shortcut.id, binding)}
82
+ oncancel={handleCancelCapture}
83
+ />
84
+ {:else}
85
+ <button
86
+ type="button"
87
+ onclick={() => startCapture(shortcut.id)}
88
+ class={cn(
89
+ "inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[11px] font-mono",
90
+ "bg-zinc-100 dark:bg-zinc-800",
91
+ "border border-zinc-200 dark:border-zinc-700",
92
+ "text-zinc-600 dark:text-zinc-400",
93
+ "hover:bg-zinc-200 dark:hover:bg-zinc-700",
94
+ "transition-colors cursor-pointer",
95
+ isModified(shortcut) &&
96
+ "ring-1 ring-blue-400/50 dark:ring-blue-500/50",
97
+ )}
98
+ >
99
+ {formatBinding(shortcut.binding, isMac)}
100
+ </button>
101
+ {/if}
102
+
103
+ <label
104
+ class="relative inline-flex items-center cursor-pointer"
105
+ title={t("shortcuts.enableDisable")}
106
+ >
107
+ <input
108
+ type="checkbox"
109
+ checked={shortcut.enabled}
110
+ onchange={() => toggleEnabled(shortcut.id)}
111
+ class="sr-only peer"
112
+ />
113
+ <div
114
+ class={cn(
115
+ "w-7 h-4 rounded-full transition-colors",
116
+ "bg-zinc-200 dark:bg-zinc-700",
117
+ "peer-checked:bg-blue-500 dark:peer-checked:bg-blue-600",
118
+ "after:content-[''] after:absolute after:top-0.5 after:start-[2px]",
119
+ "after:bg-white after:rounded-full after:size-3",
120
+ "after:transition-all after:duration-150",
121
+ "peer-checked:after:translate-x-full peer-checked:after:translate-x-3",
122
+ )}
123
+ ></div>
124
+ </label>
125
+ </div>
126
+ </div>
127
+ {/if}
128
+ {/each}
129
+ </div>
130
+ </div>
131
+ {/each}
132
+
133
+ {#if hasModifications}
134
+ <div class="pt-2 border-t border-zinc-100 dark:border-zinc-800">
135
+ <Button
136
+ variant="ghost"
137
+ size="sm"
138
+ onclick={resetToDefaults}
139
+ class="text-xs"
140
+ >
141
+ {t("shortcuts.resetToDefaults")}
142
+ </Button>
143
+ </div>
144
+ {/if}
145
+ </div>
@@ -0,0 +1,52 @@
1
+ <script lang="ts">
2
+ import { cn } from "../lib/utils";
3
+ import { app, closeDocument, setActiveDocument } from "../stores/app.svelte";
4
+ </script>
5
+
6
+ {#if app.documentOrder.length > 1}
7
+ <div
8
+ class="flex border-b border-zinc-200 dark:border-zinc-800 bg-zinc-50 dark:bg-zinc-900 px-2 overflow-x-auto"
9
+ role="tablist"
10
+ >
11
+ {#each app.documentOrder as filePath (filePath)}
12
+ {@const docState = app.documents.get(filePath)}
13
+ {@const isActive = filePath === app.activeDocumentPath}
14
+
15
+ {#if docState}
16
+ <div
17
+ role="tab"
18
+ tabindex={isActive ? 0 : -1}
19
+ aria-selected={isActive}
20
+ class={cn(
21
+ "flex items-center gap-1.5 px-3 py-1.5 text-sm border-b-2 whitespace-nowrap cursor-pointer select-none",
22
+ isActive
23
+ ? "border-zinc-900 dark:border-zinc-100 text-zinc-900 dark:text-zinc-100"
24
+ : "border-transparent text-zinc-500 dark:text-zinc-400 hover:text-zinc-700 dark:hover:text-zinc-300 hover:bg-zinc-100 dark:hover:bg-zinc-800",
25
+ )}
26
+ onclick={() => setActiveDocument(filePath)}
27
+ onkeydown={(e) => {
28
+ if (e.key === "Enter" || e.key === " ") {
29
+ e.preventDefault();
30
+ setActiveDocument(filePath);
31
+ }
32
+ }}
33
+ >
34
+ <span>{docState.document.fileName}</span>
35
+ <button
36
+ type="button"
37
+ aria-label="Close tab"
38
+ class="ml-1 rounded p-0.5 hover:bg-zinc-200 dark:hover:bg-zinc-700"
39
+ onclick={(e) => {
40
+ e.stopPropagation();
41
+ closeDocument(filePath);
42
+ }}
43
+ >
44
+ <svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2">
45
+ <path d="M18 6 6 18M6 6l12 12"></path>
46
+ </svg>
47
+ </button>
48
+ </div>
49
+ {/if}
50
+ {/each}
51
+ </div>
52
+ {/if}
@@ -0,0 +1,125 @@
1
+ <script lang="ts">
2
+ import type { Heading } from "../lib/headings";
3
+ import { cn } from "../lib/utils";
4
+ import { FontFamilies } from "../schema";
5
+ import { settings } from "../stores/settings.svelte";
6
+
7
+ interface Props {
8
+ headings: Heading[];
9
+ onheadingclick: (id: string) => void;
10
+ }
11
+
12
+ let { headings, onheadingclick }: Props = $props();
13
+
14
+ let fontClass = $derived(
15
+ settings.fontFamily === FontFamilies.SANS_SERIF ? "font-sans" : "font-serif",
16
+ );
17
+
18
+ let expandedH2s = $state(new Set<string>());
19
+
20
+ let h2sWithChildren = $derived.by(() => {
21
+ const result = new Set<string>();
22
+ let currentH2: string | null = null;
23
+
24
+ for (const heading of headings) {
25
+ if (heading.level === 2) {
26
+ currentH2 = heading.id;
27
+ } else if (heading.level > 2 && currentH2) {
28
+ result.add(currentH2);
29
+ } else if (heading.level === 1) {
30
+ currentH2 = null;
31
+ }
32
+ }
33
+ return result;
34
+ });
35
+
36
+ let visibleHeadings = $derived.by(() => {
37
+ let currentH2: string | null = null;
38
+
39
+ return headings.filter((heading) => {
40
+ if (heading.level <= 2) {
41
+ if (heading.level === 2) {
42
+ currentH2 = heading.id;
43
+ } else {
44
+ currentH2 = null;
45
+ }
46
+ return true;
47
+ }
48
+
49
+ return currentH2 !== null && expandedH2s.has(currentH2);
50
+ });
51
+ });
52
+
53
+ function toggleH2(id: string) {
54
+ const next = new Set(expandedH2s);
55
+ if (next.has(id)) {
56
+ next.delete(id);
57
+ } else {
58
+ next.add(id);
59
+ }
60
+ expandedH2s = next;
61
+ }
62
+
63
+ let observedActiveId = $state<string | null>(null);
64
+
65
+ $effect(() => {
66
+ if (headings.length === 0) return;
67
+
68
+ const headingElements = headings
69
+ .map((h) => document.getElementById(h.id))
70
+ .filter((el): el is HTMLElement => el !== null);
71
+
72
+ if (headingElements.length === 0) return;
73
+
74
+ const observer = new IntersectionObserver(
75
+ (entries) => {
76
+ for (const entry of entries) {
77
+ if (entry.isIntersecting) {
78
+ observedActiveId = entry.target.id;
79
+ }
80
+ }
81
+ },
82
+ {
83
+ rootMargin: "-80px 0px -60% 0px",
84
+ threshold: 0,
85
+ },
86
+ );
87
+
88
+ for (const el of headingElements) {
89
+ observer.observe(el);
90
+ }
91
+
92
+ return () => observer.disconnect();
93
+ });
94
+
95
+ let effectiveActiveId = $derived(observedActiveId);
96
+ </script>
97
+
98
+ {#if headings.length > 0}
99
+ <nav class={cn("toc", fontClass)} aria-label="Table of contents">
100
+ {#each visibleHeadings as heading (heading.id)}
101
+ {@const hasChildren =
102
+ heading.level === 2 && h2sWithChildren.has(heading.id)}
103
+ {@const isExpanded = expandedH2s.has(heading.id)}
104
+ <a
105
+ href={`#${heading.id}`}
106
+ title={heading.text}
107
+ class={`toc-item toc-level-${heading.level}${effectiveActiveId === heading.id ? " toc-active" : ""}`}
108
+ onclick={(e) => {
109
+ e.preventDefault();
110
+ if (hasChildren) {
111
+ toggleH2(heading.id);
112
+ }
113
+ onheadingclick(heading.id);
114
+ }}
115
+ >
116
+ {heading.text}
117
+ {#if hasChildren}
118
+ <span class="toc-toggle ml-1 opacity-40">
119
+ {isExpanded ? "\u25BE" : "\u25B8"}
120
+ </span>
121
+ {/if}
122
+ </a>
123
+ {/each}
124
+ </nav>
125
+ {/if}
@@ -0,0 +1,40 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ import { cn } from "../../lib/utils";
4
+
5
+ const variantStyles = {
6
+ default: "hover:text-zinc-600",
7
+ destructive: "hover:text-red-500",
8
+ } as const;
9
+
10
+ type ActionLinkVariant = keyof typeof variantStyles;
11
+
12
+ interface Props {
13
+ variant?: ActionLinkVariant;
14
+ onclick?: (e: MouseEvent) => void;
15
+ class?: string;
16
+ disabled?: boolean;
17
+ children: Snippet;
18
+ }
19
+
20
+ let {
21
+ variant = "default",
22
+ onclick,
23
+ class: className,
24
+ disabled = false,
25
+ children,
26
+ }: Props = $props();
27
+ </script>
28
+
29
+ <button
30
+ type="button"
31
+ {disabled}
32
+ class={cn(
33
+ "cursor-pointer transition-colors duration-150",
34
+ variantStyles[variant],
35
+ className,
36
+ )}
37
+ {onclick}
38
+ >
39
+ {@render children()}
40
+ </button>