@inshapardaz/likhari-react 0.1.19-dev.191 → 0.1.20

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.
@@ -1,40 +0,0 @@
1
- /** Languages the spellchecker has a dictionary slot for. */
2
- export type SpellLanguage = 'en' | 'ur' | 'pa-shahmukhi';
3
- /** A Hunspell dictionary as the two text files every Hunspell dictionary ships with. */
4
- export interface HunspellFiles {
5
- /** Affix file: language, encoding, character rules. */
6
- aff: string;
7
- /** Dictionary file: one word per line, with optional affix flags. */
8
- dic: string;
9
- }
10
- export interface Speller {
11
- correct(word: string): boolean;
12
- suggest(word: string): string[];
13
- }
14
- type Loader = () => Promise<HunspellFiles>;
15
- /**
16
- * Registers a dictionary for a language. Call once at startup with files you
17
- * have licence to ship — e.g. the Urdu `.aff`/`.dic` pair — either as strings
18
- * or as a loader that fetches them on demand. Registering again replaces the
19
- * previous dictionary for that language.
20
- */
21
- export declare function registerSpellDictionary(language: SpellLanguage, files: HunspellFiles | Loader): void;
22
- /** Whether a dictionary is registered for the language. */
23
- export declare function hasSpellDictionary(language: SpellLanguage): boolean;
24
- /**
25
- * The speller for a language, loading its dictionary the first time it is
26
- * asked for. Resolves to null when no dictionary is registered, so callers
27
- * can skip spellchecking that language rather than flag every word.
28
- */
29
- export declare function getSpeller(language: SpellLanguage): Promise<Speller> | null;
30
- /** A word in a text, with its position as character offsets. */
31
- export interface WordSpan {
32
- word: string;
33
- start: number;
34
- end: number;
35
- }
36
- export declare function wordsIn(text: string): WordSpan[];
37
- /** The words in `text` the speller does not recognise. */
38
- export declare function misspellingsIn(text: string, speller: Speller): WordSpan[];
39
- export {};
40
- //# sourceMappingURL=spellDictionaries.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spellDictionaries.d.ts","sourceRoot":"","sources":["../../src/spellcheck/spellDictionaries.ts"],"names":[],"mappings":"AAEA,4DAA4D;AAC5D,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,IAAI,GAAG,cAAc,CAAC;AAEzD,wFAAwF;AACxF,MAAM,WAAW,aAAa;IAC5B,uDAAuD;IACvD,GAAG,EAAE,MAAM,CAAC;IACZ,qEAAqE;IACrE,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACjC;AAED,KAAK,MAAM,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,CAAC;AAmB3C;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CAGpG;AAED,2DAA2D;AAC3D,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAEnE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAS3E;AAED,gEAAgE;AAChE,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AASD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,CAMhD;AAED,0DAA0D;AAC1D,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,QAAQ,EAAE,CAEzE"}
@@ -1,62 +0,0 @@
1
- import nspell from 'nspell';
2
- const loaders = new Map();
3
- const spellers = new Map();
4
- async function fetchText(url) {
5
- const response = await fetch(url);
6
- if (!response.ok)
7
- throw new Error(`Spellcheck dictionary failed to load: ${url}`);
8
- return response.text();
9
- }
10
- /** English ships with the editor: its files are fetched on first use. */
11
- const englishLoader = async () => ({
12
- aff: await fetchText(new URL('./dictionaries/en/index.aff', import.meta.url).href),
13
- dic: await fetchText(new URL('./dictionaries/en/index.dic', import.meta.url).href),
14
- });
15
- loaders.set('en', englishLoader);
16
- /**
17
- * Registers a dictionary for a language. Call once at startup with files you
18
- * have licence to ship — e.g. the Urdu `.aff`/`.dic` pair — either as strings
19
- * or as a loader that fetches them on demand. Registering again replaces the
20
- * previous dictionary for that language.
21
- */
22
- export function registerSpellDictionary(language, files) {
23
- loaders.set(language, typeof files === 'function' ? files : async () => files);
24
- spellers.delete(language);
25
- }
26
- /** Whether a dictionary is registered for the language. */
27
- export function hasSpellDictionary(language) {
28
- return loaders.has(language);
29
- }
30
- /**
31
- * The speller for a language, loading its dictionary the first time it is
32
- * asked for. Resolves to null when no dictionary is registered, so callers
33
- * can skip spellchecking that language rather than flag every word.
34
- */
35
- export function getSpeller(language) {
36
- const loader = loaders.get(language);
37
- if (!loader)
38
- return null;
39
- let speller = spellers.get(language);
40
- if (!speller) {
41
- speller = loader().then(({ aff, dic }) => nspell(aff, dic));
42
- spellers.set(language, speller);
43
- }
44
- return speller;
45
- }
46
- /**
47
- * Letters and combining marks, with apostrophes inside a word kept. The
48
- * Unicode classes cover Arabic-script letters and their diacritics, so Urdu
49
- * and Shahmukhi words are found the same way English ones are.
50
- */
51
- const WORD = /[\p{L}\p{M}]+(?:['’][\p{L}\p{M}]+)*/gu;
52
- export function wordsIn(text) {
53
- return [...text.matchAll(WORD)].map((match) => ({
54
- word: match[0],
55
- start: match.index ?? 0,
56
- end: (match.index ?? 0) + match[0].length,
57
- }));
58
- }
59
- /** The words in `text` the speller does not recognise. */
60
- export function misspellingsIn(text, speller) {
61
- return wordsIn(text).filter((span) => !speller.correct(span.word));
62
- }
@@ -1,21 +0,0 @@
1
- import { type FindMatch } from '../find/findReplaceActions.js';
2
- import { type Speller } from './spellDictionaries.js';
3
- /** The checker for each text direction: English for LTR blocks, Urdu for RTL. */
4
- export interface Checkers {
5
- ltr?: Speller;
6
- rtl?: Speller;
7
- }
8
- /** The part of a misspelled word that falls inside one text node. */
9
- export interface Segment {
10
- key: string;
11
- start: number;
12
- end: number;
13
- }
14
- export interface Misspelling {
15
- word: string;
16
- match: FindMatch;
17
- segments: Segment[];
18
- }
19
- /** Every word in the document its block's checker does not recognise. */
20
- export declare function $collectMisspellings(checkers: Checkers): Misspelling[];
21
- //# sourceMappingURL=spellcheckActions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spellcheckActions.d.ts","sourceRoot":"","sources":["../../src/spellcheck/spellcheckActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAClF,OAAO,EAAW,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE5D,iFAAiF;AACjF,MAAM,WAAW,QAAQ;IACvB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,qEAAqE;AACrE,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,yEAAyE;AACzE,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,WAAW,EAAE,CAmBtE"}
@@ -1,38 +0,0 @@
1
- import { $textGroups, $locate } from '../find/findReplaceActions.js';
2
- import { wordsIn } from './spellDictionaries.js';
3
- /** Every word in the document its block's checker does not recognise. */
4
- export function $collectMisspellings(checkers) {
5
- const found = [];
6
- for (const group of $textGroups()) {
7
- const direction = group[0].getParentOrThrow().getDirection();
8
- const speller = direction === 'rtl' ? checkers.rtl : checkers.ltr;
9
- if (!speller)
10
- continue;
11
- const text = group.map((node) => node.getTextContent()).join('');
12
- for (const span of wordsIn(text)) {
13
- if (speller.correct(span.word))
14
- continue;
15
- const start = $locate(group, span.start, false);
16
- const end = $locate(group, span.end, true);
17
- found.push({
18
- word: span.word,
19
- match: { anchorKey: start.key, anchorOffset: start.offset, focusKey: end.key, focusOffset: end.offset },
20
- segments: segmentsOf(group, span.start, span.end),
21
- });
22
- }
23
- }
24
- return found;
25
- }
26
- function segmentsOf(group, start, end) {
27
- const segments = [];
28
- let offset = 0;
29
- for (const node of group) {
30
- const length = node.getTextContent().length;
31
- const from = Math.max(start, offset);
32
- const to = Math.min(end, offset + length);
33
- if (to > from)
34
- segments.push({ key: node.getKey(), start: from - offset, end: to - offset });
35
- offset += length;
36
- }
37
- return segments;
38
- }