@khanacademy/perseus 54.0.0 → 54.1.0

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
@@ -1,6 +1,6 @@
1
1
  import * as KAS from '@khanacademy/kas';
2
2
  import { MathInputI18nContext, CursorContext, getKeyTranslator, createMathField, getCursorContext, DesktopKeypad, convertDotToTimesByLocale, mathQuillInstance, KeypadInput, KeypadType, KeyArray, keypadElementPropType } from '@khanacademy/math-input';
3
- import { PerseusError, Errors, expressionLogic, getDecimalSeparator, approximateDeepEqual, pluck, CoreWidgetRegistry, getUpgradedWidgetOptions, mapObject, passageRefLogic, radioLogic, GrapherUtil as GrapherUtil$1, lockedFigureColors, lockedFigureFillStyles, approximateEqual, getMatrixSize, measurerLogic, addLibraryVersionToPerseusDebug, upgradeWidgetInfoToLatestVersion, getWidgetIdsFromContentByType } from '@khanacademy/perseus-core';
3
+ import { PerseusError, Errors, expressionLogic, getDecimalSeparator, approximateDeepEqual, pluck, CoreWidgetRegistry, getUpgradedWidgetOptions, mapObject, passageRefLogic, radioLogic, shuffle, random, GrapherUtil as GrapherUtil$1, lockedFigureColors, lockedFigureFillStyles, approximateEqual, shuffleMatcher, getMatrixSize, measurerLogic, addLibraryVersionToPerseusDebug, upgradeWidgetInfoToLatestVersion, getWidgetIdsFromContentByType } from '@khanacademy/perseus-core';
4
4
  export { isFailure, isSuccess, parseAndMigratePerseusArticle, parseAndMigratePerseusItem, parsePerseusItem } from '@khanacademy/perseus-core';
5
5
  import * as PerseusLinter from '@khanacademy/perseus-linter';
6
6
  import { linterContextDefault, Rule } from '@khanacademy/perseus-linter';
@@ -1939,54 +1939,6 @@ const rWidgetRule = /^\[\[\u2603 (([a-z-]+) ([0-9]+))\]\]/;
1939
1939
  const rTypeFromWidgetId = /^([a-z-]+) ([0-9]+)$/;
1940
1940
  const rWidgetParts = new RegExp(rWidgetRule.source + "$");
1941
1941
  const snowman = "\u2603";
1942
- const seededRNG$1 = function seededRNG(seed) {
1943
- let randomSeed = seed;
1944
- return function () {
1945
- // Robert Jenkins' 32 bit integer hash function.
1946
- let seed = randomSeed;
1947
- seed = seed + 0x7ed55d16 + (seed << 12) & 0xffffffff;
1948
- seed = (seed ^ 0xc761c23c ^ seed >>> 19) & 0xffffffff;
1949
- seed = seed + 0x165667b1 + (seed << 5) & 0xffffffff;
1950
- seed = (seed + 0xd3a2646c ^ seed << 9) & 0xffffffff;
1951
- seed = seed + 0xfd7046c5 + (seed << 3) & 0xffffffff;
1952
- seed = (seed ^ 0xb55a4f09 ^ seed >>> 16) & 0xffffffff;
1953
- return (randomSeed = seed & 0xfffffff) / 0x10000000;
1954
- };
1955
- };
1956
-
1957
- // Shuffle an array using a given random seed or function.
1958
- // If `ensurePermuted` is true, the input and ouput are guaranteed to be
1959
- // distinct permutations.
1960
- function shuffle$3(array, randomSeed, ensurePermuted = false) {
1961
- // Always return a copy of the input array
1962
- const shuffled = _.clone(array);
1963
-
1964
- // Handle edge cases (input array is empty or uniform)
1965
- if (!shuffled.length || _.all(shuffled, function (value) {
1966
- return _.isEqual(value, shuffled[0]);
1967
- })) {
1968
- return shuffled;
1969
- }
1970
- let random;
1971
- if (typeof randomSeed === "function") {
1972
- random = randomSeed;
1973
- } else {
1974
- random = seededRNG$1(randomSeed);
1975
- }
1976
- do {
1977
- // Fischer-Yates shuffle
1978
- for (let top = shuffled.length; top > 0; top--) {
1979
- const newEnd = Math.floor(random() * top);
1980
- const temp = shuffled[newEnd];
1981
-
1982
- // @ts-expect-error - TS2542 - Index signature in type 'readonly T[]' only permits reading.
1983
- shuffled[newEnd] = shuffled[top - 1];
1984
- // @ts-expect-error - TS2542 - Index signature in type 'readonly T[]' only permits reading.
1985
- shuffled[top - 1] = temp;
1986
- }
1987
- } while (ensurePermuted && _.isEqual(array, shuffled));
1988
- return shuffled;
1989
- }
1990
1942
 
1991
1943
  /**
1992
1944
  * TODO(somewhatabstract, FEI-3463):
@@ -2419,7 +2371,6 @@ const textarea = {
2419
2371
  * to translate it but don't need the extra dollar signs.
2420
2372
  */
2421
2373
  const unescapeMathMode$1 = label => label.startsWith("$") && label.endsWith("$") ? label.slice(1, -1) : label;
2422
- const random$1 = seededRNG$1(new Date().getTime() & 0xffffffff);
2423
2374
  const Util = {
2424
2375
  inputPathsEqual,
2425
2376
  nestedMap: nestedMap$2,
@@ -2427,8 +2378,6 @@ const Util = {
2427
2378
  rTypeFromWidgetId,
2428
2379
  rWidgetParts,
2429
2380
  snowman,
2430
- seededRNG: seededRNG$1,
2431
- shuffle: shuffle$3,
2432
2381
  split,
2433
2382
  firstNumericalParse: firstNumericalParse$1,
2434
2383
  stringArrayOfSize: stringArrayOfSize$1,
@@ -2456,8 +2405,7 @@ const Util = {
2456
2405
  getSvgUrl: getSvgUrl,
2457
2406
  getDataUrl: getDataUrl,
2458
2407
  textarea,
2459
- unescapeMathMode: unescapeMathMode$1,
2460
- random: random$1
2408
+ unescapeMathMode: unescapeMathMode$1
2461
2409
  };
2462
2410
 
2463
2411
  // TODO(LP-11481): Change the primary API we use for logging in Perseus to use
@@ -24369,11 +24317,6 @@ Radio$1.defaultProps = {
24369
24317
  showSolutions: "none"
24370
24318
  };
24371
24319
 
24372
- const {
24373
- shuffle: shuffle$2,
24374
- random
24375
- } = Util;
24376
-
24377
24320
  // Transforms the choices for display.
24378
24321
  const _choiceTransform = (widgetOptions, strings, problemNum) => {
24379
24322
  const _maybeRandomize = function _maybeRandomize(array) {
@@ -24384,7 +24327,7 @@ const _choiceTransform = (widgetOptions, strings, problemNum) => {
24384
24327
  // or if rendered within an article. This results in a predictable
24385
24328
  // shuffle order. To avoid this we use a random seed when `problemNum`
24386
24329
  // is `undefined`.
24387
- return widgetOptions.randomize ? shuffle$2(array, randomSeed != null ? randomSeed : 0) : array;
24330
+ return widgetOptions.randomize ? shuffle(array, randomSeed != null ? randomSeed : 0) : array;
24388
24331
  };
24389
24332
  const _addNoneOfAbove = function _addNoneOfAbove(choices) {
24390
24333
  let noneOfTheAbove = null;
@@ -24614,8 +24557,7 @@ class Categorizer extends React.Component {
24614
24557
  const isMobile = this.props.apiOptions.isMobile;
24615
24558
  let indexedItems = this.props.items.map((item, n) => [item, n]);
24616
24559
  if (this.props.randomizeItems) {
24617
- // @ts-expect-error - TS4104 - The type 'readonly (string | number)[][]' is 'readonly' and cannot be assigned to the mutable type '(string | number)[][]'. | TS2345 - Argument of type 'number | null | undefined' is not assignable to parameter of type 'number | RNG'.
24618
- indexedItems = Util.shuffle(indexedItems, this.props.problemNum);
24560
+ indexedItems = shuffle(indexedItems, this.props.problemNum);
24619
24561
  }
24620
24562
  const table = /*#__PURE__*/React.createElement("table", {
24621
24563
  className: "categorizer-table " + css(styles$n.mobileTable)
@@ -24641,9 +24583,7 @@ class Categorizer extends React.Component {
24641
24583
  const uniqueId = self.state.uniqueId + "_" + itemNum;
24642
24584
  return /*#__PURE__*/React.createElement("tr", {
24643
24585
  key: itemNum
24644
- }, /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement(Renderer
24645
- // @ts-expect-error - TS2322 - Type 'string | number' is not assignable to type 'string | undefined'.
24646
- , {
24586
+ }, /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement(Renderer, {
24647
24587
  content: item,
24648
24588
  linterContext: this.props.linterContext,
24649
24589
  strings: this.context.strings
@@ -37013,10 +36953,6 @@ const getPromptJSON$9 = (renderProps, userInput) => {
37013
36953
  };
37014
36954
  };
37015
36955
 
37016
- const {
37017
- shuffle: shuffle$1,
37018
- seededRNG
37019
- } = Util;
37020
36956
  const HACKY_CSS_CLASSNAME = "perseus-widget-matcher";
37021
36957
  class Matcher extends React.Component {
37022
36958
  constructor(...args) {
@@ -37108,16 +37044,16 @@ class Matcher extends React.Component {
37108
37044
  }, "1")));
37109
37045
  }
37110
37046
 
37111
- // Use the same random() function to shuffle both columns sequentially
37112
- const rng = seededRNG(this.props.problemNum);
37113
- let left;
37114
- if (!this.props.orderMatters) {
37115
- // If the order doesn't matter, don't shuffle the left column
37116
- left = this.props.left;
37117
- } else {
37118
- left = shuffle$1(this.props.left, rng, /* ensurePermuted */true);
37119
- }
37120
- const right = shuffle$1(this.props.right, rng, /* ensurePermuted */true);
37047
+ /* TODO(LEMS-2841):
37048
+ Once the getMatcherPublicWidgetOptions function gets connected to the
37049
+ widget, we'll need to update this to the line below to only shuffle
37050
+ on the server.
37051
+ const {left, right} = this.props;
37052
+ */
37053
+ const {
37054
+ left,
37055
+ right
37056
+ } = shuffleMatcher(this.props);
37121
37057
  const showLabels = _.any(this.props.labels);
37122
37058
  const constraints = {
37123
37059
  height: _.max([this.state.leftHeight, this.state.rightHeight])
@@ -40893,9 +40829,6 @@ const getPromptJSON$1 = userInput => {
40893
40829
  };
40894
40830
  };
40895
40831
 
40896
- const {
40897
- shuffle
40898
- } = Util;
40899
40832
  class Sorter extends React.Component {
40900
40833
  constructor(...args) {
40901
40834
  super(...args);
@@ -40947,6 +40880,10 @@ class Sorter extends React.Component {
40947
40880
  return getPromptJSON$1(this.getUserInput());
40948
40881
  }
40949
40882
  render() {
40883
+ // TODO(LEMS-2841): Remove client-side shuffle once receiving public
40884
+ // options. The correct field will already be shuffled.
40885
+ // Probably easiest to replace "options" with "this.props.correct" when
40886
+ // setting up Sortable below. Or use the assignment to rename for clarity.
40950
40887
  const options = shuffle(this.props.correct, this.props.problemNum, /* ensurePermuted */true);
40951
40888
  const {
40952
40889
  apiOptions
@@ -41377,7 +41314,7 @@ const init = function init() {
41377
41314
 
41378
41315
  // This file is processed by a Rollup plugin (replace) to inject the production
41379
41316
  const libName = "@khanacademy/perseus";
41380
- const libVersion = "54.0.0";
41317
+ const libVersion = "54.1.0";
41381
41318
  addLibraryVersionToPerseusDebug(libName, libVersion);
41382
41319
 
41383
41320
  const apiVersion = {