@khanacademy/perseus-core 0.0.0-PR875-20250222011102 → 0.0.0-PR875-20250225011257

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.
@@ -745,9 +745,10 @@ export type PerseusMeasurerWidgetOptions = {
745
745
  };
746
746
  export type MathFormat = "integer" | "mixed" | "improper" | "proper" | "decimal" | "percent" | "pi";
747
747
  export type PerseusNumericInputAnswerForm = {
748
- simplify: "required" | "correct" | "enforced" | "optional" | null | undefined;
748
+ simplify: PerseusNumericInputSimplify | null | undefined;
749
749
  name: MathFormat;
750
750
  };
751
+ export type PerseusNumericInputSimplify = "required" | "correct" | "enforced" | "optional";
751
752
  export type PerseusNumericInputWidgetOptions = {
752
753
  answers: ReadonlyArray<PerseusNumericInputAnswer>;
753
754
  labelText?: string | undefined;
@@ -755,7 +756,6 @@ export type PerseusNumericInputWidgetOptions = {
755
756
  coefficient: boolean;
756
757
  rightAlign?: boolean;
757
758
  static: boolean;
758
- answerForms?: ReadonlyArray<PerseusNumericInputAnswerForm>;
759
759
  };
760
760
  export type PerseusNumericInputAnswer = {
761
761
  message: string;
@@ -764,7 +764,7 @@ export type PerseusNumericInputAnswer = {
764
764
  answerForms?: ReadonlyArray<MathFormat>;
765
765
  strict: boolean;
766
766
  maxError: number | null | undefined;
767
- simplify: string | null | undefined;
767
+ simplify: PerseusNumericInputSimplify | null | undefined;
768
768
  };
769
769
  export type PerseusNumberLineWidgetOptions = {
770
770
  range: ReadonlyArray<number>;
package/dist/es/index.js CHANGED
@@ -48,7 +48,9 @@ const getDecimalSeparator = locale => {
48
48
  const match = new Intl.NumberFormat(locale).format(numberWithDecimalSeparator)
49
49
  // 0x661 is ARABIC-INDIC DIGIT ONE
50
50
  // 0x6F1 is EXTENDED ARABIC-INDIC DIGIT ONE
51
- .match(/[^\d\u0661\u06F1]/);
51
+ // 0x967 is DEVANAGARI DIGIT ONE
52
+ // 0x9e7 is BENGALI/BANGLA DIGIT ONE
53
+ .match(/[^\d\u0661\u06F1\u0967\u09e7]/);
52
54
  return (_match$ = match == null ? void 0 : match[0]) != null ? _match$ : ".";
53
55
  }
54
56
  };
@@ -2132,6 +2134,7 @@ const parseNumberLineWidget = parseWidget(constant("number-line"), object({
2132
2134
  }));
2133
2135
 
2134
2136
  const parseMathFormat = enumeration("integer", "mixed", "improper", "proper", "decimal", "percent", "pi");
2137
+ const parseSimplify = enumeration("required", "correct", "enforced", "optional");
2135
2138
  const parseNumericInputWidget = parseWidget(constant("numeric-input"), object({
2136
2139
  answers: array(object({
2137
2140
  message: string,
@@ -2146,7 +2149,12 @@ const parseNumericInputWidget = parseWidget(constant("numeric-input"), object({
2146
2149
  // TODO(benchristel): simplify should never be a boolean, but we
2147
2150
  // have some content where it is anyway. If we ever backfill
2148
2151
  // the data, we should simplify `simplify`.
2149
- simplify: optional(nullable(union(string).or(pipeParsers(boolean).then(convert(String)).parser).parser))
2152
+ simplify: optional(nullable(union(parseSimplify).or(pipeParsers(boolean).then(convert(value => {
2153
+ if (typeof value === "boolean") {
2154
+ return value ? "required" : "optional";
2155
+ }
2156
+ return value;
2157
+ })).parser).parser))
2150
2158
  })),
2151
2159
  labelText: optional(string),
2152
2160
  size: string,
@@ -3213,13 +3221,35 @@ const _excluded$3 = ["answers"];
3213
3221
  * PerseusNumericInputWidgetOptions type
3214
3222
  */
3215
3223
 
3224
+ /**
3225
+ * This data from `answers` is used pre-scoring to give hints
3226
+ * to the learner regarding the format of accepted answers
3227
+ */
3228
+ function getNumericInputAnswerPublicData(answer) {
3229
+ const {
3230
+ answerForms,
3231
+ simplify,
3232
+ status
3233
+ } = answer;
3234
+ return {
3235
+ answerForms,
3236
+ simplify,
3237
+ status
3238
+ };
3239
+ }
3240
+
3216
3241
  /**
3217
3242
  * Given a PerseusNumericInputWidgetOptions object, return a new object with only
3218
3243
  * the public options that should be exposed to the client.
3219
3244
  */
3220
3245
  function getNumericInputPublicWidgetOptions(options) {
3221
- const publicWidgetOptions = _objectWithoutPropertiesLoose(options, _excluded$3);
3222
- return publicWidgetOptions;
3246
+ const {
3247
+ answers
3248
+ } = options,
3249
+ publicWidgetOptions = _objectWithoutPropertiesLoose(options, _excluded$3);
3250
+ return _extends({}, publicWidgetOptions, {
3251
+ answers: answers.map(getNumericInputAnswerPublicData)
3252
+ });
3223
3253
  }
3224
3254
 
3225
3255
  const defaultWidgetOptions$b = {