@khanacademy/perseus-core 31.0.0 → 32.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 +21 -14
- package/dist/es/index.item-splitting.js +1 -1
- package/dist/es/index.item-splitting.js.map +1 -1
- package/dist/es/index.js +4 -4
- 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 +4 -4
- package/dist/index.js.map +1 -1
- package/dist/parse-perseus-json/perseus-parsers/image-widget.d.ts +9 -10
- package/dist/parse-perseus-json/regression-tests/item-data/image-missing-defaulted-fields.d.ts +26 -0
- package/dist/utils/generators/image-widget-generator.d.ts +1 -1
- package/package.json +2 -2
package/dist/data-schema.d.ts
CHANGED
|
@@ -721,30 +721,37 @@ export type PerseusGroupWidgetOptions = PerseusRenderer;
|
|
|
721
721
|
/** Options for the image widget. Shows an image with a caption and alt text. */
|
|
722
722
|
export type PerseusImageWidgetOptions = {
|
|
723
723
|
/** Translatable Markdown; Text to be shown for the title of the image */
|
|
724
|
-
title
|
|
724
|
+
title: string;
|
|
725
725
|
/** Translatable Markdown; Text to be shown in the caption section of an image */
|
|
726
|
-
caption
|
|
726
|
+
caption: string;
|
|
727
727
|
/** Translatable Text; The alt text to be shown in the img.alt attribute */
|
|
728
|
-
alt
|
|
728
|
+
alt: string;
|
|
729
729
|
/** Translatable Markdown; Text to be shown as the long description of an image */
|
|
730
|
-
longDescription
|
|
730
|
+
longDescription: string;
|
|
731
731
|
/**
|
|
732
732
|
* When true, standalone image will be rendered with alt="" and without any alt
|
|
733
733
|
* text, caption, title, or long description.
|
|
734
734
|
*/
|
|
735
|
-
decorative
|
|
735
|
+
decorative: boolean;
|
|
736
736
|
/** The image details for the image to be displayed */
|
|
737
737
|
backgroundImage: PerseusImageBackground;
|
|
738
738
|
/** The size scale of the image */
|
|
739
|
-
scale
|
|
740
|
-
/**
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
739
|
+
scale: number;
|
|
740
|
+
/**
|
|
741
|
+
* @deprecated - labels were removed from the image widget editor in 2017,
|
|
742
|
+
* but still appear in old content.
|
|
743
|
+
*/
|
|
744
|
+
labels: Array<PerseusImageLabel>;
|
|
745
|
+
/**
|
|
746
|
+
* @deprecated - range for labels was removed from the image widget editor
|
|
747
|
+
* in 2017, but still appears in old content.
|
|
748
|
+
*/
|
|
749
|
+
range: [Interval, Interval];
|
|
750
|
+
/**
|
|
751
|
+
* @deprecated - box for labels was removed from the image widget editor
|
|
752
|
+
* in 2017, but still appears in old content.
|
|
753
|
+
*/
|
|
754
|
+
box: Size;
|
|
748
755
|
};
|
|
749
756
|
export type PerseusImageLabel = {
|
|
750
757
|
/** Translatable Text; The content of the label to display */
|
|
@@ -94,7 +94,7 @@ const stringToNumber=(rawValue,ctx)=>{if(typeof rawValue==="number"){return ctx.
|
|
|
94
94
|
|
|
95
95
|
function emptyToZero(x){return x===""?0:x}const imageDimensionToNumber=pipeParsers(union(number).or(string).parser).then(convert(emptyToZero)).then(stringToNumber).parser;const dimensionOrUndefined=defaulted(optional(imageDimensionToNumber),()=>undefined);const parsePerseusImageBackground=object({url:optional(nullable(string)),width:dimensionOrUndefined,height:dimensionOrUndefined,top:dimensionOrUndefined,left:dimensionOrUndefined,bottom:dimensionOrUndefined,scale:dimensionOrUndefined});
|
|
96
96
|
|
|
97
|
-
const pairOfNumbers$2=pair(number,number);const parseImageWidget=parseWidget(constant("image"),object({title:
|
|
97
|
+
const pairOfNumbers$2=pair(number,number);const parseImageWidget=parseWidget(constant("image"),object({title:defaulted(string,()=>""),caption:defaulted(string,()=>""),alt:defaulted(string,()=>""),longDescription:defaulted(string,()=>""),decorative:defaulted(boolean,()=>false),backgroundImage:parsePerseusImageBackground,scale:defaulted(number,()=>1),labels:defaulted(array(object({content:string,alignment:string,coordinates:array(number)})),()=>[]),range:defaulted(pair(pairOfNumbers$2,pairOfNumbers$2),()=>[[0,10],[0,10]]),box:defaulted(pairOfNumbers$2,()=>[400,400])}));
|
|
98
98
|
|
|
99
99
|
const booleanToZero=(rawValue,ctx)=>{if(typeof rawValue==="boolean"){return ctx.success(0)}return ctx.failure("boolean",rawValue)};const parseMathFormat$1=enumeration("integer","mixed","improper","proper","decimal","percent","pi");const parseInputNumberWidgetV1=parseWidgetWithVersion(object({major:constant(1),minor:number}),constant("input-number"),object({size:string,coefficient:boolean,labelText:optional(string),textAlign:enumeration("left","center","right"),answers:array(object({value:optional(nullable(number)),status:string,message:string,answerForms:optional(array(parseMathFormat$1)),strict:boolean,maxError:optional(nullable(number)),simplify:enumeration("required","enforced","optional")}))}));function migrateV0ToV1$3(v0){const v1Options=convertInputNumberOptionsToNumericInput(v0.options);return {...v0,version:{major:1,minor:0},options:v1Options}}const parseInputNumberWidgetV0=parseWidgetWithVersion(defaulted(optional(object({major:constant(0),minor:number})),()=>undefined),constant("input-number"),object({answerType:optional(enumeration("number","decimal","integer","rational","improper","mixed","percent","pi")),inexact:optional(boolean),maxError:optional(union(number).or(string).parser),rightAlign:optional(boolean),simplify:enumeration("required","optional","enforced"),size:enumeration("normal","small"),value:defaulted(union(number).or(string).or(booleanToZero).parser,()=>0)}));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)}const parseInputNumberWidget=versionedWidgetOptions(1,parseInputNumberWidgetV1).withMigrationFrom(0,parseInputNumberWidgetV0,migrateV0ToV1$3).parser;
|
|
100
100
|
|