lipilekhika 0.0.0-alpha.21 → 0.0.0-alpha.22
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/cjs/Assamese-Dv2Uz5Ga.cjs +1 -0
- package/dist/cjs/Bengali-CP-jqwb3.cjs +1 -0
- package/dist/cjs/Brahmi-BOnETq6u.cjs +1 -0
- package/dist/cjs/Devanagari-DogoRXY8.cjs +1 -0
- package/dist/cjs/Granth-9Z5eCctH.cjs +1 -0
- package/dist/cjs/Gujarati-CUm-ZsKN.cjs +1 -0
- package/dist/cjs/Gurumukhi-CsObr-GI.cjs +1 -0
- package/dist/cjs/Kannada-SXQdSng_.cjs +1 -0
- package/dist/cjs/Malayalam-IcKWWsaB.cjs +1 -0
- package/dist/cjs/Modi-C3Chvoab.cjs +1 -0
- package/dist/cjs/Normal-BZe6xAux.cjs +1 -0
- package/dist/cjs/Odia-C_-bjsx6.cjs +1 -0
- package/dist/cjs/Purna-Devanagari-BkPRDmig.cjs +1 -0
- package/dist/cjs/Romanized-B_o6BaP0.cjs +1 -0
- package/dist/cjs/Sharada-DfQQFnhQ.cjs +1 -0
- package/dist/cjs/Siddham-D4xax5q5.cjs +1 -0
- package/dist/cjs/Sinhala-oz5fU6-H.cjs +1 -0
- package/dist/cjs/Tamil-Extended-Bg0_zDSf.cjs +1 -0
- package/dist/cjs/Tamil-pc27DGFa.cjs +1 -0
- package/dist/cjs/Telugu-C9jvVXuj.cjs +1 -0
- package/dist/cjs/index.cjs +2 -0
- package/dist/esm/Assamese-C2ZNJvdv.js +25 -0
- package/dist/esm/Bengali-B4lwiGw-.js +25 -0
- package/dist/esm/Brahmi-P_BhbEU1.js +23 -0
- package/dist/esm/Devanagari-CU6oiaDU.js +25 -0
- package/dist/esm/Granth-v69SsV6n.js +25 -0
- package/dist/esm/Gujarati-GMDcD3zf.js +25 -0
- package/dist/esm/Gurumukhi-cSQGlqXa.js +25 -0
- package/dist/esm/Kannada-BC0s2WZG.js +25 -0
- package/dist/esm/Malayalam-R6qN3iwf.js +23 -0
- package/dist/esm/Modi-B8YiZBXf.js +23 -0
- package/dist/esm/Normal-DH6dfVGR.js +21 -0
- package/dist/esm/Odia-DphK-sRO.js +25 -0
- package/dist/esm/Purna-Devanagari-iW765mfa.js +25 -0
- package/dist/esm/Romanized-BQU9AmMX.js +21 -0
- package/dist/esm/Sharada-DOmuoJ5u.js +25 -0
- package/dist/esm/Siddham-CZ7F2rJg.js +25 -0
- package/dist/esm/Sinhala-BKPrzGBh.js +23 -0
- package/dist/esm/Tamil-B_Q1LP6g.js +23 -0
- package/dist/esm/Tamil-Extended-8h88s1_g.js +23 -0
- package/dist/esm/Telugu-w-eiYYTU.js +23 -0
- package/dist/esm/index.mjs +764 -0
- package/dist/index.d.ts +668 -0
- package/dist/lipilekhika.umd.js +1 -1
- package/dist/tsdoc-metadata.json +11 -0
- package/package.json +1 -1
- package/dist/types/src/custom_options.json.d.ts +0 -220
- package/dist/types/src/index.d.ts +0 -100
- package/dist/types/src/make_script_data/custom_options_input.d.ts +0 -62
- package/dist/types/src/make_script_data/input_data/Assamese.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Bengali.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Brahmi.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Devanagari.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Granth.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Gujarati.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Gurumukhi.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Kannada.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Malayalam.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Modi.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Normal.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Odia.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Purna-Devanagari.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Romanized.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Sharada.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Siddham.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Sinhala.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Tamil-Extended.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Tamil.d.ts +0 -3
- package/dist/types/src/make_script_data/input_data/Telugu.d.ts +0 -3
- package/dist/types/src/make_script_data/input_script_data_schema.d.ts +0 -91
- package/dist/types/src/make_script_data/krama_array_keys.d.ts +0 -145
- package/dist/types/src/make_script_data/make_output_script_data.d.ts +0 -1
- package/dist/types/src/make_script_data/output_script_data_schema.d.ts +0 -46
- package/dist/types/src/tools/kry.d.ts +0 -18
- package/dist/types/src/transliteration/a.d.ts +0 -1
- package/dist/types/src/transliteration/active_option_resolver.test.d.ts +0 -1
- package/dist/types/src/transliteration/context_clear.test.d.ts +0 -1
- package/dist/types/src/transliteration/emulate_typing.test.d.ts +0 -1
- package/dist/types/src/transliteration/helpers.d.ts +0 -90
- package/dist/types/src/transliteration/test_commons.d.ts +0 -13
- package/dist/types/src/transliteration/transliterate.d.ts +0 -47
- package/dist/types/src/transliteration/transliterate.test.d.ts +0 -2
- package/dist/types/src/utils/binary_search/binary_search.d.ts +0 -25
- package/dist/types/src/utils/binary_search/binary_search.test.d.ts +0 -1
- package/dist/types/src/utils/get_script_data.d.ts +0 -8
- package/dist/types/src/utils/lang_list/index.d.ts +0 -50
- package/dist/types/src/utils/lang_list/langs.json.d.ts +0 -44
- package/dist/types/src/utils/lang_list/script_normalization.d.ts +0 -6
- package/dist/types/src/utils/lang_list/script_normalization.test.d.ts +0 -1
- package/dist/types/src/utils/non_bmp.d.ts +0 -3
- package/dist/types/src/utils/runtime_macros.d.ts +0 -5
|
@@ -0,0 +1,764 @@
|
|
|
1
|
+
function V(t, e, r, n) {
|
|
2
|
+
const { accessor: a, compareFn: s } = n ?? {}, o = a ?? ((i, l) => i[l]);
|
|
3
|
+
let u = 0, _ = e.length - 1, c = -1;
|
|
4
|
+
for (; u <= _; ) {
|
|
5
|
+
const i = Math.floor((u + _) / 2), l = e[i], p = o(t, l);
|
|
6
|
+
let h;
|
|
7
|
+
s ? h = s(r, p) : h = r < p ? -1 : r > p ? 1 : 0, h === 0 ? (c = l, _ = i - 1) : h < 0 ? _ = i - 1 : u = i + 1;
|
|
8
|
+
}
|
|
9
|
+
return c;
|
|
10
|
+
}
|
|
11
|
+
function ae(t, e, r) {
|
|
12
|
+
const { accessor: n, compareFn: a } = r ?? {}, s = n ?? ((c, i) => c[i]);
|
|
13
|
+
let o = 0, u = t.length - 1, _ = -1;
|
|
14
|
+
for (; o <= u; ) {
|
|
15
|
+
const c = Math.floor((o + u) / 2), i = s(t, c);
|
|
16
|
+
let l;
|
|
17
|
+
a ? l = a(e, i) : l = e < i ? -1 : e > i ? 1 : 0, l === 0 ? (_ = c, u = c - 1) : l < 0 ? u = c - 1 : o = c + 1;
|
|
18
|
+
}
|
|
19
|
+
return _;
|
|
20
|
+
}
|
|
21
|
+
const ge = (t, e, r) => {
|
|
22
|
+
const n = t[e];
|
|
23
|
+
return n ? typeof n == "function" ? n() : Promise.resolve(n) : new Promise((a, s) => {
|
|
24
|
+
(typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(s.bind(null, /* @__PURE__ */ new Error("Unknown variable dynamic import: " + e + (e.split("/").length !== r ? ". Note that variables only represent file names one level deep." : ""))));
|
|
25
|
+
});
|
|
26
|
+
}, re = {}, R = async (t) => (re[t] || (re[t] = ge(/* @__PURE__ */ Object.assign({ "../script_data/Assamese.json": () => import("./Assamese-C2ZNJvdv.js"), "../script_data/Bengali.json": () => import("./Bengali-B4lwiGw-.js"), "../script_data/Brahmi.json": () => import("./Brahmi-P_BhbEU1.js"), "../script_data/Devanagari.json": () => import("./Devanagari-CU6oiaDU.js"), "../script_data/Granth.json": () => import("./Granth-v69SsV6n.js"), "../script_data/Gujarati.json": () => import("./Gujarati-GMDcD3zf.js"), "../script_data/Gurumukhi.json": () => import("./Gurumukhi-cSQGlqXa.js"), "../script_data/Kannada.json": () => import("./Kannada-BC0s2WZG.js"), "../script_data/Malayalam.json": () => import("./Malayalam-R6qN3iwf.js"), "../script_data/Modi.json": () => import("./Modi-B8YiZBXf.js"), "../script_data/Normal.json": () => import("./Normal-DH6dfVGR.js"), "../script_data/Odia.json": () => import("./Odia-DphK-sRO.js"), "../script_data/Purna-Devanagari.json": () => import("./Purna-Devanagari-iW765mfa.js"), "../script_data/Romanized.json": () => import("./Romanized-BQU9AmMX.js"), "../script_data/Sharada.json": () => import("./Sharada-DOmuoJ5u.js"), "../script_data/Siddham.json": () => import("./Siddham-CZ7F2rJg.js"), "../script_data/Sinhala.json": () => import("./Sinhala-BKPrzGBh.js"), "../script_data/Tamil-Extended.json": () => import("./Tamil-Extended-8h88s1_g.js"), "../script_data/Tamil.json": () => import("./Tamil-B_Q1LP6g.js"), "../script_data/Telugu.json": () => import("./Telugu-w-eiYYTU.js") }), `../script_data/${t}.json`, 3).then(
|
|
27
|
+
(e) => e.default
|
|
28
|
+
)), re[t]), Y = {
|
|
29
|
+
"all_to_normal:replace_pancham_varga_varna_with_n": { from_script_type: "all", to_script_name: ["Normal"], check_in: "output", rules: [{ type: "replace_prev_krama_keys", check_in: "output", prev: [60], following: [52, 53, 54, 55, 56, 57, 58, 59], replace_with: [72] }, { type: "replace_prev_krama_keys", check_in: "output", prev: [67], following: [61, 62, 63, 64, 65, 66], replace_with: [72] }] },
|
|
30
|
+
"brahmic_to_brahmic:replace_pancham_varga_varna_with_anuvsvAra": { from_script_type: "brahmic", to_script_type: "brahmic", check_in: "input", rules: [{ type: "replace_prev_krama_keys", check_in: "input", prev: [60, 49], following: [52, 53, 54, 55, 56, 57, 58, 59], replace_with: [45] }, { type: "replace_prev_krama_keys", check_in: "input", prev: [67, 49], following: [61, 62, 63, 64, 65, 66], replace_with: [45] }, { type: "replace_prev_krama_keys", check_in: "input", prev: [81, 49], following: [74, 75, 76, 77, 78, 79, 80], replace_with: [45] }, { type: "replace_prev_krama_keys", check_in: "input", prev: [72, 49], following: [68, 69, 70, 71], replace_with: [45] }, { type: "replace_prev_krama_keys", check_in: "input", prev: [88, 49], following: [82, 83, 85, 86, 87], replace_with: [45] }] },
|
|
31
|
+
"all_to_sinhala:use_conjuct_enabling_halant": { from_script_type: "all", to_script_name: ["Sinhala"], check_in: "output", rules: [{ type: "direct_replace", check_in: "output", to_replace: [[49]], replace_text: "්", replace_with: [] }] },
|
|
32
|
+
"all_to_normal:remove_virAma_and_double_virAma": { from_script_type: "all", to_script_name: ["Normal", "Romanized"], check_in: "output", rules: [{ type: "direct_replace", check_in: "output", to_replace: [[116], [115]], replace_with: [-1] }] },
|
|
33
|
+
"all_to_normal:replace_avagraha_with_a": { from_script_type: "all", to_script_name: ["Normal", "Romanized"], check_in: "output", rules: [{ type: "direct_replace", check_in: "output", to_replace: [[48]], replace_with: [1] }] }
|
|
34
|
+
}, ve = (t, e) => {
|
|
35
|
+
const r = t.krama_text_arr[e]?.[0];
|
|
36
|
+
return typeof r == "string" ? r : null;
|
|
37
|
+
}, L = (t, e) => ve(t, e) ?? "", J = (t, e) => V(
|
|
38
|
+
t.krama_text_arr,
|
|
39
|
+
t.krama_text_arr_index,
|
|
40
|
+
e,
|
|
41
|
+
{
|
|
42
|
+
accessor: (r, n) => r[n][0]
|
|
43
|
+
}
|
|
44
|
+
), xe = () => {
|
|
45
|
+
let t = [];
|
|
46
|
+
function e(i) {
|
|
47
|
+
i && t.push(i);
|
|
48
|
+
}
|
|
49
|
+
function r(i) {
|
|
50
|
+
for (const l of i) e(l);
|
|
51
|
+
}
|
|
52
|
+
function n() {
|
|
53
|
+
return t.at(-1);
|
|
54
|
+
}
|
|
55
|
+
function a() {
|
|
56
|
+
return n()?.at(-1);
|
|
57
|
+
}
|
|
58
|
+
function s() {
|
|
59
|
+
const i = n();
|
|
60
|
+
if (!i) return;
|
|
61
|
+
const l = i.at(-1), p = i.slice(0, -1);
|
|
62
|
+
return p ? t[t.length - 1] = p : t.pop(), l;
|
|
63
|
+
}
|
|
64
|
+
function o(i, l) {
|
|
65
|
+
t.splice(-i, i, ...l.filter(Boolean));
|
|
66
|
+
}
|
|
67
|
+
function u(i, l) {
|
|
68
|
+
const p = s();
|
|
69
|
+
if (!p) {
|
|
70
|
+
r(i), r(l);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
r(i), e(p), r(l);
|
|
74
|
+
}
|
|
75
|
+
function _(i) {
|
|
76
|
+
const l = t.at(i);
|
|
77
|
+
return l ? {
|
|
78
|
+
cp: i,
|
|
79
|
+
ch: l,
|
|
80
|
+
width: l.length
|
|
81
|
+
} : null;
|
|
82
|
+
}
|
|
83
|
+
function c(i, l) {
|
|
84
|
+
i < 0 && (i = t.length + i), !(i < 0 || i >= t.length) && (t[i] = l);
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
emit: e,
|
|
88
|
+
emitPieces: r,
|
|
89
|
+
lastPiece: n,
|
|
90
|
+
lastChar: a,
|
|
91
|
+
popLastChar: s,
|
|
92
|
+
rewriteTailPieces: o,
|
|
93
|
+
withLastCharMovedAfter: u,
|
|
94
|
+
toString: () => t.join(""),
|
|
95
|
+
rewriteAt: c,
|
|
96
|
+
peekAt: _
|
|
97
|
+
};
|
|
98
|
+
}, we = (t) => {
|
|
99
|
+
let e = [];
|
|
100
|
+
function r() {
|
|
101
|
+
e = [];
|
|
102
|
+
}
|
|
103
|
+
function n() {
|
|
104
|
+
return e.length;
|
|
105
|
+
}
|
|
106
|
+
function a(p) {
|
|
107
|
+
return e.at(p);
|
|
108
|
+
}
|
|
109
|
+
function s() {
|
|
110
|
+
return e.at(-1);
|
|
111
|
+
}
|
|
112
|
+
function o() {
|
|
113
|
+
return s()?.[0];
|
|
114
|
+
}
|
|
115
|
+
function u() {
|
|
116
|
+
return s()?.[1]?.type;
|
|
117
|
+
}
|
|
118
|
+
function _(p) {
|
|
119
|
+
return a(p)?.[1]?.type;
|
|
120
|
+
}
|
|
121
|
+
function c(p) {
|
|
122
|
+
return a(p)?.[0];
|
|
123
|
+
}
|
|
124
|
+
function i(p) {
|
|
125
|
+
return u() === p;
|
|
126
|
+
}
|
|
127
|
+
function l(p) {
|
|
128
|
+
const h = p[0];
|
|
129
|
+
h !== void 0 && h.length > 0 && e.push(p), e.length > t && e.shift();
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
clear: r,
|
|
133
|
+
length: n,
|
|
134
|
+
at: a,
|
|
135
|
+
last: s,
|
|
136
|
+
lastText: o,
|
|
137
|
+
lastType: u,
|
|
138
|
+
typeAt: _,
|
|
139
|
+
textAt: c,
|
|
140
|
+
isLastType: i,
|
|
141
|
+
push: l
|
|
142
|
+
};
|
|
143
|
+
}, Ae = (t) => {
|
|
144
|
+
let e = 0;
|
|
145
|
+
function r(u) {
|
|
146
|
+
const _ = t.codePointAt(u);
|
|
147
|
+
if (_ === void 0) return null;
|
|
148
|
+
const c = String.fromCodePoint(_);
|
|
149
|
+
return { cp: _, ch: c, width: c.length };
|
|
150
|
+
}
|
|
151
|
+
function n() {
|
|
152
|
+
return r(e);
|
|
153
|
+
}
|
|
154
|
+
function a(u) {
|
|
155
|
+
return r(e + u);
|
|
156
|
+
}
|
|
157
|
+
function s(u) {
|
|
158
|
+
e += u;
|
|
159
|
+
}
|
|
160
|
+
function o(u, _) {
|
|
161
|
+
return t.substring(u, _);
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
get pos() {
|
|
165
|
+
return e;
|
|
166
|
+
},
|
|
167
|
+
peek: n,
|
|
168
|
+
peekAt: r,
|
|
169
|
+
peekAtOffsetUnits: a,
|
|
170
|
+
advance: s,
|
|
171
|
+
slice: o
|
|
172
|
+
};
|
|
173
|
+
}, ie = (t, e, r, n) => {
|
|
174
|
+
for (let a = 0; a < r.length; a++) {
|
|
175
|
+
const s = r[r.length - 1 - a], o = t(e - a);
|
|
176
|
+
if (o === null) return { matched: !1, matchedLen: 0 };
|
|
177
|
+
const u = J(n, o.ch);
|
|
178
|
+
if (u === -1 || u !== s)
|
|
179
|
+
return { matched: !1, matchedLen: 0 };
|
|
180
|
+
}
|
|
181
|
+
return { matched: !0, matchedLen: r.length };
|
|
182
|
+
}, le = (t, e) => t.map((r) => L(e, r)).filter(Boolean), be = ["²", "³", "⁴"], O = (t) => !!t && be.indexOf(
|
|
183
|
+
t
|
|
184
|
+
) !== -1, I = (t) => t === "Tamil-Extended", K = (t, e, r, n) => {
|
|
185
|
+
if (e.length === 0) return;
|
|
186
|
+
if (!n) {
|
|
187
|
+
t.emitPieces(e);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const a = e[0] ?? "";
|
|
191
|
+
if (a[0] === r) {
|
|
192
|
+
const s = a.slice(1), o = [];
|
|
193
|
+
s && o.push(s);
|
|
194
|
+
for (let u = 1; u < e.length; u++) o.push(e[u]);
|
|
195
|
+
t.withLastCharMovedAfter([r], o);
|
|
196
|
+
} else
|
|
197
|
+
t.withLastCharMovedAfter(e, []);
|
|
198
|
+
}, Te = [" ", `
|
|
199
|
+
`, "\r", " ", ",", ";", "!", "@", "?", "%"], je = 3;
|
|
200
|
+
function T(t, e, r) {
|
|
201
|
+
const {
|
|
202
|
+
from_script_name: n,
|
|
203
|
+
to_script_name: a,
|
|
204
|
+
from_script_data: s,
|
|
205
|
+
to_script_data: o,
|
|
206
|
+
trans_options: u,
|
|
207
|
+
result: _,
|
|
208
|
+
prev_context: c,
|
|
209
|
+
BRAHMIC_HALANT: i,
|
|
210
|
+
BRAHMIC_NUQTA: l,
|
|
211
|
+
typing_mode: p
|
|
212
|
+
} = t, { next: h, last_extra_call: k } = r ?? {};
|
|
213
|
+
let g = !1;
|
|
214
|
+
if (
|
|
215
|
+
// vyanjana, nuqta, svara
|
|
216
|
+
(l && c.typeAt(-3) === "vyanjana" && c.textAt(-2) === l && c.typeAt(-1) === "mAtrA" || // or vyanjana, svara
|
|
217
|
+
c.typeAt(-2) === "vyanjana" && c.typeAt(-1) === "mAtrA") && // to anya or null
|
|
218
|
+
(!e || e[1]?.type === "anya") && c.clear(), s.script_type === "brahmic" && o.script_type === "other"
|
|
219
|
+
)
|
|
220
|
+
e[0] !== i && (!(I(n) && e[0] && e[0].length > 0) || e[0].charAt(0) !== i) && // (BRAHMIC_NUQTA ? item[0] !== BRAHMIC_NUQTA : true) &&
|
|
221
|
+
(!l || e[0] !== l) && // ^ two special cases to ignore
|
|
222
|
+
// vyanjana or vyanjana, nuqta
|
|
223
|
+
(c.typeAt(-1) === "vyanjana" || l && c.typeAt(-2) === "vyanjana" && c.textAt(-1) === l) && // to anya or null
|
|
224
|
+
(e[1]?.type !== "mAtrA" && e[0] !== i || e[1]?.type === "anya" || e[1] === null || e[1] === void 0) && _.emit(o.schwa_character);
|
|
225
|
+
else if (s.script_type === "other" && o.script_type === "brahmic")
|
|
226
|
+
if (c.typeAt(-1) === "vyanjana" && (e[1]?.type === "mAtrA" || e[1]?.type === "svara")) {
|
|
227
|
+
const d = e[1].type === "svara" ? L(o, e[1].mAtrA_krama_ref?.[0] ?? -1) : e[0];
|
|
228
|
+
I(a) && O(_.lastChar()) ? K(_, [d], o.halant, !0) : K(
|
|
229
|
+
_,
|
|
230
|
+
[d],
|
|
231
|
+
o.halant,
|
|
232
|
+
!1
|
|
233
|
+
), g = !0;
|
|
234
|
+
} else c.typeAt(-1) === "vyanjana" && !(e[0] === i || e[1]?.type === "mAtrA") && (I(a) && O(_.lastChar()) ? K(
|
|
235
|
+
_,
|
|
236
|
+
[i],
|
|
237
|
+
o.halant,
|
|
238
|
+
!0
|
|
239
|
+
) : (K(
|
|
240
|
+
_,
|
|
241
|
+
[i],
|
|
242
|
+
o.halant,
|
|
243
|
+
!1
|
|
244
|
+
), a === "Sinhala" && u["all_to_sinhala:use_conjuct_enabling_halant"] && _.rewriteAt(-1, _.lastPiece() + "")));
|
|
245
|
+
let f = !1;
|
|
246
|
+
return p && (h === void 0 || h.length === 0) && !k && (f = !0, e[1]?.type === "vyanjana" && (f = !1), f && c.clear()), (!p || !k && !f) && c.push(e), g;
|
|
247
|
+
}
|
|
248
|
+
function ce(t, e, r) {
|
|
249
|
+
const { custom_rules: n, cursor: a, result: s, from_script_data: o, to_script_data: u } = t, _ = e + r;
|
|
250
|
+
for (let c = 0; c < n.length; c++) {
|
|
251
|
+
if (n[c].use_replace === !0) continue;
|
|
252
|
+
const i = n[c];
|
|
253
|
+
if (i.type === "replace_prev_krama_keys") {
|
|
254
|
+
if (i.check_in === "input") {
|
|
255
|
+
const l = ie(
|
|
256
|
+
a.peekAt,
|
|
257
|
+
_,
|
|
258
|
+
i.prev,
|
|
259
|
+
o
|
|
260
|
+
), p = a.peekAt(e);
|
|
261
|
+
if (l.matched && p !== null) {
|
|
262
|
+
const h = p.ch, k = J(o, h);
|
|
263
|
+
if (k !== -1 && i.following.indexOf(k) !== -1) {
|
|
264
|
+
const g = le(i.replace_with, u);
|
|
265
|
+
s.rewriteTailPieces(l.matchedLen, g);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
} else if (i.check_in === "output") {
|
|
269
|
+
const l = s.lastPiece();
|
|
270
|
+
if (!l) continue;
|
|
271
|
+
const p = J(u, l);
|
|
272
|
+
if (p !== -1 && i.following.indexOf(p) !== -1) {
|
|
273
|
+
const h = ie(s.peekAt, -2, i.prev, u);
|
|
274
|
+
if (h.matched) {
|
|
275
|
+
const k = le(i.replace_with, u);
|
|
276
|
+
s.rewriteTailPieces(h.matchedLen + 1, [
|
|
277
|
+
...k,
|
|
278
|
+
l
|
|
279
|
+
]);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
} else if (i.type === "direct_replace") {
|
|
284
|
+
const l = i.check_in === "output" ? u : o;
|
|
285
|
+
for (const p of i.to_replace) {
|
|
286
|
+
const h = ie(s.peekAt, -1, p, l);
|
|
287
|
+
if (!h.matched) continue;
|
|
288
|
+
if (i.replace_text) {
|
|
289
|
+
s.rewriteTailPieces(h.matchedLen, [i.replace_text]);
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
const k = le(i.replace_with, l);
|
|
293
|
+
s.rewriteTailPieces(h.matchedLen, k);
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const pe = (t, e, r) => {
|
|
300
|
+
if (!r) return {};
|
|
301
|
+
const n = {};
|
|
302
|
+
for (const [a, s] of Object.entries(r ?? {})) {
|
|
303
|
+
if (!s || !(a in Y)) continue;
|
|
304
|
+
const o = Y[a];
|
|
305
|
+
(o.from_script_type !== void 0 && (o.from_script_type === "all" || o.from_script_type === t.script_type) || o.from_script_name !== void 0 && o.from_script_name.includes(t.script_name)) && (o.to_script_type !== void 0 && (o.to_script_type === "all" || o.to_script_type === e.script_type) || o.to_script_name !== void 0 && o.to_script_name.includes(e.script_name)) && (n[a] = !0);
|
|
306
|
+
}
|
|
307
|
+
return n;
|
|
308
|
+
}, he = (t, e, r) => {
|
|
309
|
+
const n = pe(
|
|
310
|
+
t,
|
|
311
|
+
e,
|
|
312
|
+
r
|
|
313
|
+
), a = Object.keys(n).flatMap(
|
|
314
|
+
(s) => Y[s].rules
|
|
315
|
+
);
|
|
316
|
+
return { trans_options: n, custom_rules: a };
|
|
317
|
+
}, se = (t, e) => t.replace_with.map((r) => L(e, r)).join(""), ue = (t, e, r, n) => {
|
|
318
|
+
if (r.length === 0) return t;
|
|
319
|
+
for (const a of r)
|
|
320
|
+
if (!(a.use_replace !== !0 || a.check_in !== n)) {
|
|
321
|
+
if (a.type === "replace_prev_krama_keys") {
|
|
322
|
+
const s = a.prev.map((o) => L(e, o)).join("");
|
|
323
|
+
for (let o of a.following) {
|
|
324
|
+
const u = L(e, o);
|
|
325
|
+
if (!u) continue;
|
|
326
|
+
const _ = se(a, e) + u;
|
|
327
|
+
t = t.replaceAll(s + u, _);
|
|
328
|
+
}
|
|
329
|
+
} else if (a.type === "direct_replace") {
|
|
330
|
+
const s = a.to_replace.map(
|
|
331
|
+
(o) => o.map((u) => L(e, u)).join("")
|
|
332
|
+
);
|
|
333
|
+
for (let o of s)
|
|
334
|
+
t = t.replaceAll(o, se(a, e));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return t;
|
|
338
|
+
}, me = (t, e, r, n, a, s, o, u) => {
|
|
339
|
+
const _ = u?.typing_mode ?? !1;
|
|
340
|
+
if (_ && e !== "Normal")
|
|
341
|
+
throw new Error("Typing mode is only supported with Normal script as the input");
|
|
342
|
+
t = ue(t, n, o, "input");
|
|
343
|
+
const c = xe();
|
|
344
|
+
let i = 0;
|
|
345
|
+
const l = Ae(t), p = we(je), h = n.script_type === "brahmic" && a.script_type === "other" || n.script_type === "other" && a.script_type === "brahmic" || _ && e === "Normal" && a.script_type === "other", k = n.script_type === "brahmic" && a.script_type === "other" ? n.nuqta ?? null : n.script_type === "other" && a.script_type === "brahmic" ? a.nuqta ?? null : null, g = n.script_type === "brahmic" && a.script_type === "other" ? n.halant : n.script_type === "other" && a.script_type === "brahmic" ? a.halant : null, f = {
|
|
346
|
+
from_script_name: e,
|
|
347
|
+
to_script_name: r,
|
|
348
|
+
from_script_data: n,
|
|
349
|
+
to_script_data: a,
|
|
350
|
+
trans_options: s,
|
|
351
|
+
custom_rules: o,
|
|
352
|
+
cursor: l,
|
|
353
|
+
result: c,
|
|
354
|
+
prev_context: p,
|
|
355
|
+
BRAHMIC_NUQTA: k,
|
|
356
|
+
BRAHMIC_HALANT: g,
|
|
357
|
+
typing_mode: _
|
|
358
|
+
};
|
|
359
|
+
let d = -1;
|
|
360
|
+
for (; l.pos < t.length; ) {
|
|
361
|
+
i = l.pos;
|
|
362
|
+
const Z = l.peek();
|
|
363
|
+
if (!Z) break;
|
|
364
|
+
const ee = Z.ch, B = Z.width, oe = B === 2 ? 1 : B;
|
|
365
|
+
if (d !== -1 && i >= d) {
|
|
366
|
+
d = -1, l.advance(B);
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (Te.indexOf(ee) !== -1) {
|
|
370
|
+
l.advance(B), h && (T(f, [" ", null]), p.clear()), c.emit(ee);
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
let D = -1;
|
|
374
|
+
{
|
|
375
|
+
let b = 0, G = -1;
|
|
376
|
+
const j = h && n.script_type === "other" && a.script_type === "brahmic" && (p.typeAt(-1) === "vyanjana" || k && p.typeAt(-2) === "vyanjana" && p.textAt(-1) === k);
|
|
377
|
+
for (; ; ) {
|
|
378
|
+
const Q = l.peekAt(i + oe + b), N = Q?.ch ?? "";
|
|
379
|
+
d !== -1 && N && O(N) && (b += Q?.width ?? 0);
|
|
380
|
+
const y = i + oe + b, A = (
|
|
381
|
+
// usage example: க்⁴ரு² -> ghR
|
|
382
|
+
d !== -1 ? (
|
|
383
|
+
// in this we will ignore the current charcter and scan one ahead
|
|
384
|
+
l.slice(i, d) + (y > d ? l.slice(d + 1, y) : "")
|
|
385
|
+
) : l.slice(i, y)
|
|
386
|
+
), v = ae(
|
|
387
|
+
n.text_to_krama_map,
|
|
388
|
+
A,
|
|
389
|
+
{
|
|
390
|
+
accessor: (x, E) => x[E][0]
|
|
391
|
+
}
|
|
392
|
+
);
|
|
393
|
+
if (v === -1) {
|
|
394
|
+
D = -1;
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
const P = n.text_to_krama_map[v];
|
|
398
|
+
if (j && P[1].krama && P[1].krama.length >= 1) {
|
|
399
|
+
const x = P[1].krama, E = x[0], S = a.krama_text_arr[E]?.[1], ne = a.list[S ?? -1]?.type;
|
|
400
|
+
if (x.length === 1 && S !== null && S !== void 0 && (ne === "svara" || ne === "mAtrA"))
|
|
401
|
+
G = v;
|
|
402
|
+
else if (G !== -1) {
|
|
403
|
+
D = G;
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (P[1].next && P[1].next.length > 0) {
|
|
408
|
+
const x = l.peekAt(y), E = x?.ch;
|
|
409
|
+
if (I(e) && n.script_type === "brahmic") {
|
|
410
|
+
const $ = x ? l.peekAt(y + x.width) : null, S = $?.ch, q = (x && $ ? l.peekAt(y + x.width + $.width) : null)?.ch;
|
|
411
|
+
if (d === -1 && S !== void 0 && O(S) && P[1].next.indexOf(S) !== -1) {
|
|
412
|
+
const X = ae(
|
|
413
|
+
n.text_to_krama_map,
|
|
414
|
+
A + S,
|
|
415
|
+
{
|
|
416
|
+
accessor: (C, w) => C[w][0]
|
|
417
|
+
}
|
|
418
|
+
), F = V(
|
|
419
|
+
n.krama_text_arr,
|
|
420
|
+
n.krama_text_arr_index,
|
|
421
|
+
E ?? "",
|
|
422
|
+
{
|
|
423
|
+
accessor: (C, w) => C[w][0]
|
|
424
|
+
}
|
|
425
|
+
);
|
|
426
|
+
if (X !== -1 && F !== -1) {
|
|
427
|
+
D = X;
|
|
428
|
+
const C = n.krama_text_arr[F], w = n.list[C[1] ?? -1]?.type;
|
|
429
|
+
if (E === n.halant || w === "mAtrA") {
|
|
430
|
+
d = y + (x?.width ?? 0);
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
} else if (d === -1 && q !== void 0 && O(q) && P[1].next.indexOf(q) !== -1) {
|
|
435
|
+
const X = ae(
|
|
436
|
+
n.text_to_krama_map,
|
|
437
|
+
A + q,
|
|
438
|
+
{
|
|
439
|
+
accessor: (w, M) => w[M][0]
|
|
440
|
+
}
|
|
441
|
+
), F = V(
|
|
442
|
+
n.krama_text_arr,
|
|
443
|
+
n.krama_text_arr_index,
|
|
444
|
+
E ?? "",
|
|
445
|
+
{
|
|
446
|
+
accessor: (w, M) => w[M][0]
|
|
447
|
+
}
|
|
448
|
+
), C = V(
|
|
449
|
+
n.krama_text_arr,
|
|
450
|
+
n.krama_text_arr_index,
|
|
451
|
+
S ?? "",
|
|
452
|
+
{
|
|
453
|
+
accessor: (w, M) => w[M][0]
|
|
454
|
+
}
|
|
455
|
+
);
|
|
456
|
+
if (X !== -1 && F !== -1 && C !== -1) {
|
|
457
|
+
const w = n.krama_text_arr[F], M = n.krama_text_arr[C];
|
|
458
|
+
D = X;
|
|
459
|
+
const de = n.list[w[1] ?? -1]?.type, ke = n.list[M[1] ?? -1]?.type;
|
|
460
|
+
if (de === "mAtrA" && ke === "mAtrA") {
|
|
461
|
+
d = y + (x?.width ?? 0) + ($?.width ?? 0);
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
if (E !== void 0 && P[1].next.indexOf(E) !== -1) {
|
|
468
|
+
b += x?.width ?? 0;
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
D = v;
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
const m = D !== -1 ? n.text_to_krama_map[D] : null;
|
|
477
|
+
if (m !== null) {
|
|
478
|
+
const b = d !== -1 && m[0].length > 1 && n.list[n.krama_text_arr[m[1].krama?.[0] ?? -1]?.[1] ?? -1]?.type === "vyanjana" && O(m[0].at(-1) ?? void 0) ? 1 : 0, G = m[0].length - b;
|
|
479
|
+
if (l.advance(G), i = l.pos, m[1].krama !== null && m[1].krama !== void 0 && m[1].krama.some((j) => j !== -1)) {
|
|
480
|
+
const j = m[1].krama.map(
|
|
481
|
+
(y) => L(a, y)
|
|
482
|
+
// revert to the original character if the krama index is not found
|
|
483
|
+
), Q = j.join("");
|
|
484
|
+
let N = !1;
|
|
485
|
+
if (h)
|
|
486
|
+
if (n.script_type === "brahmic" && a.script_type === "other") {
|
|
487
|
+
let y = null;
|
|
488
|
+
if (m[1].fallback_list_ref !== void 0 && m[1].fallback_list_ref !== null)
|
|
489
|
+
y = n.list[m[1].fallback_list_ref];
|
|
490
|
+
else if (!m[1].krama || m[1].krama.length === 0)
|
|
491
|
+
y = null;
|
|
492
|
+
else {
|
|
493
|
+
const A = m[1].krama.map(
|
|
494
|
+
(v) => n.list[n.krama_text_arr[v][1] ?? -1]
|
|
495
|
+
);
|
|
496
|
+
I(e) && A.some((v) => v?.type === "mAtrA") && A.some((v) => v?.type === "vyanjana") ? y = { ...A[0], type: "anya" } : I(e) && A.length > 1 && A.some((v) => v == null) ? y = A.at(-1) : y = A[0];
|
|
497
|
+
}
|
|
498
|
+
N = T(f, [m[0], y]);
|
|
499
|
+
} else if (a.script_type === "brahmic" && n.script_type === "other") {
|
|
500
|
+
let y = null;
|
|
501
|
+
m[1].fallback_list_ref !== void 0 && m[1].fallback_list_ref !== null ? y = a.list[m[1].fallback_list_ref] : y = m[1].krama && m[1].krama.length > 0 ? a.list[a.krama_text_arr[m[1].krama[0]]?.[1] ?? -1] ?? null : null, _ && e === "Normal" ? N = T(f, [m[0], y], {
|
|
502
|
+
next: m[1].next ?? void 0
|
|
503
|
+
}) : N = T(f, [m[0], y]);
|
|
504
|
+
} else _ && e === "Normal" && a.script_type === "other" && (N = T(f, [m[0], null], {
|
|
505
|
+
next: m[1].next ?? void 0
|
|
506
|
+
}));
|
|
507
|
+
N || (a.script_type === "brahmic" && I(r) && (a.list[m[1].krama?.at(-1) ?? -1]?.type === "mAtrA" || Q === a.halant) && O(c.lastChar()) ? K(
|
|
508
|
+
c,
|
|
509
|
+
j,
|
|
510
|
+
a.halant,
|
|
511
|
+
!0
|
|
512
|
+
) : c.emitPieces(j)), ce(f, i, -G);
|
|
513
|
+
continue;
|
|
514
|
+
} else if (m[1].krama !== null && m[1].krama !== void 0 && m[1].krama.some((j) => j === -1)) {
|
|
515
|
+
c.emit(m[0]), _ && T(f, [m[0], null], {
|
|
516
|
+
next: m[1].next ?? void 0
|
|
517
|
+
});
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
} else
|
|
521
|
+
l.advance(B), i = l.pos;
|
|
522
|
+
const H = m === null ? ee : m[0], U = J(n, H);
|
|
523
|
+
if (U === -1) {
|
|
524
|
+
h && (T(f, [H, null]), p.clear()), c.emit(H);
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
let te = !1;
|
|
528
|
+
if (h && (n.script_type === "brahmic" ? te = T(f, [
|
|
529
|
+
H,
|
|
530
|
+
n.list[n.krama_text_arr[U][1] ?? -1]
|
|
531
|
+
]) : a.script_type === "brahmic" && (te = T(f, [
|
|
532
|
+
H,
|
|
533
|
+
a.list[a.krama_text_arr[U][1] ?? -1]
|
|
534
|
+
]))), !te) {
|
|
535
|
+
const b = L(a, U);
|
|
536
|
+
a.script_type === "brahmic" && I(r) && (a.list[a.krama_text_arr[U][1] ?? -1]?.type === "mAtrA" || b === a.halant) && O(c.lastChar()) ? K(c, [b], a.halant, !0) : c.emit(b);
|
|
537
|
+
}
|
|
538
|
+
ce(f, i, -B);
|
|
539
|
+
}
|
|
540
|
+
h && T(f, [void 0, null], { last_extra_call: !0 });
|
|
541
|
+
let W = c.toString();
|
|
542
|
+
return W = ue(W, a, o, "output"), {
|
|
543
|
+
output: W,
|
|
544
|
+
/** Can be used to manage context while using the typing feature.
|
|
545
|
+
* If this is 0, the external context can be cleared
|
|
546
|
+
*/
|
|
547
|
+
context_length: p.length()
|
|
548
|
+
};
|
|
549
|
+
}, Ee = async (t, e, r, n, a) => {
|
|
550
|
+
const [s, o] = await Promise.all([
|
|
551
|
+
R(e),
|
|
552
|
+
R(r)
|
|
553
|
+
]), { trans_options: u, custom_rules: _ } = he(
|
|
554
|
+
s,
|
|
555
|
+
o,
|
|
556
|
+
n
|
|
557
|
+
);
|
|
558
|
+
return me(
|
|
559
|
+
t,
|
|
560
|
+
e,
|
|
561
|
+
r,
|
|
562
|
+
s,
|
|
563
|
+
o,
|
|
564
|
+
u,
|
|
565
|
+
_,
|
|
566
|
+
a
|
|
567
|
+
);
|
|
568
|
+
}, Se = { Devanagari: 1, Telugu: 2, Tamil: 3, "Tamil-Extended": 4, Bengali: 5, Kannada: 6, Gujarati: 7, Malayalam: 8, Odia: 9, Sinhala: 10, Normal: 11, Romanized: 12, Gurumukhi: 13, Assamese: 14, "Purna-Devanagari": 15, Brahmi: 16, Granth: 17, Modi: 18, Sharada: 20, Siddham: 21 }, Ne = { English: 1, Sanskrit: 2, Hindi: 3, Telugu: 4, Tamil: 5, Bengali: 6, Kannada: 7, Gujarati: 8, Malayalam: 9, Odia: 10, Sinhala: 11, Marathi: 12, Nepali: 13, Punjabi: 14, Assamese: 15 }, Pe = {
|
|
569
|
+
script_list: Se,
|
|
570
|
+
lang_list: Ne
|
|
571
|
+
}, { script_list: Ce, lang_list: Oe } = Pe, fe = Object.keys(Ce), ye = Object.keys(Oe), Re = Array.from(
|
|
572
|
+
/* @__PURE__ */ new Set([...ye, ...fe])
|
|
573
|
+
), Ie = {
|
|
574
|
+
Bengali: "Bengali",
|
|
575
|
+
Gujarati: "Gujarati",
|
|
576
|
+
Hindi: "Devanagari",
|
|
577
|
+
Kannada: "Kannada",
|
|
578
|
+
Malayalam: "Malayalam",
|
|
579
|
+
Odia: "Odia",
|
|
580
|
+
Sinhala: "Sinhala",
|
|
581
|
+
Tamil: "Tamil",
|
|
582
|
+
Telugu: "Telugu",
|
|
583
|
+
English: "Normal",
|
|
584
|
+
Sanskrit: "Devanagari",
|
|
585
|
+
Marathi: "Devanagari",
|
|
586
|
+
Nepali: "Devanagari",
|
|
587
|
+
Punjabi: "Gurumukhi",
|
|
588
|
+
Assamese: "Assamese"
|
|
589
|
+
}, _e = {
|
|
590
|
+
dev: "Devanagari",
|
|
591
|
+
te: "Telugu",
|
|
592
|
+
tel: "Telugu",
|
|
593
|
+
tam: "Tamil",
|
|
594
|
+
"tam-ex": "Tamil-Extended",
|
|
595
|
+
ben: "Bengali",
|
|
596
|
+
be: "Bengali",
|
|
597
|
+
ka: "Kannada",
|
|
598
|
+
kan: "Kannada",
|
|
599
|
+
gu: "Gujarati",
|
|
600
|
+
guj: "Gujarati",
|
|
601
|
+
mal: "Malayalam",
|
|
602
|
+
or: "Odia",
|
|
603
|
+
od: "Odia",
|
|
604
|
+
oriya: "Odia",
|
|
605
|
+
si: "Sinhala",
|
|
606
|
+
sinh: "Sinhala",
|
|
607
|
+
sin: "Sinhala",
|
|
608
|
+
en: "Normal",
|
|
609
|
+
eng: "Normal",
|
|
610
|
+
la: "Normal",
|
|
611
|
+
lat: "Normal",
|
|
612
|
+
nor: "Normal",
|
|
613
|
+
norm: "Normal",
|
|
614
|
+
rom: "Romanized",
|
|
615
|
+
gur: "Gurumukhi",
|
|
616
|
+
as: "Assamese",
|
|
617
|
+
sa: "Devanagari",
|
|
618
|
+
san: "Devanagari",
|
|
619
|
+
hin: "Devanagari",
|
|
620
|
+
hi: "Devanagari",
|
|
621
|
+
mar: "Devanagari",
|
|
622
|
+
ne: "Devanagari",
|
|
623
|
+
nep: "Devanagari",
|
|
624
|
+
pun: "Gurumukhi"
|
|
625
|
+
};
|
|
626
|
+
function Le(t) {
|
|
627
|
+
return t.toLowerCase().replace(/(^|-)([a-z])/g, (e, r, n) => r + n.toUpperCase());
|
|
628
|
+
}
|
|
629
|
+
const z = (t) => {
|
|
630
|
+
const e = Le(t);
|
|
631
|
+
return fe.includes(e) ? e : ye.includes(e) ? Ie[e] : t.toLocaleLowerCase() in _e ? _e[t.toLocaleLowerCase()] : null;
|
|
632
|
+
}, Be = async (t) => {
|
|
633
|
+
const e = z(t);
|
|
634
|
+
if (!e)
|
|
635
|
+
throw new Error(`Invalid script name: ${t}`);
|
|
636
|
+
return await R(e);
|
|
637
|
+
};
|
|
638
|
+
async function Ge(t, e, r, n) {
|
|
639
|
+
const a = z(e);
|
|
640
|
+
if (!a)
|
|
641
|
+
throw new Error(`Invalid script name: ${e}`);
|
|
642
|
+
const s = z(r);
|
|
643
|
+
if (!s)
|
|
644
|
+
throw new Error(`Invalid script name: ${r}`);
|
|
645
|
+
return a === s ? t : (await Ee(t, a, s, n)).output;
|
|
646
|
+
}
|
|
647
|
+
async function Ke(t, e) {
|
|
648
|
+
const r = z(t);
|
|
649
|
+
if (!r)
|
|
650
|
+
throw new Error(`Invalid script name: ${t}`);
|
|
651
|
+
const n = z(e);
|
|
652
|
+
if (!n)
|
|
653
|
+
throw new Error(`Invalid script name: ${e}`);
|
|
654
|
+
const a = await R(r), s = await R(n);
|
|
655
|
+
return Object.keys(
|
|
656
|
+
pe(
|
|
657
|
+
a,
|
|
658
|
+
s,
|
|
659
|
+
Object.fromEntries(Object.keys(Y).map((o) => [o, !0]))
|
|
660
|
+
)
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
function ze(t) {
|
|
664
|
+
const e = z(t);
|
|
665
|
+
if (!e)
|
|
666
|
+
throw new Error(`Invalid script name: ${t}`);
|
|
667
|
+
let r = "", n = "", a = null, s = null, o = {}, u = [];
|
|
668
|
+
const _ = (async () => {
|
|
669
|
+
const [l, p] = await Promise.all([
|
|
670
|
+
R("Normal"),
|
|
671
|
+
R(e)
|
|
672
|
+
]);
|
|
673
|
+
a = l, s = p;
|
|
674
|
+
const h = he(l, p);
|
|
675
|
+
o = h.trans_options, u = h.custom_rules;
|
|
676
|
+
})();
|
|
677
|
+
function c() {
|
|
678
|
+
r = "", n = "";
|
|
679
|
+
}
|
|
680
|
+
function i(l) {
|
|
681
|
+
if (!a || !s)
|
|
682
|
+
throw new Error(
|
|
683
|
+
"Typing context not ready. Await `ctx.ready` before calling takeKeyInputSync."
|
|
684
|
+
);
|
|
685
|
+
let p = l?.[0] ?? "";
|
|
686
|
+
r += p;
|
|
687
|
+
let h = n;
|
|
688
|
+
const { context_length: k, output: g } = me(
|
|
689
|
+
r,
|
|
690
|
+
"Normal",
|
|
691
|
+
e,
|
|
692
|
+
a,
|
|
693
|
+
s,
|
|
694
|
+
o,
|
|
695
|
+
u,
|
|
696
|
+
{ typing_mode: !0 }
|
|
697
|
+
);
|
|
698
|
+
k > 0 ? n = g : k === 0 && (r = "", n = "");
|
|
699
|
+
let f = 0;
|
|
700
|
+
for (; f < g.length && f < h.length && g[f] === h[f]; )
|
|
701
|
+
f++;
|
|
702
|
+
let d = g.substring(f);
|
|
703
|
+
return {
|
|
704
|
+
/** These number of characters need to be deleted from the current "app" input state */
|
|
705
|
+
to_delete_chars_count: h.length - f,
|
|
706
|
+
/** These characters need to be added to the current "app" input state */
|
|
707
|
+
diff_add_text: d
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
return {
|
|
711
|
+
/** Await once, then use `takeKeyInputSync` for best typing latency. */
|
|
712
|
+
ready: _,
|
|
713
|
+
clearContext: c,
|
|
714
|
+
takeKeyInput: i,
|
|
715
|
+
getCurrentOutput: () => n
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
function De(t) {
|
|
719
|
+
return "nativeEvent" in t ? t.nativeEvent : t;
|
|
720
|
+
}
|
|
721
|
+
async function He(t, e, r) {
|
|
722
|
+
const n = e.currentTarget, a = De(e);
|
|
723
|
+
if (typeof InputEvent < "u" && a instanceof InputEvent && a.data !== null) {
|
|
724
|
+
await t.ready;
|
|
725
|
+
const { diff_add_text: o, to_delete_chars_count: u } = t.takeKeyInput(a.data), _ = n.value, c = (n.selectionStart ?? 0) + 1, i = c - u - 2, l = _.substring(0, i), p = o;
|
|
726
|
+
let h = "";
|
|
727
|
+
const k = _.length + 1 === c, g = _.length + 1 !== c;
|
|
728
|
+
k ? h = _.substring(c + 1) : g && (h = _.substring(c - 1));
|
|
729
|
+
const f = l.length + p.length, d = l + p + h;
|
|
730
|
+
n.value = d, n.focus(), n.selectionStart = f, n.selectionEnd = f, r?.(d);
|
|
731
|
+
} else
|
|
732
|
+
r?.(n.value), t.clearContext();
|
|
733
|
+
}
|
|
734
|
+
const Me = /* @__PURE__ */ new Set([
|
|
735
|
+
"Backspace",
|
|
736
|
+
"Delete",
|
|
737
|
+
"Enter",
|
|
738
|
+
"Tab",
|
|
739
|
+
"Escape",
|
|
740
|
+
"ArrowLeft",
|
|
741
|
+
"ArrowRight",
|
|
742
|
+
"ArrowUp",
|
|
743
|
+
"ArrowDown",
|
|
744
|
+
"Home",
|
|
745
|
+
"End",
|
|
746
|
+
"PageUp",
|
|
747
|
+
"PageDown"
|
|
748
|
+
]);
|
|
749
|
+
function Ue(t, e) {
|
|
750
|
+
if (t.isComposing) return !1;
|
|
751
|
+
const r = t.key;
|
|
752
|
+
return !r || r === "Unidentified" || r === "Process" || r === "Dead" || t.ctrlKey || t.metaKey || t.altKey ? !1 : Me.has(r) ? (e.clearContext(), !0) : !1;
|
|
753
|
+
}
|
|
754
|
+
export {
|
|
755
|
+
Re as ALL_LANG_SCRIPT_LIST,
|
|
756
|
+
ye as LANG_LIST,
|
|
757
|
+
fe as SCRIPT_LIST,
|
|
758
|
+
Ue as clearTypingContextOnKeyDown,
|
|
759
|
+
ze as createTypingContext,
|
|
760
|
+
Ke as getAllOptions,
|
|
761
|
+
He as handleTypingInputEvent,
|
|
762
|
+
Be as preloadScriptData,
|
|
763
|
+
Ge as transliterate
|
|
764
|
+
};
|