@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
@@ -1,86 +0,0 @@
1
- import { useCallback, useEffect } from "react";
2
- import type { Selection } from "../schema";
3
- import { appStore, useAppStore } from "../store";
4
-
5
- /** Remove pending highlight marks from the DOM without triggering a full clear/reapply cycle. */
6
- function clearPendingMarks() {
7
- for (const mark of document.querySelectorAll("mark[data-pending]")) {
8
- const parent = mark.parentNode;
9
- if (!parent) continue;
10
- while (mark.firstChild) parent.insertBefore(mark.firstChild, mark);
11
- parent.removeChild(mark);
12
- }
13
- }
14
-
15
- interface UseTextSelectionResult {
16
- selection: Selection | null;
17
- pendingSelectionTop: number | undefined;
18
- onTextSelect: (
19
- text: string,
20
- startOffset: number,
21
- endOffset: number,
22
- selectionTop: number,
23
- ) => void;
24
- clearSelection: () => void;
25
- }
26
-
27
- export function useTextSelection(): UseTextSelectionResult {
28
- const selection = useAppStore(
29
- (s) => s.getActiveDocumentState()?.selection ?? null,
30
- );
31
- const pendingSelectionTop = useAppStore(
32
- (s) => s.getActiveDocumentState()?.pendingSelectionTop,
33
- );
34
-
35
- useEffect(() => {
36
- if (!selection) return;
37
-
38
- const handleClickOutside = (e: MouseEvent) => {
39
- const target = e.target as HTMLElement;
40
- if (target.closest("[data-comment-input]")) return;
41
- if (target.closest("mark[data-pending]")) return;
42
- if (target.closest("mark[data-comment-id]")) return;
43
-
44
- appStore.getState().setSelection(null);
45
- appStore.getState().setPendingSelectionTop(undefined);
46
- clearPendingMarks();
47
- requestAnimationFrame(() => {
48
- const sel = window.getSelection();
49
- if (sel?.isCollapsed) {
50
- sel.removeAllRanges();
51
- }
52
- });
53
- };
54
-
55
- // Use mousedown to catch clicks before text selection
56
- document.addEventListener("mousedown", handleClickOutside);
57
- return () => document.removeEventListener("mousedown", handleClickOutside);
58
- }, [selection]);
59
-
60
- const onTextSelect = useCallback(
61
- (
62
- text: string,
63
- startOffset: number,
64
- endOffset: number,
65
- selectionTop: number,
66
- ) => {
67
- appStore.getState().setSelection({ text, startOffset, endOffset });
68
- appStore.getState().setPendingSelectionTop(selectionTop);
69
- },
70
- [],
71
- );
72
-
73
- const clearSelection = useCallback(() => {
74
- appStore.getState().setSelection(null);
75
- appStore.getState().setPendingSelectionTop(undefined);
76
- clearPendingMarks();
77
- window.getSelection()?.removeAllRanges();
78
- }, []);
79
-
80
- return {
81
- selection,
82
- pendingSelectionTop,
83
- onTextSelect,
84
- clearSelection,
85
- };
86
- }
@@ -1,45 +0,0 @@
1
- // Inlined to avoid module import issues in Worker context
2
- function find(
3
- text: string,
4
- needle: string,
5
- hint?: number,
6
- ): { start: number; end: number } | undefined {
7
- if (!needle || !text) return undefined;
8
-
9
- const hits: number[] = [];
10
- let i = 0;
11
- for (;;) {
12
- i = text.indexOf(needle, i);
13
- if (i === -1) break;
14
- hits.push(i);
15
- i += 1;
16
- }
17
-
18
- if (hits.length === 0) return undefined;
19
- if (hits.length === 1)
20
- return { start: hits[0], end: hits[0] + needle.length };
21
-
22
- const target = hint ?? 0;
23
- let best = hits[0];
24
- let bestDist = Math.abs(best - target);
25
- for (const h of hits) {
26
- const d = Math.abs(h - target);
27
- if (d < bestDist) {
28
- bestDist = d;
29
- best = h;
30
- }
31
- }
32
- return { start: best, end: best + needle.length };
33
- }
34
-
35
- self.onmessage = (e: MessageEvent) => {
36
- const { id, textContent, comments } = e.data;
37
- const results: { id: string; start: number; end: number }[] = [];
38
-
39
- for (const c of comments) {
40
- const pos = find(textContent, c.selectedText, c.startOffset);
41
- if (pos) results.push({ id: c.id, ...pos });
42
- }
43
-
44
- self.postMessage({ id, results });
45
- };
package/src/main.tsx DELETED
@@ -1,13 +0,0 @@
1
- import React from "react";
2
- import ReactDOM from "react-dom/client";
3
- import App from "./App";
4
- import { LocaleProvider } from "./contexts/LocaleContext";
5
- import "./index.css";
6
-
7
- ReactDOM.createRoot(document.getElementById("root")!).render(
8
- <React.StrictMode>
9
- <LocaleProvider>
10
- <App />
11
- </LocaleProvider>
12
- </React.StrictMode>,
13
- );
package/src/store.ts DELETED
@@ -1,222 +0,0 @@
1
- import { createStore, useStore } from "zustand";
2
- import type { Comment, Document, Selection } from "./schema";
3
-
4
- export interface DocumentState {
5
- document: Document;
6
- comments: Comment[];
7
- commentsError: string | null;
8
- sortedComments: Comment[];
9
- selection: Selection | null;
10
- pendingSelectionTop: number | undefined;
11
- pendingCommentText: string;
12
- scrollY: number;
13
- reanchorTarget: { commentId: string } | null;
14
- }
15
-
16
- export interface AppStore {
17
- documents: Map<string, DocumentState>;
18
- activeDocumentPath: string | null;
19
- documentOrder: string[];
20
- workingDirectory: string | null;
21
-
22
- setWorkingDirectory: (dir: string) => void;
23
- openDocument: (doc: Document, opts?: { active?: boolean }) => void;
24
- closeDocument: (filePath: string) => void;
25
- setActiveDocument: (filePath: string) => void;
26
-
27
- // Setters default to active doc when filePath omitted
28
- setComments: (comments: Comment[], filePath?: string) => void;
29
- setCommentsError: (error: string | null, filePath?: string) => void;
30
- setSelection: (selection: Selection | null, filePath?: string) => void;
31
- setPendingSelectionTop: (top: number | undefined, filePath?: string) => void;
32
- setScrollY: (y: number, filePath?: string) => void;
33
- setReanchorTarget: (
34
- target: { commentId: string } | null,
35
- filePath?: string,
36
- ) => void;
37
- setPendingCommentText: (text: string, filePath?: string) => void;
38
- updateDocumentContent: (content: string, filePath?: string) => void;
39
-
40
- getActiveDocumentState: () => DocumentState | undefined;
41
- }
42
-
43
- function createInitialDocumentState(doc: Document): DocumentState {
44
- return {
45
- document: doc,
46
- comments: [],
47
- commentsError: null,
48
- sortedComments: [],
49
- selection: null,
50
- pendingSelectionTop: undefined,
51
- pendingCommentText: "",
52
- scrollY: 0,
53
- reanchorTarget: null,
54
- };
55
- }
56
-
57
- function sortComments(comments: Comment[]): Comment[] {
58
- return [...comments].sort((a, b) => a.startOffset - b.startOffset);
59
- }
60
-
61
- export function createAppStore() {
62
- return createStore<AppStore>((set, get) => {
63
- const resolveFilePath = (filePath?: string): string | null =>
64
- filePath ?? get().activeDocumentPath;
65
-
66
- const updateDocState = (
67
- filePath: string,
68
- updater: (state: DocumentState) => Partial<DocumentState>,
69
- ) => {
70
- set((prev) => {
71
- const docState = prev.documents.get(filePath);
72
- if (!docState) return prev;
73
- const updates = updater(docState);
74
- const newDocs = new Map(prev.documents);
75
- newDocs.set(filePath, { ...docState, ...updates });
76
- return { documents: newDocs };
77
- });
78
- };
79
-
80
- return {
81
- documents: new Map(),
82
- activeDocumentPath: null,
83
- documentOrder: [],
84
- workingDirectory: null,
85
-
86
- setWorkingDirectory: (dir) => set({ workingDirectory: dir }),
87
-
88
- openDocument: (doc, opts) => {
89
- set((prev) => {
90
- const active = opts?.active ?? true;
91
- const nextActive =
92
- active || !prev.activeDocumentPath
93
- ? doc.filePath
94
- : prev.activeDocumentPath;
95
-
96
- if (prev.documents.has(doc.filePath)) {
97
- const newDocs = new Map(prev.documents);
98
- const prevDoc = newDocs.get(doc.filePath)!;
99
- newDocs.set(doc.filePath, {
100
- ...prevDoc,
101
- document: { ...prevDoc.document, ...doc },
102
- });
103
- return {
104
- documents: newDocs,
105
- activeDocumentPath: nextActive,
106
- };
107
- }
108
- const newDocs = new Map(prev.documents);
109
- newDocs.set(doc.filePath, createInitialDocumentState(doc));
110
- return {
111
- documents: newDocs,
112
- activeDocumentPath: nextActive,
113
- documentOrder: [...prev.documentOrder, doc.filePath],
114
- };
115
- });
116
- },
117
-
118
- closeDocument: (filePath) => {
119
- set((prev) => {
120
- const newDocs = new Map(prev.documents);
121
- newDocs.delete(filePath);
122
- const newOrder = prev.documentOrder.filter((p) => p !== filePath);
123
-
124
- let newActive = prev.activeDocumentPath;
125
- if (prev.activeDocumentPath === filePath) {
126
- const oldIndex = prev.documentOrder.indexOf(filePath);
127
- newActive = newOrder[oldIndex] ?? newOrder[oldIndex - 1] ?? null;
128
- }
129
-
130
- return {
131
- documents: newDocs,
132
- activeDocumentPath: newActive,
133
- documentOrder: newOrder,
134
- };
135
- });
136
- },
137
-
138
- setActiveDocument: (filePath) => {
139
- if (get().documents.has(filePath)) {
140
- set({ activeDocumentPath: filePath });
141
- }
142
- },
143
-
144
- setComments: (comments, filePath?) => {
145
- const path = resolveFilePath(filePath);
146
- if (!path) return;
147
- updateDocState(path, () => ({
148
- comments,
149
- sortedComments: sortComments(comments),
150
- }));
151
- },
152
-
153
- setCommentsError: (error, filePath?) => {
154
- const path = resolveFilePath(filePath);
155
- if (!path) return;
156
- updateDocState(path, () => ({ commentsError: error }));
157
- },
158
-
159
- setSelection: (selection, filePath?) => {
160
- const path = resolveFilePath(filePath);
161
- if (!path) return;
162
- updateDocState(path, () => ({ selection }));
163
- },
164
-
165
- setPendingSelectionTop: (top, filePath?) => {
166
- const path = resolveFilePath(filePath);
167
- if (!path) return;
168
- updateDocState(path, () => ({ pendingSelectionTop: top }));
169
- },
170
-
171
- setScrollY: (y, filePath?) => {
172
- const path = resolveFilePath(filePath);
173
- if (!path) return;
174
- updateDocState(path, () => ({ scrollY: y }));
175
- },
176
-
177
- setReanchorTarget: (target, filePath?) => {
178
- const path = resolveFilePath(filePath);
179
- if (!path) return;
180
- updateDocState(path, () => ({ reanchorTarget: target }));
181
- },
182
-
183
- setPendingCommentText: (text, filePath?) => {
184
- const path = resolveFilePath(filePath);
185
- if (!path) return;
186
- updateDocState(path, () => ({ pendingCommentText: text }));
187
- },
188
-
189
- updateDocumentContent: (content, filePath?) => {
190
- const path = resolveFilePath(filePath);
191
- if (!path) return;
192
- updateDocState(path, (s) => ({
193
- document: { ...s.document, content },
194
- }));
195
- },
196
-
197
- getActiveDocumentState: () => {
198
- const { documents, activeDocumentPath } = get();
199
- if (!activeDocumentPath) return undefined;
200
- return documents.get(activeDocumentPath);
201
- },
202
- };
203
- });
204
- }
205
-
206
- export const appStore = createAppStore();
207
-
208
- export function useAppStore<T>(selector: (state: AppStore) => T): T {
209
- return useStore(appStore, selector);
210
- }
211
-
212
- interface UIState {
213
- hoveredCommentId: string | undefined;
214
- }
215
-
216
- export const uiStore = createStore<UIState>(() => ({
217
- hoveredCommentId: undefined,
218
- }));
219
-
220
- export function useUI<T>(selector: (s: UIState) => T): T {
221
- return useStore(uiStore, selector);
222
- }