@khanacademy/perseus-core 5.3.0 → 5.4.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.
@@ -323,6 +323,7 @@ export type PerseusImageBackground = {
323
323
  * - none: shows no markings
324
324
  */
325
325
  export type MarkingsType = "axes" | "graph" | "grid" | "none";
326
+ export type AxisLabelLocation = "onAxis" | "alongEdge";
326
327
  export type PerseusCategorizerWidgetOptions = {
327
328
  items: ReadonlyArray<string>;
328
329
  categories: ReadonlyArray<string>;
@@ -476,6 +477,13 @@ export type PerseusInteractiveGraphWidgetOptions = {
476
477
  */
477
478
  markings: MarkingsType;
478
479
  labels?: ReadonlyArray<string>;
480
+ /**
481
+ * Specifies the location of the labels on the graph. default: "onAxis".
482
+ * - "onAxis": Labels are positioned on the axis at the right (x) and top (y) of the graph.
483
+ * - "alongEdge": Labels are centered along the bottom (x) and left (y) edges of the graph.
484
+ * The y label is rotated. Typically used when the range min is near 0 with longer labels.
485
+ */
486
+ labelLocation?: AxisLabelLocation;
479
487
  showProtractor: boolean;
480
488
  /**
481
489
  * Whether to show the Ruler tool overlayed on top of the graph.
@@ -758,10 +766,18 @@ export type PerseusMeasurerWidgetOptions = {
758
766
  };
759
767
  export type MathFormat = "integer" | "mixed" | "improper" | "proper" | "decimal" | "percent" | "pi";
760
768
  export type PerseusNumericInputAnswerForm = {
761
- simplify: PerseusNumericInputSimplify | null | undefined;
769
+ simplify: PerseusNumericInputSimplify;
762
770
  name: MathFormat;
763
771
  };
764
- export type PerseusNumericInputSimplify = "required" | "correct" | "enforced" | "optional";
772
+ /**
773
+ * Determines how unsimplified fractions are scored.
774
+ *
775
+ * - "required" means unsimplified fractions are considered invalid input, and
776
+ * the learner can try again.
777
+ * - "enforced" means unsimplified fractions are marked incorrect.
778
+ * - "optional" means unsimplified fractions are accepted.
779
+ */
780
+ export type PerseusNumericInputSimplify = "required" | "enforced" | "optional";
765
781
  export type PerseusNumericInputWidgetOptions = {
766
782
  answers: ReadonlyArray<PerseusNumericInputAnswer>;
767
783
  labelText?: string | undefined;
@@ -777,7 +793,7 @@ export type PerseusNumericInputAnswer = {
777
793
  answerForms?: ReadonlyArray<MathFormat>;
778
794
  strict: boolean;
779
795
  maxError: number | null | undefined;
780
- simplify: PerseusNumericInputSimplify | null | undefined;
796
+ simplify: PerseusNumericInputSimplify;
781
797
  };
782
798
  export type PerseusNumberLineWidgetOptions = {
783
799
  range: ReadonlyArray<number>;
package/dist/es/index.js CHANGED
@@ -1959,6 +1959,15 @@ const lockedFigureFillStyles = {
1959
1959
 
1960
1960
  // Not associated with a specific figure
1961
1961
 
1962
+ /**
1963
+ * Determines how unsimplified fractions are scored.
1964
+ *
1965
+ * - "required" means unsimplified fractions are considered invalid input, and
1966
+ * the learner can try again.
1967
+ * - "enforced" means unsimplified fractions are marked incorrect.
1968
+ * - "optional" means unsimplified fractions are accepted.
1969
+ */
1970
+
1962
1971
  const plotterPlotTypes = ["bar", "line", "pic", "histogram", "dotplot"];
1963
1972
 
1964
1973
  // Used to represent 2-D points and ranges
@@ -2243,7 +2252,21 @@ const parseNumberLineWidget = parseWidget(constant("number-line"), object({
2243
2252
  }));
2244
2253
 
2245
2254
  const parseMathFormat = enumeration("integer", "mixed", "improper", "proper", "decimal", "percent", "pi");
2246
- const parseSimplify = enumeration("required", "correct", "enforced", "optional");
2255
+ const parseSimplify = pipeParsers(union(constant(null)).or(constant(undefined)).or(boolean).or(constant("required")).or(constant("correct")).or(constant("enforced")).or(constant("optional")).or(constant("accepted")).parser).then(convert(deprecatedSimplifyValuesToRequired)).parser;
2256
+ function deprecatedSimplifyValuesToRequired(simplify) {
2257
+ switch (simplify) {
2258
+ case "enforced":
2259
+ case "required":
2260
+ case "optional":
2261
+ return simplify;
2262
+ // NOTE(benchristel): "accepted", "correct", true, false, undefined, and
2263
+ // null are all treated the same as "required" during scoring, so we
2264
+ // convert them to "required" here to preserve behavior. See the tests
2265
+ // in score-numeric-input.test.ts
2266
+ default:
2267
+ return "required";
2268
+ }
2269
+ }
2247
2270
  const parseNumericInputWidget = parseWidget(constant("numeric-input"), object({
2248
2271
  answers: array(object({
2249
2272
  message: string,
@@ -2258,12 +2281,7 @@ const parseNumericInputWidget = parseWidget(constant("numeric-input"), object({
2258
2281
  // TODO(benchristel): simplify should never be a boolean, but we
2259
2282
  // have some content where it is anyway. If we ever backfill
2260
2283
  // the data, we should simplify `simplify`.
2261
- simplify: optional(nullable(union(parseSimplify).or(pipeParsers(boolean).then(convert(value => {
2262
- if (typeof value === "boolean") {
2263
- return value ? "required" : "optional";
2264
- }
2265
- return value;
2266
- })).parser).parser))
2284
+ simplify: parseSimplify
2267
2285
  })),
2268
2286
  labelText: optional(string),
2269
2287
  size: string,
@@ -2272,7 +2290,7 @@ const parseNumericInputWidget = parseWidget(constant("numeric-input"), object({
2272
2290
  static: defaulted(boolean, () => false),
2273
2291
  answerForms: optional(array(object({
2274
2292
  name: parseMathFormat,
2275
- simplify: optional(nullable(enumeration("required", "correct", "enforced", "optional")))
2293
+ simplify: parseSimplify
2276
2294
  })))
2277
2295
  }));
2278
2296
 
@@ -2844,7 +2862,7 @@ const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
2844
2862
 
2845
2863
  // This file is processed by a Rollup plugin (replace) to inject the production
2846
2864
  const libName = "@khanacademy/perseus-core";
2847
- const libVersion = "5.3.0";
2865
+ const libVersion = "5.4.1";
2848
2866
  addLibraryVersionToPerseusDebug(libName, libVersion);
2849
2867
 
2850
2868
  /**
@@ -4025,8 +4043,9 @@ function getUpgradedWidgetOptions(oldWidgetOptions) {
4025
4043
  }
4026
4044
 
4027
4045
  /**
4028
- * Upgrades widget options and removes answerful data for all the widgets in a
4029
- * Perseus item.
4046
+ * Return a copy of a Perseus item with rubric data removed (ie answers)
4047
+ *
4048
+ * @param originalItem - the original, full Perseus item (which includes the rubric - aka answer data)
4030
4049
  */
4031
4050
  function splitPerseusItem(originalItem) {
4032
4051
  var _item$widgets;