@khanacademy/perseus-core 30.0.0 → 30.0.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.
- package/dist/data-schema.d.ts +1 -1
- package/dist/es/index.item-splitting.js +1 -1
- package/dist/es/index.item-splitting.js.map +1 -1
- package/dist/es/index.js +5 -5
- package/dist/es/index.js.map +1 -1
- package/dist/index.item-splitting.js +1 -1
- package/dist/index.item-splitting.js.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/parse-perseus-json/perseus-parsers/perseus-answer-area.d.ts +4 -3
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var grapherUtil = /*#__PURE__*/Object.freeze({
|
|
|
28
28
|
functionForType: functionForType
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
const blankPerseusRenderer={content:"",images:{},widgets:{}};function generateTestPerseusRenderer(customFields={}){return deepClone({...blankPerseusRenderer,...customFields})}const blankPerseusItemData={question:generateTestPerseusRenderer(),answerArea:{calculator:false,calculatorVariant:
|
|
31
|
+
const blankPerseusRenderer={content:"",images:{},widgets:{}};function generateTestPerseusRenderer(customFields={}){return deepClone({...blankPerseusRenderer,...customFields})}const blankPerseusItemData={question:generateTestPerseusRenderer(),answerArea:{calculator:false,calculatorVariant:undefined,periodicTable:false,financialCalculatorMonthlyPayment:false,financialCalculatorTotalAmount:false,financialCalculatorTimeToPayOff:false,periodicTableWithKey:false},hints:[]};function generateTestPerseusItem(customFields={}){return deepClone({...blankPerseusItemData,...customFields})}
|
|
32
32
|
|
|
33
33
|
const itemHasRationales=item=>widgetsHaveRationales(item.question.widgets);const widgetsHaveRationales=widgets=>Object.values(widgets).some(widgetHasRationales);const widgetHasRationales=widget=>{switch(widget.type){case "radio":return radioWidgetHasRationales(widget);case "label-image":return labelImageWidgetHasRationales(widget);case "graded-group":case "group":return widgetsHaveRationales(widget.options.widgets);default:return false}};const radioWidgetHasRationales=widget=>{return widget.options.choices.some(choice=>!!choice.rationale)};const labelImageWidgetHasRationales=widget=>{return widget.options.markers.some(marker=>marker.answers.length>0)};
|
|
34
34
|
|
|
@@ -180,7 +180,7 @@ const parsePerseusArticle=union(parsePerseusRenderer).or(array(parsePerseusRende
|
|
|
180
180
|
|
|
181
181
|
const parseHint=object({replace:defaulted(optional(boolean),()=>undefined),placeholder:defaulted(optional(boolean),()=>undefined),content:string,widgets:defaulted(parseWidgetsMap,()=>({})),images:parseImages,metadata:any});
|
|
182
182
|
|
|
183
|
-
const booleanOrFalse=defaulted(boolean,()=>false);const
|
|
183
|
+
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;
|
|
184
184
|
|
|
185
185
|
const parsePerseusItem=object({question:parsePerseusRenderer,hints:defaulted(array(parseHint),()=>[]),answerArea:parsePerseusAnswerArea});
|
|
186
186
|
|
|
@@ -228,7 +228,7 @@ const parseUserInputMap=(rawValue,ctx)=>{if(!isPlainObject(rawValue)){return ctx
|
|
|
228
228
|
|
|
229
229
|
function parseAndMigratePerseusItem(data){const object=typeof data==="string"?JSON.parse(data):data;const result=parse(object,parsePerseusItem);if(isFailure(result)){return failure({message:result.detail,invalidObject:object})}return result}function parseAndMigratePerseusArticle(data){const object=typeof data==="string"?JSON.parse(data):data;const result=parse(object,parsePerseusArticle);if(isFailure(result)){return failure({message:result.detail,invalidObject:object})}return result}function parseAndMigrateUserInputMap(data){const object=typeof data==="string"?JSON.parse(data):data;const result=parse(object,parseUserInputMap);if(isFailure(result)){return failure({message:result.detail,invalidObject:object})}return result}function parseAndMigratePerseusRenderer(data){const object=typeof data==="string"?JSON.parse(data):data;const result=parse(object,parsePerseusRenderer);if(isFailure(result)){return failure({message:result.detail,invalidObject:object})}return result}
|
|
230
230
|
|
|
231
|
-
const libName="@khanacademy/perseus-core";const libVersion="30.0.
|
|
231
|
+
const libName="@khanacademy/perseus-core";const libVersion="30.0.1";addLibraryVersionToPerseusDebug(libName,libVersion);
|
|
232
232
|
|
|
233
233
|
const Errors=Object.freeze({Unknown:"Unknown",Internal:"Internal",InvalidInput:"InvalidInput",NotAllowed:"NotAllowed",TransientService:"TransientService",Service:"Service"});
|
|
234
234
|
|
|
@@ -284,7 +284,7 @@ function getNumericInputAnswerPublicData(answer){return {status:answer.status,an
|
|
|
284
284
|
|
|
285
285
|
const getInputNumberPublicWidgetOptions=getNumericInputPublicWidgetOptions;
|
|
286
286
|
|
|
287
|
-
const defaultWidgetOptions$h={textAlign:"left",coefficient:false,size:"normal",answers:[{status:"correct",value:0,simplify:"required",maxError:0,answerForms:[],message:"",strict:true}]};const inputNumberWidgetLogic={name:"input-number",version:{major:1,minor:0},defaultWidgetOptions: defaultWidgetOptions$h,defaultAlignment:"inline-block",accessible:
|
|
287
|
+
const defaultWidgetOptions$h={textAlign:"left",coefficient:false,size:"normal",answers:[{status:"correct",value:0,simplify:"required",maxError:0,answerForms:[],message:"",strict:true}]};const inputNumberWidgetLogic={name:"input-number",version:{major:1,minor:0},defaultWidgetOptions: defaultWidgetOptions$h,defaultAlignment:"inline-block",accessible:true,getPublicWidgetOptions:getInputNumberPublicWidgetOptions};
|
|
288
288
|
|
|
289
289
|
const defaultWidgetOptions$g={graph:{box:[400,400],labels:["x","y"],range:[[-10,10],[-10,10]],tickStep:[1,1],gridStep:[1,1],markings:"graph"},elements:[]};const interactionWidgetLogic={name:"interaction",defaultWidgetOptions: defaultWidgetOptions$g,accessible:false};
|
|
290
290
|
|
|
@@ -371,7 +371,7 @@ const defaultWidgetOptions={content:"",widgets:{},images:{}};const traverseChild
|
|
|
371
371
|
|
|
372
372
|
function convertGrapherOptionsToInteractiveGraph(grapherOptions){if(grapherOptions.availableTypes.length!==1){return null}const[type]=grapherOptions.availableTypes;if(type==="quadratic"){return null}const graph={type:grapherFunctionTypeToInteractiveGraphType(type)};return {step:grapherOptions.graph.step,gridStep:grapherOptions.graph.gridStep,snapStep:grapherOptions.graph.snapStep,backgroundImage:grapherOptions.graph.backgroundImage,markings:grapherOptions.graph.markings,labels:grapherOptions.graph.labels.map(wrapTexInDelimitersForMarkdown),labelLocation:"onAxis",showAxisArrows:{xMin:true,xMax:true,yMin:true,yMax:true},showAxisTicks:{x:true,y:true},showProtractor:grapherOptions.graph.showProtractor??false,showTooltips:grapherOptions.graph.showTooltips,range:grapherOptions.graph.range,graph,correct:grapherOptions.correct?grapherAnswerTypesToPerseusGraphType(grapherOptions.correct):graph,lockedFigures:[]}}function convertGrapherUserInputToInteractiveGraph(grapherUserInput){return grapherAnswerTypesToPerseusGraphType(grapherUserInput)}function convertInteractiveGraphUserInputToGrapher(interactiveGraphUserInput){switch(interactiveGraphUserInput.type){case "absolute-value":return {type:"absolute_value",coords:interactiveGraphUserInput.coords??null};case "exponential":{invariant(interactiveGraphUserInput.asymptote!=null,"exponential graph asymptote must not be nullish in user input");const asymptoteY=interactiveGraphUserInput.asymptote;return {type:"exponential",coords:interactiveGraphUserInput.coords??null,asymptote:[[0,asymptoteY],[1,asymptoteY]]}}case "linear":return {type:"linear",coords:interactiveGraphUserInput.coords??null};case "logarithm":{invariant(interactiveGraphUserInput.asymptote!=null,"logarithm graph asymptote must not be nullish in user input");const asymptoteX=interactiveGraphUserInput.asymptote;return {type:"logarithm",coords:interactiveGraphUserInput.coords??null,asymptote:[[asymptoteX,0],[asymptoteX,1]]}}case "sinusoid":return {type:"sinusoid",coords:interactiveGraphUserInput.coords??null};case "tangent":return {type:"tangent",coords:interactiveGraphUserInput.coords??null};case "angle":case "circle":case "linear-system":case "none":case "point":case "polygon":case "quadratic":case "ray":case "segment":case "vector":throw Error("Can't convert interactive-graph user input to grapher user input. Type: "+interactiveGraphUserInput.type);default:throw new UnreachableCaseError(interactiveGraphUserInput)}}function grapherAnswerTypesToPerseusGraphType(grapherAnswerTypes){switch(grapherAnswerTypes.type){case "absolute_value":return {type:"absolute-value",coords:grapherAnswerTypes.coords};case "exponential":return {type:"exponential",coords:grapherAnswerTypes.coords,asymptote:grapherAnswerTypes.asymptote[0][1]};case "linear":return {type:"linear",coords:grapherAnswerTypes.coords};case "logarithm":return {type:"logarithm",coords:grapherAnswerTypes.coords,asymptote:grapherAnswerTypes.asymptote[0][0]};case "quadratic":throw Error("Can't convert GrapherAnswerTypes to interactive graph. Type: quadratic");case "sinusoid":return {type:"sinusoid",coords:grapherAnswerTypes.coords};case "tangent":return {type:"tangent",coords:grapherAnswerTypes.coords};default:throw new UnreachableCaseError(grapherAnswerTypes)}}function grapherFunctionTypeToInteractiveGraphType(type){return type==="absolute_value"?"absolute-value":type}function wrapTexInDelimitersForMarkdown(tex){return `$${tex}$`}
|
|
373
373
|
|
|
374
|
-
function getDefaultAnswerArea(){return {...ItemExtras.reduce((acc,curr)=>({...acc,[curr]:false}),{}),calculatorVariant:
|
|
374
|
+
function getDefaultAnswerArea(){return {...ItemExtras.reduce((acc,curr)=>({...acc,[curr]:false}),{}),calculatorVariant:undefined}}
|
|
375
375
|
|
|
376
376
|
const DEFAULT_COLOR="grayH";function getDefaultFigureForType(type){switch(type){case "point":return {type:"point",coord:[0,0],color:DEFAULT_COLOR,filled:true,labels:[]};case "line":return {type:"line",kind:"line",points:[getDefaultFigureForType("point"),{...getDefaultFigureForType("point"),coord:[2,2]}],color:DEFAULT_COLOR,lineStyle:"solid",showPoint1:false,showPoint2:false,weight:"medium",labels:[]};case "vector":return {type:"vector",points:[[0,0],[2,2]],color:DEFAULT_COLOR,weight:"medium",labels:[]};case "ellipse":return {type:"ellipse",center:[0,0],radius:[1,1],angle:0,color:DEFAULT_COLOR,fillStyle:"none",strokeStyle:"solid",weight:"medium",labels:[]};case "polygon":return {type:"polygon",points:[[0,2],[-1,0],[1,0]],color:DEFAULT_COLOR,showVertices:false,fillStyle:"none",strokeStyle:"solid",weight:"medium",labels:[]};case "function":return {type:"function",color:DEFAULT_COLOR,strokeStyle:"solid",weight:"medium",equation:"x^2",domain:[-Infinity,Infinity],directionalAxis:"x",labels:[]};case "label":return {type:"label",coord:[0,0],text:"label",color:DEFAULT_COLOR,size:"medium"};default:throw new UnreachableCaseError(type)}}
|
|
377
377
|
|