@peaske7/readit 0.1.8 → 0.2.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 (118) hide show
  1. package/README.md +0 -3
  2. package/biome.json +1 -1
  3. package/bun.lock +43 -185
  4. package/docs/perf-baseline.md +75 -0
  5. package/docs/superpowers/plans/2026-03-26-surgical-pruning.md +1176 -0
  6. package/e2e/perf/add-comment.spec.ts +118 -0
  7. package/e2e/perf/fixtures/generate.ts +331 -0
  8. package/e2e/perf/initial-load.spec.ts +49 -0
  9. package/e2e/perf/perf.setup.ts +23 -0
  10. package/e2e/perf/perf.teardown.ts +9 -0
  11. package/e2e/perf/scroll.spec.ts +39 -0
  12. package/e2e/perf/tab-switch.spec.ts +69 -0
  13. package/e2e/perf/text-selection.spec.ts +119 -0
  14. package/e2e/perf/utils/metrics.ts +286 -0
  15. package/e2e/perf/utils/perf-cli.ts +86 -0
  16. package/package.json +9 -18
  17. package/playwright.config.ts +12 -0
  18. package/src/App.tsx +124 -172
  19. package/src/{cli/index.ts → cli.ts} +37 -53
  20. package/src/components/ActionsMenu.tsx +6 -27
  21. package/src/components/DocumentViewer/DocumentViewer.tsx +77 -106
  22. package/src/components/DocumentViewer/MermaidDiagram.tsx +6 -7
  23. package/src/components/Header.tsx +9 -20
  24. package/src/components/InlineEditor.tsx +5 -5
  25. package/src/components/MarginNote.tsx +71 -93
  26. package/src/components/MarginNotes.tsx +7 -34
  27. package/src/components/RawModal.tsx +9 -8
  28. package/src/components/ReanchorConfirm.tsx +2 -2
  29. package/src/components/SettingsModal.tsx +11 -89
  30. package/src/components/TabBar.tsx +4 -4
  31. package/src/components/TableOfContents.tsx +5 -5
  32. package/src/components/comments/CommentInput.tsx +7 -35
  33. package/src/components/comments/CommentListItem.tsx +9 -11
  34. package/src/components/comments/CommentManager.tsx +53 -37
  35. package/src/components/comments/CommentNav.tsx +14 -14
  36. package/src/components/ui/ActionLink.tsx +14 -18
  37. package/src/components/ui/Button.tsx +42 -43
  38. package/src/components/ui/Dialog.tsx +73 -113
  39. package/src/components/ui/DropdownMenu.tsx +113 -69
  40. package/src/components/ui/Text.tsx +30 -37
  41. package/src/contexts/CommentContext.tsx +75 -106
  42. package/src/contexts/LocaleContext.tsx +45 -4
  43. package/src/contexts/PositionsContext.tsx +16 -0
  44. package/src/contexts/SettingsContext.tsx +133 -0
  45. package/src/hooks/useClickOutside.ts +0 -4
  46. package/src/hooks/useCommentNavigation.ts +6 -29
  47. package/src/hooks/useComments.ts +6 -18
  48. package/src/hooks/useDocument.ts +35 -34
  49. package/src/hooks/useHeadings.test.ts +8 -50
  50. package/src/hooks/useHeadings.ts +5 -88
  51. package/src/hooks/useScrollSpy.ts +10 -14
  52. package/src/hooks/useTextSelection.ts +1 -38
  53. package/src/lib/__fixtures__/bench-data.ts +1 -41
  54. package/src/lib/anchor.bench.ts +57 -67
  55. package/src/lib/anchor.test.ts +5 -1
  56. package/src/lib/anchor.ts +13 -93
  57. package/src/lib/comment-storage.test.ts +4 -4
  58. package/src/lib/comment-storage.ts +2 -46
  59. package/src/lib/export.ts +7 -13
  60. package/src/lib/highlight/core.test.ts +1 -1
  61. package/src/lib/highlight/dom.ts +5 -68
  62. package/src/lib/highlight/highlighter.ts +102 -262
  63. package/src/lib/highlight/resolver.ts +112 -0
  64. package/src/lib/highlight/types.ts +0 -35
  65. package/src/lib/highlight/worker.ts +45 -0
  66. package/src/lib/i18n/en.ts +1 -50
  67. package/src/lib/i18n/ja.ts +1 -50
  68. package/src/lib/i18n/types.ts +1 -49
  69. package/src/lib/margin-layout.ts +5 -27
  70. package/src/lib/positions.ts +150 -0
  71. package/src/lib/utils.ts +2 -19
  72. package/src/schema.ts +81 -0
  73. package/src/{server/index.ts → server.ts} +74 -74
  74. package/src/{store/index.ts → store.ts} +14 -46
  75. package/vite.config.ts +8 -0
  76. package/src/components/DocumentViewer/IframeContainer.tsx +0 -251
  77. package/src/components/DocumentViewer/InlineCode.tsx +0 -60
  78. package/src/components/DocumentViewer/index.ts +0 -1
  79. package/src/components/FloatingTOC.tsx +0 -61
  80. package/src/components/ShortcutCapture.tsx +0 -48
  81. package/src/components/ShortcutList.tsx +0 -198
  82. package/src/components/comments/CommentMinimap.tsx +0 -62
  83. package/src/components/ui/ActionBar.tsx +0 -16
  84. package/src/components/ui/SeparatorDot.tsx +0 -9
  85. package/src/contexts/LayoutContext.tsx +0 -88
  86. package/src/hooks/useClipboard.ts +0 -82
  87. package/src/hooks/useEditorScheme.ts +0 -51
  88. package/src/hooks/useFontPreference.ts +0 -59
  89. package/src/hooks/useKeybindings.ts +0 -108
  90. package/src/hooks/useKeyboardShortcuts.ts +0 -63
  91. package/src/hooks/useLayoutMode.ts +0 -44
  92. package/src/hooks/useLocalePreference.ts +0 -42
  93. package/src/hooks/useReanchorMode.ts +0 -33
  94. package/src/hooks/useScrollMetrics.ts +0 -56
  95. package/src/hooks/useThemePreference.ts +0 -66
  96. package/src/lib/comment-storage.bench.ts +0 -63
  97. package/src/lib/context.bench.ts +0 -41
  98. package/src/lib/context.test.ts +0 -224
  99. package/src/lib/context.ts +0 -193
  100. package/src/lib/editor-links.ts +0 -59
  101. package/src/lib/export.bench.ts +0 -35
  102. package/src/lib/highlight/colors.ts +0 -37
  103. package/src/lib/highlight/core.ts +0 -54
  104. package/src/lib/highlight/index.ts +0 -23
  105. package/src/lib/highlight/script-builder.ts +0 -485
  106. package/src/lib/html-processor.test.tsx +0 -170
  107. package/src/lib/html-processor.tsx +0 -95
  108. package/src/lib/i18n/completeness.test.ts +0 -51
  109. package/src/lib/i18n/translations.test.ts +0 -39
  110. package/src/lib/layout-constants.ts +0 -12
  111. package/src/lib/margin-layout.bench.ts +0 -28
  112. package/src/lib/scroll.test.ts +0 -118
  113. package/src/lib/scroll.ts +0 -47
  114. package/src/lib/shortcut-registry.test.ts +0 -173
  115. package/src/lib/shortcut-registry.ts +0 -209
  116. package/src/lib/utils.test.ts +0 -110
  117. package/src/store/index.test.ts +0 -242
  118. package/src/types/index.ts +0 -127
@@ -1,193 +0,0 @@
1
- /**
2
- * Context extraction and formatting utilities for LLM clipboard copy.
3
- */
4
-
5
- interface ContextResult {
6
- lines: string[]; // Lines with >>> markers inserted
7
- startLine: number; // 1-based line number
8
- endLine: number; // 1-based line number
9
- }
10
-
11
- interface FormatOptions {
12
- context: ContextResult;
13
- fileName: string;
14
- comment?: string;
15
- }
16
-
17
- /**
18
- * Parameters for context extraction.
19
- * Using object destructuring per style guide §3.5 for clarity.
20
- */
21
- export interface ExtractContextParams {
22
- content: string;
23
- startOffset: number;
24
- endOffset: number;
25
- contextLines?: number;
26
- }
27
-
28
- const DEFAULT_CONTEXT_LINES = 2;
29
- const MAX_SELECTION_LINES = 10;
30
- const MAX_LINE_LENGTH = 200;
31
-
32
- /**
33
- * Strip HTML tags to get plain text matching TreeWalker offset calculation.
34
- */
35
- export function stripHtmlTags(html: string): string {
36
- // Remove script/style content entirely
37
- let text = html.replace(/<(script|style)[^>]*>[\s\S]*?<\/\1>/gi, "");
38
- // Remove all HTML tags
39
- text = text.replace(/<[^>]+>/g, "");
40
- // Decode common named entities
41
- text = text.replace(/&nbsp;/g, " ");
42
- text = text.replace(/&lt;/g, "<");
43
- text = text.replace(/&gt;/g, ">");
44
- text = text.replace(/&amp;/g, "&");
45
- text = text.replace(/&quot;/g, '"');
46
- text = text.replace(/&#39;/g, "'");
47
- // Decode numeric entities (decimal and hex)
48
- text = text.replace(/&#(\d+);/g, (_, code) =>
49
- String.fromCharCode(Number.parseInt(code, 10)),
50
- );
51
- text = text.replace(/&#x([0-9a-f]+);/gi, (_, code) =>
52
- String.fromCharCode(Number.parseInt(code, 16)),
53
- );
54
- return text;
55
- }
56
-
57
- /**
58
- * Detect if content is HTML based on presence of HTML tags.
59
- */
60
- function isHtml(content: string): boolean {
61
- return /<[a-z][\s\S]*>/i.test(content);
62
- }
63
-
64
- /**
65
- * Truncate a line if it exceeds max length.
66
- */
67
- function truncateLine(
68
- line: string,
69
- maxLength: number = MAX_LINE_LENGTH,
70
- ): string {
71
- if (line.length <= maxLength) return line;
72
- return `${line.slice(0, maxLength - 3)}...`;
73
- }
74
-
75
- /**
76
- * Extract context around a selection using character offsets.
77
- * Returns lines with >>> and <<< markers inserted at selection boundaries.
78
- */
79
- export function extractContext({
80
- content,
81
- startOffset,
82
- endOffset,
83
- contextLines = DEFAULT_CONTEXT_LINES,
84
- }: ExtractContextParams): ContextResult {
85
- // For HTML, strip tags to match offset calculation
86
- const textContent = isHtml(content) ? stripHtmlTags(content) : content;
87
- // Normalize CRLF to LF for consistent offset calculation
88
- const normalizedContent = textContent.replace(/\r\n/g, "\n");
89
-
90
- const lines = normalizedContent.split("\n");
91
- let currentOffset = 0;
92
- let startLineIndex = -1;
93
- let endLineIndex = -1;
94
- let startCharInLine = 0;
95
- let endCharInLine = 0;
96
-
97
- // Find lines containing the selection
98
- for (let i = 0; i < lines.length; i++) {
99
- const lineLength = lines[i].length;
100
- const lineEnd = currentOffset + lineLength;
101
-
102
- if (startLineIndex === -1 && lineEnd >= startOffset) {
103
- startLineIndex = i;
104
- startCharInLine = startOffset - currentOffset;
105
- }
106
-
107
- if (lineEnd >= endOffset) {
108
- endLineIndex = i;
109
- endCharInLine = endOffset - currentOffset;
110
- break;
111
- }
112
-
113
- currentOffset += lineLength + 1; // +1 for newline
114
- }
115
-
116
- // Handle edge case: couldn't find lines
117
- if (startLineIndex === -1) startLineIndex = 0;
118
- if (endLineIndex === -1) endLineIndex = lines.length - 1;
119
-
120
- // Calculate context range
121
- const contextStart = Math.max(0, startLineIndex - contextLines);
122
- const contextEnd = Math.min(lines.length - 1, endLineIndex + contextLines);
123
-
124
- // Build output lines with markers
125
- const outputLines: string[] = [];
126
- const selectionSpan = endLineIndex - startLineIndex + 1;
127
- const shouldTruncateMiddle = selectionSpan > MAX_SELECTION_LINES;
128
-
129
- for (let i = contextStart; i <= contextEnd; i++) {
130
- let line = lines[i];
131
-
132
- // Handle truncation for very long selections
133
- if (shouldTruncateMiddle) {
134
- const showStart = startLineIndex + 2;
135
- const showEnd = endLineIndex - 2;
136
-
137
- if (i > showStart && i < showEnd) {
138
- if (i === showStart + 1) {
139
- outputLines.push("...");
140
- }
141
- continue;
142
- }
143
- }
144
-
145
- // Insert markers for selection boundaries
146
- if (i === startLineIndex && i === endLineIndex) {
147
- // Single line selection
148
- const before = line.slice(0, startCharInLine);
149
- const selected = line.slice(startCharInLine, endCharInLine);
150
- const after = line.slice(endCharInLine);
151
- line = `${before}>>> ${selected} <<<${after}`;
152
- } else if (i === startLineIndex) {
153
- // Start of multi-line selection
154
- const before = line.slice(0, startCharInLine);
155
- const selected = line.slice(startCharInLine);
156
- line = `${before}>>> ${selected}`;
157
- } else if (i === endLineIndex) {
158
- // End of multi-line selection
159
- const selected = line.slice(0, endCharInLine);
160
- const after = line.slice(endCharInLine);
161
- line = `${selected} <<<${after}`;
162
- }
163
-
164
- outputLines.push(truncateLine(line));
165
- }
166
-
167
- return {
168
- lines: outputLines,
169
- startLine: startLineIndex + 1, // 1-based
170
- endLine: endLineIndex + 1, // 1-based
171
- };
172
- }
173
-
174
- /**
175
- * Format extracted context for LLM clipboard copy.
176
- */
177
- export function formatForLLM({
178
- context,
179
- fileName,
180
- comment,
181
- }: FormatOptions): string {
182
- const header = `# From: ${fileName}`;
183
- const lineRange = `Lines ${context.startLine}-${context.endLine}:`;
184
- const body = ["---", ...context.lines, "---"].join("\n");
185
-
186
- const parts = [header, "", lineRange, body];
187
-
188
- if (comment) {
189
- parts.push("", `Comment: ${comment}`);
190
- }
191
-
192
- return parts.join("\n");
193
- }
@@ -1,59 +0,0 @@
1
- import { type EditorScheme, EditorSchemes } from "../types";
2
-
3
- // Known source file extensions — kept broad to cover common languages
4
- const EXTENSIONS =
5
- "ts|tsx|js|jsx|mjs|cjs|json|md|mdx|css|scss|html|htm|py|rs|go|rb|java|kt|yml|yaml|toml|sh|bash|zsh|sql|graphql|gql|vue|svelte|astro|c|cpp|h|hpp|cs|swift|zig|lua|ex|exs|erl|hrl|elm|clj|cljs|ml|mli|fs|fsx|r|jl|dart|tf|hcl|proto|xml|svg";
6
-
7
- // Match file paths with known extensions and optional :line[:col] suffix
8
- // Requires at least one `/` to avoid matching bare filenames like "README.md"
9
- const FILE_PATH_RE = new RegExp(
10
- `^(?:\\.\\.\\/|\\.\\/)?((?:[\\w@.-]+\\/)+[\\w.-]+\\.(?:${EXTENSIONS}))(?::(\\d+)(?::(\\d+))?)?$`,
11
- );
12
-
13
- export interface FilePathMatch {
14
- path: string;
15
- line?: number;
16
- col?: number;
17
- }
18
-
19
- export function parseFilePath(text: string): FilePathMatch | undefined {
20
- const match = FILE_PATH_RE.exec(text.trim());
21
- if (!match) return undefined;
22
-
23
- return {
24
- path: match[1],
25
- line: match[2] ? Number.parseInt(match[2], 10) : undefined,
26
- col: match[3] ? Number.parseInt(match[3], 10) : undefined,
27
- };
28
- }
29
-
30
- export function buildEditorUri(
31
- scheme: EditorScheme,
32
- absolutePath: string,
33
- line?: number,
34
- col?: number,
35
- ): string {
36
- if (scheme === EditorSchemes.NONE) return "";
37
-
38
- // vscode://file/path:line:col
39
- let uri = `${scheme}://file/${absolutePath}`;
40
- if (line !== undefined) {
41
- uri += `:${line}`;
42
- if (col !== undefined) {
43
- uri += `:${col}`;
44
- }
45
- }
46
- return uri;
47
- }
48
-
49
- export function resolveAbsolutePath(
50
- relativePath: string,
51
- workingDirectory: string,
52
- ): string {
53
- if (relativePath.startsWith("/")) return relativePath;
54
-
55
- const base = workingDirectory.endsWith("/")
56
- ? workingDirectory
57
- : `${workingDirectory}/`;
58
- return `${base}${relativePath}`;
59
- }
@@ -1,35 +0,0 @@
1
- import { bench, describe } from "vitest";
2
- import {
3
- COMMENTS_1,
4
- COMMENTS_10,
5
- COMMENTS_50,
6
- } from "./__fixtures__/bench-data";
7
- import { generatePrompt, generateRawText } from "./export";
8
-
9
- describe("generatePrompt", () => {
10
- bench("1 comment", () => {
11
- generatePrompt(COMMENTS_1, "test.md");
12
- });
13
-
14
- bench("10 comments", () => {
15
- generatePrompt(COMMENTS_10, "test.md");
16
- });
17
-
18
- bench("50 comments", () => {
19
- generatePrompt(COMMENTS_50, "test.md");
20
- });
21
- });
22
-
23
- describe("generateRawText", () => {
24
- bench("1 comment", () => {
25
- generateRawText(COMMENTS_1);
26
- });
27
-
28
- bench("10 comments", () => {
29
- generateRawText(COMMENTS_10);
30
- });
31
-
32
- bench("50 comments", () => {
33
- generateRawText(COMMENTS_50);
34
- });
35
- });
@@ -1,37 +0,0 @@
1
- /**
2
- * Color palette for comment highlights.
3
- * Colors are assigned by document position (top-to-bottom).
4
- */
5
-
6
- export const COMMENT_COLORS = [
7
- {
8
- name: "amber",
9
- bg: "rgba(245, 222, 160, 0.5)",
10
- bgFocused: "rgba(228, 195, 110, 0.65)",
11
- border: "#c9a84a",
12
- text: "#8b6914",
13
- },
14
- {
15
- name: "blue",
16
- bg: "rgba(168, 196, 228, 0.5)",
17
- bgFocused: "rgba(130, 168, 210, 0.65)",
18
- border: "#5b7fa8",
19
- text: "#3d5f8a",
20
- },
21
- {
22
- name: "green",
23
- bg: "rgba(170, 210, 170, 0.5)",
24
- bgFocused: "rgba(130, 185, 135, 0.65)",
25
- border: "#5a9a62",
26
- text: "#3d6e45",
27
- },
28
- {
29
- name: "rose",
30
- bg: "rgba(225, 180, 185, 0.5)",
31
- bgFocused: "rgba(205, 145, 155, 0.65)",
32
- border: "#b86b78",
33
- text: "#8a4a55",
34
- },
35
- ] as const;
36
-
37
- export type CommentColor = (typeof COMMENT_COLORS)[number];
@@ -1,54 +0,0 @@
1
- import type { TextPosition } from "./types";
2
-
3
- /**
4
- * Find text position in content, handling duplicate occurrences.
5
- * Returns the occurrence closest to hintOffset when multiple exist.
6
- */
7
- export function findTextPosition(
8
- textContent: string,
9
- selectedText: string,
10
- hintOffset?: number,
11
- ): TextPosition | undefined {
12
- if (!selectedText || !textContent) {
13
- return undefined;
14
- }
15
-
16
- const occurrences: number[] = [];
17
- let idx = 0;
18
-
19
- for (;;) {
20
- idx = textContent.indexOf(selectedText, idx);
21
- if (idx === -1) break;
22
- occurrences.push(idx);
23
- idx += 1;
24
- }
25
-
26
- if (occurrences.length === 0) {
27
- return undefined;
28
- }
29
-
30
- if (occurrences.length === 1) {
31
- return {
32
- start: occurrences[0],
33
- end: occurrences[0] + selectedText.length,
34
- };
35
- }
36
-
37
- // Multiple occurrences: find closest to hint offset
38
- const target = hintOffset ?? 0;
39
- let closest = occurrences[0];
40
- let minDist = Math.abs(closest - target);
41
-
42
- for (const occ of occurrences) {
43
- const dist = Math.abs(occ - target);
44
- if (dist < minDist) {
45
- minDist = dist;
46
- closest = occ;
47
- }
48
- }
49
-
50
- return {
51
- start: closest,
52
- end: closest + selectedText.length,
53
- };
54
- }
@@ -1,23 +0,0 @@
1
- // Highlighter (unified adapter)
2
-
3
- export type { CommentColor } from "./colors";
4
- // Colors
5
- export { COMMENT_COLORS } from "./colors";
6
- export type {
7
- Highlighter,
8
- HighlighterOptions,
9
- HoverHandler,
10
- PositionChangeHandler,
11
- SelectionHandler,
12
- } from "./highlighter";
13
- export { createHighlighter } from "./highlighter";
14
-
15
- // Script builder (needed by IframeContainer)
16
- export { buildIframeScript } from "./script-builder";
17
-
18
- // Types (public API)
19
- export type {
20
- HighlightComment,
21
- HighlightPositions,
22
- HighlightStyle,
23
- } from "./types";