@khanacademy/perseus-core 35.0.0 → 36.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 +6 -2
- package/dist/es/index.item-splitting.js +4 -4
- package/dist/es/index.item-splitting.js.map +1 -1
- package/dist/es/index.js +10 -6
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.item-splitting.js +4 -4
- package/dist/index.item-splitting.js.map +1 -1
- package/dist/index.js +14 -5
- package/dist/index.js.map +1 -1
- package/dist/parse-perseus-json/general-purpose-parsers/object.d.ts +0 -19
- package/dist/parse-perseus-json/perseus-parsers/blank-widget.d.ts +15 -4
- package/dist/parse-perseus-json/perseus-parsers/categorizer-widget.d.ts +18 -7
- package/dist/parse-perseus-json/perseus-parsers/cs-program-widget.d.ts +22 -11
- package/dist/parse-perseus-json/perseus-parsers/definition-widget.d.ts +16 -5
- package/dist/parse-perseus-json/perseus-parsers/dropdown-widget.d.ts +21 -10
- package/dist/parse-perseus-json/perseus-parsers/explanation-widget.d.ts +18 -7
- package/dist/parse-perseus-json/perseus-parsers/expression-widget.d.ts +27 -16
- package/dist/parse-perseus-json/perseus-parsers/graded-group-set-widget.d.ts +26 -15
- package/dist/parse-perseus-json/perseus-parsers/graded-group-widget.d.ts +24 -13
- package/dist/parse-perseus-json/perseus-parsers/grapher-widget.d.ts +60 -49
- package/dist/parse-perseus-json/perseus-parsers/group-widget.d.ts +12 -1
- package/dist/parse-perseus-json/perseus-parsers/iframe-widget.d.ts +23 -12
- package/dist/parse-perseus-json/perseus-parsers/image-widget.d.ts +34 -23
- package/dist/parse-perseus-json/perseus-parsers/input-number-widget.d.ts +45 -23
- package/dist/parse-perseus-json/perseus-parsers/interaction-widget.d.ts +135 -124
- package/dist/parse-perseus-json/perseus-parsers/interactive-graph-widget.d.ts +375 -364
- package/dist/parse-perseus-json/perseus-parsers/label-image-widget.d.ts +27 -16
- package/dist/parse-perseus-json/perseus-parsers/matcher-widget.d.ts +18 -7
- package/dist/parse-perseus-json/perseus-parsers/matrix-widget.d.ts +17 -6
- package/dist/parse-perseus-json/perseus-parsers/measurer-widget.d.ts +28 -17
- package/dist/parse-perseus-json/perseus-parsers/number-line-widget.d.ts +28 -17
- package/dist/parse-perseus-json/perseus-parsers/numeric-input-widget.d.ts +26 -15
- package/dist/parse-perseus-json/perseus-parsers/orderer-widget.d.ts +18 -7
- package/dist/parse-perseus-json/perseus-parsers/phet-simulation-widget.d.ts +15 -4
- package/dist/parse-perseus-json/perseus-parsers/plotter-widget.d.ts +26 -15
- package/dist/parse-perseus-json/perseus-parsers/python-program-widget.d.ts +15 -4
- package/dist/parse-perseus-json/perseus-parsers/radio-widget.d.ts +138 -83
- package/dist/parse-perseus-json/perseus-parsers/sorter-widget.d.ts +16 -5
- package/dist/parse-perseus-json/perseus-parsers/table-widget.d.ts +17 -6
- package/dist/parse-perseus-json/perseus-parsers/video-widget.d.ts +14 -3
- package/dist/parse-perseus-json/perseus-parsers/widget.d.ts +25 -4
- package/dist/types.d.ts +0 -1
- package/dist/utils/generators/number-line-widget-generator.d.ts +3 -0
- package/dist/utils/generators/orderer-widget-generator.d.ts +9 -0
- package/dist/widgets/core-widget-registry.d.ts +1 -2
- package/dist/widgets/logic-export.types.d.ts +1 -2
- package/package.json +1 -1
package/dist/data-schema.d.ts
CHANGED
|
@@ -293,6 +293,7 @@ export type PerseusImageDetail = {
|
|
|
293
293
|
/** the height of the image */
|
|
294
294
|
height: number;
|
|
295
295
|
};
|
|
296
|
+
export type Alignment = "default" | "block" | "inline-block" | "inline" | "wrap-left" | "wrap-right" | "full-width";
|
|
296
297
|
/**
|
|
297
298
|
* ItemExtras represent extra UI elements that help the learner in answering
|
|
298
299
|
* the question (such as a calculator for questions where solving by hand is
|
|
@@ -341,7 +342,7 @@ export type WidgetOptions<Type extends string, Options extends Record<string, an
|
|
|
341
342
|
* widget logic, which can be various other alignments (e.g.
|
|
342
343
|
* "inline-block", "inline", etc).
|
|
343
344
|
*/
|
|
344
|
-
alignment?:
|
|
345
|
+
alignment?: Alignment;
|
|
345
346
|
/**
|
|
346
347
|
* Options specific to the type field of the widget. See Perseus*WidgetOptions for
|
|
347
348
|
* more details
|
|
@@ -1912,7 +1913,10 @@ export type PerseusIFrameWidgetOptions = {
|
|
|
1912
1913
|
height: number | string;
|
|
1913
1914
|
/** Whether to allow the IFrame to become full-screen (like a video) */
|
|
1914
1915
|
allowFullScreen: boolean;
|
|
1915
|
-
/**
|
|
1916
|
+
/**
|
|
1917
|
+
* Whether to allow the iframe content to redirect the page
|
|
1918
|
+
* @deprecated - not used in Perseus.
|
|
1919
|
+
*/
|
|
1916
1920
|
allowTopNavigation?: boolean;
|
|
1917
1921
|
/** Always false */
|
|
1918
1922
|
static: boolean;
|
|
@@ -30,7 +30,7 @@ function nullable(parseValue){return (rawValue,ctx)=>{if(rawValue===null){return
|
|
|
30
30
|
|
|
31
31
|
const number=(rawValue,ctx)=>{if(typeof rawValue==="number"&&Number.isFinite(rawValue)){return ctx.success(rawValue)}return ctx.failure("number",rawValue)};
|
|
32
32
|
|
|
33
|
-
function
|
|
33
|
+
function object(schema){return objectParserWithInitializer(()=>({}),schema)}function looseObject(schema){return objectParserWithInitializer(rawValue=>({...rawValue}),schema)}function objectParserWithInitializer(initializeParsedValue,schema){return (rawValue,ctx)=>{if(!isPlainObject(rawValue)){return ctx.failure("object",rawValue)}const parsed=initializeParsedValue(rawValue);const mismatches=[];for(const[prop,propParser]of Object.entries(schema)){const result=propParser(rawValue[prop],ctx.forSubtree(prop));if(isSuccess(result)){if(result.value!==undefined||prop in rawValue){parsed[prop]=result.value;}}else {mismatches.push(...result.detail);}}if(mismatches.length>0){return failure(mismatches)}return ctx.success(parsed)}}
|
|
34
34
|
|
|
35
35
|
function optional(parseValue){return (rawValue,ctx)=>{if(rawValue===undefined){return ctx.success(rawValue)}return parseValue(rawValue,ctx)}}
|
|
36
36
|
|
|
@@ -50,7 +50,9 @@ const parsePerseusImageDetail=object({width:number,height:number});
|
|
|
50
50
|
|
|
51
51
|
const parseImages=defaulted(record(string,parsePerseusImageDetail),()=>({}));
|
|
52
52
|
|
|
53
|
-
function
|
|
53
|
+
function convert(f){return (rawValue,ctx)=>ctx.success(f(rawValue))}
|
|
54
|
+
|
|
55
|
+
const parseAlignment=pipeParsers(enumeration("default","block","inline-block","inline","wrap-left","wrap-right","full-width","",undefined)).then(convert(value=>value===""?"default":value)).parser;function parseWidget(parseType,parseOptions){return object({type:parseType,static:optional(boolean),graded:optional(boolean),alignment:parseAlignment,options:parseOptions,key:optional(nullable(number)),version:optional(object({major:number,minor:number}))})}function parseWidgetWithVersion(parseVersion,parseType,parseOptions){return object({type:parseType,static:optional(boolean),graded:optional(boolean),alignment:parseAlignment,options:parseOptions,key:optional(nullable(number)),version:parseVersion})}
|
|
54
56
|
|
|
55
57
|
const parseBlankWidget=parseWidget(constant("blank"),object({displayType:defaulted(enumeration("normal","superscript","subscript"),()=>"normal"),correctId:string}));
|
|
56
58
|
|
|
@@ -68,8 +70,6 @@ const KeypadKeys=["PLUS","MINUS","NEGATIVE","TIMES","DIVIDE","DECIMAL","PERIOD",
|
|
|
68
70
|
|
|
69
71
|
function deriveExtraKeys(widgetOptions){if(widgetOptions.extraKeys){return widgetOptions.extraKeys}const defaultKeys=["PI"];if(widgetOptions.answerForms==null){return defaultKeys}const uniqueExtraVariables={};const uniqueExtraConstants={};for(const answerForm of widgetOptions.answerForms){const maybeExpr=KAS.parse(answerForm.value,widgetOptions);if(maybeExpr.parsed){const expr=maybeExpr.expr;const isGreek=symbol=>symbol==="pi"||symbol==="theta";const toKey=symbol=>isGreek(symbol)?symbol.toUpperCase():symbol;const isKey=key=>KeypadKeys.includes(key);for(const variable of expr.getVars()){const maybeKey=toKey(variable);if(isKey(maybeKey)){uniqueExtraVariables[maybeKey]=true;}}for(const constant of expr.getConsts()){const maybeKey=toKey(constant);if(isKey(maybeKey)){uniqueExtraConstants[maybeKey]=true;}}}}const extraVariables=Object.keys(uniqueExtraVariables).sort();const extraConstants=Object.keys(uniqueExtraConstants).sort();const extraKeys=[...extraVariables,...extraConstants];if(!extraKeys.length){return defaultKeys}return extraKeys}
|
|
70
72
|
|
|
71
|
-
function convert(f){return (rawValue,ctx)=>ctx.success(f(rawValue))}
|
|
72
|
-
|
|
73
73
|
const keypadKeys=enumeration("PLUS","MINUS","NEGATIVE","TIMES","DIVIDE","DECIMAL","PERIOD","PERCENT","CDOT","EQUAL","NEQ","GT","LT","GEQ","LEQ","FRAC_INCLUSIVE","FRAC_EXCLUSIVE","FRAC","EXP","EXP_2","EXP_3","SUB","SQRT","CUBE_ROOT","RADICAL","LEFT_PAREN","RIGHT_PAREN","LN","LOG","LOG_N","SIN","COS","TAN","PI","THETA","UP","RIGHT","DOWN","LEFT","BACKSPACE","DISMISS","JUMP_OUT_PARENTHESES","JUMP_OUT_EXPONENT","JUMP_OUT_BASE","JUMP_INTO_NUMERATOR","JUMP_OUT_NUMERATOR","JUMP_OUT_DENOMINATOR","NUM_0","NUM_1","NUM_2","NUM_3","NUM_4","NUM_5","NUM_6","NUM_7","NUM_8","NUM_9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
|
|
74
74
|
|
|
75
75
|
const parseLegacyButtonSet=enumeration("basic","basic+div","trig","prealgebra","logarithms","basic relations","advanced relations","scientific");const parseLegacyButtonSets=defaulted(array(parseLegacyButtonSet),()=>["basic","trig","prealgebra","logarithms"]);
|