@khanacademy/math-input 21.0.0 → 21.0.2

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/index.js CHANGED
@@ -45,7 +45,7 @@ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
45
45
 
46
46
  // This file is processed by a Rollup plugin (replace) to inject the production
47
47
  const libName = "@khanacademy/math-input";
48
- const libVersion = "21.0.0";
48
+ const libVersion = "21.0.2";
49
49
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
50
50
 
51
51
  function _extends() {
@@ -1243,13 +1243,31 @@ function buildGenericCallback(str) {
1243
1243
  }
1244
1244
  };
1245
1245
  }
1246
+
1247
+ /**
1248
+ * This lets us use translated functions
1249
+ * (like tg->tan and sen->sin) when we know it's safe to.
1250
+ * This lets us progressively support translations without needing
1251
+ * to support every language all at once.
1252
+ *
1253
+ * @param {string} command - the translated command/function to check
1254
+ * @param {string[]} supportedTranslations - list of translations we support
1255
+ * @param {string} defaultCommand - what to fallback to if the command isn't supported
1256
+ */
1257
+ function buildTranslatableFunctionCallback(command, supportedTranslations, defaultCommand) {
1258
+ const cmd = supportedTranslations.includes(command) ? command : defaultCommand;
1259
+ return function (mathField) {
1260
+ mathField.write(`${cmd}\\left(\\right)`);
1261
+ mathField.keystroke("Left");
1262
+ };
1263
+ }
1246
1264
  function buildNormalFunctionCallback(command) {
1247
1265
  return function (mathField) {
1248
1266
  mathField.write(`\\${command}\\left(\\right)`);
1249
1267
  mathField.keystroke("Left");
1250
1268
  };
1251
1269
  }
1252
- const getKeyTranslator = locale => ({
1270
+ const getKeyTranslator = (locale, strings) => ({
1253
1271
  EXP: handleExponent,
1254
1272
  EXP_2: handleExponent,
1255
1273
  EXP_3: handleExponent,
@@ -1263,9 +1281,9 @@ const getKeyTranslator = locale => ({
1263
1281
  RIGHT: handleArrow,
1264
1282
  LOG: buildNormalFunctionCallback("log"),
1265
1283
  LN: buildNormalFunctionCallback("ln"),
1266
- SIN: buildNormalFunctionCallback("sin"),
1267
- COS: buildNormalFunctionCallback("cos"),
1268
- TAN: buildNormalFunctionCallback("tan"),
1284
+ COS: buildNormalFunctionCallback(strings.cos),
1285
+ SIN: buildTranslatableFunctionCallback(strings.sin, ["sin", "sen"], "sin"),
1286
+ TAN: buildTranslatableFunctionCallback(strings.tan, ["tan", "tg"], "tan"),
1269
1287
  CDOT: buildGenericCallback("\\cdot"),
1270
1288
  DECIMAL: buildGenericCallback(getDecimalSeparator(locale)),
1271
1289
  DIVIDE: buildGenericCallback("\\div"),
@@ -1407,7 +1425,7 @@ class MathWrapper {
1407
1425
  this.mathField?.setAriaLabel(ariaLabel);
1408
1426
  this.callbacks = callbacks;
1409
1427
  this.mobileKeyTranslator = {
1410
- ...getKeyTranslator(locale),
1428
+ ...getKeyTranslator(locale, strings),
1411
1429
  // note(Matthew): our mobile backspace logic is really complicated
1412
1430
  // and for some reason doesn't really work in the desktop experience.
1413
1431
  // So we default to the basic backspace functionality in the