@khanacademy/perseus-core 8.0.0 → 9.0.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.
@@ -50,8 +50,8 @@ export type ShowSolutions = "all" | "selected" | "none";
50
50
  *
51
51
  * ```
52
52
  * interface DummyRegistry {
53
- * categorizer: { categories: ReadonlyArray<string> };
54
- * dropdown: { choices: ReadonlyArray<string> }:
53
+ * categorizer: { categories: string[] };
54
+ * dropdown: { choices: string[] }:
55
55
  * }
56
56
  * ```
57
57
  *
@@ -65,8 +65,8 @@ export type ShowSolutions = "all" | "selected" | "none";
65
65
  *
66
66
  * ```
67
67
  * type DummyMap = {
68
- * `categorizer ${number}`: { categories: ReadonlyArray<string> };
69
- * `dropdown ${number}`: { choices: ReadonlyArray<string> };
68
+ * `categorizer ${number}`: { categories: string[] };
69
+ * `dropdown ${number}`: { choices: string[] };
70
70
  * }
71
71
  * ```
72
72
  *
@@ -192,14 +192,14 @@ export type PerseusWidget = PerseusWidgetTypes[keyof PerseusWidgetTypes];
192
192
  */
193
193
  export type PerseusItem = {
194
194
  question: PerseusRenderer;
195
- hints: ReadonlyArray<Hint>;
195
+ hints: Hint[];
196
196
  answerArea: PerseusAnswerArea | null | undefined;
197
197
  };
198
198
  /**
199
199
  * A "PerseusArticle" is an item that is meant to be rendered as an article.
200
200
  * This item is never scored and is rendered by the `ArticleRenderer`.
201
201
  */
202
- export type PerseusArticle = PerseusRenderer | ReadonlyArray<PerseusRenderer>;
202
+ export type PerseusArticle = PerseusRenderer | PerseusRenderer[];
203
203
  export type Version = {
204
204
  major: number;
205
205
  minor: number;
@@ -316,18 +316,18 @@ export type PerseusImageBackground = {
316
316
  export type MarkingsType = "axes" | "graph" | "grid" | "none";
317
317
  export type AxisLabelLocation = "onAxis" | "alongEdge";
318
318
  export type PerseusCategorizerWidgetOptions = {
319
- items: ReadonlyArray<string>;
320
- categories: ReadonlyArray<string>;
319
+ items: string[];
320
+ categories: string[];
321
321
  randomizeItems: boolean;
322
322
  static: boolean;
323
- values: ReadonlyArray<number>;
323
+ values: number[];
324
324
  highlightLint?: boolean;
325
325
  linterContext?: PerseusLinterContext;
326
326
  };
327
327
  export type PerseusLinterContext = {
328
328
  contentType: string;
329
- paths: ReadonlyArray<string>;
330
- stack: ReadonlyArray<string>;
329
+ paths: string[];
330
+ stack: string[];
331
331
  };
332
332
  export type PerseusDefinitionWidgetOptions = {
333
333
  togglePrompt: string;
@@ -335,7 +335,7 @@ export type PerseusDefinitionWidgetOptions = {
335
335
  static: boolean;
336
336
  };
337
337
  export type PerseusDropdownWidgetOptions = {
338
- choices: ReadonlyArray<PerseusDropdownChoice>;
338
+ choices: PerseusDropdownChoice[];
339
339
  placeholder: string;
340
340
  static: boolean;
341
341
  visibleLabel?: string;
@@ -352,13 +352,13 @@ export type PerseusExplanationWidgetOptions = {
352
352
  widgets: PerseusWidgetsMap;
353
353
  static: boolean;
354
354
  };
355
- export type LegacyButtonSets = ReadonlyArray<"basic" | "basic+div" | "trig" | "prealgebra" | "logarithms" | "basic relations" | "advanced relations" | "scientific">;
355
+ export type LegacyButtonSets = Array<"basic" | "basic+div" | "trig" | "prealgebra" | "logarithms" | "basic relations" | "advanced relations" | "scientific">;
356
356
  export type PerseusExpressionWidgetOptions = {
357
- answerForms: ReadonlyArray<PerseusExpressionAnswerForm>;
357
+ answerForms: PerseusExpressionAnswerForm[];
358
358
  buttonSets: LegacyButtonSets;
359
- functions: ReadonlyArray<string>;
359
+ functions: string[];
360
360
  times: boolean;
361
- extraKeys?: ReadonlyArray<KeypadKey>;
361
+ extraKeys?: KeypadKey[];
362
362
  visibleLabel?: string;
363
363
  ariaLabel?: string;
364
364
  buttonsVisible?: "always" | "never" | "focused";
@@ -384,7 +384,7 @@ export type PerseusGradedGroupWidgetOptions = {
384
384
  };
385
385
  };
386
386
  export type PerseusGradedGroupSetWidgetOptions = {
387
- gradedGroups: ReadonlyArray<PerseusGradedGroupWidgetOptions>;
387
+ gradedGroups: PerseusGradedGroupWidgetOptions[];
388
388
  };
389
389
  export type GraphRange = [
390
390
  x: [min: number, max: number],
@@ -415,7 +415,7 @@ export type GrapherAnswerTypes = {
415
415
  coords: null | [Coord, Coord];
416
416
  };
417
417
  export type PerseusGrapherWidgetOptions = {
418
- availableTypes: ReadonlyArray<"absolute_value" | "exponential" | "linear" | "logarithm" | "quadratic" | "sinusoid" | "tangent">;
418
+ availableTypes: Array<"absolute_value" | "exponential" | "linear" | "logarithm" | "quadratic" | "sinusoid" | "tangent">;
419
419
  correct: GrapherAnswerTypes;
420
420
  graph: {
421
421
  backgroundImage: {
@@ -427,7 +427,7 @@ export type PerseusGrapherWidgetOptions = {
427
427
  width?: number;
428
428
  };
429
429
  box?: [number, number];
430
- editableSettings?: ReadonlyArray<"graph" | "snap" | "image" | "measure">;
430
+ editableSettings?: Array<"graph" | "snap" | "image" | "measure">;
431
431
  gridStep?: [number, number];
432
432
  labels: [string, string];
433
433
  markings: MarkingsType;
@@ -449,14 +449,14 @@ export type PerseusImageWidgetOptions = {
449
449
  alt?: string;
450
450
  backgroundImage: PerseusImageBackground;
451
451
  static?: boolean;
452
- labels?: ReadonlyArray<PerseusImageLabel>;
452
+ labels?: Array<PerseusImageLabel>;
453
453
  range?: [Interval, Interval];
454
454
  box?: Size;
455
455
  };
456
456
  export type PerseusImageLabel = {
457
457
  content: string;
458
458
  alignment: string;
459
- coordinates: ReadonlyArray<number>;
459
+ coordinates: number[];
460
460
  };
461
461
  export type PerseusInteractiveGraphWidgetOptions = {
462
462
  step: [number, number];
@@ -467,7 +467,7 @@ export type PerseusInteractiveGraphWidgetOptions = {
467
467
  * The type of markings to display on the graph.
468
468
  */
469
469
  markings: MarkingsType;
470
- labels?: ReadonlyArray<string>;
470
+ labels?: string[];
471
471
  /**
472
472
  * Specifies the location of the labels on the graph. default: "onAxis".
473
473
  * - "onAxis": Labels are positioned on the axis at the right (x) and top (y) of the graph.
@@ -503,7 +503,7 @@ export type PerseusInteractiveGraphWidgetOptions = {
503
503
  range: GraphRange;
504
504
  graph: PerseusGraphType;
505
505
  correct: PerseusGraphType;
506
- lockedFigures?: ReadonlyArray<LockedFigure>;
506
+ lockedFigures?: LockedFigure[];
507
507
  fullGraphAriaLabel?: string;
508
508
  fullGraphAriaDescription?: string;
509
509
  };
@@ -554,7 +554,7 @@ export type LockedEllipseType = {
554
554
  };
555
555
  export type LockedPolygonType = {
556
556
  type: "polygon";
557
- points: ReadonlyArray<Coord>;
557
+ points: Coord[];
558
558
  color: LockedFigureColor;
559
559
  showVertices: boolean;
560
560
  fillStyle: LockedFigureFillType;
@@ -629,8 +629,8 @@ export type PerseusGraphTypeNone = {
629
629
  export type PerseusGraphTypePoint = {
630
630
  type: "point";
631
631
  numPoints?: number | "unlimited";
632
- coords?: ReadonlyArray<Coord> | null;
633
- startCoords?: ReadonlyArray<Coord>;
632
+ coords?: Coord[] | null;
633
+ startCoords?: Coord[];
634
634
  } & PerseusGraphTypeCommon;
635
635
  export type PerseusGraphTypePolygon = {
636
636
  type: "polygon";
@@ -639,8 +639,8 @@ export type PerseusGraphTypePolygon = {
639
639
  showSides?: boolean;
640
640
  snapTo?: "grid" | "angles" | "sides";
641
641
  match?: "similar" | "congruent" | "approx" | "exact";
642
- coords?: ReadonlyArray<Coord> | null;
643
- startCoords?: ReadonlyArray<Coord>;
642
+ coords?: Coord[] | null;
643
+ startCoords?: Coord[];
644
644
  } & PerseusGraphTypeCommon;
645
645
  export type PerseusGraphTypeQuadratic = {
646
646
  type: "quadratic";
@@ -655,8 +655,8 @@ export type PerseusGraphTypeSegment = {
655
655
  } & PerseusGraphTypeCommon;
656
656
  export type PerseusGraphTypeSinusoid = {
657
657
  type: "sinusoid";
658
- coords?: ReadonlyArray<Coord> | null;
659
- startCoords?: ReadonlyArray<Coord>;
658
+ coords?: Coord[] | null;
659
+ startCoords?: Coord[];
660
660
  } & PerseusGraphTypeCommon;
661
661
  export type PerseusGraphTypeRay = {
662
662
  type: "ray";
@@ -687,12 +687,12 @@ type NoneGraphCorrect = {
687
687
  };
688
688
  type PointGraphCorrect = {
689
689
  type: "point";
690
- coords: ReadonlyArray<Coord>;
690
+ coords: Coord[];
691
691
  };
692
692
  type PolygonGraphCorrect = {
693
693
  type: "polygon";
694
694
  match: "similar" | "congruent" | "approx";
695
- coords: ReadonlyArray<Coord>;
695
+ coords: Coord[];
696
696
  };
697
697
  type QuadraticGraphCorrect = {
698
698
  type: "quadratic";
@@ -712,36 +712,36 @@ type RayGraphCorrect = {
712
712
  };
713
713
  export type PerseusGraphCorrectType = AngleGraphCorrect | CircleGraphCorrect | LinearGraphCorrect | LinearSystemGraphCorrect | NoneGraphCorrect | PointGraphCorrect | PolygonGraphCorrect | QuadraticGraphCorrect | RayGraphCorrect | SegmentGraphCorrect | SinusoidGraphCorrect;
714
714
  export type PerseusLabelImageWidgetOptions = {
715
- choices: ReadonlyArray<string>;
715
+ choices: string[];
716
716
  imageUrl: string;
717
717
  imageAlt: string;
718
718
  imageHeight: number;
719
719
  imageWidth: number;
720
- markers: ReadonlyArray<PerseusLabelImageMarker>;
720
+ markers: PerseusLabelImageMarker[];
721
721
  hideChoicesFromInstructions: boolean;
722
722
  multipleAnswers: boolean;
723
723
  static: boolean;
724
724
  };
725
725
  export type PerseusLabelImageMarker = {
726
- answers: ReadonlyArray<string>;
726
+ answers: string[];
727
727
  label: string;
728
728
  x: number;
729
729
  y: number;
730
730
  };
731
731
  export type PerseusMatcherWidgetOptions = {
732
- labels: ReadonlyArray<string>;
733
- left: ReadonlyArray<string>;
734
- right: ReadonlyArray<string>;
732
+ labels: string[];
733
+ left: string[];
734
+ right: string[];
735
735
  orderMatters: boolean;
736
736
  padding: boolean;
737
737
  };
738
- export type PerseusMatrixWidgetAnswers = ReadonlyArray<ReadonlyArray<number>>;
738
+ export type PerseusMatrixWidgetAnswers = number[][];
739
739
  export type PerseusMatrixWidgetOptions = {
740
740
  prefix?: string | undefined;
741
741
  suffix?: string | undefined;
742
742
  answers: PerseusMatrixWidgetAnswers;
743
- cursorPosition?: ReadonlyArray<number> | undefined;
744
- matrixBoardSize: ReadonlyArray<number>;
743
+ cursorPosition?: number[] | undefined;
744
+ matrixBoardSize: number[];
745
745
  static?: boolean | undefined;
746
746
  };
747
747
  export type PerseusMeasurerWidgetOptions = {
@@ -770,7 +770,7 @@ export type PerseusNumericInputAnswerForm = {
770
770
  */
771
771
  export type PerseusNumericInputSimplify = "required" | "enforced" | "optional";
772
772
  export type PerseusNumericInputWidgetOptions = {
773
- answers: ReadonlyArray<PerseusNumericInputAnswer>;
773
+ answers: PerseusNumericInputAnswer[];
774
774
  labelText?: string | undefined;
775
775
  size: string;
776
776
  coefficient: boolean;
@@ -781,18 +781,18 @@ export type PerseusNumericInputAnswer = {
781
781
  message: string;
782
782
  value?: number | null;
783
783
  status: string;
784
- answerForms?: ReadonlyArray<MathFormat>;
784
+ answerForms?: MathFormat[];
785
785
  strict: boolean;
786
786
  maxError?: number | null;
787
787
  simplify: PerseusNumericInputSimplify;
788
788
  };
789
789
  export type PerseusNumberLineWidgetOptions = {
790
- range: ReadonlyArray<number>;
791
- labelRange: ReadonlyArray<number | null>;
790
+ range: number[];
791
+ labelRange: Array<number | null>;
792
792
  labelStyle: string;
793
793
  labelTicks: boolean;
794
794
  isTickCtrl?: boolean | null;
795
- divisionRange: ReadonlyArray<number>;
795
+ divisionRange: number[];
796
796
  numDivisions?: number | null;
797
797
  snapDivisions: number;
798
798
  tickStep?: number | null;
@@ -803,9 +803,9 @@ export type PerseusNumberLineWidgetOptions = {
803
803
  static: boolean;
804
804
  };
805
805
  export type PerseusOrdererWidgetOptions = {
806
- options: ReadonlyArray<PerseusRenderer>;
807
- correctOptions: ReadonlyArray<PerseusRenderer>;
808
- otherOptions: ReadonlyArray<PerseusRenderer>;
806
+ options: PerseusRenderer[];
807
+ correctOptions: PerseusRenderer[];
808
+ otherOptions: PerseusRenderer[];
809
809
  height: "normal" | "auto";
810
810
  layout: "horizontal" | "vertical";
811
811
  };
@@ -824,22 +824,22 @@ export type PerseusPassageRefWidgetOptions = {
824
824
  export declare const plotterPlotTypes: readonly ["bar", "line", "pic", "histogram", "dotplot"];
825
825
  export type PlotType = (typeof plotterPlotTypes)[number];
826
826
  export type PerseusPlotterWidgetOptions = {
827
- labels: ReadonlyArray<string>;
828
- categories: ReadonlyArray<string>;
827
+ labels: string[];
828
+ categories: string[];
829
829
  type: PlotType;
830
830
  maxY: number;
831
831
  scaleY: number;
832
832
  labelInterval?: number | null;
833
833
  snapsPerLine: number;
834
- starting: ReadonlyArray<number>;
835
- correct: ReadonlyArray<number>;
834
+ starting: number[];
835
+ correct: number[];
836
836
  picUrl?: string | null;
837
837
  picSize?: number | null;
838
838
  picBoxHeight?: number | null;
839
- plotDimensions: ReadonlyArray<number>;
839
+ plotDimensions: number[];
840
840
  };
841
841
  export type PerseusRadioWidgetOptions = {
842
- choices: ReadonlyArray<PerseusRadioChoice>;
842
+ choices: PerseusRadioChoice[];
843
843
  hasNoneOfTheAbove?: boolean;
844
844
  countChoices?: boolean;
845
845
  numCorrect?: number;
@@ -858,25 +858,25 @@ export type PerseusRadioChoice = {
858
858
  widgets?: PerseusWidgetsMap;
859
859
  };
860
860
  export type PerseusSorterWidgetOptions = {
861
- correct: ReadonlyArray<string>;
861
+ correct: string[];
862
862
  padding: boolean;
863
863
  layout: "horizontal" | "vertical";
864
864
  };
865
865
  export type PerseusTableWidgetOptions = {
866
- headers: ReadonlyArray<string>;
866
+ headers: string[];
867
867
  rows: number;
868
868
  columns: number;
869
- answers: ReadonlyArray<ReadonlyArray<string>>;
869
+ answers: string[][];
870
870
  };
871
871
  export type PerseusInteractionWidgetOptions = {
872
872
  graph: PerseusInteractionGraph;
873
- elements: ReadonlyArray<PerseusInteractionElement>;
873
+ elements: PerseusInteractionElement[];
874
874
  static: boolean;
875
875
  };
876
876
  export type PerseusInteractionGraph = {
877
- editableSettings?: ReadonlyArray<"canvas" | "graph">;
877
+ editableSettings?: Array<"canvas" | "graph">;
878
878
  box: Size;
879
- labels: ReadonlyArray<string>;
879
+ labels: string[];
880
880
  range: [Interval, Interval];
881
881
  gridStep: [number, number];
882
882
  /**
@@ -1001,7 +1001,7 @@ export type PerseusInteractionRectangleElementOptions = {
1001
1001
  export type PerseusCSProgramWidgetOptions = {
1002
1002
  programID: string;
1003
1003
  programType?: any;
1004
- settings: ReadonlyArray<PerseusCSProgramSetting>;
1004
+ settings: PerseusCSProgramSetting[];
1005
1005
  showEditor: boolean;
1006
1006
  showButtons: boolean;
1007
1007
  height: number;
@@ -1017,7 +1017,7 @@ export type PerseusPythonProgramWidgetOptions = {
1017
1017
  };
1018
1018
  export type PerseusIFrameWidgetOptions = {
1019
1019
  url: string;
1020
- settings?: ReadonlyArray<PerseusCSProgramSetting>;
1020
+ settings?: PerseusCSProgramSetting[];
1021
1021
  width: number | string;
1022
1022
  height: number | string;
1023
1023
  allowFullScreen: boolean;
package/dist/es/index.js CHANGED
@@ -171,7 +171,7 @@ const parsePerseusItem$1=object({question:parsePerseusRenderer,hints:defaulted(a
171
171
 
172
172
  function parsePerseusItem(json){if(isRealJSONParse(JSON.parse)){return JSON.parse(json)}throw new Error("Something went wrong.")}function parseAndMigratePerseusItem(json){throwErrorIfCheatingDetected();const object=JSON.parse(json);const result=parse(object,parsePerseusItem$1);if(isFailure(result)){return failure({message:result.detail,invalidObject:object})}return result}function parseAndMigratePerseusArticle(json){throwErrorIfCheatingDetected();const object=JSON.parse(json);const result=parse(object,parsePerseusArticle);if(isFailure(result)){return failure({message:result.detail,invalidObject:object})}return result}function throwErrorIfCheatingDetected(){if(!isRealJSONParse(JSON.parse)){throw new Error("Something went wrong.")}}
173
173
 
174
- const libName="@khanacademy/perseus-core";const libVersion="8.0.0";addLibraryVersionToPerseusDebug(libName,libVersion);
174
+ const libName="@khanacademy/perseus-core";const libVersion="9.0.0";addLibraryVersionToPerseusDebug(libName,libVersion);
175
175
 
176
176
  const Errors=Object.freeze({Unknown:"Unknown",Internal:"Internal",InvalidInput:"InvalidInput",NotAllowed:"NotAllowed",TransientService:"TransientService",Service:"Service"});
177
177
 
@@ -229,7 +229,7 @@ function getLabelImagePublicWidgetOptions(options){return {...options,markers:op
229
229
 
230
230
  const defaultWidgetOptions$f={choices:[],imageAlt:"",imageUrl:"",imageWidth:0,imageHeight:0,markers:[],multipleAnswers:false,hideChoicesFromInstructions:false};const labelImageWidgetLogic={name:"label-image",defaultWidgetOptions: defaultWidgetOptions$f,getPublicWidgetOptions:getLabelImagePublicWidgetOptions};
231
231
 
232
- const seededRNG=function(seed){let randomSeed=seed;return function(){let seed=randomSeed;seed=seed+0x7ed55d16+(seed<<12)&0xffffffff;seed=(seed^0xc761c23c^seed>>>19)&0xffffffff;seed=seed+0x165667b1+(seed<<5)&0xffffffff;seed=(seed+0xd3a2646c^seed<<9)&0xffffffff;seed=seed+0xfd7046c5+(seed<<3)&0xffffffff;seed=(seed^0xb55a4f09^seed>>>16)&0xffffffff;return (randomSeed=seed&0xfffffff)/0x10000000}};function shuffle(array,randomSeed,ensurePermuted=false){const shuffled=_.clone(array);if(!shuffled.length||_.all(shuffled,function(value){return _.isEqual(value,shuffled[0])})){return shuffled}let random;if(typeof randomSeed==="function"){random=randomSeed;}else {random=seededRNG(randomSeed);}do{for(let top=shuffled.length;top>0;top--){const newEnd=Math.floor(random()*top);const temp=shuffled[newEnd];shuffled[newEnd]=shuffled[top-1];shuffled[top-1]=temp;}}while(ensurePermuted&&_.isEqual(array,shuffled))return shuffled}const random=seededRNG(new Date().getTime()&0xffffffff);
232
+ const seededRNG=function(seed){let randomSeed=seed;return function(){let seed=randomSeed;seed=seed+0x7ed55d16+(seed<<12)&0xffffffff;seed=(seed^0xc761c23c^seed>>>19)&0xffffffff;seed=seed+0x165667b1+(seed<<5)&0xffffffff;seed=(seed+0xd3a2646c^seed<<9)&0xffffffff;seed=seed+0xfd7046c5+(seed<<3)&0xffffffff;seed=(seed^0xb55a4f09^seed>>>16)&0xffffffff;return (randomSeed=seed&0xfffffff)/0x10000000}};function shuffle(array,randomSeed,ensurePermuted=false){const shuffled=[...array];if(!shuffled.length||_.all(shuffled,function(value){return _.isEqual(value,shuffled[0])})){return shuffled}let random;if(typeof randomSeed==="function"){random=randomSeed;}else {random=seededRNG(randomSeed);}do{for(let top=shuffled.length;top>0;top--){const newEnd=Math.floor(random()*top);const temp=shuffled[newEnd];shuffled[newEnd]=shuffled[top-1];shuffled[top-1]=temp;}}while(ensurePermuted&&_.isEqual(array,shuffled))return shuffled}const random=seededRNG(new Date().getTime()&0xffffffff);
233
233
 
234
234
  const shuffleMatcher=props=>{const rng=seededRNG(props.problemNum);let left;if(!props.orderMatters){left=props.left;}else {left=shuffle(props.left,rng,true);}const right=shuffle(props.right,rng,true);return {left,right}};function shuffleMatcherWithRandom(data){let left;if(!data.orderMatters){left=data.left;}else {left=shuffle(data.left,Math.random,true);}const right=shuffle(data.right,Math.random,true);return {left,right}}function getMatcherPublicWidgetOptions(options){const{left,right}=shuffleMatcherWithRandom(options);return {...options,left:left,right:right}}
235
235