@khanacademy/perseus-core 28.3.0 → 29.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.
- package/dist/data-schema.d.ts +4 -2
- package/dist/es/index.item-splitting.js +3 -3
- package/dist/es/index.item-splitting.js.map +1 -1
- package/dist/es/index.js +6 -6
- package/dist/es/index.js.map +1 -1
- package/dist/index.item-splitting.js +3 -3
- package/dist/index.item-splitting.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/parse-perseus-json/perseus-parsers/numeric-input-widget.d.ts +1 -1
- package/dist/parse-perseus-json/regression-tests/item-data/numeric-input-center-aligned.d.ts +41 -0
- package/dist/parse-perseus-json/regression-tests/item-data/numeric-input-right-aligned.d.ts +41 -0
- package/dist/widgets/numeric-input/index.d.ts +1 -1
- package/dist/widgets/numeric-input/numeric-input-util.d.ts +1 -1
- package/package.json +3 -3
package/dist/es/index.js
CHANGED
|
@@ -110,7 +110,7 @@ const parseLegacyButtonSet=enumeration("basic","basic+div","trig","prealgebra","
|
|
|
110
110
|
|
|
111
111
|
function versionedWidgetOptions(latestMajorVersion,parseLatest){return new VersionedWidgetOptionsParserBuilder(latestMajorVersion,parseLatest,latest=>latest,(raw,ctx)=>ctx.failure("widget options with a known version number",raw))}class VersionedWidgetOptionsParserBuilder{withMigrationFrom(majorVersion,parseOldVersion,migrateToNextVersion){const parseOtherVersions=this.parser;const migrateToLatest=old=>this.migrateToLatest(migrateToNextVersion(old));return new VersionedWidgetOptionsParserBuilder(majorVersion,parseOldVersion,migrateToLatest,parseOtherVersions)}constructor(majorVersion,parseThisVersion,migrateToLatest,parseOtherVersions){this.migrateToLatest=migrateToLatest;this.parseOtherVersions=parseOtherVersions;const parseThisVersionAndMigrateToLatest=pipeParsers(parseThisVersion).then(convert(this.migrateToLatest)).parser;this.parser=(raw,ctx)=>{if(!isPlainObject(raw)){return ctx.failure("object",raw)}const versionParseResult=parseVersionedObject(raw,ctx);if(isFailure(versionParseResult)){return versionParseResult}if(versionParseResult.value.version.major!==majorVersion){return this.parseOtherVersions(raw,ctx)}return parseThisVersionAndMigrateToLatest(raw,ctx)};}}const parseVersionedObject=object({version:defaulted(object({major:number,minor:number}),()=>({major:0,minor:0}))});
|
|
112
112
|
|
|
113
|
-
const stringOrNumberOrNullOrUndefined=union(string).or(number).or(constant(null)).or(constant(undefined)).parser;function numberOrNullToString(v){return typeof v==="number"||v===null?String(v):v}const parsePossiblyInvalidAnswerForm=object({value:optional(string),form:defaulted(boolean,()=>false),simplify:defaulted(boolean,()=>false),considered:enumeration("correct","wrong","ungraded"),key:pipeParsers(stringOrNumberOrNullOrUndefined).then(convert(numberOrNullToString)).parser});function removeInvalidAnswerForms(possiblyInvalid){return possiblyInvalid.flatMap(answerForm=>{const{value}=answerForm;if(value!=null){return [{...answerForm,value}]}return []})}const parseAnswerForms=pipeParsers(defaulted(array(parsePossiblyInvalidAnswerForm),()=>[])).then(convert(removeInvalidAnswerForms)).parser;const version2$1=object({major:constant(2),minor:number});const parseExpressionWidgetV2=parseWidgetWithVersion(version2$1,constant("expression"),object({answerForms:parseAnswerForms,functions:array(string),times:boolean,visibleLabel:optional(string),ariaLabel:optional(string),buttonSets:parseLegacyButtonSets,buttonsVisible:optional(enumeration("always","never","focused")),extraKeys:optional(array(keypadKeys))}));const version1$
|
|
113
|
+
const stringOrNumberOrNullOrUndefined=union(string).or(number).or(constant(null)).or(constant(undefined)).parser;function numberOrNullToString(v){return typeof v==="number"||v===null?String(v):v}const parsePossiblyInvalidAnswerForm=object({value:optional(string),form:defaulted(boolean,()=>false),simplify:defaulted(boolean,()=>false),considered:enumeration("correct","wrong","ungraded"),key:pipeParsers(stringOrNumberOrNullOrUndefined).then(convert(numberOrNullToString)).parser});function removeInvalidAnswerForms(possiblyInvalid){return possiblyInvalid.flatMap(answerForm=>{const{value}=answerForm;if(value!=null){return [{...answerForm,value}]}return []})}const parseAnswerForms=pipeParsers(defaulted(array(parsePossiblyInvalidAnswerForm),()=>[])).then(convert(removeInvalidAnswerForms)).parser;const version2$1=object({major:constant(2),minor:number});const parseExpressionWidgetV2=parseWidgetWithVersion(version2$1,constant("expression"),object({answerForms:parseAnswerForms,functions:array(string),times:boolean,visibleLabel:optional(string),ariaLabel:optional(string),buttonSets:parseLegacyButtonSets,buttonsVisible:optional(enumeration("always","never","focused")),extraKeys:optional(array(keypadKeys))}));const version1$2=object({major:constant(1),minor:number});const parseExpressionWidgetV1=parseWidgetWithVersion(version1$2,constant("expression"),object({answerForms:parseAnswerForms,functions:array(string),times:boolean,visibleLabel:optional(string),ariaLabel:optional(string),buttonSets:parseLegacyButtonSets,buttonsVisible:optional(enumeration("always","never","focused"))}));function migrateV1ToV2$1(widget){const{options}=widget;return {...widget,version:{major:2,minor:0},options:{times:options.times,buttonSets:options.buttonSets,functions:options.functions,buttonsVisible:options.buttonsVisible,visibleLabel:options.visibleLabel,ariaLabel:options.ariaLabel,answerForms:options.answerForms,extraKeys:deriveExtraKeys(options)??[]}}}const version0$2=optional(object({major:constant(0),minor:number}));const parseExpressionWidgetV0=parseWidgetWithVersion(version0$2,constant("expression"),object({functions:array(string),times:boolean,visibleLabel:optional(string),ariaLabel:optional(string),form:boolean,simplify:boolean,value:string,buttonSets:parseLegacyButtonSets,buttonsVisible:optional(enumeration("always","never","focused"))}));function migrateV0ToV1$3(widget){const{options}=widget;return {...widget,version:{major:1,minor:0},options:{times:options.times,buttonSets:options.buttonSets,functions:options.functions,buttonsVisible:options.buttonsVisible,visibleLabel:options.visibleLabel,ariaLabel:options.ariaLabel,answerForms:[{considered:"correct",form:options.form,simplify:options.simplify,value:options.value}]}}}const parseExpressionWidget=versionedWidgetOptions(2,parseExpressionWidgetV2).withMigrationFrom(1,parseExpressionWidgetV1,migrateV1ToV2$1).withMigrationFrom(0,parseExpressionWidgetV0,migrateV0ToV1$3).parser;
|
|
114
114
|
|
|
115
115
|
const parseFreeResponseWidget=parseWidget(constant("free-response"),object({allowUnlimitedCharacters:boolean,characterLimit:number,placeholder:string,question:string,scoringCriteria:array(object({text:string}))}));
|
|
116
116
|
|
|
@@ -144,13 +144,13 @@ const matcherOptions=object({labels:array(string),left:array(string),right:array
|
|
|
144
144
|
|
|
145
145
|
const numberOrStringOrNaN=union(number).or(string).or(constant(NaN)).parser;const numeric=pipeParsers(defaulted(numberOrStringOrNaN,()=>NaN)).then(stringToNumber).parser;const parseMatrixWidget=parseWidget(defaulted(constant("matrix"),()=>"matrix"),object({prefix:optional(string),suffix:optional(string),answers:defaulted(array(array(numeric)),()=>[]),cursorPosition:optional(array(number)),matrixBoardSize:array(number),static:optional(boolean)}));
|
|
146
146
|
|
|
147
|
-
const parseMeasurerWidgetV1=parseWidgetWithVersion(object({major:constant(1),minor:number}),constant("measurer"),object({image:defaulted(parsePerseusImageBackground,()=>({url:null,top:0,left:0})),showProtractor:boolean,showRuler:boolean,rulerLabel:string,rulerTicks:number,rulerPixels:number,rulerLength:number,box:pair(number,number)}));const parseMeasurerWidgetV0=parseWidget(constant("measurer"),object({imageTop:number,imageLeft:number,imageUrl:optional(nullable(string)),showProtractor:boolean,showRuler:boolean,rulerLabel:string,rulerTicks:number,rulerPixels:number,rulerLength:number,box:pair(number,number)}));function migrateV0ToV1$
|
|
147
|
+
const parseMeasurerWidgetV1=parseWidgetWithVersion(object({major:constant(1),minor:number}),constant("measurer"),object({image:defaulted(parsePerseusImageBackground,()=>({url:null,top:0,left:0})),showProtractor:boolean,showRuler:boolean,rulerLabel:string,rulerTicks:number,rulerPixels:number,rulerLength:number,box:pair(number,number)}));const parseMeasurerWidgetV0=parseWidget(constant("measurer"),object({imageTop:number,imageLeft:number,imageUrl:optional(nullable(string)),showProtractor:boolean,showRuler:boolean,rulerLabel:string,rulerTicks:number,rulerPixels:number,rulerLength:number,box:pair(number,number)}));function migrateV0ToV1$2(v0){const{imageTop,imageLeft,imageUrl,...v1Options}=v0.options;return {...v0,version:{major:1,minor:0},options:{image:{top:imageTop,left:imageLeft,url:imageUrl},...v1Options}}}const parseMeasurerWidget=versionedWidgetOptions(1,parseMeasurerWidgetV1).withMigrationFrom(0,parseMeasurerWidgetV0,migrateV0ToV1$2).parser;
|
|
148
148
|
|
|
149
149
|
const parseMoleculeRendererWidget=parseWidget(constant("molecule-renderer"),object({widgetId:string,rotationAngle:optional(number),smiles:optional(string)}));
|
|
150
150
|
|
|
151
151
|
const emptyStringToNull=pipeParsers(constant("")).then(convert(()=>null)).parser;const parseNumberLineWidget=parseWidget(constant("number-line"),object({range:array(number),labelRange:array(nullable(union(number).or(emptyStringToNull).parser)),labelStyle:string,labelTicks:boolean,isTickCtrl:defaulted(boolean,()=>false),isInequality:defaulted(boolean,()=>false),divisionRange:array(number),numDivisions:optional(nullable(number)),snapDivisions:defaulted(number,()=>2),tickStep:optional(nullable(number)),correctRel:defaulted(optional(enumeration("eq","lt","gt","le","ge")),()=>undefined),correctX:defaulted(nullable(number),()=>null),initialX:optional(nullable(number)),showTooltips:optional(boolean),static:defaulted(boolean,()=>false)}));
|
|
152
152
|
|
|
153
|
-
const parseMathFormat=enumeration("integer","mixed","improper","proper","decimal","percent","pi");const parseSimplify=pipeParsers(union(constant(null)).or(constant(undefined)).or(boolean).or(constant("true")).or(constant("required")).or(constant("correct")).or(constant("enforced")).or(constant("optional")).or(constant("accepted")).parser).then(convert(deprecatedSimplifyValuesToRequired)).parser;function deprecatedSimplifyValuesToRequired(simplify){switch(simplify){case "enforced":case "required":case "optional":return simplify;default:return "required"}}const
|
|
153
|
+
const parseMathFormat=enumeration("integer","mixed","improper","proper","decimal","percent","pi");const parseSimplify=pipeParsers(union(constant(null)).or(constant(undefined)).or(boolean).or(constant("true")).or(constant("required")).or(constant("correct")).or(constant("enforced")).or(constant("optional")).or(constant("accepted")).parser).then(convert(deprecatedSimplifyValuesToRequired)).parser;function deprecatedSimplifyValuesToRequired(simplify){switch(simplify){case "enforced":case "required":case "optional":return simplify;default:return "required"}}const parseNumericInputAnswers=array(object({message:defaulted(string,()=>""),value:optional(nullable(number)),status:string,answerForms:defaulted(optional(array(parseMathFormat)),()=>undefined),strict:defaulted(boolean,()=>false),maxError:optional(nullable(number)),simplify:parseSimplify}));const version1$1=object({major:constant(1),minor:number});const parseNumericInputWidgetV1=parseWidgetWithVersion(version1$1,constant("numeric-input"),object({answers:parseNumericInputAnswers,labelText:optional(string),size:string,coefficient:defaulted(boolean,()=>false),textAlign:defaulted(enumeration("left","right","center"),()=>"left")}));const version0$1=optional(object({major:constant(0),minor:number}));const parseNumericInputWidgetV0=parseWidgetWithVersion(version0$1,constant("numeric-input"),object({answers:parseNumericInputAnswers,labelText:optional(string),size:string,coefficient:defaulted(boolean,()=>false),rightAlign:optional(boolean)}));function migrateV0ToV1$1(widget){const{rightAlign,...options}=widget.options;return {...widget,version:{major:1,minor:0},options:{...options,textAlign:rightAlign?"right":"left"}}}const parseNumericInputWidget=versionedWidgetOptions(1,parseNumericInputWidgetV1).withMigrationFrom(0,parseNumericInputWidgetV0,migrateV0ToV1$1).parser;
|
|
154
154
|
|
|
155
155
|
function parseRenderer(rawValue,ctx){return parsePerseusRenderer(rawValue,ctx)}const largeToAuto=(height,ctx)=>{if(height==="large"){return ctx.success("auto")}return ctx.success(height)};const parseOrdererWidget=parseWidget(constant("orderer"),object({options:defaulted(array(parseRenderer),()=>[]),correctOptions:defaulted(array(parseRenderer),()=>[]),otherOptions:defaulted(array(parseRenderer),()=>[]),height:pipeParsers(enumeration("normal","auto","large")).then(largeToAuto).parser,layout:defaulted(enumeration("horizontal","vertical"),()=>"horizontal")}));
|
|
156
156
|
|
|
@@ -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="
|
|
231
|
+
const libName="@khanacademy/perseus-core";const libVersion="29.0.0";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
|
|
|
@@ -316,7 +316,7 @@ const defaultWidgetOptions$a={range:[0,10],labelRange:[null,null],labelStyle:"de
|
|
|
316
316
|
|
|
317
317
|
function getNumericInputAnswerPublicData(answer){const{answerForms,simplify,status}=answer;return {answerForms,simplify,status}}function getNumericInputPublicWidgetOptions(options){const{answers,...publicWidgetOptions}=options;return {...publicWidgetOptions,answers:answers.map(getNumericInputAnswerPublicData)}}
|
|
318
318
|
|
|
319
|
-
const defaultWidgetOptions$9={answers:[{value:null,status:"correct",message:"",simplify:"required",answerForms:[],strict:false,maxError:null}],size:"normal",coefficient:false,labelText:"",
|
|
319
|
+
const defaultWidgetOptions$9={answers:[{value:null,status:"correct",message:"",simplify:"required",answerForms:[],strict:false,maxError:null}],size:"normal",coefficient:false,labelText:"",textAlign:"left"};const numericInputWidgetLogic={name:"numeric-input",version:{major:1,minor:0},defaultWidgetOptions: defaultWidgetOptions$9,defaultAlignment:"inline-block",getPublicWidgetOptions:getNumericInputPublicWidgetOptions,accessible:true};
|
|
320
320
|
|
|
321
321
|
function getOrdererPublicWidgetOptions(fullOptions){const{options,height,layout}=fullOptions;return {options,height,layout}}
|
|
322
322
|
|
|
@@ -369,7 +369,7 @@ function getGroupPublicWidgetOptions(options){return splitPerseusRenderer(option
|
|
|
369
369
|
|
|
370
370
|
const defaultWidgetOptions={content:"",widgets:{},images:{}};const traverseChildWidgets=function(props,traverseRenderer){return {...props,...traverseRenderer(props)}};const groupWidgetLogic={name:"group",defaultWidgetOptions,accessible:false,traverseChildWidgets:traverseChildWidgets,getPublicWidgetOptions:getGroupPublicWidgetOptions};
|
|
371
371
|
|
|
372
|
-
function convertInputNumberOptionsToNumericInput(inputNumberOptions){return {coefficient:false,
|
|
372
|
+
function convertInputNumberOptionsToNumericInput(inputNumberOptions){return {coefficient:false,textAlign:inputNumberOptions.rightAlign?"right":"left",size:inputNumberOptions.size,answers:[{status:"correct",value:Number(inputNumberOptions.value),simplify:inputNumberOptions.simplify,message:"",maxError:getMaxError(inputNumberOptions),strict:true,answerForms:getAnswerForms(inputNumberOptions)}]}}function getMaxError(inputNumberOptions){if(!inputNumberOptions.inexact){return 0}if(inputNumberOptions.maxError==null){return undefined}return Number(inputNumberOptions.maxError)}const mathFormatsForAnswerType={number:[],decimal:["decimal"],integer:["integer"],rational:["integer","proper","improper","mixed"],improper:["integer","proper","improper"],mixed:["integer","proper","mixed"],percent:["integer","decimal","proper","improper","mixed","percent"],pi:["pi"]};function getAnswerForms(options){const value=Number(options.value);const{inexact}=options;const precision=1e10;const rounded=Math.round(value*precision)/precision;const answerType=options.answerType??"number";if(answerType==="number"&&!inexact&&!equalFloats(rounded,value)){return ["proper","improper","mixed"]}return mathFormatsForAnswerType[answerType]}function equalFloats(a,b){return Math.abs(a-b)<Math.pow(2,-42)}
|
|
373
373
|
|
|
374
374
|
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}$`}
|
|
375
375
|
|