Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
Redesign harper-editor UI (#3278)
Jason Adams8e784c129574
diff --git a/demo.md b/demo.mdindex 1841e96e0..31feafdc9 100644--- a/demo.md+++ b/demo.md@@ -1,17 +1,7 @@-There are some cases where the the standard grammar-checkers don't cut it. That;s where Harper comes in handy.+There are some cases where the the standard grammar checkers don't cut it. That;s where Harper comes in handy.-Harper is an language checker for developers. It can detect-improper capitalization and misspellled words,-as well as a number of other issues.-Like if you break up words you shoul dn't.-Harper can be an lifesaver when writing technical documents,-emails or other formal forms of communication.+Harper is an language checker for developers. It can detect improper capitalization and misspellled words, as well as a number of other issues. Like if you break up words you shoul dn't. Harper can be an lifesaver when writing technical documents, emails or other formal forms of communication.-Harper works everywhere, even when you're not online. Since your data-never leaves your device, you don't ned too worry abuot us-selling it or using it to train large language models.+Harper works everywhere, even when you're not online. Since your data never leaves your device, you don't ned too worry abuot us selling it or using it to train large language models.-The best part: Harper can give you feedback instantly.-For most documents, Harper can serve up suggestions in-under 10 ms, faster that Grammarly.+The best part: Harper can give you feedback instantly. For most documents, Harper can serve up suggestions in under 10 ms, faster that Grammarly.diff --git a/packages/harper-editor/src/lib/Editor.svelte b/packages/harper-editor/src/lib/Editor.svelteindex 139237491..a01fb7907 100644--- a/packages/harper-editor/src/lib/Editor.svelte+++ b/packages/harper-editor/src/lib/Editor.svelte@@ -1,25 +1,58 @@<script lang="ts">-import { Card } from 'components';-import type Linter from 'harper.js';+import type { Lint, Linter } from 'harper.js';import {type IgnorableLintBox,LintFramework,type UnpackedLintGroups,unpackLint,} from 'lint-framework';+import { tick } from 'svelte';+import { fade } from 'svelte/transition';+import {+ type EditorFontFamily,+ type EditorFontSize,+ fontStackFor,+ normalizeFontFamily,+ normalizeFontSize,+} from './editorDisplay.js';import LintSidebar from './LintSidebar.svelte';+import StatusBar from './StatusBar.svelte';export let content = '';export let linter: Linter;export let onReady: () => void = () => null;+export let defaultFontFamily: EditorFontFamily = 'sans';+export let defaultFontSize: EditorFontSize = 'default';+export let onChange: (text: string) => void = () => {};let editor: HTMLDivElement | null;let linterVersion = 0;let quill: any;let lintBoxes: IgnorableLintBox[] = [];+let activeLintId: string | null = null;+let documentText = content;+let fontFamily = normalizeFontFamily(defaultFontFamily);+let fontSize = normalizeFontSize(defaultFontSize);+let lastExternalContent = content;+let readySent = false;+let restoreButtonTimeout: ReturnType<typeof setTimeout> | null = null;+let restoreButtonVisible = false;+let sidebarVisible = true;+let syncTimeout: ReturnType<typeof setTimeout> | null = null;++const sidebarTransitionDuration = 250;+const restoreButtonDelay = sidebarTransitionDuration + 40;++$: fontStack = fontStackFor(fontFamily);+$: editorStyle =+ `--harper-editor-font-family: ${fontStack};` ++ (fontSize === 'default' ? '' : ` --harper-editor-font-size: ${fontSize}px;`);$: if (linter != null && quill != null) {- onReady();+ if (!readySent) {+ readySent = true;+ onReady();+ }}let lfw = new LintFramework(@@ -27,7 +60,7 @@ let lfw = new LintFramework(const raw = await linter.organizedLints(text);// The framework expects grouped lints keyed by sourceconst entries = await Promise.all(- Object.entries(raw).map(async ([source, lintGroup]) => {+ Object.entries(raw).map(async ([source, lintGroup]: [string, Lint[]]) => {const unpacked = await Promise.all(lintGroup.map((lint) => unpackLint(text, lint, linter)));return [source, unpacked] as const;}),@@ -35,7 +68,7 @@ let lfw = new LintFramework(const grouped: UnpackedLintGroups = Object.fromEntries(entries);- lintBoxes = lfw.getLastIgnorableLintBoxes();+ scheduleLintBoxSync();return grouped;},@@ -46,6 +79,7 @@ let lfw = new LintFramework(console.log(`Ignored ${hash}`);// Re-run linting to hide ignored lint immediatelylfw.update();+ scheduleLintBoxSync();} catch (e) {console.error('Failed to ignore lint', e);}@@ -86,10 +120,16 @@ async function updateLintFrameworkElements() {let { default: Quill } = await import('quill');quill = new Quill(editor, {});const container = quill.container ?? quill.root?.parentElement;- container?.classList.add('h-full', 'min-h-0');+ container?.classList.add('harper-editor-quill-container');- quill.root?.classList.add('flex', 'flex-col', 'h-full', 'min-h-0', 'outline-transparent');+ quill.root?.classList.add('harper-editor-surface');quill.root?.setAttribute('data-enable-grammarly', 'false');+ quill.root?.setAttribute('spellcheck', 'false');+ setQuillText(content, false);+ quill.on('text-change', () => {+ syncDocumentText(true);+ scheduleLintFrameworkUpdate();+ });}for (let el of editor.getElementsByTagName('p')) {@@ -103,11 +143,21 @@ $: if (editor != null) {updateLintFrameworkElements();}+$: if (quill != null && content !== lastExternalContent) {+ lastExternalContent = content;+ if (content !== documentText) {+ setQuillText(content, false);+ scheduleLintFrameworkUpdate();+ }+}+function jumpTo(lintBox: IgnorableLintBox) {if (typeof window === 'undefined') {return;}+ activeLintId = lintBox.lint.context_hash;+const range = lintBox.range;if (!range) {return;@@ -129,17 +179,173 @@ function jumpTo(lintBox: IgnorableLintBox) {console.error('Failed to jump to lint', error);}}++// Quill always keeps a trailing document newline; callers expect plain text.+function normalizeQuillText(text: string): string {+ return text.endsWith('\n') ? text.slice(0, -1) : text;+}++function setQuillText(text: string, notify: boolean) {+ if (quill == null) {+ documentText = text;+ return;+ }++ const source = notify ? 'user' : 'silent';+ quill.setText(text, source);+ syncDocumentText(notify);+}++// Keep the public text state and `onChange` callback in sync with Quill's document.+function syncDocumentText(notify: boolean) {+ if (quill == null) {+ return;+ }++ const next = normalizeQuillText(quill.getText());+ if (next === documentText) {+ return;+ }++ documentText = next;+ if (notify) {+ onChange(next);+ }+}++// The lint framework owns highlight DOM, so copy its latest boxes into Svelte state.+function syncLintBoxes() {+ lintBoxes = [...lfw.getLastIgnorableLintBoxes()];+ if (+ activeLintId != null &&+ !lintBoxes.some((lintBox) => lintBox.lint.context_hash === activeLintId)+ ) {+ activeLintId = null;+ }+}++// Lint decorations settle across layout frames; the timeout catches slower browser updates.+function scheduleLintBoxSync() {+ requestAnimationFrame(() => {+ requestAnimationFrame(syncLintBoxes);+ });++ if (syncTimeout != null) {+ clearTimeout(syncTimeout);+ }++ syncTimeout = setTimeout(syncLintBoxes, 150);+}++// Refresh target elements, ask the framework to lint, then mirror its current boxes.+function scheduleLintFrameworkUpdate() {+ updateLintFrameworkElements();+ lfw.update();+ scheduleLintBoxSync();+}++// Suggestions and ignores mutate the document/lint state outside Quill's text-change path.+function handleProblemAction() {+ syncDocumentText(true);+ scheduleLintFrameworkUpdate();+}++async function ignoreAllProblems() {+ syncDocumentText(false);++ const text = documentText;+ const activeLinter = linter;+ const groupedLints = await activeLinter.organizedLints(text, { dedup: false });+ const lints = Object.values(groupedLints).flat();++ if (lints.length === 0) {+ return;+ }++ await activeLinter.ignoreLints(text, lints);+}++async function showSidebar() {+ if (restoreButtonTimeout != null) {+ clearTimeout(restoreButtonTimeout);+ restoreButtonTimeout = null;+ }++ restoreButtonVisible = false;+ await tick();+ sidebarVisible = true;+}++function hideSidebar() {+ sidebarVisible = false;+ restoreButtonVisible = false;++ if (restoreButtonTimeout != null) {+ clearTimeout(restoreButtonTimeout);+ }++ restoreButtonTimeout = setTimeout(() => {+ if (!sidebarVisible) {+ restoreButtonVisible = true;+ }+ restoreButtonTimeout = null;+ }, restoreButtonDelay);+}</script>-<div class="flex flex-row h-full w-full [&_*]:outline-none">- <Card class="flex-1 h-full p-5 z-10 max-w-full text-lg mr-5 bg-white dark:bg-black overflow-auto">- <div bind:this={editor} spellcheck="false">- {@html content.replace(/\n\n/g, '<br>')}- </div>- </Card>+<div+ class="harper-editor @container flex h-full min-h-0 w-full flex-col overflow-hidden rounded-[10px] border-[0.5px] border-[rgba(28,26,22,0.14)] bg-[#fbfaf6] text-stone-950 shadow-2xl shadow-stone-950/5"+ style={editorStyle}+>+ <div class="flex min-h-0 min-w-0 flex-1 @max-[760px]:flex-col">+ <section class="relative min-w-0 flex-1 bg-[#fbfaf6]" aria-label="Document editor">+ <div class="h-full overflow-auto p-[34px_40px_56px] @max-[760px]:p-[28px_24px_42px]">+ <div class="mx-auto flex min-h-full max-w-[640px]">+ <div bind:this={editor} class="flex min-h-full w-full flex-1" spellcheck="false"></div>+ </div>+ </div>++ {#if !sidebarVisible && restoreButtonVisible}+ <button+ type="button"+ class="absolute top-3 right-3 z-20 inline-flex h-8 w-8 items-center justify-center rounded-md border-0 bg-transparent text-stone-600 shadow-none transition-colors duration-150 hover:text-stone-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500"+ aria-label="Show problems sidebar"+ title="Show problems sidebar"+ in:fade={{ duration: 120 }}+ on:click={showSidebar}+ >+ <svg+ viewBox="0 0 20 20"+ aria-hidden="true"+ class="h-[18px] w-[18px] fill-none stroke-current stroke-[1.5] [stroke-linecap:round] [stroke-linejoin:round]"+ >+ <rect x="3.5" y="3" width="13" height="14" rx="3" />+ <path d="M12.5 3v14" />+ </svg>+ </button>+ {/if}+ </section>++ {#if sidebarVisible}+ <LintSidebar+ {lintBoxes}+ {activeLintId}+ focusLint={jumpTo}+ onActivate={(lintBox) => (activeLintId = lintBox == null ? null : lintBox.lint.context_hash)}+ onApplied={handleProblemAction}+ onIgnored={handleProblemAction}+ onIgnoreAll={ignoreAllProblems}+ onHideSidebar={hideSidebar}+ />+ {/if}+ </div>- <LintSidebar- lintBoxes={lintBoxes}- focusLint={jumpTo}+ <StatusBar+ text={documentText}+ problemCount={lintBoxes.length}+ {fontFamily}+ {fontSize}+ onFontFamilyChange={(next) => (fontFamily = next)}+ onFontSizeChange={(next) => (fontSize = normalizeFontSize(next))}/></div>diff --git a/packages/harper-editor/src/lib/LazyEditor.svelte b/packages/harper-editor/src/lib/LazyEditor.svelteindex 37137b097..8af265672 100644--- a/packages/harper-editor/src/lib/LazyEditor.svelte+++ b/packages/harper-editor/src/lib/LazyEditor.svelte@@ -1,9 +1,13 @@<script lang="ts">import { Spinner } from 'components';-import type Linter from 'harper.js';+import type { Linter } from 'harper.js';+import type { EditorFontFamily, EditorFontSize } from './editorDisplay.js';export let content = '';export let linter: Linter;+export let defaultFontFamily: EditorFontFamily = 'sans';+export let defaultFontSize: EditorFontSize = 'default';+export let onChange: (text: string) => void = () => {};let editor = import('./Editor.svelte');let loading = true;@@ -15,7 +19,14 @@ function onReady() {{#await editor then { default: Editor}}<div class={`flex-row h-full w-full ${loading ? 'hidden' : 'flex'}`}>- <Editor content={content} {linter} {onReady} />+ <Editor+ {content}+ {linter}+ {onReady}+ {defaultFontFamily}+ {defaultFontSize}+ {onChange}+ /></div>{/await}diff --git a/packages/harper-editor/src/lib/LintCard.svelte b/packages/harper-editor/src/lib/LintCard.svelteindex 67b189388..fb7496cf1 100644--- a/packages/harper-editor/src/lib/LintCard.svelte+++ b/packages/harper-editor/src/lib/LintCard.svelte@@ -1,14 +1,16 @@<script lang="ts">-import { Button } from 'components';-import { lintKindColor, lintKindTextColor } from 'lint-framework';import { slide } from 'svelte/transition';-import type { UnpackedLint, UnpackedSuggestion } from './types';+import { LINT_KIND_STYLES, suggestionText } from './editorDisplay.js';+import type { UnpackedLint, UnpackedSuggestion } from './types.js';export let lint: UnpackedLint;export let open = false;+export let active = false;export let onToggleOpen: () => void;export let focusError: () => void;+export let onActivate: () => void = () => {};export let onApply: (s: UnpackedSuggestion) => void;+export let onIgnore: () => void | Promise<void> = () => {};export let snippet: {prefix: string;problem: string;@@ -17,70 +19,137 @@ export let snippet: {suffixEllipsis: boolean;};-function suggestionText(s: UnpackedSuggestion): string {- return s.replacement_text !== '' ? s.replacement_text : String(s.kind);+let cardEl: HTMLDivElement | null = null;++const iconClass =+ 'h-3.5 w-3.5 fill-none stroke-current stroke-[1.6] [stroke-linecap:round] [stroke-linejoin:round]';+const baseSuggestionClass =+ 'h-[26px] max-w-full overflow-hidden text-ellipsis rounded-full px-[11px] text-[12.5px] font-semibold';++$: lintKindStyle = LINT_KIND_STYLES[lint.lint_kind];+$: if (open && cardEl != null) {+ requestAnimationFrame(() => {+ const scroller = cardEl?.closest('[data-problems-scroller]');+ if (!(scroller instanceof HTMLElement) || cardEl == null) {+ return;+ }++ const top = cardEl.offsetTop;+ const bottom = top + cardEl.offsetHeight;+ const viewTop = scroller.scrollTop;+ const viewBottom = viewTop + scroller.clientHeight;++ if (top < viewTop + 8) {+ scroller.scrollTo({ top: Math.max(0, top - 14), behavior: 'smooth' });+ } else if (bottom > viewBottom - 8) {+ scroller.scrollTo({ top: bottom - scroller.clientHeight + 14, behavior: 'smooth' });+ }+ });+}++function handleFocus() {+ onActivate();+ focusError?.();}</script><div- class="rounded-lg border border-gray-300 dark:border-gray-700 shadow-sm bg-white dark:bg-[#0d1117]"- role="button"- tabindex="0"- aria-label="Focus lint error"- on:click={() => focusError?.()}- on:keydown={(e) => (e.key === 'Enter' || e.key === ' ') && (e.preventDefault(), focusError?.())}+ bind:this={cardEl}+ role="group"+ class={`shrink-0 overflow-hidden rounded-[10px] border-[0.5px] bg-white shadow-sm shadow-stone-950/5 transition-[box-shadow,border-color] duration-150 ${+ active ? lintKindStyle.activeClass : 'border-[rgba(28,26,22,0.14)]'+ }`}+ on:mouseenter={onActivate}>- <div- role="button"- tabindex="0"- class="flex items-center justify-between p-3 cursor-pointer select-none"+ <button+ type="button"+ class="m-0 flex min-h-8 w-full items-center gap-2 border-0 bg-transparent px-3 py-2 text-left text-inherit"aria-expanded={open}- on:click={() => onToggleOpen?.()}- on:keydown={(e) => (e.key === 'Enter' || e.key === ' ') && (e.preventDefault(), onToggleOpen?.())}+ on:click={onToggleOpen}>- <div- class="text-sm font-semibold pb-1"- style={`border-bottom: 2px solid ${lintKindColor(lint.lint_kind)}`}+ <span+ class={`inline-flex h-[11px] w-[11px] shrink-0 items-center justify-center rounded-full ${lintKindStyle.haloClass}`}>- {lint.lint_kind_pretty}- </div>- <svg- class={`ml-3 h-4 w-4 transform transition-transform duration-200 ${open ? 'rotate-180' : ''}`}- viewBox="0 0 20 20"- fill="currentColor"- aria-hidden="true"+ <span class={`h-[7px] w-[7px] rounded-full ${lintKindStyle.dotClass}`}></span>+ </span>+ <span class="text-[12.5px] leading-[1.1] font-semibold text-stone-950">+ {lintKindStyle.label}+ </span>+ <span+ class={`ml-auto inline-flex shrink-0 text-stone-500 transition-transform duration-150 ${+ open ? 'rotate-180' : ''+ }`}>- <path fill-rule="evenodd" d="M5.23 7.21a.75.75 0 011.06.02L10 11.127l3.71-3.896a.75.75 0 111.08 1.04l-4.243 4.46a.75.75 0 01-1.08 0L5.25 8.27a.75.75 0 01-.02-1.06z" clip-rule="evenodd" />- </svg>- </div>+ <svg viewBox="0 0 16 16" aria-hidden="true" class={iconClass}>+ <path d="M4 6 8 10 12 6" />+ </svg>+ </span>+ </button>+{#if open}- <div class="px-3 pb-3" in:slide={{ duration: 150 }} out:slide={{ duration: 150 }}>- <div class="text-sm text-gray-700 dark:text-gray-300 mb-2 break-words">- {@html lint.message_html}- </div>- <div class="text-xs font-mono mb-2 p-2 rounded border border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-[#0b0f14] text-gray-800 dark:text-gray-200 leading-snug">- <span class="text-gray-500">{snippet.prefixEllipsis ? '…' : ''}{snippet.prefix}</span>- <span class="px-0.5 rounded bg-yellow-200 text-black dark:bg-yellow-800 dark:text-yellow-100">{snippet.problem}</span>- <span class="text-gray-500">{snippet.suffix}{snippet.suffixEllipsis ? '…' : ''}</span>+ <div class="flex flex-col gap-2.5 px-3 pt-0.5 pb-3" in:slide={{ duration: 130 }} out:slide={{ duration: 130 }}>+ <button+ type="button"+ class="m-0 flex w-full flex-col border-0 bg-transparent p-0 text-left text-[13px] leading-[1.4] font-medium text-stone-950"+ on:click={handleFocus}+ >+ <span>{@html lint.message_html}</span>+ </button>++ <button+ type="button"+ class="m-0 block max-h-[84px] w-full overflow-hidden rounded-[7px] border-[0.5px] border-[rgba(28,26,22,0.09)] bg-[#fbfaf6] px-3 py-2.5 text-left text-xs leading-[1.45] text-stone-700"+ on:click={handleFocus}+ aria-label="Focus problem in editor"+ >+ <span class="text-stone-500">+ {snippet.prefixEllipsis ? '...' : ''}{snippet.prefix}+ </span>+ <mark+ class={`rounded-[3px] px-0.5 font-semibold ${lintKindStyle.softClass} ${lintKindStyle.textClass}`}+ >{snippet.problem}</mark+ >+ <span class="text-stone-500">+ {snippet.suffix}{snippet.suffixEllipsis ? '...' : ''}+ </span>+ </button>++ <div class="flex items-center justify-end gap-2">+ {#if lint.suggestions && lint.suggestions.length > 0}+ <div class="flex flex-1 flex-wrap justify-end gap-1.5">+ {#each lint.suggestions as suggestion, i}+ <button+ type="button"+ class={`${baseSuggestionClass} ${+ i === 0+ ? `border-transparent ${lintKindStyle.softClass} ${lintKindStyle.textClass} shadow-none`+ : 'border-[0.5px] border-stone-300 bg-linear-to-b from-white to-stone-50 text-stone-950 shadow-sm shadow-stone-950/5'+ }`}+ title={`Replace with "${suggestionText(suggestion)}"`}+ on:click={(event) => {+ event.stopPropagation();+ onApply?.(suggestion);+ }}+ >+ {suggestionText(suggestion)}+ </button>+ {/each}+ </div>+ {:else}+ <span class="mr-auto text-xs text-stone-400">No suggestions available.</span>+ {/if}++ <button+ type="button"+ class="h-[26px] shrink-0 border-0 bg-transparent px-1 text-[12.5px] font-medium text-stone-500 shadow-none"+ on:click={(event) => {+ event.stopPropagation();+ onIgnore();+ }}+ >+ Ignore+ </button></div>- {#if lint.suggestions && lint.suggestions.length > 0}- <div class="flex flex-wrap gap-2 justify-end">- {#each lint.suggestions as s}- <Button- size="xs"- color={lintKindColor(lint.lint_kind)}- textColor={lintKindTextColor(lint.lint_kind)}- class="!px-2 !py-1 text-xs font-semibold"- title={`Replace with "${suggestionText(s)}"`}- on:click={() => onApply?.(s)}- >- {suggestionText(s)}- </Button>- {/each}- </div>- {:else}- <div class="text-xs text-gray-400">No suggestions available.</div>- {/if}</div>{/if}</div>diff --git a/packages/harper-editor/src/lib/LintSidebar.svelte b/packages/harper-editor/src/lib/LintSidebar.svelteindex eb2d1c679..251fe00ec 100644--- a/packages/harper-editor/src/lib/LintSidebar.svelte+++ b/packages/harper-editor/src/lib/LintSidebar.svelte@@ -1,38 +1,138 @@<script lang="ts">-import { Button, Card } from 'components';+import { cubicOut } from 'svelte/easing';+import { fade, fly } from 'svelte/transition';+import { createEmptyLintKindCounts, LINT_KIND_STYLE_ENTRIES } from './editorDisplay.js';import LintCard from './LintCard.svelte';-import type { IgnorableLintBox, LintBox } from './types';+import type { IgnorableLintBox, LintBox } from './types.js';export let lintBoxes: IgnorableLintBox[] = [];+export let activeLintId: string | null = null;export let focusLint: (lintBox: IgnorableLintBox) => void = () => {};+export let onActivate: (lintBox: IgnorableLintBox | null) => void = () => {};+export let onApplied: () => void = () => {};+export let onIgnored: () => void = () => {};+export let onIgnoreAll: (() => void | Promise<void>) | null = null;+export let onHideSidebar: () => void = () => {};-async function ignoreAll() {- await Promise.all(lintBoxes.map((b) => (b.ignoreLint ? b.ignoreLint() : Promise.resolve())));-}+let openSet: Set<string> = new Set();+let menuRoot: HTMLDivElement | null = null;+let previousSignature = '';+let showLintKindCounts = true;+let menuOpen = false;+let showIgnoreConfirm = false;-let openSet: Set<number> = new Set();+const iconButtonClass =+ 'inline-flex h-7 w-7 items-center justify-center rounded-md border-0 bg-transparent text-stone-600 shadow-none transition-colors duration-150 hover:text-stone-950 disabled:opacity-50';+const menuItemClass =+ 'm-0 flex h-8 w-full items-center border-0 bg-transparent px-3 text-left text-[13px] font-medium text-stone-700 shadow-none hover:bg-stone-100 disabled:text-stone-300 disabled:hover:bg-transparent';+const dangerMenuItemClass =+ 'm-0 flex h-8 w-full items-center border-0 bg-transparent px-3 text-left text-[13px] font-medium text-red-700 shadow-none hover:bg-red-50 disabled:text-stone-300 disabled:hover:bg-transparent';$: allOpen = lintBoxes.length > 0 && openSet.size === lintBoxes.length;+$: problemCountLabel = `${lintBoxes.length} ${lintBoxes.length === 1 ? 'problem' : 'problems'}`;+$: counts = lintBoxes.reduce((acc, lintBox) => {+ acc[lintBox.lint.lint_kind] += 1;+ return acc;+}, createEmptyLintKindCounts());+$: visibleLintKindEntries = LINT_KIND_STYLE_ENTRIES.filter(([key]) => counts[key] > 0);+$: signature = lintBoxes.map((lintBox) => lintBox.lint.context_hash).join('|');+$: if (signature !== previousSignature) {+ previousSignature = signature;+ const availableIds = new Set(lintBoxes.map((lintBox) => lintBox.lint.context_hash));+ const next = new Set([...openSet].filter((id) => availableIds.has(id)));++ if (next.size === 0 && lintBoxes.length > 0) {+ next.add(lintBoxes[0].lint.context_hash);+ }-function toggleCard(i: number) {- const wasOpen = openSet.has(i);- if (wasOpen) {- const ns = new Set(openSet);- ns.delete(i);- openSet = ns;+ openSet = next;+}++async function ignoreAll() {+ if (onIgnoreAll != null) {+ await onIgnoreAll();} else {- const ns = new Set(openSet);- ns.add(i);- openSet = ns;+ const boxesToIgnore = [...lintBoxes];+ for (const lintBox of boxesToIgnore) {+ await lintBox.ignoreLint?.();+ }}++ openSet = new Set();+ onIgnored();}-function toggleAll() {- if (allOpen) {- openSet = new Set();+function hideSidebar() {+ menuOpen = false;+ showIgnoreConfirm = false;+ onHideSidebar();+}++function openAllCards() {+ openSet = new Set(lintBoxes.map((lintBox) => lintBox.lint.context_hash));+ menuOpen = false;+}++function closeAllCards() {+ openSet = new Set();+ menuOpen = false;+}++function requestIgnoreAll() {+ menuOpen = false;+ showIgnoreConfirm = true;+}++async function confirmIgnoreAll() {+ showIgnoreConfirm = false;+ await ignoreAll();+}++function cancelIgnoreAll() {+ showIgnoreConfirm = false;+}++function handleIgnoreBackdropClick(event: MouseEvent) {+ if (event.target === event.currentTarget) {+ cancelIgnoreAll();+ }+}++function handleWindowClick(event: MouseEvent) {+ if (!menuOpen || menuRoot == null || event.target == null) {+ return;+ }++ if (!menuRoot.contains(event.target as Node)) {+ menuOpen = false;+ }+}++function handleWindowKeydown(event: KeyboardEvent) {+ if (event.key !== 'Escape') {+ return;+ }++ if (showIgnoreConfirm) {+ event.preventDefault();+ showIgnoreConfirm = false;+ return;+ }++ if (menuOpen) {+ event.preventDefault();+ menuOpen = false;+ }+}++function toggleCard(id: string) {+ const next = new Set(openSet);+ if (next.has(id)) {+ next.delete(id);} else {- openSet = new Set(lintBoxes.map((_, i) => i));+ next.add(id);}+ openSet = next;}function collapse(contents: string) {@@ -41,7 +141,7 @@ function collapse(contents: string) {function createSnippetFor(lintBox: LintBox) {let lint = lintBox.lint;- let content = lintBox.source.textContent ?? '';+ let content = lint.source || lintBox.source.textContent || '';const CONTEXT = 60;const start = Math.max(0, lint.span.start - CONTEXT);@@ -62,58 +162,232 @@ function createSnippetFor(lintBox: LintBox) {suffixEllipsis: end < content.length,};}--$: if (openSet.size > 0) {- const max = lintBoxes.length;- const next = new Set<number>();- for (const idx of openSet) {- if (idx >= 0 && idx < max) next.add(idx);- }- if (next.size !== openSet.size) openSet = next;-}</script>-<Card class="hidden md:flex md:flex-col md:w-1/3 h-full p-5 z-10 bg-white dark:bg-black">- <div class="flex items-center justify-between mb-3">- <div class="text-base font-semibold">Problems</div>- <div class="flex items-center gap-2">- <Button- size="xs"- color="light"- class="text-xs"- on:click={toggleAll}- aria-label={allOpen ? 'Collapse all lint cards' : 'Open all lint cards'}+<svelte:window on:click={handleWindowClick} on:keydown={handleWindowKeydown} />++<aside+ class="flex min-h-0 w-[320px] flex-[0_0_320px] overflow-hidden border-l-[0.5px] border-[rgba(28,26,22,0.14)] bg-[#f4f0e7] [font-family:'Inter',-apple-system,BlinkMacSystemFont,'SF_Pro_Text','Helvetica_Neue',sans-serif] @max-[760px]:w-full @max-[760px]:flex-[0_0_42%] @max-[760px]:border-t-[0.5px] @max-[760px]:border-l-0"+ aria-label="Problems"+ transition:fly={{ x: 320, duration: 250, easing: cubicOut }}+>+ <div class="flex min-h-0 flex-1 flex-col" transition:fade={{ duration: 250 }}>+ <header class="flex items-center gap-1.5 px-3.5 pt-2.5 pb-2">+ <h2+ class="!m-0 flex min-w-0 flex-1 items-center !p-0 !text-[15px] !leading-none !font-bold text-stone-950 ![font-family:inherit]">- {allOpen ? 'Collapse all' : 'Open all'}- </Button>- <Button- size="xs"- color="light"- class="text-xs"- on:click={ignoreAll}- disabled={lintBoxes.length === 0}- aria-label="Ignore all current lints"+ <button+ type="button"+ class="!m-0 inline-flex min-w-0 items-center gap-1.5 border-0 bg-transparent !p-0 text-left !text-[15px] !leading-none font-[inherit] text-inherit"+ aria-expanded={showLintKindCounts}+ on:click={() => (showLintKindCounts = !showLintKindCounts)}+ >+ Problems+ <span+ class="inline-flex h-[18px] min-w-5 items-center justify-center rounded-full bg-amber-700 px-1.5 text-[11px] font-semibold text-white tabular-nums"+ >+ {lintBoxes.length}+ </span>+ <span+ class={`inline-flex shrink-0 text-stone-500 transition-transform duration-150 ${+ showLintKindCounts ? 'rotate-180' : ''+ }`}+ >+ <svg+ viewBox="0 0 16 16"+ aria-hidden="true"+ class="h-3.5 w-3.5 fill-none stroke-current stroke-[1.6] [stroke-linecap:round] [stroke-linejoin:round]"+ >+ <path d="M4 6 8 10 12 6" />+ </svg>+ </span>+ </button>+ </h2>++ <div bind:this={menuRoot} class="relative flex shrink-0 items-center gap-1.5">+ <button+ type="button"+ class={iconButtonClass}+ aria-label="Hide problems sidebar"+ title="Hide problems sidebar"+ on:click={hideSidebar}+ >+ <svg+ viewBox="0 0 20 20"+ aria-hidden="true"+ class="h-[18px] w-[18px] fill-none stroke-current stroke-[1.5] [stroke-linecap:round] [stroke-linejoin:round]"+ >+ <rect x="3.5" y="3" width="13" height="14" rx="3" />+ <path d="M13.25 5.5v9" />+ </svg>+ </button>++ <button+ type="button"+ class={iconButtonClass}+ aria-label="More problem actions"+ aria-haspopup="menu"+ aria-expanded={menuOpen}+ title="More problem actions"+ on:click={() => (menuOpen = !menuOpen)}+ >+ <svg viewBox="0 0 16 16" aria-hidden="true" class="h-4 w-4 fill-current">+ <circle cx="8" cy="4" r="1.15" />+ <circle cx="8" cy="8" r="1.15" />+ <circle cx="8" cy="12" r="1.15" />+ </svg>+ </button>++ {#if menuOpen}+ <div+ id="problem-actions-menu"+ role="menu"+ class="absolute top-[calc(100%+6px)] right-0 z-30 w-36 overflow-hidden rounded-lg border-[0.5px] border-[rgba(28,26,22,0.16)] bg-white py-1 shadow-lg shadow-stone-950/10"+ transition:fade={{ duration: 100 }}+ >+ <button+ type="button"+ role="menuitem"+ class={menuItemClass}+ disabled={lintBoxes.length === 0 || allOpen}+ on:click={openAllCards}+ >+ Open All+ </button>+ <button+ type="button"+ role="menuitem"+ class={menuItemClass}+ disabled={lintBoxes.length === 0 || openSet.size === 0}+ on:click={closeAllCards}+ >+ Close All+ </button>+ <div class="my-1 h-px bg-[rgba(28,26,22,0.09)]"></div>+ <button+ type="button"+ role="menuitem"+ class={dangerMenuItemClass}+ disabled={lintBoxes.length === 0}+ on:click={requestIgnoreAll}+ >+ Ignore All+ </button>+ </div>+ {/if}+ </div>+ </header>++ {#if showLintKindCounts && visibleLintKindEntries.length > 0}+ <div+ class="grid grid-cols-3 gap-x-2 gap-y-[7px] overflow-hidden border-b-[0.5px] border-[rgba(28,26,22,0.09)] px-[18px] pb-3"+ aria-label="Problem lint kinds">- Ignore all- </Button>- </div>- </div>- <div class="flex-1 overflow-y-auto pr-1">- {#if lintBoxes.length === 0}- <p class="text-sm text-gray-500">No lints yet.</p>- {:else}- <div class="space-y-3">- {#each lintBoxes as lintBox, i}+ {#each visibleLintKindEntries as [key, lintKindStyle]}+ <div+ class="grid min-w-0 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-1 whitespace-nowrap text-[10px] font-medium text-stone-500"+ >+ <span+ class={`inline-flex h-[9px] w-[9px] shrink-0 items-center justify-center rounded-full ${lintKindStyle.haloClass}`}+ >+ <span class={`h-[7px] w-[7px] rounded-full ${lintKindStyle.dotClass}`}></span>+ </span>+ <span class="overflow-hidden text-ellipsis">{lintKindStyle.label}</span>+ <strong class="font-medium text-stone-400 tabular-nums">{counts[key]}</strong>+ </div>+ {/each}+ </div>+ {/if}++ <div class="flex min-h-0 flex-1 flex-col gap-2 overflow-auto px-3.5 pt-3.5 pb-6" data-problems-scroller>+ {#if lintBoxes.length === 0}+ <div+ class="m-auto max-w-[220px] px-3 py-7 text-center text-[12.5px] leading-[1.55] text-stone-500"+ >+ <div+ aria-hidden="true"+ class="mb-2.5 inline-flex h-8 w-8 items-center justify-center rounded-lg bg-linear-to-b from-emerald-400 to-emerald-600 text-white shadow-sm shadow-emerald-900/20"+ >+ <svg+ viewBox="0 0 16 16"+ class="h-4 w-4 fill-none stroke-current stroke-[1.6] [stroke-linecap:round] [stroke-linejoin:round]"+ >+ <path d="M3.5 8.5 6.5 11.5 12.5 5" />+ </svg>+ </div>+ <strong class="mb-0.5 block font-semibold text-stone-950">All clear</strong>+ <p class="m-0">Harper has no suggestions for this document.</p>+ </div>+ {:else}+ {#each lintBoxes as lintBox}+ {@const id = lintBox.lint.context_hash}<LintCardlint={lintBox.lint}snippet={createSnippetFor(lintBox)}- open={openSet.has(i)}- onToggleOpen={() => toggleCard(i)}+ open={openSet.has(id)}+ active={activeLintId === id}+ onToggleOpen={() => toggleCard(id)}focusError={() => focusLint(lintBox)}- onApply={(s) => lintBox.applySuggestion(s)}+ onActivate={() => onActivate(lintBox)}+ onApply={(suggestion) => {+ lintBox.applySuggestion(suggestion);+ onApplied();+ }}+ onIgnore={async () => {+ await lintBox.ignoreLint?.();+ onIgnored();+ }}/>{/each}+ {/if}+ </div>+ </div>+</aside>++{#if showIgnoreConfirm}+ <div+ class="fixed inset-0 z-50 flex items-center justify-center bg-stone-950/35 px-4"+ role="presentation"+ transition:fade={{ duration: 120 }}+ on:click={handleIgnoreBackdropClick}+ >+ <div+ class="w-full max-w-[340px] rounded-lg border-[0.5px] border-[rgba(28,26,22,0.16)] bg-white p-4 text-stone-950 shadow-2xl shadow-stone-950/20"+ role="dialog"+ aria-modal="true"+ aria-labelledby="ignore-all-title"+ tabindex="-1"+ >+ <h3 id="ignore-all-title" class="!m-0 !p-0 text-[15px] leading-5 font-semibold">+ Ignore all problems?+ </h3>+ <p class="mt-2 mb-4 text-[13px] leading-5 text-stone-600">+ This will ignore {problemCountLabel} in the current document.+ </p>+ <div class="flex justify-end gap-2">+ <button+ type="button"+ class="h-8 rounded-md border-[0.5px] border-stone-300 bg-linear-to-b from-white to-stone-50 px-3 text-[13px] font-medium text-stone-700 shadow-sm shadow-stone-950/5"+ on:click={cancelIgnoreAll}+ >+ Cancel+ </button>+ <button+ type="button"+ class="h-8 rounded-md border-[0.5px] border-red-700 bg-red-700 px-3 text-[13px] font-medium text-white shadow-sm shadow-red-950/10 disabled:opacity-50"+ disabled={lintBoxes.length === 0}+ on:click={confirmIgnoreAll}+ >+ Ignore All+ </button></div>- {/if}+ </div></div>-</Card>+{/if}++<style>+ aside :global(code) {+ font-family: inherit;+ font-size: inherit;+ }+</style>diff --git a/packages/harper-editor/src/lib/StatusBar.svelte b/packages/harper-editor/src/lib/StatusBar.sveltenew file mode 100644index 000000000..8b07e3490--- /dev/null+++ b/packages/harper-editor/src/lib/StatusBar.svelte@@ -0,0 +1,91 @@+<script lang="ts">+import {+ type EditorFontFamily,+ type EditorFontSize,+ FONT_OPTIONS,+ FONT_SIZES,+ wordCount,+} from './editorDisplay.js';++export let text = '';+export let problemCount = 0;+export let fontFamily: EditorFontFamily = 'sans';+export let fontSize: EditorFontSize = 'default';+export let onFontFamilyChange: (fontFamily: EditorFontFamily) => void = () => {};+export let onFontSizeChange: (fontSize: EditorFontSize) => void = () => {};++const fontButtonClass =+ 'inline-flex h-4 min-w-7 items-center justify-center rounded px-2 text-xs leading-none font-medium text-stone-500';++$: words = wordCount(text);+$: chars = text.length;+</script>++<footer+ class="flex min-h-[26px] flex-[0_0_26px] items-center gap-3.5 border-t-[0.5px] border-[rgba(28,26,22,0.09)] bg-[#f4f0e7] px-2 pr-2 pl-3.5 text-[11px] whitespace-nowrap text-stone-500 tabular-nums [font-family:'JetBrains_Mono',ui-monospace,'SF_Mono',Menlo,monospace] @max-[760px]:h-auto @max-[760px]:min-h-[30px] @max-[760px]:flex-wrap @max-[760px]:gap-y-1.5 @max-[760px]:py-[5px]"+ aria-label="Editor status"+>+ <div class="inline-flex items-center gap-2">+ <span class="inline-flex items-center gap-1.5">+ <span+ class={`h-1.5 w-1.5 rounded-full ${+ problemCount === 0 ? 'bg-emerald-600' : 'bg-amber-700'+ }`}+ ></span>+ {#if problemCount === 0}+ All clear+ {:else}+ {problemCount} problem{problemCount === 1 ? '' : 's'}+ {/if}+ </span>+ </div>++ <span class="h-2.5 w-px bg-[rgba(28,26,22,0.14)]"></span>+ <span>{words} words</span>+ <span>{chars} chars</span>++ <span class="flex-1"></span>++ <div+ class="inline-flex h-[18px] items-center rounded-[5px] border-[0.5px] border-stone-200 bg-stone-200/60 p-px"+ aria-label="Font family"+ >+ {#each FONT_OPTIONS as option}+ <button+ type="button"+ class={`${fontButtonClass} ${+ fontFamily === option.value+ ? 'bg-white font-bold text-stone-950 shadow-sm shadow-stone-950/10'+ : ''+ }`}+ style={`font-family: ${option.stack}`}+ title={option.label}+ aria-label={`Use ${option.label.toLowerCase()} font`}+ aria-pressed={fontFamily === option.value}+ on:click={() => onFontFamilyChange(option.value)}+ >+ {option.sample}+ </button>+ {/each}+ </div>++ <label+ class="relative inline-flex h-[18px] items-center rounded-[5px] border-[0.5px] border-stone-200 bg-stone-200/60 pr-[18px] pl-2 text-[11px] font-medium text-stone-950 after:absolute after:top-1/2 after:right-[5px] after:-translate-y-1/2 after:text-[9px] after:leading-none after:text-stone-500 after:content-['v'] after:[font-family:-apple-system,BlinkMacSystemFont,'SF_Pro_Text',sans-serif]"+ >+ <span>{fontSize === 'default' ? 'Default' : `${fontSize}px`}</span>+ <select+ value={fontSize}+ class="absolute inset-0 border-0 opacity-0"+ aria-label="Font size"+ on:change={(event) => {+ const value = event.currentTarget.value;+ onFontSizeChange(value === 'default' ? 'default' : Number(value));+ }}+ >+ <option value="default">Default</option>+ {#each FONT_SIZES as size}+ <option value={size}>{size}px</option>+ {/each}+ </select>+ </label>+</footer>diff --git a/packages/harper-editor/src/lib/bundle.ts b/packages/harper-editor/src/lib/bundle.tsindex 1ac6b829c..12c1a4cd1 100644--- a/packages/harper-editor/src/lib/bundle.ts+++ b/packages/harper-editor/src/lib/bundle.ts@@ -1,4 +1,4 @@import 'components/components.css';import './styles.css';-export * from './index';+export * from './index.js';diff --git a/packages/harper-editor/src/lib/editorDisplay.ts b/packages/harper-editor/src/lib/editorDisplay.tsnew file mode 100644index 000000000..5806b6a90--- /dev/null+++ b/packages/harper-editor/src/lib/editorDisplay.ts@@ -0,0 +1,328 @@+/**+ * Shared display configuration and helpers for the Harper editor UI.+ *+ * This module keeps editor-only presentation choices, such as lint-kind styles,+ * lint-kind ordering, font options, and small formatting helpers, out of Svelte+ * components. Canonical linting concepts still come from `harper.js` and+ * `lint-framework`; this file only describes how those values should appear in+ * the editor.+ */+import type { LintKind } from 'harper.js';+import type { UnpackedSuggestion } from './types.js';++export type EditorFontFamily = 'sans' | 'serif' | 'mono';++export type EditorFontSize = 'default' | number;++export type LintKindCounts = Record<LintKind, number>;++export const FONT_OPTIONS: {+ value: EditorFontFamily;+ label: string;+ sample: string;+ stack: string;+}[] = [+ {+ value: 'sans',+ label: 'Sans',+ sample: 'Aa',+ stack:+ "'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif",+ },+ {+ value: 'serif',+ label: 'Serif',+ sample: 'Aa',+ stack: "'Iowan Old Style', 'New York', Georgia, serif",+ },+ {+ value: 'mono',+ label: 'Mono',+ sample: 'Aa',+ stack: "'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace",+ },+];++export const FONT_SIZES = [12, 13, 14, 15, 16, 17, 18, 20, 22];+export const DEFAULT_FONT_SIZE = 'default';++export const LINT_KIND_ORDER: LintKind[] = [+ 'Spelling',+ 'Typo',+ 'Capitalization',+ 'Grammar',+ 'Agreement',+ 'BoundaryError',+ 'Punctuation',+ 'Usage',+ 'WordChoice',+ 'Style',+ 'Readability',+ 'Enhancement',+ 'Redundancy',+ 'Repetition',+ 'Formatting',+ 'Regionalism',+ 'Nonstandard',+ 'Eggcorn',+ 'Malapropism',+ 'Miscellaneous',+];++/**+ * Presentation metadata for each Harper lint kind.+ *+ * Keeping these classes here lets the editor share one visual language across+ * cards, counts, and active states without spreading Tailwind class maps through+ * Svelte components.+ */+export const LINT_KIND_STYLES: Record<+ LintKind,+ {+ label: string;+ dotClass: string;+ haloClass: string;+ textClass: string;+ softClass: string;+ activeClass: string;+ }+> = {+ Agreement: {+ label: 'Agreement',+ dotClass: 'bg-emerald-500',+ haloClass: 'bg-emerald-100',+ textClass: 'text-emerald-700',+ softClass: 'bg-emerald-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-emerald-500/10',+ },+ BoundaryError: {+ label: 'Boundary',+ dotClass: 'bg-indigo-500',+ haloClass: 'bg-indigo-100',+ textClass: 'text-indigo-700',+ softClass: 'bg-indigo-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-indigo-500/10',+ },+ Capitalization: {+ label: 'Capitalization',+ dotClass: 'bg-rose-500',+ haloClass: 'bg-rose-100',+ textClass: 'text-rose-700',+ softClass: 'bg-rose-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-rose-500/10',+ },+ Eggcorn: {+ label: 'Eggcorn',+ dotClass: 'bg-violet-500',+ haloClass: 'bg-violet-100',+ textClass: 'text-violet-700',+ softClass: 'bg-violet-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-violet-500/10',+ },+ Enhancement: {+ label: 'Enhancement',+ dotClass: 'bg-amber-600',+ haloClass: 'bg-amber-100',+ textClass: 'text-amber-700',+ softClass: 'bg-amber-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-amber-600/10',+ },+ Formatting: {+ label: 'Formatting',+ dotClass: 'bg-slate-500',+ haloClass: 'bg-slate-100',+ textClass: 'text-slate-700',+ softClass: 'bg-slate-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-slate-500/10',+ },+ Grammar: {+ label: 'Grammar',+ dotClass: 'bg-emerald-600',+ haloClass: 'bg-emerald-100',+ textClass: 'text-emerald-700',+ softClass: 'bg-emerald-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-emerald-600/10',+ },+ Malapropism: {+ label: 'Malapropism',+ dotClass: 'bg-fuchsia-500',+ haloClass: 'bg-fuchsia-100',+ textClass: 'text-fuchsia-700',+ softClass: 'bg-fuchsia-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-fuchsia-500/10',+ },+ Miscellaneous: {+ label: 'Miscellaneous',+ dotClass: 'bg-sky-500',+ haloClass: 'bg-sky-100',+ textClass: 'text-sky-700',+ softClass: 'bg-sky-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-sky-500/10',+ },+ Nonstandard: {+ label: 'Nonstandard',+ dotClass: 'bg-stone-500',+ haloClass: 'bg-stone-100',+ textClass: 'text-stone-700',+ softClass: 'bg-stone-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-stone-500/10',+ },+ Punctuation: {+ label: 'Punctuation',+ dotClass: 'bg-cyan-600',+ haloClass: 'bg-cyan-100',+ textClass: 'text-cyan-700',+ softClass: 'bg-cyan-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-cyan-600/10',+ },+ Readability: {+ label: 'Readability',+ dotClass: 'bg-violet-600',+ haloClass: 'bg-violet-100',+ textClass: 'text-violet-700',+ softClass: 'bg-violet-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-violet-600/10',+ },+ Redundancy: {+ label: 'Redundancy',+ dotClass: 'bg-amber-600',+ haloClass: 'bg-amber-100',+ textClass: 'text-amber-700',+ softClass: 'bg-amber-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-amber-600/10',+ },+ Regionalism: {+ label: 'Regionalism',+ dotClass: 'bg-teal-700',+ haloClass: 'bg-teal-100',+ textClass: 'text-teal-700',+ softClass: 'bg-teal-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-teal-700/10',+ },+ Repetition: {+ label: 'Repetition',+ dotClass: 'bg-amber-700',+ haloClass: 'bg-amber-100',+ textClass: 'text-amber-700',+ softClass: 'bg-amber-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-amber-700/10',+ },+ Spelling: {+ label: 'Spelling',+ dotClass: 'bg-rose-500',+ haloClass: 'bg-rose-100',+ textClass: 'text-rose-700',+ softClass: 'bg-rose-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-rose-500/10',+ },+ Style: {+ label: 'Style',+ dotClass: 'bg-blue-500',+ haloClass: 'bg-blue-100',+ textClass: 'text-blue-700',+ softClass: 'bg-blue-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-blue-500/10',+ },+ Typo: {+ label: 'Typo',+ dotClass: 'bg-rose-500',+ haloClass: 'bg-rose-100',+ textClass: 'text-rose-700',+ softClass: 'bg-rose-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-rose-500/10',+ },+ Usage: {+ label: 'Usage',+ dotClass: 'bg-green-600',+ haloClass: 'bg-green-100',+ textClass: 'text-green-700',+ softClass: 'bg-green-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-green-600/10',+ },+ WordChoice: {+ label: 'Word Choice',+ dotClass: 'bg-blue-600',+ haloClass: 'bg-blue-100',+ textClass: 'text-blue-700',+ softClass: 'bg-blue-50',+ activeClass: 'border-[rgba(28,26,22,0.14)] shadow-blue-600/10',+ },+};++export const LINT_KIND_STYLE_ENTRIES = LINT_KIND_ORDER.map(+ (key) => [key, LINT_KIND_STYLES[key]] as const,+);++/**+ * Create a zero-filled count map for every lint kind shown by the editor.+ *+ * Components use this as a stable accumulator shape so lint-kind count rendering+ * does not need to handle missing keys.+ */+export function createEmptyLintKindCounts(): LintKindCounts {+ return Object.fromEntries(LINT_KIND_ORDER.map((key) => [key, 0])) as LintKindCounts;+}++/**+ * Convert persisted or caller-provided font family values to a supported option.+ *+ * This keeps the editor resilient to stale settings or arbitrary input while+ * preserving a predictable default.+ */+export function normalizeFontFamily(value: string): EditorFontFamily {+ if (value === 'serif' || value === 'mono') {+ return value;+ }++ return 'sans';+}++/**+ * Resolve an editor font family option to the CSS stack used by the editor.+ *+ * Components call this instead of duplicating font-stack strings or fallback+ * behavior.+ */+export function fontStackFor(value: EditorFontFamily): string {+ return FONT_OPTIONS.find((option) => option.value === value)?.stack ?? FONT_OPTIONS[0].stack;+}++/**+ * Convert persisted or caller-provided font size values to a supported editor size.+ *+ * Numeric values are rounded and clamped so user input cannot produce unreadable+ * or layout-breaking editor text.+ */+export function normalizeFontSize(value: EditorFontSize | string): EditorFontSize {+ if (value === DEFAULT_FONT_SIZE || value == null || value === '') {+ return DEFAULT_FONT_SIZE;+ }++ const numericValue = typeof value === 'number' ? value : Number(value);+ if (!Number.isFinite(numericValue)) {+ return DEFAULT_FONT_SIZE;+ }++ const rounded = Math.round(numericValue);+ return Math.min(28, Math.max(11, rounded));+}++/**+ * Return the user-facing text for an unpacked suggestion.+ *+ * Replacement suggestions show their replacement text, while non-replacement+ * suggestions fall back to their kind so buttons still have meaningful labels.+ */+export function suggestionText(suggestion: UnpackedSuggestion): string {+ return suggestion.replacement_text !== '' ? suggestion.replacement_text : String(suggestion.kind);+}++/**+ * Count whitespace-delimited words for the editor status bar.+ *+ * This lightweight count is intentionally display-oriented and avoids coupling+ * status text to Harper's parser internals.+ */+export function wordCount(text: string): number {+ return text.trim().match(/\S+/g)?.length ?? 0;+}diff --git a/packages/harper-editor/src/lib/index.ts b/packages/harper-editor/src/lib/index.tsindex 1599dd4df..d4641f204 100644--- a/packages/harper-editor/src/lib/index.ts+++ b/packages/harper-editor/src/lib/index.ts@@ -1,4 +1,5 @@export { default as Editor } from './Editor.svelte';+export type { EditorFontFamily, EditorFontSize } from './editorDisplay.js';export { default as LazyEditor } from './LazyEditor.svelte';export { default as LintCard } from './LintCard.svelte';export { default as LintSidebar } from './LintSidebar.svelte';@@ -12,4 +13,4 @@ export type {UnpackedLint,UnpackedSpan,UnpackedSuggestion,-} from './types';+} from './types.js';diff --git a/packages/harper-editor/src/lib/styles.css b/packages/harper-editor/src/lib/styles.cssindex 81d706f6b..ebf498bb9 100644--- a/packages/harper-editor/src/lib/styles.css+++ b/packages/harper-editor/src/lib/styles.css@@ -3,3 +3,75 @@@custom-variant dark (&:where(.dark, .dark *));@source "./**/*.{svelte,ts}";++.harper-editor {+ --harper-editor-font-size: inherit;+}++.harper-editor *,+.harper-editor *::before,+.harper-editor *::after {+ box-sizing: border-box;+}++.harper-editor button,+.harper-editor input,+.harper-editor select {+ font: inherit;+}++.harper-editor button:not(:disabled) {+ cursor: pointer;+}++.harper-editor button:disabled {+ cursor: default;+}++.harper-editor button:focus-visible,+.harper-editor select:focus-visible {+ outline: 2px solid var(--color-blue-600);+ outline-offset: 2px;+}++.harper-editor-quill-container {+ display: flex;+ flex: 1;+ width: 100%;+ min-height: 100%;+}++.harper-editor-surface {+ flex: 1;+ min-height: 100%;+}++.harper-editor-surface,+.harper-editor-surface.ql-editor {+ padding: 0;+ border: 0;+ outline: 0;+ background: transparent;+ color: inherit;+ font-family: var(--harper-editor-font-family);+ font-size: var(--harper-editor-font-size);+ line-height: 1.5;+ letter-spacing: 0;+ white-space: pre-wrap;+}++.harper-editor-surface:focus,+.harper-editor-surface:focus-visible {+ outline: 0;+}++.harper-editor-surface p,+.harper-editor-surface.ql-editor p {+ margin: 0;+ line-height: inherit;+}++.harper-editor-surface p:last-child,+.harper-editor-surface.ql-editor p:last-child {+ margin-bottom: 0;+}diff --git a/packages/harper-editor/src/lib/types.ts b/packages/harper-editor/src/lib/types.tsindex 9784bda0c..e8134a911 100644--- a/packages/harper-editor/src/lib/types.ts+++ b/packages/harper-editor/src/lib/types.ts@@ -1,69 +1,14 @@-import type { Linter, SuggestionKind } from 'harper.js';+export type { Linter as EditorLinter, LintKind } from 'harper.js';-export type EditorLinter = Linter;--export type LintKind =- | 'Agreement'- | 'BoundaryError'- | 'Capitalization'- | 'Eggcorn'- | 'Enhancement'- | 'Formatting'- | 'Grammar'- | 'Malapropism'- | 'Miscellaneous'- | 'Nonstandard'- | 'Punctuation'- | 'Readability'- | 'Redundancy'- | 'Regionalism'- | 'Repetition'- | 'Spelling'- | 'Style'- | 'Typo'- | 'Usage'- | 'WordChoice';--export type UnpackedSpan = {- start: number;- end: number;-};--export type UnpackedSuggestion = {- kind: SuggestionKind;- replacement_text: string;-};--export type UnpackedLint = {- span: UnpackedSpan;- message_html: string;- problem_text: string;- lint_kind: LintKind;- lint_kind_pretty: string;- suggestions: UnpackedSuggestion[];- context_hash: string;- source: string;-};+export type {+ Box,+ IgnorableLintBox,+ LintBox,+ UnpackedLint,+ UnpackedSpan,+ UnpackedSuggestion,+} from 'lint-framework';export type SourceTextNode = {textContent: string | null;};--export type Box = {- x: number;- y: number;- width: number;- height: number;-};--export type LintBox = Box & {- lint: UnpackedLint;- source: SourceTextNode;- range?: Range;- applySuggestion: (sug: UnpackedSuggestion) => void;-};--export type IgnorableLintBox = LintBox & {- rule: string;- ignoreLint?: () => Promise<void>;-};diff --git a/packages/harper.js/src/main.ts b/packages/harper.js/src/main.tsindex 483e5b959..21cf2ff75 100644--- a/packages/harper.js/src/main.ts+++ b/packages/harper.js/src/main.ts@@ -16,6 +16,28 @@ export { packWeirpackFiles, unpackWeirpackBytes } from './weirpack';* This is a record, since you shouldn't hard-code the existence of any particular rules and should generalize based on this struct. */export type LintConfig = Record<string, boolean | null>;+export type LintKind =+ | 'Agreement'+ | 'BoundaryError'+ | 'Capitalization'+ | 'Eggcorn'+ | 'Enhancement'+ | 'Formatting'+ | 'Grammar'+ | 'Malapropism'+ | 'Miscellaneous'+ | 'Nonstandard'+ | 'Punctuation'+ | 'Readability'+ | 'Redundancy'+ | 'Regionalism'+ | 'Repetition'+ | 'Spelling'+ | 'Style'+ | 'Typo'+ | 'Usage'+ | 'WordChoice';+export type StructuredLintSetting =| StructuredLintBoolSetting| StructuredLintOneOfManySettingdiff --git a/packages/lint-framework/src/lint/lintKindColor.ts b/packages/lint-framework/src/lint/lintKindColor.tsindex 49c647497..d0e8d052d 100644--- a/packages/lint-framework/src/lint/lintKindColor.ts+++ b/packages/lint-framework/src/lint/lintKindColor.ts@@ -1,5 +1,8 @@+import type { LintKind } from 'harper.js';import { getContrastingTextColor } from './utils';+export type { LintKind } from 'harper.js';+// First, define the color map as a constantconst LINT_KIND_COLORS = {Agreement: '#228B22', // Forest green@@ -22,10 +25,7 @@ const LINT_KIND_COLORS = {Typo: '#FF6B35', // Vibrant orange-redUsage: '#1E90FF', // Dodger blueWordChoice: '#228B22', // Forest green-} as const;--// Export the type for the lint kind keys-export type LintKind = keyof typeof LINT_KIND_COLORS;+} as const satisfies Record<LintKind, string>;// Export the array of all lint kind namesexport const LINT_KINDS = Object.keys(LINT_KIND_COLORS) as LintKind[];