import type { AliasNameTable } from 'mathjslab'; import type { Locale } from './i18n'; /** * Language-aware aliases passed to MathJSLab's parser and lexer context. */ export const languageAlias: Record = { en: { abs: /^abs(olute)?$/, arg: /^arg(ument)?$|^angle$/, sign: /^sign(al)?$|^sgn$/, conj: /^conj(ugate)?$/, sqrt: /^sq(uare)?r(oo)?t$/, root: /^r(oo)?t$/, power: /^pow(er)?$/, exp: /^exp(onential)?$/, log: /^ln$/, log10: /^l((og)?arithm)10$/, asin: /^a(rc)?sine?$/, sin: /^sin$/, acos: /^a(rc)?cos(ine)?$/, cos: /^cos(ine)?$/, atan: /^a(rc)?tan(gent)?$/, tan: /^tan(gent)?$/, asinh: /^a(rea)?sine?h(((yp)?erb)?olic)?$/, sinh: /^sine?h(((yp)?erb)?olic)?$/, acosh: /^a(rea)?cos(ine)?h(((yp)?erb)?olic)?$/, cosh: /^cos(ine)?h(((yp)?erb)?olic)?$/, atanh: /^a(rea)?tan(gent)?h(((yp)?erb)?olic)?$/, tanh: /^tan(gent)?h(((yp)?erb)?olic)?$/, factorial: /^fact(orial)?$/, eye: /^ident(ity)?$/, inv: /^inv(erse)?$/, det: /^det(erminant)?$/, trace: /^tr(ace)?$/, ctranspose: /^trans(p((ose)?)?)?$/, min: /^min(imum)?$/, max: /^max(imum)?$/, mean: /^mean|avg|average$/, plot2d: /^graph(ics?)?$/, histogram: /^hist(ogram)?$/, }, es: { abs: /^abs(olut(o|e))?$/, arg: /^arg(ument(o)?)?$|^ang(ulo|le)$/, sign: /^sign(o|al)?$|^sgn$/, conj: /^conj(uga(do|te)?)?$/, sqrt: /^r(ai)?z(2|cuadrada)?$|^sqrt$/, root: /^r(ai)?z$|^r(oo)?t$/, power: /^pot(encia)?$|^pow(er)?$/, exp: /^exp(onencial|onential)?$/, log: /^ln$/, log10: /^l((og)?aritmo)10$/, asin: /^a(rc)?s[ei]n(o)?$/, sin: /^s[ei]n(o)?$/, acos: /^a(rc)?cos(eno)?$/, cos: /^cos(eno)?$/, atan: /^a(rc)?t(g|an)(gente)?$/, tan: /^t(g|an)(gente)?$/, asinh: /^a(rc)?s[ei]nh$/, sinh: /^s[ei]nh$/, acosh: /^a(rc)?cosh$/, cosh: /^cosh$/, atanh: /^a(rc)?t(g|an)h$/, tanh: /^t(g|an)h$/, factorial: /^fact(orial)?$/, eye: /^ident(i(dad|ty))?$|^eye$/, inv: /^inv(er(s[ao]|tir)?)?$/, det: /^det(erminant(e)?)?$/, trace: /^tr(aza|ace)$/, ctranspose: /^trans(p((ose)?|(uesta)?))?$/, min: /^min(imo)?$|^min(imum)?$/, max: /^max(imo)?$|^max(imum)?$/, mean: /^media|mean$/, plot2d: /^graph(ics?)?$/, histogram: /^hist(ogram)?$/, }, pt: { abs: /^abs(olut(o|e))?$/, arg: /^arg(ument(o)?)?$|^angle$|^angulo$/, sign: /^sign(al)?$|^sinal$|^sgn$/, conj: /^conj(uga(do|te)?)?$/, sqrt: /^r(ai)?z(2|q(uadrada)?)$|^sqrt$/, root: /^r(ai)?z$|^r(oo)?t$/, power: /^pot(encia)?$|^elev(ado)?$|^pow(er)?$/, exp: /^exp(onen((cial)|(tial)))?$/, log: /^ln$/, log10: /^l((og)?aritmo)10$/, asin: /^a(rc)?s[ei]n$/, sin: /^s[ei]n$/, acos: /^a(rc)?cos$/, cos: /^cos$/, atan: /^a(rc)?t(g|an)$/, tan: /^t(g|an)$/, asinh: /^a(rc)?s[ei]nh$/, sinh: /^s[ei]nh$/, acosh: /^a(rc)?cosh$/, cosh: /^cosh$/, atanh: /^a(rc)?t(g|an)h$/, tanh: /^t(g|an)h$/, factorial: /^fa(c)?t(orial)?$/, eye: /^ident(i(dade|ty))?$|^eye$/, inv: /^inv(er(t(er)?|s[ea])?)?$/, det: /^det(erminant(e)?)?$/, trace: /^tr(aco|ace)$/, ctranspose: /^trans(p((ose)?|(osta)?))?$/, min: /^min(imo)?$|^min(imum)?$/, max: /^max(imo)?$|^max(imum)?$/, mean: /^media|mean$/, summation: /^somatorio$/, productory: /^produtorio$/, plot2d: /^gra(f(ico)?|ph?(ics?)?)?$/, histogram: /^hist(ogram(a)?)?$/, }, }; /** Accept the supported locale aliases in the persistent Worker workspace. */ export const workerAliasNameTable: AliasNameTable = Object.fromEntries( [...new Set(Object.values(languageAlias).flatMap((table) => Object.keys(table)))].map((name) => [ name, new RegExp( Object.values(languageAlias) .map((table) => '(?:' + (table[name]?.source ?? '^' + name + '$') + ')') .join('|'), ), ]), );