decord/source/lib/spellcheck/Spellchecker.tsx

345 lines
11 KiB
TypeScript
Raw Normal View History

2026-08-24 06:08:38 +00:00
// Module ID: 6954
// Function ID: 6955
2026-08-07 06:50:47 +00:00
// Name: _install
2026-08-24 06:08:38 +00:00
// Dependencies: [5, 32, 1995, 3, 4007, 6955, 6956, 6957, 6958, 1370, 12, 1906, 2]
2026-07-20 16:05:17 +00:00
// Exports: install
2026-08-24 06:08:38 +00:00
// Module 6954 (_install)
import timestampDefault from "timestamp" /* 3 */;
import set from "set" /* 1906 */;
import closure_3 from "asyncGeneratorStep" /* 5 */;
import closure_4 from "_slicedToArray" /* 32 */;
import closure_5 from "_getSystemLocale" /* 1995 */;
import importDefaultResult from "set" /* 4007 */;
import importDefaultResult1 from "apply" /* 12 */;
2026-07-23 10:11:24 +00:00
2026-08-24 06:08:38 +00:00
require = arg1;
2026-07-29 08:29:29 +00:00
function _install() {
const self = this;
const tmp = callback(function*() {
2026-08-24 06:08:38 +00:00
closure_2 = tmp2;
2026-08-07 06:50:47 +00:00
let usesMultilang = tmp3;
2026-08-24 06:08:38 +00:00
closure_0 = yield closure_1_7.getAvailableDictionaries();
2026-08-04 21:03:28 +00:00
if (arg1 == null) {
2026-08-07 06:50:47 +00:00
closure_0 = [];
2026-07-20 16:05:17 +00:00
}
2026-08-07 06:50:47 +00:00
usesMultilang = new closure_8(closure_0);
if (!usesMultilang.usesMultilang) {
(function attachToInput(closure_1) {
2026-08-24 06:08:38 +00:00
closure_0 = closure_1;
2026-08-07 06:50:47 +00:00
if (null != document.body) {
const _document = document;
2026-08-24 06:08:38 +00:00
const listener = body.addEventListener("beforeinput", (target) => closure_1_9(closure_0, target.target), true);
2026-08-07 06:50:47 +00:00
}
})(usesMultilang);
}
2026-08-24 06:08:38 +00:00
return closure_1_1;
2026-07-29 08:29:29 +00:00
});
2026-08-24 06:08:38 +00:00
closure_10 = tmp;
2026-07-29 08:29:29 +00:00
const apply = tmp.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
let closure_6 = new timestampDefault("Spellchecker");
2026-07-20 16:05:17 +00:00
let spellCheck;
2026-07-29 08:29:29 +00:00
if (importDefaultResult != null) {
spellCheck = importDefaultResult.spellCheck;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
class Spellchecker {
constructor(arg0) {
obj = Object.create(new.target.prototype);
2026-08-07 06:50:47 +00:00
closure_2 = obj;
obj.rawLocaleByNormalized = {};
obj.languageDetector = null;
obj.availableLanguagesByLanguage = {};
2026-07-29 08:29:29 +00:00
obj._enabled = true;
obj.misspelledWord = "";
obj.corrections = [];
2026-08-07 06:50:47 +00:00
items = [];
closure_0 = items;
item = global.forEach((arg0) => {
let str = "nb";
if ("no" !== arg0) {
str = arg0;
}
let str2 = first(obj[5])[str];
if (str2 == null) {
str2 = str;
}
obj = items(obj[6]);
const parsed = obj.parse(str2.replace(/[_-]/g, "-"));
if (null != parsed) {
if (null != parsed.langtag.language) {
if (null != parsed.langtag.region) {
const langtag = parsed.langtag;
const formatted = langtag.language.language.toLowerCase();
const _HermesInternal = HermesInternal;
const combined = "" + formatted + "-" + langtag.region.toUpperCase();
const str3 = langtag.region;
const str4 = langtag.language.language;
}
if (null != combined) {
items.push(combined);
let tmp10 = obj.rawLocaleByNormalized[combined];
if (tmp10 == null) {
tmp10 = arg0;
}
obj.rawLocaleByNormalized[combined] = tmp10;
}
2026-07-20 16:05:17 +00:00
}
}
2026-08-24 06:08:38 +00:00
closure_1_6.error("" + str2 + " is not a valid locale.");
2026-07-29 08:29:29 +00:00
});
2026-08-07 06:50:47 +00:00
obj.availableLocales = items;
tmp2 = closure_2;
obj2 = require("apexExperiment");
obj.useMultilang = obj2.isElectronMultilangSpellcheckEnabled();
obj.availableLanguagesByLanguage = obj.buildLanguageIndex(items);
if (obj.useMultilang) {
2026-08-24 06:08:38 +00:00
tmp13 = closure_5;
applyLanguagesResult = obj.applyLanguages(closure_5.locale);
2026-08-07 06:50:47 +00:00
} else {
2026-08-24 06:08:38 +00:00
tmp3 = closure_5;
str = closure_5.locale;
2026-08-07 06:50:47 +00:00
str2 = "-";
2026-08-24 06:08:38 +00:00
tmp4 = closure_4;
2026-08-07 06:50:47 +00:00
num = 2;
2026-08-24 06:08:38 +00:00
tmp5 = closure_4(str.split("-"), 2);
2026-08-07 06:50:47 +00:00
first = tmp5[0];
2026-08-24 06:08:38 +00:00
closure_1 = first;
2026-08-07 06:50:47 +00:00
obj.regionPreference = tmp5[1];
2026-08-24 06:08:38 +00:00
tmp7 = closure_1;
2026-08-07 06:50:47 +00:00
tmp8 = new.target;
tmp9 = new.target;
tmp10 = first;
tmp11 = new require("language")(first, (arg0) => {
const combined = "" + arg0 + "-" + obj.regionPreference;
const availableLocales = obj.availableLocales;
if (-1 !== availableLocales.indexOf(combined)) {
obj.applyLocale(combined);
} else {
let tmp2 = obj.availableLanguagesByLanguage[arg0];
if (tmp2 == null) {
tmp2 = first(obj[5])[first];
}
if (null != tmp2) {
obj.applyLocale(tmp2);
}
}
});
tmp12 = tmp11;
obj.languageDetector = tmp11;
}
2026-07-29 08:29:29 +00:00
onResult = spellCheck.on("spellcheck-result", (arg0, arg1) => {
let str = arg0;
if (arg0 == null) {
str = "";
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
items = arg1;
2026-07-29 08:29:29 +00:00
obj.misspelledWord = str;
if (arg1 == null) {
items = [];
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj.corrections = items;
});
return obj;
}
}
const prototype = Spellchecker.prototype;
Object.defineProperty(prototype, "enabled", {
get: function enabled() {
return this._enabled;
},
set: undefined
});
Object.defineProperty(prototype, "enabled", {
get: undefined,
set: function enabled(_enabled) {
this._enabled = _enabled;
}
});
2026-08-07 06:50:47 +00:00
Object.defineProperty(prototype, "usesMultilang", {
get: function usesMultilang() {
return this.useMultilang;
},
set: undefined
});
2026-07-29 08:29:29 +00:00
prototype["setLearnedWords"] = function setLearnedWords(arg0) {
spellCheck.setLearnedWords(arg0);
};
2026-08-07 06:50:47 +00:00
prototype["setAppLocale"] = function setAppLocale(locale) {
const self = this;
if (this.useMultilang) {
self.applyLanguages(locale);
} else {
self.regionPreference = locale.split("-")[1];
}
};
prototype["detectLanguage"] = function detectLanguage(textContent) {
const self = this;
const useMultilang = this.useMultilang;
let enabled = !useMultilang;
if (!useMultilang) {
enabled = self.enabled;
}
if (enabled) {
const languageDetector = self.languageDetector;
if (languageDetector != null) {
languageDetector.process(textContent);
}
}
};
prototype["isMisspelled"] = function isMisspelled(arg0) {
let tmp2 = "" !== this.misspelledWord;
if (tmp2) {
tmp2 = arg0 === tmp.misspelledWord;
}
return tmp2;
};
prototype["getCorrectionsForMisspelling"] = function getCorrectionsForMisspelling(closure_0, flag) {
return this.isMisspelled(closure_0, flag) ? this.corrections : [];
};
prototype["getCachedMisspelling"] = function getCachedMisspelling() {
return { misspelledWord: this.misspelledWord, corrections: this.corrections };
};
prototype["replaceMisspelling"] = function replaceMisspelling(closure_0) {
spellCheck.replaceMisspelling(closure_0);
};
prototype["applyLocale"] = function applyLocale(combined) {
2026-08-24 06:08:38 +00:00
closure_0 = combined;
2026-08-07 06:50:47 +00:00
const setLocaleResult = spellCheck.setLocale(combined);
2026-07-29 08:29:29 +00:00
if (setLocaleResult != null) {
setLocaleResult.then((arg0) => {
let str = "(unavailable)";
2026-08-24 06:08:38 +00:00
combined = "Switching to " + closure_0;
2026-07-29 08:29:29 +00:00
if (arg0) {
str = "(available)";
}
2026-08-24 06:08:38 +00:00
closure_1_6.info(combined, str);
2026-07-29 08:29:29 +00:00
});
}
};
2026-08-07 06:50:47 +00:00
prototype["applyLanguages"] = function applyLanguages(locale) {
let self = this;
self = this;
const items = [locale, ...navigator.languages];
const mapped = items.map((str) => {
str = "nb";
2026-08-24 06:08:38 +00:00
let str2 = self(closure_1_2[5])[str];
2026-08-07 06:50:47 +00:00
if (str2 == null) {
str2 = str;
}
2026-08-24 06:08:38 +00:00
const parsed = mapped1(closure_1_2[6]).parse(str2.replace(/[_-]/g, "-"));
2026-08-07 06:50:47 +00:00
if (null != parsed) {
if (null != parsed.langtag.language) {
if (null != parsed.langtag.region) {
const langtag = parsed.langtag;
const formatted = langtag.language.language.toLowerCase();
const _HermesInternal = HermesInternal;
const combined = "" + formatted + "-" + langtag.region.toUpperCase();
const str3 = langtag.region;
const str4 = langtag.language.language;
}
if (null != combined) {
const availableLocales = self.availableLocales;
if (availableLocales.includes(combined)) {
return combined;
}
}
2026-08-24 06:08:38 +00:00
const str7 = closure_1_4(str.replace(/_/g, "-").split("-"), 1)[0];
2026-08-07 06:50:47 +00:00
let tmp10 = self.availableLanguagesByLanguage[str7.toLowerCase(str7)];
if (tmp10 == null) {
tmp10 = null;
}
return tmp10;
}
}
2026-08-24 06:08:38 +00:00
closure_1_6.error("" + str2 + " is not a valid locale.");
2026-08-07 06:50:47 +00:00
});
2026-08-11 06:20:06 +00:00
const arr = Array.from(new Set(mapped.filter(mapped1(1370).isNotNullish)));
2026-08-07 06:50:47 +00:00
if (0 !== arr.length) {
mapped1 = arr.map((arg0) => {
let tmp = self.rawLocaleByNormalized[arg0];
if (tmp == null) {
tmp = arg0;
}
return tmp;
});
if (null == spellCheck.setSpellCheckerLanguages) {
let _HermesInternal2 = HermesInternal;
2026-08-24 06:08:38 +00:00
logger.info("setSpellCheckerLanguages unavailable, falling back to single-locale: " + mapped1[0]);
2026-08-07 06:50:47 +00:00
self.applyLocale(mapped1[0]);
} else {
const result = obj.setSpellCheckerLanguages(mapped1);
if (result != null) {
result.then((arg0) => {
2026-08-24 06:08:38 +00:00
const info = closure_1_6.info;
2026-08-07 06:50:47 +00:00
if (arg0) {
const _HermesInternal2 = HermesInternal;
info("Spellcheck languages: " + obj.join(", "), "(applied)");
} else {
const _HermesInternal = HermesInternal;
info("Failed to set spellcheck languages, falling back to single-locale: " + obj[0]);
self.applyLocale(obj[0]);
}
});
}
}
obj = spellCheck;
} else {
let _HermesInternal = HermesInternal;
2026-08-24 06:08:38 +00:00
logger.info("No spellcheck languages resolved from candidates: " + items.join(", "));
2026-07-29 08:29:29 +00:00
}
};
2026-08-07 06:50:47 +00:00
prototype["buildLanguageIndex"] = function buildLanguageIndex(items) {
2026-07-29 08:29:29 +00:00
const obj = {};
2026-08-07 06:50:47 +00:00
const item = items.forEach((arg0) => {
2026-08-24 06:08:38 +00:00
const first = closure_1_4(arg0.split("-"), 1)[0];
2026-07-29 08:29:29 +00:00
let tmp3 = obj[first];
if (tmp3 == null) {
tmp3 = arg0;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj[first] = tmp3;
});
return obj;
};
2026-08-24 06:08:38 +00:00
let tmp2 = new timestampDefault("Spellchecker");
let closure_9 = importDefaultResult1.debounce((detectLanguage, hasAttribute) => {
2026-07-20 16:05:17 +00:00
let textContent = null;
if (null != hasAttribute) {
if (!obj.isElement(hasAttribute, globalThis.HTMLInputElement)) {
2026-08-11 06:20:06 +00:00
let tmp2Result = tmp2(1906);
2026-07-29 08:29:29 +00:00
if (!tmp2Result.isElement(hasAttribute, globalThis.HTMLTextAreaElement)) {
2026-08-11 06:20:06 +00:00
tmp2Result = tmp2(1906);
2026-07-29 08:29:29 +00:00
if (tmp2Result.isElement(hasAttribute)) {
2026-07-20 16:05:17 +00:00
if (hasAttribute.hasAttribute("contenteditable")) {
textContent = hasAttribute.textContent;
}
}
}
}
textContent = hasAttribute.value;
2026-08-24 06:08:38 +00:00
obj = set;
2026-07-20 16:05:17 +00:00
}
if (null != textContent) {
detectLanguage.detectLanguage(textContent);
}
}, 250);
2026-08-24 06:08:38 +00:00
let result = require("set").fileFinishedImporting("lib/spellcheck/Spellchecker.tsx");
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
export { Spellchecker };
2026-07-20 16:05:17 +00:00
export const install = function install() {
2026-07-29 08:29:29 +00:00
const self = this;
const apply = _install.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
2026-07-20 16:05:17 +00:00
};