@mrsf/markdown-it-mrsf 0.3.0 → 0.4.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.
- package/README.md +1 -0
- package/dist/browser.js +24 -248
- package/dist/browser.js.map +3 -3
- package/dist/controller.d.ts +113 -10
- package/dist/controller.js +813 -276
- package/dist/controller.js.map +3 -3
- package/dist/html.d.ts +13 -0
- package/dist/index.js +24 -248
- package/dist/index.js.map +3 -3
- package/dist/rules/core.d.ts +12 -11
- package/dist/rules/renderer.d.ts +4 -4
- package/dist/style.css +157 -118
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts", "../../shared/src/comments.ts", "
|
|
4
|
-
"sourcesContent": ["/**\n * @mrsf/markdown-it-mrsf \u2014 markdown-it plugin for MRSF review comments.\n *\n * This is the full-featured Node.js entry point. It supports all four\n * sidecar provisioning modes: `comments`, `loader`, `sidecarPath`, and\n * `documentPath`. The latter two require Node.js file-system APIs.\n *\n * In browser / bundler environments, the `\"browser\"` export condition in\n * package.json automatically resolves to the browser-safe entry, so you\n * never need to import a different path \u2014 just use:\n *\n * @example\n * ```ts\n * import MarkdownIt from \"markdown-it\";\n * import { mrsfPlugin } from \"@mrsf/markdown-it-mrsf\";\n *\n * const md = new MarkdownIt();\n * md.use(mrsfPlugin, { documentPath: \"docs/guide.md\" });\n * const html = md.render(markdownSource);\n * ```\n */\n\nimport { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { parseSidecarContent } from \"@mrsf/cli\";\nimport type { MrsfPluginOptions } from \"./types.js\";\nimport { createMrsfPlugin } from \"./shared.js\";\n\n// Re-export types for consumers\nexport type { MrsfPluginOptions, SlimComment, CommentThread, LineMap, CommentLoader } from \"./types.js\";\n\n/**\n * The markdown-it plugin function (Node.js \u2014 full feature set).\n */\nexport const mrsfPlugin = createMrsfPlugin((options: MrsfPluginOptions) => {\n // Priority 1: inline data\n if (options.comments) {\n return options.comments;\n }\n\n // Priority 2: custom loader function\n if (options.loader) {\n try {\n return options.loader();\n } catch {\n return null;\n }\n }\n\n // Priority 3: explicit sidecar path\n if (options.sidecarPath) {\n try {\n const abs = path.resolve(options.cwd || process.cwd(), options.sidecarPath);\n const content = readFileSync(abs, \"utf-8\");\n return parseSidecarContent(content, abs);\n } catch {\n return null;\n }\n }\n\n // Priority 4: auto-discover from documentPath\n if (options.documentPath) {\n try {\n const cwd = options.cwd || process.cwd();\n const abs = path.resolve(cwd, options.documentPath);\n const yamlPath = abs + \".review.yaml\";\n const jsonPath = abs + \".review.json\";\n\n let raw: string | null = null;\n let hint: string | null = null;\n try {\n raw = readFileSync(yamlPath, \"utf-8\");\n hint = yamlPath;\n } catch {\n try {\n raw = readFileSync(jsonPath, \"utf-8\");\n hint = jsonPath;\n } catch {\n return null;\n }\n }\n\n if (!raw) return null;\n return parseSidecarContent(raw, hint!);\n } catch {\n return null;\n }\n }\n\n return null;\n});\n\nexport default mrsfPlugin;\n", "/**\n * Shared comment loading and grouping logic for MRSF rendering plugins.\n */\n\nimport type { MrsfDocument } from \"@mrsf/cli\";\nimport type { MrsfPluginOptions, SlimComment, CommentThread, LineMap, CommentLoader } from \"./types.js\";\n\nexport type { CommentLoader };\n\n/**\n * Convert an MrsfDocument into a slim comment array.\n */\nexport function toSlimComments(doc: MrsfDocument): SlimComment[] {\n return doc.comments.map((c) => ({\n id: c.id,\n author: c.author || \"Unknown\",\n text: c.text || \"\",\n line: c.line ?? null,\n end_line: c.end_line ?? null,\n start_column: c.start_column ?? null,\n end_column: c.end_column ?? null,\n selected_text: c.selected_text || null,\n resolved: !!c.resolved,\n reply_to: c.reply_to || null,\n severity: c.severity || null,\n type: c.type || null,\n timestamp: c.timestamp || null,\n }));\n}\n\n/**\n * Group comments by line number, threading replies under parents.\n */\nexport function groupByLine(comments: SlimComment[]): LineMap {\n const rootComments = comments.filter((c) => !c.reply_to && c.line != null);\n const replies = comments.filter((c) => c.reply_to);\n\n const replyMap = new Map<string, SlimComment[]>();\n for (const r of replies) {\n const list = replyMap.get(r.reply_to!) || [];\n list.push(r);\n replyMap.set(r.reply_to!, list);\n }\n\n const lineMap: LineMap = new Map();\n for (const c of rootComments) {\n const line = c.line!;\n const threads = lineMap.get(line) || [];\n threads.push({\n comment: c,\n replies: replyMap.get(c.id) || [],\n });\n lineMap.set(line, threads);\n }\n\n return lineMap;\n}\n\n/**\n * Resolve options into a filtered LineMap ready for rendering.\n * Returns null if there are no comments to render.\n */\nexport function resolveComments(\n loader: CommentLoader,\n options: MrsfPluginOptions,\n): { lineMap: LineMap; comments: SlimComment[] } | null {\n const showResolved = options.showResolved ?? true;\n\n const doc = loader(options);\n if (!doc || !doc.comments || doc.comments.length === 0) {\n return null;\n }\n\n let comments = toSlimComments(doc);\n if (!showResolved) {\n comments = comments.filter((c) => !c.resolved);\n }\n\n if (comments.length === 0) return null;\n\n const lineMap = groupByLine(comments);\n return { lineMap, comments };\n}\n", "/**\n * Shared HTML rendering helpers for MRSF rendering plugins.\n *\n * These produce the HTML strings used in tooltips, badges, and comment\n * rendering. Both the markdown-it and rehype plugins use these functions\n * to ensure identical visual output.\n */\n\nimport type { CommentThread, SlimComment } from \"./types.js\";\n\nexport function escapeHtml(str: string): string {\n return str\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\");\n}\n\nexport function formatTime(iso: string | null): string {\n if (!iso) return \"\";\n try {\n const d = new Date(iso);\n return d.toLocaleDateString(undefined, {\n year: \"numeric\",\n month: \"short\",\n day: \"numeric\",\n });\n } catch {\n return \"\";\n }\n}\n\nexport function renderCommentHtml(\n comment: SlimComment,\n isReply: boolean,\n interactive: boolean,\n): string {\n const resolvedClass = comment.resolved ? \" mrsf-resolved\" : \"\";\n const replyClass = isReply ? \" mrsf-reply\" : \"\";\n let html = `<span class=\"mrsf-comment${resolvedClass}${replyClass}\" data-mrsf-comment-id=\"${escapeHtml(comment.id)}\">`;\n\n // Header\n html += `<span class=\"mrsf-comment-header\">`;\n html += `<span class=\"mrsf-author\">${escapeHtml(comment.author)}</span>`;\n if (comment.timestamp) {\n html += `<span class=\"mrsf-date\">${escapeHtml(formatTime(comment.timestamp))}</span>`;\n }\n if (comment.severity) {\n html += `<span class=\"mrsf-severity mrsf-severity-${escapeHtml(comment.severity)}\">${escapeHtml(comment.severity)}</span>`;\n }\n if (comment.type) {\n html += `<span class=\"mrsf-type\">${escapeHtml(comment.type)}</span>`;\n }\n if (comment.resolved) {\n html += `<span class=\"mrsf-resolved-badge\">\u2713 resolved</span>`;\n }\n html += `</span>`;\n\n // Selected text quote\n if (comment.selected_text) {\n html += `<span class=\"mrsf-selected-text\">${escapeHtml(comment.selected_text)}</span>`;\n }\n\n // Body\n html += `<span class=\"mrsf-comment-body\">${escapeHtml(comment.text)}</span>`;\n\n // Action buttons (interactive mode)\n if (interactive) {\n const line = comment.line != null ? String(comment.line) : \"\";\n html += `<span class=\"mrsf-actions\">`;\n if (comment.resolved) {\n html += `<button class=\"mrsf-action-btn\" data-mrsf-action=\"unresolve\" data-mrsf-comment-id=\"${escapeHtml(comment.id)}\" data-mrsf-line=\"${line}\">Unresolve</button>`;\n } else {\n html += `<button class=\"mrsf-action-btn\" data-mrsf-action=\"resolve\" data-mrsf-comment-id=\"${escapeHtml(comment.id)}\" data-mrsf-line=\"${line}\">Resolve</button>`;\n }\n html += `<button class=\"mrsf-action-btn\" data-mrsf-action=\"reply\" data-mrsf-comment-id=\"${escapeHtml(comment.id)}\" data-mrsf-line=\"${line}\">Reply</button>`;\n html += `<button class=\"mrsf-action-btn\" data-mrsf-action=\"edit\" data-mrsf-comment-id=\"${escapeHtml(comment.id)}\" data-mrsf-line=\"${line}\">Edit</button>`;\n html += `<button class=\"mrsf-action-btn mrsf-action-danger\" data-mrsf-action=\"delete\" data-mrsf-comment-id=\"${escapeHtml(comment.id)}\" data-mrsf-line=\"${line}\">Delete</button>`;\n html += `</span>`;\n }\n\n html += `</span>`;\n return html;\n}\n\nexport function renderThreadHtml(thread: CommentThread, interactive: boolean): string {\n let html = `<span class=\"mrsf-thread\">`;\n html += renderCommentHtml(thread.comment, false, interactive);\n if (thread.replies.length > 0) {\n html += `<span class=\"mrsf-replies\">`;\n for (const reply of thread.replies) {\n html += renderCommentHtml(reply, true, interactive);\n }\n html += `</span>`;\n }\n html += `</span>`;\n return html;\n}\n", "/**\n * MRSF markdown-it plugin \u2014 core rule.\n *\n * Walks the parsed token stream and injects `mrsf_badge` tokens\n * at lines that have comments, and wraps `selected_text` matches\n * with `mrsf_highlight_open`/`close` tokens (with tooltip metadata).\n */\n\nimport type Token from \"markdown-it/lib/token.mjs\";\nimport type { Nesting } from \"markdown-it/lib/token.mjs\";\nimport type StateCore from \"markdown-it/lib/rules_core/state_core.mjs\";\nimport type { LineMap, CommentThread } from \"../types.js\";\n\n/** Options forwarded from the plugin to the core rule. */\nexport interface CoreOptions {\n interactive: boolean;\n gutterPosition: \"left\" | \"tight\" | \"right\";\n gutterForInline: boolean;\n inlineHighlights: boolean;\n}\n\n/**\n * Find the token index for a given 1-based source line.\n * markdown-it tokens use `token.map = [startLine, endLine]` (0-based).\n */\nfunction findTokenIndexForLine(\n tokens: Token[],\n line: number,\n): number {\n const line0 = line - 1; // convert to 0-based\n for (let i = 0; i < tokens.length; i++) {\n const map = tokens[i].map;\n if (map && map[0] <= line0 && line0 < map[1]) {\n return i;\n }\n }\n return -1;\n}\n\n/**\n * Wrap occurrences of `text` inside inline token children with\n * highlight open/close tokens. Stores thread data on the tokens\n * so the renderer can produce an inline tooltip.\n */\nfunction highlightInlineText(\n token: Token,\n thread: CommentThread,\n interactive: boolean,\n Token: new (type: string, tag: string, nesting: Nesting) => Token,\n): boolean {\n if (!token.children) return false;\n\n const text = thread.comment.selected_text;\n if (!text) return false;\n const trimmed = text.trim();\n if (!trimmed) return false;\n\n for (let i = 0; i < token.children.length; i++) {\n const child = token.children[i];\n if (child.type !== \"text\") continue;\n\n const idx = child.content.indexOf(trimmed);\n if (idx === -1) continue;\n\n // Split the text token into: before + highlight_open + matched + highlight_close + after\n const newTokens: Token[] = [];\n\n // Text before match\n if (idx > 0) {\n const before = new Token(\"text\", \"\", 0);\n before.content = child.content.slice(0, idx);\n newTokens.push(before);\n }\n\n // Highlight open \u2014 carries thread metadata for inline tooltip\n const open = new Token(\"mrsf_highlight_open\", \"mark\", 1);\n open.attrSet(\"class\", \"mrsf-highlight\");\n open.attrSet(\"data-mrsf-comment-id\", thread.comment.id);\n open.meta = { thread };\n newTokens.push(open);\n\n // Matched text\n const matched = new Token(\"text\", \"\", 0);\n matched.content = trimmed;\n newTokens.push(matched);\n\n // Highlight close \u2014 carries thread metadata for inline tooltip\n const close = new Token(\"mrsf_highlight_close\", \"mark\", -1);\n close.meta = { thread, interactive };\n newTokens.push(close);\n\n // Text after match\n if (idx + trimmed.length < child.content.length) {\n const after = new Token(\"text\", \"\", 0);\n after.content = child.content.slice(idx + trimmed.length);\n newTokens.push(after);\n }\n\n // Replace the original child with our new tokens\n token.children.splice(i, 1, ...newTokens);\n return true;\n }\n\n return false;\n}\n\n/**\n * Install the MRSF core rule on a markdown-it instance.\n */\nexport function installCoreRule(\n md: { core: { ruler: { push: (name: string, fn: (state: StateCore) => void) => void } } },\n lineMap: LineMap,\n options: CoreOptions,\n): void {\n const { interactive, gutterPosition, gutterForInline, inlineHighlights } = options;\n\n md.core.ruler.push(\"mrsf_inject\", (state: StateCore) => {\n const tokens = state.tokens;\n const TokenCtor = state.Token;\n\n // Track which lines we've already processed (to avoid double-injection\n // when multiple tokens share the same source line).\n const processed = new Set<number>();\n\n // We iterate backwards so that inserting tokens doesn't shift indices\n // for tokens we haven't visited yet.\n for (let i = tokens.length - 1; i >= 0; i--) {\n const token = tokens[i];\n const map = token.map;\n if (!map) continue;\n\n // Skip inline tokens \u2014 they share the same map as their parent block.\n // We must process the parent block (paragraph_open, heading_open, etc.)\n // so the badge and class land on the correct rendered element.\n if (token.type === \"inline\") continue;\n\n // Always expose source line metadata for selection-based adds\n const startLine1 = map[0] + 1;\n const endLine1 = map[1];\n token.attrSet(\"data-mrsf-line\", String(startLine1));\n token.attrSet(\"data-mrsf-start-line\", String(startLine1));\n token.attrSet(\"data-mrsf-end-line\", String(endLine1));\n\n // Mark line elements as hover targets (for gutter add visibility)\n if (interactive) {\n const existingClass = token.attrGet(\"class\") || \"\";\n token.attrSet(\n \"class\",\n existingClass\n ? `${existingClass} mrsf-line-hover-target`\n : \"mrsf-line-hover-target\",\n );\n }\n\n // Check each line in this token's range for comments\n for (let line0 = map[0]; line0 < map[1]; line0++) {\n const line = line0 + 1; // 1-based\n if (processed.has(line)) continue;\n\n const threads = lineMap.get(line) || [];\n const hasThreads = threads.length > 0;\n processed.add(line);\n\n // Add line-highlight class to the block token if we have threads on this line\n if (hasThreads) {\n const existingClass = token.attrGet(\"class\") || \"\";\n token.attrSet(\n \"class\",\n existingClass\n ? `${existingClass} mrsf-line-highlight`\n : \"mrsf-line-highlight\",\n );\n token.attrSet(\"data-mrsf-line\", String(line));\n\n // Determine whether all threads on this line have inline highlights\n const allHaveInline = inlineHighlights &&\n threads.every((t) => !!t.comment.selected_text);\n\n // Inject badge unless gutterForInline is false AND all threads are inline-highlighted\n const showBadge = gutterForInline || !allHaveInline || !inlineHighlights;\n if (showBadge) {\n const badgeToken = new TokenCtor(\"mrsf_badge\", \"\", 0);\n badgeToken.meta = { line, threads, interactive, gutterPosition };\n tokens.splice(i + 1, 0, badgeToken);\n }\n\n // Highlight selected_text in the following inline token\n if (inlineHighlights) {\n const offset = showBadge ? 2 : 1;\n const inlineAfter = tokens[i + offset];\n if (inlineAfter && inlineAfter.type === \"inline\") {\n for (const thread of threads) {\n if (thread.comment.selected_text) {\n highlightInlineText(inlineAfter, thread, interactive, TokenCtor);\n }\n }\n }\n }\n } else if (interactive) {\n // No existing threads: inject a gutter add button for this line\n const addToken = new TokenCtor(\"mrsf_gutter_add\", \"\", 0);\n addToken.meta = { line, gutterPosition };\n tokens.splice(i + 1, 0, addToken);\n }\n }\n }\n\n // Wrap the entire output in a gutter container when using left gutter\n if (gutterPosition === \"left\" && processed.size > 0) {\n const openToken = new TokenCtor(\"mrsf_gutter_open\", \"div\", 1);\n openToken.attrSet(\"class\", \"mrsf-gutter-container\");\n tokens.unshift(openToken);\n const closeToken = new TokenCtor(\"mrsf_gutter_close\", \"div\", -1 as Nesting);\n tokens.push(closeToken);\n }\n });\n}\n", "/**\n * MRSF markdown-it plugin \u2014 renderer rules.\n *\n * Adds custom renderer rules for MRSF tokens:\n * - mrsf_badge: renders badge + tooltip HTML (gutter)\n * - mrsf_highlight_open/close: renders <mark> wrappers with inline tooltips\n */\n\nimport type { CommentThread } from \"../types.js\";\nimport { escapeHtml, renderThreadHtml } from \"@mrsf/plugin-shared\";\n\n/**\n * Install MRSF renderer rules on a markdown-it instance.\n */\nexport function installRendererRules(\n md: { renderer: { rules: Record<string, ((...args: any[]) => string) | undefined> } },\n): void {\n // Badge + tooltip (gutter)\n md.renderer.rules[\"mrsf_badge\"] = (\n tokens: { meta: { line: number; threads: CommentThread[]; interactive: boolean; gutterPosition: \"left\" | \"tight\" | \"right\" } }[],\n idx: number,\n ): string => {\n const { line, threads, interactive, gutterPosition } = tokens[idx].meta;\n\n const total = threads.reduce(\n (n, t) => n + 1 + t.replies.length,\n 0,\n );\n const allResolved = threads.every((t) => t.comment.resolved);\n const highestSeverity = threads.reduce<string | null>((sev, t) => {\n if (t.comment.severity === \"high\" || sev === \"high\") return \"high\";\n if (t.comment.severity === \"medium\" || sev === \"medium\") return \"medium\";\n if (t.comment.severity === \"low\" || sev === \"low\") return \"low\";\n return sev;\n }, null);\n\n const resolvedClass = allResolved ? \" mrsf-badge-resolved\" : \"\";\n const severityClass = highestSeverity === \"high\" || highestSeverity === \"medium\"\n ? ` mrsf-badge-severity-${highestSeverity}`\n : \"\";\n const positionClass = ` mrsf-gutter-${gutterPosition}`;\n\n const icon = allResolved ? \"\u2713\" : \"\uD83D\uDCAC\";\n\n let html = `<span class=\"mrsf-tooltip-anchor${positionClass}\">`;\n\n // Badge\n html += `<span class=\"mrsf-badge${resolvedClass}${severityClass}\" data-mrsf-line=\"${line}\" data-mrsf-action=\"navigate\" data-mrsf-comment-id=\"${escapeHtml(threads[0].comment.id)}\" tabindex=\"0\">${icon} ${total}</span>`;\n\n if (interactive) {\n html += `<button class=\"mrsf-gutter-add\" data-mrsf-action=\"add\" data-mrsf-line=\"${line}\" data-mrsf-start-line=\"${line}\" data-mrsf-end-line=\"${line}\" aria-label=\"Add comment\">+</button>`;\n }\n\n // Tooltip\n const tooltipClass = interactive ? \"mrsf-tooltip mrsf-interactive\" : \"mrsf-tooltip\";\n html += `<span class=\"${tooltipClass}\" data-mrsf-line=\"${line}\">`;\n for (const thread of threads) {\n html += renderThreadHtml(thread, interactive);\n }\n if (interactive) {\n html += `<span class=\"mrsf-tooltip-actions\"><button class=\"mrsf-action-btn\" data-mrsf-action=\"add\" data-mrsf-line=\"${line}\">Add comment</button></span>`;\n }\n html += `</span>`;\n\n html += `</span>`;\n return html;\n };\n\n // Gutter add button for lines without existing threads\n md.renderer.rules[\"mrsf_gutter_add\"] = (\n tokens: { meta: { line: number; gutterPosition: \"left\" | \"tight\" | \"right\" } }[],\n idx: number,\n ): string => {\n const { line, gutterPosition } = tokens[idx].meta;\n const positionClass = ` mrsf-gutter-${gutterPosition}`;\n let html = `<span class=\"mrsf-tooltip-anchor mrsf-gutter-add-only${positionClass}\">`;\n html += `<button class=\"mrsf-gutter-add\" data-mrsf-action=\"add\" data-mrsf-line=\"${line}\" data-mrsf-start-line=\"${line}\" data-mrsf-end-line=\"${line}\" aria-label=\"Add comment\">+</button>`;\n html += `</span>`;\n return html;\n };\n\n // Highlight open \u2014 wraps in tooltip-anchor for inline hover (feature D)\n md.renderer.rules[\"mrsf_highlight_open\"] = (\n tokens: any[],\n idx: number,\n ): string => {\n const token = tokens[idx];\n const cls = token.attrGet(\"class\") || \"mrsf-highlight\";\n const commentId = token.attrGet(\"data-mrsf-comment-id\") || \"\";\n const thread = token.meta?.thread as CommentThread | undefined;\n\n const line = thread?.comment.line ?? null;\n const endLine = thread?.comment.end_line ?? line ?? null;\n const startCol = thread?.comment.start_column ?? null;\n const endCol = thread?.comment.end_column ?? null;\n\n let html = \"\";\n if (thread) {\n const dataAttrs = [\n line != null ? `data-mrsf-line=\"${line}\"` : \"\",\n line != null ? `data-mrsf-start-line=\"${line}\"` : \"\",\n endLine != null ? `data-mrsf-end-line=\"${endLine}\"` : \"\",\n startCol != null ? `data-mrsf-start-column=\"${startCol}\"` : \"\",\n endCol != null ? `data-mrsf-end-column=\"${endCol}\"` : \"\",\n ].filter(Boolean).join(\" \");\n html += `<span class=\"mrsf-tooltip-anchor mrsf-inline-anchor\" ${dataAttrs}>`;\n }\n html += `<mark class=\"${escapeHtml(cls)}\" data-mrsf-comment-id=\"${escapeHtml(commentId)}\" tabindex=\"0\">`;\n return html;\n };\n\n // Highlight close \u2014 adds inline tooltip and closes tooltip-anchor\n md.renderer.rules[\"mrsf_highlight_close\"] = (\n tokens: any[],\n idx: number,\n ): string => {\n const token = tokens[idx];\n const meta = token.meta;\n let html = \"</mark>\";\n\n if (meta?.thread) {\n const thread = meta.thread as CommentThread;\n const interactive = meta.interactive as boolean;\n const tooltipClass = interactive\n ? \"mrsf-tooltip mrsf-inline-tooltip mrsf-interactive\"\n : \"mrsf-tooltip mrsf-inline-tooltip\";\n html += `<span class=\"${tooltipClass}\">`;\n html += renderThreadHtml(thread, interactive);\n html += `</span>`;\n html += `</span>`;\n }\n\n return html;\n };\n\n // Gutter container wrapper (left gutter mode)\n md.renderer.rules[\"mrsf_gutter_open\"] = (\n tokens: any[],\n idx: number,\n ): string => {\n const cls = tokens[idx].attrGet(\"class\") || \"mrsf-gutter-container\";\n return `<div class=\"${escapeHtml(cls)}\">`;\n };\n\n md.renderer.rules[\"mrsf_gutter_close\"] = (): string => {\n return `</div>`;\n };\n}\n", "/**\n * Shared logic for @mrsf/markdown-it-mrsf.\n *\n * Contains the plugin factory using shared comment loading/grouping logic.\n */\n\nimport type MarkdownIt from \"markdown-it\";\nimport type { MrsfPluginOptions, CommentLoader } from \"./types.js\";\nimport { resolveComments } from \"@mrsf/plugin-shared\";\nimport { installCoreRule } from \"./rules/core.js\";\nimport { installRendererRules } from \"./rules/renderer.js\";\n\n/**\n * Create a markdown-it plugin function with the given comment loader.\n *\n * @param loader - Function that resolves sidecar data from plugin options\n * @returns A markdown-it plugin function\n */\nexport function createMrsfPlugin(loader: CommentLoader) {\n return function mrsfPlugin(md: MarkdownIt, options: MrsfPluginOptions = {}): void {\n const interactive = options.interactive ?? false;\n const gutterPosition = options.gutterPosition ?? \"right\";\n const gutterForInline = options.gutterForInline ?? true;\n const inlineHighlights = options.inlineHighlights ?? true;\n\n const result = resolveComments(loader, options);\n if (!result) return;\n\n installCoreRule(md, result.lineMap, {\n interactive,\n gutterPosition,\n gutterForInline,\n inlineHighlights,\n });\n installRendererRules(md);\n };\n}\n"],
|
|
5
|
-
"mappings": ";AAsBA,SAAS,oBAAoB;AAC7B,OAAO,UAAU;AACjB,SAAS,2BAA2B;;;ACZ9B,SAAU,eAAe,KAAiB;AAC9C,SAAO,IAAI,SAAS,IAAI,CAAC,OAAO;IAC9B,IAAI,EAAE;IACN,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,YAAY;IACxB,cAAc,EAAE,gBAAgB;IAChC,YAAY,EAAE,cAAc;IAC5B,eAAe,EAAE,iBAAiB;IAClC,UAAU,CAAC,CAAC,EAAE;IACd,UAAU,EAAE,YAAY;IACxB,UAAU,EAAE,YAAY;IACxB,MAAM,EAAE,QAAQ;IAChB,WAAW,EAAE,aAAa;IAC1B;AACJ;AAKM,SAAU,YAAY,UAAuB;AACjD,QAAM,eAAe,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,QAAQ,IAAI;AACzE,QAAM,UAAU,SAAS,OAAO,CAAC,MAAM,EAAE,QAAQ;AAEjD,QAAM,WAAW,oBAAI,IAAG;AACxB,aAAW,KAAK,SAAS;AACvB,UAAM,OAAO,SAAS,IAAI,EAAE,QAAS,KAAK,CAAA;AAC1C,SAAK,KAAK,CAAC;AACX,aAAS,IAAI,EAAE,UAAW,IAAI;EAChC;AAEA,QAAM,UAAmB,oBAAI,IAAG;AAChC,aAAW,KAAK,cAAc;AAC5B,UAAM,OAAO,EAAE;AACf,UAAM,UAAU,QAAQ,IAAI,IAAI,KAAK,CAAA;AACrC,YAAQ,KAAK;MACX,SAAS;MACT,SAAS,SAAS,IAAI,EAAE,EAAE,KAAK,CAAA;KAChC;AACD,YAAQ,IAAI,MAAM,OAAO;EAC3B;AAEA,SAAO;AACT;AAMM,SAAU,gBACd,QACA,SAA0B;AAE1B,QAAM,eAAe,QAAQ,gBAAgB;AAE7C,QAAM,MAAM,OAAO,OAAO;AAC1B,MAAI,CAAC,OAAO,CAAC,IAAI,YAAY,IAAI,SAAS,WAAW,GAAG;AACtD,WAAO;EACT;AAEA,MAAI,WAAW,eAAe,GAAG;AACjC,MAAI,CAAC,cAAc;AACjB,eAAW,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ;EAC/C;AAEA,MAAI,SAAS,WAAW;AAAG,WAAO;AAElC,QAAM,UAAU,YAAY,QAAQ;AACpC,SAAO,EAAE,SAAS,SAAQ;AAC5B;;;
|
|
3
|
+
"sources": ["../src/index.ts", "../../shared/src/comments.ts", "../src/rules/core.ts", "../src/rules/renderer.ts", "../src/shared.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * @mrsf/markdown-it-mrsf \u2014 markdown-it plugin for MRSF review comments.\n *\n * This is the full-featured Node.js entry point. It supports all four\n * sidecar provisioning modes: `comments`, `loader`, `sidecarPath`, and\n * `documentPath`. The latter two require Node.js file-system APIs.\n *\n * In browser / bundler environments, the `\"browser\"` export condition in\n * package.json automatically resolves to the browser-safe entry, so you\n * never need to import a different path \u2014 just use:\n *\n * @example\n * ```ts\n * import MarkdownIt from \"markdown-it\";\n * import { mrsfPlugin } from \"@mrsf/markdown-it-mrsf\";\n *\n * const md = new MarkdownIt();\n * md.use(mrsfPlugin, { documentPath: \"docs/guide.md\" });\n * const html = md.render(markdownSource);\n * ```\n */\n\nimport { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { parseSidecarContent } from \"@mrsf/cli\";\nimport type { MrsfPluginOptions } from \"./types.js\";\nimport { createMrsfPlugin } from \"./shared.js\";\n\n// Re-export types for consumers\nexport type { MrsfPluginOptions, SlimComment, CommentThread, LineMap, CommentLoader } from \"./types.js\";\n\n/**\n * The markdown-it plugin function (Node.js \u2014 full feature set).\n */\nexport const mrsfPlugin = createMrsfPlugin((options: MrsfPluginOptions) => {\n // Priority 1: inline data\n if (options.comments) {\n return options.comments;\n }\n\n // Priority 2: custom loader function\n if (options.loader) {\n try {\n return options.loader();\n } catch {\n return null;\n }\n }\n\n // Priority 3: explicit sidecar path\n if (options.sidecarPath) {\n try {\n const abs = path.resolve(options.cwd || process.cwd(), options.sidecarPath);\n const content = readFileSync(abs, \"utf-8\");\n return parseSidecarContent(content, abs);\n } catch {\n return null;\n }\n }\n\n // Priority 4: auto-discover from documentPath\n if (options.documentPath) {\n try {\n const cwd = options.cwd || process.cwd();\n const abs = path.resolve(cwd, options.documentPath);\n const yamlPath = abs + \".review.yaml\";\n const jsonPath = abs + \".review.json\";\n\n let raw: string | null = null;\n let hint: string | null = null;\n try {\n raw = readFileSync(yamlPath, \"utf-8\");\n hint = yamlPath;\n } catch {\n try {\n raw = readFileSync(jsonPath, \"utf-8\");\n hint = jsonPath;\n } catch {\n return null;\n }\n }\n\n if (!raw) return null;\n return parseSidecarContent(raw, hint!);\n } catch {\n return null;\n }\n }\n\n return null;\n});\n\nexport default mrsfPlugin;\n", "/**\n * Shared comment loading and grouping logic for MRSF rendering plugins.\n */\n\nimport type { MrsfDocument } from \"@mrsf/cli\";\nimport type { MrsfPluginOptions, SlimComment, CommentThread, LineMap, CommentLoader } from \"./types.js\";\n\nexport type { CommentLoader };\n\n/**\n * Convert an MrsfDocument into a slim comment array.\n */\nexport function toSlimComments(doc: MrsfDocument): SlimComment[] {\n return doc.comments.map((c) => ({\n id: c.id,\n author: c.author || \"Unknown\",\n text: c.text || \"\",\n line: c.line ?? null,\n end_line: c.end_line ?? null,\n start_column: c.start_column ?? null,\n end_column: c.end_column ?? null,\n selected_text: c.selected_text || null,\n resolved: !!c.resolved,\n reply_to: c.reply_to || null,\n severity: c.severity || null,\n type: c.type || null,\n timestamp: c.timestamp || null,\n }));\n}\n\n/**\n * Group comments by line number, threading replies under parents.\n */\nexport function groupByLine(comments: SlimComment[]): LineMap {\n const rootComments = comments.filter((c) => !c.reply_to && c.line != null);\n const replies = comments.filter((c) => c.reply_to);\n\n const replyMap = new Map<string, SlimComment[]>();\n for (const r of replies) {\n const list = replyMap.get(r.reply_to!) || [];\n list.push(r);\n replyMap.set(r.reply_to!, list);\n }\n\n const lineMap: LineMap = new Map();\n for (const c of rootComments) {\n const line = c.line!;\n const threads = lineMap.get(line) || [];\n threads.push({\n comment: c,\n replies: replyMap.get(c.id) || [],\n });\n lineMap.set(line, threads);\n }\n\n return lineMap;\n}\n\n/**\n * Resolve options into a filtered LineMap ready for rendering.\n * Returns null if there are no comments to render.\n */\nexport function resolveComments(\n loader: CommentLoader,\n options: MrsfPluginOptions,\n): { lineMap: LineMap; comments: SlimComment[] } | null {\n const showResolved = options.showResolved ?? true;\n\n const doc = loader(options);\n if (!doc || !doc.comments || doc.comments.length === 0) {\n return null;\n }\n\n let comments = toSlimComments(doc);\n if (!showResolved) {\n comments = comments.filter((c) => !c.resolved);\n }\n\n if (comments.length === 0) return null;\n\n const lineMap = groupByLine(comments);\n return { lineMap, comments };\n}\n", "/**\n * MRSF markdown-it plugin \u2014 core rule (overlay gutter architecture).\n *\n * Walks the parsed token stream and annotates block tokens with\n * `data-mrsf-line` attributes. Adds `mrsf-line-highlight` class on\n * commented lines. Appends an `mrsf_data_script` token with serialized\n * comment data for the client-side MrsfController.\n *\n * NO visual tokens are injected \u2014 all badges, tooltips, and gutter\n * elements are created at runtime by the controller.\n */\n\nimport type Token from \"markdown-it/lib/token.mjs\";\nimport type { Nesting } from \"markdown-it/lib/token.mjs\";\nimport type StateCore from \"markdown-it/lib/rules_core/state_core.mjs\";\nimport type { LineMap, CommentThread } from \"../types.js\";\n\nexport interface CoreRuleOptions {\n /** Whether to add mrsf-line-highlight class on commented tokens. Default: false. */\n lineHighlight?: boolean;\n}\n\n/**\n * Install the MRSF core rule on a markdown-it instance.\n */\nexport function installCoreRule(\n md: { core: { ruler: { push: (name: string, fn: (state: StateCore) => void) => void } } },\n lineMap: LineMap,\n options: CoreRuleOptions = {},\n): void {\n md.core.ruler.push(\"mrsf_inject\", (state: StateCore) => {\n const tokens = state.tokens;\n const TokenCtor = state.Token;\n const processed = new Set<number>();\n\n for (let i = tokens.length - 1; i >= 0; i--) {\n const token = tokens[i];\n const map = token.map;\n if (!map) continue;\n\n // Skip inline tokens \u2014 process their parent block tokens only.\n if (token.type === \"inline\") continue;\n\n // Annotate the element with line range\n const startLine1 = map[0] + 1;\n const endLine1 = map[1];\n token.attrSet(\"data-mrsf-line\", String(startLine1));\n token.attrSet(\"data-mrsf-start-line\", String(startLine1));\n token.attrSet(\"data-mrsf-end-line\", String(endLine1));\n\n // Check each line in this token's range for comments\n for (let line0 = map[0]; line0 < map[1]; line0++) {\n const line = line0 + 1; // 1-based\n if (processed.has(line)) continue;\n processed.add(line);\n\n const threads = lineMap.get(line);\n if (threads && threads.length > 0) {\n if (options.lineHighlight) {\n const existingClass = token.attrGet(\"class\") || \"\";\n if (!existingClass.includes(\"mrsf-line-highlight\")) {\n token.attrSet(\n \"class\",\n existingClass\n ? `${existingClass} mrsf-line-highlight`\n : \"mrsf-line-highlight\",\n );\n }\n }\n token.attrSet(\"data-mrsf-line\", String(line));\n }\n }\n }\n\n // Append a data script token with all comment data\n const allThreads: CommentThread[] = [];\n for (const threads of lineMap.values()) {\n allThreads.push(...threads);\n }\n if (allThreads.length > 0) {\n const scriptToken = new TokenCtor(\"mrsf_data_script\", \"\", 0);\n scriptToken.meta = { threads: allThreads };\n tokens.push(scriptToken);\n }\n });\n}\n", "/**\n * MRSF markdown-it plugin \u2014 renderer rules (overlay gutter architecture).\n *\n * Adds a single custom renderer rule:\n * - mrsf_data_script: renders a <script type=\"application/mrsf+json\">\n * containing serialized comment data for the MrsfController.\n */\n\nimport type { CommentThread } from \"../types.js\";\n\n/**\n * Install MRSF renderer rules on a markdown-it instance.\n */\nexport function installRendererRules(\n md: { renderer: { rules: Record<string, ((...args: any[]) => string) | undefined> } },\n): void {\n md.renderer.rules[\"mrsf_data_script\"] = (\n tokens: { meta: { threads: CommentThread[] } }[],\n idx: number,\n ): string => {\n const { threads } = tokens[idx].meta;\n // Escape < to prevent script tag injection (XSS safety)\n const data = JSON.stringify({ threads }).replace(/</g, \"\\\\u003c\");\n return `<script type=\"application/mrsf+json\">${data}</script>`;\n };\n}\n", "/**\n * Shared logic for @mrsf/markdown-it-mrsf.\n *\n * Contains the plugin factory using shared comment loading/grouping logic.\n */\n\nimport type MarkdownIt from \"markdown-it\";\nimport type { MrsfPluginOptions, CommentLoader } from \"./types.js\";\nimport { resolveComments } from \"@mrsf/plugin-shared\";\nimport { installCoreRule } from \"./rules/core.js\";\nimport { installRendererRules } from \"./rules/renderer.js\";\n\n/**\n * Create a markdown-it plugin function with the given comment loader.\n *\n * @param loader - Function that resolves sidecar data from plugin options\n * @returns A markdown-it plugin function\n */\nexport function createMrsfPlugin(loader: CommentLoader) {\n return function mrsfPlugin(md: MarkdownIt, options: MrsfPluginOptions = {}): void {\n const result = resolveComments(loader, options);\n if (!result) return;\n\n installCoreRule(md, result.lineMap, { lineHighlight: options.lineHighlight ?? false });\n installRendererRules(md);\n };\n}\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E,YAAM,UAAU,aAAa,KAAK,OAAO;AACzC,aAAO,oBAAoB,SAAS,GAAG;AAAA,IACzC,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAGA,MAAI,QAAQ,cAAc;AACxB,QAAI;AACF,YAAM,MAAM,QAAQ,OAAO,QAAQ,IAAI;AACvC,YAAM,MAAM,KAAK,QAAQ,KAAK,QAAQ,YAAY;AAClD,YAAM,WAAW,MAAM;AACvB,YAAM,WAAW,MAAM;AAEvB,UAAI,MAAqB;AACzB,UAAI,OAAsB;AAC1B,UAAI;AACF,cAAM,aAAa,UAAU,OAAO;AACpC,eAAO;AAAA,MACT,QAAQ;AACN,YAAI;AACF,gBAAM,aAAa,UAAU,OAAO;AACpC,iBAAO;AAAA,QACT,QAAQ;AACN,iBAAO;AAAA,QACT;AAAA,MACF;AAEA,UAAI,CAAC,IAAK,QAAO;AACjB,aAAO,oBAAoB,KAAK,IAAK;AAAA,IACvC,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT,CAAC;AAED,IAAO,gBAAQ;",
|
|
6
6
|
"names": ["mrsfPlugin"]
|
|
7
7
|
}
|
package/dist/rules/core.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* MRSF markdown-it plugin — core rule.
|
|
2
|
+
* MRSF markdown-it plugin — core rule (overlay gutter architecture).
|
|
3
3
|
*
|
|
4
|
-
* Walks the parsed token stream and
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Walks the parsed token stream and annotates block tokens with
|
|
5
|
+
* `data-mrsf-line` attributes. Adds `mrsf-line-highlight` class on
|
|
6
|
+
* commented lines. Appends an `mrsf_data_script` token with serialized
|
|
7
|
+
* comment data for the client-side MrsfController.
|
|
8
|
+
*
|
|
9
|
+
* NO visual tokens are injected — all badges, tooltips, and gutter
|
|
10
|
+
* elements are created at runtime by the controller.
|
|
7
11
|
*/
|
|
8
12
|
import type StateCore from "markdown-it/lib/rules_core/state_core.mjs";
|
|
9
13
|
import type { LineMap } from "../types.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
gutterPosition: "left" | "tight" | "right";
|
|
14
|
-
gutterForInline: boolean;
|
|
15
|
-
inlineHighlights: boolean;
|
|
14
|
+
export interface CoreRuleOptions {
|
|
15
|
+
/** Whether to add mrsf-line-highlight class on commented tokens. Default: false. */
|
|
16
|
+
lineHighlight?: boolean;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Install the MRSF core rule on a markdown-it instance.
|
|
@@ -23,5 +24,5 @@ export declare function installCoreRule(md: {
|
|
|
23
24
|
push: (name: string, fn: (state: StateCore) => void) => void;
|
|
24
25
|
};
|
|
25
26
|
};
|
|
26
|
-
}, lineMap: LineMap, options
|
|
27
|
+
}, lineMap: LineMap, options?: CoreRuleOptions): void;
|
|
27
28
|
//# sourceMappingURL=core.d.ts.map
|
package/dist/rules/renderer.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* MRSF markdown-it plugin — renderer rules.
|
|
2
|
+
* MRSF markdown-it plugin — renderer rules (overlay gutter architecture).
|
|
3
3
|
*
|
|
4
|
-
* Adds custom renderer
|
|
5
|
-
* -
|
|
6
|
-
*
|
|
4
|
+
* Adds a single custom renderer rule:
|
|
5
|
+
* - mrsf_data_script: renders a <script type="application/mrsf+json">
|
|
6
|
+
* containing serialized comment data for the MrsfController.
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Install MRSF renderer rules on a markdown-it instance.
|
package/dist/style.css
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Sidemark —
|
|
2
|
+
* Sidemark — MRSF plugin default styles (overlay gutter architecture).
|
|
3
3
|
*
|
|
4
|
-
* Include via: import "@mrsf/
|
|
5
|
-
* or <link rel="stylesheet" href=".../@mrsf/
|
|
4
|
+
* Include via: import "@mrsf/plugin-shared/style.css"
|
|
5
|
+
* or <link rel="stylesheet" href=".../@mrsf/plugin-shared/dist/style.css">
|
|
6
6
|
*
|
|
7
7
|
* Customise with CSS custom properties (--mrsf-*).
|
|
8
|
+
*
|
|
9
|
+
* Layout: The controller wraps the rendered markdown in an overlay root
|
|
10
|
+
* with position:relative, and creates absolute-positioned gutter columns
|
|
11
|
+
* on the left and/or right. The plugins only add data-mrsf-line
|
|
12
|
+
* attributes — no visual DOM injection.
|
|
8
13
|
*/
|
|
9
14
|
|
|
10
15
|
/* ── Custom property defaults ────────────────────────────── */
|
|
@@ -22,6 +27,7 @@
|
|
|
22
27
|
--mrsf-severity-high: #e74c3c;
|
|
23
28
|
--mrsf-severity-medium: #f39c12;
|
|
24
29
|
--mrsf-severity-low: #3498db;
|
|
30
|
+
--mrsf-gutter-width: 36px;
|
|
25
31
|
--mrsf-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
26
32
|
}
|
|
27
33
|
|
|
@@ -33,29 +39,36 @@
|
|
|
33
39
|
}
|
|
34
40
|
}
|
|
35
41
|
|
|
36
|
-
/* ──
|
|
42
|
+
/* ── Overlay root (created by controller) ────────────────── */
|
|
37
43
|
|
|
38
|
-
.mrsf-
|
|
39
|
-
--mrsf-gutter-width: 44px;
|
|
44
|
+
.mrsf-overlay-root {
|
|
40
45
|
position: relative;
|
|
41
|
-
padding-left: var(--mrsf-gutter-width);
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
.mrsf-gutter {
|
|
49
|
+
position: absolute;
|
|
50
|
+
top: 0;
|
|
51
|
+
bottom: 0;
|
|
52
|
+
width: var(--mrsf-gutter-width);
|
|
53
|
+
pointer-events: none;
|
|
54
|
+
z-index: 10;
|
|
49
55
|
}
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
.mrsf-gutter-left {
|
|
58
|
+
left: calc(-1 * var(--mrsf-gutter-width) - 8px);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.mrsf-gutter-right {
|
|
62
|
+
right: calc(-1 * var(--mrsf-gutter-width) - 8px);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* ── Line highlight (CSS-only tinting for commented lines) ── */
|
|
52
66
|
|
|
53
67
|
.mrsf-line-highlight {
|
|
54
68
|
border-left: 3px solid var(--mrsf-accent);
|
|
55
69
|
padding-left: 8px;
|
|
56
70
|
background: rgba(55, 148, 255, 0.06);
|
|
57
71
|
border-radius: 2px;
|
|
58
|
-
position: relative;
|
|
59
72
|
transition: background 0.15s ease;
|
|
60
73
|
}
|
|
61
74
|
|
|
@@ -63,6 +76,18 @@
|
|
|
63
76
|
background: rgba(55, 148, 255, 0.12);
|
|
64
77
|
}
|
|
65
78
|
|
|
79
|
+
/* ── Gutter items (badges & add buttons, positioned by JS) ── */
|
|
80
|
+
|
|
81
|
+
.mrsf-gutter-item {
|
|
82
|
+
position: absolute;
|
|
83
|
+
left: 0;
|
|
84
|
+
right: 0;
|
|
85
|
+
display: flex;
|
|
86
|
+
align-items: center;
|
|
87
|
+
justify-content: center;
|
|
88
|
+
pointer-events: auto;
|
|
89
|
+
}
|
|
90
|
+
|
|
66
91
|
/* ── Badge ──────────────────────────────────────────────── */
|
|
67
92
|
|
|
68
93
|
.mrsf-badge {
|
|
@@ -74,11 +99,9 @@
|
|
|
74
99
|
line-height: 1;
|
|
75
100
|
padding: 2px 6px;
|
|
76
101
|
border-radius: 10px;
|
|
77
|
-
cursor:
|
|
102
|
+
cursor: pointer;
|
|
78
103
|
user-select: none;
|
|
79
104
|
white-space: nowrap;
|
|
80
|
-
vertical-align: middle;
|
|
81
|
-
margin-left: 6px;
|
|
82
105
|
|
|
83
106
|
color: var(--mrsf-badge-fg);
|
|
84
107
|
background: var(--mrsf-badge-bg);
|
|
@@ -100,19 +123,9 @@
|
|
|
100
123
|
border-left-color: var(--mrsf-severity-medium);
|
|
101
124
|
}
|
|
102
125
|
|
|
103
|
-
/* ──
|
|
104
|
-
|
|
105
|
-
.mrsf-tooltip-anchor {
|
|
106
|
-
position: relative;
|
|
107
|
-
display: inline-block;
|
|
108
|
-
vertical-align: baseline;
|
|
109
|
-
}
|
|
126
|
+
/* ── Add button (in gutter) ─────────────────────────────── */
|
|
110
127
|
|
|
111
128
|
.mrsf-gutter-add {
|
|
112
|
-
position: absolute;
|
|
113
|
-
right: -18px;
|
|
114
|
-
top: 50%;
|
|
115
|
-
transform: translateY(-50%);
|
|
116
129
|
opacity: 0;
|
|
117
130
|
pointer-events: none;
|
|
118
131
|
border: 1px solid var(--mrsf-tooltip-border);
|
|
@@ -125,83 +138,21 @@
|
|
|
125
138
|
line-height: 18px;
|
|
126
139
|
text-align: center;
|
|
127
140
|
cursor: pointer;
|
|
128
|
-
transition: opacity 0.12s ease
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
.mrsf-tooltip-anchor:hover > .mrsf-gutter-add,
|
|
132
|
-
.mrsf-tooltip-anchor:focus-within > .mrsf-gutter-add {
|
|
133
|
-
opacity: 1;
|
|
134
|
-
pointer-events: auto;
|
|
135
|
-
transform: translateY(-50%) scale(1.02);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/* Add-only anchors need hoverable area even without a badge */
|
|
139
|
-
.mrsf-tooltip-anchor.mrsf-gutter-add-only {
|
|
140
|
-
display: inline-block;
|
|
141
|
-
width: 24px;
|
|
142
|
-
height: 24px;
|
|
141
|
+
transition: opacity 0.12s ease;
|
|
143
142
|
}
|
|
144
143
|
|
|
145
|
-
/*
|
|
146
|
-
|
|
147
|
-
.mrsf-
|
|
144
|
+
/* Show add button on line hover (detected by controller via data attr) */
|
|
145
|
+
[data-mrsf-line]:hover ~ .mrsf-gutter .mrsf-gutter-add,
|
|
146
|
+
.mrsf-gutter-item:hover .mrsf-gutter-add {
|
|
148
147
|
opacity: 1;
|
|
149
148
|
pointer-events: auto;
|
|
150
|
-
transform: translateY(-50%) scale(1.02);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/* Gutter position: right (default) — float the badge to the right */
|
|
154
|
-
.mrsf-tooltip-anchor.mrsf-gutter-right {
|
|
155
|
-
float: right;
|
|
156
|
-
margin-left: 8px;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
.mrsf-tooltip-anchor.mrsf-gutter-right .mrsf-badge {
|
|
160
|
-
margin-left: 0;
|
|
161
149
|
}
|
|
162
150
|
|
|
163
|
-
/*
|
|
164
|
-
.mrsf-tooltip-anchor.mrsf-gutter-tight .mrsf-badge {
|
|
165
|
-
margin-right: 6px;
|
|
166
|
-
margin-left: 0;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/* Gutter position: left — badge in the left margin gutter.
|
|
170
|
-
Positioned against the gutter container (not the line element). */
|
|
171
|
-
.mrsf-tooltip-anchor.mrsf-gutter-left {
|
|
172
|
-
position: absolute;
|
|
173
|
-
left: 4px;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
.mrsf-tooltip-anchor.mrsf-gutter-left > .mrsf-gutter-add {
|
|
177
|
-
left: -18px;
|
|
178
|
-
right: auto;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
.mrsf-tooltip-anchor.mrsf-gutter-right > .mrsf-gutter-add {
|
|
182
|
-
right: -18px;
|
|
183
|
-
left: auto;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
.mrsf-tooltip-anchor.mrsf-gutter-left .mrsf-badge {
|
|
187
|
-
margin-left: 0;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/* Tooltip for left-gutter badges */
|
|
191
|
-
.mrsf-tooltip-anchor.mrsf-gutter-left > .mrsf-tooltip {
|
|
192
|
-
left: 0;
|
|
193
|
-
right: auto;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/* Inline highlight tooltip anchor */
|
|
197
|
-
.mrsf-inline-anchor {
|
|
198
|
-
/* inherit inline-block from .mrsf-tooltip-anchor */
|
|
199
|
-
}
|
|
151
|
+
/* ── Tooltip (positioned by JS, appended to gutter item) ── */
|
|
200
152
|
|
|
201
153
|
.mrsf-tooltip {
|
|
202
154
|
display: none;
|
|
203
155
|
position: absolute;
|
|
204
|
-
left: 0;
|
|
205
156
|
top: 100%;
|
|
206
157
|
z-index: 1000;
|
|
207
158
|
min-width: 300px;
|
|
@@ -222,20 +173,19 @@
|
|
|
222
173
|
color: var(--mrsf-tooltip-fg);
|
|
223
174
|
}
|
|
224
175
|
|
|
225
|
-
/*
|
|
226
|
-
.mrsf-
|
|
227
|
-
left:
|
|
228
|
-
right:
|
|
176
|
+
/* Left gutter: tooltip opens to the right */
|
|
177
|
+
.mrsf-gutter-left .mrsf-tooltip {
|
|
178
|
+
left: 0;
|
|
179
|
+
right: auto;
|
|
229
180
|
}
|
|
230
181
|
|
|
231
|
-
/*
|
|
232
|
-
.mrsf-
|
|
233
|
-
|
|
182
|
+
/* Right gutter: tooltip opens to the left */
|
|
183
|
+
.mrsf-gutter-right .mrsf-tooltip {
|
|
184
|
+
left: auto;
|
|
185
|
+
right: 0;
|
|
234
186
|
}
|
|
235
187
|
|
|
236
|
-
|
|
237
|
-
.mrsf-tooltip-anchor:hover > .mrsf-tooltip,
|
|
238
|
-
.mrsf-tooltip-anchor:focus-within > .mrsf-tooltip {
|
|
188
|
+
.mrsf-tooltip.mrsf-tooltip-visible {
|
|
239
189
|
display: block;
|
|
240
190
|
animation: mrsf-fade-in 0.15s ease;
|
|
241
191
|
}
|
|
@@ -246,11 +196,8 @@
|
|
|
246
196
|
}
|
|
247
197
|
|
|
248
198
|
/* ── Thread / Comment ───────────────────────────────────── */
|
|
249
|
-
/* All inner elements use <span> for valid HTML inside <p>/<h> elements,
|
|
250
|
-
with display: block to maintain block layout. */
|
|
251
199
|
|
|
252
200
|
.mrsf-thread {
|
|
253
|
-
display: block;
|
|
254
201
|
padding: 4px 0;
|
|
255
202
|
}
|
|
256
203
|
|
|
@@ -261,7 +208,6 @@
|
|
|
261
208
|
}
|
|
262
209
|
|
|
263
210
|
.mrsf-comment {
|
|
264
|
-
display: block;
|
|
265
211
|
padding: 4px 0;
|
|
266
212
|
}
|
|
267
213
|
|
|
@@ -273,7 +219,6 @@
|
|
|
273
219
|
/* ── Replies ────────────────────────────────────────────── */
|
|
274
220
|
|
|
275
221
|
.mrsf-replies {
|
|
276
|
-
display: block;
|
|
277
222
|
margin-left: 16px;
|
|
278
223
|
padding-left: 8px;
|
|
279
224
|
border-left: 2px solid var(--mrsf-tooltip-border);
|
|
@@ -343,7 +288,6 @@
|
|
|
343
288
|
/* ── Comment body ───────────────────────────────────────── */
|
|
344
289
|
|
|
345
290
|
.mrsf-comment-body {
|
|
346
|
-
display: block;
|
|
347
291
|
white-space: pre-wrap;
|
|
348
292
|
word-break: break-word;
|
|
349
293
|
}
|
|
@@ -351,30 +295,92 @@
|
|
|
351
295
|
/* ── Selected text quote in tooltip ─────────────────────── */
|
|
352
296
|
|
|
353
297
|
.mrsf-selected-text {
|
|
354
|
-
display: block;
|
|
355
298
|
font-family: monospace;
|
|
356
299
|
font-size: 0.85em;
|
|
357
300
|
background: rgba(127, 127, 127, 0.1);
|
|
358
301
|
border-left: 3px solid rgba(127, 127, 127, 0.3);
|
|
359
|
-
padding: 4px 8px;
|
|
360
302
|
margin: 4px 0;
|
|
361
303
|
border-radius: 2px;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.mrsf-selected-text-summary {
|
|
307
|
+
padding: 4px 8px;
|
|
308
|
+
cursor: pointer;
|
|
309
|
+
overflow: hidden;
|
|
310
|
+
text-overflow: ellipsis;
|
|
311
|
+
white-space: nowrap;
|
|
312
|
+
display: block;
|
|
313
|
+
list-style: none;
|
|
314
|
+
color: var(--mrsf-fg, inherit);
|
|
315
|
+
opacity: 0.7;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.mrsf-selected-text-summary::-webkit-details-marker {
|
|
319
|
+
display: none;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
.mrsf-selected-text-summary::before {
|
|
323
|
+
content: "▶ ";
|
|
324
|
+
font-size: 0.7em;
|
|
325
|
+
vertical-align: middle;
|
|
326
|
+
margin-right: 2px;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.mrsf-selected-text[open] > .mrsf-selected-text-summary {
|
|
330
|
+
display: none;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
.mrsf-selected-text-full {
|
|
334
|
+
display: block;
|
|
335
|
+
padding: 4px 8px;
|
|
362
336
|
white-space: pre-wrap;
|
|
363
337
|
word-break: break-word;
|
|
364
338
|
}
|
|
365
339
|
|
|
366
|
-
/* ── Inline text highlight
|
|
340
|
+
/* ── Inline text highlight (overlay positioned by JS) ───── */
|
|
341
|
+
|
|
342
|
+
.mrsf-highlight-overlay {
|
|
343
|
+
position: absolute;
|
|
344
|
+
background: var(--mrsf-highlight-bg);
|
|
345
|
+
border-bottom: 2px solid var(--mrsf-highlight-border);
|
|
346
|
+
border-radius: 2px;
|
|
347
|
+
pointer-events: none;
|
|
348
|
+
transition: background 0.15s ease;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/* ── Inline comment text highlight (<mark> by controller) ── */
|
|
367
352
|
|
|
368
|
-
.mrsf-highlight {
|
|
353
|
+
.mrsf-inline-highlight {
|
|
369
354
|
background: var(--mrsf-highlight-bg);
|
|
370
355
|
border-bottom: 2px solid var(--mrsf-highlight-border);
|
|
371
356
|
border-radius: 2px;
|
|
372
|
-
|
|
357
|
+
cursor: pointer;
|
|
373
358
|
transition: background 0.15s ease;
|
|
374
359
|
}
|
|
375
360
|
|
|
376
|
-
.mrsf-highlight:hover {
|
|
377
|
-
background: rgba(255, 213, 79, 0.
|
|
361
|
+
.mrsf-inline-highlight:hover {
|
|
362
|
+
background: rgba(255, 213, 79, 0.4);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/* Inline tooltip (appended to document.body, positioned by JS) */
|
|
366
|
+
.mrsf-inline-tooltip {
|
|
367
|
+
position: fixed;
|
|
368
|
+
z-index: 1100;
|
|
369
|
+
min-width: 300px;
|
|
370
|
+
max-width: 480px;
|
|
371
|
+
max-height: 400px;
|
|
372
|
+
overflow-y: auto;
|
|
373
|
+
padding: 8px;
|
|
374
|
+
border-radius: 6px;
|
|
375
|
+
background: var(--mrsf-tooltip-bg);
|
|
376
|
+
border: 1px solid var(--mrsf-tooltip-border);
|
|
377
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
|
|
378
|
+
font-family: var(--mrsf-font-family);
|
|
379
|
+
font-size: 13px;
|
|
380
|
+
line-height: 1.5;
|
|
381
|
+
color: var(--mrsf-tooltip-fg);
|
|
382
|
+
white-space: normal;
|
|
383
|
+
animation: mrsf-fade-in 0.15s ease;
|
|
378
384
|
}
|
|
379
385
|
|
|
380
386
|
/* ── Interactive action buttons ─────────────────────────── */
|
|
@@ -421,6 +427,39 @@
|
|
|
421
427
|
background: rgba(127, 127, 127, 0.2);
|
|
422
428
|
}
|
|
423
429
|
|
|
430
|
+
/* ── Floating "Add comment" button (selection-based) ────── */
|
|
431
|
+
|
|
432
|
+
/* ── Orphaned comments section (bottom of container) ────── */
|
|
433
|
+
|
|
434
|
+
.mrsf-orphaned-section {
|
|
435
|
+
margin-top: 24px;
|
|
436
|
+
padding-top: 16px;
|
|
437
|
+
border-top: 2px dashed var(--mrsf-tooltip-border);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
.mrsf-orphaned-heading {
|
|
441
|
+
font-family: var(--mrsf-font-family);
|
|
442
|
+
font-size: 12px;
|
|
443
|
+
font-weight: 600;
|
|
444
|
+
text-transform: uppercase;
|
|
445
|
+
letter-spacing: 0.5px;
|
|
446
|
+
color: #999;
|
|
447
|
+
margin-bottom: 8px;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
.mrsf-orphaned-thread {
|
|
451
|
+
padding: 8px;
|
|
452
|
+
margin-bottom: 6px;
|
|
453
|
+
border-radius: 6px;
|
|
454
|
+
border: 1px solid var(--mrsf-tooltip-border);
|
|
455
|
+
background: rgba(127, 127, 127, 0.06);
|
|
456
|
+
opacity: 0.7;
|
|
457
|
+
font-family: var(--mrsf-font-family);
|
|
458
|
+
font-size: 13px;
|
|
459
|
+
line-height: 1.5;
|
|
460
|
+
color: var(--mrsf-tooltip-fg);
|
|
461
|
+
}
|
|
462
|
+
|
|
424
463
|
.mrsf-add-inline-button {
|
|
425
464
|
position: absolute;
|
|
426
465
|
z-index: 1200;
|
package/dist/types.d.ts
CHANGED
|
@@ -55,6 +55,12 @@ export interface MrsfPluginOptions {
|
|
|
55
55
|
* Default: true.
|
|
56
56
|
*/
|
|
57
57
|
inlineHighlights?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Whether to add a `mrsf-line-highlight` CSS class on block elements
|
|
60
|
+
* that have comments. Provides a subtle visual tint on commented lines.
|
|
61
|
+
* Default: false.
|
|
62
|
+
*/
|
|
63
|
+
lineHighlight?: boolean;
|
|
58
64
|
/** Color scheme hint (default: 'auto'). */
|
|
59
65
|
theme?: "light" | "dark" | "auto";
|
|
60
66
|
/** Working directory for sidecar discovery (default: process.cwd()). */
|
package/package.json
CHANGED