@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/index.d.ts CHANGED
@@ -87,7 +87,7 @@ export { default as WIDGET_PROP_DENYLIST } from "./mixins/widget-prop-denylist";
87
87
  export type { PerseusOptions } from "./init";
88
88
  export type { ILogger, LogErrorOptions } from "./logging/log";
89
89
  export type { ServerItemRenderer as ServerItemRendererComponent } from "./server-item-renderer";
90
- export type { Alignment, APIOptions, APIOptionsWithDefaults, ChangeHandler, DeviceType, DomInsertCheckFn, EditorMode, FocusPath, ImageDict, ImageUploader, JiptLabelStore, JiptRenderer, PerseusDependencies, PerseusScore, Version, VideoData, VideoKind, WidgetExports, SharedRendererProps, } from "./types";
90
+ export type { Alignment, APIOptions, APIOptionsWithDefaults, ChangeHandler, DeviceType, DomInsertCheckFn, EditorMode, FocusPath, ImageDict, ImageUploader, JiptLabelStore, JiptRenderer, PerseusDependencies, PerseusDependenciesV2, PerseusScore, Version, VideoData, VideoKind, WidgetExports, SharedRendererProps, } from "./types";
91
91
  export type { ParsedValue } from "./util";
92
92
  export type { Hint, LegacyButtonSets, LockedFigure, LockedFigureColor, LockedFigureFillType, LockedFigureType, LockedPointType, LockedLineType, LockedVectorType, LockedEllipseType, LockedPolygonType, LockedFunctionType, LockedLabelType, LockedLineStyle, PerseusGraphType, PerseusAnswerArea, PerseusExpressionWidgetOptions, Range, Size, CollinearTuple, MathFormat, InputNumberWidget, // TODO(jeremy): remove?
93
93
  PerseusImageBackground, PerseusInputNumberWidgetOptions, PerseusInteractiveGraphWidgetOptions, PerseusItem, PerseusPhetSimulationWidgetOptions, PerseusPlotterWidgetOptions, PerseusPythonProgramWidgetOptions, PerseusRadioWidgetOptions, PerseusExampleWidgetOptions, PerseusSimpleMarkdownTesterWidgetOptions, PerseusRenderer, PerseusWidget, PerseusWidgetsMap, MultiItem, } from "./perseus-types";
package/dist/index.js CHANGED
@@ -36307,11 +36307,7 @@ function interactiveGraphValidator(userInput, rubric) {
36307
36307
 
36308
36308
  // If both of the guess points are on the correct line, it's
36309
36309
  // correct.
36310
- if (
36311
- // @ts-expect-error - TS2532 - Object is possibly 'undefined'. | TS2532 - Object is possibly 'undefined'.
36312
- collinear(correct[0], correct[1], guess[0]) &&
36313
- // @ts-expect-error - TS2532 - Object is possibly 'undefined'. | TS2532 - Object is possibly 'undefined'.
36314
- collinear(correct[0], correct[1], guess[1])) {
36310
+ if (collinear(correct[0], correct[1], guess[0]) && collinear(correct[0], correct[1], guess[1])) {
36315
36311
  return {
36316
36312
  type: "points",
36317
36313
  earned: 1,
@@ -36333,9 +36329,7 @@ function interactiveGraphValidator(userInput, rubric) {
36333
36329
  } else if (userInput.type === "quadratic" && rubric.correct.type === "quadratic" && userInput.coords != null) {
36334
36330
  // If the parabola coefficients match, it's correct.
36335
36331
  const guessCoeffs = getQuadraticCoefficients(userInput.coords);
36336
- const correctCoeffs = getQuadraticCoefficients(
36337
- // @ts-expect-error - TS2345 - Argument of type 'readonly Coord[] | undefined' is not assignable to parameter of type 'readonly Coord[]'.
36338
- rubric.correct.coords);
36332
+ const correctCoeffs = getQuadraticCoefficients(rubric.correct.coords);
36339
36333
  if (deepEq$2(guessCoeffs, correctCoeffs)) {
36340
36334
  return {
36341
36335
  type: "points",
@@ -36346,9 +36340,7 @@ function interactiveGraphValidator(userInput, rubric) {
36346
36340
  }
36347
36341
  } else if (userInput.type === "sinusoid" && rubric.correct.type === "sinusoid" && userInput.coords != null) {
36348
36342
  const guessCoeffs = getSinusoidCoefficients(userInput.coords);
36349
- const correctCoeffs = getSinusoidCoefficients(
36350
- // @ts-expect-error - TS2345 - Argument of type 'readonly Coord[] | undefined' is not assignable to parameter of type 'readonly Coord[]'.
36351
- rubric.correct.coords);
36343
+ const correctCoeffs = getSinusoidCoefficients(rubric.correct.coords);
36352
36344
  const canonicalGuessCoeffs = canonicalSineCoefficients$1(guessCoeffs);
36353
36345
  const canonicalCorrectCoeffs = canonicalSineCoefficients$1(correctCoeffs);
36354
36346
  // If the canonical coefficients match, it's correct.
@@ -36392,9 +36384,8 @@ function interactiveGraphValidator(userInput, rubric) {
36392
36384
  };
36393
36385
  }
36394
36386
  } else if (userInput.type === "polygon" && rubric.correct.type === "polygon" && userInput.coords != null) {
36395
- const guess = userInput.coords?.slice();
36396
- // @ts-expect-error - TS2322 - Type 'Coord[] | undefined' is not assignable to type 'Coord[]'.
36397
- const correct = rubric.correct.coords?.slice();
36387
+ const guess = userInput.coords.slice();
36388
+ const correct = rubric.correct.coords.slice();
36398
36389
  let match;
36399
36390
  if (rubric.correct.match === "similar") {
36400
36391
  match = similar(guess, correct, Number.POSITIVE_INFINITY);
@@ -36418,9 +36409,8 @@ function interactiveGraphValidator(userInput, rubric) {
36418
36409
  }
36419
36410
  } else if (userInput.type === "segment" && rubric.correct.type === "segment" && userInput.coords != null) {
36420
36411
  let guess = Util.deepClone(userInput.coords);
36421
- let correct = Util.deepClone(rubric.correct?.coords);
36412
+ let correct = Util.deepClone(rubric.correct.coords);
36422
36413
  guess = ___default["default"].invoke(guess, "sort").sort();
36423
- // @ts-expect-error - TS2345 - Argument of type '(readonly Coord[])[] | undefined' is not assignable to parameter of type 'Collection<any>'.
36424
36414
  correct = ___default["default"].invoke(correct, "sort").sort();
36425
36415
  if (deepEq$2(guess, correct)) {
36426
36416
  return {
@@ -36433,11 +36423,7 @@ function interactiveGraphValidator(userInput, rubric) {
36433
36423
  } else if (userInput.type === "ray" && rubric.correct.type === "ray" && userInput.coords != null) {
36434
36424
  const guess = userInput.coords;
36435
36425
  const correct = rubric.correct.coords;
36436
- if (
36437
- // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
36438
- deepEq$2(guess[0], correct[0]) &&
36439
- // @ts-expect-error - TS2532 - Object is possibly 'undefined'. | TS2532 - Object is possibly 'undefined'.
36440
- collinear(correct[0], correct[1], guess[1])) {
36426
+ if (deepEq$2(guess[0], correct[0]) && collinear(correct[0], correct[1], guess[1])) {
36441
36427
  return {
36442
36428
  type: "points",
36443
36429
  earned: 1,
@@ -44412,7 +44398,7 @@ const init = function (options) {
44412
44398
 
44413
44399
  // This file is processed by a Rollup plugin (replace) to inject the production
44414
44400
  const libName = "@khanacademy/perseus";
44415
- const libVersion = "41.0.0";
44401
+ const libVersion = "41.1.1";
44416
44402
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
44417
44403
 
44418
44404
  const apiVersion = {
@@ -47678,16 +47664,7 @@ const getValidWidgetIds = perseusItem => {
47678
47664
  };
47679
47665
 
47680
47666
  const deepEq = Util.deepEq;
47681
-
47682
- /**
47683
- * Helper to parse PerseusItem JSON
47684
- * Why not just use JSON.parse? We want:
47685
- * - To make sure types are correct
47686
- * - To give us a central place to validate/transform output if needed
47687
- * @param {string} json - the stringified PerseusItem JSON
47688
- * @returns {PerseusItem} the parsed PerseusItem object
47689
- */
47690
- function parsePerseusItem(json) {
47667
+ function isRealJSONParse(jsonParse) {
47691
47668
  const randomPhrase = buildRandomPhrase();
47692
47669
  const randomHintPhrase = buildRandomPhrase();
47693
47670
  const randomString = buildRandomString();
@@ -47740,15 +47717,10 @@ function parsePerseusItem(json) {
47740
47717
  }
47741
47718
  }
47742
47719
  });
47743
- // @ts-expect-error TS2550: Property 'replaceAll' does not exist on type 'string'.
47744
- const testJSON = buildTestData(testingObject.replaceAll('"', '\\"'));
47745
- const parsedJSON = JSON.parse(testJSON);
47746
- const parsedItemData = parsedJSON.data.assessmentItem.item.itemData;
47747
- const isNotCheating = deepEq(parsedItemData, testingObject);
47748
- if (isNotCheating) {
47749
- return JSON.parse(json);
47750
- }
47751
- throw new Error("Something went wrong.");
47720
+ const testJSON = buildTestData(testingObject.replace(/"/g, '\\"'));
47721
+ const parsedTestJSON = jsonParse(testJSON);
47722
+ const parsedTestItemData = parsedTestJSON.data.assessmentItem.item.itemData;
47723
+ return deepEq(parsedTestItemData, testingObject);
47752
47724
  }
47753
47725
  function buildRandomString() {
47754
47726
  let capitalize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
@@ -47775,6 +47747,23 @@ function buildTestData(testObject) {
47775
47747
  return `{"data":{"assessmentItem":{"__typename":"AssessmentItemOrError","error":null,"item":{"__typename":"AssessmentItem","id":"x890b3c70f3e8f4a6","itemData":"${testObject}","problemType":"Type 1","sha":"c7284a3ad65214b4e62bccce236d92f7f5d35941"}}}}`;
47776
47748
  }
47777
47749
 
47750
+ /**
47751
+ * Helper to parse PerseusItem JSON
47752
+ * Why not just use JSON.parse? We want:
47753
+ * - To make sure types are correct
47754
+ * - To give us a central place to validate/transform output if needed
47755
+ * @param {string} json - the stringified PerseusItem JSON
47756
+ * @returns {PerseusItem} the parsed PerseusItem object
47757
+ */
47758
+ function parsePerseusItem(json) {
47759
+ // Try to block a cheating vector which relies on monkey-patching
47760
+ // JSON.parse
47761
+ if (isRealJSONParse(JSON.parse)) {
47762
+ return JSON.parse(json);
47763
+ }
47764
+ throw new Error("Something went wrong.");
47765
+ }
47766
+
47778
47767
  const genericPerseusItemData = {
47779
47768
  question: {
47780
47769
  content: "",