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