@type32/codemirror-rich-obsidian-editor 0.0.18 → 0.0.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.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@type32/codemirror-rich-obsidian-editor",
3
3
  "configKey": "cmOfmEditor",
4
- "version": "0.0.18",
4
+ "version": "0.0.20",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -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,5 +1,6 @@
1
- import * as alfaaz from "alfaaz";
1
+ import { useAlfaaz } from "./useAlfaaz.js";
2
2
  export function useDocumentUtils() {
3
+ const alfaaz = useAlfaaz();
3
4
  function getWordCount(text) {
4
5
  return alfaaz.countWords(text);
5
6
  }
@@ -23,7 +23,7 @@ const revealComponentMarkTokensOnCursor = [
23
23
  // 'LinkMark',
24
24
  ];
25
25
  const hideComponentMarkTokens = [
26
- "HardBreak",
26
+ // 'HardBreak',
27
27
  // 'LinkMark',
28
28
  "EmphasisMark",
29
29
  "CodeMark",
@@ -50,3 +50,5 @@ export type Frontmatter<T extends object = {}> = {
50
50
  slug?: string;
51
51
  [key: string]: any;
52
52
  } & T
53
+
54
+ export type UnicodeRange = number[][]
@@ -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]];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@type32/codemirror-rich-obsidian-editor",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "OFM Editor Component for Nuxt.",
5
5
  "repository": "Type-32/codemirror-rich-obsidian",
6
6
  "license": "MIT",