@khanacademy/perseus 41.0.0 → 41.1.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/es/index.js CHANGED
@@ -35924,11 +35924,7 @@ function interactiveGraphValidator(userInput, rubric) {
35924
35924
 
35925
35925
  // If both of the guess points are on the correct line, it's
35926
35926
  // correct.
35927
- if (
35928
- // @ts-expect-error - TS2532 - Object is possibly 'undefined'. | TS2532 - Object is possibly 'undefined'.
35929
- collinear(correct[0], correct[1], guess[0]) &&
35930
- // @ts-expect-error - TS2532 - Object is possibly 'undefined'. | TS2532 - Object is possibly 'undefined'.
35931
- collinear(correct[0], correct[1], guess[1])) {
35927
+ if (collinear(correct[0], correct[1], guess[0]) && collinear(correct[0], correct[1], guess[1])) {
35932
35928
  return {
35933
35929
  type: "points",
35934
35930
  earned: 1,
@@ -35950,9 +35946,7 @@ function interactiveGraphValidator(userInput, rubric) {
35950
35946
  } else if (userInput.type === "quadratic" && rubric.correct.type === "quadratic" && userInput.coords != null) {
35951
35947
  // If the parabola coefficients match, it's correct.
35952
35948
  const guessCoeffs = getQuadraticCoefficients(userInput.coords);
35953
- const correctCoeffs = getQuadraticCoefficients(
35954
- // @ts-expect-error - TS2345 - Argument of type 'readonly Coord[] | undefined' is not assignable to parameter of type 'readonly Coord[]'.
35955
- rubric.correct.coords);
35949
+ const correctCoeffs = getQuadraticCoefficients(rubric.correct.coords);
35956
35950
  if (deepEq$2(guessCoeffs, correctCoeffs)) {
35957
35951
  return {
35958
35952
  type: "points",
@@ -35963,9 +35957,7 @@ function interactiveGraphValidator(userInput, rubric) {
35963
35957
  }
35964
35958
  } else if (userInput.type === "sinusoid" && rubric.correct.type === "sinusoid" && userInput.coords != null) {
35965
35959
  const guessCoeffs = getSinusoidCoefficients(userInput.coords);
35966
- const correctCoeffs = getSinusoidCoefficients(
35967
- // @ts-expect-error - TS2345 - Argument of type 'readonly Coord[] | undefined' is not assignable to parameter of type 'readonly Coord[]'.
35968
- rubric.correct.coords);
35960
+ const correctCoeffs = getSinusoidCoefficients(rubric.correct.coords);
35969
35961
  const canonicalGuessCoeffs = canonicalSineCoefficients$1(guessCoeffs);
35970
35962
  const canonicalCorrectCoeffs = canonicalSineCoefficients$1(correctCoeffs);
35971
35963
  // If the canonical coefficients match, it's correct.
@@ -36009,10 +36001,8 @@ function interactiveGraphValidator(userInput, rubric) {
36009
36001
  };
36010
36002
  }
36011
36003
  } else if (userInput.type === "polygon" && rubric.correct.type === "polygon" && userInput.coords != null) {
36012
- var _userInput$coords, _rubric$correct$coord;
36013
- const guess = (_userInput$coords = userInput.coords) == null ? void 0 : _userInput$coords.slice();
36014
- // @ts-expect-error - TS2322 - Type 'Coord[] | undefined' is not assignable to type 'Coord[]'.
36015
- const correct = (_rubric$correct$coord = rubric.correct.coords) == null ? void 0 : _rubric$correct$coord.slice();
36004
+ const guess = userInput.coords.slice();
36005
+ const correct = rubric.correct.coords.slice();
36016
36006
  let match;
36017
36007
  if (rubric.correct.match === "similar") {
36018
36008
  match = similar(guess, correct, Number.POSITIVE_INFINITY);
@@ -36035,11 +36025,9 @@ function interactiveGraphValidator(userInput, rubric) {
36035
36025
  };
36036
36026
  }
36037
36027
  } else if (userInput.type === "segment" && rubric.correct.type === "segment" && userInput.coords != null) {
36038
- var _rubric$correct;
36039
36028
  let guess = Util.deepClone(userInput.coords);
36040
- let correct = Util.deepClone((_rubric$correct = rubric.correct) == null ? void 0 : _rubric$correct.coords);
36029
+ let correct = Util.deepClone(rubric.correct.coords);
36041
36030
  guess = _.invoke(guess, "sort").sort();
36042
- // @ts-expect-error - TS2345 - Argument of type '(readonly Coord[])[] | undefined' is not assignable to parameter of type 'Collection<any>'.
36043
36031
  correct = _.invoke(correct, "sort").sort();
36044
36032
  if (deepEq$2(guess, correct)) {
36045
36033
  return {
@@ -36052,11 +36040,7 @@ function interactiveGraphValidator(userInput, rubric) {
36052
36040
  } else if (userInput.type === "ray" && rubric.correct.type === "ray" && userInput.coords != null) {
36053
36041
  const guess = userInput.coords;
36054
36042
  const correct = rubric.correct.coords;
36055
- if (
36056
- // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
36057
- deepEq$2(guess[0], correct[0]) &&
36058
- // @ts-expect-error - TS2532 - Object is possibly 'undefined'. | TS2532 - Object is possibly 'undefined'.
36059
- collinear(correct[0], correct[1], guess[1])) {
36043
+ if (deepEq$2(guess[0], correct[0]) && collinear(correct[0], correct[1], guess[1])) {
36060
36044
  return {
36061
36045
  type: "points",
36062
36046
  earned: 1,
@@ -44046,7 +44030,7 @@ const init = function init(options) {
44046
44030
 
44047
44031
  // This file is processed by a Rollup plugin (replace) to inject the production
44048
44032
  const libName = "@khanacademy/perseus";
44049
- const libVersion = "41.0.0";
44033
+ const libVersion = "41.1.1";
44050
44034
  addLibraryVersionToPerseusDebug(libName, libVersion);
44051
44035
 
44052
44036
  const apiVersion = {
@@ -47301,16 +47285,7 @@ const getValidWidgetIds = perseusItem => {
47301
47285
  };
47302
47286
 
47303
47287
  const deepEq = Util.deepEq;
47304
-
47305
- /**
47306
- * Helper to parse PerseusItem JSON
47307
- * Why not just use JSON.parse? We want:
47308
- * - To make sure types are correct
47309
- * - To give us a central place to validate/transform output if needed
47310
- * @param {string} json - the stringified PerseusItem JSON
47311
- * @returns {PerseusItem} the parsed PerseusItem object
47312
- */
47313
- function parsePerseusItem(json) {
47288
+ function isRealJSONParse(jsonParse) {
47314
47289
  const randomPhrase = buildRandomPhrase();
47315
47290
  const randomHintPhrase = buildRandomPhrase();
47316
47291
  const randomString = buildRandomString();
@@ -47363,15 +47338,10 @@ function parsePerseusItem(json) {
47363
47338
  }
47364
47339
  }
47365
47340
  });
47366
- // @ts-expect-error TS2550: Property 'replaceAll' does not exist on type 'string'.
47367
- const testJSON = buildTestData(testingObject.replaceAll('"', '\\"'));
47368
- const parsedJSON = JSON.parse(testJSON);
47369
- const parsedItemData = parsedJSON.data.assessmentItem.item.itemData;
47370
- const isNotCheating = deepEq(parsedItemData, testingObject);
47371
- if (isNotCheating) {
47372
- return JSON.parse(json);
47373
- }
47374
- throw new Error("Something went wrong.");
47341
+ const testJSON = buildTestData(testingObject.replace(/"/g, '\\"'));
47342
+ const parsedTestJSON = jsonParse(testJSON);
47343
+ const parsedTestItemData = parsedTestJSON.data.assessmentItem.item.itemData;
47344
+ return deepEq(parsedTestItemData, testingObject);
47375
47345
  }
47376
47346
  function buildRandomString(capitalize = false) {
47377
47347
  let randomString = "";
@@ -47397,6 +47367,23 @@ function buildTestData(testObject) {
47397
47367
  return `{"data":{"assessmentItem":{"__typename":"AssessmentItemOrError","error":null,"item":{"__typename":"AssessmentItem","id":"x890b3c70f3e8f4a6","itemData":"${testObject}","problemType":"Type 1","sha":"c7284a3ad65214b4e62bccce236d92f7f5d35941"}}}}`;
47398
47368
  }
47399
47369
 
47370
+ /**
47371
+ * Helper to parse PerseusItem JSON
47372
+ * Why not just use JSON.parse? We want:
47373
+ * - To make sure types are correct
47374
+ * - To give us a central place to validate/transform output if needed
47375
+ * @param {string} json - the stringified PerseusItem JSON
47376
+ * @returns {PerseusItem} the parsed PerseusItem object
47377
+ */
47378
+ function parsePerseusItem(json) {
47379
+ // Try to block a cheating vector which relies on monkey-patching
47380
+ // JSON.parse
47381
+ if (isRealJSONParse(JSON.parse)) {
47382
+ return JSON.parse(json);
47383
+ }
47384
+ throw new Error("Something went wrong.");
47385
+ }
47386
+
47400
47387
  const genericPerseusItemData = {
47401
47388
  question: {
47402
47389
  content: "",