@peaske7/readit 0.1.8 → 0.2.1
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.
- package/.claude/CLAUDE.md +118 -76
- package/.claude/commands/review.md +1 -1
- package/.claude/roadmap.md +32 -9
- package/.claude/user-stories.md +100 -15
- package/AGENTS.md +30 -26
- package/Makefile +32 -0
- package/README.md +90 -5
- package/biome.json +18 -8
- package/bun.lock +426 -710
- package/bunfig.toml +2 -0
- package/docs/perf-baseline.md +130 -0
- package/docs/superpowers/plans/2026-03-26-surgical-pruning.md +1176 -0
- package/docs/superpowers/specs/2026-03-27-go-server-rewrite-design.md +284 -0
- package/e2e/comments.spec.ts +14 -58
- package/e2e/document-load.spec.ts +1 -23
- package/e2e/export.spec.ts +4 -4
- package/e2e/perf/add-comment.spec.ts +116 -0
- package/e2e/perf/fixtures/generate.ts +327 -0
- package/e2e/perf/initial-load.spec.ts +49 -0
- package/e2e/perf/perf.setup.ts +23 -0
- package/e2e/perf/perf.teardown.ts +9 -0
- package/e2e/perf/screenshot-final.png +0 -0
- package/e2e/perf/scroll.spec.ts +39 -0
- package/e2e/perf/tab-switch.spec.ts +69 -0
- package/e2e/perf/text-selection.spec.ts +119 -0
- package/e2e/perf/utils/metrics.ts +350 -0
- package/e2e/perf/utils/perf-cli.ts +86 -0
- package/e2e/persistence-file.spec.ts +41 -26
- package/e2e/utils/selection.ts +17 -73
- package/go/cmd/readit/main.go +416 -0
- package/go/go.mod +20 -0
- package/go/go.sum +41 -0
- package/go/internal/server/anchor.go +302 -0
- package/go/internal/server/anchor_test.go +111 -0
- package/go/internal/server/comments.go +390 -0
- package/go/internal/server/documents.go +113 -0
- package/go/internal/server/embed.go +17 -0
- package/go/internal/server/headings.go +33 -0
- package/go/internal/server/headings_test.go +75 -0
- package/go/internal/server/htmltext.go +123 -0
- package/go/internal/server/markdown.go +157 -0
- package/go/internal/server/markdown_bench_test.go +42 -0
- package/go/internal/server/markdown_test.go +79 -0
- package/go/internal/server/server.go +453 -0
- package/go/internal/server/server_bench_test.go +122 -0
- package/go/internal/server/settings.go +110 -0
- package/go/internal/server/sse.go +140 -0
- package/go/internal/server/storage.go +275 -0
- package/go/internal/server/storage_test.go +118 -0
- package/go/internal/server/template.go +66 -0
- package/go/internal/server/types.go +101 -0
- package/go/internal/server/watcher.go +74 -0
- package/index.html +4 -14
- package/nvim-readit/lua/readit/health.lua +64 -0
- package/nvim-readit/lua/readit/init.lua +463 -0
- package/nvim-readit/plugin/readit.lua +19 -0
- package/package.json +24 -41
- package/playwright.config.ts +12 -0
- package/shell/_readit +158 -0
- package/shell/readit.zsh +87 -0
- package/src/App.svelte +881 -0
- package/src/{cli/index.ts → cli.ts} +216 -70
- package/src/components/ActionsMenu.svelte +95 -0
- package/src/components/CommentBadge.svelte +67 -0
- package/src/components/CommentErrorBanner.svelte +33 -0
- package/src/components/CommentInput.svelte +75 -0
- package/src/components/CommentListItem.svelte +95 -0
- package/src/components/CommentManager.svelte +129 -0
- package/src/components/CommentNav.svelte +109 -0
- package/src/components/DocumentViewer.svelte +218 -0
- package/src/components/FloatingComment.svelte +107 -0
- package/src/components/Header.svelte +76 -0
- package/src/components/InlineEditor.svelte +72 -0
- package/src/components/MarginNote.svelte +167 -0
- package/src/components/MarginNotesContainer.svelte +33 -0
- package/src/components/RawModal.svelte +126 -0
- package/src/components/ReanchorConfirm.svelte +30 -0
- package/src/components/SettingsModal.svelte +220 -0
- package/src/components/ShortcutCapture.svelte +82 -0
- package/src/components/ShortcutList.svelte +145 -0
- package/src/components/TabBar.svelte +52 -0
- package/src/components/TableOfContents.svelte +125 -0
- package/src/components/ui/ActionLink.svelte +40 -0
- package/src/components/ui/Button.svelte +53 -0
- package/src/components/ui/Dialog.svelte +97 -0
- package/src/components/ui/DropdownMenu.svelte +85 -0
- package/src/components/ui/DropdownMenuItem.svelte +38 -0
- package/src/components/ui/DropdownMenuSeparator.svelte +11 -0
- package/src/components/ui/Text.svelte +42 -0
- package/src/env.d.ts +6 -0
- package/src/index.css +36 -166
- package/src/lib/__fixtures__/bench-data.ts +1 -54
- package/src/lib/anchor.bench.ts +47 -68
- package/src/lib/anchor.test.ts +5 -9
- package/src/lib/anchor.ts +9 -93
- package/src/lib/comment-storage.bench.ts +6 -20
- package/src/lib/comment-storage.test.ts +45 -37
- package/src/lib/comment-storage.ts +23 -64
- package/src/lib/export.bench.ts +9 -23
- package/src/lib/export.ts +7 -14
- package/src/lib/headings.test.ts +103 -0
- package/src/lib/headings.ts +44 -0
- package/src/lib/highlight/core.test.ts +1 -6
- package/src/lib/highlight/dom.ts +53 -280
- package/src/lib/highlight/highlight-registry.ts +221 -0
- package/src/lib/highlight/highlight.bench.ts +92 -0
- package/src/lib/highlight/highlighter.ts +122 -302
- package/src/lib/highlight/{core.ts → resolver.ts} +3 -19
- package/src/lib/highlight/types.ts +0 -40
- package/src/lib/html-text.test.ts +162 -0
- package/src/lib/html-text.ts +161 -0
- package/src/lib/i18n/en.ts +13 -36
- package/src/lib/i18n/ja.ts +14 -37
- package/src/lib/i18n/types.ts +13 -36
- package/src/lib/margin-layout.bench.ts +48 -15
- package/src/lib/margin-layout.ts +2 -31
- package/src/lib/markdown-renderer.test.ts +154 -0
- package/src/lib/markdown-renderer.ts +177 -0
- package/src/lib/mermaid-config.ts +38 -0
- package/src/lib/mermaid-renderer.ts +162 -0
- package/src/lib/mermaid-worker.ts +60 -0
- package/src/lib/positions.ts +157 -0
- package/src/lib/shortcut-registry.ts +138 -103
- package/src/lib/utils.ts +2 -48
- package/src/main.ts +16 -0
- package/src/schema.ts +92 -0
- package/src/{server/index.ts → server.ts} +427 -163
- package/src/stores/app.svelte.ts +231 -0
- package/src/stores/locale.svelte.ts +46 -0
- package/src/stores/settings.svelte.ts +90 -0
- package/src/stores/shortcuts.svelte.ts +104 -0
- package/src/stores/ui.svelte.ts +12 -0
- package/src/template.ts +104 -0
- package/src/test-setup.ts +47 -0
- package/svelte.config.js +5 -0
- package/tsconfig.json +2 -2
- package/vite.config.ts +31 -3
- package/vscode-readit/.mcp.json +7 -0
- package/vscode-readit/.vscodeignore +7 -0
- package/vscode-readit/bun.lock +78 -0
- package/vscode-readit/icon.svg +10 -0
- package/vscode-readit/package.json +110 -0
- package/vscode-readit/src/extension.ts +117 -0
- package/vscode-readit/src/server-manager.ts +272 -0
- package/vscode-readit/src/webview-provider.ts +204 -0
- package/vscode-readit/tsconfig.json +20 -0
- package/e2e/fixtures/sample.html +0 -13
- package/src/App.tsx +0 -416
- package/src/components/ActionsMenu.tsx +0 -112
- package/src/components/DocumentViewer/CodeBlock.tsx +0 -160
- package/src/components/DocumentViewer/DocumentViewer.tsx +0 -259
- package/src/components/DocumentViewer/IframeContainer.tsx +0 -251
- package/src/components/DocumentViewer/InlineCode.tsx +0 -60
- package/src/components/DocumentViewer/MermaidDiagram.tsx +0 -137
- package/src/components/DocumentViewer/index.ts +0 -1
- package/src/components/FloatingTOC.tsx +0 -61
- package/src/components/Header.tsx +0 -65
- package/src/components/InlineEditor.tsx +0 -74
- package/src/components/MarginNote.tsx +0 -207
- package/src/components/MarginNotes.tsx +0 -50
- package/src/components/RawModal.tsx +0 -143
- package/src/components/ReanchorConfirm.tsx +0 -36
- package/src/components/SettingsModal.tsx +0 -310
- package/src/components/ShortcutCapture.tsx +0 -48
- package/src/components/ShortcutList.tsx +0 -198
- package/src/components/TabBar.tsx +0 -60
- package/src/components/TableOfContents.tsx +0 -108
- package/src/components/comments/CommentBadge.tsx +0 -49
- package/src/components/comments/CommentInput.tsx +0 -114
- package/src/components/comments/CommentListItem.tsx +0 -92
- package/src/components/comments/CommentManager.tsx +0 -113
- package/src/components/comments/CommentMinimap.tsx +0 -62
- package/src/components/comments/CommentNav.tsx +0 -109
- package/src/components/ui/ActionBar.tsx +0 -16
- package/src/components/ui/ActionLink.tsx +0 -32
- package/src/components/ui/Button.tsx +0 -55
- package/src/components/ui/Dialog.tsx +0 -156
- package/src/components/ui/DropdownMenu.tsx +0 -114
- package/src/components/ui/SeparatorDot.tsx +0 -9
- package/src/components/ui/Text.tsx +0 -54
- package/src/contexts/CommentContext.tsx +0 -229
- package/src/contexts/LayoutContext.tsx +0 -88
- package/src/contexts/LocaleContext.tsx +0 -35
- package/src/hooks/useClickOutside.ts +0 -35
- package/src/hooks/useClipboard.ts +0 -82
- package/src/hooks/useCommentNavigation.ts +0 -130
- package/src/hooks/useComments.ts +0 -323
- package/src/hooks/useDocument.ts +0 -156
- package/src/hooks/useEditorScheme.ts +0 -51
- package/src/hooks/useFontPreference.ts +0 -59
- package/src/hooks/useHeadings.test.ts +0 -159
- package/src/hooks/useHeadings.ts +0 -129
- package/src/hooks/useKeybindings.ts +0 -108
- package/src/hooks/useKeyboardShortcuts.ts +0 -63
- package/src/hooks/useLayoutMode.ts +0 -44
- package/src/hooks/useLocalePreference.ts +0 -42
- package/src/hooks/useReanchorMode.ts +0 -33
- package/src/hooks/useScrollMetrics.ts +0 -56
- package/src/hooks/useScrollSpy.ts +0 -81
- package/src/hooks/useTextSelection.ts +0 -123
- package/src/hooks/useThemePreference.ts +0 -66
- package/src/lib/context.bench.ts +0 -41
- package/src/lib/context.test.ts +0 -224
- package/src/lib/context.ts +0 -193
- package/src/lib/editor-links.ts +0 -59
- package/src/lib/highlight/colors.ts +0 -37
- package/src/lib/highlight/index.ts +0 -23
- package/src/lib/highlight/script-builder.ts +0 -485
- package/src/lib/html-processor.test.tsx +0 -170
- package/src/lib/html-processor.tsx +0 -95
- package/src/lib/i18n/completeness.test.ts +0 -51
- package/src/lib/i18n/translations.test.ts +0 -39
- package/src/lib/layout-constants.ts +0 -12
- package/src/lib/scroll.test.ts +0 -118
- package/src/lib/scroll.ts +0 -47
- package/src/lib/shortcut-registry.test.ts +0 -173
- package/src/lib/utils.test.ts +0 -110
- package/src/main.tsx +0 -13
- package/src/store/index.test.ts +0 -242
- package/src/store/index.ts +0 -254
- package/src/types/index.ts +0 -127
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import DOMPurify from "dompurify";
|
|
2
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
-
import {
|
|
4
|
-
buildIframeScript,
|
|
5
|
-
createHighlighter,
|
|
6
|
-
type HighlightComment,
|
|
7
|
-
type Highlighter,
|
|
8
|
-
} from "../../lib/highlight";
|
|
9
|
-
import {
|
|
10
|
-
AnchorConfidences,
|
|
11
|
-
type Comment,
|
|
12
|
-
FontFamilies,
|
|
13
|
-
type FontFamily,
|
|
14
|
-
type SelectionRange,
|
|
15
|
-
} from "../../types";
|
|
16
|
-
|
|
17
|
-
interface IframeContainerProps {
|
|
18
|
-
html: string;
|
|
19
|
-
comments: Comment[];
|
|
20
|
-
pendingSelection?: SelectionRange;
|
|
21
|
-
onTextSelect: (
|
|
22
|
-
text: string,
|
|
23
|
-
startOffset: number,
|
|
24
|
-
endOffset: number,
|
|
25
|
-
selectionTop: number,
|
|
26
|
-
) => void;
|
|
27
|
-
onHighlightPositionsChange?: (
|
|
28
|
-
positions: Record<string, number>,
|
|
29
|
-
documentPositions: Record<string, number>,
|
|
30
|
-
pendingTop?: number,
|
|
31
|
-
) => void;
|
|
32
|
-
onHighlightHover?: (commentId: string | undefined) => void;
|
|
33
|
-
onHighlightClick?: (commentId: string) => void;
|
|
34
|
-
fontFamily?: FontFamily;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const FONT_SERIF =
|
|
38
|
-
'ui-serif, Georgia, Cambria, "Times New Roman", Times, serif';
|
|
39
|
-
const FONT_SANS =
|
|
40
|
-
'ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';
|
|
41
|
-
|
|
42
|
-
function getFontStack(fontFamily: FontFamily): string {
|
|
43
|
-
return fontFamily === FontFamilies.SANS_SERIF ? FONT_SANS : FONT_SERIF;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Layout styles use !important; prose styles use :where() for zero specificity
|
|
47
|
-
function getBaseStyles(fontFamily: FontFamily): string {
|
|
48
|
-
const fontStack = getFontStack(fontFamily);
|
|
49
|
-
return `
|
|
50
|
-
/* Critical layout - must override external CSS to ensure proper sizing */
|
|
51
|
-
html {
|
|
52
|
-
width: 100% !important;
|
|
53
|
-
}
|
|
54
|
-
body {
|
|
55
|
-
width: 100% !important;
|
|
56
|
-
min-width: 65ch;
|
|
57
|
-
box-sizing: border-box !important;
|
|
58
|
-
margin: 0;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/* Prose styles as fallback - zero specificity via :where(), easily overridden */
|
|
62
|
-
:where(body:not([class])) {
|
|
63
|
-
max-width: 65ch;
|
|
64
|
-
margin-left: auto;
|
|
65
|
-
margin-right: auto;
|
|
66
|
-
padding: 2rem 1rem;
|
|
67
|
-
line-height: 1.75;
|
|
68
|
-
color: #3f3f46;
|
|
69
|
-
font-family: ${fontStack};
|
|
70
|
-
}
|
|
71
|
-
:where(body:not([class])) :where(h1, h2, h3, h4, h5, h6) {
|
|
72
|
-
color: #18181b;
|
|
73
|
-
font-weight: 600;
|
|
74
|
-
line-height: 1.25;
|
|
75
|
-
margin-top: 2em;
|
|
76
|
-
margin-bottom: 0.5em;
|
|
77
|
-
}
|
|
78
|
-
:where(body:not([class])) :where(h1) { font-size: 2.25em; margin-top: 0; }
|
|
79
|
-
:where(body:not([class])) :where(h2) { font-size: 1.5em; }
|
|
80
|
-
:where(body:not([class])) :where(h3) { font-size: 1.25em; }
|
|
81
|
-
:where(body:not([class])) :where(h4) { font-size: 1.125em; }
|
|
82
|
-
:where(body:not([class])) :where(p) { margin: 1em 0; }
|
|
83
|
-
:where(body:not([class])) :where(ul, ol) { padding-left: 1.5em; margin: 1em 0; }
|
|
84
|
-
:where(body:not([class])) :where(li) { margin: 0.5em 0; }
|
|
85
|
-
:where(body:not([class])) :where(a) { color: #2563eb; text-decoration: underline; }
|
|
86
|
-
:where(body:not([class])) :where(code) { background: #f4f4f5; padding: 0.2em 0.4em; border-radius: 0.25em; font-size: 0.875em; }
|
|
87
|
-
:where(body:not([class])) :where(pre) { background: #f4f4f5; padding: 1em; border-radius: 0.5em; overflow-x: auto; }
|
|
88
|
-
:where(body:not([class])) :where(pre code) { background: none; padding: 0; }
|
|
89
|
-
:where(body:not([class])) :where(blockquote) { border-left: 4px solid #e4e4e7; padding-left: 1em; color: #71717a; margin: 1em 0; font-style: italic; }
|
|
90
|
-
:where(body:not([class])) :where(hr) { border: none; border-top: 1px solid #e4e4e7; margin: 2em 0; }
|
|
91
|
-
:where(body:not([class])) :where(table) { border-collapse: collapse; width: 100%; margin: 1em 0; }
|
|
92
|
-
:where(body:not([class])) :where(th, td) { border: 1px solid #e4e4e7; padding: 0.5em 1em; text-align: left; }
|
|
93
|
-
:where(body:not([class])) :where(th) { background: #fafafa; font-weight: 600; }
|
|
94
|
-
:where(body:not([class])) :where(img) { max-width: 100%; height: auto; }
|
|
95
|
-
|
|
96
|
-
/* Highlight styles - warm ink palette */
|
|
97
|
-
mark[data-comment-id] {
|
|
98
|
-
background: rgba(245, 222, 160, 0.5);
|
|
99
|
-
cursor: pointer;
|
|
100
|
-
transition: background-color 0.15s ease;
|
|
101
|
-
}
|
|
102
|
-
mark[data-comment-id]:hover {
|
|
103
|
-
background-color: rgba(228, 195, 110, 0.65);
|
|
104
|
-
}
|
|
105
|
-
mark[data-comment-id]:active {
|
|
106
|
-
background-color: rgba(228, 195, 110, 0.75);
|
|
107
|
-
}
|
|
108
|
-
mark[data-pending] { background: rgba(180, 180, 180, 0.3); cursor: text; }
|
|
109
|
-
`;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function sanitizeHtml(html: string): string {
|
|
113
|
-
const sanitized = DOMPurify.sanitize(html, {
|
|
114
|
-
ADD_TAGS: ["style"],
|
|
115
|
-
ADD_ATTR: ["style"],
|
|
116
|
-
FORBID_TAGS: ["script", "iframe", "object", "embed", "form"],
|
|
117
|
-
FORBID_ATTR: ["onerror", "onload", "onclick", "onmouseover"],
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// Escape </iframe> to prevent breaking out of srcdoc
|
|
121
|
-
return sanitized.replace(/<\/iframe/gi, "</iframe");
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function injectStyleTag(html: string, styleTag: string): string {
|
|
125
|
-
if (/<\/head>/i.test(html)) {
|
|
126
|
-
return html.replace(/<\/head>/i, `${styleTag}</head>`);
|
|
127
|
-
}
|
|
128
|
-
if (/<head[^>]*>/i.test(html)) {
|
|
129
|
-
return html.replace(/(<head[^>]*>)/i, `$1${styleTag}`);
|
|
130
|
-
}
|
|
131
|
-
return styleTag + html;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function IframeContainer({
|
|
135
|
-
html,
|
|
136
|
-
comments,
|
|
137
|
-
pendingSelection,
|
|
138
|
-
onTextSelect,
|
|
139
|
-
onHighlightPositionsChange,
|
|
140
|
-
onHighlightHover,
|
|
141
|
-
onHighlightClick,
|
|
142
|
-
fontFamily = FontFamilies.SERIF,
|
|
143
|
-
}: IframeContainerProps) {
|
|
144
|
-
const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
145
|
-
const adapterRef = useRef<Highlighter | null>(null);
|
|
146
|
-
const [contentHeight, setContentHeight] = useState<number>(0);
|
|
147
|
-
|
|
148
|
-
const srcdoc = useMemo(() => {
|
|
149
|
-
const sanitized = sanitizeHtml(html);
|
|
150
|
-
const baseStyles = getBaseStyles(fontFamily);
|
|
151
|
-
const styleTag = `<style id="readit-base-styles">${baseStyles}</style>`;
|
|
152
|
-
|
|
153
|
-
const finalHtml = injectStyleTag(sanitized, styleTag);
|
|
154
|
-
|
|
155
|
-
return finalHtml + buildIframeScript(window.location.origin);
|
|
156
|
-
}, [html, fontFamily]);
|
|
157
|
-
|
|
158
|
-
useEffect(() => {
|
|
159
|
-
const adapter = createHighlighter({
|
|
160
|
-
type: "iframe",
|
|
161
|
-
getIframe: () => iframeRef.current,
|
|
162
|
-
onSelect: onTextSelect,
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
adapterRef.current = adapter;
|
|
166
|
-
|
|
167
|
-
const unsubPositions = onHighlightPositionsChange
|
|
168
|
-
? adapter.onPositionsChange((pos) => {
|
|
169
|
-
const iframe = iframeRef.current;
|
|
170
|
-
const iframeOffset = iframe
|
|
171
|
-
? iframe.getBoundingClientRect().top + window.scrollY
|
|
172
|
-
: 0;
|
|
173
|
-
|
|
174
|
-
const adjustedDocPositions: Record<string, number> = {};
|
|
175
|
-
for (const [id, iframePos] of Object.entries(pos.documentPositions)) {
|
|
176
|
-
adjustedDocPositions[id] = iframePos + iframeOffset;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
onHighlightPositionsChange(
|
|
180
|
-
pos.positions,
|
|
181
|
-
adjustedDocPositions,
|
|
182
|
-
pos.pendingTop,
|
|
183
|
-
);
|
|
184
|
-
})
|
|
185
|
-
: () => {};
|
|
186
|
-
|
|
187
|
-
const unsubHover = onHighlightHover
|
|
188
|
-
? adapter.onHighlightHover(onHighlightHover)
|
|
189
|
-
: () => {};
|
|
190
|
-
|
|
191
|
-
const unsubClick = onHighlightClick
|
|
192
|
-
? adapter.onHighlightClick(onHighlightClick)
|
|
193
|
-
: () => {};
|
|
194
|
-
|
|
195
|
-
const unsubHeight = adapter.onContentHeightChange?.((height) => {
|
|
196
|
-
setContentHeight(height);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
return () => {
|
|
200
|
-
unsubPositions();
|
|
201
|
-
unsubHover();
|
|
202
|
-
unsubClick();
|
|
203
|
-
unsubHeight?.();
|
|
204
|
-
adapter.dispose();
|
|
205
|
-
adapterRef.current = null;
|
|
206
|
-
};
|
|
207
|
-
}, [
|
|
208
|
-
onTextSelect,
|
|
209
|
-
onHighlightPositionsChange,
|
|
210
|
-
onHighlightHover,
|
|
211
|
-
onHighlightClick,
|
|
212
|
-
]);
|
|
213
|
-
|
|
214
|
-
useEffect(() => {
|
|
215
|
-
const adapter = adapterRef.current;
|
|
216
|
-
if (!adapter) return;
|
|
217
|
-
|
|
218
|
-
const highlightComments: HighlightComment[] = comments
|
|
219
|
-
.filter((c) => c.anchorConfidence !== AnchorConfidences.UNRESOLVED)
|
|
220
|
-
.map((c) => ({
|
|
221
|
-
id: c.id,
|
|
222
|
-
selectedText: c.selectedText,
|
|
223
|
-
startOffset: c.startOffset,
|
|
224
|
-
endOffset: c.endOffset,
|
|
225
|
-
}));
|
|
226
|
-
|
|
227
|
-
adapter.applyHighlights(highlightComments, pendingSelection ?? undefined);
|
|
228
|
-
}, [comments, pendingSelection]);
|
|
229
|
-
|
|
230
|
-
useEffect(() => {
|
|
231
|
-
const handleTestSelect = (e: Event) => {
|
|
232
|
-
const { text, startOffset, endOffset } = (e as CustomEvent).detail;
|
|
233
|
-
onTextSelect(text, startOffset, endOffset, 0);
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
window.addEventListener("test:select-text", handleTestSelect);
|
|
237
|
-
return () =>
|
|
238
|
-
window.removeEventListener("test:select-text", handleTestSelect);
|
|
239
|
-
}, [onTextSelect]);
|
|
240
|
-
|
|
241
|
-
return (
|
|
242
|
-
<iframe
|
|
243
|
-
ref={iframeRef}
|
|
244
|
-
srcDoc={srcdoc}
|
|
245
|
-
sandbox="allow-scripts allow-same-origin"
|
|
246
|
-
title="Document content"
|
|
247
|
-
className="w-full border-0"
|
|
248
|
-
style={{ height: contentHeight || "100%" }}
|
|
249
|
-
/>
|
|
250
|
-
);
|
|
251
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { ComponentPropsWithoutRef } from "react";
|
|
2
|
-
import {
|
|
3
|
-
buildEditorUri,
|
|
4
|
-
parseFilePath,
|
|
5
|
-
resolveAbsolutePath,
|
|
6
|
-
} from "../../lib/editor-links";
|
|
7
|
-
import type { EditorScheme } from "../../types";
|
|
8
|
-
import { EditorSchemes } from "../../types";
|
|
9
|
-
import { CodeBlock } from "./CodeBlock";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Creates a combined code component for react-markdown that:
|
|
13
|
-
* - Routes fenced code blocks to CodeBlock (syntax highlighting)
|
|
14
|
-
* - Wraps inline code containing file paths with editor links
|
|
15
|
-
* - Falls back to plain <code> for non-file-path inline code
|
|
16
|
-
*/
|
|
17
|
-
export function createCodeComponent(
|
|
18
|
-
editorScheme: EditorScheme,
|
|
19
|
-
workingDirectory: string | null,
|
|
20
|
-
) {
|
|
21
|
-
return function CodeComponent({
|
|
22
|
-
children,
|
|
23
|
-
className,
|
|
24
|
-
...props
|
|
25
|
-
}: ComponentPropsWithoutRef<"code">) {
|
|
26
|
-
// Fenced code blocks have className (e.g., "language-ts") or contain newlines
|
|
27
|
-
if (className || String(children).includes("\n")) {
|
|
28
|
-
return <CodeBlock className={className}>{children}</CodeBlock>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Inline code — check for file path patterns
|
|
32
|
-
if (editorScheme === EditorSchemes.NONE || !workingDirectory) {
|
|
33
|
-
return <code {...props}>{children}</code>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const text = typeof children === "string" ? children : "";
|
|
37
|
-
if (!text) {
|
|
38
|
-
return <code {...props}>{children}</code>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const match = parseFilePath(text);
|
|
42
|
-
if (!match) {
|
|
43
|
-
return <code {...props}>{children}</code>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const absolutePath = resolveAbsolutePath(match.path, workingDirectory);
|
|
47
|
-
const uri = buildEditorUri(
|
|
48
|
-
editorScheme,
|
|
49
|
-
absolutePath,
|
|
50
|
-
match.line,
|
|
51
|
-
match.col,
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<a href={uri} title={`Open in ${editorScheme}`} className="editor-link">
|
|
56
|
-
<code {...props}>{children}</code>
|
|
57
|
-
</a>
|
|
58
|
-
);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import DOMPurify from "dompurify";
|
|
2
|
-
import { useEffect, useId, useState } from "react";
|
|
3
|
-
|
|
4
|
-
interface MermaidDiagramProps {
|
|
5
|
-
code: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function MermaidDiagram({ code }: MermaidDiagramProps) {
|
|
9
|
-
const id = useId().replace(/:/g, "-"); // Mermaid IDs can't have colons
|
|
10
|
-
const [svg, setSvg] = useState<string | null>(null);
|
|
11
|
-
const [error, setError] = useState<string | null>(null);
|
|
12
|
-
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
let cancelled = false;
|
|
15
|
-
|
|
16
|
-
async function renderDiagram() {
|
|
17
|
-
try {
|
|
18
|
-
// Lazy load mermaid
|
|
19
|
-
const mermaid = (await import("mermaid")).default;
|
|
20
|
-
|
|
21
|
-
mermaid.initialize({
|
|
22
|
-
startOnLoad: false,
|
|
23
|
-
theme: "base",
|
|
24
|
-
securityLevel: "strict",
|
|
25
|
-
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
26
|
-
themeVariables: {
|
|
27
|
-
// Typography
|
|
28
|
-
fontSize: "16px",
|
|
29
|
-
|
|
30
|
-
// Primary colors - warm amber (matches app's comment colors)
|
|
31
|
-
primaryColor: "rgba(245, 222, 160, 0.8)",
|
|
32
|
-
primaryTextColor: "#3f3f46",
|
|
33
|
-
primaryBorderColor: "#c9a84a",
|
|
34
|
-
|
|
35
|
-
// Secondary colors - slate blue
|
|
36
|
-
secondaryColor: "rgba(168, 196, 228, 0.6)",
|
|
37
|
-
secondaryTextColor: "#3f3f46",
|
|
38
|
-
secondaryBorderColor: "#5b7fa8",
|
|
39
|
-
|
|
40
|
-
// Tertiary colors - sage green
|
|
41
|
-
tertiaryColor: "rgba(170, 210, 170, 0.6)",
|
|
42
|
-
tertiaryTextColor: "#3f3f46",
|
|
43
|
-
tertiaryBorderColor: "#5a9a62",
|
|
44
|
-
|
|
45
|
-
// Background and text
|
|
46
|
-
background: "#ffffff",
|
|
47
|
-
mainBkg: "#ffffff",
|
|
48
|
-
textColor: "#3f3f46",
|
|
49
|
-
lineColor: "#a1a1aa",
|
|
50
|
-
|
|
51
|
-
// Gantt-specific
|
|
52
|
-
taskBkgColor: "rgba(245, 222, 160, 0.7)",
|
|
53
|
-
taskTextColor: "#3f3f46",
|
|
54
|
-
taskTextDarkColor: "#3f3f46",
|
|
55
|
-
taskTextOutsideColor: "#3f3f46",
|
|
56
|
-
activeTaskBkgColor: "rgba(228, 195, 110, 0.8)",
|
|
57
|
-
activeTaskBorderColor: "#c9a84a",
|
|
58
|
-
doneTaskBkgColor: "rgba(170, 210, 170, 0.6)",
|
|
59
|
-
doneTaskBorderColor: "#5a9a62",
|
|
60
|
-
critTaskBkgColor: "rgba(225, 180, 185, 0.7)",
|
|
61
|
-
critBorderColor: "#b86b78",
|
|
62
|
-
gridColor: "#e4e4e7",
|
|
63
|
-
todayLineColor: "#b86b78",
|
|
64
|
-
sectionBkgColor: "rgba(250, 250, 250, 0.5)",
|
|
65
|
-
altSectionBkgColor: "rgba(244, 244, 245, 0.5)",
|
|
66
|
-
sectionBkgColor2: "rgba(250, 250, 250, 0.5)",
|
|
67
|
-
|
|
68
|
-
// Flowchart/general diagram
|
|
69
|
-
nodeBkg: "rgba(245, 222, 160, 0.6)",
|
|
70
|
-
nodeBorder: "#c9a84a",
|
|
71
|
-
clusterBkg: "rgba(250, 250, 250, 0.8)",
|
|
72
|
-
clusterBorder: "#e4e4e7",
|
|
73
|
-
|
|
74
|
-
// Sequence diagram
|
|
75
|
-
actorBkg: "rgba(168, 196, 228, 0.5)",
|
|
76
|
-
actorBorder: "#5b7fa8",
|
|
77
|
-
actorTextColor: "#3f3f46",
|
|
78
|
-
signalColor: "#3f3f46",
|
|
79
|
-
signalTextColor: "#3f3f46",
|
|
80
|
-
noteBkgColor: "rgba(245, 222, 160, 0.5)",
|
|
81
|
-
noteBorderColor: "#c9a84a",
|
|
82
|
-
noteTextColor: "#3f3f46",
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const { svg: rawSvg } = await mermaid.render(`mermaid-${id}`, code);
|
|
87
|
-
// Sanitize SVG output with DOMPurify before storing in state
|
|
88
|
-
const sanitizedSvg = DOMPurify.sanitize(rawSvg, {
|
|
89
|
-
USE_PROFILES: { svg: true },
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
if (!cancelled) {
|
|
93
|
-
setSvg(sanitizedSvg);
|
|
94
|
-
setError(null);
|
|
95
|
-
}
|
|
96
|
-
} catch (err) {
|
|
97
|
-
if (!cancelled) {
|
|
98
|
-
setError(
|
|
99
|
-
err instanceof Error ? err.message : "Failed to render diagram",
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
renderDiagram();
|
|
106
|
-
return () => {
|
|
107
|
-
cancelled = true;
|
|
108
|
-
};
|
|
109
|
-
}, [code, id]);
|
|
110
|
-
|
|
111
|
-
if (error) {
|
|
112
|
-
return (
|
|
113
|
-
<div className="my-6">
|
|
114
|
-
<div className="text-red-500 text-sm mb-2">Mermaid Error: {error}</div>
|
|
115
|
-
<pre className="bg-zinc-900 p-4 rounded-lg overflow-x-auto text-sm">
|
|
116
|
-
<code>{code}</code>
|
|
117
|
-
</pre>
|
|
118
|
-
</div>
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (!svg) {
|
|
123
|
-
return (
|
|
124
|
-
<div className="my-6 bg-zinc-900 p-4 rounded-lg text-zinc-400">
|
|
125
|
-
Loading diagram...
|
|
126
|
-
</div>
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return (
|
|
131
|
-
<div
|
|
132
|
-
className="mermaid-container my-6 flex justify-center overflow-x-auto"
|
|
133
|
-
// biome-ignore lint/security/noDangerouslySetInnerHtml: svg is sanitized by DOMPurify
|
|
134
|
-
dangerouslySetInnerHTML={{ __html: svg }}
|
|
135
|
-
/>
|
|
136
|
-
);
|
|
137
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { DocumentViewer } from "./DocumentViewer";
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { List } from "lucide-react";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import { useLocale } from "../contexts/LocaleContext";
|
|
4
|
-
import type { Heading } from "../hooks/useHeadings";
|
|
5
|
-
import { cn } from "../lib/utils";
|
|
6
|
-
import { TableOfContents } from "./TableOfContents";
|
|
7
|
-
|
|
8
|
-
interface FloatingTOCProps {
|
|
9
|
-
headings: Heading[];
|
|
10
|
-
activeId: string | null;
|
|
11
|
-
onHeadingClick: (id: string) => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function FloatingTOC({
|
|
15
|
-
headings,
|
|
16
|
-
activeId,
|
|
17
|
-
onHeadingClick,
|
|
18
|
-
}: FloatingTOCProps) {
|
|
19
|
-
const { t } = useLocale();
|
|
20
|
-
const [isExpanded, setIsExpanded] = useState(false);
|
|
21
|
-
|
|
22
|
-
if (headings.length === 0) return null;
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<nav
|
|
26
|
-
className="fixed left-4 top-16 z-40"
|
|
27
|
-
onMouseEnter={() => setIsExpanded(true)}
|
|
28
|
-
onMouseLeave={() => setIsExpanded(false)}
|
|
29
|
-
aria-label={t("floatingTOC.label")}
|
|
30
|
-
>
|
|
31
|
-
{/* Collapsed state: circular button */}
|
|
32
|
-
<button
|
|
33
|
-
type="button"
|
|
34
|
-
onClick={() => setIsExpanded(!isExpanded)}
|
|
35
|
-
className={cn(
|
|
36
|
-
"w-10 h-10 rounded-full bg-white dark:bg-zinc-900 shadow-lg border border-zinc-100 dark:border-zinc-800 flex items-center justify-center text-zinc-400 dark:text-zinc-500 hover:text-zinc-600 dark:hover:text-zinc-300 transition-colors duration-150",
|
|
37
|
-
isExpanded && "opacity-0 pointer-events-none",
|
|
38
|
-
)}
|
|
39
|
-
aria-label={t("floatingTOC.label")}
|
|
40
|
-
>
|
|
41
|
-
<List className="w-5 h-5" />
|
|
42
|
-
</button>
|
|
43
|
-
|
|
44
|
-
{/* Expanded state: panel */}
|
|
45
|
-
{isExpanded && (
|
|
46
|
-
<div className="absolute left-0 top-0 w-56 bg-white/95 dark:bg-zinc-900/95 backdrop-blur-sm rounded-lg shadow-lg border border-zinc-200/40 dark:border-zinc-700/40 p-4 floating-toc-panel">
|
|
47
|
-
<div className="max-h-[calc(100vh-8rem)] overflow-y-auto">
|
|
48
|
-
<TableOfContents
|
|
49
|
-
headings={headings}
|
|
50
|
-
activeId={activeId}
|
|
51
|
-
onHeadingClick={(id) => {
|
|
52
|
-
onHeadingClick(id);
|
|
53
|
-
setIsExpanded(false);
|
|
54
|
-
}}
|
|
55
|
-
/>
|
|
56
|
-
</div>
|
|
57
|
-
</div>
|
|
58
|
-
)}
|
|
59
|
-
</nav>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { useCommentContext } from "../contexts/CommentContext";
|
|
2
|
-
import { useLayoutContext } from "../contexts/LayoutContext";
|
|
3
|
-
import { useLocale } from "../contexts/LocaleContext";
|
|
4
|
-
import { cn } from "../lib/utils";
|
|
5
|
-
import { ActionsMenu } from "./ActionsMenu";
|
|
6
|
-
import { CommentBadge } from "./comments/CommentBadge";
|
|
7
|
-
import { Text } from "./ui/Text";
|
|
8
|
-
|
|
9
|
-
interface HeaderProps {
|
|
10
|
-
fileName: string;
|
|
11
|
-
onCopyAll: () => void;
|
|
12
|
-
onCopyAllRaw: () => void;
|
|
13
|
-
onExportJson: () => void;
|
|
14
|
-
onReload: () => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function Header({
|
|
18
|
-
fileName,
|
|
19
|
-
onCopyAll,
|
|
20
|
-
onCopyAllRaw,
|
|
21
|
-
onExportJson,
|
|
22
|
-
onReload,
|
|
23
|
-
}: HeaderProps) {
|
|
24
|
-
const { reanchorTarget } = useCommentContext();
|
|
25
|
-
const { isFullscreen } = useLayoutContext();
|
|
26
|
-
const { t } = useLocale();
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<header className="sticky top-0 z-50 bg-white/95 dark:bg-zinc-900/95 backdrop-blur-sm border-b border-zinc-100 dark:border-zinc-800">
|
|
30
|
-
<div
|
|
31
|
-
className={cn(
|
|
32
|
-
"px-6 py-3 flex items-center justify-between",
|
|
33
|
-
!isFullscreen && "max-w-7xl mx-auto",
|
|
34
|
-
)}
|
|
35
|
-
>
|
|
36
|
-
<div className="flex items-center gap-3">
|
|
37
|
-
<Text variant="title" asChild>
|
|
38
|
-
<h1>readit</h1>
|
|
39
|
-
</Text>
|
|
40
|
-
<span className="text-zinc-200 dark:text-zinc-700 font-light">—</span>
|
|
41
|
-
<Text variant="caption" asChild>
|
|
42
|
-
<span className="truncate max-w-[200px]">{fileName}</span>
|
|
43
|
-
</Text>
|
|
44
|
-
</div>
|
|
45
|
-
|
|
46
|
-
<div className="flex items-center gap-3">
|
|
47
|
-
{reanchorTarget && (
|
|
48
|
-
<Text variant="caption" asChild>
|
|
49
|
-
<span className="italic">{t("header.selectTextToReanchor")}</span>
|
|
50
|
-
</Text>
|
|
51
|
-
)}
|
|
52
|
-
|
|
53
|
-
<CommentBadge />
|
|
54
|
-
|
|
55
|
-
<ActionsMenu
|
|
56
|
-
onCopyAll={onCopyAll}
|
|
57
|
-
onCopyAllRaw={onCopyAllRaw}
|
|
58
|
-
onExportJson={onExportJson}
|
|
59
|
-
onReload={onReload}
|
|
60
|
-
/>
|
|
61
|
-
</div>
|
|
62
|
-
</div>
|
|
63
|
-
</header>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { use, useEffect, useRef, useState } from "react";
|
|
2
|
-
import { LayoutContext } from "../contexts/LayoutContext";
|
|
3
|
-
import { useLocale } from "../contexts/LocaleContext";
|
|
4
|
-
import { cn } from "../lib/utils";
|
|
5
|
-
import { FontFamilies } from "../types";
|
|
6
|
-
import { Button } from "./ui/Button";
|
|
7
|
-
|
|
8
|
-
interface InlineEditorProps {
|
|
9
|
-
initialText: string;
|
|
10
|
-
onSave: (text: string) => void;
|
|
11
|
-
onCancel: () => void;
|
|
12
|
-
rows?: number;
|
|
13
|
-
className?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function InlineEditor({
|
|
17
|
-
initialText,
|
|
18
|
-
onSave,
|
|
19
|
-
onCancel,
|
|
20
|
-
rows = 2,
|
|
21
|
-
className,
|
|
22
|
-
}: InlineEditorProps) {
|
|
23
|
-
const layout = use(LayoutContext);
|
|
24
|
-
const { t } = useLocale();
|
|
25
|
-
const fontClass = layout
|
|
26
|
-
? layout.fontFamily === FontFamilies.SANS_SERIF
|
|
27
|
-
? "font-sans"
|
|
28
|
-
: "font-serif"
|
|
29
|
-
: undefined;
|
|
30
|
-
const [editText, setEditText] = useState(initialText);
|
|
31
|
-
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
textareaRef.current?.focus();
|
|
35
|
-
}, []);
|
|
36
|
-
|
|
37
|
-
const handleSave = () => {
|
|
38
|
-
if (editText.trim()) {
|
|
39
|
-
onSave(editText);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<div className="space-y-2">
|
|
45
|
-
<textarea
|
|
46
|
-
ref={textareaRef}
|
|
47
|
-
value={editText}
|
|
48
|
-
onChange={(e) => setEditText(e.target.value)}
|
|
49
|
-
className={cn(
|
|
50
|
-
fontClass,
|
|
51
|
-
"w-full px-2 py-1.5 text-sm border border-zinc-200 dark:border-zinc-700 dark:bg-zinc-800 resize-none focus:outline-none focus:border-zinc-400 dark:focus:border-zinc-500",
|
|
52
|
-
className,
|
|
53
|
-
)}
|
|
54
|
-
rows={rows}
|
|
55
|
-
onKeyDown={(e) => {
|
|
56
|
-
if (e.key === "Enter" && e.metaKey) {
|
|
57
|
-
handleSave();
|
|
58
|
-
}
|
|
59
|
-
if (e.key === "Escape") {
|
|
60
|
-
onCancel();
|
|
61
|
-
}
|
|
62
|
-
}}
|
|
63
|
-
/>
|
|
64
|
-
<div className="flex gap-3 text-sm">
|
|
65
|
-
<Button variant="link" size="sm" onClick={handleSave}>
|
|
66
|
-
{t("editor.save")}
|
|
67
|
-
</Button>
|
|
68
|
-
<Button variant="ghost" size="sm" onClick={onCancel}>
|
|
69
|
-
{t("editor.cancel")}
|
|
70
|
-
</Button>
|
|
71
|
-
</div>
|
|
72
|
-
</div>
|
|
73
|
-
);
|
|
74
|
-
}
|