@khanacademy/perseus-core 38.0.1 → 38.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.
@@ -549,6 +549,8 @@ export type PerseusGradedGroupWidgetOptions = {
549
549
  images: {
550
550
  [key: string]: PerseusImageDetail;
551
551
  };
552
+ /** optional content extras (calculators/financial calcs/periodic tables) */
553
+ answerArea?: PerseusAnswerArea;
552
554
  };
553
555
  /** Options for the graded-group-set widget. A set of graded groups. */
554
556
  export type PerseusGradedGroupSetWidgetOptions = {
@@ -80,7 +80,9 @@ const stringOrNumberOrNullOrUndefined=union(string).or(number).or(constant(null)
80
80
 
81
81
  const parseFreeResponseWidget=parseWidget(constant("free-response"),object({allowUnlimitedCharacters:boolean,characterLimit:number,placeholder:string,question:string,scoringCriteria:array(object({text:string}))}));
82
82
 
83
- const falseToNull=pipeParsers(constant(false)).then(convert(()=>null)).parser;const parseGradedGroupWidgetOptions=object({title:defaulted(string,()=>""),hint:union(falseToNull).or(constant(null)).or(constant(undefined)).or((rawVal,ctx)=>parsePerseusRenderer(rawVal,ctx)).parser,content:string,widgets:(rawVal,ctx)=>parseWidgetsMap(rawVal,ctx),images:record(string,object({width:number,height:number}))});const parseGradedGroupWidget=parseWidget(constant("graded-group"),parseGradedGroupWidgetOptions);
83
+ const booleanOrFalse=defaulted(boolean,()=>false);const calculatorVariantOrUndefined=pipeParsers(defaulted(nullable(enumeration("scientific","graphing","four_function")),()=>null)).then(convert(v=>v??undefined)).parser;const baseParser=defaulted(object({calculator:booleanOrFalse,calculatorVariant:calculatorVariantOrUndefined,financialCalculatorMonthlyPayment:booleanOrFalse,financialCalculatorTotalAmount:booleanOrFalse,financialCalculatorTimeToPayOff:booleanOrFalse,periodicTable:booleanOrFalse,periodicTableWithKey:booleanOrFalse}),()=>({calculator:false,calculatorVariant:undefined,financialCalculatorMonthlyPayment:false,financialCalculatorTotalAmount:false,financialCalculatorTimeToPayOff:false,periodicTable:false,periodicTableWithKey:false}));const parsePerseusAnswerArea=pipeParsers(baseParser).then(convert(parsed=>{const{calculatorVariant:parsedCalcVariant,...rest}=parsed;const calculatorVariant=parsed.calculator&&parsedCalcVariant===undefined?"scientific":parsedCalcVariant;return calculatorVariant!==undefined?{...rest,calculatorVariant}:rest})).parser;
84
+
85
+ const falseToNull=pipeParsers(constant(false)).then(convert(()=>null)).parser;const parseGradedGroupWidgetOptions=object({title:defaulted(string,()=>""),hint:union(falseToNull).or(constant(null)).or(constant(undefined)).or((rawVal,ctx)=>parsePerseusRenderer(rawVal,ctx)).parser,content:string,widgets:(rawVal,ctx)=>parseWidgetsMap(rawVal,ctx),images:record(string,object({width:number,height:number})),answerArea:optional(parsePerseusAnswerArea)});const parseGradedGroupWidget=parseWidget(constant("graded-group"),parseGradedGroupWidgetOptions);
84
86
 
85
87
  const parseGradedGroupSetWidget=parseWidget(constant("graded-group-set"),object({gradedGroups:array(parseGradedGroupWidgetOptions)}));
86
88
 
@@ -144,8 +146,6 @@ union(parsePerseusRenderer).or(array(parsePerseusRenderer)).parser;
144
146
 
145
147
  const parseHint=object({replace:defaulted(optional(boolean),()=>undefined),placeholder:defaulted(optional(boolean),()=>undefined),content:string,widgets:defaulted(parseWidgetsMap,()=>({})),images:parseImages,metadata:any});
146
148
 
147
- const booleanOrFalse=defaulted(boolean,()=>false);const calculatorVariantOrUndefined=pipeParsers(defaulted(nullable(enumeration("scientific","graphing","four_function")),()=>null)).then(convert(v=>v??undefined)).parser;const baseParser=defaulted(object({calculator:booleanOrFalse,calculatorVariant:calculatorVariantOrUndefined,financialCalculatorMonthlyPayment:booleanOrFalse,financialCalculatorTotalAmount:booleanOrFalse,financialCalculatorTimeToPayOff:booleanOrFalse,periodicTable:booleanOrFalse,periodicTableWithKey:booleanOrFalse}),()=>({calculator:false,calculatorVariant:undefined,financialCalculatorMonthlyPayment:false,financialCalculatorTotalAmount:false,financialCalculatorTimeToPayOff:false,periodicTable:false,periodicTableWithKey:false}));const parsePerseusAnswerArea=pipeParsers(baseParser).then(convert(parsed=>{const{calculatorVariant:parsedCalcVariant,...rest}=parsed;const calculatorVariant=parsed.calculator&&parsedCalcVariant===undefined?"scientific":parsedCalcVariant;return calculatorVariant!==undefined?{...rest,calculatorVariant}:rest})).parser;
148
-
149
149
  const parsePerseusItem=object({question:parsePerseusRenderer,hints:defaulted(array(parseHint),()=>[]),answerArea:parsePerseusAnswerArea});
150
150
 
151
151
  const coord=pair(number,number);const coordPair=pair(coord,coord);const parseAbsoluteValueBranch=object({type:constant("absolute_value"),coords:nullable(coordPair)});const parseExponentialBranch=object({type:constant("exponential"),asymptote:coordPair,coords:nullable(coordPair)});const parseLinearBranch=object({type:constant("linear"),coords:nullable(coordPair)});const parseLogarithmBranch=object({type:constant("logarithm"),asymptote:coordPair,coords:nullable(coordPair)});const parseQuadraticBranch=object({type:constant("quadratic"),coords:nullable(coordPair)});const parseSinusoidBranch=object({type:constant("sinusoid"),coords:nullable(coordPair)});const parseTangentBranch=object({type:constant("tangent"),coords:nullable(coordPair)});discriminatedUnionOn("type").withBranch("absolute_value",parseAbsoluteValueBranch).withBranch("exponential",parseExponentialBranch).withBranch("linear",parseLinearBranch).withBranch("logarithm",parseLogarithmBranch).withBranch("quadratic",parseQuadraticBranch).withBranch("sinusoid",parseSinusoidBranch).withBranch("tangent",parseTangentBranch).parser;