@type32/codemirror-rich-obsidian-editor 0.0.17 → 0.0.19
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/dist/module.json +1 -1
- package/dist/module.mjs +5 -5
- package/dist/runtime/composables/useAlfaaz.d.ts +8 -0
- package/dist/runtime/composables/useAlfaaz.js +70 -0
- package/dist/runtime/composables/useDocumentUtils.js +5 -4
- package/dist/runtime/editor/types/editor-types.d.ts +2 -0
- package/dist/runtime/utils/languages/burmese.d.ts +6 -0
- package/dist/runtime/utils/languages/burmese.js +1 -0
- package/dist/runtime/utils/languages/cjk.d.ts +6 -0
- package/dist/runtime/utils/languages/cjk.js +34 -0
- package/dist/runtime/utils/languages/index.d.ts +6 -0
- package/dist/runtime/utils/languages/index.js +16 -0
- package/dist/runtime/utils/languages/javanese.d.ts +6 -0
- package/dist/runtime/utils/languages/javanese.js +1 -0
- package/dist/runtime/utils/languages/khmer.d.ts +6 -0
- package/dist/runtime/utils/languages/khmer.js +1 -0
- package/dist/runtime/utils/languages/lao.d.ts +6 -0
- package/dist/runtime/utils/languages/lao.js +1 -0
- package/dist/runtime/utils/languages/thai.d.ts +6 -0
- package/dist/runtime/utils/languages/thai.js +1 -0
- package/dist/runtime/utils/languages/vai.d.ts +6 -0
- package/dist/runtime/utils/languages/vai.js +1 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -9,6 +9,11 @@ const module = defineNuxtModule({
|
|
|
9
9
|
defaults: {},
|
|
10
10
|
setup(_options, _nuxt) {
|
|
11
11
|
const resolver = createResolver(import.meta.url);
|
|
12
|
+
addComponentsDir({
|
|
13
|
+
path: resolver.resolve("runtime/components")
|
|
14
|
+
});
|
|
15
|
+
addImportsDir(resolver.resolve("runtime/composables"));
|
|
16
|
+
addImportsDir(resolver.resolve("runtime/utils"));
|
|
12
17
|
_nuxt.options.build.transpile.push("alfaaz", "js-yaml");
|
|
13
18
|
_nuxt.options.alias["#codemirror-rich-obsidian-editor"] = resolver.resolve(
|
|
14
19
|
"./runtime/editor/types"
|
|
@@ -17,11 +22,6 @@ const module = defineNuxtModule({
|
|
|
17
22
|
"./runtime/assets/css"
|
|
18
23
|
);
|
|
19
24
|
_nuxt.options.css.unshift(resolver.resolve("./runtime/assets/css/editor.css"));
|
|
20
|
-
addComponentsDir({
|
|
21
|
-
path: resolver.resolve("./runtime/components")
|
|
22
|
-
});
|
|
23
|
-
addImportsDir(resolver.resolve("./runtime/composables"));
|
|
24
|
-
addImportsDir(resolver.resolve("./runtime/utils"));
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a port of the code from the Alfaaz library. I DO NOT OWN THIS CODE. ALL CREDIT GOES TO THECODRR.
|
|
3
|
+
* https://github.com/thecodrr/alfaaz
|
|
4
|
+
*/
|
|
5
|
+
export declare function useAlfaaz(): {
|
|
6
|
+
countWords: (str: string) => number;
|
|
7
|
+
countLines: (str: string) => number;
|
|
8
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { UNICODE_RANGES } from "../utils/languages/index.js";
|
|
2
|
+
const CHINESE_MAX_CODE_POINT = 205743;
|
|
3
|
+
const CHINESE_MIN_CODE_POINT = 11904;
|
|
4
|
+
const BYTE_SIZE = 8;
|
|
5
|
+
const BITMAP = new Uint8Array(CHINESE_MAX_CODE_POINT / BYTE_SIZE + 1);
|
|
6
|
+
export function useAlfaaz() {
|
|
7
|
+
function insertCharsIntoMap(...chars) {
|
|
8
|
+
for (const char of chars) {
|
|
9
|
+
const charCode = char.charCodeAt(0);
|
|
10
|
+
const byteIndex = Math.floor(charCode / BYTE_SIZE);
|
|
11
|
+
const bitIndex = charCode % BYTE_SIZE;
|
|
12
|
+
BITMAP[byteIndex] = BITMAP[byteIndex] ^ 1 << bitIndex;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function insertRangeIntoMap(from, to) {
|
|
16
|
+
for (let i = from / BYTE_SIZE; i < Math.ceil(to / BYTE_SIZE); i++) {
|
|
17
|
+
BITMAP[i] = 255;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const NEWLINE = "\n";
|
|
21
|
+
insertCharsIntoMap(
|
|
22
|
+
" ",
|
|
23
|
+
"\n",
|
|
24
|
+
" ",
|
|
25
|
+
"\v",
|
|
26
|
+
"*",
|
|
27
|
+
"/",
|
|
28
|
+
"&",
|
|
29
|
+
":",
|
|
30
|
+
";",
|
|
31
|
+
".",
|
|
32
|
+
",",
|
|
33
|
+
"?",
|
|
34
|
+
"=",
|
|
35
|
+
"\u0F0B",
|
|
36
|
+
// Tibetan uses [U+0F0B TIBETAN MARK INTERSYLLABIC TSHEG] (pronounced tsek) to signal the end of a syllable.
|
|
37
|
+
"\u1361",
|
|
38
|
+
// Ethiopic text uses the traditional wordspace character [U+1361 ETHIOPIC WORDSPACE] to indicate word boundaries
|
|
39
|
+
"\u200B"
|
|
40
|
+
// ZERO-WIDTH-SPACE can also be considered a word boundary
|
|
41
|
+
);
|
|
42
|
+
for (const range of UNICODE_RANGES) {
|
|
43
|
+
insertRangeIntoMap(range[0], range[1]);
|
|
44
|
+
}
|
|
45
|
+
function countWords(str) {
|
|
46
|
+
let count = 0;
|
|
47
|
+
let shouldCount = false;
|
|
48
|
+
for (let i = 0; i < str.length; i++) {
|
|
49
|
+
const charCode = str.charCodeAt(i);
|
|
50
|
+
const byteIndex = charCode / BYTE_SIZE | 0;
|
|
51
|
+
const bitIndex = charCode % BYTE_SIZE;
|
|
52
|
+
const byteAtIndex = BITMAP[byteIndex];
|
|
53
|
+
const isMatch = (byteAtIndex >> bitIndex & 1) === 1;
|
|
54
|
+
if (isMatch && (shouldCount || byteAtIndex === 255)) count++;
|
|
55
|
+
shouldCount = !isMatch;
|
|
56
|
+
}
|
|
57
|
+
if (shouldCount) count++;
|
|
58
|
+
return count;
|
|
59
|
+
}
|
|
60
|
+
function countLines(str) {
|
|
61
|
+
let count = 0;
|
|
62
|
+
for (let i = -1; (i = str.indexOf(NEWLINE, ++i)) !== -1 && i < str.length; count++) ;
|
|
63
|
+
count++;
|
|
64
|
+
return count;
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
countWords,
|
|
68
|
+
countLines
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useAlfaaz } from "./useAlfaaz.js";
|
|
2
2
|
export function useDocumentUtils() {
|
|
3
|
+
const alfaaz = useAlfaaz();
|
|
3
4
|
function getWordCount(text) {
|
|
4
|
-
return countWords(text);
|
|
5
|
+
return alfaaz.countWords(text);
|
|
5
6
|
}
|
|
6
7
|
function getLineCount(text) {
|
|
7
|
-
return countLines(text);
|
|
8
|
+
return alfaaz.countLines(text);
|
|
8
9
|
}
|
|
9
10
|
function getCharacters(text) {
|
|
10
11
|
return text.length;
|
|
11
12
|
}
|
|
12
13
|
function getReadingTime(text, wordsPerMinute = 200) {
|
|
13
|
-
const wordCount = countWords(text);
|
|
14
|
+
const wordCount = alfaaz.countWords(text);
|
|
14
15
|
return Math.ceil(wordCount / wordsPerMinute);
|
|
15
16
|
}
|
|
16
17
|
function getParagraphs(text) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a port of the code from the Alfaaz library. I DO NOT OWN THIS CODE. ALL CREDIT GOES TO THECODRR.
|
|
3
|
+
* https://github.com/thecodrr/alfaaz
|
|
4
|
+
*/
|
|
5
|
+
import type { UnicodeRange } from '../../editor/types/editor-types.js';
|
|
6
|
+
export declare const BURMESE_UNICODE_RANGE: UnicodeRange;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const BURMESE_UNICODE_RANGE = [[4096, 4255]];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a port of the code from the Alfaaz library. I DO NOT OWN THIS CODE. ALL CREDIT GOES TO THECODRR.
|
|
3
|
+
* https://github.com/thecodrr/alfaaz
|
|
4
|
+
*/
|
|
5
|
+
import type { UnicodeRange } from '../../editor/types/editor-types.js';
|
|
6
|
+
export declare const CJK_UNICODE_RANGES: UnicodeRange;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const CJK_UNICODE_RANGES = [
|
|
2
|
+
[19968, 40959],
|
|
3
|
+
// CJK Unified Ideographs 4E00-9FFF Common
|
|
4
|
+
[13312, 19903],
|
|
5
|
+
// CJK Unified Ideographs Extension A 3400-4DBF Rare
|
|
6
|
+
[131072, 173791],
|
|
7
|
+
// CJK Unified Ideographs Extension B 20000-2A6DF Rare, historic
|
|
8
|
+
[173824, 177983],
|
|
9
|
+
// CJK Unified Ideographs Extension C 2A700–2B73F Rare, historic
|
|
10
|
+
[177984, 178207],
|
|
11
|
+
// CJK Unified Ideographs Extension D 2B740–2B81F Uncommon, some in current use
|
|
12
|
+
[178208, 183983],
|
|
13
|
+
// CJK Unified Ideographs Extension E 2B820–2CEAF Rare, historic
|
|
14
|
+
[183984, 191471],
|
|
15
|
+
// CJK Unified Ideographs Extension F 2CEB0–2EBEF Rare, historic
|
|
16
|
+
[196608, 201551],
|
|
17
|
+
// CJK Unified Ideographs Extension G 30000–3134F Rare, historic
|
|
18
|
+
[201552, 205743],
|
|
19
|
+
// CJK Unified Ideographs Extension H 31350–323AF Rare, historic
|
|
20
|
+
[63744, 64255],
|
|
21
|
+
// CJK Compatibility Ideographs F900-FAFF Duplicates, unifiable variants, corporate characters
|
|
22
|
+
[194560, 195103],
|
|
23
|
+
// CJK Compatibility Ideographs Supplement 2F800-2FA1F Unifiable variants
|
|
24
|
+
[12032, 12255],
|
|
25
|
+
// CJK Radicals / Kangxi Radicals 2F00–2FDF
|
|
26
|
+
[11904, 12031],
|
|
27
|
+
// CJK Radicals Supplement 2E80–2EFF
|
|
28
|
+
[12288, 12351],
|
|
29
|
+
// CJK Symbols and Punctuation 3000–303F
|
|
30
|
+
[13056, 13311],
|
|
31
|
+
// CJK Compatibility 3300-33FF
|
|
32
|
+
[65072, 65103]
|
|
33
|
+
// CJK Compatibility Forms FE30-FE4F
|
|
34
|
+
];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a port of the code from the Alfaaz library. I DO NOT OWN THIS CODE. ALL CREDIT GOES TO THECODRR.
|
|
3
|
+
* https://github.com/thecodrr/alfaaz
|
|
4
|
+
*/
|
|
5
|
+
import type { UnicodeRange } from '../../editor/types/editor-types.js';
|
|
6
|
+
export declare const UNICODE_RANGES: UnicodeRange;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BURMESE_UNICODE_RANGE } from "./burmese.js";
|
|
2
|
+
import { CJK_UNICODE_RANGES } from "./cjk.js";
|
|
3
|
+
import { JAVANESE_UNICODE_RANGE } from "./javanese.js";
|
|
4
|
+
import { KHMER_UNICODE_RANGE } from "./khmer.js";
|
|
5
|
+
import { LAO_UNICODE_RANGE } from "./lao.js";
|
|
6
|
+
import { THAI_UNICODE_RANGE } from "./thai.js";
|
|
7
|
+
import { VAI_UNICODE_RANGE } from "./vai.js";
|
|
8
|
+
export const UNICODE_RANGES = [
|
|
9
|
+
...THAI_UNICODE_RANGE,
|
|
10
|
+
...LAO_UNICODE_RANGE,
|
|
11
|
+
...BURMESE_UNICODE_RANGE,
|
|
12
|
+
...KHMER_UNICODE_RANGE,
|
|
13
|
+
...JAVANESE_UNICODE_RANGE,
|
|
14
|
+
...VAI_UNICODE_RANGE,
|
|
15
|
+
...CJK_UNICODE_RANGES
|
|
16
|
+
];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a port of the code from the Alfaaz library. I DO NOT OWN THIS CODE. ALL CREDIT GOES TO THECODRR.
|
|
3
|
+
* https://github.com/thecodrr/alfaaz
|
|
4
|
+
*/
|
|
5
|
+
import type { UnicodeRange } from '../../editor/types/editor-types.js';
|
|
6
|
+
export declare const JAVANESE_UNICODE_RANGE: UnicodeRange;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const JAVANESE_UNICODE_RANGE = [[43392, 43487]];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a port of the code from the Alfaaz library. I DO NOT OWN THIS CODE. ALL CREDIT GOES TO THECODRR.
|
|
3
|
+
* https://github.com/thecodrr/alfaaz
|
|
4
|
+
*/
|
|
5
|
+
import type { UnicodeRange } from '../../editor/types/editor-types.js';
|
|
6
|
+
export declare const KHMER_UNICODE_RANGE: UnicodeRange;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const KHMER_UNICODE_RANGE = [[6016, 6143]];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a port of the code from the Alfaaz library. I DO NOT OWN THIS CODE. ALL CREDIT GOES TO THECODRR.
|
|
3
|
+
* https://github.com/thecodrr/alfaaz
|
|
4
|
+
*/
|
|
5
|
+
import type { UnicodeRange } from '../../editor/types/editor-types.js';
|
|
6
|
+
export declare const LAO_UNICODE_RANGE: UnicodeRange;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const LAO_UNICODE_RANGE = [[3712, 3839]];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a port of the code from the Alfaaz library. I DO NOT OWN THIS CODE. ALL CREDIT GOES TO THECODRR.
|
|
3
|
+
* https://github.com/thecodrr/alfaaz
|
|
4
|
+
*/
|
|
5
|
+
import type { UnicodeRange } from '../../editor/types/editor-types.js';
|
|
6
|
+
export declare const THAI_UNICODE_RANGE: UnicodeRange;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const THAI_UNICODE_RANGE = [[3584, 3711]];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a port of the code from the Alfaaz library. I DO NOT OWN THIS CODE. ALL CREDIT GOES TO THECODRR.
|
|
3
|
+
* https://github.com/thecodrr/alfaaz
|
|
4
|
+
*/
|
|
5
|
+
import type { UnicodeRange } from '../../editor/types/editor-types.js';
|
|
6
|
+
export declare const VAI_UNICODE_RANGE: UnicodeRange;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VAI_UNICODE_RANGE = [[42240, 42559]];
|