Phase 7: browser-side spell check (nspell, en-US)
Vendored Hunspell en.aff/en.dic into web/public/dictionaries/en/ (served as a static asset + embedded in the binary, kept out of the JS bundle). dictionary-en moved to a devDep — only used to source the files. - useSpellChecker (App-level, loads once/session): fetches the dict, builds an nspell instance, replays a localStorage personal word list; addWord persists and bumps a version so consumers re-decorate. Ambient types in src/types/nspell.d.ts (the package ships none). - SpellCheck Tiptap extension: misspellings as ProseMirror decorations (no stored marks), recomputed on edit / caret move / checker swap. Latin-only tokenizer so CJK is never flagged; skips short tokens + all-caps acronyms; exempts the caret word to avoid mid-typing jitter. Reuses mapOffset (now exported from SuggestionHighlight); wordAt resolves the exact span on click. - MisspellCard: soft rose wavy underline, bilingual popover with up to 5 nspell corrections (click to replace) + add-to-dictionary. Closes on outside-pointer, edit, or doc switch. Chinese spell check intentionally omitted — nspell is dictionary-based and English-only; Chinese typos (homophone 别字) need an LLM, out of v1 scope. tsc/vite/go build+vet clean; live server serves both dict files; nspell behavior smoke-tested. Claude-Session: https://claude.ai/code/session_016Yr6jELuRc7hyzYLccQKZd
This commit is contained in:
19
web/src/types/nspell.d.ts
vendored
Normal file
19
web/src/types/nspell.d.ts
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// Minimal ambient types for nspell (the package ships no declarations). We use
|
||||
// only the handful of methods the spell checker needs: correctness lookup,
|
||||
// correction suggestions, and adding words to the in-memory personal dictionary.
|
||||
declare module 'nspell' {
|
||||
export interface NSpell {
|
||||
correct(word: string): boolean
|
||||
suggest(word: string): string[]
|
||||
add(word: string, model?: string): NSpell
|
||||
remove(word: string): NSpell
|
||||
}
|
||||
export interface Dictionary {
|
||||
aff: string | Buffer
|
||||
dic: string | Buffer
|
||||
}
|
||||
export default function nspell(
|
||||
aff: string | Buffer | Dictionary,
|
||||
dic?: string | Buffer,
|
||||
): NSpell
|
||||
}
|
||||
Reference in New Issue
Block a user